@ones-editor/editor 0.0.3-beta.58 → 0.0.3-beta.59

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
@@ -1,5 +1,5 @@
1
1
  (function(){"use strict";try{if(typeof document!="undefined"){var t=document.createElement("style");t.appendChild(document.createTextNode(`@charset "UTF-8";@keyframes ones-editor-blink{0%,to{background-color:transparent}50%{background-color:var(--primary-color)}}*{--link-color: #338fe5;--color-0: #e52727;--color-1: #eb6414;--color-2: #f0a100;--color-3: #24b47e;--color-4: #338fe5;--color-5: #9678d3;--color-6: #909090;--background-color-0: #fad4d4;--background-color-1: #fbe0d0;--background-color-2: #fceccc;--background-color-3: #d3f0e5;--background-color-4: #d6e9fa;--background-color-5: #eae4f6;--background-color-6: #dedede;--background-color-7: #e52727;--background-color-8: #eb6414;--background-color-9: #f0a100;--background-color-10: #24b47e;--background-color-11: #338fe5;--background-color-12: #9678d3;--background-color-13: #909090;--background-color-14: #e8e8e8;--font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif}div.editor-root{--text-color: #303030;--primary-color: #338fe5;--background-selection: #338fe533;--background-code: #eeeeee}div.editor-root{color:var(--text-color);position:relative;box-sizing:border-box;height:100%;width:100%;z-index:1}div.editor-root *{box-sizing:border-box;font-family:var(--font-family)}div.editor-root.active div.editor-content .editor-cursor{opacity:1}div.editor-root .safari.mobile div.editor-content .editor-input{pointer-events:all;width:8px}div.editor-root div.editor-content{height:100%;width:100%;padding:0 30px 30px}div.editor-root div.editor-content .editor-cursor{position:absolute;background:var(--primary-color);width:2px;transition:top .125s ease-in,left .125s ease-in;animation:ones-editor-blink 1s ease-in-out infinite;opacity:0;pointer-events:none}div.editor-root div.editor-content .editor-input{position:absolute;opacity:0;pointer-events:none;width:16px;height:20px;font-size:16px}div.editor-root div.editor-content div[data-type=editor-container]{position:relative}div.editor-root div.editor-content div[data-type=editor-container].root{user-select:none;width:100%;cursor:text}div.editor-root div.editor-content div[data-type=editor-container].root>.container-blocks>*+*{margin-top:1em}div.editor-root div.editor-content div[data-type=editor-container].root.select-all>.container-blocks>div[data-type=editor-block]:not(:first-of-type){background-color:var(--background-selection)}div.editor-root div.editor-content div[data-type=editor-container].root.select-all>.container-blocks>div[data-type=editor-block]:not(:first-of-type) div[data-type=block-background]>.editor-selection-background{background-color:transparent!important}div.editor-root div.editor-content div[data-type=editor-container].root.select-all>.container-blocks>div[data-type=editor-block].embed-block>div[data-type=block-content]:before,div.editor-root div.editor-content div[data-type=editor-container].root.select-all>.container-blocks>div[data-type=editor-block].embed-block .embed-selected-content:before{display:none}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block][data-style-quoted]+div[data-type=editor-block][data-style-quoted]{margin-top:0;padding-top:0}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block]{position:relative;--font-size: 14px;--line-height: 1.6}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block][data-style-align=center] div[data-type=block-content]{text-align:center}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block][data-style-align=right] div[data-type=block-content]{text-align:end}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block].block-hidden{display:none}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block][data-block-type=text]{cursor:text}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]{word-break:break-word;position:relative}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span{line-height:1.4em;cursor:text}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span.text{white-space:pre-wrap}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span.text.link{color:var(--link-color)}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span.text.link:hover{text-decoration:underline}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span.text.style-bold{font-weight:700}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span.text.style-italic{font-style:italic}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span.text.style-underline{text-decoration:underline}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span.text.style-strikethrough{text-decoration:line-through}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span.text.style-underline.style-strikethrough{text-decoration:underline line-through}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span.text.style-code{border-radius:5px;-moz-border-radius:5px;-webkit-border-radius:5px;background-color:var(--background-code);padding:4px;font:.8em Monaco,Consolas,"Andale Mono",DejaVu Sans Mono,monospace}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span.text.style-subscript{vertical-align:sub;font-size:70%}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span.text.style-superscript{vertical-align:super;font-size:70%}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span.text[data-style-color="0"]{color:var(--color-0)}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span.text[data-style-color="1"]{color:var(--color-1)}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span.text[data-style-color="2"]{color:var(--color-2)}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span.text[data-style-color="3"]{color:var(--color-3)}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span.text[data-style-color="4"]{color:var(--color-4)}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span.text[data-style-color="5"]{color:var(--color-5)}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span.text[data-style-color="6"]{color:var(--color-6)}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span.text[data-style-bg-color="0"]{background-color:var(--background-color-0)}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span.text[data-style-bg-color="1"]{background-color:var(--background-color-1)}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span.text[data-style-bg-color="2"]{background-color:var(--background-color-2)}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span.text[data-style-bg-color="3"]{background-color:var(--background-color-3)}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span.text[data-style-bg-color="4"]{background-color:var(--background-color-4)}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span.text[data-style-bg-color="5"]{background-color:var(--background-color-5)}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span.text[data-style-bg-color="6"]{background-color:var(--background-color-6)}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span.text[data-style-bg-color="7"]{background-color:var(--background-color-7)}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span.text[data-style-bg-color="8"]{background-color:var(--background-color-8)}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span.text[data-style-bg-color="9"]{background-color:var(--background-color-9)}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span.text[data-style-bg-color="10"]{background-color:var(--background-color-10)}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span.text[data-style-bg-color="11"]{background-color:var(--background-color-11)}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span.text[data-style-bg-color="12"]{background-color:var(--background-color-12)}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span.text[data-style-bg-color="13"]{background-color:var(--background-color-13)}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span.text[data-style-bg-color="14"]{background-color:var(--background-color-14)}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span[data-type=editor-insertion].inputting-insertion>span[data-type=insertion-content]{border-bottom:1px solid var(--primary-color)}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span[data-type=editor-insertion].remote-cursor-insertion{width:0px;position:relative;display:inline-block;vertical-align:text-bottom;overflow:visible;height:1em}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span[data-type=editor-insertion].remote-cursor-insertion>span[data-type=insertion-content]{position:absolute;color:transparent;width:3px;left:-3px;border-right:var(--cursor-color) 1px solid;text-overflow:clip;display:inline-block;top:-5px;bottom:0}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span[data-type=editor-insertion].remote-cursor-insertion>span[data-type=insertion-content] span[data-cursor-name]{display:inline-block;width:8px;background-color:transparent;border:none}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span[data-type=editor-insertion].remote-cursor-insertion>span[data-type=insertion-content] span[data-cursor-name]:hover:before,div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span[data-type=editor-insertion].remote-cursor-insertion.active>span[data-type=insertion-content] span[data-cursor-name]:before{content:attr(data-cursor-name);position:absolute;top:-12px;height:1.1em;background-color:var(--cursor-color);z-index:27;left:0px;color:#fff;white-space:nowrap;font-size:12px;display:flex;align-items:center;padding:1px 4px}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content] span[data-type=box-content]{border-radius:2px;margin-left:8px;margin-right:8px}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content] span[data-type=editor-box].br-box>span[data-type=box-content] img{vertical-align:middle;max-width:1em}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-tools] .editor-block-anchor{position:absolute}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-background] .editor-selection-background{position:absolute;background-color:var(--background-selection);z-index:1;pointer-events:none}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block].embed-block,div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block].unknown-block{cursor:default}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block].embed-block.hover>div[data-type=block-content],div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block].unknown-block.hover>div[data-type=block-content]{outline:1px solid #338fe5}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block].embed-block>div[data-type=block-content],div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block].unknown-block>div[data-type=block-content]{display:flex}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block].embed-block.hover .embed-hover-content{outline:1px solid #338fe5}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block].embed-block.selected>div[data-type=block-content],div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block].embed-block.selected .embed-selected-content{position:relative}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block].embed-block.selected>div[data-type=block-content]:before,div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block].embed-block.selected .embed-selected-content:before{content:" ";position:absolute;left:0;top:0;right:0;bottom:0;pointer-events:none;z-index:1;background-color:#338fe5;opacity:.1}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block].unknown-block{color:#909090;font-size:12px}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block].unknown-block>div[data-type=block-content]{padding:5px}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block][data-style-quoted]{border-left:4px solid #e8e8e8;color:#909090}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block][data-style-quoted]:not([data-list-level]){padding-left:8px}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block][data-style-heading="1"]{--font-size: 28px;--line-height: 1.5}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block][data-style-heading="2"]{--font-size: 26px;--line-height: 1.5}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block][data-style-heading="3"]{--font-size: 24px;--line-height: 1.5}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block][data-style-heading="4"]{--font-size: 22px;--line-height: 1.5}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block][data-style-heading="5"]{--font-size: 20px;--line-height: 1.6}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block][data-style-heading="6"]{--font-size: 18px;--line-height: 1.6}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block][data-style-heading="7"]{--font-size: 16px;--line-height: 1.6}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block][data-style-heading="8"]{--font-size: 14px;--line-height: 1.6}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block][data-style-heading]{font-size:var(--font-size);line-height:var(--line-height);font-weight:700}.editor-disable-scroll{position:fixed;left:0;top:0;width:100vw;height:100vh;z-index:9900;overflow:hidden}.editor-root .editor-content div[data-type=editor-block] div[data-type=block-tools] .block-anchor{position:absolute;pointer-events:none;z-index:-1}.editor-command-bar.toolbar .color-button{width:24px;height:24px;display:flex;padding:0;margin:0;align-items:center;justify-content:center;background-color:transparent;border:0;outline:0;border-radius:3px;cursor:pointer}.editor-command-bar.toolbar .color-button[data-color="0"]{color:var(--color-0)}.editor-command-bar.toolbar .color-button[data-color="1"]{color:var(--color-1)}.editor-command-bar.toolbar .color-button[data-color="2"]{color:var(--color-2)}.editor-command-bar.toolbar .color-button[data-color="3"]{color:var(--color-3)}.editor-command-bar.toolbar .color-button[data-color="4"]{color:var(--color-4)}.editor-command-bar.toolbar .color-button[data-color="5"]{color:var(--color-5)}.editor-command-bar.toolbar .color-button[data-color="6"]{color:var(--color-6)}.editor-command-bar.toolbar .color-button[data-background-color="0"]{background-color:var(--background-color-0)}.editor-command-bar.toolbar .color-button[data-background-color="1"]{background-color:var(--background-color-1)}.editor-command-bar.toolbar .color-button[data-background-color="2"]{background-color:var(--background-color-2)}.editor-command-bar.toolbar .color-button[data-background-color="3"]{background-color:var(--background-color-3)}.editor-command-bar.toolbar .color-button[data-background-color="4"]{background-color:var(--background-color-4)}.editor-command-bar.toolbar .color-button[data-background-color="5"]{background-color:var(--background-color-5)}.editor-command-bar.toolbar .color-button[data-background-color="6"]{background-color:var(--background-color-6)}.editor-command-bar.toolbar .color-button[data-background-color="7"]{background-color:var(--background-color-7)}.editor-command-bar.toolbar .color-button[data-background-color="8"]{background-color:var(--background-color-8)}.editor-command-bar.toolbar .color-button[data-background-color="9"]{background-color:var(--background-color-9)}.editor-command-bar.toolbar .color-button[data-background-color="10"]{background-color:var(--background-color-10)}.editor-command-bar.toolbar .color-button[data-background-color="11"]{background-color:var(--background-color-11)}.editor-command-bar.toolbar .color-button[data-background-color="12"]{background-color:var(--background-color-12)}.editor-command-bar.toolbar .color-button[data-background-color="13"]{background-color:var(--background-color-13)}.editor-command-bar.toolbar .color-button[data-background-color="14"]{background-color:var(--background-color-14)}.tippy-content{white-space:pre-line}.editor-button{min-height:26px;min-width:46px;font-size:12px;font-weight:500;outline:none;background-color:var(--editor-button-bg-color, #338fe5);color:var(--editor-button-color, #fff);border:0;padding:4px 8px;border-radius:4px;margin-right:8px;cursor:pointer}.editor-button:hover{background-color:#5ca5ea}.tippy-box[data-animation=fade][data-state=hidden]{opacity:0}[data-tippy-root]{max-width:calc(100vw - 10px)}.tippy-box{position:relative;background-color:#333;color:#fff;border-radius:4px;font-size:14px;line-height:1.4;white-space:normal;outline:0;transition-property:transform,visibility,opacity}.tippy-box[data-placement^=top]>.tippy-arrow{bottom:0}.tippy-box[data-placement^=top]>.tippy-arrow:before{bottom:-7px;left:0;border-width:8px 8px 0;border-top-color:initial;transform-origin:center top}.tippy-box[data-placement^=bottom]>.tippy-arrow{top:0}.tippy-box[data-placement^=bottom]>.tippy-arrow:before{top:-7px;left:0;border-width:0 8px 8px;border-bottom-color:initial;transform-origin:center bottom}.tippy-box[data-placement^=left]>.tippy-arrow{right:0}.tippy-box[data-placement^=left]>.tippy-arrow:before{border-width:8px 0 8px 8px;border-left-color:initial;right:-7px;transform-origin:center left}.tippy-box[data-placement^=right]>.tippy-arrow{left:0}.tippy-box[data-placement^=right]>.tippy-arrow:before{left:-7px;border-width:8px 8px 8px 0;border-right-color:initial;transform-origin:center right}.tippy-box[data-inertia][data-state=visible]{transition-timing-function:cubic-bezier(.54,1.5,.38,1.11)}.tippy-arrow{width:16px;height:16px;color:#333}.tippy-arrow:before{content:"";position:absolute;border-color:transparent;border-style:solid}.tippy-content{position:relative;padding:5px 9px;z-index:1}[data-theme=dropdown-list]{border-radius:4px;background:white;position:relative;max-width:calc(100vw - 24px);box-shadow:#0f0f0f0d 0 0 0 1px,#0f0f0f1a 0 3px 6px,#0f0f0f33 0 9px 24px;overflow:hidden}[data-theme=dropdown-list] .tippy-content{padding:0;background:white;color:#303030}[data-theme=dropdown-list] .tippy-content .editor-command-bar{max-height:50vh}[data-theme=dropdown-list] .filterable-list{min-width:100px;max-width:300px;display:flex;flex-direction:column;max-height:100%}[data-theme=dropdown-list] .filterable-list .filter{padding:8px}[data-theme=dropdown-list] .filterable-list .filter .filter-container{width:100%;font-size:14px;line-height:20px;padding:3px 6px;position:relative;border-radius:3px;box-shadow:#0f0f0f1a 0 0 0 1px inset;background:rgba(242,241,238,.6);cursor:text;height:28px;box-sizing:border-box;display:flex;align-items:center}[data-theme=dropdown-list] .filterable-list .filter .filter-container input.filter-input{border:none;outline:none;flex-grow:1;background:transparent}[data-theme=dropdown-list] .filterable-list .list{max-height:60vh;overflow-y:auto;padding:8px 0}[data-theme=dropdown-list] .filterable-list .list .list-item{user-select:none;transition:background 20ms ease-in 0s;cursor:pointer;width:calc(100% - 8px);margin-left:4px;margin-right:4px;border-radius:3px;height:24px;padding:4px 8px;display:flex;align-items:center;box-sizing:border-box}[data-theme=dropdown-list] .filterable-list .list .list-item .list-text{white-space:nowrap}[data-theme=dropdown-list] .filterable-list .list .list-item.selected{background-color:#eee}::placeholder{color:#bbb}.toast{font-family:Avenir,Helvetica,Arial,sans-serif;visibility:hidden;min-width:250px;margin-left:-125px;background-color:#333;color:#fff;text-align:center;border-radius:2px;padding:8px;position:fixed;z-index:1;left:50%;bottom:30px}.toast.show{visibility:visible;animation:toast_fade_in .5s,toast_fade_out .5s 2.5s}.toast.positioned.show{animation:toast_fade_in_positioned .5s,toast_fade_out_positioned .5s 2.5s}.toast.positioned{bottom:unset}@keyframes toast_fade_in{0%{bottom:0;opacity:0}to{bottom:30px;opacity:1}}@keyframes toast_fade_out{0%{bottom:30px;opacity:1}to{bottom:0;opacity:0}}@keyframes toast_fade_in_positioned{0%{opacity:0}to{opacity:1}}@keyframes toast_fade_out_positioned{0%{opacity:1}to{opacity:0}}div.tippy-box[data-theme=toolbar] .tippy-content,div.tippy-box[data-theme=menu] .tippy-content{padding:0}div.tippy-box[data-theme=menu] .tippy-content .editor-command-bar.menu{min-width:180px}.editor-command-bar{pointer-events:all;display:flex;box-sizing:border-box;--text-color: #606060;--primary-color: #338fe5;--selected-color: #f8f8f8;--separator-color: #dedede;--warn-color: #fdf4f4}.editor-command-bar.menu{display:flex;flex-direction:column;align-items:flex-start;padding:5px 0;background:#ffffff;box-shadow:0 0 1px #30303040,0 12px 24px #30303026;border-radius:2px;max-height:50vh;overflow:auto}.editor-command-bar.menu .command-item.standard{color:var(--text-color);user-select:none;transition:background 20ms ease-in 0s;cursor:pointer;width:100%;height:32px;padding:6px 10px;display:flex;align-items:center;box-sizing:border-box}.editor-command-bar.menu .command-item.standard .menu-item-icon{align-items:center;height:24px;width:24px;margin-right:5px;margin-top:-2px;display:flex;flex-direction:column;justify-content:center}.editor-command-bar.menu .command-item.standard .menu-item-name{white-space:nowrap;flex-grow:1;display:flex;align-items:center}.editor-command-bar.menu .command-item.standard .item-subtext{color:#b2bccd}.editor-command-bar.menu .command-item.standard .menu-item-sub-indicator{display:flex;align-items:center;justify-content:center}.editor-command-bar.menu .command-item.standard .menu-item-sub-indicator svg{width:16px;height:16px}.editor-command-bar.menu .command-item.standard.disabled{color:#c7c7c7;cursor:not-allowed}.editor-command-bar.menu .command-item.separator{height:1px;margin:4px 0;background-color:var(--separator-color);width:100%}.editor-command-bar.menu .command-item.section{font-size:.8em;color:#ccc;padding:5px 5px 5px 10px}.editor-command-bar.menu .command-item.selected{background-color:var(--selected-color)}.editor-command-bar.menu .command-item.selected[data-id=delete]{background-color:var(--warn-color)}.editor-command-bar.menu .command-item.selected.disabled{background-color:transparent}.editor-command-bar.menu .command-item.checked{color:var(--primary-color)}.editor-command-bar.menu .command-item.checked .menu-item-checked-icon{display:flex;align-items:center;justify-content:center;margin-left:10px}.editor-command-bar.menu .command-item.checked.disabled{color:#c7c7c7}.editor-command-bar.menu .command-item span.highlight{color:#e52727}.editor-command-bar.toolbar{display:flex;flex-direction:row;align-items:flex-start;padding:5px 10px;gap:5px;background:#ffffff;box-shadow:0 0 1px #30303033,0 8px 16px #30303026;border-radius:3px}.editor-command-bar.toolbar .command-item{background:transparent;border:none;display:flex;align-items:center;justify-content:center;color:var(--text-color);height:24px;padding:0;cursor:pointer;border-radius:3px;min-width:24px}.editor-command-bar.toolbar .command-item.selected{background-color:var(--selected-color)}.editor-command-bar.toolbar .command-item.disabled{color:#c7c7c7}.editor-command-bar.toolbar .command-item.checked{color:var(--primary-color)}.editor-command-bar.toolbar .command-item.checked.disabled{color:#c7c7c7}.editor-command-bar.toolbar .command-item.separator{margin:auto 2px;height:20px;min-width:1px;width:1px;background-color:var(--separator-color);padding:0;pointer-events:none;cursor:default}.editor-command-bar.toolbar .command-item .toolbar-item-name-container,.editor-command-bar.toolbar .command-item .toolbar-item-icon-container{display:flex}.editor-command-bar.toolbar .command-item[data-dropdown=true]{padding-left:4px;padding-right:4px}.editor-command-bar.toolbar .command-item[data-dropdown=true] .toolbar-item-icon-container{width:24px;height:24px;align-items:center;justify-content:center}.editor-command-bar.toolbar .command-item .toolbar-item-dropdown-container{display:flex}.editor-command-bar.toolbar .command-item .toolbar-item-dropdown-container svg{transform:rotate(360deg);transition:transform .2s linear}.editor-command-bar.toolbar .command-item.active .toolbar-item-dropdown-container svg{transform:rotate(180deg)}.editor-command-bar.toolbar .editor-button+.editor-button{margin-left:5px}.reference-hidden .tippy-box[data-reference-hidden]{opacity:0;pointer-events:none;transition:none}.tippy-box[data-theme~=light]{color:#26323d;box-shadow:0 0 20px 4px #9aa1b126,0 4px 80px -8px #24282f40,0 4px 4px -2px #5b5e6926;background-color:#fff}.tippy-box[data-theme~=light][data-placement^=top]>.tippy-arrow:before{border-top-color:#fff}.tippy-box[data-theme~=light][data-placement^=bottom]>.tippy-arrow:before{border-bottom-color:#fff}.tippy-box[data-theme~=light][data-placement^=left]>.tippy-arrow:before{border-left-color:#fff}.tippy-box[data-theme~=light][data-placement^=right]>.tippy-arrow:before{border-right-color:#fff}.tippy-box[data-theme~=light]>.tippy-backdrop{background-color:#fff}.tippy-box[data-theme~=light]>.tippy-svg-arrow{fill:#fff}.scale-border:after,.color-palette .palette-container-row .background-color-button.selected:after,.color-palette .palette-container-row .background-color-button:hover:after{content:"";outline:1px solid #d6e9fa;border-radius:3px;position:absolute;left:0;right:0;top:0;bottom:0;transform:scale(1.1)}.color-palette{display:flex;flex-direction:column;align-items:center;padding-top:5px;background-color:#fff;--active-color: #2872b7}.color-palette .bar-desc{box-sizing:border-box;width:100%;height:24px;padding-left:10px;margin-bottom:10px;line-height:24px;font-size:12px;font-weight:500;background:#F8F8F8;color:#909090}.color-palette .palette-container{padding:0 10px}.color-palette .background-color .palette-container-row:first-child{margin-bottom:5px}.color-palette .palette-container-row{display:flex;flex-direction:row;margin-bottom:20px}.color-palette .palette-container-row .color-button{width:24px;height:24px;border:none;outline:none;cursor:pointer;border-radius:3px;background-color:#fff;border:1px solid #f0f0f0;display:flex;margin:0;padding:0;align-items:center;justify-content:center}.color-palette .palette-container-row .color-button:hover{border:1px solid #d6e9fa}.color-palette .palette-container-row .color-button.selected{border:1px solid var(--primary-color)}.color-palette .palette-container-row .color-button[data-color-index="-1"]{color:var(--text-color)}.color-palette .palette-container-row .color-button[data-color-index="0"]{color:var(--color-0)}.color-palette .palette-container-row .color-button[data-color-index="1"]{color:var(--color-1)}.color-palette .palette-container-row .color-button[data-color-index="2"]{color:var(--color-2)}.color-palette .palette-container-row .color-button[data-color-index="3"]{color:var(--color-3)}.color-palette .palette-container-row .color-button[data-color-index="4"]{color:var(--color-4)}.color-palette .palette-container-row .color-button[data-color-index="5"]{color:var(--color-5)}.color-palette .palette-container-row .color-button[data-color-index="6"]{color:var(--color-6)}.color-palette .palette-container-row .background-color-button{width:24px;height:24px;border:none;outline:none;cursor:pointer;border-radius:3px;position:relative}.color-palette .palette-container-row .background-color-button.selected:after{outline:1px solid var(--primary-color)}.color-palette .palette-container-row .background-color-button[data-color-index="-1"]{position:relative;background-color:#fff;border:1px solid #e8e8e8}.color-palette .palette-container-row .background-color-button[data-color-index="-1"]:after{transform:scale(1.2)}.color-palette .palette-container-row .background-color-button[data-color-index="-1"]:before{content:"";position:absolute;width:1px;height:56px;top:2px;left:22px;background-color:#c7c7c7;transform:rotate(45deg) scale(.5);transform-origin:-1px -2px}.color-palette .palette-container-row .background-color-button[data-color-index="0"]{background-color:var(--background-color-0)}.color-palette .palette-container-row .background-color-button[data-color-index="1"]{background-color:var(--background-color-1)}.color-palette .palette-container-row .background-color-button[data-color-index="2"]{background-color:var(--background-color-2)}.color-palette .palette-container-row .background-color-button[data-color-index="3"]{background-color:var(--background-color-3)}.color-palette .palette-container-row .background-color-button[data-color-index="4"]{background-color:var(--background-color-4)}.color-palette .palette-container-row .background-color-button[data-color-index="5"]{background-color:var(--background-color-5)}.color-palette .palette-container-row .background-color-button[data-color-index="6"]{background-color:var(--background-color-6)}.color-palette .palette-container-row .background-color-button[data-color-index="7"]{background-color:var(--background-color-7)}.color-palette .palette-container-row .background-color-button[data-color-index="8"]{background-color:var(--background-color-8)}.color-palette .palette-container-row .background-color-button[data-color-index="9"]{background-color:var(--background-color-9)}.color-palette .palette-container-row .background-color-button[data-color-index="10"]{background-color:var(--background-color-10)}.color-palette .palette-container-row .background-color-button[data-color-index="11"]{background-color:var(--background-color-11)}.color-palette .palette-container-row .background-color-button[data-color-index="12"]{background-color:var(--background-color-12)}.color-palette .palette-container-row .background-color-button[data-color-index="13"]{background-color:var(--background-color-13)}.color-palette .palette-container-row .background-color-button[data-color-index="14"]{background-color:var(--background-color-14)}.color-palette .palette-container-row .color-button+.color-button{margin-left:5px}.color-palette .palette-container-row .background-color-button+.background-color-button{margin-left:5px}.color-palette .clear-button-container{box-sizing:border-box;width:100%;margin-bottom:5px;padding:0 10px}.color-palette .clear-button-container .clear-button{box-sizing:border-box;padding:3px 10px;width:100%;height:26px;background:#ffffff;color:#606060;border:1px solid #c7c7c7;border-radius:3px;cursor:pointer}.color-palette .clear-button-container .clear-button:hover{border-color:var(--primary-color);color:var(--primary-color)}.color-palette .clear-button-container .clear-button:active{border-color:var(--active-color);color:var(--active-color);background-color:#d6e9fa}.editor-input-wrap .editor-input-label{margin-top:8px;margin-bottom:8px;position:relative}.editor-input-wrap .editor-input-label.required:before{content:"*";color:#e82100;position:absolute;left:-8px;top:3px}.editor-input-wrap .editor-input-label .span{font-size:14px;line-height:1.4;font-weight:700;color:#303030}.editor-input-wrap .editor-input-container{display:flex;border:none;border-radius:4px;padding:4px;background-color:#fff}.editor-input-wrap .editor-input-container .editor-input{outline:none;border:1px solid #c7c7c7;border-radius:3px;padding:4px 10px;font-size:14px;line-height:1.4;color:#000;width:100%}.editor-input-wrap .editor-input-container .editor-input:focus{border-color:#338fe5;box-shadow:0 0 0 2px #338fe533}.editor-input-wrap.error .editor-input-container{border:1px solid #e82100}.editor-input-wrap.error .editor-input-container .editor-input{border:none;outline:none;box-shadow:unset}.editor-input-wrap.error .editor-input-error{margin-top:8px;color:red;display:block}.editor-input-wrap .editor-input-error{display:none}div.scroll-container-root{position:relative}div.scroll-container-root>div.scroll-container{position:relative;overflow-x:auto;overflow-y:hidden;box-sizing:border-box;line-height:0px}div.scroll-container-root>div.scroll-container>.scroll-area{position:relative;display:inline-block;overflow:hidden;line-height:normal}div.scroll-container-root>div.scroll-container{scrollbar-width:none}div.scroll-container-root>div.scroll-container::-webkit-scrollbar{height:0;opacity:0}div.scroll-container-root>div.container-scroll-tool .container-border-shadow{position:absolute;top:0;opacity:0;width:0;border:none;pointer-events:none;transition:opacity 50ms ease-in;z-index:1}div.scroll-container-root>div.container-scroll-tool .container-right-border-shadow{right:0;background:linear-gradient(90deg,rgba(31,35,41,0) 0,rgba(31,35,41,.1));border-right:0px solid #dee0e3}div.scroll-container-root>div.container-scroll-tool .container-left-border-shadow{left:0;background:linear-gradient(270deg,rgba(31,35,41,0) 0,rgba(31,35,41,.1));border-left:0px solid #dee0e3}div.scroll-container-root>div.container-scroll-tool .container-border-shadow.active{width:8px;opacity:1}div.scroll-container-root>div.container-scroll-tool .container-right-border-shadow.active{border-right-width:1px}div.scroll-container-root>div.container-scroll-tool .container-left-border-shadow.active{border-left-width:1px}div.scroll-container-root>div.container-scroll-tool .container-scrollbar{position:absolute;left:0;z-index:1000;visibility:visible;overflow-x:auto;overflow-y:hidden;cursor:auto}div.scroll-container-root>div.container-scroll-tool .container-scrollbar div{height:1px}div.scroll-container-root>div.container-scroll-tool div.container-scrollbar.fixed{position:fixed}div.scroll-container-root.mac>div.container-scroll-tool .container-scrollbar{opacity:.6;transition:opacity .1s ease-in-out}div.scroll-container-root.mac>div.container-scroll-tool .container-scrollbar::-webkit-scrollbar{height:8px}div.scroll-container-root.mac>div.container-scroll-tool .container-scrollbar::-webkit-scrollbar-track{background-color:transparent}div.scroll-container-root.mac>div.container-scroll-tool .container-scrollbar::-webkit-scrollbar-thumb{background-color:#646a73cc;border-radius:8px}div.scroll-container-root.mac>div.container-scroll-tool .container-scrollbar::-webkit-scrollbar-button{display:none}[data-tippy-root]{font-family:Avenir,Helvetica,Arial,sans-serif}[data-command-bar-id=editor-toolbar]{padding-top:10px;padding-bottom:5px}[data-command-bar-id=editor-toolbar] .command-item[data-id=link-text]{width:unset}[data-command-bar-id=editor-toolbar] .command-item[data-id=link-text]:hover{background-color:transparent}[data-command-bar-id=editor-toolbar] .command-item[data-id=link-text] .link-href-button{max-width:400px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}[data-command-bar-id=editor-toolbar] .command-item[data-id=link-text] .link-href-button:hover{text-decoration:underline}[data-command-bar-id=quick-menu],[data-command-bar-id=empty-block-menu]{box-sizing:border-box;width:240px}[data-command-bar-id=quick-menu] .command-item.menu-item,[data-command-bar-id=empty-block-menu] .command-item.menu-item{width:100%;cursor:pointer}[data-command-bar-id=quick-menu] .command-item.menu-item.section,[data-command-bar-id=empty-block-menu] .command-item.menu-item.section{height:24px;padding:2px 10px;font-weight:500;font-size:12px;line-height:20px;color:#909090;background:#F8F8F8;min-height:initial;box-sizing:border-box;margin-bottom:5px}[data-command-bar-id=quick-menu] .command-item.menu-item .quick-menu-item,[data-command-bar-id=empty-block-menu] .command-item.menu-item .quick-menu-item{color:#303030;display:flex;width:100%;padding:6px 10px}[data-command-bar-id=quick-menu] .command-item.menu-item .quick-menu-item .quick-menu-item-icon-container,[data-command-bar-id=empty-block-menu] .command-item.menu-item .quick-menu-item .quick-menu-item-icon-container{display:flex;align-items:center;justify-content:center;padding-right:6px}[data-command-bar-id=quick-menu] .command-item.menu-item .quick-menu-item .quick-menu-item-icon-container .quick-menu-item-icon,[data-command-bar-id=empty-block-menu] .command-item.menu-item .quick-menu-item .quick-menu-item-icon-container .quick-menu-item-icon{width:16px;height:16px;display:flex;align-items:center;justify-content:center}[data-command-bar-id=quick-menu] .command-item.menu-item .quick-menu-item .quick-menu-item-content,[data-command-bar-id=empty-block-menu] .command-item.menu-item .quick-menu-item .quick-menu-item-content{flex-grow:1;display:flex;flex-direction:column;justify-content:center}[data-command-bar-id=quick-menu] .command-item.menu-item .quick-menu-item .quick-menu-item-content .item-line-1,[data-command-bar-id=empty-block-menu] .command-item.menu-item .quick-menu-item .quick-menu-item-content .item-line-1{display:flex;align-items:center}[data-command-bar-id=quick-menu] .command-item.menu-item .quick-menu-item .quick-menu-item-content .item-line-1 .item-name,[data-command-bar-id=empty-block-menu] .command-item.menu-item .quick-menu-item .quick-menu-item-content .item-line-1 .item-name{flex-grow:1;font-size:14px;line-height:22px;color:#303030}[data-command-bar-id=quick-menu] .command-item.menu-item .quick-menu-item .quick-menu-item-content .item-line-1 .item-subtext,[data-command-bar-id=empty-block-menu] .command-item.menu-item .quick-menu-item .quick-menu-item-content .item-line-1 .item-subtext{color:#b2bccd}[data-command-bar-id=quick-menu] .command-item.menu-item .quick-menu-item .quick-menu-item-content .item-line-1 .quick-menu-item-submenu-icon,[data-command-bar-id=empty-block-menu] .command-item.menu-item .quick-menu-item .quick-menu-item-content .item-line-1 .quick-menu-item-submenu-icon{display:flex;align-items:center;margin-left:12px}[data-command-bar-id=quick-menu] .command-item.menu-item .quick-menu-item .quick-menu-item-content .item-line-2,[data-command-bar-id=empty-block-menu] .command-item.menu-item .quick-menu-item .quick-menu-item-content .item-line-2{margin-top:5px}[data-command-bar-id=quick-menu] .command-item.menu-item .quick-menu-item .quick-menu-item-content .item-line-2 .item-markdown,[data-command-bar-id=empty-block-menu] .command-item.menu-item .quick-menu-item .quick-menu-item-content .item-line-2 .item-markdown{color:#b2bccd}[data-command-bar-id=quick-menu] .command-item.menu-item[data-id=placeholder] .quick-menu-item-icon-container,[data-command-bar-id=empty-block-menu] .command-item.menu-item[data-id=placeholder] .quick-menu-item-icon-container{display:none}[data-command-bar-id=quick-menu] .command-item.menu-item[data-id=placeholder] .item-name.text,[data-command-bar-id=empty-block-menu] .command-item.menu-item[data-id=placeholder] .item-name.text{color:#909090!important;padding:5px 0}[data-command-bar-id=block-menu]{width:240px}div.tippy-box .editor-tooltip-desc{display:block;margin-top:2px;color:#a8a9ab}.link-popup-content{padding:10px 7px}.link-popup-content .link-popup-gap{margin-top:16px}.link-popup-content .editor-input-container{padding:4px 0}.link-popup-content .editor-input-container .editor-input{width:330px;line-height:1.5}.link-popup-content .editor-input-wrap .editor-input-label{margin-bottom:4px}.link-popup-content .link-popup-footer{margin:10px 0 5px;text-align:right}.link-popup-content .link-popup-footer button{min-width:58px;min-height:30px;padding:0 10px;border-radius:3px;background-color:#eef3f8;font-size:14px;color:#fff;cursor:pointer;outline:none}.link-popup-content .link-popup-footer .cancel-button{margin:0 8px 0 0;background-color:transparent;border:1px solid #c7c7c7;color:#606060}.link-popup-content .link-popup-footer .cancel-button:hover{color:#303030;background:#eee;border:1px solid #c7c7c7}.link-popup-content .link-popup-footer .submit-button{outline:none;background-color:#338fe5;color:#fff;border:0}.link-popup-content .link-popup-footer .submit-button:disabled{color:#fff;background-color:#338fe580}.link-popup-content .link-popup-footer .submit-button:disabled:hover{background-color:#338fe580}.link-popup-content .link-popup-footer .submit-button:hover{background-color:#5ca5ea}div.editor-root div.editor-content div[data-block-type=text][block-padding-level="1"]{padding-left:24px}div.editor-root div.editor-content div[data-block-type=text][block-padding-level="1"]>div[data-type=block-content]{position:relative}div.editor-root div.editor-content div[data-block-type=text][block-padding-level="2"]{padding-left:48px}div.editor-root div.editor-content div[data-block-type=text][block-padding-level="2"]>div[data-type=block-content]{position:relative}div.editor-root div.editor-content div[data-block-type=text][block-padding-level="3"]{padding-left:72px}div.editor-root div.editor-content div[data-block-type=text][block-padding-level="3"]>div[data-type=block-content]{position:relative}div.editor-root div.editor-content div[data-block-type=text][block-padding-level="4"]{padding-left:96px}div.editor-root div.editor-content div[data-block-type=text][block-padding-level="4"]>div[data-type=block-content]{position:relative}div.editor-root div.editor-content div[data-block-type=text][block-padding-level="5"]{padding-left:120px}div.editor-root div.editor-content div[data-block-type=text][block-padding-level="5"]>div[data-type=block-content]{position:relative}div.editor-root div.editor-content div[data-block-type=text][block-padding-level="6"]{padding-left:144px}div.editor-root div.editor-content div[data-block-type=text][block-padding-level="6"]>div[data-type=block-content]{position:relative}div.editor-root div.editor-content div[data-block-type=text][block-padding-level="7"]{padding-left:168px}div.editor-root div.editor-content div[data-block-type=text][block-padding-level="7"]>div[data-type=block-content]{position:relative}div.editor-root div.editor-content div[data-block-type=text][block-padding-level="8"]{padding-left:192px}div.editor-root div.editor-content div[data-block-type=text][block-padding-level="8"]>div[data-type=block-content]{position:relative}div.editor-root div.editor-content div[data-block-type=text][block-padding-level="9"]{padding-left:216px}div.editor-root div.editor-content div[data-block-type=text][block-padding-level="9"]>div[data-type=block-content]{position:relative}div.editor-root div.editor-content div[data-block-type=text][block-padding-level="10"]{padding-left:240px}div.editor-root div.editor-content div[data-block-type=text][block-padding-level="10"]>div[data-type=block-content]{position:relative}div.editor-root div.editor-content div[data-block-type=text][block-padding-level="11"]{padding-left:264px}div.editor-root div.editor-content div[data-block-type=text][block-padding-level="11"]>div[data-type=block-content]{position:relative}div.editor-root div.editor-content div[data-block-type=text][block-padding-level="12"]{padding-left:288px}div.editor-root div.editor-content div[data-block-type=text][block-padding-level="12"]>div[data-type=block-content]{position:relative}:root{--mindmap-bg-color: #f0f2f4}.editor-root [data-type=editor-container].root div[data-type=editor-block].list-block.focused [data-type=block-tools] .editor-mindmap-svg{border-radius:3px;outline:1px solid #338FE5}.editor-root [data-type=editor-container].root div[data-type=editor-block].list-block.editor-in-mindmap-first{height:600px;min-width:150px}.editor-root [data-type=editor-container].root div[data-type=editor-block].list-block [data-type=block-content]{margin-right:24px;transition:background-color .25s linear}.editor-root [data-type=editor-container].root div[data-type=editor-block].list-block [data-type=block-tools] .editor-mindmap-svg{position:absolute;left:0;top:0;right:0;bottom:0;z-index:2;font-size:14px;background-color:var(--mindmap-bg-color)}.editor-root [data-type=editor-container].root div[data-type=editor-block].list-block [data-type=block-tools] .mindmap-toolbar{position:absolute;top:8px;right:8px;height:24px;z-index:3}.editor-root [data-type=editor-container].root div[data-type=editor-block].list-block [data-type=block-tools] .mindmap-toolbar .editor-button.mindmap-button{background-color:transparent;outline:none;border:none;fill:none;color:#c1c1c1;cursor:pointer;min-width:initial;margin-right:0}.editor-root [data-type=editor-container].root div[data-type=editor-block].list-block [data-type=block-tools] .mindmap-toolbar .editor-button.mindmap-button:hover{color:#5587f0}.editor-root [data-type=editor-container].root div[data-type=editor-block].list-block.to-mindmap-highlight [data-type=block-content],.editor-root [data-type=editor-container].root div[data-type=editor-block].list-block.to-mindmap-highlight:hover [data-type=block-content]{background-color:#eaf3fc}.editor-root [data-type=editor-container].root div[data-type=editor-block].list-block .list-to-mindmap-wrap,.editor-root [data-type=editor-container].root div[data-type=editor-block].list-block .mention-button-wrap{position:absolute;right:0;top:2px;display:flex;align-items:center}.editor-root [data-type=editor-container].root div[data-type=editor-block].list-block .list-to-mindmap-wrap .button-sizer,.editor-root [data-type=editor-container].root div[data-type=editor-block].list-block .mention-button-wrap .button-sizer{width:0;opacity:0;pointer-events:none}.editor-root [data-type=editor-container].root div[data-type=editor-block].list-block button[data-button-id=list-to-mindmap],.editor-root [data-type=editor-container].root div[data-type=editor-block].list-block button[data-button-id=list-block-mention]{flex-grow:0;flex-shrink:0;width:24px;height:24px;min-width:24px;min-height:24px;padding:0;border:0;outline:0;display:flex;align-items:center;justify-content:end;background-color:transparent;color:#07142a}.editor-root [data-type=editor-container].root div[data-type=editor-block].list-block button[data-button-id=list-to-mindmap] svg,.editor-root [data-type=editor-container].root div[data-type=editor-block].list-block button[data-button-id=list-block-mention] svg{width:16px;height:16px}.editor-root [data-type=editor-container].root div[data-type=editor-block].list-block button[data-button-id=list-block-mention]:hover>svg{cursor:initial;background-color:#eee}.editor-root [data-type=editor-container].root div[data-type=editor-block].list-block button+button[data-button-id=list-block-mention]{right:20px}div.editor-root div.editor-content div[data-block-type=list][data-list-level="1"]{padding-left:0}div.editor-root div.editor-content div[data-block-type=list][data-list-level="2"]{padding-left:24px}div.editor-root div.editor-content div[data-block-type=list][data-list-level="3"]{padding-left:48px}div.editor-root div.editor-content div[data-block-type=list][data-list-level="4"]{padding-left:72px}div.editor-root div.editor-content div[data-block-type=list][data-list-level="5"]{padding-left:96px}div.editor-root div.editor-content div[data-block-type=list][data-list-level="6"]{padding-left:120px}div.editor-root div.editor-content div[data-block-type=list][data-list-level="7"]{padding-left:144px}div.editor-root div.editor-content div[data-block-type=list][data-list-level="8"]{padding-left:168px}div.editor-root div.editor-content div[data-block-type=list][data-list-level="9"]{padding-left:192px}div.editor-root div.editor-content div[data-block-type=list][data-list-level="10"]{padding-left:216px}div.editor-root div.editor-content div[data-block-type=list][data-list-level="11"]{padding-left:240px}div.editor-root div.editor-content div[data-block-type=list][data-list-level="12"]{padding-left:264px}.editor-root [data-type=editor-container].root div[data-type=editor-block].list-block+div[data-type=editor-block].list-block{margin-top:0}.editor-root [data-type=editor-container].root div[data-type=editor-block].list-block{display:flex;padding-bottom:2px;padding-top:2px}.editor-root [data-type=editor-container].root div[data-type=editor-block].list-block[data-list-type=text-only] .list-container{pointer-events:none}.editor-root [data-type=editor-container].root div[data-type=editor-block].list-block[data-list-type=checked] div[data-type=block-content] span.text{color:#c7c7c7}.editor-root [data-type=editor-container].root div[data-type=editor-block].list-block [data-type=block-content]{position:relative;flex-grow:1;padding-left:2px;margin-right:29px}.editor-root [data-type=editor-container].root div[data-type=editor-block].list-block .list-container{display:flex;min-width:24px;align-items:center;justify-content:center;flex-shrink:0;border-radius:3px;height:calc(var(--font-size) * var(--line-height))}.editor-root [data-type=editor-container].root div[data-type=editor-block].list-block .list-container .list-marker{min-width:16px;border:none;background-color:transparent;outline:none;display:flex;align-items:center;justify-content:flex-end;padding:0;overflow:visible;color:var(--primary-color);font-size:var(--font-size)}.editor-root [data-type=editor-container].root div[data-type=editor-block].list-block div[data-type=block-tools] .block-helper{top:2px}.editor-root.readonly button[data-button-id=mindmap-close]{display:none}.editor-root:not(.readonly) div[data-type=editor-block].list-block.active [data-type=block-content],.editor-root:not(.readonly) div[data-type=editor-block].list-block.hover [data-type=block-content]{background-color:#f4f4f4}.editor-root:not(.readonly) div[data-type=editor-block].list-block.active [data-type=block-content] .list-container,.editor-root:not(.readonly) div[data-type=editor-block].list-block.hover [data-type=block-content] .list-container{cursor:pointer}.editor-root:not(.readonly) div[data-type=editor-block].list-block .list-container:hover .list-marker{cursor:pointer}.editor-root:not(.readonly) div[data-type=editor-block].list-block:not([data-list-type=unchecked]):not([data-list-type=checked]) .list-container:hover{background-color:var(--background-selection)}.editor-root:not(.readonly) div[data-type=editor-block].list-block[data-list-type=unchecked] .list-container:hover .list-marker svg>*{fill:var(--background-selection)}[data-tippy-root] .customize-start-panel{max-width:350px;padding:0 16px;color:#333;font-size:14px;line-height:21px;user-select:none;background-color:#fff!important}[data-tippy-root] .customize-start-panel-input{width:64px;margin:0 8px;border:1px solid #CFD6E1;height:24px;border-radius:3px;padding:1px 0 1px 8px;outline:none;color:inherit;background-color:#fff}[data-tippy-root] .customize-start-panel-button{min-width:40px;font-size:12px;min-height:30px;margin:0 8px 0 0;background-color:var(--primary-color);color:#fff;outline:none;border:none;padding:4px 8px;border-radius:4px;cursor:pointer}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span.math-box{display:inline-flex}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content]>span.math-box .mathjax-tex-text.mathjax-error{color:var(--color-0)}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content] img.mathjax{max-width:100%}div.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-embed-type=math]>div[data-type=block-content]{align-items:center;justify-content:center;min-height:40px}div.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-embed-type=math]>div[data-type=block-content] img{margin:auto;padding:8px}.mathjax-editor-textarea{border:none;outline:none;width:400px;height:128px}.editor-text-button{border:0;color:var(--text-button-color, #c1c1c1);background-color:var(--text-button-bg-color, transparent);cursor:pointer;border-radius:var(--editor-border-radius, 3px);font-size:14px;padding:1px 6px;display:flex;align-items:center}.editor-text-button:hover{color:var(--text-button-color-hover, #5587F0);background-color:var(--text-button-bg-color-hover, transparent)}div[data-type=editor-block].table-block{--table-bar-width: 6px;--table-bar-left: -6px;--table-bar-top: -6px}div[data-type=editor-block].table-block>div[data-type=block-content]{position:relative;left:-26px}div[data-type=editor-block].table-block.locked-by-self>[data-type=block-content]:after,div[data-type=editor-block].table-block.locked-by-others>[data-type=block-content]:after{display:none}div[data-type=editor-block].table-block.locked-by-self>[data-type=block-content] div[data-type=table-content],div[data-type=editor-block].table-block.locked-by-others>[data-type=block-content] div[data-type=table-content]{position:relative}div[data-type=editor-block].table-block.locked-by-self>[data-type=block-content] div[data-type=table-content]:after,div[data-type=editor-block].table-block.locked-by-others>[data-type=block-content] div[data-type=table-content]:after{content:" ";position:absolute;left:0;top:0;right:0;bottom:0;pointer-events:none;z-index:1;background-color:#303030;opacity:.1}div[data-type=editor-block].table-block div[data-type=table-tools] .table-resize-gripper{position:absolute;background-color:transparent;cursor:col-resize;padding:0 2px}div[data-type=editor-block].table-block div[data-type=table-tools] .table-resize-gripper>.table-resize-gripper-indicator{pointer-events:none;background-color:var(--primary-color);width:100%;height:100%}div[data-type=editor-block].table-block div[data-type=table-tools] .table-border-bar-container{position:absolute;background-color:transparent;z-index:10}div[data-type=editor-block].table-block div[data-type=table-tools] .table-border-bar-container.top{left:var(--table-bar-left);top:var(--table-bar-top);right:0;height:var(--table-bar-width);flex-direction:row}div[data-type=editor-block].table-block div[data-type=table-tools] .table-border-bar-container.left{top:0;left:var(--table-bar-left);width:var(--table-bar-width);bottom:0;flex-direction:column}div[data-type=editor-block].table-block div[data-type=table-tools] .table-border-bar-container .table-border-bar{position:absolute;left:0;top:0;right:0;bottom:0;cursor:pointer;display:flex}div[data-type=editor-block].table-block div[data-type=table-tools] .table-border-bar-container .table-border-bar.left{flex-direction:column}div[data-type=editor-block].table-block div[data-type=table-tools] .table-border-bar-container .table-border-bar .table-border-bar-cell{background-color:#e8e8e8;position:relative;flex-grow:0;flex-shrink:0}div[data-type=editor-block].table-block div[data-type=table-tools] .table-border-bar-container .table-border-bar .table-border-bar-cell.corner{width:var(--table-bar-width)}div[data-type=editor-block].table-block div[data-type=table-tools] .table-border-bar-container .table-border-bar .table-border-bar-cell.top{height:100%}div[data-type=editor-block].table-block div[data-type=table-tools] .table-border-bar-container .table-border-bar .table-border-bar-cell:hover{background-color:#dedede}div[data-type=editor-block].table-block div[data-type=table-tools] .table-border-bar-container .table-border-bar .table-border-bar-cell.selected{background-color:var(--primary-color)}div[data-type=editor-block].table-block div[data-type=table-tools] .table-border-bar-container .table-border-bar .table-border-bar-cell.danger{background-color:#e52727}div[data-type=editor-block].table-block div[data-type=table-tools] .table-border-bar-container .table-border-bar .button-root{position:relative}div[data-type=editor-block].table-block div[data-type=table-tools] .table-border-bar-container .table-border-bar .button-root.top{max-width:0;width:0;overflow:visible}div[data-type=editor-block].table-block div[data-type=table-tools] .table-border-bar-container .table-border-bar .button-root.top:last-child{margin-left:-2px}div[data-type=editor-block].table-block div[data-type=table-tools] .table-border-bar-container .table-border-bar .button-root.left{max-height:0;height:0;overflow:visible}div[data-type=editor-block].table-block div[data-type=table-tools] .table-border-bar-container .table-border-bar .button-root.left:last-child{margin-top:-2px}div[data-type=editor-block].table-block div[data-type=table-tools] .table-border-bar-container .table-border-bar .button-root .button-container{position:absolute;width:26px;height:26px;display:flex;align-items:center;justify-content:center;z-index:1}div[data-type=editor-block].table-block div[data-type=table-tools] .table-border-bar-container .table-border-bar .button-root .button-container.top{right:-14px;top:-22px}div[data-type=editor-block].table-block div[data-type=table-tools] .table-border-bar-container .table-border-bar .button-root .button-container.left{transform:rotate(270deg);left:-22px;bottom:-14px}div[data-type=editor-block].table-block div[data-type=table-tools] .table-border-bar-container .table-border-bar .button-root .button-container .insert-indicator{position:absolute;width:3px;height:3px;background:#e8e8e8;border-radius:50%;margin-top:6px}div[data-type=editor-block].table-block div[data-type=table-tools] .table-border-bar-container .table-border-bar .button-root .button-container:hover .insert-indicator{display:none}div[data-type=editor-block].table-block div[data-type=table-tools] .table-border-bar-container .table-border-bar .button-root .button-container:hover .insert-column-button{display:unset}div[data-type=editor-block].table-block div[data-type=table-tools] .table-border-bar-container .table-border-bar .button-root .button-container:hover .insert-column-button span.icon{margin-top:2px}div[data-type=editor-block].table-block div[data-type=table-tools] .table-border-bar-container .table-border-bar .button-root .button-container:hover .drop-marker{opacity:1;transform:scale(.7)}div[data-type=editor-block].table-block div[data-type=table-tools] .table-border-bar-container .table-border-bar .button-root .button-container .drop-marker{width:26px;height:26px;border-radius:3px;background:var(--primary-color);cursor:pointer;opacity:0;transform:scale(.4);transition:transform .2s ease-in,opacity .2s ease-in}div[data-type=editor-block].table-block div[data-type=table-tools] .table-border-bar-container .table-border-bar .button-root .button-container .drop-marker:after{content:"";display:block;width:10px;height:1px;background-color:#fff;position:absolute;left:50%;top:50%;transform:translate(-50%,-50%)}div[data-type=editor-block].table-block div[data-type=table-tools] .table-border-bar-container .table-border-bar .button-root .button-container .drop-marker:before{content:"";display:block;width:1px;height:10px;background-color:#fff;position:absolute;left:50%;top:50%;transform:translate(-50%,-50%)}div[data-type=editor-block].table-block div[data-type=table-tools] .editor-table-chart{padding-top:16px}div[data-type=editor-block].table-block div[data-type=table-content]{position:relative}div[data-type=editor-block].table-block div[data-type=table-content] .error{color:red;border:1px solid red;padding:8px}div[data-type=editor-block].table-block div[data-type=table-content]>table{border-collapse:collapse;width:max-content;border-spacing:0}div[data-type=editor-block].table-block div[data-type=table-content]>table colgroup col{min-width:40px}div[data-type=editor-block].table-block div[data-type=table-content]>table,div[data-type=editor-block].table-block div[data-type=table-content]>table td,div[data-type=editor-block].table-block div[data-type=table-content]>table th{border:1px solid #c7c7c7;background-color:transparent}div[data-type=editor-block].table-block div[data-type=table-content]>table tr td.danger{background-color:#fce9e9!important}div[data-type=editor-block].table-block div[data-type=table-content]>table td{min-width:40px;padding:0;position:relative}div[data-type=editor-block].table-block div[data-type=table-content]>table td .table-cell-menu-btn{display:none;position:absolute;right:2px;top:2px;padding:0;width:16px;height:16px;border:none;border-radius:3px;background:#eaf3fc;color:#338fe5;cursor:pointer;transform:rotate(0);transition:transform .2s}div[data-type=editor-block].table-block div[data-type=table-content]>table td .table-cell-menu-btn.active{transform:rotate(180deg)}div[data-type=editor-block].table-block div[data-type=table-content]>table td>div[data-type=editor-container].child{padding:8px}div[data-type=editor-block].table-block div[data-type=table-content]>table td>div[data-type=editor-container].child div[data-type=editor-block].table-block>div[data-type=block-content]{pointer-events:none}div[data-type=editor-block].table-block div[data-type=table-content]>table td>div[data-type=editor-container].child div[data-type=editor-block].table-block>div[data-type=block-content] div[data-type=table-content]{pointer-events:auto}div[data-type=editor-block].table-block div[data-type=table-content]>table td.style-bg-color-0{background-color:var(--background-color-0)}div[data-type=editor-block].table-block div[data-type=table-content]>table td.style-bg-color-1{background-color:var(--background-color-1)}div[data-type=editor-block].table-block div[data-type=table-content]>table td.style-bg-color-2{background-color:var(--background-color-2)}div[data-type=editor-block].table-block div[data-type=table-content]>table td.style-bg-color-3{background-color:var(--background-color-3)}div[data-type=editor-block].table-block div[data-type=table-content]>table td.style-bg-color-4{background-color:var(--background-color-4)}div[data-type=editor-block].table-block div[data-type=table-content]>table td.style-bg-color-5{background-color:var(--background-color-5)}div[data-type=editor-block].table-block div[data-type=table-content]>table td.style-bg-color-6{background-color:var(--background-color-6)}div[data-type=editor-block].table-block div[data-type=table-content]>table td.style-bg-color-7{background-color:var(--background-color-7)}div[data-type=editor-block].table-block div[data-type=table-content]>table td.style-bg-color-8{background-color:var(--background-color-8)}div[data-type=editor-block].table-block div[data-type=table-content]>table td.style-bg-color-9{background-color:var(--background-color-9)}div[data-type=editor-block].table-block div[data-type=table-content]>table td.style-bg-color-10{background-color:var(--background-color-10)}div[data-type=editor-block].table-block div[data-type=table-content]>table td.style-bg-color-11{background-color:var(--background-color-11)}div[data-type=editor-block].table-block div[data-type=table-content]>table td.style-bg-color-12{background-color:var(--background-color-12)}div[data-type=editor-block].table-block div[data-type=table-content]>table td.style-bg-color-13{background-color:var(--background-color-13)}div[data-type=editor-block].table-block div[data-type=table-content]>table td.style-bg-color-14{background-color:var(--background-color-14)}div[data-type=editor-block].table-block div[data-type=table-content]>table.row-title>tbody>tr:first-child>td,div[data-type=editor-block].table-block div[data-type=table-content]>table.col-title td.col-title-item{background-color:#f8f8f8}div[data-type=editor-block].table-block div[data-type=table-content]>table.stripe:not(.row-title)>tbody>tr:nth-of-type(2n),div[data-type=editor-block].table-block div[data-type=table-content]>table.stripe.row-title>tbody>tr:nth-of-type(2n + 1){background-color:#f5f8fb}div[data-type=editor-block].table-block div[data-type=table-content]>table.no-border,div[data-type=editor-block].table-block div[data-type=table-content]>.no-border>tbody>tr>td{border:1px dashed;border-color:transparent}div[data-type=editor-block].table-block.focused div[data-type=table-content]>table.no-border,div[data-type=editor-block].table-block.focused div[data-type=table-content]>table.no-border>tbody>tr>td,div[data-type=editor-block].table-block.child-focused div[data-type=table-content]>table.no-border,div[data-type=editor-block].table-block.child-focused div[data-type=table-content]>table.no-border>tbody>tr>td{border-color:#b9bfc8}div[data-type=editor-block].table-block.full-selected>div[data-type=block-content]>.scroll-container-root>.scroll-container>.scroll-area>div[data-type=table-content]>table{background-color:var(--background-selection)}div[data-type=editor-block].table-block div[data-type=table-content]>table tbody tr td.selected,div[data-type=editor-block].table-block div[data-type=table-content]>table.row-title tbody tr td.selected,div[data-type=editor-block].table-block div[data-type=table-content]>table.col-title tbody tr td.selected{background-color:var(--background-selection)}div[data-type=editor-block].table-block div[data-type=table-content]>table td div[data-type=editor-block].table-block div[data-type=table-content]>table{max-width:100%}.command-item.menu-item .table-creator{background-color:#fff;padding:0 5px}.command-item.menu-item .table-creator .table-creator-row{display:flex}.command-item.menu-item .table-creator .table-creator-row .table-creator-cell{width:16px;height:16px;margin:3px;border:solid 1px #ddd}.command-item.menu-item .table-creator .table-creator-row .table-creator-cell.active{background-color:#99c7f2}div.editor-root div.editor-content div[data-type=editor-container].root div[data-type=editor-block].table-block{margin-top:0}div.tippy-box[data-theme=menu] .tippy-content div[data-id=cell-background-color]{width:100%}div.tippy-box[data-theme=menu] .tippy-content div[data-id=cell-background-color] .bar-desc{display:none}div.tippy-box[data-theme=menu] .tippy-content div[data-id=cell-background-color] .cell-background-color-item{box-sizing:border-box;width:100%;height:32px;padding:5px 10px;display:flex;align-items:center;justify-content:space-between;color:var(--text-color)}div.tippy-box[data-theme=menu] .tippy-content div[data-id=cell-background-color] .cell-background-color-item .item-sub-indicator{display:flex;align-items:center;margin-left:5px}div.tippy-box[data-theme=menu] .tippy-content div[data-id=cell-background-color] .cell-background-color-item .item-sub-indicator svg{height:16px;width:16px}div.tippy-box[data-theme=menu] .tippy-content div[data-id=cell-background-color] .cell-background-color-item .item-button{width:24px;height:24px;border:none;outline:none;cursor:pointer;border-radius:3px;position:relative;margin-left:auto}div.tippy-box[data-theme=menu] .tippy-content div[data-id=cell-background-color] .cell-background-color-item .item-button[data-color-index="-1"]{position:relative;background-color:#fff;border:1px solid #e8e8e8}div.tippy-box[data-theme=menu] .tippy-content div[data-id=cell-background-color] .cell-background-color-item .item-button[data-color-index="-1"]:after{transform:scale(1.2)}div.tippy-box[data-theme=menu] .tippy-content div[data-id=cell-background-color] .cell-background-color-item .item-button[data-color-index="-1"]:before{content:"";position:absolute;width:1px;height:56px;top:2px;left:22px;background-color:#c7c7c7;transform:rotate(45deg) scale(.5);transform-origin:-1px -2px}div.tippy-box[data-theme=menu] .tippy-content div[data-id=cell-background-color] .cell-background-color-item .item-button[data-color-index="0"]{background-color:var(--background-color-0)}div.tippy-box[data-theme=menu] .tippy-content div[data-id=cell-background-color] .cell-background-color-item .item-button[data-color-index="1"]{background-color:var(--background-color-1)}div.tippy-box[data-theme=menu] .tippy-content div[data-id=cell-background-color] .cell-background-color-item .item-button[data-color-index="2"]{background-color:var(--background-color-2)}div.tippy-box[data-theme=menu] .tippy-content div[data-id=cell-background-color] .cell-background-color-item .item-button[data-color-index="3"]{background-color:var(--background-color-3)}div.tippy-box[data-theme=menu] .tippy-content div[data-id=cell-background-color] .cell-background-color-item .item-button[data-color-index="4"]{background-color:var(--background-color-4)}div.tippy-box[data-theme=menu] .tippy-content div[data-id=cell-background-color] .cell-background-color-item .item-button[data-color-index="5"]{background-color:var(--background-color-5)}div.tippy-box[data-theme=menu] .tippy-content div[data-id=cell-background-color] .cell-background-color-item .item-button[data-color-index="6"]{background-color:var(--background-color-6)}div.tippy-box[data-theme=menu] .tippy-content div[data-id=cell-background-color] .cell-background-color-item .item-button[data-color-index="7"]{background-color:var(--background-color-7)}div.tippy-box[data-theme=menu] .tippy-content div[data-id=cell-background-color] .cell-background-color-item .item-button[data-color-index="8"]{background-color:var(--background-color-8)}div.tippy-box[data-theme=menu] .tippy-content div[data-id=cell-background-color] .cell-background-color-item .item-button[data-color-index="9"]{background-color:var(--background-color-9)}div.tippy-box[data-theme=menu] .tippy-content div[data-id=cell-background-color] .cell-background-color-item .item-button[data-color-index="10"]{background-color:var(--background-color-10)}div.tippy-box[data-theme=menu] .tippy-content div[data-id=cell-background-color] .cell-background-color-item .item-button[data-color-index="11"]{background-color:var(--background-color-11)}div.tippy-box[data-theme=menu] .tippy-content div[data-id=cell-background-color] .cell-background-color-item .item-button[data-color-index="12"]{background-color:var(--background-color-12)}div.tippy-box[data-theme=menu] .tippy-content div[data-id=cell-background-color] .cell-background-color-item .item-button[data-color-index="13"]{background-color:var(--background-color-13)}div.tippy-box[data-theme=menu] .tippy-content div[data-id=cell-background-color] .cell-background-color-item .item-button[data-color-index="14"]{background-color:var(--background-color-14)}div.editor-root div.editor-content div[data-type=editor-container].root.select-all>.container-blocks>div[data-type=editor-block][data-block-type=table]{background-color:transparent}div.editor-root div.editor-content div[data-type=editor-container].root.select-all>.container-blocks>div[data-type=editor-block][data-block-type=table] table.row-title>tbody>tr:first-child>td,div.editor-root div.editor-content div[data-type=editor-container].root.select-all>.container-blocks>div[data-type=editor-block][data-block-type=table] table.col-title td.col-title-item{background-color:transparent}div.editor-root div.editor-content div[data-type=editor-container].root.select-all>.container-blocks>div[data-type=editor-block][data-block-type=table] table.stripe:not(.row-title)>tbody>tr:nth-of-type(2n),div.editor-root div.editor-content div[data-type=editor-container].root.select-all>.container-blocks>div[data-type=editor-block][data-block-type=table] table.stripe.row-title>tbody>tr:nth-of-type(2n + 1){background-color:transparent}div.editor-root div.editor-content div[data-type=editor-block] [data-type=block-tools] .block-resizer{position:absolute;background-color:transparent;border:1px solid #338FE5;pointer-events:none;z-index:1;display:none}div.editor-root div.editor-content div[data-type=editor-block] [data-type=block-tools] .block-resizer.active{display:block}div.editor-root div.editor-content div[data-type=editor-block] [data-type=block-tools] .block-resizer .resize-gripper{position:absolute;width:16px;height:16px;border:2px solid white;background-color:#338fe5;border-radius:50%;pointer-events:all}div.editor-root div.editor-content div[data-type=editor-block] [data-type=block-tools] .block-resizer .resize-gripper.bottom{left:calc(50% - 8px);bottom:-8px;cursor:ns-resize}div.editor-root div.editor-content div[data-type=editor-block] [data-type=block-tools] .block-resizer .resize-gripper.top-left{left:-8px;top:-8px;cursor:nwse-resize}div.editor-root div.editor-content div[data-type=editor-block] [data-type=block-tools] .block-resizer .resize-gripper.top-right{right:-8px;top:-8px;cursor:nesw-resize}div.editor-root div.editor-content div[data-type=editor-block] [data-type=block-tools] .block-resizer .resize-gripper.bottom-left{left:-8px;bottom:-8px;cursor:nesw-resize}div.editor-root div.editor-content div[data-type=editor-block] [data-type=block-tools] .block-resizer .resize-gripper.bottom-right{right:-8px;bottom:-8px;cursor:nwse-resize}div.editor-root.readonly div.editor-content div[data-type=editor-block]>[data-type=block-tools] .block-resizer{display:none}.editor-dialog-container{min-width:500px;position:relative;left:-9px}.editor-dialog-container .dialog-header{display:flex;justify-content:space-between;align-items:center;padding:0 20px;border-bottom:1px solid #e8e8e8}.editor-dialog-container .dialog-header .close-icon{cursor:pointer}.editor-dialog-container .dialog-header .dialog-header-title{padding:8px 0 11px;font-size:18px;font-weight:700;flex-grow:1}.editor-dialog-container .dialog-content{padding:20px;border-bottom:1px solid #e8e8e8}.editor-dialog-container .dialog-footer{margin:10px 0 5px;padding:0 20px;text-align:right}.editor-dialog-container .dialog-footer button{min-width:58px;min-height:30px;padding:0 10px;border-radius:3px;background-color:#eef3f8;font-size:14px;color:#fff;cursor:pointer}.editor-dialog-container .dialog-footer .cancel-button{margin:0 8px 0 0;background-color:transparent;border:1px solid #c7c7c7;color:#606060}.editor-dialog-container .dialog-footer .cancel-button:hover{color:#303030;background:#eee;border:1px solid #c7c7c7}.editor-dialog-container .dialog-footer .submit-button{outline:none;background-color:#338fe5;color:#fff;border:0}.editor-dialog-container .dialog-footer .submit-button:hover{background-color:#5ca5ea}.embed-block[data-embed-type=webpage]{min-height:100px;max-height:1000px}.embed-block[data-embed-type=webpage] .webpage-mask{position:absolute;left:0;right:0;top:0;bottom:0;z-index:1;background-color:transparent}.embed-block[data-embed-type=webpage].resizing [data-type=block-tools] .block-resizer{pointer-events:all!important}.embed-block[data-embed-type=webpage].hover>div[data-type=block-content]{outline:none!important}.embed-block[data-embed-type=webpage].selected>div[data-type=block-content]{outline:none!important}.embed-block[data-embed-type=webpage]>div[data-type=block-content]{justify-content:center;height:100%}.embed-block[data-embed-type=webpage]>div[data-type=block-content]>.editor-embed{width:100%}.embed-block[data-embed-type=webpage]>div[data-type=block-content]>.editor-embed .editor-preview-iframe{width:100%;max-height:500px;height:100%;border:none;position:relative}.embed-block[data-embed-type=webpage]>div[data-type=block-content]>.editor-embed .editor-preview-iframe-loading{position:absolute;top:0;left:0;bottom:0;right:0;display:flex;justify-content:center;align-items:center;background-color:#fff}.webpage-content .help-container{color:#303030;border:1px solid #dedede;padding:10px;border-radius:4px;border-left:4px solid #338fe5;margin-top:16px;margin-bottom:16px}.webpage-content .help-container .help-content{display:flex;align-items:center}.webpage-content .help-container .help-content .help-icon{color:#338fe5;margin-right:12px}.webpage-content .help-link-container{margin-top:8px;display:flex;align-items:center}.webpage-content .help-link-container .help-link-content{display:flex;align-items:center;color:#338fe5;text-decoration:none}.webpage-content .help-link-container .help-link-content .help-link-icon{width:16px;height:16px;margin-left:8px}div.editor-root div.editor-content div[data-type=editor-container].root.select-all>.container-blocks>div[data-type=editor-block][data-embed-type=webpage]>div[data-type=block-content]:before{display:block}div.editor-root:not(.readonly) div.editor-content div[data-type=editor-container] div[data-type=editor-block] [data-type=block-content][data-title-placeholder]:before{position:absolute;left:0;top:0;right:0;bottom:0;content:attr(data-title-placeholder);color:#c7c7c7}div.editor-root:not(.readonly) div.editor-content div[data-type=editor-container] div[data-type=editor-block] [data-type=block-content][data-content-placeholder]:before{position:absolute;left:0;top:0;right:0;bottom:0;content:attr(data-content-placeholder);color:#c7c7c7;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;display:flex;align-items:center}div.editor-root:not(.readonly) div.editor-content div[data-type=editor-container] div[data-type=editor-block] [data-type=block-tools] .block-placeholder-container{position:absolute;left:0;top:0;right:0}div.editor-root.readonly div.editor-content div[data-type=editor-container] div[data-type=editor-block] [data-type=block-content][data-title-placeholder]:before{position:absolute;left:0;top:0;right:0;bottom:0;content:attr(data-title-placeholder-readonly);color:#c7c7c7}.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block{min-width:360px;counter-reset:code-line}.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block.full-selected{background-color:var(--background-selection)}.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block.editing-language div[data-type=block-tools] .code-block-header,.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block.child-focused div[data-type=block-tools] .code-block-header,.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block:hover div[data-type=block-tools] .code-block-header{opacity:1}.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block.wrap>div[data-type=block-tools] .code-block-header button[data-id=wrap] *{color:var(--primary-color)}.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block:not(.wrap)>div[data-type=block-content] div[data-type=editor-container].child{overflow-x:auto}.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block:not(.wrap)>div[data-type=block-content] div[data-type=editor-container].child div[data-type=block-content]{word-break:keep-all;overflow:visible}.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block:not(.wrap)>div[data-type=block-content] div[data-type=editor-container].child div[data-type=block-content]>span.text{white-space:pre}.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-tools] .code-block-header{opacity:0;transition:opacity .3s ease-in 0s;position:absolute;top:0;display:flex;padding-left:16px;padding-right:4px;align-items:center;left:0;right:0;height:32px}.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-tools] .code-block-header .language-select{font-size:14px;color:#999;cursor:pointer;display:flex;align-items:center}.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-tools] .code-block-header .language-select .arrow-icon{width:16px;height:16px}.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-tools] .code-block-header .code-header-spacer{flex-grow:1}.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-tools] .code-block-header .code-header-button{display:flex;justify-content:center;align-items:center;height:24px;background:#ddd;border:none;border-radius:2px;margin-left:4px;cursor:pointer}.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-tools] .code-block-header .code-header-button .button-icon{width:16px;height:16px;display:flex;align-items:center;justify-content:center}.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-tools] .code-block-header .code-header-button .button-label{margin-left:4px;font-size:14px}.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block.full-selected>div[data-type=block-content]>div.editor-code-root>div.code-text-root{background-color:unset}.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-text-root{background-color:var(--background-code)}.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-text-root>div.child[data-type=editor-container]{padding-left:32px;padding-top:32px;padding-bottom:24px}.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-text-root>div.child[data-type=editor-container].selected{background-color:var(--background-selection)}.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-text-root>div.child[data-type=editor-container] *{font-family:Consolas,Monaco,Andale Mono,Ubuntu Mono,monospace;font-size:14px}.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-text-root>div.child[data-type=editor-container] div.text-block+div.text-block{margin-top:4px}.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-text-root>div.child[data-type=editor-container] div.text-block:before{content:counter(code-line);counter-increment:code-line;position:absolute;left:-48px;top:10px;z-index:1;margin-top:-6px;display:block;width:48px;padding-right:8px;text-align:right;color:#aaa;box-sizing:border-box;font-size:12px;font-weight:400;line-height:12px;letter-spacing:0;white-space:nowrap;opacity:1}.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-text-root>div.child[data-type=editor-container] div.text-block>div[data-type=block-content] span.style-code-comment,.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-text-root>div.child[data-type=editor-container] div.text-block>div[data-type=block-content] span.style-code-prolog,.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-text-root>div.child[data-type=editor-container] div.text-block>div[data-type=block-content] span.style-code-doctype,.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-text-root>div.child[data-type=editor-container] div.text-block>div[data-type=block-content] span.style-code-cdata{color:#708090}.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-text-root>div.child[data-type=editor-container] div.text-block>div[data-type=block-content] span.style-code-punctuation{color:#999}.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-text-root>div.child[data-type=editor-container] div.text-block>div[data-type=block-content] span.style-code-namespace{opacity:.7}.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-text-root>div.child[data-type=editor-container] div.text-block>div[data-type=block-content] span.style-code-property,.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-text-root>div.child[data-type=editor-container] div.text-block>div[data-type=block-content] span.style-code-tag,.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-text-root>div.child[data-type=editor-container] div.text-block>div[data-type=block-content] span.style-code-boolean,.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-text-root>div.child[data-type=editor-container] div.text-block>div[data-type=block-content] span.style-code-number,.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-text-root>div.child[data-type=editor-container] div.text-block>div[data-type=block-content] span.style-code-constant,.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-text-root>div.child[data-type=editor-container] div.text-block>div[data-type=block-content] span.style-code-symbol,.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-text-root>div.child[data-type=editor-container] div.text-block>div[data-type=block-content] span.style-code-deleted{color:#905}.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-text-root>div.child[data-type=editor-container] div.text-block>div[data-type=block-content] span.style-code-selector,.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-text-root>div.child[data-type=editor-container] div.text-block>div[data-type=block-content] span.style-code-attr-name,.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-text-root>div.child[data-type=editor-container] div.text-block>div[data-type=block-content] span.style-code-string,.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-text-root>div.child[data-type=editor-container] div.text-block>div[data-type=block-content] span.style-code-char,.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-text-root>div.child[data-type=editor-container] div.text-block>div[data-type=block-content] span.style-code-builtin,.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-text-root>div.child[data-type=editor-container] div.text-block>div[data-type=block-content] span.style-code-inserted{color:#690}.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-text-root>div.child[data-type=editor-container] div.text-block>div[data-type=block-content] span.style-code-operator,.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-text-root>div.child[data-type=editor-container] div.text-block>div[data-type=block-content] span.style-code-entity,.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-text-root>div.child[data-type=editor-container] div.text-block>div[data-type=block-content] span.style-code-url,.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-text-root>div.child[data-type=editor-container] div.text-block>div[data-type=block-content] span.style-code-string{color:#9a6e3a}.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-text-root>div.child[data-type=editor-container] div.text-block>div[data-type=block-content] span.style-code-atrule,.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-text-root>div.child[data-type=editor-container] div.text-block>div[data-type=block-content] span.style-code-attr-value,.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-text-root>div.child[data-type=editor-container] div.text-block>div[data-type=block-content] span.style-code-keyword{color:#07a}.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-text-root>div.child[data-type=editor-container] div.text-block>div[data-type=block-content] span.style-code-function,.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-text-root>div.child[data-type=editor-container] div.text-block>div[data-type=block-content] span.style-code-class-name{color:#dd4a68}.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-text-root>div.child[data-type=editor-container] div.text-block>div[data-type=block-content] span.style-code-regex,.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-text-root>div.child[data-type=editor-container] div.text-block>div[data-type=block-content] span.style-code-important,.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-text-root>div.child[data-type=editor-container] div.text-block>div[data-type=block-content] span.style-code-variable{color:#e90}.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-text-root>div.child[data-type=editor-container] div.text-block>div[data-type=block-content] span.style-code-important,.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-text-root>div.child[data-type=editor-container] div.text-block>div[data-type=block-content] span.style-code-bold{font-weight:700}.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-text-root>div.child[data-type=editor-container] div.text-block>div[data-type=block-content] span.style-code-italic{font-style:italic}.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-text-root>div.child[data-type=editor-container] div.text-block>div[data-type=block-content] span.style-code-entity{cursor:help}.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-caption-root{padding:8px}.editor-root [data-type=editor-container].root div[data-type=editor-block].code-block>div[data-type=block-content]>div.editor-code-root>div.code-caption-root *{color:#aaa}div.editor-root div.editor-content div[data-type=editor-container].root.select-all div[data-type=block-content]>div.editor-code-root>div.code-text-root{background-color:unset}.before-content,.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image].selected [data-type=block-content] .images .image-container.active:before,.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image].selected:not(.focused) [data-type=block-content] .images .image-container:before{content:" ";position:absolute;left:0;top:0;right:0;bottom:0;pointer-events:none;z-index:1;background-color:#338fe5;opacity:.1}.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image]{display:flex}.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image][data-style-align=left]{justify-content:flex-start}.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image][data-style-align=right]{justify-content:flex-end}.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image].hover [data-type=block-content]{outline:none}.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image].hover [data-type=block-content] .images .image-container.empty:hover,.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image].hover [data-type=block-content] .images .image-container.error:hover{outline:1px solid #338FE5}.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image].selected [data-type=block-content]:before{display:none}.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image].selected [data-type=block-content]{outline:none}.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image].multi [data-type=block-tools] .block-resizer{display:none}.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image]:not(.multi) [data-type=block-content] .images.empty{min-height:400px}.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image] [data-type=block-content]{cursor:default}.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image] [data-type=block-content] .images{width:100%;display:flex;align-items:flex-start}.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image] [data-type=block-content] .images .image-splitter{width:10px;flex-grow:0;flex-shrink:0;padding:0 4px;cursor:col-resize;height:100%}.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image] [data-type=block-content] .images .image-splitter .image-splitter-indicator{width:100%;height:100%}.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image] [data-type=block-content] .images .image-splitter:active .image-splitter-indicator,.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image] [data-type=block-content] .images .image-splitter:hover .image-splitter-indicator{background-color:#d9d9d9}.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image] [data-type=block-content] .images .image-container{position:relative;flex:1;background-color:#f8f8f8;display:flex;min-height:inherit}.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image] [data-type=block-content] .images .image-container img{max-width:100%;width:100%;height:auto}.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image] [data-type=block-content] .images .image-container.empty .upload-image-icon{color:#c7c7c7}.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image] [data-type=block-content] .images .image-container.error{height:100%;outline:1px solid #DEDEDE;border-radius:3px}.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image] [data-type=block-content] .images .image-container.error img{display:none}.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image] [data-type=block-content] .images .image-container .load-error,.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image] [data-type=block-content] .images .image-container .upload-error{position:absolute;left:0;top:0;right:0;bottom:0;display:flex;flex-direction:column;align-items:center;justify-content:center;z-index:1}.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image] [data-type=block-content] .images .image-container .load-error .error-icon,.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image] [data-type=block-content] .images .image-container .upload-error .error-icon{color:#c7c7c7}.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image] [data-type=block-content] .images .image-container .load-error .error-message,.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image] [data-type=block-content] .images .image-container .upload-error .error-message{display:flex;flex-direction:column;align-items:center;overflow:hidden}.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image] [data-type=block-content] .images .image-container .load-error .error-message .line-1,.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image] [data-type=block-content] .images .image-container .upload-error .error-message .line-1{margin-top:10px;font-size:18px;font-weight:500;color:#303030;height:26px;vertical-align:middle;line-height:26px;white-space:nowrap;text-overflow:ellipsis;overflow:hidden;flex-shrink:0}.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image] [data-type=block-content] .images .image-container .load-error .error-message .line-2,.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image] [data-type=block-content] .images .image-container .load-error .error-message .line-3,.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image] [data-type=block-content] .images .image-container .upload-error .error-message .line-2,.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image] [data-type=block-content] .images .image-container .upload-error .error-message .line-3{font-size:14px;color:#606060;vertical-align:middle;height:22px;line-height:22px;white-space:nowrap;text-overflow:ellipsis;overflow:hidden;flex-shrink:0}.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image] [data-type=block-content] .images .image-container .load-error .error-message .line-2 a,.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image] [data-type=block-content] .images .image-container .load-error .error-message .line-3 a,.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image] [data-type=block-content] .images .image-container .upload-error .error-message .line-2 a,.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image] [data-type=block-content] .images .image-container .upload-error .error-message .line-3 a{text-decoration:none;color:#338fe5}.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image] [data-type=block-content] .images .image-container .load-error .line-3 a{display:inline-flex;align-items:center;text-decoration:none}.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image] [data-type=block-content] .images .image-container .load-error .line-3 a:after{content:" ";display:inline-block;width:16px;height:16px;margin-left:5px;background-image:url("data:image/svg+xml,%3Csvg width='17' height='16' viewBox='0 0 17 16' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M6.5 2H3.5C2.94772 2 2.5 2.44772 2.5 3V13C2.5 13.5523 2.94772 14 3.5 14H13.5C14.0523 14 14.5 13.5523 14.5 13V10' stroke='%23338FE5'/%3E%3Cpath d='M14.5 2L9 7.5' stroke='%23338FE5'/%3E%3Cpath d='M8.5 2H14.5V8' stroke='%23338FE5'/%3E%3C/svg%3E%0A")}.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image] [data-type=block-content] .images .image-container .uploading-progress-mask{position:absolute;top:0;left:0;right:0;bottom:0;background-color:#303030;opacity:.8;display:flex;align-items:center;justify-content:center}.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image] [data-type=block-content] .images .image-container .uploading-progress-mask .uploading-progress-bar{width:75%;height:6px;border-radius:3px;display:flex;background-color:#fff}.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image] [data-type=block-content] .images .image-container .uploading-progress-mask .uploading-progress-bar .uploading-progress-bar-value{background-color:#338fe5}.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image] [data-type=block-content] .images .image-container .image-warning{position:absolute;right:5px;top:5px;color:#fff;background-color:#f8f8f8;width:24px;height:24px;display:flex;align-items:center;justify-content:center;border-radius:3px;z-index:2}.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image] [data-type=block-content] .images .image-container.empty{display:flex;flex-direction:column;align-items:center;outline:1px solid #DEDEDE;border-radius:3px;justify-content:center}.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image] [data-type=block-content] .images .image-container.empty svg{width:64px;height:64px}.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image] [data-type=block-tools] .drag-container{display:flex;box-sizing:content-box;pointer-events:none;position:fixed;z-index:100;background-color:#fff;border:1px solid #338FE5}.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-type=editor-block][data-embed-type=image] [data-type=block-tools] .drag-container .drag-target{width:100%}.editor-root[readonly=true] .image-splitter{visibility:hidden}.editor-root .editor-content div[data-type=editor-block].dragging div[data-type=block-tools] .block-helper{opacity:0}.editor-root .editor-content div[data-type=editor-block] div[data-type=block-tools] .block-helper{position:absolute;right:100%;top:0;padding-right:8px;display:flex;align-items:center}.editor-root .editor-content div[data-type=editor-block] div[data-type=block-tools] .block-helper .helper-sizer{width:0;opacity:0;pointer-events:none}div[data-type=editor-block].locked-by-self>[data-type=block-content],div[data-type=editor-block].locked-by-others>[data-type=block-content]{position:relative}div[data-type=editor-block].locked-by-self>[data-type=block-content]:after,div[data-type=editor-block].locked-by-others>[data-type=block-content]:after{content:" ";position:absolute;left:0;top:0;right:0;bottom:0;pointer-events:none;z-index:1;background-color:#303030;opacity:.1}div[data-type=editor-block].locked-by-self.text-block>[data-type=block-content]:after,div[data-type=editor-block].locked-by-others.text-block>[data-type=block-content]:after{outline:2px solid #303030}.editor-root{--selected-color: #e8e8e8}.editor-root .editor-content .editor-drop-indicator{position:absolute;background-color:var(--primary-color);pointer-events:none;transition:top .2s linear,left .2s linear,width .2s linear}.editor-root .editor-content div[data-type=editor-block].text-block.highlighted{outline:2px solid var(--background-selection);background-color:var(--background-selection)}.editor-root .editor-content div[data-type=editor-block] div[data-type=block-tools] .block-helper .block-button{width:24px;height:24px;cursor:grab;margin:0;padding:0;display:flex;align-items:center;justify-content:center;background-color:transparent;border:none;border-radius:3px}.editor-root .editor-content div[data-type=editor-block] div[data-type=block-tools] .block-helper .block-button:hover{background-color:var(--selected-color)}.editor-root .editor-content div[data-type=editor-block] div[data-type=block-tools] .block-helper .block-button svg{width:16px;height:16px;color:#909090}.drag-image-container{position:fixed;z-index:100;box-shadow:0 3px 20px #00000026;background-color:#fff;opacity:.4}.drag-image-container.drag-placeholder{width:500px;height:200px;border:1px solid #dedede;border-radius:3px;background:#e8e8e8}.drag-image-container .drag-image{width:100%;display:none}.drag-image-container[data-status=loaded] .drag-image{display:block}.drag-image-container[data-status=loaded] .drag-loading{display:none}.editor-command-bar-root .editor-command-bar .command-item.menu-item{display:flex;align-items:center;flex:none}.editor-command-bar-root .editor-command-bar .command-item.menu-item .text-styles{padding:5px 10px;background-color:#fff}.editor-command-bar-root .editor-command-bar .command-item.menu-item .text-styles .text-style-section+.text-style-section{margin-top:5px}.editor-command-bar-root .editor-command-bar .command-item.menu-item .text-styles .text-style-section{display:flex;flex-wrap:wrap}.editor-command-bar-root .editor-command-bar .command-item.menu-item .text-styles .text-style-section .style-icon{width:24px;height:24px;padding:0;margin:0 5px 0 0;display:flex;align-items:center;justify-content:center;background-color:transparent;border:none;outline:none;cursor:pointer;border-radius:3px;color:#606060}.editor-command-bar-root .editor-command-bar .command-item.menu-item .text-styles .text-style-section .style-icon:hover{background-color:var(--selected-color)}.editor-command-bar-root .editor-command-bar .command-item.menu-item .text-styles .text-style-section .style-icon.active{color:#338fe5}:root{--editor-quoted-color: #7084a4;--editor-drawio-empty-svg: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNDgiIGhlaWdodD0iNDgiIHZpZXdCb3g9IjAgMCA0OCA0OCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0zOC43MjAzIDI4LjcwOTdIMjUuOTIzM0MyNS4yMTY1IDI4LjcwOTcgMjQuNjQzNSAyOC4xNDgxIDI0LjY0MzUgMjcuNDU1MlYyNS43MzMzSDIwLjUyODNDMjAuNDk4NiAyNS43Njk2IDIwLjQ2NjkgMjUuODA0MiAyMC40MzMzIDI1LjgzN0wxNS45MTkyIDMwLjI2MjFWMzQuNzU1NkgyNC42NDM1VjMzLjcyNzZDMjQuNjQzNSAzMy4wMzQ4IDI1LjIxNjUgMzIuNDczMiAyNS45MjMzIDMyLjQ3MzJIMzguNzIwM0MzOS40MjcgMzIuNDczMiA0MCAzMy4wMzQ4IDQwIDMzLjcyNzZWMzguNzQ1NUM0MCAzOS40MzgzIDM5LjQyNyA0MCAzOC43MjAzIDQwSDI1LjkyMzNDMjUuMjE2NSA0MCAyNC42NDM1IDM5LjQzODMgMjQuNjQzNSAzOC43NDU1VjM3LjMzMzNIMTQuNjI2M0MxMy45MTIyIDM3LjMzMzMgMTMuMzMzMyAzNi43NTYyIDEzLjMzMzMgMzYuMDQ0NFYzMC42OTQxTDguMzc4NTIgMjUuODM3QzguMTM2MjYgMjUuNjAxNCA4IDI1LjI4MDggOCAyNC45NDYzQzggMjQuNjExOCA4LjEzNjI2IDI0LjI5MTEgOC4zNzg1MiAyNC4wNTU2TDEzLjMzMzMgMTkuMTk4NVYxNS43NzJDMTEuNzc5OCAxNS4yMjI5IDEwLjY2NjcgMTMuNzQxNiAxMC42NjY3IDEyQzEwLjY2NjcgOS43OTA4NSAxMi40NTc1IDggMTQuNjY2NyA4QzE2Ljg3NTggOCAxOC42NjY2IDkuNzkwODUgMTguNjY2NiAxMkMxOC42NjY2IDEzLjcyNjUgMTcuNTU4OCAxNS4yNTgxIDE1LjkxOTEgMTUuNzk4OFYxOS4yODg4QzE1LjkxOTEgMTkuMzkxOCAxNS45MDY4IDE5LjQ5NDMgMTUuODgyMyAxOS41OTQzTDE5LjUxNTEgMjMuMTU1NUgyNC42NDM1VjIyLjQzNzNDMjQuNjQzNSAyMS43NDQ1IDI1LjIxNjUgMjEuMTgyOSAyNS45MjMzIDIxLjE4MjlIMzguNzIwM0MzOS40MjcgMjEuMTgyOSA0MCAyMS43NDQ1IDQwIDIyLjQzNzNWMjcuNDU1MkM0MCAyOC4xNDgxIDM5LjQyNyAyOC43MDk3IDM4LjcyMDMgMjguNzA5N1pNMjcuMjAzIDM3LjQ5MUgzNy40NDA2VjM0Ljk4MjFIMjcuMjAzVjM3LjQ5MVpNMTQuNDA1OSAyOC4xOTU0TDExLjA5MTUgMjQuOTQ2M0wxNC40MDU5IDIxLjY5NzJMMTcuNzIwNCAyNC45NDYzTDE0LjQwNTkgMjguMTk1NFpNMjcuMjAzIDI2LjIwMDhIMzcuNDQwNlYyMy42OTE4SDI3LjIwM1YyNi4yMDA4WiIgZmlsbD0iIzA3MTQyQSIvPgo8L3N2Zz4K)}.flex-center,.editor-drawio-iframe-container.loading:before,.embed-block .editor-empty-drawio.editor-drawio-content.editor-embed:after,.embed-block .editor-empty-drawio.editor-drawio-content.editor-embed:before{display:flex;align-items:center;justify-content:center}.full-screen,.editor-drawio-iframe-container.loading:before,.drawio-iframe-element,.editor-drawio-iframe-container{width:100%;height:100%}.editor-drawio-iframe-container{position:fixed;top:0;left:0;z-index:1000}div[data-type=editor-block].embed-block[data-embed-type=drawio]>div[data-type=block-content]{outline:1px solid #dedede}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block].embed-block[data-embed-type=drawio]>div[data-type=block-content]{justify-content:center;border-radius:3px;padding:10px}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block].embed-block[data-embed-type=drawio]>div[data-type=block-content] .editor-drawio-content{text-align:center}.embed-block .editor-empty-drawio.editor-drawio-content.editor-embed{width:240px;height:80px;display:inline-block;text-align:center}.embed-block .editor-empty-drawio.editor-drawio-content.editor-embed:before{background-image:var(--editor-drawio-empty-svg);position:absolute;content:" ";color:var(--editor-quoted-color);top:8px;left:calc(50% - 24px);width:48px;height:48px}.embed-block .editor-empty-drawio.editor-drawio-content.editor-embed:after{position:absolute;content:attr(data-empty-drawio-content);color:var(--editor-quoted-color);bottom:0;left:0;width:100%;height:32px;top:50%}div.editor-root div.editor-content div[data-type=editor-container] div[data-embed-type=drawio].embed-block>div[data-type=block-content] img{max-width:100%;height:auto}.editor-drawio-iframe-container.loading:before{content:attr(data-placeholder);position:absolute;top:0;left:0;background-color:#f7f6f3;z-index:2}.editor-content .editing{background-color:#cdcdcd40}.editor-content div[data-type=block-tools] .embed-code-editor-container{position:absolute;top:0;left:0px;right:0px;bottom:0;background-color:#cdcdcd40;z-index:var(--wiz-editor-z-embed-code-editor-mask);padding:8px}.editor-content div[data-type=block-tools] .embed-code-editor-container textarea{width:100%;height:100%;resize:none;outline:none;padding:12px;border:1px solid #b9bfc8;border-radius:4px;background-color:#fff;color:#333}.flex-row-center,.embed-block div[data-type=block-content] .graph-embed,div[data-embed-type=mermaid] div[data-type=block-content] .graph-embed,div[data-embed-type=flowchart] div[data-type=block-content] .graph-embed,div[data-embed-type=plantuml] div[data-type=block-content] .graph-embed,.embed-block div[data-type=block-content] .invalid-code:not(.empty-embed),div[data-embed-type=mermaid] div[data-type=block-content] .invalid-code:not(.empty-embed),div[data-embed-type=flowchart] div[data-type=block-content] .invalid-code:not(.empty-embed),div[data-embed-type=plantuml] div[data-type=block-content] .invalid-code:not(.empty-embed),.embed-block div[data-type=block-content] .empty-embed:after,div[data-embed-type=mermaid] div[data-type=block-content] .empty-embed:after,div[data-embed-type=flowchart] div[data-type=block-content] .empty-embed:after,div[data-embed-type=plantuml] div[data-type=block-content] .empty-embed:after,.embed-block,div[data-embed-type=mermaid],div[data-embed-type=flowchart],div[data-embed-type=plantuml]{display:flex;flex-direction:row;align-items:center;justify-content:center}.embed-block div[data-type=block-content],div[data-embed-type=mermaid] div[data-type=block-content],.embed-block div[data-type=block-content],div[data-embed-type=flowchart] div[data-type=block-content],.embed-block div[data-type=block-content],div[data-embed-type=plantuml] div[data-type=block-content]{width:100%;position:relative}.embed-block div[data-type=block-content] .empty-embed,div[data-embed-type=mermaid] div[data-type=block-content] .empty-embed,.embed-block div[data-type=block-content] .empty-embed,div[data-embed-type=flowchart] div[data-type=block-content] .empty-embed,.embed-block div[data-type=block-content] .empty-embed,div[data-embed-type=plantuml] div[data-type=block-content] .empty-embed{width:100%;min-height:106px;background-color:#cdcdcd40}.embed-block div[data-type=block-content] .empty-embed:after,div[data-embed-type=mermaid] div[data-type=block-content] .empty-embed:after,.embed-block div[data-type=block-content] .empty-embed:after,div[data-embed-type=flowchart] div[data-type=block-content] .empty-embed:after,.embed-block div[data-type=block-content] .empty-embed:after,div[data-embed-type=plantuml] div[data-type=block-content] .empty-embed:after{content:attr(data-empty-tips);position:absolute;top:0;right:0;width:100%;height:100%;color:#07142a;white-space:nowrap}.embed-block div[data-type=block-content] .invalid-code:not(.empty-embed),div[data-embed-type=mermaid] div[data-type=block-content] .invalid-code:not(.empty-embed),.embed-block div[data-type=block-content] .invalid-code:not(.empty-embed),div[data-embed-type=flowchart] div[data-type=block-content] .invalid-code:not(.empty-embed),.embed-block div[data-type=block-content] .invalid-code:not(.empty-embed),div[data-embed-type=plantuml] div[data-type=block-content] .invalid-code:not(.empty-embed){width:100%;height:100px}.embed-block div[data-type=block-content] .invalid-code:not(.empty-embed) img,div[data-embed-type=mermaid] div[data-type=block-content] .invalid-code:not(.empty-embed) img,.embed-block div[data-type=block-content] .invalid-code:not(.empty-embed) img,div[data-embed-type=flowchart] div[data-type=block-content] .invalid-code:not(.empty-embed) img,.embed-block div[data-type=block-content] .invalid-code:not(.empty-embed) img,div[data-embed-type=plantuml] div[data-type=block-content] .invalid-code:not(.empty-embed) img{display:none}.embed-block div[data-type=block-content] .invalid-code:not(.empty-embed):after,div[data-embed-type=mermaid] div[data-type=block-content] .invalid-code:not(.empty-embed):after,.embed-block div[data-type=block-content] .invalid-code:not(.empty-embed):after,div[data-embed-type=flowchart] div[data-type=block-content] .invalid-code:not(.empty-embed):after,.embed-block div[data-type=block-content] .invalid-code:not(.empty-embed):after,div[data-embed-type=plantuml] div[data-type=block-content] .invalid-code:not(.empty-embed):after{content:attr(data-invalid-text);position:absolute;top:0;right:0;width:100%;height:100%;outline:1px solid red;display:flex;flex-direction:row;align-items:center;justify-content:center;color:red}.embed-block div[data-type=block-content] .embed-img-content,div[data-embed-type=mermaid] div[data-type=block-content] .embed-img-content,.embed-block div[data-type=block-content] .embed-img-content,div[data-embed-type=flowchart] div[data-type=block-content] .embed-img-content,.embed-block div[data-type=block-content] .embed-img-content,div[data-embed-type=plantuml] div[data-type=block-content] .embed-img-content{width:100%;text-align:center}.embed-block div[data-type=block-content] .mermaid-embed-img,div[data-embed-type=mermaid] div[data-type=block-content] .mermaid-embed-img,.embed-block div[data-type=block-content] .mermaid-embed-img,div[data-embed-type=flowchart] div[data-type=block-content] .mermaid-embed-img,.embed-block div[data-type=block-content] .mermaid-embed-img,div[data-embed-type=plantuml] div[data-type=block-content] .mermaid-embed-img{max-width:100%;min-width:200px}.embed-block div[data-type=block-content] .editor-plantuml-img,div[data-embed-type=mermaid] div[data-type=block-content] .editor-plantuml-img,.embed-block div[data-type=block-content] .editor-plantuml-img,div[data-embed-type=flowchart] div[data-type=block-content] .editor-plantuml-img,.embed-block div[data-type=block-content] .editor-plantuml-img,div[data-embed-type=plantuml] div[data-type=block-content] .editor-plantuml-img{max-width:100%}.embed-block div[data-type=block-content] .embed-graph-img-content,div[data-embed-type=mermaid] div[data-type=block-content] .embed-graph-img-content,.embed-block div[data-type=block-content] .embed-graph-img-content,div[data-embed-type=flowchart] div[data-type=block-content] .embed-graph-img-content,.embed-block div[data-type=block-content] .embed-graph-img-content,div[data-embed-type=plantuml] div[data-type=block-content] .embed-graph-img-content{width:100%;text-align:center;padding:10px}.embed-block div[data-type=block-content] .embed-graph-img-content img,div[data-embed-type=mermaid] div[data-type=block-content] .embed-graph-img-content img,.embed-block div[data-type=block-content] .embed-graph-img-content img,div[data-embed-type=flowchart] div[data-type=block-content] .embed-graph-img-content img,.embed-block div[data-type=block-content] .embed-graph-img-content img,div[data-embed-type=plantuml] div[data-type=block-content] .embed-graph-img-content img{max-width:100%}.embed-block div[data-type=block-content] .graph-embed,div[data-embed-type=mermaid] div[data-type=block-content] .graph-embed,.embed-block div[data-type=block-content] .graph-embed,div[data-embed-type=flowchart] div[data-type=block-content] .graph-embed,.embed-block div[data-type=block-content] .graph-embed,div[data-embed-type=plantuml] div[data-type=block-content] .graph-embed{width:100%}.hr-transition,.embed-block div[data-type=block-content] .editor-embed-container .editor-embed-hr{transition:border-top ease-in-out .4s}.embed-block div[data-type=block-content] .editor-embed-container{display:flex;align-items:center;width:100%}.embed-block div[data-type=block-content] .editor-embed-container .editor-embed-hr{display:block;width:100%;border:none;margin:0;border-top:2px dashed #cccccc;cursor:pointer}.embed-block:is(.focused) div[data-type=block-content] .editor-embed-container .editor-embed-hr{caret-color:transparent}.embed-block[data-type=editor-block][data-embed-type=hr]>div[data-type=block-content] .editor-embed-container{height:30px}.embed-block[data-type=editor-block][data-embed-type=hr].hover>div[data-type=block-content]{outline:none!important}.embed-block[data-type=editor-block][data-embed-type=hr].selected>div[data-type=block-content]{outline:none!important}.editor-root .editor-content div[data-type=editor-block] div[data-type=block-tools] .block-anchor[data-id=paste-special-button-anchor]{z-index:unset}[data-command-bar-id=paste-special-button] .editor-command-bar.toolbar{padding:0}[data-command-bar-id=paste-special-button] .editor-command-bar.toolbar .command-item[data-dropdown=true]{padding-left:5px;padding-right:5px}.editor-find-dialog{--popover-input-border: 1px solid #CFD6E1;--editor-find-dialog-input-container-border-color: #CFD6E1;--editor-find-dialog-input-container-bg-color: transparent;--editor-border-radius-big: 3px;--editor-color: #07142A;--button-black-text-color: #333;--editor-find-dialog-button-color: #333;--editor-find-dialog-icon-button-color: #333;--editor-find-dialog-button-border-bg-color: rgba(255, 255, 255, .56);--editor-find-dialog-input-placeholder-color: #b9bfc8;--editor-find-dialog-button-disabled-color: #ccc !important;--editor-find-dialog-button-hover-color: rgba(150, 150, 150, .2);--editor-find-dialog-button-border: solid 1px #ccc;box-sizing:border-box;width:400px;background-color:var(--editor-find-dialog-bg-color);border:var(--editor-find-dialog-border);border-radius:var(--editor-border-radius-big);display:flex;padding:8px 8px 0 16px;align-items:flex-start;font-size:14px;font-family:var(--editor-font-family)}.editor-find-dialog .editor-find-content{display:flex;flex-direction:column;flex-grow:1;font-family:inherit}.editor-find-dialog .editor-find-dialog-row{display:flex;margin-bottom:8px;align-items:center}.editor-find-dialog .editor-find-dialog-label{width:80px;flex-grow:0;flex-shrink:0;align-self:center}.editor-find-dialog .editor-find-dialog-input-container{border:var(--popover-input-border);border-color:var(--editor-find-dialog-input-container-border-color);background-color:var(--editor-find-dialog-input-container-bg-color);border-radius:var(--editor-border-radius-big);flex-grow:1;display:flex;padding:2px;align-items:center;height:32px;box-sizing:border-box}.editor-find-dialog .editor-find-dialog-input{border:none;flex-grow:1;width:80px;outline:none;background-color:transparent;color:var(--editor-color)}.editor-find-dialog .editor-find-dialog-input::placeholder{color:var(--editor-find-dialog-input-placeholder-color);opacity:1}.editor-find-dialog .editor-find-dialog-prev{width:24px}.editor-find-dialog .editor-find-dialog-curr{flex-grow:0;text-align:center;flex-shrink:1;display:flex;align-items:center;margin-bottom:2px}.editor-find-dialog .editor-find-dialog-next{width:24px}.editor-find-dialog .editor-find-dialog-icon-button{cursor:pointer;border-radius:4px;color:var(--editor-find-dialog-icon-button-color);background-color:var(--editor-find-dialog-button-border-bg-color);border:none;display:flex;padding:0}.editor-find-dialog .editor-find-dialog-button{padding:6px 16px;cursor:pointer;border-radius:4px;color:var(--editor-find-dialog-button-color);background-color:var(--editor-find-dialog-button-border-bg-color);margin:0 4px;border:none;font-family:inherit;line-height:21px}.editor-find-dialog .editor-find-dialog-button.icon-button{width:32px;height:32px}.editor-find-dialog .editor-find-dialog-button.active,.editor-find-dialog .editor-find-dialog-button:hover{background-color:var(--editor-find-dialog-button-hover-color)}.editor-find-dialog .editor-find-dialog-button:disabled{color:var(--editor-find-dialog-button-disabled-color);cursor:default}.editor-find-dialog .editor-find-dialog-button:disabled:hover{background-color:transparent}.editor-find-dialog .editor-find-dialog-button svg{fill:currentColor}.editor-find-dialog .editor-find-dialog-space{flex-grow:1}.editor-find-dialog .editor-find-dialog-icon-button-border{margin:0 0 0 8px;cursor:pointer;border-radius:4px;color:var(--button-black-text-color);border:var(--editor-find-dialog-button-border);background-color:var(--editor-find-dialog-button-border-bg-color);padding:0;width:32px;display:flex;justify-content:center;align-items:center}.editor-find-dialog .editor-find-dialog-button-close{margin:0 0 0 8px;cursor:pointer;border-radius:4px;color:var(--button-black-text-color);background-color:var(--editor-find-dialog-button-border-bg-color);border:none;padding:0;width:32px;height:32px;display:flex;justify-content:center;align-items:center}.editor-find-dialog .editor-find-dialog-icon-button-border svg,.editor-find-dialog .editor-find-dialog-button-close svg{fill:currentColor}.editor-find-dialog .editor-highlight{opacity:.6;pointer-events:none}.editor-find-dialog .editor-highlight .editor-highlight-child{position:absolute;background-color:bisque}.editor-find-dialog .editor-highlight.active .editor-highlight-child{position:absolute;background-color:tomato}.editor-find-dialog .editor-search-result-highlight{opacity:.6;pointer-events:none}.editor-find-dialog .editor-search-result-highlight .editor-highlight-child{position:absolute;background-color:#40e0d0}.editor-find-dialog .editor-find-dialog-status{display:flex}.editor-highlight{opacity:.6;pointer-events:none}.editor-highlight .editor-highlight-child{position:absolute;background-color:bisque}.editor-highlight.active .editor-highlight-child{position:absolute;background-color:tomato}.editor-search-result-highlight{opacity:.6;pointer-events:none}.editor-search-result-highlight .editor-highlight-child{position:absolute;background-color:#40e0d0}.editor-find-dialog-status{display:flex}.comment-editor{font-size:14px;border:1px solid #c7c7c7;border-radius:3px;padding:1px 10px;margin:6px 10px 0}.comment-editor:after{content:"";height:0;display:block;clear:both}.comment-editor-root{display:inline-block;min-width:calc(100% - 40px);padding-top:2px}.comment-editor-root .editor-root .editor-content{padding:0}.comment-editor-img{float:right;color:#c1c1c1;padding:0}.comment-editor-root:not(.comment-editor-readonly) .editor-root .editor-content [data-type=editor-block]:not([data-block-type=text]){width:248px}.comment-editor-editing{border:1px solid #338fe5}.comment-editor-readonly{border:none;padding-left:37px;margin:0}.comment-editor-readonly .comment-editor-img{display:none}.comment-item-root{position:relative;margin-top:10px}.comment-item-root:not(.last-comment-item):before{content:" ";display:block;position:absolute;left:20px;width:1px;background-color:var(--editor-border-color, #e8e8e8);overflow:hidden;opacity:.8;top:21px;bottom:-12px;transform:scaleX(.5)}.comment-item-root .item-head{padding:0 10px;position:relative;display:flex;align-items:center}.comment-item-root .item-head-avatar{margin-right:5px;width:var(--editor-comment-avatar-width, 21px);height:var(--editor-comment-avatar-width, 21px);border-radius:100%}.comment-item-root .item-head-username{font-size:var(--editor-comment-username-font-size, 12px);color:var(--editor-comment-username-color, #07142a);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.comment-item-root .item-head-modified{margin-left:8px;font-size:12px;color:var(--editor-comment-modified-color, #808080);flex-grow:1;white-space:nowrap}.comment-item-root .item-head-tools{display:flex;align-items:center;visibility:hidden}.comment-item-root .item-head-tools .editor-text-button svg{width:20px;height:20px}.comment-item-root .item-head-tools.active{visibility:visible}.comment-item-root .item-actions{margin-top:10px;display:flex;justify-content:flex-end}.comment-item-root .item-actions.hidden{display:none}.comment-item-root .item-actions .editor-button[data-button-id=comment-item-cancel]{color:#606060;background:transparent;border:1px solid #c7c7c7}.comment-item-root .item-actions .editor-button[data-button-id=comment-item-cancel]:hover{color:#303030;background:#eee;border:1px solid #c7c7c7}.comment-item-root .item-actions .editor-button.disabled[data-button-id=comment-item-ok]{color:#fff;background-color:#338fe580;cursor:default}.comment-item-root:hover:not(.comment-item-editing) .item-head-tools{visibility:visible}.comment-item-root.readonly .item-head-tools{display:none}.mobile-comment-item{margin-top:4px;background-color:var(--editor-comment-layer-bg-color);padding-bottom:20px;color:var(--editor-comment-username-color)}.mobile-comment-item .item-head{padding:12px;display:flex;align-items:center}.mobile-comment-item .item-head-avatar{width:var(--editor-comment-avatar-size);height:var(--editor-comment-avatar-size);flex-grow:0}.mobile-comment-item .item-head-username{margin-left:12px}.mobile-comment-item .item-head-modified{margin-left:12px;color:#999}.mobile-comment-item .item-editor .comment-editor-readonly{padding-left:18px}.mini-comment-item{position:relative;line-height:16px;width:20px;height:16px;text-align:center;font-size:12px;border-radius:1px;background-color:var(--editor-comment-active-color, #FFC328);color:var(--editor-comment-mini-text-color, #ffffff);cursor:pointer}.mini-comment-item:after{content:"";position:absolute;left:50%;bottom:-4px;width:6px;height:6px;background-color:var(--editor-comment-active-color, #FFC328);border-radius:1px;transform:matrix(.71,.61,.82,-.71,0,0) translate(-50%);z-index:-1}.comment-quick-reply .quick-reply-button{position:absolute;left:8px;bottom:3px;z-index:2;color:var(--editor-comment-quick-reply-color, #7084A4);font-size:12px}.comment-quick-reply .quick-reply-button.editor-text-button:hover{color:var(--text-button-color-hover, #5587F0);background-color:var(--text-button-bg-color-hover, transparent)}.comment-quick-reply .quick-reply-editor{display:none}.comment-quick-reply .quick-reply-editor .reply-editor-actions{display:flex;justify-content:flex-end;margin-top:10px}.comment-quick-reply .quick-reply-editor .reply-editor-actions .editor-button[data-button-id=quick-reply-cancel]{color:#606060;background:transparent;border:1px solid #c7c7c7}.comment-quick-reply .quick-reply-editor .reply-editor-actions .editor-button[data-button-id=quick-reply-cancel]:hover{color:#303030;background:#eee;border:1px solid #c7c7c7}.comment-quick-reply .quick-reply-editor .reply-editor-actions .editor-button.disabled[data-button-id=quick-reply-ok]{color:#fff;background-color:#338fe580;cursor:default}.comment-quick-reply.hidden,.comment-quick-reply.reply-editor-editing .quick-reply-button{display:none}.comment-quick-reply.reply-editor-editing .quick-reply-editor{display:block}:root{--editor-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Robot, "Helvetica Neue", Helvetica, Arial, sans-serif;--editor-comment-layer-bg-color:#ffffff;--editor-comment-group-bg-color: #ffffff;--comment-root-border-color: #eaeaea;--editor-comment-layer-active-border-color: #cecece;--editor-box-shadow: 0px 3px 20px rgba(0, 0, 0, .15);--wiz-editor-z-comment-group-active-top-before: 29;--editor-comment-quote-color: #909090;--editor-comment-quote-before-bg-color: #909090;--editor-comment-switch-button-width: 12px;--editor-comment-active-color: #FFC328;--editor-bg-color: #ffffff;--wiz-editor-z-comment-head:11;--text-button-color-hover:#5587f0;--editor-comment-username-color:#07142A;--editor-comment-avatar-size: 32px}.disabled-scroll{overflow:hidden}.editor-root .editor-content div[data-type=editor-block].text-block.comment span{border-bottom:2px solid #f8e6ab}.editor-root .editor-content div[data-type=editor-block].text-block.comment.active span{background-color:#f8e6ab}.editor-root .editor-content div[data-type=editor-block] span.text.comment{border-bottom:2px solid #f8e6ab}.editor-root .editor-content div[data-type=editor-block] span.text.comment.active{background-color:#f8e6ab}.editor-root .editor-content div[data-type=editor-block] div[data-type=block-tools] .block-comment-button{all:unset;position:absolute;right:-28px;top:0;width:24px;height:24px;display:flex;align-items:center;justify-content:center;padding:0;border-radius:3px;color:#07142a;cursor:pointer}.editor-root .editor-content div[data-type=editor-block] div[data-type=block-tools] .block-comment-button:hover{background:#eaeaea}.editor-web-comment-root{position:absolute;right:0;width:300px;top:0;bottom:0;transition:width .16s ease-in;will-change:width;font-family:var(--editor-font-family)}.editor-web-comment-root .comment-groups-container .comment-group-item-root{position:absolute;left:50%;right:0;width:290px;transform:translate(-50%);background-color:var(--editor-comment-group-bg-color);border-radius:2px;border-color:var(--editor-comment-layer-active-border-color);box-shadow:var(--editor-box-shadow);padding-bottom:18px}.editor-web-comment-root .comment-groups-container .comment-group-item-root:not(.no-animation){transition:top .2s ease-in,opacity .35s ease-in}.editor-web-comment-root .comment-groups-container .comment-group-item-root:before{content:"";position:absolute;left:0;right:0;height:6px;background-color:#fff;border-radius:2px 2px 0 0;z-index:var(--wiz-editor-z-comment-group-active-top-before)}.editor-web-comment-root .comment-groups-container .comment-group-item-root .comment-item-head{display:flex;align-items:center}.editor-web-comment-root .comment-groups-container .comment-group-item-root .comment-item-head .item-head-quote{font-size:12px;line-height:12px;height:12px;color:var(--editor-comment-quote-color);padding:18px 12px 10px;white-space:nowrap;text-overflow:ellipsis;overflow:hidden;width:100%;max-width:calc(100% - 80px)}.editor-web-comment-root .comment-groups-container .comment-group-item-root .comment-item-head .item-head-quote:before{content:"";display:block;width:2px;height:100%;background-color:var(--editor-comment-quote-before-bg-color);margin-right:6px;float:left;border-radius:10px}.editor-web-comment-root .comment-groups-container .comment-group-item-root .comment-item-head .item-head-switch{display:flex;align-items:center;height:22px;padding-top:6px;visibility:hidden}.editor-web-comment-root .comment-groups-container .comment-group-item-root .comment-item-head .item-head-switch .editor-text-button{padding:0;width:var(--editor-comment-switch-button-width);margin:3px 0;color:#606060}.editor-web-comment-root .comment-groups-container .comment-group-item-root .comment-item-head .item-head-switch .editor-text-button[data-button-id=switch-up]{margin-right:16px}.editor-web-comment-root .comment-groups-container .comment-group-item-root .comment-item-head .item-head-switch .editor-text-button:not(.disabled):hover{color:var(--text-button-color-hover)}.editor-web-comment-root .comment-groups-container .comment-group-item-root .comment-item-head .item-head-switch .editor-text-button.disabled{color:#60606080;cursor:not-allowed}.editor-web-comment-root .comment-groups-container .comment-group-item-root.active:before{background-color:var(--editor-comment-active-color)}.editor-web-comment-root .comment-groups-container .comment-group-item-root.active .item-head-switch{visibility:visible}.editor-web-comment-root .comment-groups-container .comment-group-item-root.readonly .comment-quick-reply{display:none}.editor-mobile-comments-root{position:fixed;left:0;right:0;bottom:0;top:0;overflow:hidden;z-index:11}.editor-mobile-comments-root .mobile-comment-mask{position:absolute;left:0;right:0;bottom:0;top:0;background-color:#00000073}.editor-mobile-comments-root .mobile-comment-groups-container{position:absolute;width:100%;height:100vh;z-index:1;overflow:hidden}.editor-mobile-comments-root .mobile-comment-groups-container .mobile-comment-groups-scroll-container{padding:0 12px}.editor-mobile-comments-root .mobile-comment-pull-info-container{position:absolute;right:0;left:0;bottom:100px;z-index:2;text-align:center;display:none}.editor-mobile-comments-root .mobile-comment-pull-info-container .mobile-comment-pull-info{display:inline-block;padding:12px;border-radius:36px;margin:0 auto;background-color:#000c;color:#fff;font-size:12px;opacity:0;transition:opacity .25s cubic-bezier(.65,.05,.36,1)}.editor-mobile-comments-root .mobile-comment-pull-info-container.active{display:block}.editor-mobile-comments-root .mobile-comment-pull-info-container.active .mobile-comment-pull-info{opacity:1}.editor-mobile-comments-root .mobile-group-item-root{margin:0 auto;width:100%;height:100vh;overflow:hidden}.editor-mobile-comments-root .mobile-group-item-root .mobile-group-item{min-height:calc(100vh + 1px);padding-bottom:50px}.editor-mobile-comments-root .mobile-group-item-root .mobile-group-item-space{height:50vh}.editor-mobile-comments-root .mobile-group-item-root .mobile-group-item-abstract{background-color:var(--editor-comment-layer-bg-color);padding:12px;color:#999;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.editor-mini-comment-root{position:absolute;right:0;top:0;bottom:0;width:48px;border-left:1px solid #f0f0f0;transition:width .16s ease-in;will-change:width;font-family:var(--editor-font-family);border:none;background-color:transparent;z-index:11}.editor-mini-comment-root .comment-groups-container{width:100%;height:100%}.editor-mini-comment-root .comment-groups-container .mini-group-item{position:absolute;top:0;left:50%;margin-left:-10px;transition:top .2s cubic-bezier(.65,.05,.36,1)}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content] [data-box-type=file] span[data-type=box-content]{margin:0}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content] [data-box-type=file] span[data-type=box-content] span.file-icon{display:inline-flex;vertical-align:text-bottom}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content] [data-box-type=file] span[data-type=box-content] .file-name{color:var(--primary-color);padding:0;border-radius:12px;margin-right:4px;white-space:wrap;word-break:break-all;cursor:pointer}div.editor-root div.editor-content div[data-type=editor-container] div.embed-block[data-type=editor-block][data-embed-type=office]{justify-content:start}div.editor-root div.editor-content div[data-type=editor-container] div.embed-block[data-type=editor-block][data-embed-type=office].hover [data-type=block-content]{border-radius:3px}div.editor-root div.editor-content div[data-type=editor-container] div.embed-block[data-type=editor-block][data-embed-type=office] [data-type=block-content]{width:unset;height:48px;cursor:pointer}div.editor-root div.editor-content div[data-type=editor-container] div.embed-block[data-type=editor-block][data-embed-type=office] [data-type=block-content] .card-root{display:flex;align-items:center;min-width:360px;max-width:100%;background-color:#f5f6f7;border-radius:3px}div.editor-root div.editor-content div[data-type=editor-container] div.embed-block[data-type=editor-block][data-embed-type=office] [data-type=block-content] .card-root:before{border-radius:3px}div.editor-root div.editor-content div[data-type=editor-container] div.embed-block[data-type=editor-block][data-embed-type=office] [data-type=block-content] .card-root .file-details{display:flex;flex-direction:column;justify-content:center;font-size:14px;flex-grow:1}div.editor-root div.editor-content div[data-type=editor-container] div.embed-block[data-type=editor-block][data-embed-type=office] [data-type=block-content] .card-root .file-details .file-name{color:#1f2329}div.editor-root div.editor-content div[data-type=editor-container] div.embed-block[data-type=editor-block][data-embed-type=office] [data-type=block-content] .card-root .file-details .file-size{color:#646a73;font-size:12px;margin-top:2px}div.editor-root div.editor-content div[data-type=editor-container] div.embed-block[data-type=editor-block][data-embed-type=office] [data-type=block-content] .card-root .file-actions button{width:34px;height:34px;background-color:#fff;border:1px solid #dee0e3;border-radius:50%;margin:0 8px;padding:0;background-repeat:no-repeat;background-position:50%;cursor:pointer;display:flex;align-items:center;justify-content:center;flex-shrink:0}div.editor-root div.editor-content div[data-type=editor-container] div.embed-block[data-type=editor-block][data-embed-type=office] [data-type=block-content] .card-root .file-actions button svg{width:16px;height:16px}div.editor-root div.editor-content div[data-type=editor-container] div.embed-block[data-type=editor-block][data-embed-type=office] [data-type=block-content] .card-root .file-icon{display:flex;width:36px;height:36px;margin:6px 6px 6px 12px}div.editor-root div.editor-content div[data-type=editor-container] div.embed-block[data-type=editor-block][data-embed-type=office] [data-type=block-content] .card-root .file-icon>svg{width:100%;height:100%}:root{--hover-color: #40a9ff}.flex-column-center,.embed-block[data-embed-type=video]>div[data-type=block-content] .media-empty,.embed-block[data-embed-type=audio]>div[data-type=block-content] .media-empty,.embed-block[data-embed-type=video]>div[data-type=block-content] .media-error,.embed-block[data-embed-type=audio]>div[data-type=block-content] .media-error{display:flex;justify-content:center;align-items:center;flex-flow:column}.common{width:400px;height:180px;background-color:#fafafa;border:1px dashed #d9d9d9;border-radius:2px;transition:border-color .3s}.embed-block[data-embed-type=audio]>div[data-type=block-content] .media-empty,.embed-block[data-embed-type=audio]>div[data-type=block-content] .media-error{height:200px}.embed-block[data-embed-type=video]>div[data-type=block-content] .media-empty,.embed-block[data-embed-type=video]>div[data-type=block-content] .media-error{height:400px}.embed-block[data-embed-type=video].locked-by-self>[data-type=block-content]:after,.embed-block[data-embed-type=video].locked-by-others>[data-type=block-content]:after,.embed-block[data-embed-type=audio].locked-by-self>[data-type=block-content]:after,.embed-block[data-embed-type=audio].locked-by-others>[data-type=block-content]:after{display:none}.embed-block[data-embed-type=video].locked-by-self>[data-type=block-content] .video-container,.embed-block[data-embed-type=video].locked-by-self>[data-type=block-content] .audio-container,.embed-block[data-embed-type=video].locked-by-others>[data-type=block-content] .video-container,.embed-block[data-embed-type=video].locked-by-others>[data-type=block-content] .audio-container,.embed-block[data-embed-type=audio].locked-by-self>[data-type=block-content] .video-container,.embed-block[data-embed-type=audio].locked-by-self>[data-type=block-content] .audio-container,.embed-block[data-embed-type=audio].locked-by-others>[data-type=block-content] .video-container,.embed-block[data-embed-type=audio].locked-by-others>[data-type=block-content] .audio-container{position:relative}.embed-block[data-embed-type=video].locked-by-self>[data-type=block-content] .video-container:after,.embed-block[data-embed-type=video].locked-by-self>[data-type=block-content] .audio-container:after,.embed-block[data-embed-type=video].locked-by-others>[data-type=block-content] .video-container:after,.embed-block[data-embed-type=video].locked-by-others>[data-type=block-content] .audio-container:after,.embed-block[data-embed-type=audio].locked-by-self>[data-type=block-content] .video-container:after,.embed-block[data-embed-type=audio].locked-by-self>[data-type=block-content] .audio-container:after,.embed-block[data-embed-type=audio].locked-by-others>[data-type=block-content] .video-container:after,.embed-block[data-embed-type=audio].locked-by-others>[data-type=block-content] .audio-container:after{content:" ";position:absolute;left:0;top:0;right:0;bottom:0;pointer-events:none;z-index:1;background-color:#303030;opacity:.1}.embed-block[data-embed-type=video].hover>div[data-type=block-content],.embed-block[data-embed-type=audio].hover>div[data-type=block-content]{outline:none!important}.embed-block[data-embed-type=video].selected>div[data-type=block-content]:before,.embed-block[data-embed-type=audio].selected>div[data-type=block-content]:before{display:none}.embed-block[data-embed-type=video]>div[data-type=block-content],.embed-block[data-embed-type=audio]>div[data-type=block-content]{justify-content:center;max-width:100%}.embed-block[data-embed-type=video]>div[data-type=block-content] .media,.embed-block[data-embed-type=audio]>div[data-type=block-content] .media{width:100%;display:flex;justify-content:center}.embed-block[data-embed-type=video]>div[data-type=block-content] .media-progress,.embed-block[data-embed-type=audio]>div[data-type=block-content] .media-progress{position:relative;max-width:100%}.embed-block[data-embed-type=video]>div[data-type=block-content] .media-progress audio,.embed-block[data-embed-type=audio]>div[data-type=block-content] .media-progress audio{display:block;width:100%}.embed-block[data-embed-type=video]>div[data-type=block-content] .media-progress video,.embed-block[data-embed-type=audio]>div[data-type=block-content] .media-progress video{display:block;max-width:100%}.embed-block[data-embed-type=video]>div[data-type=block-content] .media-progress .uploading-progress-mask,.embed-block[data-embed-type=audio]>div[data-type=block-content] .media-progress .uploading-progress-mask{position:absolute;top:0;left:0;right:0;bottom:0;background-color:#303030;opacity:.8;display:flex;align-items:center;justify-content:center}.embed-block[data-embed-type=video]>div[data-type=block-content] .media-progress .uploading-progress-mask .uploading-progress-bar,.embed-block[data-embed-type=audio]>div[data-type=block-content] .media-progress .uploading-progress-mask .uploading-progress-bar{width:75%;height:6px;border-radius:3px;display:flex;background-color:#fff;overflow:hidden}.embed-block[data-embed-type=video]>div[data-type=block-content] .media-progress .uploading-progress-mask .uploading-progress-bar .uploading-progress-bar-value,.embed-block[data-embed-type=audio]>div[data-type=block-content] .media-progress .uploading-progress-mask .uploading-progress-bar .uploading-progress-bar-value{background-color:#338fe5}.embed-block[data-embed-type=video]>div[data-type=block-content] .media-error,.embed-block[data-embed-type=audio]>div[data-type=block-content] .media-error{width:100%;background:#F8F8F8;outline:1px solid #DEDEDE;border-radius:3px}.embed-block[data-embed-type=video]>div[data-type=block-content] .media-error-icon svg,.embed-block[data-embed-type=audio]>div[data-type=block-content] .media-error-icon svg{width:48px;height:48px;color:#c7c7c7}.embed-block[data-embed-type=video]>div[data-type=block-content] .media-error .line-1,.embed-block[data-embed-type=audio]>div[data-type=block-content] .media-error .line-1{margin-top:10px;font-size:18px;text-align:center;color:#303030}.embed-block[data-embed-type=video]>div[data-type=block-content] .media-error .line-2,.embed-block[data-embed-type=audio]>div[data-type=block-content] .media-error .line-2{margin-top:5px;font-size:14px;text-align:center;color:#606060}.embed-block[data-embed-type=video]>div[data-type=block-content] .media-error a,.embed-block[data-embed-type=audio]>div[data-type=block-content] .media-error a{margin-left:4px;color:#338fe5;cursor:pointer;text-decoration:none}.embed-block[data-embed-type=video]>div[data-type=block-content] .media-empty,.embed-block[data-embed-type=audio]>div[data-type=block-content] .media-empty{width:100%;background:#FFFFFF;outline:1px solid #DEDEDE;border-radius:3px}.embed-block[data-embed-type=video]>div[data-type=block-content] .media-empty svg,.embed-block[data-embed-type=audio]>div[data-type=block-content] .media-empty svg{width:48px;height:48px;color:#c7c7c7}.embed-block[data-embed-type=video]>div[data-type=block-content] .media-element,.embed-block[data-embed-type=audio]>div[data-type=block-content] .media-element{width:100%;display:flex;justify-content:center}.embed-block[data-embed-type=video]>div[data-type=block-content] .media-element .video-container video,.embed-block[data-embed-type=audio]>div[data-type=block-content] .media-element .video-container video{display:block;min-width:50px;max-width:100%}.embed-block[data-embed-type=video]>div[data-type=block-content] .media-element .audio-container,.embed-block[data-embed-type=audio]>div[data-type=block-content] .media-element .audio-container{width:100%}.embed-block[data-embed-type=video]>div[data-type=block-content] .media-element .audio-container audio,.embed-block[data-embed-type=audio]>div[data-type=block-content] .media-element .audio-container audio{display:block;width:100%}:root{--editor-version-select-bg-color: green;--editor-version-button-border: black;--editor-bg-color: #ffffff;--editor-version-list-bg-color: #f5f8fb;--editor-version-select-bg-color: #dae6f2}.version-dialog{display:flex;background-color:var(--editor-bg-color);width:100%;height:100%;color:var(--editor-color);font-family:var(--font-family)}.version-dialog-note-viewer{flex:1;display:flex;flex-direction:column;width:0;padding:16px 32px 32px 16px}.version-dialog-note-viewer .dialog-button-text{margin-top:1px;margin-left:-4px}.version-dialog-action-container{height:48px;display:flex;align-items:center;justify-content:space-between;padding-bottom:16px;box-sizing:border-box}.version-dialog-note-viewer .dialog-text-button{outline:none;background:transparent;border:none;display:flex;align-items:center;color:var(--editor-color);font-size:16px;font-weight:500;padding:4px 0;cursor:pointer}.dialog-text-button .dialog-button-icon{margin-right:0;width:24px;height:24px}.dialog-text-button .dialog-button-icon svg{fill:currentColor}.dialog-version-button{outline:none;background:transparent;border:1px solid var(--editor-version-button-border);min-width:88px;height:32px;color:var(--editor-color);font-weight:500;padding:4px 0;border-radius:4px;font-size:16px;cursor:pointer}.dialog-version-button[disabled]{color:#7084a4;cursor:not-allowed;pointer-events:unset;background-color:#cfd6e1}.version-dialog-versions-list{width:320px;background:var(--editor-version-list-bg-color);overflow-y:auto;padding:32px 8px}.version-dialog-list-header{padding:0 12px;font-size:16px;display:flex;align-items:center;margin-top:16px;margin-bottom:12px}.dialog-version-list-item{padding:4px 12px;border-radius:8px;cursor:pointer}.dialog-version-list-item.child{padding-left:32px}.dialog-version-list-item.active{background-color:var(--editor-version-select-bg-color)}.dialog-version-list-item:not(.active):hover{background:rgba(112,132,164,.1)}.dialog-version-list-item-title{display:flex;align-items:center;margin-top:16px;margin-bottom:12px}.dialog-version-list-item-title .dialog-version-list-item-date{font-size:14px}.dialog-version-list-item-now-ver{border-radius:3px;background:#909090;color:#fff;padding:3px 4px;font-size:12px;line-height:14px;margin-left:8px}.dialog-version-list-item-authors{list-style:none;margin:0;padding-left:0;font-size:14px}.dialog-version-list-item-author{display:flex;align-items:center;margin-right:8px;margin-top:8px;margin-bottom:12px}.dialog-version-list-item-mark-author{width:10px;height:10px;border-radius:5px;margin-right:8px;margin-top:1px}.version-dialog-editor{flex-grow:1;overflow-y:auto}.editor-root.history .root-container .editor-block .text-element .inline-plugin.editor-box-loading{display:none}.editor-root.history .editor-content{padding:72px 32px 32px 48px}.version-dialog .dialog-version-item-from-container{color:#909090;font-size:12px;line-height:1.5em;margin-bottom:4px}.editor-root.history .history-inserted-block[data-type=editor-block]:not(.table-block,.list-block,.text-block) [data-type=block-content]{border:4px solid var(--op-selected-color)}.editor-root.history .history-inserted-block[data-type=editor-block]:not(.table-block,.list-block,.text-block){position:relative}.editor-root.history .history-inserted-block[data-type=editor-block]:not(.table-block,.list-block,.text-block):hover:after{content:attr(data-op-description);position:absolute;top:-26px;left:0;line-height:24px;background-color:var(--op-color);min-width:20px;opacity:1;color:#fff;padding:0 8px;z-index:var(--wiz-editor-z-history-op-description, 10);font-size:14px;font-weight:400;white-space:nowrap;border-radius:3px}.editor-root.history .history-inserted-block[data-type=editor-block].table-block table{border:4px solid var(--op-selected-color)}.editor-root.history .history-inserted-block[data-type=editor-block].table-block table .child{pointer-events:none}.editor-root.history .history-inserted-block[data-type=editor-block].table-block{position:relative}.editor-root.history .history-inserted-block[data-type=editor-block].table-block:hover:after{content:attr(data-op-description);position:absolute;top:-26px;left:0;line-height:24px;background-color:var(--op-color);min-width:20px;opacity:1;color:#fff;padding:0 8px;z-index:var(--wiz-editor-z-history-op-description, 10);font-size:14px;font-weight:400;white-space:nowrap;border-radius:3px}.editor-root.history .history-deleted-block[data-type=editor-block]:is(.code-block,.table-block,.embed-block) [data-type=block-content]{border:4px solid var(--op-selected-color)}.editor-root.history .history-deleted-block[data-type=editor-block]:is(.code-block,.table-block,.embed-block) [data-type=block-content]{position:relative}.editor-root.history .history-deleted-block[data-type=editor-block]:is(.code-block,.table-block,.embed-block) [data-type=block-content]:after,.editor-root.history .history-deleted-block[data-type=editor-block]:is(.code-block,.table-block,.embed-block) [data-type=block-content]:before{content:" ";position:absolute;display:flex;z-index:var(--wiz-editor-z-history-delete-marker);color:var(--op-color);justify-items:center;align-items:center;justify-content:center;align-content:center;pointer-events:none;overflow:visible;max-width:100%;max-height:100%;left:calc(50% - 16px);top:calc(50% - 2px);width:32px;height:4px;background-color:var(--op-color);transform:rotate(45deg);opacity:1}.editor-root.history .history-deleted-block[data-type=editor-block]:is(.code-block,.table-block,.embed-block) [data-type=block-content]:before{transform:rotate(135deg)}.editor-root.history .history-deleted-block[data-type=editor-block]:is(.code-block,.table-block,.embed-block){position:relative}.editor-root.history .history-deleted-block[data-type=editor-block]:is(.code-block,.table-block,.embed-block):hover:after{content:attr(data-op-description);position:absolute;top:-26px;left:0;line-height:24px;background-color:var(--op-color);min-width:20px;opacity:1;color:#fff;padding:0 8px;z-index:var(--wiz-editor-z-history-op-description, 10);font-size:14px;font-weight:400;white-space:nowrap;border-radius:3px}.editor-root.history .history-inserted-text{line-height:revert!important;background-color:var(--op-selected-color)}.editor-root.history .history-inserted-text{position:relative}.editor-root.history .history-inserted-text:hover:after{content:attr(data-op-description);position:absolute;top:-26px;left:0;line-height:24px;background-color:var(--op-color);min-width:20px;opacity:1;color:#fff;padding:0 8px;z-index:var(--wiz-editor-z-history-op-description, 10);font-size:14px;font-weight:400;white-space:nowrap;border-radius:3px}.editor-root.history .history-deleted-box{background-color:var(--op-selected-color);text-decoration:line-through}.editor-root.history .history-deleted-box{position:relative}.editor-root.history .history-deleted-box:hover:after{content:attr(data-op-description);position:absolute;top:-26px;left:0;line-height:24px;background-color:var(--op-color);min-width:20px;opacity:1;color:#fff;padding:0 8px;z-index:var(--wiz-editor-z-history-op-description, 10);font-size:14px;font-weight:400;white-space:nowrap;border-radius:3px}.editor-root.history [data-box-type=history-deleted-box]>span[data-type=box-content]{border:none!important;margin:0!important}.editor-root.history [data-type=editor-block].table-block div[data-type=block-content]{overflow-x:revert}.dialog-root{position:absolute;left:0;top:0;bottom:0;right:0;background-color:#639;z-index:1}.editor-root .editor-content div[data-type=editor-block].heading-collapsed div[data-type=block-tools] .block-helper .heading-collapse-button svg{transform:rotate(270deg)}.editor-root .editor-content div[data-type=editor-block].focused div[data-type=block-tools] .block-helper .heading-marker,.editor-root .editor-content div[data-type=editor-block].highlighted div[data-type=block-tools] .block-helper .heading-marker{display:none}.editor-root .editor-content div[data-type=editor-block] div[data-type=block-tools] .block-helper .heading-marker,.editor-root .editor-content div[data-type=editor-block] div[data-type=block-tools] .block-helper .heading-collapse-button{width:24px;height:24px;cursor:grab;margin:0;padding:0;display:flex;align-items:center;justify-content:center;background-color:transparent;border:none;border-radius:3px}.editor-root .editor-content div[data-type=editor-block] div[data-type=block-tools] .block-helper .heading-marker:hover,.editor-root .editor-content div[data-type=editor-block] div[data-type=block-tools] .block-helper .heading-collapse-button:hover{background-color:var(--selected-color)}.editor-root .editor-content div[data-type=editor-block] div[data-type=block-tools] .block-helper .heading-marker svg,.editor-root .editor-content div[data-type=editor-block] div[data-type=block-tools] .block-helper .heading-collapse-button svg{transform:rotate(360deg);transition:transform .2s linear}.editor-root .editor-content div[data-type=editor-block] div[data-type=block-tools] .block-helper .heading-marker svg,.editor-root .editor-content div[data-type=editor-block] div[data-type=block-tools] .block-helper .heading-collapse-button svg{width:16px;height:16px}.editor-root .editor-content div[data-type=editor-block] div[data-type=block-tools] .block-helper .heading-marker:hover{background-color:transparent}.embed-block div[data-type=block-content] .editor-toc-container{display:block;width:100%;background-color:#f0f0f0;padding:20px}.embed-block div[data-type=block-content] .editor-toc-container.loading{margin:0;min-height:100px}.embed-block div[data-type=block-content] .editor-toc-container .toc-node+.toc-node{margin-top:10px}.embed-block div[data-type=block-content] .editor-toc-container .toc-node .toc-text{cursor:pointer;color:var(--primary-color)}.embed-block div[data-type=block-content] .editor-toc-container .toc-node .toc-children{margin-top:10px;padding-left:20px}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content] [data-box-type=mention] span[data-type=box-content]{margin:0}div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content] [data-box-type=mention] span[data-type=box-content] .mention-name{color:var(--primary-color);padding:0;border-radius:12px;margin-left:4px;margin-right:4px;white-space:wrap;word-break:break-all;cursor:pointer}[data-command-bar-id=editor-mention] .editor-command-bar.menu .command-item.menu-item .menu-item-icon{width:20px;height:20px;border-radius:50%;overflow:hidden}[data-command-bar-id=editor-mention] .editor-command-bar.menu .command-item.menu-item .menu-item-icon img{width:100%;height:100%}[data-command-bar-id=editor-mention] .editor-command-bar.menu .command-item.menu-item .menu-item-name{flex-grow:0;margin-right:5px}.editor-root .editor-templates{position:fixed;bottom:26px;height:256px;width:auto;max-width:100%;padding-left:30px;padding-right:44px;overflow:hidden}.editor-root .editor-templates .editor-templates-title{color:#909090;font-size:14px;margin-left:0;margin-bottom:20px;line-height:19.6px}.editor-root .editor-templates .editor-templates-cards{display:flex;margin-left:0}.editor-root .editor-templates .editor-templates-cards .editor-template-card{box-sizing:border-box;display:flex;flex-direction:column;justify-content:center;cursor:pointer;flex-shrink:0;height:192px;width:188px;background:none;border:1px solid #e8e8e8;border-radius:3px;margin:0 0 0 15px;padding:0;align-items:revert}.editor-root .editor-templates .editor-templates-cards .editor-template-card:first-child{margin-left:0}.editor-root .editor-templates .editor-templates-cards .editor-template-card:hover{box-shadow:0 0 1px #30303033,0 8px 16px #30303026}.editor-root .editor-templates .editor-templates-cards .editor-template-card:hover>.editor-template-name{color:#338fe5}.editor-root .editor-templates .editor-templates-cards .editor-template-card .editor-template-name{display:flex;align-items:center;height:40px;width:100%;border-top:1px solid #dedede;padding-left:20px;padding-right:20px;flex:0 0 50px;font-size:14px;font-weight:500;line-height:22px;color:#303030}.editor-root .editor-templates .editor-templates-cards .editor-template-card .editor-template-name span{display:block;width:100%;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.editor-root .editor-templates .editor-templates-cards .editor-template-card.more .editor-template-name{border-top:none}.editor-root .editor-templates .editor-templates-cards .editor-template-card.more .editor-template-name span{padding-left:0;text-align:center}.editor-root .editor-templates .editor-templates-cards .editor-template-card.more .editor-template-thumb-container{display:flex;align-items:center;justify-content:center;padding:16px 39px 14px}.editor-root .editor-templates .editor-templates-cards .editor-template-card.more .editor-template-thumb-container>img{width:110px;height:112px;max-width:revert}.editor-root .editor-templates .editor-templates-cards .editor-template-card .editor-template-thumb-container{flex:1;position:relative;padding:10px 5px 0;height:142px;margin:0;overflow:revert}.editor-root .editor-templates .editor-templates-cards .editor-template-card .editor-template-thumb-container>img{max-width:100%}div[data-type=editor-block].encrypted-block{border:2px solid #ccc;padding:8px;border-radius:4px}div[data-type=editor-block].encrypted-block.encrypted div[data-type=block-content]{min-height:60px;width:100%}div[data-type=editor-block].encrypted-block.full-selected>div[data-type=block-content]{background-color:var(--background-selection)}div[data-type=editor-block].encrypted-block .password-container{position:absolute;top:0;left:0;right:0;bottom:0;display:flex;align-items:center;justify-content:center}`)),document.head.appendChild(t)}}catch(o){console.error("vite-plugin-css-injected-by-js",o)}})();
2
- (function(g,Ie){typeof exports=="object"&&typeof module<"u"?Ie(exports,require("kiwi-intl"),require("lodash.merge"),require("string-template"),require("nanoid"),require("events"),require("query-string"),require("js-base64"),require("snabbdom"),require("lodash.clonedeep"),require("lodash.isequal"),require("quill-delta"),require("tiny-typed-emitter"),require("lodash.intersection"),require("ot-json1"),require("axios"),require("lodash.findlastindex"),require("reconnecting-websocket"),require("fast-sha256"),require("lodash.debounce"),require("tippy.js"),require("blueimp-md5"),require("css-color-converter"),require("markmap-view"),require("lodash.throttle"),require("prismjs"),require("prismjs/components/prism-c"),require("prismjs/components/prism-cpp"),require("prismjs/components/prism-abap"),require("prismjs/components/prism-arduino"),require("prismjs/components/prism-bash"),require("prismjs/components/prism-basic"),require("prismjs/components/prism-clojure"),require("prismjs/components/prism-coffeescript"),require("prismjs/components/prism-csharp"),require("prismjs/components/prism-css"),require("prismjs/components/prism-dart"),require("prismjs/components/prism-diff"),require("prismjs/components/prism-docker"),require("prismjs/components/prism-elixir"),require("prismjs/components/prism-elm"),require("prismjs/components/prism-erlang"),require("prismjs/components/prism-flow"),require("prismjs/components/prism-fortran"),require("prismjs/components/prism-fsharp"),require("prismjs/components/prism-gherkin"),require("prismjs/components/prism-glsl"),require("prismjs/components/prism-go"),require("prismjs/components/prism-graphql"),require("prismjs/components/prism-groovy"),require("prismjs/components/prism-haskell"),require("prismjs/components/prism-java"),require("prismjs/components/prism-javascript"),require("prismjs/components/prism-json"),require("prismjs/components/prism-julia"),require("prismjs/components/prism-kotlin"),require("prismjs/components/prism-latex"),require("prismjs/components/prism-less"),require("prismjs/components/prism-lisp"),require("prismjs/components/prism-livescript"),require("prismjs/components/prism-lua"),require("prismjs/components/prism-makefile"),require("prismjs/components/prism-markdown"),require("prismjs/components/prism-markup"),require("prismjs/components/prism-matlab"),require("prismjs/components/prism-mermaid"),require("prismjs/components/prism-nix"),require("prismjs/components/prism-objectivec"),require("prismjs/components/prism-ocaml"),require("prismjs/components/prism-pascal"),require("prismjs/components/prism-perl"),require("prismjs/components/prism-php"),require("prismjs/components/prism-powershell"),require("prismjs/components/prism-prolog"),require("prismjs/components/prism-protobuf"),require("prismjs/components/prism-python"),require("prismjs/components/prism-r"),require("prismjs/components/prism-reason"),require("prismjs/components/prism-ruby"),require("prismjs/components/prism-rust"),require("prismjs/components/prism-sass"),require("prismjs/components/prism-scala"),require("prismjs/components/prism-scheme"),require("prismjs/components/prism-scss"),require("prismjs/components/prism-solidity"),require("prismjs/components/prism-sql"),require("prismjs/components/prism-swift"),require("prismjs/components/prism-typescript"),require("prismjs/components/prism-vbnet"),require("prismjs/components/prism-verilog"),require("prismjs/components/prism-vhdl"),require("prismjs/components/prism-visual-basic"),require("prismjs/components/prism-wasm"),require("prismjs/components/prism-yaml"),require("mime-db"),require("dom-to-image"),require("plantuml-encoder"),require("@guyplusplus/turndown-plugin-gfm"),require("turndown"),require("marked"),require("@better-scroll/core")):typeof define=="function"&&define.amd?define(["exports","kiwi-intl","lodash.merge","string-template","nanoid","events","query-string","js-base64","snabbdom","lodash.clonedeep","lodash.isequal","quill-delta","tiny-typed-emitter","lodash.intersection","ot-json1","axios","lodash.findlastindex","reconnecting-websocket","fast-sha256","lodash.debounce","tippy.js","blueimp-md5","css-color-converter","markmap-view","lodash.throttle","prismjs","prismjs/components/prism-c","prismjs/components/prism-cpp","prismjs/components/prism-abap","prismjs/components/prism-arduino","prismjs/components/prism-bash","prismjs/components/prism-basic","prismjs/components/prism-clojure","prismjs/components/prism-coffeescript","prismjs/components/prism-csharp","prismjs/components/prism-css","prismjs/components/prism-dart","prismjs/components/prism-diff","prismjs/components/prism-docker","prismjs/components/prism-elixir","prismjs/components/prism-elm","prismjs/components/prism-erlang","prismjs/components/prism-flow","prismjs/components/prism-fortran","prismjs/components/prism-fsharp","prismjs/components/prism-gherkin","prismjs/components/prism-glsl","prismjs/components/prism-go","prismjs/components/prism-graphql","prismjs/components/prism-groovy","prismjs/components/prism-haskell","prismjs/components/prism-java","prismjs/components/prism-javascript","prismjs/components/prism-json","prismjs/components/prism-julia","prismjs/components/prism-kotlin","prismjs/components/prism-latex","prismjs/components/prism-less","prismjs/components/prism-lisp","prismjs/components/prism-livescript","prismjs/components/prism-lua","prismjs/components/prism-makefile","prismjs/components/prism-markdown","prismjs/components/prism-markup","prismjs/components/prism-matlab","prismjs/components/prism-mermaid","prismjs/components/prism-nix","prismjs/components/prism-objectivec","prismjs/components/prism-ocaml","prismjs/components/prism-pascal","prismjs/components/prism-perl","prismjs/components/prism-php","prismjs/components/prism-powershell","prismjs/components/prism-prolog","prismjs/components/prism-protobuf","prismjs/components/prism-python","prismjs/components/prism-r","prismjs/components/prism-reason","prismjs/components/prism-ruby","prismjs/components/prism-rust","prismjs/components/prism-sass","prismjs/components/prism-scala","prismjs/components/prism-scheme","prismjs/components/prism-scss","prismjs/components/prism-solidity","prismjs/components/prism-sql","prismjs/components/prism-swift","prismjs/components/prism-typescript","prismjs/components/prism-vbnet","prismjs/components/prism-verilog","prismjs/components/prism-vhdl","prismjs/components/prism-visual-basic","prismjs/components/prism-wasm","prismjs/components/prism-yaml","mime-db","dom-to-image","plantuml-encoder","@guyplusplus/turndown-plugin-gfm","turndown","marked","@better-scroll/core"],Ie):(g=typeof globalThis<"u"?globalThis:g||self,Ie(g["oneseditor-editor"]={},g.KiwiIntl,g.merge,g.stringFormat,g.nanoid$1,g.events,g.queryString,g.jsBase64,g.snabbdom,g.cloneDeep,g.isEqual,g.Delta,g.tinyTypedEmitter,g.intersection,g.json1,g.axios,g.findLastIndex,g.ReconnectingWebSocket,g.sha256,g.debounce,g.tippy$1,g.md5,g.cssColorConverter,g.markmap,g.throttle,g.Prism,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,g.mime,g.domToImage,g.plantumlEncoder,g.turndownPluginGfm,g.TurndownService,g.marked,g.BetterScroll))})(this,function(g,Ie,Oo,Z9,Y9,Zf,Q9,xi,oo,K9,J9,X9,Yt,t7,e7,n7,o7,r7,i7,s7,Qa,l7,Ka,c7,a7,d7,YH,QH,KH,JH,XH,tF,eF,nF,oF,rF,iF,sF,lF,cF,aF,dF,uF,hF,fF,mF,gF,pF,CF,bF,kF,vF,yF,wF,BF,EF,IF,xF,TF,SF,DF,LF,MF,RF,AF,OF,_F,NF,$F,PF,jF,HF,FF,zF,UF,VF,qF,WF,GF,ZF,YF,QF,KF,JF,XF,tz,ez,nz,oz,rz,iz,sz,lz,cz,u7,h7,f7,m7,g7,Yf,p7){"use strict";var GH=Object.defineProperty;var ZH=(g,Ie,Oo)=>Ie in g?GH(g,Ie,{enumerable:!0,configurable:!0,writable:!0,value:Oo}):g[Ie]=Oo;var h=(g,Ie,Oo)=>(ZH(g,typeof Ie!="symbol"?Ie+"":Ie,Oo),Oo);const _t=n=>n&&typeof n=="object"&&"default"in n?n:{default:n};function fl(n){if(n&&n.__esModule)return n;const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const e in n)if(e!=="default"){const o=Object.getOwnPropertyDescriptor(n,e);Object.defineProperty(t,e,o.get?o:{enumerable:!0,get:()=>n[e]})}}return t.default=n,Object.freeze(t)}const C7=_t(Ie),Ja=_t(Oo),b7=_t(Z9),Qf=_t(Zf),Y=_t(K9),ml=_t(J9),oe=_t(X9),Xa=_t(t7),gl=fl(e7),k7=_t(n7),v7=_t(o7),y7=_t(r7),w7=fl(i7),Xt=_t(s7),B7=_t(Qa),E7=fl(Qa),Ti=_t(l7),I7=fl(c7),x7=_t(a7),Si=_t(d7),Kf=_t(u7),Jf=_t(h7),T7=_t(f7),S7=_t(g7),Xf=_t(p7);function D7(n){const t=o=>o<10?`0${String(o)}`:String(o),e=o=>o<10?`00${String(o)}`:o<100?`0${String(o)}`:String(o);return`${n.getFullYear()}-${t(n.getMonth()+1)}-${t(n.getDate())} ${t(n.getHours())}:${t(n.getMinutes())}:${t(n.getSeconds())}.${e(n.getMilliseconds())}`}const tm=new Map,nl=class{constructor(t){h(this,"times",new Map);this.category=t}_log(t,e,o,r){var k;const i=typeof process>"u"?{}:process;let s="";if(typeof e=="object")try{s="message"in e?e.message:JSON.stringify(e,null,4)}catch{s=""}else typeof e=="string"?e&&(s=e):s=JSON.stringify(e);s=r?`${s} - ${r}`:s;const l=`${this.category}`;let c=console.log;t==="WARN "&&(c=console.warn),t==="ERROR"&&(c=console.error);const a=`${D7(new Date)}`,u=t,f=l,m=nl.extParams?"[{date}] {level}: [{module} {extParams}] - {msg}":"[{date}] {level}: [{module}] - {msg}",C=[b7.default(((k=i.env)==null?void 0:k.LOG_TEMPLATE)||m,{date:a,level:u,module:f,msg:s,extParams:nl.extParams})];if(typeof e=="object"){const w=e.stack;w&&C.push(w)}if(c===console.error&&nl.debugMode){const w=new Error().stack;w&&C.push(w)}c(...C),o&&this._log(t,o)}log(t,e){this._log("INFO ",t,void 0,e)}debug(t,e){this._log("DEBUG",t,void 0,e)}info(t,e){this._log("INFO ",t,void 0,e)}warn(t,e,o){this._log("WARN ",t,e,o)}error(t,e,o){this._log("ERROR",t,e,o)}time(t){this.times.set(t,Date.now())}timeEnd(t){this.timeLog(t),this.times.delete(t)}timeLog(t){const e=this.times.get(t);if(!e){this.warn(`no time label: ${t}`);return}this.debug(`${t}: ${Date.now()-e}`)}static setExtParams(t){this.extParams=t}};let kr=nl;h(kr,"debugMode",!1),h(kr,"extParams","");function B(n){const t=tm.get(n);if(t)return t;const e=new kr(n);return tm.set(n,e),e}const L7={name:"Ones Editor",date:{dateFromFuture:"From future",dateJustNow:"Just now",dateYesterday:"Yesterday",dateMinutesAgo:"{num} minutes ago",date1HourAgo:"1 hour ago",dateHoursAgo:"{num} hours ago",dateDaysAgo:"{num} days ago",dateWeeksAgo:"{num} weeks ago"},common:{cancel:"cancel"}},M7={name:"Ones Editor",date:{dateFromFuture:"\u6765\u81EA\u672A\u6765",dateJustNow:"\u521A\u521A",dateYesterday:"\u6628\u5929",dateMinutesAgo:"{num}\u5206\u949F\u524D",date1HourAgo:"1\u5C0F\u65F6\u524D",dateHoursAgo:"{num}\u5C0F\u65F6\u524D",dateDaysAgo:"{num}\u5929\u524D",dateWeeksAgo:"{num}\u5468\u524D"},common:{cancel:"\u53D6\u6D88"}},R7=B("i18n"),A7={"en-US":L7,"zh-CN":M7},pl=C7.default.init("en-US",A7);function O7(n=void 0){pl.setLang&&pl.setLang(n||"en-US")}function _7(n){Ja.default(pl.__metas__,n)}function N7(n,t){const e=pl.get(n,t);return e===n&&R7.warn(`no locale value for key ${n}`),e}const T=Object.freeze(Object.defineProperty({__proto__:null,setLang:O7,mergeLang:_7,t:N7},Symbol.toStringTag,{value:"Module"})),az="";class em{constructor(t,e){this.editor=t,this.data=e}getData(){return this.data}getEditor(){return this.editor}destroy(){}}class $7 extends Error{constructor(t){if(super(t),this.code="Assert",this.stack){const e=this.stack.split(`
2
+ (function(g,Ie){typeof exports=="object"&&typeof module<"u"?Ie(exports,require("kiwi-intl"),require("lodash.merge"),require("string-template"),require("nanoid"),require("events"),require("query-string"),require("js-base64"),require("snabbdom"),require("lodash.clonedeep"),require("lodash.isequal"),require("quill-delta"),require("tiny-typed-emitter"),require("lodash.intersection"),require("ot-json1"),require("axios"),require("lodash.findlastindex"),require("reconnecting-websocket"),require("fast-sha256"),require("lodash.debounce"),require("tippy.js"),require("blueimp-md5"),require("css-color-converter"),require("markmap-view"),require("lodash.throttle"),require("prismjs"),require("prismjs/components/prism-c"),require("prismjs/components/prism-cpp"),require("prismjs/components/prism-abap"),require("prismjs/components/prism-arduino"),require("prismjs/components/prism-bash"),require("prismjs/components/prism-basic"),require("prismjs/components/prism-clojure"),require("prismjs/components/prism-coffeescript"),require("prismjs/components/prism-csharp"),require("prismjs/components/prism-css"),require("prismjs/components/prism-dart"),require("prismjs/components/prism-diff"),require("prismjs/components/prism-docker"),require("prismjs/components/prism-elixir"),require("prismjs/components/prism-elm"),require("prismjs/components/prism-erlang"),require("prismjs/components/prism-flow"),require("prismjs/components/prism-fortran"),require("prismjs/components/prism-fsharp"),require("prismjs/components/prism-gherkin"),require("prismjs/components/prism-glsl"),require("prismjs/components/prism-go"),require("prismjs/components/prism-graphql"),require("prismjs/components/prism-groovy"),require("prismjs/components/prism-haskell"),require("prismjs/components/prism-java"),require("prismjs/components/prism-javascript"),require("prismjs/components/prism-json"),require("prismjs/components/prism-julia"),require("prismjs/components/prism-kotlin"),require("prismjs/components/prism-latex"),require("prismjs/components/prism-less"),require("prismjs/components/prism-lisp"),require("prismjs/components/prism-livescript"),require("prismjs/components/prism-lua"),require("prismjs/components/prism-makefile"),require("prismjs/components/prism-markdown"),require("prismjs/components/prism-markup"),require("prismjs/components/prism-matlab"),require("prismjs/components/prism-mermaid"),require("prismjs/components/prism-nix"),require("prismjs/components/prism-objectivec"),require("prismjs/components/prism-ocaml"),require("prismjs/components/prism-pascal"),require("prismjs/components/prism-perl"),require("prismjs/components/prism-php"),require("prismjs/components/prism-powershell"),require("prismjs/components/prism-prolog"),require("prismjs/components/prism-protobuf"),require("prismjs/components/prism-python"),require("prismjs/components/prism-r"),require("prismjs/components/prism-reason"),require("prismjs/components/prism-ruby"),require("prismjs/components/prism-rust"),require("prismjs/components/prism-sass"),require("prismjs/components/prism-scala"),require("prismjs/components/prism-scheme"),require("prismjs/components/prism-scss"),require("prismjs/components/prism-solidity"),require("prismjs/components/prism-sql"),require("prismjs/components/prism-swift"),require("prismjs/components/prism-typescript"),require("prismjs/components/prism-vbnet"),require("prismjs/components/prism-verilog"),require("prismjs/components/prism-vhdl"),require("prismjs/components/prism-visual-basic"),require("prismjs/components/prism-wasm"),require("prismjs/components/prism-yaml"),require("mime-db"),require("dom-to-image"),require("plantuml-encoder"),require("@guyplusplus/turndown-plugin-gfm"),require("turndown"),require("marked"),require("@better-scroll/core")):typeof define=="function"&&define.amd?define(["exports","kiwi-intl","lodash.merge","string-template","nanoid","events","query-string","js-base64","snabbdom","lodash.clonedeep","lodash.isequal","quill-delta","tiny-typed-emitter","lodash.intersection","ot-json1","axios","lodash.findlastindex","reconnecting-websocket","fast-sha256","lodash.debounce","tippy.js","blueimp-md5","css-color-converter","markmap-view","lodash.throttle","prismjs","prismjs/components/prism-c","prismjs/components/prism-cpp","prismjs/components/prism-abap","prismjs/components/prism-arduino","prismjs/components/prism-bash","prismjs/components/prism-basic","prismjs/components/prism-clojure","prismjs/components/prism-coffeescript","prismjs/components/prism-csharp","prismjs/components/prism-css","prismjs/components/prism-dart","prismjs/components/prism-diff","prismjs/components/prism-docker","prismjs/components/prism-elixir","prismjs/components/prism-elm","prismjs/components/prism-erlang","prismjs/components/prism-flow","prismjs/components/prism-fortran","prismjs/components/prism-fsharp","prismjs/components/prism-gherkin","prismjs/components/prism-glsl","prismjs/components/prism-go","prismjs/components/prism-graphql","prismjs/components/prism-groovy","prismjs/components/prism-haskell","prismjs/components/prism-java","prismjs/components/prism-javascript","prismjs/components/prism-json","prismjs/components/prism-julia","prismjs/components/prism-kotlin","prismjs/components/prism-latex","prismjs/components/prism-less","prismjs/components/prism-lisp","prismjs/components/prism-livescript","prismjs/components/prism-lua","prismjs/components/prism-makefile","prismjs/components/prism-markdown","prismjs/components/prism-markup","prismjs/components/prism-matlab","prismjs/components/prism-mermaid","prismjs/components/prism-nix","prismjs/components/prism-objectivec","prismjs/components/prism-ocaml","prismjs/components/prism-pascal","prismjs/components/prism-perl","prismjs/components/prism-php","prismjs/components/prism-powershell","prismjs/components/prism-prolog","prismjs/components/prism-protobuf","prismjs/components/prism-python","prismjs/components/prism-r","prismjs/components/prism-reason","prismjs/components/prism-ruby","prismjs/components/prism-rust","prismjs/components/prism-sass","prismjs/components/prism-scala","prismjs/components/prism-scheme","prismjs/components/prism-scss","prismjs/components/prism-solidity","prismjs/components/prism-sql","prismjs/components/prism-swift","prismjs/components/prism-typescript","prismjs/components/prism-vbnet","prismjs/components/prism-verilog","prismjs/components/prism-vhdl","prismjs/components/prism-visual-basic","prismjs/components/prism-wasm","prismjs/components/prism-yaml","mime-db","dom-to-image","plantuml-encoder","@guyplusplus/turndown-plugin-gfm","turndown","marked","@better-scroll/core"],Ie):(g=typeof globalThis<"u"?globalThis:g||self,Ie(g["oneseditor-editor"]={},g.KiwiIntl,g.merge,g.stringFormat,g.nanoid$1,g.events,g.queryString,g.jsBase64,g.snabbdom,g.cloneDeep,g.isEqual,g.Delta,g.tinyTypedEmitter,g.intersection,g.json1,g.axios,g.findLastIndex,g.ReconnectingWebSocket,g.sha256,g.debounce,g.tippy$1,g.md5,g.cssColorConverter,g.markmap,g.throttle,g.Prism,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,g.mime,g.domToImage,g.plantumlEncoder,g.turndownPluginGfm,g.TurndownService,g.marked,g.BetterScroll))})(this,function(g,Ie,_o,Z9,Y9,Zf,Q9,xi,oo,K9,J9,X9,Yt,t7,e7,n7,o7,r7,i7,s7,Qa,l7,Ka,c7,a7,d7,YH,QH,KH,JH,XH,tF,eF,nF,oF,rF,iF,sF,lF,cF,aF,dF,uF,hF,fF,mF,gF,pF,CF,bF,kF,vF,yF,wF,BF,EF,IF,xF,TF,SF,DF,LF,MF,RF,AF,OF,_F,NF,$F,PF,jF,HF,FF,zF,UF,VF,qF,WF,GF,ZF,YF,QF,KF,JF,XF,tz,ez,nz,oz,rz,iz,sz,lz,cz,u7,h7,f7,m7,g7,Yf,p7){"use strict";var GH=Object.defineProperty;var ZH=(g,Ie,_o)=>Ie in g?GH(g,Ie,{enumerable:!0,configurable:!0,writable:!0,value:_o}):g[Ie]=_o;var h=(g,Ie,_o)=>(ZH(g,typeof Ie!="symbol"?Ie+"":Ie,_o),_o);const _t=n=>n&&typeof n=="object"&&"default"in n?n:{default:n};function fl(n){if(n&&n.__esModule)return n;const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const e in n)if(e!=="default"){const o=Object.getOwnPropertyDescriptor(n,e);Object.defineProperty(t,e,o.get?o:{enumerable:!0,get:()=>n[e]})}}return t.default=n,Object.freeze(t)}const C7=_t(Ie),Ja=_t(_o),b7=_t(Z9),Qf=_t(Zf),Y=_t(K9),ml=_t(J9),oe=_t(X9),Xa=_t(t7),gl=fl(e7),k7=_t(n7),v7=_t(o7),y7=_t(r7),w7=fl(i7),Xt=_t(s7),B7=_t(Qa),E7=fl(Qa),Ti=_t(l7),I7=fl(c7),x7=_t(a7),Si=_t(d7),Kf=_t(u7),Jf=_t(h7),T7=_t(f7),S7=_t(g7),Xf=_t(p7);function D7(n){const t=o=>o<10?`0${String(o)}`:String(o),e=o=>o<10?`00${String(o)}`:o<100?`0${String(o)}`:String(o);return`${n.getFullYear()}-${t(n.getMonth()+1)}-${t(n.getDate())} ${t(n.getHours())}:${t(n.getMinutes())}:${t(n.getSeconds())}.${e(n.getMilliseconds())}`}const tm=new Map,nl=class{constructor(t){h(this,"times",new Map);this.category=t}_log(t,e,o,r){var k;const i=typeof process>"u"?{}:process;let s="";if(typeof e=="object")try{s="message"in e?e.message:JSON.stringify(e,null,4)}catch{s=""}else typeof e=="string"?e&&(s=e):s=JSON.stringify(e);s=r?`${s} - ${r}`:s;const l=`${this.category}`;let c=console.log;t==="WARN "&&(c=console.warn),t==="ERROR"&&(c=console.error);const a=`${D7(new Date)}`,u=t,f=l,m=nl.extParams?"[{date}] {level}: [{module} {extParams}] - {msg}":"[{date}] {level}: [{module}] - {msg}",C=[b7.default(((k=i.env)==null?void 0:k.LOG_TEMPLATE)||m,{date:a,level:u,module:f,msg:s,extParams:nl.extParams})];if(typeof e=="object"){const w=e.stack;w&&C.push(w)}if(c===console.error&&nl.debugMode){const w=new Error().stack;w&&C.push(w)}c(...C),o&&this._log(t,o)}log(t,e){this._log("INFO ",t,void 0,e)}debug(t,e){this._log("DEBUG",t,void 0,e)}info(t,e){this._log("INFO ",t,void 0,e)}warn(t,e,o){this._log("WARN ",t,e,o)}error(t,e,o){this._log("ERROR",t,e,o)}time(t){this.times.set(t,Date.now())}timeEnd(t){this.timeLog(t),this.times.delete(t)}timeLog(t){const e=this.times.get(t);if(!e){this.warn(`no time label: ${t}`);return}this.debug(`${t}: ${Date.now()-e}`)}static setExtParams(t){this.extParams=t}};let kr=nl;h(kr,"debugMode",!1),h(kr,"extParams","");function B(n){const t=tm.get(n);if(t)return t;const e=new kr(n);return tm.set(n,e),e}const L7={name:"Ones Editor",date:{dateFromFuture:"From future",dateJustNow:"Just now",dateYesterday:"Yesterday",dateMinutesAgo:"{num} minutes ago",date1HourAgo:"1 hour ago",dateHoursAgo:"{num} hours ago",dateDaysAgo:"{num} days ago",dateWeeksAgo:"{num} weeks ago"},common:{cancel:"cancel"}},M7={name:"Ones Editor",date:{dateFromFuture:"\u6765\u81EA\u672A\u6765",dateJustNow:"\u521A\u521A",dateYesterday:"\u6628\u5929",dateMinutesAgo:"{num}\u5206\u949F\u524D",date1HourAgo:"1\u5C0F\u65F6\u524D",dateHoursAgo:"{num}\u5C0F\u65F6\u524D",dateDaysAgo:"{num}\u5929\u524D",dateWeeksAgo:"{num}\u5468\u524D"},common:{cancel:"\u53D6\u6D88"}},R7=B("i18n"),A7={"en-US":L7,"zh-CN":M7},pl=C7.default.init("en-US",A7);function O7(n=void 0){pl.setLang&&pl.setLang(n||"en-US")}function _7(n){Ja.default(pl.__metas__,n)}function N7(n,t){const e=pl.get(n,t);return e===n&&R7.warn(`no locale value for key ${n}`),e}const T=Object.freeze(Object.defineProperty({__proto__:null,setLang:O7,mergeLang:_7,t:N7},Symbol.toStringTag,{value:"Module"})),az="";class em{constructor(t,e){this.editor=t,this.data=e}getData(){return this.data}getEditor(){return this.editor}destroy(){}}class $7 extends Error{constructor(t){if(super(t),this.code="Assert",this.stack){const e=this.stack.split(`
3
3
  `);if(e.length>1)if(this.lineNumber&&this.columnNumber){const o=e[1].match(/(.*)@(.*):(\d+):(\d+)/);o&&(this.lineNumber=+o[3],this.columnNumber=+o[4],this.fileName=o[2]),e.splice(0,1)}else e.splice(1,1);this.stack=e.join(`
4
4
  `)}}}function d(n,t,e){if(!t)throw n.error(`assert failed: ${e}`),new $7(e)}const P7=Y9.customAlphabet("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",8),nm="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";function j7(){return nm[Date.now()%nm.length]}const N=()=>`${j7()}${P7()}`;class om extends Qf.default.EventEmitter{constructor(e=60){super();h(this,"cache",new Map);h(this,"expiredSeconds");this.expiredSeconds=e,this.startAutoClear()}delete(e){const o=this.cache.get(e);o&&this.emit("delete",o.data),this.cache.delete(e)}getSync(e,o){const r=this.cache.get(e),i=Date.now();if(r&&(i-r.lastRead)/1e3<this.expiredSeconds)return r.lastRead=i,r.data;const s=o(e);return this.cache.set(e,{lastRead:i,data:s}),s}async get(e,o){const r=this.cache.get(e),i=Date.now();if(r&&(i-r.lastRead)/1e3<this.expiredSeconds)return r.lastRead=i,r.data;const s=await o(e);return this.cache.set(e,{lastRead:i,data:s}),s}startAutoClear(){setInterval(()=>{const e=Date.now();Array.from(this.cache.entries()).forEach(([o,r])=>{(e-r.lastRead)/1e3>this.expiredSeconds&&this.delete(o)})},10*1e3)}}class Di{constructor(){h(this,"_callbacks",new Set)}get callbacks(){return Array.from(this._callbacks)}registerCallback(t){this._callbacks.add(t)}unregisterCallback(t){this._callbacks.delete(t)}clearCallbacks(){this._callbacks.clear()}}const H7=B("await-locker");class F7{constructor(){h(this,"_acquired",!1);h(this,"_waitingResolvers",[]);this._acquired=!1,this._waitingResolvers=[]}acquireAsync(t){return this._acquired?new Promise((e,o)=>{this._waitingResolvers.push(e),t&&t>0&&setTimeout(()=>{const r=this._waitingResolvers.indexOf(e);if(r!==-1){this._waitingResolvers.splice(r,1);const i=new Error(`lock timeout: ${t}, waiting resolves: ${this._waitingResolvers.length}`);o(i)}},t)}):(this._acquired=!0,Promise.resolve())}tryAcquire(){return this._acquired?!1:(this._acquired=!0,!0)}release(){if(!this._acquired)throw new Error("Cannot release an unacquired lock");if(this._waitingResolvers.length>0){const t=this._waitingResolvers.shift();d(H7,t,"Resolver missing"),t(void 0)}else this._acquired=!1}acquired(){return this._acquired}debug(){const t=this._waitingResolvers.length;return console.log(`waiting resolves: ${t}`),{waitingCount:t}}}class z7{constructor(){h(this,"_map");this._map=new Map}getLocker(t){let e=this._map.get(t);return e||(e=new F7,this._map.set(t,e)),e}async lock(t,e){await this.getLocker(t).acquireAsync(e)}release(t){this.getLocker(t).release()}remove(t){this.isLocking(t)||this._map.delete(t)}isLocking(t){return this._map.has(t)?this.getLocker(t).acquired():!1}}const qe=new z7;/**
5
5
  * @name string-character-is-astral-surrogate
@@ -8,23 +8,23 @@
8
8
  * @author Roy Revelt, Codsen Ltd
9
9
  * @license MIT
10
10
  * {@link https://codsen.com/os/string-character-is-astral-surrogate/}
11
- */function U7(n){if(typeof n=="string")return n.length===0?!1:n.charCodeAt(0)>=55296&&n.charCodeAt(0)<=56319;if(n===void 0)return!1;throw new TypeError(`string-character-is-astral-surrogate/isHighSurrogate(): the input is not string but ${typeof n}`)}function td(n){if(typeof n=="string")return n.length===0?!1:n.charCodeAt(0)>=56320&&n.charCodeAt(0)<=57343;if(n===void 0)return!1;throw new TypeError(`string-character-is-astral-surrogate/isLowSurrogate(): the input is not string but ${typeof n}`)}const Li="\u200B";function V7(n){return[...n].length}function q7(n,t,e){const r=[...n];let i;return e===void 0?i=r.length:i=t+e,r.slice(t,i).join("")}const _o=B("dom-utils");function A(n,...t){n&&n.nodeType===Node.ELEMENT_NODE&&n.classList.add(...t)}function nt(n,t){return n instanceof HTMLElement?n.classList.contains(t):!1}function z(n,...t){n&&n.nodeType===Node.ELEMENT_NODE&&n.classList.remove(...t),n.classList.length===0&&n.removeAttribute("class")}function b(n,t,e,o){const r=document.createElement(n);return t&&t.length>0&&A(r,...t),e&&e.appendChild(r),o&&(typeof o=="string"?r.innerText=o:nd(r,o)),r}function vr(n,t,e){const o=b("button",t,e);return o.innerHTML=n,o}function rm(n,t,e){const o=b("img",t,e);return o.src=n,o}function im(n,t){try{const e=document.createRange();return e.setStart(n,t),e}catch(e){d(_o,!1,`failed to create range: ${n.childNodes.length}, ${t}, ${e.message}`)}}function Cl(n,t,e,o){try{const r=document.createRange();return r.setStart(n,t),r.setEnd(e,o),r}catch(r){d(_o,!1,`failed to create expanded range: ${n.childNodes.length}, ${t}, ${e.childNodes.length}, ${o}, ${r.message}`)}}function bl(n){const t=n.getClientRects();return d(_o,t.length>=1,"getFirstClientRect: no rects"),t[0]}function No(n){const t=n.getClientRects();return d(_o,t.length>=1,"getLastClientRect: no rects"),t[t.length-1]}function Cn(n,t,e){const o=n.left+n.width/2,r=n.top+n.height/2;return(o-t)**2+(r-e)**2}function sm(n,t,e){const o=n.data;d(_o,o,"invalid text node, no data");let r=Number.MAX_SAFE_INTEGER,i=0;const s=document.createRange();for(let l=0;l<=o.length;l++){if(l<o.length&&td(o[l]))continue;s.setStart(n,l);const c=s.getClientRects();for(let a=0;a<c.length;a++){const u=c[a],f=Cn(u,t,e);f<r&&(r=f,i=l)}}return i}function kl(n,t){if(n===t)return 0;if((!n.parentElement||!t.parentElement)&&d(_o,!1,"invalid dom node to compare"),n.parentElement===t.parentElement){const i=Array.from(n.parentElement.children);return i.indexOf(n)-i.indexOf(t)}const e=i=>{const s=[i];for(;i.parentElement;)s.unshift(i.parentElement),i=i.parentElement;return s},o=e(n),r=e(t);o[0]!==r[0]&&d(_o,!1,"invalid dom node to compare, different tree");for(let i=1;;i++){const s=o[i],l=r[i];if(s===l)continue;const c=o[i-1],a=Array.from(c.children);return a.indexOf(s)-a.indexOf(l)}}function ed(n){var r,i;const t=window.getComputedStyle(n),e=(r=Number.parseInt(t.paddingLeft,10))!=null?r:0,o=(i=Number.parseInt(t.paddingRight,10))!=null?i:0;return e+o}function lm(n){return!document.documentElement.contains(n)}function It(n,t){let e=t;for(;e;){if(n===e)return!0;e=e.parentNode}return!1}function cm(n,t,e){if(document.getElementById(t)){setTimeout(e);return}const r=document.createElement("script");r.async=!0,r.src=n,r.id=t,document.head.appendChild(r),r.onload=()=>e(),r.onerror=i=>{if(i instanceof Event){const s=i.target;let l="";s&&(l=s.src),e(new URIError(`The script ${l} didn't load correctly.`))}else e(new URIError(`The script ${i} didn't load correctly.`))}}async function $o(n,t){const e=new Promise((o,r)=>{cm(n,t,i=>{i?r(i):o(void 0)})});try{await qe.lock(t),await e}finally{qe.release(t)}}function nd(n,t){Object.entries(t).forEach(([e,o])=>{n.dataset[e]=`${o}`})}function od(n,t){Object.entries(t).forEach(([e,o])=>{n.setAttribute(e,o)})}function rd(n,t){Object.entries(t).forEach(([e,o])=>{n.style.setProperty(e,o)})}function Mi(n){let t=0,e=0,o=n;do t+=o.offsetTop||0,e+=o.offsetLeft||0,o=o.offsetParent;while(o);return{top:t,left:e}}function Ri(n,t){return!n.target||!(n.target instanceof Element)?null:n.target.closest(t)}class W7{constructor(t){h(this,"element");this.element=t}getHorizontalScroll(){return this.element.scrollLeft}getVerticalScroll(){return this.element.scrollTop}getMaxHorizontalScroll(){return this.element.scrollWidth-this.element.clientWidth}getMaxVerticalScroll(){return this.element.scrollHeight-this.element.clientHeight}getHorizontalElementScrollOffset(t,e){return Mi(t).left-Mi(e).left}getVerticalElementScrollOffset(t,e){return Mi(t).top-Mi(e).top}scrollTo(t,e){this.element.scrollLeft=t,this.element.scrollTop=e}}class G7{constructor(){h(this,"element",window)}getHorizontalScroll(){return window.scrollX||document.documentElement.scrollLeft}getVerticalScroll(){return window.scrollY||document.documentElement.scrollTop}getMaxHorizontalScroll(){return Math.max(document.body.scrollWidth,document.documentElement.scrollWidth,document.body.offsetWidth,document.documentElement.offsetWidth,document.body.clientWidth,document.documentElement.clientWidth)-window.innerWidth}getMaxVerticalScroll(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)-window.innerHeight}getHorizontalElementScrollOffset(t){return(window.scrollX||document.documentElement.scrollLeft)+t.getBoundingClientRect().left}getVerticalElementScrollOffset(t){return(window.scrollY||document.documentElement.scrollTop)+t.getBoundingClientRect().top}scrollTo(t,e){window.scrollTo(t,e)}}const $n={elements:[],cancelMethods:[],add:(n,t)=>{$n.elements.push(n),$n.cancelMethods.push(t)},remove:(n,t)=>{const e=$n.elements.indexOf(n);e>-1&&(t&&$n.cancelMethods[e](),$n.elements.splice(e,1),$n.cancelMethods.splice(e,1))}},am=typeof window<"u",Z7={cancelOnUserAction:!0,easing:n=>--n*n*n+1,elementToScroll:am?window:null,horizontalOffset:0,maxDuration:3e3,minDuration:250,speed:500,verticalOffset:0};async function id(n,t={}){if(!am)return new Promise(R=>{R(!1)});if(!window.Promise)throw"Browser doesn't support Promises, and animated-scroll-to depends on it, please provide a polyfill.";let e,o,r;const i={...Z7,...t},s=i.elementToScroll===window,l=!!i.elementToScroll.nodeName;if(!s&&!l)throw"Element to scroll needs to be either window or DOM element.";const c=s?document.documentElement:i.elementToScroll;getComputedStyle(c).getPropertyValue("scroll-behavior")==="smooth"&&console.warn(`${c.tagName} has "scroll-behavior: smooth" which can mess up with animated-scroll-to's animations`);const u=s?new G7:new W7(i.elementToScroll);if(n instanceof Element){if(r=n,l&&(!i.elementToScroll.contains(r)||i.elementToScroll.isSameNode(r)))throw"options.elementToScroll has to be a parent of scrollToElement";e=u.getHorizontalElementScrollOffset(r,i.elementToScroll),o=u.getVerticalElementScrollOffset(r,i.elementToScroll)}else if(typeof n=="number")e=u.getHorizontalScroll(),o=n;else if(Array.isArray(n)&&n.length===2)e=n[0]===null?u.getHorizontalScroll():n[0],o=n[1]===null?u.getVerticalScroll():n[1];else throw`Wrong function signature. Check documentation.
11
+ */function U7(n){if(typeof n=="string")return n.length===0?!1:n.charCodeAt(0)>=55296&&n.charCodeAt(0)<=56319;if(n===void 0)return!1;throw new TypeError(`string-character-is-astral-surrogate/isHighSurrogate(): the input is not string but ${typeof n}`)}function td(n){if(typeof n=="string")return n.length===0?!1:n.charCodeAt(0)>=56320&&n.charCodeAt(0)<=57343;if(n===void 0)return!1;throw new TypeError(`string-character-is-astral-surrogate/isLowSurrogate(): the input is not string but ${typeof n}`)}const Li="\u200B";function V7(n){return[...n].length}function q7(n,t,e){const r=[...n];let i;return e===void 0?i=r.length:i=t+e,r.slice(t,i).join("")}const No=B("dom-utils");function A(n,...t){n&&n.nodeType===Node.ELEMENT_NODE&&n.classList.add(...t)}function nt(n,t){return n instanceof HTMLElement?n.classList.contains(t):!1}function z(n,...t){n&&n.nodeType===Node.ELEMENT_NODE&&n.classList.remove(...t),n.classList.length===0&&n.removeAttribute("class")}function b(n,t,e,o){const r=document.createElement(n);return t&&t.length>0&&A(r,...t),e&&e.appendChild(r),o&&(typeof o=="string"?r.innerText=o:nd(r,o)),r}function vr(n,t,e){const o=b("button",t,e);return o.innerHTML=n,o}function rm(n,t,e){const o=b("img",t,e);return o.src=n,o}function im(n,t){try{const e=document.createRange();return e.setStart(n,t),e}catch(e){d(No,!1,`failed to create range: ${n.childNodes.length}, ${t}, ${e.message}`)}}function Cl(n,t,e,o){try{const r=document.createRange();return r.setStart(n,t),r.setEnd(e,o),r}catch(r){d(No,!1,`failed to create expanded range: ${n.childNodes.length}, ${t}, ${e.childNodes.length}, ${o}, ${r.message}`)}}function bl(n){const t=n.getClientRects();return d(No,t.length>=1,"getFirstClientRect: no rects"),t[0]}function $o(n){const t=n.getClientRects();return d(No,t.length>=1,"getLastClientRect: no rects"),t[t.length-1]}function Cn(n,t,e){const o=n.left+n.width/2,r=n.top+n.height/2;return(o-t)**2+(r-e)**2}function sm(n,t,e){const o=n.data;d(No,o,"invalid text node, no data");let r=Number.MAX_SAFE_INTEGER,i=0;const s=document.createRange();for(let l=0;l<=o.length;l++){if(l<o.length&&td(o[l]))continue;s.setStart(n,l);const c=s.getClientRects();for(let a=0;a<c.length;a++){const u=c[a],f=Cn(u,t,e);f<r&&(r=f,i=l)}}return i}function kl(n,t){if(n===t)return 0;if((!n.parentElement||!t.parentElement)&&d(No,!1,"invalid dom node to compare"),n.parentElement===t.parentElement){const i=Array.from(n.parentElement.children);return i.indexOf(n)-i.indexOf(t)}const e=i=>{const s=[i];for(;i.parentElement;)s.unshift(i.parentElement),i=i.parentElement;return s},o=e(n),r=e(t);o[0]!==r[0]&&d(No,!1,"invalid dom node to compare, different tree");for(let i=1;;i++){const s=o[i],l=r[i];if(s===l)continue;const c=o[i-1],a=Array.from(c.children);return a.indexOf(s)-a.indexOf(l)}}function ed(n){var r,i;const t=window.getComputedStyle(n),e=(r=Number.parseInt(t.paddingLeft,10))!=null?r:0,o=(i=Number.parseInt(t.paddingRight,10))!=null?i:0;return e+o}function lm(n){return!document.documentElement.contains(n)}function It(n,t){let e=t;for(;e;){if(n===e)return!0;e=e.parentNode}return!1}function cm(n,t,e){if(document.getElementById(t)){setTimeout(e);return}const r=document.createElement("script");r.async=!0,r.src=n,r.id=t,document.head.appendChild(r),r.onload=()=>e(),r.onerror=i=>{if(i instanceof Event){const s=i.target;let l="";s&&(l=s.src),e(new URIError(`The script ${l} didn't load correctly.`))}else e(new URIError(`The script ${i} didn't load correctly.`))}}async function Po(n,t){const e=new Promise((o,r)=>{cm(n,t,i=>{i?r(i):o(void 0)})});try{await qe.lock(t),await e}finally{qe.release(t)}}function nd(n,t){Object.entries(t).forEach(([e,o])=>{n.dataset[e]=`${o}`})}function od(n,t){Object.entries(t).forEach(([e,o])=>{n.setAttribute(e,o)})}function rd(n,t){Object.entries(t).forEach(([e,o])=>{n.style.setProperty(e,o)})}function Mi(n){let t=0,e=0,o=n;do t+=o.offsetTop||0,e+=o.offsetLeft||0,o=o.offsetParent;while(o);return{top:t,left:e}}function Ri(n,t){return!n.target||!(n.target instanceof Element)?null:n.target.closest(t)}class W7{constructor(t){h(this,"element");this.element=t}getHorizontalScroll(){return this.element.scrollLeft}getVerticalScroll(){return this.element.scrollTop}getMaxHorizontalScroll(){return this.element.scrollWidth-this.element.clientWidth}getMaxVerticalScroll(){return this.element.scrollHeight-this.element.clientHeight}getHorizontalElementScrollOffset(t,e){return Mi(t).left-Mi(e).left}getVerticalElementScrollOffset(t,e){return Mi(t).top-Mi(e).top}scrollTo(t,e){this.element.scrollLeft=t,this.element.scrollTop=e}}class G7{constructor(){h(this,"element",window)}getHorizontalScroll(){return window.scrollX||document.documentElement.scrollLeft}getVerticalScroll(){return window.scrollY||document.documentElement.scrollTop}getMaxHorizontalScroll(){return Math.max(document.body.scrollWidth,document.documentElement.scrollWidth,document.body.offsetWidth,document.documentElement.offsetWidth,document.body.clientWidth,document.documentElement.clientWidth)-window.innerWidth}getMaxVerticalScroll(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)-window.innerHeight}getHorizontalElementScrollOffset(t){return(window.scrollX||document.documentElement.scrollLeft)+t.getBoundingClientRect().left}getVerticalElementScrollOffset(t){return(window.scrollY||document.documentElement.scrollTop)+t.getBoundingClientRect().top}scrollTo(t,e){window.scrollTo(t,e)}}const $n={elements:[],cancelMethods:[],add:(n,t)=>{$n.elements.push(n),$n.cancelMethods.push(t)},remove:(n,t)=>{const e=$n.elements.indexOf(n);e>-1&&(t&&$n.cancelMethods[e](),$n.elements.splice(e,1),$n.cancelMethods.splice(e,1))}},am=typeof window<"u",Z7={cancelOnUserAction:!0,easing:n=>--n*n*n+1,elementToScroll:am?window:null,horizontalOffset:0,maxDuration:3e3,minDuration:250,speed:500,verticalOffset:0};async function id(n,t={}){if(!am)return new Promise(R=>{R(!1)});if(!window.Promise)throw"Browser doesn't support Promises, and animated-scroll-to depends on it, please provide a polyfill.";let e,o,r;const i={...Z7,...t},s=i.elementToScroll===window,l=!!i.elementToScroll.nodeName;if(!s&&!l)throw"Element to scroll needs to be either window or DOM element.";const c=s?document.documentElement:i.elementToScroll;getComputedStyle(c).getPropertyValue("scroll-behavior")==="smooth"&&console.warn(`${c.tagName} has "scroll-behavior: smooth" which can mess up with animated-scroll-to's animations`);const u=s?new G7:new W7(i.elementToScroll);if(n instanceof Element){if(r=n,l&&(!i.elementToScroll.contains(r)||i.elementToScroll.isSameNode(r)))throw"options.elementToScroll has to be a parent of scrollToElement";e=u.getHorizontalElementScrollOffset(r,i.elementToScroll),o=u.getVerticalElementScrollOffset(r,i.elementToScroll)}else if(typeof n=="number")e=u.getHorizontalScroll(),o=n;else if(Array.isArray(n)&&n.length===2)e=n[0]===null?u.getHorizontalScroll():n[0],o=n[1]===null?u.getVerticalScroll():n[1];else throw`Wrong function signature. Check documentation.
12
12
  Available method signatures are:
13
13
  animateScrollTo(y:number, options)
14
14
  animateScrollTo([x:number | null, y:number | null], options)
15
- animateScrollTo(scrollToElement:Element, options)`;e+=i.horizontalOffset,o+=i.verticalOffset;const f=u.getMaxHorizontalScroll(),m=u.getHorizontalScroll();e>f&&(e=f);const C=e-m,k=u.getMaxVerticalScroll(),w=u.getVerticalScroll();w<o?o-=window.innerHeight*3/4:o-=window.innerHeight*1/4,o>k&&(o=k);const y=o-w,S=Math.abs(Math.round(C/1e3*i.speed)),I=Math.abs(Math.round(y/1e3*i.speed));let M=S>I?S:I;return M<i.minDuration?M=i.minDuration:M>i.maxDuration&&(M=i.maxDuration),new Promise((R,$)=>{C===0&&y===0&&R(!0),$n.remove(u.element,!0);let Z;const rt=()=>{le(),cancelAnimationFrame(Z),R(!1)};$n.add(u.element,rt);const st=Ue=>Ue.preventDefault(),mt=i.cancelOnUserAction?rt:st,ut=i.cancelOnUserAction?{passive:!0}:{passive:!1},yt=["wheel","touchstart","keydown","mousedown"],le=()=>{yt.forEach(Ue=>{u.element.removeEventListener(Ue,mt,ut)})};yt.forEach(Ue=>{u.element.addEventListener(Ue,mt,ut)});const eo=Date.now(),ee=()=>{const Ue=Date.now()-eo,Do=Ue/M,pr=Math.round(m+C*i.easing(Do)),Cr=Math.round(w+y*i.easing(Do));Ue<M&&(pr!==e||Cr!==o)?(u.scrollTo(pr,Cr),Z=requestAnimationFrame(ee)):(u.scrollTo(e,o),cancelAnimationFrame(Z),le(),$n.remove(u.element,!1),R(!0))};Z=requestAnimationFrame(ee)})}function Po(n,t,e){return n.left<=t&&t<=n.right&&n.top<=e&&e<=n.bottom}function Y7(n){const t="\xA0";if(!n)return"";if(n===" ")return t;let e=n;return e.startsWith(" ")&&(e=t+e.substr(1)),e.endsWith(" ")&&(e=e.substr(0,e.length-1)+t),e=e.replace(/ {2}/g,` ${t}`),e}function dm(n){if(!/["'&<>]/.exec(n))return n;const o={'"':"&quot;","'":"&#39;","&":"&amp;","<":"&lt;",">":"&gt;"};return n.split("").map(l=>o[l]||l).join("")}function um(n){const t=document.getElementById(n);t&&t.remove()}function hm(n,t){const e=document.getElementById(t);if(e)return e.textContent=n,e;const o=document.createElement("style");return o.id=t,o.textContent=n,document.head.append(o),o}function Ai(n){const t="custom-cursor-style";if(n){const e=`body * { cursor: ${n} !important}`;hm(e,t)}else um(t)}const fm=3,mm=B("drag-drop");class gm{constructor(t){h(this,"dragStarted",!1);h(this,"mouseDownEvent",null);h(this,"_dragOffsetX",0);h(this,"_dragOffsetY",0);h(this,"handleMouseDown",t=>{t.preventDefault(),t.stopPropagation(),this.mouseDownEvent=t;const e=this.options.elem.getBoundingClientRect();this._dragOffsetX=this.mouseDownEvent.x-e.left,this._dragOffsetY=this.mouseDownEvent.y-e.top,this.bindEvents()});h(this,"handleMouseMove",t=>{var i;t.preventDefault(),t.stopPropagation(),d(mm,this.mouseDownEvent,"no mouse down event");const e=t.x-this.mouseDownEvent.x,o=t.y-this.mouseDownEvent.y;if(this.dragStarted){this.onDragging(t,e,o);return}const r=(i=this.options.minThreshold)!=null?i:fm;(Math.abs(e)>=r||Math.abs(o)>=r)&&this.onDragStart(this.mouseDownEvent)});h(this,"handleMouseUp",t=>{if(t.button===0){d(mm,this.mouseDownEvent,"no mouse down event");const e=t.x-this.mouseDownEvent.x,o=t.y-this.mouseDownEvent.y;this.onDragEnd(t,e,o),t.preventDefault(),t.stopPropagation()}});this.options=t,this.options.mouseDownEvent?this.handleMouseDown(this.options.mouseDownEvent):this.trackEvents()}get data(){return this.options.data}get dragOffsetX(){return this._dragOffsetX}get dragOffsetY(){return this._dragOffsetY}get dragOffset(){return{x:this._dragOffsetX,y:this._dragOffsetY}}trackEvents(){this.options.elem.addEventListener("mousedown",this.handleMouseDown)}untrackEvents(){this.options.elem.removeEventListener("mousedown",this.handleMouseDown)}bindEvents(){document.addEventListener("mousemove",this.handleMouseMove),document.addEventListener("mouseup",this.handleMouseUp)}unbindEvents(){document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp)}onDragStart(t){this.dragStarted=!0,this.options.cursor&&Ai(this.options.cursor),this.options.onDragStart(this,t,this.options.elem)}onDragging(t,e,o){this.options.onDragging(this,t,this.options.elem,e,o)}onDragEnd(t,e,o){this.options.cursor&&Ai(null),this.dragStarted&&this.options.onDragEnd(this,t,this.options.elem,e,o),this.unbindEvents(),this.dragStarted=!1}destroy(){this.unbindEvents(),this.untrackEvents()}}function sd(n){return new gm(n)}const Q7=B("character");function pm(n,t){for(let e=0;e<t.length;e++){const o=t[e][0],r=t[e].length>1?t[e][1]:null;if(r===null&&n===o||r!==null&&n>=o&&n<=r)return!0}return!1}function Cm(n){const t=n.charAt(0);return t>="0"&&t<="9"}function bm(n){const t=n.charAt(0);return t>="a"&&t<="z"||t>="A"&&t<="Z"||t.toUpperCase()!==t.toLowerCase()?!0:RegExp(/^\p{L}/,"u").test(t)}function vl(n){const t=[[9,13],[32],[160]];return pm(n.charCodeAt(0),t)}function km(n){const t=[[12352,12687],[13056,13183],[13312,15661],[19968,40959],[63744,64255],[44032,55215]];return pm(n.charCodeAt(0),t)}function ld(n,t){let e=t;return d(Q7,e.length===1,"invalid char length"),e==="]"&&(e="\\]"),e==="\\"&&(e="\\\\"),n.replace(new RegExp(`^[${e}]+|[${e}]+$`,"g"),"")}const Pn=navigator.userAgent;function vm(){const n=navigator.userAgent.toLowerCase();return n.indexOf("safari")!==-1&&!(n.indexOf("chrome")>-1)}function cd(){return navigator.userAgent.toLowerCase().indexOf("firefox")>-1}const xt={isAndroid:!!Pn.match(/Android/i),isIOS:!!Pn.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/i),isIPad:!!Pn.match(/iPad/i),isIPhone:!!Pn.match(/iPhone/i),isLinux:!!Pn.match(/Linux/i),isMac:!!Pn.match(/Macintosh/i),isMobile:!!Pn.match(/AppleWebKit.*Mobile.*/i),isWindows:!!Pn.match(/Window/i),isIe:!!Pn.match(/msie|trident/i),isSafari:vm(),isMobileSafari:!1};xt.isMobileSafari=xt.isMobile&&xt.isSafari;function ad(n){return n?n.length===1||n==="Process"||n==="Unidentified"&&xt.isAndroid:!1}function ym(n){switch(n){case"ArrowDown":case"ArrowUp":case"ArrowLeft":case"ArrowRight":case"End":case"Home":case"PageDown":case"PageUp":return!0;default:return!1}}function K7(n){return ym(n.key)}function J7(n){switch(n){case"ArrowUp":case"ArrowLeft":case"Home":case"PageUp":return!0;default:return!1}}function jo(n){return n.ctrlKey||n.altKey||n.shiftKey||n.metaKey}function X7(n){return n.key?!!(n.ctrlKey||n.metaKey||n.altKey):!1}function wm(n){return xt.isMac?n.metaKey&&!n.ctrlKey:!n.metaKey&&n.ctrlKey}function t8(n){return wm(n)&&!n.altKey&&!n.shiftKey}function e8(n){return!n.metaKey&&!n.ctrlKey&&!n.shiftKey&&n.altKey}function Bm(n){return!jo(n)&&n.key==="Enter"}function n8(n){return n.key==="Enter"&&n.shiftKey&&!n.altKey&&!n.ctrlKey&&!n.metaKey}function dd(n){return!jo(n)&&n.key==="Escape"}function o8(n){return!jo(n)&&n.key==="Delete"}function Em(n){return!jo(n)&&n.key==="Backspace"}function r8(n){return!jo(n)&&n.key==="Tab"}function i8(n){return n.shiftKey&&n.key==="Tab"&&!n.ctrlKey&&!n.metaKey}function s8(n){if(!n)return"";if(xt.isMac){const t=n.replace("CtrlOrCmd","\u2318").replace("Shift","\u21E7").replace("Ctrl","\u2303").replace("Alt","\u2325").replace(/\+(?!$)/gm,""),e={"\u2318":4,"\u21E7":3,"\u2325":2,"\u2303":1};return t.split(/(?=[\s\S])/u).sort((r,i)=>{var c,a;const s=(c=e[r])!=null?c:5,l=(a=e[i])!=null?a:5;return s-l}).join("")}return n.replace("CtrlOrCmd","Ctrl")}function Im(n){const t={ctrl:!1,alt:!1,shift:!1,cmd:!1,key:""},e=n.toLocaleUpperCase().split("+");for(let o=0;o<e.length;o++){const r=e[o];r==="CTRL"||r==="CONTROL"?t.ctrl=!0:r==="ALT"||r==="OPTION"?t.alt=!0:r==="SHIFT"?t.shift=!0:r==="CMD"||r==="COMMAND"?t.cmd=!0:r==="CMDORCTRL"||r==="CTRLORCMD"?xt.isMac?t.cmd=!0:t.ctrl=!0:r==="SPACE"?t.key=" ":t.key=r.substring(0,1)+r.substring(1).toLocaleLowerCase()}return t}function jn(n,t){const e=Im(t);return e.ctrl!==n.ctrlKey||e.alt!==n.altKey||e.shift!==n.shiftKey||xt.isMac&&e.cmd!==n.metaKey?!1:e.key.length===1?e.key===n.key.toUpperCase():e.key.toUpperCase()===n.key.toUpperCase()}function ud(n,t){return Q9.stringifyUrl({url:n,query:t})}function Ho(n){return typeof n=="string"?xi.Base64.encode(n,!0):xi.Base64.fromUint8Array(n,!0)}function yl(n){return xi.Base64.decode(n)}function l8(n){return xi.Base64.toUint8Array(n)}function xm(n){return new Blob([xi.Base64.toUint8Array(n)])}const c8=oo.init([oo.classModule,oo.styleModule,oo.datasetModule,oo.attributesModule,oo.propsModule]);function Oi(n,t){const e=oo.toVNode(n),o=oo.toVNode(t);c8(e,o)}async function Tm(n,t){const e=new FileReader,o=new Promise((i,s)=>{e.onload=i,e.onerror=s});return e.readAsDataURL(new Blob([n],{type:t})),await o,e.result}async function wl(n){const t=new FileReader,e=new Promise((r,i)=>{t.onload=r,t.onerror=i});return t.readAsDataURL(n),await e,t.result}function a8(n,...t){const e=n.tagName.toLowerCase();for(let o=0,r=t.length;o<r;o++)if(e===t[o].toLowerCase())return!0;return!1}function We(n,t){let e=n;for(;e;){const o=window.getComputedStyle(e);if(t!=null&&t.horizontal){if(/auto|scroll/i.test(o.overflowX))break}else if(/auto|scroll/i.test(o.overflowY))break;e=e.parentElement}return(!e||a8(e,"body"))&&(e=document.documentElement),e}function Sm(n){n.preventDefault(),n.stopPropagation()}function Dm(n){if(document.querySelector(`.editor-disable-scroll[data-scroll-id="${n}"]`))return;const t=b("div",["editor-disable-scroll"],null);t.setAttribute("data-scroll-id",n),t.addEventListener("wheel",Sm,{passive:!1}),document.body.appendChild(t)}function Lm(n){const t=document.querySelector(`.editor-disable-scroll[data-scroll-id="${n}"]`);t&&(t.removeEventListener("wheel",Sm),t.remove())}function hd(n,t,e){const o=new Blob([n]),r=new File([o],e,{type:t});return URL.createObjectURL(r)}function Bl(n){const t=document.createElement("template");if("content"in t)return t.innerHTML=n,document.importNode(t.content,!0);const e=document.createDocumentFragment(),o=document.createElement("div");for(o.innerHTML=n;o.firstChild;)e.appendChild(o.firstChild);return e}function Mm(n){const t=document.createElement("div");return t.appendChild(n),t.innerHTML}function Rm(n){let t=n.getPropertyValue("font");if(t)return t;const e=n.getPropertyValue("font-style"),o=n.getPropertyValue("font-variant"),r=n.getPropertyValue("font-weight"),i=n.getPropertyValue("font-size"),s=n.getPropertyValue("font-family");return t=`${e} ${o} ${r} ${i} ${s}`.replace(/ +/g," ").trim(),t}function El(n,t){const o=(El.canvas||(El.canvas=document.createElement("canvas"))).getContext("2d");return o?(typeof t=="string"?t?o.font=t:o.font=Rm(window.getComputedStyle(document.body)):t instanceof Element&&(o.font=Rm(window.getComputedStyle(t))),o.measureText(n).width+4):200}const d8=B("editor-clipboard");async function u8(n,t){if(t.clipboardData){const e=t.clipboardData;for(const o of n)e.setData(o.type,o.data);return!0}return!1}async function Il(n){try{const t={};n.forEach(o=>{t[o.type]=o.data});const e=new ClipboardItem(t);return await navigator.clipboard.write([e]),!0}catch(t){return d8.error(t),!1}}function Fo(n,t){return new Promise((e,o)=>{const r=document.createElement("input");r.type="file",r.style.display="none",t!=null&&t.multiple&&(r.multiple=!0),r.accept=n,r.onchange=()=>{const i=r.files;if(i){const s=t!=null&&t.multiple?Array.from(i):i[0];e(s)}r.remove()},r.onerror=i=>{o(i),r.remove()},r.click()})}function xl(n){return Array.isArray(n)?n.every(t=>t instanceof File):!1}function Am(n){const t=n;if(!t)return"";const e=t.lastIndexOf(".");return e===-1?"":t.slice(e+1)}function Tl(n,t){const e=document.createElement("a");e.setAttribute("download",`${t||""}`),e.setAttribute("href",`${n}`),e.click(),e.remove()}const Om=B("auto-scroll");function _m(n,t){return!(n.scrollHeight===n.clientHeight||t==="top"&&n.scrollTop===0||t==="bottom"&&n.scrollTop+n.clientHeight===n.scrollHeight||t==="left"&&n.scrollLeft===0||t==="right"&&n.scrollLeft+n.clientWidth===n.scrollWidth)}function Nm(n,{direction:t,step:e}){let o=null;const r=t==="left"||t==="right",i=()=>{if(!_m(n,t))return Om.debug("No need for scroll"),null;if(r){const s=n.scrollLeft,l=t==="left"?s-e:s+e;n.scrollLeft=l}else{const s=n.scrollTop,l=t==="top"?s-e:s+e;n.scrollTop=l}return o=requestAnimationFrame(i),o};return o=requestAnimationFrame(i),()=>{o&&cancelAnimationFrame(o)}}class $m{constructor(t){h(this,"cancelScroll",null);h(this,"options");h(this,"scrollDomInfo");h(this,"scrolling",!1);h(this,"getScrollingDirection",t=>{const{x:e,y:o}=t,{top:r,bottom:i,left:s,right:l}=this.scrollDomInfo,{edge:c}=this.options;return c.top&&o>=r&&o<=c.top+r?"top":c.bottom&&o<=i&&o>=i-c.bottom?"bottom":c.left&&e>=s&&e<=s+c.left?"left":c.right&&e<=l&&e>=l-c.right?"right":null});h(this,"handleMouseMove",t=>{var s;const{scrollElement:e,step:o=10,onDirectionChange:r}=this.options,i=this.getScrollingDirection(t);if(i){if(this.scrolling)return;Om.debug(`scroll direction: ${i}`),this.cancelScroll=Nm(e,{direction:i,step:o}),r==null||r(i),this.scrolling=!0}else(s=this.cancelScroll)==null||s.call(this),this.scrolling=!1});this.options=t,this.scrollDomInfo=this.getScrollDomInfo()}getScrollDomInfo(){const{scrollElement:t}=this.options,e=t.clientTop,o=t.clientLeft,r=t.clientHeight,i=t.clientWidth;return{left:o,top:e,right:i,bottom:r}}active(){const{trackMouseEvent:t="mousemove"}=this.options;window.addEventListener(t,this.handleMouseMove,!0)}inactive(){var e;const{trackMouseEvent:t="mousemove"}=this.options;window.removeEventListener(t,this.handleMouseMove,!0),(e=this.cancelScroll)==null||e.call(this),this.scrolling=!1}}function Pm(n,t){if(n===0)return"0 Bytes";const e=1024,o=t||2,r=["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"],i=Math.floor(Math.log(n)/Math.log(e));return`${parseFloat((n/e**i).toFixed(o))} ${r[i]}`}function fd(n,t){let e=`${n}`;const o=t-e.length;for(let r=0;r<o;r++)e=`0${e}`;return e}const{t:zo}=T;function md(n,t){const e=new Date(n).getTime()+864e5*t;return new Date(e)}function h8(n,t){const e=n,o=Math.floor(t/12),r=t-o*12;return o&&e.setFullYear(e.getFullYear()+o),r&&e.setMonth(e.getMonth()+r),e}function f8(n,t){return md(n,t)}function gd(n,t){const e=new Date(n),o=new Date(t);return e.getDate()===o.getDate()&&e.getMonth()===o.getMonth()&&e.getFullYear()===o.getFullYear()}function jm(n){const t=new Date,e=new Date(n);return gd(t,e)}function Hm(n){const t=md(new Date,-1);return gd(t,n)}function m8(n,t){return Math.round((n.getTime()-t.getTime())/864e5)}function Fm(n,t){const e=new Date(n);if(t){const o=e.getFullYear(),r=e.getMonth()+1,i=e.getDate();let s=t;return s=s.replace("yyyy",`${o}`),s=s.replace("mm",fd(r,2)),s=s.replace("dd",fd(i,2)),s=s.replace("m",`${r}`),s=s.replace("d",`${i}`),s}return n.toLocaleDateString()}function pd(n,t){const e=new Date(n),o=new Date;if(e.getTime()-o.getTime()>10*1e3)return T.t("date.dateFromFuture");if(jm(e)){const i=(o.getTime()-n.getTime())/1e3;if(i<10*60)return zo("date.dateJustNow");if(i<60*60)return zo("date.dateMinutesAgo",{num:`${Math.floor(i/60)}`});const s=Math.floor(i/60/60);return s===1?zo("date.date1HourAgo"):zo("date.dateHoursAgo",{num:`${s}`})}if(Hm(n))return zo("date.dateYesterday");const r=Math.floor((o.getTime()-n.getTime())/1e3/24/60/60)+1;return r<14?zo("date.dateDaysAgo",{num:`${r}`}):r<28?zo("date.dateWeeksAgo",{num:`${Math.round(r/7)}`}):Fm(n,t)}function Cd(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function g8(n,t,e){return n.replace(new RegExp(Cd(t),"g"),e)}function p8(n,t,e){return n.replace(new RegExp(Cd(t),"gi"),e)}const zm=B("container-children");function Mt(n){const t=Array.from(n.querySelectorAll(":scope > .container-blocks > div[data-type=editor-block]"));return d(zm,t.length>0,"container have not any child block"),t}function Ut(n){const t=n.querySelector(":scope > .container-blocks > div[data-type=editor-block]");return d(zm,t,"container have not any child block"),t}function Qt(n){const t=Mt(n);return t[t.length-1]}function Ge(n){return Mt(n).length}function yr(n,t){return Mt(n)[t]}const Ze=B("block-dom");function Uo(n){return n instanceof HTMLDivElement?n.getAttribute("data-type")==="editor-block":!1}function Um(n){A(n,"block-hidden")}function Vm(n){z(n,"block-hidden")}function Sl(n){return!nt(n,"block-hidden")}function q(n){const{id:t}=n;return d(Ze,t,"no block id"),t}function ot(n){const t=n.getAttribute("data-block-type");return d(Ze,t,"invalid block dom, no data-type"),t}function F(n){const t=n instanceof Element?n:n.parentElement;if(!t)return null;const e=t.closest("div[data-type=editor-block]");return e||null}function H(n){const t=n.closest("div[data-type=editor-container]");return d(Ze,t,"failed to get block container"),t}function it(n){const t=n.querySelector(":scope >div[data-type=block-content]");return d(Ze,t,"no block content"),t}function Rt(n){let t=n.querySelector(":scope >div[data-type=block-tools]");return t||(t=b("div",[],n),t.setAttribute("data-type","block-tools")),d(Ze,t,"no block tools"),t}function Dl(n){const t=n.querySelector(":scope >div[data-type=block-tools]");return t||null}function qm(n){let t=n.querySelector(":scope > div[data-type=block-background]");return t||(t=b("div",[],n),t.setAttribute("data-type","block-background")),t}function Wm(n,t,e){const o=n.editorDecorators.decorateBlock(t,e),{id:r,type:i}=o;d(Ze,r,"no block id");const s=b("div",[`${i}-block`],null);s.id=r,s.setAttribute("data-type","editor-block"),s.setAttribute("data-block-type",i);const l=n.editorBlockRenders.renderBlock(n,t,e);return l.classes&&A(s,...l.classes),l.attributes&&Object.entries(l.attributes).forEach(([c,a])=>{s.setAttribute(c,a)}),l.styles&&Object.entries(l.styles).forEach(([c,a])=>{s.style.setProperty(c,a)}),s}function ro(n,t){const e=b(t,[],null);return e.setAttribute("data-type","block-content"),n&&n.appendChild(e),e}function Gm(n){const t=b("span",[`${n.type}-box`],null);return t.setAttribute("data-type","editor-box"),t.setAttribute("data-box-type",n.type),t.id=n.id,t}function _i(n){const t=n.getAttribute("data-box-type");return d(Ze,t,"not a valid box element, no type"),t}function bd(n){return n instanceof HTMLSpanElement?n.getAttribute("data-type")==="editor-box":!1}function Zm(n){const{id:t}=n;return d(Ze,t,"no box id"),t}function kd(n){const t=n instanceof Element?n:n.parentElement;if(!t)return null;const e=t.closest("span[data-type=editor-box]");return e||null}function Ym(n){n.innerHTML="",b("span",["box-space-start"],n,Li);const t=b("span",[],n);return t.setAttribute("data-type","box-content"),b("span",["box-space-start"],n,Li),t}function vd(n){const t=n.querySelector("span[data-type=box-content]");return d(Ze,t,"invalid box dom, no content"),t}function Qm(n,t){const e=b("span",[`${n}-insertion`],null);return e.setAttribute("data-type","editor-insertion"),e.setAttribute("data-insertion-id",t),e}function Km(n,t){return n.rootContainer.querySelector(`[data-insertion-id=${t}]`)}function Jm(n){n.innerHTML="",b("span",["insertion-space-start"],n,Li);const t=b("span",[],n);return t.setAttribute("data-type","insertion-content"),b("span",["insertion-space-start"],n,Li),t}function yd(n){const t=n.querySelector("span[data-type=insertion-content]");return d(Ze,t,"invalid insertion-child dom, no content"),t}function gt(n){let t=n.previousElementSibling;for(;t;){if(Uo(t))return t;t=t.nextElementSibling}return null}function dt(n){let t=n.nextElementSibling;for(;t;){if(Uo(t))return t;t=t.nextElementSibling}return null}function wr(n){let t=n.previousElementSibling;for(;t;){if(Uo(t)&&Sl(t))return t;t=t.previousElementSibling}return null}function Br(n){let t=n.nextElementSibling;for(;t;){if(Uo(t)&&Sl(t))return t;t=t.nextElementSibling}return null}function J(n){const t=H(n),o=Mt(t).indexOf(n);return d(Ze,o!==-1,"invalid block & container dom, failed to get block index"),o}function wd(n){return!n||!(n instanceof Node)?!1:!!F(n)}function Ni(n){if(!wd(n))return!1;const t=n,e=t instanceof Element?t:t.parentElement;return e?!!e.closest("div[data-type=block-tools]"):!1}const Xm=B("element");function Bd(n,t,e){const o=b("div",[t],n);return o.setAttribute("data-type","editor-container"),o.setAttribute("data-container-id",e),b("div",["container-blocks"],o),o}function Er(n,t){const e=n.rootElement.querySelector(`[data-container-id=${t}`);return d(Xm,e,`no container: ${t}`),e}function tg(n,t){return n.rootElement.querySelector(`[data-container-id=${t}`)}function Ll(n){const t=n.querySelector(":scope > .container-blocks");return d(Xm,t,"no container blocks element"),t}function C8(n){let t=n.querySelector(":scope > .container-tools");return t||(t=b("div",["container-tools"],n)),t}const eg=B("container");function bn(n){return n.getAttribute("data-type")==="editor-container"}function pt(n){return nt(n,"root")}function Ye(n){return nt(n,"child")}function U(n){const t=n.getAttribute("data-container-id");return d(eg,t,"no id for container"),pt(n)&&d(eg,t==="root",`invalid root container id, : ${t}`),t}function ng(n,t){const e=U(n);return t.getContainerBlocks(e)}const og=B("block-path");function Vo(n){const t=[];let e=n;for(;e;){const o=H(e);if(t.unshift({containerId:U(o),blockIndex:J(e)}),pt(o))return t;const r=F(o);d(og,r,"no parent block"),e=r}return d(og,!1,"no parent block"),[]}const b8=B("child-container-path");function rg(n){if(pt(n))return[];const t=F(n);return d(b8,t,"no parent block"),Vo(t)}const ig=B("load-blocks");function Ed(n,t,e){const o=U(t),r=ng(t,n.doc);d(ig,r.length>0,"no blocks in container");const i=document.createDocumentFragment();r.forEach((l,c)=>{const a=n.editorBlocks.createBlock([...e,{containerId:o,blockIndex:c}],t,l);i.appendChild(a)}),Ll(t).appendChild(i)}function k8(n,t,e){const o=Ll(n),r=Mt(n);return d(ig,t>=0&&t<=r.length,"invalid block index"),t===r.length?o.appendChild(e):o.insertBefore(e,r[t]),e}function v8(n,t,e,o){const r=rg(t);r.push({containerId:U(t),blockIndex:e});const i=n.editorBlocks.createBlock(r,t,o);return k8(t,e,i),i}const sg=B("root-container");class y8{constructor(t,e){h(this,"resizeObserver");h(this,"handleContextMenu",t=>{t.preventDefault()});h(this,"handleResize",()=>{try{this.editor.selection.updateSelection(null),this.editor.emit("resize",this.editor)}catch(t){sg.warn(`failed to update selection while container resizing: ${t.message}`)}});h(this,"handleClick",t=>{var o,r;this.editor.emit("click",this.editor,t);const e=t.target;if(!Ni(e)&&(t.detail===1&&this.editor.input.focus(),t.detail===3&&this.editor.selectionHandler.handleTripleClick(t),t.detail===1&&t.button===0)){const i=document.elementFromPoint(t.clientX,t.clientY);if(i&&It(this.rootContainer,i)){const s=kd(i);if(s){const l=F(s);d(sg,l,"no parent block"),(r=(o=this.editor.editorBoxes.getBoxClass(_i(s)))==null?void 0:o.handleClickBox)==null||r.call(o,this.editor,s,t)}}}});h(this,"handleDblClick",t=>{Ni(t.target)||this.editor.selectionHandler.handleDblClick(t)});h(this,"handleMouseDown",t=>{const e=t.target;if(!!e&&e instanceof Node&&!Ni(e)){if(e instanceof HTMLElement&&e.draggable){this.editor.selectionHandler.handleMouseDown(t),this.editor.selectionHandler.stopSelection(),this.editor.input.focus();return}t.button===0&&(document.addEventListener("mousemove",this.handleMouseMove),document.addEventListener("mouseup",this.handleMouseUp),this.editor.selectionHandler.handleMouseDown(t)),xt.isMobileSafari||(t.preventDefault(),this.editor.input.focus()),t.button===2&&t.stopPropagation()}});h(this,"handleMouseMove",t=>{this.editor.selectionHandler.handleMouseMove(t)});h(this,"handleMouseUp",t=>{t.button===0&&(this.editor.selectionHandler.handleMouseUp(t),document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp))});this.editor=t,this.rootContainer=e,this.editor=t,this.resizeObserver=new ResizeObserver(this.handleResize),this.bindEvents(e)}bindEvents(t){this.resizeObserver.observe(t);const e=this.editor.rootElement;e.onmousedown=this.handleMouseDown,e.ondblclick=this.handleDblClick,e.onclick=this.handleClick,e.oncontextmenu=this.handleContextMenu}unbindEvents(){this.resizeObserver.disconnect();const t=this.editor.rootElement;t.onmousedown=null,t.ondblclick=null,t.onclick=null,t.oncontextmenu=null}destroy(){this.unbindEvents()}reload(){const t=this.editor.selection.range,e=Ll(this.rootContainer);e.innerHTML="",Ed(this.editor,this.rootContainer,[]);const o=this.editor.findBlockById(t.start.blockId);if(o)this.editor.selection.selectBlock(o,0);else{const r=Ut(this.rootContainer);this.editor.selection.selectBlock(r,0)}}}function lg(n){const t=Bd(n.contentElement,"root","root");return n.rootContainer=t,Ed(n,t,[]),new y8(n,t)}function cg(n,t,e,o){const r=tg(n,o);if(r)return e.appendChild(r),r;const i=Bd(e,"child",o);return Ed(n,i,t),i}const ag=B("block-class");function kt(n,t){return n.editorBlocks.getBlockClass(ot(t))}function dg(n,t){const e=n.editorBlocks.getBlockClass(ot(t));return d(ag,e.blockKind==="text",`is not a text block, ${e.blockType}`),e}function xe(n,t){const e=n.editorBlocks.getBlockClass(ot(t));return d(ag,e.blockKind==="complex",`is not a text block, ${e.blockType}`),e}function Ir(n,t){return n.editorBlocks.getBlockClass(t)}const Id=B("block");function W(n,t){return kt(n,t).getBlockTextLength(t)}function ug(n){n.editorBlocks.forEach(t=>{t.clearSelection(n)})}function hg(n,t,e,o){kt(n,t).updateSelection(n,t,e,o)}function xd(n){for(;;){const t=H(n);if(pt(t))return n;const e=F(t);d(Id,e,"no parent block exists for child container"),n=e}}function fg(n,t){const e=kt(n,t);if(!!e.getMinWidth)return e.getMinWidth(n,t)}function mg(n,t,e){const o=kt(n,t);o.handleBlockElementUpdated&&o.handleBlockElementUpdated(n,t,e)}function Ml(n,t,e,o){try{const r=Ir(n,e).convertFrom;return r?r(n,t,o):null}catch{return Id.debug(`unsupported block type: ${e}`),null}}function io(n,t,e){const o=kt(n,t);return o.getClientRects?o.getClientRects(n,t,e):[t.getBoundingClientRect()]}function w8(n,t){const e=kt(n,t);if(e.getBlockStyles)return e.getBlockStyles(n,t);const o=n.getBlockData(t),r=Object.fromEntries(Object.entries(o).filter(([i])=>i.startsWith("style-")));return Object.entries(r).forEach(([,i])=>{const s=typeof i;d(Id,s==="string"||s==="number"||s==="boolean","invalid style value")}),r}function gg(n,t){const e=n.getBoundingClientRect().width;return t.withPadding?e:e-ed(n)}function Td(n,t){let e=Number.MAX_SAFE_INTEGER;const o=Mt(t);for(let i=0;i<o.length;i++){const s=o[i],l=fg(n,s);l&&(e=Math.min(e,l))}return e===Number.MAX_SAFE_INTEGER?void 0:e+ed(t)}function P(n,t){return kt(n,t).blockKind==="text"}function $i(n,t){return n.editorBlocks.getBlockClass(t).blockKind==="text"}function at(n,t){return kt(n,t).blockKind==="complex"}function B8(n,t){return!at(n,t)}function Qe(n,t){return kt(n,t).blockKind}function Tt(n,t){return Qe(n,t)==="text"?W(n,t)===0:!1}function Sd(n,t){const e=Mt(t);return e.length!==1?!1:Tt(n,e[0])}function Ke(n,t,e){return kt(n,t).getCaretRect(t,e)}function E8(n,t){var r,i;const e=kt(n,t);return(i=(r=e.getOptions)==null?void 0:r.call(e,n))!=null?i:{name:ot(t)}}function pg(n,t){var r;const e=kt(n,t);return(r=e.getBlockProperties)==null?void 0:r.call(e,n,t)}function Dd(n,t){var i,s;const e=kt(n,t),o=(i=e.getBlockProperties)==null?void 0:i.call(e,n,t);let r={};o!=null&&o.blockCommands&&(r={...o.blockCommands});for(const l of n.blockHooks){const c=(s=l.commands)==null?void 0:s.call(l,n,t);c&&(r[c.group]=c)}return r}function Cg(n,t,e){var s,l,c,a;const o=kt(n,t),r=(s=o.getBlockProperties)==null?void 0:s.call(o,n,t);let i={};r!=null&&r.blockCommands&&(i={...r.blockCommands});for(const u of n.blockHooks){const f=(l=u.commands)==null?void 0:l.call(u,n,t);f&&(i[f.group]=f)}return(a=(c=i[e])==null?void 0:c.commands)!=null?a:[]}const bg=B("embed-block-common");function Te(n){return ot(n)==="embed"}function Oe(n){d(bg,Te(n),"not an embed block");const t=n.getAttribute("data-embed-type");return d(bg,t,"no embed data type"),t}function I8(n,t){return n.editorEmbeds.getEmbedClass(Oe(t))}function qo(n,t){return n.editorEmbeds.getEmbedClass(t)}async function Ld(n,t,e,o,r){const i=qo(n,t);if(!i.getOptions)return null;const s=i.getOptions(n);if(!s.insertEmbedCommandItems||!s.insertEmbedCommandItems||s.insertEmbedCommandItems.length===0||!s.handleInsertEmptyEmbed)return null;const l=s.insertEmbedCommandItems[0];return s.handleInsertEmptyEmbed(n,{item:l,containerId:e,blockIndex:o,data:r})}function x8(n,t,e,o,r){var l,c;const i=(c=(l=Ir(n,t)).getOptions)==null?void 0:c.call(l,n);if(!i||!i.insertBlockCommandItems||i.insertBlockCommandItems.length===0||!i.handleInsertEmptyBlock)return null;const s=i.insertBlockCommandItems[0];return i.handleInsertEmptyBlock(n,{item:s,containerId:e,blockIndex:o,data:r})}const T8=B("execute-block-command");function kg(n,t,e,o){var a;d(T8,Te(t),"not a embed block");const r=Oe(t),i=qo(n,r);if(!i.getOptions)return;const s=(a=i.getBlockProperties)==null?void 0:a.call(i,n,t),l=s==null?void 0:s.blockCommands;if(!l)return;const c=Object.entries(l);for(const u of c)if(u[0]===e)return u[1].executeCommand(n,t,o)}function vg(n,t,e,o){const r=Dd(n,t);if(!r)return;const i=Object.entries(r);for(const s of i)if(s[0]===e)return s[1].executeCommand(n,t,o)}const S8=B("complex-block-position");class Je{constructor(t,e,o){h(this,"blockId");h(this,"childContainerId");h(this,"custom");t instanceof HTMLElement?this.blockId=q(t):(d(S8,typeof t=="string",`not a valid block id: ${t}`),this.blockId=t),this.childContainerId=e,o!==void 0&&(this.custom=o)}isSimple(){return!1}}const D8=B("simple-block-position");class Vt{constructor(t,e,o){h(this,"blockId");h(this,"offset");h(this,"type");t instanceof HTMLElement?this.blockId=q(t):(d(D8,typeof t=="string",`not a valid block id: ${t}`),this.blockId=t),this.offset=e,this.type=o}isSimple(){return!0}}const Md=B("editor-position");function j(n,t,e){return new Vt(n,t,e)}function wt(n,t,e){return new Je(n,t,e)}function so(n){return n instanceof Vt}function Rd(n){return n instanceof Je}function Ad(n,t,e){if(so(t)&&so(e)){const o=t,r=e;if(o.blockId===r.blockId)return o.offset-r.offset;const i=n.getBlockById(t.blockId),s=n.getBlockById(e.blockId);return d(Md,i!==s,"comparePosition: blocks are the same"),kl(i,s)}if(Rd(t)&&Rd(e)){const o=t,r=e;if(o.childContainerId===r.childContainerId)return 0;const i=n.getContainerById(o.childContainerId),s=n.getContainerById(r.childContainerId);return d(Md,i!==s,"comparePosition: containers are the same"),kl(i,s)}return d(Md,!1,"invalid "),0}const Rl=B("simple-range");class ae{constructor(t,e){h(this,"editor");h(this,"_anchor");h(this,"_focus");h(this,"reverse");this.editor=t,this._anchor=e.anchor,this._focus=e.focus,this.reverse=Ad(this.editor,this._anchor,this._focus)>0}isCollapsed(){return this.start.blockId===this.end.blockId&&this.start.offset===this.end.offset}isEqual(t){if(!(t instanceof ae))return!1;const e=t,{start:o,end:r}=e;return this.start.blockId===o.blockId&&this.start.offset===o.offset&&this.start.type===o.type&&this.end.blockId===r.blockId&&this.end.offset===r.offset&&this.end.type===r.type}isSimple(){return!0}isReverse(){return this.reverse}getEditor(){return this.editor}get start(){return this.reverse?this._focus:this._anchor}get end(){return this.reverse?this._anchor:this._focus}get anchor(){return this._anchor}get focus(){return this._focus}getSelectedBlocks(){const{editor:t}=this,e=t.getBlockById(this.start.blockId),o=t.getBlockById(this.end.blockId);d(Rl,e,"no start block"),d(Rl,o,"no end block");const r=H(e),i=H(o);d(Rl,r===i,"invalid range");const s=[];if(e===o)s.push({block:e,start:this.start,end:this.end});else{const l=J(e),c=J(o);d(Rl,l<c,"invalid range, start > index"),s.push({block:e,start:this.start,end:j(e,W(this.editor,e),"end")});const a=Mt(r);for(let u=l+1;u<c;u+=1){const f=a[u];s.push({block:f,start:j(f,0,"home"),end:j(f,W(this.editor,f),"end")})}s.push({block:o,start:j(o,0,"home"),end:this.end})}return s}getSelectedContainers(){return[]}getAnchorPos(){return this.isReverse()?this.end:this.start}getFocusedPos(){return this.isReverse()?this.start:this.end}clone(){return new ae(this.editor,this)}toDocRange(){return{anchor:this.anchor,focus:this.focus}}}B("unknown-block");function L8(n,t,e,o,r){A(o,"unknown-block");const i=ro(o,"div");return i.innerText=`unknown block (${r.type}): ${JSON.stringify(r)}`,i}function M8(n){return 1}function R8(n,t,e,o){return null}function A8(n,t,e,o){const r=document.elementsFromPoint(e,o)[0];if(!r||!t.contains(r)||!n.contains(t))return null;const i=q(t),s=j(i,0,"home"),l=j(i,1,"end");return new ae(n,{anchor:s,focus:l})}function O8(n,t){const o=it(n).getBoundingClientRect();return new DOMRect(o.left+o.width/2,o.top,1,o.height)}function _8(n,t,e,o){A(t,"selected")}function N8(n){n.rootContainer.querySelectorAll("div.unknown-block[data-type=editor-block]").forEach(t=>{z(t,"selected")})}function $8(n,t,e,o){return`[unknown block, ${t.type}]`}const P8={blockType:"unknown-block",blockKind:"embed",createBlockContent:L8,getBlockTextLength:M8,getRangeFromPoint:A8,moveCaret:R8,getCaretRect:O8,updateSelection:_8,clearSelection:N8,convertTo:$8},Od=B("editor-blocks");class yg{constructor(t){h(this,"blocks",new Map);this.editor=t}registerBlockClass(t){const e=t.blockType,o=this.blocks.get(e);d(Od,!o,`duplicated block type: ${e}`),this.blocks.set(e,t)}getBlockClass(t){const e=this.blocks.get(t);return d(Od,e,`unknown block type: ${t}`),e}hasBlock(t){return this.blocks.has(t)}createBlock(t,e,o){const r=Wm(this.editor,t,o);let i;this.hasBlock(o.type)?i=this.getBlockClass(o.type):i=this.registerUnknownBlock(o.type);const s=i.createBlockContent(this.editor,t,e,r,o);return s.parentElement!==r&&(Od.warn("content parent is not block"),r.appendChild(s)),this.editor.blockHooks.forEach(l=>{var c;(c=l.create)==null||c.call(l,this.editor,t,e,r,o)}),r}forEach(t){this.blocks.forEach(t)}registerUnknownBlock(t){const e={...P8,blockType:t};return this.editor.editorBlocks.registerBlockClass(e),e}}const wg=B("editor-embeds");class Bg{constructor(t){h(this,"objects",new Map);this.editor=t}registerEmbedClass(t){const e=t.embedType,o=this.objects.get(e);d(wg,!o,`duplicated embed object type: ${e}`),this.objects.set(e,t)}getEmbedClass(t){const e=this.objects.get(t);return d(wg,e,`unknown embed type: ${t}`),e}getEmbedClassFromBlock(t){return this.getEmbedClass(Oe(t))}forEach(t){this.objects.forEach(t)}}const Eg=B("embed-block");function j8(n,t,e,o,r){const i=ro(o,"div");d(Eg,r.type==="embed",`not an embed data: ${JSON.stringify(r)}`);const s=r;return d(Eg,s.embedType&&s.embedData,`not an embed data: ${JSON.stringify(s)}`),n.editorEmbeds.getEmbedClass(s.embedType).createEmbedContent(n,i,s,t,e,o),o.setAttribute("data-embed-type",s.embedType),i}function H8(n){return 1}function F8(n,t,e,o){return null}function z8(n,t,e,o){const r=document.elementsFromPoint(e,o)[0];if(!r||!t.contains(r)||!n.contains(t))return null;const i=q(t),s=j(i,0,"home"),l=j(i,1,"end");return new ae(n,{anchor:s,focus:l})}function U8(n,t){const o=it(n).getBoundingClientRect();return new DOMRect(o.left+o.width/2,o.top,1,o.height)}function V8(n,t,e,o){A(t,"selected")}function q8(n){n.rootContainer.querySelectorAll("div.embed-block[data-type=editor-block][data-block-type=embed]").forEach(t=>{z(t,"selected")})}function W8(n,t,e){let o=null;return n.editorEmbeds.forEach(r=>{var s,l;const i=(l=(s=r.convertFrom)==null?void 0:s.call(r,n,t,e))!=null?l:null;i&&(o=i)}),o}function G8(n,t,e,o){const r=qo(n,t.embedType);return r.convertTo?r.convertTo(n,t,e,o):""}function Z8(n,t){const e=I8(n,t);return e.getBlockProperties?e.getBlockProperties(n,t):{}}function Y8(n){const t=new Map,e=[];return n.editorEmbeds.forEach(o=>{if(o.getOptions){const r=o.getOptions(n);r.insertEmbedCommandItems&&r.insertEmbedCommandItems.forEach(i=>{e.push(i),t.set(i.id,o)})}}),{name:"EmbedBlock",insertBlockCommandItems:e,async handleInsertEmptyBlock(o,r){const i=t.get(r.item.id);if(!i||!i.getOptions)return null;const s=i.getOptions(o);return s.handleInsertEmptyEmbed?s.handleInsertEmptyEmbed(o,r):null}}}function Q8(n,t,e,o){const r=Oe(t),i=qo(n,r);!i.handleDeleteBlock||i.handleDeleteBlock(n,t,e,o)}function K8(n,t,e){const o=Oe(t),r=qo(n,o);return r.handleUpdateBlock?r.handleUpdateBlock(n,t,e):!1}function J8(n,t,e,o,r){const i=Oe(t),s=qo(n,i);if(s.handleDropOver)return s.handleDropOver(n,t,e,o,r)}function X8(n,t,e,o,r){const i=Oe(t),s=qo(n,i);if(s.handleDrop&&n.isWritable())return s.handleDrop(n,t,e,o,r)}async function tb(n,t,e){const o=t.embedType,r=n.editorEmbeds.getEmbedClass(o);if(r.toStandardDoc)return r.toStandardDoc(n,t,e)}const Ig={blockType:"embed",blockKind:"embed",createBlockContent:j8,getBlockTextLength:H8,getRangeFromPoint:z8,moveCaret:F8,getCaretRect:U8,updateSelection:V8,clearSelection:q8,convertFrom:W8,convertTo:G8,getBlockProperties:Z8,getOptions:Y8,handleDeleteBlock:Q8,handleUpdateBlock:K8,handleDropOver:J8,handleDrop:X8,toStandardDoc:tb},de=B("complex-block-helper");function Se(n,t){return xe(n,t).getChildContainers(n,t)}function xr(n,t,e,o){return e.isSimple()?(d(de,o.isSimple(),"invalid start and end position"),Se(n,t)):(d(de,!e.isSimple(),"invalid start pos"),d(de,!o.isSimple(),"invalid end pos"),xe(n,t).getSelectedContainers(n,t,e,o))}function eb(n,t){if(J(t)!==0)return!1;const e=F(H(t));if(!e)return!1;d(de,at(n,e),"not a complex block");const o=H(t),i=Se(n,e).indexOf(o);return d(de,i>=0,"not valid child container"),i===0}function _d(n,t){const e=Se(n,t);if(e.length===0)return null;const o=e[0],r=Ut(o);return at(n,r)?_d(n,r):r}function Pi(n,t){const e=Se(n,t);if(e.length===0)return null;const o=e[e.length-1],r=Qt(o);return at(n,r)?Pi(n,r):r}function xg(n,t){d(de,Ye(t),"not a child container");const e=F(t);d(de,e,"no parent block"),d(de,at(n,e),"not a complex block");const o=Se(n,e),r=o.indexOf(t);if(d(de,r!==-1,"child container not found"),r===0){const l=gt(e);return l?at(n,l)?Pi(n,l):l:null}const i=o[r-1],s=Qt(i);return at(n,s)?Pi(n,s):s}function Tg(n,t){d(de,at(n,t),"not a complex block");const e=Se(n,t);if(d(de,e.length>0,"no child container"),e.length===1)return e;const o=e[0],r=o.getBoundingClientRect();let i=r.left,s=r.right;const l=[o];for(let c=1;c<e.length;c++){const a=e[c],u=a.getBoundingClientRect();if(u.right<=i){l.push(a),i=u.left;continue}if(u.left>=s){s=u.right;continue}}return l}function Sg(n,t){d(de,at(n,t),"not a complex block");const e=Se(n,t);if(d(de,e.length>0,"no child container"),e.length===1)return e;const o=e[e.length-1],r=o.getBoundingClientRect();let i=r.left,s=r.right;const l=[o];for(let c=e.length-2;c>=0;c--){const a=e[c],u=a.getBoundingClientRect();if(u.right<=i){l.push(a),i=u.left;continue}if(u.left>=s){s=u.right;continue}}return l}function Dg(n,t,e,o){const r=t.getBoundingClientRect(),i=o<r.top,s=i?Tg(n,t):Sg(n,t);let l=s[0],c=Cn(l.getBoundingClientRect(),e,o);for(let a=1;a<s.length;a++){const u=s[a],f=u.getBoundingClientRect(),m=Cn(f,e,o);m<c&&(l=u,c=m)}return i?Ut(l):Qt(l)}function Al(n,t,e,o){const r=q(t);d(de,r===e.blockId,"invalid start pos"),d(de,r===o.blockId,"invalid end pos");const i=xe(n,t);return i.adjustSelectionPos?i.adjustSelectionPos(n,t,e,o):{anchor:e,focus:o}}class Xe{constructor(t,e){h(this,"editor");h(this,"reverse");h(this,"_anchor");h(this,"_focus");this.editor=t,this._anchor=e.anchor,this._focus=e.focus,this.reverse=Ad(this.editor,this._anchor,this._focus)>0}isCollapsed(){return!1}isEqual(t){if(!(t instanceof Xe))return!1;const e=t,{anchor:o,focus:r}=e;return this._anchor.blockId===o.blockId&&this._anchor.childContainerId===o.childContainerId&&this._focus.blockId===r.blockId&&this._focus.childContainerId===r.childContainerId&&this._anchor.custom===o.custom&&this._focus.custom===r.custom}isReverse(){return this.reverse}isSimple(){return!1}getEditor(){return this.editor}get anchor(){return this._anchor}get focus(){return this._focus}get start(){return this.reverse?this._focus:this._anchor}get end(){return this.reverse?this._anchor:this._focus}getSelectedBlocks(){const t=this.start,e=this.end;return[{block:this.editor.getBlockById(t.blockId),start:t,end:e}]}getAnchorPos(){return this._anchor}getFocusedPos(){return this._focus}getSelectedContainers(){const t=this.editor.getBlockById(this._anchor.blockId);return xr(this.editor,t,this.start,this.end)}clone(){return new Xe(this.editor,this)}toDocRange(){return{anchor:this._anchor,focus:this._focus}}}const nb=B("selection-range");function qt(n,t){const{anchor:e,focus:o}=t;return e instanceof Vt&&o instanceof Vt?new ae(n,{anchor:e,focus:o}):(d(nb,e instanceof Je&&o instanceof Je,"start position type does not math end type"),new Xe(n,{anchor:e,focus:o}))}function At(n,t,e,o){const r=new Vt(t,e,"normal"),i=new Vt(t,o!=null?o:e,"normal");return qt(n,{anchor:r,focus:i})}function ob(n){return!!n.anchor.childContainerId}function lo(n,t){var r,i;if(ob(t)){const s=wt(t.anchor.blockId,t.anchor.childContainerId,(r=t.anchor)==null?void 0:r.custom),l=wt(t.focus.blockId,t.focus.childContainerId,(i=t.focus)==null?void 0:i.custom);return qt(n,{anchor:s,focus:l})}const e=j(t.anchor.blockId,t.anchor.offset,"normal"),o=j(t.focus.blockId,t.focus.offset,"normal");return qt(n,{anchor:e,focus:o})}const rb=B("range-from-point");function Ol(n,t,e){const o=[0,-8,8];for(let r=0;r<o.length;r++){const i=document.elementsFromPoint(t,e+o[r])[0];if(!i||!n.rootContainer.contains(i))continue;const s=F(i);if(!s||!n.contains(s))continue;const l=kt(n,s).getRangeFromPoint(n,s,t,e+o[r]);if(l)return l}return null}function Lg(n,t,e,o){const r=t.getBoundingClientRect();if(o<=r.top){const l=Ut(t),c=j(l,0,"home");return new ae(n,{anchor:c,focus:c})}const i=Qt(t),s=j(i,W(n,i),"end");return new ae(n,{anchor:s,focus:s})}function Mg(n,t,e){const o=Ol(n,t,e);if(o){if(o instanceof ae)return o;d(rb,o instanceof Xe,`invalid range type: ${typeof o}`);const c=o,a=n.getContainerById(c.start.childContainerId);return Lg(n,a,t,e)}const r=document.elementsFromPoint(t,e)[0];if(!r)return null;const{children:i}=r,s=Array.from(i).filter(c=>bn(c));if(s.length===0)return null;const l=s.reduce((c,a)=>{const u=c.getBoundingClientRect(),f=a.getBoundingClientRect();return Cn(u,t,e)>Cn(f,t,e)?a:c});return Lg(n,l,t,e)}function Nd(n,t){const e=[];return Mt(t).forEach(r=>{e.push(r),at(n,r)&&Se(n,r).forEach(s=>{e.push(...Nd(n,s))})}),e}function $d(n,t){let e=Nd(n,n.rootContainer);return t!=null&&t.simpleBlockOnly&&(e=e.filter(o=>!at(n,o))),e}function tn(n,t){const e=n.selection.range.getSelectedBlocks(),o=[];for(const r of e)o.push(r),at(n,r.block)&&xr(n,r.block,r.start,r.end).forEach(s=>{const c=Nd(n,s).map(a=>({block:a,start:j(a,0,"home"),end:j(a,W(n,a),"home")}));o.push(...c)});return t!=null&&t.simpleBlockOnly?o.filter(r=>!at(n,r.block)):o}const dz="",Hn=B("text-block-child");function ji(n){return n.tagName==="SPAN"}function _e(n){return d(Hn,ji(n),"not a valid text child"),n.getAttribute("data-type")==="editor-box"}function Fn(n){return d(Hn,ji(n),"not a valid text child"),n.getAttribute("data-type")==="editor-insertion"}function Hi(n){return!_e(n)&&!Fn(n)}function Rg(n){return d(Hn,ji(n),"not a valid text child"),_e(n)?"box":Fn(n)?"insertion":"text"}function Ne(n){const t=Rg(n);return t==="insertion"?0:t==="box"?1:(d(Hn,n.textContent!==null,"text block content is undefined"),d(Hn,n.textContent.length>=0,"text block content length is negative"),n.textContent.length)}function zn(n){const t=it(n),e=Array.from(t.children);return e.forEach(o=>{d(Hn,ji(o),"not a valid text child")}),e}function _l(n,t){const e=zn(n);let o=0;for(let r=0;r<e.length;r++){const i=e[r],s=Ne(i);if(o+s<t){o+=s;continue}if(o===t)return{prev:e[r-1],next:i,offset:0};if(o+s===t)return{prev:i,next:e[r+1],offset:0};const l=t-o;return d(Hn,l>0,"invalid offset value"),d(Hn,!_e(i),"invalid box child"),{prev:i,next:i,offset:l}}d(Hn,!1,`invalid block child at position: ${t}`)}const Kt=B("text-range");function ib(n,t){const e=(i,s)=>{if(Fn(i))return d(Kt,s===0,`invalid offset for insertion child: ${s}`),{child:i,container:i,offset:2};if(_e(i))return d(Kt,s===0||s===1,`invalid offset for box: ${s}`),{child:i,container:i,offset:s===0?1:2};const l=i.firstChild;return d(Kt,l,"no child node for text child"),d(Kt,l instanceof Text||l instanceof HTMLBRElement,`invalid child for text child, ${l.nodeName}`),l instanceof HTMLBRElement?(d(Kt,s>=0&&s<=0,"invalid offset for text child"),{child:i,container:l,offset:s}):(d(Kt,s>=0&&s<=l.data.length,"invalid offset for text child"),{child:i,container:l,offset:s})};let o=0;const r=zn(n);for(let i=0;i<r.length;i++){const s=r[i],l=Ne(s);if(t===o)return[e(s,0)];if(t<o+l)return[e(s,t-o)];if(t===o+l){const c=[];c.push(e(s,Ne(s)));const a=r[i+1];return a&&c.push(e(a,0)),c}o+=l}d(Kt,!1,"failed to get range info")}function sb(n,t,e){if(t===e?d(Kt,Fn(n),"only insertion child can be zero offset"):d(Kt,t<e,`invalid start & end: ${t}, ${e}`),Fn(n)){d(Kt,t===e,`invalid insertion child range offset: ${t}, ${e}`),d(Kt,t===0,`invalid insertion child range start: ${t}`);const i=n;return d(Kt,i.children.length===3,`invalid insertion dom, children.length = ${i.children.length}`),Cl(i,1,i,2)}if(_e(n)){d(Kt,t+1===e,`invalid box child range offset: ${t}, ${e}`),d(Kt,t===0,`invalid box child range start: ${t}`);const i=n;return d(Kt,i.children.length===3,`invalid box dom, children.length = ${i.children.length}`),Cl(i,1,i,2)}const o=Ne(n);d(Kt,e<=o,`invalid child end: ${e}, ${o}`);const r=n.firstChild;return d(Kt,r instanceof Text,"invalid block text child"),d(Kt,r.data.length>=e,`invalid range end: ${e}, ${r.data.length}`),Cl(r,t,r,e)}const en=B("caret-rect");function lb(n,t){if(bd(t)){const e=t,o=vd(e);if(e.getAttribute("data-box-type")==="br"){const r=it(n),i=Number.parseFloat(window.getComputedStyle(r).lineHeight)||o.getBoundingClientRect().height,s=Array.from(o.getClientRects());d(en,s.length>0,"no box client rects");const l=r.getBoundingClientRect(),c=s[0],a=new DOMRect(l.left,c.bottom,1,i);return s.push(a),s}return o.getClientRects()}return yd(t).getClientRects()}function De(n,t){var l,c;const e=ib(n,t.offset);if(e[1]&&e[0].child!==((l=e[1])==null?void 0:l.child)){if(t.type==="end"){const u=No(e[0].child);return new DOMRect(u.right,u.top,1,u.height)}d(en,e[1],"invalid ranges");const a=bl(e[1].child);return new DOMRect(a.left,a.top,1,a.height)}let r=e[0];if(d(en,e.length>=1,"failed to get block range"),e.length===1)r=e[0];else{if(d(en,e.length>=2,`invalid range info length: ${e.length}`),Fn(e[e.length-1].child)){r=e[e.length-1];const a=r.child,f=yd(a).getClientRects();d(en,f.length>=1,"no client rects for box content");const m=f[f.length-1];return new DOMRect(m.right,m.y,1,m.height)}t.type==="home"?r=e[1]:t.type==="end"||Hi(e[0].child)?r=e[0]:Hi(e[1].child)&&(r=e[1])}if(r.container instanceof HTMLBRElement){d(en,t.offset===0,"invalid offset for empty block text");const a=(c=r.container.parentElement)==null?void 0:c.parentElement;d(en,a===it(n),"invalid br parent, is not block parent");const u=a.getBoundingClientRect();return new DOMRect(u.left,u.top,1,u.height)}const s=im(r.container,r.offset).getClientRects();if(s.length===0){d(en,!Hi(r.child),"only box or insertion child range has zero client rect"),d(en,r.offset===1||r.offset===2,"invalid offset for box or insertion child");const a=r.child,u=lb(n,a);if(d(en,u.length>=1,"no client rects for box content"),r.offset===1){const m=u[0];return new DOMRect(m.x,m.y,1,m.height)}const f=u[u.length-1];return t.type==="end"||r.offset===2?new DOMRect(f.right,f.y,1,f.height):new DOMRect(f.x,f.y,1,f.height)}return d(en,s.length>0,"no client rects for range"),t.type==="home"?s[s.length-1]:s[0]}const cb=B("core");function co(n,t,e,o){const r=Rt(t);let i=r.querySelector(`.block-anchor[data-id=${e}]`);i||(i=b("div",["block-anchor"],r),i.setAttribute("data-id",e));const s=o!=null?o:t.getBoundingClientRect(),l=t.getBoundingClientRect(),c=new DOMRect(s.left-l.left,s.top-l.top,s.width,s.height);return i.style.left=`${c.left}px`,i.style.top=`${c.top}px`,i.style.width=`${c.width}px`,i.style.height=`${c.height}px`,i}function Ag(n,t,e,o){d(cb,P(n,t),"not a text kind block");const r=De(t,j(t,e,"normal")),i=t.getBoundingClientRect(),s=Rt(t);let l=s.querySelector(`.block-anchor[data-id=${o}]`);l||(l=b("div",["block-anchor"],s),l.setAttribute("data-id",o));const c=new DOMRect(r.left-i.left,r.top-i.top,r.width,r.height);return l.style.left=`${c.left}px`,l.style.top=`${c.top}px`,l.style.width=`${c.width}px`,l.style.height=`${c.height}px`,l}function Fi(n){const t=zn(n);let e=0;return t.forEach(o=>{e+=Ne(o)}),e}const Og=B("box");function zi(n){return!n.attributes||!n.attributes.box?!1:(d(Og,n.attributes.box===!0,`invalid op attribute box property, ${n.attributes.box}`),d(Og,n.attributes.type,`no box type: ${JSON.stringify(n)}`),!0)}const _g=B("rich-text-length");function Pd(n){return d(_g,typeof n.insert=="string","op.insert is not string"),n.insert.length}function ue(n){let t=0;return n.forEach(e=>{e.insert&&(d(_g,typeof e.insert=="string","op.insert is not string"),t+=Pd(e))}),t}const kn=B("split-text");function be(n,t,e){if(n=Y.default(n),t===0)return{left:[],right:n};if(t===-1)return{left:n,right:[]};let o=0;for(let r=0;r<n.length;r++){const i=n[r];d(kn,typeof i=="object",`invalid op type, ${typeof i}`),d(kn,typeof i.insert=="string",`invalid op.insert type, ${typeof i.insert}`);const s=Pd(i);if(o+s<t)o+=s;else{if(o+s===t)return{left:n.slice(0,r+1),right:n.slice(r+1)};{d(kn,o+s>t,`invalid offset, ${o}, ${s}, ${t}`);const l=t-o,c=Y.default(i);d(kn,c.insert,"no copied.insert"),d(kn,typeof c.insert=="string","invalid copied.insert type"),c.insert=c.insert.substr(0,l),i.insert=i.insert.substr(l),c.insert===""&&d(kn,!1,"invalid copied.insert, is empty string"),i.insert===""&&d(kn,!1,"invalid op.insert, is empty string");const a=[i,...n.slice(r+1)],u=[...n.splice(0,r),c];return e&&(e.sourceOp=i),{left:u,right:a}}}}throw new Error(`invalid split offset: ${t}, ${JSON.stringify(n)}`)}function Wt(n,t,e){d(kn,t>=0,"invalid offset, < 0"),d(kn,e>0,"invalid length, <= 0"),d(kn,t+e<=ue(n),"invalid offset + length < text length");const{left:o,right:r}=be(n,t+e),{left:i,right:s}=be(o,t);return{left:i,middle:s,right:r}}function Ng(n,t){const e=Array.from(new Set(t)).sort((i,s)=>i-s),o=[];let r=n;for(let i=e.length-1;i>=0;i--){const s=e[i],{left:l,right:c}=be(r,s);r=l,o.unshift(c)}return r.length>0&&o.unshift(r),o}function $g(n,t,e){return Wt(n,t,e).middle}const Tr=B("text-block-content");function ab(n,t,e,o,r){if(d(Tr,o,"no text for block"),o.length===0&&(!r||r.size===0)){e.innerHTML="<span><br></span>";return}const i=[];r&&i.push(...r.keys());const s=f=>n.editorInsertions.createInsertion(e,f),l=(f,m)=>{const C=r==null?void 0:r.get(m);C&&(C.forEach(k=>{f.appendChild(s(k))}),r==null||r.delete(m))},c=document.createDocumentFragment();let a=0;const u=Ng(o,i);for(let f=0;f<u.length;f++){l(c,a);const m=u[f];a+=ue(m);for(let C=0;C<m.length;C++){const k=m[C];if(zi(k)){d(Tr,k.attributes,`op is not an valid box: ${JSON.stringify(k)}`);const y=n.editorBoxes.createBox(e,k.attributes);d(Tr,y instanceof HTMLSpanElement,`invalid box element: ${y.tagName}`),c.appendChild(y);continue}d(Tr,k.insert,`no insert in op: ${JSON.stringify(k)}`);const w=b("span",["text"],c,k.insert);if(k.attributes){const y=n.editorBlockRenders.renderText(t,k.attributes);y.classes&&A(w,...y.classes),y.attributes&&Object.entries(y.attributes).forEach(([S,I])=>{w.setAttribute(S,I)}),y.styles&&Object.entries(y.styles).forEach(([S,I])=>{w.style.setProperty(S,I)})}c.appendChild(w)}}l(c,a),e.innerHTML="",e.appendChild(c)}function Nl(n,t,e,o,r){const{text:i,insertions:s}=n.editorDecorators.decorateText(t,r),l=n.compositingText;if(l){const c=n.selection.range.start;d(Tr,c.isSimple(),"not an simple position while compositing"),c.blockId===e&&s.set(c.offset,[{type:"inputting",id:N(),text:l}])}return ab(n,t,o,i,s)}function db(n){const t=n.rootContainer.querySelectorAll('span[data-type="editor-insertion"].inputting-insertion');t.length&&Tr.debug(`remove ${t.length} temp composition span`),Array.from(t).forEach(e=>e.remove())}const vn=B("client-rects");function ub(n){const t=zn(n);let e=0;const o=[];for(let r=0;r<t.length;r++){const i=t[r],s=Ne(i);o.push({child:i,startBlockOffset:e,endBlockOffset:e+s}),e+=s}return o}function hb(n,t,e,o){d(vn,e<o,`invalid from & to: ${e}, ${o}`);const r=W(n,t);d(vn,e>=0&&o>=0&&e<=r&&o<=r,`invalid offset: ${e}, ${o}, length: ${r}`);const i=ub(t),s=i.findIndex(C=>C.startBlockOffset<=e&&e<C.endBlockOffset),l=i.findIndex(C=>C.startBlockOffset<o&&o<=C.endBlockOffset);if(d(vn,s!==-1,"failed to find start child"),d(vn,l!==-1,"failed to find end child"),d(vn,s<=l,`invalid start index & end index: ${s}, ${l}`),s===l){const C=i[s];return[{child:C.child,startChildOffset:e-C.startBlockOffset,endChildOffset:o-C.startBlockOffset}]}const c=[],a=i[s],u={child:a.child,startChildOffset:e-a.startBlockOffset,endChildOffset:Ne(a.child)};c.push(u);for(let C=s+1;C<l;C++){const k=i[C],w={child:k.child,startChildOffset:0,endChildOffset:k.endBlockOffset-k.startBlockOffset};c.push(w)}const f=i[l],m={child:f.child,startChildOffset:0,endChildOffset:o-f.startBlockOffset};return c.push(m),c}function fb(n){const t=(o,r)=>o.left<=r.left&&o.top<=r.top&&o.right>=r.right&&o.bottom>=r.bottom&&(o.width!==r.width||o.height!==r.height);n=n.filter(o=>!n.find(i=>t(o,i)));const e=[];return n=n.filter(o=>e.find(r=>r.left===o.left&&r.top===o.top&&r.width===o.width&&r.height===o.height)?!1:(e.push(o),!0)),n}function Pg(n,t,e,o){if(W(n,t)===0){const u=it(t).getBoundingClientRect();return[new DOMRect(u.left,u.top,4,u.height)]}const r=e.offset,i=o.offset;if(r===i)return[De(t,e)];const l=hb(n,t,r,i).map(a=>sb(a.child,a.startChildOffset,a.endChildOffset)),c=[];return l.forEach(a=>{const u=fb(Array.from(a.getClientRects()));c.push(...u)}),c}function mb(n,t,e){d(vn,e instanceof ae,"invalid range");const o=e.start,r=e.end;return d(vn,o.isSimple(),"text block only allow simple position"),d(vn,r.isSimple(),"text block only allow simple position"),d(vn,o.blockId===r.blockId,"only allow update one text block selection"),d(vn,o.blockId===q(t),"only allow update one text block selection"),Pg(n,t,o,r)}const jd=B("selection-background");function gb(n,t,e,o){d(jd,e.isSimple(),"text block only allow simple position"),d(jd,o.isSimple(),"text block only allow simple position"),d(jd,e.blockId===o.blockId,"only allow update one text block selection");const r=e.offset,i=o.offset;if(r===i&&(W(n,t)!==0||n.selection.range.isCollapsed()))return;const s=Pg(n,t,e,o),l=t.getBoundingClientRect(),c=qm(t);c.innerHTML="",s.forEach(a=>{const u=b("div",["editor-selection-background"],c);u.style.left=`${a.left-l.left}px`,u.style.top=`${a.top-l.top}px`,u.style.width=`${a.width}px`,u.style.height=`${a.height}px`})}function pb(n){n.rootContainer.querySelectorAll("div[data-type=block-background]").forEach(t=>{t.remove()})}const Wo=B("text-offset"),jg="\u200D";function ao(n,t){const e=zn(n);let o=0;for(let r=0;r<e.length;r++){const i=e[r],s=Ne(i);if(i===t){const l=o+s;return{start:o,end:l}}o+=s}d(Wo,!1,"can not find child in children")}function re(n,t){d(Wo,t>=0,`invalid offset: ${t}`);const e=_l(n,t),{prev:o,next:r,offset:i}=e;if(!o&&!r&&d(Wo,!1,"invalid offset, no prev & next child at offset"),o!==r)return!0;const s=o;if(d(Wo,s,"no child"),_e(s))return d(Wo,i===0||i===1,`invalid box child offset: ${i}`),!0;const l=s.textContent;d(Wo,l,"no content for text child");const c=l.charAt(i-1),a=l.charAt(i);return!(c===jg||a===jg||td(l[i]))}function uo(n,t){if(t===0)return 0;const e=t-1;if(re(n,e))return e;let o=e-1;for(;!re(n,o);)o-=1;return o}function Go(n,t){const e=Fi(n);if(d(Wo,t>=0&&t<=e,`invalid offset: ${t}, ${e}`),t===e)return e;const o=t+1;if(re(n,o))return o;let r=o+1;for(;!re(n,r);)r+=1;return r}const Zo=B("line-breaker");function Ui(n){const t=c=>{const a=bl(c);return No(c).top>a.top+a.height/2},e=(c,a)=>{const u=No(c);return bl(a).left<u.right},o=(c,a)=>{const u=No(c),f=No(a);return f.top+f.height/2>u.bottom},r=c=>{if(c.length===0||c.length===1)return!1;const a=c[0],u=c[c.length-1];return a.right-u.left>10},i=[];let s=0;const l=zn(n);for(let c=0;c<l.length;c++){const a=l[c];if(Fn(a)){const y=a,S=l[c+1];if(!S)break;const I=l[c-1];if(I&&o(I,y)&&i.push({offset:s,type:"betweenChild",childInfo:{prevChild:I,nextChild:y,wrap:"nextWrapped",prevWrapped:t(I),nextWrapped:t(y)}}),e(y,S)){i.push({offset:s,type:"betweenChild",childInfo:{prevChild:I,nextChild:y,wrap:"nowrap",prevWrapped:t(I),nextWrapped:t(y)}});continue}continue}if(_e(a)){const y=a,S=l[c+1];if(!S)break;const I=l[c-1];if(I&&o(I,y)&&i.push({offset:s,type:"betweenChild",childInfo:{prevChild:I,nextChild:y,wrap:"nextWrapped",prevWrapped:t(I),nextWrapped:t(y)}}),e(y,S)){s+=1,i.push({offset:s,type:"betweenChild",childInfo:{prevChild:I,nextChild:a,wrap:"nowrap",prevWrapped:t(I),nextWrapped:t(a)}});continue}s+=1;continue}const u=a,f=u.getClientRects();if(d(Zo,f.length>0,"invalid text child dom"),f.length===1){const y=l[c+1];if(!y)break;if(e(u,y)){s+=Ne(u),i.push({offset:s,type:"betweenChild",childInfo:{prevChild:u,nextChild:y,wrap:"nowrap",prevWrapped:t(u),nextWrapped:t(y)}});continue}s+=Ne(u);continue}const m=u.firstChild;d(Zo,m,"invalid text child, no text node"),d(Zo,m instanceof Text,`invalid text child, not a valid text node: ${typeof m}`);const C=document.createRange(),k=document.createRange(),w=Ne(u);d(Zo,m.data.length===w,"text node data length not equal child text length");for(let y=0;y<m.data.length;y++){if(!re(n,s+y))continue;C.setStart(m,y),cd()&&C.selectNodeContents(m);const S=C.getClientRects();if(d(Zo,S.length>=1,"invalid text node, no client rects"),r(S)){const Z=s+y;i.push({offset:Z,type:"textBreakWord",childInfo:{prevChild:a,nextChild:a,wrap:"nowrap",prevWrapped:t(a),nextWrapped:t(a)}});continue}let I=y+1;re(n,s+I)||(I=y+2),k.setStart(m,I);const M=k.getClientRects(),R=S[0];M[0].left<R.right&&d(Zo,!1,"span pre-wrap should not has a line-wrap by white space")}s+=w}return i}function Hd(n,t){const e=Ui(n);for(let o=0;o<e.length;o++){const{offset:r,type:i}=e[o];if(t.offset<r)return{lineIndex:o,lineBreaks:e};if(t.offset===r&&t.type==="end")return{lineIndex:o,lineBreaks:e}}return d(Zo,t.offset<=Fi(n),"invalid position, offset > block length"),{lineIndex:e.length,lineBreaks:e}}const Cb=B("line-offset");function Fd(n){const t=Ui(n),e=[];let o=0;for(let r=0;r<t.length;r++){const i=t[r];e.push({start:o,end:i.offset}),o=i.offset}return e.push({start:o,end:Fi(n)}),e}function $l(n,t){const e=Fd(n);return d(Cb,t>=0&&t<e.length,`invalid line index: ${t}, ${e.length}`),e[t]}function Hg(n,t){const{lineIndex:e}=Hd(n,t);return $l(n,e)}function bb(n){const t=Fd(n),e=n.getBoundingClientRect(),o=[];return t.forEach(({start:r,end:i})=>{const s=j(n,r,"home");let l=De(n,s);const c=j(n,i,"end"),a=De(n,c);l.top+l.height/2<a.top&&(l=new DOMRect(e.left-1e4,a.top,1,a.height));const u=new DOMRect(l.left,a.top,a.left-l.left,a.height),f=new DOMRect(e.left,a.top,e.width,a.height);o.push({start:r,end:i,rect:f,contentRect:u})}),o}function kb(n,t,e){const r=bb(n).find(s=>Po(s.rect,t,e));if(!r)return null;const i=r.contentRect;return t-i.left<i.right-t?j(n,r.start,"home"):j(n,r.end,"end")}function Fg(n,t,e){const o=De(n,t),r=De(n,e),i=o.top+o.height/2,s=r.top+r.height/2,l=r.top<i&&i<r.bottom,c=o.top<s&&s<o.bottom;return l&&c}function zg(n){return Fd(n).length}const Yo=B("find-text-position");function Ug(n,t){const{start:e,end:o}=$l(n,t),r=q(n),i=De(n,j(r,e,"home"));if(!(De(n,j(r,o,"end")).top>i.top+i.height/2))return!1;const c=_l(n,e);return d(Yo,c.next,"no next child at offset"),d(Yo,!Hi(c.next),"next child is not text child"),!0}function vb(n,t){const e=q(n);d(Yo,Ug(n,t),"line is not wrapped");const{start:o,end:r}=$l(n,t),i=j(e,o,"home");for(let s=o+1;s<=r;s+=1){let l="normal";s===o?l="home":s===r&&(l="end");const c=j(e,s,l);if(!Fg(n,i,c))return s-1}return d(Yo,!1,"failed to find wrapped offset"),0}function Pl(n,t,e,o,r,i,s){d(Yo,P(n,t),`not a text kind block: ${ot(t)}`);const{start:l,end:c}=$l(t,e);let a=l;const u=q(t);if(t===o&&Ug(t,e)){const y=vb(t,e);(i==="up"||i==="down"&&Fg(t,r,j(u,l,"home")))&&(a=y+1)}let f=Number.MAX_SAFE_INTEGER;const m=Ke(n,o,r),C=s!=null?s:m.left+m.width/2,k=m.top+m.height/2;let w=j(u,a,"home");for(let y=a;y<=c;y++){if(!re(t,y))continue;let S="normal";y===l?S="home":y===c&&(S="end");const I=j(u,y,S),M=De(t,I),R=Cn(M,C,k);R<f&&(f=R,w=I)}return w}function yb(n,t,e,o,r){return d(Yo,P(n,t),"not a text block"),Pl(n,t,zg(t)-1,e,o,"up",r)}function wb(n,t,e,o,r){return d(Yo,P(n,t),"not a text block"),Pl(n,t,0,e,o,"down",r)}function Bb(n,t,e,o){const{lineIndex:r}=Hd(t,e);if(r===zg(t)-1)return null;const i=Pl(n,t,r+1,t,e,"down",o);return i||null}function Eb(n,t){if(t.offset===0)return null;const e=Ui(n),o=e.find(r=>r.offset===t.offset);if(!o){const r=uo(n,t.offset);return e.find(s=>s.offset===r)?{offset:r,type:"home"}:{offset:r,type:"normal"}}if(o.type==="betweenChild"){if(t.type==="home"&&o.childInfo.wrap==="nowrap")return{offset:t.offset,type:"end"};if(o.childInfo.prevWrapped)return{offset:uo(n,t.offset),type:"normal"}}return{offset:uo(n,t.offset),type:"normal"}}function Ib(n,t){const e=Fi(n);if(t.offset===e)return null;const o=Ui(n),r=o.find(i=>i.offset===t.offset);if(!r){const i=Go(n,t.offset),s=o.find(l=>l.offset===i);return s?s.type==="betweenChild"?{offset:i,type:"end"}:{offset:i,type:"home"}:{offset:i,type:"normal"}}return r.type==="betweenChild"?r.childInfo.wrap==="nowrap"&&t.type==="end"?{offset:t.offset,type:"home"}:{offset:Go(n,t.offset),type:"home"}:{offset:Go(n,t.offset),type:"normal"}}function xb(n,t,e,o){const{lineIndex:r}=Hd(t,e);if(r===0)return null;const i=Pl(n,t,r-1,t,e,"up",o);return i||null}const Tb=B("move-caret");function Sb(n,t,e,o){if(o==="ArrowLeft"){const r=Eb(t,e);return r?j(q(t),r.offset,r.type):null}if(o==="ArrowRight"){const r=Ib(t,e);return r?j(q(t),r.offset,r.type):null}if(o==="ArrowUp"){const r=xb(n,t,e,n.selection.getSuggestedCaretX());return r?j(q(t),r.offset,r.type):null}if(o==="ArrowDown"){const r=Bb(n,t,e,n.selection.getSuggestedCaretX());return r?j(q(t),r.offset,r.type):null}d(Tb,!1,`invalid navigation direction: ${o}`)}const zd=B("text-range");function Db(n){const t=[];return zn(n).forEach(o=>{const r=Array.from(o.getClientRects()).map(i=>({rect:i,child:o}));t.push(...r)}),t}function Lb(n,t,e){const o=Db(n);for(let r=1;r<o.length;r++){const i=o[r-1],s=o[r];if(t>=i.rect.right&&t<=s.rect.left&&e>=i.rect.top&&e<=i.rect.bottom&&e>=s.rect.top&&e<=s.rect.bottom)return ao(n,s.child).start}return null}function Mb(n,t,e,o){const r=document.elementsFromPoint(e,o)[0];if(!r||!t.contains(r)||!n.contains(t))return null;const i=r.closest("div[data-type=block-content]>span");if(!i){const S=t.getBoundingClientRect();if(!Po(S,e,o))return null;const I=Lb(t,e,o);if(I!==null){const R=j(t,I,"normal");return new ae(n,{anchor:R,focus:R})}const M=kb(t,e,o);return M?new ae(n,{anchor:M,focus:M}):null}const s=zn(t);d(zd,s.indexOf(i)!==-1,"failed to find child in children");const l=ao(t,i);d(zd,l,"failed to get child offset");const{start:c}=l;let a,u;Fn(i)||_e(i)?(a=c,u=0):(d(zd,i.firstChild instanceof Text,"child is not text"),a=c+sm(i.firstChild,e,o),u=0);const f=q(t),C=Ui(t).find(S=>S.offset===a);let k="normal";if(C){const S=j(f,a,"home"),I=j(f,a,"end"),M=De(t,S),R=De(t,I),$=Cn(M,e,o),Z=Cn(R,e,o);k=$<Z?"home":"end"}const w=j(f,a,k);let y;return u&&(y=j(f,a+u,k)),new ae(n,{anchor:w,focus:y!=null?y:w})}const Rb=B("create-text-op");function $e(n,t){d(Rb,n,"text is empty");const e={insert:n};return t&&Object.keys(t).length>0&&(e.attributes=t),e}function Ud(n,t){if(n.length===0)return[];if(n.indexOf(`
15
+ animateScrollTo(scrollToElement:Element, options)`;e+=i.horizontalOffset,o+=i.verticalOffset;const f=u.getMaxHorizontalScroll(),m=u.getHorizontalScroll();e>f&&(e=f);const C=e-m,k=u.getMaxVerticalScroll(),w=u.getVerticalScroll();w<o?o-=window.innerHeight*3/4:o-=window.innerHeight*1/4,o>k&&(o=k);const y=o-w,S=Math.abs(Math.round(C/1e3*i.speed)),I=Math.abs(Math.round(y/1e3*i.speed));let M=S>I?S:I;return M<i.minDuration?M=i.minDuration:M>i.maxDuration&&(M=i.maxDuration),new Promise((R,$)=>{C===0&&y===0&&R(!0),$n.remove(u.element,!0);let Z;const rt=()=>{le(),cancelAnimationFrame(Z),R(!1)};$n.add(u.element,rt);const st=Ue=>Ue.preventDefault(),mt=i.cancelOnUserAction?rt:st,ut=i.cancelOnUserAction?{passive:!0}:{passive:!1},yt=["wheel","touchstart","keydown","mousedown"],le=()=>{yt.forEach(Ue=>{u.element.removeEventListener(Ue,mt,ut)})};yt.forEach(Ue=>{u.element.addEventListener(Ue,mt,ut)});const eo=Date.now(),ee=()=>{const Ue=Date.now()-eo,Lo=Ue/M,pr=Math.round(m+C*i.easing(Lo)),Cr=Math.round(w+y*i.easing(Lo));Ue<M&&(pr!==e||Cr!==o)?(u.scrollTo(pr,Cr),Z=requestAnimationFrame(ee)):(u.scrollTo(e,o),cancelAnimationFrame(Z),le(),$n.remove(u.element,!1),R(!0))};Z=requestAnimationFrame(ee)})}function jo(n,t,e){return n.left<=t&&t<=n.right&&n.top<=e&&e<=n.bottom}function Y7(n){const t="\xA0";if(!n)return"";if(n===" ")return t;let e=n;return e.startsWith(" ")&&(e=t+e.substr(1)),e.endsWith(" ")&&(e=e.substr(0,e.length-1)+t),e=e.replace(/ {2}/g,` ${t}`),e}function dm(n){if(!/["'&<>]/.exec(n))return n;const o={'"':"&quot;","'":"&#39;","&":"&amp;","<":"&lt;",">":"&gt;"};return n.split("").map(l=>o[l]||l).join("")}function um(n){const t=document.getElementById(n);t&&t.remove()}function hm(n,t){const e=document.getElementById(t);if(e)return e.textContent=n,e;const o=document.createElement("style");return o.id=t,o.textContent=n,document.head.append(o),o}function Ai(n){const t="custom-cursor-style";if(n){const e=`body * { cursor: ${n} !important}`;hm(e,t)}else um(t)}const fm=3,mm=B("drag-drop");class gm{constructor(t){h(this,"dragStarted",!1);h(this,"mouseDownEvent",null);h(this,"_dragOffsetX",0);h(this,"_dragOffsetY",0);h(this,"handleMouseDown",t=>{t.preventDefault(),t.stopPropagation(),this.mouseDownEvent=t;const e=this.options.elem.getBoundingClientRect();this._dragOffsetX=this.mouseDownEvent.x-e.left,this._dragOffsetY=this.mouseDownEvent.y-e.top,this.bindEvents()});h(this,"handleMouseMove",t=>{var i;t.preventDefault(),t.stopPropagation(),d(mm,this.mouseDownEvent,"no mouse down event");const e=t.x-this.mouseDownEvent.x,o=t.y-this.mouseDownEvent.y;if(this.dragStarted){this.onDragging(t,e,o);return}const r=(i=this.options.minThreshold)!=null?i:fm;(Math.abs(e)>=r||Math.abs(o)>=r)&&this.onDragStart(this.mouseDownEvent)});h(this,"handleMouseUp",t=>{if(t.button===0){d(mm,this.mouseDownEvent,"no mouse down event");const e=t.x-this.mouseDownEvent.x,o=t.y-this.mouseDownEvent.y;this.onDragEnd(t,e,o),t.preventDefault(),t.stopPropagation()}});this.options=t,this.options.mouseDownEvent?this.handleMouseDown(this.options.mouseDownEvent):this.trackEvents()}get data(){return this.options.data}get dragOffsetX(){return this._dragOffsetX}get dragOffsetY(){return this._dragOffsetY}get dragOffset(){return{x:this._dragOffsetX,y:this._dragOffsetY}}trackEvents(){this.options.elem.addEventListener("mousedown",this.handleMouseDown)}untrackEvents(){this.options.elem.removeEventListener("mousedown",this.handleMouseDown)}bindEvents(){document.addEventListener("mousemove",this.handleMouseMove),document.addEventListener("mouseup",this.handleMouseUp)}unbindEvents(){document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp)}onDragStart(t){this.dragStarted=!0,this.options.cursor&&Ai(this.options.cursor),this.options.onDragStart(this,t,this.options.elem)}onDragging(t,e,o){this.options.onDragging(this,t,this.options.elem,e,o)}onDragEnd(t,e,o){this.options.cursor&&Ai(null),this.dragStarted&&this.options.onDragEnd(this,t,this.options.elem,e,o),this.unbindEvents(),this.dragStarted=!1}destroy(){this.unbindEvents(),this.untrackEvents()}}function sd(n){return new gm(n)}const Q7=B("character");function pm(n,t){for(let e=0;e<t.length;e++){const o=t[e][0],r=t[e].length>1?t[e][1]:null;if(r===null&&n===o||r!==null&&n>=o&&n<=r)return!0}return!1}function Cm(n){const t=n.charAt(0);return t>="0"&&t<="9"}function bm(n){const t=n.charAt(0);return t>="a"&&t<="z"||t>="A"&&t<="Z"||t.toUpperCase()!==t.toLowerCase()?!0:RegExp(/^\p{L}/,"u").test(t)}function vl(n){const t=[[9,13],[32],[160]];return pm(n.charCodeAt(0),t)}function km(n){const t=[[12352,12687],[13056,13183],[13312,15661],[19968,40959],[63744,64255],[44032,55215]];return pm(n.charCodeAt(0),t)}function ld(n,t){let e=t;return d(Q7,e.length===1,"invalid char length"),e==="]"&&(e="\\]"),e==="\\"&&(e="\\\\"),n.replace(new RegExp(`^[${e}]+|[${e}]+$`,"g"),"")}const Pn=navigator.userAgent;function vm(){const n=navigator.userAgent.toLowerCase();return n.indexOf("safari")!==-1&&!(n.indexOf("chrome")>-1)}function cd(){return navigator.userAgent.toLowerCase().indexOf("firefox")>-1}const xt={isAndroid:!!Pn.match(/Android/i),isIOS:!!Pn.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/i),isIPad:!!Pn.match(/iPad/i),isIPhone:!!Pn.match(/iPhone/i),isLinux:!!Pn.match(/Linux/i),isMac:!!Pn.match(/Macintosh/i),isMobile:!!Pn.match(/AppleWebKit.*Mobile.*/i),isWindows:!!Pn.match(/Window/i),isIe:!!Pn.match(/msie|trident/i),isSafari:vm(),isMobileSafari:!1};xt.isMobileSafari=xt.isMobile&&xt.isSafari;function ad(n){return n?n.length===1||n==="Process"||n==="Unidentified"&&xt.isAndroid:!1}function ym(n){switch(n){case"ArrowDown":case"ArrowUp":case"ArrowLeft":case"ArrowRight":case"End":case"Home":case"PageDown":case"PageUp":return!0;default:return!1}}function K7(n){return ym(n.key)}function J7(n){switch(n){case"ArrowUp":case"ArrowLeft":case"Home":case"PageUp":return!0;default:return!1}}function Ho(n){return n.ctrlKey||n.altKey||n.shiftKey||n.metaKey}function X7(n){return n.key?!!(n.ctrlKey||n.metaKey||n.altKey):!1}function wm(n){return xt.isMac?n.metaKey&&!n.ctrlKey:!n.metaKey&&n.ctrlKey}function t8(n){return wm(n)&&!n.altKey&&!n.shiftKey}function e8(n){return!n.metaKey&&!n.ctrlKey&&!n.shiftKey&&n.altKey}function Bm(n){return!Ho(n)&&n.key==="Enter"}function n8(n){return n.key==="Enter"&&n.shiftKey&&!n.altKey&&!n.ctrlKey&&!n.metaKey}function dd(n){return!Ho(n)&&n.key==="Escape"}function o8(n){return!Ho(n)&&n.key==="Delete"}function Em(n){return!Ho(n)&&n.key==="Backspace"}function r8(n){return!Ho(n)&&n.key==="Tab"}function i8(n){return n.shiftKey&&n.key==="Tab"&&!n.ctrlKey&&!n.metaKey}function s8(n){if(!n)return"";if(xt.isMac){const t=n.replace("CtrlOrCmd","\u2318").replace("Shift","\u21E7").replace("Ctrl","\u2303").replace("Alt","\u2325").replace(/\+(?!$)/gm,""),e={"\u2318":4,"\u21E7":3,"\u2325":2,"\u2303":1};return t.split(/(?=[\s\S])/u).sort((r,i)=>{var c,a;const s=(c=e[r])!=null?c:5,l=(a=e[i])!=null?a:5;return s-l}).join("")}return n.replace("CtrlOrCmd","Ctrl")}function Im(n){const t={ctrl:!1,alt:!1,shift:!1,cmd:!1,key:""},e=n.toLocaleUpperCase().split("+");for(let o=0;o<e.length;o++){const r=e[o];r==="CTRL"||r==="CONTROL"?t.ctrl=!0:r==="ALT"||r==="OPTION"?t.alt=!0:r==="SHIFT"?t.shift=!0:r==="CMD"||r==="COMMAND"?t.cmd=!0:r==="CMDORCTRL"||r==="CTRLORCMD"?xt.isMac?t.cmd=!0:t.ctrl=!0:r==="SPACE"?t.key=" ":t.key=r.substring(0,1)+r.substring(1).toLocaleLowerCase()}return t}function jn(n,t){const e=Im(t);return e.ctrl!==n.ctrlKey||e.alt!==n.altKey||e.shift!==n.shiftKey||xt.isMac&&e.cmd!==n.metaKey?!1:e.key.length===1?e.key===n.key.toUpperCase():e.key.toUpperCase()===n.key.toUpperCase()}function ud(n,t){return Q9.stringifyUrl({url:n,query:t})}function Fo(n){return typeof n=="string"?xi.Base64.encode(n,!0):xi.Base64.fromUint8Array(n,!0)}function yl(n){return xi.Base64.decode(n)}function l8(n){return xi.Base64.toUint8Array(n)}function xm(n){return new Blob([xi.Base64.toUint8Array(n)])}const c8=oo.init([oo.classModule,oo.styleModule,oo.datasetModule,oo.attributesModule,oo.propsModule]);function Oi(n,t){const e=oo.toVNode(n),o=oo.toVNode(t);c8(e,o)}async function Tm(n,t){const e=new FileReader,o=new Promise((i,s)=>{e.onload=i,e.onerror=s});return e.readAsDataURL(new Blob([n],{type:t})),await o,e.result}async function wl(n){const t=new FileReader,e=new Promise((r,i)=>{t.onload=r,t.onerror=i});return t.readAsDataURL(n),await e,t.result}function a8(n,...t){const e=n.tagName.toLowerCase();for(let o=0,r=t.length;o<r;o++)if(e===t[o].toLowerCase())return!0;return!1}function We(n,t){let e=n;for(;e;){const o=window.getComputedStyle(e);if(t!=null&&t.horizontal){if(/auto|scroll/i.test(o.overflowX))break}else if(/auto|scroll/i.test(o.overflowY))break;e=e.parentElement}return(!e||a8(e,"body"))&&(e=document.documentElement),e}function Sm(n){n.preventDefault(),n.stopPropagation()}function Dm(n){if(document.querySelector(`.editor-disable-scroll[data-scroll-id="${n}"]`))return;const t=b("div",["editor-disable-scroll"],null);t.setAttribute("data-scroll-id",n),t.addEventListener("wheel",Sm,{passive:!1}),document.body.appendChild(t)}function Lm(n){const t=document.querySelector(`.editor-disable-scroll[data-scroll-id="${n}"]`);t&&(t.removeEventListener("wheel",Sm),t.remove())}function hd(n,t,e){const o=new Blob([n]),r=new File([o],e,{type:t});return URL.createObjectURL(r)}function Bl(n){const t=document.createElement("template");if("content"in t)return t.innerHTML=n,document.importNode(t.content,!0);const e=document.createDocumentFragment(),o=document.createElement("div");for(o.innerHTML=n;o.firstChild;)e.appendChild(o.firstChild);return e}function Mm(n){const t=document.createElement("div");return t.appendChild(n),t.innerHTML}function Rm(n){let t=n.getPropertyValue("font");if(t)return t;const e=n.getPropertyValue("font-style"),o=n.getPropertyValue("font-variant"),r=n.getPropertyValue("font-weight"),i=n.getPropertyValue("font-size"),s=n.getPropertyValue("font-family");return t=`${e} ${o} ${r} ${i} ${s}`.replace(/ +/g," ").trim(),t}function El(n,t){const o=(El.canvas||(El.canvas=document.createElement("canvas"))).getContext("2d");return o?(typeof t=="string"?t?o.font=t:o.font=Rm(window.getComputedStyle(document.body)):t instanceof Element&&(o.font=Rm(window.getComputedStyle(t))),o.measureText(n).width+4):200}const d8=B("editor-clipboard");async function u8(n,t){if(t.clipboardData){const e=t.clipboardData;for(const o of n)e.setData(o.type,o.data);return!0}return!1}async function Il(n){try{const t={};n.forEach(o=>{t[o.type]=o.data});const e=new ClipboardItem(t);return await navigator.clipboard.write([e]),!0}catch(t){return d8.error(t),!1}}function zo(n,t){return new Promise((e,o)=>{const r=document.createElement("input");r.type="file",r.style.display="none",t!=null&&t.multiple&&(r.multiple=!0),r.accept=n,r.onchange=()=>{const i=r.files;if(i){const s=t!=null&&t.multiple?Array.from(i):i[0];e(s)}r.remove()},r.onerror=i=>{o(i),r.remove()},r.click()})}function xl(n){return Array.isArray(n)?n.every(t=>t instanceof File):!1}function Am(n){const t=n;if(!t)return"";const e=t.lastIndexOf(".");return e===-1?"":t.slice(e+1)}function Tl(n,t){const e=document.createElement("a");e.setAttribute("download",`${t||""}`),e.setAttribute("href",`${n}`),e.click(),e.remove()}const Om=B("auto-scroll");function _m(n,t){return!(n.scrollHeight===n.clientHeight||t==="top"&&n.scrollTop===0||t==="bottom"&&n.scrollTop+n.clientHeight===n.scrollHeight||t==="left"&&n.scrollLeft===0||t==="right"&&n.scrollLeft+n.clientWidth===n.scrollWidth)}function Nm(n,{direction:t,step:e}){let o=null;const r=t==="left"||t==="right",i=()=>{if(!_m(n,t))return Om.debug("No need for scroll"),null;if(r){const s=n.scrollLeft,l=t==="left"?s-e:s+e;n.scrollLeft=l}else{const s=n.scrollTop,l=t==="top"?s-e:s+e;n.scrollTop=l}return o=requestAnimationFrame(i),o};return o=requestAnimationFrame(i),()=>{o&&cancelAnimationFrame(o)}}class $m{constructor(t){h(this,"cancelScroll",null);h(this,"options");h(this,"scrollDomInfo");h(this,"scrolling",!1);h(this,"getScrollingDirection",t=>{const{x:e,y:o}=t,{top:r,bottom:i,left:s,right:l}=this.scrollDomInfo,{edge:c}=this.options;return c.top&&o>=r&&o<=c.top+r?"top":c.bottom&&o<=i&&o>=i-c.bottom?"bottom":c.left&&e>=s&&e<=s+c.left?"left":c.right&&e<=l&&e>=l-c.right?"right":null});h(this,"handleMouseMove",t=>{var s;const{scrollElement:e,step:o=10,onDirectionChange:r}=this.options,i=this.getScrollingDirection(t);if(i){if(this.scrolling)return;Om.debug(`scroll direction: ${i}`),this.cancelScroll=Nm(e,{direction:i,step:o}),r==null||r(i),this.scrolling=!0}else(s=this.cancelScroll)==null||s.call(this),this.scrolling=!1});this.options=t,this.scrollDomInfo=this.getScrollDomInfo()}getScrollDomInfo(){const{scrollElement:t}=this.options,e=t.clientTop,o=t.clientLeft,r=t.clientHeight,i=t.clientWidth;return{left:o,top:e,right:i,bottom:r}}active(){const{trackMouseEvent:t="mousemove"}=this.options;window.addEventListener(t,this.handleMouseMove,!0)}inactive(){var e;const{trackMouseEvent:t="mousemove"}=this.options;window.removeEventListener(t,this.handleMouseMove,!0),(e=this.cancelScroll)==null||e.call(this),this.scrolling=!1}}function Pm(n,t){if(n===0)return"0 Bytes";const e=1024,o=t||2,r=["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"],i=Math.floor(Math.log(n)/Math.log(e));return`${parseFloat((n/e**i).toFixed(o))} ${r[i]}`}function fd(n,t){let e=`${n}`;const o=t-e.length;for(let r=0;r<o;r++)e=`0${e}`;return e}const{t:Uo}=T;function md(n,t){const e=new Date(n).getTime()+864e5*t;return new Date(e)}function h8(n,t){const e=n,o=Math.floor(t/12),r=t-o*12;return o&&e.setFullYear(e.getFullYear()+o),r&&e.setMonth(e.getMonth()+r),e}function f8(n,t){return md(n,t)}function gd(n,t){const e=new Date(n),o=new Date(t);return e.getDate()===o.getDate()&&e.getMonth()===o.getMonth()&&e.getFullYear()===o.getFullYear()}function jm(n){const t=new Date,e=new Date(n);return gd(t,e)}function Hm(n){const t=md(new Date,-1);return gd(t,n)}function m8(n,t){return Math.round((n.getTime()-t.getTime())/864e5)}function Fm(n,t){const e=new Date(n);if(t){const o=e.getFullYear(),r=e.getMonth()+1,i=e.getDate();let s=t;return s=s.replace("yyyy",`${o}`),s=s.replace("mm",fd(r,2)),s=s.replace("dd",fd(i,2)),s=s.replace("m",`${r}`),s=s.replace("d",`${i}`),s}return n.toLocaleDateString()}function pd(n,t){const e=new Date(n),o=new Date;if(e.getTime()-o.getTime()>10*1e3)return T.t("date.dateFromFuture");if(jm(e)){const i=(o.getTime()-n.getTime())/1e3;if(i<10*60)return Uo("date.dateJustNow");if(i<60*60)return Uo("date.dateMinutesAgo",{num:`${Math.floor(i/60)}`});const s=Math.floor(i/60/60);return s===1?Uo("date.date1HourAgo"):Uo("date.dateHoursAgo",{num:`${s}`})}if(Hm(n))return Uo("date.dateYesterday");const r=Math.floor((o.getTime()-n.getTime())/1e3/24/60/60)+1;return r<14?Uo("date.dateDaysAgo",{num:`${r}`}):r<28?Uo("date.dateWeeksAgo",{num:`${Math.round(r/7)}`}):Fm(n,t)}function Cd(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function g8(n,t,e){return n.replace(new RegExp(Cd(t),"g"),e)}function p8(n,t,e){return n.replace(new RegExp(Cd(t),"gi"),e)}const zm=B("container-children");function Mt(n){const t=Array.from(n.querySelectorAll(":scope > .container-blocks > div[data-type=editor-block]"));return d(zm,t.length>0,"container have not any child block"),t}function Ut(n){const t=n.querySelector(":scope > .container-blocks > div[data-type=editor-block]");return d(zm,t,"container have not any child block"),t}function Qt(n){const t=Mt(n);return t[t.length-1]}function Ge(n){return Mt(n).length}function yr(n,t){return Mt(n)[t]}const Ze=B("block-dom");function Vo(n){return n instanceof HTMLDivElement?n.getAttribute("data-type")==="editor-block":!1}function Um(n){A(n,"block-hidden")}function Vm(n){z(n,"block-hidden")}function Sl(n){return!nt(n,"block-hidden")}function q(n){const{id:t}=n;return d(Ze,t,"no block id"),t}function ot(n){const t=n.getAttribute("data-block-type");return d(Ze,t,"invalid block dom, no data-type"),t}function F(n){const t=n instanceof Element?n:n.parentElement;if(!t)return null;const e=t.closest("div[data-type=editor-block]");return e||null}function H(n){const t=n.closest("div[data-type=editor-container]");return d(Ze,t,"failed to get block container"),t}function it(n){const t=n.querySelector(":scope >div[data-type=block-content]");return d(Ze,t,"no block content"),t}function Rt(n){let t=n.querySelector(":scope >div[data-type=block-tools]");return t||(t=b("div",[],n),t.setAttribute("data-type","block-tools")),d(Ze,t,"no block tools"),t}function Dl(n){const t=n.querySelector(":scope >div[data-type=block-tools]");return t||null}function qm(n){let t=n.querySelector(":scope > div[data-type=block-background]");return t||(t=b("div",[],n),t.setAttribute("data-type","block-background")),t}function Wm(n,t,e){const o=n.editorDecorators.decorateBlock(t,e),{id:r,type:i}=o;d(Ze,r,"no block id");const s=b("div",[`${i}-block`],null);s.id=r,s.setAttribute("data-type","editor-block"),s.setAttribute("data-block-type",i);const l=n.editorBlockRenders.renderBlock(n,t,e);return l.classes&&A(s,...l.classes),l.attributes&&Object.entries(l.attributes).forEach(([c,a])=>{s.setAttribute(c,a)}),l.styles&&Object.entries(l.styles).forEach(([c,a])=>{s.style.setProperty(c,a)}),s}function ro(n,t){const e=b(t,[],null);return e.setAttribute("data-type","block-content"),n&&n.appendChild(e),e}function Gm(n){const t=b("span",[`${n.type}-box`],null);return t.setAttribute("data-type","editor-box"),t.setAttribute("data-box-type",n.type),t.id=n.id,t}function _i(n){const t=n.getAttribute("data-box-type");return d(Ze,t,"not a valid box element, no type"),t}function bd(n){return n instanceof HTMLSpanElement?n.getAttribute("data-type")==="editor-box":!1}function Zm(n){const{id:t}=n;return d(Ze,t,"no box id"),t}function kd(n){const t=n instanceof Element?n:n.parentElement;if(!t)return null;const e=t.closest("span[data-type=editor-box]");return e||null}function Ym(n){n.innerHTML="",b("span",["box-space-start"],n,Li);const t=b("span",[],n);return t.setAttribute("data-type","box-content"),b("span",["box-space-start"],n,Li),t}function vd(n){const t=n.querySelector("span[data-type=box-content]");return d(Ze,t,"invalid box dom, no content"),t}function Qm(n,t){const e=b("span",[`${n}-insertion`],null);return e.setAttribute("data-type","editor-insertion"),e.setAttribute("data-insertion-id",t),e}function Km(n,t){return n.rootContainer.querySelector(`[data-insertion-id=${t}]`)}function Jm(n){n.innerHTML="",b("span",["insertion-space-start"],n,Li);const t=b("span",[],n);return t.setAttribute("data-type","insertion-content"),b("span",["insertion-space-start"],n,Li),t}function yd(n){const t=n.querySelector("span[data-type=insertion-content]");return d(Ze,t,"invalid insertion-child dom, no content"),t}function gt(n){let t=n.previousElementSibling;for(;t;){if(Vo(t))return t;t=t.nextElementSibling}return null}function dt(n){let t=n.nextElementSibling;for(;t;){if(Vo(t))return t;t=t.nextElementSibling}return null}function wr(n){let t=n.previousElementSibling;for(;t;){if(Vo(t)&&Sl(t))return t;t=t.previousElementSibling}return null}function Br(n){let t=n.nextElementSibling;for(;t;){if(Vo(t)&&Sl(t))return t;t=t.nextElementSibling}return null}function J(n){const t=H(n),o=Mt(t).indexOf(n);return d(Ze,o!==-1,"invalid block & container dom, failed to get block index"),o}function wd(n){return!n||!(n instanceof Node)?!1:!!F(n)}function Ni(n){if(!wd(n))return!1;const t=n,e=t instanceof Element?t:t.parentElement;return e?!!e.closest("div[data-type=block-tools]"):!1}const Xm=B("element");function Bd(n,t,e){const o=b("div",[t],n);return o.setAttribute("data-type","editor-container"),o.setAttribute("data-container-id",e),b("div",["container-blocks"],o),o}function Er(n,t){const e=n.rootElement.querySelector(`[data-container-id=${t}`);return d(Xm,e,`no container: ${t}`),e}function tg(n,t){return n.rootElement.querySelector(`[data-container-id=${t}`)}function Ll(n){const t=n.querySelector(":scope > .container-blocks");return d(Xm,t,"no container blocks element"),t}function C8(n){let t=n.querySelector(":scope > .container-tools");return t||(t=b("div",["container-tools"],n)),t}const eg=B("container");function bn(n){return n.getAttribute("data-type")==="editor-container"}function pt(n){return nt(n,"root")}function Ye(n){return nt(n,"child")}function U(n){const t=n.getAttribute("data-container-id");return d(eg,t,"no id for container"),pt(n)&&d(eg,t==="root",`invalid root container id, : ${t}`),t}function ng(n,t){const e=U(n);return t.getContainerBlocks(e)}const og=B("block-path");function io(n){const t=[];let e=n;for(;e;){const o=H(e);if(t.unshift({containerId:U(o),blockIndex:J(e)}),pt(o))return t;const r=F(o);d(og,r,"no parent block"),e=r}return d(og,!1,"no parent block"),[]}const b8=B("child-container-path");function rg(n){if(pt(n))return[];const t=F(n);return d(b8,t,"no parent block"),io(t)}const ig=B("load-blocks");function Ed(n,t,e){const o=U(t),r=ng(t,n.doc);d(ig,r.length>0,"no blocks in container");const i=document.createDocumentFragment();r.forEach((l,c)=>{const a=n.editorBlocks.createBlock([...e,{containerId:o,blockIndex:c}],t,l);i.appendChild(a)}),Ll(t).appendChild(i)}function k8(n,t,e){const o=Ll(n),r=Mt(n);return d(ig,t>=0&&t<=r.length,"invalid block index"),t===r.length?o.appendChild(e):o.insertBefore(e,r[t]),e}function v8(n,t,e,o){const r=rg(t);r.push({containerId:U(t),blockIndex:e});const i=n.editorBlocks.createBlock(r,t,o);return k8(t,e,i),i}const sg=B("root-container");class y8{constructor(t,e){h(this,"resizeObserver");h(this,"handleContextMenu",t=>{t.preventDefault()});h(this,"handleResize",()=>{try{this.editor.selection.updateSelection(null),this.editor.emit("resize",this.editor)}catch(t){sg.warn(`failed to update selection while container resizing: ${t.message}`)}});h(this,"handleClick",t=>{var o,r;this.editor.emit("click",this.editor,t);const e=t.target;if(!Ni(e)&&(t.detail===1&&this.editor.input.focus(),t.detail===3&&this.editor.selectionHandler.handleTripleClick(t),t.detail===1&&t.button===0)){const i=document.elementFromPoint(t.clientX,t.clientY);if(i&&It(this.rootContainer,i)){const s=kd(i);if(s){const l=F(s);d(sg,l,"no parent block"),(r=(o=this.editor.editorBoxes.getBoxClass(_i(s)))==null?void 0:o.handleClickBox)==null||r.call(o,this.editor,s,t)}}}});h(this,"handleDblClick",t=>{Ni(t.target)||this.editor.selectionHandler.handleDblClick(t)});h(this,"handleMouseDown",t=>{const e=t.target;if(!!e&&e instanceof Node&&!Ni(e)){if(e instanceof HTMLElement&&e.draggable){this.editor.selectionHandler.handleMouseDown(t),this.editor.selectionHandler.stopSelection(),this.editor.input.focus();return}t.button===0&&(document.addEventListener("mousemove",this.handleMouseMove),document.addEventListener("mouseup",this.handleMouseUp),this.editor.selectionHandler.handleMouseDown(t)),xt.isMobileSafari||(t.preventDefault(),this.editor.input.focus()),t.button===2&&t.stopPropagation()}});h(this,"handleMouseMove",t=>{this.editor.selectionHandler.handleMouseMove(t)});h(this,"handleMouseUp",t=>{t.button===0&&(this.editor.selectionHandler.handleMouseUp(t),document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp))});this.editor=t,this.rootContainer=e,this.editor=t,this.resizeObserver=new ResizeObserver(this.handleResize),this.bindEvents(e)}bindEvents(t){this.resizeObserver.observe(t);const e=this.editor.rootElement;e.onmousedown=this.handleMouseDown,e.ondblclick=this.handleDblClick,e.onclick=this.handleClick,e.oncontextmenu=this.handleContextMenu}unbindEvents(){this.resizeObserver.disconnect();const t=this.editor.rootElement;t.onmousedown=null,t.ondblclick=null,t.onclick=null,t.oncontextmenu=null}destroy(){this.unbindEvents()}reload(){const t=this.editor.selection.range,e=Ll(this.rootContainer);e.innerHTML="",Ed(this.editor,this.rootContainer,[]);const o=this.editor.findBlockById(t.start.blockId);if(o)this.editor.selection.selectBlock(o,0);else{const r=Ut(this.rootContainer);this.editor.selection.selectBlock(r,0)}}}function lg(n){const t=Bd(n.contentElement,"root","root");return n.rootContainer=t,Ed(n,t,[]),new y8(n,t)}function cg(n,t,e,o){const r=tg(n,o);if(r)return e.appendChild(r),r;const i=Bd(e,"child",o);return Ed(n,i,t),i}const ag=B("block-class");function kt(n,t){return n.editorBlocks.getBlockClass(ot(t))}function dg(n,t){const e=n.editorBlocks.getBlockClass(ot(t));return d(ag,e.blockKind==="text",`is not a text block, ${e.blockType}`),e}function xe(n,t){const e=n.editorBlocks.getBlockClass(ot(t));return d(ag,e.blockKind==="complex",`is not a text block, ${e.blockType}`),e}function Ir(n,t){return n.editorBlocks.getBlockClass(t)}const Id=B("block");function W(n,t){return kt(n,t).getBlockTextLength(t)}function ug(n){n.editorBlocks.forEach(t=>{t.clearSelection(n)})}function hg(n,t,e,o){kt(n,t).updateSelection(n,t,e,o)}function xd(n){for(;;){const t=H(n);if(pt(t))return n;const e=F(t);d(Id,e,"no parent block exists for child container"),n=e}}function fg(n,t){const e=kt(n,t);if(!!e.getMinWidth)return e.getMinWidth(n,t)}function mg(n,t,e){const o=kt(n,t);o.handleBlockElementUpdated&&o.handleBlockElementUpdated(n,t,e)}function Ml(n,t,e,o){try{const r=Ir(n,e).convertFrom;return r?r(n,t,o):null}catch{return Id.debug(`unsupported block type: ${e}`),null}}function so(n,t,e){const o=kt(n,t);return o.getClientRects?o.getClientRects(n,t,e):[t.getBoundingClientRect()]}function w8(n,t){const e=kt(n,t);if(e.getBlockStyles)return e.getBlockStyles(n,t);const o=n.getBlockData(t),r=Object.fromEntries(Object.entries(o).filter(([i])=>i.startsWith("style-")));return Object.entries(r).forEach(([,i])=>{const s=typeof i;d(Id,s==="string"||s==="number"||s==="boolean","invalid style value")}),r}function gg(n,t){const e=n.getBoundingClientRect().width;return t.withPadding?e:e-ed(n)}function Td(n,t){let e=Number.MAX_SAFE_INTEGER;const o=Mt(t);for(let i=0;i<o.length;i++){const s=o[i],l=fg(n,s);l&&(e=Math.min(e,l))}return e===Number.MAX_SAFE_INTEGER?void 0:e+ed(t)}function P(n,t){return kt(n,t).blockKind==="text"}function $i(n,t){return n.editorBlocks.getBlockClass(t).blockKind==="text"}function at(n,t){return kt(n,t).blockKind==="complex"}function B8(n,t){return!at(n,t)}function Qe(n,t){return kt(n,t).blockKind}function Tt(n,t){return Qe(n,t)==="text"?W(n,t)===0:!1}function Sd(n,t){const e=Mt(t);return e.length!==1?!1:Tt(n,e[0])}function Ke(n,t,e){return kt(n,t).getCaretRect(t,e)}function E8(n,t){var r,i;const e=kt(n,t);return(i=(r=e.getOptions)==null?void 0:r.call(e,n))!=null?i:{name:ot(t)}}function pg(n,t){var r;const e=kt(n,t);return(r=e.getBlockProperties)==null?void 0:r.call(e,n,t)}function Dd(n,t){var i,s;const e=kt(n,t),o=(i=e.getBlockProperties)==null?void 0:i.call(e,n,t);let r={};o!=null&&o.blockCommands&&(r={...o.blockCommands});for(const l of n.blockHooks){const c=(s=l.commands)==null?void 0:s.call(l,n,t);c&&(r[c.group]=c)}return r}function Cg(n,t,e){var s,l,c,a;const o=kt(n,t),r=(s=o.getBlockProperties)==null?void 0:s.call(o,n,t);let i={};r!=null&&r.blockCommands&&(i={...r.blockCommands});for(const u of n.blockHooks){const f=(l=u.commands)==null?void 0:l.call(u,n,t);f&&(i[f.group]=f)}return(a=(c=i[e])==null?void 0:c.commands)!=null?a:[]}const bg=B("embed-block-common");function Te(n){return ot(n)==="embed"}function Oe(n){d(bg,Te(n),"not an embed block");const t=n.getAttribute("data-embed-type");return d(bg,t,"no embed data type"),t}function I8(n,t){return n.editorEmbeds.getEmbedClass(Oe(t))}function qo(n,t){return n.editorEmbeds.getEmbedClass(t)}async function Ld(n,t,e,o,r){const i=qo(n,t);if(!i.getOptions)return null;const s=i.getOptions(n);if(!s.insertEmbedCommandItems||!s.insertEmbedCommandItems||s.insertEmbedCommandItems.length===0||!s.handleInsertEmptyEmbed)return null;const l=s.insertEmbedCommandItems[0];return s.handleInsertEmptyEmbed(n,{item:l,containerId:e,blockIndex:o,data:r})}function x8(n,t,e,o,r){var l,c;const i=(c=(l=Ir(n,t)).getOptions)==null?void 0:c.call(l,n);if(!i||!i.insertBlockCommandItems||i.insertBlockCommandItems.length===0||!i.handleInsertEmptyBlock)return null;const s=i.insertBlockCommandItems[0];return i.handleInsertEmptyBlock(n,{item:s,containerId:e,blockIndex:o,data:r})}const T8=B("execute-block-command");function kg(n,t,e,o){var a;d(T8,Te(t),"not a embed block");const r=Oe(t),i=qo(n,r);if(!i.getOptions)return;const s=(a=i.getBlockProperties)==null?void 0:a.call(i,n,t),l=s==null?void 0:s.blockCommands;if(!l)return;const c=Object.entries(l);for(const u of c)if(u[0]===e)return u[1].executeCommand(n,t,o)}function vg(n,t,e,o){const r=Dd(n,t);if(!r)return;const i=Object.entries(r);for(const s of i)if(s[0]===e)return s[1].executeCommand(n,t,o)}const S8=B("complex-block-position");class Je{constructor(t,e,o){h(this,"blockId");h(this,"childContainerId");h(this,"custom");t instanceof HTMLElement?this.blockId=q(t):(d(S8,typeof t=="string",`not a valid block id: ${t}`),this.blockId=t),this.childContainerId=e,o!==void 0&&(this.custom=o)}isSimple(){return!1}}const D8=B("simple-block-position");class Vt{constructor(t,e,o){h(this,"blockId");h(this,"offset");h(this,"type");t instanceof HTMLElement?this.blockId=q(t):(d(D8,typeof t=="string",`not a valid block id: ${t}`),this.blockId=t),this.offset=e,this.type=o}isSimple(){return!0}}const Md=B("editor-position");function j(n,t,e){return new Vt(n,t,e)}function wt(n,t,e){return new Je(n,t,e)}function lo(n){return n instanceof Vt}function Rd(n){return n instanceof Je}function Ad(n,t,e){if(lo(t)&&lo(e)){const o=t,r=e;if(o.blockId===r.blockId)return o.offset-r.offset;const i=n.getBlockById(t.blockId),s=n.getBlockById(e.blockId);return d(Md,i!==s,"comparePosition: blocks are the same"),kl(i,s)}if(Rd(t)&&Rd(e)){const o=t,r=e;if(o.childContainerId===r.childContainerId)return 0;const i=n.getContainerById(o.childContainerId),s=n.getContainerById(r.childContainerId);return d(Md,i!==s,"comparePosition: containers are the same"),kl(i,s)}return d(Md,!1,"invalid "),0}const Rl=B("simple-range");class ae{constructor(t,e){h(this,"editor");h(this,"_anchor");h(this,"_focus");h(this,"reverse");this.editor=t,this._anchor=e.anchor,this._focus=e.focus,this.reverse=Ad(this.editor,this._anchor,this._focus)>0}isCollapsed(){return this.start.blockId===this.end.blockId&&this.start.offset===this.end.offset}isEqual(t){if(!(t instanceof ae))return!1;const e=t,{start:o,end:r}=e;return this.start.blockId===o.blockId&&this.start.offset===o.offset&&this.start.type===o.type&&this.end.blockId===r.blockId&&this.end.offset===r.offset&&this.end.type===r.type}isSimple(){return!0}isReverse(){return this.reverse}getEditor(){return this.editor}get start(){return this.reverse?this._focus:this._anchor}get end(){return this.reverse?this._anchor:this._focus}get anchor(){return this._anchor}get focus(){return this._focus}getSelectedBlocks(){const{editor:t}=this,e=t.getBlockById(this.start.blockId),o=t.getBlockById(this.end.blockId);d(Rl,e,"no start block"),d(Rl,o,"no end block");const r=H(e),i=H(o);d(Rl,r===i,"invalid range");const s=[];if(e===o)s.push({block:e,start:this.start,end:this.end});else{const l=J(e),c=J(o);d(Rl,l<c,"invalid range, start > index"),s.push({block:e,start:this.start,end:j(e,W(this.editor,e),"end")});const a=Mt(r);for(let u=l+1;u<c;u+=1){const f=a[u];s.push({block:f,start:j(f,0,"home"),end:j(f,W(this.editor,f),"end")})}s.push({block:o,start:j(o,0,"home"),end:this.end})}return s}getSelectedContainers(){return[]}getAnchorPos(){return this.isReverse()?this.end:this.start}getFocusedPos(){return this.isReverse()?this.start:this.end}clone(){return new ae(this.editor,this)}toDocRange(){return{anchor:this.anchor,focus:this.focus}}}B("unknown-block");function L8(n,t,e,o,r){A(o,"unknown-block");const i=ro(o,"div");return i.innerText=`unknown block (${r.type}): ${JSON.stringify(r)}`,i}function M8(n){return 1}function R8(n,t,e,o){return null}function A8(n,t,e,o){const r=document.elementsFromPoint(e,o)[0];if(!r||!t.contains(r)||!n.contains(t))return null;const i=q(t),s=j(i,0,"home"),l=j(i,1,"end");return new ae(n,{anchor:s,focus:l})}function O8(n,t){const o=it(n).getBoundingClientRect();return new DOMRect(o.left+o.width/2,o.top,1,o.height)}function _8(n,t,e,o){A(t,"selected")}function N8(n){n.rootContainer.querySelectorAll("div.unknown-block[data-type=editor-block]").forEach(t=>{z(t,"selected")})}function $8(n,t,e,o){return`[unknown block, ${t.type}]`}const P8={blockType:"unknown-block",blockKind:"embed",createBlockContent:L8,getBlockTextLength:M8,getRangeFromPoint:A8,moveCaret:R8,getCaretRect:O8,updateSelection:_8,clearSelection:N8,convertTo:$8},Od=B("editor-blocks");class yg{constructor(t){h(this,"blocks",new Map);this.editor=t}registerBlockClass(t){const e=t.blockType,o=this.blocks.get(e);d(Od,!o,`duplicated block type: ${e}`),this.blocks.set(e,t)}getBlockClass(t){const e=this.blocks.get(t);return d(Od,e,`unknown block type: ${t}`),e}hasBlock(t){return this.blocks.has(t)}createBlock(t,e,o){const r=Wm(this.editor,t,o);let i;this.hasBlock(o.type)?i=this.getBlockClass(o.type):i=this.registerUnknownBlock(o.type);const s=i.createBlockContent(this.editor,t,e,r,o);return s.parentElement!==r&&(Od.warn("content parent is not block"),r.appendChild(s)),this.editor.blockHooks.forEach(l=>{var c;(c=l.create)==null||c.call(l,this.editor,t,e,r,o)}),r}forEach(t){this.blocks.forEach(t)}registerUnknownBlock(t){const e={...P8,blockType:t};return this.editor.editorBlocks.registerBlockClass(e),e}}const wg=B("editor-embeds");class Bg{constructor(t){h(this,"objects",new Map);this.editor=t}registerEmbedClass(t){const e=t.embedType,o=this.objects.get(e);d(wg,!o,`duplicated embed object type: ${e}`),this.objects.set(e,t)}getEmbedClass(t){const e=this.objects.get(t);return d(wg,e,`unknown embed type: ${t}`),e}getEmbedClassFromBlock(t){return this.getEmbedClass(Oe(t))}forEach(t){this.objects.forEach(t)}}const Eg=B("embed-block");function j8(n,t,e,o,r){const i=ro(o,"div");d(Eg,r.type==="embed",`not an embed data: ${JSON.stringify(r)}`);const s=r;return d(Eg,s.embedType&&s.embedData,`not an embed data: ${JSON.stringify(s)}`),n.editorEmbeds.getEmbedClass(s.embedType).createEmbedContent(n,i,s,t,e,o),o.setAttribute("data-embed-type",s.embedType),i}function H8(n){return 1}function F8(n,t,e,o){return null}function z8(n,t,e,o){const r=document.elementsFromPoint(e,o)[0];if(!r||!t.contains(r)||!n.contains(t))return null;const i=q(t),s=j(i,0,"home"),l=j(i,1,"end");return new ae(n,{anchor:s,focus:l})}function U8(n,t){const o=it(n).getBoundingClientRect();return new DOMRect(o.left+o.width/2,o.top,1,o.height)}function V8(n,t,e,o){A(t,"selected")}function q8(n){n.rootContainer.querySelectorAll("div.embed-block[data-type=editor-block][data-block-type=embed]").forEach(t=>{z(t,"selected")})}function W8(n,t,e){let o=null;return n.editorEmbeds.forEach(r=>{var s,l;const i=(l=(s=r.convertFrom)==null?void 0:s.call(r,n,t,e))!=null?l:null;i&&(o=i)}),o}function G8(n,t,e,o){const r=qo(n,t.embedType);return r.convertTo?r.convertTo(n,t,e,o):""}function Z8(n,t){const e=I8(n,t);return e.getBlockProperties?e.getBlockProperties(n,t):{}}function Y8(n){const t=new Map,e=[];return n.editorEmbeds.forEach(o=>{if(o.getOptions){const r=o.getOptions(n);r.insertEmbedCommandItems&&r.insertEmbedCommandItems.forEach(i=>{e.push(i),t.set(i.id,o)})}}),{name:"EmbedBlock",insertBlockCommandItems:e,async handleInsertEmptyBlock(o,r){const i=t.get(r.item.id);if(!i||!i.getOptions)return null;const s=i.getOptions(o);return s.handleInsertEmptyEmbed?s.handleInsertEmptyEmbed(o,r):null}}}function Q8(n,t,e,o){const r=Oe(t),i=qo(n,r);!i.handleDeleteBlock||i.handleDeleteBlock(n,t,e,o)}function K8(n,t,e){const o=Oe(t),r=qo(n,o);return r.handleUpdateBlock?r.handleUpdateBlock(n,t,e):!1}function J8(n,t,e,o,r){const i=Oe(t),s=qo(n,i);if(s.handleDropOver)return s.handleDropOver(n,t,e,o,r)}function X8(n,t,e,o,r){const i=Oe(t),s=qo(n,i);if(s.handleDrop&&n.isWritable())return s.handleDrop(n,t,e,o,r)}async function tb(n,t,e){const o=t.embedType,r=n.editorEmbeds.getEmbedClass(o);if(r.toStandardDoc){const i=n.getBlockById(t.id),s=io(i);return r.toStandardDoc(n,t,e,s)}}const Ig={blockType:"embed",blockKind:"embed",createBlockContent:j8,getBlockTextLength:H8,getRangeFromPoint:z8,moveCaret:F8,getCaretRect:U8,updateSelection:V8,clearSelection:q8,convertFrom:W8,convertTo:G8,getBlockProperties:Z8,getOptions:Y8,handleDeleteBlock:Q8,handleUpdateBlock:K8,handleDropOver:J8,handleDrop:X8,toStandardDoc:tb},de=B("complex-block-helper");function Se(n,t){return xe(n,t).getChildContainers(n,t)}function xr(n,t,e,o){return e.isSimple()?(d(de,o.isSimple(),"invalid start and end position"),Se(n,t)):(d(de,!e.isSimple(),"invalid start pos"),d(de,!o.isSimple(),"invalid end pos"),xe(n,t).getSelectedContainers(n,t,e,o))}function eb(n,t){if(J(t)!==0)return!1;const e=F(H(t));if(!e)return!1;d(de,at(n,e),"not a complex block");const o=H(t),i=Se(n,e).indexOf(o);return d(de,i>=0,"not valid child container"),i===0}function _d(n,t){const e=Se(n,t);if(e.length===0)return null;const o=e[0],r=Ut(o);return at(n,r)?_d(n,r):r}function Pi(n,t){const e=Se(n,t);if(e.length===0)return null;const o=e[e.length-1],r=Qt(o);return at(n,r)?Pi(n,r):r}function xg(n,t){d(de,Ye(t),"not a child container");const e=F(t);d(de,e,"no parent block"),d(de,at(n,e),"not a complex block");const o=Se(n,e),r=o.indexOf(t);if(d(de,r!==-1,"child container not found"),r===0){const l=gt(e);return l?at(n,l)?Pi(n,l):l:null}const i=o[r-1],s=Qt(i);return at(n,s)?Pi(n,s):s}function Tg(n,t){d(de,at(n,t),"not a complex block");const e=Se(n,t);if(d(de,e.length>0,"no child container"),e.length===1)return e;const o=e[0],r=o.getBoundingClientRect();let i=r.left,s=r.right;const l=[o];for(let c=1;c<e.length;c++){const a=e[c],u=a.getBoundingClientRect();if(u.right<=i){l.push(a),i=u.left;continue}if(u.left>=s){s=u.right;continue}}return l}function Sg(n,t){d(de,at(n,t),"not a complex block");const e=Se(n,t);if(d(de,e.length>0,"no child container"),e.length===1)return e;const o=e[e.length-1],r=o.getBoundingClientRect();let i=r.left,s=r.right;const l=[o];for(let c=e.length-2;c>=0;c--){const a=e[c],u=a.getBoundingClientRect();if(u.right<=i){l.push(a),i=u.left;continue}if(u.left>=s){s=u.right;continue}}return l}function Dg(n,t,e,o){const r=t.getBoundingClientRect(),i=o<r.top,s=i?Tg(n,t):Sg(n,t);let l=s[0],c=Cn(l.getBoundingClientRect(),e,o);for(let a=1;a<s.length;a++){const u=s[a],f=u.getBoundingClientRect(),m=Cn(f,e,o);m<c&&(l=u,c=m)}return i?Ut(l):Qt(l)}function Al(n,t,e,o){const r=q(t);d(de,r===e.blockId,"invalid start pos"),d(de,r===o.blockId,"invalid end pos");const i=xe(n,t);return i.adjustSelectionPos?i.adjustSelectionPos(n,t,e,o):{anchor:e,focus:o}}class Xe{constructor(t,e){h(this,"editor");h(this,"reverse");h(this,"_anchor");h(this,"_focus");this.editor=t,this._anchor=e.anchor,this._focus=e.focus,this.reverse=Ad(this.editor,this._anchor,this._focus)>0}isCollapsed(){return!1}isEqual(t){if(!(t instanceof Xe))return!1;const e=t,{anchor:o,focus:r}=e;return this._anchor.blockId===o.blockId&&this._anchor.childContainerId===o.childContainerId&&this._focus.blockId===r.blockId&&this._focus.childContainerId===r.childContainerId&&this._anchor.custom===o.custom&&this._focus.custom===r.custom}isReverse(){return this.reverse}isSimple(){return!1}getEditor(){return this.editor}get anchor(){return this._anchor}get focus(){return this._focus}get start(){return this.reverse?this._focus:this._anchor}get end(){return this.reverse?this._anchor:this._focus}getSelectedBlocks(){const t=this.start,e=this.end;return[{block:this.editor.getBlockById(t.blockId),start:t,end:e}]}getAnchorPos(){return this._anchor}getFocusedPos(){return this._focus}getSelectedContainers(){const t=this.editor.getBlockById(this._anchor.blockId);return xr(this.editor,t,this.start,this.end)}clone(){return new Xe(this.editor,this)}toDocRange(){return{anchor:this._anchor,focus:this._focus}}}const nb=B("selection-range");function qt(n,t){const{anchor:e,focus:o}=t;return e instanceof Vt&&o instanceof Vt?new ae(n,{anchor:e,focus:o}):(d(nb,e instanceof Je&&o instanceof Je,"start position type does not math end type"),new Xe(n,{anchor:e,focus:o}))}function At(n,t,e,o){const r=new Vt(t,e,"normal"),i=new Vt(t,o!=null?o:e,"normal");return qt(n,{anchor:r,focus:i})}function ob(n){return!!n.anchor.childContainerId}function co(n,t){var r,i;if(ob(t)){const s=wt(t.anchor.blockId,t.anchor.childContainerId,(r=t.anchor)==null?void 0:r.custom),l=wt(t.focus.blockId,t.focus.childContainerId,(i=t.focus)==null?void 0:i.custom);return qt(n,{anchor:s,focus:l})}const e=j(t.anchor.blockId,t.anchor.offset,"normal"),o=j(t.focus.blockId,t.focus.offset,"normal");return qt(n,{anchor:e,focus:o})}const rb=B("range-from-point");function Ol(n,t,e){const o=[0,-8,8];for(let r=0;r<o.length;r++){const i=document.elementsFromPoint(t,e+o[r])[0];if(!i||!n.rootContainer.contains(i))continue;const s=F(i);if(!s||!n.contains(s))continue;const l=kt(n,s).getRangeFromPoint(n,s,t,e+o[r]);if(l)return l}return null}function Lg(n,t,e,o){const r=t.getBoundingClientRect();if(o<=r.top){const l=Ut(t),c=j(l,0,"home");return new ae(n,{anchor:c,focus:c})}const i=Qt(t),s=j(i,W(n,i),"end");return new ae(n,{anchor:s,focus:s})}function Mg(n,t,e){const o=Ol(n,t,e);if(o){if(o instanceof ae)return o;d(rb,o instanceof Xe,`invalid range type: ${typeof o}`);const c=o,a=n.getContainerById(c.start.childContainerId);return Lg(n,a,t,e)}const r=document.elementsFromPoint(t,e)[0];if(!r)return null;const{children:i}=r,s=Array.from(i).filter(c=>bn(c));if(s.length===0)return null;const l=s.reduce((c,a)=>{const u=c.getBoundingClientRect(),f=a.getBoundingClientRect();return Cn(u,t,e)>Cn(f,t,e)?a:c});return Lg(n,l,t,e)}function Nd(n,t){const e=[];return Mt(t).forEach(r=>{e.push(r),at(n,r)&&Se(n,r).forEach(s=>{e.push(...Nd(n,s))})}),e}function $d(n,t){let e=Nd(n,n.rootContainer);return t!=null&&t.simpleBlockOnly&&(e=e.filter(o=>!at(n,o))),e}function tn(n,t){const e=n.selection.range.getSelectedBlocks(),o=[];for(const r of e)o.push(r),at(n,r.block)&&xr(n,r.block,r.start,r.end).forEach(s=>{const c=Nd(n,s).map(a=>({block:a,start:j(a,0,"home"),end:j(a,W(n,a),"home")}));o.push(...c)});return t!=null&&t.simpleBlockOnly?o.filter(r=>!at(n,r.block)):o}const dz="",Hn=B("text-block-child");function ji(n){return n.tagName==="SPAN"}function _e(n){return d(Hn,ji(n),"not a valid text child"),n.getAttribute("data-type")==="editor-box"}function Fn(n){return d(Hn,ji(n),"not a valid text child"),n.getAttribute("data-type")==="editor-insertion"}function Hi(n){return!_e(n)&&!Fn(n)}function Rg(n){return d(Hn,ji(n),"not a valid text child"),_e(n)?"box":Fn(n)?"insertion":"text"}function Ne(n){const t=Rg(n);return t==="insertion"?0:t==="box"?1:(d(Hn,n.textContent!==null,"text block content is undefined"),d(Hn,n.textContent.length>=0,"text block content length is negative"),n.textContent.length)}function zn(n){const t=it(n),e=Array.from(t.children);return e.forEach(o=>{d(Hn,ji(o),"not a valid text child")}),e}function _l(n,t){const e=zn(n);let o=0;for(let r=0;r<e.length;r++){const i=e[r],s=Ne(i);if(o+s<t){o+=s;continue}if(o===t)return{prev:e[r-1],next:i,offset:0};if(o+s===t)return{prev:i,next:e[r+1],offset:0};const l=t-o;return d(Hn,l>0,"invalid offset value"),d(Hn,!_e(i),"invalid box child"),{prev:i,next:i,offset:l}}d(Hn,!1,`invalid block child at position: ${t}`)}const Kt=B("text-range");function ib(n,t){const e=(i,s)=>{if(Fn(i))return d(Kt,s===0,`invalid offset for insertion child: ${s}`),{child:i,container:i,offset:2};if(_e(i))return d(Kt,s===0||s===1,`invalid offset for box: ${s}`),{child:i,container:i,offset:s===0?1:2};const l=i.firstChild;return d(Kt,l,"no child node for text child"),d(Kt,l instanceof Text||l instanceof HTMLBRElement,`invalid child for text child, ${l.nodeName}`),l instanceof HTMLBRElement?(d(Kt,s>=0&&s<=0,"invalid offset for text child"),{child:i,container:l,offset:s}):(d(Kt,s>=0&&s<=l.data.length,"invalid offset for text child"),{child:i,container:l,offset:s})};let o=0;const r=zn(n);for(let i=0;i<r.length;i++){const s=r[i],l=Ne(s);if(t===o)return[e(s,0)];if(t<o+l)return[e(s,t-o)];if(t===o+l){const c=[];c.push(e(s,Ne(s)));const a=r[i+1];return a&&c.push(e(a,0)),c}o+=l}d(Kt,!1,"failed to get range info")}function sb(n,t,e){if(t===e?d(Kt,Fn(n),"only insertion child can be zero offset"):d(Kt,t<e,`invalid start & end: ${t}, ${e}`),Fn(n)){d(Kt,t===e,`invalid insertion child range offset: ${t}, ${e}`),d(Kt,t===0,`invalid insertion child range start: ${t}`);const i=n;return d(Kt,i.children.length===3,`invalid insertion dom, children.length = ${i.children.length}`),Cl(i,1,i,2)}if(_e(n)){d(Kt,t+1===e,`invalid box child range offset: ${t}, ${e}`),d(Kt,t===0,`invalid box child range start: ${t}`);const i=n;return d(Kt,i.children.length===3,`invalid box dom, children.length = ${i.children.length}`),Cl(i,1,i,2)}const o=Ne(n);d(Kt,e<=o,`invalid child end: ${e}, ${o}`);const r=n.firstChild;return d(Kt,r instanceof Text,"invalid block text child"),d(Kt,r.data.length>=e,`invalid range end: ${e}, ${r.data.length}`),Cl(r,t,r,e)}const en=B("caret-rect");function lb(n,t){if(bd(t)){const e=t,o=vd(e);if(e.getAttribute("data-box-type")==="br"){const r=it(n),i=Number.parseFloat(window.getComputedStyle(r).lineHeight)||o.getBoundingClientRect().height,s=Array.from(o.getClientRects());d(en,s.length>0,"no box client rects");const l=r.getBoundingClientRect(),c=s[0],a=new DOMRect(l.left,c.bottom,1,i);return s.push(a),s}return o.getClientRects()}return yd(t).getClientRects()}function De(n,t){var l,c;const e=ib(n,t.offset);if(e[1]&&e[0].child!==((l=e[1])==null?void 0:l.child)){if(t.type==="end"){const u=$o(e[0].child);return new DOMRect(u.right,u.top,1,u.height)}d(en,e[1],"invalid ranges");const a=bl(e[1].child);return new DOMRect(a.left,a.top,1,a.height)}let r=e[0];if(d(en,e.length>=1,"failed to get block range"),e.length===1)r=e[0];else{if(d(en,e.length>=2,`invalid range info length: ${e.length}`),Fn(e[e.length-1].child)){r=e[e.length-1];const a=r.child,f=yd(a).getClientRects();d(en,f.length>=1,"no client rects for box content");const m=f[f.length-1];return new DOMRect(m.right,m.y,1,m.height)}t.type==="home"?r=e[1]:t.type==="end"||Hi(e[0].child)?r=e[0]:Hi(e[1].child)&&(r=e[1])}if(r.container instanceof HTMLBRElement){d(en,t.offset===0,"invalid offset for empty block text");const a=(c=r.container.parentElement)==null?void 0:c.parentElement;d(en,a===it(n),"invalid br parent, is not block parent");const u=a.getBoundingClientRect();return new DOMRect(u.left,u.top,1,u.height)}const s=im(r.container,r.offset).getClientRects();if(s.length===0){d(en,!Hi(r.child),"only box or insertion child range has zero client rect"),d(en,r.offset===1||r.offset===2,"invalid offset for box or insertion child");const a=r.child,u=lb(n,a);if(d(en,u.length>=1,"no client rects for box content"),r.offset===1){const m=u[0];return new DOMRect(m.x,m.y,1,m.height)}const f=u[u.length-1];return t.type==="end"||r.offset===2?new DOMRect(f.right,f.y,1,f.height):new DOMRect(f.x,f.y,1,f.height)}return d(en,s.length>0,"no client rects for range"),t.type==="home"?s[s.length-1]:s[0]}const cb=B("core");function ao(n,t,e,o){const r=Rt(t);let i=r.querySelector(`.block-anchor[data-id=${e}]`);i||(i=b("div",["block-anchor"],r),i.setAttribute("data-id",e));const s=o!=null?o:t.getBoundingClientRect(),l=t.getBoundingClientRect(),c=new DOMRect(s.left-l.left,s.top-l.top,s.width,s.height);return i.style.left=`${c.left}px`,i.style.top=`${c.top}px`,i.style.width=`${c.width}px`,i.style.height=`${c.height}px`,i}function Ag(n,t,e,o){d(cb,P(n,t),"not a text kind block");const r=De(t,j(t,e,"normal")),i=t.getBoundingClientRect(),s=Rt(t);let l=s.querySelector(`.block-anchor[data-id=${o}]`);l||(l=b("div",["block-anchor"],s),l.setAttribute("data-id",o));const c=new DOMRect(r.left-i.left,r.top-i.top,r.width,r.height);return l.style.left=`${c.left}px`,l.style.top=`${c.top}px`,l.style.width=`${c.width}px`,l.style.height=`${c.height}px`,l}function Fi(n){const t=zn(n);let e=0;return t.forEach(o=>{e+=Ne(o)}),e}const Og=B("box");function zi(n){return!n.attributes||!n.attributes.box?!1:(d(Og,n.attributes.box===!0,`invalid op attribute box property, ${n.attributes.box}`),d(Og,n.attributes.type,`no box type: ${JSON.stringify(n)}`),!0)}const _g=B("rich-text-length");function Pd(n){return d(_g,typeof n.insert=="string","op.insert is not string"),n.insert.length}function ue(n){let t=0;return n.forEach(e=>{e.insert&&(d(_g,typeof e.insert=="string","op.insert is not string"),t+=Pd(e))}),t}const kn=B("split-text");function be(n,t,e){if(n=Y.default(n),t===0)return{left:[],right:n};if(t===-1)return{left:n,right:[]};let o=0;for(let r=0;r<n.length;r++){const i=n[r];d(kn,typeof i=="object",`invalid op type, ${typeof i}`),d(kn,typeof i.insert=="string",`invalid op.insert type, ${typeof i.insert}`);const s=Pd(i);if(o+s<t)o+=s;else{if(o+s===t)return{left:n.slice(0,r+1),right:n.slice(r+1)};{d(kn,o+s>t,`invalid offset, ${o}, ${s}, ${t}`);const l=t-o,c=Y.default(i);d(kn,c.insert,"no copied.insert"),d(kn,typeof c.insert=="string","invalid copied.insert type"),c.insert=c.insert.substr(0,l),i.insert=i.insert.substr(l),c.insert===""&&d(kn,!1,"invalid copied.insert, is empty string"),i.insert===""&&d(kn,!1,"invalid op.insert, is empty string");const a=[i,...n.slice(r+1)],u=[...n.splice(0,r),c];return e&&(e.sourceOp=i),{left:u,right:a}}}}throw new Error(`invalid split offset: ${t}, ${JSON.stringify(n)}`)}function Wt(n,t,e){d(kn,t>=0,"invalid offset, < 0"),d(kn,e>0,"invalid length, <= 0"),d(kn,t+e<=ue(n),"invalid offset + length < text length");const{left:o,right:r}=be(n,t+e),{left:i,right:s}=be(o,t);return{left:i,middle:s,right:r}}function Ng(n,t){const e=Array.from(new Set(t)).sort((i,s)=>i-s),o=[];let r=n;for(let i=e.length-1;i>=0;i--){const s=e[i],{left:l,right:c}=be(r,s);r=l,o.unshift(c)}return r.length>0&&o.unshift(r),o}function $g(n,t,e){return Wt(n,t,e).middle}const Tr=B("text-block-content");function ab(n,t,e,o,r){if(d(Tr,o,"no text for block"),o.length===0&&(!r||r.size===0)){e.innerHTML="<span><br></span>";return}const i=[];r&&i.push(...r.keys());const s=f=>n.editorInsertions.createInsertion(e,f),l=(f,m)=>{const C=r==null?void 0:r.get(m);C&&(C.forEach(k=>{f.appendChild(s(k))}),r==null||r.delete(m))},c=document.createDocumentFragment();let a=0;const u=Ng(o,i);for(let f=0;f<u.length;f++){l(c,a);const m=u[f];a+=ue(m);for(let C=0;C<m.length;C++){const k=m[C];if(zi(k)){d(Tr,k.attributes,`op is not an valid box: ${JSON.stringify(k)}`);const y=n.editorBoxes.createBox(e,k.attributes);d(Tr,y instanceof HTMLSpanElement,`invalid box element: ${y.tagName}`),c.appendChild(y);continue}d(Tr,k.insert,`no insert in op: ${JSON.stringify(k)}`);const w=b("span",["text"],c,k.insert);if(k.attributes){const y=n.editorBlockRenders.renderText(t,k.attributes);y.classes&&A(w,...y.classes),y.attributes&&Object.entries(y.attributes).forEach(([S,I])=>{w.setAttribute(S,I)}),y.styles&&Object.entries(y.styles).forEach(([S,I])=>{w.style.setProperty(S,I)})}c.appendChild(w)}}l(c,a),e.innerHTML="",e.appendChild(c)}function Nl(n,t,e,o,r){const{text:i,insertions:s}=n.editorDecorators.decorateText(t,r),l=n.compositingText;if(l){const c=n.selection.range.start;d(Tr,c.isSimple(),"not an simple position while compositing"),c.blockId===e&&s.set(c.offset,[{type:"inputting",id:N(),text:l}])}return ab(n,t,o,i,s)}function db(n){const t=n.rootContainer.querySelectorAll('span[data-type="editor-insertion"].inputting-insertion');t.length&&Tr.debug(`remove ${t.length} temp composition span`),Array.from(t).forEach(e=>e.remove())}const vn=B("client-rects");function ub(n){const t=zn(n);let e=0;const o=[];for(let r=0;r<t.length;r++){const i=t[r],s=Ne(i);o.push({child:i,startBlockOffset:e,endBlockOffset:e+s}),e+=s}return o}function hb(n,t,e,o){d(vn,e<o,`invalid from & to: ${e}, ${o}`);const r=W(n,t);d(vn,e>=0&&o>=0&&e<=r&&o<=r,`invalid offset: ${e}, ${o}, length: ${r}`);const i=ub(t),s=i.findIndex(C=>C.startBlockOffset<=e&&e<C.endBlockOffset),l=i.findIndex(C=>C.startBlockOffset<o&&o<=C.endBlockOffset);if(d(vn,s!==-1,"failed to find start child"),d(vn,l!==-1,"failed to find end child"),d(vn,s<=l,`invalid start index & end index: ${s}, ${l}`),s===l){const C=i[s];return[{child:C.child,startChildOffset:e-C.startBlockOffset,endChildOffset:o-C.startBlockOffset}]}const c=[],a=i[s],u={child:a.child,startChildOffset:e-a.startBlockOffset,endChildOffset:Ne(a.child)};c.push(u);for(let C=s+1;C<l;C++){const k=i[C],w={child:k.child,startChildOffset:0,endChildOffset:k.endBlockOffset-k.startBlockOffset};c.push(w)}const f=i[l],m={child:f.child,startChildOffset:0,endChildOffset:o-f.startBlockOffset};return c.push(m),c}function fb(n){const t=(o,r)=>o.left<=r.left&&o.top<=r.top&&o.right>=r.right&&o.bottom>=r.bottom&&(o.width!==r.width||o.height!==r.height);n=n.filter(o=>!n.find(i=>t(o,i)));const e=[];return n=n.filter(o=>e.find(r=>r.left===o.left&&r.top===o.top&&r.width===o.width&&r.height===o.height)?!1:(e.push(o),!0)),n}function Pg(n,t,e,o){if(W(n,t)===0){const u=it(t).getBoundingClientRect();return[new DOMRect(u.left,u.top,4,u.height)]}const r=e.offset,i=o.offset;if(r===i)return[De(t,e)];const l=hb(n,t,r,i).map(a=>sb(a.child,a.startChildOffset,a.endChildOffset)),c=[];return l.forEach(a=>{const u=fb(Array.from(a.getClientRects()));c.push(...u)}),c}function mb(n,t,e){d(vn,e instanceof ae,"invalid range");const o=e.start,r=e.end;return d(vn,o.isSimple(),"text block only allow simple position"),d(vn,r.isSimple(),"text block only allow simple position"),d(vn,o.blockId===r.blockId,"only allow update one text block selection"),d(vn,o.blockId===q(t),"only allow update one text block selection"),Pg(n,t,o,r)}const jd=B("selection-background");function gb(n,t,e,o){d(jd,e.isSimple(),"text block only allow simple position"),d(jd,o.isSimple(),"text block only allow simple position"),d(jd,e.blockId===o.blockId,"only allow update one text block selection");const r=e.offset,i=o.offset;if(r===i&&(W(n,t)!==0||n.selection.range.isCollapsed()))return;const s=Pg(n,t,e,o),l=t.getBoundingClientRect(),c=qm(t);c.innerHTML="",s.forEach(a=>{const u=b("div",["editor-selection-background"],c);u.style.left=`${a.left-l.left}px`,u.style.top=`${a.top-l.top}px`,u.style.width=`${a.width}px`,u.style.height=`${a.height}px`})}function pb(n){n.rootContainer.querySelectorAll("div[data-type=block-background]").forEach(t=>{t.remove()})}const Wo=B("text-offset"),jg="\u200D";function uo(n,t){const e=zn(n);let o=0;for(let r=0;r<e.length;r++){const i=e[r],s=Ne(i);if(i===t){const l=o+s;return{start:o,end:l}}o+=s}d(Wo,!1,"can not find child in children")}function re(n,t){d(Wo,t>=0,`invalid offset: ${t}`);const e=_l(n,t),{prev:o,next:r,offset:i}=e;if(!o&&!r&&d(Wo,!1,"invalid offset, no prev & next child at offset"),o!==r)return!0;const s=o;if(d(Wo,s,"no child"),_e(s))return d(Wo,i===0||i===1,`invalid box child offset: ${i}`),!0;const l=s.textContent;d(Wo,l,"no content for text child");const c=l.charAt(i-1),a=l.charAt(i);return!(c===jg||a===jg||td(l[i]))}function ho(n,t){if(t===0)return 0;const e=t-1;if(re(n,e))return e;let o=e-1;for(;!re(n,o);)o-=1;return o}function Go(n,t){const e=Fi(n);if(d(Wo,t>=0&&t<=e,`invalid offset: ${t}, ${e}`),t===e)return e;const o=t+1;if(re(n,o))return o;let r=o+1;for(;!re(n,r);)r+=1;return r}const Zo=B("line-breaker");function Ui(n){const t=c=>{const a=bl(c);return $o(c).top>a.top+a.height/2},e=(c,a)=>{const u=$o(c);return bl(a).left<u.right},o=(c,a)=>{const u=$o(c),f=$o(a);return f.top+f.height/2>u.bottom},r=c=>{if(c.length===0||c.length===1)return!1;const a=c[0],u=c[c.length-1];return a.right-u.left>10},i=[];let s=0;const l=zn(n);for(let c=0;c<l.length;c++){const a=l[c];if(Fn(a)){const y=a,S=l[c+1];if(!S)break;const I=l[c-1];if(I&&o(I,y)&&i.push({offset:s,type:"betweenChild",childInfo:{prevChild:I,nextChild:y,wrap:"nextWrapped",prevWrapped:t(I),nextWrapped:t(y)}}),e(y,S)){i.push({offset:s,type:"betweenChild",childInfo:{prevChild:I,nextChild:y,wrap:"nowrap",prevWrapped:t(I),nextWrapped:t(y)}});continue}continue}if(_e(a)){const y=a,S=l[c+1];if(!S)break;const I=l[c-1];if(I&&o(I,y)&&i.push({offset:s,type:"betweenChild",childInfo:{prevChild:I,nextChild:y,wrap:"nextWrapped",prevWrapped:t(I),nextWrapped:t(y)}}),e(y,S)){s+=1,i.push({offset:s,type:"betweenChild",childInfo:{prevChild:I,nextChild:a,wrap:"nowrap",prevWrapped:t(I),nextWrapped:t(a)}});continue}s+=1;continue}const u=a,f=u.getClientRects();if(d(Zo,f.length>0,"invalid text child dom"),f.length===1){const y=l[c+1];if(!y)break;if(e(u,y)){s+=Ne(u),i.push({offset:s,type:"betweenChild",childInfo:{prevChild:u,nextChild:y,wrap:"nowrap",prevWrapped:t(u),nextWrapped:t(y)}});continue}s+=Ne(u);continue}const m=u.firstChild;d(Zo,m,"invalid text child, no text node"),d(Zo,m instanceof Text,`invalid text child, not a valid text node: ${typeof m}`);const C=document.createRange(),k=document.createRange(),w=Ne(u);d(Zo,m.data.length===w,"text node data length not equal child text length");for(let y=0;y<m.data.length;y++){if(!re(n,s+y))continue;C.setStart(m,y),cd()&&C.selectNodeContents(m);const S=C.getClientRects();if(d(Zo,S.length>=1,"invalid text node, no client rects"),r(S)){const Z=s+y;i.push({offset:Z,type:"textBreakWord",childInfo:{prevChild:a,nextChild:a,wrap:"nowrap",prevWrapped:t(a),nextWrapped:t(a)}});continue}let I=y+1;re(n,s+I)||(I=y+2),k.setStart(m,I);const M=k.getClientRects(),R=S[0];M[0].left<R.right&&d(Zo,!1,"span pre-wrap should not has a line-wrap by white space")}s+=w}return i}function Hd(n,t){const e=Ui(n);for(let o=0;o<e.length;o++){const{offset:r,type:i}=e[o];if(t.offset<r)return{lineIndex:o,lineBreaks:e};if(t.offset===r&&t.type==="end")return{lineIndex:o,lineBreaks:e}}return d(Zo,t.offset<=Fi(n),"invalid position, offset > block length"),{lineIndex:e.length,lineBreaks:e}}const Cb=B("line-offset");function Fd(n){const t=Ui(n),e=[];let o=0;for(let r=0;r<t.length;r++){const i=t[r];e.push({start:o,end:i.offset}),o=i.offset}return e.push({start:o,end:Fi(n)}),e}function $l(n,t){const e=Fd(n);return d(Cb,t>=0&&t<e.length,`invalid line index: ${t}, ${e.length}`),e[t]}function Hg(n,t){const{lineIndex:e}=Hd(n,t);return $l(n,e)}function bb(n){const t=Fd(n),e=n.getBoundingClientRect(),o=[];return t.forEach(({start:r,end:i})=>{const s=j(n,r,"home");let l=De(n,s);const c=j(n,i,"end"),a=De(n,c);l.top+l.height/2<a.top&&(l=new DOMRect(e.left-1e4,a.top,1,a.height));const u=new DOMRect(l.left,a.top,a.left-l.left,a.height),f=new DOMRect(e.left,a.top,e.width,a.height);o.push({start:r,end:i,rect:f,contentRect:u})}),o}function kb(n,t,e){const r=bb(n).find(s=>jo(s.rect,t,e));if(!r)return null;const i=r.contentRect;return t-i.left<i.right-t?j(n,r.start,"home"):j(n,r.end,"end")}function Fg(n,t,e){const o=De(n,t),r=De(n,e),i=o.top+o.height/2,s=r.top+r.height/2,l=r.top<i&&i<r.bottom,c=o.top<s&&s<o.bottom;return l&&c}function zg(n){return Fd(n).length}const Yo=B("find-text-position");function Ug(n,t){const{start:e,end:o}=$l(n,t),r=q(n),i=De(n,j(r,e,"home"));if(!(De(n,j(r,o,"end")).top>i.top+i.height/2))return!1;const c=_l(n,e);return d(Yo,c.next,"no next child at offset"),d(Yo,!Hi(c.next),"next child is not text child"),!0}function vb(n,t){const e=q(n);d(Yo,Ug(n,t),"line is not wrapped");const{start:o,end:r}=$l(n,t),i=j(e,o,"home");for(let s=o+1;s<=r;s+=1){let l="normal";s===o?l="home":s===r&&(l="end");const c=j(e,s,l);if(!Fg(n,i,c))return s-1}return d(Yo,!1,"failed to find wrapped offset"),0}function Pl(n,t,e,o,r,i,s){d(Yo,P(n,t),`not a text kind block: ${ot(t)}`);const{start:l,end:c}=$l(t,e);let a=l;const u=q(t);if(t===o&&Ug(t,e)){const y=vb(t,e);(i==="up"||i==="down"&&Fg(t,r,j(u,l,"home")))&&(a=y+1)}let f=Number.MAX_SAFE_INTEGER;const m=Ke(n,o,r),C=s!=null?s:m.left+m.width/2,k=m.top+m.height/2;let w=j(u,a,"home");for(let y=a;y<=c;y++){if(!re(t,y))continue;let S="normal";y===l?S="home":y===c&&(S="end");const I=j(u,y,S),M=De(t,I),R=Cn(M,C,k);R<f&&(f=R,w=I)}return w}function yb(n,t,e,o,r){return d(Yo,P(n,t),"not a text block"),Pl(n,t,zg(t)-1,e,o,"up",r)}function wb(n,t,e,o,r){return d(Yo,P(n,t),"not a text block"),Pl(n,t,0,e,o,"down",r)}function Bb(n,t,e,o){const{lineIndex:r}=Hd(t,e);if(r===zg(t)-1)return null;const i=Pl(n,t,r+1,t,e,"down",o);return i||null}function Eb(n,t){if(t.offset===0)return null;const e=Ui(n),o=e.find(r=>r.offset===t.offset);if(!o){const r=ho(n,t.offset);return e.find(s=>s.offset===r)?{offset:r,type:"home"}:{offset:r,type:"normal"}}if(o.type==="betweenChild"){if(t.type==="home"&&o.childInfo.wrap==="nowrap")return{offset:t.offset,type:"end"};if(o.childInfo.prevWrapped)return{offset:ho(n,t.offset),type:"normal"}}return{offset:ho(n,t.offset),type:"normal"}}function Ib(n,t){const e=Fi(n);if(t.offset===e)return null;const o=Ui(n),r=o.find(i=>i.offset===t.offset);if(!r){const i=Go(n,t.offset),s=o.find(l=>l.offset===i);return s?s.type==="betweenChild"?{offset:i,type:"end"}:{offset:i,type:"home"}:{offset:i,type:"normal"}}return r.type==="betweenChild"?r.childInfo.wrap==="nowrap"&&t.type==="end"?{offset:t.offset,type:"home"}:{offset:Go(n,t.offset),type:"home"}:{offset:Go(n,t.offset),type:"normal"}}function xb(n,t,e,o){const{lineIndex:r}=Hd(t,e);if(r===0)return null;const i=Pl(n,t,r-1,t,e,"up",o);return i||null}const Tb=B("move-caret");function Sb(n,t,e,o){if(o==="ArrowLeft"){const r=Eb(t,e);return r?j(q(t),r.offset,r.type):null}if(o==="ArrowRight"){const r=Ib(t,e);return r?j(q(t),r.offset,r.type):null}if(o==="ArrowUp"){const r=xb(n,t,e,n.selection.getSuggestedCaretX());return r?j(q(t),r.offset,r.type):null}if(o==="ArrowDown"){const r=Bb(n,t,e,n.selection.getSuggestedCaretX());return r?j(q(t),r.offset,r.type):null}d(Tb,!1,`invalid navigation direction: ${o}`)}const zd=B("text-range");function Db(n){const t=[];return zn(n).forEach(o=>{const r=Array.from(o.getClientRects()).map(i=>({rect:i,child:o}));t.push(...r)}),t}function Lb(n,t,e){const o=Db(n);for(let r=1;r<o.length;r++){const i=o[r-1],s=o[r];if(t>=i.rect.right&&t<=s.rect.left&&e>=i.rect.top&&e<=i.rect.bottom&&e>=s.rect.top&&e<=s.rect.bottom)return uo(n,s.child).start}return null}function Mb(n,t,e,o){const r=document.elementsFromPoint(e,o)[0];if(!r||!t.contains(r)||!n.contains(t))return null;const i=r.closest("div[data-type=block-content]>span");if(!i){const S=t.getBoundingClientRect();if(!jo(S,e,o))return null;const I=Lb(t,e,o);if(I!==null){const R=j(t,I,"normal");return new ae(n,{anchor:R,focus:R})}const M=kb(t,e,o);return M?new ae(n,{anchor:M,focus:M}):null}const s=zn(t);d(zd,s.indexOf(i)!==-1,"failed to find child in children");const l=uo(t,i);d(zd,l,"failed to get child offset");const{start:c}=l;let a,u;Fn(i)||_e(i)?(a=c,u=0):(d(zd,i.firstChild instanceof Text,"child is not text"),a=c+sm(i.firstChild,e,o),u=0);const f=q(t),C=Ui(t).find(S=>S.offset===a);let k="normal";if(C){const S=j(f,a,"home"),I=j(f,a,"end"),M=De(t,S),R=De(t,I),$=Cn(M,e,o),Z=Cn(R,e,o);k=$<Z?"home":"end"}const w=j(f,a,k);let y;return u&&(y=j(f,a+u,k)),new ae(n,{anchor:w,focus:y!=null?y:w})}const Rb=B("create-text-op");function $e(n,t){d(Rb,n,"text is empty");const e={insert:n};return t&&Object.keys(t).length>0&&(e.attributes=t),e}function Ud(n,t){if(n.length===0)return[];if(n.indexOf(`
16
16
  `)===-1)return[$e(n,t)];const e=n.replace(/\r\n/g,`
17
17
  `).replace(/\r/g,`
18
- `).replace(/\n/g," "),o=[];return e&&o.push($e(e,t)),o}const jl=B("merge-ops");function Vd(n){if(n.length<=1)return n;const t=(r,i)=>r.insert===void 0||i.insert===void 0||r.delete!==void 0||i.delete!==void 0||r.retain!==void 0||i.retain!==void 0||r.attributes!==void 0&&i.attributes===void 0||r.attributes===void 0&&i.attributes!==void 0?!1:r.attributes===void 0?(d(jl,i.attributes===void 0,"op2.attributes is not undefined"),!0):(d(jl,r.attributes&&i.attributes,"op1.attributes && op2.attributes is undefined"),ml.default(r.attributes,i.attributes)),e=[];let o=n[0];e.push(o);for(let r=1;r<n.length;r+=1){const i=n[r];t(o,i)?(d(jl,typeof o.insert=="string","before.insert is not string"),d(jl,typeof i.insert=="string","op.insert is not string"),o.insert+=i.insert):(e.push(i),o=i)}return e}function Ab(n){let t;for(t=n.length-1;t>=0;t--){const e=n[t];if(!e.attributes||!e.attributes.box||e.attributes.type!=="br")break}return t===n.length-1?n:n.slice(0,t+1)}const Vg=B("delete-text");function qd(n,t,e){const{left:o,right:r}=Wt(n,t,e),i=[...o,...r];return Vd(i)}function qg(n,t){d(Vg,n>=0,`invalid offset: ${n}`),d(Vg,t>=1,`invalid delete count: ${t}`);const e=[];return n!==0&&e.push({retain:n}),e.push({delete:t}),e}const Wg=B("delta");function Gg(n,t){const e=new oe.default(n),o=new oe.default(t);return e.diff(o).ops}function Ob(n,t,e){return new oe.default(t).transformPosition(n,!e)}function _b(n){d(Wg,n,"ops is null or undefined");for(let t=0;t<n.length;t++){const e=n[t];if(e.insert===null||e.insert===void 0||e.retain!==void 0||e.delete!==void 0)return!1}return!0}function Nb(n,t){const e=new oe.default(n),o=new oe.default(t);return e.compose(o).ops}class ie{static ensureValidText(t){d(Wg,_b(t),`text is not a valid text, ${JSON.stringify(t)}`)}static diff(t,e){return this.ensureValidText(t),this.ensureValidText(e),Gg(t,e)}static transformCursor(t,e,o){return Ob(t,e,o)}static transformOffset(t,e,o){const r=Gg(t,e),i=new oe.default(r);return o.map(s=>i.transformPosition(s))}static apply(t,e){this.ensureValidText(t);const o=Nb(t,e);return this.ensureValidText(o),o}}const Zg=B("insert-text");function ho(n,t,e,o){d(Zg,e,`invalid text to insert: ${e}`);const{left:r,right:i}=be(n,t),s=typeof e=="string"?[$e(e,o)]:e,l=[...r,...s,...i];return Vd(l)}function Yg(n){return{insert:" ",attributes:n}}function Hl(n,t,e){if(d(Zg,n>=0,`invalid offset: ${n}`),t.length===0)return[];const o=[];if(n>0&&o.push({retain:n}),typeof t!="string")return o.push(...t),o;const i={insert:t.replaceAll(`\r
18
+ `).replace(/\n/g," "),o=[];return e&&o.push($e(e,t)),o}const jl=B("merge-ops");function Vd(n){if(n.length<=1)return n;const t=(r,i)=>r.insert===void 0||i.insert===void 0||r.delete!==void 0||i.delete!==void 0||r.retain!==void 0||i.retain!==void 0||r.attributes!==void 0&&i.attributes===void 0||r.attributes===void 0&&i.attributes!==void 0?!1:r.attributes===void 0?(d(jl,i.attributes===void 0,"op2.attributes is not undefined"),!0):(d(jl,r.attributes&&i.attributes,"op1.attributes && op2.attributes is undefined"),ml.default(r.attributes,i.attributes)),e=[];let o=n[0];e.push(o);for(let r=1;r<n.length;r+=1){const i=n[r];t(o,i)?(d(jl,typeof o.insert=="string","before.insert is not string"),d(jl,typeof i.insert=="string","op.insert is not string"),o.insert+=i.insert):(e.push(i),o=i)}return e}function Ab(n){let t;for(t=n.length-1;t>=0;t--){const e=n[t];if(!e.attributes||!e.attributes.box||e.attributes.type!=="br")break}return t===n.length-1?n:n.slice(0,t+1)}const Vg=B("delete-text");function qd(n,t,e){const{left:o,right:r}=Wt(n,t,e),i=[...o,...r];return Vd(i)}function qg(n,t){d(Vg,n>=0,`invalid offset: ${n}`),d(Vg,t>=1,`invalid delete count: ${t}`);const e=[];return n!==0&&e.push({retain:n}),e.push({delete:t}),e}const Wg=B("delta");function Gg(n,t){const e=new oe.default(n),o=new oe.default(t);return e.diff(o).ops}function Ob(n,t,e){return new oe.default(t).transformPosition(n,!e)}function _b(n){d(Wg,n,"ops is null or undefined");for(let t=0;t<n.length;t++){const e=n[t];if(e.insert===null||e.insert===void 0||e.retain!==void 0||e.delete!==void 0)return!1}return!0}function Nb(n,t){const e=new oe.default(n),o=new oe.default(t);return e.compose(o).ops}class ie{static ensureValidText(t){d(Wg,_b(t),`text is not a valid text, ${JSON.stringify(t)}`)}static diff(t,e){return this.ensureValidText(t),this.ensureValidText(e),Gg(t,e)}static transformCursor(t,e,o){return Ob(t,e,o)}static transformOffset(t,e,o){const r=Gg(t,e),i=new oe.default(r);return o.map(s=>i.transformPosition(s))}static apply(t,e){this.ensureValidText(t);const o=Nb(t,e);return this.ensureValidText(o),o}}const Zg=B("insert-text");function fo(n,t,e,o){d(Zg,e,`invalid text to insert: ${e}`);const{left:r,right:i}=be(n,t),s=typeof e=="string"?[$e(e,o)]:e,l=[...r,...s,...i];return Vd(l)}function Yg(n){return{insert:" ",attributes:n}}function Hl(n,t,e){if(d(Zg,n>=0,`invalid offset: ${n}`),t.length===0)return[];const o=[];if(n>0&&o.push({retain:n}),typeof t!="string")return o.push(...t),o;const i={insert:t.replaceAll(`\r
19
19
  `," ").replaceAll(`
20
- `," ").replaceAll("\r"," ")};return e&&Object.keys(e).length>0&&(i.attributes=e),o.push(i),o}function $b(n,t){return[...n,...t]}const Qg=B("text-op");function Wd(n){return d(Qg,typeof n.insert=="string","invalid op, no insert"),n.insert.length}function Kg(n,t){const e=n;let o=0;for(let r=0;r<e.length;r++){const i=e[r];d(Qg,typeof i.insert=="string","invalid text op, no insert");const s=o+Wd(i);if(s>t)return[i];if(s===t){const l=[i];return r<e.length-1&&l.push(e[r+1]),l}o=s}return[]}const Gd="style-color-",Zd="style-bg-color-";function Fl(n,t,e){const o=Y.default(n);return o.forEach(r=>{if(!(r.attributes&&r.attributes.box===!0))if(e===void 0){if(!r.attributes||r.attributes[t]===void 0)return;delete r.attributes[t],Object.keys(r.attributes).length===0&&delete r.attributes}else r.attributes||(r.attributes={}),r.attributes[t]=e}),o}function Yd(n,t,e,o){const r=Y.default(n);return r.forEach(i=>{i.attributes&&i.attributes.box===!0||i.attributes&&((o==null?void 0:o.ignoreValue)||i.attributes[t]===e)&&(delete i.attributes[t],Object.keys(i.attributes).length===0&&delete i.attributes)}),r}function Vi(n,t,e,o,r){if(t===0)return e;const i=Wt(e,n,t);return[...i.left,...Fl(i.middle,o,r),...i.right]}function Sr(n,t,e,o,r,i){if(t===0)return e;const s=Wt(e,n,t);return[...s.left,...Yd(s.middle,o,r,i),...s.right]}function zl(n,t){const e=Kg(n,t);if(e.length===1)return e[0].attributes;if(e.length===2)return e[1].attributes}function Jg(n,t,e,o){if(t===0)return e;const r=Wt(e,n,t),i=r.middle.map(s=>o(s));return[...r.left,...i,...r.right]}function Xg(n,t){t==="color"?Object.keys(n).forEach(e=>{e.startsWith("style-color-")&&delete n[e]}):t==="backgroundColor"&&Object.keys(n).forEach(e=>{e.startsWith("style-bg-color-")&&delete n[e]})}function Pb(n,t){if(!n.attributes||n.attributes.box)return;const e=n.attributes;Xg(e,t),Object.keys(e).length===0&&delete n.attributes}function jb(n,t,e){n.attributes||(n.attributes={}),!n.attributes.box&&(t==="color"?n.attributes[`style-color-${e}`]=!0:n.attributes[`style-bg-color-${e}`]=!0)}function tp(n,t,e,o,r){const i=Y.default(e);return Jg(n,t,i,l=>(Pb(l,o),r!==null&&jb(l,o,r),l))}function Qd(n){var r,i;if(!n||n.box)return[null,null];const t=Array.from(Object.keys(n));let e=null,o=null;for(let s=0;s<t.length;s++){const l=t[s];l.startsWith(Gd)?e=(r=Number.parseInt(l.substring(Gd.length),10))!=null?r:null:l.startsWith(Zd)&&(o=(i=Number.parseInt(l.substring(Zd.length),10))!=null?i:null)}return[e,o]}function ep(n,t,e){Xg(n,t),t==="color"?n[`style-color-${e}`]=!0:n[`style-bg-color-${e}`]=!0}function np(n){return n.attributes?n.attributes.box?[null,null]:Qd(n.attributes):[null,null]}function op(n,t,e){let o=[];if(t===0?n!==0&&(o=Wt(e,n-1,1).middle):o=Wt(e,n,t).middle,o.length===0)return[null,null];let[r,i]=np(o[0]);if(r===null&&i===null)return[r,i];for(let s=1;s<o.length;s++){const l=o[s];if(!l.attributes)return[null,null];if(l.attributes.box)continue;const[c,a]=np(l);c===null||r===null?r=null:r=c===r?r:null,a===null||i===null?i=null:i=a===i?i:null}return[r,i]}function rp(n){return Y.default(n)}const Hb=B("update-op-attribute");function ip(n,t,e,o){const r=rp(n),i=r.findIndex(l=>l.attributes?l.attributes[t]===e:!1);d(Hb,i!==-1,`can not find op by key: ${t}, value: ${e}`);const s=r[i];return s.attributes={...s.attributes,...o},r}const Fb="\u200B",zb=B("to-plain-text");function bt(n,t){let e="";return n.forEach(o=>{if(d(zb,typeof o.insert=="string","invalid op"),o.attributes&&o.attributes.box===!0){if(t!=null&&t.boxReplacement){e+=t.boxReplacement;return}if(o.attributes.text){e+=o.attributes.text;return}e+=" "}e+=o.insert}),e}function sp(n){return bt(n,{boxReplacement:" "})}function Ul(n,t,e,o){const r=zl(n,t),i=qd(n,t,e-t);return o?ho(i,t,o,r!=null?r:null):i}function Kd(n,t){if(!t)return[];const e=t.length,o=bt(n,{boxReplacement:" "}).toLowerCase();t=t.toLowerCase();let r=o.indexOf(t,0);const i=[];for(;r!==-1;)i.push({start:r,end:r+e}),r=o.indexOf(t,r+e);return i}function lp(n,t,e,o){const r=Kd(n,t);let i=Y.default(n);return r.length===0||(r.reverse().forEach(s=>{i=Ul(i,s.start,s.end,e)}),o&&(o.count=r.length)),i}function Qo(n,t){return n?[{insert:n,attributes:t}]:[]}function Un(n,t){return{id:N(),type:"text",text:typeof n=="string"?Qo(n):n,...t}}function Vl(n){return Un(n!=null?n:"")}function Ko(n,t){return{blocks:{root:(n!=null?n:"").replaceAll("\r","").split(`
20
+ `," ").replaceAll("\r"," ")};return e&&Object.keys(e).length>0&&(i.attributes=e),o.push(i),o}function $b(n,t){return[...n,...t]}const Qg=B("text-op");function Wd(n){return d(Qg,typeof n.insert=="string","invalid op, no insert"),n.insert.length}function Kg(n,t){const e=n;let o=0;for(let r=0;r<e.length;r++){const i=e[r];d(Qg,typeof i.insert=="string","invalid text op, no insert");const s=o+Wd(i);if(s>t)return[i];if(s===t){const l=[i];return r<e.length-1&&l.push(e[r+1]),l}o=s}return[]}const Gd="style-color-",Zd="style-bg-color-";function Fl(n,t,e){const o=Y.default(n);return o.forEach(r=>{if(!(r.attributes&&r.attributes.box===!0))if(e===void 0){if(!r.attributes||r.attributes[t]===void 0)return;delete r.attributes[t],Object.keys(r.attributes).length===0&&delete r.attributes}else r.attributes||(r.attributes={}),r.attributes[t]=e}),o}function Yd(n,t,e,o){const r=Y.default(n);return r.forEach(i=>{i.attributes&&i.attributes.box===!0||i.attributes&&((o==null?void 0:o.ignoreValue)||i.attributes[t]===e)&&(delete i.attributes[t],Object.keys(i.attributes).length===0&&delete i.attributes)}),r}function Vi(n,t,e,o,r){if(t===0)return e;const i=Wt(e,n,t);return[...i.left,...Fl(i.middle,o,r),...i.right]}function Sr(n,t,e,o,r,i){if(t===0)return e;const s=Wt(e,n,t);return[...s.left,...Yd(s.middle,o,r,i),...s.right]}function zl(n,t){const e=Kg(n,t);if(e.length===1)return e[0].attributes;if(e.length===2)return e[1].attributes}function Jg(n,t,e,o){if(t===0)return e;const r=Wt(e,n,t),i=r.middle.map(s=>o(s));return[...r.left,...i,...r.right]}function Xg(n,t){t==="color"?Object.keys(n).forEach(e=>{e.startsWith("style-color-")&&delete n[e]}):t==="backgroundColor"&&Object.keys(n).forEach(e=>{e.startsWith("style-bg-color-")&&delete n[e]})}function Pb(n,t){if(!n.attributes||n.attributes.box)return;const e=n.attributes;Xg(e,t),Object.keys(e).length===0&&delete n.attributes}function jb(n,t,e){n.attributes||(n.attributes={}),!n.attributes.box&&(t==="color"?n.attributes[`style-color-${e}`]=!0:n.attributes[`style-bg-color-${e}`]=!0)}function tp(n,t,e,o,r){const i=Y.default(e);return Jg(n,t,i,l=>(Pb(l,o),r!==null&&jb(l,o,r),l))}function Qd(n){var r,i;if(!n||n.box)return[null,null];const t=Array.from(Object.keys(n));let e=null,o=null;for(let s=0;s<t.length;s++){const l=t[s];l.startsWith(Gd)?e=(r=Number.parseInt(l.substring(Gd.length),10))!=null?r:null:l.startsWith(Zd)&&(o=(i=Number.parseInt(l.substring(Zd.length),10))!=null?i:null)}return[e,o]}function ep(n,t,e){Xg(n,t),t==="color"?n[`style-color-${e}`]=!0:n[`style-bg-color-${e}`]=!0}function np(n){return n.attributes?n.attributes.box?[null,null]:Qd(n.attributes):[null,null]}function op(n,t,e){let o=[];if(t===0?n!==0&&(o=Wt(e,n-1,1).middle):o=Wt(e,n,t).middle,o.length===0)return[null,null];let[r,i]=np(o[0]);if(r===null&&i===null)return[r,i];for(let s=1;s<o.length;s++){const l=o[s];if(!l.attributes)return[null,null];if(l.attributes.box)continue;const[c,a]=np(l);c===null||r===null?r=null:r=c===r?r:null,a===null||i===null?i=null:i=a===i?i:null}return[r,i]}function rp(n){return Y.default(n)}const Hb=B("update-op-attribute");function ip(n,t,e,o){const r=rp(n),i=r.findIndex(l=>l.attributes?l.attributes[t]===e:!1);d(Hb,i!==-1,`can not find op by key: ${t}, value: ${e}`);const s=r[i];return s.attributes={...s.attributes,...o},r}const Fb="\u200B",zb=B("to-plain-text");function bt(n,t){let e="";return n.forEach(o=>{if(d(zb,typeof o.insert=="string","invalid op"),o.attributes&&o.attributes.box===!0){if(t!=null&&t.boxReplacement){e+=t.boxReplacement;return}if(o.attributes.text){e+=o.attributes.text;return}e+=" "}e+=o.insert}),e}function sp(n){return bt(n,{boxReplacement:" "})}function Ul(n,t,e,o){const r=zl(n,t),i=qd(n,t,e-t);return o?fo(i,t,o,r!=null?r:null):i}function Kd(n,t){if(!t)return[];const e=t.length,o=bt(n,{boxReplacement:" "}).toLowerCase();t=t.toLowerCase();let r=o.indexOf(t,0);const i=[];for(;r!==-1;)i.push({start:r,end:r+e}),r=o.indexOf(t,r+e);return i}function lp(n,t,e,o){const r=Kd(n,t);let i=Y.default(n);return r.length===0||(r.reverse().forEach(s=>{i=Ul(i,s.start,s.end,e)}),o&&(o.count=r.length)),i}function Qo(n,t){return n?[{insert:n,attributes:t}]:[]}function Un(n,t){return{id:N(),type:"text",text:typeof n=="string"?Qo(n):n,...t}}function Vl(n){return Un(n!=null?n:"")}function Ko(n,t){return{blocks:{root:(n!=null?n:"").replaceAll("\r","").split(`
21
21
  `).map((r,i)=>{const l=i===0&&(t==null?void 0:t.firstLineAsTitle)?{heading:1}:void 0;return Un(r,l)})},meta:{},comments:{}}}function ql(n){const t=n.blocks.root;if(t.length!==1)return!1;const e=t[0];return!(!e.text||ue(e.text))}function cp(n,t){const e=N();return n.localInsertChildContainer(e,t),e}function yn(n,t){return cp(n,[Vl(t)])}function ap(n){return typeof n.offset=="number"}function Wl(n){return ap(n.anchor)}function Ub(n){return Wl(n)&&n.anchor.offset===n.focus.offset&&n.anchor.blockId===n.focus.blockId}function dp(n,t){return{blockId:n,offset:t}}function Gl(n,t){const e=dp(n,t);return{anchor:e,focus:e}}function up(n,t){return{blockId:n,childContainerId:t}}function Vb(n,t){const e=up(n,t);return{anchor:e,focus:e}}const qb=B("block-to-text");function Wb(n,t,e){let o="";return t.forEach(r=>{if(d(qb,typeof r.insert=="string","invalid op"),r.attributes&&r.attributes.box===!0){const i=r.attributes,s=n.editorBoxes.getBoxClass(i.type);if(s!=null&&s.convertTo){o+=s.convertTo(n,i,e,"text");return}if(r.attributes.text){o+=r.attributes.text;return}o+=`[${i.type}]`}o+=r.insert}),o}const Gb=B("block-to-text");function Zb(n,t,e){let o="";return t.forEach(r=>{if(d(Gb,typeof r.insert=="string","invalid op"),r.attributes&&r.attributes.box===!0){const s=r.attributes,l=n.editorBoxes.getBoxClass(s.type);if(l!=null&&l.convertTo){o+=l.convertTo(n,s,e,"markdown");return}if(r.attributes.text){o+=r.attributes.text;return}o+=`[${s.type}]`}const i=r.attributes;if(i){let s=r.insert;i.link&&(s=`[${s}](${i.link})`);const l=[];i["style-code"]?l.push("`"):(i["style-bold"]&&l.push("**"),i["style-italic"]&&l.push("*"),i["style-underline"]&&l.push("__"),i["style-strikethrough"]&&l.push("~~"));const c=l.join("");o.endsWith(c.substring(0,1))&&(o+=" ");const a=l.reverse().join("");o+=c+s+a;return}o+=r.insert}),o}function Yb(n,t,e){const o=t.text||[];let i=Zb(n,o,e);if(t.heading){const s=t.heading;i=`${"#".repeat(s)} ${i}`}return t.quoted&&(i=`> ${i}`),t.type==="text"&&(i=`${i}
22
- `),i}const Qb=B("block-to-text");function Kb(n,t,e){let o="";return t.forEach(r=>{if(d(Qb,typeof r.insert=="string","invalid op"),r.attributes&&r.attributes.box===!0){const s=r.attributes,l=n.editorBoxes.getBoxClass(s.type);if(l!=null&&l.convertTo){o+=l.convertTo(n,s,e,"html");return}if(r.attributes.text){o+=r.attributes.text;return}o+=`[${s.type}]`}const i=r.attributes;if(i){let s=r.insert;i.link&&(s=`<a href="${i.link}">${s}</a>`);const l=[];i.bold&&l.push("strong"),i.italic&&l.push("em"),i.underline&&l.push("u"),i.strike&&l.push("s"),i.code&&l.push("code");const c=l.map(u=>`<${u}>`).join(""),a=l.reverse().map(u=>`</${u}>`).join("");o+=c+s+a;return}o+=r.insert}),o||(o="<br>"),`<p>${o}</p>`}const qi=B("text-block");function Jb(n,t,e,o,r){const{text:i}=r;d(qi,i,"no text for text block");const s=ro(o,"div");return Nl(n,t,r.id,s,i),s}function Xb(n,t,e){d(qi,e,"no text to update");const o=ro(null,"div");Nl(n,Vo(t),q(t),o,e);const r=it(t);Oi(r,o)}function tk(n,t,e){return mb(n,t,e)}function hp(n,t){let e="";return t.forEach(o=>{if(!!o.insert){if(o.attributes&&o.attributes.box===!0&&o.attributes.type==="math"){e+=`[${T.t("mathjax.abstract")}] `;return}e+=o.insert}}),e}function ek(n,t){d(qi,P(n,t),"block in not textBlock");const e=n.selection.range;let o="";if(e.isCollapsed()){const r=n.getBlockText(t);o=hp(n,r)}else{const r=q(t),i=tn(n,{simpleBlockOnly:!0}).find(s=>q(s.block)===r);if(i&&!Tt(n,i.block)){d(qi,i.block===t,"block not match");const s=n.getBlockText(t),{start:l,end:c}=i,a=l.offset,u=c.offset-a;if(u>0){const{middle:f}=Wt(s,a,u);o=hp(n,f)}}}return{abstract:o.trim()}}function nk(n,t,e,o){return d(qi,t.text,"no text for text block"),o==="text"?Wb(n,t.text,e):o==="markdown"?Yb(n,t,e):Kb(n,t.text,e)}const ke={blockType:"text",blockKind:"text",createBlockContent:Jb,getBlockTextLength:Fi,getRangeFromPoint:Mb,moveCaret:Sb,updateSelection:gb,clearSelection:pb,getCaretRect:De,getClientRects:tk,setBlockText:Xb,getBlockProperties:ek,convertTo:nk},ok=Nl,Zl=B("action-helper");function fo(n,t){const e=H(t),o=U(e),r=J(t);return n.doc.getBlockData(o,r)}function he(n,t){d(Zl,P(n,t),"not a text kind block");const o=fo(n,t).text;return d(Zl,o,"no text in block"),o}function Yl(n,t,e){return be(he(n,t),e).left}function fp(n,t){const e=F(t);d(Zl,e,"no parent block");const o=he(n,e),r=Zm(t),i=o.find(s=>{const l=s.attributes;return l?l.box&&l.id===r:!1});return d(Zl,i,"failed to find box"),i.attributes}const St=B("block-text");function rk(n,t,e){d(St,P(n,t),"not a text kind block"),d(St,re(t,e),"not a valid offset"),d(St,e>=0&&e<W(n,t),`invalid offset: ${e}`);const r=Go(t,e)-e;r===0&&d(St,!1,`no text after offset: ${e}`);const i=he(n,t),{middle:s}=Wt(i,e,r);d(St,s.length===1,"failed to split text to 3 parts");const l=s[0];return zi(l)?" ":(d(St,l.insert.length===1||l.insert.length===2,"invalid op"),l.insert)}function ik(n,t,e){d(St,P(n,t),"not a text kind block"),d(St,re(t,e),"not a valid offset"),d(St,e>0&&e<=W(n,t),`invalid offset: ${e}`);const o=uo(t,e),r=e-o;r===0&&d(St,!1,`no text before offset: ${e}`);const i=he(n,t),{middle:s}=Wt(i,o,r);d(St,s.length===1,"failed to split text to 3 parts");const l=s[0];return zi(l)?" ":(d(St,l.insert.length===1||l.insert.length===2,"invalid op"),l.insert)}function Ql(n,t,e){d(St,P(n,t),"not a text kind block"),d(St,re(t,e),"not a valid offset"),d(St,e>0&&e<=W(n,t),`invalid offset: ${e}`);const o=uo(t,e),r=e-o;r===0&&d(St,!1,`no text before offset: ${e}`);const i=he(n,t),{middle:s}=Wt(i,o,r);d(St,s.length===1,"failed to split text to 3 parts");const l=s[0];return zi(l)?{op:l,charType:"box",offset:o,length:1}:{op:l,charType:vl(l.insert)?"space":"text",offset:o,length:l.insert.length}}function Wi(n,t,e){d(St,P(n,t),"not a text kind block"),d(St,re(t,e),"not a valid offset"),d(St,e>=0&&e<W(n,t),`invalid offset: ${e}`);const r=Go(t,e)-e;r===0&&d(St,!1,`no text after offset: ${e}`);const i=he(n,t),{middle:s}=Wt(i,e,r);d(St,s.length===1,"failed to split text to 3 parts");const l=s[0];return zi(l)?{op:l,charType:"box",offset:e,length:1}:{op:l,charType:vl(l.insert)?"space":"text",offset:e,length:l.insert.length}}function sk(n,t,e,o){let r=e;for(;r>0;){const i=Ql(n,t,r);if(i.charType===o)return i;r-=i.length}return null}function lk(n,t,e,o){const r=W(n,t);let i=e;for(;i<r;){const s=Wi(n,t,i);if(s.charType===o)return s;i+=s.length}return null}function Jd(n,t,e,o){let r=e;for(;r>0;){const i=Ql(n,t,r);if(i.charType!==o)return i;r-=i.length}return null}function Xd(n,t,e,o){const r=W(n,t);let i=e;for(;i<r;){const s=Wi(n,t,i);if(s.charType!==o)return s;i+=s.length}return null}function tu(n,t,e){if(d(St,P(n,t),"invalid blok type"),Tt(n,t))return 0;const o=Ql(n,t,e);if(o.charType==="box")return e-1;let r=e;if(o.charType==="space"){const s=Jd(n,t,r,"space");if(!s||s.offset===0)return 0;if(s.charType==="box")return s.offset;r=s.offset}const i=Jd(n,t,r,"text");return i?i.offset+i.length:0}function eu(n,t,e){if(d(St,P(n,t),"invalid blok type"),Tt(n,t))return 0;const o=Wi(n,t,e);if(o.charType==="box")return e+1;let r=e;if(o.charType==="space"){const s=Xd(n,t,r,"space");if(!s||s.offset===0)return W(n,t);if(s.charType==="box")return s.offset;r=s.offset}const i=Xd(n,t,r,"text");return i?i.offset:W(n,t)}const mp=B("text-box");function ck(n,t,e,o){d(mp,o.text,`no text for text box data: ${JSON.stringify(o)}`),d(mp,typeof o.text=="string",`invalid text type for text box data: ${JSON.stringify(o)}`),b("span",[],e,o.text)}function ak(n,t,e,o){var r;return(r=t.text)!=null?r:""}const gp={boxType:"text",updateBoxContent:ck,convertTo:ak},dk="data:image/svg+xml;base64,Cjxzdmcgdmlld0JveD0iMCAwIDI0IDI0IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgo8cGF0aCBkPSJNMTguMjQ0NSA2QzE3LjgyNzQgNiAxNy41MzYzIDYuMjkxMTcgMTcuNTM2MyA2LjcwODI2QzE3LjUzNjMgNi45ODM3IDE3LjU1OTkgNy4yMzU1MyAxNy41NTk5IDcuNjEzMjdDMTcuNTU5OSAxMC4yODExIDE2LjYyMzQgMTEuMzc0OSAxMy45NzkyIDExLjM3NDlIOC45NDI2Nkw3LjEyNDc5IDExLjQ4NTFMOS41NDA3NSA5LjI4MTYyTDExLjE5MzQgNy41OTc1M0MxMS4zMjcxIDcuNDcxNjEgMTEuMzk4IDcuMjgyNzQgMTEuMzk4IDcuMDkzODdDMTEuMzk4IDYuNjkyNTIgMTEuMDk4OSA2LjQwMTM1IDEwLjY5NzYgNi40MDEzNUMxMC41MDg3IDYuNDAxMzUgMTAuMzM1NiA2LjQ3MjE4IDEwLjE3ODIgNi42MjE3TDUuMjQzOTYgMTEuNTQ4MUM1LjA4NjU3IDExLjcwNTUgNSAxMS44OTQzIDUgMTIuMDkxMUM1IDEyLjI4NzggNS4wODY1NyAxMi40NzY3IDUuMjQzOTYgMTIuNjI2MkwxMC4xNjI1IDE3LjUzNjhDMTAuMzM1NiAxNy43MDk5IDEwLjUwODcgMTcuNzgwOCAxMC42OTc2IDE3Ljc4MDhDMTEuMDk4OSAxNy43ODA4IDExLjM5OCAxNy40ODk2IDExLjM5OCAxNy4wODgzQzExLjM5OCAxNi44OTE1IDExLjMyNzEgMTYuNzEwNSAxMS4xOTM0IDE2LjU4NDZMOS41NDA3NSAxNC45MDA1TDcuMTMyNjYgMTIuNjk3TDguOTQyNjYgMTIuODA3MkgxNC4wNTc5QzE3LjU1OTkgMTIuODA3MiAxOSAxMS4yNDExIDE5IDcuNjc2MjJDMTkgNy4yMzU1MyAxOC45OTIxIDYuODY1NjUgMTguOTM3IDYuNjEzODNDMTguODc0MSA2LjI5OTA0IDE4LjY3NzMgNiAxOC4yNDQ1IDZaIiBmaWxsPSIjQjJCQ0NEIi8+Cjwvc3ZnPgo=";function uk(n,t,e,o){rm(dk,[],e),b("br",[],e)}function hk(n,t,e,o){return o==="text"?`
22
+ `),i}const Qb=B("block-to-text");function Kb(n,t,e){let o="";return t.forEach(r=>{if(d(Qb,typeof r.insert=="string","invalid op"),r.attributes&&r.attributes.box===!0){const s=r.attributes,l=n.editorBoxes.getBoxClass(s.type);if(l!=null&&l.convertTo){o+=l.convertTo(n,s,e,"html");return}if(r.attributes.text){o+=r.attributes.text;return}o+=`[${s.type}]`}const i=r.attributes;if(i){let s=r.insert;i.link&&(s=`<a href="${i.link}">${s}</a>`);const l=[];i.bold&&l.push("strong"),i.italic&&l.push("em"),i.underline&&l.push("u"),i.strike&&l.push("s"),i.code&&l.push("code");const c=l.map(u=>`<${u}>`).join(""),a=l.reverse().map(u=>`</${u}>`).join("");o+=c+s+a;return}o+=r.insert}),o||(o="<br>"),`<p>${o}</p>`}const qi=B("text-block");function Jb(n,t,e,o,r){const{text:i}=r;d(qi,i,"no text for text block");const s=ro(o,"div");return Nl(n,t,r.id,s,i),s}function Xb(n,t,e){d(qi,e,"no text to update");const o=ro(null,"div");Nl(n,io(t),q(t),o,e);const r=it(t);Oi(r,o)}function tk(n,t,e){return mb(n,t,e)}function hp(n,t){let e="";return t.forEach(o=>{if(!!o.insert){if(o.attributes&&o.attributes.box===!0&&o.attributes.type==="math"){e+=`[${T.t("mathjax.abstract")}] `;return}e+=o.insert}}),e}function ek(n,t){d(qi,P(n,t),"block in not textBlock");const e=n.selection.range;let o="";if(e.isCollapsed()){const r=n.getBlockText(t);o=hp(n,r)}else{const r=q(t),i=tn(n,{simpleBlockOnly:!0}).find(s=>q(s.block)===r);if(i&&!Tt(n,i.block)){d(qi,i.block===t,"block not match");const s=n.getBlockText(t),{start:l,end:c}=i,a=l.offset,u=c.offset-a;if(u>0){const{middle:f}=Wt(s,a,u);o=hp(n,f)}}}return{abstract:o.trim()}}function nk(n,t,e,o){return d(qi,t.text,"no text for text block"),o==="text"?Wb(n,t.text,e):o==="markdown"?Yb(n,t,e):Kb(n,t.text,e)}const ke={blockType:"text",blockKind:"text",createBlockContent:Jb,getBlockTextLength:Fi,getRangeFromPoint:Mb,moveCaret:Sb,updateSelection:gb,clearSelection:pb,getCaretRect:De,getClientRects:tk,setBlockText:Xb,getBlockProperties:ek,convertTo:nk},ok=Nl,Zl=B("action-helper");function mo(n,t){const e=H(t),o=U(e),r=J(t);return n.doc.getBlockData(o,r)}function he(n,t){d(Zl,P(n,t),"not a text kind block");const o=mo(n,t).text;return d(Zl,o,"no text in block"),o}function Yl(n,t,e){return be(he(n,t),e).left}function fp(n,t){const e=F(t);d(Zl,e,"no parent block");const o=he(n,e),r=Zm(t),i=o.find(s=>{const l=s.attributes;return l?l.box&&l.id===r:!1});return d(Zl,i,"failed to find box"),i.attributes}const St=B("block-text");function rk(n,t,e){d(St,P(n,t),"not a text kind block"),d(St,re(t,e),"not a valid offset"),d(St,e>=0&&e<W(n,t),`invalid offset: ${e}`);const r=Go(t,e)-e;r===0&&d(St,!1,`no text after offset: ${e}`);const i=he(n,t),{middle:s}=Wt(i,e,r);d(St,s.length===1,"failed to split text to 3 parts");const l=s[0];return zi(l)?" ":(d(St,l.insert.length===1||l.insert.length===2,"invalid op"),l.insert)}function ik(n,t,e){d(St,P(n,t),"not a text kind block"),d(St,re(t,e),"not a valid offset"),d(St,e>0&&e<=W(n,t),`invalid offset: ${e}`);const o=ho(t,e),r=e-o;r===0&&d(St,!1,`no text before offset: ${e}`);const i=he(n,t),{middle:s}=Wt(i,o,r);d(St,s.length===1,"failed to split text to 3 parts");const l=s[0];return zi(l)?" ":(d(St,l.insert.length===1||l.insert.length===2,"invalid op"),l.insert)}function Ql(n,t,e){d(St,P(n,t),"not a text kind block"),d(St,re(t,e),"not a valid offset"),d(St,e>0&&e<=W(n,t),`invalid offset: ${e}`);const o=ho(t,e),r=e-o;r===0&&d(St,!1,`no text before offset: ${e}`);const i=he(n,t),{middle:s}=Wt(i,o,r);d(St,s.length===1,"failed to split text to 3 parts");const l=s[0];return zi(l)?{op:l,charType:"box",offset:o,length:1}:{op:l,charType:vl(l.insert)?"space":"text",offset:o,length:l.insert.length}}function Wi(n,t,e){d(St,P(n,t),"not a text kind block"),d(St,re(t,e),"not a valid offset"),d(St,e>=0&&e<W(n,t),`invalid offset: ${e}`);const r=Go(t,e)-e;r===0&&d(St,!1,`no text after offset: ${e}`);const i=he(n,t),{middle:s}=Wt(i,e,r);d(St,s.length===1,"failed to split text to 3 parts");const l=s[0];return zi(l)?{op:l,charType:"box",offset:e,length:1}:{op:l,charType:vl(l.insert)?"space":"text",offset:e,length:l.insert.length}}function sk(n,t,e,o){let r=e;for(;r>0;){const i=Ql(n,t,r);if(i.charType===o)return i;r-=i.length}return null}function lk(n,t,e,o){const r=W(n,t);let i=e;for(;i<r;){const s=Wi(n,t,i);if(s.charType===o)return s;i+=s.length}return null}function Jd(n,t,e,o){let r=e;for(;r>0;){const i=Ql(n,t,r);if(i.charType!==o)return i;r-=i.length}return null}function Xd(n,t,e,o){const r=W(n,t);let i=e;for(;i<r;){const s=Wi(n,t,i);if(s.charType!==o)return s;i+=s.length}return null}function tu(n,t,e){if(d(St,P(n,t),"invalid blok type"),Tt(n,t))return 0;const o=Ql(n,t,e);if(o.charType==="box")return e-1;let r=e;if(o.charType==="space"){const s=Jd(n,t,r,"space");if(!s||s.offset===0)return 0;if(s.charType==="box")return s.offset;r=s.offset}const i=Jd(n,t,r,"text");return i?i.offset+i.length:0}function eu(n,t,e){if(d(St,P(n,t),"invalid blok type"),Tt(n,t))return 0;const o=Wi(n,t,e);if(o.charType==="box")return e+1;let r=e;if(o.charType==="space"){const s=Xd(n,t,r,"space");if(!s||s.offset===0)return W(n,t);if(s.charType==="box")return s.offset;r=s.offset}const i=Xd(n,t,r,"text");return i?i.offset:W(n,t)}const mp=B("text-box");function ck(n,t,e,o){d(mp,o.text,`no text for text box data: ${JSON.stringify(o)}`),d(mp,typeof o.text=="string",`invalid text type for text box data: ${JSON.stringify(o)}`),b("span",[],e,o.text)}function ak(n,t,e,o){var r;return(r=t.text)!=null?r:""}const gp={boxType:"text",updateBoxContent:ck,convertTo:ak},dk="data:image/svg+xml;base64,Cjxzdmcgdmlld0JveD0iMCAwIDI0IDI0IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgo8cGF0aCBkPSJNMTguMjQ0NSA2QzE3LjgyNzQgNiAxNy41MzYzIDYuMjkxMTcgMTcuNTM2MyA2LjcwODI2QzE3LjUzNjMgNi45ODM3IDE3LjU1OTkgNy4yMzU1MyAxNy41NTk5IDcuNjEzMjdDMTcuNTU5OSAxMC4yODExIDE2LjYyMzQgMTEuMzc0OSAxMy45NzkyIDExLjM3NDlIOC45NDI2Nkw3LjEyNDc5IDExLjQ4NTFMOS41NDA3NSA5LjI4MTYyTDExLjE5MzQgNy41OTc1M0MxMS4zMjcxIDcuNDcxNjEgMTEuMzk4IDcuMjgyNzQgMTEuMzk4IDcuMDkzODdDMTEuMzk4IDYuNjkyNTIgMTEuMDk4OSA2LjQwMTM1IDEwLjY5NzYgNi40MDEzNUMxMC41MDg3IDYuNDAxMzUgMTAuMzM1NiA2LjQ3MjE4IDEwLjE3ODIgNi42MjE3TDUuMjQzOTYgMTEuNTQ4MUM1LjA4NjU3IDExLjcwNTUgNSAxMS44OTQzIDUgMTIuMDkxMUM1IDEyLjI4NzggNS4wODY1NyAxMi40NzY3IDUuMjQzOTYgMTIuNjI2MkwxMC4xNjI1IDE3LjUzNjhDMTAuMzM1NiAxNy43MDk5IDEwLjUwODcgMTcuNzgwOCAxMC42OTc2IDE3Ljc4MDhDMTEuMDk4OSAxNy43ODA4IDExLjM5OCAxNy40ODk2IDExLjM5OCAxNy4wODgzQzExLjM5OCAxNi44OTE1IDExLjMyNzEgMTYuNzEwNSAxMS4xOTM0IDE2LjU4NDZMOS41NDA3NSAxNC45MDA1TDcuMTMyNjYgMTIuNjk3TDguOTQyNjYgMTIuODA3MkgxNC4wNTc5QzE3LjU1OTkgMTIuODA3MiAxOSAxMS4yNDExIDE5IDcuNjc2MjJDMTkgNy4yMzU1MyAxOC45OTIxIDYuODY1NjUgMTguOTM3IDYuNjEzODNDMTguODc0MSA2LjI5OTA0IDE4LjY3NzMgNiAxOC4yNDQ1IDZaIiBmaWxsPSIjQjJCQ0NEIi8+Cjwvc3ZnPgo=";function uk(n,t,e,o){rm(dk,[],e),b("br",[],e)}function hk(n,t,e,o){return o==="text"?`
23
23
  `:o==="html"?"<br>":o==="markdown"?`
24
- `:""}const pp={boxType:"br",updateBoxContent:uk,convertTo:hk},Cp=B("editor-boxes");class bp{constructor(t){h(this,"boxes",new Map);this.editor=t}registerBoxClass(t){const e=t.boxType,o=this.boxes.get(e);d(Cp,!o,`duplicated box type: ${e}`),this.boxes.set(e,t)}getBoxClass(t){const e=this.boxes.get(t);return d(Cp,e,`unknown box type: ${t}`),e}createBox(t,e){const o=Gm(e),r=Ym(o);return this.getBoxClass(e.type).updateBoxContent(this.editor,o,r,e),o}}function fk(n,t,e,o){b("span",[],e,o.text)}const kp={insertionType:"inputting",updateInsertionContent:fk},vp=B("editor-insertion");class yp{constructor(t){h(this,"insertions",new Map);this.editor=t}registerInsertionClass(t){const e=t.insertionType,o=this.insertions.get(e);d(vp,!o,`duplicated insertion type: ${e}`),this.insertions.set(e,t)}getInsertionClass(t){const e=this.insertions.get(t);return d(vp,e,`unknown insertion type: ${t}`),e}createInsertion(t,e){const o=Qm(e.type,e.id),r=Jm(o);return this.getInsertionClass(e.type).updateInsertionContent(this.editor,o,r,e),o}}class mk{constructor(t){h(this,"cursors",new Map);h(this,"timer");this.editor=t,this.timer=this.startTimer()}add(t,e){this.cursors.set(t,e)}startTimer(){return setInterval(()=>{const t=Date.now();Array.from(this.cursors).forEach(([e,o])=>{if(t-o>3e3){const r=Km(this.editor,e);r&&z(r,"active"),this.cursors.delete(e)}})},1e3)}destroy(){clearInterval(this.timer)}}function gk(n,t,e,o){var l;const r=o;Date.now()-r.time<5*1e3&&(n.addCustom("active-cursors",a=>new mk(a)).add(r.id,r.time),A(t,"active")),b("span",[],e,"|").setAttribute("data-cursor-name",r.name),t.style.setProperty("--cursor-color",n.getColor((l=r.rainbowIndex)!=null?l:0))}const nu={insertionType:"remote-cursor",updateInsertionContent:gk};class wp{constructor(t){h(this,"decorators",[]);this.editor=t}registerDecorator(t){this.decorators.push(t)}decorateBlock(t,e){let o=e;return this.decorators.forEach(r=>{if(r.decorateBlock){const i=r.decorateBlock(this.editor,t,e);i&&(o=Y.default(i))}}),o}decorateText(t,e){let o=e;const r=new Map;return this.decorators.forEach(i=>{if(i.decorateText){const s=i.decorateText(this.editor,t,e);if(s){const{insertions:l,text:c}=s;l&&Array.from(l.entries()).forEach(([a,u])=>{const f=r.get(a);f?f.push(...u):r.set(a,u)}),c&&(o=Y.default(c))}}}),{insertions:r,text:o}}}const ou=B("editor-input");class pk{constructor(t,e){h(this,"editor");h(this,"composing",!1);h(this,"callbacks");h(this,"inputElement");h(this,"handleDocumentSelectionChange",()=>{setTimeout(()=>{var e;const t=(e=document.getSelection())==null?void 0:e.focusNode;t&&this.editor.contains(t)&&!Ni(t)?(this.editor.emit("focus",this.editor),this.callbacks.onFocus(),this.editor.input.focus()):(this.editor.emit("blur",this.editor),this.callbacks.onBlur())},100)});h(this,"handleEditorSelectionChanged",()=>{const e=!this.editor.isWritable();this.inputElement.readOnly=e});h(this,"handleReadonlyChanged",()=>{this.handleEditorSelectionChanged()});h(this,"handleCompositionstart",t=>{this.composing=!0,this.callbacks.onCompositionStart(t)});h(this,"handleCompositionend",t=>{this.composing=!1,this.callbacks.onUpdateCompositionText(t,this.inputElement.value,!0),this.inputElement.value=""});h(this,"handleInput",t=>{if(t instanceof InputEvent&&!!t.data){if(this.editor.readonly){this.inputElement.value="";return}this.composing?this.callbacks.onUpdateCompositionText(t,t.data,!1):(this.callbacks.onInsertText(t,t.data),this.inputElement.value="")}});h(this,"handleKeyDown",t=>{if(!this.composing){if(this.callbacks.onKeyDown(t)){t.preventDefault(),t.stopPropagation();return}setTimeout(()=>{this.composing||(this.inputElement.value="")})}});h(this,"handleCopy",t=>{this.callbacks.onCopy(t)});h(this,"handleCut",t=>{if(this.editor.readonly){t.stopPropagation(),t.preventDefault();return}ou.debug("on cut")});h(this,"handlePaste",t=>{if(this.editor.readonly){t.stopPropagation(),t.preventDefault();return}this.callbacks.onPaste(t)});h(this,"handlePasteText",t=>{this.callbacks.onPasteText(t)});this.editor=t,this.callbacks=e;const o=b("input",["editor-input"],t.contentElement);o.type="text",o.name="editor-input",o.onkeydown=this.handleKeyDown,o.oninput=this.handleInput,o.oncopy=this.handleCopy,o.onpaste=this.handlePaste,o.oncut=this.handleCut,o.addEventListener("compositionstart",this.handleCompositionstart),o.addEventListener("compositionend",this.handleCompositionend),this.inputElement=o,document.addEventListener("selectionchange",this.handleDocumentSelectionChange),this.editor.addListener("selectionChanged",this.handleEditorSelectionChanged),this.editor.addListener("readonlyChanged",this.handleReadonlyChanged)}destroy(){this.callbacks.destroy(),document.removeEventListener("selectionchange",this.handleDocumentSelectionChange),this.editor.removeListener("selectionChanged",this.handleEditorSelectionChanged),this.editor.removeListener("readonlyChanged",this.handleReadonlyChanged);const t=this.inputElement;t.removeEventListener("compositionstart",this.handleCompositionstart),t.removeEventListener("compositionend",this.handleCompositionend),t.onkeydown=null,t.oninput=null,t.oncopy=null,t.onpaste=null,t.oncut=null}getInput(){return this.inputElement}focus(){this.editor.selection.caret.visible()||this.editor.selection.caret.update(),xt.isMobileSafari?this.inputElement.focus():setTimeout(()=>{this.inputElement.focus()})}handleChanged(t){this.callbacks.onChanged(t)}handleRemoteChanged(t){this.callbacks.onRemoteChanged(t)}addHandler(t){this.callbacks.addHandler(t)}removeHandler(t){this.callbacks.removeHandler(t)}defaultInsertText(t,e,o,r,i){d(ou,t===this.editor,"invalid editor"),this.callbacks.defaultInsertText(t,e,o,r,i)}defaultHandleKeydown(t,e){return d(ou,t===this.editor,"invalid editor"),this.callbacks.defaultHandleKeydown(t,e)}}function Bp(n){const e=n.rootElement.getBoundingClientRect(),o=window.innerWidth,r=window.innerHeight,i=e.left<0?0:e.left,s=e.top<0?0:e.top,l=e.right>o?o:e.right,c=e.bottom>r?r:e.bottom,a=(i+l)/2,u=(s+c)/2,f=0-e.left+a,m=0-e.top+u,C=n.input.inputElement;C.style.left=`${f}px`,C.style.top=`${m}px`}const ru=B("editor-caret");class Ck{constructor(t){h(this,"editor");h(this,"caretElem");h(this,"handleReadOnlyChanged",()=>{this.update()});this.editor=t,this.caretElem=b("div",["editor-cursor"],this.editor.contentElement),this.editor.on("readonlyChanged",this.handleReadOnlyChanged)}destroy(){this.editor.off("readonlyChanged",this.handleReadOnlyChanged)}visible(){const t=window.getComputedStyle(this.caretElem);return t.display!=="none"&&t.opacity!=="0"}hasCaret(){if(this.editor.readonly||!this.editor.selection.range.isCollapsed())return!1;const t=this.editor.selection.range.start;if(!(t instanceof Vt))return!1;const e=this.editor.getBlockById(t.blockId);return!!P(this.editor,e)}update(){if(lm(this.editor.rootElement))return;const t=this.caretElem;if(this.hasCaret())t.style.display="";else{t.style.display="none",Bp(this.editor);return}const{range:e}=this.editor.selection;d(ru,e.isCollapsed,"range is not collapsed");const o=e.start;d(ru,o instanceof Vt,"only simple block position can has caret");const r=this.editor.getBlockById(o.blockId);d(ru,P(this.editor,r),"only text kind block can has caret");let i;const s=r.querySelector("span.inputting-insertion");s?(i=No(s),i=new DOMRect(i.right,i.top,1,i.height)):i=De(r,o);const l=this.editor.contentElement.getBoundingClientRect(),c=i.left-l.left,a=i.top-l.top;t.style.left=`${c}px`,t.style.top=`${a}px`,t.style.height=`${i.height}px`;const u=this.editor.input.inputElement;u.style.left=`${c}px`,u.style.top=`${a+i.height-24}px`,xt.isMobileSafari&&(u.style.left=`${c-4}px`,u.style.height=`${i.height}px`);const m=We(r,{horizontal:!0}).getBoundingClientRect(),C=m.left-l.left,k=C+m.width;c<C||c>k?(Bp(this.editor),t.style.opacity="0"):t.style.opacity="1"}}function bk(n){ug(n),n.selection.range.getSelectedBlocks().forEach(t=>hg(n,t.block,t.start,t.end))}function Ep(n){return We(n.rootContainer).clientHeight}function kk(n){return n.getFirstBlock().getBoundingClientRect().top}function vk(n){return n.getLastBlock().getBoundingClientRect().bottom}function iu(n){const e=We(n.rootContainer).getBoundingClientRect(),o=e.x<0?0:e.x,r=e.y<0?0:e.y,i=e.right>window.innerWidth?window.innerWidth:e.right,s=e.bottom>window.innerHeight?window.innerHeight:e.bottom;return new DOMRect(o,r,i-o,s-r)}function yk(n,t){const e=iu(n),o=n.getBlockById(t.blockId),i=Ke(n,o,t);return Po(e,i.x,i.y)&&Po(e,i.right,i.bottom)}function wk(n,t){const e=iu(n),o=t.getBoundingClientRect();return o.top>=e.top&&o.top<=e.bottom||o.bottom<=e.bottom&&o.bottom>=e.top}function Bk(n,t){const e=iu(n),o=t.getBoundingClientRect();return Po(e,o.x,o.y)||Po(e,o.right,o.bottom)}function Ek(n){const t=n.selection,e=t.range.focus;if(!e.isSimple()){const a=e,u=n.getContainerById(a.childContainerId);Bk(n,u)||u.scrollIntoView();return}if(t.range.start.blockId===t.range.end.blockId){const a=n.getBlockById(t.range.start.blockId);if(Te(a)&&wk(n,a))return}const o=e,r=n.getBlockById(o.blockId);if(yk(n,o))return;const i=Ke(n,r,o),s=r.getBoundingClientRect(),l=Rt(r),c=b("div",["editor-block-anchor"],l);c.style.top=`${i.top-s.top}px`,id(c,{elementToScroll:We(n.rootContainer)}),setTimeout(()=>{c.remove()},200)}function Ik(n,t){if(t.isCollapsed())return!1;const e=Ut(n.rootContainer),o=Qt(n.rootContainer),{start:r,end:i}=t;return r.blockId===q(e)&&r.offset===0&&i.blockId===q(o)&&i.offset===W(n,o)}const Ip=B("range-in-block");function xp(n,t){const e=t.getEditor(),o=e.getBlockById(t.start.blockId),r=e.getBlockById(t.end.blockId),i=o===n||It(n,o),s=r===n||It(n,r);return!!(i||s)}function Tp(n,t){const e=n.doc.toJSON(),o=new Set(Object.values(e.blocks).map(s=>s.map(l=>l.id)).flat());let r,i=gt(t);if(i){for(;i&&!o.has(q(i));)i=gt(i);d(Ip,i,"no prev block while deleting a block"),r=At(n,i,W(n,i))}else{const s=dt(t);d(Ip,s,"no prev and next block while deleting a block"),r=At(n,s,0)}return r}const xk=B("block-to-html");function su(n,t,e,o){const r=Ir(n,t.type);if(r.convertTo)return r.convertTo(n,t,e,"html",o);if(r.blockKind!=="text")return`[${t.type}]`;d(xk,t.text,"no text");const i=bt(t.text);return`<div>${dm(i)}</div>`}const Sp=B("block-to-text");function Tk(n,t,e){let o="";return t.forEach(r=>{if(d(Sp,typeof r.insert=="string","invalid op"),r.attributes&&r.attributes.box===!0){const i=r.attributes,s=n.editorBoxes.getBoxClass(i.type);if(s!=null&&s.convertTo){o+=s.convertTo(n,i,e,"text");return}if(r.attributes.text){o+=r.attributes.text;return}o+=`[${i.type}]`}o+=r.insert}),o}function Kl(n,t,e,o){const r=Ir(n,t.type);return r.convertTo?r.convertTo(n,t,e,"text",o):r.blockKind!=="text"?`[${t.type}]`:(d(Sp,t.text,"no text"),Tk(n,t.text,e))}function lu(n,t,e,o){const r=Ir(n,t.type);return r.convertTo?r.convertTo(n,t,e,"markdown",o):Kl(n,t,e,o)}function Dr(n,t){return t.blocks.root.map((r,i)=>su(n,r,t,[{containerId:"root",blockIndex:i}])).join(`
24
+ `:""}const pp={boxType:"br",updateBoxContent:uk,convertTo:hk},Cp=B("editor-boxes");class bp{constructor(t){h(this,"boxes",new Map);this.editor=t}registerBoxClass(t){const e=t.boxType,o=this.boxes.get(e);d(Cp,!o,`duplicated box type: ${e}`),this.boxes.set(e,t)}getBoxClass(t){const e=this.boxes.get(t);return d(Cp,e,`unknown box type: ${t}`),e}createBox(t,e){const o=Gm(e),r=Ym(o);return this.getBoxClass(e.type).updateBoxContent(this.editor,o,r,e),o}}function fk(n,t,e,o){b("span",[],e,o.text)}const kp={insertionType:"inputting",updateInsertionContent:fk},vp=B("editor-insertion");class yp{constructor(t){h(this,"insertions",new Map);this.editor=t}registerInsertionClass(t){const e=t.insertionType,o=this.insertions.get(e);d(vp,!o,`duplicated insertion type: ${e}`),this.insertions.set(e,t)}getInsertionClass(t){const e=this.insertions.get(t);return d(vp,e,`unknown insertion type: ${t}`),e}createInsertion(t,e){const o=Qm(e.type,e.id),r=Jm(o);return this.getInsertionClass(e.type).updateInsertionContent(this.editor,o,r,e),o}}class mk{constructor(t){h(this,"cursors",new Map);h(this,"timer");this.editor=t,this.timer=this.startTimer()}add(t,e){this.cursors.set(t,e)}startTimer(){return setInterval(()=>{const t=Date.now();Array.from(this.cursors).forEach(([e,o])=>{if(t-o>3e3){const r=Km(this.editor,e);r&&z(r,"active"),this.cursors.delete(e)}})},1e3)}destroy(){clearInterval(this.timer)}}function gk(n,t,e,o){var l;const r=o;Date.now()-r.time<5*1e3&&(n.addCustom("active-cursors",a=>new mk(a)).add(r.id,r.time),A(t,"active")),b("span",[],e,"|").setAttribute("data-cursor-name",r.name),t.style.setProperty("--cursor-color",n.getColor((l=r.rainbowIndex)!=null?l:0))}const nu={insertionType:"remote-cursor",updateInsertionContent:gk};class wp{constructor(t){h(this,"decorators",[]);this.editor=t}registerDecorator(t){this.decorators.push(t)}decorateBlock(t,e){let o=e;return this.decorators.forEach(r=>{if(r.decorateBlock){const i=r.decorateBlock(this.editor,t,e);i&&(o=Y.default(i))}}),o}decorateText(t,e){let o=e;const r=new Map;return this.decorators.forEach(i=>{if(i.decorateText){const s=i.decorateText(this.editor,t,e);if(s){const{insertions:l,text:c}=s;l&&Array.from(l.entries()).forEach(([a,u])=>{const f=r.get(a);f?f.push(...u):r.set(a,u)}),c&&(o=Y.default(c))}}}),{insertions:r,text:o}}}const ou=B("editor-input");class pk{constructor(t,e){h(this,"editor");h(this,"composing",!1);h(this,"callbacks");h(this,"inputElement");h(this,"handleDocumentSelectionChange",()=>{setTimeout(()=>{var e;const t=(e=document.getSelection())==null?void 0:e.focusNode;t&&this.editor.contains(t)&&!Ni(t)?(this.editor.emit("focus",this.editor),this.callbacks.onFocus(),this.editor.input.focus()):(this.editor.emit("blur",this.editor),this.callbacks.onBlur())},100)});h(this,"handleEditorSelectionChanged",()=>{const e=!this.editor.isWritable();this.inputElement.readOnly=e});h(this,"handleReadonlyChanged",()=>{this.handleEditorSelectionChanged()});h(this,"handleCompositionstart",t=>{this.composing=!0,this.callbacks.onCompositionStart(t)});h(this,"handleCompositionend",t=>{this.composing=!1,this.callbacks.onUpdateCompositionText(t,this.inputElement.value,!0),this.inputElement.value=""});h(this,"handleInput",t=>{if(t instanceof InputEvent&&!!t.data){if(this.editor.readonly){this.inputElement.value="";return}this.composing?this.callbacks.onUpdateCompositionText(t,t.data,!1):(this.callbacks.onInsertText(t,t.data),this.inputElement.value="")}});h(this,"handleKeyDown",t=>{if(!this.composing){if(this.callbacks.onKeyDown(t)){t.preventDefault(),t.stopPropagation();return}setTimeout(()=>{this.composing||(this.inputElement.value="")})}});h(this,"handleCopy",t=>{this.callbacks.onCopy(t)});h(this,"handleCut",t=>{if(this.editor.readonly){t.stopPropagation(),t.preventDefault();return}ou.debug("on cut")});h(this,"handlePaste",t=>{if(this.editor.readonly){t.stopPropagation(),t.preventDefault();return}this.callbacks.onPaste(t)});h(this,"handlePasteText",t=>{this.callbacks.onPasteText(t)});this.editor=t,this.callbacks=e;const o=b("input",["editor-input"],t.contentElement);o.type="text",o.name="editor-input",o.onkeydown=this.handleKeyDown,o.oninput=this.handleInput,o.oncopy=this.handleCopy,o.onpaste=this.handlePaste,o.oncut=this.handleCut,o.addEventListener("compositionstart",this.handleCompositionstart),o.addEventListener("compositionend",this.handleCompositionend),this.inputElement=o,document.addEventListener("selectionchange",this.handleDocumentSelectionChange),this.editor.addListener("selectionChanged",this.handleEditorSelectionChanged),this.editor.addListener("readonlyChanged",this.handleReadonlyChanged)}destroy(){this.callbacks.destroy(),document.removeEventListener("selectionchange",this.handleDocumentSelectionChange),this.editor.removeListener("selectionChanged",this.handleEditorSelectionChanged),this.editor.removeListener("readonlyChanged",this.handleReadonlyChanged);const t=this.inputElement;t.removeEventListener("compositionstart",this.handleCompositionstart),t.removeEventListener("compositionend",this.handleCompositionend),t.onkeydown=null,t.oninput=null,t.oncopy=null,t.onpaste=null,t.oncut=null}getInput(){return this.inputElement}focus(){this.editor.selection.caret.visible()||this.editor.selection.caret.update(),xt.isMobileSafari?this.inputElement.focus():setTimeout(()=>{this.inputElement.focus()})}handleChanged(t){this.callbacks.onChanged(t)}handleRemoteChanged(t){this.callbacks.onRemoteChanged(t)}addHandler(t){this.callbacks.addHandler(t)}removeHandler(t){this.callbacks.removeHandler(t)}defaultInsertText(t,e,o,r,i){d(ou,t===this.editor,"invalid editor"),this.callbacks.defaultInsertText(t,e,o,r,i)}defaultHandleKeydown(t,e){return d(ou,t===this.editor,"invalid editor"),this.callbacks.defaultHandleKeydown(t,e)}}function Bp(n){const e=n.rootElement.getBoundingClientRect(),o=window.innerWidth,r=window.innerHeight,i=e.left<0?0:e.left,s=e.top<0?0:e.top,l=e.right>o?o:e.right,c=e.bottom>r?r:e.bottom,a=(i+l)/2,u=(s+c)/2,f=0-e.left+a,m=0-e.top+u,C=n.input.inputElement;C.style.left=`${f}px`,C.style.top=`${m}px`}const ru=B("editor-caret");class Ck{constructor(t){h(this,"editor");h(this,"caretElem");h(this,"handleReadOnlyChanged",()=>{this.update()});this.editor=t,this.caretElem=b("div",["editor-cursor"],this.editor.contentElement),this.editor.on("readonlyChanged",this.handleReadOnlyChanged)}destroy(){this.editor.off("readonlyChanged",this.handleReadOnlyChanged)}visible(){const t=window.getComputedStyle(this.caretElem);return t.display!=="none"&&t.opacity!=="0"}hasCaret(){if(this.editor.readonly||!this.editor.selection.range.isCollapsed())return!1;const t=this.editor.selection.range.start;if(!(t instanceof Vt))return!1;const e=this.editor.getBlockById(t.blockId);return!!P(this.editor,e)}update(){if(lm(this.editor.rootElement))return;const t=this.caretElem;if(this.hasCaret())t.style.display="";else{t.style.display="none",Bp(this.editor);return}const{range:e}=this.editor.selection;d(ru,e.isCollapsed,"range is not collapsed");const o=e.start;d(ru,o instanceof Vt,"only simple block position can has caret");const r=this.editor.getBlockById(o.blockId);d(ru,P(this.editor,r),"only text kind block can has caret");let i;const s=r.querySelector("span.inputting-insertion");s?(i=$o(s),i=new DOMRect(i.right,i.top,1,i.height)):i=De(r,o);const l=this.editor.contentElement.getBoundingClientRect(),c=i.left-l.left,a=i.top-l.top;t.style.left=`${c}px`,t.style.top=`${a}px`,t.style.height=`${i.height}px`;const u=this.editor.input.inputElement;u.style.left=`${c}px`,u.style.top=`${a+i.height-24}px`,xt.isMobileSafari&&(u.style.left=`${c-4}px`,u.style.height=`${i.height}px`);const m=We(r,{horizontal:!0}).getBoundingClientRect(),C=m.left-l.left,k=C+m.width;c<C||c>k?(Bp(this.editor),t.style.opacity="0"):t.style.opacity="1"}}function bk(n){ug(n),n.selection.range.getSelectedBlocks().forEach(t=>hg(n,t.block,t.start,t.end))}function Ep(n){return We(n.rootContainer).clientHeight}function kk(n){return n.getFirstBlock().getBoundingClientRect().top}function vk(n){return n.getLastBlock().getBoundingClientRect().bottom}function iu(n){const e=We(n.rootContainer).getBoundingClientRect(),o=e.x<0?0:e.x,r=e.y<0?0:e.y,i=e.right>window.innerWidth?window.innerWidth:e.right,s=e.bottom>window.innerHeight?window.innerHeight:e.bottom;return new DOMRect(o,r,i-o,s-r)}function yk(n,t){const e=iu(n),o=n.getBlockById(t.blockId),i=Ke(n,o,t);return jo(e,i.x,i.y)&&jo(e,i.right,i.bottom)}function wk(n,t){const e=iu(n),o=t.getBoundingClientRect();return o.top>=e.top&&o.top<=e.bottom||o.bottom<=e.bottom&&o.bottom>=e.top}function Bk(n,t){const e=iu(n),o=t.getBoundingClientRect();return jo(e,o.x,o.y)||jo(e,o.right,o.bottom)}function Ek(n){const t=n.selection,e=t.range.focus;if(!e.isSimple()){const a=e,u=n.getContainerById(a.childContainerId);Bk(n,u)||u.scrollIntoView();return}if(t.range.start.blockId===t.range.end.blockId){const a=n.getBlockById(t.range.start.blockId);if(Te(a)&&wk(n,a))return}const o=e,r=n.getBlockById(o.blockId);if(yk(n,o))return;const i=Ke(n,r,o),s=r.getBoundingClientRect(),l=Rt(r),c=b("div",["editor-block-anchor"],l);c.style.top=`${i.top-s.top}px`,id(c,{elementToScroll:We(n.rootContainer)}),setTimeout(()=>{c.remove()},200)}function Ik(n,t){if(t.isCollapsed())return!1;const e=Ut(n.rootContainer),o=Qt(n.rootContainer),{start:r,end:i}=t;return r.blockId===q(e)&&r.offset===0&&i.blockId===q(o)&&i.offset===W(n,o)}const Ip=B("range-in-block");function xp(n,t){const e=t.getEditor(),o=e.getBlockById(t.start.blockId),r=e.getBlockById(t.end.blockId),i=o===n||It(n,o),s=r===n||It(n,r);return!!(i||s)}function Tp(n,t){const e=n.doc.toJSON(),o=new Set(Object.values(e.blocks).map(s=>s.map(l=>l.id)).flat());let r,i=gt(t);if(i){for(;i&&!o.has(q(i));)i=gt(i);d(Ip,i,"no prev block while deleting a block"),r=At(n,i,W(n,i))}else{const s=dt(t);d(Ip,s,"no prev and next block while deleting a block"),r=At(n,s,0)}return r}const xk=B("block-to-html");function su(n,t,e,o){const r=Ir(n,t.type);if(r.convertTo)return r.convertTo(n,t,e,"html",o);if(r.blockKind!=="text")return`[${t.type}]`;d(xk,t.text,"no text");const i=bt(t.text);return`<div>${dm(i)}</div>`}const Sp=B("block-to-text");function Tk(n,t,e){let o="";return t.forEach(r=>{if(d(Sp,typeof r.insert=="string","invalid op"),r.attributes&&r.attributes.box===!0){const i=r.attributes,s=n.editorBoxes.getBoxClass(i.type);if(s!=null&&s.convertTo){o+=s.convertTo(n,i,e,"text");return}if(r.attributes.text){o+=r.attributes.text;return}o+=`[${i.type}]`}o+=r.insert}),o}function Kl(n,t,e,o){const r=Ir(n,t.type);return r.convertTo?r.convertTo(n,t,e,"text",o):r.blockKind!=="text"?`[${t.type}]`:(d(Sp,t.text,"no text"),Tk(n,t.text,e))}function lu(n,t,e,o){const r=Ir(n,t.type);return r.convertTo?r.convertTo(n,t,e,"markdown",o):Kl(n,t,e,o)}function Dr(n,t){return t.blocks.root.map((r,i)=>su(n,r,t,[{containerId:"root",blockIndex:i}])).join(`
25
25
  `)}function Dp(n,t){return`<!doctype html><html><head><meta charset="utf8" /></head><body>${Dr(n,t)}</body></html>`}function Jl(n,t){return t.blocks.root.map((r,i)=>Kl(n,r,t,[{containerId:"root",blockIndex:i}])).join(`
26
26
  `)}function Lr(n,t){return t.blocks.root.map((r,i)=>lu(n,r,t,[{containerId:"root",blockIndex:i}])).join(`
27
- `)}const Sk=B("get-text-position");function Mr(n,t){const e=t!=null?t:n.selection.range.start;e instanceof Vt||d(Sk,!1,`invalid insert pos type: ${typeof e}`);const{blockId:o}=e,r=n.getBlockById(o),i=J(r),s=H(r),l=U(s),{offset:c}=e;return{block:r,container:s,containerId:l,blockIndex:i,offset:c}}const Gi=B("insert-text");function Lp(n,t,e,o){var s;const r=n.doc.getBlockData(t,e);if(d(Gi,r,"no block data"),d(Gi,r.text,"no block text"),ue(r.text)===0)return d(Gi,o===0,"invalid text offset"),n.editorCommandProviders.getEmptyBlockTextAttributes(n,r.id);if(o===0)return;const i=Wt(r.text,o-1,1).middle;if(!((s=i[0].attributes)!=null&&s.box))return i[0].attributes}function Dk(n,t,e){const o=H(t),r=U(o),i=J(t);return Lp(n,r,i,e)}function Mp(n,t,e,o,r){const i=H(t),s=U(i),l=J(t),c=Dk(n,t,e),a=Hl(e,o,c!=null?c:null);return n.doc.localUpdateBlockText(s,l,a,r),he(n,t)}function Rp(n,t,e,o){const r=H(t),i=U(r),s=J(t),l=Hl(e," ",o);return n.doc.localUpdateBlockText(i,s,l),he(n,t)}function cu(n,t,e,o,r){const i=n.doc.getBlockData(e,o);d(Gi,i,"no block data"),d(Gi,i.text,"no block text");const s=Lp(n,e,o,r),l=Hl(r,t,s!=null?s:null);return n.doc.localUpdateBlockText(e,o,l),he(n,n.getBlockById(i.id))}function au(n,t){n.selection.range.isCollapsed()||n.clearSelectedContents();const{containerId:e,blockIndex:o,offset:r}=Mr(n);cu(n,t,e,o,r)}const Xl=B("update-composition-text");function Ap(n){const t=n.selection.range.start;t instanceof Vt||d(Xl,!1,`invalid insert pos type: ${typeof t}`);const{blockId:e}=t,o=n.getBlockById(e);d(Xl,P(n,o),"not a text kind block");const r=H(o),i=U(r),s=J(o),l=n.doc.getBlockData(i,s);d(Xl,l,"no block data in doc"),d(Xl,l.text,"no text data in text block");const c=it(o);Nl(n,Vo(o),e,c,l.text)}function Op(n){db(n)}function Rr(n,t,e,o,r,i){return n.doc.localInsertBlock(t,e,o,r,i),n.getBlockById(o.id)}const tc=B("delete-block-text");function du(n,t,e,o,r){d(tc,P(n,t),"block is not a text kind block");const i=H(t),s=U(i),l=J(t),c=n.doc.getBlockData(s,l);d(tc,c,"no block data in doc"),d(tc,c.text,"no text data in text block");let a=e;re(t,e)||(a=uo(t,a));let u=e+o;d(tc,u<=W(n,t),`invalid offset and count: ${e}, ${o}`),re(t,u)||(u=Go(t,u));const f=u-a,m=qg(a,f);return n.doc.localUpdateBlockText(s,l,m,r),f}const uu=B("break-text-block");function _p(n,t){const o=n.getBlockData(t).quoted;return o?{quoted:o}:{}}function Ar(n,t,e,o){d(uu,P(n,t),`block is not a text kind block: ${ot(t)}`),d(uu,e>=0&&e<=W(n,t),`invalid offset: ${e}`);const r=H(t),i=U(r),s=J(t),l=o!=null&&o.copyBlockAttributes?_p(n,t):{};if(!(o!=null&&o.forceInsertAfter)&&(e===0||e===W(n,t))){const C=e===0?s:s+1,k={...Un(""),...l,...o==null?void 0:o.newBlockData},w=At(n,t.id,0),y=Rr(n,i,C,k,w);return{block:t,newBlock:y}}d(uu,re(t,e),"not a valid offset");const c=he(n,t),{right:a}=be(c,e),u=ue(a);u>0&&du(n,t,e,u);const f={...Un(a),...l,...o==null?void 0:o.newBlockData},m=Rr(n,i,s+1,f,At(n,f.id,0));return{block:t,newBlock:m}}const Lk=B("prepare-insert-new-block");function Mk(n,t,e){if(t&&e!==void 0&&e!==null){const a=n.getContainerById(t),u=Mt(a);return d(Lk,e>=0&&e<=u.length,`invalid blockIndex: ${e}`),{containerId:t,blockIndex:e}}const o=n.selection.range.start;if(!o.isSimple())return null;const r=n.getBlockById(o.blockId);if(t=U(H(r)),e=J(r),!P(n,r))return{containerId:t,blockIndex:e+1};const s=o.offset;if(s===0||s===W(n,r))return{containerId:t,blockIndex:s===0?e:e+1};const c=Ar(n,r,s).newBlock;return{containerId:t,blockIndex:J(c)}}const Rk=B("auto-insert-block");function Np(n,t,e,o,r,i){const s=Mk(n,e,o);d(Rk,s,`not an valid insert position: ${n.selection.range}`);const l={blockId:t.id,offset:0},c={anchor:l,focus:l};return Rr(n,s.containerId,s.blockIndex,t,r!=null?r:c,i)}const Ak=B("delete-block");function ec(n,t,e){t.children&&(e.push(...t.children),t.children.forEach(o=>{n.getChildContainerData(o).forEach(i=>{ec(n,i,e)})}))}function hu(n,t,e){const o=H(t),r=U(o),i=J(t),s=n.doc.getBlockData(r,i);return d(Ak,s,"no block data in doc"),n.doc.localDeleteBlock(r,i,qt(n,{anchor:e.start,focus:e.end})),s}function fu(n,t,e){return n.undoManager.runInGroup(()=>{const o=H(t);Ge(o)===1&&n.insertTextBlock("",U(o),0);let r=e?lo(n,e):null;if(!r){const l=n.selection.range;xp(t,l)?r=Tp(n,t):r=l}const i=hu(n,t,r),s=[];return ec(n,i,s),s.length>0&&n.doc.localDeleteChildContainers(s),i})}function Ok(n,t){const e=[t];n.doc.getContainerBlocks(t).forEach(r=>{ec(n,r,e)}),n.doc.localDeleteChildContainers(e)}function $p(n,t){const e=[...t];t.forEach(o=>{n.doc.getContainerBlocks(o).forEach(i=>{ec(n,i,e)})}),n.doc.localDeleteChildContainers(e)}const mu=B("merge-text-block");function Pp(n,t,e){d(mu,P(n,t),"only text block can be merged"),d(mu,P(n,e),"only text block can be merged");const o=fo(n,t),r=fo(n,e),i=o.text,s=r.text;d(mu,i&&s,"block data has no text");const l=H(t),c=U(l),a=J(t),u=W(n,t),f=cu(n,s,c,a,u),m=At(n,t,ue(i));return fu(n,e,m),f}const wn=B("clear-selected-contents");function nc(n,t){d(wn,P(n,t.block),"not a text kind block");const{start:e,end:o}=t;d(wn,e.isSimple(),"not a simple block position"),d(wn,o.isSimple(),"not a simple block position");const r=e.offset,i=o.offset;d(wn,r<=i,`invalid delete text offset: ${r}, ${i}`),r!==i&&n.deleteTextFromBlock(t.block,r,i-r)}function jp(n,t,e){const o=U(t),r=Mt(t),i=e.focus?void 0:n.selection.range.toDocRange(),s=n.insertTextBlock("",o,0,{newRange:i});e.focus&&n.selection.selectBlock(s,0),r.reverse().forEach(l=>{n.deleteBlock(l)})}function _k(n,t){const{block:e,start:o,end:r}=t;if(P(n,e)){nc(n,t);return}if(Te(e)||o.isSimple()){d(wn,r.isSimple(),"invalid range");const s=H(e),l=J(e),c=n.insertTextBlock("",U(s),l);n.selection.selectBlock(c,0),n.deleteBlock(e);return}d(wn,at(n,e),"invalid block kind"),d(wn,!o.isSimple()&&!r.isSimple(),"invalid range"),xr(n,e,o,r),n.selection.range.getSelectedContainers().forEach((s,l)=>{jp(n,s,{focus:l===0})})}function Nk(n){const t=n.selection.range;if(t.isCollapsed())return;const e=t.getSelectedBlocks();if(d(wn,e.length>0,"no selected block"),e.length===1){_k(n,e[0]);return}const o=e[0],r=o.block,i=H(r);d(wn,e.length>1,"no selected block");const s=e[e.length-1],l=s.block;if(P(n,r)){nc(n,o);const u=At(n,o.block,o.start.offset);if(e.slice(1,e.length-1).reverse().forEach(m=>n.deleteBlock(m.block)),P(n,l)){nc(n,s),n.mergeTextBlock(r,l,{focus:!0}),n.selection.setRange(u);return}n.deleteBlock(l),n.selection.setRange(u);return}if(P(n,l)){nc(n,s),e.slice(0,e.length-1).reverse().forEach(u=>n.deleteBlock(u.block)),n.selection.selectBlock(s.block,0);return}if(e.length===Ge(i)){jp(n,i,{focus:!0});return}const c=gt(r),a=dt(l);d(wn,c||a,"no prev or next block"),e.forEach(u=>n.deleteBlock(u.block))}function gu(n){n.selection.range.isCollapsed()||n.undoManager.runInGroup(()=>{n.emit("beforeClearSelection",n);try{n.doc.beginBatchUpdate(),Nk(n)}finally{n.doc.endBatchUpdate()}n.emit("afterClearSelection",n)})}function Hp(n,t,e){const o=H(t),r=U(o),i=J(t);return n.doc.localUpdateBlockText(r,i,e),setTimeout(()=>{n.selection.updateSelection(null)}),he(n,t)}function Fp(n,t,e){const o=n.getBlockText(t),r=ie.diff(o,e);Hp(n,t,r)}function oc(n,t,e){const o=he(n,t),r=typeof e=="string"?Qo(e):e,i=ie.diff(o,r);return Hp(n,t,i)}const Zi=B("update-block-data");function rc(n,t,e,o){const r=H(t),i=U(r),s=J(t),l=n.doc.getBlockData(i,s),c={insert:{},delete:[]},a=new Set(Object.keys(l)),u=new Set(Object.keys(e));return a.forEach(m=>{if(!u.has(m)){if(m==="id"||m==="type"||m==="text")return;Zi.debug(`delete key: ${m}`),c.delete.push(m)}}),Object.entries(e).forEach(([m,C])=>{d(Zi,m!=="id"&&m!=="type",`invalid block data delta, ${m}`);const k=l[m];if(C==null){k!=null&&(Zi.debug(`delete key: ${m}`),c.delete.push(m));return}k!==C&&(ml.default(k,C)||m==="text"&&ie.diff(k,C).length===0||(a.has(m)?(Zi.debug(`replace key: ${m}`),c.delete.push(m)):Zi.debug(`insert key: ${m}`),c.insert[m]=C))}),n.doc.localUpdateBlockData(i,s,c,o),fo(n,t)}function zp(n,t,e,o){const i={...n.getBlockData(t),embedData:e};return n.updateBlockData(t,i,o)}function pu(n,t,e){if(!at(n,t)||!(e!=null&&e.tryFocusToChildSimpleBlock)){n.selection.selectBlock(t,0);return}const r=xe(n,t).getChildContainers(n,t)[0],i=Ut(r);pu(n,i,e)}function Jo(n){const t=[];let e={};return n.forEach(o=>{t.push(...o.blocks.root);const{root:r,...i}=o.blocks;e={...e,...i}}),{blocks:{...e,root:t},meta:{},comments:{}}}const Yi=B("clone-block");function mo(n,t,e,o){const r=n.getBlockClass(e.type);if(r.blockToDoc)return r.blockToDoc(t,e,(u,f)=>(d(Yi,e!==f,"invalid child block"),mo(n,u,e,o)));let i={};const s=new Map,l=Y.default(e);l.children&&(l.children=l.children.map(u=>{const f=N(),m=t.blocks[u];d(Yi,Array.isArray(m),"invalid child blocks");const C=m.map(S=>mo(n,t,S,o)),k=Jo(C),{root:w,...y}=k.blocks;return i={...i,...y},i[f]=k.blocks.root,s.set(u,f),f}));const c=Array.from(s.entries()),a=u=>{for(const f of c){const[m,C]=f;{const k=`${m}/`;if(u.startsWith(k)){const w=u.substring(k.length),y=`${C}/${w}`;return Yi.debug(`replace key: ${u} -> ${y}`),y}}{const k=`${m}_`;if(u.startsWith(k)){const w=u.substring(k.length),y=`${C}_${w}`;return Yi.debug(`replace key: ${u} -> ${y}`),y}}}return u};return Array.from(Object.entries(l)).forEach(([u,f])=>{const m=a(u);m!==u&&delete l.key,l[m]=f}),l.id=N(),o&&(o.blockIdMap.set(e.id,l.id),s.forEach((u,f)=>o.containerIdMap.set(f,u))),{blocks:{root:[l],...i},meta:{},comments:{}}}function Cu(n,t,e,o){const r=t.blocks[e];d(Yi,Array.isArray(r),"invalid child blocks");const i=r.map(l=>mo(n,t,l,o));return Jo(i)}function bu(n,t,e){const o=t.blocks.root.map(r=>mo(n.editorBlocks,t,r,e));return Y.default(Jo(o))}const Up=B("insert-doc");function Vp(n,t,e,o,r){if(at(n,t)){Up.warn("failed to insert doc into a complex block");return}const i=bu(n,o,r),s=H(t),l=J(t),c=U(s);n.doc.beginBatchUpdate(),n.undoManager.runInGroup(()=>{var I,M,R;Object.entries(i.blocks).forEach(([$,Z])=>{$!=="root"&&n.doc.localInsertChildContainer($,Z)});const a=i.blocks.root;if(Te(t)){n.deleteBlock(t);let $;a.reverse().forEach(Z=>{const rt=n.insertBlock(c,l,Z);$||($=rt)}),$&&n.selection.selectBlock($,W(n,$));return}if(d(Up,P(n,t),"not a text block"),Tt(n,t)){const $=J(t);let Z;a.forEach((rt,st)=>{const mt=n.insertBlock(c,$+st,rt);st===a.length-1&&(Z=mt)}),Z&&n.selection.selectBlock(Z,W(n,Z));return}if(a.length===1){const $=a[0];if($i(n,$.type)){n.insertTextToBlock(t,e,(I=$.text)!=null?I:[]);return}n.breakTextBlock(t,e),n.insertBlock(c,l+1,$);return}const u=e===W(n,t),f=e===0,m=a[0],C=a[a.length-1];let k;!u&&!f?k=n.breakTextBlock(t,e,{forceInsertAfter:!0}):k=t;const w=f?l:l+1;u?(k=n.insertBlock(c,l+1,C),n.selection.selectBlock(k,W(n,k))):(n.selection.selectBlock(k,0),$i(n,C.type)?n.insertTextToBlock(k,0,(M=C.text)!=null?M:[]):n.insertBlock(c,w,C));const y=n.selection.range;let S=w;$i(n,m.type)?f?(n.insertBlock(c,w,m),S+=1):n.insertTextToBlock(t,e,(R=m.text)!=null?R:[]):(n.insertBlock(c,w,m),S+=1),a.slice(1,a.length-1).reverse().forEach($=>{n.insertBlock(c,S,$)}),n.selection.setRange(y)}),n.doc.endBatchUpdate()}function ku(n,t,e,o,r){const i=bu(n,o,r),s=U(t),l=[];return n.undoManager.runInGroup(()=>{Object.entries(i.blocks).forEach(([a,u])=>{a!=="root"&&n.doc.localInsertChildContainer(a,u)}),i.blocks.root.reverse().forEach(a=>{const u=n.insertBlock(s,e,a);l.push(u)})}),l}function qp(n,t,e){const o=Ge(t);ku(n,t,o,e);for(let r=0;r<o;r++){const i=Ut(t);n.deleteBlock(i)}}const Qi=B("add-text-attribute");function $k(n,t,e,o){const{start:r,end:i}=e;d(Qi,r.blockId===i.blockId&&r.blockId===q(t),"invalid range"),d(Qi,o,"invalid attribute name");const s=n.getBlockText(t),l=Sr(r.offset,i.offset-r.offset,s,o,void 0,{ignoreValue:!0});return n.setBlockText(t,l),l}function Wp(n,t,e,o,r){const{start:i,end:s}=e;d(Qi,i.blockId===s.blockId&&i.blockId===q(t),"invalid range"),d(Qi,o,"invalid attribute name");const l=n.getBlockText(t),c=Vi(i.offset,s.offset-i.offset,l,o,r);return n.setBlockText(t,c),c}function Or(n,t,e,o,r){const{start:i,end:s}=e;d(Qi,i.blockId===s.blockId&&i.blockId===q(t),"invalid range");const l=n.getBlockText(t),c=tp(i.offset,s.offset-i.offset,l,o,r);return n.setBlockText(t,c),c}function Gp(n,t,e,o){const r=tn(n,{simpleBlockOnly:!0});n.undoManager.runInGroup(()=>{r.forEach(i=>{const{block:s,start:l,end:c}=i;if(!P(n,s))return;if(Tt(n,s)){o(n,q(s),t,e);return}const a=qt(n,{anchor:l,focus:c});t==="color"||t==="backgroundColor"?Or(n,s,a,t,e):(Or(n,s,a,"color",null),Or(n,s,a,"backgroundColor",null))})})}function Zp(n,t,e){const o=tn(n,{simpleBlockOnly:!0});n.undoManager.runInGroup(()=>{o.forEach(r=>{const{block:i,start:s,end:l}=r;if(!P(n,i))return;if(Tt(n,i)){(t==="clearColor"||t==="clearAll")&&e(n,q(i),"color",null),(t==="clearBackground"||t==="clearAll")&&e(n,q(i),"backgroundColor",null);return}const c=qt(n,{anchor:s,focus:l});(t==="clearColor"||t==="clearAll")&&Or(n,i,c,"color",null),(t==="clearBackground"||t==="clearAll")&&Or(n,i,c,"backgroundColor",null)})})}function vu(n,t){const e=tn(n,{simpleBlockOnly:!0}).filter(s=>P(n,s.block));if(e.length===0)return[null,null];const o=s=>{if(W(n,s.block)===0)return t(n,q(s.block));const l=s.start,c=s.end,a=n.getBlockText(s.block);return op(l.offset,c.offset-l.offset,a)};let[r,i]=o(e[0]);return r===null&&i===null?[r,i]:(e.forEach(s=>{const[l,c]=o(s);l===null||r===null?r=null:r=l===r?r:null,c===null||i===null?i=null:i=c===i?i:null}),[r,i])}const ve=B("adjust-selection-pos");function Yp(n){const t=[];for(;n;){const e=H(n);if(t.unshift(e),pt(e))return t;const o=F(e);d(ve,o,"child container has not parent container"),n=o}d(ve,!1,"should not come here: getParentContainers")}function Qp(n,t){for(;t;){const e=H(t);if(e===n)return t;const o=F(e);d(ve,o,"could not find parent block for a child container"),t=o}d(ve,!1,"no parent block in specified container")}function Pk(n,t){const e=Yp(n),o=Yp(t);d(ve,e.length>0&&o.length>0,"block has not parent container"),d(ve,e[0]===o[0],"root container does not equal");let r=e[0];for(let l=1;l<e.length||o.length;l++)if(e[l]!==o[l]){r=e[l-1];break}const i=Qp(r,n),s=Qp(r,t);return{parentContainer:r,newBlock1:i,newBlock2:s}}function Kp(n,t){let e=F(t);for(d(ve,e,"element is not in a block");e;){const o=H(e);d(ve,Ye(o),"not a child container");const r=F(o);if(d(ve,r,"child container has not parent block"),r===n)return o;e=r}d(ve,!1,"failed to find parent container in complex block")}function ic(n,t,e){const o=n.getBlockById(t.blockId),r=n.getBlockById(e.blockId);if(o===r)return t instanceof Vt&&e instanceof Vt?{anchor:t,focus:e}:(d(ve,t instanceof Je&&e instanceof Je,"both start and end are not simple or complex"),Al(n,o,t,e));const i=H(o),s=H(r);if(i===s)return t instanceof Je&&(t=j(o,0,"home")),e instanceof Je&&(e=j(r,W(n,r),"end")),d(ve,t instanceof Vt,"not valid position type"),d(ve,e instanceof Vt,"not valid position type"),{anchor:t,focus:e};if(o.contains(s))return null;if(r.contains(i)){if(t instanceof Vt&&e instanceof Je){const k=n.getContainerById(e.childContainerId);if(k===i)return{anchor:e,focus:e};const w=F(i);if(w&&w===F(k)){const y=wt(w,U(i)),S=wt(w,U(k));return Al(n,w,y,S)}}return null}const l=kl(o,r)>0,{newBlock1:c,newBlock2:a}=Pk(o,r);if(c===a){const k=c,w=Kp(k,o),y=Kp(k,r);return t=wt(c,U(w)),e=wt(c,U(y)),ve.debug(`select in complex block: ${w.id}, ${y.id}`),Al(n,k,t,e)}let u=l?W(n,c):0;c===o&&t instanceof Vt&&(u=t.offset);let m=l?0:W(n,a);return a===r&&e instanceof Vt&&(m=e.offset),t=j(c,u,l?"end":"home"),e=j(a,m,l?"home":"end"),{anchor:t,focus:e}}const jk=B("move-complex-block-position");function Hk(n,t,e){const o=n.getBlockById(t.blockId);d(jk,at(n,o),"is not a complex block");const r=xe(n,o),i=n.getContainerById(t.childContainerId),s=r.getNextContainer(n,o,i,e,{noWrap:!0});return s?wt(o,U(s)):null}const Ki=B("move-simple-block-position");function Jp(n,t){const e=Se(n,t);d(Ki,e.length>0,"complex block has not any child container");const o=e[0];return Ut(o)}function Xp(n,t){const e=Se(n,t);d(Ki,e.length>0,"complex block has not any child container");const o=e[e.length-1];return Qt(o)}function t0(n,t,e){const o=e?Jp(n,t):Xp(n,t);return at(n,o)?t0(n,o,e):o}function Fk(n,t){const e=n.getBlockById(t.blockId);return at(n,e)&&t.offset===0?Jp(n,e):Br(e)}function zk(n,t){const e=n.getBlockById(t.blockId);return at(n,e)&&t.offset===1?Xp(n,e):wr(e)}function yu(n){return n==="ArrowLeft"||n==="ArrowUp"}function wu(n,t,e){const o=H(t);if(pt(o))return null;const r=F(o);d(Ki,r,"child container has not parent block"),d(Ki,at(n,r),"is not a complex block");const i=xe(n,r).getNextContainer(n,r,o,e);return i?yu(e)?Qt(i):Ut(i):wu(n,r,e)}function Uk(n,t,e){const o=H(t);if(pt(o))return null;const r=F(o);if(d(Ki,r,"child container has not parent block"),yu(e)){const l=gt(r);if(l)return l}else{const l=dt(r);if(l)return l}const i=wu(n,r,e);if(i)return i;let s=r;for(;!pt(H(s));)s=F(H(s));return yu(e)?gt(s):dt(s)}function Vk(n,t,e){return!at(n,t)||xe(n,t).enableKeyboardSelect?t:t0(n,t,e==="ArrowDown"||e==="ArrowRight")}function qk(n,t,e){const o=n.getBlockById(t.blockId),i=kt(n,o).moveCaret(n,o,t,e);if(i)return i;let s=e==="ArrowDown"||e==="ArrowRight"?Fk(n,t):zk(n,t);if(s||(s=wu(n,o,e),s||(s=Uk(n,o,e))),!s){if(e==="ArrowDown"||e==="ArrowRight"){if(n.readonly||!pt(H(o)))return null;const l=n.insertTextBlock("",U(n.rootContainer),Ge(n.rootContainer));return j(l,0,"home")}return null}if(s=Vk(n,s,e),P(n,s)){const l=n.selection.getSuggestedCaretX();if(e==="ArrowDown")return wb(n,s,o,t,l);if(e==="ArrowUp")return yb(n,s,o,t,l)}return e==="ArrowLeft"||e==="ArrowUp"?j(s,W(n,s),"end"):e==="ArrowRight"||e==="ArrowDown"?j(s,0,"home"):null}function Wk(n,t,e){if(t==="ArrowLeft")return e.start;const o=e.end,r=n.getBlockById(o.blockId);if(P(n,r))return o;const i=dt(r);if(i)return j(i,0,"home");if(!pt(H(r))||n.readonly)return o;const s=n.insertTextBlock("",U(n.rootContainer),Ge(n.rootContainer));return j(s,0,"home")}function Gk(n,t,e){const o=n.selection.range;let r;if(o instanceof ae)e==="move"&&!o.isCollapsed()&&(t==="ArrowLeft"||t==="ArrowRight")?r=Wk(n,t,o):r=qk(n,o.getFocusedPos(),t);else if(r=Hk(n,o.focus,t),e==="move"){const i=r!=null?r:o.focus,s=n.getContainerById(i.childContainerId);if(t==="ArrowLeft"||t==="ArrowUp"){const l=Qt(s);r=j(l,0,"home")}else{const l=Ut(s);r=j(l,W(n,l),"end")}}return r?e==="move"?{anchor:r,focus:r}:ic(n,o.anchor,r):null}function go(n,t,e){const o=Gk(n,t,e);if(!o)return!1;const{anchor:r,focus:i}=o;return n.selection.setSelection(r,i),(t==="ArrowLeft"||t==="ArrowRight")&&n.selection.updateLastCaretRect(),!0}function e0(n){return go(n,"ArrowLeft","move"),!0}function n0(n){return go(n,"ArrowRight","move"),!0}function o0(n){return go(n,"ArrowUp","move"),!0}function r0(n){if(go(n,"ArrowDown","move")||n.readonly)return!0;const t=n.getFocusedBlock(),e=H(t);if(pt(e)||Qt(e)!==t)return!0;const o=n.rootContainer;return n.insertTextBlock("",U(o),Ge(o)),!0}function i0(n){return go(n,"ArrowDown","select"),!0}function s0(n){return go(n,"ArrowLeft","select"),!0}function l0(n){return go(n,"ArrowRight","select"),!0}function c0(n){return go(n,"ArrowUp","select"),!0}const a0=B("word-offset");function Bu(n,t){const e=n.selection.range.focus;d(a0,e.isSimple(),"invalid range type");const o=n.getBlockById(e.blockId);if(Tt(n,o))return j(o,0,"home");if(e.offset===0||!P(n,o)){const s=gt(o);if(!s)return null;const l=j(s,W(n,s),"end");if(t==="select"&&P(n,s)){const c=tu(n,s,l.offset);return j(s,c,"normal")}return l}const r=tu(n,o,e.offset);return j(o,r,"normal")}function Eu(n,t){const e=n.selection.range.focus;d(a0,e.isSimple(),"invalid range type");const o=n.getBlockById(e.blockId);if(Tt(n,o))return j(o,0,"end");if(e.offset===W(n,o)||!P(n,o)){const s=dt(o);if(!s)return null;const l=j(s,0,"home");if(t==="select"&&P(n,s)){const c=eu(n,s,l.offset);return j(s,c,"end")}return l}const r=eu(n,o,e.offset);return j(o,r,"normal")}function d0(n){if(!n.selection.range.focus.isSimple())return!1;const e=Bu(n,"move");return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function u0(n){if(!n.selection.range.focus.isSimple())return!1;const e=Eu(n,"move");return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function h0(n){if(!n.selection.range.focus.isSimple())return!1;const e=Bu(n,"select");return e?(n.selection.setSelection(n.selection.getAnchorPos(),e),n.selection.updateLastCaretRect(),!0):!1}function f0(n){if(!n.selection.range.focus.isSimple())return!1;const e=Eu(n,"select");return e?(n.selection.setSelection(n.selection.range.anchor,e),n.selection.updateLastCaretRect(),!0):!1}B("find-block");function Iu(n,t){if(!at(n,t))return t;const o=xe(n,t).getChildContainers(n,t)[0],i=Mt(o)[0];return Iu(n,i)}function xu(n,t){if(!at(n,t))return t;const e=xe(n,t).getChildContainers(n,t),o=e[e.length-1],r=Mt(o),i=r[r.length-1];return xu(n,i)}function m0(n){const t=xu(n,Qt(n.rootContainer)),e=j(t,W(n,t),"end");return n.selection.setSelection(e),!0}function g0(n){const t=Iu(n,n.getFirstBlock()),e=j(t,0,"home");return n.selection.setSelection(e),!0}function p0(n){const t=Iu(n,n.getFirstBlock()),e=j(t,0,"home");return n.selection.setSelection(n.selection.getAnchorPos(),e),!0}function Tu(n){const t=xu(n,Qt(n.rootContainer)),e=j(t,W(n,t),"end");return n.selection.setSelection(n.selection.getAnchorPos(),e),!0}const C0=B("line-offset");function b0(n){const t=n.selection.range.focus;d(C0,t.isSimple(),"invalid range type");const e=n.getBlockById(t.blockId);if(t.offset===0||!P(n,e))return j(e,0,"home");let r=Hg(e,t).start;const{next:i}=_l(e,r);return i&&_e(i)&&_i(i)==="br"&&(r+=1),j(e,r,"home")}function k0(n){const t=n.selection.range.focus;d(C0,t.isSimple(),"invalid range type");const e=n.getBlockById(t.blockId);if(t.offset===W(n,e)||!P(n,e))return j(e,W(n,e),"end");const o=Hg(e,t);return j(e,o.end,"end")}function v0(n){if(!n.selection.range.focus.isSimple())return!1;const e=b0(n);return e?(n.selection.setSelection(n.selection.getAnchorPos(),e),n.selection.updateLastCaretRect(),!0):!1}function y0(n){if(!n.selection.range.focus.isSimple())return!1;const e=k0(n);return e?(n.selection.setSelection(n.selection.getAnchorPos(),e),n.selection.updateLastCaretRect(),!0):!1}function w0(n){if(!n.selection.range.focus.isSimple())return!1;const e=b0(n);return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function B0(n){if(!n.selection.range.focus.isSimple())return!1;const e=k0(n);return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}const E0=B("find-block-position");function Zk(n,t,e,o){d(E0,at(n,t),"is not a complex block");const r=xe(n,t).getChildContainers(n,t);d(E0,r.length>0,"complex block has not any child container");const i=Ke(n,e,o),s=i.left+i.width/2,l=i.top+i.height/2,c=Dg(n,t,s,l);return Su(n,c,e,o)}function Su(n,t,e,o){if(at(n,t))return Zk(n,t,e,o);const r=q(t);let i=Number.MAX_SAFE_INTEGER;const s=Ke(n,e,o),l=s.left+s.width/2,c=s.top+s.height/2;let a=j(r,0,"home");const u=W(n,t);for(let f=0;f<=u;f++){const m=j(r,f,"normal"),C=Ke(n,t,m),k=Cn(C,l,c);k<i&&(i=k,a=m)}return a}const I0=B("page-offset");function Yk(n,t){const e=Ep(n)*.9,r=t.getBoundingClientRect().bottom-e;if(r<kk(n))return n.getFirstBlock();const i=gt(t);if(!i)return n.getFirstBlock();let s=i;for(;s;){if(s.getBoundingClientRect().y<r)return s;s=gt(s)}return n.getFirstBlock()}function Qk(n,t){const e=Ep(n)*.9,o=t.getBoundingClientRect(),r=vk(n),i=o.top+e;if(i>r)return n.getLastBlock();const s=dt(t);if(!s)return n.getLastBlock();let l=s;for(;l;){if(l.getBoundingClientRect().bottom>i)return l;l=dt(l)}return n.getLastBlock()}function x0(n){const t=n.selection.range.focus;d(I0,t.isSimple(),"invalid range type");const e=n.getBlockById(t.blockId),o=Yk(n,e);let r;return o===n.getFirstBlock()?r=j(o,0,"home"):r=Su(n,o,e,t),r}function T0(n){const t=n.selection.range.focus;d(I0,t.isSimple(),"invalid range type");const e=n.getBlockById(t.blockId),o=Qk(n,e);let r;return o===n.getLastBlock()?r=j(o,W(n,o),"end"):r=Su(n,o,e,t),r}function S0(n){if(!n.selection.range.focus.isSimple())return!1;const e=x0(n);return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function D0(n){if(!n.selection.range.focus.isSimple())return!1;const e=T0(n);return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function L0(n){if(!n.selection.range.focus.isSimple())return!1;const e=x0(n);if(!e)return!1;const o=ic(n,n.selection.getAnchorPos(),e);if(!o)return!1;const{anchor:r,focus:i}=o;return n.selection.setSelection(r,i),n.selection.updateLastCaretRect(),!0}function M0(n){if(!n.selection.range.focus.isSimple())return!1;const e=T0(n);if(!e)return!1;const o=ic(n,n.selection.getAnchorPos(),e);if(!o)return!1;const{anchor:r,focus:i}=o;return n.selection.setSelection(r,i),n.selection.updateLastCaretRect(),!0}const Ji=B("select-all");function R0(n,t){const e=Ut(n),o=Qt(n);return t.start.offset===0&&t.start.blockId===q(e)&&t.end.offset===W(t.getEditor(),o)&&t.end.blockId===q(o)}function Kk(n,t){const e=t.getEditor(),o=xe(e,n).getChildContainers(e,n),r=o[0],i=o[o.length-1],s=q(n);return t.start.blockId===s&&t.start.childContainerId===U(r)&&t.end.blockId===s&&t.end.childContainerId===U(i)}function Jk(n,t){d(Ji,t,"no parent block"),d(Ji,at(n,t),"not a complex block");const e=xe(n,t).getChildContainers(n,t),o=e[0],r=e[e.length-1];n.selection.setRange(qt(n,{anchor:wt(t,U(o)),focus:wt(t,U(r))}))}function A0(n,t){const e=H(t);Du(n,e)}function O0(n){const t=n.getFocusedBlock(),e=n.selection.range;if(e.start.isSimple()){if(e.start.blockId===e.end.blockId&&P(n,t)){const r=e.start,i=e.end,s=W(n,t);if(r.offset>0||i.offset<s)return n.selection.selectBlock(t,0,s),!1}return A(n.rootContainer,"select-all"),A0(n,Ut(n.rootContainer)),!1}return d(Ji,!e.isSimple(),"invalid range type"),Kk(t,e)?(A0(n,t),!1):(d(Ji,t,"no parent block"),d(Ji,at(n,t),"not a complex block"),Jk(n,t),!0)}function Du(n,t){const e=Mt(t),o=e[0],r=e[e.length-1],i=j(o,0,"home"),s=j(r,W(n,r),"end");n.selection.setSelection(i,s,{noScroll:!0})}function _0(n){Tu(n),n.focus()}const Lu=B("selected-block-to-doc");function N0(n,t,e){!t.children||t.children.forEach(o=>{const r=n.getChildContainerData(o);r.forEach(i=>{N0(n,i,e)}),e.blocks[o]=Y.default(r)})}function sc(n,t,e={ignoreLockInfo:!0}){const o=kt(n,t.block);if(o.selectionToDoc)return o.selectionToDoc(n,t);const r=Y.default(fo(n,t.block));if(!e.ignoreLockInfo&&r.lock&&delete r.lock,P(n,t.block)){const s=t.start,l=t.end;if(d(Lu,r.text,"no block text"),s.offset===l.offset)return{blocks:{root:[{...r,text:[]}]},meta:{},comments:{}};const{middle:c}=Wt(r.text,s.offset,l.offset-s.offset);return{blocks:{root:[{...r,text:c}]},meta:{},comments:{}}}if(Te(t.block))return{blocks:{root:[r]},meta:{},comments:{}};d(Lu,at(n,t.block),"not complex block"),d(Lu,r.children,"no children");const i={blocks:{root:[r]},meta:{},comments:{}};return N0(n,r,i),i}function Mu(n,t,e=!0){const o=j(t,0,"normal"),r=j(t,W(n,t),"end");return sc(n,{block:t,start:o,end:r},{ignoreLockInfo:e})}const Xk=B("block-to-doc");function tv(n,t){d(Xk,t.length>0,"invalid params, no blocks");const e=t.map(o=>Mu(n,o));return Jo(e)}function Xi(n){const e=n.selection.range.getSelectedBlocks().map(o=>sc(n,o));return Jo(e)}function $0(n,t){const e=n.getContainerById(t),i=Mt(e).map(s=>({start:j(s,0,"home"),end:j(s,W(n,s),"end"),block:s})).map(s=>sc(n,s));return Jo(i)}const lc=B("editor-selection");class ev{constructor(t){h(this,"editor");h(this,"caret");h(this,"_range");h(this,"lastCaretRect");h(this,"handleBlockDelete",(t,e,o,r)=>{if(o||r.child)return;const i=this.range;if(xp(e,i)){lc.debug("adjust selection because remote deleted current block");const s=Tp(t,e);this.setRange(s,{noScroll:!0})}});this.editor=t;const e=t.getFirstBlock(),o=q(e);this.caret=new Ck(t);const r=j(o,0,"normal");this._range=qt(t,{anchor:r,focus:r}),this.lastCaretRect=null,this.editor.addListener("blockDeleted",this.handleBlockDelete),setTimeout(()=>{this.updateFocusedBlock(null)})}destroy(){this.caret.destroy()}get range(){return this._range}get focusedBlock(){return this.getFocusedBlock()}get startBlock(){return this.getStartBlock()}get endBlock(){return this.getEndBlock()}getFocusedBlock(){const t=this.range.focus;return this.editor.getBlockById(t.blockId)}getStartBlock(){const t=this.range.start;return this.editor.getBlockById(t.blockId)}getEndBlock(){const t=this.range.end;return this.editor.getBlockById(t.blockId)}selectBlock(t,e,o){const r=j(t,e,"normal");let i;o&&(i=j(t,o,"normal")),this.setSelection(r,i)}setSelection(t,e,o){if(e||(e=t),this.verifyPos(t),this.verifyPos(e),!this.selectionChanging(t,e))return this.range;const r=qt(this.editor,{anchor:t,focus:e});if(this.range.isEqual(r))return this.range;const i=this._range;return this._range=r,this.selectionChanged(),this.updateFocusedBlock(i),nt(this.editor.rootContainer,"select-all")&&(!r.isSimple()||!Ik(this.editor,r))&&z(this.editor.rootContainer,"select-all"),o!=null&&o.noScroll||this.scrollIntoView(),this.range}setRange(t,e){return this.setSelection(t.anchor,t.focus,e)}updateSelection(){this.caret.update(),bk(this.editor)}getFocusedPos(){return this.range.focus}getAnchorPos(){return this.range.anchor}selectionChanging(t,e){return!0}selectionChanged(){this.updateSelection(),this.editor.emit("selectionChanged",this.editor)}updateLastCaretRect(){const t=this.range.focus;if(!so(t))return;const e=this.editor.getBlockById(t.blockId);this.lastCaretRect=Ke(this.editor,e,t)}getSuggestedCaretX(){var t;return(t=this.lastCaretRect)==null?void 0:t.x}scrollIntoView(){Ek(this.editor)}verifyPos(t){const e=this.editor.getBlockById(t.blockId);if(t.isSimple())t.offset>=0&&t.offset<=W(this.editor,e)||d(lc,!1,"invalid block position, out of range");else{const o=t.childContainerId;!!this.editor.getContainerById(o)||d(lc,!1,"invalid complex block position, no container found")}}updateFocusedBlock(t){if(t&&this.range.start.blockId===t.start.blockId)return;let e;t&&t.start.blockId===t.end.blockId&&(e=this.editor.findBlockById(t.start.blockId));let o;(this.range.isCollapsed()||!this.range.isSimple()||this.range.start.blockId===this.range.end.blockId)&&(o=this.editor.getBlockById(this.range.start.blockId));let r=!1;e&&nt(e,"focused")&&(z(e,"focused"),r=!0),this.removeAllBlockFocusedClass(),o&&this.setBlockFocused(o)&&(r=!0),r&&this.editor.emit("focusBlockChanged",this.editor,o!=null?o:null,e!=null?e:null)}verify(){this.verifyPos(this._range.start),this.verifyPos(this._range.end)}to(t){const e=Xi(this.editor);return t==="text"?Jl(this.editor,e):t==="markdown"?Lr(this.editor,e):Dp(this.editor,e)}removeAllBlockFocusedClass(){this.editor.rootContainer.querySelectorAll('div[data-type="editor-block"].focused, div[data-type="editor-block"].child-focused').forEach(t=>{z(t,"focused"),z(t,"child-focused")})}setBlockFocused(t){if(nt(t,"focused"))return!1;A(t,"focused");let e=H(t);for(;Ye(e);){const o=F(e);d(lc,o,"parent block not found"),A(o,"child-focused"),e=H(o)}return!0}}function nv(n){const t=n.selection.range.focus;if(!t.isSimple())return;const e=n.findBlockById(t.blockId);!e||n.selection.selectBlock(e,0,W(n,e))}function ov(n){const t=n.selection.range.focus;if(!t.isSimple())return;const e=n.findBlockById(t.blockId);if(!e||!P(n,e))return;let o=Bu(n,"select"),r=Eu(n,"select");if(!o||!r)return;const i=t.blockId;o.blockId!==i&&(o=j(e,0,"home")),r.blockId!==i&&(r=j(e,W(n,e),"end")),n.selection.setSelection(o,r)}class rv{constructor(t){h(this,"editor");h(this,"startPos",null);h(this,"lastCaretRect");h(this,"mouseDownEvent",null);h(this,"handleMouseDown",t=>{this.mouseDownEvent=t;const e=Mg(this.editor,t.x,t.y);if(e){if(e instanceof Xe)return;const o=this.editor.selection.range;if(t.shiftKey&&o.isSimple()){const r=o.anchor;this.editor.selection.setSelection(r,e.focus),this.startPos=e.start}else this.editor.selection.setSelection(e.anchor,e.focus),this.startPos=e.start;this.editor.selection.updateLastCaretRect()}});h(this,"handleMouseMove",t=>{if(!this.startPos||!this.mouseDownEvent||Math.abs(this.mouseDownEvent.x-t.x)<3&&Math.abs(this.mouseDownEvent.y-t.y)<3)return;const e=Ol(this.editor,t.x,t.y);if(!e)return;const o=ic(this.editor,this.startPos,e.end);if(!o)return;const{anchor:r,focus:i}=o;this.editor.selection.setSelection(r,i)});h(this,"handleMouseUp",t=>{this.startPos=null});this.editor=t,this.startPos=null,this.lastCaretRect=new DOMRect}isSelecting(){return this.startPos!==null}stopSelection(){this.startPos=null}handleDblClick(t){ov(this.editor)}handleTripleClick(t){nv(this.editor)}}function iv(n){return n.readonly||!n.isWritable()?!1:(n.undoManager.undo(),!0)}function sv(n){return n.readonly||!n.isWritable()?!1:(n.undoManager.redo(),!0)}const P0=B("delete-text");function j0(n,t,e,o){const r=o!=null?o:n.selection.range.start;r instanceof Vt||d(P0,!1,`invalid insert pos type: ${typeof r}`);const{blockId:i}=r,s=n.getBlockById(i);d(P0,P(n,s),"block is not a text kind block");let{offset:l}=r;if(t==="backward"){if(l-e<0)return 0;if(!re(s,l-e)){const c=uo(s,l);e=l-c}}else if(t==="forward"&&l+e>W(n,s))return 0;return t==="backward"&&(l-=e),n.deleteTextFromBlock(s,l,e)}function H0(n,t){if(n.getBlockData(t).quoted){const e={quoted:null};return n.updateBlockData(t,e),!0}return!1}const lv=B("handle-backspace");function Ru(n,t){if(!Tt(n,t))return;const e=H(t);Ge(e)!==1&&n.deleteBlock(t)}function cv(n,t){if(!n.selection.range.isCollapsed()){n.clearSelectedContents();return}const e=n.selection.range.start,o=n.getBlockById(e.blockId);if(P(n,o))if(e.offset===0){if(H0(n,o))return;const r=gt(o);if(r)if(P(n,r))n.mergeTextBlock(r,o,{focus:!0});else if(at(n,r)){Ru(n,o);const i=Pi(n,r);i?n.selection.selectBlock(i,W(n,i)):n.selection.selectBlock(r,0,W(n,r))}else Ru(n,o),d(lv,Te(r),"prev block is not embed block"),n.selection.selectBlock(r,1);else{const i=H(o);if(Ye(i)){const s=xg(n,i);s&&(Ru(n,o),n.selection.selectBlock(s,W(n,s)))}}}else j0(n,"backward",1,null);else{const r=J(o),i=H(o);n.insertTextBlock("",U(i),r),n.deleteBlock(o)}}function av(n,t){if(!n.selection.range.isCollapsed()){n.clearSelectedContents();return}const e=n.selection.range.start,o=n.getBlockById(e.blockId);if(P(n,o))if(e.offset===W(n,o)){const r=dt(o);r&&(P(n,r)?n.mergeTextBlock(o,r,{focus:!0}):Tt(n,o)?n.deleteBlock(o,At(n,r,0)):n.deleteBlock(r))}else j0(n,"forward",1,null);else{const r=J(o),i=H(o);n.insertTextBlock("",U(i),r),n.deleteBlock(o)}}function dv(n,t){n.selection.range.isCollapsed()||n.clearSelectedContents();const e=n.getFocusedBlock();if(P(n,e)){if(Tt(n,e)&&H0(n,e))return;const o=n.selection.range.start,r=n.breakTextBlock(e,o.offset,{copyBlockAttributes:!0});o.offset!==0?n.selection.selectBlock(r,0):n.selection.scrollIntoView()}else{const o=n.insertTextBlock();n.selection.selectBlock(o,0)}}function uv(n,t){const e=n.selection.range.getSelectedBlocks()[0],{block:o}=e;if(!P(n,o))return!1;const r=e.end;return n.insertBoxToBlock(o,r.offset,{type:"br",id:N(),box:!0,created:Date.now()}),!0}const hv=B("input-handler-actions");function fv(n,t){return n.readonly||!n.isWritable()?!1:n.undoManager.runInGroup(()=>(dv(n),!0))}function mv(n,t){return n.readonly||!n.isWritable()?!1:n.undoManager.runInGroup(()=>(av(n),!0))}function gv(n,t){return n.readonly||!n.isWritable()?!1:n.undoManager.runInGroup(()=>(cv(n),!0))}function pv(n,t){return n.readonly||!n.isWritable()?!1:n.undoManager.runInGroup(()=>(uv(n),!0))}function Cv(n){return n.readonly||!n.isWritable()||!window.isSecureContext?!1:(navigator.clipboard.readText().then(t=>{n.input.handlePasteText(t)}).catch(t=>{hv.error(t)}),!0)}function F0(n,t,e){if(t.type==="embed"){const s=t.embedData.src;s&&typeof s=="string"&&e.add(s);return}const o=t.text;o&&o.forEach(i=>{i.attributes&&i.attributes.src&&typeof i.attributes.src=="string"&&e.add(i.attributes.src)});const r=t.children;r&&r.forEach(i=>{n.blocks[i].forEach(l=>{F0(n,l,e)})})}function bv(n,t){const e=new Set;return t.blocks.root.forEach(r=>{const i=n.editorBlocks.getBlockClass(r.type);i.getResources?i.getResources(r).forEach(s=>{e.add(s)}):F0(t,r,e)}),Array.from(e)}function ts(n,t){return`<!doctype html><html><head><meta charset="utf8" />${`<meta charset="utf-8"><ones-editor-doc data-source="ones-editor-doc::${Ho(JSON.stringify(t))}::ones-editor-doc" />`}</head><body>${n}</body></html>`}function es(n,t){var i,s,l;const e=(l=(s=(i=n.doc).getServerMeta)==null?void 0:s.call(i))!=null?l:{},o=bv(n,t),r={};o.forEach(c=>{const a=n.doc.buildResourceUrl(c,{withToken:!0});r[c]=a}),t.meta={...e,resources:r}}function kv(n,t,e){if(t.preventDefault(),t.stopPropagation(),!t.clipboardData)return;let o=Xi(n);const r=e==null?void 0:e(n,t,o);if(r===!0)return;typeof r=="object"&&r!==null&&(o=r),es(n,o);const i=Dr(n,o),s=Lr(n,o),l=ts(i,o);t.clipboardData.setData("text/html",l),t.clipboardData.setData("text/plain",s),t.clipboardData.setData("text/x-ones-editor-doc",JSON.stringify(o))}function vv(n){if(n.selection.range.isCollapsed())return;const t=Xi(n);es(n,t);const e=Dr(n,t),o=ts(e,t),r=Lr(n,t),i=new Blob([o],{type:"text/html"});Il([{type:"text/plain",data:new Blob([r],{type:"text/plain"})},{type:"text/html",data:i}])}async function cc(n,t){const e=Mu(n,t,!1);es(n,e);const o=Dr(n,e),r=Lr(n,e),i=ts(o,e);return Il([{type:"text/plain",data:new Blob([r],{type:"text/plain"})},{type:"text/html",data:new Blob([i],{type:"text/html"})}])}function yv(n){return vv(n),gu(n),!0}const ac={ArrowDown:r0,ArrowUp:o0,ArrowLeft:e0,ArrowRight:n0,"Shift+ArrowDown":i0,"Shift+ArrowUp":c0,"Shift+ArrowLeft":s0,"Shift+ArrowRight":l0,"CtrlOrCmd+ArrowLeft":d0,"CtrlOrCmd+ArrowRight":u0,"CtrlOrCmd+Shift+ArrowLeft":h0,"CtrlOrCmd+Shift+ArrowRight":f0,"CtrlOrCmd+ArrowUp":g0,"CtrlOrCmd+ArrowDown":m0,"CtrlOrCmd+Shift+ArrowUp":p0,"CtrlOrCmd+Shift+ArrowDown":Tu,"CtrlOrCmd+A":O0,Home:w0,End:B0,"Shift+Home":v0,"Shift+End":y0,PageUp:S0,PageDown:D0,"Shift+PageUp":L0,"Shift+PageDown":M0,"CtrlOrCmd+X":yv,"CtrlOrCmd+Z":iv,"CtrlOrCmd+Shift+Z":sv,Enter:fv,Delete:mv,Backspace:gv,"Shift+Enter":pv,"CtrlOrCmd+Shift+V":Cv};function z0(n,t){return n.shortcuts.handleKeyboardEvents(n,t)!==void 0}function U0(n,t,e){if(t.type==="embed"){const i=t.embedData,s=i.src;if(s&&typeof s=="string"){const l=e.get(s);l&&(i.src=l)}return}const o=t.text;o&&o.forEach(i=>{if(i.attributes&&i.attributes.src&&typeof i.attributes.src=="string"){const s=e.get(i.attributes.src);s&&(i.attributes.src=s)}});const r=t.children;r&&r.forEach(i=>{n.blocks[i].forEach(l=>{U0(n,l,e)})})}function V0(n,t,e){if(e.size===0)return;t.blocks.root.forEach(r=>{const i=n.editorBlocks.getBlockClass(r.type);i.replaceResources?i.replaceResources(r,e):U0(t,r,e)})}async function wv(n,t){const e=t.filter(i=>i.indexOf(":")===-1),o=await n.doc.addResources(e),r=new Map;if(e.length!==o.length)return r;for(let i=0;i<e.length;i++)r.set(e[i],o[i]);return r}function Bv(n,t){var i,s;const o=t.meta.serverId;if(!o||typeof o!="string")return!1;const r=(s=(i=n.doc).getServerMeta)==null?void 0:s.call(i);return!(!r||r.serverId!==o)}async function Ev(n,t){const o=t.meta.resources;if(!o||Object.keys(o).length===0)return;let r=new Map;if(Bv(n,t)){const s=Array.from(Object.keys(o));r=await wv(n,s),V0(n,t,r)}const i=new Map;Object.entries(o).forEach(([s,l])=>{r.get(s)===void 0&&s!==l&&i.set(s,l)}),i.size!==0&&V0(n,t,i)}async function Iv(n,t){await Ev(n,t),n.undoManager.runInGroup(()=>{n.clearSelectedContents();const{block:e,offset:o}=Mr(n);n.insertDoc(e,o,t)})}const xv=["text/x-ones-editor-doc","image/*","text/html","text/plain","text/markdown","*"];function Tv(n){let t;for(const e of xv)if(t=n[e],t)break;return t||null}class Sv{constructor(t){h(this,"editor");h(this,"handlers",[]);h(this,"onPasteText",async t=>{const e=new DataTransfer;e.setData("text/plain",t);const o=await this.editor.dataConverter.fromData(this.editor,e);o&&this.pasteDocs(o,null)});this.editor=t}onInsertText(t,e){if(!P(this.editor,this.editor.getFocusedBlock()))return;const{containerId:o,blockIndex:r,offset:i}=Mr(this.editor);this.handleBeforeInsertText(o,r,i,e)||(this.defaultInsertText(this.editor,o,r,i,e),this.handleAfterInsertText(o,r,i,e))}onKeyDown(t){if(this.handleBeforeKeyDown(t))return!0;const e=this.defaultHandleKeydown(this.editor,t);return this.handleAfterKeyDown(t)?!0:e}onChanged(t){for(let e=0;e<this.handlers.length;e++){const o=this.handlers[e];o.handleChanged&&o.handleChanged(this.editor,t)}}onRemoteChanged(t){for(let e=0;e<this.handlers.length;e++){const o=this.handlers[e];o.handleRemoteChanged&&o.handleRemoteChanged(this.editor,t)}}onCompositionStart(t){this.editor.updateCompositionText("",!1);const{containerId:e,blockIndex:o,offset:r}=Mr(this.editor);for(let i=0;i<this.handlers.length;i++){const s=this.handlers[i];s.handleCompositionStart&&s.handleCompositionStart(this.editor,e,o,r)}}onUpdateCompositionText(t,e,o){this.editor.updateCompositionText(e,o),this.editor.selection.caret.update();const{containerId:r,blockIndex:i,offset:s}=Mr(this.editor);for(let l=0;l<this.handlers.length;l++){const c=this.handlers[l];c.handleUpdateCompositionText&&c.handleUpdateCompositionText(this.editor,r,i,s,o)}}onCopy(t){kv(this.editor,t,(e,o,r)=>{for(let i=0;i<this.handlers.length;i++){const s=this.handlers[i];if(s.handleBeforeCopy){const l=s.handleBeforeCopy(this.editor,o,r);if(l===!0)return!0;if(typeof l=="object"&&l!=null)return l}}})}onPaste(t){if(t.preventDefault(),t.stopPropagation(),!t.clipboardData)return;this.editor.dataConverter.fromData(this.editor,t.clipboardData).then(async o=>{o&&this.pasteDocs(o,t)})}onFocus(){A(this.editor.rootElement,"active")}onBlur(){z(this.editor.rootElement,"active")}addHandler(t){this.handlers.push(t)}removeHandler(t){const e=this.handlers.indexOf(t);e!==-1&&this.handlers.splice(e)}handleBeforeInsertText(t,e,o,r){for(let i=0;i<this.handlers.length;i++){const s=this.handlers[i];if(s.handleBeforeInsertText&&s.handleBeforeInsertText(this.editor,t,e,o,r))return!0}return!1}handleAfterInsertText(t,e,o,r){for(let i=0;i<this.handlers.length;i++){const s=this.handlers[i];if(s.handleAfterInsertText&&s.handleAfterInsertText(this.editor,t,e,o,r))return!0}return!1}handleBeforeKeyDown(t){for(let o=0;o<this.handlers.length;o++){const r=this.handlers[o];if(r.handleBeforeKeyDown&&r.handleBeforeKeyDown(this.editor,t))return!0}const e=this.defaultHandleKeydown(this.editor,t);for(let o=0;o<this.handlers.length;o++){const r=this.handlers[o];if(r.handleAfterKeyDown&&r.handleAfterKeyDown(this.editor,t))return!0}return e}handleAfterKeyDown(t){for(let o=0;o<this.handlers.length;o++){const r=this.handlers[o];if(r.handleBeforeKeyDown&&r.handleBeforeKeyDown(this.editor,t))return!0}const e=this.defaultHandleKeydown(this.editor,t);for(let o=0;o<this.handlers.length;o++){const r=this.handlers[o];if(r.handleAfterKeyDown&&r.handleAfterKeyDown(this.editor,t))return!0}return e}defaultInsertText(t,e,o,r,i){au(this.editor,i)}defaultHandleKeydown(t,e){return z0(this.editor,e)?(e.preventDefault(),e.stopPropagation(),!0):!1}async pasteDoc(t){for(let e=0;e<this.handlers.length;e++){const o=this.handlers[e];if(o.handleBeforePasteDoc&&await o.handleBeforePasteDoc(this.editor,t))return}await Iv(this.editor,t);for(let e=0;e<this.handlers.length;e++){const o=this.handlers[e];if(o.handleAfterPasteDoc&&await o.handleAfterPasteDoc(this.editor,t))return}}async pasteDocs(t,e){for(let r=0;r<this.handlers.length;r++){const i=this.handlers[r];if(i.handleBeforePaste&&await i.handleBeforePaste(this.editor,e,t))return}const o=Tv(t);if(!!o){await this.pasteDoc(o);for(let r=0;r<this.handlers.length;r++){const i=this.handlers[r];if(i.handleAfterPaste&&await i.handleAfterPaste(this.editor,e,t))return}}}destroy(){this.handlers.forEach(t=>{var e;(e=t.destroy)==null||e.call(t,this.editor)}),this.handlers=[]}}function Dv(n,t,e){const o=yr(t,e);return o.remove(),o}B("copy-dom-attributes");const q0=["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 Lv(n,t){for(let l=0;l<q0.length;l++){const c=q0[l];t[c]=n[c]}const e=n.attributes,o=t.attributes,r=[],i=[];for(let l=0;l<e.length;l++){const c=e[l],a=o.getNamedItem(c.name);a?a.value!==c.value&&(a.value=c.value,i.push(c)):r.push(c)}const s=[];for(let l=0;l<o.length;l++){const c=o[l];e.getNamedItem(c.name)||s.push(c)}r.forEach(l=>{t.setAttribute(l.name,l.value)}),i.forEach(l=>{t.setAttribute(l.name,l.value)}),s.forEach(l=>{t.removeAttribute(l.name)})}function W0(n){const t=Array.from(n.childNodes);return t.forEach(e=>{e instanceof HTMLElement&&e.getAttribute("data-type")==="block-tools"||e.remove()}),t}function G0(n,t,e){var a;const o=n.getContainerById(t),r=yr(o,e),i=Vo(r),s=n.doc.getBlockData(t,e),l=kt(n,r);if((a=l==null?void 0:l.handleUpdateBlock)==null?void 0:a.call(l,n,r,s))n.editorBlockRenders.updateBlock(n,i,r,s);else{const u=n.editorBlocks.createBlock(i,o,s),f=W0(u);W0(r),f.forEach(C=>r.appendChild(C));const m=Dl(u);if(m){const C=Dl(r);C&&C.remove(),r.appendChild(m)}Lv(u,r)}mg(n,r,s),n.blockHooks.forEach(u=>{var f;(f=u.update)==null||f.call(u,n,i,o,r,s)}),setTimeout(()=>{n.selection.updateSelection(null)})}const Mv=B("transform-selection");function Z0(n,t,e,o){const{range:r}=n.selection,{anchor:i,focus:s}=r;if(i.blockId!==t&&s.blockId!==t)return r;d(Mv,i.isSimple()&&s.isSimple(),"invalid text pos type");let l=i;if(i.blockId===t){const a=ie.transformCursor(i.offset,e,o);l=j(t,a,"normal")}let c=s;if(s.blockId===t){const a=ie.transformCursor(s.offset,e,o);c=j(t,a,"normal")}return qt(n,{anchor:l,focus:c})}const Rv=B("handle-block-text-changed");function Av(n,t,e,o,r){const i=n.getContainerById(t),s=yr(i,e),l=n.doc.getBlockData(t,e);if(d(Rv,l.text,"no block text"),dg(n,s).setBlockText(n,s,l.text),!r){const c=Z0(n,l.id,o,r);n.selection.setRange(c,{noScroll:!0})}}function Ov(n,t){const e=Y.default(n);return t.delete.forEach(r=>{delete e[r]}),{...e,...t.insert}}function Y0(n,t,e,o){const r=kt(n,t);r.handleDeleteBlock&&r.handleDeleteBlock(n,t,e,o),n.emit("blockDeleted",n,t,e,o)}function _v(n,t,e,o){const r=n.getBlockByIndex(t,e);r.querySelectorAll('[data-type="editor-block"]').forEach(i=>{Y0(n,i,o,{child:!0})}),Y0(n,r,o,{child:!1})}const Vn=B("editor-doc");class Nv extends Di{constructor(e,o,r){super();h(this,"localEvents",[]);this.editor=e,this.externalDoc=o,this.externalDoc.registerCallback(this),this.registerLocalEvents(r)}beginBatchUpdate(){return this.externalDoc.beginBatchUpdate()}endBatchUpdate(){return this.externalDoc.endBatchUpdate()}registerLocalEvents(e){this.localEvents.push(e)}toJSON(){return this.externalDoc.toJSON()}getVersionHelper(){var o,r;return(r=(o=this.externalDoc).getVersionHelper)==null?void 0:r.call(o)}getContainerBlocks(e){return this.externalDoc.getContainerBlocks(e)}getBlockData(e,o){return this.externalDoc.getBlockData(e,o)}localUpdateBlockText(e,o,r,i){d(Vn,this.editor.isWritable(),"editor is readonly");const s=this.getBlockData(e,o),l=s.text;d(Vn,l,`no text, ${e}, ${o}`);const c=Z0(this.editor,s.id,r,!0),a=ie.apply(l,r);this.localEvents.forEach(f=>f.onBeforeUpdateBlockText(e,s.id,l,a,c.toDocRange()));const u=this.externalDoc.localUpdateBlockText(e,o,r);return this.editor.selection.setRange(c,i),u}localUpdateBlockData(e,o,r,i){d(Vn,this.editor.isWritable(),"editor is readonly");const s=Y.default(this.getBlockData(e,o)),l=Y.default(Ov(s,r));this.localEvents.forEach(a=>a.onBeforeUpdateBlockData(e,s.id,s,l,i));const c=this.externalDoc.localUpdateBlockData(e,o,r,i);return this.editor.selection.setRange(lo(this.editor,i)),c}localInsertBlock(e,o,r,i,s){d(Vn,this.editor.isWritable(),"editor is readonly"),this.localEvents.forEach(c=>c.onBeforeInsertBlock(e,o,r,i));const l=this.externalDoc.localInsertBlock(e,o,r,i);return this.editor.selection.setRange(lo(this.editor,i),s),l}localDeleteBlock(e,o,r){d(Vn,this.editor.isWritable(),"editor is readonly");const i=Y.default(this.getBlockData(e,o));this.localEvents.forEach(l=>l.onBeforeDeleteBlock(e,o,i,r));const s=this.externalDoc.localDeleteBlock(e,o,r);return this.editor.selection.setRange(lo(this.editor,r)),s}localDeleteChildContainers(e){return d(Vn,this.editor.isWritable(),"editor is readonly"),e.forEach(o=>{const r=Y.default(this.getContainerBlocks(o));this.localEvents.forEach(i=>i.onBeforeDeleteChildContainer(o,r))}),this.externalDoc.localDeleteChildContainers(e)}localInsertChildContainer(e,o){return d(Vn,this.editor.isWritable(),"editor is readonly"),this.localEvents.forEach(r=>r.onBeforeInsertChildContainer(e,Y.default(o))),this.externalDoc.localInsertChildContainer(e,o)}onRequestReload(e){Vn.debug(`reload doc: ${e}`),this.editor.reload(),this.callbacks.forEach(r=>{var i;return(i=r.onRequestReload)==null?void 0:i.call(r,e)});const o=!1;this.editor.emit("docChanged",this.editor,o)}onUpdateBlockText(e,o,r,i){this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockText)==null?void 0:l.call(s,e,o,r,i)}),Av(this.editor,e,o,r,i),this.editor.emit("docChanged",this.editor,i)}onUpdateBlockData(e,o,r,i){this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockData)==null?void 0:l.call(s,e,o,r,i)}),G0(this.editor,e,o),this.editor.emit("docChanged",this.editor,i)}onInsertBlock(e,o,r,i){this.callbacks.forEach(l=>{var c;return(c=l.onInsertBlock)==null?void 0:c.call(l,e,o,r,i)});const s=this.editor.getContainerById(e);v8(this.editor,s,o,r),this.editor.emit("docChanged",this.editor,i)}onDeleteBlock(e,o,r){_v(this.editor,e,o,r),this.callbacks.forEach(s=>{var l;return(l=s.onDeleteBlock)==null?void 0:l.call(s,e,o,r)});const i=this.editor.getContainerById(e);Dv(this.editor,i,o),this.editor.emit("docChanged",this.editor,r)}onInsertChildContainer(e,o,r){this.callbacks.forEach(i=>{var s;return(s=i.onInsertChildContainer)==null?void 0:s.call(i,e,o,r)})}onDeleteChildContainer(e,o){this.callbacks.forEach(r=>{var i;return(i=r.onDeleteChildContainer)==null?void 0:i.call(r,e,o)})}onCustomMessage(e){this.callbacks.forEach(o=>{var r;return(r=o.onCustomMessage)==null?void 0:r.call(o,e)})}onStatusChanged(e){this.callbacks.forEach(o=>{var r;return(r=o.onStatusChanged)==null?void 0:r.call(o,e)})}onError(e){this.callbacks.forEach(o=>{var r;return(r=o.onError)==null?void 0:r.call(o,e)})}uploadResource(e,o){return this.externalDoc.uploadResource(e,o)}addResources(e){return this.externalDoc.addResources(e)}buildResourceUrl(e,o){return this.externalDoc.buildResourceUrl(e,o)}request(e,o){return this.externalDoc.request(e,o)}broadcastMessage(e){return this.externalDoc.broadcastMessage(e)}getUser(){return this.externalDoc.getUser()}getRemoteUsers(){return this.externalDoc.getRemoteUsers()}destroy(){this.externalDoc.destroy(),this.clearCallbacks()}getServerMeta(){var e,o,r;return(r=(o=(e=this.externalDoc).getServerMeta)==null?void 0:o.call(e))!=null?r:{}}reset(e){Vn.log("reset doc"),this.externalDoc=e,this.externalDoc.registerCallback(this),this.editor.reload()}}function Q0(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 Au=B("undo-action");class _r{constructor(t,e,o){h(this,"beforeRange");h(this,"afterRange");this.containerId=e,this.beforeRange=t.selection.range.clone().toDocRange(),this.afterRange=o}undo(t){return!1}redo(t){return!1}combinable(t){return d(Au,t,"no other action"),!1}combine(t){d(Au,!1,"no other")}setAfterRange(t){this.afterRange&&Au.warn("after range has already set"),this.afterRange=t}}const $v=B("block-action");class K0 extends _r{constructor(e,o,r,i,s){super(e,o,s);h(this,"blockData");h(this,"blockIndex");this.blockData=Y.default(i),this.blockIndex=r}deleteBlock(e,o){if(!e.getContainerById(this.containerId))return!1;const i=e.getBlockById(this.blockData.id);return i?(d($v,this.blockIndex===J(i),"invalid block index"),hu(e,i,lo(e,o)),!0):!1}insertBlock(e,o){return Rr(e,this.containerId,this.blockIndex,Y.default(this.blockData),o),!0}}class Pv extends K0{undo(t){return this.deleteBlock(t,this.beforeRange)}redo(t){return this.insertBlock(t,this.afterRange)}}class jv extends K0{undo(t){return this.insertBlock(t,this.beforeRange)}redo(t){return this.deleteBlock(t,this.afterRange)}}class Hv extends _r{constructor(e){super(e,U(e.rootContainer),e.selection.range.toDocRange());h(this,"actions",[])}addAction(e){Q0(this.actions,e),this.afterRange=e.afterRange}undo(e){let o=!1;return this.actions.concat().reverse().forEach(r=>{r.undo(e)&&(o=!0)}),o}redo(e){let o=!1;return this.actions.forEach(r=>{r.redo(e)&&(o=!0)}),o}setAfterRange(e){this.afterRange=e;const o=this.actions[this.actions.length-1];!o||o instanceof _r&&(o.afterRange||o.setAfterRange(e))}}const Xo=B("update-block-data-action");class dc extends _r{constructor(e,o,r,i,s,l){super(e,o,l);h(this,"beforeBlockData");h(this,"afterBlockData");h(this,"blockId");this.blockId=r,d(Xo,this.blockId===i.id,"invalid block id"),d(Xo,this.blockId===s.id,"invalid block id"),this.beforeBlockData=Y.default(i),this.afterBlockData=Y.default(s),d(Xo,this.beforeBlockData.type===this.afterBlockData.type,"invalid block type")}undo(e){d(Xo,e,"no editor");const o=e.getBlockById(this.blockId);if(!o)return!1;const r=e.getContainerById(this.containerId);return d(Xo,r,"no container"),rc(e,o,dc.toAttributes(this.beforeBlockData),this.beforeRange),!0}redo(e){d(Xo,e,"no editor");const o=e.getBlockById(this.blockId);if(!o)return!1;const r=e.getContainerById(this.containerId);return d(Xo,r,"no container"),rc(e,o,dc.toAttributes(this.afterBlockData),this.afterRange),!0}static toAttributes(e){const o=Y.default(e);return delete o.id,delete o.type,o}}const Ou=B("update-block-text-action");class ns extends _r{constructor(e,o,r,i,s,l){super(e,o,l);h(this,"beforeRichTextData");h(this,"afterRichTextData");h(this,"blockId");h(this,"type");this.blockId=r,this.beforeRichTextData=Y.default(i),this.afterRichTextData=Y.default(s),this.type=ns.calType(i,s)}static calType(e,o){d(Ou,e,"no old data"),d(Ou,o,"no new data");const i=ie.diff(e,o),s=new Set;let l=!1;const c=u=>km(u)?`cjk_${u}`:Cm(u)?"number":vl(u)?"space":bm(u)?"letter":"unknown";let a=!1;return i.forEach(u=>{u.insert?u.insert===" "?s.add("insert_letter"):typeof u.insert=="string"&&u.insert.startsWith(" ")&&u.insert.length>1?(l=!0,a=!0,s.add(`insert_${c(u.insert.substr(1))}`)):s.add(`insert_${c(u.insert)}`):u.delete&&(l?l=!1:s.add("delete"))}),{textType:Array.from(s).join("|"),begin:a}}undo(e){if(!e.getContainerById(this.containerId))return!1;const r=e.getBlockById(this.blockId);return r?(oc(e,r,this.beforeRichTextData),!0):!1}redo(e){if(!e.getContainerById(this.containerId))return!1;const r=e.getBlockById(this.blockId);return r?(oc(e,r,this.afterRichTextData),!0):!1}combinable(e){if(!(e instanceof ns)||e.type.begin||this.type.textType!==e.type.textType||e.blockId!==this.blockId)return!1;const o=e.beforeRange,r=o.anchor;if(!r.isSimple())return!1;const i=this.afterRange;if(!i)return!1;const s=i.anchor;return!(!s.isSimple()||s.blockId!==o.anchor.blockId||s.offset!==r.offset)}combine(e){d(Ou,e instanceof ns,"invalid action type");const o=e;this.afterRichTextData=o.afterRichTextData,this.afterRange=e.afterRange}}class J0 extends _r{constructor(t,e,o){super(t,e,t.selection.range.toDocRange()),this.blocks=o}deleteChildContainer(t){return t.doc.localDeleteChildContainers([this.containerId]),!0}insertChildContainer(t){return t.doc.localInsertChildContainer(this.containerId,Y.default(this.blocks)),!0}}class Fv extends J0{undo(t){return this.deleteChildContainer(t)}redo(t){return this.insertChildContainer(t)}}class zv extends J0{undo(t){return this.insertChildContainer(t)}redo(t){return this.deleteChildContainer(t)}}const nn=B("undo");class Uv{constructor(t){h(this,"editor");h(this,"actions",[]);h(this,"undoCursor");h(this,"currentGroup",null);h(this,"groupCounter",0);h(this,"undoRedoing",!1);h(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):(Q0(this.actions,t),setTimeout(()=>{this.editor.input.handleChanged(t)}))}beginGroup(){this.groupCounter===0?(d(nn,!this.currentGroup,"current group already exists"),this.currentGroup=new Hv(this.editor),this.groupCounter=1):(d(nn,this.currentGroup,"current group not exists"),this.groupCounter+=1)}endGroup(){d(nn,this.currentGroup,"current group not exists"),d(nn,this.groupCounter>0,"group counter === 0"),this.groupCounter-=1,this.groupCounter===0&&(this.currentGroup.actions.length===0?nn.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 nn.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(lo(this.editor,t.beforeRange))}catch(e){nn.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(lo(this.editor,e)):nn.warn("no after range")}catch(e){nn.error(`redo: failed to set caret pos after redo: ${e.message}`)}return this.editor.input.handleChanged(t),!0}}return!1}finally{this.undoRedoing=!1}}canUndo(){return!(this.actions.length===0||this.undoCursor===0)}canRedo(){return!(this.actions.length===0||this.undoCursor===-1||this.undoCursor===this.actions.length)}lastAction(){var e;const t=this.undoCursor===-1?this.actions.length-1:this.undoCursor-1;return(e=this.actions[t])!=null?e:null}undoTo(t){for(;;){const e=this.lastAction();if(!e||e===t)return!0;if(!this.undo())return!1}}onBeforeUpdateBlockText(t,e,o,r,i){this.undoRedoing||(this.prepareSaveUndoState(),ie.diff(o,r).length!==0&&this.addAction(new ns(this.editor,t,e,o,r,i)))}onBeforeUpdateBlockData(t,e,o,r,i){if(this.undoRedoing)return;this.prepareSaveUndoState();const s=new dc(this.editor,t,e,o,r,i);this.addAction(s)}onBeforeInsertBlock(t,e,o,r){this.undoRedoing||(this.prepareSaveUndoState(),d(nn,e>=0,"invalid block index"),d(nn,o,"no block data"),this.addAction(new Pv(this.editor,t,e,o,r)))}onBeforeDeleteBlock(t,e,o,r){this.undoRedoing||(this.prepareSaveUndoState(),this.addAction(new jv(this.editor,t,e,o,r)))}onBeforeInsertChildContainer(t,e){this.undoRedoing||(this.prepareSaveUndoState(),this.addAction(new Fv(this.editor,t,e)))}onBeforeDeleteChildContainer(t,e){this.undoRedoing||(this.prepareSaveUndoState(),this.addAction(new zv(this.editor,t,e)))}}class Vv{async fromData(t,e){const o=e.getData("text/x-ones-editor-doc");if(o)return{"text/x-ones-editor-doc":JSON.parse(o)}}}class qv{constructor(){h(this,"converters",[]);this.addConverter(new Vv)}async fromData(t,e){let o={};for(const r of this.converters){const i=await r.fromData(t,e);i&&(o={...o,...i})}return o}addConverter(t){this.converters.push(t)}}class Wv{constructor(t){h(this,"renders",[]);this.editor=t}registerRender(t){this.renders.push(t)}renderText(t,e){const o={classes:[],attributes:{},styles:{}};return this.renders.forEach(r=>{if(r.renderText){const i=r.renderText(this.editor,t,e);i.classes&&o.classes.push(...i.classes),i.attributes&&(o.attributes={...o.attributes,...i.attributes}),i.styles&&(o.styles={...o.styles,...i.styles})}}),o}renderBlock(t,e,o){const r={classes:[],attributes:{},styles:{}};return this.renders.forEach(i=>{if(i.renderBlock){const s=i.renderBlock(this.editor,e,o);s.classes&&r.classes.push(...s.classes),s.attributes&&(r.attributes={...r.attributes,...s.attributes}),s.styles&&(r.styles={...r.styles,...s.styles})}}),r}updateBlock(t,e,o,r){this.renders.forEach(i=>{var s;(s=i.updateBlock)==null||s.call(i,t,e,o,r)})}}class Nt extends Yt.TypedEmitter{constructor(e){super();h(this,"hoveringBlock",null);h(this,"hoveringTextChild",null);h(this,"filters",[]);h(this,"finders",[]);h(this,"handleDocumentMouseMove",e=>{if(this.hoveringBlock){for(const s of this.filters)if(s.isInBlock(this.hoveringBlock,e))return}const o=document.elementFromPoint(e.x,e.y);if(!o){this.setHoveringBlock(null,e,null);return}let r=F(o);if((!r||!It(this.editor.rootContainer,r))&&(r=this.findBlockByFinders(e),!r)){this.setHoveringBlock(null,e,null);return}const i=this.getParentTextContentChild(r,o);this.setHoveringBlock(r,e,i)});this.editor=e,document.addEventListener("mousemove",this.handleDocumentMouseMove)}destroy(){document.removeEventListener("mousemove",this.handleDocumentMouseMove),this.filters.forEach(e=>e.destroy()),this.filters=[],this.finders.forEach(e=>e.destroy()),this.finders=[]}addFilter(e){this.filters.push(e)}addFinder(e){this.finders.push(e)}hoveringBlockId(){return this.hoveringBlock?q(this.hoveringBlock):""}findBlockByFinders(e){for(let o=0;o<this.finders.length;o++){const i=this.finders[o].findTargetBlock(this.editor,e);if(i)return i}return null}setHoveringBlock(e,o,r){if(this.hoveringBlock===e&&this.hoveringTextChild===r)return;if(this.hoveringBlock!==e){const s=this.hoveringBlock&&It(this.editor.rootContainer,this.hoveringBlock)?this.hoveringBlock:null;s&&z(s,"hover"),e&&A(e,"hover"),this.hoveringBlock=e,this.emit("change",this.hoveringBlock,s,o)}const i=this.hoveringTextChild;this.hoveringTextChild=r,this.emit("childChange",this.hoveringBlock,r,i,o)}static get(e){return e.addCustom("standard-hovering-block",()=>new Nt(e))}getParentTextContentChild(e,o){if(!P(this.editor,e))return null;const r=it(e);return o.parentElement===r?o:kd(o)}}const X0="style-color-",t2="style-bg-color-";class Gv{renderText(t,e,o){const r=[],i={};return Object.entries(o).forEach(([s,l])=>{l===!0?s.startsWith(X0)?i["data-style-color"]=s.substring(X0.length):s.startsWith(t2)?i["data-style-bg-color"]=s.substring(t2.length):s.startsWith("style")&&r.push(s):typeof l=="string"&&s==="link"&&(r.push("link"),i.link=l)}),{classes:r,attributes:i}}renderBlock(t,e,o){var l,c;const r={};Object.entries(o).filter(a=>a[0].startsWith("style-")).forEach(([a,u])=>{r[`data-${a}`]=`${u}`});const s=[];return((c=(l=t.selection)==null?void 0:l.range)==null?void 0:c.start.blockId)===o.id&&s.push("focused"),typeof o.align=="string"&&o.align&&(r["data-style-align"]=o.align),o.heading&&(r["data-style-heading"]=String(o.heading)),o.quoted&&(r["data-style-quoted"]="true"),Nt.get(t).hoveringBlockId()===o.id&&s.push("hover"),{attributes:r,classes:s}}updateBlock(t,e,o,r){var s,l;Array.from(o.attributes).forEach(c=>{c.name.startsWith("data-style-")&&o.removeAttribute(c.name)}),Object.entries(r).filter(c=>c[0].startsWith("style-")).forEach(([c,a])=>{o.setAttribute(`data-${c}`,`${a}`)}),((l=(s=t.selection)==null?void 0:s.range)==null?void 0:l.start.blockId)===r.id&&A(o,"focused"),Nt.get(t).hoveringBlockId()===r.id&&A(o,"hover")}}function Zv(n){n.editorBlocks.registerBlockClass(ke),n.editorBlocks.registerBlockClass(Ig),n.editorBoxes.registerBoxClass(gp),n.editorBoxes.registerBoxClass(pp),n.editorInsertions.registerInsertionClass(kp),n.editorBlockRenders.registerRender(new Gv)}function Yv(n,t){Zv(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 e2=B("range-commands");function n2(n,t){n.forEach(e=>{e.source=t,e.children&&n2(e.children,t)})}function o2(n,t,e){const o=q(t);d(e2,o===e.start.blockId,"invalid start range"),d(e2,o===e.end.blockId,"invalid end range");const r=n.editorCommandProviders.getCommandProviders();let i=[];return r.forEach(s=>{const l=s.getAvailableCommands(n,t,e);n2(l,s.id),i.push(...l)}),r.forEach(s=>{if(s.filterCommands){const l=s.filterCommands(n,t,e,i);l&&(i=l)}}),at(n,t)&&xr(n,t,e.start,e.end).forEach(l=>{Mt(l).forEach(a=>{const u=W(n,a),f=qt(n,{anchor:j(a,0,"home"),focus:j(a,u,"end")}),m=o2(n,a,f);i.push(...m)})}),i}function r2(n){const t=n.getEditor(),e=n.getSelectedBlocks(),o=[];return e.forEach(r=>{const i=qt(t,{anchor:r.start,focus:r.end});o2(t,r.block,i).forEach(l=>{o.push(l)})}),o}function i2(n,t,e,o,r,i){var u;const s=n.editorCommandProviders.getCommandProviders();for(let f=0;f<s.length;f++){const m=s[f];if(m.beforeExecuteCommand&&m.beforeExecuteCommand(n,t,e,o,r))return!1}const l=n.editorCommandProviders.getCommandProvider(o.source),c={};if((u=l.executeCommand)!=null&&u.call(l,n,t,e,o,r,{}))return i[q(t)]=c,!0;let a=!1;return at(n,t)&&xr(n,t,e.start,e.end).forEach(m=>{Mt(m).forEach(k=>{const w=W(n,k),y=qt(n,{anchor:j(k,0,"home"),focus:j(k,w,"end")});i2(n,k,y,o,r,i)&&(a=!0)})}),s.forEach(f=>{f.afterExecuteCommand&&f.afterExecuteCommand(n,t,e,o,r,i)}),a}function s2(n,t,e){const o=n.getEditor(),r={},i=o.editorCommandProviders.getCommandProvider(t.source);return i.executeRangeCommand&&i.executeRangeCommand(o,n,t,e,r)||n.getSelectedBlocks().forEach(l=>{const c=qt(o,{anchor:l.start,focus:l.end});i2(o,l.block,c,t,e,r)}),r}const Qv=B("command-providers");class l2{constructor(t){h(this,"providers",[]);this.editor=t}registerCommandProvider(t){this.providers.push(t)}getCommandProviders(){return this.providers}getCommandProvider(t){const e=this.providers.find(o=>o.id===t);return d(Qv,e,`no command provider, id=${t}`),e}getCommands(t){return r2(t)}executeCommand(t,e,o){return this.editor.undoManager.runInGroup(()=>s2(t,e,o))}getEmptyBlockTextAttributes(t,e){let o={};if(this.providers.forEach(r=>{var s;const i=(s=r.getEmptyBlockTextAttributes)==null?void 0:s.call(r,t,e);i&&(o={...o,...i})}),Object.keys(o).length!==0)return o}}function Kv(n,t){const e=H(t),o=U(e),r=J(t);G0(n,o,r)}const Jv=B("table-scroll");class c2{constructor(t,e,o,r,i){h(this,"handleEvent",t=>{this.handler(this.editor,t,this.data)});this.editor=t,this.dom=e,this.name=o,this.handler=r,this.data=i,e.addEventListener(o,this.handleEvent)}destroy(){this.dom.removeEventListener(this.name,this.handleEvent)}}class Xv{constructor(t){h(this,"handlers",new Map);this.editor=t}destroy(){Array.from(this.handlers.entries()).forEach(([t,e])=>{e.forEach(o=>o.destroy()),this.handlers.delete(t)})}addEventListener(t,e,o,r){const i=this.handlers.get(t);if(i){if(i.find(s=>s.handler===o&&s.name===e)){Jv.warn(`event has already registered: ${e}`);return}i.push(new c2(this.editor,t,e,o,r))}else{const s=new c2(this.editor,t,e,o,r);this.handlers.set(t,[s])}}removeEventListener(t,e,o){if(!t){for(const[i,s]of Array.from(this.handlers.entries()))for(let l=s.length-1;l>=0;l--){const c=s[l];if(e)e===c.name&&o===c.handler&&s.splice(l,1);else if(o===c.handler){s.splice(l,1),c.destroy(),s.length===0&&this.handlers.delete(i);continue}}return}const r=this.handlers.get(t);if(r){const i=r.findIndex(s=>s.handler===o&&s.name===e);if(i!==-1){const s=r[i];r.splice(i,1),s.destroy(),r.length===0&&this.handlers.delete(t)}}}removeAllListeners(t,e){const o=this.handlers.get(t);if(o)if(e)for(let r=0;r<o.length;r++){const i=o[r];i.name===e&&(o.splice(r,1),i.destroy())}else o.forEach(r=>{r.destroy()}),this.handlers.delete(t)}}const a2=B("update-block-text");function ty(n,t){const e=n.getBoxById(t.id),o=F(e);d(a2,o,"no parent block"),d(a2,P(n,o),"not a text block");const r=n.getBlockText(o),i=ip(r,"id",t.id,t);Fp(n,o,i)}function ey(n,t){for(const e of n.blockHooks)if(e.writable){const o=e.writable(n,t);if(typeof o=="boolean")return o}return!0}function ny(n){return n.readonly?!1:!tn(n).find(o=>!n.isBlockWritable(o.block))}class oy{constructor(t){this.editor=t}getKey(t){return`${this.editor.id}-${t}`}async getItem(t){return window.localStorage.getItem(this.getKey(t))}async setItem(t,e){if(!e){this.removeItem(t);return}window.localStorage.setItem(this.getKey(t),e)}async removeItem(t){window.localStorage.removeItem(this.getKey(t))}}class ry{constructor(){h(this,"shortcuts",[])}handleKeyboardEvents(t,e){const o=this.shortcuts;for(const r of o){const i=Object.entries(r);for(const[s,l]of i)if(jn(e,s)){const c=l(t,e);if(c!==void 0)return c}}}}const Bn=B("editor");class iy extends Yt.TypedEmitter{constructor(e,o,r){var i,s,l,c,a,u,f,m;super();h(this,"parent");h(this,"rootElement");h(this,"contentElement");h(this,"rootContainerObject");h(this,"rootContainer");h(this,"input");h(this,"selection");h(this,"selectionHandler");h(this,"doc");h(this,"id");h(this,"clientId");h(this,"compositingText","");h(this,"undoManager");h(this,"shortcuts",new ry);h(this,"dataConverter",new qv);h(this,"editorBlocks",new yg(this));h(this,"editorBoxes",new bp(this));h(this,"editorInsertions",new yp(this));h(this,"editorEmbeds",new Bg(this));h(this,"editorDecorators",new wp(this));h(this,"editorCommandProviders",new l2(this));h(this,"editorBlockRenders",new Wv(this));h(this,"blockHooks",[]);h(this,"domEvents",new Xv(this));h(this,"customs",new Map);h(this,"options");h(this,"inputHandlers",new Sv(this));h(this,"settingsProvider");h(this,"_readonly",!1);Bn.debug("create editor"),this.setMaxListeners(100),this.options={colors:(i=r==null?void 0:r.colors)!=null?i:["#9923E9","#4587C2","#8BDB7A","#FB28D3","#CBC619","#10FEEB","#812A1A","#8A3F25","#22D742","#A53E74","#555C87","#57E0AA"],componentsOptions:(l=(s=r==null?void 0:r.components)==null?void 0:s.options)!=null?l:{},scrollContainer:r==null?void 0:r.scrollContainer},this.settingsProvider=(c=r==null?void 0:r.settingsProvider)!=null?c:new oy(this),Yv(this,r==null?void 0:r.components),Bn.debug(((a=r==null?void 0:r.components)==null?void 0:a.blockHooks)||[],"register block hooks"),this.blockHooks.push(...(f=(u=r==null?void 0:r.components)==null?void 0:u.blockHooks)!=null?f:[]),this.id=(m=r==null?void 0:r.id)!=null?m:N(),this.clientId=N(),this.undoManager=new Uv(this),this.doc=new Nv(this,o,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=lg(this),this.rootContainer=this.rootContainerObject.rootContainer,this.input=new pk(this,this.inputHandlers),this.selection=new ev(this),this.selectionHandler=new rv(this),r!=null&&r.shortcuts&&this.shortcuts.shortcuts.push(...r.shortcuts),xt.isMobile&&A(this.rootElement,"mobile"),xt.isSafari&&A(this.rootElement,"safari"),this._readonly&&A(this.rootElement,"readonly"),this.emit("load",this,!1)}get readonly(){return this._readonly}set readonly(e){this._readonly=e,e?A(this.rootElement,"readonly"):z(this.rootElement,"readonly"),this.emit("readonlyChanged",this)}get scrollContainer(){return this.options.scrollContainer?this.options.scrollContainer:We(this.rootContainer)}addCustom(e,o){const r=this.customs.get(e);if(r)return r;const i=o(this);return this.customs.set(e,i),i}getCustom(e){const o=this.customs.get(e);return d(Bn,o,`${e} does not exists`),o}replaceCustom(e,o){const r=this.customs.get(e);return r&&r.destroy(),this.customs.set(e,o),o}findCustom(e){return this.customs.get(e)}findCustomByType(e){const o=this.customs.values();for(const r of o)if(r instanceof e)return r;return null}destroyCustom(e){const o=this.customs.get(e);o&&(this.customs.delete(e),o.destroy())}getComponentOptions(e){return this.options.componentsOptions[e]}registerLocalEvents(e){this.doc.registerLocalEvents(e)}reload(){this.rootContainerObject.reload(),this.emit("load",this,!0)}createBlock(e,o,r){return this.editorBlocks.createBlock(e,o,r)}createBox(e,o){return this.editorBoxes.createBox(e,o)}createInsertion(e,o){return this.editorInsertions.createInsertion(e,o)}destroy(){Bn.debug("destroy editor"),this.emit("destroy",this),this.input.destroy(),this.rootContainerObject.destroy(),this.rootElement.remove(),this.doc.destroy(),this.customs.forEach(e=>e.destroy()),this.customs.clear(),this.selection.destroy(),this.domEvents.destroy(),this.removeAllListeners(),this.inputHandlers.destroy()}focus(){this.input.focus()}focusToBlock(e,o){pu(this,e,o)}isWritable(){return ny(this)}isBlockWritable(e){return ey(this,e)}getChildContainerData(e){const o=this.doc.getContainerBlocks(e);return d(Bn,o,`no child container data: ${e}, ${JSON.stringify(this.doc)}`),d(Bn,Array.isArray(o),`container data is not an array: ${JSON.stringify(o)}`),o}createChildContainer(e,o,r){return cg(this,e,o,r)}getFirstBlock(){return this.rootContainer.querySelector("[data-type=editor-block]")}getLastBlock(){const e=Array.from(this.rootContainer.querySelectorAll(":scope [data-type=editor-block]"));return e[e.length-1]}getFocusedBlock(){return this.selection.getFocusedBlock()}findBlockById(e){const o=this.rootContainer.querySelector(`#${e}`);return o&&d(Bn,Uo(o),"not an valid block element"),o!=null?o:null}findBoxById(e){const o=this.rootContainer.querySelector(`#${e}`);return o&&d(Bn,bd(o),"not an valid box element"),o!=null?o:null}getBlockById(e){const o=this.findBlockById(e);return d(Bn,o,`no block, id=${e}`),o}getBoxById(e){const o=this.findBoxById(e);return d(Bn,o,`no box, id=${e}`),o}getBlockByIndex(e,o){const r=this.getContainerById(e);return yr(r,o)}getBlockIndex(e){if(typeof e=="string"){const o=this.getBlockById(e);return J(o)}return J(e)}getContainerById(e){return Er(this,e)}getParentContainer(e){return H(e)}reloadBlock(e){Kv(this,e)}contains(e){const o=e instanceof Element?e:e.parentElement;return o?o.closest("div.editor-root")===this.rootElement:!1}insertBlock(e,o,r,i,s){const l={blockId:r.id,offset:0},c={anchor:l,focus:l};return Rr(this,e,o,r,i!=null?i:c,s)}insertEmbed(e,o,r,i,s){const l={id:N(),type:"embed",embedType:r,embedData:i};return this.insertBlock(e,o,l,s)}deleteBlock(e,o){fu(this,e,o)}mergeTextBlock(e,o){return Pp(this,e,o)}breakTextBlock(e,o,r){return Ar(this,e,o,r).newBlock}getTextPosition(){return Mr(this)}getBlockString(e,o){const r=this.getBlockText(e);return bt(r,o)}getBlockData(e){return fo(this,e)}getBoxData(e){return fp(this,e)}getBlockText(e){return he(this,e)}setBlockText(e,o){Fp(this,e,o)}deleteTextFromBlock(e,o,r,i){return du(this,e,o,r,i)}insertTextToBlock(e,o,r,i){return Mp(this,e,o,r,i)}insertBoxToBlock(e,o,r){return Rp(this,e,o,r)}pasteDoc(e){return this.inputHandlers.pasteDoc(e)}insertDoc(e,o,r,i){Vp(this,e,o,r,i)}insertDocAt(e,o,r,i){return ku(this,e,o,r,i)}deleteChildContainers(e){$p(this,e)}replaceBlockText(e,o){return oc(this,e,o)}updateBlockData(e,o,r){const i={...this.getBlockData(e),...o},{id:s,type:l,...c}=i;return rc(this,e,c,(r!=null?r:this.selection.range).toDocRange())}updateEmbedData(e,o,r){return zp(this,e,o,r)}updateBoxData(e){ty(this,e)}getSelectedText(){const e=Xi(this);return Jl(this,e)}clearSelectedContents(){gu(this)}insertTextBlock(e,o,r,i){const s=Un(e!=null?e:"");return Np(this,s,o,r,i==null?void 0:i.newRange,i==null?void 0:i.insertBlockOptions)}updateCompositionText(e,o){if(e&&!o&&(this.selection.range.isCollapsed()||this.clearSelectedContents()),!e&&!o){Op(this);return}o?(this.compositingText="",cd()||au(this,e)):(this.compositingText=e,Ap(this))}getColor(e){const o=this.options.colors;return o.length===0?"#FF1A75":o[e%o.length]}}function os(n,t,e){return new iy(n,t,e)}function sy(n){const t=(o,r)=>{const i=o.findIndex(l=>l.id===r.id);if(i===-1){o.push(r);return}const s=o[i];if(s.value!==r.value){o.splice(i,1);return}if(!!s.states){if(!r.states){s.states=[];return}s.states=Xa.default(s.states,r.states)}},e=[];return n.forEach(o=>{o.forEach(r=>{t(e,r)})}),e}const ly=["#FBBFBD","#FFDDB6","#FFF897","#C5F0C1","#CEDDFE","#DCC9FC","#E5E6E8","#F76964","#FFA53D","#FFE928","#63D156","#A0BBFE","#C4A5FB","#BBBFC3"];class uc extends Yt.TypedEmitter{constructor(e){super();h(this,"users",new Map);h(this,"cursors",new Map);h(this,"addingUser",!1);h(this,"colors");this.colors=e&&e.length>0?e:ly}setCursor(e){this.addUser(e.user);const o=this.cursors.get(e.user.userId);if(o&&ml.default(o,e))return;this.cursors.set(e.user.userId,e);const r=new Set([e.range.anchor.blockId,e.range.focus.blockId]),i=new Set(r);o&&new Set([o.range.anchor.blockId,o.range.focus.blockId]).forEach(l=>{r.has(l)||i.add(l)}),this.emit("remote-carets-change",[...i])}addUsers(e){this.addingUser=!0,e.forEach(o=>this.addUser(o)),this.addingUser=!1,this.emit("change",Array.from(this.users.values()))}addUser(e){this.users.set(e.userId,e),this.addingUser||this.emit("change",Array.from(this.users.values()))}findUser(e){var o;return(o=this.users.get(e))!=null?o:null}removeUser(e){this.users.delete(e),this.cursors.delete(e),this.emit("change",Array.from(this.users.values()))}updateUsers(e){this.users.clear(),this.addingUser=!0;try{e.forEach(o=>{this.addUser(o)})}finally{this.addingUser=!1}setTimeout(()=>{this.emit("change",Array.from(this.users.values()))},300)}getSimpleCursors(e){const o=new Map;return Array.from(this.cursors.values()).filter(r=>r.range.anchor.blockId===e&&Wl(r.range)).forEach(r=>{const i=r.range.focus.offset;let s=o.get(i);s||(s=[],o.set(i,s)),s.push(r)}),o}getCursors(e){return Array.from(this.cursors.values()).filter(o=>o.range.anchor.blockId===e||o.range.focus.blockId===e)}onUpdateBlockText(e,o,r){if(!e.text)return;this.getCursors(e.id).forEach(l=>{if(Wl(l.range)){const{anchor:c,focus:a}=l.range;c.blockId===e.id&&(c.offset=ie.transformCursor(c.offset,o,r)),a.blockId===e.id&&(a.offset=ie.transformCursor(a.offset,o,r))}})}getFixedUserColor(e,o){let r=0;Array.from(e).forEach(s=>{r+=s.charCodeAt(0)});const i=r%this.colors.length;return this.colors[i]}destroy(){this.removeAllListeners()}}const te=B("local-doc");class _u extends Di{constructor(e,o){super();h(this,"doc");h(this,"serviceUrl");e?this.doc=e:this.doc={meta:{},comments:{},blocks:{root:[Un("")]}},this.serviceUrl=(o==null?void 0:o.serverUrl)||""}beginBatchUpdate(){return 0}endBatchUpdate(){return 0}toJSON(){return Y.default(this.doc)}getContainerBlocks(e){return this.doc.blocks[e]}getBlockData(e,o){const r=this.getContainerBlocks(e);d(te,r,`no container data: ${e}`);const i=r[o];return d(te,i,`no block data: ${o}`),i}localUpdateBlockText(e,o,r){const i=this.getBlockData(e,o);d(te,i.text,"no text for data");const s=ie.apply(i.text,r);return i.text=s,d(te,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(l=>{var c;return(c=l.onUpdateBlockText)==null?void 0:c.call(l,e,o,r,!0)}),s}localUpdateBlockData(e,o,r){const i=this.getBlockData(e,o);return r.delete.forEach(s=>delete i[s]),Object.entries(r.insert).forEach(([s,l])=>{i[s]=l}),d(te,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockData)==null?void 0:l.call(s,e,o,r,!0)}),i}localInsertBlock(e,o,r){const i=this.getContainerBlocks(e);return d(te,i,`no container data: ${e}`),d(te,o>=0&&o<=i.length,`invalid block index: ${o}, ${i.length}`),i.splice(o,0,r),d(te,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onInsertBlock)==null?void 0:l.call(s,e,o,r,!0)}),r}localDeleteBlock(e,o){const r=this.getContainerBlocks(e);d(te,r,`no container data: ${e}`),d(te,o>=0&&o<=r.length,`invalid block index: ${o}, ${r.length}`);const i=r[o];return r.splice(o,1),d(te,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onDeleteBlock)==null?void 0:l.call(s,e,o,!0)}),i}localInsertChildContainer(e,o){this.doc.blocks[e]=o,d(te,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(r=>{var i;return(i=r.onInsertChildContainer)==null?void 0:i.call(r,e,o,!0)})}localDeleteChildContainers(e){te.debug(`delete child containers: ${e}`),e.forEach(o=>{d(te,this.doc.blocks[o],`no child container: ${o}`),delete this.doc.blocks[o]}),e.forEach(o=>{d(te,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(r=>{var i;return(i=r.onDeleteChildContainer)==null?void 0:i.call(r,o,!0)})})}uploadResource(e,o){d(te,!1,"not implemented")}async addResources(e){return e}buildResourceUrl(e){return e}request(e,o){d(te,!1,"not implemented")}broadcastMessage(e){}getServerMeta(){return{serverId:this.serviceUrl}}getUser(){return{permission:"w",userId:"-",displayName:"-",avatarUrl:"-",rainbowIndex:0}}getRemoteUsers(){return new uc}setDoc(e){this.doc=Y.default(e),this.callbacks.forEach(o=>{var r;return(r=o.onRequestReload)==null?void 0:r.call(o,"change doc")})}destroy(){this.clearCallbacks()}}function po(n){return pt(H(n))}class cy{constructor(t){this.cleanup=t}destroy(){var t;(t=this.cleanup)==null||t.call(this)}}function Nu(n,t,e){n.addCustom(t,()=>{var i;const o=(i=e())!=null?i:void 0;return new cy(o)})}const ay=B("remote-cursor");class dy{constructor(){h(this,"remoteUsers",new uc)}onCustomMessage(t){const e=t;if(e.type==="onlineUsers"){const o=e;this.handleUpdateUsers(o.users)}else e.type==="caret"?this.handleUpdateCaret(e):ay.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 uy(n){const{blocks:t,meta:e,comments:o,...r}=n;return{rootBlocks:t,meta:e,comments:o,childBlocks:r}}function rs(n){const{childBlocks:t,meta:e,comments:o,rootBlocks:r}=uy(Y.default(n));return{blocks:{root:r,...t},meta:e,comments:o}}function Co(n){return n==="root"?"blocks":n}function Nr(n){return n==="blocks"?"root":n}const hy={type:{name:"rich-text",uri:"http://sharejs.org/types/rich-text/v1",create(n){return new oe.default(n)},apply(n,t){const e=new oe.default(n),o=new oe.default(t);return e.compose(o).ops},compose(n,t){const e=new oe.default(n),o=new oe.default(t);return e.compose(o).ops},diff(n,t){const e=new oe.default(n),o=new oe.default(t);return e.diff(o).ops},transform(n,t,e){const o=new oe.default(n);return new oe.default(t).transform(o,e==="left").ops},transformCursor(n,t,e){return t.transformPosition(n,!e)},normalize(n){return n},serialize(n){return n.ops},deserialize(n){return n},transformPresence(n,t,e){if(!n)return null;const o=new oe.default(t),r=this.transformCursor(n.index,o,e),i=this.transformCursor(n.index+n.length,o,e);return{...n,index:r,length:i-r}}}};var is=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},bo={},$u=Qf.default.EventEmitter;bo.EventEmitter=$u,bo.mixin=fy;function fy(n){for(var t in $u.prototype)n.prototype[t]=$u.prototype[t]}var d2=["info","warn","error"];function u2(){var n={};d2.forEach(function(t){n[t]=console[t].bind(console)}),this.setMethods(n)}var my=u2;u2.prototype.setMethods=function(n){n=n||{};var t=this;d2.forEach(function(e){typeof n[e]=="function"&&(t[e]=n[e])})};var gy=my,py=new gy,h2=py;function tr(n,t){this.code=n,this.message=t||"",Error.captureStackTrace?Error.captureStackTrace(this,tr):this.stack=new Error().stack}tr.prototype=Object.create(Error.prototype),tr.prototype.constructor=tr,tr.prototype.name="ShareDBError",tr.CODES={ERR_APPLY_OP_VERSION_DOES_NOT_MATCH_SNAPSHOT:"ERR_APPLY_OP_VERSION_DOES_NOT_MATCH_SNAPSHOT",ERR_APPLY_SNAPSHOT_NOT_PROVIDED:"ERR_APPLY_SNAPSHOT_NOT_PROVIDED",ERR_CLIENT_ID_BADLY_FORMED:"ERR_CLIENT_ID_BADLY_FORMED",ERR_CANNOT_PING_OFFLINE:"ERR_CANNOT_PING_OFFLINE",ERR_CONNECTION_SEQ_INTEGER_OVERFLOW:"ERR_CONNECTION_SEQ_INTEGER_OVERFLOW",ERR_CONNECTION_STATE_TRANSITION_INVALID:"ERR_CONNECTION_STATE_TRANSITION_INVALID",ERR_DATABASE_ADAPTER_NOT_FOUND:"ERR_DATABASE_ADAPTER_NOT_FOUND",ERR_DATABASE_DOES_NOT_SUPPORT_SUBSCRIBE:"ERR_DATABASE_DOES_NOT_SUPPORT_SUBSCRIBE",ERR_DATABASE_METHOD_NOT_IMPLEMENTED:"ERR_DATABASE_METHOD_NOT_IMPLEMENTED",ERR_DEFAULT_TYPE_MISMATCH:"ERR_DEFAULT_TYPE_MISMATCH",ERR_DOC_MISSING_VERSION:"ERR_DOC_MISSING_VERSION",ERR_DOC_ALREADY_CREATED:"ERR_DOC_ALREADY_CREATED",ERR_DOC_DOES_NOT_EXIST:"ERR_DOC_DOES_NOT_EXIST",ERR_DOC_TYPE_NOT_RECOGNIZED:"ERR_DOC_TYPE_NOT_RECOGNIZED",ERR_DOC_WAS_DELETED:"ERR_DOC_WAS_DELETED",ERR_INFLIGHT_OP_MISSING:"ERR_INFLIGHT_OP_MISSING",ERR_INGESTED_SNAPSHOT_HAS_NO_VERSION:"ERR_INGESTED_SNAPSHOT_HAS_NO_VERSION",ERR_MAX_SUBMIT_RETRIES_EXCEEDED:"ERR_MAX_SUBMIT_RETRIES_EXCEEDED",ERR_MESSAGE_BADLY_FORMED:"ERR_MESSAGE_BADLY_FORMED",ERR_MILESTONE_ARGUMENT_INVALID:"ERR_MILESTONE_ARGUMENT_INVALID",ERR_OP_ALREADY_SUBMITTED:"ERR_OP_ALREADY_SUBMITTED",ERR_OP_NOT_ALLOWED_IN_PROJECTION:"ERR_OP_NOT_ALLOWED_IN_PROJECTION",ERR_OP_SUBMIT_REJECTED:"ERR_OP_SUBMIT_REJECTED",ERR_OP_VERSION_MISMATCH_AFTER_TRANSFORM:"ERR_OP_VERSION_MISMATCH_AFTER_TRANSFORM",ERR_OP_VERSION_MISMATCH_DURING_TRANSFORM:"ERR_OP_VERSION_MISMATCH_DURING_TRANSFORM",ERR_OP_VERSION_NEWER_THAN_CURRENT_SNAPSHOT:"ERR_OP_VERSION_NEWER_THAN_CURRENT_SNAPSHOT",ERR_OT_LEGACY_JSON0_OP_CANNOT_BE_NORMALIZED:"ERR_OT_LEGACY_JSON0_OP_CANNOT_BE_NORMALIZED",ERR_OT_OP_BADLY_FORMED:"ERR_OT_OP_BADLY_FORMED",ERR_OT_OP_NOT_APPLIED:"ERR_OT_OP_NOT_APPLIED",ERR_OT_OP_NOT_PROVIDED:"ERR_OT_OP_NOT_PROVIDED",ERR_PRESENCE_TRANSFORM_FAILED:"ERR_PRESENCE_TRANSFORM_FAILED",ERR_PROTOCOL_VERSION_NOT_SUPPORTED:"ERR_PROTOCOL_VERSION_NOT_SUPPORTED",ERR_QUERY_EMITTER_LISTENER_NOT_ASSIGNED:"ERR_QUERY_EMITTER_LISTENER_NOT_ASSIGNED",ERR_SNAPSHOT_READ_SILENT_REJECTION:"ERR_SNAPSHOT_READ_SILENT_REJECTION",ERR_SNAPSHOT_READS_REJECTED:"ERR_SNAPSHOT_READS_REJECTED",ERR_SUBMIT_TRANSFORM_OPS_NOT_FOUND:"ERR_SUBMIT_TRANSFORM_OPS_NOT_FOUND",ERR_TYPE_CANNOT_BE_PROJECTED:"ERR_TYPE_CANNOT_BE_PROJECTED",ERR_TYPE_DOES_NOT_SUPPORT_PRESENCE:"ERR_TYPE_DOES_NOT_SUPPORT_PRESENCE",ERR_UNKNOWN_ERROR:"ERR_UNKNOWN_ERROR"};var hc=tr,ss={},f2=Cy;function Cy(n,t,e,o){var r=function(s,l,c,a){t(c,s,l,"left"),t(a,l,s,"right")},i=n.transformX=function(s,l){e(s),e(l);for(var c=[],a=0;a<l.length;a++){for(var u=l[a],f=[],m=0;m<s.length;){var C=[];if(r(s[m],u,f,C),m++,C.length===1)u=C[0];else if(C.length===0){for(var k=m;k<s.length;k++)o(f,s[k]);u=null;break}else{for(var w=i(s.slice(m),C),y=0;y<w[0].length;y++)o(f,w[0][y]);for(var S=0;S<w[1].length;S++)o(c,w[1][S]);u=null;break}}u!=null&&o(c,u),s=f}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"?i(s,l)[0]:i(l,s)[1]}}var m2={exports:{}},ko=m2.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||""}},Pu=function(n,t,e){return n.slice(0,t)+e+n.slice(t)},ju=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")},fc=function(n){for(var t=0;t<n.length;t++)ju(n[t])};ko.apply=function(n,t){var e;fc(t);for(var o=0;o<t.length;o++){var r=t[o];if(r.i!=null)n=Pu(n,r.p,r.i);else{if(e=n.slice(r.p,r.p+r.d.length),r.d!==e)throw new Error("Delete component '"+r.d+"' does not match deleted text '"+e+"'");n=n.slice(0,r.p)+n.slice(r.p+r.d.length)}}return n};var qn=ko._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:Pu(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:Pu(t.d,e.p-t.p,e.d),p:t.p}:n.push(t)}};ko.compose=function(n,t){fc(n),fc(t);for(var e=n.slice(),o=0;o<t.length;o++)qn(e,t[o]);return e},ko.normalize=function(n){var t=[];(n.i!=null||n.p!=null)&&(n=[n]);for(var e=0;e<n.length;e++){var o=n[e];o.p==null&&(o.p=0),qn(t,o)}return t};var Hu=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};ko.transformCursor=function(n,t,e){for(var o=e==="right",r=0;r<t.length;r++)n=Hu(n,t[r],o);return n};var by=ko._tc=function(n,t,e,o){if(ju(t),ju(e),t.i!=null)qn(n,{i:t.i,p:Hu(t.p,e,o==="right")});else if(e.i!=null){var r=t.d;t.p<e.p&&(qn(n,{d:r.slice(0,e.p-t.p),p:t.p}),r=r.slice(e.p-t.p)),r!==""&&qn(n,{d:r,p:t.p+e.i.length})}else if(t.p>=e.p+e.d.length)qn(n,{d:t.d,p:t.p-e.d.length});else if(t.p+t.d.length<=e.p)qn(n,t);else{var i={d:"",p:t.p};t.p<e.p&&(i.d=t.d.slice(0,e.p-t.p)),t.p+t.d.length>e.p+e.d.length&&(i.d+=t.d.slice(e.p+e.d.length-t.p));var s=Math.max(t.p,e.p),l=Math.min(t.p+t.d.length,e.p+e.d.length),c=t.d.slice(s-t.p,l-t.p),a=e.d.slice(s-e.p,l-e.p);if(c!==a)throw new Error("Delete ops delete different text in the same region of the document");i.d!==""&&(i.p=Hu(i.p,e),qn(n,i))}return n},ky=function(n){return n.i!=null?{d:n.i,p:n.p}:{i:n.d,p:n.p}};ko.invert=function(n){n=n.slice().reverse();for(var t=0;t<n.length;t++)n[t]=ky(n[t]);return n},f2(ko,by,fc,qn);var mc=function(n){return Object.prototype.toString.call(n)=="[object Array]"},vy=function(n){return!!n&&n.constructor===Object},on=function(n){return JSON.parse(JSON.stringify(n))},tt={name:"json0",uri:"http://sharejs.org/types/JSONv0"},Wn={};tt.registerSubtype=function(n){Wn[n.name]=n},tt.create=function(n){return n===void 0?null:on(n)},tt.invertComponent=function(n){var t={p:n.p};return n.t&&Wn[n.t]&&(t.t=n.t,t.o=Wn[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},tt.invert=function(n){for(var t=n.slice().reverse(),e=[],o=0;o<t.length;o++)e.push(tt.invertComponent(t[o]));return e},tt.checkValidOp=function(n){for(var t=0;t<n.length;t++)if(!mc(n[t].p))throw new Error("Missing path")},tt.checkList=function(n){if(!mc(n))throw new Error("Referenced element not a list")},tt.checkObj=function(n){if(!vy(n))throw new Error("Referenced element not an object (it was "+JSON.stringify(n)+")")};function ls(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 cs(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}tt.apply=function(n,t){tt.checkValidOp(t),t=on(t);for(var e={data:n},o=0;o<t.length;o++){var r=t[o];(r.si!=null||r.sd!=null)&&ls(r);for(var i=null,s=e,l="data",c=0;c<r.p.length;c++){var a=r.p[c];if(i=s,s=s[l],l=a,i==null)throw new Error("Path invalid")}if(r.t&&r.o!==void 0&&Wn[r.t])s[l]=Wn[r.t].apply(s[l],r.o);else if(r.na!==void 0){if(typeof s[l]!="number")throw new Error("Referenced element not a number");s[l]+=r.na}else if(r.li!==void 0&&r.ld!==void 0)tt.checkList(s),s[l]=r.li;else if(r.li!==void 0)tt.checkList(s),s.splice(l,0,r.li);else if(r.ld!==void 0)tt.checkList(s),s.splice(l,1);else if(r.lm!==void 0){if(tt.checkList(s),r.lm!=l){var u=s[l];s.splice(l,1),s.splice(r.lm,0,u)}}else if(r.oi!==void 0)tt.checkObj(s),s[l]=r.oi;else if(r.od!==void 0)tt.checkObj(s),delete s[l];else throw new Error("invalid / missing instruction in op")}return e.data},tt.shatter=function(n){for(var t=[],e=0;e<n.length;e++)t.push([n[e]]);return t},tt.incrementalApply=function(n,t,e){for(var o=0;o<t.length;o++){var r=[t[o]];n=tt.apply(n,r),e(r,n)}return n};var yy=tt.pathMatches=function(n,t,e){if(n.length!=t.length)return!1;for(var o=0;o<n.length;o++)if(n[o]!==t[o]&&(!e||o!==n.length-1))return!1;return!0};tt.append=function(n,t){if(t=on(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)&&(ls(t),ls(e)),yy(t.p,e.p))if(t.t&&e.t&&t.t===e.t&&Wn[t.t]){if(e.o=Wn[t.t].compose(e.o,t.o),t.si!=null||t.sd!=null){for(var o=t.p,r=0;r<e.o.length-1;r++)t.o=[e.o.pop()],t.p=o.slice(),cs(t),n.push(t);cs(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)&&(cs(t),cs(e)),n.push(t)},tt.compose=function(n,t){tt.checkValidOp(n),tt.checkValidOp(t);for(var e=on(n),o=0;o<t.length;o++)tt.append(e,t[o]);return e},tt.normalize=function(n){var t=[];n=mc(n)?n:[n];for(var e=0;e<n.length;e++){var o=n[e];o.p==null&&(o.p=[]),tt.append(t,o)}return t},tt.commonLengthForOps=function(n,t){var e=n.p.length,o=t.p.length;if((n.na!=null||n.t)&&e++,(t.na!=null||t.t)&&o++,e===0)return-1;if(o===0)return null;e--,o--;for(var r=0;r<e;r++){var i=n.p[r];if(r>=o||i!==t.p[r])return null}return e},tt.canOpAffectPath=function(n,t){return tt.commonLengthForOps({p:t},n)!=null},tt.transformComponent=function(n,t,e,o){t=on(t);var r=tt.commonLengthForOps(e,t),i=tt.commonLengthForOps(t,e),s=t.p.length,l=e.p.length;if((t.na!=null||t.t)&&s++,(e.na!=null||e.t)&&l++,i!=null&&l>s&&t.p[i]==e.p[i]){if(t.ld!==void 0){var c=on(e);c.p=c.p.slice(s),t.ld=tt.apply(on(t.ld),[c])}else if(t.od!==void 0){var c=on(e);c.p=c.p.slice(s),t.od=tt.apply(on(t.od),[c])}}if(r!=null){var a=s==l,c=e;if((t.si!=null||t.sd!=null)&&(e.si!=null||e.sd!=null)&&(ls(t),c=on(e),ls(c)),c.t&&Wn[c.t]){if(t.t&&t.t===c.t){var u=Wn[t.t].transform(t.o,c.o,o);if(t.si!=null||t.sd!=null)for(var f=t.p,m=0;m<u.length;m++)t.o=[u[m]],t.p=f.slice(),cs(t),tt.append(n,t);else(!mc(u)||u.length>0)&&(t.o=u,tt.append(n,t));return n}}else if(e.na===void 0){if(e.li!==void 0&&e.ld!==void 0){if(e.p[r]===t.p[r])if(a){if(t.ld!==void 0)if(t.li!==void 0&&o==="left")t.ld=on(e.li);else return n}else return n}else if(e.li!==void 0)t.li!==void 0&&t.ld===void 0&&a&&t.p[r]===e.p[r]?o==="right"&&t.p[r]++:e.p[r]<=t.p[r]&&t.p[r]++,t.lm!==void 0&&a&&e.p[r]<=t.lm&&t.lm++;else if(e.ld!==void 0){if(t.lm!==void 0&&a){if(e.p[r]===t.p[r])return n;var f=e.p[r],C=t.p[r],k=t.lm;(f<k||f===k&&C<k)&&t.lm--}if(e.p[r]<t.p[r])t.p[r]--;else if(e.p[r]===t.p[r]){if(l<s)return n;if(t.ld!==void 0)if(t.li!==void 0)delete t.ld;else return n}}else if(e.lm!==void 0)if(t.lm!==void 0&&s===l){var C=t.p[r],k=t.lm,w=e.p[r],y=e.lm;if(w!==y)if(C===w)if(o==="left")t.p[r]=y,C===k&&(t.lm=y);else return n;else C>w&&t.p[r]--,C>y?t.p[r]++:C===y&&w>y&&(t.p[r]++,C===k&&t.lm++),(k>w||k===w&&k>C)&&t.lm--,k>y?t.lm++:k===y&&(y>w&&k>C||y<w&&k<C?o==="right"&&t.lm++:k>C?t.lm++:k===w&&t.lm--)}else if(t.li!==void 0&&t.ld===void 0&&a){var C=e.p[r],k=e.lm;f=t.p[r],f>C&&t.p[r]--,f>k&&t.p[r]++}else{var C=e.p[r],k=e.lm;f=t.p[r],f===C?t.p[r]=k:(f>C&&t.p[r]--,(f>k||f===k&&C>k)&&t.p[r]++)}else if(e.oi!==void 0&&e.od!==void 0){if(t.p[r]===e.p[r])if(t.oi!==void 0&&a){if(o==="right")return n;t.od=e.oi}else return n}else if(e.oi!==void 0){if(t.oi!==void 0&&t.p[r]===e.p[r])if(o==="left")tt.append(n,{p:t.p,od:e.oi});else return n}else if(e.od!==void 0&&t.p[r]==e.p[r]){if(!a)return n;if(t.oi!==void 0)delete t.od;else return n}}}return tt.append(n,t),n},f2(tt,tt.transformComponent,tt.checkValidOp,tt.append);var wy=m2.exports;tt.registerSubtype(wy);var By=tt,Ey={type:By};(function(n){n.defaultType=Ey.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)})(ss);var rn={};(function(n){n.doNothing=t;function t(){}n.hasKeys=function(e){for(var o in e)return!0;return!1},n.isInteger=Number.isInteger||function(e){return typeof e=="number"&&isFinite(e)&&Math.floor(e)===e},n.isValidVersion=function(e){return e===null?!0:n.isInteger(e)&&e>=0},n.isValidTimestamp=function(e){return n.isValidVersion(e)},n.MAX_SAFE_INTEGER=9007199254740991,n.dig=function(){for(var e=arguments[0],o=1;o<arguments.length;o++){var r=arguments[o];e=e[r]||(o===arguments.length-1?void 0:{})}return e},n.digOrCreate=function(){for(var e=arguments[0],o=arguments[arguments.length-1],r=1;r<arguments.length-1;r++){var i=arguments[r];e=e[i]||(e[i]=r===arguments.length-2?o():{})}return e},n.digAndRemove=function(){for(var e=arguments[0],o=[e],r=1;r<arguments.length-1;r++){var i=arguments[r];if(!e.hasOwnProperty(i))break;e=e[i],o.push(e)}for(var r=o.length-1;r>=0;r--){var s=o[r],i=arguments[r+1],l=s[i];(r===o.length-1||!n.hasKeys(l))&&delete s[i]}},n.supportsPresence=function(e){return e&&typeof e.transformPresence=="function"},n.callEach=function(e,o){var r=!1;return e.forEach(function(i){i&&(i(o),r=!0)}),r},n.truthy=function(e){return!!e},n.nextTick=function(e){if(typeof process<"u"&&process.nextTick)return process.nextTick.apply(null,arguments);for(var o=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];setTimeout(function(){e.apply(null,o)})},n.clone=function(e){return e===void 0?void 0:JSON.parse(JSON.stringify(e))}})(rn);var g2=Array.isArray,p2=Object.keys,Iy=Object.prototype.hasOwnProperty,xy=function n(t,e){if(t===e)return!0;if(t&&e&&typeof t=="object"&&typeof e=="object"){var o=g2(t),r=g2(e),i,s,l;if(o&&r){if(s=t.length,s!=e.length)return!1;for(i=s;i--!==0;)if(!n(t[i],e[i]))return!1;return!0}if(o!=r)return!1;var c=t instanceof Date,a=e instanceof Date;if(c!=a)return!1;if(c&&a)return t.getTime()==e.getTime();var u=t instanceof RegExp,f=e instanceof RegExp;if(u!=f)return!1;if(u&&f)return t.toString()==e.toString();var m=p2(t);if(s=m.length,s!==p2(e).length)return!1;for(i=s;i--!==0;)if(!Iy.call(e,m[i]))return!1;for(i=s;i--!==0;)if(l=m[i],!n(t[l],e[l]))return!1;return!0}return t!==t&&e!==e},C2=bo,Ty=h2,Le=hc,gc=ss,sn=rn,Sy=sn.clone,Dy=xy,ye=Le.CODES,Ly=lt;function lt(n,t,e){C2.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}C2.mixin(lt),lt.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())})},lt.prototype._setType=function(n){if(typeof n=="string"&&(n=gc.map[n]),n)this.type=n;else if(n===null)this.type=n,this._setData(void 0);else{var t=new Le(ye.ERR_DOC_TYPE_NOT_RECOGNIZED,"Missing type "+n);return this.emit("error",t)}},lt.prototype._setData=function(n){this.data=n,this._dataStateVersion++},lt.prototype.ingestSnapshot=function(n,t){if(!n)return t&&t();if(typeof n.v!="number"){var e=new Le(ye.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 Le(ye.ERR_DOC_MISSING_VERSION,"Cannot ingest snapshot in doc with null version. "+this.collection+"."+this.id);return t?t(e):this.emit("error",e)}return n.v>this.version?this.fetch(t):t&&t()}if(this.version>n.v)return t&&t();this.version=n.v;var o=n.type===void 0?gc.defaultType:n.type;this._setType(o),this._setData(this.type&&this.type.deserialize?this.type.deserialize(n.data):n.data),this.emit("load"),t&&t()},lt.prototype.whenNothingPending=function(n){var t=this;sn.nextTick(function(){if(t.hasPending()){t.once("nothing pending",n);return}n()})},lt.prototype.hasPending=function(){return!!(this.inflightOp||this.pendingOps.length||this.inflightFetch.length||this.inflightSubscribe||this.pendingFetch.length||this.pendingSubscribe.length)},lt.prototype.hasWritePending=function(){return!!(this.inflightOp||this.pendingOps.length)},lt.prototype._emitNothingPending=function(){this.hasWritePending()||(this.emit("no write pending"),!this.hasPending()&&this.emit("nothing pending"))},lt.prototype._emitResponseError=function(n,t){if(n&&n.code===ye.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)},lt.prototype._handleFetch=function(n,t){var e=this.pendingFetch;this.pendingFetch=[];var o=this.inflightFetch.shift();if(o&&e.push(o),e.length&&(o=function(r){sn.callEach(e,r)}),n)return this._emitResponseError(n,o);this.ingestSnapshot(t,o),this._emitNothingPending()},lt.prototype._handleSubscribe=function(n,t){var e=this.inflightSubscribe;this.inflightSubscribe=null;var o=this.pendingFetch;this.pendingFetch=[],e.callback&&o.push(e.callback);var r;if(o.length&&(r=function(i){sn.callEach(o,i)}),n)return this._emitResponseError(n,r);this.subscribed=e.wantSubscribe,this.subscribed?this.ingestSnapshot(t,r):r&&r(),this._emitNothingPending(),this._flushSubscribe()},lt.prototype._handleOp=function(n,t){if(n)return this.inflightOp?(n.code===ye.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=pc(this.inflightOp,t);if(e)return this._hardRollback(e)}for(var o=0;o<this.pendingOps.length;o++){var e=pc(this.pendingOps[o],t);if(e)return this._hardRollback(e)}this.version++;try{this._otApply(t,!1)}catch(r){return this._hardRollback(r)}}},lt.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))},lt.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()},lt.prototype.fetch=function(n){if(this.connection.canSend){var t=this.connection.sendFetch(this);My(this.inflightFetch,t,n);return}this.pendingFetch.push(n)},lt.prototype.subscribe=function(n){var t=!0;this._queueSubscribe(t,n)},lt.prototype.unsubscribe=function(n){var t=!1;this._queueSubscribe(t,n)},lt.prototype._queueSubscribe=function(n,t){var e=this.pendingSubscribe[this.pendingSubscribe.length-1]||this.inflightSubscribe,o=e&&e.wantSubscribe===n;if(o){e.callback=Ry([e.callback,t]);return}this.pendingSubscribe.push({wantSubscribe:!!n,callback:t}),this._flushSubscribe()},lt.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;sn.nextTick(function(){n._handleSubscribe()})}}};function My(n,t,e){if(t){var o=n.pop();n.push(function(r){o&&o(r),e&&e(r)})}else n.push(e)}function Ry(n){return n=n.filter(sn.truthy),n.length?function(t){sn.callEach(n,t)}:null}lt.prototype.flush=function(){!this.connection.canSend||this.inflightOp||!this.paused&&this.pendingOps.length&&this._sendOp()};function Ay(n){delete n.op,delete n.create,delete n.del}function pc(n,t){if(n.del)return Ay(t);if(t.del)return new Le(ye.ERR_DOC_WAS_DELETED,"Document was deleted");if(t.create)return new Le(ye.ERR_DOC_ALREADY_CREATED,"Document already created");if("op"in t){if(n.create)return new Le(ye.ERR_DOC_ALREADY_CREATED,"Document already created");if(n.type.transformX){var e=n.type.transformX(n.op,t.op);n.op=e[0],t.op=e[1]}else{var o=n.type.transform(n.op,t.op,"left"),r=n.type.transform(t.op,n.op,"right");n.op=o,t.op=r}}}lt.prototype._otApply=function(n,t){if("op"in n){if(!this.type)throw new Le(ye.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===gc.defaultType&&n.op.length>1){this.applyStack||(this.applyStack=[]);for(var e=this.applyStack.length,o=0;o<n.op.length;o++){var r=n.op[o],i={op:[r]};this.emit("before op",i.op,t,n.src);for(var s=e;s<this.applyStack.length;s++){var l=pc(this.applyStack[s],i);if(l)return this._hardRollback(l)}this._setData(this.type.apply(this.data,i.op)),this.emit("op",i.op,t,n.src)}this.emit("op batch",n.op,t),this._popApplyStack(e);return}this.emit("before op",n.op,t,n.src),this._setData(this.type.apply(this.data,n.op)),this.emit("op",n.op,t,n.src),this.emit("op batch",n.op,t);return}if(n.create){this._setType(n.create.type),this.type.deserialize?this.type.createDeserialized?this._setData(this.type.createDeserialized(n.create.data)):this._setData(this.type.deserialize(this.type.create(n.create.data))):this._setData(this.type.create(n.create.data)),this.emit("create",t);return}if(n.del){var c=this.data;this._setType(null),this.emit("del",c,t);return}},lt.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 Le(ye.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>=sn.MAX_SAFE_INTEGER)return this.emit("error",new Le(ye.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)}},lt.prototype._submit=function(n,t,e){if(t||(t=!0),"op"in n){if(!this.type){var o=new Le(ye.ERR_DOC_DOES_NOT_EXIST,"Cannot submit op. Document has not been created. "+this.collection+"."+this.id);return e?e(o):this.emit("error",o)}this.type.normalize&&(n.op=this.type.normalize(n.op))}try{this._pushOp(n,t,e),this._otApply(n,t)}catch(i){return this._hardRollback(i)}var r=this;sn.nextTick(function(){r.flush()})},lt.prototype._pushOp=function(n,t,e){if(n.source=t,this.applyStack)this.applyStack.push(n);else{var o=this._tryCompose(n);if(o){o.callbacks.push(e);return}}n.type=this.type,n.callbacks=[e],this.pendingOps.push(n)},lt.prototype._popApplyStack=function(n){if(n>0){this.applyStack.length=n;return}var t=this.applyStack[0];if(this.applyStack=null,!!t){var e=this.pendingOps.indexOf(t);if(e!==-1)for(var o=this.pendingOps.splice(e),e=0;e<o.length;e++){var t=o[e],r=this._tryCompose(t);r?r.callbacks=r.callbacks.concat(t.callbacks):this.pendingOps.push(t)}}},lt.prototype._tryCompose=function(n){if(!this.preventCompose){var t=this.pendingOps[this.pendingOps.length-1];if(!(!t||t.sentAt)&&!(this.submitSource&&!Dy(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}}},lt.prototype.submitOp=function(n,t,e){typeof t=="function"&&(e=t,t=null);var o={op:n},r=t&&t.source;this._submit(o,r,e)},lt.prototype.create=function(n,t,e,o){if(typeof t=="function"?(o=t,e=null,t=null):typeof e=="function"&&(o=e,e=null),t||(t=gc.defaultType.uri),this.type){var r=new Le(ye.ERR_DOC_ALREADY_CREATED,"Document already exists");return o?o(r):this.emit("error",r)}var i={create:{type:t,data:n}},s=e&&e.source;this._submit(i,s,o)},lt.prototype.del=function(n,t){if(typeof n=="function"&&(t=n,n=null),!this.type){var e=new Le(ye.ERR_DOC_DOES_NOT_EXIST,"Document does not exist");return t?t(e):this.emit("error",e)}var o={del:!0},r=n&&n.source;this._submit(o,r,t)},lt.prototype.pause=function(){this.paused=!0},lt.prototype.resume=function(){this.paused=!1,this.flush()},lt.prototype.toSnapshot=function(){return{v:this.version,data:Sy(this.data),type:this.type.uri}},lt.prototype._opAcknowledged=function(n){if(this.inflightOp.create)this.version=n.v;else if(n.v!==this.version)return Ty.warn("Invalid version from server. Expected: "+this.version+" Received: "+n.v,n),this.fetch();this.version++,this._clearInflightOp()},lt.prototype._rollback=function(n){var t=this.inflightOp;if("op"in t&&t.type.invert){try{t.op=t.type.invert(t.op)}catch{return this._hardRollback(n)}for(var e=0;e<this.pendingOps.length;e++){var o=pc(this.pendingOps[e],t);if(o)return this._hardRollback(o)}try{this._otApply(t,!1)}catch(r){return this._hardRollback(r)}this._clearInflightOp(n);return}this._hardRollback(n)},lt.prototype._hardRollback=function(n){var t=[];this.inflightOp&&t.push(this.inflightOp),t=t.concat(this.pendingOps),this._setType(null),this.version=null,this.inflightOp=null,this.pendingOps=[];var e=this;this.fetch(function(){for(var o=!!t.length,r=0;r<t.length;r++)o=sn.callEach(t[r].callbacks,n)&&o;if(n&&!o)return e.emit("error",n)})},lt.prototype._clearInflightOp=function(n){var t=this.inflightOp;this.inflightOp=null;var e=sn.callEach(t.callbacks,n);if(this.flush(),this._emitNothingPending(),n&&!e)return this.emit("error",n)};var er={};er.ACTIONS={initLegacy:"init",handshake:"hs",queryFetch:"qf",querySubscribe:"qs",queryUnsubscribe:"qu",queryUpdate:"q",bulkFetch:"bf",bulkSubscribe:"bs",bulkUnsubscribe:"bu",fetch:"f",subscribe:"s",unsubscribe:"u",op:"op",snapshotFetch:"nf",snapshotFetchByTimestamp:"nt",pingPong:"pp",presence:"p",presenceSubscribe:"ps",presenceUnsubscribe:"pu",presenceRequest:"pr"};var b2=bo,k2=er.ACTIONS,Oy=rn,_y=we;function we(n,t,e,o,r,i,s){b2.EventEmitter.call(this),this.action=n,this.connection=t,this.id=e,this.collection=o,this.query=r,this.results=null,i&&i.results&&(this.results=i.results,delete i.results),this.extra=void 0,this.options=i,this.callback=s,this.ready=!1,this.sent=!1}b2.mixin(we),we.prototype.hasPending=function(){return!this.ready},we.prototype.send=function(){if(!!this.connection.canSend){var n={a:this.action,id:this.id,c:this.collection,q:this.query};if(this.options&&(n.o=this.options),this.results){for(var t=[],e=0;e<this.results.length;e++){var o=this.results[e];t.push([o.id,o.version])}n.r=t}this.connection.send(n),this.sent=!0}},we.prototype.destroy=function(n){this.connection.canSend&&this.action===k2.querySubscribe&&this.connection.send({a:k2.queryUnsubscribe,id:this.id}),this.connection._destroyQuery(this),n&&Oy.nextTick(n)},we.prototype._onConnectionStateChanged=function(){this.connection.canSend&&!this.sent?this.send():this.sent=!1},we.prototype._handleFetch=function(n,t,e){this.connection._destroyQuery(this),this._handleResponse(n,t,e)},we.prototype._handleSubscribe=function(n,t,e){this._handleResponse(n,t,e)},we.prototype._handleResponse=function(n,t,e){var o=this.callback;if(this.callback=null,n)return this._finishResponse(n,o);if(!t)return this._finishResponse(null,o);var r=this,i=1,s=function(u){if(u)return r._finishResponse(u,o);--i||r._finishResponse(null,o)};if(Array.isArray(t))i+=t.length,this.results=this._ingestSnapshots(t,s),this.extra=e;else for(var l in t){i++;var c=t[l],a=this.connection.get(c.c||this.collection,l);a.ingestSnapshot(c,s)}s()},we.prototype._ingestSnapshots=function(n,t){for(var e=[],o=0;o<n.length;o++){var r=n[o],i=this.connection.get(r.c||this.collection,r.d);i.ingestSnapshot(r,t),e.push(i)}return e},we.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)},we.prototype._handleError=function(n){this.emit("error",n)},we.prototype._handleDiff=function(n){for(var t=0;t<n.length;t++){var e=n[t];e.type==="insert"&&(e.values=this._ingestSnapshots(e.values))}for(var t=0;t<n.length;t++){var e=n[t];switch(e.type){case"insert":var o=e.values;Array.prototype.splice.apply(this.results,[e.index,0].concat(o)),this.emit("insert",o,e.index);break;case"remove":var i=e.howMany||1,r=this.results.splice(e.index,i);this.emit("remove",r,e.index);break;case"move":var i=e.howMany||1,s=this.results.splice(e.from,i);Array.prototype.splice.apply(this.results,[e.to,0].concat(s)),this.emit("move",s,e.from,e.to);break}}this.emit("changed",this.results)},we.prototype._handleExtra=function(n){this.extra=n,this.emit("extra",n)};var v2=bo,Ny=er.ACTIONS,$y=rn,y2=En;function En(n,t){if(v2.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={}}v2.mixin(En),En.prototype.submit=function(n,t){this.value=n,this.send(t)},En.prototype.send=function(n){var t=this._message();this._pendingMessages.push(t),this._callbacksByPresenceVersion[t.pv]=n,this._sendPending()},En.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()})},En.prototype._sendPending=function(){if(!!this.connection.canSend){var n=this;this._pendingMessages.forEach(function(t){n.connection.send(t)}),this._pendingMessages=[]}},En.prototype._ack=function(n,t){var e=this._getCallback(t);this._callbackOrEmit(n,e)},En.prototype._message=function(){return{a:Ny.presence,ch:this.presence.channel,id:this.presenceId,p:this.value,pv:this.presenceVersion++}},En.prototype._getCallback=function(n){var t=this._callbacksByPresenceVersion[n];return delete this._callbacksByPresenceVersion[n],t},En.prototype._callbackOrEmit=function(n,t){if(t)return $y.nextTick(t,n);n&&this.emit("error",n)};var Py=rn,w2=Fu;function Fu(n,t){this.presence=n,this.presenceId=t,this.connection=this.presence.connection,this.value=null,this.presenceVersion=0}Fu.prototype.receiveUpdate=function(n){n.pv<this.presenceVersion||(this.value=n.p,this.presenceVersion=n.pv,this.presence._updateRemotePresence(this))},Fu.prototype.destroy=function(n){delete this.presence._remotePresenceInstances[this.presenceId],delete this.presence.remotePresences[this.presenceId],n&&Py.nextTick(n)};var zu={exports:{}};(function(n,t){(function(e,o){o(t)})(is,function(e){function o(p,v){v=v|0;for(var E=Math.max(p.length-v,0),x=Array(E),L=0;L<E;L++)x[L]=p[v+L];return x}var r=function(p){var v=o(arguments,1);return function(){var E=o(arguments);return p.apply(null,v.concat(E))}},i=function(p){return function(){var v=o(arguments),E=v.pop();p.call(this,v,E)}};function s(p){var v=typeof p;return p!=null&&(v=="object"||v=="function")}var l=typeof setImmediate=="function"&&setImmediate,c=typeof process=="object"&&typeof process.nextTick=="function";function a(p){setTimeout(p,0)}function u(p){return function(v){var E=o(arguments,1);p(function(){v.apply(null,E)})}}var f;l?f=setImmediate:c?f=process.nextTick:f=a;var m=u(f);function C(p){return i(function(v,E){var x;try{x=p.apply(this,v)}catch(L){return E(L)}s(x)&&typeof x.then=="function"?x.then(function(L){k(E,null,L)},function(L){k(E,L.message?L:new Error(L))}):E(null,x)})}function k(p,v,E){try{p(v,E)}catch(x){m(w,x)}}function w(p){throw p}var y=typeof Symbol=="function";function S(p){return y&&p[Symbol.toStringTag]==="AsyncFunction"}function I(p){return S(p)?C(p):p}function M(p){return function(v){var E=o(arguments,1),x=i(function(L,D){var O=this;return p(v,function(_,V){I(_).apply(O,L.concat(V))},D)});return E.length?x.apply(this,E):x}}var R=typeof is=="object"&&is&&is.Object===Object&&is,$=typeof self=="object"&&self&&self.Object===Object&&self,Z=R||$||Function("return this")(),rt=Z.Symbol,st=Object.prototype,mt=st.hasOwnProperty,ut=st.toString,yt=rt?rt.toStringTag:void 0;function le(p){var v=mt.call(p,yt),E=p[yt];try{p[yt]=void 0;var x=!0}catch{}var L=ut.call(p);return x&&(v?p[yt]=E:delete p[yt]),L}var eo=Object.prototype,ee=eo.toString;function Ue(p){return ee.call(p)}var Do="[object Null]",pr="[object Undefined]",Cr=rt?rt.toStringTag:void 0;function Lo(p){return p==null?p===void 0?pr:Do:Cr&&Cr in Object(p)?le(p):Ue(p)}var xa="[object AsyncFunction]",jP="[object Function]",HP="[object GeneratorFunction]",FP="[object Proxy]";function zP(p){if(!s(p))return!1;var v=Lo(p);return v==jP||v==HP||v==xa||v==FP}var UP=9007199254740991;function NC(p){return typeof p=="number"&&p>-1&&p%1==0&&p<=UP}function ol(p){return p!=null&&NC(p.length)&&!zP(p)}var Df={};function ht(){}function Mo(p){return function(){if(p!==null){var v=p;p=null,v.apply(this,arguments)}}}var Lf=typeof Symbol=="function"&&Symbol.iterator,VP=function(p){return Lf&&p[Lf]&&p[Lf]()};function qP(p,v){for(var E=-1,x=Array(p);++E<p;)x[E]=v(E);return x}function Ta(p){return p!=null&&typeof p=="object"}var WP="[object Arguments]";function $C(p){return Ta(p)&&Lo(p)==WP}var PC=Object.prototype,GP=PC.hasOwnProperty,ZP=PC.propertyIsEnumerable,YP=$C(function(){return arguments}())?$C:function(p){return Ta(p)&&GP.call(p,"callee")&&!ZP.call(p,"callee")},gn=Array.isArray;function QP(){return!1}var jC=typeof e=="object"&&e&&!e.nodeType&&e,HC=jC&&!0&&n&&!n.nodeType&&n,KP=HC&&HC.exports===jC,FC=KP?Z.Buffer:void 0,JP=FC?FC.isBuffer:void 0,XP=JP||QP,tj=9007199254740991,ej=/^(?:0|[1-9]\d*)$/;function nj(p,v){var E=typeof p;return v=v==null?tj:v,!!v&&(E=="number"||E!="symbol"&&ej.test(p))&&p>-1&&p%1==0&&p<v}var oj="[object Arguments]",rj="[object Array]",ij="[object Boolean]",sj="[object Date]",lj="[object Error]",cj="[object Function]",aj="[object Map]",dj="[object Number]",uj="[object Object]",hj="[object RegExp]",fj="[object Set]",mj="[object String]",gj="[object WeakMap]",pj="[object ArrayBuffer]",Cj="[object DataView]",bj="[object Float32Array]",kj="[object Float64Array]",vj="[object Int8Array]",yj="[object Int16Array]",wj="[object Int32Array]",Bj="[object Uint8Array]",Ej="[object Uint8ClampedArray]",Ij="[object Uint16Array]",xj="[object Uint32Array]",Bt={};Bt[bj]=Bt[kj]=Bt[vj]=Bt[yj]=Bt[wj]=Bt[Bj]=Bt[Ej]=Bt[Ij]=Bt[xj]=!0,Bt[oj]=Bt[rj]=Bt[pj]=Bt[ij]=Bt[Cj]=Bt[sj]=Bt[lj]=Bt[cj]=Bt[aj]=Bt[dj]=Bt[uj]=Bt[hj]=Bt[fj]=Bt[mj]=Bt[gj]=!1;function Tj(p){return Ta(p)&&NC(p.length)&&!!Bt[Lo(p)]}function Sj(p){return function(v){return p(v)}}var zC=typeof e=="object"&&e&&!e.nodeType&&e,rl=zC&&!0&&n&&!n.nodeType&&n,Dj=rl&&rl.exports===zC,Mf=Dj&&R.process,UC=function(){try{var p=rl&&rl.require&&rl.require("util").types;return p||Mf&&Mf.binding&&Mf.binding("util")}catch{}}(),VC=UC&&UC.isTypedArray,Lj=VC?Sj(VC):Tj,Mj=Object.prototype,Rj=Mj.hasOwnProperty;function Aj(p,v){var E=gn(p),x=!E&&YP(p),L=!E&&!x&&XP(p),D=!E&&!x&&!L&&Lj(p),O=E||x||L||D,_=O?qP(p.length,String):[],V=_.length;for(var Q in p)(v||Rj.call(p,Q))&&!(O&&(Q=="length"||L&&(Q=="offset"||Q=="parent")||D&&(Q=="buffer"||Q=="byteLength"||Q=="byteOffset")||nj(Q,V)))&&_.push(Q);return _}var Oj=Object.prototype;function _j(p){var v=p&&p.constructor,E=typeof v=="function"&&v.prototype||Oj;return p===E}function Nj(p,v){return function(E){return p(v(E))}}var $j=Nj(Object.keys,Object),Pj=Object.prototype,jj=Pj.hasOwnProperty;function Hj(p){if(!_j(p))return $j(p);var v=[];for(var E in Object(p))jj.call(p,E)&&E!="constructor"&&v.push(E);return v}function Rf(p){return ol(p)?Aj(p):Hj(p)}function Fj(p){var v=-1,E=p.length;return function(){return++v<E?{value:p[v],key:v}:null}}function zj(p){var v=-1;return function(){var x=p.next();return x.done?null:(v++,{value:x.value,key:v})}}function Uj(p){var v=Rf(p),E=-1,x=v.length;return function L(){var D=v[++E];return D==="__proto__"?L():E<x?{value:p[D],key:D}:null}}function Vj(p){if(ol(p))return Fj(p);var v=VP(p);return v?zj(v):Uj(p)}function On(p){return function(){if(p===null)throw new Error("Callback was already called.");var v=p;p=null,v.apply(this,arguments)}}function Sa(p){return function(v,E,x){if(x=Mo(x||ht),p<=0||!v)return x(null);var L=Vj(v),D=!1,O=0,_=!1;function V(G,X){if(O-=1,G)D=!0,x(G);else{if(X===Df||D&&O<=0)return D=!0,x(null);_||Q()}}function Q(){for(_=!0;O<p&&!D;){var G=L();if(G===null){D=!0,O<=0&&x(null);return}O+=1,E(G.value,G.key,On(V))}_=!1}Q()}}function br(p,v,E,x){Sa(v)(p,I(E),x)}function ne(p,v){return function(E,x,L){return p(E,v,x,L)}}function qj(p,v,E){E=Mo(E||ht);var x=0,L=0,D=p.length;D===0&&E(null);function O(_,V){_?E(_):(++L===D||V===Df)&&E(null)}for(;x<D;x++)v(p[x],x,On(O))}var Wj=ne(br,1/0),Ro=function(p,v,E){var x=ol(p)?qj:Wj;x(p,I(v),E)};function ki(p){return function(v,E,x){return p(Ro,v,I(E),x)}}function qC(p,v,E,x){x=x||ht,v=v||[];var L=[],D=0,O=I(E);p(v,function(_,V,Q){var G=D++;O(_,function(X,Et){L[G]=Et,Q(X)})},function(_){x(_,L)})}var Da=ki(qC),WC=M(Da);function vi(p){return function(v,E,x,L){return p(Sa(E),v,I(x),L)}}var yi=vi(qC),Af=ne(yi,1),GC=M(Af);function La(p,v){for(var E=-1,x=p==null?0:p.length;++E<x&&v(p[E],E,p)!==!1;);return p}function Gj(p){return function(v,E,x){for(var L=-1,D=Object(v),O=x(v),_=O.length;_--;){var V=O[p?_:++L];if(E(D[V],V,D)===!1)break}return v}}var Zj=Gj();function il(p,v){return p&&Zj(p,v,Rf)}function Yj(p,v,E,x){for(var L=p.length,D=E+(x?1:-1);x?D--:++D<L;)if(v(p[D],D,p))return D;return-1}function Qj(p){return p!==p}function Kj(p,v,E){for(var x=E-1,L=p.length;++x<L;)if(p[x]===v)return x;return-1}function Ma(p,v,E){return v===v?Kj(p,v,E):Yj(p,Qj,E)}var Of=function(p,v,E){typeof v=="function"&&(E=v,v=null),E=Mo(E||ht);var x=Rf(p),L=x.length;if(!L)return E(null);v||(v=L);var D={},O=0,_=!1,V=Object.create(null),Q=[],G=[],X={};il(p,function(Dt,Lt){if(!gn(Dt)){Et(Lt,[Dt]),G.push(Lt);return}var Jt=Dt.slice(0,Dt.length-1),no=Jt.length;if(no===0){Et(Lt,Dt),G.push(Lt);return}X[Lt]=no,La(Jt,function(Ii){if(!p[Ii])throw new Error("async.auto task `"+Lt+"` has a non-existent dependency `"+Ii+"` in "+Jt.join(", "));_n(Ii,function(){no--,no===0&&Et(Lt,Dt)})})}),UH(),ce();function Et(Dt,Lt){Q.push(function(){Nn(Dt,Lt)})}function ce(){if(Q.length===0&&O===0)return E(null,D);for(;Q.length&&O<v;){var Dt=Q.shift();Dt()}}function _n(Dt,Lt){var Jt=V[Dt];Jt||(Jt=V[Dt]=[]),Jt.push(Lt)}function Ve(Dt){var Lt=V[Dt]||[];La(Lt,function(Jt){Jt()}),ce()}function Nn(Dt,Lt){if(!_){var Jt=On(function(Ii,Wf){if(O--,arguments.length>2&&(Wf=o(arguments,1)),Ii){var Gf={};il(D,function(qH,WH){Gf[WH]=qH}),Gf[Dt]=Wf,_=!0,V=Object.create(null),E(Ii,Gf)}else D[Dt]=Wf,Ve(Dt)});O++;var no=I(Lt[Lt.length-1]);Lt.length>1?no(D,Jt):no(Jt)}}function UH(){for(var Dt,Lt=0;G.length;)Dt=G.pop(),Lt++,La(VH(Dt),function(Jt){--X[Jt]===0&&G.push(Jt)});if(Lt!==L)throw new Error("async.auto cannot execute tasks due to a recursive dependency")}function VH(Dt){var Lt=[];return il(p,function(Jt,no){gn(Jt)&&Ma(Jt,Dt,0)>=0&&Lt.push(no)}),Lt}};function wi(p,v){for(var E=-1,x=p==null?0:p.length,L=Array(x);++E<x;)L[E]=v(p[E],E,p);return L}var Jj="[object Symbol]";function Xj(p){return typeof p=="symbol"||Ta(p)&&Lo(p)==Jj}var tH=1/0,ZC=rt?rt.prototype:void 0,YC=ZC?ZC.toString:void 0;function _f(p){if(typeof p=="string")return p;if(gn(p))return wi(p,_f)+"";if(Xj(p))return YC?YC.call(p):"";var v=p+"";return v=="0"&&1/p==-tH?"-0":v}function eH(p,v,E){var x=-1,L=p.length;v<0&&(v=-v>L?0:L+v),E=E>L?L:E,E<0&&(E+=L),L=v>E?0:E-v>>>0,v>>>=0;for(var D=Array(L);++x<L;)D[x]=p[x+v];return D}function nH(p,v,E){var x=p.length;return E=E===void 0?x:E,!v&&E>=x?p:eH(p,v,E)}function oH(p,v){for(var E=p.length;E--&&Ma(v,p[E],0)>-1;);return E}function rH(p,v){for(var E=-1,x=p.length;++E<x&&Ma(v,p[E],0)>-1;);return E}function iH(p){return p.split("")}var sH="\\ud800-\\udfff",lH="\\u0300-\\u036f",cH="\\ufe20-\\ufe2f",aH="\\u20d0-\\u20ff",dH=lH+cH+aH,uH="\\ufe0e\\ufe0f",hH="\\u200d",fH=RegExp("["+hH+sH+dH+uH+"]");function mH(p){return fH.test(p)}var QC="\\ud800-\\udfff",gH="\\u0300-\\u036f",pH="\\ufe20-\\ufe2f",CH="\\u20d0-\\u20ff",bH=gH+pH+CH,kH="\\ufe0e\\ufe0f",vH="["+QC+"]",Nf="["+bH+"]",$f="\\ud83c[\\udffb-\\udfff]",yH="(?:"+Nf+"|"+$f+")",KC="[^"+QC+"]",JC="(?:\\ud83c[\\udde6-\\uddff]){2}",XC="[\\ud800-\\udbff][\\udc00-\\udfff]",wH="\\u200d",t9=yH+"?",e9="["+kH+"]?",BH="(?:"+wH+"(?:"+[KC,JC,XC].join("|")+")"+e9+t9+")*",EH=e9+t9+BH,IH="(?:"+[KC+Nf+"?",Nf,JC,XC,vH].join("|")+")",xH=RegExp($f+"(?="+$f+")|"+IH+EH,"g");function TH(p){return p.match(xH)||[]}function n9(p){return mH(p)?TH(p):iH(p)}function SH(p){return p==null?"":_f(p)}var DH=/^\s+|\s+$/g;function LH(p,v,E){if(p=SH(p),p&&(E||v===void 0))return p.replace(DH,"");if(!p||!(v=_f(v)))return p;var x=n9(p),L=n9(v),D=rH(x,L),O=oH(x,L)+1;return nH(x,D,O).join("")}var MH=/^(?:async\s+)?(function)?\s*[^\(]*\(\s*([^\)]*)\)/m,RH=/,/,AH=/(=.+)?(\s*)$/,OH=/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;function _H(p){return p=p.toString().replace(OH,""),p=p.match(MH)[2].replace(" ",""),p=p?p.split(RH):[],p=p.map(function(v){return LH(v.replace(AH,""))}),p}function o9(p,v){var E={};il(p,function(x,L){var D,O=S(x),_=!O&&x.length===1||O&&x.length===0;if(gn(x))D=x.slice(0,-1),x=x[x.length-1],E[L]=D.concat(D.length>0?V:x);else if(_)E[L]=x;else{if(D=_H(x),x.length===0&&!O&&D.length===0)throw new Error("autoInject task functions require explicit parameters.");O||D.pop(),E[L]=D.concat(V)}function V(Q,G){var X=wi(D,function(Et){return Q[Et]});X.push(G),I(x).apply(null,X)}}),Of(E,v)}function pn(){this.head=this.tail=null,this.length=0}function r9(p,v){p.length=1,p.head=p.tail=v}pn.prototype.removeLink=function(p){return p.prev?p.prev.next=p.next:this.head=p.next,p.next?p.next.prev=p.prev:this.tail=p.prev,p.prev=p.next=null,this.length-=1,p},pn.prototype.empty=function(){for(;this.head;)this.shift();return this},pn.prototype.insertAfter=function(p,v){v.prev=p,v.next=p.next,p.next?p.next.prev=v:this.tail=v,p.next=v,this.length+=1},pn.prototype.insertBefore=function(p,v){v.prev=p.prev,v.next=p,p.prev?p.prev.next=v:this.head=v,p.prev=v,this.length+=1},pn.prototype.unshift=function(p){this.head?this.insertBefore(this.head,p):r9(this,p)},pn.prototype.push=function(p){this.tail?this.insertAfter(this.tail,p):r9(this,p)},pn.prototype.shift=function(){return this.head&&this.removeLink(this.head)},pn.prototype.pop=function(){return this.tail&&this.removeLink(this.tail)},pn.prototype.toArray=function(){for(var p=Array(this.length),v=this.head,E=0;E<this.length;E++)p[E]=v.data,v=v.next;return p},pn.prototype.remove=function(p){for(var v=this.head;v;){var E=v.next;p(v)&&this.removeLink(v),v=E}return this};function i9(p,v,E){if(v==null)v=1;else if(v===0)throw new Error("Concurrency must not be zero");var x=I(p),L=0,D=[],O=!1;function _(X,Et,ce){if(ce!=null&&typeof ce!="function")throw new Error("task callback must be a function");if(G.started=!0,gn(X)||(X=[X]),X.length===0&&G.idle())return m(function(){G.drain()});for(var _n=0,Ve=X.length;_n<Ve;_n++){var Nn={data:X[_n],callback:ce||ht};Et?G._tasks.unshift(Nn):G._tasks.push(Nn)}O||(O=!0,m(function(){O=!1,G.process()}))}function V(X){return function(Et){L-=1;for(var ce=0,_n=X.length;ce<_n;ce++){var Ve=X[ce],Nn=Ma(D,Ve,0);Nn===0?D.shift():Nn>0&&D.splice(Nn,1),Ve.callback.apply(Ve,arguments),Et!=null&&G.error(Et,Ve.data)}L<=G.concurrency-G.buffer&&G.unsaturated(),G.idle()&&G.drain(),G.process()}}var Q=!1,G={_tasks:new pn,concurrency:v,payload:E,saturated:ht,unsaturated:ht,buffer:v/4,empty:ht,drain:ht,error:ht,started:!1,paused:!1,push:function(X,Et){_(X,!1,Et)},kill:function(){G.drain=ht,G._tasks.empty()},unshift:function(X,Et){_(X,!0,Et)},remove:function(X){G._tasks.remove(X)},process:function(){if(!Q){for(Q=!0;!G.paused&&L<G.concurrency&&G._tasks.length;){var X=[],Et=[],ce=G._tasks.length;G.payload&&(ce=Math.min(ce,G.payload));for(var _n=0;_n<ce;_n++){var Ve=G._tasks.shift();X.push(Ve),D.push(Ve),Et.push(Ve.data)}L+=1,G._tasks.length===0&&G.empty(),L===G.concurrency&&G.saturated();var Nn=On(V(X));x(Et,Nn)}Q=!1}},length:function(){return G._tasks.length},running:function(){return L},workersList:function(){return D},idle:function(){return G._tasks.length+L===0},pause:function(){G.paused=!0},resume:function(){G.paused!==!1&&(G.paused=!1,m(G.process))}};return G}function s9(p,v){return i9(p,1,v)}var Bi=ne(br,1);function Ao(p,v,E,x){x=Mo(x||ht);var L=I(E);Bi(p,function(D,O,_){L(v,D,function(V,Q){v=Q,_(V)})},function(D){x(D,v)})}function Pf(){var p=wi(arguments,I);return function(){var v=o(arguments),E=this,x=v[v.length-1];typeof x=="function"?v.pop():x=ht,Ao(p,v,function(L,D,O){D.apply(E,L.concat(function(_){var V=o(arguments,1);O(_,V)}))},function(L,D){x.apply(E,[L].concat(D))})}}var l9=function(){return Pf.apply(null,o(arguments).reverse())},NH=Array.prototype.concat,Ra=function(p,v,E,x){x=x||ht;var L=I(E);yi(p,v,function(D,O){L(D,function(_){return _?O(_):O(null,o(arguments,1))})},function(D,O){for(var _=[],V=0;V<O.length;V++)O[V]&&(_=NH.apply(_,O[V]));return x(D,_)})},c9=ne(Ra,1/0),a9=ne(Ra,1),d9=function(){var p=o(arguments),v=[null].concat(p);return function(){var E=arguments[arguments.length-1];return E.apply(this,v)}};function sl(p){return p}function Ei(p,v){return function(E,x,L,D){D=D||ht;var O=!1,_;E(x,function(V,Q,G){L(V,function(X,Et){X?G(X):p(Et)&&!_?(O=!0,_=v(!0,V),G(null,Df)):G()})},function(V){V?D(V):D(null,O?_:v(!1))})}}function u9(p,v){return v}var Aa=ki(Ei(sl,u9)),ll=vi(Ei(sl,u9)),Oa=ne(ll,1);function h9(p){return function(v){var E=o(arguments,1);E.push(function(x){var L=o(arguments,1);typeof console=="object"&&(x?console.error&&console.error(x):console[p]&&La(L,function(D){console[p](D)}))}),I(v).apply(null,E)}}var f9=h9("dir");function m9(p,v,E){E=On(E||ht);var x=I(p),L=I(v);function D(_){if(_)return E(_);var V=o(arguments,1);V.push(O),L.apply(this,V)}function O(_,V){if(_)return E(_);if(!V)return E(null);x(D)}O(null,!0)}function jf(p,v,E){E=On(E||ht);var x=I(p),L=function(D){if(D)return E(D);var O=o(arguments,1);if(v.apply(this,O))return x(L);E.apply(null,[null].concat(O))};x(L)}function g9(p,v,E){jf(p,function(){return!v.apply(this,arguments)},E)}function p9(p,v,E){E=On(E||ht);var x=I(v),L=I(p);function D(_){if(_)return E(_);L(O)}function O(_,V){if(_)return E(_);if(!V)return E(null);x(D)}L(O)}function C9(p){return function(v,E,x){return p(v,x)}}function _a(p,v,E){Ro(p,C9(I(v)),E)}function cl(p,v,E,x){Sa(v)(p,C9(I(E)),x)}var al=ne(cl,1);function Hf(p){return S(p)?p:i(function(v,E){var x=!0;v.push(function(){var L=arguments;x?m(function(){E.apply(null,L)}):E.apply(null,L)}),p.apply(this,v),x=!1})}function Na(p){return!p}var $a=ki(Ei(Na,Na)),dl=vi(Ei(Na,Na)),Pa=ne(dl,1);function b9(p){return function(v){return v==null?void 0:v[p]}}function $H(p,v,E,x){var L=new Array(v.length);p(v,function(D,O,_){E(D,function(V,Q){L[O]=!!Q,_(V)})},function(D){if(D)return x(D);for(var O=[],_=0;_<v.length;_++)L[_]&&O.push(v[_]);x(null,O)})}function PH(p,v,E,x){var L=[];p(v,function(D,O,_){E(D,function(V,Q){V?_(V):(Q&&L.push({index:O,value:D}),_())})},function(D){D?x(D):x(null,wi(L.sort(function(O,_){return O.index-_.index}),b9("value")))})}function Ff(p,v,E,x){var L=ol(v)?$H:PH;L(p,v,I(E),x||ht)}var ja=ki(Ff),ul=vi(Ff),Ha=ne(ul,1);function k9(p,v){var E=On(v||ht),x=I(Hf(p));function L(D){if(D)return E(D);x(L)}L()}var Fa=function(p,v,E,x){x=x||ht;var L=I(E);yi(p,v,function(D,O){L(D,function(_,V){return _?O(_):O(null,{key:V,val:D})})},function(D,O){for(var _={},V=Object.prototype.hasOwnProperty,Q=0;Q<O.length;Q++)if(O[Q]){var G=O[Q].key,X=O[Q].val;V.call(_,G)?_[G].push(X):_[G]=[X]}return x(D,_)})},v9=ne(Fa,1/0),y9=ne(Fa,1),w9=h9("log");function za(p,v,E,x){x=Mo(x||ht);var L={},D=I(E);br(p,v,function(O,_,V){D(O,_,function(Q,G){if(Q)return V(Q);L[_]=G,V()})},function(O){x(O,L)})}var B9=ne(za,1/0),E9=ne(za,1);function I9(p,v){return v in p}function x9(p,v){var E=Object.create(null),x=Object.create(null);v=v||sl;var L=I(p),D=i(function(_,V){var Q=v.apply(null,_);I9(E,Q)?m(function(){V.apply(null,E[Q])}):I9(x,Q)?x[Q].push(V):(x[Q]=[V],L.apply(null,_.concat(function(){var G=o(arguments);E[Q]=G;var X=x[Q];delete x[Q];for(var Et=0,ce=X.length;Et<ce;Et++)X[Et].apply(null,G)})))});return D.memo=E,D.unmemoized=p,D}var Ua;c?Ua=process.nextTick:l?Ua=setImmediate:Ua=a;var T9=u(Ua);function zf(p,v,E){E=E||ht;var x=ol(v)?[]:{};p(v,function(L,D,O){I(L)(function(_,V){arguments.length>2&&(V=o(arguments,1)),x[D]=V,O(_)})},function(L){E(L,x)})}function S9(p,v){zf(Ro,p,v)}function D9(p,v,E){zf(Sa(v),p,E)}var Uf=function(p,v){var E=I(p);return i9(function(x,L){E(x[0],L)},v,1)},L9=function(p,v){var E=Uf(p,v);return E.push=function(x,L,D){if(D==null&&(D=ht),typeof D!="function")throw new Error("task callback must be a function");if(E.started=!0,gn(x)||(x=[x]),x.length===0)return m(function(){E.drain()});L=L||0;for(var O=E._tasks.head;O&&L>=O.priority;)O=O.next;for(var _=0,V=x.length;_<V;_++){var Q={data:x[_],priority:L,callback:D};O?E._tasks.insertBefore(O,Q):E._tasks.push(Q)}m(E.process)},delete E.unshift,E};function M9(p,v){if(v=Mo(v||ht),!gn(p))return v(new TypeError("First argument to race must be an array of functions"));if(!p.length)return v();for(var E=0,x=p.length;E<x;E++)I(p[E])(v)}function Va(p,v,E,x){var L=o(p).reverse();Ao(L,v,E,x)}function qa(p){var v=I(p);return i(function(x,L){return x.push(function(O,_){if(O)L(null,{error:O});else{var V;arguments.length<=2?V=_:V=o(arguments,1),L(null,{value:V})}}),v.apply(this,x)})}function R9(p){var v;return gn(p)?v=wi(p,qa):(v={},il(p,function(E,x){v[x]=qa.call(this,E)})),v}function A9(p,v,E,x){Ff(p,v,function(L,D){E(L,function(O,_){D(O,!_)})},x)}var O9=ki(A9),Vf=vi(A9),_9=ne(Vf,1);function N9(p){return function(){return p}}function Wa(p,v,E){var x=5,L=0,D={times:x,intervalFunc:N9(L)};function O(G,X){if(typeof X=="object")G.times=+X.times||x,G.intervalFunc=typeof X.interval=="function"?X.interval:N9(+X.interval||L),G.errorFilter=X.errorFilter;else if(typeof X=="number"||typeof X=="string")G.times=+X||x;else throw new Error("Invalid arguments for async.retry")}if(arguments.length<3&&typeof p=="function"?(E=v||ht,v=p):(O(D,p),E=E||ht),typeof v!="function")throw new Error("Invalid arguments for async.retry");var _=I(v),V=1;function Q(){_(function(G){G&&V++<D.times&&(typeof D.errorFilter!="function"||D.errorFilter(G))?setTimeout(Q,D.intervalFunc(V)):E.apply(null,arguments)})}Q()}var $9=function(p,v){v||(v=p,p=null);var E=I(v);return i(function(x,L){function D(O){E.apply(null,x.concat(O))}p?Wa(p,D,L):Wa(D,L)})};function P9(p,v){zf(Bi,p,v)}var Ga=ki(Ei(Boolean,sl)),hl=vi(Ei(Boolean,sl)),Za=ne(hl,1);function j9(p,v,E){var x=I(v);Da(p,function(D,O){x(D,function(_,V){if(_)return O(_);O(null,{value:D,criteria:V})})},function(D,O){if(D)return E(D);E(null,wi(O.sort(L),b9("value")))});function L(D,O){var _=D.criteria,V=O.criteria;return _<V?-1:_>V?1:0}}function H9(p,v,E){var x=I(p);return i(function(L,D){var O=!1,_;function V(){var Q=p.name||"anonymous",G=new Error('Callback function "'+Q+'" timed out.');G.code="ETIMEDOUT",E&&(G.info=E),O=!0,D(G)}L.push(function(){O||(D.apply(null,arguments),clearTimeout(_))}),_=setTimeout(V,v),x.apply(null,L)})}var jH=Math.ceil,HH=Math.max;function FH(p,v,E,x){for(var L=-1,D=HH(jH((v-p)/(E||1)),0),O=Array(D);D--;)O[x?D:++L]=p,p+=E;return O}function Ya(p,v,E,x){var L=I(E);yi(FH(0,p,1),v,L,x)}var F9=ne(Ya,1/0),z9=ne(Ya,1);function U9(p,v,E,x){arguments.length<=3&&(x=E,E=v,v=gn(p)?[]:{}),x=Mo(x||ht);var L=I(E);Ro(p,function(D,O,_){L(v,D,O,_)},function(D){x(D,v)})}function V9(p,v){var E=null,x;v=v||ht,al(p,function(L,D){I(L)(function(O,_){arguments.length>2?x=o(arguments,1):x=_,E=O,D(!O)})},function(){v(E,x)})}function q9(p){return function(){return(p.unmemoized||p).apply(null,arguments)}}function qf(p,v,E){E=On(E||ht);var x=I(v);if(!p())return E(null);var L=function(D){if(D)return E(D);if(p())return x(L);var O=o(arguments,1);E.apply(null,[null].concat(O))};x(L)}function W9(p,v,E){qf(function(){return!p.apply(this,arguments)},v,E)}var G9=function(p,v){if(v=Mo(v||ht),!gn(p))return v(new Error("First argument to waterfall must be an array of functions"));if(!p.length)return v();var E=0;function x(D){var O=I(p[E++]);D.push(On(L)),O.apply(null,D)}function L(D){if(D||E===p.length)return v.apply(null,arguments);x(o(arguments,1))}x([])},zH={apply:r,applyEach:WC,applyEachSeries:GC,asyncify:C,auto:Of,autoInject:o9,cargo:s9,compose:l9,concat:c9,concatLimit:Ra,concatSeries:a9,constant:d9,detect:Aa,detectLimit:ll,detectSeries:Oa,dir:f9,doDuring:m9,doUntil:g9,doWhilst:jf,during:p9,each:_a,eachLimit:cl,eachOf:Ro,eachOfLimit:br,eachOfSeries:Bi,eachSeries:al,ensureAsync:Hf,every:$a,everyLimit:dl,everySeries:Pa,filter:ja,filterLimit:ul,filterSeries:Ha,forever:k9,groupBy:v9,groupByLimit:Fa,groupBySeries:y9,log:w9,map:Da,mapLimit:yi,mapSeries:Af,mapValues:B9,mapValuesLimit:za,mapValuesSeries:E9,memoize:x9,nextTick:T9,parallel:S9,parallelLimit:D9,priorityQueue:L9,queue:Uf,race:M9,reduce:Ao,reduceRight:Va,reflect:qa,reflectAll:R9,reject:O9,rejectLimit:Vf,rejectSeries:_9,retry:Wa,retryable:$9,seq:Pf,series:P9,setImmediate:m,some:Ga,someLimit:hl,someSeries:Za,sortBy:j9,timeout:H9,times:F9,timesLimit:Ya,timesSeries:z9,transform:U9,tryEach:V9,unmemoize:q9,until:W9,waterfall:G9,whilst:qf,all:$a,allLimit:dl,allSeries:Pa,any:Ga,anyLimit:hl,anySeries:Za,find:Aa,findLimit:ll,findSeries:Oa,forEach:_a,forEachSeries:al,forEachLimit:cl,forEachOf:Ro,forEachOfSeries:Bi,forEachOfLimit:br,inject:Ao,foldl:Ao,foldr:Va,select:ja,selectLimit:ul,selectSeries:Ha,wrapSync:C};e.default=zH,e.apply=r,e.applyEach=WC,e.applyEachSeries=GC,e.asyncify=C,e.auto=Of,e.autoInject=o9,e.cargo=s9,e.compose=l9,e.concat=c9,e.concatLimit=Ra,e.concatSeries=a9,e.constant=d9,e.detect=Aa,e.detectLimit=ll,e.detectSeries=Oa,e.dir=f9,e.doDuring=m9,e.doUntil=g9,e.doWhilst=jf,e.during=p9,e.each=_a,e.eachLimit=cl,e.eachOf=Ro,e.eachOfLimit=br,e.eachOfSeries=Bi,e.eachSeries=al,e.ensureAsync=Hf,e.every=$a,e.everyLimit=dl,e.everySeries=Pa,e.filter=ja,e.filterLimit=ul,e.filterSeries=Ha,e.forever=k9,e.groupBy=v9,e.groupByLimit=Fa,e.groupBySeries=y9,e.log=w9,e.map=Da,e.mapLimit=yi,e.mapSeries=Af,e.mapValues=B9,e.mapValuesLimit=za,e.mapValuesSeries=E9,e.memoize=x9,e.nextTick=T9,e.parallel=S9,e.parallelLimit=D9,e.priorityQueue=L9,e.queue=Uf,e.race=M9,e.reduce=Ao,e.reduceRight=Va,e.reflect=qa,e.reflectAll=R9,e.reject=O9,e.rejectLimit=Vf,e.rejectSeries=_9,e.retry=Wa,e.retryable=$9,e.seq=Pf,e.series=P9,e.setImmediate=m,e.some=Ga,e.someLimit=hl,e.someSeries=Za,e.sortBy=j9,e.timeout=H9,e.times=F9,e.timesLimit=Ya,e.timesSeries=z9,e.transform=U9,e.tryEach=V9,e.unmemoize=q9,e.until=W9,e.waterfall=G9,e.whilst=qf,e.all=$a,e.allLimit=dl,e.allSeries=Pa,e.any=Ga,e.anyLimit=hl,e.anySeries=Za,e.find=Aa,e.findLimit=ll,e.findSeries=Oa,e.forEach=_a,e.forEachSeries=al,e.forEachLimit=cl,e.forEachOf=Ro,e.forEachOfSeries=Bi,e.forEachOfLimit=br,e.inject=Ao,e.foldl=Ao,e.foldr=Va,e.select=ja,e.selectLimit=ul,e.selectSeries=Ha,e.wrapSync=C,Object.defineProperty(e,"__esModule",{value:!0})})})(zu,zu.exports);var B2={exports:{}},Uu=B2.exports=function(n,t){if(t||(t=16),n===void 0&&(n=128),n<=0)return"0";for(var e=Math.log(Math.pow(2,n))/Math.log(t),o=2;e===1/0;o*=2)e=Math.log(Math.pow(2,n/o))/Math.log(t)*o;for(var r=e-Math.floor(e),i="",o=0;o<Math.floor(e);o++){var s=Math.floor(Math.random()*t).toString(t);i=s+i}if(r){var l=Math.pow(t,r),s=Math.floor(Math.random()*l).toString(t);i=s+i}var c=parseInt(i,t);return c!==1/0&&c>=Math.pow(2,n)?Uu(n,t):i};Uu.rack=function(n,t,e){var o=function(i){var s=0;do{if(s++>10)if(e)n+=e;else throw new Error("too many ID collisions, use more bits");var l=Uu(n,t)}while(Object.hasOwnProperty.call(r,l));return r[l]=i,l},r=o.hats={};return o.get=function(i){return o.hats[i]},o.set=function(i,s){return o.hats[i]=s,o},o.bits=n||128,o.base=t||16,o};var E2=bo,jy=y2,Hy=w2,Cc=rn,Vu=zu.exports,Fy=B2.exports,I2=er.ACTIONS,x2=Pt;function Pt(n,t){if(E2.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}E2.mixin(Pt),Pt.prototype.subscribe=function(n){this._sendSubscriptionAction(!0,n)},Pt.prototype.unsubscribe=function(n){this._sendSubscriptionAction(!1,n)},Pt.prototype.create=function(n){if(this._wantsDestroy)throw new Error("Presence is being destroyed");n=n||Fy();var t=this._createLocalPresence(n);return this.localPresences[n]=t,t},Pt.prototype.destroy=function(n){this._wantsDestroy=!0;var t=this,e=Object.keys(t.localPresences);this.unsubscribe(function(o){if(o)return t._callbackOrEmit(o,n);var r=Object.keys(t._remotePresenceInstances);Vu.parallel([function(i){Vu.each(e,function(s,l){t.localPresences[s].destroy(l)},i)},function(i){if(!t._wantsDestroy)return i();Vu.each(r,function(s,l){t._remotePresenceInstances[s].destroy(l)},i)}],function(i){t._wantsDestroy&&delete t.connection._presences[t.channel],t._callbackOrEmit(i,n)})})},Pt.prototype._sendSubscriptionAction=function(n,t){this.wantSubscribe=!!n;var e=this.wantSubscribe?I2.presenceSubscribe:I2.presenceUnsubscribe,o=this.connection._presenceSeq++;this._subscriptionCallbacksBySeq[o]=t,this.connection.canSend&&this.connection._sendPresenceAction(e,o,this)},Pt.prototype._handleSubscribe=function(n,t){this.wantSubscribe&&(this.subscribed=!0);var e=this._subscriptionCallback(t);this._callbackOrEmit(n,e)},Pt.prototype._handleUnsubscribe=function(n,t){this.subscribed=!1;var e=this._subscriptionCallback(t);this._callbackOrEmit(n,e)},Pt.prototype._receiveUpdate=function(n,t){var e=Cc.dig(this.localPresences,t.id);if(e)return e._ack(n,t.pv);if(n)return this.emit("error",n);var o=this,r=Cc.digOrCreate(this._remotePresenceInstances,t.id,function(){return o._createRemotePresence(t.id)});r.receiveUpdate(t)},Pt.prototype._updateRemotePresence=function(n){this.remotePresences[n.presenceId]=n.value,n.value===null&&this._removeRemotePresence(n.presenceId),this.emit("receive",n.presenceId,n.value)},Pt.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()}},Pt.prototype._removeRemotePresence=function(n){this._remotePresenceInstances[n].destroy(),delete this._remotePresenceInstances[n],delete this.remotePresences[n]},Pt.prototype._onConnectionStateChanged=function(){if(!!this.connection.canSend){this._resubscribe();for(var n in this.localPresences)this.localPresences[n]._sendPending()}},Pt.prototype._resubscribe=function(){var n=[];for(var t in this._subscriptionCallbacksBySeq){var e=this._subscriptionCallback(t);n.push(e)}if(!this.wantSubscribe)return this._callEachOrEmit(n);var o=this;this.subscribe(function(r){o._callEachOrEmit(n,r)})},Pt.prototype._subscriptionCallback=function(n){var t=this._subscriptionCallbacksBySeq[n];return delete this._subscriptionCallbacksBySeq[n],t},Pt.prototype._callbackOrEmit=function(n,t){if(t)return Cc.nextTick(t,n);n&&this.emit("error",n)},Pt.prototype._createLocalPresence=function(n){return new jy(this,n)},Pt.prototype._createRemotePresence=function(n){return new Hy(this,n)},Pt.prototype._callEachOrEmit=function(n,t){var e=Cc.callEach(n,t);!e&&t&&this.emit("error",t)};var as=y2,T2=hc,zy=rn,S2=T2.CODES,Uy=ln;function ln(n,t){as.call(this,n,t),this.collection=this.presence.collection,this.id=this.presence.id,this._doc=this.connection.get(this.collection,this.id),this._isSending=!1,this._docDataVersionByPresenceVersion={},this._opHandler=this._transformAgainstOp.bind(this),this._createOrDelHandler=this._handleCreateOrDel.bind(this),this._loadHandler=this._handleLoad.bind(this),this._destroyHandler=this.destroy.bind(this),this._registerWithDoc()}ln.prototype=Object.create(as.prototype),ln.prototype.submit=function(n,t){if(!this._doc.type){if(n===null)return this._callbackOrEmit(null,t);var e={code:S2.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,as.prototype.submit.call(this,n,t)},ln.prototype.destroy=function(n){this._doc.removeListener("op",this._opHandler),this._doc.removeListener("create",this._createOrDelHandler),this._doc.removeListener("del",this._createOrDelHandler),this._doc.removeListener("load",this._loadHandler),this._doc.removeListener("destroy",this._destroyHandler),as.prototype.destroy.call(this,n)},ln.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={})})}},ln.prototype._registerWithDoc=function(){this._doc.on("op",this._opHandler),this._doc.on("create",this._createOrDelHandler),this._doc.on("del",this._createOrDelHandler),this._doc.on("load",this._loadHandler),this._doc.on("destroy",this._destroyHandler)},ln.prototype._transformAgainstOp=function(n,t){var e=this,o=this._doc._dataStateVersion;this._pendingMessages.forEach(function(r){var i=e._docDataVersionByPresenceVersion[r.pv];if(!(i>=o))try{r.p=e._transformPresence(r.p,n,t),e._docDataVersionByPresenceVersion[r.pv]=o}catch(l){var s=e._getCallback(r.pv);e._callbackOrEmit(l,s)}});try{this.value=this._transformPresence(this.value,n,t)}catch(r){this.emit("error",r)}},ln.prototype._handleCreateOrDel=function(){this._pendingMessages.forEach(function(n){n.p=null}),this.value=null},ln.prototype._handleLoad=function(){this.value=null,this._pendingMessages=[],this._docDataVersionByPresenceVersion={}},ln.prototype._message=function(){var n=as.prototype._message.call(this);return n.c=this.collection,n.d=this.id,n.v=null,n.t=null,n},ln.prototype._transformPresence=function(n,t,e){var o=this._doc.type;if(!zy.supportsPresence(o))throw new T2(S2.ERR_TYPE_DOES_NOT_SUPPORT_PRESENCE,"Type does not support presence: "+o.name);return o.transformPresence(n,t,e)};var D2={};(function(n){var t=ss,e=hc,o=rn,r=e.CODES;n.checkOp=function(l){if(l==null||typeof l!="object")return new e(r.ERR_OT_OP_BADLY_FORMED,"Op must be an object");if(l.create!=null){if(typeof l.create!="object")return new e(r.ERR_OT_OP_BADLY_FORMED,"Create data must be an object");var c=l.create.type;if(typeof c!="string")return new e(r.ERR_OT_OP_BADLY_FORMED,"Missing create type");var a=t.map[c];if(a==null||typeof a!="object")return new e(r.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type")}else if(l.del!=null){if(l.del!==!0)return new e(r.ERR_OT_OP_BADLY_FORMED,"del value must be true")}else if(!("op"in l))return new e(r.ERR_OT_OP_BADLY_FORMED,"Missing op, create, or del");if(l.src!=null&&typeof l.src!="string")return new e(r.ERR_OT_OP_BADLY_FORMED,"src must be a string");if(l.seq!=null&&typeof l.seq!="number")return new e(r.ERR_OT_OP_BADLY_FORMED,"seq must be a number");if(l.src==null&&l.seq!=null||l.src!=null&&l.seq==null)return new e(r.ERR_OT_OP_BADLY_FORMED,"Both src and seq must be set together");if(l.m!=null&&typeof l.m!="object")return new e(r.ERR_OT_OP_BADLY_FORMED,"op.m must be an object or null")},n.normalizeType=function(l){return t.map[l]&&t.map[l].uri},n.apply=function(l,c){if(typeof l!="object")return new e(r.ERR_APPLY_SNAPSHOT_NOT_PROVIDED,"Missing snapshot");if(l.v!=null&&c.v!=null&&l.v!==c.v)return new e(r.ERR_APPLY_OP_VERSION_DOES_NOT_MATCH_SNAPSHOT,"Version mismatch");if(c.create){if(l.type)return new e(r.ERR_DOC_ALREADY_CREATED,"Document already exists");var a=c.create,u=t.map[a.type];if(!u)return new e(r.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type");try{l.data=u.create(a.data),l.type=u.uri,l.v++}catch(m){return m}}else if(c.del)l.data=void 0,l.type=null,l.v++;else if("op"in c){var f=i(l,c.op);if(f)return f;l.v++}else l.v++};function i(l,c){if(!l.type)return new e(r.ERR_DOC_DOES_NOT_EXIST,"Document does not exist");if(c===void 0)return new e(r.ERR_OT_OP_NOT_PROVIDED,"Missing op");var a=t.map[l.type];if(!a)return new e(r.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type");try{l.data=a.apply(l.data,c)}catch(u){return new e(r.ERR_OT_OP_NOT_APPLIED,u.message)}}n.transform=function(l,c,a){if(c.v!=null&&c.v!==a.v)return new e(r.ERR_OP_VERSION_MISMATCH_DURING_TRANSFORM,"Version mismatch");if(a.del){if(c.create||"op"in c)return new e(r.ERR_DOC_WAS_DELETED,"Document was deleted")}else{if(a.create&&("op"in c||c.create||c.del)||"op"in a&&c.create)return new e(r.ERR_DOC_ALREADY_CREATED,"Document was created remotely");if("op"in a&&"op"in c){if(!l)return new e(r.ERR_DOC_DOES_NOT_EXIST,"Document does not exist");if(typeof l=="string"&&(l=t.map[l],!l))return new e(r.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type");try{c.op=l.transform(c.op,a.op,"left")}catch(u){return u}}}c.v!=null&&c.v++},n.applyOps=function(l,c,a){a=a||{};for(var u=0;u<c.length;u++){var f=c[u];if(a._normalizeLegacyJson0Ops)try{s(l,f)}catch{return new e(r.ERR_OT_LEGACY_JSON0_OP_CANNOT_BE_NORMALIZED,"Cannot normalize legacy json0 op")}l.v=f.v;var m=n.apply(l,f);if(m)return m}},n.transformPresence=function(l,c,a){var u=this.checkOp(c);if(u)return u;var f=l.t;if(typeof f=="string"&&(f=t.map[f]),!f)return{code:r.ERR_DOC_TYPE_NOT_RECOGNIZED,message:"Unknown type"};if(!o.supportsPresence(f))return{code:r.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:f.transformPresence(l.p,c.op,a)}catch(m){return{code:r.ERR_PRESENCE_TRANSFORM_FAILED,message:m.message||m}}l.v++};function s(l,c){if(l.type===t.defaultType.uri){var a=c.op;if(!!a){var u=l.data;a.length>1&&(u=o.clone(u));for(var f=0;f<a.length;f++){var m=a[f];typeof m.lm=="string"&&(m.lm=+m.lm);for(var C=m.p,k=u,w=0;w<C.length;w++){var y=C[w];Object.prototype.toString.call(k)=="[object Array]"?C[w]=+y:k.constructor===Object&&(C[w]=y.toString()),k=k[y]}f<a.length-1&&(u=t.defaultType.apply(u,[m]))}}}}})(D2);var ds=w2,Vy=D2,qy=Pe;function Pe(n,t){ds.call(this,n,t),this.collection=this.presence.collection,this.id=this.presence.id,this.src=null,this.presenceVersion=null,this._doc=this.connection.get(this.collection,this.id),this._pending=null,this._opCache=null,this._pendingSetPending=!1,this._opHandler=this._handleOp.bind(this),this._createDelHandler=this._handleCreateDel.bind(this),this._loadHandler=this._handleLoad.bind(this),this._registerWithDoc()}Pe.prototype=Object.create(ds.prototype),Pe.prototype.receiveUpdate=function(n){this._pending&&n.pv<this._pending.pv||(this.src=n.src,this._pending=n,this._setPendingPresence())},Pe.prototype.destroy=function(n){this._doc.removeListener("op",this._opHandler),this._doc.removeListener("create",this._createDelHandler),this._doc.removeListener("del",this._createDelHandler),this._doc.removeListener("load",this._loadHandler),ds.prototype.destroy.call(this,n)},Pe.prototype._registerWithDoc=function(){this._doc.on("op",this._opHandler),this._doc.on("create",this._createDelHandler),this._doc.on("del",this._createDelHandler),this._doc.on("load",this._loadHandler)},Pe.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))}})}},Pe.prototype._handleOp=function(n,t,e){var o=e===this.src;this._transformAgainstOp(n,o),this._cacheOp(n,o),this._setPendingPresence()},ds.prototype._handleCreateDel=function(){this._cacheOp(null),this._setPendingPresence()},ds.prototype._handleLoad=function(){this.value=null,this._pending=null,this._opCache=null,this.presence._updateRemotePresence(this)},Pe.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)}},Pe.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++):Vy.transformPresence(this._pending,t,e)}var o=this._pending.v>=this._doc.version;return o&&this._stopCachingOps(),o},Pe.prototype._startCachingOps=function(){this._opCache=[]},Pe.prototype._stopCachingOps=function(){this._opCache=null},Pe.prototype._cacheOp=function(n,t){this._opCache&&(n=n?{op:n}:null,this._opCache[this._doc.version-1]={op:n,isOwnOp:t})};var L2=x2,Wy=Uy,Gy=qy;function $r(n,t,e){var o=$r.channel(t,e);L2.call(this,n,o),this.collection=t,this.id=e}var Zy=$r;$r.prototype=Object.create(L2.prototype),$r.channel=function(n,t){return n+"."+t},$r.prototype._createLocalPresence=function(n){return new Wy(this,n)},$r.prototype._createRemotePresence=function(n){return new Gy(this,n)};var Yy=Qy;function Qy(n,t,e,o,r){this.id=n,this.v=t,this.type=e,this.data=o,this.m=r}var Ky=Yy,M2=bo,R2=us;function us(n,t,e,o,r){if(M2.EventEmitter.call(this),typeof r!="function")throw new Error("Callback is required for SnapshotRequest");this.requestId=t,this.connection=n,this.id=o,this.collection=e,this.callback=r,this.sent=!1}M2.mixin(us),us.prototype.send=function(){!this.connection.canSend||(this.connection.send(this._message()),this.sent=!0)},us.prototype._onConnectionStateChanged=function(){this.connection.canSend?this.sent||this.send():this.sent=!1},us.prototype._handleResponse=function(n,t){if(this.emit("ready"),n)return this.callback(n);var e=t.meta?t.meta:null,o=new Ky(this.id,t.v,t.type,t.data,e);this.callback(null,o)};var A2=R2,Jy=rn,Xy=er.ACTIONS,tw=qu;function qu(n,t,e,o,r,i){if(A2.call(this,n,t,e,o,i),!Jy.isValidVersion(r))throw new Error("Snapshot version must be a positive integer or null");this.version=r}qu.prototype=Object.create(A2.prototype),qu.prototype._message=function(){return{a:Xy.snapshotFetch,id:this.requestId,c:this.collection,d:this.id,v:this.version}};var O2=R2,ew=rn,nw=er.ACTIONS,ow=Wu;function Wu(n,t,e,o,r,i){if(O2.call(this,n,t,e,o,i),!ew.isValidTimestamp(r))throw new Error("Snapshot timestamp must be a positive integer or null");this.timestamp=r}Wu.prototype=Object.create(O2.prototype),Wu.prototype._message=function(){return{a:nw.snapshotFetchByTimestamp,id:this.requestId,c:this.collection,d:this.id,ts:this.timestamp}};var rw=Ly,iw=_y,sw=x2,_2=Zy,lw=tw,cw=ow,N2=bo,Pr=hc,Ct=er.ACTIONS,$2=ss,cn=rn,hs=h2,fs=Pr.CODES;function P2(n){return n.readyState===0||n.readyState===1?"connecting":"disconnected"}var aw=K;function K(n){N2.EventEmitter.call(this),this.collections={},this.nextQueryId=1,this.nextSnapshotRequestId=1,this.queries={},this._presences={},this._snapshotRequests={},this.seq=1,this._presenceSeq=1,this.id=null,this.agent=null,this.debug=!1,this.state=P2(n),this.bindToSocket(n)}N2.mixin(K),K.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=P2(n);this._setState(t),this.canSend=!1;var e=this;n.onmessage=function(o){try{var r=typeof o.data=="string"?JSON.parse(o.data):o.data}catch{hs.warn("Failed to parse message",o);return}e.debug&&hs.info("RECV",JSON.stringify(r));var i={data:r};if(e.emit("receive",i),!!i.data)try{e.handleMessage(i.data)}catch(s){cn.nextTick(function(){e.emit("error",s)})}},n.readyState===1&&e._initializeHandshake(),n.onopen=function(){e._setState("connecting"),e._initializeHandshake()},n.onerror=function(o){e.emit("connection error",o)},n.onclose=function(o){o==="closed"||o==="Closed"?e._setState("closed",o):o==="stopped"||o==="Stopped by server"?e._setState("stopped",o):e._setState("disconnected",o)}},K.prototype.handleMessage=function(n){var t=null;switch(n.error&&(t=j2(n.error,n),delete n.error),n.a){case Ct.initLegacy:return this._handleLegacyInit(n);case Ct.handshake:return this._handleHandshake(t,n);case Ct.queryFetch:var e=this.queries[n.id];e&&e._handleFetch(t,n.data,n.extra);return;case Ct.querySubscribe:var e=this.queries[n.id];e&&e._handleSubscribe(t,n.data,n.extra);return;case Ct.queryUnsubscribe:return;case Ct.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 Ct.bulkFetch:return this._handleBulkMessage(t,n,"_handleFetch");case Ct.bulkSubscribe:case Ct.bulkUnsubscribe:return this._handleBulkMessage(t,n,"_handleSubscribe");case Ct.snapshotFetch:case Ct.snapshotFetchByTimestamp:return this._handleSnapshotFetch(t,n);case Ct.fetch:var o=this.getExisting(n.c,n.d);o&&o._handleFetch(t,n.data);return;case Ct.subscribe:case Ct.unsubscribe:var o=this.getExisting(n.c,n.d);o&&o._handleSubscribe(t,n.data);return;case Ct.op:var o=this.getExisting(n.c,n.d);o&&o._handleOp(t,n);return;case Ct.presence:return this._handlePresence(t,n);case Ct.presenceSubscribe:return this._handlePresenceSubscribe(t,n);case Ct.presenceUnsubscribe:return this._handlePresenceUnsubscribe(t,n);case Ct.presenceRequest:return this._handlePresenceRequest(t,n);case Ct.pingPong:return this._handlePingPong(t);default:hs.warn("Ignoring unrecognized message",n)}};function j2(n,t){var e=new Error(n.message);return e.code=n.code,t&&(e.data=t),e}K.prototype._handleBulkMessage=function(n,t,e){if(t.data)for(var o in t.data){var r=t.data[o],i=this.getExisting(t.c,o);i&&(n?i[e](n):r.error?i[e](j2(r.error)):i[e](null,r))}else if(Array.isArray(t.b))for(var s=0;s<t.b.length;s++){var o=t.b[s],i=this.getExisting(t.c,o);i&&i[e](n)}else if(t.b)for(var o in t.b){var i=this.getExisting(t.c,o);i&&i[e](n)}else hs.error("Invalid bulk message",t)},K.prototype._reset=function(){this.agent=null},K.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 Pr(fs.ERR_CONNECTION_STATE_TRANSITION_INVALID,"Cannot transition directly from "+this.state+" to "+n);return this.emit("error",e)}this.state=n,this.canSend=n==="connected",(n==="disconnected"||n==="stopped"||n==="closed")&&this._reset(),this.startBulk();for(var o in this.queries){var r=this.queries[o];r._onConnectionStateChanged()}for(var i in this.collections){var s=this.collections[i];for(var o in s)s[o]._onConnectionStateChanged()}for(var l in this._presences)this._presences[l]._onConnectionStateChanged();for(var o in this._snapshotRequests){var c=this._snapshotRequests[o];c._onConnectionStateChanged()}this.endBulk(),this.emit(n,t),this.emit("state",n,t)}},K.prototype.startBulk=function(){this.bulk||(this.bulk={})},K.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},K.prototype._sendBulk=function(n,t,e){if(!!e){var o=[],r={},i=0,s;for(var l in e){var c=e[l];c==null?o.push(l):(r[l]=c,s=l,i++)}if(o.length===1){var l=o[0];this.send({a:n,c:t,d:l})}else o.length&&this.send({a:"b"+n,c:t,b:o});if(i===1){var a=r[s];this.send({a:n,c:t,d:s,v:a})}else i&&this.send({a:"b"+n,c:t,b:r})}},K.prototype._sendActions=function(n,t,e){if(this._addDoc(t),this.bulk){var o=this.bulk[t.collection]||(this.bulk[t.collection]={}),r=o[n]||(o[n]={}),i=r.hasOwnProperty(t.id);return r[t.id]=e,i}else{var s={a:n,c:t.collection,d:t.id,v:e};this.send(s)}},K.prototype.sendFetch=function(n){return this._sendActions(Ct.fetch,n,n.version)},K.prototype.sendSubscribe=function(n){return this._sendActions(Ct.subscribe,n,n.version)},K.prototype.sendUnsubscribe=function(n){return this._sendActions(Ct.unsubscribe,n)},K.prototype.sendOp=function(n,t){this._addDoc(n);var e={a:Ct.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)},K.prototype.send=function(n){this.debug&&hs.info("SEND",JSON.stringify(n)),this.emit("send",n),this.socket.send(JSON.stringify(n))},K.prototype.ping=function(){if(!this.canSend)throw new Pr(fs.ERR_CANNOT_PING_OFFLINE,"Socket must be CONNECTED to ping");var n={a:Ct.pingPong};this.send(n)},K.prototype.close=function(){this.socket.close()},K.prototype.getExisting=function(n,t){if(this.collections[n])return this.collections[n][t]},K.prototype.get=function(n,t){var e=this.collections[n]||(this.collections[n]={}),o=e[t];return o||(o=e[t]=new rw(this,n,t),this.emit("doc",o)),o._wantsDestroy=!1,o},K.prototype._destroyDoc=function(n){!n._wantsDestroy||(cn.digAndRemove(this.collections,n.collection,n.id),n.emit("destroy"))},K.prototype._addDoc=function(n){var t=this.collections[n.collection];t||(t=this.collections[n.collection]={}),t[n.id]!==n&&(t[n.id]=n)},K.prototype._createQuery=function(n,t,e,o,r){var i=this.nextQueryId++,s=new iw(n,this,i,t,e,o,r);return this.queries[i]=s,s.send(),s},K.prototype._destroyQuery=function(n){delete this.queries[n.id]},K.prototype.createFetchQuery=function(n,t,e,o){return this._createQuery(Ct.queryFetch,n,t,e,o)},K.prototype.createSubscribeQuery=function(n,t,e,o){return this._createQuery(Ct.querySubscribe,n,t,e,o)},K.prototype.hasPending=function(){return!!(this._firstDoc(bc)||this._firstQuery(bc)||this._firstSnapshotRequest())};function bc(n){return n.hasPending()}K.prototype.hasWritePending=function(){return!!this._firstDoc(dw)};function dw(n){return n.hasWritePending()}K.prototype.whenNothingPending=function(n){var t=this._firstDoc(bc);if(t){t.once("nothing pending",this._nothingPendingRetry(n));return}var e=this._firstQuery(bc);if(e){e.once("ready",this._nothingPendingRetry(n));return}var o=this._firstSnapshotRequest();if(o){o.once("ready",this._nothingPendingRetry(n));return}cn.nextTick(n)},K.prototype._nothingPendingRetry=function(n){var t=this;return function(){cn.nextTick(function(){t.whenNothingPending(n)})}},K.prototype._firstDoc=function(n){for(var t in this.collections){var e=this.collections[t];for(var o in e){var r=e[o];if(n(r))return r}}},K.prototype._firstQuery=function(n){for(var t in this.queries){var e=this.queries[t];if(n(e))return e}},K.prototype._firstSnapshotRequest=function(){for(var n in this._snapshotRequests)return this._snapshotRequests[n]},K.prototype.fetchSnapshot=function(n,t,e,o){typeof e=="function"&&(o=e,e=null);var r=this.nextSnapshotRequestId++,i=new lw(this,r,n,t,e,o);this._snapshotRequests[i.requestId]=i,i.send()},K.prototype.fetchSnapshotByTimestamp=function(n,t,e,o){typeof e=="function"&&(o=e,e=null);var r=this.nextSnapshotRequestId++,i=new cw(this,r,n,t,e,o);this._snapshotRequests[i.requestId]=i,i.send()},K.prototype._handleSnapshotFetch=function(n,t){var e=this._snapshotRequests[t.id];!e||(delete this._snapshotRequests[t.id],e._handleResponse(n,t))},K.prototype._handleLegacyInit=function(n){if(n.protocolMinor)return this._initializeHandshake();this._initialize(n)},K.prototype._initializeHandshake=function(){this.send({a:Ct.handshake,id:this.id})},K.prototype._handleHandshake=function(n,t){if(n)return this.emit("error",n);this._initialize(t)},K.prototype._handlePingPong=function(n){if(n)return this.emit("error",n);this.emit("pong")},K.prototype._initialize=function(n){if(this.state==="connecting"){if(n.protocol!==1)return this.emit("error",new Pr(fs.ERR_PROTOCOL_VERSION_NOT_SUPPORTED,"Unsupported protocol version: "+n.protocol));if($2.map[n.type]!==$2.defaultType)return this.emit("error",new Pr(fs.ERR_DEFAULT_TYPE_MISMATCH,n.type+" does not match the server default type"));if(typeof n.id!="string")return this.emit("error",new Pr(fs.ERR_CLIENT_ID_BADLY_FORMED,"Client id must be a string"));this.id=n.id,this._setState("connected")}},K.prototype.getPresence=function(n){var t=this,e=cn.digOrCreate(this._presences,n,function(){return new sw(t,n)});return e._wantsDestroy=!1,e},K.prototype.getDocPresence=function(n,t){var e=_2.channel(n,t),o=this,r=cn.digOrCreate(this._presences,e,function(){return new _2(o,n,t)});return r._wantsDestroy=!1,r},K.prototype._sendPresenceAction=function(n,t,e){this._addPresence(e);var o={a:n,ch:e.channel,seq:t};return this.send(o),o.seq},K.prototype._addPresence=function(n){cn.digOrCreate(this._presences,n.channel,function(){return n})},K.prototype._handlePresenceSubscribe=function(n,t){var e=cn.dig(this._presences,t.ch);e&&e._handleSubscribe(n,t.seq)},K.prototype._handlePresenceUnsubscribe=function(n,t){var e=cn.dig(this._presences,t.ch);e&&e._handleUnsubscribe(n,t.seq)},K.prototype._handlePresence=function(n,t){var e=cn.dig(this._presences,t.ch);e&&e._receiveUpdate(n,t)},K.prototype._handlePresenceRequest=function(n,t){var e=cn.dig(this._presences,t.ch);e&&e._broadcastAllLocalPresence(n,t)};var H2=aw,uw=ss;const kc={err:1001,msg:"user auth error",name:"AuthError"},hw={err:1002,msg:"you don't have required permission",name:"PermissionError"},Gu={err:1003,msg:"Too many user connected",name:"MaxUserError"},ms={err:1004,msg:"document server changed, reload it",name:"RequestReloadError"},fw={err:1005,msg:"app id must be at least 2 chars, doc id must be at least 5 chars",name:"DocIdError"},mw={err:1028,msg:"upload file ext not allowed",name:"FileExtError"},gs="x-live-editor-token",vc="x-live-editor-base-url",fe=B("auth-connection");function gw(n){try{n()}catch(t){fe.error(t)}}class pw{constructor(t,e){h(this,"connection");h(this,"ws");h(this,"retryCount");h(this,"events",new Zf.EventEmitter);h(this,"token",null);h(this,"resourceToken",null);this.url=t,this.reauthFunc=e,this.retryCount=0}getBaseURL(){const t=new URL(this.url);return`${t.protocol==="wss:"?"https:":"http:"}//${t.host}${t.pathname}`}getBase64BaseURL(){return Ho(this.getBaseURL())}async auth(t){d(fe,t.token,"no auth token");const e=`${this.getBaseURL()}/auth`,o=await window.fetch(e,{method:"GET",headers:{[gs]:t.token,[vc]:this.getBase64BaseURL()},credentials:"include"});if(o.status!==200)throw new Error("http auth error");return this.token=t.token,await o.json()}async logout(){if(!this.token)return;const t=`${this.getBaseURL()}/logout`;await window.fetch(t,{method:"GET",headers:{[vc]:Ho(this.getBaseURL())}})}async init(t){const e=await this.auth(t);this.resourceToken=e.read,this.ws=new y7.default(this.url,void 0,{maxReconnectionDelay:2500,minReconnectionDelay:1e3}),this.connection=Object.create(H2.prototype),d(fe,this.connection,"no this.connection"),this.ws,this.connection._initializeHandshake=function(){this.send({a:"hs",id:this.id,auth:t})};const o=this.connection.handleMessage.bind(this.connection);this.connection.handleMessage=r=>{var s;const i=r;if(this.connection&&(this.connection.lastReceiveTime=Date.now()),"err"in i||i.a==="pong")this.handleMessage(i);else{Object.prototype.hasOwnProperty.call(i,"a")&&i.a!=="init"&&i.a!=="hs"&&(this.retryCount=0);try{o(i)}catch(l){if((l==null?void 0:l.type)==="writeConflict"){this.emitWriteConflictError(l,i);return}if((s=l==null?void 0:l.message)!=null&&s.startsWith("Cannot invert subtype")){this.emitWriteConflictError(l,i);return}throw l}}},H2.apply(this.connection,[this.ws])}async handleAuthError(){if(this.reauthFunc&&this.retryCount<5){this.retryCount+=1,fe.info(`retrying re-auth attempt no. ${this.retryCount}`);try{if(this.connection){const t=await this.reauthFunc();await this.auth(t),this.connection._initializeHandshake=function(){this.send({a:"hs",id:this.id,auth:t})}}}catch(t){fe.error(t),setTimeout(()=>this.handleAuthError(),0)}}else fe.error("auth error, cannot retry anymore"),this.emitAuthError(),this.end(!1)}emitAuthError(){const t=new Error(kc.msg);t.code=kc.err,this.events.emit("error",t)}emitRequestReloadError(){const t=new Error(ms.msg);t.code=ms.err,this.events.emit("requestReloadError",t)}emitWriteConflictError(t,e){t.orgMsg=e,this.events.emit("writeConflictError",t)}emitMaxUsersError(){this.events.emit("maxUsersError"),this.end(!1)}handleMessage(t){const e=t;if(e.a==="pong")return;const o=e.err;if(o===kc.err)fe.warn("auth error"),this.handleAuthError();else if(o===Gu.err)fe.warn(Gu.msg),this.emitMaxUsersError();else if(o===ms.err){fe.warn(ms.msg);try{this.emitRequestReloadError()}catch(r){fe.error(`error occurred while process reload error: ${JSON.stringify(r)}`)}finally{this.end(!1)}}else fe.error(`unknown message received: ${JSON.stringify(e)}`),this.emitAuthError()}get(t,e){return d(fe,this.connection,"no this.connection"),this.connection.get(t,e)}addEventListener(t,e){t==="error"?this.events.addListener(t,e):(d(fe,this.ws,"no this.ws"),this.ws.addEventListener(t,e))}onWriteConflictError(t){this.events.addListener("writeConflictError",t)}onMaxUsersError(t){d(fe,this.events.listenerCount("maxUsersError")===0,"too many maxUserError listener"),this.events.addListener("maxUsersError",t)}onRequestReloadError(t){d(fe,this.events.listenerCount("requestReloadError")===0,"to many requestReloadError listener"),this.events.addListener("requestReloadError",t)}end(t){var e;this.reauthFunc=void 0,this.events.removeAllListeners(),gw(()=>{var o;return(o=this.connection)==null?void 0:o.close()}),this.connection=void 0,(e=this.ws)==null||e.close(),this.ws=void 0,t&&this.logout()}}B("utils/file");function Cw(){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}Cw();async function bw(n){const e=n.size,o=Math.floor((e+102400-1)/102400),r=new w7.Hash;for(let s=0;s<o;s++){const l=s*102400;let c=l+102400;c>e&&(c=e);const u=await n.slice(l,c,n.type).arrayBuffer();r.update(new Uint8Array(u))}const i=r.digest();return Ho(i)}const In=B("sharedb-doc/client");class kw{constructor(t,e,o){h(this,"connection");h(this,"auth");h(this,"doc",null);h(this,"reauthFunc");h(this,"clientId",N());h(this,"getDoc",async()=>{const t=o=>new Promise((r,i)=>{o.fetch(s=>{s?i(s):r()})});d(In,!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),In.debug(e),e});this.auth=t;const r=`${e}/${this.auth.appId}/${this.auth.docId}`;uw.register(gl.type),this.connection=new pw(r,o),this.reauthFunc=o}editorServer(){const t=this.apiServer(),e=`/${this.auth.appId}/${this.auth.docId}`;return d(In,t.endsWith(e),`invalid api server: ${t}, ${e}`),t.substr(0,t.length-e.length)}close(t){this.connection.end(t),this.doc=null}on(t,e){this.connection.addEventListener(t,o=>{(t==="error"||this.doc)&&e(o)})}onWriteConflictError(t){this.connection.onWriteConflictError(t)}onMaxUsersError(t){this.connection.onMaxUsersError(t)}onRequestReloadError(t){this.connection.onRequestReloadError(t)}async authOnly(){await this.connection.auth(this.auth)}getResourceToken(){return this.connection.resourceToken}hasDocContainer(){return!!this.doc}apiServer(){const t=this.connection.url;if(t.startsWith("ws://"))return`http://${t.substring(5)}`;if(t.startsWith("wss://"))return`https://${t.substring(6)}`;throw new Error(`invalid server url: ${t}`)}async getFileUrlByHash(t,e,o,r,i){try{const s=`${t}/${e}`,l=await this.request(s,{method:"post",headers:{...i},data:{name:o,size:r}});return l.data&&Array.isArray(l.data)&&l.data.length===1?l.data[0]:""}catch{return""}}async getFileUrlsByHashes(t){const o=`${this.apiServer()}/resources`;let r=[];t.forEach(l=>{const c=l.split("|");r.push(...c)}),r=Array.from(new Set(r));const i=r.map(l=>this.getFileUrlByHash(o,l,"",0,{[gs]:this.connection.token}));return await Promise.all(i)}async uploadFile(t,e,o,r,i){let s=e.size;if(s===0)throw new Error("file is empty");s+=500;const l=C=>{In.info(`on progress: ${C.loaded}`);let k=C.loaded*100/s;k>100&&(k=100),r(k)},c=await bw(e),a=await this.getFileUrlByHash(t,c,e.name,e.size,o);if(a)return r(-1),a;let u=t;i!=null&&i.thumbnail&&(u+="/thumbnail");const f=new FormData;f.append("file-size",`${e.size}`),f.append("file-hash",c),f.append("file",e,e.name);const m=await this.request(u,{method:"post",data:f,withCredentials:!0,headers:{...o},onUploadProgress:l});return In.info(m),r(100),Array.isArray(m.data)?m.data[0]:m.data}async uploadResource(t,e=()=>{},o){const i=`${this.apiServer()}/resources`;d(In,this.connection.token,"no connection token");const s=await this.uploadFile(i,t,{[gs]:this.connection.token},e,o);return d(In,s,"no result"),s}async request(t,e){var i,s;let o=this.connection.token,r;for(let l=0;l<2;l++){const c=e||{};c.url=t,c.headers||(c.headers={}),d(In,o,"no token"),c.headers={...c.headers,[gs]:o,[vc]:this.connection.getBase64BaseURL()};try{return await k7.default(t,c)}catch(a){if(r=a,((i=a==null?void 0:a.response)==null?void 0:i.status)===403&&this.reauthFunc){const u=await this.reauthFunc();if(await this.connection.auth(u),!u.token)throw a;o=u.token;continue}throw(s=a.response)!=null&&s.data&&(a.responseData=a.response.data),a}}throw d(In,r,"no error"),r}async getVersions(){const e=`${this.apiServer()}/versions`,o=await this.request(e),r=o.data.versions,i=o.data.latest;return i&&r.findIndex(s=>s.version===i)===-1&&r.unshift({version:-1,tag:"",published:!1}),r}async getVersion(t){const o=`${this.apiServer()}/versions/${t}`,r=await this.request(o);return JSON.parse(r.data.data)}async getLatestVersion(){const e=`${this.apiServer()}/versions/latest`,o=await this.request(e);return JSON.parse(o.data.data)}async getVersionOps(t,e){let r=`${this.apiServer()}/versions/before/${t}?withOp=true`;e!==void 0&&e!==0&&(r+=`&from=${e}`);const i=await this.request(r),s=i.data.ops,l=v7.default(s,u=>!!u.create);let c=null;l!==-1&&(c=s[l],s.splice(0,l+1));let a;return c?(d(In,c.create,"no createDoc.create"),a=c.create.data):a=JSON.parse(i.data.data),a.blocks||(a.blocks=[]),{doc:a,ops:i.data.ops}}async revertVersion(t){const o=`${this.apiServer()}/versions/revert/${t}`;await this.request(o,{method:"post",data:{}})}async createVersion(t,e){const r=`${this.apiServer()}/versions`;return(await this.request(r,{method:"post",data:{publish:e,tag:t}})).data}async recognizeLink(t){const o=`${this.apiServer()}/resources/external/${Ho(t)}`;return(await this.request(o)).data}buildResourceUrl(t,e){if(!t)return"";if(t.startsWith("https:")||t.startsWith("http:")||t.startsWith("file:")||t.startsWith("data:")||t.startsWith("blob:"))return t;let r=`${this.apiServer()}/resources/${encodeURIComponent(t)}`;const i=[];if(e!=null&&e.withToken&&i.push(`token=${this.getResourceToken()}`),e!=null&&e.downloadFileName&&i.push(`&fileName=${encodeURIComponent(e.downloadFileName)}`),i.length>0){const s=i.join("&");r+=`?${s}`}return r}}function vw(){return{blocks:[{id:N(),type:"text",text:[]}],comments:{},meta:{}}}const Zu=B("block-ids");class yw{constructor(){h(this,"ids",new Map)}onInsertBlock(t){const e=Array.from(this.ids.keys()).sort((r,i)=>i-r);for(let r=0;r<e.length;r++){const i=e[r];if(i>=t){const s=this.ids.get(i);d(Zu,s!==void 0,"old id is not exists"),this.ids.delete(i),this.ids.set(i+1,s)}}const o=N();this.ids.set(t,o)}onDeleteBlock(t){this.ids.delete(t);const e=Array.from(this.ids.keys()).sort((o,r)=>o-r);for(let o=0;o<e.length;o++){const r=e[o];if(r>t){const i=this.ids.get(r);d(Zu,i!==void 0,"old id is not exists"),this.ids.delete(r),this.ids.set(r-1,i)}}}getId(t){let e=this.ids.get(t);return e||(e=N(),this.ids.set(t,e)),e}getById(t){return Array.from(this.ids.entries()).find(([,e])=>e===t)}}class ww{constructor(){h(this,"ids",new Map)}getContainerIds(t){let e=this.ids.get(t);return e||(e=new yw,this.ids.set(t,e)),e}onInsertBlock(t,e){this.getContainerIds(t).onInsertBlock(e)}onDeleteBlock(t,e){this.getContainerIds(t).onDeleteBlock(e)}getBlockId(t,e){return this.getContainerIds(t).getId(e)}getBlockIndexById(t){const e=Array.from(this.ids.entries());for(let o=0;o<e.length;o++){const r=e[o],i=r[1].getById(t);if(i)return{containerId:r[0],blockIndex:i[0]}}return d(Zu,!1,"fault error: failed to get block index"),{containerId:"error",blockIndex:-1}}}class F2{constructor(t=new Set,e=new Map){this.deletedKeys=t,this.insertedValues=e}insert(t,e){this.insertedValues.set(t,e)}delete(t){this.deletedKeys.add(t)}toDocBlockDelta(){const t={};return this.insertedValues.forEach((e,o)=>{t[o]=e}),{insert:t,delete:Array.from(this.deletedKeys)}}}const $t=B("op-parser");function jr(n){return n==="blocks"?"root":n}class Bw{constructor(t,e){h(this,"updatingBlockDataDeltaMap",new Map);h(this,"blockIds",new ww);this.handler=t,this.local=e}onDeleteBlock(t,e){const o=this.blockIds.getBlockId(t,e);this.blockIds.onDeleteBlock(t,e);const r=this.updatingBlockDataDeltaMap.get(o);r&&($t.debug(`ignore update object data before delete block: ${JSON.stringify(r)}`),this.updatingBlockDataDeltaMap.delete(o)),this.handler.onDeleteBlock(jr(t),e,this.local)}onInsertBlock(t,e,o){this.blockIds.onInsertBlock(t,e),this.handler.onInsertBlock(jr(t),e,o,this.local)}onUpdateBlockText(t,e,o){this.handler.onUpdateBlockText(jr(t),e,o,this.local)}onDeleteBlockData(t,e,o){const r=this.blockIds.getBlockId(t,e);let i=this.updatingBlockDataDeltaMap.get(r);i||(i=new F2,this.updatingBlockDataDeltaMap.set(r,i)),i.delete(o)}onInsertBlockData(t,e,o,r){const i=this.blockIds.getBlockId(t,e);let s=this.updatingBlockDataDeltaMap.get(i);s||(s=new F2,this.updatingBlockDataDeltaMap.set(i,s)),s.insert(o,r)}executeUpdateBlockDataActions(){Array.from(this.updatingBlockDataDeltaMap.entries()).forEach(([t,e])=>{const{containerId:o,blockIndex:r}=this.blockIds.getBlockIndexById(t);this.handler.onUpdateBlockData(jr(o),r,e.toDocBlockDelta(),this.local)})}}class z2{}class Yu{constructor(t){h(this,"key");this.key=t}}function Ew(n,t,e){const o=t.concat(),r=o[0];if(typeof r!="number"||(o.shift(),o.length===1))return!1;const i=o[0];if(typeof i!="object"||!i.i||Object.keys(i).length!==1)return!1;for(let l=1;l<o.length;l++){const c=o[l];if(!Array.isArray(c)||c.length!==2||typeof c[0]!="string")return!1;const u=c[1];if(typeof u!="object"||u.i===void 0||Object.keys(u).length!==1)return!1}const s=i.i;d($t,s.id,"block id is required"),d($t,s.type,"block type is required");for(let l=1;l<o.length;l++){const c=o[l],a=c[0],u=c[1];s[a]=u.i}return e.onInsertBlock(n,r,s),!0}function Qu(n,t,e,o){if(e==="upsert"&&Ew(n,t,o))return;d($t,Array.isArray(t),`invalid block op: ${n}, ${JSON.stringify(t)}`);const r=t.concat(),i=r[0];r.shift();const s=[];for(;r.length>0;){const l=r[0];if(l==="text"){const c=r[1];if(d($t,typeof c=="object",`invalid block op: ${n}, ${JSON.stringify(t)}`),d($t,c.et==="rich-text",`invalid block op: ${n}, ${JSON.stringify(t)}`),r.splice(0,2),e==="upsert"){const u=c.e;o.onUpdateBlockText(n,i,u)}d($t,r.length===0,`invalid block ops.length !== 0, ${JSON.stringify(r)}`)}else if(Array.isArray(l)){d($t,l.length===2,`invalid block op: data.length !== 2, ${JSON.stringify(l)}`);const c=l[0];d($t,typeof c=="string",`invalid block op: key ${JSON.stringify(c)}`);const a=l[1];if(c==="text"){if(d($t,typeof a=="object",`invalid opData type, ${JSON.stringify(a)}`),a.i&&e==="upsert"&&o.onInsertBlockData(n,i,c,a.i),a.r&&e==="remove"&&o.onDeleteBlockData(n,i,c),a.et==="rich-text"&&e==="upsert"){const f=a.e;o.onUpdateBlockText(n,i,f)}}else e==="remove"&&a.r&&s.push(new Yu(c)),e==="upsert"&&a.i&&o.onInsertBlockData(n,i,c,a.i);r.shift()}else if(typeof l=="object"){const c=l;e==="remove"&&c.r&&s.push(new z2),e==="upsert"&&c.i&&o.onInsertBlock(n,i,c.i),r.shift()}else{d($t,typeof l=="string","data is not string"),d($t,l!=="text","data !== 'text'"),d($t,r.length===2,`invalid block op: ops.length !== 2, ${JSON.stringify(r)}`);const c=l,a=r[1];e==="remove"&&a.r&&s.push(new Yu(c)),e==="upsert"&&a.i&&o.onInsertBlockData(n,i,c,a.i),r.splice(0,2)}}s.reverse(),s.forEach(l=>{l instanceof z2?o.onDeleteBlock(n,i):l instanceof Yu?o.onDeleteBlockData(n,i,l.key):d($t,!1,`invalid action type: ${typeof l}, ${JSON.stringify(l)}`)})}function Iw(n,t,e,o){$t.warn(`unsupported meta op, ${JSON.stringify(n)}`)}function xw(n,t,e,o){const r=n[1],i=n[2];d($t,r,`invalid comment op, no commentId: ${JSON.stringify(n)}`),d($t,i,`invalid comment op, no actions: ${JSON.stringify(n)}`),typeof i=="string"?$t.error(`unknown comment op, ${JSON.stringify(n)}`):i.i&&i.r?t==="upsert"&&o.onUpdateComment(r,e.local):i.i?t==="upsert"&&o.onCreateComment(r,e.local):i.r?t==="remove"&&o.onDeleteComment(r,e.local):$t.error(`unknown comment op, ${JSON.stringify(n)}`)}function Ku(n,t,e,o){const r=n[0];if(Array.isArray(r)){r.forEach(l=>{Ku(l,t,e,o)});return}const i=r;if(d($t,typeof i=="string",`invalid container id: ${JSON.stringify(n)}`),i==="meta"){Iw(n);return}if(i==="comments"){xw(n,t,e,o);return}const s=i;if(Array.isArray(n[1]))t==="remove"?n.slice(1).reverse().forEach(l=>{Qu(s,l,t,e)}):n.slice(1).forEach(l=>{Qu(s,l,t,e)});else if(typeof n[1]=="object"){const l=n[1];l.r&&t==="remove"&&o.onDeleteContainer(jr(s),e.local),l.i&&t==="upsert"&&o.onCreateContainer(jr(s),l.i,e.local)}else d($t,typeof n[1]=="number",`invalid ops[1], not a number: ${JSON.stringify(n)}`),Qu(s,n.slice(1),t,e)}function U2(n,t,e){const o=new Bw(t,e);for(let r=0;r<2;r++){const i=r===0?"remove":"upsert",s=Y.default(n),l=s[0];Array.isArray(l)?s.forEach(c=>{Ku(c,i,o,t)}):Ku(s,i,o,t)}o.executeUpdateBlockDataActions()}const Tw=B("sharedb-comments");function Ju(n){if(n.doc)return Y.default(n.doc);const t=n.blocks;d(Tw,t,"no comment blocks");const e={blocks:{root:t},meta:{},comments:{}};return Object.entries(n).forEach(([o,r])=>{Array.isArray(r)&&(e.blocks[o]=r)}),Y.default(e)}function V2(n){const{id:t,groupId:e,userId:o,displayName:r,avatarUrl:i,abstract:s,created:l,modified:c}=n;return{id:t,groupId:e,userId:o,displayName:r,avatarUrl:i,abstract:s,created:l,modified:c}}function Xu(n,t){const e={...n,doc:t};return delete e.blocks,Y.default(e)}const vt=B("sharedb-doc/doc-container"),q2="ot-json1";gl.type.registerSubtype(hy.type),gl.type.name=q2,gl.type.invert=null;class ps extends Di{constructor(e,o,r=!0){super();h(this,"doc");h(this,"client");h(this,"localPresence");h(this,"remoteCaretHandler",new dy);h(this,"batching",0);h(this,"status","clean");h(this,"disableLogout");h(this,"destroyed",!1);h(this,"handleNothingPending",()=>{this.setStatus("clean")});h(this,"handleCreate",()=>{this.handleReload("doc created")});h(this,"handleDel",()=>{});h(this,"handleReload",e=>{this.callbacks.forEach(o=>{var r;return(r=o.onRequestReload)==null?void 0:r.call(o,e)})});h(this,"handleReset",async e=>{const o=new Error(`reset doc: ${e}`);o.code="ResetDoc",this.callbacks.forEach(r=>{var i;return(i=r.onError)==null?void 0:i.call(r,o)}),this.destroy()});h(this,"handleWriteConflictError",e=>{this.handleReset(`write conflict: ${e.message}, ${JSON.stringify(e.orgMsg)}`)});h(this,"insertObject",async(e,o,r)=>{const i=[e,o,{i:r}];return this.submitOp(i)});h(this,"deleteObject",async(e,o)=>{const r=[e,o,{r:!0}];return this.submitOp(r)});h(this,"replaceObject",async(e,o,r)=>{const i=[e,o,{r:!0,i:r}];return this.submitOp(i)});h(this,"updateObject",async(e,o,r)=>{const i=this.data()[e][o],s=[e,o];return Object.entries(r).forEach(([l,c])=>{if(!ml.default(i[l],c))if(i[l]===void 0){if(c!=null){const a={i:c};s.push([l,a])}}else if(c==null){const a={r:!0};s.push([l,a])}else{const a={r:!0,i:c};s.push([l,a])}}),Object.entries(i).forEach(([l,c])=>{if((r[l]===void 0||r[l]===null)&&c!==void 0){const a={r:!0};s.push([l,a])}}),s.length<=2?Promise.resolve():this.submitOp(s)});h(this,"broadcastMessage",async e=>{const o={type:"custom",data:e,clientId:this.client.clientId};this.localPresence&&this.localPresence.submit(o)});h(this,"data",()=>this.doc.data);h(this,"submitOp",async e=>new Promise((o,r)=>{if(this.destroyed){vt.warn("submit op after destroyed");return}this.setStatus("dirty"),this.doc.submitOp(e,{},i=>{i?(vt.error(`invalid op, ${i.message}, ${JSON.stringify(e)}`),r(i),vt.error("Transform detected write conflict, reload editor"),this.handleReset("write conflict")):o()}),this.doc.data||(vt.error("no data after submit op, may be the submitted op is invalid"),this.handleReset(`invalid op, ${JSON.stringify(e)}`))}));h(this,"createDoc",async e=>new Promise((o,r)=>{this.doc.create(e,q2,i=>{i?r(i):o()})}));h(this,"submitInsertChildContainer",async(e,o)=>{const r=[Co(e),{i:o}];return this.submitOp(r)});h(this,"submitDeleteChildContainer",async e=>{const o=[Co(e),{r:!0}];return this.submitOp(o)});h(this,"submitInsertBlock",async(e,o,r)=>{const i=[Co(e),o,{i:r}];return this.submitOp(i)});h(this,"submitDeleteBlock",async(e,o)=>{const r=[Co(e),o,{r:!0}];return this.submitOp(r)});h(this,"submitUpdateBlockData",async(e,o,r)=>{if(r.delete.length===0&&Object.keys(r.insert).length===0)return Promise.resolve();const i=[Co(e),o],s=new Set(r.delete);Object.entries(r.insert).forEach(([c,a])=>{if(s.has(c)){const u={r:!0,i:a};i.push([c,u])}});const l=new Set(Object.keys(r.insert));return r.delete.forEach(c=>{if(l.has(c))return;const a={r:!0};i.push([c,a])}),Object.entries(r.insert).forEach(([c,a])=>{if(s.has(c))return;const u={i:a};i.push([c,u])}),this.submitOp(i)});h(this,"submitUpdateRichText",async(e,o,r)=>{const i=[Co(e),o,"text",{e:r,et:"rich-text"}];return this.submitOp(i)});h(this,"handleOp",(e,o,r)=>{if(this.destroyed){vt.warn("handleOp: destroyed");return}U2(e,this,!!o)});this.client=e,this.doc=o,this.doc.preventCompose=!0,this.disableLogout=r,this.registerCallback(this.remoteCaretHandler)}beginBatchUpdate(){return this.doc.preventCompose=!1,this.batching++,this.batching}endBatchUpdate(){return this.batching--,d(vt,this.batching>=0,"invalid call beginBatchUpdate/endBatchUpdate"),this.batching===0&&(this.doc.preventCompose=!0),this.batching}static async load(e){try{const o=new kw(e.auth,e.serverUrl,e.reauthFunc),r=await o.getDoc(),i=new ps(o,r,e.disableLogout);if(r.type===null){if(e.autoCreateDoc===!1){const s=new Error("doc not exists");throw s.code="DocNotExists",s}await i.createDoc(e.templateData||vw())}return await i.initPresence(),await i.subscribe(),i.initEvents(),i}catch(o){throw vt.error(o),vt.error(`failed to load doc: ${JSON.stringify(o)}`),o}}setStatus(e){this.status!==e&&(this.status=e,this.callbacks.forEach(o=>{var r;return(r=o.onStatusChanged)==null?void 0:r.call(o,e)}))}initEvents(){this.doc.on("nothing pending",this.handleNothingPending),this.doc.on("create",this.handleCreate),this.doc.on("del",this.handleDel),this.client.onWriteConflictError(this.handleWriteConflictError)}clearEvents(){this.doc.off("nothing pending",this.handleNothingPending),this.doc.off("create",this.handleCreate),this.doc.off("del",this.handleDel)}initPresence(){return new Promise((e,o)=>{if(this.localPresence)e();else{const r=this.doc.connection.getPresence(`${this.doc.collection}:${this.doc.id}`);r.on("receive",(i,s)=>{this.onCustomMessage(s)}),r.subscribe(i=>{i?o(i):(this.localPresence=r.create(N()),e())})}})}subscribe(){return new Promise((e,o)=>{this.doc.subscribe(r=>{r?o(r):(this.doc.on("op",this.handleOp),e())})})}toJSON(){return rs(this.data())}getContainerBlocks(e){const o=this.data();d(vt,o,"no doc data");const r=o[Co(e)];return d(vt,r,`no container data: ${e}`),Y.default(r)}getBlockData(e,o){const r=this.data();d(vt,r,"no doc data");const i=r[Co(e)];d(vt,i,`no container data: ${e}`);const s=i[o];return d(vt,s,`no block data: ${o}`),Y.default(s)}localInsertBlock(e,o,r){return this.submitInsertBlock(e,o,r),this.getBlockData(e,o)}localDeleteBlock(e,o){const r=this.getBlockData(e,o);return this.submitDeleteBlock(e,o),r}localUpdateBlockText(e,o,r){const i=this.getBlockData(e,o);d(vt,i.text,"no block text");const s=Y.default(i.text);this.submitUpdateRichText(e,o,r);const l=ie.apply(s,r);return d(vt,l,"no block text"),l}localUpdateBlockData(e,o,r){const i=Y.default(this.getBlockData(e,o));return this.submitUpdateBlockData(e,o,r),i}localInsertChildContainer(e,o){this.submitInsertChildContainer(e,o)}localDeleteChildContainers(e){this.beginBatchUpdate(),e.forEach(o=>{this.submitDeleteChildContainer(o)}),this.endBatchUpdate()}getComments(){return Object.values(this.data().comments).map(o=>V2(o))}getComment(e){return this.data().comments[e]}getCommentDoc(e){const o=this.data().comments[e];return Ju(o)}localCreateComment(e,o){const r=Xu(e,o),s=["comments",r.id,{i:r}];return this.submitOp(s)}localDeleteComment(e){const o=["comments",e,{r:!0}];return this.submitOp(o)}localUpdateComment(e,o){const r=Xu(e,o),i=["comments",e.id,{r:!0,i:r}];return this.submitOp(i)}destroy(){var e;this.destroyed=!0,this.clearEvents(),this.clearCallbacks(),this.doc.destroy(),(e=this.localPresence)==null||e.destroy(),this.client.close(!this.disableLogout),this.remoteCaretHandler.destroy()}onDeleteBlock(e,o,r){d(vt,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(i=>{var s;return(s=i.onDeleteBlock)==null?void 0:s.call(i,Nr(e),o,r)})}onInsertBlock(e,o,r,i){d(vt,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onInsertBlock)==null?void 0:l.call(s,Nr(e),o,r,i)})}onUpdateBlockData(e,o,r,i){d(vt,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockData)==null?void 0:l.call(s,Nr(e),o,r,i)})}onUpdateBlockText(e,o,r,i){d(vt,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockText)==null?void 0:l.call(s,Nr(e),o,r,i)})}onDeleteContainer(e,o){d(vt,this.callbacks.length>0,"no callbacks"),d(vt,e!=="root","should not delete root container in doc"),this.callbacks.forEach(r=>{var i;return(i=r.onDeleteChildContainer)==null?void 0:i.call(r,Nr(e),o)})}onCreateContainer(e,o,r){d(vt,this.callbacks.length>0,"no callbacks"),d(vt,e!=="root","should not create root container in doc"),this.callbacks.forEach(i=>{var s;return(s=i.onInsertChildContainer)==null?void 0:s.call(i,Nr(e),o,r)})}onDeleteComment(e,o){d(vt,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(r=>{var i;return(i=r.onDeleteComment)==null?void 0:i.call(r,e,o)})}onCreateComment(e,o){d(vt,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(r=>{var i;return(i=r.onCreateComment)==null?void 0:i.call(r,e,o)})}onUpdateComment(e,o){d(vt,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(r=>{var i;return(i=r.onUpdateComment)==null?void 0:i.call(r,e,o)})}onCustomMessage(e){const o=e;(o==null?void 0:o.type)==="custom"&&(o==null?void 0:o.clientId)!==this.client.clientId?this.callbacks.forEach(r=>{var i;return(i=r.onCustomMessage)==null?void 0:i.call(r,o.data)}):(o==null?void 0:o.type)==="onlineUsers"&&setTimeout(()=>{const r={type:"custom",data:e,clientId:"-"};this.onCustomMessage(r)})}async addResources(e){return await this.client.getFileUrlsByHashes(e)}async uploadResource(e,o){var i;return{resourceId:await this.client.uploadResource(e,(i=o==null?void 0:o.onProgress)!=null?i:()=>{})}}buildResourceUrl(e,o){return this.client.buildResourceUrl(e,o)}request(e,o){return this.client.request(e,o)}getUser(){const e=this.client.clientId,{permission:o,userId:r,displayName:i,avatarUrl:s}=this.client.auth;return{permission:o,clientId:e,userId:r,displayName:i,avatarUrl:s,rainbowIndex:0}}getRemoteUsers(){return this.remoteCaretHandler.remoteUsers}getVersionHelper(){return this}getVersions(){return this.client.getVersions()}async getVersion(e){const o=await this.client.getVersion(e);return rs(o)}async getLatestVersion(){const e=await this.client.getLatestVersion();return rs(e)}async getHistoryData(e,o){const{doc:r,ops:i}=await this.client.getVersionOps(e,o),s=i.map(l=>({user:l.meta.createdBy,data:l}));return{doc:rs(r),historyData:s}}async getVersionData(e,o){const{doc:r,ops:i}=await this.client.getVersionOps(e,o);return{doc:rs(r),versionData:i}}revertVersion(e){return this.client.revertVersion(e)}createVersion(e,o){return this.client.createVersion(e,o)}async recognizeLink(e){return this.client.recognizeLink(e)}parseHistoryData(e,o){U2(e.data.op,o,!0)}getServerMeta(){return{appId:this.client.auth.appId,docId:this.client.auth.docId,serverId:this.client.apiServer()}}}B("remote-cursor");class W2{constructor(t){h(this,"handleDocSelectionChange",()=>{this.broadcastCaretPos()});h(this,"broadcastCaretPos",Xt.default(()=>{const t={type:"caret",userId:this.editor.doc.getUser().userId,range:this.editor.selection.range.toDocRange()};this.editor.doc.broadcastMessage(t)},300));h(this,"handleRemoteCaretsChanged",t=>{t.forEach(e=>{const o=this.editor.findBlockById(e);o&&this.editor.reloadBlock(o)})});this.editor=t,this.editor.addListener("selectionChanged",this.handleDocSelectionChange),this.editor.doc.getRemoteUsers().addListener("remote-carets-change",this.handleRemoteCaretsChanged)}destroy(){this.editor.removeListener("selectionChanged",this.handleDocSelectionChange),this.editor.doc.getRemoteUsers().removeListener("remote-carets-change",this.handleRemoteCaretsChanged)}}const G2=B("remote-cursor-decorator");class th{decorateText(t,e,o){const r=t.doc.getRemoteUsers();if(!r)return{};const i=new Map,{containerId:s,blockIndex:l}=e[e.length-1];d(G2,typeof s=="string","invalid path containerId"),d(G2,typeof l=="number","invalid path blockIndex");const c=t.doc.getBlockData(s,l),a=ue(o);return r.getSimpleCursors(c.id).forEach((f,m)=>{m>a&&(m=a);const C=f.map(w=>({id:N(),type:"remote-cursor",name:w.user.displayName,time:w.time,rainbowIndex:w.user.rainbowIndex})),k=i.get(m);k?k.push(...C):i.set(m,C)}),{insertions:i}}}class Z2 extends Yt.TypedEmitter{constructor(t){super(),this.editor=t,this.editor.doc.registerCallback(this)}handleChild(t,e,o){if(pt(Er(this.editor,t)))return;const r=this.editor.getBlockByIndex(t,e),i=F(this.editor.getContainerById(t));i&&this.emit("change",this.editor,i,r,o)}onUpdateBlockData(t,e){this.handleChild(t,e,"data-change")}onUpdateBlockText(t,e){this.handleChild(t,e,"text-change")}destroy(){this.editor.doc.unregisterCallback(this)}}function Sw(n,t){n.addCustom("child-block-tracker",()=>new Z2(n)).addListener("change",t)}function Dw(n,t){n.addCustom("child-block-tracker",()=>new Z2(n)).removeListener("change",t)}const uz="",Lw={colorPalette:{colorDesc:"\u5B57\u4F53\u989C\u8272",backgroundDesc:"\u80CC\u666F\u989C\u8272",reset:"\u6062\u590D\u9ED8\u8BA4",name:"\u6587\u672C\u989C\u8272"},search:{emptyTips:"\u6682\u65E0\u641C\u7D22\u7ED3\u679C"}},Mw={colorPalette:{colorDesc:"Text Color",name:"Text Color",backgroundDesc:"Background Color",reset:"Reset"},search:{emptyTips:"\u6682\u65E0\u641C\u7D22\u7ED3\u679C"}};T.mergeLang({"zh-CN":Lw,"en-US":Mw});const hz="";B("button");function vo(n,t,e,o,r){const i=b("button",["editor-button"],null);return i.setAttribute("data-button-id",n),r&&i.setAttribute(`data-editor-tooltip-${r}`,t),e?typeof e=="string"?e.startsWith("<")?i.innerHTML=e:i.innerText=e:i.appendChild(e):i.innerText=t,o&&(o.indexOf("checked")!==-1&&A(i,"checked"),o.indexOf("disabled")!==-1&&(i.disabled=!0)),i}function Y2(n,t,e){e?n.setAttribute(`data-editor-tooltip-${e}`,t):n.innerText=t}const fz="",Hr=B("ui-command-bar-base"),Rw={itemElementTag:"div",tippyArrow:!1},Tf=class extends Yt.TypedEmitter{constructor(e,o,r){var i,s;super();h(this,"content");h(this,"items");h(this,"subBar",null);h(this,"parentItem",null);h(this,"closeable",null);h(this,"options");h(this,"id");h(this,"handleDocumentKeydown",e=>{if(!!this.isVisible&&!e.isComposing){if(this.subBar){this.subBar.handleDocumentKeydown(e);return}if(this.items.length!==0){if(e.key==="Escape"){this.close();return}if(e.key==="ArrowUp"){const o=this.getPrevItemIndex(this.getSelectedItemIndex());this.selectItem(this.items[o].id),e.preventDefault(),e.stopPropagation()}else if(e.key==="ArrowDown"){const o=this.getNextItemIndex(this.getSelectedItemIndex());this.selectItem(this.items[o].id),e.preventDefault(),e.stopPropagation()}else if(e.key==="ArrowRight"){const o=this.getSelectedItem();o&&o.children&&this.showSubCommandBar(o.childrenMenuId)}else if(e.key==="ArrowLeft")this.parentItem&&this.close();else if(e.key==="Enter"){const o=this.getSelectedItemIndex();if(o===-1)return;const r=this.items[o],i=this.getItemElementById(r.id);i&&this.emit("click",this,r,i)}}}});h(this,"handleDocumentMouseDown",e=>{e.target instanceof Element&&(this.isInCommandBar(e.target)||this.close())});h(this,"handleHidden",()=>{this.close(),this.emit("close",this),Lm(this.id)});h(this,"handleShow",()=>{this.popper&&(this.popper.setAttribute("data-command-bar-id",this.id),this.options.classes&&A(this.popper,...this.options.classes),this.options.refuseOverflow&&this.popper.classList.add("reference-hidden")),this.emit("show",this),this.options.disablePageScroll&&Dm(this.id)});h(this,"handleItemMouseEnter",e=>{const o=this.getParentCommandItemElement(e.target);if(!o)return;const r=this.getItemElementId(o),i=this.getItemById(r);if(this.selectItem(r),i.manualShowChildren)return;const s=i.childrenMenuId||"";this.showSubCommandBar(s)});h(this,"handleItemMouseLeave",e=>{var r,i;const o=this.getParentCommandItemElement(e.target);!o||((i=(r=this.subBar)==null?void 0:r.parentItem)==null?void 0:i.id)!==this.getItemElementId(o)&&(z(o,"selected"),this.emit("selectionChange",this,""))});h(this,"handleItemClick",e=>{const o=this.getParentCommandItemElement(e.target);if(!o)return;const r=this.getItemElementId(o),i=this.items.find(s=>s.id===r);if(!!i&&!(i.states&&i.states.indexOf("disabled")!==-1)){if(i.children&&i.children.length>0&&i.manualShowChildren){this.showSubCommandBar(i.childrenMenuId);return}i.element||(this.emit("click",this,i,o),this.options.autoClose&&this.close())}});h(this,"handleWheel",e=>{if(!this.options.disablePageScroll&&!document.querySelector(".editor-disable-scroll"))return;const o=e.target;if(!o||!(o instanceof Node))return;const r=o instanceof HTMLElement?o:o.parentElement;if(!r)return;const i=We(r);if(!It(this.content,i)){e.stopPropagation(),e.preventDefault();return}e.deltaY<0?i.scrollTop===0&&(e.stopPropagation(),e.preventDefault()):e.deltaY>0&&i.scrollTop+i.clientHeight>=i.scrollHeight&&(e.stopPropagation(),e.preventDefault())});this.id=(i=r==null?void 0:r.id)!=null?i:N(),this.options={...Rw,...r},this.items=e,this.parentItem=(s=r==null?void 0:r.parentItem)!=null?s:null,this.closeable=o!=null?o:null,this.content=this.createCommandBarContent(e)}close(){this.subBar&&this.subBar.close(),document.removeEventListener("keydown",this.handleDocumentKeydown),document.removeEventListener("mousedown",this.handleDocumentMouseDown)}click(e,o){this.emit("click",this,e,o)}createPopperOptions(){var r;const e={modifiers:[]},o=this.options.overflowBoundary;return o&&((r=e==null?void 0:e.modifiers)==null||r.push({name:"flip",options:{boundary:o,fallbackPlacements:["top","bottom"]}})),e}destroy(){var e;this.close(),this.removeAllListeners(),(e=this.subBar)==null||e.destroy(),this.subBar=null,this.closeable=null,this.content.removeEventListener("wheel",this.handleWheel)}get isSubCommandBar(){return!!this.parentItem}updateItems(e){var r;this.subBar&&e.findIndex(s=>{var l,c;return s.id===((c=(l=this.subBar)==null?void 0:l.parentItem)==null?void 0:c.id)})===-1&&((r=this.subBar)==null||r.destroy(),this.subBar=null),this.items=e;const o=this.createCommandBarContent(e);this.content.innerHTML="",Array.from(o.children).forEach(i=>{this.content.appendChild(i)})}get popper(){return this.content.closest("[data-tippy-root]")}getSelectedItemIndex(){const e=this.getSelectedItem();return e?this.items.indexOf(e):-1}getPrevItemIndex(e){if(e<=0)return this.items.length-1;let o=e-1;for(;;){const r=this.items[o].type;if(r!=="separator"&&r!=="section")return o;if(o-=1,o<=0)return this.items.length-1}}getNextItemIndex(e){let o=e+1;for(;;){if(!this.items[o])return this.getNextItemIndex(-1);const r=this.items[o].type;if(r!=="separator"&&r!=="section")return o;if(o+=1,o>this.items.length-1)return 0}}clearSelectedItem(){const e=this.getSelectedItem();if(!e)return;const o=this.getItemElementById(e.id);o&&z(o,"selected")}selectItem(e){const o=this.getSelectedItem();if(o){if(o.id===e)return;const i=o.id,s=this.getItemElementById(i);s&&z(s,"selected")}const r=this.getItemElementById(e);r?(A(r,"selected"),this.emit("selectionChange",this,r.getAttribute("data-id")||""),r.scrollIntoView({block:"nearest"})):this.emit("selectionChange",this,"")}showSubCommandBar(e){var s,l;const o=this.getSelectedItem();if(!o)return;if(this.subBar){if(((s=this.subBar.parentItem)==null?void 0:s.id)===o.id){o.manualShowChildren&&this.subBar.close();return}this.subBar.destroy(),this.subBar=null}if(!o.children)return;const r=this.getItemElementById(o.id);if(!r)return;const i=Tf.createSubCommandBar(o,(l=this.closeable)!=null?l:this,e?{id:e}:{});this.subBar=i,this.subBar.on("click",(c,a,u)=>{this.emit("click",c,a,u)}),this.subBar.on("close",()=>{var c;(c=this.subBar)==null||c.destroy(),this.subBar=null,z(r,"active")}),o.beforePopup&&o.beforePopup(i),this.subBar.manualShow(r,this.getSubBarOptions(o)),A(r,"active")}isInCommandBar(e){if(!e||!(e instanceof Node))return!1;const o=this.getCommandBarRoot();return o&&It(o,e)||It(this.content,e)?!0:this.subBar?this.subBar.isInCommandBar(e):!1}createCommandItem(e){var i,s,l,c;let o=(i=this.options.itemElementTag)!=null?i:"div";e.element&&(o="div");const r=b(o,["command-item"],null);return r.setAttribute("data-id",e.id),e.type==="separator"?r.classList.add("separator"):e.type==="section"?(r.classList.add("section","text"),e.element&&(typeof e.element=="function"?r.appendChild(e.element(e)):r.appendChild(e.element))):((s=e.states)!=null&&s.includes("selected")&&r.classList.add("selected"),(l=e.states)!=null&&l.includes("checked")&&r.classList.add("checked"),(c=e.states)!=null&&c.includes("disabled")&&r.classList.add("disabled"),r.onclick=this.handleItemClick,r.onmouseenter=this.handleItemMouseEnter,r.onmouseleave=this.handleItemMouseLeave,e.element?typeof e.element=="function"?r.appendChild(e.element(e)):r.appendChild(e.element):r.classList.add("standard")),this.initItemElement(e,r),r}getItemById(e){const o=this.items.find(r=>r.id===e);return d(Hr,o,`can not find command item for id: ${e}`),o}getSelectedItem(){const e=this.content.querySelector(":scope >.editor-command-bar >.command-item.selected");if(e){const o=this.getItemElementId(e),r=this.items.find(i=>i.id===o);return d(Hr,r,`can not find command item for id: ${o}`),r}return null}getItemElementId(e){const o=e.getAttribute("data-id");return d(Hr,o,"no data-id attribute"),o}getItemElementById(e){const o=this.content.querySelector(`:scope >.editor-command-bar > .command-item[data-id="${e}"]`);return d(Hr,o,`no exists command item, id=${e}`),o}getParentCommandItemElement(e){if(!e||!(e instanceof Element))return null;if(nt(e,"command-item"))return e;const o=e.closest(".command-item");return o||null}createCommandBarContent(e){this.content&&this.content.removeEventListener("wheel",this.handleWheel);const o=b("div",["editor-command-bar-root"],null),r=b("div",["editor-command-bar"],o);return e.forEach(i=>{var l;const s=this.createCommandItem(i);r.appendChild(s),i.element&&i.setCloseable&&i.setCloseable((l=this.closeable)!=null?l:this)}),this.initCommandBarElement(r),o.addEventListener("wheel",this.handleWheel,{passive:!1}),o}getSubBarOptions(e){var o;return{placement:(o=e.childrenPlacement)!=null?o:"right-start"}}static registerManualCommandBar(e,o){this.commandBarCreators.set(e,o)}static createSubCommandBar(e,o,r){var l;d(Hr,e.children&&e.children.length>0,"no item children");const i=(l=e.childrenType)!=null?l:"menu",s=this.commandBarCreators.get(i);return d(Hr,s,`no creator for command type: ${i}`),s(e,o,r)}static hasExistsCommandBar(){return!!document.querySelector("[data-command-bar-id]")}};let Fr=Tf;h(Fr,"commandBarCreators",new Map),B("ui-command-bar");class yc extends Fr{constructor(){super(...arguments);h(this,"tippyInstance",null)}manualShow(e,o){var r,i;if(!this.isVisible){if(this.tippyInstance&&(this.tippyInstance.destroy(),this.tippyInstance=null),this.tippyInstance=B7.default(e,{interactive:!0,content:this.content,trigger:"manual",triggerTarget:null,hideOnClick:!1,placement:(r=o==null?void 0:o.placement)!=null?r:"bottom-start",maxWidth:650,arrow:this.options.tippyArrow,appendTo:document.body,onShow:this.handleShow,onHidden:this.handleHidden,theme:o==null?void 0:o.theme,getReferenceClientRect:o==null?void 0:o.getReferenceClientRect,offset:(i=o==null?void 0:o.offset)!=null?i:[0,0],popperOptions:this.createPopperOptions()}),o!=null&&o.point){const{x:s,y:l}=o.point;this.tippyInstance.setProps({getReferenceClientRect:()=>new DOMRect(s,l,0,0)})}this.clearSelectedItem(),this.tippyInstance.show(),this.parentItem||(document.addEventListener("keydown",this.handleDocumentKeydown),document.addEventListener("mousedown",this.handleDocumentMouseDown)),this.popper&&this.options.id&&this.popper.setAttribute("data-command-bar-id",this.options.id)}}close(){var e;super.close(),this.isVisible&&((e=this.tippyInstance)==null||e.hide())}destroy(){var e;(e=this.tippyInstance)==null||e.destroy(),this.tippyInstance=null,super.destroy()}getCommandBarRoot(){return this.content.closest("[data-tippy-root]")}get isVisible(){var e,o;return(o=(e=this.tippyInstance)==null?void 0:e.state.isVisible)!=null?o:!1}get popper(){return this.content.closest("[data-tippy-root]")}}const Q2=B("ui-base");class Cs extends yc{constructor(t,e){var i;const r=[{id:(i=e==null?void 0:e.id)!=null?i:`popup-${N()}`,name:"",element:t}];super(r,void 0,{disablePageScroll:!0})}initCommandBarElement(t){A(t,"popper")}initItemElement(t,e){}get popupContent(){const t=this.items[0];d(Q2,t,"no dialog item");const e=typeof t.element=="function"?t.element(t):t.element;return d(Q2,e,"no item element"),e}}const yo=B("filterable-list");function Aw(n){var e;const t=b("div",["list-item"],null);return t.setAttribute("data-id",n.id),t.appendChild(b("div",["list-item-text"],null,n.name)),(e=n.states)!=null&&e.includes("selected")&&A(t,"selected"),t}function K2(n){const t=b("div",["list-root"],null);return n.forEach(e=>{t.appendChild(Aw(e))}),t}function J2(n,t){let e=n;return t&&(e=n.map(o=>({...o,states:o.id===t?["selected"]:void 0}))),e}function Ow(n,t){const e=b("div",["filterable-list"],null),o=b("div",["filter"],e),r=b("div",["filter-container"],o),i=b("input",["filter-input"],r);t&&t.placeholder&&(i.placeholder=t.placeholder);const s=b("div",["list"],e),l=K2(J2(n,t==null?void 0:t.initialSelectedId));return s.appendChild(l),e}function X2(n,t,e){const o=n.querySelector(".list");d(yo,o,"no list root");const r=K2(J2(t,e)),i=o.querySelector(".list-root");if(d(yo,i,"no exists menu"),Oi(i,r),e){const s=o.querySelector(".list-item.selected");s&&(d(yo,s,"no selected menu item"),s.scrollIntoView({block:"nearest"}))}}class _w{constructor(t,e){h(this,"root");h(this,"visibleItems");h(this,"selectedId");h(this,"filter","");h(this,"onSelected",null);h(this,"handleKeydown",t=>{this.processKeyDown(t)});h(this,"handleInputChanged",()=>{const t=this.root.querySelector(".filter-input");d(yo,t,"no input");const e=t.value.toLocaleLowerCase();this.setFilter(e)});h(this,"handleClick",t=>{this.processClick(t)});var o;this.items=t,this.options=e,this.root=Ow(t,e),this.bindEvents(),this.selectedId=(o=e==null?void 0:e.initialSelectedId)!=null?o:"",this.visibleItems=t}bindEvents(){const t=this.root.querySelector(".filter-input");d(yo,t,"no input"),t.addEventListener("keyup",this.handleInputChanged),t.addEventListener("keydown",this.handleKeydown),this.root.addEventListener("click",this.handleClick)}unbindEvents(){const t=this.root.querySelector(".filter-input");d(yo,t,"no input"),t.removeEventListener("keyup",this.handleInputChanged),t.removeEventListener("keydown",this.handleKeydown),this.root.removeEventListener("click",this.handleClick)}destroy(){this.unbindEvents(),this.onSelected=null}getSelectedIndex(){return this.selectedId?this.visibleItems.findIndex(t=>t.id===this.selectedId):-1}setSelectedId(t){this.selectedId=t,X2(this.root,this.visibleItems,t)}focus(){const t=this.root.querySelector(".filter-input");d(yo,t,"no input"),t.focus()}reset(){this.setFilter("");const t=this.root.querySelector(".filter-input");d(yo,t,"no input"),t.value=""}setFilter(t){this.filter!==t&&(this.filter=t,this.visibleItems=this.items.filter(e=>e.name.toLocaleLowerCase().includes(t)),X2(this.root,this.visibleItems,this.selectedId))}processClick(t){var s,l;const e=t.target;if(!(e instanceof HTMLElement))return;const o=e.closest(".list-item");if(!o)return;const r=(s=o.getAttribute("data-id"))!=null?s:"",i=(l=this.visibleItems.find(c=>c.id===r))!=null?l:null;this.onSelected&&this.onSelected(this,i)}processKeyDown(t){var e;if(t.key==="ArrowUp"){let o=this.getSelectedIndex();o===-1?o=this.visibleItems.length-1:o>0&&(o-=1);let r="";o!==-1&&(r=this.visibleItems[o].id),this.setSelectedId(r);return}if(t.key==="ArrowDown"){let o=this.getSelectedIndex();o===-1?o=0:o<this.visibleItems.length-1&&(o+=1);let r="";o!==-1&&(r=this.visibleItems[o].id),this.setSelectedId(r);return}if(t.key==="Enter"){const o=(e=this.visibleItems.find(r=>r.id===this.selectedId))!=null?e:null;this.onSelected&&this.onSelected(this,o)}}}class Nw extends _w{constructor(e,o,r){super(e,r);h(this,"popup");h(this,"onShow",null);h(this,"onHide",null);h(this,"custom",null);h(this,"handleShow",()=>{this.onShow&&this.onShow(this)});h(this,"handleHide",()=>{this.onHide&&this.onHide(this)});h(this,"handleShown",()=>{this.focus()});this.popup=new Cs(this.root)}destroy(){super.destroy(),this.onShow=null,this.onHide=null}show(e){this.reset(),this.popup.manualShow(e,{theme:"dropdown-list"}),this.focus()}processKeyDown(e){super.processKeyDown(e),(e.key==="Esc"||e.key==="Enter")&&this.popup.close()}processClick(e){super.processClick(e);const o=e.target;!(o instanceof HTMLElement)||!o.closest(".list-item")||this.popup.close()}}const mz="",gz="";function $w(n,t){const e=document.createElement("div");e.classList.add("toast","show"),t!=null&&t.theme&&e.setAttribute("data-theme",t.theme),t!=null&&t.id&&e.setAttribute("data-id",t.id),t!=null&&t.html?e.innerHTML=n:e.textContent=n,t!=null&&t.position&&(e.style.left=`${t.position.x}px`,e.style.top=`${t.position.y}px`,e.classList.add("positioned")),document.body.appendChild(e),setTimeout(()=>{e.classList.remove("show"),setTimeout(()=>{e.remove()},500)},(t==null?void 0:t.duration)||3e3)}const t5=`<?xml version="1.0" ?>
27
+ `)}const Sk=B("get-text-position");function Mr(n,t){const e=t!=null?t:n.selection.range.start;e instanceof Vt||d(Sk,!1,`invalid insert pos type: ${typeof e}`);const{blockId:o}=e,r=n.getBlockById(o),i=J(r),s=H(r),l=U(s),{offset:c}=e;return{block:r,container:s,containerId:l,blockIndex:i,offset:c}}const Gi=B("insert-text");function Lp(n,t,e,o){var s;const r=n.doc.getBlockData(t,e);if(d(Gi,r,"no block data"),d(Gi,r.text,"no block text"),ue(r.text)===0)return d(Gi,o===0,"invalid text offset"),n.editorCommandProviders.getEmptyBlockTextAttributes(n,r.id);if(o===0)return;const i=Wt(r.text,o-1,1).middle;if(!((s=i[0].attributes)!=null&&s.box))return i[0].attributes}function Dk(n,t,e){const o=H(t),r=U(o),i=J(t);return Lp(n,r,i,e)}function Mp(n,t,e,o,r){const i=H(t),s=U(i),l=J(t),c=Dk(n,t,e),a=Hl(e,o,c!=null?c:null);return n.doc.localUpdateBlockText(s,l,a,r),he(n,t)}function Rp(n,t,e,o){const r=H(t),i=U(r),s=J(t),l=Hl(e," ",o);return n.doc.localUpdateBlockText(i,s,l),he(n,t)}function cu(n,t,e,o,r){const i=n.doc.getBlockData(e,o);d(Gi,i,"no block data"),d(Gi,i.text,"no block text");const s=Lp(n,e,o,r),l=Hl(r,t,s!=null?s:null);return n.doc.localUpdateBlockText(e,o,l),he(n,n.getBlockById(i.id))}function au(n,t){n.selection.range.isCollapsed()||n.clearSelectedContents();const{containerId:e,blockIndex:o,offset:r}=Mr(n);cu(n,t,e,o,r)}const Xl=B("update-composition-text");function Ap(n){const t=n.selection.range.start;t instanceof Vt||d(Xl,!1,`invalid insert pos type: ${typeof t}`);const{blockId:e}=t,o=n.getBlockById(e);d(Xl,P(n,o),"not a text kind block");const r=H(o),i=U(r),s=J(o),l=n.doc.getBlockData(i,s);d(Xl,l,"no block data in doc"),d(Xl,l.text,"no text data in text block");const c=it(o);Nl(n,io(o),e,c,l.text)}function Op(n){db(n)}function Rr(n,t,e,o,r,i){return n.doc.localInsertBlock(t,e,o,r,i),n.getBlockById(o.id)}const tc=B("delete-block-text");function du(n,t,e,o,r){d(tc,P(n,t),"block is not a text kind block");const i=H(t),s=U(i),l=J(t),c=n.doc.getBlockData(s,l);d(tc,c,"no block data in doc"),d(tc,c.text,"no text data in text block");let a=e;re(t,e)||(a=ho(t,a));let u=e+o;d(tc,u<=W(n,t),`invalid offset and count: ${e}, ${o}`),re(t,u)||(u=Go(t,u));const f=u-a,m=qg(a,f);return n.doc.localUpdateBlockText(s,l,m,r),f}const uu=B("break-text-block");function _p(n,t){const o=n.getBlockData(t).quoted;return o?{quoted:o}:{}}function Ar(n,t,e,o){d(uu,P(n,t),`block is not a text kind block: ${ot(t)}`),d(uu,e>=0&&e<=W(n,t),`invalid offset: ${e}`);const r=H(t),i=U(r),s=J(t),l=o!=null&&o.copyBlockAttributes?_p(n,t):{};if(!(o!=null&&o.forceInsertAfter)&&(e===0||e===W(n,t))){const C=e===0?s:s+1,k={...Un(""),...l,...o==null?void 0:o.newBlockData},w=At(n,t.id,0),y=Rr(n,i,C,k,w);return{block:t,newBlock:y}}d(uu,re(t,e),"not a valid offset");const c=he(n,t),{right:a}=be(c,e),u=ue(a);u>0&&du(n,t,e,u);const f={...Un(a),...l,...o==null?void 0:o.newBlockData},m=Rr(n,i,s+1,f,At(n,f.id,0));return{block:t,newBlock:m}}const Lk=B("prepare-insert-new-block");function Mk(n,t,e){if(t&&e!==void 0&&e!==null){const a=n.getContainerById(t),u=Mt(a);return d(Lk,e>=0&&e<=u.length,`invalid blockIndex: ${e}`),{containerId:t,blockIndex:e}}const o=n.selection.range.start;if(!o.isSimple())return null;const r=n.getBlockById(o.blockId);if(t=U(H(r)),e=J(r),!P(n,r))return{containerId:t,blockIndex:e+1};const s=o.offset;if(s===0||s===W(n,r))return{containerId:t,blockIndex:s===0?e:e+1};const c=Ar(n,r,s).newBlock;return{containerId:t,blockIndex:J(c)}}const Rk=B("auto-insert-block");function Np(n,t,e,o,r,i){const s=Mk(n,e,o);d(Rk,s,`not an valid insert position: ${n.selection.range}`);const l={blockId:t.id,offset:0},c={anchor:l,focus:l};return Rr(n,s.containerId,s.blockIndex,t,r!=null?r:c,i)}const Ak=B("delete-block");function ec(n,t,e){t.children&&(e.push(...t.children),t.children.forEach(o=>{n.getChildContainerData(o).forEach(i=>{ec(n,i,e)})}))}function hu(n,t,e){const o=H(t),r=U(o),i=J(t),s=n.doc.getBlockData(r,i);return d(Ak,s,"no block data in doc"),n.doc.localDeleteBlock(r,i,qt(n,{anchor:e.start,focus:e.end})),s}function fu(n,t,e){return n.undoManager.runInGroup(()=>{const o=H(t);Ge(o)===1&&n.insertTextBlock("",U(o),0);let r=e?co(n,e):null;if(!r){const l=n.selection.range;xp(t,l)?r=Tp(n,t):r=l}const i=hu(n,t,r),s=[];return ec(n,i,s),s.length>0&&n.doc.localDeleteChildContainers(s),i})}function Ok(n,t){const e=[t];n.doc.getContainerBlocks(t).forEach(r=>{ec(n,r,e)}),n.doc.localDeleteChildContainers(e)}function $p(n,t){const e=[...t];t.forEach(o=>{n.doc.getContainerBlocks(o).forEach(i=>{ec(n,i,e)})}),n.doc.localDeleteChildContainers(e)}const mu=B("merge-text-block");function Pp(n,t,e){d(mu,P(n,t),"only text block can be merged"),d(mu,P(n,e),"only text block can be merged");const o=mo(n,t),r=mo(n,e),i=o.text,s=r.text;d(mu,i&&s,"block data has no text");const l=H(t),c=U(l),a=J(t),u=W(n,t),f=cu(n,s,c,a,u),m=At(n,t,ue(i));return fu(n,e,m),f}const wn=B("clear-selected-contents");function nc(n,t){d(wn,P(n,t.block),"not a text kind block");const{start:e,end:o}=t;d(wn,e.isSimple(),"not a simple block position"),d(wn,o.isSimple(),"not a simple block position");const r=e.offset,i=o.offset;d(wn,r<=i,`invalid delete text offset: ${r}, ${i}`),r!==i&&n.deleteTextFromBlock(t.block,r,i-r)}function jp(n,t,e){const o=U(t),r=Mt(t),i=e.focus?void 0:n.selection.range.toDocRange(),s=n.insertTextBlock("",o,0,{newRange:i});e.focus&&n.selection.selectBlock(s,0),r.reverse().forEach(l=>{n.deleteBlock(l)})}function _k(n,t){const{block:e,start:o,end:r}=t;if(P(n,e)){nc(n,t);return}if(Te(e)||o.isSimple()){d(wn,r.isSimple(),"invalid range");const s=H(e),l=J(e),c=n.insertTextBlock("",U(s),l);n.selection.selectBlock(c,0),n.deleteBlock(e);return}d(wn,at(n,e),"invalid block kind"),d(wn,!o.isSimple()&&!r.isSimple(),"invalid range"),xr(n,e,o,r),n.selection.range.getSelectedContainers().forEach((s,l)=>{jp(n,s,{focus:l===0})})}function Nk(n){const t=n.selection.range;if(t.isCollapsed())return;const e=t.getSelectedBlocks();if(d(wn,e.length>0,"no selected block"),e.length===1){_k(n,e[0]);return}const o=e[0],r=o.block,i=H(r);d(wn,e.length>1,"no selected block");const s=e[e.length-1],l=s.block;if(P(n,r)){nc(n,o);const u=At(n,o.block,o.start.offset);if(e.slice(1,e.length-1).reverse().forEach(m=>n.deleteBlock(m.block)),P(n,l)){nc(n,s),n.mergeTextBlock(r,l,{focus:!0}),n.selection.setRange(u);return}n.deleteBlock(l),n.selection.setRange(u);return}if(P(n,l)){nc(n,s),e.slice(0,e.length-1).reverse().forEach(u=>n.deleteBlock(u.block)),n.selection.selectBlock(s.block,0);return}if(e.length===Ge(i)){jp(n,i,{focus:!0});return}const c=gt(r),a=dt(l);d(wn,c||a,"no prev or next block"),e.forEach(u=>n.deleteBlock(u.block))}function gu(n){n.selection.range.isCollapsed()||n.undoManager.runInGroup(()=>{n.emit("beforeClearSelection",n);try{n.doc.beginBatchUpdate(),Nk(n)}finally{n.doc.endBatchUpdate()}n.emit("afterClearSelection",n)})}function Hp(n,t,e){const o=H(t),r=U(o),i=J(t);return n.doc.localUpdateBlockText(r,i,e),setTimeout(()=>{n.selection.updateSelection(null)}),he(n,t)}function Fp(n,t,e){const o=n.getBlockText(t),r=ie.diff(o,e);Hp(n,t,r)}function oc(n,t,e){const o=he(n,t),r=typeof e=="string"?Qo(e):e,i=ie.diff(o,r);return Hp(n,t,i)}const Zi=B("update-block-data");function rc(n,t,e,o){const r=H(t),i=U(r),s=J(t),l=n.doc.getBlockData(i,s),c={insert:{},delete:[]},a=new Set(Object.keys(l)),u=new Set(Object.keys(e));return a.forEach(m=>{if(!u.has(m)){if(m==="id"||m==="type"||m==="text")return;Zi.debug(`delete key: ${m}`),c.delete.push(m)}}),Object.entries(e).forEach(([m,C])=>{d(Zi,m!=="id"&&m!=="type",`invalid block data delta, ${m}`);const k=l[m];if(C==null){k!=null&&(Zi.debug(`delete key: ${m}`),c.delete.push(m));return}k!==C&&(ml.default(k,C)||m==="text"&&ie.diff(k,C).length===0||(a.has(m)?(Zi.debug(`replace key: ${m}`),c.delete.push(m)):Zi.debug(`insert key: ${m}`),c.insert[m]=C))}),n.doc.localUpdateBlockData(i,s,c,o),mo(n,t)}function zp(n,t,e,o){const i={...n.getBlockData(t),embedData:e};return n.updateBlockData(t,i,o)}function pu(n,t,e){if(!at(n,t)||!(e!=null&&e.tryFocusToChildSimpleBlock)){n.selection.selectBlock(t,0);return}const r=xe(n,t).getChildContainers(n,t)[0],i=Ut(r);pu(n,i,e)}function Jo(n){const t=[];let e={};return n.forEach(o=>{t.push(...o.blocks.root);const{root:r,...i}=o.blocks;e={...e,...i}}),{blocks:{...e,root:t},meta:{},comments:{}}}const Yi=B("clone-block");function go(n,t,e,o){const r=n.getBlockClass(e.type);if(r.blockToDoc)return r.blockToDoc(t,e,(u,f)=>(d(Yi,e!==f,"invalid child block"),go(n,u,e,o)));let i={};const s=new Map,l=Y.default(e);l.children&&(l.children=l.children.map(u=>{const f=N(),m=t.blocks[u];d(Yi,Array.isArray(m),"invalid child blocks");const C=m.map(S=>go(n,t,S,o)),k=Jo(C),{root:w,...y}=k.blocks;return i={...i,...y},i[f]=k.blocks.root,s.set(u,f),f}));const c=Array.from(s.entries()),a=u=>{for(const f of c){const[m,C]=f;{const k=`${m}/`;if(u.startsWith(k)){const w=u.substring(k.length),y=`${C}/${w}`;return Yi.debug(`replace key: ${u} -> ${y}`),y}}{const k=`${m}_`;if(u.startsWith(k)){const w=u.substring(k.length),y=`${C}_${w}`;return Yi.debug(`replace key: ${u} -> ${y}`),y}}}return u};return Array.from(Object.entries(l)).forEach(([u,f])=>{const m=a(u);m!==u&&delete l.key,l[m]=f}),l.id=N(),o&&(o.blockIdMap.set(e.id,l.id),s.forEach((u,f)=>o.containerIdMap.set(f,u))),{blocks:{root:[l],...i},meta:{},comments:{}}}function Cu(n,t,e,o){const r=t.blocks[e];d(Yi,Array.isArray(r),"invalid child blocks");const i=r.map(l=>go(n,t,l,o));return Jo(i)}function bu(n,t,e){const o=t.blocks.root.map(r=>go(n.editorBlocks,t,r,e));return Y.default(Jo(o))}const Up=B("insert-doc");function Vp(n,t,e,o,r){if(at(n,t)){Up.warn("failed to insert doc into a complex block");return}const i=bu(n,o,r),s=H(t),l=J(t),c=U(s);n.doc.beginBatchUpdate(),n.undoManager.runInGroup(()=>{var I,M,R;Object.entries(i.blocks).forEach(([$,Z])=>{$!=="root"&&n.doc.localInsertChildContainer($,Z)});const a=i.blocks.root;if(Te(t)){n.deleteBlock(t);let $;a.reverse().forEach(Z=>{const rt=n.insertBlock(c,l,Z);$||($=rt)}),$&&n.selection.selectBlock($,W(n,$));return}if(d(Up,P(n,t),"not a text block"),Tt(n,t)){const $=J(t);let Z;a.forEach((rt,st)=>{const mt=n.insertBlock(c,$+st,rt);st===a.length-1&&(Z=mt)}),Z&&n.selection.selectBlock(Z,W(n,Z));return}if(a.length===1){const $=a[0];if($i(n,$.type)){n.insertTextToBlock(t,e,(I=$.text)!=null?I:[]);return}n.breakTextBlock(t,e),n.insertBlock(c,l+1,$);return}const u=e===W(n,t),f=e===0,m=a[0],C=a[a.length-1];let k;!u&&!f?k=n.breakTextBlock(t,e,{forceInsertAfter:!0}):k=t;const w=f?l:l+1;u?(k=n.insertBlock(c,l+1,C),n.selection.selectBlock(k,W(n,k))):(n.selection.selectBlock(k,0),$i(n,C.type)?n.insertTextToBlock(k,0,(M=C.text)!=null?M:[]):n.insertBlock(c,w,C));const y=n.selection.range;let S=w;$i(n,m.type)?f?(n.insertBlock(c,w,m),S+=1):n.insertTextToBlock(t,e,(R=m.text)!=null?R:[]):(n.insertBlock(c,w,m),S+=1),a.slice(1,a.length-1).reverse().forEach($=>{n.insertBlock(c,S,$)}),n.selection.setRange(y)}),n.doc.endBatchUpdate()}function ku(n,t,e,o,r){const i=bu(n,o,r),s=U(t),l=[];return n.undoManager.runInGroup(()=>{Object.entries(i.blocks).forEach(([a,u])=>{a!=="root"&&n.doc.localInsertChildContainer(a,u)}),i.blocks.root.reverse().forEach(a=>{const u=n.insertBlock(s,e,a);l.push(u)})}),l}function qp(n,t,e){const o=Ge(t);ku(n,t,o,e);for(let r=0;r<o;r++){const i=Ut(t);n.deleteBlock(i)}}const Qi=B("add-text-attribute");function $k(n,t,e,o){const{start:r,end:i}=e;d(Qi,r.blockId===i.blockId&&r.blockId===q(t),"invalid range"),d(Qi,o,"invalid attribute name");const s=n.getBlockText(t),l=Sr(r.offset,i.offset-r.offset,s,o,void 0,{ignoreValue:!0});return n.setBlockText(t,l),l}function Wp(n,t,e,o,r){const{start:i,end:s}=e;d(Qi,i.blockId===s.blockId&&i.blockId===q(t),"invalid range"),d(Qi,o,"invalid attribute name");const l=n.getBlockText(t),c=Vi(i.offset,s.offset-i.offset,l,o,r);return n.setBlockText(t,c),c}function Or(n,t,e,o,r){const{start:i,end:s}=e;d(Qi,i.blockId===s.blockId&&i.blockId===q(t),"invalid range");const l=n.getBlockText(t),c=tp(i.offset,s.offset-i.offset,l,o,r);return n.setBlockText(t,c),c}function Gp(n,t,e,o){const r=tn(n,{simpleBlockOnly:!0});n.undoManager.runInGroup(()=>{r.forEach(i=>{const{block:s,start:l,end:c}=i;if(!P(n,s))return;if(Tt(n,s)){o(n,q(s),t,e);return}const a=qt(n,{anchor:l,focus:c});t==="color"||t==="backgroundColor"?Or(n,s,a,t,e):(Or(n,s,a,"color",null),Or(n,s,a,"backgroundColor",null))})})}function Zp(n,t,e){const o=tn(n,{simpleBlockOnly:!0});n.undoManager.runInGroup(()=>{o.forEach(r=>{const{block:i,start:s,end:l}=r;if(!P(n,i))return;if(Tt(n,i)){(t==="clearColor"||t==="clearAll")&&e(n,q(i),"color",null),(t==="clearBackground"||t==="clearAll")&&e(n,q(i),"backgroundColor",null);return}const c=qt(n,{anchor:s,focus:l});(t==="clearColor"||t==="clearAll")&&Or(n,i,c,"color",null),(t==="clearBackground"||t==="clearAll")&&Or(n,i,c,"backgroundColor",null)})})}function vu(n,t){const e=tn(n,{simpleBlockOnly:!0}).filter(s=>P(n,s.block));if(e.length===0)return[null,null];const o=s=>{if(W(n,s.block)===0)return t(n,q(s.block));const l=s.start,c=s.end,a=n.getBlockText(s.block);return op(l.offset,c.offset-l.offset,a)};let[r,i]=o(e[0]);return r===null&&i===null?[r,i]:(e.forEach(s=>{const[l,c]=o(s);l===null||r===null?r=null:r=l===r?r:null,c===null||i===null?i=null:i=c===i?i:null}),[r,i])}const ve=B("adjust-selection-pos");function Yp(n){const t=[];for(;n;){const e=H(n);if(t.unshift(e),pt(e))return t;const o=F(e);d(ve,o,"child container has not parent container"),n=o}d(ve,!1,"should not come here: getParentContainers")}function Qp(n,t){for(;t;){const e=H(t);if(e===n)return t;const o=F(e);d(ve,o,"could not find parent block for a child container"),t=o}d(ve,!1,"no parent block in specified container")}function Pk(n,t){const e=Yp(n),o=Yp(t);d(ve,e.length>0&&o.length>0,"block has not parent container"),d(ve,e[0]===o[0],"root container does not equal");let r=e[0];for(let l=1;l<e.length||o.length;l++)if(e[l]!==o[l]){r=e[l-1];break}const i=Qp(r,n),s=Qp(r,t);return{parentContainer:r,newBlock1:i,newBlock2:s}}function Kp(n,t){let e=F(t);for(d(ve,e,"element is not in a block");e;){const o=H(e);d(ve,Ye(o),"not a child container");const r=F(o);if(d(ve,r,"child container has not parent block"),r===n)return o;e=r}d(ve,!1,"failed to find parent container in complex block")}function ic(n,t,e){const o=n.getBlockById(t.blockId),r=n.getBlockById(e.blockId);if(o===r)return t instanceof Vt&&e instanceof Vt?{anchor:t,focus:e}:(d(ve,t instanceof Je&&e instanceof Je,"both start and end are not simple or complex"),Al(n,o,t,e));const i=H(o),s=H(r);if(i===s)return t instanceof Je&&(t=j(o,0,"home")),e instanceof Je&&(e=j(r,W(n,r),"end")),d(ve,t instanceof Vt,"not valid position type"),d(ve,e instanceof Vt,"not valid position type"),{anchor:t,focus:e};if(o.contains(s))return null;if(r.contains(i)){if(t instanceof Vt&&e instanceof Je){const k=n.getContainerById(e.childContainerId);if(k===i)return{anchor:e,focus:e};const w=F(i);if(w&&w===F(k)){const y=wt(w,U(i)),S=wt(w,U(k));return Al(n,w,y,S)}}return null}const l=kl(o,r)>0,{newBlock1:c,newBlock2:a}=Pk(o,r);if(c===a){const k=c,w=Kp(k,o),y=Kp(k,r);return t=wt(c,U(w)),e=wt(c,U(y)),ve.debug(`select in complex block: ${w.id}, ${y.id}`),Al(n,k,t,e)}let u=l?W(n,c):0;c===o&&t instanceof Vt&&(u=t.offset);let m=l?0:W(n,a);return a===r&&e instanceof Vt&&(m=e.offset),t=j(c,u,l?"end":"home"),e=j(a,m,l?"home":"end"),{anchor:t,focus:e}}const jk=B("move-complex-block-position");function Hk(n,t,e){const o=n.getBlockById(t.blockId);d(jk,at(n,o),"is not a complex block");const r=xe(n,o),i=n.getContainerById(t.childContainerId),s=r.getNextContainer(n,o,i,e,{noWrap:!0});return s?wt(o,U(s)):null}const Ki=B("move-simple-block-position");function Jp(n,t){const e=Se(n,t);d(Ki,e.length>0,"complex block has not any child container");const o=e[0];return Ut(o)}function Xp(n,t){const e=Se(n,t);d(Ki,e.length>0,"complex block has not any child container");const o=e[e.length-1];return Qt(o)}function t0(n,t,e){const o=e?Jp(n,t):Xp(n,t);return at(n,o)?t0(n,o,e):o}function Fk(n,t){const e=n.getBlockById(t.blockId);return at(n,e)&&t.offset===0?Jp(n,e):Br(e)}function zk(n,t){const e=n.getBlockById(t.blockId);return at(n,e)&&t.offset===1?Xp(n,e):wr(e)}function yu(n){return n==="ArrowLeft"||n==="ArrowUp"}function wu(n,t,e){const o=H(t);if(pt(o))return null;const r=F(o);d(Ki,r,"child container has not parent block"),d(Ki,at(n,r),"is not a complex block");const i=xe(n,r).getNextContainer(n,r,o,e);return i?yu(e)?Qt(i):Ut(i):wu(n,r,e)}function Uk(n,t,e){const o=H(t);if(pt(o))return null;const r=F(o);if(d(Ki,r,"child container has not parent block"),yu(e)){const l=gt(r);if(l)return l}else{const l=dt(r);if(l)return l}const i=wu(n,r,e);if(i)return i;let s=r;for(;!pt(H(s));)s=F(H(s));return yu(e)?gt(s):dt(s)}function Vk(n,t,e){return!at(n,t)||xe(n,t).enableKeyboardSelect?t:t0(n,t,e==="ArrowDown"||e==="ArrowRight")}function qk(n,t,e){const o=n.getBlockById(t.blockId),i=kt(n,o).moveCaret(n,o,t,e);if(i)return i;let s=e==="ArrowDown"||e==="ArrowRight"?Fk(n,t):zk(n,t);if(s||(s=wu(n,o,e),s||(s=Uk(n,o,e))),!s){if(e==="ArrowDown"||e==="ArrowRight"){if(n.readonly||!pt(H(o)))return null;const l=n.insertTextBlock("",U(n.rootContainer),Ge(n.rootContainer));return j(l,0,"home")}return null}if(s=Vk(n,s,e),P(n,s)){const l=n.selection.getSuggestedCaretX();if(e==="ArrowDown")return wb(n,s,o,t,l);if(e==="ArrowUp")return yb(n,s,o,t,l)}return e==="ArrowLeft"||e==="ArrowUp"?j(s,W(n,s),"end"):e==="ArrowRight"||e==="ArrowDown"?j(s,0,"home"):null}function Wk(n,t,e){if(t==="ArrowLeft")return e.start;const o=e.end,r=n.getBlockById(o.blockId);if(P(n,r))return o;const i=dt(r);if(i)return j(i,0,"home");if(!pt(H(r))||n.readonly)return o;const s=n.insertTextBlock("",U(n.rootContainer),Ge(n.rootContainer));return j(s,0,"home")}function Gk(n,t,e){const o=n.selection.range;let r;if(o instanceof ae)e==="move"&&!o.isCollapsed()&&(t==="ArrowLeft"||t==="ArrowRight")?r=Wk(n,t,o):r=qk(n,o.getFocusedPos(),t);else if(r=Hk(n,o.focus,t),e==="move"){const i=r!=null?r:o.focus,s=n.getContainerById(i.childContainerId);if(t==="ArrowLeft"||t==="ArrowUp"){const l=Qt(s);r=j(l,0,"home")}else{const l=Ut(s);r=j(l,W(n,l),"end")}}return r?e==="move"?{anchor:r,focus:r}:ic(n,o.anchor,r):null}function po(n,t,e){const o=Gk(n,t,e);if(!o)return!1;const{anchor:r,focus:i}=o;return n.selection.setSelection(r,i),(t==="ArrowLeft"||t==="ArrowRight")&&n.selection.updateLastCaretRect(),!0}function e0(n){return po(n,"ArrowLeft","move"),!0}function n0(n){return po(n,"ArrowRight","move"),!0}function o0(n){return po(n,"ArrowUp","move"),!0}function r0(n){if(po(n,"ArrowDown","move")||n.readonly)return!0;const t=n.getFocusedBlock(),e=H(t);if(pt(e)||Qt(e)!==t)return!0;const o=n.rootContainer;return n.insertTextBlock("",U(o),Ge(o)),!0}function i0(n){return po(n,"ArrowDown","select"),!0}function s0(n){return po(n,"ArrowLeft","select"),!0}function l0(n){return po(n,"ArrowRight","select"),!0}function c0(n){return po(n,"ArrowUp","select"),!0}const a0=B("word-offset");function Bu(n,t){const e=n.selection.range.focus;d(a0,e.isSimple(),"invalid range type");const o=n.getBlockById(e.blockId);if(Tt(n,o))return j(o,0,"home");if(e.offset===0||!P(n,o)){const s=gt(o);if(!s)return null;const l=j(s,W(n,s),"end");if(t==="select"&&P(n,s)){const c=tu(n,s,l.offset);return j(s,c,"normal")}return l}const r=tu(n,o,e.offset);return j(o,r,"normal")}function Eu(n,t){const e=n.selection.range.focus;d(a0,e.isSimple(),"invalid range type");const o=n.getBlockById(e.blockId);if(Tt(n,o))return j(o,0,"end");if(e.offset===W(n,o)||!P(n,o)){const s=dt(o);if(!s)return null;const l=j(s,0,"home");if(t==="select"&&P(n,s)){const c=eu(n,s,l.offset);return j(s,c,"end")}return l}const r=eu(n,o,e.offset);return j(o,r,"normal")}function d0(n){if(!n.selection.range.focus.isSimple())return!1;const e=Bu(n,"move");return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function u0(n){if(!n.selection.range.focus.isSimple())return!1;const e=Eu(n,"move");return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function h0(n){if(!n.selection.range.focus.isSimple())return!1;const e=Bu(n,"select");return e?(n.selection.setSelection(n.selection.getAnchorPos(),e),n.selection.updateLastCaretRect(),!0):!1}function f0(n){if(!n.selection.range.focus.isSimple())return!1;const e=Eu(n,"select");return e?(n.selection.setSelection(n.selection.range.anchor,e),n.selection.updateLastCaretRect(),!0):!1}B("find-block");function Iu(n,t){if(!at(n,t))return t;const o=xe(n,t).getChildContainers(n,t)[0],i=Mt(o)[0];return Iu(n,i)}function xu(n,t){if(!at(n,t))return t;const e=xe(n,t).getChildContainers(n,t),o=e[e.length-1],r=Mt(o),i=r[r.length-1];return xu(n,i)}function m0(n){const t=xu(n,Qt(n.rootContainer)),e=j(t,W(n,t),"end");return n.selection.setSelection(e),!0}function g0(n){const t=Iu(n,n.getFirstBlock()),e=j(t,0,"home");return n.selection.setSelection(e),!0}function p0(n){const t=Iu(n,n.getFirstBlock()),e=j(t,0,"home");return n.selection.setSelection(n.selection.getAnchorPos(),e),!0}function Tu(n){const t=xu(n,Qt(n.rootContainer)),e=j(t,W(n,t),"end");return n.selection.setSelection(n.selection.getAnchorPos(),e),!0}const C0=B("line-offset");function b0(n){const t=n.selection.range.focus;d(C0,t.isSimple(),"invalid range type");const e=n.getBlockById(t.blockId);if(t.offset===0||!P(n,e))return j(e,0,"home");let r=Hg(e,t).start;const{next:i}=_l(e,r);return i&&_e(i)&&_i(i)==="br"&&(r+=1),j(e,r,"home")}function k0(n){const t=n.selection.range.focus;d(C0,t.isSimple(),"invalid range type");const e=n.getBlockById(t.blockId);if(t.offset===W(n,e)||!P(n,e))return j(e,W(n,e),"end");const o=Hg(e,t);return j(e,o.end,"end")}function v0(n){if(!n.selection.range.focus.isSimple())return!1;const e=b0(n);return e?(n.selection.setSelection(n.selection.getAnchorPos(),e),n.selection.updateLastCaretRect(),!0):!1}function y0(n){if(!n.selection.range.focus.isSimple())return!1;const e=k0(n);return e?(n.selection.setSelection(n.selection.getAnchorPos(),e),n.selection.updateLastCaretRect(),!0):!1}function w0(n){if(!n.selection.range.focus.isSimple())return!1;const e=b0(n);return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function B0(n){if(!n.selection.range.focus.isSimple())return!1;const e=k0(n);return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}const E0=B("find-block-position");function Zk(n,t,e,o){d(E0,at(n,t),"is not a complex block");const r=xe(n,t).getChildContainers(n,t);d(E0,r.length>0,"complex block has not any child container");const i=Ke(n,e,o),s=i.left+i.width/2,l=i.top+i.height/2,c=Dg(n,t,s,l);return Su(n,c,e,o)}function Su(n,t,e,o){if(at(n,t))return Zk(n,t,e,o);const r=q(t);let i=Number.MAX_SAFE_INTEGER;const s=Ke(n,e,o),l=s.left+s.width/2,c=s.top+s.height/2;let a=j(r,0,"home");const u=W(n,t);for(let f=0;f<=u;f++){const m=j(r,f,"normal"),C=Ke(n,t,m),k=Cn(C,l,c);k<i&&(i=k,a=m)}return a}const I0=B("page-offset");function Yk(n,t){const e=Ep(n)*.9,r=t.getBoundingClientRect().bottom-e;if(r<kk(n))return n.getFirstBlock();const i=gt(t);if(!i)return n.getFirstBlock();let s=i;for(;s;){if(s.getBoundingClientRect().y<r)return s;s=gt(s)}return n.getFirstBlock()}function Qk(n,t){const e=Ep(n)*.9,o=t.getBoundingClientRect(),r=vk(n),i=o.top+e;if(i>r)return n.getLastBlock();const s=dt(t);if(!s)return n.getLastBlock();let l=s;for(;l;){if(l.getBoundingClientRect().bottom>i)return l;l=dt(l)}return n.getLastBlock()}function x0(n){const t=n.selection.range.focus;d(I0,t.isSimple(),"invalid range type");const e=n.getBlockById(t.blockId),o=Yk(n,e);let r;return o===n.getFirstBlock()?r=j(o,0,"home"):r=Su(n,o,e,t),r}function T0(n){const t=n.selection.range.focus;d(I0,t.isSimple(),"invalid range type");const e=n.getBlockById(t.blockId),o=Qk(n,e);let r;return o===n.getLastBlock()?r=j(o,W(n,o),"end"):r=Su(n,o,e,t),r}function S0(n){if(!n.selection.range.focus.isSimple())return!1;const e=x0(n);return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function D0(n){if(!n.selection.range.focus.isSimple())return!1;const e=T0(n);return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function L0(n){if(!n.selection.range.focus.isSimple())return!1;const e=x0(n);if(!e)return!1;const o=ic(n,n.selection.getAnchorPos(),e);if(!o)return!1;const{anchor:r,focus:i}=o;return n.selection.setSelection(r,i),n.selection.updateLastCaretRect(),!0}function M0(n){if(!n.selection.range.focus.isSimple())return!1;const e=T0(n);if(!e)return!1;const o=ic(n,n.selection.getAnchorPos(),e);if(!o)return!1;const{anchor:r,focus:i}=o;return n.selection.setSelection(r,i),n.selection.updateLastCaretRect(),!0}const Ji=B("select-all");function R0(n,t){const e=Ut(n),o=Qt(n);return t.start.offset===0&&t.start.blockId===q(e)&&t.end.offset===W(t.getEditor(),o)&&t.end.blockId===q(o)}function Kk(n,t){const e=t.getEditor(),o=xe(e,n).getChildContainers(e,n),r=o[0],i=o[o.length-1],s=q(n);return t.start.blockId===s&&t.start.childContainerId===U(r)&&t.end.blockId===s&&t.end.childContainerId===U(i)}function Jk(n,t){d(Ji,t,"no parent block"),d(Ji,at(n,t),"not a complex block");const e=xe(n,t).getChildContainers(n,t),o=e[0],r=e[e.length-1];n.selection.setRange(qt(n,{anchor:wt(t,U(o)),focus:wt(t,U(r))}))}function A0(n,t){const e=H(t);Du(n,e)}function O0(n){const t=n.getFocusedBlock(),e=n.selection.range;if(e.start.isSimple()){if(e.start.blockId===e.end.blockId&&P(n,t)){const r=e.start,i=e.end,s=W(n,t);if(r.offset>0||i.offset<s)return n.selection.selectBlock(t,0,s),!1}return A(n.rootContainer,"select-all"),A0(n,Ut(n.rootContainer)),!1}return d(Ji,!e.isSimple(),"invalid range type"),Kk(t,e)?(A0(n,t),!1):(d(Ji,t,"no parent block"),d(Ji,at(n,t),"not a complex block"),Jk(n,t),!0)}function Du(n,t){const e=Mt(t),o=e[0],r=e[e.length-1],i=j(o,0,"home"),s=j(r,W(n,r),"end");n.selection.setSelection(i,s,{noScroll:!0})}function _0(n){Tu(n),n.focus()}const Lu=B("selected-block-to-doc");function N0(n,t,e){!t.children||t.children.forEach(o=>{const r=n.getChildContainerData(o);r.forEach(i=>{N0(n,i,e)}),e.blocks[o]=Y.default(r)})}function sc(n,t,e={ignoreLockInfo:!0}){const o=kt(n,t.block);if(o.selectionToDoc)return o.selectionToDoc(n,t);const r=Y.default(mo(n,t.block));if(!e.ignoreLockInfo&&r.lock&&delete r.lock,P(n,t.block)){const s=t.start,l=t.end;if(d(Lu,r.text,"no block text"),s.offset===l.offset)return{blocks:{root:[{...r,text:[]}]},meta:{},comments:{}};const{middle:c}=Wt(r.text,s.offset,l.offset-s.offset);return{blocks:{root:[{...r,text:c}]},meta:{},comments:{}}}if(Te(t.block))return{blocks:{root:[r]},meta:{},comments:{}};d(Lu,at(n,t.block),"not complex block"),d(Lu,r.children,"no children");const i={blocks:{root:[r]},meta:{},comments:{}};return N0(n,r,i),i}function Mu(n,t,e=!0){const o=j(t,0,"normal"),r=j(t,W(n,t),"end");return sc(n,{block:t,start:o,end:r},{ignoreLockInfo:e})}const Xk=B("block-to-doc");function tv(n,t){d(Xk,t.length>0,"invalid params, no blocks");const e=t.map(o=>Mu(n,o));return Jo(e)}function Xi(n){const e=n.selection.range.getSelectedBlocks().map(o=>sc(n,o));return Jo(e)}function $0(n,t){const e=n.getContainerById(t),i=Mt(e).map(s=>({start:j(s,0,"home"),end:j(s,W(n,s),"end"),block:s})).map(s=>sc(n,s));return Jo(i)}const lc=B("editor-selection");class ev{constructor(t){h(this,"editor");h(this,"caret");h(this,"_range");h(this,"lastCaretRect");h(this,"handleBlockDelete",(t,e,o,r)=>{if(o||r.child)return;const i=this.range;if(xp(e,i)){lc.debug("adjust selection because remote deleted current block");const s=Tp(t,e);this.setRange(s,{noScroll:!0})}});this.editor=t;const e=t.getFirstBlock(),o=q(e);this.caret=new Ck(t);const r=j(o,0,"normal");this._range=qt(t,{anchor:r,focus:r}),this.lastCaretRect=null,this.editor.addListener("blockDeleted",this.handleBlockDelete),setTimeout(()=>{this.updateFocusedBlock(null)})}destroy(){this.caret.destroy()}get range(){return this._range}get focusedBlock(){return this.getFocusedBlock()}get startBlock(){return this.getStartBlock()}get endBlock(){return this.getEndBlock()}getFocusedBlock(){const t=this.range.focus;return this.editor.getBlockById(t.blockId)}getStartBlock(){const t=this.range.start;return this.editor.getBlockById(t.blockId)}getEndBlock(){const t=this.range.end;return this.editor.getBlockById(t.blockId)}selectBlock(t,e,o){const r=j(t,e,"normal");let i;o&&(i=j(t,o,"normal")),this.setSelection(r,i)}setSelection(t,e,o){if(e||(e=t),this.verifyPos(t),this.verifyPos(e),!this.selectionChanging(t,e))return this.range;const r=qt(this.editor,{anchor:t,focus:e});if(this.range.isEqual(r))return this.range;const i=this._range;return this._range=r,this.selectionChanged(),this.updateFocusedBlock(i),nt(this.editor.rootContainer,"select-all")&&(!r.isSimple()||!Ik(this.editor,r))&&z(this.editor.rootContainer,"select-all"),o!=null&&o.noScroll||this.scrollIntoView(),this.range}setRange(t,e){return this.setSelection(t.anchor,t.focus,e)}updateSelection(){this.caret.update(),bk(this.editor)}getFocusedPos(){return this.range.focus}getAnchorPos(){return this.range.anchor}selectionChanging(t,e){return!0}selectionChanged(){this.updateSelection(),this.editor.emit("selectionChanged",this.editor)}updateLastCaretRect(){const t=this.range.focus;if(!lo(t))return;const e=this.editor.getBlockById(t.blockId);this.lastCaretRect=Ke(this.editor,e,t)}getSuggestedCaretX(){var t;return(t=this.lastCaretRect)==null?void 0:t.x}scrollIntoView(){Ek(this.editor)}verifyPos(t){const e=this.editor.getBlockById(t.blockId);if(t.isSimple())t.offset>=0&&t.offset<=W(this.editor,e)||d(lc,!1,"invalid block position, out of range");else{const o=t.childContainerId;!!this.editor.getContainerById(o)||d(lc,!1,"invalid complex block position, no container found")}}updateFocusedBlock(t){if(t&&this.range.start.blockId===t.start.blockId)return;let e;t&&t.start.blockId===t.end.blockId&&(e=this.editor.findBlockById(t.start.blockId));let o;(this.range.isCollapsed()||!this.range.isSimple()||this.range.start.blockId===this.range.end.blockId)&&(o=this.editor.getBlockById(this.range.start.blockId));let r=!1;e&&nt(e,"focused")&&(z(e,"focused"),r=!0),this.removeAllBlockFocusedClass(),o&&this.setBlockFocused(o)&&(r=!0),r&&this.editor.emit("focusBlockChanged",this.editor,o!=null?o:null,e!=null?e:null)}verify(){this.verifyPos(this._range.start),this.verifyPos(this._range.end)}to(t){const e=Xi(this.editor);return t==="text"?Jl(this.editor,e):t==="markdown"?Lr(this.editor,e):Dp(this.editor,e)}removeAllBlockFocusedClass(){this.editor.rootContainer.querySelectorAll('div[data-type="editor-block"].focused, div[data-type="editor-block"].child-focused').forEach(t=>{z(t,"focused"),z(t,"child-focused")})}setBlockFocused(t){if(nt(t,"focused"))return!1;A(t,"focused");let e=H(t);for(;Ye(e);){const o=F(e);d(lc,o,"parent block not found"),A(o,"child-focused"),e=H(o)}return!0}}function nv(n){const t=n.selection.range.focus;if(!t.isSimple())return;const e=n.findBlockById(t.blockId);!e||n.selection.selectBlock(e,0,W(n,e))}function ov(n){const t=n.selection.range.focus;if(!t.isSimple())return;const e=n.findBlockById(t.blockId);if(!e||!P(n,e))return;let o=Bu(n,"select"),r=Eu(n,"select");if(!o||!r)return;const i=t.blockId;o.blockId!==i&&(o=j(e,0,"home")),r.blockId!==i&&(r=j(e,W(n,e),"end")),n.selection.setSelection(o,r)}class rv{constructor(t){h(this,"editor");h(this,"startPos",null);h(this,"lastCaretRect");h(this,"mouseDownEvent",null);h(this,"handleMouseDown",t=>{this.mouseDownEvent=t;const e=Mg(this.editor,t.x,t.y);if(e){if(e instanceof Xe)return;const o=this.editor.selection.range;if(t.shiftKey&&o.isSimple()){const r=o.anchor;this.editor.selection.setSelection(r,e.focus),this.startPos=e.start}else this.editor.selection.setSelection(e.anchor,e.focus),this.startPos=e.start;this.editor.selection.updateLastCaretRect()}});h(this,"handleMouseMove",t=>{if(!this.startPos||!this.mouseDownEvent||Math.abs(this.mouseDownEvent.x-t.x)<3&&Math.abs(this.mouseDownEvent.y-t.y)<3)return;const e=Ol(this.editor,t.x,t.y);if(!e)return;const o=ic(this.editor,this.startPos,e.end);if(!o)return;const{anchor:r,focus:i}=o;this.editor.selection.setSelection(r,i)});h(this,"handleMouseUp",t=>{this.startPos=null});this.editor=t,this.startPos=null,this.lastCaretRect=new DOMRect}isSelecting(){return this.startPos!==null}stopSelection(){this.startPos=null}handleDblClick(t){ov(this.editor)}handleTripleClick(t){nv(this.editor)}}function iv(n){return n.readonly||!n.isWritable()?!1:(n.undoManager.undo(),!0)}function sv(n){return n.readonly||!n.isWritable()?!1:(n.undoManager.redo(),!0)}const P0=B("delete-text");function j0(n,t,e,o){const r=o!=null?o:n.selection.range.start;r instanceof Vt||d(P0,!1,`invalid insert pos type: ${typeof r}`);const{blockId:i}=r,s=n.getBlockById(i);d(P0,P(n,s),"block is not a text kind block");let{offset:l}=r;if(t==="backward"){if(l-e<0)return 0;if(!re(s,l-e)){const c=ho(s,l);e=l-c}}else if(t==="forward"&&l+e>W(n,s))return 0;return t==="backward"&&(l-=e),n.deleteTextFromBlock(s,l,e)}function H0(n,t){if(n.getBlockData(t).quoted){const e={quoted:null};return n.updateBlockData(t,e),!0}return!1}const lv=B("handle-backspace");function Ru(n,t){if(!Tt(n,t))return;const e=H(t);Ge(e)!==1&&n.deleteBlock(t)}function cv(n,t){if(!n.selection.range.isCollapsed()){n.clearSelectedContents();return}const e=n.selection.range.start,o=n.getBlockById(e.blockId);if(P(n,o))if(e.offset===0){if(H0(n,o))return;const r=gt(o);if(r)if(P(n,r))n.mergeTextBlock(r,o,{focus:!0});else if(at(n,r)){Ru(n,o);const i=Pi(n,r);i?n.selection.selectBlock(i,W(n,i)):n.selection.selectBlock(r,0,W(n,r))}else Ru(n,o),d(lv,Te(r),"prev block is not embed block"),n.selection.selectBlock(r,1);else{const i=H(o);if(Ye(i)){const s=xg(n,i);s&&(Ru(n,o),n.selection.selectBlock(s,W(n,s)))}}}else j0(n,"backward",1,null);else{const r=J(o),i=H(o);n.insertTextBlock("",U(i),r),n.deleteBlock(o)}}function av(n,t){if(!n.selection.range.isCollapsed()){n.clearSelectedContents();return}const e=n.selection.range.start,o=n.getBlockById(e.blockId);if(P(n,o))if(e.offset===W(n,o)){const r=dt(o);r&&(P(n,r)?n.mergeTextBlock(o,r,{focus:!0}):Tt(n,o)?n.deleteBlock(o,At(n,r,0)):n.deleteBlock(r))}else j0(n,"forward",1,null);else{const r=J(o),i=H(o);n.insertTextBlock("",U(i),r),n.deleteBlock(o)}}function dv(n,t){n.selection.range.isCollapsed()||n.clearSelectedContents();const e=n.getFocusedBlock();if(P(n,e)){if(Tt(n,e)&&H0(n,e))return;const o=n.selection.range.start,r=n.breakTextBlock(e,o.offset,{copyBlockAttributes:!0});o.offset!==0?n.selection.selectBlock(r,0):n.selection.scrollIntoView()}else{const o=n.insertTextBlock();n.selection.selectBlock(o,0)}}function uv(n,t){const e=n.selection.range.getSelectedBlocks()[0],{block:o}=e;if(!P(n,o))return!1;const r=e.end;return n.insertBoxToBlock(o,r.offset,{type:"br",id:N(),box:!0,created:Date.now()}),!0}const hv=B("input-handler-actions");function fv(n,t){return n.readonly||!n.isWritable()?!1:n.undoManager.runInGroup(()=>(dv(n),!0))}function mv(n,t){return n.readonly||!n.isWritable()?!1:n.undoManager.runInGroup(()=>(av(n),!0))}function gv(n,t){return n.readonly||!n.isWritable()?!1:n.undoManager.runInGroup(()=>(cv(n),!0))}function pv(n,t){return n.readonly||!n.isWritable()?!1:n.undoManager.runInGroup(()=>(uv(n),!0))}function Cv(n){return n.readonly||!n.isWritable()||!window.isSecureContext?!1:(navigator.clipboard.readText().then(t=>{n.input.handlePasteText(t)}).catch(t=>{hv.error(t)}),!0)}function F0(n,t,e){if(t.type==="embed"){const s=t.embedData.src;s&&typeof s=="string"&&e.add(s);return}const o=t.text;o&&o.forEach(i=>{i.attributes&&i.attributes.src&&typeof i.attributes.src=="string"&&e.add(i.attributes.src)});const r=t.children;r&&r.forEach(i=>{n.blocks[i].forEach(l=>{F0(n,l,e)})})}function bv(n,t){const e=new Set;return t.blocks.root.forEach(r=>{const i=n.editorBlocks.getBlockClass(r.type);i.getResources?i.getResources(r).forEach(s=>{e.add(s)}):F0(t,r,e)}),Array.from(e)}function ts(n,t){return`<!doctype html><html><head><meta charset="utf8" />${`<meta charset="utf-8"><ones-editor-doc data-source="ones-editor-doc::${Fo(JSON.stringify(t))}::ones-editor-doc" />`}</head><body>${n}</body></html>`}function es(n,t){var i,s,l;const e=(l=(s=(i=n.doc).getServerMeta)==null?void 0:s.call(i))!=null?l:{},o=bv(n,t),r={};o.forEach(c=>{const a=n.doc.buildResourceUrl(c,{withToken:!0});r[c]=a}),t.meta={...e,resources:r}}function kv(n,t,e){if(t.preventDefault(),t.stopPropagation(),!t.clipboardData)return;let o=Xi(n);const r=e==null?void 0:e(n,t,o);if(r===!0)return;typeof r=="object"&&r!==null&&(o=r),es(n,o);const i=Dr(n,o),s=Lr(n,o),l=ts(i,o);t.clipboardData.setData("text/html",l),t.clipboardData.setData("text/plain",s),t.clipboardData.setData("text/x-ones-editor-doc",JSON.stringify(o))}function vv(n){if(n.selection.range.isCollapsed())return;const t=Xi(n);es(n,t);const e=Dr(n,t),o=ts(e,t),r=Lr(n,t),i=new Blob([o],{type:"text/html"});Il([{type:"text/plain",data:new Blob([r],{type:"text/plain"})},{type:"text/html",data:i}])}async function cc(n,t){const e=Mu(n,t,!1);es(n,e);const o=Dr(n,e),r=Lr(n,e),i=ts(o,e);return Il([{type:"text/plain",data:new Blob([r],{type:"text/plain"})},{type:"text/html",data:new Blob([i],{type:"text/html"})}])}function yv(n){return vv(n),gu(n),!0}const ac={ArrowDown:r0,ArrowUp:o0,ArrowLeft:e0,ArrowRight:n0,"Shift+ArrowDown":i0,"Shift+ArrowUp":c0,"Shift+ArrowLeft":s0,"Shift+ArrowRight":l0,"CtrlOrCmd+ArrowLeft":d0,"CtrlOrCmd+ArrowRight":u0,"CtrlOrCmd+Shift+ArrowLeft":h0,"CtrlOrCmd+Shift+ArrowRight":f0,"CtrlOrCmd+ArrowUp":g0,"CtrlOrCmd+ArrowDown":m0,"CtrlOrCmd+Shift+ArrowUp":p0,"CtrlOrCmd+Shift+ArrowDown":Tu,"CtrlOrCmd+A":O0,Home:w0,End:B0,"Shift+Home":v0,"Shift+End":y0,PageUp:S0,PageDown:D0,"Shift+PageUp":L0,"Shift+PageDown":M0,"CtrlOrCmd+X":yv,"CtrlOrCmd+Z":iv,"CtrlOrCmd+Shift+Z":sv,Enter:fv,Delete:mv,Backspace:gv,"Shift+Enter":pv,"CtrlOrCmd+Shift+V":Cv};function z0(n,t){return n.shortcuts.handleKeyboardEvents(n,t)!==void 0}function U0(n,t,e){if(t.type==="embed"){const i=t.embedData,s=i.src;if(s&&typeof s=="string"){const l=e.get(s);l&&(i.src=l)}return}const o=t.text;o&&o.forEach(i=>{if(i.attributes&&i.attributes.src&&typeof i.attributes.src=="string"){const s=e.get(i.attributes.src);s&&(i.attributes.src=s)}});const r=t.children;r&&r.forEach(i=>{n.blocks[i].forEach(l=>{U0(n,l,e)})})}function V0(n,t,e){if(e.size===0)return;t.blocks.root.forEach(r=>{const i=n.editorBlocks.getBlockClass(r.type);i.replaceResources?i.replaceResources(r,e):U0(t,r,e)})}async function wv(n,t){const e=t.filter(i=>i.indexOf(":")===-1),o=await n.doc.addResources(e),r=new Map;if(e.length!==o.length)return r;for(let i=0;i<e.length;i++)r.set(e[i],o[i]);return r}function Bv(n,t){var i,s;const o=t.meta.serverId;if(!o||typeof o!="string")return!1;const r=(s=(i=n.doc).getServerMeta)==null?void 0:s.call(i);return!(!r||r.serverId!==o)}async function Ev(n,t){const o=t.meta.resources;if(!o||Object.keys(o).length===0)return;let r=new Map;if(Bv(n,t)){const s=Array.from(Object.keys(o));r=await wv(n,s),V0(n,t,r)}const i=new Map;Object.entries(o).forEach(([s,l])=>{r.get(s)===void 0&&s!==l&&i.set(s,l)}),i.size!==0&&V0(n,t,i)}async function Iv(n,t){await Ev(n,t),n.undoManager.runInGroup(()=>{n.clearSelectedContents();const{block:e,offset:o}=Mr(n);n.insertDoc(e,o,t)})}const xv=["text/x-ones-editor-doc","image/*","text/html","text/plain","text/markdown","*"];function Tv(n){let t;for(const e of xv)if(t=n[e],t)break;return t||null}class Sv{constructor(t){h(this,"editor");h(this,"handlers",[]);h(this,"onPasteText",async t=>{const e=new DataTransfer;e.setData("text/plain",t);const o=await this.editor.dataConverter.fromData(this.editor,e);o&&this.pasteDocs(o,null)});this.editor=t}onInsertText(t,e){if(!P(this.editor,this.editor.getFocusedBlock()))return;const{containerId:o,blockIndex:r,offset:i}=Mr(this.editor);this.handleBeforeInsertText(o,r,i,e)||(this.defaultInsertText(this.editor,o,r,i,e),this.handleAfterInsertText(o,r,i,e))}onKeyDown(t){if(this.handleBeforeKeyDown(t))return!0;const e=this.defaultHandleKeydown(this.editor,t);return this.handleAfterKeyDown(t)?!0:e}onChanged(t){for(let e=0;e<this.handlers.length;e++){const o=this.handlers[e];o.handleChanged&&o.handleChanged(this.editor,t)}}onRemoteChanged(t){for(let e=0;e<this.handlers.length;e++){const o=this.handlers[e];o.handleRemoteChanged&&o.handleRemoteChanged(this.editor,t)}}onCompositionStart(t){this.editor.updateCompositionText("",!1);const{containerId:e,blockIndex:o,offset:r}=Mr(this.editor);for(let i=0;i<this.handlers.length;i++){const s=this.handlers[i];s.handleCompositionStart&&s.handleCompositionStart(this.editor,e,o,r)}}onUpdateCompositionText(t,e,o){this.editor.updateCompositionText(e,o),this.editor.selection.caret.update();const{containerId:r,blockIndex:i,offset:s}=Mr(this.editor);for(let l=0;l<this.handlers.length;l++){const c=this.handlers[l];c.handleUpdateCompositionText&&c.handleUpdateCompositionText(this.editor,r,i,s,o)}}onCopy(t){kv(this.editor,t,(e,o,r)=>{for(let i=0;i<this.handlers.length;i++){const s=this.handlers[i];if(s.handleBeforeCopy){const l=s.handleBeforeCopy(this.editor,o,r);if(l===!0)return!0;if(typeof l=="object"&&l!=null)return l}}})}onPaste(t){if(t.preventDefault(),t.stopPropagation(),!t.clipboardData)return;this.editor.dataConverter.fromData(this.editor,t.clipboardData).then(async o=>{o&&this.pasteDocs(o,t)})}onFocus(){A(this.editor.rootElement,"active")}onBlur(){z(this.editor.rootElement,"active")}addHandler(t){this.handlers.push(t)}removeHandler(t){const e=this.handlers.indexOf(t);e!==-1&&this.handlers.splice(e)}handleBeforeInsertText(t,e,o,r){for(let i=0;i<this.handlers.length;i++){const s=this.handlers[i];if(s.handleBeforeInsertText&&s.handleBeforeInsertText(this.editor,t,e,o,r))return!0}return!1}handleAfterInsertText(t,e,o,r){for(let i=0;i<this.handlers.length;i++){const s=this.handlers[i];if(s.handleAfterInsertText&&s.handleAfterInsertText(this.editor,t,e,o,r))return!0}return!1}handleBeforeKeyDown(t){for(let o=0;o<this.handlers.length;o++){const r=this.handlers[o];if(r.handleBeforeKeyDown&&r.handleBeforeKeyDown(this.editor,t))return!0}const e=this.defaultHandleKeydown(this.editor,t);for(let o=0;o<this.handlers.length;o++){const r=this.handlers[o];if(r.handleAfterKeyDown&&r.handleAfterKeyDown(this.editor,t))return!0}return e}handleAfterKeyDown(t){for(let o=0;o<this.handlers.length;o++){const r=this.handlers[o];if(r.handleBeforeKeyDown&&r.handleBeforeKeyDown(this.editor,t))return!0}const e=this.defaultHandleKeydown(this.editor,t);for(let o=0;o<this.handlers.length;o++){const r=this.handlers[o];if(r.handleAfterKeyDown&&r.handleAfterKeyDown(this.editor,t))return!0}return e}defaultInsertText(t,e,o,r,i){au(this.editor,i)}defaultHandleKeydown(t,e){return z0(this.editor,e)?(e.preventDefault(),e.stopPropagation(),!0):!1}async pasteDoc(t){for(let e=0;e<this.handlers.length;e++){const o=this.handlers[e];if(o.handleBeforePasteDoc&&await o.handleBeforePasteDoc(this.editor,t))return}await Iv(this.editor,t);for(let e=0;e<this.handlers.length;e++){const o=this.handlers[e];if(o.handleAfterPasteDoc&&await o.handleAfterPasteDoc(this.editor,t))return}}async pasteDocs(t,e){for(let r=0;r<this.handlers.length;r++){const i=this.handlers[r];if(i.handleBeforePaste&&await i.handleBeforePaste(this.editor,e,t))return}const o=Tv(t);if(!!o){await this.pasteDoc(o);for(let r=0;r<this.handlers.length;r++){const i=this.handlers[r];if(i.handleAfterPaste&&await i.handleAfterPaste(this.editor,e,t))return}}}destroy(){this.handlers.forEach(t=>{var e;(e=t.destroy)==null||e.call(t,this.editor)}),this.handlers=[]}}function Dv(n,t,e){const o=yr(t,e);return o.remove(),o}B("copy-dom-attributes");const q0=["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 Lv(n,t){for(let l=0;l<q0.length;l++){const c=q0[l];t[c]=n[c]}const e=n.attributes,o=t.attributes,r=[],i=[];for(let l=0;l<e.length;l++){const c=e[l],a=o.getNamedItem(c.name);a?a.value!==c.value&&(a.value=c.value,i.push(c)):r.push(c)}const s=[];for(let l=0;l<o.length;l++){const c=o[l];e.getNamedItem(c.name)||s.push(c)}r.forEach(l=>{t.setAttribute(l.name,l.value)}),i.forEach(l=>{t.setAttribute(l.name,l.value)}),s.forEach(l=>{t.removeAttribute(l.name)})}function W0(n){const t=Array.from(n.childNodes);return t.forEach(e=>{e instanceof HTMLElement&&e.getAttribute("data-type")==="block-tools"||e.remove()}),t}function G0(n,t,e){var a;const o=n.getContainerById(t),r=yr(o,e),i=io(r),s=n.doc.getBlockData(t,e),l=kt(n,r);if((a=l==null?void 0:l.handleUpdateBlock)==null?void 0:a.call(l,n,r,s))n.editorBlockRenders.updateBlock(n,i,r,s);else{const u=n.editorBlocks.createBlock(i,o,s),f=W0(u);W0(r),f.forEach(C=>r.appendChild(C));const m=Dl(u);if(m){const C=Dl(r);C&&C.remove(),r.appendChild(m)}Lv(u,r)}mg(n,r,s),n.blockHooks.forEach(u=>{var f;(f=u.update)==null||f.call(u,n,i,o,r,s)}),setTimeout(()=>{n.selection.updateSelection(null)})}const Mv=B("transform-selection");function Z0(n,t,e,o){const{range:r}=n.selection,{anchor:i,focus:s}=r;if(i.blockId!==t&&s.blockId!==t)return r;d(Mv,i.isSimple()&&s.isSimple(),"invalid text pos type");let l=i;if(i.blockId===t){const a=ie.transformCursor(i.offset,e,o);l=j(t,a,"normal")}let c=s;if(s.blockId===t){const a=ie.transformCursor(s.offset,e,o);c=j(t,a,"normal")}return qt(n,{anchor:l,focus:c})}const Rv=B("handle-block-text-changed");function Av(n,t,e,o,r){const i=n.getContainerById(t),s=yr(i,e),l=n.doc.getBlockData(t,e);if(d(Rv,l.text,"no block text"),dg(n,s).setBlockText(n,s,l.text),!r){const c=Z0(n,l.id,o,r);n.selection.setRange(c,{noScroll:!0})}}function Ov(n,t){const e=Y.default(n);return t.delete.forEach(r=>{delete e[r]}),{...e,...t.insert}}function Y0(n,t,e,o){const r=kt(n,t);r.handleDeleteBlock&&r.handleDeleteBlock(n,t,e,o),n.emit("blockDeleted",n,t,e,o)}function _v(n,t,e,o){const r=n.getBlockByIndex(t,e);r.querySelectorAll('[data-type="editor-block"]').forEach(i=>{Y0(n,i,o,{child:!0})}),Y0(n,r,o,{child:!1})}const Vn=B("editor-doc");class Nv extends Di{constructor(e,o,r){super();h(this,"localEvents",[]);this.editor=e,this.externalDoc=o,this.externalDoc.registerCallback(this),this.registerLocalEvents(r)}beginBatchUpdate(){return this.externalDoc.beginBatchUpdate()}endBatchUpdate(){return this.externalDoc.endBatchUpdate()}registerLocalEvents(e){this.localEvents.push(e)}toJSON(){return this.externalDoc.toJSON()}getVersionHelper(){var o,r;return(r=(o=this.externalDoc).getVersionHelper)==null?void 0:r.call(o)}getContainerBlocks(e){return this.externalDoc.getContainerBlocks(e)}getBlockData(e,o){return this.externalDoc.getBlockData(e,o)}localUpdateBlockText(e,o,r,i){d(Vn,this.editor.isWritable(),"editor is readonly");const s=this.getBlockData(e,o),l=s.text;d(Vn,l,`no text, ${e}, ${o}`);const c=Z0(this.editor,s.id,r,!0),a=ie.apply(l,r);this.localEvents.forEach(f=>f.onBeforeUpdateBlockText(e,s.id,l,a,c.toDocRange()));const u=this.externalDoc.localUpdateBlockText(e,o,r);return this.editor.selection.setRange(c,i),u}localUpdateBlockData(e,o,r,i){d(Vn,this.editor.isWritable(),"editor is readonly");const s=Y.default(this.getBlockData(e,o)),l=Y.default(Ov(s,r));this.localEvents.forEach(a=>a.onBeforeUpdateBlockData(e,s.id,s,l,i));const c=this.externalDoc.localUpdateBlockData(e,o,r,i);return this.editor.selection.setRange(co(this.editor,i)),c}localInsertBlock(e,o,r,i,s){d(Vn,this.editor.isWritable(),"editor is readonly"),this.localEvents.forEach(c=>c.onBeforeInsertBlock(e,o,r,i));const l=this.externalDoc.localInsertBlock(e,o,r,i);return this.editor.selection.setRange(co(this.editor,i),s),l}localDeleteBlock(e,o,r){d(Vn,this.editor.isWritable(),"editor is readonly");const i=Y.default(this.getBlockData(e,o));this.localEvents.forEach(l=>l.onBeforeDeleteBlock(e,o,i,r));const s=this.externalDoc.localDeleteBlock(e,o,r);return this.editor.selection.setRange(co(this.editor,r)),s}localDeleteChildContainers(e){return d(Vn,this.editor.isWritable(),"editor is readonly"),e.forEach(o=>{const r=Y.default(this.getContainerBlocks(o));this.localEvents.forEach(i=>i.onBeforeDeleteChildContainer(o,r))}),this.externalDoc.localDeleteChildContainers(e)}localInsertChildContainer(e,o){return d(Vn,this.editor.isWritable(),"editor is readonly"),this.localEvents.forEach(r=>r.onBeforeInsertChildContainer(e,Y.default(o))),this.externalDoc.localInsertChildContainer(e,o)}onRequestReload(e){Vn.debug(`reload doc: ${e}`),this.editor.reload(),this.callbacks.forEach(r=>{var i;return(i=r.onRequestReload)==null?void 0:i.call(r,e)});const o=!1;this.editor.emit("docChanged",this.editor,o)}onUpdateBlockText(e,o,r,i){this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockText)==null?void 0:l.call(s,e,o,r,i)}),Av(this.editor,e,o,r,i),this.editor.emit("docChanged",this.editor,i)}onUpdateBlockData(e,o,r,i){this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockData)==null?void 0:l.call(s,e,o,r,i)}),G0(this.editor,e,o),this.editor.emit("docChanged",this.editor,i)}onInsertBlock(e,o,r,i){this.callbacks.forEach(l=>{var c;return(c=l.onInsertBlock)==null?void 0:c.call(l,e,o,r,i)});const s=this.editor.getContainerById(e);v8(this.editor,s,o,r),this.editor.emit("docChanged",this.editor,i)}onDeleteBlock(e,o,r){_v(this.editor,e,o,r),this.callbacks.forEach(s=>{var l;return(l=s.onDeleteBlock)==null?void 0:l.call(s,e,o,r)});const i=this.editor.getContainerById(e);Dv(this.editor,i,o),this.editor.emit("docChanged",this.editor,r)}onInsertChildContainer(e,o,r){this.callbacks.forEach(i=>{var s;return(s=i.onInsertChildContainer)==null?void 0:s.call(i,e,o,r)})}onDeleteChildContainer(e,o){this.callbacks.forEach(r=>{var i;return(i=r.onDeleteChildContainer)==null?void 0:i.call(r,e,o)})}onCustomMessage(e){this.callbacks.forEach(o=>{var r;return(r=o.onCustomMessage)==null?void 0:r.call(o,e)})}onStatusChanged(e){this.callbacks.forEach(o=>{var r;return(r=o.onStatusChanged)==null?void 0:r.call(o,e)})}onError(e){this.callbacks.forEach(o=>{var r;return(r=o.onError)==null?void 0:r.call(o,e)})}uploadResource(e,o){return this.externalDoc.uploadResource(e,o)}addResources(e){return this.externalDoc.addResources(e)}buildResourceUrl(e,o){return this.externalDoc.buildResourceUrl(e,o)}request(e,o){return this.externalDoc.request(e,o)}broadcastMessage(e){return this.externalDoc.broadcastMessage(e)}getUser(){return this.externalDoc.getUser()}getRemoteUsers(){return this.externalDoc.getRemoteUsers()}destroy(){this.externalDoc.destroy(),this.clearCallbacks()}getServerMeta(){var e,o,r;return(r=(o=(e=this.externalDoc).getServerMeta)==null?void 0:o.call(e))!=null?r:{}}reset(e){Vn.log("reset doc"),this.externalDoc=e,this.externalDoc.registerCallback(this),this.editor.reload()}}function Q0(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 Au=B("undo-action");class _r{constructor(t,e,o){h(this,"beforeRange");h(this,"afterRange");this.containerId=e,this.beforeRange=t.selection.range.clone().toDocRange(),this.afterRange=o}undo(t){return!1}redo(t){return!1}combinable(t){return d(Au,t,"no other action"),!1}combine(t){d(Au,!1,"no other")}setAfterRange(t){this.afterRange&&Au.warn("after range has already set"),this.afterRange=t}}const $v=B("block-action");class K0 extends _r{constructor(e,o,r,i,s){super(e,o,s);h(this,"blockData");h(this,"blockIndex");this.blockData=Y.default(i),this.blockIndex=r}deleteBlock(e,o){if(!e.getContainerById(this.containerId))return!1;const i=e.getBlockById(this.blockData.id);return i?(d($v,this.blockIndex===J(i),"invalid block index"),hu(e,i,co(e,o)),!0):!1}insertBlock(e,o){return Rr(e,this.containerId,this.blockIndex,Y.default(this.blockData),o),!0}}class Pv extends K0{undo(t){return this.deleteBlock(t,this.beforeRange)}redo(t){return this.insertBlock(t,this.afterRange)}}class jv extends K0{undo(t){return this.insertBlock(t,this.beforeRange)}redo(t){return this.deleteBlock(t,this.afterRange)}}class Hv extends _r{constructor(e){super(e,U(e.rootContainer),e.selection.range.toDocRange());h(this,"actions",[])}addAction(e){Q0(this.actions,e),this.afterRange=e.afterRange}undo(e){let o=!1;return this.actions.concat().reverse().forEach(r=>{r.undo(e)&&(o=!0)}),o}redo(e){let o=!1;return this.actions.forEach(r=>{r.redo(e)&&(o=!0)}),o}setAfterRange(e){this.afterRange=e;const o=this.actions[this.actions.length-1];!o||o instanceof _r&&(o.afterRange||o.setAfterRange(e))}}const Xo=B("update-block-data-action");class dc extends _r{constructor(e,o,r,i,s,l){super(e,o,l);h(this,"beforeBlockData");h(this,"afterBlockData");h(this,"blockId");this.blockId=r,d(Xo,this.blockId===i.id,"invalid block id"),d(Xo,this.blockId===s.id,"invalid block id"),this.beforeBlockData=Y.default(i),this.afterBlockData=Y.default(s),d(Xo,this.beforeBlockData.type===this.afterBlockData.type,"invalid block type")}undo(e){d(Xo,e,"no editor");const o=e.getBlockById(this.blockId);if(!o)return!1;const r=e.getContainerById(this.containerId);return d(Xo,r,"no container"),rc(e,o,dc.toAttributes(this.beforeBlockData),this.beforeRange),!0}redo(e){d(Xo,e,"no editor");const o=e.getBlockById(this.blockId);if(!o)return!1;const r=e.getContainerById(this.containerId);return d(Xo,r,"no container"),rc(e,o,dc.toAttributes(this.afterBlockData),this.afterRange),!0}static toAttributes(e){const o=Y.default(e);return delete o.id,delete o.type,o}}const Ou=B("update-block-text-action");class ns extends _r{constructor(e,o,r,i,s,l){super(e,o,l);h(this,"beforeRichTextData");h(this,"afterRichTextData");h(this,"blockId");h(this,"type");this.blockId=r,this.beforeRichTextData=Y.default(i),this.afterRichTextData=Y.default(s),this.type=ns.calType(i,s)}static calType(e,o){d(Ou,e,"no old data"),d(Ou,o,"no new data");const i=ie.diff(e,o),s=new Set;let l=!1;const c=u=>km(u)?`cjk_${u}`:Cm(u)?"number":vl(u)?"space":bm(u)?"letter":"unknown";let a=!1;return i.forEach(u=>{u.insert?u.insert===" "?s.add("insert_letter"):typeof u.insert=="string"&&u.insert.startsWith(" ")&&u.insert.length>1?(l=!0,a=!0,s.add(`insert_${c(u.insert.substr(1))}`)):s.add(`insert_${c(u.insert)}`):u.delete&&(l?l=!1:s.add("delete"))}),{textType:Array.from(s).join("|"),begin:a}}undo(e){if(!e.getContainerById(this.containerId))return!1;const r=e.getBlockById(this.blockId);return r?(oc(e,r,this.beforeRichTextData),!0):!1}redo(e){if(!e.getContainerById(this.containerId))return!1;const r=e.getBlockById(this.blockId);return r?(oc(e,r,this.afterRichTextData),!0):!1}combinable(e){if(!(e instanceof ns)||e.type.begin||this.type.textType!==e.type.textType||e.blockId!==this.blockId)return!1;const o=e.beforeRange,r=o.anchor;if(!r.isSimple())return!1;const i=this.afterRange;if(!i)return!1;const s=i.anchor;return!(!s.isSimple()||s.blockId!==o.anchor.blockId||s.offset!==r.offset)}combine(e){d(Ou,e instanceof ns,"invalid action type");const o=e;this.afterRichTextData=o.afterRichTextData,this.afterRange=e.afterRange}}class J0 extends _r{constructor(t,e,o){super(t,e,t.selection.range.toDocRange()),this.blocks=o}deleteChildContainer(t){return t.doc.localDeleteChildContainers([this.containerId]),!0}insertChildContainer(t){return t.doc.localInsertChildContainer(this.containerId,Y.default(this.blocks)),!0}}class Fv extends J0{undo(t){return this.deleteChildContainer(t)}redo(t){return this.insertChildContainer(t)}}class zv extends J0{undo(t){return this.insertChildContainer(t)}redo(t){return this.deleteChildContainer(t)}}const nn=B("undo");class Uv{constructor(t){h(this,"editor");h(this,"actions",[]);h(this,"undoCursor");h(this,"currentGroup",null);h(this,"groupCounter",0);h(this,"undoRedoing",!1);h(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):(Q0(this.actions,t),setTimeout(()=>{this.editor.input.handleChanged(t)}))}beginGroup(){this.groupCounter===0?(d(nn,!this.currentGroup,"current group already exists"),this.currentGroup=new Hv(this.editor),this.groupCounter=1):(d(nn,this.currentGroup,"current group not exists"),this.groupCounter+=1)}endGroup(){d(nn,this.currentGroup,"current group not exists"),d(nn,this.groupCounter>0,"group counter === 0"),this.groupCounter-=1,this.groupCounter===0&&(this.currentGroup.actions.length===0?nn.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 nn.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(co(this.editor,t.beforeRange))}catch(e){nn.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(co(this.editor,e)):nn.warn("no after range")}catch(e){nn.error(`redo: failed to set caret pos after redo: ${e.message}`)}return this.editor.input.handleChanged(t),!0}}return!1}finally{this.undoRedoing=!1}}canUndo(){return!(this.actions.length===0||this.undoCursor===0)}canRedo(){return!(this.actions.length===0||this.undoCursor===-1||this.undoCursor===this.actions.length)}lastAction(){var e;const t=this.undoCursor===-1?this.actions.length-1:this.undoCursor-1;return(e=this.actions[t])!=null?e:null}undoTo(t){for(;;){const e=this.lastAction();if(!e||e===t)return!0;if(!this.undo())return!1}}onBeforeUpdateBlockText(t,e,o,r,i){this.undoRedoing||(this.prepareSaveUndoState(),ie.diff(o,r).length!==0&&this.addAction(new ns(this.editor,t,e,o,r,i)))}onBeforeUpdateBlockData(t,e,o,r,i){if(this.undoRedoing)return;this.prepareSaveUndoState();const s=new dc(this.editor,t,e,o,r,i);this.addAction(s)}onBeforeInsertBlock(t,e,o,r){this.undoRedoing||(this.prepareSaveUndoState(),d(nn,e>=0,"invalid block index"),d(nn,o,"no block data"),this.addAction(new Pv(this.editor,t,e,o,r)))}onBeforeDeleteBlock(t,e,o,r){this.undoRedoing||(this.prepareSaveUndoState(),this.addAction(new jv(this.editor,t,e,o,r)))}onBeforeInsertChildContainer(t,e){this.undoRedoing||(this.prepareSaveUndoState(),this.addAction(new Fv(this.editor,t,e)))}onBeforeDeleteChildContainer(t,e){this.undoRedoing||(this.prepareSaveUndoState(),this.addAction(new zv(this.editor,t,e)))}}class Vv{async fromData(t,e){const o=e.getData("text/x-ones-editor-doc");if(o)return{"text/x-ones-editor-doc":JSON.parse(o)}}}class qv{constructor(){h(this,"converters",[]);this.addConverter(new Vv)}async fromData(t,e){let o={};for(const r of this.converters){const i=await r.fromData(t,e);i&&(o={...o,...i})}return o}addConverter(t){this.converters.push(t)}}class Wv{constructor(t){h(this,"renders",[]);this.editor=t}registerRender(t){this.renders.push(t)}renderText(t,e){const o={classes:[],attributes:{},styles:{}};return this.renders.forEach(r=>{if(r.renderText){const i=r.renderText(this.editor,t,e);i.classes&&o.classes.push(...i.classes),i.attributes&&(o.attributes={...o.attributes,...i.attributes}),i.styles&&(o.styles={...o.styles,...i.styles})}}),o}renderBlock(t,e,o){const r={classes:[],attributes:{},styles:{}};return this.renders.forEach(i=>{if(i.renderBlock){const s=i.renderBlock(this.editor,e,o);s.classes&&r.classes.push(...s.classes),s.attributes&&(r.attributes={...r.attributes,...s.attributes}),s.styles&&(r.styles={...r.styles,...s.styles})}}),r}updateBlock(t,e,o,r){this.renders.forEach(i=>{var s;(s=i.updateBlock)==null||s.call(i,t,e,o,r)})}}class Nt extends Yt.TypedEmitter{constructor(e){super();h(this,"hoveringBlock",null);h(this,"hoveringTextChild",null);h(this,"filters",[]);h(this,"finders",[]);h(this,"handleDocumentMouseMove",e=>{if(this.hoveringBlock){for(const s of this.filters)if(s.isInBlock(this.hoveringBlock,e))return}const o=document.elementFromPoint(e.x,e.y);if(!o){this.setHoveringBlock(null,e,null);return}let r=F(o);if((!r||!It(this.editor.rootContainer,r))&&(r=this.findBlockByFinders(e),!r)){this.setHoveringBlock(null,e,null);return}const i=this.getParentTextContentChild(r,o);this.setHoveringBlock(r,e,i)});this.editor=e,document.addEventListener("mousemove",this.handleDocumentMouseMove)}destroy(){document.removeEventListener("mousemove",this.handleDocumentMouseMove),this.filters.forEach(e=>e.destroy()),this.filters=[],this.finders.forEach(e=>e.destroy()),this.finders=[]}addFilter(e){this.filters.push(e)}addFinder(e){this.finders.push(e)}hoveringBlockId(){return this.hoveringBlock?q(this.hoveringBlock):""}findBlockByFinders(e){for(let o=0;o<this.finders.length;o++){const i=this.finders[o].findTargetBlock(this.editor,e);if(i)return i}return null}setHoveringBlock(e,o,r){if(this.hoveringBlock===e&&this.hoveringTextChild===r)return;if(this.hoveringBlock!==e){const s=this.hoveringBlock&&It(this.editor.rootContainer,this.hoveringBlock)?this.hoveringBlock:null;s&&z(s,"hover"),e&&A(e,"hover"),this.hoveringBlock=e,this.emit("change",this.hoveringBlock,s,o)}const i=this.hoveringTextChild;this.hoveringTextChild=r,this.emit("childChange",this.hoveringBlock,r,i,o)}static get(e){return e.addCustom("standard-hovering-block",()=>new Nt(e))}getParentTextContentChild(e,o){if(!P(this.editor,e))return null;const r=it(e);return o.parentElement===r?o:kd(o)}}const X0="style-color-",t2="style-bg-color-";class Gv{renderText(t,e,o){const r=[],i={};return Object.entries(o).forEach(([s,l])=>{l===!0?s.startsWith(X0)?i["data-style-color"]=s.substring(X0.length):s.startsWith(t2)?i["data-style-bg-color"]=s.substring(t2.length):s.startsWith("style")&&r.push(s):typeof l=="string"&&s==="link"&&(r.push("link"),i.link=l)}),{classes:r,attributes:i}}renderBlock(t,e,o){var l,c;const r={};Object.entries(o).filter(a=>a[0].startsWith("style-")).forEach(([a,u])=>{r[`data-${a}`]=`${u}`});const s=[];return((c=(l=t.selection)==null?void 0:l.range)==null?void 0:c.start.blockId)===o.id&&s.push("focused"),typeof o.align=="string"&&o.align&&(r["data-style-align"]=o.align),o.heading&&(r["data-style-heading"]=String(o.heading)),o.quoted&&(r["data-style-quoted"]="true"),Nt.get(t).hoveringBlockId()===o.id&&s.push("hover"),{attributes:r,classes:s}}updateBlock(t,e,o,r){var s,l;Array.from(o.attributes).forEach(c=>{c.name.startsWith("data-style-")&&o.removeAttribute(c.name)}),Object.entries(r).filter(c=>c[0].startsWith("style-")).forEach(([c,a])=>{o.setAttribute(`data-${c}`,`${a}`)}),((l=(s=t.selection)==null?void 0:s.range)==null?void 0:l.start.blockId)===r.id&&A(o,"focused"),Nt.get(t).hoveringBlockId()===r.id&&A(o,"hover")}}function Zv(n){n.editorBlocks.registerBlockClass(ke),n.editorBlocks.registerBlockClass(Ig),n.editorBoxes.registerBoxClass(gp),n.editorBoxes.registerBoxClass(pp),n.editorInsertions.registerInsertionClass(kp),n.editorBlockRenders.registerRender(new Gv)}function Yv(n,t){Zv(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 e2=B("range-commands");function n2(n,t){n.forEach(e=>{e.source=t,e.children&&n2(e.children,t)})}function o2(n,t,e){const o=q(t);d(e2,o===e.start.blockId,"invalid start range"),d(e2,o===e.end.blockId,"invalid end range");const r=n.editorCommandProviders.getCommandProviders();let i=[];return r.forEach(s=>{const l=s.getAvailableCommands(n,t,e);n2(l,s.id),i.push(...l)}),r.forEach(s=>{if(s.filterCommands){const l=s.filterCommands(n,t,e,i);l&&(i=l)}}),at(n,t)&&xr(n,t,e.start,e.end).forEach(l=>{Mt(l).forEach(a=>{const u=W(n,a),f=qt(n,{anchor:j(a,0,"home"),focus:j(a,u,"end")}),m=o2(n,a,f);i.push(...m)})}),i}function r2(n){const t=n.getEditor(),e=n.getSelectedBlocks(),o=[];return e.forEach(r=>{const i=qt(t,{anchor:r.start,focus:r.end});o2(t,r.block,i).forEach(l=>{o.push(l)})}),o}function i2(n,t,e,o,r,i){var u;const s=n.editorCommandProviders.getCommandProviders();for(let f=0;f<s.length;f++){const m=s[f];if(m.beforeExecuteCommand&&m.beforeExecuteCommand(n,t,e,o,r))return!1}const l=n.editorCommandProviders.getCommandProvider(o.source),c={};if((u=l.executeCommand)!=null&&u.call(l,n,t,e,o,r,{}))return i[q(t)]=c,!0;let a=!1;return at(n,t)&&xr(n,t,e.start,e.end).forEach(m=>{Mt(m).forEach(k=>{const w=W(n,k),y=qt(n,{anchor:j(k,0,"home"),focus:j(k,w,"end")});i2(n,k,y,o,r,i)&&(a=!0)})}),s.forEach(f=>{f.afterExecuteCommand&&f.afterExecuteCommand(n,t,e,o,r,i)}),a}function s2(n,t,e){const o=n.getEditor(),r={},i=o.editorCommandProviders.getCommandProvider(t.source);return i.executeRangeCommand&&i.executeRangeCommand(o,n,t,e,r)||n.getSelectedBlocks().forEach(l=>{const c=qt(o,{anchor:l.start,focus:l.end});i2(o,l.block,c,t,e,r)}),r}const Qv=B("command-providers");class l2{constructor(t){h(this,"providers",[]);this.editor=t}registerCommandProvider(t){this.providers.push(t)}getCommandProviders(){return this.providers}getCommandProvider(t){const e=this.providers.find(o=>o.id===t);return d(Qv,e,`no command provider, id=${t}`),e}getCommands(t){return r2(t)}executeCommand(t,e,o){return this.editor.undoManager.runInGroup(()=>s2(t,e,o))}getEmptyBlockTextAttributes(t,e){let o={};if(this.providers.forEach(r=>{var s;const i=(s=r.getEmptyBlockTextAttributes)==null?void 0:s.call(r,t,e);i&&(o={...o,...i})}),Object.keys(o).length!==0)return o}}function Kv(n,t){const e=H(t),o=U(e),r=J(t);G0(n,o,r)}const Jv=B("table-scroll");class c2{constructor(t,e,o,r,i){h(this,"handleEvent",t=>{this.handler(this.editor,t,this.data)});this.editor=t,this.dom=e,this.name=o,this.handler=r,this.data=i,e.addEventListener(o,this.handleEvent)}destroy(){this.dom.removeEventListener(this.name,this.handleEvent)}}class Xv{constructor(t){h(this,"handlers",new Map);this.editor=t}destroy(){Array.from(this.handlers.entries()).forEach(([t,e])=>{e.forEach(o=>o.destroy()),this.handlers.delete(t)})}addEventListener(t,e,o,r){const i=this.handlers.get(t);if(i){if(i.find(s=>s.handler===o&&s.name===e)){Jv.warn(`event has already registered: ${e}`);return}i.push(new c2(this.editor,t,e,o,r))}else{const s=new c2(this.editor,t,e,o,r);this.handlers.set(t,[s])}}removeEventListener(t,e,o){if(!t){for(const[i,s]of Array.from(this.handlers.entries()))for(let l=s.length-1;l>=0;l--){const c=s[l];if(e)e===c.name&&o===c.handler&&s.splice(l,1);else if(o===c.handler){s.splice(l,1),c.destroy(),s.length===0&&this.handlers.delete(i);continue}}return}const r=this.handlers.get(t);if(r){const i=r.findIndex(s=>s.handler===o&&s.name===e);if(i!==-1){const s=r[i];r.splice(i,1),s.destroy(),r.length===0&&this.handlers.delete(t)}}}removeAllListeners(t,e){const o=this.handlers.get(t);if(o)if(e)for(let r=0;r<o.length;r++){const i=o[r];i.name===e&&(o.splice(r,1),i.destroy())}else o.forEach(r=>{r.destroy()}),this.handlers.delete(t)}}const a2=B("update-block-text");function ty(n,t){const e=n.getBoxById(t.id),o=F(e);d(a2,o,"no parent block"),d(a2,P(n,o),"not a text block");const r=n.getBlockText(o),i=ip(r,"id",t.id,t);Fp(n,o,i)}function ey(n,t){for(const e of n.blockHooks)if(e.writable){const o=e.writable(n,t);if(typeof o=="boolean")return o}return!0}function ny(n){return n.readonly?!1:!tn(n).find(o=>!n.isBlockWritable(o.block))}class oy{constructor(t){this.editor=t}getKey(t){return`${this.editor.id}-${t}`}async getItem(t){return window.localStorage.getItem(this.getKey(t))}async setItem(t,e){if(!e){this.removeItem(t);return}window.localStorage.setItem(this.getKey(t),e)}async removeItem(t){window.localStorage.removeItem(this.getKey(t))}}class ry{constructor(){h(this,"shortcuts",[])}handleKeyboardEvents(t,e){const o=this.shortcuts;for(const r of o){const i=Object.entries(r);for(const[s,l]of i)if(jn(e,s)){const c=l(t,e);if(c!==void 0)return c}}}}const Bn=B("editor");class iy extends Yt.TypedEmitter{constructor(e,o,r){var i,s,l,c,a,u,f,m;super();h(this,"parent");h(this,"rootElement");h(this,"contentElement");h(this,"rootContainerObject");h(this,"rootContainer");h(this,"input");h(this,"selection");h(this,"selectionHandler");h(this,"doc");h(this,"id");h(this,"clientId");h(this,"compositingText","");h(this,"undoManager");h(this,"shortcuts",new ry);h(this,"dataConverter",new qv);h(this,"editorBlocks",new yg(this));h(this,"editorBoxes",new bp(this));h(this,"editorInsertions",new yp(this));h(this,"editorEmbeds",new Bg(this));h(this,"editorDecorators",new wp(this));h(this,"editorCommandProviders",new l2(this));h(this,"editorBlockRenders",new Wv(this));h(this,"blockHooks",[]);h(this,"domEvents",new Xv(this));h(this,"customs",new Map);h(this,"options");h(this,"inputHandlers",new Sv(this));h(this,"settingsProvider");h(this,"_readonly",!1);Bn.debug("create editor"),this.setMaxListeners(100),this.options={colors:(i=r==null?void 0:r.colors)!=null?i:["#9923E9","#4587C2","#8BDB7A","#FB28D3","#CBC619","#10FEEB","#812A1A","#8A3F25","#22D742","#A53E74","#555C87","#57E0AA"],componentsOptions:(l=(s=r==null?void 0:r.components)==null?void 0:s.options)!=null?l:{},scrollContainer:r==null?void 0:r.scrollContainer},this.settingsProvider=(c=r==null?void 0:r.settingsProvider)!=null?c:new oy(this),Yv(this,r==null?void 0:r.components),Bn.debug(((a=r==null?void 0:r.components)==null?void 0:a.blockHooks)||[],"register block hooks"),this.blockHooks.push(...(f=(u=r==null?void 0:r.components)==null?void 0:u.blockHooks)!=null?f:[]),this.id=(m=r==null?void 0:r.id)!=null?m:N(),this.clientId=N(),this.undoManager=new Uv(this),this.doc=new Nv(this,o,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=lg(this),this.rootContainer=this.rootContainerObject.rootContainer,this.input=new pk(this,this.inputHandlers),this.selection=new ev(this),this.selectionHandler=new rv(this),r!=null&&r.shortcuts&&this.shortcuts.shortcuts.push(...r.shortcuts),xt.isMobile&&A(this.rootElement,"mobile"),xt.isSafari&&A(this.rootElement,"safari"),this._readonly&&A(this.rootElement,"readonly"),this.emit("load",this,!1)}get readonly(){return this._readonly}set readonly(e){this._readonly=e,e?A(this.rootElement,"readonly"):z(this.rootElement,"readonly"),this.emit("readonlyChanged",this)}get scrollContainer(){return this.options.scrollContainer?this.options.scrollContainer:We(this.rootContainer)}addCustom(e,o){const r=this.customs.get(e);if(r)return r;const i=o(this);return this.customs.set(e,i),i}getCustom(e){const o=this.customs.get(e);return d(Bn,o,`${e} does not exists`),o}replaceCustom(e,o){const r=this.customs.get(e);return r&&r.destroy(),this.customs.set(e,o),o}findCustom(e){return this.customs.get(e)}findCustomByType(e){const o=this.customs.values();for(const r of o)if(r instanceof e)return r;return null}destroyCustom(e){const o=this.customs.get(e);o&&(this.customs.delete(e),o.destroy())}getComponentOptions(e){return this.options.componentsOptions[e]}registerLocalEvents(e){this.doc.registerLocalEvents(e)}reload(){this.rootContainerObject.reload(),this.emit("load",this,!0)}createBlock(e,o,r){return this.editorBlocks.createBlock(e,o,r)}createBox(e,o){return this.editorBoxes.createBox(e,o)}createInsertion(e,o){return this.editorInsertions.createInsertion(e,o)}destroy(){Bn.debug("destroy editor"),this.emit("destroy",this),this.input.destroy(),this.rootContainerObject.destroy(),this.rootElement.remove(),this.doc.destroy(),this.customs.forEach(e=>e.destroy()),this.customs.clear(),this.selection.destroy(),this.domEvents.destroy(),this.removeAllListeners(),this.inputHandlers.destroy()}focus(){this.input.focus()}focusToBlock(e,o){pu(this,e,o)}isWritable(){return ny(this)}isBlockWritable(e){return ey(this,e)}getChildContainerData(e){const o=this.doc.getContainerBlocks(e);return d(Bn,o,`no child container data: ${e}, ${JSON.stringify(this.doc)}`),d(Bn,Array.isArray(o),`container data is not an array: ${JSON.stringify(o)}`),o}createChildContainer(e,o,r){return cg(this,e,o,r)}getFirstBlock(){return this.rootContainer.querySelector("[data-type=editor-block]")}getLastBlock(){const e=Array.from(this.rootContainer.querySelectorAll(":scope [data-type=editor-block]"));return e[e.length-1]}getFocusedBlock(){return this.selection.getFocusedBlock()}findBlockById(e){const o=this.rootContainer.querySelector(`#${e}`);return o&&d(Bn,Vo(o),"not an valid block element"),o!=null?o:null}findBoxById(e){const o=this.rootContainer.querySelector(`#${e}`);return o&&d(Bn,bd(o),"not an valid box element"),o!=null?o:null}getBlockById(e){const o=this.findBlockById(e);return d(Bn,o,`no block, id=${e}`),o}getBoxById(e){const o=this.findBoxById(e);return d(Bn,o,`no box, id=${e}`),o}getBlockByIndex(e,o){const r=this.getContainerById(e);return yr(r,o)}getBlockIndex(e){if(typeof e=="string"){const o=this.getBlockById(e);return J(o)}return J(e)}getContainerById(e){return Er(this,e)}getParentContainer(e){return H(e)}reloadBlock(e){Kv(this,e)}contains(e){const o=e instanceof Element?e:e.parentElement;return o?o.closest("div.editor-root")===this.rootElement:!1}insertBlock(e,o,r,i,s){const l={blockId:r.id,offset:0},c={anchor:l,focus:l};return Rr(this,e,o,r,i!=null?i:c,s)}insertEmbed(e,o,r,i,s){const l={id:N(),type:"embed",embedType:r,embedData:i};return this.insertBlock(e,o,l,s)}deleteBlock(e,o){fu(this,e,o)}mergeTextBlock(e,o){return Pp(this,e,o)}breakTextBlock(e,o,r){return Ar(this,e,o,r).newBlock}getTextPosition(){return Mr(this)}getBlockString(e,o){const r=this.getBlockText(e);return bt(r,o)}getBlockData(e){return mo(this,e)}getBoxData(e){return fp(this,e)}getBlockText(e){return he(this,e)}setBlockText(e,o){Fp(this,e,o)}deleteTextFromBlock(e,o,r,i){return du(this,e,o,r,i)}insertTextToBlock(e,o,r,i){return Mp(this,e,o,r,i)}insertBoxToBlock(e,o,r){return Rp(this,e,o,r)}pasteDoc(e){return this.inputHandlers.pasteDoc(e)}insertDoc(e,o,r,i){Vp(this,e,o,r,i)}insertDocAt(e,o,r,i){return ku(this,e,o,r,i)}deleteChildContainers(e){$p(this,e)}replaceBlockText(e,o){return oc(this,e,o)}updateBlockData(e,o,r){const i={...this.getBlockData(e),...o},{id:s,type:l,...c}=i;return rc(this,e,c,(r!=null?r:this.selection.range).toDocRange())}updateEmbedData(e,o,r){return zp(this,e,o,r)}updateBoxData(e){ty(this,e)}getSelectedText(){const e=Xi(this);return Jl(this,e)}clearSelectedContents(){gu(this)}insertTextBlock(e,o,r,i){const s=Un(e!=null?e:"");return Np(this,s,o,r,i==null?void 0:i.newRange,i==null?void 0:i.insertBlockOptions)}updateCompositionText(e,o){if(e&&!o&&(this.selection.range.isCollapsed()||this.clearSelectedContents()),!e&&!o){Op(this);return}o?(this.compositingText="",cd()||au(this,e)):(this.compositingText=e,Ap(this))}getColor(e){const o=this.options.colors;return o.length===0?"#FF1A75":o[e%o.length]}}function os(n,t,e){return new iy(n,t,e)}function sy(n){const t=(o,r)=>{const i=o.findIndex(l=>l.id===r.id);if(i===-1){o.push(r);return}const s=o[i];if(s.value!==r.value){o.splice(i,1);return}if(!!s.states){if(!r.states){s.states=[];return}s.states=Xa.default(s.states,r.states)}},e=[];return n.forEach(o=>{o.forEach(r=>{t(e,r)})}),e}const ly=["#FBBFBD","#FFDDB6","#FFF897","#C5F0C1","#CEDDFE","#DCC9FC","#E5E6E8","#F76964","#FFA53D","#FFE928","#63D156","#A0BBFE","#C4A5FB","#BBBFC3"];class uc extends Yt.TypedEmitter{constructor(e){super();h(this,"users",new Map);h(this,"cursors",new Map);h(this,"addingUser",!1);h(this,"colors");this.colors=e&&e.length>0?e:ly}setCursor(e){this.addUser(e.user);const o=this.cursors.get(e.user.userId);if(o&&ml.default(o,e))return;this.cursors.set(e.user.userId,e);const r=new Set([e.range.anchor.blockId,e.range.focus.blockId]),i=new Set(r);o&&new Set([o.range.anchor.blockId,o.range.focus.blockId]).forEach(l=>{r.has(l)||i.add(l)}),this.emit("remote-carets-change",[...i])}addUsers(e){this.addingUser=!0,e.forEach(o=>this.addUser(o)),this.addingUser=!1,this.emit("change",Array.from(this.users.values()))}addUser(e){this.users.set(e.userId,e),this.addingUser||this.emit("change",Array.from(this.users.values()))}findUser(e){var o;return(o=this.users.get(e))!=null?o:null}removeUser(e){this.users.delete(e),this.cursors.delete(e),this.emit("change",Array.from(this.users.values()))}updateUsers(e){this.users.clear(),this.addingUser=!0;try{e.forEach(o=>{this.addUser(o)})}finally{this.addingUser=!1}setTimeout(()=>{this.emit("change",Array.from(this.users.values()))},300)}getSimpleCursors(e){const o=new Map;return Array.from(this.cursors.values()).filter(r=>r.range.anchor.blockId===e&&Wl(r.range)).forEach(r=>{const i=r.range.focus.offset;let s=o.get(i);s||(s=[],o.set(i,s)),s.push(r)}),o}getCursors(e){return Array.from(this.cursors.values()).filter(o=>o.range.anchor.blockId===e||o.range.focus.blockId===e)}onUpdateBlockText(e,o,r){if(!e.text)return;this.getCursors(e.id).forEach(l=>{if(Wl(l.range)){const{anchor:c,focus:a}=l.range;c.blockId===e.id&&(c.offset=ie.transformCursor(c.offset,o,r)),a.blockId===e.id&&(a.offset=ie.transformCursor(a.offset,o,r))}})}getFixedUserColor(e,o){let r=0;Array.from(e).forEach(s=>{r+=s.charCodeAt(0)});const i=r%this.colors.length;return this.colors[i]}destroy(){this.removeAllListeners()}}const te=B("local-doc");class _u extends Di{constructor(e,o){super();h(this,"doc");h(this,"serviceUrl");e?this.doc=e:this.doc={meta:{},comments:{},blocks:{root:[Un("")]}},this.serviceUrl=(o==null?void 0:o.serverUrl)||""}beginBatchUpdate(){return 0}endBatchUpdate(){return 0}toJSON(){return Y.default(this.doc)}getContainerBlocks(e){return this.doc.blocks[e]}getBlockData(e,o){const r=this.getContainerBlocks(e);d(te,r,`no container data: ${e}`);const i=r[o];return d(te,i,`no block data: ${o}`),i}localUpdateBlockText(e,o,r){const i=this.getBlockData(e,o);d(te,i.text,"no text for data");const s=ie.apply(i.text,r);return i.text=s,d(te,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(l=>{var c;return(c=l.onUpdateBlockText)==null?void 0:c.call(l,e,o,r,!0)}),s}localUpdateBlockData(e,o,r){const i=this.getBlockData(e,o);return r.delete.forEach(s=>delete i[s]),Object.entries(r.insert).forEach(([s,l])=>{i[s]=l}),d(te,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockData)==null?void 0:l.call(s,e,o,r,!0)}),i}localInsertBlock(e,o,r){const i=this.getContainerBlocks(e);return d(te,i,`no container data: ${e}`),d(te,o>=0&&o<=i.length,`invalid block index: ${o}, ${i.length}`),i.splice(o,0,r),d(te,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onInsertBlock)==null?void 0:l.call(s,e,o,r,!0)}),r}localDeleteBlock(e,o){const r=this.getContainerBlocks(e);d(te,r,`no container data: ${e}`),d(te,o>=0&&o<=r.length,`invalid block index: ${o}, ${r.length}`);const i=r[o];return r.splice(o,1),d(te,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onDeleteBlock)==null?void 0:l.call(s,e,o,!0)}),i}localInsertChildContainer(e,o){this.doc.blocks[e]=o,d(te,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(r=>{var i;return(i=r.onInsertChildContainer)==null?void 0:i.call(r,e,o,!0)})}localDeleteChildContainers(e){te.debug(`delete child containers: ${e}`),e.forEach(o=>{d(te,this.doc.blocks[o],`no child container: ${o}`),delete this.doc.blocks[o]}),e.forEach(o=>{d(te,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(r=>{var i;return(i=r.onDeleteChildContainer)==null?void 0:i.call(r,o,!0)})})}uploadResource(e,o){d(te,!1,"not implemented")}async addResources(e){return e}buildResourceUrl(e){return e}request(e,o){d(te,!1,"not implemented")}broadcastMessage(e){}getServerMeta(){return{serverId:this.serviceUrl}}getUser(){return{permission:"w",userId:"-",displayName:"-",avatarUrl:"-",rainbowIndex:0}}getRemoteUsers(){return new uc}setDoc(e){this.doc=Y.default(e),this.callbacks.forEach(o=>{var r;return(r=o.onRequestReload)==null?void 0:r.call(o,"change doc")})}destroy(){this.clearCallbacks()}}function Co(n){return pt(H(n))}class cy{constructor(t){this.cleanup=t}destroy(){var t;(t=this.cleanup)==null||t.call(this)}}function Nu(n,t,e){n.addCustom(t,()=>{var i;const o=(i=e())!=null?i:void 0;return new cy(o)})}const ay=B("remote-cursor");class dy{constructor(){h(this,"remoteUsers",new uc)}onCustomMessage(t){const e=t;if(e.type==="onlineUsers"){const o=e;this.handleUpdateUsers(o.users)}else e.type==="caret"?this.handleUpdateCaret(e):ay.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 uy(n){const{blocks:t,meta:e,comments:o,...r}=n;return{rootBlocks:t,meta:e,comments:o,childBlocks:r}}function rs(n){const{childBlocks:t,meta:e,comments:o,rootBlocks:r}=uy(Y.default(n));return{blocks:{root:r,...t},meta:e,comments:o}}function bo(n){return n==="root"?"blocks":n}function Nr(n){return n==="blocks"?"root":n}const hy={type:{name:"rich-text",uri:"http://sharejs.org/types/rich-text/v1",create(n){return new oe.default(n)},apply(n,t){const e=new oe.default(n),o=new oe.default(t);return e.compose(o).ops},compose(n,t){const e=new oe.default(n),o=new oe.default(t);return e.compose(o).ops},diff(n,t){const e=new oe.default(n),o=new oe.default(t);return e.diff(o).ops},transform(n,t,e){const o=new oe.default(n);return new oe.default(t).transform(o,e==="left").ops},transformCursor(n,t,e){return t.transformPosition(n,!e)},normalize(n){return n},serialize(n){return n.ops},deserialize(n){return n},transformPresence(n,t,e){if(!n)return null;const o=new oe.default(t),r=this.transformCursor(n.index,o,e),i=this.transformCursor(n.index+n.length,o,e);return{...n,index:r,length:i-r}}}};var is=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},ko={},$u=Qf.default.EventEmitter;ko.EventEmitter=$u,ko.mixin=fy;function fy(n){for(var t in $u.prototype)n.prototype[t]=$u.prototype[t]}var d2=["info","warn","error"];function u2(){var n={};d2.forEach(function(t){n[t]=console[t].bind(console)}),this.setMethods(n)}var my=u2;u2.prototype.setMethods=function(n){n=n||{};var t=this;d2.forEach(function(e){typeof n[e]=="function"&&(t[e]=n[e])})};var gy=my,py=new gy,h2=py;function tr(n,t){this.code=n,this.message=t||"",Error.captureStackTrace?Error.captureStackTrace(this,tr):this.stack=new Error().stack}tr.prototype=Object.create(Error.prototype),tr.prototype.constructor=tr,tr.prototype.name="ShareDBError",tr.CODES={ERR_APPLY_OP_VERSION_DOES_NOT_MATCH_SNAPSHOT:"ERR_APPLY_OP_VERSION_DOES_NOT_MATCH_SNAPSHOT",ERR_APPLY_SNAPSHOT_NOT_PROVIDED:"ERR_APPLY_SNAPSHOT_NOT_PROVIDED",ERR_CLIENT_ID_BADLY_FORMED:"ERR_CLIENT_ID_BADLY_FORMED",ERR_CANNOT_PING_OFFLINE:"ERR_CANNOT_PING_OFFLINE",ERR_CONNECTION_SEQ_INTEGER_OVERFLOW:"ERR_CONNECTION_SEQ_INTEGER_OVERFLOW",ERR_CONNECTION_STATE_TRANSITION_INVALID:"ERR_CONNECTION_STATE_TRANSITION_INVALID",ERR_DATABASE_ADAPTER_NOT_FOUND:"ERR_DATABASE_ADAPTER_NOT_FOUND",ERR_DATABASE_DOES_NOT_SUPPORT_SUBSCRIBE:"ERR_DATABASE_DOES_NOT_SUPPORT_SUBSCRIBE",ERR_DATABASE_METHOD_NOT_IMPLEMENTED:"ERR_DATABASE_METHOD_NOT_IMPLEMENTED",ERR_DEFAULT_TYPE_MISMATCH:"ERR_DEFAULT_TYPE_MISMATCH",ERR_DOC_MISSING_VERSION:"ERR_DOC_MISSING_VERSION",ERR_DOC_ALREADY_CREATED:"ERR_DOC_ALREADY_CREATED",ERR_DOC_DOES_NOT_EXIST:"ERR_DOC_DOES_NOT_EXIST",ERR_DOC_TYPE_NOT_RECOGNIZED:"ERR_DOC_TYPE_NOT_RECOGNIZED",ERR_DOC_WAS_DELETED:"ERR_DOC_WAS_DELETED",ERR_INFLIGHT_OP_MISSING:"ERR_INFLIGHT_OP_MISSING",ERR_INGESTED_SNAPSHOT_HAS_NO_VERSION:"ERR_INGESTED_SNAPSHOT_HAS_NO_VERSION",ERR_MAX_SUBMIT_RETRIES_EXCEEDED:"ERR_MAX_SUBMIT_RETRIES_EXCEEDED",ERR_MESSAGE_BADLY_FORMED:"ERR_MESSAGE_BADLY_FORMED",ERR_MILESTONE_ARGUMENT_INVALID:"ERR_MILESTONE_ARGUMENT_INVALID",ERR_OP_ALREADY_SUBMITTED:"ERR_OP_ALREADY_SUBMITTED",ERR_OP_NOT_ALLOWED_IN_PROJECTION:"ERR_OP_NOT_ALLOWED_IN_PROJECTION",ERR_OP_SUBMIT_REJECTED:"ERR_OP_SUBMIT_REJECTED",ERR_OP_VERSION_MISMATCH_AFTER_TRANSFORM:"ERR_OP_VERSION_MISMATCH_AFTER_TRANSFORM",ERR_OP_VERSION_MISMATCH_DURING_TRANSFORM:"ERR_OP_VERSION_MISMATCH_DURING_TRANSFORM",ERR_OP_VERSION_NEWER_THAN_CURRENT_SNAPSHOT:"ERR_OP_VERSION_NEWER_THAN_CURRENT_SNAPSHOT",ERR_OT_LEGACY_JSON0_OP_CANNOT_BE_NORMALIZED:"ERR_OT_LEGACY_JSON0_OP_CANNOT_BE_NORMALIZED",ERR_OT_OP_BADLY_FORMED:"ERR_OT_OP_BADLY_FORMED",ERR_OT_OP_NOT_APPLIED:"ERR_OT_OP_NOT_APPLIED",ERR_OT_OP_NOT_PROVIDED:"ERR_OT_OP_NOT_PROVIDED",ERR_PRESENCE_TRANSFORM_FAILED:"ERR_PRESENCE_TRANSFORM_FAILED",ERR_PROTOCOL_VERSION_NOT_SUPPORTED:"ERR_PROTOCOL_VERSION_NOT_SUPPORTED",ERR_QUERY_EMITTER_LISTENER_NOT_ASSIGNED:"ERR_QUERY_EMITTER_LISTENER_NOT_ASSIGNED",ERR_SNAPSHOT_READ_SILENT_REJECTION:"ERR_SNAPSHOT_READ_SILENT_REJECTION",ERR_SNAPSHOT_READS_REJECTED:"ERR_SNAPSHOT_READS_REJECTED",ERR_SUBMIT_TRANSFORM_OPS_NOT_FOUND:"ERR_SUBMIT_TRANSFORM_OPS_NOT_FOUND",ERR_TYPE_CANNOT_BE_PROJECTED:"ERR_TYPE_CANNOT_BE_PROJECTED",ERR_TYPE_DOES_NOT_SUPPORT_PRESENCE:"ERR_TYPE_DOES_NOT_SUPPORT_PRESENCE",ERR_UNKNOWN_ERROR:"ERR_UNKNOWN_ERROR"};var hc=tr,ss={},f2=Cy;function Cy(n,t,e,o){var r=function(s,l,c,a){t(c,s,l,"left"),t(a,l,s,"right")},i=n.transformX=function(s,l){e(s),e(l);for(var c=[],a=0;a<l.length;a++){for(var u=l[a],f=[],m=0;m<s.length;){var C=[];if(r(s[m],u,f,C),m++,C.length===1)u=C[0];else if(C.length===0){for(var k=m;k<s.length;k++)o(f,s[k]);u=null;break}else{for(var w=i(s.slice(m),C),y=0;y<w[0].length;y++)o(f,w[0][y]);for(var S=0;S<w[1].length;S++)o(c,w[1][S]);u=null;break}}u!=null&&o(c,u),s=f}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"?i(s,l)[0]:i(l,s)[1]}}var m2={exports:{}},vo=m2.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||""}},Pu=function(n,t,e){return n.slice(0,t)+e+n.slice(t)},ju=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")},fc=function(n){for(var t=0;t<n.length;t++)ju(n[t])};vo.apply=function(n,t){var e;fc(t);for(var o=0;o<t.length;o++){var r=t[o];if(r.i!=null)n=Pu(n,r.p,r.i);else{if(e=n.slice(r.p,r.p+r.d.length),r.d!==e)throw new Error("Delete component '"+r.d+"' does not match deleted text '"+e+"'");n=n.slice(0,r.p)+n.slice(r.p+r.d.length)}}return n};var qn=vo._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:Pu(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:Pu(t.d,e.p-t.p,e.d),p:t.p}:n.push(t)}};vo.compose=function(n,t){fc(n),fc(t);for(var e=n.slice(),o=0;o<t.length;o++)qn(e,t[o]);return e},vo.normalize=function(n){var t=[];(n.i!=null||n.p!=null)&&(n=[n]);for(var e=0;e<n.length;e++){var o=n[e];o.p==null&&(o.p=0),qn(t,o)}return t};var Hu=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};vo.transformCursor=function(n,t,e){for(var o=e==="right",r=0;r<t.length;r++)n=Hu(n,t[r],o);return n};var by=vo._tc=function(n,t,e,o){if(ju(t),ju(e),t.i!=null)qn(n,{i:t.i,p:Hu(t.p,e,o==="right")});else if(e.i!=null){var r=t.d;t.p<e.p&&(qn(n,{d:r.slice(0,e.p-t.p),p:t.p}),r=r.slice(e.p-t.p)),r!==""&&qn(n,{d:r,p:t.p+e.i.length})}else if(t.p>=e.p+e.d.length)qn(n,{d:t.d,p:t.p-e.d.length});else if(t.p+t.d.length<=e.p)qn(n,t);else{var i={d:"",p:t.p};t.p<e.p&&(i.d=t.d.slice(0,e.p-t.p)),t.p+t.d.length>e.p+e.d.length&&(i.d+=t.d.slice(e.p+e.d.length-t.p));var s=Math.max(t.p,e.p),l=Math.min(t.p+t.d.length,e.p+e.d.length),c=t.d.slice(s-t.p,l-t.p),a=e.d.slice(s-e.p,l-e.p);if(c!==a)throw new Error("Delete ops delete different text in the same region of the document");i.d!==""&&(i.p=Hu(i.p,e),qn(n,i))}return n},ky=function(n){return n.i!=null?{d:n.i,p:n.p}:{i:n.d,p:n.p}};vo.invert=function(n){n=n.slice().reverse();for(var t=0;t<n.length;t++)n[t]=ky(n[t]);return n},f2(vo,by,fc,qn);var mc=function(n){return Object.prototype.toString.call(n)=="[object Array]"},vy=function(n){return!!n&&n.constructor===Object},on=function(n){return JSON.parse(JSON.stringify(n))},tt={name:"json0",uri:"http://sharejs.org/types/JSONv0"},Wn={};tt.registerSubtype=function(n){Wn[n.name]=n},tt.create=function(n){return n===void 0?null:on(n)},tt.invertComponent=function(n){var t={p:n.p};return n.t&&Wn[n.t]&&(t.t=n.t,t.o=Wn[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},tt.invert=function(n){for(var t=n.slice().reverse(),e=[],o=0;o<t.length;o++)e.push(tt.invertComponent(t[o]));return e},tt.checkValidOp=function(n){for(var t=0;t<n.length;t++)if(!mc(n[t].p))throw new Error("Missing path")},tt.checkList=function(n){if(!mc(n))throw new Error("Referenced element not a list")},tt.checkObj=function(n){if(!vy(n))throw new Error("Referenced element not an object (it was "+JSON.stringify(n)+")")};function ls(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 cs(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}tt.apply=function(n,t){tt.checkValidOp(t),t=on(t);for(var e={data:n},o=0;o<t.length;o++){var r=t[o];(r.si!=null||r.sd!=null)&&ls(r);for(var i=null,s=e,l="data",c=0;c<r.p.length;c++){var a=r.p[c];if(i=s,s=s[l],l=a,i==null)throw new Error("Path invalid")}if(r.t&&r.o!==void 0&&Wn[r.t])s[l]=Wn[r.t].apply(s[l],r.o);else if(r.na!==void 0){if(typeof s[l]!="number")throw new Error("Referenced element not a number");s[l]+=r.na}else if(r.li!==void 0&&r.ld!==void 0)tt.checkList(s),s[l]=r.li;else if(r.li!==void 0)tt.checkList(s),s.splice(l,0,r.li);else if(r.ld!==void 0)tt.checkList(s),s.splice(l,1);else if(r.lm!==void 0){if(tt.checkList(s),r.lm!=l){var u=s[l];s.splice(l,1),s.splice(r.lm,0,u)}}else if(r.oi!==void 0)tt.checkObj(s),s[l]=r.oi;else if(r.od!==void 0)tt.checkObj(s),delete s[l];else throw new Error("invalid / missing instruction in op")}return e.data},tt.shatter=function(n){for(var t=[],e=0;e<n.length;e++)t.push([n[e]]);return t},tt.incrementalApply=function(n,t,e){for(var o=0;o<t.length;o++){var r=[t[o]];n=tt.apply(n,r),e(r,n)}return n};var yy=tt.pathMatches=function(n,t,e){if(n.length!=t.length)return!1;for(var o=0;o<n.length;o++)if(n[o]!==t[o]&&(!e||o!==n.length-1))return!1;return!0};tt.append=function(n,t){if(t=on(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)&&(ls(t),ls(e)),yy(t.p,e.p))if(t.t&&e.t&&t.t===e.t&&Wn[t.t]){if(e.o=Wn[t.t].compose(e.o,t.o),t.si!=null||t.sd!=null){for(var o=t.p,r=0;r<e.o.length-1;r++)t.o=[e.o.pop()],t.p=o.slice(),cs(t),n.push(t);cs(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)&&(cs(t),cs(e)),n.push(t)},tt.compose=function(n,t){tt.checkValidOp(n),tt.checkValidOp(t);for(var e=on(n),o=0;o<t.length;o++)tt.append(e,t[o]);return e},tt.normalize=function(n){var t=[];n=mc(n)?n:[n];for(var e=0;e<n.length;e++){var o=n[e];o.p==null&&(o.p=[]),tt.append(t,o)}return t},tt.commonLengthForOps=function(n,t){var e=n.p.length,o=t.p.length;if((n.na!=null||n.t)&&e++,(t.na!=null||t.t)&&o++,e===0)return-1;if(o===0)return null;e--,o--;for(var r=0;r<e;r++){var i=n.p[r];if(r>=o||i!==t.p[r])return null}return e},tt.canOpAffectPath=function(n,t){return tt.commonLengthForOps({p:t},n)!=null},tt.transformComponent=function(n,t,e,o){t=on(t);var r=tt.commonLengthForOps(e,t),i=tt.commonLengthForOps(t,e),s=t.p.length,l=e.p.length;if((t.na!=null||t.t)&&s++,(e.na!=null||e.t)&&l++,i!=null&&l>s&&t.p[i]==e.p[i]){if(t.ld!==void 0){var c=on(e);c.p=c.p.slice(s),t.ld=tt.apply(on(t.ld),[c])}else if(t.od!==void 0){var c=on(e);c.p=c.p.slice(s),t.od=tt.apply(on(t.od),[c])}}if(r!=null){var a=s==l,c=e;if((t.si!=null||t.sd!=null)&&(e.si!=null||e.sd!=null)&&(ls(t),c=on(e),ls(c)),c.t&&Wn[c.t]){if(t.t&&t.t===c.t){var u=Wn[t.t].transform(t.o,c.o,o);if(t.si!=null||t.sd!=null)for(var f=t.p,m=0;m<u.length;m++)t.o=[u[m]],t.p=f.slice(),cs(t),tt.append(n,t);else(!mc(u)||u.length>0)&&(t.o=u,tt.append(n,t));return n}}else if(e.na===void 0){if(e.li!==void 0&&e.ld!==void 0){if(e.p[r]===t.p[r])if(a){if(t.ld!==void 0)if(t.li!==void 0&&o==="left")t.ld=on(e.li);else return n}else return n}else if(e.li!==void 0)t.li!==void 0&&t.ld===void 0&&a&&t.p[r]===e.p[r]?o==="right"&&t.p[r]++:e.p[r]<=t.p[r]&&t.p[r]++,t.lm!==void 0&&a&&e.p[r]<=t.lm&&t.lm++;else if(e.ld!==void 0){if(t.lm!==void 0&&a){if(e.p[r]===t.p[r])return n;var f=e.p[r],C=t.p[r],k=t.lm;(f<k||f===k&&C<k)&&t.lm--}if(e.p[r]<t.p[r])t.p[r]--;else if(e.p[r]===t.p[r]){if(l<s)return n;if(t.ld!==void 0)if(t.li!==void 0)delete t.ld;else return n}}else if(e.lm!==void 0)if(t.lm!==void 0&&s===l){var C=t.p[r],k=t.lm,w=e.p[r],y=e.lm;if(w!==y)if(C===w)if(o==="left")t.p[r]=y,C===k&&(t.lm=y);else return n;else C>w&&t.p[r]--,C>y?t.p[r]++:C===y&&w>y&&(t.p[r]++,C===k&&t.lm++),(k>w||k===w&&k>C)&&t.lm--,k>y?t.lm++:k===y&&(y>w&&k>C||y<w&&k<C?o==="right"&&t.lm++:k>C?t.lm++:k===w&&t.lm--)}else if(t.li!==void 0&&t.ld===void 0&&a){var C=e.p[r],k=e.lm;f=t.p[r],f>C&&t.p[r]--,f>k&&t.p[r]++}else{var C=e.p[r],k=e.lm;f=t.p[r],f===C?t.p[r]=k:(f>C&&t.p[r]--,(f>k||f===k&&C>k)&&t.p[r]++)}else if(e.oi!==void 0&&e.od!==void 0){if(t.p[r]===e.p[r])if(t.oi!==void 0&&a){if(o==="right")return n;t.od=e.oi}else return n}else if(e.oi!==void 0){if(t.oi!==void 0&&t.p[r]===e.p[r])if(o==="left")tt.append(n,{p:t.p,od:e.oi});else return n}else if(e.od!==void 0&&t.p[r]==e.p[r]){if(!a)return n;if(t.oi!==void 0)delete t.od;else return n}}}return tt.append(n,t),n},f2(tt,tt.transformComponent,tt.checkValidOp,tt.append);var wy=m2.exports;tt.registerSubtype(wy);var By=tt,Ey={type:By};(function(n){n.defaultType=Ey.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)})(ss);var rn={};(function(n){n.doNothing=t;function t(){}n.hasKeys=function(e){for(var o in e)return!0;return!1},n.isInteger=Number.isInteger||function(e){return typeof e=="number"&&isFinite(e)&&Math.floor(e)===e},n.isValidVersion=function(e){return e===null?!0:n.isInteger(e)&&e>=0},n.isValidTimestamp=function(e){return n.isValidVersion(e)},n.MAX_SAFE_INTEGER=9007199254740991,n.dig=function(){for(var e=arguments[0],o=1;o<arguments.length;o++){var r=arguments[o];e=e[r]||(o===arguments.length-1?void 0:{})}return e},n.digOrCreate=function(){for(var e=arguments[0],o=arguments[arguments.length-1],r=1;r<arguments.length-1;r++){var i=arguments[r];e=e[i]||(e[i]=r===arguments.length-2?o():{})}return e},n.digAndRemove=function(){for(var e=arguments[0],o=[e],r=1;r<arguments.length-1;r++){var i=arguments[r];if(!e.hasOwnProperty(i))break;e=e[i],o.push(e)}for(var r=o.length-1;r>=0;r--){var s=o[r],i=arguments[r+1],l=s[i];(r===o.length-1||!n.hasKeys(l))&&delete s[i]}},n.supportsPresence=function(e){return e&&typeof e.transformPresence=="function"},n.callEach=function(e,o){var r=!1;return e.forEach(function(i){i&&(i(o),r=!0)}),r},n.truthy=function(e){return!!e},n.nextTick=function(e){if(typeof process<"u"&&process.nextTick)return process.nextTick.apply(null,arguments);for(var o=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];setTimeout(function(){e.apply(null,o)})},n.clone=function(e){return e===void 0?void 0:JSON.parse(JSON.stringify(e))}})(rn);var g2=Array.isArray,p2=Object.keys,Iy=Object.prototype.hasOwnProperty,xy=function n(t,e){if(t===e)return!0;if(t&&e&&typeof t=="object"&&typeof e=="object"){var o=g2(t),r=g2(e),i,s,l;if(o&&r){if(s=t.length,s!=e.length)return!1;for(i=s;i--!==0;)if(!n(t[i],e[i]))return!1;return!0}if(o!=r)return!1;var c=t instanceof Date,a=e instanceof Date;if(c!=a)return!1;if(c&&a)return t.getTime()==e.getTime();var u=t instanceof RegExp,f=e instanceof RegExp;if(u!=f)return!1;if(u&&f)return t.toString()==e.toString();var m=p2(t);if(s=m.length,s!==p2(e).length)return!1;for(i=s;i--!==0;)if(!Iy.call(e,m[i]))return!1;for(i=s;i--!==0;)if(l=m[i],!n(t[l],e[l]))return!1;return!0}return t!==t&&e!==e},C2=ko,Ty=h2,Le=hc,gc=ss,sn=rn,Sy=sn.clone,Dy=xy,ye=Le.CODES,Ly=lt;function lt(n,t,e){C2.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}C2.mixin(lt),lt.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())})},lt.prototype._setType=function(n){if(typeof n=="string"&&(n=gc.map[n]),n)this.type=n;else if(n===null)this.type=n,this._setData(void 0);else{var t=new Le(ye.ERR_DOC_TYPE_NOT_RECOGNIZED,"Missing type "+n);return this.emit("error",t)}},lt.prototype._setData=function(n){this.data=n,this._dataStateVersion++},lt.prototype.ingestSnapshot=function(n,t){if(!n)return t&&t();if(typeof n.v!="number"){var e=new Le(ye.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 Le(ye.ERR_DOC_MISSING_VERSION,"Cannot ingest snapshot in doc with null version. "+this.collection+"."+this.id);return t?t(e):this.emit("error",e)}return n.v>this.version?this.fetch(t):t&&t()}if(this.version>n.v)return t&&t();this.version=n.v;var o=n.type===void 0?gc.defaultType:n.type;this._setType(o),this._setData(this.type&&this.type.deserialize?this.type.deserialize(n.data):n.data),this.emit("load"),t&&t()},lt.prototype.whenNothingPending=function(n){var t=this;sn.nextTick(function(){if(t.hasPending()){t.once("nothing pending",n);return}n()})},lt.prototype.hasPending=function(){return!!(this.inflightOp||this.pendingOps.length||this.inflightFetch.length||this.inflightSubscribe||this.pendingFetch.length||this.pendingSubscribe.length)},lt.prototype.hasWritePending=function(){return!!(this.inflightOp||this.pendingOps.length)},lt.prototype._emitNothingPending=function(){this.hasWritePending()||(this.emit("no write pending"),!this.hasPending()&&this.emit("nothing pending"))},lt.prototype._emitResponseError=function(n,t){if(n&&n.code===ye.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)},lt.prototype._handleFetch=function(n,t){var e=this.pendingFetch;this.pendingFetch=[];var o=this.inflightFetch.shift();if(o&&e.push(o),e.length&&(o=function(r){sn.callEach(e,r)}),n)return this._emitResponseError(n,o);this.ingestSnapshot(t,o),this._emitNothingPending()},lt.prototype._handleSubscribe=function(n,t){var e=this.inflightSubscribe;this.inflightSubscribe=null;var o=this.pendingFetch;this.pendingFetch=[],e.callback&&o.push(e.callback);var r;if(o.length&&(r=function(i){sn.callEach(o,i)}),n)return this._emitResponseError(n,r);this.subscribed=e.wantSubscribe,this.subscribed?this.ingestSnapshot(t,r):r&&r(),this._emitNothingPending(),this._flushSubscribe()},lt.prototype._handleOp=function(n,t){if(n)return this.inflightOp?(n.code===ye.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=pc(this.inflightOp,t);if(e)return this._hardRollback(e)}for(var o=0;o<this.pendingOps.length;o++){var e=pc(this.pendingOps[o],t);if(e)return this._hardRollback(e)}this.version++;try{this._otApply(t,!1)}catch(r){return this._hardRollback(r)}}},lt.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))},lt.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()},lt.prototype.fetch=function(n){if(this.connection.canSend){var t=this.connection.sendFetch(this);My(this.inflightFetch,t,n);return}this.pendingFetch.push(n)},lt.prototype.subscribe=function(n){var t=!0;this._queueSubscribe(t,n)},lt.prototype.unsubscribe=function(n){var t=!1;this._queueSubscribe(t,n)},lt.prototype._queueSubscribe=function(n,t){var e=this.pendingSubscribe[this.pendingSubscribe.length-1]||this.inflightSubscribe,o=e&&e.wantSubscribe===n;if(o){e.callback=Ry([e.callback,t]);return}this.pendingSubscribe.push({wantSubscribe:!!n,callback:t}),this._flushSubscribe()},lt.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;sn.nextTick(function(){n._handleSubscribe()})}}};function My(n,t,e){if(t){var o=n.pop();n.push(function(r){o&&o(r),e&&e(r)})}else n.push(e)}function Ry(n){return n=n.filter(sn.truthy),n.length?function(t){sn.callEach(n,t)}:null}lt.prototype.flush=function(){!this.connection.canSend||this.inflightOp||!this.paused&&this.pendingOps.length&&this._sendOp()};function Ay(n){delete n.op,delete n.create,delete n.del}function pc(n,t){if(n.del)return Ay(t);if(t.del)return new Le(ye.ERR_DOC_WAS_DELETED,"Document was deleted");if(t.create)return new Le(ye.ERR_DOC_ALREADY_CREATED,"Document already created");if("op"in t){if(n.create)return new Le(ye.ERR_DOC_ALREADY_CREATED,"Document already created");if(n.type.transformX){var e=n.type.transformX(n.op,t.op);n.op=e[0],t.op=e[1]}else{var o=n.type.transform(n.op,t.op,"left"),r=n.type.transform(t.op,n.op,"right");n.op=o,t.op=r}}}lt.prototype._otApply=function(n,t){if("op"in n){if(!this.type)throw new Le(ye.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===gc.defaultType&&n.op.length>1){this.applyStack||(this.applyStack=[]);for(var e=this.applyStack.length,o=0;o<n.op.length;o++){var r=n.op[o],i={op:[r]};this.emit("before op",i.op,t,n.src);for(var s=e;s<this.applyStack.length;s++){var l=pc(this.applyStack[s],i);if(l)return this._hardRollback(l)}this._setData(this.type.apply(this.data,i.op)),this.emit("op",i.op,t,n.src)}this.emit("op batch",n.op,t),this._popApplyStack(e);return}this.emit("before op",n.op,t,n.src),this._setData(this.type.apply(this.data,n.op)),this.emit("op",n.op,t,n.src),this.emit("op batch",n.op,t);return}if(n.create){this._setType(n.create.type),this.type.deserialize?this.type.createDeserialized?this._setData(this.type.createDeserialized(n.create.data)):this._setData(this.type.deserialize(this.type.create(n.create.data))):this._setData(this.type.create(n.create.data)),this.emit("create",t);return}if(n.del){var c=this.data;this._setType(null),this.emit("del",c,t);return}},lt.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 Le(ye.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>=sn.MAX_SAFE_INTEGER)return this.emit("error",new Le(ye.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)}},lt.prototype._submit=function(n,t,e){if(t||(t=!0),"op"in n){if(!this.type){var o=new Le(ye.ERR_DOC_DOES_NOT_EXIST,"Cannot submit op. Document has not been created. "+this.collection+"."+this.id);return e?e(o):this.emit("error",o)}this.type.normalize&&(n.op=this.type.normalize(n.op))}try{this._pushOp(n,t,e),this._otApply(n,t)}catch(i){return this._hardRollback(i)}var r=this;sn.nextTick(function(){r.flush()})},lt.prototype._pushOp=function(n,t,e){if(n.source=t,this.applyStack)this.applyStack.push(n);else{var o=this._tryCompose(n);if(o){o.callbacks.push(e);return}}n.type=this.type,n.callbacks=[e],this.pendingOps.push(n)},lt.prototype._popApplyStack=function(n){if(n>0){this.applyStack.length=n;return}var t=this.applyStack[0];if(this.applyStack=null,!!t){var e=this.pendingOps.indexOf(t);if(e!==-1)for(var o=this.pendingOps.splice(e),e=0;e<o.length;e++){var t=o[e],r=this._tryCompose(t);r?r.callbacks=r.callbacks.concat(t.callbacks):this.pendingOps.push(t)}}},lt.prototype._tryCompose=function(n){if(!this.preventCompose){var t=this.pendingOps[this.pendingOps.length-1];if(!(!t||t.sentAt)&&!(this.submitSource&&!Dy(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}}},lt.prototype.submitOp=function(n,t,e){typeof t=="function"&&(e=t,t=null);var o={op:n},r=t&&t.source;this._submit(o,r,e)},lt.prototype.create=function(n,t,e,o){if(typeof t=="function"?(o=t,e=null,t=null):typeof e=="function"&&(o=e,e=null),t||(t=gc.defaultType.uri),this.type){var r=new Le(ye.ERR_DOC_ALREADY_CREATED,"Document already exists");return o?o(r):this.emit("error",r)}var i={create:{type:t,data:n}},s=e&&e.source;this._submit(i,s,o)},lt.prototype.del=function(n,t){if(typeof n=="function"&&(t=n,n=null),!this.type){var e=new Le(ye.ERR_DOC_DOES_NOT_EXIST,"Document does not exist");return t?t(e):this.emit("error",e)}var o={del:!0},r=n&&n.source;this._submit(o,r,t)},lt.prototype.pause=function(){this.paused=!0},lt.prototype.resume=function(){this.paused=!1,this.flush()},lt.prototype.toSnapshot=function(){return{v:this.version,data:Sy(this.data),type:this.type.uri}},lt.prototype._opAcknowledged=function(n){if(this.inflightOp.create)this.version=n.v;else if(n.v!==this.version)return Ty.warn("Invalid version from server. Expected: "+this.version+" Received: "+n.v,n),this.fetch();this.version++,this._clearInflightOp()},lt.prototype._rollback=function(n){var t=this.inflightOp;if("op"in t&&t.type.invert){try{t.op=t.type.invert(t.op)}catch{return this._hardRollback(n)}for(var e=0;e<this.pendingOps.length;e++){var o=pc(this.pendingOps[e],t);if(o)return this._hardRollback(o)}try{this._otApply(t,!1)}catch(r){return this._hardRollback(r)}this._clearInflightOp(n);return}this._hardRollback(n)},lt.prototype._hardRollback=function(n){var t=[];this.inflightOp&&t.push(this.inflightOp),t=t.concat(this.pendingOps),this._setType(null),this.version=null,this.inflightOp=null,this.pendingOps=[];var e=this;this.fetch(function(){for(var o=!!t.length,r=0;r<t.length;r++)o=sn.callEach(t[r].callbacks,n)&&o;if(n&&!o)return e.emit("error",n)})},lt.prototype._clearInflightOp=function(n){var t=this.inflightOp;this.inflightOp=null;var e=sn.callEach(t.callbacks,n);if(this.flush(),this._emitNothingPending(),n&&!e)return this.emit("error",n)};var er={};er.ACTIONS={initLegacy:"init",handshake:"hs",queryFetch:"qf",querySubscribe:"qs",queryUnsubscribe:"qu",queryUpdate:"q",bulkFetch:"bf",bulkSubscribe:"bs",bulkUnsubscribe:"bu",fetch:"f",subscribe:"s",unsubscribe:"u",op:"op",snapshotFetch:"nf",snapshotFetchByTimestamp:"nt",pingPong:"pp",presence:"p",presenceSubscribe:"ps",presenceUnsubscribe:"pu",presenceRequest:"pr"};var b2=ko,k2=er.ACTIONS,Oy=rn,_y=we;function we(n,t,e,o,r,i,s){b2.EventEmitter.call(this),this.action=n,this.connection=t,this.id=e,this.collection=o,this.query=r,this.results=null,i&&i.results&&(this.results=i.results,delete i.results),this.extra=void 0,this.options=i,this.callback=s,this.ready=!1,this.sent=!1}b2.mixin(we),we.prototype.hasPending=function(){return!this.ready},we.prototype.send=function(){if(!!this.connection.canSend){var n={a:this.action,id:this.id,c:this.collection,q:this.query};if(this.options&&(n.o=this.options),this.results){for(var t=[],e=0;e<this.results.length;e++){var o=this.results[e];t.push([o.id,o.version])}n.r=t}this.connection.send(n),this.sent=!0}},we.prototype.destroy=function(n){this.connection.canSend&&this.action===k2.querySubscribe&&this.connection.send({a:k2.queryUnsubscribe,id:this.id}),this.connection._destroyQuery(this),n&&Oy.nextTick(n)},we.prototype._onConnectionStateChanged=function(){this.connection.canSend&&!this.sent?this.send():this.sent=!1},we.prototype._handleFetch=function(n,t,e){this.connection._destroyQuery(this),this._handleResponse(n,t,e)},we.prototype._handleSubscribe=function(n,t,e){this._handleResponse(n,t,e)},we.prototype._handleResponse=function(n,t,e){var o=this.callback;if(this.callback=null,n)return this._finishResponse(n,o);if(!t)return this._finishResponse(null,o);var r=this,i=1,s=function(u){if(u)return r._finishResponse(u,o);--i||r._finishResponse(null,o)};if(Array.isArray(t))i+=t.length,this.results=this._ingestSnapshots(t,s),this.extra=e;else for(var l in t){i++;var c=t[l],a=this.connection.get(c.c||this.collection,l);a.ingestSnapshot(c,s)}s()},we.prototype._ingestSnapshots=function(n,t){for(var e=[],o=0;o<n.length;o++){var r=n[o],i=this.connection.get(r.c||this.collection,r.d);i.ingestSnapshot(r,t),e.push(i)}return e},we.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)},we.prototype._handleError=function(n){this.emit("error",n)},we.prototype._handleDiff=function(n){for(var t=0;t<n.length;t++){var e=n[t];e.type==="insert"&&(e.values=this._ingestSnapshots(e.values))}for(var t=0;t<n.length;t++){var e=n[t];switch(e.type){case"insert":var o=e.values;Array.prototype.splice.apply(this.results,[e.index,0].concat(o)),this.emit("insert",o,e.index);break;case"remove":var i=e.howMany||1,r=this.results.splice(e.index,i);this.emit("remove",r,e.index);break;case"move":var i=e.howMany||1,s=this.results.splice(e.from,i);Array.prototype.splice.apply(this.results,[e.to,0].concat(s)),this.emit("move",s,e.from,e.to);break}}this.emit("changed",this.results)},we.prototype._handleExtra=function(n){this.extra=n,this.emit("extra",n)};var v2=ko,Ny=er.ACTIONS,$y=rn,y2=En;function En(n,t){if(v2.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={}}v2.mixin(En),En.prototype.submit=function(n,t){this.value=n,this.send(t)},En.prototype.send=function(n){var t=this._message();this._pendingMessages.push(t),this._callbacksByPresenceVersion[t.pv]=n,this._sendPending()},En.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()})},En.prototype._sendPending=function(){if(!!this.connection.canSend){var n=this;this._pendingMessages.forEach(function(t){n.connection.send(t)}),this._pendingMessages=[]}},En.prototype._ack=function(n,t){var e=this._getCallback(t);this._callbackOrEmit(n,e)},En.prototype._message=function(){return{a:Ny.presence,ch:this.presence.channel,id:this.presenceId,p:this.value,pv:this.presenceVersion++}},En.prototype._getCallback=function(n){var t=this._callbacksByPresenceVersion[n];return delete this._callbacksByPresenceVersion[n],t},En.prototype._callbackOrEmit=function(n,t){if(t)return $y.nextTick(t,n);n&&this.emit("error",n)};var Py=rn,w2=Fu;function Fu(n,t){this.presence=n,this.presenceId=t,this.connection=this.presence.connection,this.value=null,this.presenceVersion=0}Fu.prototype.receiveUpdate=function(n){n.pv<this.presenceVersion||(this.value=n.p,this.presenceVersion=n.pv,this.presence._updateRemotePresence(this))},Fu.prototype.destroy=function(n){delete this.presence._remotePresenceInstances[this.presenceId],delete this.presence.remotePresences[this.presenceId],n&&Py.nextTick(n)};var zu={exports:{}};(function(n,t){(function(e,o){o(t)})(is,function(e){function o(p,v){v=v|0;for(var E=Math.max(p.length-v,0),x=Array(E),L=0;L<E;L++)x[L]=p[v+L];return x}var r=function(p){var v=o(arguments,1);return function(){var E=o(arguments);return p.apply(null,v.concat(E))}},i=function(p){return function(){var v=o(arguments),E=v.pop();p.call(this,v,E)}};function s(p){var v=typeof p;return p!=null&&(v=="object"||v=="function")}var l=typeof setImmediate=="function"&&setImmediate,c=typeof process=="object"&&typeof process.nextTick=="function";function a(p){setTimeout(p,0)}function u(p){return function(v){var E=o(arguments,1);p(function(){v.apply(null,E)})}}var f;l?f=setImmediate:c?f=process.nextTick:f=a;var m=u(f);function C(p){return i(function(v,E){var x;try{x=p.apply(this,v)}catch(L){return E(L)}s(x)&&typeof x.then=="function"?x.then(function(L){k(E,null,L)},function(L){k(E,L.message?L:new Error(L))}):E(null,x)})}function k(p,v,E){try{p(v,E)}catch(x){m(w,x)}}function w(p){throw p}var y=typeof Symbol=="function";function S(p){return y&&p[Symbol.toStringTag]==="AsyncFunction"}function I(p){return S(p)?C(p):p}function M(p){return function(v){var E=o(arguments,1),x=i(function(L,D){var O=this;return p(v,function(_,V){I(_).apply(O,L.concat(V))},D)});return E.length?x.apply(this,E):x}}var R=typeof is=="object"&&is&&is.Object===Object&&is,$=typeof self=="object"&&self&&self.Object===Object&&self,Z=R||$||Function("return this")(),rt=Z.Symbol,st=Object.prototype,mt=st.hasOwnProperty,ut=st.toString,yt=rt?rt.toStringTag:void 0;function le(p){var v=mt.call(p,yt),E=p[yt];try{p[yt]=void 0;var x=!0}catch{}var L=ut.call(p);return x&&(v?p[yt]=E:delete p[yt]),L}var eo=Object.prototype,ee=eo.toString;function Ue(p){return ee.call(p)}var Lo="[object Null]",pr="[object Undefined]",Cr=rt?rt.toStringTag:void 0;function Mo(p){return p==null?p===void 0?pr:Lo:Cr&&Cr in Object(p)?le(p):Ue(p)}var xa="[object AsyncFunction]",jP="[object Function]",HP="[object GeneratorFunction]",FP="[object Proxy]";function zP(p){if(!s(p))return!1;var v=Mo(p);return v==jP||v==HP||v==xa||v==FP}var UP=9007199254740991;function NC(p){return typeof p=="number"&&p>-1&&p%1==0&&p<=UP}function ol(p){return p!=null&&NC(p.length)&&!zP(p)}var Df={};function ht(){}function Ro(p){return function(){if(p!==null){var v=p;p=null,v.apply(this,arguments)}}}var Lf=typeof Symbol=="function"&&Symbol.iterator,VP=function(p){return Lf&&p[Lf]&&p[Lf]()};function qP(p,v){for(var E=-1,x=Array(p);++E<p;)x[E]=v(E);return x}function Ta(p){return p!=null&&typeof p=="object"}var WP="[object Arguments]";function $C(p){return Ta(p)&&Mo(p)==WP}var PC=Object.prototype,GP=PC.hasOwnProperty,ZP=PC.propertyIsEnumerable,YP=$C(function(){return arguments}())?$C:function(p){return Ta(p)&&GP.call(p,"callee")&&!ZP.call(p,"callee")},gn=Array.isArray;function QP(){return!1}var jC=typeof e=="object"&&e&&!e.nodeType&&e,HC=jC&&!0&&n&&!n.nodeType&&n,KP=HC&&HC.exports===jC,FC=KP?Z.Buffer:void 0,JP=FC?FC.isBuffer:void 0,XP=JP||QP,tj=9007199254740991,ej=/^(?:0|[1-9]\d*)$/;function nj(p,v){var E=typeof p;return v=v==null?tj:v,!!v&&(E=="number"||E!="symbol"&&ej.test(p))&&p>-1&&p%1==0&&p<v}var oj="[object Arguments]",rj="[object Array]",ij="[object Boolean]",sj="[object Date]",lj="[object Error]",cj="[object Function]",aj="[object Map]",dj="[object Number]",uj="[object Object]",hj="[object RegExp]",fj="[object Set]",mj="[object String]",gj="[object WeakMap]",pj="[object ArrayBuffer]",Cj="[object DataView]",bj="[object Float32Array]",kj="[object Float64Array]",vj="[object Int8Array]",yj="[object Int16Array]",wj="[object Int32Array]",Bj="[object Uint8Array]",Ej="[object Uint8ClampedArray]",Ij="[object Uint16Array]",xj="[object Uint32Array]",Bt={};Bt[bj]=Bt[kj]=Bt[vj]=Bt[yj]=Bt[wj]=Bt[Bj]=Bt[Ej]=Bt[Ij]=Bt[xj]=!0,Bt[oj]=Bt[rj]=Bt[pj]=Bt[ij]=Bt[Cj]=Bt[sj]=Bt[lj]=Bt[cj]=Bt[aj]=Bt[dj]=Bt[uj]=Bt[hj]=Bt[fj]=Bt[mj]=Bt[gj]=!1;function Tj(p){return Ta(p)&&NC(p.length)&&!!Bt[Mo(p)]}function Sj(p){return function(v){return p(v)}}var zC=typeof e=="object"&&e&&!e.nodeType&&e,rl=zC&&!0&&n&&!n.nodeType&&n,Dj=rl&&rl.exports===zC,Mf=Dj&&R.process,UC=function(){try{var p=rl&&rl.require&&rl.require("util").types;return p||Mf&&Mf.binding&&Mf.binding("util")}catch{}}(),VC=UC&&UC.isTypedArray,Lj=VC?Sj(VC):Tj,Mj=Object.prototype,Rj=Mj.hasOwnProperty;function Aj(p,v){var E=gn(p),x=!E&&YP(p),L=!E&&!x&&XP(p),D=!E&&!x&&!L&&Lj(p),O=E||x||L||D,_=O?qP(p.length,String):[],V=_.length;for(var Q in p)(v||Rj.call(p,Q))&&!(O&&(Q=="length"||L&&(Q=="offset"||Q=="parent")||D&&(Q=="buffer"||Q=="byteLength"||Q=="byteOffset")||nj(Q,V)))&&_.push(Q);return _}var Oj=Object.prototype;function _j(p){var v=p&&p.constructor,E=typeof v=="function"&&v.prototype||Oj;return p===E}function Nj(p,v){return function(E){return p(v(E))}}var $j=Nj(Object.keys,Object),Pj=Object.prototype,jj=Pj.hasOwnProperty;function Hj(p){if(!_j(p))return $j(p);var v=[];for(var E in Object(p))jj.call(p,E)&&E!="constructor"&&v.push(E);return v}function Rf(p){return ol(p)?Aj(p):Hj(p)}function Fj(p){var v=-1,E=p.length;return function(){return++v<E?{value:p[v],key:v}:null}}function zj(p){var v=-1;return function(){var x=p.next();return x.done?null:(v++,{value:x.value,key:v})}}function Uj(p){var v=Rf(p),E=-1,x=v.length;return function L(){var D=v[++E];return D==="__proto__"?L():E<x?{value:p[D],key:D}:null}}function Vj(p){if(ol(p))return Fj(p);var v=VP(p);return v?zj(v):Uj(p)}function On(p){return function(){if(p===null)throw new Error("Callback was already called.");var v=p;p=null,v.apply(this,arguments)}}function Sa(p){return function(v,E,x){if(x=Ro(x||ht),p<=0||!v)return x(null);var L=Vj(v),D=!1,O=0,_=!1;function V(G,X){if(O-=1,G)D=!0,x(G);else{if(X===Df||D&&O<=0)return D=!0,x(null);_||Q()}}function Q(){for(_=!0;O<p&&!D;){var G=L();if(G===null){D=!0,O<=0&&x(null);return}O+=1,E(G.value,G.key,On(V))}_=!1}Q()}}function br(p,v,E,x){Sa(v)(p,I(E),x)}function ne(p,v){return function(E,x,L){return p(E,v,x,L)}}function qj(p,v,E){E=Ro(E||ht);var x=0,L=0,D=p.length;D===0&&E(null);function O(_,V){_?E(_):(++L===D||V===Df)&&E(null)}for(;x<D;x++)v(p[x],x,On(O))}var Wj=ne(br,1/0),Ao=function(p,v,E){var x=ol(p)?qj:Wj;x(p,I(v),E)};function ki(p){return function(v,E,x){return p(Ao,v,I(E),x)}}function qC(p,v,E,x){x=x||ht,v=v||[];var L=[],D=0,O=I(E);p(v,function(_,V,Q){var G=D++;O(_,function(X,Et){L[G]=Et,Q(X)})},function(_){x(_,L)})}var Da=ki(qC),WC=M(Da);function vi(p){return function(v,E,x,L){return p(Sa(E),v,I(x),L)}}var yi=vi(qC),Af=ne(yi,1),GC=M(Af);function La(p,v){for(var E=-1,x=p==null?0:p.length;++E<x&&v(p[E],E,p)!==!1;);return p}function Gj(p){return function(v,E,x){for(var L=-1,D=Object(v),O=x(v),_=O.length;_--;){var V=O[p?_:++L];if(E(D[V],V,D)===!1)break}return v}}var Zj=Gj();function il(p,v){return p&&Zj(p,v,Rf)}function Yj(p,v,E,x){for(var L=p.length,D=E+(x?1:-1);x?D--:++D<L;)if(v(p[D],D,p))return D;return-1}function Qj(p){return p!==p}function Kj(p,v,E){for(var x=E-1,L=p.length;++x<L;)if(p[x]===v)return x;return-1}function Ma(p,v,E){return v===v?Kj(p,v,E):Yj(p,Qj,E)}var Of=function(p,v,E){typeof v=="function"&&(E=v,v=null),E=Ro(E||ht);var x=Rf(p),L=x.length;if(!L)return E(null);v||(v=L);var D={},O=0,_=!1,V=Object.create(null),Q=[],G=[],X={};il(p,function(Dt,Lt){if(!gn(Dt)){Et(Lt,[Dt]),G.push(Lt);return}var Jt=Dt.slice(0,Dt.length-1),no=Jt.length;if(no===0){Et(Lt,Dt),G.push(Lt);return}X[Lt]=no,La(Jt,function(Ii){if(!p[Ii])throw new Error("async.auto task `"+Lt+"` has a non-existent dependency `"+Ii+"` in "+Jt.join(", "));_n(Ii,function(){no--,no===0&&Et(Lt,Dt)})})}),UH(),ce();function Et(Dt,Lt){Q.push(function(){Nn(Dt,Lt)})}function ce(){if(Q.length===0&&O===0)return E(null,D);for(;Q.length&&O<v;){var Dt=Q.shift();Dt()}}function _n(Dt,Lt){var Jt=V[Dt];Jt||(Jt=V[Dt]=[]),Jt.push(Lt)}function Ve(Dt){var Lt=V[Dt]||[];La(Lt,function(Jt){Jt()}),ce()}function Nn(Dt,Lt){if(!_){var Jt=On(function(Ii,Wf){if(O--,arguments.length>2&&(Wf=o(arguments,1)),Ii){var Gf={};il(D,function(qH,WH){Gf[WH]=qH}),Gf[Dt]=Wf,_=!0,V=Object.create(null),E(Ii,Gf)}else D[Dt]=Wf,Ve(Dt)});O++;var no=I(Lt[Lt.length-1]);Lt.length>1?no(D,Jt):no(Jt)}}function UH(){for(var Dt,Lt=0;G.length;)Dt=G.pop(),Lt++,La(VH(Dt),function(Jt){--X[Jt]===0&&G.push(Jt)});if(Lt!==L)throw new Error("async.auto cannot execute tasks due to a recursive dependency")}function VH(Dt){var Lt=[];return il(p,function(Jt,no){gn(Jt)&&Ma(Jt,Dt,0)>=0&&Lt.push(no)}),Lt}};function wi(p,v){for(var E=-1,x=p==null?0:p.length,L=Array(x);++E<x;)L[E]=v(p[E],E,p);return L}var Jj="[object Symbol]";function Xj(p){return typeof p=="symbol"||Ta(p)&&Mo(p)==Jj}var tH=1/0,ZC=rt?rt.prototype:void 0,YC=ZC?ZC.toString:void 0;function _f(p){if(typeof p=="string")return p;if(gn(p))return wi(p,_f)+"";if(Xj(p))return YC?YC.call(p):"";var v=p+"";return v=="0"&&1/p==-tH?"-0":v}function eH(p,v,E){var x=-1,L=p.length;v<0&&(v=-v>L?0:L+v),E=E>L?L:E,E<0&&(E+=L),L=v>E?0:E-v>>>0,v>>>=0;for(var D=Array(L);++x<L;)D[x]=p[x+v];return D}function nH(p,v,E){var x=p.length;return E=E===void 0?x:E,!v&&E>=x?p:eH(p,v,E)}function oH(p,v){for(var E=p.length;E--&&Ma(v,p[E],0)>-1;);return E}function rH(p,v){for(var E=-1,x=p.length;++E<x&&Ma(v,p[E],0)>-1;);return E}function iH(p){return p.split("")}var sH="\\ud800-\\udfff",lH="\\u0300-\\u036f",cH="\\ufe20-\\ufe2f",aH="\\u20d0-\\u20ff",dH=lH+cH+aH,uH="\\ufe0e\\ufe0f",hH="\\u200d",fH=RegExp("["+hH+sH+dH+uH+"]");function mH(p){return fH.test(p)}var QC="\\ud800-\\udfff",gH="\\u0300-\\u036f",pH="\\ufe20-\\ufe2f",CH="\\u20d0-\\u20ff",bH=gH+pH+CH,kH="\\ufe0e\\ufe0f",vH="["+QC+"]",Nf="["+bH+"]",$f="\\ud83c[\\udffb-\\udfff]",yH="(?:"+Nf+"|"+$f+")",KC="[^"+QC+"]",JC="(?:\\ud83c[\\udde6-\\uddff]){2}",XC="[\\ud800-\\udbff][\\udc00-\\udfff]",wH="\\u200d",t9=yH+"?",e9="["+kH+"]?",BH="(?:"+wH+"(?:"+[KC,JC,XC].join("|")+")"+e9+t9+")*",EH=e9+t9+BH,IH="(?:"+[KC+Nf+"?",Nf,JC,XC,vH].join("|")+")",xH=RegExp($f+"(?="+$f+")|"+IH+EH,"g");function TH(p){return p.match(xH)||[]}function n9(p){return mH(p)?TH(p):iH(p)}function SH(p){return p==null?"":_f(p)}var DH=/^\s+|\s+$/g;function LH(p,v,E){if(p=SH(p),p&&(E||v===void 0))return p.replace(DH,"");if(!p||!(v=_f(v)))return p;var x=n9(p),L=n9(v),D=rH(x,L),O=oH(x,L)+1;return nH(x,D,O).join("")}var MH=/^(?:async\s+)?(function)?\s*[^\(]*\(\s*([^\)]*)\)/m,RH=/,/,AH=/(=.+)?(\s*)$/,OH=/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;function _H(p){return p=p.toString().replace(OH,""),p=p.match(MH)[2].replace(" ",""),p=p?p.split(RH):[],p=p.map(function(v){return LH(v.replace(AH,""))}),p}function o9(p,v){var E={};il(p,function(x,L){var D,O=S(x),_=!O&&x.length===1||O&&x.length===0;if(gn(x))D=x.slice(0,-1),x=x[x.length-1],E[L]=D.concat(D.length>0?V:x);else if(_)E[L]=x;else{if(D=_H(x),x.length===0&&!O&&D.length===0)throw new Error("autoInject task functions require explicit parameters.");O||D.pop(),E[L]=D.concat(V)}function V(Q,G){var X=wi(D,function(Et){return Q[Et]});X.push(G),I(x).apply(null,X)}}),Of(E,v)}function pn(){this.head=this.tail=null,this.length=0}function r9(p,v){p.length=1,p.head=p.tail=v}pn.prototype.removeLink=function(p){return p.prev?p.prev.next=p.next:this.head=p.next,p.next?p.next.prev=p.prev:this.tail=p.prev,p.prev=p.next=null,this.length-=1,p},pn.prototype.empty=function(){for(;this.head;)this.shift();return this},pn.prototype.insertAfter=function(p,v){v.prev=p,v.next=p.next,p.next?p.next.prev=v:this.tail=v,p.next=v,this.length+=1},pn.prototype.insertBefore=function(p,v){v.prev=p.prev,v.next=p,p.prev?p.prev.next=v:this.head=v,p.prev=v,this.length+=1},pn.prototype.unshift=function(p){this.head?this.insertBefore(this.head,p):r9(this,p)},pn.prototype.push=function(p){this.tail?this.insertAfter(this.tail,p):r9(this,p)},pn.prototype.shift=function(){return this.head&&this.removeLink(this.head)},pn.prototype.pop=function(){return this.tail&&this.removeLink(this.tail)},pn.prototype.toArray=function(){for(var p=Array(this.length),v=this.head,E=0;E<this.length;E++)p[E]=v.data,v=v.next;return p},pn.prototype.remove=function(p){for(var v=this.head;v;){var E=v.next;p(v)&&this.removeLink(v),v=E}return this};function i9(p,v,E){if(v==null)v=1;else if(v===0)throw new Error("Concurrency must not be zero");var x=I(p),L=0,D=[],O=!1;function _(X,Et,ce){if(ce!=null&&typeof ce!="function")throw new Error("task callback must be a function");if(G.started=!0,gn(X)||(X=[X]),X.length===0&&G.idle())return m(function(){G.drain()});for(var _n=0,Ve=X.length;_n<Ve;_n++){var Nn={data:X[_n],callback:ce||ht};Et?G._tasks.unshift(Nn):G._tasks.push(Nn)}O||(O=!0,m(function(){O=!1,G.process()}))}function V(X){return function(Et){L-=1;for(var ce=0,_n=X.length;ce<_n;ce++){var Ve=X[ce],Nn=Ma(D,Ve,0);Nn===0?D.shift():Nn>0&&D.splice(Nn,1),Ve.callback.apply(Ve,arguments),Et!=null&&G.error(Et,Ve.data)}L<=G.concurrency-G.buffer&&G.unsaturated(),G.idle()&&G.drain(),G.process()}}var Q=!1,G={_tasks:new pn,concurrency:v,payload:E,saturated:ht,unsaturated:ht,buffer:v/4,empty:ht,drain:ht,error:ht,started:!1,paused:!1,push:function(X,Et){_(X,!1,Et)},kill:function(){G.drain=ht,G._tasks.empty()},unshift:function(X,Et){_(X,!0,Et)},remove:function(X){G._tasks.remove(X)},process:function(){if(!Q){for(Q=!0;!G.paused&&L<G.concurrency&&G._tasks.length;){var X=[],Et=[],ce=G._tasks.length;G.payload&&(ce=Math.min(ce,G.payload));for(var _n=0;_n<ce;_n++){var Ve=G._tasks.shift();X.push(Ve),D.push(Ve),Et.push(Ve.data)}L+=1,G._tasks.length===0&&G.empty(),L===G.concurrency&&G.saturated();var Nn=On(V(X));x(Et,Nn)}Q=!1}},length:function(){return G._tasks.length},running:function(){return L},workersList:function(){return D},idle:function(){return G._tasks.length+L===0},pause:function(){G.paused=!0},resume:function(){G.paused!==!1&&(G.paused=!1,m(G.process))}};return G}function s9(p,v){return i9(p,1,v)}var Bi=ne(br,1);function Oo(p,v,E,x){x=Ro(x||ht);var L=I(E);Bi(p,function(D,O,_){L(v,D,function(V,Q){v=Q,_(V)})},function(D){x(D,v)})}function Pf(){var p=wi(arguments,I);return function(){var v=o(arguments),E=this,x=v[v.length-1];typeof x=="function"?v.pop():x=ht,Oo(p,v,function(L,D,O){D.apply(E,L.concat(function(_){var V=o(arguments,1);O(_,V)}))},function(L,D){x.apply(E,[L].concat(D))})}}var l9=function(){return Pf.apply(null,o(arguments).reverse())},NH=Array.prototype.concat,Ra=function(p,v,E,x){x=x||ht;var L=I(E);yi(p,v,function(D,O){L(D,function(_){return _?O(_):O(null,o(arguments,1))})},function(D,O){for(var _=[],V=0;V<O.length;V++)O[V]&&(_=NH.apply(_,O[V]));return x(D,_)})},c9=ne(Ra,1/0),a9=ne(Ra,1),d9=function(){var p=o(arguments),v=[null].concat(p);return function(){var E=arguments[arguments.length-1];return E.apply(this,v)}};function sl(p){return p}function Ei(p,v){return function(E,x,L,D){D=D||ht;var O=!1,_;E(x,function(V,Q,G){L(V,function(X,Et){X?G(X):p(Et)&&!_?(O=!0,_=v(!0,V),G(null,Df)):G()})},function(V){V?D(V):D(null,O?_:v(!1))})}}function u9(p,v){return v}var Aa=ki(Ei(sl,u9)),ll=vi(Ei(sl,u9)),Oa=ne(ll,1);function h9(p){return function(v){var E=o(arguments,1);E.push(function(x){var L=o(arguments,1);typeof console=="object"&&(x?console.error&&console.error(x):console[p]&&La(L,function(D){console[p](D)}))}),I(v).apply(null,E)}}var f9=h9("dir");function m9(p,v,E){E=On(E||ht);var x=I(p),L=I(v);function D(_){if(_)return E(_);var V=o(arguments,1);V.push(O),L.apply(this,V)}function O(_,V){if(_)return E(_);if(!V)return E(null);x(D)}O(null,!0)}function jf(p,v,E){E=On(E||ht);var x=I(p),L=function(D){if(D)return E(D);var O=o(arguments,1);if(v.apply(this,O))return x(L);E.apply(null,[null].concat(O))};x(L)}function g9(p,v,E){jf(p,function(){return!v.apply(this,arguments)},E)}function p9(p,v,E){E=On(E||ht);var x=I(v),L=I(p);function D(_){if(_)return E(_);L(O)}function O(_,V){if(_)return E(_);if(!V)return E(null);x(D)}L(O)}function C9(p){return function(v,E,x){return p(v,x)}}function _a(p,v,E){Ao(p,C9(I(v)),E)}function cl(p,v,E,x){Sa(v)(p,C9(I(E)),x)}var al=ne(cl,1);function Hf(p){return S(p)?p:i(function(v,E){var x=!0;v.push(function(){var L=arguments;x?m(function(){E.apply(null,L)}):E.apply(null,L)}),p.apply(this,v),x=!1})}function Na(p){return!p}var $a=ki(Ei(Na,Na)),dl=vi(Ei(Na,Na)),Pa=ne(dl,1);function b9(p){return function(v){return v==null?void 0:v[p]}}function $H(p,v,E,x){var L=new Array(v.length);p(v,function(D,O,_){E(D,function(V,Q){L[O]=!!Q,_(V)})},function(D){if(D)return x(D);for(var O=[],_=0;_<v.length;_++)L[_]&&O.push(v[_]);x(null,O)})}function PH(p,v,E,x){var L=[];p(v,function(D,O,_){E(D,function(V,Q){V?_(V):(Q&&L.push({index:O,value:D}),_())})},function(D){D?x(D):x(null,wi(L.sort(function(O,_){return O.index-_.index}),b9("value")))})}function Ff(p,v,E,x){var L=ol(v)?$H:PH;L(p,v,I(E),x||ht)}var ja=ki(Ff),ul=vi(Ff),Ha=ne(ul,1);function k9(p,v){var E=On(v||ht),x=I(Hf(p));function L(D){if(D)return E(D);x(L)}L()}var Fa=function(p,v,E,x){x=x||ht;var L=I(E);yi(p,v,function(D,O){L(D,function(_,V){return _?O(_):O(null,{key:V,val:D})})},function(D,O){for(var _={},V=Object.prototype.hasOwnProperty,Q=0;Q<O.length;Q++)if(O[Q]){var G=O[Q].key,X=O[Q].val;V.call(_,G)?_[G].push(X):_[G]=[X]}return x(D,_)})},v9=ne(Fa,1/0),y9=ne(Fa,1),w9=h9("log");function za(p,v,E,x){x=Ro(x||ht);var L={},D=I(E);br(p,v,function(O,_,V){D(O,_,function(Q,G){if(Q)return V(Q);L[_]=G,V()})},function(O){x(O,L)})}var B9=ne(za,1/0),E9=ne(za,1);function I9(p,v){return v in p}function x9(p,v){var E=Object.create(null),x=Object.create(null);v=v||sl;var L=I(p),D=i(function(_,V){var Q=v.apply(null,_);I9(E,Q)?m(function(){V.apply(null,E[Q])}):I9(x,Q)?x[Q].push(V):(x[Q]=[V],L.apply(null,_.concat(function(){var G=o(arguments);E[Q]=G;var X=x[Q];delete x[Q];for(var Et=0,ce=X.length;Et<ce;Et++)X[Et].apply(null,G)})))});return D.memo=E,D.unmemoized=p,D}var Ua;c?Ua=process.nextTick:l?Ua=setImmediate:Ua=a;var T9=u(Ua);function zf(p,v,E){E=E||ht;var x=ol(v)?[]:{};p(v,function(L,D,O){I(L)(function(_,V){arguments.length>2&&(V=o(arguments,1)),x[D]=V,O(_)})},function(L){E(L,x)})}function S9(p,v){zf(Ao,p,v)}function D9(p,v,E){zf(Sa(v),p,E)}var Uf=function(p,v){var E=I(p);return i9(function(x,L){E(x[0],L)},v,1)},L9=function(p,v){var E=Uf(p,v);return E.push=function(x,L,D){if(D==null&&(D=ht),typeof D!="function")throw new Error("task callback must be a function");if(E.started=!0,gn(x)||(x=[x]),x.length===0)return m(function(){E.drain()});L=L||0;for(var O=E._tasks.head;O&&L>=O.priority;)O=O.next;for(var _=0,V=x.length;_<V;_++){var Q={data:x[_],priority:L,callback:D};O?E._tasks.insertBefore(O,Q):E._tasks.push(Q)}m(E.process)},delete E.unshift,E};function M9(p,v){if(v=Ro(v||ht),!gn(p))return v(new TypeError("First argument to race must be an array of functions"));if(!p.length)return v();for(var E=0,x=p.length;E<x;E++)I(p[E])(v)}function Va(p,v,E,x){var L=o(p).reverse();Oo(L,v,E,x)}function qa(p){var v=I(p);return i(function(x,L){return x.push(function(O,_){if(O)L(null,{error:O});else{var V;arguments.length<=2?V=_:V=o(arguments,1),L(null,{value:V})}}),v.apply(this,x)})}function R9(p){var v;return gn(p)?v=wi(p,qa):(v={},il(p,function(E,x){v[x]=qa.call(this,E)})),v}function A9(p,v,E,x){Ff(p,v,function(L,D){E(L,function(O,_){D(O,!_)})},x)}var O9=ki(A9),Vf=vi(A9),_9=ne(Vf,1);function N9(p){return function(){return p}}function Wa(p,v,E){var x=5,L=0,D={times:x,intervalFunc:N9(L)};function O(G,X){if(typeof X=="object")G.times=+X.times||x,G.intervalFunc=typeof X.interval=="function"?X.interval:N9(+X.interval||L),G.errorFilter=X.errorFilter;else if(typeof X=="number"||typeof X=="string")G.times=+X||x;else throw new Error("Invalid arguments for async.retry")}if(arguments.length<3&&typeof p=="function"?(E=v||ht,v=p):(O(D,p),E=E||ht),typeof v!="function")throw new Error("Invalid arguments for async.retry");var _=I(v),V=1;function Q(){_(function(G){G&&V++<D.times&&(typeof D.errorFilter!="function"||D.errorFilter(G))?setTimeout(Q,D.intervalFunc(V)):E.apply(null,arguments)})}Q()}var $9=function(p,v){v||(v=p,p=null);var E=I(v);return i(function(x,L){function D(O){E.apply(null,x.concat(O))}p?Wa(p,D,L):Wa(D,L)})};function P9(p,v){zf(Bi,p,v)}var Ga=ki(Ei(Boolean,sl)),hl=vi(Ei(Boolean,sl)),Za=ne(hl,1);function j9(p,v,E){var x=I(v);Da(p,function(D,O){x(D,function(_,V){if(_)return O(_);O(null,{value:D,criteria:V})})},function(D,O){if(D)return E(D);E(null,wi(O.sort(L),b9("value")))});function L(D,O){var _=D.criteria,V=O.criteria;return _<V?-1:_>V?1:0}}function H9(p,v,E){var x=I(p);return i(function(L,D){var O=!1,_;function V(){var Q=p.name||"anonymous",G=new Error('Callback function "'+Q+'" timed out.');G.code="ETIMEDOUT",E&&(G.info=E),O=!0,D(G)}L.push(function(){O||(D.apply(null,arguments),clearTimeout(_))}),_=setTimeout(V,v),x.apply(null,L)})}var jH=Math.ceil,HH=Math.max;function FH(p,v,E,x){for(var L=-1,D=HH(jH((v-p)/(E||1)),0),O=Array(D);D--;)O[x?D:++L]=p,p+=E;return O}function Ya(p,v,E,x){var L=I(E);yi(FH(0,p,1),v,L,x)}var F9=ne(Ya,1/0),z9=ne(Ya,1);function U9(p,v,E,x){arguments.length<=3&&(x=E,E=v,v=gn(p)?[]:{}),x=Ro(x||ht);var L=I(E);Ao(p,function(D,O,_){L(v,D,O,_)},function(D){x(D,v)})}function V9(p,v){var E=null,x;v=v||ht,al(p,function(L,D){I(L)(function(O,_){arguments.length>2?x=o(arguments,1):x=_,E=O,D(!O)})},function(){v(E,x)})}function q9(p){return function(){return(p.unmemoized||p).apply(null,arguments)}}function qf(p,v,E){E=On(E||ht);var x=I(v);if(!p())return E(null);var L=function(D){if(D)return E(D);if(p())return x(L);var O=o(arguments,1);E.apply(null,[null].concat(O))};x(L)}function W9(p,v,E){qf(function(){return!p.apply(this,arguments)},v,E)}var G9=function(p,v){if(v=Ro(v||ht),!gn(p))return v(new Error("First argument to waterfall must be an array of functions"));if(!p.length)return v();var E=0;function x(D){var O=I(p[E++]);D.push(On(L)),O.apply(null,D)}function L(D){if(D||E===p.length)return v.apply(null,arguments);x(o(arguments,1))}x([])},zH={apply:r,applyEach:WC,applyEachSeries:GC,asyncify:C,auto:Of,autoInject:o9,cargo:s9,compose:l9,concat:c9,concatLimit:Ra,concatSeries:a9,constant:d9,detect:Aa,detectLimit:ll,detectSeries:Oa,dir:f9,doDuring:m9,doUntil:g9,doWhilst:jf,during:p9,each:_a,eachLimit:cl,eachOf:Ao,eachOfLimit:br,eachOfSeries:Bi,eachSeries:al,ensureAsync:Hf,every:$a,everyLimit:dl,everySeries:Pa,filter:ja,filterLimit:ul,filterSeries:Ha,forever:k9,groupBy:v9,groupByLimit:Fa,groupBySeries:y9,log:w9,map:Da,mapLimit:yi,mapSeries:Af,mapValues:B9,mapValuesLimit:za,mapValuesSeries:E9,memoize:x9,nextTick:T9,parallel:S9,parallelLimit:D9,priorityQueue:L9,queue:Uf,race:M9,reduce:Oo,reduceRight:Va,reflect:qa,reflectAll:R9,reject:O9,rejectLimit:Vf,rejectSeries:_9,retry:Wa,retryable:$9,seq:Pf,series:P9,setImmediate:m,some:Ga,someLimit:hl,someSeries:Za,sortBy:j9,timeout:H9,times:F9,timesLimit:Ya,timesSeries:z9,transform:U9,tryEach:V9,unmemoize:q9,until:W9,waterfall:G9,whilst:qf,all:$a,allLimit:dl,allSeries:Pa,any:Ga,anyLimit:hl,anySeries:Za,find:Aa,findLimit:ll,findSeries:Oa,forEach:_a,forEachSeries:al,forEachLimit:cl,forEachOf:Ao,forEachOfSeries:Bi,forEachOfLimit:br,inject:Oo,foldl:Oo,foldr:Va,select:ja,selectLimit:ul,selectSeries:Ha,wrapSync:C};e.default=zH,e.apply=r,e.applyEach=WC,e.applyEachSeries=GC,e.asyncify=C,e.auto=Of,e.autoInject=o9,e.cargo=s9,e.compose=l9,e.concat=c9,e.concatLimit=Ra,e.concatSeries=a9,e.constant=d9,e.detect=Aa,e.detectLimit=ll,e.detectSeries=Oa,e.dir=f9,e.doDuring=m9,e.doUntil=g9,e.doWhilst=jf,e.during=p9,e.each=_a,e.eachLimit=cl,e.eachOf=Ao,e.eachOfLimit=br,e.eachOfSeries=Bi,e.eachSeries=al,e.ensureAsync=Hf,e.every=$a,e.everyLimit=dl,e.everySeries=Pa,e.filter=ja,e.filterLimit=ul,e.filterSeries=Ha,e.forever=k9,e.groupBy=v9,e.groupByLimit=Fa,e.groupBySeries=y9,e.log=w9,e.map=Da,e.mapLimit=yi,e.mapSeries=Af,e.mapValues=B9,e.mapValuesLimit=za,e.mapValuesSeries=E9,e.memoize=x9,e.nextTick=T9,e.parallel=S9,e.parallelLimit=D9,e.priorityQueue=L9,e.queue=Uf,e.race=M9,e.reduce=Oo,e.reduceRight=Va,e.reflect=qa,e.reflectAll=R9,e.reject=O9,e.rejectLimit=Vf,e.rejectSeries=_9,e.retry=Wa,e.retryable=$9,e.seq=Pf,e.series=P9,e.setImmediate=m,e.some=Ga,e.someLimit=hl,e.someSeries=Za,e.sortBy=j9,e.timeout=H9,e.times=F9,e.timesLimit=Ya,e.timesSeries=z9,e.transform=U9,e.tryEach=V9,e.unmemoize=q9,e.until=W9,e.waterfall=G9,e.whilst=qf,e.all=$a,e.allLimit=dl,e.allSeries=Pa,e.any=Ga,e.anyLimit=hl,e.anySeries=Za,e.find=Aa,e.findLimit=ll,e.findSeries=Oa,e.forEach=_a,e.forEachSeries=al,e.forEachLimit=cl,e.forEachOf=Ao,e.forEachOfSeries=Bi,e.forEachOfLimit=br,e.inject=Oo,e.foldl=Oo,e.foldr=Va,e.select=ja,e.selectLimit=ul,e.selectSeries=Ha,e.wrapSync=C,Object.defineProperty(e,"__esModule",{value:!0})})})(zu,zu.exports);var B2={exports:{}},Uu=B2.exports=function(n,t){if(t||(t=16),n===void 0&&(n=128),n<=0)return"0";for(var e=Math.log(Math.pow(2,n))/Math.log(t),o=2;e===1/0;o*=2)e=Math.log(Math.pow(2,n/o))/Math.log(t)*o;for(var r=e-Math.floor(e),i="",o=0;o<Math.floor(e);o++){var s=Math.floor(Math.random()*t).toString(t);i=s+i}if(r){var l=Math.pow(t,r),s=Math.floor(Math.random()*l).toString(t);i=s+i}var c=parseInt(i,t);return c!==1/0&&c>=Math.pow(2,n)?Uu(n,t):i};Uu.rack=function(n,t,e){var o=function(i){var s=0;do{if(s++>10)if(e)n+=e;else throw new Error("too many ID collisions, use more bits");var l=Uu(n,t)}while(Object.hasOwnProperty.call(r,l));return r[l]=i,l},r=o.hats={};return o.get=function(i){return o.hats[i]},o.set=function(i,s){return o.hats[i]=s,o},o.bits=n||128,o.base=t||16,o};var E2=ko,jy=y2,Hy=w2,Cc=rn,Vu=zu.exports,Fy=B2.exports,I2=er.ACTIONS,x2=Pt;function Pt(n,t){if(E2.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}E2.mixin(Pt),Pt.prototype.subscribe=function(n){this._sendSubscriptionAction(!0,n)},Pt.prototype.unsubscribe=function(n){this._sendSubscriptionAction(!1,n)},Pt.prototype.create=function(n){if(this._wantsDestroy)throw new Error("Presence is being destroyed");n=n||Fy();var t=this._createLocalPresence(n);return this.localPresences[n]=t,t},Pt.prototype.destroy=function(n){this._wantsDestroy=!0;var t=this,e=Object.keys(t.localPresences);this.unsubscribe(function(o){if(o)return t._callbackOrEmit(o,n);var r=Object.keys(t._remotePresenceInstances);Vu.parallel([function(i){Vu.each(e,function(s,l){t.localPresences[s].destroy(l)},i)},function(i){if(!t._wantsDestroy)return i();Vu.each(r,function(s,l){t._remotePresenceInstances[s].destroy(l)},i)}],function(i){t._wantsDestroy&&delete t.connection._presences[t.channel],t._callbackOrEmit(i,n)})})},Pt.prototype._sendSubscriptionAction=function(n,t){this.wantSubscribe=!!n;var e=this.wantSubscribe?I2.presenceSubscribe:I2.presenceUnsubscribe,o=this.connection._presenceSeq++;this._subscriptionCallbacksBySeq[o]=t,this.connection.canSend&&this.connection._sendPresenceAction(e,o,this)},Pt.prototype._handleSubscribe=function(n,t){this.wantSubscribe&&(this.subscribed=!0);var e=this._subscriptionCallback(t);this._callbackOrEmit(n,e)},Pt.prototype._handleUnsubscribe=function(n,t){this.subscribed=!1;var e=this._subscriptionCallback(t);this._callbackOrEmit(n,e)},Pt.prototype._receiveUpdate=function(n,t){var e=Cc.dig(this.localPresences,t.id);if(e)return e._ack(n,t.pv);if(n)return this.emit("error",n);var o=this,r=Cc.digOrCreate(this._remotePresenceInstances,t.id,function(){return o._createRemotePresence(t.id)});r.receiveUpdate(t)},Pt.prototype._updateRemotePresence=function(n){this.remotePresences[n.presenceId]=n.value,n.value===null&&this._removeRemotePresence(n.presenceId),this.emit("receive",n.presenceId,n.value)},Pt.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()}},Pt.prototype._removeRemotePresence=function(n){this._remotePresenceInstances[n].destroy(),delete this._remotePresenceInstances[n],delete this.remotePresences[n]},Pt.prototype._onConnectionStateChanged=function(){if(!!this.connection.canSend){this._resubscribe();for(var n in this.localPresences)this.localPresences[n]._sendPending()}},Pt.prototype._resubscribe=function(){var n=[];for(var t in this._subscriptionCallbacksBySeq){var e=this._subscriptionCallback(t);n.push(e)}if(!this.wantSubscribe)return this._callEachOrEmit(n);var o=this;this.subscribe(function(r){o._callEachOrEmit(n,r)})},Pt.prototype._subscriptionCallback=function(n){var t=this._subscriptionCallbacksBySeq[n];return delete this._subscriptionCallbacksBySeq[n],t},Pt.prototype._callbackOrEmit=function(n,t){if(t)return Cc.nextTick(t,n);n&&this.emit("error",n)},Pt.prototype._createLocalPresence=function(n){return new jy(this,n)},Pt.prototype._createRemotePresence=function(n){return new Hy(this,n)},Pt.prototype._callEachOrEmit=function(n,t){var e=Cc.callEach(n,t);!e&&t&&this.emit("error",t)};var as=y2,T2=hc,zy=rn,S2=T2.CODES,Uy=ln;function ln(n,t){as.call(this,n,t),this.collection=this.presence.collection,this.id=this.presence.id,this._doc=this.connection.get(this.collection,this.id),this._isSending=!1,this._docDataVersionByPresenceVersion={},this._opHandler=this._transformAgainstOp.bind(this),this._createOrDelHandler=this._handleCreateOrDel.bind(this),this._loadHandler=this._handleLoad.bind(this),this._destroyHandler=this.destroy.bind(this),this._registerWithDoc()}ln.prototype=Object.create(as.prototype),ln.prototype.submit=function(n,t){if(!this._doc.type){if(n===null)return this._callbackOrEmit(null,t);var e={code:S2.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,as.prototype.submit.call(this,n,t)},ln.prototype.destroy=function(n){this._doc.removeListener("op",this._opHandler),this._doc.removeListener("create",this._createOrDelHandler),this._doc.removeListener("del",this._createOrDelHandler),this._doc.removeListener("load",this._loadHandler),this._doc.removeListener("destroy",this._destroyHandler),as.prototype.destroy.call(this,n)},ln.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={})})}},ln.prototype._registerWithDoc=function(){this._doc.on("op",this._opHandler),this._doc.on("create",this._createOrDelHandler),this._doc.on("del",this._createOrDelHandler),this._doc.on("load",this._loadHandler),this._doc.on("destroy",this._destroyHandler)},ln.prototype._transformAgainstOp=function(n,t){var e=this,o=this._doc._dataStateVersion;this._pendingMessages.forEach(function(r){var i=e._docDataVersionByPresenceVersion[r.pv];if(!(i>=o))try{r.p=e._transformPresence(r.p,n,t),e._docDataVersionByPresenceVersion[r.pv]=o}catch(l){var s=e._getCallback(r.pv);e._callbackOrEmit(l,s)}});try{this.value=this._transformPresence(this.value,n,t)}catch(r){this.emit("error",r)}},ln.prototype._handleCreateOrDel=function(){this._pendingMessages.forEach(function(n){n.p=null}),this.value=null},ln.prototype._handleLoad=function(){this.value=null,this._pendingMessages=[],this._docDataVersionByPresenceVersion={}},ln.prototype._message=function(){var n=as.prototype._message.call(this);return n.c=this.collection,n.d=this.id,n.v=null,n.t=null,n},ln.prototype._transformPresence=function(n,t,e){var o=this._doc.type;if(!zy.supportsPresence(o))throw new T2(S2.ERR_TYPE_DOES_NOT_SUPPORT_PRESENCE,"Type does not support presence: "+o.name);return o.transformPresence(n,t,e)};var D2={};(function(n){var t=ss,e=hc,o=rn,r=e.CODES;n.checkOp=function(l){if(l==null||typeof l!="object")return new e(r.ERR_OT_OP_BADLY_FORMED,"Op must be an object");if(l.create!=null){if(typeof l.create!="object")return new e(r.ERR_OT_OP_BADLY_FORMED,"Create data must be an object");var c=l.create.type;if(typeof c!="string")return new e(r.ERR_OT_OP_BADLY_FORMED,"Missing create type");var a=t.map[c];if(a==null||typeof a!="object")return new e(r.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type")}else if(l.del!=null){if(l.del!==!0)return new e(r.ERR_OT_OP_BADLY_FORMED,"del value must be true")}else if(!("op"in l))return new e(r.ERR_OT_OP_BADLY_FORMED,"Missing op, create, or del");if(l.src!=null&&typeof l.src!="string")return new e(r.ERR_OT_OP_BADLY_FORMED,"src must be a string");if(l.seq!=null&&typeof l.seq!="number")return new e(r.ERR_OT_OP_BADLY_FORMED,"seq must be a number");if(l.src==null&&l.seq!=null||l.src!=null&&l.seq==null)return new e(r.ERR_OT_OP_BADLY_FORMED,"Both src and seq must be set together");if(l.m!=null&&typeof l.m!="object")return new e(r.ERR_OT_OP_BADLY_FORMED,"op.m must be an object or null")},n.normalizeType=function(l){return t.map[l]&&t.map[l].uri},n.apply=function(l,c){if(typeof l!="object")return new e(r.ERR_APPLY_SNAPSHOT_NOT_PROVIDED,"Missing snapshot");if(l.v!=null&&c.v!=null&&l.v!==c.v)return new e(r.ERR_APPLY_OP_VERSION_DOES_NOT_MATCH_SNAPSHOT,"Version mismatch");if(c.create){if(l.type)return new e(r.ERR_DOC_ALREADY_CREATED,"Document already exists");var a=c.create,u=t.map[a.type];if(!u)return new e(r.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type");try{l.data=u.create(a.data),l.type=u.uri,l.v++}catch(m){return m}}else if(c.del)l.data=void 0,l.type=null,l.v++;else if("op"in c){var f=i(l,c.op);if(f)return f;l.v++}else l.v++};function i(l,c){if(!l.type)return new e(r.ERR_DOC_DOES_NOT_EXIST,"Document does not exist");if(c===void 0)return new e(r.ERR_OT_OP_NOT_PROVIDED,"Missing op");var a=t.map[l.type];if(!a)return new e(r.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type");try{l.data=a.apply(l.data,c)}catch(u){return new e(r.ERR_OT_OP_NOT_APPLIED,u.message)}}n.transform=function(l,c,a){if(c.v!=null&&c.v!==a.v)return new e(r.ERR_OP_VERSION_MISMATCH_DURING_TRANSFORM,"Version mismatch");if(a.del){if(c.create||"op"in c)return new e(r.ERR_DOC_WAS_DELETED,"Document was deleted")}else{if(a.create&&("op"in c||c.create||c.del)||"op"in a&&c.create)return new e(r.ERR_DOC_ALREADY_CREATED,"Document was created remotely");if("op"in a&&"op"in c){if(!l)return new e(r.ERR_DOC_DOES_NOT_EXIST,"Document does not exist");if(typeof l=="string"&&(l=t.map[l],!l))return new e(r.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type");try{c.op=l.transform(c.op,a.op,"left")}catch(u){return u}}}c.v!=null&&c.v++},n.applyOps=function(l,c,a){a=a||{};for(var u=0;u<c.length;u++){var f=c[u];if(a._normalizeLegacyJson0Ops)try{s(l,f)}catch{return new e(r.ERR_OT_LEGACY_JSON0_OP_CANNOT_BE_NORMALIZED,"Cannot normalize legacy json0 op")}l.v=f.v;var m=n.apply(l,f);if(m)return m}},n.transformPresence=function(l,c,a){var u=this.checkOp(c);if(u)return u;var f=l.t;if(typeof f=="string"&&(f=t.map[f]),!f)return{code:r.ERR_DOC_TYPE_NOT_RECOGNIZED,message:"Unknown type"};if(!o.supportsPresence(f))return{code:r.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:f.transformPresence(l.p,c.op,a)}catch(m){return{code:r.ERR_PRESENCE_TRANSFORM_FAILED,message:m.message||m}}l.v++};function s(l,c){if(l.type===t.defaultType.uri){var a=c.op;if(!!a){var u=l.data;a.length>1&&(u=o.clone(u));for(var f=0;f<a.length;f++){var m=a[f];typeof m.lm=="string"&&(m.lm=+m.lm);for(var C=m.p,k=u,w=0;w<C.length;w++){var y=C[w];Object.prototype.toString.call(k)=="[object Array]"?C[w]=+y:k.constructor===Object&&(C[w]=y.toString()),k=k[y]}f<a.length-1&&(u=t.defaultType.apply(u,[m]))}}}}})(D2);var ds=w2,Vy=D2,qy=Pe;function Pe(n,t){ds.call(this,n,t),this.collection=this.presence.collection,this.id=this.presence.id,this.src=null,this.presenceVersion=null,this._doc=this.connection.get(this.collection,this.id),this._pending=null,this._opCache=null,this._pendingSetPending=!1,this._opHandler=this._handleOp.bind(this),this._createDelHandler=this._handleCreateDel.bind(this),this._loadHandler=this._handleLoad.bind(this),this._registerWithDoc()}Pe.prototype=Object.create(ds.prototype),Pe.prototype.receiveUpdate=function(n){this._pending&&n.pv<this._pending.pv||(this.src=n.src,this._pending=n,this._setPendingPresence())},Pe.prototype.destroy=function(n){this._doc.removeListener("op",this._opHandler),this._doc.removeListener("create",this._createDelHandler),this._doc.removeListener("del",this._createDelHandler),this._doc.removeListener("load",this._loadHandler),ds.prototype.destroy.call(this,n)},Pe.prototype._registerWithDoc=function(){this._doc.on("op",this._opHandler),this._doc.on("create",this._createDelHandler),this._doc.on("del",this._createDelHandler),this._doc.on("load",this._loadHandler)},Pe.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))}})}},Pe.prototype._handleOp=function(n,t,e){var o=e===this.src;this._transformAgainstOp(n,o),this._cacheOp(n,o),this._setPendingPresence()},ds.prototype._handleCreateDel=function(){this._cacheOp(null),this._setPendingPresence()},ds.prototype._handleLoad=function(){this.value=null,this._pending=null,this._opCache=null,this.presence._updateRemotePresence(this)},Pe.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)}},Pe.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++):Vy.transformPresence(this._pending,t,e)}var o=this._pending.v>=this._doc.version;return o&&this._stopCachingOps(),o},Pe.prototype._startCachingOps=function(){this._opCache=[]},Pe.prototype._stopCachingOps=function(){this._opCache=null},Pe.prototype._cacheOp=function(n,t){this._opCache&&(n=n?{op:n}:null,this._opCache[this._doc.version-1]={op:n,isOwnOp:t})};var L2=x2,Wy=Uy,Gy=qy;function $r(n,t,e){var o=$r.channel(t,e);L2.call(this,n,o),this.collection=t,this.id=e}var Zy=$r;$r.prototype=Object.create(L2.prototype),$r.channel=function(n,t){return n+"."+t},$r.prototype._createLocalPresence=function(n){return new Wy(this,n)},$r.prototype._createRemotePresence=function(n){return new Gy(this,n)};var Yy=Qy;function Qy(n,t,e,o,r){this.id=n,this.v=t,this.type=e,this.data=o,this.m=r}var Ky=Yy,M2=ko,R2=us;function us(n,t,e,o,r){if(M2.EventEmitter.call(this),typeof r!="function")throw new Error("Callback is required for SnapshotRequest");this.requestId=t,this.connection=n,this.id=o,this.collection=e,this.callback=r,this.sent=!1}M2.mixin(us),us.prototype.send=function(){!this.connection.canSend||(this.connection.send(this._message()),this.sent=!0)},us.prototype._onConnectionStateChanged=function(){this.connection.canSend?this.sent||this.send():this.sent=!1},us.prototype._handleResponse=function(n,t){if(this.emit("ready"),n)return this.callback(n);var e=t.meta?t.meta:null,o=new Ky(this.id,t.v,t.type,t.data,e);this.callback(null,o)};var A2=R2,Jy=rn,Xy=er.ACTIONS,tw=qu;function qu(n,t,e,o,r,i){if(A2.call(this,n,t,e,o,i),!Jy.isValidVersion(r))throw new Error("Snapshot version must be a positive integer or null");this.version=r}qu.prototype=Object.create(A2.prototype),qu.prototype._message=function(){return{a:Xy.snapshotFetch,id:this.requestId,c:this.collection,d:this.id,v:this.version}};var O2=R2,ew=rn,nw=er.ACTIONS,ow=Wu;function Wu(n,t,e,o,r,i){if(O2.call(this,n,t,e,o,i),!ew.isValidTimestamp(r))throw new Error("Snapshot timestamp must be a positive integer or null");this.timestamp=r}Wu.prototype=Object.create(O2.prototype),Wu.prototype._message=function(){return{a:nw.snapshotFetchByTimestamp,id:this.requestId,c:this.collection,d:this.id,ts:this.timestamp}};var rw=Ly,iw=_y,sw=x2,_2=Zy,lw=tw,cw=ow,N2=ko,Pr=hc,Ct=er.ACTIONS,$2=ss,cn=rn,hs=h2,fs=Pr.CODES;function P2(n){return n.readyState===0||n.readyState===1?"connecting":"disconnected"}var aw=K;function K(n){N2.EventEmitter.call(this),this.collections={},this.nextQueryId=1,this.nextSnapshotRequestId=1,this.queries={},this._presences={},this._snapshotRequests={},this.seq=1,this._presenceSeq=1,this.id=null,this.agent=null,this.debug=!1,this.state=P2(n),this.bindToSocket(n)}N2.mixin(K),K.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=P2(n);this._setState(t),this.canSend=!1;var e=this;n.onmessage=function(o){try{var r=typeof o.data=="string"?JSON.parse(o.data):o.data}catch{hs.warn("Failed to parse message",o);return}e.debug&&hs.info("RECV",JSON.stringify(r));var i={data:r};if(e.emit("receive",i),!!i.data)try{e.handleMessage(i.data)}catch(s){cn.nextTick(function(){e.emit("error",s)})}},n.readyState===1&&e._initializeHandshake(),n.onopen=function(){e._setState("connecting"),e._initializeHandshake()},n.onerror=function(o){e.emit("connection error",o)},n.onclose=function(o){o==="closed"||o==="Closed"?e._setState("closed",o):o==="stopped"||o==="Stopped by server"?e._setState("stopped",o):e._setState("disconnected",o)}},K.prototype.handleMessage=function(n){var t=null;switch(n.error&&(t=j2(n.error,n),delete n.error),n.a){case Ct.initLegacy:return this._handleLegacyInit(n);case Ct.handshake:return this._handleHandshake(t,n);case Ct.queryFetch:var e=this.queries[n.id];e&&e._handleFetch(t,n.data,n.extra);return;case Ct.querySubscribe:var e=this.queries[n.id];e&&e._handleSubscribe(t,n.data,n.extra);return;case Ct.queryUnsubscribe:return;case Ct.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 Ct.bulkFetch:return this._handleBulkMessage(t,n,"_handleFetch");case Ct.bulkSubscribe:case Ct.bulkUnsubscribe:return this._handleBulkMessage(t,n,"_handleSubscribe");case Ct.snapshotFetch:case Ct.snapshotFetchByTimestamp:return this._handleSnapshotFetch(t,n);case Ct.fetch:var o=this.getExisting(n.c,n.d);o&&o._handleFetch(t,n.data);return;case Ct.subscribe:case Ct.unsubscribe:var o=this.getExisting(n.c,n.d);o&&o._handleSubscribe(t,n.data);return;case Ct.op:var o=this.getExisting(n.c,n.d);o&&o._handleOp(t,n);return;case Ct.presence:return this._handlePresence(t,n);case Ct.presenceSubscribe:return this._handlePresenceSubscribe(t,n);case Ct.presenceUnsubscribe:return this._handlePresenceUnsubscribe(t,n);case Ct.presenceRequest:return this._handlePresenceRequest(t,n);case Ct.pingPong:return this._handlePingPong(t);default:hs.warn("Ignoring unrecognized message",n)}};function j2(n,t){var e=new Error(n.message);return e.code=n.code,t&&(e.data=t),e}K.prototype._handleBulkMessage=function(n,t,e){if(t.data)for(var o in t.data){var r=t.data[o],i=this.getExisting(t.c,o);i&&(n?i[e](n):r.error?i[e](j2(r.error)):i[e](null,r))}else if(Array.isArray(t.b))for(var s=0;s<t.b.length;s++){var o=t.b[s],i=this.getExisting(t.c,o);i&&i[e](n)}else if(t.b)for(var o in t.b){var i=this.getExisting(t.c,o);i&&i[e](n)}else hs.error("Invalid bulk message",t)},K.prototype._reset=function(){this.agent=null},K.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 Pr(fs.ERR_CONNECTION_STATE_TRANSITION_INVALID,"Cannot transition directly from "+this.state+" to "+n);return this.emit("error",e)}this.state=n,this.canSend=n==="connected",(n==="disconnected"||n==="stopped"||n==="closed")&&this._reset(),this.startBulk();for(var o in this.queries){var r=this.queries[o];r._onConnectionStateChanged()}for(var i in this.collections){var s=this.collections[i];for(var o in s)s[o]._onConnectionStateChanged()}for(var l in this._presences)this._presences[l]._onConnectionStateChanged();for(var o in this._snapshotRequests){var c=this._snapshotRequests[o];c._onConnectionStateChanged()}this.endBulk(),this.emit(n,t),this.emit("state",n,t)}},K.prototype.startBulk=function(){this.bulk||(this.bulk={})},K.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},K.prototype._sendBulk=function(n,t,e){if(!!e){var o=[],r={},i=0,s;for(var l in e){var c=e[l];c==null?o.push(l):(r[l]=c,s=l,i++)}if(o.length===1){var l=o[0];this.send({a:n,c:t,d:l})}else o.length&&this.send({a:"b"+n,c:t,b:o});if(i===1){var a=r[s];this.send({a:n,c:t,d:s,v:a})}else i&&this.send({a:"b"+n,c:t,b:r})}},K.prototype._sendActions=function(n,t,e){if(this._addDoc(t),this.bulk){var o=this.bulk[t.collection]||(this.bulk[t.collection]={}),r=o[n]||(o[n]={}),i=r.hasOwnProperty(t.id);return r[t.id]=e,i}else{var s={a:n,c:t.collection,d:t.id,v:e};this.send(s)}},K.prototype.sendFetch=function(n){return this._sendActions(Ct.fetch,n,n.version)},K.prototype.sendSubscribe=function(n){return this._sendActions(Ct.subscribe,n,n.version)},K.prototype.sendUnsubscribe=function(n){return this._sendActions(Ct.unsubscribe,n)},K.prototype.sendOp=function(n,t){this._addDoc(n);var e={a:Ct.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)},K.prototype.send=function(n){this.debug&&hs.info("SEND",JSON.stringify(n)),this.emit("send",n),this.socket.send(JSON.stringify(n))},K.prototype.ping=function(){if(!this.canSend)throw new Pr(fs.ERR_CANNOT_PING_OFFLINE,"Socket must be CONNECTED to ping");var n={a:Ct.pingPong};this.send(n)},K.prototype.close=function(){this.socket.close()},K.prototype.getExisting=function(n,t){if(this.collections[n])return this.collections[n][t]},K.prototype.get=function(n,t){var e=this.collections[n]||(this.collections[n]={}),o=e[t];return o||(o=e[t]=new rw(this,n,t),this.emit("doc",o)),o._wantsDestroy=!1,o},K.prototype._destroyDoc=function(n){!n._wantsDestroy||(cn.digAndRemove(this.collections,n.collection,n.id),n.emit("destroy"))},K.prototype._addDoc=function(n){var t=this.collections[n.collection];t||(t=this.collections[n.collection]={}),t[n.id]!==n&&(t[n.id]=n)},K.prototype._createQuery=function(n,t,e,o,r){var i=this.nextQueryId++,s=new iw(n,this,i,t,e,o,r);return this.queries[i]=s,s.send(),s},K.prototype._destroyQuery=function(n){delete this.queries[n.id]},K.prototype.createFetchQuery=function(n,t,e,o){return this._createQuery(Ct.queryFetch,n,t,e,o)},K.prototype.createSubscribeQuery=function(n,t,e,o){return this._createQuery(Ct.querySubscribe,n,t,e,o)},K.prototype.hasPending=function(){return!!(this._firstDoc(bc)||this._firstQuery(bc)||this._firstSnapshotRequest())};function bc(n){return n.hasPending()}K.prototype.hasWritePending=function(){return!!this._firstDoc(dw)};function dw(n){return n.hasWritePending()}K.prototype.whenNothingPending=function(n){var t=this._firstDoc(bc);if(t){t.once("nothing pending",this._nothingPendingRetry(n));return}var e=this._firstQuery(bc);if(e){e.once("ready",this._nothingPendingRetry(n));return}var o=this._firstSnapshotRequest();if(o){o.once("ready",this._nothingPendingRetry(n));return}cn.nextTick(n)},K.prototype._nothingPendingRetry=function(n){var t=this;return function(){cn.nextTick(function(){t.whenNothingPending(n)})}},K.prototype._firstDoc=function(n){for(var t in this.collections){var e=this.collections[t];for(var o in e){var r=e[o];if(n(r))return r}}},K.prototype._firstQuery=function(n){for(var t in this.queries){var e=this.queries[t];if(n(e))return e}},K.prototype._firstSnapshotRequest=function(){for(var n in this._snapshotRequests)return this._snapshotRequests[n]},K.prototype.fetchSnapshot=function(n,t,e,o){typeof e=="function"&&(o=e,e=null);var r=this.nextSnapshotRequestId++,i=new lw(this,r,n,t,e,o);this._snapshotRequests[i.requestId]=i,i.send()},K.prototype.fetchSnapshotByTimestamp=function(n,t,e,o){typeof e=="function"&&(o=e,e=null);var r=this.nextSnapshotRequestId++,i=new cw(this,r,n,t,e,o);this._snapshotRequests[i.requestId]=i,i.send()},K.prototype._handleSnapshotFetch=function(n,t){var e=this._snapshotRequests[t.id];!e||(delete this._snapshotRequests[t.id],e._handleResponse(n,t))},K.prototype._handleLegacyInit=function(n){if(n.protocolMinor)return this._initializeHandshake();this._initialize(n)},K.prototype._initializeHandshake=function(){this.send({a:Ct.handshake,id:this.id})},K.prototype._handleHandshake=function(n,t){if(n)return this.emit("error",n);this._initialize(t)},K.prototype._handlePingPong=function(n){if(n)return this.emit("error",n);this.emit("pong")},K.prototype._initialize=function(n){if(this.state==="connecting"){if(n.protocol!==1)return this.emit("error",new Pr(fs.ERR_PROTOCOL_VERSION_NOT_SUPPORTED,"Unsupported protocol version: "+n.protocol));if($2.map[n.type]!==$2.defaultType)return this.emit("error",new Pr(fs.ERR_DEFAULT_TYPE_MISMATCH,n.type+" does not match the server default type"));if(typeof n.id!="string")return this.emit("error",new Pr(fs.ERR_CLIENT_ID_BADLY_FORMED,"Client id must be a string"));this.id=n.id,this._setState("connected")}},K.prototype.getPresence=function(n){var t=this,e=cn.digOrCreate(this._presences,n,function(){return new sw(t,n)});return e._wantsDestroy=!1,e},K.prototype.getDocPresence=function(n,t){var e=_2.channel(n,t),o=this,r=cn.digOrCreate(this._presences,e,function(){return new _2(o,n,t)});return r._wantsDestroy=!1,r},K.prototype._sendPresenceAction=function(n,t,e){this._addPresence(e);var o={a:n,ch:e.channel,seq:t};return this.send(o),o.seq},K.prototype._addPresence=function(n){cn.digOrCreate(this._presences,n.channel,function(){return n})},K.prototype._handlePresenceSubscribe=function(n,t){var e=cn.dig(this._presences,t.ch);e&&e._handleSubscribe(n,t.seq)},K.prototype._handlePresenceUnsubscribe=function(n,t){var e=cn.dig(this._presences,t.ch);e&&e._handleUnsubscribe(n,t.seq)},K.prototype._handlePresence=function(n,t){var e=cn.dig(this._presences,t.ch);e&&e._receiveUpdate(n,t)},K.prototype._handlePresenceRequest=function(n,t){var e=cn.dig(this._presences,t.ch);e&&e._broadcastAllLocalPresence(n,t)};var H2=aw,uw=ss;const kc={err:1001,msg:"user auth error",name:"AuthError"},hw={err:1002,msg:"you don't have required permission",name:"PermissionError"},Gu={err:1003,msg:"Too many user connected",name:"MaxUserError"},ms={err:1004,msg:"document server changed, reload it",name:"RequestReloadError"},fw={err:1005,msg:"app id must be at least 2 chars, doc id must be at least 5 chars",name:"DocIdError"},mw={err:1028,msg:"upload file ext not allowed",name:"FileExtError"},gs="x-live-editor-token",vc="x-live-editor-base-url",fe=B("auth-connection");function gw(n){try{n()}catch(t){fe.error(t)}}class pw{constructor(t,e){h(this,"connection");h(this,"ws");h(this,"retryCount");h(this,"events",new Zf.EventEmitter);h(this,"token",null);h(this,"resourceToken",null);this.url=t,this.reauthFunc=e,this.retryCount=0}getBaseURL(){const t=new URL(this.url);return`${t.protocol==="wss:"?"https:":"http:"}//${t.host}${t.pathname}`}getBase64BaseURL(){return Fo(this.getBaseURL())}async auth(t){d(fe,t.token,"no auth token");const e=`${this.getBaseURL()}/auth`,o=await window.fetch(e,{method:"GET",headers:{[gs]:t.token,[vc]:this.getBase64BaseURL()},credentials:"include"});if(o.status!==200)throw new Error("http auth error");return this.token=t.token,await o.json()}async logout(){if(!this.token)return;const t=`${this.getBaseURL()}/logout`;await window.fetch(t,{method:"GET",headers:{[vc]:Fo(this.getBaseURL())}})}async init(t){const e=await this.auth(t);this.resourceToken=e.read,this.ws=new y7.default(this.url,void 0,{maxReconnectionDelay:2500,minReconnectionDelay:1e3}),this.connection=Object.create(H2.prototype),d(fe,this.connection,"no this.connection"),this.ws,this.connection._initializeHandshake=function(){this.send({a:"hs",id:this.id,auth:t})};const o=this.connection.handleMessage.bind(this.connection);this.connection.handleMessage=r=>{var s;const i=r;if(this.connection&&(this.connection.lastReceiveTime=Date.now()),"err"in i||i.a==="pong")this.handleMessage(i);else{Object.prototype.hasOwnProperty.call(i,"a")&&i.a!=="init"&&i.a!=="hs"&&(this.retryCount=0);try{o(i)}catch(l){if((l==null?void 0:l.type)==="writeConflict"){this.emitWriteConflictError(l,i);return}if((s=l==null?void 0:l.message)!=null&&s.startsWith("Cannot invert subtype")){this.emitWriteConflictError(l,i);return}throw l}}},H2.apply(this.connection,[this.ws])}async handleAuthError(){if(this.reauthFunc&&this.retryCount<5){this.retryCount+=1,fe.info(`retrying re-auth attempt no. ${this.retryCount}`);try{if(this.connection){const t=await this.reauthFunc();await this.auth(t),this.connection._initializeHandshake=function(){this.send({a:"hs",id:this.id,auth:t})}}}catch(t){fe.error(t),setTimeout(()=>this.handleAuthError(),0)}}else fe.error("auth error, cannot retry anymore"),this.emitAuthError(),this.end(!1)}emitAuthError(){const t=new Error(kc.msg);t.code=kc.err,this.events.emit("error",t)}emitRequestReloadError(){const t=new Error(ms.msg);t.code=ms.err,this.events.emit("requestReloadError",t)}emitWriteConflictError(t,e){t.orgMsg=e,this.events.emit("writeConflictError",t)}emitMaxUsersError(){this.events.emit("maxUsersError"),this.end(!1)}handleMessage(t){const e=t;if(e.a==="pong")return;const o=e.err;if(o===kc.err)fe.warn("auth error"),this.handleAuthError();else if(o===Gu.err)fe.warn(Gu.msg),this.emitMaxUsersError();else if(o===ms.err){fe.warn(ms.msg);try{this.emitRequestReloadError()}catch(r){fe.error(`error occurred while process reload error: ${JSON.stringify(r)}`)}finally{this.end(!1)}}else fe.error(`unknown message received: ${JSON.stringify(e)}`),this.emitAuthError()}get(t,e){return d(fe,this.connection,"no this.connection"),this.connection.get(t,e)}addEventListener(t,e){t==="error"?this.events.addListener(t,e):(d(fe,this.ws,"no this.ws"),this.ws.addEventListener(t,e))}onWriteConflictError(t){this.events.addListener("writeConflictError",t)}onMaxUsersError(t){d(fe,this.events.listenerCount("maxUsersError")===0,"too many maxUserError listener"),this.events.addListener("maxUsersError",t)}onRequestReloadError(t){d(fe,this.events.listenerCount("requestReloadError")===0,"to many requestReloadError listener"),this.events.addListener("requestReloadError",t)}end(t){var e;this.reauthFunc=void 0,this.events.removeAllListeners(),gw(()=>{var o;return(o=this.connection)==null?void 0:o.close()}),this.connection=void 0,(e=this.ws)==null||e.close(),this.ws=void 0,t&&this.logout()}}B("utils/file");function Cw(){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}Cw();async function bw(n){const e=n.size,o=Math.floor((e+102400-1)/102400),r=new w7.Hash;for(let s=0;s<o;s++){const l=s*102400;let c=l+102400;c>e&&(c=e);const u=await n.slice(l,c,n.type).arrayBuffer();r.update(new Uint8Array(u))}const i=r.digest();return Fo(i)}const In=B("sharedb-doc/client");class kw{constructor(t,e,o){h(this,"connection");h(this,"auth");h(this,"doc",null);h(this,"reauthFunc");h(this,"clientId",N());h(this,"getDoc",async()=>{const t=o=>new Promise((r,i)=>{o.fetch(s=>{s?i(s):r()})});d(In,!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),In.debug(e),e});this.auth=t;const r=`${e}/${this.auth.appId}/${this.auth.docId}`;uw.register(gl.type),this.connection=new pw(r,o),this.reauthFunc=o}editorServer(){const t=this.apiServer(),e=`/${this.auth.appId}/${this.auth.docId}`;return d(In,t.endsWith(e),`invalid api server: ${t}, ${e}`),t.substr(0,t.length-e.length)}close(t){this.connection.end(t),this.doc=null}on(t,e){this.connection.addEventListener(t,o=>{(t==="error"||this.doc)&&e(o)})}onWriteConflictError(t){this.connection.onWriteConflictError(t)}onMaxUsersError(t){this.connection.onMaxUsersError(t)}onRequestReloadError(t){this.connection.onRequestReloadError(t)}async authOnly(){await this.connection.auth(this.auth)}getResourceToken(){return this.connection.resourceToken}hasDocContainer(){return!!this.doc}apiServer(){const t=this.connection.url;if(t.startsWith("ws://"))return`http://${t.substring(5)}`;if(t.startsWith("wss://"))return`https://${t.substring(6)}`;throw new Error(`invalid server url: ${t}`)}async getFileUrlByHash(t,e,o,r,i){try{const s=`${t}/${e}`,l=await this.request(s,{method:"post",headers:{...i},data:{name:o,size:r}});return l.data&&Array.isArray(l.data)&&l.data.length===1?l.data[0]:""}catch{return""}}async getFileUrlsByHashes(t){const o=`${this.apiServer()}/resources`;let r=[];t.forEach(l=>{const c=l.split("|");r.push(...c)}),r=Array.from(new Set(r));const i=r.map(l=>this.getFileUrlByHash(o,l,"",0,{[gs]:this.connection.token}));return await Promise.all(i)}async uploadFile(t,e,o,r,i){let s=e.size;if(s===0)throw new Error("file is empty");s+=500;const l=C=>{In.info(`on progress: ${C.loaded}`);let k=C.loaded*100/s;k>100&&(k=100),r(k)},c=await bw(e),a=await this.getFileUrlByHash(t,c,e.name,e.size,o);if(a)return r(-1),a;let u=t;i!=null&&i.thumbnail&&(u+="/thumbnail");const f=new FormData;f.append("file-size",`${e.size}`),f.append("file-hash",c),f.append("file",e,e.name);const m=await this.request(u,{method:"post",data:f,withCredentials:!0,headers:{...o},onUploadProgress:l});return In.info(m),r(100),Array.isArray(m.data)?m.data[0]:m.data}async uploadResource(t,e=()=>{},o){const i=`${this.apiServer()}/resources`;d(In,this.connection.token,"no connection token");const s=await this.uploadFile(i,t,{[gs]:this.connection.token},e,o);return d(In,s,"no result"),s}async request(t,e){var i,s;let o=this.connection.token,r;for(let l=0;l<2;l++){const c=e||{};c.url=t,c.headers||(c.headers={}),d(In,o,"no token"),c.headers={...c.headers,[gs]:o,[vc]:this.connection.getBase64BaseURL()};try{return await k7.default(t,c)}catch(a){if(r=a,((i=a==null?void 0:a.response)==null?void 0:i.status)===403&&this.reauthFunc){const u=await this.reauthFunc();if(await this.connection.auth(u),!u.token)throw a;o=u.token;continue}throw(s=a.response)!=null&&s.data&&(a.responseData=a.response.data),a}}throw d(In,r,"no error"),r}async getVersions(){const e=`${this.apiServer()}/versions`,o=await this.request(e),r=o.data.versions,i=o.data.latest;return i&&r.findIndex(s=>s.version===i)===-1&&r.unshift({version:-1,tag:"",published:!1}),r}async getVersion(t){const o=`${this.apiServer()}/versions/${t}`,r=await this.request(o);return JSON.parse(r.data.data)}async getLatestVersion(){const e=`${this.apiServer()}/versions/latest`,o=await this.request(e);return JSON.parse(o.data.data)}async getVersionOps(t,e){let r=`${this.apiServer()}/versions/before/${t}?withOp=true`;e!==void 0&&e!==0&&(r+=`&from=${e}`);const i=await this.request(r),s=i.data.ops,l=v7.default(s,u=>!!u.create);let c=null;l!==-1&&(c=s[l],s.splice(0,l+1));let a;return c?(d(In,c.create,"no createDoc.create"),a=c.create.data):a=JSON.parse(i.data.data),a.blocks||(a.blocks=[]),{doc:a,ops:i.data.ops}}async revertVersion(t){const o=`${this.apiServer()}/versions/revert/${t}`;await this.request(o,{method:"post",data:{}})}async createVersion(t,e){const r=`${this.apiServer()}/versions`;return(await this.request(r,{method:"post",data:{publish:e,tag:t}})).data}async recognizeLink(t){const o=`${this.apiServer()}/resources/external/${Fo(t)}`;return(await this.request(o)).data}buildResourceUrl(t,e){if(!t)return"";if(t.startsWith("https:")||t.startsWith("http:")||t.startsWith("file:")||t.startsWith("data:")||t.startsWith("blob:"))return t;let r=`${this.apiServer()}/resources/${encodeURIComponent(t)}`;const i=[];if(e!=null&&e.withToken&&i.push(`token=${this.getResourceToken()}`),e!=null&&e.downloadFileName&&i.push(`&fileName=${encodeURIComponent(e.downloadFileName)}`),i.length>0){const s=i.join("&");r+=`?${s}`}return r}}function vw(){return{blocks:[{id:N(),type:"text",text:[]}],comments:{},meta:{}}}const Zu=B("block-ids");class yw{constructor(){h(this,"ids",new Map)}onInsertBlock(t){const e=Array.from(this.ids.keys()).sort((r,i)=>i-r);for(let r=0;r<e.length;r++){const i=e[r];if(i>=t){const s=this.ids.get(i);d(Zu,s!==void 0,"old id is not exists"),this.ids.delete(i),this.ids.set(i+1,s)}}const o=N();this.ids.set(t,o)}onDeleteBlock(t){this.ids.delete(t);const e=Array.from(this.ids.keys()).sort((o,r)=>o-r);for(let o=0;o<e.length;o++){const r=e[o];if(r>t){const i=this.ids.get(r);d(Zu,i!==void 0,"old id is not exists"),this.ids.delete(r),this.ids.set(r-1,i)}}}getId(t){let e=this.ids.get(t);return e||(e=N(),this.ids.set(t,e)),e}getById(t){return Array.from(this.ids.entries()).find(([,e])=>e===t)}}class ww{constructor(){h(this,"ids",new Map)}getContainerIds(t){let e=this.ids.get(t);return e||(e=new yw,this.ids.set(t,e)),e}onInsertBlock(t,e){this.getContainerIds(t).onInsertBlock(e)}onDeleteBlock(t,e){this.getContainerIds(t).onDeleteBlock(e)}getBlockId(t,e){return this.getContainerIds(t).getId(e)}getBlockIndexById(t){const e=Array.from(this.ids.entries());for(let o=0;o<e.length;o++){const r=e[o],i=r[1].getById(t);if(i)return{containerId:r[0],blockIndex:i[0]}}return d(Zu,!1,"fault error: failed to get block index"),{containerId:"error",blockIndex:-1}}}class F2{constructor(t=new Set,e=new Map){this.deletedKeys=t,this.insertedValues=e}insert(t,e){this.insertedValues.set(t,e)}delete(t){this.deletedKeys.add(t)}toDocBlockDelta(){const t={};return this.insertedValues.forEach((e,o)=>{t[o]=e}),{insert:t,delete:Array.from(this.deletedKeys)}}}const $t=B("op-parser");function jr(n){return n==="blocks"?"root":n}class Bw{constructor(t,e){h(this,"updatingBlockDataDeltaMap",new Map);h(this,"blockIds",new ww);this.handler=t,this.local=e}onDeleteBlock(t,e){const o=this.blockIds.getBlockId(t,e);this.blockIds.onDeleteBlock(t,e);const r=this.updatingBlockDataDeltaMap.get(o);r&&($t.debug(`ignore update object data before delete block: ${JSON.stringify(r)}`),this.updatingBlockDataDeltaMap.delete(o)),this.handler.onDeleteBlock(jr(t),e,this.local)}onInsertBlock(t,e,o){this.blockIds.onInsertBlock(t,e),this.handler.onInsertBlock(jr(t),e,o,this.local)}onUpdateBlockText(t,e,o){this.handler.onUpdateBlockText(jr(t),e,o,this.local)}onDeleteBlockData(t,e,o){const r=this.blockIds.getBlockId(t,e);let i=this.updatingBlockDataDeltaMap.get(r);i||(i=new F2,this.updatingBlockDataDeltaMap.set(r,i)),i.delete(o)}onInsertBlockData(t,e,o,r){const i=this.blockIds.getBlockId(t,e);let s=this.updatingBlockDataDeltaMap.get(i);s||(s=new F2,this.updatingBlockDataDeltaMap.set(i,s)),s.insert(o,r)}executeUpdateBlockDataActions(){Array.from(this.updatingBlockDataDeltaMap.entries()).forEach(([t,e])=>{const{containerId:o,blockIndex:r}=this.blockIds.getBlockIndexById(t);this.handler.onUpdateBlockData(jr(o),r,e.toDocBlockDelta(),this.local)})}}class z2{}class Yu{constructor(t){h(this,"key");this.key=t}}function Ew(n,t,e){const o=t.concat(),r=o[0];if(typeof r!="number"||(o.shift(),o.length===1))return!1;const i=o[0];if(typeof i!="object"||!i.i||Object.keys(i).length!==1)return!1;for(let l=1;l<o.length;l++){const c=o[l];if(!Array.isArray(c)||c.length!==2||typeof c[0]!="string")return!1;const u=c[1];if(typeof u!="object"||u.i===void 0||Object.keys(u).length!==1)return!1}const s=i.i;d($t,s.id,"block id is required"),d($t,s.type,"block type is required");for(let l=1;l<o.length;l++){const c=o[l],a=c[0],u=c[1];s[a]=u.i}return e.onInsertBlock(n,r,s),!0}function Qu(n,t,e,o){if(e==="upsert"&&Ew(n,t,o))return;d($t,Array.isArray(t),`invalid block op: ${n}, ${JSON.stringify(t)}`);const r=t.concat(),i=r[0];r.shift();const s=[];for(;r.length>0;){const l=r[0];if(l==="text"){const c=r[1];if(d($t,typeof c=="object",`invalid block op: ${n}, ${JSON.stringify(t)}`),d($t,c.et==="rich-text",`invalid block op: ${n}, ${JSON.stringify(t)}`),r.splice(0,2),e==="upsert"){const u=c.e;o.onUpdateBlockText(n,i,u)}d($t,r.length===0,`invalid block ops.length !== 0, ${JSON.stringify(r)}`)}else if(Array.isArray(l)){d($t,l.length===2,`invalid block op: data.length !== 2, ${JSON.stringify(l)}`);const c=l[0];d($t,typeof c=="string",`invalid block op: key ${JSON.stringify(c)}`);const a=l[1];if(c==="text"){if(d($t,typeof a=="object",`invalid opData type, ${JSON.stringify(a)}`),a.i&&e==="upsert"&&o.onInsertBlockData(n,i,c,a.i),a.r&&e==="remove"&&o.onDeleteBlockData(n,i,c),a.et==="rich-text"&&e==="upsert"){const f=a.e;o.onUpdateBlockText(n,i,f)}}else e==="remove"&&a.r&&s.push(new Yu(c)),e==="upsert"&&a.i&&o.onInsertBlockData(n,i,c,a.i);r.shift()}else if(typeof l=="object"){const c=l;e==="remove"&&c.r&&s.push(new z2),e==="upsert"&&c.i&&o.onInsertBlock(n,i,c.i),r.shift()}else{d($t,typeof l=="string","data is not string"),d($t,l!=="text","data !== 'text'"),d($t,r.length===2,`invalid block op: ops.length !== 2, ${JSON.stringify(r)}`);const c=l,a=r[1];e==="remove"&&a.r&&s.push(new Yu(c)),e==="upsert"&&a.i&&o.onInsertBlockData(n,i,c,a.i),r.splice(0,2)}}s.reverse(),s.forEach(l=>{l instanceof z2?o.onDeleteBlock(n,i):l instanceof Yu?o.onDeleteBlockData(n,i,l.key):d($t,!1,`invalid action type: ${typeof l}, ${JSON.stringify(l)}`)})}function Iw(n,t,e,o){$t.warn(`unsupported meta op, ${JSON.stringify(n)}`)}function xw(n,t,e,o){const r=n[1],i=n[2];d($t,r,`invalid comment op, no commentId: ${JSON.stringify(n)}`),d($t,i,`invalid comment op, no actions: ${JSON.stringify(n)}`),typeof i=="string"?$t.error(`unknown comment op, ${JSON.stringify(n)}`):i.i&&i.r?t==="upsert"&&o.onUpdateComment(r,e.local):i.i?t==="upsert"&&o.onCreateComment(r,e.local):i.r?t==="remove"&&o.onDeleteComment(r,e.local):$t.error(`unknown comment op, ${JSON.stringify(n)}`)}function Ku(n,t,e,o){const r=n[0];if(Array.isArray(r)){r.forEach(l=>{Ku(l,t,e,o)});return}const i=r;if(d($t,typeof i=="string",`invalid container id: ${JSON.stringify(n)}`),i==="meta"){Iw(n);return}if(i==="comments"){xw(n,t,e,o);return}const s=i;if(Array.isArray(n[1]))t==="remove"?n.slice(1).reverse().forEach(l=>{Qu(s,l,t,e)}):n.slice(1).forEach(l=>{Qu(s,l,t,e)});else if(typeof n[1]=="object"){const l=n[1];l.r&&t==="remove"&&o.onDeleteContainer(jr(s),e.local),l.i&&t==="upsert"&&o.onCreateContainer(jr(s),l.i,e.local)}else d($t,typeof n[1]=="number",`invalid ops[1], not a number: ${JSON.stringify(n)}`),Qu(s,n.slice(1),t,e)}function U2(n,t,e){const o=new Bw(t,e);for(let r=0;r<2;r++){const i=r===0?"remove":"upsert",s=Y.default(n),l=s[0];Array.isArray(l)?s.forEach(c=>{Ku(c,i,o,t)}):Ku(s,i,o,t)}o.executeUpdateBlockDataActions()}const Tw=B("sharedb-comments");function Ju(n){if(n.doc)return Y.default(n.doc);const t=n.blocks;d(Tw,t,"no comment blocks");const e={blocks:{root:t},meta:{},comments:{}};return Object.entries(n).forEach(([o,r])=>{Array.isArray(r)&&(e.blocks[o]=r)}),Y.default(e)}function V2(n){const{id:t,groupId:e,userId:o,displayName:r,avatarUrl:i,abstract:s,created:l,modified:c}=n;return{id:t,groupId:e,userId:o,displayName:r,avatarUrl:i,abstract:s,created:l,modified:c}}function Xu(n,t){const e={...n,doc:t};return delete e.blocks,Y.default(e)}const vt=B("sharedb-doc/doc-container"),q2="ot-json1";gl.type.registerSubtype(hy.type),gl.type.name=q2,gl.type.invert=null;class ps extends Di{constructor(e,o,r=!0){super();h(this,"doc");h(this,"client");h(this,"localPresence");h(this,"remoteCaretHandler",new dy);h(this,"batching",0);h(this,"status","clean");h(this,"disableLogout");h(this,"destroyed",!1);h(this,"handleNothingPending",()=>{this.setStatus("clean")});h(this,"handleCreate",()=>{this.handleReload("doc created")});h(this,"handleDel",()=>{});h(this,"handleReload",e=>{this.callbacks.forEach(o=>{var r;return(r=o.onRequestReload)==null?void 0:r.call(o,e)})});h(this,"handleReset",async e=>{const o=new Error(`reset doc: ${e}`);o.code="ResetDoc",this.callbacks.forEach(r=>{var i;return(i=r.onError)==null?void 0:i.call(r,o)}),this.destroy()});h(this,"handleWriteConflictError",e=>{this.handleReset(`write conflict: ${e.message}, ${JSON.stringify(e.orgMsg)}`)});h(this,"insertObject",async(e,o,r)=>{const i=[e,o,{i:r}];return this.submitOp(i)});h(this,"deleteObject",async(e,o)=>{const r=[e,o,{r:!0}];return this.submitOp(r)});h(this,"replaceObject",async(e,o,r)=>{const i=[e,o,{r:!0,i:r}];return this.submitOp(i)});h(this,"updateObject",async(e,o,r)=>{const i=this.data()[e][o],s=[e,o];return Object.entries(r).forEach(([l,c])=>{if(!ml.default(i[l],c))if(i[l]===void 0){if(c!=null){const a={i:c};s.push([l,a])}}else if(c==null){const a={r:!0};s.push([l,a])}else{const a={r:!0,i:c};s.push([l,a])}}),Object.entries(i).forEach(([l,c])=>{if((r[l]===void 0||r[l]===null)&&c!==void 0){const a={r:!0};s.push([l,a])}}),s.length<=2?Promise.resolve():this.submitOp(s)});h(this,"broadcastMessage",async e=>{const o={type:"custom",data:e,clientId:this.client.clientId};this.localPresence&&this.localPresence.submit(o)});h(this,"data",()=>this.doc.data);h(this,"submitOp",async e=>new Promise((o,r)=>{if(this.destroyed){vt.warn("submit op after destroyed");return}this.setStatus("dirty"),this.doc.submitOp(e,{},i=>{i?(vt.error(`invalid op, ${i.message}, ${JSON.stringify(e)}`),r(i),vt.error("Transform detected write conflict, reload editor"),this.handleReset("write conflict")):o()}),this.doc.data||(vt.error("no data after submit op, may be the submitted op is invalid"),this.handleReset(`invalid op, ${JSON.stringify(e)}`))}));h(this,"createDoc",async e=>new Promise((o,r)=>{this.doc.create(e,q2,i=>{i?r(i):o()})}));h(this,"submitInsertChildContainer",async(e,o)=>{const r=[bo(e),{i:o}];return this.submitOp(r)});h(this,"submitDeleteChildContainer",async e=>{const o=[bo(e),{r:!0}];return this.submitOp(o)});h(this,"submitInsertBlock",async(e,o,r)=>{const i=[bo(e),o,{i:r}];return this.submitOp(i)});h(this,"submitDeleteBlock",async(e,o)=>{const r=[bo(e),o,{r:!0}];return this.submitOp(r)});h(this,"submitUpdateBlockData",async(e,o,r)=>{if(r.delete.length===0&&Object.keys(r.insert).length===0)return Promise.resolve();const i=[bo(e),o],s=new Set(r.delete);Object.entries(r.insert).forEach(([c,a])=>{if(s.has(c)){const u={r:!0,i:a};i.push([c,u])}});const l=new Set(Object.keys(r.insert));return r.delete.forEach(c=>{if(l.has(c))return;const a={r:!0};i.push([c,a])}),Object.entries(r.insert).forEach(([c,a])=>{if(s.has(c))return;const u={i:a};i.push([c,u])}),this.submitOp(i)});h(this,"submitUpdateRichText",async(e,o,r)=>{const i=[bo(e),o,"text",{e:r,et:"rich-text"}];return this.submitOp(i)});h(this,"handleOp",(e,o,r)=>{if(this.destroyed){vt.warn("handleOp: destroyed");return}U2(e,this,!!o)});this.client=e,this.doc=o,this.doc.preventCompose=!0,this.disableLogout=r,this.registerCallback(this.remoteCaretHandler)}beginBatchUpdate(){return this.doc.preventCompose=!1,this.batching++,this.batching}endBatchUpdate(){return this.batching--,d(vt,this.batching>=0,"invalid call beginBatchUpdate/endBatchUpdate"),this.batching===0&&(this.doc.preventCompose=!0),this.batching}static async load(e){try{const o=new kw(e.auth,e.serverUrl,e.reauthFunc),r=await o.getDoc(),i=new ps(o,r,e.disableLogout);if(r.type===null){if(e.autoCreateDoc===!1){const s=new Error("doc not exists");throw s.code="DocNotExists",s}await i.createDoc(e.templateData||vw())}return await i.initPresence(),await i.subscribe(),i.initEvents(),i}catch(o){throw vt.error(o),vt.error(`failed to load doc: ${JSON.stringify(o)}`),o}}setStatus(e){this.status!==e&&(this.status=e,this.callbacks.forEach(o=>{var r;return(r=o.onStatusChanged)==null?void 0:r.call(o,e)}))}initEvents(){this.doc.on("nothing pending",this.handleNothingPending),this.doc.on("create",this.handleCreate),this.doc.on("del",this.handleDel),this.client.onWriteConflictError(this.handleWriteConflictError)}clearEvents(){this.doc.off("nothing pending",this.handleNothingPending),this.doc.off("create",this.handleCreate),this.doc.off("del",this.handleDel)}initPresence(){return new Promise((e,o)=>{if(this.localPresence)e();else{const r=this.doc.connection.getPresence(`${this.doc.collection}:${this.doc.id}`);r.on("receive",(i,s)=>{this.onCustomMessage(s)}),r.subscribe(i=>{i?o(i):(this.localPresence=r.create(N()),e())})}})}subscribe(){return new Promise((e,o)=>{this.doc.subscribe(r=>{r?o(r):(this.doc.on("op",this.handleOp),e())})})}toJSON(){return rs(this.data())}getContainerBlocks(e){const o=this.data();d(vt,o,"no doc data");const r=o[bo(e)];return d(vt,r,`no container data: ${e}`),Y.default(r)}getBlockData(e,o){const r=this.data();d(vt,r,"no doc data");const i=r[bo(e)];d(vt,i,`no container data: ${e}`);const s=i[o];return d(vt,s,`no block data: ${o}`),Y.default(s)}localInsertBlock(e,o,r){return this.submitInsertBlock(e,o,r),this.getBlockData(e,o)}localDeleteBlock(e,o){const r=this.getBlockData(e,o);return this.submitDeleteBlock(e,o),r}localUpdateBlockText(e,o,r){const i=this.getBlockData(e,o);d(vt,i.text,"no block text");const s=Y.default(i.text);this.submitUpdateRichText(e,o,r);const l=ie.apply(s,r);return d(vt,l,"no block text"),l}localUpdateBlockData(e,o,r){const i=Y.default(this.getBlockData(e,o));return this.submitUpdateBlockData(e,o,r),i}localInsertChildContainer(e,o){this.submitInsertChildContainer(e,o)}localDeleteChildContainers(e){this.beginBatchUpdate(),e.forEach(o=>{this.submitDeleteChildContainer(o)}),this.endBatchUpdate()}getComments(){return Object.values(this.data().comments).map(o=>V2(o))}getComment(e){return this.data().comments[e]}getCommentDoc(e){const o=this.data().comments[e];return Ju(o)}localCreateComment(e,o){const r=Xu(e,o),s=["comments",r.id,{i:r}];return this.submitOp(s)}localDeleteComment(e){const o=["comments",e,{r:!0}];return this.submitOp(o)}localUpdateComment(e,o){const r=Xu(e,o),i=["comments",e.id,{r:!0,i:r}];return this.submitOp(i)}destroy(){var e;this.destroyed=!0,this.clearEvents(),this.clearCallbacks(),this.doc.destroy(),(e=this.localPresence)==null||e.destroy(),this.client.close(!this.disableLogout),this.remoteCaretHandler.destroy()}onDeleteBlock(e,o,r){d(vt,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(i=>{var s;return(s=i.onDeleteBlock)==null?void 0:s.call(i,Nr(e),o,r)})}onInsertBlock(e,o,r,i){d(vt,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onInsertBlock)==null?void 0:l.call(s,Nr(e),o,r,i)})}onUpdateBlockData(e,o,r,i){d(vt,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockData)==null?void 0:l.call(s,Nr(e),o,r,i)})}onUpdateBlockText(e,o,r,i){d(vt,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockText)==null?void 0:l.call(s,Nr(e),o,r,i)})}onDeleteContainer(e,o){d(vt,this.callbacks.length>0,"no callbacks"),d(vt,e!=="root","should not delete root container in doc"),this.callbacks.forEach(r=>{var i;return(i=r.onDeleteChildContainer)==null?void 0:i.call(r,Nr(e),o)})}onCreateContainer(e,o,r){d(vt,this.callbacks.length>0,"no callbacks"),d(vt,e!=="root","should not create root container in doc"),this.callbacks.forEach(i=>{var s;return(s=i.onInsertChildContainer)==null?void 0:s.call(i,Nr(e),o,r)})}onDeleteComment(e,o){d(vt,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(r=>{var i;return(i=r.onDeleteComment)==null?void 0:i.call(r,e,o)})}onCreateComment(e,o){d(vt,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(r=>{var i;return(i=r.onCreateComment)==null?void 0:i.call(r,e,o)})}onUpdateComment(e,o){d(vt,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(r=>{var i;return(i=r.onUpdateComment)==null?void 0:i.call(r,e,o)})}onCustomMessage(e){const o=e;(o==null?void 0:o.type)==="custom"&&(o==null?void 0:o.clientId)!==this.client.clientId?this.callbacks.forEach(r=>{var i;return(i=r.onCustomMessage)==null?void 0:i.call(r,o.data)}):(o==null?void 0:o.type)==="onlineUsers"&&setTimeout(()=>{const r={type:"custom",data:e,clientId:"-"};this.onCustomMessage(r)})}async addResources(e){return await this.client.getFileUrlsByHashes(e)}async uploadResource(e,o){var i;return{resourceId:await this.client.uploadResource(e,(i=o==null?void 0:o.onProgress)!=null?i:()=>{})}}buildResourceUrl(e,o){return this.client.buildResourceUrl(e,o)}request(e,o){return this.client.request(e,o)}getUser(){const e=this.client.clientId,{permission:o,userId:r,displayName:i,avatarUrl:s}=this.client.auth;return{permission:o,clientId:e,userId:r,displayName:i,avatarUrl:s,rainbowIndex:0}}getRemoteUsers(){return this.remoteCaretHandler.remoteUsers}getVersionHelper(){return this}getVersions(){return this.client.getVersions()}async getVersion(e){const o=await this.client.getVersion(e);return rs(o)}async getLatestVersion(){const e=await this.client.getLatestVersion();return rs(e)}async getHistoryData(e,o){const{doc:r,ops:i}=await this.client.getVersionOps(e,o),s=i.map(l=>({user:l.meta.createdBy,data:l}));return{doc:rs(r),historyData:s}}async getVersionData(e,o){const{doc:r,ops:i}=await this.client.getVersionOps(e,o);return{doc:rs(r),versionData:i}}revertVersion(e){return this.client.revertVersion(e)}createVersion(e,o){return this.client.createVersion(e,o)}async recognizeLink(e){return this.client.recognizeLink(e)}parseHistoryData(e,o){U2(e.data.op,o,!0)}getServerMeta(){return{appId:this.client.auth.appId,docId:this.client.auth.docId,serverId:this.client.apiServer()}}}B("remote-cursor");class W2{constructor(t){h(this,"handleDocSelectionChange",()=>{this.broadcastCaretPos()});h(this,"broadcastCaretPos",Xt.default(()=>{const t={type:"caret",userId:this.editor.doc.getUser().userId,range:this.editor.selection.range.toDocRange()};this.editor.doc.broadcastMessage(t)},300));h(this,"handleRemoteCaretsChanged",t=>{t.forEach(e=>{const o=this.editor.findBlockById(e);o&&this.editor.reloadBlock(o)})});this.editor=t,this.editor.addListener("selectionChanged",this.handleDocSelectionChange),this.editor.doc.getRemoteUsers().addListener("remote-carets-change",this.handleRemoteCaretsChanged)}destroy(){this.editor.removeListener("selectionChanged",this.handleDocSelectionChange),this.editor.doc.getRemoteUsers().removeListener("remote-carets-change",this.handleRemoteCaretsChanged)}}const G2=B("remote-cursor-decorator");class th{decorateText(t,e,o){const r=t.doc.getRemoteUsers();if(!r)return{};const i=new Map,{containerId:s,blockIndex:l}=e[e.length-1];d(G2,typeof s=="string","invalid path containerId"),d(G2,typeof l=="number","invalid path blockIndex");const c=t.doc.getBlockData(s,l),a=ue(o);return r.getSimpleCursors(c.id).forEach((f,m)=>{m>a&&(m=a);const C=f.map(w=>({id:N(),type:"remote-cursor",name:w.user.displayName,time:w.time,rainbowIndex:w.user.rainbowIndex})),k=i.get(m);k?k.push(...C):i.set(m,C)}),{insertions:i}}}class Z2 extends Yt.TypedEmitter{constructor(t){super(),this.editor=t,this.editor.doc.registerCallback(this)}handleChild(t,e,o){if(pt(Er(this.editor,t)))return;const r=this.editor.getBlockByIndex(t,e),i=F(this.editor.getContainerById(t));i&&this.emit("change",this.editor,i,r,o)}onUpdateBlockData(t,e){this.handleChild(t,e,"data-change")}onUpdateBlockText(t,e){this.handleChild(t,e,"text-change")}destroy(){this.editor.doc.unregisterCallback(this)}}function Sw(n,t){n.addCustom("child-block-tracker",()=>new Z2(n)).addListener("change",t)}function Dw(n,t){n.addCustom("child-block-tracker",()=>new Z2(n)).removeListener("change",t)}const uz="",Lw={colorPalette:{colorDesc:"\u5B57\u4F53\u989C\u8272",backgroundDesc:"\u80CC\u666F\u989C\u8272",reset:"\u6062\u590D\u9ED8\u8BA4",name:"\u6587\u672C\u989C\u8272"},search:{emptyTips:"\u6682\u65E0\u641C\u7D22\u7ED3\u679C"}},Mw={colorPalette:{colorDesc:"Text Color",name:"Text Color",backgroundDesc:"Background Color",reset:"Reset"},search:{emptyTips:"\u6682\u65E0\u641C\u7D22\u7ED3\u679C"}};T.mergeLang({"zh-CN":Lw,"en-US":Mw});const hz="";B("button");function yo(n,t,e,o,r){const i=b("button",["editor-button"],null);return i.setAttribute("data-button-id",n),r&&i.setAttribute(`data-editor-tooltip-${r}`,t),e?typeof e=="string"?e.startsWith("<")?i.innerHTML=e:i.innerText=e:i.appendChild(e):i.innerText=t,o&&(o.indexOf("checked")!==-1&&A(i,"checked"),o.indexOf("disabled")!==-1&&(i.disabled=!0)),i}function Y2(n,t,e){e?n.setAttribute(`data-editor-tooltip-${e}`,t):n.innerText=t}const fz="",Hr=B("ui-command-bar-base"),Rw={itemElementTag:"div",tippyArrow:!1},Tf=class extends Yt.TypedEmitter{constructor(e,o,r){var i,s;super();h(this,"content");h(this,"items");h(this,"subBar",null);h(this,"parentItem",null);h(this,"closeable",null);h(this,"options");h(this,"id");h(this,"handleDocumentKeydown",e=>{if(!!this.isVisible&&!e.isComposing){if(this.subBar){this.subBar.handleDocumentKeydown(e);return}if(this.items.length!==0){if(e.key==="Escape"){this.close();return}if(e.key==="ArrowUp"){const o=this.getPrevItemIndex(this.getSelectedItemIndex());this.selectItem(this.items[o].id),e.preventDefault(),e.stopPropagation()}else if(e.key==="ArrowDown"){const o=this.getNextItemIndex(this.getSelectedItemIndex());this.selectItem(this.items[o].id),e.preventDefault(),e.stopPropagation()}else if(e.key==="ArrowRight"){const o=this.getSelectedItem();o&&o.children&&this.showSubCommandBar(o.childrenMenuId)}else if(e.key==="ArrowLeft")this.parentItem&&this.close();else if(e.key==="Enter"){const o=this.getSelectedItemIndex();if(o===-1)return;const r=this.items[o],i=this.getItemElementById(r.id);i&&this.emit("click",this,r,i)}}}});h(this,"handleDocumentMouseDown",e=>{e.target instanceof Element&&(this.isInCommandBar(e.target)||this.close())});h(this,"handleHidden",()=>{this.close(),this.emit("close",this),Lm(this.id)});h(this,"handleShow",()=>{this.popper&&(this.popper.setAttribute("data-command-bar-id",this.id),this.options.classes&&A(this.popper,...this.options.classes),this.options.refuseOverflow&&this.popper.classList.add("reference-hidden")),this.emit("show",this),this.options.disablePageScroll&&Dm(this.id)});h(this,"handleItemMouseEnter",e=>{const o=this.getParentCommandItemElement(e.target);if(!o)return;const r=this.getItemElementId(o),i=this.getItemById(r);if(this.selectItem(r),i.manualShowChildren)return;const s=i.childrenMenuId||"";this.showSubCommandBar(s)});h(this,"handleItemMouseLeave",e=>{var r,i;const o=this.getParentCommandItemElement(e.target);!o||((i=(r=this.subBar)==null?void 0:r.parentItem)==null?void 0:i.id)!==this.getItemElementId(o)&&(z(o,"selected"),this.emit("selectionChange",this,""))});h(this,"handleItemClick",e=>{const o=this.getParentCommandItemElement(e.target);if(!o)return;const r=this.getItemElementId(o),i=this.items.find(s=>s.id===r);if(!!i&&!(i.states&&i.states.indexOf("disabled")!==-1)){if(i.children&&i.children.length>0&&i.manualShowChildren){this.showSubCommandBar(i.childrenMenuId);return}i.element||(this.emit("click",this,i,o),this.options.autoClose&&this.close())}});h(this,"handleWheel",e=>{if(!this.options.disablePageScroll&&!document.querySelector(".editor-disable-scroll"))return;const o=e.target;if(!o||!(o instanceof Node))return;const r=o instanceof HTMLElement?o:o.parentElement;if(!r)return;const i=We(r);if(!It(this.content,i)){e.stopPropagation(),e.preventDefault();return}e.deltaY<0?i.scrollTop===0&&(e.stopPropagation(),e.preventDefault()):e.deltaY>0&&i.scrollTop+i.clientHeight>=i.scrollHeight&&(e.stopPropagation(),e.preventDefault())});this.id=(i=r==null?void 0:r.id)!=null?i:N(),this.options={...Rw,...r},this.items=e,this.parentItem=(s=r==null?void 0:r.parentItem)!=null?s:null,this.closeable=o!=null?o:null,this.content=this.createCommandBarContent(e)}close(){this.subBar&&this.subBar.close(),document.removeEventListener("keydown",this.handleDocumentKeydown),document.removeEventListener("mousedown",this.handleDocumentMouseDown)}click(e,o){this.emit("click",this,e,o)}createPopperOptions(){var r;const e={modifiers:[]},o=this.options.overflowBoundary;return o&&((r=e==null?void 0:e.modifiers)==null||r.push({name:"flip",options:{boundary:o,fallbackPlacements:["top","bottom"]}})),e}destroy(){var e;this.close(),this.removeAllListeners(),(e=this.subBar)==null||e.destroy(),this.subBar=null,this.closeable=null,this.content.removeEventListener("wheel",this.handleWheel)}get isSubCommandBar(){return!!this.parentItem}updateItems(e){var r;this.subBar&&e.findIndex(s=>{var l,c;return s.id===((c=(l=this.subBar)==null?void 0:l.parentItem)==null?void 0:c.id)})===-1&&((r=this.subBar)==null||r.destroy(),this.subBar=null),this.items=e;const o=this.createCommandBarContent(e);this.content.innerHTML="",Array.from(o.children).forEach(i=>{this.content.appendChild(i)})}get popper(){return this.content.closest("[data-tippy-root]")}getSelectedItemIndex(){const e=this.getSelectedItem();return e?this.items.indexOf(e):-1}getPrevItemIndex(e){if(e<=0)return this.items.length-1;let o=e-1;for(;;){const r=this.items[o].type;if(r!=="separator"&&r!=="section")return o;if(o-=1,o<=0)return this.items.length-1}}getNextItemIndex(e){let o=e+1;for(;;){if(!this.items[o])return this.getNextItemIndex(-1);const r=this.items[o].type;if(r!=="separator"&&r!=="section")return o;if(o+=1,o>this.items.length-1)return 0}}clearSelectedItem(){const e=this.getSelectedItem();if(!e)return;const o=this.getItemElementById(e.id);o&&z(o,"selected")}selectItem(e){const o=this.getSelectedItem();if(o){if(o.id===e)return;const i=o.id,s=this.getItemElementById(i);s&&z(s,"selected")}const r=this.getItemElementById(e);r?(A(r,"selected"),this.emit("selectionChange",this,r.getAttribute("data-id")||""),r.scrollIntoView({block:"nearest"})):this.emit("selectionChange",this,"")}showSubCommandBar(e){var s,l;const o=this.getSelectedItem();if(!o)return;if(this.subBar){if(((s=this.subBar.parentItem)==null?void 0:s.id)===o.id){o.manualShowChildren&&this.subBar.close();return}this.subBar.destroy(),this.subBar=null}if(!o.children)return;const r=this.getItemElementById(o.id);if(!r)return;const i=Tf.createSubCommandBar(o,(l=this.closeable)!=null?l:this,e?{id:e}:{});this.subBar=i,this.subBar.on("click",(c,a,u)=>{this.emit("click",c,a,u)}),this.subBar.on("close",()=>{var c;(c=this.subBar)==null||c.destroy(),this.subBar=null,z(r,"active")}),o.beforePopup&&o.beforePopup(i),this.subBar.manualShow(r,this.getSubBarOptions(o)),A(r,"active")}isInCommandBar(e){if(!e||!(e instanceof Node))return!1;const o=this.getCommandBarRoot();return o&&It(o,e)||It(this.content,e)?!0:this.subBar?this.subBar.isInCommandBar(e):!1}createCommandItem(e){var i,s,l,c;let o=(i=this.options.itemElementTag)!=null?i:"div";e.element&&(o="div");const r=b(o,["command-item"],null);return r.setAttribute("data-id",e.id),e.type==="separator"?r.classList.add("separator"):e.type==="section"?(r.classList.add("section","text"),e.element&&(typeof e.element=="function"?r.appendChild(e.element(e)):r.appendChild(e.element))):((s=e.states)!=null&&s.includes("selected")&&r.classList.add("selected"),(l=e.states)!=null&&l.includes("checked")&&r.classList.add("checked"),(c=e.states)!=null&&c.includes("disabled")&&r.classList.add("disabled"),r.onclick=this.handleItemClick,r.onmouseenter=this.handleItemMouseEnter,r.onmouseleave=this.handleItemMouseLeave,e.element?typeof e.element=="function"?r.appendChild(e.element(e)):r.appendChild(e.element):r.classList.add("standard")),this.initItemElement(e,r),r}getItemById(e){const o=this.items.find(r=>r.id===e);return d(Hr,o,`can not find command item for id: ${e}`),o}getSelectedItem(){const e=this.content.querySelector(":scope >.editor-command-bar >.command-item.selected");if(e){const o=this.getItemElementId(e),r=this.items.find(i=>i.id===o);return d(Hr,r,`can not find command item for id: ${o}`),r}return null}getItemElementId(e){const o=e.getAttribute("data-id");return d(Hr,o,"no data-id attribute"),o}getItemElementById(e){const o=this.content.querySelector(`:scope >.editor-command-bar > .command-item[data-id="${e}"]`);return d(Hr,o,`no exists command item, id=${e}`),o}getParentCommandItemElement(e){if(!e||!(e instanceof Element))return null;if(nt(e,"command-item"))return e;const o=e.closest(".command-item");return o||null}createCommandBarContent(e){this.content&&this.content.removeEventListener("wheel",this.handleWheel);const o=b("div",["editor-command-bar-root"],null),r=b("div",["editor-command-bar"],o);return e.forEach(i=>{var l;const s=this.createCommandItem(i);r.appendChild(s),i.element&&i.setCloseable&&i.setCloseable((l=this.closeable)!=null?l:this)}),this.initCommandBarElement(r),o.addEventListener("wheel",this.handleWheel,{passive:!1}),o}getSubBarOptions(e){var o;return{placement:(o=e.childrenPlacement)!=null?o:"right-start"}}static registerManualCommandBar(e,o){this.commandBarCreators.set(e,o)}static createSubCommandBar(e,o,r){var l;d(Hr,e.children&&e.children.length>0,"no item children");const i=(l=e.childrenType)!=null?l:"menu",s=this.commandBarCreators.get(i);return d(Hr,s,`no creator for command type: ${i}`),s(e,o,r)}static hasExistsCommandBar(){return!!document.querySelector("[data-command-bar-id]")}};let Fr=Tf;h(Fr,"commandBarCreators",new Map),B("ui-command-bar");class yc extends Fr{constructor(){super(...arguments);h(this,"tippyInstance",null)}manualShow(e,o){var r,i;if(!this.isVisible){if(this.tippyInstance&&(this.tippyInstance.destroy(),this.tippyInstance=null),this.tippyInstance=B7.default(e,{interactive:!0,content:this.content,trigger:"manual",triggerTarget:null,hideOnClick:!1,placement:(r=o==null?void 0:o.placement)!=null?r:"bottom-start",maxWidth:650,arrow:this.options.tippyArrow,appendTo:document.body,onShow:this.handleShow,onHidden:this.handleHidden,theme:o==null?void 0:o.theme,getReferenceClientRect:o==null?void 0:o.getReferenceClientRect,offset:(i=o==null?void 0:o.offset)!=null?i:[0,0],popperOptions:this.createPopperOptions()}),o!=null&&o.point){const{x:s,y:l}=o.point;this.tippyInstance.setProps({getReferenceClientRect:()=>new DOMRect(s,l,0,0)})}this.clearSelectedItem(),this.tippyInstance.show(),this.parentItem||(document.addEventListener("keydown",this.handleDocumentKeydown),document.addEventListener("mousedown",this.handleDocumentMouseDown)),this.popper&&this.options.id&&this.popper.setAttribute("data-command-bar-id",this.options.id)}}close(){var e;super.close(),this.isVisible&&((e=this.tippyInstance)==null||e.hide())}destroy(){var e;(e=this.tippyInstance)==null||e.destroy(),this.tippyInstance=null,super.destroy()}getCommandBarRoot(){return this.content.closest("[data-tippy-root]")}get isVisible(){var e,o;return(o=(e=this.tippyInstance)==null?void 0:e.state.isVisible)!=null?o:!1}get popper(){return this.content.closest("[data-tippy-root]")}}const Q2=B("ui-base");class Cs extends yc{constructor(t,e){var i;const r=[{id:(i=e==null?void 0:e.id)!=null?i:`popup-${N()}`,name:"",element:t}];super(r,void 0,{disablePageScroll:!0})}initCommandBarElement(t){A(t,"popper")}initItemElement(t,e){}get popupContent(){const t=this.items[0];d(Q2,t,"no dialog item");const e=typeof t.element=="function"?t.element(t):t.element;return d(Q2,e,"no item element"),e}}const wo=B("filterable-list");function Aw(n){var e;const t=b("div",["list-item"],null);return t.setAttribute("data-id",n.id),t.appendChild(b("div",["list-item-text"],null,n.name)),(e=n.states)!=null&&e.includes("selected")&&A(t,"selected"),t}function K2(n){const t=b("div",["list-root"],null);return n.forEach(e=>{t.appendChild(Aw(e))}),t}function J2(n,t){let e=n;return t&&(e=n.map(o=>({...o,states:o.id===t?["selected"]:void 0}))),e}function Ow(n,t){const e=b("div",["filterable-list"],null),o=b("div",["filter"],e),r=b("div",["filter-container"],o),i=b("input",["filter-input"],r);t&&t.placeholder&&(i.placeholder=t.placeholder);const s=b("div",["list"],e),l=K2(J2(n,t==null?void 0:t.initialSelectedId));return s.appendChild(l),e}function X2(n,t,e){const o=n.querySelector(".list");d(wo,o,"no list root");const r=K2(J2(t,e)),i=o.querySelector(".list-root");if(d(wo,i,"no exists menu"),Oi(i,r),e){const s=o.querySelector(".list-item.selected");s&&(d(wo,s,"no selected menu item"),s.scrollIntoView({block:"nearest"}))}}class _w{constructor(t,e){h(this,"root");h(this,"visibleItems");h(this,"selectedId");h(this,"filter","");h(this,"onSelected",null);h(this,"handleKeydown",t=>{this.processKeyDown(t)});h(this,"handleInputChanged",()=>{const t=this.root.querySelector(".filter-input");d(wo,t,"no input");const e=t.value.toLocaleLowerCase();this.setFilter(e)});h(this,"handleClick",t=>{this.processClick(t)});var o;this.items=t,this.options=e,this.root=Ow(t,e),this.bindEvents(),this.selectedId=(o=e==null?void 0:e.initialSelectedId)!=null?o:"",this.visibleItems=t}bindEvents(){const t=this.root.querySelector(".filter-input");d(wo,t,"no input"),t.addEventListener("keyup",this.handleInputChanged),t.addEventListener("keydown",this.handleKeydown),this.root.addEventListener("click",this.handleClick)}unbindEvents(){const t=this.root.querySelector(".filter-input");d(wo,t,"no input"),t.removeEventListener("keyup",this.handleInputChanged),t.removeEventListener("keydown",this.handleKeydown),this.root.removeEventListener("click",this.handleClick)}destroy(){this.unbindEvents(),this.onSelected=null}getSelectedIndex(){return this.selectedId?this.visibleItems.findIndex(t=>t.id===this.selectedId):-1}setSelectedId(t){this.selectedId=t,X2(this.root,this.visibleItems,t)}focus(){const t=this.root.querySelector(".filter-input");d(wo,t,"no input"),t.focus()}reset(){this.setFilter("");const t=this.root.querySelector(".filter-input");d(wo,t,"no input"),t.value=""}setFilter(t){this.filter!==t&&(this.filter=t,this.visibleItems=this.items.filter(e=>e.name.toLocaleLowerCase().includes(t)),X2(this.root,this.visibleItems,this.selectedId))}processClick(t){var s,l;const e=t.target;if(!(e instanceof HTMLElement))return;const o=e.closest(".list-item");if(!o)return;const r=(s=o.getAttribute("data-id"))!=null?s:"",i=(l=this.visibleItems.find(c=>c.id===r))!=null?l:null;this.onSelected&&this.onSelected(this,i)}processKeyDown(t){var e;if(t.key==="ArrowUp"){let o=this.getSelectedIndex();o===-1?o=this.visibleItems.length-1:o>0&&(o-=1);let r="";o!==-1&&(r=this.visibleItems[o].id),this.setSelectedId(r);return}if(t.key==="ArrowDown"){let o=this.getSelectedIndex();o===-1?o=0:o<this.visibleItems.length-1&&(o+=1);let r="";o!==-1&&(r=this.visibleItems[o].id),this.setSelectedId(r);return}if(t.key==="Enter"){const o=(e=this.visibleItems.find(r=>r.id===this.selectedId))!=null?e:null;this.onSelected&&this.onSelected(this,o)}}}class Nw extends _w{constructor(e,o,r){super(e,r);h(this,"popup");h(this,"onShow",null);h(this,"onHide",null);h(this,"custom",null);h(this,"handleShow",()=>{this.onShow&&this.onShow(this)});h(this,"handleHide",()=>{this.onHide&&this.onHide(this)});h(this,"handleShown",()=>{this.focus()});this.popup=new Cs(this.root)}destroy(){super.destroy(),this.onShow=null,this.onHide=null}show(e){this.reset(),this.popup.manualShow(e,{theme:"dropdown-list"}),this.focus()}processKeyDown(e){super.processKeyDown(e),(e.key==="Esc"||e.key==="Enter")&&this.popup.close()}processClick(e){super.processClick(e);const o=e.target;!(o instanceof HTMLElement)||!o.closest(".list-item")||this.popup.close()}}const mz="",gz="";function $w(n,t){const e=document.createElement("div");e.classList.add("toast","show"),t!=null&&t.theme&&e.setAttribute("data-theme",t.theme),t!=null&&t.id&&e.setAttribute("data-id",t.id),t!=null&&t.html?e.innerHTML=n:e.textContent=n,t!=null&&t.position&&(e.style.left=`${t.position.x}px`,e.style.top=`${t.position.y}px`,e.classList.add("positioned")),document.body.appendChild(e),setTimeout(()=>{e.classList.remove("show"),setTimeout(()=>{e.remove()},500)},(t==null?void 0:t.duration)||3e3)}const t5=`<?xml version="1.0" ?>
28
28
  <svg
29
29
  fill="currentColor"
30
30
  xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24">
@@ -334,8 +334,8 @@ xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24">
334
334
  <path d="M5.27137 5.61819C6.60787 5.61819 7.69131 4.53475 7.69131 3.19825C7.69131 1.86176 6.60787 0.77832 5.27137 0.77832C3.93488 0.77832 2.85144 1.86176 2.85144 3.19825C2.85144 4.53475 3.93488 5.61819 5.27137 5.61819Z" stroke="#999999" stroke-linejoin="round" fill="none"/>
335
335
  <path d="M9.07413 10.8036H13.2226M11.1484 8.91895V13.1009V8.91895Z" stroke="#999999" stroke-linecap="square" fill="none"/>
336
336
  <path d="M8.03712 8.38281H5.20234C3.65344 8.38281 2.87899 8.38281 2.28739 8.68423C1.76699 8.94939 1.3439 9.3725 1.07875 9.89289C0.777313 10.4845 0.777313 11.2589 0.777313 12.8078V13.2227H8.03712" stroke="#999999" stroke-linecap="square" stroke-linejoin="round" fill="none"/>
337
- </svg>`;function EB(n,t){var e;if(A(t,"menu-item"),!n.element){if(n.type==="section"){const o=b("div",["section-name"],null,n.name);t.appendChild(o)}else if(n.type!=="separator"){if(n.icon){const r=b("div",["menu-item-icon"],null);n.icon&&(r.innerHTML=n.icon),t.appendChild(r)}const o=b("div",["menu-item-name","text"],null,n.name);if(t.appendChild(o),n.subText&&b("div",["item-subtext","text"],t,n.subText),n.children&&!n.element){const r=b("div",["menu-item-sub-indicator"],null);r.innerHTML=o5,t.appendChild(r)}if((e=n.states)!=null&&e.includes("checked")){const r=b("div",["menu-item-checked-icon"],null);r.innerHTML=rB,t.appendChild(r)}}}}class nr extends yc{constructor(t,e,o){super(t,e,{autoClose:!0,disablePageScroll:!0,...o})}manualShow(t,e){const o={theme:"menu",...e};super.manualShow(t,o)}initCommandBarElement(t){A(t,"menu")}initItemElement(t,e){EB(t,e)}}function IB(n,t,e){var o;return new nr((o=n.children)!=null?o:[],t,{...e,parentItem:n})}class ks extends yc{constructor(t,e,o){super(t,e,{itemElementTag:"button",tippyArrow:!1,...o})}getSubBarOptions(t){var r,i;const e=()=>{const s=this.getItemElementById(t.id),c=this.content.getBoundingClientRect(),a=s.getBoundingClientRect();return new DOMRect(a.left,c.top,a.width,c.height)};return{placement:(r=t.childrenPlacement)!=null?r:"top",getReferenceClientRect:e,offset:(i=t.childrenOffset)!=null?i:[0,4]}}manualShow(t,e){const o={theme:"toolbar",...e};super.manualShow(t,o)}initCommandBarElement(t){A(t,"toolbar")}initItemElement(t,e){e.setAttribute("data-button-id",t.id),this.options.tooltipId&&t.name&&!t.disableTooltip&&(e.setAttribute(`data-editor-tooltip-${this.options.tooltipId}`,t.name),t.desc&&e.setAttribute(`data-editor-tooltip-desc-${this.options.tooltipId}`,t.desc));const o=e;if(!t.element)if(t.icon){const r=b("span",["toolbar-item-icon-container"],o);t.icon.trim().startsWith("<")?r.innerHTML=t.icon:r.innerText=t.icon}else{const r=b("span",["toolbar-item-name-container"],o);r.innerText=t.name}if(t.dropdown){e.setAttribute("data-dropdown","true");const r=b("span",["toolbar-item-dropdown-container"],o);r.innerHTML=eh}t.states&&(t.states.indexOf("checked")!==-1&&A(o,"checked"),t.states.indexOf("disabled")!==-1&&(o.disabled=!0))}}function xB(n,t,e){var o;return new ks((o=n.children)!=null?o:[],t,{...e,parentItem:n})}const pz="";Fr.registerManualCommandBar("menu",IB),Fr.registerManualCommandBar("toolbar",xB);const Cz="",h5=B("ui-base");class vs extends yc{constructor(e,o){super(vs.getCommandItems(e,o),void 0,{disablePageScroll:!0,...o});h(this,"handleDocumentMouseDown",e=>{})}initCommandBarElement(e){A(e,"dialog","manual")}initItemElement(e,o){}show(e,o){this.manualShow(e,{...o,theme:"light"})}get dialogContent(){const e=this.items[0];d(h5,e,"no dialog item");const o=e.element;return d(h5,o,"no item element"),o}static getCommandItems(e,o){var s;return[{id:(s=o==null?void 0:o.id)!=null?s:`manual-dialog-${N()}`,name:"",element:e}]}}const TB=[-1,6,0,1,2,3,4,5],SB=[-1,6,0,1,2,3,4,5,14,13,7,8,9,10,11,12],f5=B("color-palette");function m5(n,t,e,o){d(f5,n>0,"no color in palette");const r=t||1;d(f5,r>0,`invalid palette rows: ${r}`);const i=n/r,s=b("div",["palette-container",o],null);for(let l=0;l<r;l++){const c=b("div",["palette-container-row"],s);for(let a=0;a<i;a++){const u=e(l*i+a);c.appendChild(u)}}return s}function DB(n){const t=b("button",["color-button"],null),e=TB[n];return t.setAttribute("data-color-index",`${e}`),t.innerHTML=n5,t}function LB(n){const t=b("button",["background-color-button"],null),e=SB[n];return t.setAttribute("data-color-index",`${e}`),t}function MB(){const n=b("div",["clear-button-container"],null),t=b("button",["clear-button"],n);return t.innerText=T.t("colorPalette.reset"),n}function RB(n){const t=b("div",["color-palette"],null);return n.color!==!1&&(b("div",["bar-desc"],t,T.t("colorPalette.colorDesc")),t.appendChild(m5(8,1,DB,"color"))),n.backgroundColor!==!1&&(b("div",["bar-desc"],t,T.t("colorPalette.backgroundDesc")),t.appendChild(m5(16,2,LB,"background-color"))),n.clearColorButton!==!1&&t.appendChild(MB()),t}function AB(n,t,e){const o=t==="color"?"color":"background-color",r=n.querySelector(`.${o} button.selected`);r&&z(r,"selected"),e===null&&(e=-1);const i=n.querySelector(`.${o} button[data-color-index="${e}"]`);i&&A(i,"selected")}const bz="",OB={};class _B extends Yt.TypedEmitter{constructor(e=OB){super();h(this,"root");h(this,"handleClick",e=>{const o=e.target;if(!o||!(o instanceof Element))return;const r=o.closest("button");if(!r)return;if(nt(r,"clear-button")){this.setColor("backgroundColor",null),this.setColor("color",null),this.emit("onClick","clearColor",0);return}const i=r.getAttribute("data-color-index");if(!i)return;const s=Number.parseInt(i,10);Number.isNaN(s)||(nt(r,"color-button")?s===-1?(this.setColor("color",null),this.emit("onClick","clearColor",1)):(this.setColor("color",s),this.emit("onClick","color",s)):s===-1?(this.setColor("backgroundColor",null),this.emit("onClick","clearColor",2)):(this.setColor("backgroundColor",s),this.emit("onClick","backgroundColor",s)))});this.options=e,this.root=RB(e),this.root.addEventListener("click",this.handleClick)}destroy(){this.removeAllListeners(),this.root.removeEventListener("click",this.handleClick)}setColor(e,o){AB(this.root,e,o)}}class g5{constructor(t,e){h(this,"name","Color Palette");h(this,"element");h(this,"palette");h(this,"closeable",null);this.id=t,this.palette=new _B(e),this.element=this.palette.root}setCloseable(t){this.closeable=t}destroy(){this.palette.destroy(),this.closeable=null}}function NB(){const n=b("button",["color-button"],null);return n.innerHTML=n5,n}function fh(n,t){const[e,o]=t;e===null?n.removeAttribute("data-color"):n.setAttribute("data-color",`${e}`),o===null?n.removeAttribute("data-background-color"):n.setAttribute("data-background-color",`${o}`)}class $B extends Yt.TypedEmitter{constructor(e){super();h(this,"id","text-color-item");h(this,"name",T.t("colorPalette.name"));h(this,"dropdown",!0);h(this,"manualShowChildren",!0);h(this,"children",[]);h(this,"element");h(this,"colorPaletteItem");h(this,"latestColors",[null,null]);h(this,"handlePaletteClick",(e,o)=>{this.emit("onClick",e,o),e==="color"||e==="backgroundColor"?e==="color"?this.latestColors[0]=o:this.latestColors[1]=o:this.latestColors=[null,null],fh(this.element,this.latestColors)});h(this,"beforePopup",()=>{this.emit("beforePopup")});this.editor=e,this.colorPaletteItem=new g5("text-color-palette-item"),this.colorPaletteItem.palette.addListener("onClick",this.handlePaletteClick),this.children.push(this.colorPaletteItem),this.element=NB()}destroy(){this.colorPaletteItem.destroy()}updatePaletteColor(e){this.colorPaletteItem.palette.setColor("color",e[0]),this.colorPaletteItem.palette.setColor("backgroundColor",e[1]),this.latestColors=e,fh(this.element,this.latestColors)}updateButtonColor(e){this.latestColors=e,fh(this.element,this.latestColors)}}const kz="";function mh(n,t){const e=b("div",["editor-input-wrap"],n);t!=null&&t.className&&A(e,t==null?void 0:t.className);const o=b("div",["editor-input-label"],e);b("span",[],o,t.label),t.required&&A(o,"required");const r=b("div",["editor-input-container"],e),i=b("input",["editor-input"],r);t.placeholder&&(i.placeholder=t.placeholder),t.defaultValue&&(i.value=t.defaultValue);const s=b("div",["editor-input-error"],e);return i.addEventListener("input",l=>{var c;(c=t.onChange)==null||c.call(t,l),z(e,"error")}),i.addEventListener("keydown",l=>{var c;(c=t.onKeyDown)==null||c.call(t,l)}),{getField:()=>i,getInputValue:()=>i.value,setFieldError:l=>{A(e,"error"),s.innerText=l},focus:()=>{setTimeout(()=>{i.focus()})}}}function gh(n){const t=document.getSelection();if(!t)return!0;const e=t.focusNode;if(!e)return!0;const o=t.focusOffset,r=e.childNodes[o];if(!r)return!0;if(r instanceof HTMLElement){const i=r.tagName.toLowerCase();if(r===n.input.inputElement)return!0;if(i==="input"||i==="textarea")return!1}return!0}const PB=B("ui-base");class jB{constructor(t,e){h(this,"menu");h(this,"currentText","");h(this,"handleClick",(t,e)=>{this.options.onClickItem(this,e)});h(this,"handleClose",()=>{gh(this.editor)&&this.editor.focus()});h(this,"handleKeydown",t=>{this.menu.handleDocumentKeydown(t)});this.editor=t,this.options=e,this.menu=new nr([],void 0,{id:e.id}),this.menu.addListener("click",this.handleClick),this.menu.addListener("close",this.handleClose)}setItems(t){if(this.menu.updateItems(t),t.length>0){const e=t.find(o=>o.type!=="section"&&o.type!=="separator");e&&this.menu.selectItem(e.id)}}async popup(t,e,o){var a,u;if(((u=(a=this.options).onShow)==null?void 0:u.call(a,this,t,e,o))===!1)return;this.options.showLoading&&this.showLoading();const r=this.editor.getBlockByIndex(t,e);if(!It(this.editor.rootContainer,r)||W(this.editor,r)<o)return;const i=io(this.editor,r,At(this.editor,r,o));if(i.length===0)return;const s=i[0],l=co(this.editor,r,"editor-auto-suggest-menu",s);this.menu.manualShow(l),this.options.placeholder&&this.showPlaceholder();const c=await this.options.queryItems(this,"");this.highlightText(""),this.setItems(c)}showLoading(){!this.options.showLoading||(this.options.loadingElement?this.setItems([{id:"loading",name:"",element:this.options.loadingElement,states:["disabled"]}]):this.setItems([{id:"loading",name:"loading",states:["disabled"]}]))}showPlaceholder(){this.setItems([{id:"placeholder",name:"enter text to search",states:["disabled"]}])}showNoResultMessage(t){if(this.options.noResultMessage){const e={name:"",id:"placeholder",states:["disabled"]};typeof this.options.noResultMessage=="string"?e.name=this.options.noResultMessage:(this.options.noResultMessage instanceof HTMLElement||typeof this.options.noResultMessage=="function")&&(e.element=this.options.noResultMessage),this.setItems([e])}else this.setItems([{id:"placeholder",name:T.t("search.emptyTips"),states:["disabled"]}])}close(){this.menu.close()}get isVisible(){return this.menu.isVisible}destroy(){this.menu.close(),this.menu.removeAllListeners(),this.menu.destroy()}async handleSearchText(t){this.currentText=t;const e="auto-suggest";try{await qe.lock(e),this.showLoading();const o=this.currentText,r=await this.options.queryItems(this,o);if(this.currentText===o&&(this.currentText=""),r.length===0){this.showNoResultMessage(t);return}this.setItems(r),this.options.highlight&&this.highlightText(o.replace(/^\s+|\s+$/g,""))}finally{qe.release(e)}}highlightText(t){PB.debug(`highlight menu text: ${t}`);const e=this.menu.content,o=(i,s)=>{if(!s)return i;let l="";const c=s.length,a=s.toLocaleLowerCase();let u=0;for(u=0;u<=i.length-c;u){let f=i.substring(u,u+c);if(f.toLocaleLowerCase()===a){u+=c;const m=i.charAt(u);let C=!1;f.endsWith(" ")&&(C=!0,f=f.trimEnd()),l+=`<span class="highlight">${f}${m===" "||C?"&nbsp":""}</span>`}else l+=i.charAt(u),u++}return u<i.length&&(l+=i.substring(u)),l},r=i=>{if(nt(i,"text")){const s=i.textContent;if(!s)return;const l=o(s,t);i.innerHTML=l;return}Array.from(i.children).forEach(r)};r(e)}}const ph=B("auto-suggest-menu");class Ch{constructor(t,e){h(this,"menu");h(this,"anchor",null);h(this,"handleSelectionChanged",t=>{var o,r;if(!((o=this.menu)!=null&&o.isVisible))return;const e=t.selection.range.start;if(e.isSimple()&&e.blockId===((r=this.anchor)==null?void 0:r.blockId)&&e.offset>=this.anchor.offset){const i=t.getBlockById(e.blockId);if(bt(be(he(t,i),e.offset).left).startsWith(this.anchor.leftText))return}this.menu.close()});h(this,"deleteTrigger",()=>{const t=this.editor,e=t.selection.range.start;if(!e.isSimple()||!this.anchor)return!1;const{blockId:o,offset:r}=e,i=t.getBlockById(o),s=bt(Yl(t,i,r));if(d(ph,this.anchor,"no anchor"),!s.startsWith(this.anchor.leftText))return!1;const l=this.anchor.offset-this.anchor.trigger.length,c=r-l;return t.selection.selectBlock(i,l),c&&(t.deleteTextFromBlock(i,l,c),this.anchor.offset-=this.anchor.trigger.length),this.anchor.trigger.length||this.menu.close(),!0});h(this,"onShow",(t,e,o,r)=>{var i;if((i=this.options)!=null&&i.onShow)return this.options.onShow(this,e,o,r)});h(this,"onClickItem",(t,e)=>{!this.anchor||(this.options.autoDeleteTrigger&&this.deleteTrigger(),this.options.onClickItem(this,e,this.anchor))});h(this,"queryItems",(t,e)=>this.options.queryItems(this,e));h(this,"renderMenuItem",(t,e)=>{var r,i;return(i=(r=this.options).renderMenuItem)==null?void 0:i.call(r,this,e)});this.editor=t,this.options=e,this.menu=new jB(t,{id:e.id,showLoading:e.showLoading,loadingElement:e.loadingElement,placeholder:e.placeholder,noResultMessage:e.noResultMessage,highlight:e.highlight,onShow:this.onShow,onClickItem:this.onClickItem,queryItems:this.queryItems,renderMenuItem:this.renderMenuItem}),t.input.addHandler(this),t.addListener("selectionChanged",this.handleSelectionChanged)}handleBeforeKeyDown(t,e){var o;return!((o=this.menu)!=null&&o.isVisible)||ad(e.key)?!1:Em(e)&&!jo(e)?(setTimeout(()=>{this.resetItems()}),!1):dd(e)?(this.menu.close(),!0):(this.menu.handleKeydown(e),!0)}popup(t,e,o,r){this.anchor={blockId:q(t),offset:e,leftText:o,trigger:r};const i=U(H(t)),s=J(t);this.menu.popup(i,s,e)}handleAfterInsertText(t,e,o,r,i){var u;const s=t.selection.range.start;if(!s.isSimple()||e==="root"&&o===0)return!1;const{blockId:l,offset:c}=s,a=t.getBlockByIndex(e,o);if(q(a)!==l)return!1;if((u=this.menu)!=null&&u.isVisible)this.resetItems();else if(this.options.trigger.indexOf(i)!==-1){if(r>0&&this.options.needSpaceBeforeTrigger&&t.getBlockString(a)[r-1]!==" ")return!1;const f=bt(Yl(t,a,c));this.popup(a,c,f,i)}return!1}handleUpdateCompositionText(t,e,o,r,i){var a;const s=t.selection.range.start;if(!s.isSimple())return!1;const{blockId:l}=s,c=t.getBlockByIndex(e,o);return q(c)!==l||(a=this.menu)!=null&&a.isVisible&&this.resetItems(),!1}resetItems(){var l;if(!((l=this.menu)!=null&&l.isVisible))return;const t=this.editor,e=t.selection.range.start;if(!e.isSimple())return;const{blockId:o,offset:r}=e,i=t.getBlockById(o),s=bt(Yl(t,i,r));if(d(ph,this.anchor,"no anchor"),s.startsWith(this.anchor.leftText)){const c=s.substring(this.anchor.leftText.length);ph.debug(`search text: ${c}`),this.menu.handleSearchText(c)}}destroy(){var t;this.editor.input.removeHandler(this),this.editor.removeListener("selectionChanged",this.handleSelectionChanged),(t=this.menu)==null||t.destroy()}}function HB(){const n={};for(let t=1;t<=8;t++)n[`heading-${t}`]={shortcut:`/h${t}`};return n}const FB={"insert-hr":{shortcut:"/hr"},"insert-uml":{shortcut:"/uml"},"insert-table":{shortcut:"/table"},"insert-image":{shortcut:"/image"},"insert-code":{shortcut:"/code"},"insert-link":{shortcut:"/link"},"insert-drawio":{shortcut:"/uml"},"insert-video":{shortcut:"/video"},"insert-audio":{shortcut:"/audio"},"insert-math":{shortcut:"/math"},"insert-webPage":{shortcut:"/web"},"insert-bilibili":{shortcut:"/bilibili"},"insert-youku":{shortcut:"/youku"},"insert-figma":{shortcut:"/figma"},"insert-modao":{shortcut:"/modao"},"insert-tencent":{shortcut:"/tencent"},"insert-unordered":{shortcut:"/bl"},"insert-ordered":{shortcut:"/nu"},"insert-checkbox":{shortcut:"/todo"},"insert-quote":{shortcut:"/quote"},...HB()};function me(n){var t;return(t=FB[n])==null?void 0:t.shortcut}function zB(n){var t;return(t=n.subText)!=null?t:""}const xn=B("table-dom");function wo(n){return`${q(n)}_scroll`}function jt(n){const t=n.querySelector("div[data-type=table-content] >table");return d(xn,t instanceof HTMLTableElement,"invalid table"),t}function Tn(n,t){const o=n.getCustom(wo(t)).contentElement.firstElementChild;d(xn,o instanceof HTMLElement,"invalid table content");let r=o.querySelector(":scope >div[data-type=table-tools]");return r||(r=b("div",[],o),r.setAttribute("data-type","table-tools")),d(xn,r,"no table tools"),r}function p5(n){const t=[];return Array.from(n.rows).forEach(e=>{t.push(...Array.from(e.cells))}),t}function ys(n){const t=n.querySelector(":scope div[data-type=editor-container]");return d(xn,t,"no child container in cell"),t}function UB(n){const o=p5(n).map(r=>{const i=ys(r),s=U(i),l=r.colSpan,c=r.rowSpan;return`${s}/${l}/${c}`}).join();return Ti.default(o)}function Ht(n){return ot(n)==="table"}function bh(n){const t=H(n);if(pt(t))return null;const e=F(t);return d(xn,e,"no parent block"),Ht(e)?t:bh(e)}function Me(n){if(Ht(n))return n;const t=H(n);if(pt(t))return null;const e=F(t);return d(xn,e,"no parent block"),Ht(e)?e:Me(e)}function VB(n,t){const e=n.querySelector("colgroup");d(xn,e,"no colgroup");const o=e.children[t];return d(xn,o,"no col"),d(xn,o instanceof HTMLTableColElement,`invalid col: ${o.tagName}`),o}function C5(n){try{return jt(n),!0}catch{return!1}}function qB(n){return Rt(n).querySelector(":scope > .block-helper")}function b5(n){const t=F(n.contentElement);d(xn,t,"no block");const e=qB(t);if(e){const o=Math.min(n.contentElement.offsetLeft,n.rootElement.scrollLeft),r=t.getBoundingClientRect().width;e.style.right=`${o+r}px`}}const Re=B("doc-table-grid");class WB{constructor(t){h(this,"_cells",[]);for(let e=0;e<t;e++)this._cells.push(void 0)}cols(){return this._cells.length}setCell(t,e){d(Re,t>=0&&t<this.cols(),`set cell, invalid col: ${t}`),this._cells[t]=e}getCell(t){d(Re,t>=0&&t<this.cols(),`get cell, invalid col: ${t}`);const e=this._cells[t];return d(Re,e,"get cell, no cell"),e}getCellAllowEmpty(t){return d(Re,t>=0&&t<this.cols(),`get cell, invalid col, ${t}`),this._cells[t]}getNextNonVirtualCell(t){return this._cells.slice(t+1).find(e=>!e.virtual)}forEach(t){this._cells.forEach(t)}}class Ec{constructor(t){h(this,"_data");h(this,"_rows");this._data=t,this._rows=[];for(let e=0;e<this.rowCount;e++)this._rows.push(new WB(this.colCount));this.fillGrid(),d(Re,t.colsWidth,"no colsWidth"),d(Re,this.colCount===t.colsWidth.length,"invalid col count")}get rowCount(){return this._data.rows}get colCount(){return this._data.cols}getNextEmptyCell(t,e){let o=t,r=e;for(;;){if(o+=1,o===this.colCount&&(o=0,r+=1),r>=this.rowCount)return null;if(this._rows[r].getCellAllowEmpty(o)===void 0)return{col:o,row:r}}}fillGrid(){const t=this._data.children;d(Re,t,"no children");let e=0,o=0;t.forEach((r,i)=>{const s=this._data[`${r}_colSpan`]||1,l=this._data[`${r}_rowSpan`]||1;for(let a=0;a<l;a++)for(let u=0;u<s;u++)this._rows[o+a].setCell(e+u,{col:e,row:o,containerId:r,virtual:u!==0||a!==0,colSpan:s,rowSpan:l});const c=this.getNextEmptyCell(e,o);c?(e=c.col,o=c.row):d(Re,i===t.length-1,`invalid table data, no next empty cell: ${JSON.stringify(this._data)}`)}),this._rows.forEach(r=>{r.forEach(i=>{d(Re,i,"no cell"),d(Re,i.containerId,"no containerId")})})}getCell(t){const{col:e,row:o}=t,r=this._rows[o];d(Re,r,`get cell, no row: ${o}`);const i=r.getCell(e);return d(Re,i,`get cell, no cell: ${e}`),i}getRow(t){const e=this._rows[t];return d(Re,e,`get row, no row: ${t}`),e}forEach(t){this._rows.forEach(t)}}const Ic=B("table-data");function GB(n){const t=n.firstElementChild;return d(Ic,t,"no child element for cell"),d(Ic,bn(t),"cell first child is not a container"),d(Ic,Ye(t),"cell first child is not a container"),t}function ZB(n){const t=F(n);d(Ic,t,"no parent block for table");const e=[],o={};Array.from(n.rows).forEach(l=>{Array.from(l.cells).forEach(c=>{const a=GB(c),u=U(a);e.push(u),(c.colSpan>1||c.rowSpan>1)&&(o[`${u}_colSpan`]=c.colSpan,o[`${u}_rowSpan`]=c.rowSpan)})});const r=n.rows.length,i=Array.from(n.rows[0].cells).map(l=>l.colSpan).reduce((l,c)=>l+c,0);return{id:q(t),type:ot(t),rows:r,cols:i,children:e,colsWidth:Array(i).fill(100),...o}}function or(n){return new Ec(n)}function YB(n){return or(ZB(n))}const Gt=B("table-grid"),QB=60;class KB{constructor(t,e){h(this,"containerId");h(this,"row");h(this,"col");h(this,"colSpan");h(this,"rowSpan");h(this,"virtual");h(this,"table");this.table=t,this.containerId=e.containerId,this.row=e.row,this.col=e.col,this.colSpan=e.colSpan,this.rowSpan=e.rowSpan,this.virtual=e.virtual}get cell(){const e=this.container.closest("td");return d(Gt,e,"no parent cell for child container"),e}get container(){const t=this.table.querySelectorAll(`[data-container-id=${this.containerId}]`);d(Gt,t.length===1,"containers !== 1"),d(Gt,bn(t[0]),"not a container");const e=t[0];return d(Gt,Ye(e),"not a child container"),e}}class JB{constructor(t,e){h(this,"_cells",[]);e.forEach(o=>{this._cells.push(new KB(t,o))})}get cells(){return this._cells}getCell(t){return d(Gt,t<this._cells.length,"get cell, invalid col"),this._cells[t]}getNextNonVirtualCell(t){return this._cells.slice(t+1).find(e=>!e.virtual)}getSpannedCell(){return this._cells.find(t=>t.virtual||t.colSpan>1||t.rowSpan>1)}}const Sf=class{constructor(t){h(this,"_rows",[]);this.table=t,YB(t).forEach(r=>{this._rows.push(new JB(t,r))});const o=this.colCount;this._rows.forEach(r=>{d(Gt,r.cells.length===o,"row.cells.length !== colCount")})}get rowCount(){return this._rows.length}get colCount(){return this._rows.length===0?0:(d(Gt,this.rowCount>0,"rowCount <= 0"),this.getRow(0).cells.length)}getRow(t){return this._rows[t]}getCell(t){const e=this.getRow(t.row);return d(Gt,e,"no row"),e.getCell(t.col)}getCellContainer(t){return this.getCell(t).container}getFirstCellContainer(){return this.getCellContainer({row:0,col:0})}getLastCellContainer(){const t=this.rowCount-1,e=this.colCount-1;return this.getCellContainer({row:t,col:e})}getColumnCells(t){d(Gt,t>=0&&t<this.colCount,"colIndex out of range");const e=this.rowCount,o=[];for(let r=0;r<e;r++){const i=this.getCell({row:r,col:t});o.push(i)}return o}toRealCells(t){const e=[];return t.forEach(o=>{const r=this.getRealCell(o);e.findIndex(i=>i.containerId===r.containerId)===-1&&e.push(r)}),e}getColumnRealCells(t){const e=this.getColumnCells(t);return this.toRealCells(e)}getRowRealCells(t){const e=this.getRow(t).cells;return this.toRealCells(e)}getFirstSpannedCell(t){d(Gt,t>=0&&t<this.colCount,"colIndex out of range");const e=this.rowCount;for(let o=0;o<e;o++){const r=this.getCell({row:o,col:t});if(r.virtual||r.colSpan>1||r.rowSpan>1)return r}}getRealCell(t){const e=this.getCell(t);if(!e.virtual)return e;const o=this.getCellById(e.containerId);return d(Gt,!o.virtual,"found a virtual cell"),o}getColumnSpannedRange(t){const e=this.getColumnRealCells(t);let o=1e5,r=-1;return e.forEach(i=>{o=Math.min(i.col,o),r=Math.max(i.col+i.colSpan-1,r)}),d(Gt,o<=r,"min > max"),d(Gt,o>=0,"min < 0"),d(Gt,r<this.colCount,"max >= colCount"),[o,r]}getRowSpannedRange(t){const e=this.getRowRealCells(t);let o=1e5,r=-1;return e.forEach(i=>{o=Math.min(i.row,o),r=Math.max(i.row+i.rowSpan-1,r)}),d(Gt,o<=r,"min > max"),d(Gt,o>=0,"min < 0"),d(Gt,r<this.rowCount,"max >= rowCount"),[o,r]}getSpannedRange(t,e){const o=Math.min(t.row,e.row),r=Math.max(t.row,e.row),i=Math.min(t.col,e.col),s=Math.max(t.col,e.col),l=[];for(let C=o;C<=r;C++)for(let k=i;k<=s;k++)l.push(this.getCell({row:C,col:k}));const c=this.toRealCells(l);let a=1e4,u=1e4,f=-1,m=-1;return c.forEach(C=>{u=Math.min(C.col,u),a=Math.min(C.row,a),m=Math.max(C.col+C.colSpan-1,m),f=Math.max(C.row+C.rowSpan-1,f)}),[{row:a,col:u},{row:f,col:m}]}getAllCells(){return this.getCells({col:0,row:0},{col:this.colCount-1,row:this.rowCount-1})}sub(t,e){const o=[];for(let r=t.row;r<=e.row;r++){const i=[];for(let s=t.col;s<=e.col;s++){const l=this.getCell({row:r,col:s});i.push(l)}o.push(i)}return o}getAllContainers(){return this.getAllCells().map(e=>e.container)}getCells(t,e){const o=[],r=this.getSpannedRange(t,e),i=r[0],s=r[1],l=Math.min(i.row,s.row),c=Math.max(i.row,s.row),a=Math.min(i.col,s.col),u=Math.max(i.col,s.col);for(let f=l;f<=c;f++)for(let m=a;m<=u;m++){const C=this.getCell({row:f,col:m});C.virtual||o.push(C)}return o}map(t){const e=[];for(let o=0;o<this.rowCount;o++){const r=[];for(let i=0;i<this.colCount;i++){const s=this.getCell({row:o,col:i});r.push(t(s))}e.push(r)}return e}getBottomCell(t){const e=this.rowCount;let o=t,r=t.row;for(;o.containerId===t.containerId;){if(r+=1,r>=e)return null;o=this.getCell({row:r,col:t.col})}return this.getRealCell(o)}getTopCell(t){let e=t,o=t.row;for(;e.containerId===t.containerId;){if(o-=1,o<0)return null;e=this.getCell({row:o,col:t.col})}return this.getRealCell(e)}get cells(){let t=[];return this._rows.forEach(e=>{t=t.concat(e.cells)}),t}getVirtualCellContainersGrid(){return this.map(t=>t.containerId)}static virtualCellContainersGridToChildren(t){const e=t,o=[];return e.forEach(r=>{r.forEach(i=>{o.indexOf(i)===-1&&o.push(i)})}),o}getCellById(t){const o=this.cells.find(r=>r.containerId===t);return d(Gt,o,"cell not found"),o}getCellByCellElement(t){const e=ys(t);return this.getCellByContainerId(U(e))}getCellByContainerId(t){return this.getCellById(t)}static fromTable(t){const e=UB(t),o=this.caches.getSync(e,()=>(Gt.debug("create table grid"),new Sf(t)));return o.table!==t?(this.caches.delete(e),this.fromTable(t)):o}static fromBlock(t){return this.fromTable(jt(t))}};let et=Sf;h(et,"caches",new om(QB));function xc(n,t){Object.entries(n).forEach(([e])=>{e.startsWith(`${t}/`)&&delete n[e]})}const XB=B("table-selection-range");function an(n,t,e){var I,M,R,$;const o=et.fromBlock(n),r=t,i=e,s=o.getCellByContainerId(r.childContainerId),l=o.getCellByContainerId(i.childContainerId),c=r.custom,a=i.custom,u=(I=c==null?void 0:c.rowIndex)!=null?I:s.row,f=(M=c==null?void 0:c.colIndex)!=null?M:s.col,m=(R=a==null?void 0:a.rowIndex)!=null?R:l.row+l.rowSpan-1,C=($=a==null?void 0:a.colIndex)!=null?$:l.col+l.colSpan-1,k=Math.min(u,m),w=Math.max(u,m),y=Math.min(f,C),S=Math.max(f,C);return{fromRow:k,toRow:w,fromCol:y,toCol:S}}function kh(n,t){const e=new Set,o=new Set,r=n.selection.range;if(!r.isSimple()&&r.start.blockId===q(t)){const i=et.fromBlock(t),{start:s,end:l}=r;d(XB,!s.isSimple()&&!l.isSimple(),"invalid range");const{fromCol:c,toCol:a,fromRow:u,toRow:f}=an(t,s,l);if(u===0&&f===i.rowCount-1)for(let m=c;m<=a;m++)o.add(m);if(c===0&&a===i.colCount-1)for(let m=u;m<=f;m++)e.add(m)}return{selectedRows:e,selectedColumns:o}}const zr=B("delete-columns");function k5(n,t,e){const{start:o,end:r}=e;if(o.blockId!==r.blockId||e.isSimple()||n.getBlockById(o.blockId)!==t||ot(t)!=="table")return!1;const{fromRow:s,toRow:l}=an(t,e.start,e.end),c=et.fromBlock(t);return s===0&&l===c.rowCount-1}function vh(n){var M;const t=n.getEditor(),e=t.getBlockById(n.start.blockId);if(!k5(t,e,n))return;if(n.isSimple()){t.deleteBlock(e);return}const{fromCol:o,toCol:r}=an(e,n.start,n.end),i=et.fromBlock(e);if(o===0&&r===i.colCount-1){t.deleteBlock(e);return}const s=new Set,l=i.map(R=>R.containerId);for(let R=0;R<l.length;R++){const $=l[R];for(let Z=o;Z<=r;Z++){const rt=$[Z];s.add(rt)}$.splice(o,r-o+1)}const c=new Set(l.flat()),a=new Set(Array.from(s).filter(R=>!c.has(R))),u=r-o+1,f=new Map,m=new Map;s.forEach(R=>{if(a.has(R))return;const $=i.getCellByContainerId(R);if(d(zr,$.colSpan>1,"invalid effected cell, colSpan === 1"),$.col<o){d(zr,c.has(R),"invalid effected cell, not exists");let yt=$.col+$.colSpan-1;yt>r&&(yt=r);const le=yt-o+1,eo=$.colSpan-le;f.set(R,eo);return}d(zr,$.col<=r,"invalid effected cell, col > endCol");const Z=$.col,rt=$.col+$.colSpan-1,st=$.col-o,mt=rt-Z+1-u+st;d(zr,mt>0,"invalid effected cell, newSpanned <= 0");const ut=yn(t.doc);m.set(R,{newContainerId:ut,colSpan:mt})});for(let R=0;R<l.length;R++){const $=l[R];for(let Z=o;Z<$.length;Z++){const rt=$[Z],st=m.get(rt);st&&($[Z]=st.newContainerId)}}const C=Y.default(t.getBlockData(e));C.colsWidth.splice(o,r-o+1),a.forEach(R=>{xc(C,R)}),f.forEach((R,$)=>{d(zr,R>=1,"invalid modified colSpan, colSpan < 1"),R===1?C[`${$}_colSpan`]=void 0:C[`${$}_colSpan`]=R}),m.forEach((R,$)=>{xc(C,$);const{newContainerId:Z,colSpan:rt}=R;d(zr,rt>=1,"invalid newContainerData, colSpan < 1"),rt>1&&(C[`${Z}_colSpan`]=rt);const st=i.getCellByContainerId($).rowSpan;st>1&&(C[`${Z}_rowSpan`]=st)});const w=(M=l[0][o])!=null?M:l[0][o-1],y=t.getChildContainerData(w)[0],S=et.virtualCellContainersGridToChildren(l),I={...C,cols:C.cols-u,children:S};or(I),t.undoManager.runInGroup(()=>{t.updateBlockData(e,I,At(t,y.id,0)),t.deleteChildContainers(Array.from(a)),t.deleteChildContainers(Array.from(m.keys()))})}const Ur=B("delete-rows");function v5(n,t,e){const{start:o,end:r}=e;if(o.blockId!==r.blockId||e.isSimple()||n.getBlockById(o.blockId)!==t||ot(t)!=="table")return!1;const{fromCol:s,toCol:l}=an(t,e.start,e.end),c=et.fromBlock(t);return s===0&&l===c.colCount-1}function yh(n){const t=n.getEditor(),e=t.getBlockById(n.start.blockId);if(!v5(t,e,n))return;if(n.isSimple()){t.deleteBlock(e);return}const{fromRow:o,toRow:r}=an(e,n.start,n.end),i=et.fromBlock(e);if(o===0&&r===i.rowCount-1){t.deleteBlock(e);return}const s=new Set,l=i.map(I=>I.containerId);for(let I=r;I>=o;I--)l[I].forEach(R=>s.add(R)),l.splice(I,1);const c=new Set(l.flat()),a=new Set(Array.from(s).filter(I=>!c.has(I))),u=r-o+1,f=new Map,m=new Map;s.forEach(I=>{if(a.has(I))return;const M=i.getCellByContainerId(I);if(d(Ur,M.rowSpan>1,"invalid effected cell, rowSpan === 1"),M.row<o){d(Ur,c.has(I),"invalid effected cell, not exists");let mt=M.row+M.rowSpan-1;mt>r&&(mt=r);const ut=mt-o+1,yt=M.rowSpan-ut;f.set(I,yt);return}d(Ur,M.row<=r,"invalid effected cell, col > endCol");const R=M.row,$=M.row+M.rowSpan-1,Z=M.row-o,rt=$-R+1-u+Z;d(Ur,rt>0,"invalid effected cell, newSpanned <= 0");const st=yn(t.doc);m.set(I,{newContainerId:st,rowSpan:rt})});for(let I=o;I<l.length;I++){const M=l[I];for(let R=0;R<M.length;R++){const $=M[R],Z=m.get($);Z&&(M[R]=Z.newContainerId)}}const C=Y.default(t.getBlockData(e));a.forEach(I=>{xc(C,I)}),f.forEach((I,M)=>{d(Ur,I>=1,"invalid modified rowSpan, rowSpan < 1"),I===1?delete C[`${M}_rowSpan`]:C[`${M}_rowSpan`]=I}),m.forEach((I,M)=>{xc(C,M);const{newContainerId:R,rowSpan:$}=I;d(Ur,$>=1,"invalid newContainerData, rowSpan < 1"),$>1&&(C[`${R}_rowSpan`]=$);const Z=i.getCellByContainerId(M).colSpan;Z>1&&(C[`${R}_colSpan`]=Z)});const k=l[o]?l[o][0]:l[o-1][0],w=t.getChildContainerData(k)[0],y=et.virtualCellContainersGridToChildren(l),S={...C,rows:C.rows-u,children:y};or(S),t.undoManager.runInGroup(()=>{t.updateBlockData(e,S,At(t,w.id,0)),t.deleteChildContainers(Array.from(a)),t.deleteChildContainers(Array.from(m.keys()))})}const ws=B("table-range");function Tc(n){d(ws,!n.isSimple(),"must be complex selection range");const{anchor:t,focus:e}=n;d(ws,!t.isSimple(),"invalid start pos type"),d(ws,!e.isSimple(),"invalid end pos type");const o=n.getEditor();d(ws,t.blockId===e.blockId,"invalid range, not same block");const r=o.getBlockById(t.blockId);d(ws,ot(r)==="table","invalid block type, not a table block");const i=jt(r),s=et.fromTable(i),l=s.getCellByContainerId(t.childContainerId),c=s.getCellByContainerId(e.childContainerId),a=Math.min(l.row,c.row),u=Math.max(l.row,c.row),f=Math.min(l.col,c.col),m=Math.max(l.col,c.col),C=s.getCell({row:a,col:f}),k=s.getCell({row:u,col:m});return{editor:o,block:r,table:i,startCell:C,endCell:k,startRow:a,startCol:f,endRow:u,endCol:m}}const wh=B("split-cell");function Bh(n,t,e){const o=et.fromBlock(t),r=o.getRealCell(e);d(wh,!r.virtual,"should not split virtual cell"),d(wh,r.colSpan>1||r.rowSpan>1,"cell does not has span data");const i=o.getVirtualCellContainersGrid();for(let f=0;f<r.rowSpan;f++)for(let m=0;m<r.colSpan;m++){if(f===0&&m===0)continue;const C=f+r.row,k=m+r.col,w=yn(n.doc);i[C][k]=w}const s=n.getBlockData(t),l=Y.default(s);l[`${r.containerId}_colSpan`]=null,l[`${r.containerId}_rowSpan`]=null,l.children=et.virtualCellContainersGridToChildren(i);const a=n.getChildContainerData(r.containerId)[0];d(wh,a,"no child block");const u=At(n,a.id,0);or(l),n.updateBlockData(t,l,u)}function tE(n,t,e){e.forEach(o=>{const r=et.fromBlock(t).getCell(o);(r.virtual||r.colSpan>1||r.rowSpan>1)&&Bh(n,t,o)})}function y5(n,t,e){if(e.isSimple())return!1;const{start:o,end:r}=e;if(o.blockId!==r.blockId||n.getBlockById(o.blockId)!==t||ot(t)!=="table")return!1;const{startCell:s,endCell:l}=Tc(e);return!(s.cell!==l.cell||s.colSpan===1&&s.rowSpan===1)}function Eh(n){const{editor:t,block:e,startRow:o,startCol:r,endRow:i,endCol:s}=Tc(n),l=[];for(let c=o;c<=i;c++)for(let a=r;a<=s;a++)l.push({row:c,col:a});return tE(t,e,l),!0}const Vr=B("merge-cells");function w5(n,t,e){if(e.isSimple())return!1;const{start:o,end:r}=e;if(o.blockId!==r.blockId||n.getBlockById(o.blockId)!==t||ot(t)!=="table")return!1;const{startCell:s,endCell:l}=Tc(e);return s.cell!==l.cell}function B5(n){const t=Tc(n),e=t.endCell,o=e.row+e.rowSpan-1,r=e.col+e.colSpan-1,i=q(t.block),s=t.editor;Eh(n);const l=s.getBlockById(i),c=jt(l),{startRow:a,startCol:u}=t,f=Y.default(s.getBlockData(l));d(Vr,f.children,"no table children");const m=et.fromTable(c),C=[];for(let mt=a;mt<=o;mt++)for(let ut=u;ut<=r;ut++){const yt=m.getCell({row:mt,col:ut});d(Vr,!yt.virtual,"cell is virtual"),C.push(yt)}d(Vr,C.length>0,"no selected cells");const k=C[0],w=C.slice(1),y=m.getCellByContainerId(k.containerId).container,S=[];w.forEach(mt=>{const ut=m.getCellByContainerId(mt.containerId).container,yt=U(ut);if(!Sd(s,ut)){const le=$0(s,yt);s.insertDocAt(y,Ge(y),le)}S.push(yt)});const I=U(y),M=r-u+1,R=o-a+1;f[`${I}_colSpan`]=M,f[`${I}_rowSpan`]=R,S.forEach(mt=>{d(Vr,f.children,"no table children");const ut=f.children.indexOf(mt);d(Vr,ut>0,"no deleted container"),f.children.splice(ut,1)});const $=f,rt=s.getChildContainerData(I)[0];d(Vr,rt,"no child block");const st=At(s,rt.id,0);or($),s.updateBlockData(l,$,st),s.deleteChildContainers(S)}const Ih=10,eE=["table/merge-cells","table/split-cell","table/insert-column","table/insert-row","table/delete-rows","table/delete-columns","table/delete"];class xh{constructor(){h(this,"id","TableBlockCommandProvider")}getAvailableCommands(t,e,o){if(ot(e)!=="table")return[];const r={blockId:q(e),blockKind:Qe(t,e),blockType:ot(e)},i=[];w5(t,e,o)&&i.push({id:"table/merge-cells",name:T.t("table.mergeCell"),icon:zw,groupIndex:Ih,...r}),y5(t,e,o)&&i.push({id:"table/split-cell",name:T.t("table.splitCell"),icon:Uw,groupIndex:Ih,...r});const s=k5(t,e,o),l=v5(t,e,o);return s&&l&&i.push({id:"table/delete",name:T.t("table.deleteTable"),icon:Vw,groupIndex:Ih,...r}),i}executeCommand(t,e,o,r,i,s){return ot(e)!=="table"||!new Set(eE).has(r.id)?!1:r.id==="table/merge-cells"?(B5(o),!0):r.id==="table/split-cell"?(Eh(o),!0):r.id==="table/delete-columns"?(vh(o),!0):r.id==="table/delete-rows"?(yh(o),!0):r.id==="table/delete"?(t.deleteBlock(e),!0):!1}}var E5=(n=>(n.COL_TITLE_TABLE="col-title-table",n.COL_TITLE_ITEM="col-title-item",n.STRIPE_STYLE_TABLE="stripe-style-table",n.NO_BORDER="table-no-border",n))(E5||{});const Th=6,Bs=20,Sh="table-cell-menu-btn";function nE(n,t){if(!n.isBlockWritable(t))return;const o={...Y.default(n.getBlockData(t)),hasColTitle:!0};n.updateBlockData(t,o)}function oE(n,t){if(!n.isBlockWritable(t))return;const o={...Y.default(n.getBlockData(t)),hasColTitle:!1};n.updateBlockData(t,o)}function rE(n,t){if(!n.isBlockWritable(t))return;const o={...Y.default(n.getBlockData(t)),hasRowTitle:!0};n.updateBlockData(t,o)}function iE(n,t){if(!n.isBlockWritable(t))return;const o={...Y.default(n.getBlockData(t)),hasRowTitle:!1};n.updateBlockData(t,o)}function sE(n,t){if(!n.isBlockWritable(t))return;const o={...Y.default(n.getBlockData(t)),isStripeStyle:!0};n.updateBlockData(t,o)}function lE(n,t){if(!n.isBlockWritable(t))return;const o={...Y.default(n.getBlockData(t)),isStripeStyle:!1};n.updateBlockData(t,o)}function cE(n,t,e){if(!n.isBlockWritable(t))return;const r={...Y.default(n.getBlockData(t)),noBorder:!e};n.updateBlockData(t,r)}const Dh=B("get-selected-containers");function Lh(n,t,e,o){d(Dh,e.blockId===o.blockId,"only allow select in single table block"),d(Dh,q(t)===e.blockId,"only allow select in single table block");const r=et.fromBlock(t),i=r.getCellByContainerId(e.childContainerId),s=r.getCellByContainerId(o.childContainerId);if(e.custom===void 0||o.custom===void 0)return r.getCells(i,s).map(y=>r.getCellContainer(y));const{fromCol:l,toCol:c,fromRow:a,toRow:u}=an(t,e,o),f=new Set,m=[];return r.sub({row:a,col:l},{row:u,col:c}).forEach(k=>{k.forEach(w=>{const y=r.getCellByContainerId(w.containerId);y.col<l||y.row<a||y.col+y.colSpan-1>c||y.row+y.rowSpan-1>u||f.has(w.containerId)||(f.add(w.containerId),m.push(y.container))})}),m}function aE(n,t,e){d(Dh,t.blockId===e.blockId,"only allow select in single table block");const o=n.getBlockById(t.blockId);return Lh(n,o,t,e)}const rr=B("table-cell-dom");function dE(n,t,e){let o=n.getBlockById(e);for(;o;){const r=o.closest("td");d(rr,r,"no parent cell");const i=F(r);if(d(rr,i,"no parent block"),i===t)return r;o=i}return d(rr,!1,"filed to get cell by child block id"),null}function Gn(n,t,e){if(n.getBlockById(e.blockId)===t&&!e.isSimple())return d(rr,e.childContainerId,"block position must have childContainerId attribute"),e;const r=dE(n,t,e.blockId),i=U(ys(r));return wt(t,i)}function Mh(n,t){const e=n.selection.range,o=Gn(n,t,e.start),r=Gn(n,t,e.end);return an(t,o,r)}function I5(n,t,e,o){d(rr,Ht(t),"invalid table block");const r=Tn(n,t),i=()=>{const l=r.querySelector(".table-border-bar-container.top");d(rr,l,"no top border bar container"),l.querySelectorAll(".table-border-bar-cell.top").forEach(a=>{const u=parseInt(a.getAttribute("data-top-index")||"0",10);o.includes(u)?A(a,"danger"):z(a,"danger")})},s=()=>{const l=r.querySelector(".table-border-bar-container.left");d(rr,l,"no left border bar container"),l.querySelectorAll(".table-border-bar-cell.left").forEach(a=>{const u=parseInt(a.getAttribute("data-left-index")||"0",10);e.includes(u)?A(a,"danger"):z(a,"danger")})};i(),s()}function qr(n,t,e=!0,o){const i=et.fromBlock(t).map(u=>u),{fromCol:s,toCol:l,fromRow:c,toRow:a}=Mh(n,t);for(let u=0;u<i.length;u++){const f=i[u];for(let m=0;m<f.length;m++){const C=f[m],k=o?m>=s&&m+C.colSpan-1<=l:u>=c&&u+C.rowSpan-1<=a;e&&k?C.virtual||A(C.cell,"danger"):C.virtual||z(C.cell,"danger")}}}function Wr(n,t,e=!0,o){const r=new Set,i=new Set;if(!e){I5(n,t,Array.from(r),Array.from(i));return}const{fromCol:s,toCol:l,fromRow:c,toRow:a}=Mh(n,t);if(o)for(let u=s;u<=l;u++)i.add(u);else for(let u=c;u<=a;u++)r.add(u);I5(n,t,Array.from(r),Array.from(i))}function x5(n,t,e){const{fromCol:o,toCol:r,fromRow:i,toRow:s}=Mh(n,t),l=et.fromBlock(t);let c=null,a=null;return e?(c=l.getCell({col:o,row:0}),a=l.getCell({col:r,row:l.rowCount-1}),qt(n,{anchor:wt(t,c.containerId,{colIndex:o,rowIndex:0}),focus:wt(t,a.containerId,{colIndex:r,rowIndex:l.rowCount-1})})):(c=l.getCell({col:0,row:i}),a=l.getCell({col:l.colCount-1,row:s}),qt(n,{anchor:wt(t,c.containerId,{colIndex:0,rowIndex:i}),focus:wt(t,a.containerId,{colIndex:l.colCount-1,rowIndex:s})}))}function uE(n,t){const e=n.selection.range,o=Gn(n,t,e.start),r=Gn(n,t,e.end);return Lh(n,t,o,r)}const T5=["style-bg-color-0","style-bg-color-1","style-bg-color-2","style-bg-color-3","style-bg-color-4","style-bg-color-5","style-bg-color-6","style-bg-color-7","style-bg-color-8","style-bg-color-9","style-bg-color-10","style-bg-color-11","style-bg-color-12","style-bg-color-13"];function S5(n){return`style-bg-color-${n}`}function Es(n){return`${n}_background`}function hE(n,t,e){const o=jt(n),s=(e!=null?e:et.fromTable(o)).getCell(t).cell;for(let l=0;l<T5.length;l++){const c=T5[l];if(nt(s,c))return c}}function D5(n,t,e){if(!n.isBlockWritable(t))return;const o=n.selection.range,i={...Y.default(n.getBlockData(t))},s=Gn(n,t,o.start),l=Gn(n,t,o.end);if(o.isSimple()){const c=s.childContainerId;e===-1?i[Es(c)]=void 0:i[Es(c)]=S5(e)}else{const c=et.fromBlock(t),a=an(t,s,l),u=new Set;for(let f=a.fromRow;f<=a.toRow;f++)for(let m=a.fromCol;m<=a.toCol;m++){const C=c.getCell({row:f,col:m});!u.has(C.containerId)&&C.col>=a.fromCol&&C.row>=a.fromRow&&C.col+C.colSpan-1<=a.toCol&&C.row+C.rowSpan-1<=a.toRow&&(u.add(C.containerId),e===-1?i[Es(C.containerId)]=void 0:i[Es(C.containerId)]=S5(e))}}n.updateBlockData(t,i)}function fE(n,t,e){if(!n.isBlockWritable(t))return;const r={...Y.default(n.getBlockData(t)),chart:e};n.updateBlockData(t,r)}const L5=B("table-chart");function mE(n,t){const e=Tn(n,t);if(e){const o=e.querySelector(".editor-table-chart");if(o){const r=o.chartObject;r&&r.destroy(),o.remove()}}}async function gE(n,t){if(!n.isBlockWritable(t))return;if(!!!n.getBlockData(t).chart){mE(n,t);return}const r=[],i=et.fromBlock(t),s=["line","bar","pie","radar"];let l=i.getCell({row:0,col:0}).container.innerText.trim().toLowerCase();new Set(s).has(l)||(l=s[0]);const c=[];for(let w=1;w<i.colCount;w++)c.push(i.getCell({row:0,col:w}).container.innerText);for(let w=1;w<i.rowCount;w++){const y=i.getCell({row:w,col:0}),I=y.container.innerText,M=[];for(let le=1;le<i.colCount;le++){const eo=i.getCell({row:w,col:le}).container.innerText,ee=Number.parseFloat(eo)||0;M.push(ee)}let R;const $=hE(t,y,i);$?R=window.getComputedStyle(n.rootElement).getPropertyValue(`--${$}`).trim():R=window.getComputedStyle(n.rootElement).getPropertyValue("--background-color").trim();let[Z,rt,st,mt]=R?Ka.fromString(R).toRgbaArray():[];if(!Z&&!rt&&!st&&!mt){const le=(w-1)%n.options.colors.length;R=n.options.colors[le],[Z,rt,st,mt]=Ka.fromString(R).toRgbaArray()}const ut=R,yt=Ka.fromRgba([Z,rt,st,mt/3]).toHexString();r.push({label:I,data:M,borderColor:ut,backgroundColor:yt,borderWidth:2})}const a=Tn(n,t);let u=null,f=a.querySelector(".editor-table-chart");f?u=f.chartObject:f=b("div",["editor-table-chart"],a);const m=f;d(L5,m,"no chart container");const C=n.getComponentOptions("table"),k=(C==null?void 0:C.chartCdn)||"https://cdn.jsdelivr.net/npm/chart.js@2.9.4/dist/Chart.min.js";try{await $o(k,"editor-chartjs"),u&&l!==u.config.type&&(u.destroy(),u=null,Array.from(f.querySelectorAll(".editor-chartjs-canvas")).forEach(S=>{S.remove()}));const w=Ja.default({},{type:l,data:{datasets:r,labels:c},options:{onClick:()=>{n.selection.selectBlock(t,0,0)}}});if(u)Ja.default(u.config,w),u.update();else{const S=b("canvas",["editor-chartjs-canvas"],m).getContext("2d");u=new window.Chart(S,w),f.chartObject=u}}catch(w){L5.error(`failed to resolve chart cdn: ${JSON.stringify(w)}`)}}async function M5(n,t){await qe.lock("updateTableChart");try{await gE(n,t)}finally{qe.release("updateTableChart")}}const R5=Xt.default(M5,1e3);let A5=null;function Rh(n,t,e){if(A5!==t&&(R5.flush(),A5=t),e.updateNow){M5(n,t);return}R5(n,t)}function Ah(n,t){Ht(t)&&Rh(n,t,{updateNow:!1})}function pE(n,t){Ht(t)&&Rh(n,t,{updateNow:!0})}const je={SCROLL:"container-scroll-tool",COMMON:"container-border-shadow",RIGHT:"container-right-border-shadow",LEFT:"container-left-border-shadow",LAYOUT_SIGN:"container-layout-border-shadow",ACTIVE:"active"},Sc={SCROLL_BAR:"container-scrollbar",FIXED:"fixed"},Bo={SCROLL_CONTAINER:"scroll-container",TOOL:"container-scroll-tool",CONTAINER:"scroll-container-root",MAC:"mac",SCROLL_AREA:"scroll-area"};function Dc(n,t){return n.containers.get(t)}function O5(n){return n.closest(`.${Bo.SCROLL_CONTAINER}`)}function dn(n){return n.firstElementChild}function Ae(n){return n.closest(`.${Bo.CONTAINER}`)}function Is(n){const t=Ae(n);let e=t.querySelector(`:scope >.${Bo.TOOL}`);return e||(e=b("div",[Bo.TOOL],t)),e}function CE(n){return Ae(n).firstElementChild}function Lc(n){let t;return n instanceof HTMLElement?t=n.offsetWidth:t=Number.parseInt(getComputedStyle(n).width,10),n.getBoundingClientRect().width/t}function He(n,t){const e=Lc(n);return t/e}function xs(n){const t=window.getComputedStyle(n),e=Lc(n);return{paddingBottom:parseFloat(t.paddingBottom)*e,paddingTop:parseFloat(t.paddingTop)*e,paddingLeft:parseFloat(t.paddingLeft)*e,paddingRight:parseFloat(t.paddingRight)*e}}function Gr(n){const t=Lc(n);return{scrollLeft:n.scrollLeft*t,scrollWidth:n.scrollWidth*t,clientWidth:n.clientWidth*t,clientHeight:n.clientHeight*t}}function bE(n,t){const e=Lc(n);return n[t]*e}function Oh(n,t){const e=Ae(t),o=Dc(n,e),r=(o==null?void 0:o.safeRightSpace)||0,i=(o==null?void 0:o.safeLeftSpace)||0,l=(o==null?void 0:o.locatingContainer).getBoundingClientRect(),c=e.getBoundingClientRect(),a=c.width;let u=Math.floor(c.left-l.left-i);u<0&&(u=0);let f=l.right;f-=r;let m=f-c.right;return m<0&&(m=0),u=Math.round(u),m=Math.round(m),{originWidth:a,maxLeft:u,maxRight:m}}function kE(n,t){const e=Oh(n,t),{maxLeft:o}=e;t.style.marginLeft=`${He(t,0-o)}px`,t.style.paddingLeft=`${He(t,o)}px`}function vE(n,t){const e=Oh(n,t);t.style.marginRight=`${He(t,0-e.maxRight)}px`}function yE(n){if(n!==document.documentElement&&n!==document.body)return n.getBoundingClientRect();const t=0,e=0,o=document.documentElement.clientWidth,r=document.documentElement.clientHeight;return new DOMRect(t,e,o,r)}const _5=B("scroll-bar-handle"),wE=2;function Zr(n){const t=Is(n);let e=t.querySelector(`.${Sc.SCROLL_BAR}`);return e||(e=b("div",[Sc.SCROLL_BAR],t)),d(_5,e instanceof HTMLDivElement,"invalid child for container tools"),e.firstElementChild||b("div",[],e),e}function Mc(n,t){const e=O5(t),o=Zr(e),{scrollWidth:r,clientWidth:i}=Gr(e),{paddingLeft:s,paddingRight:l}=xs(t);e.style.marginLeft="",e.style.paddingLeft="",e.style.marginRight="";const c=Oh(n,e),{originWidth:a,maxRight:u}=c;vE(n,e),kE(n,e);const f=r-i;d(_5,o.firstElementChild instanceof HTMLDivElement,"invalid child for scroll bar"),o.style.width=`${He(e,a+u-s-l)}px`,o.firstElementChild.style.width=`${He(e,a+u+f-s-l)}px`}function BE(n,t){const e=dn(n),{paddingLeft:o}=xs(e);if(nt(t,"fixed")){const i=Ae(n).getBoundingClientRect();t.style.left=`${He(n,i.left+o)}px`}else t.style.left=`${He(n,o)}px`}function Yr(n,t){var I;const e=n.getParentScrollContainer(),o=yE(e),r=t.getBoundingClientRect(),i=Zr(t),s=i.getBoundingClientRect(),l=Dc(n,Ae(t)),c=(l==null?void 0:l.barFloatWindowBottom)||0,a=dn(t),{paddingTop:u,paddingBottom:f}=xs(a),{scrollWidth:m,clientWidth:C}=Gr(t),k=document.documentElement.clientHeight-c,w=o.top+Gr(e).clientHeight-k,y=k+Math.min(0,w);if(m>C&&r.top+u<y-s.height&&r.bottom>y-s.height+f&&!((I=l==null?void 0:l.isSetScale)!=null&&I.call(l))){A(i,Sc.FIXED);const M=w>0?c:0;i.style.bottom=`${Math.max(document.documentElement.clientHeight-o.bottom,0)+wE+M}px`}else z(i,Sc.FIXED),i.style.bottom=`${He(t,f-s.height)}px`;BE(t,i)}class EE{constructor(t,e){h(this,"intersectionObserver");h(this,"handleIntersection",t=>{t.forEach(e=>{this.containers.get(Ae(e.target))?(this.handleIntersectionEntry(e),this.callback(e)):this.intersectionObserver.unobserve(e.target)})});h(this,"handleIntersectionEntry",t=>{const e=t.target;Yr(this.scrollCore,e);const o=dn(e);Mc(this.scrollCore,o)});this.scrollCore=t,this.callback=e;const r={root:this.scrollCore.getParentScrollContainer(),rootMargin:"20px",threshold:0};this.intersectionObserver=new IntersectionObserver(this.handleIntersection,r)}get containers(){return this.scrollCore.containers}bind(t){this.unbind(t),this.intersectionObserver.observe(t)}unbind(t){this.intersectionObserver.unobserve(t)}destroy(){this.intersectionObserver.disconnect()}}const ir=B("container-scroll-shadow");function N5(n,t,e){const o=n,r=t.getBoundingClientRect(),i=e.getBoundingClientRect(),{paddingTop:s,paddingBottom:l}=xs(e);o.style.top=`${He(t,i.top-r.top+s)}px`,o.style.bottom=`${He(t,r.bottom-i.bottom+l)}px`}function $5(n,t){const e=n;t<24?e.style.width=`${(t/3).toFixed(2)}px`:e.style.width=""}function IE(n){const t=Is(n);d(ir,t,"no container tools");let e=t.querySelector(`.${je.LEFT}`);if(!e){const l=dn(n),c=[je.COMMON,je.LEFT];e=b("div",c,t),d(ir,e instanceof HTMLDivElement,"invalid child for container tools"),N5(e,n,l)}d(ir,e instanceof HTMLElement,"invalid child for container tools");const r=Ae(n).getBoundingClientRect(),i=n.getBoundingClientRect();e.style.left=`${He(n,i.left-r.left)}px`;const s=Gr(n).scrollLeft;d(ir,e instanceof HTMLDivElement,"invalid child for container tools"),$5(e,s),A(e,je.ACTIVE)}function xE(n){const t=Is(n);let e=t.querySelector(`.${je.RIGHT}`);if(!e){const u=dn(n),f=[je.COMMON,je.RIGHT];e=b("div",f,t),d(ir,e instanceof HTMLDivElement,"no div, create shadow failed"),N5(e,n,u)}d(ir,e instanceof HTMLElement,"");const r=Ae(n).getBoundingClientRect(),i=n.getBoundingClientRect();e.style.right=`${He(n,r.right-i.right)}px`;const{scrollWidth:s,scrollLeft:l,clientWidth:c}=Gr(n),a=s-l-c;d(ir,e instanceof HTMLDivElement,"no shadow element"),$5(e,a),A(e,je.ACTIVE)}function TE(n){const e=Is(n).querySelector(`.${je.LEFT}`);e&&z(e,je.ACTIVE)}function SE(n){const e=Is(n).querySelector(`.${je.RIGHT}`);e&&z(e,je.ACTIVE)}function Ts(n){const{scrollLeft:t,scrollWidth:e,clientWidth:o}=Gr(n),r=dn(n),{paddingLeft:i,paddingRight:s}=xs(r),l=bE(r,"offsetLeft");e-i<=o-s||e-i<=t+o-s?SE(n):xE(n),r&&t>=l+i?IE(n):TE(n)}class DE{constructor(t,e){h(this,"resizeObserver");h(this,"handleResizeEntry",t=>{const e=t.target,o=dn(e);Ts(e),Mc(this.scrollCore,o),Yr(this.scrollCore,e),this.callback(e)});h(this,"handleContentResize",t=>{t.forEach(e=>{this.containers.get(Ae(e.target))?this.handleResizeEntry(e):this.unbind(e.target)})});this.scrollCore=t,this.callback=e,this.resizeObserver=new ResizeObserver(this.handleContentResize)}get containers(){return this.scrollCore.containers}bind(t){this.unbind(t),this.resizeObserver.observe(t)}unbind(t){this.resizeObserver.unobserve(t)}destroy(){this.resizeObserver.disconnect()}}const P5=B("container-scroll-observer");class LE{constructor(t,e){h(this,"handleContentScroll",t=>{const e=t.target;d(P5,e instanceof Element,"invalid target for scroll event");const o=Zr(e);o.removeEventListener("scroll",this.handleScroll);const r=!0;this.fixScrollXPos(e,e.scrollLeft,r),this.bind(o),Ts(e),this.callback(e)});h(this,"handleScroll",t=>{const e=t.target;d(P5,e instanceof HTMLElement,"");const o=e.scrollLeft,r=!1,i=CE(e);this.unbindContentScroll(i),this.fixScrollXPos(i,o,r),this.bindContentScroll(i),Ts(i),this.callback(i)});h(this,"handlePrevent",t=>{t.stopPropagation()});h(this,"bindContentScrollCore",t=>{this.unbindContentScroll(t),t.addEventListener("scroll",this.handleContentScroll)});h(this,"unbindContentScroll",t=>{t.removeEventListener("scroll",this.handleContentScroll)});h(this,"bindContentScroll",Xt.default(this.bindContentScrollCore,300));h(this,"bind",Xt.default(this.bindCore,200));this.scrollCore=t,this.callback=e}fixScrollXPos(t,e,o){const r=Zr(t);o||(t.scrollLeft=e),o&&r.scrollLeft!==e&&(r.scrollLeft=e)}bindCore(t){this.unbind(t),t.addEventListener("scroll",this.handleScroll),t.addEventListener("mousedown",this.handlePrevent)}unbind(t){t.removeEventListener("scroll",this.handleScroll),t.removeEventListener("mousedown",this.handlePrevent)}}class ME{constructor(t){h(this,"scrollContainers",new Set);h(this,"handleParentContainerScroll",()=>{this.scrollContainers.forEach(t=>{Yr(this.scrollCore,t)})});h(this,"bindScrollContainer",t=>{const e=this.scrollContainers.size===0;this.scrollContainers.add(t),e&&this.eventTarget.addEventListener("scroll",this.handleParentContainerScroll)});h(this,"unbindScrollContainer",t=>{let e=!1;this.scrollContainers.has(t)&&(this.scrollContainers.delete(t),e=this.scrollContainers.size===0),e&&this.eventTarget.removeEventListener("scroll",this.handleParentContainerScroll)});this.scrollCore=t}get eventTarget(){const t=this.scrollCore.getParentScrollContainer();return t===document.documentElement?document:t}destroy(){this.eventTarget.removeEventListener("scroll",this.handleParentContainerScroll),this.scrollContainers.clear()}}const RE=B("scroll-wrap-resize-observer");class AE{constructor(t){h(this,"resizeObserver");h(this,"handleScrollWrapResize",t=>{t.forEach(e=>{this.containers.get(Ae(e.target))?this.handleScrollWrapResizeEntry(e):this.unbind(e.target)})});h(this,"handleScrollWrapResizeEntry",t=>{const e=t.target;d(RE,e instanceof HTMLElement,"invalid target for observer entry");const o=O5(e);Mc(this.scrollCore,e),Ts(o),Yr(this.scrollCore,o)});this.scrollCore=t,this.resizeObserver=new ResizeObserver(this.handleScrollWrapResize)}get containers(){return this.scrollCore.containers}bind(t){this.unbind(t),this.resizeObserver.observe(t)}unbind(t){this.resizeObserver.unobserve(t)}destroy(){this.resizeObserver.disconnect()}}class OE{constructor(t,e){h(this,"resizeObserver");h(this,"scrollContainersMap",new Map);h(this,"handleResizeEntry",t=>{t==null||t.forEach(e=>{const o=dn(e);Ts(e),Mc(this.scrollCore,o),Yr(this.scrollCore,e),this.callback(e)})});h(this,"handleResize",t=>{t.forEach(e=>{const o=this.scrollContainersMap.get(e.target);o!=null&&o.length&&this.handleResizeEntry(o)})});this.scrollCore=t,this.callback=e,this.resizeObserver=new ResizeObserver(this.handleResize)}bind(t){var r,i;const e=Ae(t),o=(r=Dc(this.scrollCore,e))==null?void 0:r.locatingContainer;this.scrollContainersMap.has(o)?(i=this.scrollContainersMap.get(o))==null||i.push(t):(this.scrollContainersMap.set(o,[t]),this.resizeObserver.observe(o))}unbind(t){var i,s;const e=Ae(t),o=(i=Dc(this.scrollCore,e))==null?void 0:i.locatingContainer;if(!o)return;const r=this.scrollContainersMap.get(o);this.scrollContainersMap.set(o,(r==null?void 0:r.filter(l=>l!==t))||[]),(s=this.scrollContainersMap.get(o))!=null&&s.length||(this.resizeObserver.unobserve(o),this.scrollContainersMap.delete(o))}destroy(){this.scrollContainersMap.clear(),this.resizeObserver.disconnect()}}const vz="";class _E extends Yt.TypedEmitter{constructor(e){super();h(this,"containerIntersectionObserver",null);h(this,"containerResizeObserver",null);h(this,"containerScrollObserver",null);h(this,"parentContainerScrollObserver",null);h(this,"scrollWrapResizeObserve",null);h(this,"locatingContainerResizeObserver",null);h(this,"isWindowEventBind",!1);h(this,"containers",new Map);h(this,"handleScrollContainerScroll",e=>{this.emit("scroll",this,e)});h(this,"handleResize",e=>{this.emit("resize",this,e)});h(this,"handleIntersection",e=>{const o=e.target,r=dn(o);e.isIntersecting?(this.load(),this.bindCore(o,r)):this.unbindCore(o,r)});h(this,"handleWindowEffect",()=>{var e;(e=this.getScrollContainerInViewable())==null||e.forEach(o=>{Yr(this,o)})});this.parentContainer=e}load(){this.containerResizeObserver||(this.containerResizeObserver=new DE(this,this.handleResize)),this.containerScrollObserver||(this.containerScrollObserver=new LE(this,this.handleScrollContainerScroll)),this.parentContainerScrollObserver||(this.parentContainerScrollObserver=new ME(this)),this.scrollWrapResizeObserve||(this.scrollWrapResizeObserve=new AE(this)),this.locatingContainerResizeObserver||(this.locatingContainerResizeObserver=new OE(this,this.handleResize)),this.isWindowEventBind||(window.addEventListener("resize",this.handleWindowEffect),this.getParentScrollContainer()!==document.documentElement&&window.addEventListener("scroll",this.handleWindowEffect))}getParentScrollContainer(){return this.parentContainer}getScrollContainerInViewable(){var e;return(e=this.parentContainerScrollObserver)==null?void 0:e.scrollContainers}unbindCore(e,o){var i,s,l,c,a,u;const r=Zr(e);(i=this.containerScrollObserver)==null||i.unbindContentScroll(e),(s=this.containerScrollObserver)==null||s.unbind(r),(l=this.scrollWrapResizeObserve)==null||l.unbind(o),(c=this.containerResizeObserver)==null||c.unbind(e),(a=this.parentContainerScrollObserver)==null||a.unbindScrollContainer(e),(u=this.locatingContainerResizeObserver)==null||u.unbind(e)}bindCore(e,o){var i,s,l,c,a,u;if(this.unbindCore(e,o),!e.closest("body"))return;const r=Zr(e);(i=this.containerScrollObserver)==null||i.bindContentScrollCore(e),(s=this.containerScrollObserver)==null||s.bindCore(r),(l=this.scrollWrapResizeObserve)==null||l.bind(o),(c=this.containerResizeObserver)==null||c.bind(e),(a=this.parentContainerScrollObserver)==null||a.bindScrollContainer(e),(u=this.locatingContainerResizeObserver)==null||u.bind(e)}bind(e,o){this.containers.set(e,o);const r=e.firstElementChild;this.containerIntersectionObserver||(this.containerIntersectionObserver=new EE(this,this.handleIntersection)),this.containerIntersectionObserver.bind(r)}unbind(e){var i;const o=e.firstElementChild,r=dn(o);this.unbindCore(o,r),this.containers.delete(e),(i=this.containerIntersectionObserver)==null||i.unbind(o),this.containers.size||this.destroy()}destroy(){var e,o,r,i,s;this.containers.forEach((l,c)=>{this.unbind(c)}),this.containers.clear(),(e=this.parentContainerScrollObserver)==null||e.destroy(),(o=this.containerIntersectionObserver)==null||o.destroy(),(r=this.containerResizeObserver)==null||r.destroy(),(i=this.scrollWrapResizeObserve)==null||i.destroy(),(s=this.locatingContainerResizeObserver)==null||s.destroy(),window.removeEventListener("resize",this.handleWindowEffect),window.removeEventListener("scroll",this.handleWindowEffect)}}const j5=B("scroll-container"),Rc=new Map;class NE extends Yt.TypedEmitter{constructor(){super(...arguments);h(this,"scrollListener");h(this,"options");h(this,"scrollContainerElement");h(this,"init",e=>{this.options=e;const o=b("div",[Bo.CONTAINER],e.parentElement);xt.isMac&&A(o,Bo.MAC);const r=b("div",[Bo.SCROLL_CONTAINER],o),i=b("div",[Bo.SCROLL_AREA],r);i.style.paddingLeft=e.paddingLeft?`${e.paddingLeft}px`:"",i.style.paddingTop=e.paddingTop?`${e.paddingTop}px`:"",i.style.paddingBottom=e.paddingBottom?`${e.paddingBottom}px`:"",i.style.paddingRight=e.paddingRight?`${e.paddingRight}px`:"",i.appendChild(e.childElement);const s=e.parentContainer;this.scrollListener=Rc.get(s),this.scrollListener||(this.scrollListener=new _E(s),Rc.set(s,this.scrollListener)),this.scrollListener.unbind(o),this.scrollListener.bind(o,e),this.scrollListener.on("scroll",this.handleContainerScroll),this.scrollListener.on("resize",this.handleResize),this.scrollContainerElement=r});h(this,"handleContainerScroll",(e,o)=>{o===this.scrollContainerElement&&this.emit("scroll",this)});h(this,"handleResize",(e,o)=>{o===this.scrollContainerElement&&this.emit("scroll",this)})}get rootElement(){return this.scrollContainerElement}get contentElement(){return d(j5,this.scrollContainerElement,"scrollContainerElement cannot be undefined"),dn(this.scrollContainerElement)}get scrollOptions(){return d(j5,this.options,"options cannot be undefined"),{...this.options}}handleBaseListenerDestroy(e){e.destroy()}destroy(){var o;(o=this.scrollListener)==null||o.off("scroll",this.handleContainerScroll);const e=Ae(this.contentElement);e&&Rc.forEach((r,i)=>{r.unbind(e),r.containers.size===0&&(this.handleBaseListenerDestroy(r),Rc.delete(i))})}}function $E(){return new NE}const Ac=100,PE=40,_h=B("column-width");function jE(n,t,e){VB(n,t).style.width=`${e}px`}function HE(n){const e=Array.from(n.querySelector("colgroup").children).map(c=>c.getBoundingClientRect().width);if(e[0]!==0)return e;const o=et.fromTable(n),r=Array(o.colCount).fill(-1),i=n.getBoundingClientRect().left;o.toRealCells(o.cells).forEach(c=>{const a=c.col+c.colSpan-1;r[a]===-1&&(r[a]=c.cell.getBoundingClientRect().right-i)}),_h.debug(`cellRightOffsets1: ${r.join()}`);for(let c=0;c<r.length;c++){const a=r[c];if(a===-1||c===0)continue;let u=c-1;for(;r[u]===-1&&(u--,u!==-1););const f=u===-1?0:r[u],C=(a-f)/(c-u);for(let k=u+1;k<c;k++)r[k]=f+C*(k-u)}_h.debug(`cellRightOffsets2: ${r.join()}`);const s=[];let l=0;for(let c=0;c<r.length;c++){const a=r[c];s.push(a-l),l=a}return _h.debug(`widths: ${s.join()}`),s}function Ss(n){return Array.from(n.querySelector("colgroup").children).map(o=>o.getBoundingClientRect().width||Number.parseInt(o.style.width,10)||100)}const FE=B("table-resize-gripper"),H5=7,Nh=(H5-1)/2,zE=3;function UE(n,t,e){const{rows:o}=n;for(let r=0;r<o.length;r++){const i=o[r],s=Array.from(i.cells);for(let l=0;l<s.length;l++){const c=s[l],a=c.getBoundingClientRect(),u=Math.round(a.right);if(Math.abs(t-u)<=Nh&&a.top<=e&&e<=a.bottom)return c}}return null}function VE(n){return!!n.rootContainer.querySelector(".table-resize-gripper")}function $h(n,t){return Tn(n,t).querySelector(".table-resize-gripper")}function F5(n,t){const e=$h(n,t);d(FE,!e,"resize gripper has already exists");const o=Tn(n,t),r=b("div",["table-resize-gripper","table-indicator"],o);return b("div",["table-resize-gripper-indicator"],r),r}function z5(n,t,e){let o=$h(n,t);o||(o=F5(n,t));const i=jt(t).getBoundingClientRect(),s=e.getBoundingClientRect(),l=0,c=i.height,a=n.getCustom(wo(t)).contentElement.getBoundingClientRect(),u=s.right-a.left;o.style.left=`${u-Nh-Th-Bs}px`,o.style.top=`${l}px`,o.style.height=`${c}px`,o.style.width=`${H5}px`}function Ph(n){n.rootContainer.querySelectorAll(".table-resize-gripper").forEach(t=>{t.remove()})}function qE(n,t,e){const r={...n.getBlockData(t),colsWidth:e};n.updateBlockData(t,r)}function WE(n,t,e,o){const r=t,i=et.fromTable(e),s=i.getCellByCellElement(r),l=s.col+s.colSpan-1,c=Ss(e);let a=o;const u=(m,C)=>{const k=C+1,w=m.col+m.colSpan;return c.slice(k,w).reduce((S,I)=>S+I,0)},f=new Set;for(let m=0;m<i.rowCount;m++){const C=i.getCell({row:m,col:l});if(f.has(C.cell))continue;f.add(C.cell);const k=C.cell,w=k.getBoundingClientRect();let y=o-w.left+Nh-zE;const S=ys(k),I=Td(n,S)||PE*C.colSpan,M=u(C,l),R=I-M;y<R&&(y=R);const $=w.left+y;a=Math.max(a,$)}return a}const GE=B("table-resize-drag-drop");class ZE{constructor(t,e,o,r){h(this,"cursor","col-resize");this.editor=t,this.elem=e,this.data=o,this.onEnd=r}onDragStart(t,e,o){}onDragging(t,e,o,r,i){const{table:s,block:l,draggingRefCell:c}=t.data,u=WE(this.editor,c,s,e.x-t.dragOffsetX)-s.getBoundingClientRect().left;d(GE,c,"no dragging cell");const m=et.fromTable(s).getCellByCellElement(c),C=m.col+m.colSpan-1,w=Ss(s).slice(0,C).reduce((S,I)=>S+I,0),y=u-w;jE(s,C,y),z5(this.editor,l,c),this.editor.selection.caret.update()}onDragEnd(t,e,o,r,i){const s=Ss(t.data.table);qE(this.editor,t.data.block,s),Ph(this.editor),this.onEnd&&(this.onEnd(e),this.onEnd=null)}}function YE(n,t){const e=document.elementFromPoint(t.x,t.y);if(!e)return null;const o=F(e);return!o||!n.contains(o)||!Ht(o)?null:o}B("table-resize");class QE{constructor(t){h(this,"draggingRefCell",null);h(this,"handleMouseMove",(t,e)=>{if(t.readonly||t.selectionHandler.isSelecting()&&!this.draggingRefCell||this.draggingRefCell)return;const o=e.target;if(!(o instanceof Element)||o.closest(".table-indicator"))return;const i=e,s=YE(t,i);if(!s||!C5(s)){Ph(t);return}this.updateGripper(s,i.x,i.y)});this.editor=t,t.domEvents.addEventListener(document,"mousemove",this.handleMouseMove)}destroy(){this.editor.domEvents.removeEventListener(document,"mousemove",this.handleMouseMove)}updateGripper(t,e,o){const r=jt(t),i=UE(r,e,o);if(i){if(!$h(this.editor,t)){if(VE(this.editor))return;const l=F5(this.editor,t),c={block:t,table:r,draggingRefCell:i};sd(new ZE(this.editor,l,c,a=>{this.updateGripper(t,a.x,a.y)}))}z5(this.editor,t,i)}else Ph(this.editor)}}function U5(n){n.addCustom("table-mouse-event-handler",t=>new QE(t))}const V5=B("table-insert-column");function q5(n,t,e){const o=jt(t),r=et.fromTable(o),i=r.colCount;d(V5,e>=0&&e<=i,`insert index ${e} is out of range [0, ${i}]`);const s=r.map(m=>m.containerId),l=new Set;n.doc.beginBatchUpdate();for(let m=0;m<s.length;m++){const C=s[m],k=C[e-1],w=C[e];if(e===0||e===C.length||k!==w){const y=yn(n.doc);C.splice(e,0,y)}else C.splice(e,0,k),l.add(k)}n.doc.endBatchUpdate();const c=Y.default(n.getBlockData(t));l.forEach(m=>{const C=`${m}_colSpan`,k=c[C];d(V5,typeof k=="number"&&k>1,`no colSpan for containerId ${m}, ${k}`),c[C]=k+1});const a=c.colsWidth.concat();a.splice(e,0,Ac);const u=et.virtualCellContainersGridToChildren(s),f={...c,cols:c.cols+1,children:u,colsWidth:a};or(f),n.updateBlockData(t,f)}const Oc=B("table-insert-row");function W5(n,t,e){const o=jt(t),r=et.fromTable(o),i=r.rowCount;d(Oc,e>=0&&e<=i,`insert index ${e} is out of range [0, ${i}]`);const s=r.map(m=>m.containerId),l=new Set;n.doc.beginBatchUpdate();const c=[];for(let m=0;m<r.colCount;m++){const C=e>0&&s[e-1][m],k=e<r.rowCount&&s[e][m];if(d(Oc,C||k,"no top and bottom cell"),e===0||e===r.rowCount||C!==k){const w=yn(n.doc);c.push(w)}else d(Oc,C,"no top cell"),c.push(C),l.add(C)}n.doc.endBatchUpdate(),s.splice(e,0,c);const a=Y.default(n.getBlockData(t));l.forEach(m=>{const C=`${m}_rowSpan`,k=a[C];d(Oc,typeof k=="number"&&k>1,`no rowSpan for containerId ${m}, ${k}`),a[C]=k+1});const u=et.virtualCellContainersGridToChildren(s),f={...a,rows:a.rows+1,children:u};or(f),n.updateBlockData(t,f)}const jh=B("paste-table-in-table-block");function KE(n,t,e,o){let r=et.fromBlock(e);const i=t.blocks.root[0];d(jh,i,"no table data"),d(jh,i.type==="table",`table data type is not table, but ${i.type}`);const s=i,l=r.getCellByCellElement(o),c=s.cols,a=s.rows,u=l.col,f=l.row,m=u+c,C=f+a,k=[];for(let w=u;w<m&&w<r.colCount;w++)for(let y=f;y<C&&y<r.rowCount;y++){const S=r.getCell({col:w,row:y});S.virtual?S.virtual&&k.push({col:w,row:y}):(S.colSpan>1||S.rowSpan>1)&&k.push({col:w,row:y})}n.undoManager.runInGroup(()=>{if(k.forEach(I=>{const M=et.fromBlock(e).getCell(I);(M.colSpan>1||M.rowSpan>1)&&Bh(n,e,I)}),m>r.colCount)for(let I=r.colCount;I<m;I++)q5(n,e,I);if(C>r.rowCount)for(let I=r.rowCount;I<C;I++)W5(n,e,I);r=et.fromBlock(e);const w=new Ec(s);let y;for(let I=0;I<w.colCount;I++)for(let M=0;M<w.rowCount;M++){const R=w.getCell({col:I,row:M});if(!R.virtual){const $=Cu(n.editorBlocks,t,R.containerId),Z=u+I,rt=f+M,st={col:Z,row:rt},mt=r.getCellContainer(st);qp(n,mt,$),y=mt}}d(jh,y,"no last container");const S=Qt(y);n.selection.selectBlock(S,W(n,S))})}const G5=B("paste-in-table-block");class JE{constructor(t){this.editor=t,setTimeout(()=>{t.input.addHandler(this)})}destroy(){}async handleBeforePasteDoc(t,e){if(!t.selection.range.isSimple()||t.selection.range.start.offset!==0)return!1;const r=t.selection.startBlock,i=H(r);if(pt(i)||!Sd(t,i))return!1;const s=F(i);if(d(G5,s,"no parent block"),!Ht(s)||e.blocks.root.length!==1||e.blocks.root[0].type!=="table")return!1;G5.debug("paste child table in table");const a=et.fromBlock(s).getCellByContainerId(U(i)).cell;return KE(t,e,s,a),!0}}function Z5(n){n.addCustom("table-block-paste-event",t=>new JE(t))}const Hh=B("table-select-columns");function XE(n,t,e,o,r){d(Hh,Ht(t),"is not a table block");const i=et.fromBlock(t);d(Hh,e>=0&&e<i.colCount,"invalid from"),d(Hh,o>0&&e+o<=i.colCount,"invalid count");const s=i.getCell({row:0,col:e}),l=i.getCell({row:i.rowCount-1,col:e+o-1}),c=wt(t,s.containerId,{colIndex:e,rowIndex:0}),a=wt(t,l.containerId,{colIndex:e+o-1,rowIndex:i.rowCount-1});r!=null&&r.reverse?n.selection.setSelection(a,c):n.selection.setSelection(c,a)}const Fh=B("table-select-columns");function tI(n,t,e,o,r){d(Fh,Ht(t),"is not a table block");const i=et.fromBlock(t);d(Fh,e>=0&&e<i.rowCount,"invalid from"),d(Fh,o>0&&e+o<=i.rowCount,"invalid count");const s=i.getCell({row:e,col:0}),l=i.getCell({row:e+o-1,col:i.colCount-1}),c=wt(t,s.containerId,{rowIndex:e,colIndex:0}),a=wt(t,l.containerId,{rowIndex:e+o-1,colIndex:i.colCount-1});r!=null&&r.reverse?n.selection.setSelection(a,c):n.selection.setSelection(c,a)}const yz="",Y5=B("get-toolbar-reference-client");function eI(n,t){const e=n.selection.range;if(!e.isSimple()){d(Y5,e.start.blockId===e.end.blockId,"invalid selection range");const s=n.getBlockById(e.start.blockId);d(Y5,at(n,s),"not a complex block");const l=kt(n,s);if(l.getTextToolbarReferenceClient){const c=l.getTextToolbarReferenceClient(n,s);if(c)return c}}const o=e.isReverse()?t.start:t.end,r=qt(n,{anchor:o,focus:o}),i=io(n,t.block,r);if(i.length!==0)return i[0]}function nI(n){var t,e;if(n.children){let o=!1;const r=[];for(const i of n.children){if((t=i.states)!=null&&t.includes("checked")){o=!0;break}(e=n.defaultCheckedChildren)!=null&&e.includes(i.id)&&r.push(i)}if(!o&&(r==null?void 0:r.length))for(const i of r)Array.isArray(i.states)?i.states.push("checked"):i.states=["checked"]}}function _c(n){const t=(r,i)=>{const s=r.findIndex(c=>c.id===i.id);if(s===-1){r.push(i);return}const l=r[s];if(l.value!==i.value&&delete l.value,!!l.states){if(!i.states){l.states=[];return}l.states=Xa.default(l.states,i.states)}},e=[],o=new Map;return n.forEach(r=>{var i,s;(i=r.children)!=null&&i.length&&(o.has(r.id)?(s=o.get(r.id))==null||s.push(...r.children):o.set(r.id,[...r.children])),t(e,r)}),o.forEach((r,i)=>{const s=e.find(l=>l.id===i);s&&(s.children=_c(r),nI(s))}),e}function Nc(n){return n.getCustom("toolbar-handler")}const wz="";class oI{constructor(){h(this,"linkPopup",null);h(this,"form",{});h(this,"onFinished",null);h(this,"onClose",null);h(this,"handleOk",async()=>{var t;try{await this.checkValue();const{linkText:e,linkUrl:o}=this.form;(t=this.onFinished)==null||t.call(this,e.getInputValue()||o.getInputValue(),o.getInputValue()),this._destroy()}catch{}});h(this,"handleClose",()=>{var t;(t=this.onClose)==null||t.call(this),this._destroy()});h(this,"onShow",()=>{setTimeout(()=>{var t;(t=this.form.linkText)==null||t.getField().focus()},400)});h(this,"onChange",()=>{var e;const t=(e=this.linkPopup)==null?void 0:e.content.querySelector(".submit-button");t.disabled=!1});h(this,"handleTextKeyboard",t=>{var e;if(!t.isComposing){if(t.key==="Enter"){(e=this.form.linkUrl)==null||e.getField().focus(),t.stopPropagation();return}t.key==="Escape"&&this.handleClose()}});h(this,"handleUrlKeyboard",t=>{if(!t.isComposing){if(t.key==="Enter"){this.handleOk(),t.preventDefault();return}t.key==="Escape"&&this.handleClose()}})}async checkValue(){const{linkUrl:t}=this.form;if(!t.getInputValue())throw t.setFieldError(T.t("link.urlPlaceholder")),new Error(T.t("link.urlPlaceholder"))}editLink(t){var u,f;const{target:e,linkText:o,linkUrl:r,onFinished:i,onClose:s,placement:l="bottom-start"}=t;this.linkPopup=new Cs(this.createPopupContent(o,r)),this.linkPopup.addListener("show",this.onShow),this.linkPopup.manualShow(e,{theme:"light",placement:l}),this.onFinished=i,s&&(this.onClose=s);const c=(u=this.linkPopup)==null?void 0:u.content.querySelector(".submit-button"),a=(f=this.linkPopup)==null?void 0:f.content.querySelector(".cancel-button");c==null||c.addEventListener("click",this.handleOk),a==null||a.addEventListener("click",this.handleClose)}createPopupContent(t,e){const o=b("div",["link-popup-content"],null);this.form.linkText=mh(o,{label:T.t("link.textLabel"),required:!1,placeholder:T.t("link.textPlaceholder"),defaultValue:t,onChange:this.onChange,onKeyDown:this.handleTextKeyboard}),this.form.linkUrl=mh(o,{className:"link-popup-gap",label:T.t("link.urlLabel"),required:!0,placeholder:T.t("link.urlPlaceholder"),defaultValue:e,onChange:this.onChange,onKeyDown:this.handleUrlKeyboard});const r=b("div",["link-popup-footer"],o);b("button",["cancel-button"],r,T.t("link.cancelText"));const i=b("button",["submit-button"],r,T.t("link.submitText"));return i.disabled=!0,o}_destroy(){var o,r,i,s;const t=(o=this.linkPopup)==null?void 0:o.content.querySelector(".submit-button"),e=(r=this.linkPopup)==null?void 0:r.content.querySelector(".cancel-button");t==null||t.removeEventListener("click",this.handleOk),e==null||e.removeEventListener("click",this.handleClose),this.onFinished=null,this.onClose=null,this.form={},(i=this.linkPopup)==null||i.removeAllListeners(),(s=this.linkPopup)==null||s.destroy()}destroy(){this._destroy()}}function Ds(n,t){n.addCustom("link-editor",()=>new oI).editLink(t)}const rI=B("link-popup");function iI(n){return nt(n,"link")}function $c(n){var t,e;return(e=(t=n.getAttribute("link"))!=null?t:n.textContent)!=null?e:""}function sI(n,t,e){var r,i,s,l;if(n.isBlockWritable(t)&&e&&_e(e)){const c=e,a=(i=(r=n.editorBoxes.getBoxClass(_i(c))).getBoxProperties)==null?void 0:i.call(r,n,c);return a!=null&&a.boxCommands?(l=(s=a.boxCommands["hovering-toolbar"])==null?void 0:s.commands)!=null?l:[]:[]}return n.isWritable()&&e&&P(n,t)&&iI(e)?[{id:"link-text",name:$c(e),disableTooltip:!0,element:b("span",["link-href-button"],null,$c(e))},{id:"edit-link",name:"Edit",icon:hh},{id:"remove-link",name:"Remove link",icon:Xw}]:Cg(n,t,"hovering-toolbar")}function lI(n,t,e){var c;const o=ao(t,e);n.selection.selectBlock(t,o.start,o.end);const r=(c=e.textContent)!=null?c:"",i=$c(e);Ds(n,{target:e,linkText:r,linkUrl:i,onFinished:(a,u)=>{try{const f=n.getBlockText(t),m=qd(f,o.start,o.end-o.start),C=ho(m,o.start,a,{link:u});n.setBlockText(t,C),n.selection.selectBlock(t,o.start+a.length),n.focus()}catch(f){rI.error(f)}},onClose:()=>{n.selection.selectBlock(t,o.end),n.focus()}})}function cI(n,t,e){const o=ao(t,e),r=n.getBlockText(t),i=$c(e),s=Sr(o.start,o.end-o.start,r,"link",i);n.setBlockText(t,s),n.selection.selectBlock(t,o.end)}function aI(n,t,e,o){var s,l,c;if(e){if(n.isBlockWritable(t)&&_e(e)){const u=e,f=(l=(s=n.editorBoxes.getBoxClass(_i(u))).getBoxProperties)==null?void 0:l.call(s,n,u);if(f!=null&&f.boxCommands){f.boxCommands["hovering-toolbar"].executeCommand(n,t,u,o);return}return}const a=Nc(n);a.disableTextToolbar(),a.hide(),setTimeout(()=>{a.enableTextToolbar()},1e4),o.id==="edit-link"?lI(n,t,e):o.id==="remove-link"&&cI(n,t,e);return}const r=pg(n,t);if(!r)return;const i=(c=r.blockCommands)==null?void 0:c["hovering-toolbar"];!i||i.executeCommand(n,t,o)}function Pc(){let n=8;for(;n>0&&!document.querySelector(`div[data-style-heading='${n}']`);)n--;return n}const dI=[nh,oh,rh,ih,sh,lh,ch,ah];class uI{constructor(t){h(this,"id","BlockTurnIntoCommandProvider");this.editor=t}getHeadingIndex(){let t=Pc();return t<=4?t=5:t<8&&(t+=1),t}getAvailableCommands(t,e,o){if(P(t,e)){const r=q(e),i=ot(e),s=Qe(t,e),c=t.getBlockData(e).heading,a=[];for(let f=0;f<this.getHeadingIndex();f++)a.push({id:`heading-${f+1}`,name:T.t("commands.heading",{name:`${f+1}`}),icon:dI[f],states:c===f+1?["checked"]:[],value:`${f+1}`});const u=f=>{var C;const m=b("span",["toolbar-item-name-container"],null);for(const k of f.children)if((C=k.states)!=null&&C.includes("checked"))return m.innerHTML=k.icon||Bc,m;return m.innerHTML=Bc,m};return[{id:"turn-into",name:T.t("commands.headingGroup"),blockId:r,blockType:i,blockKind:s,element:u,groupIndex:200,dropdown:!0,manualShowChildren:!0,childrenPlacement:"bottom-start",defaultCheckedChildren:["text"],children:[{id:"text",name:T.t("commands.text"),icon:Bc,states:c?[]:["checked"]},...a],childrenType:"menu"}]}return[]}applyHeadingStyle(t,e,o){t.updateBlockData(e,{heading:o})}executeCommand(t,e,o,r){if(P(t,e)&&(r.id.startsWith("heading-")||r.id==="text")){const i=r.value?Number(r.value):null;return this.applyHeadingStyle(t,e,i),!0}return!1}}function jc(n){const t=n.getAttribute("block-padding-level");return t?Number(t):null}function hI(n,t){let e;const o=jc(t);if(!o)e=1;else{if(o>=12)return e=12,!1;e=o+1}return n.updateBlockData(t,{...n.getBlockData(t),padding:e}),!0}function Q5(n,t){const e=jc(t);if(!e)return!1;const o=n.getBlockData(t);return e>1?(n.updateBlockData(t,{...o,padding:e-1}),!0):(n.updateBlockData(t,{...o,padding:null}),!0)}function zh(n){return n.readonly||!n.isWritable()}function fI(n){return n.selection.range.getSelectedBlocks().forEach(e=>{const o=e.block;P(n,o)&&hI(n,o)}),!0}function mI(n){return n.selection.range.getSelectedBlocks().forEach(e=>{const o=e.block;P(n,o)&&Q5(n,o)}),!0}function gI(n){return zh(n)?!1:n.undoManager.runInGroup(()=>(fI(n),!0))}function pI(n){return zh(n)?!1:n.undoManager.runInGroup(()=>(mI(n),!0))}function CI(n){if(zh(n))return!1;if(!n.selection.range.isCollapsed())return;const t=n.selection.focusedBlock;if(!P(n,t))return;const e=n.selection.range.focus;if(!(!e.isSimple()||e.offset!==0||!jc(t)))return Q5(n,t),!0}class bI{renderBlock(t,e,o){const{padding:r}=o;return r?{attributes:{"block-padding-level":r}}:{}}}const Bz="",kI={Tab:gI,"Shift+Tab":pI,Backspace:CI},Hc=B("list-block");function ct(n){return ot(n)==="list"}function Ft(n){d(Hc,ct(n),"not a list block")}function Fe(n){Ft(n);const t=n.getAttribute("data-list-type");return d(Hc,t,"no list type"),t}function Fc(n){return ct(n)&&Fe(n)==="text-only"}function un(n){var t,e;return Ft(n),(e=Number.parseInt((t=n.getAttribute("data-list-start"))!=null?t:"1",10))!=null?e:1}function ge(n){var t,e;return Ft(n),(e=Number.parseInt((t=n.getAttribute("data-list-level"))!=null?t:"1",10))!=null?e:1}function Qr(n){Ft(n);const t=n.getAttribute("data-list-group-id");return d(Hc,t,"no group id"),t}function Eo(n){var i,s,l,c,a;Ft(n);const t=(i=n.getAttribute("data-list-type"))!=null?i:"ordered",e=(l=Number.parseInt((s=n.getAttribute("data-list-start"))!=null?s:"1",10))!=null?l:1,o=(a=Number.parseInt((c=n.getAttribute("data-list-level"))!=null?c:"1",10))!=null?a:1,r=n.getAttribute("data-list-group-id");return d(Hc,r,"no group id"),{type:t,start:e,level:o,groupId:r}}function Uh(n){switch(n){case"ordered":return{ordered:!0,checkbox:null,textOnly:null};case"unordered":return{ordered:!1,checkbox:null,textOnly:null};case"checked":return{checkbox:"checked",ordered:!1,textOnly:null};case"unchecked":return{checkbox:"unchecked",ordered:!1,textOnly:null};case"text-only":return{checkbox:null,ordered:!1,textOnly:!0};default:return{checkbox:null,ordered:!0,textOnly:!1}}}function Zn(n){Ft(n);const{level:t,groupId:e,type:o}=Eo(n);let r=gt(n);for(;r;){if(!ct(r))return null;const{level:i,groupId:s,type:l}=Eo(r);if(i<t)return null;if(t===i&&e===s&&(l==="text-only"||o==="text-only"||o===l))return r;r=gt(r)}return null}function sr(n){Ft(n);const{level:t,groupId:e,type:o}=Eo(n);let r=dt(n);for(;r;){if(ct(r)){const{level:i,groupId:s,type:l}=Eo(r);if(t===i&&e===s&&(l==="text-only"||o==="text-only"||o===l))return r;if(i<t)return null}r=dt(r)}return null}function K5(n){Ft(n);const t=[];let e=Zn(n);for(;e;)t.unshift(e),e=Zn(e);return t}function Ls(n){Ft(n);const t=[];let e=sr(n);for(;e;)t.push(e),e=sr(e);return t}function Ms(n){Ft(n);let t=Zn(n);for(;t;){const e=Zn(t);if(!e)return t;t=e}return n}function vI(n){Ft(n);let t=sr(n);for(;t;){const e=sr(t);if(!e)return t;t=e}return null}function J5(n,t){const e=K5(n),o=Ls(n);return t.withSelf?[...e,n,...o]:[...e,...o]}function Rs(n,t,e,o){var i;const r=(i=o==null?void 0:o.groupId)!=null?i:N();t.forEach(s=>{const l=n.getBlockData(s);if(l.start!==e||(o==null?void 0:o.resetGroupId)){const c={...l,start:e};o!=null&&o.resetGroupId&&(c.groupId=r),n.updateBlockData(s,c)}l.textOnly||(e+=1)})}function Vh(n,t,e,o){const r=J5(t,{withSelf:!0});r.length!==0&&Rs(n,r,e,o)}function yI(n){const t={M:1e3,CM:900,D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1};let e="",o=n;return Object.entries(t).forEach(([r,i])=>{for(;o>=i;)e+=r,o-=i}),e.toLowerCase()}const wI="abcdefghijklmnopqrstuvwxyz";function X5(n){if(n<=0)return`${n}`;const t=(n-1)%26,e=Math.floor((n-1)/26),o=wI[t];return e?X5(e)+o:o}function BI(n){return`${n}`}const t4=[BI,X5,yI];function EI(n,t){const e=t4[(n-1)%t4.length];return e(t)}function II(n){return["\u2022","\u25E6","\u25AA"][(n-1)%3]}class lr{constructor(t,e,o){h(this,"listStart");h(this,"listBrother",null);this.editor=t,this.options=o;const r=Ms(e),i=un(r);this.listStart=i,this.listBrother=r,o!=null&&o.resetStart&&(this.listStart=1)}fix(){!this.listBrother||Vh(this.editor,this.listBrother,this.listStart,this.options)}}function xI(n,t,e=1){if(!t)return null;let o=gt(n);for(;o;){const r=o.getAttribute("data-style-heading"),i=Number(o.getAttribute("data-list-level"));if(r){if(r<t)return null;if(r===t&&i===e)return ct(o)?o:null}o=gt(o)}return null}function TI(n,t){const e=n.getAttribute("data-style-heading"),o=xI(n,e);if(o)return o;const r=gt(n);if(r&&ct(r)&&Fe(r)===t)return r;const i=dt(n);return i&&ct(i)&&Fe(i)===t?i:null}function SI(n,t,e){var y,S,I,M;const o=(y=e.data)!=null?y:{};let r=1;if(ct(t))r=ge(t);else{const R=jc(t);R&&(r=R+1),r>8&&(r=8)}const i=(S=o.listType)!=null?S:"ordered";if(i==="text-only")return null;const s=n.getBlockData(t);let l=(I=s.text)!=null?I:[];const c=n.selection.range.focus;if(!c.isSimple())return null;let u=bt(l);const f=(M=e.offset)!=null?M:c.offset;f<=ue(l)&&(l=be(l,f).right,u=u.substring(0,f));let m=1;i==="ordered"&&(m=Number.parseInt(u,10)||1);let C=N();const k=TI(t,i);if(k){if(J(t)>J(k))m=un(k)+1;else{const R=un(k);R>1&&(m=R-1)}C=Qr(k)}const w={id:N(),type:"list",level:r,start:m,groupId:C,ordered:!1,text:l};return s.quoted&&(w.quoted=!0),s.heading&&(w.heading=s.heading),i==="ordered"?w.ordered=!0:(i==="checked"||i==="unchecked")&&(w.checkbox=i),{blockData:w,onConverted:(R,$)=>{new lr(R,$).fix()}}}function Kr(n){return n.textOnly?"text-only":n.checkbox?n.checkbox:n.ordered?"ordered":"unordered"}function DI(n){var e,o;if(n.checkbox||n.textOnly)return"";const t=(e=n.level)!=null?e:1;return n.ordered?`${EI(t,(o=n.start)!=null?o:1)}.`:II(t)}function zc(n){return n==="checked"||n==="unchecked"}function e4(n,t,e,o){const r=t,{containerId:i,blockIndex:s}=o[o.length-1];if(s===0)return!0;const l=e.blocks[i][s-1];if(l.type!=="list")return!0;const c=Kr(r),a=Kr(l);return c!==a&&(!zc(c)||!zc(a))||r.level>l.level}function n4(n,t,e,o){const r=t,{containerId:i,blockIndex:s}=o[o.length-1];if(s===e.blocks[i].length-1)return!0;const l=e.blocks[i][s+1];if(l.type!=="list")return!0;const c=Kr(r),a=Kr(l);return c!==a&&(!zc(c)||!zc(a))||r.level>l.level}function LI(n,t,e,o,r){var s,l,c;const i=t;if(o==="text"){let a=((s=ke.convertTo)==null?void 0:s.call(ke,n,t,e,"text",r))||"";i.checkbox==="checked"?a=`[x] ${a}`:i.checkbox==="unchecked"&&(a=`[ ] ${a}`),i.ordered?a=`${i.start}. ${a}`:a=`- ${a}`;const u=i.level||0;return a=(u>0?" ".repeat(u-1):"")+a,a}if(o==="markdown"){let a=((l=ke.convertTo)==null?void 0:l.call(ke,n,t,e,"markdown",r))||"";i.checkbox==="checked"?a=`[x] ${a}`:i.checkbox==="unchecked"&&(a=`[ ] ${a}`),i.ordered?a=`${i.start}. ${a}`:a=`- ${a}`;const u=i.level||0;return a=(u>0?" ".repeat(u-1):"")+a,e4(n,t,e,r)&&(a=`${a}`),n4(n,t,e,r)&&(a=`${a}`,u<=1&&(a+=`
338
- `)),a}if(o==="html"){let a=((c=ke.convertTo)==null?void 0:c.call(ke,n,t,e,"html",r))||"";a=a.replace("<p>","").replace("</p>",""),i.checkbox==="checked"?a=`<input type="checkbox" checked="checked" disabled="disabled" /> ${a}`:i.checkbox==="unchecked"&&(a=`<input type="checkbox" disabled="disabled" /> ${a}`);let u="ul";return i.ordered?(a=`<li value="${i.start}">${a}</li>`,u="ol"):a=`<li>${a}</li>`,e4(n,t,e,r)&&(a=`<${u}>${a}`),n4(n,t,e,r)&&(a=`${a}</${u}>`),a}return""}const MI=8,Ot=B("list-block");class Uc{constructor(t,e){h(this,"listStart",0);h(this,"listBrother",null);if(this.editor=t,Fc(e))return;const o=Ms(e),r=un(o);this.listStart=r,o===e?this.listBrother=sr(o):this.listBrother=o}fix(){!this.listBrother||Vh(this.editor,this.listBrother,this.listStart)}}function RI(n,t,e){n.getBlockData(t).quoted&&(e.quoted=!0)}function qh(n,t,e,o){if(Ot.debug("drag a block on a list block"),!P(n,t))return!1;d(Ot,ct(e),"target is not a list block");const{type:r,start:i,level:s,groupId:l}=Eo(e),c=o==="after"?i+1:i,a=n.getBlockData(t),u={id:N(),type:"list",groupId:l,level:s,start:c,text:a.text,...Uh(r)};RI(n,e,u);let f=J(e);const m=H(e);o==="after"&&(f+=1);let C=null;ct(t)&&(C=new Uc(n,t));const k=n.insertBlock(U(m),f,u,Gl(u.id,0));return n.deleteBlock(t),new lr(n,k).fix(),C==null||C.fix(),!0}function AI(n,t,e,o){if(Ot.debug("drag a list between text blocks"),o==="after"){const a=dt(e);if(a&&ct(a))return qh(n,t,a,"before")}if(o==="before"){const a=gt(e);if(a&&ct(a))return qh(n,t,a,"after")}const i={...n.getBlockData(t),groupId:N(),start:1,level:1};let s=J(e);const l=H(e);o==="after"&&(s+=1),n.insertBlock(U(l),s,i,Gl(i.id,0));const c=new Uc(n,t);return n.deleteBlock(t),c.fix(),!0}function OI(n,t,e,o,r){if(xl(e))return!1;const{blockId:i}=e,s=n.getBlockById(i);d(Ot,s,"no dragged block");const{isSourceBlock:l,targetBlock:c}=r;return!l&&c?(d(Ot,t===c,"block !== target block"),d(Ot,ct(c),"target is not a list block"),qh(n,s,c,o)):AI(n,s,c,o)}const _I=`<?xml version="1.0" ?>
337
+ </svg>`;function EB(n,t){var e;if(A(t,"menu-item"),!n.element){if(n.type==="section"){const o=b("div",["section-name"],null,n.name);t.appendChild(o)}else if(n.type!=="separator"){if(n.icon){const r=b("div",["menu-item-icon"],null);n.icon&&(r.innerHTML=n.icon),t.appendChild(r)}const o=b("div",["menu-item-name","text"],null,n.name);if(t.appendChild(o),n.subText&&b("div",["item-subtext","text"],t,n.subText),n.children&&!n.element){const r=b("div",["menu-item-sub-indicator"],null);r.innerHTML=o5,t.appendChild(r)}if((e=n.states)!=null&&e.includes("checked")){const r=b("div",["menu-item-checked-icon"],null);r.innerHTML=rB,t.appendChild(r)}}}}class nr extends yc{constructor(t,e,o){super(t,e,{autoClose:!0,disablePageScroll:!0,...o})}manualShow(t,e){const o={theme:"menu",...e};super.manualShow(t,o)}initCommandBarElement(t){A(t,"menu")}initItemElement(t,e){EB(t,e)}}function IB(n,t,e){var o;return new nr((o=n.children)!=null?o:[],t,{...e,parentItem:n})}class ks extends yc{constructor(t,e,o){super(t,e,{itemElementTag:"button",tippyArrow:!1,...o})}getSubBarOptions(t){var r,i;const e=()=>{const s=this.getItemElementById(t.id),c=this.content.getBoundingClientRect(),a=s.getBoundingClientRect();return new DOMRect(a.left,c.top,a.width,c.height)};return{placement:(r=t.childrenPlacement)!=null?r:"top",getReferenceClientRect:e,offset:(i=t.childrenOffset)!=null?i:[0,4]}}manualShow(t,e){const o={theme:"toolbar",...e};super.manualShow(t,o)}initCommandBarElement(t){A(t,"toolbar")}initItemElement(t,e){e.setAttribute("data-button-id",t.id),this.options.tooltipId&&t.name&&!t.disableTooltip&&(e.setAttribute(`data-editor-tooltip-${this.options.tooltipId}`,t.name),t.desc&&e.setAttribute(`data-editor-tooltip-desc-${this.options.tooltipId}`,t.desc));const o=e;if(!t.element)if(t.icon){const r=b("span",["toolbar-item-icon-container"],o);t.icon.trim().startsWith("<")?r.innerHTML=t.icon:r.innerText=t.icon}else{const r=b("span",["toolbar-item-name-container"],o);r.innerText=t.name}if(t.dropdown){e.setAttribute("data-dropdown","true");const r=b("span",["toolbar-item-dropdown-container"],o);r.innerHTML=eh}t.states&&(t.states.indexOf("checked")!==-1&&A(o,"checked"),t.states.indexOf("disabled")!==-1&&(o.disabled=!0))}}function xB(n,t,e){var o;return new ks((o=n.children)!=null?o:[],t,{...e,parentItem:n})}const pz="";Fr.registerManualCommandBar("menu",IB),Fr.registerManualCommandBar("toolbar",xB);const Cz="",h5=B("ui-base");class vs extends yc{constructor(e,o){super(vs.getCommandItems(e,o),void 0,{disablePageScroll:!0,...o});h(this,"handleDocumentMouseDown",e=>{})}initCommandBarElement(e){A(e,"dialog","manual")}initItemElement(e,o){}show(e,o){this.manualShow(e,{...o,theme:"light"})}get dialogContent(){const e=this.items[0];d(h5,e,"no dialog item");const o=e.element;return d(h5,o,"no item element"),o}static getCommandItems(e,o){var s;return[{id:(s=o==null?void 0:o.id)!=null?s:`manual-dialog-${N()}`,name:"",element:e}]}}const TB=[-1,6,0,1,2,3,4,5],SB=[-1,6,0,1,2,3,4,5,14,13,7,8,9,10,11,12],f5=B("color-palette");function m5(n,t,e,o){d(f5,n>0,"no color in palette");const r=t||1;d(f5,r>0,`invalid palette rows: ${r}`);const i=n/r,s=b("div",["palette-container",o],null);for(let l=0;l<r;l++){const c=b("div",["palette-container-row"],s);for(let a=0;a<i;a++){const u=e(l*i+a);c.appendChild(u)}}return s}function DB(n){const t=b("button",["color-button"],null),e=TB[n];return t.setAttribute("data-color-index",`${e}`),t.innerHTML=n5,t}function LB(n){const t=b("button",["background-color-button"],null),e=SB[n];return t.setAttribute("data-color-index",`${e}`),t}function MB(){const n=b("div",["clear-button-container"],null),t=b("button",["clear-button"],n);return t.innerText=T.t("colorPalette.reset"),n}function RB(n){const t=b("div",["color-palette"],null);return n.color!==!1&&(b("div",["bar-desc"],t,T.t("colorPalette.colorDesc")),t.appendChild(m5(8,1,DB,"color"))),n.backgroundColor!==!1&&(b("div",["bar-desc"],t,T.t("colorPalette.backgroundDesc")),t.appendChild(m5(16,2,LB,"background-color"))),n.clearColorButton!==!1&&t.appendChild(MB()),t}function AB(n,t,e){const o=t==="color"?"color":"background-color",r=n.querySelector(`.${o} button.selected`);r&&z(r,"selected"),e===null&&(e=-1);const i=n.querySelector(`.${o} button[data-color-index="${e}"]`);i&&A(i,"selected")}const bz="",OB={};class _B extends Yt.TypedEmitter{constructor(e=OB){super();h(this,"root");h(this,"handleClick",e=>{const o=e.target;if(!o||!(o instanceof Element))return;const r=o.closest("button");if(!r)return;if(nt(r,"clear-button")){this.setColor("backgroundColor",null),this.setColor("color",null),this.emit("onClick","clearColor",0);return}const i=r.getAttribute("data-color-index");if(!i)return;const s=Number.parseInt(i,10);Number.isNaN(s)||(nt(r,"color-button")?s===-1?(this.setColor("color",null),this.emit("onClick","clearColor",1)):(this.setColor("color",s),this.emit("onClick","color",s)):s===-1?(this.setColor("backgroundColor",null),this.emit("onClick","clearColor",2)):(this.setColor("backgroundColor",s),this.emit("onClick","backgroundColor",s)))});this.options=e,this.root=RB(e),this.root.addEventListener("click",this.handleClick)}destroy(){this.removeAllListeners(),this.root.removeEventListener("click",this.handleClick)}setColor(e,o){AB(this.root,e,o)}}class g5{constructor(t,e){h(this,"name","Color Palette");h(this,"element");h(this,"palette");h(this,"closeable",null);this.id=t,this.palette=new _B(e),this.element=this.palette.root}setCloseable(t){this.closeable=t}destroy(){this.palette.destroy(),this.closeable=null}}function NB(){const n=b("button",["color-button"],null);return n.innerHTML=n5,n}function fh(n,t){const[e,o]=t;e===null?n.removeAttribute("data-color"):n.setAttribute("data-color",`${e}`),o===null?n.removeAttribute("data-background-color"):n.setAttribute("data-background-color",`${o}`)}class $B extends Yt.TypedEmitter{constructor(e){super();h(this,"id","text-color-item");h(this,"name",T.t("colorPalette.name"));h(this,"dropdown",!0);h(this,"manualShowChildren",!0);h(this,"children",[]);h(this,"element");h(this,"colorPaletteItem");h(this,"latestColors",[null,null]);h(this,"handlePaletteClick",(e,o)=>{this.emit("onClick",e,o),e==="color"||e==="backgroundColor"?e==="color"?this.latestColors[0]=o:this.latestColors[1]=o:this.latestColors=[null,null],fh(this.element,this.latestColors)});h(this,"beforePopup",()=>{this.emit("beforePopup")});this.editor=e,this.colorPaletteItem=new g5("text-color-palette-item"),this.colorPaletteItem.palette.addListener("onClick",this.handlePaletteClick),this.children.push(this.colorPaletteItem),this.element=NB()}destroy(){this.colorPaletteItem.destroy()}updatePaletteColor(e){this.colorPaletteItem.palette.setColor("color",e[0]),this.colorPaletteItem.palette.setColor("backgroundColor",e[1]),this.latestColors=e,fh(this.element,this.latestColors)}updateButtonColor(e){this.latestColors=e,fh(this.element,this.latestColors)}}const kz="";function mh(n,t){const e=b("div",["editor-input-wrap"],n);t!=null&&t.className&&A(e,t==null?void 0:t.className);const o=b("div",["editor-input-label"],e);b("span",[],o,t.label),t.required&&A(o,"required");const r=b("div",["editor-input-container"],e),i=b("input",["editor-input"],r);t.placeholder&&(i.placeholder=t.placeholder),t.defaultValue&&(i.value=t.defaultValue);const s=b("div",["editor-input-error"],e);return i.addEventListener("input",l=>{var c;(c=t.onChange)==null||c.call(t,l),z(e,"error")}),i.addEventListener("keydown",l=>{var c;(c=t.onKeyDown)==null||c.call(t,l)}),{getField:()=>i,getInputValue:()=>i.value,setFieldError:l=>{A(e,"error"),s.innerText=l},focus:()=>{setTimeout(()=>{i.focus()})}}}function gh(n){const t=document.getSelection();if(!t)return!0;const e=t.focusNode;if(!e)return!0;const o=t.focusOffset,r=e.childNodes[o];if(!r)return!0;if(r instanceof HTMLElement){const i=r.tagName.toLowerCase();if(r===n.input.inputElement)return!0;if(i==="input"||i==="textarea")return!1}return!0}const PB=B("ui-base");class jB{constructor(t,e){h(this,"menu");h(this,"currentText","");h(this,"handleClick",(t,e)=>{this.options.onClickItem(this,e)});h(this,"handleClose",()=>{gh(this.editor)&&this.editor.focus()});h(this,"handleKeydown",t=>{this.menu.handleDocumentKeydown(t)});this.editor=t,this.options=e,this.menu=new nr([],void 0,{id:e.id}),this.menu.addListener("click",this.handleClick),this.menu.addListener("close",this.handleClose)}setItems(t){if(this.menu.updateItems(t),t.length>0){const e=t.find(o=>o.type!=="section"&&o.type!=="separator");e&&this.menu.selectItem(e.id)}}async popup(t,e,o){var a,u;if(((u=(a=this.options).onShow)==null?void 0:u.call(a,this,t,e,o))===!1)return;this.options.showLoading&&this.showLoading();const r=this.editor.getBlockByIndex(t,e);if(!It(this.editor.rootContainer,r)||W(this.editor,r)<o)return;const i=so(this.editor,r,At(this.editor,r,o));if(i.length===0)return;const s=i[0],l=ao(this.editor,r,"editor-auto-suggest-menu",s);this.menu.manualShow(l),this.options.placeholder&&this.showPlaceholder();const c=await this.options.queryItems(this,"");this.highlightText(""),this.setItems(c)}showLoading(){!this.options.showLoading||(this.options.loadingElement?this.setItems([{id:"loading",name:"",element:this.options.loadingElement,states:["disabled"]}]):this.setItems([{id:"loading",name:"loading",states:["disabled"]}]))}showPlaceholder(){this.setItems([{id:"placeholder",name:"enter text to search",states:["disabled"]}])}showNoResultMessage(t){if(this.options.noResultMessage){const e={name:"",id:"placeholder",states:["disabled"]};typeof this.options.noResultMessage=="string"?e.name=this.options.noResultMessage:(this.options.noResultMessage instanceof HTMLElement||typeof this.options.noResultMessage=="function")&&(e.element=this.options.noResultMessage),this.setItems([e])}else this.setItems([{id:"placeholder",name:T.t("search.emptyTips"),states:["disabled"]}])}close(){this.menu.close()}get isVisible(){return this.menu.isVisible}destroy(){this.menu.close(),this.menu.removeAllListeners(),this.menu.destroy()}async handleSearchText(t){this.currentText=t;const e="auto-suggest";try{await qe.lock(e),this.showLoading();const o=this.currentText,r=await this.options.queryItems(this,o);if(this.currentText===o&&(this.currentText=""),r.length===0){this.showNoResultMessage(t);return}this.setItems(r),this.options.highlight&&this.highlightText(o.replace(/^\s+|\s+$/g,""))}finally{qe.release(e)}}highlightText(t){PB.debug(`highlight menu text: ${t}`);const e=this.menu.content,o=(i,s)=>{if(!s)return i;let l="";const c=s.length,a=s.toLocaleLowerCase();let u=0;for(u=0;u<=i.length-c;u){let f=i.substring(u,u+c);if(f.toLocaleLowerCase()===a){u+=c;const m=i.charAt(u);let C=!1;f.endsWith(" ")&&(C=!0,f=f.trimEnd()),l+=`<span class="highlight">${f}${m===" "||C?"&nbsp":""}</span>`}else l+=i.charAt(u),u++}return u<i.length&&(l+=i.substring(u)),l},r=i=>{if(nt(i,"text")){const s=i.textContent;if(!s)return;const l=o(s,t);i.innerHTML=l;return}Array.from(i.children).forEach(r)};r(e)}}const ph=B("auto-suggest-menu");class Ch{constructor(t,e){h(this,"menu");h(this,"anchor",null);h(this,"handleSelectionChanged",t=>{var o,r;if(!((o=this.menu)!=null&&o.isVisible))return;const e=t.selection.range.start;if(e.isSimple()&&e.blockId===((r=this.anchor)==null?void 0:r.blockId)&&e.offset>=this.anchor.offset){const i=t.getBlockById(e.blockId);if(bt(be(he(t,i),e.offset).left).startsWith(this.anchor.leftText))return}this.menu.close()});h(this,"deleteTrigger",()=>{const t=this.editor,e=t.selection.range.start;if(!e.isSimple()||!this.anchor)return!1;const{blockId:o,offset:r}=e,i=t.getBlockById(o),s=bt(Yl(t,i,r));if(d(ph,this.anchor,"no anchor"),!s.startsWith(this.anchor.leftText))return!1;const l=this.anchor.offset-this.anchor.trigger.length,c=r-l;return t.selection.selectBlock(i,l),c&&(t.deleteTextFromBlock(i,l,c),this.anchor.offset-=this.anchor.trigger.length),this.anchor.trigger.length||this.menu.close(),!0});h(this,"onShow",(t,e,o,r)=>{var i;if((i=this.options)!=null&&i.onShow)return this.options.onShow(this,e,o,r)});h(this,"onClickItem",(t,e)=>{!this.anchor||(this.options.autoDeleteTrigger&&this.deleteTrigger(),this.options.onClickItem(this,e,this.anchor))});h(this,"queryItems",(t,e)=>this.options.queryItems(this,e));h(this,"renderMenuItem",(t,e)=>{var r,i;return(i=(r=this.options).renderMenuItem)==null?void 0:i.call(r,this,e)});this.editor=t,this.options=e,this.menu=new jB(t,{id:e.id,showLoading:e.showLoading,loadingElement:e.loadingElement,placeholder:e.placeholder,noResultMessage:e.noResultMessage,highlight:e.highlight,onShow:this.onShow,onClickItem:this.onClickItem,queryItems:this.queryItems,renderMenuItem:this.renderMenuItem}),t.input.addHandler(this),t.addListener("selectionChanged",this.handleSelectionChanged)}handleBeforeKeyDown(t,e){var o;return!((o=this.menu)!=null&&o.isVisible)||ad(e.key)?!1:Em(e)&&!Ho(e)?(setTimeout(()=>{this.resetItems()}),!1):dd(e)?(this.menu.close(),!0):(this.menu.handleKeydown(e),!0)}popup(t,e,o,r){this.anchor={blockId:q(t),offset:e,leftText:o,trigger:r};const i=U(H(t)),s=J(t);this.menu.popup(i,s,e)}handleAfterInsertText(t,e,o,r,i){var u;const s=t.selection.range.start;if(!s.isSimple()||e==="root"&&o===0)return!1;const{blockId:l,offset:c}=s,a=t.getBlockByIndex(e,o);if(q(a)!==l)return!1;if((u=this.menu)!=null&&u.isVisible)this.resetItems();else if(this.options.trigger.indexOf(i)!==-1){if(r>0&&this.options.needSpaceBeforeTrigger&&t.getBlockString(a)[r-1]!==" ")return!1;const f=bt(Yl(t,a,c));this.popup(a,c,f,i)}return!1}handleUpdateCompositionText(t,e,o,r,i){var a;const s=t.selection.range.start;if(!s.isSimple())return!1;const{blockId:l}=s,c=t.getBlockByIndex(e,o);return q(c)!==l||(a=this.menu)!=null&&a.isVisible&&this.resetItems(),!1}resetItems(){var l;if(!((l=this.menu)!=null&&l.isVisible))return;const t=this.editor,e=t.selection.range.start;if(!e.isSimple())return;const{blockId:o,offset:r}=e,i=t.getBlockById(o),s=bt(Yl(t,i,r));if(d(ph,this.anchor,"no anchor"),s.startsWith(this.anchor.leftText)){const c=s.substring(this.anchor.leftText.length);ph.debug(`search text: ${c}`),this.menu.handleSearchText(c)}}destroy(){var t;this.editor.input.removeHandler(this),this.editor.removeListener("selectionChanged",this.handleSelectionChanged),(t=this.menu)==null||t.destroy()}}function HB(){const n={};for(let t=1;t<=8;t++)n[`heading-${t}`]={shortcut:`/h${t}`};return n}const FB={"insert-hr":{shortcut:"/hr"},"insert-uml":{shortcut:"/uml"},"insert-table":{shortcut:"/table"},"insert-image":{shortcut:"/image"},"insert-code":{shortcut:"/code"},"insert-link":{shortcut:"/link"},"insert-drawio":{shortcut:"/uml"},"insert-video":{shortcut:"/video"},"insert-audio":{shortcut:"/audio"},"insert-math":{shortcut:"/math"},"insert-webPage":{shortcut:"/web"},"insert-bilibili":{shortcut:"/bilibili"},"insert-youku":{shortcut:"/youku"},"insert-figma":{shortcut:"/figma"},"insert-modao":{shortcut:"/modao"},"insert-tencent":{shortcut:"/tencent"},"insert-unordered":{shortcut:"/bl"},"insert-ordered":{shortcut:"/nu"},"insert-checkbox":{shortcut:"/todo"},"insert-quote":{shortcut:"/quote"},...HB()};function me(n){var t;return(t=FB[n])==null?void 0:t.shortcut}function zB(n){var t;return(t=n.subText)!=null?t:""}const xn=B("table-dom");function Bo(n){return`${q(n)}_scroll`}function jt(n){const t=n.querySelector("div[data-type=table-content] >table");return d(xn,t instanceof HTMLTableElement,"invalid table"),t}function Tn(n,t){const o=n.getCustom(Bo(t)).contentElement.firstElementChild;d(xn,o instanceof HTMLElement,"invalid table content");let r=o.querySelector(":scope >div[data-type=table-tools]");return r||(r=b("div",[],o),r.setAttribute("data-type","table-tools")),d(xn,r,"no table tools"),r}function p5(n){const t=[];return Array.from(n.rows).forEach(e=>{t.push(...Array.from(e.cells))}),t}function ys(n){const t=n.querySelector(":scope div[data-type=editor-container]");return d(xn,t,"no child container in cell"),t}function UB(n){const o=p5(n).map(r=>{const i=ys(r),s=U(i),l=r.colSpan,c=r.rowSpan;return`${s}/${l}/${c}`}).join();return Ti.default(o)}function Ht(n){return ot(n)==="table"}function bh(n){const t=H(n);if(pt(t))return null;const e=F(t);return d(xn,e,"no parent block"),Ht(e)?t:bh(e)}function Me(n){if(Ht(n))return n;const t=H(n);if(pt(t))return null;const e=F(t);return d(xn,e,"no parent block"),Ht(e)?e:Me(e)}function VB(n,t){const e=n.querySelector("colgroup");d(xn,e,"no colgroup");const o=e.children[t];return d(xn,o,"no col"),d(xn,o instanceof HTMLTableColElement,`invalid col: ${o.tagName}`),o}function C5(n){try{return jt(n),!0}catch{return!1}}function qB(n){return Rt(n).querySelector(":scope > .block-helper")}function b5(n){const t=F(n.contentElement);d(xn,t,"no block");const e=qB(t);if(e){const o=Math.min(n.contentElement.offsetLeft,n.rootElement.scrollLeft),r=t.getBoundingClientRect().width;e.style.right=`${o+r}px`}}const Re=B("doc-table-grid");class WB{constructor(t){h(this,"_cells",[]);for(let e=0;e<t;e++)this._cells.push(void 0)}cols(){return this._cells.length}setCell(t,e){d(Re,t>=0&&t<this.cols(),`set cell, invalid col: ${t}`),this._cells[t]=e}getCell(t){d(Re,t>=0&&t<this.cols(),`get cell, invalid col: ${t}`);const e=this._cells[t];return d(Re,e,"get cell, no cell"),e}getCellAllowEmpty(t){return d(Re,t>=0&&t<this.cols(),`get cell, invalid col, ${t}`),this._cells[t]}getNextNonVirtualCell(t){return this._cells.slice(t+1).find(e=>!e.virtual)}forEach(t){this._cells.forEach(t)}}class Ec{constructor(t){h(this,"_data");h(this,"_rows");this._data=t,this._rows=[];for(let e=0;e<this.rowCount;e++)this._rows.push(new WB(this.colCount));this.fillGrid(),d(Re,t.colsWidth,"no colsWidth"),d(Re,this.colCount===t.colsWidth.length,"invalid col count")}get rowCount(){return this._data.rows}get colCount(){return this._data.cols}getNextEmptyCell(t,e){let o=t,r=e;for(;;){if(o+=1,o===this.colCount&&(o=0,r+=1),r>=this.rowCount)return null;if(this._rows[r].getCellAllowEmpty(o)===void 0)return{col:o,row:r}}}fillGrid(){const t=this._data.children;d(Re,t,"no children");let e=0,o=0;t.forEach((r,i)=>{const s=this._data[`${r}_colSpan`]||1,l=this._data[`${r}_rowSpan`]||1;for(let a=0;a<l;a++)for(let u=0;u<s;u++)this._rows[o+a].setCell(e+u,{col:e,row:o,containerId:r,virtual:u!==0||a!==0,colSpan:s,rowSpan:l});const c=this.getNextEmptyCell(e,o);c?(e=c.col,o=c.row):d(Re,i===t.length-1,`invalid table data, no next empty cell: ${JSON.stringify(this._data)}`)}),this._rows.forEach(r=>{r.forEach(i=>{d(Re,i,"no cell"),d(Re,i.containerId,"no containerId")})})}getCell(t){const{col:e,row:o}=t,r=this._rows[o];d(Re,r,`get cell, no row: ${o}`);const i=r.getCell(e);return d(Re,i,`get cell, no cell: ${e}`),i}getRow(t){const e=this._rows[t];return d(Re,e,`get row, no row: ${t}`),e}forEach(t){this._rows.forEach(t)}}const Ic=B("table-data");function GB(n){const t=n.firstElementChild;return d(Ic,t,"no child element for cell"),d(Ic,bn(t),"cell first child is not a container"),d(Ic,Ye(t),"cell first child is not a container"),t}function ZB(n){const t=F(n);d(Ic,t,"no parent block for table");const e=[],o={};Array.from(n.rows).forEach(l=>{Array.from(l.cells).forEach(c=>{const a=GB(c),u=U(a);e.push(u),(c.colSpan>1||c.rowSpan>1)&&(o[`${u}_colSpan`]=c.colSpan,o[`${u}_rowSpan`]=c.rowSpan)})});const r=n.rows.length,i=Array.from(n.rows[0].cells).map(l=>l.colSpan).reduce((l,c)=>l+c,0);return{id:q(t),type:ot(t),rows:r,cols:i,children:e,colsWidth:Array(i).fill(100),...o}}function or(n){return new Ec(n)}function YB(n){return or(ZB(n))}const Gt=B("table-grid"),QB=60;class KB{constructor(t,e){h(this,"containerId");h(this,"row");h(this,"col");h(this,"colSpan");h(this,"rowSpan");h(this,"virtual");h(this,"table");this.table=t,this.containerId=e.containerId,this.row=e.row,this.col=e.col,this.colSpan=e.colSpan,this.rowSpan=e.rowSpan,this.virtual=e.virtual}get cell(){const e=this.container.closest("td");return d(Gt,e,"no parent cell for child container"),e}get container(){const t=this.table.querySelectorAll(`[data-container-id=${this.containerId}]`);d(Gt,t.length===1,"containers !== 1"),d(Gt,bn(t[0]),"not a container");const e=t[0];return d(Gt,Ye(e),"not a child container"),e}}class JB{constructor(t,e){h(this,"_cells",[]);e.forEach(o=>{this._cells.push(new KB(t,o))})}get cells(){return this._cells}getCell(t){return d(Gt,t<this._cells.length,"get cell, invalid col"),this._cells[t]}getNextNonVirtualCell(t){return this._cells.slice(t+1).find(e=>!e.virtual)}getSpannedCell(){return this._cells.find(t=>t.virtual||t.colSpan>1||t.rowSpan>1)}}const Sf=class{constructor(t){h(this,"_rows",[]);this.table=t,YB(t).forEach(r=>{this._rows.push(new JB(t,r))});const o=this.colCount;this._rows.forEach(r=>{d(Gt,r.cells.length===o,"row.cells.length !== colCount")})}get rowCount(){return this._rows.length}get colCount(){return this._rows.length===0?0:(d(Gt,this.rowCount>0,"rowCount <= 0"),this.getRow(0).cells.length)}getRow(t){return this._rows[t]}getCell(t){const e=this.getRow(t.row);return d(Gt,e,"no row"),e.getCell(t.col)}getCellContainer(t){return this.getCell(t).container}getFirstCellContainer(){return this.getCellContainer({row:0,col:0})}getLastCellContainer(){const t=this.rowCount-1,e=this.colCount-1;return this.getCellContainer({row:t,col:e})}getColumnCells(t){d(Gt,t>=0&&t<this.colCount,"colIndex out of range");const e=this.rowCount,o=[];for(let r=0;r<e;r++){const i=this.getCell({row:r,col:t});o.push(i)}return o}toRealCells(t){const e=[];return t.forEach(o=>{const r=this.getRealCell(o);e.findIndex(i=>i.containerId===r.containerId)===-1&&e.push(r)}),e}getColumnRealCells(t){const e=this.getColumnCells(t);return this.toRealCells(e)}getRowRealCells(t){const e=this.getRow(t).cells;return this.toRealCells(e)}getFirstSpannedCell(t){d(Gt,t>=0&&t<this.colCount,"colIndex out of range");const e=this.rowCount;for(let o=0;o<e;o++){const r=this.getCell({row:o,col:t});if(r.virtual||r.colSpan>1||r.rowSpan>1)return r}}getRealCell(t){const e=this.getCell(t);if(!e.virtual)return e;const o=this.getCellById(e.containerId);return d(Gt,!o.virtual,"found a virtual cell"),o}getColumnSpannedRange(t){const e=this.getColumnRealCells(t);let o=1e5,r=-1;return e.forEach(i=>{o=Math.min(i.col,o),r=Math.max(i.col+i.colSpan-1,r)}),d(Gt,o<=r,"min > max"),d(Gt,o>=0,"min < 0"),d(Gt,r<this.colCount,"max >= colCount"),[o,r]}getRowSpannedRange(t){const e=this.getRowRealCells(t);let o=1e5,r=-1;return e.forEach(i=>{o=Math.min(i.row,o),r=Math.max(i.row+i.rowSpan-1,r)}),d(Gt,o<=r,"min > max"),d(Gt,o>=0,"min < 0"),d(Gt,r<this.rowCount,"max >= rowCount"),[o,r]}getSpannedRange(t,e){const o=Math.min(t.row,e.row),r=Math.max(t.row,e.row),i=Math.min(t.col,e.col),s=Math.max(t.col,e.col),l=[];for(let C=o;C<=r;C++)for(let k=i;k<=s;k++)l.push(this.getCell({row:C,col:k}));const c=this.toRealCells(l);let a=1e4,u=1e4,f=-1,m=-1;return c.forEach(C=>{u=Math.min(C.col,u),a=Math.min(C.row,a),m=Math.max(C.col+C.colSpan-1,m),f=Math.max(C.row+C.rowSpan-1,f)}),[{row:a,col:u},{row:f,col:m}]}getAllCells(){return this.getCells({col:0,row:0},{col:this.colCount-1,row:this.rowCount-1})}sub(t,e){const o=[];for(let r=t.row;r<=e.row;r++){const i=[];for(let s=t.col;s<=e.col;s++){const l=this.getCell({row:r,col:s});i.push(l)}o.push(i)}return o}getAllContainers(){return this.getAllCells().map(e=>e.container)}getCells(t,e){const o=[],r=this.getSpannedRange(t,e),i=r[0],s=r[1],l=Math.min(i.row,s.row),c=Math.max(i.row,s.row),a=Math.min(i.col,s.col),u=Math.max(i.col,s.col);for(let f=l;f<=c;f++)for(let m=a;m<=u;m++){const C=this.getCell({row:f,col:m});C.virtual||o.push(C)}return o}map(t){const e=[];for(let o=0;o<this.rowCount;o++){const r=[];for(let i=0;i<this.colCount;i++){const s=this.getCell({row:o,col:i});r.push(t(s))}e.push(r)}return e}getBottomCell(t){const e=this.rowCount;let o=t,r=t.row;for(;o.containerId===t.containerId;){if(r+=1,r>=e)return null;o=this.getCell({row:r,col:t.col})}return this.getRealCell(o)}getTopCell(t){let e=t,o=t.row;for(;e.containerId===t.containerId;){if(o-=1,o<0)return null;e=this.getCell({row:o,col:t.col})}return this.getRealCell(e)}get cells(){let t=[];return this._rows.forEach(e=>{t=t.concat(e.cells)}),t}getVirtualCellContainersGrid(){return this.map(t=>t.containerId)}static virtualCellContainersGridToChildren(t){const e=t,o=[];return e.forEach(r=>{r.forEach(i=>{o.indexOf(i)===-1&&o.push(i)})}),o}getCellById(t){const o=this.cells.find(r=>r.containerId===t);return d(Gt,o,"cell not found"),o}getCellByCellElement(t){const e=ys(t);return this.getCellByContainerId(U(e))}getCellByContainerId(t){return this.getCellById(t)}static fromTable(t){const e=UB(t),o=this.caches.getSync(e,()=>(Gt.debug("create table grid"),new Sf(t)));return o.table!==t?(this.caches.delete(e),this.fromTable(t)):o}static fromBlock(t){return this.fromTable(jt(t))}};let et=Sf;h(et,"caches",new om(QB));function xc(n,t){Object.entries(n).forEach(([e])=>{e.startsWith(`${t}/`)&&delete n[e]})}const XB=B("table-selection-range");function an(n,t,e){var I,M,R,$;const o=et.fromBlock(n),r=t,i=e,s=o.getCellByContainerId(r.childContainerId),l=o.getCellByContainerId(i.childContainerId),c=r.custom,a=i.custom,u=(I=c==null?void 0:c.rowIndex)!=null?I:s.row,f=(M=c==null?void 0:c.colIndex)!=null?M:s.col,m=(R=a==null?void 0:a.rowIndex)!=null?R:l.row+l.rowSpan-1,C=($=a==null?void 0:a.colIndex)!=null?$:l.col+l.colSpan-1,k=Math.min(u,m),w=Math.max(u,m),y=Math.min(f,C),S=Math.max(f,C);return{fromRow:k,toRow:w,fromCol:y,toCol:S}}function kh(n,t){const e=new Set,o=new Set,r=n.selection.range;if(!r.isSimple()&&r.start.blockId===q(t)){const i=et.fromBlock(t),{start:s,end:l}=r;d(XB,!s.isSimple()&&!l.isSimple(),"invalid range");const{fromCol:c,toCol:a,fromRow:u,toRow:f}=an(t,s,l);if(u===0&&f===i.rowCount-1)for(let m=c;m<=a;m++)o.add(m);if(c===0&&a===i.colCount-1)for(let m=u;m<=f;m++)e.add(m)}return{selectedRows:e,selectedColumns:o}}const zr=B("delete-columns");function k5(n,t,e){const{start:o,end:r}=e;if(o.blockId!==r.blockId||e.isSimple()||n.getBlockById(o.blockId)!==t||ot(t)!=="table")return!1;const{fromRow:s,toRow:l}=an(t,e.start,e.end),c=et.fromBlock(t);return s===0&&l===c.rowCount-1}function vh(n){var M;const t=n.getEditor(),e=t.getBlockById(n.start.blockId);if(!k5(t,e,n))return;if(n.isSimple()){t.deleteBlock(e);return}const{fromCol:o,toCol:r}=an(e,n.start,n.end),i=et.fromBlock(e);if(o===0&&r===i.colCount-1){t.deleteBlock(e);return}const s=new Set,l=i.map(R=>R.containerId);for(let R=0;R<l.length;R++){const $=l[R];for(let Z=o;Z<=r;Z++){const rt=$[Z];s.add(rt)}$.splice(o,r-o+1)}const c=new Set(l.flat()),a=new Set(Array.from(s).filter(R=>!c.has(R))),u=r-o+1,f=new Map,m=new Map;s.forEach(R=>{if(a.has(R))return;const $=i.getCellByContainerId(R);if(d(zr,$.colSpan>1,"invalid effected cell, colSpan === 1"),$.col<o){d(zr,c.has(R),"invalid effected cell, not exists");let yt=$.col+$.colSpan-1;yt>r&&(yt=r);const le=yt-o+1,eo=$.colSpan-le;f.set(R,eo);return}d(zr,$.col<=r,"invalid effected cell, col > endCol");const Z=$.col,rt=$.col+$.colSpan-1,st=$.col-o,mt=rt-Z+1-u+st;d(zr,mt>0,"invalid effected cell, newSpanned <= 0");const ut=yn(t.doc);m.set(R,{newContainerId:ut,colSpan:mt})});for(let R=0;R<l.length;R++){const $=l[R];for(let Z=o;Z<$.length;Z++){const rt=$[Z],st=m.get(rt);st&&($[Z]=st.newContainerId)}}const C=Y.default(t.getBlockData(e));C.colsWidth.splice(o,r-o+1),a.forEach(R=>{xc(C,R)}),f.forEach((R,$)=>{d(zr,R>=1,"invalid modified colSpan, colSpan < 1"),R===1?C[`${$}_colSpan`]=void 0:C[`${$}_colSpan`]=R}),m.forEach((R,$)=>{xc(C,$);const{newContainerId:Z,colSpan:rt}=R;d(zr,rt>=1,"invalid newContainerData, colSpan < 1"),rt>1&&(C[`${Z}_colSpan`]=rt);const st=i.getCellByContainerId($).rowSpan;st>1&&(C[`${Z}_rowSpan`]=st)});const w=(M=l[0][o])!=null?M:l[0][o-1],y=t.getChildContainerData(w)[0],S=et.virtualCellContainersGridToChildren(l),I={...C,cols:C.cols-u,children:S};or(I),t.undoManager.runInGroup(()=>{t.updateBlockData(e,I,At(t,y.id,0)),t.deleteChildContainers(Array.from(a)),t.deleteChildContainers(Array.from(m.keys()))})}const Ur=B("delete-rows");function v5(n,t,e){const{start:o,end:r}=e;if(o.blockId!==r.blockId||e.isSimple()||n.getBlockById(o.blockId)!==t||ot(t)!=="table")return!1;const{fromCol:s,toCol:l}=an(t,e.start,e.end),c=et.fromBlock(t);return s===0&&l===c.colCount-1}function yh(n){const t=n.getEditor(),e=t.getBlockById(n.start.blockId);if(!v5(t,e,n))return;if(n.isSimple()){t.deleteBlock(e);return}const{fromRow:o,toRow:r}=an(e,n.start,n.end),i=et.fromBlock(e);if(o===0&&r===i.rowCount-1){t.deleteBlock(e);return}const s=new Set,l=i.map(I=>I.containerId);for(let I=r;I>=o;I--)l[I].forEach(R=>s.add(R)),l.splice(I,1);const c=new Set(l.flat()),a=new Set(Array.from(s).filter(I=>!c.has(I))),u=r-o+1,f=new Map,m=new Map;s.forEach(I=>{if(a.has(I))return;const M=i.getCellByContainerId(I);if(d(Ur,M.rowSpan>1,"invalid effected cell, rowSpan === 1"),M.row<o){d(Ur,c.has(I),"invalid effected cell, not exists");let mt=M.row+M.rowSpan-1;mt>r&&(mt=r);const ut=mt-o+1,yt=M.rowSpan-ut;f.set(I,yt);return}d(Ur,M.row<=r,"invalid effected cell, col > endCol");const R=M.row,$=M.row+M.rowSpan-1,Z=M.row-o,rt=$-R+1-u+Z;d(Ur,rt>0,"invalid effected cell, newSpanned <= 0");const st=yn(t.doc);m.set(I,{newContainerId:st,rowSpan:rt})});for(let I=o;I<l.length;I++){const M=l[I];for(let R=0;R<M.length;R++){const $=M[R],Z=m.get($);Z&&(M[R]=Z.newContainerId)}}const C=Y.default(t.getBlockData(e));a.forEach(I=>{xc(C,I)}),f.forEach((I,M)=>{d(Ur,I>=1,"invalid modified rowSpan, rowSpan < 1"),I===1?delete C[`${M}_rowSpan`]:C[`${M}_rowSpan`]=I}),m.forEach((I,M)=>{xc(C,M);const{newContainerId:R,rowSpan:$}=I;d(Ur,$>=1,"invalid newContainerData, rowSpan < 1"),$>1&&(C[`${R}_rowSpan`]=$);const Z=i.getCellByContainerId(M).colSpan;Z>1&&(C[`${R}_colSpan`]=Z)});const k=l[o]?l[o][0]:l[o-1][0],w=t.getChildContainerData(k)[0],y=et.virtualCellContainersGridToChildren(l),S={...C,rows:C.rows-u,children:y};or(S),t.undoManager.runInGroup(()=>{t.updateBlockData(e,S,At(t,w.id,0)),t.deleteChildContainers(Array.from(a)),t.deleteChildContainers(Array.from(m.keys()))})}const ws=B("table-range");function Tc(n){d(ws,!n.isSimple(),"must be complex selection range");const{anchor:t,focus:e}=n;d(ws,!t.isSimple(),"invalid start pos type"),d(ws,!e.isSimple(),"invalid end pos type");const o=n.getEditor();d(ws,t.blockId===e.blockId,"invalid range, not same block");const r=o.getBlockById(t.blockId);d(ws,ot(r)==="table","invalid block type, not a table block");const i=jt(r),s=et.fromTable(i),l=s.getCellByContainerId(t.childContainerId),c=s.getCellByContainerId(e.childContainerId),a=Math.min(l.row,c.row),u=Math.max(l.row,c.row),f=Math.min(l.col,c.col),m=Math.max(l.col,c.col),C=s.getCell({row:a,col:f}),k=s.getCell({row:u,col:m});return{editor:o,block:r,table:i,startCell:C,endCell:k,startRow:a,startCol:f,endRow:u,endCol:m}}const wh=B("split-cell");function Bh(n,t,e){const o=et.fromBlock(t),r=o.getRealCell(e);d(wh,!r.virtual,"should not split virtual cell"),d(wh,r.colSpan>1||r.rowSpan>1,"cell does not has span data");const i=o.getVirtualCellContainersGrid();for(let f=0;f<r.rowSpan;f++)for(let m=0;m<r.colSpan;m++){if(f===0&&m===0)continue;const C=f+r.row,k=m+r.col,w=yn(n.doc);i[C][k]=w}const s=n.getBlockData(t),l=Y.default(s);l[`${r.containerId}_colSpan`]=null,l[`${r.containerId}_rowSpan`]=null,l.children=et.virtualCellContainersGridToChildren(i);const a=n.getChildContainerData(r.containerId)[0];d(wh,a,"no child block");const u=At(n,a.id,0);or(l),n.updateBlockData(t,l,u)}function tE(n,t,e){e.forEach(o=>{const r=et.fromBlock(t).getCell(o);(r.virtual||r.colSpan>1||r.rowSpan>1)&&Bh(n,t,o)})}function y5(n,t,e){if(e.isSimple())return!1;const{start:o,end:r}=e;if(o.blockId!==r.blockId||n.getBlockById(o.blockId)!==t||ot(t)!=="table")return!1;const{startCell:s,endCell:l}=Tc(e);return!(s.cell!==l.cell||s.colSpan===1&&s.rowSpan===1)}function Eh(n){const{editor:t,block:e,startRow:o,startCol:r,endRow:i,endCol:s}=Tc(n),l=[];for(let c=o;c<=i;c++)for(let a=r;a<=s;a++)l.push({row:c,col:a});return tE(t,e,l),!0}const Vr=B("merge-cells");function w5(n,t,e){if(e.isSimple())return!1;const{start:o,end:r}=e;if(o.blockId!==r.blockId||n.getBlockById(o.blockId)!==t||ot(t)!=="table")return!1;const{startCell:s,endCell:l}=Tc(e);return s.cell!==l.cell}function B5(n){const t=Tc(n),e=t.endCell,o=e.row+e.rowSpan-1,r=e.col+e.colSpan-1,i=q(t.block),s=t.editor;Eh(n);const l=s.getBlockById(i),c=jt(l),{startRow:a,startCol:u}=t,f=Y.default(s.getBlockData(l));d(Vr,f.children,"no table children");const m=et.fromTable(c),C=[];for(let mt=a;mt<=o;mt++)for(let ut=u;ut<=r;ut++){const yt=m.getCell({row:mt,col:ut});d(Vr,!yt.virtual,"cell is virtual"),C.push(yt)}d(Vr,C.length>0,"no selected cells");const k=C[0],w=C.slice(1),y=m.getCellByContainerId(k.containerId).container,S=[];w.forEach(mt=>{const ut=m.getCellByContainerId(mt.containerId).container,yt=U(ut);if(!Sd(s,ut)){const le=$0(s,yt);s.insertDocAt(y,Ge(y),le)}S.push(yt)});const I=U(y),M=r-u+1,R=o-a+1;f[`${I}_colSpan`]=M,f[`${I}_rowSpan`]=R,S.forEach(mt=>{d(Vr,f.children,"no table children");const ut=f.children.indexOf(mt);d(Vr,ut>0,"no deleted container"),f.children.splice(ut,1)});const $=f,rt=s.getChildContainerData(I)[0];d(Vr,rt,"no child block");const st=At(s,rt.id,0);or($),s.updateBlockData(l,$,st),s.deleteChildContainers(S)}const Ih=10,eE=["table/merge-cells","table/split-cell","table/insert-column","table/insert-row","table/delete-rows","table/delete-columns","table/delete"];class xh{constructor(){h(this,"id","TableBlockCommandProvider")}getAvailableCommands(t,e,o){if(ot(e)!=="table")return[];const r={blockId:q(e),blockKind:Qe(t,e),blockType:ot(e)},i=[];w5(t,e,o)&&i.push({id:"table/merge-cells",name:T.t("table.mergeCell"),icon:zw,groupIndex:Ih,...r}),y5(t,e,o)&&i.push({id:"table/split-cell",name:T.t("table.splitCell"),icon:Uw,groupIndex:Ih,...r});const s=k5(t,e,o),l=v5(t,e,o);return s&&l&&i.push({id:"table/delete",name:T.t("table.deleteTable"),icon:Vw,groupIndex:Ih,...r}),i}executeCommand(t,e,o,r,i,s){return ot(e)!=="table"||!new Set(eE).has(r.id)?!1:r.id==="table/merge-cells"?(B5(o),!0):r.id==="table/split-cell"?(Eh(o),!0):r.id==="table/delete-columns"?(vh(o),!0):r.id==="table/delete-rows"?(yh(o),!0):r.id==="table/delete"?(t.deleteBlock(e),!0):!1}}var E5=(n=>(n.COL_TITLE_TABLE="col-title-table",n.COL_TITLE_ITEM="col-title-item",n.STRIPE_STYLE_TABLE="stripe-style-table",n.NO_BORDER="table-no-border",n))(E5||{});const Th=6,Bs=20,Sh="table-cell-menu-btn";function nE(n,t){if(!n.isBlockWritable(t))return;const o={...Y.default(n.getBlockData(t)),hasColTitle:!0};n.updateBlockData(t,o)}function oE(n,t){if(!n.isBlockWritable(t))return;const o={...Y.default(n.getBlockData(t)),hasColTitle:!1};n.updateBlockData(t,o)}function rE(n,t){if(!n.isBlockWritable(t))return;const o={...Y.default(n.getBlockData(t)),hasRowTitle:!0};n.updateBlockData(t,o)}function iE(n,t){if(!n.isBlockWritable(t))return;const o={...Y.default(n.getBlockData(t)),hasRowTitle:!1};n.updateBlockData(t,o)}function sE(n,t){if(!n.isBlockWritable(t))return;const o={...Y.default(n.getBlockData(t)),isStripeStyle:!0};n.updateBlockData(t,o)}function lE(n,t){if(!n.isBlockWritable(t))return;const o={...Y.default(n.getBlockData(t)),isStripeStyle:!1};n.updateBlockData(t,o)}function cE(n,t,e){if(!n.isBlockWritable(t))return;const r={...Y.default(n.getBlockData(t)),noBorder:!e};n.updateBlockData(t,r)}const Dh=B("get-selected-containers");function Lh(n,t,e,o){d(Dh,e.blockId===o.blockId,"only allow select in single table block"),d(Dh,q(t)===e.blockId,"only allow select in single table block");const r=et.fromBlock(t),i=r.getCellByContainerId(e.childContainerId),s=r.getCellByContainerId(o.childContainerId);if(e.custom===void 0||o.custom===void 0)return r.getCells(i,s).map(y=>r.getCellContainer(y));const{fromCol:l,toCol:c,fromRow:a,toRow:u}=an(t,e,o),f=new Set,m=[];return r.sub({row:a,col:l},{row:u,col:c}).forEach(k=>{k.forEach(w=>{const y=r.getCellByContainerId(w.containerId);y.col<l||y.row<a||y.col+y.colSpan-1>c||y.row+y.rowSpan-1>u||f.has(w.containerId)||(f.add(w.containerId),m.push(y.container))})}),m}function aE(n,t,e){d(Dh,t.blockId===e.blockId,"only allow select in single table block");const o=n.getBlockById(t.blockId);return Lh(n,o,t,e)}const rr=B("table-cell-dom");function dE(n,t,e){let o=n.getBlockById(e);for(;o;){const r=o.closest("td");d(rr,r,"no parent cell");const i=F(r);if(d(rr,i,"no parent block"),i===t)return r;o=i}return d(rr,!1,"filed to get cell by child block id"),null}function Gn(n,t,e){if(n.getBlockById(e.blockId)===t&&!e.isSimple())return d(rr,e.childContainerId,"block position must have childContainerId attribute"),e;const r=dE(n,t,e.blockId),i=U(ys(r));return wt(t,i)}function Mh(n,t){const e=n.selection.range,o=Gn(n,t,e.start),r=Gn(n,t,e.end);return an(t,o,r)}function I5(n,t,e,o){d(rr,Ht(t),"invalid table block");const r=Tn(n,t),i=()=>{const l=r.querySelector(".table-border-bar-container.top");d(rr,l,"no top border bar container"),l.querySelectorAll(".table-border-bar-cell.top").forEach(a=>{const u=parseInt(a.getAttribute("data-top-index")||"0",10);o.includes(u)?A(a,"danger"):z(a,"danger")})},s=()=>{const l=r.querySelector(".table-border-bar-container.left");d(rr,l,"no left border bar container"),l.querySelectorAll(".table-border-bar-cell.left").forEach(a=>{const u=parseInt(a.getAttribute("data-left-index")||"0",10);e.includes(u)?A(a,"danger"):z(a,"danger")})};i(),s()}function qr(n,t,e=!0,o){const i=et.fromBlock(t).map(u=>u),{fromCol:s,toCol:l,fromRow:c,toRow:a}=Mh(n,t);for(let u=0;u<i.length;u++){const f=i[u];for(let m=0;m<f.length;m++){const C=f[m],k=o?m>=s&&m+C.colSpan-1<=l:u>=c&&u+C.rowSpan-1<=a;e&&k?C.virtual||A(C.cell,"danger"):C.virtual||z(C.cell,"danger")}}}function Wr(n,t,e=!0,o){const r=new Set,i=new Set;if(!e){I5(n,t,Array.from(r),Array.from(i));return}const{fromCol:s,toCol:l,fromRow:c,toRow:a}=Mh(n,t);if(o)for(let u=s;u<=l;u++)i.add(u);else for(let u=c;u<=a;u++)r.add(u);I5(n,t,Array.from(r),Array.from(i))}function x5(n,t,e){const{fromCol:o,toCol:r,fromRow:i,toRow:s}=Mh(n,t),l=et.fromBlock(t);let c=null,a=null;return e?(c=l.getCell({col:o,row:0}),a=l.getCell({col:r,row:l.rowCount-1}),qt(n,{anchor:wt(t,c.containerId,{colIndex:o,rowIndex:0}),focus:wt(t,a.containerId,{colIndex:r,rowIndex:l.rowCount-1})})):(c=l.getCell({col:0,row:i}),a=l.getCell({col:l.colCount-1,row:s}),qt(n,{anchor:wt(t,c.containerId,{colIndex:0,rowIndex:i}),focus:wt(t,a.containerId,{colIndex:l.colCount-1,rowIndex:s})}))}function uE(n,t){const e=n.selection.range,o=Gn(n,t,e.start),r=Gn(n,t,e.end);return Lh(n,t,o,r)}const T5=["style-bg-color-0","style-bg-color-1","style-bg-color-2","style-bg-color-3","style-bg-color-4","style-bg-color-5","style-bg-color-6","style-bg-color-7","style-bg-color-8","style-bg-color-9","style-bg-color-10","style-bg-color-11","style-bg-color-12","style-bg-color-13"];function S5(n){return`style-bg-color-${n}`}function Es(n){return`${n}_background`}function hE(n,t,e){const o=jt(n),s=(e!=null?e:et.fromTable(o)).getCell(t).cell;for(let l=0;l<T5.length;l++){const c=T5[l];if(nt(s,c))return c}}function D5(n,t,e){if(!n.isBlockWritable(t))return;const o=n.selection.range,i={...Y.default(n.getBlockData(t))},s=Gn(n,t,o.start),l=Gn(n,t,o.end);if(o.isSimple()){const c=s.childContainerId;e===-1?i[Es(c)]=void 0:i[Es(c)]=S5(e)}else{const c=et.fromBlock(t),a=an(t,s,l),u=new Set;for(let f=a.fromRow;f<=a.toRow;f++)for(let m=a.fromCol;m<=a.toCol;m++){const C=c.getCell({row:f,col:m});!u.has(C.containerId)&&C.col>=a.fromCol&&C.row>=a.fromRow&&C.col+C.colSpan-1<=a.toCol&&C.row+C.rowSpan-1<=a.toRow&&(u.add(C.containerId),e===-1?i[Es(C.containerId)]=void 0:i[Es(C.containerId)]=S5(e))}}n.updateBlockData(t,i)}function fE(n,t,e){if(!n.isBlockWritable(t))return;const r={...Y.default(n.getBlockData(t)),chart:e};n.updateBlockData(t,r)}const L5=B("table-chart");function mE(n,t){const e=Tn(n,t);if(e){const o=e.querySelector(".editor-table-chart");if(o){const r=o.chartObject;r&&r.destroy(),o.remove()}}}async function gE(n,t){if(!n.isBlockWritable(t))return;if(!!!n.getBlockData(t).chart){mE(n,t);return}const r=[],i=et.fromBlock(t),s=["line","bar","pie","radar"];let l=i.getCell({row:0,col:0}).container.innerText.trim().toLowerCase();new Set(s).has(l)||(l=s[0]);const c=[];for(let w=1;w<i.colCount;w++)c.push(i.getCell({row:0,col:w}).container.innerText);for(let w=1;w<i.rowCount;w++){const y=i.getCell({row:w,col:0}),I=y.container.innerText,M=[];for(let le=1;le<i.colCount;le++){const eo=i.getCell({row:w,col:le}).container.innerText,ee=Number.parseFloat(eo)||0;M.push(ee)}let R;const $=hE(t,y,i);$?R=window.getComputedStyle(n.rootElement).getPropertyValue(`--${$}`).trim():R=window.getComputedStyle(n.rootElement).getPropertyValue("--background-color").trim();let[Z,rt,st,mt]=R?Ka.fromString(R).toRgbaArray():[];if(!Z&&!rt&&!st&&!mt){const le=(w-1)%n.options.colors.length;R=n.options.colors[le],[Z,rt,st,mt]=Ka.fromString(R).toRgbaArray()}const ut=R,yt=Ka.fromRgba([Z,rt,st,mt/3]).toHexString();r.push({label:I,data:M,borderColor:ut,backgroundColor:yt,borderWidth:2})}const a=Tn(n,t);let u=null,f=a.querySelector(".editor-table-chart");f?u=f.chartObject:f=b("div",["editor-table-chart"],a);const m=f;d(L5,m,"no chart container");const C=n.getComponentOptions("table"),k=(C==null?void 0:C.chartCdn)||"https://cdn.jsdelivr.net/npm/chart.js@2.9.4/dist/Chart.min.js";try{await Po(k,"editor-chartjs"),u&&l!==u.config.type&&(u.destroy(),u=null,Array.from(f.querySelectorAll(".editor-chartjs-canvas")).forEach(S=>{S.remove()}));const w=Ja.default({},{type:l,data:{datasets:r,labels:c},options:{onClick:()=>{n.selection.selectBlock(t,0,0)}}});if(u)Ja.default(u.config,w),u.update();else{const S=b("canvas",["editor-chartjs-canvas"],m).getContext("2d");u=new window.Chart(S,w),f.chartObject=u}}catch(w){L5.error(`failed to resolve chart cdn: ${JSON.stringify(w)}`)}}async function M5(n,t){await qe.lock("updateTableChart");try{await gE(n,t)}finally{qe.release("updateTableChart")}}const R5=Xt.default(M5,1e3);let A5=null;function Rh(n,t,e){if(A5!==t&&(R5.flush(),A5=t),e.updateNow){M5(n,t);return}R5(n,t)}function Ah(n,t){Ht(t)&&Rh(n,t,{updateNow:!1})}function pE(n,t){Ht(t)&&Rh(n,t,{updateNow:!0})}const je={SCROLL:"container-scroll-tool",COMMON:"container-border-shadow",RIGHT:"container-right-border-shadow",LEFT:"container-left-border-shadow",LAYOUT_SIGN:"container-layout-border-shadow",ACTIVE:"active"},Sc={SCROLL_BAR:"container-scrollbar",FIXED:"fixed"},Eo={SCROLL_CONTAINER:"scroll-container",TOOL:"container-scroll-tool",CONTAINER:"scroll-container-root",MAC:"mac",SCROLL_AREA:"scroll-area"};function Dc(n,t){return n.containers.get(t)}function O5(n){return n.closest(`.${Eo.SCROLL_CONTAINER}`)}function dn(n){return n.firstElementChild}function Ae(n){return n.closest(`.${Eo.CONTAINER}`)}function Is(n){const t=Ae(n);let e=t.querySelector(`:scope >.${Eo.TOOL}`);return e||(e=b("div",[Eo.TOOL],t)),e}function CE(n){return Ae(n).firstElementChild}function Lc(n){let t;return n instanceof HTMLElement?t=n.offsetWidth:t=Number.parseInt(getComputedStyle(n).width,10),n.getBoundingClientRect().width/t}function He(n,t){const e=Lc(n);return t/e}function xs(n){const t=window.getComputedStyle(n),e=Lc(n);return{paddingBottom:parseFloat(t.paddingBottom)*e,paddingTop:parseFloat(t.paddingTop)*e,paddingLeft:parseFloat(t.paddingLeft)*e,paddingRight:parseFloat(t.paddingRight)*e}}function Gr(n){const t=Lc(n);return{scrollLeft:n.scrollLeft*t,scrollWidth:n.scrollWidth*t,clientWidth:n.clientWidth*t,clientHeight:n.clientHeight*t}}function bE(n,t){const e=Lc(n);return n[t]*e}function Oh(n,t){const e=Ae(t),o=Dc(n,e),r=(o==null?void 0:o.safeRightSpace)||0,i=(o==null?void 0:o.safeLeftSpace)||0,l=(o==null?void 0:o.locatingContainer).getBoundingClientRect(),c=e.getBoundingClientRect(),a=c.width;let u=Math.floor(c.left-l.left-i);u<0&&(u=0);let f=l.right;f-=r;let m=f-c.right;return m<0&&(m=0),u=Math.round(u),m=Math.round(m),{originWidth:a,maxLeft:u,maxRight:m}}function kE(n,t){const e=Oh(n,t),{maxLeft:o}=e;t.style.marginLeft=`${He(t,0-o)}px`,t.style.paddingLeft=`${He(t,o)}px`}function vE(n,t){const e=Oh(n,t);t.style.marginRight=`${He(t,0-e.maxRight)}px`}function yE(n){if(n!==document.documentElement&&n!==document.body)return n.getBoundingClientRect();const t=0,e=0,o=document.documentElement.clientWidth,r=document.documentElement.clientHeight;return new DOMRect(t,e,o,r)}const _5=B("scroll-bar-handle"),wE=2;function Zr(n){const t=Is(n);let e=t.querySelector(`.${Sc.SCROLL_BAR}`);return e||(e=b("div",[Sc.SCROLL_BAR],t)),d(_5,e instanceof HTMLDivElement,"invalid child for container tools"),e.firstElementChild||b("div",[],e),e}function Mc(n,t){const e=O5(t),o=Zr(e),{scrollWidth:r,clientWidth:i}=Gr(e),{paddingLeft:s,paddingRight:l}=xs(t);e.style.marginLeft="",e.style.paddingLeft="",e.style.marginRight="";const c=Oh(n,e),{originWidth:a,maxRight:u}=c;vE(n,e),kE(n,e);const f=r-i;d(_5,o.firstElementChild instanceof HTMLDivElement,"invalid child for scroll bar"),o.style.width=`${He(e,a+u-s-l)}px`,o.firstElementChild.style.width=`${He(e,a+u+f-s-l)}px`}function BE(n,t){const e=dn(n),{paddingLeft:o}=xs(e);if(nt(t,"fixed")){const i=Ae(n).getBoundingClientRect();t.style.left=`${He(n,i.left+o)}px`}else t.style.left=`${He(n,o)}px`}function Yr(n,t){var I;const e=n.getParentScrollContainer(),o=yE(e),r=t.getBoundingClientRect(),i=Zr(t),s=i.getBoundingClientRect(),l=Dc(n,Ae(t)),c=(l==null?void 0:l.barFloatWindowBottom)||0,a=dn(t),{paddingTop:u,paddingBottom:f}=xs(a),{scrollWidth:m,clientWidth:C}=Gr(t),k=document.documentElement.clientHeight-c,w=o.top+Gr(e).clientHeight-k,y=k+Math.min(0,w);if(m>C&&r.top+u<y-s.height&&r.bottom>y-s.height+f&&!((I=l==null?void 0:l.isSetScale)!=null&&I.call(l))){A(i,Sc.FIXED);const M=w>0?c:0;i.style.bottom=`${Math.max(document.documentElement.clientHeight-o.bottom,0)+wE+M}px`}else z(i,Sc.FIXED),i.style.bottom=`${He(t,f-s.height)}px`;BE(t,i)}class EE{constructor(t,e){h(this,"intersectionObserver");h(this,"handleIntersection",t=>{t.forEach(e=>{this.containers.get(Ae(e.target))?(this.handleIntersectionEntry(e),this.callback(e)):this.intersectionObserver.unobserve(e.target)})});h(this,"handleIntersectionEntry",t=>{const e=t.target;Yr(this.scrollCore,e);const o=dn(e);Mc(this.scrollCore,o)});this.scrollCore=t,this.callback=e;const r={root:this.scrollCore.getParentScrollContainer(),rootMargin:"20px",threshold:0};this.intersectionObserver=new IntersectionObserver(this.handleIntersection,r)}get containers(){return this.scrollCore.containers}bind(t){this.unbind(t),this.intersectionObserver.observe(t)}unbind(t){this.intersectionObserver.unobserve(t)}destroy(){this.intersectionObserver.disconnect()}}const ir=B("container-scroll-shadow");function N5(n,t,e){const o=n,r=t.getBoundingClientRect(),i=e.getBoundingClientRect(),{paddingTop:s,paddingBottom:l}=xs(e);o.style.top=`${He(t,i.top-r.top+s)}px`,o.style.bottom=`${He(t,r.bottom-i.bottom+l)}px`}function $5(n,t){const e=n;t<24?e.style.width=`${(t/3).toFixed(2)}px`:e.style.width=""}function IE(n){const t=Is(n);d(ir,t,"no container tools");let e=t.querySelector(`.${je.LEFT}`);if(!e){const l=dn(n),c=[je.COMMON,je.LEFT];e=b("div",c,t),d(ir,e instanceof HTMLDivElement,"invalid child for container tools"),N5(e,n,l)}d(ir,e instanceof HTMLElement,"invalid child for container tools");const r=Ae(n).getBoundingClientRect(),i=n.getBoundingClientRect();e.style.left=`${He(n,i.left-r.left)}px`;const s=Gr(n).scrollLeft;d(ir,e instanceof HTMLDivElement,"invalid child for container tools"),$5(e,s),A(e,je.ACTIVE)}function xE(n){const t=Is(n);let e=t.querySelector(`.${je.RIGHT}`);if(!e){const u=dn(n),f=[je.COMMON,je.RIGHT];e=b("div",f,t),d(ir,e instanceof HTMLDivElement,"no div, create shadow failed"),N5(e,n,u)}d(ir,e instanceof HTMLElement,"");const r=Ae(n).getBoundingClientRect(),i=n.getBoundingClientRect();e.style.right=`${He(n,r.right-i.right)}px`;const{scrollWidth:s,scrollLeft:l,clientWidth:c}=Gr(n),a=s-l-c;d(ir,e instanceof HTMLDivElement,"no shadow element"),$5(e,a),A(e,je.ACTIVE)}function TE(n){const e=Is(n).querySelector(`.${je.LEFT}`);e&&z(e,je.ACTIVE)}function SE(n){const e=Is(n).querySelector(`.${je.RIGHT}`);e&&z(e,je.ACTIVE)}function Ts(n){const{scrollLeft:t,scrollWidth:e,clientWidth:o}=Gr(n),r=dn(n),{paddingLeft:i,paddingRight:s}=xs(r),l=bE(r,"offsetLeft");e-i<=o-s||e-i<=t+o-s?SE(n):xE(n),r&&t>=l+i?IE(n):TE(n)}class DE{constructor(t,e){h(this,"resizeObserver");h(this,"handleResizeEntry",t=>{const e=t.target,o=dn(e);Ts(e),Mc(this.scrollCore,o),Yr(this.scrollCore,e),this.callback(e)});h(this,"handleContentResize",t=>{t.forEach(e=>{this.containers.get(Ae(e.target))?this.handleResizeEntry(e):this.unbind(e.target)})});this.scrollCore=t,this.callback=e,this.resizeObserver=new ResizeObserver(this.handleContentResize)}get containers(){return this.scrollCore.containers}bind(t){this.unbind(t),this.resizeObserver.observe(t)}unbind(t){this.resizeObserver.unobserve(t)}destroy(){this.resizeObserver.disconnect()}}const P5=B("container-scroll-observer");class LE{constructor(t,e){h(this,"handleContentScroll",t=>{const e=t.target;d(P5,e instanceof Element,"invalid target for scroll event");const o=Zr(e);o.removeEventListener("scroll",this.handleScroll);const r=!0;this.fixScrollXPos(e,e.scrollLeft,r),this.bind(o),Ts(e),this.callback(e)});h(this,"handleScroll",t=>{const e=t.target;d(P5,e instanceof HTMLElement,"");const o=e.scrollLeft,r=!1,i=CE(e);this.unbindContentScroll(i),this.fixScrollXPos(i,o,r),this.bindContentScroll(i),Ts(i),this.callback(i)});h(this,"handlePrevent",t=>{t.stopPropagation()});h(this,"bindContentScrollCore",t=>{this.unbindContentScroll(t),t.addEventListener("scroll",this.handleContentScroll)});h(this,"unbindContentScroll",t=>{t.removeEventListener("scroll",this.handleContentScroll)});h(this,"bindContentScroll",Xt.default(this.bindContentScrollCore,300));h(this,"bind",Xt.default(this.bindCore,200));this.scrollCore=t,this.callback=e}fixScrollXPos(t,e,o){const r=Zr(t);o||(t.scrollLeft=e),o&&r.scrollLeft!==e&&(r.scrollLeft=e)}bindCore(t){this.unbind(t),t.addEventListener("scroll",this.handleScroll),t.addEventListener("mousedown",this.handlePrevent)}unbind(t){t.removeEventListener("scroll",this.handleScroll),t.removeEventListener("mousedown",this.handlePrevent)}}class ME{constructor(t){h(this,"scrollContainers",new Set);h(this,"handleParentContainerScroll",()=>{this.scrollContainers.forEach(t=>{Yr(this.scrollCore,t)})});h(this,"bindScrollContainer",t=>{const e=this.scrollContainers.size===0;this.scrollContainers.add(t),e&&this.eventTarget.addEventListener("scroll",this.handleParentContainerScroll)});h(this,"unbindScrollContainer",t=>{let e=!1;this.scrollContainers.has(t)&&(this.scrollContainers.delete(t),e=this.scrollContainers.size===0),e&&this.eventTarget.removeEventListener("scroll",this.handleParentContainerScroll)});this.scrollCore=t}get eventTarget(){const t=this.scrollCore.getParentScrollContainer();return t===document.documentElement?document:t}destroy(){this.eventTarget.removeEventListener("scroll",this.handleParentContainerScroll),this.scrollContainers.clear()}}const RE=B("scroll-wrap-resize-observer");class AE{constructor(t){h(this,"resizeObserver");h(this,"handleScrollWrapResize",t=>{t.forEach(e=>{this.containers.get(Ae(e.target))?this.handleScrollWrapResizeEntry(e):this.unbind(e.target)})});h(this,"handleScrollWrapResizeEntry",t=>{const e=t.target;d(RE,e instanceof HTMLElement,"invalid target for observer entry");const o=O5(e);Mc(this.scrollCore,e),Ts(o),Yr(this.scrollCore,o)});this.scrollCore=t,this.resizeObserver=new ResizeObserver(this.handleScrollWrapResize)}get containers(){return this.scrollCore.containers}bind(t){this.unbind(t),this.resizeObserver.observe(t)}unbind(t){this.resizeObserver.unobserve(t)}destroy(){this.resizeObserver.disconnect()}}class OE{constructor(t,e){h(this,"resizeObserver");h(this,"scrollContainersMap",new Map);h(this,"handleResizeEntry",t=>{t==null||t.forEach(e=>{const o=dn(e);Ts(e),Mc(this.scrollCore,o),Yr(this.scrollCore,e),this.callback(e)})});h(this,"handleResize",t=>{t.forEach(e=>{const o=this.scrollContainersMap.get(e.target);o!=null&&o.length&&this.handleResizeEntry(o)})});this.scrollCore=t,this.callback=e,this.resizeObserver=new ResizeObserver(this.handleResize)}bind(t){var r,i;const e=Ae(t),o=(r=Dc(this.scrollCore,e))==null?void 0:r.locatingContainer;this.scrollContainersMap.has(o)?(i=this.scrollContainersMap.get(o))==null||i.push(t):(this.scrollContainersMap.set(o,[t]),this.resizeObserver.observe(o))}unbind(t){var i,s;const e=Ae(t),o=(i=Dc(this.scrollCore,e))==null?void 0:i.locatingContainer;if(!o)return;const r=this.scrollContainersMap.get(o);this.scrollContainersMap.set(o,(r==null?void 0:r.filter(l=>l!==t))||[]),(s=this.scrollContainersMap.get(o))!=null&&s.length||(this.resizeObserver.unobserve(o),this.scrollContainersMap.delete(o))}destroy(){this.scrollContainersMap.clear(),this.resizeObserver.disconnect()}}const vz="";class _E extends Yt.TypedEmitter{constructor(e){super();h(this,"containerIntersectionObserver",null);h(this,"containerResizeObserver",null);h(this,"containerScrollObserver",null);h(this,"parentContainerScrollObserver",null);h(this,"scrollWrapResizeObserve",null);h(this,"locatingContainerResizeObserver",null);h(this,"isWindowEventBind",!1);h(this,"containers",new Map);h(this,"handleScrollContainerScroll",e=>{this.emit("scroll",this,e)});h(this,"handleResize",e=>{this.emit("resize",this,e)});h(this,"handleIntersection",e=>{const o=e.target,r=dn(o);e.isIntersecting?(this.load(),this.bindCore(o,r)):this.unbindCore(o,r)});h(this,"handleWindowEffect",()=>{var e;(e=this.getScrollContainerInViewable())==null||e.forEach(o=>{Yr(this,o)})});this.parentContainer=e}load(){this.containerResizeObserver||(this.containerResizeObserver=new DE(this,this.handleResize)),this.containerScrollObserver||(this.containerScrollObserver=new LE(this,this.handleScrollContainerScroll)),this.parentContainerScrollObserver||(this.parentContainerScrollObserver=new ME(this)),this.scrollWrapResizeObserve||(this.scrollWrapResizeObserve=new AE(this)),this.locatingContainerResizeObserver||(this.locatingContainerResizeObserver=new OE(this,this.handleResize)),this.isWindowEventBind||(window.addEventListener("resize",this.handleWindowEffect),this.getParentScrollContainer()!==document.documentElement&&window.addEventListener("scroll",this.handleWindowEffect))}getParentScrollContainer(){return this.parentContainer}getScrollContainerInViewable(){var e;return(e=this.parentContainerScrollObserver)==null?void 0:e.scrollContainers}unbindCore(e,o){var i,s,l,c,a,u;const r=Zr(e);(i=this.containerScrollObserver)==null||i.unbindContentScroll(e),(s=this.containerScrollObserver)==null||s.unbind(r),(l=this.scrollWrapResizeObserve)==null||l.unbind(o),(c=this.containerResizeObserver)==null||c.unbind(e),(a=this.parentContainerScrollObserver)==null||a.unbindScrollContainer(e),(u=this.locatingContainerResizeObserver)==null||u.unbind(e)}bindCore(e,o){var i,s,l,c,a,u;if(this.unbindCore(e,o),!e.closest("body"))return;const r=Zr(e);(i=this.containerScrollObserver)==null||i.bindContentScrollCore(e),(s=this.containerScrollObserver)==null||s.bindCore(r),(l=this.scrollWrapResizeObserve)==null||l.bind(o),(c=this.containerResizeObserver)==null||c.bind(e),(a=this.parentContainerScrollObserver)==null||a.bindScrollContainer(e),(u=this.locatingContainerResizeObserver)==null||u.bind(e)}bind(e,o){this.containers.set(e,o);const r=e.firstElementChild;this.containerIntersectionObserver||(this.containerIntersectionObserver=new EE(this,this.handleIntersection)),this.containerIntersectionObserver.bind(r)}unbind(e){var i;const o=e.firstElementChild,r=dn(o);this.unbindCore(o,r),this.containers.delete(e),(i=this.containerIntersectionObserver)==null||i.unbind(o),this.containers.size||this.destroy()}destroy(){var e,o,r,i,s;this.containers.forEach((l,c)=>{this.unbind(c)}),this.containers.clear(),(e=this.parentContainerScrollObserver)==null||e.destroy(),(o=this.containerIntersectionObserver)==null||o.destroy(),(r=this.containerResizeObserver)==null||r.destroy(),(i=this.scrollWrapResizeObserve)==null||i.destroy(),(s=this.locatingContainerResizeObserver)==null||s.destroy(),window.removeEventListener("resize",this.handleWindowEffect),window.removeEventListener("scroll",this.handleWindowEffect)}}const j5=B("scroll-container"),Rc=new Map;class NE extends Yt.TypedEmitter{constructor(){super(...arguments);h(this,"scrollListener");h(this,"options");h(this,"scrollContainerElement");h(this,"init",e=>{this.options=e;const o=b("div",[Eo.CONTAINER],e.parentElement);xt.isMac&&A(o,Eo.MAC);const r=b("div",[Eo.SCROLL_CONTAINER],o),i=b("div",[Eo.SCROLL_AREA],r);i.style.paddingLeft=e.paddingLeft?`${e.paddingLeft}px`:"",i.style.paddingTop=e.paddingTop?`${e.paddingTop}px`:"",i.style.paddingBottom=e.paddingBottom?`${e.paddingBottom}px`:"",i.style.paddingRight=e.paddingRight?`${e.paddingRight}px`:"",i.appendChild(e.childElement);const s=e.parentContainer;this.scrollListener=Rc.get(s),this.scrollListener||(this.scrollListener=new _E(s),Rc.set(s,this.scrollListener)),this.scrollListener.unbind(o),this.scrollListener.bind(o,e),this.scrollListener.on("scroll",this.handleContainerScroll),this.scrollListener.on("resize",this.handleResize),this.scrollContainerElement=r});h(this,"handleContainerScroll",(e,o)=>{o===this.scrollContainerElement&&this.emit("scroll",this)});h(this,"handleResize",(e,o)=>{o===this.scrollContainerElement&&this.emit("scroll",this)})}get rootElement(){return this.scrollContainerElement}get contentElement(){return d(j5,this.scrollContainerElement,"scrollContainerElement cannot be undefined"),dn(this.scrollContainerElement)}get scrollOptions(){return d(j5,this.options,"options cannot be undefined"),{...this.options}}handleBaseListenerDestroy(e){e.destroy()}destroy(){var o;(o=this.scrollListener)==null||o.off("scroll",this.handleContainerScroll);const e=Ae(this.contentElement);e&&Rc.forEach((r,i)=>{r.unbind(e),r.containers.size===0&&(this.handleBaseListenerDestroy(r),Rc.delete(i))})}}function $E(){return new NE}const Ac=100,PE=40,_h=B("column-width");function jE(n,t,e){VB(n,t).style.width=`${e}px`}function HE(n){const e=Array.from(n.querySelector("colgroup").children).map(c=>c.getBoundingClientRect().width);if(e[0]!==0)return e;const o=et.fromTable(n),r=Array(o.colCount).fill(-1),i=n.getBoundingClientRect().left;o.toRealCells(o.cells).forEach(c=>{const a=c.col+c.colSpan-1;r[a]===-1&&(r[a]=c.cell.getBoundingClientRect().right-i)}),_h.debug(`cellRightOffsets1: ${r.join()}`);for(let c=0;c<r.length;c++){const a=r[c];if(a===-1||c===0)continue;let u=c-1;for(;r[u]===-1&&(u--,u!==-1););const f=u===-1?0:r[u],C=(a-f)/(c-u);for(let k=u+1;k<c;k++)r[k]=f+C*(k-u)}_h.debug(`cellRightOffsets2: ${r.join()}`);const s=[];let l=0;for(let c=0;c<r.length;c++){const a=r[c];s.push(a-l),l=a}return _h.debug(`widths: ${s.join()}`),s}function Ss(n){return Array.from(n.querySelector("colgroup").children).map(o=>o.getBoundingClientRect().width||Number.parseInt(o.style.width,10)||100)}const FE=B("table-resize-gripper"),H5=7,Nh=(H5-1)/2,zE=3;function UE(n,t,e){const{rows:o}=n;for(let r=0;r<o.length;r++){const i=o[r],s=Array.from(i.cells);for(let l=0;l<s.length;l++){const c=s[l],a=c.getBoundingClientRect(),u=Math.round(a.right);if(Math.abs(t-u)<=Nh&&a.top<=e&&e<=a.bottom)return c}}return null}function VE(n){return!!n.rootContainer.querySelector(".table-resize-gripper")}function $h(n,t){return Tn(n,t).querySelector(".table-resize-gripper")}function F5(n,t){const e=$h(n,t);d(FE,!e,"resize gripper has already exists");const o=Tn(n,t),r=b("div",["table-resize-gripper","table-indicator"],o);return b("div",["table-resize-gripper-indicator"],r),r}function z5(n,t,e){let o=$h(n,t);o||(o=F5(n,t));const i=jt(t).getBoundingClientRect(),s=e.getBoundingClientRect(),l=0,c=i.height,a=n.getCustom(Bo(t)).contentElement.getBoundingClientRect(),u=s.right-a.left;o.style.left=`${u-Nh-Th-Bs}px`,o.style.top=`${l}px`,o.style.height=`${c}px`,o.style.width=`${H5}px`}function Ph(n){n.rootContainer.querySelectorAll(".table-resize-gripper").forEach(t=>{t.remove()})}function qE(n,t,e){const r={...n.getBlockData(t),colsWidth:e};n.updateBlockData(t,r)}function WE(n,t,e,o){const r=t,i=et.fromTable(e),s=i.getCellByCellElement(r),l=s.col+s.colSpan-1,c=Ss(e);let a=o;const u=(m,C)=>{const k=C+1,w=m.col+m.colSpan;return c.slice(k,w).reduce((S,I)=>S+I,0)},f=new Set;for(let m=0;m<i.rowCount;m++){const C=i.getCell({row:m,col:l});if(f.has(C.cell))continue;f.add(C.cell);const k=C.cell,w=k.getBoundingClientRect();let y=o-w.left+Nh-zE;const S=ys(k),I=Td(n,S)||PE*C.colSpan,M=u(C,l),R=I-M;y<R&&(y=R);const $=w.left+y;a=Math.max(a,$)}return a}const GE=B("table-resize-drag-drop");class ZE{constructor(t,e,o,r){h(this,"cursor","col-resize");this.editor=t,this.elem=e,this.data=o,this.onEnd=r}onDragStart(t,e,o){}onDragging(t,e,o,r,i){const{table:s,block:l,draggingRefCell:c}=t.data,u=WE(this.editor,c,s,e.x-t.dragOffsetX)-s.getBoundingClientRect().left;d(GE,c,"no dragging cell");const m=et.fromTable(s).getCellByCellElement(c),C=m.col+m.colSpan-1,w=Ss(s).slice(0,C).reduce((S,I)=>S+I,0),y=u-w;jE(s,C,y),z5(this.editor,l,c),this.editor.selection.caret.update()}onDragEnd(t,e,o,r,i){const s=Ss(t.data.table);qE(this.editor,t.data.block,s),Ph(this.editor),this.onEnd&&(this.onEnd(e),this.onEnd=null)}}function YE(n,t){const e=document.elementFromPoint(t.x,t.y);if(!e)return null;const o=F(e);return!o||!n.contains(o)||!Ht(o)?null:o}B("table-resize");class QE{constructor(t){h(this,"draggingRefCell",null);h(this,"handleMouseMove",(t,e)=>{if(t.readonly||t.selectionHandler.isSelecting()&&!this.draggingRefCell||this.draggingRefCell)return;const o=e.target;if(!(o instanceof Element)||o.closest(".table-indicator"))return;const i=e,s=YE(t,i);if(!s||!C5(s)){Ph(t);return}this.updateGripper(s,i.x,i.y)});this.editor=t,t.domEvents.addEventListener(document,"mousemove",this.handleMouseMove)}destroy(){this.editor.domEvents.removeEventListener(document,"mousemove",this.handleMouseMove)}updateGripper(t,e,o){const r=jt(t),i=UE(r,e,o);if(i){if(!$h(this.editor,t)){if(VE(this.editor))return;const l=F5(this.editor,t),c={block:t,table:r,draggingRefCell:i};sd(new ZE(this.editor,l,c,a=>{this.updateGripper(t,a.x,a.y)}))}z5(this.editor,t,i)}else Ph(this.editor)}}function U5(n){n.addCustom("table-mouse-event-handler",t=>new QE(t))}const V5=B("table-insert-column");function q5(n,t,e){const o=jt(t),r=et.fromTable(o),i=r.colCount;d(V5,e>=0&&e<=i,`insert index ${e} is out of range [0, ${i}]`);const s=r.map(m=>m.containerId),l=new Set;n.doc.beginBatchUpdate();for(let m=0;m<s.length;m++){const C=s[m],k=C[e-1],w=C[e];if(e===0||e===C.length||k!==w){const y=yn(n.doc);C.splice(e,0,y)}else C.splice(e,0,k),l.add(k)}n.doc.endBatchUpdate();const c=Y.default(n.getBlockData(t));l.forEach(m=>{const C=`${m}_colSpan`,k=c[C];d(V5,typeof k=="number"&&k>1,`no colSpan for containerId ${m}, ${k}`),c[C]=k+1});const a=c.colsWidth.concat();a.splice(e,0,Ac);const u=et.virtualCellContainersGridToChildren(s),f={...c,cols:c.cols+1,children:u,colsWidth:a};or(f),n.updateBlockData(t,f)}const Oc=B("table-insert-row");function W5(n,t,e){const o=jt(t),r=et.fromTable(o),i=r.rowCount;d(Oc,e>=0&&e<=i,`insert index ${e} is out of range [0, ${i}]`);const s=r.map(m=>m.containerId),l=new Set;n.doc.beginBatchUpdate();const c=[];for(let m=0;m<r.colCount;m++){const C=e>0&&s[e-1][m],k=e<r.rowCount&&s[e][m];if(d(Oc,C||k,"no top and bottom cell"),e===0||e===r.rowCount||C!==k){const w=yn(n.doc);c.push(w)}else d(Oc,C,"no top cell"),c.push(C),l.add(C)}n.doc.endBatchUpdate(),s.splice(e,0,c);const a=Y.default(n.getBlockData(t));l.forEach(m=>{const C=`${m}_rowSpan`,k=a[C];d(Oc,typeof k=="number"&&k>1,`no rowSpan for containerId ${m}, ${k}`),a[C]=k+1});const u=et.virtualCellContainersGridToChildren(s),f={...a,rows:a.rows+1,children:u};or(f),n.updateBlockData(t,f)}const jh=B("paste-table-in-table-block");function KE(n,t,e,o){let r=et.fromBlock(e);const i=t.blocks.root[0];d(jh,i,"no table data"),d(jh,i.type==="table",`table data type is not table, but ${i.type}`);const s=i,l=r.getCellByCellElement(o),c=s.cols,a=s.rows,u=l.col,f=l.row,m=u+c,C=f+a,k=[];for(let w=u;w<m&&w<r.colCount;w++)for(let y=f;y<C&&y<r.rowCount;y++){const S=r.getCell({col:w,row:y});S.virtual?S.virtual&&k.push({col:w,row:y}):(S.colSpan>1||S.rowSpan>1)&&k.push({col:w,row:y})}n.undoManager.runInGroup(()=>{if(k.forEach(I=>{const M=et.fromBlock(e).getCell(I);(M.colSpan>1||M.rowSpan>1)&&Bh(n,e,I)}),m>r.colCount)for(let I=r.colCount;I<m;I++)q5(n,e,I);if(C>r.rowCount)for(let I=r.rowCount;I<C;I++)W5(n,e,I);r=et.fromBlock(e);const w=new Ec(s);let y;for(let I=0;I<w.colCount;I++)for(let M=0;M<w.rowCount;M++){const R=w.getCell({col:I,row:M});if(!R.virtual){const $=Cu(n.editorBlocks,t,R.containerId),Z=u+I,rt=f+M,st={col:Z,row:rt},mt=r.getCellContainer(st);qp(n,mt,$),y=mt}}d(jh,y,"no last container");const S=Qt(y);n.selection.selectBlock(S,W(n,S))})}const G5=B("paste-in-table-block");class JE{constructor(t){this.editor=t,setTimeout(()=>{t.input.addHandler(this)})}destroy(){}async handleBeforePasteDoc(t,e){if(!t.selection.range.isSimple()||t.selection.range.start.offset!==0)return!1;const r=t.selection.startBlock,i=H(r);if(pt(i)||!Sd(t,i))return!1;const s=F(i);if(d(G5,s,"no parent block"),!Ht(s)||e.blocks.root.length!==1||e.blocks.root[0].type!=="table")return!1;G5.debug("paste child table in table");const a=et.fromBlock(s).getCellByContainerId(U(i)).cell;return KE(t,e,s,a),!0}}function Z5(n){n.addCustom("table-block-paste-event",t=>new JE(t))}const Hh=B("table-select-columns");function XE(n,t,e,o,r){d(Hh,Ht(t),"is not a table block");const i=et.fromBlock(t);d(Hh,e>=0&&e<i.colCount,"invalid from"),d(Hh,o>0&&e+o<=i.colCount,"invalid count");const s=i.getCell({row:0,col:e}),l=i.getCell({row:i.rowCount-1,col:e+o-1}),c=wt(t,s.containerId,{colIndex:e,rowIndex:0}),a=wt(t,l.containerId,{colIndex:e+o-1,rowIndex:i.rowCount-1});r!=null&&r.reverse?n.selection.setSelection(a,c):n.selection.setSelection(c,a)}const Fh=B("table-select-columns");function tI(n,t,e,o,r){d(Fh,Ht(t),"is not a table block");const i=et.fromBlock(t);d(Fh,e>=0&&e<i.rowCount,"invalid from"),d(Fh,o>0&&e+o<=i.rowCount,"invalid count");const s=i.getCell({row:e,col:0}),l=i.getCell({row:e+o-1,col:i.colCount-1}),c=wt(t,s.containerId,{rowIndex:e,colIndex:0}),a=wt(t,l.containerId,{rowIndex:e+o-1,colIndex:i.colCount-1});r!=null&&r.reverse?n.selection.setSelection(a,c):n.selection.setSelection(c,a)}const yz="",Y5=B("get-toolbar-reference-client");function eI(n,t){const e=n.selection.range;if(!e.isSimple()){d(Y5,e.start.blockId===e.end.blockId,"invalid selection range");const s=n.getBlockById(e.start.blockId);d(Y5,at(n,s),"not a complex block");const l=kt(n,s);if(l.getTextToolbarReferenceClient){const c=l.getTextToolbarReferenceClient(n,s);if(c)return c}}const o=e.isReverse()?t.start:t.end,r=qt(n,{anchor:o,focus:o}),i=so(n,t.block,r);if(i.length!==0)return i[0]}function nI(n){var t,e;if(n.children){let o=!1;const r=[];for(const i of n.children){if((t=i.states)!=null&&t.includes("checked")){o=!0;break}(e=n.defaultCheckedChildren)!=null&&e.includes(i.id)&&r.push(i)}if(!o&&(r==null?void 0:r.length))for(const i of r)Array.isArray(i.states)?i.states.push("checked"):i.states=["checked"]}}function _c(n){const t=(r,i)=>{const s=r.findIndex(c=>c.id===i.id);if(s===-1){r.push(i);return}const l=r[s];if(l.value!==i.value&&delete l.value,!!l.states){if(!i.states){l.states=[];return}l.states=Xa.default(l.states,i.states)}},e=[],o=new Map;return n.forEach(r=>{var i,s;(i=r.children)!=null&&i.length&&(o.has(r.id)?(s=o.get(r.id))==null||s.push(...r.children):o.set(r.id,[...r.children])),t(e,r)}),o.forEach((r,i)=>{const s=e.find(l=>l.id===i);s&&(s.children=_c(r),nI(s))}),e}function Nc(n){return n.getCustom("toolbar-handler")}const wz="";class oI{constructor(){h(this,"linkPopup",null);h(this,"form",{});h(this,"onFinished",null);h(this,"onClose",null);h(this,"handleOk",async()=>{var t;try{await this.checkValue();const{linkText:e,linkUrl:o}=this.form;(t=this.onFinished)==null||t.call(this,e.getInputValue()||o.getInputValue(),o.getInputValue()),this._destroy()}catch{}});h(this,"handleClose",()=>{var t;(t=this.onClose)==null||t.call(this),this._destroy()});h(this,"onShow",()=>{setTimeout(()=>{var t;(t=this.form.linkText)==null||t.getField().focus()},400)});h(this,"onChange",()=>{var e;const t=(e=this.linkPopup)==null?void 0:e.content.querySelector(".submit-button");t.disabled=!1});h(this,"handleTextKeyboard",t=>{var e;if(!t.isComposing){if(t.key==="Enter"){(e=this.form.linkUrl)==null||e.getField().focus(),t.stopPropagation();return}t.key==="Escape"&&this.handleClose()}});h(this,"handleUrlKeyboard",t=>{if(!t.isComposing){if(t.key==="Enter"){this.handleOk(),t.preventDefault();return}t.key==="Escape"&&this.handleClose()}})}async checkValue(){const{linkUrl:t}=this.form;if(!t.getInputValue())throw t.setFieldError(T.t("link.urlPlaceholder")),new Error(T.t("link.urlPlaceholder"))}editLink(t){var u,f;const{target:e,linkText:o,linkUrl:r,onFinished:i,onClose:s,placement:l="bottom-start"}=t;this.linkPopup=new Cs(this.createPopupContent(o,r)),this.linkPopup.addListener("show",this.onShow),this.linkPopup.manualShow(e,{theme:"light",placement:l}),this.onFinished=i,s&&(this.onClose=s);const c=(u=this.linkPopup)==null?void 0:u.content.querySelector(".submit-button"),a=(f=this.linkPopup)==null?void 0:f.content.querySelector(".cancel-button");c==null||c.addEventListener("click",this.handleOk),a==null||a.addEventListener("click",this.handleClose)}createPopupContent(t,e){const o=b("div",["link-popup-content"],null);this.form.linkText=mh(o,{label:T.t("link.textLabel"),required:!1,placeholder:T.t("link.textPlaceholder"),defaultValue:t,onChange:this.onChange,onKeyDown:this.handleTextKeyboard}),this.form.linkUrl=mh(o,{className:"link-popup-gap",label:T.t("link.urlLabel"),required:!0,placeholder:T.t("link.urlPlaceholder"),defaultValue:e,onChange:this.onChange,onKeyDown:this.handleUrlKeyboard});const r=b("div",["link-popup-footer"],o);b("button",["cancel-button"],r,T.t("link.cancelText"));const i=b("button",["submit-button"],r,T.t("link.submitText"));return i.disabled=!0,o}_destroy(){var o,r,i,s;const t=(o=this.linkPopup)==null?void 0:o.content.querySelector(".submit-button"),e=(r=this.linkPopup)==null?void 0:r.content.querySelector(".cancel-button");t==null||t.removeEventListener("click",this.handleOk),e==null||e.removeEventListener("click",this.handleClose),this.onFinished=null,this.onClose=null,this.form={},(i=this.linkPopup)==null||i.removeAllListeners(),(s=this.linkPopup)==null||s.destroy()}destroy(){this._destroy()}}function Ds(n,t){n.addCustom("link-editor",()=>new oI).editLink(t)}const rI=B("link-popup");function iI(n){return nt(n,"link")}function $c(n){var t,e;return(e=(t=n.getAttribute("link"))!=null?t:n.textContent)!=null?e:""}function sI(n,t,e){var r,i,s,l;if(n.isBlockWritable(t)&&e&&_e(e)){const c=e,a=(i=(r=n.editorBoxes.getBoxClass(_i(c))).getBoxProperties)==null?void 0:i.call(r,n,c);return a!=null&&a.boxCommands?(l=(s=a.boxCommands["hovering-toolbar"])==null?void 0:s.commands)!=null?l:[]:[]}return n.isWritable()&&e&&P(n,t)&&iI(e)?[{id:"link-text",name:$c(e),disableTooltip:!0,element:b("span",["link-href-button"],null,$c(e))},{id:"edit-link",name:"Edit",icon:hh},{id:"remove-link",name:"Remove link",icon:Xw}]:Cg(n,t,"hovering-toolbar")}function lI(n,t,e){var c;const o=uo(t,e);n.selection.selectBlock(t,o.start,o.end);const r=(c=e.textContent)!=null?c:"",i=$c(e);Ds(n,{target:e,linkText:r,linkUrl:i,onFinished:(a,u)=>{try{const f=n.getBlockText(t),m=qd(f,o.start,o.end-o.start),C=fo(m,o.start,a,{link:u});n.setBlockText(t,C),n.selection.selectBlock(t,o.start+a.length),n.focus()}catch(f){rI.error(f)}},onClose:()=>{n.selection.selectBlock(t,o.end),n.focus()}})}function cI(n,t,e){const o=uo(t,e),r=n.getBlockText(t),i=$c(e),s=Sr(o.start,o.end-o.start,r,"link",i);n.setBlockText(t,s),n.selection.selectBlock(t,o.end)}function aI(n,t,e,o){var s,l,c;if(e){if(n.isBlockWritable(t)&&_e(e)){const u=e,f=(l=(s=n.editorBoxes.getBoxClass(_i(u))).getBoxProperties)==null?void 0:l.call(s,n,u);if(f!=null&&f.boxCommands){f.boxCommands["hovering-toolbar"].executeCommand(n,t,u,o);return}return}const a=Nc(n);a.disableTextToolbar(),a.hide(),setTimeout(()=>{a.enableTextToolbar()},1e4),o.id==="edit-link"?lI(n,t,e):o.id==="remove-link"&&cI(n,t,e);return}const r=pg(n,t);if(!r)return;const i=(c=r.blockCommands)==null?void 0:c["hovering-toolbar"];!i||i.executeCommand(n,t,o)}function Pc(){let n=8;for(;n>0&&!document.querySelector(`div[data-style-heading='${n}']`);)n--;return n}const dI=[nh,oh,rh,ih,sh,lh,ch,ah];class uI{constructor(t){h(this,"id","BlockTurnIntoCommandProvider");this.editor=t}getHeadingIndex(){let t=Pc();return t<=4?t=5:t<8&&(t+=1),t}getAvailableCommands(t,e,o){if(P(t,e)){const r=q(e),i=ot(e),s=Qe(t,e),c=t.getBlockData(e).heading,a=[];for(let f=0;f<this.getHeadingIndex();f++)a.push({id:`heading-${f+1}`,name:T.t("commands.heading",{name:`${f+1}`}),icon:dI[f],states:c===f+1?["checked"]:[],value:`${f+1}`});const u=f=>{var C;const m=b("span",["toolbar-item-name-container"],null);for(const k of f.children)if((C=k.states)!=null&&C.includes("checked"))return m.innerHTML=k.icon||Bc,m;return m.innerHTML=Bc,m};return[{id:"turn-into",name:T.t("commands.headingGroup"),blockId:r,blockType:i,blockKind:s,element:u,groupIndex:200,dropdown:!0,manualShowChildren:!0,childrenPlacement:"bottom-start",defaultCheckedChildren:["text"],children:[{id:"text",name:T.t("commands.text"),icon:Bc,states:c?[]:["checked"]},...a],childrenType:"menu"}]}return[]}applyHeadingStyle(t,e,o){t.updateBlockData(e,{heading:o})}executeCommand(t,e,o,r){if(P(t,e)&&(r.id.startsWith("heading-")||r.id==="text")){const i=r.value?Number(r.value):null;return this.applyHeadingStyle(t,e,i),!0}return!1}}function jc(n){const t=n.getAttribute("block-padding-level");return t?Number(t):null}function hI(n,t){let e;const o=jc(t);if(!o)e=1;else{if(o>=12)return e=12,!1;e=o+1}return n.updateBlockData(t,{...n.getBlockData(t),padding:e}),!0}function Q5(n,t){const e=jc(t);if(!e)return!1;const o=n.getBlockData(t);return e>1?(n.updateBlockData(t,{...o,padding:e-1}),!0):(n.updateBlockData(t,{...o,padding:null}),!0)}function zh(n){return n.readonly||!n.isWritable()}function fI(n){return n.selection.range.getSelectedBlocks().forEach(e=>{const o=e.block;P(n,o)&&hI(n,o)}),!0}function mI(n){return n.selection.range.getSelectedBlocks().forEach(e=>{const o=e.block;P(n,o)&&Q5(n,o)}),!0}function gI(n){return zh(n)?!1:n.undoManager.runInGroup(()=>(fI(n),!0))}function pI(n){return zh(n)?!1:n.undoManager.runInGroup(()=>(mI(n),!0))}function CI(n){if(zh(n))return!1;if(!n.selection.range.isCollapsed())return;const t=n.selection.focusedBlock;if(!P(n,t))return;const e=n.selection.range.focus;if(!(!e.isSimple()||e.offset!==0||!jc(t)))return Q5(n,t),!0}class bI{renderBlock(t,e,o){const{padding:r}=o;return r?{attributes:{"block-padding-level":r}}:{}}}const Bz="",kI={Tab:gI,"Shift+Tab":pI,Backspace:CI},Hc=B("list-block");function ct(n){return ot(n)==="list"}function Ft(n){d(Hc,ct(n),"not a list block")}function Fe(n){Ft(n);const t=n.getAttribute("data-list-type");return d(Hc,t,"no list type"),t}function Fc(n){return ct(n)&&Fe(n)==="text-only"}function un(n){var t,e;return Ft(n),(e=Number.parseInt((t=n.getAttribute("data-list-start"))!=null?t:"1",10))!=null?e:1}function ge(n){var t,e;return Ft(n),(e=Number.parseInt((t=n.getAttribute("data-list-level"))!=null?t:"1",10))!=null?e:1}function Qr(n){Ft(n);const t=n.getAttribute("data-list-group-id");return d(Hc,t,"no group id"),t}function Io(n){var i,s,l,c,a;Ft(n);const t=(i=n.getAttribute("data-list-type"))!=null?i:"ordered",e=(l=Number.parseInt((s=n.getAttribute("data-list-start"))!=null?s:"1",10))!=null?l:1,o=(a=Number.parseInt((c=n.getAttribute("data-list-level"))!=null?c:"1",10))!=null?a:1,r=n.getAttribute("data-list-group-id");return d(Hc,r,"no group id"),{type:t,start:e,level:o,groupId:r}}function Uh(n){switch(n){case"ordered":return{ordered:!0,checkbox:null,textOnly:null};case"unordered":return{ordered:!1,checkbox:null,textOnly:null};case"checked":return{checkbox:"checked",ordered:!1,textOnly:null};case"unchecked":return{checkbox:"unchecked",ordered:!1,textOnly:null};case"text-only":return{checkbox:null,ordered:!1,textOnly:!0};default:return{checkbox:null,ordered:!0,textOnly:!1}}}function Zn(n){Ft(n);const{level:t,groupId:e,type:o}=Io(n);let r=gt(n);for(;r;){if(!ct(r))return null;const{level:i,groupId:s,type:l}=Io(r);if(i<t)return null;if(t===i&&e===s&&(l==="text-only"||o==="text-only"||o===l))return r;r=gt(r)}return null}function sr(n){Ft(n);const{level:t,groupId:e,type:o}=Io(n);let r=dt(n);for(;r;){if(ct(r)){const{level:i,groupId:s,type:l}=Io(r);if(t===i&&e===s&&(l==="text-only"||o==="text-only"||o===l))return r;if(i<t)return null}r=dt(r)}return null}function K5(n){Ft(n);const t=[];let e=Zn(n);for(;e;)t.unshift(e),e=Zn(e);return t}function Ls(n){Ft(n);const t=[];let e=sr(n);for(;e;)t.push(e),e=sr(e);return t}function Ms(n){Ft(n);let t=Zn(n);for(;t;){const e=Zn(t);if(!e)return t;t=e}return n}function vI(n){Ft(n);let t=sr(n);for(;t;){const e=sr(t);if(!e)return t;t=e}return null}function J5(n,t){const e=K5(n),o=Ls(n);return t.withSelf?[...e,n,...o]:[...e,...o]}function Rs(n,t,e,o){var i;const r=(i=o==null?void 0:o.groupId)!=null?i:N();t.forEach(s=>{const l=n.getBlockData(s);if(l.start!==e||(o==null?void 0:o.resetGroupId)){const c={...l,start:e};o!=null&&o.resetGroupId&&(c.groupId=r),n.updateBlockData(s,c)}l.textOnly||(e+=1)})}function Vh(n,t,e,o){const r=J5(t,{withSelf:!0});r.length!==0&&Rs(n,r,e,o)}function yI(n){const t={M:1e3,CM:900,D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1};let e="",o=n;return Object.entries(t).forEach(([r,i])=>{for(;o>=i;)e+=r,o-=i}),e.toLowerCase()}const wI="abcdefghijklmnopqrstuvwxyz";function X5(n){if(n<=0)return`${n}`;const t=(n-1)%26,e=Math.floor((n-1)/26),o=wI[t];return e?X5(e)+o:o}function BI(n){return`${n}`}const t4=[BI,X5,yI];function EI(n,t){const e=t4[(n-1)%t4.length];return e(t)}function II(n){return["\u2022","\u25E6","\u25AA"][(n-1)%3]}class lr{constructor(t,e,o){h(this,"listStart");h(this,"listBrother",null);this.editor=t,this.options=o;const r=Ms(e),i=un(r);this.listStart=i,this.listBrother=r,o!=null&&o.resetStart&&(this.listStart=1)}fix(){!this.listBrother||Vh(this.editor,this.listBrother,this.listStart,this.options)}}function xI(n,t,e=1){if(!t)return null;let o=gt(n);for(;o;){const r=o.getAttribute("data-style-heading"),i=Number(o.getAttribute("data-list-level"));if(r){if(r<t)return null;if(r===t&&i===e)return ct(o)?o:null}o=gt(o)}return null}function TI(n,t){const e=n.getAttribute("data-style-heading"),o=xI(n,e);if(o)return o;const r=gt(n);if(r&&ct(r)&&Fe(r)===t)return r;const i=dt(n);return i&&ct(i)&&Fe(i)===t?i:null}function SI(n,t,e){var y,S,I,M;const o=(y=e.data)!=null?y:{};let r=1;if(ct(t))r=ge(t);else{const R=jc(t);R&&(r=R+1),r>8&&(r=8)}const i=(S=o.listType)!=null?S:"ordered";if(i==="text-only")return null;const s=n.getBlockData(t);let l=(I=s.text)!=null?I:[];const c=n.selection.range.focus;if(!c.isSimple())return null;let u=bt(l);const f=(M=e.offset)!=null?M:c.offset;f<=ue(l)&&(l=be(l,f).right,u=u.substring(0,f));let m=1;i==="ordered"&&(m=Number.parseInt(u,10)||1);let C=N();const k=TI(t,i);if(k){if(J(t)>J(k))m=un(k)+1;else{const R=un(k);R>1&&(m=R-1)}C=Qr(k)}const w={id:N(),type:"list",level:r,start:m,groupId:C,ordered:!1,text:l};return s.quoted&&(w.quoted=!0),s.heading&&(w.heading=s.heading),i==="ordered"?w.ordered=!0:(i==="checked"||i==="unchecked")&&(w.checkbox=i),{blockData:w,onConverted:(R,$)=>{new lr(R,$).fix()}}}function Kr(n){return n.textOnly?"text-only":n.checkbox?n.checkbox:n.ordered?"ordered":"unordered"}function DI(n){var e,o;if(n.checkbox||n.textOnly)return"";const t=(e=n.level)!=null?e:1;return n.ordered?`${EI(t,(o=n.start)!=null?o:1)}.`:II(t)}function zc(n){return n==="checked"||n==="unchecked"}function e4(n,t,e,o){const r=t,{containerId:i,blockIndex:s}=o[o.length-1];if(s===0)return!0;const l=e.blocks[i][s-1];if(l.type!=="list")return!0;const c=Kr(r),a=Kr(l);return c!==a&&(!zc(c)||!zc(a))||r.level>l.level}function n4(n,t,e,o){const r=t,{containerId:i,blockIndex:s}=o[o.length-1];if(s===e.blocks[i].length-1)return!0;const l=e.blocks[i][s+1];if(l.type!=="list")return!0;const c=Kr(r),a=Kr(l);return c!==a&&(!zc(c)||!zc(a))||r.level>l.level}function LI(n,t,e,o,r){var s,l,c;const i=t;if(o==="text"){let a=((s=ke.convertTo)==null?void 0:s.call(ke,n,t,e,"text",r))||"";i.checkbox==="checked"?a=`[x] ${a}`:i.checkbox==="unchecked"&&(a=`[ ] ${a}`),i.ordered?a=`${i.start}. ${a}`:a=`- ${a}`;const u=i.level||0;return a=(u>0?" ".repeat(u-1):"")+a,a}if(o==="markdown"){let a=((l=ke.convertTo)==null?void 0:l.call(ke,n,t,e,"markdown",r))||"";i.checkbox==="checked"?a=`[x] ${a}`:i.checkbox==="unchecked"&&(a=`[ ] ${a}`),i.ordered?a=`${i.start}. ${a}`:a=`- ${a}`;const u=i.level||0;return a=(u>0?" ".repeat(u-1):"")+a,e4(n,t,e,r)&&(a=`${a}`),n4(n,t,e,r)&&(a=`${a}`,u<=1&&(a+=`
338
+ `)),a}if(o==="html"){let a=((c=ke.convertTo)==null?void 0:c.call(ke,n,t,e,"html",r))||"";a=a.replace("<p>","").replace("</p>",""),i.checkbox==="checked"?a=`<input type="checkbox" checked="checked" disabled="disabled" /> ${a}`:i.checkbox==="unchecked"&&(a=`<input type="checkbox" disabled="disabled" /> ${a}`);let u="ul";return i.ordered?(a=`<li value="${i.start}">${a}</li>`,u="ol"):a=`<li>${a}</li>`,e4(n,t,e,r)&&(a=`<${u}>${a}`),n4(n,t,e,r)&&(a=`${a}</${u}>`),a}return""}const MI=8,Ot=B("list-block");class Uc{constructor(t,e){h(this,"listStart",0);h(this,"listBrother",null);if(this.editor=t,Fc(e))return;const o=Ms(e),r=un(o);this.listStart=r,o===e?this.listBrother=sr(o):this.listBrother=o}fix(){!this.listBrother||Vh(this.editor,this.listBrother,this.listStart)}}function RI(n,t,e){n.getBlockData(t).quoted&&(e.quoted=!0)}function qh(n,t,e,o){if(Ot.debug("drag a block on a list block"),!P(n,t))return!1;d(Ot,ct(e),"target is not a list block");const{type:r,start:i,level:s,groupId:l}=Io(e),c=o==="after"?i+1:i,a=n.getBlockData(t),u={id:N(),type:"list",groupId:l,level:s,start:c,text:a.text,...Uh(r)};RI(n,e,u);let f=J(e);const m=H(e);o==="after"&&(f+=1);let C=null;ct(t)&&(C=new Uc(n,t));const k=n.insertBlock(U(m),f,u,Gl(u.id,0));return n.deleteBlock(t),new lr(n,k).fix(),C==null||C.fix(),!0}function AI(n,t,e,o){if(Ot.debug("drag a list between text blocks"),o==="after"){const a=dt(e);if(a&&ct(a))return qh(n,t,a,"before")}if(o==="before"){const a=gt(e);if(a&&ct(a))return qh(n,t,a,"after")}const i={...n.getBlockData(t),groupId:N(),start:1,level:1};let s=J(e);const l=H(e);o==="after"&&(s+=1),n.insertBlock(U(l),s,i,Gl(i.id,0));const c=new Uc(n,t);return n.deleteBlock(t),c.fix(),!0}function OI(n,t,e,o,r){if(xl(e))return!1;const{blockId:i}=e,s=n.getBlockById(i);d(Ot,s,"no dragged block");const{isSourceBlock:l,targetBlock:c}=r;return!l&&c?(d(Ot,t===c,"block !== target block"),d(Ot,ct(c),"target is not a list block"),qh(n,s,c,o)):AI(n,s,c,o)}const _I=`<?xml version="1.0" ?>
339
339
  <svg t="1666868766077" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3547" width="16" height="16">
340
340
  <path d="M864 128H160c-17.6 0-32 14.4-32 32v704c0 17.6 14.4 32 32 32h704c17.6 0 32-14.4 32-32V160c0-17.6-14.4-32-32-32zM428 718.4l-45.6 45.6-45.6-45.6-116-117.6 45.6-45.6L383.2 672l367.2-367.2 45.6 45.6-368 368z" p-id="3548" fill="#1296db"></path>
341
341
  </svg>
@@ -356,24 +356,24 @@ xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24">
356
356
  <path d="M9.99978 5.99611L14.5 1.49609" stroke="currentColor" stroke-width="2"/>
357
357
  <path d="M1 10.0039H5.99738L5.99608 15" stroke="currentColor" stroke-width="2"/>
358
358
  <path d="M14.9971 5.99611H9.99969L10.001 1" stroke="currentColor" stroke-width="2"/>
359
- </svg>`;async function WI(n,t,e){const o=Rt(t),r=o.querySelector('[data-button-id="mindmap-fullscreen"]');d(Ot,r,"no full screen button");const i=()=>{setTimeout(()=>{e.toMindmap(n,t,{},{reset:!0,mindmapTools:e})},300)},s=()=>{z(o,"fullscreen"),r.innerHTML=r4,Y2(r,"Full screen",n.clientId),s4(t)&&setTimeout(()=>{i()},300)};if(document.fullscreenElement===o){try{await i4()}catch(l){Ot.error(l)}s()}else{try{A(o,"fullscreen"),await UI(o),i()}catch(l){Ot.error(l)}r.innerHTML=qI,Y2(r,T.t("mindmap.exitFullscreen"),n.clientId)}o.onfullscreenchange=()=>{document.fullscreenElement||s()}}function Gh(n,t,e,o,r){if(t.querySelector(`[data-button-id="${e}"]`))return null;const s=vo(e,o,r,[],n.clientId);return A(s,"mindmap-button"),t.appendChild(s),s}function Zh(n,t){return n.querySelector(`[data-button-id="${t}"]`)}function GI(n){return Zh(n,"mindmap-fullscreen")}function ZI(n){return Zh(n,"mindmap-fit")}function YI(n){return Zh(n,"mindmap-close")}function QI(n,t,e,o){const r=Gh(n,t,"mindmap-close",T.t("mindmap.close"),FI);!r||n.domEvents.addEventListener(r,"click",()=>{o.closeMindmap(n,e)})}function KI(n,t,e,o){const r=Gh(n,t,"mindmap-fit",T.t("mindmap.autoFit"),zI);!r||n.domEvents.addEventListener(r,"click",()=>{o.fitMindmap(n,e)})}function JI(n,t,e,o){if(navigator.userAgent.includes("Mobile")&&!navigator.userAgent.includes("iPad"))return;const i=Gh(n,t,"mindmap-fullscreen",T.t("mindmap.fullScreen"),r4);!i||n.domEvents.addEventListener(i,"click",()=>{WI(n,e,o)})}function XI(n,t){const e=Dl(t);if(!e)return;const o=ZI(e);o&&(o.remove(),n.domEvents.removeAllListeners(o));const r=YI(e);r&&(r.remove(),n.domEvents.removeAllListeners(r));const i=GI(e);i&&(i.remove(),n.domEvents.removeAllListeners(i))}const Jr=new Map;function Yh(n,t,e){const o=(s,l)=>{s.forEach(c=>{l?A(c.block,"to-mindmap-highlight"):z(c.block,"to-mindmap-highlight"),o(c.children,l)})},r=o4(n,t);if(r.length===0)return;const i=r[0].block;if(e){const s=Jr.get(i);s&&(s.forEach(l=>l.cancel()),Jr.delete(i)),o(r,!0)}else{const s=setTimeout(()=>{o(r,!1),Jr.delete(i)},300),l=()=>{clearTimeout(s),Jr.delete(i)},c=Jr.get(i);c?c.push({cancel:l}):Jr.set(i,[{cancel:l}])}}const{Markmap:tx}=I7;function ex(n,t){Ft(t);const e=o4(n,t),o=e[0].block,r=a=>({t:"text",v:it(a.block).textContent,d:1,c:a.children.length>0?a.children.map(f=>r(f)):void 0});let i=null;e.length>1?i={t:"root",v:"root",d:0,c:e.length>0?e.map(a=>r(a)):void 0}:i=r(e[0]);const l=a=>{if(a.length===0)return null;const u=a[a.length-1];return u.children&&u.children.length>0?l(u.children):u},c=l(e);return{root:i,block:o,nodes:e,last:c}}function Qh(n,t,e,o){const{root:r,block:i,last:s}=ex(n,t);o.selectBlock&&n.selection.selectBlock(i,0,0),Yh(n,i,!1),o.saveData&&n.updateBlockData(i,{viewAsMindmap:!0});const l=Rt(i);let c=l.querySelector(".editor-mindmap-svg");if(o.reset&&(c&&c.remove(),c=null),c)c.innerHTML="";else{const S="http://www.w3.org/2000/svg",I=l.getBoundingClientRect(),M=document.fullscreenElement===l,R=M?`${I.width}`:`${t.getBoundingClientRect().width}`,$=M?`${I.height}`:"600",Z=document.createElementNS(S,"svg");Z.setAttributeNS(null,"viewBox",`0 0 ${R} ${$}`),Z.setAttributeNS(null,"width","100%"),Z.setAttributeNS(null,"height",$),Z.style.display="block",Z.style.width="100%",Z.style.height=`${$}px`,Z.classList.add("editor-mindmap-svg"),l.appendChild(Z),c=Z}const a=i,f=`editor-mindmap-root-${q(i)}`;A(a,"editor-in-mindmap-first",f,"readonly"),a.contentEditable="false";const m=dt(i);m&&J(m)<=J(s.block)&&VI(m,s.block,["block-hidden",f]);const C=(S,I)=>{if(I.length>0){const M=I[0].parentElement;M&&(M.style.width="100vw",M.style.maxWidth="200px")}I.forEach(M=>{A(M,"editor-mindmap-node")})},k=new tx(c,{...e,autoFit:!0});k.viewHooks.transformHtml.tap(C),k.setData(r),k.fit();const w=Rt(i);let y=w.querySelector(".mindmap-toolbar");y||(y=b("div",["mindmap-toolbar"],w)),KI(n,y,a,o.mindmapTools),JI(n,y,a,o.mindmapTools),QI(n,y,a,o.mindmapTools),n.domEvents.addEventListener(c,"click",()=>{n.selection.selectBlock(i,0),n.input.focus()}),a.mindMap=k}function nx(n){const t=n.classList,e="editor-mindmap-root-";return Array.from(t).find(r=>{if(r.startsWith(e))return r})}async function l4(n,t){const e=nx(t);if(!e)return;n.updateBlockData(t,{viewAsMindmap:null});const o=H(t);Mt(o).forEach(l=>{nt(l,e)&&z(l,e,"editor-in-mindmap-first","block-hidden")});const i=Rt(t);document.fullscreenElement===i&&await i4();const s=i.querySelector(".editor-mindmap-svg");d(Ot,s,"no mindmap svg"),s.remove(),n.domEvents.removeAllListeners(s),t.contentEditable="inherit",XI(n,t),n.selection.selectBlock(t,0)}function ox(n,t){const e=t.mindMap;e&&e.fit()}const c4={toMindmap:Qh,closeMindmap:l4,fitMindmap:ox};function a4(n){let t=dt(n);if(!t)return null;const e=sr(n);for(;t!==e;){if(d(Ot,t,"no next block"),ct(t))return ge(t)>ge(n)?t:null;if(t=dt(t),!t)return null}return null}function Kh(n){const t=[];let e=a4(n);if(!e)return t;for(;e;){const o=sr(e);t.push({block:e,children:Kh(e)}),e=o}return t}function rx(n){const t=(o,r)=>{r.push(o.block),o.children.forEach(i=>t(i,r))},e=[];return n.forEach(o=>t(o,e)),e}function d4(n,t){return ge(t)!==1}function u4(n,t,e){t.forEach(o=>{const r=n.getBlockData(o.block);n.updateBlockData(o.block,{...r,groupId:e,level:r.level-1}),o.children.length&&u4(n,o.children,r.groupId)})}function Jh(n,t){if(!d4(n,t))return!1;const e=ge(t);if(e===1)return!1;let o=N(),r=1,i=Fe(t);const s=e-1,l=Wh(t);l&&(o=Qr(l),r=un(l)+1,i!=="text-only"&&(i=Fe(l)));const c=Kh(t),a=n.getBlockData(t),u={...a,groupId:o,level:s,start:r,...Uh(i)};n.updateBlockData(t,u),n.doc.beginBatchUpdate(),u4(n,c,a.groupId),n.doc.endBatchUpdate(),new lr(n,t).fix();const m=a4(t);return m&&new lr(n,m,{resetStart:!0,resetGroupId:!0}).fix(),!0}function Xr(n,t){Ft(t);const e=n.getBlockData(t),o={id:N(),type:"text",text:e.text};e.heading&&(o.heading=e.heading),e.heading&&(o.heading=e.heading);const r=new Uc(n,t),i=H(t),s=J(t);n.deleteBlock(t);const l=Gl(o.id,0);n.insertBlock(U(i),s,o,l),r.fix()}function ix(n){if(!n.selection.range.isCollapsed())return!1;const t=n.selection.focusedBlock;if(!ct(t))return!1;const e=n.selection.range.focus;return!e.isSimple()||e.offset!==0?!1:ge(t)===1?(Xr(n,t),!0):(Jh(n,t),!0)}const sx=B("list-block");function lx(n,t,e){d(sx,ct(t),"not a list block");const o={...n.getBlockData(t),id:N()};return e!=null&&e.level&&(o.level=e.level),e!=null&&e.start&&(o.start=e.start),e!=null&&e.keepText||delete o.text,o}function cx(n){if(Ft(n),!Fc(n))return n;let t=Zn(n);for(;t;){if(!Fc(t))return t;t=Zn(t)}return null}function ax(n,t,e,o){const r=new lr(n,o),i=un(o)+1;Ar(n,t,e,{forceInsertAfter:!0,newBlockData:lx(n,o,{start:i})}),r.fix()}function dx(n){var s;if(n.selection.range.isCollapsed()){const l=n.selection.focusedBlock;if(ct(l)&&W(n,l)===0)return Xr(n,l),!0}n.clearSelectedContents();const t=n.selection.focusedBlock;if(!ct(t))return!1;const e=n.selection.range.focus;if(!e.isSimple())return!1;const o=e.offset,i=(s=o===W(n,t)?cx(t):t)!=null?s:t;return ax(n,t,o,i),!0}function h4(n){d(Ot,ct(n),"not a list block");const{level:t}=Eo(n);let e=gt(n);for(;e;){if(ct(e)){const{level:o}=Eo(e);if(t===o)return e;if(o<t)return null}e=gt(e)}return null}function f4(n,t){return Ft(t),h4(t)?ge(t)<MI:!1}function ux(n,t,e){let o=gt(t);d(Ot,o,"no prev brother");const r=ge(e);for(;o;){if(o===e)return null;if(ct(o)&&ge(o)===r+1)return o;o=gt(o)}return null}function m4(n,t){if(!f4(n,t))return!1;Ft(t);const e=h4(t);d(Ot,e,"no list prev brother");const o=e,r=ux(n,t,o),i=ge(o)+1;let s=N(),l=1,c=Fe(t);r&&(s=Qr(r),l=un(r)+1,c=Fe(r));const a=Kh(t),f={...n.getBlockData(t),groupId:s,level:i,start:l,...Uh(c)};return n.updateBlockData(t,f),n.doc.beginBatchUpdate(),rx(a).forEach(C=>{const k=n.getBlockData(C);n.updateBlockData(C,{...k,level:k.level+1})}),n.doc.endBatchUpdate(),!0}function hx(n,t,e){return t.length===0||!t.every(o=>ct(o.block))?!1:e==="increase"?f4(n,t[0].block):d4(n,t[0].block)}function g4(n,t,e){if(!hx(n,t,e))return!1;const o=t[0].block,r=ge(o),i=t.filter(a=>ge(a.block)<=r),s=J5(o,{withSelf:!1}),l=new Set(i.map(a=>a.block)),c=s.filter(a=>!l.has(a));return n.undoManager.runInGroup(()=>{let a=null;c.length>0&&(a=new lr(n,c[0])),i.forEach(u=>{e==="increase"?m4(n,u.block):Jh(n,u.block)}),a==null||a.fix()}),!0}function fx(n,t){return m4(n,t)}function mx(n,t){return Jh(n,t)}function gx(n){const t=n.selection.range.getSelectedBlocks();if(t.length>1)return g4(n,t,"increase"),!0;const e=t[0].block;if(!ct(e))return!1;const o=new Uc(n,e);return fx(n,e)&&(o.fix(),new lr(n,e).fix()),!0}function px(n){const t=n.selection.range.getSelectedBlocks();if(t.length>1)return g4(n,t,"decrease"),!0;const e=t[0].block;return ct(e)?(mx(n,e),!0):!1}class Cx{constructor(t){this.editor=t}handleBeforeKeyDown(t,e){const o=t.selection.range.getSelectedBlocks();if(o.length===0||!o.some(i=>ct(i.block)))return!1;switch(e.key){case"Enter":return this.handleEnter(e);case"Backspace":return this.handleBackspace();case"Tab":return this.handleTab(e);default:return!1}}handleEnter(t){const e=this.editor.selection.range.getSelectedBlocks()[0];return!e.block||!ct(e.block)||jn(t,"Shift+Enter")?!1:this.editor.undoManager.runInGroup(()=>dx(this.editor))}handleBackspace(){return this.editor.undoManager.runInGroup(()=>ix(this.editor))}handleTab(t){return jn(t,"Shift+Tab")?this.editor.undoManager.runInGroup(()=>px(this.editor)):this.editor.undoManager.runInGroup(()=>gx(this.editor))}}class bx{constructor(t){h(this,"effectedBlockIds",new Map);h(this,"handleBeforeClearSelection",()=>{this.effectedBlockIds.clear();const t=this.editor.selection.range.getSelectedBlocks();if(t.length===0)return;const e=new Set;t.forEach(r=>{const i=r.block;ct(i)&&e.add(i)});const o=new Map;Array.from(e.values()).forEach(r=>{var c;const i=Ms(r),{start:s}=Eo(i);o.set(q(i),s);const l=(c=vI(r))!=null?c:r;o.set(q(l),s)}),this.effectedBlockIds=o});h(this,"handleAfterClearSelection",()=>{Array.from(this.effectedBlockIds.entries()).forEach(([t,e])=>{const o=this.editor.findBlockById(t);!o||Vh(this.editor,o,e)}),this.effectedBlockIds.clear()});this.editor=t,this.editor.addListener("beforeClearSelection",this.handleBeforeClearSelection),this.editor.addListener("afterClearSelection",this.handleAfterClearSelection)}destroy(){this.editor.removeListener("beforeClearSelection",this.handleBeforeClearSelection),this.editor.removeListener("afterClearSelection",this.handleAfterClearSelection)}}const kx=B("customize-list-start-menu");class vx{constructor(t){h(this,"popup");h(this,"block",null);h(this,"show",(t,e)=>{const o=e.querySelector("div.list-container");d(kx,o,"list-block mark does not exist"),this.block=e,this.popup.manualShow(o,{theme:"light"})});h(this,"createDialogContent",()=>{const t=b("div",["customize-start-panel"],null);b("span",["customize-start-panel-title"],t,T.t("list.numberLabel"));const e=b("input",["customize-start-panel-input"],t);e.type="number",e.setAttribute("min","1");const o=b("button",["customize-start-panel-button"],t,T.t("list.confirm"));return this.editor.domEvents.addEventListener(t,"keydown",this.handleKeydown),this.editor.domEvents.addEventListener(o,"click",this.handleOk),t});h(this,"handleDialogShow",()=>{const t=this.block;if(!t)return;const e=this.popup.popupContent,o=e.querySelector("button.customize-start-panel-button"),r=e.querySelector("input.customize-start-panel-input"),i=un(t);!o||!r||requestAnimationFrame(()=>{r.focus(),r.value=String(i)})});h(this,"handleOk",()=>{const e=this.popup.popupContent.querySelector("input.customize-start-panel-input"),o=this.block;if(!o)return;const r=Number(e.value);!r||(this.editor.undoManager.runInGroup(()=>{Rs(this.editor,[o,...Ls(o)],r,{resetGroupId:!0})}),this.popup.close())});h(this,"handleKeydown",(t,e)=>{const o=e;o.isComposing||o.key==="Escape"&&this.popup.close()});this.editor=t,this.popup=new Cs(this.createDialogContent()),this.popup.on("show",this.handleDialogShow)}destroy(){this.popup.destroy()}}function yx(n,t){return Qr(n)===Qr(t)}function wx(n,t){const e=Zn(t),o=gt(t);return!e&&!o||!o||!ct(o)?!1:ct(o)&&yx(o,t)?un(o)!==un(t)-1:!0}function Bx(n,t){return!!Zn(t)}function Ex(n,t){Ft(t);const e=[{id:"continue-numbering",name:T.t("list.continueList")},{id:"start-new-list",name:T.t("list.restartList")},{id:"set-numbering-value",name:T.t("list.changeNumber")}];return wx(n,t)||(e[0].states=["disabled"]),Bx(n,t)||(e[1].states=["disabled"]),e}function Ix(n,t,e){var o,r;if(Ft(t),e.id==="continue-numbering"){const i=gt(t),s=Zn(t)||(i&&ct(i)?i:null);s&&Rs(n,[t,...Ls(t)],un(s)+1,{resetGroupId:!0,groupId:Qr(s)})}if(e.id==="start-new-list"&&n.undoManager.runInGroup(()=>{Rs(n,[t,...Ls(t)],1,{resetGroupId:!0})}),e.id==="set-numbering-value"){const i=(o=n.options.componentsOptions)==null?void 0:o.list;if((r=i==null?void 0:i.onChangeStart)!=null&&r.call(i,n,t,e))return;n.addCustom("list-customize-start-dialog",()=>new vx(n)).show(n,t)}}class xx{constructor(t){h(this,"menu");h(this,"handleClick",(t,e)=>{const o=Ri(e,"div.list-container");if(o&&this.editor.isWritable()){const r=F(o);d(Ot,r,"no parent block"),Ft(r);const i=t.getBlockData(r);if(i&&i.checkbox){t.updateBlockData(r,{...i,checkbox:i.checkbox==="checked"?"unchecked":"checked"});return}this.menu.updateItems(this.getCommandItems(r)),this.menu.manualShow(o),this.activeList(o,!0)}});h(this,"handleMenuClose",()=>{var e;const t=(e=this.menu.tippyInstance)==null?void 0:e.reference;t&&this.activeList(t,!1)});h(this,"handleMenuClick",(t,e)=>{var r;const o=(r=this.menu.tippyInstance)==null?void 0:r.reference;if(o){const i=F(o);i&&Ix(this.editor,i,e)}});this.editor=t,this.editor.addListener("click",this.handleClick),this.menu=new nr([]),this.menu.addListener("close",this.handleMenuClose),this.menu.addListener("click",this.handleMenuClick)}destroy(){this.editor.removeListener("click",this.handleClick),this.menu.removeListener("close",this.handleMenuClose)}getCommandItems(t){return Ex(this.editor,t)}activeList(t,e){const o=F(t);!o||(e?(A(t,"active"),A(o,"active")):(z(t,"active"),z(o,"active")))}}class Tx{constructor(t){this.editor=t}handleBeforeKeyDown(t,e){const o=t.selection.range.getSelectedBlocks();if(o.length===0)return!1;const r=o[0].block;if(!ct(r)||!s4(r))return!1;if(e.key==="ArrowUp"||e.key==="ArrowLeft"){const i=wr(r);return i&&t.selection.selectBlock(i,W(t,i)),!0}if(e.key==="ArrowDown"||e.key==="ArrowRight"){const i=Br(r);return i&&t.selection.selectBlock(i,0),!0}return(e.key==="Delete"||e.key==="Backspace"||e.key==="Escape")&&l4(t,r),!0}}function Sx(n,t,e,o,r){Nu(n,"list-block-init",()=>{setTimeout(()=>{n.input.addHandler(new Tx(n)),n.input.addHandler(new Cx(n)),n.addCustom("list-clear-selection-handler",()=>new bx(n)),n.addCustom("list-marker-menu",()=>new xx(n))})});const i=ke.createBlockContent(n,t,e,o,r),s=r,{level:l,start:c,groupId:a}=s,u=Kr(s);o.setAttribute("data-list-level",`${l}`),o.setAttribute("data-list-start",`${c||1}`),o.setAttribute("data-list-group-id",`${a}`),o.setAttribute("data-list-type",u);const f=PI(s);return o.insertBefore(f,i),s.viewAsMindmap&&setTimeout(()=>{const m=n.getBlockById(r.id);m&&Qh(n,m,{},{mindmapTools:c4,saveData:!1})}),i}const Dx=`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
359
+ </svg>`;async function WI(n,t,e){const o=Rt(t),r=o.querySelector('[data-button-id="mindmap-fullscreen"]');d(Ot,r,"no full screen button");const i=()=>{setTimeout(()=>{e.toMindmap(n,t,{},{reset:!0,mindmapTools:e})},300)},s=()=>{z(o,"fullscreen"),r.innerHTML=r4,Y2(r,"Full screen",n.clientId),s4(t)&&setTimeout(()=>{i()},300)};if(document.fullscreenElement===o){try{await i4()}catch(l){Ot.error(l)}s()}else{try{A(o,"fullscreen"),await UI(o),i()}catch(l){Ot.error(l)}r.innerHTML=qI,Y2(r,T.t("mindmap.exitFullscreen"),n.clientId)}o.onfullscreenchange=()=>{document.fullscreenElement||s()}}function Gh(n,t,e,o,r){if(t.querySelector(`[data-button-id="${e}"]`))return null;const s=yo(e,o,r,[],n.clientId);return A(s,"mindmap-button"),t.appendChild(s),s}function Zh(n,t){return n.querySelector(`[data-button-id="${t}"]`)}function GI(n){return Zh(n,"mindmap-fullscreen")}function ZI(n){return Zh(n,"mindmap-fit")}function YI(n){return Zh(n,"mindmap-close")}function QI(n,t,e,o){const r=Gh(n,t,"mindmap-close",T.t("mindmap.close"),FI);!r||n.domEvents.addEventListener(r,"click",()=>{o.closeMindmap(n,e)})}function KI(n,t,e,o){const r=Gh(n,t,"mindmap-fit",T.t("mindmap.autoFit"),zI);!r||n.domEvents.addEventListener(r,"click",()=>{o.fitMindmap(n,e)})}function JI(n,t,e,o){if(navigator.userAgent.includes("Mobile")&&!navigator.userAgent.includes("iPad"))return;const i=Gh(n,t,"mindmap-fullscreen",T.t("mindmap.fullScreen"),r4);!i||n.domEvents.addEventListener(i,"click",()=>{WI(n,e,o)})}function XI(n,t){const e=Dl(t);if(!e)return;const o=ZI(e);o&&(o.remove(),n.domEvents.removeAllListeners(o));const r=YI(e);r&&(r.remove(),n.domEvents.removeAllListeners(r));const i=GI(e);i&&(i.remove(),n.domEvents.removeAllListeners(i))}const Jr=new Map;function Yh(n,t,e){const o=(s,l)=>{s.forEach(c=>{l?A(c.block,"to-mindmap-highlight"):z(c.block,"to-mindmap-highlight"),o(c.children,l)})},r=o4(n,t);if(r.length===0)return;const i=r[0].block;if(e){const s=Jr.get(i);s&&(s.forEach(l=>l.cancel()),Jr.delete(i)),o(r,!0)}else{const s=setTimeout(()=>{o(r,!1),Jr.delete(i)},300),l=()=>{clearTimeout(s),Jr.delete(i)},c=Jr.get(i);c?c.push({cancel:l}):Jr.set(i,[{cancel:l}])}}const{Markmap:tx}=I7;function ex(n,t){Ft(t);const e=o4(n,t),o=e[0].block,r=a=>({t:"text",v:it(a.block).textContent,d:1,c:a.children.length>0?a.children.map(f=>r(f)):void 0});let i=null;e.length>1?i={t:"root",v:"root",d:0,c:e.length>0?e.map(a=>r(a)):void 0}:i=r(e[0]);const l=a=>{if(a.length===0)return null;const u=a[a.length-1];return u.children&&u.children.length>0?l(u.children):u},c=l(e);return{root:i,block:o,nodes:e,last:c}}function Qh(n,t,e,o){const{root:r,block:i,last:s}=ex(n,t);o.selectBlock&&n.selection.selectBlock(i,0,0),Yh(n,i,!1),o.saveData&&n.updateBlockData(i,{viewAsMindmap:!0});const l=Rt(i);let c=l.querySelector(".editor-mindmap-svg");if(o.reset&&(c&&c.remove(),c=null),c)c.innerHTML="";else{const S="http://www.w3.org/2000/svg",I=l.getBoundingClientRect(),M=document.fullscreenElement===l,R=M?`${I.width}`:`${t.getBoundingClientRect().width}`,$=M?`${I.height}`:"600",Z=document.createElementNS(S,"svg");Z.setAttributeNS(null,"viewBox",`0 0 ${R} ${$}`),Z.setAttributeNS(null,"width","100%"),Z.setAttributeNS(null,"height",$),Z.style.display="block",Z.style.width="100%",Z.style.height=`${$}px`,Z.classList.add("editor-mindmap-svg"),l.appendChild(Z),c=Z}const a=i,f=`editor-mindmap-root-${q(i)}`;A(a,"editor-in-mindmap-first",f,"readonly"),a.contentEditable="false";const m=dt(i);m&&J(m)<=J(s.block)&&VI(m,s.block,["block-hidden",f]);const C=(S,I)=>{if(I.length>0){const M=I[0].parentElement;M&&(M.style.width="100vw",M.style.maxWidth="200px")}I.forEach(M=>{A(M,"editor-mindmap-node")})},k=new tx(c,{...e,autoFit:!0});k.viewHooks.transformHtml.tap(C),k.setData(r),k.fit();const w=Rt(i);let y=w.querySelector(".mindmap-toolbar");y||(y=b("div",["mindmap-toolbar"],w)),KI(n,y,a,o.mindmapTools),JI(n,y,a,o.mindmapTools),QI(n,y,a,o.mindmapTools),n.domEvents.addEventListener(c,"click",()=>{n.selection.selectBlock(i,0),n.input.focus()}),a.mindMap=k}function nx(n){const t=n.classList,e="editor-mindmap-root-";return Array.from(t).find(r=>{if(r.startsWith(e))return r})}async function l4(n,t){const e=nx(t);if(!e)return;n.updateBlockData(t,{viewAsMindmap:null});const o=H(t);Mt(o).forEach(l=>{nt(l,e)&&z(l,e,"editor-in-mindmap-first","block-hidden")});const i=Rt(t);document.fullscreenElement===i&&await i4();const s=i.querySelector(".editor-mindmap-svg");d(Ot,s,"no mindmap svg"),s.remove(),n.domEvents.removeAllListeners(s),t.contentEditable="inherit",XI(n,t),n.selection.selectBlock(t,0)}function ox(n,t){const e=t.mindMap;e&&e.fit()}const c4={toMindmap:Qh,closeMindmap:l4,fitMindmap:ox};function a4(n){let t=dt(n);if(!t)return null;const e=sr(n);for(;t!==e;){if(d(Ot,t,"no next block"),ct(t))return ge(t)>ge(n)?t:null;if(t=dt(t),!t)return null}return null}function Kh(n){const t=[];let e=a4(n);if(!e)return t;for(;e;){const o=sr(e);t.push({block:e,children:Kh(e)}),e=o}return t}function rx(n){const t=(o,r)=>{r.push(o.block),o.children.forEach(i=>t(i,r))},e=[];return n.forEach(o=>t(o,e)),e}function d4(n,t){return ge(t)!==1}function u4(n,t,e){t.forEach(o=>{const r=n.getBlockData(o.block);n.updateBlockData(o.block,{...r,groupId:e,level:r.level-1}),o.children.length&&u4(n,o.children,r.groupId)})}function Jh(n,t){if(!d4(n,t))return!1;const e=ge(t);if(e===1)return!1;let o=N(),r=1,i=Fe(t);const s=e-1,l=Wh(t);l&&(o=Qr(l),r=un(l)+1,i!=="text-only"&&(i=Fe(l)));const c=Kh(t),a=n.getBlockData(t),u={...a,groupId:o,level:s,start:r,...Uh(i)};n.updateBlockData(t,u),n.doc.beginBatchUpdate(),u4(n,c,a.groupId),n.doc.endBatchUpdate(),new lr(n,t).fix();const m=a4(t);return m&&new lr(n,m,{resetStart:!0,resetGroupId:!0}).fix(),!0}function Xr(n,t){Ft(t);const e=n.getBlockData(t),o={id:N(),type:"text",text:e.text};e.heading&&(o.heading=e.heading),e.heading&&(o.heading=e.heading);const r=new Uc(n,t),i=H(t),s=J(t);n.deleteBlock(t);const l=Gl(o.id,0);n.insertBlock(U(i),s,o,l),r.fix()}function ix(n){if(!n.selection.range.isCollapsed())return!1;const t=n.selection.focusedBlock;if(!ct(t))return!1;const e=n.selection.range.focus;return!e.isSimple()||e.offset!==0?!1:ge(t)===1?(Xr(n,t),!0):(Jh(n,t),!0)}const sx=B("list-block");function lx(n,t,e){d(sx,ct(t),"not a list block");const o={...n.getBlockData(t),id:N()};return e!=null&&e.level&&(o.level=e.level),e!=null&&e.start&&(o.start=e.start),e!=null&&e.keepText||delete o.text,o}function cx(n){if(Ft(n),!Fc(n))return n;let t=Zn(n);for(;t;){if(!Fc(t))return t;t=Zn(t)}return null}function ax(n,t,e,o){const r=new lr(n,o),i=un(o)+1;Ar(n,t,e,{forceInsertAfter:!0,newBlockData:lx(n,o,{start:i})}),r.fix()}function dx(n){var s;if(n.selection.range.isCollapsed()){const l=n.selection.focusedBlock;if(ct(l)&&W(n,l)===0)return Xr(n,l),!0}n.clearSelectedContents();const t=n.selection.focusedBlock;if(!ct(t))return!1;const e=n.selection.range.focus;if(!e.isSimple())return!1;const o=e.offset,i=(s=o===W(n,t)?cx(t):t)!=null?s:t;return ax(n,t,o,i),!0}function h4(n){d(Ot,ct(n),"not a list block");const{level:t}=Io(n);let e=gt(n);for(;e;){if(ct(e)){const{level:o}=Io(e);if(t===o)return e;if(o<t)return null}e=gt(e)}return null}function f4(n,t){return Ft(t),h4(t)?ge(t)<MI:!1}function ux(n,t,e){let o=gt(t);d(Ot,o,"no prev brother");const r=ge(e);for(;o;){if(o===e)return null;if(ct(o)&&ge(o)===r+1)return o;o=gt(o)}return null}function m4(n,t){if(!f4(n,t))return!1;Ft(t);const e=h4(t);d(Ot,e,"no list prev brother");const o=e,r=ux(n,t,o),i=ge(o)+1;let s=N(),l=1,c=Fe(t);r&&(s=Qr(r),l=un(r)+1,c=Fe(r));const a=Kh(t),f={...n.getBlockData(t),groupId:s,level:i,start:l,...Uh(c)};return n.updateBlockData(t,f),n.doc.beginBatchUpdate(),rx(a).forEach(C=>{const k=n.getBlockData(C);n.updateBlockData(C,{...k,level:k.level+1})}),n.doc.endBatchUpdate(),!0}function hx(n,t,e){return t.length===0||!t.every(o=>ct(o.block))?!1:e==="increase"?f4(n,t[0].block):d4(n,t[0].block)}function g4(n,t,e){if(!hx(n,t,e))return!1;const o=t[0].block,r=ge(o),i=t.filter(a=>ge(a.block)<=r),s=J5(o,{withSelf:!1}),l=new Set(i.map(a=>a.block)),c=s.filter(a=>!l.has(a));return n.undoManager.runInGroup(()=>{let a=null;c.length>0&&(a=new lr(n,c[0])),i.forEach(u=>{e==="increase"?m4(n,u.block):Jh(n,u.block)}),a==null||a.fix()}),!0}function fx(n,t){return m4(n,t)}function mx(n,t){return Jh(n,t)}function gx(n){const t=n.selection.range.getSelectedBlocks();if(t.length>1)return g4(n,t,"increase"),!0;const e=t[0].block;if(!ct(e))return!1;const o=new Uc(n,e);return fx(n,e)&&(o.fix(),new lr(n,e).fix()),!0}function px(n){const t=n.selection.range.getSelectedBlocks();if(t.length>1)return g4(n,t,"decrease"),!0;const e=t[0].block;return ct(e)?(mx(n,e),!0):!1}class Cx{constructor(t){this.editor=t}handleBeforeKeyDown(t,e){const o=t.selection.range.getSelectedBlocks();if(o.length===0||!o.some(i=>ct(i.block)))return!1;switch(e.key){case"Enter":return this.handleEnter(e);case"Backspace":return this.handleBackspace();case"Tab":return this.handleTab(e);default:return!1}}handleEnter(t){const e=this.editor.selection.range.getSelectedBlocks()[0];return!e.block||!ct(e.block)||jn(t,"Shift+Enter")?!1:this.editor.undoManager.runInGroup(()=>dx(this.editor))}handleBackspace(){return this.editor.undoManager.runInGroup(()=>ix(this.editor))}handleTab(t){return jn(t,"Shift+Tab")?this.editor.undoManager.runInGroup(()=>px(this.editor)):this.editor.undoManager.runInGroup(()=>gx(this.editor))}}class bx{constructor(t){h(this,"effectedBlockIds",new Map);h(this,"handleBeforeClearSelection",()=>{this.effectedBlockIds.clear();const t=this.editor.selection.range.getSelectedBlocks();if(t.length===0)return;const e=new Set;t.forEach(r=>{const i=r.block;ct(i)&&e.add(i)});const o=new Map;Array.from(e.values()).forEach(r=>{var c;const i=Ms(r),{start:s}=Io(i);o.set(q(i),s);const l=(c=vI(r))!=null?c:r;o.set(q(l),s)}),this.effectedBlockIds=o});h(this,"handleAfterClearSelection",()=>{Array.from(this.effectedBlockIds.entries()).forEach(([t,e])=>{const o=this.editor.findBlockById(t);!o||Vh(this.editor,o,e)}),this.effectedBlockIds.clear()});this.editor=t,this.editor.addListener("beforeClearSelection",this.handleBeforeClearSelection),this.editor.addListener("afterClearSelection",this.handleAfterClearSelection)}destroy(){this.editor.removeListener("beforeClearSelection",this.handleBeforeClearSelection),this.editor.removeListener("afterClearSelection",this.handleAfterClearSelection)}}const kx=B("customize-list-start-menu");class vx{constructor(t){h(this,"popup");h(this,"block",null);h(this,"show",(t,e)=>{const o=e.querySelector("div.list-container");d(kx,o,"list-block mark does not exist"),this.block=e,this.popup.manualShow(o,{theme:"light"})});h(this,"createDialogContent",()=>{const t=b("div",["customize-start-panel"],null);b("span",["customize-start-panel-title"],t,T.t("list.numberLabel"));const e=b("input",["customize-start-panel-input"],t);e.type="number",e.setAttribute("min","1");const o=b("button",["customize-start-panel-button"],t,T.t("list.confirm"));return this.editor.domEvents.addEventListener(t,"keydown",this.handleKeydown),this.editor.domEvents.addEventListener(o,"click",this.handleOk),t});h(this,"handleDialogShow",()=>{const t=this.block;if(!t)return;const e=this.popup.popupContent,o=e.querySelector("button.customize-start-panel-button"),r=e.querySelector("input.customize-start-panel-input"),i=un(t);!o||!r||requestAnimationFrame(()=>{r.focus(),r.value=String(i)})});h(this,"handleOk",()=>{const e=this.popup.popupContent.querySelector("input.customize-start-panel-input"),o=this.block;if(!o)return;const r=Number(e.value);!r||(this.editor.undoManager.runInGroup(()=>{Rs(this.editor,[o,...Ls(o)],r,{resetGroupId:!0})}),this.popup.close())});h(this,"handleKeydown",(t,e)=>{const o=e;o.isComposing||o.key==="Escape"&&this.popup.close()});this.editor=t,this.popup=new Cs(this.createDialogContent()),this.popup.on("show",this.handleDialogShow)}destroy(){this.popup.destroy()}}function yx(n,t){return Qr(n)===Qr(t)}function wx(n,t){const e=Zn(t),o=gt(t);return!e&&!o||!o||!ct(o)?!1:ct(o)&&yx(o,t)?un(o)!==un(t)-1:!0}function Bx(n,t){return!!Zn(t)}function Ex(n,t){Ft(t);const e=[{id:"continue-numbering",name:T.t("list.continueList")},{id:"start-new-list",name:T.t("list.restartList")},{id:"set-numbering-value",name:T.t("list.changeNumber")}];return wx(n,t)||(e[0].states=["disabled"]),Bx(n,t)||(e[1].states=["disabled"]),e}function Ix(n,t,e){var o,r;if(Ft(t),e.id==="continue-numbering"){const i=gt(t),s=Zn(t)||(i&&ct(i)?i:null);s&&Rs(n,[t,...Ls(t)],un(s)+1,{resetGroupId:!0,groupId:Qr(s)})}if(e.id==="start-new-list"&&n.undoManager.runInGroup(()=>{Rs(n,[t,...Ls(t)],1,{resetGroupId:!0})}),e.id==="set-numbering-value"){const i=(o=n.options.componentsOptions)==null?void 0:o.list;if((r=i==null?void 0:i.onChangeStart)!=null&&r.call(i,n,t,e))return;n.addCustom("list-customize-start-dialog",()=>new vx(n)).show(n,t)}}class xx{constructor(t){h(this,"menu");h(this,"handleClick",(t,e)=>{const o=Ri(e,"div.list-container");if(o&&this.editor.isWritable()){const r=F(o);d(Ot,r,"no parent block"),Ft(r);const i=t.getBlockData(r);if(i&&i.checkbox){t.updateBlockData(r,{...i,checkbox:i.checkbox==="checked"?"unchecked":"checked"});return}this.menu.updateItems(this.getCommandItems(r)),this.menu.manualShow(o),this.activeList(o,!0)}});h(this,"handleMenuClose",()=>{var e;const t=(e=this.menu.tippyInstance)==null?void 0:e.reference;t&&this.activeList(t,!1)});h(this,"handleMenuClick",(t,e)=>{var r;const o=(r=this.menu.tippyInstance)==null?void 0:r.reference;if(o){const i=F(o);i&&Ix(this.editor,i,e)}});this.editor=t,this.editor.addListener("click",this.handleClick),this.menu=new nr([]),this.menu.addListener("close",this.handleMenuClose),this.menu.addListener("click",this.handleMenuClick)}destroy(){this.editor.removeListener("click",this.handleClick),this.menu.removeListener("close",this.handleMenuClose)}getCommandItems(t){return Ex(this.editor,t)}activeList(t,e){const o=F(t);!o||(e?(A(t,"active"),A(o,"active")):(z(t,"active"),z(o,"active")))}}class Tx{constructor(t){this.editor=t}handleBeforeKeyDown(t,e){const o=t.selection.range.getSelectedBlocks();if(o.length===0)return!1;const r=o[0].block;if(!ct(r)||!s4(r))return!1;if(e.key==="ArrowUp"||e.key==="ArrowLeft"){const i=wr(r);return i&&t.selection.selectBlock(i,W(t,i)),!0}if(e.key==="ArrowDown"||e.key==="ArrowRight"){const i=Br(r);return i&&t.selection.selectBlock(i,0),!0}return(e.key==="Delete"||e.key==="Backspace"||e.key==="Escape")&&l4(t,r),!0}}function Sx(n,t,e,o,r){Nu(n,"list-block-init",()=>{setTimeout(()=>{n.input.addHandler(new Tx(n)),n.input.addHandler(new Cx(n)),n.addCustom("list-clear-selection-handler",()=>new bx(n)),n.addCustom("list-marker-menu",()=>new xx(n))})});const i=ke.createBlockContent(n,t,e,o,r),s=r,{level:l,start:c,groupId:a}=s,u=Kr(s);o.setAttribute("data-list-level",`${l}`),o.setAttribute("data-list-start",`${c||1}`),o.setAttribute("data-list-group-id",`${a}`),o.setAttribute("data-list-type",u);const f=PI(s);return o.insertBefore(f,i),s.viewAsMindmap&&setTimeout(()=>{const m=n.getBlockById(r.id);m&&Qh(n,m,{},{mindmapTools:c4,saveData:!1})}),i}const Dx=`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
360
360
  <path d="M8 8H15" stroke="currentColor" stroke-linecap="square" stroke-linejoin="round"></path>
361
361
  <path d="M8 14H15" stroke="currentColor" stroke-linecap="square" stroke-linejoin="round"></path>
362
362
  <path d="M8 2H15" stroke="currentColor" stroke-linecap="square" stroke-linejoin="round"></path>
363
363
  <path d="M4 8H0C0 8 0.552283 8 1.33333 8M4 14C2 13.1429 3.33333 8 1.33333 8M4 2C2 2.85714 3.33333 8 1.33333 8" stroke="currentColor" stroke-linecap="square"></path>
364
364
  </svg>
365
- `;function Lx(n){const t=b("div",["list-to-mindmap-wrap"],null),e=vo("list-to-mindmap",T.t("mindmap.viewAsMindMap"),Dx,[],n.clientId);return t.appendChild(e),b("span",["button-sizer"],t,"A"),t}const Ez="";class Vc{constructor(t){h(this,"toMindmapButton");h(this,"currentBlock",null);h(this,"handleHoveringBlock",t=>{!this.editor.isWritable()||(t&&ct(t)&&Fe(t)!=="unchecked"&&Fe(t)!=="checked"?Rt(t).appendChild(this.toMindmapButton):this.toMindmapButton.remove())});h(this,"handleMouseEnter",()=>{const t=F(this.toMindmapButton);d(Ot,t&&ct(t),"no parent list"),Yh(this.editor,t,!0),this.currentBlock=t});h(this,"handleMouseLeave",()=>{this.currentBlock&&(Yh(this.editor,this.currentBlock,!1),this.currentBlock=null)});h(this,"handleClick",()=>{const t=F(this.toMindmapButton);d(Ot,t&&ct(t),"no parent list"),Qh(this.editor,t,{},{saveData:!0,selectBlock:!0,mindmapTools:c4})});this.editor=t,Nt.get(this.editor).addListener("change",this.handleHoveringBlock),this.toMindmapButton=Lx(t),t.domEvents.addEventListener(this.toMindmapButton,"mouseenter",this.handleMouseEnter),t.domEvents.addEventListener(this.toMindmapButton,"mouseleave",this.handleMouseLeave),t.domEvents.addEventListener(this.toMindmapButton,"click",this.handleClick)}static get(t){return t.findCustomByType(Vc)}destroy(){Nt.get(this.editor).removeListener("change",this.handleHoveringBlock)}hide(){this.currentBlock&&(this.currentBlock=null),this.toMindmapButton.remove()}}const Mx={list:{confirm:"\u786E\u5B9A",setStart:"\u8BBE\u7F6E\u7F16\u53F7",continueList:"\u7EE7\u7EED\u7F16\u53F7",restartList:"\u5F00\u59CB\u65B0\u5217\u8868",changeNumber:"\u4FEE\u6539\u7F16\u53F7\u503C",numberLabel:"\u7F16\u53F7\u987A\u5E8F",mention:{tooltip:"\u63D0\u53CA\u4EBA\u5458\u5E76\u901A\u77E5"}},mindmap:{viewAsMindMap:"\u663E\u793A\u4E3A\u8111\u56FE",autoFit:"\u81EA\u52A8\u7F29\u653E",fullScreen:"\u5168\u5C4F\u67E5\u770B",close:"\u5173\u95ED",exitFullscreen:"\u9000\u51FA\u5168\u5C4F"}},Rx={list:{confirm:"OK",setStart:"Set the number",continueList:"Continue numbering",restartList:"Start a new list",changeNumber:"Set numbering value",numberLabel:"Numbering order",mention:{tooltip:"@Mention someone"}},mindmap:{viewAsMindMap:"View as MindMap",autoFit:"Auto fit",fullScreen:"Fullscreen",close:"Close",exitFullscreen:"Exit fullscreen"}};T.mergeLang({"zh-CN":Mx,"en-US":Rx});const Iz="";function Ax(n,t,e){var o;t==="beginDrag"&&((o=Vc.get(n))==null||o.hide())}const p4={...ke,blockType:"list",createBlockContent:Sx,convertFrom:SI,convertTo:LI,handleDrop:OI,notify:Ax},Xh=B("paragraph");class Ox{constructor(t){h(this,"id","BlockParagraphProvider");this.editor=t}isChecked(t,e){return!!(t[e]||t.level&&(t.ordered===!0&&!t.checkbox&&e==="ordered-list"||t.ordered===!1&&!t.checkbox&&e==="unordered-list")||e==="check-list"&&t.checkbox)}getAvailableCommands(t,e){const o=[],r={"unordered-list":[T.t("commands.unordered"),xt.isMac?T.t("commandDesc.mac.unordered"):T.t("commandDesc.window.unordered"),Ww],"ordered-list":[T.t("commands.ordered"),xt.isMac?T.t("commandDesc.mac.ordered"):T.t("commandDesc.window.ordered"),qw],"check-list":[T.t("commands.check"),void 0,Gw],link:[T.t("commands.link"),xt.isMac?T.t("commandDesc.mac.link"):T.t("commandDesc.window.link"),l5],quoted:[T.t("commands.quote"),void 0,Zw]};if(P(t,e)){const i=q(e),s=ot(e),l=Qe(t,e),c=t.getBlockData(e);Object.entries(r).forEach(([a,[u,f,m]])=>{const C=[];if(this.isChecked(c,a)&&C.push("checked"),a==="link"){if(!t.selection.range.isSimple())return;t.selection.range.getSelectedBlocks().length!==1&&C.push("disabled")}o.push({blockId:i,blockType:s,blockKind:l,id:a,name:u,desc:f,states:C,icon:m,groupIndex:600})})}return o}convertLink(t,e,o){d(Xh,so(e.start),""),d(Xh,so(e.start),"");const r="bottom-start",i=e.start.offset,s=e.end.offset,l=(C,k)=>{t.undoManager.runInGroup(()=>{try{let w=Ul(t.getBlockText(o),i,s,C);w=Vi(i,C.length,w,"link",k),t.setBlockText(o,w),t.selection.selectBlock(o,i+C.length),t.focus()}catch(w){Xh.error(w)}})},c=()=>{t.focus()},a=io(t,o,e)[0];if(!a)return;const u=co(t,o,"link-button-anchor",a),f=t.getBlockText(o),m=zl(f,i);Ds(t,{target:u,linkText:t.getSelectedText(),linkUrl:(m==null?void 0:m.link)||"",onFinished:l,onClose:c,placement:r})}convertToList(t,e,o){const r=Ml(t,e,"list",{offset:0,data:{listType:o}});r&&t.undoManager.runInGroup(()=>{const i=J(e),s=H(e);t.deleteBlock(e),t.insertBlock(U(s),i,r.blockData)})}executeCommand(t,e,o,r){var c;if(!P(t,e))return!1;const i=r.id,s=(c=r.states)==null?void 0:c.includes("checked");let l=!1;if(i==="unordered-list"&&(s?Xr(t,e):this.convertToList(t,e,"unordered"),l=!0),i==="ordered-list"&&(s?Xr(t,e):this.convertToList(t,e,"ordered"),l=!0),i==="check-list"&&(s?Xr(t,e):this.convertToList(t,e,"unchecked"),l=!0),i==="quoted"){const u=t.getBlockData(e).quoted;t.updateBlockData(e,{quoted:u?void 0:!0}),l=!0}if(i==="link"){const a=Nc(t);a.disableTextToolbar(),a.hide(),setTimeout(()=>{a.enableTextToolbar()},1e3),this.convertLink(t,o,e),l=!0}return l}}const _x={left:bs,right:dh,center:uh};class Nx{constructor(t){h(this,"id","BlockAlignProvider");this.editor=t}applyAlignStyle(t,e,o){Object.keys(_x).includes(o)?t.updateBlockData(e,{align:o}):t.updateBlockData(e,{align:null})}isChecked(t,e){return t.align===e}getAvailableCommands(t,e,o){if(P(t,e)){const r=q(e),i=ot(e),s=Qe(t,e),l=t.getBlockData(e),c=a=>{var f;const u=b("span",["toolbar-item-name-container"],null);for(const m of a.children)if((f=m.states)!=null&&f.includes("checked"))return u.innerHTML=m.icon||bs,u;return u.innerHTML=bs,u};return[{id:"align",name:T.t("commands.alignGroup"),blockId:r,blockType:i,blockKind:s,groupIndex:700,dropdown:!0,element:c,manualShowChildren:!0,childrenPlacement:"bottom-start",defaultCheckedChildren:["align-left"],children:[{id:"align-left",name:T.t("commands.alignLeft"),icon:bs,states:this.isChecked(l,"left")?["checked"]:[]},{id:"align-center",name:T.t("commands.alignCenter"),icon:uh,states:this.isChecked(l,"center")?["checked"]:[]},{id:"align-right",name:T.t("commands.alignRight"),icon:dh,states:this.isChecked(l,"right")?["checked"]:[]}],childrenType:"menu"}]}return[]}executeCommand(t,e,o,r){if(r.id.startsWith("align")){const i=r.id.replace(/^align-/,"");return this.applyAlignStyle(t,e,i),!0}return!1}}function $x(n){const e=n.selection.range;if(e.isCollapsed()||e.start.blockId!==e.end.blockId||!e.start.isSimple()||!e.end.isSimple()||e.end.offset-e.start.offset!==1)return!1;const o=n.getBlockById(e.start.blockId);return Wi(n,o,e.start.offset).charType==="box"}const Px=B("toolbar-handler"),jx={id:"",name:"",type:"separator"};class ti{constructor(t){h(this,"toolbar");h(this,"toolbarType","object");h(this,"mouseDown",!1);h(this,"oldRange",null);h(this,"hoveringBlock",null);h(this,"hoveringTextChild",null);h(this,"_disableTextToolbar",!1);h(this,"handleButtonClick",(t,e)=>{this.toolbarType==="text"?(this.editor.editorCommandProviders.executeCommand(this.editor.selection.range,e,{}),this.showTextToolbar("click")):this.hoveringBlock&&aI(this.editor,this.hoveringBlock,this.hoveringTextChild,e)});h(this,"handleClose",()=>{gh(this.editor)&&this.editor.focus()});h(this,"handleDocumentMouseDown",t=>{t.button===0&&(document.addEventListener("mouseup",this.handleDocumentMouseUp),this.mouseDown=!0)});h(this,"handleDocumentMouseUp",()=>{document.removeEventListener("mouseup",this.handleDocumentMouseUp),this.mouseDown=!1,this.handleSelectionChange(this.editor)});h(this,"handleHoveringBlockChildChange",(t,e,o,r)=>{if(!(this.hoveringBlock===t&&this.hoveringTextChild===e)&&(this.hoveringBlock=t,this.hoveringTextChild=e,!(this.toolbar.isVisible&&this.toolbarType==="text"))){if(!t){this.toolbar.close();return}this.showObjectToolbar()}});h(this,"handleSelectionChange",Xt.default(t=>{if(d(Px,t===this.editor,"editor mismatch"),t.selection.range.isCollapsed()||this.mouseDown){this.toolbar.close(),this.oldRange=null;return}if(t.selection.range.getSelectedBlocks().length===0){this.toolbar.close(),this.oldRange=null;return}this.oldRange&&this.oldRange.isEqual(t.selection.range)||(this.oldRange=t.selection.range,this.showTextToolbar("selectionChange"))},50));this.editor=t;const e=t.options.componentsOptions.popover;this.toolbar=new ks([],void 0,{tooltipId:t.clientId,id:"editor-toolbar",overflowBoundary:e==null?void 0:e.overflowBoundary,refuseOverflow:!0}),this.toolbar.on("click",this.handleButtonClick),this.toolbar.on("close",this.handleClose),this.bindEvents(),t.addListener("selectionChanged",this.handleSelectionChange),Nt.get(t).addListener("childChange",this.handleHoveringBlockChildChange),Nt.get(t).addFilter(this),t.editorCommandProviders.registerCommandProvider(new uI(t)),t.editorCommandProviders.registerCommandProvider(new Ox(t)),t.editorCommandProviders.registerCommandProvider(new Nx(t))}disableTextToolbar(){this._disableTextToolbar=!0}enableTextToolbar(){this._disableTextToolbar=!1}hide(){this.toolbar.close()}destroy(){this.unbindEvents(),this.toolbar.destroy(),this.editor.removeListener("selectionChanged",this.handleSelectionChange),Nt.get(this.editor).removeListener("childChange",this.handleHoveringBlockChildChange)}isInBlock(t,e){return t!==this.hoveringBlock?!1:!!(e.target&&e.target instanceof Node&&this.toolbar.popper&&It(this.toolbar.popper,e.target))}bindEvents(){document.addEventListener("mousedown",this.handleDocumentMouseDown)}unbindEvents(){document.removeEventListener("mousedown",this.handleDocumentMouseDown)}update(t){this.showTextToolbar(t)}showTextToolbar(t){if(this._disableTextToolbar||!this.editor.isWritable())return;const o=this.editor.selection.range.getSelectedBlocks();if(o.length===0)return;const r=o[0];if(!r)return;if(o.length===1&&Te(r.block)){t==="click"&&this.showObjectToolbar();return}if($x(this.editor))return;const i=this.editor.editorCommandProviders.getCommands(this.editor.selection.range),s=new Map;i.forEach(u=>{const f=u.groupIndex,m=s.get(f);m?m.push(u):s.set(f,[u])});const l=[[]],c=Array.from(s.entries()).sort((u,f)=>u[0]-f[0]);for(let u=0;u<c.length;u++){const[,f]=c[u];if(f.length===0)continue;let m=l[l.length-1];m.length>0&&m[m.length-1].groupIndex!==f[f.length-1].groupIndex&&(m=[],l.push(m)),m.push(..._c(f))}if(l.length===0){this.toolbar.close();return}this.toolbarType="text";const a=[];if(l.forEach((u,f)=>{const m=u.sort((C,k)=>{var w,y;return((w=C.order)!=null?w:0)-((y=k.order)!=null?y:0)});a.push(...m),f!==l.length-1&&a.push(jx)}),a.length===0){this.toolbar.close();return}if(this.toolbar.updateItems(a),!this.toolbar.isVisible){const u=o[o.length-1],f=!this.editor.selection.range.isReverse()&&u!==r,m=f?u:r,C=eI(this.editor,m),k=co(this.editor,m.block,"editor-quick-menu",C);this.toolbar.manualShow(k,{placement:f?"bottom":"top"})}}showObjectToolbar(){var r,i;if(!this.hoveringBlock)return;const t=this.hoveringBlock,e=this.hoveringTextChild,o=sI(this.editor,t,e);if(!o.length){this.toolbar.close();return}this.toolbarType="object",this.toolbar.isVisible&&((i=(r=this.toolbar)==null?void 0:r.tippyInstance)==null?void 0:i.reference)!==t&&this.toolbar.close(),this.toolbar.updateItems(o),this.toolbar.isVisible||this.toolbar.manualShow(e||it(t),{placement:e?"bottom":"top"})}static register(t){return t.addCustom("toolbar-handler",e=>new ti(e))}static get(t){return t.getCustom("toolbar-handler")}}function qc(n,t,e){n.getBlockData(t).heading===e?n.updateBlockData(t,{heading:null}):n.updateBlockData(t,{heading:e})}function C4(n,t,e){["left","center","right"].includes(e)?n.updateBlockData(t,{align:e}):n.updateBlockData(t,{align:null})}function t1(n,t){const o=n.getBlockData(t).quoted;n.updateBlockData(t,{quoted:o?void 0:!0})}function e1(n,t){return!!(n[t]||n.level&&(n.ordered===!0&&!n.checkbox&&t==="ordered-list"||n.ordered===!1&&!n.checkbox&&t==="unordered-list")||t==="check-list"&&n.checkbox)}function n1(n,t,e){if(!n.selection.range.focus.isSimple())return;const r=n.getBlockData(t);let i;switch(e){case"unordered-list":i=e1(r,"unordered-list")?void 0:"unordered";break;case"ordered-list":i=e1(r,"ordered-list")?void 0:"ordered";break;case"check-list":i=e1(r,"check-list")?void 0:"unchecked";break}if(i){const s=Ml(n,t,"list",{offset:0,data:{listType:i}});s&&n.undoManager.runInGroup(()=>{const l=J(t),c=H(t);n.deleteBlock(t),n.insertBlock(U(c),l,s.blockData)})}else Xr(n,t)}const Hx=Object.freeze(Object.defineProperty({__proto__:null,applyHeadingStyle:qc,applyAlignStyle:C4,applyQuoteStyle:t1,applyList:n1},Symbol.toStringTag,{value:"Module"})),Fx=[nh,oh,rh,ih,sh,lh,ch,ah],zx={Unordered:d5,Ordered:u5,Checkbox:c5,Quote:a5};function b4(n,t){const e=n;e.blockOptions=t,e.itemType="insert-block",n.children&&n.children.forEach(o=>b4(o,t))}function o1(n=1){var r;const t={name:"basic",insertBlockCommandItems:[]};let e=Pc();e<=4?e=5:e<8&&(e+=1);let o=n;for(;o<=e;){const i=`heading-${o}`;(r=t.insertBlockCommandItems)==null||r.push({id:i,icon:Fx[o-1],name:T.t("quickMenu.basic.heading.title",{heading:String(o)}),order:o,group:"basics",value:String(o),subText:me(i)}),o++}return t}function Ux(){const n={name:"basic",insertBlockCommandItems:[]};return["Unordered","Ordered","Checkbox","Quote"].forEach((e,o)=>{var i;const r=`insert-${e.toLocaleLowerCase()}`;(i=n.insertBlockCommandItems)==null||i.push({id:r,name:T.t(`quickMenu.basic.${e.toLocaleLowerCase()}`),icon:zx[e],value:e.toLocaleLowerCase(),group:"basics",order:10+o,subText:me(r)})}),n}class k4{getCommands(){const t=o1(),e=Ux();return[...t.insertBlockCommandItems||[],...e.insertBlockCommandItems||[]]}updateBlock(t,e,o,r){const{value:i,id:s}=r;return s.startsWith("heading-")?qc(t,o,Number.parseInt(i!=null?i:"1",10)||1):i==="ordered"||i==="unordered"||i==="checkbox"?n1(t,o,{ordered:"ordered-list",unordered:"unordered-list",checkbox:"check-list"}[i]):i==="quote"&&t1(t,o),null}async handleUpdateBlockCore(t,e){const o=t.getBlockByIndex(e.containerId,e.blockIndex);return this.updateBlock(t,e.containerId,o,e.item)}async handleInsertEmptyBlockCore(t,e){const{containerId:o,blockIndex:r}=e,i=t.insertTextBlock(void 0,o,r);return this.updateBlock(t,e.containerId,i,e.item)}async executeCommand(t,e,o){if(o.from==="quick-menu"){const r=t.getBlockById(o.blockId),i=t.getParentContainer(r),s=U(i),l=t.getBlockIndex(r);t.undoManager.runInGroup(()=>this.handleUpdateBlockCore(t,{item:e,containerId:s,blockIndex:l}))}else o.from==="block-menu"&&t.undoManager.runInGroup(()=>this.handleInsertEmptyBlockCore(t,{item:e,containerId:o.containerId,blockIndex:o.blockIndex}));return null}}const Vx={basics:100,system:200,common:300,thirdParty:400};class r1{constructor(){h(this,"dataUrl","");h(this,"error",null)}destroy(){}setDataUrl(t){this.error=null,this.dataUrl=t}setError(t){this.dataUrl="",this.error=t}}const qx=B("mathjax-converter"),Wx="MathJax-script";async function Gx(n){var o;window.MathJax||(window.MathJax={options:{skipHtmlTags:["script","noscript","style","textarea","pre","code","annotation","annotation-xml","body"]}});const t=n.getComponentOptions("mathjax"),e=((o=t==null?void 0:t.cdn)==null?void 0:o.mathjax)||"https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js";await $o(e,Wx)}function Zx(){try{window.MathJax&&window.MathJax.texReset()}catch{}}async function v4(n,t){const e="mathjax2Svg";try{await qe.lock(e),Zx(),await Gx(n);const o=await window.MathJax.tex2svgPromise(t),r=o.querySelector("merror");if(r)throw new Error(r.textContent);return o.querySelector("svg").outerHTML}catch(o){throw qx.error(o),o}finally{qe.release(e)}}async function y4(n,t){const e=await v4(n,t);return e?await Tm(e,"image/svg+xml"):""}async function i1(n,t){const o=await v4(n,t),r=new File([o],"math.svg");return(await n.doc.uploadResource(r)).resourceId}const w4=B("edit-mathjax");class Yx{constructor(){h(this,"editMathjaxPopup",null);h(this,"onChange",null);h(this,"tex","");h(this,"handleShow",()=>{setTimeout(()=>{this.getTextarea().focus()})});h(this,"handleClose",t=>{var o;const e=t.content.querySelector("textarea");if(e){const r=e.value;r!==this.tex&&((o=this.onChange)==null||o.call(this,r,!0))}});h(this,"handleKeyup",t=>{var e;t.isComposing||(t.key==="Escape"&&((e=this.editMathjaxPopup)==null||e.close()),this.handleChange(t.target.value))});h(this,"handleChange",Xt.default(t=>{var e;(e=this.onChange)==null||e.call(this,t,!1)},300))}editMathjax(t,e,o){if(!this.editMathjaxPopup)this.editMathjaxPopup=new Cs(this.createPopupContent(e));else{const r=this.getTextarea();r.value=e}this.tex=e,this.editMathjaxPopup.addListener("show",this.handleShow),this.editMathjaxPopup.manualShow(t,{theme:"light"}),this.editMathjaxPopup.removeAllListeners("close"),this.editMathjaxPopup.addListener("close",this.handleClose),this.onChange=o}createPopupContent(t){const e=b("textarea",["mathjax-editor-textarea"],null);return e.value=t,e.addEventListener("keyup",this.handleKeyup),e}getTextarea(){d(w4,this.editMathjaxPopup,"no exists mathjax editor popup");const t=this.editMathjaxPopup.content.querySelector("textarea");return d(w4,t,"no textarea"),t}destroy(){var t;this.onChange=null,(t=this.editMathjaxPopup)==null||t.removeAllListeners()}}function B4(n,t,e,o){n.addCustom("mathjax-editor",()=>new Yx).editMathjax(t,e.trim(),o)}function E4(){return{insert:" ",attributes:{id:N(),box:!0,type:"math",tex:" ",src:"",created:Date.now()}}}function Wc(n,t){const e=n.getBoxData(t),o=F(t);if(!o)return;const r=ao(o,t);n.selection.selectBlock(o,r.start,r.end);const i=async(s,l)=>{if(!s.trim()){n.updateBoxData({...e,tex:s,src:null});return}try{await qe.lock("convertAndUploadMathjax");const c=await i1(n,s);n.updateBoxData({...e,tex:s,src:c})}catch(c){const a=n.getBoxData(t);n.addCustom(`mathjax-box-${a.id}`,()=>new r1).setError(c),n.updateBoxData({...e,tex:s,src:""})}finally{qe.release("convertAndUploadMathjax"),l&&n.focus()}};B4(n,t,e.tex,i)}const Qx=B("mathjax-box");function s1(n,t){n.selection.updateSelection(null);const e=t.target;!e||!(e instanceof HTMLElement)||n.domEvents.removeEventListener(e,null,s1)}async function Kx(n,t,e){try{if(!t.tex.trim())return;const o=await y4(n,t.tex),r=n.findBoxById(t.id);if(!r)return;const i=vd(r);i.innerHTML="";const s=b("img",["mathjax"],i);s.src=o,e.setDataUrl(o),n.domEvents.addEventListener(s,"load",s1)}catch(o){e.setError(o);const r=n.findBoxById(t.id);if(!r)return;const i=r.querySelector(".mathjax-tex-text");A(i,"mathjax-error"),i.innerText=o.message,n.selection.updateSelection(null)}}function Jx(n,t,e,o){const r=o,i=n.addCustom(`mathjax-box-${r.id}`,()=>new r1);if(r.src||i.dataUrl){const c=b("img",["mathjax"],e);c.src=n.doc.buildResourceUrl(r.src||i.dataUrl),n.domEvents.addEventListener(c,"load",s1);return}const s=["mathjax-tex-text"];let l=r.tex;l.trim()?i.error&&(l=i.error.message,s.push("mathjax-error")):l=T.t("mathjax.emptyText"),b("span",s,e,l),Kx(n,r,i)}function Xx(n,t){const e={id:N(),box:!0,type:"math",tex:t,src:"",created:Date.now()};return i1(n,t).then(o=>{if(!n.findBoxById(e.id))return;const i={...e,src:o};n.updateBoxData(i)}).catch(o=>{Qx.error(`failed to convert and upload mathjax: ${JSON.stringify(o)}`)}),e}function tT(n,t,e,o){const r=t;return o==="text"?r.tex:o==="markdown"?` $${r.tex}$ `:r.src?`<img src="${n.doc.buildResourceUrl(r.src,{withToken:!0})}" />`:`<code>$${r.tex}$</code>`}function eT(n,t,e){Wc(n,t)}const Gc={boxType:"math",updateBoxContent:Jx,convertFrom:Xx,convertTo:tT,handleClickBox:eT};async function nT(n,t,e){try{const o=t.embedData,r=await y4(n,o.mathjaxText),i=n.findBlockById(t.id);if(!i)return;const s=it(i);s.innerHTML="";const l=b("img",["mathjax"],s);l.src=r,e.setDataUrl(r)}catch(o){e.setError(o)}}function oT(n,t){if(n.readonly||!t.target||!(t.target instanceof Node))return;const e=F(t.target);if(!e||!Te(e)||Oe(e)!=="math")return;const o=it(e),r=o.querySelector("img")||o.querySelector("span.mathjax-tex-text");if(!r||!It(r,t.target))return;const s=n.getBlockData(e).embedData;B4(n,r,s.mathjaxText,async l=>{const c=await i1(n,l),a={mathjaxText:l,src:c};n.updateEmbedData(e,a)})}function rT(n,t,e){const o=e.embedData,r=n.addCustom(`mathjax-block-${e.id}`,()=>new r1);if(n.domEvents.addEventListener(t,"click",oT),o.src||r.dataUrl){const i=b("img",["mathjax"],t);i.src=n.doc.buildResourceUrl(o.src||r.dataUrl);return}r.error,b("span",["mathjax-tex-text"],t,o.mathjaxText),nT(n,e,r)}function iT(n,t,e){if(!P(n,t))return null;const o=n.getBlockString(t).trim();if(!o||!o.startsWith("$$")||!o.endsWith("$$"))return null;const r=ld(o,"$");if(!r)return null;const i={mathjaxText:r,src:""};return{blockData:{id:N(),type:"embed",embedType:"math",embedData:i}}}function sT(n){return{name:"Mathjax"}}function lT(n,t){const e=it(t);n.domEvents.removeAllListeners(e)}function cT(n,t,e,o){const r=t.embedData;return o==="html"?`<img src="${n.doc.buildResourceUrl(r.src,{withToken:!0})}" />`:o==="markdown"?`
365
+ `;function Lx(n){const t=b("div",["list-to-mindmap-wrap"],null),e=yo("list-to-mindmap",T.t("mindmap.viewAsMindMap"),Dx,[],n.clientId);return t.appendChild(e),b("span",["button-sizer"],t,"A"),t}const Ez="";class Vc{constructor(t){h(this,"toMindmapButton");h(this,"currentBlock",null);h(this,"handleHoveringBlock",t=>{!this.editor.isWritable()||(t&&ct(t)&&Fe(t)!=="unchecked"&&Fe(t)!=="checked"?Rt(t).appendChild(this.toMindmapButton):this.toMindmapButton.remove())});h(this,"handleMouseEnter",()=>{const t=F(this.toMindmapButton);d(Ot,t&&ct(t),"no parent list"),Yh(this.editor,t,!0),this.currentBlock=t});h(this,"handleMouseLeave",()=>{this.currentBlock&&(Yh(this.editor,this.currentBlock,!1),this.currentBlock=null)});h(this,"handleClick",()=>{const t=F(this.toMindmapButton);d(Ot,t&&ct(t),"no parent list"),Qh(this.editor,t,{},{saveData:!0,selectBlock:!0,mindmapTools:c4})});this.editor=t,Nt.get(this.editor).addListener("change",this.handleHoveringBlock),this.toMindmapButton=Lx(t),t.domEvents.addEventListener(this.toMindmapButton,"mouseenter",this.handleMouseEnter),t.domEvents.addEventListener(this.toMindmapButton,"mouseleave",this.handleMouseLeave),t.domEvents.addEventListener(this.toMindmapButton,"click",this.handleClick)}static get(t){return t.findCustomByType(Vc)}destroy(){Nt.get(this.editor).removeListener("change",this.handleHoveringBlock)}hide(){this.currentBlock&&(this.currentBlock=null),this.toMindmapButton.remove()}}const Mx={list:{confirm:"\u786E\u5B9A",setStart:"\u8BBE\u7F6E\u7F16\u53F7",continueList:"\u7EE7\u7EED\u7F16\u53F7",restartList:"\u5F00\u59CB\u65B0\u5217\u8868",changeNumber:"\u4FEE\u6539\u7F16\u53F7\u503C",numberLabel:"\u7F16\u53F7\u987A\u5E8F",mention:{tooltip:"\u63D0\u53CA\u4EBA\u5458\u5E76\u901A\u77E5"}},mindmap:{viewAsMindMap:"\u663E\u793A\u4E3A\u8111\u56FE",autoFit:"\u81EA\u52A8\u7F29\u653E",fullScreen:"\u5168\u5C4F\u67E5\u770B",close:"\u5173\u95ED",exitFullscreen:"\u9000\u51FA\u5168\u5C4F"}},Rx={list:{confirm:"OK",setStart:"Set the number",continueList:"Continue numbering",restartList:"Start a new list",changeNumber:"Set numbering value",numberLabel:"Numbering order",mention:{tooltip:"@Mention someone"}},mindmap:{viewAsMindMap:"View as MindMap",autoFit:"Auto fit",fullScreen:"Fullscreen",close:"Close",exitFullscreen:"Exit fullscreen"}};T.mergeLang({"zh-CN":Mx,"en-US":Rx});const Iz="";function Ax(n,t,e){var o;t==="beginDrag"&&((o=Vc.get(n))==null||o.hide())}const p4={...ke,blockType:"list",createBlockContent:Sx,convertFrom:SI,convertTo:LI,handleDrop:OI,notify:Ax},Xh=B("paragraph");class Ox{constructor(t){h(this,"id","BlockParagraphProvider");this.editor=t}isChecked(t,e){return!!(t[e]||t.level&&(t.ordered===!0&&!t.checkbox&&e==="ordered-list"||t.ordered===!1&&!t.checkbox&&e==="unordered-list")||e==="check-list"&&t.checkbox)}getAvailableCommands(t,e){const o=[],r={"unordered-list":[T.t("commands.unordered"),xt.isMac?T.t("commandDesc.mac.unordered"):T.t("commandDesc.window.unordered"),Ww],"ordered-list":[T.t("commands.ordered"),xt.isMac?T.t("commandDesc.mac.ordered"):T.t("commandDesc.window.ordered"),qw],"check-list":[T.t("commands.check"),void 0,Gw],link:[T.t("commands.link"),xt.isMac?T.t("commandDesc.mac.link"):T.t("commandDesc.window.link"),l5],quoted:[T.t("commands.quote"),void 0,Zw]};if(P(t,e)){const i=q(e),s=ot(e),l=Qe(t,e),c=t.getBlockData(e);Object.entries(r).forEach(([a,[u,f,m]])=>{const C=[];if(this.isChecked(c,a)&&C.push("checked"),a==="link"){if(!t.selection.range.isSimple())return;t.selection.range.getSelectedBlocks().length!==1&&C.push("disabled")}o.push({blockId:i,blockType:s,blockKind:l,id:a,name:u,desc:f,states:C,icon:m,groupIndex:600})})}return o}convertLink(t,e,o){d(Xh,lo(e.start),""),d(Xh,lo(e.start),"");const r="bottom-start",i=e.start.offset,s=e.end.offset,l=(C,k)=>{t.undoManager.runInGroup(()=>{try{let w=Ul(t.getBlockText(o),i,s,C);w=Vi(i,C.length,w,"link",k),t.setBlockText(o,w),t.selection.selectBlock(o,i+C.length),t.focus()}catch(w){Xh.error(w)}})},c=()=>{t.focus()},a=so(t,o,e)[0];if(!a)return;const u=ao(t,o,"link-button-anchor",a),f=t.getBlockText(o),m=zl(f,i);Ds(t,{target:u,linkText:t.getSelectedText(),linkUrl:(m==null?void 0:m.link)||"",onFinished:l,onClose:c,placement:r})}convertToList(t,e,o){const r=Ml(t,e,"list",{offset:0,data:{listType:o}});r&&t.undoManager.runInGroup(()=>{const i=J(e),s=H(e);t.deleteBlock(e),t.insertBlock(U(s),i,r.blockData)})}executeCommand(t,e,o,r){var c;if(!P(t,e))return!1;const i=r.id,s=(c=r.states)==null?void 0:c.includes("checked");let l=!1;if(i==="unordered-list"&&(s?Xr(t,e):this.convertToList(t,e,"unordered"),l=!0),i==="ordered-list"&&(s?Xr(t,e):this.convertToList(t,e,"ordered"),l=!0),i==="check-list"&&(s?Xr(t,e):this.convertToList(t,e,"unchecked"),l=!0),i==="quoted"){const u=t.getBlockData(e).quoted;t.updateBlockData(e,{quoted:u?void 0:!0}),l=!0}if(i==="link"){const a=Nc(t);a.disableTextToolbar(),a.hide(),setTimeout(()=>{a.enableTextToolbar()},1e3),this.convertLink(t,o,e),l=!0}return l}}const _x={left:bs,right:dh,center:uh};class Nx{constructor(t){h(this,"id","BlockAlignProvider");this.editor=t}applyAlignStyle(t,e,o){Object.keys(_x).includes(o)?t.updateBlockData(e,{align:o}):t.updateBlockData(e,{align:null})}isChecked(t,e){return t.align===e}getAvailableCommands(t,e,o){if(P(t,e)){const r=q(e),i=ot(e),s=Qe(t,e),l=t.getBlockData(e),c=a=>{var f;const u=b("span",["toolbar-item-name-container"],null);for(const m of a.children)if((f=m.states)!=null&&f.includes("checked"))return u.innerHTML=m.icon||bs,u;return u.innerHTML=bs,u};return[{id:"align",name:T.t("commands.alignGroup"),blockId:r,blockType:i,blockKind:s,groupIndex:700,dropdown:!0,element:c,manualShowChildren:!0,childrenPlacement:"bottom-start",defaultCheckedChildren:["align-left"],children:[{id:"align-left",name:T.t("commands.alignLeft"),icon:bs,states:this.isChecked(l,"left")?["checked"]:[]},{id:"align-center",name:T.t("commands.alignCenter"),icon:uh,states:this.isChecked(l,"center")?["checked"]:[]},{id:"align-right",name:T.t("commands.alignRight"),icon:dh,states:this.isChecked(l,"right")?["checked"]:[]}],childrenType:"menu"}]}return[]}executeCommand(t,e,o,r){if(r.id.startsWith("align")){const i=r.id.replace(/^align-/,"");return this.applyAlignStyle(t,e,i),!0}return!1}}function $x(n){const e=n.selection.range;if(e.isCollapsed()||e.start.blockId!==e.end.blockId||!e.start.isSimple()||!e.end.isSimple()||e.end.offset-e.start.offset!==1)return!1;const o=n.getBlockById(e.start.blockId);return Wi(n,o,e.start.offset).charType==="box"}const Px=B("toolbar-handler"),jx={id:"",name:"",type:"separator"};class ti{constructor(t){h(this,"toolbar");h(this,"toolbarType","object");h(this,"mouseDown",!1);h(this,"oldRange",null);h(this,"hoveringBlock",null);h(this,"hoveringTextChild",null);h(this,"_disableTextToolbar",!1);h(this,"handleButtonClick",(t,e)=>{this.toolbarType==="text"?(this.editor.editorCommandProviders.executeCommand(this.editor.selection.range,e,{}),this.showTextToolbar("click")):this.hoveringBlock&&aI(this.editor,this.hoveringBlock,this.hoveringTextChild,e)});h(this,"handleClose",()=>{gh(this.editor)&&this.editor.focus()});h(this,"handleDocumentMouseDown",t=>{t.button===0&&(document.addEventListener("mouseup",this.handleDocumentMouseUp),this.mouseDown=!0)});h(this,"handleDocumentMouseUp",()=>{document.removeEventListener("mouseup",this.handleDocumentMouseUp),this.mouseDown=!1,this.handleSelectionChange(this.editor)});h(this,"handleHoveringBlockChildChange",(t,e,o,r)=>{if(!(this.hoveringBlock===t&&this.hoveringTextChild===e)&&(this.hoveringBlock=t,this.hoveringTextChild=e,!(this.toolbar.isVisible&&this.toolbarType==="text"))){if(!t){this.toolbar.close();return}this.showObjectToolbar()}});h(this,"handleSelectionChange",Xt.default(t=>{if(d(Px,t===this.editor,"editor mismatch"),t.selection.range.isCollapsed()||this.mouseDown){this.toolbar.close(),this.oldRange=null;return}if(t.selection.range.getSelectedBlocks().length===0){this.toolbar.close(),this.oldRange=null;return}this.oldRange&&this.oldRange.isEqual(t.selection.range)||(this.oldRange=t.selection.range,this.showTextToolbar("selectionChange"))},50));this.editor=t;const e=t.options.componentsOptions.popover;this.toolbar=new ks([],void 0,{tooltipId:t.clientId,id:"editor-toolbar",overflowBoundary:e==null?void 0:e.overflowBoundary,refuseOverflow:!0}),this.toolbar.on("click",this.handleButtonClick),this.toolbar.on("close",this.handleClose),this.bindEvents(),t.addListener("selectionChanged",this.handleSelectionChange),Nt.get(t).addListener("childChange",this.handleHoveringBlockChildChange),Nt.get(t).addFilter(this),t.editorCommandProviders.registerCommandProvider(new uI(t)),t.editorCommandProviders.registerCommandProvider(new Ox(t)),t.editorCommandProviders.registerCommandProvider(new Nx(t))}disableTextToolbar(){this._disableTextToolbar=!0}enableTextToolbar(){this._disableTextToolbar=!1}hide(){this.toolbar.close()}destroy(){this.unbindEvents(),this.toolbar.destroy(),this.editor.removeListener("selectionChanged",this.handleSelectionChange),Nt.get(this.editor).removeListener("childChange",this.handleHoveringBlockChildChange)}isInBlock(t,e){return t!==this.hoveringBlock?!1:!!(e.target&&e.target instanceof Node&&this.toolbar.popper&&It(this.toolbar.popper,e.target))}bindEvents(){document.addEventListener("mousedown",this.handleDocumentMouseDown)}unbindEvents(){document.removeEventListener("mousedown",this.handleDocumentMouseDown)}update(t){this.showTextToolbar(t)}showTextToolbar(t){if(this._disableTextToolbar||!this.editor.isWritable())return;const o=this.editor.selection.range.getSelectedBlocks();if(o.length===0)return;const r=o[0];if(!r)return;if(o.length===1&&Te(r.block)){t==="click"&&this.showObjectToolbar();return}if($x(this.editor))return;const i=this.editor.editorCommandProviders.getCommands(this.editor.selection.range),s=new Map;i.forEach(u=>{const f=u.groupIndex,m=s.get(f);m?m.push(u):s.set(f,[u])});const l=[[]],c=Array.from(s.entries()).sort((u,f)=>u[0]-f[0]);for(let u=0;u<c.length;u++){const[,f]=c[u];if(f.length===0)continue;let m=l[l.length-1];m.length>0&&m[m.length-1].groupIndex!==f[f.length-1].groupIndex&&(m=[],l.push(m)),m.push(..._c(f))}if(l.length===0){this.toolbar.close();return}this.toolbarType="text";const a=[];if(l.forEach((u,f)=>{const m=u.sort((C,k)=>{var w,y;return((w=C.order)!=null?w:0)-((y=k.order)!=null?y:0)});a.push(...m),f!==l.length-1&&a.push(jx)}),a.length===0){this.toolbar.close();return}if(this.toolbar.updateItems(a),!this.toolbar.isVisible){const u=o[o.length-1],f=!this.editor.selection.range.isReverse()&&u!==r,m=f?u:r,C=eI(this.editor,m),k=ao(this.editor,m.block,"editor-quick-menu",C);this.toolbar.manualShow(k,{placement:f?"bottom":"top"})}}showObjectToolbar(){var r,i;if(!this.hoveringBlock)return;const t=this.hoveringBlock,e=this.hoveringTextChild,o=sI(this.editor,t,e);if(!o.length){this.toolbar.close();return}this.toolbarType="object",this.toolbar.isVisible&&((i=(r=this.toolbar)==null?void 0:r.tippyInstance)==null?void 0:i.reference)!==t&&this.toolbar.close(),this.toolbar.updateItems(o),this.toolbar.isVisible||this.toolbar.manualShow(e||it(t),{placement:e?"bottom":"top"})}static register(t){return t.addCustom("toolbar-handler",e=>new ti(e))}static get(t){return t.getCustom("toolbar-handler")}}function qc(n,t,e){n.getBlockData(t).heading===e?n.updateBlockData(t,{heading:null}):n.updateBlockData(t,{heading:e})}function C4(n,t,e){["left","center","right"].includes(e)?n.updateBlockData(t,{align:e}):n.updateBlockData(t,{align:null})}function t1(n,t){const o=n.getBlockData(t).quoted;n.updateBlockData(t,{quoted:o?void 0:!0})}function e1(n,t){return!!(n[t]||n.level&&(n.ordered===!0&&!n.checkbox&&t==="ordered-list"||n.ordered===!1&&!n.checkbox&&t==="unordered-list")||t==="check-list"&&n.checkbox)}function n1(n,t,e){if(!n.selection.range.focus.isSimple())return;const r=n.getBlockData(t);let i;switch(e){case"unordered-list":i=e1(r,"unordered-list")?void 0:"unordered";break;case"ordered-list":i=e1(r,"ordered-list")?void 0:"ordered";break;case"check-list":i=e1(r,"check-list")?void 0:"unchecked";break}if(i){const s=Ml(n,t,"list",{offset:0,data:{listType:i}});s&&n.undoManager.runInGroup(()=>{const l=J(t),c=H(t);n.deleteBlock(t),n.insertBlock(U(c),l,s.blockData)})}else Xr(n,t)}const Hx=Object.freeze(Object.defineProperty({__proto__:null,applyHeadingStyle:qc,applyAlignStyle:C4,applyQuoteStyle:t1,applyList:n1},Symbol.toStringTag,{value:"Module"})),Fx=[nh,oh,rh,ih,sh,lh,ch,ah],zx={Unordered:d5,Ordered:u5,Checkbox:c5,Quote:a5};function b4(n,t){const e=n;e.blockOptions=t,e.itemType="insert-block",n.children&&n.children.forEach(o=>b4(o,t))}function o1(n=1){var r;const t={name:"basic",insertBlockCommandItems:[]};let e=Pc();e<=4?e=5:e<8&&(e+=1);let o=n;for(;o<=e;){const i=`heading-${o}`;(r=t.insertBlockCommandItems)==null||r.push({id:i,icon:Fx[o-1],name:T.t("quickMenu.basic.heading.title",{heading:String(o)}),order:o,group:"basics",value:String(o),subText:me(i)}),o++}return t}function Ux(){const n={name:"basic",insertBlockCommandItems:[]};return["Unordered","Ordered","Checkbox","Quote"].forEach((e,o)=>{var i;const r=`insert-${e.toLocaleLowerCase()}`;(i=n.insertBlockCommandItems)==null||i.push({id:r,name:T.t(`quickMenu.basic.${e.toLocaleLowerCase()}`),icon:zx[e],value:e.toLocaleLowerCase(),group:"basics",order:10+o,subText:me(r)})}),n}class k4{getCommands(){const t=o1(),e=Ux();return[...t.insertBlockCommandItems||[],...e.insertBlockCommandItems||[]]}updateBlock(t,e,o,r){const{value:i,id:s}=r;return s.startsWith("heading-")?qc(t,o,Number.parseInt(i!=null?i:"1",10)||1):i==="ordered"||i==="unordered"||i==="checkbox"?n1(t,o,{ordered:"ordered-list",unordered:"unordered-list",checkbox:"check-list"}[i]):i==="quote"&&t1(t,o),null}async handleUpdateBlockCore(t,e){const o=t.getBlockByIndex(e.containerId,e.blockIndex);return this.updateBlock(t,e.containerId,o,e.item)}async handleInsertEmptyBlockCore(t,e){const{containerId:o,blockIndex:r}=e,i=t.insertTextBlock(void 0,o,r);return this.updateBlock(t,e.containerId,i,e.item)}async executeCommand(t,e,o){if(o.from==="quick-menu"){const r=t.getBlockById(o.blockId),i=t.getParentContainer(r),s=U(i),l=t.getBlockIndex(r);t.undoManager.runInGroup(()=>this.handleUpdateBlockCore(t,{item:e,containerId:s,blockIndex:l}))}else o.from==="block-menu"&&t.undoManager.runInGroup(()=>this.handleInsertEmptyBlockCore(t,{item:e,containerId:o.containerId,blockIndex:o.blockIndex}));return null}}const Vx={basics:100,system:200,common:300,thirdParty:400};class r1{constructor(){h(this,"dataUrl","");h(this,"error",null)}destroy(){}setDataUrl(t){this.error=null,this.dataUrl=t}setError(t){this.dataUrl="",this.error=t}}const qx=B("mathjax-converter"),Wx="MathJax-script";async function Gx(n){var o;window.MathJax||(window.MathJax={options:{skipHtmlTags:["script","noscript","style","textarea","pre","code","annotation","annotation-xml","body"]}});const t=n.getComponentOptions("mathjax"),e=((o=t==null?void 0:t.cdn)==null?void 0:o.mathjax)||"https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js";await Po(e,Wx)}function Zx(){try{window.MathJax&&window.MathJax.texReset()}catch{}}async function v4(n,t){const e="mathjax2Svg";try{await qe.lock(e),Zx(),await Gx(n);const o=await window.MathJax.tex2svgPromise(t),r=o.querySelector("merror");if(r)throw new Error(r.textContent);return o.querySelector("svg").outerHTML}catch(o){throw qx.error(o),o}finally{qe.release(e)}}async function y4(n,t){const e=await v4(n,t);return e?await Tm(e,"image/svg+xml"):""}async function i1(n,t){const o=await v4(n,t),r=new File([o],"math.svg");return(await n.doc.uploadResource(r)).resourceId}const w4=B("edit-mathjax");class Yx{constructor(){h(this,"editMathjaxPopup",null);h(this,"onChange",null);h(this,"tex","");h(this,"handleShow",()=>{setTimeout(()=>{this.getTextarea().focus()})});h(this,"handleClose",t=>{var o;const e=t.content.querySelector("textarea");if(e){const r=e.value;r!==this.tex&&((o=this.onChange)==null||o.call(this,r,!0))}});h(this,"handleKeyup",t=>{var e;t.isComposing||(t.key==="Escape"&&((e=this.editMathjaxPopup)==null||e.close()),this.handleChange(t.target.value))});h(this,"handleChange",Xt.default(t=>{var e;(e=this.onChange)==null||e.call(this,t,!1)},300))}editMathjax(t,e,o){if(!this.editMathjaxPopup)this.editMathjaxPopup=new Cs(this.createPopupContent(e));else{const r=this.getTextarea();r.value=e}this.tex=e,this.editMathjaxPopup.addListener("show",this.handleShow),this.editMathjaxPopup.manualShow(t,{theme:"light"}),this.editMathjaxPopup.removeAllListeners("close"),this.editMathjaxPopup.addListener("close",this.handleClose),this.onChange=o}createPopupContent(t){const e=b("textarea",["mathjax-editor-textarea"],null);return e.value=t,e.addEventListener("keyup",this.handleKeyup),e}getTextarea(){d(w4,this.editMathjaxPopup,"no exists mathjax editor popup");const t=this.editMathjaxPopup.content.querySelector("textarea");return d(w4,t,"no textarea"),t}destroy(){var t;this.onChange=null,(t=this.editMathjaxPopup)==null||t.removeAllListeners()}}function B4(n,t,e,o){n.addCustom("mathjax-editor",()=>new Yx).editMathjax(t,e.trim(),o)}function E4(){return{insert:" ",attributes:{id:N(),box:!0,type:"math",tex:" ",src:"",created:Date.now()}}}function Wc(n,t){const e=n.getBoxData(t),o=F(t);if(!o)return;const r=uo(o,t);n.selection.selectBlock(o,r.start,r.end);const i=async(s,l)=>{if(!s.trim()){n.updateBoxData({...e,tex:s,src:null});return}try{await qe.lock("convertAndUploadMathjax");const c=await i1(n,s);n.updateBoxData({...e,tex:s,src:c})}catch(c){const a=n.getBoxData(t);n.addCustom(`mathjax-box-${a.id}`,()=>new r1).setError(c),n.updateBoxData({...e,tex:s,src:""})}finally{qe.release("convertAndUploadMathjax"),l&&n.focus()}};B4(n,t,e.tex,i)}const Qx=B("mathjax-box");function s1(n,t){n.selection.updateSelection(null);const e=t.target;!e||!(e instanceof HTMLElement)||n.domEvents.removeEventListener(e,null,s1)}async function Kx(n,t,e){try{if(!t.tex.trim())return;const o=await y4(n,t.tex),r=n.findBoxById(t.id);if(!r)return;const i=vd(r);i.innerHTML="";const s=b("img",["mathjax"],i);s.src=o,e.setDataUrl(o),n.domEvents.addEventListener(s,"load",s1)}catch(o){e.setError(o);const r=n.findBoxById(t.id);if(!r)return;const i=r.querySelector(".mathjax-tex-text");A(i,"mathjax-error"),i.innerText=o.message,n.selection.updateSelection(null)}}function Jx(n,t,e,o){const r=o,i=n.addCustom(`mathjax-box-${r.id}`,()=>new r1);if(r.src||i.dataUrl){const c=b("img",["mathjax"],e);c.src=n.doc.buildResourceUrl(r.src||i.dataUrl),n.domEvents.addEventListener(c,"load",s1);return}const s=["mathjax-tex-text"];let l=r.tex;l.trim()?i.error&&(l=i.error.message,s.push("mathjax-error")):l=T.t("mathjax.emptyText"),b("span",s,e,l),Kx(n,r,i)}function Xx(n,t){const e={id:N(),box:!0,type:"math",tex:t,src:"",created:Date.now()};return i1(n,t).then(o=>{if(!n.findBoxById(e.id))return;const i={...e,src:o};n.updateBoxData(i)}).catch(o=>{Qx.error(`failed to convert and upload mathjax: ${JSON.stringify(o)}`)}),e}function tT(n,t,e,o){const r=t;return o==="text"?r.tex:o==="markdown"?` $${r.tex}$ `:r.src?`<img src="${n.doc.buildResourceUrl(r.src,{withToken:!0})}" />`:`<code>$${r.tex}$</code>`}function eT(n,t,e){Wc(n,t)}const Gc={boxType:"math",updateBoxContent:Jx,convertFrom:Xx,convertTo:tT,handleClickBox:eT};async function nT(n,t,e){try{const o=t.embedData,r=await y4(n,o.mathjaxText),i=n.findBlockById(t.id);if(!i)return;const s=it(i);s.innerHTML="";const l=b("img",["mathjax"],s);l.src=r,e.setDataUrl(r)}catch(o){e.setError(o)}}function oT(n,t){if(n.readonly||!t.target||!(t.target instanceof Node))return;const e=F(t.target);if(!e||!Te(e)||Oe(e)!=="math")return;const o=it(e),r=o.querySelector("img")||o.querySelector("span.mathjax-tex-text");if(!r||!It(r,t.target))return;const s=n.getBlockData(e).embedData;B4(n,r,s.mathjaxText,async l=>{const c=await i1(n,l),a={mathjaxText:l,src:c};n.updateEmbedData(e,a)})}function rT(n,t,e){const o=e.embedData,r=n.addCustom(`mathjax-block-${e.id}`,()=>new r1);if(n.domEvents.addEventListener(t,"click",oT),o.src||r.dataUrl){const i=b("img",["mathjax"],t);i.src=n.doc.buildResourceUrl(o.src||r.dataUrl);return}r.error,b("span",["mathjax-tex-text"],t,o.mathjaxText),nT(n,e,r)}function iT(n,t,e){if(!P(n,t))return null;const o=n.getBlockString(t).trim();if(!o||!o.startsWith("$$")||!o.endsWith("$$"))return null;const r=ld(o,"$");if(!r)return null;const i={mathjaxText:r,src:""};return{blockData:{id:N(),type:"embed",embedType:"math",embedData:i}}}function sT(n){return{name:"Mathjax"}}function lT(n,t){const e=it(t);n.domEvents.removeAllListeners(e)}function cT(n,t,e,o){const r=t.embedData;return o==="html"?`<img src="${n.doc.buildResourceUrl(r.src,{withToken:!0})}" />`:o==="markdown"?`
366
366
  $$${r.mathjaxText}$$
367
- `:r.mathjaxText}const l1={embedType:"math",createEmbedContent:rT,getOptions:sT,convertFrom:iT,handleDeleteBlock:lT,convertTo:cT},xz="",aT={mathjax:{emptyText:"\u7A7A\u7684\u516C\u5F0F",abstract:"\u516C\u5F0F"}},dT={mathjax:{emptyText:"Empty Tex",abstract:"TeX"}};T.mergeLang({"zh-CN":aT,"en-US":dT});function uT(n,t,e,o){const r=n.getBlockByIndex(t,e),i=n.getBlockText(r),{left:s}=be(i,o);if(!bt(s).endsWith("$$$$"))return!1;const c=o-4,a=o,u={id:N(),box:!0,type:"math",tex:" ",src:"",created:Date.now()};return n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,c,a-c),n.insertBoxToBlock(r,c,u),setTimeout(()=>{const f=n.getBoxById(u.id);Wc(n,f)})}),!0}class hT{handleAfterInsertText(t,e,o,r,i){return!!(i===" "&&uT(t,e,o,r))}}const ei=B("inline-box-items");function fT(n,t,e){return n.undoManager.runInGroup(()=>{var s;let o=n.getBlockByIndex(t,e);Tt(n,o)||(o=n.insertTextBlock([],t,e));const r=E4();n.setBlockText(o,[r]);const i=(s=r.attributes)==null?void 0:s.id;return d(ei,i,"mathjax box id is empty"),setTimeout(()=>{const l=n.getBoxById(i);Wc(n,l)},100),o})}function mT(n,t,e){let o=n.getBlockByIndex(t,e),r="bottom-start";return Tt(n,o)||(r="top-start"),Ds(n,{target:o,linkText:"",linkUrl:"",onFinished:(l,c)=>{n.undoManager.runInGroup(()=>{try{Tt(n,o)||(o=n.insertTextBlock([],t,e));const a=$e(l,{link:c}),u=$e(" ",null),f=[a,u];n.insertTextToBlock(o,0,f),n.selection.selectBlock(o,ue(f)),n.focus()}catch(a){ei.error(a)}})},onClose:()=>{n.focus()},placement:r}),o}function gT(n,t,e){return n.undoManager.runInGroup(()=>{var l;const o=n.getBlockByIndex(t,e),r=n.selection.range;d(ei,so(r.start),"invalid block position");const i=E4();n.insertBoxToBlock(o,r.start.offset,i.attributes);const s=(l=i.attributes)==null?void 0:l.id;return d(ei,s,"mathjax box id is empty"),setTimeout(()=>{const c=n.getBoxById(s);Wc(n,c)},100),o})}function pT(n,t,e){const o=n.getBlockByIndex(t,e),r=n.selection.range;d(ei,so(r.start),"invalid block position");const i=io(n,o,r);if(i.length===0)return;const s=i[0],l=co(n,o,"quick-menu-inline-link",s);Ds(n,{target:l,linkText:"",linkUrl:"",onFinished:(u,f)=>{n.undoManager.runInGroup(()=>{try{const m=n.getBlockText(o),C=ho(m,r.start.offset,u,{link:f});n.setBlockText(o,C),n.selection.selectBlock(o,r.start.offset+u.length),n.focus()}catch(m){ei.error(m)}})},onClose:()=>{n.focus()},placement:"bottom-start"})}class CT{getCommands(){return[{id:"insert-math",name:T.t("quickMenu.inlineBox.math"),icon:tB,order:900,group:"common",subText:me("insert-math")},{id:"insert-link",name:T.t("quickMenu.inlineBox.link"),icon:l5,order:400,group:"common",subText:me("insert-link")}]}async handleUpdateBlockCore(t,e){switch(e.item.id){case"insert-math":return gT(t,e.containerId,e.blockIndex);case"insert-link":return pT(t,e.containerId,e.blockIndex);default:return null}}async handleInsertEmptyBlockCore(t,e){switch(e.item.id){case"insert-math":return fT(t,e.containerId,e.blockIndex);case"insert-link":return mT(t,e.containerId,e.blockIndex);default:return null}}async executeCommand(t,e,o){if(o.from==="quick-menu"){const r=t.getBlockById(o.blockId),i=t.getParentContainer(r),s=U(i),l=t.getBlockIndex(r);t.undoManager.runInGroup(()=>this.handleUpdateBlockCore(t,{item:e,containerId:s,blockIndex:l}))}else o.from==="block-menu"&&t.undoManager.runInGroup(()=>this.handleInsertEmptyBlockCore(t,{item:e,containerId:o.containerId,blockIndex:o.blockIndex}));return null}}function bT(n){var o,r;const t=(r=(o=n.options.componentsOptions)==null?void 0:o.quickMenu)==null?void 0:r.commandProviders;if(!t)return[];const e=[];return[...t,new k4,new CT].forEach(i=>{const s=i.getCommands(n);e.push(...s.map(l=>({...l,itemType:"insert-block",commandProvider:i})))}),e}function kT(n){const t=[];return n.editorBlocks.forEach(e=>{if(!e.getOptions)return;const o=e.getOptions(n);!o.insertBlockCommandItems||(o.insertBlockCommandItems.forEach(r=>{b4(r,o)}),t.push(...o.insertBlockCommandItems))}),t.push(...bT(n)),t}function c1(n){const t=kT(n),e=new Map;t.forEach(i=>{var c;const s=(c=i.group)!=null?c:"";let l=e.get(s);l?l.items.push(i):(l={group:s,order:i.groupOrder||Vx[s]||1e3,items:[i]},e.set(s,l))});const o=Array.from(e.values());o.sort((i,s)=>i.order-s.order),o.forEach(i=>{i.items.sort((s,l)=>{var c,a;return((c=s.order)!=null?c:0)-((a=l.order)!=null?a:0)})});const r=[];return o.forEach((i,s)=>{const l=T.t(`blockMenu.section.${i.group||"common"}`),c=l===i.group?i.group:l;r.push({id:`section-${s}`,name:c,type:"section",group:i.group,itemType:"insert-block"}),r.push(...i.items.map(a=>({...a})))}),r}function vT(n,t,e){const o=n.getFocusedBlock();if(!o)return;const r=n.getParentContainer(o),i=U(r);let l=n.getBlockIndex(o);if(Tt(n,o)||(l+=1),t.commandProvider){t.commandProvider.executeCommand(n,t,{from:"quick-menu",...e});return}!t.blockOptions||!t.blockOptions.handleInsertEmptyBlock||t.blockOptions.handleInsertEmptyBlock(n,{containerId:i,blockIndex:l,item:t})}const I4=B("quick-menu"),yT={id:"quick-menu",trigger:["/"]};class Zc{constructor(t,e=yT){h(this,"suggest");h(this,"items");h(this,"maxHeading");h(this,"queryItems",async(t,e)=>{if(this.items.length===0?this.initMenuItems():this.refreshMenuItems(),e){const o=new Set,r=e.toLocaleLowerCase().replace(/^\s+|\s+$/g,"");return this.items.filter(i=>{var s;return i.type==="section"?!0:i.name.toLocaleLowerCase().indexOf(r)!==-1||zB(i).toLocaleLowerCase().indexOf(r)!==-1||i.group&&((s=i.group)==null?void 0:s.toLocaleLowerCase().indexOf(r))!==-1?(o.add(i.group),!0):!1}).filter(i=>i.type==="section"?o.has(i.group):!0)}return this.items});h(this,"onShow",(t,e,o,r)=>{const i=this.editor.getBlockByIndex(e,o);if(!po(i)){const s=F(H(i));if(s&&ot(s)==="code")return!1}return!0});h(this,"onClickItem",(t,e)=>{const o=e;o.itemType==="insert-block"&&(d(I4,o.blockOptions||o.commandProvider,"invalid quick item, no block options or command provider"),d(I4,this.suggest.anchor,"invalid suggest, no anchor"),vT(this.editor,o,this.suggest.anchor))});this.editor=t,this.options=e,this.items=[],this.maxHeading=Pc(),this.suggest=new Ch(t,{id:e.id||"quick-menu",trigger:e.trigger,needSpaceBeforeTrigger:!0,autoDeleteTrigger:!0,highlight:!0,onShow:this.onShow,onClickItem:this.onClickItem,queryItems:this.queryItems})}get menu(){return this.suggest.menu.menu}destroy(){this.suggest.destroy()}initMenuItems(){const t=c1(this.editor);this.items=t}refreshMenuItems(){let t=null,e=0;const o=Pc();if(o!==this.maxHeading){const r=new k4,s=r.getCommands().map(l=>({...l,itemType:"insert-block",commandProvider:r}));for(let l=0;l<this.items.length;l++)this.items[l].group==="basics"&&(t||(t=l),t&&e++);t&&e&&this.items.splice(t,e,...s),this.maxHeading=o}}}class a1{constructor(t){h(this,"instance");h(this,"mousedown",!1);h(this,"currentInstance",null);h(this,"attributeName","");h(this,"attributeDesc","");h(this,"observer",null);h(this,"observerCallback",null);h(this,"createContent",t=>{var i;const e=(i=t.getAttribute(this.attributeName))!=null?i:"",o=t.getAttribute(this.attributeDesc);if(!o)return e;const r=b("div",[],null);return b("span",[],r,e),o&&b("span",["editor-tooltip-desc"],r,o),r});h(this,"handleDocumentMouseDown",()=>{this.mousedown=!0,this.editor.domEvents.addEventListener(document,"mouseup",this.handleDocumentMouseUp)});h(this,"handleDocumentMouseUp",()=>{this.mousedown=!1,this.editor.domEvents.removeEventListener(document,"mouseup",this.handleDocumentMouseUp)});h(this,"handleShown",t=>{this.currentInstance&&this.hide(),this.currentInstance=t,this.createObserver()});h(this,"handleHidden",()=>{this.destroyObserver(),this.currentInstance=null});h(this,"handleShow",t=>{var r;const e=t.reference;if(!e||!It(document.body,e)||window.isDragging||this.mousedown)return!1;const o=Number.parseInt((r=e.getAttribute("data-tooltip-hide-at"))!=null?r:"",10);return!(o&&Date.now()-o<1e3)});this.editor=t;const e=t.clientId;this.attributeName=`data-editor-tooltip-${e}`,this.attributeDesc=`data-editor-tooltip-desc-${e}`,this.instance=Qa.delegate(document.body,{delay:200,target:`[${this.attributeName}]`,content:this.createContent,onShow:this.handleShow,onShown:this.handleShown,onHide:this.handleHidden}),t.domEvents.addEventListener(document,"mousedown",this.handleDocumentMouseDown)}visible(){var t;return(t=this.currentInstance)==null?void 0:t.state.isVisible}hide(){var t;(t=this.currentInstance)!=null&&t.state.isVisible&&this.currentInstance.hide()}destroy(){this.destroyObserver(),this.instance.destroy(),this.editor.domEvents.removeEventListener(document,"mousedown",this.handleDocumentMouseDown),this.editor.domEvents.removeEventListener(document,"mouseup",this.handleDocumentMouseUp)}createObserver(){this.destroyObserver();const t=this.currentInstance;if(!t||!t.reference)return;this.observerCallback=Xt.default(()=>{t.reference.closest("body")||(t.hide(),this.destroyObserver())},200),this.observer=new MutationObserver(this.observerCallback);const e=document.body,o={childList:!0,attributes:!1,subtree:!0};this.observer.observe(e,o)}destroyObserver(){this.observer&&(this.observer.disconnect(),this.observer=null),this.observerCallback&&(this.observerCallback.cancel(),this.observerCallback=null)}}const wT={"text/style-bold":"bold","text/style-italic":"italic","text/style-underline":"underline","text/style-strikethrough":"line-through","text/style-code":"code","text/style-subscript":"subscript","text/style-superscript":"superscript"};function BT(n,t){const e=new Set(Object.keys(wT)),o=t.filter(i=>e.has(i.id));return _c(o)}function Yc(n,t){if(!n.isWritable())return!1;const e=n.selection.range,o=n.editorCommandProviders.getCommands(e),i=BT(n,o).find(s=>s.id===`text/${t}`);return i?(n.editorCommandProviders.executeCommand(e,i,{}),ti.get(n).update("selectionChange"),!0):!1}const d1={"CtrlOrCmd+B":n=>Yc(n,"style-bold"),"CtrlOrCmd+I":n=>Yc(n,"style-italic"),"CtrlOrCmd+U":n=>Yc(n,"style-underline"),"CtrlOrCmd+D":n=>Yc(n,"style-strikethrough")},ET={quickMenu:{basic:{heading:{title:"\u6807\u9898 {heading}",space:"{markdown}\u7A7A\u683C"},unordered:"\u65E0\u5E8F\u5217\u8868",ordered:"\u6709\u5E8F\u5217\u8868",checkbox:"\u5F85\u529E\u4E8B\u9879",quote:"\u5F15\u7528"},inlineBox:{math:"\u516C\u5F0F",link:"\u94FE\u63A5"}},link:{textLabel:"\u6587\u672C",urlLabel:"\u94FE\u63A5\u5730\u5740",textPlaceholder:"\u8BF7\u8F93\u5165\u6587\u672C",urlPlaceholder:"\u8BF7\u8F93\u5165\u94FE\u63A5\u5730\u5740",submitText:"\u786E\u5B9A",cancelText:"\u53D6\u6D88"},commands:{unordered:"\u65E0\u5E8F\u5217\u8868",ordered:"\u6709\u5E8F\u5217\u8868",check:"\u5F85\u529E\u5217\u8868",link:"\u94FE\u63A5",quote:"\u5F15\u7528",alignLeft:"\u5DE6\u5BF9\u9F50",alignRight:"\u53F3\u5BF9\u9F50",alignCenter:"\u5C45\u4E2D\u5BF9\u9F50",alignGroup:"\u5BF9\u9F50\u65B9\u5F0F",heading:"\u6807\u9898 {name}",headingGroup:"\u6807\u9898\u6837\u5F0F",text:"\u6B63\u6587"},commandDesc:{mac:{unordered:"\u2318+\u21E7+L",ordered:"\u2318+\u21E7+U",link:"\u2318+K"},window:{unordered:"Ctrl+Shift+L",ordered:"Ctrl+Shift+U",link:"Ctrl+K"}}},IT={quickMenu:{basic:{heading:{title:"Heading {heading}",space:"{markdown}space"},unordered:"Bulleted list",ordered:"Numbered list",checkbox:"Todo list",quote:"Quote"},inlineBox:{math:"Math",link:"Link"},link:{textLabel:"Text",urlLabel:"Link Address",textPlaceholder:"Please enter text",urlPlaceholder:"Please enter the link address",submitText:"Ok",cancelText:"Cancel"}},commands:{unordered:"Bulleted list",ordered:"Numberer list",check:"Todo list",link:"Link",quote:"Quote",alignLeft:"Align left",alignRight:"Align right",alignCenter:"Align center",alignGroup:"Alignment",heading:"Heading {name}",headingGroup:"Text style",text:"Text"},commandDesc:{mac:{unordered:"\u2318+\u21E7+L",ordered:"\u2318+\u21E7+U",link:"\u2318+K"},window:{unordered:"Ctrl+Shift+L",ordered:"Ctrl+Shift+U",link:"Ctrl+K"}}};T.mergeLang({"zh-CN":ET,"en-US":IT});const Tz="";function cr(n,...t){const e=vo(...t);return e.classList.remove("editor-button"),e.classList.add("editor-text-button"),n.append(e),e}function x4(n){Nc(n).hide();const e=n.getCustom("table-border-bar");e==null||e.closeToolbar()}function xT(n){return b("div",["insert-column-button","drop-marker"],n)}const T4=B("row-height");function S4(n){const t=et.fromTable(n),e=n.rows;d(T4,e.length===t.rowCount,"row count mismatch");const o=Array(t.rowCount).fill(0);for(let r=0;r<e.length;){let i=1,l=e[r].getBoundingClientRect().height,c=r+1;for(;c<e.length;){const a=e[c];if(a.cells.length!==0)break;i++,c++,l+=a.getBoundingClientRect().height}for(let a=0;a<i;a++)o[r+a]=l/i;r=c}return T4.debug("heights",o.join(", ")),o}const Io=B("table-border-bar-dom");function As(n,t){d(Io,Ht(t),"invalid table block");const e=jt(t),o=Tn(n,t),r=(a,u,f)=>{const m=b("div",["button-root",u],a),C=b("div",["button-container",u],m);m.setAttribute(`data-${u}-index`,`${f}`),C.setAttribute(`data-editor-tooltip-${n.clientId}`,u==="left"?T.t("table.insertRow"):T.t("table.insertCol")),b("span",["insert-indicator"],C),xT(C)},{selectedRows:i,selectedColumns:s}=kh(n,t),l=()=>{const a=o.querySelector(".table-border-bar-container.top");d(Io,a,"no top border bar container");const u=b("div",["table-border-bar-container","top"],null),f=b("div",["table-border-bar","top"],u),m=HE(e);b("span",["table-border-bar-cell","corner"],f);const k=et.fromTable(e).colCount;n.selection.range.isSimple()&&r(f,"top",0);for(let w=0;w<k;w++){const y=w===k-1?m[w]+2:m[w],S=b("span",["table-border-bar-cell","top"],f);s.has(w)&&S.classList.add("selected"),S.setAttribute("data-top-index",`${w}`),S.style.width=`${y}px`,n.selection.range.isSimple()&&r(f,"top",w+1)}Oi(a,u)},c=()=>{const a=o.querySelector(".table-border-bar-container.left");d(Io,a,"no left border bar container");const u=b("div",["table-border-bar-container","left"],null),f=b("div",["table-border-bar","left"],u),m=S4(e);n.selection.range.isSimple()&&r(f,"left",0),Array.from(e.rows).forEach((C,k,w)=>{const y=b("span",["table-border-bar-cell","left"],f);i.has(k)&&y.classList.add("selected"),y.setAttribute("data-left-index",`${k}`);const S=k===w.length-1?m[k]+2:m[k];y.style.height=`${S}px`,n.selection.range.isSimple()&&r(f,"left",k+1)}),Oi(a,u)};l(),c()}function D4(n,t){const e=t.target;if(!(e instanceof Element))return;const o=F(e);d(Io,o&&Ht(o),"invalid table block"),As(n,o),n.selection.caret.update()}function u1(n,t){const e=t.target;if(!(e instanceof Element))return;const o=F(e);d(Io,o&&Ht(o),"invalid table block");const r=e.closest(".button-root");if(r){if(r.classList.contains("top")){const i=parseInt(r.getAttribute("data-top-index")||"0",10);q5(n,o,i),As(n,o)}else if(r.classList.contains("left")){const i=parseInt(r.getAttribute("data-left-index")||"0",10);W5(n,o,i),As(n,o)}}}function h1(n,t){var s;x4(n),t.preventDefault(),t.stopPropagation();let e=null,o,r;const i=l=>{var c;if(l.target instanceof HTMLElement&&o&&e&&r!==void 0){const a=F(l.target),u=l.target.closest(".table-border-bar");if(a===e&&u){const f=parseInt((c=l.target.getAttribute(`data-${o}-index`))!=null?c:"0",10),m=Math.min(r,f),C=Math.abs(r-f)+1;nt(l.target,"top")&&o==="top"?XE(n,a,m,C,{reverse:!0}):nt(l.target,"left")&&o==="left"&&tI(n,a,m,C,{reverse:!0})}}l.type==="mouseup"&&(e=null,r=void 0,o=void 0,document.body.removeEventListener("mousemove",i),document.body.removeEventListener("mouseup",i))};t.target instanceof HTMLElement&&nt(t.target,"table-border-bar-cell")&&(e=F(t.target),nt(t.target,"top")?o="top":nt(t.target,"left")&&(o="left"),o&&e&&(r=parseInt((s=t.target.getAttribute(`data-${o}-index`))!=null?s:"0",10),document.body.addEventListener("mousemove",i),document.body.addEventListener("mouseup",i)))}function TT(n,t){d(Io,Ht(t),"invalid table block");const e=Tn(n,t),o=b("div",["table-border-bar-container","top"],e),r=b("div",["table-border-bar-container","left"],e);As(n,t),n.domEvents.addEventListener(it(t),"scroll",D4),n.domEvents.addEventListener(o,"click",u1),n.domEvents.addEventListener(r,"click",u1),n.domEvents.addEventListener(o,"mousedown",h1),n.domEvents.addEventListener(r,"mousedown",h1)}function L4(n,t){if(!n.isWritable())return;if(Tn(n,t).querySelector(".table-border-bar-container")){As(n,t);return}TT(n,t)}function M4(n,t){d(Io,Ht(t),"invalid table block"),Tn(n,t).querySelectorAll(".table-border-bar-container").forEach(r=>{n.domEvents.removeEventListener(r,"click",u1),n.domEvents.removeEventListener(r,"mousedown",h1),r.remove()}),n.domEvents.removeEventListener(it(t),"scroll",D4)}function ST(n,t){d(Io,Ht(t),"invalid table block");const o=Tn(n,t).querySelector(".table-border-bar-container.top");return o?o.getBoundingClientRect().height:0}class DT{constructor(t,e){h(this,"toolbar");h(this,"handleSelectionChange",(t,e)=>{e==="delete-columns"?(qr(this.editor,this.tableBlock,!0,!0),Wr(this.editor,this.tableBlock,!0,!0)):e==="delete-rows"?(qr(this.editor,this.tableBlock,!0,!1),Wr(this.editor,this.tableBlock,!0,!1)):(qr(this.editor,this.tableBlock,!1),Wr(this.editor,this.tableBlock,!1))});h(this,"handleClick",(t,e,o)=>{e.id==="delete-columns"?vh(this.editor.selection.range):e.id==="delete-rows"&&yh(this.editor.selection.range)});this.editor=t,this.tableBlock=e;const o=t.options.componentsOptions.popover;this.toolbar=new ks([],void 0,{overflowBoundary:o==null?void 0:o.overflowBoundary,refuseOverflow:!0,tooltipId:this.editor.clientId}),this.toolbar.addListener("selectionChange",this.handleSelectionChange),this.toolbar.addListener("click",this.handleClick)}close(){this.toolbar.close()}update(){const{selectedColumns:t,selectedRows:e}=kh(this.editor,this.tableBlock);if(!this.editor.isWritable())return;if(t.size>0&&e.size>0){this.toolbar.close();return}if(t.size===0&&e.size===0){this.toolbar.close();return}const o=io(this.editor,this.tableBlock,this.editor.selection.range)[0];if(!o){this.toolbar.close();return}if(t.size>0){const r={id:"delete-columns",name:T.t("table.deleteCol"),icon:Fw};this.toolbar.updateItems([r]);const i=co(this.editor,this.tableBlock,"editor-quick-menu",o);this.toolbar.manualShow(i,{placement:"top"})}else{const r={id:"delete-rows",name:T.t("table.deleteRow"),icon:Hw};this.toolbar.updateItems([r]);const i=new DOMRect(o.left-15,o.top,o.width,o.height),s=co(this.editor,this.tableBlock,"editor-quick-menu",i);this.toolbar.manualShow(s,{placement:"left"})}}destroy(){this.toolbar.destroy(),this.toolbar.removeAllListeners()}}const Qc=B("table-border-bar");class LT{constructor(t,e){h(this,"toolbar");h(this,"resizeObserver");h(this,"handleReadonlyChanged",t=>{t.isWritable()?this.update():M4(this.editor,this.tableBlock)});h(this,"handleBlockUpdated",()=>{this.resizeObserver.disconnect(),setTimeout(()=>{const t=this.editor.getBlockById(q(this.tableBlock));this.resizeObserver.observe(jt(t))})});h(this,"handleTableResize",()=>{!this.editor.isWritable()||(console.log("resize"),this.update())});this.editor=t,this.tableBlock=e,d(Qc,this.tableBlock,"no table block"),Qc.debug("create table border bar"),L4(this.editor,this.tableBlock),this.resizeObserver=new ResizeObserver(this.handleTableResize),this.resizeObserver.observe(jt(this.tableBlock)),this.toolbar=new DT(this.editor,this.tableBlock),this.editor.addListener("readonlyChanged",this.handleReadonlyChanged)}close(){this.toolbar.close()}destroy(){Qc.debug("destroy table border bar"),this.resizeObserver.disconnect(),M4(this.editor,this.tableBlock),this.toolbar.destroy(),this.editor.removeListener("readonlyChanged",this.handleReadonlyChanged)}update(){Qc.debug("update table border bar"),L4(this.editor,this.tableBlock),this.toolbar.update()}}const MT=B("table-border-bar");class RT{constructor(t){h(this,"activeTableBar",null);h(this,"handleBlockDeleted",(t,e)=>{!this.activeTableBar||(e===this.activeTableBar.tableBlock||It(e,this.activeTableBar.tableBlock))&&(this.activeTableBar.destroy(),this.activeTableBar=null)});h(this,"handleSelectionChanged",t=>{var r;const e=t.selection.range;let o=null;if(e.isCollapsed()&&e.isSimple()){const i=t.getBlockById(e.start.blockId);if(Ht(i)){const s=H(i),l=F(s);l&&(o=Me(l))}else o=Me(i)}else{const i=t.getBlockById(e.start.blockId),s=Me(i),l=t.getBlockById(e.end.blockId),c=Me(l);s===c&&(o=s)}((r=this.activeTableBar)==null?void 0:r.tableBlock)!==o&&this.activeTableBar&&this.hide(),o&&this.show(o)});this.editor=t,this.editor.addListener("blockDeleted",this.handleBlockDeleted),this.editor.addListener("selectionChanged",this.handleSelectionChanged)}destroy(){this.editor.removeListener("blockDeleted",this.handleBlockDeleted),this.editor.removeListener("selectionChanged",this.handleSelectionChanged)}show(t){this.activeTableBar?(this.activeTableBar.tableBlock!==t&&this.hide(),this.activeTableBar.update()):this.activeTableBar=new LT(this.editor,t)}update(){var t;(t=this.activeTableBar)==null||t.handleBlockUpdated()}closeToolbar(){var t;(t=this.activeTableBar)==null||t.close()}hide(){!this.activeTableBar||(d(MT,this.activeTableBar,"no active table bar"),this.activeTableBar.destroy(),this.activeTableBar=null)}}function R4(n,t){const e=n.addCustom("table-border-bar",o=>new RT(o));t==="update"&&e.update()}const Be=B("table-cell-menu"),AT="style-bg-color-";class OT{constructor(t){h(this,"activeTableBlock",null);h(this,"targetButton",null);h(this,"manualMenu",null);h(this,"colorPaletteItem",null);h(this,"handlePrevent",(t,e)=>{e.stopPropagation()});h(this,"handleReadonlyChanged",t=>{t.isWritable()||this.hide()});h(this,"handleSelectionChanged",t=>{const e=t.selection.range;let o=null;if(e.isCollapsed()&&e.isSimple()){const r=t.getBlockById(e.start.blockId);if(Ht(r)){const i=H(r),s=F(i);s&&(o=Me(s))}else o=Me(r)}else{const r=t.getBlockById(e.start.blockId),i=Me(r),s=t.getBlockById(e.end.blockId),l=Me(s);i===l&&(o=i)}if(this.hide(),this.activeTableBlock!==o&&(this.activeTableBlock=o),this.activeTableBlock){const r=et.fromBlock(this.activeTableBlock),i=e.isReverse()?e.start:e.end;let s=null;e.isCollapsed()?s=this.getCellByChildBlockId(r,i.blockId):i instanceof Je&&(t.getBlockById(i.blockId)===this.activeTableBlock?s=r.getCellByContainerId(i.childContainerId):s=this.getCellByChildBlockId(r,i.blockId)),s&&this.editor.isWritable()&&this.showCellMenuButton(s)}});h(this,"handleBeforePopupPalette",()=>{var e;const t=this.getSelectedBkgColorIndex();(e=this.colorPaletteItem)==null||e.palette.setColor("backgroundColor",t)});h(this,"createBkgColorItem",()=>{const t=b("div",["cell-background-color-item"],null);b("span",[],t,T.t("table.cellBackground"));const e=this.getSelectedBkgColorIndex();b("button",["item-button"],t).setAttribute("data-color-index",`${e}`);const r=b("span",["item-sub-indicator"],t);return r.innerHTML=o5,t});h(this,"handleCommand",t=>{var r;d(Be,this.activeTableBlock,"no target table block");const e=((r=t.states)==null?void 0:r.includes("checked"))||!1,o=t.value;switch(t.id){case"delete-select-row":yh(x5(this.editor,this.activeTableBlock,!1));break;case"delete-select-col":vh(x5(this.editor,this.activeTableBlock,!0));break;case"merge-cell":B5(this.editor.selection.range);break;case"split-cell":this.handleSplitCell();break;case"row-title":this.handleRowTitle(e);break;case"col-title":this.handleColTitle(e);break;case"stripe-style":this.handleStripeStyle(e);break;case"hide-border":cE(this.editor,this.activeTableBlock,o==="show-border");break;case"show-chart":fE(this.editor,this.activeTableBlock,o==="show-chart"),Rh(this.editor,this.activeTableBlock,{updateNow:!0});break}});h(this,"handleSelectionChange",(t,e)=>{d(Be,this.activeTableBlock,"no target table block"),e==="cell-background-color"&&this.handleBeforePopupPalette(),e==="delete-select-row"?(qr(this.editor,this.activeTableBlock,!0,!1),Wr(this.editor,this.activeTableBlock,!0,!1)):e==="delete-select-col"?(qr(this.editor,this.activeTableBlock,!0,!0),Wr(this.editor,this.activeTableBlock,!0,!0)):(qr(this.editor,this.activeTableBlock,!1),Wr(this.editor,this.activeTableBlock,!1))});h(this,"handleClick",()=>{var t;d(Be,this.activeTableBlock,"no target table block"),d(Be,this.targetButton,"no target button"),x4(this.editor),nt(this.targetButton,"active")?(z(this.targetButton,"active"),(t=this.manualMenu)==null||t.close()):(A(this.targetButton,"active"),this.manualMenu?this.manualMenu.updateItems(this.createCommandMenu()):(this.manualMenu=new nr(this.createCommandMenu()),this.manualMenu.on("click",(e,o)=>{var r;this.handleCommand(o),(r=this.manualMenu)==null||r.close()}),this.manualMenu.on("selectionChange",this.handleSelectionChange),this.manualMenu.on("close",()=>{this.targetButton&&z(this.targetButton,"active"),this.editor.focus()})),this.manualMenu.manualShow(this.targetButton,{placement:"right-start"}))});this.editor=t,this.editor.addListener("selectionChanged",this.handleSelectionChanged),this.editor.addListener("readonlyChanged",this.handleReadonlyChanged)}destroy(){var t,e;this.activeTableBlock=null,this.targetButton=null,this.editor.removeListener("selectionChanged",this.handleSelectionChanged),this.editor.removeListener("readonlyChanged",this.handleReadonlyChanged),(t=this.manualMenu)==null||t.destroy(),(e=this.colorPaletteItem)==null||e.destroy()}hide(){var t;(t=this.manualMenu)==null||t.close(),this.targetButton&&(z(this.targetButton,"active"),this.targetButton.style.display="none")}getCellByChildBlockId(t,e){let o=this.editor.getBlockById(e);for(;o;){const r=o.closest("td");d(Be,r,"no parent cell");const i=F(r);if(d(Be,i,"no parent block"),jt(i)===t.table)return t.getCellByCellElement(r);o=i}return d(Be,!1,"filed to get cell by child block id"),null}createTargetButton(t){this.targetButton?t.querySelector(`:scope > .${Sh}`)||t.appendChild(this.targetButton):(this.targetButton=b("button",[Sh],t),this.targetButton.innerHTML=eh,this.editor.domEvents.addEventListener(this.targetButton,"click",this.handleClick),this.editor.domEvents.addEventListener(this.targetButton,"mousedown",this.handlePrevent))}showCellMenuButton(t){this.createTargetButton(t.cell),d(Be,this.targetButton,"no target button"),this.targetButton.style.display="inline-block"}handleSplitCell(){if(this.activeTableBlock){const t=et.fromBlock(this.activeTableBlock),e=this.editor.selection.range;if(e.isSimple()){const{col:o,row:r}=this.getCellByChildBlockId(t,e.start.blockId);Bh(this.editor,this.activeTableBlock,{col:o,row:r})}else Eh(this.editor.selection.range)}}getSelectedBkgColorIndex(){var r;d(Be,this.activeTableBlock,"no target table block");const t=uE(this.editor,this.activeTableBlock),e=this.editor.getBlockData(this.activeTableBlock),o=new Set;for(const i of t){if(o.size>1)break;const s=U(i),l=e[`${s}_background`];if(l)o.add(Number.parseInt((r=l.substring(AT.length))!=null?r:"0",10));else{o.add(-1);break}}return o.size===1&&[...o][0]!==-1?[...o][0]:-1}createCommandMenu(){d(Be,this.activeTableBlock,"no target table block");const t=this.editor.getBlockData(this.activeTableBlock),e=w5(this.editor,this.activeTableBlock,this.editor.selection.range);let o=this.editor.selection.range;if(o.isSimple()){const u=Gn(this.editor,this.activeTableBlock,o.start);o=qt(this.editor,{anchor:u,focus:u})}const r=y5(this.editor,this.activeTableBlock,o),i=t.hasRowTitle,s=t.hasColTitle,l=t.isStripeStyle,c=t.noBorder,a=t.chart;return this.colorPaletteItem=new g5("cell-background-color",{color:!1}),this.colorPaletteItem.palette.on("onClick",(u,f)=>{var m;switch(d(Be,this.activeTableBlock,"no target table block"),u){case"clearColor":D5(this.editor,this.activeTableBlock,-1);break;case"backgroundColor":D5(this.editor,this.activeTableBlock,f);break}(m=this.manualMenu)==null||m.close()}),[{id:"cell-background-color",name:T.t("table.cellBackground"),element:this.createBkgColorItem(),children:[this.colorPaletteItem]},{id:"separator",name:"",type:"separator"},{id:"merge-cell",name:T.t("table.mergeCell"),states:e?[]:["disabled"]},{id:"split-cell",name:T.t("table.splitCell"),states:r?[]:["disabled"]},{id:"separator",name:"",type:"separator"},{id:"delete-select-row",name:T.t("table.deleteSelectRow")},{id:"delete-select-col",name:T.t("table.deleteSelectCol")},{id:"separator",name:"",type:"separator"},{id:"table-config",name:T.t("table.tableConfigKey"),children:[{id:"row-title",name:T.t("table.tableConfig.rowTitle"),states:i?["checked"]:[]},{id:"col-title",name:T.t("table.tableConfig.colTitle"),states:s?["checked"]:[]},{id:"stripe-style",name:T.t("table.tableConfig.stripeStyle"),states:l?["checked"]:[]},{id:"hide-border",name:c?T.t("table.tableConfig.showBorder"):T.t("table.tableConfig.hideBorder"),value:c?"show-border":"hide-border"},{id:"show-chart",name:a?T.t("table.tableConfig.hideChart"):T.t("table.tableConfig.showChart"),value:a?"hide-chart":"show-chart"}]}]}handleRowTitle(t){d(Be,this.activeTableBlock,"no target table block"),t?iE(this.editor,this.activeTableBlock):rE(this.editor,this.activeTableBlock)}handleColTitle(t){d(Be,this.activeTableBlock,"no target table block"),t?oE(this.editor,this.activeTableBlock):nE(this.editor,this.activeTableBlock)}handleStripeStyle(t){d(Be,this.activeTableBlock,"no target table block"),t?lE(this.editor,this.activeTableBlock):sE(this.editor,this.activeTableBlock)}}function A4(n){n.addCustom("table-cell-menu",t=>new OT(t))}const Kc=B("table-container");function f1(n){const t=n.closest("td");return d(Kc,t,"no parent cell for a table cell container"),t}function O4(n){const t=jt(n);return Array.from(t.querySelectorAll(':scope > tbody > tr > td > [data-type="editor-container"].child'))}function m1(n,t,e,o){const r=et.fromBlock(n),i=r.getCellByContainerId(U(t));if(e==="ArrowDown"){const s=r.getBottomCell(i);return s?s.container:null}if(e==="ArrowUp"){const s=r.getTopCell(i);return s?s.container:null}if(e==="ArrowLeft"){const s=r.getAllContainers(),l=s.indexOf(t);if(d(Kc,l>=0,"not a valid child container"),l===0)return null;const c=s[l-1];return o!=null&&o.noWrap&&r.getCellByContainerId(U(c)).row!==i.row?null:c}if(e==="ArrowRight"){const s=r.getAllContainers(),l=s.indexOf(t);if(d(Kc,l>=0,"not a valid child container"),l===s.length-1)return null;const c=s[l+1];return o!=null&&o.noWrap&&r.getCellByContainerId(U(c)).row!==i.row?null:c}d(Kc,!1,`invalid navigation type: ${e}`)}const _T=12,NT=90,Jc=23,_4=2;class $T{constructor(t){h(this,"scrollTableBlock",null);h(this,"autoScrollDir",null);h(this,"autoScrollTimer",null);h(this,"handleMouseDown",t=>{const e=document.elementFromPoint(t.clientX,t.clientY);if(e&&e instanceof HTMLElement){const o=F(e);if(o&&It(this.editor.rootContainer,o)){const r=Me(o);r&&(this.scrollTableBlock=r,document.addEventListener("mousemove",this.handleAutoScroll))}}});h(this,"handleAutoScroll",x7.default(t=>{if(this.scrollTableBlock){const e=this.editor.getCustom(wo(this.scrollTableBlock)),o=e.rootElement,r=e.scrollOptions.parentContainer,i=o.getBoundingClientRect(),s=window.innerHeight-(e.scrollOptions.barFloatWindowBottom||0),l=r.getBoundingClientRect(),c=Math.min(l.bottom,s),a=Math.max(l.top,0);i.bottom>c&&t.clientY>=c?this.setAutoScroll("bottom"):i.top<a&&t.clientY<=a?this.setAutoScroll("top"):o.scrollLeft>0&&t.clientX<i.left?this.setAutoScroll("left"):o.scrollLeft<o.scrollWidth-o.offsetWidth&&t.clientX>i.right?this.setAutoScroll("right"):this.clearAutoScroll()}},15));h(this,"handleMouseUp",()=>{document.removeEventListener("mousemove",this.handleAutoScroll),setTimeout(()=>{this.scrollTableBlock=null})});h(this,"handleSelectionChanged",t=>{const e=t.selection.range;if(e.isCollapsed()&&e.isSimple()){const o=t.getBlockById(e.start.blockId),r=Me(o);if(r){const i=t.getCustom(wo(r)),s=i.rootElement.getBoundingClientRect(),l=Ke(t,o,e.start);if(s.left>l.left){const c=e.start.offset===0?_T:_4;i.rootElement.scrollLeft-=s.left-l.left+c}else if(l.right>s.right){const c=e.start.offset===0?NT:_4;i.rootElement.scrollLeft+=l.right-s.right+c}}}else{const o=t.getBlockById(e.start.blockId),r=Me(o),i=t.getBlockById(e.end.blockId),s=Me(i);if(r&&r===s){const l=t.getCustom(wo(r)),c=l.rootElement.getBoundingClientRect();let a=null;if(e.isSimple())a=e.isReverse()?Ke(t,o,e.start):Ke(t,i,e.end);else{const u=f1(Er(t,e.start.childContainerId)),f=f1(Er(t,e.end.childContainerId));a=e.isReverse()?u.getBoundingClientRect():f.getBoundingClientRect()}c.left>a.left&&e.isReverse()?l.rootElement.scrollLeft-=c.left-a.left:c.right<a.right&&!e.isReverse()&&(l.rootElement.scrollLeft+=a.right-c.right)}}});h(this,"handleScroll",t=>{b5(t),this.editor.selection.caret.update()});h(this,"handleReset",t=>{b5(t),this.editor.selection.caret.update()});this.editor=t,this.editor.addListener("selectionChanged",this.handleSelectionChanged),document.addEventListener("mousedown",this.handleMouseDown),document.addEventListener("mouseup",this.handleMouseUp)}clearAutoScroll(){this.autoScrollTimer&&(clearInterval(this.autoScrollTimer),this.autoScrollTimer=null,this.autoScrollDir=null)}setAutoScroll(t){this.autoScrollDir&&this.autoScrollDir!==t&&this.clearAutoScroll(),this.autoScrollTimer||(this.autoScrollDir=t,this.autoScrollTimer=window.setInterval(()=>{if(this.scrollTableBlock){const e=this.editor.getCustom(wo(this.scrollTableBlock)),o=e.rootElement,r=e.scrollOptions.parentContainer,i=o.getBoundingClientRect(),s=r===document.documentElement?window.innerHeight:r.offsetHeight,l=window.innerHeight-(e.scrollOptions.barFloatWindowBottom||0),c=r.getBoundingClientRect(),a=Math.min(c.bottom,l),u=Math.max(c.top,0);this.autoScrollDir==="left"&&(o.scrollLeft-=Jc,o.scrollLeft<=0&&this.clearAutoScroll()),this.autoScrollDir==="right"&&(o.scrollLeft+=Jc,o.scrollLeft>=o.scrollWidth-o.offsetWidth&&this.clearAutoScroll()),this.autoScrollDir==="bottom"&&(r.scrollTop+=Jc,(r.scrollTop>=r.scrollHeight-s||i.bottom<=a)&&this.clearAutoScroll()),this.autoScrollDir==="top"&&(r.scrollTop-=Jc,(r.scrollTop<=0||i.top>=u)&&this.clearAutoScroll())}},100))}destroy(){document.removeEventListener("mousedown",this.handleMouseDown),document.removeEventListener("mouseup",this.handleMouseUp),this.editor.removeListener("selectionChanged",this.handleSelectionChanged)}}function N4(n){return n.addCustom("table-scroll-events",t=>new $T(t))}const Sn=B("create-content");function $4(n,t,e){const o=new Ec(e),r=e.rows,i=e.cols;d(Sn,r>=1,`invalid rows: ${r}`),d(Sn,i>=1,`invalid cols: ${i}`),d(Sn,e.children,"no table children");const s=b("table",[],null),l=e.colsWidth,c=b("colgroup",[],s);for(let f=0;f<o.colCount;f++){const m=b("col",[],c);m.style.width=`${l[f]||Ac}px`}const a=b("tbody",[],s);let u=0;for(let f=0;f<r;f++){const m=b("tr",[],a);for(let C=0;C<i;C++){const k=o.getCell({col:C,row:f});if(k.virtual)d(Sn,k.colSpan>1||k.rowSpan>1,"virtual cell should have colSpan or rowSpan");else{const w=e.children[u],y=b("td",[],m);k.colSpan>1&&(y.colSpan=k.colSpan),k.rowSpan>1&&(y.rowSpan=k.rowSpan);const S=e[Es(w)];S&&A(y,S),C===0&&e.hasColTitle&&A(y,E5.COL_TITLE_ITEM),n.createChildContainer(t,y,w),u+=1}}}return d(Sn,u===e.children.length,"container count mismatch"),e.noBorder&&A(s,"no-border"),e.chart&&A(s,"editor-table-chart"),e.isStripeStyle&&A(s,"stripe"),e.hasRowTitle&&A(s,"row-title"),e.hasColTitle&&A(s,"col-title"),s}function PT(n,t,e,o,r){d(Sn,r.type==="table","not table data"),d(Sn,U(e)===t[t.length-1].containerId,"invalid path");const i=r,s=ro(o,"div");try{const l=b("div",[],null);l.setAttribute("data-type","table-content");const c=$4(n,t,i);c.classList.add("drag-preview-element"),l.appendChild(c),U5(n),Z5(n),R4(n,"create"),A4(n),Sw(n,Ah);const a=n.getComponentOptions("table"),u=n.addCustom(wo(o),()=>$E());u.init({parentElement:s,childElement:l,safeRightSpace:50,safeLeftSpace:40,parentContainer:pt(e)?n.scrollContainer:e,locatingContainer:pt(e)?(a==null?void 0:a.locatingContainer)||n.parent:e,paddingLeft:Th+Bs,paddingTop:Th+Bs,paddingBottom:Bs/2,paddingRight:Bs/2,barFloatWindowBottom:a==null?void 0:a.barFloatWindowBottom,isSetScale:a==null?void 0:a.isSetScale});const f=N4(n);u.on("scroll",f.handleReset),u.on("resize",f.handleReset),setTimeout(()=>{pE(n,o)})}catch{const c=`invalid table data: ${JSON.stringify(i)}`;Sn.error(c);const a=b("div",["error"],s);a.innerText=c}return s}function jT(n,t,e){d(Sn,e.type==="table","not table data");const o=e,r=it(t);try{const i=jt(t),s=Vo(t),l=$4(n,s,o);l.classList.add("drag-preview-element"),i.insertAdjacentElement("afterend",l),i.remove(),U5(n),Z5(n),R4(n,"update"),A4(n),Ah(n,t)}catch{const s=`invalid table data: ${JSON.stringify(o)}`;Sn.error(s);const l=b("div",["error"],r);l.innerText=s}}function HT(n,t){let e,o,r=!1;if([...t].every(m=>m==="|")?(o=t.length,e=Array(o).fill(""),r=!0):(e=ld(t,"|").split("|"),o=e.length),o<2)return null;const i=3,s=o,l=[];for(let m=0;m<3;m++)e.forEach(C=>{l.push(yn(n.doc,m===0?C:""))});const c=Array(s).fill(Ac),a=l[r?0:s],u=n.doc.getContainerBlocks(a)[0].id;return{blockData:{id:N(),type:"table",rows:i,cols:s,children:l,colsWidth:c},focusBlockId:u}}function FT(n,t){const e=t.rows,o=t.cols;if(e<1||o<1)return null;const r=[];for(let a=0;a<e;a++)for(let u=0;u<o;u++)r.push(yn(n.doc));const i=Array(o).fill(Ac),s=r[0],l=n.doc.getContainerBlocks(s)[0].id;return{blockData:{id:N(),type:"table",rows:e,cols:o,children:r,colsWidth:i},focusBlockId:l}}const P4=B("table-selection-to-doc");function zT(n,t){const{start:e,end:o,block:r}=t,i=ot(r);d(P4,i==="table",`invalid block type: ${i}`);const s=n.getBlockData(r);if(e.isSimple()&&o.isSimple())return mo(n.editorBlocks,n.doc.toJSON(),s);d(P4,!e.isSimple()&&!o.isSimple(),"invalid block pos type");const l=et.fromBlock(r),{fromCol:c,toCol:a,fromRow:u,toRow:f}=an(r,e,o),m={},C=[],k=n.doc.toJSON();let w={};l.sub({row:u,col:c},{row:f,col:a}).forEach((Z,rt)=>{Z.forEach((st,mt)=>{const ut=st.containerId;if(C.indexOf(ut)!==-1)return;C.push(ut);let yt;if(st.virtual){const ee=l.getCellByContainerId(st.containerId),Ue=c+mt;let Do=ee.col+ee.colSpan-1;Do>a&&(Do=a);const pr=Do-Ue+1;pr>1&&(m[`${ut}_colSpan`]=pr);const Cr=u+rt;let Lo=ee.row+ee.rowSpan-1;Lo>f&&(Lo=f);const xa=Lo-Cr+1;xa>1&&(m[`${ut}_rowSpan`]=xa),yt=Ko()}else{if(yt=Cu(n.editorBlocks,k,ut),st.col+st.colSpan>a+1){const ee=a-st.col+1;ee>1&&(m[`${ut}_colSpan`]=ee)}else st.colSpan>1&&(m[`${ut}_colSpan`]=st.colSpan);if(st.row+st.rowSpan>f+1){const ee=f-st.row+1;ee>1&&(m[`${ut}_rowSpan`]=ee)}else st.rowSpan>1&&(m[`${ut}_rowSpan`]=st.rowSpan)}const{root:le,...eo}=yt.blocks;w={...w,...eo,[ut]:le}})});const S=Ss(jt(r)).slice(c,a+1);return{blocks:{root:[{id:N(),type:i,children:C,colsWidth:S,rows:f-u+1,cols:a-c+1,...m}],...w},meta:{},comments:{}}}function UT(n,t){if(t.top===0)return!0;for(let e=t.left;e<=t.right;e++)if(n[t.top-1][e]===n[t.top][e])return!1;return!0}function VT(n,t){if(t.left===0)return!0;for(let e=t.top;e<=t.bottom;e++)if(n[e][t.left-1]===n[e][t.left])return!1;return!0}function qT(n,t){if(t.bottom===n.length-1)return!0;for(let e=t.left;e<=t.right;e++)if(n[t.bottom][e]===n[t.bottom+1][e])return!1;return!0}function WT(n,t){if(t.right===n[0].length-1)return!0;for(let e=t.top;e<=t.bottom;e++)if(n[e][t.right]===n[e][t.right+1])return!1;return!0}function GT(n,t,e){const o=t.col,r=t.row,i=e.col,s=e.row,l={left:o,top:r,right:i,bottom:s};let c=!1;do{if(c=!1,!UT(n,l)){l.top--,c=!0;continue}if(!VT(n,l)){l.left--,c=!0;continue}if(!qT(n,l)){l.bottom++,c=!0;continue}if(!WT(n,l)){l.right++,c=!0;continue}}while(c);return l}function ZT(n,t,e,o){if(e.custom!==void 0||o.custom!==void 0)return{anchor:e,focus:o};const r=et.fromBlock(t),i=r.map(M=>M.containerId),s=r.getCellByContainerId(e.childContainerId),l=r.getCellByContainerId(o.childContainerId),c=Math.min(s.row,l.row),a=Math.max(s.row,l.row),u=Math.min(s.col,l.col),f=Math.max(s.col,l.col),m=GT(i,{row:c,col:u},{row:a,col:f}),C=r.getCell({row:m.top,col:m.left}),k=r.getCell({row:m.bottom,col:m.right}),w=r.getCell({row:m.top,col:m.right}),y=r.getCell({row:m.bottom,col:m.left});let S,I;return s.row<=l.row?s.col<=l.col?(S=C,I=k):(S=w,I=y):s.col<l.col?(S=y,I=w):(S=k,I=C),console.log(`move ${S.col}, ${S.row}, -> ${I.col}, ${I.row}`),{anchor:wt(t,S.containerId),focus:wt(t,I.containerId)}}function j4(n,t,e){if(e.isSimple())return[jt(t).getBoundingClientRect()];const o=jt(t),r=o.getBoundingClientRect(),{fromCol:i,fromRow:s,toCol:l,toRow:c}=an(t,e.start,e.end),a=Ss(o),u=a.slice(0,i).reduce((w,y)=>w+y,0),f=u+a.slice(i,l+1).reduce((w,y)=>w+y,0),m=S4(o);let C=m.slice(0,s).reduce((w,y)=>w+y,0);const k=C+m.slice(s,c+1).reduce((w,y)=>w+y,0);if(s===0){const w=ST(n,t);C-=w}return[new DOMRect(r.left+u,r.top+C,f-u,k-C)]}B("table-size");const YT=40;function Xc(n){const t=n.querySelector("td");if(!t)return 0;const e=window.getComputedStyle(t),o=Number.parseInt(e.borderLeft,10),r=Number.parseInt(e.borderRight,10);return(o+r)/2}function QT(n,t,e){const o=Td(n,e.container);return o!==void 0?o+Xc(t):YT*e.colSpan-Xc(t)}function KT(n,t,e,o){let r=0;const i=e.colCount;for(let s=0;s<i;s++){const l=e.getRealCell({col:s,row:o});if(l.virtual)continue;let c=QT(n,t,l);const a=gg(l.container,{withPadding:!0});a&&a>c&&(c=a),r+=c+Xc(t)}return r}function JT(n,t){const e=jt(t),o=et.fromTable(e);let r=0;for(let s=0;s<o.rowCount;s++)r=Math.max(r,KT(n,e,o,s));const i=Xc(e);return r+=i,r}const Yn=B("table-creator");async function XT(n,t){return n.undoManager.runInGroup(()=>{var c,a;const e=t.item,o=(c=e.colCount)!=null?c:5,r=(a=e.rowCount)!=null?a:3,i=FT(n,{cols:o,rows:r});if(!i)return null;const{blockData:s,focusBlockId:l}=i;return n.insertBlock(t.containerId,t.blockIndex,s,At(n,l,0))})}class tS{constructor(){h(this,"id","insert-table");h(this,"name","Create table");h(this,"element");h(this,"closeable",null);h(this,"colCount");h(this,"rowCount");h(this,"setCloseable",t=>{this.closeable=t});h(this,"destroy",()=>{this.closeable=null});h(this,"getTableCreatorCellId",(t,e)=>`table-creator-cell-${t}-${e}`);h(this,"handleTableCreatorClick",t=>{var m,C;t.preventDefault(),t.stopPropagation();const e=t.target;d(Yn,e instanceof HTMLElement,"invalid event target");const o=e.closest(".table-creator");d(Yn,o,"no table creator");const r=o.querySelectorAll(".active");if(r.length===0)return;const s=r[r.length-1].id;d(Yn,s,"no cell id");const l="table-creator-cell-";if(!s.startsWith(l))return;const a=s.substring(l.length).split("-");d(Yn,a.length===2,"invalid cell id");const u=Number.parseInt(a[0],10)+1,f=Number.parseInt(a[1],10)+1;Yn.debug(`${u}, ${f}`),this.colCount=f,this.rowCount=u,(m=this.closeable)==null||m.click(this,this.element),(C=this.closeable)==null||C.close(),this.handleTableCreatorLeave()});h(this,"handleTableCreatorLeave",()=>{for(let t=0;t<9;t++)for(let e=0;e<9;e++){const o=this.getTableCreatorCellId(t,e),r=document.getElementById(o);r&&z(r,"active")}});h(this,"handleTableCreatorCellEnter",t=>{const e=t.target;d(Yn,e instanceof HTMLElement,"invalid event target");const o=e.id,r="table-creator-cell-";d(Yn,o.startsWith(r),"invalid cell id");const s=o.substring(r.length).split("-");d(Yn,s.length===2,"invalid cell id");let l=Number.parseInt(s[0],10),c=Number.parseInt(s[1],10);l===0&&c===0&&(l=-1,c=-1);for(let a=0;a<9;a++)for(let u=0;u<9;u++){const f=this.getTableCreatorCellId(a,u),m=document.getElementById(f);d(Yn,m,"no cell"),a<=l&&u<=c?A(m,"active"):z(m,"active")}});this.element=this.createTableCreatorElement()}createTableCreatorElement(){const t=b("div",["table-creator"],null),e=(o,r,i)=>{const s=b("div",["table-creator-cell"],o);return s.id=this.getTableCreatorCellId(r,i),s};t.addEventListener("click",this.handleTableCreatorClick),t.addEventListener("mouseleave",this.handleTableCreatorLeave);for(let o=0;o<9;o++){const r=b("div",["table-creator-row"],t);for(let i=0;i<9;i++)e(r,o,i).addEventListener("mouseenter",this.handleTableCreatorCellEnter)}return t}}function eS(){return new tS}function nS(n){const t=/[\u4e00-\u9fff\u3040-\u309f\u30a0-\u30ff\uac00-\ud7af]/g,e=n.match(t);return e?e.length:0}function H4(n){const t=nS(n);return n.length+t}function oS(n,t){const e=H4(n),o=t-e;return o>0?n+" ".repeat(o):n}function rS(n,t,e,o,r){const i=t,s=new Ec(i);if(o==="markdown"||o==="text"){const l=y=>e.blocks[y].map((M,R)=>o==="markdown"?lu(n,M,e,[...r,{containerId:y,blockIndex:R}]):Kl(n,M,e,[...r,{containerId:y,blockIndex:R}])),c=y=>l(y).join(" ").replace(/\n/g," ").trim(),a=new Map,u=new Map;for(let y=0;y<s.colCount;y++){let S=0;for(let I=0;I<s.rowCount;I++){const M=s.getCell({row:I,col:y});let R="";M.virtual||(R=c(M.containerId)),a.set(`${I},${y}`,R),S=Math.max(S,H4(R))}u.set(y,S)}const f=y=>{const S=a.get(`${y.row},${y.col}`)||"",I=u.get(y.col)||0;return oS(S,I)},m=[];let C="|",k="|";for(let y=0;y<s.colCount;y++){const S=f({row:0,col:y});C+=` ${S} |`;const I="-".repeat((u.get(y)||0)+2);k+=`${I}|`}m.push(C),m.push(k);for(let y=1;y<s.rowCount;y++){let S="|";for(let I=0;I<s.colCount;I++){const M=f({row:y,col:I});S+=` ${M} |`}m.push(S)}return`${m.join(`
367
+ `:r.mathjaxText}const l1={embedType:"math",createEmbedContent:rT,getOptions:sT,convertFrom:iT,handleDeleteBlock:lT,convertTo:cT},xz="",aT={mathjax:{emptyText:"\u7A7A\u7684\u516C\u5F0F",abstract:"\u516C\u5F0F"}},dT={mathjax:{emptyText:"Empty Tex",abstract:"TeX"}};T.mergeLang({"zh-CN":aT,"en-US":dT});function uT(n,t,e,o){const r=n.getBlockByIndex(t,e),i=n.getBlockText(r),{left:s}=be(i,o);if(!bt(s).endsWith("$$$$"))return!1;const c=o-4,a=o,u={id:N(),box:!0,type:"math",tex:" ",src:"",created:Date.now()};return n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,c,a-c),n.insertBoxToBlock(r,c,u),setTimeout(()=>{const f=n.getBoxById(u.id);Wc(n,f)})}),!0}class hT{handleAfterInsertText(t,e,o,r,i){return!!(i===" "&&uT(t,e,o,r))}}const ei=B("inline-box-items");function fT(n,t,e){return n.undoManager.runInGroup(()=>{var s;let o=n.getBlockByIndex(t,e);Tt(n,o)||(o=n.insertTextBlock([],t,e));const r=E4();n.setBlockText(o,[r]);const i=(s=r.attributes)==null?void 0:s.id;return d(ei,i,"mathjax box id is empty"),setTimeout(()=>{const l=n.getBoxById(i);Wc(n,l)},100),o})}function mT(n,t,e){let o=n.getBlockByIndex(t,e),r="bottom-start";return Tt(n,o)||(r="top-start"),Ds(n,{target:o,linkText:"",linkUrl:"",onFinished:(l,c)=>{n.undoManager.runInGroup(()=>{try{Tt(n,o)||(o=n.insertTextBlock([],t,e));const a=$e(l,{link:c}),u=$e(" ",null),f=[a,u];n.insertTextToBlock(o,0,f),n.selection.selectBlock(o,ue(f)),n.focus()}catch(a){ei.error(a)}})},onClose:()=>{n.focus()},placement:r}),o}function gT(n,t,e){return n.undoManager.runInGroup(()=>{var l;const o=n.getBlockByIndex(t,e),r=n.selection.range;d(ei,lo(r.start),"invalid block position");const i=E4();n.insertBoxToBlock(o,r.start.offset,i.attributes);const s=(l=i.attributes)==null?void 0:l.id;return d(ei,s,"mathjax box id is empty"),setTimeout(()=>{const c=n.getBoxById(s);Wc(n,c)},100),o})}function pT(n,t,e){const o=n.getBlockByIndex(t,e),r=n.selection.range;d(ei,lo(r.start),"invalid block position");const i=so(n,o,r);if(i.length===0)return;const s=i[0],l=ao(n,o,"quick-menu-inline-link",s);Ds(n,{target:l,linkText:"",linkUrl:"",onFinished:(u,f)=>{n.undoManager.runInGroup(()=>{try{const m=n.getBlockText(o),C=fo(m,r.start.offset,u,{link:f});n.setBlockText(o,C),n.selection.selectBlock(o,r.start.offset+u.length),n.focus()}catch(m){ei.error(m)}})},onClose:()=>{n.focus()},placement:"bottom-start"})}class CT{getCommands(){return[{id:"insert-math",name:T.t("quickMenu.inlineBox.math"),icon:tB,order:900,group:"common",subText:me("insert-math")},{id:"insert-link",name:T.t("quickMenu.inlineBox.link"),icon:l5,order:400,group:"common",subText:me("insert-link")}]}async handleUpdateBlockCore(t,e){switch(e.item.id){case"insert-math":return gT(t,e.containerId,e.blockIndex);case"insert-link":return pT(t,e.containerId,e.blockIndex);default:return null}}async handleInsertEmptyBlockCore(t,e){switch(e.item.id){case"insert-math":return fT(t,e.containerId,e.blockIndex);case"insert-link":return mT(t,e.containerId,e.blockIndex);default:return null}}async executeCommand(t,e,o){if(o.from==="quick-menu"){const r=t.getBlockById(o.blockId),i=t.getParentContainer(r),s=U(i),l=t.getBlockIndex(r);t.undoManager.runInGroup(()=>this.handleUpdateBlockCore(t,{item:e,containerId:s,blockIndex:l}))}else o.from==="block-menu"&&t.undoManager.runInGroup(()=>this.handleInsertEmptyBlockCore(t,{item:e,containerId:o.containerId,blockIndex:o.blockIndex}));return null}}function bT(n){var o,r;const t=(r=(o=n.options.componentsOptions)==null?void 0:o.quickMenu)==null?void 0:r.commandProviders;if(!t)return[];const e=[];return[...t,new k4,new CT].forEach(i=>{const s=i.getCommands(n);e.push(...s.map(l=>({...l,itemType:"insert-block",commandProvider:i})))}),e}function kT(n){const t=[];return n.editorBlocks.forEach(e=>{if(!e.getOptions)return;const o=e.getOptions(n);!o.insertBlockCommandItems||(o.insertBlockCommandItems.forEach(r=>{b4(r,o)}),t.push(...o.insertBlockCommandItems))}),t.push(...bT(n)),t}function c1(n){const t=kT(n),e=new Map;t.forEach(i=>{var c;const s=(c=i.group)!=null?c:"";let l=e.get(s);l?l.items.push(i):(l={group:s,order:i.groupOrder||Vx[s]||1e3,items:[i]},e.set(s,l))});const o=Array.from(e.values());o.sort((i,s)=>i.order-s.order),o.forEach(i=>{i.items.sort((s,l)=>{var c,a;return((c=s.order)!=null?c:0)-((a=l.order)!=null?a:0)})});const r=[];return o.forEach((i,s)=>{const l=T.t(`blockMenu.section.${i.group||"common"}`),c=l===i.group?i.group:l;r.push({id:`section-${s}`,name:c,type:"section",group:i.group,itemType:"insert-block"}),r.push(...i.items.map(a=>({...a})))}),r}function vT(n,t,e){const o=n.getFocusedBlock();if(!o)return;const r=n.getParentContainer(o),i=U(r);let l=n.getBlockIndex(o);if(Tt(n,o)||(l+=1),t.commandProvider){t.commandProvider.executeCommand(n,t,{from:"quick-menu",...e});return}!t.blockOptions||!t.blockOptions.handleInsertEmptyBlock||t.blockOptions.handleInsertEmptyBlock(n,{containerId:i,blockIndex:l,item:t})}const I4=B("quick-menu"),yT={id:"quick-menu",trigger:["/"]};class Zc{constructor(t,e=yT){h(this,"suggest");h(this,"items");h(this,"maxHeading");h(this,"queryItems",async(t,e)=>{if(this.items.length===0?this.initMenuItems():this.refreshMenuItems(),e){const o=new Set,r=e.toLocaleLowerCase().replace(/^\s+|\s+$/g,"");return this.items.filter(i=>{var s;return i.type==="section"?!0:i.name.toLocaleLowerCase().indexOf(r)!==-1||zB(i).toLocaleLowerCase().indexOf(r)!==-1||i.group&&((s=i.group)==null?void 0:s.toLocaleLowerCase().indexOf(r))!==-1?(o.add(i.group),!0):!1}).filter(i=>i.type==="section"?o.has(i.group):!0)}return this.items});h(this,"onShow",(t,e,o,r)=>{const i=this.editor.getBlockByIndex(e,o);if(!Co(i)){const s=F(H(i));if(s&&ot(s)==="code")return!1}return!0});h(this,"onClickItem",(t,e)=>{const o=e;o.itemType==="insert-block"&&(d(I4,o.blockOptions||o.commandProvider,"invalid quick item, no block options or command provider"),d(I4,this.suggest.anchor,"invalid suggest, no anchor"),vT(this.editor,o,this.suggest.anchor))});this.editor=t,this.options=e,this.items=[],this.maxHeading=Pc(),this.suggest=new Ch(t,{id:e.id||"quick-menu",trigger:e.trigger,needSpaceBeforeTrigger:!0,autoDeleteTrigger:!0,highlight:!0,onShow:this.onShow,onClickItem:this.onClickItem,queryItems:this.queryItems})}get menu(){return this.suggest.menu.menu}destroy(){this.suggest.destroy()}initMenuItems(){const t=c1(this.editor);this.items=t}refreshMenuItems(){let t=null,e=0;const o=Pc();if(o!==this.maxHeading){const r=new k4,s=r.getCommands().map(l=>({...l,itemType:"insert-block",commandProvider:r}));for(let l=0;l<this.items.length;l++)this.items[l].group==="basics"&&(t||(t=l),t&&e++);t&&e&&this.items.splice(t,e,...s),this.maxHeading=o}}}class a1{constructor(t){h(this,"instance");h(this,"mousedown",!1);h(this,"currentInstance",null);h(this,"attributeName","");h(this,"attributeDesc","");h(this,"observer",null);h(this,"observerCallback",null);h(this,"createContent",t=>{var i;const e=(i=t.getAttribute(this.attributeName))!=null?i:"",o=t.getAttribute(this.attributeDesc);if(!o)return e;const r=b("div",[],null);return b("span",[],r,e),o&&b("span",["editor-tooltip-desc"],r,o),r});h(this,"handleDocumentMouseDown",()=>{this.mousedown=!0,this.editor.domEvents.addEventListener(document,"mouseup",this.handleDocumentMouseUp)});h(this,"handleDocumentMouseUp",()=>{this.mousedown=!1,this.editor.domEvents.removeEventListener(document,"mouseup",this.handleDocumentMouseUp)});h(this,"handleShown",t=>{this.currentInstance&&this.hide(),this.currentInstance=t,this.createObserver()});h(this,"handleHidden",()=>{this.destroyObserver(),this.currentInstance=null});h(this,"handleShow",t=>{var r;const e=t.reference;if(!e||!It(document.body,e)||window.isDragging||this.mousedown)return!1;const o=Number.parseInt((r=e.getAttribute("data-tooltip-hide-at"))!=null?r:"",10);return!(o&&Date.now()-o<1e3)});this.editor=t;const e=t.clientId;this.attributeName=`data-editor-tooltip-${e}`,this.attributeDesc=`data-editor-tooltip-desc-${e}`,this.instance=Qa.delegate(document.body,{delay:200,target:`[${this.attributeName}]`,content:this.createContent,onShow:this.handleShow,onShown:this.handleShown,onHide:this.handleHidden}),t.domEvents.addEventListener(document,"mousedown",this.handleDocumentMouseDown)}visible(){var t;return(t=this.currentInstance)==null?void 0:t.state.isVisible}hide(){var t;(t=this.currentInstance)!=null&&t.state.isVisible&&this.currentInstance.hide()}destroy(){this.destroyObserver(),this.instance.destroy(),this.editor.domEvents.removeEventListener(document,"mousedown",this.handleDocumentMouseDown),this.editor.domEvents.removeEventListener(document,"mouseup",this.handleDocumentMouseUp)}createObserver(){this.destroyObserver();const t=this.currentInstance;if(!t||!t.reference)return;this.observerCallback=Xt.default(()=>{t.reference.closest("body")||(t.hide(),this.destroyObserver())},200),this.observer=new MutationObserver(this.observerCallback);const e=document.body,o={childList:!0,attributes:!1,subtree:!0};this.observer.observe(e,o)}destroyObserver(){this.observer&&(this.observer.disconnect(),this.observer=null),this.observerCallback&&(this.observerCallback.cancel(),this.observerCallback=null)}}const wT={"text/style-bold":"bold","text/style-italic":"italic","text/style-underline":"underline","text/style-strikethrough":"line-through","text/style-code":"code","text/style-subscript":"subscript","text/style-superscript":"superscript"};function BT(n,t){const e=new Set(Object.keys(wT)),o=t.filter(i=>e.has(i.id));return _c(o)}function Yc(n,t){if(!n.isWritable())return!1;const e=n.selection.range,o=n.editorCommandProviders.getCommands(e),i=BT(n,o).find(s=>s.id===`text/${t}`);return i?(n.editorCommandProviders.executeCommand(e,i,{}),ti.get(n).update("selectionChange"),!0):!1}const d1={"CtrlOrCmd+B":n=>Yc(n,"style-bold"),"CtrlOrCmd+I":n=>Yc(n,"style-italic"),"CtrlOrCmd+U":n=>Yc(n,"style-underline"),"CtrlOrCmd+D":n=>Yc(n,"style-strikethrough")},ET={quickMenu:{basic:{heading:{title:"\u6807\u9898 {heading}",space:"{markdown}\u7A7A\u683C"},unordered:"\u65E0\u5E8F\u5217\u8868",ordered:"\u6709\u5E8F\u5217\u8868",checkbox:"\u5F85\u529E\u4E8B\u9879",quote:"\u5F15\u7528"},inlineBox:{math:"\u516C\u5F0F",link:"\u94FE\u63A5"}},link:{textLabel:"\u6587\u672C",urlLabel:"\u94FE\u63A5\u5730\u5740",textPlaceholder:"\u8BF7\u8F93\u5165\u6587\u672C",urlPlaceholder:"\u8BF7\u8F93\u5165\u94FE\u63A5\u5730\u5740",submitText:"\u786E\u5B9A",cancelText:"\u53D6\u6D88"},commands:{unordered:"\u65E0\u5E8F\u5217\u8868",ordered:"\u6709\u5E8F\u5217\u8868",check:"\u5F85\u529E\u5217\u8868",link:"\u94FE\u63A5",quote:"\u5F15\u7528",alignLeft:"\u5DE6\u5BF9\u9F50",alignRight:"\u53F3\u5BF9\u9F50",alignCenter:"\u5C45\u4E2D\u5BF9\u9F50",alignGroup:"\u5BF9\u9F50\u65B9\u5F0F",heading:"\u6807\u9898 {name}",headingGroup:"\u6807\u9898\u6837\u5F0F",text:"\u6B63\u6587"},commandDesc:{mac:{unordered:"\u2318+\u21E7+L",ordered:"\u2318+\u21E7+U",link:"\u2318+K"},window:{unordered:"Ctrl+Shift+L",ordered:"Ctrl+Shift+U",link:"Ctrl+K"}}},IT={quickMenu:{basic:{heading:{title:"Heading {heading}",space:"{markdown}space"},unordered:"Bulleted list",ordered:"Numbered list",checkbox:"Todo list",quote:"Quote"},inlineBox:{math:"Math",link:"Link"},link:{textLabel:"Text",urlLabel:"Link Address",textPlaceholder:"Please enter text",urlPlaceholder:"Please enter the link address",submitText:"Ok",cancelText:"Cancel"}},commands:{unordered:"Bulleted list",ordered:"Numberer list",check:"Todo list",link:"Link",quote:"Quote",alignLeft:"Align left",alignRight:"Align right",alignCenter:"Align center",alignGroup:"Alignment",heading:"Heading {name}",headingGroup:"Text style",text:"Text"},commandDesc:{mac:{unordered:"\u2318+\u21E7+L",ordered:"\u2318+\u21E7+U",link:"\u2318+K"},window:{unordered:"Ctrl+Shift+L",ordered:"Ctrl+Shift+U",link:"Ctrl+K"}}};T.mergeLang({"zh-CN":ET,"en-US":IT});const Tz="";function cr(n,...t){const e=yo(...t);return e.classList.remove("editor-button"),e.classList.add("editor-text-button"),n.append(e),e}function x4(n){Nc(n).hide();const e=n.getCustom("table-border-bar");e==null||e.closeToolbar()}function xT(n){return b("div",["insert-column-button","drop-marker"],n)}const T4=B("row-height");function S4(n){const t=et.fromTable(n),e=n.rows;d(T4,e.length===t.rowCount,"row count mismatch");const o=Array(t.rowCount).fill(0);for(let r=0;r<e.length;){let i=1,l=e[r].getBoundingClientRect().height,c=r+1;for(;c<e.length;){const a=e[c];if(a.cells.length!==0)break;i++,c++,l+=a.getBoundingClientRect().height}for(let a=0;a<i;a++)o[r+a]=l/i;r=c}return T4.debug("heights",o.join(", ")),o}const xo=B("table-border-bar-dom");function As(n,t){d(xo,Ht(t),"invalid table block");const e=jt(t),o=Tn(n,t),r=(a,u,f)=>{const m=b("div",["button-root",u],a),C=b("div",["button-container",u],m);m.setAttribute(`data-${u}-index`,`${f}`),C.setAttribute(`data-editor-tooltip-${n.clientId}`,u==="left"?T.t("table.insertRow"):T.t("table.insertCol")),b("span",["insert-indicator"],C),xT(C)},{selectedRows:i,selectedColumns:s}=kh(n,t),l=()=>{const a=o.querySelector(".table-border-bar-container.top");d(xo,a,"no top border bar container");const u=b("div",["table-border-bar-container","top"],null),f=b("div",["table-border-bar","top"],u),m=HE(e);b("span",["table-border-bar-cell","corner"],f);const k=et.fromTable(e).colCount;n.selection.range.isSimple()&&r(f,"top",0);for(let w=0;w<k;w++){const y=w===k-1?m[w]+2:m[w],S=b("span",["table-border-bar-cell","top"],f);s.has(w)&&S.classList.add("selected"),S.setAttribute("data-top-index",`${w}`),S.style.width=`${y}px`,n.selection.range.isSimple()&&r(f,"top",w+1)}Oi(a,u)},c=()=>{const a=o.querySelector(".table-border-bar-container.left");d(xo,a,"no left border bar container");const u=b("div",["table-border-bar-container","left"],null),f=b("div",["table-border-bar","left"],u),m=S4(e);n.selection.range.isSimple()&&r(f,"left",0),Array.from(e.rows).forEach((C,k,w)=>{const y=b("span",["table-border-bar-cell","left"],f);i.has(k)&&y.classList.add("selected"),y.setAttribute("data-left-index",`${k}`);const S=k===w.length-1?m[k]+2:m[k];y.style.height=`${S}px`,n.selection.range.isSimple()&&r(f,"left",k+1)}),Oi(a,u)};l(),c()}function D4(n,t){const e=t.target;if(!(e instanceof Element))return;const o=F(e);d(xo,o&&Ht(o),"invalid table block"),As(n,o),n.selection.caret.update()}function u1(n,t){const e=t.target;if(!(e instanceof Element))return;const o=F(e);d(xo,o&&Ht(o),"invalid table block");const r=e.closest(".button-root");if(r){if(r.classList.contains("top")){const i=parseInt(r.getAttribute("data-top-index")||"0",10);q5(n,o,i),As(n,o)}else if(r.classList.contains("left")){const i=parseInt(r.getAttribute("data-left-index")||"0",10);W5(n,o,i),As(n,o)}}}function h1(n,t){var s;x4(n),t.preventDefault(),t.stopPropagation();let e=null,o,r;const i=l=>{var c;if(l.target instanceof HTMLElement&&o&&e&&r!==void 0){const a=F(l.target),u=l.target.closest(".table-border-bar");if(a===e&&u){const f=parseInt((c=l.target.getAttribute(`data-${o}-index`))!=null?c:"0",10),m=Math.min(r,f),C=Math.abs(r-f)+1;nt(l.target,"top")&&o==="top"?XE(n,a,m,C,{reverse:!0}):nt(l.target,"left")&&o==="left"&&tI(n,a,m,C,{reverse:!0})}}l.type==="mouseup"&&(e=null,r=void 0,o=void 0,document.body.removeEventListener("mousemove",i),document.body.removeEventListener("mouseup",i))};t.target instanceof HTMLElement&&nt(t.target,"table-border-bar-cell")&&(e=F(t.target),nt(t.target,"top")?o="top":nt(t.target,"left")&&(o="left"),o&&e&&(r=parseInt((s=t.target.getAttribute(`data-${o}-index`))!=null?s:"0",10),document.body.addEventListener("mousemove",i),document.body.addEventListener("mouseup",i)))}function TT(n,t){d(xo,Ht(t),"invalid table block");const e=Tn(n,t),o=b("div",["table-border-bar-container","top"],e),r=b("div",["table-border-bar-container","left"],e);As(n,t),n.domEvents.addEventListener(it(t),"scroll",D4),n.domEvents.addEventListener(o,"click",u1),n.domEvents.addEventListener(r,"click",u1),n.domEvents.addEventListener(o,"mousedown",h1),n.domEvents.addEventListener(r,"mousedown",h1)}function L4(n,t){if(!n.isWritable())return;if(Tn(n,t).querySelector(".table-border-bar-container")){As(n,t);return}TT(n,t)}function M4(n,t){d(xo,Ht(t),"invalid table block"),Tn(n,t).querySelectorAll(".table-border-bar-container").forEach(r=>{n.domEvents.removeEventListener(r,"click",u1),n.domEvents.removeEventListener(r,"mousedown",h1),r.remove()}),n.domEvents.removeEventListener(it(t),"scroll",D4)}function ST(n,t){d(xo,Ht(t),"invalid table block");const o=Tn(n,t).querySelector(".table-border-bar-container.top");return o?o.getBoundingClientRect().height:0}class DT{constructor(t,e){h(this,"toolbar");h(this,"handleSelectionChange",(t,e)=>{e==="delete-columns"?(qr(this.editor,this.tableBlock,!0,!0),Wr(this.editor,this.tableBlock,!0,!0)):e==="delete-rows"?(qr(this.editor,this.tableBlock,!0,!1),Wr(this.editor,this.tableBlock,!0,!1)):(qr(this.editor,this.tableBlock,!1),Wr(this.editor,this.tableBlock,!1))});h(this,"handleClick",(t,e,o)=>{e.id==="delete-columns"?vh(this.editor.selection.range):e.id==="delete-rows"&&yh(this.editor.selection.range)});this.editor=t,this.tableBlock=e;const o=t.options.componentsOptions.popover;this.toolbar=new ks([],void 0,{overflowBoundary:o==null?void 0:o.overflowBoundary,refuseOverflow:!0,tooltipId:this.editor.clientId}),this.toolbar.addListener("selectionChange",this.handleSelectionChange),this.toolbar.addListener("click",this.handleClick)}close(){this.toolbar.close()}update(){const{selectedColumns:t,selectedRows:e}=kh(this.editor,this.tableBlock);if(!this.editor.isWritable())return;if(t.size>0&&e.size>0){this.toolbar.close();return}if(t.size===0&&e.size===0){this.toolbar.close();return}const o=so(this.editor,this.tableBlock,this.editor.selection.range)[0];if(!o){this.toolbar.close();return}if(t.size>0){const r={id:"delete-columns",name:T.t("table.deleteCol"),icon:Fw};this.toolbar.updateItems([r]);const i=ao(this.editor,this.tableBlock,"editor-quick-menu",o);this.toolbar.manualShow(i,{placement:"top"})}else{const r={id:"delete-rows",name:T.t("table.deleteRow"),icon:Hw};this.toolbar.updateItems([r]);const i=new DOMRect(o.left-15,o.top,o.width,o.height),s=ao(this.editor,this.tableBlock,"editor-quick-menu",i);this.toolbar.manualShow(s,{placement:"left"})}}destroy(){this.toolbar.destroy(),this.toolbar.removeAllListeners()}}const Qc=B("table-border-bar");class LT{constructor(t,e){h(this,"toolbar");h(this,"resizeObserver");h(this,"handleReadonlyChanged",t=>{t.isWritable()?this.update():M4(this.editor,this.tableBlock)});h(this,"handleBlockUpdated",()=>{this.resizeObserver.disconnect(),setTimeout(()=>{const t=this.editor.getBlockById(q(this.tableBlock));this.resizeObserver.observe(jt(t))})});h(this,"handleTableResize",()=>{!this.editor.isWritable()||(console.log("resize"),this.update())});this.editor=t,this.tableBlock=e,d(Qc,this.tableBlock,"no table block"),Qc.debug("create table border bar"),L4(this.editor,this.tableBlock),this.resizeObserver=new ResizeObserver(this.handleTableResize),this.resizeObserver.observe(jt(this.tableBlock)),this.toolbar=new DT(this.editor,this.tableBlock),this.editor.addListener("readonlyChanged",this.handleReadonlyChanged)}close(){this.toolbar.close()}destroy(){Qc.debug("destroy table border bar"),this.resizeObserver.disconnect(),M4(this.editor,this.tableBlock),this.toolbar.destroy(),this.editor.removeListener("readonlyChanged",this.handleReadonlyChanged)}update(){Qc.debug("update table border bar"),L4(this.editor,this.tableBlock),this.toolbar.update()}}const MT=B("table-border-bar");class RT{constructor(t){h(this,"activeTableBar",null);h(this,"handleBlockDeleted",(t,e)=>{!this.activeTableBar||(e===this.activeTableBar.tableBlock||It(e,this.activeTableBar.tableBlock))&&(this.activeTableBar.destroy(),this.activeTableBar=null)});h(this,"handleSelectionChanged",t=>{var r;const e=t.selection.range;let o=null;if(e.isCollapsed()&&e.isSimple()){const i=t.getBlockById(e.start.blockId);if(Ht(i)){const s=H(i),l=F(s);l&&(o=Me(l))}else o=Me(i)}else{const i=t.getBlockById(e.start.blockId),s=Me(i),l=t.getBlockById(e.end.blockId),c=Me(l);s===c&&(o=s)}((r=this.activeTableBar)==null?void 0:r.tableBlock)!==o&&this.activeTableBar&&this.hide(),o&&this.show(o)});this.editor=t,this.editor.addListener("blockDeleted",this.handleBlockDeleted),this.editor.addListener("selectionChanged",this.handleSelectionChanged)}destroy(){this.editor.removeListener("blockDeleted",this.handleBlockDeleted),this.editor.removeListener("selectionChanged",this.handleSelectionChanged)}show(t){this.activeTableBar?(this.activeTableBar.tableBlock!==t&&this.hide(),this.activeTableBar.update()):this.activeTableBar=new LT(this.editor,t)}update(){var t;(t=this.activeTableBar)==null||t.handleBlockUpdated()}closeToolbar(){var t;(t=this.activeTableBar)==null||t.close()}hide(){!this.activeTableBar||(d(MT,this.activeTableBar,"no active table bar"),this.activeTableBar.destroy(),this.activeTableBar=null)}}function R4(n,t){const e=n.addCustom("table-border-bar",o=>new RT(o));t==="update"&&e.update()}const Be=B("table-cell-menu"),AT="style-bg-color-";class OT{constructor(t){h(this,"activeTableBlock",null);h(this,"targetButton",null);h(this,"manualMenu",null);h(this,"colorPaletteItem",null);h(this,"handlePrevent",(t,e)=>{e.stopPropagation()});h(this,"handleReadonlyChanged",t=>{t.isWritable()||this.hide()});h(this,"handleSelectionChanged",t=>{const e=t.selection.range;let o=null;if(e.isCollapsed()&&e.isSimple()){const r=t.getBlockById(e.start.blockId);if(Ht(r)){const i=H(r),s=F(i);s&&(o=Me(s))}else o=Me(r)}else{const r=t.getBlockById(e.start.blockId),i=Me(r),s=t.getBlockById(e.end.blockId),l=Me(s);i===l&&(o=i)}if(this.hide(),this.activeTableBlock!==o&&(this.activeTableBlock=o),this.activeTableBlock){const r=et.fromBlock(this.activeTableBlock),i=e.isReverse()?e.start:e.end;let s=null;e.isCollapsed()?s=this.getCellByChildBlockId(r,i.blockId):i instanceof Je&&(t.getBlockById(i.blockId)===this.activeTableBlock?s=r.getCellByContainerId(i.childContainerId):s=this.getCellByChildBlockId(r,i.blockId)),s&&this.editor.isWritable()&&this.showCellMenuButton(s)}});h(this,"handleBeforePopupPalette",()=>{var e;const t=this.getSelectedBkgColorIndex();(e=this.colorPaletteItem)==null||e.palette.setColor("backgroundColor",t)});h(this,"createBkgColorItem",()=>{const t=b("div",["cell-background-color-item"],null);b("span",[],t,T.t("table.cellBackground"));const e=this.getSelectedBkgColorIndex();b("button",["item-button"],t).setAttribute("data-color-index",`${e}`);const r=b("span",["item-sub-indicator"],t);return r.innerHTML=o5,t});h(this,"handleCommand",t=>{var r;d(Be,this.activeTableBlock,"no target table block");const e=((r=t.states)==null?void 0:r.includes("checked"))||!1,o=t.value;switch(t.id){case"delete-select-row":yh(x5(this.editor,this.activeTableBlock,!1));break;case"delete-select-col":vh(x5(this.editor,this.activeTableBlock,!0));break;case"merge-cell":B5(this.editor.selection.range);break;case"split-cell":this.handleSplitCell();break;case"row-title":this.handleRowTitle(e);break;case"col-title":this.handleColTitle(e);break;case"stripe-style":this.handleStripeStyle(e);break;case"hide-border":cE(this.editor,this.activeTableBlock,o==="show-border");break;case"show-chart":fE(this.editor,this.activeTableBlock,o==="show-chart"),Rh(this.editor,this.activeTableBlock,{updateNow:!0});break}});h(this,"handleSelectionChange",(t,e)=>{d(Be,this.activeTableBlock,"no target table block"),e==="cell-background-color"&&this.handleBeforePopupPalette(),e==="delete-select-row"?(qr(this.editor,this.activeTableBlock,!0,!1),Wr(this.editor,this.activeTableBlock,!0,!1)):e==="delete-select-col"?(qr(this.editor,this.activeTableBlock,!0,!0),Wr(this.editor,this.activeTableBlock,!0,!0)):(qr(this.editor,this.activeTableBlock,!1),Wr(this.editor,this.activeTableBlock,!1))});h(this,"handleClick",()=>{var t;d(Be,this.activeTableBlock,"no target table block"),d(Be,this.targetButton,"no target button"),x4(this.editor),nt(this.targetButton,"active")?(z(this.targetButton,"active"),(t=this.manualMenu)==null||t.close()):(A(this.targetButton,"active"),this.manualMenu?this.manualMenu.updateItems(this.createCommandMenu()):(this.manualMenu=new nr(this.createCommandMenu()),this.manualMenu.on("click",(e,o)=>{var r;this.handleCommand(o),(r=this.manualMenu)==null||r.close()}),this.manualMenu.on("selectionChange",this.handleSelectionChange),this.manualMenu.on("close",()=>{this.targetButton&&z(this.targetButton,"active"),this.editor.focus()})),this.manualMenu.manualShow(this.targetButton,{placement:"right-start"}))});this.editor=t,this.editor.addListener("selectionChanged",this.handleSelectionChanged),this.editor.addListener("readonlyChanged",this.handleReadonlyChanged)}destroy(){var t,e;this.activeTableBlock=null,this.targetButton=null,this.editor.removeListener("selectionChanged",this.handleSelectionChanged),this.editor.removeListener("readonlyChanged",this.handleReadonlyChanged),(t=this.manualMenu)==null||t.destroy(),(e=this.colorPaletteItem)==null||e.destroy()}hide(){var t;(t=this.manualMenu)==null||t.close(),this.targetButton&&(z(this.targetButton,"active"),this.targetButton.style.display="none")}getCellByChildBlockId(t,e){let o=this.editor.getBlockById(e);for(;o;){const r=o.closest("td");d(Be,r,"no parent cell");const i=F(r);if(d(Be,i,"no parent block"),jt(i)===t.table)return t.getCellByCellElement(r);o=i}return d(Be,!1,"filed to get cell by child block id"),null}createTargetButton(t){this.targetButton?t.querySelector(`:scope > .${Sh}`)||t.appendChild(this.targetButton):(this.targetButton=b("button",[Sh],t),this.targetButton.innerHTML=eh,this.editor.domEvents.addEventListener(this.targetButton,"click",this.handleClick),this.editor.domEvents.addEventListener(this.targetButton,"mousedown",this.handlePrevent))}showCellMenuButton(t){this.createTargetButton(t.cell),d(Be,this.targetButton,"no target button"),this.targetButton.style.display="inline-block"}handleSplitCell(){if(this.activeTableBlock){const t=et.fromBlock(this.activeTableBlock),e=this.editor.selection.range;if(e.isSimple()){const{col:o,row:r}=this.getCellByChildBlockId(t,e.start.blockId);Bh(this.editor,this.activeTableBlock,{col:o,row:r})}else Eh(this.editor.selection.range)}}getSelectedBkgColorIndex(){var r;d(Be,this.activeTableBlock,"no target table block");const t=uE(this.editor,this.activeTableBlock),e=this.editor.getBlockData(this.activeTableBlock),o=new Set;for(const i of t){if(o.size>1)break;const s=U(i),l=e[`${s}_background`];if(l)o.add(Number.parseInt((r=l.substring(AT.length))!=null?r:"0",10));else{o.add(-1);break}}return o.size===1&&[...o][0]!==-1?[...o][0]:-1}createCommandMenu(){d(Be,this.activeTableBlock,"no target table block");const t=this.editor.getBlockData(this.activeTableBlock),e=w5(this.editor,this.activeTableBlock,this.editor.selection.range);let o=this.editor.selection.range;if(o.isSimple()){const u=Gn(this.editor,this.activeTableBlock,o.start);o=qt(this.editor,{anchor:u,focus:u})}const r=y5(this.editor,this.activeTableBlock,o),i=t.hasRowTitle,s=t.hasColTitle,l=t.isStripeStyle,c=t.noBorder,a=t.chart;return this.colorPaletteItem=new g5("cell-background-color",{color:!1}),this.colorPaletteItem.palette.on("onClick",(u,f)=>{var m;switch(d(Be,this.activeTableBlock,"no target table block"),u){case"clearColor":D5(this.editor,this.activeTableBlock,-1);break;case"backgroundColor":D5(this.editor,this.activeTableBlock,f);break}(m=this.manualMenu)==null||m.close()}),[{id:"cell-background-color",name:T.t("table.cellBackground"),element:this.createBkgColorItem(),children:[this.colorPaletteItem]},{id:"separator",name:"",type:"separator"},{id:"merge-cell",name:T.t("table.mergeCell"),states:e?[]:["disabled"]},{id:"split-cell",name:T.t("table.splitCell"),states:r?[]:["disabled"]},{id:"separator",name:"",type:"separator"},{id:"delete-select-row",name:T.t("table.deleteSelectRow")},{id:"delete-select-col",name:T.t("table.deleteSelectCol")},{id:"separator",name:"",type:"separator"},{id:"table-config",name:T.t("table.tableConfigKey"),children:[{id:"row-title",name:T.t("table.tableConfig.rowTitle"),states:i?["checked"]:[]},{id:"col-title",name:T.t("table.tableConfig.colTitle"),states:s?["checked"]:[]},{id:"stripe-style",name:T.t("table.tableConfig.stripeStyle"),states:l?["checked"]:[]},{id:"hide-border",name:c?T.t("table.tableConfig.showBorder"):T.t("table.tableConfig.hideBorder"),value:c?"show-border":"hide-border"},{id:"show-chart",name:a?T.t("table.tableConfig.hideChart"):T.t("table.tableConfig.showChart"),value:a?"hide-chart":"show-chart"}]}]}handleRowTitle(t){d(Be,this.activeTableBlock,"no target table block"),t?iE(this.editor,this.activeTableBlock):rE(this.editor,this.activeTableBlock)}handleColTitle(t){d(Be,this.activeTableBlock,"no target table block"),t?oE(this.editor,this.activeTableBlock):nE(this.editor,this.activeTableBlock)}handleStripeStyle(t){d(Be,this.activeTableBlock,"no target table block"),t?lE(this.editor,this.activeTableBlock):sE(this.editor,this.activeTableBlock)}}function A4(n){n.addCustom("table-cell-menu",t=>new OT(t))}const Kc=B("table-container");function f1(n){const t=n.closest("td");return d(Kc,t,"no parent cell for a table cell container"),t}function O4(n){const t=jt(n);return Array.from(t.querySelectorAll(':scope > tbody > tr > td > [data-type="editor-container"].child'))}function m1(n,t,e,o){const r=et.fromBlock(n),i=r.getCellByContainerId(U(t));if(e==="ArrowDown"){const s=r.getBottomCell(i);return s?s.container:null}if(e==="ArrowUp"){const s=r.getTopCell(i);return s?s.container:null}if(e==="ArrowLeft"){const s=r.getAllContainers(),l=s.indexOf(t);if(d(Kc,l>=0,"not a valid child container"),l===0)return null;const c=s[l-1];return o!=null&&o.noWrap&&r.getCellByContainerId(U(c)).row!==i.row?null:c}if(e==="ArrowRight"){const s=r.getAllContainers(),l=s.indexOf(t);if(d(Kc,l>=0,"not a valid child container"),l===s.length-1)return null;const c=s[l+1];return o!=null&&o.noWrap&&r.getCellByContainerId(U(c)).row!==i.row?null:c}d(Kc,!1,`invalid navigation type: ${e}`)}const _T=12,NT=90,Jc=23,_4=2;class $T{constructor(t){h(this,"scrollTableBlock",null);h(this,"autoScrollDir",null);h(this,"autoScrollTimer",null);h(this,"handleMouseDown",t=>{const e=document.elementFromPoint(t.clientX,t.clientY);if(e&&e instanceof HTMLElement){const o=F(e);if(o&&It(this.editor.rootContainer,o)){const r=Me(o);r&&(this.scrollTableBlock=r,document.addEventListener("mousemove",this.handleAutoScroll))}}});h(this,"handleAutoScroll",x7.default(t=>{if(this.scrollTableBlock){const e=this.editor.getCustom(Bo(this.scrollTableBlock)),o=e.rootElement,r=e.scrollOptions.parentContainer,i=o.getBoundingClientRect(),s=window.innerHeight-(e.scrollOptions.barFloatWindowBottom||0),l=r.getBoundingClientRect(),c=Math.min(l.bottom,s),a=Math.max(l.top,0);i.bottom>c&&t.clientY>=c?this.setAutoScroll("bottom"):i.top<a&&t.clientY<=a?this.setAutoScroll("top"):o.scrollLeft>0&&t.clientX<i.left?this.setAutoScroll("left"):o.scrollLeft<o.scrollWidth-o.offsetWidth&&t.clientX>i.right?this.setAutoScroll("right"):this.clearAutoScroll()}},15));h(this,"handleMouseUp",()=>{document.removeEventListener("mousemove",this.handleAutoScroll),setTimeout(()=>{this.scrollTableBlock=null})});h(this,"handleSelectionChanged",t=>{const e=t.selection.range;if(e.isCollapsed()&&e.isSimple()){const o=t.getBlockById(e.start.blockId),r=Me(o);if(r){const i=t.getCustom(Bo(r)),s=i.rootElement.getBoundingClientRect(),l=Ke(t,o,e.start);if(s.left>l.left){const c=e.start.offset===0?_T:_4;i.rootElement.scrollLeft-=s.left-l.left+c}else if(l.right>s.right){const c=e.start.offset===0?NT:_4;i.rootElement.scrollLeft+=l.right-s.right+c}}}else{const o=t.getBlockById(e.start.blockId),r=Me(o),i=t.getBlockById(e.end.blockId),s=Me(i);if(r&&r===s){const l=t.getCustom(Bo(r)),c=l.rootElement.getBoundingClientRect();let a=null;if(e.isSimple())a=e.isReverse()?Ke(t,o,e.start):Ke(t,i,e.end);else{const u=f1(Er(t,e.start.childContainerId)),f=f1(Er(t,e.end.childContainerId));a=e.isReverse()?u.getBoundingClientRect():f.getBoundingClientRect()}c.left>a.left&&e.isReverse()?l.rootElement.scrollLeft-=c.left-a.left:c.right<a.right&&!e.isReverse()&&(l.rootElement.scrollLeft+=a.right-c.right)}}});h(this,"handleScroll",t=>{b5(t),this.editor.selection.caret.update()});h(this,"handleReset",t=>{b5(t),this.editor.selection.caret.update()});this.editor=t,this.editor.addListener("selectionChanged",this.handleSelectionChanged),document.addEventListener("mousedown",this.handleMouseDown),document.addEventListener("mouseup",this.handleMouseUp)}clearAutoScroll(){this.autoScrollTimer&&(clearInterval(this.autoScrollTimer),this.autoScrollTimer=null,this.autoScrollDir=null)}setAutoScroll(t){this.autoScrollDir&&this.autoScrollDir!==t&&this.clearAutoScroll(),this.autoScrollTimer||(this.autoScrollDir=t,this.autoScrollTimer=window.setInterval(()=>{if(this.scrollTableBlock){const e=this.editor.getCustom(Bo(this.scrollTableBlock)),o=e.rootElement,r=e.scrollOptions.parentContainer,i=o.getBoundingClientRect(),s=r===document.documentElement?window.innerHeight:r.offsetHeight,l=window.innerHeight-(e.scrollOptions.barFloatWindowBottom||0),c=r.getBoundingClientRect(),a=Math.min(c.bottom,l),u=Math.max(c.top,0);this.autoScrollDir==="left"&&(o.scrollLeft-=Jc,o.scrollLeft<=0&&this.clearAutoScroll()),this.autoScrollDir==="right"&&(o.scrollLeft+=Jc,o.scrollLeft>=o.scrollWidth-o.offsetWidth&&this.clearAutoScroll()),this.autoScrollDir==="bottom"&&(r.scrollTop+=Jc,(r.scrollTop>=r.scrollHeight-s||i.bottom<=a)&&this.clearAutoScroll()),this.autoScrollDir==="top"&&(r.scrollTop-=Jc,(r.scrollTop<=0||i.top>=u)&&this.clearAutoScroll())}},100))}destroy(){document.removeEventListener("mousedown",this.handleMouseDown),document.removeEventListener("mouseup",this.handleMouseUp),this.editor.removeListener("selectionChanged",this.handleSelectionChanged)}}function N4(n){return n.addCustom("table-scroll-events",t=>new $T(t))}const Sn=B("create-content");function $4(n,t,e){const o=new Ec(e),r=e.rows,i=e.cols;d(Sn,r>=1,`invalid rows: ${r}`),d(Sn,i>=1,`invalid cols: ${i}`),d(Sn,e.children,"no table children");const s=b("table",[],null),l=e.colsWidth,c=b("colgroup",[],s);for(let f=0;f<o.colCount;f++){const m=b("col",[],c);m.style.width=`${l[f]||Ac}px`}const a=b("tbody",[],s);let u=0;for(let f=0;f<r;f++){const m=b("tr",[],a);for(let C=0;C<i;C++){const k=o.getCell({col:C,row:f});if(k.virtual)d(Sn,k.colSpan>1||k.rowSpan>1,"virtual cell should have colSpan or rowSpan");else{const w=e.children[u],y=b("td",[],m);k.colSpan>1&&(y.colSpan=k.colSpan),k.rowSpan>1&&(y.rowSpan=k.rowSpan);const S=e[Es(w)];S&&A(y,S),C===0&&e.hasColTitle&&A(y,E5.COL_TITLE_ITEM),n.createChildContainer(t,y,w),u+=1}}}return d(Sn,u===e.children.length,"container count mismatch"),e.noBorder&&A(s,"no-border"),e.chart&&A(s,"editor-table-chart"),e.isStripeStyle&&A(s,"stripe"),e.hasRowTitle&&A(s,"row-title"),e.hasColTitle&&A(s,"col-title"),s}function PT(n,t,e,o,r){d(Sn,r.type==="table","not table data"),d(Sn,U(e)===t[t.length-1].containerId,"invalid path");const i=r,s=ro(o,"div");try{const l=b("div",[],null);l.setAttribute("data-type","table-content");const c=$4(n,t,i);c.classList.add("drag-preview-element"),l.appendChild(c),U5(n),Z5(n),R4(n,"create"),A4(n),Sw(n,Ah);const a=n.getComponentOptions("table"),u=n.addCustom(Bo(o),()=>$E());u.init({parentElement:s,childElement:l,safeRightSpace:50,safeLeftSpace:40,parentContainer:pt(e)?n.scrollContainer:e,locatingContainer:pt(e)?(a==null?void 0:a.locatingContainer)||n.parent:e,paddingLeft:Th+Bs,paddingTop:Th+Bs,paddingBottom:Bs/2,paddingRight:Bs/2,barFloatWindowBottom:a==null?void 0:a.barFloatWindowBottom,isSetScale:a==null?void 0:a.isSetScale});const f=N4(n);u.on("scroll",f.handleReset),u.on("resize",f.handleReset),setTimeout(()=>{pE(n,o)})}catch{const c=`invalid table data: ${JSON.stringify(i)}`;Sn.error(c);const a=b("div",["error"],s);a.innerText=c}return s}function jT(n,t,e){d(Sn,e.type==="table","not table data");const o=e,r=it(t);try{const i=jt(t),s=io(t),l=$4(n,s,o);l.classList.add("drag-preview-element"),i.insertAdjacentElement("afterend",l),i.remove(),U5(n),Z5(n),R4(n,"update"),A4(n),Ah(n,t)}catch{const s=`invalid table data: ${JSON.stringify(o)}`;Sn.error(s);const l=b("div",["error"],r);l.innerText=s}}function HT(n,t){let e,o,r=!1;if([...t].every(m=>m==="|")?(o=t.length,e=Array(o).fill(""),r=!0):(e=ld(t,"|").split("|"),o=e.length),o<2)return null;const i=3,s=o,l=[];for(let m=0;m<3;m++)e.forEach(C=>{l.push(yn(n.doc,m===0?C:""))});const c=Array(s).fill(Ac),a=l[r?0:s],u=n.doc.getContainerBlocks(a)[0].id;return{blockData:{id:N(),type:"table",rows:i,cols:s,children:l,colsWidth:c},focusBlockId:u}}function FT(n,t){const e=t.rows,o=t.cols;if(e<1||o<1)return null;const r=[];for(let a=0;a<e;a++)for(let u=0;u<o;u++)r.push(yn(n.doc));const i=Array(o).fill(Ac),s=r[0],l=n.doc.getContainerBlocks(s)[0].id;return{blockData:{id:N(),type:"table",rows:e,cols:o,children:r,colsWidth:i},focusBlockId:l}}const P4=B("table-selection-to-doc");function zT(n,t){const{start:e,end:o,block:r}=t,i=ot(r);d(P4,i==="table",`invalid block type: ${i}`);const s=n.getBlockData(r);if(e.isSimple()&&o.isSimple())return go(n.editorBlocks,n.doc.toJSON(),s);d(P4,!e.isSimple()&&!o.isSimple(),"invalid block pos type");const l=et.fromBlock(r),{fromCol:c,toCol:a,fromRow:u,toRow:f}=an(r,e,o),m={},C=[],k=n.doc.toJSON();let w={};l.sub({row:u,col:c},{row:f,col:a}).forEach((Z,rt)=>{Z.forEach((st,mt)=>{const ut=st.containerId;if(C.indexOf(ut)!==-1)return;C.push(ut);let yt;if(st.virtual){const ee=l.getCellByContainerId(st.containerId),Ue=c+mt;let Lo=ee.col+ee.colSpan-1;Lo>a&&(Lo=a);const pr=Lo-Ue+1;pr>1&&(m[`${ut}_colSpan`]=pr);const Cr=u+rt;let Mo=ee.row+ee.rowSpan-1;Mo>f&&(Mo=f);const xa=Mo-Cr+1;xa>1&&(m[`${ut}_rowSpan`]=xa),yt=Ko()}else{if(yt=Cu(n.editorBlocks,k,ut),st.col+st.colSpan>a+1){const ee=a-st.col+1;ee>1&&(m[`${ut}_colSpan`]=ee)}else st.colSpan>1&&(m[`${ut}_colSpan`]=st.colSpan);if(st.row+st.rowSpan>f+1){const ee=f-st.row+1;ee>1&&(m[`${ut}_rowSpan`]=ee)}else st.rowSpan>1&&(m[`${ut}_rowSpan`]=st.rowSpan)}const{root:le,...eo}=yt.blocks;w={...w,...eo,[ut]:le}})});const S=Ss(jt(r)).slice(c,a+1);return{blocks:{root:[{id:N(),type:i,children:C,colsWidth:S,rows:f-u+1,cols:a-c+1,...m}],...w},meta:{},comments:{}}}function UT(n,t){if(t.top===0)return!0;for(let e=t.left;e<=t.right;e++)if(n[t.top-1][e]===n[t.top][e])return!1;return!0}function VT(n,t){if(t.left===0)return!0;for(let e=t.top;e<=t.bottom;e++)if(n[e][t.left-1]===n[e][t.left])return!1;return!0}function qT(n,t){if(t.bottom===n.length-1)return!0;for(let e=t.left;e<=t.right;e++)if(n[t.bottom][e]===n[t.bottom+1][e])return!1;return!0}function WT(n,t){if(t.right===n[0].length-1)return!0;for(let e=t.top;e<=t.bottom;e++)if(n[e][t.right]===n[e][t.right+1])return!1;return!0}function GT(n,t,e){const o=t.col,r=t.row,i=e.col,s=e.row,l={left:o,top:r,right:i,bottom:s};let c=!1;do{if(c=!1,!UT(n,l)){l.top--,c=!0;continue}if(!VT(n,l)){l.left--,c=!0;continue}if(!qT(n,l)){l.bottom++,c=!0;continue}if(!WT(n,l)){l.right++,c=!0;continue}}while(c);return l}function ZT(n,t,e,o){if(e.custom!==void 0||o.custom!==void 0)return{anchor:e,focus:o};const r=et.fromBlock(t),i=r.map(M=>M.containerId),s=r.getCellByContainerId(e.childContainerId),l=r.getCellByContainerId(o.childContainerId),c=Math.min(s.row,l.row),a=Math.max(s.row,l.row),u=Math.min(s.col,l.col),f=Math.max(s.col,l.col),m=GT(i,{row:c,col:u},{row:a,col:f}),C=r.getCell({row:m.top,col:m.left}),k=r.getCell({row:m.bottom,col:m.right}),w=r.getCell({row:m.top,col:m.right}),y=r.getCell({row:m.bottom,col:m.left});let S,I;return s.row<=l.row?s.col<=l.col?(S=C,I=k):(S=w,I=y):s.col<l.col?(S=y,I=w):(S=k,I=C),console.log(`move ${S.col}, ${S.row}, -> ${I.col}, ${I.row}`),{anchor:wt(t,S.containerId),focus:wt(t,I.containerId)}}function j4(n,t,e){if(e.isSimple())return[jt(t).getBoundingClientRect()];const o=jt(t),r=o.getBoundingClientRect(),{fromCol:i,fromRow:s,toCol:l,toRow:c}=an(t,e.start,e.end),a=Ss(o),u=a.slice(0,i).reduce((w,y)=>w+y,0),f=u+a.slice(i,l+1).reduce((w,y)=>w+y,0),m=S4(o);let C=m.slice(0,s).reduce((w,y)=>w+y,0);const k=C+m.slice(s,c+1).reduce((w,y)=>w+y,0);if(s===0){const w=ST(n,t);C-=w}return[new DOMRect(r.left+u,r.top+C,f-u,k-C)]}B("table-size");const YT=40;function Xc(n){const t=n.querySelector("td");if(!t)return 0;const e=window.getComputedStyle(t),o=Number.parseInt(e.borderLeft,10),r=Number.parseInt(e.borderRight,10);return(o+r)/2}function QT(n,t,e){const o=Td(n,e.container);return o!==void 0?o+Xc(t):YT*e.colSpan-Xc(t)}function KT(n,t,e,o){let r=0;const i=e.colCount;for(let s=0;s<i;s++){const l=e.getRealCell({col:s,row:o});if(l.virtual)continue;let c=QT(n,t,l);const a=gg(l.container,{withPadding:!0});a&&a>c&&(c=a),r+=c+Xc(t)}return r}function JT(n,t){const e=jt(t),o=et.fromTable(e);let r=0;for(let s=0;s<o.rowCount;s++)r=Math.max(r,KT(n,e,o,s));const i=Xc(e);return r+=i,r}const Yn=B("table-creator");async function XT(n,t){return n.undoManager.runInGroup(()=>{var c,a;const e=t.item,o=(c=e.colCount)!=null?c:5,r=(a=e.rowCount)!=null?a:3,i=FT(n,{cols:o,rows:r});if(!i)return null;const{blockData:s,focusBlockId:l}=i;return n.insertBlock(t.containerId,t.blockIndex,s,At(n,l,0))})}class tS{constructor(){h(this,"id","insert-table");h(this,"name","Create table");h(this,"element");h(this,"closeable",null);h(this,"colCount");h(this,"rowCount");h(this,"setCloseable",t=>{this.closeable=t});h(this,"destroy",()=>{this.closeable=null});h(this,"getTableCreatorCellId",(t,e)=>`table-creator-cell-${t}-${e}`);h(this,"handleTableCreatorClick",t=>{var m,C;t.preventDefault(),t.stopPropagation();const e=t.target;d(Yn,e instanceof HTMLElement,"invalid event target");const o=e.closest(".table-creator");d(Yn,o,"no table creator");const r=o.querySelectorAll(".active");if(r.length===0)return;const s=r[r.length-1].id;d(Yn,s,"no cell id");const l="table-creator-cell-";if(!s.startsWith(l))return;const a=s.substring(l.length).split("-");d(Yn,a.length===2,"invalid cell id");const u=Number.parseInt(a[0],10)+1,f=Number.parseInt(a[1],10)+1;Yn.debug(`${u}, ${f}`),this.colCount=f,this.rowCount=u,(m=this.closeable)==null||m.click(this,this.element),(C=this.closeable)==null||C.close(),this.handleTableCreatorLeave()});h(this,"handleTableCreatorLeave",()=>{for(let t=0;t<9;t++)for(let e=0;e<9;e++){const o=this.getTableCreatorCellId(t,e),r=document.getElementById(o);r&&z(r,"active")}});h(this,"handleTableCreatorCellEnter",t=>{const e=t.target;d(Yn,e instanceof HTMLElement,"invalid event target");const o=e.id,r="table-creator-cell-";d(Yn,o.startsWith(r),"invalid cell id");const s=o.substring(r.length).split("-");d(Yn,s.length===2,"invalid cell id");let l=Number.parseInt(s[0],10),c=Number.parseInt(s[1],10);l===0&&c===0&&(l=-1,c=-1);for(let a=0;a<9;a++)for(let u=0;u<9;u++){const f=this.getTableCreatorCellId(a,u),m=document.getElementById(f);d(Yn,m,"no cell"),a<=l&&u<=c?A(m,"active"):z(m,"active")}});this.element=this.createTableCreatorElement()}createTableCreatorElement(){const t=b("div",["table-creator"],null),e=(o,r,i)=>{const s=b("div",["table-creator-cell"],o);return s.id=this.getTableCreatorCellId(r,i),s};t.addEventListener("click",this.handleTableCreatorClick),t.addEventListener("mouseleave",this.handleTableCreatorLeave);for(let o=0;o<9;o++){const r=b("div",["table-creator-row"],t);for(let i=0;i<9;i++)e(r,o,i).addEventListener("mouseenter",this.handleTableCreatorCellEnter)}return t}}function eS(){return new tS}function nS(n){const t=/[\u4e00-\u9fff\u3040-\u309f\u30a0-\u30ff\uac00-\ud7af]/g,e=n.match(t);return e?e.length:0}function H4(n){const t=nS(n);return n.length+t}function oS(n,t){const e=H4(n),o=t-e;return o>0?n+" ".repeat(o):n}function rS(n,t,e,o,r){const i=t,s=new Ec(i);if(o==="markdown"||o==="text"){const l=y=>e.blocks[y].map((M,R)=>o==="markdown"?lu(n,M,e,[...r,{containerId:y,blockIndex:R}]):Kl(n,M,e,[...r,{containerId:y,blockIndex:R}])),c=y=>l(y).join(" ").replace(/\n/g," ").trim(),a=new Map,u=new Map;for(let y=0;y<s.colCount;y++){let S=0;for(let I=0;I<s.rowCount;I++){const M=s.getCell({row:I,col:y});let R="";M.virtual||(R=c(M.containerId)),a.set(`${I},${y}`,R),S=Math.max(S,H4(R))}u.set(y,S)}const f=y=>{const S=a.get(`${y.row},${y.col}`)||"",I=u.get(y.col)||0;return oS(S,I)},m=[];let C="|",k="|";for(let y=0;y<s.colCount;y++){const S=f({row:0,col:y});C+=` ${S} |`;const I="-".repeat((u.get(y)||0)+2);k+=`${I}|`}m.push(C),m.push(k);for(let y=1;y<s.rowCount;y++){let S="|";for(let I=0;I<s.colCount;I++){const M=f({row:y,col:I});S+=` ${M} |`}m.push(S)}return`${m.join(`
368
368
  `)}
369
369
  `}if(o==="html"){const l=a=>e.blocks[a].map((m,C)=>su(n,m,e,[...r,{containerId:a,blockIndex:C}])).join(`
370
370
  `),c=[];c.push("<table>");for(let a=0;a<s.rowCount;a++){let u="<tr>";for(let f=0;f<s.colCount;f++){const m=s.getCell({row:a,col:f});if(m.virtual)u+="<td></td>";else{const C=l(m.containerId);u+=`<td colSpan="${m.colSpan}" rowSpan="${m.rowSpan}">${C}</td>`}}u+="</tr>",c.push(u)}return c.push("</table>"),c.join(`
371
- `)}return""}const Os=B("table-block");function iS(n){return 1}function sS(n){return!!n.closest(`.${Sh}`)}function lS(n,t,e,o){const r=document.elementsFromPoint(e,o)[0];if(!r||!t.contains(r)||!n.contains(t))return null;let i=r;if(sS(r)&&(i=r.closest("td"),d(Os,i instanceof HTMLTableCellElement,"invalid element")),i instanceof HTMLTableCellElement){const c=jt(t);if(p5(c).indexOf(i)!==-1){const u=ys(i),f=wt(t,U(u));return new Xe(n,{anchor:f,focus:f})}}if(!bn(r))return null;const s=r;if(O4(t).indexOf(s)===-1)return null;const l=wt(t,U(s));return new Xe(n,{anchor:l,focus:l})}function cS(n,t,e,o){return null}function aS(n,t){return n.getBoundingClientRect()}function F4(n,t,e,o){if(e.isSimple()){d(Os,o.isSimple(),"from is simple position but to is not simple position"),Os.debug("full select table"),A(t,"full-selected");return}d(Os,!o.isSimple(),"from is complex position but end is simple position");const r=Gn(n,t,e),i=Gn(n,t,o);d(Os,r.blockId===i.blockId,"only allow update one table selection"),aE(n,r,i).forEach(l=>{const c=f1(l);A(c,"selected")})}function dS(n){n.rootContainer.querySelectorAll('[data-type="editor-block"][data-block-type="table"]').forEach(t=>{z(t,"full-selected"),t.querySelectorAll("td.selected").forEach(e=>{z(e,"selected")})})}function uS(n,t){return C5(t)?O4(t):[]}function hS(n,t,e,o,r){return m1(t,e,o,r)}function fS(n,t){return JT(n,t)}function mS(n,t){return P(n,t)?HT(n,n.getBlockString(t).trim()):null}function gS(n){return{name:"TableBlock",insertBlockCommandItems:[{id:"insert-table",name:T.t("table.title"),order:200,icon:eB,children:[eS()],group:"common",subText:me("insert-table")}],handleInsertEmptyBlock:XT}}function pS(n,t,e){return jT(n,t,e),setTimeout(()=>{const o=n.selection.range;o.isSimple()?n.selection.caret.update():F4(n,t,o.start,o.end)}),!0}function CS(n,t){let e=0;const{selectedColumns:o}=kh(n,t);if(o.size>0){const{fromCol:i,toCol:s}=an(t,n.selection.range.start,n.selection.range.end),l=et.fromBlock(t);(i!==0||s!==l.colCount-1)&&(e=60)}const r=j4(n,t,n.selection.range)[0];return new DOMRect(r.left,r.top+e,r.width,r.height-e)}function bS(n,t){Dw(n,Ah);const e=n.findCustom(wo(t));if(e){const o=N4(n);e.off("scroll",o.handleScroll),e.destroy()}}function kS(){return{abstract:`[${T.t("table.abstract")}]`}}const _s={blockType:"table",blockKind:"complex",enableKeyboardSelect:!0,createBlockContent:PT,getBlockTextLength:iS,getRangeFromPoint:lS,moveCaret:cS,getCaretRect:aS,updateSelection:F4,clearSelection:dS,getChildContainers:uS,getNextContainer:hS,getMinWidth:fS,getSelectedContainers:Lh,convertFrom:mS,convertTo:rS,adjustSelectionPos:ZT,getClientRects:j4,selectionToDoc:zT,getOptions:gS,getTextToolbarReferenceClient:CS,handleUpdateBlock:pS,handleDeleteBlock:bS,getBlockProperties:kS},vS={table:{cellBackground:"\u5355\u5143\u683C\u80CC\u666F\u8272",deleteSelectRow:"\u5220\u9664\u6240\u9009\u884C",deleteSelectCol:"\u5220\u9664\u6240\u9009\u5217",mergeCell:"\u5408\u5E76\u5355\u5143\u683C",splitCell:"\u62C6\u5206\u5355\u5143\u683C",tableConfigKey:"\u8868\u683C\u8BBE\u7F6E",deleteTable:"\u5220\u9664\u8868\u683C",insertCol:"\u63D2\u5165\u5217",insertRow:"\u63D2\u5165\u884C",deleteCol:"\u5220\u9664\u5217",deleteRow:"\u5220\u9664\u884C",tableConfig:{rowTitle:"\u884C\u6807\u9898",colTitle:"\u5217\u6807\u9898",stripeStyle:"\u6761\u7EB9\u6837\u5F0F",hideBorder:"\u9690\u85CF\u8868\u683C\u7EBF",showBorder:"\u663E\u793A\u8868\u683C\u7EBF",showChart:"\u663E\u793A\u56FE\u8868",hideChart:"\u9690\u85CF\u56FE\u8868"},title:"\u8868\u683C",abstract:"\u8868\u683C"}},yS={table:{cellBackground:"Cell background",deleteSelectRow:"Delete rows",deleteSelectCol:"Delete columns",mergeCell:"Merge cells",splitCell:"Split cell",tableConfigKey:"Table setting",deleteTable:"Delete table",insertCol:"Insert column",insertRow:"Insert row",deleteCol:"Delete column",deleteRow:"Delete row",tableConfig:{rowTitle:"Row Title",colTitle:"Col Title",stripeStyle:"Stripe style",hideBorder:"Hide border",showBorder:"Show border",showChart:"Show chart",hideChart:"Hide chart"},title:"Table",abstract:"Table"}};T.mergeLang({"zh-CN":vS,"en-US":yS});const Dz="",z4=B("table");function U4(n,t){const e=bh(t);if(!e)return;const o=F(e);d(z4,o&&Ht(o),"not a table block");const r=m1(o,e,"ArrowRight");if(!r){const s=dt(o);return s?(n.selection.selectBlock(s,0),!0):U4(n,o)}const i=Ut(r);return n.selection.selectBlock(i,0),!0}function wS(n){if(!n.isWritable())return!1;const t=n.getFocusedBlock();if(!!t)return U4(n,t)}function V4(n,t){const e=bh(t);if(!e)return;const o=F(e);d(z4,o&&Ht(o),"not a table block");const r=m1(o,e,"ArrowLeft");if(!r){const s=gt(o);return s?(n.selection.selectBlock(s,W(n,s)),!0):V4(n,o)}const i=Qt(r);return n.selection.selectBlock(i,W(n,i)),!0}function BS(n){if(!n.isWritable())return!1;const t=n.getFocusedBlock();if(!!t)return V4(n,t)}const g1={Tab:wS,"Shift+Tab":BS},ES=`<svg width="24" height="25" viewBox="0 0 24 25" fill="none" xmlns="http://www.w3.org/2000/svg">
371
+ `)}return""}const Os=B("table-block");function iS(n){return 1}function sS(n){return!!n.closest(`.${Sh}`)}function lS(n,t,e,o){const r=document.elementsFromPoint(e,o)[0];if(!r||!t.contains(r)||!n.contains(t))return null;let i=r;if(sS(r)&&(i=r.closest("td"),d(Os,i instanceof HTMLTableCellElement,"invalid element")),i instanceof HTMLTableCellElement){const c=jt(t);if(p5(c).indexOf(i)!==-1){const u=ys(i),f=wt(t,U(u));return new Xe(n,{anchor:f,focus:f})}}if(!bn(r))return null;const s=r;if(O4(t).indexOf(s)===-1)return null;const l=wt(t,U(s));return new Xe(n,{anchor:l,focus:l})}function cS(n,t,e,o){return null}function aS(n,t){return n.getBoundingClientRect()}function F4(n,t,e,o){if(e.isSimple()){d(Os,o.isSimple(),"from is simple position but to is not simple position"),Os.debug("full select table"),A(t,"full-selected");return}d(Os,!o.isSimple(),"from is complex position but end is simple position");const r=Gn(n,t,e),i=Gn(n,t,o);d(Os,r.blockId===i.blockId,"only allow update one table selection"),aE(n,r,i).forEach(l=>{const c=f1(l);A(c,"selected")})}function dS(n){n.rootContainer.querySelectorAll('[data-type="editor-block"][data-block-type="table"]').forEach(t=>{z(t,"full-selected"),t.querySelectorAll("td.selected").forEach(e=>{z(e,"selected")})})}function uS(n,t){return C5(t)?O4(t):[]}function hS(n,t,e,o,r){return m1(t,e,o,r)}function fS(n,t){return JT(n,t)}function mS(n,t){return P(n,t)?HT(n,n.getBlockString(t).trim()):null}function gS(n){return{name:"TableBlock",insertBlockCommandItems:[{id:"insert-table",name:T.t("table.title"),order:200,icon:eB,children:[eS()],group:"common",subText:me("insert-table")}],handleInsertEmptyBlock:XT}}function pS(n,t,e){return jT(n,t,e),setTimeout(()=>{const o=n.selection.range;o.isSimple()?n.selection.caret.update():F4(n,t,o.start,o.end)}),!0}function CS(n,t){let e=0;const{selectedColumns:o}=kh(n,t);if(o.size>0){const{fromCol:i,toCol:s}=an(t,n.selection.range.start,n.selection.range.end),l=et.fromBlock(t);(i!==0||s!==l.colCount-1)&&(e=60)}const r=j4(n,t,n.selection.range)[0];return new DOMRect(r.left,r.top+e,r.width,r.height-e)}function bS(n,t){Dw(n,Ah);const e=n.findCustom(Bo(t));if(e){const o=N4(n);e.off("scroll",o.handleScroll),e.destroy()}}function kS(){return{abstract:`[${T.t("table.abstract")}]`}}const _s={blockType:"table",blockKind:"complex",enableKeyboardSelect:!0,createBlockContent:PT,getBlockTextLength:iS,getRangeFromPoint:lS,moveCaret:cS,getCaretRect:aS,updateSelection:F4,clearSelection:dS,getChildContainers:uS,getNextContainer:hS,getMinWidth:fS,getSelectedContainers:Lh,convertFrom:mS,convertTo:rS,adjustSelectionPos:ZT,getClientRects:j4,selectionToDoc:zT,getOptions:gS,getTextToolbarReferenceClient:CS,handleUpdateBlock:pS,handleDeleteBlock:bS,getBlockProperties:kS},vS={table:{cellBackground:"\u5355\u5143\u683C\u80CC\u666F\u8272",deleteSelectRow:"\u5220\u9664\u6240\u9009\u884C",deleteSelectCol:"\u5220\u9664\u6240\u9009\u5217",mergeCell:"\u5408\u5E76\u5355\u5143\u683C",splitCell:"\u62C6\u5206\u5355\u5143\u683C",tableConfigKey:"\u8868\u683C\u8BBE\u7F6E",deleteTable:"\u5220\u9664\u8868\u683C",insertCol:"\u63D2\u5165\u5217",insertRow:"\u63D2\u5165\u884C",deleteCol:"\u5220\u9664\u5217",deleteRow:"\u5220\u9664\u884C",tableConfig:{rowTitle:"\u884C\u6807\u9898",colTitle:"\u5217\u6807\u9898",stripeStyle:"\u6761\u7EB9\u6837\u5F0F",hideBorder:"\u9690\u85CF\u8868\u683C\u7EBF",showBorder:"\u663E\u793A\u8868\u683C\u7EBF",showChart:"\u663E\u793A\u56FE\u8868",hideChart:"\u9690\u85CF\u56FE\u8868"},title:"\u8868\u683C",abstract:"\u8868\u683C"}},yS={table:{cellBackground:"Cell background",deleteSelectRow:"Delete rows",deleteSelectCol:"Delete columns",mergeCell:"Merge cells",splitCell:"Split cell",tableConfigKey:"Table setting",deleteTable:"Delete table",insertCol:"Insert column",insertRow:"Insert row",deleteCol:"Delete column",deleteRow:"Delete row",tableConfig:{rowTitle:"Row Title",colTitle:"Col Title",stripeStyle:"Stripe style",hideBorder:"Hide border",showBorder:"Show border",showChart:"Show chart",hideChart:"Hide chart"},title:"Table",abstract:"Table"}};T.mergeLang({"zh-CN":vS,"en-US":yS});const Dz="",z4=B("table");function U4(n,t){const e=bh(t);if(!e)return;const o=F(e);d(z4,o&&Ht(o),"not a table block");const r=m1(o,e,"ArrowRight");if(!r){const s=dt(o);return s?(n.selection.selectBlock(s,0),!0):U4(n,o)}const i=Ut(r);return n.selection.selectBlock(i,0),!0}function wS(n){if(!n.isWritable())return!1;const t=n.getFocusedBlock();if(!!t)return U4(n,t)}function V4(n,t){const e=bh(t);if(!e)return;const o=F(e);d(z4,o&&Ht(o),"not a table block");const r=m1(o,e,"ArrowLeft");if(!r){const s=gt(o);return s?(n.selection.selectBlock(s,W(n,s)),!0):V4(n,o)}const i=Qt(r);return n.selection.selectBlock(i,W(n,i)),!0}function BS(n){if(!n.isWritable())return!1;const t=n.getFocusedBlock();if(!!t)return V4(n,t)}const g1={Tab:wS,"Shift+Tab":BS},ES=`<svg width="24" height="25" viewBox="0 0 24 25" fill="none" xmlns="http://www.w3.org/2000/svg">
372
372
  <g>
373
373
  <path fill-rule="evenodd" clip-rule="evenodd" d="M12 7.61719C11.4477 7.61719 11 7.16947 11 6.61719V3.61719C11 3.0649 11.4477 2.61719 12 2.61719C12.5523 2.61719 13 3.0649 13 3.61719V6.61719C13 7.16947 12.5523 7.61719 12 7.61719ZM4.92893 5.54612C5.31946 5.15559 5.95262 5.1556 6.34315 5.54612L8.46447 7.66744C8.85499 8.05796 8.85499 8.69113 8.46447 9.08165C8.07394 9.47218 7.44078 9.47218 7.05025 9.08165L4.92893 6.96033C4.53841 6.56981 4.53841 5.93664 4.92893 5.54612ZM15.5355 9.08165C15.145 8.69113 15.145 8.05796 15.5355 7.66744L17.6569 5.54612C18.0474 5.1556 18.6805 5.1556 19.0711 5.54612C19.4616 5.93664 19.4616 6.56981 19.0711 6.96033L16.9497 9.08165C16.5592 9.47218 15.9261 9.47218 15.5355 9.08165ZM2 12.6172C2 12.0649 2.44772 11.6172 3 11.6172L6 11.6172C6.55229 11.6172 7 12.0649 7 12.6172C7 13.1695 6.55228 13.6172 6 13.6172L3 13.6172C2.44772 13.6172 2 13.1695 2 12.6172ZM17 12.6172C17 12.0649 17.4477 11.6172 18 11.6172L21 11.6172C21.5523 11.6172 22 12.0649 22 12.6172C22 13.1695 21.5523 13.6172 21 13.6172L18 13.6172C17.4477 13.6172 17 13.1695 17 12.6172ZM15.5355 16.1527C15.9261 15.7622 16.5592 15.7622 16.9497 16.1527L19.0711 18.274C19.4616 18.6646 19.4616 19.2977 19.0711 19.6883C18.6805 20.0788 18.0474 20.0788 17.6569 19.6883L15.5355 17.5669C15.145 17.1764 15.145 16.5432 15.5355 16.1527ZM4.92893 19.6883C4.53841 19.2977 4.53841 18.6646 4.92893 18.274L7.05025 16.1527C7.44078 15.7622 8.07394 15.7622 8.46447 16.1527C8.85499 16.5432 8.85499 17.1764 8.46447 17.5669L6.34315 19.6883C5.95262 20.0788 5.31946 20.0788 4.92893 19.6883ZM12 22.6172C11.4477 22.6172 11 22.1695 11 21.6172V18.6172C11 18.0649 11.4477 17.6172 12 17.6172C12.5523 17.6172 13 18.0649 13 18.6172V21.6172C13 22.1695 12.5523 22.6172 12 22.6172Z" fill="#5587F0"/>
374
374
  <animateTransform attributeType="xml" attributeName="transform" type="rotate" values="0 12 12.5;360 12 12.5" dur="2s" repeatCount="indefinite" />
375
375
  </g>
376
- </svg>`,p1=B("webpage");class IS{constructor(t,e){h(this,"currentSrc","");h(this,"loading",null);h(this,"handleMaskMouseMove",(t,e)=>{if(!window.isDragging){if(e.target&&e.target instanceof Element){const o=e.target.closest("webpage-mask");o&&(o.style.display="none")}t.domEvents.addEventListener(document,"mousemove",this.handleDocumentMouseMove)}});h(this,"handleDocumentMouseMove",(t,e)=>{if(!e.target||!(e.target instanceof Element))return;const o=this.editor.findBlockById(this.blockData.id);if(o){const r=this.getExistsMask(o);if(r){if(It(o,e.target)){r.style.display="none";return}r.style.display=""}}});this.editor=t,this.blockData=e}create(t,e,o,r){const i=e.src,s=b("div",["editor-embed"],null),l=b("iframe",["editor-preview-iframe"],s);this.loading=this.createLoading(s);const c=()=>{d(p1,this.loading,"not created"),this.loading.hide(),this.currentSrc=i};t.domEvents.addEventListener(l,"load",c),l.src=i,this.loading.show(),o.append(s),this.createMask(t,r)}update(t,e,o){if(d(p1,this.loading,"not created"),this.currentSrc===o.src)return;const r=e.querySelector(".editor-preview-iframe");d(p1,r,"no exists iframe"),this.loading.show(),r.src=o.src,this.createMask(t,e)}createLoading(t){const e=b("div",["editor-preview-iframe-loading"],null),o=b("span",[],e);return o.innerHTML=ES,{show(){t.append(e)},hide(){const r=t.querySelector(":scope > .editor-preview-iframe-loading");!r||r.remove()}}}getExistsMask(t){return Rt(t).querySelector(".webpage-mask")}createMask(t,e){const o=Rt(e);let r=this.getExistsMask(e);if(r){r.style.display="";return}r=b("div",["webpage-mask"],o),t.domEvents.addEventListener(r,"mousemove",this.handleMaskMouseMove)}destroy(){const t=this.editor.findBlockById(this.blockData.id);if(t){const e=this.getExistsMask(t);e&&(this.editor.domEvents.removeEventListener(e,"mousemove",this.handleMaskMouseMove),this.editor.domEvents.removeEventListener(document,"mousemove",this.handleDocumentMouseMove))}}}function xS(n,t){b("div",["resize-gripper",t],n).setAttribute("data-resize-type",t)}function C1(n){return Rt(n).querySelector(".block-resizer")}function TS(n){const t=C1(n);t&&z(t,"active")}function q4(n,t,e){const o=n.getBoundingClientRect(),r=t.getBoundingClientRect(),i=r.top-o.top,s=r.left-o.left,l=r.width,c=r.height;e.style.top=`${i}px`,e.style.left=`${s}px`,e.style.width=`${l}px`,e.style.height=`${c}px`}function SS(n,t,e,o){const r=C1(n);if(r)return A(r,"active"),q4(n,t,r),r;const i=Rt(n),s=b("div",["block-resizer"],i);return q4(n,t,s),e.resize.forEach(l=>{xS(s,l)}),s.addEventListener("mousedown",o),A(s,"active"),s}function W4(n,t){const e=C1(n);if(!e)return;const o=n.getBoundingClientRect(),r=t.getBoundingClientRect(),i=r.top-o.top,s=r.left-o.left,l=r.width,c=r.height;e.style.top=`${i}px`,e.style.left=`${s}px`,e.style.width=`${l}px`,e.style.height=`${c}px`}const Lz="",DS=B("block-resizer");class ta extends Yt.TypedEmitter{constructor(e,o){super();h(this,"resizableElement");h(this,"block",null);h(this,"startRect",null);h(this,"startPos",null);h(this,"resizeType",null);h(this,"enabled",!1);h(this,"handleMouseDown",e=>{e.preventDefault(),e.stopPropagation();const o=this.getResizableElement();if(!o||e.button!==0)return;const r=e.target;if(!r||!(r instanceof HTMLElement))return;const i=r.getAttribute("data-resize-type");!i||(this.bindEvents(),this.startRect=o.getBoundingClientRect(),this.startPos=e,this.resizeType=i,Ai(window.getComputedStyle(r).cursor),this.block&&this.editor.selection.selectBlock(this.block,0))});h(this,"handleMouseMove",e=>{if(!this.startPos||!this.startRect||!this.resizeType)return;const o=this.getResizableElement();if(!o||!this.block)return;const r=e.x-this.startPos.x,i=e.y-this.startPos.y,s=this.startRect;let{top:l,left:c,right:a,bottom:u}=s;(this.resizeType==="bottom"||this.resizeType==="bottom-left"||this.resizeType==="bottom-right")&&(u+=i),(this.resizeType==="top"||this.resizeType==="top-left"||this.resizeType==="top-right")&&(l+=i),(this.resizeType==="left"||this.resizeType==="top-left"||this.resizeType==="bottom-left")&&(c+=r),(this.resizeType==="right"||this.resizeType==="top-right"||this.resizeType==="bottom-right")&&(a+=r);const f=a>c?a-c:0,m=u>l?u-l:0,C=new DOMRect(c,l,f,m);this.emit("resizing",this,C),W4(this.block,o)});h(this,"handleMouseUp",e=>{if(e.button!==0)return;Ai(""),this.unbindEvents(),this.emit("resized",this);const o=this.getResizableElement();!o||!this.block||W4(this.block,o)});this.editor=e,this.options=o}enableResize(e,o){this.block=e,this.resizableElement=o,this.createResizer(),this.enabled=!0}disableResize(){!this.block||(TS(this.block),this.enabled=!1)}update(e,o){this.block=e,this.resizableElement=o,this.getResizableElement()&&this.enabled&&this.createResizer()}getBlock(){return this.block}destroy(){}getResizableElement(){return this.resizableElement?this.resizableElement:this.block?it(this.block):null}createResizer(){const e=this.getResizableElement();!e||!this.block||(d(DS,It(this.block,e),"not a block child element"),SS(this.block,e,this.options,this.handleMouseDown))}bindEvents(){document.addEventListener("mousemove",this.handleMouseMove),document.addEventListener("mouseup",this.handleMouseUp)}unbindEvents(){document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp)}}function G4(n){return n&&Te(n)&&Oe(n)==="webpage"}const LS=1e3,MS=100;class RS{constructor(t){h(this,"currentBlockElement",null);h(this,"resizing",!1);h(this,"handleHoveringBlockChange",(t,e)=>{this.resizing||!this.editor.isWritable()||(e&&G4(e)&&this.disableBlockResize(e),t&&G4(t)&&this.enableBlockResize(t))});h(this,"handleResizing",(t,e)=>{this.resizing=!0;const o=t.getBlock();if(!o)return;const r=Math.max(Math.min(e.height,LS),MS);o.style.height=`${r}px`,A(o,"resizing")});h(this,"handleResized",t=>{this.resizing=!1;const e=t.getBlock();if(!e)return;z(e,"resizing");const o=this.editor.getBlockData(e),r=e.getBoundingClientRect().height;this.editor.updateBlockData(e,{...o,height:r})});this.editor=t,Nt.get(t).addListener("change",this.handleHoveringBlockChange)}destroy(){this.currentBlockElement=null,Nt.get(this.editor).removeListener("change",this.handleHoveringBlockChange)}disableBlockResize(t){const e=this.editor.findCustom(`${q(t)}-resizer`);e&&e.disableResize()}enableBlockResize(t){const e=this.editor.addCustom(`${q(t)}-resizer`,()=>new ta(this.editor,{resize:["bottom"]}));e.enableResize(t),e.removeListener("resizing",this.handleResizing),e.removeListener("resized",this.handleResized),e.addListener("resizing",this.handleResizing),e.addListener("resized",this.handleResized),this.currentBlockElement=t}}const Mz="",AS=B("editor-dialog");function OS(n,t){const e=b("div",["editor-dialog-container"],null),o=b("div",["dialog-header"],e);b("span",["dialog-header-title"],o,t.title);const r=b("span",["close-icon"],o);r.innerHTML=t5,b("div",["dialog-content"],e).appendChild(n);const s=b("div",["dialog-footer"],e);return b("button",["cancel-button"],s,"Cancel"),b("button",["submit-button"],s,"Ok"),e}class _S extends vs{constructor(e,o){super(OS(e,o),o);h(this,"_options");h(this,"getReferenceClientRect",()=>{const e=document.documentElement.clientHeight/2,o=document.documentElement.clientWidth/2,r=this.getCommandBarRoot();d(AS,r,"no command bar root");const{width:i,height:s}=r.getBoundingClientRect();return new DOMRect(Math.max(o-i/2,0),Math.max(e-s/2,0),0,0)});h(this,"handleOk",async()=>{var e,o;try{await((o=(e=this._options).onOk)==null?void 0:o.call(e)),this.destroy()}catch{}});h(this,"handleClose",()=>{var e,o;(o=(e=this._options).onClose)==null||o.call(e),this.destroy()});const r=this.content.querySelector(".submit-button"),i=this.content.querySelector(".cancel-button"),s=this.content.querySelector(".close-icon");r==null||r.addEventListener("click",this.handleOk),s==null||s.addEventListener("click",this.handleClose),i==null||i.addEventListener("click",this.handleClose),this._options=o}show(){super.show(document.documentElement,{getReferenceClientRect:this.getReferenceClientRect})}destroy(){const e=this.content.querySelector(".submit-button"),o=this.content.querySelector(".cancel-button"),r=this.content.querySelector(".close-icon");e==null||e.removeEventListener("click",this.handleOk),o==null||o.removeEventListener("click",this.handleClose),r==null||r.removeEventListener("click",this.handleClose),super.destroy()}}const Z4=()=>[{name:T.t("webpage.bilibili"),id:"insert-bilibili",icon:iB,group:"thirdParty",subText:me("insert-bilibili")},{name:T.t("webpage.youku"),id:"insert-youku",icon:sB,group:"thirdParty",subText:me("insert-youku")},{name:T.t("webpage.figma"),id:"insert-figma",icon:lB,group:"thirdParty",subText:me("insert-figma")},{name:T.t("webpage.modao"),id:"insert-modao",icon:cB,group:"thirdParty",subText:me("insert-modao")},{name:T.t("webpage.tencent"),id:"insert-tencent",icon:aB,group:"thirdParty",subText:me("insert-tencent")},{id:"insert-webPage",name:T.t("webpage.title"),icon:dB,group:"common",order:1e3,subText:me("insert-webPage")}];function b1(n){return n==="insert-webPage"}async function NS(n,t){return n.doc.externalDoc.recognizeLink?n.doc.externalDoc.recognizeLink(t):null}function $S(n){return n&&!n.startsWith("http://")&&!n.startsWith("https://")&&!n.startsWith("//")?`//${n}`:n}async function PS(n){if(!n)throw new Error(T.t("webpage.dialog.errorEnterUrl"));let t=n;t.startsWith("//")&&(t=`http:${t}`);try{new URL(t)}catch{throw new Error(T.t("webpage.dialog.unsupportedUrl"))}}async function jS(n,t){const e=t.item.id,o=Z4().find(a=>a.id===e),r=b("div",["webpage-content"],null);if(b1(e)){const a=b("div",["help-container"],r),u=b("div",["help-content"],a),f=b("span",["help-icon"],u);f.innerHTML=r5,b("span",[],u,T.t("webpage.dialog.helpContent"))}const{getInputValue:i,setFieldError:s,focus:l,getField:c}=mh(r,{required:!0,label:T.t("webpage.dialog.label"),placeholder:T.t("webpage.dialog.placeholder")});if(!b1(e)){const a=b("div",["help-link-container"],r),u=b("a",["help-link-content"],a);b("span",[],u,T.t("webpage.dialog.helpLink"));const f=b("span",["help-link-icon"],u);f.innerHTML=s5;const m=n.getComponentOptions("webpage");u.href=(m==null?void 0:m.helpLink)||"",u.target="_blank"}try{const a=await new Promise((m,C)=>{const k=new _S(r,{title:T.t("webpage.dialog.title",{name:(o==null?void 0:o.name)||""}),async onOk(){var S;const y=$S(i());try{await PS(y);const I=await NS(n,y);m((I==null?void 0:I.url)||"")}catch(I){if(((S=I==null?void 0:I.responseData)==null?void 0:S.statusCode)===415)if(b1(e))m(y);else throw s(T.t("webpage.dialog.unsupportedUrl")),I;else throw s(I.message||""),I}},onClose(){n.focus(),C()}});k.addListener("show",l),k.show(),c().addEventListener("keydown",async y=>{if(!y.isComposing){if(y.key==="Enter"){await k.handleOk(),y.preventDefault();return}y.key==="Escape"&&k.handleClose()}})}),u={id:N(),type:"embed",embedType:"webpage",embedData:{src:a}},f=n.insertBlock(t.containerId,t.blockIndex,u);return n.focus(),f}catch{return null}}const Y4=B("embed-block-properties");function k1(n,t){var e;for(const o of n.blockHooks){const r=(e=o.commands)==null?void 0:e.call(o,n,t);if(!!r&&r.group==="block-comment-actions")return r.executeCommand(n,t,r.commands[0]),!0}return!1}class v1{constructor(t,e){h(this,"group","hovering-toolbar");h(this,"_commands",[{id:"edit",name:"Edit",icon:hh},{id:"add-comment",name:"Add Comment",icon:wc}]);this.editor=t,this.properties=e}get commands(){var e,o,r;if(!this.editor.isWritable())return[];const t=(e=this.properties)!=null&&e.presetIds?this._commands.filter(i=>{var s,l;return(l=(s=this.properties)==null?void 0:s.presetIds)==null?void 0:l.includes(i.id)}):[...this._commands];return(r=(o=this.properties)==null?void 0:o.extCommands)!=null&&r.length&&(t.push({id:N(),type:"separator",name:""}),t.push(...this.properties.extCommands)),t}executeCommand(t,e,o){var r,i;if(!((i=(r=this.properties)==null?void 0:r.handleExecuteCommand)!=null&&i.call(r,t,e,o))){if(o.id==="add-comment"){k1(t,e)||Y4.error("failed to add comment to block");return}Y4.error(`unknown command: ${JSON.stringify(o)}`)}}}function y1(n,t,e){return{blockCommands:{"hovering-toolbar":new v1(n,e)}}}function HS(n){const t=n.querySelector(".editor-preview-iframe"),e=t.src;t.src="about:blank";const o=setTimeout(()=>{t.src=e,clearTimeout(o)},300);return!0}function FS(n,t){const e=n.getBlockData(t),{embedData:o}=e,r=o.src;return window.open(r,"_blank"),!0}function zS(n,t){const e=y1(n,t,{presetIds:["add-comment"],extCommands:[{id:"refresh",name:"Refresh page",icon:nB},{id:"open-page",name:"Open the original page",icon:s5}],handleExecuteCommand:(r,i,s)=>{switch(s.id){case"refresh":return HS(i);case"open-page":return FS(r,i)}return!1}}),o=`[${T.t("webpage.abstract")}]`;return{...e,abstract:o}}const US=B("webpage-embed");function VS(n,t,e,o,r,i){const{embedData:s,id:l}=e,{src:c}=s,a=n.addCustom(`webpage-${l}`,()=>new IS(n,e));d(US,c,"The src from blockData is invalid "),a.create(n,s,t,i),n.addCustom("webpage-resizer",()=>new RS(n)),e.height&&(i.style.height=`${e.height}px`)}function qS(n,t,e){const{embedData:o,id:r}=e;return n.getCustom(`webpage-${r}`).update(n,t,o),e.height&&(t.style.height=`${e.height}px`),!0}function WS(){return{name:"WebPage",insertEmbedCommandItems:Z4(),handleInsertEmptyEmbed:jS}}function GS(n,t,e,o){const i=t.embedData.src;return o==="html"?`<iframe src="${i}" ></iframe>`:o==="markdown"?`[${i}](${i})`:i}const w1={embedType:"webpage",createEmbedContent:VS,getBlockProperties:zS,getOptions:WS,handleUpdateBlock:qS,convertTo:GS},ZS={webpage:{title:"\u7F51\u9875",youku:"\u4F18\u9177\u89C6\u9891",modao:"\u58A8\u5200",tencent:"\u817E\u8BAF\u89C6\u9891",bilibili:"Bilibili",figma:"Figma",dialog:{helpContent:"\u56E0\u76EE\u6807\u7F51\u9875\u7684\u9650\u5236\uFF0C\u90E8\u5206\u7F51\u9875\u53EF\u80FD\u65E0\u6CD5\u6210\u529F\u9884\u89C8\u3002",helpLink:"\u5982\u4F55\u83B7\u53D6\u94FE\u63A5",label:"\u7F51\u9875\u5730\u5740",placeholder:"\u8BF7\u8F93\u5165",title:"\u63D2\u5165{name}",errorEnterUrl:"\u8BF7\u8F93\u5165\u7F51\u9875\u5730\u5740",unsupportedUrl:"\u6682\u4E0D\u652F\u6301\u63D2\u5165\u8BE5\u94FE\u63A5\u5185\u5BB9"},abstract:"\u7F51\u9875"}},YS={webpage:{title:"Webpage",youku:"Youku",modao:"Modao",tencent:"Tencent Video",bilibili:"Bilibili",figma:"Figma",dialog:{helpContent:"Due to the limitation of the landing page, some pages may not be previewed successfully.",helpLink:"How to get the URL link",label:"Please enter webpage address",placeholder:"Please enter url",title:"Insert {name}",errorEnterUrl:"Please enter the webpage address",unsupportedUrl:"Unsupported url"},abstract:"Webpage"}};T.mergeLang({"zh-CN":ZS,"en-US":YS});const Rz="";function QS(n,t,e,o){var f;const r=n.getBlockByIndex(t,e);if(W(n,r)!==o)return!1;const i=bt(n.getBlockText(r));if(![...i].every(m=>m==="|")||i.length<3||!n.editorBlocks.hasBlock("table"))return!1;const s=n.editorBlocks.getBlockClass("table");if(!s.convertFrom)return!1;const l=s.convertFrom(n,r,{offset:o});if(!l)return!1;const{blockData:c,focusBlockId:a}=l;if(!c)return!1;const u=n.insertBlock(t,e,c,At(n,a!=null?a:c.id,0));return n.deleteBlock(r),(f=l.onConverted)==null||f.call(l,n,u),!0}const KS={mermaid:{blockType:"embed",reg:/^```mermaid$/,data:{embedType:"mermaid"}},flowchart:{blockType:"embed",reg:/^```flowchart$/,data:{embedType:"flowchart"}},plantuml:{blockType:"embed",reg:/^```plantuml$/,data:{embedType:"plantuml"}},code:{blockType:"code",reg:/^```\S+$/},code2:{blockType:"code",reg:/^```$/},table:{blockType:"table",reg:/^\|.+\|.+\|$/},math:{blockType:"embed",reg:/^\$\$.+\$\$$/},image:{blockType:"embed",reg:/^!\[[^\]]*\]\((?<filename>.*?)(?="|\))(?<optionalPart>".*")?\)/,data:{embedType:"image"}},dividing:{blockType:"embed",reg:/^-{3,}$/,data:{embedType:"dividing-line"}},toc:{blockType:"embed",reg:/^\[toc\]/,data:{embedType:"toc"}}},JS={orderedList:{reg:/^(\d)+(\.|。)$/,blockType:"list",data:{listType:"ordered"}},unorderedList1:{reg:/^\*$/,blockType:"list",data:{listType:"unordered"}},unorderedList2:{reg:/^-$/,blockType:"list",data:{listType:"unordered"}},checkList1:{reg:/^\[\s?\]$/,blockType:"list",data:{listType:"unchecked"}},checkList2:{reg:/^\[X\]$/i,blockType:"list",data:{listType:"checked"}},image:{blockType:"embed",reg:/^!\[[^\]]*\]\((?<filename>.*?)(?="|\))(?<optionalPart>".*")?\)/,data:{embedType:"image"}}};function Q4(n,t,e,o,r){if(r==="enter"&&QS(n,t,e,o))return!0;const i=n.getBlockByIndex(t,e),s=bt(be(n.getBlockText(i),o).left).trim(),l=r==="enter"?KS:JS;for(const[,c]of Object.entries(l)){if(!s.match(c.reg))continue;return!!n.undoManager.runInGroup(()=>{var k;const u=Ml(n,i,c.blockType,{offset:o,data:c.data});if(!u)return null;const{blockData:f,focusBlockId:m}=u;if(!f)return null;const C=n.insertBlock(t,e,f,At(n,m!=null?m:f.id,0));return n.deleteBlock(i),(k=u.onConverted)==null||k.call(u,n,C),{newBlock:C,focusBlockId:m}})}return!1}function XS(n,t,e,o){const r=n.getBlockByIndex(t,e);return n.getBlockString(r,{boxReplacement:" "}).substring(0,o)!==">"?!1:(n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,0,o+1),n.updateBlockData(r,{quoted:!0},At(n,r,0))}),!0)}const tD={"#":1,"##":2,"###":3,"####":4,"#####":5,"######":6,"#######":7,"########":8};function eD(n,t,e,o){const r=n.getBlockByIndex(t,e),i=n.getBlockString(r,{boxReplacement:" "}).substring(0,o);let s=tD[i];if(!s)return!1;const l=n.getBlockData(r).heading;return l&&l==s&&(s=null),n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,0,o+1),n.updateBlockData(r,{heading:s},At(n,r,0))}),!0}function nD(n,t,e,o){return!!(eD(n,t,e,o)||XS(n,t,e,o))}const oD=B("match-text-style");function rD(n){let t="";for(let e=n.length-1;e>=0;e--){const o=n[e];if(!o.attributes||Object.keys(o.attributes).length===0){t+=o.insert;continue}break}return t}function iD(n,t){if(n.length<t.length*2+1||!n.endsWith(t)||n.substring(0,n.length-1).endsWith(t))return-1;const e=n.substring(0,n.length-t.length),o=e.lastIndexOf(t);return o===-1?-1:o===0?0:e.substring(o-1).startsWith(t)?-1:o}const sD={"*":{type:"style",styles:["style-italic"],boxType:""},"**":{type:"style",styles:["style-bold"],boxType:""},"***":{type:"style",styles:["style-bold","style-italic"],boxType:""},"~~":{type:"style",styles:["style-strikethrough"],boxType:""},"`":{type:"style",styles:["style-code"],boxType:""},$$:{type:"box",styles:[],boxType:"math"}};function lD(n,t,e,o){var u,f;const r=n.getBlockByIndex(t,e),i=n.getBlockText(r),{left:s}=be(i,o),l=rD(s),c=ue(s)-l.length,a=Object.entries(sD);for(const[m,C]of a){const k=iD(l,m);if(k===-1)continue;const w=c+k,y=o,S=m.length,I=bt(Wt(i,w+S,y-w-S*2).middle);if(C.type==="style"){const M={};C.styles.forEach($=>{M[$]=!0});const R=Qo(I,M);n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,w,y-w),n.insertTextToBlock(r,w,R)})}else if(C.type==="box")try{const M=(f=(u=n.editorBoxes.getBoxClass(C.boxType)).convertFrom)==null?void 0:f.call(u,n,I);if(!M)continue;n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,w,y-w),n.insertBoxToBlock(r,w,M)})}catch(M){oD.warn(`failed to convert to box, ${M.message}`);continue}return!0}return!1}class ea{handleAfterInsertText(t,e,o,r,i){return!!(i===" "&&(nD(t,e,o,r)||lD(t,e,o,r)))}handleBeforeKeyDown(t,e){if(!t.selection.range.isSimple())return!1;const{containerId:r,blockIndex:i,offset:s}=t.getTextPosition();if(P(t,t.getBlockByIndex(r,i))){if(jn(e,"Enter")){if(Q4(t,r,i,s,"enter"))return!0}else if(jn(e,"Space")&&Q4(t,r,i,s,"space"))return!0}return!1}}const cD={"en-US":{placeholder:{default:"Type \u2018/\u2019 for commands",heading:"Heading {heading}",list:"List",mention:"Quickly assign tasks @mention yourself or others",quote:"Quote",title:"Enter document title"}},"zh-CN":{placeholder:{default:"\u8F93\u5165\u300C/\u300D\u5FEB\u901F\u63D2\u5165",heading:"\u6807\u9898{heading}",list:"\u5217\u8868",mention:"\u5FEB\u901F\u5206\u914D\u4EFB\u52A1\uFF0C@\u63D0\u53CA\u81EA\u5DF1\u6216\u4ED6\u4EBA",quote:"\u5F15\u7528",title:"\u8BF7\u8F93\u5165\u6587\u6863\u6807\u9898"}}};T.mergeLang(cD);function Ns(n,t){const e=fo(n,t);return!!(e.text&&ue(e.text)===0&&!t.querySelector(".inputting-insertion"))}function K4(n,t){var o;it(t).removeAttribute("data-content-placeholder"),(o=t.querySelector("[data-type=block-tools] .block-placeholder-container"))==null||o.remove()}function na(n,t,e){var r;if(!Ns(n,t)){K4(n,t);return}const o=it(t);if(typeof e=="string")o.setAttribute("data-content-placeholder",e);else{const i=Rt(t),s=(r=i.querySelector(".block-placeholder-container"))!=null?r:b("div",["block-placeholder-container"],i);s.innerHTML="",s.appendChild(e)}}function aD(n){const t=n.getAttribute("data-style-heading");return t?T.t("placeholder.heading",{heading:t}):n.getAttribute("data-style-quoted")?T.t("placeholder.quote"):null}function dD(n){const t=n.getAttribute("data-list-type");return t?t==="ordered"||t==="unordered"?T.t("placeholder.list"):T.t("placeholder.mention"):null}function J4(n){switch(ot(n)){case"text":return aD(n);case"list":return dD(n);default:return null}}function uD(n){if(po(n))return!1;const t=F(H(n));return t?ot(t)==="code":!1}function hD(n){if(po(n))return!1;const t=F(H(n));return t?ot(t)==="table":!1}function fD(n,t){var u,f;const e=n.selection.focusedBlock,o=ot(e),r=t.contentPlaceholder||T.t("placeholder.default");let i=r;if(o&&$i(n,o)&&e){if(uD(e))return;hD(e)?i=T.t("placeholder.common.contentInTable"):i=(u=J4(e))!=null?u:i}const s=n.getFirstBlock(),l=dt(s);if(!l)return;const c=dt(l);if(c&&!t.addPlaceholderToAllCurrentEmptyBlock)return;if(!c){Ns(n,l)&&na(n,l,(f=J4(l))!=null?f:r);return}const a=n.getFocusedBlock();!Ns(n,a)||a!==s&&na(n,a,i)}function mD(n,t){var r,i;const e=n.getFirstBlock(),o=it(e);Ns(n,e)?(o.setAttribute("data-title-placeholder",(r=t.titlePlaceholder)!=null?r:T.t("placeholder.title")),o.setAttribute("data-title-placeholder-readonly",(i=t.readonlyTitlePlaceholder)!=null?i:"")):(o.removeAttribute("data-title-placeholder"),o.removeAttribute("data-title-placeholder-readonly"))}function gD(n){n.rootContainer.querySelectorAll("[data-content-placeholder").forEach(t=>{t.removeAttribute("data-content-placeholder")}),n.rootContainer.querySelectorAll("[data-type=block-tools] .block-placeholder-container").forEach(t=>{t.remove()})}function pD(n,t){gD(n),n.selection.range.isCollapsed()&&(mD(n,t),fD(n,t))}const _z="",CD=B("enforce-title");class $s{constructor(t,e={headingLevel:1}){h(this,"handleSelectionChange",t=>{setTimeout(()=>{this.applyPlaceholder(t)})});this.options=e,this.handleChanged(t),this.applyPlaceholder(t),t.addListener("selectionChanged",this.handleSelectionChange)}destroy(t){t.removeListener("selectionChanged",this.handleSelectionChange)}handleBeforeKeyDown(t,e){if(!t.selection.range.isSimple())return!1;const{containerId:r,blockIndex:i,offset:s}=t.getTextPosition();if(!$s.isDocumentTitleBlock(r,i)||!jn(e,"Enter"))return!1;let l=!1,c=null;Ge(t.rootContainer)===2&&(c=yr(t.rootContainer,1),W(t,c)===0&&(l=!0));const a=t.getFirstBlock();return t.undoManager.runInGroup(()=>{t.breakTextBlock(a,s,{forceInsertAfter:!0}),l&&c&&t.deleteBlock(c)}),!0}handleChanged(t){var e;try{const o=t.doc.getContainerBlocks(U(t.rootContainer));d(CD,o.length>0,"root container is empty");const r=o[0];if(r.type!=="text"||r.heading!==this.options.headingLevel){const i=Un("",{heading:(e=this.options.headingLevel)!=null?e:1});t.insertBlock(U(t.rootContainer),0,i);return}if(o.length>1)return;t.insertTextBlock("",U(t.rootContainer),1,{newRange:t.selection.range.toDocRange()})}finally{this.applyPlaceholder(t)}}handleRemoteChanged(t){setTimeout(()=>{this.applyPlaceholder(t)})}handleUpdateCompositionText(t){this.applyPlaceholder(t)}applyPlaceholder(t){var e,o;!((e=this.options)!=null&&e.titlePlaceholder)&&!((o=this.options)!=null&&o.contentPlaceholder)||pD(t,this.options)}static isDocumentTitleBlock(t,e){return t==="root"&&e===0}}const X4=B("code-dom");function xo(n){return ot(n)==="code"}function t6(n,t,e){e.language?t.setAttribute("data-language",e.language):t.removeAttribute("data-language"),e.nowrap?z(t,"wrap"):A(t,"wrap")}function B1(n){const t=n.closest("div[data-type=editor-block][data-block-type=code]");return d(X4,t,"no parent code block"),d(X4,xo(t),"not a code block"),t}const oa={plain:{name:"Plain Text",aliases:["txt","text"]},abap:{name:"ABAP",aliases:["abap"]},arduino:{name:"Arduino",aliases:["ino"]},bash:{name:"Bash",aliases:["sh","shell"]},basic:{name:"BASIC",aliases:["bas"]},c:{name:"C",aliases:["c"]},clojure:{name:"Clojure",aliases:["clj"]},cofeescript:{name:"CoffeeScript",aliases:["coffee"]},cpp:{name:"C++",aliases:["cpp","cxx"]},csharp:{name:"C#",aliases:["cs"]},css:{name:"CSS",aliases:["css"]},dart:{name:"Dart",aliases:["dart"]},diff:{name:"Diff",aliases:["diff","patch"]},docker:{name:"Docker",aliases:["dockerfile"]},elixir:{name:"Elixir",aliases:["ex","exs"]},elm:{name:"Elm",aliases:["elm"]},erlang:{name:"Erlang",aliases:["erl"]},flow:{name:"Flow",aliases:["flow"]},fortran:{name:"Fortran",aliases:["f","for","f77","f90"]},fsharp:{name:"F#",aliases:["fsharp"]},gherkin:{name:"Gherkin",aliases:["feature"]},glsl:{name:"GLSL",aliases:["glsl"]},go:{name:"Go",aliases:["go"]},graphql:{name:"GraphQL",aliases:["graphql"]},groovy:{name:"Groovy",aliases:["groovy"]},haskell:{name:"Haskell",aliases:["hs"]},java:{name:"Java",aliases:["java"]},js:{name:"JavaScript",aliases:["js","jsx"]},json:{name:"JSON",aliases:["json"]},julia:{name:"Julia",aliases:["jl"]},kotlin:{name:"Kotlin",aliases:["kt","ktm","kts"]},latex:{name:"LaTeX",aliases:["tex"]},less:{name:"LESS",aliases:["less"]},lisp:{name:"Lisp",aliases:["lisp"]},livescript:{name:"LiveScript",aliases:["ls"]},lua:{name:"Lua",aliases:["lua"]},makefile:{name:"Makefile",aliases:["mk","mak"]},markdown:{name:"Markdown",aliases:["md","mkdown","mkd"]},markup:{name:"HTML / XML",aliases:["html","htm","xml","xsd","xsl","xslt","wsdl"]},matlab:{name:"MATLAB",aliases:["matlab"]},mermaid:{name:"Mermaid",aliases:["mermaid"]},nix:{name:"Nix",aliases:["nix"]},objectivec:{name:"Objective-C",aliases:["m","mm"]},ocaml:{name:"OCaml",aliases:["ml"]},pascal:{name:"Pascal",aliases:["pas"]},perl:{name:"Perl",aliases:["pl","pm"]},php:{name:"PHP",aliases:["php"]},powershell:{name:"PowerShell",aliases:["ps","ps1"]},prolog:{name:"Prolog",aliases:["plg"]},protobuf:{name:"Protocol Buffers",aliases:["proto"]},python:{name:"Python",aliases:["py"]},r:{name:"R",aliases:["r"]},reason:{name:"Reason",aliases:["re","rei"]},ruby:{name:"Ruby",aliases:["rb"]},rust:{name:"Rust",aliases:["rs"]},sass:{name:"Sass",aliases:["sass"]},scala:{name:"Scala",aliases:["scala"]},scheme:{name:"Scheme",aliases:["scm","sm"]},scss:{name:"SCSS",aliases:["scss"]},solidity:{name:"Solidity",aliases:["sol"]},sql:{name:"SQL",aliases:["sql"]},swift:{name:"Swift",aliases:["swift"]},typescript:{name:"TypeScript",aliases:["ts","tsx"]},vbnet:{name:"VB.Net",aliases:["vbnet"]},verilog:{name:"Verilog",aliases:["v"]},vhdl:{name:"VHDL",aliases:["vhdl"]},"visual-basic":{name:"Visual Basic",aliases:["vb","vba"]},wasm:{name:"WebAssembly",aliases:["wasm"]},yaml:{name:"YAML",aliases:["yaml"]}};function bD(n){const t=n.toLocaleLowerCase();let e="plain";return Object.entries(oa).forEach(([o,r])=>{(o===t||r.aliases.includes(t)||r.name.toLocaleLowerCase()===t)&&(e=o)}),e}const kD=B("convert-to-code");function vD(n,t){if(!P(n,t))return null;const e={id:N(),type:"text",text:[]},o=N();n.doc.localInsertChildContainer(o,[e]);const r=n.getBlockData(t).text;d(kD,r,"no text");let i=bt(r);i.startsWith("```")&&(i=i.substring(3));const s=bD(i);return{blockData:{id:N(),type:"code",language:s,children:[o]},focusBlockId:e.id}}const Nz="",E1=B("code-block-child-container");function ni(n){d(E1,xo(n),"not a code block");const e=it(n).querySelector(":scope > div.editor-code-root > div.code-text-root [data-type=editor-container].child");return d(E1,e,"no code text container"),e}function oi(n){d(E1,xo(n),"not a code block");const e=it(n).querySelector(":scope > div.editor-code-root > div.code-caption-root [data-type=editor-container].child");return e||null}function ra(n){const t=[ni(n)],e=oi(n);return e&&t.push(e),t}function ri(n){const t=H(n),e=F(t);return e?xo(e)?t===ni(e):ot(n)==="code":!1}const I1=B("code-caption");function yD(n,t){if(n.readonly)return;const e=oi(t);if(e){const c=Ut(e);n.selection.selectBlock(c,0);return}const o=yn(n.doc),r=n.getBlockData(t);d(I1,r.children.length===1,"code block should have only one child");const i={...r,children:[r.children[0],o]};n.updateBlockData(t,i);const s=n.getContainerById(o),l=Ut(s);n.selection.selectBlock(l,0)}function e6(n,t){const e=H(t);if(pt(e))return!1;const o=F(e);if(d(I1,o,"no parent block"),!xo(o))return!1;const i=oi(o);return e===i}function wD(n,t){if(n.readonly||!oi(t))return;const o=ni(t),r=Qt(o);n.selection.selectBlock(r,W(n,r));const i=n.getBlockData(t);d(I1,i.children.length===2,"code block should have only one child");const s=i.children[1],l={...i,children:[i.children[0]]};n.updateBlockData(t,l),n.deleteChildContainers([s])}const BD=B("paste-in-table-block");class ED{constructor(t){this.editor=t,setTimeout(()=>{t.input.addHandler(this)})}destroy(){}async handleBeforePaste(t,e,o){if(!t.selection.range.isSimple())return!1;const r=t.selection.range.start,i=t.getBlockById(r.blockId),s=H(i);if(pt(s))return!1;const l=F(s);if(d(BD,l,"no parent block"),!xo(l)||e6(t,i))return!1;const c=o["text/plain"];return c&&t.undoManager.runInGroup(()=>{t.clearSelectedContents(),t.insertDoc(i,r.offset,c)}),!0}}function ID(n){n.addCustom("code-block-paste-event",t=>new ED(t))}class xD{constructor(t){h(this,"id","CodeBlockCommandProvider");setTimeout(()=>{t.editorCommandProviders.registerCommandProvider(this)})}destroy(){}getAvailableCommands(){return[]}executeCommand(){return!1}filterCommands(t,e,o,r){if(ri(e))return[]}beforeExecuteCommand(t,e,o,r,i){return!!ri(e)}}function TD(n){n.addCustom("code-block-command-provider",t=>new xD(t))}const SD=B("code-caption-input-handler");function x1(n){if(!n.selection.range.isSimple())return null;const t=n.selection.range.start;if(!t.isSimple())return null;const e=n.getBlockById(t.blockId);return e6(n,e)?e:null}function DD(n){const t=x1(n);if(!t)return!1;const e=B1(t),o=dt(e);return o?(n.selection.selectBlock(o,0),!0):(n.insertTextBlock("",U(H(e)),J(e)+1),!0)}function LD(n){const t=x1(n);if(!t)return!1;if(Tt(n,t)){const e=B1(t);return wD(n,e),!0}return!1}class T1{constructor(t){setTimeout(()=>{t.input.addHandler(this)})}destroy(){}handleBeforeKeyDown(t,e){return e.key==="Enter"?DD(t):e.key==="Backspace"?LD(t):!1}async handleBeforePaste(t,e,o){const r=x1(t);if(!r)return!1;const i=o["text/plain"];if(!i)return!0;const s=Jl(t,i);return s&&t.undoManager.runInGroup(()=>{t.clearSelectedContents();const l=t.selection.range.start;d(SD,l.isSimple(),"not simple position"),t.insertTextToBlock(r,l.offset,s)}),!0}static init(t){t.addCustom("code-block-caption-input-handler",e=>new T1(e))}}const MD=`
376
+ </svg>`,p1=B("webpage");class IS{constructor(t,e){h(this,"currentSrc","");h(this,"loading",null);h(this,"handleMaskMouseMove",(t,e)=>{if(!window.isDragging){if(e.target&&e.target instanceof Element){const o=e.target.closest("webpage-mask");o&&(o.style.display="none")}t.domEvents.addEventListener(document,"mousemove",this.handleDocumentMouseMove)}});h(this,"handleDocumentMouseMove",(t,e)=>{if(!e.target||!(e.target instanceof Element))return;const o=this.editor.findBlockById(this.blockData.id);if(o){const r=this.getExistsMask(o);if(r){if(It(o,e.target)){r.style.display="none";return}r.style.display=""}}});this.editor=t,this.blockData=e}create(t,e,o,r){const i=e.src,s=b("div",["editor-embed"],null),l=b("iframe",["editor-preview-iframe"],s);this.loading=this.createLoading(s);const c=()=>{d(p1,this.loading,"not created"),this.loading.hide(),this.currentSrc=i};t.domEvents.addEventListener(l,"load",c),l.src=i,this.loading.show(),o.append(s),this.createMask(t,r)}update(t,e,o){if(d(p1,this.loading,"not created"),this.currentSrc===o.src)return;const r=e.querySelector(".editor-preview-iframe");d(p1,r,"no exists iframe"),this.loading.show(),r.src=o.src,this.createMask(t,e)}createLoading(t){const e=b("div",["editor-preview-iframe-loading"],null),o=b("span",[],e);return o.innerHTML=ES,{show(){t.append(e)},hide(){const r=t.querySelector(":scope > .editor-preview-iframe-loading");!r||r.remove()}}}getExistsMask(t){return Rt(t).querySelector(".webpage-mask")}createMask(t,e){const o=Rt(e);let r=this.getExistsMask(e);if(r){r.style.display="";return}r=b("div",["webpage-mask"],o),t.domEvents.addEventListener(r,"mousemove",this.handleMaskMouseMove)}destroy(){const t=this.editor.findBlockById(this.blockData.id);if(t){const e=this.getExistsMask(t);e&&(this.editor.domEvents.removeEventListener(e,"mousemove",this.handleMaskMouseMove),this.editor.domEvents.removeEventListener(document,"mousemove",this.handleDocumentMouseMove))}}}function xS(n,t){b("div",["resize-gripper",t],n).setAttribute("data-resize-type",t)}function C1(n){return Rt(n).querySelector(".block-resizer")}function TS(n){const t=C1(n);t&&z(t,"active")}function q4(n,t,e){const o=n.getBoundingClientRect(),r=t.getBoundingClientRect(),i=r.top-o.top,s=r.left-o.left,l=r.width,c=r.height;e.style.top=`${i}px`,e.style.left=`${s}px`,e.style.width=`${l}px`,e.style.height=`${c}px`}function SS(n,t,e,o){const r=C1(n);if(r)return A(r,"active"),q4(n,t,r),r;const i=Rt(n),s=b("div",["block-resizer"],i);return q4(n,t,s),e.resize.forEach(l=>{xS(s,l)}),s.addEventListener("mousedown",o),A(s,"active"),s}function W4(n,t){const e=C1(n);if(!e)return;const o=n.getBoundingClientRect(),r=t.getBoundingClientRect(),i=r.top-o.top,s=r.left-o.left,l=r.width,c=r.height;e.style.top=`${i}px`,e.style.left=`${s}px`,e.style.width=`${l}px`,e.style.height=`${c}px`}const Lz="",DS=B("block-resizer");class ta extends Yt.TypedEmitter{constructor(e,o){super();h(this,"resizableElement");h(this,"block",null);h(this,"startRect",null);h(this,"startPos",null);h(this,"resizeType",null);h(this,"enabled",!1);h(this,"handleMouseDown",e=>{e.preventDefault(),e.stopPropagation();const o=this.getResizableElement();if(!o||e.button!==0)return;const r=e.target;if(!r||!(r instanceof HTMLElement))return;const i=r.getAttribute("data-resize-type");!i||(this.bindEvents(),this.startRect=o.getBoundingClientRect(),this.startPos=e,this.resizeType=i,Ai(window.getComputedStyle(r).cursor),this.block&&this.editor.selection.selectBlock(this.block,0))});h(this,"handleMouseMove",e=>{if(!this.startPos||!this.startRect||!this.resizeType)return;const o=this.getResizableElement();if(!o||!this.block)return;const r=e.x-this.startPos.x,i=e.y-this.startPos.y,s=this.startRect;let{top:l,left:c,right:a,bottom:u}=s;(this.resizeType==="bottom"||this.resizeType==="bottom-left"||this.resizeType==="bottom-right")&&(u+=i),(this.resizeType==="top"||this.resizeType==="top-left"||this.resizeType==="top-right")&&(l+=i),(this.resizeType==="left"||this.resizeType==="top-left"||this.resizeType==="bottom-left")&&(c+=r),(this.resizeType==="right"||this.resizeType==="top-right"||this.resizeType==="bottom-right")&&(a+=r);const f=a>c?a-c:0,m=u>l?u-l:0,C=new DOMRect(c,l,f,m);this.emit("resizing",this,C),W4(this.block,o)});h(this,"handleMouseUp",e=>{if(e.button!==0)return;Ai(""),this.unbindEvents(),this.emit("resized",this);const o=this.getResizableElement();!o||!this.block||W4(this.block,o)});this.editor=e,this.options=o}enableResize(e,o){this.block=e,this.resizableElement=o,this.createResizer(),this.enabled=!0}disableResize(){!this.block||(TS(this.block),this.enabled=!1)}update(e,o){this.block=e,this.resizableElement=o,this.getResizableElement()&&this.enabled&&this.createResizer()}getBlock(){return this.block}destroy(){}getResizableElement(){return this.resizableElement?this.resizableElement:this.block?it(this.block):null}createResizer(){const e=this.getResizableElement();!e||!this.block||(d(DS,It(this.block,e),"not a block child element"),SS(this.block,e,this.options,this.handleMouseDown))}bindEvents(){document.addEventListener("mousemove",this.handleMouseMove),document.addEventListener("mouseup",this.handleMouseUp)}unbindEvents(){document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp)}}function G4(n){return n&&Te(n)&&Oe(n)==="webpage"}const LS=1e3,MS=100;class RS{constructor(t){h(this,"currentBlockElement",null);h(this,"resizing",!1);h(this,"handleHoveringBlockChange",(t,e)=>{this.resizing||!this.editor.isWritable()||(e&&G4(e)&&this.disableBlockResize(e),t&&G4(t)&&this.enableBlockResize(t))});h(this,"handleResizing",(t,e)=>{this.resizing=!0;const o=t.getBlock();if(!o)return;const r=Math.max(Math.min(e.height,LS),MS);o.style.height=`${r}px`,A(o,"resizing")});h(this,"handleResized",t=>{this.resizing=!1;const e=t.getBlock();if(!e)return;z(e,"resizing");const o=this.editor.getBlockData(e),r=e.getBoundingClientRect().height;this.editor.updateBlockData(e,{...o,height:r})});this.editor=t,Nt.get(t).addListener("change",this.handleHoveringBlockChange)}destroy(){this.currentBlockElement=null,Nt.get(this.editor).removeListener("change",this.handleHoveringBlockChange)}disableBlockResize(t){const e=this.editor.findCustom(`${q(t)}-resizer`);e&&e.disableResize()}enableBlockResize(t){const e=this.editor.addCustom(`${q(t)}-resizer`,()=>new ta(this.editor,{resize:["bottom"]}));e.enableResize(t),e.removeListener("resizing",this.handleResizing),e.removeListener("resized",this.handleResized),e.addListener("resizing",this.handleResizing),e.addListener("resized",this.handleResized),this.currentBlockElement=t}}const Mz="",AS=B("editor-dialog");function OS(n,t){const e=b("div",["editor-dialog-container"],null),o=b("div",["dialog-header"],e);b("span",["dialog-header-title"],o,t.title);const r=b("span",["close-icon"],o);r.innerHTML=t5,b("div",["dialog-content"],e).appendChild(n);const s=b("div",["dialog-footer"],e);return b("button",["cancel-button"],s,"Cancel"),b("button",["submit-button"],s,"Ok"),e}class _S extends vs{constructor(e,o){super(OS(e,o),o);h(this,"_options");h(this,"getReferenceClientRect",()=>{const e=document.documentElement.clientHeight/2,o=document.documentElement.clientWidth/2,r=this.getCommandBarRoot();d(AS,r,"no command bar root");const{width:i,height:s}=r.getBoundingClientRect();return new DOMRect(Math.max(o-i/2,0),Math.max(e-s/2,0),0,0)});h(this,"handleOk",async()=>{var e,o;try{await((o=(e=this._options).onOk)==null?void 0:o.call(e)),this.destroy()}catch{}});h(this,"handleClose",()=>{var e,o;(o=(e=this._options).onClose)==null||o.call(e),this.destroy()});const r=this.content.querySelector(".submit-button"),i=this.content.querySelector(".cancel-button"),s=this.content.querySelector(".close-icon");r==null||r.addEventListener("click",this.handleOk),s==null||s.addEventListener("click",this.handleClose),i==null||i.addEventListener("click",this.handleClose),this._options=o}show(){super.show(document.documentElement,{getReferenceClientRect:this.getReferenceClientRect})}destroy(){const e=this.content.querySelector(".submit-button"),o=this.content.querySelector(".cancel-button"),r=this.content.querySelector(".close-icon");e==null||e.removeEventListener("click",this.handleOk),o==null||o.removeEventListener("click",this.handleClose),r==null||r.removeEventListener("click",this.handleClose),super.destroy()}}const Z4=()=>[{name:T.t("webpage.bilibili"),id:"insert-bilibili",icon:iB,group:"thirdParty",subText:me("insert-bilibili")},{name:T.t("webpage.youku"),id:"insert-youku",icon:sB,group:"thirdParty",subText:me("insert-youku")},{name:T.t("webpage.figma"),id:"insert-figma",icon:lB,group:"thirdParty",subText:me("insert-figma")},{name:T.t("webpage.modao"),id:"insert-modao",icon:cB,group:"thirdParty",subText:me("insert-modao")},{name:T.t("webpage.tencent"),id:"insert-tencent",icon:aB,group:"thirdParty",subText:me("insert-tencent")},{id:"insert-webPage",name:T.t("webpage.title"),icon:dB,group:"common",order:1e3,subText:me("insert-webPage")}];function b1(n){return n==="insert-webPage"}async function NS(n,t){return n.doc.externalDoc.recognizeLink?n.doc.externalDoc.recognizeLink(t):null}function $S(n){return n&&!n.startsWith("http://")&&!n.startsWith("https://")&&!n.startsWith("//")?`//${n}`:n}async function PS(n){if(!n)throw new Error(T.t("webpage.dialog.errorEnterUrl"));let t=n;t.startsWith("//")&&(t=`http:${t}`);try{new URL(t)}catch{throw new Error(T.t("webpage.dialog.unsupportedUrl"))}}async function jS(n,t){const e=t.item.id,o=Z4().find(a=>a.id===e),r=b("div",["webpage-content"],null);if(b1(e)){const a=b("div",["help-container"],r),u=b("div",["help-content"],a),f=b("span",["help-icon"],u);f.innerHTML=r5,b("span",[],u,T.t("webpage.dialog.helpContent"))}const{getInputValue:i,setFieldError:s,focus:l,getField:c}=mh(r,{required:!0,label:T.t("webpage.dialog.label"),placeholder:T.t("webpage.dialog.placeholder")});if(!b1(e)){const a=b("div",["help-link-container"],r),u=b("a",["help-link-content"],a);b("span",[],u,T.t("webpage.dialog.helpLink"));const f=b("span",["help-link-icon"],u);f.innerHTML=s5;const m=n.getComponentOptions("webpage");u.href=(m==null?void 0:m.helpLink)||"",u.target="_blank"}try{const a=await new Promise((m,C)=>{const k=new _S(r,{title:T.t("webpage.dialog.title",{name:(o==null?void 0:o.name)||""}),async onOk(){var S;const y=$S(i());try{await PS(y);const I=await NS(n,y);m((I==null?void 0:I.url)||"")}catch(I){if(((S=I==null?void 0:I.responseData)==null?void 0:S.statusCode)===415)if(b1(e))m(y);else throw s(T.t("webpage.dialog.unsupportedUrl")),I;else throw s(I.message||""),I}},onClose(){n.focus(),C()}});k.addListener("show",l),k.show(),c().addEventListener("keydown",async y=>{if(!y.isComposing){if(y.key==="Enter"){await k.handleOk(),y.preventDefault();return}y.key==="Escape"&&k.handleClose()}})}),u={id:N(),type:"embed",embedType:"webpage",embedData:{src:a}},f=n.insertBlock(t.containerId,t.blockIndex,u);return n.focus(),f}catch{return null}}const Y4=B("embed-block-properties");function k1(n,t){var e;for(const o of n.blockHooks){const r=(e=o.commands)==null?void 0:e.call(o,n,t);if(!!r&&r.group==="block-comment-actions")return r.executeCommand(n,t,r.commands[0]),!0}return!1}class v1{constructor(t,e){h(this,"group","hovering-toolbar");h(this,"_commands",[{id:"edit",name:"Edit",icon:hh},{id:"add-comment",name:"Add Comment",icon:wc}]);this.editor=t,this.properties=e}get commands(){var e,o,r;if(!this.editor.isWritable())return[];const t=(e=this.properties)!=null&&e.presetIds?this._commands.filter(i=>{var s,l;return(l=(s=this.properties)==null?void 0:s.presetIds)==null?void 0:l.includes(i.id)}):[...this._commands];return(r=(o=this.properties)==null?void 0:o.extCommands)!=null&&r.length&&(t.push({id:N(),type:"separator",name:""}),t.push(...this.properties.extCommands)),t}executeCommand(t,e,o){var r,i;if(!((i=(r=this.properties)==null?void 0:r.handleExecuteCommand)!=null&&i.call(r,t,e,o))){if(o.id==="add-comment"){k1(t,e)||Y4.error("failed to add comment to block");return}Y4.error(`unknown command: ${JSON.stringify(o)}`)}}}function y1(n,t,e){return{blockCommands:{"hovering-toolbar":new v1(n,e)}}}function HS(n){const t=n.querySelector(".editor-preview-iframe"),e=t.src;t.src="about:blank";const o=setTimeout(()=>{t.src=e,clearTimeout(o)},300);return!0}function FS(n,t){const e=n.getBlockData(t),{embedData:o}=e,r=o.src;return window.open(r,"_blank"),!0}function zS(n,t){const e=y1(n,t,{presetIds:["add-comment"],extCommands:[{id:"refresh",name:"Refresh page",icon:nB},{id:"open-page",name:"Open the original page",icon:s5}],handleExecuteCommand:(r,i,s)=>{switch(s.id){case"refresh":return HS(i);case"open-page":return FS(r,i)}return!1}}),o=`[${T.t("webpage.abstract")}]`;return{...e,abstract:o}}const US=B("webpage-embed");function VS(n,t,e,o,r,i){const{embedData:s,id:l}=e,{src:c}=s,a=n.addCustom(`webpage-${l}`,()=>new IS(n,e));d(US,c,"The src from blockData is invalid "),a.create(n,s,t,i),n.addCustom("webpage-resizer",()=>new RS(n)),e.height&&(i.style.height=`${e.height}px`)}function qS(n,t,e){const{embedData:o,id:r}=e;return n.getCustom(`webpage-${r}`).update(n,t,o),e.height&&(t.style.height=`${e.height}px`),!0}function WS(){return{name:"WebPage",insertEmbedCommandItems:Z4(),handleInsertEmptyEmbed:jS}}function GS(n,t,e,o){const i=t.embedData.src;return o==="html"?`<iframe src="${i}" ></iframe>`:o==="markdown"?`[${i}](${i})`:i}const w1={embedType:"webpage",createEmbedContent:VS,getBlockProperties:zS,getOptions:WS,handleUpdateBlock:qS,convertTo:GS},ZS={webpage:{title:"\u7F51\u9875",youku:"\u4F18\u9177\u89C6\u9891",modao:"\u58A8\u5200",tencent:"\u817E\u8BAF\u89C6\u9891",bilibili:"Bilibili",figma:"Figma",dialog:{helpContent:"\u56E0\u76EE\u6807\u7F51\u9875\u7684\u9650\u5236\uFF0C\u90E8\u5206\u7F51\u9875\u53EF\u80FD\u65E0\u6CD5\u6210\u529F\u9884\u89C8\u3002",helpLink:"\u5982\u4F55\u83B7\u53D6\u94FE\u63A5",label:"\u7F51\u9875\u5730\u5740",placeholder:"\u8BF7\u8F93\u5165",title:"\u63D2\u5165{name}",errorEnterUrl:"\u8BF7\u8F93\u5165\u7F51\u9875\u5730\u5740",unsupportedUrl:"\u6682\u4E0D\u652F\u6301\u63D2\u5165\u8BE5\u94FE\u63A5\u5185\u5BB9"},abstract:"\u7F51\u9875"}},YS={webpage:{title:"Webpage",youku:"Youku",modao:"Modao",tencent:"Tencent Video",bilibili:"Bilibili",figma:"Figma",dialog:{helpContent:"Due to the limitation of the landing page, some pages may not be previewed successfully.",helpLink:"How to get the URL link",label:"Please enter webpage address",placeholder:"Please enter url",title:"Insert {name}",errorEnterUrl:"Please enter the webpage address",unsupportedUrl:"Unsupported url"},abstract:"Webpage"}};T.mergeLang({"zh-CN":ZS,"en-US":YS});const Rz="";function QS(n,t,e,o){var f;const r=n.getBlockByIndex(t,e);if(W(n,r)!==o)return!1;const i=bt(n.getBlockText(r));if(![...i].every(m=>m==="|")||i.length<3||!n.editorBlocks.hasBlock("table"))return!1;const s=n.editorBlocks.getBlockClass("table");if(!s.convertFrom)return!1;const l=s.convertFrom(n,r,{offset:o});if(!l)return!1;const{blockData:c,focusBlockId:a}=l;if(!c)return!1;const u=n.insertBlock(t,e,c,At(n,a!=null?a:c.id,0));return n.deleteBlock(r),(f=l.onConverted)==null||f.call(l,n,u),!0}const KS={mermaid:{blockType:"embed",reg:/^```mermaid$/,data:{embedType:"mermaid"}},flowchart:{blockType:"embed",reg:/^```flowchart$/,data:{embedType:"flowchart"}},plantuml:{blockType:"embed",reg:/^```plantuml$/,data:{embedType:"plantuml"}},code:{blockType:"code",reg:/^```\S+$/},code2:{blockType:"code",reg:/^```$/},table:{blockType:"table",reg:/^\|.+\|.+\|$/},math:{blockType:"embed",reg:/^\$\$.+\$\$$/},image:{blockType:"embed",reg:/^!\[[^\]]*\]\((?<filename>.*?)(?="|\))(?<optionalPart>".*")?\)/,data:{embedType:"image"}},dividing:{blockType:"embed",reg:/^-{3,}$/,data:{embedType:"dividing-line"}},toc:{blockType:"embed",reg:/^\[toc\]/,data:{embedType:"toc"}}},JS={orderedList:{reg:/^(\d)+(\.|。)$/,blockType:"list",data:{listType:"ordered"}},unorderedList1:{reg:/^\*$/,blockType:"list",data:{listType:"unordered"}},unorderedList2:{reg:/^-$/,blockType:"list",data:{listType:"unordered"}},checkList1:{reg:/^\[\s?\]$/,blockType:"list",data:{listType:"unchecked"}},checkList2:{reg:/^\[X\]$/i,blockType:"list",data:{listType:"checked"}},image:{blockType:"embed",reg:/^!\[[^\]]*\]\((?<filename>.*?)(?="|\))(?<optionalPart>".*")?\)/,data:{embedType:"image"}}};function Q4(n,t,e,o,r){if(r==="enter"&&QS(n,t,e,o))return!0;const i=n.getBlockByIndex(t,e),s=bt(be(n.getBlockText(i),o).left).trim(),l=r==="enter"?KS:JS;for(const[,c]of Object.entries(l)){if(!s.match(c.reg))continue;return!!n.undoManager.runInGroup(()=>{var k;const u=Ml(n,i,c.blockType,{offset:o,data:c.data});if(!u)return null;const{blockData:f,focusBlockId:m}=u;if(!f)return null;const C=n.insertBlock(t,e,f,At(n,m!=null?m:f.id,0));return n.deleteBlock(i),(k=u.onConverted)==null||k.call(u,n,C),{newBlock:C,focusBlockId:m}})}return!1}function XS(n,t,e,o){const r=n.getBlockByIndex(t,e);return n.getBlockString(r,{boxReplacement:" "}).substring(0,o)!==">"?!1:(n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,0,o+1),n.updateBlockData(r,{quoted:!0},At(n,r,0))}),!0)}const tD={"#":1,"##":2,"###":3,"####":4,"#####":5,"######":6,"#######":7,"########":8};function eD(n,t,e,o){const r=n.getBlockByIndex(t,e),i=n.getBlockString(r,{boxReplacement:" "}).substring(0,o);let s=tD[i];if(!s)return!1;const l=n.getBlockData(r).heading;return l&&l==s&&(s=null),n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,0,o+1),n.updateBlockData(r,{heading:s},At(n,r,0))}),!0}function nD(n,t,e,o){return!!(eD(n,t,e,o)||XS(n,t,e,o))}const oD=B("match-text-style");function rD(n){let t="";for(let e=n.length-1;e>=0;e--){const o=n[e];if(!o.attributes||Object.keys(o.attributes).length===0){t+=o.insert;continue}break}return t}function iD(n,t){if(n.length<t.length*2+1||!n.endsWith(t)||n.substring(0,n.length-1).endsWith(t))return-1;const e=n.substring(0,n.length-t.length),o=e.lastIndexOf(t);return o===-1?-1:o===0?0:e.substring(o-1).startsWith(t)?-1:o}const sD={"*":{type:"style",styles:["style-italic"],boxType:""},"**":{type:"style",styles:["style-bold"],boxType:""},"***":{type:"style",styles:["style-bold","style-italic"],boxType:""},"~~":{type:"style",styles:["style-strikethrough"],boxType:""},"`":{type:"style",styles:["style-code"],boxType:""},$$:{type:"box",styles:[],boxType:"math"}};function lD(n,t,e,o){var u,f;const r=n.getBlockByIndex(t,e),i=n.getBlockText(r),{left:s}=be(i,o),l=rD(s),c=ue(s)-l.length,a=Object.entries(sD);for(const[m,C]of a){const k=iD(l,m);if(k===-1)continue;const w=c+k,y=o,S=m.length,I=bt(Wt(i,w+S,y-w-S*2).middle);if(C.type==="style"){const M={};C.styles.forEach($=>{M[$]=!0});const R=Qo(I,M);n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,w,y-w),n.insertTextToBlock(r,w,R)})}else if(C.type==="box")try{const M=(f=(u=n.editorBoxes.getBoxClass(C.boxType)).convertFrom)==null?void 0:f.call(u,n,I);if(!M)continue;n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,w,y-w),n.insertBoxToBlock(r,w,M)})}catch(M){oD.warn(`failed to convert to box, ${M.message}`);continue}return!0}return!1}class ea{handleAfterInsertText(t,e,o,r,i){return!!(i===" "&&(nD(t,e,o,r)||lD(t,e,o,r)))}handleBeforeKeyDown(t,e){if(!t.selection.range.isSimple())return!1;const{containerId:r,blockIndex:i,offset:s}=t.getTextPosition();if(P(t,t.getBlockByIndex(r,i))){if(jn(e,"Enter")){if(Q4(t,r,i,s,"enter"))return!0}else if(jn(e,"Space")&&Q4(t,r,i,s,"space"))return!0}return!1}}const cD={"en-US":{placeholder:{default:"Type \u2018/\u2019 for commands",heading:"Heading {heading}",list:"List",mention:"Quickly assign tasks @mention yourself or others",quote:"Quote",title:"Enter document title"}},"zh-CN":{placeholder:{default:"\u8F93\u5165\u300C/\u300D\u5FEB\u901F\u63D2\u5165",heading:"\u6807\u9898{heading}",list:"\u5217\u8868",mention:"\u5FEB\u901F\u5206\u914D\u4EFB\u52A1\uFF0C@\u63D0\u53CA\u81EA\u5DF1\u6216\u4ED6\u4EBA",quote:"\u5F15\u7528",title:"\u8BF7\u8F93\u5165\u6587\u6863\u6807\u9898"}}};T.mergeLang(cD);function Ns(n,t){const e=mo(n,t);return!!(e.text&&ue(e.text)===0&&!t.querySelector(".inputting-insertion"))}function K4(n,t){var o;it(t).removeAttribute("data-content-placeholder"),(o=t.querySelector("[data-type=block-tools] .block-placeholder-container"))==null||o.remove()}function na(n,t,e){var r;if(!Ns(n,t)){K4(n,t);return}const o=it(t);if(typeof e=="string")o.setAttribute("data-content-placeholder",e);else{const i=Rt(t),s=(r=i.querySelector(".block-placeholder-container"))!=null?r:b("div",["block-placeholder-container"],i);s.innerHTML="",s.appendChild(e)}}function aD(n){const t=n.getAttribute("data-style-heading");return t?T.t("placeholder.heading",{heading:t}):n.getAttribute("data-style-quoted")?T.t("placeholder.quote"):null}function dD(n){const t=n.getAttribute("data-list-type");return t?t==="ordered"||t==="unordered"?T.t("placeholder.list"):T.t("placeholder.mention"):null}function J4(n){switch(ot(n)){case"text":return aD(n);case"list":return dD(n);default:return null}}function uD(n){if(Co(n))return!1;const t=F(H(n));return t?ot(t)==="code":!1}function hD(n){if(Co(n))return!1;const t=F(H(n));return t?ot(t)==="table":!1}function fD(n,t){var u,f;const e=n.selection.focusedBlock,o=ot(e),r=t.contentPlaceholder||T.t("placeholder.default");let i=r;if(o&&$i(n,o)&&e){if(uD(e))return;hD(e)?i=T.t("placeholder.common.contentInTable"):i=(u=J4(e))!=null?u:i}const s=n.getFirstBlock(),l=dt(s);if(!l)return;const c=dt(l);if(c&&!t.addPlaceholderToAllCurrentEmptyBlock)return;if(!c){Ns(n,l)&&na(n,l,(f=J4(l))!=null?f:r);return}const a=n.getFocusedBlock();!Ns(n,a)||a!==s&&na(n,a,i)}function mD(n,t){var r,i;const e=n.getFirstBlock(),o=it(e);Ns(n,e)?(o.setAttribute("data-title-placeholder",(r=t.titlePlaceholder)!=null?r:T.t("placeholder.title")),o.setAttribute("data-title-placeholder-readonly",(i=t.readonlyTitlePlaceholder)!=null?i:"")):(o.removeAttribute("data-title-placeholder"),o.removeAttribute("data-title-placeholder-readonly"))}function gD(n){n.rootContainer.querySelectorAll("[data-content-placeholder").forEach(t=>{t.removeAttribute("data-content-placeholder")}),n.rootContainer.querySelectorAll("[data-type=block-tools] .block-placeholder-container").forEach(t=>{t.remove()})}function pD(n,t){gD(n),n.selection.range.isCollapsed()&&(mD(n,t),fD(n,t))}const _z="",CD=B("enforce-title");class $s{constructor(t,e={headingLevel:1}){h(this,"handleSelectionChange",t=>{setTimeout(()=>{this.applyPlaceholder(t)})});this.options=e,this.handleChanged(t),this.applyPlaceholder(t),t.addListener("selectionChanged",this.handleSelectionChange)}destroy(t){t.removeListener("selectionChanged",this.handleSelectionChange)}handleBeforeKeyDown(t,e){if(!t.selection.range.isSimple())return!1;const{containerId:r,blockIndex:i,offset:s}=t.getTextPosition();if(!$s.isDocumentTitleBlock(r,i)||!jn(e,"Enter"))return!1;let l=!1,c=null;Ge(t.rootContainer)===2&&(c=yr(t.rootContainer,1),W(t,c)===0&&(l=!0));const a=t.getFirstBlock();return t.undoManager.runInGroup(()=>{t.breakTextBlock(a,s,{forceInsertAfter:!0}),l&&c&&t.deleteBlock(c)}),!0}handleChanged(t){var e;try{const o=t.doc.getContainerBlocks(U(t.rootContainer));d(CD,o.length>0,"root container is empty");const r=o[0];if(r.type!=="text"||r.heading!==this.options.headingLevel){const i=Un("",{heading:(e=this.options.headingLevel)!=null?e:1});t.insertBlock(U(t.rootContainer),0,i);return}if(o.length>1)return;t.insertTextBlock("",U(t.rootContainer),1,{newRange:t.selection.range.toDocRange()})}finally{this.applyPlaceholder(t)}}handleRemoteChanged(t){setTimeout(()=>{this.applyPlaceholder(t)})}handleUpdateCompositionText(t){this.applyPlaceholder(t)}applyPlaceholder(t){var e,o;!((e=this.options)!=null&&e.titlePlaceholder)&&!((o=this.options)!=null&&o.contentPlaceholder)||pD(t,this.options)}static isDocumentTitleBlock(t,e){return t==="root"&&e===0}}const X4=B("code-dom");function To(n){return ot(n)==="code"}function t6(n,t,e){e.language?t.setAttribute("data-language",e.language):t.removeAttribute("data-language"),e.nowrap?z(t,"wrap"):A(t,"wrap")}function B1(n){const t=n.closest("div[data-type=editor-block][data-block-type=code]");return d(X4,t,"no parent code block"),d(X4,To(t),"not a code block"),t}const oa={plain:{name:"Plain Text",aliases:["txt","text"]},abap:{name:"ABAP",aliases:["abap"]},arduino:{name:"Arduino",aliases:["ino"]},bash:{name:"Bash",aliases:["sh","shell"]},basic:{name:"BASIC",aliases:["bas"]},c:{name:"C",aliases:["c"]},clojure:{name:"Clojure",aliases:["clj"]},cofeescript:{name:"CoffeeScript",aliases:["coffee"]},cpp:{name:"C++",aliases:["cpp","cxx"]},csharp:{name:"C#",aliases:["cs"]},css:{name:"CSS",aliases:["css"]},dart:{name:"Dart",aliases:["dart"]},diff:{name:"Diff",aliases:["diff","patch"]},docker:{name:"Docker",aliases:["dockerfile"]},elixir:{name:"Elixir",aliases:["ex","exs"]},elm:{name:"Elm",aliases:["elm"]},erlang:{name:"Erlang",aliases:["erl"]},flow:{name:"Flow",aliases:["flow"]},fortran:{name:"Fortran",aliases:["f","for","f77","f90"]},fsharp:{name:"F#",aliases:["fsharp"]},gherkin:{name:"Gherkin",aliases:["feature"]},glsl:{name:"GLSL",aliases:["glsl"]},go:{name:"Go",aliases:["go"]},graphql:{name:"GraphQL",aliases:["graphql"]},groovy:{name:"Groovy",aliases:["groovy"]},haskell:{name:"Haskell",aliases:["hs"]},java:{name:"Java",aliases:["java"]},js:{name:"JavaScript",aliases:["js","jsx"]},json:{name:"JSON",aliases:["json"]},julia:{name:"Julia",aliases:["jl"]},kotlin:{name:"Kotlin",aliases:["kt","ktm","kts"]},latex:{name:"LaTeX",aliases:["tex"]},less:{name:"LESS",aliases:["less"]},lisp:{name:"Lisp",aliases:["lisp"]},livescript:{name:"LiveScript",aliases:["ls"]},lua:{name:"Lua",aliases:["lua"]},makefile:{name:"Makefile",aliases:["mk","mak"]},markdown:{name:"Markdown",aliases:["md","mkdown","mkd"]},markup:{name:"HTML / XML",aliases:["html","htm","xml","xsd","xsl","xslt","wsdl"]},matlab:{name:"MATLAB",aliases:["matlab"]},mermaid:{name:"Mermaid",aliases:["mermaid"]},nix:{name:"Nix",aliases:["nix"]},objectivec:{name:"Objective-C",aliases:["m","mm"]},ocaml:{name:"OCaml",aliases:["ml"]},pascal:{name:"Pascal",aliases:["pas"]},perl:{name:"Perl",aliases:["pl","pm"]},php:{name:"PHP",aliases:["php"]},powershell:{name:"PowerShell",aliases:["ps","ps1"]},prolog:{name:"Prolog",aliases:["plg"]},protobuf:{name:"Protocol Buffers",aliases:["proto"]},python:{name:"Python",aliases:["py"]},r:{name:"R",aliases:["r"]},reason:{name:"Reason",aliases:["re","rei"]},ruby:{name:"Ruby",aliases:["rb"]},rust:{name:"Rust",aliases:["rs"]},sass:{name:"Sass",aliases:["sass"]},scala:{name:"Scala",aliases:["scala"]},scheme:{name:"Scheme",aliases:["scm","sm"]},scss:{name:"SCSS",aliases:["scss"]},solidity:{name:"Solidity",aliases:["sol"]},sql:{name:"SQL",aliases:["sql"]},swift:{name:"Swift",aliases:["swift"]},typescript:{name:"TypeScript",aliases:["ts","tsx"]},vbnet:{name:"VB.Net",aliases:["vbnet"]},verilog:{name:"Verilog",aliases:["v"]},vhdl:{name:"VHDL",aliases:["vhdl"]},"visual-basic":{name:"Visual Basic",aliases:["vb","vba"]},wasm:{name:"WebAssembly",aliases:["wasm"]},yaml:{name:"YAML",aliases:["yaml"]}};function bD(n){const t=n.toLocaleLowerCase();let e="plain";return Object.entries(oa).forEach(([o,r])=>{(o===t||r.aliases.includes(t)||r.name.toLocaleLowerCase()===t)&&(e=o)}),e}const kD=B("convert-to-code");function vD(n,t){if(!P(n,t))return null;const e={id:N(),type:"text",text:[]},o=N();n.doc.localInsertChildContainer(o,[e]);const r=n.getBlockData(t).text;d(kD,r,"no text");let i=bt(r);i.startsWith("```")&&(i=i.substring(3));const s=bD(i);return{blockData:{id:N(),type:"code",language:s,children:[o]},focusBlockId:e.id}}const Nz="",E1=B("code-block-child-container");function ni(n){d(E1,To(n),"not a code block");const e=it(n).querySelector(":scope > div.editor-code-root > div.code-text-root [data-type=editor-container].child");return d(E1,e,"no code text container"),e}function oi(n){d(E1,To(n),"not a code block");const e=it(n).querySelector(":scope > div.editor-code-root > div.code-caption-root [data-type=editor-container].child");return e||null}function ra(n){const t=[ni(n)],e=oi(n);return e&&t.push(e),t}function ri(n){const t=H(n),e=F(t);return e?To(e)?t===ni(e):ot(n)==="code":!1}const I1=B("code-caption");function yD(n,t){if(n.readonly)return;const e=oi(t);if(e){const c=Ut(e);n.selection.selectBlock(c,0);return}const o=yn(n.doc),r=n.getBlockData(t);d(I1,r.children.length===1,"code block should have only one child");const i={...r,children:[r.children[0],o]};n.updateBlockData(t,i);const s=n.getContainerById(o),l=Ut(s);n.selection.selectBlock(l,0)}function e6(n,t){const e=H(t);if(pt(e))return!1;const o=F(e);if(d(I1,o,"no parent block"),!To(o))return!1;const i=oi(o);return e===i}function wD(n,t){if(n.readonly||!oi(t))return;const o=ni(t),r=Qt(o);n.selection.selectBlock(r,W(n,r));const i=n.getBlockData(t);d(I1,i.children.length===2,"code block should have only one child");const s=i.children[1],l={...i,children:[i.children[0]]};n.updateBlockData(t,l),n.deleteChildContainers([s])}const BD=B("paste-in-table-block");class ED{constructor(t){this.editor=t,setTimeout(()=>{t.input.addHandler(this)})}destroy(){}async handleBeforePaste(t,e,o){if(!t.selection.range.isSimple())return!1;const r=t.selection.range.start,i=t.getBlockById(r.blockId),s=H(i);if(pt(s))return!1;const l=F(s);if(d(BD,l,"no parent block"),!To(l)||e6(t,i))return!1;const c=o["text/plain"];return c&&t.undoManager.runInGroup(()=>{t.clearSelectedContents(),t.insertDoc(i,r.offset,c)}),!0}}function ID(n){n.addCustom("code-block-paste-event",t=>new ED(t))}class xD{constructor(t){h(this,"id","CodeBlockCommandProvider");setTimeout(()=>{t.editorCommandProviders.registerCommandProvider(this)})}destroy(){}getAvailableCommands(){return[]}executeCommand(){return!1}filterCommands(t,e,o,r){if(ri(e))return[]}beforeExecuteCommand(t,e,o,r,i){return!!ri(e)}}function TD(n){n.addCustom("code-block-command-provider",t=>new xD(t))}const SD=B("code-caption-input-handler");function x1(n){if(!n.selection.range.isSimple())return null;const t=n.selection.range.start;if(!t.isSimple())return null;const e=n.getBlockById(t.blockId);return e6(n,e)?e:null}function DD(n){const t=x1(n);if(!t)return!1;const e=B1(t),o=dt(e);return o?(n.selection.selectBlock(o,0),!0):(n.insertTextBlock("",U(H(e)),J(e)+1),!0)}function LD(n){const t=x1(n);if(!t)return!1;if(Tt(n,t)){const e=B1(t);return wD(n,e),!0}return!1}class T1{constructor(t){setTimeout(()=>{t.input.addHandler(this)})}destroy(){}handleBeforeKeyDown(t,e){return e.key==="Enter"?DD(t):e.key==="Backspace"?LD(t):!1}async handleBeforePaste(t,e,o){const r=x1(t);if(!r)return!1;const i=o["text/plain"];if(!i)return!0;const s=Jl(t,i);return s&&t.undoManager.runInGroup(()=>{t.clearSelectedContents();const l=t.selection.range.start;d(SD,l.isSimple(),"not simple position"),t.insertTextToBlock(r,l.offset,s)}),!0}static init(t){t.addCustom("code-block-caption-input-handler",e=>new T1(e))}}const MD=`
377
377
  <svg fill="currentColor" focusable="false" viewBox="0 0 24 24" aria-hidden="true" tabindex="-1">
378
378
  <path d="M8.12 9.29 12 13.17l3.88-3.88c.39-.39 1.02-.39 1.41 0 .39.39.39 1.02 0 1.41l-4.59 4.59c-.39.39-1.02.39-1.41 0L6.7 10.7a.9959.9959 0 0 1 0-1.41c.39-.38 1.03-.39 1.42 0z"></path>
379
379
  </svg>`,RD=`
@@ -384,14 +384,14 @@ $$${r.mathjaxText}$$
384
384
  <svg focusable="false" viewBox="0 0 24 24" aria-hidden="true" tabindex="-1">
385
385
  <path fill="currentColor" d="M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3 3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"></path>
386
386
  </svg>
387
- `;function OD(n,t,e){const r={...n.getBlockData(t),language:e};n.updateBlockData(t,r),Se(n,t).forEach(s=>{Mt(s).forEach(l=>{n.reloadBlock(l)})})}function _D(n,t,e){const r={...n.getBlockData(t),nowrap:e};n.updateBlockData(t,r)}async function ND(n){const t=await n.settingsProvider.getItem("editor-code-lang");return t!=null?t:"plain"}async function $D(n,t){return n.settingsProvider.setItem("editor-code-lang",t)}const ar=B("code-block-header"),PD=Object.entries(oa).map(([n,t])=>({id:n,name:t.name,language:t}));function n6(n,t,e){d(ar,xo(t),"not a code block");const o=Ut(ni(t));n.selection.selectBlock(o,0),e.focusToEditor&&n.focus()}function jD(n,t){if(t){const e=n,{editor:o,codeBlock:r}=e.custom;OD(o,r,t.id);const i=r.querySelector(".code-block-header .language-select .name-label");i.innerText=t.name,$D(o,t.id),o.focus()}}function HD(n,t,e){n.addCustom("code-header-language-select-dropdown",i=>{const s=new Nw(PD,i.rootElement,{placeholder:"Search for a language..."});return s.onSelected=jD,s});const o=b("div",["language-select"],null);b("span",["name-label"],o,e);const r=b("span",["arrow-icon"],o);return r.innerHTML=MD,n.domEvents.addEventListener(o,"click",(i,s)=>{const c=s.target.closest(".language-select"),a=F(c);d(ar,a,"no parent block"),d(ar,ot(a)==="code","not a code block");const u=i.getBlockData(a),f=i.getCustom("code-header-language-select-dropdown");f.custom={codeBlock:a,editor:i},f.setSelectedId(u.language),f.show(c),n6(i,a,{focusToEditor:!1}),A(t,"editing-language"),f.onHide=()=>{z(t,"editing-language")}}),o}function FD(){return b("div",["code-header-spacer"],null)}function zD(n,t){const e=t.target,o=e.closest(".code-header-button");d(ar,o,"no button");const r=F(e);d(ar,r,"no parent block");const i=o.getAttribute("data-id");if(d(ar,ot(r)==="code","not a code block"),i==="wrap"){const s=n.getBlockData(r);_D(n,r,!s.nowrap);return}if(i==="copy"){n6(n,r,{focusToEditor:!0}),cc(n,r).then(()=>{const s=o.getBoundingClientRect();$w("Copied to clipboard",{position:{x:s.x+s.width/2,y:s.bottom+30}})}).catch(s=>{ar.error(s.message)});return}i==="caption"&&(yD(n,r),setTimeout(()=>{n.focus()}))}function S1(n,t,e,o){const r=b("button",["code-header-button"],null);if(r.setAttribute("data-id",t),o){const i=b("span",["button-icon"],r);i.innerHTML=o}if(e){const i=b("span",["button-label"],r);i.innerHTML=e}return n.domEvents.addEventListener(r,"click",zD),r}function UD(n,t,e){const o=Rt(t),r=b("div",["code-block-header"],o),i=oa[e.language]||oa.plain;r.appendChild(HD(n,t,i.name)),r.appendChild(FD()),r.appendChild(S1(n,"copy","Copy",RD)),r.appendChild(S1(n,"wrap","Wrap",AD)),r.appendChild(S1(n,"caption","Caption",null))}function VD(n,t){!t.target||setTimeout(()=>{n.selection.caret.update()})}function qD(n,t,e,o){T1.init(n);const r=o.children,i=ro(e,"div");i.setAttribute("data-language",o.language||"text"),t6(n,e,o);const s=b("div",["editor-code-root"],i),l=b("div",["code-text-root"],s),c=n.createChildContainer(t,l,r[0]);if(r.length===2){const a=b("div",["code-caption-root"],s);n.createChildContainer(t,a,r[1])}return n.domEvents.addEventListener(c,"scroll",VD),UD(n,e,o),i}async function WD(n){const t={id:N(),type:"text",text:[]},e=N();n.doc.localInsertChildContainer(e,[t]);const o=await ND(n);return{blockData:{id:N(),type:"code",language:o,children:[e]},focusBlockId:t.id}}const Dn=B("list-block");function GD(n,t,e,o,r){ID(n),TD(n),d(Dn,r.type==="code","invalid block data type");const i=r;return d(Dn,i.children,"invalid block data children"),d(Dn,i.children.length===1||i.children.length===2,"invalid block data children length"),qD(n,t,o,i)}function ZD(n){return 1}function YD(n,t,e,o){const r=document.elementsFromPoint(e,o)[0];if(!r||!t.contains(r)||!n.contains(t)||!bn(r))return null;const i=ra(t);if(!bn(r))return null;const s=r;if(i.indexOf(s)===-1||Ge(s)>1)return null;const l=wt(t,U(s));return new Xe(n,{anchor:l,focus:l})}function QD(n,t,e,o){return null}function KD(n,t){return n.getBoundingClientRect()}function JD(n,t,e,o){if(e.isSimple()){d(Dn,o.isSimple(),"from is simple position but to is not simple position"),Dn.debug("full select list"),A(t,"full-selected");return}d(Dn,!o.isSimple(),"from is complex position but end is simple position");const r=e,i=o;d(Dn,r.blockId===i.blockId,"only allow update one table selection"),ra(t).forEach(l=>{const c=U(l);(c===r.childContainerId||c===i.childContainerId)&&A(l,"selected")})}function XD(n){n.rootContainer.querySelectorAll('[data-type="editor-block"][data-block-type="code"]').forEach(t=>{z(t,"full-selected"),t.querySelectorAll("div[data-type=editor-container].child.selected").forEach(e=>{z(e,"selected")})})}function tL(n,t){return ra(t)}function eL(n,t,e,o,r){if(o==="ArrowDown"||o==="ArrowRight"){if(e===ni(t))return oi(t)}else if(e===oi(t))return ni(t);return null}function nL(n,t,e,o){const r=ra(t),i=r.map(U),s=i.indexOf(e.childContainerId),l=i.indexOf(o.childContainerId);d(Dn,s!==-1,"invalid start pos"),d(Dn,l!==-1,"invalid end pos");const c=[r[s]];return s!==l&&c.push(r[l]),c}function oL(n,t,e){d(Dn,xo(t),"invalid block type"),t6(n,t,e)}async function rL(n,t){const e=await WD(n);if(!e)return null;const{blockData:o,focusBlockId:r}=e;return n.insertBlock(t.containerId,t.blockIndex,o,At(n,r,0))}function iL(n){return{name:"CodeBlock",insertBlockCommandItems:[{id:"insert-code",name:T.t("code.title"),icon:gB,order:300,group:"common",subText:me("insert-code")}],handleInsertEmptyBlock:rL}}function sL(){return{abstract:`[${T.t("code.abstract")}]`}}function lL(n,t,e,o){const r=t,i=c=>{const a=[];return e.blocks[c].forEach(f=>{var m;a.push(bt((m=f.text)!=null?m:[]))}),a.join(`
387
+ `;function OD(n,t,e){const r={...n.getBlockData(t),language:e};n.updateBlockData(t,r),Se(n,t).forEach(s=>{Mt(s).forEach(l=>{n.reloadBlock(l)})})}function _D(n,t,e){const r={...n.getBlockData(t),nowrap:e};n.updateBlockData(t,r)}async function ND(n){const t=await n.settingsProvider.getItem("editor-code-lang");return t!=null?t:"plain"}async function $D(n,t){return n.settingsProvider.setItem("editor-code-lang",t)}const ar=B("code-block-header"),PD=Object.entries(oa).map(([n,t])=>({id:n,name:t.name,language:t}));function n6(n,t,e){d(ar,To(t),"not a code block");const o=Ut(ni(t));n.selection.selectBlock(o,0),e.focusToEditor&&n.focus()}function jD(n,t){if(t){const e=n,{editor:o,codeBlock:r}=e.custom;OD(o,r,t.id);const i=r.querySelector(".code-block-header .language-select .name-label");i.innerText=t.name,$D(o,t.id),o.focus()}}function HD(n,t,e){n.addCustom("code-header-language-select-dropdown",i=>{const s=new Nw(PD,i.rootElement,{placeholder:"Search for a language..."});return s.onSelected=jD,s});const o=b("div",["language-select"],null);b("span",["name-label"],o,e);const r=b("span",["arrow-icon"],o);return r.innerHTML=MD,n.domEvents.addEventListener(o,"click",(i,s)=>{const c=s.target.closest(".language-select"),a=F(c);d(ar,a,"no parent block"),d(ar,ot(a)==="code","not a code block");const u=i.getBlockData(a),f=i.getCustom("code-header-language-select-dropdown");f.custom={codeBlock:a,editor:i},f.setSelectedId(u.language),f.show(c),n6(i,a,{focusToEditor:!1}),A(t,"editing-language"),f.onHide=()=>{z(t,"editing-language")}}),o}function FD(){return b("div",["code-header-spacer"],null)}function zD(n,t){const e=t.target,o=e.closest(".code-header-button");d(ar,o,"no button");const r=F(e);d(ar,r,"no parent block");const i=o.getAttribute("data-id");if(d(ar,ot(r)==="code","not a code block"),i==="wrap"){const s=n.getBlockData(r);_D(n,r,!s.nowrap);return}if(i==="copy"){n6(n,r,{focusToEditor:!0}),cc(n,r).then(()=>{const s=o.getBoundingClientRect();$w("Copied to clipboard",{position:{x:s.x+s.width/2,y:s.bottom+30}})}).catch(s=>{ar.error(s.message)});return}i==="caption"&&(yD(n,r),setTimeout(()=>{n.focus()}))}function S1(n,t,e,o){const r=b("button",["code-header-button"],null);if(r.setAttribute("data-id",t),o){const i=b("span",["button-icon"],r);i.innerHTML=o}if(e){const i=b("span",["button-label"],r);i.innerHTML=e}return n.domEvents.addEventListener(r,"click",zD),r}function UD(n,t,e){const o=Rt(t),r=b("div",["code-block-header"],o),i=oa[e.language]||oa.plain;r.appendChild(HD(n,t,i.name)),r.appendChild(FD()),r.appendChild(S1(n,"copy","Copy",RD)),r.appendChild(S1(n,"wrap","Wrap",AD)),r.appendChild(S1(n,"caption","Caption",null))}function VD(n,t){!t.target||setTimeout(()=>{n.selection.caret.update()})}function qD(n,t,e,o){T1.init(n);const r=o.children,i=ro(e,"div");i.setAttribute("data-language",o.language||"text"),t6(n,e,o);const s=b("div",["editor-code-root"],i),l=b("div",["code-text-root"],s),c=n.createChildContainer(t,l,r[0]);if(r.length===2){const a=b("div",["code-caption-root"],s);n.createChildContainer(t,a,r[1])}return n.domEvents.addEventListener(c,"scroll",VD),UD(n,e,o),i}async function WD(n){const t={id:N(),type:"text",text:[]},e=N();n.doc.localInsertChildContainer(e,[t]);const o=await ND(n);return{blockData:{id:N(),type:"code",language:o,children:[e]},focusBlockId:t.id}}const Dn=B("list-block");function GD(n,t,e,o,r){ID(n),TD(n),d(Dn,r.type==="code","invalid block data type");const i=r;return d(Dn,i.children,"invalid block data children"),d(Dn,i.children.length===1||i.children.length===2,"invalid block data children length"),qD(n,t,o,i)}function ZD(n){return 1}function YD(n,t,e,o){const r=document.elementsFromPoint(e,o)[0];if(!r||!t.contains(r)||!n.contains(t)||!bn(r))return null;const i=ra(t);if(!bn(r))return null;const s=r;if(i.indexOf(s)===-1||Ge(s)>1)return null;const l=wt(t,U(s));return new Xe(n,{anchor:l,focus:l})}function QD(n,t,e,o){return null}function KD(n,t){return n.getBoundingClientRect()}function JD(n,t,e,o){if(e.isSimple()){d(Dn,o.isSimple(),"from is simple position but to is not simple position"),Dn.debug("full select list"),A(t,"full-selected");return}d(Dn,!o.isSimple(),"from is complex position but end is simple position");const r=e,i=o;d(Dn,r.blockId===i.blockId,"only allow update one table selection"),ra(t).forEach(l=>{const c=U(l);(c===r.childContainerId||c===i.childContainerId)&&A(l,"selected")})}function XD(n){n.rootContainer.querySelectorAll('[data-type="editor-block"][data-block-type="code"]').forEach(t=>{z(t,"full-selected"),t.querySelectorAll("div[data-type=editor-container].child.selected").forEach(e=>{z(e,"selected")})})}function tL(n,t){return ra(t)}function eL(n,t,e,o,r){if(o==="ArrowDown"||o==="ArrowRight"){if(e===ni(t))return oi(t)}else if(e===oi(t))return ni(t);return null}function nL(n,t,e,o){const r=ra(t),i=r.map(U),s=i.indexOf(e.childContainerId),l=i.indexOf(o.childContainerId);d(Dn,s!==-1,"invalid start pos"),d(Dn,l!==-1,"invalid end pos");const c=[r[s]];return s!==l&&c.push(r[l]),c}function oL(n,t,e){d(Dn,To(t),"invalid block type"),t6(n,t,e)}async function rL(n,t){const e=await WD(n);if(!e)return null;const{blockData:o,focusBlockId:r}=e;return n.insertBlock(t.containerId,t.blockIndex,o,At(n,r,0))}function iL(n){return{name:"CodeBlock",insertBlockCommandItems:[{id:"insert-code",name:T.t("code.title"),icon:gB,order:300,group:"common",subText:me("insert-code")}],handleInsertEmptyBlock:rL}}function sL(){return{abstract:`[${T.t("code.abstract")}]`}}function lL(n,t,e,o){const r=t,i=c=>{const a=[];return e.blocks[c].forEach(f=>{var m;a.push(bt((m=f.text)!=null?m:[]))}),a.join(`
388
388
  `)},s=i(r.children[0]),l=r.children[1]?i(r.children[1]):"";return o==="text"?`${s}
389
389
  ${l}`:o==="markdown"?`\`\`\`${r.language}
390
390
  ${s}
391
391
  \`\`\`
392
392
  ${l}`:`<p><pre><code>${s}</code></pre></p>
393
393
  <p>${l}</p>`}const Ps={blockType:"code",blockKind:"complex",createBlockContent:GD,getBlockTextLength:ZD,getRangeFromPoint:YD,moveCaret:QD,getCaretRect:KD,updateSelection:JD,clearSelection:XD,getChildContainers:tL,getNextContainer:eL,getSelectedContainers:nL,convertFrom:vD,handleBlockElementUpdated:oL,getOptions:iL,getBlockProperties:sL,convertTo:lL},D1={...ke,blockType:"code-line"};class cL{constructor(t){h(this,"handleSelectionChange",()=>{const t=this.editor.selection;if(!t.range.isCollapsed())return;const e=t.focusedBlock;if(!ri(e))return;const o=e,r=t.range.focus.offset,i=Ag(this.editor,o,r,"code-caret");i.scrollIntoView({block:"nearest"}),setTimeout(()=>{i.remove(),this.editor.selection.caret.update()})});this.editor=t,t.addListener("selectionChanged",this.handleSelectionChange)}destroy(){this.editor.removeListener("selectionChanged",this.handleSelectionChange)}}function o6(n,t){const e=n.split(`
394
- `).map(s=>({id:N(),type:"text",text:Qo(s)})),o=N();return{blocks:{root:[{children:[o],type:"code",id:N(),...t}],[o]:e},meta:{},comments:{}}}class aL{handleBeforeCopy(t,e,o){const r=t.getFocusedBlock();if(!ri(r))return;const i=B1(r),s=t.getBlockData(i),{language:l,nowrap:c}=s;if(t.selection.range.isCollapsed()){const u=t.getBlockString(r);return o6(u,{language:l,nowrap:c})}const a=t.getSelectedText();return o6(a,{language:l,nowrap:c})}}function dL(n){if(!n.isWritable())return!1;const t=n.getFocusedBlock();if(!!ri(t)){if(n.selection.range.isCollapsed()){const e=n.selection.range.start;return n.insertTextToBlock(t,e.offset," "),!0}return n.undoManager.runInGroup(()=>{tn(n).forEach(o=>{n.insertTextToBlock(o.block,0," ")})}),!0}}function uL(n){if(!n.isWritable())return!1;const t=n.getFocusedBlock();if(!ri(t))return;const e=[" "," "];return n.undoManager.runInGroup(()=>{tn(n).forEach(r=>{const i=bt(n.getBlockText(r.block));for(let s=0;s<e.length;s++){const l=e[s];if(i.startsWith(l)){n.deleteTextFromBlock(r.block,0,l.length);break}}})}),!0}function hL(n){const t=n.getFocusedBlock(),e=H(t);if(pt(e))return;const o=F(e);if(!o||ot(o)!=="code")return;const r=n.selection.range;if(!!r.isSimple()&&!R0(e,r))return Du(n,e),!0}const fL={Tab:dL,"Shift+Tab":uL,"CtrlOrCmd+A":hL},js=B("code-text-decorate");class Hs{decorateText(t,e,o){var C;if(d(js,e.length>0,"invalid path"),e.length===1)return{};const r=e[e.length-2];if(t.doc.getBlockData(r.containerId,r.blockIndex).type!=="code")return{};const s=o;if(s.length===0)return{};const l=bt(s),c=t.doc.getBlockData(r.containerId,r.blockIndex),a=Si.default.tokenize(l,(C=Si.default.languages[c.language])!=null?C:Si.default.languages.plain),u=(k,w)=>{if(d(js,k,"no token"),typeof k=="string")return[{insert:k,attributes:Y.default(w)}];d(js,k instanceof Si.default.Token,"invalid token type");const y=k.content,S=Y.default(w);return S[`style-code-${k.type}`]=!0,typeof y=="string"?[{insert:y,attributes:S}]:Array.isArray(y)?y.map(R=>u(R,S)).flat():(d(js,y instanceof Si.default.Token,"invalid token"),u(y,S))},m=a.map(k=>u(k,{})).flat();return d(js,ue(m)===ue(s),"failed to highlight code, text length mismatch"),{text:m}}}const mL={code:{title:"\u4EE3\u7801",abstract:"\u4EE3\u7801"}},gL={code:{title:"Code",abstract:"Code"}};T.mergeLang({"zh-CN":mL,"en-US":gL});const pL=B("image-data"),CL=1e3,bL=400,kL=10;function Fs(n){return n.src.startsWith("empty:")||!n.src}function vL(n){return n.src.startsWith("http:")||n.src.startsWith("https:")}function r6(n){return`${Ti.default(n)}_width`}function i6(n){return`${Ti.default(n)}_height`}function s6(n){return`${n}_flex`}function zs(n){if(n.every(r=>typeof r.flex=="number"&&r.flex))return;const t=100,o=n.map(r=>r.width/(r.height/t)).reduce((r,i)=>r+i,0);n.forEach(r=>{const i=r.width/(r.height/t);r.flex=i/o})}function ii(n){const t=(r,i)=>{r||(r=`empty:${i}`);const s=r6(r),l=i6(r),c=s6(i);let a=n[s],u=n[l],f=n[c];return typeof a=="string"&&(a=Number.parseInt(a,10)),typeof u=="string"&&(u=Number.parseInt(u,10)),typeof f=="string"&&(f=Number.parseInt(f,10)),a&&u?{src:r,width:a,height:u,flex:f,virtualSize:!1}:(a=CL,u=bL,{src:r,width:a,height:u,flex:f,virtualSize:!0})};let e=[];const o=n.src;return Array.isArray(o)?e=o.map(t):typeof o=="string"&&(e=o.split("|").map(t)),zs(e),e}function hn(n){var o;const t=n.embedData;return ii(n.embedData).length>1?100:(o=t.widthPercent)!=null?o:100}function yL(n,t){if(ii(t.embedData).length>1)return"100%";const o=hn(t);return`${n.rootContainer.getBoundingClientRect().width*o/100}px`}function se(n,t){const o={src:n.map(r=>r.src).join("|"),widthPercent:t};return n.forEach((r,i)=>{if(r.width&&r.height&&!r.virtualSize){const l=r.src||`empty:${i}`,c=r6(l);o[c]=r.width;const a=i6(l);o[a]=r.height}d(pL,r.flex,"no image flex");const s=s6(i);o[s]=r.flex}),o}function wL(n,t,e){const o=ii(t.embedData),r=o.length===1?n.rootContainer:e,i=hn(t);let s=r.getBoundingClientRect().width*(i/100);if(s-=Number.parseFloat(window.getComputedStyle(r).paddingLeft)+Number.parseFloat(window.getComputedStyle(r).paddingRight),o.length===1){const a=o[0];return a.height/(a.width/s)}s-=(o.length-1)*kL;const l=o.reduce((a,u)=>a+u.flex,0);let c=0;for(const a of o){const f=s*a.flex/l/a.width*a.height;c=Math.max(f,c)}return c}function BL(n){return n.reduce((e,o)=>e+o.flex,0)}const EL=B("image-dom");function l6(n){return n.querySelector(".uploading-progress-mask")}function IL(n){const t=l6(n);if(t)return t;const e=b("div",["uploading-progress-mask"],n),o=b("div",["uploading-progress-bar"],e);return b("div",["uploading-progress-bar-value"],o),o}function xL(n){const e=IL(n).querySelector(".uploading-progress-bar-value");return d(EL,e,"no progress value"),e}function c6(n,t){const e=xL(n);e.style.width=`${t}%`}function TL(n){var t;(t=l6(n))==null||t.remove()}function SL(n){let t;return n.forEach((e,o)=>{o.toLocaleLowerCase()==="content-type"&&(t=e)}),t!=null?t:""}async function DL(n){try{const t=await fetch(n,{credentials:"same-origin"}),e=await t.blob(),o=SL(t.headers).toLocaleLowerCase();let r="";if(o){const s=Kf.default[o].extensions;s&&s.length>0&&(r=s[0])}return new File([e],`${Date.now()}.${r}`,{type:o})}catch{return null}}function dr(n,t){const e=typeof t=="string"?t:q(t);return n.getCustom(`image-${e}`)}function ia(n,t){if(!t||!(t instanceof Node))return null;const e=F(t);return e?dr(n,e):null}function Qn(n){return Array.from(n.querySelectorAll(".image-container"))}function sa(n,t,e,o){const r=e!=null?e:n.findBlockById(t.id);if(!r)return;const i=o||H(r),s=yL(n,t),l=wL(n,t,i),c=it(r);c.style.width=s;const a=r.querySelector(".images");!a||(a.style.height=`${l}px`)}const L1=B("table-resize-drag-drop");class LL{constructor(t,e,o,r){h(this,"cursor","col-resize");h(this,"initWidths");this.editor=t,this.elem=e,this.data=o,this.mouseDownEvent=r;const i=this.data.block,l=dr(this.editor,i).getImages(),c=this.data.splitterIndex;d(L1,c>=0&&c<l.length-1,`invalid splitter index: ${c}`);const u=Qn(i).map(f=>f.getBoundingClientRect().width);this.initWidths=u}onDragStart(t,e,o){if(!this.editor.isWritable())return;const r=this.data.block;dr(this.editor,r).setResizing(!0)}onDragging(t,e,o,r,i){const s=this.data.block,l=dr(this.editor,s),c=Y.default(l.getImages()),a=this.data.splitterIndex;d(L1,a>=0&&a<c.length-1,`invalid splitter index: ${a}`);const u=this.initWidths[a],f=this.initWidths[a+1];if(u+f<100)return;let m=r;u+m<50&&(m=50-u),f-m<50&&(m=f-50);const w=[...this.initWidths];w[a]+=m,w[a+1]-=m;const y=Qn(s);d(L1,y.length===c.length,"invalid image data");const S=w.reduce((R,$)=>R+$,0);for(let R=0;R<c.length;R++){const $=w[R]/S;c[R].flex=$,y[R].style.flexGrow=`${$}`}const I=Y.default(this.editor.getBlockData(s)),M=se(c,hn(I));I.embedData=M,sa(this.editor,I,s,null)}onDragEnd(t,e,o,r,i){const s=this.data.block,l=dr(this.editor,s),a=Qn(s).map(u=>Number.parseFloat(u.style.flexGrow));l.updateFlex(a),l.setResizing(!1)}}function a6(n){var t;return!n||!(n instanceof HTMLElement)?null:nt(n,"image-splitter")?n:(t=n.closest(".image-splitter"))!=null?t:null}function ML(n,t){var s;const e=a6(t.target);if(!e)return;const o=F(e);if(!o)return;dr(n,o).setSelectedIndex(-1),n.selection.selectBlock(o,0);const r=Number.parseInt((s=e.getAttribute("data-index"))!=null?s:"",10);if(Number.isNaN(r)||typeof r!="number")return;const i={block:o,splitterIndex:r};sd(new LL(n,e,i,t))}function RL(n,t){t.preventDefault(),t.stopPropagation();const e=a6(t.target);if(!e)return;const o=F(e);!o||dr(n,o).resetFlex()}function AL(n,t,e,o){const r=b("div",["image-splitter"],e);b("div",["image-splitter-indicator"],r),r.setAttribute("data-index",`${o}`),n.domEvents.addEventListener(r,"mousedown",ML),n.domEvents.addEventListener(r,"dblclick",RL)}const OL=B("image-item");function d6(n){return!n||!(n instanceof Node)?null:F(n)}function u6(n){const t=d6(n);return t?Qn(t):[]}function M1(n){if(!n||!(n instanceof Node))return null;const t=n instanceof Element?n:n.parentElement;if(!t)return null;const e=t.closest(".image-container");return e||null}function Us(n){const t=M1(n);return t?u6(n).indexOf(t):-1}async function _L(n,t){const e=ia(n,t.target);if(!e)return;const o=Us(t.target);if(o===-1)return;const r=t.target;if(!(r instanceof HTMLImageElement))return;const i=e.getImages()[o];if(i.virtualSize&&e.fixImageSize(o,r),!i||!vL(i)||i.downloading)return;i.downloading=!0;const s=await DL(i.src);s?e.replaceImage(o,s):OL.warn(`failed to download image: ${i.src}`)}function NL(n,t,e){if(t.querySelector(".load-error"))return;const r=e.src.startsWith("http:")||e.src.startsWith("https:"),i=b("div",["load-error"],t),s=b("div",["error-icon"],i);s.innerHTML=i5;const l=b("div",["error-message"],i);r?(l.innerHTML=T.t("image.load.remote.failed"),n.domEvents.addEventListener(i,"click",(c,a)=>{a.preventDefault(),a.target instanceof HTMLElement&&a.target.tagName==="A"&&window.open(e.src,"_blank")})):(l.innerHTML=T.t("image.load.failed"),n.domEvents.addEventListener(i,"click",(c,a)=>{a.preventDefault(),a.target instanceof HTMLElement&&a.target.tagName==="A"&&HL(c,a.target)}))}function $L(n,t){const e=ia(n,t.target);if(!e)return;const o=Us(t.target);if(o===-1)return;const r=e.getImages()[o];if(!r)return;const i=M1(t.target);!i||(A(i,"error","error-load"),NL(n,i,r))}function PL(n,t,e){if(t.querySelector(".upload-error"))return;const r=b("div",["upload-error"],t),i=b("div",["error-icon"],r);i.innerHTML=i5;const s=b("div",["error-message"],r);s.innerHTML=T.t("image.upload.failed"),n.domEvents.addEventListener(r,"click",(l,c)=>{if(c.preventDefault(),!c.target||!(c.target instanceof Element)||c.target.tagName!=="A")return;const a=ia(l,c.target),u=Us(c.target);!a||u===-1||a.replaceImage(u,e)})}function h6(n,t,e,o,r){const i=Qn(t)[e];!i||(A(i,"error","error-upload"),PL(n,i,r))}function f6(n,t,e,o,r,i){const s=b("div",["image-container"],t);if(s.setAttribute("data-src",e.src),i.length>1&&(s.style.flexShrink=`${e.flex}`,s.style.flexGrow=`${e.flex}`),r===o&&A(s,"active"),Fs(e)){A(s,"empty");const c=b("div",["upload-image-icon"],s);return c.innerHTML=Jw,s}const l=b("img",["editor-image"],s);if(l.src=n.doc.buildResourceUrl(e.src),l.draggable=!0,!Fs(e)&&!n.readonly&&n.domEvents.addEventListener(l,"load",_L),n.domEvents.addEventListener(l,"error",$L),e.src.startsWith("https:")||e.src.startsWith("http:")){const c=b("div",["image-warning"],s);c.innerHTML=r5,c.setAttribute(`data-editor-tooltip-${n.clientId}`,T.t("image.load.remote.tooltip"))}return s}function jL(n,t,e,o,r){const i=b("div",["images"],e);return o.forEach((s,l)=>{l>0&&AL(n,t,i,l-1),f6(n,i,s,l,r,o)}),o.length>1&&A(t,"multi"),i}function m6(n,t,e,o,r,i){const l=Array.from(t.querySelectorAll(".image-container"))[o];if(!l)return;const c=f6(n,null,e,o,r,i);l.insertAdjacentElement("beforebegin",c),l.remove()}function Vs(n,t){return Qn(n)[t]}function HL(n,t){const e=d6(t);if(!e)return;const o=Us(t);if(o===-1)return;const r=ia(n,t);if(!r)return;const i=r.getImages()[o];m6(n,e,i,o,r.getSelectedIndex(),r.getImages())}function fn(n){return ot(n)==="embed"&&Oe(n)==="image"}async function g6(n){return new Promise((t,e)=>{const o=new Image;o.onload=()=>{t({width:o.naturalWidth,height:o.naturalHeight})},o.onerror=e,o.src=n})}async function FL(n){const t=await wl(n);return g6(t)}const p6=B("image-object");class zt{constructor(t,e){h(this,"images",[]);h(this,"selectedIndex",-1);h(this,"blockResizer");h(this,"resizing",!1);h(this,"parentContainerResizerObserver",null);h(this,"handleMouseDown",async(t,e)=>{const o=Us(e.target);if(o===-1)return;const r=this.images[o];Fs(r)||this.setSelectedIndex(o)});h(this,"handleEditorResize",()=>{if(this.isEmpty()||this.resizing)return;const t=this.editor.findBlockById(this.blockData.id);!t||sa(this.editor,this.blockData,t,null)});h(this,"handleResizing",(t,e)=>{const o=this.editor.findBlockById(this.blockData.id);if(!o)return;const i=this.editor.rootContainer.getBoundingClientRect().width,s=o.getBoundingClientRect();let l=e.width>s.width?s.width:e.width;l<50&&(l=50);const c=l*100/i;this.blockData.embedData.widthPercent=c,sa(this.editor,this.blockData,o,null)});h(this,"handleResized",t=>{const e=this.editor.findBlockById(this.blockData.id);if(!e)return;const o=se(this.images,hn(this.blockData));this.editor.updateEmbedData(e,o),this.blockResizer.enableResize(e)});h(this,"fixImageSizes",Xt.default(()=>{const t=this.editor.findBlockById(this.blockData.id);if(!t)return;const e=se(this.images,hn(this.blockData));this.editor.updateEmbedData(t,e)},1e3));this.editor=t,this.blockData=e,this.blockResizer=new ta(this.editor,{resize:["top-left","top-right","bottom-left","bottom-right"]}),this.blockResizer.addListener("resizing",this.handleResizing),this.blockResizer.addListener("resized",this.handleResized),this.images=ii(this.blockData.embedData)}destroy(){var t;this.blockResizer.removeAllListeners(),this.blockResizer.destroy(),this.editor.domEvents.removeEventListener(null,null,this.handleMouseDown),(t=this.parentContainerResizerObserver)==null||t.disconnect()}createContent(t,e,o){const r=jL(this.editor,e,o,this.images,this.selectedIndex);this.editor.domEvents.addEventListener(o,"mousedown",this.handleMouseDown),this.editor.addListener("resize",this.handleEditorResize),Ye(t)&&(this.parentContainerResizerObserver=new ResizeObserver(this.handleEditorResize),this.parentContainerResizerObserver.observe(t)),this.isEmpty()?A(r,"empty"):sa(this.editor,this.blockData,e,t),setTimeout(()=>{const i=this.editor.findBlockById(this.blockData.id);i&&this.blockResizer.update(i)})}getImages(){return this.images}getWidthPercent(){return hn(this.blockData)}isEmpty(){return this.images.length===1&&Fs(this.images[0])}setResizing(t){this.resizing=t}getSelectedIndex(){return this.selectedIndex}getBlock(){return this.editor.findBlockById(this.blockData.id)}setSelectedIndex(t){const e=this.getBlock();if(!e||t===this.selectedIndex)return;if(this.selectedIndex!==-1){const r=Vs(e,this.selectedIndex);r&&z(r,"active")}this.selectedIndex=t;const o=Vs(e,t);o&&A(o,"active")}async requestUploadImage(t){const e=this.editor.findBlockById(this.blockData.id);if(!e)return;const o=Vs(e,t);if(nt(o,"error"))return;const r=await Fo("image/*");await this.replaceImage(t,r)}tryEnableResizer(){const t=this.editor.findBlockById(this.blockData.id);if(!t||!this.editor.isWritable())return;const e=Vs(t,0);!this.isEmpty()&&this.images.length===1&&!nt(e,"error")&&this.blockResizer.enableResize(t)}disableResizer(){this.blockResizer.disableResize()}fixImageSize(t,e){const o=this.images[t];Fs(o)||(o.width=e.naturalWidth,o.height=e.naturalHeight,o.virtualSize=!1,this.fixImageSizes())}removeImage(t){const e=this.editor.findBlockById(this.blockData.id);if(!e||t===-1||t>=this.images.length)return!1;const o=Y.default(this.images);o.splice(t,1),o[0].flex=NaN,zs(o),this.selectedIndex>=o.length&&(this.selectedIndex=o.length-1);const r=se(o,hn(this.blockData));return this.editor.updateEmbedData(e,r),!0}async replaceImage(t,e){const o=this.editor.findBlockById(this.blockData.id);if(!o)return!1;try{const i=await wl(e),s=this.images[t];if(s.virtualSize){const{width:c,height:a}=await g6(i);s.width=c,s.height=a,s.virtualSize=!1;const u=se(this.images,hn(this.blockData));this.editor.updateEmbedData(o,u)}const l={...s,src:i};m6(this.editor,o,l,t,this.selectedIndex,this.images),setTimeout(()=>{this.blockResizer.update(o)})}catch(i){return h6(this.editor,o,t,i,e),!1}const r=Vs(o,t);if(!r)return!1;A(r,"uploading"),c6(r,0);try{const i=await this.editor.doc.uploadResource(e,{onProgress:c=>{c6(r,c)}});z(r,"uploading"),this.images[t].src=i.resourceId;const s=this.editor.findBlockById(this.blockData.id);if(!s)return!1;const l=se(this.images,hn(this.blockData));return this.editor.updateEmbedData(s,l),!0}catch(i){p6.error(i);const s=this.editor.findBlockById(this.blockData.id);return s&&(z(r,"uploading"),TL(r),h6(this.editor,s,t,i,e)),!1}}updateFlex(t){const e=this.editor.findBlockById(this.blockData.id);if(!e)return;d(p6,t.length===this.images.length,"invalid flex");for(let r=0;r<this.images.length;r++)this.images[r].flex=t[r];const o=se(this.images,hn(this.blockData));this.editor.updateEmbedData(e,o)}resetFlex(){const t=this.editor.findBlockById(this.blockData.id);if(!t)return;const e=Y.default(this.images);e[0].flex=NaN,zs(e);const o=se(e,hn(this.blockData));this.editor.updateEmbedData(t,o)}setData(t){this.blockData=t,this.images=ii(t.embedData)}static create(t,e){const o=t.addCustom(`image-${e.id}`,()=>new zt(t,e));return o.setData(e),o}static getImageObject(t,e){let o;return typeof e=="string"?o=e:o=q(e),t.getCustom(`image-${o}`)}}const $z="";function C6(n,t,e){const o=zt.getImageObject(n,t),r=Y.default(o.getImages());if(r.length===1){n.deleteBlock(t);return}if(e===-1||e>=r.length)return;const i=BL(r);if(r.splice(e,1),r.length===1){const l=r[0],c=100*(l.flex/i);l.flex=1;const a=se([l],c);n.updateEmbedData(t,a);return}r[0].flex=NaN,zs(r);const s=se(r,o.getWidthPercent());n.updateEmbedData(t,s)}function zL(n,t,e,o){if(t.length===0||o==="after"||o==="before")return!1;let r=o.data;const i=zt.getImageObject(n,e),s=Y.default(i.getImages());return t.forEach(l=>{const c={src:"",flex:1,width:0,height:0,virtualSize:!0};s.splice(r,0,c);const a=se(s,i.getWidthPercent());n.updateEmbedData(e,a),i.replaceImage(r,l),r+=1}),!0}function UL(n,t,e,o,r){var s,l,c;if(xl(e))return zL(n,e,t,o);if(e.type!=="custom"||e.customType!=="image"||!e.data)return;const i=e.data;if(r.isSourceBlock){const a=r.targetBlock,u=H(a);let f=J(a);o==="after"&&(f+=1);const C=100*(i.boundingRect.width/n.rootContainer.getBoundingClientRect().width),k=se([i.image],C),w={id:N(),type:"embed",embedType:"image",embedData:k},y=(l=(s=n.options.componentsOptions)==null?void 0:s.image)==null?void 0:l.defaultAlign;y&&(w.align=y),n.insertBlock(U(u),f,w),C6(n,t,i.index),(c=n.findCustom("drag-handler"))==null||c.handleDragEnd()}else{if(typeof o=="string")return;const a=t;let u=o.data;const f=zt.getImageObject(n,a),m=Y.default(f.getImages());u>m.length&&(u=m.length),n.undoManager.runInGroup(()=>{var k,w;const C=n.getBlockById(e.blockId);if(C===a){const y=i.index,S=u,I=i.image;if(y===S||S===y+1)return;let M=S;y<S?(m.splice(S,0,I),m.splice(y,1),M-=1):(m.splice(y,1),m.splice(S,0,I));const R=se(m,f.getWidthPercent());n.updateEmbedData(a,R),f.setSelectedIndex(M),(k=n.findCustom("drag-handler"))==null||k.handleDragEnd()}else{m.splice(u,0,i.image),m[0].flex=NaN,zs(m);const y=se(m,f.getWidthPercent());n.updateEmbedData(a,y),C6(n,C,i.index),(w=n.findCustom("drag-handler"))==null||w.handleDragEnd()}})}return!0}const VL=2;function la(n,t,e){const o=Qn(t);if(e<=0){const s=o[0].getBoundingClientRect();return new DOMRect(s.left-4,s.top,2,s.height)}if(e===o.length){const s=o[e-1].getBoundingClientRect();return new DOMRect(s.right+2,s.top,2,s.height)}const r=o[e-1].getBoundingClientRect(),i=o[e].getBoundingClientRect();return new DOMRect((i.left+r.right)/2-1,r.top,VL,r.height)}function qL(n,t,e,o,r){for(let i=0;i<e.length;i++){const l=e[i].getBoundingClientRect();if(o<=l.right)return o<=l.left+l.width/2?{rect:la(n,t,i),data:i}:{rect:la(n,t,i+1),data:i+1}}return o>e[e.length-1].getBoundingClientRect().right?{rect:la(n,t,e.length),data:e.length}:{rect:la(n,t,e.length),data:0}}function WL(n,t,e,o,r){const i=Qn(t);if((e==null?void 0:e.type)==="block"||i.length>=6&&(e==null?void 0:e.blockId)!==q(t))return;const s=q(t);if(!(i.length===1&&s===(e==null?void 0:e.blockId)))return qL(n,t,i,o)}const Pz="";function ca(n){const t=Rt(n);let e=t.querySelector(":scope > .block-helper");return e||(e=b("div",["block-helper"],t),b("span",["helper-sizer"],e,"A")),e}function R1(n,t,e){const o=ca(n),i=Array.from(o.children).find(s=>{var c;return Number.parseInt((c=s.getAttribute("data-index"))!=null?c:"0",10)>e});o.insertBefore(t,i!=null?i:null)}const b6=40,GL=20;class ZL{findTargetBlock(t,e){const o=e.target;if(o&&o instanceof Element){const c=F(o);if(c&&It(t.rootContainer,c))return c}let r=e.clientX,i=e.clientY;const s=t.rootContainer.getBoundingClientRect().left;r<s&&s-r<b6&&(r+=b6);let l=document.elementFromPoint(r,i);if(l){const c=F(l);if(c&&It(t.rootContainer,c))return c}if(i-=GL,l=document.elementFromPoint(r,i),l){const c=F(l);if(c&&It(t.rootContainer,c))return c}return null}destroy(){}}class YL extends Zc{constructor(e){super(e,{trigger:[],id:"empty-block-menu"});h(this,"currentBlock",null)}get isVisible(){return this.suggest.menu.isVisible}isInMenu(e){return this.menu.isInCommandBar(e)}show(){const o=this.editor.selection.focusedBlock;this.suggest.popup(o,0,"","")}setBlock(e){this.currentBlock=e}}function QL(n,t){const e=Dd(n,t);if(!e)return[];const o=[];return Object.values(e).forEach(r=>{o.push(...r.commands.map(i=>({...i,source:"block-command",blockMenuItemCustomData:r.group})))}),o}function A1(n,t){const e=c1(n),o=r=>{r.forEach(i=>{i.source=t,i.children&&o(i.children)})};return o(e),e}function KL(n,t,e,o=!1){var a,u;const r=H(t);let s=J(t);Tt(n,t)||o||(s+=1);const l=U(r),c=e;return c.commandProvider?c.commandProvider.executeCommand(n,e,{from:"block-menu",containerId:l,blockIndex:s}):(u=(a=c.blockOptions)==null?void 0:a.handleInsertEmptyBlock)==null?void 0:u.call(a,n,{containerId:l,blockIndex:s,item:e})}function JL(n,t){const e=Qe(n,t),o=n.getBlockData(t);return!(e!=="text"||o.heading)}class XL{constructor(t,e,o){h(this,"source","text-style");h(this,"id","text-style-item");h(this,"name","Text styles");h(this,"element");h(this,"createHeadingItemElement",(t,e,o)=>{var i;const r=o1();this.createItem("text",Bc,e,JL(this.editor,t)),(i=r.insertBlockCommandItems)==null||i.forEach(s=>{s.id&&s.icon&&this.createItem(s.id,s.icon,e,o?o===Number(s.value):!1)})});h(this,"createListItemElement",(t,e,o)=>{const{checkbox:r,ordered:i}=o,l=ot(t)==="list",c=l&&i===!1&&!r,a=l&&i,u=l&&!!r;this.createItem("unordered-list",d5,e,c),this.createItem("ordered-list",u5,e,a),this.createItem("check-list",c5,e,u)});h(this,"handleClick",(t,e)=>{var l,c;if(!e.target||!(e.target instanceof Node))return;const o=e.target instanceof Element?e.target:e.target.parentElement;if(!o)return;const r=o.closest(".text-style-item");if(!r)return;const i=r.id,s="heading-";if(i==="text"&&qc(t,this.block,null),i.startsWith(s)){const a=Number.parseInt(i.substring(s.length),10);a&&qc(t,this.block,a)}if(i==="blockquote"&&t1(t,this.block),i.startsWith("align")){const a=i.replace(/^align-/,"");C4(t,this.block,a)}(i==="unordered-list"||i==="ordered-list"||i==="check-list")&&n1(t,this.block,i),(c=(l=this.options).onAfterStyleItemClick)==null||c.call(l)});this.editor=t,this.block=e,this.options=o,this.element=this.createItemElement(t,e),t.domEvents.addEventListener(this.element,"click",this.handleClick)}createItemElement(t,e){const o=b("div",["text-styles"],null),r=b("div",["text-style-section"],o),i=t.getBlockData(e),s=i.heading,l=i.quoted,c=i.align||"left";return this.createHeadingItemElement(e,r,s),this.createListItemElement(e,r,i),this.createItem("blockquote",a5,r,!!l),this.createItem("align-left",bs,r,c==="left"),this.createItem("align-center",uh,r,c==="center"),this.createItem("align-right",dh,r,c==="right"),o}createItem(t,e,o,r=!1){const i=["style-icon","text-style-item"];r&&i.push("active");const s=vr(e,i,o);s.id=t}}function k6(){return{source:"separator",type:"separator",id:`section-${N()}`,name:""}}const v6={copy:pB,cut:CB,delete:bB,"lock-block":kB,"unlock-block":vB,comment:wc};function tM(n,t,e){const o=[],r=P(n,t);if(r&&o.push(new XL(n,t,e)),!Tt(n,t)){r&&o.push(k6());const i=QL(n,t);i.sort((s,l)=>{var c,a;return((c=s.order)!=null?c:0)-((a=l.order)!=null?a:0)}),i.forEach(s=>{s.id in v6&&(s.icon=v6[s.id])}),o.push(...i)}return Tt(n,t)?o.push(...A1(n,"insert-block")):o.push(k6(),{id:"insert-block-before",icon:yB,name:T.t("blockMenu.command.insertAbove"),children:A1(n,"insert-block-before"),childrenMenuId:"quick-menu",source:"insert-block-before"},{id:"insert-block-after",icon:wB,name:T.t("blockMenu.command.insertAfter"),children:A1(n,"insert-block"),source:"insert-block",childrenMenuId:"quick-menu"}),o}function eM(n,t,e){if(e.source==="block-command"){const o=e.blockMenuItemCustomData;vg(n,t,o,e)}else(e.source==="insert-block"||e.source==="insert-block-before")&&KL(n,t,e,e.source==="insert-block-before")}function aa(n,t){return n.getBlockData(t).lock}function O1(n,t){return!!aa(n,t)}function da(n,t){const e=aa(n,t);return e?e.userId===n.doc.getUser().userId:!1}function nM(n,t){const e=aa(n,t);return e?e.userId!==n.doc.getUser().userId:!1}function y6(n,t){if(n.readonly||!n.isBlockWritable(t)||O1(n,t)&&!da(n,t))return;const e=n.doc.getUser(),o={userId:e.userId,displayName:e.displayName,locked:Date.now()},i={...n.getBlockData(t),lock:o};n.updateBlockData(t,i)}function w6(n,t){if(!da(n,t))return;const e={lock:null};n.updateBlockData(t,e)}class B6{constructor(){h(this,"executeCommand",(t,e,o)=>{const r=o.data;if(!r||!r.blockId)return;const i=t.getBlockById(r.blockId);r.type==="lock"?y6(t,i):r.type==="unlock"&&w6(t,i)})}create(t,e,o,r,i){const s=i.lock;s&&(s.userId!==t.doc.getUser().userId?A(r,"locked-by-others"):A(r,"locked-by-self"))}writable(t,e){if(nM(t,e))return!1}commands(t,e){const o=O1(t,e),r=da(t,e),i={blockId:q(e),type:"lock"},s={id:"lock-block",name:"",data:i,order:10};if(o)if(r)s.id="unlock-block",s.name=T.t("locker.unlock"),i.type="unlock";else{const l=aa(t,e);s.name=T.t("locker.lockedBy",{name:(l==null?void 0:l.displayName)||""}),s.states=["disabled"]}else s.name=T.t("locker.lock");return{group:"block-locker",commands:[s],executeCommand:this.executeCommand}}}const jz="",oM={locker:{lock:"\u9501\u5B9A",unlock:"\u89E3\u9664\u9501\u5B9A",lockedBy:"\u88AB {name} \u9501\u5B9A"}},rM={locker:{lock:"Lock",unlock:"Unlock",lockedBy:"Locked by {name}"}};T.mergeLang({"zh-CN":oM,"en-US":rM});const iM=B("standard-block-actions");class sM{constructor(){h(this,"executeCommand",(t,e,o)=>{const r=o.data;try{const i=t.getBlockById(r);if(o.id==="delete"){t.deleteBlock(i);return}o.id==="copy"&&cc(t,i),o.id==="cut"&&(cc(t,i),t.deleteBlock(i))}catch(i){iM.error(`failed to execute block command: ${JSON.stringify(i)}`)}})}commands(t,e){const o=O1(t,e),r=o&&da(t,e),i=q(e);return{group:"standard-block-actions",commands:[{id:"copy",name:"Copy",data:i,order:1},{id:"cut",name:"Cut",data:i,order:2,states:o&&!r?["disabled"]:[]},{id:"delete",name:"Delete",data:i,order:3,states:o&&!r?["disabled"]:[]}],executeCommand:this.executeCommand}}}const E6=B("block-menu");class lM{constructor(t){h(this,"menu");h(this,"currentBlock",null);h(this,"commandBlock",null);h(this,"handleShow",()=>{d(E6,this.currentBlock,"no target block before show block menu");const t=tM(this.editor,this.currentBlock,{onAfterStyleItemClick:this.close});this.menu.updateItems(t),this.commandBlock=this.currentBlock});h(this,"handleClose",()=>{gh(this.editor)&&this.editor.focus()});h(this,"handleItemClick",(t,e)=>{d(E6,this.commandBlock,"no command block before show block menu"),eM(this.editor,this.commandBlock,e),!e.element&&!e.children&&this.close()});h(this,"close",()=>{this.menu.close()});this.editor=t,this.menu=new nr([],void 0,{id:"block-menu"}),this.menu.on("show",this.handleShow),this.menu.on("close",this.handleClose),this.menu.on("click",this.handleItemClick),t.blockHooks.push(new sM)}show(t){this.menu.manualShow(t,{placement:"bottom-start"})}isInMenu(t){return this.menu.isInCommandBar(t)}setBlock(t){this.currentBlock=t}get isVisible(){return this.menu.isVisible}destroy(){this.menu.destroy()}}const I6=`<svg width="16" height="17" viewBox="0 0 16 17" fill="none" xmlns="http://www.w3.org/2000/svg">
394
+ `).map(s=>({id:N(),type:"text",text:Qo(s)})),o=N();return{blocks:{root:[{children:[o],type:"code",id:N(),...t}],[o]:e},meta:{},comments:{}}}class aL{handleBeforeCopy(t,e,o){const r=t.getFocusedBlock();if(!ri(r))return;const i=B1(r),s=t.getBlockData(i),{language:l,nowrap:c}=s;if(t.selection.range.isCollapsed()){const u=t.getBlockString(r);return o6(u,{language:l,nowrap:c})}const a=t.getSelectedText();return o6(a,{language:l,nowrap:c})}}function dL(n){if(!n.isWritable())return!1;const t=n.getFocusedBlock();if(!!ri(t)){if(n.selection.range.isCollapsed()){const e=n.selection.range.start;return n.insertTextToBlock(t,e.offset," "),!0}return n.undoManager.runInGroup(()=>{tn(n).forEach(o=>{n.insertTextToBlock(o.block,0," ")})}),!0}}function uL(n){if(!n.isWritable())return!1;const t=n.getFocusedBlock();if(!ri(t))return;const e=[" "," "];return n.undoManager.runInGroup(()=>{tn(n).forEach(r=>{const i=bt(n.getBlockText(r.block));for(let s=0;s<e.length;s++){const l=e[s];if(i.startsWith(l)){n.deleteTextFromBlock(r.block,0,l.length);break}}})}),!0}function hL(n){const t=n.getFocusedBlock(),e=H(t);if(pt(e))return;const o=F(e);if(!o||ot(o)!=="code")return;const r=n.selection.range;if(!!r.isSimple()&&!R0(e,r))return Du(n,e),!0}const fL={Tab:dL,"Shift+Tab":uL,"CtrlOrCmd+A":hL},js=B("code-text-decorate");class Hs{decorateText(t,e,o){var C;if(d(js,e.length>0,"invalid path"),e.length===1)return{};const r=e[e.length-2];if(t.doc.getBlockData(r.containerId,r.blockIndex).type!=="code")return{};const s=o;if(s.length===0)return{};const l=bt(s),c=t.doc.getBlockData(r.containerId,r.blockIndex),a=Si.default.tokenize(l,(C=Si.default.languages[c.language])!=null?C:Si.default.languages.plain),u=(k,w)=>{if(d(js,k,"no token"),typeof k=="string")return[{insert:k,attributes:Y.default(w)}];d(js,k instanceof Si.default.Token,"invalid token type");const y=k.content,S=Y.default(w);return S[`style-code-${k.type}`]=!0,typeof y=="string"?[{insert:y,attributes:S}]:Array.isArray(y)?y.map(R=>u(R,S)).flat():(d(js,y instanceof Si.default.Token,"invalid token"),u(y,S))},m=a.map(k=>u(k,{})).flat();return d(js,ue(m)===ue(s),"failed to highlight code, text length mismatch"),{text:m}}}const mL={code:{title:"\u4EE3\u7801",abstract:"\u4EE3\u7801"}},gL={code:{title:"Code",abstract:"Code"}};T.mergeLang({"zh-CN":mL,"en-US":gL});const pL=B("image-data"),CL=1e3,bL=400,kL=10;function Fs(n){return n.src.startsWith("empty:")||!n.src}function vL(n){return n.src.startsWith("http:")||n.src.startsWith("https:")}function r6(n){return`${Ti.default(n)}_width`}function i6(n){return`${Ti.default(n)}_height`}function s6(n){return`${n}_flex`}function zs(n){if(n.every(r=>typeof r.flex=="number"&&r.flex))return;const t=100,o=n.map(r=>r.width/(r.height/t)).reduce((r,i)=>r+i,0);n.forEach(r=>{const i=r.width/(r.height/t);r.flex=i/o})}function ii(n){const t=(r,i)=>{r||(r=`empty:${i}`);const s=r6(r),l=i6(r),c=s6(i);let a=n[s],u=n[l],f=n[c];return typeof a=="string"&&(a=Number.parseInt(a,10)),typeof u=="string"&&(u=Number.parseInt(u,10)),typeof f=="string"&&(f=Number.parseInt(f,10)),a&&u?{src:r,width:a,height:u,flex:f,virtualSize:!1}:(a=CL,u=bL,{src:r,width:a,height:u,flex:f,virtualSize:!0})};let e=[];const o=n.src;return Array.isArray(o)?e=o.map(t):typeof o=="string"&&(e=o.split("|").map(t)),zs(e),e}function hn(n){var o;const t=n.embedData;return ii(n.embedData).length>1?100:(o=t.widthPercent)!=null?o:100}function yL(n,t){if(ii(t.embedData).length>1)return"100%";const o=hn(t);return`${n.rootContainer.getBoundingClientRect().width*o/100}px`}function se(n,t){const o={src:n.map(r=>r.src).join("|"),widthPercent:t};return n.forEach((r,i)=>{if(r.width&&r.height&&!r.virtualSize){const l=r.src||`empty:${i}`,c=r6(l);o[c]=r.width;const a=i6(l);o[a]=r.height}d(pL,r.flex,"no image flex");const s=s6(i);o[s]=r.flex}),o}function wL(n,t,e){const o=ii(t.embedData),r=o.length===1?n.rootContainer:e,i=hn(t);let s=r.getBoundingClientRect().width*(i/100);if(s-=Number.parseFloat(window.getComputedStyle(r).paddingLeft)+Number.parseFloat(window.getComputedStyle(r).paddingRight),o.length===1){const a=o[0];return a.height/(a.width/s)}s-=(o.length-1)*kL;const l=o.reduce((a,u)=>a+u.flex,0);let c=0;for(const a of o){const f=s*a.flex/l/a.width*a.height;c=Math.max(f,c)}return c}function BL(n){return n.reduce((e,o)=>e+o.flex,0)}const EL=B("image-dom");function l6(n){return n.querySelector(".uploading-progress-mask")}function IL(n){const t=l6(n);if(t)return t;const e=b("div",["uploading-progress-mask"],n),o=b("div",["uploading-progress-bar"],e);return b("div",["uploading-progress-bar-value"],o),o}function xL(n){const e=IL(n).querySelector(".uploading-progress-bar-value");return d(EL,e,"no progress value"),e}function c6(n,t){const e=xL(n);e.style.width=`${t}%`}function TL(n){var t;(t=l6(n))==null||t.remove()}function SL(n){let t;return n.forEach((e,o)=>{o.toLocaleLowerCase()==="content-type"&&(t=e)}),t!=null?t:""}async function DL(n){try{const t=await fetch(n,{credentials:"same-origin"}),e=await t.blob(),o=SL(t.headers).toLocaleLowerCase();let r="";if(o){const s=Kf.default[o].extensions;s&&s.length>0&&(r=s[0])}return new File([e],`${Date.now()}.${r}`,{type:o})}catch{return null}}function dr(n,t){const e=typeof t=="string"?t:q(t);return n.getCustom(`image-${e}`)}function ia(n,t){if(!t||!(t instanceof Node))return null;const e=F(t);return e?dr(n,e):null}function Qn(n){return Array.from(n.querySelectorAll(".image-container"))}function sa(n,t,e,o){const r=e!=null?e:n.findBlockById(t.id);if(!r)return;const i=o||H(r),s=yL(n,t),l=wL(n,t,i),c=it(r);c.style.width=s;const a=r.querySelector(".images");!a||(a.style.height=`${l}px`)}const L1=B("table-resize-drag-drop");class LL{constructor(t,e,o,r){h(this,"cursor","col-resize");h(this,"initWidths");this.editor=t,this.elem=e,this.data=o,this.mouseDownEvent=r;const i=this.data.block,l=dr(this.editor,i).getImages(),c=this.data.splitterIndex;d(L1,c>=0&&c<l.length-1,`invalid splitter index: ${c}`);const u=Qn(i).map(f=>f.getBoundingClientRect().width);this.initWidths=u}onDragStart(t,e,o){if(!this.editor.isWritable())return;const r=this.data.block;dr(this.editor,r).setResizing(!0)}onDragging(t,e,o,r,i){const s=this.data.block,l=dr(this.editor,s),c=Y.default(l.getImages()),a=this.data.splitterIndex;d(L1,a>=0&&a<c.length-1,`invalid splitter index: ${a}`);const u=this.initWidths[a],f=this.initWidths[a+1];if(u+f<100)return;let m=r;u+m<50&&(m=50-u),f-m<50&&(m=f-50);const w=[...this.initWidths];w[a]+=m,w[a+1]-=m;const y=Qn(s);d(L1,y.length===c.length,"invalid image data");const S=w.reduce((R,$)=>R+$,0);for(let R=0;R<c.length;R++){const $=w[R]/S;c[R].flex=$,y[R].style.flexGrow=`${$}`}const I=Y.default(this.editor.getBlockData(s)),M=se(c,hn(I));I.embedData=M,sa(this.editor,I,s,null)}onDragEnd(t,e,o,r,i){const s=this.data.block,l=dr(this.editor,s),a=Qn(s).map(u=>Number.parseFloat(u.style.flexGrow));l.updateFlex(a),l.setResizing(!1)}}function a6(n){var t;return!n||!(n instanceof HTMLElement)?null:nt(n,"image-splitter")?n:(t=n.closest(".image-splitter"))!=null?t:null}function ML(n,t){var s;const e=a6(t.target);if(!e)return;const o=F(e);if(!o)return;dr(n,o).setSelectedIndex(-1),n.selection.selectBlock(o,0);const r=Number.parseInt((s=e.getAttribute("data-index"))!=null?s:"",10);if(Number.isNaN(r)||typeof r!="number")return;const i={block:o,splitterIndex:r};sd(new LL(n,e,i,t))}function RL(n,t){t.preventDefault(),t.stopPropagation();const e=a6(t.target);if(!e)return;const o=F(e);!o||dr(n,o).resetFlex()}function AL(n,t,e,o){const r=b("div",["image-splitter"],e);b("div",["image-splitter-indicator"],r),r.setAttribute("data-index",`${o}`),n.domEvents.addEventListener(r,"mousedown",ML),n.domEvents.addEventListener(r,"dblclick",RL)}const OL=B("image-item");function d6(n){return!n||!(n instanceof Node)?null:F(n)}function u6(n){const t=d6(n);return t?Qn(t):[]}function M1(n){if(!n||!(n instanceof Node))return null;const t=n instanceof Element?n:n.parentElement;if(!t)return null;const e=t.closest(".image-container");return e||null}function Us(n){const t=M1(n);return t?u6(n).indexOf(t):-1}async function _L(n,t){const e=ia(n,t.target);if(!e)return;const o=Us(t.target);if(o===-1)return;const r=t.target;if(!(r instanceof HTMLImageElement))return;const i=e.getImages()[o];if(i.virtualSize&&e.fixImageSize(o,r),!i||!vL(i)||i.downloading)return;i.downloading=!0;const s=await DL(i.src);s?e.replaceImage(o,s):OL.warn(`failed to download image: ${i.src}`)}function NL(n,t,e){if(t.querySelector(".load-error"))return;const r=e.src.startsWith("http:")||e.src.startsWith("https:"),i=b("div",["load-error"],t),s=b("div",["error-icon"],i);s.innerHTML=i5;const l=b("div",["error-message"],i);r?(l.innerHTML=T.t("image.load.remote.failed"),n.domEvents.addEventListener(i,"click",(c,a)=>{a.preventDefault(),a.target instanceof HTMLElement&&a.target.tagName==="A"&&window.open(e.src,"_blank")})):(l.innerHTML=T.t("image.load.failed"),n.domEvents.addEventListener(i,"click",(c,a)=>{a.preventDefault(),a.target instanceof HTMLElement&&a.target.tagName==="A"&&HL(c,a.target)}))}function $L(n,t){const e=ia(n,t.target);if(!e)return;const o=Us(t.target);if(o===-1)return;const r=e.getImages()[o];if(!r)return;const i=M1(t.target);!i||(A(i,"error","error-load"),NL(n,i,r))}function PL(n,t,e){if(t.querySelector(".upload-error"))return;const r=b("div",["upload-error"],t),i=b("div",["error-icon"],r);i.innerHTML=i5;const s=b("div",["error-message"],r);s.innerHTML=T.t("image.upload.failed"),n.domEvents.addEventListener(r,"click",(l,c)=>{if(c.preventDefault(),!c.target||!(c.target instanceof Element)||c.target.tagName!=="A")return;const a=ia(l,c.target),u=Us(c.target);!a||u===-1||a.replaceImage(u,e)})}function h6(n,t,e,o,r){const i=Qn(t)[e];!i||(A(i,"error","error-upload"),PL(n,i,r))}function f6(n,t,e,o,r,i){const s=b("div",["image-container"],t);if(s.setAttribute("data-src",e.src),i.length>1&&(s.style.flexShrink=`${e.flex}`,s.style.flexGrow=`${e.flex}`),r===o&&A(s,"active"),Fs(e)){A(s,"empty");const c=b("div",["upload-image-icon"],s);return c.innerHTML=Jw,s}const l=b("img",["editor-image"],s);if(l.src=n.doc.buildResourceUrl(e.src),l.draggable=!0,!Fs(e)&&!n.readonly&&n.domEvents.addEventListener(l,"load",_L),n.domEvents.addEventListener(l,"error",$L),e.src.startsWith("https:")||e.src.startsWith("http:")){const c=b("div",["image-warning"],s);c.innerHTML=r5,c.setAttribute(`data-editor-tooltip-${n.clientId}`,T.t("image.load.remote.tooltip"))}return s}function jL(n,t,e,o,r){const i=b("div",["images"],e);return o.forEach((s,l)=>{l>0&&AL(n,t,i,l-1),f6(n,i,s,l,r,o)}),o.length>1&&A(t,"multi"),i}function m6(n,t,e,o,r,i){const l=Array.from(t.querySelectorAll(".image-container"))[o];if(!l)return;const c=f6(n,null,e,o,r,i);l.insertAdjacentElement("beforebegin",c),l.remove()}function Vs(n,t){return Qn(n)[t]}function HL(n,t){const e=d6(t);if(!e)return;const o=Us(t);if(o===-1)return;const r=ia(n,t);if(!r)return;const i=r.getImages()[o];m6(n,e,i,o,r.getSelectedIndex(),r.getImages())}function fn(n){return ot(n)==="embed"&&Oe(n)==="image"}async function g6(n){return new Promise((t,e)=>{const o=new Image;o.onload=()=>{t({width:o.naturalWidth,height:o.naturalHeight})},o.onerror=e,o.src=n})}async function FL(n){const t=await wl(n);return g6(t)}const p6=B("image-object");class zt{constructor(t,e){h(this,"images",[]);h(this,"selectedIndex",-1);h(this,"blockResizer");h(this,"resizing",!1);h(this,"parentContainerResizerObserver",null);h(this,"handleMouseDown",async(t,e)=>{const o=Us(e.target);if(o===-1)return;const r=this.images[o];Fs(r)||this.setSelectedIndex(o)});h(this,"handleEditorResize",()=>{if(this.isEmpty()||this.resizing)return;const t=this.editor.findBlockById(this.blockData.id);!t||sa(this.editor,this.blockData,t,null)});h(this,"handleResizing",(t,e)=>{const o=this.editor.findBlockById(this.blockData.id);if(!o)return;const i=this.editor.rootContainer.getBoundingClientRect().width,s=o.getBoundingClientRect();let l=e.width>s.width?s.width:e.width;l<50&&(l=50);const c=l*100/i;this.blockData.embedData.widthPercent=c,sa(this.editor,this.blockData,o,null)});h(this,"handleResized",t=>{const e=this.editor.findBlockById(this.blockData.id);if(!e)return;const o=se(this.images,hn(this.blockData));this.editor.updateEmbedData(e,o),this.blockResizer.enableResize(e)});h(this,"fixImageSizes",Xt.default(()=>{const t=this.editor.findBlockById(this.blockData.id);if(!t)return;const e=se(this.images,hn(this.blockData));this.editor.updateEmbedData(t,e)},1e3));this.editor=t,this.blockData=e,this.blockResizer=new ta(this.editor,{resize:["top-left","top-right","bottom-left","bottom-right"]}),this.blockResizer.addListener("resizing",this.handleResizing),this.blockResizer.addListener("resized",this.handleResized),this.images=ii(this.blockData.embedData)}destroy(){var t;this.blockResizer.removeAllListeners(),this.blockResizer.destroy(),this.editor.domEvents.removeEventListener(null,null,this.handleMouseDown),(t=this.parentContainerResizerObserver)==null||t.disconnect()}createContent(t,e,o){const r=jL(this.editor,e,o,this.images,this.selectedIndex);this.editor.domEvents.addEventListener(o,"mousedown",this.handleMouseDown),this.editor.addListener("resize",this.handleEditorResize),Ye(t)&&(this.parentContainerResizerObserver=new ResizeObserver(this.handleEditorResize),this.parentContainerResizerObserver.observe(t)),this.isEmpty()?A(r,"empty"):sa(this.editor,this.blockData,e,t),setTimeout(()=>{const i=this.editor.findBlockById(this.blockData.id);i&&this.blockResizer.update(i)})}getImages(){return this.images}getWidthPercent(){return hn(this.blockData)}isEmpty(){return this.images.length===1&&Fs(this.images[0])}setResizing(t){this.resizing=t}getSelectedIndex(){return this.selectedIndex}getBlock(){return this.editor.findBlockById(this.blockData.id)}setSelectedIndex(t){const e=this.getBlock();if(!e||t===this.selectedIndex)return;if(this.selectedIndex!==-1){const r=Vs(e,this.selectedIndex);r&&z(r,"active")}this.selectedIndex=t;const o=Vs(e,t);o&&A(o,"active")}async requestUploadImage(t){const e=this.editor.findBlockById(this.blockData.id);if(!e)return;const o=Vs(e,t);if(nt(o,"error"))return;const r=await zo("image/*");await this.replaceImage(t,r)}tryEnableResizer(){const t=this.editor.findBlockById(this.blockData.id);if(!t||!this.editor.isWritable())return;const e=Vs(t,0);!this.isEmpty()&&this.images.length===1&&!nt(e,"error")&&this.blockResizer.enableResize(t)}disableResizer(){this.blockResizer.disableResize()}fixImageSize(t,e){const o=this.images[t];Fs(o)||(o.width=e.naturalWidth,o.height=e.naturalHeight,o.virtualSize=!1,this.fixImageSizes())}removeImage(t){const e=this.editor.findBlockById(this.blockData.id);if(!e||t===-1||t>=this.images.length)return!1;const o=Y.default(this.images);o.splice(t,1),o[0].flex=NaN,zs(o),this.selectedIndex>=o.length&&(this.selectedIndex=o.length-1);const r=se(o,hn(this.blockData));return this.editor.updateEmbedData(e,r),!0}async replaceImage(t,e){const o=this.editor.findBlockById(this.blockData.id);if(!o)return!1;try{const i=await wl(e),s=this.images[t];if(s.virtualSize){const{width:c,height:a}=await g6(i);s.width=c,s.height=a,s.virtualSize=!1;const u=se(this.images,hn(this.blockData));this.editor.updateEmbedData(o,u)}const l={...s,src:i};m6(this.editor,o,l,t,this.selectedIndex,this.images),setTimeout(()=>{this.blockResizer.update(o)})}catch(i){return h6(this.editor,o,t,i,e),!1}const r=Vs(o,t);if(!r)return!1;A(r,"uploading"),c6(r,0);try{const i=await this.editor.doc.uploadResource(e,{onProgress:c=>{c6(r,c)}});z(r,"uploading"),this.images[t].src=i.resourceId;const s=this.editor.findBlockById(this.blockData.id);if(!s)return!1;const l=se(this.images,hn(this.blockData));return this.editor.updateEmbedData(s,l),!0}catch(i){p6.error(i);const s=this.editor.findBlockById(this.blockData.id);return s&&(z(r,"uploading"),TL(r),h6(this.editor,s,t,i,e)),!1}}updateFlex(t){const e=this.editor.findBlockById(this.blockData.id);if(!e)return;d(p6,t.length===this.images.length,"invalid flex");for(let r=0;r<this.images.length;r++)this.images[r].flex=t[r];const o=se(this.images,hn(this.blockData));this.editor.updateEmbedData(e,o)}resetFlex(){const t=this.editor.findBlockById(this.blockData.id);if(!t)return;const e=Y.default(this.images);e[0].flex=NaN,zs(e);const o=se(e,hn(this.blockData));this.editor.updateEmbedData(t,o)}setData(t){this.blockData=t,this.images=ii(t.embedData)}static create(t,e){const o=t.addCustom(`image-${e.id}`,()=>new zt(t,e));return o.setData(e),o}static getImageObject(t,e){let o;return typeof e=="string"?o=e:o=q(e),t.getCustom(`image-${o}`)}}const $z="";function C6(n,t,e){const o=zt.getImageObject(n,t),r=Y.default(o.getImages());if(r.length===1){n.deleteBlock(t);return}if(e===-1||e>=r.length)return;const i=BL(r);if(r.splice(e,1),r.length===1){const l=r[0],c=100*(l.flex/i);l.flex=1;const a=se([l],c);n.updateEmbedData(t,a);return}r[0].flex=NaN,zs(r);const s=se(r,o.getWidthPercent());n.updateEmbedData(t,s)}function zL(n,t,e,o){if(t.length===0||o==="after"||o==="before")return!1;let r=o.data;const i=zt.getImageObject(n,e),s=Y.default(i.getImages());return t.forEach(l=>{const c={src:"",flex:1,width:0,height:0,virtualSize:!0};s.splice(r,0,c);const a=se(s,i.getWidthPercent());n.updateEmbedData(e,a),i.replaceImage(r,l),r+=1}),!0}function UL(n,t,e,o,r){var s,l,c;if(xl(e))return zL(n,e,t,o);if(e.type!=="custom"||e.customType!=="image"||!e.data)return;const i=e.data;if(r.isSourceBlock){const a=r.targetBlock,u=H(a);let f=J(a);o==="after"&&(f+=1);const C=100*(i.boundingRect.width/n.rootContainer.getBoundingClientRect().width),k=se([i.image],C),w={id:N(),type:"embed",embedType:"image",embedData:k},y=(l=(s=n.options.componentsOptions)==null?void 0:s.image)==null?void 0:l.defaultAlign;y&&(w.align=y),n.insertBlock(U(u),f,w),C6(n,t,i.index),(c=n.findCustom("drag-handler"))==null||c.handleDragEnd()}else{if(typeof o=="string")return;const a=t;let u=o.data;const f=zt.getImageObject(n,a),m=Y.default(f.getImages());u>m.length&&(u=m.length),n.undoManager.runInGroup(()=>{var k,w;const C=n.getBlockById(e.blockId);if(C===a){const y=i.index,S=u,I=i.image;if(y===S||S===y+1)return;let M=S;y<S?(m.splice(S,0,I),m.splice(y,1),M-=1):(m.splice(y,1),m.splice(S,0,I));const R=se(m,f.getWidthPercent());n.updateEmbedData(a,R),f.setSelectedIndex(M),(k=n.findCustom("drag-handler"))==null||k.handleDragEnd()}else{m.splice(u,0,i.image),m[0].flex=NaN,zs(m);const y=se(m,f.getWidthPercent());n.updateEmbedData(a,y),C6(n,C,i.index),(w=n.findCustom("drag-handler"))==null||w.handleDragEnd()}})}return!0}const VL=2;function la(n,t,e){const o=Qn(t);if(e<=0){const s=o[0].getBoundingClientRect();return new DOMRect(s.left-4,s.top,2,s.height)}if(e===o.length){const s=o[e-1].getBoundingClientRect();return new DOMRect(s.right+2,s.top,2,s.height)}const r=o[e-1].getBoundingClientRect(),i=o[e].getBoundingClientRect();return new DOMRect((i.left+r.right)/2-1,r.top,VL,r.height)}function qL(n,t,e,o,r){for(let i=0;i<e.length;i++){const l=e[i].getBoundingClientRect();if(o<=l.right)return o<=l.left+l.width/2?{rect:la(n,t,i),data:i}:{rect:la(n,t,i+1),data:i+1}}return o>e[e.length-1].getBoundingClientRect().right?{rect:la(n,t,e.length),data:e.length}:{rect:la(n,t,e.length),data:0}}function WL(n,t,e,o,r){const i=Qn(t);if((e==null?void 0:e.type)==="block"||i.length>=6&&(e==null?void 0:e.blockId)!==q(t))return;const s=q(t);if(!(i.length===1&&s===(e==null?void 0:e.blockId)))return qL(n,t,i,o)}const Pz="";function ca(n){const t=Rt(n);let e=t.querySelector(":scope > .block-helper");return e||(e=b("div",["block-helper"],t),b("span",["helper-sizer"],e,"A")),e}function R1(n,t,e){const o=ca(n),i=Array.from(o.children).find(s=>{var c;return Number.parseInt((c=s.getAttribute("data-index"))!=null?c:"0",10)>e});o.insertBefore(t,i!=null?i:null)}const b6=40,GL=20;class ZL{findTargetBlock(t,e){const o=e.target;if(o&&o instanceof Element){const c=F(o);if(c&&It(t.rootContainer,c))return c}let r=e.clientX,i=e.clientY;const s=t.rootContainer.getBoundingClientRect().left;r<s&&s-r<b6&&(r+=b6);let l=document.elementFromPoint(r,i);if(l){const c=F(l);if(c&&It(t.rootContainer,c))return c}if(i-=GL,l=document.elementFromPoint(r,i),l){const c=F(l);if(c&&It(t.rootContainer,c))return c}return null}destroy(){}}class YL extends Zc{constructor(e){super(e,{trigger:[],id:"empty-block-menu"});h(this,"currentBlock",null)}get isVisible(){return this.suggest.menu.isVisible}isInMenu(e){return this.menu.isInCommandBar(e)}show(){const o=this.editor.selection.focusedBlock;this.suggest.popup(o,0,"","")}setBlock(e){this.currentBlock=e}}function QL(n,t){const e=Dd(n,t);if(!e)return[];const o=[];return Object.values(e).forEach(r=>{o.push(...r.commands.map(i=>({...i,source:"block-command",blockMenuItemCustomData:r.group})))}),o}function A1(n,t){const e=c1(n),o=r=>{r.forEach(i=>{i.source=t,i.children&&o(i.children)})};return o(e),e}function KL(n,t,e,o=!1){var a,u;const r=H(t);let s=J(t);Tt(n,t)||o||(s+=1);const l=U(r),c=e;return c.commandProvider?c.commandProvider.executeCommand(n,e,{from:"block-menu",containerId:l,blockIndex:s}):(u=(a=c.blockOptions)==null?void 0:a.handleInsertEmptyBlock)==null?void 0:u.call(a,n,{containerId:l,blockIndex:s,item:e})}function JL(n,t){const e=Qe(n,t),o=n.getBlockData(t);return!(e!=="text"||o.heading)}class XL{constructor(t,e,o){h(this,"source","text-style");h(this,"id","text-style-item");h(this,"name","Text styles");h(this,"element");h(this,"createHeadingItemElement",(t,e,o)=>{var i;const r=o1();this.createItem("text",Bc,e,JL(this.editor,t)),(i=r.insertBlockCommandItems)==null||i.forEach(s=>{s.id&&s.icon&&this.createItem(s.id,s.icon,e,o?o===Number(s.value):!1)})});h(this,"createListItemElement",(t,e,o)=>{const{checkbox:r,ordered:i}=o,l=ot(t)==="list",c=l&&i===!1&&!r,a=l&&i,u=l&&!!r;this.createItem("unordered-list",d5,e,c),this.createItem("ordered-list",u5,e,a),this.createItem("check-list",c5,e,u)});h(this,"handleClick",(t,e)=>{var l,c;if(!e.target||!(e.target instanceof Node))return;const o=e.target instanceof Element?e.target:e.target.parentElement;if(!o)return;const r=o.closest(".text-style-item");if(!r)return;const i=r.id,s="heading-";if(i==="text"&&qc(t,this.block,null),i.startsWith(s)){const a=Number.parseInt(i.substring(s.length),10);a&&qc(t,this.block,a)}if(i==="blockquote"&&t1(t,this.block),i.startsWith("align")){const a=i.replace(/^align-/,"");C4(t,this.block,a)}(i==="unordered-list"||i==="ordered-list"||i==="check-list")&&n1(t,this.block,i),(c=(l=this.options).onAfterStyleItemClick)==null||c.call(l)});this.editor=t,this.block=e,this.options=o,this.element=this.createItemElement(t,e),t.domEvents.addEventListener(this.element,"click",this.handleClick)}createItemElement(t,e){const o=b("div",["text-styles"],null),r=b("div",["text-style-section"],o),i=t.getBlockData(e),s=i.heading,l=i.quoted,c=i.align||"left";return this.createHeadingItemElement(e,r,s),this.createListItemElement(e,r,i),this.createItem("blockquote",a5,r,!!l),this.createItem("align-left",bs,r,c==="left"),this.createItem("align-center",uh,r,c==="center"),this.createItem("align-right",dh,r,c==="right"),o}createItem(t,e,o,r=!1){const i=["style-icon","text-style-item"];r&&i.push("active");const s=vr(e,i,o);s.id=t}}function k6(){return{source:"separator",type:"separator",id:`section-${N()}`,name:""}}const v6={copy:pB,cut:CB,delete:bB,"lock-block":kB,"unlock-block":vB,comment:wc};function tM(n,t,e){const o=[],r=P(n,t);if(r&&o.push(new XL(n,t,e)),!Tt(n,t)){r&&o.push(k6());const i=QL(n,t);i.sort((s,l)=>{var c,a;return((c=s.order)!=null?c:0)-((a=l.order)!=null?a:0)}),i.forEach(s=>{s.id in v6&&(s.icon=v6[s.id])}),o.push(...i)}return Tt(n,t)?o.push(...A1(n,"insert-block")):o.push(k6(),{id:"insert-block-before",icon:yB,name:T.t("blockMenu.command.insertAbove"),children:A1(n,"insert-block-before"),childrenMenuId:"quick-menu",source:"insert-block-before"},{id:"insert-block-after",icon:wB,name:T.t("blockMenu.command.insertAfter"),children:A1(n,"insert-block"),source:"insert-block",childrenMenuId:"quick-menu"}),o}function eM(n,t,e){if(e.source==="block-command"){const o=e.blockMenuItemCustomData;vg(n,t,o,e)}else(e.source==="insert-block"||e.source==="insert-block-before")&&KL(n,t,e,e.source==="insert-block-before")}function aa(n,t){return n.getBlockData(t).lock}function O1(n,t){return!!aa(n,t)}function da(n,t){const e=aa(n,t);return e?e.userId===n.doc.getUser().userId:!1}function nM(n,t){const e=aa(n,t);return e?e.userId!==n.doc.getUser().userId:!1}function y6(n,t){if(n.readonly||!n.isBlockWritable(t)||O1(n,t)&&!da(n,t))return;const e=n.doc.getUser(),o={userId:e.userId,displayName:e.displayName,locked:Date.now()},i={...n.getBlockData(t),lock:o};n.updateBlockData(t,i)}function w6(n,t){if(!da(n,t))return;const e={lock:null};n.updateBlockData(t,e)}class B6{constructor(){h(this,"executeCommand",(t,e,o)=>{const r=o.data;if(!r||!r.blockId)return;const i=t.getBlockById(r.blockId);r.type==="lock"?y6(t,i):r.type==="unlock"&&w6(t,i)})}create(t,e,o,r,i){const s=i.lock;s&&(s.userId!==t.doc.getUser().userId?A(r,"locked-by-others"):A(r,"locked-by-self"))}writable(t,e){if(nM(t,e))return!1}commands(t,e){const o=O1(t,e),r=da(t,e),i={blockId:q(e),type:"lock"},s={id:"lock-block",name:"",data:i,order:10};if(o)if(r)s.id="unlock-block",s.name=T.t("locker.unlock"),i.type="unlock";else{const l=aa(t,e);s.name=T.t("locker.lockedBy",{name:(l==null?void 0:l.displayName)||""}),s.states=["disabled"]}else s.name=T.t("locker.lock");return{group:"block-locker",commands:[s],executeCommand:this.executeCommand}}}const jz="",oM={locker:{lock:"\u9501\u5B9A",unlock:"\u89E3\u9664\u9501\u5B9A",lockedBy:"\u88AB {name} \u9501\u5B9A"}},rM={locker:{lock:"Lock",unlock:"Unlock",lockedBy:"Locked by {name}"}};T.mergeLang({"zh-CN":oM,"en-US":rM});const iM=B("standard-block-actions");class sM{constructor(){h(this,"executeCommand",(t,e,o)=>{const r=o.data;try{const i=t.getBlockById(r);if(o.id==="delete"){t.deleteBlock(i);return}o.id==="copy"&&cc(t,i),o.id==="cut"&&(cc(t,i),t.deleteBlock(i))}catch(i){iM.error(`failed to execute block command: ${JSON.stringify(i)}`)}})}commands(t,e){const o=O1(t,e),r=o&&da(t,e),i=q(e);return{group:"standard-block-actions",commands:[{id:"copy",name:"Copy",data:i,order:1},{id:"cut",name:"Cut",data:i,order:2,states:o&&!r?["disabled"]:[]},{id:"delete",name:"Delete",data:i,order:3,states:o&&!r?["disabled"]:[]}],executeCommand:this.executeCommand}}}const E6=B("block-menu");class lM{constructor(t){h(this,"menu");h(this,"currentBlock",null);h(this,"commandBlock",null);h(this,"handleShow",()=>{d(E6,this.currentBlock,"no target block before show block menu");const t=tM(this.editor,this.currentBlock,{onAfterStyleItemClick:this.close});this.menu.updateItems(t),this.commandBlock=this.currentBlock});h(this,"handleClose",()=>{gh(this.editor)&&this.editor.focus()});h(this,"handleItemClick",(t,e)=>{d(E6,this.commandBlock,"no command block before show block menu"),eM(this.editor,this.commandBlock,e),!e.element&&!e.children&&this.close()});h(this,"close",()=>{this.menu.close()});this.editor=t,this.menu=new nr([],void 0,{id:"block-menu"}),this.menu.on("show",this.handleShow),this.menu.on("close",this.handleClose),this.menu.on("click",this.handleItemClick),t.blockHooks.push(new sM)}show(t){this.menu.manualShow(t,{placement:"bottom-start"})}isInMenu(t){return this.menu.isInCommandBar(t)}setBlock(t){this.currentBlock=t}get isVisible(){return this.menu.isVisible}destroy(){this.menu.destroy()}}const I6=`<svg width="16" height="17" viewBox="0 0 16 17" fill="none" xmlns="http://www.w3.org/2000/svg">
395
395
  <path fill="currentColor" fill-rule="evenodd" clip-rule="evenodd" d="M6.33341 3.48568C6.33341 4.22204 5.73645 4.81901 5.00008 4.81901C4.26371 4.81901 3.66675 4.22204 3.66675 3.48568C3.66675 2.7493 4.26371 2.15234 5.00008 2.15234C5.73645 2.15234 6.33341 2.7493 6.33341 3.48568ZM5.00008 9.48568C5.73645 9.48568 6.33341 8.88871 6.33341 8.15234C6.33341 7.41598 5.73645 6.81901 5.00008 6.81901C4.26371 6.81901 3.66675 7.41598 3.66675 8.15234C3.66675 8.88871 4.26371 9.48568 5.00008 9.48568ZM5.00008 14.1523C5.73645 14.1523 6.33341 13.5554 6.33341 12.819C6.33341 12.0826 5.73645 11.4857 5.00008 11.4857C4.26371 11.4857 3.66675 12.0826 3.66675 12.819C3.66675 13.5554 4.26371 14.1523 5.00008 14.1523Z" />
396
396
  <path fill="currentColor" fill-rule="evenodd" clip-rule="evenodd" d="M12.3334 3.48568C12.3334 4.22204 11.7364 4.81901 11.0001 4.81901C10.2637 4.81901 9.66675 4.22204 9.66675 3.48568C9.66675 2.7493 10.2637 2.15234 11.0001 2.15234C11.7364 2.15234 12.3334 2.7493 12.3334 3.48568ZM11.0001 9.48568C11.7364 9.48568 12.3334 8.88871 12.3334 8.15234C12.3334 7.41598 11.7364 6.81901 11.0001 6.81901C10.2637 6.81901 9.66675 7.41598 9.66675 8.15234C9.66675 8.88871 10.2637 9.48568 11.0001 9.48568ZM11.0001 14.1523C11.7364 14.1523 12.3334 13.5554 12.3334 12.819C12.3334 12.0826 11.7364 11.4857 11.0001 11.4857C10.2637 11.4857 9.66675 12.0826 9.66675 12.819C9.66675 13.5554 10.2637 14.1523 11.0001 14.1523Z" />
397
397
  </svg>
@@ -407,10 +407,10 @@ ${s}
407
407
  </g>
408
408
  </svg>`,dM=1e3;async function uM(n,t){const{width:e}=n.rootContainer.getBoundingClientRect(),o=t.getBoundingClientRect();return o.width>e||o.height>=dM?"":(await Jf.default.toSvg(t)).replace(/margin-block:.*?;/,"").replace(/margin:.*?;/,"")}const hM=B("drag-preview-image");class fM{constructor(t){h(this,"startPosition",null);h(this,"dragContainer",null);h(this,"handleDragStart",async(t,e)=>{const o=t.target;d(hM,o instanceof HTMLButtonElement,`Invalid Drag target:${o}`);const{x:r,y:i}=t;this.startPosition={x:r,y:i};const s=b("div",["drag-image-container"],this.editor.rootContainer),l=b("img",["drag-image"],s),c=b("span",["drag-loading"],s);c.innerHTML=aM;const{x:a,width:u,height:f,y:m}=o.getBoundingClientRect(),C=this.editor.rootContainer.getBoundingClientRect(),k=e.getBoundingClientRect();s.style.left=`${a+u}px`,s.style.top=`${m+f}px`,s.style.width=`${Math.min(C.width/2,k.width)}px`,this.dragContainer=s;const y=await uM(this.editor,e);y?l.src=y:A(s,"drag-placeholder"),nd(s,{status:"loaded"})});h(this,"handleDrag",t=>{if(this.startPosition&&this.dragContainer){const{x:e,y:o}=t;if(e===0&&o===0){this.dragContainer.style.transition="transform 0.15s, opacity .15s",this.dragContainer.style.transform="",this.dragContainer.style.opacity="0";return}const{x:r,y:i}=this.startPosition,s=e-r,l=o-i;this.dragContainer.style.transform=`translate(${s}px, ${l}px)`}});h(this,"handleDragEnd",()=>{this.dragContainer&&(this.dragContainer.remove(),this.startPosition=null,this.dragContainer=null)});this.editor=t}}const x6="drag-preview-element";function mM(n){if(nt(n,x6))return n;const t=n.querySelector(`.${x6}`);return t||(Te(n)?it(n):n)}const _1=B("block-menu-drag-handler");class gM{constructor(t,e){h(this,"dragPreview");h(this,"autoScroll");h(this,"oldPos",{x:0,y:0});h(this,"handleDragStart",t=>{var i,s;const e=t.dataTransfer;e&&(e.dropEffect="move");const o=this.button.blockMenu.currentBlock;d(_1,o,"no dragged block"),(s=(i=kt(this.editor,o)).notify)==null||s.call(i,this.editor,"beginDrag"),kM(this.editor,t,o),window.isDragging=!0,this.button.buttonElement.style.opacity="0";const r=mM(o);this.dragPreview.handleDragStart(t,r),this.autoScroll.active(),A(o,"dragging")});h(this,"handleDrag",t=>{const{target:e,x:o,y:r}=t;this.oldPos.x===o&&this.oldPos.y===r||(this.oldPos={x:o,y:r},d(_1,e instanceof HTMLElement,"target is invalid"),o===0&&r===0&&this.autoScroll.inactive(),this.dragPreview.handleDrag(t))});h(this,"handleDragEnd",()=>{const t=this.button.blockMenu.currentBlock;d(_1,t,"no dragged block"),window.isDragging=!1,this.button.buttonElement.style.opacity="1",this.dragPreview.handleDragEnd(),this.autoScroll.inactive(),z(t,"dragging")});this.editor=t,this.button=e;const o=this.button.buttonElement;o.draggable=!0,o.addEventListener("dragstart",this.handleDragStart),o.addEventListener("dragend",this.handleDragEnd),o.addEventListener("drag",this.handleDrag),this.dragPreview=new fM(t);const r=We(o);this.autoScroll=new $m({scrollElement:r,trackMouseEvent:"drag",edge:{top:50,bottom:50}})}destroy(){const t=this.button.buttonElement;t.removeEventListener("dragstart",this.handleDragStart),t.removeEventListener("dragend",this.handleDragEnd),t.removeEventListener("drag",this.handleDrag)}}class qs{constructor(t){h(this,"highlightedBlockId","");h(this,"handleSelectionChange",()=>{this.clearHighlightedBlock()});this.editor=t,this.editor.addListener("selectionChanged",this.handleSelectionChange)}highlightBlock(t){this.clearHighlightedBlock(),this.highlightedBlockId=q(t),A(t,"highlighted")}clearHighlightedBlock(){if(this.highlightedBlockId){const t=this.editor.findBlockById(this.highlightedBlockId);t&&z(t,"highlighted"),this.highlightedBlockId=""}}destroy(){}static register(t){return t.addCustom("editor-block-highlighter",()=>new qs(t))}static get(t){return t.getCustom("editor-block-highlighter")}}class T6{constructor(t){h(this,"buttonElement");h(this,"emptyBlockMenu");h(this,"blockMenu");h(this,"dragHandler");h(this,"handleHoverBlock",(t,e,o)=>{if(this.emptyBlockMenu.isVisible||this.blockMenu.isVisible||!this.editor.isWritable())return;const r=this.editor.getCustom("editor-tooltip");if(r&&r.visible()&&(r.hide(),this.buttonElement.setAttribute("data-tooltip-hide-at",`${Date.now()}`)),!t){this.buttonElement.parentElement&&(this.blockMenu.isInMenu(o.target)||this.buttonElement.remove());return}const i=xd(t);this.editor.getBlockIndex(i)===0&&this.editor.getBlockData(i).heading===1||(this.updateButton(i),R1(i,this.buttonElement,Number.MAX_SAFE_INTEGER))});h(this,"handleButtonClick",()=>{if(this.buttonElement.getAttribute("data-type")==="move"){const o=this.blockMenu.currentBlock;if(!o)return;this.editor.selection.selectBlock(o,0),this.blockMenu.show(this.buttonElement),setTimeout(()=>{qs.get(this.editor).highlightBlock(o)});return}const e=this.emptyBlockMenu.currentBlock;!e||(this.editor.selection.selectBlock(e,0),setTimeout(()=>{this.editor.focus(),this.updatePlaceholder(e),this.emptyBlockMenu.show()}))});h(this,"updatePlaceholder",t=>{it(t).setAttribute("data-content-placeholder",T.t("blockMenu.button.searchPlaceholder"))});h(this,"handleChanged",()=>{const t=this.emptyBlockMenu.currentBlock;if(!t)return;const e=Tt(this.editor,t)?"insert":"move";this.buttonElement.getAttribute("data-type")!==e&&this.setButtonType(e)});this.editor=t,this.buttonElement=this.createButton(),this.emptyBlockMenu=new YL(t),this.blockMenu=new lM(t),this.editor.addListener("docChanged",this.handleChanged),this.buttonElement.addEventListener("click",this.handleButtonClick),this.dragHandler=new gM(this.editor,this);const e=Nt.get(t);e.addListener("change",this.handleHoverBlock),e.addFinder(new ZL),qs.register(this.editor)}destroy(){Nt.get(this.editor).removeListener("change",this.handleHoverBlock),this.buttonElement.removeEventListener("click",this.handleButtonClick),this.editor.removeListener("docChanged",this.handleChanged),this.emptyBlockMenu.destroy(),this.blockMenu.destroy(),this.buttonElement.remove(),this.dragHandler.destroy()}createButton(){const t=b("button",["block-button"],null);return t.setAttribute(`data-editor-tooltip-${this.editor.clientId}`,T.t("blockMenu.button.tips")),t.innerHTML=I6,t}setButtonType(t){this.buttonElement.setAttribute("data-type",t);const e=`data-editor-tooltip-${this.editor.clientId}`;t==="insert"?(this.buttonElement.innerHTML=cM,this.buttonElement.removeAttribute(e)):(this.buttonElement.innerHTML=I6,this.buttonElement.setAttribute(e,T.t("blockMenu.button.tips")))}updateButton(t){this.emptyBlockMenu.setBlock(t),this.blockMenu.setBlock(t),Tt(this.editor,t)?this.setButtonType("insert"):this.setButtonType("move")}}const pM={blockMenu:{section:{basics:"\u57FA\u7840",system:"\u7CFB\u7EDF",styles:"\u6837\u5F0F",common:"\u901A\u7528",actions:"\u64CD\u4F5C",thirdParty:"\u7B2C\u4E09\u65B9\u5185\u5BB9"},command:{insertAbove:"Insert above",insertAfter:"Insert after"},button:{searchPlaceholder:"\u8F93\u5165\u5173\u952E\u8BCD\u641C\u7D22",tips:`\u957F\u6309\u62D6\u62FD
409
409
  \u70B9\u51FB\u6253\u5F00\u83DC\u5355`}}},CM={blockMenu:{section:{basics:"Basics",system:"System",styles:"Styles",common:"Common",actions:"Actions",thirdParty:"Third-party content"},command:{insertAbove:"Insert above",insertAfter:"Insert after"},button:{searchPlaceholder:"Type to filter",tips:`Long press drag
410
- Click to open the menu`}}};T.mergeLang({"zh-CN":pM,"en-US":CM});const Hz="";class bM{constructor(){h(this,"dragObject",null)}setData(t){this.dragObject=t}getData(){return this.dragObject}clearData(){this.dragObject=null}destroy(){}}function ua(n){return n.addCustom("drag-data",()=>new bM)}function N1(n,t){if(!t)return null;const e=ua(n).getData();return!e||e.editorId!==n.id?null:e}function S6(n,t){const e=N1(n,t);return e?n.findBlockById(e.blockId):null}function kM(n,t,e){if(!t.dataTransfer)return;const r=H(e),i=U(r),s=q(e),l={type:"block",editorId:n.id,containerId:i,blockId:s};ua(n).setData(l)}function vM(n,t,e,o,r){if(!t.dataTransfer)return;const s=H(e),l=U(s),c=q(e),a={type:"custom",customType:o,editorId:n.id,containerId:l,blockId:c,data:r};ua(n).setData(a)}function D6(n){ua(n).clearData()}const yM=B("drop-indicator"),ha=2;class wM{constructor(t){h(this,"indicator");h(this,"target",null);this.editor=t,this.indicator=b("div",["editor-drop-indicator"],this.editor.contentElement)}show(t,e){const o=this.getIndicatorRect(t,e),r=this.editor.rootElement.getBoundingClientRect(),i=o.top-r.top,s=o.left-r.left;this.indicator.style.top=`${i}px`,this.indicator.style.left=`${s}px`,this.indicator.style.width=`${o.width}px`,this.indicator.style.height=`${o.height}px`,this.indicator.style.display="",this.target={block:t,insertPos:e}}hide(){this.indicator.style.display="none",this.target=null}getIndicatorRect(t,e){if(typeof e!="string")return e.rect;if(e==="before"){const s=wr(t);if(!s){d(yM,Ye(H(t)),"block does not in a child container");const a=t.getBoundingClientRect();return new DOMRect(a.x,a.y,a.width,ha)}const l=s.getBoundingClientRect(),c=t.getBoundingClientRect();return new DOMRect(l.x,(l.bottom+c.top)/2,l.width,ha)}const o=Br(t);if(!o){const s=t.getBoundingClientRect();return new DOMRect(s.x,s.bottom,s.width,ha)}const r=t.getBoundingClientRect(),i=o.getBoundingClientRect();return new DOMRect(r.x,(r.bottom+i.top)/2,r.width,ha)}}const BM=B("find-drop-target");function EM(n,t){const e=document.elementFromPoint(n,t);if(!e)return null;if(bn(e)&&Ye(e))return e;const o=e.firstElementChild;return o&&bn(o)&&Ye(o)?o:null}function IM(n,t){const s=t,l=n;for(let c=0;c<2;c++){const a=l+c*50;for(let u=0;u<5;u++){const f=s+u*8,m=document.elementFromPoint(a,f);if(m){const w=F(m);if(w)return w}if(u===0)continue;const C=s-u*8,k=document.elementFromPoint(a,C);if(k){const w=F(k);if(w)return w}}}return null}function xM(n,t,e){const o=document.elementFromPoint(t,e);if(o){const u=F(o);if(u&&!at(n,u))return u}const r=new Set,i=EM(t,e);if(i){const u=i.getBoundingClientRect();e<u.top+u.height/2?r.add(Ut(i)):r.add(Qt(i))}const s=IM(t,e);s&&r.add(s);const l=Array.from(r),c=u=>{for(let f=0;f<l.length;f++){const m=l[f];if(u!==m&&It(u,m))return!0}return!1},a=l.filter(u=>!c(u));return a.length>0?a[0]:null}function $1(n,t){if(n.readonly)return!1;const e=H(t);if(pt(e))return!0;const o=F(e);return d(BM,o,"no parent block"),n.isBlockWritable(o)?$1(n,o):!1}const TM=B("drop-target");class SM{constructor(t){h(this,"getEmbedClassByFile",t=>{let e={};return/image/.test(t.type)?e=this.editor.editorEmbeds.getEmbedClass("image"):/audio/.test(t.type)?e=this.editor.editorEmbeds.getEmbedClass("audio"):/video/.test(t.type)&&(e=this.editor.editorEmbeds.getEmbedClass("video")),d(TM,e,`unSupport file type ${t.type}`),e});h(this,"handleDrop",(t,e,o,r)=>{if(Array.isArray(e)){const i=e;if(i.length>0){let s=r;return i.forEach(l=>{var u,f,m;const c=this.getEmbedClassByFile(l),a=U(o);(m=(u=c.getOptions)==null?void 0:(f=u.call(c,t)).handleInsertEmptyEmbed)==null||m.call(f,t,{containerId:a,blockIndex:s,data:{file:l}}),s+=1}),!0}}return!1});this.editor=t}}class Ws{constructor(t){h(this,"indicator");h(this,"lastDropOverResult");h(this,"handlers",[]);h(this,"handleDragOver",t=>{if(!this.editor.isWritable())return;const e=i=>{const s=N1(this.editor,i.dataTransfer),l=S6(this.editor,i.dataTransfer),c=this.findTargetBlock(l,i.x,i.y);if(c&&It(this.editor.rootContainer,c)){const a=this.findInsertPos(l,c,i.x,i.y,s);if(a)return this.indicator.show(c,a),"move"}return this.indicator.hide(),"none"},o=(i,s)=>{i.dataTransfer&&(i.dataTransfer.dropEffect=s),s==="move"&&i.preventDefault()};if(this.lastDropOverResult&&t.x===this.lastDropOverResult.x&&t.y===this.lastDropOverResult.y){const i=this.lastDropOverResult.dropEffect;o(t,i);return}const r=e(t);o(t,r),this.lastDropOverResult={x:t.x,y:t.y,dropEffect:r}});h(this,"handleDrop",t=>{var i,s;setTimeout(()=>{this.indicator.hide()});const e=N1(this.editor,t.dataTransfer),o=Array.from((s=(i=t.dataTransfer)==null?void 0:i.files)!=null?s:[]);if(!e&&o.length===0){t.dataTransfer&&(t.dataTransfer.dropEffect="none");return}const r=this.indicator.target;if(r){const{block:l,insertPos:c}=r,a=S6(this.editor,t.dataTransfer);this.editor.undoManager.runInGroup(()=>{const u=kt(this.editor,l);if(u.handleDrop&&u.handleDrop(this.editor,l,e!=null?e:o,c,{isSourceBlock:!1,targetBlock:l})){t.preventDefault();return}if(a){const f=kt(this.editor,a);if(f.handleDrop&&f.handleDrop(this.editor,a,e!=null?e:o,c,{isSourceBlock:!0,targetBlock:l})){t.preventDefault();return}}if(typeof c=="string"){const f=H(l);let m=J(l);c==="after"&&(m+=1),t.preventDefault();for(let C=0;C<this.handlers.length;C++)if(this.handlers[C].handleDrop(this.editor,a!=null?a:o,f,m))return;if(a){const C=this.editor.getBlockData(a),k=mo(this.editor.editorBlocks,this.editor.doc.toJSON(),C),[w]=this.editor.insertDocAt(f,m,k);this.editor.selection.selectBlock(w,0),qs.get(this.editor).highlightBlock(w),this.editor.deleteBlock(a)}}}),D6(this.editor)}});this.editor=t,this.indicator=new wM(this.editor),this.handlers.push(new SM(this.editor)),this.editor.contentElement.addEventListener("dragover",this.handleDragOver),this.editor.contentElement.addEventListener("drop",this.handleDrop)}destroy(){this.editor.contentElement.removeEventListener("dragover",this.handleDragOver),this.editor.contentElement.removeEventListener("drop",this.handleDrop),this.handlers=[]}addHandler(t){this.handlers.push(t)}static register(t){return t.addCustom("drop-target",()=>new Ws(t))}static get(t){return t.getCustom("drop-target")}canInsertAfter(t,e){return t===null?!0:this.editor.readonly||Br(e)===t?!1:$1(this.editor,e)}canInsertBefore(t,e){return this.editor.readonly?!1:t===null?!0:!(wr(e)===t||!$1(this.editor,e)||pt(H(e))&&J(e)===0)}canDrop(t,e){return t===null||t===e?!0:!It(t,e)}findTargetBlock(t,e,o){const r=xM(this.editor,e,o);return!r||!It(this.editor.rootContainer,r)||!this.canDrop(t,r)?null:r}findInsertPos(t,e,o,r,i){const s=kt(this.editor,e);if(s.handleDropOver){const c=s.handleDropOver(this.editor,e,i,o,r);if(c)return c}if(t===e)return"";const l=e.getBoundingClientRect();if(l.top<=r&&r<=l.bottom){if(r<l.top+l.height/2){if(this.canInsertBefore(t,e))return"before";if(this.canInsertAfter(t,e))return"after"}else{if(this.canInsertAfter(t,e))return"after";if(this.canInsertBefore(t,e))return"before"}return""}return r<l.top&&this.canInsertBefore(t,e)?"before":l.bottom<r&&this.canInsertAfter(t,e)?"after":""}}async function DM(n){return await Jf.default.toSvg(n)}class LM{constructor(t){h(this,"img");h(this,"dragContainer",null);h(this,"startPosition",null);h(this,"handleDragStart",async t=>{var R;const e=t.target;if(!e||!(e instanceof HTMLImageElement))return;const o=F(e);if(!o||!fn(o))return;const r=zt.getImageObject(this.editor,o),i=M1(t.target);if(!i)return;const l=u6(t.target).indexOf(i);if(l===-1)return;const c=r.getImages()[l];if(!c)return;const a=t.dataTransfer;a&&(a.dropEffect="move");const u={image:c,index:l,boundingRect:i.getBoundingClientRect()};vM(this.editor,t,o,"image",u),(R=t.dataTransfer)==null||R.setDragImage(this.img,0,0);const{x:f,y:m}=t;this.startPosition={x:f,y:m};const{width:C,height:k}=t.target.getBoundingClientRect(),w=Rt(o),y=b("div",["drag-container"],w);y.style.left=`${f-C/4}px`,y.style.top=`${m-k/4}px`,y.style.width=`${Math.max(C/2,16)}px`,y.style.height=`${k/2}px`,this.dragContainer=y;const S=b("img",["drag-target"],y),M=await DM(i);M&&(S.src=M),window.isDragging=!0});h(this,"handleDrag",t=>{if(this.startPosition&&this.dragContainer){const{x:e,y:o}=t;if(e===0&&o===0){this.dragContainer.style.transform="",this.dragContainer.style.opacity="0";return}const{x:r,y:i}=this.startPosition,s=e-r,l=o-i;this.dragContainer.style.transform=`translate(${s}px, ${l}px)`,this.dragContainer.style.opacity="0.5"}});h(this,"handleDragEnd",()=>{D6(this.editor),window.isDragging=!1,this.dragContainer&&this.dragContainer.remove(),this.dragContainer=null,this.startPosition=null});this.editor=t,this.editor.rootContainer.addEventListener("dragstart",this.handleDragStart),this.editor.rootContainer.addEventListener("dragend",this.handleDragEnd),this.editor.rootContainer.addEventListener("drag",this.handleDrag),this.img=new Image,this.img.src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"}destroy(){this.editor.rootContainer.removeEventListener("dragstart",this.handleDragStart),this.editor.rootContainer.removeEventListener("dragend",this.handleDragEnd),this.editor.rootContainer.removeEventListener("drag",this.handleDrag)}}class MM{constructor(t){h(this,"handleFocusBlockChanged",(t,e,o)=>{const i=this.editor.getFocusedBlock();if(i&&fn(i)){const s=zt.getImageObject(this.editor,i);s.getImages().length>0&&s.getSelectedIndex()===-1&&s.setSelectedIndex(0)}o&&fn(o)&&zt.getImageObject(this.editor,o).blockResizer.disableResize()});this.editor=t,this.editor.addListener("focusBlockChanged",this.handleFocusBlockChanged)}destroy(){this.editor.removeListener("focusBlockChanged",this.handleFocusBlockChanged)}}class RM{constructor(t){h(this,"handleHoveringBlockChange",(t,e)=>{if(e&&fn(e)&&zt.getImageObject(this.editor,e).disableResizer(),t&&fn(t)){const o=zt.getImageObject(this.editor,t);this.editor.isBlockWritable(t)&&o.tryEnableResizer()}});this.editor=t,Nt.get(t).addListener("change",this.handleHoveringBlockChange)}destroy(){Nt.get(this.editor).removeListener("change",this.handleHoveringBlockChange)}}const AM={image:{upload:{failed:'<div class="line-1">\u56FE\u7247\u4E0A\u4F20\u5931\u8D25</div><div class="line-2">\u7F51\u7EDC\u670D\u52A1\u5F02\u5E38\uFF0C\u4F60\u53EF\u4EE5 <a href="" class="retry-upload">\u91CD\u8BD5</a></div>'},load:{failed:'<div class="line-1">\u56FE\u7247\u52A0\u8F7D\u5931\u8D25</div><div class="line-2">\u7F51\u7EDC\u670D\u52A1\u5F02\u5E38\uFF0C\u4F60\u53EF\u4EE5 <a href="" class="retry-upload">\u91CD\u8BD5</a></div>',remote:{failed:'<div class="line-1">\u8BE5\u56FE\u7247\u6765\u81EA\u5916\u90E8\u94FE\u63A5\uFF0C\u5916\u90E8\u94FE\u63A5\u5DF2\u5931\u6548</div><div class="line-2">\u8BF7\u5C06\u539F\u56FE\u4FDD\u5B58\u5230\u672C\u5730\u540E\u4E0A\u4F20\uFF0C <a href="" class="retry-upload">\u6253\u5F00\u56FE\u7247\u94FE\u63A5</a></div>',tooltip:"\u8BE5\u56FE\u7247\u6765\u81EA\u5916\u90E8\u94FE\u63A5\uFF0C\u5982\u679C\u94FE\u63A5\u5931\u6548\u56FE\u7247\u5C06\u65E0\u6CD5\u67E5\u770B\uFF0C\u5EFA\u8BAE\u4FDD\u5B58\u5230\u672C\u5730\u540E\u6DFB\u52A0\u5230\u9875\u9762\u4E2D"}},abstract:"\u56FE\u7247"}},OM={image:{upload:{failed:'<div class="line-1">Image upload failed</div><div class="line-2">The network service is abnormal, you can <a href="" class="retry-upload">Try again</a></div>'},load:{failed:'<div class="line-1">Image failed to load</div><div class="line-2">The network service is abnormal, you can <a href="" class="retry-upload">Try again</a></div>',remote:{failed:'<div class="line-1">The picture comes from an external link, and the external link has expired</div><div class="line-2">Please save the original image locally and then upload it. <a href="" class="retry-upload">Open image link</a></div>',tooltip:"\u8BE5\u56FE\u7247\u6765\u81EA\u5916\u90E8\u94FE\u63A5\uFF0C\u5982\u679C\u94FE\u63A5\u5931\u6548\u56FE\u7247\u5C06\u65E0\u6CD5\u67E5\u770B\uFF0C\u5EFA\u8BAE\u4FDD\u5B58\u5230\u672C\u5730\u540E\u6DFB\u52A0\u5230\u9875\u9762\u4E2D"}},image:"Image"}};T.mergeLang({"zh-CN":AM,"en-US":OM});function _M(n,t,e,o){const r=n.getBlockByIndex(t,e),i=n.getBlockText(r),{left:s}=be(i,o),l=bt(s);let c=o;if(l.endsWith("![]()"))c-=5;else if(l.endsWith("![]"))c-=3;else return!1;const a=o;return Fo("image/*").then(u=>{n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,c,a-c);let f=e+1;bt(n.getBlockText(r)).trim()?(Ar(n,r,c,{forceInsertAfter:!0}),c===0&&(n.deleteBlock(r),f--)):(n.deleteBlock(r),f--),Ld(n,"image",t,f,{file:u})})}),!0}class NM{handleAfterInsertText(t,e,o,r,i){return!!(i===" "&&_M(t,e,o,r))}}function $M(n){const t=n.getFocusedBlock(),e=Br(t);if(e&&fn(e)){n.selection.selectBlock(e,0);const o=zt.getImageObject(n,e);return o.getImages().length>0&&o.setSelectedIndex(0),!0}}function PM(n){const t=n.getFocusedBlock(),e=wr(t);if(e&&fn(e)){n.selection.selectBlock(e,0);const o=zt.getImageObject(n,e);return o.getImages().length>0&&o.setSelectedIndex(0),!0}}function jM(n){const e=n.getFocusedBlock();if(e&&fn(e)){const o=zt.getImageObject(n,e),r=o.getImages();if(r.length>0){const i=o.getSelectedIndex();if(i===-1)return o.setSelectedIndex(r.length-1),!0;if(i>0)return o.setSelectedIndex(i-1),!0}}}function HM(n){const e=n.getFocusedBlock();if(e&&fn(e)){const o=zt.getImageObject(n,e),r=o.getImages();if(r.length>0){const i=o.getSelectedIndex();if(i===-1)return o.setSelectedIndex(0),!0;if(i<r.length-1)return o.setSelectedIndex(i+1),!0}}}function FM(n,t,e,o){const r=e.getImages()[o],i=e.getImages().length===1?e.getWidthPercent():r.flex*100,s=se([r],i),l={id:N(),type:"embed",embedType:"image",embedData:s},c=n.options.componentsOptions.image;c!=null&&c.defaultAlign&&(l.align=c.defaultAlign);const a={blocks:{root:[l]},comments:{},meta:{}},u=document.createElement("canvas");u.width=t.naturalWidth,u.height=t.naturalHeight;const f=u.getContext("2d");if(!f)return;f.drawImage(t,0,0,u.width,u.height);const C=u.toDataURL("image/png").replace(/^data:image\/(png|jpg);base64,/,""),k=xm(C),w=new File([k],`${Date.now()}.png`,{type:"image/png"});es(n,a);const y=ts(Dr(n,a),a),S=Lr(n,a),I=new Blob([y],{type:"text/html"});return Il([{type:"text/plain",data:new Blob([S],{type:"text/plain"})},{type:"text/html",data:I},{type:"image/png",data:w}]),!0}function L6(n){const t=n.selection.range;if(t.start.blockId!==t.end.blockId)return;const o=n.getFocusedBlock();if(o&&fn(o)){const r=zt.getImageObject(n,o);if(r.getImages().length>0){const s=r.getSelectedIndex();if(s!==-1){const c=Qn(o)[s].querySelector("img");if(c)return FM(n,c,r,s)}}}}function P1(n){const e=n.getFocusedBlock();if(e&&fn(e)){const o=zt.getImageObject(n,e);if(o.getImages().length>1){const i=o.getSelectedIndex();if(i!==-1)return o.removeImage(i),!0}}}function zM(n){if(L6(n))return P1(n),!0}const UM={ArrowLeft:jM,ArrowRight:HM,ArrowUp:PM,ArrowDown:$M,"CtrlOrCmd+C":L6,"CtrlOrCmd+X":zM,Delete:P1,Backspace:P1};function VM(n,t,e,o,r,i){zt.create(n,e).createContent(r,i,t),n.addCustom("image-select-handler",()=>new MM(n)),n.addCustom("image-resizer",()=>new RM(n)),setTimeout(()=>{n.addCustom("drag-handler",()=>new LM(n))})}function qM(n,t,e,o){const r=t.embedData,i=ii(r);return o==="html"?i.map(s=>`<img src="${n.doc.buildResourceUrl(s.src,{withToken:!0})}">`).join(""):o==="markdown"?`${i.map(l=>`![img](${n.doc.buildResourceUrl(l.src,{withToken:!0})})`).join(`
410
+ Click to open the menu`}}};T.mergeLang({"zh-CN":pM,"en-US":CM});const Hz="";class bM{constructor(){h(this,"dragObject",null)}setData(t){this.dragObject=t}getData(){return this.dragObject}clearData(){this.dragObject=null}destroy(){}}function ua(n){return n.addCustom("drag-data",()=>new bM)}function N1(n,t){if(!t)return null;const e=ua(n).getData();return!e||e.editorId!==n.id?null:e}function S6(n,t){const e=N1(n,t);return e?n.findBlockById(e.blockId):null}function kM(n,t,e){if(!t.dataTransfer)return;const r=H(e),i=U(r),s=q(e),l={type:"block",editorId:n.id,containerId:i,blockId:s};ua(n).setData(l)}function vM(n,t,e,o,r){if(!t.dataTransfer)return;const s=H(e),l=U(s),c=q(e),a={type:"custom",customType:o,editorId:n.id,containerId:l,blockId:c,data:r};ua(n).setData(a)}function D6(n){ua(n).clearData()}const yM=B("drop-indicator"),ha=2;class wM{constructor(t){h(this,"indicator");h(this,"target",null);this.editor=t,this.indicator=b("div",["editor-drop-indicator"],this.editor.contentElement)}show(t,e){const o=this.getIndicatorRect(t,e),r=this.editor.rootElement.getBoundingClientRect(),i=o.top-r.top,s=o.left-r.left;this.indicator.style.top=`${i}px`,this.indicator.style.left=`${s}px`,this.indicator.style.width=`${o.width}px`,this.indicator.style.height=`${o.height}px`,this.indicator.style.display="",this.target={block:t,insertPos:e}}hide(){this.indicator.style.display="none",this.target=null}getIndicatorRect(t,e){if(typeof e!="string")return e.rect;if(e==="before"){const s=wr(t);if(!s){d(yM,Ye(H(t)),"block does not in a child container");const a=t.getBoundingClientRect();return new DOMRect(a.x,a.y,a.width,ha)}const l=s.getBoundingClientRect(),c=t.getBoundingClientRect();return new DOMRect(l.x,(l.bottom+c.top)/2,l.width,ha)}const o=Br(t);if(!o){const s=t.getBoundingClientRect();return new DOMRect(s.x,s.bottom,s.width,ha)}const r=t.getBoundingClientRect(),i=o.getBoundingClientRect();return new DOMRect(r.x,(r.bottom+i.top)/2,r.width,ha)}}const BM=B("find-drop-target");function EM(n,t){const e=document.elementFromPoint(n,t);if(!e)return null;if(bn(e)&&Ye(e))return e;const o=e.firstElementChild;return o&&bn(o)&&Ye(o)?o:null}function IM(n,t){const s=t,l=n;for(let c=0;c<2;c++){const a=l+c*50;for(let u=0;u<5;u++){const f=s+u*8,m=document.elementFromPoint(a,f);if(m){const w=F(m);if(w)return w}if(u===0)continue;const C=s-u*8,k=document.elementFromPoint(a,C);if(k){const w=F(k);if(w)return w}}}return null}function xM(n,t,e){const o=document.elementFromPoint(t,e);if(o){const u=F(o);if(u&&!at(n,u))return u}const r=new Set,i=EM(t,e);if(i){const u=i.getBoundingClientRect();e<u.top+u.height/2?r.add(Ut(i)):r.add(Qt(i))}const s=IM(t,e);s&&r.add(s);const l=Array.from(r),c=u=>{for(let f=0;f<l.length;f++){const m=l[f];if(u!==m&&It(u,m))return!0}return!1},a=l.filter(u=>!c(u));return a.length>0?a[0]:null}function $1(n,t){if(n.readonly)return!1;const e=H(t);if(pt(e))return!0;const o=F(e);return d(BM,o,"no parent block"),n.isBlockWritable(o)?$1(n,o):!1}const TM=B("drop-target");class SM{constructor(t){h(this,"getEmbedClassByFile",t=>{let e={};return/image/.test(t.type)?e=this.editor.editorEmbeds.getEmbedClass("image"):/audio/.test(t.type)?e=this.editor.editorEmbeds.getEmbedClass("audio"):/video/.test(t.type)&&(e=this.editor.editorEmbeds.getEmbedClass("video")),d(TM,e,`unSupport file type ${t.type}`),e});h(this,"handleDrop",(t,e,o,r)=>{if(Array.isArray(e)){const i=e;if(i.length>0){let s=r;return i.forEach(l=>{var u,f,m;const c=this.getEmbedClassByFile(l),a=U(o);(m=(u=c.getOptions)==null?void 0:(f=u.call(c,t)).handleInsertEmptyEmbed)==null||m.call(f,t,{containerId:a,blockIndex:s,data:{file:l}}),s+=1}),!0}}return!1});this.editor=t}}class Ws{constructor(t){h(this,"indicator");h(this,"lastDropOverResult");h(this,"handlers",[]);h(this,"handleDragOver",t=>{if(!this.editor.isWritable())return;const e=i=>{const s=N1(this.editor,i.dataTransfer),l=S6(this.editor,i.dataTransfer),c=this.findTargetBlock(l,i.x,i.y);if(c&&It(this.editor.rootContainer,c)){const a=this.findInsertPos(l,c,i.x,i.y,s);if(a)return this.indicator.show(c,a),"move"}return this.indicator.hide(),"none"},o=(i,s)=>{i.dataTransfer&&(i.dataTransfer.dropEffect=s),s==="move"&&i.preventDefault()};if(this.lastDropOverResult&&t.x===this.lastDropOverResult.x&&t.y===this.lastDropOverResult.y){const i=this.lastDropOverResult.dropEffect;o(t,i);return}const r=e(t);o(t,r),this.lastDropOverResult={x:t.x,y:t.y,dropEffect:r}});h(this,"handleDrop",t=>{var i,s;setTimeout(()=>{this.indicator.hide()});const e=N1(this.editor,t.dataTransfer),o=Array.from((s=(i=t.dataTransfer)==null?void 0:i.files)!=null?s:[]);if(!e&&o.length===0){t.dataTransfer&&(t.dataTransfer.dropEffect="none");return}const r=this.indicator.target;if(r){const{block:l,insertPos:c}=r,a=S6(this.editor,t.dataTransfer);this.editor.undoManager.runInGroup(()=>{const u=kt(this.editor,l);if(u.handleDrop&&u.handleDrop(this.editor,l,e!=null?e:o,c,{isSourceBlock:!1,targetBlock:l})){t.preventDefault();return}if(a){const f=kt(this.editor,a);if(f.handleDrop&&f.handleDrop(this.editor,a,e!=null?e:o,c,{isSourceBlock:!0,targetBlock:l})){t.preventDefault();return}}if(typeof c=="string"){const f=H(l);let m=J(l);c==="after"&&(m+=1),t.preventDefault();for(let C=0;C<this.handlers.length;C++)if(this.handlers[C].handleDrop(this.editor,a!=null?a:o,f,m))return;if(a){const C=this.editor.getBlockData(a),k=go(this.editor.editorBlocks,this.editor.doc.toJSON(),C),[w]=this.editor.insertDocAt(f,m,k);this.editor.selection.selectBlock(w,0),qs.get(this.editor).highlightBlock(w),this.editor.deleteBlock(a)}}}),D6(this.editor)}});this.editor=t,this.indicator=new wM(this.editor),this.handlers.push(new SM(this.editor)),this.editor.contentElement.addEventListener("dragover",this.handleDragOver),this.editor.contentElement.addEventListener("drop",this.handleDrop)}destroy(){this.editor.contentElement.removeEventListener("dragover",this.handleDragOver),this.editor.contentElement.removeEventListener("drop",this.handleDrop),this.handlers=[]}addHandler(t){this.handlers.push(t)}static register(t){return t.addCustom("drop-target",()=>new Ws(t))}static get(t){return t.getCustom("drop-target")}canInsertAfter(t,e){return t===null?!0:this.editor.readonly||Br(e)===t?!1:$1(this.editor,e)}canInsertBefore(t,e){return this.editor.readonly?!1:t===null?!0:!(wr(e)===t||!$1(this.editor,e)||pt(H(e))&&J(e)===0)}canDrop(t,e){return t===null||t===e?!0:!It(t,e)}findTargetBlock(t,e,o){const r=xM(this.editor,e,o);return!r||!It(this.editor.rootContainer,r)||!this.canDrop(t,r)?null:r}findInsertPos(t,e,o,r,i){const s=kt(this.editor,e);if(s.handleDropOver){const c=s.handleDropOver(this.editor,e,i,o,r);if(c)return c}if(t===e)return"";const l=e.getBoundingClientRect();if(l.top<=r&&r<=l.bottom){if(r<l.top+l.height/2){if(this.canInsertBefore(t,e))return"before";if(this.canInsertAfter(t,e))return"after"}else{if(this.canInsertAfter(t,e))return"after";if(this.canInsertBefore(t,e))return"before"}return""}return r<l.top&&this.canInsertBefore(t,e)?"before":l.bottom<r&&this.canInsertAfter(t,e)?"after":""}}async function DM(n){return await Jf.default.toSvg(n)}class LM{constructor(t){h(this,"img");h(this,"dragContainer",null);h(this,"startPosition",null);h(this,"handleDragStart",async t=>{var R;const e=t.target;if(!e||!(e instanceof HTMLImageElement))return;const o=F(e);if(!o||!fn(o))return;const r=zt.getImageObject(this.editor,o),i=M1(t.target);if(!i)return;const l=u6(t.target).indexOf(i);if(l===-1)return;const c=r.getImages()[l];if(!c)return;const a=t.dataTransfer;a&&(a.dropEffect="move");const u={image:c,index:l,boundingRect:i.getBoundingClientRect()};vM(this.editor,t,o,"image",u),(R=t.dataTransfer)==null||R.setDragImage(this.img,0,0);const{x:f,y:m}=t;this.startPosition={x:f,y:m};const{width:C,height:k}=t.target.getBoundingClientRect(),w=Rt(o),y=b("div",["drag-container"],w);y.style.left=`${f-C/4}px`,y.style.top=`${m-k/4}px`,y.style.width=`${Math.max(C/2,16)}px`,y.style.height=`${k/2}px`,this.dragContainer=y;const S=b("img",["drag-target"],y),M=await DM(i);M&&(S.src=M),window.isDragging=!0});h(this,"handleDrag",t=>{if(this.startPosition&&this.dragContainer){const{x:e,y:o}=t;if(e===0&&o===0){this.dragContainer.style.transform="",this.dragContainer.style.opacity="0";return}const{x:r,y:i}=this.startPosition,s=e-r,l=o-i;this.dragContainer.style.transform=`translate(${s}px, ${l}px)`,this.dragContainer.style.opacity="0.5"}});h(this,"handleDragEnd",()=>{D6(this.editor),window.isDragging=!1,this.dragContainer&&this.dragContainer.remove(),this.dragContainer=null,this.startPosition=null});this.editor=t,this.editor.rootContainer.addEventListener("dragstart",this.handleDragStart),this.editor.rootContainer.addEventListener("dragend",this.handleDragEnd),this.editor.rootContainer.addEventListener("drag",this.handleDrag),this.img=new Image,this.img.src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"}destroy(){this.editor.rootContainer.removeEventListener("dragstart",this.handleDragStart),this.editor.rootContainer.removeEventListener("dragend",this.handleDragEnd),this.editor.rootContainer.removeEventListener("drag",this.handleDrag)}}class MM{constructor(t){h(this,"handleFocusBlockChanged",(t,e,o)=>{const i=this.editor.getFocusedBlock();if(i&&fn(i)){const s=zt.getImageObject(this.editor,i);s.getImages().length>0&&s.getSelectedIndex()===-1&&s.setSelectedIndex(0)}o&&fn(o)&&zt.getImageObject(this.editor,o).blockResizer.disableResize()});this.editor=t,this.editor.addListener("focusBlockChanged",this.handleFocusBlockChanged)}destroy(){this.editor.removeListener("focusBlockChanged",this.handleFocusBlockChanged)}}class RM{constructor(t){h(this,"handleHoveringBlockChange",(t,e)=>{if(e&&fn(e)&&zt.getImageObject(this.editor,e).disableResizer(),t&&fn(t)){const o=zt.getImageObject(this.editor,t);this.editor.isBlockWritable(t)&&o.tryEnableResizer()}});this.editor=t,Nt.get(t).addListener("change",this.handleHoveringBlockChange)}destroy(){Nt.get(this.editor).removeListener("change",this.handleHoveringBlockChange)}}const AM={image:{upload:{failed:'<div class="line-1">\u56FE\u7247\u4E0A\u4F20\u5931\u8D25</div><div class="line-2">\u7F51\u7EDC\u670D\u52A1\u5F02\u5E38\uFF0C\u4F60\u53EF\u4EE5 <a href="" class="retry-upload">\u91CD\u8BD5</a></div>'},load:{failed:'<div class="line-1">\u56FE\u7247\u52A0\u8F7D\u5931\u8D25</div><div class="line-2">\u7F51\u7EDC\u670D\u52A1\u5F02\u5E38\uFF0C\u4F60\u53EF\u4EE5 <a href="" class="retry-upload">\u91CD\u8BD5</a></div>',remote:{failed:'<div class="line-1">\u8BE5\u56FE\u7247\u6765\u81EA\u5916\u90E8\u94FE\u63A5\uFF0C\u5916\u90E8\u94FE\u63A5\u5DF2\u5931\u6548</div><div class="line-2">\u8BF7\u5C06\u539F\u56FE\u4FDD\u5B58\u5230\u672C\u5730\u540E\u4E0A\u4F20\uFF0C <a href="" class="retry-upload">\u6253\u5F00\u56FE\u7247\u94FE\u63A5</a></div>',tooltip:"\u8BE5\u56FE\u7247\u6765\u81EA\u5916\u90E8\u94FE\u63A5\uFF0C\u5982\u679C\u94FE\u63A5\u5931\u6548\u56FE\u7247\u5C06\u65E0\u6CD5\u67E5\u770B\uFF0C\u5EFA\u8BAE\u4FDD\u5B58\u5230\u672C\u5730\u540E\u6DFB\u52A0\u5230\u9875\u9762\u4E2D"}},abstract:"\u56FE\u7247"}},OM={image:{upload:{failed:'<div class="line-1">Image upload failed</div><div class="line-2">The network service is abnormal, you can <a href="" class="retry-upload">Try again</a></div>'},load:{failed:'<div class="line-1">Image failed to load</div><div class="line-2">The network service is abnormal, you can <a href="" class="retry-upload">Try again</a></div>',remote:{failed:'<div class="line-1">The picture comes from an external link, and the external link has expired</div><div class="line-2">Please save the original image locally and then upload it. <a href="" class="retry-upload">Open image link</a></div>',tooltip:"\u8BE5\u56FE\u7247\u6765\u81EA\u5916\u90E8\u94FE\u63A5\uFF0C\u5982\u679C\u94FE\u63A5\u5931\u6548\u56FE\u7247\u5C06\u65E0\u6CD5\u67E5\u770B\uFF0C\u5EFA\u8BAE\u4FDD\u5B58\u5230\u672C\u5730\u540E\u6DFB\u52A0\u5230\u9875\u9762\u4E2D"}},image:"Image"}};T.mergeLang({"zh-CN":AM,"en-US":OM});function _M(n,t,e,o){const r=n.getBlockByIndex(t,e),i=n.getBlockText(r),{left:s}=be(i,o),l=bt(s);let c=o;if(l.endsWith("![]()"))c-=5;else if(l.endsWith("![]"))c-=3;else return!1;const a=o;return zo("image/*").then(u=>{n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,c,a-c);let f=e+1;bt(n.getBlockText(r)).trim()?(Ar(n,r,c,{forceInsertAfter:!0}),c===0&&(n.deleteBlock(r),f--)):(n.deleteBlock(r),f--),Ld(n,"image",t,f,{file:u})})}),!0}class NM{handleAfterInsertText(t,e,o,r,i){return!!(i===" "&&_M(t,e,o,r))}}function $M(n){const t=n.getFocusedBlock(),e=Br(t);if(e&&fn(e)){n.selection.selectBlock(e,0);const o=zt.getImageObject(n,e);return o.getImages().length>0&&o.setSelectedIndex(0),!0}}function PM(n){const t=n.getFocusedBlock(),e=wr(t);if(e&&fn(e)){n.selection.selectBlock(e,0);const o=zt.getImageObject(n,e);return o.getImages().length>0&&o.setSelectedIndex(0),!0}}function jM(n){const e=n.getFocusedBlock();if(e&&fn(e)){const o=zt.getImageObject(n,e),r=o.getImages();if(r.length>0){const i=o.getSelectedIndex();if(i===-1)return o.setSelectedIndex(r.length-1),!0;if(i>0)return o.setSelectedIndex(i-1),!0}}}function HM(n){const e=n.getFocusedBlock();if(e&&fn(e)){const o=zt.getImageObject(n,e),r=o.getImages();if(r.length>0){const i=o.getSelectedIndex();if(i===-1)return o.setSelectedIndex(0),!0;if(i<r.length-1)return o.setSelectedIndex(i+1),!0}}}function FM(n,t,e,o){const r=e.getImages()[o],i=e.getImages().length===1?e.getWidthPercent():r.flex*100,s=se([r],i),l={id:N(),type:"embed",embedType:"image",embedData:s},c=n.options.componentsOptions.image;c!=null&&c.defaultAlign&&(l.align=c.defaultAlign);const a={blocks:{root:[l]},comments:{},meta:{}},u=document.createElement("canvas");u.width=t.naturalWidth,u.height=t.naturalHeight;const f=u.getContext("2d");if(!f)return;f.drawImage(t,0,0,u.width,u.height);const C=u.toDataURL("image/png").replace(/^data:image\/(png|jpg);base64,/,""),k=xm(C),w=new File([k],`${Date.now()}.png`,{type:"image/png"});es(n,a);const y=ts(Dr(n,a),a),S=Lr(n,a),I=new Blob([y],{type:"text/html"});return Il([{type:"text/plain",data:new Blob([S],{type:"text/plain"})},{type:"text/html",data:I},{type:"image/png",data:w}]),!0}function L6(n){const t=n.selection.range;if(t.start.blockId!==t.end.blockId)return;const o=n.getFocusedBlock();if(o&&fn(o)){const r=zt.getImageObject(n,o);if(r.getImages().length>0){const s=r.getSelectedIndex();if(s!==-1){const c=Qn(o)[s].querySelector("img");if(c)return FM(n,c,r,s)}}}}function P1(n){const e=n.getFocusedBlock();if(e&&fn(e)){const o=zt.getImageObject(n,e);if(o.getImages().length>1){const i=o.getSelectedIndex();if(i!==-1)return o.removeImage(i),!0}}}function zM(n){if(L6(n))return P1(n),!0}const UM={ArrowLeft:jM,ArrowRight:HM,ArrowUp:PM,ArrowDown:$M,"CtrlOrCmd+C":L6,"CtrlOrCmd+X":zM,Delete:P1,Backspace:P1};function VM(n,t,e,o,r,i){zt.create(n,e).createContent(r,i,t),n.addCustom("image-select-handler",()=>new MM(n)),n.addCustom("image-resizer",()=>new RM(n)),setTimeout(()=>{n.addCustom("drag-handler",()=>new LM(n))})}function qM(n,t,e,o){const r=t.embedData,i=ii(r);return o==="html"?i.map(s=>`<img src="${n.doc.buildResourceUrl(s.src,{withToken:!0})}">`).join(""):o==="markdown"?`${i.map(l=>`![img](${n.doc.buildResourceUrl(l.src,{withToken:!0})})`).join(`
411
411
  `)}
412
412
  `:i.map(s=>n.doc.buildResourceUrl(s.src,{withToken:!0})).join(`
413
- `)}class WM{constructor(){h(this,"group","image");h(this,"commands",[])}executeCommand(t,e,o){if(o.id==="replace-image"){const{block:r,image:i}=o.data;zt.getImageObject(t,r).replaceImage(0,i)}}}function GM(){return{blockCommands:{image:new WM},abstract:`[${T.t("image.abstract")}]`}}function ZM(){return{name:"Image",insertEmbedCommandItems:[{id:"insert-image",name:"Image",icon:Qw,group:"common",subText:"/image",order:100}],handleInsertEmptyEmbed:async(n,t)=>{var m;let e;if((m=t.data)!=null&&m.file&&(e=t.data.file),e=e!=null?e:await Fo("image/*",{}),!e)return null;const o=await FL(e),r=n.rootContainer.clientWidth,i=o.width<r?Math.min(100,o.width/r*100):100,s={src:"",width:o.width,height:o.height,flex:1,virtualSize:!1},l=se([s],i),c={id:N(),type:"embed",embedType:"image",embedData:l},a=n.options.componentsOptions.image;a!=null&&a.defaultAlign&&(c.align=a.defaultAlign);const u=n.insertBlock(t.containerId,t.blockIndex,c);return zt.getImageObject(n,u).replaceImage(0,e),u}}}function YM(n,t,e){var u;const{data:o}=e,r=n.getBlockString(t).trim();if(!o||o.embedType!=="image"||!P(n,t))return null;const i=r.match(/^!\[[^\]]*\]\((?<filename>.*?)(?="|\))(?<optionalPart>".*")?\)/),s=(u=i==null?void 0:i.groups)==null?void 0:u.filename;if(!s)return null;const l={src:s},c={id:N(),type:"embed",embedType:"image",embedData:l},a=n.options.componentsOptions.image.defaultAlign;return a&&(c.align=a),{blockData:c}}function QM(n,t){const e=q(t);n.destroyCustom(`image-${e}`)}const M6={embedType:"image",createEmbedContent:VM,convertTo:qM,convertFrom:YM,getBlockProperties:GM,getOptions:ZM,handleDrop:UL,handleDropOver:WL,handleDeleteBlock:QM},R6={"en-US":{title:"UML",empty:"Empty Graph",loading:"Loading diagram editor...",abstract:"UML"},"zh-CN":{title:"\u6D41\u7A0B\u56FE/UML",empty:"\u7A7A\u56FE\u8868",loading:"\u52A0\u8F7D\u4E2D",abstract:"\u6D41\u7A0B\u56FE/UML"}};function KM(n,t){const e={};t&&Object.entries(R6).forEach(([o,r])=>{e[o]={[`${t}`]:r}}),T.mergeLang(e||n)}function JM(){KM(R6,"drawio")}class XM{constructor(){h(this,"isAlreadyInstalled",!1)}stamp(){this.isAlreadyInstalled=!0}isFirstInit(){return this.isAlreadyInstalled===!1}destroy(){}}function tR(n){const t=Object.entries(n);for(let e=0;e<t.length;e++){const[o,r]=t[e];if(o.toLocaleLowerCase()==="content-type")return r}return""}async function eR(n,t,e=!0){try{const o=await n.doc.request(t,{method:"get",responseType:"blob",withCredentials:e}),r=new FileReader,i=new Promise((u,f)=>{r.onload=u,r.onerror=f});r.readAsArrayBuffer(o.data),await i;const s=r.result,l=tR(o.headers).toLocaleLowerCase();let c="";if(l){const u=Kf.default[l].extensions;u&&u.length>0&&(c=u[0])}return new File([s],`${Date.now()}.${c}`,{type:l})}catch{return null}}async function j1(n,t){return await eR(n,t)}async function A6(n,t){const e=await j1(n,t);return e?await e.text():null}const nR=n=>{const t=n.getBoundingClientRect();return t.width<=1&&t.height<=1},oR=n=>{var i,s;const t=(i=n.getAttribute("width"))!=null?i:"",e=(s=n.getAttribute("height"))!=null?s:"",o=Number.parseInt(t,10),r=Number.parseInt(e,10);return!o||!r||o<=1&&r<=1},rR=n=>n!=null?n[n.textContent===void 0?"text":"textContent"]:"",O6={"zh-CN":"zh","zh-TW":"zh-tw","js-JP":"zh"},iR="https://embed.diagrams.net/?embed=1",sR="https://www.draw.io/embed.js",lR="https://cdn.jsdelivr.net/npm/pako@2.0.3/dist/pako.es5.js",cR=`
413
+ `)}class WM{constructor(){h(this,"group","image");h(this,"commands",[])}executeCommand(t,e,o){if(o.id==="replace-image"){const{block:r,image:i}=o.data;zt.getImageObject(t,r).replaceImage(0,i)}}}function GM(){return{blockCommands:{image:new WM},abstract:`[${T.t("image.abstract")}]`}}function ZM(){return{name:"Image",insertEmbedCommandItems:[{id:"insert-image",name:"Image",icon:Qw,group:"common",subText:"/image",order:100}],handleInsertEmptyEmbed:async(n,t)=>{var m;let e;if((m=t.data)!=null&&m.file&&(e=t.data.file),e=e!=null?e:await zo("image/*",{}),!e)return null;const o=await FL(e),r=n.rootContainer.clientWidth,i=o.width<r?Math.min(100,o.width/r*100):100,s={src:"",width:o.width,height:o.height,flex:1,virtualSize:!1},l=se([s],i),c={id:N(),type:"embed",embedType:"image",embedData:l},a=n.options.componentsOptions.image;a!=null&&a.defaultAlign&&(c.align=a.defaultAlign);const u=n.insertBlock(t.containerId,t.blockIndex,c);return zt.getImageObject(n,u).replaceImage(0,e),u}}}function YM(n,t,e){var u;const{data:o}=e,r=n.getBlockString(t).trim();if(!o||o.embedType!=="image"||!P(n,t))return null;const i=r.match(/^!\[[^\]]*\]\((?<filename>.*?)(?="|\))(?<optionalPart>".*")?\)/),s=(u=i==null?void 0:i.groups)==null?void 0:u.filename;if(!s)return null;const l={src:s},c={id:N(),type:"embed",embedType:"image",embedData:l},a=n.options.componentsOptions.image.defaultAlign;return a&&(c.align=a),{blockData:c}}function QM(n,t){const e=q(t);n.destroyCustom(`image-${e}`)}const M6={embedType:"image",createEmbedContent:VM,convertTo:qM,convertFrom:YM,getBlockProperties:GM,getOptions:ZM,handleDrop:UL,handleDropOver:WL,handleDeleteBlock:QM},R6={"en-US":{title:"UML",empty:"Empty Graph",loading:"Loading diagram editor...",abstract:"UML"},"zh-CN":{title:"\u6D41\u7A0B\u56FE/UML",empty:"\u7A7A\u56FE\u8868",loading:"\u52A0\u8F7D\u4E2D",abstract:"\u6D41\u7A0B\u56FE/UML"}};function KM(n,t){const e={};t&&Object.entries(R6).forEach(([o,r])=>{e[o]={[`${t}`]:r}}),T.mergeLang(e||n)}function JM(){KM(R6,"drawio")}class XM{constructor(){h(this,"isAlreadyInstalled",!1)}stamp(){this.isAlreadyInstalled=!0}isFirstInit(){return this.isAlreadyInstalled===!1}destroy(){}}function tR(n){const t=Object.entries(n);for(let e=0;e<t.length;e++){const[o,r]=t[e];if(o.toLocaleLowerCase()==="content-type")return r}return""}async function eR(n,t,e=!0){try{const o=await n.doc.request(t,{method:"get",responseType:"blob",withCredentials:e}),r=new FileReader,i=new Promise((u,f)=>{r.onload=u,r.onerror=f});r.readAsArrayBuffer(o.data),await i;const s=r.result,l=tR(o.headers).toLocaleLowerCase();let c="";if(l){const u=Kf.default[l].extensions;u&&u.length>0&&(c=u[0])}return new File([s],`${Date.now()}.${c}`,{type:l})}catch{return null}}async function j1(n,t){return await eR(n,t)}async function A6(n,t){const e=await j1(n,t);return e?await e.text():null}const nR=n=>{const t=n.getBoundingClientRect();return t.width<=1&&t.height<=1},oR=n=>{var i,s;const t=(i=n.getAttribute("width"))!=null?i:"",e=(s=n.getAttribute("height"))!=null?s:"",o=Number.parseInt(t,10),r=Number.parseInt(e,10);return!o||!r||o<=1&&r<=1},rR=n=>n!=null?n[n.textContent===void 0?"text":"textContent"]:"",O6={"zh-CN":"zh","zh-TW":"zh-tw","js-JP":"zh"},iR="https://embed.diagrams.net/?embed=1",sR="https://www.draw.io/embed.js",lR="https://cdn.jsdelivr.net/npm/pako@2.0.3/dist/pako.es5.js",cR=`
414
414
  <mxStylesheet>
415
415
  <add as="defaultVertex">
416
416
  <add as="shape" value="label"/>
@@ -520,13 +520,13 @@ ${s}
520
520
  <add as="fillColor" value="#ffffff"/>
521
521
  </add>
522
522
  </mxStylesheet>
523
- `,_6=0,aR=30*1e3,N6="editor-empty-drawio",$6="show-full-screen-iframe",Zt=B("embed-block-drawio");function si(n){return n.options.componentsOptions.drawIO||{}}function dR(n){const e=si(n).lang||"zh-CN";return O6[e]||O6["zh-CN"]}function uR(n){var r;const e=((r=(si(n)||{}).cdn)==null?void 0:r.drawioIframe)||iR,o=dR(n);return ud(e,{spin:1,proto:"json",configure:1,lang:o})}function hR(n){const t=()=>{d(Zt,n,"el does not exist");const o=document.body.clientWidth||document.documentElement.clientWidth,r=document.body.clientHeight||document.documentElement.clientHeight;n.setAttribute("width",`${o-2*_6}`),n.setAttribute("height",`${r-2*_6}`)},e=()=>{window.removeEventListener("resize",t)};return t(),window.addEventListener("resize",t),{disconnect:e}}async function fR(n){const e=(si(n)||{}).callbacks||{},{onCreateDrawIoFrame:o,onCloseDrawIoFrame:r}=e;let i=null,s;if(o)i=await o(n),d(Zt,i,"iframe create failed"),s=()=>{d(Zt,i,"iframe does not exist"),d(Zt,r,"missing parameters: onCloseDrawIoFrame"),r(n,i)};else{const l=b("div",["editor-drawio-iframe-container","loading"],document.body);l.setAttribute("data-placeholder",T.t("drawio.loading")),i=b("iframe",["drawio-iframe-element"],l),i.setAttribute("frameborder","0"),A(l,$6);const{disconnect:c}=hR(i);s=()=>{d(Zt,i,"iframe does not exist"),c(),document.body.removeChild(l),z(l,$6)}}return{drawioIframe:i,exit:s}}async function mR(n,t,e,o){var r,i;try{o&&Zt.debug("auto saving drawio data");const s=new Blob([e]),l=new File([s],"drawio.svg",{type:"image/svg+xml"});try{const c=await n.doc.uploadResource(l),{resourceId:a}=c,f={...n.getBlockData(t),embedData:{src:a}};n.updateBlockData(t,f)}catch(c){const a=`failed to upload drawio data: ${c.message}`;Zt.error(a)}}catch(s){const l=`failed to save drawio data: ${s.message}`,c=si(n);if((r=c.callbacks)!=null&&r.onError){const a=new Error(l);a.code="SaveDrawIo",(i=c.callbacks)==null||i.onError(n,a)}}}function gR(n,t,e,o,r,i,s){const l=()=>{window.removeEventListener("message",c),i()},c=async a=>{var u,f;if(d(Zt,o.contentWindow,"iframe.contentWindow does not exist"),a.data.length>0){const m=JSON.parse(a.data),C=e.xmlSvg||e.xml,k=document.querySelectorAll(".editor-drawio-iframe-container");switch(m.event){case"configure":o.contentWindow.postMessage(JSON.stringify({action:"configure",config:{defaultFonts:["Humor Sans","Helvetica","Times New Roman"]}}),"*");break;case"init":C!=null&&o.contentWindow.postMessage(JSON.stringify({action:"load",saveAndExit:1,noSaveBtn:1,noExitBtn:0,xml:C}),"*"),r(),k.forEach(y=>{z(y,"loading")});break;case"export":const w=yl(m.data.substring(m.data.indexOf(",")+1));mR(n,t,w,!!((u=m.message)!=null&&u.autoSave)),(f=m.message)!=null&&f.autoSave||l();break;case"save":o.contentWindow.postMessage(JSON.stringify({action:"export",format:"xmlsvg",spin:"Saving graph"}),"*");break;case"exit":l();break}}};window.addEventListener("message",c)}async function P6(n,t,e,o){if(o)return;o=!0;const r=si(n)||{},{callbacks:i}=r;let s;const l=it(t);i&&(i==null?void 0:i.onBeginInitDrawIo)&&i.onBeginInitDrawIo(n,l),y6(n,t);const{drawioIframe:c,exit:a}=await fR(n);if(e.src){const C=await A6(n,n.doc.buildResourceUrl(e.src));C&&(e.xmlSvg=C)}gR(n,t,e,c,()=>{s=setInterval(()=>{!c||!c.contentWindow||c.contentWindow.postMessage(JSON.stringify({action:"export",format:"xmlsvg",spin:"Saving graph",autoSave:!0}),"*")},aR)},()=>{a(),s&&clearInterval(s),w6(n,t)});const m=uR(n);c.setAttribute("src",m)}async function pR(n){var r,i;const t=si(n),e=((r=t.cdn)==null?void 0:r.drawio)||sR,o=((i=t.cdn)==null?void 0:i.pako)||lR;await $o(o,"editor-pako"),await $o(e,"editor-drawio"),await new Promise(s=>{setTimeout(s,100)})}function j6(n){z(n,N6)}function H1(n){n.setAttribute("data-empty-drawio-content",T.t("drawio.empty")),A(n,N6)}function F1(n,t){if(d(Zt,t,"Required data is missing in setGraph"),"src"in t){n.setAttribute("data-src",t.src);return}if("xmlSvg"in t){n.setAttribute("data-xmlsvg",t.xmlSvg);return}if("graph"in t){const{xml:e,graph:o}=t;n.graph=o,n.setAttribute("data-mxfile",e)}}function CR(n,t,e){d(Zt,n,"params error: src"),d(Zt,e,"params error: editor");const o=t,r=e.doc.buildResourceUrl(n),i=document.createElement("img");o.innerHTML="",o.appendChild(i),i.src=r,F1(o,{src:n}),i.onload=()=>{nR(i)?H1(t):j6(t)}}function bR(n,t,e){d(Zt,e,"parameter missing"),pR(e).then(()=>{const{mxUtils:o,mxGraph:r,mxCodec:i}=window;d(Zt,o,"External resource loading exception: mxUtils"),d(Zt,r,"External resource loading exception: MxGraph"),d(Zt,i,"External resource loading exception: MxCodec");const s=o.parseXml(n);t.innerHTML="";const l=s.documentElement;d(Zt,l,"Resource parsing exception"),d(Zt,l.nodeName==="mxfile","Resource parsing exception");const c=l.getElementsByTagName("diagram");d(Zt,c.length>0,"Resource parsing exception");let a;const u=c[0];if(u.text||u.textContent){const w=rR(u),y=atob(w),S=window.pako;d(Zt,S,"External resource loading exception: pako");const I=S.inflateRaw(Uint8Array.from(y,R=>R.charCodeAt(0)),{to:"string"}),M=decodeURIComponent(I);a=o.parseXml(M)}else{const w=new XMLSerializer().serializeToString(u.firstChild);a=o.parseXml(w)}const f=new r(t);f.resetViewOnRootChange=!1,f.foldingEnabled=!1,f.setTooltips(!1),f.setEnabled(!1),f.setHtmlLabels(!0);const m=o.parseXml(cR);new i(m).decode(m.documentElement,f.getStylesheet());const k=new i(a);k.decode(k.document.documentElement,f.getModel()),f.maxFitScale=1,f.fit(),f.center(!0,!1),F1(t,{graph:f,xml:n})})}function kR(n,t){t.innerHTML=n,F1(t,{xmlSvg:n});const e=t.querySelectorAll("svg");for(let o=0;o<e.length;o++){const r=e[o];if(!oR(r))return}H1(t)}function vR(n,t){const e=y1(n,t,{handleExecuteCommand:(o,r,i)=>{if(i.id==="edit"){const s=o.getBlockData(r).embedData;return P6(o,r,s,!1),!0}return!1}});return n.isBlockWritable(t)||e.blockCommands["hovering-toolbar"].commands.forEach(o=>{o.id==="edit"&&(o.states=["disabled"])}),e}const Gs=B("embed-block-drawio"),yR=!1;JM();function H6(n,t,e,o){d(Gs,e,`parameter missing: ${e}`),d(Gs,n,`parameter missing: ${n}`),P6(n,t,o,yR)}function wR(n,t,e){j6(t);const o=e;o.src?CR(o.src,t,n):o.xml?bR(o.xml,t,n):o.xmlSvg?kR(o.xmlSvg,t):H1(t)}function BR(n,t,e,o,r={isInit:!1}){const{isInit:i}=r,l=b("div",["editor-drawio-content","editor-embed"],null);e.appendChild(l),wR(n,l,o),d(Gs,t,"embedContainer parentElement node does not exist"),i&&!n.readonly&&n.domEvents.addEventListener(e,"dblclick",()=>{const c=n.getBlockData(t);H6(n,t,l,c.embedData)})}function ER(n,t,e,o,r,i){const s=e.embedData,l=n.addCustom(`drawio-${e.id}`,()=>new XM),c=l.isFirstInit();c?Gs.log("create new embed block"):Gs.log("update exists embed block"),l.stamp(),BR(n,i,t,s,{isInit:c})}function IR(){return{name:"UML",insertEmbedCommandItems:[{id:"insert-drawio",name:T.t("drawio.title"),icon:fB,group:"common",order:600,subText:me("insert-drawio")}],handleInsertEmptyEmbed:async(n,t)=>{const e={src:"",xml:"",xmlSvg:""},o=n.insertEmbed(t.containerId,t.blockIndex,"drawio",e);return setTimeout(()=>{const i=it(o).querySelector(":scope > .editor-drawio-content"),s=n.getBlockData(o);H6(n,o,i,s.embedData)},100),o}}}function xR(n,t,e,o){const{embedData:r}=t,i=r;return o==="html"?i.src?`<img src="${n.doc.buildResourceUrl(i.src,{withToken:!0})}" />`:i.xmlSvg?i.xmlSvg:"<p>[drawio]</p>":o==="markdown"?i.src?`![drawio](${n.doc.buildResourceUrl(i.src,{withToken:!0})})`:i.xmlSvg?i.xmlSvg:"[drawio]":i.src?`[drawio](${n.doc.buildResourceUrl(i.src,{withToken:!0})})`:"[drawio]"}const fa={embedType:"drawio",getOptions:IR,createEmbedContent:ER,getBlockProperties:vR,convertTo:xR},Uz="",Vz="",TR=500,SR=300,z1=B("code-editor");function DR(n){const t=n.closest(".embed-code-editor-container");return d(z1,t,"code-editor-container non-existent"),t}function LR(n,t,e){const o=n.target;d(z1,o,"Parameter error: textarea must be an element");const r=o.value;DR(o).remove(),z(t,"editing"),e(r),it(t).style.removeProperty("margin-top")}function MR(n,t){d(z1,n,"Parameter Error: handleCodeUpdate[event]");const e=n.target.value;t(e)}const RR=Xt.default(MR,TR);function AR(n,t,e,o,r){n.domEvents.addEventListener(t,"blur",(i,s)=>{LR(s,e,r)}),n.domEvents.addEventListener(t,"keyup",(i,s)=>{const l=s.target;s.key==="Escape"&&l.blur()}),n.domEvents.addEventListener(t,"input",(i,s)=>{RR(s,o)})}function OR(n,t,e){const{height:o,codeValue:r,onChange:i,onEnd:s}=e,l=o||SR,c=it(t),a=Rt(t),u=b("div",["embed-code-editor-container"],a),f=b("textarea",["embed-code-editor-textarea"],u);f.value=r||"",f.setAttribute("spellcheck","false"),u.style.height=`${l}px`,AR(n,f,t,i,s),c.style.marginTop=`${l}px`,A(t,"editing"),window.requestAnimationFrame(()=>{f.setSelectionRange(0,0),f.focus(),f.scrollTop=0})}const _R={mermaid:"https://mermaid-js.github.io/mermaid/",flowchart:"https://flowchart.js.org/",plantuml:"https://plantuml.com/"};class NR extends v1{constructor(e,o,r){super(e,r);h(this,"group","hovering-toolbar");h(this,"_commands",[{id:"edit",name:"Edit",icon:hh},{id:"help",name:"Help",icon:oB}]);this.editor=e,this.graphType=o,this.properties=r}executeCommand(e,o,r){var i,s;(s=(i=this.properties)==null?void 0:i.handleExecuteCommand)!=null&&s.call(i,e,o,r)||r.id==="edit"||r.id==="help"&&window.open(_R[this.graphType])}}function $R(n,t,e){return{blockCommands:{"hovering-toolbar":new NR(n,t,e)}}}class U1{constructor(t,e,o){h(this,"editor");h(this,"logger");h(this,"editing",!1);this.graphType=e,this.codeEmbedDataKey=o,this.editor=t,this.logger=B(`embed-block-${this.graphType}`)}i18nt(t,e){return T.t(`graph.${t}`,e||{})}getContent(t){d(this.logger,t,"embed-element does not exist");const e=t.parentElement;return d(this.logger,e,"content-element does not exist"),e}getEmbed(t){const e=t.childNodes[0];return d(this.logger,e,"embed-element does not exist"),e}async uploadResource(t){const e=new Blob([t]),o=new File([e],`${this.graphType}.svg`,{type:"image/svg+xml"});try{const r=await this.editor.doc.uploadResource(o);d(this.logger,r,"uploadResource failed");const{resourceId:i}=r;return this.editor.doc.buildResourceUrl(i)}catch(r){return this.logger.error(r),null}}createEmbedContent(t,e){const o=b("div",["graph-embed"],t);this.editor.domEvents.addEventListener(o,"dblclick",(a,u)=>{this.editGraph(t),u.preventDefault(),u.stopPropagation()});const{embedData:r}=e,i=r[`${this.codeEmbedDataKey}`],s=r.src,l=b("div",["embed-graph-img-content"],o),c=b("img",["graph-embed-image"],l);c.draggable=!1,this.updateImage(o,i,s,null)}updateEmbedContent(t,e){const{embedData:o}=e,r=o[this.codeEmbedDataKey],i=o.src,s=t.querySelector(".graph-embed");this.updateImage(s,r,i,null)}async updateImage(t,e,o,r){const i=t.querySelector("img.graph-embed-image");let s=this.editor.doc.buildResourceUrl(o||"");if(!s&&!r&&e)try{s=await this.code2ObjectUrl(e)}catch(l){this.updateImage(t,e,o,l);return}this.updateClasses(t,e,r),s&&(i.src=s)}updateClasses(t,e,o){z(t,"empty-embed","invalid-code");const r=t.querySelector("img.graph-embed-image");if(o){r.src="",A(t,"invalid-code");const i=this.i18nt("invalid",{EmbedName:this.graphType,message:`${o.message}`||""});t.setAttribute("data-invalid-text",i);return}if(!e){r.src="";const i=this.i18nt("empty",{EmbedName:this.graphType});t.setAttribute("data-empty-tips",i),A(t,"empty-embed")}}editGraph(t){this.editing=!0;const e=F(t);d(this.logger,e,`${this.graphType} block does not exist`);const o=t.querySelector(".graph-embed"),r=l=>{this.updateImage(o,l,null,null)},i=async l=>{try{if(this.editing=!1,r(l),!this.hasChanged(e,l))return;const a={src:await this.code2ResourceId(l),[`${this.codeEmbedDataKey}`]:l};this.editor.updateEmbedData(e,a)}catch(c){this.updateClasses(o,l,c);const a={src:"",[`${this.codeEmbedDataKey}`]:l};this.editor.updateEmbedData(e,a)}},s=this.editor.getBlockData(e);OR(this.editor,e,{onChange:r,onEnd:i,codeValue:s.embedData[`${this.codeEmbedDataKey}`]})}getBlockProperties(t){return this.editing?{}:$R(this.editor,this.graphType,{handleExecuteCommand:(e,o,r)=>{if(r.id==="edit"){const i=it(o);return this.editGraph(i),!0}return!1}})}hasChanged(t,e){return this.editor.getBlockData(t).embedData[`${this.codeEmbedDataKey}`]!==e}}const PR="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js",jR=["//cdnjs.cloudflare.com/ajax/libs/raphael/2.3.0/raphael.min.js","//cdnjs.cloudflare.com/ajax/libs/flowchart/1.15.0/flowchart.min.js"],HR="https://www.plantuml.com/plantuml/svg",FR=B("mermaid-helper"),zR="wiz-editor-mermaid";async function F6(n,t){var k;const o=((k=(n.getComponentOptions("mermaid")||{}).cdn)==null?void 0:k.mermaid)||PR;await $o(o,zR);const r=window.mermaid;d(FR,r,"Resource load failed: Mermaid javaScript resource injection failed");const i=N(),l=await new Promise((w,y)=>{try{r.mermaidAPI.render(i,t,S=>{setTimeout(()=>{w(S)})})}catch(S){S.message=S.str,y(S)}}),u=new DOMParser().parseFromString(l,"image/svg+xml").firstChild,f=u.style.maxWidth;return f&&u.setAttribute("width",f),new XMLSerializer().serializeToString(u)}async function UR(n,t){const e=await F6(n,t);return hd(e,"image/svg+xml",`${N()}.svg`)}async function VR(n,t){const e=await F6(n,t),o=new Blob([e]),r=new File([o],`${N()}.svg`,{type:"image/svg+xml"});return(await n.doc.uploadResource(r)).resourceId}class li extends U1{constructor(t){super(t,"mermaid","mermaidText")}static get(t,e){return t.addCustom(`mermaid-${e.id}`,()=>new li(t))}code2ObjectUrl(t){return UR(this.editor,t)}code2ResourceId(t){return VR(this.editor,t)}destroy(){}}const qR={graph:{invalid:"\u65E0\u6548\u7684 {EmbedName} \u5185\u5BB9\uFF1A{message}",empty:"\u7A7A\u7684 {EmbedName}",flowchart:{},mermaid:{},plantuml:{}}},WR={invalid:"Invalid {EmbedName} content: {message}",empty:"Empty {EmbedName}",flowchart:{},mermaid:{},plantuml:{}};T.mergeLang({"zh-CN":qR,"en-US":WR});function GR(n,t,e){li.get(n,e).createEmbedContent(t,e)}function ZR(n,t,e){const o=li.get(n,n.getBlockData(t)),r=it(t);return o.updateEmbedContent(r,e),!0}function YR(n,t,e){const{data:o}=e,r=n.getBlockString(t).trim();if(!o||o.embedType!=="mermaid"||r!=="```mermaid"||!P(n,t))return null;const i={src:"",mermaidText:""};return{blockData:{id:N(),type:"embed",embedType:"mermaid",embedData:i},onConverted:(c,a)=>{li.get(c,c.getBlockData(a)).editGraph(it(a))}}}function QR(n,t){return li.get(n,n.getBlockData(t)).getBlockProperties()}function KR(n,t,e,o){const{embedData:r}=t,i=r;if(o==="html")return i.src?`<img src="${n.doc.buildResourceUrl(i.src,{withToken:!0})}" />`:i.mermaidText?`<div class="mermaid">${i.mermaidText}</div>`:"<p>[mermaid]</p>";if(o==="markdown"){if(i.src)return`![mermaid](${n.doc.buildResourceUrl(i.src,{withToken:!0})})`;if(i.mermaidText)return`\`\`\`mermaid\`\`\`
523
+ `,_6=0,aR=30*1e3,N6="editor-empty-drawio",$6="show-full-screen-iframe",Zt=B("embed-block-drawio");function si(n){return n.options.componentsOptions.drawIO||{}}function dR(n){const e=si(n).lang||"zh-CN";return O6[e]||O6["zh-CN"]}function uR(n){var r;const e=((r=(si(n)||{}).cdn)==null?void 0:r.drawioIframe)||iR,o=dR(n);return ud(e,{spin:1,proto:"json",configure:1,lang:o})}function hR(n){const t=()=>{d(Zt,n,"el does not exist");const o=document.body.clientWidth||document.documentElement.clientWidth,r=document.body.clientHeight||document.documentElement.clientHeight;n.setAttribute("width",`${o-2*_6}`),n.setAttribute("height",`${r-2*_6}`)},e=()=>{window.removeEventListener("resize",t)};return t(),window.addEventListener("resize",t),{disconnect:e}}async function fR(n){const e=(si(n)||{}).callbacks||{},{onCreateDrawIoFrame:o,onCloseDrawIoFrame:r}=e;let i=null,s;if(o)i=await o(n),d(Zt,i,"iframe create failed"),s=()=>{d(Zt,i,"iframe does not exist"),d(Zt,r,"missing parameters: onCloseDrawIoFrame"),r(n,i)};else{const l=b("div",["editor-drawio-iframe-container","loading"],document.body);l.setAttribute("data-placeholder",T.t("drawio.loading")),i=b("iframe",["drawio-iframe-element"],l),i.setAttribute("frameborder","0"),A(l,$6);const{disconnect:c}=hR(i);s=()=>{d(Zt,i,"iframe does not exist"),c(),document.body.removeChild(l),z(l,$6)}}return{drawioIframe:i,exit:s}}async function mR(n,t,e,o){var r,i;try{o&&Zt.debug("auto saving drawio data");const s=new Blob([e]),l=new File([s],"drawio.svg",{type:"image/svg+xml"});try{const c=await n.doc.uploadResource(l),{resourceId:a}=c,f={...n.getBlockData(t),embedData:{src:a}};n.updateBlockData(t,f)}catch(c){const a=`failed to upload drawio data: ${c.message}`;Zt.error(a)}}catch(s){const l=`failed to save drawio data: ${s.message}`,c=si(n);if((r=c.callbacks)!=null&&r.onError){const a=new Error(l);a.code="SaveDrawIo",(i=c.callbacks)==null||i.onError(n,a)}}}function gR(n,t,e,o,r,i,s){const l=()=>{window.removeEventListener("message",c),i()},c=async a=>{var u,f;if(d(Zt,o.contentWindow,"iframe.contentWindow does not exist"),a.data.length>0){const m=JSON.parse(a.data),C=e.xmlSvg||e.xml,k=document.querySelectorAll(".editor-drawio-iframe-container");switch(m.event){case"configure":o.contentWindow.postMessage(JSON.stringify({action:"configure",config:{defaultFonts:["Humor Sans","Helvetica","Times New Roman"]}}),"*");break;case"init":C!=null&&o.contentWindow.postMessage(JSON.stringify({action:"load",saveAndExit:1,noSaveBtn:1,noExitBtn:0,xml:C}),"*"),r(),k.forEach(y=>{z(y,"loading")});break;case"export":const w=yl(m.data.substring(m.data.indexOf(",")+1));mR(n,t,w,!!((u=m.message)!=null&&u.autoSave)),(f=m.message)!=null&&f.autoSave||l();break;case"save":o.contentWindow.postMessage(JSON.stringify({action:"export",format:"xmlsvg",spin:"Saving graph"}),"*");break;case"exit":l();break}}};window.addEventListener("message",c)}async function P6(n,t,e,o){if(o)return;o=!0;const r=si(n)||{},{callbacks:i}=r;let s;const l=it(t);i&&(i==null?void 0:i.onBeginInitDrawIo)&&i.onBeginInitDrawIo(n,l),y6(n,t);const{drawioIframe:c,exit:a}=await fR(n);if(e.src){const C=await A6(n,n.doc.buildResourceUrl(e.src));C&&(e.xmlSvg=C)}gR(n,t,e,c,()=>{s=setInterval(()=>{!c||!c.contentWindow||c.contentWindow.postMessage(JSON.stringify({action:"export",format:"xmlsvg",spin:"Saving graph",autoSave:!0}),"*")},aR)},()=>{a(),s&&clearInterval(s),w6(n,t)});const m=uR(n);c.setAttribute("src",m)}async function pR(n){var r,i;const t=si(n),e=((r=t.cdn)==null?void 0:r.drawio)||sR,o=((i=t.cdn)==null?void 0:i.pako)||lR;await Po(o,"editor-pako"),await Po(e,"editor-drawio"),await new Promise(s=>{setTimeout(s,100)})}function j6(n){z(n,N6)}function H1(n){n.setAttribute("data-empty-drawio-content",T.t("drawio.empty")),A(n,N6)}function F1(n,t){if(d(Zt,t,"Required data is missing in setGraph"),"src"in t){n.setAttribute("data-src",t.src);return}if("xmlSvg"in t){n.setAttribute("data-xmlsvg",t.xmlSvg);return}if("graph"in t){const{xml:e,graph:o}=t;n.graph=o,n.setAttribute("data-mxfile",e)}}function CR(n,t,e){d(Zt,n,"params error: src"),d(Zt,e,"params error: editor");const o=t,r=e.doc.buildResourceUrl(n),i=document.createElement("img");o.innerHTML="",o.appendChild(i),i.src=r,F1(o,{src:n}),i.onload=()=>{nR(i)?H1(t):j6(t)}}function bR(n,t,e){d(Zt,e,"parameter missing"),pR(e).then(()=>{const{mxUtils:o,mxGraph:r,mxCodec:i}=window;d(Zt,o,"External resource loading exception: mxUtils"),d(Zt,r,"External resource loading exception: MxGraph"),d(Zt,i,"External resource loading exception: MxCodec");const s=o.parseXml(n);t.innerHTML="";const l=s.documentElement;d(Zt,l,"Resource parsing exception"),d(Zt,l.nodeName==="mxfile","Resource parsing exception");const c=l.getElementsByTagName("diagram");d(Zt,c.length>0,"Resource parsing exception");let a;const u=c[0];if(u.text||u.textContent){const w=rR(u),y=atob(w),S=window.pako;d(Zt,S,"External resource loading exception: pako");const I=S.inflateRaw(Uint8Array.from(y,R=>R.charCodeAt(0)),{to:"string"}),M=decodeURIComponent(I);a=o.parseXml(M)}else{const w=new XMLSerializer().serializeToString(u.firstChild);a=o.parseXml(w)}const f=new r(t);f.resetViewOnRootChange=!1,f.foldingEnabled=!1,f.setTooltips(!1),f.setEnabled(!1),f.setHtmlLabels(!0);const m=o.parseXml(cR);new i(m).decode(m.documentElement,f.getStylesheet());const k=new i(a);k.decode(k.document.documentElement,f.getModel()),f.maxFitScale=1,f.fit(),f.center(!0,!1),F1(t,{graph:f,xml:n})})}function kR(n,t){t.innerHTML=n,F1(t,{xmlSvg:n});const e=t.querySelectorAll("svg");for(let o=0;o<e.length;o++){const r=e[o];if(!oR(r))return}H1(t)}function vR(n,t){const e=y1(n,t,{handleExecuteCommand:(o,r,i)=>{if(i.id==="edit"){const s=o.getBlockData(r).embedData;return P6(o,r,s,!1),!0}return!1}});return n.isBlockWritable(t)||e.blockCommands["hovering-toolbar"].commands.forEach(o=>{o.id==="edit"&&(o.states=["disabled"])}),e}const Gs=B("embed-block-drawio"),yR=!1;JM();function H6(n,t,e,o){d(Gs,e,`parameter missing: ${e}`),d(Gs,n,`parameter missing: ${n}`),P6(n,t,o,yR)}function wR(n,t,e){j6(t);const o=e;o.src?CR(o.src,t,n):o.xml?bR(o.xml,t,n):o.xmlSvg?kR(o.xmlSvg,t):H1(t)}function BR(n,t,e,o,r={isInit:!1}){const{isInit:i}=r,l=b("div",["editor-drawio-content","editor-embed"],null);e.appendChild(l),wR(n,l,o),d(Gs,t,"embedContainer parentElement node does not exist"),i&&!n.readonly&&n.domEvents.addEventListener(e,"dblclick",()=>{const c=n.getBlockData(t);H6(n,t,l,c.embedData)})}function ER(n,t,e,o,r,i){const s=e.embedData,l=n.addCustom(`drawio-${e.id}`,()=>new XM),c=l.isFirstInit();c?Gs.log("create new embed block"):Gs.log("update exists embed block"),l.stamp(),BR(n,i,t,s,{isInit:c})}function IR(){return{name:"UML",insertEmbedCommandItems:[{id:"insert-drawio",name:T.t("drawio.title"),icon:fB,group:"common",order:600,subText:me("insert-drawio")}],handleInsertEmptyEmbed:async(n,t)=>{const e={src:"",xml:"",xmlSvg:""},o=n.insertEmbed(t.containerId,t.blockIndex,"drawio",e);return setTimeout(()=>{const i=it(o).querySelector(":scope > .editor-drawio-content"),s=n.getBlockData(o);H6(n,o,i,s.embedData)},100),o}}}function xR(n,t,e,o){const{embedData:r}=t,i=r;return o==="html"?i.src?`<img src="${n.doc.buildResourceUrl(i.src,{withToken:!0})}" />`:i.xmlSvg?i.xmlSvg:"<p>[drawio]</p>":o==="markdown"?i.src?`![drawio](${n.doc.buildResourceUrl(i.src,{withToken:!0})})`:i.xmlSvg?i.xmlSvg:"[drawio]":i.src?`[drawio](${n.doc.buildResourceUrl(i.src,{withToken:!0})})`:"[drawio]"}const fa={embedType:"drawio",getOptions:IR,createEmbedContent:ER,getBlockProperties:vR,convertTo:xR},Uz="",Vz="",TR=500,SR=300,z1=B("code-editor");function DR(n){const t=n.closest(".embed-code-editor-container");return d(z1,t,"code-editor-container non-existent"),t}function LR(n,t,e){const o=n.target;d(z1,o,"Parameter error: textarea must be an element");const r=o.value;DR(o).remove(),z(t,"editing"),e(r),it(t).style.removeProperty("margin-top")}function MR(n,t){d(z1,n,"Parameter Error: handleCodeUpdate[event]");const e=n.target.value;t(e)}const RR=Xt.default(MR,TR);function AR(n,t,e,o,r){n.domEvents.addEventListener(t,"blur",(i,s)=>{LR(s,e,r)}),n.domEvents.addEventListener(t,"keyup",(i,s)=>{const l=s.target;s.key==="Escape"&&l.blur()}),n.domEvents.addEventListener(t,"input",(i,s)=>{RR(s,o)})}function OR(n,t,e){const{height:o,codeValue:r,onChange:i,onEnd:s}=e,l=o||SR,c=it(t),a=Rt(t),u=b("div",["embed-code-editor-container"],a),f=b("textarea",["embed-code-editor-textarea"],u);f.value=r||"",f.setAttribute("spellcheck","false"),u.style.height=`${l}px`,AR(n,f,t,i,s),c.style.marginTop=`${l}px`,A(t,"editing"),window.requestAnimationFrame(()=>{f.setSelectionRange(0,0),f.focus(),f.scrollTop=0})}const _R={mermaid:"https://mermaid-js.github.io/mermaid/",flowchart:"https://flowchart.js.org/",plantuml:"https://plantuml.com/"};class NR extends v1{constructor(e,o,r){super(e,r);h(this,"group","hovering-toolbar");h(this,"_commands",[{id:"edit",name:"Edit",icon:hh},{id:"help",name:"Help",icon:oB}]);this.editor=e,this.graphType=o,this.properties=r}executeCommand(e,o,r){var i,s;(s=(i=this.properties)==null?void 0:i.handleExecuteCommand)!=null&&s.call(i,e,o,r)||r.id==="edit"||r.id==="help"&&window.open(_R[this.graphType])}}function $R(n,t,e){return{blockCommands:{"hovering-toolbar":new NR(n,t,e)}}}class U1{constructor(t,e,o){h(this,"editor");h(this,"logger");h(this,"editing",!1);this.graphType=e,this.codeEmbedDataKey=o,this.editor=t,this.logger=B(`embed-block-${this.graphType}`)}i18nt(t,e){return T.t(`graph.${t}`,e||{})}getContent(t){d(this.logger,t,"embed-element does not exist");const e=t.parentElement;return d(this.logger,e,"content-element does not exist"),e}getEmbed(t){const e=t.childNodes[0];return d(this.logger,e,"embed-element does not exist"),e}async uploadResource(t){const e=new Blob([t]),o=new File([e],`${this.graphType}.svg`,{type:"image/svg+xml"});try{const r=await this.editor.doc.uploadResource(o);d(this.logger,r,"uploadResource failed");const{resourceId:i}=r;return this.editor.doc.buildResourceUrl(i)}catch(r){return this.logger.error(r),null}}createEmbedContent(t,e){const o=b("div",["graph-embed"],t);this.editor.domEvents.addEventListener(o,"dblclick",(a,u)=>{this.editGraph(t),u.preventDefault(),u.stopPropagation()});const{embedData:r}=e,i=r[`${this.codeEmbedDataKey}`],s=r.src,l=b("div",["embed-graph-img-content"],o),c=b("img",["graph-embed-image"],l);c.draggable=!1,this.updateImage(o,i,s,null)}updateEmbedContent(t,e){const{embedData:o}=e,r=o[this.codeEmbedDataKey],i=o.src,s=t.querySelector(".graph-embed");this.updateImage(s,r,i,null)}async updateImage(t,e,o,r){const i=t.querySelector("img.graph-embed-image");let s=this.editor.doc.buildResourceUrl(o||"");if(!s&&!r&&e)try{s=await this.code2ObjectUrl(e)}catch(l){this.updateImage(t,e,o,l);return}this.updateClasses(t,e,r),s&&(i.src=s)}updateClasses(t,e,o){z(t,"empty-embed","invalid-code");const r=t.querySelector("img.graph-embed-image");if(o){r.src="",A(t,"invalid-code");const i=this.i18nt("invalid",{EmbedName:this.graphType,message:`${o.message}`||""});t.setAttribute("data-invalid-text",i);return}if(!e){r.src="";const i=this.i18nt("empty",{EmbedName:this.graphType});t.setAttribute("data-empty-tips",i),A(t,"empty-embed")}}editGraph(t){this.editing=!0;const e=F(t);d(this.logger,e,`${this.graphType} block does not exist`);const o=t.querySelector(".graph-embed"),r=l=>{this.updateImage(o,l,null,null)},i=async l=>{try{if(this.editing=!1,r(l),!this.hasChanged(e,l))return;const a={src:await this.code2ResourceId(l),[`${this.codeEmbedDataKey}`]:l};this.editor.updateEmbedData(e,a)}catch(c){this.updateClasses(o,l,c);const a={src:"",[`${this.codeEmbedDataKey}`]:l};this.editor.updateEmbedData(e,a)}},s=this.editor.getBlockData(e);OR(this.editor,e,{onChange:r,onEnd:i,codeValue:s.embedData[`${this.codeEmbedDataKey}`]})}getBlockProperties(t){return this.editing?{}:$R(this.editor,this.graphType,{handleExecuteCommand:(e,o,r)=>{if(r.id==="edit"){const i=it(o);return this.editGraph(i),!0}return!1}})}hasChanged(t,e){return this.editor.getBlockData(t).embedData[`${this.codeEmbedDataKey}`]!==e}}const PR="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js",jR=["//cdnjs.cloudflare.com/ajax/libs/raphael/2.3.0/raphael.min.js","//cdnjs.cloudflare.com/ajax/libs/flowchart/1.15.0/flowchart.min.js"],HR="https://www.plantuml.com/plantuml/svg",FR=B("mermaid-helper"),zR="wiz-editor-mermaid";async function F6(n,t){var k;const o=((k=(n.getComponentOptions("mermaid")||{}).cdn)==null?void 0:k.mermaid)||PR;await Po(o,zR);const r=window.mermaid;d(FR,r,"Resource load failed: Mermaid javaScript resource injection failed");const i=N(),l=await new Promise((w,y)=>{try{r.mermaidAPI.render(i,t,S=>{setTimeout(()=>{w(S)})})}catch(S){S.message=S.str,y(S)}}),u=new DOMParser().parseFromString(l,"image/svg+xml").firstChild,f=u.style.maxWidth;return f&&u.setAttribute("width",f),new XMLSerializer().serializeToString(u)}async function UR(n,t){const e=await F6(n,t);return hd(e,"image/svg+xml",`${N()}.svg`)}async function VR(n,t){const e=await F6(n,t),o=new Blob([e]),r=new File([o],`${N()}.svg`,{type:"image/svg+xml"});return(await n.doc.uploadResource(r)).resourceId}class li extends U1{constructor(t){super(t,"mermaid","mermaidText")}static get(t,e){return t.addCustom(`mermaid-${e.id}`,()=>new li(t))}code2ObjectUrl(t){return UR(this.editor,t)}code2ResourceId(t){return VR(this.editor,t)}destroy(){}}const qR={graph:{invalid:"\u65E0\u6548\u7684 {EmbedName} \u5185\u5BB9\uFF1A{message}",empty:"\u7A7A\u7684 {EmbedName}",flowchart:{},mermaid:{},plantuml:{}}},WR={invalid:"Invalid {EmbedName} content: {message}",empty:"Empty {EmbedName}",flowchart:{},mermaid:{},plantuml:{}};T.mergeLang({"zh-CN":qR,"en-US":WR});function GR(n,t,e){li.get(n,e).createEmbedContent(t,e)}function ZR(n,t,e){const o=li.get(n,n.getBlockData(t)),r=it(t);return o.updateEmbedContent(r,e),!0}function YR(n,t,e){const{data:o}=e,r=n.getBlockString(t).trim();if(!o||o.embedType!=="mermaid"||r!=="```mermaid"||!P(n,t))return null;const i={src:"",mermaidText:""};return{blockData:{id:N(),type:"embed",embedType:"mermaid",embedData:i},onConverted:(c,a)=>{li.get(c,c.getBlockData(a)).editGraph(it(a))}}}function QR(n,t){return li.get(n,n.getBlockData(t)).getBlockProperties()}function KR(n,t,e,o){const{embedData:r}=t,i=r;if(o==="html")return i.src?`<img src="${n.doc.buildResourceUrl(i.src,{withToken:!0})}" />`:i.mermaidText?`<div class="mermaid">${i.mermaidText}</div>`:"<p>[mermaid]</p>";if(o==="markdown"){if(i.src)return`![mermaid](${n.doc.buildResourceUrl(i.src,{withToken:!0})})`;if(i.mermaidText)return`\`\`\`mermaid\`\`\`
524
524
  ${i.mermaidText}
525
- \`\`\`\`\`\``}return"[mermaid]"}const V1={embedType:"mermaid",convertFrom:YR,handleUpdateBlock:ZR,createEmbedContent:GR,getBlockProperties:QR,convertTo:KR},z6=B("flowchart-helper");async function JR(n){var o;const t=n.getComponentOptions("flowchart")||{},e=((o=t==null?void 0:t.cdn)==null?void 0:o.flowchart)||jR;for(let r=0;r<e.length;r+=1){const i=e[r];await $o(i,`flowchart-scripts-${r}`)}}async function U6(n,t){const e=b("div",["flowchart-chart-container"],document.body);e.id=`flowchart-${N()}`,await JR(n);const o=window.flowchart;d(z6,o,"flowchart resource does not exist"),o.parse(t).drawSVG(e.id);const i=e.firstElementChild;d(z6,i,"svg element non-existent");const l=new XMLSerializer().serializeToString(i);return e.remove(),l}async function XR(n,t){const e=await U6(n,t);return hd(e,"image/svg+xml",`${Date.now()}.svg`)}async function tA(n,t){const e=await U6(n,t),o=new Blob([e]),r=new File([o],`${N()}.svg`,{type:"image/svg+xml"});return(await n.doc.uploadResource(r)).resourceId}class ci extends U1{constructor(t){super(t,"flowchart","flowchartText")}static get(t,e){return t.addCustom(`flowchart-${e.id}`,()=>new ci(t))}code2ObjectUrl(t){return XR(this.editor,t)}code2ResourceId(t){return tA(this.editor,t)}destroy(){}}function eA(n,t,e){ci.get(n,e).createEmbedContent(t,e)}function nA(n,t,e){const o=ci.get(n,e),r=it(t);return o.updateEmbedContent(r,e),!0}function oA(n,t,e){const{data:o}=e,r=n.getBlockString(t).trim();if(!o||o.embedType!=="flowchart"||r!=="```flowchart"||!P(n,t))return null;const i={src:"",flowchartText:""};return{blockData:{id:N(),type:"embed",embedType:"flowchart",embedData:i},onConverted:(c,a)=>{ci.get(c,c.getBlockData(a)).editGraph(it(a))}}}function rA(n,t){return ci.get(n,n.getBlockData(t)).getBlockProperties()}function iA(n,t,e,o){const{embedData:r}=t,i=r;if(o==="html")return i.src?`<img src="${n.doc.buildResourceUrl(i.src,{withToken:!0})}" />`:i.flowchartText?`<div>${i.flowchartText}</div>`:"<p>[flowchart]</p>";if(o==="markdown"){if(i.src)return`![flowchart](${n.doc.buildResourceUrl(i.src,{withToken:!0})})`;if(i.flowchartText)return`\`\`\`flowchart\`\`\`
525
+ \`\`\`\`\`\``}return"[mermaid]"}const V1={embedType:"mermaid",convertFrom:YR,handleUpdateBlock:ZR,createEmbedContent:GR,getBlockProperties:QR,convertTo:KR},z6=B("flowchart-helper");async function JR(n){var o;const t=n.getComponentOptions("flowchart")||{},e=((o=t==null?void 0:t.cdn)==null?void 0:o.flowchart)||jR;for(let r=0;r<e.length;r+=1){const i=e[r];await Po(i,`flowchart-scripts-${r}`)}}async function U6(n,t){const e=b("div",["flowchart-chart-container"],document.body);e.id=`flowchart-${N()}`,await JR(n);const o=window.flowchart;d(z6,o,"flowchart resource does not exist"),o.parse(t).drawSVG(e.id);const i=e.firstElementChild;d(z6,i,"svg element non-existent");const l=new XMLSerializer().serializeToString(i);return e.remove(),l}async function XR(n,t){const e=await U6(n,t);return hd(e,"image/svg+xml",`${Date.now()}.svg`)}async function tA(n,t){const e=await U6(n,t),o=new Blob([e]),r=new File([o],`${N()}.svg`,{type:"image/svg+xml"});return(await n.doc.uploadResource(r)).resourceId}class ci extends U1{constructor(t){super(t,"flowchart","flowchartText")}static get(t,e){return t.addCustom(`flowchart-${e.id}`,()=>new ci(t))}code2ObjectUrl(t){return XR(this.editor,t)}code2ResourceId(t){return tA(this.editor,t)}destroy(){}}function eA(n,t,e){ci.get(n,e).createEmbedContent(t,e)}function nA(n,t,e){const o=ci.get(n,e),r=it(t);return o.updateEmbedContent(r,e),!0}function oA(n,t,e){const{data:o}=e,r=n.getBlockString(t).trim();if(!o||o.embedType!=="flowchart"||r!=="```flowchart"||!P(n,t))return null;const i={src:"",flowchartText:""};return{blockData:{id:N(),type:"embed",embedType:"flowchart",embedData:i},onConverted:(c,a)=>{ci.get(c,c.getBlockData(a)).editGraph(it(a))}}}function rA(n,t){return ci.get(n,n.getBlockData(t)).getBlockProperties()}function iA(n,t,e,o){const{embedData:r}=t,i=r;if(o==="html")return i.src?`<img src="${n.doc.buildResourceUrl(i.src,{withToken:!0})}" />`:i.flowchartText?`<div>${i.flowchartText}</div>`:"<p>[flowchart]</p>";if(o==="markdown"){if(i.src)return`![flowchart](${n.doc.buildResourceUrl(i.src,{withToken:!0})})`;if(i.flowchartText)return`\`\`\`flowchart\`\`\`
526
526
  ${i.flowchartText}
527
527
  \`\`\`\`\`\``}return"[flowchart]"}const q1={embedType:"flowchart",convertFrom:oA,handleUpdateBlock:nA,createEmbedContent:eA,getBlockProperties:rA,convertTo:iA},sA=B("plantuml-helper");function V6(n,t){var l;let o=((l=(n.getComponentOptions("plantuml")||{}).cdn)==null?void 0:l.plantuml)||HR;o.endsWith("/")||(o+="/");const r=T7.default.encode(t);d(sA,r,r),o+=r;const s=new URLSearchParams(document.location.search).get("doc");return ud(o,{id:`${s}-${N()}`})}async function lA(n,t){const e=await j1(n,t);return(await n.doc.uploadResource(e)).resourceId}class ai extends U1{constructor(t){super(t,"plantuml","plantumlText")}static get(t,e){return t.addCustom(`plantuml-${e.id}`,()=>new ai(t))}code2ObjectUrl(t){return Promise.resolve(V6(this.editor,t))}code2ResourceId(t){const e=V6(this.editor,t);return lA(this.editor,e)}destroy(){}}function cA(n,t,e){ai.get(n,e).createEmbedContent(t,e)}function aA(n,t,e){const o=ai.get(n,e),r=it(t);return o.updateEmbedContent(r,e),!0}function dA(n,t,e){const{data:o}=e,r=n.getBlockString(t).trim();if(!o||o.embedType!=="plantuml"||r!=="```plantuml"||!P(n,t))return null;const i={src:"",plantumlText:""};return{blockData:{id:N(),type:"embed",embedType:"plantuml",embedData:i},onConverted:(c,a)=>{ai.get(c,c.getBlockData(a)).editGraph(it(a))}}}function uA(n,t){return ai.get(n,n.getBlockData(t)).getBlockProperties()}function hA(n,t,e,o){const{embedData:r}=t,i=r;if(o==="html")return i.src?`<img src="${n.doc.buildResourceUrl(i.src,{withToken:!0})}" />`:i.flowchartText?`<div>${i.flowchartText}</div>`:"<p>[plantuml]</p>";if(o==="markdown"){if(i.src)return`![plantuml](${n.doc.buildResourceUrl(i.src,{withToken:!0})})`;if(i.flowchartText)return`\`\`\`plantuml\`\`\`
528
528
  ${i.flowchartText}
529
- \`\`\`\`\`\``}return"[plantuml]"}const W1={embedType:"plantuml",convertFrom:dA,handleUpdateBlock:aA,createEmbedContent:cA,getBlockProperties:uA,convertTo:hA},qz="",fA="hr",mA={dividingLine:{type:"\u5206\u5272\u7EBF"}},gA={dividingLine:{type:"dividing-line"}};T.mergeLang({"zh-CN":mA,"en-US":gA});function pA(n,t){const e=b("div",["editor-embed-container"],t);b("hr",["editor-embed-hr"],e)}function CA(n,t,e,o){return o==="html"?"<hr />":o==="markdown"?"---":"------------"}function bA(){return{name:"hr",insertEmbedCommandItems:[{id:"insert-hr",name:T.t("dividingLine.type"),icon:mB,order:500,group:"common",subText:me("insert-hr")}],handleInsertEmptyEmbed:async(n,t)=>{const{containerId:e,blockIndex:o}=t;return n.insertEmbed(e,o,fA,{})}}}function kA(n,t,e){const{data:o}=e;if(!o||o.embedType!=="dividing-line"||!P(n,t))return null;const r={};return{blockData:{id:N(),type:"embed",embedType:"hr",embedData:r}}}const G1={embedType:"hr",createEmbedContent:pA,convertTo:CA,getOptions:bA,convertFrom:kA},Wz="";class vA{constructor(t,e){h(this,"toolbar");h(this,"anchor",null);h(this,"item");h(this,"docs",null);h(this,"checkedId");h(this,"handlePasteSpecial",(t,e)=>{!e.data||(this.checkedId===e.id?this.checkedId=void 0:this.checkedId=e.id,this.onPasteSpecial(e.data),setTimeout(()=>{this.docs&&this.show(this.docs),this.editor.focus()}))});h(this,"handleClose",()=>{this.editor.focus()});h(this,"handleSelectionChange",()=>{this.hide()});this.editor=t,this.onPasteSpecial=e,this.item={id:"paste-special",name:"Paste special",icon:Kw,dropdown:!0,manualShowChildren:!0,childrenPlacement:"bottom-start",childrenOffset:[-4,4],children:[]},this.toolbar=new ks([this.item],void 0,{id:"paste-special-button",tooltipId:this.editor.clientId,refuseOverflow:!0}),this.toolbar.addListener("click",this.handlePasteSpecial),this.toolbar.addListener("close",this.handleClose),this.editor.addListener("selectionChanged",this.handleSelectionChange)}show(t){this.docs=t;const e=this.editor,o=e.selection.range;if(!o.isCollapsed())return;const r=e.getBlockById(o.start.blockId);if(!P(e,r))return;const i=io(e,r,o)[0];if(!i)return;this.anchor&&this.anchor.remove(),this.anchor=co(e,r,"paste-special-button-anchor",i);const s=this.getCommandItems(t);this.item.children=s,this.toolbar.manualShow(this.anchor)}hide(){this.toolbar.close()}clearCheckedState(){this.checkedId=void 0}destroy(){this.toolbar.destroy(),this.editor.removeListener("selectionChanged",this.handleSelectionChange)}getCommandItems(t){const e=i=>({id:i,states:this.checkedId===i?["checked"]:void 0,name:"Keep origin formats",data:t[i]}),o=[];let r=!0;return t["text/x-ones-editor-doc"]?o.push(e("text/x-ones-editor-doc")):t["text/office-html"]?o.push(e("text/office-html")):t["text/html"]?o.push(e("text/html")):t["text/plain"]&&(o.push(e("text/plain")),r=!1),t["text/plain"]&&(r&&o.push({id:"text/plain",states:this.checkedId==="text/plain"?["checked"]:void 0,name:"Paste as plain text",data:t["text/plain"]}),o.push({id:"text/markdown",states:this.checkedId==="text/markdown"?["checked"]:void 0,name:"Paste as markdown",data:t["text/markdown"]})),o}}const yA=B("paste-special");class Z1{constructor(t){h(this,"button");h(this,"lastUndoAction",null);h(this,"event",null);h(this,"handlePasteSpecial",t=>{this.editor.undoManager.runInGroup(()=>{this.editor.undoManager.undoTo(this.lastUndoAction),this.editor.pasteDoc(t)})});this.editor=t,this.button=new vA(t,this.handlePasteSpecial)}destroy(){this.event=null,this.button.destroy()}handleChanged(t,e){this.event=null,this.button.hide()}async handleBeforePaste(t,e){return yA.debug("before paste"),this.lastUndoAction=t.undoManager.lastAction(),!1}async handleAfterPaste(t,e,o){if(Object.keys(o).length<=1)return!1;const r=t.selection.range;if(r.isCollapsed()){const i=t.getBlockById(r.start.blockId);if(!P(t,i))return!1;this.button.clearCheckedState(),this.button.show(o),this.event=e}return!1}}const Gz="",wA=B("html-to-doc");function BA(n){const t="ones-editor-doc::",e="::ones-editor-doc";let o=n.indexOf(t);if(o!==-1){o+=t.length;const r=n.indexOf(e,o);if(r!==-1){const i=n.substr(o,r-o);try{const s=yl(i);return JSON.parse(s)}catch(s){wA.error(`invalid doc data: ${s}, ${i}`)}}}return null}const q6="latex-b172fea480b",EA=n=>({name:"latex-block",level:"block",start(t){var e,o;return(o=(e=t.match(/\$\$[^\$]/))==null?void 0:e.index)!=null?o:-1},tokenizer(t,e){const o=/^\$\$([^\$]+)\$\$/.exec(t);return o?{type:"latex-block",raw:o[0],formula:o[1]}:void 0},renderer(t){return n.lazy?`<span class="${q6}" block>${t.formula}</span>`:n.render(t.formula,!0)}}),IA=n=>({name:"latex",level:"inline",start(t){var e,o;return(o=(e=t.match(/\$[^\$]/))==null?void 0:e.index)!=null?o:-1},tokenizer(t,e){const o=/^\$([^\$]+)\$/.exec(t);return o?{type:"latex",raw:o[0],formula:o[1]}:void 0},renderer(t){return n.lazy?`<span class="${q6}">${t.formula}</span>`:n.render(t.formula,!1)}});var xA=(n={})=>(n.lazy&&n.env!=="test"&&new IntersectionObserver((t,e)=>{for(const o of t){if(!o.isIntersecting)continue;const r=o.target;e.unobserve(r),Promise.resolve(n.render(r.innerText,r.hasAttribute("block"))).then(i=>{r.innerHTML=i}),r.classList.add("latex-rendered")}},{threshold:1}),{extensions:[EA(n),IA(n)]});function di(n){const t=n.type;if(t==="link")return!!n.tokens.some(di);switch(t){case"code":case"table":case"hr":case"blockquote":case"list":case"list_item":case"image":case"paragraph":return!0;default:return!1}}function TA(n){return!di(n)}function SA(n){if(n.length===0)return[];if(n.length===1)return[n];const t=[];let e=[n[0]],o=di(n[0]);for(let r=1;r<n.length;r++){const i=n[r];o===di(i)?e.push(i):(t.push(e),e=[i],o=di(i))}return t.push(e),t}function DA(n,t,e){const o=n.href;let r=e.tokensToText(n.tokens,t,e);return r.length===0&&(r=Qo(o,t)),r=Fl(r,"link",o),r}let Zs;function Y1(n){Zs||(Zs=document.createElement("textarea")),Zs.innerHTML=n;const t=Zs.childNodes.length===0?"":Zs.childNodes[0].nodeValue;return t!=null?t:""}function LA(n,t){const e=Y1(n.text);return[$e(e,{...t,"style-code":!0})]}function MA(n,t,e){const r=n.tokens;return r?e.tokensToText(r,t,e):Ud(Y1(n.text),t)}const RA=B("token-to-text");function Q1(n,t,e){return n.map(r=>r.type==="text"?MA(r,t,e):r.type==="strong"?e.tokensToText(r.tokens,{...t,"style-bold":!0},e):r.type==="em"?e.tokensToText(r.tokens,{...t,"style-italic":!0},e):r.type==="link"?DA(r,t,e):r.type==="codespan"?LA(r,t):r.type==="br"?[{insert:" ",attributes:{id:N(),created:Date.now(),box:!0,type:"br"}}]:r.type==="escape"?Ud(Y1(r.text),t):r.type==="latex"?[{insert:" ",attributes:{id:N(),created:Date.now(),box:!0,type:"math",tex:r.formula}}]:(RA.warn(`unknown token in text: ${JSON.stringify(r)}`),[])).flat()}function AA(n,t){const e=Q1(n.tokens,{},t);return[{id:N(),type:"text",text:e,heading:n.depth}]}function OA(n,t){const{text:e,children:o}=t.tokensToTextWithChildren(n.tokens,t),r=[];return e.length>0&&r.push({id:N(),type:"text",text:e}),r.push(...o),r}function _A(n,t){const{text:e,children:o}=t.tokensToTextWithChildren([n],t),r=[];return e.length>0&&r.push({id:N(),type:"text",text:e}),r.push(...o),r}function NA(n,t){const e=typeof n.start=="number"?n.start:1,o=n.ordered,r=N(),i=[];return n.items.forEach((l,c)=>{const a={...t,listLevel:t.listLevel+1},{text:u,children:f}=t.tokensToTextWithChildren(l.tokens,a);let m;typeof l.checked=="boolean"&&(m=l.checked?"checked":"unchecked");const C={id:N(),type:"list",groupId:r,ordered:o,checkbox:m,start:e+c,text:u,level:t.listLevel};i.push(C),i.push(...f)}),i}function $A(n,t){const e=t.tokensToBlocks(n.tokens,t);return e.forEach(o=>{o.quoted=!0}),e}const W6=100,PA=20,jA=600;function HA(n,t){const e=t.text;if(e){const o=bt(e);return Math.min(El(o,n)+PA,jA)}return W6}function G6(n,t){let e=W6;return t.forEach(o=>{e=Math.max(e,HA(n,o))}),e}function FA(n,t){var l,c;const e=n.header.length,o=n.rows.length+1,r=[],i=Array(e).fill(100);for(let a=0;a<o;a++){let u;a===0?u=n.header:u=n.rows[a-1];for(let f=0;f<e;f++){const m=u[f],C=(l=m==null?void 0:m.tokens)!=null?l:[],k=N();r.push(k);let w;if(C.length===0)w=[Vl()];else if(di(C[0]))w=t.tokensToBlocks(m.tokens,t),w.length===0&&w.push(Vl());else{const{text:y,children:S}=t.tokensToTextWithChildren(m.tokens,t);w=[{id:N(),type:"text",text:y},...S]}t.doc.blocks[k]=w,i[f]=Math.max(i[f],G6((c=t.font)!=null?c:"",w))}}return[{id:N(),type:"table",cols:e,rows:o,colsWidth:i,children:r}]}function zA(n){return[{id:N(),type:"embed",embedType:"hr",embedData:{}}]}function UA(n,t){var c;const e=n.text;if(!e)return[];try{const a=n.text,u=yl(a),f=JSON.parse(u);if(f){const{root:m,...C}=f.blocks;return t.doc.blocks={...t.doc.blocks,...C},m}}catch{}const o=(c=n.lang)!=null?c:"Plain Text";if(o==="mermaid")return[{id:N(),type:"embed",embedType:"mermaid",embedData:{mermaidText:e}}];if(o==="plantuml")return[{id:N(),type:"embed",embedType:"plantuml",embedData:{plantumlText:e}}];if(o==="flow"||o==="flowchart")return[{id:N(),type:"embed",embedType:"flowchart",embedData:{flowchartText:e}}];const i=e.split(`
529
+ \`\`\`\`\`\``}return"[plantuml]"}const W1={embedType:"plantuml",convertFrom:dA,handleUpdateBlock:aA,createEmbedContent:cA,getBlockProperties:uA,convertTo:hA},qz="",fA="hr",mA={dividingLine:{type:"\u5206\u5272\u7EBF"}},gA={dividingLine:{type:"dividing-line"}};T.mergeLang({"zh-CN":mA,"en-US":gA});function pA(n,t){const e=b("div",["editor-embed-container"],t);b("hr",["editor-embed-hr"],e)}function CA(n,t,e,o){return o==="html"?"<hr />":o==="markdown"?"---":"------------"}function bA(){return{name:"hr",insertEmbedCommandItems:[{id:"insert-hr",name:T.t("dividingLine.type"),icon:mB,order:500,group:"common",subText:me("insert-hr")}],handleInsertEmptyEmbed:async(n,t)=>{const{containerId:e,blockIndex:o}=t;return n.insertEmbed(e,o,fA,{})}}}function kA(n,t,e){const{data:o}=e;if(!o||o.embedType!=="dividing-line"||!P(n,t))return null;const r={};return{blockData:{id:N(),type:"embed",embedType:"hr",embedData:r}}}const G1={embedType:"hr",createEmbedContent:pA,convertTo:CA,getOptions:bA,convertFrom:kA},Wz="";class vA{constructor(t,e){h(this,"toolbar");h(this,"anchor",null);h(this,"item");h(this,"docs",null);h(this,"checkedId");h(this,"handlePasteSpecial",(t,e)=>{!e.data||(this.checkedId===e.id?this.checkedId=void 0:this.checkedId=e.id,this.onPasteSpecial(e.data),setTimeout(()=>{this.docs&&this.show(this.docs),this.editor.focus()}))});h(this,"handleClose",()=>{this.editor.focus()});h(this,"handleSelectionChange",()=>{this.hide()});this.editor=t,this.onPasteSpecial=e,this.item={id:"paste-special",name:"Paste special",icon:Kw,dropdown:!0,manualShowChildren:!0,childrenPlacement:"bottom-start",childrenOffset:[-4,4],children:[]},this.toolbar=new ks([this.item],void 0,{id:"paste-special-button",tooltipId:this.editor.clientId,refuseOverflow:!0}),this.toolbar.addListener("click",this.handlePasteSpecial),this.toolbar.addListener("close",this.handleClose),this.editor.addListener("selectionChanged",this.handleSelectionChange)}show(t){this.docs=t;const e=this.editor,o=e.selection.range;if(!o.isCollapsed())return;const r=e.getBlockById(o.start.blockId);if(!P(e,r))return;const i=so(e,r,o)[0];if(!i)return;this.anchor&&this.anchor.remove(),this.anchor=ao(e,r,"paste-special-button-anchor",i);const s=this.getCommandItems(t);this.item.children=s,this.toolbar.manualShow(this.anchor)}hide(){this.toolbar.close()}clearCheckedState(){this.checkedId=void 0}destroy(){this.toolbar.destroy(),this.editor.removeListener("selectionChanged",this.handleSelectionChange)}getCommandItems(t){const e=i=>({id:i,states:this.checkedId===i?["checked"]:void 0,name:"Keep origin formats",data:t[i]}),o=[];let r=!0;return t["text/x-ones-editor-doc"]?o.push(e("text/x-ones-editor-doc")):t["text/office-html"]?o.push(e("text/office-html")):t["text/html"]?o.push(e("text/html")):t["text/plain"]&&(o.push(e("text/plain")),r=!1),t["text/plain"]&&(r&&o.push({id:"text/plain",states:this.checkedId==="text/plain"?["checked"]:void 0,name:"Paste as plain text",data:t["text/plain"]}),o.push({id:"text/markdown",states:this.checkedId==="text/markdown"?["checked"]:void 0,name:"Paste as markdown",data:t["text/markdown"]})),o}}const yA=B("paste-special");class Z1{constructor(t){h(this,"button");h(this,"lastUndoAction",null);h(this,"event",null);h(this,"handlePasteSpecial",t=>{this.editor.undoManager.runInGroup(()=>{this.editor.undoManager.undoTo(this.lastUndoAction),this.editor.pasteDoc(t)})});this.editor=t,this.button=new vA(t,this.handlePasteSpecial)}destroy(){this.event=null,this.button.destroy()}handleChanged(t,e){this.event=null,this.button.hide()}async handleBeforePaste(t,e){return yA.debug("before paste"),this.lastUndoAction=t.undoManager.lastAction(),!1}async handleAfterPaste(t,e,o){if(Object.keys(o).length<=1)return!1;const r=t.selection.range;if(r.isCollapsed()){const i=t.getBlockById(r.start.blockId);if(!P(t,i))return!1;this.button.clearCheckedState(),this.button.show(o),this.event=e}return!1}}const Gz="",wA=B("html-to-doc");function BA(n){const t="ones-editor-doc::",e="::ones-editor-doc";let o=n.indexOf(t);if(o!==-1){o+=t.length;const r=n.indexOf(e,o);if(r!==-1){const i=n.substr(o,r-o);try{const s=yl(i);return JSON.parse(s)}catch(s){wA.error(`invalid doc data: ${s}, ${i}`)}}}return null}const q6="latex-b172fea480b",EA=n=>({name:"latex-block",level:"block",start(t){var e,o;return(o=(e=t.match(/\$\$[^\$]/))==null?void 0:e.index)!=null?o:-1},tokenizer(t,e){const o=/^\$\$([^\$]+)\$\$/.exec(t);return o?{type:"latex-block",raw:o[0],formula:o[1]}:void 0},renderer(t){return n.lazy?`<span class="${q6}" block>${t.formula}</span>`:n.render(t.formula,!0)}}),IA=n=>({name:"latex",level:"inline",start(t){var e,o;return(o=(e=t.match(/\$[^\$]/))==null?void 0:e.index)!=null?o:-1},tokenizer(t,e){const o=/^\$([^\$]+)\$/.exec(t);return o?{type:"latex",raw:o[0],formula:o[1]}:void 0},renderer(t){return n.lazy?`<span class="${q6}">${t.formula}</span>`:n.render(t.formula,!1)}});var xA=(n={})=>(n.lazy&&n.env!=="test"&&new IntersectionObserver((t,e)=>{for(const o of t){if(!o.isIntersecting)continue;const r=o.target;e.unobserve(r),Promise.resolve(n.render(r.innerText,r.hasAttribute("block"))).then(i=>{r.innerHTML=i}),r.classList.add("latex-rendered")}},{threshold:1}),{extensions:[EA(n),IA(n)]});function di(n){const t=n.type;if(t==="link")return!!n.tokens.some(di);switch(t){case"code":case"table":case"hr":case"blockquote":case"list":case"list_item":case"image":case"paragraph":return!0;default:return!1}}function TA(n){return!di(n)}function SA(n){if(n.length===0)return[];if(n.length===1)return[n];const t=[];let e=[n[0]],o=di(n[0]);for(let r=1;r<n.length;r++){const i=n[r];o===di(i)?e.push(i):(t.push(e),e=[i],o=di(i))}return t.push(e),t}function DA(n,t,e){const o=n.href;let r=e.tokensToText(n.tokens,t,e);return r.length===0&&(r=Qo(o,t)),r=Fl(r,"link",o),r}let Zs;function Y1(n){Zs||(Zs=document.createElement("textarea")),Zs.innerHTML=n;const t=Zs.childNodes.length===0?"":Zs.childNodes[0].nodeValue;return t!=null?t:""}function LA(n,t){const e=Y1(n.text);return[$e(e,{...t,"style-code":!0})]}function MA(n,t,e){const r=n.tokens;return r?e.tokensToText(r,t,e):Ud(Y1(n.text),t)}const RA=B("token-to-text");function Q1(n,t,e){return n.map(r=>r.type==="text"?MA(r,t,e):r.type==="strong"?e.tokensToText(r.tokens,{...t,"style-bold":!0},e):r.type==="em"?e.tokensToText(r.tokens,{...t,"style-italic":!0},e):r.type==="link"?DA(r,t,e):r.type==="codespan"?LA(r,t):r.type==="br"?[{insert:" ",attributes:{id:N(),created:Date.now(),box:!0,type:"br"}}]:r.type==="escape"?Ud(Y1(r.text),t):r.type==="latex"?[{insert:" ",attributes:{id:N(),created:Date.now(),box:!0,type:"math",tex:r.formula}}]:(RA.warn(`unknown token in text: ${JSON.stringify(r)}`),[])).flat()}function AA(n,t){const e=Q1(n.tokens,{},t);return[{id:N(),type:"text",text:e,heading:n.depth}]}function OA(n,t){const{text:e,children:o}=t.tokensToTextWithChildren(n.tokens,t),r=[];return e.length>0&&r.push({id:N(),type:"text",text:e}),r.push(...o),r}function _A(n,t){const{text:e,children:o}=t.tokensToTextWithChildren([n],t),r=[];return e.length>0&&r.push({id:N(),type:"text",text:e}),r.push(...o),r}function NA(n,t){const e=typeof n.start=="number"?n.start:1,o=n.ordered,r=N(),i=[];return n.items.forEach((l,c)=>{const a={...t,listLevel:t.listLevel+1},{text:u,children:f}=t.tokensToTextWithChildren(l.tokens,a);let m;typeof l.checked=="boolean"&&(m=l.checked?"checked":"unchecked");const C={id:N(),type:"list",groupId:r,ordered:o,checkbox:m,start:e+c,text:u,level:t.listLevel};i.push(C),i.push(...f)}),i}function $A(n,t){const e=t.tokensToBlocks(n.tokens,t);return e.forEach(o=>{o.quoted=!0}),e}const W6=100,PA=20,jA=600;function HA(n,t){const e=t.text;if(e){const o=bt(e);return Math.min(El(o,n)+PA,jA)}return W6}function G6(n,t){let e=W6;return t.forEach(o=>{e=Math.max(e,HA(n,o))}),e}function FA(n,t){var l,c;const e=n.header.length,o=n.rows.length+1,r=[],i=Array(e).fill(100);for(let a=0;a<o;a++){let u;a===0?u=n.header:u=n.rows[a-1];for(let f=0;f<e;f++){const m=u[f],C=(l=m==null?void 0:m.tokens)!=null?l:[],k=N();r.push(k);let w;if(C.length===0)w=[Vl()];else if(di(C[0]))w=t.tokensToBlocks(m.tokens,t),w.length===0&&w.push(Vl());else{const{text:y,children:S}=t.tokensToTextWithChildren(m.tokens,t);w=[{id:N(),type:"text",text:y},...S]}t.doc.blocks[k]=w,i[f]=Math.max(i[f],G6((c=t.font)!=null?c:"",w))}}return[{id:N(),type:"table",cols:e,rows:o,colsWidth:i,children:r}]}function zA(n){return[{id:N(),type:"embed",embedType:"hr",embedData:{}}]}function UA(n,t){var c;const e=n.text;if(!e)return[];try{const a=n.text,u=yl(a),f=JSON.parse(u);if(f){const{root:m,...C}=f.blocks;return t.doc.blocks={...t.doc.blocks,...C},m}}catch{}const o=(c=n.lang)!=null?c:"Plain Text";if(o==="mermaid")return[{id:N(),type:"embed",embedType:"mermaid",embedData:{mermaidText:e}}];if(o==="plantuml")return[{id:N(),type:"embed",embedType:"plantuml",embedData:{plantumlText:e}}];if(o==="flow"||o==="flowchart")return[{id:N(),type:"embed",embedType:"flowchart",embedData:{flowchartText:e}}];const i=e.split(`
530
530
  `).map(a=>({id:N(),type:"text",text:Qo(a)})),s=t.doc,l=N();return s.blocks[l]=i,[{id:N(),type:"code",language:o,children:[l]}]}function VA(n){return[{id:N(),type:"embed",embedType:"image",embedData:{src:n.href,title:n.title}}]}function qA(n,t){const{text:e,children:o}=t.tokensToTextWithChildren(n.tokens,t),r=[];return e.length>0&&r.push({id:N(),type:"text",text:e}),r.push(...o),r}function WA(n){const t=n.formula;return t?[{id:N(),type:"embed",embedType:"math",embedData:{mathjaxText:t}}]:[]}const GA=B("markdown-to-doc");function ZA(n,t){if(n.type==="heading")return AA(n,t);if(n.type==="paragraph")return OA(n,t);if(n.type==="list")return NA(n,t);if(n.type==="blockquote")return $A(n,t);if(n.type==="table")return FA(n,t);if(n.type==="hr")return zA();if(n.type==="code")return UA(n,t);if(n.type==="image")return VA(n);if(n.type==="link")return qA(n,t);if(n.type==="latex-block")return WA(n);if(n.type==="text")return _A(n,t);if(n.type==="space"){const e=n.raw.replaceAll(" ",""),o=Math.floor(e.split(`
531
531
  `).length/2)-1;return o>0?new Array(o).fill("").map(()=>({type:"text",id:N(),text:[]})):[]}return GA.log(`unknown block token: ${JSON.stringify(n)}`),[]}function K1(n,t){const e=[];return n.forEach(o=>{const r=ZA(o,t);e.push(...r)}),e}B("markdown-to-doc");function YA(n,t){const e={text:[],children:[]};return SA(n).forEach((r,i)=>{const s=r[0];if(i===0&&TA(s)){e.text=Q1(r,{},t);return}e.children.push(...K1(r,t))}),e}const QA={render:(n,t)=>""};Yf.marked.use(xA(QA));function Z6(n,t){const o=new Yf.marked.Lexer().lex(n),r={blocks:{root:[]},meta:{},comments:{}},i={font:t==null?void 0:t.font,doc:r,tokensToText:Q1,tokensToBlocks:K1,tokensToTextWithChildren:YA,htmlToDoc:t==null?void 0:t.htmlToDoc,listLevel:1},s=K1(o,i);return s.length===0?null:(r.blocks.root.push(...s),r)}function KA(n){if(n.nodeName!=="DIV")return!1;const t=n;return Array.from(t.childNodes).every(e=>e.nodeName==="SPAN"||e instanceof Text)?!!t.querySelector(":scope > .hljs-function, :scope > .hljs-params, :scope > .hljs-string, :scope > .hljs-keyword, :scope > .hljs-attr"):!1}function Y6(n){if(KA(n)){const t=n,e=t.parentNode,o=document.createElement("pre");Array.from(t.childNodes).forEach(r=>o.appendChild(r)),e==null||e.insertBefore(o,t);return}n.childNodes.forEach(t=>Y6(t))}function ma(n){var t;if(n instanceof HTMLBRElement){const e=document.createTextNode(`
532
532
  `);(t=n.parentNode)==null||t.insertBefore(e,n),n.remove();return}n.childNodes.forEach(ma)}function JA(n){n.addRule("preOnlyBlockToCode",{filter:t=>t.nodeName!=="PRE"?!1:Array.from(t.childNodes).every(e=>e.nodeName==="SPAN"||e instanceof Text||e.nodeName==="BR"),replacement:(t,e,o)=>{var r;return ma(e),`
@@ -572,20 +572,20 @@ ${i.flowchartText}
572
572
 
573
573
  > ${o}
574
574
 
575
- `}})}class iO{constructor(t){h(this,"_grid",[]);h(this,"_needFixSpanData",!1);Array.from(t.rows).forEach((e,o)=>{Array.from(e.cells).forEach(r=>{this._addCell(o,r)})})}_addCell(t,e){const o=this._getNextColIndex(t),r=e.colSpan,i=e.rowSpan;for(let s=0;s<i;s++)for(let l=0;l<r;l++){const c=t+s,a=o+l;if(this._getCell({row:c,col:a})){this._needFixSpanData=!0,console.warn(`invalid table data, cell data already exists, ${c}, ${a}`);continue}this._setCell({row:c,col:a},{cell:e,virtual:!(l===0&&s===0)})}}_getNextColIndex(t){const e=this._grid[t];if(!e)return 0;let o=0;for(let r=0;r<e.length;r++)if(e[r])o+=1;else return o;return o}_setCell(t,e){if(!(e.cell.colSpan===0||e.cell.rowSpan===0)){for(;this._grid.length<=t.row;)this._grid.push([]);for(let o=0;o<this._grid.length;o++){const r=this._grid[o];for(;r.length<=t.col;)r.push(null)}this._grid[t.row][t.col]=e}}_getCell(t){var o;const e=this._grid[t.row];return e&&(o=e[t.col])!=null?o:null}get rowCount(){return this._grid.length}get colCount(){return this._grid[0].length}getCellData(t){const e=this._getCell(t);return e||null}getCellSpan(t){const e=this._getCell(t);if(!e)return{colSpan:1,rowSpan:1};if(e.virtual)return{colSpan:1,rowSpan:1};const o=()=>{let l=t.col+1;for(;;){const c=this._getCell({row:t.row,col:l});if(!c||c.cell!==e.cell)return l-t.col;l+=1}},r=()=>{let l=t.row+1;for(;;){const c=this._getCell({row:l,col:t.col});if(!c||c.cell!==e.cell)return l-t.row;l+=1}},i=o(),s=r();return i!==e.cell.colSpan&&console.warn(`invalid colSpan: ${i} -> ${e.cell.colSpan}`),s!==e.cell.rowSpan&&console.warn(`invalid rowSpan: ${s} -> ${e.cell.rowSpan}`),{colSpan:i,rowSpan:s}}getColumnWidth(t){const r=Array(this.rowCount).fill(0).map((s,l)=>{const c=this.getCellData({row:l,col:t});if(c&&!c.virtual){const a=c.cell.getAttribute("width")||c.cell.style.width;if(a){if(a.endsWith("%")){const f=a.substr(0,a.length-1),m=Number.parseInt(f,10);if(m>0&&m<=100)return Math.floor(720*m/100)}const u=Number.parseInt(a,10);if(u)return u}return c.cell.getBoundingClientRect().width}return 1e9}),i=Math.min(...r);return i===1e9||Number.isNaN(i)||i<30?0:i}}function sO(n){return new iO(n)}function Q6(n,t){var c;const e=sO(n),o=[],r={},i=e.rowCount,s=e.colCount,l=Array(s).fill(100);for(let a=0;a<i;a++)for(let u=0;u<s;u++){let f;const m=e.getCellData({row:a,col:u});if(m&&m.virtual)continue;m&&!m.virtual&&(f=t.htmlToBlocks(m.cell.innerHTML,t)),(!f||f.length===0)&&(f=[{id:N(),type:"text",text:[]}]);const C=N();o.push(C);const{colSpan:k,rowSpan:w}=e.getCellSpan({row:a,col:u});w>1&&(r[`${C}_rowSpan`]=w),k>1&&(r[`${C}_colSpan`]=k),t.doc.blocks[C]=f,m&&!m.virtual&&(l[u]=Math.max(l[u],G6((c=t.font)!=null?c:"",f)))}for(let a=0;a<e.colCount;a++)l[a]=e.getColumnWidth(a)||l[a];return o.length===0?[]:[{cols:e.colCount,rows:e.rowCount,id:N(),type:"table",children:o,...r,colsWidth:l}]}function K6(n,t){var e;if(n.tagName==="TABLE"){const o={blocks:{root:[]},meta:{},comments:{}},r=Q6(n,{doc:o,...t});if(r.length===0||((e=r[0].children)==null?void 0:e.length)===0)return;o.blocks.root=r;const i=JSON.stringify(o),s=Ho(i),l=document.createElement("div");l.classList.add("highlight-text-wizdoc");const c=document.createElement("pre");l.appendChild(c),c.innerText=s,n.insertAdjacentElement("beforebegin",l),n.remove();return}Array.from(n.children).forEach(o=>K6(o,t))}function J6(n){if(n instanceof HTMLStyleElement){n.remove();return}Array.from(n.children).forEach(J6)}function X6(n){if(n instanceof HTMLElement){if(n.style.display==="none"){n.remove();return}if(n.style.visibility==="hidden"){n.remove();return}}Array.from(n.children).forEach(X6)}function lO(n,t){const e=Bl(n);return e.querySelectorAll("td.js-line-number").forEach(r=>r.remove()),e.querySelectorAll("div.copy-button").forEach(r=>r.remove()),e.querySelectorAll("div.code-copy-button").forEach(r=>r.remove()),e.querySelectorAll("noscript").forEach(r=>r.remove()),Array.from(e.children).forEach(X6),Array.from(e.children).forEach(r=>K6(r,t)),Array.from(e.children).forEach(J6),Y6(e),Mm(e)}const Kn=new S7.default;Kn.use(JA),Kn.use(XA),Kn.use(tO),Kn.use(eO),Kn.use(nO),Kn.use(oO),Kn.use(rO),Kn.use(m7.gfm);function cO(n,t){const e=t3(n,t);if(!e)return[];const{root:o,...r}=e.blocks;return t.doc.blocks={...t.doc.blocks,...r},o}function t3(n,t){const e=Kn.turndown(n);return Z6(e,{htmlToDoc:o=>e3(o,t)})}function e3(n,t){const e=lO(n,{font:t==null?void 0:t.font,htmlToBlocks:cO});return t3(e)}function n3(n){return n.indexOf('xmlns:o="urn:schemas-microsoft-com:office:office"')!==-1}function ga(n){return["A","B","DEL","I","U","S","SPAN","SUB","SUP"].indexOf(n.tagName)!==-1}function aO(n){return["P","H1","H2","H3","H4","H5","H6","H7","H8","LI"].indexOf(n.tagName)!==-1}function o3(n){return n.replace(/\r\n/g," ").replace(/\n/g," ").replace(/\r/g," ")}function dO(n){if(!n.tagName)return!1;if(n.tagName.toLocaleLowerCase()==="img")return!0;const t=n.querySelectorAll("img");for(let e=0;e<t.length;e+=1){const o=t[e];if(!o.src||o.getAttribute("width")==="0"||o.getAttribute("height")==="0")return!1}return t.length}function uO(n){return(n.tagName.toLocaleLowerCase()==="img"?[n]:Array.from(n.querySelectorAll("img"))).map(r=>({id:N(),type:"embed",embedType:"image",embedData:{src:r.src,width:r.width,height:r.height}}))}function r3(n){var e;return Array.from(((e=n.getAttribute("style"))!=null?e:"").split(" ")).findIndex(o=>o.startsWith("level"))!==-1}function hO(n){var e;const t=Array.from(((e=n.getAttribute("style"))!=null?e:"").split(" "));for(let o=0;o<t.length;o++){const r=t[o];if(r.startsWith("mso-list:"))return r}return""}function i3(n){var e,o;const t=Array.from(((e=n.getAttribute("style"))!=null?e:"").split(" "));for(let r=0;r<t.length;r++){const i=t[r];if(i.startsWith("level")){const s=(o=Number.parseInt(i.substring(5),10))!=null?o:void 0;if(s)return s}}return 1}function fO(n,t){n.setAttribute("data-group-id",t)}function mO(n){const t={},e=r=>{Array.from(Object.keys(t)).forEach(i=>{Number.parseInt(i,10)>r&&delete t[i]})};let o="";Array.from(n.children).forEach(r=>{if(r3(r)){const i=hO(r);o!==i&&(e(0),o=i);const s=i3(r);e(s);let l=t[`${s}`];l||(l=N(),t[`${s}`]=l),fO(r,l)}})}function s3(n){if(!r3(n))return{};const t=i3(n),e=n.getAttribute("data-group-id")||N();return{start:1,level:t,groupId:e,ordered:!0,type:"list"}}const gO=B("office-list");function l3(n){return n instanceof HTMLOListElement||n instanceof HTMLUListElement}function pO(n,t){d(gO,l3(n),"not list group element");let e=!1,o=1;const r=N();n instanceof HTMLOListElement&&(e=!0,o=n.start);const i=n,s=[];let l;return Array.from(i.children).forEach(c=>{if(c instanceof HTMLLIElement){const u=s3(c),f=t.textElementToBlocks(c,t);l||(l=u.level);const m=f[0];s.push({...m,type:"list",ordered:e,level:l,groupId:r,start:o}),o+=1,s.push(...f.slice(1));return}const a=t.blockElementToBlocks(c,t);s.push(...a)}),s}function c3(n,t){if(n.nodeName==="META")return[];if(n instanceof HTMLTableElement)return Q6(n,t);if(l3(n))return[...pO(n,t)];if(dO(n))return[...uO(n)];if(aO(n))return[...t.textElementToBlocks(n,t)];if(!n.children)return[];const e=[];return Array.from(n.children).forEach(o=>{const r=c3(o,t);e.push(...r)}),e}function a3(n,t){const e=[];return n.forEach(o=>{var r;if(o instanceof Element)if(ga(o)){const i=document.createElement("p");i.appendChild(o);const s=t.blockElementToBlocks(i,t);e.push(...s)}else{const i=t.blockElementToBlocks(o,t);e.push(...i)}else if(o instanceof Text){const i=Un(o3((r=o.textContent)!=null?r:""));e.push(i)}}),e}function CO(n){const t=Array.from(n.children);for(let e=0;e<t.length;e++){const o=t[e];if(!ga(o))continue;let r=e+1;for(;r<t.length&&ga(t[r]);)r+=1;const i=document.createElement("p");o.insertAdjacentElement("beforebegin",i);for(let s=e;s<r;s++)i.appendChild(t[s]);e=r-1}}function bO(n,t){const e=Bl(n);return a3(Array.from(e.childNodes),t)}function kO(n){if(!(n instanceof HTMLElement))return{};const t={};if(n.style.textAlign==="right"?t.align="right":n.style.textAlign==="center"&&(t.align="center"),n.style.marginLeft){const e=Math.ceil(Number.parseInt(n.style.marginLeft,10)/20);e>=1&&e<=12&&(t.padding=e)}return t}function vO(n,t){var o;const e=o3((o=n.nodeValue)!=null?o:" ");return t&&Object.keys(t).length>0?{insert:e,attributes:t}:{insert:e}}function yO(n,t){if(n.nodeName==="B")return{...t,"style-bold":!0};if(n.nodeName==="I")return{...t,"style-italic":!0};if(n.nodeName==="U")return{...t,"style-underline":!0};if(n.nodeName==="S"||n.nodeName==="DEL")return{...t,"style-strikethrough":!0};if(n.nodeName==="SUB")return{...t,"style-sub":!0};if(n.nodeName==="SUP")return{...t,"style-super":!0};if(n.nodeName==="A"&&n.href){const o=n.href;if(o.startsWith("http:")||o.startsWith("https:"))return{...t,link:n.href}}const e={...t};return n instanceof HTMLSpanElement?(n.style.backgroundColor&&(e["inline-style-background-color"]=n.style.backgroundColor),n.style.color&&(e["inline-style-color"]=n.style.color),n.style.fontSize&&(e["inline-style-font-size"]=n.style.fontSize),n.style.fontFamily&&(e["inline-style-font-family"]=n.style.fontFamily),e):t}function d3(n,t,e){if(n instanceof HTMLSpanElement&&n.getAttribute("style")==="mso-list:Ignore")return;const o=yO(n,t);if(n instanceof Text&&n.nodeValue){e.push(vO(n,o));return}n.childNodes.length>0&&Array.from(n.childNodes).forEach(r=>{d3(r,o,e)})}function u3(n){return n instanceof Element?ga(n):!0}function J1(n){return!u3(n)}function wO(n){if(n.length===0)return[];if(n.length===1)return[n];const t=[];let e=[n[0]],o=J1(n[0]);for(let r=1;r<n.length;r++){const i=n[r];o===J1(i)?e.push(i):(t.push(e),e=[i],o=J1(i))}return t.push(e),t}function BO(n,t){const e={};if(n.tagName.startsWith("H")){const i=Number.parseInt(n.tagName.substr(1),10);i>=1&&i<=8&&(e.heading=i)}const o=wO(Array.from(n.childNodes)),r=[];return o.forEach((i,s)=>{if(u3(i[0])){const l=[],c={};Array.from(n.childNodes).forEach(u=>{d3(u,c,l)});let a={};s===0&&(a=s3(n)),r.push({id:N(),type:"text",text:l,...a,...e,...kO(n)})}i.forEach(l=>{const c=t.blockElementToBlocks(l,t);r.push(...c)})}),r}function EO(n,t){const e=Bl(n);mO(e),CO(e);const o={blocks:{root:[]},meta:{},comments:{}},r={font:t==null?void 0:t.font,doc:o,blockElementToBlocks:c3,textElementToBlocks:BO,htmlToBlocks:bO},i=a3(Array.from(e.children),r);if(i.length!==0)return o.blocks.root=i,o}const IO=B("html-to-doc");function h3(n,t){if(!n)return null;const e=BA(n);if(e)return e;if(n3(n)){const o=EO(n,t);if(o)return o}try{return e3(n,t)}catch(o){IO.error(o)}return null}class xO{async fromData(t,e){const o={},r=e.getData("text/html");if(r){const i=h3(r,{font:t.rootContainer});i&&(n3(r)?o["text/office-html"]=i:o["text/html"]=i)}return o}}class TO{async fromData(t,e){const o=e.getData("text/plain");if(!o)return;const r=Z6(o,{font:t.rootContainer,htmlToDoc:h3});if(!!r)return{"text/markdown":r}}}function SO(n){return/^([\d\w\u4e00-\u9fa5\s]*[\u4e00-\u9fa5\s]{1}|)((https|http|ftp)?:\/\/)[^\s]+/.test(n)}function DO(n){const t=[],e=n.split(/https|http|ftp/)[0],o=n.substring(e.length).trim();if(e&&e.length){const i=$e(e,null);t.push(i,$e(" ",null))}const r=$e(o,{link:o});return t.push(r,$e(" ",null)),t}class LO{async fromData(t,e){const o={},r=e.getData("text/plain");if(r){const l={blocks:{root:r.replace(/\r\n/g,`
575
+ `}})}class iO{constructor(t){h(this,"_grid",[]);h(this,"_needFixSpanData",!1);Array.from(t.rows).forEach((e,o)=>{Array.from(e.cells).forEach(r=>{this._addCell(o,r)})})}_addCell(t,e){const o=this._getNextColIndex(t),r=e.colSpan,i=e.rowSpan;for(let s=0;s<i;s++)for(let l=0;l<r;l++){const c=t+s,a=o+l;if(this._getCell({row:c,col:a})){this._needFixSpanData=!0,console.warn(`invalid table data, cell data already exists, ${c}, ${a}`);continue}this._setCell({row:c,col:a},{cell:e,virtual:!(l===0&&s===0)})}}_getNextColIndex(t){const e=this._grid[t];if(!e)return 0;let o=0;for(let r=0;r<e.length;r++)if(e[r])o+=1;else return o;return o}_setCell(t,e){if(!(e.cell.colSpan===0||e.cell.rowSpan===0)){for(;this._grid.length<=t.row;)this._grid.push([]);for(let o=0;o<this._grid.length;o++){const r=this._grid[o];for(;r.length<=t.col;)r.push(null)}this._grid[t.row][t.col]=e}}_getCell(t){var o;const e=this._grid[t.row];return e&&(o=e[t.col])!=null?o:null}get rowCount(){return this._grid.length}get colCount(){return this._grid[0].length}getCellData(t){const e=this._getCell(t);return e||null}getCellSpan(t){const e=this._getCell(t);if(!e)return{colSpan:1,rowSpan:1};if(e.virtual)return{colSpan:1,rowSpan:1};const o=()=>{let l=t.col+1;for(;;){const c=this._getCell({row:t.row,col:l});if(!c||c.cell!==e.cell)return l-t.col;l+=1}},r=()=>{let l=t.row+1;for(;;){const c=this._getCell({row:l,col:t.col});if(!c||c.cell!==e.cell)return l-t.row;l+=1}},i=o(),s=r();return i!==e.cell.colSpan&&console.warn(`invalid colSpan: ${i} -> ${e.cell.colSpan}`),s!==e.cell.rowSpan&&console.warn(`invalid rowSpan: ${s} -> ${e.cell.rowSpan}`),{colSpan:i,rowSpan:s}}getColumnWidth(t){const r=Array(this.rowCount).fill(0).map((s,l)=>{const c=this.getCellData({row:l,col:t});if(c&&!c.virtual){const a=c.cell.getAttribute("width")||c.cell.style.width;if(a){if(a.endsWith("%")){const f=a.substr(0,a.length-1),m=Number.parseInt(f,10);if(m>0&&m<=100)return Math.floor(720*m/100)}const u=Number.parseInt(a,10);if(u)return u}return c.cell.getBoundingClientRect().width}return 1e9}),i=Math.min(...r);return i===1e9||Number.isNaN(i)||i<30?0:i}}function sO(n){return new iO(n)}function Q6(n,t){var c;const e=sO(n),o=[],r={},i=e.rowCount,s=e.colCount,l=Array(s).fill(100);for(let a=0;a<i;a++)for(let u=0;u<s;u++){let f;const m=e.getCellData({row:a,col:u});if(m&&m.virtual)continue;m&&!m.virtual&&(f=t.htmlToBlocks(m.cell.innerHTML,t)),(!f||f.length===0)&&(f=[{id:N(),type:"text",text:[]}]);const C=N();o.push(C);const{colSpan:k,rowSpan:w}=e.getCellSpan({row:a,col:u});w>1&&(r[`${C}_rowSpan`]=w),k>1&&(r[`${C}_colSpan`]=k),t.doc.blocks[C]=f,m&&!m.virtual&&(l[u]=Math.max(l[u],G6((c=t.font)!=null?c:"",f)))}for(let a=0;a<e.colCount;a++)l[a]=e.getColumnWidth(a)||l[a];return o.length===0?[]:[{cols:e.colCount,rows:e.rowCount,id:N(),type:"table",children:o,...r,colsWidth:l}]}function K6(n,t){var e;if(n.tagName==="TABLE"){const o={blocks:{root:[]},meta:{},comments:{}},r=Q6(n,{doc:o,...t});if(r.length===0||((e=r[0].children)==null?void 0:e.length)===0)return;o.blocks.root=r;const i=JSON.stringify(o),s=Fo(i),l=document.createElement("div");l.classList.add("highlight-text-wizdoc");const c=document.createElement("pre");l.appendChild(c),c.innerText=s,n.insertAdjacentElement("beforebegin",l),n.remove();return}Array.from(n.children).forEach(o=>K6(o,t))}function J6(n){if(n instanceof HTMLStyleElement){n.remove();return}Array.from(n.children).forEach(J6)}function X6(n){if(n instanceof HTMLElement){if(n.style.display==="none"){n.remove();return}if(n.style.visibility==="hidden"){n.remove();return}}Array.from(n.children).forEach(X6)}function lO(n,t){const e=Bl(n);return e.querySelectorAll("td.js-line-number").forEach(r=>r.remove()),e.querySelectorAll("div.copy-button").forEach(r=>r.remove()),e.querySelectorAll("div.code-copy-button").forEach(r=>r.remove()),e.querySelectorAll("noscript").forEach(r=>r.remove()),Array.from(e.children).forEach(X6),Array.from(e.children).forEach(r=>K6(r,t)),Array.from(e.children).forEach(J6),Y6(e),Mm(e)}const Kn=new S7.default;Kn.use(JA),Kn.use(XA),Kn.use(tO),Kn.use(eO),Kn.use(nO),Kn.use(oO),Kn.use(rO),Kn.use(m7.gfm);function cO(n,t){const e=t3(n,t);if(!e)return[];const{root:o,...r}=e.blocks;return t.doc.blocks={...t.doc.blocks,...r},o}function t3(n,t){const e=Kn.turndown(n);return Z6(e,{htmlToDoc:o=>e3(o,t)})}function e3(n,t){const e=lO(n,{font:t==null?void 0:t.font,htmlToBlocks:cO});return t3(e)}function n3(n){return n.indexOf('xmlns:o="urn:schemas-microsoft-com:office:office"')!==-1}function ga(n){return["A","B","DEL","I","U","S","SPAN","SUB","SUP"].indexOf(n.tagName)!==-1}function aO(n){return["P","H1","H2","H3","H4","H5","H6","H7","H8","LI"].indexOf(n.tagName)!==-1}function o3(n){return n.replace(/\r\n/g," ").replace(/\n/g," ").replace(/\r/g," ")}function dO(n){if(!n.tagName)return!1;if(n.tagName.toLocaleLowerCase()==="img")return!0;const t=n.querySelectorAll("img");for(let e=0;e<t.length;e+=1){const o=t[e];if(!o.src||o.getAttribute("width")==="0"||o.getAttribute("height")==="0")return!1}return t.length}function uO(n){return(n.tagName.toLocaleLowerCase()==="img"?[n]:Array.from(n.querySelectorAll("img"))).map(r=>({id:N(),type:"embed",embedType:"image",embedData:{src:r.src,width:r.width,height:r.height}}))}function r3(n){var e;return Array.from(((e=n.getAttribute("style"))!=null?e:"").split(" ")).findIndex(o=>o.startsWith("level"))!==-1}function hO(n){var e;const t=Array.from(((e=n.getAttribute("style"))!=null?e:"").split(" "));for(let o=0;o<t.length;o++){const r=t[o];if(r.startsWith("mso-list:"))return r}return""}function i3(n){var e,o;const t=Array.from(((e=n.getAttribute("style"))!=null?e:"").split(" "));for(let r=0;r<t.length;r++){const i=t[r];if(i.startsWith("level")){const s=(o=Number.parseInt(i.substring(5),10))!=null?o:void 0;if(s)return s}}return 1}function fO(n,t){n.setAttribute("data-group-id",t)}function mO(n){const t={},e=r=>{Array.from(Object.keys(t)).forEach(i=>{Number.parseInt(i,10)>r&&delete t[i]})};let o="";Array.from(n.children).forEach(r=>{if(r3(r)){const i=hO(r);o!==i&&(e(0),o=i);const s=i3(r);e(s);let l=t[`${s}`];l||(l=N(),t[`${s}`]=l),fO(r,l)}})}function s3(n){if(!r3(n))return{};const t=i3(n),e=n.getAttribute("data-group-id")||N();return{start:1,level:t,groupId:e,ordered:!0,type:"list"}}const gO=B("office-list");function l3(n){return n instanceof HTMLOListElement||n instanceof HTMLUListElement}function pO(n,t){d(gO,l3(n),"not list group element");let e=!1,o=1;const r=N();n instanceof HTMLOListElement&&(e=!0,o=n.start);const i=n,s=[];let l;return Array.from(i.children).forEach(c=>{if(c instanceof HTMLLIElement){const u=s3(c),f=t.textElementToBlocks(c,t);l||(l=u.level);const m=f[0];s.push({...m,type:"list",ordered:e,level:l,groupId:r,start:o}),o+=1,s.push(...f.slice(1));return}const a=t.blockElementToBlocks(c,t);s.push(...a)}),s}function c3(n,t){if(n.nodeName==="META")return[];if(n instanceof HTMLTableElement)return Q6(n,t);if(l3(n))return[...pO(n,t)];if(dO(n))return[...uO(n)];if(aO(n))return[...t.textElementToBlocks(n,t)];if(!n.children)return[];const e=[];return Array.from(n.children).forEach(o=>{const r=c3(o,t);e.push(...r)}),e}function a3(n,t){const e=[];return n.forEach(o=>{var r;if(o instanceof Element)if(ga(o)){const i=document.createElement("p");i.appendChild(o);const s=t.blockElementToBlocks(i,t);e.push(...s)}else{const i=t.blockElementToBlocks(o,t);e.push(...i)}else if(o instanceof Text){const i=Un(o3((r=o.textContent)!=null?r:""));e.push(i)}}),e}function CO(n){const t=Array.from(n.children);for(let e=0;e<t.length;e++){const o=t[e];if(!ga(o))continue;let r=e+1;for(;r<t.length&&ga(t[r]);)r+=1;const i=document.createElement("p");o.insertAdjacentElement("beforebegin",i);for(let s=e;s<r;s++)i.appendChild(t[s]);e=r-1}}function bO(n,t){const e=Bl(n);return a3(Array.from(e.childNodes),t)}function kO(n){if(!(n instanceof HTMLElement))return{};const t={};if(n.style.textAlign==="right"?t.align="right":n.style.textAlign==="center"&&(t.align="center"),n.style.marginLeft){const e=Math.ceil(Number.parseInt(n.style.marginLeft,10)/20);e>=1&&e<=12&&(t.padding=e)}return t}function vO(n,t){var o;const e=o3((o=n.nodeValue)!=null?o:" ");return t&&Object.keys(t).length>0?{insert:e,attributes:t}:{insert:e}}function yO(n,t){if(n.nodeName==="B")return{...t,"style-bold":!0};if(n.nodeName==="I")return{...t,"style-italic":!0};if(n.nodeName==="U")return{...t,"style-underline":!0};if(n.nodeName==="S"||n.nodeName==="DEL")return{...t,"style-strikethrough":!0};if(n.nodeName==="SUB")return{...t,"style-sub":!0};if(n.nodeName==="SUP")return{...t,"style-super":!0};if(n.nodeName==="A"&&n.href){const o=n.href;if(o.startsWith("http:")||o.startsWith("https:"))return{...t,link:n.href}}const e={...t};return n instanceof HTMLSpanElement?(n.style.backgroundColor&&(e["inline-style-background-color"]=n.style.backgroundColor),n.style.color&&(e["inline-style-color"]=n.style.color),n.style.fontSize&&(e["inline-style-font-size"]=n.style.fontSize),n.style.fontFamily&&(e["inline-style-font-family"]=n.style.fontFamily),e):t}function d3(n,t,e){if(n instanceof HTMLSpanElement&&n.getAttribute("style")==="mso-list:Ignore")return;const o=yO(n,t);if(n instanceof Text&&n.nodeValue){e.push(vO(n,o));return}n.childNodes.length>0&&Array.from(n.childNodes).forEach(r=>{d3(r,o,e)})}function u3(n){return n instanceof Element?ga(n):!0}function J1(n){return!u3(n)}function wO(n){if(n.length===0)return[];if(n.length===1)return[n];const t=[];let e=[n[0]],o=J1(n[0]);for(let r=1;r<n.length;r++){const i=n[r];o===J1(i)?e.push(i):(t.push(e),e=[i],o=J1(i))}return t.push(e),t}function BO(n,t){const e={};if(n.tagName.startsWith("H")){const i=Number.parseInt(n.tagName.substr(1),10);i>=1&&i<=8&&(e.heading=i)}const o=wO(Array.from(n.childNodes)),r=[];return o.forEach((i,s)=>{if(u3(i[0])){const l=[],c={};Array.from(n.childNodes).forEach(u=>{d3(u,c,l)});let a={};s===0&&(a=s3(n)),r.push({id:N(),type:"text",text:l,...a,...e,...kO(n)})}i.forEach(l=>{const c=t.blockElementToBlocks(l,t);r.push(...c)})}),r}function EO(n,t){const e=Bl(n);mO(e),CO(e);const o={blocks:{root:[]},meta:{},comments:{}},r={font:t==null?void 0:t.font,doc:o,blockElementToBlocks:c3,textElementToBlocks:BO,htmlToBlocks:bO},i=a3(Array.from(e.children),r);if(i.length!==0)return o.blocks.root=i,o}const IO=B("html-to-doc");function h3(n,t){if(!n)return null;const e=BA(n);if(e)return e;if(n3(n)){const o=EO(n,t);if(o)return o}try{return e3(n,t)}catch(o){IO.error(o)}return null}class xO{async fromData(t,e){const o={},r=e.getData("text/html");if(r){const i=h3(r,{font:t.rootContainer});i&&(n3(r)?o["text/office-html"]=i:o["text/html"]=i)}return o}}class TO{async fromData(t,e){const o=e.getData("text/plain");if(!o)return;const r=Z6(o,{font:t.rootContainer,htmlToDoc:h3});if(!!r)return{"text/markdown":r}}}function SO(n){return/^([\d\w\u4e00-\u9fa5\s]*[\u4e00-\u9fa5\s]{1}|)((https|http|ftp)?:\/\/)[^\s]+/.test(n)}function DO(n){const t=[],e=n.split(/https|http|ftp/)[0],o=n.substring(e.length).trim();if(e&&e.length){const i=$e(e,null);t.push(i,$e(" ",null))}const r=$e(o,{link:o});return t.push(r,$e(" ",null)),t}class LO{async fromData(t,e){const o={},r=e.getData("text/plain");if(r){const l={blocks:{root:r.replace(/\r\n/g,`
576
576
  `).replace(/\r/g,`
577
577
  `).split(`
578
- `).map(c=>{const a={id:N(),type:"text"};if(SO(c))return a.text=DO(c),a;const u=c?[$e(c,null)]:[];return a.text=u,a})},meta:{},comments:{}};o["text/plain"]=l}return o}}function MO(n){const t=[];for(let e=0;e<n.length;e++){const o=n[e];o.type.toLocaleLowerCase().startsWith("image/")&&t.push(o)}return t}class f3{constructor(t){t.dataConverter.addConverter(new xO),t.dataConverter.addConverter(new LO),t.dataConverter.addConverter(new TO)}async handleBeforePaste(t,e,o){if(!e)return!1;const r=e.clipboardData;if(r){if(r.getData("text/html").indexOf("<ones-editor-doc")>0)return!1;const s=MO(r.files);if(s.length>0&&!o["text/office-html"])return await this.handleInsertImages(t,s),!0}return!1}async handleInsertImages(t,e){const o=t.selection.focusedBlock,r=H(o),i=J(o),s=U(r);let l=i;Tt(t,o)||(l+=1);for(let c=0;c<e.length;c++){const a=e[c],u=await Ld(t,"image",s,l+c,{file:a});u&&kg(t,u,"image",{id:"replace-image",name:"Replace image",data:{block:u,image:a}})}}}function m3(n){return xt.isSafari&&!!n&&Date.now()-n<100}const g3=B("highlight-data");class pa{constructor(t){h(this,"data",new Map);this.editor=t}add(t,e,o){const r={id:N(),blockId:q(t),oldText:this.editor.getBlockText(t),start:e,end:o};return this.data.set(r.id,r),r}get(t){const e=this.data.get(t);return d(g3,e,`no highligh data: ${t}`),e}remove(t){this.data.delete(t)}clearBlockData(t){Array.from(this.data.values()).forEach(e=>{e.blockId===t&&this.data.delete(e.id)})}destroy(){}static getData(t){return t.addCustom("highligh-data",()=>new pa(t))}}function RO(n,t,e,o,r){const s=pa.getData(n).add(t,e,o);return r.setAttribute("data-highlight-id",s.id),s}function Ca(n,t){const e=t.getAttribute("data-highlight-id");return d(g3,e,"invalid highlight elem, no id"),pa.getData(n).get(e)}const Ys=B("highligh-dom");function AO(n){return nt(n,"editor-highlight")}function Ln(n){const t=n.rootContainer.querySelectorAll(".editor-highlight");return Array.from(t)}function OO(n){const t=n.rootContainer.querySelectorAll(".editor-replace-result-highlight");return Array.from(t)}function X1(n){const t=n.querySelectorAll(".editor-highlight");return Array.from(t)}function _O(n){X1(n).forEach(t=>{t.remove()})}function ui(n){return Ln(n).length}function NO(n,t){d(Ys,t>=0,`invalid highlight index: ${t}`);const e=Ln(n);return e.length===0?null:(d(Ys,t<e.length,`invalid highlight index: ${t}/${e.length}`),e[t])}function $O(n,t,{left:e,top:o,width:r,height:i},s){const l=["editor-highlight-child"];s&&l.push("editor-highlight-readonly");const c=b("div",l,n);c.style.top=`${o}px`,c.style.left=`${e}px`,c.style.width=`${r}px`,c.style.height=`${i}px`}function p3(n,t,e,o,r){d(Ys,o>0,`invalid end: ${o}`);const i=Rt(t),s=t.getBoundingClientRect(),l=io(n,t,At(n,t,e,o)),a=b("div",[r==="find"?"editor-highlight":"editor-replace-result-highlight"],i);l.forEach(u=>{$O(a,t,{left:u.left-s.left,width:u.width,top:u.top-s.top,height:u.height})}),RO(n,t,e,o,a)}function PO(n,t,e,o){return p3(n,t,e,o,"find")}function C3(n,t,e,o){return p3(n,t,e,o,"replace")}function ba(n,t){Ln(n).forEach(l=>{nt(l,"active")&&z(l,"active")}),A(t,"active"),d(Ys,t.firstChild instanceof HTMLElement,"invalid highligh dom, invalid elem child");const o=t.firstChild,r=o.getBoundingClientRect(),i=We(n.rootContainer);let s=r.y;s===0&&(s=o.getBoundingClientRect().y),id(i,{elementToScroll:n.scrollContainer})}function Qs(n){const t=n.rootContainer.querySelector(".editor-highlight.active");return t||null}function b3(n){return d(Ys,n,"no highlight elem"),nt(n,"editor-highlight-readonly")}const hi=B("highligh-text");function jO(n){OO(n).forEach(e=>{e.remove()})}function tf(n,t){Ln(n).forEach(o=>{o.remove()}),t!=null&&t.keepReplaceResult||jO(n)}function k3(n){const t=Qs(n);if(!t)return-1;const o=Ln(n).indexOf(t);return d(hi,o!==-1,`invalid highlight index: ${o}`),o}function HO(n){const t=Ln(n);if(t.length===0)return 0;const e=Qs(n);let o=e?t.indexOf(e):-1;!e||o===-1||o===t.length-1?o=0:o+=1;const r=t[o];return ba(n,r),o}function FO(n){const t=Ln(n);if(t.length===0)return 0;const e=Qs(n);let o=e?t.indexOf(e):-1;!e||o===-1||o===0?o=t.length-1:o-=1;const r=t[o];return ba(n,r),o}function zO(n,t){const e=Ln(n);e.length>0&&t<e.length&&ba(n,e[t])}function UO(n,t,e){const o=Qs(n);if(!o)return!1;const r=F(o);if(d(hi,r,"no parent block"),!n.isBlockWritable(r))return!1;const i=ui(n);let s=k3(n);if(!b3(o)&&n.isBlockWritable(r)){const a=Ca(n,o),u=n.getBlockText(r),{start:f,end:m}=Ca(n,o),[C,k]=ie.transformOffset(a.oldText,u,[f,m]),w=$g(u,C,k-C);if(bt(w).toLowerCase()!==t.toLowerCase())return!1;const y=Ul(u,C,k,e);n.setBlockText(r,y),_O(r),v3(n,r,t),e&&C3(n,r,C,C+e.length)}const l=ui(n);s>=l?s=0:l>i&&(s+=1);const c=NO(n,s);return c&&ba(n,c),!0}function VO(n,t,e,o){if(!P(n,t)||!n.isBlockWritable(t))return 0;const r=n.getBlockText(t);d(hi,r,"no block text");const i={count:0},s=lp(r,e,o,i);return bt(r)===bt(s)?0:(n.setBlockText(t,s),i.count)}function qO(n,t,e){if(d(hi,AO(t),"not a highlight elem"),b3(t))return;d(hi,e>0,"invalid highlight length");const o=Ca(n,t),r=F(t);d(hi,r,"no parent block"),C3(n,r,o.start,o.start+e)}function WO(n,t){Ln(n).forEach(o=>{qO(n,o,t)})}function GO(n,t,e){if(n.readonly)return 0;const o=i=>{let s=0;return Mt(i).forEach(c=>{at(n,c)?Se(n,c).forEach(u=>{s+=o(u)}):s+=VO(n,c,t,e)}),s},r=o(n.rootContainer);return e.length>0&&WO(n,e.length),r}function ZO(n){const t=n.selection.range.end,e=n.getBlockById(t.blockId),o=t.isSimple()?t.offset:1,r=X1(e);for(let l=0;l<r.length;l++){const c=r[l],{end:a}=Ca(n,c);if(a>=o)return c}const i=$d(n,{simpleBlockOnly:!0}),s=i.indexOf(e);if(s===-1)return null;for(let l=s+1;l<i.length;l++){const c=i[l],a=X1(c);if(a.length>0)return a[0]}return null}function YO(n){const t=Ln(n),e=ZO(n);return e?t.indexOf(e):0}function v3(n,t,e){if(!!e&&P(n,t)){const o=n.getBlockText(t),r=Kd(o,e);r.length>0&&r.forEach(({start:i,end:s})=>{PO(n,t,i,s)})}}function QO(n,t){if(tf(n),!t)return;$d(n,{simpleBlockOnly:!0}).forEach(o=>{v3(n,o,t)})}class KO{constructor(t){h(this,"dialog",null);h(this,"root");h(this,"oldText","");h(this,"_compositionEndTime",0);h(this,"components");h(this,"handleFindChanged",()=>{this.doSearch({keepReplaceResult:!1,gotoFirstSearchResult:!0})});h(this,"handleCompositionEnd",()=>{this._compositionEndTime=Date.now(),this.handleFindChanged()});h(this,"handleInput",t=>{if(t.isComposing||m3(this._compositionEndTime)){this.doSearch.cancel();return}this.handleFindChanged()});h(this,"handleFind",()=>{this.findNext({keepSearchResult:!1})});h(this,"handleReplace",()=>{const t=this.components.findInput.value;if(!t||!Qs(this.editor))return;const o=this.components.replaceInput.value;if(t===o)return;if(UO(this.editor,t,o)){const i=k3(this.editor),s=ui(this.editor);this.updateSearchStatus(i,s)}this.findNext({keepSearchResult:!0})});h(this,"handleReplaceAll",()=>{const t=this.components.findInput.value;if(!t)return;const e=this.components.replaceInput.value;if(t===e)return;GO(this.editor,t,e)>0&&(this.oldText="",this.doSearchNow({keepReplaceResult:!0,gotoFirstSearchResult:!0}),this.clearFind({keepReplaceResult:!0}))});h(this,"doSearch",Xt.default(this.doSearchNow,300));this.editor=t;const e=b("div",["editor-find-dialog"],null),o=b("div",["editor-find-content"],e),r=b("div",["editor-find-dialog-row"],o),i=vr(t5,["editor-find-dialog-button-close"],e),s=b("label",["editor-find-dialog-label"],r,T.t("find.findLabel"));s.htmlFor="";const l=b("div",["editor-find-dialog-input-container"],r),c=b("input",["editor-find-dialog-input"],l);c.type="text",c.placeholder=T.t("find.findPlaceholder");const a=b("div",["editor-find-dialog-status"],l),u=vr(Pw,["editor-find-dialog-icon-button"],a),f=b("div",["editor-find-dialog-curr"],a,"0/0"),m=vr(jw,["editor-find-dialog-icon-button"],a);let C;T.t("find.moreButton")?C=b("button",["editor-find-dialog-button"],r,T.t("find.moreButton")):C=vr(e5,["editor-find-dialog-icon-button-border"],r);const k=b("div",["editor-find-dialog-row"],o),w=b("label",["editor-find-dialog-label"],k,T.t("find.replaceLabel"));w.htmlFor="";const y=b("div",["editor-find-dialog-input-container"],k),S=b("input",["editor-find-dialog-input"],y);S.type="text",S.placeholder=T.t("find.replacePlaceholder");const I=b("div",["editor-find-dialog-row"],o);b("div",["editor-find-dialog-space"],I);const M=b("button",["editor-find-dialog-button"],I,T.t("find.findButton")),R=b("button",["editor-find-dialog-button"],I,T.t("find.replaceButton")),$=b("button",["editor-find-dialog-button"],I,T.t("find.replaceAllButton"));C.onclick=()=>{this.showReplace()},i.onclick=()=>{this.hide()},c.onkeydown=Z=>{if(Z.isComposing||m3(this._compositionEndTime)){this.doSearch.cancel();return}Bm(Z)?(this.doSearch.cancel(),this.doSearchNow({keepReplaceResult:!1,gotoFirstSearchResult:!0})):dd(Z)&&this.hide()},c.oninput=this.handleInput,c.onpaste=this.handleFindChanged,c.oncut=this.handleFindChanged,c.addEventListener("compositionend",this.handleCompositionEnd),c.maxLength=50,M.onclick=this.handleFind,R.onclick=this.handleReplace,$.onclick=this.handleReplaceAll,S.maxLength=50,m.onclick=()=>{this.gotoNext()},u.onclick=()=>{this.gotoPrev()},this.components={findInput:c,findPrev:u,findCurrent:f,findNext:m,replaceInput:S,findButton:M,replaceButton:R,replaceAllButton:$,closeButton:i,showReplaceButton:C,rowReplace:k,rowActions:I,statusContainer:a},this.root=e}findNext(t){this.doSearch.cancel(),this.doSearchNow({keepReplaceResult:t.keepSearchResult,gotoFirstSearchResult:!0})}doSearchNow(t){const e=this.components.findInput.value;if(e||this.clearFind(t),this.oldText===e){this.gotoNext();return}this.oldText=e,QO(this.editor,e);const o=ui(this.editor),r=YO(this.editor);t.gotoFirstSearchResult&&zO(this.editor,r),this.updateSearchStatus(r,o)}gotoNext(){const t=ui(this.editor),e=HO(this.editor);this.updateSearchStatus(e,t)}gotoPrev(){const t=ui(this.editor),e=FO(this.editor);this.updateSearchStatus(e,t)}updateSearchStatus(t,e){if(this.oldText?this.components.statusContainer.style.display="flex":this.components.statusContainer.style.display="none",e===0)this.components.findCurrent.innerText="0/0",this.components.replaceAllButton.disabled=!0,this.components.replaceButton.disabled=!0,this.components.findButton.disabled=!0;else{this.components.findCurrent.innerText=`${t+1}/${e}`;const o=this.editor.readonly;this.components.replaceAllButton.disabled=o,this.components.replaceButton.disabled=o,this.components.findButton.disabled=!1}}clearFind(t){tf(this.editor),this.updateSearchStatus(0,0)}showFindOnly(){this.components.rowReplace.style.display="none",this.components.rowActions.style.display="none",this.components.showReplaceButton.style.display="flex"}showReplace(){this.components.rowReplace.style.display="flex",this.components.rowActions.style.display="flex",this.components.showReplaceButton.style.display="none",this.components.replaceInput.focus(),this.components.replaceInput.select()}hideSearchResult(){this.components.statusContainer.style.display="none"}showSearchResult(){this.components.statusContainer.style.display="flex"}show(t){const e=this.editor.getSelectedText();e.length>0&&e.length<50&&(this.components.findInput.value=e),this.root.style.display="flex",t!=null&&t.showFindAndReplace?(this.showReplace(),this.components.findInput.value&&setTimeout(()=>{this.components.replaceInput.focus()})):this.showFindOnly(),this.hideSearchResult(),this.oldText="",this.doSearchNow({keepReplaceResult:!1,gotoFirstSearchResult:!0});const o=this.editor.readonly;this.components.replaceButton.disabled=o,this.components.replaceAllButton.disabled=o,this.components.replaceInput.disabled=o,this.dialog||(this.dialog=new vs(this.root,{disablePageScroll:!1}));const r=this.editor.options.componentsOptions.findDialog,i=(r==null?void 0:r.popoverTarget)||this.editor.rootContainer,s=()=>{var f,m,C,k;const l=r==null?void 0:r.getReferenceClientRect;if(l&&((m=(f=this.dialog)==null?void 0:f.tippyInstance)==null?void 0:m.popper))return l(i,(k=(C=this.dialog)==null?void 0:C.tippyInstance)==null?void 0:k.popper);const c=i.getBoundingClientRect(),a=c.top<0?12:c.top+12,u=c.right-this.root.clientWidth-12;return new DOMRect(u,a,0,0)};this.dialog.show(i,{getReferenceClientRect:s}),setTimeout(()=>{this.components.findInput.focus(),this.components.findInput.select()},300)}hide(){var t;(t=this.dialog)==null||t.close(),tf(this.editor)}isVisible(){return this.dialog&&this.dialog.isVisible}research(){this.oldText="",this.doSearch({keepReplaceResult:!0,gotoFirstSearchResult:!1})}destroy(){var t;(t=this.dialog)==null||t.destroy()}}const JO={find:{findLabel:"\u67E5\u627E:",replaceLabel:"\u66FF\u6362:",findButton:"\u67E5\u627E",replaceButton:"\u66FF\u6362",replaceAllButton:"\u5168\u90E8\u66FF\u6362",moreButton:"",findPlaceholder:"\u5728\u6587\u6863\u5185\u67E5\u627E",replacePlaceholder:"\u66FF\u6362\u4E3A"}},XO={find:{findLabel:"Find:",replaceLabel:"Replace:",findButton:"Find",replaceButton:"Replace",replaceAllButton:"Replace All",moreButton:"",findPlaceholder:"Find text in document",replacePlaceholder:"Replace to"}};T.mergeLang({"zh-CN":JO,"en-US":XO});function y3(n){return n.addCustom("find-dialog",()=>new KO(n)).show(),!0}const w3={"CtrlOrCmd+F":y3},Zz="";function t_(n){y3(n)}function ef(n,t){return t.map(e=>{var i,s;const o=kt(n,e),r=(i=o.getBlockProperties)==null?void 0:i.call(o,n,e);return(s=r==null?void 0:r.abstract)!=null?s:""}).join(" ")}function ka(n){const{editor:t,commentGroupId:e,abstract:o="text"}=n,r=N(),i=t.doc.getUser(),s=Date.now(),l=e!=null?e:r;return{id:r,groupId:l,userId:i.userId,displayName:i.displayName,avatarUrl:i.avatarUrl,abstract:o,created:s,modified:s}}function B3(n,t,e){const o=e.id,i=n.getBlockData(t).comments;let s;i?s=[...i,o]:s=[o];const l={comments:s};n.updateBlockData(t,l)}function nf(n,t,e){const o=ef(n,[t]),r=ka({editor:n,abstract:o});B3(n,t,r);const i=Ko();return e.localCreateComment(r,i),r}const e_=B("standard-block-actions");class n_{constructor(t,e){h(this,"executeCommand",(t,e,o)=>{const r=o.data;try{this.editorComments.showCommentList();const i=t.getBlockById(r);nf(t,i,this.provider)}catch(i){e_.error(`failed to execute block command: ${JSON.stringify(i)}`)}});this.provider=t,this.editorComments=e}commands(t,e){return{group:"block-comment-actions",commands:[{id:"comment",name:"Add comment",data:q(e),order:100}],executeCommand:this.executeCommand}}}var ft=(n=>(n.SwitchUp="switch-up",n.SwitchDown="switch-down",n.CommentItemReply="comment-item-reply",n.CommentItemMore="comment-item-more",n.CommentItemOk="comment-item-ok",n.CommentItemCancel="comment-item-cancel",n.CommentItemDelete="comment-item-delete",n.CommentItemEdit="comment-item-edit",n.QuickReply="quick-reply",n.QuickReplyOk="quick-reply-ok",n.QuickReplyCancel="quick-reply-cancel",n))(ft||{});const of="group-item-action",E3="last-comment-item",Jn="disabled",I3=500;function ur(n){return n.id!==n.groupId}function x3(n,t=".comment-item-root"){return n.querySelectorAll(t).length}function o_(n){const t=n.closest(".comment-item-root");return t?t.id:null}function Xn(n,t){n.setAttribute(of,t)}function r_(n){return n.closest(`[${of}]`)}function i_(n){var t;return(t=n.getAttribute(of))!=null?t:""}function s_(n){return nt(n,Jn)}function T3(n,t){const e=n.rootContainer.querySelector(`[comment-${t.toLocaleLowerCase()}=${t}`);if(!e)return null;const o=e.closest('[data-type="editor-block"]');return o?o.id:null}function S3(n){return Array.from(n.attributes).map(e=>e.name).filter(e=>e.startsWith("comment-")).map(e=>e.replace("comment-",""))}const D3=B("doc-comments");function L3(n,t,e,o){if(t.comments){const i=t.comments;Array.isArray(i)&&i.forEach(s=>{o.has(s)||(o.add(s),e.push(s))})}t.text&&t.text.forEach(s=>{if(s.attributes){const l="comment-";Object.entries(s.attributes).forEach(([c,a])=>{if(c.startsWith(l)){const u=a;o.has(u)||(o.add(u),e.push(u))}})}});const r=t.children;!r||r.forEach(i=>{n.blocks[i].forEach(l=>{L3(n,l,e,o)})})}function l_(n){const t=[],e=new Set;n.blocks.root.forEach(r=>{L3(n,r,t,e)});const o=new Map;return t.forEach((r,i)=>o.set(r,i)),o}function c_(n){const t=new Map;n.forEach(r=>{if(ur(r)){const i=t.get(r.groupId);i?i.push(r):t.set(r.groupId,[r])}});const e=[];return n.forEach(r=>{var i;if(!ur(r)){const s=(i=t.get(r.id))!=null?i:[];t.delete(r.id);const l={...r,children:s};e.push(l)}}),Array.from(t.values()).forEach(r=>{const i=r[0],s=r.slice(1),l={...i,children:s};e.push(l)}),e}function To(n,t){const e=n.doc.toJSON(),o=l_(e);return c_(t.getComments()).filter(s=>o.has(s.groupId)).sort((s,l)=>{const c=o.get(s.groupId),a=o.get(l.groupId);return d(D3,c!==void 0,`comment not exists in doc, ${s.groupId}`),d(D3,a!==void 0,`comment not exists in doc, ${l.groupId}`),c-a})}function rf(n){const{children:t,...e}=n,o=[e];return t.forEach(r=>{o.push(r)}),o}function a_(n,t){return To(n,t).map(rf).reduce((r,i)=>i.length+r,0)}function sf(n,t){const e=[],o=n.getBlockById(t.blockId);if(P(n,o)){const i=t.blockId,s=t.offset,l=n.getBlockById(i),c=n.getBlockText(l),a=zl(c,s);a&&Object.entries(a).forEach(([u,f])=>{u.startsWith("comment-")&&e.push(f)})}const r=o.attributes;for(let i=0;i<r.length;i++){const s=r[i];s.name.startsWith("comment-")&&e.push(s.value)}return e}function d_(n){const t=n.selection.range;if(!t.isSimple())return[];if(t.start.blockId!==t.end.blockId)return[];if(t.isCollapsed())return sf(n,t.start);const{start:e,end:o}=t,r=sf(n,e),i=sf(n,o);return Xa.default(r,i)}const u_=B("active-comments");function M3(n,t){n.rootContainer.querySelectorAll(`span.text.comment[comment-${t}],[data-type=editor-block].comment[comment-${t}]`).forEach(o=>{z(o,"active")})}function R3(n,t){const e=n.rootContainer.querySelector("span.text.comment.active,[data-type=editor-block].comment.active");if(!t)e&&S3(e).forEach(r=>M3(n,r));else{const o=t.toLocaleLowerCase();if(e){const i=S3(e);if(i.length===1&&i[0]===o)return;i.forEach(s=>M3(n,s))}const r=n.rootContainer.querySelectorAll(`span.text.comment[comment-${o}],[data-type=editor-block].comment[comment-${o}]`);if(r){r.forEach(s=>{A(s,"active")});const i=r[0];if(Uo(i))n.selection.selectBlock(i,0);else{const s=F(i);d(u_,s,"block not found");const l=ao(s,i);n.selection.selectBlock(s,l.start)}n.focus()}}}const Yz="";B("comment-editor");const{t:h_}=T,lf="comment-editor-readonly",Ks="comment-editor-editing";class cf{constructor(t,e,o){h(this,"root");h(this,"components");h(this,"handleEditorBlur",()=>{this.inactiveEditor()});h(this,"handleEditorFocus",()=>{this.editor.readonly||this.activeEditor()});h(this,"activeEditor",()=>{nt(this.root,Ks)||A(this.root,Ks)});h(this,"inactiveEditor",()=>{z(this.root,Ks)});h(this,"handleInsertImg",async()=>{const{editor:t}=this.components,e=U(t.rootContainer),o=await Fo("image/*",{}),r={src:"",widthPercent:50},i={id:N(),type:"embed",embedType:"image",embedData:r},s=t.options.componentsOptions.image;s!=null&&s.defaultAlign&&(i.align=s.defaultAlign);const l=t.getFocusedBlock(),c=t.getBlockIndex(l),a=t.insertBlock(e,c+1,i);zt.getImageObject(t,a).replaceImage(0,o)});h(this,"handleReadonlyChange",t=>{t.readonly?(z(this.root,Ks),A(this.root,lf)):(A(this.root,Ks),z(this.root,lf))});h(this,"setDoc",t=>{const{components:{editor:e}}=this;e.doc.externalDoc.setDoc(t)});h(this,"getDoc",()=>{const{components:{editor:t}}=this;return t.doc.toJSON()});h(this,"isEmpty",()=>ql(this.getDoc()));h(this,"edit",()=>{const{editor:t}=this.components;t.readonly=!1,_0(t),this.activeEditor()});h(this,"clear",()=>{const t=Ko();this.setDoc(t)});h(this,"readonly",()=>{const{editor:t}=this.components;t.readonly=!0});h(this,"destroy",()=>{const{root:t,components:{editor:e,insertImgButton:o}}=this;o.onclick=null,e.destroy(),t.remove()});this.mainEditor=t,this.commentsProvider=e,this.doc=o,this.root=b("div",["comment-editor",lf],null),this.components=this.createEditor()}createEditor(){const t=b("div",["comment-editor-root"],this.root),{commentsProvider:e,mainEditor:o}=this,r=e.createCommentEditor(t,new _u(this.doc));r.readonly=!0,r.addListener("readonlyChanged",this.handleReadonlyChange),r.addListener("focus",this.handleEditorFocus),r.addListener("blur",this.handleEditorBlur);const i=cr(this.root,"comment-editor-img",h_("comment.image"),Yw,void 0,o.clientId);return i.classList.add("comment-editor-img"),i.onclick=this.handleInsertImg,{editor:r,insertImgButton:i}}get editor(){return this.components.editor}}class f_{constructor(t){h(this,"handleBeforeKeyDown",(t,e)=>{if(jn(e,"Enter")){const{quickReply:o,updateLastCommentItem:r}=this.groupItem;return o.getReplyEditor().isEmpty()?(o.hideReplyEditor(),!0):(o.reply(),r(),!0)}return!1});this.groupItem=t}}class m_{constructor(t,e,o){h(this,"handleBeforeKeyDown",(t,e)=>{if(jn(e,"Enter")){const{quickReply:o}=this.groupItem,{comment:r,getCommentEditor:i}=this.commentItem,s=i();if(s.isEmpty())this.commentsProvider.localDeleteComment(r.id);else{const l=s.getDoc();this.commentsProvider.localUpdateComment(r,l),s.readonly()}return o.show(),!0}return!1});this.commentsProvider=t,this.groupItem=e,this.commentItem=o}}const g_=`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
578
+ `).map(c=>{const a={id:N(),type:"text"};if(SO(c))return a.text=DO(c),a;const u=c?[$e(c,null)]:[];return a.text=u,a})},meta:{},comments:{}};o["text/plain"]=l}return o}}function MO(n){const t=[];for(let e=0;e<n.length;e++){const o=n[e];o.type.toLocaleLowerCase().startsWith("image/")&&t.push(o)}return t}class f3{constructor(t){t.dataConverter.addConverter(new xO),t.dataConverter.addConverter(new LO),t.dataConverter.addConverter(new TO)}async handleBeforePaste(t,e,o){if(!e)return!1;const r=e.clipboardData;if(r){if(r.getData("text/html").indexOf("<ones-editor-doc")>0)return!1;const s=MO(r.files);if(s.length>0&&!o["text/office-html"])return await this.handleInsertImages(t,s),!0}return!1}async handleInsertImages(t,e){const o=t.selection.focusedBlock,r=H(o),i=J(o),s=U(r);let l=i;Tt(t,o)||(l+=1);for(let c=0;c<e.length;c++){const a=e[c],u=await Ld(t,"image",s,l+c,{file:a});u&&kg(t,u,"image",{id:"replace-image",name:"Replace image",data:{block:u,image:a}})}}}function m3(n){return xt.isSafari&&!!n&&Date.now()-n<100}const g3=B("highlight-data");class pa{constructor(t){h(this,"data",new Map);this.editor=t}add(t,e,o){const r={id:N(),blockId:q(t),oldText:this.editor.getBlockText(t),start:e,end:o};return this.data.set(r.id,r),r}get(t){const e=this.data.get(t);return d(g3,e,`no highligh data: ${t}`),e}remove(t){this.data.delete(t)}clearBlockData(t){Array.from(this.data.values()).forEach(e=>{e.blockId===t&&this.data.delete(e.id)})}destroy(){}static getData(t){return t.addCustom("highligh-data",()=>new pa(t))}}function RO(n,t,e,o,r){const s=pa.getData(n).add(t,e,o);return r.setAttribute("data-highlight-id",s.id),s}function Ca(n,t){const e=t.getAttribute("data-highlight-id");return d(g3,e,"invalid highlight elem, no id"),pa.getData(n).get(e)}const Ys=B("highligh-dom");function AO(n){return nt(n,"editor-highlight")}function Ln(n){const t=n.rootContainer.querySelectorAll(".editor-highlight");return Array.from(t)}function OO(n){const t=n.rootContainer.querySelectorAll(".editor-replace-result-highlight");return Array.from(t)}function X1(n){const t=n.querySelectorAll(".editor-highlight");return Array.from(t)}function _O(n){X1(n).forEach(t=>{t.remove()})}function ui(n){return Ln(n).length}function NO(n,t){d(Ys,t>=0,`invalid highlight index: ${t}`);const e=Ln(n);return e.length===0?null:(d(Ys,t<e.length,`invalid highlight index: ${t}/${e.length}`),e[t])}function $O(n,t,{left:e,top:o,width:r,height:i},s){const l=["editor-highlight-child"];s&&l.push("editor-highlight-readonly");const c=b("div",l,n);c.style.top=`${o}px`,c.style.left=`${e}px`,c.style.width=`${r}px`,c.style.height=`${i}px`}function p3(n,t,e,o,r){d(Ys,o>0,`invalid end: ${o}`);const i=Rt(t),s=t.getBoundingClientRect(),l=so(n,t,At(n,t,e,o)),a=b("div",[r==="find"?"editor-highlight":"editor-replace-result-highlight"],i);l.forEach(u=>{$O(a,t,{left:u.left-s.left,width:u.width,top:u.top-s.top,height:u.height})}),RO(n,t,e,o,a)}function PO(n,t,e,o){return p3(n,t,e,o,"find")}function C3(n,t,e,o){return p3(n,t,e,o,"replace")}function ba(n,t){Ln(n).forEach(l=>{nt(l,"active")&&z(l,"active")}),A(t,"active"),d(Ys,t.firstChild instanceof HTMLElement,"invalid highligh dom, invalid elem child");const o=t.firstChild,r=o.getBoundingClientRect(),i=We(n.rootContainer);let s=r.y;s===0&&(s=o.getBoundingClientRect().y),id(i,{elementToScroll:n.scrollContainer})}function Qs(n){const t=n.rootContainer.querySelector(".editor-highlight.active");return t||null}function b3(n){return d(Ys,n,"no highlight elem"),nt(n,"editor-highlight-readonly")}const hi=B("highligh-text");function jO(n){OO(n).forEach(e=>{e.remove()})}function tf(n,t){Ln(n).forEach(o=>{o.remove()}),t!=null&&t.keepReplaceResult||jO(n)}function k3(n){const t=Qs(n);if(!t)return-1;const o=Ln(n).indexOf(t);return d(hi,o!==-1,`invalid highlight index: ${o}`),o}function HO(n){const t=Ln(n);if(t.length===0)return 0;const e=Qs(n);let o=e?t.indexOf(e):-1;!e||o===-1||o===t.length-1?o=0:o+=1;const r=t[o];return ba(n,r),o}function FO(n){const t=Ln(n);if(t.length===0)return 0;const e=Qs(n);let o=e?t.indexOf(e):-1;!e||o===-1||o===0?o=t.length-1:o-=1;const r=t[o];return ba(n,r),o}function zO(n,t){const e=Ln(n);e.length>0&&t<e.length&&ba(n,e[t])}function UO(n,t,e){const o=Qs(n);if(!o)return!1;const r=F(o);if(d(hi,r,"no parent block"),!n.isBlockWritable(r))return!1;const i=ui(n);let s=k3(n);if(!b3(o)&&n.isBlockWritable(r)){const a=Ca(n,o),u=n.getBlockText(r),{start:f,end:m}=Ca(n,o),[C,k]=ie.transformOffset(a.oldText,u,[f,m]),w=$g(u,C,k-C);if(bt(w).toLowerCase()!==t.toLowerCase())return!1;const y=Ul(u,C,k,e);n.setBlockText(r,y),_O(r),v3(n,r,t),e&&C3(n,r,C,C+e.length)}const l=ui(n);s>=l?s=0:l>i&&(s+=1);const c=NO(n,s);return c&&ba(n,c),!0}function VO(n,t,e,o){if(!P(n,t)||!n.isBlockWritable(t))return 0;const r=n.getBlockText(t);d(hi,r,"no block text");const i={count:0},s=lp(r,e,o,i);return bt(r)===bt(s)?0:(n.setBlockText(t,s),i.count)}function qO(n,t,e){if(d(hi,AO(t),"not a highlight elem"),b3(t))return;d(hi,e>0,"invalid highlight length");const o=Ca(n,t),r=F(t);d(hi,r,"no parent block"),C3(n,r,o.start,o.start+e)}function WO(n,t){Ln(n).forEach(o=>{qO(n,o,t)})}function GO(n,t,e){if(n.readonly)return 0;const o=i=>{let s=0;return Mt(i).forEach(c=>{at(n,c)?Se(n,c).forEach(u=>{s+=o(u)}):s+=VO(n,c,t,e)}),s},r=o(n.rootContainer);return e.length>0&&WO(n,e.length),r}function ZO(n){const t=n.selection.range.end,e=n.getBlockById(t.blockId),o=t.isSimple()?t.offset:1,r=X1(e);for(let l=0;l<r.length;l++){const c=r[l],{end:a}=Ca(n,c);if(a>=o)return c}const i=$d(n,{simpleBlockOnly:!0}),s=i.indexOf(e);if(s===-1)return null;for(let l=s+1;l<i.length;l++){const c=i[l],a=X1(c);if(a.length>0)return a[0]}return null}function YO(n){const t=Ln(n),e=ZO(n);return e?t.indexOf(e):0}function v3(n,t,e){if(!!e&&P(n,t)){const o=n.getBlockText(t),r=Kd(o,e);r.length>0&&r.forEach(({start:i,end:s})=>{PO(n,t,i,s)})}}function QO(n,t){if(tf(n),!t)return;$d(n,{simpleBlockOnly:!0}).forEach(o=>{v3(n,o,t)})}class KO{constructor(t){h(this,"dialog",null);h(this,"root");h(this,"oldText","");h(this,"_compositionEndTime",0);h(this,"components");h(this,"handleFindChanged",()=>{this.doSearch({keepReplaceResult:!1,gotoFirstSearchResult:!0})});h(this,"handleCompositionEnd",()=>{this._compositionEndTime=Date.now(),this.handleFindChanged()});h(this,"handleInput",t=>{if(t.isComposing||m3(this._compositionEndTime)){this.doSearch.cancel();return}this.handleFindChanged()});h(this,"handleFind",()=>{this.findNext({keepSearchResult:!1})});h(this,"handleReplace",()=>{const t=this.components.findInput.value;if(!t||!Qs(this.editor))return;const o=this.components.replaceInput.value;if(t===o)return;if(UO(this.editor,t,o)){const i=k3(this.editor),s=ui(this.editor);this.updateSearchStatus(i,s)}this.findNext({keepSearchResult:!0})});h(this,"handleReplaceAll",()=>{const t=this.components.findInput.value;if(!t)return;const e=this.components.replaceInput.value;if(t===e)return;GO(this.editor,t,e)>0&&(this.oldText="",this.doSearchNow({keepReplaceResult:!0,gotoFirstSearchResult:!0}),this.clearFind({keepReplaceResult:!0}))});h(this,"doSearch",Xt.default(this.doSearchNow,300));this.editor=t;const e=b("div",["editor-find-dialog"],null),o=b("div",["editor-find-content"],e),r=b("div",["editor-find-dialog-row"],o),i=vr(t5,["editor-find-dialog-button-close"],e),s=b("label",["editor-find-dialog-label"],r,T.t("find.findLabel"));s.htmlFor="";const l=b("div",["editor-find-dialog-input-container"],r),c=b("input",["editor-find-dialog-input"],l);c.type="text",c.placeholder=T.t("find.findPlaceholder");const a=b("div",["editor-find-dialog-status"],l),u=vr(Pw,["editor-find-dialog-icon-button"],a),f=b("div",["editor-find-dialog-curr"],a,"0/0"),m=vr(jw,["editor-find-dialog-icon-button"],a);let C;T.t("find.moreButton")?C=b("button",["editor-find-dialog-button"],r,T.t("find.moreButton")):C=vr(e5,["editor-find-dialog-icon-button-border"],r);const k=b("div",["editor-find-dialog-row"],o),w=b("label",["editor-find-dialog-label"],k,T.t("find.replaceLabel"));w.htmlFor="";const y=b("div",["editor-find-dialog-input-container"],k),S=b("input",["editor-find-dialog-input"],y);S.type="text",S.placeholder=T.t("find.replacePlaceholder");const I=b("div",["editor-find-dialog-row"],o);b("div",["editor-find-dialog-space"],I);const M=b("button",["editor-find-dialog-button"],I,T.t("find.findButton")),R=b("button",["editor-find-dialog-button"],I,T.t("find.replaceButton")),$=b("button",["editor-find-dialog-button"],I,T.t("find.replaceAllButton"));C.onclick=()=>{this.showReplace()},i.onclick=()=>{this.hide()},c.onkeydown=Z=>{if(Z.isComposing||m3(this._compositionEndTime)){this.doSearch.cancel();return}Bm(Z)?(this.doSearch.cancel(),this.doSearchNow({keepReplaceResult:!1,gotoFirstSearchResult:!0})):dd(Z)&&this.hide()},c.oninput=this.handleInput,c.onpaste=this.handleFindChanged,c.oncut=this.handleFindChanged,c.addEventListener("compositionend",this.handleCompositionEnd),c.maxLength=50,M.onclick=this.handleFind,R.onclick=this.handleReplace,$.onclick=this.handleReplaceAll,S.maxLength=50,m.onclick=()=>{this.gotoNext()},u.onclick=()=>{this.gotoPrev()},this.components={findInput:c,findPrev:u,findCurrent:f,findNext:m,replaceInput:S,findButton:M,replaceButton:R,replaceAllButton:$,closeButton:i,showReplaceButton:C,rowReplace:k,rowActions:I,statusContainer:a},this.root=e}findNext(t){this.doSearch.cancel(),this.doSearchNow({keepReplaceResult:t.keepSearchResult,gotoFirstSearchResult:!0})}doSearchNow(t){const e=this.components.findInput.value;if(e||this.clearFind(t),this.oldText===e){this.gotoNext();return}this.oldText=e,QO(this.editor,e);const o=ui(this.editor),r=YO(this.editor);t.gotoFirstSearchResult&&zO(this.editor,r),this.updateSearchStatus(r,o)}gotoNext(){const t=ui(this.editor),e=HO(this.editor);this.updateSearchStatus(e,t)}gotoPrev(){const t=ui(this.editor),e=FO(this.editor);this.updateSearchStatus(e,t)}updateSearchStatus(t,e){if(this.oldText?this.components.statusContainer.style.display="flex":this.components.statusContainer.style.display="none",e===0)this.components.findCurrent.innerText="0/0",this.components.replaceAllButton.disabled=!0,this.components.replaceButton.disabled=!0,this.components.findButton.disabled=!0;else{this.components.findCurrent.innerText=`${t+1}/${e}`;const o=this.editor.readonly;this.components.replaceAllButton.disabled=o,this.components.replaceButton.disabled=o,this.components.findButton.disabled=!1}}clearFind(t){tf(this.editor),this.updateSearchStatus(0,0)}showFindOnly(){this.components.rowReplace.style.display="none",this.components.rowActions.style.display="none",this.components.showReplaceButton.style.display="flex"}showReplace(){this.components.rowReplace.style.display="flex",this.components.rowActions.style.display="flex",this.components.showReplaceButton.style.display="none",this.components.replaceInput.focus(),this.components.replaceInput.select()}hideSearchResult(){this.components.statusContainer.style.display="none"}showSearchResult(){this.components.statusContainer.style.display="flex"}show(t){const e=this.editor.getSelectedText();e.length>0&&e.length<50&&(this.components.findInput.value=e),this.root.style.display="flex",t!=null&&t.showFindAndReplace?(this.showReplace(),this.components.findInput.value&&setTimeout(()=>{this.components.replaceInput.focus()})):this.showFindOnly(),this.hideSearchResult(),this.oldText="",this.doSearchNow({keepReplaceResult:!1,gotoFirstSearchResult:!0});const o=this.editor.readonly;this.components.replaceButton.disabled=o,this.components.replaceAllButton.disabled=o,this.components.replaceInput.disabled=o,this.dialog||(this.dialog=new vs(this.root,{disablePageScroll:!1}));const r=this.editor.options.componentsOptions.findDialog,i=(r==null?void 0:r.popoverTarget)||this.editor.rootContainer,s=()=>{var f,m,C,k;const l=r==null?void 0:r.getReferenceClientRect;if(l&&((m=(f=this.dialog)==null?void 0:f.tippyInstance)==null?void 0:m.popper))return l(i,(k=(C=this.dialog)==null?void 0:C.tippyInstance)==null?void 0:k.popper);const c=i.getBoundingClientRect(),a=c.top<0?12:c.top+12,u=c.right-this.root.clientWidth-12;return new DOMRect(u,a,0,0)};this.dialog.show(i,{getReferenceClientRect:s}),setTimeout(()=>{this.components.findInput.focus(),this.components.findInput.select()},300)}hide(){var t;(t=this.dialog)==null||t.close(),tf(this.editor)}isVisible(){return this.dialog&&this.dialog.isVisible}research(){this.oldText="",this.doSearch({keepReplaceResult:!0,gotoFirstSearchResult:!1})}destroy(){var t;(t=this.dialog)==null||t.destroy()}}const JO={find:{findLabel:"\u67E5\u627E:",replaceLabel:"\u66FF\u6362:",findButton:"\u67E5\u627E",replaceButton:"\u66FF\u6362",replaceAllButton:"\u5168\u90E8\u66FF\u6362",moreButton:"",findPlaceholder:"\u5728\u6587\u6863\u5185\u67E5\u627E",replacePlaceholder:"\u66FF\u6362\u4E3A"}},XO={find:{findLabel:"Find:",replaceLabel:"Replace:",findButton:"Find",replaceButton:"Replace",replaceAllButton:"Replace All",moreButton:"",findPlaceholder:"Find text in document",replacePlaceholder:"Replace to"}};T.mergeLang({"zh-CN":JO,"en-US":XO});function y3(n){return n.addCustom("find-dialog",()=>new KO(n)).show(),!0}const w3={"CtrlOrCmd+F":y3},Zz="";function t_(n){y3(n)}function ef(n,t){return t.map(e=>{var i,s;const o=kt(n,e),r=(i=o.getBlockProperties)==null?void 0:i.call(o,n,e);return(s=r==null?void 0:r.abstract)!=null?s:""}).join(" ")}function ka(n){const{editor:t,commentGroupId:e,abstract:o="text"}=n,r=N(),i=t.doc.getUser(),s=Date.now(),l=e!=null?e:r;return{id:r,groupId:l,userId:i.userId,displayName:i.displayName,avatarUrl:i.avatarUrl,abstract:o,created:s,modified:s}}function B3(n,t,e){const o=e.id,i=n.getBlockData(t).comments;let s;i?s=[...i,o]:s=[o];const l={comments:s};n.updateBlockData(t,l)}function nf(n,t,e){const o=ef(n,[t]),r=ka({editor:n,abstract:o});B3(n,t,r);const i=Ko();return e.localCreateComment(r,i),r}const e_=B("standard-block-actions");class n_{constructor(t,e){h(this,"executeCommand",(t,e,o)=>{const r=o.data;try{this.editorComments.showCommentList();const i=t.getBlockById(r);nf(t,i,this.provider)}catch(i){e_.error(`failed to execute block command: ${JSON.stringify(i)}`)}});this.provider=t,this.editorComments=e}commands(t,e){return{group:"block-comment-actions",commands:[{id:"comment",name:"Add comment",data:q(e),order:100}],executeCommand:this.executeCommand}}}var ft=(n=>(n.SwitchUp="switch-up",n.SwitchDown="switch-down",n.CommentItemReply="comment-item-reply",n.CommentItemMore="comment-item-more",n.CommentItemOk="comment-item-ok",n.CommentItemCancel="comment-item-cancel",n.CommentItemDelete="comment-item-delete",n.CommentItemEdit="comment-item-edit",n.QuickReply="quick-reply",n.QuickReplyOk="quick-reply-ok",n.QuickReplyCancel="quick-reply-cancel",n))(ft||{});const of="group-item-action",E3="last-comment-item",Jn="disabled",I3=500;function ur(n){return n.id!==n.groupId}function x3(n,t=".comment-item-root"){return n.querySelectorAll(t).length}function o_(n){const t=n.closest(".comment-item-root");return t?t.id:null}function Xn(n,t){n.setAttribute(of,t)}function r_(n){return n.closest(`[${of}]`)}function i_(n){var t;return(t=n.getAttribute(of))!=null?t:""}function s_(n){return nt(n,Jn)}function T3(n,t){const e=n.rootContainer.querySelector(`[comment-${t.toLocaleLowerCase()}=${t}`);if(!e)return null;const o=e.closest('[data-type="editor-block"]');return o?o.id:null}function S3(n){return Array.from(n.attributes).map(e=>e.name).filter(e=>e.startsWith("comment-")).map(e=>e.replace("comment-",""))}const D3=B("doc-comments");function L3(n,t,e,o){if(t.comments){const i=t.comments;Array.isArray(i)&&i.forEach(s=>{o.has(s)||(o.add(s),e.push(s))})}t.text&&t.text.forEach(s=>{if(s.attributes){const l="comment-";Object.entries(s.attributes).forEach(([c,a])=>{if(c.startsWith(l)){const u=a;o.has(u)||(o.add(u),e.push(u))}})}});const r=t.children;!r||r.forEach(i=>{n.blocks[i].forEach(l=>{L3(n,l,e,o)})})}function l_(n){const t=[],e=new Set;n.blocks.root.forEach(r=>{L3(n,r,t,e)});const o=new Map;return t.forEach((r,i)=>o.set(r,i)),o}function c_(n){const t=new Map;n.forEach(r=>{if(ur(r)){const i=t.get(r.groupId);i?i.push(r):t.set(r.groupId,[r])}});const e=[];return n.forEach(r=>{var i;if(!ur(r)){const s=(i=t.get(r.id))!=null?i:[];t.delete(r.id);const l={...r,children:s};e.push(l)}}),Array.from(t.values()).forEach(r=>{const i=r[0],s=r.slice(1),l={...i,children:s};e.push(l)}),e}function So(n,t){const e=n.doc.toJSON(),o=l_(e);return c_(t.getComments()).filter(s=>o.has(s.groupId)).sort((s,l)=>{const c=o.get(s.groupId),a=o.get(l.groupId);return d(D3,c!==void 0,`comment not exists in doc, ${s.groupId}`),d(D3,a!==void 0,`comment not exists in doc, ${l.groupId}`),c-a})}function rf(n){const{children:t,...e}=n,o=[e];return t.forEach(r=>{o.push(r)}),o}function a_(n,t){return So(n,t).map(rf).reduce((r,i)=>i.length+r,0)}function sf(n,t){const e=[],o=n.getBlockById(t.blockId);if(P(n,o)){const i=t.blockId,s=t.offset,l=n.getBlockById(i),c=n.getBlockText(l),a=zl(c,s);a&&Object.entries(a).forEach(([u,f])=>{u.startsWith("comment-")&&e.push(f)})}const r=o.attributes;for(let i=0;i<r.length;i++){const s=r[i];s.name.startsWith("comment-")&&e.push(s.value)}return e}function d_(n){const t=n.selection.range;if(!t.isSimple())return[];if(t.start.blockId!==t.end.blockId)return[];if(t.isCollapsed())return sf(n,t.start);const{start:e,end:o}=t,r=sf(n,e),i=sf(n,o);return Xa.default(r,i)}const u_=B("active-comments");function M3(n,t){n.rootContainer.querySelectorAll(`span.text.comment[comment-${t}],[data-type=editor-block].comment[comment-${t}]`).forEach(o=>{z(o,"active")})}function R3(n,t){const e=n.rootContainer.querySelector("span.text.comment.active,[data-type=editor-block].comment.active");if(!t)e&&S3(e).forEach(r=>M3(n,r));else{const o=t.toLocaleLowerCase();if(e){const i=S3(e);if(i.length===1&&i[0]===o)return;i.forEach(s=>M3(n,s))}const r=n.rootContainer.querySelectorAll(`span.text.comment[comment-${o}],[data-type=editor-block].comment[comment-${o}]`);if(r){r.forEach(s=>{A(s,"active")});const i=r[0];if(Vo(i))n.selection.selectBlock(i,0);else{const s=F(i);d(u_,s,"block not found");const l=uo(s,i);n.selection.selectBlock(s,l.start)}n.focus()}}}const Yz="";B("comment-editor");const{t:h_}=T,lf="comment-editor-readonly",Ks="comment-editor-editing";class cf{constructor(t,e,o){h(this,"root");h(this,"components");h(this,"handleEditorBlur",()=>{this.inactiveEditor()});h(this,"handleEditorFocus",()=>{this.editor.readonly||this.activeEditor()});h(this,"activeEditor",()=>{nt(this.root,Ks)||A(this.root,Ks)});h(this,"inactiveEditor",()=>{z(this.root,Ks)});h(this,"handleInsertImg",async()=>{const{editor:t}=this.components,e=U(t.rootContainer),o=await zo("image/*",{}),r={src:"",widthPercent:50},i={id:N(),type:"embed",embedType:"image",embedData:r},s=t.options.componentsOptions.image;s!=null&&s.defaultAlign&&(i.align=s.defaultAlign);const l=t.getFocusedBlock(),c=t.getBlockIndex(l),a=t.insertBlock(e,c+1,i);zt.getImageObject(t,a).replaceImage(0,o)});h(this,"handleReadonlyChange",t=>{t.readonly?(z(this.root,Ks),A(this.root,lf)):(A(this.root,Ks),z(this.root,lf))});h(this,"setDoc",t=>{const{components:{editor:e}}=this;e.doc.externalDoc.setDoc(t)});h(this,"getDoc",()=>{const{components:{editor:t}}=this;return t.doc.toJSON()});h(this,"isEmpty",()=>ql(this.getDoc()));h(this,"edit",()=>{const{editor:t}=this.components;t.readonly=!1,_0(t),this.activeEditor()});h(this,"clear",()=>{const t=Ko();this.setDoc(t)});h(this,"readonly",()=>{const{editor:t}=this.components;t.readonly=!0});h(this,"destroy",()=>{const{root:t,components:{editor:e,insertImgButton:o}}=this;o.onclick=null,e.destroy(),t.remove()});this.mainEditor=t,this.commentsProvider=e,this.doc=o,this.root=b("div",["comment-editor",lf],null),this.components=this.createEditor()}createEditor(){const t=b("div",["comment-editor-root"],this.root),{commentsProvider:e,mainEditor:o}=this,r=e.createCommentEditor(t,new _u(this.doc));r.readonly=!0,r.addListener("readonlyChanged",this.handleReadonlyChange),r.addListener("focus",this.handleEditorFocus),r.addListener("blur",this.handleEditorBlur);const i=cr(this.root,"comment-editor-img",h_("comment.image"),Yw,void 0,o.clientId);return i.classList.add("comment-editor-img"),i.onclick=this.handleInsertImg,{editor:r,insertImgButton:i}}get editor(){return this.components.editor}}class f_{constructor(t){h(this,"handleBeforeKeyDown",(t,e)=>{if(jn(e,"Enter")){const{quickReply:o,updateLastCommentItem:r}=this.groupItem;return o.getReplyEditor().isEmpty()?(o.hideReplyEditor(),!0):(o.reply(),r(),!0)}return!1});this.groupItem=t}}class m_{constructor(t,e,o){h(this,"handleBeforeKeyDown",(t,e)=>{if(jn(e,"Enter")){const{quickReply:o}=this.groupItem,{comment:r,getCommentEditor:i}=this.commentItem,s=i();if(s.isEmpty())this.commentsProvider.localDeleteComment(r.id);else{const l=s.getDoc();this.commentsProvider.localUpdateComment(r,l),s.readonly()}return o.show(),!0}return!1});this.commentsProvider=t,this.groupItem=e,this.commentItem=o}}const g_=`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
579
579
  <path fill-rule="evenodd" clip-rule="evenodd" d="M3.65499 6.6665C3.09433 6.6665 2.66699 7.1275 2.66699 7.67617C2.66699 8.2255 3.02633 8.64284 3.65499 8.6645C4.23833 8.6645 4.66399 8.26917 4.66399 7.67617C4.66399 7.1275 4.23899 6.6665 3.65499 6.6665ZM12.9883 6.6665C12.4277 6.6665 12.0003 7.1275 12.0003 7.67617C12.0003 8.2255 12.3597 8.64284 12.9883 8.6645C13.5717 8.6645 13.9973 8.26917 13.9973 7.67617C13.9973 7.1275 13.5723 6.6665 12.9883 6.6665ZM8.32166 6.6665C7.76099 6.6665 7.33399 7.1275 7.33399 7.67617C7.33399 8.2255 7.69299 8.64284 8.32166 8.6645C8.90499 8.6645 9.33066 8.26917 9.33066 7.67617C9.33066 7.1275 8.90566 6.6665 8.32166 6.6665Z" fill="currentColor"></path>
580
580
  </svg>`,p_=`<svg
581
581
  fill="currentColor"
582
582
  width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
583
583
  <path fill-rule="evenodd" clip-rule="evenodd" d="M8.63999 19.5893C8.82172 19.5893 8.9891 19.5427 9.14214 19.4494C9.29518 19.3561 9.48169 19.2115 9.70168 19.0154L12.0403 16.9422H16.2512C16.9255 16.9422 17.497 16.8191 17.9657 16.5728C18.4343 16.3265 18.7906 15.969 19.0345 15.5003C19.2784 15.0317 19.4004 14.4626 19.4004 13.793V8.55629C19.4004 7.88675 19.2784 7.31765 19.0345 6.84897C18.7906 6.38029 18.4343 6.02161 17.9657 5.77293C17.497 5.52424 16.9255 5.3999 16.2512 5.3999H7.5496C6.88007 5.3999 6.31096 5.52305 5.84228 5.76934C5.37361 6.01564 5.01612 6.37432 4.76983 6.84538C4.52354 7.31645 4.40039 7.88675 4.40039 8.55629V13.793C4.40039 14.4626 4.52354 15.0329 4.76983 15.5039C5.01612 15.975 5.37241 16.3325 5.8387 16.5764C6.30498 16.8203 6.86811 16.9422 7.52808 16.9422H7.82937V18.6639C7.82937 18.9461 7.89991 19.1708 8.04099 19.3382C8.18207 19.5056 8.38174 19.5893 8.63999 19.5893ZM8.94845 18.1976V16.2536C8.94845 16.0623 8.90541 15.9248 8.81933 15.8411C8.73325 15.7574 8.59695 15.7155 8.41043 15.7155H7.5783C6.91832 15.7155 6.42932 15.5505 6.11129 15.2206C5.79326 14.8906 5.63425 14.4076 5.63425 13.7715V8.57781C5.63425 7.94175 5.79326 7.45992 6.11129 7.13233C6.42932 6.80473 6.91832 6.64094 7.5783 6.64094H16.2225C16.8825 6.64094 17.3715 6.80473 17.6895 7.13233C18.0075 7.45992 18.1665 7.94175 18.1665 8.57781V13.7715C18.1665 14.4076 18.0075 14.8906 17.6895 15.2206C17.3715 15.5505 16.8825 15.7155 16.2225 15.7155H11.9757C11.7749 15.7155 11.6146 15.7383 11.4951 15.7837C11.3755 15.8291 11.2464 15.9212 11.1077 16.0599L8.94845 18.1976ZM15.584 9.23419C15.5027 9.3131 15.4047 9.35256 15.2899 9.35256H8.42478C8.31479 9.35256 8.22033 9.3131 8.14142 9.23419C8.06251 9.15528 8.02306 9.05844 8.02306 8.94366C8.02306 8.83367 8.06251 8.73802 8.14142 8.65672C8.22033 8.57542 8.31479 8.53477 8.42478 8.53477H15.2899C15.4047 8.53477 15.5027 8.57542 15.584 8.65672C15.6653 8.73802 15.706 8.83367 15.706 8.94366C15.706 9.05844 15.6653 9.15528 15.584 9.23419ZM15.2899 11.5333C15.4047 11.5333 15.5027 11.4939 15.584 11.415C15.6653 11.3361 15.706 11.2392 15.706 11.1244C15.706 11.0097 15.6653 10.9116 15.584 10.8303C15.5027 10.749 15.4047 10.7084 15.2899 10.7084H8.42478C8.31479 10.7084 8.22033 10.749 8.14142 10.8303C8.06251 10.9116 8.02306 11.0097 8.02306 11.1244C8.02306 11.2392 8.06251 11.3361 8.14142 11.415C8.22033 11.4939 8.31479 11.5333 8.42478 11.5333H15.2899ZM13.1845 13.5957C13.1056 13.6747 13.0111 13.7141 12.9011 13.7141H8.42478C8.31479 13.7141 8.22033 13.6747 8.14142 13.5957C8.06251 13.5168 8.02306 13.4224 8.02306 13.3124C8.02306 13.1928 8.06251 13.0924 8.14142 13.0111C8.22033 12.9298 8.31479 12.8891 8.42478 12.8891H12.9011C13.0111 12.8891 13.1056 12.9298 13.1845 13.0111C13.2634 13.0924 13.3028 13.1928 13.3028 13.3124C13.3028 13.4224 13.2634 13.5168 13.1845 13.5957Z"></path>
584
- </svg>`,Qz="";B("comment-item");const{t:fi}=T,A3="comment-item-editing",O3="active";class _3{constructor(t){h(this,"root");h(this,"moreMenu");h(this,"components");h(this,"createRoot",()=>{const t=b("div",["comment-item-root"],null);return t.id=this.comment.id,t});h(this,"handleMore",()=>{const{moreButton:t}=this.components;!t||this.moreMenu.manualShow(t,{placement:"bottom-start"})});h(this,"handleMoreMenuItemShow",()=>{const{headTools:t}=this.components;t.classList.add(O3)});h(this,"handleMoreMenuItemClose",()=>{const{headTools:t}=this.components;t.classList.remove(O3)});h(this,"handleMoreMenuItemClick",(t,e)=>{const o=this.options.groupList.groupItemHandlers,{id:r}=e;r==="edit"&&o.handleCommentItemEdit(this),r==="delete"&&o.handleCommentItemDelete(this)});h(this,"handleEditorReadonlyChange",t=>{const{components:{actions:e},root:o}=this;t.readonly?(o.classList.remove(A3),e.classList.add("hidden")):(o.classList.add(A3),e.classList.remove("hidden"))});h(this,"handleFocus",()=>{const{components:{commentEditor:t,okButton:e}}=this;t.isEmpty()?A(e,Jn):z(e,Jn)});h(this,"handleDocChanged",()=>{const{commentEditor:t,okButton:e}=this.components;t.isEmpty()?A(e,Jn):z(e,Jn)});h(this,"getCommentEditor",()=>this.components.commentEditor);h(this,"handleReadonlyChanged",t=>{t.readonly?A(this.root,"readonly"):z(this.root,"readonly")});this.options=t,this.root=this.createRoot(),this.components=this.createItem(),this.moreMenu=this.createMoreMenu(),t.mainEditor.on("readonlyChanged",this.handleReadonlyChanged)}get commentOptions(){return this.options.mainEditor.getComponentOptions("comment")}get comment(){return this.options.comment}get doc(){const{comment:t,commentsProvider:e}=this.options;return e.getCommentDoc(t.id)}createMoreMenu(){const t=new nr([{id:"edit",name:fi("comment.edit")},{id:"delete",name:fi("comment.delete")}]);return t.on("click",this.handleMoreMenuItemClick),t.on("close",this.handleMoreMenuItemClose),t.on("show",this.handleMoreMenuItemShow),t}createItem(){var $,Z;const{comment:t,commentsProvider:e,mainEditor:o,groupItem:r}=this.options,i=!(($=this.commentOptions)!=null&&$.disableReply)&&!o.readonly,l=!((Z=this.commentOptions)!=null&&Z.disableEdit)&&!o.readonly&&i,c=b("div",["item-head"],this.root),a=b("img",["item-head-avatar"],c);a.src=t.avatarUrl;const u=b("span",["item-head-username"],c);u.innerText=t.displayName;const f=b("span",["item-head-modified"],c),m=new Date(t.modified);f.innerText=pd(m);const C=b("div",["item-head-tools"],c);let k=null;i&&(k=cr(C,ft.CommentItemReply,fi("comment.reply"),p_,void 0,o.clientId),Xn(k,ft.CommentItemReply));let w=null;l&&(w=cr(C,ft.CommentItemMore,fi("comment.more"),g_,void 0,o.clientId),Xn(w,ft.CommentItemMore),w.onclick=this.handleMore);const y=b("div",["item-editor"],this.root),S=new cf(o,e,this.doc);S.editor.addListener("readonlyChanged",this.handleEditorReadonlyChange),S.editor.addListener("docChanged",this.handleDocChanged),S.editor.addListener("focus",this.handleFocus),S.editor.input.addHandler(new m_(e,r,this)),y.append(S.root);const I=b("div",["item-actions","hidden"],this.root),M=vo(ft.CommentItemCancel,fi("common.cancel"));Xn(M,ft.CommentItemCancel);const R=vo(ft.CommentItemOk,fi("comment.send"));return Xn(R,ft.CommentItemOk),I.append(M,R),{head:c,replyButton:k,moreButton:w,commentEditor:S,okButton:R,cancelButton:M,actions:I,headTools:C}}reloadDoc(){const{components:{commentEditor:t}}=this;t.setDoc(this.doc)}edit(){const{components:{commentEditor:t}}=this;t.edit()}destroy(){const{replyButton:t,moreButton:e,commentEditor:o,okButton:r,cancelButton:i}=this.components;e&&(e.onclick=null),t&&(t.onclick=null),r.onclick=null,i.onclick=null,o.destroy(),this.moreMenu.removeAllListeners(),this.moreMenu.destroy(),this.root.remove(),this.options.mainEditor.removeListener("readonlyChanged",this.handleReadonlyChanged)}}const Kz="";class N3{constructor(t,e,o){h(this,"root");h(this,"components");h(this,"reloadDoc",()=>{const{mobileCommentEditor:t}=this.components;t.setDoc(this.doc)});this.editor=t,this.commentsProvider=e,this.comment=o,this.root=b("div",["mobile-comment-item"],null),this.components=this.createItem()}get doc(){const{comment:t,commentsProvider:e}=this;return e.getCommentDoc(t.id)}createItem(){const{comment:t,editor:e,commentsProvider:o}=this,r=b("div",["item-head"],this.root),i=b("img",["item-head-avatar"],r);i.src=t.avatarUrl;const s=b("span",["item-head-username"],r);s.innerText=t.displayName;const l=b("span",["item-head-modified"],r),c=new Date(t.modified);l.innerText=pd(c);const a=b("div",["item-editor"],this.root),u=new cf(e,o,this.doc);return a.append(u.root),{mobileCommentEditor:u}}destroy(){this.root.remove(),this.components.mobileCommentEditor.destroy()}}const Jz="";class C_{constructor(t,e){h(this,"root");h(this,"countElement");h(this,"updateCount",t=>{this.countElement.textContent=`${t}`});this.root=b("div",["mini-comment-item"],e),this.root.id=t,this.countElement=b("span",["mini-comment-item-count"],this.root)}}class Js extends Yt.TypedEmitter{constructor(e,o,r,i,s){super();h(this,"_items");this.editor=e,this.commentsProvider=o,this.container=r,this.options=s,this._items=this.createList(i)}get items(){return this._items}createList(e){return e.map(r=>{const i=this.createItem(r,"init");return this.container.appendChild(i.root),i})}reloadList(e){this.container.innerHTML="",this.createList(e)}insertItem(e){const o=this.findInsertPos(e);if(o===-1)return null;const r=this.createItem(e,"insert");if(o===this.items.length)this.container.appendChild(r.root);else{const i=this.items[o];this.container.insertBefore(r.root,i.root)}return this.items.splice(o,0,r),r}deleteItem(e){const o=this.findItemIndex(e);if(o!==-1){const r=this.items[o];return this.items.splice(o,1),r.destroy(),!0}return!1}findItemIndex(e){return this.items.findIndex(o=>o.comment.id===e)}findItem(e){const o=this.findItemIndex(e);return o===-1?null:this.items[o]}destroy(){this._items.forEach(e=>e.destroy()),this._items=[]}}class b_ extends Js{constructor(t){const{editor:e,comments:o,commentsProvider:r,parent:i}=t;super(e,r,i,o,t)}createItem(t){const{editor:e,commentsProvider:o,groupList:r,groupItem:i}=this.options;return new _3({mainEditor:e,commentsProvider:o,comment:t,groupList:r,groupItem:i})}findInsertPos(){return this.items.length}destroy(){this.items.forEach(t=>{t.destroy()})}}const k_=`<svg width="17" height="16" viewBox="0 0 17 16" fill="none" xmlns="http://www.w3.org/2000/svg">
584
+ </svg>`,Qz="";B("comment-item");const{t:fi}=T,A3="comment-item-editing",O3="active";class _3{constructor(t){h(this,"root");h(this,"moreMenu");h(this,"components");h(this,"createRoot",()=>{const t=b("div",["comment-item-root"],null);return t.id=this.comment.id,t});h(this,"handleMore",()=>{const{moreButton:t}=this.components;!t||this.moreMenu.manualShow(t,{placement:"bottom-start"})});h(this,"handleMoreMenuItemShow",()=>{const{headTools:t}=this.components;t.classList.add(O3)});h(this,"handleMoreMenuItemClose",()=>{const{headTools:t}=this.components;t.classList.remove(O3)});h(this,"handleMoreMenuItemClick",(t,e)=>{const o=this.options.groupList.groupItemHandlers,{id:r}=e;r==="edit"&&o.handleCommentItemEdit(this),r==="delete"&&o.handleCommentItemDelete(this)});h(this,"handleEditorReadonlyChange",t=>{const{components:{actions:e},root:o}=this;t.readonly?(o.classList.remove(A3),e.classList.add("hidden")):(o.classList.add(A3),e.classList.remove("hidden"))});h(this,"handleFocus",()=>{const{components:{commentEditor:t,okButton:e}}=this;t.isEmpty()?A(e,Jn):z(e,Jn)});h(this,"handleDocChanged",()=>{const{commentEditor:t,okButton:e}=this.components;t.isEmpty()?A(e,Jn):z(e,Jn)});h(this,"getCommentEditor",()=>this.components.commentEditor);h(this,"handleReadonlyChanged",t=>{t.readonly?A(this.root,"readonly"):z(this.root,"readonly")});this.options=t,this.root=this.createRoot(),this.components=this.createItem(),this.moreMenu=this.createMoreMenu(),t.mainEditor.on("readonlyChanged",this.handleReadonlyChanged)}get commentOptions(){return this.options.mainEditor.getComponentOptions("comment")}get comment(){return this.options.comment}get doc(){const{comment:t,commentsProvider:e}=this.options;return e.getCommentDoc(t.id)}createMoreMenu(){const t=new nr([{id:"edit",name:fi("comment.edit")},{id:"delete",name:fi("comment.delete")}]);return t.on("click",this.handleMoreMenuItemClick),t.on("close",this.handleMoreMenuItemClose),t.on("show",this.handleMoreMenuItemShow),t}createItem(){var $,Z;const{comment:t,commentsProvider:e,mainEditor:o,groupItem:r}=this.options,i=!(($=this.commentOptions)!=null&&$.disableReply)&&!o.readonly,l=!((Z=this.commentOptions)!=null&&Z.disableEdit)&&!o.readonly&&i,c=b("div",["item-head"],this.root),a=b("img",["item-head-avatar"],c);a.src=t.avatarUrl;const u=b("span",["item-head-username"],c);u.innerText=t.displayName;const f=b("span",["item-head-modified"],c),m=new Date(t.modified);f.innerText=pd(m);const C=b("div",["item-head-tools"],c);let k=null;i&&(k=cr(C,ft.CommentItemReply,fi("comment.reply"),p_,void 0,o.clientId),Xn(k,ft.CommentItemReply));let w=null;l&&(w=cr(C,ft.CommentItemMore,fi("comment.more"),g_,void 0,o.clientId),Xn(w,ft.CommentItemMore),w.onclick=this.handleMore);const y=b("div",["item-editor"],this.root),S=new cf(o,e,this.doc);S.editor.addListener("readonlyChanged",this.handleEditorReadonlyChange),S.editor.addListener("docChanged",this.handleDocChanged),S.editor.addListener("focus",this.handleFocus),S.editor.input.addHandler(new m_(e,r,this)),y.append(S.root);const I=b("div",["item-actions","hidden"],this.root),M=yo(ft.CommentItemCancel,fi("common.cancel"));Xn(M,ft.CommentItemCancel);const R=yo(ft.CommentItemOk,fi("comment.send"));return Xn(R,ft.CommentItemOk),I.append(M,R),{head:c,replyButton:k,moreButton:w,commentEditor:S,okButton:R,cancelButton:M,actions:I,headTools:C}}reloadDoc(){const{components:{commentEditor:t}}=this;t.setDoc(this.doc)}edit(){const{components:{commentEditor:t}}=this;t.edit()}destroy(){const{replyButton:t,moreButton:e,commentEditor:o,okButton:r,cancelButton:i}=this.components;e&&(e.onclick=null),t&&(t.onclick=null),r.onclick=null,i.onclick=null,o.destroy(),this.moreMenu.removeAllListeners(),this.moreMenu.destroy(),this.root.remove(),this.options.mainEditor.removeListener("readonlyChanged",this.handleReadonlyChanged)}}const Kz="";class N3{constructor(t,e,o){h(this,"root");h(this,"components");h(this,"reloadDoc",()=>{const{mobileCommentEditor:t}=this.components;t.setDoc(this.doc)});this.editor=t,this.commentsProvider=e,this.comment=o,this.root=b("div",["mobile-comment-item"],null),this.components=this.createItem()}get doc(){const{comment:t,commentsProvider:e}=this;return e.getCommentDoc(t.id)}createItem(){const{comment:t,editor:e,commentsProvider:o}=this,r=b("div",["item-head"],this.root),i=b("img",["item-head-avatar"],r);i.src=t.avatarUrl;const s=b("span",["item-head-username"],r);s.innerText=t.displayName;const l=b("span",["item-head-modified"],r),c=new Date(t.modified);l.innerText=pd(c);const a=b("div",["item-editor"],this.root),u=new cf(e,o,this.doc);return a.append(u.root),{mobileCommentEditor:u}}destroy(){this.root.remove(),this.components.mobileCommentEditor.destroy()}}const Jz="";class C_{constructor(t,e){h(this,"root");h(this,"countElement");h(this,"updateCount",t=>{this.countElement.textContent=`${t}`});this.root=b("div",["mini-comment-item"],e),this.root.id=t,this.countElement=b("span",["mini-comment-item-count"],this.root)}}class Js extends Yt.TypedEmitter{constructor(e,o,r,i,s){super();h(this,"_items");this.editor=e,this.commentsProvider=o,this.container=r,this.options=s,this._items=this.createList(i)}get items(){return this._items}createList(e){return e.map(r=>{const i=this.createItem(r,"init");return this.container.appendChild(i.root),i})}reloadList(e){this.container.innerHTML="",this.createList(e)}insertItem(e){const o=this.findInsertPos(e);if(o===-1)return null;const r=this.createItem(e,"insert");if(o===this.items.length)this.container.appendChild(r.root);else{const i=this.items[o];this.container.insertBefore(r.root,i.root)}return this.items.splice(o,0,r),r}deleteItem(e){const o=this.findItemIndex(e);if(o!==-1){const r=this.items[o];return this.items.splice(o,1),r.destroy(),!0}return!1}findItemIndex(e){return this.items.findIndex(o=>o.comment.id===e)}findItem(e){const o=this.findItemIndex(e);return o===-1?null:this.items[o]}destroy(){this._items.forEach(e=>e.destroy()),this._items=[]}}class b_ extends Js{constructor(t){const{editor:e,comments:o,commentsProvider:r,parent:i}=t;super(e,r,i,o,t)}createItem(t){const{editor:e,commentsProvider:o,groupList:r,groupItem:i}=this.options;return new _3({mainEditor:e,commentsProvider:o,comment:t,groupList:r,groupItem:i})}findInsertPos(){return this.items.length}destroy(){this.items.forEach(t=>{t.destroy()})}}const k_=`<svg width="17" height="16" viewBox="0 0 17 16" fill="none" xmlns="http://www.w3.org/2000/svg">
585
585
  <path d="M2.00218 11.0005L8.00341 4.99923L14.0046 11.0005" stroke="currentColor" fill="transparent" stroke-width="1.5" stroke-linejoin="bevel"/>
586
586
  </svg>`,v_=`<svg width="17" height="16" viewBox="0 0 17 16" xmlns="http://www.w3.org/2000/svg">
587
587
  <path d="M14.0029 4.99933L8.00172 11.0006L2.00049 4.99933" stroke="currentColor" fill="transparent" stroke-width="1.5" stroke-linejoin="bevel"/>
588
- </svg>`,Xz="",va="reply-editor-editing",{t:af}=T;class y_{constructor(t,e,o,r){h(this,"root");h(this,"components");h(this,"handleFocus",()=>{const{replyEditor:t,okButton:e}=this.components;t.isEmpty()&&A(e,Jn)});h(this,"handleDocChange",()=>{const{replyEditor:t,okButton:e}=this.components,o=t.getDoc();ql(o)?A(e,Jn):z(e,Jn)});h(this,"getReplyEditor",()=>this.components.replyEditor);h(this,"showReplyEditor",()=>{nt(this.root,va)||(A(this.root,va),this.components.replyEditor.edit())});h(this,"hideReplyEditor",()=>{!nt(this.root,va)||z(this.root,va)});h(this,"reply",()=>{const{mainEditor:t,comment:e,components:{replyEditor:o},commentsProvider:r}=this,i=o.getDoc(),s=ka({editor:t,commentGroupId:e.groupId});r.localCreateComment(s,i),this.hideReplyEditor(),o.clear()});h(this,"cancel",()=>{const{replyEditor:t}=this.components;this.hideReplyEditor(),t.clear()});h(this,"hide",()=>{nt(this.root,"hidden")||A(this.root,"hidden")});h(this,"show",()=>{z(this.root,"hidden")});this.mainEditor=t,this.commentsProvider=e,this.comment=o,this.groupItem=r,this.root=b("div",["comment-quick-reply"],null),this.components=this.createQuickReply()}createQuickReply(){const{commentsProvider:t}=this,e=cr(this.root,ft.QuickReply,af("comment.placeholder"));Xn(e,ft.QuickReply),e.classList.add("quick-reply-button");const o=b("div",["quick-reply-editor"],this.root),r=Ko(),i=new cf(this.mainEditor,t,r);i.editor.addListener("docChanged",this.handleDocChange),i.editor.addListener("focus",this.handleFocus),i.editor.input.addHandler(new f_(this.groupItem)),o.append(i.root);const s=b("div",["reply-editor-actions"],o),l=vo(ft.QuickReplyCancel,af("common.cancel"));Xn(l,ft.QuickReplyCancel);const c=vo(ft.QuickReplyOk,af("comment.send"));return Xn(c,ft.QuickReplyOk),A(c,Jn),s.append(l,c),this.hideReplyEditor(),{replyTextButton:e,replyEditor:i,replyEditorContainer:o,okButton:c}}}const to=B("comment-group-item");class w_ extends Yt.TypedEmitter{constructor(e,o,r,i){super();h(this,"root");h(this,"header");h(this,"mainItem");h(this,"childrenList");h(this,"resizeObserver");h(this,"quickReply");h(this,"createRoot",()=>b("div",["comment-group-item-root"],null));h(this,"createChildrenList",()=>{const e=b("div",["comment-children-list-container"],this.root);return new b_({editor:this.editor,commentsProvider:this.commentsProvider,comments:this.comment.children,parent:e,groupList:this.groupList,groupItem:this})});h(this,"updateLastCommentItem",()=>{const e=Array.from(this.root.querySelectorAll(":scope .comment-item-root"));d(to,e.length!==0,"current group item not exist comment-item"),e.forEach(r=>{z(r,E3)});const o=e.at(-1);A(o,E3)});h(this,"updateSwitchButton",()=>{const e=this.root.querySelector(':scope .editor-text-button[group-item-action="switch-up"]'),o=this.root.querySelector(':scope .editor-text-button[group-item-action="switch-down"]');d(to,e,"switchUpButton not exist"),d(to,o,"switchDownButton not exist"),z(o,"disabled"),z(e,"disabled"),this.root.previousElementSibling===null&&A(e,"disabled"),this.root.nextElementSibling===null&&A(o,"disabled")});h(this,"handleReadonlyChanged",e=>{e.readonly?A(this.root,"readonly"):z(this.root,"readonly")});h(this,"handleResize",()=>{this.emit("resize")});this.editor=e,this.commentsProvider=o,this.comment=r,this.groupList=i,this.root=this.createRoot(),this.header=this.createHeader(),this.mainItem=this.createItem(),this.childrenList=this.createChildrenList(),this.quickReply=this.createQuickReply(),this.editor.on("readonlyChanged",this.handleReadonlyChanged),this.resizeObserver=new ResizeObserver(this.handleResize),this.resizeObserver.observe(this.root),this.updateLastCommentItem()}get commentCount(){return x3(this.root)}createQuickReply(){const{editor:e,commentsProvider:o,comment:r}=this,i=new y_(e,o,r,this);return this.root.append(i.root),i}createHeader(){const{comment:e}=this,o=b("div",["comment-item-head"],this.root),r=b("span",["item-head-quote"],o);r.innerText=e.abstract;const i=b("span",["item-head-switch"],o),s=cr(i,ft.SwitchUp,"up",k_),l=cr(i,ft.SwitchDown,"down",v_);return Xn(s,ft.SwitchUp),Xn(l,ft.SwitchDown),o}createItem(){const e=b("div",["comment-item-container"],this.root),{editor:o,commentsProvider:r,comment:i,groupList:s}=this,l=new _3({mainEditor:o,commentsProvider:r,comment:i,groupList:s,groupItem:this});return e.appendChild(l.root),l}findCommentItem(e){return e?e===this.mainItem.comment.id?this.mainItem:this.childrenList.items.find(o=>o.comment.id===e):null}handleCreateComment(e){return d(to,ur(e),"invalid comment, not a child comment"),d(to,e.groupId===this.comment.id,"invalid comment, not a child comment"),this.childrenList.createItem(e)}handleUpdateChildComment(e){d(to,e.groupId===this.mainItem.comment.id,"invalid child comment");const o=this.childrenList.findItem(e.id);if(!o){to.error(`can't find child comment item: ${e.id}`);return}o.reloadDoc()}handleUpdateMainComment(e){d(to,e.id===this.mainItem.comment.id,"invalid comment"),this.mainItem.reloadDoc()}deleteMainComment(e){d(to,e===this.mainItem.comment.id,"invalid comment"),this.mainItem.destroy()}edit(){this.mainItem.edit()}destroy(){this.mainItem.destroy(),this.childrenList.destroy(),this.root.remove(),this.resizeObserver.disconnect(),this.removeAllListeners(),this.editor.removeListener("readonlyChanged",this.handleReadonlyChanged)}}const B_=B("arrange=items"),$3=20;function P3(n,t){const e=n.rootContainer.querySelector(`[comment-${t.toLocaleLowerCase()}=${t}`);if(!e)return-1;const o=n.scrollContainer.getBoundingClientRect(),r=n.scrollContainer.scrollTop;return e.getBoundingClientRect().top-o.top+r}function j3(n,t){return Number.parseInt(t.root.style.top,10)}function H3(n,t,e,o){let r=0;e&&(r=t.indexOf(e),r===-1&&(r=0));for(let i=r;i<t.length;i++){const s=t[i],l=s.comment,c=P3(n,l.groupId);if(s.root.setAttribute("data-target-top",c.toString()),i===r){if(o!==void 0){const f=t[0];f.root.style.top=`${o}px`}else s.root.style.top=`${c}px`;continue}const a=t[i-1],u=j3(n,a)+a.root.getBoundingClientRect().height;u>c?s.root.style.top=`${u+$3}px`:s.root.style.top=`${c}px`}for(let i=r-1;i>=0;i--){const s=t[i],l=s.comment,c=P3(n,l.groupId);s.root.setAttribute("data-target-top",c.toString());const a=s.root.getBoundingClientRect(),u=c+a.height,f=t[i+1];d(B_,f,"no next item");const m=j3(n,f);m<u?s.root.style.top=`${m-a.height-$3}px`:s.root.style.top=`${c}px`}}const ya=B("comment-group-item-handler");class E_{constructor(t,e){h(this,"handleSwitchUp",t=>{const e=Math.max(0,t-1);this.groupList.setActiveItem(e),this.groupList.updateItemsLayout()});h(this,"handleSwitchDown",t=>{const e=Math.min(t+1,this.groupList.items.length);this.groupList.setActiveItem(e),this.groupList.updateItemsLayout()});h(this,"handleQuickReply",t=>{const{quickReply:e}=t;e.showReplyEditor()});h(this,"handleQuickReplyOk",t=>{const{quickReply:e}=t;e.reply(),t.updateLastCommentItem()});h(this,"handleQuickReplyCancel",t=>{const{quickReply:e}=t;e.cancel()});h(this,"handleCommentItemReply",(t,e)=>{const o=t.findCommentItem(e);d(ya,o,`the commentItem: ${e} not exist `);const{quickReply:r}=t;r.show(),r.showReplyEditor();const{comment:i}=o,s=r.getReplyEditor(),l=s.editor.getFocusedBlock(),c={type:"mention",id:N(),box:!0,created:Date.now(),text:i.displayName,iconUrl:i.avatarUrl,mentionId:i.userId};s.editor.insertBoxToBlock(l,0,c)});h(this,"handleCommentItemMore",t=>{const{quickReply:e}=t;e.hideReplyEditor(),e.getReplyEditor().clear()});h(this,"handleCommentItemOk",(t,e)=>{const o=t.findCommentItem(e);d(ya,o,`the commentItem: ${e} not exist `);const{quickReply:r}=t,{comment:i,getCommentEditor:s}=o,l=s(),c=l.getDoc();this.commentsProvider.localUpdateComment(i,c),l.readonly(),r.show()});h(this,"handleCommentItemCancel",(t,e)=>{const o=t.findCommentItem(e);d(ya,o,`the commentItem: ${e} not exist `);const r=this.commentsProvider.getComment(o.comment.id);if(ql(r.doc)){this.commentsProvider.localDeleteComment(o.comment.id);return}const{quickReply:i}=t,s=o.getCommentEditor();s.setDoc(o.doc),s.readonly(),i.show()});h(this,"handleCommentItemEdit",t=>{const e=this.groupList.findItem(t.comment.groupId);if(!e)return;const{quickReply:o}=e;t.getCommentEditor().edit(),o.hide()});h(this,"handleCommentItemDelete",t=>{const e=this.groupList.findItem(t.comment.groupId);if(!e)return;const{quickReply:o}=e,{comment:r}=t;this.commentsProvider.localDeleteComment(r.id),o.show()});h(this,"execute",(t,e,o,r)=>{const i=r_(t);if(!i||s_(i))return;const s=i_(i);switch(s){case ft.SwitchUp:this.handleSwitchUp(r);break;case ft.SwitchDown:this.handleSwitchDown(r);break;case ft.CommentItemReply:this.handleCommentItemReply(e,o);break;case ft.CommentItemMore:this.handleCommentItemMore(e);break;case ft.CommentItemOk:this.handleCommentItemOk(e,o);break;case ft.CommentItemCancel:this.handleCommentItemCancel(e,o);break;case ft.CommentItemDelete:break;case ft.CommentItemEdit:break;case ft.QuickReply:this.handleQuickReply(e);break;case ft.QuickReplyOk:this.handleQuickReplyOk(e);break;case ft.QuickReplyCancel:this.handleQuickReplyCancel(e);break;default:const l=s;ya.debug(`not implement handler for ${l}`)}});this.groupList=t,this.commentsProvider=e}destroy(){}}const wa=B("comment-group-list");class I_ extends Js{constructor(e,o,r){super(e,o,r,To(e,o),{});h(this,"groupItemHandlers");h(this,"findGroupItem",e=>this.items.find(o=>o.comment.groupId===e));h(this,"handleContainerClick",e=>{if(!e.target||!(e.target instanceof Element))return;const o=e.target.closest(".comment-group-item-root");if(!o)return;const r=o_(e.target),i=this.items.findIndex(s=>s.root===o);if(i!==-1){this.setActiveItem(i);const{groupItemHandlers:s}=this;s.execute(e.target,this.items.at(i),r,i)}});h(this,"handleSelectionChanged",()=>{const e=d_(this.editor);if(e.length>0){const o=e[0],r=this.items.findIndex(i=>i.comment.groupId===o);this.setActiveItem(r),this.emit("selectionOnComment")}else this.setActiveItem(-1)});h(this,"handleEditorResize",()=>{this.updateItemsLayout()});h(this,"handleDocChanged",()=>{this.updateComments()});h(this,"handleItemResize",()=>{this.updateItemsLayout()});h(this,"handleScroll",e=>{if(e.deltaY>=0||this.editor.scrollContainer.scrollTop!==0)return;const o=document.elementFromPoint(e.clientX,e.clientY);if(!o||!(o instanceof HTMLElement)||!this.editor.scrollContainer.contains(o))return;const r=this.container.querySelector(".comment-group-item-root");if(!r)return;const i=Number.parseFloat(r.style.top),s=Number.parseFloat(r.getAttribute("data-target-top")||"0");!Number.isNaN(i)&&!Number.isNaN(s)&&i<s&&H3(this.editor,this.items,null,Math.min(i+(0-e.deltaY)*3,s))});h(this,"updateGroupItemSwitch",()=>{const e=this.activeItem;d(wa,e,"invalid activeItem"),e.updateSwitchButton()});h(this,"updateComments",Xt.default(()=>{const e=To(this.editor,this.commentsProvider);let o=!1;for(let r=0;r<e.length;r++){const i=e[r];if(!this.findGroupItem(i.groupId)){this.handleCreateComment(i,!1),o=!0;continue}}for(let r=this.items.length-1;r>=0;r--){const i=this.items[r];e.findIndex(s=>s.groupId===i.comment.groupId)===-1&&(this.deleteItem(i.comment.id),o=!0)}o&&(this.updateItemsLayout(),this.emit("commentCountChanged"))},100));this.updateItemsLayout(),this.bindEvents(),this.editor.addListener("selectionChanged",this.handleSelectionChanged),this.editor.addListener("resize",this.handleEditorResize),this.editor.addListener("docChanged",this.handleDocChanged),this.editor.scrollContainer.addEventListener("wheel",this.handleScroll),this.items.forEach(i=>i.addListener("resize",this.handleItemResize)),this.groupItemHandlers=new E_(this,o)}destroy(){this.editor.removeListener("selectionChanged",this.handleSelectionChanged),this.editor.removeListener("resize",this.handleEditorResize),this.editor.removeListener("docChanged",this.handleDocChanged),this.editor.scrollContainer.removeEventListener("wheel",this.handleScroll),super.destroy(),this.unbindEvents(),this.removeAllListeners()}updateItemsLayout(){H3(this.editor,this.items,this.activeItem)}bindEvents(){this.container.addEventListener("click",this.handleContainerClick)}unbindEvents(){this.container.removeEventListener("click",this.handleContainerClick)}createItem(e,o){const r=new w_(this.editor,this.commentsProvider,e,this);return o==="insert"&&(A(r.root,"no-animation"),r.root.style.opacity="0",setTimeout(()=>{z(r.root,"no-animation"),r.root.style.opacity="1"},150)),r}findInsertPos(e){const r=To(this.editor,this.commentsProvider).findIndex(i=>i.id===e.id);return r===-1||r>this.items.length?-1:r}insertItem(e){const o=super.insertItem(e);return o?(this.setActiveItem(this.items.indexOf(o)),this.updateItemsLayout(),o.addListener("resize",this.handleItemResize),o):null}setActiveItem(e){if(d(wa,e>=-1&&e<this.items.length,`invalid index: ${e}`),e===this.activeIndex)return;const o=this.container.querySelector(".comment-group-item-root.active");if(o&&z(o,"active"),e!==-1){const r=this.items[e];A(r.root,"active"),this.updateItemsLayout(),this.updateGroupItemSwitch()}this.emit("activeItemChanged",e)}get activeIndex(){const e=this.container.querySelector(".comment-group-item-root.active");return e?this.items.findIndex(o=>o.root===e):-1}get activeItem(){const e=this.activeIndex;return e===-1?null:this.items[e]}handleCreateComment(e,o){if(ur(e)){const l=this.findGroupItem(e.groupId);l&&l.childrenList.insertItem(e)}const r=this.findItem(e.id);d(wa,!r,"comment group item has already exists");const i={children:[],...e};d(wa,i.children,"not a comment group");const s=this.insertItem(i);!s||o&&setTimeout(()=>{const l=this.items.indexOf(s);this.setActiveItem(l),s.edit(),s.quickReply.hide()})}handleDeleteComment(e){for(let o=0;o<this.items.length;o++){const r=this.items[o];if(r.comment.id===e){r.childrenList.items.length===0?this.deleteItem(r.comment.id):r.deleteMainComment(e);return}if(r.childrenList.deleteItem(e)){r.commentCount===0&&this.deleteItem(r.comment.id);return}}}handleUpdateComment(e){if(ur(e)){const r=this.commentsProvider.getComment(e.groupId),i=this.findItem(r.id);i&&i.handleUpdateChildComment(e);return}const o=this.findItem(e.id);o&&o.handleUpdateMainComment(e)}}const x_="comment-mini";B("comment-list");class T_ extends Yt.TypedEmitter{constructor(e,o,r){super();h(this,"root");h(this,"groupsContainer");h(this,"list");h(this,"handleSelectionOnComment",()=>{this.emit("onSelectComment")});h(this,"updateCommentCount",()=>{var o,r;const e=a_(this.editor,this.commentsProvider);(r=(o=this.commentOptions)==null?void 0:o.onCommentCountChange)==null||r.call(o,e)});h(this,"handleActiveItemChanged",()=>{var o;const e=this.list.activeItem;R3(this.editor,(o=e==null?void 0:e.comment.id)!=null?o:"")});h(this,"handleItemLayoutUpdated",()=>{var o,r;const e=nt(this.root,x_);(r=(o=this.commentOptions)==null?void 0:o.onUpdateLayout)==null||r.call(o,this.editor,{expand:e})});this.editor=e,this.commentsProvider=o,this.root=b("div",["editor-web-comment-root"],r),this.groupsContainer=b("div",["comment-groups-container"],this.root),this.list=this.createList(),this.commentsProvider.addListener(this),this.list.addListener("activeItemChanged",this.handleActiveItemChanged),this.list.addListener("itemLayoutUpdated",this.handleItemLayoutUpdated),this.list.addListener("selectionOnComment",this.handleSelectionOnComment),this.list.addListener("commentCountChanged",this.updateCommentCount),this.updateCommentCount()}get commentOptions(){return this.editor.getComponentOptions("comment")}destroy(){this.list.removeAllListeners(),this.commentsProvider.removeListener(this),this.list.destroy(),this.root.remove()}onCreateComment(e,o){const r=this.commentsProvider.getComment(e);this.list.handleCreateComment(r,o),this.updateCommentCount()}onDeleteComment(e,o){this.list.handleDeleteComment(e),this.updateCommentCount()}onUpdateComment(e,o){const r=this.commentsProvider.getComment(e);this.list.handleUpdateComment(r)}createList(){return new I_(this.editor,this.commentsProvider,this.groupsContainer)}show(e){var o;if(z(this.root,"hidden"),e){const r=this.list.findItemIndex(e);this.list.setActiveItem(r)}(o=this.commentOptions)==null||o.controller.showCommentList()}hide(){A(this.root,"hidden")}}class S_ extends Js{constructor({editor:t,parent:e,commentsProvider:o,comments:r}){super(t,o,e,r,{})}findInsertPos(){return this.items.length}createItem(t){const{editor:e,commentsProvider:o}=this;return new N3(e,o,t)}destroy(){this.items.forEach(t=>{t.destroy()})}}const Ba=B("mobile-comment-group-item"),D_=20;class L_ extends Yt.TypedEmitter{constructor(e,o,r){super();h(this,"root");h(this,"childrenList");h(this,"mainItem");h(this,"scroller");h(this,"createRoot",()=>b("div",["mobile-group-item-root"],null));h(this,"createMainItem",e=>{const{editor:o,commentsProvider:r,comment:i}=this,s=new N3(o,r,i);return e.append(s.root),s});h(this,"createChildrenList",e=>{const{editor:o,commentsProvider:r,comment:i}=this,s=b("div",["mobile-comment-children-list-container"],e);return new S_({editor:o,commentsProvider:r,comments:i.children,parent:s})});h(this,"handleTouchEnd",()=>{var i;const{scroller:e}=this,{pullThreshold:o=D_}=(i=this.editor.getComponentOptions("comment"))!=null?i:{};let r=null;if(e.y>e.minScrollY+o?(r=this.root.previousElementSibling,r||this.emit("onReachTop")):e.y<e.maxScrollY-o&&(r=this.root.nextElementSibling,r||this.emit("onReachBottom")),r){const s=r.id;this.emit("onSwitchGroup",s,I3)}});h(this,"refreshScroller",()=>{this.scroller.refresh()});this.editor=e,this.commentsProvider=o,this.comment=r,this.root=b("div",["mobile-group-item-root"],null),this.root.id=r.groupId;const i=b("div",["mobile-group-item"],this.root),s=b("div",["mobile-group-item-space"],null),l=b("div",["mobile-group-item-abstract"],null);l.textContent=r.abstract;const c=b("div",["mobile-group-item-list-container"],null);this.mainItem=this.createMainItem(c),this.childrenList=this.createChildrenList(c),i.append(s,l,c),this.scroller=new Xf.default(this.root,{stopPropagation:!0,click:!0}),this.scroller.on("touchEnd",this.handleTouchEnd)}get commentCount(){return x3(this.root,".mobile-group-item")}handleUpdateChildComment(e){d(Ba,e.groupId===this.mainItem.comment.id,"invalid child comment");const o=this.childrenList.findItem(e.id);if(!o){Ba.error(`can't find child comment item: ${e.id}`);return}o.reloadDoc()}handleUpdateMainComment(e){d(Ba,e.id===this.mainItem.comment.id,"invalid comment"),this.mainItem.reloadDoc()}deleteMainComment(e){d(Ba,e===this.mainItem.comment.id,"invalid comment"),this.mainItem.destroy()}destroy(){this.mainItem.destroy(),this.childrenList.destroy(),this.scroller.off("touchEnd",this.handleTouchEnd),this.scroller.destroy(),this.root.remove(),this.removeAllListeners()}}const df=B("mobile-group-list");class M_ extends Js{constructor(e,o,r,i){super(e,o,r,To(e,o),{});h(this,"scroller");h(this,"deleteItem",e=>{if(this.items.length<=1)return super.deleteItem(e);const o=this.findItemIndex(e);let r=null;return o===0?r=this.items[o+1].root.id:r=this.items[o-1].root.id,super.deleteItem(e)?(this.scrollToGroup(r,I3),!0):!1});h(this,"setupGroupItem",e=>{e.on("onSwitchGroup",this.scrollToGroup),e.on("onReachBottom",this.handleReachBottom),e.on("onReachTop",this.handleReachTop),e.refreshScroller()});h(this,"handleReachBottom",()=>{this.emit("onReachBottom")});h(this,"handleReachTop",()=>{this.emit("onReachTop")});h(this,"scrollToGroup",(e,o=0)=>{const r=this.findGroupItem(e);d(df,r,"invalid scroll target"),this.scroller.scrollToElement(r.root,o,!1,!1),R3(this.editor,r.comment.id)});h(this,"findGroupItem",e=>this.items.find(o=>o.comment.groupId===e));h(this,"handleDocChanged",()=>{this.updateComments()});h(this,"updateComments",Xt.default(()=>{const e=To(this.editor,this.commentsProvider);for(let o=0;o<e.length;o++){const r=e[o];if(!this.findGroupItem(r.groupId)){this.handleCreateComment(r,!1);continue}}for(let o=this.items.length-1;o>=0;o--){const r=this.items[o];e.findIndex(i=>i.groupId===r.comment.groupId)===-1&&this.deleteItem(r.comment.id)}},100));this.scroller=new Xf.default(i),this.scroller.disable(),this.editor.addListener("docChanged",this.handleDocChanged),this.items.forEach(this.setupGroupItem)}createItem(e){return new L_(this.editor,this.commentsProvider,e)}insertItem(e){const o=super.insertItem(e);return o?(this.setupGroupItem(o),o):null}findInsertPos(e){const r=To(this.editor,this.commentsProvider).findIndex(i=>i.id===e.id);return r===-1||r>this.items.length?-1:r}setActiveItem(e){this.scrollToGroup(e)}handleCreateComment(e,o){if(ur(e)){const s=this.findGroupItem(e.groupId);s&&s.childrenList.insertItem(e)}const r=this.findItem(e.id);d(df,!r,"comment group item has already exists");const i={children:[],...e};d(df,i.children,"not a comment group"),this.insertItem(i),this.scroller.refresh()}handleDeleteComment(e){for(let o=0;o<this.items.length;o++){const r=this.items[o];if(r.comment.id===e){r.childrenList.items.length===0?this.deleteItem(r.comment.id):r.deleteMainComment(e);return}if(r.childrenList.deleteItem(e)){r.commentCount===0&&this.deleteItem(r.comment.id);return}}}handleUpdateComment(e){if(ur(e)){const r=this.commentsProvider.getComment(e.groupId),i=this.findItem(r.id);i&&i.handleUpdateChildComment(e);return}const o=this.findItem(e.id);o&&o.handleUpdateMainComment(e)}destroy(){this.editor.removeListener("docChanged",this.handleDocChanged),this.scroller.destroy(),this.items.forEach(e=>e.destroy())}}const R_=B("mobile-comment-list"),{t:F3}=T;class A_ extends Yt.TypedEmitter{constructor(e,o,r){super();h(this,"root");h(this,"list");h(this,"mask");h(this,"pullInfoContainer");h(this,"handleRootClick",e=>{const o=e.target;d(R_,o instanceof Element,"invalid target"),!(o.closest(".mobile-group-item-abstract")||o.closest(".mobile-group-item-list-container"))&&(this.hide(),this.emit("onCommentListClose"))});h(this,"hidePullInfo",Xt.default(()=>{z(this.pullInfoContainer,"active")},1e3*3));h(this,"handleReachBottom",()=>{this.showPullInfo("bottom")});h(this,"handleReachTop",()=>{this.showPullInfo("top")});h(this,"show",e=>{z(this.root,"hidden"),A(document.documentElement,"disabled-scroll"),e&&this.list.setActiveItem(e)});h(this,"hide",()=>{A(this.root,"hidden"),z(document.documentElement,"disabled-scroll")});this.editor=e,this.commentsProvider=o,this.root=b("div",["editor-mobile-comments-root"],r),this.mask=b("div",["mobile-comment-mask"],this.root);const i=b("div",["mobile-comment-groups-container"],this.root),s=b("div",["mobile-comment-groups-scroll-container"],i);this.list=new M_(this.editor,this.commentsProvider,s,i),this.pullInfoContainer=this.createPullInfo(),this.commentsProvider.addListener(this),this.list.on("onReachBottom",this.handleReachBottom),this.list.on("onReachTop",this.handleReachTop),this.root.onclick=this.handleRootClick}onCreateComment(e,o){const r=this.commentsProvider.getComment(e);this.list.handleCreateComment(r,o)}onDeleteComment(e,o){this.list.handleDeleteComment(e)}onUpdateComment(e,o){const r=this.commentsProvider.getComment(e);this.list.handleUpdateComment(r)}createPullInfo(){const e=b("div",["mobile-comment-pull-info-container"],this.root);return b("div",["mobile-comment-pull-info"],e),e}showPullInfo(e){const o=F3(e==="bottom"?"comment.isLast":"comment.isFirst");this.pullInfoContainer.firstElementChild.textContent=o,A(this.pullInfoContainer,"active"),this.hidePullInfo()}destroy(){this.list.removeAllListeners(),this.list.destroy(),this.root.onclick=null}}function z3(n,t){const e=To(n,t),o=new Map;for(const r of e){const i=T3(n,r.groupId);if(!!i)if(o.has(i)){const s=o.get(i);rf(r).forEach(c=>{s==null||s.commentIds.add(c.id)})}else{const s=rf(r),l=new Set(s.map(c=>c.id));o.set(i,{commentIds:l,firstComment:r})}}return Array.from(o.entries()).map(([r,i])=>({blockId:r,...i}))}const O_=B("mini-group-item");class __{constructor(t,e){h(this,"root");h(this,"blockId");h(this,"comment");h(this,"miniCommentItem");h(this,"updateCommentItemCount",()=>{this.miniCommentItem.updateCount(this.commentCount)});this.editor=t,this.commentGroup=e,this.root=b("div",["mini-group-item"],null),this.comment=e.firstComment,this.miniCommentItem=new C_(this.comment.id,this.root),this.blockId=this.getBlockId(),this.alignToBlock(),this.updateCommentItemCount()}getBlockId(){return T3(this.editor,this.comment.groupId)}get commentCount(){return this.commentGroup.commentIds.size}alignToBlock(){const t=this.getBlockId(),e=this.editor.getBlockById(t);d(O_,e,`The blockId: ${t} not exist in doc`);const o=this.editor.scrollContainer.getBoundingClientRect(),i=e.getBoundingClientRect().top-o.top;requestAnimationFrame(()=>{this.root.style.transform=`translateY(${i}px)`})}destroy(){this.root.remove()}}class N_ extends Js{constructor(e,o,r){super(e,o,r,z3(e,o),{});h(this,"handleDocChanged",Xt.default(()=>{this.updateMiniCommentsGroup()},100));h(this,"updateMiniCommentsGroup",()=>{const e=z3(this.editor,this.commentsProvider);this.reloadList(e)});this.editor=e,this.commentsProvider=o,this.editor.addListener("docChanged",this.handleDocChanged)}createItem(e){return new __(this.editor,e)}findInsertPos(){return-1}handleCreateComment(e,o){this.updateMiniCommentsGroup()}handleDeleteComment(e){this.updateMiniCommentsGroup()}destroy(){this.editor.removeListener("docChanged",this.handleDocChanged),super.destroy(),this.removeAllListeners()}}const $_=B("mini-comments-list");class P_ extends Yt.TypedEmitter{constructor(e,o,r){super();h(this,"list");h(this,"root");h(this,"createList",()=>{const e=b("div",["comment-groups-container"],this.root);return this.editor.domEvents.addEventListener(e,"click",this.handleListContainerClick),new N_(this.editor,this.commentsProvider,e)});h(this,"handleListContainerClick",(e,o)=>{const r=o.target;d($_,r instanceof HTMLElement,"The target is not a valid html element");const i=r.closest(".mini-comment-item");i&&this.emit("onItemClick",i.id)});this.editor=e,this.commentsProvider=o,this.root=b("div",["editor-mini-comment-root"],r),this.list=this.createList(),this.commentsProvider.addListener(this)}onCreateComment(e,o){const r=this.commentsProvider.getComment(e);this.list.handleCreateComment(r,o)}onDeleteComment(e,o){this.list.handleDeleteComment(e)}onUpdateComment(e,o){}show(){z(this.root,"hidden")}hide(){A(this.root,"hidden")}destroy(){this.list.destroy(),this.removeAllListeners()}}function U3(n,t,e){if(!t.start.isSimple()||!t.end.isSimple())return;const o=t.block,r=At(n,o,t.start.offset,t.end.offset),i=`comment-${e.id.toLocaleLowerCase()}`,s=e.id;Wp(n,o,r,i,s)}function j_(n,t,e){const o=tn(n).map(s=>s.block),r=ef(n,o),i=ka({editor:n,abstract:r});return n.undoManager.runInGroup(()=>{tn(n,{simpleBlockOnly:!0}).forEach(c=>{!P(n,c.block)||U3(n,c,i)});const l=Ko();e.localCreateComment(i,l)}),i}class H_{constructor(t,e){h(this,"id","CommentsCommandProvider");this.provider=t,this.editorComments=e}getAvailableCommands(t,e,o){const r=t.selection.range;if(P(t,e)&&!o.isCollapsed()&&r.isSimple()){const i=q(e),s=ot(e),l=Qe(t,e);return[{id:"add-comment",name:"Add comment",blockId:i,blockType:s,blockKind:l,groupIndex:1e3,icon:wc}]}return[]}executeRangeCommand(t,e,o,r,i){if(o.id==="add-comment"){this.editorComments.showCommentList();const s=j_(t,e,this.provider);return i["add-comment"]=s,!0}return!1}}class V3{constructor(t,e){h(this,"commentList",null);h(this,"mobileCommentList",null);h(this,"miniCommentList");h(this,"showComment",(t,e)=>{var o,r;t==="mini"&&this.miniCommentList.show(),t==="mobile"&&((o=this.mobileCommentList)==null||o.show(e)),t==="web"&&((r=this.commentList)==null||r.show(e))});h(this,"showCommentList",t=>{this.isMobile?this.showComment("mobile",t):this.showComment("web",t)});h(this,"handleCommentListClose",()=>{this.showComment("mini")});h(this,"handleOnSelectComment",()=>{this.showComment("web")});h(this,"handleMiniCommentItemClick",t=>{this.showCommentList(t)});this.editor=t,this.provider=e,t.editorCommandProviders.registerCommandProvider(new H_(e,this)),t.blockHooks.push(new n_(this.provider,this)),this.isMobile?(this.mobileCommentList=new A_(this.editor,this.provider,this.getCommentRoot("mobileContainer")),this.mobileCommentList.on("onCommentListClose",this.handleCommentListClose)):(this.commentList=new T_(this.editor,this.provider,this.getCommentRoot("container")),this.commentList.on("onSelectComment",this.handleOnSelectComment)),this.miniCommentList=new P_(this.editor,this.provider,this.getCommentRoot("miniContainer")),this.miniCommentList.on("onItemClick",this.handleMiniCommentItemClick)}get commentOptions(){return this.editor.getComponentOptions("comment")}get commentProvider(){return this.provider}get isMobile(){return xt.isMobile}getCommentRoot(t){var e,o;return(o=(e=this.commentOptions)==null?void 0:e[t])!=null?o:document.body}destroy(){var t,e;(t=this.commentList)==null||t.destroy(),(e=this.mobileCommentList)==null||e.destroy(),this.miniCommentList.destroy()}}const tU="",F_={comment:{count:"\u6279\u6CE8 ({num})",hide:"\u9690\u85CF\u6279\u6CE8",show:"\u663E\u793A\u6279\u6CE8",reply:"\u56DE\u590D",quicklyReply:"\u56DE\u590D...",send:"\u786E\u8BA4",placeholder:"\u6DFB\u52A0\u6279\u6CE8...",replyPlaceholder:"\u56DE\u590D\u6216@\u4ED6\u4EBA",edit:"\u7F16\u8F91",delete:"\u5220\u9664",image:"\u56FE\u7247",sendTitle:"\u6309Enter\u53D1\u9001\u6279\u6CE8",replyTitle:"\u6309Enter\u56DE\u590D\u6279\u6CE8",isFirst:"\u5DF2\u7ECF\u662F\u7B2C\u4E00\u6761\u6279\u6CE8",isLast:"\u5DF2\u7ECF\u662F\u6700\u540E\u4E00\u6761\u6279\u6CE8",comment:"\u6279\u6CE8"}},z_={comment:{count:"Comments ({num})",hide:"Hide Comments",show:"Show Comments",reply:"Reply",quicklyReply:"Reply...",send:"OK",placeholder:"Add a comment...",replyPlaceholder:"Add Comments or @ others",edit:"Edit",delete:"Delete",image:"Image",sendTitle:"Press Enter to send comment",replyTitle:"Press Enter to reply comment",isFirst:"\u5DF2\u7ECF\u662F\u7B2C\u4E00\u6761\u6279\u6CE8",isLast:"\u5DF2\u7ECF\u662F\u6700\u540E\u4E00\u6761\u6279\u6CE8",more:"more",comment:"Comment"}},U_={comment:{count:"\u30B3\u30E1\u30F3\u30C8 ({num})",hide:"\u30B3\u30E1\u30F3\u30C8\u3092\u975E\u8868\u793A",show:"\u30B3\u30E1\u30F3\u30C8\u3092\u8868\u793A",reply:"\u8FD4\u4FE1",quicklyReply:"\u8FD4\u4FE1...",send:"\u9001\u4FE1",placeholder:"\u30B3\u30E1\u30F3\u30C8\u3092\u8FFD\u52A0...",replyPlaceholder:"\u8FD4\u4FE1\u307E\u305F\u306F\u30E1\u30F3\u30B7\u30E7\u30F3(@)",edit:"\u7DE8\u96C6",delete:"\u524A\u9664",image:"\u753B\u50CF",sendTitle:"Enter\u3092\u62BC\u3057\u3066\u30B3\u30E1\u30F3\u30C8\u3092\u9001\u4FE1",replyTitle:"Enter\u3092\u62BC\u3057\u3066\u30B3\u30E1\u30F3\u30C8\u3092\u8FD4\u4FE1",isFirst:"\u6700\u521D\u306E\u30B3\u30E1\u30F3\u30C8\u3067\u3059",isLast:"\u6700\u5F8C\u306E\u30B3\u30E1\u30F3\u30C8\u3067\u3059",comment:"\u30B3\u30E1\u30F3\u30C8\u3092"}};T.mergeLang({"zh-CN":F_,"en-US":z_,"ja-JP":U_});class q3{renderText(t,e,o){const r=[],i={};return Object.entries(o).forEach(([s,l])=>{s.startsWith("comment-")&&(r.push("comment"),i[s]=l)}),{classes:r,attributes:i}}renderBlock(t,e,o){const r=o.comments;if(!r||r.length===0)return{};const i=["comment"],s={};return r.forEach(l=>{s[`comment-${l.toLocaleLowerCase()}`]=l}),{classes:i,attributes:s}}updateBlock(t,e,o,r){const i=r.comments;z(o,"comment"),Array.from(o.attributes).forEach(s=>{s.name.startsWith("comment-")&&o.removeAttribute(s.name)}),!(!i||i.length===0)&&(A(o,"comment"),i.forEach(s=>{o.setAttribute(`comment-${s.toLocaleLowerCase()}`,s)}))}}class V_{constructor(t){h(this,"handleUpdateCompositionText",(t,e,o,r,i)=>{const s=t.getFocusedBlock(),l=t.getFirstBlock();s===l&&this.applyPlaceholder(t)});h(this,"handleSelectionChange",t=>{this.applyPlaceholder(t)});h(this,"applyPlaceholder",t=>{const e=t.getFirstBlock();na(t,e,T.t("comment.replyPlaceholder"))});this.applyPlaceholder(t),t.addListener("selectionChanged",this.handleSelectionChange)}}function q_(n,t,e){const o=n.getBlockData(t),r=o.comments;if((r==null?void 0:r.indexOf(e))!==-1){const s=new Set(r);s.delete(e),n.updateBlockData(t,{comments:Array.from(s)})}const i=o.text;if(!!i&&P(n,t)){const s=Yd(i,`comment-${e.toLocaleLowerCase()}`,e);n.setBlockText(t,s)}}const W_=B("editor-comment");function G_(n){const t=n.getCustom("editor-comments");if(d(W_,t,"the editor comment not exist"),t.showCommentList(),n.selection.range.isCollapsed()){const s=n.selection.startBlock,l=Vo(s);if(l.length>=2){const{containerId:c}=l.at(-1),a=F(Er(n,c));if(a&&ot(a)==="code"){nf(n,a,t.commentProvider);return}}nf(n,s,t.commentProvider);return}const e=tn(n,{simpleBlockOnly:!0}),o=e.map(s=>s.block),r=ef(n,o),i=ka({editor:n,abstract:r});n.undoManager.runInGroup(()=>{e.forEach(l=>{P(n,l.block)?U3(n,l,i):B3(n,l.block,i)});const s=Ko();t.commentProvider.localCreateComment(i,s)})}const uf=B("text-styles");function Z_(n){const t=o=>{if(!o.attributes)return new Map;const r=Object.entries(o.attributes).filter(([i])=>!!i.startsWith("style-"));return new Map(r)};if(n.length===0)return new Map;let e=t(n[0]);for(let o=1;o<n.length;o++){const r=t(n[o]);e=new Map(Array.from(e.entries()).filter(([i,s])=>r.get(i)===s))}return e}function Y_(n,t,e,o,r){d(uf,e.isSimple(),"invalid range");const{start:i,end:s}=e;d(uf,i.blockId===s.blockId&&i.blockId===q(t),"invalid range"),d(uf,o.startsWith("style-"),"invalid style");let c=n.getBlockText(t);return o==="style-subscript"?c=Sr(i.offset,s.offset-i.offset,c,"style-superscript",void 0,{ignoreValue:!0}):o==="style-superscript"&&(c=Sr(i.offset,s.offset-i.offset,c,"style-subscript",void 0,{ignoreValue:!0})),r===!1||r===void 0||r===null?c=Sr(i.offset,s.offset-i.offset,c,o,void 0,{ignoreValue:!0}):c=Vi(i.offset,s.offset-i.offset,c,o,r),n.setBlockText(t,c),c}const Q_=`<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
588
+ </svg>`,Xz="",va="reply-editor-editing",{t:af}=T;class y_{constructor(t,e,o,r){h(this,"root");h(this,"components");h(this,"handleFocus",()=>{const{replyEditor:t,okButton:e}=this.components;t.isEmpty()&&A(e,Jn)});h(this,"handleDocChange",()=>{const{replyEditor:t,okButton:e}=this.components,o=t.getDoc();ql(o)?A(e,Jn):z(e,Jn)});h(this,"getReplyEditor",()=>this.components.replyEditor);h(this,"showReplyEditor",()=>{nt(this.root,va)||(A(this.root,va),this.components.replyEditor.edit())});h(this,"hideReplyEditor",()=>{!nt(this.root,va)||z(this.root,va)});h(this,"reply",()=>{const{mainEditor:t,comment:e,components:{replyEditor:o},commentsProvider:r}=this,i=o.getDoc(),s=ka({editor:t,commentGroupId:e.groupId});r.localCreateComment(s,i),this.hideReplyEditor(),o.clear()});h(this,"cancel",()=>{const{replyEditor:t}=this.components;this.hideReplyEditor(),t.clear()});h(this,"hide",()=>{nt(this.root,"hidden")||A(this.root,"hidden")});h(this,"show",()=>{z(this.root,"hidden")});this.mainEditor=t,this.commentsProvider=e,this.comment=o,this.groupItem=r,this.root=b("div",["comment-quick-reply"],null),this.components=this.createQuickReply()}createQuickReply(){const{commentsProvider:t}=this,e=cr(this.root,ft.QuickReply,af("comment.placeholder"));Xn(e,ft.QuickReply),e.classList.add("quick-reply-button");const o=b("div",["quick-reply-editor"],this.root),r=Ko(),i=new cf(this.mainEditor,t,r);i.editor.addListener("docChanged",this.handleDocChange),i.editor.addListener("focus",this.handleFocus),i.editor.input.addHandler(new f_(this.groupItem)),o.append(i.root);const s=b("div",["reply-editor-actions"],o),l=yo(ft.QuickReplyCancel,af("common.cancel"));Xn(l,ft.QuickReplyCancel);const c=yo(ft.QuickReplyOk,af("comment.send"));return Xn(c,ft.QuickReplyOk),A(c,Jn),s.append(l,c),this.hideReplyEditor(),{replyTextButton:e,replyEditor:i,replyEditorContainer:o,okButton:c}}}const to=B("comment-group-item");class w_ extends Yt.TypedEmitter{constructor(e,o,r,i){super();h(this,"root");h(this,"header");h(this,"mainItem");h(this,"childrenList");h(this,"resizeObserver");h(this,"quickReply");h(this,"createRoot",()=>b("div",["comment-group-item-root"],null));h(this,"createChildrenList",()=>{const e=b("div",["comment-children-list-container"],this.root);return new b_({editor:this.editor,commentsProvider:this.commentsProvider,comments:this.comment.children,parent:e,groupList:this.groupList,groupItem:this})});h(this,"updateLastCommentItem",()=>{const e=Array.from(this.root.querySelectorAll(":scope .comment-item-root"));d(to,e.length!==0,"current group item not exist comment-item"),e.forEach(r=>{z(r,E3)});const o=e.at(-1);A(o,E3)});h(this,"updateSwitchButton",()=>{const e=this.root.querySelector(':scope .editor-text-button[group-item-action="switch-up"]'),o=this.root.querySelector(':scope .editor-text-button[group-item-action="switch-down"]');d(to,e,"switchUpButton not exist"),d(to,o,"switchDownButton not exist"),z(o,"disabled"),z(e,"disabled"),this.root.previousElementSibling===null&&A(e,"disabled"),this.root.nextElementSibling===null&&A(o,"disabled")});h(this,"handleReadonlyChanged",e=>{e.readonly?A(this.root,"readonly"):z(this.root,"readonly")});h(this,"handleResize",()=>{this.emit("resize")});this.editor=e,this.commentsProvider=o,this.comment=r,this.groupList=i,this.root=this.createRoot(),this.header=this.createHeader(),this.mainItem=this.createItem(),this.childrenList=this.createChildrenList(),this.quickReply=this.createQuickReply(),this.editor.on("readonlyChanged",this.handleReadonlyChanged),this.resizeObserver=new ResizeObserver(this.handleResize),this.resizeObserver.observe(this.root),this.updateLastCommentItem()}get commentCount(){return x3(this.root)}createQuickReply(){const{editor:e,commentsProvider:o,comment:r}=this,i=new y_(e,o,r,this);return this.root.append(i.root),i}createHeader(){const{comment:e}=this,o=b("div",["comment-item-head"],this.root),r=b("span",["item-head-quote"],o);r.innerText=e.abstract;const i=b("span",["item-head-switch"],o),s=cr(i,ft.SwitchUp,"up",k_),l=cr(i,ft.SwitchDown,"down",v_);return Xn(s,ft.SwitchUp),Xn(l,ft.SwitchDown),o}createItem(){const e=b("div",["comment-item-container"],this.root),{editor:o,commentsProvider:r,comment:i,groupList:s}=this,l=new _3({mainEditor:o,commentsProvider:r,comment:i,groupList:s,groupItem:this});return e.appendChild(l.root),l}findCommentItem(e){return e?e===this.mainItem.comment.id?this.mainItem:this.childrenList.items.find(o=>o.comment.id===e):null}handleCreateComment(e){return d(to,ur(e),"invalid comment, not a child comment"),d(to,e.groupId===this.comment.id,"invalid comment, not a child comment"),this.childrenList.createItem(e)}handleUpdateChildComment(e){d(to,e.groupId===this.mainItem.comment.id,"invalid child comment");const o=this.childrenList.findItem(e.id);if(!o){to.error(`can't find child comment item: ${e.id}`);return}o.reloadDoc()}handleUpdateMainComment(e){d(to,e.id===this.mainItem.comment.id,"invalid comment"),this.mainItem.reloadDoc()}deleteMainComment(e){d(to,e===this.mainItem.comment.id,"invalid comment"),this.mainItem.destroy()}edit(){this.mainItem.edit()}destroy(){this.mainItem.destroy(),this.childrenList.destroy(),this.root.remove(),this.resizeObserver.disconnect(),this.removeAllListeners(),this.editor.removeListener("readonlyChanged",this.handleReadonlyChanged)}}const B_=B("arrange=items"),$3=20;function P3(n,t){const e=n.rootContainer.querySelector(`[comment-${t.toLocaleLowerCase()}=${t}`);if(!e)return-1;const o=n.scrollContainer.getBoundingClientRect(),r=n.scrollContainer.scrollTop;return e.getBoundingClientRect().top-o.top+r}function j3(n,t){return Number.parseInt(t.root.style.top,10)}function H3(n,t,e,o){let r=0;e&&(r=t.indexOf(e),r===-1&&(r=0));for(let i=r;i<t.length;i++){const s=t[i],l=s.comment,c=P3(n,l.groupId);if(s.root.setAttribute("data-target-top",c.toString()),i===r){if(o!==void 0){const f=t[0];f.root.style.top=`${o}px`}else s.root.style.top=`${c}px`;continue}const a=t[i-1],u=j3(n,a)+a.root.getBoundingClientRect().height;u>c?s.root.style.top=`${u+$3}px`:s.root.style.top=`${c}px`}for(let i=r-1;i>=0;i--){const s=t[i],l=s.comment,c=P3(n,l.groupId);s.root.setAttribute("data-target-top",c.toString());const a=s.root.getBoundingClientRect(),u=c+a.height,f=t[i+1];d(B_,f,"no next item");const m=j3(n,f);m<u?s.root.style.top=`${m-a.height-$3}px`:s.root.style.top=`${c}px`}}const ya=B("comment-group-item-handler");class E_{constructor(t,e){h(this,"handleSwitchUp",t=>{const e=Math.max(0,t-1);this.groupList.setActiveItem(e),this.groupList.updateItemsLayout()});h(this,"handleSwitchDown",t=>{const e=Math.min(t+1,this.groupList.items.length);this.groupList.setActiveItem(e),this.groupList.updateItemsLayout()});h(this,"handleQuickReply",t=>{const{quickReply:e}=t;e.showReplyEditor()});h(this,"handleQuickReplyOk",t=>{const{quickReply:e}=t;e.reply(),t.updateLastCommentItem()});h(this,"handleQuickReplyCancel",t=>{const{quickReply:e}=t;e.cancel()});h(this,"handleCommentItemReply",(t,e)=>{const o=t.findCommentItem(e);d(ya,o,`the commentItem: ${e} not exist `);const{quickReply:r}=t;r.show(),r.showReplyEditor();const{comment:i}=o,s=r.getReplyEditor(),l=s.editor.getFocusedBlock(),c={type:"mention",id:N(),box:!0,created:Date.now(),text:i.displayName,iconUrl:i.avatarUrl,mentionId:i.userId};s.editor.insertBoxToBlock(l,0,c)});h(this,"handleCommentItemMore",t=>{const{quickReply:e}=t;e.hideReplyEditor(),e.getReplyEditor().clear()});h(this,"handleCommentItemOk",(t,e)=>{const o=t.findCommentItem(e);d(ya,o,`the commentItem: ${e} not exist `);const{quickReply:r}=t,{comment:i,getCommentEditor:s}=o,l=s(),c=l.getDoc();this.commentsProvider.localUpdateComment(i,c),l.readonly(),r.show()});h(this,"handleCommentItemCancel",(t,e)=>{const o=t.findCommentItem(e);d(ya,o,`the commentItem: ${e} not exist `);const r=this.commentsProvider.getComment(o.comment.id);if(ql(r.doc)){this.commentsProvider.localDeleteComment(o.comment.id);return}const{quickReply:i}=t,s=o.getCommentEditor();s.setDoc(o.doc),s.readonly(),i.show()});h(this,"handleCommentItemEdit",t=>{const e=this.groupList.findItem(t.comment.groupId);if(!e)return;const{quickReply:o}=e;t.getCommentEditor().edit(),o.hide()});h(this,"handleCommentItemDelete",t=>{const e=this.groupList.findItem(t.comment.groupId);if(!e)return;const{quickReply:o}=e,{comment:r}=t;this.commentsProvider.localDeleteComment(r.id),o.show()});h(this,"execute",(t,e,o,r)=>{const i=r_(t);if(!i||s_(i))return;const s=i_(i);switch(s){case ft.SwitchUp:this.handleSwitchUp(r);break;case ft.SwitchDown:this.handleSwitchDown(r);break;case ft.CommentItemReply:this.handleCommentItemReply(e,o);break;case ft.CommentItemMore:this.handleCommentItemMore(e);break;case ft.CommentItemOk:this.handleCommentItemOk(e,o);break;case ft.CommentItemCancel:this.handleCommentItemCancel(e,o);break;case ft.CommentItemDelete:break;case ft.CommentItemEdit:break;case ft.QuickReply:this.handleQuickReply(e);break;case ft.QuickReplyOk:this.handleQuickReplyOk(e);break;case ft.QuickReplyCancel:this.handleQuickReplyCancel(e);break;default:const l=s;ya.debug(`not implement handler for ${l}`)}});this.groupList=t,this.commentsProvider=e}destroy(){}}const wa=B("comment-group-list");class I_ extends Js{constructor(e,o,r){super(e,o,r,So(e,o),{});h(this,"groupItemHandlers");h(this,"findGroupItem",e=>this.items.find(o=>o.comment.groupId===e));h(this,"handleContainerClick",e=>{if(!e.target||!(e.target instanceof Element))return;const o=e.target.closest(".comment-group-item-root");if(!o)return;const r=o_(e.target),i=this.items.findIndex(s=>s.root===o);if(i!==-1){this.setActiveItem(i);const{groupItemHandlers:s}=this;s.execute(e.target,this.items.at(i),r,i)}});h(this,"handleSelectionChanged",()=>{const e=d_(this.editor);if(e.length>0){const o=e[0],r=this.items.findIndex(i=>i.comment.groupId===o);this.setActiveItem(r),this.emit("selectionOnComment")}else this.setActiveItem(-1)});h(this,"handleEditorResize",()=>{this.updateItemsLayout()});h(this,"handleDocChanged",()=>{this.updateComments()});h(this,"handleItemResize",()=>{this.updateItemsLayout()});h(this,"handleScroll",e=>{if(e.deltaY>=0||this.editor.scrollContainer.scrollTop!==0)return;const o=document.elementFromPoint(e.clientX,e.clientY);if(!o||!(o instanceof HTMLElement)||!this.editor.scrollContainer.contains(o))return;const r=this.container.querySelector(".comment-group-item-root");if(!r)return;const i=Number.parseFloat(r.style.top),s=Number.parseFloat(r.getAttribute("data-target-top")||"0");!Number.isNaN(i)&&!Number.isNaN(s)&&i<s&&H3(this.editor,this.items,null,Math.min(i+(0-e.deltaY)*3,s))});h(this,"updateGroupItemSwitch",()=>{const e=this.activeItem;d(wa,e,"invalid activeItem"),e.updateSwitchButton()});h(this,"updateComments",Xt.default(()=>{const e=So(this.editor,this.commentsProvider);let o=!1;for(let r=0;r<e.length;r++){const i=e[r];if(!this.findGroupItem(i.groupId)){this.handleCreateComment(i,!1),o=!0;continue}}for(let r=this.items.length-1;r>=0;r--){const i=this.items[r];e.findIndex(s=>s.groupId===i.comment.groupId)===-1&&(this.deleteItem(i.comment.id),o=!0)}o&&(this.updateItemsLayout(),this.emit("commentCountChanged"))},100));this.updateItemsLayout(),this.bindEvents(),this.editor.addListener("selectionChanged",this.handleSelectionChanged),this.editor.addListener("resize",this.handleEditorResize),this.editor.addListener("docChanged",this.handleDocChanged),this.editor.scrollContainer.addEventListener("wheel",this.handleScroll),this.items.forEach(i=>i.addListener("resize",this.handleItemResize)),this.groupItemHandlers=new E_(this,o)}destroy(){this.editor.removeListener("selectionChanged",this.handleSelectionChanged),this.editor.removeListener("resize",this.handleEditorResize),this.editor.removeListener("docChanged",this.handleDocChanged),this.editor.scrollContainer.removeEventListener("wheel",this.handleScroll),super.destroy(),this.unbindEvents(),this.removeAllListeners()}updateItemsLayout(){H3(this.editor,this.items,this.activeItem)}bindEvents(){this.container.addEventListener("click",this.handleContainerClick)}unbindEvents(){this.container.removeEventListener("click",this.handleContainerClick)}createItem(e,o){const r=new w_(this.editor,this.commentsProvider,e,this);return o==="insert"&&(A(r.root,"no-animation"),r.root.style.opacity="0",setTimeout(()=>{z(r.root,"no-animation"),r.root.style.opacity="1"},150)),r}findInsertPos(e){const r=So(this.editor,this.commentsProvider).findIndex(i=>i.id===e.id);return r===-1||r>this.items.length?-1:r}insertItem(e){const o=super.insertItem(e);return o?(this.setActiveItem(this.items.indexOf(o)),this.updateItemsLayout(),o.addListener("resize",this.handleItemResize),o):null}setActiveItem(e){if(d(wa,e>=-1&&e<this.items.length,`invalid index: ${e}`),e===this.activeIndex)return;const o=this.container.querySelector(".comment-group-item-root.active");if(o&&z(o,"active"),e!==-1){const r=this.items[e];A(r.root,"active"),this.updateItemsLayout(),this.updateGroupItemSwitch()}this.emit("activeItemChanged",e)}get activeIndex(){const e=this.container.querySelector(".comment-group-item-root.active");return e?this.items.findIndex(o=>o.root===e):-1}get activeItem(){const e=this.activeIndex;return e===-1?null:this.items[e]}handleCreateComment(e,o){if(ur(e)){const l=this.findGroupItem(e.groupId);l&&l.childrenList.insertItem(e)}const r=this.findItem(e.id);d(wa,!r,"comment group item has already exists");const i={children:[],...e};d(wa,i.children,"not a comment group");const s=this.insertItem(i);!s||o&&setTimeout(()=>{const l=this.items.indexOf(s);this.setActiveItem(l),s.edit(),s.quickReply.hide()})}handleDeleteComment(e){for(let o=0;o<this.items.length;o++){const r=this.items[o];if(r.comment.id===e){r.childrenList.items.length===0?this.deleteItem(r.comment.id):r.deleteMainComment(e);return}if(r.childrenList.deleteItem(e)){r.commentCount===0&&this.deleteItem(r.comment.id);return}}}handleUpdateComment(e){if(ur(e)){const r=this.commentsProvider.getComment(e.groupId),i=this.findItem(r.id);i&&i.handleUpdateChildComment(e);return}const o=this.findItem(e.id);o&&o.handleUpdateMainComment(e)}}const x_="comment-mini";B("comment-list");class T_ extends Yt.TypedEmitter{constructor(e,o,r){super();h(this,"root");h(this,"groupsContainer");h(this,"list");h(this,"handleSelectionOnComment",()=>{this.emit("onSelectComment")});h(this,"updateCommentCount",()=>{var o,r;const e=a_(this.editor,this.commentsProvider);(r=(o=this.commentOptions)==null?void 0:o.onCommentCountChange)==null||r.call(o,e)});h(this,"handleActiveItemChanged",()=>{var o;const e=this.list.activeItem;R3(this.editor,(o=e==null?void 0:e.comment.id)!=null?o:"")});h(this,"handleItemLayoutUpdated",()=>{var o,r;const e=nt(this.root,x_);(r=(o=this.commentOptions)==null?void 0:o.onUpdateLayout)==null||r.call(o,this.editor,{expand:e})});this.editor=e,this.commentsProvider=o,this.root=b("div",["editor-web-comment-root"],r),this.groupsContainer=b("div",["comment-groups-container"],this.root),this.list=this.createList(),this.commentsProvider.addListener(this),this.list.addListener("activeItemChanged",this.handleActiveItemChanged),this.list.addListener("itemLayoutUpdated",this.handleItemLayoutUpdated),this.list.addListener("selectionOnComment",this.handleSelectionOnComment),this.list.addListener("commentCountChanged",this.updateCommentCount),this.updateCommentCount()}get commentOptions(){return this.editor.getComponentOptions("comment")}destroy(){this.list.removeAllListeners(),this.commentsProvider.removeListener(this),this.list.destroy(),this.root.remove()}onCreateComment(e,o){const r=this.commentsProvider.getComment(e);this.list.handleCreateComment(r,o),this.updateCommentCount()}onDeleteComment(e,o){this.list.handleDeleteComment(e),this.updateCommentCount()}onUpdateComment(e,o){const r=this.commentsProvider.getComment(e);this.list.handleUpdateComment(r)}createList(){return new I_(this.editor,this.commentsProvider,this.groupsContainer)}show(e){var o;if(z(this.root,"hidden"),e){const r=this.list.findItemIndex(e);this.list.setActiveItem(r)}(o=this.commentOptions)==null||o.controller.showCommentList()}hide(){A(this.root,"hidden")}}class S_ extends Js{constructor({editor:t,parent:e,commentsProvider:o,comments:r}){super(t,o,e,r,{})}findInsertPos(){return this.items.length}createItem(t){const{editor:e,commentsProvider:o}=this;return new N3(e,o,t)}destroy(){this.items.forEach(t=>{t.destroy()})}}const Ba=B("mobile-comment-group-item"),D_=20;class L_ extends Yt.TypedEmitter{constructor(e,o,r){super();h(this,"root");h(this,"childrenList");h(this,"mainItem");h(this,"scroller");h(this,"createRoot",()=>b("div",["mobile-group-item-root"],null));h(this,"createMainItem",e=>{const{editor:o,commentsProvider:r,comment:i}=this,s=new N3(o,r,i);return e.append(s.root),s});h(this,"createChildrenList",e=>{const{editor:o,commentsProvider:r,comment:i}=this,s=b("div",["mobile-comment-children-list-container"],e);return new S_({editor:o,commentsProvider:r,comments:i.children,parent:s})});h(this,"handleTouchEnd",()=>{var i;const{scroller:e}=this,{pullThreshold:o=D_}=(i=this.editor.getComponentOptions("comment"))!=null?i:{};let r=null;if(e.y>e.minScrollY+o?(r=this.root.previousElementSibling,r||this.emit("onReachTop")):e.y<e.maxScrollY-o&&(r=this.root.nextElementSibling,r||this.emit("onReachBottom")),r){const s=r.id;this.emit("onSwitchGroup",s,I3)}});h(this,"refreshScroller",()=>{this.scroller.refresh()});this.editor=e,this.commentsProvider=o,this.comment=r,this.root=b("div",["mobile-group-item-root"],null),this.root.id=r.groupId;const i=b("div",["mobile-group-item"],this.root),s=b("div",["mobile-group-item-space"],null),l=b("div",["mobile-group-item-abstract"],null);l.textContent=r.abstract;const c=b("div",["mobile-group-item-list-container"],null);this.mainItem=this.createMainItem(c),this.childrenList=this.createChildrenList(c),i.append(s,l,c),this.scroller=new Xf.default(this.root,{stopPropagation:!0,click:!0}),this.scroller.on("touchEnd",this.handleTouchEnd)}get commentCount(){return x3(this.root,".mobile-group-item")}handleUpdateChildComment(e){d(Ba,e.groupId===this.mainItem.comment.id,"invalid child comment");const o=this.childrenList.findItem(e.id);if(!o){Ba.error(`can't find child comment item: ${e.id}`);return}o.reloadDoc()}handleUpdateMainComment(e){d(Ba,e.id===this.mainItem.comment.id,"invalid comment"),this.mainItem.reloadDoc()}deleteMainComment(e){d(Ba,e===this.mainItem.comment.id,"invalid comment"),this.mainItem.destroy()}destroy(){this.mainItem.destroy(),this.childrenList.destroy(),this.scroller.off("touchEnd",this.handleTouchEnd),this.scroller.destroy(),this.root.remove(),this.removeAllListeners()}}const df=B("mobile-group-list");class M_ extends Js{constructor(e,o,r,i){super(e,o,r,So(e,o),{});h(this,"scroller");h(this,"deleteItem",e=>{if(this.items.length<=1)return super.deleteItem(e);const o=this.findItemIndex(e);let r=null;return o===0?r=this.items[o+1].root.id:r=this.items[o-1].root.id,super.deleteItem(e)?(this.scrollToGroup(r,I3),!0):!1});h(this,"setupGroupItem",e=>{e.on("onSwitchGroup",this.scrollToGroup),e.on("onReachBottom",this.handleReachBottom),e.on("onReachTop",this.handleReachTop),e.refreshScroller()});h(this,"handleReachBottom",()=>{this.emit("onReachBottom")});h(this,"handleReachTop",()=>{this.emit("onReachTop")});h(this,"scrollToGroup",(e,o=0)=>{const r=this.findGroupItem(e);d(df,r,"invalid scroll target"),this.scroller.scrollToElement(r.root,o,!1,!1),R3(this.editor,r.comment.id)});h(this,"findGroupItem",e=>this.items.find(o=>o.comment.groupId===e));h(this,"handleDocChanged",()=>{this.updateComments()});h(this,"updateComments",Xt.default(()=>{const e=So(this.editor,this.commentsProvider);for(let o=0;o<e.length;o++){const r=e[o];if(!this.findGroupItem(r.groupId)){this.handleCreateComment(r,!1);continue}}for(let o=this.items.length-1;o>=0;o--){const r=this.items[o];e.findIndex(i=>i.groupId===r.comment.groupId)===-1&&this.deleteItem(r.comment.id)}},100));this.scroller=new Xf.default(i),this.scroller.disable(),this.editor.addListener("docChanged",this.handleDocChanged),this.items.forEach(this.setupGroupItem)}createItem(e){return new L_(this.editor,this.commentsProvider,e)}insertItem(e){const o=super.insertItem(e);return o?(this.setupGroupItem(o),o):null}findInsertPos(e){const r=So(this.editor,this.commentsProvider).findIndex(i=>i.id===e.id);return r===-1||r>this.items.length?-1:r}setActiveItem(e){this.scrollToGroup(e)}handleCreateComment(e,o){if(ur(e)){const s=this.findGroupItem(e.groupId);s&&s.childrenList.insertItem(e)}const r=this.findItem(e.id);d(df,!r,"comment group item has already exists");const i={children:[],...e};d(df,i.children,"not a comment group"),this.insertItem(i),this.scroller.refresh()}handleDeleteComment(e){for(let o=0;o<this.items.length;o++){const r=this.items[o];if(r.comment.id===e){r.childrenList.items.length===0?this.deleteItem(r.comment.id):r.deleteMainComment(e);return}if(r.childrenList.deleteItem(e)){r.commentCount===0&&this.deleteItem(r.comment.id);return}}}handleUpdateComment(e){if(ur(e)){const r=this.commentsProvider.getComment(e.groupId),i=this.findItem(r.id);i&&i.handleUpdateChildComment(e);return}const o=this.findItem(e.id);o&&o.handleUpdateMainComment(e)}destroy(){this.editor.removeListener("docChanged",this.handleDocChanged),this.scroller.destroy(),this.items.forEach(e=>e.destroy())}}const R_=B("mobile-comment-list"),{t:F3}=T;class A_ extends Yt.TypedEmitter{constructor(e,o,r){super();h(this,"root");h(this,"list");h(this,"mask");h(this,"pullInfoContainer");h(this,"handleRootClick",e=>{const o=e.target;d(R_,o instanceof Element,"invalid target"),!(o.closest(".mobile-group-item-abstract")||o.closest(".mobile-group-item-list-container"))&&(this.hide(),this.emit("onCommentListClose"))});h(this,"hidePullInfo",Xt.default(()=>{z(this.pullInfoContainer,"active")},1e3*3));h(this,"handleReachBottom",()=>{this.showPullInfo("bottom")});h(this,"handleReachTop",()=>{this.showPullInfo("top")});h(this,"show",e=>{z(this.root,"hidden"),A(document.documentElement,"disabled-scroll"),e&&this.list.setActiveItem(e)});h(this,"hide",()=>{A(this.root,"hidden"),z(document.documentElement,"disabled-scroll")});this.editor=e,this.commentsProvider=o,this.root=b("div",["editor-mobile-comments-root"],r),this.mask=b("div",["mobile-comment-mask"],this.root);const i=b("div",["mobile-comment-groups-container"],this.root),s=b("div",["mobile-comment-groups-scroll-container"],i);this.list=new M_(this.editor,this.commentsProvider,s,i),this.pullInfoContainer=this.createPullInfo(),this.commentsProvider.addListener(this),this.list.on("onReachBottom",this.handleReachBottom),this.list.on("onReachTop",this.handleReachTop),this.root.onclick=this.handleRootClick}onCreateComment(e,o){const r=this.commentsProvider.getComment(e);this.list.handleCreateComment(r,o)}onDeleteComment(e,o){this.list.handleDeleteComment(e)}onUpdateComment(e,o){const r=this.commentsProvider.getComment(e);this.list.handleUpdateComment(r)}createPullInfo(){const e=b("div",["mobile-comment-pull-info-container"],this.root);return b("div",["mobile-comment-pull-info"],e),e}showPullInfo(e){const o=F3(e==="bottom"?"comment.isLast":"comment.isFirst");this.pullInfoContainer.firstElementChild.textContent=o,A(this.pullInfoContainer,"active"),this.hidePullInfo()}destroy(){this.list.removeAllListeners(),this.list.destroy(),this.root.onclick=null}}function z3(n,t){const e=So(n,t),o=new Map;for(const r of e){const i=T3(n,r.groupId);if(!!i)if(o.has(i)){const s=o.get(i);rf(r).forEach(c=>{s==null||s.commentIds.add(c.id)})}else{const s=rf(r),l=new Set(s.map(c=>c.id));o.set(i,{commentIds:l,firstComment:r})}}return Array.from(o.entries()).map(([r,i])=>({blockId:r,...i}))}const O_=B("mini-group-item");class __{constructor(t,e){h(this,"root");h(this,"blockId");h(this,"comment");h(this,"miniCommentItem");h(this,"updateCommentItemCount",()=>{this.miniCommentItem.updateCount(this.commentCount)});this.editor=t,this.commentGroup=e,this.root=b("div",["mini-group-item"],null),this.comment=e.firstComment,this.miniCommentItem=new C_(this.comment.id,this.root),this.blockId=this.getBlockId(),this.alignToBlock(),this.updateCommentItemCount()}getBlockId(){return T3(this.editor,this.comment.groupId)}get commentCount(){return this.commentGroup.commentIds.size}alignToBlock(){const t=this.getBlockId(),e=this.editor.getBlockById(t);d(O_,e,`The blockId: ${t} not exist in doc`);const o=this.editor.scrollContainer.getBoundingClientRect(),i=e.getBoundingClientRect().top-o.top;requestAnimationFrame(()=>{this.root.style.transform=`translateY(${i}px)`})}destroy(){this.root.remove()}}class N_ extends Js{constructor(e,o,r){super(e,o,r,z3(e,o),{});h(this,"handleDocChanged",Xt.default(()=>{this.updateMiniCommentsGroup()},100));h(this,"updateMiniCommentsGroup",()=>{const e=z3(this.editor,this.commentsProvider);this.reloadList(e)});this.editor=e,this.commentsProvider=o,this.editor.addListener("docChanged",this.handleDocChanged)}createItem(e){return new __(this.editor,e)}findInsertPos(){return-1}handleCreateComment(e,o){this.updateMiniCommentsGroup()}handleDeleteComment(e){this.updateMiniCommentsGroup()}destroy(){this.editor.removeListener("docChanged",this.handleDocChanged),super.destroy(),this.removeAllListeners()}}const $_=B("mini-comments-list");class P_ extends Yt.TypedEmitter{constructor(e,o,r){super();h(this,"list");h(this,"root");h(this,"createList",()=>{const e=b("div",["comment-groups-container"],this.root);return this.editor.domEvents.addEventListener(e,"click",this.handleListContainerClick),new N_(this.editor,this.commentsProvider,e)});h(this,"handleListContainerClick",(e,o)=>{const r=o.target;d($_,r instanceof HTMLElement,"The target is not a valid html element");const i=r.closest(".mini-comment-item");i&&this.emit("onItemClick",i.id)});this.editor=e,this.commentsProvider=o,this.root=b("div",["editor-mini-comment-root"],r),this.list=this.createList(),this.commentsProvider.addListener(this)}onCreateComment(e,o){const r=this.commentsProvider.getComment(e);this.list.handleCreateComment(r,o)}onDeleteComment(e,o){this.list.handleDeleteComment(e)}onUpdateComment(e,o){}show(){z(this.root,"hidden")}hide(){A(this.root,"hidden")}destroy(){this.list.destroy(),this.removeAllListeners()}}function U3(n,t,e){if(!t.start.isSimple()||!t.end.isSimple())return;const o=t.block,r=At(n,o,t.start.offset,t.end.offset),i=`comment-${e.id.toLocaleLowerCase()}`,s=e.id;Wp(n,o,r,i,s)}function j_(n,t,e){const o=tn(n).map(s=>s.block),r=ef(n,o),i=ka({editor:n,abstract:r});return n.undoManager.runInGroup(()=>{tn(n,{simpleBlockOnly:!0}).forEach(c=>{!P(n,c.block)||U3(n,c,i)});const l=Ko();e.localCreateComment(i,l)}),i}class H_{constructor(t,e){h(this,"id","CommentsCommandProvider");this.provider=t,this.editorComments=e}getAvailableCommands(t,e,o){const r=t.selection.range;if(P(t,e)&&!o.isCollapsed()&&r.isSimple()){const i=q(e),s=ot(e),l=Qe(t,e);return[{id:"add-comment",name:"Add comment",blockId:i,blockType:s,blockKind:l,groupIndex:1e3,icon:wc}]}return[]}executeRangeCommand(t,e,o,r,i){if(o.id==="add-comment"){this.editorComments.showCommentList();const s=j_(t,e,this.provider);return i["add-comment"]=s,!0}return!1}}class V3{constructor(t,e){h(this,"commentList",null);h(this,"mobileCommentList",null);h(this,"miniCommentList");h(this,"showComment",(t,e)=>{var o,r;t==="mini"&&this.miniCommentList.show(),t==="mobile"&&((o=this.mobileCommentList)==null||o.show(e)),t==="web"&&((r=this.commentList)==null||r.show(e))});h(this,"showCommentList",t=>{this.isMobile?this.showComment("mobile",t):this.showComment("web",t)});h(this,"handleCommentListClose",()=>{this.showComment("mini")});h(this,"handleOnSelectComment",()=>{this.showComment("web")});h(this,"handleMiniCommentItemClick",t=>{this.showCommentList(t)});this.editor=t,this.provider=e,t.editorCommandProviders.registerCommandProvider(new H_(e,this)),t.blockHooks.push(new n_(this.provider,this)),this.isMobile?(this.mobileCommentList=new A_(this.editor,this.provider,this.getCommentRoot("mobileContainer")),this.mobileCommentList.on("onCommentListClose",this.handleCommentListClose)):(this.commentList=new T_(this.editor,this.provider,this.getCommentRoot("container")),this.commentList.on("onSelectComment",this.handleOnSelectComment)),this.miniCommentList=new P_(this.editor,this.provider,this.getCommentRoot("miniContainer")),this.miniCommentList.on("onItemClick",this.handleMiniCommentItemClick)}get commentOptions(){return this.editor.getComponentOptions("comment")}get commentProvider(){return this.provider}get isMobile(){return xt.isMobile}getCommentRoot(t){var e,o;return(o=(e=this.commentOptions)==null?void 0:e[t])!=null?o:document.body}destroy(){var t,e;(t=this.commentList)==null||t.destroy(),(e=this.mobileCommentList)==null||e.destroy(),this.miniCommentList.destroy()}}const tU="",F_={comment:{count:"\u6279\u6CE8 ({num})",hide:"\u9690\u85CF\u6279\u6CE8",show:"\u663E\u793A\u6279\u6CE8",reply:"\u56DE\u590D",quicklyReply:"\u56DE\u590D...",send:"\u786E\u8BA4",placeholder:"\u6DFB\u52A0\u6279\u6CE8...",replyPlaceholder:"\u56DE\u590D\u6216@\u4ED6\u4EBA",edit:"\u7F16\u8F91",delete:"\u5220\u9664",image:"\u56FE\u7247",sendTitle:"\u6309Enter\u53D1\u9001\u6279\u6CE8",replyTitle:"\u6309Enter\u56DE\u590D\u6279\u6CE8",isFirst:"\u5DF2\u7ECF\u662F\u7B2C\u4E00\u6761\u6279\u6CE8",isLast:"\u5DF2\u7ECF\u662F\u6700\u540E\u4E00\u6761\u6279\u6CE8",comment:"\u6279\u6CE8"}},z_={comment:{count:"Comments ({num})",hide:"Hide Comments",show:"Show Comments",reply:"Reply",quicklyReply:"Reply...",send:"OK",placeholder:"Add a comment...",replyPlaceholder:"Add Comments or @ others",edit:"Edit",delete:"Delete",image:"Image",sendTitle:"Press Enter to send comment",replyTitle:"Press Enter to reply comment",isFirst:"\u5DF2\u7ECF\u662F\u7B2C\u4E00\u6761\u6279\u6CE8",isLast:"\u5DF2\u7ECF\u662F\u6700\u540E\u4E00\u6761\u6279\u6CE8",more:"more",comment:"Comment"}},U_={comment:{count:"\u30B3\u30E1\u30F3\u30C8 ({num})",hide:"\u30B3\u30E1\u30F3\u30C8\u3092\u975E\u8868\u793A",show:"\u30B3\u30E1\u30F3\u30C8\u3092\u8868\u793A",reply:"\u8FD4\u4FE1",quicklyReply:"\u8FD4\u4FE1...",send:"\u9001\u4FE1",placeholder:"\u30B3\u30E1\u30F3\u30C8\u3092\u8FFD\u52A0...",replyPlaceholder:"\u8FD4\u4FE1\u307E\u305F\u306F\u30E1\u30F3\u30B7\u30E7\u30F3(@)",edit:"\u7DE8\u96C6",delete:"\u524A\u9664",image:"\u753B\u50CF",sendTitle:"Enter\u3092\u62BC\u3057\u3066\u30B3\u30E1\u30F3\u30C8\u3092\u9001\u4FE1",replyTitle:"Enter\u3092\u62BC\u3057\u3066\u30B3\u30E1\u30F3\u30C8\u3092\u8FD4\u4FE1",isFirst:"\u6700\u521D\u306E\u30B3\u30E1\u30F3\u30C8\u3067\u3059",isLast:"\u6700\u5F8C\u306E\u30B3\u30E1\u30F3\u30C8\u3067\u3059",comment:"\u30B3\u30E1\u30F3\u30C8\u3092"}};T.mergeLang({"zh-CN":F_,"en-US":z_,"ja-JP":U_});class q3{renderText(t,e,o){const r=[],i={};return Object.entries(o).forEach(([s,l])=>{s.startsWith("comment-")&&(r.push("comment"),i[s]=l)}),{classes:r,attributes:i}}renderBlock(t,e,o){const r=o.comments;if(!r||r.length===0)return{};const i=["comment"],s={};return r.forEach(l=>{s[`comment-${l.toLocaleLowerCase()}`]=l}),{classes:i,attributes:s}}updateBlock(t,e,o,r){const i=r.comments;z(o,"comment"),Array.from(o.attributes).forEach(s=>{s.name.startsWith("comment-")&&o.removeAttribute(s.name)}),!(!i||i.length===0)&&(A(o,"comment"),i.forEach(s=>{o.setAttribute(`comment-${s.toLocaleLowerCase()}`,s)}))}}class V_{constructor(t){h(this,"handleUpdateCompositionText",(t,e,o,r,i)=>{const s=t.getFocusedBlock(),l=t.getFirstBlock();s===l&&this.applyPlaceholder(t)});h(this,"handleSelectionChange",t=>{this.applyPlaceholder(t)});h(this,"applyPlaceholder",t=>{const e=t.getFirstBlock();na(t,e,T.t("comment.replyPlaceholder"))});this.applyPlaceholder(t),t.addListener("selectionChanged",this.handleSelectionChange)}}function q_(n,t,e){const o=n.getBlockData(t),r=o.comments;if((r==null?void 0:r.indexOf(e))!==-1){const s=new Set(r);s.delete(e),n.updateBlockData(t,{comments:Array.from(s)})}const i=o.text;if(!!i&&P(n,t)){const s=Yd(i,`comment-${e.toLocaleLowerCase()}`,e);n.setBlockText(t,s)}}const W_=B("editor-comment");function G_(n){const t=n.getCustom("editor-comments");if(d(W_,t,"the editor comment not exist"),t.showCommentList(),n.selection.range.isCollapsed()){const s=n.selection.startBlock,l=io(s);if(l.length>=2){const{containerId:c}=l.at(-1),a=F(Er(n,c));if(a&&ot(a)==="code"){nf(n,a,t.commentProvider);return}}nf(n,s,t.commentProvider);return}const e=tn(n,{simpleBlockOnly:!0}),o=e.map(s=>s.block),r=ef(n,o),i=ka({editor:n,abstract:r});n.undoManager.runInGroup(()=>{e.forEach(l=>{P(n,l.block)?U3(n,l,i):B3(n,l.block,i)});const s=Ko();t.commentProvider.localCreateComment(i,s)})}const uf=B("text-styles");function Z_(n){const t=o=>{if(!o.attributes)return new Map;const r=Object.entries(o.attributes).filter(([i])=>!!i.startsWith("style-"));return new Map(r)};if(n.length===0)return new Map;let e=t(n[0]);for(let o=1;o<n.length;o++){const r=t(n[o]);e=new Map(Array.from(e.entries()).filter(([i,s])=>r.get(i)===s))}return e}function Y_(n,t,e,o,r){d(uf,e.isSimple(),"invalid range");const{start:i,end:s}=e;d(uf,i.blockId===s.blockId&&i.blockId===q(t),"invalid range"),d(uf,o.startsWith("style-"),"invalid style");let c=n.getBlockText(t);return o==="style-subscript"?c=Sr(i.offset,s.offset-i.offset,c,"style-superscript",void 0,{ignoreValue:!0}):o==="style-superscript"&&(c=Sr(i.offset,s.offset-i.offset,c,"style-subscript",void 0,{ignoreValue:!0})),r===!1||r===void 0||r===null?c=Sr(i.offset,s.offset-i.offset,c,o,void 0,{ignoreValue:!0}):c=Vi(i.offset,s.offset-i.offset,c,o,r),n.setBlockText(t,c),c}const Q_=`<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
589
589
  <path fill="currentColor" fill-rule="evenodd" clip-rule="evenodd" d="M13.3236 18.5C14.2519 18.5 15.0547 18.3458 15.7318 18.0374C16.409 17.729 16.9352 17.2951 17.3103 16.7355C17.6855 16.176 17.8731 15.521 17.8731 14.7707C17.8731 14.1857 17.738 13.6628 17.4677 13.2018C17.1975 12.7408 16.8271 12.372 16.3566 12.0954C15.886 11.8188 15.3424 11.6646 14.7256 11.6328V11.5565C15.4823 11.4548 16.0959 11.1464 16.5664 10.6313C17.0369 10.1163 17.2722 9.49633 17.2722 8.77146C17.2722 7.76045 16.9082 6.96246 16.1801 6.37748C15.4521 5.79249 14.4522 5.5 13.1805 5.5H8.57373C8.07777 5.5 7.69149 5.63989 7.41489 5.91966C7.1383 6.19944 7 6.59367 7 7.10235V16.8977C7 17.4063 7.1383 17.8006 7.41489 18.0803C7.69149 18.3601 8.07777 18.5 8.57373 18.5H13.3236ZM12.0073 10.8793H10.1379V7.68415H12.2076C12.8308 7.68415 13.3172 7.82086 13.6669 8.09428C14.0166 8.36769 14.1915 8.74921 14.1915 9.23881C14.1915 9.75385 13.9976 10.156 13.6097 10.4453C13.2218 10.7347 12.6877 10.8793 12.0073 10.8793ZM10.1379 16.3349H12.3412C13.1042 16.3349 13.686 16.1839 14.0866 15.8819C14.4872 15.5798 14.6875 15.1363 14.6875 14.5514C14.6875 13.9791 14.4776 13.5435 14.058 13.2447C13.6383 12.9458 13.0406 12.7964 12.2649 12.7964H10.1379V16.3349Z" />
590
590
  </svg>`,K_=`<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
591
591
  <path fill="currentColor" d="M13.5668 18.5C13.8023 18.5 13.9979 18.4316 14.1538 18.2948C14.3097 18.158 14.3877 17.9687 14.3877 17.7269C14.3877 17.4978 14.3129 17.3149 14.1634 17.178C14.0138 17.0412 13.8182 16.9728 13.5764 16.9728H11.6483L13.7959 7.02717H15.7048C15.9466 7.02717 16.1439 6.95876 16.2966 6.82195C16.4493 6.68514 16.5257 6.49584 16.5257 6.25404C16.5257 6.0186 16.4509 5.83407 16.3014 5.70044C16.1519 5.56681 15.9562 5.5 15.7144 5.5H9.94934C9.7139 5.5 9.51982 5.56681 9.36711 5.70044C9.21439 5.83407 9.13803 6.0186 9.13803 6.25404C9.13803 6.49584 9.21598 6.68514 9.37188 6.82195C9.52778 6.95876 9.72345 7.02717 9.95888 7.02717H11.8869L9.73935 16.9728H7.81131C7.56951 16.9728 7.37384 17.0412 7.2243 17.178C7.07477 17.3149 7 17.4978 7 17.7269C7 17.9687 7.07636 18.158 7.22907 18.2948C7.38179 18.4316 7.57905 18.5 7.82085 18.5H13.5668Z" />
@@ -628,7 +628,7 @@ width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
628
628
  <g id="" stroke="none" stroke-width="1" fill-rule="evenodd">
629
629
  <path stroke="currentColor" d="M19.284802,16.9726267 C19.4891443,16.9726267 19.6594295,17.0421598 19.7956577,17.1812261 C19.9318859,17.3202923 20,17.4891585 20,17.6878246 C20,17.8921669 19.9318859,18.0624521 19.7956577,18.1986803 C19.6594295,18.3349085 19.4891443,18.4030226 19.284802,18.4030226 L19.284802,18.4030226 L4.71519796,18.4030226 C4.51653186,18.4030226 4.34766567,18.3349085 4.2085994,18.1986803 C4.06953313,18.0624521 4,17.8921669 4,17.6878246 C4,17.4891585 4.06953313,17.3202923 4.2085994,17.1812261 C4.34766567,17.0421598 4.51653186,16.9726267 4.71519796,16.9726267 L4.71519796,16.9726267 Z M18.2486798,8.56372925 C18.8324532,8.56372925 19.2702832,8.70711219 19.5621699,8.99387807 C19.8540566,9.28064395 20,9.71335319 20,10.2920058 L20,10.2920058 L20,13.1033356 C20,13.6819882 19.8540566,14.1159776 19.5621699,14.4053039 C19.2702832,14.6946302 18.8324532,14.8392933 18.2486798,14.8392933 L18.2486798,14.8392933 L5.75132021,14.8392933 C5.16754681,14.8392933 4.72971675,14.6946302 4.43783005,14.4053039 C4.14594335,14.1159776 4,13.6819882 4,13.1033356 L4,13.1033356 L4,10.2920058 C4,9.71335319 4.14594335,9.28064395 4.43783005,8.99387807 C4.72971675,8.70711219 5.16754681,8.56372925 5.75132021,8.56372925 L5.75132021,8.56372925 Z M18.1027364,9.81576957 L5.88958233,9.81576957 C5.68474956,9.81576957 5.52728437,9.86953818 5.41718675,9.97707538 C5.30708913,10.0846126 5.25204033,10.2459184 5.25204033,10.4609928 L5.25204033,10.4609928 L5.25204033,12.9343485 C5.25204033,13.149423 5.30708913,13.3107288 5.41718675,13.418266 C5.52728437,13.5258032 5.68474956,13.5795718 5.88958233,13.5795718 L5.88958233,13.5795718 L18.1027364,13.5795718 C18.3075692,13.5795718 18.4650344,13.5258032 18.575132,13.418266 C18.6852296,13.3107288 18.7402784,13.149423 18.7402784,12.9343485 L18.7402784,12.9343485 L18.7402784,10.4609928 C18.7402784,10.2459184 18.6852296,10.0846126 18.575132,9.97707538 C18.4650344,9.86953818 18.3075692,9.81576957 18.1027364,9.81576957 L18.1027364,9.81576957 Z M19.284802,5 C19.4891443,5 19.6594295,5.06953313 19.7956577,5.2085994 C19.9318859,5.34766567 20,5.51653186 20,5.71519796 C20,5.91954023 19.9318859,6.08982546 19.7956577,6.22605364 C19.6594295,6.36228182 19.4891443,6.43039591 19.284802,6.43039591 L19.284802,6.43039591 L4.71519796,6.43039591 C4.51653186,6.43039591 4.34766567,6.36228182 4.2085994,6.22605364 C4.06953313,6.08982546 4,5.91954023 4,5.71519796 C4,5.51653186 4.06953313,5.34766567 4.2085994,5.2085994 C4.34766567,5.06953313 4.51653186,5 4.71519796,5 L4.71519796,5 Z" fill-rule="nonzero"></path>
630
630
  </g>
631
- </svg>`,eU="";B("file-box");function Q3(n,t){const e=n.getBoxData(t),o=n.doc.buildResourceUrl(e.src,{downloadFileName:e.fileName});Tl(o,e.fileName)}class dN{constructor(){h(this,"group","file-box-commands");h(this,"commands",[{id:"download",name:"Download",icon:hf},{id:"to-link",name:"To link",icon:Z3,states:["checked"]},{id:"to-card",name:"To card",icon:Y3}])}executeCommand(t,e,o,r){if(r.id==="to-card"){const i=H(e),s=U(i),l=J(e)+1,c=t.getBoxData(o),a=ao(e,o);t.undoManager.runInGroup(()=>{const u={src:c.src,previewType:G3.Card,fileName:c.fileName,fileSize:c.fileSize,fileType:c.fileType};a.start===0?W(t,e)===1?(t.deleteBlock(e),t.insertEmbed(s,l-1,"office",u)):(t.deleteTextFromBlock(e,a.start,1),t.insertEmbed(s,l-1,"office",u)):a.start===W(t,e)-1?(t.deleteTextFromBlock(e,a.start,1),t.insertEmbed(s,l,"office",u)):(t.deleteTextFromBlock(e,a.start,1),Ar(t,e,a.start,{forceInsertAfter:!0}),t.insertEmbed(s,l,"office",u))})}else r.id==="download"&&Q3(t,o)}}function uN(n,t,e,o){const r=o,i=b("a",["file-container"],e),s=b("span",["file-icon"],i);s.innerHTML=aN,b("span",["file-name"],i,r.fileName),i.setAttribute("data-file-id",r.id),i.setAttribute("data-file-src",r.src)}function hN(n,t,e){const o=n.options.componentsOptions.file;if(o!=null&&o.onClick){o.onClick(n,t,e);return}Q3(n,t)}function fN(n,t){return{boxCommands:{"hovering-toolbar":new dN}}}function mN(n,t,e,o){const r=t;return o==="html"?r.src?`<a href="${n.doc.buildResourceUrl(r.src,{withToken:!0})}" >${r.fileName}</a>`:`[${r.fileName}]`:o==="markdown"?r.src?`![${r.fileName}](${n.doc.buildResourceUrl(r.src,{withToken:!0})})`:`[${r.fileName}]`:r.src?`[${r.fileName}](${n.doc.buildResourceUrl(r.src,{withToken:!0})})`:`[${r.fileName}]`}const K3={boxType:"file",updateBoxContent:uN,handleClickBox:hN,getBoxProperties:fN,convertTo:mN},gN=`<svg width="48" height="48" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
631
+ </svg>`,eU="";B("file-box");function Q3(n,t){const e=n.getBoxData(t),o=n.doc.buildResourceUrl(e.src,{downloadFileName:e.fileName});Tl(o,e.fileName)}class dN{constructor(){h(this,"group","file-box-commands");h(this,"commands",[{id:"download",name:"Download",icon:hf},{id:"to-link",name:"To link",icon:Z3,states:["checked"]},{id:"to-card",name:"To card",icon:Y3}])}executeCommand(t,e,o,r){if(r.id==="to-card"){const i=H(e),s=U(i),l=J(e)+1,c=t.getBoxData(o),a=uo(e,o);t.undoManager.runInGroup(()=>{const u={src:c.src,previewType:G3.Card,fileName:c.fileName,fileSize:c.fileSize,fileType:c.fileType};a.start===0?W(t,e)===1?(t.deleteBlock(e),t.insertEmbed(s,l-1,"office",u)):(t.deleteTextFromBlock(e,a.start,1),t.insertEmbed(s,l-1,"office",u)):a.start===W(t,e)-1?(t.deleteTextFromBlock(e,a.start,1),t.insertEmbed(s,l,"office",u)):(t.deleteTextFromBlock(e,a.start,1),Ar(t,e,a.start,{forceInsertAfter:!0}),t.insertEmbed(s,l,"office",u))})}else r.id==="download"&&Q3(t,o)}}function uN(n,t,e,o){const r=o,i=b("a",["file-container"],e),s=b("span",["file-icon"],i);s.innerHTML=aN,b("span",["file-name"],i,r.fileName),i.setAttribute("data-file-id",r.id),i.setAttribute("data-file-src",r.src)}function hN(n,t,e){const o=n.options.componentsOptions.file;if(o!=null&&o.onClick){o.onClick(n,t,e);return}Q3(n,t)}function fN(n,t){return{boxCommands:{"hovering-toolbar":new dN}}}function mN(n,t,e,o){const r=t;return o==="html"?r.src?`<a href="${n.doc.buildResourceUrl(r.src,{withToken:!0})}" >${r.fileName}</a>`:`[${r.fileName}]`:o==="markdown"?r.src?`![${r.fileName}](${n.doc.buildResourceUrl(r.src,{withToken:!0})})`:`[${r.fileName}]`:r.src?`[${r.fileName}](${n.doc.buildResourceUrl(r.src,{withToken:!0})})`:`[${r.fileName}]`}const K3={boxType:"file",updateBoxContent:uN,handleClickBox:hN,getBoxProperties:fN,convertTo:mN},gN=`<svg width="48" height="48" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
632
632
  <path d="M12 1C13.5 2.5 14 3 16 5V15.6087C16 15.7914 15.9638 15.9723 15.8934 16.1411C15.8231 16.3099 15.7199 16.4633 15.5899 16.5925C15.4599 16.7217 15.3056 16.8242 15.1358 16.8941C14.9659 16.964 14.7838 17 14.6 17H3.4C3.21615 17 3.0341 16.964 2.86424 16.8941C2.69439 16.8242 2.54005 16.7217 2.41005 16.5925C2.28005 16.4633 2.17693 16.3099 2.10657 16.1411C2.03621 15.9723 2 15.7914 2 15.6087V2.3913C2 2.2086 2.03621 2.02768 2.10657 1.85888C2.17693 1.69007 2.28005 1.5367 2.41005 1.4075C2.54005 1.27831 2.69439 1.17583 2.86424 1.10591C3.0341 1.03599 3.21615 1 3.4 1H12Z" fill="#FFBE5A"/>
633
633
  <path fill-rule="evenodd" clip-rule="evenodd" d="M7.5 7.5V11.1H8.7C9.69411 11.1 10.5 10.2941 10.5 9.3C10.5 8.30589 9.69411 7.5 8.7 7.5H7.5ZM7 6C6.44772 6 6 6.44771 6 7V11.6C6 12.1523 6.44772 12.6 7 12.6H8.7C10.5225 12.6 12 11.1225 12 9.3C12 7.47746 10.5225 6 8.7 6H7Z" fill="white"/>
634
634
  <path d="M12 1L14 3L16 5H13.3333C12.9797 5 12.6406 4.84675 12.3905 4.57397C12.1405 4.30119 12 3.93122 12 3.54546V1Z" fill="#FFD89C"/>
@@ -683,6 +683,6 @@ width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
683
683
  </defs>
684
684
  </svg>`,X3={dwg:[],rvt:[],skp:[],img:["image/png","image/jpg","image/jpeg","image/bmp","image/ico","image/icon","image/gif"],txt:["text/plain"],zip:["application/zip","application/x-rar-compressed","application/x-7z-compressed","application/x-tar","application/x-bzip2","application/java-archive"],ppt:["application/vnd.ms-powerpoint","application/vnd.openxmlformats-officedocument.presentationml.presentation"],excel:["application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],pdf:["application/pdf"],word:["application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document"]},ff={dwg:gN,rvt:pN,skp:CN,img:bN,txt:kN,zip:J3,rar:J3,ppt:vN,excel:yN,pdf:wN,word:BN};function IN(n,t){const e=Object.keys(X3);for(let r=0;r<e.length;r+=1){const i=e[r];if(X3[i].includes(t))return ff[i]}const o=Am(n.toLowerCase());return ff[o]?ff[o]:EN}function xN(n,t){const e=b("div",["card-root"],n),o=b("div",["file-icon"],e);o.innerHTML=IN(t.fileName,t.fileType);const r=b("div",["file-details"],e);b("div",["file-name"],r,t.fileName),b("div",["file-size"],r,Pm(t.fileSize));const i=b("div",["file-actions"],e),s=b("button",["download"],i);return s.innerHTML=hf,{card:e,downloadButton:s}}const nU="";function tC(n,t){const o=n.getBlockData(t).embedData,r=n.options.componentsOptions.file;if(r!=null&&r.onDownloadFile){r.onDownloadFile(n,o);return}const i=n.doc.buildResourceUrl(o.src,{downloadFileName:o.fileName});Tl(i,o.fileName)}B("webpage-embed");function TN(n,t,e){const{embedData:o}=e,r=o,{card:i,downloadButton:s}=xN(t,r);n.domEvents.addEventListener(s,"click",(l,c)=>{if(!c.target)return;const a=F(c.target);!a||tC(l,a)}),n.domEvents.addEventListener(i,"click",(l,c)=>{if(!c.target)return;const a=F(c.target);if(!a||Ri(c,"button"))return;const u=l.options.componentsOptions.file;if(u!=null&&u.onClick){u.onClick(l,a,c);return}const m=l.getBlockData(a).embedData,C=l.doc.buildResourceUrl(m.src,{downloadFileName:m.fileName});Tl(C,m.fileName)})}class SN{constructor(){h(this,"group","file-card");h(this,"commands",[{id:"download",name:"Download",icon:hf},{id:"sep",name:"",type:"separator"},{id:"to-link",name:"To link",icon:Z3},{id:"to-card",name:"To card",icon:Y3,states:["checked"]},{id:"sep",name:"",type:"separator"},{id:"add-comment",name:"Add Comment",icon:wc}])}executeCommand(t,e,o){if(o.id==="to-link"){const r=H(e),i=U(r),s=J(e),l=t.getBlockData(e),{embedData:c}=l,a=c,u={id:N(),box:!0,type:"file",created:Date.now(),src:a.src,fileName:a.fileName,fileSize:a.fileSize,fileType:a.fileType};t.undoManager.runInGroup(()=>{t.deleteBlock(e);const f=[Yg(u)];t.insertTextBlock(f,i,s)})}else o.id==="download"?tC(t,e):o.id==="add-comment"&&k1(t,e)}}function DN(n,t){const e=n.getBlockData(t),{embedData:o,id:r}=e,i=o;return{blockCommands:{"hovering-toolbar":new SN},abstract:i.fileName}}function LN(n,t,e,o){const{embedData:r}=t,i=r;return o==="html"?i.src?`<p><a href="${n.doc.buildResourceUrl(i.src,{withToken:!0})}" >${i.fileName}</a></p>`:`<p>[${i.fileName}]</p>`:o==="markdown"?i.src?`![${i.fileName}](${n.doc.buildResourceUrl(i.src,{withToken:!0})})
685
685
  `:`[${i.fileName}]
686
- `:i.src?`[${i.fileName}](${n.doc.buildResourceUrl(i.src,{withToken:!0})})`:`[${i.fileName}]`}const MN={embedType:"office",createEmbedContent:TN,getBlockProperties:DN,convertTo:LN};function RN(n){const t=/(\s|^)(http|https):\/\/[\w\-]+(\.[\w\-]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?$/;return t.test(n)?n.search(t):-1}function AN(n){const t=n.selection.range;if(!t.isCollapsed()||!t.isSimple())return;const{start:e}=t,o=n.getBlockById(e.blockId);if(!P(n,o))return;const r=n.getBlockText(o),s=sp(r).slice(0,e.offset),l=RN(s);if(l===-1)return;const c=s.slice(l),a=s.length;let u=Vi(l,a-l,r,"link",c);return u=ho(u,a," ",null),n.setBlockText(o,u),n.selection.selectBlock(o,a+1),!0}const ON={Space:AN},oU="",_N={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 <a href="" class="retry-upload">\u91CD\u8BD5</a></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 <a href="" class="retry-upload">\u91CD\u8BD5</a></div>'},audio:{menuItem:"\u97F3\u9891",abstract:"\u97F3\u9891"},video:{menuItem:"\u89C6\u9891",abstract:"\u89C6\u9891"}}},NN={media:{upload:{failed:'<div class="line-1">{name} upload failed</div><div class="line-2">The network service is abnormal, you can <a href="" class="retry-upload">Try again</a></div>'},load:{failed:'<div class="line-1">{name} loading failed</div><div class="line-2">The network service is abnormal, you can <a href="" class="retry-upload">Try again</a></div>'},audio:{menuItem:"Audio",abstract:"Audio"},video:{menuItem:"Video",abstract:"Video"}}};T.mergeLang({"zh-CN":_N,"en-US":NN});var mn=(n=>(n.AUDIO="audio",n.VIDEO="video",n))(mn||{}),Xs=(n=>(n.Empty="empty",n.Progress="progress",n.Error="error",n))(Xs||{});const eC=10*1024*1024,$N=["wav","mp3","aac","ogg","webm","flac"],PN=["ogg","mp4","webm"],jN=()=>{};function nC(n){var u,f,m,C,k,w;const t=(u=n.getComponentOptions("media"))!=null?u:{},{allowedMedias:e,maxSize:o,callbacks:r}=t,i=(f=e==null?void 0:e.audio)!=null?f:$N,s=(m=e==null?void 0:e.video)!=null?m:PN,l=(C=o==null?void 0:o.audio)!=null?C:eC,c=(k=o==null?void 0:o.video)!=null?k:eC,a=(w=r==null?void 0:r.onError)!=null?w:jN;return{allowedMedias:{audio:i,video:s},maxSize:{audio:l,video:c},callbacks:{onError:a}}}const HN=B("file-utils");function FN(n){d(HN,n instanceof File,`The file: ${n} isn't instance of File`);const{name:t}=n;if(!t)return"";const e=t.lastIndexOf(".");return e===-1?"":t.slice(e+1)}function oC(n,t){const e=i=>i.map(s=>`.${s}`).join(","),{allowedMedias:o}=nC(n),r=o[t];return r?e(r):"*"}function zN(n,t,e){const{maxSize:o,callbacks:r,allowedMedias:i}=nC(t),{[e]:s}=o,{[e]:l}=i;if(s&&n.size>s){const a=new Error("media is too large");return a.code=`MaxMediaSize-${e}`,r!=null&&r.onError&&(r==null||r.onError(t,a)),a}const c=FN(n);if(l&&!l.includes(c)){const a=new Error(`media file is not allowed: ${c}`);return a.code="NotAllowedFile",r!=null&&r.onError&&(r==null||r.onError(t,a)),a}return!0}function UN(n){return n===Xs.Empty||n===Xs.Error}const pe=B("media");class VN{constructor(t){h(this,"mediaContainer",null);h(this,"media",null);h(this,"abstract",null);h(this,"handleMediaLoadError",(t,e)=>{if(!e.target||!(e.target instanceof Node)||!(e.target instanceof Element?e.target:e.target.parentElement))return;const r=F(e.target);if(!r||!r.contains(this.mediaContainer))return;const i=this.renderError();this.updateMediaContent(i)});h(this,"handleRetry",async t=>{if(t.readonly)return;d(pe,this.abstract,"no abstract");const{mediaType:e}=this.abstract,o=oC(t,e),r=await Fo(o);this.handleUploadFile(r)});h(this,"handleUploadFile",async t=>{d(pe,this.abstract,"no abstract"),d(pe,this.mediaContainer,"The media element not exist");const{editor:e}=this.options,{mediaType:o}=this.abstract,r=F(this.mediaContainer);d(pe,r,"The block element not exist");const i=e.getBlockData(r);if(!!zN(t,e,o))try{const{resourceId:s}=await e.doc.uploadResource(t,{onProgress:f=>{this.renderProgress(f,t)}}),{name:l,type:c,size:a}=t,u={...i,embedData:{...i.embedData,src:s,fileName:l,fileSize:a,fileType:c}};e.updateBlockData(r,u)}catch{this.renderRetry()}});h(this,"destroy",()=>{this.mediaContainer=null});this.options=t}bindMediaEvent(){const{editor:t}=this.options;this.media&&t.domEvents.addEventListener(this.media,"error",this.handleMediaLoadError)}unbindMediaEvent(){const{editor:t}=this.options;this.media&&t.domEvents.removeEventListener(this.media,"error",this.handleMediaLoadError)}updateMediaContent(t){d(pe,this.mediaContainer,"The media element not exist"),this.mediaContainer.innerHTML="",this.mediaContainer.append(t)}renderError(){d(pe,this.abstract,"no abstract");const{editor:t,createMediaElement:e}=this.options,{mediaIcon:o,mediaName:r}=this.abstract;d(pe,this.mediaContainer,"The media element not exist");const i=F(this.mediaContainer);d(pe,i,"The block element not exist");const s=t.getBlockData(i),l=s.embedData.src,c=b("div",["media-error","embed-selected-content","embed-hover-content"],null),a=b("span",["media-error-icon"],c);a.innerHTML=o;const u=b("div",[],c);u.innerHTML=T.t("media.load.failed",{name:r}),c.appendChild(u);const f=u.querySelector("a");return d(pe,f,"The element not exist"),t.domEvents.addEventListener(f,"click",(m,C)=>{if(C.preventDefault(),C.target instanceof HTMLElement&&C.target.tagName==="A"){const k=b("div",["media-element"],null),w=this.getResourceUrl(l),y=e(m,k,s,w);this.unbindMediaEvent(),this.media=y,this.bindMediaEvent(),this.updateMediaContent(k)}}),c}renderRetry(){d(pe,this.abstract,"no abstract");const{editor:t}=this.options,{mediaIcon:e,mediaName:o}=this.abstract,r=b("div",["media-error","embed-selected-content","embed-hover-content"],null),i=b("span",["media-error-icon"],r);i.innerHTML=e;const s=b("div",[],r);s.innerHTML=T.t("media.upload.failed",{name:o}),r.appendChild(s);const l=s.querySelector("a");d(pe,l,"The element not exist"),t.domEvents.addEventListener(l,"click",this.handleRetry),this.updateMediaContent(r)}renderProgress(t,e){d(pe,this.mediaContainer,"The media element not exist");const o=this.mediaContainer.querySelector(":scope .media-progress"),r=t===-1||t===100?100:t;if(o){const{updateProgressElement:i}=this.options;i(o,r)}else{const{createProgressElement:i}=this.options,s=b("div",["media-progress"],null);i(s,r,e),this.updateMediaContent(s)}}renderMediaElement(t){d(pe,this.mediaContainer,"The media element not exist");const e=this.mediaContainer.querySelector(":scope > .media-element"),{createMediaElement:o,updateMediaElement:r,editor:i}=this.options,s=this.getResourceUrl(t.embedData.src);if(e){const l=r(i,e,t,s);this.unbindMediaEvent(),this.media=l,this.bindMediaEvent()}else{const l=b("div",["media-element"],null),c=o(i,l,t,s);this.unbindMediaEvent(),this.media=c,this.bindMediaEvent(),this.updateMediaContent(l)}}renderEmpty(){d(pe,this.abstract,"no abstract"),d(pe,this.mediaContainer,"The media element not exist");const t=b("div",["media-empty","embed-selected-content","embed-hover-content"],this.mediaContainer);t.innerHTML=this.abstract.mediaIcon,this.updateMediaContent(t)}getResourceUrl(t){const{editor:e}=this.options;return e.doc.buildResourceUrl(t)}render(t,e){const{src:o}=t.embedData;(!this.mediaContainer||!e.contains(this.mediaContainer))&&(this.mediaContainer=b("div",["media"],e)),UN(o)?o===Xs.Empty&&this.renderEmpty():this.renderMediaElement(t)}setAbstract(t){this.abstract=t}}B("media-embed");class rC{constructor(){h(this,"handleInsertEmptyEmbed",async(t,e)=>{var u;const{containerId:o,blockIndex:r}=e;let i;(u=e.data)!=null&&u.file&&(i=e.data.file);const s=oC(t,this.embedType);if(i=i!=null?i:await Fo(s,{}),!i)return null;const l={id:N(),type:"embed",embedType:this.embedType,embedData:{src:Xs.Empty}},c=t.insertBlock(o,r,l);return await this.getMedia(t,l.id).handleUploadFile(i),c})}getMedia(t,e){const o=t.addCustom(`media-${e}`,()=>new VN({editor:t,createMediaElement:this.createMediaElement,updateMediaElement:this.updateMediaElement,createProgressElement:this.createProgressElement,updateProgressElement:this.updateProgressElement}));return o.setAbstract({...this.abstract}),o}getOptions(){const{menuItem:t,mediaIcon:e,mediaName:o,order:r,group:i}=this.abstract;return{name:o,insertEmbedCommandItems:[{id:`insert-${this.embedType}`,name:t,icon:e,order:r,group:i,subText:me(`insert-${this.embedType}`)}],handleInsertEmptyEmbed:this.handleInsertEmptyEmbed}}createEmbedContent(t,e,o){const{id:r}=o;this.getMedia(t,r).render(o,e)}handleUpdateBlock(t,e,o){const{id:r}=o,i=this.getMedia(t,r),s=it(e);return i.render(o,s),!0}handleDeleteBlock(t,e){const o=e.id;this.getMedia(t,o).destroy()}convertTo(t,e,o,r){const i=e.embedData,s=t.doc.buildResourceUrl(i.src,{withToken:!0});return r==="html"?`<${i.type} src="${s}" />`:r==="markdown"?`![${i.src}](${s})`:s}}function iC(n,t){const e=b("div",["uploading-progress-mask"],n),o=b("div",["uploading-progress-bar"],e),r=b("div",["uploading-progress-bar-value"],o);r.style.width=`${t}%`}function sC(n,t){const e=n.querySelector(".uploading-progress-bar-value");e&&(e.style.width=`${t}%`)}const qN=B("media-audio");class WN extends rC{constructor(){super(...arguments);h(this,"embedType",mn.AUDIO);h(this,"abstract",{mediaIcon:uB,mediaName:T.t(`media.${mn.AUDIO}.menuItem`),menuItem:T.t(`media.${mn.AUDIO}.menuItem`),order:800,mediaType:mn.AUDIO,group:"common"});h(this,"updateProgressElement",sC)}getBlockProperties(){return{abstract:`[${T.t(`media.${mn.AUDIO}.abstract`)}]`}}createMediaElement(e,o,r,i){const s=b("div",["audio-container","embed-hover-content","embed-selected-content"],o),l=b("audio",[],s);return l.innerHTML="Your browser does not support the <code>audio</code> element.",l.controls=!0,l.src=i,l}updateMediaElement(e,o,r,i){const s=o.querySelector(":scope .audio-container > audio");return d(qN,s,"The media element not exist"),s.src!==i&&(s.src=i),s}createProgressElement(e,o){const r=b("audio",[],e);r.innerHTML="Your browser does not support the <code>audio</code> element.",r.controls=!0,r.src="about:blank",iC(e,o)}}const mf=new WN;B("video-resizer");function lC(n){return n&&Te(n)&&Oe(n)==="video"}const GN=50;class ZN{constructor(t){h(this,"currentResizableElement",null);h(this,"resizing",!1);h(this,"handleHoveringBlockChange",(t,e)=>{if(!this.resizing&&(e&&lC(e)&&this.disableBlockResize(e),t&&lC(t))){const o=this.getVideoElement(t);if(!o)return;this.enableBlockResize(t,o)}});h(this,"handleResizing",(t,e)=>{if(this.resizing=!0,!this.currentResizableElement)return;const o=t.getBlock();if(!o)return;const r=o.getBoundingClientRect().width,i=Math.min(Math.max(e.width,GN),r);this.currentResizableElement.style.width=`${i}px`});h(this,"handleResized",t=>{this.resizing=!1;const e=t.getBlock();if(!this.currentResizableElement||!e)return;const o=this.editor.getBlockData(e),{width:r}=this.currentResizableElement.getBoundingClientRect();this.editor.updateBlockData(e,{...o,width:r})});this.editor=t,Nt.get(t).addListener("change",this.handleHoveringBlockChange)}destroy(){this.currentResizableElement=null,Nt.get(this.editor).removeListener("change",this.handleHoveringBlockChange)}getVideoElement(t){return it(t).querySelector(":scope .video-container > video")}disableBlockResize(t){const e=this.editor.findCustom(`${q(t)}-resizer`);e&&e.disableResize()}enableBlockResize(t,e){const o=this.editor.addCustom(`${q(t)}-resizer`,()=>new ta(this.editor,{resize:["top-left","top-right","bottom-left","bottom-right"]}));o.enableResize(t,e),o.removeListener("resizing",this.handleResizing),o.removeListener("resized",this.handleResized),o.addListener("resizing",this.handleResizing),o.addListener("resized",this.handleResized),this.currentResizableElement=e}}const YN=B("video");class QN extends rC{constructor(){super(...arguments);h(this,"embedType",mn.VIDEO);h(this,"abstract",{mediaName:T.t(`media.${mn.VIDEO}.menuItem`),mediaIcon:hB,menuItem:T.t(`media.${mn.VIDEO}.menuItem`),order:700,mediaType:mn.VIDEO,group:"common"});h(this,"updateProgressElement",sC);h(this,"createProgressElement",(e,o,r)=>{const i=b("video",["progress-video"],e);i.innerHTML="Your browser does not support the <code>audio</code> element.",i.controls=!0,iC(e,o),wl(r).then(s=>{const l=e.querySelector(".progress-video");l&&wd(e)&&(l.src=s)})})}getBlockProperties(){return{abstract:`[${T.t(`media.${mn.VIDEO}.abstract`)}]`}}createMediaElement(e,o,r,i){const s=b("div",["video-container","embed-selected-content","drag-preview-element"],o),l=b("video",[],s);return l.innerHTML="Your browser does not support the <code>video</code> element.",l.controls=!0,l.src=i,e.addCustom("video-resizer",()=>new ZN(e)),r.width&&(l.style.width=`${r.width}px`),l}updateMediaElement(e,o,r,i){const s=o.querySelector(":scope .video-container > video");return d(YN,s,"The media element not exist"),s.src!==i&&(s.src=i),s}}const gf=new QN,rU="",KN={version:{latest:"\u5F53\u524D\u7248\u672C",insert:"{name} \u6DFB\u52A0",delete:"{name} \u5220\u9664",goBack:"\u8FD4\u56DE",revertVersion:"\u8FD8\u539F\u5185\u5BB9",play:"\u64AD\u653E\u5386\u53F2\u64CD\u4F5C",versionList:"\u5386\u53F2\u8BB0\u5F55 {count}",unknown:"\u672A\u77E5\u7248\u672C",restoreFrom:"\u56DE\u6EDA\u81EA\u7248\u672C {from}",restoreInfo:"\u56DE\u6EDA\u7684\u7248\u672C\u6682\u4E0D\u652F\u6301\u4E0E\u4E0A\u4E00\u7248\u672C\u5BF9\u6BD4"}},JN={version:{latest:"Latest",insert:"Added by {name}",delete:"Deleted by {name}",goBack:"Back",revertVersion:"Revert",play:"Play",versionList:"Versions ({count})",unknown:"Unknown version",restoreFrom:"Reverted from {from}",restoreInfo:"The rolled back version does not currently support comparison with the previous version."}};T.mergeLang({"zh-CN":KN,"en-US":JN});var cC=(n=>(n.NEW="history-new",n.NEW_CHILD="history-new-child",n.DELETED="history-deleted",n.UPDATED="history-updated",n.HISTORY="history",n))(cC||{});const mi="--op-color",gi="--op-selected-color",iU="";class XN{constructor(t){h(this,"root");this.content=t;const e=b("div",["dialog-root"],null);e.append(t),this.root=e}show(t=document.body){t.append(this.root)}hide(){this.root.remove()}destroy(){}}const{t:pi}=T,aC=B("version-list");class t${constructor(t){h(this,"activeVersionElement");h(this,"versionsList");h(this,"versionsListHeader");h(this,"handleClickVersionItem",t=>{const o=t.target.closest(".dialog-version-list-item");if(this.isVersionElement(o)){this.toggleActiveVersionElement(o);const r=this.getVersionFromElement(o),{onSelectVersion:i}=this.options;i(r)}});this.options=t;const{versions:e,defaultSelectedIndex:o=0}=t,r=b("div",["version-dialog-list-header"],null,"count");r.innerText=pi("version.versionList",{count:`${e.length}`});const i=b("div",["version-dialog-list"],null),s=this.convertVersionsToFragment(e);i.append(s);const l=i.children[o];A(l,"active"),this.activeVersionElement=l,this.versionsList=i,this.versionsListHeader=r,i.onclick=this.handleClickVersionItem}get isSelectedFirstVersion(){return!!this.activeVersionElement&&this.versionsList.firstChild===this.activeVersionElement}get isSelectedLastVersion(){return!!this.activeVersionElement&&this.versionsList.lastChild===this.activeVersionElement}get beforeVersion(){return d(aC,this.activeVersionElement,"No active version element"),this.activeVersionElement.nextElementSibling?this.activeVersionElement.nextElementSibling.versionData:null}get beforeMajorVersion(){d(aC,this.activeVersionElement,"No active version element");let t=this.activeVersionElement.nextElementSibling;for(;t;){if(t.versionData.type)return t.versionData;t=t.nextElementSibling}return null}convertVersionsToFragment(t){const e=document.createDocumentFragment(),o=i=>{var l;let s;if(i.version!==-1){const c=new Date((l=i.created)!=null?l:i.version);s=`${c.toLocaleDateString()} ${c.toLocaleTimeString()}`}else s=pi("version.latest");return s},r=(i,s,l,c=!1)=>{var C;const a=b("div",["dialog-version-list-item"],e);a.versionData=i,s&&A(a,"child");const u=b("div",["dialog-version-list-item-title"],a);if(b("div",["dialog-version-list-item-date"],u,o(i)),c&&b("div",["dialog-version-list-item-now-ver"],u,pi("version.latest")),typeof i.source=="object"&&((C=i.source)==null?void 0:C.restore)){const k=i.source.restore,w=l.find(R=>R.version==k),y=w?o(w):pi("version.unknown"),S=pi("version.restoreFrom",{from:y}),I=pi("version.restoreInfo"),M=b("div",["dialog-version-item-from-container"],a);b("div",["dialog-version-item-from-main"],M,S),b("div",["dialog-version-item-from-info"],M,I)}const f=b("ul",["dialog-version-list-item-authors"],a),m=k=>{const w=b("li",["dialog-version-list-item-author"],f),y=b("span",["dialog-version-list-item-mark-author"],w);y.style.background=this.options.getMarkColor(k),b("span",["dialog-version-list-item-author-name"],w,k.displayName)};if(this.options.useCreatedBy)if(i.createdBy){const k=i.createdBy;m(k)}else i.authors&&i.authors.length>0&&i.authors.forEach(k=>{m(k)});else if(i.authors&&i.authors.length>0)i.authors.forEach(k=>{m(k)});else if(i.createdBy){const k=i.createdBy;m(k)}};return t.forEach((i,s)=>{r(i,!1,t,s===0),i.minorVersions&&i.minorVersions.length>0&&i.minorVersions.forEach(l=>{r(l,!0,t,!1)})}),e}isVersionElement(t){return t?nt(t,"dialog-version-list-item"):!1}getVersionFromElement(t){return t.versionData}get activeVersion(){return this.getVersionFromElement(this.activeVersionElement)}toggleActiveVersionElement(t){this.activeVersionElement!==t&&(z(this.activeVersionElement,"active"),A(t,"active"),this.activeVersionElement=t)}selectVersionByVersionNum(t){const e=Array.from(this.versionsList.children).find(o=>o.versionData.version===t);return this.isVersionElement(e)?(this.toggleActiveVersionElement(e),this.getVersionFromElement(e)):null}render(t){t.innerHTML="",t.append(this.versionsListHeader,this.versionsList)}destroy(){this.versionsList.onclick=null}}class e${constructor(t,e){this.doc=t,this.user=e}onDeleteBlock(t,e){this.doc.onDeleteBlock(t,e,this.user)}onInsertBlock(t,e,o){this.doc.onInsertBlock(t,e,o,this.user)}onUpdateBlockText(t,e,o){this.doc.onUpdateBlockText(t,e,o,this.user)}onUpdateBlockData(t,e,o){this.doc.onUpdateBlockData(t,e,o,this.user)}onCreateContainer(t,e){this.doc.onCreateContainer(t,e,this.user)}onCreateComment(){}onDeleteComment(){}onDeleteContainer(){}onUpdateComment(){}}function n$(n){return new Promise(t=>{setTimeout(t,n)})}async function o$(n,t,e,o){for(const r of e){const i=new e$(n,r.user);t.parseHistoryData(r,i),o.play&&await n$(o.speed||150)}}const r$=`<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24">
686
+ `:i.src?`[${i.fileName}](${n.doc.buildResourceUrl(i.src,{withToken:!0})})`:`[${i.fileName}]`}const MN={embedType:"office",createEmbedContent:TN,getBlockProperties:DN,convertTo:LN};function RN(n){const t=/(\s|^)(http|https):\/\/[\w\-]+(\.[\w\-]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?$/;return t.test(n)?n.search(t):-1}function AN(n){const t=n.selection.range;if(!t.isCollapsed()||!t.isSimple())return;const{start:e}=t,o=n.getBlockById(e.blockId);if(!P(n,o))return;const r=n.getBlockText(o),s=sp(r).slice(0,e.offset),l=RN(s);if(l===-1)return;const c=s.slice(l),a=s.length;let u=Vi(l,a-l,r,"link",c);return u=fo(u,a," ",null),n.setBlockText(o,u),n.selection.selectBlock(o,a+1),!0}const ON={Space:AN},oU="",_N={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 <a href="" class="retry-upload">\u91CD\u8BD5</a></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 <a href="" class="retry-upload">\u91CD\u8BD5</a></div>'},audio:{menuItem:"\u97F3\u9891",abstract:"\u97F3\u9891"},video:{menuItem:"\u89C6\u9891",abstract:"\u89C6\u9891"}}},NN={media:{upload:{failed:'<div class="line-1">{name} upload failed</div><div class="line-2">The network service is abnormal, you can <a href="" class="retry-upload">Try again</a></div>'},load:{failed:'<div class="line-1">{name} loading failed</div><div class="line-2">The network service is abnormal, you can <a href="" class="retry-upload">Try again</a></div>'},audio:{menuItem:"Audio",abstract:"Audio"},video:{menuItem:"Video",abstract:"Video"}}};T.mergeLang({"zh-CN":_N,"en-US":NN});var mn=(n=>(n.AUDIO="audio",n.VIDEO="video",n))(mn||{}),Xs=(n=>(n.Empty="empty",n.Progress="progress",n.Error="error",n))(Xs||{});const eC=10*1024*1024,$N=["wav","mp3","aac","ogg","webm","flac"],PN=["ogg","mp4","webm"],jN=()=>{};function nC(n){var u,f,m,C,k,w;const t=(u=n.getComponentOptions("media"))!=null?u:{},{allowedMedias:e,maxSize:o,callbacks:r}=t,i=(f=e==null?void 0:e.audio)!=null?f:$N,s=(m=e==null?void 0:e.video)!=null?m:PN,l=(C=o==null?void 0:o.audio)!=null?C:eC,c=(k=o==null?void 0:o.video)!=null?k:eC,a=(w=r==null?void 0:r.onError)!=null?w:jN;return{allowedMedias:{audio:i,video:s},maxSize:{audio:l,video:c},callbacks:{onError:a}}}const HN=B("file-utils");function FN(n){d(HN,n instanceof File,`The file: ${n} isn't instance of File`);const{name:t}=n;if(!t)return"";const e=t.lastIndexOf(".");return e===-1?"":t.slice(e+1)}function oC(n,t){const e=i=>i.map(s=>`.${s}`).join(","),{allowedMedias:o}=nC(n),r=o[t];return r?e(r):"*"}function zN(n,t,e){const{maxSize:o,callbacks:r,allowedMedias:i}=nC(t),{[e]:s}=o,{[e]:l}=i;if(s&&n.size>s){const a=new Error("media is too large");return a.code=`MaxMediaSize-${e}`,r!=null&&r.onError&&(r==null||r.onError(t,a)),a}const c=FN(n);if(l&&!l.includes(c)){const a=new Error(`media file is not allowed: ${c}`);return a.code="NotAllowedFile",r!=null&&r.onError&&(r==null||r.onError(t,a)),a}return!0}function UN(n){return n===Xs.Empty||n===Xs.Error}const pe=B("media");class VN{constructor(t){h(this,"mediaContainer",null);h(this,"media",null);h(this,"abstract",null);h(this,"handleMediaLoadError",(t,e)=>{if(!e.target||!(e.target instanceof Node)||!(e.target instanceof Element?e.target:e.target.parentElement))return;const r=F(e.target);if(!r||!r.contains(this.mediaContainer))return;const i=this.renderError();this.updateMediaContent(i)});h(this,"handleRetry",async t=>{if(t.readonly)return;d(pe,this.abstract,"no abstract");const{mediaType:e}=this.abstract,o=oC(t,e),r=await zo(o);this.handleUploadFile(r)});h(this,"handleUploadFile",async t=>{d(pe,this.abstract,"no abstract"),d(pe,this.mediaContainer,"The media element not exist");const{editor:e}=this.options,{mediaType:o}=this.abstract,r=F(this.mediaContainer);d(pe,r,"The block element not exist");const i=e.getBlockData(r);if(!!zN(t,e,o))try{const{resourceId:s}=await e.doc.uploadResource(t,{onProgress:f=>{this.renderProgress(f,t)}}),{name:l,type:c,size:a}=t,u={...i,embedData:{...i.embedData,src:s,fileName:l,fileSize:a,fileType:c}};e.updateBlockData(r,u)}catch{this.renderRetry()}});h(this,"destroy",()=>{this.mediaContainer=null});this.options=t}bindMediaEvent(){const{editor:t}=this.options;this.media&&t.domEvents.addEventListener(this.media,"error",this.handleMediaLoadError)}unbindMediaEvent(){const{editor:t}=this.options;this.media&&t.domEvents.removeEventListener(this.media,"error",this.handleMediaLoadError)}updateMediaContent(t){d(pe,this.mediaContainer,"The media element not exist"),this.mediaContainer.innerHTML="",this.mediaContainer.append(t)}renderError(){d(pe,this.abstract,"no abstract");const{editor:t,createMediaElement:e}=this.options,{mediaIcon:o,mediaName:r}=this.abstract;d(pe,this.mediaContainer,"The media element not exist");const i=F(this.mediaContainer);d(pe,i,"The block element not exist");const s=t.getBlockData(i),l=s.embedData.src,c=b("div",["media-error","embed-selected-content","embed-hover-content"],null),a=b("span",["media-error-icon"],c);a.innerHTML=o;const u=b("div",[],c);u.innerHTML=T.t("media.load.failed",{name:r}),c.appendChild(u);const f=u.querySelector("a");return d(pe,f,"The element not exist"),t.domEvents.addEventListener(f,"click",(m,C)=>{if(C.preventDefault(),C.target instanceof HTMLElement&&C.target.tagName==="A"){const k=b("div",["media-element"],null),w=this.getResourceUrl(l),y=e(m,k,s,w);this.unbindMediaEvent(),this.media=y,this.bindMediaEvent(),this.updateMediaContent(k)}}),c}renderRetry(){d(pe,this.abstract,"no abstract");const{editor:t}=this.options,{mediaIcon:e,mediaName:o}=this.abstract,r=b("div",["media-error","embed-selected-content","embed-hover-content"],null),i=b("span",["media-error-icon"],r);i.innerHTML=e;const s=b("div",[],r);s.innerHTML=T.t("media.upload.failed",{name:o}),r.appendChild(s);const l=s.querySelector("a");d(pe,l,"The element not exist"),t.domEvents.addEventListener(l,"click",this.handleRetry),this.updateMediaContent(r)}renderProgress(t,e){d(pe,this.mediaContainer,"The media element not exist");const o=this.mediaContainer.querySelector(":scope .media-progress"),r=t===-1||t===100?100:t;if(o){const{updateProgressElement:i}=this.options;i(o,r)}else{const{createProgressElement:i}=this.options,s=b("div",["media-progress"],null);i(s,r,e),this.updateMediaContent(s)}}renderMediaElement(t){d(pe,this.mediaContainer,"The media element not exist");const e=this.mediaContainer.querySelector(":scope > .media-element"),{createMediaElement:o,updateMediaElement:r,editor:i}=this.options,s=this.getResourceUrl(t.embedData.src);if(e){const l=r(i,e,t,s);this.unbindMediaEvent(),this.media=l,this.bindMediaEvent()}else{const l=b("div",["media-element"],null),c=o(i,l,t,s);this.unbindMediaEvent(),this.media=c,this.bindMediaEvent(),this.updateMediaContent(l)}}renderEmpty(){d(pe,this.abstract,"no abstract"),d(pe,this.mediaContainer,"The media element not exist");const t=b("div",["media-empty","embed-selected-content","embed-hover-content"],this.mediaContainer);t.innerHTML=this.abstract.mediaIcon,this.updateMediaContent(t)}getResourceUrl(t){const{editor:e}=this.options;return e.doc.buildResourceUrl(t)}render(t,e){const{src:o}=t.embedData;(!this.mediaContainer||!e.contains(this.mediaContainer))&&(this.mediaContainer=b("div",["media"],e)),UN(o)?o===Xs.Empty&&this.renderEmpty():this.renderMediaElement(t)}setAbstract(t){this.abstract=t}}B("media-embed");class rC{constructor(){h(this,"handleInsertEmptyEmbed",async(t,e)=>{var u;const{containerId:o,blockIndex:r}=e;let i;(u=e.data)!=null&&u.file&&(i=e.data.file);const s=oC(t,this.embedType);if(i=i!=null?i:await zo(s,{}),!i)return null;const l={id:N(),type:"embed",embedType:this.embedType,embedData:{src:Xs.Empty}},c=t.insertBlock(o,r,l);return await this.getMedia(t,l.id).handleUploadFile(i),c})}getMedia(t,e){const o=t.addCustom(`media-${e}`,()=>new VN({editor:t,createMediaElement:this.createMediaElement,updateMediaElement:this.updateMediaElement,createProgressElement:this.createProgressElement,updateProgressElement:this.updateProgressElement}));return o.setAbstract({...this.abstract}),o}getOptions(){const{menuItem:t,mediaIcon:e,mediaName:o,order:r,group:i}=this.abstract;return{name:o,insertEmbedCommandItems:[{id:`insert-${this.embedType}`,name:t,icon:e,order:r,group:i,subText:me(`insert-${this.embedType}`)}],handleInsertEmptyEmbed:this.handleInsertEmptyEmbed}}createEmbedContent(t,e,o){const{id:r}=o;this.getMedia(t,r).render(o,e)}handleUpdateBlock(t,e,o){const{id:r}=o,i=this.getMedia(t,r),s=it(e);return i.render(o,s),!0}handleDeleteBlock(t,e){const o=e.id;this.getMedia(t,o).destroy()}convertTo(t,e,o,r){const i=e.embedData,s=t.doc.buildResourceUrl(i.src,{withToken:!0});return r==="html"?`<${i.type} src="${s}" />`:r==="markdown"?`![${i.src}](${s})`:s}}function iC(n,t){const e=b("div",["uploading-progress-mask"],n),o=b("div",["uploading-progress-bar"],e),r=b("div",["uploading-progress-bar-value"],o);r.style.width=`${t}%`}function sC(n,t){const e=n.querySelector(".uploading-progress-bar-value");e&&(e.style.width=`${t}%`)}const qN=B("media-audio");class WN extends rC{constructor(){super(...arguments);h(this,"embedType",mn.AUDIO);h(this,"abstract",{mediaIcon:uB,mediaName:T.t(`media.${mn.AUDIO}.menuItem`),menuItem:T.t(`media.${mn.AUDIO}.menuItem`),order:800,mediaType:mn.AUDIO,group:"common"});h(this,"updateProgressElement",sC)}getBlockProperties(){return{abstract:`[${T.t(`media.${mn.AUDIO}.abstract`)}]`}}createMediaElement(e,o,r,i){const s=b("div",["audio-container","embed-hover-content","embed-selected-content"],o),l=b("audio",[],s);return l.innerHTML="Your browser does not support the <code>audio</code> element.",l.controls=!0,l.src=i,l}updateMediaElement(e,o,r,i){const s=o.querySelector(":scope .audio-container > audio");return d(qN,s,"The media element not exist"),s.src!==i&&(s.src=i),s}createProgressElement(e,o){const r=b("audio",[],e);r.innerHTML="Your browser does not support the <code>audio</code> element.",r.controls=!0,r.src="about:blank",iC(e,o)}}const mf=new WN;B("video-resizer");function lC(n){return n&&Te(n)&&Oe(n)==="video"}const GN=50;class ZN{constructor(t){h(this,"currentResizableElement",null);h(this,"resizing",!1);h(this,"handleHoveringBlockChange",(t,e)=>{if(!this.resizing&&(e&&lC(e)&&this.disableBlockResize(e),t&&lC(t))){const o=this.getVideoElement(t);if(!o)return;this.enableBlockResize(t,o)}});h(this,"handleResizing",(t,e)=>{if(this.resizing=!0,!this.currentResizableElement)return;const o=t.getBlock();if(!o)return;const r=o.getBoundingClientRect().width,i=Math.min(Math.max(e.width,GN),r);this.currentResizableElement.style.width=`${i}px`});h(this,"handleResized",t=>{this.resizing=!1;const e=t.getBlock();if(!this.currentResizableElement||!e)return;const o=this.editor.getBlockData(e),{width:r}=this.currentResizableElement.getBoundingClientRect();this.editor.updateBlockData(e,{...o,width:r})});this.editor=t,Nt.get(t).addListener("change",this.handleHoveringBlockChange)}destroy(){this.currentResizableElement=null,Nt.get(this.editor).removeListener("change",this.handleHoveringBlockChange)}getVideoElement(t){return it(t).querySelector(":scope .video-container > video")}disableBlockResize(t){const e=this.editor.findCustom(`${q(t)}-resizer`);e&&e.disableResize()}enableBlockResize(t,e){const o=this.editor.addCustom(`${q(t)}-resizer`,()=>new ta(this.editor,{resize:["top-left","top-right","bottom-left","bottom-right"]}));o.enableResize(t,e),o.removeListener("resizing",this.handleResizing),o.removeListener("resized",this.handleResized),o.addListener("resizing",this.handleResizing),o.addListener("resized",this.handleResized),this.currentResizableElement=e}}const YN=B("video");class QN extends rC{constructor(){super(...arguments);h(this,"embedType",mn.VIDEO);h(this,"abstract",{mediaName:T.t(`media.${mn.VIDEO}.menuItem`),mediaIcon:hB,menuItem:T.t(`media.${mn.VIDEO}.menuItem`),order:700,mediaType:mn.VIDEO,group:"common"});h(this,"updateProgressElement",sC);h(this,"createProgressElement",(e,o,r)=>{const i=b("video",["progress-video"],e);i.innerHTML="Your browser does not support the <code>audio</code> element.",i.controls=!0,iC(e,o),wl(r).then(s=>{const l=e.querySelector(".progress-video");l&&wd(e)&&(l.src=s)})})}getBlockProperties(){return{abstract:`[${T.t(`media.${mn.VIDEO}.abstract`)}]`}}createMediaElement(e,o,r,i){const s=b("div",["video-container","embed-selected-content","drag-preview-element"],o),l=b("video",[],s);return l.innerHTML="Your browser does not support the <code>video</code> element.",l.controls=!0,l.src=i,e.addCustom("video-resizer",()=>new ZN(e)),r.width&&(l.style.width=`${r.width}px`),l}updateMediaElement(e,o,r,i){const s=o.querySelector(":scope .video-container > video");return d(YN,s,"The media element not exist"),s.src!==i&&(s.src=i),s}}const gf=new QN,rU="",KN={version:{latest:"\u5F53\u524D\u7248\u672C",insert:"{name} \u6DFB\u52A0",delete:"{name} \u5220\u9664",goBack:"\u8FD4\u56DE",revertVersion:"\u8FD8\u539F\u5185\u5BB9",play:"\u64AD\u653E\u5386\u53F2\u64CD\u4F5C",versionList:"\u5386\u53F2\u8BB0\u5F55 {count}",unknown:"\u672A\u77E5\u7248\u672C",restoreFrom:"\u56DE\u6EDA\u81EA\u7248\u672C {from}",restoreInfo:"\u56DE\u6EDA\u7684\u7248\u672C\u6682\u4E0D\u652F\u6301\u4E0E\u4E0A\u4E00\u7248\u672C\u5BF9\u6BD4"}},JN={version:{latest:"Latest",insert:"Added by {name}",delete:"Deleted by {name}",goBack:"Back",revertVersion:"Revert",play:"Play",versionList:"Versions ({count})",unknown:"Unknown version",restoreFrom:"Reverted from {from}",restoreInfo:"The rolled back version does not currently support comparison with the previous version."}};T.mergeLang({"zh-CN":KN,"en-US":JN});var cC=(n=>(n.NEW="history-new",n.NEW_CHILD="history-new-child",n.DELETED="history-deleted",n.UPDATED="history-updated",n.HISTORY="history",n))(cC||{});const mi="--op-color",gi="--op-selected-color",iU="";class XN{constructor(t){h(this,"root");this.content=t;const e=b("div",["dialog-root"],null);e.append(t),this.root=e}show(t=document.body){t.append(this.root)}hide(){this.root.remove()}destroy(){}}const{t:pi}=T,aC=B("version-list");class t${constructor(t){h(this,"activeVersionElement");h(this,"versionsList");h(this,"versionsListHeader");h(this,"handleClickVersionItem",t=>{const o=t.target.closest(".dialog-version-list-item");if(this.isVersionElement(o)){this.toggleActiveVersionElement(o);const r=this.getVersionFromElement(o),{onSelectVersion:i}=this.options;i(r)}});this.options=t;const{versions:e,defaultSelectedIndex:o=0}=t,r=b("div",["version-dialog-list-header"],null,"count");r.innerText=pi("version.versionList",{count:`${e.length}`});const i=b("div",["version-dialog-list"],null),s=this.convertVersionsToFragment(e);i.append(s);const l=i.children[o];A(l,"active"),this.activeVersionElement=l,this.versionsList=i,this.versionsListHeader=r,i.onclick=this.handleClickVersionItem}get isSelectedFirstVersion(){return!!this.activeVersionElement&&this.versionsList.firstChild===this.activeVersionElement}get isSelectedLastVersion(){return!!this.activeVersionElement&&this.versionsList.lastChild===this.activeVersionElement}get beforeVersion(){return d(aC,this.activeVersionElement,"No active version element"),this.activeVersionElement.nextElementSibling?this.activeVersionElement.nextElementSibling.versionData:null}get beforeMajorVersion(){d(aC,this.activeVersionElement,"No active version element");let t=this.activeVersionElement.nextElementSibling;for(;t;){if(t.versionData.type)return t.versionData;t=t.nextElementSibling}return null}convertVersionsToFragment(t){const e=document.createDocumentFragment(),o=i=>{var l;let s;if(i.version!==-1){const c=new Date((l=i.created)!=null?l:i.version);s=`${c.toLocaleDateString()} ${c.toLocaleTimeString()}`}else s=pi("version.latest");return s},r=(i,s,l,c=!1)=>{var C;const a=b("div",["dialog-version-list-item"],e);a.versionData=i,s&&A(a,"child");const u=b("div",["dialog-version-list-item-title"],a);if(b("div",["dialog-version-list-item-date"],u,o(i)),c&&b("div",["dialog-version-list-item-now-ver"],u,pi("version.latest")),typeof i.source=="object"&&((C=i.source)==null?void 0:C.restore)){const k=i.source.restore,w=l.find(R=>R.version==k),y=w?o(w):pi("version.unknown"),S=pi("version.restoreFrom",{from:y}),I=pi("version.restoreInfo"),M=b("div",["dialog-version-item-from-container"],a);b("div",["dialog-version-item-from-main"],M,S),b("div",["dialog-version-item-from-info"],M,I)}const f=b("ul",["dialog-version-list-item-authors"],a),m=k=>{const w=b("li",["dialog-version-list-item-author"],f),y=b("span",["dialog-version-list-item-mark-author"],w);y.style.background=this.options.getMarkColor(k),b("span",["dialog-version-list-item-author-name"],w,k.displayName)};if(this.options.useCreatedBy)if(i.createdBy){const k=i.createdBy;m(k)}else i.authors&&i.authors.length>0&&i.authors.forEach(k=>{m(k)});else if(i.authors&&i.authors.length>0)i.authors.forEach(k=>{m(k)});else if(i.createdBy){const k=i.createdBy;m(k)}};return t.forEach((i,s)=>{r(i,!1,t,s===0),i.minorVersions&&i.minorVersions.length>0&&i.minorVersions.forEach(l=>{r(l,!0,t,!1)})}),e}isVersionElement(t){return t?nt(t,"dialog-version-list-item"):!1}getVersionFromElement(t){return t.versionData}get activeVersion(){return this.getVersionFromElement(this.activeVersionElement)}toggleActiveVersionElement(t){this.activeVersionElement!==t&&(z(this.activeVersionElement,"active"),A(t,"active"),this.activeVersionElement=t)}selectVersionByVersionNum(t){const e=Array.from(this.versionsList.children).find(o=>o.versionData.version===t);return this.isVersionElement(e)?(this.toggleActiveVersionElement(e),this.getVersionFromElement(e)):null}render(t){t.innerHTML="",t.append(this.versionsListHeader,this.versionsList)}destroy(){this.versionsList.onclick=null}}class e${constructor(t,e){this.doc=t,this.user=e}onDeleteBlock(t,e){this.doc.onDeleteBlock(t,e,this.user)}onInsertBlock(t,e,o){this.doc.onInsertBlock(t,e,o,this.user)}onUpdateBlockText(t,e,o){this.doc.onUpdateBlockText(t,e,o,this.user)}onUpdateBlockData(t,e,o){this.doc.onUpdateBlockData(t,e,o,this.user)}onCreateContainer(t,e){this.doc.onCreateContainer(t,e,this.user)}onCreateComment(){}onDeleteComment(){}onDeleteContainer(){}onUpdateComment(){}}function n$(n){return new Promise(t=>{setTimeout(t,n)})}async function o$(n,t,e,o){for(const r of e){const i=new e$(n,r.user);t.parseHistoryData(r,i),o.play&&await n$(o.speed||150)}}const r$=`<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24">
687
687
  <path d="M0 0h24v24H0z" fill="none"/><path d="M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"/>
688
- </svg>`,{t:pf}=T;class i${constructor(t){h(this,"goBackButton");h(this,"playButton");h(this,"revertButton");this.options=t;const e=b("button",["dialog-text-button"],null),o=b("span",["dialog-button-icon"],e);o.innerHTML=r$,b("span",["dialog-button-text"],e,pf("version.goBack"));const r=b("button",["dialog-version-button"],null,pf("version.play")),i=b("button",["dialog-version-button"],null,pf("version.revertVersion"));this.goBackButton=e,this.playButton=r,this.revertButton=i,this.bindEvent()}bindEvent(){const{onBack:t,onPlay:e,onRevert:o}=this.options;this.playButton.onclick=e,this.goBackButton.onclick=t,this.revertButton.onclick=o}disabledButton(){}render(t,e=!1){e||t.append(this.goBackButton,this.playButton,this.revertButton)}destroy(){this.playButton.onclick=null,this.goBackButton.onclick=null,this.revertButton.onclick=null}}const Ce=B("split-text-actions");function dC(n){return n.length>2?!1:n.length===1?n[0].insert!==void 0:(d(Ce,n.length===2,`invalid text actions: ${JSON.stringify(n)}`),n[0].retain===void 0?!1:n[1].insert!==void 0)}function uC(n){return n.length>2?!1:n.length===1?n[0].delete!==void 0:(d(Ce,n.length===2,`invalid text actions: ${JSON.stringify(n)}`),n[0].retain===void 0?!1:n[1].delete!==void 0)}function hC(n){return n.length>2?!1:n.length===1?n[0].insert===void 0&&n[0].delete===void 0&&n[0].attributes!==void 0:(d(Ce,n.length===2,`invalid text actions: ${JSON.stringify(n)}`),n[0].retain===void 0?!1:n[1].attributes!==void 0)}function s$(n){const t=[],e=Y.default(n);if(e.length===0)return[];if(e.length===1)return[n];if(e.length===2&&(uC(n)||dC(n)||hC(n)))return[n];const o=(i,s)=>i>0?[{retain:i},s]:[s];let r=0;for(;e.length>0;){const i=e[0];if(i.retain!==void 0&&i.attributes===void 0){d(Ce,i.retain>0,`invalid text op: ${JSON.stringify(i)}`),d(Ce,e.length>1,`invalid text op: ${JSON.stringify(i)}`);const s=e[1];d(Ce,s.delete||s.insert!==void 0||s.attributes!==void 0,`invalid next text op: ${JSON.stringify(s)}`),r+=i.retain,t.push(o(r,s)),s.delete!==void 0?r-=s.delete:s.insert!==void 0?r+=s.insert.length:(d(Ce,s.attributes!==void 0,`invalid next text op: ${JSON.stringify(s)}`),d(Ce,s.retain!==void 0,`invalid next text op: ${JSON.stringify(s)}`),r+=s.retain),e.splice(0,2)}else d(Ce,i.delete||i.insert!==void 0||i.attributes!==void 0,`invalid next text op: ${JSON.stringify(i)}`),t.push(o(r,i)),e.shift(),i.retain!==void 0&&(d(Ce,i.attributes!==void 0,`invalid next text op: ${JSON.stringify(i)}`),r+=i.retain),i.insert&&(r+=i.insert.length)}return t}function fC(n){if(d(Ce,n.length===1||n.length===2,`not a single action op: ${JSON.stringify(n)}`),n.length===1)return 0;const t=n[0].retain;return d(Ce,typeof t=="number"&&t>0,`invalid retain: ${JSON.stringify(n)}`),t}let mC=0;function l$(n,t,e){const o=mC;mC+=1;const r=bt(n);return{insert:" ",attributes:{box:!0,id:N(),type:"history-deleted-box",user:e,created:Date.now(),text:r,deletedOffset:t,deletedOrder:o}}}function c$(n,t,e){const o=fC(t),r=t.length===1?t[0].delete:t[1].delete;d(Ce,typeof r=="number",`not a delete op: ${JSON.stringify(t)}`);const{left:i,middle:s,right:l}=Wt(n,o,r),c=l$(s,o,e);return[...i,c,...l]}function a$(n,t,e){const o=fC(t),r=t.length===1?t[0].insert:t[1].insert;d(Ce,typeof r=="string",`invalid insert op: ${JSON.stringify(t)}`);const i=t.length===1?t[0].attributes:t[1].attributes,l=Fl([{insert:r,attributes:i}],"insertedBy",e);return ho(n,o,l,null)}function d$(n,t,e){const o=s$(t).reverse();let r=n;for(const i of o)uC(i)?r=c$(r,i,e):dC(i)?r=a$(r,i,e):(d(Ce,hC(i),`unknown op: ${JSON.stringify(i)}`),r=ie.apply(r,i));return r}const u$=B("history-update-block-text");function gC(n){const t=[],e=[];let o=0;return n.forEach(r=>{var i;if((i=r.attributes)!=null&&i.box){const s=r.attributes;if(s.type==="history-deleted-box"){t.push({boxData:s,offset:o});return}}e.push(r),o+=Wd(r)}),t.sort((r,i)=>i.offset-r.offset),{deletedBoxes:t,newText:e}}function h$(n,t,e){let o=n;return t.forEach(r=>{const i=ie.transformCursor(r.offset,e,!1);o=ho(o,i,[{insert:" ",attributes:r.boxData}],null)}),o}function f$(n){n.sort((t,e)=>t.boxData.deletedOffset!==e.boxData.deletedOffset?t.boxData.deletedOffset-e.boxData.deletedOffset:t.boxData.deletedOrder-e.boxData.deletedOrder)}function m$(n){if(n.length<=1)return n;const t=n[0].offset;n.forEach(e=>{d(u$,e.offset===t,`invalid boxes group, ${JSON.stringify(n)}`)}),f$(n);for(let e=n.length-1;e>=1;e--){const o=n[e],r=n[e-1];o.boxData.user.userId===r.boxData.user.userId&&(r.boxData.text+=o.boxData.text,n.splice(e,1))}return n}function g$(n){let{newText:t,deletedBoxes:e}=gC(n);const o=new Map;return e.forEach(i=>{let s=o.get(i.offset);s||(s=[],o.set(i.offset,s)),s.push(i),s.sort((l,c)=>l.boxData.deletedOffset-c.boxData.deletedOffset)}),Array.from(o.values()).sort((i,s)=>s[0].offset-i[0].offset).forEach(i=>{const s=i[0].offset;m$(i).reverse().forEach(l=>{t=ho(t,s,[{insert:" ",attributes:l.boxData}],null)})}),t}function p$(n,t,e){let{newText:o,deletedBoxes:r}=gC(n);return o=d$(o,t,e),o=h$(o,r,t),o=g$(o),o}const Rn=B("history-doc");function An(n){d(Rn,!1,"no local actions for history doc")}class C$ extends Di{constructor(e,o){super();h(this,"doc");h(this,"editor");this.doc=Y.default(e),this.editor=o}beginBatchUpdate(){return 0}endBatchUpdate(){return 0}toJSON(){return Y.default(this.doc)}getContainerBlocks(e){return this.doc.blocks[e]}getBlockData(e,o){const r=this.getContainerBlocks(e);d(Rn,r,`no container data: ${e}`);const i=r[o];return d(Rn,i,`no block data: ${o}`),i}localUpdateBlockText(){An()}localUpdateBlockData(){An()}localInsertBlock(){An()}localDeleteBlock(){An()}localInsertChildContainer(){An()}localDeleteChildContainers(){An()}uploadResource(){An()}async addResources(e){An()}getServerMeta(){var e,o,r;return(r=(o=(e=this.editor.doc.externalDoc).getServerMeta)==null?void 0:o.call(e))!=null?r:{}}buildResourceUrl(e){return this.editor.doc.externalDoc.buildResourceUrl(e)}request(){An()}broadcastMessage(){An()}getUser(){return{permission:"w",userId:"-",displayName:"-",avatarUrl:"-",rainbowIndex:0}}getRemoteUsers(){return new uc}destroy(){this.clearCallbacks()}transformBlockIndex(e,o,r){const i=this.doc.blocks[e];d(Rn,i,`no container blocks: ${e}`);let s=0;for(let l=0;l<i.length;l++)if(!i[l].deletedBy){if(s===o)return l;s++}return r&&d(Rn,!1,`invalid block index: ${o}, blocks: ${JSON.stringify(i)}`),d(Rn,s===o,`invalid block index: ${o}, blocks: ${JSON.stringify(i)}`),i.length}onDeleteBlock(e,o,r){const i=this.transformBlockIndex(e,o,!0),l=this.doc.blocks[e][i];d(Rn,!l.deleted,`block has already deleted: ${e}/${o}`),l.deletedBy=r,this.callbacks.forEach(c=>{var a;return(a=c.onUpdateBlockData)==null?void 0:a.call(c,e,i,{insert:{},delete:[]},!0)})}onInsertBlock(e,o,r,i){const s=this.transformBlockIndex(e,o,!1),l=this.doc.blocks[e],c=Y.default(r);c.insertedBy=i,l.splice(s,0,c),this.callbacks.forEach(a=>{var u;return(u=a.onInsertBlock)==null?void 0:u.call(a,e,s,c,!0)})}onUpdateBlockText(e,o,r,i){const s=this.transformBlockIndex(e,o,!0),c=this.doc.blocks[e][s];d(Rn,!c.deleted,`block has already deleted: ${e}/${o}`);const a=c.text;d(Rn,a,`no text for block: ${JSON.stringify(c)}`);const u=p$(a,r,i);c.text=u,this.callbacks.forEach(f=>{var m;return(m=f.onUpdateBlockText)==null?void 0:m.call(f,e,o,r,!0)})}onUpdateBlockData(e,o,r,i){const s=this.transformBlockIndex(e,o,!0),l=this.doc.blocks[e],c=l[s];d(Rn,!c.deleted,`block has already deleted: ${e}/${o}`);const a=Y.default(c);a.updatedBy=i,r.delete.forEach(u=>delete a[u]),Object.entries(r.insert).forEach(([u,f])=>{a[u]=f}),l[s]=a,this.callbacks.forEach(u=>{var f;return(f=u.onUpdateBlockData)==null?void 0:f.call(u,e,s,r,!0)})}onCreateContainer(e,o,r){this.doc.blocks[e]=Y.default(o),this.callbacks.forEach(i=>{var s;return(s=i.onInsertChildContainer)==null?void 0:s.call(i,e,o,!0)})}}const{t:pC}=T;function Ci(n,t){return t==="insert"?pC("version.insert",{name:n.displayName}):pC("version.delete",{name:n.displayName})}function fr(n,t){const{userId:e}=t;return["flag","selection"].reduce((r,i)=>{const s=n.doc.getRemoteUsers().getFixedUserColor(e,i);return r[i]=s,r},{})}class b${renderText(t,e,o){if(!o.box&&o.insertedBy){const r=o.insertedBy,{flag:i,selection:s}=fr(t,o.insertedBy);return{classes:["history-inserted-text"],attributes:{"history-inserted-by":r.displayName,"data-op-description":Ci(r,"insert")},styles:{[mi]:i,[gi]:s}}}return{}}renderBlock(t,e,o){if(o.deletedBy){const r=o.deletedBy,{flag:i,selection:s}=fr(t,r);return{classes:["history-deleted-block"],attributes:{"history-deleted-by":r.displayName,"data-op-description":Ci(r,"delete")},styles:{[mi]:i,[gi]:s}}}if(o.insertedBy){const r=o.insertedBy,{flag:i,selection:s}=fr(t,r);return{classes:["history-inserted-block"],attributes:{"history-inserted-by":r.displayName,"data-op-description":Ci(r,"insert")},styles:{[mi]:i,[gi]:s}}}return{}}updateBlock(t,e,o,r){if(r.deletedBy){const i=r.deletedBy,{flag:s,selection:l}=fr(t,i);A(o,"history-deleted-block"),od(o,{"history-inserted-by":i.displayName,"data-op-description":Ci(i,"delete")}),rd(o,{[mi]:s,[gi]:l});return}if(r.insertedBy){const i=r.insertedBy,{flag:s,selection:l}=fr(t,i);A(o,"history-inserted-block"),od(o,{"history-inserted-by":i.displayName,"data-op-description":Ci(i,"insert")}),rd(o,{[mi]:s,[gi]:l})}}}const CC=B("history-deleted-box");function k$(n,t,e,o){const r=o;d(CC,r.text,`no text for text box data: ${JSON.stringify(o)}`),d(CC,typeof r.text=="string",`invalid text type for text box data: ${JSON.stringify(o)}`);const i=b("span",["history-deleted-box"],e,r.text),s=r.user,{flag:l,selection:c}=fr(n,s);i.setAttribute("history-deleted-by",s.displayName),i.setAttribute("data-op-description",Ci(s,"delete")),i.style.setProperty(mi,l),i.style.setProperty(gi,c)}function v$(n,t,e,o){return t.text}const y$={boxType:"history-deleted-box",updateBoxContent:k$,convertTo:v$},Ee=B("version-dialog");class w${constructor(t,e){h(this,"editor");h(this,"dialog",null);h(this,"oldViewer",null);h(this,"versionOptions");h(this,"versionList",null);h(this,"actionButtons",null);h(this,"provider");h(this,"components");h(this,"handleClose",()=>{var t;(t=this.dialog)==null||t.hide()});h(this,"handlePlay",()=>{var e;d(Ee,this.versionList,"The versionList did not render");const t=(e=this.versionList)==null?void 0:e.activeVersion;d(Ee,t,`The version: ${t} is invalid`),this.viewVersion(t,{play:!0,speed:150})});h(this,"handleRevert",async()=>{var e,o;d(Ee,this.versionList,"The versionList did not render");const t=(e=this.versionList)==null?void 0:e.activeVersion;d(Ee,t,`The version: ${t} is invalid`),await this.versionHelper.revertVersion(t.version),(o=this.dialog)==null||o.hide()});h(this,"handleSelectVersion",t=>{d(Ee,t,`The version: ${t} is invalid`),this.viewVersion(t)});h(this,"viewVersion",async(t,e={play:!1,speed:1e3})=>{var C,k,w;this.oldViewer&&(this.oldViewer.destroy(),this.oldViewer=null),d(Ee,this.versionList,"The versionList did not render"),d(Ee,this.actionButtons,"The actionButtons did not render");const o=t.type==="minor"?this.versionList.beforeVersion:this.versionList.beforeMajorVersion,r=o?o.version:0,i=this.versionList.isSelectedFirstVersion,s=this.versionList.isSelectedLastVersion;this.actionButtons.revertButton.disabled=i,this.actionButtons.playButton.disabled=i;let l=(C=this.versionOptions)==null?void 0:C.hideOps;if((k=this.versionOptions)!=null&&k.onWillChangeVersion){const y=this.versionOptions.onWillChangeVersion(this.editor,t,i,s);y!=null&&y.hideOps&&(l=!0)}let c,a;if(l)c=await this.versionHelper.getVersion(t.version),a=[];else{const y=await this.versionHelper.getHistoryData(t.version,r);c=y.doc,a=y.historyData}const{editorElement:u}=this.components;u.innerHTML="";const f=new C$(c,this.editor),m=this.provider.createHistoryEditor(u,f);m.editorBlockRenders.registerRender(new b$),m.editorBoxes.registerBoxClass(y$),A(m.rootElement,cC.HISTORY);try{await o$(f,this.versionHelper,a,e)}finally{this.oldViewer=m}(w=this.versionOptions)!=null&&w.onVersionChanged&&this.versionOptions.onVersionChanged(this.editor,m,t,i,s)});h(this,"setShowOps",t=>{var e;if(this.versionOptions){this.versionOptions.hideOps=!t;const o=(e=this.versionList)==null?void 0:e.activeVersion;d(Ee,o,`The version: ${o} is invalid`),this.viewVersion(o)}});this.editor=t,this.provider=e;const o=b("div",["version-dialog"],null),r=b("div",["version-dialog-note-viewer"],o),i=b("div",["version-dialog-action-container"],r),s=b("div",["version-dialog-editor"],r),l=b("div",["version-dialog-versions-list"],o);this.components={root:o,editorElement:s,actionContainer:i,versionsListContainer:l}}get versionHelper(){d(Ee,this.editor.doc.getVersionHelper,"Can not get getVersionHelper from doc");const t=this.editor.doc.getVersionHelper();return d(Ee,t,"current doc does not support version"),t}renderContent(t){var s,l;const{actionContainer:e,versionsListContainer:o}=this.components;e.innerHTML="";const r=new i$({onBack:this.handleClose,onPlay:this.handlePlay,onRevert:this.handleRevert});r.render(e,(s=this.versionOptions)==null?void 0:s.hideActions),this.actionButtons=r,o.innerHTML="";const i=new t$({versions:t,useCreatedBy:(l=this.versionOptions)==null?void 0:l.useCreatedBy,onSelectVersion:this.handleSelectVersion,getMarkColor:c=>{const{flag:a}=fr(this.editor,c);return a}});i.render(o),this.versionList=i}initViewVersion(){var t;if((t=this.versionOptions)!=null&&t.initSelectedVersion){d(Ee,this.versionList,"The versionList did not render");const{initSelectedVersion:e}=this.versionOptions,o=this.versionList.selectVersionByVersionNum(e);d(Ee,o,`The version: ${o} is invalid`),this.viewVersion(o)}else{d(Ee,this.versionList,"The versionList did not render");const e=this.versionList.activeVersion;d(Ee,e,`The version: ${e} is invalid`),this.viewVersion(e)}}async show(t){this.versionOptions={...this.versionOptions,...t};const e=await this.versionHelper.getVersions();if(this.versionOptions.hideNonVersionedOps&&e.length&&e[0].version===-1&&e.shift(),this.versionOptions.onVersionsLoaded&&this.versionOptions.onVersionsLoaded(this.editor,e),this.renderContent(e),this.initViewVersion(),!this.dialog){const{root:o}=this.components;this.dialog=new XN(o)}this.dialog.show(t.container)}destroy(){var t,e,o;(t=this.dialog)==null||t.destroy(),(e=this.versionList)==null||e.destroy(),(o=this.actionButtons)==null||o.destroy()}}function B$(n,t,e){const o=n.addCustom("version-dialog",()=>new w$(n,t));return o.show(e),{setShowOps:o.setShowOps}}const sU="",E$=B("heading-collapse");function Cf(n){var e;const t=Number.parseInt((e=n.getAttribute("data-style-heading"))!=null?e:"",10);return d(E$,t,"not a heading block"),t}function ze(n){return!!n.getAttribute("data-style-heading")}function I$(n){return!nt(n,"heading-collapsed")}function mr(n){return nt(n,"heading-collapsed")}function bC(n){if(gt(n))return!1;const e=H(n);return pt(e)}const x$=B("heading-collapse");function bf(n){d(x$,ze(n),"not a heading block");const t=[],e=Cf(n);let o=dt(n);for(;o&&!(ze(o)&&Cf(o)<=e);)t.push(o),o=dt(o);return t}function kC(n,t){if(!po(t))return;n.selection.selectBlock(t,0),bf(t).forEach(o=>{Um(o)}),A(t,"heading-collapsed")}function bi(n,t){bf(t).forEach(o=>{Vm(o)}),z(t,"heading-collapsed")}function T$(n,t){I$(t)?kC(n,t):bi(n,t)}const S$=[nh,oh,rh,ih,sh,lh,ch,ah];function D$(n){const t=b("button",["heading-collapse-button"],null);return t.setAttribute(`data-editor-tooltip-${n.clientId}`,"Collapse / Expand"),t.innerHTML=eh,t}function vC(n){return ca(n).querySelector("button.heading-collapse-button")}function yC(n,t){vC(t)||bC(t)||!po(t)||R1(t,D$(n),-1)}function L$(n){var t;(t=vC(n))==null||t.remove()}function wC(n,t){ca(t).querySelector("button.heading-collapse-button")||yC(n,t)}function M$(n){const t=Cf(n),e=b("button",["heading-marker"],null);return e.innerHTML=S$[t-1],e}function BC(n){return ca(n).querySelector("button.heading-marker")}function kf(n){BC(n)||bC(n)||!po(n)||R1(n,M$(n),1)}function EC(n){const t=BC(n);t==null||t.remove()}function IC(n){EC(n),ze(n)&&kf(n)}class R${handleDrop(t,e,o,r){if(xl(e)||!ze(e)||!mr(e))return;const i=bf(e);i.unshift(e);const s=i.reverse();let l=null;return t.doc.beginBatchUpdate(),s.forEach((c,a,u)=>{const f=t.getBlockData(c),m=mo(t.editorBlocks,t.doc.toJSON(),f),C=t.insertDocAt(o,r,m)[0];a===u.length-1&&(l=C)}),t.doc.endBatchUpdate(),t.doc.beginBatchUpdate(),s.forEach(c=>{t.deleteBlock(c)}),t.doc.endBatchUpdate(),l&&kC(t,l),!0}}const A$=B("heading-collapse");class O${constructor(t){h(this,"handleLoad",()=>{this.showCollapseButtons()});h(this,"handleHoverBlock",(t,e)=>{e&&(z(e,"hovering-heading"),ze(e)&&pt(H(e))&&(kf(e),mr(e)||L$(e))),t&&ze(t)&&pt(H(t))&&(A(t,"hovering-heading"),EC(t),yC(this.editor,t))});h(this,"handleClick",(t,e)=>{const o=Ri(e,"button.heading-collapse-button");if(!o)return;const r=F(o);!r||(d(A$,ze(r),"not a heading block"),T$(this.editor,r),wC(this.editor,r))});this.editor=t,t.addListener("load",this.handleLoad),t.addListener("click",this.handleClick),Nt.get(t).addListener("change",this.handleHoverBlock),this.showCollapseButtons(),setTimeout(()=>{Ws.get(t).addHandler(new R$)})}showCollapseButtons(){const t=Mt(this.editor.rootContainer).filter(ze);t.length!==0&&(t[0]===Ut(this.editor.rootContainer)&&t.splice(0,1),t.forEach(kf))}destroy(){this.editor.removeListener("load",this.handleLoad),this.editor.removeListener("click",this.handleClick)}}function Ea(n){const t=n.selection.range;if(t.isCollapsed()||t.start.blockId===t.end.blockId)return;const e=n.getBlockById(t.start.blockId),o=n.getBlockById(t.end.blockId);mr(e)&&bi(n,e),mr(o)&&bi(n,o)}function _$(n){Ea(n);const t=n.getFocusedBlock();!ze(t)||mr(t)&&bi(n,t)}function N$(n){Ea(n);const t=n.getFocusedBlock();if(!ze(t))return;const e=n.selection.range.focus;!e.isSimple()||e.offset===W(n,t)&&mr(t)&&bi(n,t)}function $$(n){Ea(n);const t=n.getFocusedBlock();if(!ze(t))return;const e=n.selection.range.focus;!e.isSimple()||e.offset===0&&mr(t)&&bi(n,t)}class P${handleBeforeKeyDown(t,e){return ad(e.key)&&Ea(t),e.key==="Enter"?(_$(t),!1):e.key==="Delete"?(N$(t),!1):(e.key==="Backspace"&&$$(t),!1)}}class j${constructor(t){this.editor=t}onInsertBlock(t,e,o,r){this.updateBlockIfNeeded(o.id)}onUpdateBlockData(t,e,o,r){const i=this.editor.doc.getBlockData(t,e);this.updateBlockIfNeeded(i.id,o)}updateBlockIfNeeded(t,e){setTimeout(()=>{const o=this.editor.findBlockById(t);if(!!o){if(!ze(o)){e&&e.delete.includes("heading")&&IC(o);return}nt(o,"hovering-heading")&&wC(this.editor,o),IC(o)}},100)}}function H$(n){return!!n.heading}function xC(n){var e;const t=n.heading;return(e=Number.parseInt(`${t}`,10))!=null?e:1}function TC(n,t){var e;return{parentNode:t,children:[],text:bt((e=n.text)!=null?e:[]),level:xC(n),block:n}}class tl{constructor(){h(this,"nodes",[])}appendBlock(t){const e=this.findParent(xC(t),this.nodes);e?e.children.push(TC(t,e)):this.nodes.push(TC(t,null))}findParent(t,e){const o=e[e.length-1];if(!o||t<=1)return null;if(o.level===t-1)return o;const r=this.findParent(t,o.children);return r||(o.level<t?o:null)}static buildToc(t){const e=new tl,o=t.blocks.root;for(let r=0;r<o.length;r++){const i=o[r];H$(i)&&e.appendBlock(i)}return e}}class gr extends Yt.TypedEmitter{constructor(e){super();h(this,"toc",new tl);h(this,"updateToc",Xt.default(()=>{this.updateTocNow()},500));this.editor=e,e.doc.registerCallback(this),this.updateToc()}destroy(){this.editor.doc.unregisterCallback(this)}isHeadingBlock(e){return!!e.heading}onInsertBlock(e,o,r,i){e==="root"&&this.isHeadingBlock(r)&&this.updateToc()}onDeleteBlock(e,o,r){e==="root"&&this.updateToc()}onUpdateBlockText(e,o,r,i){if(e!=="root")return;const s=this.editor.doc.getBlockData(e,o);this.isHeadingBlock(s)&&this.updateToc()}onUpdateBlockData(e,o,r,i){if(e!=="root")return;const s=this.editor.doc.getBlockData(e,o);this.isHeadingBlock(s)&&this.updateToc()}static register(e){return e.addCustom("editor-toc",()=>new gr(e))}static get(e){return e.getCustom("editor-toc")}updateTocNow(){this.toc=tl.buildToc(this.editor.doc.toJSON()),this.emit("change",this.editor,this.toc)}}const lU="";function F$(n){return n.nodes.length===0?!0:n.nodes.length>1?!1:n.nodes[0].children.length===0}function vf(n,t){t.forEach(e=>{const o=b("div",["toc-node"],n),r=b("div",["toc-title"],o);if(b("span",["toc-text"],r,e.text).setAttribute("data-block-id",e.block.id),e.children.length>0){const s=b("div",["toc-children"],o);vf(s,e.children)}})}function z$(n,t){const e=Ri(t,".toc-text");if(!e)return;const o=e.getAttribute("data-block-id");if(!o)return;const r=n.findBlockById(o);!r||(t.preventDefault(),t.stopPropagation(),n.selection.selectBlock(r,0))}function SC(n,t,e){if(z(t,"loading"),t.innerHTML="",F$(e)){b("div",["toc-empty-message"],t,"No toc");return}e.nodes.length===1?vf(t,e.nodes[0].children):vf(t,e.nodes),Nu(n,"toc-click-handler",()=>{n.addListener("click",z$)})}class U${constructor(t){h(this,"handleUpdateToc",(t,e)=>{Array.from(t.rootContainer.querySelectorAll('.embed-block[data-type="editor-block"][data-embed-type="toc"]')).forEach(r=>{const i=r.querySelector(".editor-toc-container");i&&SC(t,i,e)})});this.editor=t,gr.register(t).addListener("change",this.handleUpdateToc)}destroy(){gr.register(this.editor).removeListener("change",this.handleUpdateToc)}get toc(){return gr.register(this.editor).toc}}function V$(n,t){const e=b("div",["editor-toc-container"],t),r=n.addCustom("init-editor-toc",()=>new U$(n)).toc;r.nodes.length===0?A(e,"loading"):SC(n,e,r)}function q$(n,t,e,o){return o==="markdown"?"[toc]":""}function W$(n,t,e){const{data:o}=e;if(!o||o.embedType!=="toc"||!P(n,t))return null;const r={};return{blockData:{id:N(),type:"embed",embedType:"toc",embedData:r}}}const DC={embedType:"toc",createEmbedContent:V$,convertTo:q$,convertFrom:W$};function G$(n){return!!n.getAttribute("data-style-heading")}function yf(n,t){return G$(t)&&W(n,t)>0}function Z$(n){const t=We(n.rootElement);let e=0,o=0,r=0;if(t===document.documentElement){const i=n.rootContainer.getBoundingClientRect();e=i.left+i.width/2,o=10,r=t.offsetHeight}else{const i=t.getBoundingClientRect();e=i.left+i.width/2,o=i.top+10,r=i.bottom}for(;o<r;){const i=document.elementsFromPoint(e,o);for(let s=0;s<i.length;s++){const l=F(i[s]);if(l&&n.rootContainer.contains(l))return l}o+=10}return null}function wf(n,t){let e=t;for(;e&&!yf(n,e);)e=dt(e);return e}function LC(n){if(gt(n))return!1;const e=H(n);return pt(e)}function Ia(n,t){let e=t;for(;e&&!yf(n,e);)e=gt(e),e&&LC(e)&&(e=null);return e}const Y$=.3;class Q$ extends Yt.TypedEmitter{constructor(e){super();h(this,"scrollContainer");h(this,"scrollEventTarget");h(this,"scrollStatus",{curHeadingBlock:null,previousHeadingBlock:null,nextHeadingBlock:null});h(this,"handleScroll",Xt.default(()=>{const e={curHeadingBlock:null,previousHeadingBlock:null,nextHeadingBlock:null};let o=Z$(this.editor);if(o&&(o=xd(o)),!o||!this.scrollContainer){this.setStatus(e);return}if(LC(o)&&(o=dt(o)),!o){this.setStatus(e);return}if(yf(this.editor,o)){e.curHeadingBlock=o,e.previousHeadingBlock=Ia(this.editor,o),e.nextHeadingBlock=wf(this.editor,o),this.setStatus(e);return}const r=this.scrollContainer.getBoundingClientRect(),i=wf(this.editor,o);if(i){const l=i.getBoundingClientRect();if(l.top>r.top&&l.top<r.top+r.height*Y$){e.curHeadingBlock=i,e.previousHeadingBlock=Ia(this.editor,i),e.nextHeadingBlock=wf(this.editor,i),this.setStatus(e);return}e.nextHeadingBlock=i}const s=Ia(this.editor,o);s&&(e.curHeadingBlock=s,e.previousHeadingBlock=Ia(this.editor,s)),this.setStatus(e)},200));this.editor=e,setTimeout(()=>{this.start()},50)}setStatus(e){this.scrollStatus.previousHeadingBlock===e.previousHeadingBlock&&this.scrollStatus.nextHeadingBlock===e.nextHeadingBlock&&this.scrollStatus.previousHeadingBlock===e.previousHeadingBlock||(this.scrollStatus=e,this.emit("change",this.editor,e))}start(){this.stop(),this.scrollContainer=We(this.editor.rootElement),this.scrollEventTarget=this.scrollContainer===document.documentElement?document:this.scrollContainer,this.scrollEventTarget.addEventListener("scroll",this.handleScroll),this.handleScroll()}stop(){this.scrollEventTarget&&this.scrollEventTarget.removeEventListener("scroll",this.handleScroll)}destroy(){this.stop(),this.scrollEventTarget=void 0}}class K${constructor(t,e){h(this,"suggest");h(this,"onShow",(t,e,o,r)=>{const i=this.editor.getBlockByIndex(e,o);if(!po(i)){const s=F(H(i));if(s&&ot(s)==="code")return!1}return!0});h(this,"onClickItem",(t,e,o)=>{const r=e.data,i={id:N(),type:"mention",box:!0,created:Date.now(),iconUrl:r.avatarUrl,text:r.displayName,mentionId:r.userId},s=this.editor.selection.range;if(!s.isCollapsed()||!s.isSimple())return;const l=s.focus,c=this.editor.getBlockById(l.blockId);this.editor.insertBoxToBlock(c,l.offset,i)});h(this,"queryItems",async(t,e)=>(await this.options.queryUsers(this.editor,e)).map(i=>({id:i.userId,name:i.displayName,icon:`<img src="${i.avatarUrl}" class="mention-user-avatar">`,element:i.element,data:i,subText:i.email})));this.editor=t,this.options=e,this.suggest=new Ch(t,{id:"editor-mention",trigger:["@"],autoDeleteTrigger:!0,showLoading:!0,onShow:this.onShow,onClickItem:this.onClickItem,queryItems:this.queryItems})}destroy(){}}B("mathjax-box");function J$(n,t,e,o){const r=o,i=b("a",["mention-container"],e);b("span",["mention-name"],i,`@${r.text}`),i.setAttribute("data-mention-id",r.mentionId)}function X$(n,t,e){}function tP(n,t,e,o){return`@${t.text}`}const Bf={boxType:"mention",updateBoxContent:J$,handleClickBox:X$,convertTo:tP};function eP(n){const t=b("div",["mention-button-wrap"],null),e=vo("mention-button",T.t("list.mention.tooltip"),BB,[],n.clientId);return t.appendChild(e),b("span",["button-sizer"],t,"A"),t}class nP{constructor(t){h(this,"mentionButton");h(this,"handleHoveringBlock",t=>{var e;!this.editor.isWritable()||(t&&this.shouldBlockShowMention(t)?Rt(t).appendChild(this.mentionButton):(e=this.mentionButton)==null||e.remove())});h(this,"handleMouseDown",(t,e)=>{e.preventDefault(),e.stopPropagation();const o=F(this.mentionButton);if(!o||!P(t,o))return;const r=t.selection.range.focus;if(!r.isSimple())return;let i;t.selection.focusedBlock!==o?i=W(t,o):i=r.offset,setTimeout(()=>{const s=t.insertTextToBlock(o,i,"@");i+=1;const l=bt(be(s,i).left);this.editor.selection.selectBlock(o,i),this.editor.focus(),t.getCustom("mention").suggest.popup(o,i,l,"@")})});h(this,"destroy",()=>{Nt.get(this.editor).removeListener("change",this.handleHoveringBlock)});this.editor=t,this.mentionButton=eP(t),Nt.get(this.editor).addListener("change",this.handleHoveringBlock),t.domEvents.addEventListener(this.mentionButton,"mousedown",this.handleMouseDown)}shouldBlockShowMention(t){if(!P(this.editor,t)||!ct(t))return!1;const e=Fe(t);return!(e==="ordered"||e==="unordered")}}const cU="",oP={templates:{title:"\u9009\u62E9\u6A21\u677F\uFF0C\u5FEB\u901F\u521B\u5EFA",create:"\u65B0\u5EFA\u6A21\u677F",choose:"\u5168\u90E8\u6A21\u677F",customizedMark:"\u81EA\u5B9A\u4E49"}},rP={templates:{title:"Choose a template",create:"New template",choose:"All templates",customizedMark:"Custom"}};T.mergeLang({"zh-CN":oP,"en-US":rP});const aU="",iP="data:image/svg+xml;base64,Cjxzdmcgd2lkdGg9IjEyMCIgaGVpZ2h0PSIxMjAiIHZpZXdCb3g9IjAgMCAxMjAgMTIwIiBmaWxsPSJub25lIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgo8cmVjdCB3aWR0aD0iMTIwIiBoZWlnaHQ9IjEyMCIgZmlsbD0id2hpdGUiLz4KPHBhdGggZD0iTTQ4IDU5QzQ4IDU0LjU4MTcgNTEuNTgxNyA1MSA1NiA1MUg5M0M5OC41MjI4IDUxIDEwMyA1NS40NzcyIDEwMyA2MVY4OEMxMDMgOTEuODY2IDk5Ljg2NiA5NSA5NiA5NUg1NkM1MS41ODE3IDk1IDQ4IDkxLjQxODMgNDggODdWNTlaIiBmaWxsPSIjRDZFOUZBIi8+CjxwYXRoIGQ9Ik0xOCA2NEMxOCA2Mi4zNDMxIDE5LjM0MzEgNjEgMjEgNjFINTZDNjAuNDE4MyA2MSA2NCA2NC41ODE3IDY0IDY5VjgzQzY0IDg1LjIwOTEgNjIuMjA5MSA4NyA2MCA4N0gyNkMyMS41ODE3IDg3IDE4IDgzLjQxODMgMTggNzlWNjRaIiBmaWxsPSIjRUFFNEY2Ii8+CjxyZWN0IHg9IjI0IiB5PSIzMSIgd2lkdGg9IjY1IiBoZWlnaHQ9IjUwIiByeD0iNSIgZmlsbD0iIzk5QzdGMiIvPgo8cmVjdCB4PSIzMy41IiB5PSI0MyIgd2lkdGg9IjQ2IiBoZWlnaHQ9IjUiIHJ4PSIyLjUiIGZpbGw9IndoaXRlIi8+CjxyZWN0IHg9IjMzLjUiIHk9IjU0IiB3aWR0aD0iNDYiIGhlaWdodD0iNSIgcng9IjIuNSIgZmlsbD0id2hpdGUiLz4KPHJlY3QgeD0iMjQiIHk9IjMxIiB3aWR0aD0iNjUiIGhlaWdodD0iNTAiIHJ4PSI1IiBzdHJva2U9IiNGOEY4RjgiLz4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik01MCA4NS4yNjhDNTMuODI2MyA4My4wNTg5IDU1LjEzNzMgNzguMTY2MiA1Mi45MjgyIDc0LjMzOThMNjMuMzIwNSA2OC4zMzk4QzY4Ljg0MzMgNzcuOTA1NyA2NS41NjU4IDkwLjEzNzUgNTYgOTUuNjYwNEM0Ni40MzQxIDEwMS4xODMgMzQuMjAyMyA5Ny45MDU3IDI4LjY3OTQgODguMzM5OEwzOS4wNzE3IDgyLjMzOThDNDEuMjgwOSA4Ni4xNjYyIDQ2LjE3MzYgODcuNDc3MiA1MCA4NS4yNjhaIiBmaWxsPSIjQUI5M0RDIi8+CjxyZWN0IHg9IjU5IiB5PSI2NSIgd2lkdGg9IjQyIiBoZWlnaHQ9IjI4IiByeD0iNSIgZmlsbD0id2hpdGUiLz4KPHBhdGggZD0iTTYzIDg4VjczLjA4MDhDNjMgNzEuNzA5NiA2My4zNjE0IDcwLjY4NjcgNjQuMDg0MSA3MC4wMTJDNjQuODI4NyA2OS4zMzczIDY1Ljg1OCA2OSA2Ny4xNzIgNjlIOTIuODYwOUM5NS42MjAzIDY5IDk3IDcwLjM2MDMgOTcgNzMuMDgwOFY4OEg5My41MTc5TDg3LjM3NDkgODAuNjIyQzg3LjA5MDIgODAuMzE3MyA4Ni43NjE3IDgwLjA4ODggODYuMzg5NCA3OS45MzY0Qzg2LjAxNzEgNzkuNzg0MSA4NS42NDQ4IDc5LjcwNzkgODUuMjcyNSA3OS43MDc5Qzg0LjkwMDIgNzkuNzA3OSA4NC41Mjc5IDc5Ljc4NDEgODQuMTU1NiA3OS45MzY0QzgzLjgwNTIgODAuMDg4OCA4My40NTQ4IDgwLjMxNzMgODMuMTA0MyA4MC42MjJMNzYuNzMxNCA4Ni4yMzcxTDc0LjIwMTkgODMuOTUxOUM3My42MzI1IDgzLjQyOTYgNzMuMDA4NCA4My4xNjg0IDcyLjMyOTUgODMuMTY4NEM3MS42NTA2IDgzLjE2ODQgNzEuMDM3NCA4My40Mjk2IDcwLjQ4OTkgODMuOTUxOUw2Ni40NDkzIDg4SDYzWk03NC40NjQ3IDgwLjYyMkM3NS4zNjI2IDgwLjYyMiA3Ni4xNDAxIDgwLjI5NTUgNzYuNzk3MSA3OS42NDI2Qzc3LjQ3NiA3OC45ODk3IDc3LjgxNTUgNzguMjE3MSA3Ny44MTU1IDc3LjMyNDdDNzcuODE1NSA3Ni40MTA3IDc3LjQ3NiA3NS42MzggNzYuNzk3MSA3NS4wMDY5Qzc2LjE0MDEgNzQuMzU0IDc1LjM2MjYgNzQuMDE2NiA3NC40NjQ3IDczLjk5NDhDNzMuNTQ0OSA3My45NTEzIDcyLjc1NjUgNzQuMjY2OSA3Mi4wOTk1IDc0Ljk0MTZDNzEuNDQyNSA3NS42MTYzIDcxLjExNCA3Ni40MTA3IDcxLjExNCA3Ny4zMjQ3QzcxLjExNCA3OC4yMTcxIDcxLjQ0MjUgNzguOTg5NyA3Mi4wOTk1IDc5LjY0MjZDNzIuNzU2NSA4MC4yOTU1IDczLjU0NDkgODAuNjIyIDc0LjQ2NDcgODAuNjIyWiIgZmlsbD0iI0Y3RDA3RiIvPgo8Y2lyY2xlIGN4PSI5NSIgY3k9IjQyIiByPSIyIiBzdHJva2U9IiM1MEMzOTgiIHN0cm9rZS13aWR0aD0iMiIvPgo8cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTk0Ljc1MDEgMjQuNDY4N0wxMDAuNzgxIDI3LjkxNDlMOTQuNzE5IDMxLjQxNDlMOTQuNzUwMSAyNC40Njg3WiIgc3Ryb2tlPSIjNUNBNUVBIiBzdHJva2Utd2lkdGg9IjEuOCIvPgo8cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTEwNSAzOEMxMDUgMzguNTUyMyAxMDUuNDQ4IDM5IDEwNiAzOUMxMDYuNTUyIDM5IDEwNyAzOC41NTIzIDEwNyAzOFYzNkgxMDlDMTA5LjU1MiAzNiAxMTAgMzUuNTUyMyAxMTAgMzVDMTEwIDM0LjQ0NzcgMTA5LjU1MiAzNCAxMDkgMzRIMTA3VjMyQzEwNyAzMS40NDc3IDEwNi41NTIgMzEgMTA2IDMxQzEwNS40NDggMzEgMTA1IDMxLjQ0NzcgMTA1IDMyVjM0SDEwM0MxMDIuNDQ4IDM0IDEwMiAzNC40NDc3IDEwMiAzNUMxMDIgMzUuNTUyMyAxMDIuNDQ4IDM2IDEwMyAzNkgxMDVWMzhaIiBmaWxsPSIjQUI5M0RDIi8+Cjwvc3ZnPgo=",sP="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzcyIiBoZWlnaHQ9IjI3OSIgdmlld0JveD0iMCAwIDM3MiAyNzkiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMF8xMjU2XzM3MTY4KSI+CjxyZWN0IHdpZHRoPSIzNzIiIGhlaWdodD0iMjc5IiBmaWxsPSJ3aGl0ZSIvPgo8cmVjdCB4PSIzOS41NzQ1IiB5PSIzOS41NzQ3IiB3aWR0aD0iMTE4LjcyMyIgaGVpZ2h0PSIxNS44Mjk4IiByeD0iNy45MTQ4OSIgZmlsbD0iI0VBRjNGQyIvPgo8cmVjdCB4PSIzOS41NzQ1IiB5PSI3MS4yMzM5IiB3aWR0aD0iMjkyLjg1MSIgaGVpZ2h0PSI3LjkxNDg5IiByeD0iMy45NTc0NSIgZmlsbD0iI0VBRjNGQyIvPgo8cmVjdCB4PSIzOS41NzQ1IiB5PSI5MS4wMjE1IiB3aWR0aD0iMjkyLjg1MSIgaGVpZ2h0PSI3LjkxNDg5IiByeD0iMy45NTc0NSIgZmlsbD0iI0VBRjNGQyIvPgo8cmVjdCB4PSIzOS41NzQ1IiB5PSIxMTAuODA5IiB3aWR0aD0iMjkyLjg1MSIgaGVpZ2h0PSI3LjkxNDg5IiByeD0iMy45NTc0NSIgZmlsbD0iI0VBRjNGQyIvPgo8cmVjdCB4PSI0MC41NjM4IiB5PSIxMzUuNTQzIiB3aWR0aD0iMjkwLjg3MiIgaGVpZ2h0PSIxMDAuOTE1IiByeD0iMi45NjgwOSIgc3Ryb2tlPSIjRUFGM0ZDIiBzdHJva2Utd2lkdGg9IjEuOTc4NzIiLz4KPHBhdGggZD0iTTM5LjU3NDUgMTM4LjUxMUMzOS41NzQ1IDEzNi4zMjUgNDEuMzQ2MyAxMzQuNTUzIDQzLjUzMTkgMTM0LjU1M0gzMjguNDY4QzMzMC42NTQgMTM0LjU1MyAzMzIuNDI2IDEzNi4zMjUgMzMyLjQyNiAxMzguNTExVjE1Mi4zNjJIMzkuNTc0NVYxMzguNTExWiIgZmlsbD0iI0Q2RTlGQSIvPgo8cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTg3LjA2MzcgMTY5LjE4MUM4Ny4wNjM3IDE2Ny41NDIgODguMzkyNiAxNjYuMjEzIDkwLjAzMTggMTY2LjIxM0gzMTcuNTg1QzMxOS4yMjQgMTY2LjIxMyAzMjAuNTUzIDE2Ny41NDIgMzIwLjU1MyAxNjkuMTgxQzMyMC41NTMgMTcwLjgyIDMxOS4yMjQgMTcyLjE0OSAzMTcuNTg1IDE3Mi4xNDlIOTAuMDMxOEM4OC4zOTI2IDE3Mi4xNDkgODcuMDYzNyAxNzAuODIgODcuMDYzNyAxNjkuMTgxWk0xMDQuODcyIDE5Mi45MjZDMTA0Ljg3MiAxOTEuMjg2IDEwNi4yMDEgMTg5Ljk1NyAxMDcuODQgMTg5Ljk1N0gzMTcuNTg1QzMxOS4yMjQgMTg5Ljk1NyAzMjAuNTUzIDE5MS4yODYgMzIwLjU1MyAxOTIuOTI2QzMyMC41NTMgMTk0LjU2NSAzMTkuMjI0IDE5NS44OTQgMzE3LjU4NSAxOTUuODk0SDEwNy44NEMxMDYuMjAxIDE5NS44OTQgMTA0Ljg3MiAxOTQuNTY1IDEwNC44NzIgMTkyLjkyNlpNMTA3Ljg0IDIxMy43MDJDMTA2LjIwMSAyMTMuNzAyIDEwNC44NzIgMjE1LjAzMSAxMDQuODcyIDIxNi42N0MxMDQuODcyIDIxOC4zMDkgMTA2LjIwMSAyMTkuNjM4IDEwNy44NCAyMTkuNjM4SDMxNy41ODVDMzE5LjIyNCAyMTkuNjM4IDMyMC41NTMgMjE4LjMwOSAzMjAuNTUzIDIxNi42N0MzMjAuNTUzIDIxNS4wMzEgMzE5LjIyNCAyMTMuNzAyIDMxNy41ODUgMjEzLjcwMkgxMDcuODRaIiBmaWxsPSIjRDZFOUZBIi8+CjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJNNTEuNDQ2OCAxNjkuMTgxQzUxLjQ0NjggMTY3LjU0MiA1Mi43NzU2IDE2Ni4yMTMgNTQuNDE0OSAxNjYuMjEzSDYwLjM1MUM2MS45OTAzIDE2Ni4yMTMgNjMuMzE5MSAxNjcuNTQyIDYzLjMxOTEgMTY5LjE4MUM2My4zMTkxIDE3MC44MiA2MS45OTAzIDE3Mi4xNDkgNjAuMzUxIDE3Mi4xNDlINTQuNDE0OUM1Mi43NzU2IDE3Mi4xNDkgNTEuNDQ2OCAxNzAuODIgNTEuNDQ2OCAxNjkuMTgxWk01MS40NDY4IDE5Mi45MjZDNTEuNDQ2OCAxOTEuMjg2IDUyLjc3NTcgMTg5Ljk1NyA1NC40MTQ5IDE4OS45NTdINjAuMzUxMUM2MS45OTAzIDE4OS45NTcgNjMuMzE5MSAxOTEuMjg2IDYzLjMxOTEgMTkyLjkyNkM2My4zMTkxIDE5NC41NjUgNjEuOTkwMyAxOTUuODk0IDYwLjM1MTEgMTk1Ljg5NEg1NC40MTQ5QzUyLjc3NTcgMTk1Ljg5NCA1MS40NDY4IDE5NC41NjUgNTEuNDQ2OCAxOTIuOTI2Wk01NC40MTQ5IDIxMy43MDJDNTIuNzc1NyAyMTMuNzAyIDUxLjQ0NjggMjE1LjAzMSA1MS40NDY4IDIxNi42N0M1MS40NDY4IDIxOC4zMDkgNTIuNzc1NyAyMTkuNjM4IDU0LjQxNDkgMjE5LjYzOEg2MC4zNTExQzYxLjk5MDMgMjE5LjYzOCA2My4zMTkxIDIxOC4zMDkgNjMuMzE5MSAyMTYuNjdDNjMuMzE5MSAyMTUuMDMxIDYxLjk5MDMgMjEzLjcwMiA2MC4zNTExIDIxMy43MDJINTQuNDE0OVoiIGZpbGw9IiM5OUM3RjIiLz4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik02OS4yNTU0IDE2OS4xODFDNjkuMjU1NCAxNjcuNTQyIDcwLjU4NDMgMTY2LjIxMyA3Mi4yMjM1IDE2Ni4yMTNINzguMTU5N0M3OS43OTg5IDE2Ni4yMTMgODEuMTI3OCAxNjcuNTQyIDgxLjEyNzggMTY5LjE4MUM4MS4xMjc4IDE3MC44MiA3OS43OTg5IDE3Mi4xNDkgNzguMTU5NyAxNzIuMTQ5SDcyLjIyMzVDNzAuNTg0MyAxNzIuMTQ5IDY5LjI1NTQgMTcwLjgyIDY5LjI1NTQgMTY5LjE4MVpNNjkuMjU1NCAxOTIuOTI2QzY5LjI1NTQgMTkxLjI4NiA3MC41ODQyIDE4OS45NTcgNzIuMjIzNSAxODkuOTU3SDc4LjE1OTZDNzkuNzk4OSAxODkuOTU3IDgxLjEyNzcgMTkxLjI4NiA4MS4xMjc3IDE5Mi45MjZDODEuMTI3NyAxOTQuNTY1IDc5Ljc5ODkgMTk1Ljg5NCA3OC4xNTk2IDE5NS44OTRINzIuMjIzNUM3MC41ODQyIDE5NS44OTQgNjkuMjU1NCAxOTQuNTY1IDY5LjI1NTQgMTkyLjkyNlpNNzIuMjIzNSAyMTMuNzAyQzcwLjU4NDIgMjEzLjcwMiA2OS4yNTU0IDIxNS4wMzEgNjkuMjU1NCAyMTYuNjdDNjkuMjU1NCAyMTguMzA5IDcwLjU4NDIgMjE5LjYzOCA3Mi4yMjM1IDIxOS42MzhINzguMTU5NkM3OS43OTg5IDIxOS42MzggODEuMTI3NyAyMTguMzA5IDgxLjEyNzcgMjE2LjY3QzgxLjEyNzcgMjE1LjAzMSA3OS43OTg5IDIxMy43MDIgNzguMTU5NiAyMTMuNzAySDcyLjIyMzVaIiBmaWxsPSIjRjdEMDdGIi8+CjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJNOTAuMDMxOCAxODkuOTU4Qzg4LjM5MjYgMTg5Ljk1OCA4Ny4wNjM3IDE5MS4yODYgODcuMDYzNyAxOTIuOTI2Qzg3LjA2MzcgMTk0LjU2NSA4OC4zOTI2IDE5NS44OTQgOTAuMDMxOCAxOTUuODk0SDk1Ljk2OEM5Ny42MDcyIDE5NS44OTQgOTguOTM2MSAxOTQuNTY1IDk4LjkzNjEgMTkyLjkyNkM5OC45MzYxIDE5MS4yODYgOTcuNjA3MiAxODkuOTU4IDk1Ljk2OCAxODkuOTU4SDkwLjAzMThaTTkwLjAzMTkgMjEzLjcwMkM4OC4zOTI3IDIxMy43MDIgODcuMDYzOCAyMTUuMDMxIDg3LjA2MzggMjE2LjY3Qzg3LjA2MzggMjE4LjMwOSA4OC4zOTI3IDIxOS42MzggOTAuMDMxOSAyMTkuNjM4SDk1Ljk2ODFDOTcuNjA3MyAyMTkuNjM4IDk4LjkzNjIgMjE4LjMwOSA5OC45MzYyIDIxNi42N0M5OC45MzYyIDIxNS4wMzEgOTcuNjA3MyAyMTMuNzAyIDk1Ljk2ODEgMjEzLjcwMkg5MC4wMzE5WiIgZmlsbD0iIzkxRDlCRSIvPgo8L2c+CjxkZWZzPgo8Y2xpcFBhdGggaWQ9ImNsaXAwXzEyNTZfMzcxNjgiPgo8cmVjdCB3aWR0aD0iMzcyIiBoZWlnaHQ9IjI3OSIgZmlsbD0id2hpdGUiLz4KPC9jbGlwUGF0aD4KPC9kZWZzPgo8L3N2Zz4K",MC=B("templates");function Ef(n){const t=n.rootElement.querySelector(":scope .editor-templates");if(!t)return null;const e=t.querySelector(":scope .editor-templates-cards");return d(MC,e,"no card container"),{root:t,cardContainer:e}}function lP(n){const t=Ef(n);if(t)return t.cardContainer.innerHTML="",t;const e=b("div",["editor-templates"],n.rootElement);b("div",["editor-templates-title"],e,T.t("templates.title"));const o=b("div",["editor-templates-cards"],e);return{root:e,cardContainer:o}}function RC(n,t,e,o,r){var f;const i=(f=n.options.componentsOptions)==null?void 0:f.templates,s=b("div",["editor-template-card",...o],null),l=b("div",["editor-template-thumb-container"],s),c=b("img",["editor-template-thumb"],l);c.src=t,c.style.display="none",c.onerror=()=>{var C;const m=(C=i==null?void 0:i.placeHolderImageSrc)!=null?C:sP;c.src!==m&&(c.src=m)},c.onload=()=>{c.style.display=""};const a=b("div",["editor-template-name"],s),u=b("span",[],a,e);return i!=null&&i.showTemplateTitleAttr&&u.setAttribute("title",e),s.onclick=()=>r(s),s}function cP(n,t){return t.thumbnailUrl?t.thumbnailUrl:n.doc.buildResourceUrl("thumbnail.png")}function aP(n,t){const e=cP(n,t);return RC(n,e,t.name,[],async()=>{var r,i;const o=(r=n.options.componentsOptions)==null?void 0:r.templates;(i=o==null?void 0:o.onApplyTemplate)==null||i.call(o,n,t)})}function dP(n,t){return RC(n,t,T.t("templates.choose"),["more"],()=>{var o,r;const e=(o=n.options.componentsOptions)==null?void 0:o.templates;(r=e==null?void 0:e.onChooseTemplate)==null||r.call(e,n)})}function uP(n,t){var f,m;const e=(f=n.options.componentsOptions)==null?void 0:f.templates;if(!e)return;const r=Qt(n.rootContainer).getBoundingClientRect().width;let i=1;const s=iP,l=Ef(n);if(l){if(t!=null&&t.reset){const C=Array.from(l.cardContainer.children),k=l.cardContainer.firstElementChild;if(d(MC,k,"no first card"),nt(k,"new")||nt(k,"more"))return;const w=window.getComputedStyle(k),y=parseFloat(w.marginLeft),S=parseFloat(w.marginRight),I=k.getBoundingClientRect().width+y+S;i=Math.floor(r/I);const R=Math.max(1,i-1-1),$=C.length-1;C.forEach((Z,rt)=>{rt>R&&rt<$?Z.style.display="none":(rt>=$&&nt(Z,"more"),Z.style.display="")})}return}const c=e.templates,{cardContainer:a}=lP(n);c.forEach((C,k)=>{const w=aP(n,C);if(k>0&&k>=i&&(w.style.display="none"),a.appendChild(w),k===0){const y=window.getComputedStyle(w),S=parseFloat(y.marginLeft),I=parseFloat(y.marginRight),M=w.getBoundingClientRect().width+S+I;i=Math.floor(r/M)-1}});const u=dP(n,s);a.appendChild(u),(m=e==null?void 0:e.onTemplateChooserStatusChanged)==null||m.call(e,n,a,"visible")}const AC=Xt.default(uP,50);function hP(n){var o,r;const t=Ef(n);if(!t)return;t.root.remove();const e=(o=n.options.componentsOptions)==null?void 0:o.templates;(r=e==null?void 0:e.onTemplateChooserStatusChanged)==null||r.call(e,n,null,"hide")}function fP(n){const t=n.blocks.root;if(t.length===0)return!0;if(t.length>5)return!1;const e=[...t];e[0].type==="text"&&e[0].heading&&e.splice(0,1);const o=r=>{var i;return r.type!=="text"&&r.type!=="list"?!1:r.text?((i=r.text)==null?void 0:i.length)===0:!0};return e.every(r=>o(r))}function If(n,t){fP(n.doc.toJSON())?AC(n,t):(AC.cancel(),hP(n))}const mP=800;class gP{constructor(t){h(this,"longPressTimeout",0);h(this,"handleSelectionChange",()=>{});h(this,"handleLongPress",t=>{const e=t.touches[0],o=Ol(this.editor,e.clientX,e.clientY);!o||console.log(o)});h(this,"handleTouchStart",t=>{t.touches.length===1&&(this.longPressTimeout=window.setTimeout(()=>{this.handleLongPress(t)},mP))});h(this,"handleTouchEnd",t=>{this.longPressTimeout&&(window.clearTimeout(this.longPressTimeout),this.longPressTimeout=0)});this.editor=t,this.editor.addListener("selectionChanged",this.handleSelectionChange),document.addEventListener("touchstart",this.handleTouchStart),document.addEventListener("touchend",this.handleTouchEnd)}destroy(){this.editor.removeListener("selectionChanged",this.handleSelectionChange),document.removeEventListener("touchstart",this.handleTouchStart),document.removeEventListener("touchend",this.handleTouchEnd)}}class el{constructor(t,e){h(this,"_decrypted",!1);this.editor=t,this.blockData=e}get decrypted(){return this._decrypted||this.blockData.owner===this.editor.doc.getUser().userId}setDecrypted(){this._decrypted=!0}destroy(){}static getState(t,e){return t.addCustom(`encrypted-block-${e.id}`,()=>new el(t,e))}}const dU="",So=B("encrypted-block");function pP(n,t,e,o,r){const i=r,s=ro(o,"div"),l=el.getState(n,i);if(l.decrypted)n.createChildContainer(t,s,i.children[0]),A(o,"decrypted");else{A(o,"encrypted");const c=Rt(o),a=b("div",["password-container"],c),u=b("input",[],a);u.type="text",u.onkeydown=f=>{if(f.key==="Enter"){const m=u.value;if(i.password===Ti.default(`${i.owner}-${m}`)){l.setDecrypted(),n.reloadBlock(o);const C=_d(n,n.getBlockById(i.id));C&&(n.selection.selectBlock(C,0),n.focus())}}}}return s}function CP(n,t,e,o){const r=document.elementsFromPoint(e,o)[0];if(!r||!t.contains(r)||!n.contains(t)||!bn(r))return null;const i=r;if(n.getBlockData(t).children[0]!==U(i))return null;const l=wt(t,U(i));return new Xe(n,{anchor:l,focus:l})}function bP(n,t,e,o){if(el.getState(n,n.getBlockData(t)).decrypted)return null;if(o==="ArrowDown"||o==="ArrowRight"){const s=dt(t);return s?j(s,W(n,s),"end"):j(t,1,"end")}const i=gt(t);return j(i||t,0,"home")}function kP(n,t){return n.getBoundingClientRect()}function vP(n,t,e,o){if(e.isSimple()){d(So,o.isSimple(),"from is simple position but to is not simple position"),So.debug("full select table"),A(t,"full-selected");return}d(So,!o.isSimple(),"from is complex position but end is simple position");const r=e,i=o;d(So,r.blockId===i.blockId,"only allow update one table selection"),d(So,r.childContainerId===i.childContainerId,"only one container");const s=n.getBlockData(t),l=n.getContainerById(s.children[0]);A(l,"selected")}function yP(n){n.rootContainer.querySelectorAll('[data-type="editor-block"][data-block-type="encrypted"]').forEach(t=>{z(t,"full-selected"),t.querySelectorAll("selected").forEach(e=>{z(e,"selected")})})}function wP(n,t){const e=n.getBlockData(t);return el.getState(n,e).decrypted?[n.getContainerById(e.children[0])]:[]}function BP(n,t,e,o,r){return null}function EP(n,t,e,o){d(So,e.blockId===o.blockId,"only allow select in single block"),d(So,q(t)===e.blockId,"only allow select in single block");const r=n.getBlockData(t);return d(So,e.childContainerId===r.children[0],"only one container"),[n.getContainerById(r.children[0])]}function IP(n){return{name:"EncryptedBlock",insertBlockCommandItems:[{id:"insert-encrypted-block",name:"Encrypted Block"}],async handleInsertEmptyBlock(t,e){const o=yn(t.doc),r={id:N(),type:"encrypted",children:[o],owner:t.doc.getUser().userId,ownerDisplayName:t.doc.getUser().displayName,password:Ti.default(`${t.doc.getUser().userId}-1234`)},i=t.doc.getContainerBlocks(o)[0];return t.insertBlock(e.containerId,e.blockIndex,r,At(t,i.id,0))}}}function xP(n,t,e,o){return o==="text"||o==="markdown"?"[Encrypted Block]":"<p>[Encrypted Block]</p>"}const TP={blockType:"encrypted",blockKind:"complex",enableKeyboardSelect:!0,createBlockContent:pP,getBlockTextLength:()=>1,getRangeFromPoint:CP,moveCaret:bP,getCaretRect:kP,updateSelection:vP,clearSelection:yP,getChildContainers:wP,getNextContainer:BP,getSelectedContainers:EP,getOptions:IP,convertTo:xP};function SP(n,t,e){const o=os(n,t,{components:{blocks:[_s,Ps,TP],decorators:[new Hs],embeds:[fa,w1,V1,q1,W1,l1,G1,gf,mf],boxes:[Gc],options:{...e.componentsOptions}}});return o.readonly=!0,o}class DP{constructor(t){this.createOptions=t}createHistoryEditor(t,e){return SP(t,e,this.createOptions)}}B("create-editor");function OC({root:n,childDoc:t,doc:e}){t.uploadResource=e.uploadResource.bind(e),t.buildResourceUrl=e.buildResourceUrl.bind(e);const o=os(n,t,{shortcuts:[ac],components:{blocks:[_s,Ps],decorators:[new Hs],embeds:[M6,fa,w1,V1,q1,W1,l1,G1,gf,mf],boxes:[Gc,Bf],options:{}}});return o.input.addHandler(new ea),o.input.addHandler(new Z1(o)),o.input.addHandler(new V_(o)),o}function LP(n,t){const e=Array.from(n.rootContainer.querySelectorAll(`[comment-${t.toLocaleLowerCase()}="${t}"]`)),o=new Set;e.forEach(r=>{const i=F(r);i&&o.add(i)}),o.forEach(r=>{q_(n,r,t)})}class MP{constructor(t){h(this,"listeners",new Set);h(this,"doc");this.editor=t,this.doc=this.editor.doc.externalDoc,this.doc.registerCallback(this)}getComments(){return this.doc.getComments()}getComment(t){return this.doc.getComment(t)}getCommentDoc(t){return this.doc.getCommentDoc(t)}localCreateComment(t,e){this.doc.localCreateComment(t,e)}localDeleteComment(t){const e=this.getComment(t);this.doc.localDeleteComment(t);const o=e.groupId;this.getComments().filter(i=>i.groupId===o).length===0&&LP(this.editor,o)}localUpdateComment(t,e){this.doc.localUpdateComment(t,e)}onCreateComment(t,e){Array.from(this.listeners.values()).forEach(o=>o.onCreateComment(t,e))}onDeleteComment(t,e){Array.from(this.listeners.values()).forEach(o=>o.onDeleteComment(t,e))}onUpdateComment(t,e){Array.from(this.listeners.values()).forEach(o=>o.onUpdateComment(t,e))}addListener(t){this.listeners.add(t)}removeListener(t){this.listeners.delete(t)}createCommentEditor(t,e){return OC({root:t,childDoc:e,doc:this.doc})}}class RP{constructor(t,e){h(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 Ju(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 OC({root:t,childDoc:e,doc:this.localDoc})}}const AP={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"}}},OP={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"}}};T.mergeLang({"zh-CN":AP,"en-US":OP});const xf=B("create-editor"),_C=[fa,w1,V1,q1,W1,l1,G1,gf,mf,M6,DC,MN];async function _P(n,t){var s,l,c,a,u,f,m,C,k,w,y,S;d(xf,n,"app does not exists"),t.lang&&T.setLang(t.lang);const e=t.onReauth?async()=>{var $;const I=t.user.userId,M=t.docId,R=await(($=t.onReauth)==null?void 0:$.call(t,I,M,t.permission));return{userId:I,docId:M,permission:t.permission,appId:t.appId,token:R,displayName:t.user.displayName,avatarUrl:t.user.avatarUrl}}:void 0,o={auth:{appId:t.appId,docId:t.docId,userId:t.user.userId,permission:t.permission,token:t.token,displayName:t.user.displayName,avatarUrl:t.user.avatarUrl},serverUrl:t.serverUrl,reauthFunc:e,disableLogout:t.disableLogout},r=await ps.load(o),i=os(n,r,{id:t.id,components:{blocks:[_s,Ps,D1,p4],commandProviders:[new xh,...((s=t.components)==null?void 0:s.commandProviders)||[]],decorators:[new Hs,new th],embeds:[..._C,...((l=t.components)==null?void 0:l.embeds)||[]],boxes:[Gc,Bf,K3,...((c=t.components)==null?void 0:c.boxes)||[]],insertions:[nu],blockHooks:[new B6,...((a=t.components)==null?void 0:a.blockHooks)||[]],textRenders:[new q3,new bI],options:{...t.componentsOptions}},shortcuts:[fL,UM,g1,w3,kI,d1,ON,ac],colors:["#338FE5","#24B47E","#F0A100","#E52727","#9678D3","#2CB2AE","#EB6414","#8AAB3F"]});if(i.editorCommandProviders.registerCommandProvider(new Mn(i)),i.input.addHandler(new P$),i.input.addHandler(new ea),i.input.addHandler(new hT),i.input.addHandler(new NM),i.input.addHandler(new $s(i,{headingLevel:1,titlePlaceholder:T.t("placeholder.common.title"),contentPlaceholder:T.t("placeholder.common.content"),readonlyTitlePlaceholder:T.t("placeholder.common.readonlyTitle"),addPlaceholderToAllCurrentEmptyBlock:!0})),i.input.addHandler(new Zc(i,(u=t.componentsOptions)==null?void 0:u.quickMenu)),i.input.addHandler(new Z1(i)),i.input.addHandler(new f3(i)),i.input.addHandler(new aL),i.doc.registerCallback(new j$(i)),i.addCustom("remote-cursor",()=>new W2(i)),i.addCustom("block-menu",I=>new T6(I)),i.addCustom("editor-tooltip",()=>new a1(i)),t!=null&&t.enableComments&&i.addCustom("editor-comments",I=>new V3(I,new MP(I))),i.addCustom("create-options",()=>new em(i,t)),i.addCustom("drop-target",()=>new Ws(i)),i.addCustom("list-to-mindmap",()=>new Vc(i)),i.addCustom("list-to-mention",()=>new nP(i)),i.addCustom("mobile-helper",()=>new gP(i)),i.addCustom("code-caret",()=>new cL(i)),(f=t.componentsOptions)!=null&&f.mention){const I=t.componentsOptions.mention;i.addCustom("mention",()=>new K$(i,I))}if(i.addCustom("heading-collapse",()=>new O$(i)),ti.register(i),Ws.register(i),gr.register(i),(C=(m=t.componentsOptions)==null?void 0:m.remoteCarets)!=null&&C.onUserChanged){const I=(w=(k=t.componentsOptions)==null?void 0:k.remoteCarets)==null?void 0:w.onUserChanged;i.doc.getRemoteUsers().on("change",M=>{I(i,M)})}return(S=(y=t.componentsOptions)==null?void 0:y.templates)!=null&&S.templates.length&&(i.addListener("docChanged",()=>{If(i)}),i.addListener("resize",()=>{If(i,{reset:!0})}),setTimeout(()=>{If(i)},100)),i.doc.registerCallback({onError:async I=>{if(I.code==="ResetDoc"){xf.error(`reset doc: ${I.message}`);const M=await ps.load(o);i.doc.reset(M)}}}),i}function NP(n){return n.toJSON!==void 0}async function $P(n,t,e){var i,s,l;d(xf,n,"app does not exists");const o=NP(t)?t:new _u(t,{serverUrl:e.serverUrl||""});e.lang&&T.setLang(e.lang);const r=os(n,o,{id:e.id,components:{blocks:[_s,Ps,D1,p4],commandProviders:[new xh],decorators:[new Hs,new th],embeds:[..._C,...((i=e.components)==null?void 0:i.embeds)||[]],boxes:[Gc,Bf,K3],insertions:[nu],blockHooks:[new B6,...((s=e.components)==null?void 0:s.blockHooks)||[]],textRenders:[new q3],options:{...e.componentsOptions}},shortcuts:[g1,w3,d1,ac]});return r.editorCommandProviders.registerCommandProvider(new Mn(r)),r.input.addHandler(new ea),r.input.addHandler(new $s(r,{headingLevel:1,titlePlaceholder:T.t("placeholder.common.title"),contentPlaceholder:T.t("placeholder.common.content"),readonlyTitlePlaceholder:T.t("placeholder.local.readonlyTitle"),addPlaceholderToAllCurrentEmptyBlock:!0})),r.input.addHandler(new Zc(r,(l=e.componentsOptions)==null?void 0:l.quickMenu)),r.input.addHandler(new Z1(r)),r.input.addHandler(new f3(r)),r.addCustom("block-menu",c=>new T6(c)),r.addCustom("editor-tooltip",()=>new a1(r)),e!=null&&e.enableComments&&r.addCustom("editor-comments",c=>new V3(c,new RP(c,o))),ti.register(r),r}function PP(n,t){var l;const e=n.doc;if(!((l=e.getVersionHelper)==null?void 0:l.call(e)))throw new Error("the editor does not support to show versions");const r=n.getCustom("create-options");if(!r)throw new Error("the editor does not support to show versions");const i=r.getData(),s=new DP(i);return B$(n,s,t)}g.tippy=E7,g.AuthError=kc,g.AuthHeader=gs,g.AutoScroll=$m,g.BaseURLHeader=vc,g.BasicCommands=Hx,g.BlockResizer=ta,g.BrBox=pp,g.CodeBlock=Ps,g.CodeLineBlock=D1,g.CodeTextDecorator=Hs,g.DefaultShortcuts=ac,g.DocIdError=fw,g.DragDrop=gm,g.DrawioEmbed=fa,g.EditorBlocks=yg,g.EditorBoxes=bp,g.EditorCommandProviders=l2,g.EditorComplexBlockPosition=Je,g.EditorComplexSelectionRange=Xe,g.EditorDecorators=wp,g.EditorEmbeds=Bg,g.EditorInsertions=yp,g.EditorSimpleBlockPosition=Vt,g.EditorSimpleSelectionRange=ae,g.EmbedBlock=Ig,g.EnforceWithDocumentTitleHandler=$s,g.EventCallbacks=Di,g.FILL_CHAR=Fb,g.FileExtError=mw,g.HeadingBlockScrollListener=Q$,g.InputtingInsertion=kp,g.LocalDoc=_u,g.Logger=kr,g.MIN_DISTANCE_THRESHOLD=fm,g.ManualCloseDialog=vs,g.ManualMenu=nr,g.ManualToolbar=ks,g.MarkdownInputHandler=ea,g.MaxUserError=Gu,g.OnesEditorAutoSuggest=Ch,g.OnesEditorCustomDataWrapper=em,g.OnesEditorHoveringBlock=Nt,g.OnesEditorQuickMenu=Zc,g.OnesEditorToc=tl,g.OnesEditorTocProvider=gr,g.OnesEditorToolbar=ti,g.OnesEditorTooltip=a1,g.PermissionError=hw,g.Popup=Cs,g.RemoteCarets=W2,g.RemoteCaretsDecorator=th,g.RemoteCaretsInsertion=nu,g.RemoteUsers=uc,g.RequestReloadError=ms,g.RichText=ie,g.ShareDBDoc=ps,g.SimpleCache=om,g.StandardEmbedBlockCommands=v1,g.TEXT_STYLE_BACKGROUND_COLOR_PREFIX=Zd,g.TEXT_STYLE_COLOR_PREFIX=Gd,g.TableBlock=_s,g.TableBlockCommandProvider=xh,g.TableShortcuts=g1,g.TextBlock=ke,g.TextBox=gp,g.TextStyleShortcuts=d1,g.TocEmbed=DC,g.ZERO_WIDTH_SPACE_CHAR=Li,g.addAttribute=Fl,g.addClass=A,g.addCommentToBlock=k1,g.addDays=f8,g.addMetaToDoc=es,g.addMonths=h8,g.animateScrollTo=id,g.applyPlaceholderToBlock=na,g.assert=d,g.blockToDoc=Mu,g.blockToHtml=su,g.blockToMarkdown=lu,g.blockToText=Kl,g.blocksToDoc=tv,g.clearAllSelection=ug,g.clientType=xt,g.cloneBlock=mo,g.cloneChildContainer=Cu,g.cloneDoc=bu,g.cloneText=rp,g.commentToShareDbComment=Xu,g.compareElement=kl,g.comparePosition=Ad,g.complexBlockAdjustSelectionPos=Al,g.complexBlockFindNearestChildBlock=Dg,g.complexBlockGeFirstSimpleChild=_d,g.complexBlockGetAllChildContainers=Se,g.complexBlockGetBottomChildContainers=Sg,g.complexBlockGetLastSimpleChild=Pi,g.complexBlockGetSelectedContainers=xr,g.complexBlockGetTopChildContainers=Tg,g.containerToDoc=$0,g.continuousScroll=Nm,g.convertBlockFrom=Ml,g.copyBlockAttributes=_p,g.createBlockAnchor=co,g.createBlockCaretAnchor=Ag,g.createBlockContentElement=ro,g.createBlockElement=Wm,g.createBlockSimpleDocRange=Gl,g.createBlockSimpleRange=At,g.createBoxContentElement=Ym,g.createBoxElement=Gm,g.createBoxOp=Yg,g.createChildContainer=cg,g.createComplexBlockPosition=wt,g.createComplexDocPos=up,g.createComplexDocRange=Vb,g.createContainer=cp,g.createContainerElement=Bd,g.createDeleteOps=qg,g.createEditor=os,g.createEditorSelectionRange=qt,g.createElement=b,g.createEmptyContainer=yn,g.createEmptyDoc=Ko,g.createEmptyTextBlockData=Vl,g.createExpandedRange=Cl,g.createIconButton=vr,g.createImage=rm,g.createInsertOps=Hl,g.createInsertionContentElement=Jm,g.createInsertionElement=Qm,g.createLocalEditor=$P,g.createOnesEditor=_P,g.createRange=im,g.createRichText=Qo,g.createRootContainer=lg,g.createSimpleBlockPosition=j,g.createSimpleDocPos=dp,g.createTextBlockData=Un,g.createTextButton=cr,g.createTextOp=$e,g.createTextWithReplaceSoftReturn=Ud,g.daysAfter=md,g.deleteText=qd,g.diffDays=m8,g.disablePageScroll=Dm,g.docToHtml=Dp,g.docToHtmlFragment=Dr,g.docToMarkdown=Lr,g.docToText=Jl,g.downloadObjectToFile=j1,g.downloadSvgToString=A6,g.editLink=Ds,g.editorAddComment=G_,g.editorAddTextAttribute=Wp,g.editorAutoInsertBlock=Np,g.editorBreakTextBlock=Ar,g.editorClearCompositionText=Op,g.editorClearSelectedContents=gu,g.editorCopyBlock=cc,g.editorDeleteBlock=fu,g.editorDeleteBlockText=du,g.editorDeleteBlockWithoutChildren=hu,g.editorDeleteChildContainer=Ok,g.editorDeleteChildContainers=$p,g.editorFocusToBlock=pu,g.editorFocusToEnd=_0,g.editorGetBlockData=fo,g.editorGetBlockText=he,g.editorGetBlockTextEx=Yl,g.editorGetBoxData=fp,g.editorHandleKeyboardEvent=z0,g.editorInsertBlock=Rr,g.editorInsertBoxToBlock=Rp,g.editorInsertDoc=Vp,g.editorInsertDocAt=ku,g.editorInsertText=au,g.editorInsertTextToBlock=Mp,g.editorInsertTextToBlockEx=cu,g.editorMergeTextBlock=Pp,g.editorMoveDown=r0,g.editorMoveEnd=m0,g.editorMoveHome=g0,g.editorMoveLeft=e0,g.editorMoveLineEnd=B0,g.editorMoveLineHome=w0,g.editorMovePageDown=D0,g.editorMovePageUp=S0,g.editorMoveRight=n0,g.editorMoveUp=o0,g.editorMoveWordEnd=u0,g.editorMoveWordLeft=d0,g.editorRangeClearColor=Zp,g.editorRangeGetColor=vu,g.editorRangeSetColor=Gp,g.editorRemoveTextAttribute=$k,g.editorReplaceBlockText=oc,g.editorReplaceContainer=qp,g.editorRunOnce=Nu,g.editorSelectAll=O0,g.editorSelectContainer=Du,g.editorSelectDown=i0,g.editorSelectEnd=Tu,g.editorSelectHome=p0,g.editorSelectLeft=s0,g.editorSelectLineEnd=y0,g.editorSelectLineHome=v0,g.editorSelectPageDown=M0,g.editorSelectPageUp=L0,g.editorSelectRight=l0,g.editorSelectUp=c0,g.editorSelectWordEnd=f0,g.editorSelectWordLeft=h0,g.editorSetTextColor=Or,g.editorShowFindDialog=t_,g.editorUpdateBlockData=rc,g.editorUpdateCompositionText=Ap,g.editorUpdateEmbedData=zp,g.enablePageScroll=Lm,g.escapeHtmlText=dm,g.escapeRegExp=Cd,g.escapeSpace=Y7,g.executeBlockCommand=vg,g.executeEmbedBlockCommand=kg,g.executeRangeCommand=s2,g.fileToDataUrl=wl,g.findAfterOffsetNotType=Xd,g.findAllText=Kd,g.findInsertionById=Km,g.findNextOffset=lk,g.findPrevOffset=sk,g.findPrevOffsetNotType=Jd,g.findPrevSimpleBlockBeforeChildContainer=xg,g.findTarget=Ri,g.findWordEnd=eu,g.findWordLeft=tu,g.format=fd,g.formatBytes=Pm,g.formatDate=Fm,g.fragmentToHtml=Mm,g.fromBase64=yl,g.fromBase64ToBlob=xm,g.fromBase64ToUint8Array=l8,g.fromDocRange=lo,g.fromNowString=pd,g.genId=N,g.getAllChildBlocks=$d,g.getAllQuickMenuItems=c1,g.getAllSelectedBlocks=tn,g.getAttributesAt=zl,g.getBlockBackground=qm,g.getBlockByIndex=yr,g.getBlockCaretRect=Ke,g.getBlockClass=kt,g.getBlockClassByType=Ir,g.getBlockClientRects=io,g.getBlockCommandsWithHook=Dd,g.getBlockContent=it,g.getBlockId=q,g.getBlockIndex=J,g.getBlockKind=Qe,g.getBlockMinWidth=fg,g.getBlockNearestRangeFromPoint=Mg,g.getBlockOptions=E8,g.getBlockPath=Vo,g.getBlockProperties=pg,g.getBlockRangeFromPoint=Ol,g.getBlockStyles=w8,g.getBlockTextLength=W,g.getBlockTools=Rt,g.getBlockType=ot,g.getBoxContent=vd,g.getBoxId=Zm,g.getBoxTypeFromElement=_i,g.getChildBlockCount=Ge,g.getChildBlocks=Mt,g.getChildOffset=ao,g.getColorFromAttributes=Qd,g.getComplexBlockClass=xe,g.getContainerBlockPath=rg,g.getContainerBlocks=ng,g.getContainerBlocksElement=Ll,g.getContainerById=Er,g.getContainerId=U,g.getContainerMinWidth=Td,g.getContainerToolsElement=C8,g.getContainerWidth=gg,g.getDistanceSquare=Cn,g.getElementOffset=Mi,g.getEmbedType=Oe,g.getExistsBlockTools=Dl,g.getExistsContainerById=tg,g.getFileExt=Am,g.getFirstChildBlock=Ut,g.getFirstClientRect=bl,g.getHeadingMenuOptions=o1,g.getHorizontalPadding=ed,g.getInsertionContent=yd,g.getLastChildBlock=Qt,g.getLastClientRect=No,g.getListAllNextBrothers=Ls,g.getLogger=B,g.getNextBlock=dt,g.getNextValidOffset=Go,g.getNextVisibleBlock=Br,g.getOffsetInfoAfter=Wi,g.getOffsetInfoBefore=Ql,g.getOpAt=Kg,g.getOpLength=Wd,g.getParentBlock=F,g.getParentBox=kd,g.getParentContainer=H,g.getPrevBlock=gt,g.getPrevValidOffset=uo,g.getPrevVisibleBlock=wr,g.getRangeCommands=r2,g.getRootBlock=xd,g.getScrollContainer=We,g.getSpecialBlockCommands=Cg,g.getStandardEmbedBlockProperties=y1,g.getTextAfterOffset=rk,g.getTextBeforeOffset=ik,g.getTextBlockChild=_l,g.getTextBlockClass=dg,g.getTextBlockContentChildTextLength=Ne,g.getTextBlockContentChildType=Rg,g.getTextBlockContentChildren=zn,g.getTextLength=ue,g.getTextOpLength=Pd,g.getTextWidth=El,g.getToolbar=Nc,g.handleBlockElementUpdated=mg,g.hasAltOnly=e8,g.hasClass=nt,g.hasCtrlOrCmd=wm,g.hasCtrlOrCmdOnly=t8,g.hideBlock=Um,g.htmlToFragment=Bl,g.i18n=T,g.injectDocToHtmlFragment=ts,g.injectStyle=hm,g.insertEmptyBlock=x8,g.insertEmptyEmbedBlock=Ld,g.insertText=ho,g.intersectionCommands=sy,g.isBackspace=Em,g.isBlock=Uo,g.isBox=bd,g.isCJK=km,g.isChildContainer=Ye,g.isChildNode=It,g.isCollapsedRange=Ub,g.isComplexBlockPosition=Rd,g.isComplexKindBlock=at,g.isContainer=bn,g.isContainerSelectedAllChildBlocks=R0,g.isControlEvent=jo,g.isDelete=o8,g.isDraggingFiles=xl,g.isEmbedBlock=Te,g.isEmptyContainer=Sd,g.isEmptyDoc=ql,g.isEmptyTextBlock=Tt,g.isEmptyTextBlockWithoutCompositionText=Ns,g.isEnterOnly=Bm,g.isEscape=dd,g.isFirefox=cd,g.isFirstChildBlockInComplexBlock=eb,g.isHighSurrogate=U7,g.isInBlock=wd,g.isInBlockTools=Ni,g.isLetter=bm,g.isLowSurrogate=td,g.isMatchShortcut=jn,g.isMoveForward=J7,g.isNavigationEvent=K7,g.isNavigationKey=ym,g.isNodeRemoved=lm,g.isNumber=Cm,g.isPrintableKey=ad,g.isRootBlock=po,g.isRootContainer=pt,g.isSafari=vm,g.isSameDay=gd,g.isShiftEnter=n8,g.isShiftTab=i8,g.isShortcutEvent=X7,g.isSimpleBlock=B8,g.isSimpleBlockPosition=so,g.isSimplePos=ap,g.isSimpleRange=Wl,g.isSpace=vl,g.isTab=r8,g.isTextBlockContentBoxChild=_e,g.isTextBlockContentChild=ji,g.isTextBlockContentInsertionChild=Fn,g.isTextBlockContentTextChild=Hi,g.isTextKindBlock=P,g.isTextKindBlockType=$i,g.isToday=jm,g.isValidOffset=re,g.isVisibleBlock=Sl,g.isYesterday=Hm,g.loadJs=cm,g.loadJsPromise=$o,g.lockers=qe,g.mergeCommands=_c,g.mergeDocs=Jo,g.mergeOps=Vd,g.mergeText=$b,g.multiSplitText=Ng,g.parseShortcut=Im,g.patchNode=Oi,g.pointInRect=Po,g.rangeAddAttribute=Vi,g.rangeGetTextColor=op,g.rangeRemoveAttribute=Sr,g.rangeSetTextColor=tp,g.rangeTransformText=Jg,g.registerDragDrop=sd,g.removeAttribute=Yd,g.removeClass=z,g.removeLastBr=Ab,g.removePlaceholderFromBlock=K4,g.removeStyle=um,g.replaceAll=g8,g.replaceAllCaseInsensitive=p8,g.replaceAllText=lp,g.replaceText=Ul,g.requestDownload=Tl,g.resetListStart=Rs,g.scrollable=_m,g.selectFile=Fo,g.selectedBlockToDoc=sc,g.selectionToDoc=Xi,g.setAttributes=od,g.setClipboardData=Il,g.setClipboardDataByEvent=u8,g.setColorToAttributes=ep,g.setDataset=nd,g.setDefaultCursor=Ai,g.setStyles=rd,g.shareDBCommentToDocObject=Ju,g.shareDBDocCommentToComment=V2,g.shortcutToDisplayText=s8,g.showBlock=Vm,g.showDocVersions=PP,g.splitText=be,g.splitToThree=Wt,g.stringToDataUrl=Tm,g.stringToObjectUrl=hd,g.subText=$g,g.textNodeOffsetFromPoint=sm,g.toBase64URL=Ho,g.toPlainText=bt,g.toPlainTextKeepLength=sp,g.trimChar=ld,g.unicodeLength=V7,g.unicodeSubstr=q7,g.updateBlockSelection=hg,g.updateOpAttributes=ip,g.updateTextBlockContent=ok,g.updateUrl=ud,Object.defineProperties(g,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
688
+ </svg>`,{t:pf}=T;class i${constructor(t){h(this,"goBackButton");h(this,"playButton");h(this,"revertButton");this.options=t;const e=b("button",["dialog-text-button"],null),o=b("span",["dialog-button-icon"],e);o.innerHTML=r$,b("span",["dialog-button-text"],e,pf("version.goBack"));const r=b("button",["dialog-version-button"],null,pf("version.play")),i=b("button",["dialog-version-button"],null,pf("version.revertVersion"));this.goBackButton=e,this.playButton=r,this.revertButton=i,this.bindEvent()}bindEvent(){const{onBack:t,onPlay:e,onRevert:o}=this.options;this.playButton.onclick=e,this.goBackButton.onclick=t,this.revertButton.onclick=o}disabledButton(){}render(t,e=!1){e||t.append(this.goBackButton,this.playButton,this.revertButton)}destroy(){this.playButton.onclick=null,this.goBackButton.onclick=null,this.revertButton.onclick=null}}const Ce=B("split-text-actions");function dC(n){return n.length>2?!1:n.length===1?n[0].insert!==void 0:(d(Ce,n.length===2,`invalid text actions: ${JSON.stringify(n)}`),n[0].retain===void 0?!1:n[1].insert!==void 0)}function uC(n){return n.length>2?!1:n.length===1?n[0].delete!==void 0:(d(Ce,n.length===2,`invalid text actions: ${JSON.stringify(n)}`),n[0].retain===void 0?!1:n[1].delete!==void 0)}function hC(n){return n.length>2?!1:n.length===1?n[0].insert===void 0&&n[0].delete===void 0&&n[0].attributes!==void 0:(d(Ce,n.length===2,`invalid text actions: ${JSON.stringify(n)}`),n[0].retain===void 0?!1:n[1].attributes!==void 0)}function s$(n){const t=[],e=Y.default(n);if(e.length===0)return[];if(e.length===1)return[n];if(e.length===2&&(uC(n)||dC(n)||hC(n)))return[n];const o=(i,s)=>i>0?[{retain:i},s]:[s];let r=0;for(;e.length>0;){const i=e[0];if(i.retain!==void 0&&i.attributes===void 0){d(Ce,i.retain>0,`invalid text op: ${JSON.stringify(i)}`),d(Ce,e.length>1,`invalid text op: ${JSON.stringify(i)}`);const s=e[1];d(Ce,s.delete||s.insert!==void 0||s.attributes!==void 0,`invalid next text op: ${JSON.stringify(s)}`),r+=i.retain,t.push(o(r,s)),s.delete!==void 0?r-=s.delete:s.insert!==void 0?r+=s.insert.length:(d(Ce,s.attributes!==void 0,`invalid next text op: ${JSON.stringify(s)}`),d(Ce,s.retain!==void 0,`invalid next text op: ${JSON.stringify(s)}`),r+=s.retain),e.splice(0,2)}else d(Ce,i.delete||i.insert!==void 0||i.attributes!==void 0,`invalid next text op: ${JSON.stringify(i)}`),t.push(o(r,i)),e.shift(),i.retain!==void 0&&(d(Ce,i.attributes!==void 0,`invalid next text op: ${JSON.stringify(i)}`),r+=i.retain),i.insert&&(r+=i.insert.length)}return t}function fC(n){if(d(Ce,n.length===1||n.length===2,`not a single action op: ${JSON.stringify(n)}`),n.length===1)return 0;const t=n[0].retain;return d(Ce,typeof t=="number"&&t>0,`invalid retain: ${JSON.stringify(n)}`),t}let mC=0;function l$(n,t,e){const o=mC;mC+=1;const r=bt(n);return{insert:" ",attributes:{box:!0,id:N(),type:"history-deleted-box",user:e,created:Date.now(),text:r,deletedOffset:t,deletedOrder:o}}}function c$(n,t,e){const o=fC(t),r=t.length===1?t[0].delete:t[1].delete;d(Ce,typeof r=="number",`not a delete op: ${JSON.stringify(t)}`);const{left:i,middle:s,right:l}=Wt(n,o,r),c=l$(s,o,e);return[...i,c,...l]}function a$(n,t,e){const o=fC(t),r=t.length===1?t[0].insert:t[1].insert;d(Ce,typeof r=="string",`invalid insert op: ${JSON.stringify(t)}`);const i=t.length===1?t[0].attributes:t[1].attributes,l=Fl([{insert:r,attributes:i}],"insertedBy",e);return fo(n,o,l,null)}function d$(n,t,e){const o=s$(t).reverse();let r=n;for(const i of o)uC(i)?r=c$(r,i,e):dC(i)?r=a$(r,i,e):(d(Ce,hC(i),`unknown op: ${JSON.stringify(i)}`),r=ie.apply(r,i));return r}const u$=B("history-update-block-text");function gC(n){const t=[],e=[];let o=0;return n.forEach(r=>{var i;if((i=r.attributes)!=null&&i.box){const s=r.attributes;if(s.type==="history-deleted-box"){t.push({boxData:s,offset:o});return}}e.push(r),o+=Wd(r)}),t.sort((r,i)=>i.offset-r.offset),{deletedBoxes:t,newText:e}}function h$(n,t,e){let o=n;return t.forEach(r=>{const i=ie.transformCursor(r.offset,e,!1);o=fo(o,i,[{insert:" ",attributes:r.boxData}],null)}),o}function f$(n){n.sort((t,e)=>t.boxData.deletedOffset!==e.boxData.deletedOffset?t.boxData.deletedOffset-e.boxData.deletedOffset:t.boxData.deletedOrder-e.boxData.deletedOrder)}function m$(n){if(n.length<=1)return n;const t=n[0].offset;n.forEach(e=>{d(u$,e.offset===t,`invalid boxes group, ${JSON.stringify(n)}`)}),f$(n);for(let e=n.length-1;e>=1;e--){const o=n[e],r=n[e-1];o.boxData.user.userId===r.boxData.user.userId&&(r.boxData.text+=o.boxData.text,n.splice(e,1))}return n}function g$(n){let{newText:t,deletedBoxes:e}=gC(n);const o=new Map;return e.forEach(i=>{let s=o.get(i.offset);s||(s=[],o.set(i.offset,s)),s.push(i),s.sort((l,c)=>l.boxData.deletedOffset-c.boxData.deletedOffset)}),Array.from(o.values()).sort((i,s)=>s[0].offset-i[0].offset).forEach(i=>{const s=i[0].offset;m$(i).reverse().forEach(l=>{t=fo(t,s,[{insert:" ",attributes:l.boxData}],null)})}),t}function p$(n,t,e){let{newText:o,deletedBoxes:r}=gC(n);return o=d$(o,t,e),o=h$(o,r,t),o=g$(o),o}const Rn=B("history-doc");function An(n){d(Rn,!1,"no local actions for history doc")}class C$ extends Di{constructor(e,o){super();h(this,"doc");h(this,"editor");this.doc=Y.default(e),this.editor=o}beginBatchUpdate(){return 0}endBatchUpdate(){return 0}toJSON(){return Y.default(this.doc)}getContainerBlocks(e){return this.doc.blocks[e]}getBlockData(e,o){const r=this.getContainerBlocks(e);d(Rn,r,`no container data: ${e}`);const i=r[o];return d(Rn,i,`no block data: ${o}`),i}localUpdateBlockText(){An()}localUpdateBlockData(){An()}localInsertBlock(){An()}localDeleteBlock(){An()}localInsertChildContainer(){An()}localDeleteChildContainers(){An()}uploadResource(){An()}async addResources(e){An()}getServerMeta(){var e,o,r;return(r=(o=(e=this.editor.doc.externalDoc).getServerMeta)==null?void 0:o.call(e))!=null?r:{}}buildResourceUrl(e){return this.editor.doc.externalDoc.buildResourceUrl(e)}request(){An()}broadcastMessage(){An()}getUser(){return{permission:"w",userId:"-",displayName:"-",avatarUrl:"-",rainbowIndex:0}}getRemoteUsers(){return new uc}destroy(){this.clearCallbacks()}transformBlockIndex(e,o,r){const i=this.doc.blocks[e];d(Rn,i,`no container blocks: ${e}`);let s=0;for(let l=0;l<i.length;l++)if(!i[l].deletedBy){if(s===o)return l;s++}return r&&d(Rn,!1,`invalid block index: ${o}, blocks: ${JSON.stringify(i)}`),d(Rn,s===o,`invalid block index: ${o}, blocks: ${JSON.stringify(i)}`),i.length}onDeleteBlock(e,o,r){const i=this.transformBlockIndex(e,o,!0),l=this.doc.blocks[e][i];d(Rn,!l.deleted,`block has already deleted: ${e}/${o}`),l.deletedBy=r,this.callbacks.forEach(c=>{var a;return(a=c.onUpdateBlockData)==null?void 0:a.call(c,e,i,{insert:{},delete:[]},!0)})}onInsertBlock(e,o,r,i){const s=this.transformBlockIndex(e,o,!1),l=this.doc.blocks[e],c=Y.default(r);c.insertedBy=i,l.splice(s,0,c),this.callbacks.forEach(a=>{var u;return(u=a.onInsertBlock)==null?void 0:u.call(a,e,s,c,!0)})}onUpdateBlockText(e,o,r,i){const s=this.transformBlockIndex(e,o,!0),c=this.doc.blocks[e][s];d(Rn,!c.deleted,`block has already deleted: ${e}/${o}`);const a=c.text;d(Rn,a,`no text for block: ${JSON.stringify(c)}`);const u=p$(a,r,i);c.text=u,this.callbacks.forEach(f=>{var m;return(m=f.onUpdateBlockText)==null?void 0:m.call(f,e,o,r,!0)})}onUpdateBlockData(e,o,r,i){const s=this.transformBlockIndex(e,o,!0),l=this.doc.blocks[e],c=l[s];d(Rn,!c.deleted,`block has already deleted: ${e}/${o}`);const a=Y.default(c);a.updatedBy=i,r.delete.forEach(u=>delete a[u]),Object.entries(r.insert).forEach(([u,f])=>{a[u]=f}),l[s]=a,this.callbacks.forEach(u=>{var f;return(f=u.onUpdateBlockData)==null?void 0:f.call(u,e,s,r,!0)})}onCreateContainer(e,o,r){this.doc.blocks[e]=Y.default(o),this.callbacks.forEach(i=>{var s;return(s=i.onInsertChildContainer)==null?void 0:s.call(i,e,o,!0)})}}const{t:pC}=T;function Ci(n,t){return t==="insert"?pC("version.insert",{name:n.displayName}):pC("version.delete",{name:n.displayName})}function fr(n,t){const{userId:e}=t;return["flag","selection"].reduce((r,i)=>{const s=n.doc.getRemoteUsers().getFixedUserColor(e,i);return r[i]=s,r},{})}class b${renderText(t,e,o){if(!o.box&&o.insertedBy){const r=o.insertedBy,{flag:i,selection:s}=fr(t,o.insertedBy);return{classes:["history-inserted-text"],attributes:{"history-inserted-by":r.displayName,"data-op-description":Ci(r,"insert")},styles:{[mi]:i,[gi]:s}}}return{}}renderBlock(t,e,o){if(o.deletedBy){const r=o.deletedBy,{flag:i,selection:s}=fr(t,r);return{classes:["history-deleted-block"],attributes:{"history-deleted-by":r.displayName,"data-op-description":Ci(r,"delete")},styles:{[mi]:i,[gi]:s}}}if(o.insertedBy){const r=o.insertedBy,{flag:i,selection:s}=fr(t,r);return{classes:["history-inserted-block"],attributes:{"history-inserted-by":r.displayName,"data-op-description":Ci(r,"insert")},styles:{[mi]:i,[gi]:s}}}return{}}updateBlock(t,e,o,r){if(r.deletedBy){const i=r.deletedBy,{flag:s,selection:l}=fr(t,i);A(o,"history-deleted-block"),od(o,{"history-inserted-by":i.displayName,"data-op-description":Ci(i,"delete")}),rd(o,{[mi]:s,[gi]:l});return}if(r.insertedBy){const i=r.insertedBy,{flag:s,selection:l}=fr(t,i);A(o,"history-inserted-block"),od(o,{"history-inserted-by":i.displayName,"data-op-description":Ci(i,"insert")}),rd(o,{[mi]:s,[gi]:l})}}}const CC=B("history-deleted-box");function k$(n,t,e,o){const r=o;d(CC,r.text,`no text for text box data: ${JSON.stringify(o)}`),d(CC,typeof r.text=="string",`invalid text type for text box data: ${JSON.stringify(o)}`);const i=b("span",["history-deleted-box"],e,r.text),s=r.user,{flag:l,selection:c}=fr(n,s);i.setAttribute("history-deleted-by",s.displayName),i.setAttribute("data-op-description",Ci(s,"delete")),i.style.setProperty(mi,l),i.style.setProperty(gi,c)}function v$(n,t,e,o){return t.text}const y$={boxType:"history-deleted-box",updateBoxContent:k$,convertTo:v$},Ee=B("version-dialog");class w${constructor(t,e){h(this,"editor");h(this,"dialog",null);h(this,"oldViewer",null);h(this,"versionOptions");h(this,"versionList",null);h(this,"actionButtons",null);h(this,"provider");h(this,"components");h(this,"handleClose",()=>{var t;(t=this.dialog)==null||t.hide()});h(this,"handlePlay",()=>{var e;d(Ee,this.versionList,"The versionList did not render");const t=(e=this.versionList)==null?void 0:e.activeVersion;d(Ee,t,`The version: ${t} is invalid`),this.viewVersion(t,{play:!0,speed:150})});h(this,"handleRevert",async()=>{var e,o;d(Ee,this.versionList,"The versionList did not render");const t=(e=this.versionList)==null?void 0:e.activeVersion;d(Ee,t,`The version: ${t} is invalid`),await this.versionHelper.revertVersion(t.version),(o=this.dialog)==null||o.hide()});h(this,"handleSelectVersion",t=>{d(Ee,t,`The version: ${t} is invalid`),this.viewVersion(t)});h(this,"viewVersion",async(t,e={play:!1,speed:1e3})=>{var C,k,w;this.oldViewer&&(this.oldViewer.destroy(),this.oldViewer=null),d(Ee,this.versionList,"The versionList did not render"),d(Ee,this.actionButtons,"The actionButtons did not render");const o=t.type==="minor"?this.versionList.beforeVersion:this.versionList.beforeMajorVersion,r=o?o.version:0,i=this.versionList.isSelectedFirstVersion,s=this.versionList.isSelectedLastVersion;this.actionButtons.revertButton.disabled=i,this.actionButtons.playButton.disabled=i;let l=(C=this.versionOptions)==null?void 0:C.hideOps;if((k=this.versionOptions)!=null&&k.onWillChangeVersion){const y=this.versionOptions.onWillChangeVersion(this.editor,t,i,s);y!=null&&y.hideOps&&(l=!0)}let c,a;if(l)c=await this.versionHelper.getVersion(t.version),a=[];else{const y=await this.versionHelper.getHistoryData(t.version,r);c=y.doc,a=y.historyData}const{editorElement:u}=this.components;u.innerHTML="";const f=new C$(c,this.editor),m=this.provider.createHistoryEditor(u,f);m.editorBlockRenders.registerRender(new b$),m.editorBoxes.registerBoxClass(y$),A(m.rootElement,cC.HISTORY);try{await o$(f,this.versionHelper,a,e)}finally{this.oldViewer=m}(w=this.versionOptions)!=null&&w.onVersionChanged&&this.versionOptions.onVersionChanged(this.editor,m,t,i,s)});h(this,"setShowOps",t=>{var e;if(this.versionOptions){this.versionOptions.hideOps=!t;const o=(e=this.versionList)==null?void 0:e.activeVersion;d(Ee,o,`The version: ${o} is invalid`),this.viewVersion(o)}});this.editor=t,this.provider=e;const o=b("div",["version-dialog"],null),r=b("div",["version-dialog-note-viewer"],o),i=b("div",["version-dialog-action-container"],r),s=b("div",["version-dialog-editor"],r),l=b("div",["version-dialog-versions-list"],o);this.components={root:o,editorElement:s,actionContainer:i,versionsListContainer:l}}get versionHelper(){d(Ee,this.editor.doc.getVersionHelper,"Can not get getVersionHelper from doc");const t=this.editor.doc.getVersionHelper();return d(Ee,t,"current doc does not support version"),t}renderContent(t){var s,l;const{actionContainer:e,versionsListContainer:o}=this.components;e.innerHTML="";const r=new i$({onBack:this.handleClose,onPlay:this.handlePlay,onRevert:this.handleRevert});r.render(e,(s=this.versionOptions)==null?void 0:s.hideActions),this.actionButtons=r,o.innerHTML="";const i=new t$({versions:t,useCreatedBy:(l=this.versionOptions)==null?void 0:l.useCreatedBy,onSelectVersion:this.handleSelectVersion,getMarkColor:c=>{const{flag:a}=fr(this.editor,c);return a}});i.render(o),this.versionList=i}initViewVersion(){var t;if((t=this.versionOptions)!=null&&t.initSelectedVersion){d(Ee,this.versionList,"The versionList did not render");const{initSelectedVersion:e}=this.versionOptions,o=this.versionList.selectVersionByVersionNum(e);d(Ee,o,`The version: ${o} is invalid`),this.viewVersion(o)}else{d(Ee,this.versionList,"The versionList did not render");const e=this.versionList.activeVersion;d(Ee,e,`The version: ${e} is invalid`),this.viewVersion(e)}}async show(t){this.versionOptions={...this.versionOptions,...t};const e=await this.versionHelper.getVersions();if(this.versionOptions.hideNonVersionedOps&&e.length&&e[0].version===-1&&e.shift(),this.versionOptions.onVersionsLoaded&&this.versionOptions.onVersionsLoaded(this.editor,e),this.renderContent(e),this.initViewVersion(),!this.dialog){const{root:o}=this.components;this.dialog=new XN(o)}this.dialog.show(t.container)}destroy(){var t,e,o;(t=this.dialog)==null||t.destroy(),(e=this.versionList)==null||e.destroy(),(o=this.actionButtons)==null||o.destroy()}}function B$(n,t,e){const o=n.addCustom("version-dialog",()=>new w$(n,t));return o.show(e),{setShowOps:o.setShowOps}}const sU="",E$=B("heading-collapse");function Cf(n){var e;const t=Number.parseInt((e=n.getAttribute("data-style-heading"))!=null?e:"",10);return d(E$,t,"not a heading block"),t}function ze(n){return!!n.getAttribute("data-style-heading")}function I$(n){return!nt(n,"heading-collapsed")}function mr(n){return nt(n,"heading-collapsed")}function bC(n){if(gt(n))return!1;const e=H(n);return pt(e)}const x$=B("heading-collapse");function bf(n){d(x$,ze(n),"not a heading block");const t=[],e=Cf(n);let o=dt(n);for(;o&&!(ze(o)&&Cf(o)<=e);)t.push(o),o=dt(o);return t}function kC(n,t){if(!Co(t))return;n.selection.selectBlock(t,0),bf(t).forEach(o=>{Um(o)}),A(t,"heading-collapsed")}function bi(n,t){bf(t).forEach(o=>{Vm(o)}),z(t,"heading-collapsed")}function T$(n,t){I$(t)?kC(n,t):bi(n,t)}const S$=[nh,oh,rh,ih,sh,lh,ch,ah];function D$(n){const t=b("button",["heading-collapse-button"],null);return t.setAttribute(`data-editor-tooltip-${n.clientId}`,"Collapse / Expand"),t.innerHTML=eh,t}function vC(n){return ca(n).querySelector("button.heading-collapse-button")}function yC(n,t){vC(t)||bC(t)||!Co(t)||R1(t,D$(n),-1)}function L$(n){var t;(t=vC(n))==null||t.remove()}function wC(n,t){ca(t).querySelector("button.heading-collapse-button")||yC(n,t)}function M$(n){const t=Cf(n),e=b("button",["heading-marker"],null);return e.innerHTML=S$[t-1],e}function BC(n){return ca(n).querySelector("button.heading-marker")}function kf(n){BC(n)||bC(n)||!Co(n)||R1(n,M$(n),1)}function EC(n){const t=BC(n);t==null||t.remove()}function IC(n){EC(n),ze(n)&&kf(n)}class R${handleDrop(t,e,o,r){if(xl(e)||!ze(e)||!mr(e))return;const i=bf(e);i.unshift(e);const s=i.reverse();let l=null;return t.doc.beginBatchUpdate(),s.forEach((c,a,u)=>{const f=t.getBlockData(c),m=go(t.editorBlocks,t.doc.toJSON(),f),C=t.insertDocAt(o,r,m)[0];a===u.length-1&&(l=C)}),t.doc.endBatchUpdate(),t.doc.beginBatchUpdate(),s.forEach(c=>{t.deleteBlock(c)}),t.doc.endBatchUpdate(),l&&kC(t,l),!0}}const A$=B("heading-collapse");class O${constructor(t){h(this,"handleLoad",()=>{this.showCollapseButtons()});h(this,"handleHoverBlock",(t,e)=>{e&&(z(e,"hovering-heading"),ze(e)&&pt(H(e))&&(kf(e),mr(e)||L$(e))),t&&ze(t)&&pt(H(t))&&(A(t,"hovering-heading"),EC(t),yC(this.editor,t))});h(this,"handleClick",(t,e)=>{const o=Ri(e,"button.heading-collapse-button");if(!o)return;const r=F(o);!r||(d(A$,ze(r),"not a heading block"),T$(this.editor,r),wC(this.editor,r))});this.editor=t,t.addListener("load",this.handleLoad),t.addListener("click",this.handleClick),Nt.get(t).addListener("change",this.handleHoverBlock),this.showCollapseButtons(),setTimeout(()=>{Ws.get(t).addHandler(new R$)})}showCollapseButtons(){const t=Mt(this.editor.rootContainer).filter(ze);t.length!==0&&(t[0]===Ut(this.editor.rootContainer)&&t.splice(0,1),t.forEach(kf))}destroy(){this.editor.removeListener("load",this.handleLoad),this.editor.removeListener("click",this.handleClick)}}function Ea(n){const t=n.selection.range;if(t.isCollapsed()||t.start.blockId===t.end.blockId)return;const e=n.getBlockById(t.start.blockId),o=n.getBlockById(t.end.blockId);mr(e)&&bi(n,e),mr(o)&&bi(n,o)}function _$(n){Ea(n);const t=n.getFocusedBlock();!ze(t)||mr(t)&&bi(n,t)}function N$(n){Ea(n);const t=n.getFocusedBlock();if(!ze(t))return;const e=n.selection.range.focus;!e.isSimple()||e.offset===W(n,t)&&mr(t)&&bi(n,t)}function $$(n){Ea(n);const t=n.getFocusedBlock();if(!ze(t))return;const e=n.selection.range.focus;!e.isSimple()||e.offset===0&&mr(t)&&bi(n,t)}class P${handleBeforeKeyDown(t,e){return ad(e.key)&&Ea(t),e.key==="Enter"?(_$(t),!1):e.key==="Delete"?(N$(t),!1):(e.key==="Backspace"&&$$(t),!1)}}class j${constructor(t){this.editor=t}onInsertBlock(t,e,o,r){this.updateBlockIfNeeded(o.id)}onUpdateBlockData(t,e,o,r){const i=this.editor.doc.getBlockData(t,e);this.updateBlockIfNeeded(i.id,o)}updateBlockIfNeeded(t,e){setTimeout(()=>{const o=this.editor.findBlockById(t);if(!!o){if(!ze(o)){e&&e.delete.includes("heading")&&IC(o);return}nt(o,"hovering-heading")&&wC(this.editor,o),IC(o)}},100)}}function H$(n){return!!n.heading}function xC(n){var e;const t=n.heading;return(e=Number.parseInt(`${t}`,10))!=null?e:1}function TC(n,t){var e;return{parentNode:t,children:[],text:bt((e=n.text)!=null?e:[]),level:xC(n),block:n}}class tl{constructor(){h(this,"nodes",[])}appendBlock(t){const e=this.findParent(xC(t),this.nodes);e?e.children.push(TC(t,e)):this.nodes.push(TC(t,null))}findParent(t,e){const o=e[e.length-1];if(!o||t<=1)return null;if(o.level===t-1)return o;const r=this.findParent(t,o.children);return r||(o.level<t?o:null)}static buildToc(t){const e=new tl,o=t.blocks.root;for(let r=0;r<o.length;r++){const i=o[r];H$(i)&&e.appendBlock(i)}return e}}class gr extends Yt.TypedEmitter{constructor(e){super();h(this,"toc",new tl);h(this,"updateToc",Xt.default(()=>{this.updateTocNow()},500));this.editor=e,e.doc.registerCallback(this),this.updateToc()}destroy(){this.editor.doc.unregisterCallback(this)}isHeadingBlock(e){return!!e.heading}onInsertBlock(e,o,r,i){e==="root"&&this.isHeadingBlock(r)&&this.updateToc()}onDeleteBlock(e,o,r){e==="root"&&this.updateToc()}onUpdateBlockText(e,o,r,i){if(e!=="root")return;const s=this.editor.doc.getBlockData(e,o);this.isHeadingBlock(s)&&this.updateToc()}onUpdateBlockData(e,o,r,i){if(e!=="root")return;const s=this.editor.doc.getBlockData(e,o);this.isHeadingBlock(s)&&this.updateToc()}static register(e){return e.addCustom("editor-toc",()=>new gr(e))}static get(e){return e.getCustom("editor-toc")}updateTocNow(){this.toc=tl.buildToc(this.editor.doc.toJSON()),this.emit("change",this.editor,this.toc)}}const lU="";function F$(n){return n.nodes.length===0?!0:n.nodes.length>1?!1:n.nodes[0].children.length===0}function vf(n,t){t.forEach(e=>{const o=b("div",["toc-node"],n),r=b("div",["toc-title"],o);if(b("span",["toc-text"],r,e.text).setAttribute("data-block-id",e.block.id),e.children.length>0){const s=b("div",["toc-children"],o);vf(s,e.children)}})}function z$(n,t){const e=Ri(t,".toc-text");if(!e)return;const o=e.getAttribute("data-block-id");if(!o)return;const r=n.findBlockById(o);!r||(t.preventDefault(),t.stopPropagation(),n.selection.selectBlock(r,0))}function SC(n,t,e){if(z(t,"loading"),t.innerHTML="",F$(e)){b("div",["toc-empty-message"],t,"No toc");return}e.nodes.length===1?vf(t,e.nodes[0].children):vf(t,e.nodes),Nu(n,"toc-click-handler",()=>{n.addListener("click",z$)})}class U${constructor(t){h(this,"handleUpdateToc",(t,e)=>{Array.from(t.rootContainer.querySelectorAll('.embed-block[data-type="editor-block"][data-embed-type="toc"]')).forEach(r=>{const i=r.querySelector(".editor-toc-container");i&&SC(t,i,e)})});this.editor=t,gr.register(t).addListener("change",this.handleUpdateToc)}destroy(){gr.register(this.editor).removeListener("change",this.handleUpdateToc)}get toc(){return gr.register(this.editor).toc}}function V$(n,t){const e=b("div",["editor-toc-container"],t),r=n.addCustom("init-editor-toc",()=>new U$(n)).toc;r.nodes.length===0?A(e,"loading"):SC(n,e,r)}function q$(n,t,e,o){return o==="markdown"?"[toc]":""}function W$(n,t,e){const{data:o}=e;if(!o||o.embedType!=="toc"||!P(n,t))return null;const r={};return{blockData:{id:N(),type:"embed",embedType:"toc",embedData:r}}}const DC={embedType:"toc",createEmbedContent:V$,convertTo:q$,convertFrom:W$};function G$(n){return!!n.getAttribute("data-style-heading")}function yf(n,t){return G$(t)&&W(n,t)>0}function Z$(n){const t=We(n.rootElement);let e=0,o=0,r=0;if(t===document.documentElement){const i=n.rootContainer.getBoundingClientRect();e=i.left+i.width/2,o=10,r=t.offsetHeight}else{const i=t.getBoundingClientRect();e=i.left+i.width/2,o=i.top+10,r=i.bottom}for(;o<r;){const i=document.elementsFromPoint(e,o);for(let s=0;s<i.length;s++){const l=F(i[s]);if(l&&n.rootContainer.contains(l))return l}o+=10}return null}function wf(n,t){let e=t;for(;e&&!yf(n,e);)e=dt(e);return e}function LC(n){if(gt(n))return!1;const e=H(n);return pt(e)}function Ia(n,t){let e=t;for(;e&&!yf(n,e);)e=gt(e),e&&LC(e)&&(e=null);return e}const Y$=.3;class Q$ extends Yt.TypedEmitter{constructor(e){super();h(this,"scrollContainer");h(this,"scrollEventTarget");h(this,"scrollStatus",{curHeadingBlock:null,previousHeadingBlock:null,nextHeadingBlock:null});h(this,"handleScroll",Xt.default(()=>{const e={curHeadingBlock:null,previousHeadingBlock:null,nextHeadingBlock:null};let o=Z$(this.editor);if(o&&(o=xd(o)),!o||!this.scrollContainer){this.setStatus(e);return}if(LC(o)&&(o=dt(o)),!o){this.setStatus(e);return}if(yf(this.editor,o)){e.curHeadingBlock=o,e.previousHeadingBlock=Ia(this.editor,o),e.nextHeadingBlock=wf(this.editor,o),this.setStatus(e);return}const r=this.scrollContainer.getBoundingClientRect(),i=wf(this.editor,o);if(i){const l=i.getBoundingClientRect();if(l.top>r.top&&l.top<r.top+r.height*Y$){e.curHeadingBlock=i,e.previousHeadingBlock=Ia(this.editor,i),e.nextHeadingBlock=wf(this.editor,i),this.setStatus(e);return}e.nextHeadingBlock=i}const s=Ia(this.editor,o);s&&(e.curHeadingBlock=s,e.previousHeadingBlock=Ia(this.editor,s)),this.setStatus(e)},200));this.editor=e,setTimeout(()=>{this.start()},50)}setStatus(e){this.scrollStatus.previousHeadingBlock===e.previousHeadingBlock&&this.scrollStatus.nextHeadingBlock===e.nextHeadingBlock&&this.scrollStatus.previousHeadingBlock===e.previousHeadingBlock||(this.scrollStatus=e,this.emit("change",this.editor,e))}start(){this.stop(),this.scrollContainer=We(this.editor.rootElement),this.scrollEventTarget=this.scrollContainer===document.documentElement?document:this.scrollContainer,this.scrollEventTarget.addEventListener("scroll",this.handleScroll),this.handleScroll()}stop(){this.scrollEventTarget&&this.scrollEventTarget.removeEventListener("scroll",this.handleScroll)}destroy(){this.stop(),this.scrollEventTarget=void 0}}class K${constructor(t,e){h(this,"suggest");h(this,"onShow",(t,e,o,r)=>{const i=this.editor.getBlockByIndex(e,o);if(!Co(i)){const s=F(H(i));if(s&&ot(s)==="code")return!1}return!0});h(this,"onClickItem",(t,e,o)=>{const r=e.data,i={id:N(),type:"mention",box:!0,created:Date.now(),iconUrl:r.avatarUrl,text:r.displayName,mentionId:r.userId},s=this.editor.selection.range;if(!s.isCollapsed()||!s.isSimple())return;const l=s.focus,c=this.editor.getBlockById(l.blockId);this.editor.insertBoxToBlock(c,l.offset,i)});h(this,"queryItems",async(t,e)=>(await this.options.queryUsers(this.editor,e)).map(i=>({id:i.userId,name:i.displayName,icon:`<img src="${i.avatarUrl}" class="mention-user-avatar">`,element:i.element,data:i,subText:i.email})));this.editor=t,this.options=e,this.suggest=new Ch(t,{id:"editor-mention",trigger:["@"],autoDeleteTrigger:!0,showLoading:!0,onShow:this.onShow,onClickItem:this.onClickItem,queryItems:this.queryItems})}destroy(){}}B("mathjax-box");function J$(n,t,e,o){const r=o,i=b("a",["mention-container"],e);b("span",["mention-name"],i,`@${r.text}`),i.setAttribute("data-mention-id",r.mentionId)}function X$(n,t,e){}function tP(n,t,e,o){return`@${t.text}`}const Bf={boxType:"mention",updateBoxContent:J$,handleClickBox:X$,convertTo:tP};function eP(n){const t=b("div",["mention-button-wrap"],null),e=yo("mention-button",T.t("list.mention.tooltip"),BB,[],n.clientId);return t.appendChild(e),b("span",["button-sizer"],t,"A"),t}class nP{constructor(t){h(this,"mentionButton");h(this,"handleHoveringBlock",t=>{var e;!this.editor.isWritable()||(t&&this.shouldBlockShowMention(t)?Rt(t).appendChild(this.mentionButton):(e=this.mentionButton)==null||e.remove())});h(this,"handleMouseDown",(t,e)=>{e.preventDefault(),e.stopPropagation();const o=F(this.mentionButton);if(!o||!P(t,o))return;const r=t.selection.range.focus;if(!r.isSimple())return;let i;t.selection.focusedBlock!==o?i=W(t,o):i=r.offset,setTimeout(()=>{const s=t.insertTextToBlock(o,i,"@");i+=1;const l=bt(be(s,i).left);this.editor.selection.selectBlock(o,i),this.editor.focus(),t.getCustom("mention").suggest.popup(o,i,l,"@")})});h(this,"destroy",()=>{Nt.get(this.editor).removeListener("change",this.handleHoveringBlock)});this.editor=t,this.mentionButton=eP(t),Nt.get(this.editor).addListener("change",this.handleHoveringBlock),t.domEvents.addEventListener(this.mentionButton,"mousedown",this.handleMouseDown)}shouldBlockShowMention(t){if(!P(this.editor,t)||!ct(t))return!1;const e=Fe(t);return!(e==="ordered"||e==="unordered")}}const cU="",oP={templates:{title:"\u9009\u62E9\u6A21\u677F\uFF0C\u5FEB\u901F\u521B\u5EFA",create:"\u65B0\u5EFA\u6A21\u677F",choose:"\u5168\u90E8\u6A21\u677F",customizedMark:"\u81EA\u5B9A\u4E49"}},rP={templates:{title:"Choose a template",create:"New template",choose:"All templates",customizedMark:"Custom"}};T.mergeLang({"zh-CN":oP,"en-US":rP});const aU="",iP="data:image/svg+xml;base64,Cjxzdmcgd2lkdGg9IjEyMCIgaGVpZ2h0PSIxMjAiIHZpZXdCb3g9IjAgMCAxMjAgMTIwIiBmaWxsPSJub25lIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgo8cmVjdCB3aWR0aD0iMTIwIiBoZWlnaHQ9IjEyMCIgZmlsbD0id2hpdGUiLz4KPHBhdGggZD0iTTQ4IDU5QzQ4IDU0LjU4MTcgNTEuNTgxNyA1MSA1NiA1MUg5M0M5OC41MjI4IDUxIDEwMyA1NS40NzcyIDEwMyA2MVY4OEMxMDMgOTEuODY2IDk5Ljg2NiA5NSA5NiA5NUg1NkM1MS41ODE3IDk1IDQ4IDkxLjQxODMgNDggODdWNTlaIiBmaWxsPSIjRDZFOUZBIi8+CjxwYXRoIGQ9Ik0xOCA2NEMxOCA2Mi4zNDMxIDE5LjM0MzEgNjEgMjEgNjFINTZDNjAuNDE4MyA2MSA2NCA2NC41ODE3IDY0IDY5VjgzQzY0IDg1LjIwOTEgNjIuMjA5MSA4NyA2MCA4N0gyNkMyMS41ODE3IDg3IDE4IDgzLjQxODMgMTggNzlWNjRaIiBmaWxsPSIjRUFFNEY2Ii8+CjxyZWN0IHg9IjI0IiB5PSIzMSIgd2lkdGg9IjY1IiBoZWlnaHQ9IjUwIiByeD0iNSIgZmlsbD0iIzk5QzdGMiIvPgo8cmVjdCB4PSIzMy41IiB5PSI0MyIgd2lkdGg9IjQ2IiBoZWlnaHQ9IjUiIHJ4PSIyLjUiIGZpbGw9IndoaXRlIi8+CjxyZWN0IHg9IjMzLjUiIHk9IjU0IiB3aWR0aD0iNDYiIGhlaWdodD0iNSIgcng9IjIuNSIgZmlsbD0id2hpdGUiLz4KPHJlY3QgeD0iMjQiIHk9IjMxIiB3aWR0aD0iNjUiIGhlaWdodD0iNTAiIHJ4PSI1IiBzdHJva2U9IiNGOEY4RjgiLz4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik01MCA4NS4yNjhDNTMuODI2MyA4My4wNTg5IDU1LjEzNzMgNzguMTY2MiA1Mi45MjgyIDc0LjMzOThMNjMuMzIwNSA2OC4zMzk4QzY4Ljg0MzMgNzcuOTA1NyA2NS41NjU4IDkwLjEzNzUgNTYgOTUuNjYwNEM0Ni40MzQxIDEwMS4xODMgMzQuMjAyMyA5Ny45MDU3IDI4LjY3OTQgODguMzM5OEwzOS4wNzE3IDgyLjMzOThDNDEuMjgwOSA4Ni4xNjYyIDQ2LjE3MzYgODcuNDc3MiA1MCA4NS4yNjhaIiBmaWxsPSIjQUI5M0RDIi8+CjxyZWN0IHg9IjU5IiB5PSI2NSIgd2lkdGg9IjQyIiBoZWlnaHQ9IjI4IiByeD0iNSIgZmlsbD0id2hpdGUiLz4KPHBhdGggZD0iTTYzIDg4VjczLjA4MDhDNjMgNzEuNzA5NiA2My4zNjE0IDcwLjY4NjcgNjQuMDg0MSA3MC4wMTJDNjQuODI4NyA2OS4zMzczIDY1Ljg1OCA2OSA2Ny4xNzIgNjlIOTIuODYwOUM5NS42MjAzIDY5IDk3IDcwLjM2MDMgOTcgNzMuMDgwOFY4OEg5My41MTc5TDg3LjM3NDkgODAuNjIyQzg3LjA5MDIgODAuMzE3MyA4Ni43NjE3IDgwLjA4ODggODYuMzg5NCA3OS45MzY0Qzg2LjAxNzEgNzkuNzg0MSA4NS42NDQ4IDc5LjcwNzkgODUuMjcyNSA3OS43MDc5Qzg0LjkwMDIgNzkuNzA3OSA4NC41Mjc5IDc5Ljc4NDEgODQuMTU1NiA3OS45MzY0QzgzLjgwNTIgODAuMDg4OCA4My40NTQ4IDgwLjMxNzMgODMuMTA0MyA4MC42MjJMNzYuNzMxNCA4Ni4yMzcxTDc0LjIwMTkgODMuOTUxOUM3My42MzI1IDgzLjQyOTYgNzMuMDA4NCA4My4xNjg0IDcyLjMyOTUgODMuMTY4NEM3MS42NTA2IDgzLjE2ODQgNzEuMDM3NCA4My40Mjk2IDcwLjQ4OTkgODMuOTUxOUw2Ni40NDkzIDg4SDYzWk03NC40NjQ3IDgwLjYyMkM3NS4zNjI2IDgwLjYyMiA3Ni4xNDAxIDgwLjI5NTUgNzYuNzk3MSA3OS42NDI2Qzc3LjQ3NiA3OC45ODk3IDc3LjgxNTUgNzguMjE3MSA3Ny44MTU1IDc3LjMyNDdDNzcuODE1NSA3Ni40MTA3IDc3LjQ3NiA3NS42MzggNzYuNzk3MSA3NS4wMDY5Qzc2LjE0MDEgNzQuMzU0IDc1LjM2MjYgNzQuMDE2NiA3NC40NjQ3IDczLjk5NDhDNzMuNTQ0OSA3My45NTEzIDcyLjc1NjUgNzQuMjY2OSA3Mi4wOTk1IDc0Ljk0MTZDNzEuNDQyNSA3NS42MTYzIDcxLjExNCA3Ni40MTA3IDcxLjExNCA3Ny4zMjQ3QzcxLjExNCA3OC4yMTcxIDcxLjQ0MjUgNzguOTg5NyA3Mi4wOTk1IDc5LjY0MjZDNzIuNzU2NSA4MC4yOTU1IDczLjU0NDkgODAuNjIyIDc0LjQ2NDcgODAuNjIyWiIgZmlsbD0iI0Y3RDA3RiIvPgo8Y2lyY2xlIGN4PSI5NSIgY3k9IjQyIiByPSIyIiBzdHJva2U9IiM1MEMzOTgiIHN0cm9rZS13aWR0aD0iMiIvPgo8cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTk0Ljc1MDEgMjQuNDY4N0wxMDAuNzgxIDI3LjkxNDlMOTQuNzE5IDMxLjQxNDlMOTQuNzUwMSAyNC40Njg3WiIgc3Ryb2tlPSIjNUNBNUVBIiBzdHJva2Utd2lkdGg9IjEuOCIvPgo8cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTEwNSAzOEMxMDUgMzguNTUyMyAxMDUuNDQ4IDM5IDEwNiAzOUMxMDYuNTUyIDM5IDEwNyAzOC41NTIzIDEwNyAzOFYzNkgxMDlDMTA5LjU1MiAzNiAxMTAgMzUuNTUyMyAxMTAgMzVDMTEwIDM0LjQ0NzcgMTA5LjU1MiAzNCAxMDkgMzRIMTA3VjMyQzEwNyAzMS40NDc3IDEwNi41NTIgMzEgMTA2IDMxQzEwNS40NDggMzEgMTA1IDMxLjQ0NzcgMTA1IDMyVjM0SDEwM0MxMDIuNDQ4IDM0IDEwMiAzNC40NDc3IDEwMiAzNUMxMDIgMzUuNTUyMyAxMDIuNDQ4IDM2IDEwMyAzNkgxMDVWMzhaIiBmaWxsPSIjQUI5M0RDIi8+Cjwvc3ZnPgo=",sP="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzcyIiBoZWlnaHQ9IjI3OSIgdmlld0JveD0iMCAwIDM3MiAyNzkiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMF8xMjU2XzM3MTY4KSI+CjxyZWN0IHdpZHRoPSIzNzIiIGhlaWdodD0iMjc5IiBmaWxsPSJ3aGl0ZSIvPgo8cmVjdCB4PSIzOS41NzQ1IiB5PSIzOS41NzQ3IiB3aWR0aD0iMTE4LjcyMyIgaGVpZ2h0PSIxNS44Mjk4IiByeD0iNy45MTQ4OSIgZmlsbD0iI0VBRjNGQyIvPgo8cmVjdCB4PSIzOS41NzQ1IiB5PSI3MS4yMzM5IiB3aWR0aD0iMjkyLjg1MSIgaGVpZ2h0PSI3LjkxNDg5IiByeD0iMy45NTc0NSIgZmlsbD0iI0VBRjNGQyIvPgo8cmVjdCB4PSIzOS41NzQ1IiB5PSI5MS4wMjE1IiB3aWR0aD0iMjkyLjg1MSIgaGVpZ2h0PSI3LjkxNDg5IiByeD0iMy45NTc0NSIgZmlsbD0iI0VBRjNGQyIvPgo8cmVjdCB4PSIzOS41NzQ1IiB5PSIxMTAuODA5IiB3aWR0aD0iMjkyLjg1MSIgaGVpZ2h0PSI3LjkxNDg5IiByeD0iMy45NTc0NSIgZmlsbD0iI0VBRjNGQyIvPgo8cmVjdCB4PSI0MC41NjM4IiB5PSIxMzUuNTQzIiB3aWR0aD0iMjkwLjg3MiIgaGVpZ2h0PSIxMDAuOTE1IiByeD0iMi45NjgwOSIgc3Ryb2tlPSIjRUFGM0ZDIiBzdHJva2Utd2lkdGg9IjEuOTc4NzIiLz4KPHBhdGggZD0iTTM5LjU3NDUgMTM4LjUxMUMzOS41NzQ1IDEzNi4zMjUgNDEuMzQ2MyAxMzQuNTUzIDQzLjUzMTkgMTM0LjU1M0gzMjguNDY4QzMzMC42NTQgMTM0LjU1MyAzMzIuNDI2IDEzNi4zMjUgMzMyLjQyNiAxMzguNTExVjE1Mi4zNjJIMzkuNTc0NVYxMzguNTExWiIgZmlsbD0iI0Q2RTlGQSIvPgo8cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTg3LjA2MzcgMTY5LjE4MUM4Ny4wNjM3IDE2Ny41NDIgODguMzkyNiAxNjYuMjEzIDkwLjAzMTggMTY2LjIxM0gzMTcuNTg1QzMxOS4yMjQgMTY2LjIxMyAzMjAuNTUzIDE2Ny41NDIgMzIwLjU1MyAxNjkuMTgxQzMyMC41NTMgMTcwLjgyIDMxOS4yMjQgMTcyLjE0OSAzMTcuNTg1IDE3Mi4xNDlIOTAuMDMxOEM4OC4zOTI2IDE3Mi4xNDkgODcuMDYzNyAxNzAuODIgODcuMDYzNyAxNjkuMTgxWk0xMDQuODcyIDE5Mi45MjZDMTA0Ljg3MiAxOTEuMjg2IDEwNi4yMDEgMTg5Ljk1NyAxMDcuODQgMTg5Ljk1N0gzMTcuNTg1QzMxOS4yMjQgMTg5Ljk1NyAzMjAuNTUzIDE5MS4yODYgMzIwLjU1MyAxOTIuOTI2QzMyMC41NTMgMTk0LjU2NSAzMTkuMjI0IDE5NS44OTQgMzE3LjU4NSAxOTUuODk0SDEwNy44NEMxMDYuMjAxIDE5NS44OTQgMTA0Ljg3MiAxOTQuNTY1IDEwNC44NzIgMTkyLjkyNlpNMTA3Ljg0IDIxMy43MDJDMTA2LjIwMSAyMTMuNzAyIDEwNC44NzIgMjE1LjAzMSAxMDQuODcyIDIxNi42N0MxMDQuODcyIDIxOC4zMDkgMTA2LjIwMSAyMTkuNjM4IDEwNy44NCAyMTkuNjM4SDMxNy41ODVDMzE5LjIyNCAyMTkuNjM4IDMyMC41NTMgMjE4LjMwOSAzMjAuNTUzIDIxNi42N0MzMjAuNTUzIDIxNS4wMzEgMzE5LjIyNCAyMTMuNzAyIDMxNy41ODUgMjEzLjcwMkgxMDcuODRaIiBmaWxsPSIjRDZFOUZBIi8+CjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJNNTEuNDQ2OCAxNjkuMTgxQzUxLjQ0NjggMTY3LjU0MiA1Mi43NzU2IDE2Ni4yMTMgNTQuNDE0OSAxNjYuMjEzSDYwLjM1MUM2MS45OTAzIDE2Ni4yMTMgNjMuMzE5MSAxNjcuNTQyIDYzLjMxOTEgMTY5LjE4MUM2My4zMTkxIDE3MC44MiA2MS45OTAzIDE3Mi4xNDkgNjAuMzUxIDE3Mi4xNDlINTQuNDE0OUM1Mi43NzU2IDE3Mi4xNDkgNTEuNDQ2OCAxNzAuODIgNTEuNDQ2OCAxNjkuMTgxWk01MS40NDY4IDE5Mi45MjZDNTEuNDQ2OCAxOTEuMjg2IDUyLjc3NTcgMTg5Ljk1NyA1NC40MTQ5IDE4OS45NTdINjAuMzUxMUM2MS45OTAzIDE4OS45NTcgNjMuMzE5MSAxOTEuMjg2IDYzLjMxOTEgMTkyLjkyNkM2My4zMTkxIDE5NC41NjUgNjEuOTkwMyAxOTUuODk0IDYwLjM1MTEgMTk1Ljg5NEg1NC40MTQ5QzUyLjc3NTcgMTk1Ljg5NCA1MS40NDY4IDE5NC41NjUgNTEuNDQ2OCAxOTIuOTI2Wk01NC40MTQ5IDIxMy43MDJDNTIuNzc1NyAyMTMuNzAyIDUxLjQ0NjggMjE1LjAzMSA1MS40NDY4IDIxNi42N0M1MS40NDY4IDIxOC4zMDkgNTIuNzc1NyAyMTkuNjM4IDU0LjQxNDkgMjE5LjYzOEg2MC4zNTExQzYxLjk5MDMgMjE5LjYzOCA2My4zMTkxIDIxOC4zMDkgNjMuMzE5MSAyMTYuNjdDNjMuMzE5MSAyMTUuMDMxIDYxLjk5MDMgMjEzLjcwMiA2MC4zNTExIDIxMy43MDJINTQuNDE0OVoiIGZpbGw9IiM5OUM3RjIiLz4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik02OS4yNTU0IDE2OS4xODFDNjkuMjU1NCAxNjcuNTQyIDcwLjU4NDMgMTY2LjIxMyA3Mi4yMjM1IDE2Ni4yMTNINzguMTU5N0M3OS43OTg5IDE2Ni4yMTMgODEuMTI3OCAxNjcuNTQyIDgxLjEyNzggMTY5LjE4MUM4MS4xMjc4IDE3MC44MiA3OS43OTg5IDE3Mi4xNDkgNzguMTU5NyAxNzIuMTQ5SDcyLjIyMzVDNzAuNTg0MyAxNzIuMTQ5IDY5LjI1NTQgMTcwLjgyIDY5LjI1NTQgMTY5LjE4MVpNNjkuMjU1NCAxOTIuOTI2QzY5LjI1NTQgMTkxLjI4NiA3MC41ODQyIDE4OS45NTcgNzIuMjIzNSAxODkuOTU3SDc4LjE1OTZDNzkuNzk4OSAxODkuOTU3IDgxLjEyNzcgMTkxLjI4NiA4MS4xMjc3IDE5Mi45MjZDODEuMTI3NyAxOTQuNTY1IDc5Ljc5ODkgMTk1Ljg5NCA3OC4xNTk2IDE5NS44OTRINzIuMjIzNUM3MC41ODQyIDE5NS44OTQgNjkuMjU1NCAxOTQuNTY1IDY5LjI1NTQgMTkyLjkyNlpNNzIuMjIzNSAyMTMuNzAyQzcwLjU4NDIgMjEzLjcwMiA2OS4yNTU0IDIxNS4wMzEgNjkuMjU1NCAyMTYuNjdDNjkuMjU1NCAyMTguMzA5IDcwLjU4NDIgMjE5LjYzOCA3Mi4yMjM1IDIxOS42MzhINzguMTU5NkM3OS43OTg5IDIxOS42MzggODEuMTI3NyAyMTguMzA5IDgxLjEyNzcgMjE2LjY3QzgxLjEyNzcgMjE1LjAzMSA3OS43OTg5IDIxMy43MDIgNzguMTU5NiAyMTMuNzAySDcyLjIyMzVaIiBmaWxsPSIjRjdEMDdGIi8+CjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJNOTAuMDMxOCAxODkuOTU4Qzg4LjM5MjYgMTg5Ljk1OCA4Ny4wNjM3IDE5MS4yODYgODcuMDYzNyAxOTIuOTI2Qzg3LjA2MzcgMTk0LjU2NSA4OC4zOTI2IDE5NS44OTQgOTAuMDMxOCAxOTUuODk0SDk1Ljk2OEM5Ny42MDcyIDE5NS44OTQgOTguOTM2MSAxOTQuNTY1IDk4LjkzNjEgMTkyLjkyNkM5OC45MzYxIDE5MS4yODYgOTcuNjA3MiAxODkuOTU4IDk1Ljk2OCAxODkuOTU4SDkwLjAzMThaTTkwLjAzMTkgMjEzLjcwMkM4OC4zOTI3IDIxMy43MDIgODcuMDYzOCAyMTUuMDMxIDg3LjA2MzggMjE2LjY3Qzg3LjA2MzggMjE4LjMwOSA4OC4zOTI3IDIxOS42MzggOTAuMDMxOSAyMTkuNjM4SDk1Ljk2ODFDOTcuNjA3MyAyMTkuNjM4IDk4LjkzNjIgMjE4LjMwOSA5OC45MzYyIDIxNi42N0M5OC45MzYyIDIxNS4wMzEgOTcuNjA3MyAyMTMuNzAyIDk1Ljk2ODEgMjEzLjcwMkg5MC4wMzE5WiIgZmlsbD0iIzkxRDlCRSIvPgo8L2c+CjxkZWZzPgo8Y2xpcFBhdGggaWQ9ImNsaXAwXzEyNTZfMzcxNjgiPgo8cmVjdCB3aWR0aD0iMzcyIiBoZWlnaHQ9IjI3OSIgZmlsbD0id2hpdGUiLz4KPC9jbGlwUGF0aD4KPC9kZWZzPgo8L3N2Zz4K",MC=B("templates");function Ef(n){const t=n.rootElement.querySelector(":scope .editor-templates");if(!t)return null;const e=t.querySelector(":scope .editor-templates-cards");return d(MC,e,"no card container"),{root:t,cardContainer:e}}function lP(n){const t=Ef(n);if(t)return t.cardContainer.innerHTML="",t;const e=b("div",["editor-templates"],n.rootElement);b("div",["editor-templates-title"],e,T.t("templates.title"));const o=b("div",["editor-templates-cards"],e);return{root:e,cardContainer:o}}function RC(n,t,e,o,r){var f;const i=(f=n.options.componentsOptions)==null?void 0:f.templates,s=b("div",["editor-template-card",...o],null),l=b("div",["editor-template-thumb-container"],s),c=b("img",["editor-template-thumb"],l);c.src=t,c.style.display="none",c.onerror=()=>{var C;const m=(C=i==null?void 0:i.placeHolderImageSrc)!=null?C:sP;c.src!==m&&(c.src=m)},c.onload=()=>{c.style.display=""};const a=b("div",["editor-template-name"],s),u=b("span",[],a,e);return i!=null&&i.showTemplateTitleAttr&&u.setAttribute("title",e),s.onclick=()=>r(s),s}function cP(n,t){return t.thumbnailUrl?t.thumbnailUrl:n.doc.buildResourceUrl("thumbnail.png")}function aP(n,t){const e=cP(n,t);return RC(n,e,t.name,[],async()=>{var r,i;const o=(r=n.options.componentsOptions)==null?void 0:r.templates;(i=o==null?void 0:o.onApplyTemplate)==null||i.call(o,n,t)})}function dP(n,t){return RC(n,t,T.t("templates.choose"),["more"],()=>{var o,r;const e=(o=n.options.componentsOptions)==null?void 0:o.templates;(r=e==null?void 0:e.onChooseTemplate)==null||r.call(e,n)})}function uP(n,t){var f,m;const e=(f=n.options.componentsOptions)==null?void 0:f.templates;if(!e)return;const r=Qt(n.rootContainer).getBoundingClientRect().width;let i=1;const s=iP,l=Ef(n);if(l){if(t!=null&&t.reset){const C=Array.from(l.cardContainer.children),k=l.cardContainer.firstElementChild;if(d(MC,k,"no first card"),nt(k,"new")||nt(k,"more"))return;const w=window.getComputedStyle(k),y=parseFloat(w.marginLeft),S=parseFloat(w.marginRight),I=k.getBoundingClientRect().width+y+S;i=Math.floor(r/I);const R=Math.max(1,i-1-1),$=C.length-1;C.forEach((Z,rt)=>{rt>R&&rt<$?Z.style.display="none":(rt>=$&&nt(Z,"more"),Z.style.display="")})}return}const c=e.templates,{cardContainer:a}=lP(n);c.forEach((C,k)=>{const w=aP(n,C);if(k>0&&k>=i&&(w.style.display="none"),a.appendChild(w),k===0){const y=window.getComputedStyle(w),S=parseFloat(y.marginLeft),I=parseFloat(y.marginRight),M=w.getBoundingClientRect().width+S+I;i=Math.floor(r/M)-1}});const u=dP(n,s);a.appendChild(u),(m=e==null?void 0:e.onTemplateChooserStatusChanged)==null||m.call(e,n,a,"visible")}const AC=Xt.default(uP,50);function hP(n){var o,r;const t=Ef(n);if(!t)return;t.root.remove();const e=(o=n.options.componentsOptions)==null?void 0:o.templates;(r=e==null?void 0:e.onTemplateChooserStatusChanged)==null||r.call(e,n,null,"hide")}function fP(n){const t=n.blocks.root;if(t.length===0)return!0;if(t.length>5)return!1;const e=[...t];e[0].type==="text"&&e[0].heading&&e.splice(0,1);const o=r=>{var i;return r.type!=="text"&&r.type!=="list"?!1:r.text?((i=r.text)==null?void 0:i.length)===0:!0};return e.every(r=>o(r))}function If(n,t){fP(n.doc.toJSON())?AC(n,t):(AC.cancel(),hP(n))}const mP=800;class gP{constructor(t){h(this,"longPressTimeout",0);h(this,"handleSelectionChange",()=>{});h(this,"handleLongPress",t=>{const e=t.touches[0],o=Ol(this.editor,e.clientX,e.clientY);!o||console.log(o)});h(this,"handleTouchStart",t=>{t.touches.length===1&&(this.longPressTimeout=window.setTimeout(()=>{this.handleLongPress(t)},mP))});h(this,"handleTouchEnd",t=>{this.longPressTimeout&&(window.clearTimeout(this.longPressTimeout),this.longPressTimeout=0)});this.editor=t,this.editor.addListener("selectionChanged",this.handleSelectionChange),document.addEventListener("touchstart",this.handleTouchStart),document.addEventListener("touchend",this.handleTouchEnd)}destroy(){this.editor.removeListener("selectionChanged",this.handleSelectionChange),document.removeEventListener("touchstart",this.handleTouchStart),document.removeEventListener("touchend",this.handleTouchEnd)}}class el{constructor(t,e){h(this,"_decrypted",!1);this.editor=t,this.blockData=e}get decrypted(){return this._decrypted||this.blockData.owner===this.editor.doc.getUser().userId}setDecrypted(){this._decrypted=!0}destroy(){}static getState(t,e){return t.addCustom(`encrypted-block-${e.id}`,()=>new el(t,e))}}const dU="",Do=B("encrypted-block");function pP(n,t,e,o,r){const i=r,s=ro(o,"div"),l=el.getState(n,i);if(l.decrypted)n.createChildContainer(t,s,i.children[0]),A(o,"decrypted");else{A(o,"encrypted");const c=Rt(o),a=b("div",["password-container"],c),u=b("input",[],a);u.type="text",u.onkeydown=f=>{if(f.key==="Enter"){const m=u.value;if(i.password===Ti.default(`${i.owner}-${m}`)){l.setDecrypted(),n.reloadBlock(o);const C=_d(n,n.getBlockById(i.id));C&&(n.selection.selectBlock(C,0),n.focus())}}}}return s}function CP(n,t,e,o){const r=document.elementsFromPoint(e,o)[0];if(!r||!t.contains(r)||!n.contains(t)||!bn(r))return null;const i=r;if(n.getBlockData(t).children[0]!==U(i))return null;const l=wt(t,U(i));return new Xe(n,{anchor:l,focus:l})}function bP(n,t,e,o){if(el.getState(n,n.getBlockData(t)).decrypted)return null;if(o==="ArrowDown"||o==="ArrowRight"){const s=dt(t);return s?j(s,W(n,s),"end"):j(t,1,"end")}const i=gt(t);return j(i||t,0,"home")}function kP(n,t){return n.getBoundingClientRect()}function vP(n,t,e,o){if(e.isSimple()){d(Do,o.isSimple(),"from is simple position but to is not simple position"),Do.debug("full select table"),A(t,"full-selected");return}d(Do,!o.isSimple(),"from is complex position but end is simple position");const r=e,i=o;d(Do,r.blockId===i.blockId,"only allow update one table selection"),d(Do,r.childContainerId===i.childContainerId,"only one container");const s=n.getBlockData(t),l=n.getContainerById(s.children[0]);A(l,"selected")}function yP(n){n.rootContainer.querySelectorAll('[data-type="editor-block"][data-block-type="encrypted"]').forEach(t=>{z(t,"full-selected"),t.querySelectorAll("selected").forEach(e=>{z(e,"selected")})})}function wP(n,t){const e=n.getBlockData(t);return el.getState(n,e).decrypted?[n.getContainerById(e.children[0])]:[]}function BP(n,t,e,o,r){return null}function EP(n,t,e,o){d(Do,e.blockId===o.blockId,"only allow select in single block"),d(Do,q(t)===e.blockId,"only allow select in single block");const r=n.getBlockData(t);return d(Do,e.childContainerId===r.children[0],"only one container"),[n.getContainerById(r.children[0])]}function IP(n){return{name:"EncryptedBlock",insertBlockCommandItems:[{id:"insert-encrypted-block",name:"Encrypted Block"}],async handleInsertEmptyBlock(t,e){const o=yn(t.doc),r={id:N(),type:"encrypted",children:[o],owner:t.doc.getUser().userId,ownerDisplayName:t.doc.getUser().displayName,password:Ti.default(`${t.doc.getUser().userId}-1234`)},i=t.doc.getContainerBlocks(o)[0];return t.insertBlock(e.containerId,e.blockIndex,r,At(t,i.id,0))}}}function xP(n,t,e,o){return o==="text"||o==="markdown"?"[Encrypted Block]":"<p>[Encrypted Block]</p>"}const TP={blockType:"encrypted",blockKind:"complex",enableKeyboardSelect:!0,createBlockContent:pP,getBlockTextLength:()=>1,getRangeFromPoint:CP,moveCaret:bP,getCaretRect:kP,updateSelection:vP,clearSelection:yP,getChildContainers:wP,getNextContainer:BP,getSelectedContainers:EP,getOptions:IP,convertTo:xP};function SP(n,t,e){const o=os(n,t,{components:{blocks:[_s,Ps,TP],decorators:[new Hs],embeds:[fa,w1,V1,q1,W1,l1,G1,gf,mf],boxes:[Gc],options:{...e.componentsOptions}}});return o.readonly=!0,o}class DP{constructor(t){this.createOptions=t}createHistoryEditor(t,e){return SP(t,e,this.createOptions)}}B("create-editor");function OC({root:n,childDoc:t,doc:e}){t.uploadResource=e.uploadResource.bind(e),t.buildResourceUrl=e.buildResourceUrl.bind(e);const o=os(n,t,{shortcuts:[ac],components:{blocks:[_s,Ps],decorators:[new Hs],embeds:[M6,fa,w1,V1,q1,W1,l1,G1,gf,mf],boxes:[Gc,Bf],options:{}}});return o.input.addHandler(new ea),o.input.addHandler(new Z1(o)),o.input.addHandler(new V_(o)),o}function LP(n,t){const e=Array.from(n.rootContainer.querySelectorAll(`[comment-${t.toLocaleLowerCase()}="${t}"]`)),o=new Set;e.forEach(r=>{const i=F(r);i&&o.add(i)}),o.forEach(r=>{q_(n,r,t)})}class MP{constructor(t){h(this,"listeners",new Set);h(this,"doc");this.editor=t,this.doc=this.editor.doc.externalDoc,this.doc.registerCallback(this)}getComments(){return this.doc.getComments()}getComment(t){return this.doc.getComment(t)}getCommentDoc(t){return this.doc.getCommentDoc(t)}localCreateComment(t,e){this.doc.localCreateComment(t,e)}localDeleteComment(t){const e=this.getComment(t);this.doc.localDeleteComment(t);const o=e.groupId;this.getComments().filter(i=>i.groupId===o).length===0&&LP(this.editor,o)}localUpdateComment(t,e){this.doc.localUpdateComment(t,e)}onCreateComment(t,e){Array.from(this.listeners.values()).forEach(o=>o.onCreateComment(t,e))}onDeleteComment(t,e){Array.from(this.listeners.values()).forEach(o=>o.onDeleteComment(t,e))}onUpdateComment(t,e){Array.from(this.listeners.values()).forEach(o=>o.onUpdateComment(t,e))}addListener(t){this.listeners.add(t)}removeListener(t){this.listeners.delete(t)}createCommentEditor(t,e){return OC({root:t,childDoc:e,doc:this.doc})}}class RP{constructor(t,e){h(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 Ju(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 OC({root:t,childDoc:e,doc:this.localDoc})}}const AP={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"}}},OP={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"}}};T.mergeLang({"zh-CN":AP,"en-US":OP});const xf=B("create-editor"),_C=[fa,w1,V1,q1,W1,l1,G1,gf,mf,M6,DC,MN];async function _P(n,t){var s,l,c,a,u,f,m,C,k,w,y,S;d(xf,n,"app does not exists"),t.lang&&T.setLang(t.lang);const e=t.onReauth?async()=>{var $;const I=t.user.userId,M=t.docId,R=await(($=t.onReauth)==null?void 0:$.call(t,I,M,t.permission));return{userId:I,docId:M,permission:t.permission,appId:t.appId,token:R,displayName:t.user.displayName,avatarUrl:t.user.avatarUrl}}:void 0,o={auth:{appId:t.appId,docId:t.docId,userId:t.user.userId,permission:t.permission,token:t.token,displayName:t.user.displayName,avatarUrl:t.user.avatarUrl},serverUrl:t.serverUrl,reauthFunc:e,disableLogout:t.disableLogout},r=await ps.load(o),i=os(n,r,{id:t.id,components:{blocks:[_s,Ps,D1,p4],commandProviders:[new xh,...((s=t.components)==null?void 0:s.commandProviders)||[]],decorators:[new Hs,new th],embeds:[..._C,...((l=t.components)==null?void 0:l.embeds)||[]],boxes:[Gc,Bf,K3,...((c=t.components)==null?void 0:c.boxes)||[]],insertions:[nu],blockHooks:[new B6,...((a=t.components)==null?void 0:a.blockHooks)||[]],textRenders:[new q3,new bI],options:{...t.componentsOptions}},shortcuts:[fL,UM,g1,w3,kI,d1,ON,ac],colors:["#338FE5","#24B47E","#F0A100","#E52727","#9678D3","#2CB2AE","#EB6414","#8AAB3F"]});if(i.editorCommandProviders.registerCommandProvider(new Mn(i)),i.input.addHandler(new P$),i.input.addHandler(new ea),i.input.addHandler(new hT),i.input.addHandler(new NM),i.input.addHandler(new $s(i,{headingLevel:1,titlePlaceholder:T.t("placeholder.common.title"),contentPlaceholder:T.t("placeholder.common.content"),readonlyTitlePlaceholder:T.t("placeholder.common.readonlyTitle"),addPlaceholderToAllCurrentEmptyBlock:!0})),i.input.addHandler(new Zc(i,(u=t.componentsOptions)==null?void 0:u.quickMenu)),i.input.addHandler(new Z1(i)),i.input.addHandler(new f3(i)),i.input.addHandler(new aL),i.doc.registerCallback(new j$(i)),i.addCustom("remote-cursor",()=>new W2(i)),i.addCustom("block-menu",I=>new T6(I)),i.addCustom("editor-tooltip",()=>new a1(i)),t!=null&&t.enableComments&&i.addCustom("editor-comments",I=>new V3(I,new MP(I))),i.addCustom("create-options",()=>new em(i,t)),i.addCustom("drop-target",()=>new Ws(i)),i.addCustom("list-to-mindmap",()=>new Vc(i)),i.addCustom("list-to-mention",()=>new nP(i)),i.addCustom("mobile-helper",()=>new gP(i)),i.addCustom("code-caret",()=>new cL(i)),(f=t.componentsOptions)!=null&&f.mention){const I=t.componentsOptions.mention;i.addCustom("mention",()=>new K$(i,I))}if(i.addCustom("heading-collapse",()=>new O$(i)),ti.register(i),Ws.register(i),gr.register(i),(C=(m=t.componentsOptions)==null?void 0:m.remoteCarets)!=null&&C.onUserChanged){const I=(w=(k=t.componentsOptions)==null?void 0:k.remoteCarets)==null?void 0:w.onUserChanged;i.doc.getRemoteUsers().on("change",M=>{I(i,M)})}return(S=(y=t.componentsOptions)==null?void 0:y.templates)!=null&&S.templates.length&&(i.addListener("docChanged",()=>{If(i)}),i.addListener("resize",()=>{If(i,{reset:!0})}),setTimeout(()=>{If(i)},100)),i.doc.registerCallback({onError:async I=>{if(I.code==="ResetDoc"){xf.error(`reset doc: ${I.message}`);const M=await ps.load(o);i.doc.reset(M)}}}),i}function NP(n){return n.toJSON!==void 0}async function $P(n,t,e){var i,s,l;d(xf,n,"app does not exists");const o=NP(t)?t:new _u(t,{serverUrl:e.serverUrl||""});e.lang&&T.setLang(e.lang);const r=os(n,o,{id:e.id,components:{blocks:[_s,Ps,D1,p4],commandProviders:[new xh],decorators:[new Hs,new th],embeds:[..._C,...((i=e.components)==null?void 0:i.embeds)||[]],boxes:[Gc,Bf,K3],insertions:[nu],blockHooks:[new B6,...((s=e.components)==null?void 0:s.blockHooks)||[]],textRenders:[new q3],options:{...e.componentsOptions}},shortcuts:[g1,w3,d1,ac]});return r.editorCommandProviders.registerCommandProvider(new Mn(r)),r.input.addHandler(new ea),r.input.addHandler(new $s(r,{headingLevel:1,titlePlaceholder:T.t("placeholder.common.title"),contentPlaceholder:T.t("placeholder.common.content"),readonlyTitlePlaceholder:T.t("placeholder.local.readonlyTitle"),addPlaceholderToAllCurrentEmptyBlock:!0})),r.input.addHandler(new Zc(r,(l=e.componentsOptions)==null?void 0:l.quickMenu)),r.input.addHandler(new Z1(r)),r.input.addHandler(new f3(r)),r.addCustom("block-menu",c=>new T6(c)),r.addCustom("editor-tooltip",()=>new a1(r)),e!=null&&e.enableComments&&r.addCustom("editor-comments",c=>new V3(c,new RP(c,o))),ti.register(r),r}function PP(n,t){var l;const e=n.doc;if(!((l=e.getVersionHelper)==null?void 0:l.call(e)))throw new Error("the editor does not support to show versions");const r=n.getCustom("create-options");if(!r)throw new Error("the editor does not support to show versions");const i=r.getData(),s=new DP(i);return B$(n,s,t)}g.tippy=E7,g.AuthError=kc,g.AuthHeader=gs,g.AutoScroll=$m,g.BaseURLHeader=vc,g.BasicCommands=Hx,g.BlockResizer=ta,g.BrBox=pp,g.CodeBlock=Ps,g.CodeLineBlock=D1,g.CodeTextDecorator=Hs,g.DefaultShortcuts=ac,g.DocIdError=fw,g.DragDrop=gm,g.DrawioEmbed=fa,g.EditorBlocks=yg,g.EditorBoxes=bp,g.EditorCommandProviders=l2,g.EditorComplexBlockPosition=Je,g.EditorComplexSelectionRange=Xe,g.EditorDecorators=wp,g.EditorEmbeds=Bg,g.EditorInsertions=yp,g.EditorSimpleBlockPosition=Vt,g.EditorSimpleSelectionRange=ae,g.EmbedBlock=Ig,g.EnforceWithDocumentTitleHandler=$s,g.EventCallbacks=Di,g.FILL_CHAR=Fb,g.FileExtError=mw,g.HeadingBlockScrollListener=Q$,g.InputtingInsertion=kp,g.LocalDoc=_u,g.Logger=kr,g.MIN_DISTANCE_THRESHOLD=fm,g.ManualCloseDialog=vs,g.ManualMenu=nr,g.ManualToolbar=ks,g.MarkdownInputHandler=ea,g.MaxUserError=Gu,g.OnesEditorAutoSuggest=Ch,g.OnesEditorCustomDataWrapper=em,g.OnesEditorHoveringBlock=Nt,g.OnesEditorQuickMenu=Zc,g.OnesEditorToc=tl,g.OnesEditorTocProvider=gr,g.OnesEditorToolbar=ti,g.OnesEditorTooltip=a1,g.PermissionError=hw,g.Popup=Cs,g.RemoteCarets=W2,g.RemoteCaretsDecorator=th,g.RemoteCaretsInsertion=nu,g.RemoteUsers=uc,g.RequestReloadError=ms,g.RichText=ie,g.ShareDBDoc=ps,g.SimpleCache=om,g.StandardEmbedBlockCommands=v1,g.TEXT_STYLE_BACKGROUND_COLOR_PREFIX=Zd,g.TEXT_STYLE_COLOR_PREFIX=Gd,g.TableBlock=_s,g.TableBlockCommandProvider=xh,g.TableShortcuts=g1,g.TextBlock=ke,g.TextBox=gp,g.TextStyleShortcuts=d1,g.TocEmbed=DC,g.ZERO_WIDTH_SPACE_CHAR=Li,g.addAttribute=Fl,g.addClass=A,g.addCommentToBlock=k1,g.addDays=f8,g.addMetaToDoc=es,g.addMonths=h8,g.animateScrollTo=id,g.applyPlaceholderToBlock=na,g.assert=d,g.blockToDoc=Mu,g.blockToHtml=su,g.blockToMarkdown=lu,g.blockToText=Kl,g.blocksToDoc=tv,g.clearAllSelection=ug,g.clientType=xt,g.cloneBlock=go,g.cloneChildContainer=Cu,g.cloneDoc=bu,g.cloneText=rp,g.commentToShareDbComment=Xu,g.compareElement=kl,g.comparePosition=Ad,g.complexBlockAdjustSelectionPos=Al,g.complexBlockFindNearestChildBlock=Dg,g.complexBlockGeFirstSimpleChild=_d,g.complexBlockGetAllChildContainers=Se,g.complexBlockGetBottomChildContainers=Sg,g.complexBlockGetLastSimpleChild=Pi,g.complexBlockGetSelectedContainers=xr,g.complexBlockGetTopChildContainers=Tg,g.containerToDoc=$0,g.continuousScroll=Nm,g.convertBlockFrom=Ml,g.copyBlockAttributes=_p,g.createBlockAnchor=ao,g.createBlockCaretAnchor=Ag,g.createBlockContentElement=ro,g.createBlockElement=Wm,g.createBlockSimpleDocRange=Gl,g.createBlockSimpleRange=At,g.createBoxContentElement=Ym,g.createBoxElement=Gm,g.createBoxOp=Yg,g.createChildContainer=cg,g.createComplexBlockPosition=wt,g.createComplexDocPos=up,g.createComplexDocRange=Vb,g.createContainer=cp,g.createContainerElement=Bd,g.createDeleteOps=qg,g.createEditor=os,g.createEditorSelectionRange=qt,g.createElement=b,g.createEmptyContainer=yn,g.createEmptyDoc=Ko,g.createEmptyTextBlockData=Vl,g.createExpandedRange=Cl,g.createIconButton=vr,g.createImage=rm,g.createInsertOps=Hl,g.createInsertionContentElement=Jm,g.createInsertionElement=Qm,g.createLocalEditor=$P,g.createOnesEditor=_P,g.createRange=im,g.createRichText=Qo,g.createRootContainer=lg,g.createSimpleBlockPosition=j,g.createSimpleDocPos=dp,g.createTextBlockData=Un,g.createTextButton=cr,g.createTextOp=$e,g.createTextWithReplaceSoftReturn=Ud,g.daysAfter=md,g.deleteText=qd,g.diffDays=m8,g.disablePageScroll=Dm,g.docToHtml=Dp,g.docToHtmlFragment=Dr,g.docToMarkdown=Lr,g.docToText=Jl,g.downloadObjectToFile=j1,g.downloadSvgToString=A6,g.editLink=Ds,g.editorAddComment=G_,g.editorAddTextAttribute=Wp,g.editorAutoInsertBlock=Np,g.editorBreakTextBlock=Ar,g.editorClearCompositionText=Op,g.editorClearSelectedContents=gu,g.editorCopyBlock=cc,g.editorDeleteBlock=fu,g.editorDeleteBlockText=du,g.editorDeleteBlockWithoutChildren=hu,g.editorDeleteChildContainer=Ok,g.editorDeleteChildContainers=$p,g.editorFocusToBlock=pu,g.editorFocusToEnd=_0,g.editorGetBlockData=mo,g.editorGetBlockText=he,g.editorGetBlockTextEx=Yl,g.editorGetBoxData=fp,g.editorHandleKeyboardEvent=z0,g.editorInsertBlock=Rr,g.editorInsertBoxToBlock=Rp,g.editorInsertDoc=Vp,g.editorInsertDocAt=ku,g.editorInsertText=au,g.editorInsertTextToBlock=Mp,g.editorInsertTextToBlockEx=cu,g.editorMergeTextBlock=Pp,g.editorMoveDown=r0,g.editorMoveEnd=m0,g.editorMoveHome=g0,g.editorMoveLeft=e0,g.editorMoveLineEnd=B0,g.editorMoveLineHome=w0,g.editorMovePageDown=D0,g.editorMovePageUp=S0,g.editorMoveRight=n0,g.editorMoveUp=o0,g.editorMoveWordEnd=u0,g.editorMoveWordLeft=d0,g.editorRangeClearColor=Zp,g.editorRangeGetColor=vu,g.editorRangeSetColor=Gp,g.editorRemoveTextAttribute=$k,g.editorReplaceBlockText=oc,g.editorReplaceContainer=qp,g.editorRunOnce=Nu,g.editorSelectAll=O0,g.editorSelectContainer=Du,g.editorSelectDown=i0,g.editorSelectEnd=Tu,g.editorSelectHome=p0,g.editorSelectLeft=s0,g.editorSelectLineEnd=y0,g.editorSelectLineHome=v0,g.editorSelectPageDown=M0,g.editorSelectPageUp=L0,g.editorSelectRight=l0,g.editorSelectUp=c0,g.editorSelectWordEnd=f0,g.editorSelectWordLeft=h0,g.editorSetTextColor=Or,g.editorShowFindDialog=t_,g.editorUpdateBlockData=rc,g.editorUpdateCompositionText=Ap,g.editorUpdateEmbedData=zp,g.enablePageScroll=Lm,g.escapeHtmlText=dm,g.escapeRegExp=Cd,g.escapeSpace=Y7,g.executeBlockCommand=vg,g.executeEmbedBlockCommand=kg,g.executeRangeCommand=s2,g.fileToDataUrl=wl,g.findAfterOffsetNotType=Xd,g.findAllText=Kd,g.findInsertionById=Km,g.findNextOffset=lk,g.findPrevOffset=sk,g.findPrevOffsetNotType=Jd,g.findPrevSimpleBlockBeforeChildContainer=xg,g.findTarget=Ri,g.findWordEnd=eu,g.findWordLeft=tu,g.format=fd,g.formatBytes=Pm,g.formatDate=Fm,g.fragmentToHtml=Mm,g.fromBase64=yl,g.fromBase64ToBlob=xm,g.fromBase64ToUint8Array=l8,g.fromDocRange=co,g.fromNowString=pd,g.genId=N,g.getAllChildBlocks=$d,g.getAllQuickMenuItems=c1,g.getAllSelectedBlocks=tn,g.getAttributesAt=zl,g.getBlockBackground=qm,g.getBlockByIndex=yr,g.getBlockCaretRect=Ke,g.getBlockClass=kt,g.getBlockClassByType=Ir,g.getBlockClientRects=so,g.getBlockCommandsWithHook=Dd,g.getBlockContent=it,g.getBlockId=q,g.getBlockIndex=J,g.getBlockKind=Qe,g.getBlockMinWidth=fg,g.getBlockNearestRangeFromPoint=Mg,g.getBlockOptions=E8,g.getBlockPath=io,g.getBlockProperties=pg,g.getBlockRangeFromPoint=Ol,g.getBlockStyles=w8,g.getBlockTextLength=W,g.getBlockTools=Rt,g.getBlockType=ot,g.getBoxContent=vd,g.getBoxId=Zm,g.getBoxTypeFromElement=_i,g.getChildBlockCount=Ge,g.getChildBlocks=Mt,g.getChildOffset=uo,g.getColorFromAttributes=Qd,g.getComplexBlockClass=xe,g.getContainerBlockPath=rg,g.getContainerBlocks=ng,g.getContainerBlocksElement=Ll,g.getContainerById=Er,g.getContainerId=U,g.getContainerMinWidth=Td,g.getContainerToolsElement=C8,g.getContainerWidth=gg,g.getDistanceSquare=Cn,g.getElementOffset=Mi,g.getEmbedType=Oe,g.getExistsBlockTools=Dl,g.getExistsContainerById=tg,g.getFileExt=Am,g.getFirstChildBlock=Ut,g.getFirstClientRect=bl,g.getHeadingMenuOptions=o1,g.getHorizontalPadding=ed,g.getInsertionContent=yd,g.getLastChildBlock=Qt,g.getLastClientRect=$o,g.getListAllNextBrothers=Ls,g.getLogger=B,g.getNextBlock=dt,g.getNextValidOffset=Go,g.getNextVisibleBlock=Br,g.getOffsetInfoAfter=Wi,g.getOffsetInfoBefore=Ql,g.getOpAt=Kg,g.getOpLength=Wd,g.getParentBlock=F,g.getParentBox=kd,g.getParentContainer=H,g.getPrevBlock=gt,g.getPrevValidOffset=ho,g.getPrevVisibleBlock=wr,g.getRangeCommands=r2,g.getRootBlock=xd,g.getScrollContainer=We,g.getSpecialBlockCommands=Cg,g.getStandardEmbedBlockProperties=y1,g.getTextAfterOffset=rk,g.getTextBeforeOffset=ik,g.getTextBlockChild=_l,g.getTextBlockClass=dg,g.getTextBlockContentChildTextLength=Ne,g.getTextBlockContentChildType=Rg,g.getTextBlockContentChildren=zn,g.getTextLength=ue,g.getTextOpLength=Pd,g.getTextWidth=El,g.getToolbar=Nc,g.handleBlockElementUpdated=mg,g.hasAltOnly=e8,g.hasClass=nt,g.hasCtrlOrCmd=wm,g.hasCtrlOrCmdOnly=t8,g.hideBlock=Um,g.htmlToFragment=Bl,g.i18n=T,g.injectDocToHtmlFragment=ts,g.injectStyle=hm,g.insertEmptyBlock=x8,g.insertEmptyEmbedBlock=Ld,g.insertText=fo,g.intersectionCommands=sy,g.isBackspace=Em,g.isBlock=Vo,g.isBox=bd,g.isCJK=km,g.isChildContainer=Ye,g.isChildNode=It,g.isCollapsedRange=Ub,g.isComplexBlockPosition=Rd,g.isComplexKindBlock=at,g.isContainer=bn,g.isContainerSelectedAllChildBlocks=R0,g.isControlEvent=Ho,g.isDelete=o8,g.isDraggingFiles=xl,g.isEmbedBlock=Te,g.isEmptyContainer=Sd,g.isEmptyDoc=ql,g.isEmptyTextBlock=Tt,g.isEmptyTextBlockWithoutCompositionText=Ns,g.isEnterOnly=Bm,g.isEscape=dd,g.isFirefox=cd,g.isFirstChildBlockInComplexBlock=eb,g.isHighSurrogate=U7,g.isInBlock=wd,g.isInBlockTools=Ni,g.isLetter=bm,g.isLowSurrogate=td,g.isMatchShortcut=jn,g.isMoveForward=J7,g.isNavigationEvent=K7,g.isNavigationKey=ym,g.isNodeRemoved=lm,g.isNumber=Cm,g.isPrintableKey=ad,g.isRootBlock=Co,g.isRootContainer=pt,g.isSafari=vm,g.isSameDay=gd,g.isShiftEnter=n8,g.isShiftTab=i8,g.isShortcutEvent=X7,g.isSimpleBlock=B8,g.isSimpleBlockPosition=lo,g.isSimplePos=ap,g.isSimpleRange=Wl,g.isSpace=vl,g.isTab=r8,g.isTextBlockContentBoxChild=_e,g.isTextBlockContentChild=ji,g.isTextBlockContentInsertionChild=Fn,g.isTextBlockContentTextChild=Hi,g.isTextKindBlock=P,g.isTextKindBlockType=$i,g.isToday=jm,g.isValidOffset=re,g.isVisibleBlock=Sl,g.isYesterday=Hm,g.loadJs=cm,g.loadJsPromise=Po,g.lockers=qe,g.mergeCommands=_c,g.mergeDocs=Jo,g.mergeOps=Vd,g.mergeText=$b,g.multiSplitText=Ng,g.parseShortcut=Im,g.patchNode=Oi,g.pointInRect=jo,g.rangeAddAttribute=Vi,g.rangeGetTextColor=op,g.rangeRemoveAttribute=Sr,g.rangeSetTextColor=tp,g.rangeTransformText=Jg,g.registerDragDrop=sd,g.removeAttribute=Yd,g.removeClass=z,g.removeLastBr=Ab,g.removePlaceholderFromBlock=K4,g.removeStyle=um,g.replaceAll=g8,g.replaceAllCaseInsensitive=p8,g.replaceAllText=lp,g.replaceText=Ul,g.requestDownload=Tl,g.resetListStart=Rs,g.scrollable=_m,g.selectFile=zo,g.selectedBlockToDoc=sc,g.selectionToDoc=Xi,g.setAttributes=od,g.setClipboardData=Il,g.setClipboardDataByEvent=u8,g.setColorToAttributes=ep,g.setDataset=nd,g.setDefaultCursor=Ai,g.setStyles=rd,g.shareDBCommentToDocObject=Ju,g.shareDBDocCommentToComment=V2,g.shortcutToDisplayText=s8,g.showBlock=Vm,g.showDocVersions=PP,g.splitText=be,g.splitToThree=Wt,g.stringToDataUrl=Tm,g.stringToObjectUrl=hd,g.subText=$g,g.textNodeOffsetFromPoint=sm,g.toBase64URL=Fo,g.toPlainText=bt,g.toPlainTextKeepLength=sp,g.trimChar=ld,g.unicodeLength=V7,g.unicodeSubstr=q7,g.updateBlockSelection=hg,g.updateOpAttributes=ip,g.updateTextBlockContent=ok,g.updateUrl=ud,Object.defineProperties(g,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});