@ones-editor/editor 0.0.3-beta.193 → 0.0.3-beta.194
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@ones-editor/tsconfig.tsbuildinfo +1 -1
- package/dist/index.js +20 -20
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -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 fE(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 gm(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 fa="\u200B";function mE(n){return[...n].length}function gE(n,t,e){const r=[...n];let i;return e===void 0?i=r.length:i=t+e,r.slice(t,i).join("")}const As=S("dom-utils");function W(n,...t){n&&n.nodeType===Node.ELEMENT_NODE&&n.classList.add(...t)}function xt(n,t){return n instanceof HTMLElement?n.classList.contains(t):!1}function ot(n,...t){n&&n.nodeType===Node.ELEMENT_NODE&&n.classList.remove(...t),n.classList.length===0&&n.removeAttribute("class")}function w(n,t,e,o){const r=document.createElement(n);return t&&t.length>0&&W(r,...t),e&&e.appendChild(r),o&&(typeof o=="string"?r.innerText=o:Am(r,o)),r}function $l(n,t,e){const o=w("button",t,e);return o.innerHTML=n,o}function pm(n,t,e){const o=w("img",t,e);return o.src=n,o}function tC(n,t){try{const e=document.createRange();return e.setStart(n,t),e}catch(e){g(As,!1,`failed to create range: ${n.childNodes.length}, ${t}, ${e.message}`)}}function $d(n,t,e,o){try{const r=document.createRange();return r.setStart(n,t),r.setEnd(e,o),r}catch(r){g(As,!1,`failed to create expanded range: ${n.childNodes.length}, ${t}, ${e.childNodes.length}, ${o}, ${r.message}`)}}function Hd(n){const t=n.getClientRects();return g(As,t.length>=1,"getFirstClientRect: no rects"),t[0]}function bs(n){const t=n.getClientRects();return g(As,t.length>=1,"getLastClientRect: no rects"),t[t.length-1]}function nr(n,t,e){const o=n.left+n.width/2,r=n.top+n.height/2;return(o-t)**2+(r-e)**2}function eC(n,t,e){const o=n.data;g(As,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&&gm(o[l]))continue;s.setStart(n,l);const a=s.getClientRects();for(let d=0;d<a.length;d++){const h=a[d],p=nr(h,t,e);p<r&&(r=p,i=l)}}return i}function jd(n,t){if(n===t)return 0;if((!n.parentElement||!t.parentElement)&&g(As,!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]&&g(As,!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 a=o[i-1],d=Array.from(a.children);return d.indexOf(s)-d.indexOf(l)}}function Cm(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 nC(n){return!document.documentElement.contains(n)}function Xt(n,t){let e=t;for(;e;){if(n===e)return!0;e=e.parentNode}return!1}function oC(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 vs(n,t){const e=new Promise((o,r)=>{oC(n,t,i=>{i?r(i):o(void 0)})});try{await Eo.lock(t),await e}finally{Eo.release(t)}}function Am(n,t){Object.entries(t).forEach(([e,o])=>{n.dataset[e]=`${o}`})}function Ud(n,t){Object.entries(t).forEach(([e,o])=>{n.setAttribute(e,o)})}function bm(n,t){Object.entries(t).forEach(([e,o])=>{n.style.setProperty(e,o)})}function ma(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 Hl(n,t){return!n.target||!(n.target instanceof Element)?null:n.target.closest(t)}function rC(n){return Hl(n,'[data-type="editor-block"]')}function vm(n){if(!n)return!1;const t=window.getComputedStyle(n);return t.display==="none"||t.visibility==="hidden"?!1:n.parentElement?vm(n.parentElement):!0}function ys(n){let t;return n instanceof HTMLElement?t=n.offsetWidth:t=Number.parseInt(getComputedStyle(n).width,10),n.getBoundingClientRect().width/t}class pE{constructor(t){m(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 ma(t).left-ma(e).left}getVerticalElementScrollOffset(t,e){return ma(t).top-ma(e).top}scrollTo(t,e){this.element.scrollLeft=t,this.element.scrollTop=e}}class CE{constructor(){m(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
|
|
11
|
+
*/function fE(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 gm(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 fa="\u200B";function mE(n){return[...n].length}function gE(n,t,e){const r=[...n];let i;return e===void 0?i=r.length:i=t+e,r.slice(t,i).join("")}const As=S("dom-utils");function W(n,...t){n&&n.nodeType===Node.ELEMENT_NODE&&n.classList.add(...t)}function xt(n,t){return n instanceof HTMLElement?n.classList.contains(t):!1}function ot(n,...t){n&&n.nodeType===Node.ELEMENT_NODE&&n.classList.remove(...t),n.classList.length===0&&n.removeAttribute("class")}function w(n,t,e,o){const r=document.createElement(n);return t&&t.length>0&&W(r,...t),e&&e.appendChild(r),o&&(typeof o=="string"?r.innerText=o:Am(r,o)),r}function $l(n,t,e){const o=w("button",t,e);return o.innerHTML=n,o}function pm(n,t,e){const o=w("img",t,e);return o.src=n,o}function tC(n,t){try{const e=document.createRange();return e.setStart(n,t),e}catch(e){g(As,!1,`failed to create range: ${n.childNodes.length}, ${t}, ${e.message}`)}}function $d(n,t,e,o){try{const r=document.createRange();return r.setStart(n,t),r.setEnd(e,o),r}catch(r){g(As,!1,`failed to create expanded range: ${n.childNodes.length}, ${t}, ${e.childNodes.length}, ${o}, ${r.message}`)}}function Hd(n){const t=n.getClientRects();return g(As,t.length>=1,"getFirstClientRect: no rects"),t[0]}function bs(n){const t=n.getClientRects();return g(As,t.length>=1,"getLastClientRect: no rects"),t[t.length-1]}function nr(n,t,e){const o=n.left+n.width/2,r=n.top+n.height/2;return(o-t)**2+(r-e)**2}function eC(n,t,e){const o=n.data;g(As,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&&gm(o[l]))continue;s.setStart(n,l);const a=s.getClientRects();for(let d=0;d<a.length;d++){const h=a[d],p=nr(h,t,e);p<r&&(r=p,i=l)}}return i}function jd(n,t){if(n===t)return 0;if((!n.parentElement||!t.parentElement)&&g(As,!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]&&g(As,!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 a=o[i-1],d=Array.from(a.children);return d.indexOf(s)-d.indexOf(l)}}function Cm(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 nC(n){return!document.documentElement.contains(n)}function Xt(n,t){let e=t;for(;e;){if(n===e)return!0;e=e.parentNode}return!1}function oC(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 vs(n,t){const e=new Promise((o,r)=>{oC(n,t,i=>{i?r(i):o(void 0)})});try{await Eo.lock(t),await e}finally{Eo.release(t)}}function Am(n,t){Object.entries(t).forEach(([e,o])=>{n.dataset[e]=`${o}`})}function Ud(n,t){Object.entries(t).forEach(([e,o])=>{n.setAttribute(e,o)})}function bm(n,t){Object.entries(t).forEach(([e,o])=>{n.style.setProperty(e,o)})}function ma(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 Hl(n,t){return!n.target||!(n.target instanceof Element)?null:n.target.closest(t)}function rC(n){return Hl(n,'[data-type="editor-block"]')}function vm(n){if(!n)return!1;const t=window.getComputedStyle(n);return t.display==="none"||t.visibility==="hidden"?!1:n.parentElement?vm(n.parentElement):!0}function ys(n){let t;return n instanceof HTMLElement?t=n.offsetWidth:t=Number.parseInt(getComputedStyle(n).width,10),n.getBoundingClientRect().width/t}class pE{constructor(t){m(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 ma(t).left-ma(e).left}getVerticalElementScrollOffset(t,e){return ma(t).top-ma(e).top}scrollTo(t,e){this.element.scrollLeft=t,this.element.scrollTop=e}}class CE{constructor(){m(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 Or={elements:[],cancelMethods:[],add:(n,t)=>{Or.elements.push(n),Or.cancelMethods.push(t)},remove:(n,t)=>{const e=Or.elements.indexOf(n);e>-1&&(t&&Or.cancelMethods[e](),Or.elements.splice(e,1),Or.cancelMethods.splice(e,1))}},iC=typeof window<"u",AE={cancelOnUserAction:!0,easing:n=>--n*n*n+1,elementToScroll:iC?window:null,horizontalOffset:0,maxDuration:3e3,minDuration:250,speed:500,verticalOffset:0};async function ym(n,t={}){if(!iC)return new Promise(z=>{z(!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={...AE,...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 a=s?document.documentElement:i.elementToScroll;getComputedStyle(a).getPropertyValue("scroll-behavior")==="smooth"&&console.warn(`${a.tagName} has "scroll-behavior: smooth" which can mess up with animated-scroll-to's animations`);const h=s?new CE:new pE(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=h.getHorizontalElementScrollOffset(r,i.elementToScroll),o=h.getVerticalElementScrollOffset(r,i.elementToScroll)}else if(typeof n=="number")e=h.getHorizontalScroll(),o=n;else if(Array.isArray(n)&&n.length===2)e=n[0]===null?h.getHorizontalScroll():n[0],o=n[1]===null?h.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 p=h.getMaxHorizontalScroll(),A=h.getHorizontalScroll();e>p&&(e=p);const v=e-A,B=h.getMaxVerticalScroll(),D=h.getVerticalScroll();D<o?o-=window.innerHeight*3/4:o-=window.innerHeight*1/4,o>B&&(o=B);const x=o-D,_=Math.abs(Math.round(v/1e3*i.speed)),M=Math.abs(Math.round(x/1e3*i.speed));let H=_>M?_:M;return H<i.minDuration?H=i.minDuration:H>i.maxDuration&&(H=i.maxDuration),new Promise((z,q)=>{v===0&&x===0&&z(!0),Rr.remove(h.element,!0);let rt;const ft=()=>{qe(),cancelAnimationFrame(rt),z(!1)};Rr.add(h.element,ft);const Bt=Rn=>Rn.preventDefault(),jt=i.cancelOnUserAction?ft:Bt,Ut=i.cancelOnUserAction?{passive:!0}:{passive:!1},ne=["wheel","touchstart","keydown","mousedown"],qe=()=>{ne.forEach(Rn=>{h.element.removeEventListener(Rn,jt,Ut)})};ne.forEach(Rn=>{h.element.addEventListener(Rn,jt,Ut)});const Yn=Date.now(),$e=()=>{const Rn=Date.now()-Yn,kr=Rn/H,vn=Math.round(A+v*i.easing(kr)),an=Math.round(D+x*i.easing(kr));Rn<H&&(vn!==e||an!==o)?(h.scrollTo(vn,an),rt=requestAnimationFrame($e)):(h.scrollTo(e,o),cancelAnimationFrame(rt),qe(),Rr.remove(h.element,!1),z(!0))};rt=requestAnimationFrame($e)})}function ks(n,t,e){return n.left<=t&&t<=n.right&&n.top<=e&&e<=n.bottom}function bE(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 sC(n){if(!/["'&<>]/.exec(n))return n;const o={'"':""","'":"'","&":"&","<":"<",">":">"};return n.split("").map(l=>o[l]||l).join("")}function lC(n){const t=document.getElementById(n);t&&t.remove()}function cC(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 ga(n){const t="custom-cursor-style";if(n){const e=`body * { cursor: ${n} !important}`;cC(e,t)}else lC(t)}const aC=3,uC=S("drag-drop");class dC{constructor(t){m(this,"dragStarted",!1);m(this,"mouseDownEvent",null);m(this,"_dragOffsetX",0);m(this,"_dragOffsetY",0);m(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()});m(this,"handleMouseMove",t=>{var i;t.preventDefault(),t.stopPropagation(),g(uC,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:aC;(Math.abs(e)>=r||Math.abs(o)>=r)&&this.onDragStart(this.mouseDownEvent)});m(this,"handleMouseUp",t=>{if(t.button===0){g(uC,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&&ga(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&&ga(null),this.dragStarted&&this.options.onDragEnd(this,t,this.options.elem,e,o),this.unbindEvents(),this.dragStarted=!1}destroy(){this.unbindEvents(),this.untrackEvents()}}function km(n){return new dC(n)}const vE=S("character");function hC(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 fC(n){const t=n.charAt(0);return t>="0"&&t<="9"}function mC(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 zd(n){const t=[[9,13],[32],[160]];return hC(n.charCodeAt(0),t)}function gC(n){const t=[[12352,12687],[13056,13183],[13312,15661],[19968,40959],[63744,64255],[44032,55215]];return hC(n.charCodeAt(0),t)}function wm(n,t){let e=t;return g(vE,e.length===1,"invalid char length"),e==="]"&&(e="\\]"),e==="\\"&&(e="\\\\"),n.replace(new RegExp(`^[${e}]+|[${e}]+$`,"g"),"")}const Or=navigator.userAgent;function pC(){const n=navigator.userAgent.toLowerCase();return n.indexOf("safari")!==-1&&!(n.indexOf("chrome")>-1)}function Vd(){return navigator.userAgent.toLowerCase().indexOf("firefox")>-1}const Ze={isAndroid:!!Or.match(/Android/i),isIOS:!!Or.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/i),isIPad:!!Or.match(/iPad/i),isIPhone:!!Or.match(/iPhone/i),isLinux:!!Or.match(/Linux/i),isMac:!!Or.match(/Macintosh/i),isMobile:!!Or.match(/AppleWebKit.*Mobile.*/i),isWindows:!!Or.match(/Window/i),isIe:!!Or.match(/msie|trident/i),isSafari:pC(),isFirefox:Vd(),isMobileSafari:!1};Ze.isMobileSafari=Ze.isMobile&&Ze.isSafari;function Bm(n){return n?n.length===1||n==="Process"||n==="Unidentified"&&Ze.isAndroid:!1}function CC(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 yE(n){return CC(n.key)}function kE(n){switch(n){case"ArrowUp":case"ArrowLeft":case"Home":case"PageUp":return!0;default:return!1}}function ws(n){return n.ctrlKey||n.altKey||n.shiftKey||n.metaKey}function wE(n){return n.key?!!(n.ctrlKey||n.metaKey||n.altKey):!1}function AC(n){return Ze.isMac?n.metaKey&&!n.ctrlKey:!n.metaKey&&n.ctrlKey}function BE(n){return AC(n)&&!n.altKey&&!n.shiftKey}function EE(n){return!n.metaKey&&!n.ctrlKey&&!n.shiftKey&&n.altKey}function bC(n){return!ws(n)&&n.key==="Enter"}function xE(n){return n.key==="Enter"&&n.shiftKey&&!n.altKey&&!n.ctrlKey&&!n.metaKey}function Em(n){return!ws(n)&&n.key==="Escape"}function IE(n){return!ws(n)&&n.key==="Delete"}function vC(n){return!ws(n)&&n.key==="Backspace"}function TE(n){return!ws(n)&&n.key==="Tab"}function DE(n){return n.shiftKey&&n.key==="Tab"&&!n.ctrlKey&&!n.metaKey}function xo(n){if(!n)return"";if(Ze.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 a,d;const s=(a=e[r])!=null?a:5,l=(d=e[i])!=null?d:5;return s-l}).map(r=>r in e?`${r}+`:r).join("")}return n.replace("CtrlOrCmd","Ctrl")}function yC(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"?Ze.isMac?t.cmd=!0:t.ctrl=!0:r==="SPACE"?t.key=" ":t.key=r.substring(0,1)+r.substring(1).toLocaleLowerCase()}return t}function _r(n,t){const e=yC(t);return e.ctrl!==n.ctrlKey||e.alt!==n.altKey||e.shift!==n.shiftKey||Ze.isMac&&e.cmd!==n.metaKey?!1:e.key.length===1?e.key===n.key.toUpperCase():e.key.toUpperCase()===n.key.toUpperCase()}function xm(n,t){return bB.stringifyUrl({url:n,query:t})}function Si(n){return typeof n=="string"?ca.Base64.encode(n,!0):ca.Base64.fromUint8Array(n,!0)}function pa(n){return ca.Base64.decode(n)}function SE(n){return ca.Base64.toUint8Array(n)}function Im(n){return new Blob([ca.Base64.toUint8Array(n)])}const LE=Ti.init([Ti.classModule,Ti.styleModule,Ti.datasetModule,Ti.attributesModule,Ti.propsModule]);function Ca(n,t){const e=Ti.toVNode(n),o=Ti.toVNode(t);LE(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 jl(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 ME(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 ro(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||ME(e,"body"))&&(e=document.documentElement),e}function kC(n){n.preventDefault(),n.stopPropagation()}function wC(n){if(document.querySelector(`.editor-disable-scroll[data-scroll-id="${n}"]`))return;const t=w("div",["editor-disable-scroll"],null);t.setAttribute("data-scroll-id",n),t.addEventListener("wheel",kC,{passive:!1}),document.body.appendChild(t)}function BC(n){const t=document.querySelector(`.editor-disable-scroll[data-scroll-id="${n}"]`);t&&(t.removeEventListener("wheel",kC),t.remove())}function Dm(n,t,e){const o=new Blob([n]),r=new File([o],e,{type:t});return URL.createObjectURL(r)}function Wd(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 EC(n){const t=document.createElement("div");return t.appendChild(n),t.innerHTML}function xC(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 qd(n,t){const o=(qd.canvas||(qd.canvas=document.createElement("canvas"))).getContext("2d");return o?(typeof t=="string"?t?o.font=t:o.font=xC(window.getComputedStyle(document.body)):t instanceof Element&&(o.font=xC(window.getComputedStyle(t))),o.measureText(n).width+4):200}const RE=S("editor-clipboard");async function OE(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 Sm(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 RE.error(t),!1}}function Ul(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 Gd(n){return Array.isArray(n)?n.every(t=>t instanceof File):!1}function Aa(n){const t=n;if(!t)return"";const e=t.lastIndexOf(".");return e===-1?"":t.slice(e+1)}function Zd(n,t){const e=document.createElement("a");e.setAttribute("download",`${t||""}`),e.setAttribute("href",`${n}`),e.click(),e.remove()}const IC=S("auto-scroll");function TC(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 DC(n,{direction:t,step:e}){let o=null;const r=t==="left"||t==="right",i=()=>TC(n,t)?(r?t==="left"?n.scrollLeft=Math.max(n.scrollLeft-e,0):n.scrollLeft=Math.min(n.scrollLeft+e,n.scrollWidth):t==="top"?n.scrollTop=Math.max(n.scrollTop-e,0):n.scrollTop=Math.min(n.scrollTop+e,n.scrollHeight),o=requestAnimationFrame(i),o):(IC.debug("No need for scroll"),null);return o=requestAnimationFrame(i),()=>{o&&cancelAnimationFrame(o)}}class Qd{constructor(t){m(this,"cancelScroll",null);m(this,"options");m(this,"scrollDomInfo");m(this,"scrolling",!1);m(this,"getScrollingDirection",t=>{const{x:e,y:o}=t,{top:r,bottom:i,left:s,right:l}=this.scrollDomInfo,{edge:a}=this.options;return a.top&&o<=a.top+r?"top":a.bottom&&o>=i-a.bottom?"bottom":a.left&&e<=s+a.left?"left":a.right&&e>=l-a.right?"right":null});m(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;IC.debug(`scroll direction: ${i}`),this.cancelScroll=DC(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.getBoundingClientRect(),o=e.top,r=e.left,i=e.bottom,s=e.right;return{left:r,top:o,right:s,bottom:i}}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 SC(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 ba(n,t){let e=`${n}`;const o=t-e.length;for(let r=0;r<o;r++)e=`0${e}`;return e}const{t:Bs}=R;function Lm(n,t){const e=new Date(n).getTime()+864e5*t;return new Date(e)}function _E(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 FE(n,t){return Lm(n,t)}function Mm(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 LC(n){const t=new Date,e=new Date(n);return Mm(t,e)}function MC(n){const t=Lm(new Date,-1);return Mm(t,n)}function PE(n,t){return Math.round((n.getTime()-t.getTime())/864e5)}function Rm(n,t){const e=new Date(n);if(t){const o=e.getFullYear(),r=e.getMonth()+1,i=e.getDate(),s=e.getHours(),l=e.getMinutes();let a=t;return a=a.replace("YYYY",`${o}`),a=a.replace("MM",ba(r,2)),a=a.replace("DD",ba(i,2)),a=a.replace("M",`${r}`),a=a.replace("D",`${i}`),a=a.replace("hh",ba(s,2)),a=a.replace("mm",ba(l,2)),a=a.replace("h",`${s}`),a=a.replace("m",`${l}`),a}return n.toLocaleDateString()}function Om(n,t){const e=new Date(n),o=new Date;if(e.getTime()-o.getTime()>10*1e3)return R.t("date.dateFromFuture");if(LC(e)){const i=(o.getTime()-n.getTime())/1e3;if(i<10*60)return Bs("date.dateJustNow");if(i<60*60)return Bs("date.dateMinutesAgo",{num:`${Math.floor(i/60)}`});const s=Math.floor(i/60/60);return s===1?Bs("date.date1HourAgo"):Bs("date.dateHoursAgo",{num:`${s}`})}if(MC(n))return Bs("date.dateYesterday");const r=Math.floor((o.getTime()-n.getTime())/1e3/24/60/60)+1;return r<14?Bs("date.dateDaysAgo",{num:`${r}`}):r<28?Bs("date.dateWeeksAgo",{num:`${Math.round(r/7)}`}):Rm(n,t)}function _m(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function NE(n,t,e){return n.replace(new RegExp(_m(t),"g"),e)}function $E(n,t,e){return n.replace(new RegExp(_m(t),"gi"),e)}function RC(n,t,e){const r=document.createElement("canvas").getContext("2d");if(!r)return null;if(r.font=String(t),r.measureText(n).width>e){let s=0,l=0;for(;l<e;)l=r.measureText(n.slice(0,s)).width,s++;return`${n.slice(0,s-2)}...`}return n}const OC=/[\u3040-\u30ff\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff\uff66-\uff9f\uAC00-\uD7AF]/,_C=" -\x7F0-9!-/:-@[-`{-~\u0370-\u03FF\u0400-\u04FF",HE=new RegExp(`[${_C}]`),jE=new RegExp(`([^(${_C})])`,"g"),FC=/(\ud83c[\udf00-\udfff])|(\ud83d[\udc00-\ude4f\ude80-\udeff])|[\u2600-\u2B55]/;function PC(n){return n.length===0?0:n.split("").reduce((t,e)=>{const o=(t<<5)-t+e.charCodeAt(0);return o&o},0)}function UE(n,t=1){var o,r;return(r=((o=Array.from(n))==null?void 0:o.filter(i=>OC.test(i))).slice(-t))==null?void 0:r.join("")}function zE(n,t=1){var r;const e=Array.from((r=n==null?void 0:n.replace(jE,""))==null?void 0:r.split(/\s/));return e.reduce((i,s,l)=>{var a,d;return l===e.length-1&&i.length<t?`${i}${(a=s==null?void 0:s.slice(0,t-i.length))!=null?a:""}`:`${i}${(d=s[0])!=null?d:""}`},"").slice(0,t)}function VE(n,t=1){var o,r;return(r=((o=Array.from(n))==null?void 0:o.filter(i=>FC.test(i))).slice(-t))==null?void 0:r.join("")}function WE(n,t=1){var e,o;return(o=(e=Array.from(n))==null?void 0:e.slice(0,t))==null?void 0:o.join("")}function Yd(n,t=1){if(!n||n.length===0)return"";const e=OC.test(n),o=HE.test(n),r=FC.test(n);switch(!0){case e:return UE(n,t);case o:return zE(n,t);case r:return VE(n,t);default:return WE(n,t)}}var NC=(n=>(n.blue="#338FE5",n.cyan="#34AFDE",n.teal="#2CB2AE",n.green="#24B47E",n.kelly="#8AAB3F",n.yellow="#F0A100",n.orange="#EB6414",n.red="#E52727",n.fuchsia="#BE507D",n.purple="#9678D3",n))(NC||{});function Jd(n){const t=Object.values(NC),e=Math.abs(typeof n=="string"&&n.trim()?PC(n.trim()):0)%t.length;return t[e]}const $C=S("container-children");function pe(n){const t=Array.from(n.querySelectorAll(":scope > .container-blocks > div[data-type=editor-block]"));return g($C,t.length>0,"container have not any child block"),t}function xe(n){const t=n.querySelector(":scope > .container-blocks > div[data-type=editor-block]");return g($C,t,"container have not any child block"),t}function Qe(n){const t=pe(n);return t[t.length-1]}function Io(n){return pe(n).length}function Fr(n,t){return pe(n)[t]}const To=S("block-dom");function Es(n){return n instanceof HTMLDivElement?n.getAttribute("data-type")==="editor-block":!1}function HC(n){return n instanceof HTMLElement&&n.getAttribute("data-type")==="block-tools"}function jC(n){W(n,"block-hidden")}function UC(n){ot(n,"block-hidden")}function Kd(n){return!xt(n,"block-hidden")}function it(n){const{id:t}=n;return g(To,t,"no block id"),t}function Dt(n){const t=n.getAttribute("data-block-type");return g(To,t,"invalid block dom, no data-type"),t}function et(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 xs(n){const t=n instanceof Element?n:n.parentElement;if(!t)return null;const e=t.closest("div[data-type=editor-block]:not(:scope)");return e||null}function nt(n){const t=n.closest("div[data-type=editor-container]");return g(To,t,"failed to get block container"),t}function Lt(n){const t=n.querySelector(":scope >div[data-type=block-content]");return g(To,t,"no block content"),t}function te(n){let t=n.querySelector(":scope >div[data-type=block-tools]");return t||(t=w("div",[],n),t.setAttribute("data-type","block-tools")),g(To,t,"no block tools"),t}function Xd(n){const t=n.querySelector(":scope >div[data-type=block-tools]");return t||null}function zC(n){let t=n.querySelector(":scope > div[data-type=block-background]");return t||(t=w("div",[],n),t.setAttribute("data-type","block-background")),t}function VC(n,t,e){const o=n.editorDecorators.decorateBlock(t,e),{id:r,type:i}=o;g(To,r,"no block id");const s=w("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&&W(s,...l.classes),l.attributes&&Object.entries(l.attributes).forEach(([a,d])=>{s.setAttribute(a,d)}),l.styles&&Object.entries(l.styles).forEach(([a,d])=>{s.style.setProperty(a,d)}),s}function Is(n,t){const e=w(t,[],null);return e.setAttribute("data-type","block-content"),n&&n.appendChild(e),e}function WC(n){const t=w("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 va(n){const t=n.getAttribute("data-box-type");return g(To,t,"not a valid box element, no type"),t}function Fm(n){return n instanceof HTMLSpanElement?n.getAttribute("data-type")==="editor-box":!1}function qC(n){const{id:t}=n;return g(To,t,"no box id"),t}function Pm(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 GC(n){n.innerHTML="",w("span",["box-space-start"],n,fa);const t=w("span",[],n);return t.setAttribute("data-type","box-content"),w("span",["box-space-start"],n,fa),t}function Nm(n){const t=n.querySelector("span[data-type=box-content]");return g(To,t,"invalid box dom, no content"),t}function ZC(n,t){const e=w("span",[`${n}-insertion`],null);return e.setAttribute("data-type","editor-insertion"),e.setAttribute("data-insertion-id",t),e}function QC(n,t){return n.rootContainer.querySelector(`[data-insertion-id=${t}]`)}function YC(n){n.innerHTML="",w("span",["insertion-space-start"],n,fa);const t=w("span",[],n);return t.setAttribute("data-type","insertion-content"),w("span",["insertion-space-start"],n,fa),t}function $m(n){const t=n.querySelector("span[data-type=insertion-content]");return g(To,t,"invalid insertion-child dom, no content"),t}function ce(n){let t=n.previousElementSibling;for(;t;){if(Es(t))return t;t=t.nextElementSibling}return null}function Zt(n){let t=n.nextElementSibling;for(;t;){if(Es(t))return t;t=t.nextElementSibling}return null}function Ts(n){let t=n.previousElementSibling;for(;t;){if(Es(t)&&Kd(t))return t;t=t.previousElementSibling}return null}function Ds(n){let t=n.nextElementSibling;for(;t;){if(Es(t)&&Kd(t))return t;t=t.nextElementSibling}return null}function bt(n){const t=nt(n),o=pe(t).indexOf(n);return g(To,o!==-1,"invalid block & container dom, failed to get block index"),o}function Hm(n){return!n||!(n instanceof Node)?!1:!!et(n)}function Ss(n){if(!Hm(n))return!1;const t=n,e=t instanceof Element?t:t.parentElement;return e?!!e.closest("div[data-type=block-tools]"):!1}const JC=S("block-class");function Qt(n,t){return n.editorBlocks.getBlockClass(Dt(t))}function KC(n,t){const e=n.editorBlocks.getBlockClass(Dt(t));return g(JC,e.blockKind==="text",`is not a text block, ${e.blockType}`),e}function zn(n,t){const e=n.editorBlocks.getBlockClass(Dt(t));return g(JC,e.blockKind==="complex",`is not a text block, ${e.blockType}`),e}function Ls(n,t){return n.editorBlocks.getBlockClass(t)}function tt(n,t){return Qt(n,t).blockKind==="text"}function ya(n,t){return n.editorBlocks.getBlockClass(t).blockKind==="text"}function Mt(n,t){return Qt(n,t).blockKind==="complex"}function qE(n,t){return!Mt(n,t)}function Do(n,t){return Qt(n,t).blockKind}function So(n,t,e){return Qt(n,t).getCaretRect(t,e)}const XC=S("container");function Pr(n){return n.getAttribute("data-type")==="editor-container"}function Yt(n){return xt(n,"root")}function Lo(n){return xt(n,"child")}function at(n){const t=n.getAttribute("data-container-id");return g(XC,t,"no id for container"),Yt(n)&&g(XC,t==="root",`invalid root container id, : ${t}`),t}function t4(n,t){const e=at(n);return t.getContainerBlocks(e)}const jm=S("block");function ut(n,t){return Qt(n,t).getBlockTextLength(t)}function e4(n){n.editorBlocks.forEach(t=>{t.clearSelection(n)})}function n4(n,t,e,o){Qt(n,t).updateSelection(n,t,e,o)}function Um(n){for(;;){const t=nt(n);if(Yt(t))return n;const e=et(t);g(jm,e,"no parent block exists for child container"),n=e}}function o4(n,t){const e=Qt(n,t);if(!!e.getMinWidth)return e.getMinWidth(n,t)}function r4(n,t,e){const o=Qt(n,t);o.handleBlockElementUpdated&&o.handleBlockElementUpdated(n,t,e)}function th(n,t,e,o){try{const r=Ls(n,e).convertFrom;return r?r(n,t,o):null}catch{return jm.debug(`unsupported block type: ${e}`),null}}function Nr(n,t,e){const o=Qt(n,t);return o.getClientRects?o.getClientRects(n,t,e):[t.getBoundingClientRect()]}function GE(n,t){const e=Qt(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;g(jm,s==="string"||s==="number"||s==="boolean","invalid style value")}),r}function he(n,t){return Do(n,t)==="text"?ut(n,t)===0:!1}const i4=S("block-path");function Li(n){const t=[];let e=n;for(;e;){const o=nt(e);if(t.unshift({containerId:at(o),blockIndex:bt(e)}),Yt(o))return t;const r=et(o);g(i4,r,"no parent block"),e=r}return g(i4,!1,"no parent block"),[]}function ZE(n,t){var r,i;const e=Qt(n,t);return(i=(r=e.getOptions)==null?void 0:r.call(e,n))!=null?i:{name:Dt(t)}}function io(n){return Yt(nt(n))}function s4(n,t){var r;const e=Qt(n,t);return(r=e.getBlockProperties)==null?void 0:r.call(e,n,t)}function zm(n,t){var i,s;const e=Qt(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 a=(s=l.commands)==null?void 0:s.call(l,n,t);a&&(r[a.group]=a)}return r}function QE(n,t,e){var s,l,a,d;const o=Qt(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 h of n.blockHooks){const p=(l=h.commands)==null?void 0:l.call(h,n,t);p&&(i[p.group]=p)}return(d=(a=i[e])==null?void 0:a.commands)!=null?d:[]}function l4(n,t,e){let o=t;for(;o;){const r=QE(n,o,e);if(r.length>0)return{element:Lt(o),commands:r};if(io(o))break;o=xs(o)}return{element:null,commands:[]}}const c4=S("embed-block-common");function Me(n){return Dt(n)==="embed"}function fn(n){g(c4,Me(n),"not an embed block");const t=n.getAttribute("data-embed-type");return g(c4,t,"no embed data type"),t}function YE(n,t){return n.editorEmbeds.getEmbedClass(fn(t))}function Ms(n,t){return n.editorEmbeds.getEmbedClass(t)}async function Vm(n,t,e,o,r){const i=Ms(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 JE(n,t,e,o,r){var l,a;const i=(a=(l=Ls(n,t)).getOptions)==null?void 0:a.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 KE=S("execute-block-command");function a4(n,t,e,o){var d;g(KE,Me(t),"not a embed block");const r=fn(t),i=Ms(n,r);if(!i.getOptions)return;const s=(d=i.getBlockProperties)==null?void 0:d.call(i,n,t),l=s==null?void 0:s.blockCommands;if(!l)return;const a=Object.entries(l);for(const h of a)if(h[0]===e)return h[1].executeCommand(n,t,o)}function u4(n,t,e,o){const r=zm(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 $r=S("text-block-child");function ka(n){return n.tagName==="SPAN"}function so(n){return g($r,ka(n),"not a valid text child"),n.getAttribute("data-type")==="editor-box"}function Hr(n){return g($r,ka(n),"not a valid text child"),n.getAttribute("data-type")==="editor-insertion"}function wa(n){return!so(n)&&!Hr(n)}function d4(n){return g($r,ka(n),"not a valid text child"),so(n)?"box":Hr(n)?"insertion":"text"}function lo(n){const t=d4(n);return t==="insertion"?0:t==="box"?1:(g($r,n.textContent!==null,"text block content is undefined"),g($r,n.textContent.length>=0,"text block content length is negative"),n.textContent.length)}function or(n){const t=Lt(n),e=Array.from(t.children);return e.forEach(o=>{g($r,ka(o),"not a valid text child")}),e}function eh(n,t){const e=or(n);let o=0;for(let r=0;r<e.length;r++){const i=e[r],s=lo(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 g($r,l>0,"invalid offset value"),g($r,!so(i),"invalid box child"),{prev:i,next:i,offset:l}}g($r,!1,`invalid block child at position: ${t}`)}const h4=S("element");function Wm(n,t,e){const o=w("div",[t],n);return o.setAttribute("data-type","editor-container"),o.setAttribute("data-container-id",e),w("div",["container-blocks"],o),o}function jr(n,t){const e=n.rootElement.querySelector(`[data-container-id=${t}`);return g(h4,e,`no container: ${t}`),e}function f4(n,t){return n.rootElement.querySelector(`[data-container-id=${t}`)}function nh(n){const t=n.querySelector(":scope > .container-blocks");return g(h4,t,"no container blocks element"),t}function XE(n){let t=n.querySelector(":scope > .container-tools");return t||(t=w("div",["container-tools"],n)),t}const tx=S("child-container-path");function m4(n){if(Yt(n))return[];const t=et(n);return g(tx,t,"no parent block"),Li(t)}const g4=S("load-blocks");function qm(n,t,e){const o=at(t),r=t4(t,n.doc);g(g4,r.length>0,"no blocks in container");const i=document.createDocumentFragment();r.forEach((l,a)=>{const d=n.editorBlocks.createBlock([...e,{containerId:o,blockIndex:a}],t,l);i.appendChild(d)}),nh(t).appendChild(i)}function ex(n,t,e){const o=nh(n);if(t===0)return o.insertBefore(e,o.firstChild),e;const r=pe(n);return g(g4,t>=0&&t<=r.length,"invalid block index"),t===r.length?o.appendChild(e):o.insertBefore(e,r[t]),e}function nx(n,t,e,o){const r=m4(t);r.push({containerId:at(t),blockIndex:e});const i=n.editorBlocks.createBlock(r,t,o);return ex(t,e,i),i}const p4=S("root-container");class ox{constructor(t,e){m(this,"resizeObserver");m(this,"handleContextMenu",t=>{});m(this,"handleResize",()=>{try{this.editor.selection.updateSelection(null),this.editor.emit("resize",this.editor)}catch(t){p4.warn(`failed to update selection while container resizing: ${t.message}`)}});m(this,"handleClick",t=>{this.editor.emit("click",this.editor,t);const e=t.target;if(!Ss(e)&&(t.detail===1&&this.editor.input.focus(),t.detail===3&&this.editor.selectionHandler.handleTripleClick(t),t.detail===1&&t.button===0)){const o=document.elementFromPoint(t.clientX,t.clientY);if(o&&Xt(this.rootContainer,o)){const r=et(o);r&&Xt(r,o)&&this.handleBlockClick(t,r,o)}}});m(this,"handleBlockClick",(t,e,o)=>{var s,l;if(!tt(this.editor,e))return;const r=Pm(o);if(r){const a=et(r);g(p4,a,"no parent block"),(l=(s=this.editor.editorBoxes.getBoxClass(va(r)))==null?void 0:s.handleClickBox)==null||l.call(s,this.editor,r,t);return}const i=o.closest("span.text.link");i&&or(e).indexOf(i)!==-1&&this.editor.emit("clickLink",this.editor,t,i)});m(this,"handleDblClick",t=>{Ss(t.target)||this.editor.selectionHandler.handleDblClick(t)});m(this,"handleMouseDown",t=>{const e=t.target;if(!!e&&e instanceof Node&&!Ss(e)){if(e instanceof HTMLElement&&e.draggable){this.editor.selectionHandler.handleMouseDown(t,{autoScroll:!1}),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,{autoScroll:!0})),Ze.isMobileSafari||(t.preventDefault(),this.editor.input.focus()),t.button===2&&t.stopPropagation()}});m(this,"handleMouseMove",t=>{this.editor.selectionHandler.handleMouseMove(t)});m(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=nh(this.rootContainer);e.innerHTML="",qm(this.editor,this.rootContainer,[]);const o=this.editor.findBlockById(t.start.blockId);if(o)this.editor.selection.selectBlock(o,0);else{const r=xe(this.rootContainer);this.editor.selection.selectBlock(r,0)}}}function C4(n){const t=Wm(n.contentElement,"root","root");return n.rootContainer=t,qm(n,t,[]),new ox(n,t)}function A4(n,t,e,o){const r=f4(n,o);if(r)return e.appendChild(r),setTimeout(()=>{n.emit("containerRemount",n,o)}),r;const i=Wm(e,"child",o);return qm(n,i,t),i}function b4(n,t){const e=n.getBoundingClientRect().width;return t.withPadding?e:e-Cm(n)}function Gm(n,t){let e=Number.MAX_SAFE_INTEGER;const o=pe(t);for(let i=0;i<o.length;i++){const s=o[i],l=o4(n,s);l&&(e=Math.min(e,l))}return e===Number.MAX_SAFE_INTEGER?void 0:e+Cm(t)}function Ba(n,t){const e=pe(t);return e.length!==1?!1:he(n,e[0])}const rx=S("complex-block-position");class Mo{constructor(t,e,o){m(this,"blockId");m(this,"childContainerId");m(this,"custom");t instanceof HTMLElement?this.blockId=it(t):(g(rx,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 ix=S("simple-block-position");class je{constructor(t,e,o){m(this,"blockId");m(this,"offset");m(this,"type");t instanceof HTMLElement?this.blockId=it(t):(g(ix,typeof t=="string",`not a valid block id: ${t}`),this.blockId=t),this.offset=e,this.type=o}isSimple(){return!0}}const Zm=S("editor-position");function st(n,t,e){return new je(n,t,e)}function fe(n,t,e){return new Mo(n,t,e)}function Ur(n){return n instanceof je}function Qm(n){return n instanceof Mo}function Ym(n,t,e){if(Ur(t)&&Ur(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 g(Zm,i!==s,"comparePosition: blocks are the same"),jd(i,s)}if(Qm(t)&&Qm(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 g(Zm,i!==s,"comparePosition: containers are the same"),jd(i,s)}return g(Zm,!1,"invalid "),0}const oh=S("simple-range");class Ye{constructor(t,e){m(this,"editor");m(this,"_anchor");m(this,"_focus");m(this,"reverse");this.editor=t,this._anchor=e.anchor,this._focus=e.focus,this.reverse=Ym(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 Ye))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);g(oh,e,"no start block"),g(oh,o,"no end block");const r=nt(e),i=nt(o);g(oh,r===i,"invalid range");const s=[];if(e===o)s.push({block:e,start:this.start,end:this.end});else{const l=bt(e),a=bt(o);g(oh,l<a,"invalid range, start > index"),s.push({block:e,start:this.start,end:st(e,ut(this.editor,e),"end")});const d=pe(r);for(let h=l+1;h<a;h+=1){const p=d[h];s.push({block:p,start:st(p,0,"home"),end:st(p,ut(this.editor,p),"end")})}s.push({block:o,start:st(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 Ye(this.editor,this)}toDocRange(){return{anchor:this.anchor,focus:this.focus}}static from(t,e){return new Ye(t,e)}}S("unknown-block");function sx(n,t,e,o,r){W(o,"unknown-block");const i=Is(o,"div");return i.innerText=`unknown block (${r.type}): ${JSON.stringify(r)}`,i}function lx(n){return 1}function cx(n,t,e,o){return null}function ax(n,t,e,o){const r=document.elementsFromPoint(e,o)[0];if(!r||!t.contains(r)||!n.contains(t))return null;const i=it(t),s=st(i,0,"home"),l=st(i,1,"end");return new Ye(n,{anchor:s,focus:l})}function ux(n,t){const o=Lt(n).getBoundingClientRect();return new DOMRect(o.left+o.width/2,o.top,1,o.height)}function dx(n,t,e,o){W(t,"selected")}function hx(n){n.rootContainer.querySelectorAll("div.unknown-block[data-type=editor-block]").forEach(t=>{ot(t,"selected")})}function fx(n,t,e,o){return`[unknown block, ${t.type}]`}const mx={blockType:"unknown-block",blockKind:"embed",createBlockContent:sx,getBlockTextLength:lx,getRangeFromPoint:ax,moveCaret:cx,getCaretRect:ux,updateSelection:dx,clearSelection:hx,convertTo:fx},Jm=S("editor-blocks");class v4{constructor(t){m(this,"blocks",new Map);this.editor=t}registerBlockClass(t){const e=t.blockType,o=this.blocks.get(e);g(Jm,!o,`duplicated block type: ${e}`),this.blocks.set(e,t)}getBlockClass(t){const e=this.blocks.get(t);return g(Jm,e,`unknown block type: ${t}`),e}hasBlock(t){return this.blocks.has(t)}createBlock(t,e,o){const r=VC(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&&(Jm.warn("content parent is not block"),r.appendChild(s)),this.editor.blockHooks.forEach(l=>{var a;(a=l.create)==null||a.call(l,this.editor,t,e,r,o)}),r}forEach(t){this.blocks.forEach(t)}registerUnknownBlock(t){const e={...mx,blockType:t};return this.editor.editorBlocks.registerBlockClass(e),e}}const y4=S("editor-embeds");class k4{constructor(t){m(this,"objects",new Map);this.editor=t}registerEmbedClass(t){const e=t.embedType,o=this.objects.get(e);g(y4,!o,`duplicated embed object type: ${e}`),this.objects.set(e,t)}getEmbedClass(t){const e=this.objects.get(t);return g(y4,e,`unknown embed type: ${t}`),e}getEmbedClassFromBlock(t){return this.getEmbedClass(fn(t))}forEach(t){this.objects.forEach(t)}}const w4=S("embed-block");function gx(n,t,e,o,r){const i=Is(o,"div");g(w4,r.type==="embed",`not an embed data: ${JSON.stringify(r)}`);const s=r;return g(w4,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 px(n){return 1}function Cx(n,t,e,o){return null}function Ax(n,t,e,o){const r=document.elementsFromPoint(e,o)[0];if(!r||!t.contains(r)||!n.contains(t))return null;const i=it(t),s=st(i,0,"home"),l=st(i,1,"end");return new Ye(n,{anchor:s,focus:l})}function bx(n,t){const o=Lt(n).getBoundingClientRect();return new DOMRect(o.left+o.width/2,o.top,1,o.height)}function vx(n,t,e,o){W(t,"selected")}function yx(n){n.rootContainer.querySelectorAll("div.embed-block[data-type=editor-block][data-block-type=embed]").forEach(t=>{ot(t,"selected")})}function kx(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 wx(n,t,e,o){const r=Ms(n,t.embedType);return r.convertTo?r.convertTo(n,t,e,o):""}function Bx(n,t){const e=YE(n,t);return e.getBlockProperties?e.getBlockProperties(n,t):{}}function Ex(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 xx(n,t,e,o){const r=fn(t),i=Ms(n,r);!i.handleDeleteBlock||i.handleDeleteBlock(n,t,e,o)}function Ix(n,t,e){const o=fn(t),r=Ms(n,o);return r.handleUpdateBlock?r.handleUpdateBlock(n,t,e):!1}function Tx(n,t,e,o,r){const i=fn(t),s=Ms(n,i);if(s.handleDropOver)return s.handleDropOver(n,t,e,o,r)}function Dx(n,t,e,o,r){const i=fn(t),s=Ms(n,i);if(s.handleDrop&&n.isWritable())return s.handleDrop(n,t,e,o,r)}async function Sx(n,t,e){const o=t.embedType,r=n.editorEmbeds.getEmbedClass(o);if(r.toStandardDoc){const i=n.getBlockById(t.id),s=Li(i);return r.toStandardDoc(n,t,e,s)}}const B4={blockType:"embed",blockKind:"embed",createBlockContent:gx,getBlockTextLength:px,getRangeFromPoint:Ax,moveCaret:Cx,getCaretRect:bx,updateSelection:vx,clearSelection:yx,convertFrom:kx,convertTo:wx,getBlockProperties:Bx,getOptions:Ex,handleDeleteBlock:xx,handleUpdateBlock:Ix,handleDropOver:Tx,handleDrop:Dx,toStandardDoc:Sx},mn=S("complex-block-helper");function xn(n,t,e){return zn(n,t).getChildContainers(n,t,e)}function Rs(n,t,e,o){return e.isSimple()?(g(mn,o.isSimple(),"invalid start and end position"),xn(n,t)):(g(mn,!e.isSimple(),"invalid start pos"),g(mn,!o.isSimple(),"invalid end pos"),zn(n,t).getSelectedContainers(n,t,e,o))}function Lx(n,t){if(bt(t)!==0)return!1;const e=et(nt(t));if(!e)return!1;g(mn,Mt(n,e),"not a complex block");const o=nt(t),i=xn(n,e).indexOf(o);return g(mn,i>=0,"not valid child container"),i===0}function Km(n,t,e){const o=xn(n,t,e);if(o.length===0)return null;const r=o[0];if(!r)return null;const i=xe(r);return Mt(n,i)?Km(n,i,e):i}function zl(n,t,e){const o=xn(n,t,e);if(o.length===0)return null;const r=o[o.length-1];if(!r)return null;const i=Qe(r);return Mt(n,i)?zl(n,i,e):i}function E4(n,t){g(mn,Lo(t),"not a child container");const e=et(t);g(mn,e,"no parent block"),g(mn,Mt(n,e),"not a complex block");const o=xn(n,e),r=o.indexOf(t);if(g(mn,r!==-1,"child container not found"),r===0){const l=ce(e);return l?Mt(n,l)?zl(n,l):l:null}const i=o[r-1],s=Qe(i);return Mt(n,s)?zl(n,s):s}function x4(n,t){g(mn,Mt(n,t),"not a complex block");const e=xn(n,t);if(g(mn,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 a=1;a<e.length;a++){const d=e[a],h=d.getBoundingClientRect();if(h.right<=i){l.push(d),i=h.left;continue}if(h.left>=s){s=h.right;continue}}return l}function I4(n,t){g(mn,Mt(n,t),"not a complex block");const e=xn(n,t);if(g(mn,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 a=e.length-2;a>=0;a--){const d=e[a],h=d.getBoundingClientRect();if(h.right<=i){l.push(d),i=h.left;continue}if(h.left>=s){s=h.right;continue}}return l}function T4(n,t,e,o){const r=t.getBoundingClientRect(),i=o<r.top,s=i?x4(n,t):I4(n,t);let l=s[0],a=nr(l.getBoundingClientRect(),e,o);for(let d=1;d<s.length;d++){const h=s[d],p=h.getBoundingClientRect(),A=nr(p,e,o);A<a&&(l=h,a=A)}return i?xe(l):Qe(l)}function rh(n,t,e,o){const r=it(t);g(mn,r===e.blockId,"invalid start pos"),g(mn,r===o.blockId,"invalid end pos");const i=zn(n,t);return i.adjustSelectionPos?i.adjustSelectionPos(n,t,e,o):{anchor:e,focus:o}}class rr{constructor(t,e){m(this,"editor");m(this,"reverse");m(this,"_anchor");m(this,"_focus");this.editor=t,this._anchor=e.anchor,this._focus=e.focus,this.reverse=Ym(this.editor,this._anchor,this._focus)>0}isCollapsed(){return!1}isEqual(t){if(!(t instanceof rr))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 Rs(this.editor,t,this.start,this.end)}clone(){return new rr(this.editor,this)}toDocRange(){return{anchor:this._anchor,focus:this._focus}}}const Mx=S("selection-range");function Ue(n,t){const{anchor:e,focus:o}=t;return e instanceof je&&o instanceof je?new Ye(n,{anchor:e,focus:o}):(g(Mx,e instanceof Mo&&o instanceof Mo,"start position type does not math end type"),new rr(n,{anchor:e,focus:o}))}function Ce(n,t,e,o){const r=new je(t,e,"normal"),i=new je(t,o!=null?o:e,"normal");return Ue(n,{anchor:r,focus:i})}function Rx(n){return!!n.anchor.childContainerId}function Mi(n,t){var r,i;if(Rx(t)){const s=fe(t.anchor.blockId,t.anchor.childContainerId,(r=t.anchor)==null?void 0:r.custom),l=fe(t.focus.blockId,t.focus.childContainerId,(i=t.focus)==null?void 0:i.custom);return Ue(n,{anchor:s,focus:l})}const e=st(t.anchor.blockId,t.anchor.offset,"normal"),o=st(t.focus.blockId,t.focus.offset,"normal");return Ue(n,{anchor:e,focus:o})}const D4=S("range-from-point");function ih(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)continue;const s=i.getBoundingClientRect();if(i.clientWidth&&i.clientHeight&&r===0&&(s.left+i.clientWidth<t||s.top+i.clientHeight<e))return D4.debug("click on scrollbar, out of element rect"),null;if(!n.rootContainer.contains(i))continue;const l=et(i);if(!l||!n.contains(l))continue;const a=Qt(n,l).getRangeFromPoint(n,l,t,e+o[r]);if(a)return a}return null}function S4(n,t,e,o){const r=t.getBoundingClientRect();if(o<=r.top){const a=xe(t),d=Qt(n,a).getRangeFromPoint(n,a,e,a.getBoundingClientRect().top+4);if(d!=null&&d.isSimple())return Ye.from(n,d);const h=st(a,0,"home");return new Ye(n,{anchor:h,focus:h})}const i=Qe(t),s=Qt(n,i).getRangeFromPoint(n,i,e,i.getBoundingClientRect().bottom-4);if(s!=null&&s.isSimple())return Ye.from(n,s);const l=st(i,ut(n,i),"end");return new Ye(n,{anchor:l,focus:l})}function L4(n,t,e){const o=ih(n,t,e);if(o){if(o instanceof Ye)return o;g(D4,o instanceof rr,`invalid range type: ${typeof o}`);const a=o,d=n.getContainerById(a.start.childContainerId);return S4(n,d,t,e)}const r=document.elementsFromPoint(t,e)[0];if(!r)return null;const{children:i}=r,s=Array.from(i).filter(a=>Pr(a));if(s.length===0)return null;const l=s.reduce((a,d)=>{const h=a.getBoundingClientRect(),p=d.getBoundingClientRect();return nr(h,t,e)>nr(p,t,e)?d:a});return S4(n,l,t,e)}function Xm(n,t){const e=[];return pe(t).forEach(r=>{e.push(r),Mt(n,r)&&xn(n,r).forEach(s=>{e.push(...Xm(n,s))})}),e}function tg(n,t){let e=Xm(n,n.rootContainer);return t!=null&&t.simpleBlockOnly&&(e=e.filter(o=>!Mt(n,o))),e}function Ro(n,t){const e=n.selection.range.getSelectedBlocks(),o=[];for(const r of e)o.push(r),Mt(n,r.block)&&Rs(n,r.block,r.start,r.end).forEach(s=>{const a=Xm(n,s).map(d=>({block:d,start:st(d,0,"home"),end:st(d,ut(n,d),"home")}));o.push(...a)});return t!=null&&t.simpleBlockOnly?o.filter(r=>!Mt(n,r.block)):o}const unt="",Je=S("text-range");function Ox(n,t){const e=(i,s)=>{if(Hr(i))return g(Je,s===0,`invalid offset for insertion child: ${s}`),{child:i,container:i,offset:2};if(so(i))return g(Je,s===0||s===1,`invalid offset for box: ${s}`),{child:i,container:i,offset:s===0?1:2};const l=i.firstChild;return g(Je,l,"no child node for text child"),g(Je,l instanceof Text||l instanceof HTMLBRElement,`invalid child for text child, ${l.nodeName}`),l instanceof HTMLBRElement?(g(Je,s>=0&&s<=0,"invalid offset for text child"),{child:i,container:l,offset:s}):(g(Je,s>=0&&s<=l.data.length,"invalid offset for text child"),{child:i,container:l,offset:s})};let o=0;const r=or(n);for(let i=0;i<r.length;i++){const s=r[i],l=lo(s);if(t===o)return[e(s,0)];if(t<o+l)return[e(s,t-o)];if(t===o+l){const a=[];a.push(e(s,lo(s)));const d=r[i+1];return d&&a.push(e(d,0)),a}o+=l}g(Je,!1,"failed to get range info")}function _x(n,t,e){if(t===e?g(Je,Hr(n),"only insertion child can be zero offset"):g(Je,t<e,`invalid start & end: ${t}, ${e}`),Hr(n)){g(Je,t===e,`invalid insertion child range offset: ${t}, ${e}`),g(Je,t===0,`invalid insertion child range start: ${t}`);const i=n;return g(Je,i.children.length===3,`invalid insertion dom, children.length = ${i.children.length}`),$d(i,1,i,2)}if(so(n)){g(Je,t+1===e,`invalid box child range offset: ${t}, ${e}`),g(Je,t===0,`invalid box child range start: ${t}`);const i=n;return g(Je,i.children.length===3,`invalid box dom, children.length = ${i.children.length}`),$d(i,1,i,2)}const o=lo(n);g(Je,e<=o,`invalid child end: ${e}, ${o}`);const r=n.firstChild;return g(Je,r instanceof Text,"invalid block text child"),g(Je,r.data.length>=e,`invalid range end: ${e}, ${r.data.length}`),$d(r,t,r,e)}const Oo=S("caret-rect");function Fx(n,t){if(Fm(t)){const e=t,o=Nm(e);if(e.getAttribute("data-box-type")==="br"){const r=Lt(n),i=Number.parseFloat(window.getComputedStyle(r).lineHeight)||o.getBoundingClientRect().height,s=Array.from(o.getClientRects());g(Oo,s.length>0,"no box client rects");const l=r.getBoundingClientRect(),a=s[0],d=new DOMRect(l.left,a.bottom,1,i);return s.push(d),s}return o.getClientRects()}return $m(t).getClientRects()}function Vn(n,t){var l;const e=Ox(n,t.offset);if(e[1]&&e[0].child!==((l=e[1])==null?void 0:l.child)){if(t.type==="end"){const d=bs(e[0].child);return new DOMRect(d.right,d.top,1,d.height)}g(Oo,e[1],"invalid ranges");const a=Hd(e[1].child);return new DOMRect(a.left,a.top,1,a.height)}let r=e[0];if(g(Oo,e.length>=1,"failed to get block range"),e.length===1)r=e[0];else{if(g(Oo,e.length>=2,`invalid range info length: ${e.length}`),Hr(e[e.length-1].child)){r=e[e.length-1];const a=r.child,h=$m(a).getClientRects();g(Oo,h.length>=1,"no client rects for box content");const p=h[h.length-1];return new DOMRect(p.right,p.y,1,p.height)}t.type==="home"?r=e[1]:t.type==="end"||wa(e[0].child)?r=e[0]:wa(e[1].child)&&(r=e[1])}if(r.container instanceof HTMLBRElement){g(Oo,t.offset===0,"invalid offset for empty block text");const a=r.container.parentElement,d=a==null?void 0:a.parentElement;g(Oo,d===Lt(n)&&a,"invalid br parent, is not block parent");const h=a.getBoundingClientRect(),p=d.getBoundingClientRect();return new DOMRect(h.left,p.top,1,p.height)}const s=tC(r.container,r.offset).getClientRects();if(s.length===0){g(Oo,!wa(r.child),"only box or insertion child range has zero client rect"),g(Oo,r.offset===1||r.offset===2,"invalid offset for box or insertion child");const a=r.child,d=Fx(n,a);if(g(Oo,d.length>=1,"no client rects for box content"),r.offset===1){const p=d[0];return new DOMRect(p.x,p.y,1,p.height)}const h=d[d.length-1];return t.type==="end"||r.offset===2?new DOMRect(h.right,h.y,1,h.height):new DOMRect(h.x,h.y,1,h.height)}return g(Oo,s.length>0,"no client rects for range"),t.type==="home"?s[s.length-1]:s[0]}const Px=S("core");function zr(n,t,e,o){const r=te(t);let i=r.querySelector(`.block-anchor[data-id=${e}]`);i||(i=w("div",["block-anchor"],r),i.setAttribute("data-id",e));const s=o!=null?o:t.getBoundingClientRect(),l=t.getBoundingClientRect(),a=new DOMRect(s.left-l.left,s.top-l.top,s.width,s.height);return i.style.left=`${a.left}px`,i.style.top=`${a.top}px`,i.style.width=`${a.width}px`,i.style.height=`${a.height}px`,i}function M4(n,t,e,o){g(Px,tt(n,t),"not a text kind block");const r=Vn(t,st(t,e,"normal")),i=t.getBoundingClientRect(),s=te(t);let l=s.querySelector(`.block-anchor[data-id=${o}]`);l||(l=w("div",["block-anchor"],s),l.setAttribute("data-id",o));const a=new DOMRect(r.left-i.left,r.top-i.top,r.width,r.height);return l.style.left=`${a.left}px`,l.style.top=`${a.top}px`,l.style.width=`${a.width}px`,l.style.height=`${a.height}px`,l}function Ea(n){const t=or(n);let e=0;return t.forEach(o=>{e+=lo(o)}),e}const R4=S("box");function xa(n){return!n.attributes||!n.attributes.box?!1:(g(R4,n.attributes.box===!0,`invalid op attribute box property, ${n.attributes.box}`),g(R4,n.attributes.type,`no box type: ${JSON.stringify(n)}`),!0)}const O4=S("rich-text-length");function eg(n){return g(O4,typeof n.insert=="string","op.insert is not string"),n.insert.length}function rn(n){let t=0;return n.forEach(e=>{e.insert&&(g(O4,typeof e.insert=="string","op.insert is not string"),t+=eg(e))}),t}const ir=S("split-text");function In(n,t,e){if(n=mt.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];g(ir,typeof i=="object",`invalid op type, ${typeof i}`),g(ir,typeof i.insert=="string",`invalid op.insert type, ${typeof i.insert}`);const s=eg(i);if(o+s<t)o+=s;else{if(o+s===t)return{left:n.slice(0,r+1),right:n.slice(r+1)};{g(ir,o+s>t,`invalid offset, ${o}, ${s}, ${t}`);const l=t-o,a=mt.default(i);g(ir,a.insert,"no copied.insert"),g(ir,typeof a.insert=="string","invalid copied.insert type"),a.insert=a.insert.substr(0,l),i.insert=i.insert.substr(l),a.insert===""&&g(ir,!1,"invalid copied.insert, is empty string"),i.insert===""&&g(ir,!1,"invalid op.insert, is empty string");const d=[i,...n.slice(r+1)],h=[...n.splice(0,r),a];return e&&(e.sourceOp=i),{left:h,right:d}}}}throw new Error(`invalid split offset: ${t}, ${JSON.stringify(n)}`)}function ze(n,t,e){g(ir,t>=0,"invalid offset, < 0"),g(ir,e>0,"invalid length, <= 0"),g(ir,t+e<=rn(n),"invalid offset + length < text length");const{left:o,right:r}=In(n,t+e),{left:i,right:s}=In(o,t);return{left:i,middle:s,right:r}}function _4(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:a}=In(r,s);r=l,o.unshift(a)}return r.length>0&&o.unshift(r),o}function F4(n,t,e){return ze(n,t,e).middle}const Vl=S("text-block-content");function Nx(n,t,e,o,r){if(g(Vl,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=p=>n.editorInsertions.createInsertion(e,p),l=(p,A)=>{const v=r==null?void 0:r.get(A);v&&(v.forEach(B=>{p.appendChild(s(B))}),r==null||r.delete(A))},a=document.createDocumentFragment();let d=0;const h=_4(o,i);for(let p=0;p<h.length;p++){l(a,d);const A=h[p];d+=rn(A);for(let v=0;v<A.length;v++){const B=A[v];if(xa(B)){g(Vl,B.attributes,`op is not an valid box: ${JSON.stringify(B)}`);const x=n.editorBoxes.createBox(e,B.attributes);g(Vl,x instanceof HTMLSpanElement,`invalid box element: ${x.tagName}`),a.appendChild(x);continue}g(Vl,B.insert,`no insert in op: ${JSON.stringify(B)}`);const D=w("span",["text"],a,B.insert);if(B.attributes){const x=n.editorBlockRenders.renderText(t,B.attributes);x.classes&&W(D,...x.classes),x.attributes&&Object.entries(x.attributes).forEach(([_,M])=>{D.setAttribute(_,M)}),x.styles&&Object.entries(x.styles).forEach(([_,M])=>{D.style.setProperty(_,M)})}a.appendChild(D)}}l(a,d),e.innerHTML="",e.appendChild(a)}function sh(n,t,e,o,r){const{text:i,insertions:s}=n.editorDecorators.decorateText(t,r),l=n.compositingText;if(l){const a=n.selection.range.start;g(Vl,a.isSimple(),"not an simple position while compositing"),a.blockId===e&&s.set(a.offset,[{type:"inputting",id:K(),text:l}])}return Nx(n,t,o,i,s)}function $x(n){const t=n.rootContainer.querySelectorAll('span[data-type="editor-insertion"].inputting-insertion');t.length&&Vl.debug(`remove ${t.length} temp composition span`),Array.from(t).forEach(e=>e.remove())}const sr=S("client-rects");function Hx(n){const t=or(n);let e=0;const o=[];for(let r=0;r<t.length;r++){const i=t[r],s=lo(i);o.push({child:i,startBlockOffset:e,endBlockOffset:e+s}),e+=s}return o}function jx(n,t,e,o){g(sr,e<o,`invalid from & to: ${e}, ${o}`);const r=ut(n,t);g(sr,e>=0&&o>=0&&e<=r&&o<=r,`invalid offset: ${e}, ${o}, length: ${r}`);const i=Hx(t),s=i.findIndex(v=>v.startBlockOffset<=e&&e<v.endBlockOffset),l=i.findIndex(v=>v.startBlockOffset<o&&o<=v.endBlockOffset);if(g(sr,s!==-1,"failed to find start child"),g(sr,l!==-1,"failed to find end child"),g(sr,s<=l,`invalid start index & end index: ${s}, ${l}`),s===l){const v=i[s];return[{child:v.child,startChildOffset:e-v.startBlockOffset,endChildOffset:o-v.startBlockOffset}]}const a=[],d=i[s],h={child:d.child,startChildOffset:e-d.startBlockOffset,endChildOffset:lo(d.child)};a.push(h);for(let v=s+1;v<l;v++){const B=i[v],D={child:B.child,startChildOffset:0,endChildOffset:B.endBlockOffset-B.startBlockOffset};a.push(D)}const p=i[l],A={child:p.child,startChildOffset:0,endChildOffset:o-p.startBlockOffset};return a.push(A),a}function Ux(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 P4(n,t,e,o){if(ut(n,t)===0){const h=Lt(t).getBoundingClientRect();return[new DOMRect(h.left,h.top,4,h.height)]}const r=e.offset,i=o.offset;if(r===i)return[Vn(t,e)];const l=jx(n,t,r,i).map(d=>_x(d.child,d.startChildOffset,d.endChildOffset)),a=[];return l.forEach(d=>{const h=Ux(Array.from(d.getClientRects()));a.push(...h)}),a}function zx(n,t,e){g(sr,e instanceof Ye,"invalid range");const o=e.start,r=e.end;return g(sr,o.isSimple(),"text block only allow simple position"),g(sr,r.isSimple(),"text block only allow simple position"),g(sr,o.blockId===r.blockId,"only allow update one text block selection"),g(sr,o.blockId===it(t),"only allow update one text block selection"),P4(n,t,o,r)}const ng=S("selection-background");function Vx(n,t,e,o){g(ng,e.isSimple(),"text block only allow simple position"),g(ng,o.isSimple(),"text block only allow simple position"),g(ng,e.blockId===o.blockId,"only allow update one text block selection");const r=e.offset,i=o.offset;if(r===i&&(ut(n,t)!==0||n.selection.range.isCollapsed()))return;const s=P4(n,t,e,o),l=t.getBoundingClientRect(),a=ys(t),d=zC(t);d.innerHTML="",s.forEach(h=>{const p=w("div",["editor-selection-background"],d);p.style.left=`${(h.left-l.left-t.clientLeft)/a}px`,p.style.top=`${(h.top-l.top-t.clientTop)/a}px`,p.style.width=`${h.width/a}px`,p.style.height=`${h.height/a}px`})}function Wx(n){n.rootContainer.querySelectorAll("div[data-type=block-background]").forEach(t=>{t.remove()})}const Os=S("text-offset"),N4="\u200D";function _s(n,t){const e=or(n);let o=0;for(let r=0;r<e.length;r++){const i=e[r],s=lo(i);if(i===t){const l=o+s;return{start:o,end:l}}o+=s}g(Os,!1,"can not find child in children")}function sn(n,t){g(Os,t>=0,`invalid offset: ${t}`);const e=eh(n,t),{prev:o,next:r,offset:i}=e;if(!o&&!r&&g(Os,!1,"invalid offset, no prev & next child at offset"),o!==r)return!0;const s=o;if(g(Os,s,"no child"),so(s))return g(Os,i===0||i===1,`invalid box child offset: ${i}`),!0;const l=s.textContent;g(Os,l,"no content for text child");const a=l.charAt(i-1),d=l.charAt(i);return!(a===N4||d===N4||gm(l[i]))}function Ri(n,t){if(t===0)return 0;const e=t-1;if(sn(n,e))return e;let o=e-1;for(;!sn(n,o);)o-=1;return o}function Fs(n,t){const e=Ea(n);if(g(Os,t>=0&&t<=e,`invalid offset: ${t}, ${e}`),t===e)return e;const o=t+1;if(sn(n,o))return o;let r=o+1;for(;!sn(n,r);)r+=1;return r}const Ps=S("line-breaker");function Ia(n){const t=a=>{const d=Hd(a);return bs(a).top>d.top+d.height/2},e=(a,d)=>{const h=bs(a);return Hd(d).left<h.right},o=(a,d)=>{const h=bs(a),p=bs(d);return p.top+p.height/2>h.bottom},r=a=>{if(a.length===0||a.length===1)return!1;const d=a[0],h=a[a.length-1];return d.right-h.left>10},i=[];let s=0;const l=or(n);for(let a=0;a<l.length;a++){const d=l[a];if(Hr(d)){const x=d,_=l[a+1];if(!_)break;const M=l[a-1];if(M&&o(M,x)&&i.push({offset:s,type:"betweenChild",childInfo:{prevChild:M,nextChild:x,wrap:"nextWrapped",prevWrapped:t(M),nextWrapped:t(x)}}),e(x,_)){i.push({offset:s,type:"betweenChild",childInfo:{prevChild:M,nextChild:x,wrap:"nowrap",prevWrapped:t(M),nextWrapped:t(x)}});continue}continue}if(so(d)){const x=d,_=l[a+1];if(!_)break;const M=l[a-1];if(M&&o(M,x)&&i.push({offset:s,type:"betweenChild",childInfo:{prevChild:M,nextChild:x,wrap:"nextWrapped",prevWrapped:t(M),nextWrapped:t(x)}}),e(x,_)){s+=1,i.push({offset:s,type:"betweenChild",childInfo:{prevChild:M,nextChild:d,wrap:"nowrap",prevWrapped:t(M),nextWrapped:t(d)}});continue}s+=1;continue}const h=d,p=h.getClientRects();if(g(Ps,p.length>0,"invalid text child dom"),p.length===1){const x=l[a+1];if(!x)break;if(e(h,x)){s+=lo(h),i.push({offset:s,type:"betweenChild",childInfo:{prevChild:h,nextChild:x,wrap:"nowrap",prevWrapped:t(h),nextWrapped:t(x)}});continue}s+=lo(h);continue}const A=h.firstChild;g(Ps,A,"invalid text child, no text node"),g(Ps,A instanceof Text,`invalid text child, not a valid text node: ${typeof A}`);const v=document.createRange(),B=document.createRange(),D=lo(h);g(Ps,A.data.length===D,"text node data length not equal child text length");for(let x=0;x<A.data.length;x++){if(!sn(n,s+x))continue;v.setStart(A,x),Vd()&&v.selectNodeContents(A);const _=v.getClientRects();if(g(Ps,_.length>=1,"invalid text node, no client rects"),r(_)){const rt=s+x;i.push({offset:rt,type:"textBreakWord",childInfo:{prevChild:d,nextChild:d,wrap:"nowrap",prevWrapped:t(d),nextWrapped:t(d)}});continue}let M=x+1;sn(n,s+M)||(M=x+2),B.setStart(A,M);const H=B.getClientRects(),z=_[0];H[0].left<z.right&&g(Ps,!1,"span pre-wrap should not has a line-wrap by white space")}s+=D}return i}function og(n,t){const e=Ia(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 g(Ps,t.offset<=Ea(n),"invalid position, offset > block length"),{lineIndex:e.length,lineBreaks:e}}const qx=S("line-offset");function rg(n){const t=Ia(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:Ea(n)}),e}function lh(n,t){const e=rg(n);return g(qx,t>=0&&t<e.length,`invalid line index: ${t}, ${e.length}`),e[t]}function $4(n,t){const{lineIndex:e}=og(n,t);return lh(n,e)}function Gx(n){const t=rg(n),e=n.getBoundingClientRect(),o=[];return t.forEach(({start:r,end:i})=>{const s=st(n,r,"home");let l=Vn(n,s);const a=st(n,i,"end"),d=Vn(n,a);l.top+l.height/2<d.top&&(l=new DOMRect(e.left-1e4,d.top,1,d.height));const h=new DOMRect(l.left,d.top,d.left-l.left,d.height),p=new DOMRect(e.left,d.top,e.width,d.height);o.push({start:r,end:i,rect:p,contentRect:h})}),o}function Zx(n,t,e){const r=Gx(n).find(s=>ks(s.rect,t,e));if(!r)return null;const i=r.contentRect;return t-i.left<i.right-t?st(n,r.start,"home"):st(n,r.end,"end")}function H4(n,t,e){const o=Vn(n,t),r=Vn(n,e),i=o.top+o.height/2,s=r.top+r.height/2,l=r.top<i&&i<r.bottom,a=o.top<s&&s<o.bottom;return l&&a}function j4(n){return rg(n).length}const Ns=S("find-text-position");function U4(n,t){const{start:e,end:o}=lh(n,t),r=it(n),i=Vn(n,st(r,e,"home"));if(!(Vn(n,st(r,o,"end")).top>i.top+i.height/2))return!1;const a=eh(n,e);return g(Ns,a.next,"no next child at offset"),g(Ns,!wa(a.next),"next child is not text child"),!0}function Qx(n,t){const e=it(n);g(Ns,U4(n,t),"line is not wrapped");const{start:o,end:r}=lh(n,t),i=st(e,o,"home");for(let s=o+1;s<=r;s+=1){let l="normal";s===o?l="home":s===r&&(l="end");const a=st(e,s,l);if(!H4(n,i,a))return s-1}return g(Ns,!1,"failed to find wrapped offset"),0}function ch(n,t,e,o,r,i,s){g(Ns,tt(n,t),`not a text kind block: ${Dt(t)}`);const{start:l,end:a}=lh(t,e);let d=l;const h=it(t);if(t===o&&U4(t,e)){const x=Qx(t,e);(i==="up"||i==="down"&&H4(t,r,st(h,l,"home")))&&(d=x+1)}let p=Number.MAX_SAFE_INTEGER;const A=So(n,o,r),v=s!=null?s:A.left+A.width/2,B=A.top+A.height/2;let D=st(h,d,"home");for(let x=d;x<=a;x++){if(!sn(t,x))continue;let _="normal";x===l?_="home":x===a&&(_="end");const M=st(h,x,_),H=Vn(t,M),z=nr(H,v,B);z<p&&(p=z,D=M)}return D}function Yx(n,t,e,o,r){return g(Ns,tt(n,t),"not a text block"),ch(n,t,j4(t)-1,e,o,"up",r)}function Jx(n,t,e,o,r){return g(Ns,tt(n,t),"not a text block"),ch(n,t,0,e,o,"down",r)}function Kx(n,t,e,o){const{lineIndex:r}=og(t,e);if(r===j4(t)-1)return null;const i=ch(n,t,r+1,t,e,"down",o);return i||null}function Xx(n,t){if(t.offset===0)return null;const e=Ia(n),o=e.find(r=>r.offset===t.offset);if(!o){const r=Ri(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:Ri(n,t.offset),type:"normal"}}return{offset:Ri(n,t.offset),type:"normal"}}function tI(n,t){const e=Ea(n);if(t.offset===e)return null;const o=Ia(n),r=o.find(i=>i.offset===t.offset);if(!r){const i=Fs(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:Fs(n,t.offset),type:"home"}:{offset:Fs(n,t.offset),type:"normal"}}function eI(n,t,e,o){const{lineIndex:r}=og(t,e);if(r===0)return null;const i=ch(n,t,r-1,t,e,"up",o);return i||null}const nI=S("move-caret");function oI(n,t,e,o){if(o==="ArrowLeft"){const r=Xx(t,e);return r?st(it(t),r.offset,r.type):null}if(o==="ArrowRight"){const r=tI(t,e);return r?st(it(t),r.offset,r.type):null}if(o==="ArrowUp"){const r=eI(n,t,e,n.selection.getSuggestedCaretX());return r?st(it(t),r.offset,r.type):null}if(o==="ArrowDown"){const r=Kx(n,t,e,n.selection.getSuggestedCaretX());return r?st(it(t),r.offset,r.type):null}g(nI,!1,`invalid navigation direction: ${o}`)}const ig=S("text-range");function rI(n){const t=[];return or(n).forEach(o=>{const r=Array.from(o.getClientRects()).map(i=>({rect:i,child:o}));t.push(...r)}),t}function iI(n,t,e){const o=rI(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 _s(n,s.child).start}return null}function sI(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 _=t.getBoundingClientRect();if(!ks(_,e,o))return null;const M=iI(t,e,o);if(M!==null){const z=st(t,M,"normal");return new Ye(n,{anchor:z,focus:z})}const H=Zx(t,e,o);return H?new Ye(n,{anchor:H,focus:H}):null}const s=or(t);g(ig,s.indexOf(i)!==-1,"failed to find child in children");const l=_s(t,i);g(ig,l,"failed to get child offset");const{start:a}=l;let d,h;Hr(i)||so(i)?(d=a,h=0):(g(ig,i.firstChild instanceof Text,"child is not text"),d=a+eC(i.firstChild,e,o),h=0);const p=it(t),v=Ia(t).find(_=>_.offset===d);let B="normal";if(v){const _=st(p,d,"home"),M=st(p,d,"end"),H=Vn(t,_),z=Vn(t,M),q=nr(H,e,o),rt=nr(z,e,o);B=q<rt?"home":"end"}const D=st(p,d,B);let x;return h&&(x=st(p,d+h,B)),new Ye(n,{anchor:D,focus:x!=null?x:D})}const lI=S("create-text-op");function co(n,t){g(lI,n,"text is empty");const e={insert:n};return t&&Object.keys(t).length>0&&(e.attributes=t),e}function sg(n,t){if(n.length===0)return[];if(n.indexOf(`
|
|
15
|
+
animateScrollTo(scrollToElement:Element, options)`;e+=i.horizontalOffset,o+=i.verticalOffset;const p=h.getMaxHorizontalScroll(),A=h.getHorizontalScroll();e>p&&(e=p);const v=e-A,B=h.getMaxVerticalScroll(),D=h.getVerticalScroll();D<o?o-=window.innerHeight*3/4:o-=window.innerHeight*1/4,o>B&&(o=B);const x=o-D,_=Math.abs(Math.round(v/1e3*i.speed)),M=Math.abs(Math.round(x/1e3*i.speed));let H=_>M?_:M;return H<i.minDuration?H=i.minDuration:H>i.maxDuration&&(H=i.maxDuration),new Promise((z,q)=>{v===0&&x===0&&z(!0),Or.remove(h.element,!0);let rt;const ft=()=>{qe(),cancelAnimationFrame(rt),z(!1)};Or.add(h.element,ft);const Bt=Rn=>Rn.preventDefault(),jt=i.cancelOnUserAction?ft:Bt,Ut=i.cancelOnUserAction?{passive:!0}:{passive:!1},ne=["wheel","touchstart","keydown","mousedown"],qe=()=>{ne.forEach(Rn=>{h.element.removeEventListener(Rn,jt,Ut)})};ne.forEach(Rn=>{h.element.addEventListener(Rn,jt,Ut)});const Yn=Date.now(),$e=()=>{const Rn=Date.now()-Yn,wr=Rn/H,vn=Math.round(A+v*i.easing(wr)),an=Math.round(D+x*i.easing(wr));Rn<H&&(vn!==e||an!==o)?(h.scrollTo(vn,an),rt=requestAnimationFrame($e)):(h.scrollTo(e,o),cancelAnimationFrame(rt),qe(),Or.remove(h.element,!1),z(!0))};rt=requestAnimationFrame($e)})}function ks(n,t,e){return n.left<=t&&t<=n.right&&n.top<=e&&e<=n.bottom}function bE(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 sC(n){if(!/["'&<>]/.exec(n))return n;const o={'"':""","'":"'","&":"&","<":"<",">":">"};return n.split("").map(l=>o[l]||l).join("")}function lC(n){const t=document.getElementById(n);t&&t.remove()}function cC(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 ga(n){const t="custom-cursor-style";if(n){const e=`body * { cursor: ${n} !important}`;cC(e,t)}else lC(t)}const aC=3,uC=S("drag-drop");class dC{constructor(t){m(this,"dragStarted",!1);m(this,"mouseDownEvent",null);m(this,"_dragOffsetX",0);m(this,"_dragOffsetY",0);m(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()});m(this,"handleMouseMove",t=>{var i;t.preventDefault(),t.stopPropagation(),g(uC,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:aC;(Math.abs(e)>=r||Math.abs(o)>=r)&&this.onDragStart(this.mouseDownEvent)});m(this,"handleMouseUp",t=>{if(t.button===0){g(uC,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&&ga(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&&ga(null),this.dragStarted&&this.options.onDragEnd(this,t,this.options.elem,e,o),this.unbindEvents(),this.dragStarted=!1}destroy(){this.unbindEvents(),this.untrackEvents()}}function km(n){return new dC(n)}const vE=S("character");function hC(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 fC(n){const t=n.charAt(0);return t>="0"&&t<="9"}function mC(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 zd(n){const t=[[9,13],[32],[160]];return hC(n.charCodeAt(0),t)}function gC(n){const t=[[12352,12687],[13056,13183],[13312,15661],[19968,40959],[63744,64255],[44032,55215]];return hC(n.charCodeAt(0),t)}function wm(n,t){let e=t;return g(vE,e.length===1,"invalid char length"),e==="]"&&(e="\\]"),e==="\\"&&(e="\\\\"),n.replace(new RegExp(`^[${e}]+|[${e}]+$`,"g"),"")}const _r=navigator.userAgent;function pC(){const n=navigator.userAgent.toLowerCase();return n.indexOf("safari")!==-1&&!(n.indexOf("chrome")>-1)}function Vd(){return navigator.userAgent.toLowerCase().indexOf("firefox")>-1}const Ze={isAndroid:!!_r.match(/Android/i),isIOS:!!_r.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/i),isIPad:!!_r.match(/iPad/i),isIPhone:!!_r.match(/iPhone/i),isLinux:!!_r.match(/Linux/i),isMac:!!_r.match(/Macintosh/i),isMobile:!!_r.match(/AppleWebKit.*Mobile.*/i),isWindows:!!_r.match(/Window/i),isIe:!!_r.match(/msie|trident/i),isSafari:pC(),isFirefox:Vd(),isMobileSafari:!1};Ze.isMobileSafari=Ze.isMobile&&Ze.isSafari;function Bm(n){return n?n.length===1||n==="Process"||n==="Unidentified"&&Ze.isAndroid:!1}function CC(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 yE(n){return CC(n.key)}function kE(n){switch(n){case"ArrowUp":case"ArrowLeft":case"Home":case"PageUp":return!0;default:return!1}}function ws(n){return n.ctrlKey||n.altKey||n.shiftKey||n.metaKey}function wE(n){return n.key?!!(n.ctrlKey||n.metaKey||n.altKey):!1}function AC(n){return Ze.isMac?n.metaKey&&!n.ctrlKey:!n.metaKey&&n.ctrlKey}function BE(n){return AC(n)&&!n.altKey&&!n.shiftKey}function EE(n){return!n.metaKey&&!n.ctrlKey&&!n.shiftKey&&n.altKey}function bC(n){return!ws(n)&&n.key==="Enter"}function xE(n){return n.key==="Enter"&&n.shiftKey&&!n.altKey&&!n.ctrlKey&&!n.metaKey}function Em(n){return!ws(n)&&n.key==="Escape"}function IE(n){return!ws(n)&&n.key==="Delete"}function vC(n){return!ws(n)&&n.key==="Backspace"}function TE(n){return!ws(n)&&n.key==="Tab"}function DE(n){return n.shiftKey&&n.key==="Tab"&&!n.ctrlKey&&!n.metaKey}function xo(n){if(!n)return"";if(Ze.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 a,d;const s=(a=e[r])!=null?a:5,l=(d=e[i])!=null?d:5;return s-l}).map(r=>r in e?`${r}+`:r).join("")}return n.replace("CtrlOrCmd","Ctrl")}function yC(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"?Ze.isMac?t.cmd=!0:t.ctrl=!0:r==="SPACE"?t.key=" ":t.key=r.substring(0,1)+r.substring(1).toLocaleLowerCase()}return t}function or(n,t){const e=yC(t);return e.ctrl!==n.ctrlKey||e.alt!==n.altKey||e.shift!==n.shiftKey||Ze.isMac&&e.cmd!==n.metaKey?!1:e.key.length===1?e.key===n.key.toUpperCase():e.key.toUpperCase()===n.key.toUpperCase()}function xm(n,t){return bB.stringifyUrl({url:n,query:t})}function Si(n){return typeof n=="string"?ca.Base64.encode(n,!0):ca.Base64.fromUint8Array(n,!0)}function pa(n){return ca.Base64.decode(n)}function SE(n){return ca.Base64.toUint8Array(n)}function Im(n){return new Blob([ca.Base64.toUint8Array(n)])}const LE=Ti.init([Ti.classModule,Ti.styleModule,Ti.datasetModule,Ti.attributesModule,Ti.propsModule]);function Ca(n,t){const e=Ti.toVNode(n),o=Ti.toVNode(t);LE(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 jl(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 ME(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 ro(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||ME(e,"body"))&&(e=document.documentElement),e}function kC(n){n.preventDefault(),n.stopPropagation()}function wC(n){if(document.querySelector(`.editor-disable-scroll[data-scroll-id="${n}"]`))return;const t=w("div",["editor-disable-scroll"],null);t.setAttribute("data-scroll-id",n),t.addEventListener("wheel",kC,{passive:!1}),document.body.appendChild(t)}function BC(n){const t=document.querySelector(`.editor-disable-scroll[data-scroll-id="${n}"]`);t&&(t.removeEventListener("wheel",kC),t.remove())}function Dm(n,t,e){const o=new Blob([n]),r=new File([o],e,{type:t});return URL.createObjectURL(r)}function Wd(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 EC(n){const t=document.createElement("div");return t.appendChild(n),t.innerHTML}function xC(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 qd(n,t){const o=(qd.canvas||(qd.canvas=document.createElement("canvas"))).getContext("2d");return o?(typeof t=="string"?t?o.font=t:o.font=xC(window.getComputedStyle(document.body)):t instanceof Element&&(o.font=xC(window.getComputedStyle(t))),o.measureText(n).width+4):200}const RE=S("editor-clipboard");async function OE(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 Sm(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 RE.error(t),!1}}function Ul(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 Gd(n){return Array.isArray(n)?n.every(t=>t instanceof File):!1}function Aa(n){const t=n;if(!t)return"";const e=t.lastIndexOf(".");return e===-1?"":t.slice(e+1)}function Zd(n,t){const e=document.createElement("a");e.setAttribute("download",`${t||""}`),e.setAttribute("href",`${n}`),e.click(),e.remove()}const IC=S("auto-scroll");function TC(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 DC(n,{direction:t,step:e}){let o=null;const r=t==="left"||t==="right",i=()=>TC(n,t)?(r?t==="left"?n.scrollLeft=Math.max(n.scrollLeft-e,0):n.scrollLeft=Math.min(n.scrollLeft+e,n.scrollWidth):t==="top"?n.scrollTop=Math.max(n.scrollTop-e,0):n.scrollTop=Math.min(n.scrollTop+e,n.scrollHeight),o=requestAnimationFrame(i),o):(IC.debug("No need for scroll"),null);return o=requestAnimationFrame(i),()=>{o&&cancelAnimationFrame(o)}}class Qd{constructor(t){m(this,"cancelScroll",null);m(this,"options");m(this,"scrollDomInfo");m(this,"scrolling",!1);m(this,"getScrollingDirection",t=>{const{x:e,y:o}=t,{top:r,bottom:i,left:s,right:l}=this.scrollDomInfo,{edge:a}=this.options;return a.top&&o<=a.top+r?"top":a.bottom&&o>=i-a.bottom?"bottom":a.left&&e<=s+a.left?"left":a.right&&e>=l-a.right?"right":null});m(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;IC.debug(`scroll direction: ${i}`),this.cancelScroll=DC(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.getBoundingClientRect(),o=e.top,r=e.left,i=e.bottom,s=e.right;return{left:r,top:o,right:s,bottom:i}}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 SC(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 ba(n,t){let e=`${n}`;const o=t-e.length;for(let r=0;r<o;r++)e=`0${e}`;return e}const{t:Bs}=R;function Lm(n,t){const e=new Date(n).getTime()+864e5*t;return new Date(e)}function _E(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 FE(n,t){return Lm(n,t)}function Mm(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 LC(n){const t=new Date,e=new Date(n);return Mm(t,e)}function MC(n){const t=Lm(new Date,-1);return Mm(t,n)}function PE(n,t){return Math.round((n.getTime()-t.getTime())/864e5)}function Rm(n,t){const e=new Date(n);if(t){const o=e.getFullYear(),r=e.getMonth()+1,i=e.getDate(),s=e.getHours(),l=e.getMinutes();let a=t;return a=a.replace("YYYY",`${o}`),a=a.replace("MM",ba(r,2)),a=a.replace("DD",ba(i,2)),a=a.replace("M",`${r}`),a=a.replace("D",`${i}`),a=a.replace("hh",ba(s,2)),a=a.replace("mm",ba(l,2)),a=a.replace("h",`${s}`),a=a.replace("m",`${l}`),a}return n.toLocaleDateString()}function Om(n,t){const e=new Date(n),o=new Date;if(e.getTime()-o.getTime()>10*1e3)return R.t("date.dateFromFuture");if(LC(e)){const i=(o.getTime()-n.getTime())/1e3;if(i<10*60)return Bs("date.dateJustNow");if(i<60*60)return Bs("date.dateMinutesAgo",{num:`${Math.floor(i/60)}`});const s=Math.floor(i/60/60);return s===1?Bs("date.date1HourAgo"):Bs("date.dateHoursAgo",{num:`${s}`})}if(MC(n))return Bs("date.dateYesterday");const r=Math.floor((o.getTime()-n.getTime())/1e3/24/60/60)+1;return r<14?Bs("date.dateDaysAgo",{num:`${r}`}):r<28?Bs("date.dateWeeksAgo",{num:`${Math.round(r/7)}`}):Rm(n,t)}function _m(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function NE(n,t,e){return n.replace(new RegExp(_m(t),"g"),e)}function $E(n,t,e){return n.replace(new RegExp(_m(t),"gi"),e)}function RC(n,t,e){const r=document.createElement("canvas").getContext("2d");if(!r)return null;if(r.font=String(t),r.measureText(n).width>e){let s=0,l=0;for(;l<e;)l=r.measureText(n.slice(0,s)).width,s++;return`${n.slice(0,s-2)}...`}return n}const OC=/[\u3040-\u30ff\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff\uff66-\uff9f\uAC00-\uD7AF]/,_C=" -\x7F0-9!-/:-@[-`{-~\u0370-\u03FF\u0400-\u04FF",HE=new RegExp(`[${_C}]`),jE=new RegExp(`([^(${_C})])`,"g"),FC=/(\ud83c[\udf00-\udfff])|(\ud83d[\udc00-\ude4f\ude80-\udeff])|[\u2600-\u2B55]/;function PC(n){return n.length===0?0:n.split("").reduce((t,e)=>{const o=(t<<5)-t+e.charCodeAt(0);return o&o},0)}function UE(n,t=1){var o,r;return(r=((o=Array.from(n))==null?void 0:o.filter(i=>OC.test(i))).slice(-t))==null?void 0:r.join("")}function zE(n,t=1){var r;const e=Array.from((r=n==null?void 0:n.replace(jE,""))==null?void 0:r.split(/\s/));return e.reduce((i,s,l)=>{var a,d;return l===e.length-1&&i.length<t?`${i}${(a=s==null?void 0:s.slice(0,t-i.length))!=null?a:""}`:`${i}${(d=s[0])!=null?d:""}`},"").slice(0,t)}function VE(n,t=1){var o,r;return(r=((o=Array.from(n))==null?void 0:o.filter(i=>FC.test(i))).slice(-t))==null?void 0:r.join("")}function WE(n,t=1){var e,o;return(o=(e=Array.from(n))==null?void 0:e.slice(0,t))==null?void 0:o.join("")}function Yd(n,t=1){if(!n||n.length===0)return"";const e=OC.test(n),o=HE.test(n),r=FC.test(n);switch(!0){case e:return UE(n,t);case o:return zE(n,t);case r:return VE(n,t);default:return WE(n,t)}}var NC=(n=>(n.blue="#338FE5",n.cyan="#34AFDE",n.teal="#2CB2AE",n.green="#24B47E",n.kelly="#8AAB3F",n.yellow="#F0A100",n.orange="#EB6414",n.red="#E52727",n.fuchsia="#BE507D",n.purple="#9678D3",n))(NC||{});function Jd(n){const t=Object.values(NC),e=Math.abs(typeof n=="string"&&n.trim()?PC(n.trim()):0)%t.length;return t[e]}const $C=S("container-children");function pe(n){const t=Array.from(n.querySelectorAll(":scope > .container-blocks > div[data-type=editor-block]"));return g($C,t.length>0,"container have not any child block"),t}function xe(n){const t=n.querySelector(":scope > .container-blocks > div[data-type=editor-block]");return g($C,t,"container have not any child block"),t}function Qe(n){const t=pe(n);return t[t.length-1]}function Io(n){return pe(n).length}function Fr(n,t){return pe(n)[t]}const To=S("block-dom");function Es(n){return n instanceof HTMLDivElement?n.getAttribute("data-type")==="editor-block":!1}function HC(n){return n instanceof HTMLElement&&n.getAttribute("data-type")==="block-tools"}function jC(n){W(n,"block-hidden")}function UC(n){ot(n,"block-hidden")}function Kd(n){return!xt(n,"block-hidden")}function it(n){const{id:t}=n;return g(To,t,"no block id"),t}function Dt(n){const t=n.getAttribute("data-block-type");return g(To,t,"invalid block dom, no data-type"),t}function et(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 xs(n){const t=n instanceof Element?n:n.parentElement;if(!t)return null;const e=t.closest("div[data-type=editor-block]:not(:scope)");return e||null}function nt(n){const t=n.closest("div[data-type=editor-container]");return g(To,t,"failed to get block container"),t}function Lt(n){const t=n.querySelector(":scope >div[data-type=block-content]");return g(To,t,"no block content"),t}function te(n){let t=n.querySelector(":scope >div[data-type=block-tools]");return t||(t=w("div",[],n),t.setAttribute("data-type","block-tools")),g(To,t,"no block tools"),t}function Xd(n){const t=n.querySelector(":scope >div[data-type=block-tools]");return t||null}function zC(n){let t=n.querySelector(":scope > div[data-type=block-background]");return t||(t=w("div",[],n),t.setAttribute("data-type","block-background")),t}function VC(n,t,e){const o=n.editorDecorators.decorateBlock(t,e),{id:r,type:i}=o;g(To,r,"no block id");const s=w("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&&W(s,...l.classes),l.attributes&&Object.entries(l.attributes).forEach(([a,d])=>{s.setAttribute(a,d)}),l.styles&&Object.entries(l.styles).forEach(([a,d])=>{s.style.setProperty(a,d)}),s}function Is(n,t){const e=w(t,[],null);return e.setAttribute("data-type","block-content"),n&&n.appendChild(e),e}function WC(n){const t=w("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 va(n){const t=n.getAttribute("data-box-type");return g(To,t,"not a valid box element, no type"),t}function Fm(n){return n instanceof HTMLSpanElement?n.getAttribute("data-type")==="editor-box":!1}function qC(n){const{id:t}=n;return g(To,t,"no box id"),t}function Pm(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 GC(n){n.innerHTML="",w("span",["box-space-start"],n,fa);const t=w("span",[],n);return t.setAttribute("data-type","box-content"),w("span",["box-space-start"],n,fa),t}function Nm(n){const t=n.querySelector("span[data-type=box-content]");return g(To,t,"invalid box dom, no content"),t}function ZC(n,t){const e=w("span",[`${n}-insertion`],null);return e.setAttribute("data-type","editor-insertion"),e.setAttribute("data-insertion-id",t),e}function QC(n,t){return n.rootContainer.querySelector(`[data-insertion-id=${t}]`)}function YC(n){n.innerHTML="",w("span",["insertion-space-start"],n,fa);const t=w("span",[],n);return t.setAttribute("data-type","insertion-content"),w("span",["insertion-space-start"],n,fa),t}function $m(n){const t=n.querySelector("span[data-type=insertion-content]");return g(To,t,"invalid insertion-child dom, no content"),t}function ce(n){let t=n.previousElementSibling;for(;t;){if(Es(t))return t;t=t.nextElementSibling}return null}function Zt(n){let t=n.nextElementSibling;for(;t;){if(Es(t))return t;t=t.nextElementSibling}return null}function Ts(n){let t=n.previousElementSibling;for(;t;){if(Es(t)&&Kd(t))return t;t=t.previousElementSibling}return null}function Ds(n){let t=n.nextElementSibling;for(;t;){if(Es(t)&&Kd(t))return t;t=t.nextElementSibling}return null}function bt(n){const t=nt(n),o=pe(t).indexOf(n);return g(To,o!==-1,"invalid block & container dom, failed to get block index"),o}function Hm(n){return!n||!(n instanceof Node)?!1:!!et(n)}function Ss(n){if(!Hm(n))return!1;const t=n,e=t instanceof Element?t:t.parentElement;return e?!!e.closest("div[data-type=block-tools]"):!1}const JC=S("block-class");function Qt(n,t){return n.editorBlocks.getBlockClass(Dt(t))}function KC(n,t){const e=n.editorBlocks.getBlockClass(Dt(t));return g(JC,e.blockKind==="text",`is not a text block, ${e.blockType}`),e}function zn(n,t){const e=n.editorBlocks.getBlockClass(Dt(t));return g(JC,e.blockKind==="complex",`is not a text block, ${e.blockType}`),e}function Ls(n,t){return n.editorBlocks.getBlockClass(t)}function tt(n,t){return Qt(n,t).blockKind==="text"}function ya(n,t){return n.editorBlocks.getBlockClass(t).blockKind==="text"}function Mt(n,t){return Qt(n,t).blockKind==="complex"}function qE(n,t){return!Mt(n,t)}function Do(n,t){return Qt(n,t).blockKind}function So(n,t,e){return Qt(n,t).getCaretRect(t,e)}const XC=S("container");function Pr(n){return n.getAttribute("data-type")==="editor-container"}function Yt(n){return xt(n,"root")}function Lo(n){return xt(n,"child")}function at(n){const t=n.getAttribute("data-container-id");return g(XC,t,"no id for container"),Yt(n)&&g(XC,t==="root",`invalid root container id, : ${t}`),t}function t4(n,t){const e=at(n);return t.getContainerBlocks(e)}const jm=S("block");function ut(n,t){return Qt(n,t).getBlockTextLength(t)}function e4(n){n.editorBlocks.forEach(t=>{t.clearSelection(n)})}function n4(n,t,e,o){Qt(n,t).updateSelection(n,t,e,o)}function Um(n){for(;;){const t=nt(n);if(Yt(t))return n;const e=et(t);g(jm,e,"no parent block exists for child container"),n=e}}function o4(n,t){const e=Qt(n,t);if(!!e.getMinWidth)return e.getMinWidth(n,t)}function r4(n,t,e){const o=Qt(n,t);o.handleBlockElementUpdated&&o.handleBlockElementUpdated(n,t,e)}function th(n,t,e,o){try{const r=Ls(n,e).convertFrom;return r?r(n,t,o):null}catch{return jm.debug(`unsupported block type: ${e}`),null}}function Nr(n,t,e){const o=Qt(n,t);return o.getClientRects?o.getClientRects(n,t,e):[t.getBoundingClientRect()]}function GE(n,t){const e=Qt(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;g(jm,s==="string"||s==="number"||s==="boolean","invalid style value")}),r}function he(n,t){return Do(n,t)==="text"?ut(n,t)===0:!1}const i4=S("block-path");function Li(n){const t=[];let e=n;for(;e;){const o=nt(e);if(t.unshift({containerId:at(o),blockIndex:bt(e)}),Yt(o))return t;const r=et(o);g(i4,r,"no parent block"),e=r}return g(i4,!1,"no parent block"),[]}function ZE(n,t){var r,i;const e=Qt(n,t);return(i=(r=e.getOptions)==null?void 0:r.call(e,n))!=null?i:{name:Dt(t)}}function io(n){return Yt(nt(n))}function s4(n,t){var r;const e=Qt(n,t);return(r=e.getBlockProperties)==null?void 0:r.call(e,n,t)}function zm(n,t){var i,s;const e=Qt(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 a=(s=l.commands)==null?void 0:s.call(l,n,t);a&&(r[a.group]=a)}return r}function QE(n,t,e){var s,l,a,d;const o=Qt(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 h of n.blockHooks){const p=(l=h.commands)==null?void 0:l.call(h,n,t);p&&(i[p.group]=p)}return(d=(a=i[e])==null?void 0:a.commands)!=null?d:[]}function l4(n,t,e){let o=t;for(;o;){const r=QE(n,o,e);if(r.length>0)return{element:Lt(o),commands:r};if(io(o))break;o=xs(o)}return{element:null,commands:[]}}const c4=S("embed-block-common");function Me(n){return Dt(n)==="embed"}function fn(n){g(c4,Me(n),"not an embed block");const t=n.getAttribute("data-embed-type");return g(c4,t,"no embed data type"),t}function YE(n,t){return n.editorEmbeds.getEmbedClass(fn(t))}function Ms(n,t){return n.editorEmbeds.getEmbedClass(t)}async function Vm(n,t,e,o,r){const i=Ms(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 JE(n,t,e,o,r){var l,a;const i=(a=(l=Ls(n,t)).getOptions)==null?void 0:a.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 KE=S("execute-block-command");function a4(n,t,e,o){var d;g(KE,Me(t),"not a embed block");const r=fn(t),i=Ms(n,r);if(!i.getOptions)return;const s=(d=i.getBlockProperties)==null?void 0:d.call(i,n,t),l=s==null?void 0:s.blockCommands;if(!l)return;const a=Object.entries(l);for(const h of a)if(h[0]===e)return h[1].executeCommand(n,t,o)}function u4(n,t,e,o){const r=zm(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 $r=S("text-block-child");function ka(n){return n.tagName==="SPAN"}function so(n){return g($r,ka(n),"not a valid text child"),n.getAttribute("data-type")==="editor-box"}function Hr(n){return g($r,ka(n),"not a valid text child"),n.getAttribute("data-type")==="editor-insertion"}function wa(n){return!so(n)&&!Hr(n)}function d4(n){return g($r,ka(n),"not a valid text child"),so(n)?"box":Hr(n)?"insertion":"text"}function lo(n){const t=d4(n);return t==="insertion"?0:t==="box"?1:(g($r,n.textContent!==null,"text block content is undefined"),g($r,n.textContent.length>=0,"text block content length is negative"),n.textContent.length)}function rr(n){const t=Lt(n),e=Array.from(t.children);return e.forEach(o=>{g($r,ka(o),"not a valid text child")}),e}function eh(n,t){const e=rr(n);let o=0;for(let r=0;r<e.length;r++){const i=e[r],s=lo(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 g($r,l>0,"invalid offset value"),g($r,!so(i),"invalid box child"),{prev:i,next:i,offset:l}}g($r,!1,`invalid block child at position: ${t}`)}const h4=S("element");function Wm(n,t,e){const o=w("div",[t],n);return o.setAttribute("data-type","editor-container"),o.setAttribute("data-container-id",e),w("div",["container-blocks"],o),o}function jr(n,t){const e=n.rootElement.querySelector(`[data-container-id=${t}`);return g(h4,e,`no container: ${t}`),e}function f4(n,t){return n.rootElement.querySelector(`[data-container-id=${t}`)}function nh(n){const t=n.querySelector(":scope > .container-blocks");return g(h4,t,"no container blocks element"),t}function XE(n){let t=n.querySelector(":scope > .container-tools");return t||(t=w("div",["container-tools"],n)),t}const tx=S("child-container-path");function m4(n){if(Yt(n))return[];const t=et(n);return g(tx,t,"no parent block"),Li(t)}const g4=S("load-blocks");function qm(n,t,e){const o=at(t),r=t4(t,n.doc);g(g4,r.length>0,"no blocks in container");const i=document.createDocumentFragment();r.forEach((l,a)=>{const d=n.editorBlocks.createBlock([...e,{containerId:o,blockIndex:a}],t,l);i.appendChild(d)}),nh(t).appendChild(i)}function ex(n,t,e){const o=nh(n);if(t===0)return o.insertBefore(e,o.firstChild),e;const r=pe(n);return g(g4,t>=0&&t<=r.length,"invalid block index"),t===r.length?o.appendChild(e):o.insertBefore(e,r[t]),e}function nx(n,t,e,o){const r=m4(t);r.push({containerId:at(t),blockIndex:e});const i=n.editorBlocks.createBlock(r,t,o);return ex(t,e,i),i}const p4=S("root-container");class ox{constructor(t,e){m(this,"resizeObserver");m(this,"handleContextMenu",t=>{});m(this,"handleResize",()=>{try{this.editor.selection.updateSelection(null),this.editor.emit("resize",this.editor)}catch(t){p4.warn(`failed to update selection while container resizing: ${t.message}`)}});m(this,"handleClick",t=>{this.editor.emit("click",this.editor,t);const e=t.target;if(!Ss(e)&&(t.detail===1&&this.editor.input.focus(),t.detail===3&&this.editor.selectionHandler.handleTripleClick(t),t.detail===1&&t.button===0)){const o=document.elementFromPoint(t.clientX,t.clientY);if(o&&Xt(this.rootContainer,o)){const r=et(o);r&&Xt(r,o)&&this.handleBlockClick(t,r,o)}}});m(this,"handleBlockClick",(t,e,o)=>{var s,l;if(!tt(this.editor,e))return;const r=Pm(o);if(r){const a=et(r);g(p4,a,"no parent block"),(l=(s=this.editor.editorBoxes.getBoxClass(va(r)))==null?void 0:s.handleClickBox)==null||l.call(s,this.editor,r,t);return}const i=o.closest("span.text.link");i&&rr(e).indexOf(i)!==-1&&this.editor.emit("clickLink",this.editor,t,i)});m(this,"handleDblClick",t=>{Ss(t.target)||this.editor.selectionHandler.handleDblClick(t)});m(this,"handleMouseDown",t=>{const e=t.target;if(!!e&&e instanceof Node&&!Ss(e)){if(e instanceof HTMLElement&&e.draggable){this.editor.selectionHandler.handleMouseDown(t,{autoScroll:!1}),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,{autoScroll:!0})),Ze.isMobileSafari||(t.preventDefault(),this.editor.input.focus()),t.button===2&&t.stopPropagation()}});m(this,"handleMouseMove",t=>{this.editor.selectionHandler.handleMouseMove(t)});m(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=nh(this.rootContainer);e.innerHTML="",qm(this.editor,this.rootContainer,[]);const o=this.editor.findBlockById(t.start.blockId);if(o)this.editor.selection.selectBlock(o,0);else{const r=xe(this.rootContainer);this.editor.selection.selectBlock(r,0)}}}function C4(n){const t=Wm(n.contentElement,"root","root");return n.rootContainer=t,qm(n,t,[]),new ox(n,t)}function A4(n,t,e,o){const r=f4(n,o);if(r)return e.appendChild(r),setTimeout(()=>{n.emit("containerRemount",n,o)}),r;const i=Wm(e,"child",o);return qm(n,i,t),i}function b4(n,t){const e=n.getBoundingClientRect().width;return t.withPadding?e:e-Cm(n)}function Gm(n,t){let e=Number.MAX_SAFE_INTEGER;const o=pe(t);for(let i=0;i<o.length;i++){const s=o[i],l=o4(n,s);l&&(e=Math.min(e,l))}return e===Number.MAX_SAFE_INTEGER?void 0:e+Cm(t)}function Ba(n,t){const e=pe(t);return e.length!==1?!1:he(n,e[0])}const rx=S("complex-block-position");class Mo{constructor(t,e,o){m(this,"blockId");m(this,"childContainerId");m(this,"custom");t instanceof HTMLElement?this.blockId=it(t):(g(rx,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 ix=S("simple-block-position");class je{constructor(t,e,o){m(this,"blockId");m(this,"offset");m(this,"type");t instanceof HTMLElement?this.blockId=it(t):(g(ix,typeof t=="string",`not a valid block id: ${t}`),this.blockId=t),this.offset=e,this.type=o}isSimple(){return!0}}const Zm=S("editor-position");function st(n,t,e){return new je(n,t,e)}function fe(n,t,e){return new Mo(n,t,e)}function Ur(n){return n instanceof je}function Qm(n){return n instanceof Mo}function Ym(n,t,e){if(Ur(t)&&Ur(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 g(Zm,i!==s,"comparePosition: blocks are the same"),jd(i,s)}if(Qm(t)&&Qm(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 g(Zm,i!==s,"comparePosition: containers are the same"),jd(i,s)}return g(Zm,!1,"invalid "),0}const oh=S("simple-range");class Ye{constructor(t,e){m(this,"editor");m(this,"_anchor");m(this,"_focus");m(this,"reverse");this.editor=t,this._anchor=e.anchor,this._focus=e.focus,this.reverse=Ym(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 Ye))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);g(oh,e,"no start block"),g(oh,o,"no end block");const r=nt(e),i=nt(o);g(oh,r===i,"invalid range");const s=[];if(e===o)s.push({block:e,start:this.start,end:this.end});else{const l=bt(e),a=bt(o);g(oh,l<a,"invalid range, start > index"),s.push({block:e,start:this.start,end:st(e,ut(this.editor,e),"end")});const d=pe(r);for(let h=l+1;h<a;h+=1){const p=d[h];s.push({block:p,start:st(p,0,"home"),end:st(p,ut(this.editor,p),"end")})}s.push({block:o,start:st(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 Ye(this.editor,this)}toDocRange(){return{anchor:this.anchor,focus:this.focus}}static from(t,e){return new Ye(t,e)}}S("unknown-block");function sx(n,t,e,o,r){W(o,"unknown-block");const i=Is(o,"div");return i.innerText=`unknown block (${r.type}): ${JSON.stringify(r)}`,i}function lx(n){return 1}function cx(n,t,e,o){return null}function ax(n,t,e,o){const r=document.elementsFromPoint(e,o)[0];if(!r||!t.contains(r)||!n.contains(t))return null;const i=it(t),s=st(i,0,"home"),l=st(i,1,"end");return new Ye(n,{anchor:s,focus:l})}function ux(n,t){const o=Lt(n).getBoundingClientRect();return new DOMRect(o.left+o.width/2,o.top,1,o.height)}function dx(n,t,e,o){W(t,"selected")}function hx(n){n.rootContainer.querySelectorAll("div.unknown-block[data-type=editor-block]").forEach(t=>{ot(t,"selected")})}function fx(n,t,e,o){return`[unknown block, ${t.type}]`}const mx={blockType:"unknown-block",blockKind:"embed",createBlockContent:sx,getBlockTextLength:lx,getRangeFromPoint:ax,moveCaret:cx,getCaretRect:ux,updateSelection:dx,clearSelection:hx,convertTo:fx},Jm=S("editor-blocks");class v4{constructor(t){m(this,"blocks",new Map);this.editor=t}registerBlockClass(t){const e=t.blockType,o=this.blocks.get(e);g(Jm,!o,`duplicated block type: ${e}`),this.blocks.set(e,t)}getBlockClass(t){const e=this.blocks.get(t);return g(Jm,e,`unknown block type: ${t}`),e}hasBlock(t){return this.blocks.has(t)}createBlock(t,e,o){const r=VC(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&&(Jm.warn("content parent is not block"),r.appendChild(s)),this.editor.blockHooks.forEach(l=>{var a;(a=l.create)==null||a.call(l,this.editor,t,e,r,o)}),r}forEach(t){this.blocks.forEach(t)}registerUnknownBlock(t){const e={...mx,blockType:t};return this.editor.editorBlocks.registerBlockClass(e),e}}const y4=S("editor-embeds");class k4{constructor(t){m(this,"objects",new Map);this.editor=t}registerEmbedClass(t){const e=t.embedType,o=this.objects.get(e);g(y4,!o,`duplicated embed object type: ${e}`),this.objects.set(e,t)}getEmbedClass(t){const e=this.objects.get(t);return g(y4,e,`unknown embed type: ${t}`),e}getEmbedClassFromBlock(t){return this.getEmbedClass(fn(t))}forEach(t){this.objects.forEach(t)}}const w4=S("embed-block");function gx(n,t,e,o,r){const i=Is(o,"div");g(w4,r.type==="embed",`not an embed data: ${JSON.stringify(r)}`);const s=r;return g(w4,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 px(n){return 1}function Cx(n,t,e,o){return null}function Ax(n,t,e,o){const r=document.elementsFromPoint(e,o)[0];if(!r||!t.contains(r)||!n.contains(t))return null;const i=it(t),s=st(i,0,"home"),l=st(i,1,"end");return new Ye(n,{anchor:s,focus:l})}function bx(n,t){const o=Lt(n).getBoundingClientRect();return new DOMRect(o.left+o.width/2,o.top,1,o.height)}function vx(n,t,e,o){W(t,"selected")}function yx(n){n.rootContainer.querySelectorAll("div.embed-block[data-type=editor-block][data-block-type=embed]").forEach(t=>{ot(t,"selected")})}function kx(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 wx(n,t,e,o){const r=Ms(n,t.embedType);return r.convertTo?r.convertTo(n,t,e,o):""}function Bx(n,t){const e=YE(n,t);return e.getBlockProperties?e.getBlockProperties(n,t):{}}function Ex(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 xx(n,t,e,o){const r=fn(t),i=Ms(n,r);!i.handleDeleteBlock||i.handleDeleteBlock(n,t,e,o)}function Ix(n,t,e){const o=fn(t),r=Ms(n,o);return r.handleUpdateBlock?r.handleUpdateBlock(n,t,e):!1}function Tx(n,t,e,o,r){const i=fn(t),s=Ms(n,i);if(s.handleDropOver)return s.handleDropOver(n,t,e,o,r)}function Dx(n,t,e,o,r){const i=fn(t),s=Ms(n,i);if(s.handleDrop&&n.isWritable())return s.handleDrop(n,t,e,o,r)}async function Sx(n,t,e){const o=t.embedType,r=n.editorEmbeds.getEmbedClass(o);if(r.toStandardDoc){const i=n.getBlockById(t.id),s=Li(i);return r.toStandardDoc(n,t,e,s)}}const B4={blockType:"embed",blockKind:"embed",createBlockContent:gx,getBlockTextLength:px,getRangeFromPoint:Ax,moveCaret:Cx,getCaretRect:bx,updateSelection:vx,clearSelection:yx,convertFrom:kx,convertTo:wx,getBlockProperties:Bx,getOptions:Ex,handleDeleteBlock:xx,handleUpdateBlock:Ix,handleDropOver:Tx,handleDrop:Dx,toStandardDoc:Sx},mn=S("complex-block-helper");function xn(n,t,e){return zn(n,t).getChildContainers(n,t,e)}function Rs(n,t,e,o){return e.isSimple()?(g(mn,o.isSimple(),"invalid start and end position"),xn(n,t)):(g(mn,!e.isSimple(),"invalid start pos"),g(mn,!o.isSimple(),"invalid end pos"),zn(n,t).getSelectedContainers(n,t,e,o))}function Lx(n,t){if(bt(t)!==0)return!1;const e=et(nt(t));if(!e)return!1;g(mn,Mt(n,e),"not a complex block");const o=nt(t),i=xn(n,e).indexOf(o);return g(mn,i>=0,"not valid child container"),i===0}function Km(n,t,e){const o=xn(n,t,e);if(o.length===0)return null;const r=o[0];if(!r)return null;const i=xe(r);return Mt(n,i)?Km(n,i,e):i}function zl(n,t,e){const o=xn(n,t,e);if(o.length===0)return null;const r=o[o.length-1];if(!r)return null;const i=Qe(r);return Mt(n,i)?zl(n,i,e):i}function E4(n,t){g(mn,Lo(t),"not a child container");const e=et(t);g(mn,e,"no parent block"),g(mn,Mt(n,e),"not a complex block");const o=xn(n,e),r=o.indexOf(t);if(g(mn,r!==-1,"child container not found"),r===0){const l=ce(e);return l?Mt(n,l)?zl(n,l):l:null}const i=o[r-1],s=Qe(i);return Mt(n,s)?zl(n,s):s}function x4(n,t){g(mn,Mt(n,t),"not a complex block");const e=xn(n,t);if(g(mn,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 a=1;a<e.length;a++){const d=e[a],h=d.getBoundingClientRect();if(h.right<=i){l.push(d),i=h.left;continue}if(h.left>=s){s=h.right;continue}}return l}function I4(n,t){g(mn,Mt(n,t),"not a complex block");const e=xn(n,t);if(g(mn,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 a=e.length-2;a>=0;a--){const d=e[a],h=d.getBoundingClientRect();if(h.right<=i){l.push(d),i=h.left;continue}if(h.left>=s){s=h.right;continue}}return l}function T4(n,t,e,o){const r=t.getBoundingClientRect(),i=o<r.top,s=i?x4(n,t):I4(n,t);let l=s[0],a=nr(l.getBoundingClientRect(),e,o);for(let d=1;d<s.length;d++){const h=s[d],p=h.getBoundingClientRect(),A=nr(p,e,o);A<a&&(l=h,a=A)}return i?xe(l):Qe(l)}function rh(n,t,e,o){const r=it(t);g(mn,r===e.blockId,"invalid start pos"),g(mn,r===o.blockId,"invalid end pos");const i=zn(n,t);return i.adjustSelectionPos?i.adjustSelectionPos(n,t,e,o):{anchor:e,focus:o}}class ir{constructor(t,e){m(this,"editor");m(this,"reverse");m(this,"_anchor");m(this,"_focus");this.editor=t,this._anchor=e.anchor,this._focus=e.focus,this.reverse=Ym(this.editor,this._anchor,this._focus)>0}isCollapsed(){return!1}isEqual(t){if(!(t instanceof ir))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 Rs(this.editor,t,this.start,this.end)}clone(){return new ir(this.editor,this)}toDocRange(){return{anchor:this._anchor,focus:this._focus}}}const Mx=S("selection-range");function Ue(n,t){const{anchor:e,focus:o}=t;return e instanceof je&&o instanceof je?new Ye(n,{anchor:e,focus:o}):(g(Mx,e instanceof Mo&&o instanceof Mo,"start position type does not math end type"),new ir(n,{anchor:e,focus:o}))}function Ce(n,t,e,o){const r=new je(t,e,"normal"),i=new je(t,o!=null?o:e,"normal");return Ue(n,{anchor:r,focus:i})}function Rx(n){return!!n.anchor.childContainerId}function Mi(n,t){var r,i;if(Rx(t)){const s=fe(t.anchor.blockId,t.anchor.childContainerId,(r=t.anchor)==null?void 0:r.custom),l=fe(t.focus.blockId,t.focus.childContainerId,(i=t.focus)==null?void 0:i.custom);return Ue(n,{anchor:s,focus:l})}const e=st(t.anchor.blockId,t.anchor.offset,"normal"),o=st(t.focus.blockId,t.focus.offset,"normal");return Ue(n,{anchor:e,focus:o})}const D4=S("range-from-point");function ih(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)continue;const s=i.getBoundingClientRect();if(i.clientWidth&&i.clientHeight&&r===0&&(s.left+i.clientWidth<t||s.top+i.clientHeight<e))return D4.debug("click on scrollbar, out of element rect"),null;if(!n.rootContainer.contains(i))continue;const l=et(i);if(!l||!n.contains(l))continue;const a=Qt(n,l).getRangeFromPoint(n,l,t,e+o[r]);if(a)return a}return null}function S4(n,t,e,o){const r=t.getBoundingClientRect();if(o<=r.top){const a=xe(t),d=Qt(n,a).getRangeFromPoint(n,a,e,a.getBoundingClientRect().top+4);if(d!=null&&d.isSimple())return Ye.from(n,d);const h=st(a,0,"home");return new Ye(n,{anchor:h,focus:h})}const i=Qe(t),s=Qt(n,i).getRangeFromPoint(n,i,e,i.getBoundingClientRect().bottom-4);if(s!=null&&s.isSimple())return Ye.from(n,s);const l=st(i,ut(n,i),"end");return new Ye(n,{anchor:l,focus:l})}function L4(n,t,e){const o=ih(n,t,e);if(o){if(o instanceof Ye)return o;g(D4,o instanceof ir,`invalid range type: ${typeof o}`);const a=o,d=n.getContainerById(a.start.childContainerId);return S4(n,d,t,e)}const r=document.elementsFromPoint(t,e)[0];if(!r)return null;const{children:i}=r,s=Array.from(i).filter(a=>Pr(a));if(s.length===0)return null;const l=s.reduce((a,d)=>{const h=a.getBoundingClientRect(),p=d.getBoundingClientRect();return nr(h,t,e)>nr(p,t,e)?d:a});return S4(n,l,t,e)}function Xm(n,t){const e=[];return pe(t).forEach(r=>{e.push(r),Mt(n,r)&&xn(n,r).forEach(s=>{e.push(...Xm(n,s))})}),e}function tg(n,t){let e=Xm(n,n.rootContainer);return t!=null&&t.simpleBlockOnly&&(e=e.filter(o=>!Mt(n,o))),e}function Ro(n,t){const e=n.selection.range.getSelectedBlocks(),o=[];for(const r of e)o.push(r),Mt(n,r.block)&&Rs(n,r.block,r.start,r.end).forEach(s=>{const a=Xm(n,s).map(d=>({block:d,start:st(d,0,"home"),end:st(d,ut(n,d),"home")}));o.push(...a)});return t!=null&&t.simpleBlockOnly?o.filter(r=>!Mt(n,r.block)):o}const unt="",Je=S("text-range");function Ox(n,t){const e=(i,s)=>{if(Hr(i))return g(Je,s===0,`invalid offset for insertion child: ${s}`),{child:i,container:i,offset:2};if(so(i))return g(Je,s===0||s===1,`invalid offset for box: ${s}`),{child:i,container:i,offset:s===0?1:2};const l=i.firstChild;return g(Je,l,"no child node for text child"),g(Je,l instanceof Text||l instanceof HTMLBRElement,`invalid child for text child, ${l.nodeName}`),l instanceof HTMLBRElement?(g(Je,s>=0&&s<=0,"invalid offset for text child"),{child:i,container:l,offset:s}):(g(Je,s>=0&&s<=l.data.length,"invalid offset for text child"),{child:i,container:l,offset:s})};let o=0;const r=rr(n);for(let i=0;i<r.length;i++){const s=r[i],l=lo(s);if(t===o)return[e(s,0)];if(t<o+l)return[e(s,t-o)];if(t===o+l){const a=[];a.push(e(s,lo(s)));const d=r[i+1];return d&&a.push(e(d,0)),a}o+=l}g(Je,!1,"failed to get range info")}function _x(n,t,e){if(t===e?g(Je,Hr(n),"only insertion child can be zero offset"):g(Je,t<e,`invalid start & end: ${t}, ${e}`),Hr(n)){g(Je,t===e,`invalid insertion child range offset: ${t}, ${e}`),g(Je,t===0,`invalid insertion child range start: ${t}`);const i=n;return g(Je,i.children.length===3,`invalid insertion dom, children.length = ${i.children.length}`),$d(i,1,i,2)}if(so(n)){g(Je,t+1===e,`invalid box child range offset: ${t}, ${e}`),g(Je,t===0,`invalid box child range start: ${t}`);const i=n;return g(Je,i.children.length===3,`invalid box dom, children.length = ${i.children.length}`),$d(i,1,i,2)}const o=lo(n);g(Je,e<=o,`invalid child end: ${e}, ${o}`);const r=n.firstChild;return g(Je,r instanceof Text,"invalid block text child"),g(Je,r.data.length>=e,`invalid range end: ${e}, ${r.data.length}`),$d(r,t,r,e)}const Oo=S("caret-rect");function Fx(n,t){if(Fm(t)){const e=t,o=Nm(e);if(e.getAttribute("data-box-type")==="br"){const r=Lt(n),i=Number.parseFloat(window.getComputedStyle(r).lineHeight)||o.getBoundingClientRect().height,s=Array.from(o.getClientRects());g(Oo,s.length>0,"no box client rects");const l=r.getBoundingClientRect(),a=s[0],d=new DOMRect(l.left,a.bottom,1,i);return s.push(d),s}return o.getClientRects()}return $m(t).getClientRects()}function Vn(n,t){var l;const e=Ox(n,t.offset);if(e[1]&&e[0].child!==((l=e[1])==null?void 0:l.child)){if(t.type==="end"){const d=bs(e[0].child);return new DOMRect(d.right,d.top,1,d.height)}g(Oo,e[1],"invalid ranges");const a=Hd(e[1].child);return new DOMRect(a.left,a.top,1,a.height)}let r=e[0];if(g(Oo,e.length>=1,"failed to get block range"),e.length===1)r=e[0];else{if(g(Oo,e.length>=2,`invalid range info length: ${e.length}`),Hr(e[e.length-1].child)){r=e[e.length-1];const a=r.child,h=$m(a).getClientRects();g(Oo,h.length>=1,"no client rects for box content");const p=h[h.length-1];return new DOMRect(p.right,p.y,1,p.height)}t.type==="home"?r=e[1]:t.type==="end"||wa(e[0].child)?r=e[0]:wa(e[1].child)&&(r=e[1])}if(r.container instanceof HTMLBRElement){g(Oo,t.offset===0,"invalid offset for empty block text");const a=r.container.parentElement,d=a==null?void 0:a.parentElement;g(Oo,d===Lt(n)&&a,"invalid br parent, is not block parent");const h=a.getBoundingClientRect(),p=d.getBoundingClientRect();return new DOMRect(h.left,p.top,1,p.height)}const s=tC(r.container,r.offset).getClientRects();if(s.length===0){g(Oo,!wa(r.child),"only box or insertion child range has zero client rect"),g(Oo,r.offset===1||r.offset===2,"invalid offset for box or insertion child");const a=r.child,d=Fx(n,a);if(g(Oo,d.length>=1,"no client rects for box content"),r.offset===1){const p=d[0];return new DOMRect(p.x,p.y,1,p.height)}const h=d[d.length-1];return t.type==="end"||r.offset===2?new DOMRect(h.right,h.y,1,h.height):new DOMRect(h.x,h.y,1,h.height)}return g(Oo,s.length>0,"no client rects for range"),t.type==="home"?s[s.length-1]:s[0]}const Px=S("core");function zr(n,t,e,o){const r=te(t);let i=r.querySelector(`.block-anchor[data-id=${e}]`);i||(i=w("div",["block-anchor"],r),i.setAttribute("data-id",e));const s=o!=null?o:t.getBoundingClientRect(),l=t.getBoundingClientRect(),a=new DOMRect(s.left-l.left,s.top-l.top,s.width,s.height);return i.style.left=`${a.left}px`,i.style.top=`${a.top}px`,i.style.width=`${a.width}px`,i.style.height=`${a.height}px`,i}function M4(n,t,e,o){g(Px,tt(n,t),"not a text kind block");const r=Vn(t,st(t,e,"normal")),i=t.getBoundingClientRect(),s=te(t);let l=s.querySelector(`.block-anchor[data-id=${o}]`);l||(l=w("div",["block-anchor"],s),l.setAttribute("data-id",o));const a=new DOMRect(r.left-i.left,r.top-i.top,r.width,r.height);return l.style.left=`${a.left}px`,l.style.top=`${a.top}px`,l.style.width=`${a.width}px`,l.style.height=`${a.height}px`,l}function Ea(n){const t=rr(n);let e=0;return t.forEach(o=>{e+=lo(o)}),e}const R4=S("box");function xa(n){return!n.attributes||!n.attributes.box?!1:(g(R4,n.attributes.box===!0,`invalid op attribute box property, ${n.attributes.box}`),g(R4,n.attributes.type,`no box type: ${JSON.stringify(n)}`),!0)}const O4=S("rich-text-length");function eg(n){return g(O4,typeof n.insert=="string","op.insert is not string"),n.insert.length}function rn(n){let t=0;return n.forEach(e=>{e.insert&&(g(O4,typeof e.insert=="string","op.insert is not string"),t+=eg(e))}),t}const sr=S("split-text");function In(n,t,e){if(n=mt.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];g(sr,typeof i=="object",`invalid op type, ${typeof i}`),g(sr,typeof i.insert=="string",`invalid op.insert type, ${typeof i.insert}`);const s=eg(i);if(o+s<t)o+=s;else{if(o+s===t)return{left:n.slice(0,r+1),right:n.slice(r+1)};{g(sr,o+s>t,`invalid offset, ${o}, ${s}, ${t}`);const l=t-o,a=mt.default(i);g(sr,a.insert,"no copied.insert"),g(sr,typeof a.insert=="string","invalid copied.insert type"),a.insert=a.insert.substr(0,l),i.insert=i.insert.substr(l),a.insert===""&&g(sr,!1,"invalid copied.insert, is empty string"),i.insert===""&&g(sr,!1,"invalid op.insert, is empty string");const d=[i,...n.slice(r+1)],h=[...n.splice(0,r),a];return e&&(e.sourceOp=i),{left:h,right:d}}}}throw new Error(`invalid split offset: ${t}, ${JSON.stringify(n)}`)}function ze(n,t,e){g(sr,t>=0,"invalid offset, < 0"),g(sr,e>0,"invalid length, <= 0"),g(sr,t+e<=rn(n),"invalid offset + length < text length");const{left:o,right:r}=In(n,t+e),{left:i,right:s}=In(o,t);return{left:i,middle:s,right:r}}function _4(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:a}=In(r,s);r=l,o.unshift(a)}return r.length>0&&o.unshift(r),o}function F4(n,t,e){return ze(n,t,e).middle}const Vl=S("text-block-content");function Nx(n,t,e,o,r){if(g(Vl,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=p=>n.editorInsertions.createInsertion(e,p),l=(p,A)=>{const v=r==null?void 0:r.get(A);v&&(v.forEach(B=>{p.appendChild(s(B))}),r==null||r.delete(A))},a=document.createDocumentFragment();let d=0;const h=_4(o,i);for(let p=0;p<h.length;p++){l(a,d);const A=h[p];d+=rn(A);for(let v=0;v<A.length;v++){const B=A[v];if(xa(B)){g(Vl,B.attributes,`op is not an valid box: ${JSON.stringify(B)}`);const x=n.editorBoxes.createBox(e,B.attributes);g(Vl,x instanceof HTMLSpanElement,`invalid box element: ${x.tagName}`),a.appendChild(x);continue}g(Vl,B.insert,`no insert in op: ${JSON.stringify(B)}`);const D=w("span",["text"],a,B.insert);if(B.attributes){const x=n.editorBlockRenders.renderText(t,B.attributes);x.classes&&W(D,...x.classes),x.attributes&&Object.entries(x.attributes).forEach(([_,M])=>{D.setAttribute(_,M)}),x.styles&&Object.entries(x.styles).forEach(([_,M])=>{D.style.setProperty(_,M)})}a.appendChild(D)}}l(a,d),e.innerHTML="",e.appendChild(a)}function sh(n,t,e,o,r){const{text:i,insertions:s}=n.editorDecorators.decorateText(t,r),l=n.compositingText;if(l){const a=n.selection.range.start;g(Vl,a.isSimple(),"not an simple position while compositing"),a.blockId===e&&s.set(a.offset,[{type:"inputting",id:K(),text:l}])}return Nx(n,t,o,i,s)}function $x(n){const t=n.rootContainer.querySelectorAll('span[data-type="editor-insertion"].inputting-insertion');t.length&&Vl.debug(`remove ${t.length} temp composition span`),Array.from(t).forEach(e=>e.remove())}const lr=S("client-rects");function Hx(n){const t=rr(n);let e=0;const o=[];for(let r=0;r<t.length;r++){const i=t[r],s=lo(i);o.push({child:i,startBlockOffset:e,endBlockOffset:e+s}),e+=s}return o}function jx(n,t,e,o){g(lr,e<o,`invalid from & to: ${e}, ${o}`);const r=ut(n,t);g(lr,e>=0&&o>=0&&e<=r&&o<=r,`invalid offset: ${e}, ${o}, length: ${r}`);const i=Hx(t),s=i.findIndex(v=>v.startBlockOffset<=e&&e<v.endBlockOffset),l=i.findIndex(v=>v.startBlockOffset<o&&o<=v.endBlockOffset);if(g(lr,s!==-1,"failed to find start child"),g(lr,l!==-1,"failed to find end child"),g(lr,s<=l,`invalid start index & end index: ${s}, ${l}`),s===l){const v=i[s];return[{child:v.child,startChildOffset:e-v.startBlockOffset,endChildOffset:o-v.startBlockOffset}]}const a=[],d=i[s],h={child:d.child,startChildOffset:e-d.startBlockOffset,endChildOffset:lo(d.child)};a.push(h);for(let v=s+1;v<l;v++){const B=i[v],D={child:B.child,startChildOffset:0,endChildOffset:B.endBlockOffset-B.startBlockOffset};a.push(D)}const p=i[l],A={child:p.child,startChildOffset:0,endChildOffset:o-p.startBlockOffset};return a.push(A),a}function Ux(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 P4(n,t,e,o){if(ut(n,t)===0){const h=Lt(t).getBoundingClientRect();return[new DOMRect(h.left,h.top,4,h.height)]}const r=e.offset,i=o.offset;if(r===i)return[Vn(t,e)];const l=jx(n,t,r,i).map(d=>_x(d.child,d.startChildOffset,d.endChildOffset)),a=[];return l.forEach(d=>{const h=Ux(Array.from(d.getClientRects()));a.push(...h)}),a}function zx(n,t,e){g(lr,e instanceof Ye,"invalid range");const o=e.start,r=e.end;return g(lr,o.isSimple(),"text block only allow simple position"),g(lr,r.isSimple(),"text block only allow simple position"),g(lr,o.blockId===r.blockId,"only allow update one text block selection"),g(lr,o.blockId===it(t),"only allow update one text block selection"),P4(n,t,o,r)}const ng=S("selection-background");function Vx(n,t,e,o){g(ng,e.isSimple(),"text block only allow simple position"),g(ng,o.isSimple(),"text block only allow simple position"),g(ng,e.blockId===o.blockId,"only allow update one text block selection");const r=e.offset,i=o.offset;if(r===i&&(ut(n,t)!==0||n.selection.range.isCollapsed()))return;const s=P4(n,t,e,o),l=t.getBoundingClientRect(),a=ys(t),d=zC(t);d.innerHTML="",s.forEach(h=>{const p=w("div",["editor-selection-background"],d);p.style.left=`${(h.left-l.left-t.clientLeft)/a}px`,p.style.top=`${(h.top-l.top-t.clientTop)/a}px`,p.style.width=`${h.width/a}px`,p.style.height=`${h.height/a}px`})}function Wx(n){n.rootContainer.querySelectorAll("div[data-type=block-background]").forEach(t=>{t.remove()})}const Os=S("text-offset"),N4="\u200D";function _s(n,t){const e=rr(n);let o=0;for(let r=0;r<e.length;r++){const i=e[r],s=lo(i);if(i===t){const l=o+s;return{start:o,end:l}}o+=s}g(Os,!1,"can not find child in children")}function sn(n,t){g(Os,t>=0,`invalid offset: ${t}`);const e=eh(n,t),{prev:o,next:r,offset:i}=e;if(!o&&!r&&g(Os,!1,"invalid offset, no prev & next child at offset"),o!==r)return!0;const s=o;if(g(Os,s,"no child"),so(s))return g(Os,i===0||i===1,`invalid box child offset: ${i}`),!0;const l=s.textContent;g(Os,l,"no content for text child");const a=l.charAt(i-1),d=l.charAt(i);return!(a===N4||d===N4||gm(l[i]))}function Ri(n,t){if(t===0)return 0;const e=t-1;if(sn(n,e))return e;let o=e-1;for(;!sn(n,o);)o-=1;return o}function Fs(n,t){const e=Ea(n);if(g(Os,t>=0&&t<=e,`invalid offset: ${t}, ${e}`),t===e)return e;const o=t+1;if(sn(n,o))return o;let r=o+1;for(;!sn(n,r);)r+=1;return r}const Ps=S("line-breaker");function Ia(n){const t=a=>{const d=Hd(a);return bs(a).top>d.top+d.height/2},e=(a,d)=>{const h=bs(a);return Hd(d).left<h.right},o=(a,d)=>{const h=bs(a),p=bs(d);return p.top+p.height/2>h.bottom},r=a=>{if(a.length===0||a.length===1)return!1;const d=a[0],h=a[a.length-1];return d.right-h.left>10},i=[];let s=0;const l=rr(n);for(let a=0;a<l.length;a++){const d=l[a];if(Hr(d)){const x=d,_=l[a+1];if(!_)break;const M=l[a-1];if(M&&o(M,x)&&i.push({offset:s,type:"betweenChild",childInfo:{prevChild:M,nextChild:x,wrap:"nextWrapped",prevWrapped:t(M),nextWrapped:t(x)}}),e(x,_)){i.push({offset:s,type:"betweenChild",childInfo:{prevChild:M,nextChild:x,wrap:"nowrap",prevWrapped:t(M),nextWrapped:t(x)}});continue}continue}if(so(d)){const x=d,_=l[a+1];if(!_)break;const M=l[a-1];if(M&&o(M,x)&&i.push({offset:s,type:"betweenChild",childInfo:{prevChild:M,nextChild:x,wrap:"nextWrapped",prevWrapped:t(M),nextWrapped:t(x)}}),e(x,_)){s+=1,i.push({offset:s,type:"betweenChild",childInfo:{prevChild:M,nextChild:d,wrap:"nowrap",prevWrapped:t(M),nextWrapped:t(d)}});continue}s+=1;continue}const h=d,p=h.getClientRects();if(g(Ps,p.length>0,"invalid text child dom"),p.length===1){const x=l[a+1];if(!x)break;if(e(h,x)){s+=lo(h),i.push({offset:s,type:"betweenChild",childInfo:{prevChild:h,nextChild:x,wrap:"nowrap",prevWrapped:t(h),nextWrapped:t(x)}});continue}s+=lo(h);continue}const A=h.firstChild;g(Ps,A,"invalid text child, no text node"),g(Ps,A instanceof Text,`invalid text child, not a valid text node: ${typeof A}`);const v=document.createRange(),B=document.createRange(),D=lo(h);g(Ps,A.data.length===D,"text node data length not equal child text length");for(let x=0;x<A.data.length;x++){if(!sn(n,s+x))continue;v.setStart(A,x),Vd()&&v.selectNodeContents(A);const _=v.getClientRects();if(g(Ps,_.length>=1,"invalid text node, no client rects"),r(_)){const rt=s+x;i.push({offset:rt,type:"textBreakWord",childInfo:{prevChild:d,nextChild:d,wrap:"nowrap",prevWrapped:t(d),nextWrapped:t(d)}});continue}let M=x+1;sn(n,s+M)||(M=x+2),B.setStart(A,M);const H=B.getClientRects(),z=_[0];H[0].left<z.right&&g(Ps,!1,"span pre-wrap should not has a line-wrap by white space")}s+=D}return i}function og(n,t){const e=Ia(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 g(Ps,t.offset<=Ea(n),"invalid position, offset > block length"),{lineIndex:e.length,lineBreaks:e}}const qx=S("line-offset");function rg(n){const t=Ia(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:Ea(n)}),e}function lh(n,t){const e=rg(n);return g(qx,t>=0&&t<e.length,`invalid line index: ${t}, ${e.length}`),e[t]}function $4(n,t){const{lineIndex:e}=og(n,t);return lh(n,e)}function Gx(n){const t=rg(n),e=n.getBoundingClientRect(),o=[];return t.forEach(({start:r,end:i})=>{const s=st(n,r,"home");let l=Vn(n,s);const a=st(n,i,"end"),d=Vn(n,a);l.top+l.height/2<d.top&&(l=new DOMRect(e.left-1e4,d.top,1,d.height));const h=new DOMRect(l.left,d.top,d.left-l.left,d.height),p=new DOMRect(e.left,d.top,e.width,d.height);o.push({start:r,end:i,rect:p,contentRect:h})}),o}function Zx(n,t,e){const r=Gx(n).find(s=>ks(s.rect,t,e));if(!r)return null;const i=r.contentRect;return t-i.left<i.right-t?st(n,r.start,"home"):st(n,r.end,"end")}function H4(n,t,e){const o=Vn(n,t),r=Vn(n,e),i=o.top+o.height/2,s=r.top+r.height/2,l=r.top<i&&i<r.bottom,a=o.top<s&&s<o.bottom;return l&&a}function j4(n){return rg(n).length}const Ns=S("find-text-position");function U4(n,t){const{start:e,end:o}=lh(n,t),r=it(n),i=Vn(n,st(r,e,"home"));if(!(Vn(n,st(r,o,"end")).top>i.top+i.height/2))return!1;const a=eh(n,e);return g(Ns,a.next,"no next child at offset"),g(Ns,!wa(a.next),"next child is not text child"),!0}function Qx(n,t){const e=it(n);g(Ns,U4(n,t),"line is not wrapped");const{start:o,end:r}=lh(n,t),i=st(e,o,"home");for(let s=o+1;s<=r;s+=1){let l="normal";s===o?l="home":s===r&&(l="end");const a=st(e,s,l);if(!H4(n,i,a))return s-1}return g(Ns,!1,"failed to find wrapped offset"),0}function ch(n,t,e,o,r,i,s){g(Ns,tt(n,t),`not a text kind block: ${Dt(t)}`);const{start:l,end:a}=lh(t,e);let d=l;const h=it(t);if(t===o&&U4(t,e)){const x=Qx(t,e);(i==="up"||i==="down"&&H4(t,r,st(h,l,"home")))&&(d=x+1)}let p=Number.MAX_SAFE_INTEGER;const A=So(n,o,r),v=s!=null?s:A.left+A.width/2,B=A.top+A.height/2;let D=st(h,d,"home");for(let x=d;x<=a;x++){if(!sn(t,x))continue;let _="normal";x===l?_="home":x===a&&(_="end");const M=st(h,x,_),H=Vn(t,M),z=nr(H,v,B);z<p&&(p=z,D=M)}return D}function Yx(n,t,e,o,r){return g(Ns,tt(n,t),"not a text block"),ch(n,t,j4(t)-1,e,o,"up",r)}function Jx(n,t,e,o,r){return g(Ns,tt(n,t),"not a text block"),ch(n,t,0,e,o,"down",r)}function Kx(n,t,e,o){const{lineIndex:r}=og(t,e);if(r===j4(t)-1)return null;const i=ch(n,t,r+1,t,e,"down",o);return i||null}function Xx(n,t){if(t.offset===0)return null;const e=Ia(n),o=e.find(r=>r.offset===t.offset);if(!o){const r=Ri(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:Ri(n,t.offset),type:"normal"}}return{offset:Ri(n,t.offset),type:"normal"}}function tI(n,t){const e=Ea(n);if(t.offset===e)return null;const o=Ia(n),r=o.find(i=>i.offset===t.offset);if(!r){const i=Fs(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:Fs(n,t.offset),type:"home"}:{offset:Fs(n,t.offset),type:"normal"}}function eI(n,t,e,o){const{lineIndex:r}=og(t,e);if(r===0)return null;const i=ch(n,t,r-1,t,e,"up",o);return i||null}const nI=S("move-caret");function oI(n,t,e,o){if(o==="ArrowLeft"){const r=Xx(t,e);return r?st(it(t),r.offset,r.type):null}if(o==="ArrowRight"){const r=tI(t,e);return r?st(it(t),r.offset,r.type):null}if(o==="ArrowUp"){const r=eI(n,t,e,n.selection.getSuggestedCaretX());return r?st(it(t),r.offset,r.type):null}if(o==="ArrowDown"){const r=Kx(n,t,e,n.selection.getSuggestedCaretX());return r?st(it(t),r.offset,r.type):null}g(nI,!1,`invalid navigation direction: ${o}`)}const ig=S("text-range");function rI(n){const t=[];return rr(n).forEach(o=>{const r=Array.from(o.getClientRects()).map(i=>({rect:i,child:o}));t.push(...r)}),t}function iI(n,t,e){const o=rI(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 _s(n,s.child).start}return null}function sI(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 _=t.getBoundingClientRect();if(!ks(_,e,o))return null;const M=iI(t,e,o);if(M!==null){const z=st(t,M,"normal");return new Ye(n,{anchor:z,focus:z})}const H=Zx(t,e,o);return H?new Ye(n,{anchor:H,focus:H}):null}const s=rr(t);g(ig,s.indexOf(i)!==-1,"failed to find child in children");const l=_s(t,i);g(ig,l,"failed to get child offset");const{start:a}=l;let d,h;Hr(i)||so(i)?(d=a,h=0):(g(ig,i.firstChild instanceof Text,"child is not text"),d=a+eC(i.firstChild,e,o),h=0);const p=it(t),v=Ia(t).find(_=>_.offset===d);let B="normal";if(v){const _=st(p,d,"home"),M=st(p,d,"end"),H=Vn(t,_),z=Vn(t,M),q=nr(H,e,o),rt=nr(z,e,o);B=q<rt?"home":"end"}const D=st(p,d,B);let x;return h&&(x=st(p,d+h,B)),new Ye(n,{anchor:D,focus:x!=null?x:D})}const lI=S("create-text-op");function co(n,t){g(lI,n,"text is empty");const e={insert:n};return t&&Object.keys(t).length>0&&(e.attributes=t),e}function sg(n,t){if(n.length===0)return[];if(n.indexOf(`
|
|
16
16
|
`)===-1)return[co(n,t)];const e=n.replace(/\r\n/g,`
|
|
17
17
|
`).replace(/\r/g,`
|
|
18
18
|
`).replace(/\n/g," "),o=[];return e&&o.push(co(e,t)),o}const ah=S("merge-ops");function lg(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?(g(ah,i.attributes===void 0,"op2.attributes is not undefined"),!0):(g(ah,r.attributes&&i.attributes,"op1.attributes && op2.attributes is undefined"),aa.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)?(g(ah,typeof o.insert=="string","before.insert is not string"),g(ah,typeof i.insert=="string","op.insert is not string"),o.insert+=i.insert):(e.push(i),o=i)}return e}function cI(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 z4=S("delete-text");function cg(n,t,e){const{left:o,right:r}=ze(n,t,e),i=[...o,...r];return lg(i)}function V4(n,t){g(z4,n>=0,`invalid offset: ${n}`),g(z4,t>=1,`invalid delete count: ${t}`);const e=[];return n!==0&&e.push({retain:n}),e.push({delete:t}),e}const W4=S("delta");function q4(n,t){const e=new on.default(n),o=new on.default(t);return e.diff(o).ops}function aI(n,t,e){return new on.default(t).transformPosition(n,!e)}function uI(n){g(W4,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 dI(n,t){const e=new on.default(n),o=new on.default(t);return e.compose(o).ops}class ln{static ensureValidText(t){g(W4,uI(t),`text is not a valid text, ${JSON.stringify(t)}`)}static diff(t,e){return this.ensureValidText(t),this.ensureValidText(e),q4(t,e)}static transformCursor(t,e,o){return aI(t,e,o)}static transformOffset(t,e,o){const r=q4(t,e),i=new on.default(r);return o.map(s=>i.transformPosition(s))}static apply(t,e){this.ensureValidText(t);const o=dI(t,e);return this.ensureValidText(o),o}}const G4=S("insert-text");function Vr(n,t,e,o){g(G4,e,`invalid text to insert: ${e}`);const{left:r,right:i}=In(n,t),s=typeof e=="string"?[co(e,o)]:e,l=[...r,...s,...i];return lg(l)}function Z4(n){return{insert:" ",attributes:n}}function uh(n,t,e){if(g(G4,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 hI(n,t){return[...n,...t]}const Q4=S("text-op");function dh(n){return g(Q4,typeof n.insert=="string","invalid op, no insert"),n.insert.length}function Y4(n,t){const e=n;let o=0;for(let r=0;r<e.length;r++){const i=e[r];g(Q4,typeof i.insert=="string","invalid text op, no insert");const s=o+dh(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 ag="style-color-",ug="style-bg-color-";function hh(n,t,e){const o=mt.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 dg(n,t,e,o){const r=mt.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 Ta(n,t,e,o,r){if(t===0)return e;const i=ze(e,n,t);return[...i.left,...hh(i.middle,o,r),...i.right]}function Wl(n,t,e,o,r,i){if(t===0)return e;const s=ze(e,n,t);return[...s.left,...dg(s.middle,o,r,i),...s.right]}function Da(n,t){const e=Y4(n,t);if(e.length===1)return e[0].attributes;if(e.length===2)return e[1].attributes}function J4(n,t,e,o){if(t===0)return e;const r=ze(e,n,t),i=r.middle.map(s=>o(s));return[...r.left,...i,...r.right]}function K4(n,t){t==="color"?Object.keys(n).forEach(e=>{(e.startsWith("style-color-")||e==="inline-style-color")&&delete n[e]}):t==="backgroundColor"&&Object.keys(n).forEach(e=>{e.startsWith("style-bg-color-")&&delete n[e]})}function fI(n,t){if(!n.attributes||n.attributes.box)return;const e=n.attributes;K4(e,t),Object.keys(e).length===0&&delete n.attributes}function mI(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 X4(n,t,e,o,r){const i=mt.default(e);return J4(n,t,i,l=>(fI(l,o),r!==null&&mI(l,o,r),l))}function hg(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(ag)?e=(r=Number.parseInt(l.substring(ag.length),10))!=null?r:null:l.startsWith(ug)&&(o=(i=Number.parseInt(l.substring(ug.length),10))!=null?i:null)}return[e,o]}function t6(n,t,e){K4(n,t),t==="color"?n[`style-color-${e}`]=!0:n[`style-bg-color-${e}`]=!0}function e6(n){return n.attributes?n.attributes.box?[null,null]:hg(n.attributes):[null,null]}function n6(n,t,e){let o=[];if(t===0?n!==0&&(o=ze(e,n-1,1).middle):o=ze(e,n,t).middle,o.length===0)return[null,null];let[r,i]=e6(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[a,d]=e6(l);a===null||r===null?r=null:r=a===r?r:null,d===null||i===null?i=null:i=d===i?i:null}return[r,i]}function o6(n){return mt.default(n)}const gI=S("update-op-attribute");function r6(n,t,e,o){const r=o6(n),i=r.findIndex(l=>l.attributes?l.attributes[t]===e:!1);g(gI,i!==-1,`can not find op by key: ${t}, value: ${e}`);const s=r[i];return s.attributes={...s.attributes,...o},r}const pI="\u200B",CI=S("to-plain-text");function ie(n,t){let e="";return n.forEach(o=>{if(g(CI,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 fg(n){return ie(n,{boxReplacement:" "})}function fh(n,t,e,o){const r=Da(n,t),i=cg(n,t,e-t);return o?Vr(i,t,o,r!=null?r:null):i}function mg(n,t){if(!t)return[];const e=t.length,o=ie(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 i6(n,t,e,o){const r=mg(n,t);let i=mt.default(n);return r.length===0||(r.reverse().forEach(s=>{i=fh(i,s.start,s.end,e)}),o&&(o.count=r.length)),i}function Oi(n,t){return n?[{insert:n,attributes:t}]:[]}function
|
|
21
|
-
`).map((r,i)=>{const l=i===0&&(t==null?void 0:t.firstLineAsTitle)?{heading:1}:void 0;return
|
|
20
|
+
`," ").replaceAll("\r"," ")};return e&&Object.keys(e).length>0&&(i.attributes=e),o.push(i),o}function hI(n,t){return[...n,...t]}const Q4=S("text-op");function dh(n){return g(Q4,typeof n.insert=="string","invalid op, no insert"),n.insert.length}function Y4(n,t){const e=n;let o=0;for(let r=0;r<e.length;r++){const i=e[r];g(Q4,typeof i.insert=="string","invalid text op, no insert");const s=o+dh(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 ag="style-color-",ug="style-bg-color-";function hh(n,t,e){const o=mt.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 dg(n,t,e,o){const r=mt.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 Ta(n,t,e,o,r){if(t===0)return e;const i=ze(e,n,t);return[...i.left,...hh(i.middle,o,r),...i.right]}function Wl(n,t,e,o,r,i){if(t===0)return e;const s=ze(e,n,t);return[...s.left,...dg(s.middle,o,r,i),...s.right]}function Da(n,t){const e=Y4(n,t);if(e.length===1)return e[0].attributes;if(e.length===2)return e[1].attributes}function J4(n,t,e,o){if(t===0)return e;const r=ze(e,n,t),i=r.middle.map(s=>o(s));return[...r.left,...i,...r.right]}function K4(n,t){t==="color"?Object.keys(n).forEach(e=>{(e.startsWith("style-color-")||e==="inline-style-color")&&delete n[e]}):t==="backgroundColor"&&Object.keys(n).forEach(e=>{e.startsWith("style-bg-color-")&&delete n[e]})}function fI(n,t){if(!n.attributes||n.attributes.box)return;const e=n.attributes;K4(e,t),Object.keys(e).length===0&&delete n.attributes}function mI(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 X4(n,t,e,o,r){const i=mt.default(e);return J4(n,t,i,l=>(fI(l,o),r!==null&&mI(l,o,r),l))}function hg(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(ag)?e=(r=Number.parseInt(l.substring(ag.length),10))!=null?r:null:l.startsWith(ug)&&(o=(i=Number.parseInt(l.substring(ug.length),10))!=null?i:null)}return[e,o]}function t6(n,t,e){K4(n,t),t==="color"?n[`style-color-${e}`]=!0:n[`style-bg-color-${e}`]=!0}function e6(n){return n.attributes?n.attributes.box?[null,null]:hg(n.attributes):[null,null]}function n6(n,t,e){let o=[];if(t===0?n!==0&&(o=ze(e,n-1,1).middle):o=ze(e,n,t).middle,o.length===0)return[null,null];let[r,i]=e6(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[a,d]=e6(l);a===null||r===null?r=null:r=a===r?r:null,d===null||i===null?i=null:i=d===i?i:null}return[r,i]}function o6(n){return mt.default(n)}const gI=S("update-op-attribute");function r6(n,t,e,o){const r=o6(n),i=r.findIndex(l=>l.attributes?l.attributes[t]===e:!1);g(gI,i!==-1,`can not find op by key: ${t}, value: ${e}`);const s=r[i];return s.attributes={...s.attributes,...o},r}const pI="\u200B",CI=S("to-plain-text");function ie(n,t){let e="";return n.forEach(o=>{if(g(CI,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 fg(n){return ie(n,{boxReplacement:" "})}function fh(n,t,e,o){const r=Da(n,t),i=cg(n,t,e-t);return o?Vr(i,t,o,r!=null?r:null):i}function mg(n,t){if(!t)return[];const e=t.length,o=ie(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 i6(n,t,e,o){const r=mg(n,t);let i=mt.default(n);return r.length===0||(r.reverse().forEach(s=>{i=fh(i,s.start,s.end,e)}),o&&(o.count=r.length)),i}function Oi(n,t){return n?[{insert:n,attributes:t}]:[]}function cr(n,t){return{id:K(),type:"text",text:typeof n=="string"?Oi(n):n,...t}}function mh(n){return cr(n!=null?n:"")}function Wr(n,t){return{blocks:{root:(n!=null?n:"").replaceAll("\r","").split(`
|
|
21
|
+
`).map((r,i)=>{const l=i===0&&(t==null?void 0:t.firstLineAsTitle)?{heading:1}:void 0;return cr(r,l)})},meta:{},comments:{}}}function gg(n){const t=n.blocks.root;if(t.length!==1)return!1;const e=t[0];return!(!e.text||rn(e.text))}function s6(n,t){const e=K();return n.localInsertChildContainer(e,t),e}function qr(n,t){return s6(n,[mh(t)])}function l6(n){return typeof n.offset=="number"}function gh(n){return l6(n.anchor)}function AI(n){return gh(n)&&n.anchor.offset===n.focus.offset&&n.anchor.blockId===n.focus.blockId}function c6(n,t){return{blockId:n,offset:t}}function ph(n,t){const e=c6(n,t);return{anchor:e,focus:e}}function a6(n,t){return{blockId:n,childContainerId:t}}function bI(n,t){const e=a6(n,t);return{anchor:e,focus:e}}const vI=S("block-to-text");function yI(n,t,e){let o="";return t.forEach(r=>{if(g(vI,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 kI=S("block-to-text");function wI(n,t,e){let o="";return t.forEach(r=>{if(g(kI,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 a=l.join("");o.endsWith(a.substring(0,1))&&(o+=" ");const d=l.reverse().join("");o+=a+s+d;return}o+=r.insert}),o}function BI(n,t,e){const o=t.text||[];let i=wI(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
22
|
`),i}const EI=S("block-to-text");function xI(n,t,e){let o="";return t.forEach(r=>{if(g(EI,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 a=l.map(h=>`<${h}>`).join(""),d=l.reverse().map(h=>`</${h}>`).join("");o+=a+s+d;return}o+=r.insert}),o||(o="<br>"),`<p>${o}</p>`}const Sa=S("text-block");function II(n,t,e,o,r){const{text:i}=r;g(Sa,i,"no text for text block");const s=Is(o,"div");return sh(n,t,r.id,s,i),s}function TI(n,t,e){g(Sa,e,"no text to update");const o=Is(null,"div");sh(n,Li(t),it(t),o,e);const r=Lt(t);Ca(r,o)}function DI(n,t,e){return zx(n,t,e)}function u6(n,t){let e="";return t.forEach(o=>{var r,i;if(!!o.insert){if(o.attributes&&o.attributes.box===!0){const s=n.getBoxById(o.attributes.id),l=(i=(r=n.editorBoxes.getBoxClass(o.attributes.type)).getBoxProperties)==null?void 0:i.call(r,n,s);e+=l!=null&&l.abstract?` [${l.abstract}] `:" ";return}e+=o.insert}}),e.trim()}function SI(n,t){g(Sa,tt(n,t),"block in not textBlock");const e=n.selection.range;let o="";if(e.isCollapsed()){const r=n.getBlockText(t);o=u6(n,r)}else{const r=it(t),i=Ro(n,{simpleBlockOnly:!0}).find(s=>it(s.block)===r);if(i&&!he(n,i.block)){g(Sa,i.block===t,"block not match");const s=n.getBlockText(t),{start:l,end:a}=i,d=l.offset,h=a.offset-d;if(h>0){const{middle:p}=ze(s,d,h);o=u6(n,p)}}}return{abstract:o.trim()}}function LI(n,t,e,o){return g(Sa,t.text,"no text for text block"),o==="text"?yI(n,t.text,e):o==="markdown"?BI(n,t,e):xI(n,t.text,e)}const Tn={blockType:"text",blockKind:"text",createBlockContent:II,getBlockTextLength:Ea,getRangeFromPoint:sI,moveCaret:oI,updateSelection:Vx,clearSelection:Wx,getCaretRect:Vn,getClientRects:DI,setBlockText:TI,getBlockProperties:SI,convertTo:LI},MI=sh,Ch=S("action-helper");function _i(n,t){const e=nt(t),o=at(e),r=bt(t);return n.doc.getBlockData(o,r)}function gn(n,t){g(Ch,tt(n,t),"not a text kind block");const o=_i(n,t).text;return g(Ch,o,"no text in block"),o}function Ah(n,t,e){return In(gn(n,t),e).left}function d6(n,t){const e=et(t);g(Ch,e,"no parent block");const o=gn(n,e),r=qC(t),i=o.find(s=>{const l=s.attributes;return l?l.box&&l.id===r:!1});return g(Ch,i,"failed to find box"),i.attributes}const me=S("block-text");function RI(n,t,e){g(me,tt(n,t),"not a text kind block"),g(me,sn(t,e),"not a valid offset"),g(me,e>=0&&e<ut(n,t),`invalid offset: ${e}`);const r=Fs(t,e)-e;r===0&&g(me,!1,`no text after offset: ${e}`);const i=gn(n,t),{middle:s}=ze(i,e,r);g(me,s.length===1,"failed to split text to 3 parts");const l=s[0];return xa(l)?" ":(g(me,l.insert.length===1||l.insert.length===2,"invalid op"),l.insert)}function OI(n,t,e){g(me,tt(n,t),"not a text kind block"),g(me,sn(t,e),"not a valid offset"),g(me,e>0&&e<=ut(n,t),`invalid offset: ${e}`);const o=Ri(t,e),r=e-o;r===0&&g(me,!1,`no text before offset: ${e}`);const i=gn(n,t),{middle:s}=ze(i,o,r);g(me,s.length===1,"failed to split text to 3 parts");const l=s[0];return xa(l)?" ":(g(me,l.insert.length===1||l.insert.length===2,"invalid op"),l.insert)}function bh(n,t,e){g(me,tt(n,t),"not a text kind block"),g(me,sn(t,e),"not a valid offset"),g(me,e>0&&e<=ut(n,t),`invalid offset: ${e}`);const o=Ri(t,e),r=e-o;r===0&&g(me,!1,`no text before offset: ${e}`);const i=gn(n,t),{middle:s}=ze(i,o,r);g(me,s.length===1,"failed to split text to 3 parts");const l=s[0];return xa(l)?{op:l,charType:"box",offset:o,length:1}:{op:l,charType:zd(l.insert)?"space":"text",offset:o,length:l.insert.length}}function La(n,t,e){g(me,tt(n,t),"not a text kind block"),g(me,sn(t,e),"not a valid offset"),g(me,e>=0&&e<ut(n,t),`invalid offset: ${e}`);const r=Fs(t,e)-e;r===0&&g(me,!1,`no text after offset: ${e}`);const i=gn(n,t),{middle:s}=ze(i,e,r);g(me,s.length===1,"failed to split text to 3 parts");const l=s[0];return xa(l)?{op:l,charType:"box",offset:e,length:1}:{op:l,charType:zd(l.insert)?"space":"text",offset:e,length:l.insert.length}}function _I(n,t,e,o){let r=e;for(;r>0;){const i=bh(n,t,r);if(i.charType===o)return i;r-=i.length}return null}function FI(n,t,e,o){const r=ut(n,t);let i=e;for(;i<r;){const s=La(n,t,i);if(s.charType===o)return s;i+=s.length}return null}function pg(n,t,e,o){let r=e;for(;r>0;){const i=bh(n,t,r);if(i.charType!==o)return i;r-=i.length}return null}function Cg(n,t,e,o){const r=ut(n,t);let i=e;for(;i<r;){const s=La(n,t,i);if(s.charType!==o)return s;i+=s.length}return null}function Ag(n,t,e){if(g(me,tt(n,t),"invalid blok type"),he(n,t))return 0;const o=bh(n,t,e);if(o.charType==="box")return e-1;let r=e;if(o.charType==="space"){const s=pg(n,t,r,"space");if(!s||s.offset===0)return 0;if(s.charType==="box")return s.offset;r=s.offset}const i=pg(n,t,r,"text");return i?i.offset+i.length:0}function bg(n,t,e){if(g(me,tt(n,t),"invalid blok type"),he(n,t))return 0;const o=La(n,t,e);if(o.charType==="box")return e+1;let r=e;if(o.charType==="space"){const s=Cg(n,t,r,"space");if(!s||s.offset===0)return ut(n,t);if(s.charType==="box")return s.offset;r=s.offset}const i=Cg(n,t,r,"text");return i?i.offset:ut(n,t)}const h6=S("text-box");function PI(n,t,e,o){g(h6,o.text,`no text for text box data: ${JSON.stringify(o)}`),g(h6,typeof o.text=="string",`invalid text type for text box data: ${JSON.stringify(o)}`),w("span",[],e,o.text)}function NI(n,t,e,o){var r;return(r=t.text)!=null?r:""}const f6={boxType:"text",updateBoxContent:PI,convertTo:NI},$I="data:image/svg+xml;base64,Cjxzdmcgdmlld0JveD0iMCAwIDI0IDI0IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgo8cGF0aCBkPSJNMTguMjQ0NSA2QzE3LjgyNzQgNiAxNy41MzYzIDYuMjkxMTcgMTcuNTM2MyA2LjcwODI2QzE3LjUzNjMgNi45ODM3IDE3LjU1OTkgNy4yMzU1MyAxNy41NTk5IDcuNjEzMjdDMTcuNTU5OSAxMC4yODExIDE2LjYyMzQgMTEuMzc0OSAxMy45NzkyIDExLjM3NDlIOC45NDI2Nkw3LjEyNDc5IDExLjQ4NTFMOS41NDA3NSA5LjI4MTYyTDExLjE5MzQgNy41OTc1M0MxMS4zMjcxIDcuNDcxNjEgMTEuMzk4IDcuMjgyNzQgMTEuMzk4IDcuMDkzODdDMTEuMzk4IDYuNjkyNTIgMTEuMDk4OSA2LjQwMTM1IDEwLjY5NzYgNi40MDEzNUMxMC41MDg3IDYuNDAxMzUgMTAuMzM1NiA2LjQ3MjE4IDEwLjE3ODIgNi42MjE3TDUuMjQzOTYgMTEuNTQ4MUM1LjA4NjU3IDExLjcwNTUgNSAxMS44OTQzIDUgMTIuMDkxMUM1IDEyLjI4NzggNS4wODY1NyAxMi40NzY3IDUuMjQzOTYgMTIuNjI2MkwxMC4xNjI1IDE3LjUzNjhDMTAuMzM1NiAxNy43MDk5IDEwLjUwODcgMTcuNzgwOCAxMC42OTc2IDE3Ljc4MDhDMTEuMDk4OSAxNy43ODA4IDExLjM5OCAxNy40ODk2IDExLjM5OCAxNy4wODgzQzExLjM5OCAxNi44OTE1IDExLjMyNzEgMTYuNzEwNSAxMS4xOTM0IDE2LjU4NDZMOS41NDA3NSAxNC45MDA1TDcuMTMyNjYgMTIuNjk3TDguOTQyNjYgMTIuODA3MkgxNC4wNTc5QzE3LjU1OTkgMTIuODA3MiAxOSAxMS4yNDExIDE5IDcuNjc2MjJDMTkgNy4yMzU1MyAxOC45OTIxIDYuODY1NjUgMTguOTM3IDYuNjEzODNDMTguODc0MSA2LjI5OTA0IDE4LjY3NzMgNiAxOC4yNDQ1IDZaIiBmaWxsPSIjQjJCQ0NEIi8+Cjwvc3ZnPgo=";function HI(n,t,e,o){pm($I,[],e),w("br",[],e)}function jI(n,t,e,o){return o==="text"?`
|
|
23
23
|
`:o==="html"?"<br>":o==="markdown"?`
|
|
24
24
|
`:""}const m6={boxType:"br",updateBoxContent:HI,convertTo:jI},g6=S("editor-boxes");class p6{constructor(t){m(this,"boxes",new Map);this.editor=t}registerBoxClass(t){const e=t.boxType,o=this.boxes.get(e);g(g6,!o,`duplicated box type: ${e}`),this.boxes.set(e,t)}getBoxClass(t){const e=this.boxes.get(t);return g(g6,e,`unknown box type: ${t}`),e}createBox(t,e){const o=WC(e),r=GC(o);return this.getBoxClass(e.type).updateBoxContent(this.editor,o,r,e),o}}function UI(n,t,e,o){const r=o,{width:i,height:s,src:l}=r,a=["editor-box-image"];r.link&&a.push("editor-box-image-link");const d=w("img",a,e);i&&(d.style.width=`${i}px`),s&&(d.style.height=`${s}px`),d.src=n.doc.buildResourceUrl(l)}const C6={boxType:"image",updateBoxContent:UI},zI="data:image/svg+xml;base64,Cjxzdmcgd2lkdGg9IjI0IiBoZWlnaHQ9IjI0IiB2aWV3Qm94PSIwIDAgMjQgMjQiIGZpbGw9InJnYigxNzgsIDE4OCwgMjA1KSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0ibTE3IDE1IDEuNTUgMS41NWMtLjk2IDEuNjktMy4zMyAzLjA0LTUuNTUgMy4zN1YxMWgzVjloLTNWNy44MkMxNC4xNiA3LjQgMTUgNi4zIDE1IDVjMC0xLjY1LTEuMzUtMy0zLTNTOSAzLjM1IDkgNWMwIDEuMy44NCAyLjQgMiAyLjgyVjlIOHYyaDN2OC45MmMtMi4yMi0uMzMtNC41OS0xLjY4LTUuNTUtMy4zN0w3IDE1bC00LTN2M2MwIDMuODggNC45MiA3IDkgN3M5LTMuMTIgOS03di0zbC00IDN6TTEyIDRjLjU1IDAgMSAuNDUgMSAxcy0uNDUgMS0xIDEtMS0uNDUtMS0xIC40NS0xIDEtMXoiPjwvcGF0aD4KPC9zdmc+Cg==";function VI(n,t,e){W(e,"editor-box-anchor"),pm(zI,[],e)}const A6={boxType:"anchor",updateBoxContent:VI};function WI(n,t,e,o){w("span",[],e,o.text)}const b6={insertionType:"inputting",updateInsertionContent:WI},v6=S("editor-insertion");class y6{constructor(t){m(this,"insertions",new Map);this.editor=t}registerInsertionClass(t){const e=t.insertionType,o=this.insertions.get(e);g(v6,!o,`duplicated insertion type: ${e}`),this.insertions.set(e,t)}getInsertionClass(t){const e=this.insertions.get(t);return g(v6,e,`unknown insertion type: ${t}`),e}createInsertion(t,e){const o=ZC(e.type,e.id),r=YC(o);return this.getInsertionClass(e.type).updateInsertionContent(this.editor,o,r,e),o}}class qI{constructor(t){m(this,"cursors",new Map);m(this,"timer");this.editor=t,this.timer=this.startTimer()}add(t,e){this.cursors.set(t,e)}startTimer(){return setInterval(()=>{const t=Date.now();Array.from(this.cursors).forEach(([e,o])=>{if(t-o>3e3){const r=QC(this.editor,e);r&&ot(r,"active"),this.cursors.delete(e)}})},1e3)}destroy(){clearInterval(this.timer)}}function GI(n,t,e,o){var l;const r=o;Date.now()-r.time<5*1e3&&(n.addCustom("active-cursors",d=>new qI(d)).add(r.id,r.time),W(t,"active")),w("span",[],e,"|").setAttribute("data-cursor-name",r.name),t.style.setProperty("--cursor-color",n.getColor((l=r.rainbowIndex)!=null?l:0))}const vg={insertionType:"remote-cursor",updateInsertionContent:GI};class k6{constructor(t){m(this,"decorators",[]);this.editor=t}registerDecorator(t){this.decorators.push(t)}decorateBlock(t,e){let o=e;return this.decorators.forEach(r=>{if(r.decorateBlock){const i=r.decorateBlock(this.editor,t,e);i&&(o=mt.default(i))}}),o}decorateText(t,e){let o=e;const r=new Map;return this.decorators.forEach(i=>{if(i.decorateText){const s=i.decorateText(this.editor,t,e);if(s){const{insertions:l,text:a}=s;l&&Array.from(l.entries()).forEach(([d,h])=>{const p=r.get(d);p?p.push(...h):r.set(d,h)}),a&&(o=mt.default(a))}}}),{insertions:r,text:o}}}const yg=S("editor-input");class ZI{constructor(t,e){m(this,"editor");m(this,"composing",!1);m(this,"callbacks");m(this,"inputElement");m(this,"handleDocumentClick",t=>{const e=this.editor.rootContainer,o=t.target;if(o&&e.contains(o)&&!Ss(o)){this.editor.emit("focus",this.editor),this.callbacks.onFocus(),this.editor.input.focus();return}this.editor.emit("blur",this.editor),this.callbacks.onBlur()});m(this,"handleDocumentSelectionChange",()=>{setTimeout(()=>{var e;const t=(e=document.getSelection())==null?void 0:e.focusNode;t&&this.editor.contains(t)&&!Ss(t)||(this.editor.emit("blur",this.editor),this.callbacks.onBlur())},100)});m(this,"handleEditorSelectionChanged",()=>{const e=!this.editor.isWritable();this.inputElement.readOnly=e});m(this,"handleReadonlyChanged",()=>{this.handleEditorSelectionChanged()});m(this,"handleCompositionstart",t=>{!this.editor.isWritable()||(this.composing=!0,this.callbacks.onCompositionStart(t))});m(this,"handleCompositionend",t=>{this.composing=!1,this.callbacks.onUpdateCompositionText(t,this.inputElement.value,!0),this.inputElement.value=""});m(this,"handleInput",t=>{if(t instanceof InputEvent&&!!t.data){if(this.editor.readonly||!this.editor.isWritable()){this.inputElement.value="";return}this.composing?this.callbacks.onUpdateCompositionText(t,t.data,!1):(this.callbacks.onInsertText(t,t.data),this.inputElement.value="")}});m(this,"handleKeyDown",t=>{if(!this.composing){if(this.callbacks.onKeyDown(t)){t.preventDefault(),t.stopPropagation();return}!this.editor.isWritable()||setTimeout(()=>{this.composing||(this.inputElement.value="")})}});m(this,"handleCopy",t=>{this.callbacks.onCopy(t)});m(this,"handleCut",t=>{if(this.editor.readonly){t.stopPropagation(),t.preventDefault();return}this.callbacks.onCut(t),yg.debug("on cut")});m(this,"handlePaste",t=>{if(this.editor.readonly){t.stopPropagation(),t.preventDefault();return}this.callbacks.onPaste(t)});m(this,"handlePasteText",(t,e)=>{this.callbacks.onPasteText(t,e)});this.editor=t,this.callbacks=e;const o=w("input",["editor-input"],t.contentElement);o.type="text",o.name="editor-input",o.onkeydown=this.handleKeyDown,o.oninput=this.handleInput,o.oncopy=this.handleCopy,o.onpaste=this.handlePaste,o.oncut=this.handleCut,o.addEventListener("compositionstart",this.handleCompositionstart),o.addEventListener("compositionend",this.handleCompositionend),this.inputElement=o,document.addEventListener("click",this.handleDocumentClick),document.addEventListener("selectionchange",this.handleDocumentSelectionChange),this.editor.addListener("selectionChanged",this.handleEditorSelectionChanged),this.editor.addListener("readonlyChanged",this.handleReadonlyChanged)}destroy(){this.callbacks.destroy(),document.removeEventListener("click",this.handleDocumentClick),document.removeEventListener("selectionchange",this.handleDocumentSelectionChange),this.editor.removeListener("selectionChanged",this.handleEditorSelectionChanged),this.editor.removeListener("readonlyChanged",this.handleReadonlyChanged);const t=this.inputElement;t.removeEventListener("compositionstart",this.handleCompositionstart),t.removeEventListener("compositionend",this.handleCompositionend),t.onkeydown=null,t.oninput=null,t.oncopy=null,t.onpaste=null,t.oncut=null}getInput(){return this.inputElement}focus(){this.editor.selection.caret.visible()||this.editor.selection.caret.update(),Ze.isMobileSafari?this.inputElement.focus():setTimeout(()=>{this.inputElement.focus()})}handleChanged(t){this.callbacks.onChanged(t)}handleRemoteChanged(t){this.callbacks.onRemoteChanged(t)}addHandler(t){this.callbacks.addHandler(t)}removeHandler(t){this.callbacks.removeHandler(t)}defaultInsertText(t,e,o,r,i){g(yg,t===this.editor,"invalid editor"),this.callbacks.defaultInsertText(t,e,o,r,i)}defaultHandleKeydown(t,e){return g(yg,t===this.editor,"invalid editor"),this.callbacks.defaultHandleKeydown(t,e)}}function w6(n){const t=n.rootElement,e=t.getBoundingClientRect(),o=ys(t),r=window.innerWidth,i=window.innerHeight,s=e.left<0?0:e.left,l=e.top<0?0:e.top,a=e.right>r?r:e.right,d=e.bottom>i?i:e.bottom,h=(s+a)/2,p=(l+d)/2,A=0-e.left+h,v=0-e.top+p,B=n.input.inputElement;B.style.left=`${A/o}px`,B.style.top=`${v/o}px`}const kg=S("editor-caret");class QI{constructor(t){m(this,"editor");m(this,"caretElem");m(this,"handleReadOnlyChanged",()=>{this.update()});this.editor=t,this.caretElem=w("div",["editor-cursor"],this.editor.contentElement),this.editor.on("readonlyChanged",this.handleReadOnlyChanged)}destroy(){this.editor.off("readonlyChanged",this.handleReadOnlyChanged)}visible(){const t=window.getComputedStyle(this.caretElem);return t.display!=="none"&&t.opacity!=="0"}hasCaret(){if(this.editor.readonly||!this.editor.selection.range.isCollapsed())return!1;const t=this.editor.selection.range.start;if(!(t instanceof je))return!1;const e=this.editor.getBlockById(t.blockId);return!!tt(this.editor,e)}update(){if(nC(this.editor.rootElement))return;const t=this.caretElem;if(this.hasCaret())t.style.display="";else{t.style.display="none",w6(this.editor);return}const{range:e}=this.editor.selection;g(kg,e.isCollapsed,"range is not collapsed");const o=e.start;g(kg,o instanceof je,"only simple block position can has caret");const r=this.editor.getBlockById(o.blockId);g(kg,tt(this.editor,r),"only text kind block can has caret");let i;const s=r.querySelector("span.inputting-insertion");s?(i=bs(s),i=new DOMRect(i.right,i.top,1,i.height)):i=Vn(r,o);const l=this.editor.contentElement.getBoundingClientRect(),a=i.left-l.left,d=i.top-l.top;t.style.left=`${a}px`,t.style.top=`${d}px`,t.style.height=`${i.height}px`;const h=this.editor.input.inputElement;h.style.left=`${a}px`,h.style.top=`${d+i.height-24}px`,Ze.isMobileSafari&&(h.style.left=`${a-4}px`,h.style.height=`${i.height}px`);const A=ro(r,{horizontal:!0}).getBoundingClientRect(),v=A.left-l.left,B=v+A.width;a<v||a>B?(w6(this.editor),t.style.display="none"):t.style.display=""}}function YI(n){e4(n),n.selection.range.getSelectedBlocks().forEach(t=>n4(n,t.block,t.start,t.end))}const JI=S("editor-dom");function B6(n){return ro(n.rootContainer).clientHeight}function KI(n){return n.getFirstBlock().getBoundingClientRect().top}function XI(n){return n.getLastBlock().getBoundingClientRect().bottom}function wg(n){const e=ro(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 tT(n,t){const e=wg(n),o=n.getBlockById(t.blockId),i=So(n,o,t);return ks(e,i.x,i.y)&&ks(e,i.right,i.bottom)}function E6(n,t){const e=wg(n),o=t.getBoundingClientRect();return o.top>=e.top&&o.top<=e.bottom||o.bottom<=e.bottom&&o.bottom>=e.top}function eT(n,t){const e=wg(n),o=t.getBoundingClientRect();return ks(e,o.x,o.y)||ks(e,o.right,o.bottom)}function nT(n){if(!vm(n.rootContainer)){JI.warn("editorScrollIntoView: editor is not visible");return}const t=n.rootContainer.getBoundingClientRect();if(t.height<1&&t.width<1)return;const e=n.selection,o=e.range.focus;if(!o.isSimple()){const h=o,p=n.getContainerById(h.childContainerId);eT(n,p)||p.scrollIntoView();return}if(e.range.start.blockId===e.range.end.blockId){const h=n.getBlockById(e.range.start.blockId);if(Me(h)&&E6(n,h)||Mt(n,h)&&E6(n,h))return}const r=o,i=n.getBlockById(r.blockId);if(tT(n,r))return;const s=So(n,i,r),l=i.getBoundingClientRect(),a=te(i),d=w("div",["editor-block-anchor"],a);d.style.top=`${s.top-l.top}px`,ym(d,{elementToScroll:ro(n.rootContainer)}),setTimeout(()=>{d.remove()},200)}function oT(n,t){if(t.isCollapsed())return!1;const e=xe(n.rootContainer),o=Qe(n.rootContainer),{start:r,end:i}=t;return r.blockId===it(e)&&r.offset===0&&i.blockId===it(o)&&i.offset===ut(n,o)}const x6=S("range-in-block");function I6(n,t){const e=t.getEditor(),o=e.getBlockById(t.start.blockId),r=e.getBlockById(t.end.blockId),i=o===n||Xt(n,o),s=r===n||Xt(n,r);return!!(i||s)}function T6(n,t){const e=n.doc.toJSON(),o=new Set(Object.values(e.blocks).map(s=>s.map(l=>l.id)).flat());let r,i=ce(t);if(i){for(;i&&!o.has(it(i));)i=ce(i);g(x6,i,"no prev block while deleting a block"),r=Ce(n,i,ut(n,i))}else{const s=Zt(t);g(x6,s,"no prev and next block while deleting a block"),r=Ce(n,s,0)}return r}const rT=S("block-to-html");function Bg(n,t,e,o){const r=Ls(n,t.type);if(r.convertTo)return r.convertTo(n,t,e,"html",o);if(r.blockKind!=="text")return`[${t.type}]`;g(rT,t.text,"no text");const i=ie(t.text);return`<div>${sC(i)}</div>`}const D6=S("block-to-text");function iT(n,t,e){let o="";return t.forEach(r=>{if(g(D6,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 vh(n,t,e,o){const r=Ls(n,t.type);return r.convertTo?r.convertTo(n,t,e,"text",o):r.blockKind!=="text"?`[${t.type}]`:(g(D6,t.text,"no text"),iT(n,t.text,e))}function Eg(n,t,e,o){const r=Ls(n,t.type);return r.convertTo?r.convertTo(n,t,e,"markdown",o):vh(n,t,e,o)}function yh(n,t){return t.blocks.root.map((r,i)=>Bg(n,r,t,[{containerId:"root",blockIndex:i}])).join(`
|
|
25
25
|
`)}function S6(n,t){return`<!doctype html><html><head><meta charset="utf8" /></head><body>${yh(n,t)}</body></html>`}function Ma(n,t){return t.blocks.root.map((r,i)=>vh(n,r,t,[{containerId:"root",blockIndex:i}])).join(`
|
|
26
26
|
`)}function Ra(n,t){const e=t.blocks.root.map((r,i)=>Eg(n,r,t,[{containerId:"root",blockIndex:i}]));return e[e.length-1]=e[e.length-1].trimEnd(),e.join(`
|
|
27
|
-
`)}const sT=S("get-text-position");function ql(n,t){const e=t!=null?t:n.selection.range.start;e instanceof je||g(sT,!1,`invalid insert pos type: ${typeof e}`);const{blockId:o}=e,r=n.getBlockById(o),i=bt(r),s=nt(r),l=at(s),{offset:a}=e;return{block:r,container:s,containerId:l,blockIndex:i,offset:a}}const Gl=S("insert-text");function xg(n,t,e,o){var s;const r=n.doc.getBlockData(t,e);if(g(Gl,r,"no block data"),g(Gl,r.text,"no block text"),rn(r.text)===0)return g(Gl,o===0,"invalid text offset"),n.editorCommandProviders.getEmptyBlockTextAttributes(n,r.id);if(o===0)return;const i=ze(r.text,o-1,1).middle;if(!((s=i[0].attributes)!=null&&s.box))return i[0].attributes}function lT(n,t,e){const o=nt(t),r=at(o),i=bt(t);return xg(n,r,i,e)}function L6(n,t,e,o,r){const i=nt(t),s=at(i),l=bt(t),a=lT(n,t,e),d=uh(e,o,a!=null?a:null);return n.doc.localUpdateBlockText(s,l,d,r),gn(n,t)}function M6(n,t,e,o){const r=nt(t),i=at(r),s=bt(t),l=uh(e," ",o);return n.doc.localUpdateBlockText(i,s,l),gn(n,t)}function cT(n,t){let e=0;if(t===0)return!1;for(let o=0;o<n.length;o++){const r=n[o];g(Gl,typeof r.insert=="string","invalid text op, no insert");const i=e+dh(r);if(i===t)return!1;if(i>t)return!0;e=i}return!1}function Ig(n,t,e,o,r){const i=n.doc.getBlockData(e,o);g(Gl,i,"no block data"),g(Gl,i.text,"no block text");const s=xg(n,e,o,r);s&&Object.keys(s).includes("link")&&(cT(i.text,r)||delete s.link);const l=uh(r,t,s!=null?s:null);return n.doc.localUpdateBlockText(e,o,l),gn(n,n.getBlockById(i.id))}function Tg(n,t){n.selection.range.isCollapsed()||n.clearSelectedContents();const{containerId:e,blockIndex:o,offset:r}=ql(n);Ig(n,t,e,o,r)}const kh=S("update-composition-text");function R6(n){const t=n.selection.range.start;t instanceof je||g(kh,!1,`invalid insert pos type: ${typeof t}`);const{blockId:e}=t,o=n.getBlockById(e);g(kh,tt(n,o),"not a text kind block");const r=nt(o),i=at(r),s=bt(o),l=n.doc.getBlockData(i,s);g(kh,l,"no block data in doc"),g(kh,l.text,"no text data in text block");const a=Lt(o);sh(n,Li(o),e,a,l.text)}function O6(n){$x(n)}function Zl(n,t,e,o,r,i){return n.doc.localInsertBlock(t,e,o,r,i),n.getBlockById(o.id)}const Oa=S("delete-block-text");function Dg(n,t,e,o,r){if(!n.isBlockWritable(t))return Oa.error("block is not writable"),0;g(Oa,tt(n,t),"block is not a text kind block");const i=nt(t),s=at(i),l=bt(t),a=n.doc.getBlockData(s,l);g(Oa,a,"no block data in doc"),g(Oa,a.text,"no text data in text block");let d=e;sn(t,e)||(d=Ri(t,d));let h=e+o;g(Oa,h<=ut(n,t),`invalid offset and count: ${e}, ${o}`),sn(t,h)||(h=Fs(t,h));const p=h-d,A=V4(d,p);return n.doc.localUpdateBlockText(s,l,A,r),p}const Sg=S("break-text-block");function _6(n,t){const o=n.getBlockData(t).quoted;return o?{quoted:o}:{}}function Ql(n,t,e,o){g(Sg,tt(n,t),`block is not a text kind block: ${Dt(t)}`),g(Sg,e>=0&&e<=ut(n,t),`invalid offset: ${e}`);const r=nt(t),i=at(r),s=bt(t),l=o!=null&&o.copyBlockAttributes?_6(n,t):{};if(!(o!=null&&o.forceInsertAfter)&&(e===0||e===ut(n,t))){const v=e===0?s:s+1,B={...lr(""),...l,...o==null?void 0:o.newBlockData},D=Ce(n,t.id,0),x=Zl(n,i,v,B,D);return{block:t,newBlock:x}}g(Sg,sn(t,e),"not a valid offset");const a=gn(n,t),{right:d}=In(a,e),h=rn(d);h>0&&Dg(n,t,e,h);const p={...lr(d),...l,...o==null?void 0:o.newBlockData},A=Zl(n,i,s+1,p,Ce(n,p.id,0));return{block:t,newBlock:A}}const aT=S("prepare-insert-new-block");function uT(n,t,e){if(t&&e!==void 0&&e!==null){const d=n.getContainerById(t),h=pe(d);return g(aT,e>=0&&e<=h.length,`invalid blockIndex: ${e}`),{containerId:t,blockIndex:e}}const o=n.selection.range.start;if(!o.isSimple())return null;const r=n.getBlockById(o.blockId);if(t=at(nt(r)),e=bt(r),!tt(n,r))return{containerId:t,blockIndex:e+1};const s=o.offset;if(s===0||s===ut(n,r))return{containerId:t,blockIndex:s===0?e:e+1};const a=Ql(n,r,s).newBlock;return{containerId:t,blockIndex:bt(a)}}const dT=S("auto-insert-block");function F6(n,t,e,o,r,i){const s=uT(n,e,o);g(dT,s,`not an valid insert position: ${n.selection.range}`);const l={blockId:t.id,offset:0},a={anchor:l,focus:l};return Zl(n,s.containerId,s.blockIndex,t,r!=null?r:a,i)}const hT=S("delete-block");function wh(n,t,e){t.children&&(e.push(...t.children),t.children.forEach(o=>{n.getChildContainerData(o).forEach(i=>{wh(n,i,e)})}))}function Bh(n,t,e){const o=nt(t),r=at(o),i=bt(t),s=n.doc.getBlockData(r,i);return g(hT,s,"no block data in doc"),n.doc.localDeleteBlock(r,i,Ue(n,{anchor:e.start,focus:e.end})),s}function Lg(n,t,e){return n.undoManager.runInGroup(()=>{const o=nt(t);Io(o)===1&&n.insertTextBlock("",at(o),0);let r=e?Mi(n,e):null;if(!r){const l=n.selection.range;I6(t,l)?r=T6(n,t):r=l}const i=Bh(n,t,r),s=[];return wh(n,i,s),s.length>0&&n.doc.localDeleteChildContainers(s),i})}function fT(n,t){const e=[t];n.doc.getContainerBlocks(t).forEach(r=>{wh(n,r,e)}),n.doc.localDeleteChildContainers(e)}function P6(n,t){const e=[...t];t.forEach(o=>{n.doc.getContainerBlocks(o).forEach(i=>{wh(n,i,e)})}),n.doc.localDeleteChildContainers(e)}const Mg=S("merge-text-block");function N6(n,t,e){g(Mg,tt(n,t),"only text block can be merged"),g(Mg,tt(n,e),"only text block can be merged");const o=_i(n,t),r=_i(n,e),i=o.text,s=r.text;g(Mg,i&&s,"block data has no text");const l=nt(t),a=at(l),d=bt(t),h=ut(n,t),p=Ig(n,s,a,d,h),A=Ce(n,t,rn(i));return Lg(n,e,A),p}const cr=S("clear-selected-contents");function Eh(n,t){g(cr,tt(n,t.block),"not a text kind block");const{start:e,end:o}=t;g(cr,e.isSimple(),"not a simple block position"),g(cr,o.isSimple(),"not a simple block position");const r=e.offset,i=o.offset;g(cr,r<=i,`invalid delete text offset: ${r}, ${i}`),r!==i&&n.deleteTextFromBlock(t.block,r,i-r)}function $6(n,t,e){const o=at(t),r=pe(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 mT(n,t){const{block:e,start:o,end:r}=t;if(tt(n,e)){Eh(n,t);return}if(Me(e)||o.isSimple()){g(cr,r.isSimple(),"invalid range");const s=nt(e),l=bt(e),a=n.insertTextBlock("",at(s),l);n.selection.selectBlock(a,0),n.deleteBlock(e);return}g(cr,Mt(n,e),"invalid block kind"),g(cr,!o.isSimple()&&!r.isSimple(),"invalid range"),Rs(n,e,o,r),n.selection.range.getSelectedContainers().forEach((s,l)=>{$6(n,s,{focus:l===0})})}function gT(n){if(!n.isWritable())return;const t=n.selection.range;if(t.isCollapsed())return;const e=t.getSelectedBlocks();if(g(cr,e.length>0,"no selected block"),e.length===1){mT(n,e[0]);return}const o=e[0],r=o.block,i=nt(r);g(cr,e.length>1,"no selected block");const s=e[e.length-1],l=s.block;if(tt(n,r)){Eh(n,o);const h=Ce(n,o.block,o.start.offset);if(e.slice(1,e.length-1).reverse().forEach(A=>n.deleteBlock(A.block)),tt(n,l)){Eh(n,s),n.mergeTextBlock(r,l,{focus:!0}),n.selection.setRange(h);return}n.deleteBlock(l),n.selection.setRange(h);return}if(tt(n,l)){Eh(n,s),e.slice(0,e.length-1).reverse().forEach(h=>n.deleteBlock(h.block)),n.selection.selectBlock(s.block,0);return}if(e.length===Io(i)){$6(n,i,{focus:!0});return}const a=ce(r),d=Zt(l);g(cr,a||d,"no prev or next block"),e.forEach(h=>n.deleteBlock(h.block))}function Rg(n){n.selection.range.isCollapsed()||n.undoManager.runInGroup(()=>{n.emit("beforeClearSelection",n);try{n.doc.beginBatchUpdate(),gT(n)}finally{n.doc.endBatchUpdate()}n.emit("afterClearSelection",n)})}const pT=S("core");function H6(n,t,e){const o=nt(t),r=at(o),i=bt(t);return n.doc.localUpdateBlockText(r,i,e),setTimeout(()=>{n.selection.updateSelection(null)}),gn(n,t)}function j6(n,t,e){if(!n.isBlockWritable(t)){pT.error("block is not writable");return}const o=n.getBlockText(t),r=ln.diff(o,e);H6(n,t,r)}function xh(n,t,e){const o=gn(n,t),r=typeof e=="string"?Oi(e):e,i=ln.diff(o,r);return H6(n,t,i)}const _a=S("update-block-data");function Ih(n,t,e,o){const r=nt(t),i=at(r),s=bt(t),l=n.doc.getBlockData(i,s),a={insert:{},delete:[]},d=new Set(Object.keys(l)),h=new Set(Object.keys(e));return d.forEach(A=>{if(!h.has(A)){if(A==="id"||A==="type"||A==="text")return;_a.debug(`delete key: ${A}`),a.delete.push(A)}}),Object.entries(e).forEach(([A,v])=>{g(_a,A!=="id"&&A!=="type",`invalid block data delta, ${A}`);const B=l[A];if(v==null){B!=null&&(_a.debug(`delete key: ${A}`),a.delete.push(A));return}B!==v&&(aa.default(B,v)||A==="text"&&ln.diff(B,v).length===0||(d.has(A)?(_a.debug(`replace key: ${A}`),a.delete.push(A)):_a.debug(`insert key: ${A}`),a.insert[A]=v))}),n.doc.localUpdateBlockData(i,s,a,o),_i(n,t)}function U6(n,t,e,o){const i={...n.getBlockData(t),embedData:e};return n.updateBlockData(t,i,o)}function Og(n,t,e){if(!Mt(n,t)||!(e!=null&&e.tryFocusToChildSimpleBlock)){n.selection.selectBlock(t,0);return}const r=zn(n,t).getChildContainers(n,t)[0],i=xe(r);Og(n,i,e)}function $s(n){const t=[];let e={};return n.forEach(o=>{t.push(...o.blocks.root);const{root:r,...i}=o.blocks;e={...e,...i}}),{blocks:{...e,root:t},meta:{},comments:{}}}const Fa=S("clone-block");function Fi(n,t,e,o){const r=n.getBlockClass(e.type);if(r.blockToDoc)return r.blockToDoc(t,e,(h,p)=>(g(Fa,e!==p,"invalid child block"),Fi(n,h,e,o)));let i={};const s=new Map,l=mt.default(e);l.children&&(l.children=l.children.map(h=>{const p=K(),A=t.blocks[h];g(Fa,Array.isArray(A),"invalid child blocks");const v=A.map(_=>Fi(n,t,_,o)),B=$s(v),{root:D,...x}=B.blocks;return i={...i,...x},i[p]=B.blocks.root,s.set(h,p),p}));const a=Array.from(s.entries()),d=h=>{for(const p of a){const[A,v]=p;{const B=`${A}/`;if(h.startsWith(B)){const D=h.substring(B.length),x=`${v}/${D}`;return Fa.debug(`replace key: ${h} -> ${x}`),x}}{const B=`${A}_`;if(h.startsWith(B)){const D=h.substring(B.length),x=`${v}_${D}`;return Fa.debug(`replace key: ${h} -> ${x}`),x}}}return h};return Array.from(Object.entries(l)).forEach(([h,p])=>{const A=d(h);A!==h&&delete l.key,l[A]=p}),l.id=K(),o&&(o.blockIdMap.set(e.id,l.id),s.forEach((h,p)=>o.containerIdMap.set(p,h))),{blocks:{root:[l],...i},meta:{},comments:{}}}function _g(n,t,e,o){const r=t.blocks[e];g(Fa,Array.isArray(r),"invalid child blocks");const i=r.map(l=>Fi(n,t,l,o));return $s(i)}function Fg(n,t,e){const o=t.blocks.root.map(r=>Fi(n.editorBlocks,t,r,e));return mt.default($s(o))}const z6=S("insert-doc");function V6(n,t,e,o,r){if(Mt(n,t)){z6.warn("failed to insert doc into a complex block");return}const i=Fg(n,o,r),s=nt(t),l=bt(t),a=at(s);n.doc.beginBatchUpdate(),n.undoManager.runInGroup(()=>{var M,H,z;Object.entries(i.blocks).forEach(([q,rt])=>{q!=="root"&&n.doc.localInsertChildContainer(q,rt)});const d=i.blocks.root;if(Me(t)){n.deleteBlock(t);let q;d.reverse().forEach(rt=>{const ft=n.insertBlock(a,l,rt,void 0,{noFocus:!0});q||(q=ft)}),q&&n.selection.selectBlock(q,ut(n,q));return}if(g(z6,tt(n,t),"not a text block"),he(n,t)){const q=a==="root"&&n.getBlockByIndex(a,0)===t,rt=bt(t);let ft;d.forEach((Bt,jt)=>{const Ut=n.insertBlock(a,rt+jt,Bt,void 0,{noFocus:!0});jt===d.length-1&&(ft=Ut)}),ft&&n.selection.selectBlock(ft,ut(n,ft)),q&&n.deleteBlock(t);return}if(d.length===1){const q=d[0];if(ya(n,q.type)){n.insertTextToBlock(t,e,(M=q.text)!=null?M:[]);return}n.breakTextBlock(t,e),n.insertBlock(a,l+1,q);return}const h=e===ut(n,t),p=e===0,A=d[0],v=d[d.length-1];let B;!h&&!p?B=n.breakTextBlock(t,e,{forceInsertAfter:!0}):B=t;const D=p?l:l+1;h?(B=n.insertBlock(a,l+1,v),n.selection.selectBlock(B,ut(n,B))):(n.selection.selectBlock(B,0),ya(n,v.type)?n.insertTextToBlock(B,0,(H=v.text)!=null?H:[]):n.insertBlock(a,D,v));const x=n.selection.range;let _=D;ya(n,A.type)?p?(n.insertBlock(a,D,A),_+=1):n.insertTextToBlock(t,e,(z=A.text)!=null?z:[]):(n.insertBlock(a,D,A),_+=1),d.slice(1,d.length-1).reverse().forEach(q=>{n.insertBlock(a,_,q)}),n.selection.setRange(x)}),n.doc.endBatchUpdate()}function Pg(n,t,e,o,r){const i=Fg(n,o,r),s=at(t),l=[];return n.undoManager.runInGroup(()=>{Object.entries(i.blocks).forEach(([d,h])=>{d!=="root"&&n.doc.localInsertChildContainer(d,h)}),i.blocks.root.reverse().forEach(d=>{const h=n.insertBlock(s,e,d);l.push(h)})}),l}function W6(n,t,e){const o=Io(t);Pg(n,t,o,e);for(let r=0;r<o;r++){const i=xe(t);n.deleteBlock(i)}}const Pa=S("add-text-attribute");function CT(n,t,e,o){const{start:r,end:i}=e;g(Pa,r.blockId===i.blockId&&r.blockId===it(t),"invalid range"),g(Pa,o,"invalid attribute name");const s=n.getBlockText(t),l=Wl(r.offset,i.offset-r.offset,s,o,void 0,{ignoreValue:!0});return n.setBlockText(t,l),l}function q6(n,t,e,o,r){const{start:i,end:s}=e;g(Pa,i.blockId===s.blockId&&i.blockId===it(t),"invalid range"),g(Pa,o,"invalid attribute name");const l=n.getBlockText(t),a=Ta(i.offset,s.offset-i.offset,l,o,r);return n.setBlockText(t,a),a}function Yl(n,t,e,o,r){const{start:i,end:s}=e;g(Pa,i.blockId===s.blockId&&i.blockId===it(t),"invalid range");const l=n.getBlockText(t),a=X4(i.offset,s.offset-i.offset,l,o,r);return n.setBlockText(t,a),a}function G6(n,t,e,o){const r=Ro(n,{simpleBlockOnly:!0});n.undoManager.runInGroup(()=>{r.forEach(i=>{const{block:s,start:l,end:a}=i;if(!tt(n,s))return;if(he(n,s)){o(n,it(s),t,e);return}const d=Ue(n,{anchor:l,focus:a});t==="color"||t==="backgroundColor"?Yl(n,s,d,t,e):(Yl(n,s,d,"color",null),Yl(n,s,d,"backgroundColor",null))})})}function Z6(n,t,e){const o=Ro(n,{simpleBlockOnly:!0});n.undoManager.runInGroup(()=>{o.forEach(r=>{const{block:i,start:s,end:l}=r;if(!tt(n,i))return;if(he(n,i)){(t==="clearColor"||t==="clearAll")&&e(n,it(i),"color",null),(t==="clearBackground"||t==="clearAll")&&e(n,it(i),"backgroundColor",null);return}const a=Ue(n,{anchor:s,focus:l});(t==="clearColor"||t==="clearAll")&&Yl(n,i,a,"color",null),(t==="clearBackground"||t==="clearAll")&&Yl(n,i,a,"backgroundColor",null)})})}function Ng(n,t){const e=Ro(n,{simpleBlockOnly:!0}).filter(s=>tt(n,s.block));if(e.length===0)return[null,null];const o=s=>{if(ut(n,s.block)===0)return t(n,it(s.block));const l=s.start,a=s.end,d=n.getBlockText(s.block);return n6(l.offset,a.offset-l.offset,d)};let[r,i]=o(e[0]);return r===null&&i===null?[r,i]:(e.forEach(s=>{const[l,a]=o(s);l===null||r===null?r=null:r=l===r?r:null,a===null||i===null?i=null:i=a===i?i:null}),[r,i])}const Wn=S("adjust-selection-pos");function Q6(n){const t=[];for(;n;){const e=nt(n);if(t.unshift(e),Yt(e))return t;const o=et(e);g(Wn,o,"child container has not parent container"),n=o}g(Wn,!1,"should not come here: getParentContainers")}function Y6(n,t){for(;t;){const e=nt(t);if(e===n)return t;const o=et(e);g(Wn,o,"could not find parent block for a child container"),t=o}g(Wn,!1,"no parent block in specified container")}function AT(n,t){const e=Q6(n),o=Q6(t);g(Wn,e.length>0&&o.length>0,"block has not parent container"),g(Wn,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=Y6(r,n),s=Y6(r,t);return{parentContainer:r,newBlock1:i,newBlock2:s}}function J6(n,t){let e=et(t);for(g(Wn,e,"element is not in a block");e;){const o=nt(e);g(Wn,Lo(o),"not a child container");const r=et(o);if(g(Wn,r,"child container has not parent block"),r===n)return o;e=r}g(Wn,!1,"failed to find parent container in complex block")}function Th(n,t,e){const o=n.getBlockById(t.blockId),r=n.getBlockById(e.blockId);if(o===r)return t instanceof je&&e instanceof je?{anchor:t,focus:e}:t instanceof Mo&&e instanceof Mo?rh(n,o,t,e):null;const i=nt(o),s=nt(r);if(i===s)return t instanceof Mo&&(t=st(o,0,"home")),e instanceof Mo&&(e=st(r,ut(n,r),"end")),g(Wn,t instanceof je,"not valid position type"),g(Wn,e instanceof je,"not valid position type"),{anchor:t,focus:e};if(o.contains(s))return null;if(r.contains(i)){if(t instanceof je&&e instanceof Mo){const B=n.getContainerById(e.childContainerId);if(B===i)return{anchor:e,focus:e};const D=et(i);if(D&&D===et(B)){const x=fe(D,at(i)),_=fe(D,at(B));return rh(n,D,x,_)}}return null}const l=jd(o,r)>0,{newBlock1:a,newBlock2:d}=AT(o,r);if(a===d){const B=a,D=J6(B,o),x=J6(B,r);return t=fe(a,at(D)),e=fe(a,at(x)),Wn.debug(`select in complex block: ${D.id}, ${x.id}`),rh(n,B,t,e)}let h=l?ut(n,a):0;a===o&&t instanceof je&&(h=t.offset);let A=l?0:ut(n,d);return d===r&&e instanceof je&&(A=e.offset),t=st(a,h,l?"end":"home"),e=st(d,A,l?"home":"end"),{anchor:t,focus:e}}const bT=S("move-complex-block-position");function vT(n,t,e){const o=n.getBlockById(t.blockId);g(bT,Mt(n,o),"is not a complex block");const r=zn(n,o),i=n.getContainerById(t.childContainerId),s=r.getNextContainer(n,o,i,e,{noWrap:!0});return s?fe(o,at(s)):null}const Na=S("move-simple-block-position");function K6(n,t){const e=xn(n,t,{visibleOnly:!0});g(Na,e.length>0,"complex block has not any child container");const o=e[0];return xe(o)}function X6(n,t){const e=xn(n,t,{visibleOnly:!0});g(Na,e.length>0,"complex block has not any child container");const o=e[e.length-1];return Qe(o)}function tA(n,t,e){const o=e?K6(n,t):X6(n,t);return Mt(n,o)?tA(n,o,e):o}function yT(n,t){const e=n.getBlockById(t.blockId);return Mt(n,e)&&t.offset===0?K6(n,e):Ds(e)}function kT(n,t){const e=n.getBlockById(t.blockId);return Mt(n,e)&&t.offset===1?X6(n,e):Ts(e)}function $g(n){return n==="ArrowLeft"||n==="ArrowUp"}function Hg(n,t,e){const o=nt(t);if(Yt(o))return null;const r=et(o);g(Na,r,"child container has not parent block"),g(Na,Mt(n,r),"is not a complex block");const i=zn(n,r).getNextContainer(n,r,o,e);return i?$g(e)?Qe(i):xe(i):Hg(n,r,e)}function wT(n,t,e){const o=nt(t);if(Yt(o))return null;const r=et(o);if(g(Na,r,"child container has not parent block"),$g(e)){const l=ce(r);if(l)return l}else{const l=Zt(r);if(l)return l}const i=Hg(n,r,e);if(i)return i;let s=r;for(;!Yt(nt(s));)s=et(nt(s));return $g(e)?ce(s):Zt(s)}function BT(n,t,e){return!Mt(n,t)||zn(n,t).enableKeyboardSelect?t:tA(n,t,e==="ArrowDown"||e==="ArrowRight")}function ET(n,t,e){const o=n.getBlockById(t.blockId),i=Qt(n,o).moveCaret(n,o,t,e);if(i)return i;let s=e==="ArrowDown"||e==="ArrowRight"?yT(n,t):kT(n,t);if(s||(s=Hg(n,o,e),s||(s=wT(n,o,e))),!s){if(e==="ArrowDown"||e==="ArrowRight"){if(n.readonly||!Yt(nt(o)))return null;const l=n.insertTextBlock("",at(n.rootContainer),Io(n.rootContainer));return st(l,0,"home")}return null}if(s=BT(n,s,e),tt(n,s)){const l=n.selection.getSuggestedCaretX();if(e==="ArrowDown")return Jx(n,s,o,t,l);if(e==="ArrowUp")return Yx(n,s,o,t,l)}return e==="ArrowLeft"||e==="ArrowUp"?st(s,ut(n,s),"end"):e==="ArrowRight"||e==="ArrowDown"?st(s,0,"home"):null}function xT(n,t,e){if(t==="ArrowLeft")return e.start;const o=e.end,r=n.getBlockById(o.blockId);if(tt(n,r))return o;const i=Zt(r);if(i)return st(i,0,"home");if(!Yt(nt(r))||n.readonly)return o;const s=n.insertTextBlock("",at(n.rootContainer),Io(n.rootContainer));return st(s,0,"home")}function IT(n,t,e){const o=n.selection.range;let r;if(o instanceof Ye)e==="move"&&!o.isCollapsed()&&(t==="ArrowLeft"||t==="ArrowRight")?r=xT(n,t,o):r=ET(n,o.getFocusedPos(),t);else if(r=vT(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=Qe(s);r=st(l,0,"home")}else{const l=xe(s);r=st(l,ut(n,l),"end")}}return r?e==="move"?{anchor:r,focus:r}:Th(n,o.anchor,r):null}function Pi(n,t,e){const o=IT(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 eA(n){return Pi(n,"ArrowLeft","move"),!0}function nA(n){return Pi(n,"ArrowRight","move"),!0}function oA(n){return Pi(n,"ArrowUp","move"),!0}function rA(n){if(Pi(n,"ArrowDown","move")||n.readonly)return!0;const t=n.getFocusedBlock(),e=nt(t);if(Yt(e)||Qe(e)!==t)return!0;const o=n.rootContainer;return n.insertTextBlock("",at(o),Io(o)),!0}function iA(n){return Pi(n,"ArrowDown","select"),!0}function sA(n){return Pi(n,"ArrowLeft","select"),!0}function lA(n){return Pi(n,"ArrowRight","select"),!0}function cA(n){return Pi(n,"ArrowUp","select"),!0}const aA=S("word-offset");function jg(n,t){const e=n.selection.range.focus;g(aA,e.isSimple(),"invalid range type");const o=n.getBlockById(e.blockId);if(he(n,o))return st(o,0,"home");if(e.offset===0||!tt(n,o)){const s=ce(o);if(!s)return null;const l=st(s,ut(n,s),"end");if(t==="select"&&tt(n,s)){const a=Ag(n,s,l.offset);return st(s,a,"normal")}return l}const r=Ag(n,o,e.offset);return st(o,r,"normal")}function Ug(n,t){const e=n.selection.range.focus;g(aA,e.isSimple(),"invalid range type");const o=n.getBlockById(e.blockId);if(he(n,o))return st(o,0,"end");if(e.offset===ut(n,o)||!tt(n,o)){const s=Zt(o);if(!s)return null;const l=st(s,0,"home");if(t==="select"&&tt(n,s)){const a=bg(n,s,l.offset);return st(s,a,"end")}return l}const r=bg(n,o,e.offset);return st(o,r,"normal")}function uA(n){if(!n.selection.range.focus.isSimple())return!1;const e=jg(n,"move");return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function dA(n){if(!n.selection.range.focus.isSimple())return!1;const e=Ug(n,"move");return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function hA(n){if(!n.selection.range.focus.isSimple())return!1;const e=jg(n,"select");return e?(n.selection.setSelection(n.selection.getAnchorPos(),e),n.selection.updateLastCaretRect(),!0):!1}function fA(n){if(!n.selection.range.focus.isSimple())return!1;const e=Ug(n,"select");return e?(n.selection.setSelection(n.selection.range.anchor,e),n.selection.updateLastCaretRect(),!0):!1}S("find-block");function zg(n,t){if(!Mt(n,t))return t;const o=zn(n,t).getChildContainers(n,t)[0],i=pe(o)[0];return zg(n,i)}function Vg(n,t){if(!Mt(n,t))return t;const e=zn(n,t).getChildContainers(n,t),o=e[e.length-1],r=pe(o),i=r[r.length-1];return Vg(n,i)}function mA(n){const t=Vg(n,Qe(n.rootContainer)),e=st(t,ut(n,t),"end");return n.selection.setSelection(e),!0}function gA(n){const t=zg(n,n.getFirstBlock()),e=st(t,0,"home");return n.selection.setSelection(e),!0}function pA(n){const t=zg(n,n.getFirstBlock()),e=st(t,0,"home");return n.selection.setSelection(n.selection.getAnchorPos(),e),!0}function Wg(n){const t=Vg(n,Qe(n.rootContainer)),e=st(t,ut(n,t),"end");return n.selection.setSelection(n.selection.getAnchorPos(),e),!0}const CA=S("line-offset");function AA(n){const t=n.selection.range.focus;g(CA,t.isSimple(),"invalid range type");const e=n.getBlockById(t.blockId);if(t.offset===0||!tt(n,e))return st(e,0,"home");let r=$4(e,t).start;const{next:i}=eh(e,r);return i&&so(i)&&va(i)==="br"&&(r+=1),st(e,r,"home")}function bA(n){const t=n.selection.range.focus;g(CA,t.isSimple(),"invalid range type");const e=n.getBlockById(t.blockId);if(t.offset===ut(n,e)||!tt(n,e))return st(e,ut(n,e),"end");const o=$4(e,t);return st(e,o.end,"end")}function vA(n){if(!n.selection.range.focus.isSimple())return!1;const e=AA(n);return e?(n.selection.setSelection(n.selection.getAnchorPos(),e),n.selection.updateLastCaretRect(),!0):!1}function yA(n){if(!n.selection.range.focus.isSimple())return!1;const e=bA(n);return e?(n.selection.setSelection(n.selection.getAnchorPos(),e),n.selection.updateLastCaretRect(),!0):!1}function kA(n){if(!n.selection.range.focus.isSimple())return!1;const e=AA(n);return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function wA(n){if(!n.selection.range.focus.isSimple())return!1;const e=bA(n);return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}const BA=S("find-block-position");function TT(n,t,e,o){g(BA,Mt(n,t),"is not a complex block");const r=zn(n,t).getChildContainers(n,t);g(BA,r.length>0,"complex block has not any child container");const i=So(n,e,o),s=i.left+i.width/2,l=i.top+i.height/2,a=T4(n,t,s,l);return qg(n,a,e,o)}function qg(n,t,e,o){if(Mt(n,t))return TT(n,t,e,o);const r=it(t);let i=Number.MAX_SAFE_INTEGER;const s=So(n,e,o),l=s.left+s.width/2,a=s.top+s.height/2;let d=st(r,0,"home");const h=ut(n,t);for(let p=0;p<=h;p++){const A=st(r,p,"normal"),v=So(n,t,A),B=nr(v,l,a);B<i&&(i=B,d=A)}return d}const EA=S("page-offset");function DT(n,t){const e=B6(n)*.9,r=t.getBoundingClientRect().bottom-e;if(r<KI(n))return n.getFirstBlock();const i=ce(t);if(!i)return n.getFirstBlock();let s=i;for(;s;){if(s.getBoundingClientRect().y<r)return s;s=ce(s)}return n.getFirstBlock()}function ST(n,t){const e=B6(n)*.9,o=t.getBoundingClientRect(),r=XI(n),i=o.top+e;if(i>r)return n.getLastBlock();const s=Zt(t);if(!s)return n.getLastBlock();let l=s;for(;l;){if(l.getBoundingClientRect().bottom>i)return l;l=Zt(l)}return n.getLastBlock()}function xA(n){const t=n.selection.range.focus;g(EA,t.isSimple(),"invalid range type");const e=n.getBlockById(t.blockId),o=DT(n,e);let r;return o===n.getFirstBlock()?r=st(o,0,"home"):r=qg(n,o,e,t),r}function IA(n){const t=n.selection.range.focus;g(EA,t.isSimple(),"invalid range type");const e=n.getBlockById(t.blockId),o=ST(n,e);let r;return o===n.getLastBlock()?r=st(o,ut(n,o),"end"):r=qg(n,o,e,t),r}function TA(n){if(!n.selection.range.focus.isSimple())return!1;const e=xA(n);return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function DA(n){if(!n.selection.range.focus.isSimple())return!1;const e=IA(n);return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function SA(n){if(!n.selection.range.focus.isSimple())return!1;const e=xA(n);if(!e)return!1;const o=Th(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 LA(n){if(!n.selection.range.focus.isSimple())return!1;const e=IA(n);if(!e)return!1;const o=Th(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 $a=S("select-all");function MA(n,t){const e=xe(n),o=Qe(n);return t.start.offset===0&&t.start.blockId===it(e)&&t.end.offset===ut(t.getEditor(),o)&&t.end.blockId===it(o)}function LT(n,t){const e=t.getEditor(),o=zn(e,n).getChildContainers(e,n),r=o[0],i=o[o.length-1],s=it(n);return t.start.blockId===s&&t.start.childContainerId===at(r)&&t.end.blockId===s&&t.end.childContainerId===at(i)}function MT(n,t){g($a,t,"no parent block"),g($a,Mt(n,t),"not a complex block");const e=zn(n,t).getChildContainers(n,t),o=e[0],r=e[e.length-1];n.selection.setRange(Ue(n,{anchor:fe(t,at(o)),focus:fe(t,at(r))}))}function RA(n,t){const e=nt(t);Gg(n,e)}function OA(n){const t=n.getFocusedBlock(),e=n.selection.range;if(e.start.isSimple()){if(e.start.blockId===e.end.blockId&&tt(n,t)){const r=e.start,i=e.end,s=ut(n,t);if(r.offset>0||i.offset<s)return n.selection.selectBlock(t,0,s),!1}return W(n.rootContainer,"select-all"),RA(n,xe(n.rootContainer)),!1}return g($a,!e.isSimple(),"invalid range type"),LT(t,e)?(RA(n,t),!1):(g($a,t,"no parent block"),g($a,Mt(n,t),"not a complex block"),MT(n,t),!0)}function Gg(n,t){const e=pe(t),o=e[0],r=e[e.length-1],i=st(o,0,"home"),s=st(r,ut(n,r),"end");n.selection.setSelection(i,s,{noScroll:!0})}function _A(n){Wg(n),n.focus()}const Zg=S("selected-block-to-doc");function FA(n,t,e){!t.children||t.children.forEach(o=>{const r=n.getChildContainerData(o);r.forEach(i=>{FA(n,i,e)}),e.blocks[o]=mt.default(r)})}function Dh(n,t){const e=Qt(n,t.block);if(e.selectionToDoc)return e.selectionToDoc(n,t);const o=mt.default(_i(n,t.block));if(tt(n,t.block)){const i=t.start,s=t.end;if(g(Zg,o.text,"no block text"),i.offset===s.offset)return{blocks:{root:[{...o,text:[]}]},meta:{},comments:{}};const{middle:l}=ze(o.text,i.offset,s.offset-i.offset);return{blocks:{root:[{...o,text:l}]},meta:{},comments:{}}}if(Me(t.block))return{blocks:{root:[o]},meta:{},comments:{}};g(Zg,Mt(n,t.block),"not complex block"),g(Zg,o.children,"no children");const r={blocks:{root:[o]},meta:{},comments:{}};return FA(n,o,r),r}function Qg(n,t){const e=st(t,0,"normal"),o=st(t,ut(n,t),"end");return Dh(n,{block:t,start:e,end:o})}const RT=S("block-to-doc");function OT(n,t){g(RT,t.length>0,"invalid params, no blocks");const e=t.map(o=>Qg(n,o));return $s(e)}function Sh(n){const e=n.selection.range.getSelectedBlocks().map(o=>Dh(n,o));return $s(e)}function PA(n,t){const e=n.getContainerById(t),i=pe(e).map(s=>({start:st(s,0,"home"),end:st(s,ut(n,s),"end"),block:s})).map(s=>Dh(n,s));return $s(i)}const Lh=S("editor-selection");class _T{constructor(t){m(this,"editor");m(this,"caret");m(this,"_range");m(this,"lastCaretRect");m(this,"handleBlockDelete",(t,e,o,r)=>{if(o||r.child)return;const i=this.range;if(I6(e,i)){Lh.debug("adjust selection because remote deleted current block");const s=T6(t,e);this.setRange(s,{noScroll:!0})}});this.editor=t;const e=t.getFirstBlock(),o=it(e);this.caret=new QI(t);const r=st(o,0,"normal");this._range=Ue(t,{anchor:r,focus:r}),this.lastCaretRect=null,this.editor.addListener("blockDeleted",this.handleBlockDelete),setTimeout(()=>{this.updateFocusedBlock(null)})}destroy(){this.caret.destroy()}get range(){return this._range}get focusedBlock(){return this.getFocusedBlock()}get startBlock(){return this.getStartBlock()}get endBlock(){return this.getEndBlock()}getFocusedBlock(){const t=this.range.focus;return this.editor.getBlockById(t.blockId)}getStartBlock(){const t=this.range.start;return this.editor.getBlockById(t.blockId)}getEndBlock(){const t=this.range.end;return this.editor.getBlockById(t.blockId)}selectBlock(t,e,o){const r=st(t,e,"normal");let i;o&&(i=st(t,o,"normal")),this.setSelection(r,i)}setSelection(t,e,o){if(e||(e=t),this.verifyPos(t),this.verifyPos(e),!this.selectionChanging(t,e))return this.range;const r=Ue(this.editor,{anchor:t,focus:e});if(this.range.isEqual(r))return this.range;const i=this._range;return this._range=r,this.selectionChanged(),this.updateFocusedBlock(i),xt(this.editor.rootContainer,"select-all")&&(!r.isSimple()||!oT(this.editor,r))&&ot(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(),YI(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(!Ur(t))return;const e=this.editor.getBlockById(t.blockId);this.lastCaretRect=So(this.editor,e,t)}getSuggestedCaretX(){var t;return(t=this.lastCaretRect)==null?void 0:t.x}scrollIntoView(){nT(this.editor)}verifyPos(t){const e=this.editor.getBlockById(t.blockId);if(t.isSimple())t.offset>=0&&t.offset<=ut(this.editor,e)||g(Lh,!1,"invalid block position, out of range");else{const o=t.childContainerId;!!this.editor.getContainerById(o)||g(Lh,!1,"invalid complex block position, no container found")}}updateFocusedBlock(t){if(t&&this.range.start.blockId===t.start.blockId)return;let e;t&&t.start.blockId===t.end.blockId&&(e=this.editor.findBlockById(t.start.blockId));let o;(this.range.isCollapsed()||!this.range.isSimple()||this.range.start.blockId===this.range.end.blockId)&&(o=this.editor.getBlockById(this.range.start.blockId));let r=!1;e&&xt(e,"focused")&&(ot(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=Sh(this.editor);return t==="text"?Ma(this.editor,e):t==="markdown"?Ra(this.editor,e):S6(this.editor,e)}removeAllBlockFocusedClass(){this.editor.rootContainer.querySelectorAll('div[data-type="editor-block"].focused, div[data-type="editor-block"].child-focused').forEach(t=>{ot(t,"focused"),ot(t,"child-focused")})}setBlockFocused(t){if(xt(t,"focused"))return!1;W(t,"focused");let e=nt(t);for(;Lo(e);){const o=et(e);g(Lh,o,"parent block not found"),W(o,"child-focused"),e=nt(o)}return!0}}function FT(n){const t=n.selection.range.focus;if(!t.isSimple())return;const e=n.findBlockById(t.blockId);!e||n.selection.selectBlock(e,0,ut(n,e))}function PT(n){const t=n.selection.range.focus;if(!t.isSimple())return;const e=n.findBlockById(t.blockId);if(!e||!tt(n,e))return;let o=jg(n,"select"),r=Ug(n,"select");if(!o||!r)return;const i=t.blockId;o.blockId!==i&&(o=st(e,0,"home")),r.blockId!==i&&(r=st(e,ut(n,e),"end")),n.selection.setSelection(o,r)}class NT{constructor(t){m(this,"editor");m(this,"startPos",null);m(this,"lastCaretRect");m(this,"mouseDownEvent",null);m(this,"autoScroll",null);m(this,"handleMouseDown",(t,e)=>{var r;this.mouseDownEvent=t;const o=L4(this.editor,t.x,t.y);if(o){if(o instanceof rr)return;if(!this.autoScroll&&e.autoScroll){const s=o.getSelectedBlocks(),l=ro(s[0].block);this.autoScroll=new Qd({scrollElement:l,edge:{top:50,bottom:50}})}const i=this.editor.selection.range;if(t.shiftKey&&i.isSimple()){const s=i.anchor;this.editor.selection.setSelection(s,o.focus),this.startPos=o.start}else this.editor.selection.setSelection(o.anchor,o.focus),this.startPos=o.start;this.editor.selection.updateLastCaretRect(),e.autoScroll&&((r=this.autoScroll)==null||r.active())}});m(this,"handleMouseMove",t=>{if(!this.startPos||!this.mouseDownEvent||Math.abs(this.mouseDownEvent.x-t.x)<3&&Math.abs(this.mouseDownEvent.y-t.y)<3)return;const e=ih(this.editor,t.x,t.y);if(!e)return;const o=Th(this.editor,this.startPos,e.end);if(!o)return;const{anchor:r,focus:i}=o;this.editor.selection.setSelection(r,i)});m(this,"handleMouseUp",t=>{var e;(e=this.autoScroll)==null||e.inactive(),this.startPos=null});this.editor=t,this.startPos=null,this.lastCaretRect=new DOMRect}isSelecting(){return this.startPos!==null}stopSelection(){this.startPos=null}handleDblClick(t){PT(this.editor)}handleTripleClick(t){FT(this.editor)}}function $T(n){return n.readonly||!n.isWritable()?!1:(n.undoManager.undo(),!0)}function HT(n){return n.readonly||!n.isWritable()?!1:(n.undoManager.redo(),!0)}const NA=S("delete-text");function $A(n,t,e,o){const r=o!=null?o:n.selection.range.start;r instanceof je||g(NA,!1,`invalid insert pos type: ${typeof r}`);const{blockId:i}=r,s=n.getBlockById(i);g(NA,tt(n,s),"block is not a text kind block");let{offset:l}=r;if(t==="backward"){if(l-e<0)return 0;if(!sn(s,l-e)){const a=Ri(s,l);e=l-a}}else if(t==="forward"&&l+e>ut(n,s))return 0;return t==="backward"&&(l-=e),n.deleteTextFromBlock(s,l,e)}function HA(n,t){if(n.getBlockData(t).quoted){const e={quoted:null};return n.updateBlockData(t,e),!0}return!1}const jT=S("handle-backspace");function Yg(n,t){if(!he(n,t))return;const e=nt(t);Io(e)!==1&&n.deleteBlock(t)}function UT(n,t){if(!n.selection.range.isCollapsed()){n.clearSelectedContents();return}const e=n.selection.range.start,o=n.getBlockById(e.blockId);if(tt(n,o))if(e.offset===0){if(HA(n,o))return;const r=ce(o);if(r){if(!n.isBlockWritable(r))return;if(tt(n,r))n.mergeTextBlock(r,o,{focus:!0});else if(Mt(n,r)){Yg(n,o);const i=zl(n,r);i?n.selection.selectBlock(i,ut(n,i)):n.selection.selectBlock(r,0,ut(n,r))}else Yg(n,o),g(jT,Me(r),"prev block is not embed block"),n.selection.selectBlock(r,1)}else{const i=nt(o);if(Lo(i)){const s=E4(n,i);if(s){if(!n.isBlockWritable(s))return;Yg(n,o),n.selection.selectBlock(s,ut(n,s))}}}}else $A(n,"backward",1,null),n.selection.updateLastCaretRect();else{const r=bt(o),i=nt(o);n.insertTextBlock("",at(i),r),n.deleteBlock(o)}}function zT(n,t){if(!n.selection.range.isCollapsed()){n.clearSelectedContents();return}const e=n.selection.range.start,o=n.getBlockById(e.blockId);if(tt(n,o))if(e.offset===ut(n,o)){const r=Zt(o);if(r){if(!n.isBlockWritable(r))return;tt(n,r)?n.mergeTextBlock(o,r,{focus:!0}):he(n,o)?n.deleteBlock(o,Ce(n,r,0)):n.deleteBlock(r)}}else $A(n,"forward",1,null);else{const r=bt(o),i=nt(o);n.insertTextBlock("",at(i),r),n.deleteBlock(o)}}function VT(n){const{range:t}=n.selection,{start:e,end:o}=t,r=n.getBlockById(e.blockId),i=n.getBlockById(o.blockId);if(r!==i||!Mt(n,r))return!1;if(Ur(e))return!0;const s=Rs(n,r,e,o),l=xn(n,r);return s.length===l.length}function WT(n,t){if(VT(n)){const o=n.getFocusedBlock(),r=bt(o),i=at(nt(o));n.insertTextBlock("",i,r+1);return}n.selection.range.isCollapsed()||n.clearSelectedContents();const e=n.getFocusedBlock();if(tt(n,e)){if(he(n,e)&&HA(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 qT(n,t){const e=n.selection.range.getSelectedBlocks()[0],{block:o}=e;if(!tt(n,o))return!1;const r=e.end;return n.insertBoxToBlock(o,r.offset,{type:"br",id:K(),box:!0,created:Date.now()}),!0}const GT=S("input-handler-actions");function ZT(n,t){return n.readonly||!n.isWritable()?!1:n.undoManager.runInGroup(()=>(WT(n),!0))}function QT(n,t){return n.readonly||!n.isWritable()?!1:n.undoManager.runInGroup(()=>(zT(n),!0))}function YT(n,t){return n.readonly||!n.isWritable()?!1:n.undoManager.runInGroup(()=>(UT(n),!0))}function JT(n,t){return n.readonly||!n.isWritable()?!1:n.undoManager.runInGroup(()=>(qT(n),!0))}function KT(n){return n.readonly||!n.isWritable()||!window.isSecureContext?!1:(navigator.clipboard.readText().then(t=>{n.input.handlePasteText(t,{toPlainText:!0})}).catch(t=>{GT.error(t)}),!0)}const Mh={ArrowDown:rA,ArrowUp:oA,ArrowLeft:eA,ArrowRight:nA,"Shift+ArrowDown":iA,"Shift+ArrowUp":cA,"Shift+ArrowLeft":sA,"Shift+ArrowRight":lA,"CtrlOrCmd+ArrowLeft":uA,"CtrlOrCmd+ArrowRight":dA,"CtrlOrCmd+Shift+ArrowLeft":hA,"CtrlOrCmd+Shift+ArrowRight":fA,"CtrlOrCmd+ArrowUp":gA,"CtrlOrCmd+ArrowDown":mA,"CtrlOrCmd+Shift+ArrowUp":pA,"CtrlOrCmd+Shift+ArrowDown":Wg,"CtrlOrCmd+A":OA,Home:kA,End:wA,"Shift+Home":vA,"Shift+End":yA,PageUp:TA,PageDown:DA,"Shift+PageUp":SA,"Shift+PageDown":LA,"CtrlOrCmd+Z":$T,"CtrlOrCmd+Shift+Z":HT,Enter:ZT,Delete:QT,Backspace:YT,"Shift+Enter":JT,"CtrlOrCmd+Shift+V":KT};function jA(n,t){return n.shortcuts.handleKeyboardEvents(n,t)!==void 0}function UA(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=>{UA(n,l,e)})})}function zA(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):UA(t,r,e)})}async function XT(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 tD(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 eD(n,t){const o=t.meta.resources;if(!o||Object.keys(o).length===0)return;let r=new Map;if(tD(n,t)){const s=Array.from(Object.keys(o));r=await XT(n,s),zA(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&&zA(n,t,i)}async function nD(n,t,e){await eD(n,t),n.undoManager.runInGroup(()=>{const{start:o,end:r}=n.selection.range,i=n.getBlockById(o.blockId);if(o.blockId===r.blockId&&Me(i)){const s=nt(i),l=n.getBlockIndex(i),[a]=n.insertDocAt(s,l+1,t,e);a&&n.selection.selectBlock(a,ut(n,a))}else{n.clearSelectedContents();const{block:s,offset:l}=ql(n);n.insertDoc(s,l,t,e)}})}const oD=["text/x-ones-editor-doc","image/*","text/office-html","text/html","text/plain","text/markdown","*"];function rD(n){let t;for(const e of oD)if(t=n[e],t)break;return t||null}function VA(n,t,e){if(t.type==="embed"){const s=t.embedData.src;if(s&&typeof s=="string")for(const l of s.split("|"))e.add(l);return}const o=t.text;o&&o.forEach(i=>{i.attributes&&i.attributes.src&&typeof i.attributes.src=="string"&&e.add(i.attributes.src)});const r=t.children;r&&r.forEach(i=>{n.blocks[i].forEach(l=>{VA(n,l,e)})})}function iD(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)}):VA(t,r,e)}),Array.from(e)}function Rh(n,t){return Ze.isFirefox?`<!doctype html><html><head><meta charset="utf8" /></head><body><canvas data-editor-doc="${Si(JSON.stringify(t))}" id="ones-editor-doc">${n}</body></html>`:`<!doctype html><html><head><meta charset="utf8" />${`<meta charset="utf-8"><ones-editor-doc data-source="ones-editor-doc::${Si(JSON.stringify(t))}::ones-editor-doc" />`}</head><body>${n}</body></html>`}function Oh(n,t){var i,s,l;const e=(l=(s=(i=n.doc).getServerMeta)==null?void 0:s.call(i))!=null?l:{},o=iD(n,t),r={};o.forEach(a=>{const d=n.doc.buildResourceUrl(a,{withToken:!0});r[a]=d}),t.meta={...e,resources:r}}function sD(n,t,e){if(t.preventDefault(),t.stopPropagation(),!t.clipboardData)return;let o=Sh(n);const r=e==null?void 0:e(n,t,o);if(r===!0)return;typeof r=="object"&&r!==null&&(o=r),Oh(n,o);const i=yh(n,o),s=Ra(n,o),l=Rh(i,o);t.clipboardData.setData("text/html",l),t.clipboardData.setData("text/plain",s),t.clipboardData.setData("text/x-ones-editor-doc",JSON.stringify(o))}async function _h(n,t){const e=Qg(n,t);Oh(n,e);const o=yh(n,e),r=Ra(n,e),i=Rh(o,e);return Sm([{type:"text/plain",data:new Blob([r],{type:"text/plain"})},{type:"text/html",data:new Blob([i],{type:"text/html"})}])}class lD{constructor(t){m(this,"editor");m(this,"handlers",[]);m(this,"onPasteText",async(t,e)=>{const o=new DataTransfer;o.setData("text/plain",t);const r=await this.editor.dataConverter.fromData(this.editor,o,e);r&&this.pasteDocs(r,null)});this.editor=t}onInsertText(t,e){if(!tt(this.editor,this.editor.getFocusedBlock()))return;const{containerId:o,blockIndex:r,offset:i}=ql(this.editor);this.handleBeforeInsertText(o,r,i,e)||(this.defaultInsertText(this.editor,o,r,i,e),this.handleAfterInsertText(o,r,i,e),this.editor.selection.updateLastCaretRect())}onKeyDown(t){if(this.handleBeforeKeyDown(t))return!0;const e=this.defaultHandleKeydown(this.editor,t);return this.handleAfterKeyDown(t)?!0:e}onChanged(t){for(let e=0;e<this.handlers.length;e++){const o=this.handlers[e];o.handleChanged&&o.handleChanged(this.editor,t)}}onRemoteChanged(t){for(let e=0;e<this.handlers.length;e++){const o=this.handlers[e];o.handleRemoteChanged&&o.handleRemoteChanged(this.editor,t)}}onCompositionStart(t){this.editor.updateCompositionText("",!1);const{containerId:e,blockIndex:o,offset:r}=ql(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}=ql(this.editor);for(let l=0;l<this.handlers.length;l++){const a=this.handlers[l];a.handleUpdateCompositionText&&a.handleUpdateCompositionText(this.editor,r,i,s,o)}this.editor.selection.updateLastCaretRect()}onCopy(t){sD(this.editor,t,(e,o,r)=>{for(let i=0;i<this.handlers.length;i++){const s=this.handlers[i];if(s.handleBeforeCopy){const l=s.handleBeforeCopy(this.editor,o,r);if(l===!0)return!0;if(typeof l=="object"&&l!=null)return l}}})}onCut(t){for(let o=0;o<this.handlers.length;o++){const r=this.handlers[o];if(r.handleBeforeCut&&r.handleBeforeCut(this.editor,t)===!0)return}if(this.onCopy(t),this.editor.selection.range.isCollapsed()){const o=this.editor.selection.focusedBlock;Me(o)&&this.editor.deleteBlock(o)}else Rg(this.editor)}onPaste(t){if(t.preventDefault(),t.stopPropagation(),!t.clipboardData)return;this.editor.dataConverter.fromData(this.editor,t.clipboardData).then(async o=>{o&&this.pasteDocs(o,t)})}onFocus(){W(this.editor.rootElement,"active")}onBlur(){ot(this.editor.rootElement,"active")}addHandler(t){this.handlers.push(t),this.handlers=this.handlers.sort((e,o)=>{var s,l;const r=(s=e.order)!=null?s:1;return((l=o.order)!=null?l:1)-r})}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){Tg(this.editor,i)}defaultHandleKeydown(t,e){return jA(this.editor,e)?(e.preventDefault(),e.stopPropagation(),!0):!1}async pasteDoc(t){for(let o=0;o<this.handlers.length;o++){const r=this.handlers[o];if(r.handleBeforePasteDoc&&await r.handleBeforePasteDoc(this.editor,t))return}const e={blockIdMap:new Map,containerIdMap:new Map};await nD(this.editor,t,e);for(let o=0;o<this.handlers.length;o++){const r=this.handlers[o];if(r.handleAfterPasteDoc&&await r.handleAfterPasteDoc(this.editor,t,e))return}}async pasteDocs(t,e){for(let r=0;r<this.handlers.length;r++){const i=this.handlers[r];if(i.handleBeforePaste&&await i.handleBeforePaste(this.editor,e,t))return}const o=rD(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 cD(n,t,e){const o=Fr(t,e);return o.remove(),o}S("copy-dom-attributes");const WA=["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 aD(n,t){for(let l=0;l<WA.length;l++){const a=WA[l];t[a]=n[a]}const e=n.attributes,o=t.attributes,r=[],i=[];for(let l=0;l<e.length;l++){const a=e[l],d=o.getNamedItem(a.name);d?d.value!==a.value&&(d.value=a.value,i.push(a)):r.push(a)}const s=[];for(let l=0;l<o.length;l++){const a=o[l];e.getNamedItem(a.name)||s.push(a)}r.forEach(l=>{t.setAttribute(l.name,l.value)}),i.forEach(l=>{t.setAttribute(l.name,l.value)}),s.forEach(l=>{t.removeAttribute(l.name)})}function qA(n){const t=Array.from(n.childNodes).filter(e=>!HC(e));return t.forEach(e=>{e.remove()}),t}function GA(n,t,e){var d;const o=n.getContainerById(t),r=Fr(o,e),i=Li(r),s=n.doc.getBlockData(t,e),l=Qt(n,r);if((d=l==null?void 0:l.handleUpdateBlock)==null?void 0:d.call(l,n,r,s))n.editorBlockRenders.updateBlock(n,i,r,s);else{const h=n.editorBlocks.createBlock(i,o,s),p=qA(h);qA(r),p.forEach(v=>{r.appendChild(v)});const A=Xd(h);if(A){const v=Xd(r);v&&v.remove(),r.appendChild(A)}aD(h,r)}r4(n,r,s),n.blockHooks.forEach(h=>{var p;(p=h.update)==null||p.call(h,n,i,o,r,s)}),setTimeout(()=>{n.selection.updateSelection(null)})}const uD=S("transform-selection");function ZA(n,t,e,o){const{range:r}=n.selection,{anchor:i,focus:s}=r;if(i.blockId!==t&&s.blockId!==t)return r;g(uD,i.isSimple()&&s.isSimple(),"invalid text pos type");let l=i;if(i.blockId===t){const d=ln.transformCursor(i.offset,e,o);l=st(t,d,"normal")}let a=s;if(s.blockId===t){const d=ln.transformCursor(s.offset,e,o);a=st(t,d,"normal")}return Ue(n,{anchor:l,focus:a})}const dD=S("handle-block-text-changed");function hD(n,t,e,o,r){const i=n.getContainerById(t),s=Fr(i,e),l=n.doc.getBlockData(t,e);if(g(dD,l.text,"no block text"),KC(n,s).setBlockText(n,s,l.text),!r){const a=ZA(n,l.id,o,r);n.selection.setRange(a,{noScroll:!0})}}function fD(n,t){const e=mt.default(n);return t.delete.forEach(r=>{delete e[r]}),{...e,...t.insert}}function QA(n,t,e,o){const r=Qt(n,t);r.handleDeleteBlock&&r.handleDeleteBlock(n,t,e,o),n.emit("blockDeleted",n,t,e,o)}function mD(n,t,e,o){const r=n.getBlockByIndex(t,e);r.querySelectorAll('[data-type="editor-block"]').forEach(i=>{QA(n,i,o,{child:!0})}),QA(n,r,o,{child:!1})}const _o=S("editor-doc");class gD extends ha{constructor(e,o,r){super();m(this,"localEvents",[]);this.editor=e,this.externalDoc=o,this.externalDoc.registerCallback(this),this.registerLocalEvents(r)}beginBatchUpdate(){return this.externalDoc.beginBatchUpdate()}endBatchUpdate(){return this.externalDoc.endBatchUpdate()}registerLocalEvents(e){this.localEvents.push(e)}toJSON(){return this.externalDoc.toJSON()}getVersionHelper(){var o,r;return(r=(o=this.externalDoc).getVersionHelper)==null?void 0:r.call(o)}getContainerBlocks(e){return this.externalDoc.getContainerBlocks(e)}getBlockData(e,o){return this.externalDoc.getBlockData(e,o)}verifyBlockWritable(e,o){const r=this.editor.getBlockByIndex(e,o);g(_o,this.editor.isBlockWritable(r),`block is not writable, ${e}, ${o}`)}localUpdateBlockText(e,o,r,i){g(_o,!this.editor.readonly,"editor is readonly"),this.verifyBlockWritable(e,o);const s=this.getBlockData(e,o),l=s.text;g(_o,l,`no text, ${e}, ${o}`);const a=ZA(this.editor,s.id,r,!0),d=ln.apply(l,r);this.localEvents.forEach(p=>p.onBeforeUpdateBlockText(e,s.id,l,d,a.toDocRange()));const h=this.externalDoc.localUpdateBlockText(e,o,r);return this.editor.selection.setRange(a,i),h}localUpdateBlockData(e,o,r,i){g(_o,!this.editor.readonly,"editor is readonly");const s=this.editor.getBlockByIndex(e,o);if(!this.editor.isBlockWritable(s)){const h=Array.from(r.delete).filter(A=>A!=="comments"),p=Object.keys(r.insert).filter(A=>A!=="comments");(h.length>0||p.length>0)&&g(_o,!1,`block is not writable, comment supported only, ${JSON.stringify(r)}}`)}const l=mt.default(this.getBlockData(e,o)),a=mt.default(fD(l,r));this.localEvents.forEach(h=>h.onBeforeUpdateBlockData(e,l.id,l,a,i));const d=this.externalDoc.localUpdateBlockData(e,o,r,i);return this.editor.selection.setRange(Mi(this.editor,i)),d}localInsertBlock(e,o,r,i,s){g(_o,!this.editor.readonly,"editor is readonly"),this.localEvents.forEach(a=>a.onBeforeInsertBlock(e,o,r,i));const l=this.externalDoc.localInsertBlock(e,o,r,i);return s!=null&&s.noFocus||this.editor.selection.setRange(Mi(this.editor,i),s),l}localDeleteBlock(e,o,r){g(_o,!this.editor.readonly,"editor is readonly"),this.verifyBlockWritable(e,o);const i=mt.default(this.getBlockData(e,o));this.localEvents.forEach(l=>l.onBeforeDeleteBlock(e,o,i,r));const s=this.externalDoc.localDeleteBlock(e,o,r);return this.editor.selection.setRange(Mi(this.editor,r)),s}localDeleteChildContainers(e){return g(_o,!this.editor.readonly,"editor is readonly"),e.forEach(o=>{const r=mt.default(this.getContainerBlocks(o));this.localEvents.forEach(i=>i.onBeforeDeleteChildContainer(o,r))}),this.externalDoc.localDeleteChildContainers(e)}localInsertChildContainer(e,o){return g(_o,!this.editor.readonly,"editor is readonly"),this.localEvents.forEach(r=>r.onBeforeInsertChildContainer(e,mt.default(o))),this.externalDoc.localInsertChildContainer(e,o)}onRequestReload(e){_o.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)}),hD(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)}),GA(this.editor,e,o),this.editor.emit("docChanged",this.editor,i)}onInsertBlock(e,o,r,i){this.callbacks.forEach(l=>{var a;return(a=l.onInsertBlock)==null?void 0:a.call(l,e,o,r,i)});const s=this.editor.getContainerById(e);nx(this.editor,s,o,r),this.editor.emit("docChanged",this.editor,i)}onDeleteBlock(e,o,r){mD(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);cD(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){_o.log("reset doc"),this.externalDoc=e,this.externalDoc.registerCallback(this),this.editor.reload()}}function YA(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 Jg=S("undo-action");class Jl{constructor(t,e,o){m(this,"beforeRange");m(this,"afterRange");this.containerId=e,this.beforeRange=t.selection.range.clone().toDocRange(),this.afterRange=o}undo(t){return!1}redo(t){return!1}combinable(t){return g(Jg,t,"no other action"),!1}combine(t){g(Jg,!1,"no other")}setAfterRange(t){this.afterRange&&Jg.warn("after range has already set"),this.afterRange=t}}const pD=S("block-action");class JA extends Jl{constructor(e,o,r,i,s){super(e,o,s);m(this,"blockData");m(this,"blockIndex");this.blockData=mt.default(i),this.blockIndex=r}deleteBlock(e,o){if(!e.getContainerById(this.containerId))return!1;const i=e.getBlockById(this.blockData.id);return i?(g(pD,this.blockIndex===bt(i),"invalid block index"),Bh(e,i,Mi(e,o)),!0):!1}insertBlock(e,o){return Zl(e,this.containerId,this.blockIndex,mt.default(this.blockData),o),!0}}class CD extends JA{undo(t){return this.deleteBlock(t,this.beforeRange)}redo(t){return this.insertBlock(t,this.afterRange)}}class AD extends JA{undo(t){return this.insertBlock(t,this.beforeRange)}redo(t){return this.deleteBlock(t,this.afterRange)}}class bD extends Jl{constructor(e){super(e,at(e.rootContainer),e.selection.range.toDocRange());m(this,"actions",[])}addAction(e){YA(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 Jl&&(o.afterRange||o.setAfterRange(e))}}const Hs=S("update-block-data-action");class Fh extends Jl{constructor(e,o,r,i,s,l){super(e,o,l);m(this,"beforeBlockData");m(this,"afterBlockData");m(this,"blockId");this.blockId=r,g(Hs,this.blockId===i.id,"invalid block id"),g(Hs,this.blockId===s.id,"invalid block id"),this.beforeBlockData=mt.default(i),this.afterBlockData=mt.default(s),g(Hs,this.beforeBlockData.type===this.afterBlockData.type,"invalid block type")}undo(e){g(Hs,e,"no editor");const o=e.getBlockById(this.blockId);if(!o)return!1;const r=e.getContainerById(this.containerId);return g(Hs,r,"no container"),Ih(e,o,Fh.toAttributes(this.beforeBlockData),this.beforeRange),!0}redo(e){g(Hs,e,"no editor");const o=e.getBlockById(this.blockId);if(!o)return!1;const r=e.getContainerById(this.containerId);return g(Hs,r,"no container"),Ih(e,o,Fh.toAttributes(this.afterBlockData),this.afterRange),!0}static toAttributes(e){const o=mt.default(e);return delete o.id,delete o.type,o}}const Kg=S("update-block-text-action");class Ha extends Jl{constructor(e,o,r,i,s,l){super(e,o,l);m(this,"beforeRichTextData");m(this,"afterRichTextData");m(this,"blockId");m(this,"type");this.blockId=r,this.beforeRichTextData=mt.default(i),this.afterRichTextData=mt.default(s),this.type=Ha.calType(i,s)}static calType(e,o){g(Kg,e,"no old data"),g(Kg,o,"no new data");const i=ln.diff(e,o),s=new Set;let l=!1;const a=h=>gC(h)?`cjk_${h}`:fC(h)?"number":zd(h)?"space":mC(h)?"letter":"unknown";let d=!1;return i.forEach(h=>{h.insert?h.insert===" "?s.add("insert_letter"):typeof h.insert=="string"&&h.insert.startsWith(" ")&&h.insert.length>1?(l=!0,d=!0,s.add(`insert_${a(h.insert.substr(1))}`)):s.add(`insert_${a(h.insert)}`):h.delete&&(l?l=!1:s.add("delete"))}),{textType:Array.from(s).join("|"),begin:d}}undo(e){if(!e.getContainerById(this.containerId))return!1;const r=e.getBlockById(this.blockId);return r?(xh(e,r,this.beforeRichTextData),!0):!1}redo(e){if(!e.getContainerById(this.containerId))return!1;const r=e.getBlockById(this.blockId);return r?(xh(e,r,this.afterRichTextData),!0):!1}combinable(e){if(!(e instanceof Ha)||e.type.begin||this.type.textType!==e.type.textType||e.blockId!==this.blockId)return!1;const o=e.beforeRange,r=o.anchor;if(!r.isSimple())return!1;const i=this.afterRange;if(!i)return!1;const s=i.anchor;return!(!s.isSimple()||s.blockId!==o.anchor.blockId||s.offset!==r.offset)}combine(e){g(Kg,e instanceof Ha,"invalid action type");const o=e;this.afterRichTextData=o.afterRichTextData,this.afterRange=e.afterRange}}class KA extends Jl{constructor(t,e,o){super(t,e,t.selection.range.toDocRange()),this.blocks=o}deleteChildContainer(t){return t.doc.localDeleteChildContainers([this.containerId]),!0}insertChildContainer(t){return t.doc.localInsertChildContainer(this.containerId,mt.default(this.blocks)),!0}}class vD extends KA{undo(t){return this.deleteChildContainer(t)}redo(t){return this.insertChildContainer(t)}}class yD extends KA{undo(t){return this.insertChildContainer(t)}redo(t){return this.deleteChildContainer(t)}}const Fo=S("undo");class kD{constructor(t){m(this,"editor");m(this,"actions",[]);m(this,"undoCursor");m(this,"currentGroup",null);m(this,"groupCounter",0);m(this,"undoRedoing",!1);m(this,"handleSelectionChange",t=>{if(this.currentGroup){this.currentGroup.setAfterRange(t.selection.range.toDocRange());return}const e=this.actions[this.actions.length-1];!e||e.afterRange||e.setAfterRange(t.selection.range.toDocRange())});this.editor=t,this.undoCursor=-1,this.editor.addListener("selectionChanged",this.handleSelectionChange)}reset(){this.actions=[],this.undoCursor=-1}prepareSaveUndoState(){this.undoCursor!==-1&&(this.actions.splice(this.undoCursor),this.undoCursor=-1)}addAction(t){this.currentGroup?this.currentGroup.addAction(t):(YA(this.actions,t),setTimeout(()=>{this.editor.input.handleChanged(t)}))}beginGroup(){this.groupCounter===0?(g(Fo,!this.currentGroup,"current group already exists"),this.currentGroup=new bD(this.editor),this.groupCounter=1):(g(Fo,this.currentGroup,"current group not exists"),this.groupCounter+=1)}endGroup(){g(Fo,this.currentGroup,"current group not exists"),g(Fo,this.groupCounter>0,"group counter === 0"),this.groupCounter-=1,this.groupCounter===0&&(this.currentGroup.actions.length===0?Fo.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 Fo.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(Mi(this.editor,t.beforeRange))}catch(e){Fo.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(Mi(this.editor,e)):Fo.warn("no after range")}catch(e){Fo.error(`redo: failed to set caret pos after redo: ${e.message}`)}return this.editor.input.handleChanged(t),!0}}return!1}finally{this.undoRedoing=!1}}canUndo(){return!(this.actions.length===0||this.undoCursor===0)}canRedo(){return!(this.actions.length===0||this.undoCursor===-1||this.undoCursor===this.actions.length)}lastAction(){var e;const t=this.undoCursor===-1?this.actions.length-1:this.undoCursor-1;return(e=this.actions[t])!=null?e:null}undoTo(t){for(;;){const e=this.lastAction();if(!e||e===t)return!0;if(!this.undo())return!1}}onBeforeUpdateBlockText(t,e,o,r,i){this.undoRedoing||(this.prepareSaveUndoState(),ln.diff(o,r).length!==0&&this.addAction(new Ha(this.editor,t,e,o,r,i)))}onBeforeUpdateBlockData(t,e,o,r,i){if(this.undoRedoing)return;this.prepareSaveUndoState();const s=new Fh(this.editor,t,e,o,r,i);this.addAction(s)}onBeforeInsertBlock(t,e,o,r){this.undoRedoing||(this.prepareSaveUndoState(),g(Fo,e>=0,"invalid block index"),g(Fo,o,"no block data"),this.addAction(new CD(this.editor,t,e,o,r)))}onBeforeDeleteBlock(t,e,o,r){this.undoRedoing||(this.prepareSaveUndoState(),this.addAction(new AD(this.editor,t,e,o,r)))}onBeforeInsertChildContainer(t,e){this.undoRedoing||(this.prepareSaveUndoState(),this.addAction(new vD(this.editor,t,e)))}onBeforeDeleteChildContainer(t,e){this.undoRedoing||(this.prepareSaveUndoState(),this.addAction(new yD(this.editor,t,e)))}}class wD{async fromData(t,e){const o=e.getData("text/x-ones-editor-doc");if(o)return{"text/x-ones-editor-doc":JSON.parse(o)}}}class BD{constructor(){m(this,"converters",[]);m(this,"converterTypes",["text/plain","text/markdown","text/html","text/x-ones-editor-doc"]);this.addConverter(new wD)}prepareData(t){const e=new DataTransfer;for(let o=0;o<this.converterTypes.length;o++)e.setData(this.converterTypes[o],t.getData(this.converterTypes[o]));return e}async fromData(t,e,o){let r={};const i=this.prepareData(e);for(const s of this.converters){const l=await s.fromData(t,i,o);l&&(r={...r,...l})}return r}addConverter(t){this.converters.push(t)}}class ED{constructor(t){m(this,"renders",[]);this.editor=t}registerRender(t){this.renders.push(t)}renderText(t,e){const o={classes:[],attributes:{},styles:{}};return this.renders.forEach(r=>{if(r.renderText){const i=r.renderText(this.editor,t,e);i.classes&&o.classes.push(...i.classes),i.attributes&&(o.attributes={...o.attributes,...i.attributes}),i.styles&&(o.styles={...o.styles,...i.styles})}}),o}renderBlock(t,e,o){const r={classes:[],attributes:{},styles:{}};return this.renders.forEach(i=>{if(i.renderBlock){const s=i.renderBlock(this.editor,e,o);s.classes&&r.classes.push(...s.classes),s.attributes&&(r.attributes={...r.attributes,...s.attributes}),s.styles&&(r.styles={...r.styles,...s.styles})}}),r}updateBlock(t,e,o,r){this.renders.forEach(i=>{var s;(s=i.updateBlock)==null||s.call(i,t,e,o,r)})}}class Ae extends ye.TypedEmitter{constructor(e){super();m(this,"hoveringBlock",null);m(this,"hoveringTextChild",null);m(this,"filters",[]);m(this,"finders",[]);m(this,"handleDocumentMouseMove",e=>{if(this.hoveringBlock){for(const s of this.filters)if(s.isInBlock(this.hoveringBlock,e))return}const o=document.elementFromPoint(e.x,e.y);if(!o){this.setHoveringBlock(null,e,null);return}let r=et(o);if((!r||!Xt(this.editor.rootContainer,r))&&(r=this.findBlockByFinders(e),!r)){this.setHoveringBlock(null,e,null);return}const i=this.getParentTextContentChild(r,o);this.setHoveringBlock(r,e,i)});this.editor=e,document.addEventListener("mousemove",this.handleDocumentMouseMove)}destroy(){document.removeEventListener("mousemove",this.handleDocumentMouseMove),this.filters.forEach(e=>e.destroy()),this.filters=[],this.finders.forEach(e=>e.destroy()),this.finders=[]}addFilter(e){this.filters.push(e)}addFinder(e){this.finders.push(e)}hoveringBlockId(){return this.hoveringBlock?it(this.hoveringBlock):""}findBlockByFinders(e){for(let o=0;o<this.finders.length;o++){const i=this.finders[o].findTargetBlock(this.editor,e);if(i)return i}return null}setHoveringBlock(e,o,r){if(this.hoveringBlock===e&&this.hoveringTextChild===r)return;if(this.hoveringBlock!==e){const s=this.hoveringBlock&&Xt(this.editor.rootContainer,this.hoveringBlock)?this.hoveringBlock:null;s&&ot(s,"hover"),e&&W(e,"hover"),this.hoveringBlock=e,this.emit("change",this.hoveringBlock,s,o)}const i=this.hoveringTextChild;this.hoveringTextChild=r,this.emit("childChange",this.hoveringBlock,r,i,o)}static get(e){return e.addCustom("standard-hovering-block",()=>new Ae(e))}getParentTextContentChild(e,o){if(!tt(this.editor,e))return null;const r=Lt(e);return o.parentElement===r?o:Pm(o)}}const XA="style-color-",tb="style-bg-color-";class xD{renderText(t,e,o){const r=[],i={},s={};return Object.entries(o).forEach(([l,a])=>{a===!0?l.startsWith(XA)?i["data-style-color"]=l.substring(XA.length):l.startsWith(tb)?i["data-style-bg-color"]=l.substring(tb.length):l.startsWith("style")&&r.push(l):typeof a=="string"&&(l==="link"&&(r.push("link"),i.link=a),l==="inline-style-color"&&(s.color=a))}),{classes:r,attributes:i,styles:s}}renderBlock(t,e,o){var l,a;const r={};Object.entries(o).filter(d=>d[0].startsWith("style-")).forEach(([d,h])=>{r[`data-${d}`]=`${h}`});const s=[];return((a=(l=t.selection)==null?void 0:l.range)==null?void 0:a.start.blockId)===o.id&&s.push("focused"),typeof o.align=="string"&&o.align&&(r["data-style-align"]=o.align),o.heading&&(r["data-style-heading"]=String(o.heading)),o.quoted&&(r["data-style-quoted"]="true"),Ae.get(t).hoveringBlockId()===o.id&&s.push("hover"),{attributes:r,classes:s}}updateBlock(t,e,o,r){var s,l;Array.from(o.attributes).forEach(a=>{a.name.startsWith("data-style-")&&o.removeAttribute(a.name)}),Object.entries(r).filter(a=>a[0].startsWith("style-")||a[0]==="align").forEach(([a,d])=>{a==="align"&&o.setAttribute(a.startsWith("style-")?`data-${a}`:`data-style-${a}`,`${d}`)}),((l=(s=t.selection)==null?void 0:s.range)==null?void 0:l.start.blockId)===r.id&&W(o,"focused"),Ae.get(t).hoveringBlockId()===r.id&&W(o,"hover")}}function ID(n){n.editorBlocks.registerBlockClass(Tn),n.editorBlocks.registerBlockClass(B4),n.editorBoxes.registerBoxClass(f6),n.editorBoxes.registerBoxClass(m6),n.editorBoxes.registerBoxClass(C6),n.editorBoxes.registerBoxClass(A6),n.editorInsertions.registerInsertionClass(b6),n.editorBlockRenders.registerRender(new xD)}function TD(n,t){ID(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 eb=S("range-commands");function nb(n,t){n.forEach(e=>{e.source=t,e.children&&nb(e.children,t)})}function ob(n,t,e){const o=it(t);g(eb,o===e.start.blockId,"invalid start range"),g(eb,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);nb(l,s.id),i.push(...l)}),r.forEach(s=>{if(s.filterCommands){const l=s.filterCommands(n,t,e,i);l&&(i=l)}}),Mt(n,t)&&Rs(n,t,e.start,e.end).forEach(l=>{pe(l).forEach(d=>{const h=ut(n,d),p=Ue(n,{anchor:st(d,0,"home"),focus:st(d,h,"end")}),A=ob(n,d,p);i.push(...A)})}),i}function rb(n){const t=n.getEditor(),e=n.getSelectedBlocks(),o=[];return e.forEach(r=>{const i=Ue(t,{anchor:r.start,focus:r.end});ob(t,r.block,i).forEach(l=>{o.push(l)})}),o}function ib(n,t,e,o,r,i){var h;const s=n.editorCommandProviders.getCommandProviders();for(let p=0;p<s.length;p++){const A=s[p];if(A.beforeExecuteCommand&&A.beforeExecuteCommand(n,t,e,o,r))return!1}const l=n.editorCommandProviders.getCommandProvider(o.source),a={};if((h=l.executeCommand)!=null&&h.call(l,n,t,e,o,r,{}))return i[it(t)]=a,!0;let d=!1;return Mt(n,t)&&Rs(n,t,e.start,e.end).forEach(A=>{pe(A).forEach(B=>{const D=ut(n,B),x=Ue(n,{anchor:st(B,0,"home"),focus:st(B,D,"end")});ib(n,B,x,o,r,i)&&(d=!0)})}),s.forEach(p=>{p.afterExecuteCommand&&p.afterExecuteCommand(n,t,e,o,r,i)}),d}function sb(n,t,e){const o=n.getEditor(),r={},i=o.editorCommandProviders.getCommandProvider(t.source);return i.executeRangeCommand&&i.executeRangeCommand(o,n,t,e,r)||n.getSelectedBlocks().forEach(l=>{const a=Ue(o,{anchor:l.start,focus:l.end});ib(o,l.block,a,t,e,r)}),r}const DD=S("command-providers");class lb{constructor(t){m(this,"providers",[]);this.editor=t}registerCommandProvider(t){this.providers.push(t)}getCommandProviders(){return this.providers}getCommandProvider(t){const e=this.providers.find(o=>o.id===t);return g(DD,e,`no command provider, id=${t}`),e}getCommands(t){return rb(t)}executeCommand(t,e,o){return this.editor.undoManager.runInGroup(()=>sb(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 SD(n,t){const e=nt(t),o=at(e),r=bt(t);GA(n,o,r)}const LD=S("table-scroll");class cb{constructor(t,e,o,r,i){m(this,"handleEvent",t=>{this.handler(this.editor,t,this.data)});this.editor=t,this.dom=e,this.name=o,this.handler=r,this.data=i,e.addEventListener(o,this.handleEvent)}destroy(){this.dom.removeEventListener(this.name,this.handleEvent)}}class MD{constructor(t){m(this,"handlers",new Map);this.editor=t}destroy(){Array.from(this.handlers.entries()).forEach(([t,e])=>{e.forEach(o=>o.destroy()),this.handlers.delete(t)})}addEventListener(t,e,o,r){const i=this.handlers.get(t);if(i){if(i.find(s=>s.handler===o&&s.name===e)){LD.warn(`event has already registered: ${e}`);return}i.push(new cb(this.editor,t,e,o,r))}else{const s=new cb(this.editor,t,e,o,r);this.handlers.set(t,[s])}}removeEventListener(t,e,o){if(!t){for(const[i,s]of Array.from(this.handlers.entries()))for(let l=s.length-1;l>=0;l--){const a=s[l];if(e)e===a.name&&o===a.handler&&s.splice(l,1);else if(o===a.handler){s.splice(l,1),a.destroy(),s.length===0&&this.handlers.delete(i);continue}}return}const r=this.handlers.get(t);if(r){const i=r.findIndex(s=>s.handler===o&&s.name===e);if(i!==-1){const s=r[i];r.splice(i,1),s.destroy(),r.length===0&&this.handlers.delete(t)}}}removeAllListeners(t,e){const o=this.handlers.get(t);if(o)if(e)for(let r=0;r<o.length;r++){const i=o[r];i.name===e&&(o.splice(r,1),i.destroy())}else o.forEach(r=>{r.destroy()}),this.handlers.delete(t)}}const ab=S("update-block-text");function RD(n,t){const e=n.getBoxById(t.id),o=et(e);g(ab,o,"no parent block"),g(ab,tt(n,o),"not a text block");const r=n.getBlockText(o),i=r6(r,"id",t.id,t);j6(n,o,i)}function OD(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 _D(n){return n.readonly?!1:!Ro(n).find(o=>!n.isBlockWritable(o.block))}class FD{constructor(t){this.editor=t}getKey(t){return`${this.editor.id}-${t}`}getItem(t){return window.localStorage.getItem(this.getKey(t))}setItem(t,e){if(!e){this.removeItem(t);return}window.localStorage.setItem(this.getKey(t),e)}removeItem(t){window.localStorage.removeItem(this.getKey(t))}}class PD{constructor(){m(this,"shortcuts",[])}handleKeyboardEvents(t,e){const o=this.shortcuts;for(const r of o){const i=Object.entries(r);for(const[s,l]of i)if(_r(e,s)){const a=l(t,e);if(a!==void 0)return a}}}}const Gr=S("editor");class ND extends ye.TypedEmitter{constructor(e,o,r){var i,s,l,a,d,h,p;super();m(this,"parent");m(this,"rootElement");m(this,"contentElement");m(this,"rootContainerObject");m(this,"rootContainer");m(this,"input");m(this,"selection");m(this,"selectionHandler");m(this,"doc");m(this,"id");m(this,"clientId");m(this,"compositingText","");m(this,"undoManager");m(this,"shortcuts",new PD);m(this,"dataConverter",new BD);m(this,"editorBlocks",new v4(this));m(this,"editorBoxes",new p6(this));m(this,"editorInsertions",new y6(this));m(this,"editorEmbeds",new k4(this));m(this,"editorDecorators",new k6(this));m(this,"editorCommandProviders",new lb(this));m(this,"editorBlockRenders",new ED(this));m(this,"blockHooks",[]);m(this,"domEvents",new MD(this));m(this,"customs",new Map);m(this,"options");m(this,"inputHandlers",new lD(this));m(this,"settingsProvider");m(this,"_readonly",!1);Gr.debug("create editor"),this.setMaxListeners(100),this.options={colors:(i=r==null?void 0:r.colors)!=null?i:["#9923E9","#4587C2","#8BDB7A","#FB28D3","#CBC619","#10FEEB","#812A1A","#8A3F25","#22D742","#A53E74","#555C87","#57E0AA"],componentsOptions:(l=(s=r==null?void 0:r.components)==null?void 0:s.options)!=null?l:{},scrollContainer:r==null?void 0:r.scrollContainer},this.settingsProvider=(a=r==null?void 0:r.settingsProvider)!=null?a:new FD(this),TD(this,r==null?void 0:r.components),this.blockHooks.push(...(h=(d=r==null?void 0:r.components)==null?void 0:d.blockHooks)!=null?h:[]),this.id=(p=r==null?void 0:r.id)!=null?p:K(),this.clientId=K(),this.undoManager=new kD(this),this.doc=new gD(this,o,this.undoManager),this.parent=e,this.rootElement=w("div",["editor-root"],this.parent),this.rootElement.setAttribute("data-editor-client-id",this.clientId),this.contentElement=w("div",["editor-content"],this.rootElement),this.rootContainerObject=C4(this),this.rootContainer=this.rootContainerObject.rootContainer,this.input=new ZI(this,this.inputHandlers),this.selection=new _T(this),this.selectionHandler=new NT(this),r!=null&&r.shortcuts&&this.shortcuts.shortcuts.push(...r.shortcuts),Ze.isMobile&&W(this.rootElement,"mobile"),Ze.isSafari&&W(this.rootElement,"safari"),this._readonly&&W(this.rootElement,"readonly"),this.emit("load",this,!1)}get readonly(){return this._readonly}set readonly(e){this._readonly=e,e?W(this.rootElement,"readonly"):ot(this.rootElement,"readonly"),this.emit("readonlyChanged",this)}get scrollContainer(){return this.options.scrollContainer?this.options.scrollContainer:ro(this.rootContainer)}addCustom(e,o){const r=this.customs.get(e);if(r)return r;const i=o(this);return this.customs.set(e,i),i}getCustom(e){const o=this.customs.get(e);return g(Gr,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(){Gr.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(),setTimeout(()=>{W(this.rootElement,"active")})}focusToBlock(e,o){Og(this,e,o)}isWritable(){return _D(this)}isBlockWritable(e){return OD(this,e)}getChildContainerData(e){const o=this.doc.getContainerBlocks(e);return g(Gr,o,`no child container data: ${e}, ${JSON.stringify(this.doc)}`),g(Gr,Array.isArray(o),`container data is not an array: ${JSON.stringify(o)}`),o}createChildContainer(e,o,r){return A4(this,e,o,r)}getFirstBlock(){return this.rootContainer.querySelector("[data-type=editor-block]")}getLastBlock(){const e=Array.from(this.rootContainer.querySelectorAll(":scope [data-type=editor-block]"));return e[e.length-1]}getFocusedBlock(){return this.selection.getFocusedBlock()}findBlockById(e){const o=this.rootContainer.querySelector(`#${e}`);return o&&g(Gr,Es(o),"not an valid block element"),o!=null?o:null}findBoxById(e){const o=this.rootContainer.querySelector(`#${e}`);return o&&g(Gr,Fm(o),"not an valid box element"),o!=null?o:null}getBlockById(e){const o=this.findBlockById(e);return g(Gr,o,`no block, id=${e}`),o}getBoxById(e){const o=this.findBoxById(e);return g(Gr,o,`no box, id=${e}`),o}getBlockByIndex(e,o){const r=this.getContainerById(e);return Fr(r,o)}getBlockIndex(e){if(typeof e=="string"){const o=this.getBlockById(e);return bt(o)}return bt(e)}getContainerById(e){return jr(this,e)}getParentContainer(e){return nt(e)}reloadBlock(e){SD(this,e)}contains(e){const o=e instanceof Element?e:e.parentElement;return o?o.closest("div.editor-root")===this.rootElement:!1}insertBlock(e,o,r,i,s){const l={blockId:r.id,offset:0},a={anchor:l,focus:l};return Zl(this,e,o,r,i!=null?i:a,s)}insertEmbed(e,o,r,i,s){const l={id:K(),type:"embed",embedType:r,embedData:i};return this.insertBlock(e,o,l,s)}deleteBlock(e,o){Lg(this,e,o)}mergeTextBlock(e,o){return N6(this,e,o)}breakTextBlock(e,o,r){return Ql(this,e,o,r).newBlock}getTextPosition(){return ql(this)}getBlockString(e,o){const r=this.getBlockText(e);return ie(r,o)}getBlockData(e){return _i(this,e)}getBoxData(e){return d6(this,e)}getBlockText(e){return gn(this,e)}setBlockText(e,o){j6(this,e,o)}deleteTextFromBlock(e,o,r,i){return Dg(this,e,o,r,i)}insertTextToBlock(e,o,r,i){return L6(this,e,o,r,i)}insertBoxToBlock(e,o,r){return M6(this,e,o,r)}pasteDoc(e){return this.inputHandlers.pasteDoc(e)}insertDoc(e,o,r,i){V6(this,e,o,r,i)}insertDocAt(e,o,r,i){return Pg(this,e,o,r,i)}deleteChildContainers(e){P6(this,e)}replaceBlockText(e,o){return xh(this,e,o)}updateBlockData(e,o,r){const i={...this.getBlockData(e),...o},{id:s,type:l,...a}=i;return Ih(this,e,a,(r!=null?r:this.selection.range).toDocRange())}updateEmbedData(e,o,r){return U6(this,e,o,r)}updateBoxData(e){RD(this,e)}getSelectedText(){const e=Sh(this);return Ma(this,e)}clearSelectedContents(){Rg(this)}insertTextBlock(e,o,r,i){const s=lr(e!=null?e:"");return F6(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){O6(this);return}o?(this.compositingText="",Vd()||Tg(this,e)):(this.compositingText=e,R6(this))}getColor(e){const o=this.options.colors;return o.length===0?"#FF1A75":o[e%o.length]}}function ja(n,t,e){return new ND(n,t,e)}function $D(n){const t=(o,r)=>{const i=o.findIndex(l=>l.id===r.id);if(i===-1){o.push(r);return}const s=o[i];if(s.value!==r.value){o.splice(i,1);return}if(!!s.states){if(!r.states){s.states=[];return}s.states=fm.default(s.states,r.states)}},e=[];return n.forEach(o=>{o.forEach(r=>{t(e,r)})}),e}const HD=["#FBBFBD","#FFDDB6","#FFF897","#C5F0C1","#CEDDFE","#DCC9FC","#E5E6E8","#F76964","#FFA53D","#FFE928","#63D156","#A0BBFE","#C4A5FB","#BBBFC3"];class Ph extends ye.TypedEmitter{constructor(e){super();m(this,"users",new Map);m(this,"cursors",new Map);m(this,"addingUser",!1);m(this,"colors");this.colors=e&&e.length>0?e:HD}setCursor(e){this.addUser(e.user);const o=this.cursors.get(e.user.userId);if(o&&aa.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&&gh(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(gh(l.range)){const{anchor:a,focus:d}=l.range;a.blockId===e.id&&(a.offset=ln.transformCursor(a.offset,o,r)),d.blockId===e.id&&(d.offset=ln.transformCursor(d.offset,o,r))}})}getFixedUserColor(e,o){let r=0;Array.from(e).forEach(s=>{r+=s.charCodeAt(0)});const i=r%this.colors.length;return this.colors[i]}destroy(){this.removeAllListeners()}}const Xe=S("local-doc");class Xg extends ha{constructor(e,o){super();m(this,"doc");m(this,"serviceUrl");e?this.doc=e:this.doc={meta:{},comments:{},blocks:{root:[lr("")]}},this.serviceUrl=(o==null?void 0:o.serverUrl)||""}beginBatchUpdate(){return 0}endBatchUpdate(){return 0}toJSON(){return mt.default(this.doc)}getContainerBlocks(e){return this.doc.blocks[e]}getBlockData(e,o){const r=this.getContainerBlocks(e);g(Xe,r,`no container data: ${e}`);const i=r[o];return g(Xe,i,`no block data: ${o}`),i}localUpdateBlockText(e,o,r){const i=this.getBlockData(e,o);g(Xe,i.text,"no text for data");const s=ln.apply(i.text,r);return i.text=s,g(Xe,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(l=>{var a;return(a=l.onUpdateBlockText)==null?void 0:a.call(l,e,o,r,!0)}),s}localUpdateBlockData(e,o,r){const i=this.getBlockData(e,o);return r.delete.forEach(s=>delete i[s]),Object.entries(r.insert).forEach(([s,l])=>{i[s]=l}),g(Xe,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockData)==null?void 0:l.call(s,e,o,r,!0)}),i}localInsertBlock(e,o,r){const i=this.getContainerBlocks(e);return g(Xe,i,`no container data: ${e}`),g(Xe,o>=0&&o<=i.length,`invalid block index: ${o}, ${i.length}`),i.splice(o,0,r),g(Xe,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onInsertBlock)==null?void 0:l.call(s,e,o,r,!0)}),r}localDeleteBlock(e,o){const r=this.getContainerBlocks(e);g(Xe,r,`no container data: ${e}`),g(Xe,o>=0&&o<=r.length,`invalid block index: ${o}, ${r.length}`);const i=r[o];return r.splice(o,1),g(Xe,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onDeleteBlock)==null?void 0:l.call(s,e,o,!0)}),i}localInsertChildContainer(e,o){this.doc.blocks[e]=o,g(Xe,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(r=>{var i;return(i=r.onInsertChildContainer)==null?void 0:i.call(r,e,o,!0)})}localDeleteChildContainers(e){Xe.debug(`delete child containers: ${e}`),e.forEach(o=>{g(Xe,this.doc.blocks[o],`no child container: ${o}`),delete this.doc.blocks[o]}),e.forEach(o=>{g(Xe,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(r=>{var i;return(i=r.onDeleteChildContainer)==null?void 0:i.call(r,o,!0)})})}uploadResource(e,o){g(Xe,!1,"not implemented")}async addResources(e){return e}buildResourceUrl(e){return e}request(e,o){g(Xe,!1,"not implemented")}broadcastMessage(e){}getServerMeta(){return{serverId:this.serviceUrl}}getUser(){return{permission:"w",userId:"-",displayName:"-",avatarUrl:"-",rainbowIndex:0}}getRemoteUsers(){return new Ph}setDoc(e){this.doc=mt.default(e),this.callbacks.forEach(o=>{var r;return(r=o.onRequestReload)==null?void 0:r.call(o,"change doc")})}destroy(){this.clearCallbacks()}}class jD{constructor(t){this.cleanup=t}destroy(){var t;(t=this.cleanup)==null||t.call(this)}}function tp(n,t,e){n.addCustom(t,()=>{var i;const o=(i=e())!=null?i:void 0;return new jD(o)})}const ub=S("find-block");function db(n,t){const e=Ts(t);if(!e){if(io(t))return null;const o=xs(t);return g(ub,o,"no parent block"),db(n,o)}return Mt(n,e)?zl(n,e,{visibleOnly:!0}):e}function hb(n,t){const e=Ds(t);if(!e){if(io(t))return null;const o=xs(t);return g(ub,o,"no parent block"),hb(n,o)}return Mt(n,e)?Km(n,e,{visibleOnly:!0}):e}const UD=S("remote-cursor");class zD{constructor(){m(this,"remoteUsers",new Ph)}onCustomMessage(t){const e=t;if(e.type==="onlineUsers"){const o=e;this.handleUpdateUsers(o.users)}else e.type==="caret"?this.handleUpdateCaret(e):UD.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 VD(n){const{blocks:t,meta:e,comments:o,...r}=n;return{rootBlocks:t,meta:e,comments:o,childBlocks:r}}function WD(n){const{blocks:t,meta:e,comments:o}=n,{root:r,...i}=t;return{blocks:r,meta:e,comments:o,...i}}function Ua(n){const{childBlocks:t,meta:e,comments:o,rootBlocks:r}=VD(mt.default(n));return{blocks:{root:r,...t},meta:e,comments:o}}function Ni(n){return n==="root"?"blocks":n}function Kl(n){return n==="blocks"?"root":n}const qD={type:{name:"rich-text",uri:"http://sharejs.org/types/rich-text/v1",create(n){return new on.default(n)},apply(n,t){const e=new on.default(n),o=new on.default(t);return e.compose(o).ops},compose(n,t){const e=new on.default(n),o=new on.default(t);return e.compose(o).ops},diff(n,t){const e=new on.default(n),o=new on.default(t);return e.diff(o).ops},transform(n,t,e){const o=new on.default(n);return new on.default(t).transform(o,e==="left").ops},transformCursor(n,t,e){return t.transformPosition(n,!e)},normalize(n){return n},serialize(n){return n.ops},deserialize(n){return n},transformPresence(n,t,e){if(!n)return null;const o=new on.default(t),r=this.transformCursor(n.index,o,e),i=this.transformCursor(n.index+n.length,o,e);return{...n,index:r,length:i-r}}}};var ar=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},$i={},ep=G5.default.EventEmitter;$i.EventEmitter=ep,$i.mixin=GD;function GD(n){for(var t in ep.prototype)n.prototype[t]=ep.prototype[t]}var fb=["info","warn","error"];function mb(){var n={};fb.forEach(function(t){n[t]=console[t].bind(console)}),this.setMethods(n)}var ZD=mb;mb.prototype.setMethods=function(n){n=n||{};var t=this;fb.forEach(function(e){typeof n[e]=="function"&&(t[e]=n[e])})};var QD=ZD,YD=new QD,gb=YD;function js(n,t){this.code=n,this.message=t||"",Error.captureStackTrace?Error.captureStackTrace(this,js):this.stack=new Error().stack}js.prototype=Object.create(Error.prototype),js.prototype.constructor=js,js.prototype.name="ShareDBError",js.CODES={ERR_APPLY_OP_VERSION_DOES_NOT_MATCH_SNAPSHOT:"ERR_APPLY_OP_VERSION_DOES_NOT_MATCH_SNAPSHOT",ERR_APPLY_SNAPSHOT_NOT_PROVIDED:"ERR_APPLY_SNAPSHOT_NOT_PROVIDED",ERR_CLIENT_ID_BADLY_FORMED:"ERR_CLIENT_ID_BADLY_FORMED",ERR_CANNOT_PING_OFFLINE:"ERR_CANNOT_PING_OFFLINE",ERR_CONNECTION_SEQ_INTEGER_OVERFLOW:"ERR_CONNECTION_SEQ_INTEGER_OVERFLOW",ERR_CONNECTION_STATE_TRANSITION_INVALID:"ERR_CONNECTION_STATE_TRANSITION_INVALID",ERR_DATABASE_ADAPTER_NOT_FOUND:"ERR_DATABASE_ADAPTER_NOT_FOUND",ERR_DATABASE_DOES_NOT_SUPPORT_SUBSCRIBE:"ERR_DATABASE_DOES_NOT_SUPPORT_SUBSCRIBE",ERR_DATABASE_METHOD_NOT_IMPLEMENTED:"ERR_DATABASE_METHOD_NOT_IMPLEMENTED",ERR_DEFAULT_TYPE_MISMATCH:"ERR_DEFAULT_TYPE_MISMATCH",ERR_DOC_MISSING_VERSION:"ERR_DOC_MISSING_VERSION",ERR_DOC_ALREADY_CREATED:"ERR_DOC_ALREADY_CREATED",ERR_DOC_DOES_NOT_EXIST:"ERR_DOC_DOES_NOT_EXIST",ERR_DOC_TYPE_NOT_RECOGNIZED:"ERR_DOC_TYPE_NOT_RECOGNIZED",ERR_DOC_WAS_DELETED:"ERR_DOC_WAS_DELETED",ERR_INFLIGHT_OP_MISSING:"ERR_INFLIGHT_OP_MISSING",ERR_INGESTED_SNAPSHOT_HAS_NO_VERSION:"ERR_INGESTED_SNAPSHOT_HAS_NO_VERSION",ERR_MAX_SUBMIT_RETRIES_EXCEEDED:"ERR_MAX_SUBMIT_RETRIES_EXCEEDED",ERR_MESSAGE_BADLY_FORMED:"ERR_MESSAGE_BADLY_FORMED",ERR_MILESTONE_ARGUMENT_INVALID:"ERR_MILESTONE_ARGUMENT_INVALID",ERR_OP_ALREADY_SUBMITTED:"ERR_OP_ALREADY_SUBMITTED",ERR_OP_NOT_ALLOWED_IN_PROJECTION:"ERR_OP_NOT_ALLOWED_IN_PROJECTION",ERR_OP_SUBMIT_REJECTED:"ERR_OP_SUBMIT_REJECTED",ERR_OP_VERSION_MISMATCH_AFTER_TRANSFORM:"ERR_OP_VERSION_MISMATCH_AFTER_TRANSFORM",ERR_OP_VERSION_MISMATCH_DURING_TRANSFORM:"ERR_OP_VERSION_MISMATCH_DURING_TRANSFORM",ERR_OP_VERSION_NEWER_THAN_CURRENT_SNAPSHOT:"ERR_OP_VERSION_NEWER_THAN_CURRENT_SNAPSHOT",ERR_OT_LEGACY_JSON0_OP_CANNOT_BE_NORMALIZED:"ERR_OT_LEGACY_JSON0_OP_CANNOT_BE_NORMALIZED",ERR_OT_OP_BADLY_FORMED:"ERR_OT_OP_BADLY_FORMED",ERR_OT_OP_NOT_APPLIED:"ERR_OT_OP_NOT_APPLIED",ERR_OT_OP_NOT_PROVIDED:"ERR_OT_OP_NOT_PROVIDED",ERR_PRESENCE_TRANSFORM_FAILED:"ERR_PRESENCE_TRANSFORM_FAILED",ERR_PROTOCOL_VERSION_NOT_SUPPORTED:"ERR_PROTOCOL_VERSION_NOT_SUPPORTED",ERR_QUERY_EMITTER_LISTENER_NOT_ASSIGNED:"ERR_QUERY_EMITTER_LISTENER_NOT_ASSIGNED",ERR_SNAPSHOT_READ_SILENT_REJECTION:"ERR_SNAPSHOT_READ_SILENT_REJECTION",ERR_SNAPSHOT_READS_REJECTED:"ERR_SNAPSHOT_READS_REJECTED",ERR_SUBMIT_TRANSFORM_OPS_NOT_FOUND:"ERR_SUBMIT_TRANSFORM_OPS_NOT_FOUND",ERR_TYPE_CANNOT_BE_PROJECTED:"ERR_TYPE_CANNOT_BE_PROJECTED",ERR_TYPE_DOES_NOT_SUPPORT_PRESENCE:"ERR_TYPE_DOES_NOT_SUPPORT_PRESENCE",ERR_UNKNOWN_ERROR:"ERR_UNKNOWN_ERROR"};var Nh=js,za={},pb=JD;function JD(n,t,e,o){var r=function(s,l,a,d){t(a,s,l,"left"),t(d,l,s,"right")},i=n.transformX=function(s,l){e(s),e(l);for(var a=[],d=0;d<l.length;d++){for(var h=l[d],p=[],A=0;A<s.length;){var v=[];if(r(s[A],h,p,v),A++,v.length===1)h=v[0];else if(v.length===0){for(var B=A;B<s.length;B++)o(p,s[B]);h=null;break}else{for(var D=i(s.slice(A),v),x=0;x<D[0].length;x++)o(p,D[0][x]);for(var _=0;_<D[1].length;_++)o(a,D[1][_]);h=null;break}}h!=null&&o(a,h),s=p}return[s,a]};n.transform=function(s,l,a){if(!(a==="left"||a==="right"))throw new Error("type must be 'left' or 'right'");return l.length===0?s:s.length===1&&l.length===1?t([],s[0],l[0],a):a==="left"?i(s,l)[0]:i(l,s)[1]}}var Cb={exports:{}},Hi=Cb.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||""}},np=function(n,t,e){return n.slice(0,t)+e+n.slice(t)},op=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")},$h=function(n){for(var t=0;t<n.length;t++)op(n[t])};Hi.apply=function(n,t){var e;$h(t);for(var o=0;o<t.length;o++){var r=t[o];if(r.i!=null)n=np(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 Zr=Hi._append=function(n,t){if(!(t.i===""||t.d===""))if(n.length===0)n.push(t);else{var e=n[n.length-1];e.i!=null&&t.i!=null&&e.p<=t.p&&t.p<=e.p+e.i.length?n[n.length-1]={i:np(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:np(t.d,e.p-t.p,e.d),p:t.p}:n.push(t)}};Hi.compose=function(n,t){$h(n),$h(t);for(var e=n.slice(),o=0;o<t.length;o++)Zr(e,t[o]);return e},Hi.normalize=function(n){var t=[];(n.i!=null||n.p!=null)&&(n=[n]);for(var e=0;e<n.length;e++){var o=n[e];o.p==null&&(o.p=0),Zr(t,o)}return t};var rp=function(n,t,e){return t.i!=null?t.p<n||t.p===n&&e?n+t.i.length:n:n<=t.p?n:n<=t.p+t.d.length?t.p:n-t.d.length};Hi.transformCursor=function(n,t,e){for(var o=e==="right",r=0;r<t.length;r++)n=rp(n,t[r],o);return n};var KD=Hi._tc=function(n,t,e,o){if(op(t),op(e),t.i!=null)Zr(n,{i:t.i,p:rp(t.p,e,o==="right")});else if(e.i!=null){var r=t.d;t.p<e.p&&(Zr(n,{d:r.slice(0,e.p-t.p),p:t.p}),r=r.slice(e.p-t.p)),r!==""&&Zr(n,{d:r,p:t.p+e.i.length})}else if(t.p>=e.p+e.d.length)Zr(n,{d:t.d,p:t.p-e.d.length});else if(t.p+t.d.length<=e.p)Zr(n,t);else{var i={d:"",p:t.p};t.p<e.p&&(i.d=t.d.slice(0,e.p-t.p)),t.p+t.d.length>e.p+e.d.length&&(i.d+=t.d.slice(e.p+e.d.length-t.p));var s=Math.max(t.p,e.p),l=Math.min(t.p+t.d.length,e.p+e.d.length),a=t.d.slice(s-t.p,l-t.p),d=e.d.slice(s-e.p,l-e.p);if(a!==d)throw new Error("Delete ops delete different text in the same region of the document");i.d!==""&&(i.p=rp(i.p,e),Zr(n,i))}return n},XD=function(n){return n.i!=null?{d:n.i,p:n.p}:{i:n.d,p:n.p}};Hi.invert=function(n){n=n.slice().reverse();for(var t=0;t<n.length;t++)n[t]=XD(n[t]);return n},pb(Hi,KD,$h,Zr);var Hh=function(n){return Object.prototype.toString.call(n)=="[object Array]"},tS=function(n){return!!n&&n.constructor===Object},Po=function(n){return JSON.parse(JSON.stringify(n))},It={name:"json0",uri:"http://sharejs.org/types/JSONv0"},Qr={};It.registerSubtype=function(n){Qr[n.name]=n},It.create=function(n){return n===void 0?null:Po(n)},It.invertComponent=function(n){var t={p:n.p};return n.t&&Qr[n.t]&&(t.t=n.t,t.o=Qr[n.t].invert(n.o)),n.si!==void 0&&(t.sd=n.si),n.sd!==void 0&&(t.si=n.sd),n.oi!==void 0&&(t.od=n.oi),n.od!==void 0&&(t.oi=n.od),n.li!==void 0&&(t.ld=n.li),n.ld!==void 0&&(t.li=n.ld),n.na!==void 0&&(t.na=-n.na),n.lm!==void 0&&(t.lm=n.p[n.p.length-1],t.p=n.p.slice(0,n.p.length-1).concat([n.lm])),t},It.invert=function(n){for(var t=n.slice().reverse(),e=[],o=0;o<t.length;o++)e.push(It.invertComponent(t[o]));return e},It.checkValidOp=function(n){for(var t=0;t<n.length;t++)if(!Hh(n[t].p))throw new Error("Missing path")},It.checkList=function(n){if(!Hh(n))throw new Error("Referenced element not a list")},It.checkObj=function(n){if(!tS(n))throw new Error("Referenced element not an object (it was "+JSON.stringify(n)+")")};function Va(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 Wa(n){n.p.push(n.o[0].p),n.o[0].i!=null&&(n.si=n.o[0].i),n.o[0].d!=null&&(n.sd=n.o[0].d),delete n.t,delete n.o}It.apply=function(n,t){It.checkValidOp(t),t=Po(t);for(var e={data:n},o=0;o<t.length;o++){var r=t[o];(r.si!=null||r.sd!=null)&&Va(r);for(var i=null,s=e,l="data",a=0;a<r.p.length;a++){var d=r.p[a];if(i=s,s=s[l],l=d,i==null)throw new Error("Path invalid")}if(r.t&&r.o!==void 0&&Qr[r.t])s[l]=Qr[r.t].apply(s[l],r.o);else if(r.na!==void 0){if(typeof s[l]!="number")throw new Error("Referenced element not a number");s[l]+=r.na}else if(r.li!==void 0&&r.ld!==void 0)It.checkList(s),s[l]=r.li;else if(r.li!==void 0)It.checkList(s),s.splice(l,0,r.li);else if(r.ld!==void 0)It.checkList(s),s.splice(l,1);else if(r.lm!==void 0){if(It.checkList(s),r.lm!=l){var h=s[l];s.splice(l,1),s.splice(r.lm,0,h)}}else if(r.oi!==void 0)It.checkObj(s),s[l]=r.oi;else if(r.od!==void 0)It.checkObj(s),delete s[l];else throw new Error("invalid / missing instruction in op")}return e.data},It.shatter=function(n){for(var t=[],e=0;e<n.length;e++)t.push([n[e]]);return t},It.incrementalApply=function(n,t,e){for(var o=0;o<t.length;o++){var r=[t[o]];n=It.apply(n,r),e(r,n)}return n};var eS=It.pathMatches=function(n,t,e){if(n.length!=t.length)return!1;for(var o=0;o<n.length;o++)if(n[o]!==t[o]&&(!e||o!==n.length-1))return!1;return!0};It.append=function(n,t){if(t=Po(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)&&(Va(t),Va(e)),eS(t.p,e.p))if(t.t&&e.t&&t.t===e.t&&Qr[t.t]){if(e.o=Qr[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(),Wa(t),n.push(t);Wa(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)&&(Wa(t),Wa(e)),n.push(t)},It.compose=function(n,t){It.checkValidOp(n),It.checkValidOp(t);for(var e=Po(n),o=0;o<t.length;o++)It.append(e,t[o]);return e},It.normalize=function(n){var t=[];n=Hh(n)?n:[n];for(var e=0;e<n.length;e++){var o=n[e];o.p==null&&(o.p=[]),It.append(t,o)}return t},It.commonLengthForOps=function(n,t){var e=n.p.length,o=t.p.length;if((n.na!=null||n.t)&&e++,(t.na!=null||t.t)&&o++,e===0)return-1;if(o===0)return null;e--,o--;for(var r=0;r<e;r++){var i=n.p[r];if(r>=o||i!==t.p[r])return null}return e},It.canOpAffectPath=function(n,t){return It.commonLengthForOps({p:t},n)!=null},It.transformComponent=function(n,t,e,o){t=Po(t);var r=It.commonLengthForOps(e,t),i=It.commonLengthForOps(t,e),s=t.p.length,l=e.p.length;if((t.na!=null||t.t)&&s++,(e.na!=null||e.t)&&l++,i!=null&&l>s&&t.p[i]==e.p[i]){if(t.ld!==void 0){var a=Po(e);a.p=a.p.slice(s),t.ld=It.apply(Po(t.ld),[a])}else if(t.od!==void 0){var a=Po(e);a.p=a.p.slice(s),t.od=It.apply(Po(t.od),[a])}}if(r!=null){var d=s==l,a=e;if((t.si!=null||t.sd!=null)&&(e.si!=null||e.sd!=null)&&(Va(t),a=Po(e),Va(a)),a.t&&Qr[a.t]){if(t.t&&t.t===a.t){var h=Qr[t.t].transform(t.o,a.o,o);if(t.si!=null||t.sd!=null)for(var p=t.p,A=0;A<h.length;A++)t.o=[h[A]],t.p=p.slice(),Wa(t),It.append(n,t);else(!Hh(h)||h.length>0)&&(t.o=h,It.append(n,t));return n}}else if(e.na===void 0){if(e.li!==void 0&&e.ld!==void 0){if(e.p[r]===t.p[r])if(d){if(t.ld!==void 0)if(t.li!==void 0&&o==="left")t.ld=Po(e.li);else return n}else return n}else if(e.li!==void 0)t.li!==void 0&&t.ld===void 0&&d&&t.p[r]===e.p[r]?o==="right"&&t.p[r]++:e.p[r]<=t.p[r]&&t.p[r]++,t.lm!==void 0&&d&&e.p[r]<=t.lm&&t.lm++;else if(e.ld!==void 0){if(t.lm!==void 0&&d){if(e.p[r]===t.p[r])return n;var p=e.p[r],v=t.p[r],B=t.lm;(p<B||p===B&&v<B)&&t.lm--}if(e.p[r]<t.p[r])t.p[r]--;else if(e.p[r]===t.p[r]){if(l<s)return n;if(t.ld!==void 0)if(t.li!==void 0)delete t.ld;else return n}}else if(e.lm!==void 0)if(t.lm!==void 0&&s===l){var v=t.p[r],B=t.lm,D=e.p[r],x=e.lm;if(D!==x)if(v===D)if(o==="left")t.p[r]=x,v===B&&(t.lm=x);else return n;else v>D&&t.p[r]--,v>x?t.p[r]++:v===x&&D>x&&(t.p[r]++,v===B&&t.lm++),(B>D||B===D&&B>v)&&t.lm--,B>x?t.lm++:B===x&&(x>D&&B>v||x<D&&B<v?o==="right"&&t.lm++:B>v?t.lm++:B===D&&t.lm--)}else if(t.li!==void 0&&t.ld===void 0&&d){var v=e.p[r],B=e.lm;p=t.p[r],p>v&&t.p[r]--,p>B&&t.p[r]++}else{var v=e.p[r],B=e.lm;p=t.p[r],p===v?t.p[r]=B:(p>v&&t.p[r]--,(p>B||p===B&&v>B)&&t.p[r]++)}else if(e.oi!==void 0&&e.od!==void 0){if(t.p[r]===e.p[r])if(t.oi!==void 0&&d){if(o==="right")return n;t.od=e.oi}else return n}else if(e.oi!==void 0){if(t.oi!==void 0&&t.p[r]===e.p[r])if(o==="left")It.append(n,{p:t.p,od:e.oi});else return n}else if(e.od!==void 0&&t.p[r]==e.p[r]){if(!d)return n;if(t.oi!==void 0)delete t.od;else return n}}}return It.append(n,t),n},pb(It,It.transformComponent,It.checkValidOp,It.append);var nS=Cb.exports;It.registerSubtype(nS);var oS=It,rS={type:oS};(function(n){n.defaultType=rS.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)})(za);var No={};(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))}})(No);var Ab=Array.isArray,bb=Object.keys,iS=Object.prototype.hasOwnProperty,sS=function n(t,e){if(t===e)return!0;if(t&&e&&typeof t=="object"&&typeof e=="object"){var o=Ab(t),r=Ab(e),i,s,l;if(o&&r){if(s=t.length,s!=e.length)return!1;for(i=s;i--!==0;)if(!n(t[i],e[i]))return!1;return!0}if(o!=r)return!1;var a=t instanceof Date,d=e instanceof Date;if(a!=d)return!1;if(a&&d)return t.getTime()==e.getTime();var h=t instanceof RegExp,p=e instanceof RegExp;if(h!=p)return!1;if(h&&p)return t.toString()==e.toString();var A=bb(t);if(s=A.length,s!==bb(e).length)return!1;for(i=s;i--!==0;)if(!iS.call(e,A[i]))return!1;for(i=s;i--!==0;)if(l=A[i],!n(t[l],e[l]))return!1;return!0}return t!==t&&e!==e},vb=$i,lS=gb,qn=Nh,jh=za,$o=No,cS=$o.clone,aS=sS,Dn=qn.CODES,uS=Ft;function Ft(n,t,e){vb.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}vb.mixin(Ft),Ft.prototype.destroy=function(n){this._wantsDestroy=!0;var t=this;t.whenNothingPending(function(){t.wantSubscribe?t.unsubscribe(function(e){if(e)return n?n(e):t.emit("error",e);t.connection._destroyDoc(t),n&&n()}):(t.connection._destroyDoc(t),n&&n())})},Ft.prototype._setType=function(n){if(typeof n=="string"&&(n=jh.map[n]),n)this.type=n;else if(n===null)this.type=n,this._setData(void 0);else{var t=new qn(Dn.ERR_DOC_TYPE_NOT_RECOGNIZED,"Missing type "+n);return this.emit("error",t)}},Ft.prototype._setData=function(n){this.data=n,this._dataStateVersion++},Ft.prototype.ingestSnapshot=function(n,t){if(!n)return t&&t();if(typeof n.v!="number"){var e=new qn(Dn.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 qn(Dn.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?jh.defaultType:n.type;this._setType(o),this._setData(this.type&&this.type.deserialize?this.type.deserialize(n.data):n.data),this.emit("load"),t&&t()},Ft.prototype.whenNothingPending=function(n){var t=this;$o.nextTick(function(){if(t.hasPending()){t.once("nothing pending",n);return}n()})},Ft.prototype.hasPending=function(){return!!(this.inflightOp||this.pendingOps.length||this.inflightFetch.length||this.inflightSubscribe||this.pendingFetch.length||this.pendingSubscribe.length)},Ft.prototype.hasWritePending=function(){return!!(this.inflightOp||this.pendingOps.length)},Ft.prototype._emitNothingPending=function(){this.hasWritePending()||(this.emit("no write pending"),!this.hasPending()&&this.emit("nothing pending"))},Ft.prototype._emitResponseError=function(n,t){if(n&&n.code===Dn.ERR_SNAPSHOT_READ_SILENT_REJECTION){this.wantSubscribe=!1,t&&t(),this._emitNothingPending();return}if(t){t(n),this._emitNothingPending();return}this._emitNothingPending(),this.emit("error",n)},Ft.prototype._handleFetch=function(n,t){var e=this.pendingFetch;this.pendingFetch=[];var o=this.inflightFetch.shift();if(o&&e.push(o),e.length&&(o=function(r){$o.callEach(e,r)}),n)return this._emitResponseError(n,o);this.ingestSnapshot(t,o),this._emitNothingPending()},Ft.prototype._handleSubscribe=function(n,t){var e=this.inflightSubscribe;this.inflightSubscribe=null;var o=this.pendingFetch;this.pendingFetch=[],e.callback&&o.push(e.callback);var r;if(o.length&&(r=function(i){$o.callEach(o,i)}),n)return this._emitResponseError(n,r);this.subscribed=e.wantSubscribe,this.subscribed?this.ingestSnapshot(t,r):r&&r(),this._emitNothingPending(),this._flushSubscribe()},Ft.prototype._handleOp=function(n,t){if(n)return this.inflightOp?(n.code===Dn.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=Uh(this.inflightOp,t);if(e)return this._hardRollback(e)}for(var o=0;o<this.pendingOps.length;o++){var e=Uh(this.pendingOps[o],t);if(e)return this._hardRollback(e)}this.version++;try{this._otApply(t,!1)}catch(r){return this._hardRollback(r)}}},Ft.prototype._onConnectionStateChanged=function(){this.connection.canSend?(this.flush(),this._resubscribe()):(this.inflightOp&&(this.pendingOps.unshift(this.inflightOp),this.inflightOp=null),this.subscribed=!1,this.inflightSubscribe&&(this.inflightSubscribe.wantSubscribe?(this.pendingSubscribe.unshift(this.inflightSubscribe),this.inflightSubscribe=null):this._handleSubscribe()),this.inflightFetch.length&&(this.pendingFetch=this.pendingFetch.concat(this.inflightFetch),this.inflightFetch.length=0))},Ft.prototype._resubscribe=function(){if(!this.pendingSubscribe.length&&this.wantSubscribe)return this.subscribe();var n=this.pendingSubscribe.some(function(t){return t.wantSubscribe});!n&&this.pendingFetch.length&&this.fetch(),this._flushSubscribe()},Ft.prototype.fetch=function(n){if(this.connection.canSend){var t=this.connection.sendFetch(this);dS(this.inflightFetch,t,n);return}this.pendingFetch.push(n)},Ft.prototype.subscribe=function(n){var t=!0;this._queueSubscribe(t,n)},Ft.prototype.unsubscribe=function(n){var t=!1;this._queueSubscribe(t,n)},Ft.prototype._queueSubscribe=function(n,t){var e=this.pendingSubscribe[this.pendingSubscribe.length-1]||this.inflightSubscribe,o=e&&e.wantSubscribe===n;if(o){e.callback=hS([e.callback,t]);return}this.pendingSubscribe.push({wantSubscribe:!!n,callback:t}),this._flushSubscribe()},Ft.prototype._flushSubscribe=function(){if(!(this.inflightSubscribe||!this.pendingSubscribe.length)){if(this.connection.canSend){this.inflightSubscribe=this.pendingSubscribe.shift(),this.wantSubscribe=this.inflightSubscribe.wantSubscribe,this.wantSubscribe?this.connection.sendSubscribe(this):(this.subscribed=!1,this.connection.sendUnsubscribe(this));return}if(!this.pendingSubscribe[0].wantSubscribe){this.inflightSubscribe=this.pendingSubscribe.shift();var n=this;$o.nextTick(function(){n._handleSubscribe()})}}};function dS(n,t,e){if(t){var o=n.pop();n.push(function(r){o&&o(r),e&&e(r)})}else n.push(e)}function hS(n){return n=n.filter($o.truthy),n.length?function(t){$o.callEach(n,t)}:null}Ft.prototype.flush=function(){!this.connection.canSend||this.inflightOp||!this.paused&&this.pendingOps.length&&this._sendOp()};function fS(n){delete n.op,delete n.create,delete n.del}function Uh(n,t){if(n.del)return fS(t);if(t.del)return new qn(Dn.ERR_DOC_WAS_DELETED,"Document was deleted");if(t.create)return new qn(Dn.ERR_DOC_ALREADY_CREATED,"Document already created");if("op"in t){if(n.create)return new qn(Dn.ERR_DOC_ALREADY_CREATED,"Document already created");if(n.type.transformX){var e=n.type.transformX(n.op,t.op);n.op=e[0],t.op=e[1]}else{var o=n.type.transform(n.op,t.op,"left"),r=n.type.transform(t.op,n.op,"right");n.op=o,t.op=r}}}Ft.prototype._otApply=function(n,t){if("op"in n){if(!this.type)throw new qn(Dn.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===jh.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=Uh(this.applyStack[s],i);if(l)return this._hardRollback(l)}this._setData(this.type.apply(this.data,i.op)),this.emit("op",i.op,t,n.src)}this.emit("op batch",n.op,t),this._popApplyStack(e);return}this.emit("before op",n.op,t,n.src),this._setData(this.type.apply(this.data,n.op)),this.emit("op",n.op,t,n.src),this.emit("op batch",n.op,t);return}if(n.create){this._setType(n.create.type),this.type.deserialize?this.type.createDeserialized?this._setData(this.type.createDeserialized(n.create.data)):this._setData(this.type.deserialize(this.type.create(n.create.data))):this._setData(this.type.create(n.create.data)),this.emit("create",t);return}if(n.del){var a=this.data;this._setType(null),this.emit("del",a,t);return}},Ft.prototype._sendOp=function(){if(!!this.connection.canSend){var n=this.connection.id;this.inflightOp||(this.inflightOp=this.pendingOps.shift());var t=this.inflightOp;if(!t){var e=new qn(Dn.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>=$o.MAX_SAFE_INTEGER)return this.emit("error",new qn(Dn.ERR_CONNECTION_SEQ_INTEGER_OVERFLOW,"Connection seq has exceeded the max safe integer, maybe from being open for too long"));t.seq=this.connection.seq++}this.connection.sendOp(this,t),t.src==null&&(t.src=n)}},Ft.prototype._submit=function(n,t,e){if(t||(t=!0),"op"in n){if(!this.type){var o=new qn(Dn.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;$o.nextTick(function(){r.flush()})},Ft.prototype._pushOp=function(n,t,e){if(n.source=t,this.applyStack)this.applyStack.push(n);else{var o=this._tryCompose(n);if(o){o.callbacks.push(e);return}}n.type=this.type,n.callbacks=[e],this.pendingOps.push(n)},Ft.prototype._popApplyStack=function(n){if(n>0){this.applyStack.length=n;return}var t=this.applyStack[0];if(this.applyStack=null,!!t){var e=this.pendingOps.indexOf(t);if(e!==-1)for(var o=this.pendingOps.splice(e),e=0;e<o.length;e++){var t=o[e],r=this._tryCompose(t);r?r.callbacks=r.callbacks.concat(t.callbacks):this.pendingOps.push(t)}}},Ft.prototype._tryCompose=function(n){if(!this.preventCompose){var t=this.pendingOps[this.pendingOps.length-1];if(!(!t||t.sentAt)&&!(this.submitSource&&!aS(n.source,t.source))){if(t.create&&"op"in n)return t.create.data=this.type.apply(t.create.data,n.op),t;if("op"in t&&"op"in n&&this.type.compose)return t.op=this.type.compose(t.op,n.op),t}}},Ft.prototype.submitOp=function(n,t,e){typeof t=="function"&&(e=t,t=null);var o={op:n},r=t&&t.source;this._submit(o,r,e)},Ft.prototype.create=function(n,t,e,o){if(typeof t=="function"?(o=t,e=null,t=null):typeof e=="function"&&(o=e,e=null),t||(t=jh.defaultType.uri),this.type){var r=new qn(Dn.ERR_DOC_ALREADY_CREATED,"Document already exists");return o?o(r):this.emit("error",r)}var i={create:{type:t,data:n}},s=e&&e.source;this._submit(i,s,o)},Ft.prototype.del=function(n,t){if(typeof n=="function"&&(t=n,n=null),!this.type){var e=new qn(Dn.ERR_DOC_DOES_NOT_EXIST,"Document does not exist");return t?t(e):this.emit("error",e)}var o={del:!0},r=n&&n.source;this._submit(o,r,t)},Ft.prototype.pause=function(){this.paused=!0},Ft.prototype.resume=function(){this.paused=!1,this.flush()},Ft.prototype.toSnapshot=function(){return{v:this.version,data:cS(this.data),type:this.type.uri}},Ft.prototype._opAcknowledged=function(n){if(this.inflightOp.create)this.version=n.v;else if(n.v!==this.version)return lS.warn("Invalid version from server. Expected: "+this.version+" Received: "+n.v,n),this.fetch();this.version++,this._clearInflightOp()},Ft.prototype._rollback=function(n){var t=this.inflightOp;if("op"in t&&t.type.invert){try{t.op=t.type.invert(t.op)}catch{return this._hardRollback(n)}for(var e=0;e<this.pendingOps.length;e++){var o=Uh(this.pendingOps[e],t);if(o)return this._hardRollback(o)}try{this._otApply(t,!1)}catch(r){return this._hardRollback(r)}this._clearInflightOp(n);return}this._hardRollback(n)},Ft.prototype._hardRollback=function(n){var t=[];this.inflightOp&&t.push(this.inflightOp),t=t.concat(this.pendingOps),this._setType(null),this.version=null,this.inflightOp=null,this.pendingOps=[];var e=this;this.fetch(function(){for(var o=!!t.length,r=0;r<t.length;r++)o=$o.callEach(t[r].callbacks,n)&&o;if(n&&!o)return e.emit("error",n)})},Ft.prototype._clearInflightOp=function(n){var t=this.inflightOp;this.inflightOp=null;var e=$o.callEach(t.callbacks,n);if(this.flush(),this._emitNothingPending(),n&&!e)return this.emit("error",n)};var Us={};Us.ACTIONS={initLegacy:"init",handshake:"hs",queryFetch:"qf",querySubscribe:"qs",queryUnsubscribe:"qu",queryUpdate:"q",bulkFetch:"bf",bulkSubscribe:"bs",bulkUnsubscribe:"bu",fetch:"f",subscribe:"s",unsubscribe:"u",op:"op",snapshotFetch:"nf",snapshotFetchByTimestamp:"nt",pingPong:"pp",presence:"p",presenceSubscribe:"ps",presenceUnsubscribe:"pu",presenceRequest:"pr"};var yb=$i,kb=Us.ACTIONS,mS=No,gS=Sn;function Sn(n,t,e,o,r,i,s){yb.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}yb.mixin(Sn),Sn.prototype.hasPending=function(){return!this.ready},Sn.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}},Sn.prototype.destroy=function(n){this.connection.canSend&&this.action===kb.querySubscribe&&this.connection.send({a:kb.queryUnsubscribe,id:this.id}),this.connection._destroyQuery(this),n&&mS.nextTick(n)},Sn.prototype._onConnectionStateChanged=function(){this.connection.canSend&&!this.sent?this.send():this.sent=!1},Sn.prototype._handleFetch=function(n,t,e){this.connection._destroyQuery(this),this._handleResponse(n,t,e)},Sn.prototype._handleSubscribe=function(n,t,e){this._handleResponse(n,t,e)},Sn.prototype._handleResponse=function(n,t,e){var o=this.callback;if(this.callback=null,n)return this._finishResponse(n,o);if(!t)return this._finishResponse(null,o);var r=this,i=1,s=function(h){if(h)return r._finishResponse(h,o);--i||r._finishResponse(null,o)};if(Array.isArray(t))i+=t.length,this.results=this._ingestSnapshots(t,s),this.extra=e;else for(var l in t){i++;var a=t[l],d=this.connection.get(a.c||this.collection,l);d.ingestSnapshot(a,s)}s()},Sn.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},Sn.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)},Sn.prototype._handleError=function(n){this.emit("error",n)},Sn.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)},Sn.prototype._handleExtra=function(n){this.extra=n,this.emit("extra",n)};var wb=$i,pS=Us.ACTIONS,CS=No,Bb=ur;function ur(n,t){if(wb.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={}}wb.mixin(ur),ur.prototype.submit=function(n,t){this.value=n,this.send(t)},ur.prototype.send=function(n){var t=this._message();this._pendingMessages.push(t),this._callbacksByPresenceVersion[t.pv]=n,this._sendPending()},ur.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()})},ur.prototype._sendPending=function(){if(!!this.connection.canSend){var n=this;this._pendingMessages.forEach(function(t){n.connection.send(t)}),this._pendingMessages=[]}},ur.prototype._ack=function(n,t){var e=this._getCallback(t);this._callbackOrEmit(n,e)},ur.prototype._message=function(){return{a:pS.presence,ch:this.presence.channel,id:this.presenceId,p:this.value,pv:this.presenceVersion++}},ur.prototype._getCallback=function(n){var t=this._callbacksByPresenceVersion[n];return delete this._callbacksByPresenceVersion[n],t},ur.prototype._callbackOrEmit=function(n,t){if(t)return CS.nextTick(t,n);n&&this.emit("error",n)};var AS=No,Eb=ip;function ip(n,t){this.presence=n,this.presenceId=t,this.connection=this.presence.connection,this.value=null,this.presenceVersion=0}ip.prototype.receiveUpdate=function(n){n.pv<this.presenceVersion||(this.value=n.p,this.presenceVersion=n.pv,this.presence._updateRemotePresence(this))},ip.prototype.destroy=function(n){delete this.presence._remotePresenceInstances[this.presenceId],delete this.presence.remotePresences[this.presenceId],n&&AS.nextTick(n)};var sp={exports:{}};(function(n,t){(function(e,o){o(t)})(ar,function(e){function o(k,T){T=T|0;for(var L=Math.max(k.length-T,0),F=Array(L),U=0;U<L;U++)F[U]=k[T+U];return F}var r=function(k){var T=o(arguments,1);return function(){var L=o(arguments);return k.apply(null,T.concat(L))}},i=function(k){return function(){var T=o(arguments),L=T.pop();k.call(this,T,L)}};function s(k){var T=typeof k;return k!=null&&(T=="object"||T=="function")}var l=typeof setImmediate=="function"&&setImmediate,a=typeof process=="object"&&typeof process.nextTick=="function";function d(k){setTimeout(k,0)}function h(k){return function(T){var L=o(arguments,1);k(function(){T.apply(null,L)})}}var p;l?p=setImmediate:a?p=process.nextTick:p=d;var A=h(p);function v(k){return i(function(T,L){var F;try{F=k.apply(this,T)}catch(U){return L(U)}s(F)&&typeof F.then=="function"?F.then(function(U){B(L,null,U)},function(U){B(L,U.message?U:new Error(U))}):L(null,F)})}function B(k,T,L){try{k(T,L)}catch(F){A(D,F)}}function D(k){throw k}var x=typeof Symbol=="function";function _(k){return x&&k[Symbol.toStringTag]==="AsyncFunction"}function M(k){return _(k)?v(k):k}function H(k){return function(T){var L=o(arguments,1),F=i(function(U,j){var Z=this;return k(T,function(J,lt){M(J).apply(Z,U.concat(lt))},j)});return L.length?F.apply(this,L):F}}var z=typeof ar=="object"&&ar&&ar.Object===Object&&ar,q=typeof self=="object"&&self&&self.Object===Object&&self,rt=z||q||Function("return this")(),ft=rt.Symbol,Bt=Object.prototype,jt=Bt.hasOwnProperty,Ut=Bt.toString,ne=ft?ft.toStringTag:void 0;function qe(k){var T=jt.call(k,ne),L=k[ne];try{k[ne]=void 0;var F=!0}catch{}var U=Ut.call(k);return F&&(T?k[ne]=L:delete k[ne]),U}var Yn=Object.prototype,$e=Yn.toString;function Rn(k){return $e.call(k)}var kr="[object Null]",vn="[object Undefined]",an=ft?ft.toStringTag:void 0;function wr(k){return k==null?k===void 0?vn:kr:an&&an in Object(k)?qe(k):Rn(k)}var oi="[object AsyncFunction]",po="[object Function]",X2="[object GeneratorFunction]",t3="[object Proxy]";function e3(k){if(!s(k))return!1;var T=wr(k);return T==po||T==X2||T==oi||T==t3}var ns=9007199254740991;function nl(k){return typeof k=="number"&&k>-1&&k%1==0&&k<=ns}function ol(k){return k!=null&&nl(k.length)&&!e3(k)}var ri={};function Nt(){}function Br(k){return function(){if(k!==null){var T=k;k=null,T.apply(this,arguments)}}}var os=typeof Symbol=="function"&&Symbol.iterator,Fc=function(k){return os&&k[os]&&k[os]()};function s1(k,T){for(var L=-1,F=Array(k);++L<k;)F[L]=T(L);return F}function un(k){return k!=null&&typeof k=="object"}var rl="[object Arguments]";function l1(k){return un(k)&&wr(k)==rl}var Co=Object.prototype,c1=Co.hasOwnProperty,n3=Co.propertyIsEnumerable,il=l1(function(){return arguments}())?l1:function(k){return un(k)&&c1.call(k,"callee")&&!n3.call(k,"callee")},be=Array.isArray;function sl(){return!1}var ll=typeof e=="object"&&e&&!e.nodeType&&e,a1=ll&&!0&&n&&!n.nodeType&&n,cl=a1&&a1.exports===ll,u1=cl?rt.Buffer:void 0,al=u1?u1.isBuffer:void 0,rs=al||sl,ju=9007199254740991,Uu=/^(?:0|[1-9]\d*)$/;function zu(k,T){var L=typeof k;return T=T==null?ju:T,!!T&&(L=="number"||L!="symbol"&&Uu.test(k))&&k>-1&&k%1==0&&k<T}var Vu="[object Arguments]",Wu="[object Array]",qu="[object Boolean]",Gu="[object Date]",Zu="[object Error]",Qu="[object Function]",o3="[object Map]",r3="[object Number]",i3="[object Object]",d1="[object RegExp]",h1="[object Set]",s3="[object String]",l3="[object WeakMap]",c3="[object ArrayBuffer]",a3="[object DataView]",f1="[object Float32Array]",u3="[object Float64Array]",d3="[object Int8Array]",h3="[object Int16Array]",Yu="[object Int32Array]",f3="[object Uint8Array]",Ju="[object Uint8ClampedArray]",m3="[object Uint16Array]",g3="[object Uint32Array]",se={};se[f1]=se[u3]=se[d3]=se[h3]=se[Yu]=se[f3]=se[Ju]=se[m3]=se[g3]=!0,se[Vu]=se[Wu]=se[c3]=se[qu]=se[a3]=se[Gu]=se[Zu]=se[Qu]=se[o3]=se[r3]=se[i3]=se[d1]=se[h1]=se[s3]=se[l3]=!1;function p3(k){return un(k)&&nl(k.length)&&!!se[wr(k)]}function C3(k){return function(T){return k(T)}}var m1=typeof e=="object"&&e&&!e.nodeType&&e,ul=m1&&!0&&n&&!n.nodeType&&n,A3=ul&&ul.exports===m1,Pc=A3&&z.process,g1=function(){try{var k=ul&&ul.require&&ul.require("util").types;return k||Pc&&Pc.binding&&Pc.binding("util")}catch{}}(),p1=g1&&g1.isTypedArray,b3=p1?C3(p1):p3,v3=Object.prototype,y3=v3.hasOwnProperty;function k3(k,T){var L=be(k),F=!L&&il(k),U=!L&&!F&&rs(k),j=!L&&!F&&!U&&b3(k),Z=L||F||U||j,J=Z?s1(k.length,String):[],lt=J.length;for(var pt in k)(T||y3.call(k,pt))&&!(Z&&(pt=="length"||U&&(pt=="offset"||pt=="parent")||j&&(pt=="buffer"||pt=="byteLength"||pt=="byteOffset")||zu(pt,lt)))&&J.push(pt);return J}var Nc=Object.prototype;function w3(k){var T=k&&k.constructor,L=typeof T=="function"&&T.prototype||Nc;return k===L}function $c(k,T){return function(L){return k(T(L))}}var B3=$c(Object.keys,Object),E3=Object.prototype,x3=E3.hasOwnProperty;function C1(k){if(!w3(k))return B3(k);var T=[];for(var L in Object(k))x3.call(k,L)&&L!="constructor"&&T.push(L);return T}function Hc(k){return ol(k)?k3(k):C1(k)}function A1(k){var T=-1,L=k.length;return function(){return++T<L?{value:k[T],key:T}:null}}function I3(k){var T=-1;return function(){var F=k.next();return F.done?null:(T++,{value:F.value,key:T})}}function T3(k){var T=Hc(k),L=-1,F=T.length;return function U(){var j=T[++L];return j==="__proto__"?U():L<F?{value:k[j],key:j}:null}}function D3(k){if(ol(k))return A1(k);var T=Fc(k);return T?I3(T):T3(k)}function Ao(k){return function(){if(k===null)throw new Error("Callback was already called.");var T=k;k=null,T.apply(this,arguments)}}function dl(k){return function(T,L,F){if(F=Br(F||Nt),k<=0||!T)return F(null);var U=D3(T),j=!1,Z=0,J=!1;function lt(ct,At){if(Z-=1,ct)j=!0,F(ct);else{if(At===ri||j&&Z<=0)return j=!0,F(null);J||pt()}}function pt(){for(J=!0;Z<k&&!j;){var ct=U();if(ct===null){j=!0,Z<=0&&F(null);return}Z+=1,L(ct.value,ct.key,Ao(lt))}J=!1}pt()}}function Er(k,T,L,F){dl(T)(k,M(L),F)}function He(k,T){return function(L,F,U){return k(L,T,F,U)}}function Ku(k,T,L){L=Br(L||Nt);var F=0,U=0,j=k.length;j===0&&L(null);function Z(J,lt){J?L(J):(++U===j||lt===ri)&&L(null)}for(;F<j;F++)T(k[F],F,Ao(Z))}var S3=He(Er,1/0),Go=function(k,T,L){var F=ol(k)?Ku:S3;F(k,M(T),L)};function Zo(k){return function(T,L,F){return k(Go,T,M(L),F)}}function Xu(k,T,L,F){F=F||Nt,T=T||[];var U=[],j=0,Z=M(L);k(T,function(J,lt,pt){var ct=j++;Z(J,function(At,Gt){U[ct]=Gt,pt(At)})},function(J){F(J,U)})}var jc=Zo(Xu),td=H(jc);function ii(k){return function(T,L,F,U){return k(dl(L),T,M(F),U)}}var xr=ii(Xu),ed=He(xr,1),nd=H(ed);function is(k,T){for(var L=-1,F=k==null?0:k.length;++L<F&&T(k[L],L,k)!==!1;);return k}function od(k){return function(T,L,F){for(var U=-1,j=Object(T),Z=F(T),J=Z.length;J--;){var lt=Z[k?J:++U];if(L(j[lt],lt,j)===!1)break}return T}}var ss=od();function ls(k,T){return k&&ss(k,T,Hc)}function b1(k,T,L,F){for(var U=k.length,j=L+(F?1:-1);F?j--:++j<U;)if(T(k[j],j,k))return j;return-1}function L3(k){return k!==k}function v1(k,T,L){for(var F=L-1,U=k.length;++F<U;)if(k[F]===T)return F;return-1}function hl(k,T,L){return T===T?v1(k,T,L):b1(k,L3,L)}var Uc=function(k,T,L){typeof T=="function"&&(L=T,T=null),L=Br(L||Nt);var F=Hc(k),U=F.length;if(!U)return L(null);T||(T=U);var j={},Z=0,J=!1,lt=Object.create(null),pt=[],ct=[],At={};ls(k,function(de,re){if(!be(de)){Gt(re,[de]),ct.push(re);return}var ge=de.slice(0,de.length-1),vo=ge.length;if(vo===0){Gt(re,de),ct.push(re);return}At[re]=vo,is(ge,function(E){if(!k[E])throw new Error("async.auto task `"+re+"` has a non-existent dependency `"+E+"` in "+ge.join(", "));en(E,function(){vo--,vo===0&&Gt(re,de)})})}),X3(),Te();function Gt(de,re){pt.push(function(){bo(de,re)})}function Te(){if(pt.length===0&&Z===0)return L(null,j);for(;pt.length&&Z<T;){var de=pt.shift();de()}}function en(de,re){var ge=lt[de];ge||(ge=lt[de]=[]),ge.push(re)}function Fn(de){var re=lt[de]||[];is(re,function(ge){ge()}),Te()}function bo(de,re){if(!J){var ge=Ao(function(E,Dr){if(Z--,arguments.length>2&&(Dr=o(arguments,1)),E){var ds={};ls(j,function(Pn,Pt){ds[Pt]=Pn}),ds[de]=Dr,J=!0,lt=Object.create(null),L(E,ds)}else j[de]=Dr,Fn(de)});Z++;var vo=M(re[re.length-1]);re.length>1?vo(j,ge):vo(ge)}}function X3(){for(var de,re=0;ct.length;)de=ct.pop(),re++,is(t5(de),function(ge){--At[ge]===0&&ct.push(ge)});if(re!==U)throw new Error("async.auto cannot execute tasks due to a recursive dependency")}function t5(de){var re=[];return ls(k,function(ge,vo){be(ge)&&hl(ge,de,0)>=0&&re.push(vo)}),re}};function si(k,T){for(var L=-1,F=k==null?0:k.length,U=Array(F);++L<F;)U[L]=T(k[L],L,k);return U}var M3="[object Symbol]";function R3(k){return typeof k=="symbol"||un(k)&&wr(k)==M3}var O3=1/0,rd=ft?ft.prototype:void 0,y1=rd?rd.toString:void 0;function id(k){if(typeof k=="string")return k;if(be(k))return si(k,id)+"";if(R3(k))return y1?y1.call(k):"";var T=k+"";return T=="0"&&1/k==-O3?"-0":T}function _3(k,T,L){var F=-1,U=k.length;T<0&&(T=-T>U?0:U+T),L=L>U?U:L,L<0&&(L+=U),U=T>L?0:L-T>>>0,T>>>=0;for(var j=Array(U);++F<U;)j[F]=k[F+T];return j}function F3(k,T,L){var F=k.length;return L=L===void 0?F:L,!T&&L>=F?k:_3(k,T,L)}function sd(k,T){for(var L=k.length;L--&&hl(T,k[L],0)>-1;);return L}function P3(k,T){for(var L=-1,F=k.length;++L<F&&hl(T,k[L],0)>-1;);return L}function N3(k){return k.split("")}var $3="\\ud800-\\udfff",H3="\\u0300-\\u036f",j3="\\ufe20-\\ufe2f",le="\\u20d0-\\u20ff",oe=H3+j3+le,U3="\\ufe0e\\ufe0f",z3="\\u200d",V3=RegExp("["+z3+$3+oe+U3+"]");function W3(k){return V3.test(k)}var k1="\\ud800-\\udfff",q3="\\u0300-\\u036f",w1="\\ufe20-\\ufe2f",G3="\\u20d0-\\u20ff",Ge=q3+w1+G3,ld="\\ufe0e\\ufe0f",li="["+k1+"]",zc="["+Ge+"]",fl="\\ud83c[\\udffb-\\udfff]",On="(?:"+zc+"|"+fl+")",cd="[^"+k1+"]",ad="(?:\\ud83c[\\udde6-\\uddff]){2}",ud="[\\ud800-\\udbff][\\udc00-\\udfff]",B1="\\u200d",dd=On+"?",hd="["+ld+"]?",yn="(?:"+B1+"(?:"+[cd,ad,ud].join("|")+")"+hd+dd+")*",Z3=hd+dd+yn,_n="(?:"+[cd+zc+"?",zc,ad,ud,li].join("|")+")",Q3=RegExp(fl+"(?="+fl+")|"+_n+Z3,"g");function E1(k){return k.match(Q3)||[]}function Qo(k){return W3(k)?E1(k):N3(k)}function Vc(k){return k==null?"":id(k)}var fd=/^\s+|\s+$/g;function ue(k,T,L){if(k=Vc(k),k&&(L||T===void 0))return k.replace(fd,"");if(!k||!(T=id(T)))return k;var F=Qo(k),U=Qo(T),j=P3(F,U),Z=sd(F,U)+1;return F3(F,j,Z).join("")}var Ir=/^(?:async\s+)?(function)?\s*[^\(]*\(\s*([^\)]*)\)/m,md=/,/,Y3=/(=.+)?(\s*)$/,gd=/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;function J3(k){return k=k.toString().replace(gd,""),k=k.match(Ir)[2].replace(" ",""),k=k?k.split(md):[],k=k.map(function(T){return ue(T.replace(Y3,""))}),k}function x1(k,T){var L={};ls(k,function(F,U){var j,Z=_(F),J=!Z&&F.length===1||Z&&F.length===0;if(be(F))j=F.slice(0,-1),F=F[F.length-1],L[U]=j.concat(j.length>0?lt:F);else if(J)L[U]=F;else{if(j=J3(F),F.length===0&&!Z&&j.length===0)throw new Error("autoInject task functions require explicit parameters.");Z||j.pop(),L[U]=j.concat(lt)}function lt(pt,ct){var At=si(j,function(Gt){return pt[Gt]});At.push(ct),M(F).apply(null,At)}}),Uc(L,T)}function Jn(){this.head=this.tail=null,this.length=0}function pd(k,T){k.length=1,k.head=k.tail=T}Jn.prototype.removeLink=function(k){return k.prev?k.prev.next=k.next:this.head=k.next,k.next?k.next.prev=k.prev:this.tail=k.prev,k.prev=k.next=null,this.length-=1,k},Jn.prototype.empty=function(){for(;this.head;)this.shift();return this},Jn.prototype.insertAfter=function(k,T){T.prev=k,T.next=k.next,k.next?k.next.prev=T:this.tail=T,k.next=T,this.length+=1},Jn.prototype.insertBefore=function(k,T){T.prev=k.prev,T.next=k,k.prev?k.prev.next=T:this.head=T,k.prev=T,this.length+=1},Jn.prototype.unshift=function(k){this.head?this.insertBefore(this.head,k):pd(this,k)},Jn.prototype.push=function(k){this.tail?this.insertAfter(this.tail,k):pd(this,k)},Jn.prototype.shift=function(){return this.head&&this.removeLink(this.head)},Jn.prototype.pop=function(){return this.tail&&this.removeLink(this.tail)},Jn.prototype.toArray=function(){for(var k=Array(this.length),T=this.head,L=0;L<this.length;L++)k[L]=T.data,T=T.next;return k},Jn.prototype.remove=function(k){for(var T=this.head;T;){var L=T.next;k(T)&&this.removeLink(T),T=L}return this};function ml(k,T,L){if(T==null)T=1;else if(T===0)throw new Error("Concurrency must not be zero");var F=M(k),U=0,j=[],Z=!1;function J(At,Gt,Te){if(Te!=null&&typeof Te!="function")throw new Error("task callback must be a function");if(ct.started=!0,be(At)||(At=[At]),At.length===0&&ct.idle())return A(function(){ct.drain()});for(var en=0,Fn=At.length;en<Fn;en++){var bo={data:At[en],callback:Te||Nt};Gt?ct._tasks.unshift(bo):ct._tasks.push(bo)}Z||(Z=!0,A(function(){Z=!1,ct.process()}))}function lt(At){return function(Gt){U-=1;for(var Te=0,en=At.length;Te<en;Te++){var Fn=At[Te],bo=hl(j,Fn,0);bo===0?j.shift():bo>0&&j.splice(bo,1),Fn.callback.apply(Fn,arguments),Gt!=null&&ct.error(Gt,Fn.data)}U<=ct.concurrency-ct.buffer&&ct.unsaturated(),ct.idle()&&ct.drain(),ct.process()}}var pt=!1,ct={_tasks:new Jn,concurrency:T,payload:L,saturated:Nt,unsaturated:Nt,buffer:T/4,empty:Nt,drain:Nt,error:Nt,started:!1,paused:!1,push:function(At,Gt){J(At,!1,Gt)},kill:function(){ct.drain=Nt,ct._tasks.empty()},unshift:function(At,Gt){J(At,!0,Gt)},remove:function(At){ct._tasks.remove(At)},process:function(){if(!pt){for(pt=!0;!ct.paused&&U<ct.concurrency&&ct._tasks.length;){var At=[],Gt=[],Te=ct._tasks.length;ct.payload&&(Te=Math.min(Te,ct.payload));for(var en=0;en<Te;en++){var Fn=ct._tasks.shift();At.push(Fn),j.push(Fn),Gt.push(Fn.data)}U+=1,ct._tasks.length===0&&ct.empty(),U===ct.concurrency&&ct.saturated();var bo=Ao(lt(At));F(Gt,bo)}pt=!1}},length:function(){return ct._tasks.length},running:function(){return U},workersList:function(){return j},idle:function(){return ct._tasks.length+U===0},pause:function(){ct.paused=!0},resume:function(){ct.paused!==!1&&(ct.paused=!1,A(ct.process))}};return ct}function ci(k,T){return ml(k,1,T)}var cs=He(Er,1);function Yo(k,T,L,F){F=Br(F||Nt);var U=M(L);cs(k,function(j,Z,J){U(T,j,function(lt,pt){T=pt,J(lt)})},function(j){F(j,T)})}function Wc(){var k=si(arguments,M);return function(){var T=o(arguments),L=this,F=T[T.length-1];typeof F=="function"?T.pop():F=Nt,Yo(k,T,function(U,j,Z){j.apply(L,U.concat(function(J){var lt=o(arguments,1);Z(J,lt)}))},function(U,j){F.apply(L,[U].concat(j))})}}var qc=function(){return Wc.apply(null,o(arguments).reverse())},Cd=Array.prototype.concat,gl=function(k,T,L,F){F=F||Nt;var U=M(L);xr(k,T,function(j,Z){U(j,function(J){return J?Z(J):Z(null,o(arguments,1))})},function(j,Z){for(var J=[],lt=0;lt<Z.length;lt++)Z[lt]&&(J=Cd.apply(J,Z[lt]));return F(j,J)})},I1=He(gl,1/0),Gc=He(gl,1),Zc=function(){var k=o(arguments),T=[null].concat(k);return function(){var L=arguments[arguments.length-1];return L.apply(this,T)}};function pl(k){return k}function ai(k,T){return function(L,F,U,j){j=j||Nt;var Z=!1,J;L(F,function(lt,pt,ct){U(lt,function(At,Gt){At?ct(At):k(Gt)&&!J?(Z=!0,J=T(!0,lt),ct(null,ri)):ct()})},function(lt){lt?j(lt):j(null,Z?J:T(!1))})}}function dn(k,T){return T}var as=Zo(ai(pl,dn)),Jo=ii(ai(pl,dn)),Cl=He(Jo,1);function Ad(k){return function(T){var L=o(arguments,1);L.push(function(F){var U=o(arguments,1);typeof console=="object"&&(F?console.error&&console.error(F):console[k]&&is(U,function(j){console[k](j)}))}),M(T).apply(null,L)}}var T1=Ad("dir");function D1(k,T,L){L=Ao(L||Nt);var F=M(k),U=M(T);function j(J){if(J)return L(J);var lt=o(arguments,1);lt.push(Z),U.apply(this,lt)}function Z(J,lt){if(J)return L(J);if(!lt)return L(null);F(j)}Z(null,!0)}function bd(k,T,L){L=Ao(L||Nt);var F=M(k),U=function(j){if(j)return L(j);var Z=o(arguments,1);if(T.apply(this,Z))return F(U);L.apply(null,[null].concat(Z))};F(U)}function S1(k,T,L){bd(k,function(){return!T.apply(this,arguments)},L)}function L1(k,T,L){L=Ao(L||Nt);var F=M(T),U=M(k);function j(J){if(J)return L(J);U(Z)}function Z(J,lt){if(J)return L(J);if(!lt)return L(null);F(j)}U(Z)}function ui(k){return function(T,L,F){return k(T,F)}}function Qc(k,T,L){Go(k,ui(M(T)),L)}function Al(k,T,L,F){dl(T)(k,ui(M(L)),F)}var di=He(Al,1);function Yc(k){return _(k)?k:i(function(T,L){var F=!0;T.push(function(){var U=arguments;F?A(function(){L.apply(null,U)}):L.apply(null,U)}),k.apply(this,T),F=!1})}function Kn(k){return!k}var hi=Zo(ai(Kn,Kn)),bl=ii(ai(Kn,Kn)),Jc=He(bl,1);function M1(k){return function(T){return T==null?void 0:T[k]}}function us(k,T,L,F){var U=new Array(T.length);k(T,function(j,Z,J){L(j,function(lt,pt){U[Z]=!!pt,J(lt)})},function(j){if(j)return F(j);for(var Z=[],J=0;J<T.length;J++)U[J]&&Z.push(T[J]);F(null,Z)})}function Xn(k,T,L,F){var U=[];k(T,function(j,Z,J){L(j,function(lt,pt){lt?J(lt):(pt&&U.push({index:Z,value:j}),J())})},function(j){j?F(j):F(null,si(U.sort(function(Z,J){return Z.index-J.index}),M1("value")))})}function Kc(k,T,L,F){var U=ol(T)?us:Xn;U(k,T,M(L),F||Nt)}var Xc=Zo(Kc),vl=ii(Kc),ta=He(vl,1);function R1(k,T){var L=Ao(T||Nt),F=M(Yc(k));function U(j){if(j)return L(j);F(U)}U()}var ea=function(k,T,L,F){F=F||Nt;var U=M(L);xr(k,T,function(j,Z){U(j,function(J,lt){return J?Z(J):Z(null,{key:lt,val:j})})},function(j,Z){for(var J={},lt=Object.prototype.hasOwnProperty,pt=0;pt<Z.length;pt++)if(Z[pt]){var ct=Z[pt].key,At=Z[pt].val;lt.call(J,ct)?J[ct].push(At):J[ct]=[At]}return F(j,J)})},fi=He(ea,1/0),N=He(ea,1),G=Ad("log");function V(k,T,L,F){F=Br(F||Nt);var U={},j=M(L);Er(k,T,function(Z,J,lt){j(Z,J,function(pt,ct){if(pt)return lt(pt);U[J]=ct,lt()})},function(Z){F(Z,U)})}var ht=He(V,1/0),Et=He(V,1);function Vt(k,T){return T in k}function we(k,T){var L=Object.create(null),F=Object.create(null);T=T||pl;var U=M(k),j=i(function(J,lt){var pt=T.apply(null,J);Vt(L,pt)?A(function(){lt.apply(null,L[pt])}):Vt(F,pt)?F[pt].push(lt):(F[pt]=[lt],U.apply(null,J.concat(function(){var ct=o(arguments);L[pt]=ct;var At=F[pt];delete F[pt];for(var Gt=0,Te=At.length;Gt<Te;Gt++)At[Gt].apply(null,ct)})))});return j.memo=L,j.unmemoized=k,j}var qt;a?qt=process.nextTick:l?qt=setImmediate:qt=d;var na=h(qt);function vd(k,T,L){L=L||Nt;var F=ol(T)?[]:{};k(T,function(U,j,Z){M(U)(function(J,lt){arguments.length>2&&(lt=o(arguments,1)),F[j]=lt,Z(J)})},function(U){L(U,F)})}function kn(k,T){vd(Go,k,T)}function yl(k,T,L){vd(dl(T),k,L)}var yd=function(k,T){var L=M(k);return ml(function(F,U){L(F[0],U)},T,1)},mi=function(k,T){var L=yd(k,T);return L.push=function(F,U,j){if(j==null&&(j=Nt),typeof j!="function")throw new Error("task callback must be a function");if(L.started=!0,be(F)||(F=[F]),F.length===0)return A(function(){L.drain()});U=U||0;for(var Z=L._tasks.head;Z&&U>=Z.priority;)Z=Z.next;for(var J=0,lt=F.length;J<lt;J++){var pt={data:F[J],priority:U,callback:j};Z?L._tasks.insertBefore(Z,pt):L._tasks.push(pt)}A(L.process)},delete L.unshift,L};function kl(k,T){if(T=Br(T||Nt),!be(k))return T(new TypeError("First argument to race must be an array of functions"));if(!k.length)return T();for(var L=0,F=k.length;L<F;L++)M(k[L])(T)}function gi(k,T,L,F){var U=o(k).reverse();Yo(U,T,L,F)}function Wt(k){var T=M(k);return i(function(F,U){return F.push(function(Z,J){if(Z)U(null,{error:Z});else{var lt;arguments.length<=2?lt=J:lt=o(arguments,1),U(null,{value:lt})}}),T.apply(this,F)})}function O1(k){var T;return be(k)?T=si(k,Wt):(T={},ls(k,function(L,F){T[F]=Wt.call(this,L)})),T}function kd(k,T,L,F){Kc(k,T,function(U,j){L(U,function(Z,J){j(Z,!J)})},F)}var wl=Zo(kd),wd=ii(kd),_1=He(wd,1);function F1(k){return function(){return k}}function pi(k,T,L){var F=5,U=0,j={times:F,intervalFunc:F1(U)};function Z(ct,At){if(typeof At=="object")ct.times=+At.times||F,ct.intervalFunc=typeof At.interval=="function"?At.interval:F1(+At.interval||U),ct.errorFilter=At.errorFilter;else if(typeof At=="number"||typeof At=="string")ct.times=+At||F;else throw new Error("Invalid arguments for async.retry")}if(arguments.length<3&&typeof k=="function"?(L=T||Nt,T=k):(Z(j,k),L=L||Nt),typeof T!="function")throw new Error("Invalid arguments for async.retry");var J=M(T),lt=1;function pt(){J(function(ct){ct&<++<j.times&&(typeof j.errorFilter!="function"||j.errorFilter(ct))?setTimeout(pt,j.intervalFunc(lt)):L.apply(null,arguments)})}pt()}var Ko=function(k,T){T||(T=k,k=null);var L=M(T);return i(function(F,U){function j(Z){L.apply(null,F.concat(Z))}k?pi(k,j,U):pi(j,U)})};function Bl(k,T){vd(cs,k,T)}var El=Zo(ai(Boolean,pl)),Tr=ii(ai(Boolean,pl)),xl=He(Tr,1);function Bd(k,T,L){var F=M(T);jc(k,function(j,Z){F(j,function(J,lt){if(J)return Z(J);Z(null,{value:j,criteria:lt})})},function(j,Z){if(j)return L(j);L(null,si(Z.sort(U),M1("value")))});function U(j,Z){var J=j.criteria,lt=Z.criteria;return J<lt?-1:J>lt?1:0}}function Il(k,T,L){var F=M(k);return i(function(U,j){var Z=!1,J;function lt(){var pt=k.name||"anonymous",ct=new Error('Callback function "'+pt+'" timed out.');ct.code="ETIMEDOUT",L&&(ct.info=L),Z=!0,j(ct)}U.push(function(){Z||(j.apply(null,arguments),clearTimeout(J))}),J=setTimeout(lt,T),F.apply(null,U)})}var P1=Math.ceil,Tl=Math.max;function Ci(k,T,L,F){for(var U=-1,j=Tl(P1((T-k)/(L||1)),0),Z=Array(j);j--;)Z[F?j:++U]=k,k+=L;return Z}function Ai(k,T,L,F){var U=M(L);xr(Ci(0,k,1),T,U,F)}var N1=He(Ai,1/0),$1=He(Ai,1);function H1(k,T,L,F){arguments.length<=3&&(F=L,L=T,T=be(k)?[]:{}),F=Br(F||Nt);var U=M(L);Go(k,function(j,Z,J){U(T,j,Z,J)},function(j){F(j,T)})}function Dl(k,T){var L=null,F;T=T||Nt,di(k,function(U,j){M(U)(function(Z,J){arguments.length>2?F=o(arguments,1):F=J,L=Z,j(!Z)})},function(){T(L,F)})}function Sl(k){return function(){return(k.unmemoized||k).apply(null,arguments)}}function Ll(k,T,L){L=Ao(L||Nt);var F=M(T);if(!k())return L(null);var U=function(j){if(j)return L(j);if(k())return F(U);var Z=o(arguments,1);L.apply(null,[null].concat(Z))};F(U)}function j1(k,T,L){Ll(function(){return!k.apply(this,arguments)},T,L)}var Ed=function(k,T){if(T=Br(T||Nt),!be(k))return T(new Error("First argument to waterfall must be an array of functions"));if(!k.length)return T();var L=0;function F(j){var Z=M(k[L++]);j.push(Ao(U)),Z.apply(null,j)}function U(j){if(j||L===k.length)return T.apply(null,arguments);F(o(arguments,1))}F([])},K3={apply:r,applyEach:td,applyEachSeries:nd,asyncify:v,auto:Uc,autoInject:x1,cargo:ci,compose:qc,concat:I1,concatLimit:gl,concatSeries:Gc,constant:Zc,detect:as,detectLimit:Jo,detectSeries:Cl,dir:T1,doDuring:D1,doUntil:S1,doWhilst:bd,during:L1,each:Qc,eachLimit:Al,eachOf:Go,eachOfLimit:Er,eachOfSeries:cs,eachSeries:di,ensureAsync:Yc,every:hi,everyLimit:bl,everySeries:Jc,filter:Xc,filterLimit:vl,filterSeries:ta,forever:R1,groupBy:fi,groupByLimit:ea,groupBySeries:N,log:G,map:jc,mapLimit:xr,mapSeries:ed,mapValues:ht,mapValuesLimit:V,mapValuesSeries:Et,memoize:we,nextTick:na,parallel:kn,parallelLimit:yl,priorityQueue:mi,queue:yd,race:kl,reduce:Yo,reduceRight:gi,reflect:Wt,reflectAll:O1,reject:wl,rejectLimit:wd,rejectSeries:_1,retry:pi,retryable:Ko,seq:Wc,series:Bl,setImmediate:A,some:El,someLimit:Tr,someSeries:xl,sortBy:Bd,timeout:Il,times:N1,timesLimit:Ai,timesSeries:$1,transform:H1,tryEach:Dl,unmemoize:Sl,until:j1,waterfall:Ed,whilst:Ll,all:hi,allLimit:bl,allSeries:Jc,any:El,anyLimit:Tr,anySeries:xl,find:as,findLimit:Jo,findSeries:Cl,forEach:Qc,forEachSeries:di,forEachLimit:Al,forEachOf:Go,forEachOfSeries:cs,forEachOfLimit:Er,inject:Yo,foldl:Yo,foldr:gi,select:Xc,selectLimit:vl,selectSeries:ta,wrapSync:v};e.default=K3,e.apply=r,e.applyEach=td,e.applyEachSeries=nd,e.asyncify=v,e.auto=Uc,e.autoInject=x1,e.cargo=ci,e.compose=qc,e.concat=I1,e.concatLimit=gl,e.concatSeries=Gc,e.constant=Zc,e.detect=as,e.detectLimit=Jo,e.detectSeries=Cl,e.dir=T1,e.doDuring=D1,e.doUntil=S1,e.doWhilst=bd,e.during=L1,e.each=Qc,e.eachLimit=Al,e.eachOf=Go,e.eachOfLimit=Er,e.eachOfSeries=cs,e.eachSeries=di,e.ensureAsync=Yc,e.every=hi,e.everyLimit=bl,e.everySeries=Jc,e.filter=Xc,e.filterLimit=vl,e.filterSeries=ta,e.forever=R1,e.groupBy=fi,e.groupByLimit=ea,e.groupBySeries=N,e.log=G,e.map=jc,e.mapLimit=xr,e.mapSeries=ed,e.mapValues=ht,e.mapValuesLimit=V,e.mapValuesSeries=Et,e.memoize=we,e.nextTick=na,e.parallel=kn,e.parallelLimit=yl,e.priorityQueue=mi,e.queue=yd,e.race=kl,e.reduce=Yo,e.reduceRight=gi,e.reflect=Wt,e.reflectAll=O1,e.reject=wl,e.rejectLimit=wd,e.rejectSeries=_1,e.retry=pi,e.retryable=Ko,e.seq=Wc,e.series=Bl,e.setImmediate=A,e.some=El,e.someLimit=Tr,e.someSeries=xl,e.sortBy=Bd,e.timeout=Il,e.times=N1,e.timesLimit=Ai,e.timesSeries=$1,e.transform=H1,e.tryEach=Dl,e.unmemoize=Sl,e.until=j1,e.waterfall=Ed,e.whilst=Ll,e.all=hi,e.allLimit=bl,e.allSeries=Jc,e.any=El,e.anyLimit=Tr,e.anySeries=xl,e.find=as,e.findLimit=Jo,e.findSeries=Cl,e.forEach=Qc,e.forEachSeries=di,e.forEachLimit=Al,e.forEachOf=Go,e.forEachOfSeries=cs,e.forEachOfLimit=Er,e.inject=Yo,e.foldl=Yo,e.foldr=gi,e.select=Xc,e.selectLimit=vl,e.selectSeries=ta,e.wrapSync=v,Object.defineProperty(e,"__esModule",{value:!0})})})(sp,sp.exports);var xb={exports:{}},lp=xb.exports=function(n,t){if(t||(t=16),n===void 0&&(n=128),n<=0)return"0";for(var e=Math.log(Math.pow(2,n))/Math.log(t),o=2;e===1/0;o*=2)e=Math.log(Math.pow(2,n/o))/Math.log(t)*o;for(var r=e-Math.floor(e),i="",o=0;o<Math.floor(e);o++){var s=Math.floor(Math.random()*t).toString(t);i=s+i}if(r){var l=Math.pow(t,r),s=Math.floor(Math.random()*l).toString(t);i=s+i}var a=parseInt(i,t);return a!==1/0&&a>=Math.pow(2,n)?lp(n,t):i};lp.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=lp(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 Ib=$i,bS=Bb,vS=Eb,zh=No,cp=sp.exports,yS=xb.exports,Tb=Us.ACTIONS,Db=Re;function Re(n,t){if(Ib.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}Ib.mixin(Re),Re.prototype.subscribe=function(n){this._sendSubscriptionAction(!0,n)},Re.prototype.unsubscribe=function(n){this._sendSubscriptionAction(!1,n)},Re.prototype.create=function(n){if(this._wantsDestroy)throw new Error("Presence is being destroyed");n=n||yS();var t=this._createLocalPresence(n);return this.localPresences[n]=t,t},Re.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);cp.parallel([function(i){cp.each(e,function(s,l){t.localPresences[s].destroy(l)},i)},function(i){if(!t._wantsDestroy)return i();cp.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)})})},Re.prototype._sendSubscriptionAction=function(n,t){this.wantSubscribe=!!n;var e=this.wantSubscribe?Tb.presenceSubscribe:Tb.presenceUnsubscribe,o=this.connection._presenceSeq++;this._subscriptionCallbacksBySeq[o]=t,this.connection.canSend&&this.connection._sendPresenceAction(e,o,this)},Re.prototype._handleSubscribe=function(n,t){this.wantSubscribe&&(this.subscribed=!0);var e=this._subscriptionCallback(t);this._callbackOrEmit(n,e)},Re.prototype._handleUnsubscribe=function(n,t){this.subscribed=!1;var e=this._subscriptionCallback(t);this._callbackOrEmit(n,e)},Re.prototype._receiveUpdate=function(n,t){var e=zh.dig(this.localPresences,t.id);if(e)return e._ack(n,t.pv);if(n)return this.emit("error",n);var o=this,r=zh.digOrCreate(this._remotePresenceInstances,t.id,function(){return o._createRemotePresence(t.id)});r.receiveUpdate(t)},Re.prototype._updateRemotePresence=function(n){this.remotePresences[n.presenceId]=n.value,n.value===null&&this._removeRemotePresence(n.presenceId),this.emit("receive",n.presenceId,n.value)},Re.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()}},Re.prototype._removeRemotePresence=function(n){this._remotePresenceInstances[n].destroy(),delete this._remotePresenceInstances[n],delete this.remotePresences[n]},Re.prototype._onConnectionStateChanged=function(){if(!!this.connection.canSend){this._resubscribe();for(var n in this.localPresences)this.localPresences[n]._sendPending()}},Re.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)})},Re.prototype._subscriptionCallback=function(n){var t=this._subscriptionCallbacksBySeq[n];return delete this._subscriptionCallbacksBySeq[n],t},Re.prototype._callbackOrEmit=function(n,t){if(t)return zh.nextTick(t,n);n&&this.emit("error",n)},Re.prototype._createLocalPresence=function(n){return new bS(this,n)},Re.prototype._createRemotePresence=function(n){return new vS(this,n)},Re.prototype._callEachOrEmit=function(n,t){var e=zh.callEach(n,t);!e&&t&&this.emit("error",t)};var qa=Bb,Sb=Nh,kS=No,Lb=Sb.CODES,wS=Ho;function Ho(n,t){qa.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()}Ho.prototype=Object.create(qa.prototype),Ho.prototype.submit=function(n,t){if(!this._doc.type){if(n===null)return this._callbackOrEmit(null,t);var e={code:Lb.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,qa.prototype.submit.call(this,n,t)},Ho.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),qa.prototype.destroy.call(this,n)},Ho.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={})})}},Ho.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)},Ho.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)}},Ho.prototype._handleCreateOrDel=function(){this._pendingMessages.forEach(function(n){n.p=null}),this.value=null},Ho.prototype._handleLoad=function(){this.value=null,this._pendingMessages=[],this._docDataVersionByPresenceVersion={}},Ho.prototype._message=function(){var n=qa.prototype._message.call(this);return n.c=this.collection,n.d=this.id,n.v=null,n.t=null,n},Ho.prototype._transformPresence=function(n,t,e){var o=this._doc.type;if(!kS.supportsPresence(o))throw new Sb(Lb.ERR_TYPE_DOES_NOT_SUPPORT_PRESENCE,"Type does not support presence: "+o.name);return o.transformPresence(n,t,e)};var Mb={};(function(n){var t=za,e=Nh,o=No,r=e.CODES;n.checkOp=function(l){if(l==null||typeof l!="object")return new e(r.ERR_OT_OP_BADLY_FORMED,"Op must be an object");if(l.create!=null){if(typeof l.create!="object")return new e(r.ERR_OT_OP_BADLY_FORMED,"Create data must be an object");var a=l.create.type;if(typeof a!="string")return new e(r.ERR_OT_OP_BADLY_FORMED,"Missing create type");var d=t.map[a];if(d==null||typeof d!="object")return new e(r.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type")}else if(l.del!=null){if(l.del!==!0)return new e(r.ERR_OT_OP_BADLY_FORMED,"del value must be true")}else if(!("op"in l))return new e(r.ERR_OT_OP_BADLY_FORMED,"Missing op, create, or del");if(l.src!=null&&typeof l.src!="string")return new e(r.ERR_OT_OP_BADLY_FORMED,"src must be a string");if(l.seq!=null&&typeof l.seq!="number")return new e(r.ERR_OT_OP_BADLY_FORMED,"seq must be a number");if(l.src==null&&l.seq!=null||l.src!=null&&l.seq==null)return new e(r.ERR_OT_OP_BADLY_FORMED,"Both src and seq must be set together");if(l.m!=null&&typeof l.m!="object")return new e(r.ERR_OT_OP_BADLY_FORMED,"op.m must be an object or null")},n.normalizeType=function(l){return t.map[l]&&t.map[l].uri},n.apply=function(l,a){if(typeof l!="object")return new e(r.ERR_APPLY_SNAPSHOT_NOT_PROVIDED,"Missing snapshot");if(l.v!=null&&a.v!=null&&l.v!==a.v)return new e(r.ERR_APPLY_OP_VERSION_DOES_NOT_MATCH_SNAPSHOT,"Version mismatch");if(a.create){if(l.type)return new e(r.ERR_DOC_ALREADY_CREATED,"Document already exists");var d=a.create,h=t.map[d.type];if(!h)return new e(r.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type");try{l.data=h.create(d.data),l.type=h.uri,l.v++}catch(A){return A}}else if(a.del)l.data=void 0,l.type=null,l.v++;else if("op"in a){var p=i(l,a.op);if(p)return p;l.v++}else l.v++};function i(l,a){if(!l.type)return new e(r.ERR_DOC_DOES_NOT_EXIST,"Document does not exist");if(a===void 0)return new e(r.ERR_OT_OP_NOT_PROVIDED,"Missing op");var d=t.map[l.type];if(!d)return new e(r.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type");try{l.data=d.apply(l.data,a)}catch(h){return new e(r.ERR_OT_OP_NOT_APPLIED,h.message)}}n.transform=function(l,a,d){if(a.v!=null&&a.v!==d.v)return new e(r.ERR_OP_VERSION_MISMATCH_DURING_TRANSFORM,"Version mismatch");if(d.del){if(a.create||"op"in a)return new e(r.ERR_DOC_WAS_DELETED,"Document was deleted")}else{if(d.create&&("op"in a||a.create||a.del)||"op"in d&&a.create)return new e(r.ERR_DOC_ALREADY_CREATED,"Document was created remotely");if("op"in d&&"op"in a){if(!l)return new e(r.ERR_DOC_DOES_NOT_EXIST,"Document does not exist");if(typeof l=="string"&&(l=t.map[l],!l))return new e(r.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type");try{a.op=l.transform(a.op,d.op,"left")}catch(h){return h}}}a.v!=null&&a.v++},n.applyOps=function(l,a,d){d=d||{};for(var h=0;h<a.length;h++){var p=a[h];if(d._normalizeLegacyJson0Ops)try{s(l,p)}catch{return new e(r.ERR_OT_LEGACY_JSON0_OP_CANNOT_BE_NORMALIZED,"Cannot normalize legacy json0 op")}l.v=p.v;var A=n.apply(l,p);if(A)return A}},n.transformPresence=function(l,a,d){var h=this.checkOp(a);if(h)return h;var p=l.t;if(typeof p=="string"&&(p=t.map[p]),!p)return{code:r.ERR_DOC_TYPE_NOT_RECOGNIZED,message:"Unknown type"};if(!o.supportsPresence(p))return{code:r.ERR_TYPE_DOES_NOT_SUPPORT_PRESENCE,message:"Type does not support presence"};if(a.create||a.del){l.p=null,l.v++;return}try{l.p=l.p===null?null:p.transformPresence(l.p,a.op,d)}catch(A){return{code:r.ERR_PRESENCE_TRANSFORM_FAILED,message:A.message||A}}l.v++};function s(l,a){if(l.type===t.defaultType.uri){var d=a.op;if(!!d){var h=l.data;d.length>1&&(h=o.clone(h));for(var p=0;p<d.length;p++){var A=d[p];typeof A.lm=="string"&&(A.lm=+A.lm);for(var v=A.p,B=h,D=0;D<v.length;D++){var x=v[D];Object.prototype.toString.call(B)=="[object Array]"?v[D]=+x:B.constructor===Object&&(v[D]=x.toString()),B=B[x]}p<d.length-1&&(h=t.defaultType.apply(h,[A]))}}}}})(Mb);var Ga=Eb,BS=Mb,ES=ao;function ao(n,t){Ga.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()}ao.prototype=Object.create(Ga.prototype),ao.prototype.receiveUpdate=function(n){this._pending&&n.pv<this._pending.pv||(this.src=n.src,this._pending=n,this._setPendingPresence())},ao.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),Ga.prototype.destroy.call(this,n)},ao.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)},ao.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))}})}},ao.prototype._handleOp=function(n,t,e){var o=e===this.src;this._transformAgainstOp(n,o),this._cacheOp(n,o),this._setPendingPresence()},Ga.prototype._handleCreateDel=function(){this._cacheOp(null),this._setPendingPresence()},Ga.prototype._handleLoad=function(){this.value=null,this._pending=null,this._opCache=null,this.presence._updateRemotePresence(this)},ao.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)}},ao.prototype._catchUpStalePresence=function(){if(this._pending.v>=this._doc.version)return!0;if(!this._opCache)return this._startCachingOps(),this._doc.fetch(),this.presence.subscribe(),!1;for(;this._opCache[this._pending.v];){var n=this._opCache[this._pending.v],t=n.op,e=n.isOwnOp;t===null?(this._pending.p=null,this._pending.v++):BS.transformPresence(this._pending,t,e)}var o=this._pending.v>=this._doc.version;return o&&this._stopCachingOps(),o},ao.prototype._startCachingOps=function(){this._opCache=[]},ao.prototype._stopCachingOps=function(){this._opCache=null},ao.prototype._cacheOp=function(n,t){this._opCache&&(n=n?{op:n}:null,this._opCache[this._doc.version-1]={op:n,isOwnOp:t})};var Rb=Db,xS=wS,IS=ES;function Xl(n,t,e){var o=Xl.channel(t,e);Rb.call(this,n,o),this.collection=t,this.id=e}var TS=Xl;Xl.prototype=Object.create(Rb.prototype),Xl.channel=function(n,t){return n+"."+t},Xl.prototype._createLocalPresence=function(n){return new xS(this,n)},Xl.prototype._createRemotePresence=function(n){return new IS(this,n)};var DS=SS;function SS(n,t,e,o,r){this.id=n,this.v=t,this.type=e,this.data=o,this.m=r}var LS=DS,Ob=$i,_b=Za;function Za(n,t,e,o,r){if(Ob.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}Ob.mixin(Za),Za.prototype.send=function(){!this.connection.canSend||(this.connection.send(this._message()),this.sent=!0)},Za.prototype._onConnectionStateChanged=function(){this.connection.canSend?this.sent||this.send():this.sent=!1},Za.prototype._handleResponse=function(n,t){if(this.emit("ready"),n)return this.callback(n);var e=t.meta?t.meta:null,o=new LS(this.id,t.v,t.type,t.data,e);this.callback(null,o)};var Fb=_b,MS=No,RS=Us.ACTIONS,OS=ap;function ap(n,t,e,o,r,i){if(Fb.call(this,n,t,e,o,i),!MS.isValidVersion(r))throw new Error("Snapshot version must be a positive integer or null");this.version=r}ap.prototype=Object.create(Fb.prototype),ap.prototype._message=function(){return{a:RS.snapshotFetch,id:this.requestId,c:this.collection,d:this.id,v:this.version}};var Pb=_b,_S=No,FS=Us.ACTIONS,PS=up;function up(n,t,e,o,r,i){if(Pb.call(this,n,t,e,o,i),!_S.isValidTimestamp(r))throw new Error("Snapshot timestamp must be a positive integer or null");this.timestamp=r}up.prototype=Object.create(Pb.prototype),up.prototype._message=function(){return{a:FS.snapshotFetchByTimestamp,id:this.requestId,c:this.collection,d:this.id,ts:this.timestamp}};var NS=uS,$S=gS,HS=Db,Nb=TS,jS=OS,US=PS,$b=$i,tc=Nh,ee=Us.ACTIONS,Hb=za,jo=No,Qa=gb,Ya=tc.CODES;function jb(n){return n.readyState===0||n.readyState===1?"connecting":"disconnected"}var zS=wt;function wt(n){$b.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=jb(n),this.bindToSocket(n)}$b.mixin(wt),wt.prototype.bindToSocket=function(n){this.socket&&(this.socket.close(),this.socket.onmessage=null,this.socket.onopen=null,this.socket.onerror=null,this.socket.onclose=null),this.socket=n;var t=jb(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{Qa.warn("Failed to parse message",o);return}e.debug&&Qa.info("RECV",JSON.stringify(r));var i={data:r};if(e.emit("receive",i),!!i.data)try{e.handleMessage(i.data)}catch(s){jo.nextTick(function(){e.emit("error",s)})}},n.readyState===1&&e._initializeHandshake(),n.onopen=function(){e._setState("connecting"),e._initializeHandshake()},n.onerror=function(o){e.emit("connection error",o)},n.onclose=function(o){o==="closed"||o==="Closed"?e._setState("closed",o):o==="stopped"||o==="Stopped by server"?e._setState("stopped",o):e._setState("disconnected",o)}},wt.prototype.handleMessage=function(n){var t=null;switch(n.error&&(t=Ub(n.error,n),delete n.error),n.a){case ee.initLegacy:return this._handleLegacyInit(n);case ee.handshake:return this._handleHandshake(t,n);case ee.queryFetch:var e=this.queries[n.id];e&&e._handleFetch(t,n.data,n.extra);return;case ee.querySubscribe:var e=this.queries[n.id];e&&e._handleSubscribe(t,n.data,n.extra);return;case ee.queryUnsubscribe:return;case ee.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 ee.bulkFetch:return this._handleBulkMessage(t,n,"_handleFetch");case ee.bulkSubscribe:case ee.bulkUnsubscribe:return this._handleBulkMessage(t,n,"_handleSubscribe");case ee.snapshotFetch:case ee.snapshotFetchByTimestamp:return this._handleSnapshotFetch(t,n);case ee.fetch:var o=this.getExisting(n.c,n.d);o&&o._handleFetch(t,n.data);return;case ee.subscribe:case ee.unsubscribe:var o=this.getExisting(n.c,n.d);o&&o._handleSubscribe(t,n.data);return;case ee.op:var o=this.getExisting(n.c,n.d);o&&o._handleOp(t,n);return;case ee.presence:return this._handlePresence(t,n);case ee.presenceSubscribe:return this._handlePresenceSubscribe(t,n);case ee.presenceUnsubscribe:return this._handlePresenceUnsubscribe(t,n);case ee.presenceRequest:return this._handlePresenceRequest(t,n);case ee.pingPong:return this._handlePingPong(t);default:Qa.warn("Ignoring unrecognized message",n)}};function Ub(n,t){var e=new Error(n.message);return e.code=n.code,t&&(e.data=t),e}wt.prototype._handleBulkMessage=function(n,t,e){if(t.data)for(var o in t.data){var r=t.data[o],i=this.getExisting(t.c,o);i&&(n?i[e](n):r.error?i[e](Ub(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 Qa.error("Invalid bulk message",t)},wt.prototype._reset=function(){this.agent=null},wt.prototype._setState=function(n,t){if(this.state!==n){if(n==="connecting"&&this.state!=="disconnected"&&this.state!=="stopped"&&this.state!=="closed"||n==="connected"&&this.state!=="connecting"){var e=new tc(Ya.ERR_CONNECTION_STATE_TRANSITION_INVALID,"Cannot transition directly from "+this.state+" to "+n);return this.emit("error",e)}this.state=n,this.canSend=n==="connected",(n==="disconnected"||n==="stopped"||n==="closed")&&this._reset(),this.startBulk();for(var o in this.queries){var r=this.queries[o];r._onConnectionStateChanged()}for(var i in this.collections){var s=this.collections[i];for(var o in s)s[o]._onConnectionStateChanged()}for(var l in this._presences)this._presences[l]._onConnectionStateChanged();for(var o in this._snapshotRequests){var a=this._snapshotRequests[o];a._onConnectionStateChanged()}this.endBulk(),this.emit(n,t),this.emit("state",n,t)}},wt.prototype.startBulk=function(){this.bulk||(this.bulk={})},wt.prototype.endBulk=function(){if(this.bulk)for(var n in this.bulk){var t=this.bulk[n];this._sendBulk("f",n,t.f),this._sendBulk("s",n,t.s),this._sendBulk("u",n,t.u)}this.bulk=null},wt.prototype._sendBulk=function(n,t,e){if(!!e){var o=[],r={},i=0,s;for(var l in e){var a=e[l];a==null?o.push(l):(r[l]=a,s=l,i++)}if(o.length===1){var l=o[0];this.send({a:n,c:t,d:l})}else o.length&&this.send({a:"b"+n,c:t,b:o});if(i===1){var d=r[s];this.send({a:n,c:t,d:s,v:d})}else i&&this.send({a:"b"+n,c:t,b:r})}},wt.prototype._sendActions=function(n,t,e){if(this._addDoc(t),this.bulk){var o=this.bulk[t.collection]||(this.bulk[t.collection]={}),r=o[n]||(o[n]={}),i=r.hasOwnProperty(t.id);return r[t.id]=e,i}else{var s={a:n,c:t.collection,d:t.id,v:e};this.send(s)}},wt.prototype.sendFetch=function(n){return this._sendActions(ee.fetch,n,n.version)},wt.prototype.sendSubscribe=function(n){return this._sendActions(ee.subscribe,n,n.version)},wt.prototype.sendUnsubscribe=function(n){return this._sendActions(ee.unsubscribe,n)},wt.prototype.sendOp=function(n,t){this._addDoc(n);var e={a:ee.op,c:n.collection,d:n.id,v:n.version,src:t.src,seq:t.seq,x:{}};"op"in t&&(e.op=t.op),t.create&&(e.create=t.create),t.del&&(e.del=t.del),n.submitSource&&(e.x.source=t.source),this.send(e)},wt.prototype.send=function(n){this.debug&&Qa.info("SEND",JSON.stringify(n)),this.emit("send",n),this.socket.send(JSON.stringify(n))},wt.prototype.ping=function(){if(!this.canSend)throw new tc(Ya.ERR_CANNOT_PING_OFFLINE,"Socket must be CONNECTED to ping");var n={a:ee.pingPong};this.send(n)},wt.prototype.close=function(){this.socket.close()},wt.prototype.getExisting=function(n,t){if(this.collections[n])return this.collections[n][t]},wt.prototype.get=function(n,t){var e=this.collections[n]||(this.collections[n]={}),o=e[t];return o||(o=e[t]=new NS(this,n,t),this.emit("doc",o)),o._wantsDestroy=!1,o},wt.prototype._destroyDoc=function(n){!n._wantsDestroy||(jo.digAndRemove(this.collections,n.collection,n.id),n.emit("destroy"))},wt.prototype._addDoc=function(n){var t=this.collections[n.collection];t||(t=this.collections[n.collection]={}),t[n.id]!==n&&(t[n.id]=n)},wt.prototype._createQuery=function(n,t,e,o,r){var i=this.nextQueryId++,s=new $S(n,this,i,t,e,o,r);return this.queries[i]=s,s.send(),s},wt.prototype._destroyQuery=function(n){delete this.queries[n.id]},wt.prototype.createFetchQuery=function(n,t,e,o){return this._createQuery(ee.queryFetch,n,t,e,o)},wt.prototype.createSubscribeQuery=function(n,t,e,o){return this._createQuery(ee.querySubscribe,n,t,e,o)},wt.prototype.hasPending=function(){return!!(this._firstDoc(Vh)||this._firstQuery(Vh)||this._firstSnapshotRequest())};function Vh(n){return n.hasPending()}wt.prototype.hasWritePending=function(){return!!this._firstDoc(VS)};function VS(n){return n.hasWritePending()}wt.prototype.whenNothingPending=function(n){var t=this._firstDoc(Vh);if(t){t.once("nothing pending",this._nothingPendingRetry(n));return}var e=this._firstQuery(Vh);if(e){e.once("ready",this._nothingPendingRetry(n));return}var o=this._firstSnapshotRequest();if(o){o.once("ready",this._nothingPendingRetry(n));return}jo.nextTick(n)},wt.prototype._nothingPendingRetry=function(n){var t=this;return function(){jo.nextTick(function(){t.whenNothingPending(n)})}},wt.prototype._firstDoc=function(n){for(var t in this.collections){var e=this.collections[t];for(var o in e){var r=e[o];if(n(r))return r}}},wt.prototype._firstQuery=function(n){for(var t in this.queries){var e=this.queries[t];if(n(e))return e}},wt.prototype._firstSnapshotRequest=function(){for(var n in this._snapshotRequests)return this._snapshotRequests[n]},wt.prototype.fetchSnapshot=function(n,t,e,o){typeof e=="function"&&(o=e,e=null);var r=this.nextSnapshotRequestId++,i=new jS(this,r,n,t,e,o);this._snapshotRequests[i.requestId]=i,i.send()},wt.prototype.fetchSnapshotByTimestamp=function(n,t,e,o){typeof e=="function"&&(o=e,e=null);var r=this.nextSnapshotRequestId++,i=new US(this,r,n,t,e,o);this._snapshotRequests[i.requestId]=i,i.send()},wt.prototype._handleSnapshotFetch=function(n,t){var e=this._snapshotRequests[t.id];!e||(delete this._snapshotRequests[t.id],e._handleResponse(n,t))},wt.prototype._handleLegacyInit=function(n){if(n.protocolMinor)return this._initializeHandshake();this._initialize(n)},wt.prototype._initializeHandshake=function(){this.send({a:ee.handshake,id:this.id})},wt.prototype._handleHandshake=function(n,t){if(n)return this.emit("error",n);this._initialize(t)},wt.prototype._handlePingPong=function(n){if(n)return this.emit("error",n);this.emit("pong")},wt.prototype._initialize=function(n){if(this.state==="connecting"){if(n.protocol!==1)return this.emit("error",new tc(Ya.ERR_PROTOCOL_VERSION_NOT_SUPPORTED,"Unsupported protocol version: "+n.protocol));if(Hb.map[n.type]!==Hb.defaultType)return this.emit("error",new tc(Ya.ERR_DEFAULT_TYPE_MISMATCH,n.type+" does not match the server default type"));if(typeof n.id!="string")return this.emit("error",new tc(Ya.ERR_CLIENT_ID_BADLY_FORMED,"Client id must be a string"));this.id=n.id,this._setState("connected")}},wt.prototype.getPresence=function(n){var t=this,e=jo.digOrCreate(this._presences,n,function(){return new HS(t,n)});return e._wantsDestroy=!1,e},wt.prototype.getDocPresence=function(n,t){var e=Nb.channel(n,t),o=this,r=jo.digOrCreate(this._presences,e,function(){return new Nb(o,n,t)});return r._wantsDestroy=!1,r},wt.prototype._sendPresenceAction=function(n,t,e){this._addPresence(e);var o={a:n,ch:e.channel,seq:t};return this.send(o),o.seq},wt.prototype._addPresence=function(n){jo.digOrCreate(this._presences,n.channel,function(){return n})},wt.prototype._handlePresenceSubscribe=function(n,t){var e=jo.dig(this._presences,t.ch);e&&e._handleSubscribe(n,t.seq)},wt.prototype._handlePresenceUnsubscribe=function(n,t){var e=jo.dig(this._presences,t.ch);e&&e._handleUnsubscribe(n,t.seq)},wt.prototype._handlePresence=function(n,t){var e=jo.dig(this._presences,t.ch);e&&e._receiveUpdate(n,t)},wt.prototype._handlePresenceRequest=function(n,t){var e=jo.dig(this._presences,t.ch);e&&e._broadcastAllLocalPresence(n,t)};var zb=zS,WS=za;const Wh={err:1001,msg:"user auth error",name:"AuthError"},qS={err:1002,msg:"you don't have required permission",name:"PermissionError"},dp={err:1003,msg:"Too many user connected",name:"MaxUserError"},Ja={err:1004,msg:"document server changed, reload it",name:"RequestReloadError"},GS={err:1005,msg:"app id must be at least 2 chars, doc id must be at least 5 chars",name:"DocIdError"},ZS={err:1028,msg:"upload file ext not allowed",name:"FileExtError"},Ka="x-live-editor-token",qh="x-live-editor-base-url",pn=S("auth-connection");function QS(n){try{n()}catch(t){pn.error(t)}}class YS{constructor(t,e){m(this,"connection");m(this,"ws");m(this,"retryCount");m(this,"events",new W5.EventEmitter);m(this,"token",null);m(this,"resourceToken",null);this.url=t,this.reauthFunc=e,this.retryCount=0}getBaseURL(){const t=new URL(this.url);return`${t.protocol==="wss:"?"https:":"http:"}//${t.host}${t.pathname}`}getBase64BaseURL(){return Si(this.getBaseURL())}async auth(t){g(pn,t.token,"no auth token");const e=`${this.getBaseURL()}/auth`,o=await window.fetch(e,{method:"GET",headers:{[Ka]:t.token,[qh]: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:{[qh]:Si(this.getBaseURL())}})}async init(t){const e=await this.auth(t);this.resourceToken=e.read,this.ws=new VB.default(this.url,void 0,{maxReconnectionDelay:2500,minReconnectionDelay:1e3}),this.connection=Object.create(zb.prototype),g(pn,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}}},zb.apply(this.connection,[this.ws])}async handleAuthError(){if(this.reauthFunc&&this.retryCount<5){this.retryCount+=1,pn.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){pn.error(t),setTimeout(()=>this.handleAuthError(),0)}}else pn.error("auth error, cannot retry anymore"),this.emitAuthError(),this.end(!1)}emitAuthError(){const t=new Error(Wh.msg);t.code=Wh.err,this.events.emit("error",t)}emitRequestReloadError(){const t=new Error(Ja.msg);t.code=Ja.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===Wh.err)pn.warn("auth error"),this.handleAuthError();else if(o===dp.err)pn.warn(dp.msg),this.emitMaxUsersError();else if(o===Ja.err){pn.warn(Ja.msg);try{this.emitRequestReloadError()}catch(r){pn.error(`error occurred while process reload error: ${JSON.stringify(r)}`)}finally{this.end(!1)}}else pn.error(`unknown message received: ${JSON.stringify(e)}`),this.emitAuthError()}get(t,e){return g(pn,this.connection,"no this.connection"),this.connection.get(t,e)}addEventListener(t,e){t==="error"?this.events.addListener(t,e):(g(pn,this.ws,"no this.ws"),this.ws.addEventListener(t,e))}onWriteConflictError(t){this.events.addListener("writeConflictError",t)}onMaxUsersError(t){g(pn,this.events.listenerCount("maxUsersError")===0,"too many maxUserError listener"),this.events.addListener("maxUsersError",t)}onRequestReloadError(t){g(pn,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(),QS(()=>{var o;return(o=this.connection)==null?void 0:o.close()}),this.connection=void 0,(e=this.ws)==null||e.close(),this.ws=void 0,t&&this.logout()}}S("utils/file");function JS(){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}JS();async function KS(n){const e=n.size,o=Math.floor((e+102400-1)/102400),r=new WB.Hash;for(let s=0;s<o;s++){const l=s*102400;let a=l+102400;a>e&&(a=e);const h=await n.slice(l,a,n.type).arrayBuffer();r.update(new Uint8Array(h))}const i=r.digest();return Si(i)}const dr=S("sharedb-doc/client");class XS{constructor(t,e,o){m(this,"connection");m(this,"auth");m(this,"doc",null);m(this,"reauthFunc");m(this,"clientId",K());m(this,"getDoc",async()=>{const t=o=>new Promise((r,i)=>{o.fetch(s=>{s?i(s):r()})});g(dr,!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),dr.debug(e),e});this.auth=t;const r=`${e}/${this.auth.appId}/${this.auth.docId}`;WS.register(Fd.type),this.connection=new YS(r,o),this.reauthFunc=o}editorServer(){const t=this.apiServer(),e=`/${this.auth.appId}/${this.auth.docId}`;return g(dr,t.endsWith(e),`invalid api server: ${t}, ${e}`),t.substr(0,t.length-e.length)}close(t){this.connection.end(t),this.doc=null}on(t,e){this.connection.addEventListener(t,o=>{(t==="error"||this.doc)&&e(o)})}onWriteConflictError(t){this.connection.onWriteConflictError(t)}onMaxUsersError(t){this.connection.onMaxUsersError(t)}onRequestReloadError(t){this.connection.onRequestReloadError(t)}async authOnly(){await this.connection.auth(this.auth)}getResourceToken(){return this.connection.resourceToken}hasDocContainer(){return!!this.doc}apiServer(){const t=this.connection.url;if(t.startsWith("ws://"))return`http://${t.substring(5)}`;if(t.startsWith("wss://"))return`https://${t.substring(6)}`;throw new Error(`invalid server url: ${t}`)}async getFileUrlByHash(t,e,o,r,i){try{const s=`${t}/${e}`,l=await this.request(s,{method:"post",headers:{...i},data:{name:o,size:r}});return l.data&&Array.isArray(l.data)&&l.data.length===1?l.data[0]:""}catch{return""}}async getFileUrlsByHashes(t){const o=`${this.apiServer()}/resources`;let r=[];t.forEach(l=>{const a=l.split("|");r.push(...a)}),r=Array.from(new Set(r));const i=r.map(l=>this.getFileUrlByHash(o,l,"",0,{[Ka]:this.connection.token}));return await Promise.all(i)}async uploadFile(t,e,o,r,i){let s=e.size;if(s===0)throw new Error("file is empty");s+=500;const l=v=>{dr.info(`on progress: ${v.loaded}`);let B=v.loaded*100/s;B>100&&(B=100),r(B)},a=await KS(e),d=await this.getFileUrlByHash(t,a,e.name,e.size,o);if(d)return r(-1),d;let h=t;i!=null&&i.thumbnail&&(h+="/thumbnail");const p=new FormData;p.append("file-size",`${e.size}`),p.append("file-hash",a),p.append("file",e,e.name);const A=await this.request(h,{method:"post",data:p,withCredentials:!0,headers:{...o},onUploadProgress:l});return dr.info(A),r(100),Array.isArray(A.data)?A.data[0]:A.data}async uploadResource(t,e=()=>{},o){const i=`${this.apiServer()}/resources`;g(dr,this.connection.token,"no connection token");const s=await this.uploadFile(i,t,{[Ka]:this.connection.token},e,o);return g(dr,s,"no result"),s}async request(t,e){var i,s;let o=this.connection.token,r;for(let l=0;l<2;l++){const a=e||{};a.url=t,a.headers||(a.headers={}),g(dr,o,"no token"),a.headers={...a.headers,[Ka]:o,[qh]:this.connection.getBase64BaseURL()};try{return await UB.default(t,a)}catch(d){if(r=d,((i=d==null?void 0:d.response)==null?void 0:i.status)===403&&this.reauthFunc){const h=await this.reauthFunc();if(await this.connection.auth(h),!h.token)throw d;o=h.token;continue}throw(s=d.response)!=null&&s.data&&(d.responseData=d.response.data),d}}throw g(dr,r,"no error"),r}async getVersions(){const e=`${this.apiServer()}/versions?withExtra=true`,r=(await this.request(e)).data.versions;return r.forEach(i=>{i.extra&&(i.extra=JSON.parse(i.extra))}),r}async getVersion(t){const o=`${this.apiServer()}/versions/${t}`,r=await this.request(o);return JSON.parse(r.data.data)}async getLatestVersion(){const e=`${this.apiServer()}/versions/latest`,o=await this.request(e);return JSON.parse(o.data.data)}async getVersionOps(t,e){let r=`${this.apiServer()}/versions/before/${t}?withOp=true`;e!==void 0&&e!==0&&(r+=`&from=${e}`);const i=await this.request(r),s=i.data.ops,l=zB.default(s,h=>!!h.create);let a=null;l!==-1&&(a=s[l],s.splice(0,l+1));let d;return a?(g(dr,a.create,"no createDoc.create"),d=a.create.data):d=JSON.parse(i.data.data),d.blocks||(d.blocks=[]),{doc:d,ops:i.data.ops}}async updateVersionExtra(t,e,o){const i=`${this.apiServer()}/versions/${t}/tags/${e}`;await this.request(i,{method:"post",data:{extra:JSON.stringify(o)}})}async revertVersion(t){const o=`${this.apiServer()}/versions/revert/${t}`;await this.request(o,{method:"post",data:{}})}async createVersion(t,e){const r=`${this.apiServer()}/versions`;return(await this.request(r,{method:"post",data:{publish:e,tag:t}})).data}async recognizeLink(t){const o=`${this.apiServer()}/resources/external/${Si(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 tL(){return{blocks:[{id:K(),type:"text",text:[]}],comments:{},meta:{}}}const hp=S("block-ids");class eL{constructor(){m(this,"ids",new Map)}onInsertBlock(t){const e=Array.from(this.ids.keys()).sort((r,i)=>i-r);for(let r=0;r<e.length;r++){const i=e[r];if(i>=t){const s=this.ids.get(i);g(hp,s!==void 0,"old id is not exists"),this.ids.delete(i),this.ids.set(i+1,s)}}const o=K();this.ids.set(t,o)}onDeleteBlock(t){this.ids.delete(t);const e=Array.from(this.ids.keys()).sort((o,r)=>o-r);for(let o=0;o<e.length;o++){const r=e[o];if(r>t){const i=this.ids.get(r);g(hp,i!==void 0,"old id is not exists"),this.ids.delete(r),this.ids.set(r-1,i)}}}getId(t){let e=this.ids.get(t);return e||(e=K(),this.ids.set(t,e)),e}getById(t){return Array.from(this.ids.entries()).find(([,e])=>e===t)}}class nL{constructor(){m(this,"ids",new Map)}getContainerIds(t){let e=this.ids.get(t);return e||(e=new eL,this.ids.set(t,e)),e}onInsertBlock(t,e){this.getContainerIds(t).onInsertBlock(e)}onDeleteBlock(t,e){this.getContainerIds(t).onDeleteBlock(e)}getBlockId(t,e){return this.getContainerIds(t).getId(e)}getBlockIndexById(t){const e=Array.from(this.ids.entries());for(let o=0;o<e.length;o++){const r=e[o],i=r[1].getById(t);if(i)return{containerId:r[0],blockIndex:i[0]}}return g(hp,!1,"fault error: failed to get block index"),{containerId:"error",blockIndex:-1}}}class Vb{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 Gh=S("op-parse-handler");class oL{constructor(t,e){m(this,"actions",[]);this.outerHandler=t,this.local=e}pushActions(t){if(!t.containerId){this.actions.push(t);return}const o={...t,containerId:(r=>r==="blocks"?"root":r)(t.containerId)};this.actions.push(o)}onDeleteBlock(t,e){this.pushActions({type:"deleteBlock",containerId:t,blockIndex:e})}onInsertBlock(t,e,o){this.pushActions({type:"insertBlock",containerId:t,blockIndex:e,data:o})}onDeleteBlockData(t,e,o){this.pushActions({type:"deleteBlockData",containerId:t,blockIndex:e,key:o})}onInsertBlockData(t,e,o,r){this.pushActions({type:"insertBlockData",containerId:t,blockIndex:e,key:o,value:r})}onUpdateBlockText(t,e,o){this.pushActions({type:"updateBlockText",containerId:t,blockIndex:e,richTextData:o})}onDeleteContainer(t){this.pushActions({type:"deleteContainer",containerId:t})}onCreateContainer(t,e){this.pushActions({type:"createContainer",containerId:t,data:e})}onDeleteComment(t){this.pushActions({type:"deleteComment",commentId:t})}onCreateComment(t){this.pushActions({type:"createComment",commentId:t})}onUpdateComment(t){this.pushActions({type:"updateComment",commentId:t})}end(){const t=this.actions,e=new Set,o=new Map,r=new nL,i=t.filter(s=>s.type==="deleteBlock"||s.type==="deleteBlockData");for(const s of i)if(s.type==="deleteBlock"){const l=s,a=r.getBlockId(l.containerId,l.blockIndex);r.onDeleteBlock(l.containerId,l.blockIndex);const d=o.get(a);d&&(Gh.debug(`ignore update object data before delete block: ${JSON.stringify(d)}`),o.delete(a));const h=`${l.containerId}-${l.blockIndex}`;e.add(h),this.outerHandler.onDeleteBlock(l.containerId,l.blockIndex,this.local)}else if(s.type==="deleteBlockData"){const l=s,a=`${l.containerId}-${l.blockIndex}`;if(e.has(a)){Gh.warn("delete block data after delete block, ignore it");continue}const d=r.getBlockId(l.containerId,l.blockIndex);let h=o.get(d);h||(h=new Vb,o.set(d,h)),h.delete(l.key)}else g(Gh,!1,`invalid action type, ${s.type}`);this.actions.forEach(s=>{if(s.type==="deleteContainer"){const l=s;this.outerHandler.onDeleteContainer(l.containerId,this.local)}else if(s.type==="deleteComment"){const l=s;this.outerHandler.onDeleteComment(l.commentId,this.local)}}),this.actions.forEach(s=>{if(s.type==="createContainer"){const l=s;this.outerHandler.onCreateContainer(l.containerId,l.data,this.local)}}),this.actions.forEach(s=>{if(s.type==="insertBlock"){const l=s;this.outerHandler.onInsertBlock(l.containerId,l.blockIndex,l.data,this.local)}else if(s.type==="insertBlockData"){const l=s,a=r.getBlockId(l.containerId,l.blockIndex);let d=o.get(a);d||(d=new Vb,o.set(a,d)),d.insert(l.key,l.value)}else if(s.type==="updateBlockText"){const l=s;this.outerHandler.onUpdateBlockText(l.containerId,l.blockIndex,l.richTextData,this.local)}else if(s.type==="createComment"){const l=s;this.outerHandler.onCreateComment(l.commentId,this.local)}else if(s.type==="updateComment"){const l=s;this.outerHandler.onUpdateComment(l.commentId,this.local)}}),Array.from(o.entries()).forEach(([s,l])=>{const{containerId:a,blockIndex:d}=r.getBlockIndexById(s);Gh.debug(`update block data: ${a}, ${d}, ${JSON.stringify(l.toDocBlockDelta())}`),this.outerHandler.onUpdateBlockData(a,d,l.toDocBlockDelta(),this.local)})}}const Oe=S("op-parser");class Wb{}class fp{constructor(t){m(this,"key");this.key=t}}function rL(n,t,e){const o=t.concat(),r=o[0];if(typeof r!="number"||(o.shift(),o.length===1))return!1;const i=o[0];if(typeof i!="object"||!i.i||Object.keys(i).length!==1)return!1;for(let l=1;l<o.length;l++){const a=o[l];if(!Array.isArray(a)||a.length!==2||typeof a[0]!="string")return!1;const h=a[1];if(typeof h!="object"||h.i===void 0||Object.keys(h).length!==1)return!1}const s=i.i;g(Oe,s.id,"block id is required"),g(Oe,s.type,"block type is required");for(let l=1;l<o.length;l++){const a=o[l],d=a[0],h=a[1];s[d]=h.i}return e.onInsertBlock(n,r,s),!0}function mp(n,t,e,o){if(e==="upsert"&&rL(n,t,o))return;g(Oe,Array.isArray(t),`invalid block op: ${n}, ${JSON.stringify(t)}`);const r=t.concat(),i=r[0];r.shift();const s=[];for(;r.length>0;){const l=r[0];if(l==="text"){const a=r[1];if(g(Oe,typeof a=="object",`invalid block op: ${n}, ${JSON.stringify(t)}`),g(Oe,a.et==="rich-text",`invalid block op: ${n}, ${JSON.stringify(t)}`),r.splice(0,2),e==="upsert"){const h=a.e;o.onUpdateBlockText(n,i,h)}g(Oe,r.length===0,`invalid block ops.length !== 0, ${JSON.stringify(r)}`)}else if(Array.isArray(l)){g(Oe,l.length===2,`invalid block op: data.length !== 2, ${JSON.stringify(l)}`);const a=l[0];g(Oe,typeof a=="string",`invalid block op: key ${JSON.stringify(a)}`);const d=l[1];if(a==="text"){if(g(Oe,typeof d=="object",`invalid opData type, ${JSON.stringify(d)}`),d.i&&e==="upsert"&&o.onInsertBlockData(n,i,a,d.i),d.r&&e==="remove"&&o.onDeleteBlockData(n,i,a),d.et==="rich-text"&&e==="upsert"){const p=d.e;o.onUpdateBlockText(n,i,p)}}else e==="remove"&&d.r&&s.push(new fp(a)),e==="upsert"&&d.i&&o.onInsertBlockData(n,i,a,d.i);r.shift()}else if(typeof l=="object"){const a=l;e==="remove"&&a.r&&s.push(new Wb),e==="upsert"&&a.i&&o.onInsertBlock(n,i,a.i),r.shift()}else{g(Oe,typeof l=="string","data is not string"),g(Oe,l!=="text","data !== 'text'"),g(Oe,r.length===2,`invalid block op: ops.length !== 2, ${JSON.stringify(r)}`);const a=l,d=r[1];e==="remove"&&d.r&&s.push(new fp(a)),e==="upsert"&&d.i&&o.onInsertBlockData(n,i,a,d.i),r.splice(0,2)}}s.reverse(),s.forEach(l=>{l instanceof Wb?o.onDeleteBlock(n,i):l instanceof fp?o.onDeleteBlockData(n,i,l.key):g(Oe,!1,`invalid action type: ${typeof l}, ${JSON.stringify(l)}`)})}function iL(n,t,e){Oe.warn(`unsupported meta op, ${JSON.stringify(n)}`)}function sL(n,t,e){const o=n[1],r=n[2];g(Oe,o,`invalid comment op, no commentId: ${JSON.stringify(n)}`),g(Oe,r,`invalid comment op, no actions: ${JSON.stringify(n)}`),typeof r=="string"?Oe.error(`unknown comment op, ${JSON.stringify(n)}`):r.i&&r.r?t==="upsert"&&e.onUpdateComment(o):r.i?t==="upsert"&&e.onCreateComment(o):r.r?t==="remove"&&e.onDeleteComment(o):Oe.error(`unknown comment op, ${JSON.stringify(n)}`)}function gp(n,t,e){const o=n[0];if(Array.isArray(o)){o.forEach(s=>{gp(s,t,e)});return}const r=o;if(g(Oe,typeof r=="string",`invalid container id: ${JSON.stringify(n)}`),r==="meta"){iL(n);return}if(r==="comments"){sL(n,t,e);return}const i=r;if(Array.isArray(n[1]))t==="remove"?n.slice(1).reverse().forEach(s=>{mp(i,s,t,e)}):n.slice(1).forEach(s=>{mp(i,s,t,e)});else if(typeof n[1]=="object"){const s=n[1];s.r&&t==="remove"&&e.onDeleteContainer(i),s.i&&t==="upsert"&&e.onCreateContainer(i,s.i)}else g(Oe,typeof n[1]=="number",`invalid ops[1], not a number: ${JSON.stringify(n)}`),mp(i,n.slice(1),t,e)}function qb(n,t,e){const o=new oL(t,e);for(let r=0;r<2;r++){const i=r===0?"remove":"upsert",s=mt.default(n),l=s[0];Array.isArray(l)?s.forEach(a=>{gp(a,i,o)}):gp(s,i,o)}o.end()}const lL=S("sharedb-comments");function pp(n){const t=n.blocks;g(lL,t,"no comment blocks");const e={blocks:{root:t},meta:{},comments:{}};return Object.entries(n).forEach(([o,r])=>{Array.isArray(r)&&(e.blocks[o]=r)}),mt.default(e)}function Gb(n){const{id:t,groupId:e,userId:o,displayName:r,avatarUrl:i,abstract:s,created:l,modified:a}=n;return{id:t,groupId:e,userId:o,displayName:r,avatarUrl:i,abstract:s,created:l,modified:a}}function Cp(n,t){const e=WD(t),{comments:o,meta:r,blocks:i,...s}=e,l={...n,blocks:i,...s},a=mt.default(l);return delete a.children,a}const ae=S("sharedb-doc/doc-container"),Zb="ot-json1";Fd.type.registerSubtype(qD.type),Fd.type.name=Zb,Fd.type.invert=null;class Xa extends ha{constructor(e,o,r=!0){super();m(this,"doc");m(this,"client");m(this,"localPresence");m(this,"remoteCaretHandler",new zD);m(this,"batching",0);m(this,"status","clean");m(this,"disableLogout");m(this,"destroyed",!1);m(this,"handleNothingPending",()=>{this.setStatus("clean")});m(this,"handleCreate",()=>{this.handleReload("doc created")});m(this,"handleDel",()=>{});m(this,"handleReload",e=>{this.callbacks.forEach(o=>{var r;return(r=o.onRequestReload)==null?void 0:r.call(o,e)})});m(this,"handleReset",async e=>{const o=new Error(`reset doc: ${e}`);o.code="ResetDoc",this.callbacks.forEach(r=>{var i;return(i=r.onError)==null?void 0:i.call(r,o)}),this.destroy()});m(this,"handleWriteConflictError",e=>{this.handleReset(`write conflict: ${e.message}, ${JSON.stringify(e.orgMsg)}`)});m(this,"insertObject",async(e,o,r)=>{const i=[e,o,{i:r}];return this.submitOp(i)});m(this,"deleteObject",async(e,o)=>{const r=[e,o,{r:!0}];return this.submitOp(r)});m(this,"replaceObject",async(e,o,r)=>{const i=[e,o,{r:!0,i:r}];return this.submitOp(i)});m(this,"updateObject",async(e,o,r)=>{const i=this.data()[e][o],s=[e,o];return Object.entries(r).forEach(([l,a])=>{if(!aa.default(i[l],a))if(i[l]===void 0){if(a!=null){const d={i:a};s.push([l,d])}}else if(a==null){const d={r:!0};s.push([l,d])}else{const d={r:!0,i:a};s.push([l,d])}}),Object.entries(i).forEach(([l,a])=>{if((r[l]===void 0||r[l]===null)&&a!==void 0){const d={r:!0};s.push([l,d])}}),s.length<=2?Promise.resolve():this.submitOp(s)});m(this,"broadcastMessage",async e=>{const o={type:"custom",data:e,clientId:this.client.clientId};this.localPresence&&this.localPresence.submit(o)});m(this,"data",()=>this.doc.data);m(this,"submitOp",async e=>new Promise((o,r)=>{if(this.destroyed){ae.warn("submit op after destroyed");return}this.setStatus("dirty"),this.doc.submitOp(e,{},i=>{i?(ae.error(`invalid op, ${i.message}, ${JSON.stringify(e)}`),r(i),ae.error("Transform detected write conflict, reload editor"),this.handleReset("write conflict")):o()}),this.doc.data||(ae.error("no data after submit op, may be the submitted op is invalid"),this.handleReset(`invalid op, ${JSON.stringify(e)}`))}));m(this,"createDoc",async e=>new Promise((o,r)=>{this.doc.create(e,Zb,i=>{i?r(i):o()})}));m(this,"submitInsertChildContainer",async(e,o)=>{const r=[Ni(e),{i:o}];return this.submitOp(r)});m(this,"submitDeleteChildContainer",async e=>{const o=[Ni(e),{r:!0}];return this.submitOp(o)});m(this,"submitInsertBlock",async(e,o,r)=>{const i=[Ni(e),o,{i:r}];return this.submitOp(i)});m(this,"submitDeleteBlock",async(e,o)=>{const r=[Ni(e),o,{r:!0}];return this.submitOp(r)});m(this,"submitUpdateBlockData",async(e,o,r)=>{if(r.delete.length===0&&Object.keys(r.insert).length===0)return Promise.resolve();const i=[Ni(e),o],s=new Set(r.delete);Object.entries(r.insert).forEach(([a,d])=>{if(s.has(a)){const h={r:!0,i:d};i.push([a,h])}});const l=new Set(Object.keys(r.insert));return r.delete.forEach(a=>{if(l.has(a))return;const d={r:!0};i.push([a,d])}),Object.entries(r.insert).forEach(([a,d])=>{if(s.has(a))return;const h={i:d};i.push([a,h])}),this.submitOp(i)});m(this,"submitUpdateRichText",async(e,o,r)=>{const i=[Ni(e),o,"text",{e:r,et:"rich-text"}];return this.submitOp(i)});m(this,"handleOp",(e,o,r)=>{if(this.destroyed){ae.warn("handleOp: destroyed");return}qb(e,this,!!o)});this.client=e,this.doc=o,this.doc.preventCompose=!0,this.disableLogout=r,this.registerCallback(this.remoteCaretHandler)}beginBatchUpdate(){return this.doc.preventCompose=!1,this.batching++,this.batching}endBatchUpdate(){return this.batching--,g(ae,this.batching>=0,"invalid call beginBatchUpdate/endBatchUpdate"),this.batching===0&&(this.doc.preventCompose=!0),this.batching}static async load(e){try{const o=new XS(e.auth,e.serverUrl,e.reauthFunc),r=await o.getDoc(),i=new Xa(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||tL())}return await i.initPresence(),await i.subscribe(),i.initEvents(),i}catch(o){throw ae.error(o),ae.error(`failed to load doc: ${JSON.stringify(o)}`),o}}setStatus(e){this.status!==e&&(this.status=e,this.callbacks.forEach(o=>{var r;return(r=o.onStatusChanged)==null?void 0:r.call(o,e)}))}initEvents(){this.doc.on("nothing pending",this.handleNothingPending),this.doc.on("create",this.handleCreate),this.doc.on("del",this.handleDel),this.client.onWriteConflictError(this.handleWriteConflictError)}clearEvents(){this.doc.off("nothing pending",this.handleNothingPending),this.doc.off("create",this.handleCreate),this.doc.off("del",this.handleDel)}initPresence(){return new Promise((e,o)=>{if(this.localPresence)e();else{const r=this.doc.connection.getPresence(`${this.doc.collection}:${this.doc.id}`);r.on("receive",(i,s)=>{this.onCustomMessage(s)}),r.subscribe(i=>{i?o(i):(this.localPresence=r.create(K()),e())})}})}subscribe(){return new Promise((e,o)=>{this.doc.subscribe(r=>{r?o(r):(this.doc.on("op",this.handleOp),e())})})}toJSON(){return Ua(this.data())}getContainerBlocks(e){const o=this.data();g(ae,o,"no doc data");const r=o[Ni(e)];return g(ae,r,`no container data: ${e}`),mt.default(r)}getBlockData(e,o){const r=this.data();g(ae,r,"no doc data");const i=r[Ni(e)];g(ae,i,`no container data: ${e}`);const s=i[o];return g(ae,s,`no block data: ${o}`),mt.default(s)}localInsertBlock(e,o,r){return this.submitInsertBlock(e,o,r),this.getBlockData(e,o)}localDeleteBlock(e,o){const r=this.getBlockData(e,o);return this.submitDeleteBlock(e,o),r}localUpdateBlockText(e,o,r){const i=this.getBlockData(e,o);g(ae,i.text,"no block text");const s=mt.default(i.text);this.submitUpdateRichText(e,o,r);const l=ln.apply(s,r);return g(ae,l,"no block text"),l}localUpdateBlockData(e,o,r){const i=mt.default(this.getBlockData(e,o));return this.submitUpdateBlockData(e,o,r),i}localInsertChildContainer(e,o){this.submitInsertChildContainer(e,o)}localDeleteChildContainers(e){this.beginBatchUpdate(),e.forEach(o=>{this.submitDeleteChildContainer(o)}),this.endBatchUpdate()}getComments(){return Object.values(this.data().comments).map(o=>Gb(o))}getComment(e){return this.data().comments[e]}getCommentDoc(e){const o=this.data().comments[e];return pp(o)}localCreateComment(e,o){const r=Cp(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=Cp(e,o),i=["comments",e.id,{r:!0,i:r}];return this.submitOp(i)}destroy(){var e;this.destroyed=!0,this.clearEvents(),this.clearCallbacks(),this.doc.destroy(),(e=this.localPresence)==null||e.destroy(),this.client.close(!this.disableLogout),this.remoteCaretHandler.destroy()}onDeleteBlock(e,o,r){g(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(i=>{var s;return(s=i.onDeleteBlock)==null?void 0:s.call(i,Kl(e),o,r)})}onInsertBlock(e,o,r,i){g(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onInsertBlock)==null?void 0:l.call(s,Kl(e),o,r,i)})}onUpdateBlockData(e,o,r,i){g(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockData)==null?void 0:l.call(s,Kl(e),o,r,i)})}onUpdateBlockText(e,o,r,i){g(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockText)==null?void 0:l.call(s,Kl(e),o,r,i)})}onDeleteContainer(e,o){g(ae,this.callbacks.length>0,"no callbacks"),g(ae,e!=="root","should not delete root container in doc"),this.callbacks.forEach(r=>{var i;return(i=r.onDeleteChildContainer)==null?void 0:i.call(r,Kl(e),o)})}onCreateContainer(e,o,r){g(ae,this.callbacks.length>0,"no callbacks"),g(ae,e!=="root","should not create root container in doc"),this.callbacks.forEach(i=>{var s;return(s=i.onInsertChildContainer)==null?void 0:s.call(i,Kl(e),o,r)})}onDeleteComment(e,o){g(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(r=>{var i;return(i=r.onDeleteComment)==null?void 0:i.call(r,e,o)})}onCreateComment(e,o){g(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(r=>{var i;return(i=r.onCreateComment)==null?void 0:i.call(r,e,o)})}onUpdateComment(e,o){g(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(r=>{var i;return(i=r.onUpdateComment)==null?void 0:i.call(r,e,o)})}onCustomMessage(e){const o=e;(o==null?void 0:o.type)==="custom"&&(o==null?void 0:o.clientId)!==this.client.clientId?this.callbacks.forEach(r=>{var i;return(i=r.onCustomMessage)==null?void 0:i.call(r,o.data)}):(o==null?void 0:o.type)==="onlineUsers"&&setTimeout(()=>{const r={type:"custom",data:e,clientId:"-"};this.onCustomMessage(r)})}async addResources(e){return await this.client.getFileUrlsByHashes(e)}async uploadResource(e,o){var i;return{resourceId:await this.client.uploadResource(e,(i=o==null?void 0:o.onProgress)!=null?i:()=>{})}}buildResourceUrl(e,o){return this.client.buildResourceUrl(e,o)}request(e,o){return this.client.request(e,o)}getUser(){const e=this.client.clientId,{permission:o,userId:r,displayName:i,avatarUrl:s}=this.client.auth;return{permission:o,clientId:e,userId:r,displayName:i,avatarUrl:s,rainbowIndex:0}}getRemoteUsers(){return this.remoteCaretHandler.remoteUsers}getVersionHelper(){return this}getVersions(){return this.client.getVersions()}async getVersion(e){const o=await this.client.getVersion(e);return Ua(o)}async getLatestVersion(){const e=await this.client.getLatestVersion();return Ua(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:Ua(r),historyData:s}}async getVersionData(e,o){const{doc:r,ops:i}=await this.client.getVersionOps(e,o);return{doc:Ua(r),versionData:i}}async updateVersionExtra(e,o,r){await this.client.updateVersionExtra(e,o,r)}revertVersion(e){return this.client.revertVersion(e)}createVersion(e,o){return this.client.createVersion(e,o)}async recognizeLink(e){return this.client.recognizeLink(e)}parseHistoryData(e,o){qb(e.data.op,o,!0)}getServerMeta(){return{appId:this.client.auth.appId,docId:this.client.auth.docId,serverId:this.client.apiServer()}}}S("remote-cursor");class Qb{constructor(t){m(this,"handleDocSelectionChange",()=>{this.broadcastCaretPos()});m(this,"broadcastCaretPos",Le.default(()=>{const t={type:"caret",userId:this.editor.doc.getUser().userId,range:this.editor.selection.range.toDocRange()};this.editor.doc.broadcastMessage(t)},300));m(this,"handleRemoteCaretsChanged",t=>{t.forEach(e=>{const o=this.editor.findBlockById(e);o&&this.editor.reloadBlock(o)})});this.editor=t,this.editor.addListener("selectionChanged",this.handleDocSelectionChange),this.editor.doc.getRemoteUsers().addListener("remote-carets-change",this.handleRemoteCaretsChanged)}destroy(){this.editor.removeListener("selectionChanged",this.handleDocSelectionChange),this.editor.doc.getRemoteUsers().removeListener("remote-carets-change",this.handleRemoteCaretsChanged)}}const Yb=S("remote-cursor-decorator");class Ap{decorateText(t,e,o){const r=t.doc.getRemoteUsers();if(!r)return{};const i=new Map,{containerId:s,blockIndex:l}=e[e.length-1];g(Yb,typeof s=="string","invalid path containerId"),g(Yb,typeof l=="number","invalid path blockIndex");const a=t.doc.getBlockData(s,l),d=rn(o);return r.getSimpleCursors(a.id).forEach((p,A)=>{A>d&&(A=d);const v=p.map(D=>({id:K(),type:"remote-cursor",name:D.user.displayName,time:D.time,rainbowIndex:D.user.rainbowIndex})),B=i.get(A);B?B.push(...v):i.set(A,v)}),{insertions:i}}}class Jb extends ye.TypedEmitter{constructor(t){super(),this.editor=t,this.editor.doc.registerCallback(this)}handleChild(t,e,o){if(Yt(jr(this.editor,t)))return;const r=this.editor.getBlockByIndex(t,e),i=et(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 cL(n,t){n.addCustom("child-block-tracker",()=>new Jb(n)).addListener("change",t)}function aL(n,t){n.addCustom("child-block-tracker",()=>new Jb(n)).removeListener("change",t)}const dnt="",uL={colorPalette:{colorDesc:"\u5B57\u4F53\u989C\u8272",name:"\u6587\u672C\u989C\u8272",backgroundDesc:"\u80CC\u666F\u989C\u8272",reset:"\u6062\u590D\u9ED8\u8BA4"},search:{emptyTips:"\u6682\u65E0\u641C\u7D22\u7ED3\u679C"}},dL={colorPalette:{colorDesc:"Text color",name:"Text color",backgroundDesc:"Background color",reset:"Restore default values"},search:{emptyTips:"No results found"}},hL={colorPalette:{colorDesc:"\u30D5\u30A9\u30F3\u30C8\u306E\u8272",name:"\u30C6\u30AD\u30B9\u30C8\u306E\u8272",backgroundDesc:"\u80CC\u666F\u8272",reset:"\u30C7\u30D5\u30A9\u30EB\u30C8\u306B\u623B\u3059"},search:{emptyTips:"\u691C\u7D22\u7D50\u679C\u304C\u3042\u308A\u307E\u305B\u3093"}};R.mergeLang({"zh-CN":uL,"en-US":dL,"js-JP":hL});const hnt="";S("button");function uo(n,t,e,o,r){const i=w("button",["editor-button"],null);return i.setAttribute("data-button-id",n),r&&i.setAttribute(`data-editor-tooltip-${r}`,t),e?typeof e=="string"?e.startsWith("<")?i.innerHTML=e:i.innerText=e:i.appendChild(e):i.innerText=t,o&&(o.indexOf("checked")!==-1&&W(i,"checked"),o.indexOf("disabled")!==-1&&(i.disabled=!0),o.indexOf("primary")!==-1&&W(i,"primary")),i}function Kb(n,t,e){e?n.setAttribute(`data-editor-tooltip-${e}`,t):n.innerText=t}const fnt="",ec=S("ui-command-bar-base"),fL={itemElementTag:"div",tippyArrow:!1},J2=class extends ye.TypedEmitter{constructor(e,o,r){var i,s;super();m(this,"content");m(this,"items");m(this,"subBar",null);m(this,"parentItem",null);m(this,"closeable",null);m(this,"closeReason",null);m(this,"options");m(this,"id");m(this,"header",null);m(this,"footer",null);m(this,"handleDocumentKeydown",e=>{if(!!this.isVisible&&!e.isComposing&&!Ss(e.target)){if(this.subBar){this.subBar.handleDocumentKeydown(e);return}if(this.items.length!==0){if(e.key==="Escape"){this.close("cancelBar");return}if(e.key==="ArrowUp"){const o=this.getPrevItemIndex(this.getSelectedItemIndex());this.startPauseMouseEnter(),this.selectItem(this.items[o].id),e.preventDefault(),e.stopPropagation()}else if(e.key==="ArrowDown"){const o=this.getNextItemIndex(this.getSelectedItemIndex());this.startPauseMouseEnter(),this.selectItem(this.items[o].id),e.preventDefault(),e.stopPropagation()}else if(e.key==="ArrowRight"){const o=this.getSelectedItem();o&&o.children&&this.showSubCommandBar(o.childrenMenuId)}else if(e.key==="ArrowLeft")this.parentItem&&this.close("switchItem");else if(e.key==="Enter"){const o=this.getSelectedItemIndex();if(o===-1)return;const r=this.items[o],i=this.getItemElementById(r.id);i&&this.emit("click",this,r,i)}}}});m(this,"handleDocumentMouseDown",e=>{if(e.target instanceof Element&&!this.isInCommandBar(e.target)){const o=this.listeners("closing");for(let r=0;r<o.length;r++)if(o[r](this,e)===!1)return;this.close("clickBackground")}});m(this,"handleHidden",()=>{this.closeReason!=="fromHover"&&this.emit("close",this),this.close(null),BC(this.id)});m(this,"handleShow",()=>{this.popper&&(this.popper.setAttribute("data-command-bar-id",this.id),this.options.classes&&W(this.popper,...this.options.classes),this.options.refuseOverflow&&this.popper.classList.add("reference-hidden")),this.emit("show",this),this.options.disablePageScroll&&wC(this.id)});m(this,"lastEnterPauseTime",0);m(this,"startPauseMouseEnter",()=>{this.lastEnterPauseTime=Date.now()});m(this,"handleItemMouseEnter",e=>{if(Date.now()-this.lastEnterPauseTime<100)return;const o=this.getParentCommandItemElement(e.target);if(!o)return;const r=this.getItemElementId(o),i=this.getItemById(r);if(this.selectItem(r),i.manualShowChildren)return;const s=i.childrenMenuId||"";this.showSubCommandBar(s)});m(this,"handleItemMouseLeave",e=>{var r,i;const o=this.getParentCommandItemElement(e.target);!o||((i=(r=this.subBar)==null?void 0:r.parentItem)==null?void 0:i.id)!==this.getItemElementId(o)&&(ot(o,"selected"),this.emit("selectionChange",this,""))});m(this,"handleItemClick",e=>{const o=this.getParentCommandItemElement(e.target);if(!o)return;const r=this.getItemElementId(o),i=this.items.find(s=>s.id===r);if(!!i&&!(i.states&&i.states.indexOf("disabled")!==-1)){if(i.children&&i.children.length>0&&i.manualShowChildren){this.showSubCommandBar(i.childrenMenuId);return}i.element||(this.emit("click",this,i,o),this.options.autoClose&&this.close("clickItem"))}});m(this,"handleWheel",e=>{if(!this.options.disablePageScroll&&!document.querySelector(".editor-disable-scroll"))return;const o=e.target;if(!o||!(o instanceof Node))return;const r=o instanceof HTMLElement?o:o.parentElement;if(!r)return;const i=ro(r);if(!Xt(this.content,i)){e.stopPropagation(),e.preventDefault();return}e.deltaY<0?i.scrollTop===0&&(e.stopPropagation(),e.preventDefault()):e.deltaY>0&&i.scrollTop+i.clientHeight>=i.scrollHeight&&(e.stopPropagation(),e.preventDefault())});this.id=(i=r==null?void 0:r.id)!=null?i:K(),this.options={...fL,...r},this.items=e,this.parentItem=(s=r==null?void 0:r.parentItem)!=null?s:null,this.closeable=o!=null?o:null,this.content=this.createCommandBarContent(e)}close(e){this.closeReason=e,this.subBar&&this.subBar.close(e),document.removeEventListener("keydown",this.handleDocumentKeydown),document.removeEventListener("mousedown",this.handleDocumentMouseDown)}click(e,o){this.emit("click",this,e,o)}createPopperOptions(){var r,i;const e={modifiers:[]},o=this.options.overflowBoundary;return o&&((r=e==null?void 0:e.modifiers)==null||r.push({name:"flip",options:{boundary:o,fallbackPlacements:["top","bottom"]}})),this.options.padding&&((i=e==null?void 0:e.modifiers)==null||i.push({name:"preventOverflow",options:{padding:this.options.padding}})),e}destroy(){var e;this.close(null),this.removeAllListeners(),(e=this.subBar)==null||e.destroy(),this.subBar=null,this.closeable=null,this.content.removeEventListener("wheel",this.handleWheel)}get isSubCommandBar(){return!!this.parentItem}updateItems(e){var r;this.subBar&&e.findIndex(s=>{var l,a;return s.id===((a=(l=this.subBar)==null?void 0:l.parentItem)==null?void 0:a.id)})===-1&&((r=this.subBar)==null||r.destroy(),this.subBar=null),this.items=e;const o=this.createCommandBarContent(e);this.content.innerHTML="",Array.from(o.children).forEach(i=>{this.content.appendChild(i)})}get popper(){return this.content.closest("[data-tippy-root]")}getSelectedItemIndex(){const e=this.getSelectedItem();return e?this.items.indexOf(e):-1}getPrevItemIndex(e){if(e<=0)return this.items.length-1;let o=e-1;for(;;){const r=this.items[o],i=r.type,l=!(r.states&&r.states.indexOf("disabled")!==-1);if(i!=="separator"&&i!=="section"&&l)return o;if(o-=1,o<=0)return this.items.length-1}}getNextItemIndex(e){let o=e+1;for(;;){if(!this.items[o])return this.getNextItemIndex(-1);const r=this.items[o],i=r.type,l=!(r.states&&r.states.indexOf("disabled")!==-1);if(i!=="separator"&&i!=="section"&&l)return o;if(o+=1,o>this.items.length-1)return 0}}clearSelectedItem(){const e=this.getSelectedItem();if(!e)return;const o=this.getItemElementById(e.id);o&&ot(o,"selected")}selectItem(e){const o=this.getSelectedItem();if(o){if(o.id===e)return;const i=o.id,s=this.getItemElementById(i);s&&ot(s,"selected")}const r=this.getItemElementById(e);r?(W(r,"selected"),this.emit("selectionChange",this,r.getAttribute("data-id")||""),r.scrollIntoView({block:"nearest"})):this.emit("selectionChange",this,"")}showSubCommandBar(e){var s,l;const o=this.getSelectedItem();if(!o)return;if(this.subBar){if(((s=this.subBar.parentItem)==null?void 0:s.id)===o.id){o.manualShowChildren&&this.subBar.close("switchItem");return}this.subBar.destroy(),this.subBar=null}if(!o.children)return;const r=this.getItemElementById(o.id);if(!r)return;const i=J2.createSubCommandBar(o,(l=this.closeable)!=null?l:this,e?{id:e}:{});this.subBar=i,this.subBar.on("click",(a,d,h)=>{this.emit("click",a,d,h)}),this.subBar.on("close",()=>{var a;(a=this.subBar)==null||a.destroy(),this.subBar=null,ot(r,"active")}),o.beforePopup&&o.beforePopup(i),this.subBar.manualShow(r,this.getSubBarOptions(o)),W(r,"active")}isInCommandBar(e){if(!e||!(e instanceof Node))return!1;const o=this.getCommandBarRoot();return o&&Xt(o,e)||Xt(this.content,e)?!0:this.subBar?this.subBar.isInCommandBar(e):!1}createCommandItem(e){var i,s,l,a;let o=(i=this.options.itemElementTag)!=null?i:"div";e.element&&(o="div");const r=w(o,["command-item"],null);return r.setAttribute("data-id",e.id),e.type==="separator"?r.classList.add("separator"):e.type==="section"?(r.classList.add("section","text"),e.element&&(typeof e.element=="function"?r.appendChild(e.element(e)):r.appendChild(e.element))):((s=e.states)!=null&&s.includes("selected")&&r.classList.add("selected"),(l=e.states)!=null&&l.includes("checked")&&r.classList.add("checked"),(a=e.states)!=null&&a.includes("disabled")&&r.classList.add("disabled"),r.onclick=this.handleItemClick,r.onmouseenter=this.handleItemMouseEnter,r.onmouseleave=this.handleItemMouseLeave,e.element?typeof e.element=="function"?r.appendChild(e.element(e)):r.appendChild(e.element):r.classList.add("standard")),this.initItemElement(e,r),r}getItemById(e){const o=this.items.find(r=>r.id===e);return g(ec,o,`can not find command item for id: ${e}`),o}getSelectedItem(){const e=this.content.querySelector(":scope >.editor-command-bar >.command-item.selected");if(e){const o=this.getItemElementId(e),r=this.items.find(i=>i.id===o);return g(ec,r,`can not find command item for id: ${o}`),r}return null}getItemElementId(e){const o=e.getAttribute("data-id");return g(ec,o,"no data-id attribute"),o}getItemElementById(e){const o=this.content.querySelector(`:scope >.editor-command-bar > .command-item[data-id="${e}"]`);return g(ec,o,`no exists command item, id=${e}`),o}getParentCommandItemElement(e){if(!e||!(e instanceof Element))return null;if(xt(e,"command-item"))return e;const o=e.closest(".command-item");return o||null}createCommandBarContent(e){this.content&&this.content.removeEventListener("wheel",this.handleWheel);const o=w("div",["editor-command-bar-root"],null);if(this.options.header){const i=w("div",["editor-command-bar-header"],null);if(this.options.header instanceof Function){const s=this.options.header();s&&i.appendChild(s)}else i.appendChild(this.options.header);this.header=i,this.header&&o.appendChild(this.header)}const r=w("div",["editor-command-bar"],o);if(e.forEach(i=>{var l;const s=this.createCommandItem(i);r.appendChild(s),i.element&&i.setCloseable&&i.setCloseable((l=this.closeable)!=null?l:this)}),this.options.footer){const i=w("div",["menu-item","editor-command-bar","footer"],null);if(this.options.footer instanceof Function){const s=this.options.footer();s&&i.appendChild(s)}else i.appendChild(this.options.footer);this.footer=i,this.footer&&o.appendChild(this.footer)}return(this.options.header||this.options.footer)&&W(o,"scrollable-bar"),this.initCommandBarElement(r),o.addEventListener("wheel",this.handleWheel,{passive:!1}),o}getSubBarOptions(e){var o;return{placement:(o=e.childrenPlacement)!=null?o:"right-start"}}static registerManualCommandBar(e,o){this.commandBarCreators.set(e,o)}static createSubCommandBar(e,o,r){var l;g(ec,e.children&&e.children.length>0,"no item children");const i=(l=e.childrenType)!=null?l:"menu",s=this.commandBarCreators.get(i);return g(ec,s,`no creator for command type: ${i}`),s(e,o,r)}static hasExistsCommandBar(){return!!document.querySelector("[data-command-bar-id]")}};let ji=J2;m(ji,"commandBarCreators",new Map),S("ui-command-bar");class Zh extends ji{constructor(){super(...arguments);m(this,"tippyInstance",null)}manualShow(e,o){var r,i;if(!this.isVisible){if(this.tippyInstance&&(this.tippyInstance.destroy(),this.tippyInstance=null),this.tippyInstance=qB.default(e,{interactive:!0,content:this.content,trigger:"manual",triggerTarget:null,hideOnClick:!1,placement:(r=o==null?void 0:o.placement)!=null?r:"bottom-start",maxWidth:650,arrow:this.options.tippyArrow,appendTo:document.body,onShow:this.handleShow,onHidden:this.handleHidden,theme:o==null?void 0:o.theme,getReferenceClientRect:o==null?void 0:o.getReferenceClientRect,offset:(i=o==null?void 0:o.offset)!=null?i:[0,0],popperOptions:this.createPopperOptions()}),o!=null&&o.point){const{x:s,y:l}=o.point;this.tippyInstance.setProps({getReferenceClientRect:()=>new DOMRect(s,l,0,0)})}this.clearSelectedItem(),this.tippyInstance.show(),this.parentItem||(document.addEventListener("keydown",this.handleDocumentKeydown),document.addEventListener("mousedown",this.handleDocumentMouseDown)),this.popper&&this.options.id&&this.popper.setAttribute("data-command-bar-id",this.options.id)}}close(e){var o;super.close(e),this.isVisible&&((o=this.tippyInstance)==null||o.hide())}destroy(){var e;(e=this.tippyInstance)==null||e.destroy(),this.tippyInstance=null,super.destroy()}getCommandBarRoot(){return this.content.closest("[data-tippy-root]")}get isVisible(){var e,o;return(o=(e=this.tippyInstance)==null?void 0:e.state.isVisible)!=null?o:!1}get popper(){return this.content.closest("[data-tippy-root]")}}const Xb=S("ui-base");class tu extends Zh{constructor(t,e){var i;const r=[{id:(i=e==null?void 0:e.id)!=null?i:`popup-${K()}`,name:"",element:t}];super(r,void 0,{disablePageScroll:!0})}initCommandBarElement(t){W(t,"popper")}initItemElement(t,e){}get popupContent(){const t=this.items[0];g(Xb,t,"no dialog item");const e=typeof t.element=="function"?t.element(t):t.element;return g(Xb,e,"no item element"),e}}const Ui=S("filterable-list");function tv(n){var e,o;const t=w("div",["list-item"],null);return t.setAttribute("data-id",n.id),t.appendChild(w("div",["list-item-text"],null,n.name)),(e=n.states)!=null&&e.includes("selected")&&W(t,"selected"),(o=n.states)!=null&&o.includes("disabled")&&W(t,"disabled"),t}function ev(n){const t=w("div",["list-root"],null);return n.forEach(e=>{t.appendChild(tv(e))}),n.length||t.appendChild(tv({id:"placeholder",states:["disabled"],name:R.t("search.emptyTips")})),t}function nv(n,t){let e=n;return t&&(e=n.map(o=>({...o,states:o.id===t?["selected"]:void 0}))),e}function mL(n,t){const e=w("div",["filterable-list"],null),o=w("div",["filter"],e),r=w("div",["filter-container"],o),i=w("input",["filter-input"],r);t&&t.placeholder&&(i.placeholder=t.placeholder);const s=w("div",["list"],e),l=ev(nv(n,t==null?void 0:t.initialSelectedId));return s.appendChild(l),e}function ov(n,t,e){const o=n.querySelector(".list");g(Ui,o,"no list root");const r=ev(nv(t,e)),i=o.querySelector(".list-root");if(g(Ui,i,"no exists menu"),Ca(i,r),e){const s=o.querySelector(".list-item.selected");s&&(g(Ui,s,"no selected menu item"),s.scrollIntoView({block:"nearest"}))}}class gL{constructor(t,e){m(this,"root");m(this,"visibleItems");m(this,"selectedId");m(this,"filter","");m(this,"onSelected",null);m(this,"handleKeydown",t=>{this.processKeyDown(t)});m(this,"handleInputChanged",()=>{const t=this.root.querySelector(".filter-input");g(Ui,t,"no input");const e=t.value.toLocaleLowerCase();this.setFilter(e)});m(this,"handleClick",t=>{this.processClick(t)});var o;this.items=t,this.options=e,this.root=mL(t,e),this.bindEvents(),this.selectedId=(o=e==null?void 0:e.initialSelectedId)!=null?o:"",this.visibleItems=t}bindEvents(){const t=this.root.querySelector(".filter-input");g(Ui,t,"no input"),t.addEventListener("keyup",this.handleInputChanged),t.addEventListener("keydown",this.handleKeydown),this.root.addEventListener("click",this.handleClick)}unbindEvents(){const t=this.root.querySelector(".filter-input");g(Ui,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,ov(this.root,this.visibleItems,t)}focus(){const t=this.root.querySelector(".filter-input");g(Ui,t,"no input"),t.focus()}reset(){this.setFilter("");const t=this.root.querySelector(".filter-input");g(Ui,t,"no input"),t.value=""}setFilter(t){this.filter!==t&&(this.filter=t,this.visibleItems=this.items.filter(e=>e.name.toLocaleLowerCase().includes(t)),ov(this.root,this.visibleItems,this.selectedId))}processClick(t){var s,l;const e=t.target;if(!(e instanceof HTMLElement))return;const o=e.closest(".list-item");if(!o)return;const r=(s=o.getAttribute("data-id"))!=null?s:"",i=(l=this.visibleItems.find(a=>a.id===r))!=null?l:null;this.onSelected&&this.onSelected(this,i)}processKeyDown(t){var e;if(t.key==="ArrowUp"){let o=this.getSelectedIndex();o===-1?o=this.visibleItems.length-1:o>0&&(o-=1);let r="";o!==-1&&(r=this.visibleItems[o].id),this.setSelectedId(r);return}if(t.key==="ArrowDown"){let o=this.getSelectedIndex();o===-1?o=0:o<this.visibleItems.length-1&&(o+=1);let r="";o!==-1&&(r=this.visibleItems[o].id),this.setSelectedId(r);return}if(t.key==="Enter"){const o=(e=this.visibleItems.find(r=>r.id===this.selectedId))!=null?e:null;this.onSelected&&this.onSelected(this,o)}}}class pL extends gL{constructor(e,o,r){super(e,r);m(this,"popup");m(this,"onShow",null);m(this,"onHide",null);m(this,"custom",null);m(this,"handleShow",()=>{this.onShow&&this.onShow(this)});m(this,"handleHide",()=>{this.onHide&&this.onHide(this)});m(this,"handleShown",()=>{this.focus()});this.popup=new tu(this.root)}destroy(){super.destroy(),this.onShow=null,this.onHide=null}show(e){this.reset(),this.popup.manualShow(e,{theme:"dropdown-list"}),this.focus()}processKeyDown(e){super.processKeyDown(e),(e.key==="Esc"||e.key==="Enter")&&this.popup.close("cancelBar")}processClick(e){super.processClick(e);const o=e.target;!(o instanceof HTMLElement)||!o.closest(".list-item")||this.popup.close("clickItem")}}const mnt="",gnt="";function CL(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 rv=`<?xml version="1.0" ?>
|
|
27
|
+
`)}const sT=S("get-text-position");function ql(n,t){const e=t!=null?t:n.selection.range.start;e instanceof je||g(sT,!1,`invalid insert pos type: ${typeof e}`);const{blockId:o}=e,r=n.getBlockById(o),i=bt(r),s=nt(r),l=at(s),{offset:a}=e;return{block:r,container:s,containerId:l,blockIndex:i,offset:a}}const Gl=S("insert-text");function xg(n,t,e,o){var s;const r=n.doc.getBlockData(t,e);if(g(Gl,r,"no block data"),g(Gl,r.text,"no block text"),rn(r.text)===0)return g(Gl,o===0,"invalid text offset"),n.editorCommandProviders.getEmptyBlockTextAttributes(n,r.id);if(o===0)return;const i=ze(r.text,o-1,1).middle;if(!((s=i[0].attributes)!=null&&s.box))return i[0].attributes}function lT(n,t,e){const o=nt(t),r=at(o),i=bt(t);return xg(n,r,i,e)}function L6(n,t,e,o,r){const i=nt(t),s=at(i),l=bt(t),a=lT(n,t,e),d=uh(e,o,a!=null?a:null);return n.doc.localUpdateBlockText(s,l,d,r),gn(n,t)}function M6(n,t,e,o){const r=nt(t),i=at(r),s=bt(t),l=uh(e," ",o);return n.doc.localUpdateBlockText(i,s,l),gn(n,t)}function cT(n,t){let e=0;if(t===0)return!1;for(let o=0;o<n.length;o++){const r=n[o];g(Gl,typeof r.insert=="string","invalid text op, no insert");const i=e+dh(r);if(i===t)return!1;if(i>t)return!0;e=i}return!1}function Ig(n,t,e,o,r){const i=n.doc.getBlockData(e,o);g(Gl,i,"no block data"),g(Gl,i.text,"no block text");const s=xg(n,e,o,r);s&&Object.keys(s).includes("link")&&(cT(i.text,r)||delete s.link);const l=uh(r,t,s!=null?s:null);return n.doc.localUpdateBlockText(e,o,l),gn(n,n.getBlockById(i.id))}function Tg(n,t){n.selection.range.isCollapsed()||n.clearSelectedContents();const{containerId:e,blockIndex:o,offset:r}=ql(n);Ig(n,t,e,o,r)}const kh=S("update-composition-text");function R6(n){const t=n.selection.range.start;t instanceof je||g(kh,!1,`invalid insert pos type: ${typeof t}`);const{blockId:e}=t,o=n.getBlockById(e);g(kh,tt(n,o),"not a text kind block");const r=nt(o),i=at(r),s=bt(o),l=n.doc.getBlockData(i,s);g(kh,l,"no block data in doc"),g(kh,l.text,"no text data in text block");const a=Lt(o);sh(n,Li(o),e,a,l.text)}function O6(n){$x(n)}function Zl(n,t,e,o,r,i){return n.doc.localInsertBlock(t,e,o,r,i),n.getBlockById(o.id)}const Oa=S("delete-block-text");function Dg(n,t,e,o,r){if(!n.isBlockWritable(t))return Oa.error("block is not writable"),0;g(Oa,tt(n,t),"block is not a text kind block");const i=nt(t),s=at(i),l=bt(t),a=n.doc.getBlockData(s,l);g(Oa,a,"no block data in doc"),g(Oa,a.text,"no text data in text block");let d=e;sn(t,e)||(d=Ri(t,d));let h=e+o;g(Oa,h<=ut(n,t),`invalid offset and count: ${e}, ${o}`),sn(t,h)||(h=Fs(t,h));const p=h-d,A=V4(d,p);return n.doc.localUpdateBlockText(s,l,A,r),p}const Sg=S("break-text-block");function _6(n,t){const o=n.getBlockData(t).quoted;return o?{quoted:o}:{}}function Ql(n,t,e,o){g(Sg,tt(n,t),`block is not a text kind block: ${Dt(t)}`),g(Sg,e>=0&&e<=ut(n,t),`invalid offset: ${e}`);const r=nt(t),i=at(r),s=bt(t),l=o!=null&&o.copyBlockAttributes?_6(n,t):{};if(!(o!=null&&o.forceInsertAfter)&&(e===0||e===ut(n,t))){const v=e===0?s:s+1,B={...cr(""),...l,...o==null?void 0:o.newBlockData},D=Ce(n,t.id,0),x=Zl(n,i,v,B,D);return{block:t,newBlock:x}}g(Sg,sn(t,e),"not a valid offset");const a=gn(n,t),{right:d}=In(a,e),h=rn(d);h>0&&Dg(n,t,e,h);const p={...cr(d),...l,...o==null?void 0:o.newBlockData},A=Zl(n,i,s+1,p,Ce(n,p.id,0));return{block:t,newBlock:A}}const aT=S("prepare-insert-new-block");function uT(n,t,e){if(t&&e!==void 0&&e!==null){const d=n.getContainerById(t),h=pe(d);return g(aT,e>=0&&e<=h.length,`invalid blockIndex: ${e}`),{containerId:t,blockIndex:e}}const o=n.selection.range.start;if(!o.isSimple())return null;const r=n.getBlockById(o.blockId);if(t=at(nt(r)),e=bt(r),!tt(n,r))return{containerId:t,blockIndex:e+1};const s=o.offset;if(s===0||s===ut(n,r))return{containerId:t,blockIndex:s===0?e:e+1};const a=Ql(n,r,s).newBlock;return{containerId:t,blockIndex:bt(a)}}const dT=S("auto-insert-block");function F6(n,t,e,o,r,i){const s=uT(n,e,o);g(dT,s,`not an valid insert position: ${n.selection.range}`);const l={blockId:t.id,offset:0},a={anchor:l,focus:l};return Zl(n,s.containerId,s.blockIndex,t,r!=null?r:a,i)}const hT=S("delete-block");function wh(n,t,e){t.children&&(e.push(...t.children),t.children.forEach(o=>{n.getChildContainerData(o).forEach(i=>{wh(n,i,e)})}))}function Bh(n,t,e){const o=nt(t),r=at(o),i=bt(t),s=n.doc.getBlockData(r,i);return g(hT,s,"no block data in doc"),n.doc.localDeleteBlock(r,i,Ue(n,{anchor:e.start,focus:e.end})),s}function Lg(n,t,e){return n.undoManager.runInGroup(()=>{const o=nt(t);Io(o)===1&&n.insertTextBlock("",at(o),0);let r=e?Mi(n,e):null;if(!r){const l=n.selection.range;I6(t,l)?r=T6(n,t):r=l}const i=Bh(n,t,r),s=[];return wh(n,i,s),s.length>0&&n.doc.localDeleteChildContainers(s),i})}function fT(n,t){const e=[t];n.doc.getContainerBlocks(t).forEach(r=>{wh(n,r,e)}),n.doc.localDeleteChildContainers(e)}function P6(n,t){const e=[...t];t.forEach(o=>{n.doc.getContainerBlocks(o).forEach(i=>{wh(n,i,e)})}),n.doc.localDeleteChildContainers(e)}const Mg=S("merge-text-block");function N6(n,t,e){g(Mg,tt(n,t),"only text block can be merged"),g(Mg,tt(n,e),"only text block can be merged");const o=_i(n,t),r=_i(n,e),i=o.text,s=r.text;g(Mg,i&&s,"block data has no text");const l=nt(t),a=at(l),d=bt(t),h=ut(n,t),p=Ig(n,s,a,d,h),A=Ce(n,t,rn(i));return Lg(n,e,A),p}const ar=S("clear-selected-contents");function Eh(n,t){g(ar,tt(n,t.block),"not a text kind block");const{start:e,end:o}=t;g(ar,e.isSimple(),"not a simple block position"),g(ar,o.isSimple(),"not a simple block position");const r=e.offset,i=o.offset;g(ar,r<=i,`invalid delete text offset: ${r}, ${i}`),r!==i&&n.deleteTextFromBlock(t.block,r,i-r)}function $6(n,t,e){const o=at(t),r=pe(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 mT(n,t){const{block:e,start:o,end:r}=t;if(tt(n,e)){Eh(n,t);return}if(Me(e)||o.isSimple()){g(ar,r.isSimple(),"invalid range");const s=nt(e),l=bt(e),a=n.insertTextBlock("",at(s),l);n.selection.selectBlock(a,0),n.deleteBlock(e);return}g(ar,Mt(n,e),"invalid block kind"),g(ar,!o.isSimple()&&!r.isSimple(),"invalid range"),Rs(n,e,o,r),n.selection.range.getSelectedContainers().forEach((s,l)=>{$6(n,s,{focus:l===0})})}function gT(n){if(!n.isWritable())return;const t=n.selection.range;if(t.isCollapsed())return;const e=t.getSelectedBlocks();if(g(ar,e.length>0,"no selected block"),e.length===1){mT(n,e[0]);return}const o=e[0],r=o.block,i=nt(r);g(ar,e.length>1,"no selected block");const s=e[e.length-1],l=s.block;if(tt(n,r)){Eh(n,o);const h=Ce(n,o.block,o.start.offset);if(e.slice(1,e.length-1).reverse().forEach(A=>n.deleteBlock(A.block)),tt(n,l)){Eh(n,s),n.mergeTextBlock(r,l,{focus:!0}),n.selection.setRange(h);return}n.deleteBlock(l),n.selection.setRange(h);return}if(tt(n,l)){Eh(n,s),e.slice(0,e.length-1).reverse().forEach(h=>n.deleteBlock(h.block)),n.selection.selectBlock(s.block,0);return}if(e.length===Io(i)){$6(n,i,{focus:!0});return}const a=ce(r),d=Zt(l);g(ar,a||d,"no prev or next block"),e.forEach(h=>n.deleteBlock(h.block))}function Rg(n){n.selection.range.isCollapsed()||n.undoManager.runInGroup(()=>{n.emit("beforeClearSelection",n);try{n.doc.beginBatchUpdate(),gT(n)}finally{n.doc.endBatchUpdate()}n.emit("afterClearSelection",n)})}const pT=S("core");function H6(n,t,e){const o=nt(t),r=at(o),i=bt(t);return n.doc.localUpdateBlockText(r,i,e),setTimeout(()=>{n.selection.updateSelection(null)}),gn(n,t)}function j6(n,t,e){if(!n.isBlockWritable(t)){pT.error("block is not writable");return}const o=n.getBlockText(t),r=ln.diff(o,e);H6(n,t,r)}function xh(n,t,e){const o=gn(n,t),r=typeof e=="string"?Oi(e):e,i=ln.diff(o,r);return H6(n,t,i)}const _a=S("update-block-data");function Ih(n,t,e,o){const r=nt(t),i=at(r),s=bt(t),l=n.doc.getBlockData(i,s),a={insert:{},delete:[]},d=new Set(Object.keys(l)),h=new Set(Object.keys(e));return d.forEach(A=>{if(!h.has(A)){if(A==="id"||A==="type"||A==="text")return;_a.debug(`delete key: ${A}`),a.delete.push(A)}}),Object.entries(e).forEach(([A,v])=>{g(_a,A!=="id"&&A!=="type",`invalid block data delta, ${A}`);const B=l[A];if(v==null){B!=null&&(_a.debug(`delete key: ${A}`),a.delete.push(A));return}B!==v&&(aa.default(B,v)||A==="text"&&ln.diff(B,v).length===0||(d.has(A)?(_a.debug(`replace key: ${A}`),a.delete.push(A)):_a.debug(`insert key: ${A}`),a.insert[A]=v))}),n.doc.localUpdateBlockData(i,s,a,o),_i(n,t)}function U6(n,t,e,o){const i={...n.getBlockData(t),embedData:e};return n.updateBlockData(t,i,o)}function Og(n,t,e){if(!Mt(n,t)||!(e!=null&&e.tryFocusToChildSimpleBlock)){n.selection.selectBlock(t,0);return}const r=zn(n,t).getChildContainers(n,t)[0],i=xe(r);Og(n,i,e)}function $s(n){const t=[];let e={};return n.forEach(o=>{t.push(...o.blocks.root);const{root:r,...i}=o.blocks;e={...e,...i}}),{blocks:{...e,root:t},meta:{},comments:{}}}const Fa=S("clone-block");function Fi(n,t,e,o){const r=n.getBlockClass(e.type);if(r.blockToDoc)return r.blockToDoc(t,e,(h,p)=>(g(Fa,e!==p,"invalid child block"),Fi(n,h,e,o)));let i={};const s=new Map,l=mt.default(e);l.children&&(l.children=l.children.map(h=>{const p=K(),A=t.blocks[h];g(Fa,Array.isArray(A),"invalid child blocks");const v=A.map(_=>Fi(n,t,_,o)),B=$s(v),{root:D,...x}=B.blocks;return i={...i,...x},i[p]=B.blocks.root,s.set(h,p),p}));const a=Array.from(s.entries()),d=h=>{for(const p of a){const[A,v]=p;{const B=`${A}/`;if(h.startsWith(B)){const D=h.substring(B.length),x=`${v}/${D}`;return Fa.debug(`replace key: ${h} -> ${x}`),x}}{const B=`${A}_`;if(h.startsWith(B)){const D=h.substring(B.length),x=`${v}_${D}`;return Fa.debug(`replace key: ${h} -> ${x}`),x}}}return h};return Array.from(Object.entries(l)).forEach(([h,p])=>{const A=d(h);A!==h&&delete l.key,l[A]=p}),l.id=K(),o&&(o.blockIdMap.set(e.id,l.id),s.forEach((h,p)=>o.containerIdMap.set(p,h))),{blocks:{root:[l],...i},meta:{},comments:{}}}function _g(n,t,e,o){const r=t.blocks[e];g(Fa,Array.isArray(r),"invalid child blocks");const i=r.map(l=>Fi(n,t,l,o));return $s(i)}function Fg(n,t,e){const o=t.blocks.root.map(r=>Fi(n.editorBlocks,t,r,e));return mt.default($s(o))}const z6=S("insert-doc");function V6(n,t,e,o,r){if(Mt(n,t)){z6.warn("failed to insert doc into a complex block");return}const i=Fg(n,o,r),s=nt(t),l=bt(t),a=at(s);n.doc.beginBatchUpdate(),n.undoManager.runInGroup(()=>{var M,H,z;Object.entries(i.blocks).forEach(([q,rt])=>{q!=="root"&&n.doc.localInsertChildContainer(q,rt)});const d=i.blocks.root;if(Me(t)){n.deleteBlock(t);let q;d.reverse().forEach(rt=>{const ft=n.insertBlock(a,l,rt,void 0,{noFocus:!0});q||(q=ft)}),q&&n.selection.selectBlock(q,ut(n,q));return}if(g(z6,tt(n,t),"not a text block"),he(n,t)){const q=a==="root"&&n.getBlockByIndex(a,0)===t,rt=bt(t);let ft;d.forEach((Bt,jt)=>{const Ut=n.insertBlock(a,rt+jt,Bt,void 0,{noFocus:!0});jt===d.length-1&&(ft=Ut)}),ft&&n.selection.selectBlock(ft,ut(n,ft)),q&&n.deleteBlock(t);return}if(d.length===1){const q=d[0];if(ya(n,q.type)){n.insertTextToBlock(t,e,(M=q.text)!=null?M:[]);return}n.breakTextBlock(t,e),n.insertBlock(a,l+1,q);return}const h=e===ut(n,t),p=e===0,A=d[0],v=d[d.length-1];let B;!h&&!p?B=n.breakTextBlock(t,e,{forceInsertAfter:!0}):B=t;const D=p?l:l+1;h?(B=n.insertBlock(a,l+1,v),n.selection.selectBlock(B,ut(n,B))):(n.selection.selectBlock(B,0),ya(n,v.type)?n.insertTextToBlock(B,0,(H=v.text)!=null?H:[]):n.insertBlock(a,D,v));const x=n.selection.range;let _=D;ya(n,A.type)?p?(n.insertBlock(a,D,A),_+=1):n.insertTextToBlock(t,e,(z=A.text)!=null?z:[]):(n.insertBlock(a,D,A),_+=1),d.slice(1,d.length-1).reverse().forEach(q=>{n.insertBlock(a,_,q)}),n.selection.setRange(x)}),n.doc.endBatchUpdate()}function Pg(n,t,e,o,r){const i=Fg(n,o,r),s=at(t),l=[];return n.undoManager.runInGroup(()=>{Object.entries(i.blocks).forEach(([d,h])=>{d!=="root"&&n.doc.localInsertChildContainer(d,h)}),i.blocks.root.reverse().forEach(d=>{const h=n.insertBlock(s,e,d);l.push(h)})}),l}function W6(n,t,e){const o=Io(t);Pg(n,t,o,e);for(let r=0;r<o;r++){const i=xe(t);n.deleteBlock(i)}}const Pa=S("add-text-attribute");function CT(n,t,e,o){const{start:r,end:i}=e;g(Pa,r.blockId===i.blockId&&r.blockId===it(t),"invalid range"),g(Pa,o,"invalid attribute name");const s=n.getBlockText(t),l=Wl(r.offset,i.offset-r.offset,s,o,void 0,{ignoreValue:!0});return n.setBlockText(t,l),l}function q6(n,t,e,o,r){const{start:i,end:s}=e;g(Pa,i.blockId===s.blockId&&i.blockId===it(t),"invalid range"),g(Pa,o,"invalid attribute name");const l=n.getBlockText(t),a=Ta(i.offset,s.offset-i.offset,l,o,r);return n.setBlockText(t,a),a}function Yl(n,t,e,o,r){const{start:i,end:s}=e;g(Pa,i.blockId===s.blockId&&i.blockId===it(t),"invalid range");const l=n.getBlockText(t),a=X4(i.offset,s.offset-i.offset,l,o,r);return n.setBlockText(t,a),a}function G6(n,t,e,o){const r=Ro(n,{simpleBlockOnly:!0});n.undoManager.runInGroup(()=>{r.forEach(i=>{const{block:s,start:l,end:a}=i;if(!tt(n,s))return;if(he(n,s)){o(n,it(s),t,e);return}const d=Ue(n,{anchor:l,focus:a});t==="color"||t==="backgroundColor"?Yl(n,s,d,t,e):(Yl(n,s,d,"color",null),Yl(n,s,d,"backgroundColor",null))})})}function Z6(n,t,e){const o=Ro(n,{simpleBlockOnly:!0});n.undoManager.runInGroup(()=>{o.forEach(r=>{const{block:i,start:s,end:l}=r;if(!tt(n,i))return;if(he(n,i)){(t==="clearColor"||t==="clearAll")&&e(n,it(i),"color",null),(t==="clearBackground"||t==="clearAll")&&e(n,it(i),"backgroundColor",null);return}const a=Ue(n,{anchor:s,focus:l});(t==="clearColor"||t==="clearAll")&&Yl(n,i,a,"color",null),(t==="clearBackground"||t==="clearAll")&&Yl(n,i,a,"backgroundColor",null)})})}function Ng(n,t){const e=Ro(n,{simpleBlockOnly:!0}).filter(s=>tt(n,s.block));if(e.length===0)return[null,null];const o=s=>{if(ut(n,s.block)===0)return t(n,it(s.block));const l=s.start,a=s.end,d=n.getBlockText(s.block);return n6(l.offset,a.offset-l.offset,d)};let[r,i]=o(e[0]);return r===null&&i===null?[r,i]:(e.forEach(s=>{const[l,a]=o(s);l===null||r===null?r=null:r=l===r?r:null,a===null||i===null?i=null:i=a===i?i:null}),[r,i])}const Wn=S("adjust-selection-pos");function Q6(n){const t=[];for(;n;){const e=nt(n);if(t.unshift(e),Yt(e))return t;const o=et(e);g(Wn,o,"child container has not parent container"),n=o}g(Wn,!1,"should not come here: getParentContainers")}function Y6(n,t){for(;t;){const e=nt(t);if(e===n)return t;const o=et(e);g(Wn,o,"could not find parent block for a child container"),t=o}g(Wn,!1,"no parent block in specified container")}function AT(n,t){const e=Q6(n),o=Q6(t);g(Wn,e.length>0&&o.length>0,"block has not parent container"),g(Wn,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=Y6(r,n),s=Y6(r,t);return{parentContainer:r,newBlock1:i,newBlock2:s}}function J6(n,t){let e=et(t);for(g(Wn,e,"element is not in a block");e;){const o=nt(e);g(Wn,Lo(o),"not a child container");const r=et(o);if(g(Wn,r,"child container has not parent block"),r===n)return o;e=r}g(Wn,!1,"failed to find parent container in complex block")}function Th(n,t,e){const o=n.getBlockById(t.blockId),r=n.getBlockById(e.blockId);if(o===r)return t instanceof je&&e instanceof je?{anchor:t,focus:e}:t instanceof Mo&&e instanceof Mo?rh(n,o,t,e):null;const i=nt(o),s=nt(r);if(i===s)return t instanceof Mo&&(t=st(o,0,"home")),e instanceof Mo&&(e=st(r,ut(n,r),"end")),g(Wn,t instanceof je,"not valid position type"),g(Wn,e instanceof je,"not valid position type"),{anchor:t,focus:e};if(o.contains(s))return null;if(r.contains(i)){if(t instanceof je&&e instanceof Mo){const B=n.getContainerById(e.childContainerId);if(B===i)return{anchor:e,focus:e};const D=et(i);if(D&&D===et(B)){const x=fe(D,at(i)),_=fe(D,at(B));return rh(n,D,x,_)}}return null}const l=jd(o,r)>0,{newBlock1:a,newBlock2:d}=AT(o,r);if(a===d){const B=a,D=J6(B,o),x=J6(B,r);return t=fe(a,at(D)),e=fe(a,at(x)),Wn.debug(`select in complex block: ${D.id}, ${x.id}`),rh(n,B,t,e)}let h=l?ut(n,a):0;a===o&&t instanceof je&&(h=t.offset);let A=l?0:ut(n,d);return d===r&&e instanceof je&&(A=e.offset),t=st(a,h,l?"end":"home"),e=st(d,A,l?"home":"end"),{anchor:t,focus:e}}const bT=S("move-complex-block-position");function vT(n,t,e){const o=n.getBlockById(t.blockId);g(bT,Mt(n,o),"is not a complex block");const r=zn(n,o),i=n.getContainerById(t.childContainerId),s=r.getNextContainer(n,o,i,e,{noWrap:!0});return s?fe(o,at(s)):null}const Na=S("move-simple-block-position");function K6(n,t){const e=xn(n,t,{visibleOnly:!0});g(Na,e.length>0,"complex block has not any child container");const o=e[0];return xe(o)}function X6(n,t){const e=xn(n,t,{visibleOnly:!0});g(Na,e.length>0,"complex block has not any child container");const o=e[e.length-1];return Qe(o)}function tA(n,t,e){const o=e?K6(n,t):X6(n,t);return Mt(n,o)?tA(n,o,e):o}function yT(n,t){const e=n.getBlockById(t.blockId);return Mt(n,e)&&t.offset===0?K6(n,e):Ds(e)}function kT(n,t){const e=n.getBlockById(t.blockId);return Mt(n,e)&&t.offset===1?X6(n,e):Ts(e)}function $g(n){return n==="ArrowLeft"||n==="ArrowUp"}function Hg(n,t,e){const o=nt(t);if(Yt(o))return null;const r=et(o);g(Na,r,"child container has not parent block"),g(Na,Mt(n,r),"is not a complex block");const i=zn(n,r).getNextContainer(n,r,o,e);return i?$g(e)?Qe(i):xe(i):Hg(n,r,e)}function wT(n,t,e){const o=nt(t);if(Yt(o))return null;const r=et(o);if(g(Na,r,"child container has not parent block"),$g(e)){const l=ce(r);if(l)return l}else{const l=Zt(r);if(l)return l}const i=Hg(n,r,e);if(i)return i;let s=r;for(;!Yt(nt(s));)s=et(nt(s));return $g(e)?ce(s):Zt(s)}function BT(n,t,e){return!Mt(n,t)||zn(n,t).enableKeyboardSelect?t:tA(n,t,e==="ArrowDown"||e==="ArrowRight")}function ET(n,t,e){const o=n.getBlockById(t.blockId),i=Qt(n,o).moveCaret(n,o,t,e);if(i)return i;let s=e==="ArrowDown"||e==="ArrowRight"?yT(n,t):kT(n,t);if(s||(s=Hg(n,o,e),s||(s=wT(n,o,e))),!s){if(e==="ArrowDown"||e==="ArrowRight"){if(n.readonly||!Yt(nt(o)))return null;const l=n.insertTextBlock("",at(n.rootContainer),Io(n.rootContainer));return st(l,0,"home")}return null}if(s=BT(n,s,e),tt(n,s)){const l=n.selection.getSuggestedCaretX();if(e==="ArrowDown")return Jx(n,s,o,t,l);if(e==="ArrowUp")return Yx(n,s,o,t,l)}return e==="ArrowLeft"||e==="ArrowUp"?st(s,ut(n,s),"end"):e==="ArrowRight"||e==="ArrowDown"?st(s,0,"home"):null}function xT(n,t,e){if(t==="ArrowLeft")return e.start;const o=e.end,r=n.getBlockById(o.blockId);if(tt(n,r))return o;const i=Zt(r);if(i)return st(i,0,"home");if(!Yt(nt(r))||n.readonly)return o;const s=n.insertTextBlock("",at(n.rootContainer),Io(n.rootContainer));return st(s,0,"home")}function IT(n,t,e){const o=n.selection.range;let r;if(o instanceof Ye)e==="move"&&!o.isCollapsed()&&(t==="ArrowLeft"||t==="ArrowRight")?r=xT(n,t,o):r=ET(n,o.getFocusedPos(),t);else if(r=vT(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=Qe(s);r=st(l,0,"home")}else{const l=xe(s);r=st(l,ut(n,l),"end")}}return r?e==="move"?{anchor:r,focus:r}:Th(n,o.anchor,r):null}function Pi(n,t,e){const o=IT(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 eA(n){return Pi(n,"ArrowLeft","move"),!0}function nA(n){return Pi(n,"ArrowRight","move"),!0}function oA(n){return Pi(n,"ArrowUp","move"),!0}function rA(n){if(Pi(n,"ArrowDown","move")||n.readonly)return!0;const t=n.getFocusedBlock(),e=nt(t);if(Yt(e)||Qe(e)!==t)return!0;const o=n.rootContainer;return n.insertTextBlock("",at(o),Io(o)),!0}function iA(n){return Pi(n,"ArrowDown","select"),!0}function sA(n){return Pi(n,"ArrowLeft","select"),!0}function lA(n){return Pi(n,"ArrowRight","select"),!0}function cA(n){return Pi(n,"ArrowUp","select"),!0}const aA=S("word-offset");function jg(n,t){const e=n.selection.range.focus;g(aA,e.isSimple(),"invalid range type");const o=n.getBlockById(e.blockId);if(he(n,o))return st(o,0,"home");if(e.offset===0||!tt(n,o)){const s=ce(o);if(!s)return null;const l=st(s,ut(n,s),"end");if(t==="select"&&tt(n,s)){const a=Ag(n,s,l.offset);return st(s,a,"normal")}return l}const r=Ag(n,o,e.offset);return st(o,r,"normal")}function Ug(n,t){const e=n.selection.range.focus;g(aA,e.isSimple(),"invalid range type");const o=n.getBlockById(e.blockId);if(he(n,o))return st(o,0,"end");if(e.offset===ut(n,o)||!tt(n,o)){const s=Zt(o);if(!s)return null;const l=st(s,0,"home");if(t==="select"&&tt(n,s)){const a=bg(n,s,l.offset);return st(s,a,"end")}return l}const r=bg(n,o,e.offset);return st(o,r,"normal")}function uA(n){if(!n.selection.range.focus.isSimple())return!1;const e=jg(n,"move");return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function dA(n){if(!n.selection.range.focus.isSimple())return!1;const e=Ug(n,"move");return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function hA(n){if(!n.selection.range.focus.isSimple())return!1;const e=jg(n,"select");return e?(n.selection.setSelection(n.selection.getAnchorPos(),e),n.selection.updateLastCaretRect(),!0):!1}function fA(n){if(!n.selection.range.focus.isSimple())return!1;const e=Ug(n,"select");return e?(n.selection.setSelection(n.selection.range.anchor,e),n.selection.updateLastCaretRect(),!0):!1}S("find-block");function zg(n,t){if(!Mt(n,t))return t;const o=zn(n,t).getChildContainers(n,t)[0],i=pe(o)[0];return zg(n,i)}function Vg(n,t){if(!Mt(n,t))return t;const e=zn(n,t).getChildContainers(n,t),o=e[e.length-1],r=pe(o),i=r[r.length-1];return Vg(n,i)}function mA(n){const t=Vg(n,Qe(n.rootContainer)),e=st(t,ut(n,t),"end");return n.selection.setSelection(e),!0}function gA(n){const t=zg(n,n.getFirstBlock()),e=st(t,0,"home");return n.selection.setSelection(e),!0}function pA(n){const t=zg(n,n.getFirstBlock()),e=st(t,0,"home");return n.selection.setSelection(n.selection.getAnchorPos(),e),!0}function Wg(n){const t=Vg(n,Qe(n.rootContainer)),e=st(t,ut(n,t),"end");return n.selection.setSelection(n.selection.getAnchorPos(),e),!0}const CA=S("line-offset");function AA(n){const t=n.selection.range.focus;g(CA,t.isSimple(),"invalid range type");const e=n.getBlockById(t.blockId);if(t.offset===0||!tt(n,e))return st(e,0,"home");let r=$4(e,t).start;const{next:i}=eh(e,r);return i&&so(i)&&va(i)==="br"&&(r+=1),st(e,r,"home")}function bA(n){const t=n.selection.range.focus;g(CA,t.isSimple(),"invalid range type");const e=n.getBlockById(t.blockId);if(t.offset===ut(n,e)||!tt(n,e))return st(e,ut(n,e),"end");const o=$4(e,t);return st(e,o.end,"end")}function vA(n){if(!n.selection.range.focus.isSimple())return!1;const e=AA(n);return e?(n.selection.setSelection(n.selection.getAnchorPos(),e),n.selection.updateLastCaretRect(),!0):!1}function yA(n){if(!n.selection.range.focus.isSimple())return!1;const e=bA(n);return e?(n.selection.setSelection(n.selection.getAnchorPos(),e),n.selection.updateLastCaretRect(),!0):!1}function kA(n){if(!n.selection.range.focus.isSimple())return!1;const e=AA(n);return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function wA(n){if(!n.selection.range.focus.isSimple())return!1;const e=bA(n);return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}const BA=S("find-block-position");function TT(n,t,e,o){g(BA,Mt(n,t),"is not a complex block");const r=zn(n,t).getChildContainers(n,t);g(BA,r.length>0,"complex block has not any child container");const i=So(n,e,o),s=i.left+i.width/2,l=i.top+i.height/2,a=T4(n,t,s,l);return qg(n,a,e,o)}function qg(n,t,e,o){if(Mt(n,t))return TT(n,t,e,o);const r=it(t);let i=Number.MAX_SAFE_INTEGER;const s=So(n,e,o),l=s.left+s.width/2,a=s.top+s.height/2;let d=st(r,0,"home");const h=ut(n,t);for(let p=0;p<=h;p++){const A=st(r,p,"normal"),v=So(n,t,A),B=nr(v,l,a);B<i&&(i=B,d=A)}return d}const EA=S("page-offset");function DT(n,t){const e=B6(n)*.9,r=t.getBoundingClientRect().bottom-e;if(r<KI(n))return n.getFirstBlock();const i=ce(t);if(!i)return n.getFirstBlock();let s=i;for(;s;){if(s.getBoundingClientRect().y<r)return s;s=ce(s)}return n.getFirstBlock()}function ST(n,t){const e=B6(n)*.9,o=t.getBoundingClientRect(),r=XI(n),i=o.top+e;if(i>r)return n.getLastBlock();const s=Zt(t);if(!s)return n.getLastBlock();let l=s;for(;l;){if(l.getBoundingClientRect().bottom>i)return l;l=Zt(l)}return n.getLastBlock()}function xA(n){const t=n.selection.range.focus;g(EA,t.isSimple(),"invalid range type");const e=n.getBlockById(t.blockId),o=DT(n,e);let r;return o===n.getFirstBlock()?r=st(o,0,"home"):r=qg(n,o,e,t),r}function IA(n){const t=n.selection.range.focus;g(EA,t.isSimple(),"invalid range type");const e=n.getBlockById(t.blockId),o=ST(n,e);let r;return o===n.getLastBlock()?r=st(o,ut(n,o),"end"):r=qg(n,o,e,t),r}function TA(n){if(!n.selection.range.focus.isSimple())return!1;const e=xA(n);return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function DA(n){if(!n.selection.range.focus.isSimple())return!1;const e=IA(n);return e?(n.selection.setSelection(e),n.selection.updateLastCaretRect(),!0):!1}function SA(n){if(!n.selection.range.focus.isSimple())return!1;const e=xA(n);if(!e)return!1;const o=Th(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 LA(n){if(!n.selection.range.focus.isSimple())return!1;const e=IA(n);if(!e)return!1;const o=Th(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 $a=S("select-all");function MA(n,t){const e=xe(n),o=Qe(n);return t.start.offset===0&&t.start.blockId===it(e)&&t.end.offset===ut(t.getEditor(),o)&&t.end.blockId===it(o)}function LT(n,t){const e=t.getEditor(),o=zn(e,n).getChildContainers(e,n),r=o[0],i=o[o.length-1],s=it(n);return t.start.blockId===s&&t.start.childContainerId===at(r)&&t.end.blockId===s&&t.end.childContainerId===at(i)}function MT(n,t){g($a,t,"no parent block"),g($a,Mt(n,t),"not a complex block");const e=zn(n,t).getChildContainers(n,t),o=e[0],r=e[e.length-1];n.selection.setRange(Ue(n,{anchor:fe(t,at(o)),focus:fe(t,at(r))}))}function RA(n,t){const e=nt(t);Gg(n,e)}function OA(n){const t=n.getFocusedBlock(),e=n.selection.range;if(e.start.isSimple()){if(e.start.blockId===e.end.blockId&&tt(n,t)){const r=e.start,i=e.end,s=ut(n,t);if(r.offset>0||i.offset<s)return n.selection.selectBlock(t,0,s),!1}return W(n.rootContainer,"select-all"),RA(n,xe(n.rootContainer)),!1}return g($a,!e.isSimple(),"invalid range type"),LT(t,e)?(RA(n,t),!1):(g($a,t,"no parent block"),g($a,Mt(n,t),"not a complex block"),MT(n,t),!0)}function Gg(n,t){const e=pe(t),o=e[0],r=e[e.length-1],i=st(o,0,"home"),s=st(r,ut(n,r),"end");n.selection.setSelection(i,s,{noScroll:!0})}function _A(n){Wg(n),n.focus()}const Zg=S("selected-block-to-doc");function FA(n,t,e){!t.children||t.children.forEach(o=>{const r=n.getChildContainerData(o);r.forEach(i=>{FA(n,i,e)}),e.blocks[o]=mt.default(r)})}function Dh(n,t){const e=Qt(n,t.block);if(e.selectionToDoc)return e.selectionToDoc(n,t);const o=mt.default(_i(n,t.block));if(tt(n,t.block)){const i=t.start,s=t.end;if(g(Zg,o.text,"no block text"),i.offset===s.offset)return{blocks:{root:[{...o,text:[]}]},meta:{},comments:{}};const{middle:l}=ze(o.text,i.offset,s.offset-i.offset);return{blocks:{root:[{...o,text:l}]},meta:{},comments:{}}}if(Me(t.block))return{blocks:{root:[o]},meta:{},comments:{}};g(Zg,Mt(n,t.block),"not complex block"),g(Zg,o.children,"no children");const r={blocks:{root:[o]},meta:{},comments:{}};return FA(n,o,r),r}function Qg(n,t){const e=st(t,0,"normal"),o=st(t,ut(n,t),"end");return Dh(n,{block:t,start:e,end:o})}const RT=S("block-to-doc");function OT(n,t){g(RT,t.length>0,"invalid params, no blocks");const e=t.map(o=>Qg(n,o));return $s(e)}function Sh(n){const e=n.selection.range.getSelectedBlocks().map(o=>Dh(n,o));return $s(e)}function PA(n,t){const e=n.getContainerById(t),i=pe(e).map(s=>({start:st(s,0,"home"),end:st(s,ut(n,s),"end"),block:s})).map(s=>Dh(n,s));return $s(i)}const Lh=S("editor-selection");class _T{constructor(t){m(this,"editor");m(this,"caret");m(this,"_range");m(this,"lastCaretRect");m(this,"handleBlockDelete",(t,e,o,r)=>{if(o||r.child)return;const i=this.range;if(I6(e,i)){Lh.debug("adjust selection because remote deleted current block");const s=T6(t,e);this.setRange(s,{noScroll:!0})}});this.editor=t;const e=t.getFirstBlock(),o=it(e);this.caret=new QI(t);const r=st(o,0,"normal");this._range=Ue(t,{anchor:r,focus:r}),this.lastCaretRect=null,this.editor.addListener("blockDeleted",this.handleBlockDelete),setTimeout(()=>{this.updateFocusedBlock(null)})}destroy(){this.caret.destroy()}get range(){return this._range}get focusedBlock(){return this.getFocusedBlock()}get startBlock(){return this.getStartBlock()}get endBlock(){return this.getEndBlock()}getFocusedBlock(){const t=this.range.focus;return this.editor.getBlockById(t.blockId)}getStartBlock(){const t=this.range.start;return this.editor.getBlockById(t.blockId)}getEndBlock(){const t=this.range.end;return this.editor.getBlockById(t.blockId)}selectBlock(t,e,o){const r=st(t,e,"normal");let i;o&&(i=st(t,o,"normal")),this.setSelection(r,i)}setSelection(t,e,o){if(e||(e=t),this.verifyPos(t),this.verifyPos(e),!this.selectionChanging(t,e))return this.range;const r=Ue(this.editor,{anchor:t,focus:e});if(this.range.isEqual(r))return this.range;const i=this._range;return this._range=r,this.selectionChanged(),this.updateFocusedBlock(i),xt(this.editor.rootContainer,"select-all")&&(!r.isSimple()||!oT(this.editor,r))&&ot(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(),YI(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(!Ur(t))return;const e=this.editor.getBlockById(t.blockId);this.lastCaretRect=So(this.editor,e,t)}getSuggestedCaretX(){var t;return(t=this.lastCaretRect)==null?void 0:t.x}scrollIntoView(){nT(this.editor)}verifyPos(t){const e=this.editor.getBlockById(t.blockId);if(t.isSimple())t.offset>=0&&t.offset<=ut(this.editor,e)||g(Lh,!1,"invalid block position, out of range");else{const o=t.childContainerId;!!this.editor.getContainerById(o)||g(Lh,!1,"invalid complex block position, no container found")}}updateFocusedBlock(t){if(t&&this.range.start.blockId===t.start.blockId)return;let e;t&&t.start.blockId===t.end.blockId&&(e=this.editor.findBlockById(t.start.blockId));let o;(this.range.isCollapsed()||!this.range.isSimple()||this.range.start.blockId===this.range.end.blockId)&&(o=this.editor.getBlockById(this.range.start.blockId));let r=!1;e&&xt(e,"focused")&&(ot(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=Sh(this.editor);return t==="text"?Ma(this.editor,e):t==="markdown"?Ra(this.editor,e):S6(this.editor,e)}removeAllBlockFocusedClass(){this.editor.rootContainer.querySelectorAll('div[data-type="editor-block"].focused, div[data-type="editor-block"].child-focused').forEach(t=>{ot(t,"focused"),ot(t,"child-focused")})}setBlockFocused(t){if(xt(t,"focused"))return!1;W(t,"focused");let e=nt(t);for(;Lo(e);){const o=et(e);g(Lh,o,"parent block not found"),W(o,"child-focused"),e=nt(o)}return!0}}function FT(n){const t=n.selection.range.focus;if(!t.isSimple())return;const e=n.findBlockById(t.blockId);!e||n.selection.selectBlock(e,0,ut(n,e))}function PT(n){const t=n.selection.range.focus;if(!t.isSimple())return;const e=n.findBlockById(t.blockId);if(!e||!tt(n,e))return;let o=jg(n,"select"),r=Ug(n,"select");if(!o||!r)return;const i=t.blockId;o.blockId!==i&&(o=st(e,0,"home")),r.blockId!==i&&(r=st(e,ut(n,e),"end")),n.selection.setSelection(o,r)}class NT{constructor(t){m(this,"editor");m(this,"startPos",null);m(this,"lastCaretRect");m(this,"mouseDownEvent",null);m(this,"autoScroll",null);m(this,"handleMouseDown",(t,e)=>{var r;this.mouseDownEvent=t;const o=L4(this.editor,t.x,t.y);if(o){if(o instanceof ir)return;if(!this.autoScroll&&e.autoScroll){const s=o.getSelectedBlocks(),l=ro(s[0].block);this.autoScroll=new Qd({scrollElement:l,edge:{top:50,bottom:50}})}const i=this.editor.selection.range;if(t.shiftKey&&i.isSimple()){const s=i.anchor;this.editor.selection.setSelection(s,o.focus),this.startPos=o.start}else this.editor.selection.setSelection(o.anchor,o.focus),this.startPos=o.start;this.editor.selection.updateLastCaretRect(),e.autoScroll&&((r=this.autoScroll)==null||r.active())}});m(this,"handleMouseMove",t=>{if(!this.startPos||!this.mouseDownEvent||Math.abs(this.mouseDownEvent.x-t.x)<3&&Math.abs(this.mouseDownEvent.y-t.y)<3)return;const e=ih(this.editor,t.x,t.y);if(!e)return;const o=Th(this.editor,this.startPos,e.end);if(!o)return;const{anchor:r,focus:i}=o;this.editor.selection.setSelection(r,i)});m(this,"handleMouseUp",t=>{var e;(e=this.autoScroll)==null||e.inactive(),this.startPos=null});this.editor=t,this.startPos=null,this.lastCaretRect=new DOMRect}isSelecting(){return this.startPos!==null}stopSelection(){this.startPos=null}handleDblClick(t){PT(this.editor)}handleTripleClick(t){FT(this.editor)}}function $T(n){return n.readonly||!n.isWritable()?!1:(n.undoManager.undo(),!0)}function HT(n){return n.readonly||!n.isWritable()?!1:(n.undoManager.redo(),!0)}const NA=S("delete-text");function $A(n,t,e,o){const r=o!=null?o:n.selection.range.start;r instanceof je||g(NA,!1,`invalid insert pos type: ${typeof r}`);const{blockId:i}=r,s=n.getBlockById(i);g(NA,tt(n,s),"block is not a text kind block");let{offset:l}=r;if(t==="backward"){if(l-e<0)return 0;if(!sn(s,l-e)){const a=Ri(s,l);e=l-a}}else if(t==="forward"&&l+e>ut(n,s))return 0;return t==="backward"&&(l-=e),n.deleteTextFromBlock(s,l,e)}function HA(n,t){if(n.getBlockData(t).quoted){const e={quoted:null};return n.updateBlockData(t,e),!0}return!1}const jT=S("handle-backspace");function Yg(n,t){if(!he(n,t))return;const e=nt(t);Io(e)!==1&&n.deleteBlock(t)}function UT(n,t){if(!n.selection.range.isCollapsed()){n.clearSelectedContents();return}const e=n.selection.range.start,o=n.getBlockById(e.blockId);if(tt(n,o))if(e.offset===0){if(HA(n,o))return;const r=ce(o);if(r){if(!n.isBlockWritable(r))return;if(tt(n,r))n.mergeTextBlock(r,o,{focus:!0});else if(Mt(n,r)){Yg(n,o);const i=zl(n,r);i?n.selection.selectBlock(i,ut(n,i)):n.selection.selectBlock(r,0,ut(n,r))}else Yg(n,o),g(jT,Me(r),"prev block is not embed block"),n.selection.selectBlock(r,1)}else{const i=nt(o);if(Lo(i)){const s=E4(n,i);if(s){if(!n.isBlockWritable(s))return;Yg(n,o),n.selection.selectBlock(s,ut(n,s))}}}}else $A(n,"backward",1,null),n.selection.updateLastCaretRect();else{const r=bt(o),i=nt(o);n.insertTextBlock("",at(i),r),n.deleteBlock(o)}}function zT(n,t){if(!n.selection.range.isCollapsed()){n.clearSelectedContents();return}const e=n.selection.range.start,o=n.getBlockById(e.blockId);if(tt(n,o))if(e.offset===ut(n,o)){const r=Zt(o);if(r){if(!n.isBlockWritable(r))return;tt(n,r)?n.mergeTextBlock(o,r,{focus:!0}):he(n,o)?n.deleteBlock(o,Ce(n,r,0)):n.deleteBlock(r)}}else $A(n,"forward",1,null);else{const r=bt(o),i=nt(o);n.insertTextBlock("",at(i),r),n.deleteBlock(o)}}function VT(n){const{range:t}=n.selection,{start:e,end:o}=t,r=n.getBlockById(e.blockId),i=n.getBlockById(o.blockId);if(r!==i||!Mt(n,r))return!1;if(Ur(e))return!0;const s=Rs(n,r,e,o),l=xn(n,r);return s.length===l.length}function WT(n,t){if(VT(n)){const o=n.getFocusedBlock(),r=bt(o),i=at(nt(o));n.insertTextBlock("",i,r+1);return}n.selection.range.isCollapsed()||n.clearSelectedContents();const e=n.getFocusedBlock();if(tt(n,e)){if(he(n,e)&&HA(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 qT(n,t){const e=n.selection.range.getSelectedBlocks()[0],{block:o}=e;if(!tt(n,o))return!1;const r=e.end;return n.insertBoxToBlock(o,r.offset,{type:"br",id:K(),box:!0,created:Date.now()}),!0}const GT=S("input-handler-actions");function ZT(n,t){return n.readonly||!n.isWritable()?!1:n.undoManager.runInGroup(()=>(WT(n),!0))}function QT(n,t){return n.readonly||!n.isWritable()?!1:n.undoManager.runInGroup(()=>(zT(n),!0))}function YT(n,t){return n.readonly||!n.isWritable()?!1:n.undoManager.runInGroup(()=>(UT(n),!0))}function JT(n,t){return n.readonly||!n.isWritable()?!1:n.undoManager.runInGroup(()=>(qT(n),!0))}function KT(n){return n.readonly||!n.isWritable()||!window.isSecureContext?!1:(navigator.clipboard.readText().then(t=>{n.input.handlePasteText(t,{toPlainText:!0})}).catch(t=>{GT.error(t)}),!0)}const Mh={ArrowDown:rA,ArrowUp:oA,ArrowLeft:eA,ArrowRight:nA,"Shift+ArrowDown":iA,"Shift+ArrowUp":cA,"Shift+ArrowLeft":sA,"Shift+ArrowRight":lA,"CtrlOrCmd+ArrowLeft":uA,"CtrlOrCmd+ArrowRight":dA,"CtrlOrCmd+Shift+ArrowLeft":hA,"CtrlOrCmd+Shift+ArrowRight":fA,"CtrlOrCmd+ArrowUp":gA,"CtrlOrCmd+ArrowDown":mA,"CtrlOrCmd+Shift+ArrowUp":pA,"CtrlOrCmd+Shift+ArrowDown":Wg,"CtrlOrCmd+A":OA,Home:kA,End:wA,"Shift+Home":vA,"Shift+End":yA,PageUp:TA,PageDown:DA,"Shift+PageUp":SA,"Shift+PageDown":LA,"CtrlOrCmd+Z":$T,"CtrlOrCmd+Shift+Z":HT,Enter:ZT,Delete:QT,Backspace:YT,"Shift+Enter":JT,"CtrlOrCmd+Shift+V":KT};function jA(n,t){return n.shortcuts.handleKeyboardEvents(n,t)!==void 0}function UA(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=>{UA(n,l,e)})})}function zA(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):UA(t,r,e)})}async function XT(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 tD(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 eD(n,t){const o=t.meta.resources;if(!o||Object.keys(o).length===0)return;let r=new Map;if(tD(n,t)){const s=Array.from(Object.keys(o));r=await XT(n,s),zA(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&&zA(n,t,i)}async function nD(n,t,e){await eD(n,t),n.undoManager.runInGroup(()=>{const{start:o,end:r}=n.selection.range,i=n.getBlockById(o.blockId);if(o.blockId===r.blockId&&Me(i)){const s=nt(i),l=n.getBlockIndex(i),[a]=n.insertDocAt(s,l+1,t,e);a&&n.selection.selectBlock(a,ut(n,a))}else{n.clearSelectedContents();const{block:s,offset:l}=ql(n);n.insertDoc(s,l,t,e)}})}const oD=["text/x-ones-editor-doc","image/*","text/office-html","text/html","text/plain","text/markdown","*"];function rD(n){let t;for(const e of oD)if(t=n[e],t)break;return t||null}function VA(n,t,e){if(t.type==="embed"){const s=t.embedData.src;if(s&&typeof s=="string")for(const l of s.split("|"))e.add(l);return}const o=t.text;o&&o.forEach(i=>{i.attributes&&i.attributes.src&&typeof i.attributes.src=="string"&&e.add(i.attributes.src)});const r=t.children;r&&r.forEach(i=>{n.blocks[i].forEach(l=>{VA(n,l,e)})})}function iD(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)}):VA(t,r,e)}),Array.from(e)}function Rh(n,t){return Ze.isFirefox?`<!doctype html><html><head><meta charset="utf8" /></head><body><canvas data-editor-doc="${Si(JSON.stringify(t))}" id="ones-editor-doc">${n}</body></html>`:`<!doctype html><html><head><meta charset="utf8" />${`<meta charset="utf-8"><ones-editor-doc data-source="ones-editor-doc::${Si(JSON.stringify(t))}::ones-editor-doc" />`}</head><body>${n}</body></html>`}function Oh(n,t){var i,s,l;const e=(l=(s=(i=n.doc).getServerMeta)==null?void 0:s.call(i))!=null?l:{},o=iD(n,t),r={};o.forEach(a=>{const d=n.doc.buildResourceUrl(a,{withToken:!0});r[a]=d}),t.meta={...e,resources:r}}function sD(n,t,e){if(t.preventDefault(),t.stopPropagation(),!t.clipboardData)return;let o=Sh(n);const r=e==null?void 0:e(n,t,o);if(r===!0)return;typeof r=="object"&&r!==null&&(o=r),Oh(n,o);const i=yh(n,o),s=Ra(n,o),l=Rh(i,o);t.clipboardData.setData("text/html",l),t.clipboardData.setData("text/plain",s),t.clipboardData.setData("text/x-ones-editor-doc",JSON.stringify(o))}async function _h(n,t){const e=Qg(n,t);Oh(n,e);const o=yh(n,e),r=Ra(n,e),i=Rh(o,e);return Sm([{type:"text/plain",data:new Blob([r],{type:"text/plain"})},{type:"text/html",data:new Blob([i],{type:"text/html"})}])}class lD{constructor(t){m(this,"editor");m(this,"handlers",[]);m(this,"onPasteText",async(t,e)=>{const o=new DataTransfer;o.setData("text/plain",t);const r=await this.editor.dataConverter.fromData(this.editor,o,e);r&&this.pasteDocs(r,null)});this.editor=t}onInsertText(t,e){if(!tt(this.editor,this.editor.getFocusedBlock()))return;const{containerId:o,blockIndex:r,offset:i}=ql(this.editor);this.handleBeforeInsertText(o,r,i,e)||(this.defaultInsertText(this.editor,o,r,i,e),this.handleAfterInsertText(o,r,i,e),this.editor.selection.updateLastCaretRect())}onKeyDown(t){if(this.handleBeforeKeyDown(t))return!0;const e=this.defaultHandleKeydown(this.editor,t);return this.handleAfterKeyDown(t)?!0:e}onChanged(t){for(let e=0;e<this.handlers.length;e++){const o=this.handlers[e];o.handleChanged&&o.handleChanged(this.editor,t)}}onRemoteChanged(t){for(let e=0;e<this.handlers.length;e++){const o=this.handlers[e];o.handleRemoteChanged&&o.handleRemoteChanged(this.editor,t)}}onCompositionStart(t){this.editor.updateCompositionText("",!1);const{containerId:e,blockIndex:o,offset:r}=ql(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}=ql(this.editor);for(let l=0;l<this.handlers.length;l++){const a=this.handlers[l];a.handleUpdateCompositionText&&a.handleUpdateCompositionText(this.editor,r,i,s,o)}this.editor.selection.updateLastCaretRect()}onCopy(t){sD(this.editor,t,(e,o,r)=>{for(let i=0;i<this.handlers.length;i++){const s=this.handlers[i];if(s.handleBeforeCopy){const l=s.handleBeforeCopy(this.editor,o,r);if(l===!0)return!0;if(typeof l=="object"&&l!=null)return l}}})}onCut(t){for(let o=0;o<this.handlers.length;o++){const r=this.handlers[o];if(r.handleBeforeCut&&r.handleBeforeCut(this.editor,t)===!0)return}if(this.onCopy(t),this.editor.selection.range.isCollapsed()){const o=this.editor.selection.focusedBlock;Me(o)&&this.editor.deleteBlock(o)}else Rg(this.editor)}onPaste(t){if(t.preventDefault(),t.stopPropagation(),!t.clipboardData)return;this.editor.dataConverter.fromData(this.editor,t.clipboardData).then(async o=>{o&&this.pasteDocs(o,t)})}onFocus(){W(this.editor.rootElement,"active")}onBlur(){ot(this.editor.rootElement,"active")}addHandler(t){this.handlers.push(t),this.handlers=this.handlers.sort((e,o)=>{var s,l;const r=(s=e.order)!=null?s:1;return((l=o.order)!=null?l:1)-r})}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){Tg(this.editor,i)}defaultHandleKeydown(t,e){return jA(this.editor,e)?(e.preventDefault(),e.stopPropagation(),!0):!1}async pasteDoc(t){for(let o=0;o<this.handlers.length;o++){const r=this.handlers[o];if(r.handleBeforePasteDoc&&await r.handleBeforePasteDoc(this.editor,t))return}const e={blockIdMap:new Map,containerIdMap:new Map};await nD(this.editor,t,e);for(let o=0;o<this.handlers.length;o++){const r=this.handlers[o];if(r.handleAfterPasteDoc&&await r.handleAfterPasteDoc(this.editor,t,e))return}}async pasteDocs(t,e){for(let r=0;r<this.handlers.length;r++){const i=this.handlers[r];if(i.handleBeforePaste&&await i.handleBeforePaste(this.editor,e,t))return}const o=rD(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 cD(n,t,e){const o=Fr(t,e);return o.remove(),o}S("copy-dom-attributes");const WA=["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 aD(n,t){for(let l=0;l<WA.length;l++){const a=WA[l];t[a]=n[a]}const e=n.attributes,o=t.attributes,r=[],i=[];for(let l=0;l<e.length;l++){const a=e[l],d=o.getNamedItem(a.name);d?d.value!==a.value&&(d.value=a.value,i.push(a)):r.push(a)}const s=[];for(let l=0;l<o.length;l++){const a=o[l];e.getNamedItem(a.name)||s.push(a)}r.forEach(l=>{t.setAttribute(l.name,l.value)}),i.forEach(l=>{t.setAttribute(l.name,l.value)}),s.forEach(l=>{t.removeAttribute(l.name)})}function qA(n){const t=Array.from(n.childNodes).filter(e=>!HC(e));return t.forEach(e=>{e.remove()}),t}function GA(n,t,e){var d;const o=n.getContainerById(t),r=Fr(o,e),i=Li(r),s=n.doc.getBlockData(t,e),l=Qt(n,r);if((d=l==null?void 0:l.handleUpdateBlock)==null?void 0:d.call(l,n,r,s))n.editorBlockRenders.updateBlock(n,i,r,s);else{const h=n.editorBlocks.createBlock(i,o,s),p=qA(h);qA(r),p.forEach(v=>{r.appendChild(v)});const A=Xd(h);if(A){const v=Xd(r);v&&v.remove(),r.appendChild(A)}aD(h,r)}r4(n,r,s),n.blockHooks.forEach(h=>{var p;(p=h.update)==null||p.call(h,n,i,o,r,s)}),setTimeout(()=>{n.selection.updateSelection(null)})}const uD=S("transform-selection");function ZA(n,t,e,o){const{range:r}=n.selection,{anchor:i,focus:s}=r;if(i.blockId!==t&&s.blockId!==t)return r;g(uD,i.isSimple()&&s.isSimple(),"invalid text pos type");let l=i;if(i.blockId===t){const d=ln.transformCursor(i.offset,e,o);l=st(t,d,"normal")}let a=s;if(s.blockId===t){const d=ln.transformCursor(s.offset,e,o);a=st(t,d,"normal")}return Ue(n,{anchor:l,focus:a})}const dD=S("handle-block-text-changed");function hD(n,t,e,o,r){const i=n.getContainerById(t),s=Fr(i,e),l=n.doc.getBlockData(t,e);if(g(dD,l.text,"no block text"),KC(n,s).setBlockText(n,s,l.text),!r){const a=ZA(n,l.id,o,r);n.selection.setRange(a,{noScroll:!0})}}function fD(n,t){const e=mt.default(n);return t.delete.forEach(r=>{delete e[r]}),{...e,...t.insert}}function QA(n,t,e,o){const r=Qt(n,t);r.handleDeleteBlock&&r.handleDeleteBlock(n,t,e,o),n.emit("blockDeleted",n,t,e,o)}function mD(n,t,e,o){const r=n.getBlockByIndex(t,e);r.querySelectorAll('[data-type="editor-block"]').forEach(i=>{QA(n,i,o,{child:!0})}),QA(n,r,o,{child:!1})}const _o=S("editor-doc");class gD extends ha{constructor(e,o,r){super();m(this,"localEvents",[]);this.editor=e,this.externalDoc=o,this.externalDoc.registerCallback(this),this.registerLocalEvents(r)}beginBatchUpdate(){return this.externalDoc.beginBatchUpdate()}endBatchUpdate(){return this.externalDoc.endBatchUpdate()}registerLocalEvents(e){this.localEvents.push(e)}toJSON(){return this.externalDoc.toJSON()}getVersionHelper(){var o,r;return(r=(o=this.externalDoc).getVersionHelper)==null?void 0:r.call(o)}getContainerBlocks(e){return this.externalDoc.getContainerBlocks(e)}getBlockData(e,o){return this.externalDoc.getBlockData(e,o)}verifyBlockWritable(e,o){const r=this.editor.getBlockByIndex(e,o);g(_o,this.editor.isBlockWritable(r),`block is not writable, ${e}, ${o}`)}localUpdateBlockText(e,o,r,i){g(_o,!this.editor.readonly,"editor is readonly"),this.verifyBlockWritable(e,o);const s=this.getBlockData(e,o),l=s.text;g(_o,l,`no text, ${e}, ${o}`);const a=ZA(this.editor,s.id,r,!0),d=ln.apply(l,r);this.localEvents.forEach(p=>p.onBeforeUpdateBlockText(e,s.id,l,d,a.toDocRange()));const h=this.externalDoc.localUpdateBlockText(e,o,r);return this.editor.selection.setRange(a,i),h}localUpdateBlockData(e,o,r,i){g(_o,!this.editor.readonly,"editor is readonly");const s=this.editor.getBlockByIndex(e,o);if(!this.editor.isBlockWritable(s)){const h=Array.from(r.delete).filter(A=>A!=="comments"),p=Object.keys(r.insert).filter(A=>A!=="comments");(h.length>0||p.length>0)&&g(_o,!1,`block is not writable, comment supported only, ${JSON.stringify(r)}}`)}const l=mt.default(this.getBlockData(e,o)),a=mt.default(fD(l,r));this.localEvents.forEach(h=>h.onBeforeUpdateBlockData(e,l.id,l,a,i));const d=this.externalDoc.localUpdateBlockData(e,o,r,i);return this.editor.selection.setRange(Mi(this.editor,i)),d}localInsertBlock(e,o,r,i,s){g(_o,!this.editor.readonly,"editor is readonly"),this.localEvents.forEach(a=>a.onBeforeInsertBlock(e,o,r,i));const l=this.externalDoc.localInsertBlock(e,o,r,i);return s!=null&&s.noFocus||this.editor.selection.setRange(Mi(this.editor,i),s),l}localDeleteBlock(e,o,r){g(_o,!this.editor.readonly,"editor is readonly"),this.verifyBlockWritable(e,o);const i=mt.default(this.getBlockData(e,o));this.localEvents.forEach(l=>l.onBeforeDeleteBlock(e,o,i,r));const s=this.externalDoc.localDeleteBlock(e,o,r);return this.editor.selection.setRange(Mi(this.editor,r)),s}localDeleteChildContainers(e){return g(_o,!this.editor.readonly,"editor is readonly"),e.forEach(o=>{const r=mt.default(this.getContainerBlocks(o));this.localEvents.forEach(i=>i.onBeforeDeleteChildContainer(o,r))}),this.externalDoc.localDeleteChildContainers(e)}localInsertChildContainer(e,o){return g(_o,!this.editor.readonly,"editor is readonly"),this.localEvents.forEach(r=>r.onBeforeInsertChildContainer(e,mt.default(o))),this.externalDoc.localInsertChildContainer(e,o)}onRequestReload(e){_o.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)}),hD(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)}),GA(this.editor,e,o),this.editor.emit("docChanged",this.editor,i)}onInsertBlock(e,o,r,i){this.callbacks.forEach(l=>{var a;return(a=l.onInsertBlock)==null?void 0:a.call(l,e,o,r,i)});const s=this.editor.getContainerById(e);nx(this.editor,s,o,r),this.editor.emit("docChanged",this.editor,i)}onDeleteBlock(e,o,r){mD(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);cD(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){_o.log("reset doc"),this.externalDoc=e,this.externalDoc.registerCallback(this),this.editor.reload()}}function YA(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 Jg=S("undo-action");class Jl{constructor(t,e,o){m(this,"beforeRange");m(this,"afterRange");this.containerId=e,this.beforeRange=t.selection.range.clone().toDocRange(),this.afterRange=o}undo(t){return!1}redo(t){return!1}combinable(t){return g(Jg,t,"no other action"),!1}combine(t){g(Jg,!1,"no other")}setAfterRange(t){this.afterRange&&Jg.warn("after range has already set"),this.afterRange=t}}const pD=S("block-action");class JA extends Jl{constructor(e,o,r,i,s){super(e,o,s);m(this,"blockData");m(this,"blockIndex");this.blockData=mt.default(i),this.blockIndex=r}deleteBlock(e,o){if(!e.getContainerById(this.containerId))return!1;const i=e.getBlockById(this.blockData.id);return i?(g(pD,this.blockIndex===bt(i),"invalid block index"),Bh(e,i,Mi(e,o)),!0):!1}insertBlock(e,o){return Zl(e,this.containerId,this.blockIndex,mt.default(this.blockData),o),!0}}class CD extends JA{undo(t){return this.deleteBlock(t,this.beforeRange)}redo(t){return this.insertBlock(t,this.afterRange)}}class AD extends JA{undo(t){return this.insertBlock(t,this.beforeRange)}redo(t){return this.deleteBlock(t,this.afterRange)}}class bD extends Jl{constructor(e){super(e,at(e.rootContainer),e.selection.range.toDocRange());m(this,"actions",[])}addAction(e){YA(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 Jl&&(o.afterRange||o.setAfterRange(e))}}const Hs=S("update-block-data-action");class Fh extends Jl{constructor(e,o,r,i,s,l){super(e,o,l);m(this,"beforeBlockData");m(this,"afterBlockData");m(this,"blockId");this.blockId=r,g(Hs,this.blockId===i.id,"invalid block id"),g(Hs,this.blockId===s.id,"invalid block id"),this.beforeBlockData=mt.default(i),this.afterBlockData=mt.default(s),g(Hs,this.beforeBlockData.type===this.afterBlockData.type,"invalid block type")}undo(e){g(Hs,e,"no editor");const o=e.getBlockById(this.blockId);if(!o)return!1;const r=e.getContainerById(this.containerId);return g(Hs,r,"no container"),Ih(e,o,Fh.toAttributes(this.beforeBlockData),this.beforeRange),!0}redo(e){g(Hs,e,"no editor");const o=e.getBlockById(this.blockId);if(!o)return!1;const r=e.getContainerById(this.containerId);return g(Hs,r,"no container"),Ih(e,o,Fh.toAttributes(this.afterBlockData),this.afterRange),!0}static toAttributes(e){const o=mt.default(e);return delete o.id,delete o.type,o}}const Kg=S("update-block-text-action");class Ha extends Jl{constructor(e,o,r,i,s,l){super(e,o,l);m(this,"beforeRichTextData");m(this,"afterRichTextData");m(this,"blockId");m(this,"type");this.blockId=r,this.beforeRichTextData=mt.default(i),this.afterRichTextData=mt.default(s),this.type=Ha.calType(i,s)}static calType(e,o){g(Kg,e,"no old data"),g(Kg,o,"no new data");const i=ln.diff(e,o),s=new Set;let l=!1;const a=h=>gC(h)?`cjk_${h}`:fC(h)?"number":zd(h)?"space":mC(h)?"letter":"unknown";let d=!1;return i.forEach(h=>{h.insert?h.insert===" "?s.add("insert_letter"):typeof h.insert=="string"&&h.insert.startsWith(" ")&&h.insert.length>1?(l=!0,d=!0,s.add(`insert_${a(h.insert.substr(1))}`)):s.add(`insert_${a(h.insert)}`):h.delete&&(l?l=!1:s.add("delete"))}),{textType:Array.from(s).join("|"),begin:d}}undo(e){if(!e.getContainerById(this.containerId))return!1;const r=e.getBlockById(this.blockId);return r?(xh(e,r,this.beforeRichTextData),!0):!1}redo(e){if(!e.getContainerById(this.containerId))return!1;const r=e.getBlockById(this.blockId);return r?(xh(e,r,this.afterRichTextData),!0):!1}combinable(e){if(!(e instanceof Ha)||e.type.begin||this.type.textType!==e.type.textType||e.blockId!==this.blockId)return!1;const o=e.beforeRange,r=o.anchor;if(!r.isSimple())return!1;const i=this.afterRange;if(!i)return!1;const s=i.anchor;return!(!s.isSimple()||s.blockId!==o.anchor.blockId||s.offset!==r.offset)}combine(e){g(Kg,e instanceof Ha,"invalid action type");const o=e;this.afterRichTextData=o.afterRichTextData,this.afterRange=e.afterRange}}class KA extends Jl{constructor(t,e,o){super(t,e,t.selection.range.toDocRange()),this.blocks=o}deleteChildContainer(t){return t.doc.localDeleteChildContainers([this.containerId]),!0}insertChildContainer(t){return t.doc.localInsertChildContainer(this.containerId,mt.default(this.blocks)),!0}}class vD extends KA{undo(t){return this.deleteChildContainer(t)}redo(t){return this.insertChildContainer(t)}}class yD extends KA{undo(t){return this.insertChildContainer(t)}redo(t){return this.deleteChildContainer(t)}}const Fo=S("undo");class kD{constructor(t){m(this,"editor");m(this,"actions",[]);m(this,"undoCursor");m(this,"currentGroup",null);m(this,"groupCounter",0);m(this,"undoRedoing",!1);m(this,"handleSelectionChange",t=>{if(this.currentGroup){this.currentGroup.setAfterRange(t.selection.range.toDocRange());return}const e=this.actions[this.actions.length-1];!e||e.afterRange||e.setAfterRange(t.selection.range.toDocRange())});this.editor=t,this.undoCursor=-1,this.editor.addListener("selectionChanged",this.handleSelectionChange)}reset(){this.actions=[],this.undoCursor=-1}prepareSaveUndoState(){this.undoCursor!==-1&&(this.actions.splice(this.undoCursor),this.undoCursor=-1)}addAction(t){this.currentGroup?this.currentGroup.addAction(t):(YA(this.actions,t),setTimeout(()=>{this.editor.input.handleChanged(t)}))}beginGroup(){this.groupCounter===0?(g(Fo,!this.currentGroup,"current group already exists"),this.currentGroup=new bD(this.editor),this.groupCounter=1):(g(Fo,this.currentGroup,"current group not exists"),this.groupCounter+=1)}endGroup(){g(Fo,this.currentGroup,"current group not exists"),g(Fo,this.groupCounter>0,"group counter === 0"),this.groupCounter-=1,this.groupCounter===0&&(this.currentGroup.actions.length===0?Fo.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 Fo.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(Mi(this.editor,t.beforeRange))}catch(e){Fo.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(Mi(this.editor,e)):Fo.warn("no after range")}catch(e){Fo.error(`redo: failed to set caret pos after redo: ${e.message}`)}return this.editor.input.handleChanged(t),!0}}return!1}finally{this.undoRedoing=!1}}canUndo(){return!(this.actions.length===0||this.undoCursor===0)}canRedo(){return!(this.actions.length===0||this.undoCursor===-1||this.undoCursor===this.actions.length)}lastAction(){var e;const t=this.undoCursor===-1?this.actions.length-1:this.undoCursor-1;return(e=this.actions[t])!=null?e:null}undoTo(t){for(;;){const e=this.lastAction();if(!e||e===t)return!0;if(!this.undo())return!1}}onBeforeUpdateBlockText(t,e,o,r,i){this.undoRedoing||(this.prepareSaveUndoState(),ln.diff(o,r).length!==0&&this.addAction(new Ha(this.editor,t,e,o,r,i)))}onBeforeUpdateBlockData(t,e,o,r,i){if(this.undoRedoing)return;this.prepareSaveUndoState();const s=new Fh(this.editor,t,e,o,r,i);this.addAction(s)}onBeforeInsertBlock(t,e,o,r){this.undoRedoing||(this.prepareSaveUndoState(),g(Fo,e>=0,"invalid block index"),g(Fo,o,"no block data"),this.addAction(new CD(this.editor,t,e,o,r)))}onBeforeDeleteBlock(t,e,o,r){this.undoRedoing||(this.prepareSaveUndoState(),this.addAction(new AD(this.editor,t,e,o,r)))}onBeforeInsertChildContainer(t,e){this.undoRedoing||(this.prepareSaveUndoState(),this.addAction(new vD(this.editor,t,e)))}onBeforeDeleteChildContainer(t,e){this.undoRedoing||(this.prepareSaveUndoState(),this.addAction(new yD(this.editor,t,e)))}}class wD{async fromData(t,e){const o=e.getData("text/x-ones-editor-doc");if(o)return{"text/x-ones-editor-doc":JSON.parse(o)}}}class BD{constructor(){m(this,"converters",[]);m(this,"converterTypes",["text/plain","text/markdown","text/html","text/x-ones-editor-doc"]);this.addConverter(new wD)}prepareData(t){const e=new DataTransfer;for(let o=0;o<this.converterTypes.length;o++)e.setData(this.converterTypes[o],t.getData(this.converterTypes[o]));return e}async fromData(t,e,o){let r={};const i=this.prepareData(e);for(const s of this.converters){const l=await s.fromData(t,i,o);l&&(r={...r,...l})}return r}addConverter(t){this.converters.push(t)}}class ED{constructor(t){m(this,"renders",[]);this.editor=t}registerRender(t){this.renders.push(t)}renderText(t,e){const o={classes:[],attributes:{},styles:{}};return this.renders.forEach(r=>{if(r.renderText){const i=r.renderText(this.editor,t,e);i.classes&&o.classes.push(...i.classes),i.attributes&&(o.attributes={...o.attributes,...i.attributes}),i.styles&&(o.styles={...o.styles,...i.styles})}}),o}renderBlock(t,e,o){const r={classes:[],attributes:{},styles:{}};return this.renders.forEach(i=>{if(i.renderBlock){const s=i.renderBlock(this.editor,e,o);s.classes&&r.classes.push(...s.classes),s.attributes&&(r.attributes={...r.attributes,...s.attributes}),s.styles&&(r.styles={...r.styles,...s.styles})}}),r}updateBlock(t,e,o,r){this.renders.forEach(i=>{var s;(s=i.updateBlock)==null||s.call(i,t,e,o,r)})}}class Ae extends ye.TypedEmitter{constructor(e){super();m(this,"hoveringBlock",null);m(this,"hoveringTextChild",null);m(this,"filters",[]);m(this,"finders",[]);m(this,"handleDocumentMouseMove",e=>{if(this.hoveringBlock){for(const s of this.filters)if(s.isInBlock(this.hoveringBlock,e))return}const o=document.elementFromPoint(e.x,e.y);if(!o){this.setHoveringBlock(null,e,null);return}let r=et(o);if((!r||!Xt(this.editor.rootContainer,r))&&(r=this.findBlockByFinders(e),!r)){this.setHoveringBlock(null,e,null);return}const i=this.getParentTextContentChild(r,o);this.setHoveringBlock(r,e,i)});this.editor=e,document.addEventListener("mousemove",this.handleDocumentMouseMove)}destroy(){document.removeEventListener("mousemove",this.handleDocumentMouseMove),this.filters.forEach(e=>e.destroy()),this.filters=[],this.finders.forEach(e=>e.destroy()),this.finders=[]}addFilter(e){this.filters.push(e)}addFinder(e){this.finders.push(e)}hoveringBlockId(){return this.hoveringBlock?it(this.hoveringBlock):""}findBlockByFinders(e){for(let o=0;o<this.finders.length;o++){const i=this.finders[o].findTargetBlock(this.editor,e);if(i)return i}return null}setHoveringBlock(e,o,r){if(this.hoveringBlock===e&&this.hoveringTextChild===r)return;if(this.hoveringBlock!==e){const s=this.hoveringBlock&&Xt(this.editor.rootContainer,this.hoveringBlock)?this.hoveringBlock:null;s&&ot(s,"hover"),e&&W(e,"hover"),this.hoveringBlock=e,this.emit("change",this.hoveringBlock,s,o)}const i=this.hoveringTextChild;this.hoveringTextChild=r,this.emit("childChange",this.hoveringBlock,r,i,o)}static get(e){return e.addCustom("standard-hovering-block",()=>new Ae(e))}getParentTextContentChild(e,o){if(!tt(this.editor,e))return null;const r=Lt(e);return o.parentElement===r?o:Pm(o)}}const XA="style-color-",tb="style-bg-color-";class xD{renderText(t,e,o){const r=[],i={},s={};return Object.entries(o).forEach(([l,a])=>{a===!0?l.startsWith(XA)?i["data-style-color"]=l.substring(XA.length):l.startsWith(tb)?i["data-style-bg-color"]=l.substring(tb.length):l.startsWith("style")&&r.push(l):typeof a=="string"&&(l==="link"&&(r.push("link"),i.link=a),l==="inline-style-color"&&(s.color=a))}),{classes:r,attributes:i,styles:s}}renderBlock(t,e,o){var l,a;const r={};Object.entries(o).filter(d=>d[0].startsWith("style-")).forEach(([d,h])=>{r[`data-${d}`]=`${h}`});const s=[];return((a=(l=t.selection)==null?void 0:l.range)==null?void 0:a.start.blockId)===o.id&&s.push("focused"),typeof o.align=="string"&&o.align&&(r["data-style-align"]=o.align),o.heading&&(r["data-style-heading"]=String(o.heading)),o.quoted&&(r["data-style-quoted"]="true"),Ae.get(t).hoveringBlockId()===o.id&&s.push("hover"),{attributes:r,classes:s}}updateBlock(t,e,o,r){var s,l;Array.from(o.attributes).forEach(a=>{a.name.startsWith("data-style-")&&o.removeAttribute(a.name)}),Object.entries(r).filter(a=>a[0].startsWith("style-")||a[0]==="align").forEach(([a,d])=>{a==="align"&&o.setAttribute(a.startsWith("style-")?`data-${a}`:`data-style-${a}`,`${d}`)}),((l=(s=t.selection)==null?void 0:s.range)==null?void 0:l.start.blockId)===r.id&&W(o,"focused"),Ae.get(t).hoveringBlockId()===r.id&&W(o,"hover")}}function ID(n){n.editorBlocks.registerBlockClass(Tn),n.editorBlocks.registerBlockClass(B4),n.editorBoxes.registerBoxClass(f6),n.editorBoxes.registerBoxClass(m6),n.editorBoxes.registerBoxClass(C6),n.editorBoxes.registerBoxClass(A6),n.editorInsertions.registerInsertionClass(b6),n.editorBlockRenders.registerRender(new xD)}function TD(n,t){ID(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 eb=S("range-commands");function nb(n,t){n.forEach(e=>{e.source=t,e.children&&nb(e.children,t)})}function ob(n,t,e){const o=it(t);g(eb,o===e.start.blockId,"invalid start range"),g(eb,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);nb(l,s.id),i.push(...l)}),r.forEach(s=>{if(s.filterCommands){const l=s.filterCommands(n,t,e,i);l&&(i=l)}}),Mt(n,t)&&Rs(n,t,e.start,e.end).forEach(l=>{pe(l).forEach(d=>{const h=ut(n,d),p=Ue(n,{anchor:st(d,0,"home"),focus:st(d,h,"end")}),A=ob(n,d,p);i.push(...A)})}),i}function rb(n){const t=n.getEditor(),e=n.getSelectedBlocks(),o=[];return e.forEach(r=>{const i=Ue(t,{anchor:r.start,focus:r.end});ob(t,r.block,i).forEach(l=>{o.push(l)})}),o}function ib(n,t,e,o,r,i){var h;const s=n.editorCommandProviders.getCommandProviders();for(let p=0;p<s.length;p++){const A=s[p];if(A.beforeExecuteCommand&&A.beforeExecuteCommand(n,t,e,o,r))return!1}const l=n.editorCommandProviders.getCommandProvider(o.source),a={};if((h=l.executeCommand)!=null&&h.call(l,n,t,e,o,r,{}))return i[it(t)]=a,!0;let d=!1;return Mt(n,t)&&Rs(n,t,e.start,e.end).forEach(A=>{pe(A).forEach(B=>{const D=ut(n,B),x=Ue(n,{anchor:st(B,0,"home"),focus:st(B,D,"end")});ib(n,B,x,o,r,i)&&(d=!0)})}),s.forEach(p=>{p.afterExecuteCommand&&p.afterExecuteCommand(n,t,e,o,r,i)}),d}function sb(n,t,e){const o=n.getEditor(),r={},i=o.editorCommandProviders.getCommandProvider(t.source);return i.executeRangeCommand&&i.executeRangeCommand(o,n,t,e,r)||n.getSelectedBlocks().forEach(l=>{const a=Ue(o,{anchor:l.start,focus:l.end});ib(o,l.block,a,t,e,r)}),r}const DD=S("command-providers");class lb{constructor(t){m(this,"providers",[]);this.editor=t}registerCommandProvider(t){this.providers.push(t)}getCommandProviders(){return this.providers}getCommandProvider(t){const e=this.providers.find(o=>o.id===t);return g(DD,e,`no command provider, id=${t}`),e}getCommands(t){return rb(t)}executeCommand(t,e,o){return this.editor.undoManager.runInGroup(()=>sb(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 SD(n,t){const e=nt(t),o=at(e),r=bt(t);GA(n,o,r)}const LD=S("table-scroll");class cb{constructor(t,e,o,r,i){m(this,"handleEvent",t=>{this.handler(this.editor,t,this.data)});this.editor=t,this.dom=e,this.name=o,this.handler=r,this.data=i,e.addEventListener(o,this.handleEvent)}destroy(){this.dom.removeEventListener(this.name,this.handleEvent)}}class MD{constructor(t){m(this,"handlers",new Map);this.editor=t}destroy(){Array.from(this.handlers.entries()).forEach(([t,e])=>{e.forEach(o=>o.destroy()),this.handlers.delete(t)})}addEventListener(t,e,o,r){const i=this.handlers.get(t);if(i){if(i.find(s=>s.handler===o&&s.name===e)){LD.warn(`event has already registered: ${e}`);return}i.push(new cb(this.editor,t,e,o,r))}else{const s=new cb(this.editor,t,e,o,r);this.handlers.set(t,[s])}}removeEventListener(t,e,o){if(!t){for(const[i,s]of Array.from(this.handlers.entries()))for(let l=s.length-1;l>=0;l--){const a=s[l];if(e)e===a.name&&o===a.handler&&s.splice(l,1);else if(o===a.handler){s.splice(l,1),a.destroy(),s.length===0&&this.handlers.delete(i);continue}}return}const r=this.handlers.get(t);if(r){const i=r.findIndex(s=>s.handler===o&&s.name===e);if(i!==-1){const s=r[i];r.splice(i,1),s.destroy(),r.length===0&&this.handlers.delete(t)}}}removeAllListeners(t,e){const o=this.handlers.get(t);if(o)if(e)for(let r=0;r<o.length;r++){const i=o[r];i.name===e&&(o.splice(r,1),i.destroy())}else o.forEach(r=>{r.destroy()}),this.handlers.delete(t)}}const ab=S("update-block-text");function RD(n,t){const e=n.getBoxById(t.id),o=et(e);g(ab,o,"no parent block"),g(ab,tt(n,o),"not a text block");const r=n.getBlockText(o),i=r6(r,"id",t.id,t);j6(n,o,i)}function OD(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 _D(n){return n.readonly?!1:!Ro(n).find(o=>!n.isBlockWritable(o.block))}class FD{constructor(t){this.editor=t}getKey(t){return`${this.editor.id}-${t}`}getItem(t){return window.localStorage.getItem(this.getKey(t))}setItem(t,e){if(!e){this.removeItem(t);return}window.localStorage.setItem(this.getKey(t),e)}removeItem(t){window.localStorage.removeItem(this.getKey(t))}}class PD{constructor(){m(this,"shortcuts",[])}handleKeyboardEvents(t,e){const o=this.shortcuts;for(const r of o){const i=Object.entries(r);for(const[s,l]of i)if(or(e,s)){const a=l(t,e);if(a!==void 0)return a}}}}const Gr=S("editor");class ND extends ye.TypedEmitter{constructor(e,o,r){var i,s,l,a,d,h,p;super();m(this,"parent");m(this,"rootElement");m(this,"contentElement");m(this,"rootContainerObject");m(this,"rootContainer");m(this,"input");m(this,"selection");m(this,"selectionHandler");m(this,"doc");m(this,"id");m(this,"clientId");m(this,"compositingText","");m(this,"undoManager");m(this,"shortcuts",new PD);m(this,"dataConverter",new BD);m(this,"editorBlocks",new v4(this));m(this,"editorBoxes",new p6(this));m(this,"editorInsertions",new y6(this));m(this,"editorEmbeds",new k4(this));m(this,"editorDecorators",new k6(this));m(this,"editorCommandProviders",new lb(this));m(this,"editorBlockRenders",new ED(this));m(this,"blockHooks",[]);m(this,"domEvents",new MD(this));m(this,"customs",new Map);m(this,"options");m(this,"inputHandlers",new lD(this));m(this,"settingsProvider");m(this,"_readonly",!1);Gr.debug("create editor"),this.setMaxListeners(100),this.options={colors:(i=r==null?void 0:r.colors)!=null?i:["#9923E9","#4587C2","#8BDB7A","#FB28D3","#CBC619","#10FEEB","#812A1A","#8A3F25","#22D742","#A53E74","#555C87","#57E0AA"],componentsOptions:(l=(s=r==null?void 0:r.components)==null?void 0:s.options)!=null?l:{},scrollContainer:r==null?void 0:r.scrollContainer},this.settingsProvider=(a=r==null?void 0:r.settingsProvider)!=null?a:new FD(this),TD(this,r==null?void 0:r.components),this.blockHooks.push(...(h=(d=r==null?void 0:r.components)==null?void 0:d.blockHooks)!=null?h:[]),this.id=(p=r==null?void 0:r.id)!=null?p:K(),this.clientId=K(),this.undoManager=new kD(this),this.doc=new gD(this,o,this.undoManager),this.parent=e,this.rootElement=w("div",["editor-root"],this.parent),this.rootElement.setAttribute("data-editor-client-id",this.clientId),this.contentElement=w("div",["editor-content"],this.rootElement),this.rootContainerObject=C4(this),this.rootContainer=this.rootContainerObject.rootContainer,this.input=new ZI(this,this.inputHandlers),this.selection=new _T(this),this.selectionHandler=new NT(this),r!=null&&r.shortcuts&&this.shortcuts.shortcuts.push(...r.shortcuts),Ze.isMobile&&W(this.rootElement,"mobile"),Ze.isSafari&&W(this.rootElement,"safari"),this._readonly&&W(this.rootElement,"readonly"),this.emit("load",this,!1)}get readonly(){return this._readonly}set readonly(e){this._readonly=e,e?W(this.rootElement,"readonly"):ot(this.rootElement,"readonly"),this.emit("readonlyChanged",this)}get scrollContainer(){return this.options.scrollContainer?this.options.scrollContainer:ro(this.rootContainer)}addCustom(e,o){const r=this.customs.get(e);if(r)return r;const i=o(this);return this.customs.set(e,i),i}getCustom(e){const o=this.customs.get(e);return g(Gr,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(){Gr.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(),setTimeout(()=>{W(this.rootElement,"active")})}focusToBlock(e,o){Og(this,e,o)}isWritable(){return _D(this)}isBlockWritable(e){return OD(this,e)}getChildContainerData(e){const o=this.doc.getContainerBlocks(e);return g(Gr,o,`no child container data: ${e}, ${JSON.stringify(this.doc)}`),g(Gr,Array.isArray(o),`container data is not an array: ${JSON.stringify(o)}`),o}createChildContainer(e,o,r){return A4(this,e,o,r)}getFirstBlock(){return this.rootContainer.querySelector("[data-type=editor-block]")}getLastBlock(){const e=Array.from(this.rootContainer.querySelectorAll(":scope [data-type=editor-block]"));return e[e.length-1]}getFocusedBlock(){return this.selection.getFocusedBlock()}findBlockById(e){const o=this.rootContainer.querySelector(`#${e}`);return o&&g(Gr,Es(o),"not an valid block element"),o!=null?o:null}findBoxById(e){const o=this.rootContainer.querySelector(`#${e}`);return o&&g(Gr,Fm(o),"not an valid box element"),o!=null?o:null}getBlockById(e){const o=this.findBlockById(e);return g(Gr,o,`no block, id=${e}`),o}getBoxById(e){const o=this.findBoxById(e);return g(Gr,o,`no box, id=${e}`),o}getBlockByIndex(e,o){const r=this.getContainerById(e);return Fr(r,o)}getBlockIndex(e){if(typeof e=="string"){const o=this.getBlockById(e);return bt(o)}return bt(e)}getContainerById(e){return jr(this,e)}getParentContainer(e){return nt(e)}reloadBlock(e){SD(this,e)}contains(e){const o=e instanceof Element?e:e.parentElement;return o?o.closest("div.editor-root")===this.rootElement:!1}insertBlock(e,o,r,i,s){const l={blockId:r.id,offset:0},a={anchor:l,focus:l};return Zl(this,e,o,r,i!=null?i:a,s)}insertEmbed(e,o,r,i,s){const l={id:K(),type:"embed",embedType:r,embedData:i};return this.insertBlock(e,o,l,s)}deleteBlock(e,o){Lg(this,e,o)}mergeTextBlock(e,o){return N6(this,e,o)}breakTextBlock(e,o,r){return Ql(this,e,o,r).newBlock}getTextPosition(){return ql(this)}getBlockString(e,o){const r=this.getBlockText(e);return ie(r,o)}getBlockData(e){return _i(this,e)}getBoxData(e){return d6(this,e)}getBlockText(e){return gn(this,e)}setBlockText(e,o){j6(this,e,o)}deleteTextFromBlock(e,o,r,i){return Dg(this,e,o,r,i)}insertTextToBlock(e,o,r,i){return L6(this,e,o,r,i)}insertBoxToBlock(e,o,r){return M6(this,e,o,r)}pasteDoc(e){return this.inputHandlers.pasteDoc(e)}insertDoc(e,o,r,i){V6(this,e,o,r,i)}insertDocAt(e,o,r,i){return Pg(this,e,o,r,i)}deleteChildContainers(e){P6(this,e)}replaceBlockText(e,o){return xh(this,e,o)}updateBlockData(e,o,r){const i={...this.getBlockData(e),...o},{id:s,type:l,...a}=i;return Ih(this,e,a,(r!=null?r:this.selection.range).toDocRange())}updateEmbedData(e,o,r){return U6(this,e,o,r)}updateBoxData(e){RD(this,e)}getSelectedText(){const e=Sh(this);return Ma(this,e)}clearSelectedContents(){Rg(this)}insertTextBlock(e,o,r,i){const s=cr(e!=null?e:"");return F6(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){O6(this);return}o?(this.compositingText="",Vd()||Tg(this,e)):(this.compositingText=e,R6(this))}getColor(e){const o=this.options.colors;return o.length===0?"#FF1A75":o[e%o.length]}}function ja(n,t,e){return new ND(n,t,e)}function $D(n){const t=(o,r)=>{const i=o.findIndex(l=>l.id===r.id);if(i===-1){o.push(r);return}const s=o[i];if(s.value!==r.value){o.splice(i,1);return}if(!!s.states){if(!r.states){s.states=[];return}s.states=fm.default(s.states,r.states)}},e=[];return n.forEach(o=>{o.forEach(r=>{t(e,r)})}),e}const HD=["#FBBFBD","#FFDDB6","#FFF897","#C5F0C1","#CEDDFE","#DCC9FC","#E5E6E8","#F76964","#FFA53D","#FFE928","#63D156","#A0BBFE","#C4A5FB","#BBBFC3"];class Ph extends ye.TypedEmitter{constructor(e){super();m(this,"users",new Map);m(this,"cursors",new Map);m(this,"addingUser",!1);m(this,"colors");this.colors=e&&e.length>0?e:HD}setCursor(e){this.addUser(e.user);const o=this.cursors.get(e.user.userId);if(o&&aa.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&&gh(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(gh(l.range)){const{anchor:a,focus:d}=l.range;a.blockId===e.id&&(a.offset=ln.transformCursor(a.offset,o,r)),d.blockId===e.id&&(d.offset=ln.transformCursor(d.offset,o,r))}})}getFixedUserColor(e,o){let r=0;Array.from(e).forEach(s=>{r+=s.charCodeAt(0)});const i=r%this.colors.length;return this.colors[i]}destroy(){this.removeAllListeners()}}const Xe=S("local-doc");class Xg extends ha{constructor(e,o){super();m(this,"doc");m(this,"serviceUrl");e?this.doc=e:this.doc={meta:{},comments:{},blocks:{root:[cr("")]}},this.serviceUrl=(o==null?void 0:o.serverUrl)||""}beginBatchUpdate(){return 0}endBatchUpdate(){return 0}toJSON(){return mt.default(this.doc)}getContainerBlocks(e){return this.doc.blocks[e]}getBlockData(e,o){const r=this.getContainerBlocks(e);g(Xe,r,`no container data: ${e}`);const i=r[o];return g(Xe,i,`no block data: ${o}`),i}localUpdateBlockText(e,o,r){const i=this.getBlockData(e,o);g(Xe,i.text,"no text for data");const s=ln.apply(i.text,r);return i.text=s,g(Xe,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(l=>{var a;return(a=l.onUpdateBlockText)==null?void 0:a.call(l,e,o,r,!0)}),s}localUpdateBlockData(e,o,r){const i=this.getBlockData(e,o);return r.delete.forEach(s=>delete i[s]),Object.entries(r.insert).forEach(([s,l])=>{i[s]=l}),g(Xe,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockData)==null?void 0:l.call(s,e,o,r,!0)}),i}localInsertBlock(e,o,r){const i=this.getContainerBlocks(e);return g(Xe,i,`no container data: ${e}`),g(Xe,o>=0&&o<=i.length,`invalid block index: ${o}, ${i.length}`),i.splice(o,0,r),g(Xe,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onInsertBlock)==null?void 0:l.call(s,e,o,r,!0)}),r}localDeleteBlock(e,o){const r=this.getContainerBlocks(e);g(Xe,r,`no container data: ${e}`),g(Xe,o>=0&&o<=r.length,`invalid block index: ${o}, ${r.length}`);const i=r[o];return r.splice(o,1),g(Xe,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onDeleteBlock)==null?void 0:l.call(s,e,o,!0)}),i}localInsertChildContainer(e,o){this.doc.blocks[e]=o,g(Xe,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(r=>{var i;return(i=r.onInsertChildContainer)==null?void 0:i.call(r,e,o,!0)})}localDeleteChildContainers(e){Xe.debug(`delete child containers: ${e}`),e.forEach(o=>{g(Xe,this.doc.blocks[o],`no child container: ${o}`),delete this.doc.blocks[o]}),e.forEach(o=>{g(Xe,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(r=>{var i;return(i=r.onDeleteChildContainer)==null?void 0:i.call(r,o,!0)})})}uploadResource(e,o){g(Xe,!1,"not implemented")}async addResources(e){return e}buildResourceUrl(e){return e}request(e,o){g(Xe,!1,"not implemented")}broadcastMessage(e){}getServerMeta(){return{serverId:this.serviceUrl}}getUser(){return{permission:"w",userId:"-",displayName:"-",avatarUrl:"-",rainbowIndex:0}}getRemoteUsers(){return new Ph}setDoc(e){this.doc=mt.default(e),this.callbacks.forEach(o=>{var r;return(r=o.onRequestReload)==null?void 0:r.call(o,"change doc")})}destroy(){this.clearCallbacks()}}class jD{constructor(t){this.cleanup=t}destroy(){var t;(t=this.cleanup)==null||t.call(this)}}function tp(n,t,e){n.addCustom(t,()=>{var i;const o=(i=e())!=null?i:void 0;return new jD(o)})}const ub=S("find-block");function db(n,t){const e=Ts(t);if(!e){if(io(t))return null;const o=xs(t);return g(ub,o,"no parent block"),db(n,o)}return Mt(n,e)?zl(n,e,{visibleOnly:!0}):e}function hb(n,t){const e=Ds(t);if(!e){if(io(t))return null;const o=xs(t);return g(ub,o,"no parent block"),hb(n,o)}return Mt(n,e)?Km(n,e,{visibleOnly:!0}):e}const UD=S("remote-cursor");class zD{constructor(){m(this,"remoteUsers",new Ph)}onCustomMessage(t){const e=t;if(e.type==="onlineUsers"){const o=e;this.handleUpdateUsers(o.users)}else e.type==="caret"?this.handleUpdateCaret(e):UD.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 VD(n){const{blocks:t,meta:e,comments:o,...r}=n;return{rootBlocks:t,meta:e,comments:o,childBlocks:r}}function WD(n){const{blocks:t,meta:e,comments:o}=n,{root:r,...i}=t;return{blocks:r,meta:e,comments:o,...i}}function Ua(n){const{childBlocks:t,meta:e,comments:o,rootBlocks:r}=VD(mt.default(n));return{blocks:{root:r,...t},meta:e,comments:o}}function Ni(n){return n==="root"?"blocks":n}function Kl(n){return n==="blocks"?"root":n}const qD={type:{name:"rich-text",uri:"http://sharejs.org/types/rich-text/v1",create(n){return new on.default(n)},apply(n,t){const e=new on.default(n),o=new on.default(t);return e.compose(o).ops},compose(n,t){const e=new on.default(n),o=new on.default(t);return e.compose(o).ops},diff(n,t){const e=new on.default(n),o=new on.default(t);return e.diff(o).ops},transform(n,t,e){const o=new on.default(n);return new on.default(t).transform(o,e==="left").ops},transformCursor(n,t,e){return t.transformPosition(n,!e)},normalize(n){return n},serialize(n){return n.ops},deserialize(n){return n},transformPresence(n,t,e){if(!n)return null;const o=new on.default(t),r=this.transformCursor(n.index,o,e),i=this.transformCursor(n.index+n.length,o,e);return{...n,index:r,length:i-r}}}};var ur=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},$i={},ep=G5.default.EventEmitter;$i.EventEmitter=ep,$i.mixin=GD;function GD(n){for(var t in ep.prototype)n.prototype[t]=ep.prototype[t]}var fb=["info","warn","error"];function mb(){var n={};fb.forEach(function(t){n[t]=console[t].bind(console)}),this.setMethods(n)}var ZD=mb;mb.prototype.setMethods=function(n){n=n||{};var t=this;fb.forEach(function(e){typeof n[e]=="function"&&(t[e]=n[e])})};var QD=ZD,YD=new QD,gb=YD;function js(n,t){this.code=n,this.message=t||"",Error.captureStackTrace?Error.captureStackTrace(this,js):this.stack=new Error().stack}js.prototype=Object.create(Error.prototype),js.prototype.constructor=js,js.prototype.name="ShareDBError",js.CODES={ERR_APPLY_OP_VERSION_DOES_NOT_MATCH_SNAPSHOT:"ERR_APPLY_OP_VERSION_DOES_NOT_MATCH_SNAPSHOT",ERR_APPLY_SNAPSHOT_NOT_PROVIDED:"ERR_APPLY_SNAPSHOT_NOT_PROVIDED",ERR_CLIENT_ID_BADLY_FORMED:"ERR_CLIENT_ID_BADLY_FORMED",ERR_CANNOT_PING_OFFLINE:"ERR_CANNOT_PING_OFFLINE",ERR_CONNECTION_SEQ_INTEGER_OVERFLOW:"ERR_CONNECTION_SEQ_INTEGER_OVERFLOW",ERR_CONNECTION_STATE_TRANSITION_INVALID:"ERR_CONNECTION_STATE_TRANSITION_INVALID",ERR_DATABASE_ADAPTER_NOT_FOUND:"ERR_DATABASE_ADAPTER_NOT_FOUND",ERR_DATABASE_DOES_NOT_SUPPORT_SUBSCRIBE:"ERR_DATABASE_DOES_NOT_SUPPORT_SUBSCRIBE",ERR_DATABASE_METHOD_NOT_IMPLEMENTED:"ERR_DATABASE_METHOD_NOT_IMPLEMENTED",ERR_DEFAULT_TYPE_MISMATCH:"ERR_DEFAULT_TYPE_MISMATCH",ERR_DOC_MISSING_VERSION:"ERR_DOC_MISSING_VERSION",ERR_DOC_ALREADY_CREATED:"ERR_DOC_ALREADY_CREATED",ERR_DOC_DOES_NOT_EXIST:"ERR_DOC_DOES_NOT_EXIST",ERR_DOC_TYPE_NOT_RECOGNIZED:"ERR_DOC_TYPE_NOT_RECOGNIZED",ERR_DOC_WAS_DELETED:"ERR_DOC_WAS_DELETED",ERR_INFLIGHT_OP_MISSING:"ERR_INFLIGHT_OP_MISSING",ERR_INGESTED_SNAPSHOT_HAS_NO_VERSION:"ERR_INGESTED_SNAPSHOT_HAS_NO_VERSION",ERR_MAX_SUBMIT_RETRIES_EXCEEDED:"ERR_MAX_SUBMIT_RETRIES_EXCEEDED",ERR_MESSAGE_BADLY_FORMED:"ERR_MESSAGE_BADLY_FORMED",ERR_MILESTONE_ARGUMENT_INVALID:"ERR_MILESTONE_ARGUMENT_INVALID",ERR_OP_ALREADY_SUBMITTED:"ERR_OP_ALREADY_SUBMITTED",ERR_OP_NOT_ALLOWED_IN_PROJECTION:"ERR_OP_NOT_ALLOWED_IN_PROJECTION",ERR_OP_SUBMIT_REJECTED:"ERR_OP_SUBMIT_REJECTED",ERR_OP_VERSION_MISMATCH_AFTER_TRANSFORM:"ERR_OP_VERSION_MISMATCH_AFTER_TRANSFORM",ERR_OP_VERSION_MISMATCH_DURING_TRANSFORM:"ERR_OP_VERSION_MISMATCH_DURING_TRANSFORM",ERR_OP_VERSION_NEWER_THAN_CURRENT_SNAPSHOT:"ERR_OP_VERSION_NEWER_THAN_CURRENT_SNAPSHOT",ERR_OT_LEGACY_JSON0_OP_CANNOT_BE_NORMALIZED:"ERR_OT_LEGACY_JSON0_OP_CANNOT_BE_NORMALIZED",ERR_OT_OP_BADLY_FORMED:"ERR_OT_OP_BADLY_FORMED",ERR_OT_OP_NOT_APPLIED:"ERR_OT_OP_NOT_APPLIED",ERR_OT_OP_NOT_PROVIDED:"ERR_OT_OP_NOT_PROVIDED",ERR_PRESENCE_TRANSFORM_FAILED:"ERR_PRESENCE_TRANSFORM_FAILED",ERR_PROTOCOL_VERSION_NOT_SUPPORTED:"ERR_PROTOCOL_VERSION_NOT_SUPPORTED",ERR_QUERY_EMITTER_LISTENER_NOT_ASSIGNED:"ERR_QUERY_EMITTER_LISTENER_NOT_ASSIGNED",ERR_SNAPSHOT_READ_SILENT_REJECTION:"ERR_SNAPSHOT_READ_SILENT_REJECTION",ERR_SNAPSHOT_READS_REJECTED:"ERR_SNAPSHOT_READS_REJECTED",ERR_SUBMIT_TRANSFORM_OPS_NOT_FOUND:"ERR_SUBMIT_TRANSFORM_OPS_NOT_FOUND",ERR_TYPE_CANNOT_BE_PROJECTED:"ERR_TYPE_CANNOT_BE_PROJECTED",ERR_TYPE_DOES_NOT_SUPPORT_PRESENCE:"ERR_TYPE_DOES_NOT_SUPPORT_PRESENCE",ERR_UNKNOWN_ERROR:"ERR_UNKNOWN_ERROR"};var Nh=js,za={},pb=JD;function JD(n,t,e,o){var r=function(s,l,a,d){t(a,s,l,"left"),t(d,l,s,"right")},i=n.transformX=function(s,l){e(s),e(l);for(var a=[],d=0;d<l.length;d++){for(var h=l[d],p=[],A=0;A<s.length;){var v=[];if(r(s[A],h,p,v),A++,v.length===1)h=v[0];else if(v.length===0){for(var B=A;B<s.length;B++)o(p,s[B]);h=null;break}else{for(var D=i(s.slice(A),v),x=0;x<D[0].length;x++)o(p,D[0][x]);for(var _=0;_<D[1].length;_++)o(a,D[1][_]);h=null;break}}h!=null&&o(a,h),s=p}return[s,a]};n.transform=function(s,l,a){if(!(a==="left"||a==="right"))throw new Error("type must be 'left' or 'right'");return l.length===0?s:s.length===1&&l.length===1?t([],s[0],l[0],a):a==="left"?i(s,l)[0]:i(l,s)[1]}}var Cb={exports:{}},Hi=Cb.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||""}},np=function(n,t,e){return n.slice(0,t)+e+n.slice(t)},op=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")},$h=function(n){for(var t=0;t<n.length;t++)op(n[t])};Hi.apply=function(n,t){var e;$h(t);for(var o=0;o<t.length;o++){var r=t[o];if(r.i!=null)n=np(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 Zr=Hi._append=function(n,t){if(!(t.i===""||t.d===""))if(n.length===0)n.push(t);else{var e=n[n.length-1];e.i!=null&&t.i!=null&&e.p<=t.p&&t.p<=e.p+e.i.length?n[n.length-1]={i:np(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:np(t.d,e.p-t.p,e.d),p:t.p}:n.push(t)}};Hi.compose=function(n,t){$h(n),$h(t);for(var e=n.slice(),o=0;o<t.length;o++)Zr(e,t[o]);return e},Hi.normalize=function(n){var t=[];(n.i!=null||n.p!=null)&&(n=[n]);for(var e=0;e<n.length;e++){var o=n[e];o.p==null&&(o.p=0),Zr(t,o)}return t};var rp=function(n,t,e){return t.i!=null?t.p<n||t.p===n&&e?n+t.i.length:n:n<=t.p?n:n<=t.p+t.d.length?t.p:n-t.d.length};Hi.transformCursor=function(n,t,e){for(var o=e==="right",r=0;r<t.length;r++)n=rp(n,t[r],o);return n};var KD=Hi._tc=function(n,t,e,o){if(op(t),op(e),t.i!=null)Zr(n,{i:t.i,p:rp(t.p,e,o==="right")});else if(e.i!=null){var r=t.d;t.p<e.p&&(Zr(n,{d:r.slice(0,e.p-t.p),p:t.p}),r=r.slice(e.p-t.p)),r!==""&&Zr(n,{d:r,p:t.p+e.i.length})}else if(t.p>=e.p+e.d.length)Zr(n,{d:t.d,p:t.p-e.d.length});else if(t.p+t.d.length<=e.p)Zr(n,t);else{var i={d:"",p:t.p};t.p<e.p&&(i.d=t.d.slice(0,e.p-t.p)),t.p+t.d.length>e.p+e.d.length&&(i.d+=t.d.slice(e.p+e.d.length-t.p));var s=Math.max(t.p,e.p),l=Math.min(t.p+t.d.length,e.p+e.d.length),a=t.d.slice(s-t.p,l-t.p),d=e.d.slice(s-e.p,l-e.p);if(a!==d)throw new Error("Delete ops delete different text in the same region of the document");i.d!==""&&(i.p=rp(i.p,e),Zr(n,i))}return n},XD=function(n){return n.i!=null?{d:n.i,p:n.p}:{i:n.d,p:n.p}};Hi.invert=function(n){n=n.slice().reverse();for(var t=0;t<n.length;t++)n[t]=XD(n[t]);return n},pb(Hi,KD,$h,Zr);var Hh=function(n){return Object.prototype.toString.call(n)=="[object Array]"},tS=function(n){return!!n&&n.constructor===Object},Po=function(n){return JSON.parse(JSON.stringify(n))},It={name:"json0",uri:"http://sharejs.org/types/JSONv0"},Qr={};It.registerSubtype=function(n){Qr[n.name]=n},It.create=function(n){return n===void 0?null:Po(n)},It.invertComponent=function(n){var t={p:n.p};return n.t&&Qr[n.t]&&(t.t=n.t,t.o=Qr[n.t].invert(n.o)),n.si!==void 0&&(t.sd=n.si),n.sd!==void 0&&(t.si=n.sd),n.oi!==void 0&&(t.od=n.oi),n.od!==void 0&&(t.oi=n.od),n.li!==void 0&&(t.ld=n.li),n.ld!==void 0&&(t.li=n.ld),n.na!==void 0&&(t.na=-n.na),n.lm!==void 0&&(t.lm=n.p[n.p.length-1],t.p=n.p.slice(0,n.p.length-1).concat([n.lm])),t},It.invert=function(n){for(var t=n.slice().reverse(),e=[],o=0;o<t.length;o++)e.push(It.invertComponent(t[o]));return e},It.checkValidOp=function(n){for(var t=0;t<n.length;t++)if(!Hh(n[t].p))throw new Error("Missing path")},It.checkList=function(n){if(!Hh(n))throw new Error("Referenced element not a list")},It.checkObj=function(n){if(!tS(n))throw new Error("Referenced element not an object (it was "+JSON.stringify(n)+")")};function Va(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 Wa(n){n.p.push(n.o[0].p),n.o[0].i!=null&&(n.si=n.o[0].i),n.o[0].d!=null&&(n.sd=n.o[0].d),delete n.t,delete n.o}It.apply=function(n,t){It.checkValidOp(t),t=Po(t);for(var e={data:n},o=0;o<t.length;o++){var r=t[o];(r.si!=null||r.sd!=null)&&Va(r);for(var i=null,s=e,l="data",a=0;a<r.p.length;a++){var d=r.p[a];if(i=s,s=s[l],l=d,i==null)throw new Error("Path invalid")}if(r.t&&r.o!==void 0&&Qr[r.t])s[l]=Qr[r.t].apply(s[l],r.o);else if(r.na!==void 0){if(typeof s[l]!="number")throw new Error("Referenced element not a number");s[l]+=r.na}else if(r.li!==void 0&&r.ld!==void 0)It.checkList(s),s[l]=r.li;else if(r.li!==void 0)It.checkList(s),s.splice(l,0,r.li);else if(r.ld!==void 0)It.checkList(s),s.splice(l,1);else if(r.lm!==void 0){if(It.checkList(s),r.lm!=l){var h=s[l];s.splice(l,1),s.splice(r.lm,0,h)}}else if(r.oi!==void 0)It.checkObj(s),s[l]=r.oi;else if(r.od!==void 0)It.checkObj(s),delete s[l];else throw new Error("invalid / missing instruction in op")}return e.data},It.shatter=function(n){for(var t=[],e=0;e<n.length;e++)t.push([n[e]]);return t},It.incrementalApply=function(n,t,e){for(var o=0;o<t.length;o++){var r=[t[o]];n=It.apply(n,r),e(r,n)}return n};var eS=It.pathMatches=function(n,t,e){if(n.length!=t.length)return!1;for(var o=0;o<n.length;o++)if(n[o]!==t[o]&&(!e||o!==n.length-1))return!1;return!0};It.append=function(n,t){if(t=Po(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)&&(Va(t),Va(e)),eS(t.p,e.p))if(t.t&&e.t&&t.t===e.t&&Qr[t.t]){if(e.o=Qr[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(),Wa(t),n.push(t);Wa(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)&&(Wa(t),Wa(e)),n.push(t)},It.compose=function(n,t){It.checkValidOp(n),It.checkValidOp(t);for(var e=Po(n),o=0;o<t.length;o++)It.append(e,t[o]);return e},It.normalize=function(n){var t=[];n=Hh(n)?n:[n];for(var e=0;e<n.length;e++){var o=n[e];o.p==null&&(o.p=[]),It.append(t,o)}return t},It.commonLengthForOps=function(n,t){var e=n.p.length,o=t.p.length;if((n.na!=null||n.t)&&e++,(t.na!=null||t.t)&&o++,e===0)return-1;if(o===0)return null;e--,o--;for(var r=0;r<e;r++){var i=n.p[r];if(r>=o||i!==t.p[r])return null}return e},It.canOpAffectPath=function(n,t){return It.commonLengthForOps({p:t},n)!=null},It.transformComponent=function(n,t,e,o){t=Po(t);var r=It.commonLengthForOps(e,t),i=It.commonLengthForOps(t,e),s=t.p.length,l=e.p.length;if((t.na!=null||t.t)&&s++,(e.na!=null||e.t)&&l++,i!=null&&l>s&&t.p[i]==e.p[i]){if(t.ld!==void 0){var a=Po(e);a.p=a.p.slice(s),t.ld=It.apply(Po(t.ld),[a])}else if(t.od!==void 0){var a=Po(e);a.p=a.p.slice(s),t.od=It.apply(Po(t.od),[a])}}if(r!=null){var d=s==l,a=e;if((t.si!=null||t.sd!=null)&&(e.si!=null||e.sd!=null)&&(Va(t),a=Po(e),Va(a)),a.t&&Qr[a.t]){if(t.t&&t.t===a.t){var h=Qr[t.t].transform(t.o,a.o,o);if(t.si!=null||t.sd!=null)for(var p=t.p,A=0;A<h.length;A++)t.o=[h[A]],t.p=p.slice(),Wa(t),It.append(n,t);else(!Hh(h)||h.length>0)&&(t.o=h,It.append(n,t));return n}}else if(e.na===void 0){if(e.li!==void 0&&e.ld!==void 0){if(e.p[r]===t.p[r])if(d){if(t.ld!==void 0)if(t.li!==void 0&&o==="left")t.ld=Po(e.li);else return n}else return n}else if(e.li!==void 0)t.li!==void 0&&t.ld===void 0&&d&&t.p[r]===e.p[r]?o==="right"&&t.p[r]++:e.p[r]<=t.p[r]&&t.p[r]++,t.lm!==void 0&&d&&e.p[r]<=t.lm&&t.lm++;else if(e.ld!==void 0){if(t.lm!==void 0&&d){if(e.p[r]===t.p[r])return n;var p=e.p[r],v=t.p[r],B=t.lm;(p<B||p===B&&v<B)&&t.lm--}if(e.p[r]<t.p[r])t.p[r]--;else if(e.p[r]===t.p[r]){if(l<s)return n;if(t.ld!==void 0)if(t.li!==void 0)delete t.ld;else return n}}else if(e.lm!==void 0)if(t.lm!==void 0&&s===l){var v=t.p[r],B=t.lm,D=e.p[r],x=e.lm;if(D!==x)if(v===D)if(o==="left")t.p[r]=x,v===B&&(t.lm=x);else return n;else v>D&&t.p[r]--,v>x?t.p[r]++:v===x&&D>x&&(t.p[r]++,v===B&&t.lm++),(B>D||B===D&&B>v)&&t.lm--,B>x?t.lm++:B===x&&(x>D&&B>v||x<D&&B<v?o==="right"&&t.lm++:B>v?t.lm++:B===D&&t.lm--)}else if(t.li!==void 0&&t.ld===void 0&&d){var v=e.p[r],B=e.lm;p=t.p[r],p>v&&t.p[r]--,p>B&&t.p[r]++}else{var v=e.p[r],B=e.lm;p=t.p[r],p===v?t.p[r]=B:(p>v&&t.p[r]--,(p>B||p===B&&v>B)&&t.p[r]++)}else if(e.oi!==void 0&&e.od!==void 0){if(t.p[r]===e.p[r])if(t.oi!==void 0&&d){if(o==="right")return n;t.od=e.oi}else return n}else if(e.oi!==void 0){if(t.oi!==void 0&&t.p[r]===e.p[r])if(o==="left")It.append(n,{p:t.p,od:e.oi});else return n}else if(e.od!==void 0&&t.p[r]==e.p[r]){if(!d)return n;if(t.oi!==void 0)delete t.od;else return n}}}return It.append(n,t),n},pb(It,It.transformComponent,It.checkValidOp,It.append);var nS=Cb.exports;It.registerSubtype(nS);var oS=It,rS={type:oS};(function(n){n.defaultType=rS.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)})(za);var No={};(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))}})(No);var Ab=Array.isArray,bb=Object.keys,iS=Object.prototype.hasOwnProperty,sS=function n(t,e){if(t===e)return!0;if(t&&e&&typeof t=="object"&&typeof e=="object"){var o=Ab(t),r=Ab(e),i,s,l;if(o&&r){if(s=t.length,s!=e.length)return!1;for(i=s;i--!==0;)if(!n(t[i],e[i]))return!1;return!0}if(o!=r)return!1;var a=t instanceof Date,d=e instanceof Date;if(a!=d)return!1;if(a&&d)return t.getTime()==e.getTime();var h=t instanceof RegExp,p=e instanceof RegExp;if(h!=p)return!1;if(h&&p)return t.toString()==e.toString();var A=bb(t);if(s=A.length,s!==bb(e).length)return!1;for(i=s;i--!==0;)if(!iS.call(e,A[i]))return!1;for(i=s;i--!==0;)if(l=A[i],!n(t[l],e[l]))return!1;return!0}return t!==t&&e!==e},vb=$i,lS=gb,qn=Nh,jh=za,$o=No,cS=$o.clone,aS=sS,Dn=qn.CODES,uS=Ft;function Ft(n,t,e){vb.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}vb.mixin(Ft),Ft.prototype.destroy=function(n){this._wantsDestroy=!0;var t=this;t.whenNothingPending(function(){t.wantSubscribe?t.unsubscribe(function(e){if(e)return n?n(e):t.emit("error",e);t.connection._destroyDoc(t),n&&n()}):(t.connection._destroyDoc(t),n&&n())})},Ft.prototype._setType=function(n){if(typeof n=="string"&&(n=jh.map[n]),n)this.type=n;else if(n===null)this.type=n,this._setData(void 0);else{var t=new qn(Dn.ERR_DOC_TYPE_NOT_RECOGNIZED,"Missing type "+n);return this.emit("error",t)}},Ft.prototype._setData=function(n){this.data=n,this._dataStateVersion++},Ft.prototype.ingestSnapshot=function(n,t){if(!n)return t&&t();if(typeof n.v!="number"){var e=new qn(Dn.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 qn(Dn.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?jh.defaultType:n.type;this._setType(o),this._setData(this.type&&this.type.deserialize?this.type.deserialize(n.data):n.data),this.emit("load"),t&&t()},Ft.prototype.whenNothingPending=function(n){var t=this;$o.nextTick(function(){if(t.hasPending()){t.once("nothing pending",n);return}n()})},Ft.prototype.hasPending=function(){return!!(this.inflightOp||this.pendingOps.length||this.inflightFetch.length||this.inflightSubscribe||this.pendingFetch.length||this.pendingSubscribe.length)},Ft.prototype.hasWritePending=function(){return!!(this.inflightOp||this.pendingOps.length)},Ft.prototype._emitNothingPending=function(){this.hasWritePending()||(this.emit("no write pending"),!this.hasPending()&&this.emit("nothing pending"))},Ft.prototype._emitResponseError=function(n,t){if(n&&n.code===Dn.ERR_SNAPSHOT_READ_SILENT_REJECTION){this.wantSubscribe=!1,t&&t(),this._emitNothingPending();return}if(t){t(n),this._emitNothingPending();return}this._emitNothingPending(),this.emit("error",n)},Ft.prototype._handleFetch=function(n,t){var e=this.pendingFetch;this.pendingFetch=[];var o=this.inflightFetch.shift();if(o&&e.push(o),e.length&&(o=function(r){$o.callEach(e,r)}),n)return this._emitResponseError(n,o);this.ingestSnapshot(t,o),this._emitNothingPending()},Ft.prototype._handleSubscribe=function(n,t){var e=this.inflightSubscribe;this.inflightSubscribe=null;var o=this.pendingFetch;this.pendingFetch=[],e.callback&&o.push(e.callback);var r;if(o.length&&(r=function(i){$o.callEach(o,i)}),n)return this._emitResponseError(n,r);this.subscribed=e.wantSubscribe,this.subscribed?this.ingestSnapshot(t,r):r&&r(),this._emitNothingPending(),this._flushSubscribe()},Ft.prototype._handleOp=function(n,t){if(n)return this.inflightOp?(n.code===Dn.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=Uh(this.inflightOp,t);if(e)return this._hardRollback(e)}for(var o=0;o<this.pendingOps.length;o++){var e=Uh(this.pendingOps[o],t);if(e)return this._hardRollback(e)}this.version++;try{this._otApply(t,!1)}catch(r){return this._hardRollback(r)}}},Ft.prototype._onConnectionStateChanged=function(){this.connection.canSend?(this.flush(),this._resubscribe()):(this.inflightOp&&(this.pendingOps.unshift(this.inflightOp),this.inflightOp=null),this.subscribed=!1,this.inflightSubscribe&&(this.inflightSubscribe.wantSubscribe?(this.pendingSubscribe.unshift(this.inflightSubscribe),this.inflightSubscribe=null):this._handleSubscribe()),this.inflightFetch.length&&(this.pendingFetch=this.pendingFetch.concat(this.inflightFetch),this.inflightFetch.length=0))},Ft.prototype._resubscribe=function(){if(!this.pendingSubscribe.length&&this.wantSubscribe)return this.subscribe();var n=this.pendingSubscribe.some(function(t){return t.wantSubscribe});!n&&this.pendingFetch.length&&this.fetch(),this._flushSubscribe()},Ft.prototype.fetch=function(n){if(this.connection.canSend){var t=this.connection.sendFetch(this);dS(this.inflightFetch,t,n);return}this.pendingFetch.push(n)},Ft.prototype.subscribe=function(n){var t=!0;this._queueSubscribe(t,n)},Ft.prototype.unsubscribe=function(n){var t=!1;this._queueSubscribe(t,n)},Ft.prototype._queueSubscribe=function(n,t){var e=this.pendingSubscribe[this.pendingSubscribe.length-1]||this.inflightSubscribe,o=e&&e.wantSubscribe===n;if(o){e.callback=hS([e.callback,t]);return}this.pendingSubscribe.push({wantSubscribe:!!n,callback:t}),this._flushSubscribe()},Ft.prototype._flushSubscribe=function(){if(!(this.inflightSubscribe||!this.pendingSubscribe.length)){if(this.connection.canSend){this.inflightSubscribe=this.pendingSubscribe.shift(),this.wantSubscribe=this.inflightSubscribe.wantSubscribe,this.wantSubscribe?this.connection.sendSubscribe(this):(this.subscribed=!1,this.connection.sendUnsubscribe(this));return}if(!this.pendingSubscribe[0].wantSubscribe){this.inflightSubscribe=this.pendingSubscribe.shift();var n=this;$o.nextTick(function(){n._handleSubscribe()})}}};function dS(n,t,e){if(t){var o=n.pop();n.push(function(r){o&&o(r),e&&e(r)})}else n.push(e)}function hS(n){return n=n.filter($o.truthy),n.length?function(t){$o.callEach(n,t)}:null}Ft.prototype.flush=function(){!this.connection.canSend||this.inflightOp||!this.paused&&this.pendingOps.length&&this._sendOp()};function fS(n){delete n.op,delete n.create,delete n.del}function Uh(n,t){if(n.del)return fS(t);if(t.del)return new qn(Dn.ERR_DOC_WAS_DELETED,"Document was deleted");if(t.create)return new qn(Dn.ERR_DOC_ALREADY_CREATED,"Document already created");if("op"in t){if(n.create)return new qn(Dn.ERR_DOC_ALREADY_CREATED,"Document already created");if(n.type.transformX){var e=n.type.transformX(n.op,t.op);n.op=e[0],t.op=e[1]}else{var o=n.type.transform(n.op,t.op,"left"),r=n.type.transform(t.op,n.op,"right");n.op=o,t.op=r}}}Ft.prototype._otApply=function(n,t){if("op"in n){if(!this.type)throw new qn(Dn.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===jh.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=Uh(this.applyStack[s],i);if(l)return this._hardRollback(l)}this._setData(this.type.apply(this.data,i.op)),this.emit("op",i.op,t,n.src)}this.emit("op batch",n.op,t),this._popApplyStack(e);return}this.emit("before op",n.op,t,n.src),this._setData(this.type.apply(this.data,n.op)),this.emit("op",n.op,t,n.src),this.emit("op batch",n.op,t);return}if(n.create){this._setType(n.create.type),this.type.deserialize?this.type.createDeserialized?this._setData(this.type.createDeserialized(n.create.data)):this._setData(this.type.deserialize(this.type.create(n.create.data))):this._setData(this.type.create(n.create.data)),this.emit("create",t);return}if(n.del){var a=this.data;this._setType(null),this.emit("del",a,t);return}},Ft.prototype._sendOp=function(){if(!!this.connection.canSend){var n=this.connection.id;this.inflightOp||(this.inflightOp=this.pendingOps.shift());var t=this.inflightOp;if(!t){var e=new qn(Dn.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>=$o.MAX_SAFE_INTEGER)return this.emit("error",new qn(Dn.ERR_CONNECTION_SEQ_INTEGER_OVERFLOW,"Connection seq has exceeded the max safe integer, maybe from being open for too long"));t.seq=this.connection.seq++}this.connection.sendOp(this,t),t.src==null&&(t.src=n)}},Ft.prototype._submit=function(n,t,e){if(t||(t=!0),"op"in n){if(!this.type){var o=new qn(Dn.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;$o.nextTick(function(){r.flush()})},Ft.prototype._pushOp=function(n,t,e){if(n.source=t,this.applyStack)this.applyStack.push(n);else{var o=this._tryCompose(n);if(o){o.callbacks.push(e);return}}n.type=this.type,n.callbacks=[e],this.pendingOps.push(n)},Ft.prototype._popApplyStack=function(n){if(n>0){this.applyStack.length=n;return}var t=this.applyStack[0];if(this.applyStack=null,!!t){var e=this.pendingOps.indexOf(t);if(e!==-1)for(var o=this.pendingOps.splice(e),e=0;e<o.length;e++){var t=o[e],r=this._tryCompose(t);r?r.callbacks=r.callbacks.concat(t.callbacks):this.pendingOps.push(t)}}},Ft.prototype._tryCompose=function(n){if(!this.preventCompose){var t=this.pendingOps[this.pendingOps.length-1];if(!(!t||t.sentAt)&&!(this.submitSource&&!aS(n.source,t.source))){if(t.create&&"op"in n)return t.create.data=this.type.apply(t.create.data,n.op),t;if("op"in t&&"op"in n&&this.type.compose)return t.op=this.type.compose(t.op,n.op),t}}},Ft.prototype.submitOp=function(n,t,e){typeof t=="function"&&(e=t,t=null);var o={op:n},r=t&&t.source;this._submit(o,r,e)},Ft.prototype.create=function(n,t,e,o){if(typeof t=="function"?(o=t,e=null,t=null):typeof e=="function"&&(o=e,e=null),t||(t=jh.defaultType.uri),this.type){var r=new qn(Dn.ERR_DOC_ALREADY_CREATED,"Document already exists");return o?o(r):this.emit("error",r)}var i={create:{type:t,data:n}},s=e&&e.source;this._submit(i,s,o)},Ft.prototype.del=function(n,t){if(typeof n=="function"&&(t=n,n=null),!this.type){var e=new qn(Dn.ERR_DOC_DOES_NOT_EXIST,"Document does not exist");return t?t(e):this.emit("error",e)}var o={del:!0},r=n&&n.source;this._submit(o,r,t)},Ft.prototype.pause=function(){this.paused=!0},Ft.prototype.resume=function(){this.paused=!1,this.flush()},Ft.prototype.toSnapshot=function(){return{v:this.version,data:cS(this.data),type:this.type.uri}},Ft.prototype._opAcknowledged=function(n){if(this.inflightOp.create)this.version=n.v;else if(n.v!==this.version)return lS.warn("Invalid version from server. Expected: "+this.version+" Received: "+n.v,n),this.fetch();this.version++,this._clearInflightOp()},Ft.prototype._rollback=function(n){var t=this.inflightOp;if("op"in t&&t.type.invert){try{t.op=t.type.invert(t.op)}catch{return this._hardRollback(n)}for(var e=0;e<this.pendingOps.length;e++){var o=Uh(this.pendingOps[e],t);if(o)return this._hardRollback(o)}try{this._otApply(t,!1)}catch(r){return this._hardRollback(r)}this._clearInflightOp(n);return}this._hardRollback(n)},Ft.prototype._hardRollback=function(n){var t=[];this.inflightOp&&t.push(this.inflightOp),t=t.concat(this.pendingOps),this._setType(null),this.version=null,this.inflightOp=null,this.pendingOps=[];var e=this;this.fetch(function(){for(var o=!!t.length,r=0;r<t.length;r++)o=$o.callEach(t[r].callbacks,n)&&o;if(n&&!o)return e.emit("error",n)})},Ft.prototype._clearInflightOp=function(n){var t=this.inflightOp;this.inflightOp=null;var e=$o.callEach(t.callbacks,n);if(this.flush(),this._emitNothingPending(),n&&!e)return this.emit("error",n)};var Us={};Us.ACTIONS={initLegacy:"init",handshake:"hs",queryFetch:"qf",querySubscribe:"qs",queryUnsubscribe:"qu",queryUpdate:"q",bulkFetch:"bf",bulkSubscribe:"bs",bulkUnsubscribe:"bu",fetch:"f",subscribe:"s",unsubscribe:"u",op:"op",snapshotFetch:"nf",snapshotFetchByTimestamp:"nt",pingPong:"pp",presence:"p",presenceSubscribe:"ps",presenceUnsubscribe:"pu",presenceRequest:"pr"};var yb=$i,kb=Us.ACTIONS,mS=No,gS=Sn;function Sn(n,t,e,o,r,i,s){yb.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}yb.mixin(Sn),Sn.prototype.hasPending=function(){return!this.ready},Sn.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}},Sn.prototype.destroy=function(n){this.connection.canSend&&this.action===kb.querySubscribe&&this.connection.send({a:kb.queryUnsubscribe,id:this.id}),this.connection._destroyQuery(this),n&&mS.nextTick(n)},Sn.prototype._onConnectionStateChanged=function(){this.connection.canSend&&!this.sent?this.send():this.sent=!1},Sn.prototype._handleFetch=function(n,t,e){this.connection._destroyQuery(this),this._handleResponse(n,t,e)},Sn.prototype._handleSubscribe=function(n,t,e){this._handleResponse(n,t,e)},Sn.prototype._handleResponse=function(n,t,e){var o=this.callback;if(this.callback=null,n)return this._finishResponse(n,o);if(!t)return this._finishResponse(null,o);var r=this,i=1,s=function(h){if(h)return r._finishResponse(h,o);--i||r._finishResponse(null,o)};if(Array.isArray(t))i+=t.length,this.results=this._ingestSnapshots(t,s),this.extra=e;else for(var l in t){i++;var a=t[l],d=this.connection.get(a.c||this.collection,l);d.ingestSnapshot(a,s)}s()},Sn.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},Sn.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)},Sn.prototype._handleError=function(n){this.emit("error",n)},Sn.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)},Sn.prototype._handleExtra=function(n){this.extra=n,this.emit("extra",n)};var wb=$i,pS=Us.ACTIONS,CS=No,Bb=dr;function dr(n,t){if(wb.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={}}wb.mixin(dr),dr.prototype.submit=function(n,t){this.value=n,this.send(t)},dr.prototype.send=function(n){var t=this._message();this._pendingMessages.push(t),this._callbacksByPresenceVersion[t.pv]=n,this._sendPending()},dr.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()})},dr.prototype._sendPending=function(){if(!!this.connection.canSend){var n=this;this._pendingMessages.forEach(function(t){n.connection.send(t)}),this._pendingMessages=[]}},dr.prototype._ack=function(n,t){var e=this._getCallback(t);this._callbackOrEmit(n,e)},dr.prototype._message=function(){return{a:pS.presence,ch:this.presence.channel,id:this.presenceId,p:this.value,pv:this.presenceVersion++}},dr.prototype._getCallback=function(n){var t=this._callbacksByPresenceVersion[n];return delete this._callbacksByPresenceVersion[n],t},dr.prototype._callbackOrEmit=function(n,t){if(t)return CS.nextTick(t,n);n&&this.emit("error",n)};var AS=No,Eb=ip;function ip(n,t){this.presence=n,this.presenceId=t,this.connection=this.presence.connection,this.value=null,this.presenceVersion=0}ip.prototype.receiveUpdate=function(n){n.pv<this.presenceVersion||(this.value=n.p,this.presenceVersion=n.pv,this.presence._updateRemotePresence(this))},ip.prototype.destroy=function(n){delete this.presence._remotePresenceInstances[this.presenceId],delete this.presence.remotePresences[this.presenceId],n&&AS.nextTick(n)};var sp={exports:{}};(function(n,t){(function(e,o){o(t)})(ur,function(e){function o(k,T){T=T|0;for(var L=Math.max(k.length-T,0),F=Array(L),U=0;U<L;U++)F[U]=k[T+U];return F}var r=function(k){var T=o(arguments,1);return function(){var L=o(arguments);return k.apply(null,T.concat(L))}},i=function(k){return function(){var T=o(arguments),L=T.pop();k.call(this,T,L)}};function s(k){var T=typeof k;return k!=null&&(T=="object"||T=="function")}var l=typeof setImmediate=="function"&&setImmediate,a=typeof process=="object"&&typeof process.nextTick=="function";function d(k){setTimeout(k,0)}function h(k){return function(T){var L=o(arguments,1);k(function(){T.apply(null,L)})}}var p;l?p=setImmediate:a?p=process.nextTick:p=d;var A=h(p);function v(k){return i(function(T,L){var F;try{F=k.apply(this,T)}catch(U){return L(U)}s(F)&&typeof F.then=="function"?F.then(function(U){B(L,null,U)},function(U){B(L,U.message?U:new Error(U))}):L(null,F)})}function B(k,T,L){try{k(T,L)}catch(F){A(D,F)}}function D(k){throw k}var x=typeof Symbol=="function";function _(k){return x&&k[Symbol.toStringTag]==="AsyncFunction"}function M(k){return _(k)?v(k):k}function H(k){return function(T){var L=o(arguments,1),F=i(function(U,j){var Z=this;return k(T,function(J,lt){M(J).apply(Z,U.concat(lt))},j)});return L.length?F.apply(this,L):F}}var z=typeof ur=="object"&&ur&&ur.Object===Object&&ur,q=typeof self=="object"&&self&&self.Object===Object&&self,rt=z||q||Function("return this")(),ft=rt.Symbol,Bt=Object.prototype,jt=Bt.hasOwnProperty,Ut=Bt.toString,ne=ft?ft.toStringTag:void 0;function qe(k){var T=jt.call(k,ne),L=k[ne];try{k[ne]=void 0;var F=!0}catch{}var U=Ut.call(k);return F&&(T?k[ne]=L:delete k[ne]),U}var Yn=Object.prototype,$e=Yn.toString;function Rn(k){return $e.call(k)}var wr="[object Null]",vn="[object Undefined]",an=ft?ft.toStringTag:void 0;function Br(k){return k==null?k===void 0?vn:wr:an&&an in Object(k)?qe(k):Rn(k)}var oi="[object AsyncFunction]",po="[object Function]",X2="[object GeneratorFunction]",t3="[object Proxy]";function e3(k){if(!s(k))return!1;var T=Br(k);return T==po||T==X2||T==oi||T==t3}var ns=9007199254740991;function nl(k){return typeof k=="number"&&k>-1&&k%1==0&&k<=ns}function ol(k){return k!=null&&nl(k.length)&&!e3(k)}var ri={};function Nt(){}function Er(k){return function(){if(k!==null){var T=k;k=null,T.apply(this,arguments)}}}var os=typeof Symbol=="function"&&Symbol.iterator,Fc=function(k){return os&&k[os]&&k[os]()};function s1(k,T){for(var L=-1,F=Array(k);++L<k;)F[L]=T(L);return F}function un(k){return k!=null&&typeof k=="object"}var rl="[object Arguments]";function l1(k){return un(k)&&Br(k)==rl}var Co=Object.prototype,c1=Co.hasOwnProperty,n3=Co.propertyIsEnumerable,il=l1(function(){return arguments}())?l1:function(k){return un(k)&&c1.call(k,"callee")&&!n3.call(k,"callee")},be=Array.isArray;function sl(){return!1}var ll=typeof e=="object"&&e&&!e.nodeType&&e,a1=ll&&!0&&n&&!n.nodeType&&n,cl=a1&&a1.exports===ll,u1=cl?rt.Buffer:void 0,al=u1?u1.isBuffer:void 0,rs=al||sl,ju=9007199254740991,Uu=/^(?:0|[1-9]\d*)$/;function zu(k,T){var L=typeof k;return T=T==null?ju:T,!!T&&(L=="number"||L!="symbol"&&Uu.test(k))&&k>-1&&k%1==0&&k<T}var Vu="[object Arguments]",Wu="[object Array]",qu="[object Boolean]",Gu="[object Date]",Zu="[object Error]",Qu="[object Function]",o3="[object Map]",r3="[object Number]",i3="[object Object]",d1="[object RegExp]",h1="[object Set]",s3="[object String]",l3="[object WeakMap]",c3="[object ArrayBuffer]",a3="[object DataView]",f1="[object Float32Array]",u3="[object Float64Array]",d3="[object Int8Array]",h3="[object Int16Array]",Yu="[object Int32Array]",f3="[object Uint8Array]",Ju="[object Uint8ClampedArray]",m3="[object Uint16Array]",g3="[object Uint32Array]",se={};se[f1]=se[u3]=se[d3]=se[h3]=se[Yu]=se[f3]=se[Ju]=se[m3]=se[g3]=!0,se[Vu]=se[Wu]=se[c3]=se[qu]=se[a3]=se[Gu]=se[Zu]=se[Qu]=se[o3]=se[r3]=se[i3]=se[d1]=se[h1]=se[s3]=se[l3]=!1;function p3(k){return un(k)&&nl(k.length)&&!!se[Br(k)]}function C3(k){return function(T){return k(T)}}var m1=typeof e=="object"&&e&&!e.nodeType&&e,ul=m1&&!0&&n&&!n.nodeType&&n,A3=ul&&ul.exports===m1,Pc=A3&&z.process,g1=function(){try{var k=ul&&ul.require&&ul.require("util").types;return k||Pc&&Pc.binding&&Pc.binding("util")}catch{}}(),p1=g1&&g1.isTypedArray,b3=p1?C3(p1):p3,v3=Object.prototype,y3=v3.hasOwnProperty;function k3(k,T){var L=be(k),F=!L&&il(k),U=!L&&!F&&rs(k),j=!L&&!F&&!U&&b3(k),Z=L||F||U||j,J=Z?s1(k.length,String):[],lt=J.length;for(var pt in k)(T||y3.call(k,pt))&&!(Z&&(pt=="length"||U&&(pt=="offset"||pt=="parent")||j&&(pt=="buffer"||pt=="byteLength"||pt=="byteOffset")||zu(pt,lt)))&&J.push(pt);return J}var Nc=Object.prototype;function w3(k){var T=k&&k.constructor,L=typeof T=="function"&&T.prototype||Nc;return k===L}function $c(k,T){return function(L){return k(T(L))}}var B3=$c(Object.keys,Object),E3=Object.prototype,x3=E3.hasOwnProperty;function C1(k){if(!w3(k))return B3(k);var T=[];for(var L in Object(k))x3.call(k,L)&&L!="constructor"&&T.push(L);return T}function Hc(k){return ol(k)?k3(k):C1(k)}function A1(k){var T=-1,L=k.length;return function(){return++T<L?{value:k[T],key:T}:null}}function I3(k){var T=-1;return function(){var F=k.next();return F.done?null:(T++,{value:F.value,key:T})}}function T3(k){var T=Hc(k),L=-1,F=T.length;return function U(){var j=T[++L];return j==="__proto__"?U():L<F?{value:k[j],key:j}:null}}function D3(k){if(ol(k))return A1(k);var T=Fc(k);return T?I3(T):T3(k)}function Ao(k){return function(){if(k===null)throw new Error("Callback was already called.");var T=k;k=null,T.apply(this,arguments)}}function dl(k){return function(T,L,F){if(F=Er(F||Nt),k<=0||!T)return F(null);var U=D3(T),j=!1,Z=0,J=!1;function lt(ct,At){if(Z-=1,ct)j=!0,F(ct);else{if(At===ri||j&&Z<=0)return j=!0,F(null);J||pt()}}function pt(){for(J=!0;Z<k&&!j;){var ct=U();if(ct===null){j=!0,Z<=0&&F(null);return}Z+=1,L(ct.value,ct.key,Ao(lt))}J=!1}pt()}}function xr(k,T,L,F){dl(T)(k,M(L),F)}function He(k,T){return function(L,F,U){return k(L,T,F,U)}}function Ku(k,T,L){L=Er(L||Nt);var F=0,U=0,j=k.length;j===0&&L(null);function Z(J,lt){J?L(J):(++U===j||lt===ri)&&L(null)}for(;F<j;F++)T(k[F],F,Ao(Z))}var S3=He(xr,1/0),Go=function(k,T,L){var F=ol(k)?Ku:S3;F(k,M(T),L)};function Zo(k){return function(T,L,F){return k(Go,T,M(L),F)}}function Xu(k,T,L,F){F=F||Nt,T=T||[];var U=[],j=0,Z=M(L);k(T,function(J,lt,pt){var ct=j++;Z(J,function(At,Gt){U[ct]=Gt,pt(At)})},function(J){F(J,U)})}var jc=Zo(Xu),td=H(jc);function ii(k){return function(T,L,F,U){return k(dl(L),T,M(F),U)}}var Ir=ii(Xu),ed=He(Ir,1),nd=H(ed);function is(k,T){for(var L=-1,F=k==null?0:k.length;++L<F&&T(k[L],L,k)!==!1;);return k}function od(k){return function(T,L,F){for(var U=-1,j=Object(T),Z=F(T),J=Z.length;J--;){var lt=Z[k?J:++U];if(L(j[lt],lt,j)===!1)break}return T}}var ss=od();function ls(k,T){return k&&ss(k,T,Hc)}function b1(k,T,L,F){for(var U=k.length,j=L+(F?1:-1);F?j--:++j<U;)if(T(k[j],j,k))return j;return-1}function L3(k){return k!==k}function v1(k,T,L){for(var F=L-1,U=k.length;++F<U;)if(k[F]===T)return F;return-1}function hl(k,T,L){return T===T?v1(k,T,L):b1(k,L3,L)}var Uc=function(k,T,L){typeof T=="function"&&(L=T,T=null),L=Er(L||Nt);var F=Hc(k),U=F.length;if(!U)return L(null);T||(T=U);var j={},Z=0,J=!1,lt=Object.create(null),pt=[],ct=[],At={};ls(k,function(de,re){if(!be(de)){Gt(re,[de]),ct.push(re);return}var ge=de.slice(0,de.length-1),vo=ge.length;if(vo===0){Gt(re,de),ct.push(re);return}At[re]=vo,is(ge,function(E){if(!k[E])throw new Error("async.auto task `"+re+"` has a non-existent dependency `"+E+"` in "+ge.join(", "));en(E,function(){vo--,vo===0&&Gt(re,de)})})}),X3(),Te();function Gt(de,re){pt.push(function(){bo(de,re)})}function Te(){if(pt.length===0&&Z===0)return L(null,j);for(;pt.length&&Z<T;){var de=pt.shift();de()}}function en(de,re){var ge=lt[de];ge||(ge=lt[de]=[]),ge.push(re)}function Fn(de){var re=lt[de]||[];is(re,function(ge){ge()}),Te()}function bo(de,re){if(!J){var ge=Ao(function(E,Sr){if(Z--,arguments.length>2&&(Sr=o(arguments,1)),E){var ds={};ls(j,function(Pn,Pt){ds[Pt]=Pn}),ds[de]=Sr,J=!0,lt=Object.create(null),L(E,ds)}else j[de]=Sr,Fn(de)});Z++;var vo=M(re[re.length-1]);re.length>1?vo(j,ge):vo(ge)}}function X3(){for(var de,re=0;ct.length;)de=ct.pop(),re++,is(t5(de),function(ge){--At[ge]===0&&ct.push(ge)});if(re!==U)throw new Error("async.auto cannot execute tasks due to a recursive dependency")}function t5(de){var re=[];return ls(k,function(ge,vo){be(ge)&&hl(ge,de,0)>=0&&re.push(vo)}),re}};function si(k,T){for(var L=-1,F=k==null?0:k.length,U=Array(F);++L<F;)U[L]=T(k[L],L,k);return U}var M3="[object Symbol]";function R3(k){return typeof k=="symbol"||un(k)&&Br(k)==M3}var O3=1/0,rd=ft?ft.prototype:void 0,y1=rd?rd.toString:void 0;function id(k){if(typeof k=="string")return k;if(be(k))return si(k,id)+"";if(R3(k))return y1?y1.call(k):"";var T=k+"";return T=="0"&&1/k==-O3?"-0":T}function _3(k,T,L){var F=-1,U=k.length;T<0&&(T=-T>U?0:U+T),L=L>U?U:L,L<0&&(L+=U),U=T>L?0:L-T>>>0,T>>>=0;for(var j=Array(U);++F<U;)j[F]=k[F+T];return j}function F3(k,T,L){var F=k.length;return L=L===void 0?F:L,!T&&L>=F?k:_3(k,T,L)}function sd(k,T){for(var L=k.length;L--&&hl(T,k[L],0)>-1;);return L}function P3(k,T){for(var L=-1,F=k.length;++L<F&&hl(T,k[L],0)>-1;);return L}function N3(k){return k.split("")}var $3="\\ud800-\\udfff",H3="\\u0300-\\u036f",j3="\\ufe20-\\ufe2f",le="\\u20d0-\\u20ff",oe=H3+j3+le,U3="\\ufe0e\\ufe0f",z3="\\u200d",V3=RegExp("["+z3+$3+oe+U3+"]");function W3(k){return V3.test(k)}var k1="\\ud800-\\udfff",q3="\\u0300-\\u036f",w1="\\ufe20-\\ufe2f",G3="\\u20d0-\\u20ff",Ge=q3+w1+G3,ld="\\ufe0e\\ufe0f",li="["+k1+"]",zc="["+Ge+"]",fl="\\ud83c[\\udffb-\\udfff]",On="(?:"+zc+"|"+fl+")",cd="[^"+k1+"]",ad="(?:\\ud83c[\\udde6-\\uddff]){2}",ud="[\\ud800-\\udbff][\\udc00-\\udfff]",B1="\\u200d",dd=On+"?",hd="["+ld+"]?",yn="(?:"+B1+"(?:"+[cd,ad,ud].join("|")+")"+hd+dd+")*",Z3=hd+dd+yn,_n="(?:"+[cd+zc+"?",zc,ad,ud,li].join("|")+")",Q3=RegExp(fl+"(?="+fl+")|"+_n+Z3,"g");function E1(k){return k.match(Q3)||[]}function Qo(k){return W3(k)?E1(k):N3(k)}function Vc(k){return k==null?"":id(k)}var fd=/^\s+|\s+$/g;function ue(k,T,L){if(k=Vc(k),k&&(L||T===void 0))return k.replace(fd,"");if(!k||!(T=id(T)))return k;var F=Qo(k),U=Qo(T),j=P3(F,U),Z=sd(F,U)+1;return F3(F,j,Z).join("")}var Tr=/^(?:async\s+)?(function)?\s*[^\(]*\(\s*([^\)]*)\)/m,md=/,/,Y3=/(=.+)?(\s*)$/,gd=/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;function J3(k){return k=k.toString().replace(gd,""),k=k.match(Tr)[2].replace(" ",""),k=k?k.split(md):[],k=k.map(function(T){return ue(T.replace(Y3,""))}),k}function x1(k,T){var L={};ls(k,function(F,U){var j,Z=_(F),J=!Z&&F.length===1||Z&&F.length===0;if(be(F))j=F.slice(0,-1),F=F[F.length-1],L[U]=j.concat(j.length>0?lt:F);else if(J)L[U]=F;else{if(j=J3(F),F.length===0&&!Z&&j.length===0)throw new Error("autoInject task functions require explicit parameters.");Z||j.pop(),L[U]=j.concat(lt)}function lt(pt,ct){var At=si(j,function(Gt){return pt[Gt]});At.push(ct),M(F).apply(null,At)}}),Uc(L,T)}function Jn(){this.head=this.tail=null,this.length=0}function pd(k,T){k.length=1,k.head=k.tail=T}Jn.prototype.removeLink=function(k){return k.prev?k.prev.next=k.next:this.head=k.next,k.next?k.next.prev=k.prev:this.tail=k.prev,k.prev=k.next=null,this.length-=1,k},Jn.prototype.empty=function(){for(;this.head;)this.shift();return this},Jn.prototype.insertAfter=function(k,T){T.prev=k,T.next=k.next,k.next?k.next.prev=T:this.tail=T,k.next=T,this.length+=1},Jn.prototype.insertBefore=function(k,T){T.prev=k.prev,T.next=k,k.prev?k.prev.next=T:this.head=T,k.prev=T,this.length+=1},Jn.prototype.unshift=function(k){this.head?this.insertBefore(this.head,k):pd(this,k)},Jn.prototype.push=function(k){this.tail?this.insertAfter(this.tail,k):pd(this,k)},Jn.prototype.shift=function(){return this.head&&this.removeLink(this.head)},Jn.prototype.pop=function(){return this.tail&&this.removeLink(this.tail)},Jn.prototype.toArray=function(){for(var k=Array(this.length),T=this.head,L=0;L<this.length;L++)k[L]=T.data,T=T.next;return k},Jn.prototype.remove=function(k){for(var T=this.head;T;){var L=T.next;k(T)&&this.removeLink(T),T=L}return this};function ml(k,T,L){if(T==null)T=1;else if(T===0)throw new Error("Concurrency must not be zero");var F=M(k),U=0,j=[],Z=!1;function J(At,Gt,Te){if(Te!=null&&typeof Te!="function")throw new Error("task callback must be a function");if(ct.started=!0,be(At)||(At=[At]),At.length===0&&ct.idle())return A(function(){ct.drain()});for(var en=0,Fn=At.length;en<Fn;en++){var bo={data:At[en],callback:Te||Nt};Gt?ct._tasks.unshift(bo):ct._tasks.push(bo)}Z||(Z=!0,A(function(){Z=!1,ct.process()}))}function lt(At){return function(Gt){U-=1;for(var Te=0,en=At.length;Te<en;Te++){var Fn=At[Te],bo=hl(j,Fn,0);bo===0?j.shift():bo>0&&j.splice(bo,1),Fn.callback.apply(Fn,arguments),Gt!=null&&ct.error(Gt,Fn.data)}U<=ct.concurrency-ct.buffer&&ct.unsaturated(),ct.idle()&&ct.drain(),ct.process()}}var pt=!1,ct={_tasks:new Jn,concurrency:T,payload:L,saturated:Nt,unsaturated:Nt,buffer:T/4,empty:Nt,drain:Nt,error:Nt,started:!1,paused:!1,push:function(At,Gt){J(At,!1,Gt)},kill:function(){ct.drain=Nt,ct._tasks.empty()},unshift:function(At,Gt){J(At,!0,Gt)},remove:function(At){ct._tasks.remove(At)},process:function(){if(!pt){for(pt=!0;!ct.paused&&U<ct.concurrency&&ct._tasks.length;){var At=[],Gt=[],Te=ct._tasks.length;ct.payload&&(Te=Math.min(Te,ct.payload));for(var en=0;en<Te;en++){var Fn=ct._tasks.shift();At.push(Fn),j.push(Fn),Gt.push(Fn.data)}U+=1,ct._tasks.length===0&&ct.empty(),U===ct.concurrency&&ct.saturated();var bo=Ao(lt(At));F(Gt,bo)}pt=!1}},length:function(){return ct._tasks.length},running:function(){return U},workersList:function(){return j},idle:function(){return ct._tasks.length+U===0},pause:function(){ct.paused=!0},resume:function(){ct.paused!==!1&&(ct.paused=!1,A(ct.process))}};return ct}function ci(k,T){return ml(k,1,T)}var cs=He(xr,1);function Yo(k,T,L,F){F=Er(F||Nt);var U=M(L);cs(k,function(j,Z,J){U(T,j,function(lt,pt){T=pt,J(lt)})},function(j){F(j,T)})}function Wc(){var k=si(arguments,M);return function(){var T=o(arguments),L=this,F=T[T.length-1];typeof F=="function"?T.pop():F=Nt,Yo(k,T,function(U,j,Z){j.apply(L,U.concat(function(J){var lt=o(arguments,1);Z(J,lt)}))},function(U,j){F.apply(L,[U].concat(j))})}}var qc=function(){return Wc.apply(null,o(arguments).reverse())},Cd=Array.prototype.concat,gl=function(k,T,L,F){F=F||Nt;var U=M(L);Ir(k,T,function(j,Z){U(j,function(J){return J?Z(J):Z(null,o(arguments,1))})},function(j,Z){for(var J=[],lt=0;lt<Z.length;lt++)Z[lt]&&(J=Cd.apply(J,Z[lt]));return F(j,J)})},I1=He(gl,1/0),Gc=He(gl,1),Zc=function(){var k=o(arguments),T=[null].concat(k);return function(){var L=arguments[arguments.length-1];return L.apply(this,T)}};function pl(k){return k}function ai(k,T){return function(L,F,U,j){j=j||Nt;var Z=!1,J;L(F,function(lt,pt,ct){U(lt,function(At,Gt){At?ct(At):k(Gt)&&!J?(Z=!0,J=T(!0,lt),ct(null,ri)):ct()})},function(lt){lt?j(lt):j(null,Z?J:T(!1))})}}function dn(k,T){return T}var as=Zo(ai(pl,dn)),Jo=ii(ai(pl,dn)),Cl=He(Jo,1);function Ad(k){return function(T){var L=o(arguments,1);L.push(function(F){var U=o(arguments,1);typeof console=="object"&&(F?console.error&&console.error(F):console[k]&&is(U,function(j){console[k](j)}))}),M(T).apply(null,L)}}var T1=Ad("dir");function D1(k,T,L){L=Ao(L||Nt);var F=M(k),U=M(T);function j(J){if(J)return L(J);var lt=o(arguments,1);lt.push(Z),U.apply(this,lt)}function Z(J,lt){if(J)return L(J);if(!lt)return L(null);F(j)}Z(null,!0)}function bd(k,T,L){L=Ao(L||Nt);var F=M(k),U=function(j){if(j)return L(j);var Z=o(arguments,1);if(T.apply(this,Z))return F(U);L.apply(null,[null].concat(Z))};F(U)}function S1(k,T,L){bd(k,function(){return!T.apply(this,arguments)},L)}function L1(k,T,L){L=Ao(L||Nt);var F=M(T),U=M(k);function j(J){if(J)return L(J);U(Z)}function Z(J,lt){if(J)return L(J);if(!lt)return L(null);F(j)}U(Z)}function ui(k){return function(T,L,F){return k(T,F)}}function Qc(k,T,L){Go(k,ui(M(T)),L)}function Al(k,T,L,F){dl(T)(k,ui(M(L)),F)}var di=He(Al,1);function Yc(k){return _(k)?k:i(function(T,L){var F=!0;T.push(function(){var U=arguments;F?A(function(){L.apply(null,U)}):L.apply(null,U)}),k.apply(this,T),F=!1})}function Kn(k){return!k}var hi=Zo(ai(Kn,Kn)),bl=ii(ai(Kn,Kn)),Jc=He(bl,1);function M1(k){return function(T){return T==null?void 0:T[k]}}function us(k,T,L,F){var U=new Array(T.length);k(T,function(j,Z,J){L(j,function(lt,pt){U[Z]=!!pt,J(lt)})},function(j){if(j)return F(j);for(var Z=[],J=0;J<T.length;J++)U[J]&&Z.push(T[J]);F(null,Z)})}function Xn(k,T,L,F){var U=[];k(T,function(j,Z,J){L(j,function(lt,pt){lt?J(lt):(pt&&U.push({index:Z,value:j}),J())})},function(j){j?F(j):F(null,si(U.sort(function(Z,J){return Z.index-J.index}),M1("value")))})}function Kc(k,T,L,F){var U=ol(T)?us:Xn;U(k,T,M(L),F||Nt)}var Xc=Zo(Kc),vl=ii(Kc),ta=He(vl,1);function R1(k,T){var L=Ao(T||Nt),F=M(Yc(k));function U(j){if(j)return L(j);F(U)}U()}var ea=function(k,T,L,F){F=F||Nt;var U=M(L);Ir(k,T,function(j,Z){U(j,function(J,lt){return J?Z(J):Z(null,{key:lt,val:j})})},function(j,Z){for(var J={},lt=Object.prototype.hasOwnProperty,pt=0;pt<Z.length;pt++)if(Z[pt]){var ct=Z[pt].key,At=Z[pt].val;lt.call(J,ct)?J[ct].push(At):J[ct]=[At]}return F(j,J)})},fi=He(ea,1/0),N=He(ea,1),G=Ad("log");function V(k,T,L,F){F=Er(F||Nt);var U={},j=M(L);xr(k,T,function(Z,J,lt){j(Z,J,function(pt,ct){if(pt)return lt(pt);U[J]=ct,lt()})},function(Z){F(Z,U)})}var ht=He(V,1/0),Et=He(V,1);function Vt(k,T){return T in k}function we(k,T){var L=Object.create(null),F=Object.create(null);T=T||pl;var U=M(k),j=i(function(J,lt){var pt=T.apply(null,J);Vt(L,pt)?A(function(){lt.apply(null,L[pt])}):Vt(F,pt)?F[pt].push(lt):(F[pt]=[lt],U.apply(null,J.concat(function(){var ct=o(arguments);L[pt]=ct;var At=F[pt];delete F[pt];for(var Gt=0,Te=At.length;Gt<Te;Gt++)At[Gt].apply(null,ct)})))});return j.memo=L,j.unmemoized=k,j}var qt;a?qt=process.nextTick:l?qt=setImmediate:qt=d;var na=h(qt);function vd(k,T,L){L=L||Nt;var F=ol(T)?[]:{};k(T,function(U,j,Z){M(U)(function(J,lt){arguments.length>2&&(lt=o(arguments,1)),F[j]=lt,Z(J)})},function(U){L(U,F)})}function kn(k,T){vd(Go,k,T)}function yl(k,T,L){vd(dl(T),k,L)}var yd=function(k,T){var L=M(k);return ml(function(F,U){L(F[0],U)},T,1)},mi=function(k,T){var L=yd(k,T);return L.push=function(F,U,j){if(j==null&&(j=Nt),typeof j!="function")throw new Error("task callback must be a function");if(L.started=!0,be(F)||(F=[F]),F.length===0)return A(function(){L.drain()});U=U||0;for(var Z=L._tasks.head;Z&&U>=Z.priority;)Z=Z.next;for(var J=0,lt=F.length;J<lt;J++){var pt={data:F[J],priority:U,callback:j};Z?L._tasks.insertBefore(Z,pt):L._tasks.push(pt)}A(L.process)},delete L.unshift,L};function kl(k,T){if(T=Er(T||Nt),!be(k))return T(new TypeError("First argument to race must be an array of functions"));if(!k.length)return T();for(var L=0,F=k.length;L<F;L++)M(k[L])(T)}function gi(k,T,L,F){var U=o(k).reverse();Yo(U,T,L,F)}function Wt(k){var T=M(k);return i(function(F,U){return F.push(function(Z,J){if(Z)U(null,{error:Z});else{var lt;arguments.length<=2?lt=J:lt=o(arguments,1),U(null,{value:lt})}}),T.apply(this,F)})}function O1(k){var T;return be(k)?T=si(k,Wt):(T={},ls(k,function(L,F){T[F]=Wt.call(this,L)})),T}function kd(k,T,L,F){Kc(k,T,function(U,j){L(U,function(Z,J){j(Z,!J)})},F)}var wl=Zo(kd),wd=ii(kd),_1=He(wd,1);function F1(k){return function(){return k}}function pi(k,T,L){var F=5,U=0,j={times:F,intervalFunc:F1(U)};function Z(ct,At){if(typeof At=="object")ct.times=+At.times||F,ct.intervalFunc=typeof At.interval=="function"?At.interval:F1(+At.interval||U),ct.errorFilter=At.errorFilter;else if(typeof At=="number"||typeof At=="string")ct.times=+At||F;else throw new Error("Invalid arguments for async.retry")}if(arguments.length<3&&typeof k=="function"?(L=T||Nt,T=k):(Z(j,k),L=L||Nt),typeof T!="function")throw new Error("Invalid arguments for async.retry");var J=M(T),lt=1;function pt(){J(function(ct){ct&<++<j.times&&(typeof j.errorFilter!="function"||j.errorFilter(ct))?setTimeout(pt,j.intervalFunc(lt)):L.apply(null,arguments)})}pt()}var Ko=function(k,T){T||(T=k,k=null);var L=M(T);return i(function(F,U){function j(Z){L.apply(null,F.concat(Z))}k?pi(k,j,U):pi(j,U)})};function Bl(k,T){vd(cs,k,T)}var El=Zo(ai(Boolean,pl)),Dr=ii(ai(Boolean,pl)),xl=He(Dr,1);function Bd(k,T,L){var F=M(T);jc(k,function(j,Z){F(j,function(J,lt){if(J)return Z(J);Z(null,{value:j,criteria:lt})})},function(j,Z){if(j)return L(j);L(null,si(Z.sort(U),M1("value")))});function U(j,Z){var J=j.criteria,lt=Z.criteria;return J<lt?-1:J>lt?1:0}}function Il(k,T,L){var F=M(k);return i(function(U,j){var Z=!1,J;function lt(){var pt=k.name||"anonymous",ct=new Error('Callback function "'+pt+'" timed out.');ct.code="ETIMEDOUT",L&&(ct.info=L),Z=!0,j(ct)}U.push(function(){Z||(j.apply(null,arguments),clearTimeout(J))}),J=setTimeout(lt,T),F.apply(null,U)})}var P1=Math.ceil,Tl=Math.max;function Ci(k,T,L,F){for(var U=-1,j=Tl(P1((T-k)/(L||1)),0),Z=Array(j);j--;)Z[F?j:++U]=k,k+=L;return Z}function Ai(k,T,L,F){var U=M(L);Ir(Ci(0,k,1),T,U,F)}var N1=He(Ai,1/0),$1=He(Ai,1);function H1(k,T,L,F){arguments.length<=3&&(F=L,L=T,T=be(k)?[]:{}),F=Er(F||Nt);var U=M(L);Go(k,function(j,Z,J){U(T,j,Z,J)},function(j){F(j,T)})}function Dl(k,T){var L=null,F;T=T||Nt,di(k,function(U,j){M(U)(function(Z,J){arguments.length>2?F=o(arguments,1):F=J,L=Z,j(!Z)})},function(){T(L,F)})}function Sl(k){return function(){return(k.unmemoized||k).apply(null,arguments)}}function Ll(k,T,L){L=Ao(L||Nt);var F=M(T);if(!k())return L(null);var U=function(j){if(j)return L(j);if(k())return F(U);var Z=o(arguments,1);L.apply(null,[null].concat(Z))};F(U)}function j1(k,T,L){Ll(function(){return!k.apply(this,arguments)},T,L)}var Ed=function(k,T){if(T=Er(T||Nt),!be(k))return T(new Error("First argument to waterfall must be an array of functions"));if(!k.length)return T();var L=0;function F(j){var Z=M(k[L++]);j.push(Ao(U)),Z.apply(null,j)}function U(j){if(j||L===k.length)return T.apply(null,arguments);F(o(arguments,1))}F([])},K3={apply:r,applyEach:td,applyEachSeries:nd,asyncify:v,auto:Uc,autoInject:x1,cargo:ci,compose:qc,concat:I1,concatLimit:gl,concatSeries:Gc,constant:Zc,detect:as,detectLimit:Jo,detectSeries:Cl,dir:T1,doDuring:D1,doUntil:S1,doWhilst:bd,during:L1,each:Qc,eachLimit:Al,eachOf:Go,eachOfLimit:xr,eachOfSeries:cs,eachSeries:di,ensureAsync:Yc,every:hi,everyLimit:bl,everySeries:Jc,filter:Xc,filterLimit:vl,filterSeries:ta,forever:R1,groupBy:fi,groupByLimit:ea,groupBySeries:N,log:G,map:jc,mapLimit:Ir,mapSeries:ed,mapValues:ht,mapValuesLimit:V,mapValuesSeries:Et,memoize:we,nextTick:na,parallel:kn,parallelLimit:yl,priorityQueue:mi,queue:yd,race:kl,reduce:Yo,reduceRight:gi,reflect:Wt,reflectAll:O1,reject:wl,rejectLimit:wd,rejectSeries:_1,retry:pi,retryable:Ko,seq:Wc,series:Bl,setImmediate:A,some:El,someLimit:Dr,someSeries:xl,sortBy:Bd,timeout:Il,times:N1,timesLimit:Ai,timesSeries:$1,transform:H1,tryEach:Dl,unmemoize:Sl,until:j1,waterfall:Ed,whilst:Ll,all:hi,allLimit:bl,allSeries:Jc,any:El,anyLimit:Dr,anySeries:xl,find:as,findLimit:Jo,findSeries:Cl,forEach:Qc,forEachSeries:di,forEachLimit:Al,forEachOf:Go,forEachOfSeries:cs,forEachOfLimit:xr,inject:Yo,foldl:Yo,foldr:gi,select:Xc,selectLimit:vl,selectSeries:ta,wrapSync:v};e.default=K3,e.apply=r,e.applyEach=td,e.applyEachSeries=nd,e.asyncify=v,e.auto=Uc,e.autoInject=x1,e.cargo=ci,e.compose=qc,e.concat=I1,e.concatLimit=gl,e.concatSeries=Gc,e.constant=Zc,e.detect=as,e.detectLimit=Jo,e.detectSeries=Cl,e.dir=T1,e.doDuring=D1,e.doUntil=S1,e.doWhilst=bd,e.during=L1,e.each=Qc,e.eachLimit=Al,e.eachOf=Go,e.eachOfLimit=xr,e.eachOfSeries=cs,e.eachSeries=di,e.ensureAsync=Yc,e.every=hi,e.everyLimit=bl,e.everySeries=Jc,e.filter=Xc,e.filterLimit=vl,e.filterSeries=ta,e.forever=R1,e.groupBy=fi,e.groupByLimit=ea,e.groupBySeries=N,e.log=G,e.map=jc,e.mapLimit=Ir,e.mapSeries=ed,e.mapValues=ht,e.mapValuesLimit=V,e.mapValuesSeries=Et,e.memoize=we,e.nextTick=na,e.parallel=kn,e.parallelLimit=yl,e.priorityQueue=mi,e.queue=yd,e.race=kl,e.reduce=Yo,e.reduceRight=gi,e.reflect=Wt,e.reflectAll=O1,e.reject=wl,e.rejectLimit=wd,e.rejectSeries=_1,e.retry=pi,e.retryable=Ko,e.seq=Wc,e.series=Bl,e.setImmediate=A,e.some=El,e.someLimit=Dr,e.someSeries=xl,e.sortBy=Bd,e.timeout=Il,e.times=N1,e.timesLimit=Ai,e.timesSeries=$1,e.transform=H1,e.tryEach=Dl,e.unmemoize=Sl,e.until=j1,e.waterfall=Ed,e.whilst=Ll,e.all=hi,e.allLimit=bl,e.allSeries=Jc,e.any=El,e.anyLimit=Dr,e.anySeries=xl,e.find=as,e.findLimit=Jo,e.findSeries=Cl,e.forEach=Qc,e.forEachSeries=di,e.forEachLimit=Al,e.forEachOf=Go,e.forEachOfSeries=cs,e.forEachOfLimit=xr,e.inject=Yo,e.foldl=Yo,e.foldr=gi,e.select=Xc,e.selectLimit=vl,e.selectSeries=ta,e.wrapSync=v,Object.defineProperty(e,"__esModule",{value:!0})})})(sp,sp.exports);var xb={exports:{}},lp=xb.exports=function(n,t){if(t||(t=16),n===void 0&&(n=128),n<=0)return"0";for(var e=Math.log(Math.pow(2,n))/Math.log(t),o=2;e===1/0;o*=2)e=Math.log(Math.pow(2,n/o))/Math.log(t)*o;for(var r=e-Math.floor(e),i="",o=0;o<Math.floor(e);o++){var s=Math.floor(Math.random()*t).toString(t);i=s+i}if(r){var l=Math.pow(t,r),s=Math.floor(Math.random()*l).toString(t);i=s+i}var a=parseInt(i,t);return a!==1/0&&a>=Math.pow(2,n)?lp(n,t):i};lp.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=lp(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 Ib=$i,bS=Bb,vS=Eb,zh=No,cp=sp.exports,yS=xb.exports,Tb=Us.ACTIONS,Db=Re;function Re(n,t){if(Ib.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}Ib.mixin(Re),Re.prototype.subscribe=function(n){this._sendSubscriptionAction(!0,n)},Re.prototype.unsubscribe=function(n){this._sendSubscriptionAction(!1,n)},Re.prototype.create=function(n){if(this._wantsDestroy)throw new Error("Presence is being destroyed");n=n||yS();var t=this._createLocalPresence(n);return this.localPresences[n]=t,t},Re.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);cp.parallel([function(i){cp.each(e,function(s,l){t.localPresences[s].destroy(l)},i)},function(i){if(!t._wantsDestroy)return i();cp.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)})})},Re.prototype._sendSubscriptionAction=function(n,t){this.wantSubscribe=!!n;var e=this.wantSubscribe?Tb.presenceSubscribe:Tb.presenceUnsubscribe,o=this.connection._presenceSeq++;this._subscriptionCallbacksBySeq[o]=t,this.connection.canSend&&this.connection._sendPresenceAction(e,o,this)},Re.prototype._handleSubscribe=function(n,t){this.wantSubscribe&&(this.subscribed=!0);var e=this._subscriptionCallback(t);this._callbackOrEmit(n,e)},Re.prototype._handleUnsubscribe=function(n,t){this.subscribed=!1;var e=this._subscriptionCallback(t);this._callbackOrEmit(n,e)},Re.prototype._receiveUpdate=function(n,t){var e=zh.dig(this.localPresences,t.id);if(e)return e._ack(n,t.pv);if(n)return this.emit("error",n);var o=this,r=zh.digOrCreate(this._remotePresenceInstances,t.id,function(){return o._createRemotePresence(t.id)});r.receiveUpdate(t)},Re.prototype._updateRemotePresence=function(n){this.remotePresences[n.presenceId]=n.value,n.value===null&&this._removeRemotePresence(n.presenceId),this.emit("receive",n.presenceId,n.value)},Re.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()}},Re.prototype._removeRemotePresence=function(n){this._remotePresenceInstances[n].destroy(),delete this._remotePresenceInstances[n],delete this.remotePresences[n]},Re.prototype._onConnectionStateChanged=function(){if(!!this.connection.canSend){this._resubscribe();for(var n in this.localPresences)this.localPresences[n]._sendPending()}},Re.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)})},Re.prototype._subscriptionCallback=function(n){var t=this._subscriptionCallbacksBySeq[n];return delete this._subscriptionCallbacksBySeq[n],t},Re.prototype._callbackOrEmit=function(n,t){if(t)return zh.nextTick(t,n);n&&this.emit("error",n)},Re.prototype._createLocalPresence=function(n){return new bS(this,n)},Re.prototype._createRemotePresence=function(n){return new vS(this,n)},Re.prototype._callEachOrEmit=function(n,t){var e=zh.callEach(n,t);!e&&t&&this.emit("error",t)};var qa=Bb,Sb=Nh,kS=No,Lb=Sb.CODES,wS=Ho;function Ho(n,t){qa.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()}Ho.prototype=Object.create(qa.prototype),Ho.prototype.submit=function(n,t){if(!this._doc.type){if(n===null)return this._callbackOrEmit(null,t);var e={code:Lb.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,qa.prototype.submit.call(this,n,t)},Ho.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),qa.prototype.destroy.call(this,n)},Ho.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={})})}},Ho.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)},Ho.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)}},Ho.prototype._handleCreateOrDel=function(){this._pendingMessages.forEach(function(n){n.p=null}),this.value=null},Ho.prototype._handleLoad=function(){this.value=null,this._pendingMessages=[],this._docDataVersionByPresenceVersion={}},Ho.prototype._message=function(){var n=qa.prototype._message.call(this);return n.c=this.collection,n.d=this.id,n.v=null,n.t=null,n},Ho.prototype._transformPresence=function(n,t,e){var o=this._doc.type;if(!kS.supportsPresence(o))throw new Sb(Lb.ERR_TYPE_DOES_NOT_SUPPORT_PRESENCE,"Type does not support presence: "+o.name);return o.transformPresence(n,t,e)};var Mb={};(function(n){var t=za,e=Nh,o=No,r=e.CODES;n.checkOp=function(l){if(l==null||typeof l!="object")return new e(r.ERR_OT_OP_BADLY_FORMED,"Op must be an object");if(l.create!=null){if(typeof l.create!="object")return new e(r.ERR_OT_OP_BADLY_FORMED,"Create data must be an object");var a=l.create.type;if(typeof a!="string")return new e(r.ERR_OT_OP_BADLY_FORMED,"Missing create type");var d=t.map[a];if(d==null||typeof d!="object")return new e(r.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type")}else if(l.del!=null){if(l.del!==!0)return new e(r.ERR_OT_OP_BADLY_FORMED,"del value must be true")}else if(!("op"in l))return new e(r.ERR_OT_OP_BADLY_FORMED,"Missing op, create, or del");if(l.src!=null&&typeof l.src!="string")return new e(r.ERR_OT_OP_BADLY_FORMED,"src must be a string");if(l.seq!=null&&typeof l.seq!="number")return new e(r.ERR_OT_OP_BADLY_FORMED,"seq must be a number");if(l.src==null&&l.seq!=null||l.src!=null&&l.seq==null)return new e(r.ERR_OT_OP_BADLY_FORMED,"Both src and seq must be set together");if(l.m!=null&&typeof l.m!="object")return new e(r.ERR_OT_OP_BADLY_FORMED,"op.m must be an object or null")},n.normalizeType=function(l){return t.map[l]&&t.map[l].uri},n.apply=function(l,a){if(typeof l!="object")return new e(r.ERR_APPLY_SNAPSHOT_NOT_PROVIDED,"Missing snapshot");if(l.v!=null&&a.v!=null&&l.v!==a.v)return new e(r.ERR_APPLY_OP_VERSION_DOES_NOT_MATCH_SNAPSHOT,"Version mismatch");if(a.create){if(l.type)return new e(r.ERR_DOC_ALREADY_CREATED,"Document already exists");var d=a.create,h=t.map[d.type];if(!h)return new e(r.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type");try{l.data=h.create(d.data),l.type=h.uri,l.v++}catch(A){return A}}else if(a.del)l.data=void 0,l.type=null,l.v++;else if("op"in a){var p=i(l,a.op);if(p)return p;l.v++}else l.v++};function i(l,a){if(!l.type)return new e(r.ERR_DOC_DOES_NOT_EXIST,"Document does not exist");if(a===void 0)return new e(r.ERR_OT_OP_NOT_PROVIDED,"Missing op");var d=t.map[l.type];if(!d)return new e(r.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type");try{l.data=d.apply(l.data,a)}catch(h){return new e(r.ERR_OT_OP_NOT_APPLIED,h.message)}}n.transform=function(l,a,d){if(a.v!=null&&a.v!==d.v)return new e(r.ERR_OP_VERSION_MISMATCH_DURING_TRANSFORM,"Version mismatch");if(d.del){if(a.create||"op"in a)return new e(r.ERR_DOC_WAS_DELETED,"Document was deleted")}else{if(d.create&&("op"in a||a.create||a.del)||"op"in d&&a.create)return new e(r.ERR_DOC_ALREADY_CREATED,"Document was created remotely");if("op"in d&&"op"in a){if(!l)return new e(r.ERR_DOC_DOES_NOT_EXIST,"Document does not exist");if(typeof l=="string"&&(l=t.map[l],!l))return new e(r.ERR_DOC_TYPE_NOT_RECOGNIZED,"Unknown type");try{a.op=l.transform(a.op,d.op,"left")}catch(h){return h}}}a.v!=null&&a.v++},n.applyOps=function(l,a,d){d=d||{};for(var h=0;h<a.length;h++){var p=a[h];if(d._normalizeLegacyJson0Ops)try{s(l,p)}catch{return new e(r.ERR_OT_LEGACY_JSON0_OP_CANNOT_BE_NORMALIZED,"Cannot normalize legacy json0 op")}l.v=p.v;var A=n.apply(l,p);if(A)return A}},n.transformPresence=function(l,a,d){var h=this.checkOp(a);if(h)return h;var p=l.t;if(typeof p=="string"&&(p=t.map[p]),!p)return{code:r.ERR_DOC_TYPE_NOT_RECOGNIZED,message:"Unknown type"};if(!o.supportsPresence(p))return{code:r.ERR_TYPE_DOES_NOT_SUPPORT_PRESENCE,message:"Type does not support presence"};if(a.create||a.del){l.p=null,l.v++;return}try{l.p=l.p===null?null:p.transformPresence(l.p,a.op,d)}catch(A){return{code:r.ERR_PRESENCE_TRANSFORM_FAILED,message:A.message||A}}l.v++};function s(l,a){if(l.type===t.defaultType.uri){var d=a.op;if(!!d){var h=l.data;d.length>1&&(h=o.clone(h));for(var p=0;p<d.length;p++){var A=d[p];typeof A.lm=="string"&&(A.lm=+A.lm);for(var v=A.p,B=h,D=0;D<v.length;D++){var x=v[D];Object.prototype.toString.call(B)=="[object Array]"?v[D]=+x:B.constructor===Object&&(v[D]=x.toString()),B=B[x]}p<d.length-1&&(h=t.defaultType.apply(h,[A]))}}}}})(Mb);var Ga=Eb,BS=Mb,ES=ao;function ao(n,t){Ga.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()}ao.prototype=Object.create(Ga.prototype),ao.prototype.receiveUpdate=function(n){this._pending&&n.pv<this._pending.pv||(this.src=n.src,this._pending=n,this._setPendingPresence())},ao.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),Ga.prototype.destroy.call(this,n)},ao.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)},ao.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))}})}},ao.prototype._handleOp=function(n,t,e){var o=e===this.src;this._transformAgainstOp(n,o),this._cacheOp(n,o),this._setPendingPresence()},Ga.prototype._handleCreateDel=function(){this._cacheOp(null),this._setPendingPresence()},Ga.prototype._handleLoad=function(){this.value=null,this._pending=null,this._opCache=null,this.presence._updateRemotePresence(this)},ao.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)}},ao.prototype._catchUpStalePresence=function(){if(this._pending.v>=this._doc.version)return!0;if(!this._opCache)return this._startCachingOps(),this._doc.fetch(),this.presence.subscribe(),!1;for(;this._opCache[this._pending.v];){var n=this._opCache[this._pending.v],t=n.op,e=n.isOwnOp;t===null?(this._pending.p=null,this._pending.v++):BS.transformPresence(this._pending,t,e)}var o=this._pending.v>=this._doc.version;return o&&this._stopCachingOps(),o},ao.prototype._startCachingOps=function(){this._opCache=[]},ao.prototype._stopCachingOps=function(){this._opCache=null},ao.prototype._cacheOp=function(n,t){this._opCache&&(n=n?{op:n}:null,this._opCache[this._doc.version-1]={op:n,isOwnOp:t})};var Rb=Db,xS=wS,IS=ES;function Xl(n,t,e){var o=Xl.channel(t,e);Rb.call(this,n,o),this.collection=t,this.id=e}var TS=Xl;Xl.prototype=Object.create(Rb.prototype),Xl.channel=function(n,t){return n+"."+t},Xl.prototype._createLocalPresence=function(n){return new xS(this,n)},Xl.prototype._createRemotePresence=function(n){return new IS(this,n)};var DS=SS;function SS(n,t,e,o,r){this.id=n,this.v=t,this.type=e,this.data=o,this.m=r}var LS=DS,Ob=$i,_b=Za;function Za(n,t,e,o,r){if(Ob.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}Ob.mixin(Za),Za.prototype.send=function(){!this.connection.canSend||(this.connection.send(this._message()),this.sent=!0)},Za.prototype._onConnectionStateChanged=function(){this.connection.canSend?this.sent||this.send():this.sent=!1},Za.prototype._handleResponse=function(n,t){if(this.emit("ready"),n)return this.callback(n);var e=t.meta?t.meta:null,o=new LS(this.id,t.v,t.type,t.data,e);this.callback(null,o)};var Fb=_b,MS=No,RS=Us.ACTIONS,OS=ap;function ap(n,t,e,o,r,i){if(Fb.call(this,n,t,e,o,i),!MS.isValidVersion(r))throw new Error("Snapshot version must be a positive integer or null");this.version=r}ap.prototype=Object.create(Fb.prototype),ap.prototype._message=function(){return{a:RS.snapshotFetch,id:this.requestId,c:this.collection,d:this.id,v:this.version}};var Pb=_b,_S=No,FS=Us.ACTIONS,PS=up;function up(n,t,e,o,r,i){if(Pb.call(this,n,t,e,o,i),!_S.isValidTimestamp(r))throw new Error("Snapshot timestamp must be a positive integer or null");this.timestamp=r}up.prototype=Object.create(Pb.prototype),up.prototype._message=function(){return{a:FS.snapshotFetchByTimestamp,id:this.requestId,c:this.collection,d:this.id,ts:this.timestamp}};var NS=uS,$S=gS,HS=Db,Nb=TS,jS=OS,US=PS,$b=$i,tc=Nh,ee=Us.ACTIONS,Hb=za,jo=No,Qa=gb,Ya=tc.CODES;function jb(n){return n.readyState===0||n.readyState===1?"connecting":"disconnected"}var zS=wt;function wt(n){$b.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=jb(n),this.bindToSocket(n)}$b.mixin(wt),wt.prototype.bindToSocket=function(n){this.socket&&(this.socket.close(),this.socket.onmessage=null,this.socket.onopen=null,this.socket.onerror=null,this.socket.onclose=null),this.socket=n;var t=jb(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{Qa.warn("Failed to parse message",o);return}e.debug&&Qa.info("RECV",JSON.stringify(r));var i={data:r};if(e.emit("receive",i),!!i.data)try{e.handleMessage(i.data)}catch(s){jo.nextTick(function(){e.emit("error",s)})}},n.readyState===1&&e._initializeHandshake(),n.onopen=function(){e._setState("connecting"),e._initializeHandshake()},n.onerror=function(o){e.emit("connection error",o)},n.onclose=function(o){o==="closed"||o==="Closed"?e._setState("closed",o):o==="stopped"||o==="Stopped by server"?e._setState("stopped",o):e._setState("disconnected",o)}},wt.prototype.handleMessage=function(n){var t=null;switch(n.error&&(t=Ub(n.error,n),delete n.error),n.a){case ee.initLegacy:return this._handleLegacyInit(n);case ee.handshake:return this._handleHandshake(t,n);case ee.queryFetch:var e=this.queries[n.id];e&&e._handleFetch(t,n.data,n.extra);return;case ee.querySubscribe:var e=this.queries[n.id];e&&e._handleSubscribe(t,n.data,n.extra);return;case ee.queryUnsubscribe:return;case ee.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 ee.bulkFetch:return this._handleBulkMessage(t,n,"_handleFetch");case ee.bulkSubscribe:case ee.bulkUnsubscribe:return this._handleBulkMessage(t,n,"_handleSubscribe");case ee.snapshotFetch:case ee.snapshotFetchByTimestamp:return this._handleSnapshotFetch(t,n);case ee.fetch:var o=this.getExisting(n.c,n.d);o&&o._handleFetch(t,n.data);return;case ee.subscribe:case ee.unsubscribe:var o=this.getExisting(n.c,n.d);o&&o._handleSubscribe(t,n.data);return;case ee.op:var o=this.getExisting(n.c,n.d);o&&o._handleOp(t,n);return;case ee.presence:return this._handlePresence(t,n);case ee.presenceSubscribe:return this._handlePresenceSubscribe(t,n);case ee.presenceUnsubscribe:return this._handlePresenceUnsubscribe(t,n);case ee.presenceRequest:return this._handlePresenceRequest(t,n);case ee.pingPong:return this._handlePingPong(t);default:Qa.warn("Ignoring unrecognized message",n)}};function Ub(n,t){var e=new Error(n.message);return e.code=n.code,t&&(e.data=t),e}wt.prototype._handleBulkMessage=function(n,t,e){if(t.data)for(var o in t.data){var r=t.data[o],i=this.getExisting(t.c,o);i&&(n?i[e](n):r.error?i[e](Ub(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 Qa.error("Invalid bulk message",t)},wt.prototype._reset=function(){this.agent=null},wt.prototype._setState=function(n,t){if(this.state!==n){if(n==="connecting"&&this.state!=="disconnected"&&this.state!=="stopped"&&this.state!=="closed"||n==="connected"&&this.state!=="connecting"){var e=new tc(Ya.ERR_CONNECTION_STATE_TRANSITION_INVALID,"Cannot transition directly from "+this.state+" to "+n);return this.emit("error",e)}this.state=n,this.canSend=n==="connected",(n==="disconnected"||n==="stopped"||n==="closed")&&this._reset(),this.startBulk();for(var o in this.queries){var r=this.queries[o];r._onConnectionStateChanged()}for(var i in this.collections){var s=this.collections[i];for(var o in s)s[o]._onConnectionStateChanged()}for(var l in this._presences)this._presences[l]._onConnectionStateChanged();for(var o in this._snapshotRequests){var a=this._snapshotRequests[o];a._onConnectionStateChanged()}this.endBulk(),this.emit(n,t),this.emit("state",n,t)}},wt.prototype.startBulk=function(){this.bulk||(this.bulk={})},wt.prototype.endBulk=function(){if(this.bulk)for(var n in this.bulk){var t=this.bulk[n];this._sendBulk("f",n,t.f),this._sendBulk("s",n,t.s),this._sendBulk("u",n,t.u)}this.bulk=null},wt.prototype._sendBulk=function(n,t,e){if(!!e){var o=[],r={},i=0,s;for(var l in e){var a=e[l];a==null?o.push(l):(r[l]=a,s=l,i++)}if(o.length===1){var l=o[0];this.send({a:n,c:t,d:l})}else o.length&&this.send({a:"b"+n,c:t,b:o});if(i===1){var d=r[s];this.send({a:n,c:t,d:s,v:d})}else i&&this.send({a:"b"+n,c:t,b:r})}},wt.prototype._sendActions=function(n,t,e){if(this._addDoc(t),this.bulk){var o=this.bulk[t.collection]||(this.bulk[t.collection]={}),r=o[n]||(o[n]={}),i=r.hasOwnProperty(t.id);return r[t.id]=e,i}else{var s={a:n,c:t.collection,d:t.id,v:e};this.send(s)}},wt.prototype.sendFetch=function(n){return this._sendActions(ee.fetch,n,n.version)},wt.prototype.sendSubscribe=function(n){return this._sendActions(ee.subscribe,n,n.version)},wt.prototype.sendUnsubscribe=function(n){return this._sendActions(ee.unsubscribe,n)},wt.prototype.sendOp=function(n,t){this._addDoc(n);var e={a:ee.op,c:n.collection,d:n.id,v:n.version,src:t.src,seq:t.seq,x:{}};"op"in t&&(e.op=t.op),t.create&&(e.create=t.create),t.del&&(e.del=t.del),n.submitSource&&(e.x.source=t.source),this.send(e)},wt.prototype.send=function(n){this.debug&&Qa.info("SEND",JSON.stringify(n)),this.emit("send",n),this.socket.send(JSON.stringify(n))},wt.prototype.ping=function(){if(!this.canSend)throw new tc(Ya.ERR_CANNOT_PING_OFFLINE,"Socket must be CONNECTED to ping");var n={a:ee.pingPong};this.send(n)},wt.prototype.close=function(){this.socket.close()},wt.prototype.getExisting=function(n,t){if(this.collections[n])return this.collections[n][t]},wt.prototype.get=function(n,t){var e=this.collections[n]||(this.collections[n]={}),o=e[t];return o||(o=e[t]=new NS(this,n,t),this.emit("doc",o)),o._wantsDestroy=!1,o},wt.prototype._destroyDoc=function(n){!n._wantsDestroy||(jo.digAndRemove(this.collections,n.collection,n.id),n.emit("destroy"))},wt.prototype._addDoc=function(n){var t=this.collections[n.collection];t||(t=this.collections[n.collection]={}),t[n.id]!==n&&(t[n.id]=n)},wt.prototype._createQuery=function(n,t,e,o,r){var i=this.nextQueryId++,s=new $S(n,this,i,t,e,o,r);return this.queries[i]=s,s.send(),s},wt.prototype._destroyQuery=function(n){delete this.queries[n.id]},wt.prototype.createFetchQuery=function(n,t,e,o){return this._createQuery(ee.queryFetch,n,t,e,o)},wt.prototype.createSubscribeQuery=function(n,t,e,o){return this._createQuery(ee.querySubscribe,n,t,e,o)},wt.prototype.hasPending=function(){return!!(this._firstDoc(Vh)||this._firstQuery(Vh)||this._firstSnapshotRequest())};function Vh(n){return n.hasPending()}wt.prototype.hasWritePending=function(){return!!this._firstDoc(VS)};function VS(n){return n.hasWritePending()}wt.prototype.whenNothingPending=function(n){var t=this._firstDoc(Vh);if(t){t.once("nothing pending",this._nothingPendingRetry(n));return}var e=this._firstQuery(Vh);if(e){e.once("ready",this._nothingPendingRetry(n));return}var o=this._firstSnapshotRequest();if(o){o.once("ready",this._nothingPendingRetry(n));return}jo.nextTick(n)},wt.prototype._nothingPendingRetry=function(n){var t=this;return function(){jo.nextTick(function(){t.whenNothingPending(n)})}},wt.prototype._firstDoc=function(n){for(var t in this.collections){var e=this.collections[t];for(var o in e){var r=e[o];if(n(r))return r}}},wt.prototype._firstQuery=function(n){for(var t in this.queries){var e=this.queries[t];if(n(e))return e}},wt.prototype._firstSnapshotRequest=function(){for(var n in this._snapshotRequests)return this._snapshotRequests[n]},wt.prototype.fetchSnapshot=function(n,t,e,o){typeof e=="function"&&(o=e,e=null);var r=this.nextSnapshotRequestId++,i=new jS(this,r,n,t,e,o);this._snapshotRequests[i.requestId]=i,i.send()},wt.prototype.fetchSnapshotByTimestamp=function(n,t,e,o){typeof e=="function"&&(o=e,e=null);var r=this.nextSnapshotRequestId++,i=new US(this,r,n,t,e,o);this._snapshotRequests[i.requestId]=i,i.send()},wt.prototype._handleSnapshotFetch=function(n,t){var e=this._snapshotRequests[t.id];!e||(delete this._snapshotRequests[t.id],e._handleResponse(n,t))},wt.prototype._handleLegacyInit=function(n){if(n.protocolMinor)return this._initializeHandshake();this._initialize(n)},wt.prototype._initializeHandshake=function(){this.send({a:ee.handshake,id:this.id})},wt.prototype._handleHandshake=function(n,t){if(n)return this.emit("error",n);this._initialize(t)},wt.prototype._handlePingPong=function(n){if(n)return this.emit("error",n);this.emit("pong")},wt.prototype._initialize=function(n){if(this.state==="connecting"){if(n.protocol!==1)return this.emit("error",new tc(Ya.ERR_PROTOCOL_VERSION_NOT_SUPPORTED,"Unsupported protocol version: "+n.protocol));if(Hb.map[n.type]!==Hb.defaultType)return this.emit("error",new tc(Ya.ERR_DEFAULT_TYPE_MISMATCH,n.type+" does not match the server default type"));if(typeof n.id!="string")return this.emit("error",new tc(Ya.ERR_CLIENT_ID_BADLY_FORMED,"Client id must be a string"));this.id=n.id,this._setState("connected")}},wt.prototype.getPresence=function(n){var t=this,e=jo.digOrCreate(this._presences,n,function(){return new HS(t,n)});return e._wantsDestroy=!1,e},wt.prototype.getDocPresence=function(n,t){var e=Nb.channel(n,t),o=this,r=jo.digOrCreate(this._presences,e,function(){return new Nb(o,n,t)});return r._wantsDestroy=!1,r},wt.prototype._sendPresenceAction=function(n,t,e){this._addPresence(e);var o={a:n,ch:e.channel,seq:t};return this.send(o),o.seq},wt.prototype._addPresence=function(n){jo.digOrCreate(this._presences,n.channel,function(){return n})},wt.prototype._handlePresenceSubscribe=function(n,t){var e=jo.dig(this._presences,t.ch);e&&e._handleSubscribe(n,t.seq)},wt.prototype._handlePresenceUnsubscribe=function(n,t){var e=jo.dig(this._presences,t.ch);e&&e._handleUnsubscribe(n,t.seq)},wt.prototype._handlePresence=function(n,t){var e=jo.dig(this._presences,t.ch);e&&e._receiveUpdate(n,t)},wt.prototype._handlePresenceRequest=function(n,t){var e=jo.dig(this._presences,t.ch);e&&e._broadcastAllLocalPresence(n,t)};var zb=zS,WS=za;const Wh={err:1001,msg:"user auth error",name:"AuthError"},qS={err:1002,msg:"you don't have required permission",name:"PermissionError"},dp={err:1003,msg:"Too many user connected",name:"MaxUserError"},Ja={err:1004,msg:"document server changed, reload it",name:"RequestReloadError"},GS={err:1005,msg:"app id must be at least 2 chars, doc id must be at least 5 chars",name:"DocIdError"},ZS={err:1028,msg:"upload file ext not allowed",name:"FileExtError"},Ka="x-live-editor-token",qh="x-live-editor-base-url",pn=S("auth-connection");function QS(n){try{n()}catch(t){pn.error(t)}}class YS{constructor(t,e){m(this,"connection");m(this,"ws");m(this,"retryCount");m(this,"events",new W5.EventEmitter);m(this,"token",null);m(this,"resourceToken",null);this.url=t,this.reauthFunc=e,this.retryCount=0}getBaseURL(){const t=new URL(this.url);return`${t.protocol==="wss:"?"https:":"http:"}//${t.host}${t.pathname}`}getBase64BaseURL(){return Si(this.getBaseURL())}async auth(t){g(pn,t.token,"no auth token");const e=`${this.getBaseURL()}/auth`,o=await window.fetch(e,{method:"GET",headers:{[Ka]:t.token,[qh]: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:{[qh]:Si(this.getBaseURL())}})}async init(t){const e=await this.auth(t);this.resourceToken=e.read,this.ws=new VB.default(this.url,void 0,{maxReconnectionDelay:2500,minReconnectionDelay:1e3}),this.connection=Object.create(zb.prototype),g(pn,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}}},zb.apply(this.connection,[this.ws])}async handleAuthError(){if(this.reauthFunc&&this.retryCount<5){this.retryCount+=1,pn.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){pn.error(t),setTimeout(()=>this.handleAuthError(),0)}}else pn.error("auth error, cannot retry anymore"),this.emitAuthError(),this.end(!1)}emitAuthError(){const t=new Error(Wh.msg);t.code=Wh.err,this.events.emit("error",t)}emitRequestReloadError(){const t=new Error(Ja.msg);t.code=Ja.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===Wh.err)pn.warn("auth error"),this.handleAuthError();else if(o===dp.err)pn.warn(dp.msg),this.emitMaxUsersError();else if(o===Ja.err){pn.warn(Ja.msg);try{this.emitRequestReloadError()}catch(r){pn.error(`error occurred while process reload error: ${JSON.stringify(r)}`)}finally{this.end(!1)}}else pn.error(`unknown message received: ${JSON.stringify(e)}`),this.emitAuthError()}get(t,e){return g(pn,this.connection,"no this.connection"),this.connection.get(t,e)}addEventListener(t,e){t==="error"?this.events.addListener(t,e):(g(pn,this.ws,"no this.ws"),this.ws.addEventListener(t,e))}onWriteConflictError(t){this.events.addListener("writeConflictError",t)}onMaxUsersError(t){g(pn,this.events.listenerCount("maxUsersError")===0,"too many maxUserError listener"),this.events.addListener("maxUsersError",t)}onRequestReloadError(t){g(pn,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(),QS(()=>{var o;return(o=this.connection)==null?void 0:o.close()}),this.connection=void 0,(e=this.ws)==null||e.close(),this.ws=void 0,t&&this.logout()}}S("utils/file");function JS(){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}JS();async function KS(n){const e=n.size,o=Math.floor((e+102400-1)/102400),r=new WB.Hash;for(let s=0;s<o;s++){const l=s*102400;let a=l+102400;a>e&&(a=e);const h=await n.slice(l,a,n.type).arrayBuffer();r.update(new Uint8Array(h))}const i=r.digest();return Si(i)}const hr=S("sharedb-doc/client");class XS{constructor(t,e,o){m(this,"connection");m(this,"auth");m(this,"doc",null);m(this,"reauthFunc");m(this,"clientId",K());m(this,"getDoc",async()=>{const t=o=>new Promise((r,i)=>{o.fetch(s=>{s?i(s):r()})});g(hr,!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),hr.debug(e),e});this.auth=t;const r=`${e}/${this.auth.appId}/${this.auth.docId}`;WS.register(Fd.type),this.connection=new YS(r,o),this.reauthFunc=o}editorServer(){const t=this.apiServer(),e=`/${this.auth.appId}/${this.auth.docId}`;return g(hr,t.endsWith(e),`invalid api server: ${t}, ${e}`),t.substr(0,t.length-e.length)}close(t){this.connection.end(t),this.doc=null}on(t,e){this.connection.addEventListener(t,o=>{(t==="error"||this.doc)&&e(o)})}onWriteConflictError(t){this.connection.onWriteConflictError(t)}onMaxUsersError(t){this.connection.onMaxUsersError(t)}onRequestReloadError(t){this.connection.onRequestReloadError(t)}async authOnly(){await this.connection.auth(this.auth)}getResourceToken(){return this.connection.resourceToken}hasDocContainer(){return!!this.doc}apiServer(){const t=this.connection.url;if(t.startsWith("ws://"))return`http://${t.substring(5)}`;if(t.startsWith("wss://"))return`https://${t.substring(6)}`;throw new Error(`invalid server url: ${t}`)}async getFileUrlByHash(t,e,o,r,i){try{const s=`${t}/${e}`,l=await this.request(s,{method:"post",headers:{...i},data:{name:o,size:r}});return l.data&&Array.isArray(l.data)&&l.data.length===1?l.data[0]:""}catch{return""}}async getFileUrlsByHashes(t){const o=`${this.apiServer()}/resources`;let r=[];t.forEach(l=>{const a=l.split("|");r.push(...a)}),r=Array.from(new Set(r));const i=r.map(l=>this.getFileUrlByHash(o,l,"",0,{[Ka]:this.connection.token}));return await Promise.all(i)}async uploadFile(t,e,o,r,i){let s=e.size;if(s===0)throw new Error("file is empty");s+=500;const l=v=>{hr.info(`on progress: ${v.loaded}`);let B=v.loaded*100/s;B>100&&(B=100),r(B)},a=await KS(e),d=await this.getFileUrlByHash(t,a,e.name,e.size,o);if(d)return r(-1),d;let h=t;i!=null&&i.thumbnail&&(h+="/thumbnail");const p=new FormData;p.append("file-size",`${e.size}`),p.append("file-hash",a),p.append("file",e,e.name);const A=await this.request(h,{method:"post",data:p,withCredentials:!0,headers:{...o},onUploadProgress:l});return hr.info(A),r(100),Array.isArray(A.data)?A.data[0]:A.data}async uploadResource(t,e=()=>{},o){const i=`${this.apiServer()}/resources`;g(hr,this.connection.token,"no connection token");const s=await this.uploadFile(i,t,{[Ka]:this.connection.token},e,o);return g(hr,s,"no result"),s}async request(t,e){var i,s;let o=this.connection.token,r;for(let l=0;l<2;l++){const a=e||{};a.url=t,a.headers||(a.headers={}),g(hr,o,"no token"),a.headers={...a.headers,[Ka]:o,[qh]:this.connection.getBase64BaseURL()};try{return await UB.default(t,a)}catch(d){if(r=d,((i=d==null?void 0:d.response)==null?void 0:i.status)===403&&this.reauthFunc){const h=await this.reauthFunc();if(await this.connection.auth(h),!h.token)throw d;o=h.token;continue}throw(s=d.response)!=null&&s.data&&(d.responseData=d.response.data),d}}throw g(hr,r,"no error"),r}async getVersions(){const e=`${this.apiServer()}/versions?withExtra=true`,r=(await this.request(e)).data.versions;return r.forEach(i=>{i.extra&&(i.extra=JSON.parse(i.extra))}),r}async getVersion(t){const o=`${this.apiServer()}/versions/${t}`,r=await this.request(o);return JSON.parse(r.data.data)}async getLatestVersion(){const e=`${this.apiServer()}/versions/latest`,o=await this.request(e);return JSON.parse(o.data.data)}async getVersionOps(t,e){let r=`${this.apiServer()}/versions/before/${t}?withOp=true`;e!==void 0&&e!==0&&(r+=`&from=${e}`);const i=await this.request(r),s=i.data.ops,l=zB.default(s,h=>!!h.create);let a=null;l!==-1&&(a=s[l],s.splice(0,l+1));let d;return a?(g(hr,a.create,"no createDoc.create"),d=a.create.data):d=JSON.parse(i.data.data),d.blocks||(d.blocks=[]),{doc:d,ops:i.data.ops}}async updateVersionExtra(t,e,o){const i=`${this.apiServer()}/versions/${t}/tags/${e}`;await this.request(i,{method:"post",data:{extra:JSON.stringify(o)}})}async revertVersion(t){const o=`${this.apiServer()}/versions/revert/${t}`;await this.request(o,{method:"post",data:{}})}async createVersion(t,e){const r=`${this.apiServer()}/versions`;return(await this.request(r,{method:"post",data:{publish:e,tag:t}})).data}async recognizeLink(t){const o=`${this.apiServer()}/resources/external/${Si(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 tL(){return{blocks:[{id:K(),type:"text",text:[]}],comments:{},meta:{}}}const hp=S("block-ids");class eL{constructor(){m(this,"ids",new Map)}onInsertBlock(t){const e=Array.from(this.ids.keys()).sort((r,i)=>i-r);for(let r=0;r<e.length;r++){const i=e[r];if(i>=t){const s=this.ids.get(i);g(hp,s!==void 0,"old id is not exists"),this.ids.delete(i),this.ids.set(i+1,s)}}const o=K();this.ids.set(t,o)}onDeleteBlock(t){this.ids.delete(t);const e=Array.from(this.ids.keys()).sort((o,r)=>o-r);for(let o=0;o<e.length;o++){const r=e[o];if(r>t){const i=this.ids.get(r);g(hp,i!==void 0,"old id is not exists"),this.ids.delete(r),this.ids.set(r-1,i)}}}getId(t){let e=this.ids.get(t);return e||(e=K(),this.ids.set(t,e)),e}getById(t){return Array.from(this.ids.entries()).find(([,e])=>e===t)}}class nL{constructor(){m(this,"ids",new Map)}getContainerIds(t){let e=this.ids.get(t);return e||(e=new eL,this.ids.set(t,e)),e}onInsertBlock(t,e){this.getContainerIds(t).onInsertBlock(e)}onDeleteBlock(t,e){this.getContainerIds(t).onDeleteBlock(e)}getBlockId(t,e){return this.getContainerIds(t).getId(e)}getBlockIndexById(t){const e=Array.from(this.ids.entries());for(let o=0;o<e.length;o++){const r=e[o],i=r[1].getById(t);if(i)return{containerId:r[0],blockIndex:i[0]}}return g(hp,!1,"fault error: failed to get block index"),{containerId:"error",blockIndex:-1}}}class Vb{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 Gh=S("op-parse-handler");class oL{constructor(t,e){m(this,"actions",[]);this.outerHandler=t,this.local=e}pushActions(t){if(!t.containerId){this.actions.push(t);return}const o={...t,containerId:(r=>r==="blocks"?"root":r)(t.containerId)};this.actions.push(o)}onDeleteBlock(t,e){this.pushActions({type:"deleteBlock",containerId:t,blockIndex:e})}onInsertBlock(t,e,o){this.pushActions({type:"insertBlock",containerId:t,blockIndex:e,data:o})}onDeleteBlockData(t,e,o){this.pushActions({type:"deleteBlockData",containerId:t,blockIndex:e,key:o})}onInsertBlockData(t,e,o,r){this.pushActions({type:"insertBlockData",containerId:t,blockIndex:e,key:o,value:r})}onUpdateBlockText(t,e,o){this.pushActions({type:"updateBlockText",containerId:t,blockIndex:e,richTextData:o})}onDeleteContainer(t){this.pushActions({type:"deleteContainer",containerId:t})}onCreateContainer(t,e){this.pushActions({type:"createContainer",containerId:t,data:e})}onDeleteComment(t){this.pushActions({type:"deleteComment",commentId:t})}onCreateComment(t){this.pushActions({type:"createComment",commentId:t})}onUpdateComment(t){this.pushActions({type:"updateComment",commentId:t})}end(){const t=this.actions,e=new Set,o=new Map,r=new nL,i=t.filter(s=>s.type==="deleteBlock"||s.type==="deleteBlockData");for(const s of i)if(s.type==="deleteBlock"){const l=s,a=r.getBlockId(l.containerId,l.blockIndex);r.onDeleteBlock(l.containerId,l.blockIndex);const d=o.get(a);d&&(Gh.debug(`ignore update object data before delete block: ${JSON.stringify(d)}`),o.delete(a));const h=`${l.containerId}-${l.blockIndex}`;e.add(h),this.outerHandler.onDeleteBlock(l.containerId,l.blockIndex,this.local)}else if(s.type==="deleteBlockData"){const l=s,a=`${l.containerId}-${l.blockIndex}`;if(e.has(a)){Gh.warn("delete block data after delete block, ignore it");continue}const d=r.getBlockId(l.containerId,l.blockIndex);let h=o.get(d);h||(h=new Vb,o.set(d,h)),h.delete(l.key)}else g(Gh,!1,`invalid action type, ${s.type}`);this.actions.forEach(s=>{if(s.type==="deleteContainer"){const l=s;this.outerHandler.onDeleteContainer(l.containerId,this.local)}else if(s.type==="deleteComment"){const l=s;this.outerHandler.onDeleteComment(l.commentId,this.local)}}),this.actions.forEach(s=>{if(s.type==="createContainer"){const l=s;this.outerHandler.onCreateContainer(l.containerId,l.data,this.local)}}),this.actions.forEach(s=>{if(s.type==="insertBlock"){const l=s;this.outerHandler.onInsertBlock(l.containerId,l.blockIndex,l.data,this.local)}else if(s.type==="insertBlockData"){const l=s,a=r.getBlockId(l.containerId,l.blockIndex);let d=o.get(a);d||(d=new Vb,o.set(a,d)),d.insert(l.key,l.value)}else if(s.type==="updateBlockText"){const l=s;this.outerHandler.onUpdateBlockText(l.containerId,l.blockIndex,l.richTextData,this.local)}else if(s.type==="createComment"){const l=s;this.outerHandler.onCreateComment(l.commentId,this.local)}else if(s.type==="updateComment"){const l=s;this.outerHandler.onUpdateComment(l.commentId,this.local)}}),Array.from(o.entries()).forEach(([s,l])=>{const{containerId:a,blockIndex:d}=r.getBlockIndexById(s);Gh.debug(`update block data: ${a}, ${d}, ${JSON.stringify(l.toDocBlockDelta())}`),this.outerHandler.onUpdateBlockData(a,d,l.toDocBlockDelta(),this.local)})}}const Oe=S("op-parser");class Wb{}class fp{constructor(t){m(this,"key");this.key=t}}function rL(n,t,e){const o=t.concat(),r=o[0];if(typeof r!="number"||(o.shift(),o.length===1))return!1;const i=o[0];if(typeof i!="object"||!i.i||Object.keys(i).length!==1)return!1;for(let l=1;l<o.length;l++){const a=o[l];if(!Array.isArray(a)||a.length!==2||typeof a[0]!="string")return!1;const h=a[1];if(typeof h!="object"||h.i===void 0||Object.keys(h).length!==1)return!1}const s=i.i;g(Oe,s.id,"block id is required"),g(Oe,s.type,"block type is required");for(let l=1;l<o.length;l++){const a=o[l],d=a[0],h=a[1];s[d]=h.i}return e.onInsertBlock(n,r,s),!0}function mp(n,t,e,o){if(e==="upsert"&&rL(n,t,o))return;g(Oe,Array.isArray(t),`invalid block op: ${n}, ${JSON.stringify(t)}`);const r=t.concat(),i=r[0];r.shift();const s=[];for(;r.length>0;){const l=r[0];if(l==="text"){const a=r[1];if(g(Oe,typeof a=="object",`invalid block op: ${n}, ${JSON.stringify(t)}`),g(Oe,a.et==="rich-text",`invalid block op: ${n}, ${JSON.stringify(t)}`),r.splice(0,2),e==="upsert"){const h=a.e;o.onUpdateBlockText(n,i,h)}g(Oe,r.length===0,`invalid block ops.length !== 0, ${JSON.stringify(r)}`)}else if(Array.isArray(l)){g(Oe,l.length===2,`invalid block op: data.length !== 2, ${JSON.stringify(l)}`);const a=l[0];g(Oe,typeof a=="string",`invalid block op: key ${JSON.stringify(a)}`);const d=l[1];if(a==="text"){if(g(Oe,typeof d=="object",`invalid opData type, ${JSON.stringify(d)}`),d.i&&e==="upsert"&&o.onInsertBlockData(n,i,a,d.i),d.r&&e==="remove"&&o.onDeleteBlockData(n,i,a),d.et==="rich-text"&&e==="upsert"){const p=d.e;o.onUpdateBlockText(n,i,p)}}else e==="remove"&&d.r&&s.push(new fp(a)),e==="upsert"&&d.i&&o.onInsertBlockData(n,i,a,d.i);r.shift()}else if(typeof l=="object"){const a=l;e==="remove"&&a.r&&s.push(new Wb),e==="upsert"&&a.i&&o.onInsertBlock(n,i,a.i),r.shift()}else{g(Oe,typeof l=="string","data is not string"),g(Oe,l!=="text","data !== 'text'"),g(Oe,r.length===2,`invalid block op: ops.length !== 2, ${JSON.stringify(r)}`);const a=l,d=r[1];e==="remove"&&d.r&&s.push(new fp(a)),e==="upsert"&&d.i&&o.onInsertBlockData(n,i,a,d.i),r.splice(0,2)}}s.reverse(),s.forEach(l=>{l instanceof Wb?o.onDeleteBlock(n,i):l instanceof fp?o.onDeleteBlockData(n,i,l.key):g(Oe,!1,`invalid action type: ${typeof l}, ${JSON.stringify(l)}`)})}function iL(n,t,e){Oe.warn(`unsupported meta op, ${JSON.stringify(n)}`)}function sL(n,t,e){const o=n[1],r=n[2];g(Oe,o,`invalid comment op, no commentId: ${JSON.stringify(n)}`),g(Oe,r,`invalid comment op, no actions: ${JSON.stringify(n)}`),typeof r=="string"?Oe.error(`unknown comment op, ${JSON.stringify(n)}`):r.i&&r.r?t==="upsert"&&e.onUpdateComment(o):r.i?t==="upsert"&&e.onCreateComment(o):r.r?t==="remove"&&e.onDeleteComment(o):Oe.error(`unknown comment op, ${JSON.stringify(n)}`)}function gp(n,t,e){const o=n[0];if(Array.isArray(o)){o.forEach(s=>{gp(s,t,e)});return}const r=o;if(g(Oe,typeof r=="string",`invalid container id: ${JSON.stringify(n)}`),r==="meta"){iL(n);return}if(r==="comments"){sL(n,t,e);return}const i=r;if(Array.isArray(n[1]))t==="remove"?n.slice(1).reverse().forEach(s=>{mp(i,s,t,e)}):n.slice(1).forEach(s=>{mp(i,s,t,e)});else if(typeof n[1]=="object"){const s=n[1];s.r&&t==="remove"&&e.onDeleteContainer(i),s.i&&t==="upsert"&&e.onCreateContainer(i,s.i)}else g(Oe,typeof n[1]=="number",`invalid ops[1], not a number: ${JSON.stringify(n)}`),mp(i,n.slice(1),t,e)}function qb(n,t,e){const o=new oL(t,e);for(let r=0;r<2;r++){const i=r===0?"remove":"upsert",s=mt.default(n),l=s[0];Array.isArray(l)?s.forEach(a=>{gp(a,i,o)}):gp(s,i,o)}o.end()}const lL=S("sharedb-comments");function pp(n){const t=n.blocks;g(lL,t,"no comment blocks");const e={blocks:{root:t},meta:{},comments:{}};return Object.entries(n).forEach(([o,r])=>{Array.isArray(r)&&(e.blocks[o]=r)}),mt.default(e)}function Gb(n){const{id:t,groupId:e,userId:o,displayName:r,avatarUrl:i,abstract:s,created:l,modified:a}=n;return{id:t,groupId:e,userId:o,displayName:r,avatarUrl:i,abstract:s,created:l,modified:a}}function Cp(n,t){const e=WD(t),{comments:o,meta:r,blocks:i,...s}=e,l={...n,blocks:i,...s},a=mt.default(l);return delete a.children,a}const ae=S("sharedb-doc/doc-container"),Zb="ot-json1";Fd.type.registerSubtype(qD.type),Fd.type.name=Zb,Fd.type.invert=null;class Xa extends ha{constructor(e,o,r=!0){super();m(this,"doc");m(this,"client");m(this,"localPresence");m(this,"remoteCaretHandler",new zD);m(this,"batching",0);m(this,"status","clean");m(this,"disableLogout");m(this,"destroyed",!1);m(this,"handleNothingPending",()=>{this.setStatus("clean")});m(this,"handleCreate",()=>{this.handleReload("doc created")});m(this,"handleDel",()=>{});m(this,"handleReload",e=>{this.callbacks.forEach(o=>{var r;return(r=o.onRequestReload)==null?void 0:r.call(o,e)})});m(this,"handleReset",async e=>{const o=new Error(`reset doc: ${e}`);o.code="ResetDoc",this.callbacks.forEach(r=>{var i;return(i=r.onError)==null?void 0:i.call(r,o)}),this.destroy()});m(this,"handleWriteConflictError",e=>{this.handleReset(`write conflict: ${e.message}, ${JSON.stringify(e.orgMsg)}`)});m(this,"insertObject",async(e,o,r)=>{const i=[e,o,{i:r}];return this.submitOp(i)});m(this,"deleteObject",async(e,o)=>{const r=[e,o,{r:!0}];return this.submitOp(r)});m(this,"replaceObject",async(e,o,r)=>{const i=[e,o,{r:!0,i:r}];return this.submitOp(i)});m(this,"updateObject",async(e,o,r)=>{const i=this.data()[e][o],s=[e,o];return Object.entries(r).forEach(([l,a])=>{if(!aa.default(i[l],a))if(i[l]===void 0){if(a!=null){const d={i:a};s.push([l,d])}}else if(a==null){const d={r:!0};s.push([l,d])}else{const d={r:!0,i:a};s.push([l,d])}}),Object.entries(i).forEach(([l,a])=>{if((r[l]===void 0||r[l]===null)&&a!==void 0){const d={r:!0};s.push([l,d])}}),s.length<=2?Promise.resolve():this.submitOp(s)});m(this,"broadcastMessage",async e=>{const o={type:"custom",data:e,clientId:this.client.clientId};this.localPresence&&this.localPresence.submit(o)});m(this,"data",()=>this.doc.data);m(this,"submitOp",async e=>new Promise((o,r)=>{if(this.destroyed){ae.warn("submit op after destroyed");return}this.setStatus("dirty"),this.doc.submitOp(e,{},i=>{i?(ae.error(`invalid op, ${i.message}, ${JSON.stringify(e)}`),r(i),ae.error("Transform detected write conflict, reload editor"),this.handleReset("write conflict")):o()}),this.doc.data||(ae.error("no data after submit op, may be the submitted op is invalid"),this.handleReset(`invalid op, ${JSON.stringify(e)}`))}));m(this,"createDoc",async e=>new Promise((o,r)=>{this.doc.create(e,Zb,i=>{i?r(i):o()})}));m(this,"submitInsertChildContainer",async(e,o)=>{const r=[Ni(e),{i:o}];return this.submitOp(r)});m(this,"submitDeleteChildContainer",async e=>{const o=[Ni(e),{r:!0}];return this.submitOp(o)});m(this,"submitInsertBlock",async(e,o,r)=>{const i=[Ni(e),o,{i:r}];return this.submitOp(i)});m(this,"submitDeleteBlock",async(e,o)=>{const r=[Ni(e),o,{r:!0}];return this.submitOp(r)});m(this,"submitUpdateBlockData",async(e,o,r)=>{if(r.delete.length===0&&Object.keys(r.insert).length===0)return Promise.resolve();const i=[Ni(e),o],s=new Set(r.delete);Object.entries(r.insert).forEach(([a,d])=>{if(s.has(a)){const h={r:!0,i:d};i.push([a,h])}});const l=new Set(Object.keys(r.insert));return r.delete.forEach(a=>{if(l.has(a))return;const d={r:!0};i.push([a,d])}),Object.entries(r.insert).forEach(([a,d])=>{if(s.has(a))return;const h={i:d};i.push([a,h])}),this.submitOp(i)});m(this,"submitUpdateRichText",async(e,o,r)=>{const i=[Ni(e),o,"text",{e:r,et:"rich-text"}];return this.submitOp(i)});m(this,"handleOp",(e,o,r)=>{if(this.destroyed){ae.warn("handleOp: destroyed");return}qb(e,this,!!o)});this.client=e,this.doc=o,this.doc.preventCompose=!0,this.disableLogout=r,this.registerCallback(this.remoteCaretHandler)}beginBatchUpdate(){return this.doc.preventCompose=!1,this.batching++,this.batching}endBatchUpdate(){return this.batching--,g(ae,this.batching>=0,"invalid call beginBatchUpdate/endBatchUpdate"),this.batching===0&&(this.doc.preventCompose=!0),this.batching}static async load(e){try{const o=new XS(e.auth,e.serverUrl,e.reauthFunc),r=await o.getDoc(),i=new Xa(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||tL())}return await i.initPresence(),await i.subscribe(),i.initEvents(),i}catch(o){throw ae.error(o),ae.error(`failed to load doc: ${JSON.stringify(o)}`),o}}setStatus(e){this.status!==e&&(this.status=e,this.callbacks.forEach(o=>{var r;return(r=o.onStatusChanged)==null?void 0:r.call(o,e)}))}initEvents(){this.doc.on("nothing pending",this.handleNothingPending),this.doc.on("create",this.handleCreate),this.doc.on("del",this.handleDel),this.client.onWriteConflictError(this.handleWriteConflictError)}clearEvents(){this.doc.off("nothing pending",this.handleNothingPending),this.doc.off("create",this.handleCreate),this.doc.off("del",this.handleDel)}initPresence(){return new Promise((e,o)=>{if(this.localPresence)e();else{const r=this.doc.connection.getPresence(`${this.doc.collection}:${this.doc.id}`);r.on("receive",(i,s)=>{this.onCustomMessage(s)}),r.subscribe(i=>{i?o(i):(this.localPresence=r.create(K()),e())})}})}subscribe(){return new Promise((e,o)=>{this.doc.subscribe(r=>{r?o(r):(this.doc.on("op",this.handleOp),e())})})}toJSON(){return Ua(this.data())}getContainerBlocks(e){const o=this.data();g(ae,o,"no doc data");const r=o[Ni(e)];return g(ae,r,`no container data: ${e}`),mt.default(r)}getBlockData(e,o){const r=this.data();g(ae,r,"no doc data");const i=r[Ni(e)];g(ae,i,`no container data: ${e}`);const s=i[o];return g(ae,s,`no block data: ${o}`),mt.default(s)}localInsertBlock(e,o,r){return this.submitInsertBlock(e,o,r),this.getBlockData(e,o)}localDeleteBlock(e,o){const r=this.getBlockData(e,o);return this.submitDeleteBlock(e,o),r}localUpdateBlockText(e,o,r){const i=this.getBlockData(e,o);g(ae,i.text,"no block text");const s=mt.default(i.text);this.submitUpdateRichText(e,o,r);const l=ln.apply(s,r);return g(ae,l,"no block text"),l}localUpdateBlockData(e,o,r){const i=mt.default(this.getBlockData(e,o));return this.submitUpdateBlockData(e,o,r),i}localInsertChildContainer(e,o){this.submitInsertChildContainer(e,o)}localDeleteChildContainers(e){this.beginBatchUpdate(),e.forEach(o=>{this.submitDeleteChildContainer(o)}),this.endBatchUpdate()}getComments(){return Object.values(this.data().comments).map(o=>Gb(o))}getComment(e){return this.data().comments[e]}getCommentDoc(e){const o=this.data().comments[e];return pp(o)}localCreateComment(e,o){const r=Cp(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=Cp(e,o),i=["comments",e.id,{r:!0,i:r}];return this.submitOp(i)}destroy(){var e;this.destroyed=!0,this.clearEvents(),this.clearCallbacks(),this.doc.destroy(),(e=this.localPresence)==null||e.destroy(),this.client.close(!this.disableLogout),this.remoteCaretHandler.destroy()}onDeleteBlock(e,o,r){g(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(i=>{var s;return(s=i.onDeleteBlock)==null?void 0:s.call(i,Kl(e),o,r)})}onInsertBlock(e,o,r,i){g(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onInsertBlock)==null?void 0:l.call(s,Kl(e),o,r,i)})}onUpdateBlockData(e,o,r,i){g(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockData)==null?void 0:l.call(s,Kl(e),o,r,i)})}onUpdateBlockText(e,o,r,i){g(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(s=>{var l;return(l=s.onUpdateBlockText)==null?void 0:l.call(s,Kl(e),o,r,i)})}onDeleteContainer(e,o){g(ae,this.callbacks.length>0,"no callbacks"),g(ae,e!=="root","should not delete root container in doc"),this.callbacks.forEach(r=>{var i;return(i=r.onDeleteChildContainer)==null?void 0:i.call(r,Kl(e),o)})}onCreateContainer(e,o,r){g(ae,this.callbacks.length>0,"no callbacks"),g(ae,e!=="root","should not create root container in doc"),this.callbacks.forEach(i=>{var s;return(s=i.onInsertChildContainer)==null?void 0:s.call(i,Kl(e),o,r)})}onDeleteComment(e,o){g(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(r=>{var i;return(i=r.onDeleteComment)==null?void 0:i.call(r,e,o)})}onCreateComment(e,o){g(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(r=>{var i;return(i=r.onCreateComment)==null?void 0:i.call(r,e,o)})}onUpdateComment(e,o){g(ae,this.callbacks.length>0,"no callbacks"),this.callbacks.forEach(r=>{var i;return(i=r.onUpdateComment)==null?void 0:i.call(r,e,o)})}onCustomMessage(e){const o=e;(o==null?void 0:o.type)==="custom"&&(o==null?void 0:o.clientId)!==this.client.clientId?this.callbacks.forEach(r=>{var i;return(i=r.onCustomMessage)==null?void 0:i.call(r,o.data)}):(o==null?void 0:o.type)==="onlineUsers"&&setTimeout(()=>{const r={type:"custom",data:e,clientId:"-"};this.onCustomMessage(r)})}async addResources(e){return await this.client.getFileUrlsByHashes(e)}async uploadResource(e,o){var i;return{resourceId:await this.client.uploadResource(e,(i=o==null?void 0:o.onProgress)!=null?i:()=>{})}}buildResourceUrl(e,o){return this.client.buildResourceUrl(e,o)}request(e,o){return this.client.request(e,o)}getUser(){const e=this.client.clientId,{permission:o,userId:r,displayName:i,avatarUrl:s}=this.client.auth;return{permission:o,clientId:e,userId:r,displayName:i,avatarUrl:s,rainbowIndex:0}}getRemoteUsers(){return this.remoteCaretHandler.remoteUsers}getVersionHelper(){return this}getVersions(){return this.client.getVersions()}async getVersion(e){const o=await this.client.getVersion(e);return Ua(o)}async getLatestVersion(){const e=await this.client.getLatestVersion();return Ua(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:Ua(r),historyData:s}}async getVersionData(e,o){const{doc:r,ops:i}=await this.client.getVersionOps(e,o);return{doc:Ua(r),versionData:i}}async updateVersionExtra(e,o,r){await this.client.updateVersionExtra(e,o,r)}revertVersion(e){return this.client.revertVersion(e)}createVersion(e,o){return this.client.createVersion(e,o)}async recognizeLink(e){return this.client.recognizeLink(e)}parseHistoryData(e,o){qb(e.data.op,o,!0)}getServerMeta(){return{appId:this.client.auth.appId,docId:this.client.auth.docId,serverId:this.client.apiServer()}}}S("remote-cursor");class Qb{constructor(t){m(this,"handleDocSelectionChange",()=>{this.broadcastCaretPos()});m(this,"broadcastCaretPos",Le.default(()=>{const t={type:"caret",userId:this.editor.doc.getUser().userId,range:this.editor.selection.range.toDocRange()};this.editor.doc.broadcastMessage(t)},300));m(this,"handleRemoteCaretsChanged",t=>{t.forEach(e=>{const o=this.editor.findBlockById(e);o&&this.editor.reloadBlock(o)})});this.editor=t,this.editor.addListener("selectionChanged",this.handleDocSelectionChange),this.editor.doc.getRemoteUsers().addListener("remote-carets-change",this.handleRemoteCaretsChanged)}destroy(){this.editor.removeListener("selectionChanged",this.handleDocSelectionChange),this.editor.doc.getRemoteUsers().removeListener("remote-carets-change",this.handleRemoteCaretsChanged)}}const Yb=S("remote-cursor-decorator");class Ap{decorateText(t,e,o){const r=t.doc.getRemoteUsers();if(!r)return{};const i=new Map,{containerId:s,blockIndex:l}=e[e.length-1];g(Yb,typeof s=="string","invalid path containerId"),g(Yb,typeof l=="number","invalid path blockIndex");const a=t.doc.getBlockData(s,l),d=rn(o);return r.getSimpleCursors(a.id).forEach((p,A)=>{A>d&&(A=d);const v=p.map(D=>({id:K(),type:"remote-cursor",name:D.user.displayName,time:D.time,rainbowIndex:D.user.rainbowIndex})),B=i.get(A);B?B.push(...v):i.set(A,v)}),{insertions:i}}}class Jb extends ye.TypedEmitter{constructor(t){super(),this.editor=t,this.editor.doc.registerCallback(this)}handleChild(t,e,o){if(Yt(jr(this.editor,t)))return;const r=this.editor.getBlockByIndex(t,e),i=et(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 cL(n,t){n.addCustom("child-block-tracker",()=>new Jb(n)).addListener("change",t)}function aL(n,t){n.addCustom("child-block-tracker",()=>new Jb(n)).removeListener("change",t)}const dnt="",uL={colorPalette:{colorDesc:"\u5B57\u4F53\u989C\u8272",name:"\u6587\u672C\u989C\u8272",backgroundDesc:"\u80CC\u666F\u989C\u8272",reset:"\u6062\u590D\u9ED8\u8BA4"},search:{emptyTips:"\u6682\u65E0\u641C\u7D22\u7ED3\u679C"}},dL={colorPalette:{colorDesc:"Text color",name:"Text color",backgroundDesc:"Background color",reset:"Restore default values"},search:{emptyTips:"No results found"}},hL={colorPalette:{colorDesc:"\u30D5\u30A9\u30F3\u30C8\u306E\u8272",name:"\u30C6\u30AD\u30B9\u30C8\u306E\u8272",backgroundDesc:"\u80CC\u666F\u8272",reset:"\u30C7\u30D5\u30A9\u30EB\u30C8\u306B\u623B\u3059"},search:{emptyTips:"\u691C\u7D22\u7D50\u679C\u304C\u3042\u308A\u307E\u305B\u3093"}};R.mergeLang({"zh-CN":uL,"en-US":dL,"js-JP":hL});const hnt="";S("button");function uo(n,t,e,o,r){const i=w("button",["editor-button"],null);return i.setAttribute("data-button-id",n),r&&i.setAttribute(`data-editor-tooltip-${r}`,t),e?typeof e=="string"?e.startsWith("<")?i.innerHTML=e:i.innerText=e:i.appendChild(e):i.innerText=t,o&&(o.indexOf("checked")!==-1&&W(i,"checked"),o.indexOf("disabled")!==-1&&(i.disabled=!0),o.indexOf("primary")!==-1&&W(i,"primary")),i}function Kb(n,t,e){e?n.setAttribute(`data-editor-tooltip-${e}`,t):n.innerText=t}const fnt="",ec=S("ui-command-bar-base"),fL={itemElementTag:"div",tippyArrow:!1},J2=class extends ye.TypedEmitter{constructor(e,o,r){var i,s;super();m(this,"content");m(this,"items");m(this,"subBar",null);m(this,"parentItem",null);m(this,"closeable",null);m(this,"closeReason",null);m(this,"options");m(this,"id");m(this,"header",null);m(this,"footer",null);m(this,"handleDocumentKeydown",e=>{if(!!this.isVisible&&!e.isComposing&&!Ss(e.target)){if(this.subBar){this.subBar.handleDocumentKeydown(e);return}if(this.items.length!==0){if(e.key==="Escape"){this.close("cancelBar");return}if(e.key==="ArrowUp"){const o=this.getPrevItemIndex(this.getSelectedItemIndex());this.startPauseMouseEnter(),this.selectItem(this.items[o].id),e.preventDefault(),e.stopPropagation()}else if(e.key==="ArrowDown"){const o=this.getNextItemIndex(this.getSelectedItemIndex());this.startPauseMouseEnter(),this.selectItem(this.items[o].id),e.preventDefault(),e.stopPropagation()}else if(e.key==="ArrowRight"){const o=this.getSelectedItem();o&&o.children&&this.showSubCommandBar(o.childrenMenuId)}else if(e.key==="ArrowLeft")this.parentItem&&this.close("switchItem");else if(e.key==="Enter"){const o=this.getSelectedItemIndex();if(o===-1)return;const r=this.items[o],i=this.getItemElementById(r.id);i&&this.emit("click",this,r,i)}}}});m(this,"handleDocumentMouseDown",e=>{if(e.target instanceof Element&&!this.isInCommandBar(e.target)){const o=this.listeners("closing");for(let r=0;r<o.length;r++)if(o[r](this,e)===!1)return;this.close("clickBackground")}});m(this,"handleHidden",()=>{this.closeReason!=="fromHover"&&this.emit("close",this),this.close(null),BC(this.id)});m(this,"handleShow",()=>{this.popper&&(this.popper.setAttribute("data-command-bar-id",this.id),this.options.classes&&W(this.popper,...this.options.classes),this.options.refuseOverflow&&this.popper.classList.add("reference-hidden")),this.emit("show",this),this.options.disablePageScroll&&wC(this.id)});m(this,"lastEnterPauseTime",0);m(this,"startPauseMouseEnter",()=>{this.lastEnterPauseTime=Date.now()});m(this,"handleItemMouseEnter",e=>{if(Date.now()-this.lastEnterPauseTime<100)return;const o=this.getParentCommandItemElement(e.target);if(!o)return;const r=this.getItemElementId(o),i=this.getItemById(r);if(this.selectItem(r),i.manualShowChildren)return;const s=i.childrenMenuId||"";this.showSubCommandBar(s)});m(this,"handleItemMouseLeave",e=>{var r,i;const o=this.getParentCommandItemElement(e.target);!o||((i=(r=this.subBar)==null?void 0:r.parentItem)==null?void 0:i.id)!==this.getItemElementId(o)&&(ot(o,"selected"),this.emit("selectionChange",this,""))});m(this,"handleItemClick",e=>{const o=this.getParentCommandItemElement(e.target);if(!o)return;const r=this.getItemElementId(o),i=this.items.find(s=>s.id===r);if(!!i&&!(i.states&&i.states.indexOf("disabled")!==-1)){if(i.children&&i.children.length>0&&i.manualShowChildren){this.showSubCommandBar(i.childrenMenuId);return}i.element||(this.emit("click",this,i,o),this.options.autoClose&&this.close("clickItem"))}});m(this,"handleWheel",e=>{if(!this.options.disablePageScroll&&!document.querySelector(".editor-disable-scroll"))return;const o=e.target;if(!o||!(o instanceof Node))return;const r=o instanceof HTMLElement?o:o.parentElement;if(!r)return;const i=ro(r);if(!Xt(this.content,i)){e.stopPropagation(),e.preventDefault();return}e.deltaY<0?i.scrollTop===0&&(e.stopPropagation(),e.preventDefault()):e.deltaY>0&&i.scrollTop+i.clientHeight>=i.scrollHeight&&(e.stopPropagation(),e.preventDefault())});this.id=(i=r==null?void 0:r.id)!=null?i:K(),this.options={...fL,...r},this.items=e,this.parentItem=(s=r==null?void 0:r.parentItem)!=null?s:null,this.closeable=o!=null?o:null,this.content=this.createCommandBarContent(e)}close(e){this.closeReason=e,this.subBar&&this.subBar.close(e),document.removeEventListener("keydown",this.handleDocumentKeydown),document.removeEventListener("mousedown",this.handleDocumentMouseDown)}click(e,o){this.emit("click",this,e,o)}createPopperOptions(){var r,i;const e={modifiers:[]},o=this.options.overflowBoundary;return o&&((r=e==null?void 0:e.modifiers)==null||r.push({name:"flip",options:{boundary:o,fallbackPlacements:["top","bottom"]}})),this.options.padding&&((i=e==null?void 0:e.modifiers)==null||i.push({name:"preventOverflow",options:{padding:this.options.padding}})),e}destroy(){var e;this.close(null),this.removeAllListeners(),(e=this.subBar)==null||e.destroy(),this.subBar=null,this.closeable=null,this.content.removeEventListener("wheel",this.handleWheel)}get isSubCommandBar(){return!!this.parentItem}updateItems(e){var r;this.subBar&&e.findIndex(s=>{var l,a;return s.id===((a=(l=this.subBar)==null?void 0:l.parentItem)==null?void 0:a.id)})===-1&&((r=this.subBar)==null||r.destroy(),this.subBar=null),this.items=e;const o=this.createCommandBarContent(e);this.content.innerHTML="",Array.from(o.children).forEach(i=>{this.content.appendChild(i)})}get popper(){return this.content.closest("[data-tippy-root]")}getSelectedItemIndex(){const e=this.getSelectedItem();return e?this.items.indexOf(e):-1}getPrevItemIndex(e){if(e<=0)return this.items.length-1;let o=e-1;for(;;){const r=this.items[o],i=r.type,l=!(r.states&&r.states.indexOf("disabled")!==-1);if(i!=="separator"&&i!=="section"&&l)return o;if(o-=1,o<=0)return this.items.length-1}}getNextItemIndex(e){let o=e+1;for(;;){if(!this.items[o])return this.getNextItemIndex(-1);const r=this.items[o],i=r.type,l=!(r.states&&r.states.indexOf("disabled")!==-1);if(i!=="separator"&&i!=="section"&&l)return o;if(o+=1,o>this.items.length-1)return 0}}clearSelectedItem(){const e=this.getSelectedItem();if(!e)return;const o=this.getItemElementById(e.id);o&&ot(o,"selected")}selectItem(e){const o=this.getSelectedItem();if(o){if(o.id===e)return;const i=o.id,s=this.getItemElementById(i);s&&ot(s,"selected")}const r=this.getItemElementById(e);r?(W(r,"selected"),this.emit("selectionChange",this,r.getAttribute("data-id")||""),r.scrollIntoView({block:"nearest"})):this.emit("selectionChange",this,"")}showSubCommandBar(e){var s,l;const o=this.getSelectedItem();if(!o)return;if(this.subBar){if(((s=this.subBar.parentItem)==null?void 0:s.id)===o.id){o.manualShowChildren&&this.subBar.close("switchItem");return}this.subBar.destroy(),this.subBar=null}if(!o.children)return;const r=this.getItemElementById(o.id);if(!r)return;const i=J2.createSubCommandBar(o,(l=this.closeable)!=null?l:this,e?{id:e}:{});this.subBar=i,this.subBar.on("click",(a,d,h)=>{this.emit("click",a,d,h)}),this.subBar.on("close",()=>{var a;(a=this.subBar)==null||a.destroy(),this.subBar=null,ot(r,"active")}),o.beforePopup&&o.beforePopup(i),this.subBar.manualShow(r,this.getSubBarOptions(o)),W(r,"active")}isInCommandBar(e){if(!e||!(e instanceof Node))return!1;const o=this.getCommandBarRoot();return o&&Xt(o,e)||Xt(this.content,e)?!0:this.subBar?this.subBar.isInCommandBar(e):!1}createCommandItem(e){var i,s,l,a;let o=(i=this.options.itemElementTag)!=null?i:"div";e.element&&(o="div");const r=w(o,["command-item"],null);return r.setAttribute("data-id",e.id),e.type==="separator"?r.classList.add("separator"):e.type==="section"?(r.classList.add("section","text"),e.element&&(typeof e.element=="function"?r.appendChild(e.element(e)):r.appendChild(e.element))):((s=e.states)!=null&&s.includes("selected")&&r.classList.add("selected"),(l=e.states)!=null&&l.includes("checked")&&r.classList.add("checked"),(a=e.states)!=null&&a.includes("disabled")&&r.classList.add("disabled"),r.onclick=this.handleItemClick,r.onmouseenter=this.handleItemMouseEnter,r.onmouseleave=this.handleItemMouseLeave,e.element?typeof e.element=="function"?r.appendChild(e.element(e)):r.appendChild(e.element):r.classList.add("standard")),this.initItemElement(e,r),r}getItemById(e){const o=this.items.find(r=>r.id===e);return g(ec,o,`can not find command item for id: ${e}`),o}getSelectedItem(){const e=this.content.querySelector(":scope >.editor-command-bar >.command-item.selected");if(e){const o=this.getItemElementId(e),r=this.items.find(i=>i.id===o);return g(ec,r,`can not find command item for id: ${o}`),r}return null}getItemElementId(e){const o=e.getAttribute("data-id");return g(ec,o,"no data-id attribute"),o}getItemElementById(e){const o=this.content.querySelector(`:scope >.editor-command-bar > .command-item[data-id="${e}"]`);return g(ec,o,`no exists command item, id=${e}`),o}getParentCommandItemElement(e){if(!e||!(e instanceof Element))return null;if(xt(e,"command-item"))return e;const o=e.closest(".command-item");return o||null}createCommandBarContent(e){this.content&&this.content.removeEventListener("wheel",this.handleWheel);const o=w("div",["editor-command-bar-root"],null);if(this.options.header){const i=w("div",["editor-command-bar-header"],null);if(this.options.header instanceof Function){const s=this.options.header();s&&i.appendChild(s)}else i.appendChild(this.options.header);this.header=i,this.header&&o.appendChild(this.header)}const r=w("div",["editor-command-bar"],o);if(e.forEach(i=>{var l;const s=this.createCommandItem(i);r.appendChild(s),i.element&&i.setCloseable&&i.setCloseable((l=this.closeable)!=null?l:this)}),this.options.footer){const i=w("div",["menu-item","editor-command-bar","footer"],null);if(this.options.footer instanceof Function){const s=this.options.footer();s&&i.appendChild(s)}else i.appendChild(this.options.footer);this.footer=i,this.footer&&o.appendChild(this.footer)}return(this.options.header||this.options.footer)&&W(o,"scrollable-bar"),this.initCommandBarElement(r),o.addEventListener("wheel",this.handleWheel,{passive:!1}),o}getSubBarOptions(e){var o;return{placement:(o=e.childrenPlacement)!=null?o:"right-start"}}static registerManualCommandBar(e,o){this.commandBarCreators.set(e,o)}static createSubCommandBar(e,o,r){var l;g(ec,e.children&&e.children.length>0,"no item children");const i=(l=e.childrenType)!=null?l:"menu",s=this.commandBarCreators.get(i);return g(ec,s,`no creator for command type: ${i}`),s(e,o,r)}static hasExistsCommandBar(){return!!document.querySelector("[data-command-bar-id]")}};let ji=J2;m(ji,"commandBarCreators",new Map),S("ui-command-bar");class Zh extends ji{constructor(){super(...arguments);m(this,"tippyInstance",null)}manualShow(e,o){var r,i;if(!this.isVisible){if(this.tippyInstance&&(this.tippyInstance.destroy(),this.tippyInstance=null),this.tippyInstance=qB.default(e,{interactive:!0,content:this.content,trigger:"manual",triggerTarget:null,hideOnClick:!1,placement:(r=o==null?void 0:o.placement)!=null?r:"bottom-start",maxWidth:650,arrow:this.options.tippyArrow,appendTo:document.body,onShow:this.handleShow,onHidden:this.handleHidden,theme:o==null?void 0:o.theme,getReferenceClientRect:o==null?void 0:o.getReferenceClientRect,offset:(i=o==null?void 0:o.offset)!=null?i:[0,0],popperOptions:this.createPopperOptions()}),o!=null&&o.point){const{x:s,y:l}=o.point;this.tippyInstance.setProps({getReferenceClientRect:()=>new DOMRect(s,l,0,0)})}this.clearSelectedItem(),this.tippyInstance.show(),this.parentItem||(document.addEventListener("keydown",this.handleDocumentKeydown),document.addEventListener("mousedown",this.handleDocumentMouseDown)),this.popper&&this.options.id&&this.popper.setAttribute("data-command-bar-id",this.options.id)}}close(e){var o;super.close(e),this.isVisible&&((o=this.tippyInstance)==null||o.hide())}destroy(){var e;(e=this.tippyInstance)==null||e.destroy(),this.tippyInstance=null,super.destroy()}getCommandBarRoot(){return this.content.closest("[data-tippy-root]")}get isVisible(){var e,o;return(o=(e=this.tippyInstance)==null?void 0:e.state.isVisible)!=null?o:!1}get popper(){return this.content.closest("[data-tippy-root]")}}const Xb=S("ui-base");class tu extends Zh{constructor(t,e){var i;const r=[{id:(i=e==null?void 0:e.id)!=null?i:`popup-${K()}`,name:"",element:t}];super(r,void 0,{disablePageScroll:!0})}initCommandBarElement(t){W(t,"popper")}initItemElement(t,e){}get popupContent(){const t=this.items[0];g(Xb,t,"no dialog item");const e=typeof t.element=="function"?t.element(t):t.element;return g(Xb,e,"no item element"),e}}const Ui=S("filterable-list");function tv(n){var e,o;const t=w("div",["list-item"],null);return t.setAttribute("data-id",n.id),t.appendChild(w("div",["list-item-text"],null,n.name)),(e=n.states)!=null&&e.includes("selected")&&W(t,"selected"),(o=n.states)!=null&&o.includes("disabled")&&W(t,"disabled"),t}function ev(n){const t=w("div",["list-root"],null);return n.forEach(e=>{t.appendChild(tv(e))}),n.length||t.appendChild(tv({id:"placeholder",states:["disabled"],name:R.t("search.emptyTips")})),t}function nv(n,t){let e=n;return t&&(e=n.map(o=>({...o,states:o.id===t?["selected"]:void 0}))),e}function mL(n,t){const e=w("div",["filterable-list"],null),o=w("div",["filter"],e),r=w("div",["filter-container"],o),i=w("input",["filter-input"],r);t&&t.placeholder&&(i.placeholder=t.placeholder);const s=w("div",["list"],e),l=ev(nv(n,t==null?void 0:t.initialSelectedId));return s.appendChild(l),e}function ov(n,t,e){const o=n.querySelector(".list");g(Ui,o,"no list root");const r=ev(nv(t,e)),i=o.querySelector(".list-root");if(g(Ui,i,"no exists menu"),Ca(i,r),e){const s=o.querySelector(".list-item.selected");s&&(g(Ui,s,"no selected menu item"),s.scrollIntoView({block:"nearest"}))}}class gL{constructor(t,e){m(this,"root");m(this,"visibleItems");m(this,"selectedId");m(this,"filter","");m(this,"onSelected",null);m(this,"handleKeydown",t=>{this.processKeyDown(t)});m(this,"handleInputChanged",()=>{const t=this.root.querySelector(".filter-input");g(Ui,t,"no input");const e=t.value.toLocaleLowerCase();this.setFilter(e)});m(this,"handleClick",t=>{this.processClick(t)});var o;this.items=t,this.options=e,this.root=mL(t,e),this.bindEvents(),this.selectedId=(o=e==null?void 0:e.initialSelectedId)!=null?o:"",this.visibleItems=t}bindEvents(){const t=this.root.querySelector(".filter-input");g(Ui,t,"no input"),t.addEventListener("keyup",this.handleInputChanged),t.addEventListener("keydown",this.handleKeydown),this.root.addEventListener("click",this.handleClick)}unbindEvents(){const t=this.root.querySelector(".filter-input");g(Ui,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,ov(this.root,this.visibleItems,t)}focus(){const t=this.root.querySelector(".filter-input");g(Ui,t,"no input"),t.focus()}reset(){this.setFilter("");const t=this.root.querySelector(".filter-input");g(Ui,t,"no input"),t.value=""}setFilter(t){this.filter!==t&&(this.filter=t,this.visibleItems=this.items.filter(e=>e.name.toLocaleLowerCase().includes(t)),ov(this.root,this.visibleItems,this.selectedId))}processClick(t){var s,l;const e=t.target;if(!(e instanceof HTMLElement))return;const o=e.closest(".list-item");if(!o)return;const r=(s=o.getAttribute("data-id"))!=null?s:"",i=(l=this.visibleItems.find(a=>a.id===r))!=null?l:null;this.onSelected&&this.onSelected(this,i)}processKeyDown(t){var e;if(t.key==="ArrowUp"){let o=this.getSelectedIndex();o===-1?o=this.visibleItems.length-1:o>0&&(o-=1);let r="";o!==-1&&(r=this.visibleItems[o].id),this.setSelectedId(r);return}if(t.key==="ArrowDown"){let o=this.getSelectedIndex();o===-1?o=0:o<this.visibleItems.length-1&&(o+=1);let r="";o!==-1&&(r=this.visibleItems[o].id),this.setSelectedId(r);return}if(t.key==="Enter"){const o=(e=this.visibleItems.find(r=>r.id===this.selectedId))!=null?e:null;this.onSelected&&this.onSelected(this,o)}}}class pL extends gL{constructor(e,o,r){super(e,r);m(this,"popup");m(this,"onShow",null);m(this,"onHide",null);m(this,"custom",null);m(this,"handleShow",()=>{this.onShow&&this.onShow(this)});m(this,"handleHide",()=>{this.onHide&&this.onHide(this)});m(this,"handleShown",()=>{this.focus()});this.popup=new tu(this.root)}destroy(){super.destroy(),this.onShow=null,this.onHide=null}show(e){this.reset(),this.popup.manualShow(e,{theme:"dropdown-list"}),this.focus()}processKeyDown(e){super.processKeyDown(e),(e.key==="Esc"||e.key==="Enter")&&this.popup.close("cancelBar")}processClick(e){super.processClick(e);const o=e.target;!(o instanceof HTMLElement)||!o.closest(".list-item")||this.popup.close("clickItem")}}const mnt="",gnt="";function CL(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 rv=`<?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">
|
|
@@ -373,7 +373,7 @@ xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24">
|
|
|
373
373
|
<path d="M12 21L12 12" stroke="#C7C7C7" stroke-width="3"/>
|
|
374
374
|
<rect x="7.5" y="3" width="9" height="9" rx="3" stroke="#C7C7C7" stroke-width="3"/>
|
|
375
375
|
</svg>
|
|
376
|
-
`;function sM(n,t){var e,o;if(W(t,"menu-item"),!n.element){if(n.type==="section"){const r=w("div",["section-name"],null,n.name);t.appendChild(r)}else if(n.type!=="separator"){if(n.icon){const s=w("div",["menu-item-icon"],null);n.icon&&(s.innerHTML=n.icon),t.appendChild(s)}const r=w("div",["menu-item-name","text"],null),i=w("span",[],r,n.name);if(n.ellipsisTooltip&&(i.setAttribute("data-editor-tooltip-allow-markdown","true"),i.setAttribute("data-editor-tooltip-offset-y","25"),i.setAttribute("data-editor-tooltip-placement","right"),i.setAttribute("data-editor-tooltip-common",`<div style="word-break: break-word;">${n.ellipsisTooltip}</div>`)),((e=n.states)==null?void 0:e.includes("disabled"))&&n.disableReason&&(i.setAttribute("data-editor-tooltip-offset-y","25"),i.setAttribute("data-editor-tooltip-maxwidth","800"),i.setAttribute("data-editor-tooltip-placement","right"),i.setAttribute("data-editor-tooltip-common",n.disableReason)),t.appendChild(r),n.subText&&w("div",["item-subtext","text"],t,n.subText),n.children&&!n.element){const s=w("div",["menu-item-sub-indicator"],null);s.innerHTML=lv,t.appendChild(s)}if((o=n.states)!=null&&o.includes("checked")){const s=w("div",["menu-item-checked-icon"],null);s.innerHTML=PL,t.appendChild(s)}}}}class zs extends Zh{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){W(t,"menu")}initItemElement(t,e){sM(t,e)}}function lM(n,t,e){var o;return new zs((o=n.children)!=null?o:[],t,{...e,parentItem:n})}function Av(n,t,e){t.setAttribute("data-button-id",n.id),e.tooltipId&&n.name&&!n.disableTooltip&&(t.setAttribute(`data-editor-tooltip-${e.tooltipId}`,n.name),n.desc&&t.setAttribute(`data-editor-tooltip-desc-${e.tooltipId}`,n.desc));const o=t;if(!n.element)if(n.icon){const r=w("span",["toolbar-item-icon-container"],o);n.icon.trim().startsWith("<")?r.innerHTML=n.icon:r.innerText=n.icon}else{const r=w("span",["toolbar-item-name-container"],o);r.innerText=n.name}if(n.dropdown){t.setAttribute("data-dropdown","true");const r=w("span",["toolbar-item-dropdown-container"],o);r.innerHTML=Qh}n.states&&(n.states.indexOf("checked")!==-1&&W(o,"checked"),n.states.indexOf("disabled")!==-1&&(o.disabled=!0))}class ru extends Zh{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),a=this.content.getBoundingClientRect(),d=s.getBoundingClientRect();return new DOMRect(d.left,a.top,d.width,a.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){W(t,"toolbar")}initItemElement(t,e){Av(t,e,this.options)}}function cM(n,t,e){var o;return new ru((o=n.children)!=null?o:[],t,{...e,parentItem:n})}class aM extends ji{constructor(t,e,o){super(e,void 0,o),t.appendChild(this.content),document.addEventListener("keydown",this.handleDocumentKeydown),document.addEventListener("mousedown",this.handleDocumentMouseDown)}initCommandBarElement(t){W(t,"toolbar","fixed")}initItemElement(t,e){Av(t,e,this.options)}close(){this.clearSelectedItem(),this.subBar&&(this.subBar.close("cancelBar"),this.subBar=null)}destroy(){this.content.remove(),super.destroy(),document.removeEventListener("keydown",this.handleDocumentKeydown),document.removeEventListener("mousedown",this.handleDocumentMouseDown)}getCommandBarRoot(){return this.content.parentElement}get isVisible(){return!0}}const pnt="";ji.registerManualCommandBar("menu",lM),ji.registerManualCommandBar("toolbar",cM);const Cnt="",bv=S("ui-base");class iu extends Zh{constructor(e,o){super(iu.getCommandItems(e,o),void 0,{disablePageScroll:!0,...o});m(this,"handleDocumentMouseDown",e=>{})}initCommandBarElement(e){W(e,"dialog","manual")}initItemElement(e,o){}show(e,o){this.manualShow(e,{...o,theme:"light"})}get dialogContent(){const e=this.items[0];g(bv,e,"no dialog item");const o=e.element;return g(bv,o,"no item element"),o}static getCommandItems(e,o){var s;return[{id:(s=o==null?void 0:o.id)!=null?s:`manual-dialog-${K()}`,name:"",element:e}]}}const Ant="",uM=S("ui-base");class vv{constructor(t){m(this,"menu");m(this,"currentText","");m(this,"handleSearchText");m(this,"handleClick",Le.default((t,e)=>{this.options.onClickItem(this,e)},3e3,{leading:!0,trailing:!1}));m(this,"handleShow",t=>{});m(this,"handleClose",()=>{var t,e;(e=(t=this.options).onClose)==null||e.call(t)});m(this,"handleKeydown",t=>{this.menu.handleDocumentKeydown(t)});this.options=t,this.menu=new zs([],void 0,{id:t.id,header:t.header,footer:t.footer}),this.menu.addListener("click",this.handleClick),this.menu.addListener("close",this.handleClose),this.menu.addListener("show",this.handleShow),this.options.wait?this.handleSearchText=Le.default(async e=>{this.handleSearchTextPure(e)},this.options.wait):this.handleSearchText=this.handleSearchTextPure}setItems(t){if(this.menu.updateItems(t),t.length>0){const e=t.find(o=>o.type!=="section"&&o.type!=="separator");e&&this.menu.selectItem(e.id)}}async popup(t,e){var r,i;if(!(e!=null&&e.noEvent)&&((i=(r=this.options).onShow)==null?void 0:i.call(r,this))===!1)return;this.menu.manualShow(t),this.options.placeholder&&this.showPlaceholder();const o=await this.options.queryItems(this,"");this.highlightText("",o),this.setItems(o)}showLoading(){!this.options.showLoading||(this.options.loadingElement?this.setItems([{id:"loading",name:"",element:this.options.loadingElement,states:["disabled"]}]):this.setItems([{id:"loading",name:"loading",states:["disabled"]}]))}showPlaceholder(){this.setItems([{id:"placeholder",name:"enter text to search",states:["disabled"]}])}showNoResultMessage(t){if(this.options.noResultMessage){const e={name:"",id:"placeholder",states:["disabled"]};typeof this.options.noResultMessage=="string"?e.name=this.options.noResultMessage:(this.options.noResultMessage instanceof HTMLElement||typeof this.options.noResultMessage=="function")&&(e.element=this.options.noResultMessage),this.setItems([e])}else this.setItems([{id:"placeholder",name:this.options.emptyPlaceholder||R.t("search.emptyTips"),states:["disabled"]}])}close(){this.menu.close("cancelBar")}get isVisible(){return this.menu.isVisible}destroy(){this.menu.close("cancelBar"),this.menu.removeAllListeners(),this.menu.destroy()}async handleSearchTextPure(t){this.currentText=t;const e="auto-suggest";try{await Eo.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,""),r)}finally{Eo.release(e)}}highlightText(t,e){uM.debug(`highlight menu text: ${t}`);const o=this.menu.content,r=(s,l)=>{if(!l)return s;let a="";const d=l.length,h=l.toLocaleLowerCase();let p=0;for(p=0;p<=s.length-d;p){let A=s.substring(p,p+d);if(A.toLocaleLowerCase()===h){p+=d;const v=s.charAt(p);let B=!1;A.endsWith(" ")&&(B=!0,A=A.trimEnd()),a+=`<span class="highlight">${A}${v===" "||B?" ":""}</span>`}else a+=s.charAt(p),p++}return p<s.length&&(a+=s.substring(p)),a},i=s=>{if(xt(s,"text")){const l=e==null?void 0:e.find(h=>h.id===s.getAttribute("data-id"));if(l&&l.element)return;const a=s.textContent;if(!a)return;const d=r(a,t);s.innerHTML=d;return}Array.from(s.children).forEach(i)};i(o)}}class Lp{constructor(t,e){m(this,"root");m(this,"input");m(this,"text");m(this,"dropdownIcon");m(this,"clearIcon");m(this,"autoSuggest");m(this,"labels");m(this,"items",[]);m(this,"handleClick",()=>{this.autoSuggest.popup(this.root),this.input.focus()});m(this,"handleClickItem",(t,e)=>{var o,r;(r=(o=this.options)==null?void 0:o.onClickItem)==null||r.call(o,e)});m(this,"handleInput",()=>{this.autoSuggest.handleSearchText(this.input.value),this.updatePlaceholder()});m(this,"handleClear",t=>{var e,o;this.clear(),this.autoSuggest.handleSearchText(""),t.preventDefault(),t.stopPropagation(),(o=(e=this.options)==null?void 0:e.onClear)==null||o.call(e)});m(this,"handleQueryItems",async(t,e)=>this.items.filter(r=>{var i;return(i=this.options)!=null&&i.filter?this.options.filter(r,e):!0}));m(this,"handleShow",()=>{W(this.root,"active"),this.input.focus()});m(this,"handleClose",()=>{var t,e;(e=(t=this.options)==null?void 0:t.onClose)==null||e.call(t),ot(this.root,"active")});var a,d,h,p,A;this.options=e,this.labels=(d=(a=this.options)==null?void 0:a.labels)!=null?d:[];const{root:o,input:r,text:i,clearIcon:s,dropdownIcon:l}=Lp.createDropdown(t,this.labels);this.root=o,this.input=r,this.text=i,this.clearIcon=s,this.dropdownIcon=l,this.autoSuggest=new vv({id:(e==null?void 0:e.popupId)||"dropdown-auto-suggest",header:(h=this.options)==null?void 0:h.header,onClickItem:this.handleClickItem,queryItems:this.handleQueryItems,onClose:this.handleClose,onShow:this.handleShow,highlight:e==null?void 0:e.highlight,emptyPlaceholder:e==null?void 0:e.emptyPlaceholder}),this.items=(A=(p=this.options)==null?void 0:p.items)!=null?A:[],this.root.addEventListener("click",this.handleClick),this.input.addEventListener("input",this.handleInput),this.clearIcon.addEventListener("click",this.handleClear)}close(){this.autoSuggest.close()}destroy(){this.input.removeEventListener("input",this.handleInput),this.root.removeEventListener("click",this.handleClick),this.clearIcon.removeEventListener("click",this.handleClear),this.autoSuggest.destroy()}updateItems(t){this.items=t,this.autoSuggest.handleSearchText("")}setText(t){this.text.innerText=t,this.input.value=t,this.updatePlaceholder()}clear(){this.setText(""),this.setLabels([])}setLabels(t){this.labels=t,this.updateLabels()}static createDropdown(t,e){const o=w("div",["editor-dropdown","empty"],t),r=w("input",["dropdown-input"],o),i=w("div",["dropdown-text"],o),s=w("div",["dropdown-labels"],o);for(let d=0;d<e.length;d+=1){const h=e[d];w("span",["dropdown-label"],s,h)}const l=w("div",["dropdown-clear-icon"],o);l.innerHTML=oM;const a=w("div",["dropdown-icon"],o);return a.innerHTML=Qh,{root:o,input:r,text:i,clearIcon:l,dropdownIcon:a}}updateLabels(){const t=this.root.querySelector(".dropdown-labels");if(t){t.innerHTML="";for(let e=0;e<this.labels.length;e+=1){const o=this.labels[e];w("span",["dropdown-label"],t,o)}}}updatePlaceholder(){var t;if(this.input.value===""){const e=(t=this.options)==null?void 0:t.placeholder;e&&(this.input.placeholder=e,this.text.textContent=e),W(this.root,"empty")}else ot(this.root,"empty")}}const dM=[-1,6,0,1,2,3,4,5],hM=[-1,6,0,1,2,3,4,5,14,13,7,8,9,10,11,12],yv=S("color-palette");function kv(n,t,e,o){g(yv,n>0,"no color in palette");const r=t||1;g(yv,r>0,`invalid palette rows: ${r}`);const i=n/r,s=w("div",["palette-container",o],null);for(let l=0;l<r;l++){const a=w("div",["palette-container-row"],s);for(let d=0;d<i;d++){const h=e(l*i+d);a.appendChild(h)}}return s}function fM(n){const t=w("button",["color-button"],null),e=dM[n];return t.setAttribute("data-color-index",`${e}`),t.innerHTML=sv,t}function mM(n){const t=w("button",["background-color-button"],null),e=hM[n];return t.setAttribute("data-color-index",`${e}`),t}function gM(){const n=w("div",["clear-button-container"],null),t=w("button",["clear-button"],n);return t.innerText=R.t("colorPalette.reset"),n}function pM(n){const t=w("div",["color-palette"],null);return n.color!==!1&&(w("div",["bar-desc"],t,R.t("colorPalette.colorDesc")),t.appendChild(kv(8,1,fM,"color"))),n.backgroundColor!==!1&&(w("div",["bar-desc"],t,R.t("colorPalette.backgroundDesc")),t.appendChild(kv(16,2,mM,"background-color"))),n.clearColorButton!==!1&&t.appendChild(gM()),t}function CM(n,t,e){const o=t==="color"?"color":"background-color",r=n.querySelector(`.${o} button.selected`);r&&ot(r,"selected"),e===null&&(e=-1);const i=n.querySelector(`.${o} button[data-color-index="${e}"]`);i&&W(i,"selected")}const bnt="",AM={};class bM extends ye.TypedEmitter{constructor(e=AM){super();m(this,"root");m(this,"handleClick",e=>{const o=e.target;if(!o||!(o instanceof Element))return;const r=o.closest("button");if(!r)return;if(xt(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)||(xt(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=pM(e),this.root.addEventListener("click",this.handleClick)}destroy(){this.removeAllListeners(),this.root.removeEventListener("click",this.handleClick)}setColor(e,o){CM(this.root,e,o)}}class wv{constructor(t,e){m(this,"name","Color Palette");m(this,"element");m(this,"palette");m(this,"closeable",null);this.id=t,this.palette=new bM(e),this.element=this.palette.root}setCloseable(t){this.closeable=t}destroy(){this.palette.destroy(),this.closeable=null}}function vM(){const n=w("button",["color-button"],null);return n.innerHTML=sv,n}function Mp(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 yM extends ye.TypedEmitter{constructor(e){super();m(this,"id","text-color-item");m(this,"name",R.t("colorPalette.name"));m(this,"dropdown",!0);m(this,"manualShowChildren",!0);m(this,"children",[]);m(this,"element");m(this,"colorPaletteItem");m(this,"latestColors",[null,null]);m(this,"handlePaletteClick",(e,o)=>{this.emit("onClick",e,o),e==="color"||e==="backgroundColor"?e==="color"?this.latestColors[0]=o:this.latestColors[1]=o:this.latestColors=[null,null],Mp(this.element,this.latestColors)});m(this,"beforePopup",()=>{this.emit("beforePopup")});this.editor=e,this.colorPaletteItem=new wv("text-color-palette-item"),this.colorPaletteItem.palette.addListener("onClick",this.handlePaletteClick),this.children.push(this.colorPaletteItem),this.element=vM()}destroy(){this.colorPaletteItem.destroy()}updatePaletteColor(e){this.colorPaletteItem.palette.setColor("color",e[0]),this.colorPaletteItem.palette.setColor("backgroundColor",e[1]),this.latestColors=e,Mp(this.element,this.latestColors)}updateButtonColor(e){this.latestColors=e,Mp(this.element,this.latestColors)}}const vnt="";function Rp(n,t){const e=w("div",["editor-input-wrap"],n);t!=null&&t.className&&W(e,t==null?void 0:t.className);const o=w("div",["editor-input-label"],e);w("span",[],o,t.label),t.required&&W(o,"required");const r=w("div",["editor-input-container"],e),i=w("input",["editor-input"],r);t.placeholder&&(i.placeholder=t.placeholder),t.defaultValue&&(i.value=t.defaultValue);const s=w("div",["editor-input-error"],e);return i.addEventListener("input",l=>{var a;(a=t.onChange)==null||a.call(t,l),ot(e,"error")}),i.addEventListener("keydown",l=>{var a;(a=t.onKeyDown)==null||a.call(t,l)}),{getField:()=>i,getInputValue:()=>i.value,setFieldError:l=>{W(e,"error"),s.innerText=l},focus:()=>{setTimeout(()=>{i.focus()})}}}function Op(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}class kM extends vv{constructor(e,o){super(o);m(this,"handleClose",()=>{var e,o;Op(this.editor)&&this.editor.focus(),(o=(e=this.options).onClose)==null||o.call(e)});this.editor=e,this.editorOptions=o}async popupInEditor(e,o,r){var d,h;if(((h=(d=this.editorOptions).onShow)==null?void 0:h.call(d,this,e,o,r))===!1)return;this.options.showLoading&&this.showLoading();const i=this.editor.getBlockByIndex(e,o);if(!Xt(this.editor.rootContainer,i)||ut(this.editor,i)<r)return;const s=Nr(this.editor,i,Ce(this.editor,i,r));if(s.length===0)return;const l=s[0],a=zr(this.editor,i,"editor-auto-suggest-menu",l);super.popup(a,{noEvent:!0})}}const _p=S("auto-suggest-menu");class Fp{constructor(t,e){m(this,"order",100);m(this,"menu");m(this,"anchor",null);m(this,"close",()=>{this.menu.close()});m(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(ie(In(gn(t,i),e.offset).left).startsWith(this.anchor.leftText))return}this.menu.close()});m(this,"deleteTrigger",()=>{const t=this.editor,e=t.selection.range.start;if(!e.isSimple()||!this.anchor)return!1;const{blockId:o,offset:r}=e,i=t.getBlockById(o),s=ie(Ah(t,i,r));if(g(_p,this.anchor,"no anchor"),!s.startsWith(this.anchor.leftText))return!1;const l=this.anchor.offset-this.anchor.trigger.length,a=r-l;return t.selection.selectBlock(i,l),a&&(t.deleteTextFromBlock(i,l,a),this.anchor.offset-=this.anchor.trigger.length),this.anchor.trigger.length||this.menu.close(),!0});m(this,"onClose",()=>{var t,e;(e=(t=this.options).onClose)==null||e.call(t)});m(this,"onShow",(t,e,o,r)=>{var i;if((i=this.options)!=null&&i.onShow)return this.options.onShow(this,e,o,r)});m(this,"onClickItem",(t,e)=>{!this.anchor||(this.options.autoDeleteTrigger&&this.deleteTrigger(),this.options.onClickItem(this,e,this.anchor))});m(this,"queryItems",(t,e)=>this.options.queryItems(this,e));m(this,"renderMenuItem",(t,e)=>{var 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 kM(t,{id:e.id,showLoading:e.showLoading,loadingElement:e.loadingElement,placeholder:e.placeholder,header:e.header,footer:e.footer,wait:e.wait,noResultMessage:e.noResultMessage,highlight:e.highlight,onClose:this.onClose,onShow:this.onShow,onClickItem:this.onClickItem,queryItems:this.queryItems,renderMenuItem:this.renderMenuItem}),t.input.addHandler(this),t.addListener("selectionChanged",this.handleSelectionChanged)}handleBeforeKeyDown(t,e){var o;return!((o=this.menu)!=null&&o.isVisible)||Bm(e.key)?!1:vC(e)&&!ws(e)?(setTimeout(()=>{this.resetItems()}),!1):Em(e)?(this.menu.close(),!0):(this.menu.handleKeydown(e),!0)}popup(t,e,o,r){this.anchor={blockId:it(t),offset:e,leftText:o,trigger:r};const i=at(nt(t)),s=bt(t);this.menu.popupInEditor(i,s,e)}handleAfterInsertText(t,e,o,r,i){var h,p;const s=t.selection.range.start;if(!s.isSimple()||!this.options.enableFirstBlock&&e==="root"&&o===0)return!1;const{blockId:l,offset:a}=s,d=t.getBlockByIndex(e,o);if(it(d)!==l)return!1;if((h=this.menu)!=null&&h.isVisible)this.resetItems();else if(this.options.trigger.indexOf(i)!==-1){if(r>0&&this.options.needSpaceBeforeTrigger&&(((p=t.getBlockData(d).text)==null?void 0:p.reduce((D,x)=>D+x.insert,""))||"")[r-1]!==" "||ji.hasExistsCommandBar())return!1;const A=ie(Ah(t,d,a));this.popup(d,a,A,i)}return!1}handleUpdateCompositionText(t,e,o,r,i){var d;const s=t.selection.range.start;if(!s.isSimple())return!1;const{blockId:l}=s,a=t.getBlockByIndex(e,o);return it(a)!==l||(d=this.menu)!=null&&d.isVisible&&this.resetItems(),!1}resetItems(){var l;if(!((l=this.menu)!=null&&l.isVisible))return;const t=this.editor,e=t.selection.range.start;if(!e.isSimple())return;const{blockId:o,offset:r}=e,i=t.getBlockById(o),s=ie(Ah(t,i,r));if(g(_p,this.anchor,"no anchor"),s.startsWith(this.anchor.leftText)){const a=s.substring(this.anchor.leftText.length);_p.debug(`search text: ${a}`),this.menu.handleSearchText(a)}}destroy(){var t;this.editor.input.removeHandler(this),this.editor.removeListener("selectionChanged",this.handleSelectionChanged),(t=this.menu)==null||t.destroy()}}function wM(){const n={};for(let t=1;t<=8;t++)n[`heading-${t}`]={shortcut:`/h${t}`};return n}const BM={"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"},...wM()};function Cn(n){var t;return(t=BM[n])==null?void 0:t.shortcut}function EM(n){var t;return(t=n.subText)!=null?t:""}const hr=S("table-dom");function fr(n){return`${it(n)}_scroll`}function _e(n){const t=n.querySelector("div[data-type=table-content] >table");return g(hr,t instanceof HTMLTableElement,"invalid table"),t}function mr(n,t){const o=n.getCustom(fr(t)).contentElement.firstElementChild;g(hr,o instanceof HTMLElement,"invalid table content");let r=o.querySelector(":scope >div[data-type=table-tools]");return r||(r=w("div",[],o),r.setAttribute("data-type","table-tools"),n.domEvents.addEventListener(r,"dblclick",(i,s)=>s.stopPropagation()),n.domEvents.addEventListener(r,"click",(i,s)=>{s.detail===3&&s.stopPropagation()})),g(hr,r,"no table tools"),r}function xM(n,t){return n.findCustom(fr(t))?mr(n,t):null}function Bv(n){const t=[];return Array.from(n.rows).forEach(e=>{t.push(...Array.from(e.cells))}),t}function su(n){const t=n.querySelector(":scope div[data-type=editor-container]");return g(hr,t,"no child container in cell"),t}function IM(n){const o=Bv(n).map(r=>{const i=su(r),s=at(i),l=r.colSpan,a=r.rowSpan;return`${s}/${l}/${a}`}).join();return Pd.default(o)}function Ve(n){return Dt(n)==="table"}function Pp(n){const t=nt(n);if(Yt(t))return null;const e=et(t);return g(hr,e,"no parent block"),Ve(e)?t:Pp(e)}function Yr(n){if(Ve(n))return n;const t=nt(n);if(Yt(t))return null;const e=et(t);return g(hr,e,"no parent block"),Ve(e)?e:Yr(e)}function TM(n,t){const e=n.querySelector("colgroup");g(hr,e,"no colgroup");const o=e.children[t];return g(hr,o,"no col"),g(hr,o instanceof HTMLTableColElement,`invalid col: ${o.tagName}`),o}function Ev(n){try{return _e(n),!0}catch{return!1}}function DM(n){return te(n).querySelector(":scope > .block-helper")}function xv(n){const t=et(n.contentElement);g(hr,t,"no block");const e=DM(t);if(e){const i=Math.min(n.contentElement.offsetLeft+29,n.rootElement.scrollLeft),s=t.getBoundingClientRect().width;e.style.right=`${i+s+5}px`}}const Gn=S("doc-table-grid");class SM{constructor(t){m(this,"_cells",[]);for(let e=0;e<t;e++)this._cells.push(void 0)}cols(){return this._cells.length}setCell(t,e){g(Gn,t>=0&&t<this.cols(),`set cell, invalid col: ${t}`),this._cells[t]=e}getCell(t){g(Gn,t>=0&&t<this.cols(),`get cell, invalid col: ${t}`);const e=this._cells[t];return g(Gn,e,"get cell, no cell"),e}getCellAllowEmpty(t){return g(Gn,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 Yh{constructor(t){m(this,"_data");m(this,"_rows");this._data=t,this._rows=[];for(let e=0;e<this.rowCount;e++)this._rows.push(new SM(this.colCount));this.fillGrid(),g(Gn,t.colsWidth,"no colsWidth"),g(Gn,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;g(Gn,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 d=0;d<l;d++)for(let h=0;h<s;h++)this._rows[o+d].setCell(e+h,{col:e,row:o,containerId:r,virtual:h!==0||d!==0,colSpan:s,rowSpan:l});const a=this.getNextEmptyCell(e,o);a?(e=a.col,o=a.row):g(Gn,i===t.length-1,`invalid table data, no next empty cell: ${JSON.stringify(this._data)}`)}),this._rows.forEach(r=>{r.forEach(i=>{g(Gn,i,"no cell"),g(Gn,i.containerId,"no containerId")})})}getCell(t){const{col:e,row:o}=t,r=this._rows[o];g(Gn,r,`get cell, no row: ${o}`);const i=r.getCell(e);return g(Gn,i,`get cell, no cell: ${e}`),i}getRow(t){const e=this._rows[t];return g(Gn,e,`get row, no row: ${t}`),e}forEach(t){this._rows.forEach(t)}}const Jh=S("table-data");function LM(n){const t=n.firstElementChild;return g(Jh,t,"no child element for cell"),g(Jh,Pr(t),"cell first child is not a container"),g(Jh,Lo(t),"cell first child is not a container"),t}function MM(n){const t=et(n);g(Jh,t,"no parent block for table");const e=[],o={};Array.from(n.rows).forEach(l=>{Array.from(l.cells).forEach(a=>{const d=LM(a),h=at(d);e.push(h),(a.colSpan>1||a.rowSpan>1)&&(o[`${h}_colSpan`]=a.colSpan,o[`${h}_rowSpan`]=a.rowSpan)})});const r=n.rows.length,i=Array.from(n.rows[0].cells).map(l=>l.colSpan).reduce((l,a)=>l+a,0);return{id:it(t),type:Dt(t),rows:r,cols:i,children:e,colsWidth:Array(i).fill(100),...o}}function Vs(n){return new Yh(n)}function RM(n){return Vs(MM(n))}const We=S("table-grid"),OM=60;class _M{constructor(t,e){m(this,"containerId");m(this,"row");m(this,"col");m(this,"colSpan");m(this,"rowSpan");m(this,"virtual");m(this,"table");this.table=t,this.containerId=e.containerId,this.row=e.row,this.col=e.col,this.colSpan=e.colSpan,this.rowSpan=e.rowSpan,this.virtual=e.virtual}get cell(){const e=this.container.closest("td");return g(We,e,"no parent cell for child container"),e}get container(){const t=this.table.querySelectorAll(`[data-container-id=${this.containerId}]`);g(We,t.length===1,"containers !== 1"),g(We,Pr(t[0]),"not a container");const e=t[0];return g(We,Lo(e),"not a child container"),e}}class FM{constructor(t,e){m(this,"_cells",[]);e.forEach(o=>{this._cells.push(new _M(t,o))})}get cells(){return this._cells}getCell(t){return g(We,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 K2=class{constructor(t){m(this,"_rows",[]);this.table=t,RM(t).forEach(r=>{this._rows.push(new FM(t,r))});const o=this.colCount;this._rows.forEach(r=>{g(We,r.cells.length===o,"row.cells.length !== colCount")})}get rowCount(){return this._rows.length}get colCount(){return this._rows.length===0?0:(g(We,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 g(We,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){g(We,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){g(We,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 g(We,!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)}),g(We,o<=r,"min > max"),g(We,o>=0,"min < 0"),g(We,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)}),g(We,o<=r,"min > max"),g(We,o>=0,"min < 0"),g(We,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 v=o;v<=r;v++)for(let B=i;B<=s;B++)l.push(this.getCell({row:v,col:B}));const a=this.toRealCells(l);let d=1e4,h=1e4,p=-1,A=-1;return a.forEach(v=>{h=Math.min(v.col,h),d=Math.min(v.row,d),A=Math.max(v.col+v.colSpan-1,A),p=Math.max(v.row+v.rowSpan-1,p)}),[{row:d,col:h},{row:p,col:A}]}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),a=Math.max(i.row,s.row),d=Math.min(i.col,s.col),h=Math.max(i.col,s.col);for(let p=l;p<=a;p++)for(let A=d;A<=h;A++){const v=this.getCell({row:p,col:A});v.virtual||o.push(v)}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 g(We,o,"cell not found"),o}getCellByCellElement(t){const e=su(t);return this.getCellByContainerId(at(e))}getCellByContainerId(t){return this.getCellById(t)}static fromTable(t){const e=IM(t),o=this.caches.getSync(e,()=>(We.debug("create table grid"),new K2(t)));return o.table!==t?(this.caches.delete(e),this.fromTable(t)):o}static fromBlock(t){return this.fromTable(_e(t))}};let Tt=K2;m(Tt,"caches",new X5(OM));function Kh(n,t){Object.entries(n).forEach(([e])=>{e.startsWith(`${t}/`)&&delete n[e]})}const PM=S("table-selection-range");function Uo(n,t,e){var M,H,z,q;const o=Tt.fromBlock(n),r=t,i=e,s=o.getCellByContainerId(r.childContainerId),l=o.getCellByContainerId(i.childContainerId),a=r.custom,d=i.custom,h=(M=a==null?void 0:a.rowIndex)!=null?M:s.row,p=(H=a==null?void 0:a.colIndex)!=null?H:s.col,A=(z=d==null?void 0:d.rowIndex)!=null?z:l.row+l.rowSpan-1,v=(q=d==null?void 0:d.colIndex)!=null?q:l.col+l.colSpan-1,B=Math.min(h,A),D=Math.max(h,A),x=Math.min(p,v),_=Math.max(p,v);return{fromRow:B,toRow:D,fromCol:x,toCol:_}}function Np(n,t){const e=new Set,o=new Set,r=n.selection.range;if(!r.isSimple()&&r.start.blockId===it(t)){const i=Tt.fromBlock(t),{start:s,end:l}=r;g(PM,!s.isSimple()&&!l.isSimple(),"invalid range");const{fromCol:a,toCol:d,fromRow:h,toRow:p}=Uo(t,s,l);if(h===0&&p===i.rowCount-1)for(let A=a;A<=d;A++)o.add(A);if(a===0&&d===i.colCount-1)for(let A=h;A<=p;A++)e.add(A)}return{selectedRows:e,selectedColumns:o}}function lu(n,t){let e=null;if(t.isCollapsed()&&t.isSimple()){const o=n.getBlockById(t.start.blockId);if(Ve(o)){const r=nt(o),i=et(r);i&&(e=Yr(i))}else e=Yr(o)}else{const o=n.getBlockById(t.start.blockId),r=Yr(o),i=n.getBlockById(t.end.blockId),s=Yr(i);r===s&&(e=r)}return e}const nc=S("delete-columns");function Iv(n,t,e){const{start:o,end:r}=e;if(o.blockId!==r.blockId||e.isSimple()||n.getBlockById(o.blockId)!==t||Dt(t)!=="table")return!1;const{fromRow:s,toRow:l}=Uo(t,e.start,e.end),a=Tt.fromBlock(t);return s===0&&l===a.rowCount-1}function $p(n){const t=n.getEditor();t.undoManager.runInGroup(()=>{var H;const e=t.getBlockById(n.start.blockId);if(!Iv(t,e,n))return;if(n.isSimple()){t.deleteBlock(e);return}const{fromCol:o,toCol:r}=Uo(e,n.start,n.end),i=Tt.fromBlock(e);if(o===0&&r===i.colCount-1){t.deleteBlock(e);return}const s=new Set,l=i.map(z=>z.containerId);for(let z=0;z<l.length;z++){const q=l[z];for(let rt=o;rt<=r;rt++){const ft=q[rt];s.add(ft)}q.splice(o,r-o+1)}const a=new Set(l.flat()),d=new Set(Array.from(s).filter(z=>!a.has(z))),h=r-o+1,p=new Map,A=new Map;s.forEach(z=>{if(d.has(z))return;const q=i.getCellByContainerId(z);if(g(nc,q.colSpan>1,"invalid effected cell, colSpan === 1"),q.col<o){g(nc,a.has(z),"invalid effected cell, not exists");let ne=q.col+q.colSpan-1;ne>r&&(ne=r);const qe=ne-o+1,Yn=q.colSpan-qe;p.set(z,Yn);return}g(nc,q.col<=r,"invalid effected cell, col > endCol");const rt=q.col,ft=q.col+q.colSpan-1,Bt=q.col-o,jt=ft-rt+1-h+Bt;g(nc,jt>0,"invalid effected cell, newSpanned <= 0");const Ut=qr(t.doc);A.set(z,{newContainerId:Ut,colSpan:jt})});for(let z=0;z<l.length;z++){const q=l[z];for(let rt=o;rt<q.length;rt++){const ft=q[rt],Bt=A.get(ft);Bt&&(q[rt]=Bt.newContainerId)}}const v=mt.default(t.getBlockData(e));v.colsWidth.splice(o,r-o+1),d.forEach(z=>{Kh(v,z)}),p.forEach((z,q)=>{g(nc,z>=1,"invalid modified colSpan, colSpan < 1"),z===1?v[`${q}_colSpan`]=void 0:v[`${q}_colSpan`]=z}),A.forEach((z,q)=>{Kh(v,q);const{newContainerId:rt,colSpan:ft}=z;g(nc,ft>=1,"invalid newContainerData, colSpan < 1"),ft>1&&(v[`${rt}_colSpan`]=ft);const Bt=i.getCellByContainerId(q).rowSpan;Bt>1&&(v[`${rt}_rowSpan`]=Bt)});const D=(H=l[0][o])!=null?H:l[0][o-1],x=t.getChildContainerData(D)[0],_=Tt.virtualCellContainersGridToChildren(l),M={...v,cols:v.cols-h,children:_};Vs(M),t.updateBlockData(e,M,Ce(t,x.id,0)),t.deleteChildContainers(Array.from(d)),t.deleteChildContainers(Array.from(A.keys()))})}const oc=S("delete-rows");function Tv(n,t,e){const{start:o,end:r}=e;if(o.blockId!==r.blockId||e.isSimple()||n.getBlockById(o.blockId)!==t||Dt(t)!=="table")return!1;const{fromCol:s,toCol:l}=Uo(t,e.start,e.end),a=Tt.fromBlock(t);return s===0&&l===a.colCount-1}function Hp(n){const t=n.getEditor();t.undoManager.runInGroup(()=>{const e=t.getBlockById(n.start.blockId);if(!Tv(t,e,n))return;if(n.isSimple()){t.deleteBlock(e);return}const{fromRow:o,toRow:r}=Uo(e,n.start,n.end),i=Tt.fromBlock(e);if(o===0&&r===i.rowCount-1){t.deleteBlock(e);return}const s=new Set,l=i.map(M=>M.containerId);for(let M=r;M>=o;M--)l[M].forEach(z=>s.add(z)),l.splice(M,1);const a=new Set(l.flat()),d=new Set(Array.from(s).filter(M=>!a.has(M))),h=r-o+1,p=new Map,A=new Map;s.forEach(M=>{if(d.has(M))return;const H=i.getCellByContainerId(M);if(g(oc,H.rowSpan>1,"invalid effected cell, rowSpan === 1"),H.row<o){g(oc,a.has(M),"invalid effected cell, not exists");let jt=H.row+H.rowSpan-1;jt>r&&(jt=r);const Ut=jt-o+1,ne=H.rowSpan-Ut;p.set(M,ne);return}g(oc,H.row<=r,"invalid effected cell, col > endCol");const z=H.row,q=H.row+H.rowSpan-1,rt=H.row-o,ft=q-z+1-h+rt;g(oc,ft>0,"invalid effected cell, newSpanned <= 0");const Bt=qr(t.doc);A.set(M,{newContainerId:Bt,rowSpan:ft})});for(let M=o;M<l.length;M++){const H=l[M];for(let z=0;z<H.length;z++){const q=H[z],rt=A.get(q);rt&&(H[z]=rt.newContainerId)}}const v=mt.default(t.getBlockData(e));d.forEach(M=>{Kh(v,M)}),p.forEach((M,H)=>{g(oc,M>=1,"invalid modified rowSpan, rowSpan < 1"),M===1?v[`${H}_rowSpan`]=void 0:v[`${H}_rowSpan`]=M}),A.forEach((M,H)=>{Kh(v,H);const{newContainerId:z,rowSpan:q}=M;g(oc,q>=1,"invalid newContainerData, rowSpan < 1"),q>1&&(v[`${z}_rowSpan`]=q);const rt=i.getCellByContainerId(H).colSpan;rt>1&&(v[`${z}_colSpan`]=rt)});const B=l[o]?l[o][0]:l[o-1][0],D=t.getChildContainerData(B)[0],x=Tt.virtualCellContainersGridToChildren(l),_={...v,rows:v.rows-h,children:x};Vs(_),t.updateBlockData(e,_,Ce(t,D.id,0)),t.deleteChildContainers(Array.from(d)),t.deleteChildContainers(Array.from(A.keys()))})}const cu=S("table-range");function Xh(n){g(cu,!n.isSimple(),"must be complex selection range");const{anchor:t,focus:e}=n;g(cu,!t.isSimple(),"invalid start pos type"),g(cu,!e.isSimple(),"invalid end pos type");const o=n.getEditor();g(cu,t.blockId===e.blockId,"invalid range, not same block");const r=o.getBlockById(t.blockId);g(cu,Dt(r)==="table","invalid block type, not a table block");const i=_e(r),s=Tt.fromTable(i),l=s.getCellByContainerId(t.childContainerId),a=s.getCellByContainerId(e.childContainerId),d=Math.min(l.row,a.row),h=Math.max(l.row,a.row),p=Math.min(l.col,a.col),A=Math.max(l.col,a.col),v=s.getCell({row:d,col:p}),B=s.getCell({row:h,col:A});return{editor:o,block:r,table:i,startCell:v,endCell:B,startRow:d,startCol:p,endRow:h,endCol:A}}const jp=S("split-cell");function Up(n,t,e){n.undoManager.runInGroup(()=>{const o=Tt.fromBlock(t),r=o.getRealCell(e);g(jp,!r.virtual,"should not split virtual cell"),g(jp,r.colSpan>1||r.rowSpan>1,"cell does not has span data");const i=o.getVirtualCellContainersGrid();for(let p=0;p<r.rowSpan;p++)for(let A=0;A<r.colSpan;A++){if(p===0&&A===0)continue;const v=p+r.row,B=A+r.col,D=qr(n.doc);i[v][B]=D}const s=n.getBlockData(t),l=mt.default(s);l[`${r.containerId}_colSpan`]=null,l[`${r.containerId}_rowSpan`]=null,l.children=Tt.virtualCellContainersGridToChildren(i);const d=n.getChildContainerData(r.containerId)[0];g(jp,d,"no child block");const h=Ce(n,d.id,0);Vs(l),n.updateBlockData(t,l,h)})}function NM(n,t,e){e.forEach(o=>{const r=Tt.fromBlock(t).getCell(o);(r.virtual||r.colSpan>1||r.rowSpan>1)&&Up(n,t,o)})}function Dv(n,t,e){if(e.isSimple())return!1;const{start:o,end:r}=e;if(o.blockId!==r.blockId||n.getBlockById(o.blockId)!==t||Dt(t)!=="table")return!1;const{startCell:s,endCell:l}=Xh(e);return!(s.cell!==l.cell||s.colSpan===1&&s.rowSpan===1)}function zp(n){const{editor:t,block:e,startRow:o,startCol:r,endRow:i,endCol:s}=Xh(n),l=[];for(let a=o;a<=i;a++)for(let d=r;d<=s;d++)l.push({row:a,col:d});return NM(t,e,l),!0}const rc=S("merge-cells");function Sv(n,t,e){if(e.isSimple())return!1;const{start:o,end:r}=e;if(o.blockId!==r.blockId||n.getBlockById(o.blockId)!==t||Dt(t)!=="table")return!1;const{startCell:s,endCell:l}=Xh(e);return s.cell!==l.cell}function Lv(n){const t=Xh(n),e=t.editor;e.undoManager.runInGroup(()=>{const o=t.endCell,r=o.row+o.rowSpan-1,i=o.col+o.colSpan-1,s=it(t.block);zp(n);const l=e.getBlockById(s),a=_e(l),{startRow:d,startCol:h}=t,p=mt.default(e.getBlockData(l));g(rc,p.children,"no table children");const A=Tt.fromTable(a),v=[];for(let jt=d;jt<=r;jt++)for(let Ut=h;Ut<=i;Ut++){const ne=A.getCell({row:jt,col:Ut});g(rc,!ne.virtual,"cell is virtual"),v.push(ne)}g(rc,v.length>0,"no selected cells");const B=v[0],D=v.slice(1),x=A.getCellByContainerId(B.containerId).container,_=[];D.forEach(jt=>{const Ut=A.getCellByContainerId(jt.containerId).container,ne=at(Ut);if(!Ba(e,Ut)){const qe=PA(e,ne);if(Ba(e,x)){const Yn=pe(x)[0];e.insertDocAt(x,0,qe),e.deleteBlock(Yn)}else e.insertDocAt(x,Io(x),qe)}_.push(ne)});const M=at(x),H=i-h+1,z=r-d+1;p[`${M}_colSpan`]=H,p[`${M}_rowSpan`]=z,_.forEach(jt=>{g(rc,p.children,"no table children");const Ut=p.children.indexOf(jt);g(rc,Ut>0,"no deleted container"),p.children.splice(Ut,1)});const q=p,ft=e.getChildContainerData(M)[0];g(rc,ft,"no child block");const Bt=Ce(e,ft.id,0);Vs(q),e.updateBlockData(l,q,Bt),e.deleteChildContainers(_)})}const Vp=10,$M=["table/merge-cells","table/split-cell","table/insert-column","table/insert-row","table/delete-rows","table/delete-columns","table/delete"];class Wp{constructor(){m(this,"id","TableBlockCommandProvider")}getAvailableCommands(t,e,o){if(Dt(e)!=="table")return[];const r={blockId:it(e),blockKind:Do(t,e),blockType:Dt(e)},i=[];Sv(t,e,o)&&i.push({id:"table/merge-cells",name:R.t("table.mergeCell"),icon:kL,groupIndex:Vp,...r}),Dv(t,e,o)&&i.push({id:"table/split-cell",name:R.t("table.splitCell"),icon:wL,groupIndex:Vp,...r});const s=Iv(t,e,o),l=Tv(t,e,o);return s&&l&&i.push({id:"table/delete",name:R.t("table.deleteTable"),icon:BL,groupIndex:Vp,...r}),i}executeCommand(t,e,o,r,i,s){return Dt(e)!=="table"||!new Set($M).has(r.id)?!1:r.id==="table/merge-cells"?(Lv(o),!0):r.id==="table/split-cell"?(zp(o),!0):r.id==="table/delete-columns"?($p(o),!0):r.id==="table/delete-rows"?(Hp(o),!0):r.id==="table/delete"?(t.deleteBlock(e),!0):!1}}var Mv=(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))(Mv||{});const zi=6,ic=20,qp="table-cell-menu-btn";function HM(n,t){if(!n.isBlockWritable(t))return;const o={...mt.default(n.getBlockData(t)),hasColTitle:!0};n.updateBlockData(t,o)}function jM(n,t){if(!n.isBlockWritable(t))return;const o={...mt.default(n.getBlockData(t)),hasColTitle:!1};n.updateBlockData(t,o)}function UM(n,t){if(!n.isBlockWritable(t))return;const o={...mt.default(n.getBlockData(t)),hasRowTitle:!0};n.updateBlockData(t,o)}function zM(n,t){if(!n.isBlockWritable(t))return;const o={...mt.default(n.getBlockData(t)),hasRowTitle:!1};n.updateBlockData(t,o)}function VM(n,t){if(!n.isBlockWritable(t))return;const o={...mt.default(n.getBlockData(t)),isStripeStyle:!0};n.updateBlockData(t,o)}function WM(n,t){if(!n.isBlockWritable(t))return;const o={...mt.default(n.getBlockData(t)),isStripeStyle:!1};n.updateBlockData(t,o)}function qM(n,t,e){if(!n.isBlockWritable(t))return;const r={...mt.default(n.getBlockData(t)),noBorder:!e};n.updateBlockData(t,r)}const Gp=S("get-selected-containers");function Zp(n,t,e,o){g(Gp,e.blockId===o.blockId,"only allow select in single table block"),g(Gp,it(t)===e.blockId,"only allow select in single table block");const r=Tt.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(x=>r.getCellContainer(x));const{fromCol:l,toCol:a,fromRow:d,toRow:h}=Uo(t,e,o),p=new Set,A=[];return r.sub({row:d,col:l},{row:h,col:a}).forEach(B=>{B.forEach(D=>{const x=r.getCellByContainerId(D.containerId);x.col<l||x.row<d||x.col+x.colSpan-1>a||x.row+x.rowSpan-1>h||p.has(D.containerId)||(p.add(D.containerId),A.push(x.container))})}),A}function GM(n,t,e){g(Gp,t.blockId===e.blockId,"only allow select in single table block");const o=n.getBlockById(t.blockId);return Zp(n,o,t,e)}const Ws=S("table-cell-dom");function ZM(n,t,e){let o=n.getBlockById(e);for(;o;){const r=o.closest("td");g(Ws,r,"no parent cell");const i=et(r);if(g(Ws,i,"no parent block"),i===t)return r;o=i}return g(Ws,!1,"filed to get cell by child block id"),null}function Jr(n,t,e){if(n.getBlockById(e.blockId)===t&&!e.isSimple())return g(Ws,e.childContainerId,"block position must have childContainerId attribute"),e;const r=ZM(n,t,e.blockId),i=at(su(r));return fe(t,i)}function Qp(n,t){const e=n.selection.range,o=Jr(n,t,e.start),r=Jr(n,t,e.end);return Uo(t,o,r)}function Rv(n,t,e,o){g(Ws,Ve(t),"invalid table block");const r=mr(n,t),i=te(t),s=()=>{const a=r.querySelector(".table-border-bar-container.top");g(Ws,a,"no top border bar container"),a.querySelectorAll(".table-border-bar-cell.top").forEach(h=>{const p=parseInt(h.getAttribute("data-top-index")||"0",10);o.includes(p)?W(h,"danger"):ot(h,"danger")})},l=()=>{const a=i.querySelector(".table-border-bar-container.left");g(Ws,a,"no left border bar container"),a.querySelectorAll(".table-border-bar-cell.left").forEach(h=>{const p=parseInt(h.getAttribute("data-left-index")||"0",10);e.includes(p)?W(h,"danger"):ot(h,"danger")})};s(),l()}function Vi(n,t,e=!0,o){const i=Tt.fromBlock(t).map(h=>h),{fromCol:s,toCol:l,fromRow:a,toRow:d}=Qp(n,t);for(let h=0;h<i.length;h++){const p=i[h];for(let A=0;A<p.length;A++){const v=p[A],B=o?A>=s&&A+v.colSpan-1<=l:h>=a&&h+v.rowSpan-1<=d;e&&B?v.virtual||W(v.cell,"danger"):v.virtual||ot(v.cell,"danger")}}}function Wi(n,t,e=!0,o){const r=new Set,i=new Set;if(!e){Rv(n,t,Array.from(r),Array.from(i));return}const{fromCol:s,toCol:l,fromRow:a,toRow:d}=Qp(n,t);if(o)for(let h=s;h<=l;h++)i.add(h);else for(let h=a;h<=d;h++)r.add(h);Rv(n,t,Array.from(r),Array.from(i))}function Ov(n,t,e){const{fromCol:o,toCol:r,fromRow:i,toRow:s}=Qp(n,t),l=Tt.fromBlock(t);let a=null,d=null;return e?(a=l.getCell({col:o,row:0}),d=l.getCell({col:r,row:l.rowCount-1}),Ue(n,{anchor:fe(t,a.containerId,{colIndex:o,rowIndex:0}),focus:fe(t,d.containerId,{colIndex:r,rowIndex:l.rowCount-1})})):(a=l.getCell({col:0,row:i}),d=l.getCell({col:l.colCount-1,row:s}),Ue(n,{anchor:fe(t,a.containerId,{colIndex:0,rowIndex:i}),focus:fe(t,d.containerId,{colIndex:l.colCount-1,rowIndex:s})}))}function QM(n,t){const e=n.selection.range,o=Jr(n,t,e.start),r=Jr(n,t,e.end);return Zp(n,t,o,r)}const _v=["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 Fv(n){return`style-bg-color-${n}`}function au(n){return`${n}_background`}function YM(n,t,e){const o=_e(n),s=(e!=null?e:Tt.fromTable(o)).getCell(t).cell;for(let l=0;l<_v.length;l++){const a=_v[l];if(xt(s,a))return a}}function Pv(n,t,e){if(!n.isBlockWritable(t))return;const o=n.selection.range,i={...mt.default(n.getBlockData(t))},s=Jr(n,t,o.start),l=Jr(n,t,o.end);if(o.isSimple()){const a=s.childContainerId;e===-1?i[au(a)]=void 0:i[au(a)]=Fv(e)}else{const a=Tt.fromBlock(t),d=Uo(t,s,l),h=new Set;for(let p=d.fromRow;p<=d.toRow;p++)for(let A=d.fromCol;A<=d.toCol;A++){const v=a.getCell({row:p,col:A});!h.has(v.containerId)&&v.col>=d.fromCol&&v.row>=d.fromRow&&v.col+v.colSpan-1<=d.toCol&&v.row+v.rowSpan-1<=d.toRow&&(h.add(v.containerId),e===-1?i[au(v.containerId)]=void 0:i[au(v.containerId)]=Fv(e))}}n.updateBlockData(t,i)}function JM(n,t,e){if(!n.isBlockWritable(t))return;const r={...mt.default(n.getBlockData(t)),chart:e};n.updateBlockData(t,r)}const Nv=S("table-chart");function KM(n,t){const e=xM(n,t);if(e){const o=e.querySelector(".editor-table-chart");if(o){const r=o.chartObject;r&&r.destroy(),o.remove()}}}async function XM(n,t){if(!n.isBlockWritable(t))return;if(!!!n.getBlockData(t).chart){KM(n,t);return}const r=[],i=Tt.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 a=[];for(let D=1;D<i.colCount;D++)a.push(i.getCell({row:0,col:D}).container.innerText);for(let D=1;D<i.rowCount;D++){const x=i.getCell({row:D,col:0}),M=x.container.innerText,H=[];for(let qe=1;qe<i.colCount;qe++){const Yn=i.getCell({row:D,col:qe}).container.innerText,$e=Number.parseFloat(Yn)||0;H.push($e)}let z;const q=YM(t,x,i);q?z=window.getComputedStyle(n.rootElement).getPropertyValue(`--${q}`).trim():z=window.getComputedStyle(n.rootElement).getPropertyValue("--background-color").trim();let[rt,ft,Bt,jt]=z?dm.fromString(z).toRgbaArray():[];if(!rt&&!ft&&!Bt&&!jt){const qe=(D-1)%n.options.colors.length;z=n.options.colors[qe],[rt,ft,Bt,jt]=dm.fromString(z).toRgbaArray()}const Ut=z,ne=dm.fromRgba([rt,ft,Bt,jt/3]).toHexString();r.push({label:M,data:H,borderColor:Ut,backgroundColor:ne,borderWidth:2})}const d=mr(n,t);let h=null,p=d.querySelector(".editor-table-chart");p?h=p.chartObject:p=w("div",["editor-table-chart"],d);const A=p;g(Nv,A,"no chart container");const v=n.getComponentOptions("table"),B=(v==null?void 0:v.chartCdn)||"https://cdn.jsdelivr.net/npm/chart.js@2.9.4/dist/Chart.min.js";try{await vs(B,"editor-chartjs");let D=!1;(h&&h.config.data.datasets.length>r.length||h&&h.config.data.datasets[0].data.length>r[0].data.length)&&(D=!0),h&&(l!==h.config.type||D)&&(h.destroy(),h=null,Array.from(p.querySelectorAll(".editor-chartjs-canvas")).forEach(M=>{M.remove()}));const x=hm.default({},{type:l,data:{datasets:r,labels:a},options:{onClick:()=>{n.selection.selectBlock(t,0,0)}}});if(h)hm.default(h.config,x),h.update();else{const M=w("canvas",["editor-chartjs-canvas"],A).getContext("2d");h=new window.Chart(M,x),p.chartObject=h}}catch(D){Nv.error(`failed to resolve chart cdn: ${JSON.stringify(D)}`)}}async function $v(n,t){await Eo.lock("updateTableChart");try{await XM(n,t)}finally{Eo.release("updateTableChart")}}const Hv=Le.default($v,1e3);let jv=null;function Yp(n,t,e){if(jv!==t&&(Hv.flush(),jv=t),e.updateNow){$v(n,t);return}Hv(n,t)}function Jp(n,t){Ve(t)&&Yp(n,t,{updateNow:!1})}function tR(n,t){Ve(t)&&Yp(n,t,{updateNow:!0})}const ho={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"},tf={SCROLL_BAR:"container-scrollbar",FIXED:"fixed"},qi={SCROLL_CONTAINER:"scroll-container",TOOL:"container-scroll-tool",CONTAINER:"scroll-container-root",MAC:"mac",SCROLL_AREA:"scroll-area"};function uu(n,t){return n.containers.get(t)}function Uv(n){return n.closest(`.${qi.SCROLL_CONTAINER}`)}function zo(n){return n.firstElementChild}function Ln(n){return n.closest(`.${qi.CONTAINER}`)}function du(n){const t=Ln(n);let e=t.querySelector(`:scope >.${qi.TOOL}`);return e||(e=w("div",[qi.TOOL],t)),e}function eR(n){return Ln(n).firstElementChild}function nR(n,t){const e=uu(n,Ln(t));return e!=null&&e.barFloatWindowBottom?typeof e.barFloatWindowBottom=="function"?e.barFloatWindowBottom():e.barFloatWindowBottom:0}function fo(n,t){const e=ys(n);return t/e}function hu(n){const t=window.getComputedStyle(n),e=ys(n);return{paddingBottom:parseFloat(t.paddingBottom)*e,paddingTop:parseFloat(t.paddingTop)*e,paddingLeft:parseFloat(t.paddingLeft)*e,paddingRight:parseFloat(t.paddingRight)*e}}function sc(n){const t=ys(n);return{scrollLeft:n.scrollLeft*t,scrollWidth:n.scrollWidth*t,clientWidth:n.clientWidth*t,clientHeight:n.clientHeight*t}}function oR(n,t){const e=ys(n);return n[t]*e}function Kp(n,t){const e=Ln(t),o=uu(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(),a=e.getBoundingClientRect(),d=a.width;let h=Math.floor(a.left-l.left-i);h<0&&(h=0);let p=l.right;p-=r;let A=p-a.right;return A<0&&(A=0),h=Math.round(h),A=Math.round(A),{originWidth:d,maxLeft:h,maxRight:A}}function rR(n,t){const e=Kp(n,t),{maxLeft:o}=e;t.style.marginLeft=`${fo(t,0-o)}px`,t.style.paddingLeft=`${fo(t,o)}px`}function iR(n,t){const e=Kp(n,t);t.style.marginRight=`${fo(t,0-e.maxRight)}px`}function sR(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 zv=S("scroll-bar-handle"),lR=2;function lc(n){const t=du(n);let e=t.querySelector(`.${tf.SCROLL_BAR}`);return e||(e=w("div",[tf.SCROLL_BAR],t)),g(zv,e instanceof HTMLDivElement,"invalid child for container tools"),e.firstElementChild||w("div",[],e),e}function ef(n,t){const e=Uv(t),o=lc(e),{scrollWidth:r,clientWidth:i}=sc(e),{paddingLeft:s,paddingRight:l}=hu(t),a=Kp(n,e),{originWidth:d,maxRight:h}=a;iR(n,e),rR(n,e);const p=r-i;g(zv,o.firstElementChild instanceof HTMLDivElement,"invalid child for scroll bar"),o.style.width=`${fo(e,d+h-s-l)}px`,o.firstElementChild.style.width=`${fo(e,d+h+p-s-l)}px`}function cR(n,t){const e=zo(n),{paddingLeft:o}=hu(e);if(xt(t,"fixed")){const i=Ln(n).getBoundingClientRect();t.style.left=`${fo(n,i.left+o)}px`}else t.style.left=`${fo(n,o)}px`}function cc(n,t){var M;const e=n.getParentScrollContainer(),o=sR(e),r=t.getBoundingClientRect(),i=lc(t),s=i.getBoundingClientRect(),l=uu(n,Ln(t)),a=nR(n,t),d=zo(t),{paddingTop:h,paddingBottom:p}=hu(d),{scrollWidth:A,clientWidth:v}=sc(t),B=document.documentElement.clientHeight-a,D=o.top+sc(e).clientHeight-B,x=B+Math.min(0,D);if(A>v&&r.top+h<x-s.height&&r.bottom>x-s.height+p&&!((M=l==null?void 0:l.isSetScale)!=null&&M.call(l))){W(i,tf.FIXED);const H=D>0?a:0;i.style.bottom=`${Math.max(document.documentElement.clientHeight-o.bottom,0)+lR+H}px`}else ot(i,tf.FIXED),i.style.bottom=`${fo(t,p-s.height)}px`;cR(t,i)}class aR{constructor(t,e){m(this,"intersectionObserver");m(this,"handleIntersection",t=>{t.forEach(e=>{this.containers.get(Ln(e.target))?(this.handleIntersectionEntry(e),this.callback(e)):this.intersectionObserver.unobserve(e.target)})});m(this,"handleIntersectionEntry",t=>{const e=t.target;cc(this.scrollCore,e);const o=zo(e);ef(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 qs=S("container-scroll-shadow");function Vv(n,t,e){const o=n,r=t.getBoundingClientRect(),i=e.getBoundingClientRect(),{paddingTop:s,paddingBottom:l}=hu(e);o.style.top=`${fo(t,i.top-r.top+s)}px`,o.style.bottom=`${fo(t,r.bottom-i.bottom+l)}px`}function Wv(n,t){const e=n;t<24?e.style.width=`${(t/3).toFixed(2)}px`:e.style.width=""}function uR(n){const t=du(n);g(qs,t,"no container tools");let e=t.querySelector(`.${ho.LEFT}`);if(!e){const l=zo(n),a=[ho.COMMON,ho.LEFT];e=w("div",a,t),g(qs,e instanceof HTMLDivElement,"invalid child for container tools"),Vv(e,n,l)}g(qs,e instanceof HTMLElement,"invalid child for container tools");const r=Ln(n).getBoundingClientRect(),i=n.getBoundingClientRect();e.style.left=`${fo(n,i.left-r.left)}px`;const s=sc(n).scrollLeft;g(qs,e instanceof HTMLDivElement,"invalid child for container tools"),Wv(e,s),W(e,ho.ACTIVE)}function dR(n){const t=du(n);let e=t.querySelector(`.${ho.RIGHT}`);if(!e){const h=zo(n),p=[ho.COMMON,ho.RIGHT];e=w("div",p,t),g(qs,e instanceof HTMLDivElement,"no div, create shadow failed"),Vv(e,n,h)}g(qs,e instanceof HTMLElement,"");const r=Ln(n).getBoundingClientRect(),i=n.getBoundingClientRect();e.style.right=`${fo(n,r.right-i.right)}px`;const{scrollWidth:s,scrollLeft:l,clientWidth:a}=sc(n),d=s-l-a;g(qs,e instanceof HTMLDivElement,"no shadow element"),Wv(e,d),W(e,ho.ACTIVE)}function hR(n){const e=du(n).querySelector(`.${ho.LEFT}`);e&&ot(e,ho.ACTIVE)}function fR(n){const e=du(n).querySelector(`.${ho.RIGHT}`);e&&ot(e,ho.ACTIVE)}function fu(n){const{scrollLeft:t,scrollWidth:e,clientWidth:o}=sc(n),r=zo(n),{paddingLeft:i,paddingRight:s}=hu(r),l=oR(r,"offsetLeft");e-i<=o-s||e-i<=t+o-s?fR(n):dR(n),r&&t>=l+i?uR(n):hR(n)}class mR{constructor(t,e){m(this,"resizeObserver");m(this,"handleResizeEntry",t=>{const e=t.target,o=zo(e);fu(e),ef(this.scrollCore,o),cc(this.scrollCore,e),this.callback(e)});m(this,"handleContentResize",t=>{t.forEach(e=>{this.containers.get(Ln(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 qv=S("container-scroll-observer");class gR{constructor(t,e){m(this,"handleContentScroll",t=>{const e=t.target;g(qv,e instanceof Element,"invalid target for scroll event");const o=lc(e);o.removeEventListener("scroll",this.handleScroll);const r=!0;this.fixScrollXPos(e,e.scrollLeft,r),this.bind(o),fu(e),this.callback(e)});m(this,"handleScroll",t=>{const e=t.target;g(qv,e instanceof HTMLElement,"");const o=e.scrollLeft,r=!1,i=eR(e);this.unbindContentScroll(i),this.fixScrollXPos(i,o,r),this.bindContentScroll(i),fu(i),this.callback(i)});m(this,"handlePrevent",t=>{t.stopPropagation()});m(this,"bindContentScrollCore",t=>{this.unbindContentScroll(t),t.addEventListener("scroll",this.handleContentScroll)});m(this,"unbindContentScroll",t=>{t.removeEventListener("scroll",this.handleContentScroll)});m(this,"bindContentScroll",Le.default(this.bindContentScrollCore,300));m(this,"bind",Le.default(this.bindCore,200));this.scrollCore=t,this.callback=e}fixScrollXPos(t,e,o){const r=lc(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 pR{constructor(t){m(this,"scrollContainers",new Set);m(this,"handleParentContainerScroll",()=>{this.scrollContainers.forEach(t=>{cc(this.scrollCore,t)})});m(this,"bindScrollContainer",t=>{const e=this.scrollContainers.size===0;this.scrollContainers.add(t),e&&this.eventTarget.addEventListener("scroll",this.handleParentContainerScroll)});m(this,"unbindScrollContainer",t=>{let e=!1;this.scrollContainers.has(t)&&(this.scrollContainers.delete(t),e=this.scrollContainers.size===0),e&&this.eventTarget.removeEventListener("scroll",this.handleParentContainerScroll)});this.scrollCore=t}get eventTarget(){const t=this.scrollCore.getParentScrollContainer();return t===document.documentElement?document:t}destroy(){this.eventTarget.removeEventListener("scroll",this.handleParentContainerScroll),this.scrollContainers.clear()}}const CR=S("scroll-wrap-resize-observer");class AR{constructor(t){m(this,"resizeObserver");m(this,"handleScrollWrapResize",t=>{t.forEach(e=>{this.containers.get(Ln(e.target))?this.handleScrollWrapResizeEntry(e):this.unbind(e.target)})});m(this,"handleScrollWrapResizeEntry",t=>{const e=t.target;g(CR,e instanceof HTMLElement,"invalid target for observer entry");const o=Uv(e);ef(this.scrollCore,e),fu(o),cc(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 bR{constructor(t,e){m(this,"resizeObserver");m(this,"scrollContainersMap",new Map);m(this,"handleResizeEntry",t=>{t==null||t.forEach(e=>{const o=zo(e);fu(e),ef(this.scrollCore,o),cc(this.scrollCore,e),this.callback(e)})});m(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=Ln(t),o=(r=uu(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=Ln(t),o=(i=uu(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 ynt="";class vR extends ye.TypedEmitter{constructor(e){super();m(this,"containerIntersectionObserver",null);m(this,"containerResizeObserver",null);m(this,"containerScrollObserver",null);m(this,"parentContainerScrollObserver",null);m(this,"scrollWrapResizeObserve",null);m(this,"locatingContainerResizeObserver",null);m(this,"isWindowEventBind",!1);m(this,"containers",new Map);m(this,"handleScrollContainerScroll",e=>{this.emit("scroll",this,e)});m(this,"handleResize",e=>{this.emit("resize",this,e)});m(this,"handleIntersection",e=>{const o=e.target,r=zo(o);e.isIntersecting?(this.load(),this.bindCore(o,r)):this.unbindCore(o,r)});m(this,"handleWindowEffect",()=>{var e;(e=this.getScrollContainerInViewable())==null||e.forEach(o=>{cc(this,o)})});this.parentContainer=e}load(){this.containerResizeObserver||(this.containerResizeObserver=new mR(this,this.handleResize)),this.containerScrollObserver||(this.containerScrollObserver=new gR(this,this.handleScrollContainerScroll)),this.parentContainerScrollObserver||(this.parentContainerScrollObserver=new pR(this)),this.scrollWrapResizeObserve||(this.scrollWrapResizeObserve=new AR(this)),this.locatingContainerResizeObserver||(this.locatingContainerResizeObserver=new bR(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,a,d,h;const r=lc(e);(i=this.containerScrollObserver)==null||i.unbindContentScroll(e),(s=this.containerScrollObserver)==null||s.unbind(r),(l=this.scrollWrapResizeObserve)==null||l.unbind(o),(a=this.containerResizeObserver)==null||a.unbind(e),(d=this.parentContainerScrollObserver)==null||d.unbindScrollContainer(e),(h=this.locatingContainerResizeObserver)==null||h.unbind(e)}bindCore(e,o){var i,s,l,a,d,h;if(this.unbindCore(e,o),!e.closest("body"))return;const r=lc(e);(i=this.containerScrollObserver)==null||i.bindContentScrollCore(e),(s=this.containerScrollObserver)==null||s.bindCore(r),(l=this.scrollWrapResizeObserve)==null||l.bind(o),(a=this.containerResizeObserver)==null||a.bind(e),(d=this.parentContainerScrollObserver)==null||d.bindScrollContainer(e),(h=this.locatingContainerResizeObserver)==null||h.bind(e)}bind(e,o){this.containers.set(e,o);const r=e.firstElementChild;this.containerIntersectionObserver||(this.containerIntersectionObserver=new aR(this,this.handleIntersection)),this.containerIntersectionObserver.bind(r)}unbind(e){var i;const o=e.firstElementChild,r=zo(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,a)=>{this.unbind(a)}),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 Gv=S("scroll-container"),nf=new Map;class yR extends ye.TypedEmitter{constructor(){super(...arguments);m(this,"scrollListener");m(this,"options");m(this,"scrollContainerElement");m(this,"init",e=>{this.options=e;const o=w("div",[qi.CONTAINER],e.parentElement);Ze.isMac&&W(o,qi.MAC);const r=w("div",[qi.SCROLL_CONTAINER],o),i=w("div",[qi.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=nf.get(s),this.scrollListener||(this.scrollListener=new vR(s),nf.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});m(this,"handleContainerScroll",(e,o)=>{o===this.scrollContainerElement&&this.emit("scroll",this)});m(this,"handleResize",(e,o)=>{o===this.scrollContainerElement&&this.emit("scroll",this)})}get rootElement(){return this.scrollContainerElement}get contentElement(){return g(Gv,this.scrollContainerElement,"scrollContainerElement cannot be undefined"),zo(this.scrollContainerElement)}get scrollOptions(){return g(Gv,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=Ln(this.contentElement);e&&nf.forEach((r,i)=>{r.unbind(e),r.containers.size===0&&(this.handleBaseListenerDestroy(r),nf.delete(i))})}}function kR(){return new yR}const Xp=S("column-width");function wR(n,t,e){TM(n,t).style.width=`${e}px`}function BR(n){const e=Array.from(n.querySelector("colgroup").children).map(a=>a.getBoundingClientRect().width);if(e[0]!==0)return e;const o=Tt.fromTable(n),r=Array(o.colCount).fill(-1),i=n.getBoundingClientRect().left;o.toRealCells(o.cells).forEach(a=>{const d=a.col+a.colSpan-1;r[d]===-1&&(r[d]=a.cell.getBoundingClientRect().right-i)}),Xp.debug(`cellRightOffsets1: ${r.join()}`);for(let a=0;a<r.length;a++){const d=r[a];if(d===-1||a===0)continue;let h=a-1;for(;r[h]===-1&&(h--,h!==-1););const p=h===-1?0:r[h],v=(d-p)/(a-h);for(let B=h+1;B<a;B++)r[B]=p+v*(B-h)}Xp.debug(`cellRightOffsets2: ${r.join()}`);const s=[];let l=0;for(let a=0;a<r.length;a++){const d=r[a];s.push(d-l),l=d}return Xp.debug(`widths: ${s.join()}`),s}function mu(n){return Array.from(n.querySelector("colgroup").children).map(o=>o.getBoundingClientRect().width||Number.parseInt(o.style.width,10))}const t0=200,ER=40,xR=S("table-resize-gripper"),Zv=7,e0=(Zv-1)/2,IR=3;function TR(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 a=s[l],d=a.getBoundingClientRect(),h=Math.round(d.right);if(Math.abs(t-h)<=e0&&d.top<=e&&e<=d.bottom)return a}}return null}function DR(n){return!!n.rootContainer.querySelector(".table-resize-gripper")}function n0(n,t){return mr(n,t).querySelector(".table-resize-gripper")}function Qv(n,t){const e=n0(n,t);g(xR,!e,"resize gripper has already exists");const o=mr(n,t),r=w("div",["table-resize-gripper","table-indicator"],o);return w("div",["table-resize-gripper-indicator"],r),r}function Yv(n,t,e){let o=n0(n,t);o||(o=Qv(n,t));const i=_e(t).getBoundingClientRect(),s=e.getBoundingClientRect(),l=0,a=i.height,d=n.getCustom(fr(t)).contentElement.getBoundingClientRect(),h=s.right-d.left;o.style.left=`${h-e0-zi-ic}px`,o.style.top=`${l}px`,o.style.height=`${a}px`,o.style.width=`${Zv}px`}function o0(n){n.rootContainer.querySelectorAll(".table-resize-gripper").forEach(t=>{t.remove()})}function SR(n,t,e){const r={...n.getBlockData(t),colsWidth:e};n.updateBlockData(t,r)}function LR(n,t,e,o){const r=t,i=Tt.fromTable(e),s=i.getCellByCellElement(r),l=s.col+s.colSpan-1,a=mu(e);let d=o;const h=(A,v)=>{const B=v+1,D=A.col+A.colSpan;return a.slice(B,D).reduce((_,M)=>_+M,0)},p=new Set;for(let A=0;A<i.rowCount;A++){const v=i.getCell({row:A,col:l});if(p.has(v.cell))continue;p.add(v.cell);const B=v.cell,D=B.getBoundingClientRect();let x=o-D.left+e0-IR;const _=su(B),M=Gm(n,_)||ER*v.colSpan,H=h(v,l),z=M-H;x<z&&(x=z);const q=D.left+x;d=Math.max(d,q)}return d}const MR=S("table-resize-drag-drop");class RR{constructor(t,e,o,r){m(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:a}=t.data,h=LR(this.editor,a,s,e.x-t.dragOffsetX)-s.getBoundingClientRect().left;g(MR,a,"no dragging cell");const A=Tt.fromTable(s).getCellByCellElement(a),v=A.col+A.colSpan-1,D=mu(s).slice(0,v).reduce((_,M)=>_+M,0),x=h-D;wR(s,v,x),Yv(this.editor,l,a),this.editor.selection.caret.update()}onDragEnd(t,e,o,r,i){const s=mu(t.data.table);SR(this.editor,t.data.block,s),o0(this.editor),this.onEnd&&(this.onEnd(e),this.onEnd=null)}}function OR(n,t){const e=document.elementFromPoint(t.x,t.y);if(!e)return null;const o=et(e);return!o||!n.contains(o)||!Ve(o)?null:o}S("table-resize");class _R{constructor(t){m(this,"draggingRefCell",null);m(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=OR(t,i);if(!s||!Ev(s)||!t.isBlockWritable(s)){o0(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=_e(t),i=TR(r,e,o);if(i){if(!n0(this.editor,t)){if(DR(this.editor))return;const l=Qv(this.editor,t),a={block:t,table:r,draggingRefCell:i};km(new RR(this.editor,l,a,d=>{this.updateGripper(t,d.x,d.y)}))}Yv(this.editor,t,i)}else o0(this.editor)}}function Jv(n){n.addCustom("table-mouse-event-handler",t=>new _R(t))}const Kv=S("table-insert-column");function Xv(n,t,e){n.undoManager.runInGroup(()=>{const o=_e(t),r=Tt.fromTable(o),i=r.colCount;g(Kv,e>=0&&e<=i,`insert index ${e} is out of range [0, ${i}]`);const s=r.map(A=>A.containerId),l=new Set;n.doc.beginBatchUpdate();for(let A=0;A<s.length;A++){const v=s[A],B=v[e-1],D=v[e];if(e===0||e===v.length||B!==D){const x=qr(n.doc);v.splice(e,0,x)}else v.splice(e,0,B),l.add(B)}n.doc.endBatchUpdate();const a=mt.default(n.getBlockData(t));l.forEach(A=>{const v=`${A}_colSpan`,B=a[v];g(Kv,typeof B=="number"&&B>1,`no colSpan for containerId ${A}, ${B}`),a[v]=B+1});const d=a.colsWidth.concat();d.splice(e,0,t0);const h=Tt.virtualCellContainersGridToChildren(s),p={...a,cols:a.cols+1,children:h,colsWidth:d};Vs(p),n.updateBlockData(t,p)})}const of=S("table-insert-row");function t9(n,t,e){n.undoManager.runInGroup(()=>{const o=_e(t),r=Tt.fromTable(o),i=r.rowCount;g(of,e>=0&&e<=i,`insert index ${e} is out of range [0, ${i}]`);const s=r.map(A=>A.containerId),l=new Set;n.doc.beginBatchUpdate();const a=[];for(let A=0;A<r.colCount;A++){const v=e>0&&s[e-1][A],B=e<r.rowCount&&s[e][A];if(g(of,v||B,"no top and bottom cell"),e===0||e===r.rowCount||v!==B){const D=qr(n.doc);a.push(D)}else g(of,v,"no top cell"),a.push(v),l.add(v)}n.doc.endBatchUpdate(),s.splice(e,0,a);const d=mt.default(n.getBlockData(t));l.forEach(A=>{const v=`${A}_rowSpan`,B=d[v];g(of,typeof B=="number"&&B>1,`no rowSpan for containerId ${A}, ${B}`),d[v]=B+1});const h=Tt.virtualCellContainersGridToChildren(s),p={...d,rows:d.rows+1,children:h};Vs(p),n.updateBlockData(t,p)})}const r0=S("paste-table-in-table-block");function FR(n,t,e,o){let r=Tt.fromBlock(e);const i=t.blocks.root[0];g(r0,i,"no table data"),g(r0,i.type==="table",`table data type is not table, but ${i.type}`);const s=i,l=r.getCellByCellElement(o),a=s.cols,d=s.rows,h=l.col,p=l.row,A=h+a,v=p+d,B=[];for(let D=h;D<A&&D<r.colCount;D++)for(let x=p;x<v&&x<r.rowCount;x++){const _=r.getCell({col:D,row:x});_.virtual?_.virtual&&B.push({col:D,row:x}):(_.colSpan>1||_.rowSpan>1)&&B.push({col:D,row:x})}n.undoManager.runInGroup(()=>{if(B.forEach(M=>{const H=Tt.fromBlock(e).getCell(M);(H.colSpan>1||H.rowSpan>1)&&Up(n,e,M)}),A>r.colCount)for(let M=r.colCount;M<A;M++)Xv(n,e,M);if(v>r.rowCount)for(let M=r.rowCount;M<v;M++)t9(n,e,M);r=Tt.fromBlock(e);const D=new Yh(s);let x;for(let M=0;M<D.colCount;M++)for(let H=0;H<D.rowCount;H++){const z=D.getCell({col:M,row:H});if(!z.virtual){const q=_g(n.editorBlocks,t,z.containerId),rt=h+M,ft=p+H,Bt={col:rt,row:ft},jt=r.getCellContainer(Bt);W6(n,jt,q),x=jt}}g(r0,x,"no last container");const _=Qe(x);n.selection.selectBlock(_,ut(n,_))})}const e9=S("paste-in-table-block");class PR{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=nt(r);if(Yt(i)||!Ba(t,i))return!1;const s=et(i);if(g(e9,s,"no parent block"),!Ve(s)||e.blocks.root.length!==1||e.blocks.root[0].type!=="table")return!1;e9.debug("paste child table in table");const d=Tt.fromBlock(s).getCellByContainerId(at(i)).cell;return FR(t,e,s,d),!0}}function n9(n){n.addCustom("table-block-paste-event",t=>new PR(t))}const i0=S("table-select-columns");function NR(n,t,e,o,r){g(i0,Ve(t),"is not a table block");const i=Tt.fromBlock(t);g(i0,e>=0&&e<i.colCount,"invalid from"),g(i0,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}),a=fe(t,s.containerId,{colIndex:e,rowIndex:0}),d=fe(t,l.containerId,{colIndex:e+o-1,rowIndex:i.rowCount-1});r!=null&&r.reverse?n.selection.setSelection(d,a):n.selection.setSelection(a,d)}const s0=S("table-select-columns");function $R(n,t,e,o,r){g(s0,Ve(t),"is not a table block");const i=Tt.fromBlock(t);g(s0,e>=0&&e<i.rowCount,"invalid from"),g(s0,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}),a=fe(t,s.containerId,{rowIndex:e,colIndex:0}),d=fe(t,l.containerId,{rowIndex:e+o-1,colIndex:i.colCount-1});r!=null&&r.reverse?n.selection.setSelection(d,a):n.selection.setSelection(a,d)}const knt="",o9=S("get-toolbar-reference-client");function HR(n,t){const e=n.selection.range;if(!e.isSimple()){g(o9,e.start.blockId===e.end.blockId,"invalid selection range");const s=n.getBlockById(e.start.blockId);g(o9,Mt(n,s),"not a complex block");const l=Qt(n,s);if(l.getTextToolbarReferenceClient){const a=l.getTextToolbarReferenceClient(n,s);if(a)return a}}const o=e.isReverse()?t.start:t.end,r=Ue(n,{anchor:o,focus:o}),i=Nr(n,t.block,r);if(i.length!==0)return i[0]}function jR(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 rf(n){const t=(r,i)=>{const s=r.findIndex(a=>a.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=fm.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=rf(r),jR(s))}),e}function sf(n){return n.getCustom("toolbar-handler")}const wnt="";class UR{constructor(){m(this,"linkPopup",null);m(this,"form",{});m(this,"onFinished",null);m(this,"onClose",null);m(this,"handleOk",async()=>{var t;try{await this.checkValue();const{linkText:e,linkUrl:o}=this.form,r=this.formatUrl(o.getInputValue());(t=this.onFinished)==null||t.call(this,e.getInputValue()||r,r),this._destroy()}catch{}});m(this,"handleClose",()=>{var t;(t=this.onClose)==null||t.call(this),this._destroy()});m(this,"onShow",()=>{setTimeout(()=>{var t;(t=this.form.linkText)==null||t.getField().focus()},400)});m(this,"onChange",()=>{var e;const t=(e=this.linkPopup)==null?void 0:e.content.querySelector('[data-button-id="submit-button"]');t.disabled=!1});m(this,"handleTextKeyboard",t=>{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()}});m(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(R.t("link.urlPlaceholder")),new Error(R.t("link.urlPlaceholder"))}formatUrl(t){if(!t)return"";try{new URL(t)}catch{return`${window.location.protocol}//${t}`}return t}editLink(t){var h,p;const{target:e,linkText:o,linkUrl:r,onFinished:i,onClose:s,placement:l="bottom-start"}=t;this.linkPopup=new tu(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 a=(h=this.linkPopup)==null?void 0:h.content.querySelector('[data-button-id="submit-button"]'),d=(p=this.linkPopup)==null?void 0:p.content.querySelector('[data-button-id="cancel-button"]');a==null||a.addEventListener("click",this.handleOk),d==null||d.addEventListener("click",this.handleClose)}createPopupContent(t,e){const o=w("div",["link-popup-content"],null);this.form.linkText=Rp(o,{label:R.t("link.textLabel"),required:!1,placeholder:R.t("link.textPlaceholder"),defaultValue:t,onChange:this.onChange,onKeyDown:this.handleTextKeyboard}),this.form.linkUrl=Rp(o,{className:"link-popup-gap",label:R.t("link.urlLabel"),required:!0,placeholder:R.t("link.urlPlaceholder"),defaultValue:e,onChange:this.onChange,onKeyDown:this.handleUrlKeyboard});const r=w("div",["link-popup-footer"],o),i=uo("cancel-button",R.t("link.cancelText"));r.appendChild(i);const s=uo("submit-button",R.t("link.submitText"),void 0,["disabled","primary"]);return r.appendChild(s),o}_destroy(){var o,r,i,s;const t=(o=this.linkPopup)==null?void 0:o.content.querySelector('[data-button-id="submit-button"]'),e=(r=this.linkPopup)==null?void 0:r.content.querySelector('[data-button-id="cancel-button"]');t==null||t.removeEventListener("click",this.handleOk),e==null||e.removeEventListener("click",this.handleClose),this.onFinished=null,this.onClose=null,this.form={},(i=this.linkPopup)==null||i.removeAllListeners(),(s=this.linkPopup)==null||s.destroy()}destroy(){this._destroy()}}function gu(n,t){n.addCustom("link-editor",()=>new UR).editLink(t)}const zR=S("link-popup");function VR(n){return xt(n,"link")}function pu(n){var t,e;return(e=(t=n.getAttribute("link"))!=null?t:n.textContent)!=null?e:""}function WR(n,t,e){var r,i,s,l;if(n.isBlockWritable(t)&&e&&so(e)){const a=e,d=(i=(r=n.editorBoxes.getBoxClass(va(a))).getBoxProperties)==null?void 0:i.call(r,n,a);if(d!=null&&d.boxCommands){const h=(l=(s=d.boxCommands["hovering-toolbar"])==null?void 0:s.commands)!=null?l:[];return{element:e,commands:h}}return{element:null,commands:[]}}if(n.isWritable()&&e&&tt(n,t)&&VR(e)){const a=w("a",["link-href-button"],null,pu(e));a.href=pu(e),a.target="_blank",a.rel="noopener noreferrer";const d=[{id:"link-text",name:pu(e),disableTooltip:!0,element:a},{id:"edit-link",name:R.t("link.edit"),icon:Dp},{id:"remove-link",name:R.t("link.remove"),icon:RL}];return{element:e,commands:d}}return l4(n,t,"hovering-toolbar")}function r9(n,t,e){var l;const o=_s(t,e),r=n.getBlockText(t),i={start:0,end:0};let s=(l=e.textContent)!=null?l:"";for(let a=0;a<r.length;a++){const d=r[a];if(i.end+d.insert.length>=o.end){i.end+=d.insert.length,s=d.insert;break}i.start<o.start&&(i.start+=d.insert.length,i.end=i.start)}return[i,s]}function qR(n,t,e){const[o,r]=r9(n,t,e);n.selection.selectBlock(t,o.start,o.end);const i=pu(e),s=(h,p)=>{try{const A=n.getBlockText(t),v=cg(A,o.start,o.end-o.start),B=Vr(v,o.start,h,{link:p});n.setBlockText(t,B),n.selection.selectBlock(t,o.start+h.length),n.focus()}catch(A){zR.error(A)}},l=()=>{n.selection.selectBlock(t,o.end),n.focus()},a=Nr(n,t,n.selection.range)[0];if(!a)return;const d=zr(n,t,"link-button-anchor",a);gu(n,{target:d,linkText:r,linkUrl:i,onFinished:s,onClose:l})}function GR(n,t,e){const[o]=r9(n,t,e),r=n.getBlockText(t),i=pu(e),s=Wl(o.start,o.end-o.start,r,"link",i);n.setBlockText(t,s),n.selection.selectBlock(t,o.end)}function ZR(n,t,e,o){var s,l,a;if(e){if(n.isBlockWritable(t)&&so(e)){const h=e,p=(l=(s=n.editorBoxes.getBoxClass(va(h))).getBoxProperties)==null?void 0:l.call(s,n,h);if(p!=null&&p.boxCommands){p.boxCommands["hovering-toolbar"].executeCommand(n,t,h,o);return}return}const d=sf(n);d.disableTextToolbar(),d.hide(),setTimeout(()=>{d.enableTextToolbar()},400),o.id==="edit-link"?qR(n,t,e):o.id==="remove-link"&&GR(n,t,e);return}const r=s4(n,t);if(!r)return;const i=(a=r.blockCommands)==null?void 0:a["hovering-toolbar"];!i||i.executeCommand(n,t,o)}function lf(){let n=8;for(;n>0&&!document.querySelector(`div[data-style-heading='${n}']`);)n--;return n}const QR=[bp,vp,yp,kp,wp,Bp,Ep,xp];class YR{constructor(t){m(this,"id","BlockTurnIntoCommandProvider");this.editor=t}getHeadingIndex(){let t=lf();return t<=4?t=5:t<8&&(t+=1),t}getAvailableCommands(t,e,o){if(tt(t,e)){const r=it(e),i=Dt(e),s=Do(t,e),a=t.getBlockData(e).heading,d=[];for(let p=0;p<this.getHeadingIndex();p++)d.push({id:`heading-${p+1}`,name:R.t("commands.heading",{name:`${p+1}`}),icon:QR[p],states:a===p+1?["checked"]:[],value:`${p+1}`});const h=p=>{var v;const A=w("span",["toolbar-item-name-container"],null);for(const B of p.children)if((v=B.states)!=null&&v.includes("checked"))return A.innerHTML=B.icon||ou,A;return A.innerHTML=ou,A};return[{id:"turn-into",name:R.t("commands.headingGroup"),blockId:r,blockType:i,blockKind:s,element:h,groupIndex:200,dropdown:!0,manualShowChildren:!0,childrenPlacement:"bottom-start",defaultCheckedChildren:["text"],children:[{id:"text",name:R.t("commands.text"),icon:ou,states:a?[]:["checked"]},...d],childrenType:"menu"}]}return[]}applyHeadingStyle(t,e,o){t.updateBlockData(e,{heading:o})}executeCommand(t,e,o,r){if(tt(t,e)&&(r.id.startsWith("heading-")||r.id==="text")){const i=r.value?Number(r.value):null;return this.applyHeadingStyle(t,e,i),t.focus(),!0}return!1}}const JR=`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
376
|
+
`;function sM(n,t){var e,o;if(W(t,"menu-item"),!n.element){if(n.type==="section"){const r=w("div",["section-name"],null,n.name);t.appendChild(r)}else if(n.type!=="separator"){if(n.icon){const s=w("div",["menu-item-icon"],null);n.icon&&(s.innerHTML=n.icon),t.appendChild(s)}const r=w("div",["menu-item-name","text"],null),i=w("span",[],r,n.name);if(n.ellipsisTooltip&&(i.setAttribute("data-editor-tooltip-allow-markdown","true"),i.setAttribute("data-editor-tooltip-offset-y","25"),i.setAttribute("data-editor-tooltip-placement","right"),i.setAttribute("data-editor-tooltip-common",`<div style="word-break: break-word;">${n.ellipsisTooltip}</div>`)),((e=n.states)==null?void 0:e.includes("disabled"))&&n.disableReason&&(i.setAttribute("data-editor-tooltip-offset-y","25"),i.setAttribute("data-editor-tooltip-maxwidth","800"),i.setAttribute("data-editor-tooltip-placement","right"),i.setAttribute("data-editor-tooltip-common",n.disableReason)),t.appendChild(r),n.subText&&w("div",["item-subtext","text"],t,n.subText),n.children&&!n.element){const s=w("div",["menu-item-sub-indicator"],null);s.innerHTML=lv,t.appendChild(s)}if((o=n.states)!=null&&o.includes("checked")){const s=w("div",["menu-item-checked-icon"],null);s.innerHTML=PL,t.appendChild(s)}}}}class zs extends Zh{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){W(t,"menu")}initItemElement(t,e){sM(t,e)}}function lM(n,t,e){var o;return new zs((o=n.children)!=null?o:[],t,{...e,parentItem:n})}function Av(n,t,e){t.setAttribute("data-button-id",n.id),e.tooltipId&&n.name&&!n.disableTooltip&&(t.setAttribute(`data-editor-tooltip-${e.tooltipId}`,n.name),n.desc&&t.setAttribute(`data-editor-tooltip-desc-${e.tooltipId}`,n.desc));const o=t;if(!n.element)if(n.icon){const r=w("span",["toolbar-item-icon-container"],o);n.icon.trim().startsWith("<")?r.innerHTML=n.icon:r.innerText=n.icon}else{const r=w("span",["toolbar-item-name-container"],o);r.innerText=n.name}if(n.dropdown){t.setAttribute("data-dropdown","true");const r=w("span",["toolbar-item-dropdown-container"],o);r.innerHTML=Qh}n.states&&(n.states.indexOf("checked")!==-1&&W(o,"checked"),n.states.indexOf("disabled")!==-1&&(o.disabled=!0))}class ru extends Zh{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),a=this.content.getBoundingClientRect(),d=s.getBoundingClientRect();return new DOMRect(d.left,a.top,d.width,a.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){W(t,"toolbar")}initItemElement(t,e){Av(t,e,this.options)}}function cM(n,t,e){var o;return new ru((o=n.children)!=null?o:[],t,{...e,parentItem:n})}class aM extends ji{constructor(t,e,o){super(e,void 0,o),t.appendChild(this.content),document.addEventListener("keydown",this.handleDocumentKeydown),document.addEventListener("mousedown",this.handleDocumentMouseDown)}initCommandBarElement(t){W(t,"toolbar","fixed")}initItemElement(t,e){Av(t,e,this.options)}close(){this.clearSelectedItem(),this.subBar&&(this.subBar.close("cancelBar"),this.subBar=null)}destroy(){this.content.remove(),super.destroy(),document.removeEventListener("keydown",this.handleDocumentKeydown),document.removeEventListener("mousedown",this.handleDocumentMouseDown)}getCommandBarRoot(){return this.content.parentElement}get isVisible(){return!0}}const pnt="";ji.registerManualCommandBar("menu",lM),ji.registerManualCommandBar("toolbar",cM);const Cnt="",bv=S("ui-base");class iu extends Zh{constructor(e,o){super(iu.getCommandItems(e,o),void 0,{disablePageScroll:!0,...o});m(this,"handleDocumentMouseDown",e=>{})}initCommandBarElement(e){W(e,"dialog","manual")}initItemElement(e,o){}show(e,o){this.manualShow(e,{...o,theme:"light"})}get dialogContent(){const e=this.items[0];g(bv,e,"no dialog item");const o=e.element;return g(bv,o,"no item element"),o}static getCommandItems(e,o){var s;return[{id:(s=o==null?void 0:o.id)!=null?s:`manual-dialog-${K()}`,name:"",element:e}]}}const Ant="",uM=S("ui-base");class vv{constructor(t){m(this,"menu");m(this,"currentText","");m(this,"handleSearchText");m(this,"handleClick",Le.default((t,e)=>{this.options.onClickItem(this,e)},3e3,{leading:!0,trailing:!1}));m(this,"handleShow",t=>{});m(this,"handleClose",()=>{var t,e;(e=(t=this.options).onClose)==null||e.call(t)});m(this,"handleKeydown",t=>{this.menu.handleDocumentKeydown(t)});this.options=t,this.menu=new zs([],void 0,{id:t.id,header:t.header,footer:t.footer}),this.menu.addListener("click",this.handleClick),this.menu.addListener("close",this.handleClose),this.menu.addListener("show",this.handleShow),this.options.wait?this.handleSearchText=Le.default(async e=>{this.handleSearchTextPure(e)},this.options.wait):this.handleSearchText=this.handleSearchTextPure}setItems(t){if(this.menu.updateItems(t),t.length>0){const e=t.find(o=>o.type!=="section"&&o.type!=="separator");e&&this.menu.selectItem(e.id)}}async popup(t,e){var r,i;if(!(e!=null&&e.noEvent)&&((i=(r=this.options).onShow)==null?void 0:i.call(r,this))===!1)return;this.menu.manualShow(t),this.options.placeholder&&this.showPlaceholder();const o=await this.options.queryItems(this,"");this.highlightText("",o),this.setItems(o)}showLoading(){!this.options.showLoading||(this.options.loadingElement?this.setItems([{id:"loading",name:"",element:this.options.loadingElement,states:["disabled"]}]):this.setItems([{id:"loading",name:"loading",states:["disabled"]}]))}showPlaceholder(){this.setItems([{id:"placeholder",name:"enter text to search",states:["disabled"]}])}showNoResultMessage(t){if(this.options.noResultMessage){const e={name:"",id:"placeholder",states:["disabled"]};typeof this.options.noResultMessage=="string"?e.name=this.options.noResultMessage:(this.options.noResultMessage instanceof HTMLElement||typeof this.options.noResultMessage=="function")&&(e.element=this.options.noResultMessage),this.setItems([e])}else this.setItems([{id:"placeholder",name:this.options.emptyPlaceholder||R.t("search.emptyTips"),states:["disabled"]}])}close(){this.menu.close("cancelBar")}get isVisible(){return this.menu.isVisible}destroy(){this.menu.close("cancelBar"),this.menu.removeAllListeners(),this.menu.destroy()}async handleSearchTextPure(t){this.currentText=t;const e="auto-suggest";try{await Eo.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,""),r)}finally{Eo.release(e)}}highlightText(t,e){uM.debug(`highlight menu text: ${t}`);const o=this.menu.content,r=(s,l)=>{if(!l)return s;let a="";const d=l.length,h=l.toLocaleLowerCase();let p=0;for(p=0;p<=s.length-d;p){let A=s.substring(p,p+d);if(A.toLocaleLowerCase()===h){p+=d;const v=s.charAt(p);let B=!1;A.endsWith(" ")&&(B=!0,A=A.trimEnd()),a+=`<span class="highlight">${A}${v===" "||B?" ":""}</span>`}else a+=s.charAt(p),p++}return p<s.length&&(a+=s.substring(p)),a},i=s=>{if(xt(s,"text")){const l=e==null?void 0:e.find(h=>h.id===s.getAttribute("data-id"));if(l&&l.element)return;const a=s.textContent;if(!a)return;const d=r(a,t);s.innerHTML=d;return}Array.from(s.children).forEach(i)};i(o)}}class Lp{constructor(t,e){m(this,"root");m(this,"input");m(this,"text");m(this,"dropdownIcon");m(this,"clearIcon");m(this,"autoSuggest");m(this,"labels");m(this,"items",[]);m(this,"handleClick",()=>{this.autoSuggest.popup(this.root),this.input.focus()});m(this,"handleClickItem",(t,e)=>{var o,r;(r=(o=this.options)==null?void 0:o.onClickItem)==null||r.call(o,e)});m(this,"handleInput",()=>{this.autoSuggest.handleSearchText(this.input.value),this.updatePlaceholder()});m(this,"handleClear",t=>{var e,o;this.clear(),this.autoSuggest.handleSearchText(""),t.preventDefault(),t.stopPropagation(),(o=(e=this.options)==null?void 0:e.onClear)==null||o.call(e)});m(this,"handleQueryItems",async(t,e)=>this.items.filter(r=>{var i;return(i=this.options)!=null&&i.filter?this.options.filter(r,e):!0}));m(this,"handleShow",()=>{W(this.root,"active"),this.input.focus()});m(this,"handleClose",()=>{var t,e;(e=(t=this.options)==null?void 0:t.onClose)==null||e.call(t),ot(this.root,"active")});var a,d,h,p,A;this.options=e,this.labels=(d=(a=this.options)==null?void 0:a.labels)!=null?d:[];const{root:o,input:r,text:i,clearIcon:s,dropdownIcon:l}=Lp.createDropdown(t,this.labels);this.root=o,this.input=r,this.text=i,this.clearIcon=s,this.dropdownIcon=l,this.autoSuggest=new vv({id:(e==null?void 0:e.popupId)||"dropdown-auto-suggest",header:(h=this.options)==null?void 0:h.header,onClickItem:this.handleClickItem,queryItems:this.handleQueryItems,onClose:this.handleClose,onShow:this.handleShow,highlight:e==null?void 0:e.highlight,emptyPlaceholder:e==null?void 0:e.emptyPlaceholder}),this.items=(A=(p=this.options)==null?void 0:p.items)!=null?A:[],this.root.addEventListener("click",this.handleClick),this.input.addEventListener("input",this.handleInput),this.clearIcon.addEventListener("click",this.handleClear)}close(){this.autoSuggest.close()}destroy(){this.input.removeEventListener("input",this.handleInput),this.root.removeEventListener("click",this.handleClick),this.clearIcon.removeEventListener("click",this.handleClear),this.autoSuggest.destroy()}updateItems(t){this.items=t,this.autoSuggest.handleSearchText("")}setText(t){this.text.innerText=t,this.input.value=t,this.updatePlaceholder()}clear(){this.setText(""),this.setLabels([])}setLabels(t){this.labels=t,this.updateLabels()}static createDropdown(t,e){const o=w("div",["editor-dropdown","empty"],t),r=w("input",["dropdown-input"],o),i=w("div",["dropdown-text"],o),s=w("div",["dropdown-labels"],o);for(let d=0;d<e.length;d+=1){const h=e[d];w("span",["dropdown-label"],s,h)}const l=w("div",["dropdown-clear-icon"],o);l.innerHTML=oM;const a=w("div",["dropdown-icon"],o);return a.innerHTML=Qh,{root:o,input:r,text:i,clearIcon:l,dropdownIcon:a}}updateLabels(){const t=this.root.querySelector(".dropdown-labels");if(t){t.innerHTML="";for(let e=0;e<this.labels.length;e+=1){const o=this.labels[e];w("span",["dropdown-label"],t,o)}}}updatePlaceholder(){var t;if(this.input.value===""){const e=(t=this.options)==null?void 0:t.placeholder;e&&(this.input.placeholder=e,this.text.textContent=e),W(this.root,"empty")}else ot(this.root,"empty")}}const dM=[-1,6,0,1,2,3,4,5],hM=[-1,6,0,1,2,3,4,5,14,13,7,8,9,10,11,12],yv=S("color-palette");function kv(n,t,e,o){g(yv,n>0,"no color in palette");const r=t||1;g(yv,r>0,`invalid palette rows: ${r}`);const i=n/r,s=w("div",["palette-container",o],null);for(let l=0;l<r;l++){const a=w("div",["palette-container-row"],s);for(let d=0;d<i;d++){const h=e(l*i+d);a.appendChild(h)}}return s}function fM(n){const t=w("button",["color-button"],null),e=dM[n];return t.setAttribute("data-color-index",`${e}`),t.innerHTML=sv,t}function mM(n){const t=w("button",["background-color-button"],null),e=hM[n];return t.setAttribute("data-color-index",`${e}`),t}function gM(){const n=w("div",["clear-button-container"],null),t=w("button",["clear-button"],n);return t.innerText=R.t("colorPalette.reset"),n}function pM(n){const t=w("div",["color-palette"],null);return n.color!==!1&&(w("div",["bar-desc"],t,R.t("colorPalette.colorDesc")),t.appendChild(kv(8,1,fM,"color"))),n.backgroundColor!==!1&&(w("div",["bar-desc"],t,R.t("colorPalette.backgroundDesc")),t.appendChild(kv(16,2,mM,"background-color"))),n.clearColorButton!==!1&&t.appendChild(gM()),t}function CM(n,t,e){const o=t==="color"?"color":"background-color",r=n.querySelector(`.${o} button.selected`);r&&ot(r,"selected"),e===null&&(e=-1);const i=n.querySelector(`.${o} button[data-color-index="${e}"]`);i&&W(i,"selected")}const bnt="",AM={};class bM extends ye.TypedEmitter{constructor(e=AM){super();m(this,"root");m(this,"handleClick",e=>{const o=e.target;if(!o||!(o instanceof Element))return;const r=o.closest("button");if(!r)return;if(xt(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)||(xt(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=pM(e),this.root.addEventListener("click",this.handleClick)}destroy(){this.removeAllListeners(),this.root.removeEventListener("click",this.handleClick)}setColor(e,o){CM(this.root,e,o)}}class wv{constructor(t,e){m(this,"name","Color Palette");m(this,"element");m(this,"palette");m(this,"closeable",null);this.id=t,this.palette=new bM(e),this.element=this.palette.root}setCloseable(t){this.closeable=t}destroy(){this.palette.destroy(),this.closeable=null}}function vM(){const n=w("button",["color-button"],null);return n.innerHTML=sv,n}function Mp(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 yM extends ye.TypedEmitter{constructor(e){super();m(this,"id","text-color-item");m(this,"name",R.t("colorPalette.name"));m(this,"dropdown",!0);m(this,"manualShowChildren",!0);m(this,"children",[]);m(this,"element");m(this,"colorPaletteItem");m(this,"latestColors",[null,null]);m(this,"handlePaletteClick",(e,o)=>{this.emit("onClick",e,o),e==="color"||e==="backgroundColor"?e==="color"?this.latestColors[0]=o:this.latestColors[1]=o:this.latestColors=[null,null],Mp(this.element,this.latestColors)});m(this,"beforePopup",()=>{this.emit("beforePopup")});this.editor=e,this.colorPaletteItem=new wv("text-color-palette-item"),this.colorPaletteItem.palette.addListener("onClick",this.handlePaletteClick),this.children.push(this.colorPaletteItem),this.element=vM()}destroy(){this.colorPaletteItem.destroy()}updatePaletteColor(e){this.colorPaletteItem.palette.setColor("color",e[0]),this.colorPaletteItem.palette.setColor("backgroundColor",e[1]),this.latestColors=e,Mp(this.element,this.latestColors)}updateButtonColor(e){this.latestColors=e,Mp(this.element,this.latestColors)}}const vnt="";function Rp(n,t){const e=w("div",["editor-input-wrap"],n);t!=null&&t.className&&W(e,t==null?void 0:t.className);const o=w("div",["editor-input-label"],e);w("span",[],o,t.label),t.required&&W(o,"required");const r=w("div",["editor-input-container"],e),i=w("input",["editor-input"],r);t.placeholder&&(i.placeholder=t.placeholder),t.defaultValue&&(i.value=t.defaultValue);const s=w("div",["editor-input-error"],e);return i.addEventListener("input",l=>{var a;(a=t.onChange)==null||a.call(t,l),ot(e,"error")}),i.addEventListener("keydown",l=>{var a;(a=t.onKeyDown)==null||a.call(t,l)}),{getField:()=>i,getInputValue:()=>i.value,setFieldError:l=>{W(e,"error"),s.innerText=l},focus:()=>{setTimeout(()=>{i.focus()})}}}function Op(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}class kM extends vv{constructor(e,o){super(o);m(this,"handleClose",()=>{var e,o;Op(this.editor)&&this.editor.focus(),(o=(e=this.options).onClose)==null||o.call(e)});this.editor=e,this.editorOptions=o}async popupInEditor(e,o,r){var d,h;if(((h=(d=this.editorOptions).onShow)==null?void 0:h.call(d,this,e,o,r))===!1)return;this.options.showLoading&&this.showLoading();const i=this.editor.getBlockByIndex(e,o);if(!Xt(this.editor.rootContainer,i)||ut(this.editor,i)<r)return;const s=Nr(this.editor,i,Ce(this.editor,i,r));if(s.length===0)return;const l=s[0],a=zr(this.editor,i,"editor-auto-suggest-menu",l);super.popup(a,{noEvent:!0})}}const _p=S("auto-suggest-menu");class Fp{constructor(t,e){m(this,"order",100);m(this,"menu");m(this,"anchor",null);m(this,"close",()=>{this.menu.close()});m(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(ie(In(gn(t,i),e.offset).left).startsWith(this.anchor.leftText))return}this.menu.close()});m(this,"deleteTrigger",()=>{const t=this.editor,e=t.selection.range.start;if(!e.isSimple()||!this.anchor)return!1;const{blockId:o,offset:r}=e,i=t.getBlockById(o),s=ie(Ah(t,i,r));if(g(_p,this.anchor,"no anchor"),!s.startsWith(this.anchor.leftText))return!1;const l=this.anchor.offset-this.anchor.trigger.length,a=r-l;return t.selection.selectBlock(i,l),a&&(t.deleteTextFromBlock(i,l,a),this.anchor.offset-=this.anchor.trigger.length),this.anchor.trigger.length||this.menu.close(),!0});m(this,"onClose",()=>{var t,e;(e=(t=this.options).onClose)==null||e.call(t)});m(this,"onShow",(t,e,o,r)=>{var i;if((i=this.options)!=null&&i.onShow)return this.options.onShow(this,e,o,r)});m(this,"onClickItem",(t,e)=>{!this.anchor||(this.options.autoDeleteTrigger&&this.deleteTrigger(),this.options.onClickItem(this,e,this.anchor))});m(this,"queryItems",(t,e)=>this.options.queryItems(this,e));m(this,"renderMenuItem",(t,e)=>{var 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 kM(t,{id:e.id,showLoading:e.showLoading,loadingElement:e.loadingElement,placeholder:e.placeholder,header:e.header,footer:e.footer,wait:e.wait,noResultMessage:e.noResultMessage,highlight:e.highlight,onClose:this.onClose,onShow:this.onShow,onClickItem:this.onClickItem,queryItems:this.queryItems,renderMenuItem:this.renderMenuItem}),t.input.addHandler(this),t.addListener("selectionChanged",this.handleSelectionChanged)}handleBeforeKeyDown(t,e){var o;return!((o=this.menu)!=null&&o.isVisible)||Bm(e.key)?!1:vC(e)&&!ws(e)?(setTimeout(()=>{this.resetItems()}),!1):Em(e)?(this.menu.close(),!0):(this.menu.handleKeydown(e),!0)}popup(t,e,o,r){this.anchor={blockId:it(t),offset:e,leftText:o,trigger:r};const i=at(nt(t)),s=bt(t);this.menu.popupInEditor(i,s,e)}handleAfterInsertText(t,e,o,r,i){var h,p;const s=t.selection.range.start;if(!s.isSimple()||!this.options.enableFirstBlock&&e==="root"&&o===0)return!1;const{blockId:l,offset:a}=s,d=t.getBlockByIndex(e,o);if(it(d)!==l)return!1;if((h=this.menu)!=null&&h.isVisible)this.resetItems();else if(this.options.trigger.indexOf(i)!==-1){if(r>0&&this.options.needSpaceBeforeTrigger&&(((p=t.getBlockData(d).text)==null?void 0:p.reduce((D,x)=>D+x.insert,""))||"")[r-1]!==" "||ji.hasExistsCommandBar())return!1;const A=ie(Ah(t,d,a));this.popup(d,a,A,i)}return!1}handleUpdateCompositionText(t,e,o,r,i){var d;const s=t.selection.range.start;if(!s.isSimple())return!1;const{blockId:l}=s,a=t.getBlockByIndex(e,o);return it(a)!==l||(d=this.menu)!=null&&d.isVisible&&this.resetItems(),!1}resetItems(){var l;if(!((l=this.menu)!=null&&l.isVisible))return;const t=this.editor,e=t.selection.range.start;if(!e.isSimple())return;const{blockId:o,offset:r}=e,i=t.getBlockById(o),s=ie(Ah(t,i,r));if(g(_p,this.anchor,"no anchor"),s.startsWith(this.anchor.leftText)){const a=s.substring(this.anchor.leftText.length);_p.debug(`search text: ${a}`),this.menu.handleSearchText(a)}}destroy(){var t;this.editor.input.removeHandler(this),this.editor.removeListener("selectionChanged",this.handleSelectionChanged),(t=this.menu)==null||t.destroy()}}function wM(){const n={};for(let t=1;t<=8;t++)n[`heading-${t}`]={shortcut:`/h${t}`};return n}const BM={"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"},...wM()};function Cn(n){var t;return(t=BM[n])==null?void 0:t.shortcut}function EM(n){var t;return(t=n.subText)!=null?t:""}const fr=S("table-dom");function mr(n){return`${it(n)}_scroll`}function _e(n){const t=n.querySelector("div[data-type=table-content] >table");return g(fr,t instanceof HTMLTableElement,"invalid table"),t}function gr(n,t){const o=n.getCustom(mr(t)).contentElement.firstElementChild;g(fr,o instanceof HTMLElement,"invalid table content");let r=o.querySelector(":scope >div[data-type=table-tools]");return r||(r=w("div",[],o),r.setAttribute("data-type","table-tools"),n.domEvents.addEventListener(r,"dblclick",(i,s)=>s.stopPropagation()),n.domEvents.addEventListener(r,"click",(i,s)=>{s.detail===3&&s.stopPropagation()})),g(fr,r,"no table tools"),r}function xM(n,t){return n.findCustom(mr(t))?gr(n,t):null}function Bv(n){const t=[];return Array.from(n.rows).forEach(e=>{t.push(...Array.from(e.cells))}),t}function su(n){const t=n.querySelector(":scope div[data-type=editor-container]");return g(fr,t,"no child container in cell"),t}function IM(n){const o=Bv(n).map(r=>{const i=su(r),s=at(i),l=r.colSpan,a=r.rowSpan;return`${s}/${l}/${a}`}).join();return Pd.default(o)}function Ve(n){return Dt(n)==="table"}function Pp(n){const t=nt(n);if(Yt(t))return null;const e=et(t);return g(fr,e,"no parent block"),Ve(e)?t:Pp(e)}function Yr(n){if(Ve(n))return n;const t=nt(n);if(Yt(t))return null;const e=et(t);return g(fr,e,"no parent block"),Ve(e)?e:Yr(e)}function TM(n,t){const e=n.querySelector("colgroup");g(fr,e,"no colgroup");const o=e.children[t];return g(fr,o,"no col"),g(fr,o instanceof HTMLTableColElement,`invalid col: ${o.tagName}`),o}function Ev(n){try{return _e(n),!0}catch{return!1}}function DM(n){return te(n).querySelector(":scope > .block-helper")}function xv(n){const t=et(n.contentElement);g(fr,t,"no block");const e=DM(t);if(e){const i=Math.min(n.contentElement.offsetLeft+29,n.rootElement.scrollLeft),s=t.getBoundingClientRect().width;e.style.right=`${i+s+5}px`}}const Gn=S("doc-table-grid");class SM{constructor(t){m(this,"_cells",[]);for(let e=0;e<t;e++)this._cells.push(void 0)}cols(){return this._cells.length}setCell(t,e){g(Gn,t>=0&&t<this.cols(),`set cell, invalid col: ${t}`),this._cells[t]=e}getCell(t){g(Gn,t>=0&&t<this.cols(),`get cell, invalid col: ${t}`);const e=this._cells[t];return g(Gn,e,"get cell, no cell"),e}getCellAllowEmpty(t){return g(Gn,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 Yh{constructor(t){m(this,"_data");m(this,"_rows");this._data=t,this._rows=[];for(let e=0;e<this.rowCount;e++)this._rows.push(new SM(this.colCount));this.fillGrid(),g(Gn,t.colsWidth,"no colsWidth"),g(Gn,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;g(Gn,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 d=0;d<l;d++)for(let h=0;h<s;h++)this._rows[o+d].setCell(e+h,{col:e,row:o,containerId:r,virtual:h!==0||d!==0,colSpan:s,rowSpan:l});const a=this.getNextEmptyCell(e,o);a?(e=a.col,o=a.row):g(Gn,i===t.length-1,`invalid table data, no next empty cell: ${JSON.stringify(this._data)}`)}),this._rows.forEach(r=>{r.forEach(i=>{g(Gn,i,"no cell"),g(Gn,i.containerId,"no containerId")})})}getCell(t){const{col:e,row:o}=t,r=this._rows[o];g(Gn,r,`get cell, no row: ${o}`);const i=r.getCell(e);return g(Gn,i,`get cell, no cell: ${e}`),i}getRow(t){const e=this._rows[t];return g(Gn,e,`get row, no row: ${t}`),e}forEach(t){this._rows.forEach(t)}}const Jh=S("table-data");function LM(n){const t=n.firstElementChild;return g(Jh,t,"no child element for cell"),g(Jh,Pr(t),"cell first child is not a container"),g(Jh,Lo(t),"cell first child is not a container"),t}function MM(n){const t=et(n);g(Jh,t,"no parent block for table");const e=[],o={};Array.from(n.rows).forEach(l=>{Array.from(l.cells).forEach(a=>{const d=LM(a),h=at(d);e.push(h),(a.colSpan>1||a.rowSpan>1)&&(o[`${h}_colSpan`]=a.colSpan,o[`${h}_rowSpan`]=a.rowSpan)})});const r=n.rows.length,i=Array.from(n.rows[0].cells).map(l=>l.colSpan).reduce((l,a)=>l+a,0);return{id:it(t),type:Dt(t),rows:r,cols:i,children:e,colsWidth:Array(i).fill(100),...o}}function Vs(n){return new Yh(n)}function RM(n){return Vs(MM(n))}const We=S("table-grid"),OM=60;class _M{constructor(t,e){m(this,"containerId");m(this,"row");m(this,"col");m(this,"colSpan");m(this,"rowSpan");m(this,"virtual");m(this,"table");this.table=t,this.containerId=e.containerId,this.row=e.row,this.col=e.col,this.colSpan=e.colSpan,this.rowSpan=e.rowSpan,this.virtual=e.virtual}get cell(){const e=this.container.closest("td");return g(We,e,"no parent cell for child container"),e}get container(){const t=this.table.querySelectorAll(`[data-container-id=${this.containerId}]`);g(We,t.length===1,"containers !== 1"),g(We,Pr(t[0]),"not a container");const e=t[0];return g(We,Lo(e),"not a child container"),e}}class FM{constructor(t,e){m(this,"_cells",[]);e.forEach(o=>{this._cells.push(new _M(t,o))})}get cells(){return this._cells}getCell(t){return g(We,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 K2=class{constructor(t){m(this,"_rows",[]);this.table=t,RM(t).forEach(r=>{this._rows.push(new FM(t,r))});const o=this.colCount;this._rows.forEach(r=>{g(We,r.cells.length===o,"row.cells.length !== colCount")})}get rowCount(){return this._rows.length}get colCount(){return this._rows.length===0?0:(g(We,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 g(We,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){g(We,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){g(We,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 g(We,!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)}),g(We,o<=r,"min > max"),g(We,o>=0,"min < 0"),g(We,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)}),g(We,o<=r,"min > max"),g(We,o>=0,"min < 0"),g(We,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 v=o;v<=r;v++)for(let B=i;B<=s;B++)l.push(this.getCell({row:v,col:B}));const a=this.toRealCells(l);let d=1e4,h=1e4,p=-1,A=-1;return a.forEach(v=>{h=Math.min(v.col,h),d=Math.min(v.row,d),A=Math.max(v.col+v.colSpan-1,A),p=Math.max(v.row+v.rowSpan-1,p)}),[{row:d,col:h},{row:p,col:A}]}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),a=Math.max(i.row,s.row),d=Math.min(i.col,s.col),h=Math.max(i.col,s.col);for(let p=l;p<=a;p++)for(let A=d;A<=h;A++){const v=this.getCell({row:p,col:A});v.virtual||o.push(v)}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 g(We,o,"cell not found"),o}getCellByCellElement(t){const e=su(t);return this.getCellByContainerId(at(e))}getCellByContainerId(t){return this.getCellById(t)}static fromTable(t){const e=IM(t),o=this.caches.getSync(e,()=>(We.debug("create table grid"),new K2(t)));return o.table!==t?(this.caches.delete(e),this.fromTable(t)):o}static fromBlock(t){return this.fromTable(_e(t))}};let Tt=K2;m(Tt,"caches",new X5(OM));function Kh(n,t){Object.entries(n).forEach(([e])=>{e.startsWith(`${t}/`)&&delete n[e]})}const PM=S("table-selection-range");function Uo(n,t,e){var M,H,z,q;const o=Tt.fromBlock(n),r=t,i=e,s=o.getCellByContainerId(r.childContainerId),l=o.getCellByContainerId(i.childContainerId),a=r.custom,d=i.custom,h=(M=a==null?void 0:a.rowIndex)!=null?M:s.row,p=(H=a==null?void 0:a.colIndex)!=null?H:s.col,A=(z=d==null?void 0:d.rowIndex)!=null?z:l.row+l.rowSpan-1,v=(q=d==null?void 0:d.colIndex)!=null?q:l.col+l.colSpan-1,B=Math.min(h,A),D=Math.max(h,A),x=Math.min(p,v),_=Math.max(p,v);return{fromRow:B,toRow:D,fromCol:x,toCol:_}}function Np(n,t){const e=new Set,o=new Set,r=n.selection.range;if(!r.isSimple()&&r.start.blockId===it(t)){const i=Tt.fromBlock(t),{start:s,end:l}=r;g(PM,!s.isSimple()&&!l.isSimple(),"invalid range");const{fromCol:a,toCol:d,fromRow:h,toRow:p}=Uo(t,s,l);if(h===0&&p===i.rowCount-1)for(let A=a;A<=d;A++)o.add(A);if(a===0&&d===i.colCount-1)for(let A=h;A<=p;A++)e.add(A)}return{selectedRows:e,selectedColumns:o}}function lu(n,t){let e=null;if(t.isCollapsed()&&t.isSimple()){const o=n.getBlockById(t.start.blockId);if(Ve(o)){const r=nt(o),i=et(r);i&&(e=Yr(i))}else e=Yr(o)}else{const o=n.getBlockById(t.start.blockId),r=Yr(o),i=n.getBlockById(t.end.blockId),s=Yr(i);r===s&&(e=r)}return e}const nc=S("delete-columns");function Iv(n,t,e){const{start:o,end:r}=e;if(o.blockId!==r.blockId||e.isSimple()||n.getBlockById(o.blockId)!==t||Dt(t)!=="table")return!1;const{fromRow:s,toRow:l}=Uo(t,e.start,e.end),a=Tt.fromBlock(t);return s===0&&l===a.rowCount-1}function $p(n){const t=n.getEditor();t.undoManager.runInGroup(()=>{var H;const e=t.getBlockById(n.start.blockId);if(!Iv(t,e,n))return;if(n.isSimple()){t.deleteBlock(e);return}const{fromCol:o,toCol:r}=Uo(e,n.start,n.end),i=Tt.fromBlock(e);if(o===0&&r===i.colCount-1){t.deleteBlock(e);return}const s=new Set,l=i.map(z=>z.containerId);for(let z=0;z<l.length;z++){const q=l[z];for(let rt=o;rt<=r;rt++){const ft=q[rt];s.add(ft)}q.splice(o,r-o+1)}const a=new Set(l.flat()),d=new Set(Array.from(s).filter(z=>!a.has(z))),h=r-o+1,p=new Map,A=new Map;s.forEach(z=>{if(d.has(z))return;const q=i.getCellByContainerId(z);if(g(nc,q.colSpan>1,"invalid effected cell, colSpan === 1"),q.col<o){g(nc,a.has(z),"invalid effected cell, not exists");let ne=q.col+q.colSpan-1;ne>r&&(ne=r);const qe=ne-o+1,Yn=q.colSpan-qe;p.set(z,Yn);return}g(nc,q.col<=r,"invalid effected cell, col > endCol");const rt=q.col,ft=q.col+q.colSpan-1,Bt=q.col-o,jt=ft-rt+1-h+Bt;g(nc,jt>0,"invalid effected cell, newSpanned <= 0");const Ut=qr(t.doc);A.set(z,{newContainerId:Ut,colSpan:jt})});for(let z=0;z<l.length;z++){const q=l[z];for(let rt=o;rt<q.length;rt++){const ft=q[rt],Bt=A.get(ft);Bt&&(q[rt]=Bt.newContainerId)}}const v=mt.default(t.getBlockData(e));v.colsWidth.splice(o,r-o+1),d.forEach(z=>{Kh(v,z)}),p.forEach((z,q)=>{g(nc,z>=1,"invalid modified colSpan, colSpan < 1"),z===1?v[`${q}_colSpan`]=void 0:v[`${q}_colSpan`]=z}),A.forEach((z,q)=>{Kh(v,q);const{newContainerId:rt,colSpan:ft}=z;g(nc,ft>=1,"invalid newContainerData, colSpan < 1"),ft>1&&(v[`${rt}_colSpan`]=ft);const Bt=i.getCellByContainerId(q).rowSpan;Bt>1&&(v[`${rt}_rowSpan`]=Bt)});const D=(H=l[0][o])!=null?H:l[0][o-1],x=t.getChildContainerData(D)[0],_=Tt.virtualCellContainersGridToChildren(l),M={...v,cols:v.cols-h,children:_};Vs(M),t.updateBlockData(e,M,Ce(t,x.id,0)),t.deleteChildContainers(Array.from(d)),t.deleteChildContainers(Array.from(A.keys()))})}const oc=S("delete-rows");function Tv(n,t,e){const{start:o,end:r}=e;if(o.blockId!==r.blockId||e.isSimple()||n.getBlockById(o.blockId)!==t||Dt(t)!=="table")return!1;const{fromCol:s,toCol:l}=Uo(t,e.start,e.end),a=Tt.fromBlock(t);return s===0&&l===a.colCount-1}function Hp(n){const t=n.getEditor();t.undoManager.runInGroup(()=>{const e=t.getBlockById(n.start.blockId);if(!Tv(t,e,n))return;if(n.isSimple()){t.deleteBlock(e);return}const{fromRow:o,toRow:r}=Uo(e,n.start,n.end),i=Tt.fromBlock(e);if(o===0&&r===i.rowCount-1){t.deleteBlock(e);return}const s=new Set,l=i.map(M=>M.containerId);for(let M=r;M>=o;M--)l[M].forEach(z=>s.add(z)),l.splice(M,1);const a=new Set(l.flat()),d=new Set(Array.from(s).filter(M=>!a.has(M))),h=r-o+1,p=new Map,A=new Map;s.forEach(M=>{if(d.has(M))return;const H=i.getCellByContainerId(M);if(g(oc,H.rowSpan>1,"invalid effected cell, rowSpan === 1"),H.row<o){g(oc,a.has(M),"invalid effected cell, not exists");let jt=H.row+H.rowSpan-1;jt>r&&(jt=r);const Ut=jt-o+1,ne=H.rowSpan-Ut;p.set(M,ne);return}g(oc,H.row<=r,"invalid effected cell, col > endCol");const z=H.row,q=H.row+H.rowSpan-1,rt=H.row-o,ft=q-z+1-h+rt;g(oc,ft>0,"invalid effected cell, newSpanned <= 0");const Bt=qr(t.doc);A.set(M,{newContainerId:Bt,rowSpan:ft})});for(let M=o;M<l.length;M++){const H=l[M];for(let z=0;z<H.length;z++){const q=H[z],rt=A.get(q);rt&&(H[z]=rt.newContainerId)}}const v=mt.default(t.getBlockData(e));d.forEach(M=>{Kh(v,M)}),p.forEach((M,H)=>{g(oc,M>=1,"invalid modified rowSpan, rowSpan < 1"),M===1?v[`${H}_rowSpan`]=void 0:v[`${H}_rowSpan`]=M}),A.forEach((M,H)=>{Kh(v,H);const{newContainerId:z,rowSpan:q}=M;g(oc,q>=1,"invalid newContainerData, rowSpan < 1"),q>1&&(v[`${z}_rowSpan`]=q);const rt=i.getCellByContainerId(H).colSpan;rt>1&&(v[`${z}_colSpan`]=rt)});const B=l[o]?l[o][0]:l[o-1][0],D=t.getChildContainerData(B)[0],x=Tt.virtualCellContainersGridToChildren(l),_={...v,rows:v.rows-h,children:x};Vs(_),t.updateBlockData(e,_,Ce(t,D.id,0)),t.deleteChildContainers(Array.from(d)),t.deleteChildContainers(Array.from(A.keys()))})}const cu=S("table-range");function Xh(n){g(cu,!n.isSimple(),"must be complex selection range");const{anchor:t,focus:e}=n;g(cu,!t.isSimple(),"invalid start pos type"),g(cu,!e.isSimple(),"invalid end pos type");const o=n.getEditor();g(cu,t.blockId===e.blockId,"invalid range, not same block");const r=o.getBlockById(t.blockId);g(cu,Dt(r)==="table","invalid block type, not a table block");const i=_e(r),s=Tt.fromTable(i),l=s.getCellByContainerId(t.childContainerId),a=s.getCellByContainerId(e.childContainerId),d=Math.min(l.row,a.row),h=Math.max(l.row,a.row),p=Math.min(l.col,a.col),A=Math.max(l.col,a.col),v=s.getCell({row:d,col:p}),B=s.getCell({row:h,col:A});return{editor:o,block:r,table:i,startCell:v,endCell:B,startRow:d,startCol:p,endRow:h,endCol:A}}const jp=S("split-cell");function Up(n,t,e){n.undoManager.runInGroup(()=>{const o=Tt.fromBlock(t),r=o.getRealCell(e);g(jp,!r.virtual,"should not split virtual cell"),g(jp,r.colSpan>1||r.rowSpan>1,"cell does not has span data");const i=o.getVirtualCellContainersGrid();for(let p=0;p<r.rowSpan;p++)for(let A=0;A<r.colSpan;A++){if(p===0&&A===0)continue;const v=p+r.row,B=A+r.col,D=qr(n.doc);i[v][B]=D}const s=n.getBlockData(t),l=mt.default(s);l[`${r.containerId}_colSpan`]=null,l[`${r.containerId}_rowSpan`]=null,l.children=Tt.virtualCellContainersGridToChildren(i);const d=n.getChildContainerData(r.containerId)[0];g(jp,d,"no child block");const h=Ce(n,d.id,0);Vs(l),n.updateBlockData(t,l,h)})}function NM(n,t,e){e.forEach(o=>{const r=Tt.fromBlock(t).getCell(o);(r.virtual||r.colSpan>1||r.rowSpan>1)&&Up(n,t,o)})}function Dv(n,t,e){if(e.isSimple())return!1;const{start:o,end:r}=e;if(o.blockId!==r.blockId||n.getBlockById(o.blockId)!==t||Dt(t)!=="table")return!1;const{startCell:s,endCell:l}=Xh(e);return!(s.cell!==l.cell||s.colSpan===1&&s.rowSpan===1)}function zp(n){const{editor:t,block:e,startRow:o,startCol:r,endRow:i,endCol:s}=Xh(n),l=[];for(let a=o;a<=i;a++)for(let d=r;d<=s;d++)l.push({row:a,col:d});return NM(t,e,l),!0}const rc=S("merge-cells");function Sv(n,t,e){if(e.isSimple())return!1;const{start:o,end:r}=e;if(o.blockId!==r.blockId||n.getBlockById(o.blockId)!==t||Dt(t)!=="table")return!1;const{startCell:s,endCell:l}=Xh(e);return s.cell!==l.cell}function Lv(n){const t=Xh(n),e=t.editor;e.undoManager.runInGroup(()=>{const o=t.endCell,r=o.row+o.rowSpan-1,i=o.col+o.colSpan-1,s=it(t.block);zp(n);const l=e.getBlockById(s),a=_e(l),{startRow:d,startCol:h}=t,p=mt.default(e.getBlockData(l));g(rc,p.children,"no table children");const A=Tt.fromTable(a),v=[];for(let jt=d;jt<=r;jt++)for(let Ut=h;Ut<=i;Ut++){const ne=A.getCell({row:jt,col:Ut});g(rc,!ne.virtual,"cell is virtual"),v.push(ne)}g(rc,v.length>0,"no selected cells");const B=v[0],D=v.slice(1),x=A.getCellByContainerId(B.containerId).container,_=[];D.forEach(jt=>{const Ut=A.getCellByContainerId(jt.containerId).container,ne=at(Ut);if(!Ba(e,Ut)){const qe=PA(e,ne);if(Ba(e,x)){const Yn=pe(x)[0];e.insertDocAt(x,0,qe),e.deleteBlock(Yn)}else e.insertDocAt(x,Io(x),qe)}_.push(ne)});const M=at(x),H=i-h+1,z=r-d+1;p[`${M}_colSpan`]=H,p[`${M}_rowSpan`]=z,_.forEach(jt=>{g(rc,p.children,"no table children");const Ut=p.children.indexOf(jt);g(rc,Ut>0,"no deleted container"),p.children.splice(Ut,1)});const q=p,ft=e.getChildContainerData(M)[0];g(rc,ft,"no child block");const Bt=Ce(e,ft.id,0);Vs(q),e.updateBlockData(l,q,Bt),e.deleteChildContainers(_)})}const Vp=10,$M=["table/merge-cells","table/split-cell","table/insert-column","table/insert-row","table/delete-rows","table/delete-columns","table/delete"];class Wp{constructor(){m(this,"id","TableBlockCommandProvider")}getAvailableCommands(t,e,o){if(Dt(e)!=="table")return[];const r={blockId:it(e),blockKind:Do(t,e),blockType:Dt(e)},i=[];Sv(t,e,o)&&i.push({id:"table/merge-cells",name:R.t("table.mergeCell"),icon:kL,groupIndex:Vp,...r}),Dv(t,e,o)&&i.push({id:"table/split-cell",name:R.t("table.splitCell"),icon:wL,groupIndex:Vp,...r});const s=Iv(t,e,o),l=Tv(t,e,o);return s&&l&&i.push({id:"table/delete",name:R.t("table.deleteTable"),icon:BL,groupIndex:Vp,...r}),i}executeCommand(t,e,o,r,i,s){return Dt(e)!=="table"||!new Set($M).has(r.id)?!1:r.id==="table/merge-cells"?(Lv(o),!0):r.id==="table/split-cell"?(zp(o),!0):r.id==="table/delete-columns"?($p(o),!0):r.id==="table/delete-rows"?(Hp(o),!0):r.id==="table/delete"?(t.deleteBlock(e),!0):!1}}var Mv=(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))(Mv||{});const zi=6,ic=20,qp="table-cell-menu-btn";function HM(n,t){if(!n.isBlockWritable(t))return;const o={...mt.default(n.getBlockData(t)),hasColTitle:!0};n.updateBlockData(t,o)}function jM(n,t){if(!n.isBlockWritable(t))return;const o={...mt.default(n.getBlockData(t)),hasColTitle:!1};n.updateBlockData(t,o)}function UM(n,t){if(!n.isBlockWritable(t))return;const o={...mt.default(n.getBlockData(t)),hasRowTitle:!0};n.updateBlockData(t,o)}function zM(n,t){if(!n.isBlockWritable(t))return;const o={...mt.default(n.getBlockData(t)),hasRowTitle:!1};n.updateBlockData(t,o)}function VM(n,t){if(!n.isBlockWritable(t))return;const o={...mt.default(n.getBlockData(t)),isStripeStyle:!0};n.updateBlockData(t,o)}function WM(n,t){if(!n.isBlockWritable(t))return;const o={...mt.default(n.getBlockData(t)),isStripeStyle:!1};n.updateBlockData(t,o)}function qM(n,t,e){if(!n.isBlockWritable(t))return;const r={...mt.default(n.getBlockData(t)),noBorder:!e};n.updateBlockData(t,r)}const Gp=S("get-selected-containers");function Zp(n,t,e,o){g(Gp,e.blockId===o.blockId,"only allow select in single table block"),g(Gp,it(t)===e.blockId,"only allow select in single table block");const r=Tt.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(x=>r.getCellContainer(x));const{fromCol:l,toCol:a,fromRow:d,toRow:h}=Uo(t,e,o),p=new Set,A=[];return r.sub({row:d,col:l},{row:h,col:a}).forEach(B=>{B.forEach(D=>{const x=r.getCellByContainerId(D.containerId);x.col<l||x.row<d||x.col+x.colSpan-1>a||x.row+x.rowSpan-1>h||p.has(D.containerId)||(p.add(D.containerId),A.push(x.container))})}),A}function GM(n,t,e){g(Gp,t.blockId===e.blockId,"only allow select in single table block");const o=n.getBlockById(t.blockId);return Zp(n,o,t,e)}const Ws=S("table-cell-dom");function ZM(n,t,e){let o=n.getBlockById(e);for(;o;){const r=o.closest("td");g(Ws,r,"no parent cell");const i=et(r);if(g(Ws,i,"no parent block"),i===t)return r;o=i}return g(Ws,!1,"filed to get cell by child block id"),null}function Jr(n,t,e){if(n.getBlockById(e.blockId)===t&&!e.isSimple())return g(Ws,e.childContainerId,"block position must have childContainerId attribute"),e;const r=ZM(n,t,e.blockId),i=at(su(r));return fe(t,i)}function Qp(n,t){const e=n.selection.range,o=Jr(n,t,e.start),r=Jr(n,t,e.end);return Uo(t,o,r)}function Rv(n,t,e,o){g(Ws,Ve(t),"invalid table block");const r=gr(n,t),i=te(t),s=()=>{const a=r.querySelector(".table-border-bar-container.top");g(Ws,a,"no top border bar container"),a.querySelectorAll(".table-border-bar-cell.top").forEach(h=>{const p=parseInt(h.getAttribute("data-top-index")||"0",10);o.includes(p)?W(h,"danger"):ot(h,"danger")})},l=()=>{const a=i.querySelector(".table-border-bar-container.left");g(Ws,a,"no left border bar container"),a.querySelectorAll(".table-border-bar-cell.left").forEach(h=>{const p=parseInt(h.getAttribute("data-left-index")||"0",10);e.includes(p)?W(h,"danger"):ot(h,"danger")})};s(),l()}function Vi(n,t,e=!0,o){const i=Tt.fromBlock(t).map(h=>h),{fromCol:s,toCol:l,fromRow:a,toRow:d}=Qp(n,t);for(let h=0;h<i.length;h++){const p=i[h];for(let A=0;A<p.length;A++){const v=p[A],B=o?A>=s&&A+v.colSpan-1<=l:h>=a&&h+v.rowSpan-1<=d;e&&B?v.virtual||W(v.cell,"danger"):v.virtual||ot(v.cell,"danger")}}}function Wi(n,t,e=!0,o){const r=new Set,i=new Set;if(!e){Rv(n,t,Array.from(r),Array.from(i));return}const{fromCol:s,toCol:l,fromRow:a,toRow:d}=Qp(n,t);if(o)for(let h=s;h<=l;h++)i.add(h);else for(let h=a;h<=d;h++)r.add(h);Rv(n,t,Array.from(r),Array.from(i))}function Ov(n,t,e){const{fromCol:o,toCol:r,fromRow:i,toRow:s}=Qp(n,t),l=Tt.fromBlock(t);let a=null,d=null;return e?(a=l.getCell({col:o,row:0}),d=l.getCell({col:r,row:l.rowCount-1}),Ue(n,{anchor:fe(t,a.containerId,{colIndex:o,rowIndex:0}),focus:fe(t,d.containerId,{colIndex:r,rowIndex:l.rowCount-1})})):(a=l.getCell({col:0,row:i}),d=l.getCell({col:l.colCount-1,row:s}),Ue(n,{anchor:fe(t,a.containerId,{colIndex:0,rowIndex:i}),focus:fe(t,d.containerId,{colIndex:l.colCount-1,rowIndex:s})}))}function QM(n,t){const e=n.selection.range,o=Jr(n,t,e.start),r=Jr(n,t,e.end);return Zp(n,t,o,r)}const _v=["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 Fv(n){return`style-bg-color-${n}`}function au(n){return`${n}_background`}function YM(n,t,e){const o=_e(n),s=(e!=null?e:Tt.fromTable(o)).getCell(t).cell;for(let l=0;l<_v.length;l++){const a=_v[l];if(xt(s,a))return a}}function Pv(n,t,e){if(!n.isBlockWritable(t))return;const o=n.selection.range,i={...mt.default(n.getBlockData(t))},s=Jr(n,t,o.start),l=Jr(n,t,o.end);if(o.isSimple()){const a=s.childContainerId;e===-1?i[au(a)]=void 0:i[au(a)]=Fv(e)}else{const a=Tt.fromBlock(t),d=Uo(t,s,l),h=new Set;for(let p=d.fromRow;p<=d.toRow;p++)for(let A=d.fromCol;A<=d.toCol;A++){const v=a.getCell({row:p,col:A});!h.has(v.containerId)&&v.col>=d.fromCol&&v.row>=d.fromRow&&v.col+v.colSpan-1<=d.toCol&&v.row+v.rowSpan-1<=d.toRow&&(h.add(v.containerId),e===-1?i[au(v.containerId)]=void 0:i[au(v.containerId)]=Fv(e))}}n.updateBlockData(t,i)}function JM(n,t,e){if(!n.isBlockWritable(t))return;const r={...mt.default(n.getBlockData(t)),chart:e};n.updateBlockData(t,r)}const Nv=S("table-chart");function KM(n,t){const e=xM(n,t);if(e){const o=e.querySelector(".editor-table-chart");if(o){const r=o.chartObject;r&&r.destroy(),o.remove()}}}async function XM(n,t){if(!n.isBlockWritable(t))return;if(!!!n.getBlockData(t).chart){KM(n,t);return}const r=[],i=Tt.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 a=[];for(let D=1;D<i.colCount;D++)a.push(i.getCell({row:0,col:D}).container.innerText);for(let D=1;D<i.rowCount;D++){const x=i.getCell({row:D,col:0}),M=x.container.innerText,H=[];for(let qe=1;qe<i.colCount;qe++){const Yn=i.getCell({row:D,col:qe}).container.innerText,$e=Number.parseFloat(Yn)||0;H.push($e)}let z;const q=YM(t,x,i);q?z=window.getComputedStyle(n.rootElement).getPropertyValue(`--${q}`).trim():z=window.getComputedStyle(n.rootElement).getPropertyValue("--background-color").trim();let[rt,ft,Bt,jt]=z?dm.fromString(z).toRgbaArray():[];if(!rt&&!ft&&!Bt&&!jt){const qe=(D-1)%n.options.colors.length;z=n.options.colors[qe],[rt,ft,Bt,jt]=dm.fromString(z).toRgbaArray()}const Ut=z,ne=dm.fromRgba([rt,ft,Bt,jt/3]).toHexString();r.push({label:M,data:H,borderColor:Ut,backgroundColor:ne,borderWidth:2})}const d=gr(n,t);let h=null,p=d.querySelector(".editor-table-chart");p?h=p.chartObject:p=w("div",["editor-table-chart"],d);const A=p;g(Nv,A,"no chart container");const v=n.getComponentOptions("table"),B=(v==null?void 0:v.chartCdn)||"https://cdn.jsdelivr.net/npm/chart.js@2.9.4/dist/Chart.min.js";try{await vs(B,"editor-chartjs");let D=!1;(h&&h.config.data.datasets.length>r.length||h&&h.config.data.datasets[0].data.length>r[0].data.length)&&(D=!0),h&&(l!==h.config.type||D)&&(h.destroy(),h=null,Array.from(p.querySelectorAll(".editor-chartjs-canvas")).forEach(M=>{M.remove()}));const x=hm.default({},{type:l,data:{datasets:r,labels:a},options:{onClick:()=>{n.selection.selectBlock(t,0,0)}}});if(h)hm.default(h.config,x),h.update();else{const M=w("canvas",["editor-chartjs-canvas"],A).getContext("2d");h=new window.Chart(M,x),p.chartObject=h}}catch(D){Nv.error(`failed to resolve chart cdn: ${JSON.stringify(D)}`)}}async function $v(n,t){await Eo.lock("updateTableChart");try{await XM(n,t)}finally{Eo.release("updateTableChart")}}const Hv=Le.default($v,1e3);let jv=null;function Yp(n,t,e){if(jv!==t&&(Hv.flush(),jv=t),e.updateNow){$v(n,t);return}Hv(n,t)}function Jp(n,t){Ve(t)&&Yp(n,t,{updateNow:!1})}function tR(n,t){Ve(t)&&Yp(n,t,{updateNow:!0})}const ho={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"},tf={SCROLL_BAR:"container-scrollbar",FIXED:"fixed"},qi={SCROLL_CONTAINER:"scroll-container",TOOL:"container-scroll-tool",CONTAINER:"scroll-container-root",MAC:"mac",SCROLL_AREA:"scroll-area"};function uu(n,t){return n.containers.get(t)}function Uv(n){return n.closest(`.${qi.SCROLL_CONTAINER}`)}function zo(n){return n.firstElementChild}function Ln(n){return n.closest(`.${qi.CONTAINER}`)}function du(n){const t=Ln(n);let e=t.querySelector(`:scope >.${qi.TOOL}`);return e||(e=w("div",[qi.TOOL],t)),e}function eR(n){return Ln(n).firstElementChild}function nR(n,t){const e=uu(n,Ln(t));return e!=null&&e.barFloatWindowBottom?typeof e.barFloatWindowBottom=="function"?e.barFloatWindowBottom():e.barFloatWindowBottom:0}function fo(n,t){const e=ys(n);return t/e}function hu(n){const t=window.getComputedStyle(n),e=ys(n);return{paddingBottom:parseFloat(t.paddingBottom)*e,paddingTop:parseFloat(t.paddingTop)*e,paddingLeft:parseFloat(t.paddingLeft)*e,paddingRight:parseFloat(t.paddingRight)*e}}function sc(n){const t=ys(n);return{scrollLeft:n.scrollLeft*t,scrollWidth:n.scrollWidth*t,clientWidth:n.clientWidth*t,clientHeight:n.clientHeight*t}}function oR(n,t){const e=ys(n);return n[t]*e}function Kp(n,t){const e=Ln(t),o=uu(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(),a=e.getBoundingClientRect(),d=a.width;let h=Math.floor(a.left-l.left-i);h<0&&(h=0);let p=l.right;p-=r;let A=p-a.right;return A<0&&(A=0),h=Math.round(h),A=Math.round(A),{originWidth:d,maxLeft:h,maxRight:A}}function rR(n,t){const e=Kp(n,t),{maxLeft:o}=e;t.style.marginLeft=`${fo(t,0-o)}px`,t.style.paddingLeft=`${fo(t,o)}px`}function iR(n,t){const e=Kp(n,t);t.style.marginRight=`${fo(t,0-e.maxRight)}px`}function sR(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 zv=S("scroll-bar-handle"),lR=2;function lc(n){const t=du(n);let e=t.querySelector(`.${tf.SCROLL_BAR}`);return e||(e=w("div",[tf.SCROLL_BAR],t)),g(zv,e instanceof HTMLDivElement,"invalid child for container tools"),e.firstElementChild||w("div",[],e),e}function ef(n,t){const e=Uv(t),o=lc(e),{scrollWidth:r,clientWidth:i}=sc(e),{paddingLeft:s,paddingRight:l}=hu(t),a=Kp(n,e),{originWidth:d,maxRight:h}=a;iR(n,e),rR(n,e);const p=r-i;g(zv,o.firstElementChild instanceof HTMLDivElement,"invalid child for scroll bar"),o.style.width=`${fo(e,d+h-s-l)}px`,o.firstElementChild.style.width=`${fo(e,d+h+p-s-l)}px`}function cR(n,t){const e=zo(n),{paddingLeft:o}=hu(e);if(xt(t,"fixed")){const i=Ln(n).getBoundingClientRect();t.style.left=`${fo(n,i.left+o)}px`}else t.style.left=`${fo(n,o)}px`}function cc(n,t){var M;const e=n.getParentScrollContainer(),o=sR(e),r=t.getBoundingClientRect(),i=lc(t),s=i.getBoundingClientRect(),l=uu(n,Ln(t)),a=nR(n,t),d=zo(t),{paddingTop:h,paddingBottom:p}=hu(d),{scrollWidth:A,clientWidth:v}=sc(t),B=document.documentElement.clientHeight-a,D=o.top+sc(e).clientHeight-B,x=B+Math.min(0,D);if(A>v&&r.top+h<x-s.height&&r.bottom>x-s.height+p&&!((M=l==null?void 0:l.isSetScale)!=null&&M.call(l))){W(i,tf.FIXED);const H=D>0?a:0;i.style.bottom=`${Math.max(document.documentElement.clientHeight-o.bottom,0)+lR+H}px`}else ot(i,tf.FIXED),i.style.bottom=`${fo(t,p-s.height)}px`;cR(t,i)}class aR{constructor(t,e){m(this,"intersectionObserver");m(this,"handleIntersection",t=>{t.forEach(e=>{this.containers.get(Ln(e.target))?(this.handleIntersectionEntry(e),this.callback(e)):this.intersectionObserver.unobserve(e.target)})});m(this,"handleIntersectionEntry",t=>{const e=t.target;cc(this.scrollCore,e);const o=zo(e);ef(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 qs=S("container-scroll-shadow");function Vv(n,t,e){const o=n,r=t.getBoundingClientRect(),i=e.getBoundingClientRect(),{paddingTop:s,paddingBottom:l}=hu(e);o.style.top=`${fo(t,i.top-r.top+s)}px`,o.style.bottom=`${fo(t,r.bottom-i.bottom+l)}px`}function Wv(n,t){const e=n;t<24?e.style.width=`${(t/3).toFixed(2)}px`:e.style.width=""}function uR(n){const t=du(n);g(qs,t,"no container tools");let e=t.querySelector(`.${ho.LEFT}`);if(!e){const l=zo(n),a=[ho.COMMON,ho.LEFT];e=w("div",a,t),g(qs,e instanceof HTMLDivElement,"invalid child for container tools"),Vv(e,n,l)}g(qs,e instanceof HTMLElement,"invalid child for container tools");const r=Ln(n).getBoundingClientRect(),i=n.getBoundingClientRect();e.style.left=`${fo(n,i.left-r.left)}px`;const s=sc(n).scrollLeft;g(qs,e instanceof HTMLDivElement,"invalid child for container tools"),Wv(e,s),W(e,ho.ACTIVE)}function dR(n){const t=du(n);let e=t.querySelector(`.${ho.RIGHT}`);if(!e){const h=zo(n),p=[ho.COMMON,ho.RIGHT];e=w("div",p,t),g(qs,e instanceof HTMLDivElement,"no div, create shadow failed"),Vv(e,n,h)}g(qs,e instanceof HTMLElement,"");const r=Ln(n).getBoundingClientRect(),i=n.getBoundingClientRect();e.style.right=`${fo(n,r.right-i.right)}px`;const{scrollWidth:s,scrollLeft:l,clientWidth:a}=sc(n),d=s-l-a;g(qs,e instanceof HTMLDivElement,"no shadow element"),Wv(e,d),W(e,ho.ACTIVE)}function hR(n){const e=du(n).querySelector(`.${ho.LEFT}`);e&&ot(e,ho.ACTIVE)}function fR(n){const e=du(n).querySelector(`.${ho.RIGHT}`);e&&ot(e,ho.ACTIVE)}function fu(n){const{scrollLeft:t,scrollWidth:e,clientWidth:o}=sc(n),r=zo(n),{paddingLeft:i,paddingRight:s}=hu(r),l=oR(r,"offsetLeft");e-i<=o-s||e-i<=t+o-s?fR(n):dR(n),r&&t>=l+i?uR(n):hR(n)}class mR{constructor(t,e){m(this,"resizeObserver");m(this,"handleResizeEntry",t=>{const e=t.target,o=zo(e);fu(e),ef(this.scrollCore,o),cc(this.scrollCore,e),this.callback(e)});m(this,"handleContentResize",t=>{t.forEach(e=>{this.containers.get(Ln(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 qv=S("container-scroll-observer");class gR{constructor(t,e){m(this,"handleContentScroll",t=>{const e=t.target;g(qv,e instanceof Element,"invalid target for scroll event");const o=lc(e);o.removeEventListener("scroll",this.handleScroll);const r=!0;this.fixScrollXPos(e,e.scrollLeft,r),this.bind(o),fu(e),this.callback(e)});m(this,"handleScroll",t=>{const e=t.target;g(qv,e instanceof HTMLElement,"");const o=e.scrollLeft,r=!1,i=eR(e);this.unbindContentScroll(i),this.fixScrollXPos(i,o,r),this.bindContentScroll(i),fu(i),this.callback(i)});m(this,"handlePrevent",t=>{t.stopPropagation()});m(this,"bindContentScrollCore",t=>{this.unbindContentScroll(t),t.addEventListener("scroll",this.handleContentScroll)});m(this,"unbindContentScroll",t=>{t.removeEventListener("scroll",this.handleContentScroll)});m(this,"bindContentScroll",Le.default(this.bindContentScrollCore,300));m(this,"bind",Le.default(this.bindCore,200));this.scrollCore=t,this.callback=e}fixScrollXPos(t,e,o){const r=lc(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 pR{constructor(t){m(this,"scrollContainers",new Set);m(this,"handleParentContainerScroll",()=>{this.scrollContainers.forEach(t=>{cc(this.scrollCore,t)})});m(this,"bindScrollContainer",t=>{const e=this.scrollContainers.size===0;this.scrollContainers.add(t),e&&this.eventTarget.addEventListener("scroll",this.handleParentContainerScroll)});m(this,"unbindScrollContainer",t=>{let e=!1;this.scrollContainers.has(t)&&(this.scrollContainers.delete(t),e=this.scrollContainers.size===0),e&&this.eventTarget.removeEventListener("scroll",this.handleParentContainerScroll)});this.scrollCore=t}get eventTarget(){const t=this.scrollCore.getParentScrollContainer();return t===document.documentElement?document:t}destroy(){this.eventTarget.removeEventListener("scroll",this.handleParentContainerScroll),this.scrollContainers.clear()}}const CR=S("scroll-wrap-resize-observer");class AR{constructor(t){m(this,"resizeObserver");m(this,"handleScrollWrapResize",t=>{t.forEach(e=>{this.containers.get(Ln(e.target))?this.handleScrollWrapResizeEntry(e):this.unbind(e.target)})});m(this,"handleScrollWrapResizeEntry",t=>{const e=t.target;g(CR,e instanceof HTMLElement,"invalid target for observer entry");const o=Uv(e);ef(this.scrollCore,e),fu(o),cc(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 bR{constructor(t,e){m(this,"resizeObserver");m(this,"scrollContainersMap",new Map);m(this,"handleResizeEntry",t=>{t==null||t.forEach(e=>{const o=zo(e);fu(e),ef(this.scrollCore,o),cc(this.scrollCore,e),this.callback(e)})});m(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=Ln(t),o=(r=uu(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=Ln(t),o=(i=uu(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 ynt="";class vR extends ye.TypedEmitter{constructor(e){super();m(this,"containerIntersectionObserver",null);m(this,"containerResizeObserver",null);m(this,"containerScrollObserver",null);m(this,"parentContainerScrollObserver",null);m(this,"scrollWrapResizeObserve",null);m(this,"locatingContainerResizeObserver",null);m(this,"isWindowEventBind",!1);m(this,"containers",new Map);m(this,"handleScrollContainerScroll",e=>{this.emit("scroll",this,e)});m(this,"handleResize",e=>{this.emit("resize",this,e)});m(this,"handleIntersection",e=>{const o=e.target,r=zo(o);e.isIntersecting?(this.load(),this.bindCore(o,r)):this.unbindCore(o,r)});m(this,"handleWindowEffect",()=>{var e;(e=this.getScrollContainerInViewable())==null||e.forEach(o=>{cc(this,o)})});this.parentContainer=e}load(){this.containerResizeObserver||(this.containerResizeObserver=new mR(this,this.handleResize)),this.containerScrollObserver||(this.containerScrollObserver=new gR(this,this.handleScrollContainerScroll)),this.parentContainerScrollObserver||(this.parentContainerScrollObserver=new pR(this)),this.scrollWrapResizeObserve||(this.scrollWrapResizeObserve=new AR(this)),this.locatingContainerResizeObserver||(this.locatingContainerResizeObserver=new bR(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,a,d,h;const r=lc(e);(i=this.containerScrollObserver)==null||i.unbindContentScroll(e),(s=this.containerScrollObserver)==null||s.unbind(r),(l=this.scrollWrapResizeObserve)==null||l.unbind(o),(a=this.containerResizeObserver)==null||a.unbind(e),(d=this.parentContainerScrollObserver)==null||d.unbindScrollContainer(e),(h=this.locatingContainerResizeObserver)==null||h.unbind(e)}bindCore(e,o){var i,s,l,a,d,h;if(this.unbindCore(e,o),!e.closest("body"))return;const r=lc(e);(i=this.containerScrollObserver)==null||i.bindContentScrollCore(e),(s=this.containerScrollObserver)==null||s.bindCore(r),(l=this.scrollWrapResizeObserve)==null||l.bind(o),(a=this.containerResizeObserver)==null||a.bind(e),(d=this.parentContainerScrollObserver)==null||d.bindScrollContainer(e),(h=this.locatingContainerResizeObserver)==null||h.bind(e)}bind(e,o){this.containers.set(e,o);const r=e.firstElementChild;this.containerIntersectionObserver||(this.containerIntersectionObserver=new aR(this,this.handleIntersection)),this.containerIntersectionObserver.bind(r)}unbind(e){var i;const o=e.firstElementChild,r=zo(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,a)=>{this.unbind(a)}),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 Gv=S("scroll-container"),nf=new Map;class yR extends ye.TypedEmitter{constructor(){super(...arguments);m(this,"scrollListener");m(this,"options");m(this,"scrollContainerElement");m(this,"init",e=>{this.options=e;const o=w("div",[qi.CONTAINER],e.parentElement);Ze.isMac&&W(o,qi.MAC);const r=w("div",[qi.SCROLL_CONTAINER],o),i=w("div",[qi.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=nf.get(s),this.scrollListener||(this.scrollListener=new vR(s),nf.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});m(this,"handleContainerScroll",(e,o)=>{o===this.scrollContainerElement&&this.emit("scroll",this)});m(this,"handleResize",(e,o)=>{o===this.scrollContainerElement&&this.emit("scroll",this)})}get rootElement(){return this.scrollContainerElement}get contentElement(){return g(Gv,this.scrollContainerElement,"scrollContainerElement cannot be undefined"),zo(this.scrollContainerElement)}get scrollOptions(){return g(Gv,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=Ln(this.contentElement);e&&nf.forEach((r,i)=>{r.unbind(e),r.containers.size===0&&(this.handleBaseListenerDestroy(r),nf.delete(i))})}}function kR(){return new yR}const Xp=S("column-width");function wR(n,t,e){TM(n,t).style.width=`${e}px`}function BR(n){const e=Array.from(n.querySelector("colgroup").children).map(a=>a.getBoundingClientRect().width);if(e[0]!==0)return e;const o=Tt.fromTable(n),r=Array(o.colCount).fill(-1),i=n.getBoundingClientRect().left;o.toRealCells(o.cells).forEach(a=>{const d=a.col+a.colSpan-1;r[d]===-1&&(r[d]=a.cell.getBoundingClientRect().right-i)}),Xp.debug(`cellRightOffsets1: ${r.join()}`);for(let a=0;a<r.length;a++){const d=r[a];if(d===-1||a===0)continue;let h=a-1;for(;r[h]===-1&&(h--,h!==-1););const p=h===-1?0:r[h],v=(d-p)/(a-h);for(let B=h+1;B<a;B++)r[B]=p+v*(B-h)}Xp.debug(`cellRightOffsets2: ${r.join()}`);const s=[];let l=0;for(let a=0;a<r.length;a++){const d=r[a];s.push(d-l),l=d}return Xp.debug(`widths: ${s.join()}`),s}function mu(n){return Array.from(n.querySelector("colgroup").children).map(o=>o.getBoundingClientRect().width||Number.parseInt(o.style.width,10))}const t0=200,ER=40,xR=S("table-resize-gripper"),Zv=7,e0=(Zv-1)/2,IR=3;function TR(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 a=s[l],d=a.getBoundingClientRect(),h=Math.round(d.right);if(Math.abs(t-h)<=e0&&d.top<=e&&e<=d.bottom)return a}}return null}function DR(n){return!!n.rootContainer.querySelector(".table-resize-gripper")}function n0(n,t){return gr(n,t).querySelector(".table-resize-gripper")}function Qv(n,t){const e=n0(n,t);g(xR,!e,"resize gripper has already exists");const o=gr(n,t),r=w("div",["table-resize-gripper","table-indicator"],o);return w("div",["table-resize-gripper-indicator"],r),r}function Yv(n,t,e){let o=n0(n,t);o||(o=Qv(n,t));const i=_e(t).getBoundingClientRect(),s=e.getBoundingClientRect(),l=0,a=i.height,d=n.getCustom(mr(t)).contentElement.getBoundingClientRect(),h=s.right-d.left;o.style.left=`${h-e0-zi-ic}px`,o.style.top=`${l}px`,o.style.height=`${a}px`,o.style.width=`${Zv}px`}function o0(n){n.rootContainer.querySelectorAll(".table-resize-gripper").forEach(t=>{t.remove()})}function SR(n,t,e){const r={...n.getBlockData(t),colsWidth:e};n.updateBlockData(t,r)}function LR(n,t,e,o){const r=t,i=Tt.fromTable(e),s=i.getCellByCellElement(r),l=s.col+s.colSpan-1,a=mu(e);let d=o;const h=(A,v)=>{const B=v+1,D=A.col+A.colSpan;return a.slice(B,D).reduce((_,M)=>_+M,0)},p=new Set;for(let A=0;A<i.rowCount;A++){const v=i.getCell({row:A,col:l});if(p.has(v.cell))continue;p.add(v.cell);const B=v.cell,D=B.getBoundingClientRect();let x=o-D.left+e0-IR;const _=su(B),M=Gm(n,_)||ER*v.colSpan,H=h(v,l),z=M-H;x<z&&(x=z);const q=D.left+x;d=Math.max(d,q)}return d}const MR=S("table-resize-drag-drop");class RR{constructor(t,e,o,r){m(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:a}=t.data,h=LR(this.editor,a,s,e.x-t.dragOffsetX)-s.getBoundingClientRect().left;g(MR,a,"no dragging cell");const A=Tt.fromTable(s).getCellByCellElement(a),v=A.col+A.colSpan-1,D=mu(s).slice(0,v).reduce((_,M)=>_+M,0),x=h-D;wR(s,v,x),Yv(this.editor,l,a),this.editor.selection.caret.update()}onDragEnd(t,e,o,r,i){const s=mu(t.data.table);SR(this.editor,t.data.block,s),o0(this.editor),this.onEnd&&(this.onEnd(e),this.onEnd=null)}}function OR(n,t){const e=document.elementFromPoint(t.x,t.y);if(!e)return null;const o=et(e);return!o||!n.contains(o)||!Ve(o)?null:o}S("table-resize");class _R{constructor(t){m(this,"draggingRefCell",null);m(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=OR(t,i);if(!s||!Ev(s)||!t.isBlockWritable(s)){o0(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=_e(t),i=TR(r,e,o);if(i){if(!n0(this.editor,t)){if(DR(this.editor))return;const l=Qv(this.editor,t),a={block:t,table:r,draggingRefCell:i};km(new RR(this.editor,l,a,d=>{this.updateGripper(t,d.x,d.y)}))}Yv(this.editor,t,i)}else o0(this.editor)}}function Jv(n){n.addCustom("table-mouse-event-handler",t=>new _R(t))}const Kv=S("table-insert-column");function Xv(n,t,e){n.undoManager.runInGroup(()=>{const o=_e(t),r=Tt.fromTable(o),i=r.colCount;g(Kv,e>=0&&e<=i,`insert index ${e} is out of range [0, ${i}]`);const s=r.map(A=>A.containerId),l=new Set;n.doc.beginBatchUpdate();for(let A=0;A<s.length;A++){const v=s[A],B=v[e-1],D=v[e];if(e===0||e===v.length||B!==D){const x=qr(n.doc);v.splice(e,0,x)}else v.splice(e,0,B),l.add(B)}n.doc.endBatchUpdate();const a=mt.default(n.getBlockData(t));l.forEach(A=>{const v=`${A}_colSpan`,B=a[v];g(Kv,typeof B=="number"&&B>1,`no colSpan for containerId ${A}, ${B}`),a[v]=B+1});const d=a.colsWidth.concat();d.splice(e,0,t0);const h=Tt.virtualCellContainersGridToChildren(s),p={...a,cols:a.cols+1,children:h,colsWidth:d};Vs(p),n.updateBlockData(t,p)})}const of=S("table-insert-row");function t9(n,t,e){n.undoManager.runInGroup(()=>{const o=_e(t),r=Tt.fromTable(o),i=r.rowCount;g(of,e>=0&&e<=i,`insert index ${e} is out of range [0, ${i}]`);const s=r.map(A=>A.containerId),l=new Set;n.doc.beginBatchUpdate();const a=[];for(let A=0;A<r.colCount;A++){const v=e>0&&s[e-1][A],B=e<r.rowCount&&s[e][A];if(g(of,v||B,"no top and bottom cell"),e===0||e===r.rowCount||v!==B){const D=qr(n.doc);a.push(D)}else g(of,v,"no top cell"),a.push(v),l.add(v)}n.doc.endBatchUpdate(),s.splice(e,0,a);const d=mt.default(n.getBlockData(t));l.forEach(A=>{const v=`${A}_rowSpan`,B=d[v];g(of,typeof B=="number"&&B>1,`no rowSpan for containerId ${A}, ${B}`),d[v]=B+1});const h=Tt.virtualCellContainersGridToChildren(s),p={...d,rows:d.rows+1,children:h};Vs(p),n.updateBlockData(t,p)})}const r0=S("paste-table-in-table-block");function FR(n,t,e,o){let r=Tt.fromBlock(e);const i=t.blocks.root[0];g(r0,i,"no table data"),g(r0,i.type==="table",`table data type is not table, but ${i.type}`);const s=i,l=r.getCellByCellElement(o),a=s.cols,d=s.rows,h=l.col,p=l.row,A=h+a,v=p+d,B=[];for(let D=h;D<A&&D<r.colCount;D++)for(let x=p;x<v&&x<r.rowCount;x++){const _=r.getCell({col:D,row:x});_.virtual?_.virtual&&B.push({col:D,row:x}):(_.colSpan>1||_.rowSpan>1)&&B.push({col:D,row:x})}n.undoManager.runInGroup(()=>{if(B.forEach(M=>{const H=Tt.fromBlock(e).getCell(M);(H.colSpan>1||H.rowSpan>1)&&Up(n,e,M)}),A>r.colCount)for(let M=r.colCount;M<A;M++)Xv(n,e,M);if(v>r.rowCount)for(let M=r.rowCount;M<v;M++)t9(n,e,M);r=Tt.fromBlock(e);const D=new Yh(s);let x;for(let M=0;M<D.colCount;M++)for(let H=0;H<D.rowCount;H++){const z=D.getCell({col:M,row:H});if(!z.virtual){const q=_g(n.editorBlocks,t,z.containerId),rt=h+M,ft=p+H,Bt={col:rt,row:ft},jt=r.getCellContainer(Bt);W6(n,jt,q),x=jt}}g(r0,x,"no last container");const _=Qe(x);n.selection.selectBlock(_,ut(n,_))})}const e9=S("paste-in-table-block");class PR{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=nt(r);if(Yt(i)||!Ba(t,i))return!1;const s=et(i);if(g(e9,s,"no parent block"),!Ve(s)||e.blocks.root.length!==1||e.blocks.root[0].type!=="table")return!1;e9.debug("paste child table in table");const d=Tt.fromBlock(s).getCellByContainerId(at(i)).cell;return FR(t,e,s,d),!0}}function n9(n){n.addCustom("table-block-paste-event",t=>new PR(t))}const i0=S("table-select-columns");function NR(n,t,e,o,r){g(i0,Ve(t),"is not a table block");const i=Tt.fromBlock(t);g(i0,e>=0&&e<i.colCount,"invalid from"),g(i0,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}),a=fe(t,s.containerId,{colIndex:e,rowIndex:0}),d=fe(t,l.containerId,{colIndex:e+o-1,rowIndex:i.rowCount-1});r!=null&&r.reverse?n.selection.setSelection(d,a):n.selection.setSelection(a,d)}const s0=S("table-select-columns");function $R(n,t,e,o,r){g(s0,Ve(t),"is not a table block");const i=Tt.fromBlock(t);g(s0,e>=0&&e<i.rowCount,"invalid from"),g(s0,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}),a=fe(t,s.containerId,{rowIndex:e,colIndex:0}),d=fe(t,l.containerId,{rowIndex:e+o-1,colIndex:i.colCount-1});r!=null&&r.reverse?n.selection.setSelection(d,a):n.selection.setSelection(a,d)}const knt="",o9=S("get-toolbar-reference-client");function HR(n,t){const e=n.selection.range;if(!e.isSimple()){g(o9,e.start.blockId===e.end.blockId,"invalid selection range");const s=n.getBlockById(e.start.blockId);g(o9,Mt(n,s),"not a complex block");const l=Qt(n,s);if(l.getTextToolbarReferenceClient){const a=l.getTextToolbarReferenceClient(n,s);if(a)return a}}const o=e.isReverse()?t.start:t.end,r=Ue(n,{anchor:o,focus:o}),i=Nr(n,t.block,r);if(i.length!==0)return i[0]}function jR(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 rf(n){const t=(r,i)=>{const s=r.findIndex(a=>a.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=fm.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=rf(r),jR(s))}),e}function sf(n){return n.getCustom("toolbar-handler")}const wnt="";class UR{constructor(){m(this,"linkPopup",null);m(this,"form",{});m(this,"onFinished",null);m(this,"onClose",null);m(this,"handleOk",async()=>{var t;try{await this.checkValue();const{linkText:e,linkUrl:o}=this.form,r=this.formatUrl(o.getInputValue());(t=this.onFinished)==null||t.call(this,e.getInputValue()||r,r),this._destroy()}catch{}});m(this,"handleClose",()=>{var t;(t=this.onClose)==null||t.call(this),this._destroy()});m(this,"onShow",()=>{setTimeout(()=>{var t;(t=this.form.linkText)==null||t.getField().focus()},400)});m(this,"onChange",()=>{var e;const t=(e=this.linkPopup)==null?void 0:e.content.querySelector('[data-button-id="submit-button"]');t.disabled=!1});m(this,"handleTextKeyboard",t=>{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()}});m(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(R.t("link.urlPlaceholder")),new Error(R.t("link.urlPlaceholder"))}formatUrl(t){if(!t)return"";try{new URL(t)}catch{return`${window.location.protocol}//${t}`}return t}editLink(t){var h,p;const{target:e,linkText:o,linkUrl:r,onFinished:i,onClose:s,placement:l="bottom-start"}=t;this.linkPopup=new tu(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 a=(h=this.linkPopup)==null?void 0:h.content.querySelector('[data-button-id="submit-button"]'),d=(p=this.linkPopup)==null?void 0:p.content.querySelector('[data-button-id="cancel-button"]');a==null||a.addEventListener("click",this.handleOk),d==null||d.addEventListener("click",this.handleClose)}createPopupContent(t,e){const o=w("div",["link-popup-content"],null);this.form.linkText=Rp(o,{label:R.t("link.textLabel"),required:!1,placeholder:R.t("link.textPlaceholder"),defaultValue:t,onChange:this.onChange,onKeyDown:this.handleTextKeyboard}),this.form.linkUrl=Rp(o,{className:"link-popup-gap",label:R.t("link.urlLabel"),required:!0,placeholder:R.t("link.urlPlaceholder"),defaultValue:e,onChange:this.onChange,onKeyDown:this.handleUrlKeyboard});const r=w("div",["link-popup-footer"],o),i=uo("cancel-button",R.t("link.cancelText"));r.appendChild(i);const s=uo("submit-button",R.t("link.submitText"),void 0,["disabled","primary"]);return r.appendChild(s),o}_destroy(){var o,r,i,s;const t=(o=this.linkPopup)==null?void 0:o.content.querySelector('[data-button-id="submit-button"]'),e=(r=this.linkPopup)==null?void 0:r.content.querySelector('[data-button-id="cancel-button"]');t==null||t.removeEventListener("click",this.handleOk),e==null||e.removeEventListener("click",this.handleClose),this.onFinished=null,this.onClose=null,this.form={},(i=this.linkPopup)==null||i.removeAllListeners(),(s=this.linkPopup)==null||s.destroy()}destroy(){this._destroy()}}function gu(n,t){n.addCustom("link-editor",()=>new UR).editLink(t)}const zR=S("link-popup");function VR(n){return xt(n,"link")}function pu(n){var t,e;return(e=(t=n.getAttribute("link"))!=null?t:n.textContent)!=null?e:""}function WR(n,t,e){var r,i,s,l;if(n.isBlockWritable(t)&&e&&so(e)){const a=e,d=(i=(r=n.editorBoxes.getBoxClass(va(a))).getBoxProperties)==null?void 0:i.call(r,n,a);if(d!=null&&d.boxCommands){const h=(l=(s=d.boxCommands["hovering-toolbar"])==null?void 0:s.commands)!=null?l:[];return{element:e,commands:h}}return{element:null,commands:[]}}if(n.isWritable()&&e&&tt(n,t)&&VR(e)){const a=w("a",["link-href-button"],null,pu(e));a.href=pu(e),a.target="_blank",a.rel="noopener noreferrer";const d=[{id:"link-text",name:pu(e),disableTooltip:!0,element:a},{id:"edit-link",name:R.t("link.edit"),icon:Dp},{id:"remove-link",name:R.t("link.remove"),icon:RL}];return{element:e,commands:d}}return l4(n,t,"hovering-toolbar")}function r9(n,t,e){var l;const o=_s(t,e),r=n.getBlockText(t),i={start:0,end:0};let s=(l=e.textContent)!=null?l:"";for(let a=0;a<r.length;a++){const d=r[a];if(i.end+d.insert.length>=o.end){i.end+=d.insert.length,s=d.insert;break}i.start<o.start&&(i.start+=d.insert.length,i.end=i.start)}return[i,s]}function qR(n,t,e){const[o,r]=r9(n,t,e);n.selection.selectBlock(t,o.start,o.end);const i=pu(e),s=(h,p)=>{try{const A=n.getBlockText(t),v=cg(A,o.start,o.end-o.start),B=Vr(v,o.start,h,{link:p});n.setBlockText(t,B),n.selection.selectBlock(t,o.start+h.length),n.focus()}catch(A){zR.error(A)}},l=()=>{n.selection.selectBlock(t,o.end),n.focus()},a=Nr(n,t,n.selection.range)[0];if(!a)return;const d=zr(n,t,"link-button-anchor",a);gu(n,{target:d,linkText:r,linkUrl:i,onFinished:s,onClose:l})}function GR(n,t,e){const[o]=r9(n,t,e),r=n.getBlockText(t),i=pu(e),s=Wl(o.start,o.end-o.start,r,"link",i);n.setBlockText(t,s),n.selection.selectBlock(t,o.end)}function ZR(n,t,e,o){var s,l,a;if(e){if(n.isBlockWritable(t)&&so(e)){const h=e,p=(l=(s=n.editorBoxes.getBoxClass(va(h))).getBoxProperties)==null?void 0:l.call(s,n,h);if(p!=null&&p.boxCommands){p.boxCommands["hovering-toolbar"].executeCommand(n,t,h,o);return}return}const d=sf(n);d.disableTextToolbar(),d.hide(),setTimeout(()=>{d.enableTextToolbar()},400),o.id==="edit-link"?qR(n,t,e):o.id==="remove-link"&&GR(n,t,e);return}const r=s4(n,t);if(!r)return;const i=(a=r.blockCommands)==null?void 0:a["hovering-toolbar"];!i||i.executeCommand(n,t,o)}function lf(){let n=8;for(;n>0&&!document.querySelector(`div[data-style-heading='${n}']`);)n--;return n}const QR=[bp,vp,yp,kp,wp,Bp,Ep,xp];class YR{constructor(t){m(this,"id","BlockTurnIntoCommandProvider");this.editor=t}getHeadingIndex(){let t=lf();return t<=4?t=5:t<8&&(t+=1),t}getAvailableCommands(t,e,o){if(tt(t,e)){const r=it(e),i=Dt(e),s=Do(t,e),a=t.getBlockData(e).heading,d=[];for(let p=0;p<this.getHeadingIndex();p++)d.push({id:`heading-${p+1}`,name:R.t("commands.heading",{name:`${p+1}`}),icon:QR[p],states:a===p+1?["checked"]:[],value:`${p+1}`});const h=p=>{var v;const A=w("span",["toolbar-item-name-container"],null);for(const B of p.children)if((v=B.states)!=null&&v.includes("checked"))return A.innerHTML=B.icon||ou,A;return A.innerHTML=ou,A};return[{id:"turn-into",name:R.t("commands.headingGroup"),blockId:r,blockType:i,blockKind:s,element:h,groupIndex:200,dropdown:!0,manualShowChildren:!0,childrenPlacement:"bottom-start",defaultCheckedChildren:["text"],children:[{id:"text",name:R.t("commands.text"),icon:ou,states:a?[]:["checked"]},...d],childrenType:"menu"}]}return[]}applyHeadingStyle(t,e,o){t.updateBlockData(e,{heading:o})}executeCommand(t,e,o,r){if(tt(t,e)&&(r.id.startsWith("heading-")||r.id==="text")){const i=r.value?Number(r.value):null;return this.applyHeadingStyle(t,e,i),t.focus(),!0}return!1}}const JR=`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
377
377
|
<path d="M8 8H15" stroke="currentColor" stroke-linecap="square" stroke-linejoin="round"></path>
|
|
378
378
|
<path d="M8 14H15" stroke="currentColor" stroke-linecap="square" stroke-linejoin="round"></path>
|
|
379
379
|
<path d="M8 2H15" stroke="currentColor" stroke-linecap="square" stroke-linejoin="round"></path>
|
|
@@ -394,13 +394,13 @@ xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24">
|
|
|
394
394
|
<path d="M1 10.0039H5.99738L5.99608 15" stroke="currentColor" stroke-width="2"/>
|
|
395
395
|
<path d="M14.9971 5.99611H9.99969L10.001 1" stroke="currentColor" stroke-width="2"/>
|
|
396
396
|
</svg>`;async function hO(n,t,e){const o=te(t),r=o.querySelector('[data-button-id="mindmap-fullscreen"]');g(ke,r,"no full screen button");const i=()=>{setTimeout(()=>{e.toMindmap(n,t,{},{reset:!0,mindmapTools:e})},300)},s=()=>{ot(o,"fullscreen"),r.innerHTML=d9,Kb(r,"Full screen",n.clientId),f9(t)&&setTimeout(()=>{i()},300)};if(document.fullscreenElement===o){try{await h9()}catch(l){ke.error(l)}s()}else{try{W(o,"fullscreen"),await aO(o),i()}catch(l){ke.error(l)}r.innerHTML=dO,Kb(r,R.t("mindmap.exitFullscreen"),n.clientId)}o.onfullscreenchange=()=>{document.fullscreenElement||s()}}function a0(n,t,e,o,r){if(t.querySelector(`[data-button-id="${e}"]`))return null;const s=uo(e,o,r,[],n.clientId);return W(s,"mindmap-button"),t.appendChild(s),s}function u0(n,t){return n.querySelector(`[data-button-id="${t}"]`)}function fO(n){return u0(n,"mindmap-fullscreen")}function mO(n){return u0(n,"mindmap-fit")}function gO(n){return u0(n,"mindmap-close")}function pO(n,t,e,o){const r=a0(n,t,"mindmap-close",R.t("mindmap.close"),lO);!r||n.domEvents.addEventListener(r,"click",()=>{o.closeMindmap(n,e)})}function CO(n,t,e,o){const r=a0(n,t,"mindmap-fit",R.t("mindmap.autoFit"),cO);!r||n.domEvents.addEventListener(r,"click",()=>{o.fitMindmap(n,e)})}function AO(n,t,e,o){if(navigator.userAgent.includes("Mobile")&&!navigator.userAgent.includes("iPad"))return;const i=a0(n,t,"mindmap-fullscreen",R.t("mindmap.fullScreen"),d9);!i||n.domEvents.addEventListener(i,"click",()=>{hO(n,e,o)})}function bO(n,t){const e=Xd(t);if(!e)return;const o=mO(e);o&&(o.remove(),n.domEvents.removeAllListeners(o));const r=gO(e);r&&(r.remove(),n.domEvents.removeAllListeners(r));const i=fO(e);i&&(i.remove(),n.domEvents.removeAllListeners(i))}const dc=new Map;function d0(n,t,e){const o=(s,l)=>{s.forEach(a=>{l?W(a.block,"to-mindmap-highlight"):ot(a.block,"to-mindmap-highlight"),o(a.children,l)})},r=u9(n,t);if(r.length===0)return;const i=r[0].block;if(e){const s=dc.get(i);s&&(s.forEach(l=>l.cancel()),dc.delete(i)),o(r,!0)}else{const s=setTimeout(()=>{o(r,!1),dc.delete(i)},300),l=()=>{clearTimeout(s),dc.delete(i)},a=dc.get(i);a?a.push({cancel:l}):dc.set(i,[{cancel:l}])}}const{Markmap:vO}=ZB;function yO(n,t){Fe(t);const e=u9(n,t),o=e[0].block,r=d=>({t:"text",v:Lt(d.block).textContent,d:1,c:d.children.length>0?d.children.map(p=>r(p)):void 0});let i=null;e.length>1?i={t:"root",v:"root",d:0,c:e.length>0?e.map(d=>r(d)):void 0}:i=r(e[0]);const l=d=>{if(d.length===0)return null;const h=d[d.length-1];return h.children&&h.children.length>0?l(h.children):h},a=l(e);return{root:i,block:o,nodes:e,last:a}}function uf(n,t,e,o){const{root:r,block:i,last:s}=yO(n,t);o.selectBlock&&n.selection.selectBlock(i,0,0),d0(n,i,!1),o.saveData&&n.updateBlockData(i,{viewAsMindmap:!0});const l=te(i);let a=l.querySelector(".editor-mindmap-svg");if(o.reset&&(a&&a.remove(),a=null),a)a.innerHTML="";else{const _="http://www.w3.org/2000/svg",M=l.getBoundingClientRect(),H=document.fullscreenElement===l,z=H?`${M.width}`:`${t.getBoundingClientRect().width}`,q=H?`${M.height}`:"600",rt=document.createElementNS(_,"svg");rt.setAttributeNS(null,"viewBox",`0 0 ${z} ${q}`),rt.setAttributeNS(null,"width","100%"),rt.setAttributeNS(null,"height",q),rt.style.display="block",rt.style.width="100%",rt.style.height=`${q}px`,rt.classList.add("editor-mindmap-svg"),l.appendChild(rt),a=rt}const d=i,p=`editor-mindmap-root-${it(i)}`;W(d,"editor-in-mindmap-first",p,"readonly"),d.contentEditable="false";const A=Zt(i);A&&bt(A)<=bt(s.block)&&uO(A,s.block,["block-hidden",p]);const v=(_,M)=>{if(M.length>0){const H=M[0].parentElement;H&&(H.style.width="100vw",H.style.maxWidth="200px")}M.forEach(H=>{W(H,"editor-mindmap-node")})},B=new vO(a,{...e,autoFit:!0});B.viewHooks.transformHtml.tap(v),B.setData(r),B.fit();const D=te(i);let x=D.querySelector(".mindmap-toolbar");x||(x=w("div",["mindmap-toolbar"],D)),CO(n,x,d,o.mindmapTools),AO(n,x,d,o.mindmapTools),pO(n,x,d,o.mindmapTools),n.domEvents.addEventListener(a,"click",()=>{n.selection.selectBlock(i,0),n.input.focus()}),d.mindMap=B}function kO(n){const t=w("div",["list-to-mindmap-wrap"],null),e=uo("list-to-mindmap",R.t("mindmap.viewAsMindMap"),JR,[],n.clientId);return t.appendChild(e),t}async function m9(n,t){const e=`editor-mindmap-root-${t.id}`,o=nt(t);pe(o).forEach(l=>{xt(l,e)&&ot(l,e,"editor-in-mindmap-first","block-hidden")});const i=te(t);document.fullscreenElement===i&&await h9();const s=i.querySelector(".editor-mindmap-svg");!s||(g(ke,s,"no mindmap svg"),s.remove(),n.domEvents.removeAllListeners(s),bO(n,t))}function wO(n){const t=n.classList,e="editor-mindmap-root-";return Array.from(t).find(r=>{if(r.startsWith(e))return r})}async function g9(n,t){!wO(t)||(n.updateBlockData(t,{viewAsMindmap:null}),m9(n,t),n.selection.selectBlock(t,0))}function BO(n,t){const e=t.mindMap;e&&e.fit()}const h0={toMindmap:uf,closeMindmap:g9,fitMindmap:BO},Bnt="";class df{constructor(t){m(this,"toMindmapButton");m(this,"currentBlock",null);m(this,"handleHoveringBlock",t=>{!this.editor.isWritable()||(t&&Ht(t)&&Zn(t)!=="unchecked"&&Zn(t)!=="checked"?te(t).appendChild(this.toMindmapButton):this.toMindmapButton.remove())});m(this,"handleMouseEnter",()=>{const t=et(this.toMindmapButton);g(ke,t&&Ht(t),"no parent list"),d0(this.editor,t,!0),this.currentBlock=t});m(this,"handleMouseLeave",()=>{this.currentBlock&&(d0(this.editor,this.currentBlock,!1),this.currentBlock=null)});m(this,"handleClick",()=>{const t=et(this.toMindmapButton);g(ke,t&&Ht(t),"no parent list"),uf(this.editor,t,{},{saveData:!0,selectBlock:!0,mindmapTools:h0})});this.editor=t,Ae.get(this.editor).addListener("change",this.handleHoveringBlock),this.toMindmapButton=kO(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(df)}destroy(){Ae.get(this.editor).removeListener("change",this.handleHoveringBlock)}hide(){this.currentBlock&&(this.currentBlock=null),this.toMindmapButton.remove()}}function EO(n,t,e){var o;t==="beginDrag"&&((o=df.get(n))==null||o.hide())}function hc(n,t,e,o){var i;const r=(i=o==null?void 0:o.groupId)!=null?i:K();t.forEach(s=>{const l=n.getBlockData(s);if(l.start!==e||(o==null?void 0:o.resetGroupId)){const a={...l,start:e};o!=null&&o.resetGroupId&&(a.groupId=r),n.updateBlockData(s,a)}l.textOnly||(e+=1)})}function f0(n,t,e,o){const r=a9(t,{withSelf:!0});r.length!==0&&hc(n,r,e,o)}class hf{constructor(t,e){m(this,"listStart",0);m(this,"listBrother",null);if(this.editor=t,af(e))return;const o=Cu(e),r=mo(o);this.listStart=r,o===e?this.listBrother=Gs(o):this.listBrother=o}fix(){!this.listBrother||f0(this.editor,this.listBrother,this.listStart)}}class Zs{constructor(t,e,o){m(this,"listStart");m(this,"listBrother",null);this.editor=t,this.options=o;const r=Cu(e),i=mo(r);this.listStart=i,this.listBrother=r,o!=null&&o.resetStart&&(this.listStart=1)}fix(){!this.listBrother||f0(this.editor,this.listBrother,this.listStart,this.options)}}class xO{constructor(t,e,o){m(this,"listStart");m(this,"listNextBrothers",[]);this.editor=t,this.listNextBrothers=uc(e);const{start:r,resetStart:i}=o||{};this.listStart=i?1:r!=null?r:1}fix(){!this.listNextBrothers.length||hc(this.editor,this.listNextBrothers,this.listStart)}}function IO(n,t,e){n.getBlockData(t).quoted&&(e.quoted=!0)}function m0(n,t,e,o){if(ke.debug("drag a block on a list block"),!tt(n,t))return!1;g(ke,Ht(e),"target is not a list block");const{type:r,start:i,level:s,groupId:l}=Gi(e),a=o==="after"?i+1:i,d=n.getBlockData(t),h={id:K(),type:"list",groupId:l,level:s,start:a,text:d.text,...l0(r)};IO(n,e,h);let p=bt(e);const A=nt(e);o==="after"&&(p+=1);let v=null;Ht(t)&&(v=new hf(n,t));const B=n.insertBlock(at(A),p,h,ph(h.id,0));return n.deleteBlock(t),new Zs(n,B).fix(),v==null||v.fix(),!0}function TO(n,t,e,o){if(ke.debug("drag a list between text blocks"),o==="after"){const d=Zt(e);if(d&&Ht(d))return m0(n,t,d,"before")}if(o==="before"){const d=ce(e);if(d&&Ht(d))return m0(n,t,d,"after")}const i={...n.getBlockData(t),groupId:K(),start:1,level:1};let s=bt(e);const l=nt(e);o==="after"&&(s+=1),n.insertBlock(at(l),s,i,ph(i.id,0));const a=new hf(n,t);return n.deleteBlock(t),a.fix(),!0}function DO(n,t,e,o,r){if(Gd(e))return!1;const{blockId:i}=e,s=n.getBlockById(i);g(ke,s,"no dragged block");const{isSourceBlock:l,targetBlock:a}=r;return!l&&a?(g(ke,t===a,"block !== target block"),g(ke,Ht(a),"target is not a list block"),m0(n,s,a,o)):TO(n,s,a,o)}function ff(n){const t=n.getAttribute("block-padding-level");return t?Number(t):null}function SO(n,t){let e;const o=ff(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 p9(n,t){const e=ff(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 g0(n){return n.readonly||!n.isWritable()}function LO(n){return n.selection.range.getSelectedBlocks().forEach(e=>{const o=e.block;tt(n,o)&&SO(n,o)}),!0}function MO(n){return n.selection.range.getSelectedBlocks().forEach(e=>{const o=e.block;tt(n,o)&&p9(n,o)}),!0}function RO(n){return g0(n)?!1:n.undoManager.runInGroup(()=>(LO(n),!0))}function OO(n){return g0(n)?!1:n.undoManager.runInGroup(()=>(MO(n),!0))}function _O(n){if(g0(n))return!1;if(!n.selection.range.isCollapsed())return;const t=n.selection.focusedBlock;if(!tt(n,t))return;const e=n.selection.range.focus;if(!(!e.isSimple()||e.offset!==0||!ff(t)))return p9(n,t),!0}class p0{renderBlock(t,e,o){const{padding:r}=o;return r?{attributes:{"block-padding-level":r}}:{}}}const Ent="",FO={Tab:RO,"Shift+Tab":OO,Backspace:_O};function PO(n,t,e=1){if(!t)return null;let o=ce(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 Ht(o)?o:null}o=ce(o)}return null}function NO(n,t){const e=n.getAttribute("data-style-heading"),o=PO(n,e);if(o)return o;const r=ce(n);if(r&&Ht(r)&&Zn(r)===t)return r;const i=Zt(n);return i&&Ht(i)&&Zn(i)===t?i:null}function $O(n,t,e){var D,x,_;const o=(D=e.data)!=null?D:{};let r=1;if(Ht(t))r=An(t);else{const M=ff(t);M&&(r=M+1),r>8&&(r=8)}const i=(x=o.listType)!=null?x:"ordered";if(i==="text-only")return null;const s=n.getBlockData(t);let l=(_=s.text)!=null?_:[],d=ie(l);const h=e.offset||0;h<=rn(l)&&(l=In(l,h).right,d=d.substring(0,h));let p=1;i==="ordered"&&(p=Number.parseInt(d,10)||1);let A=K();const v=NO(t,i);if(v){if(bt(t)>bt(v))p=mo(v)+1;else{const H=mo(v);H>1&&(p=H-1)}A=ac(v),new xO(n,v,{start:p+1}).fix()}const B={id:K(),type:"list",level:r,start:p,groupId:A,ordered:!1,text:l};return s.quoted&&(B.quoted=!0),s.heading&&(B.heading=s.heading),i==="ordered"?B.ordered=!0:(i==="checked"||i==="unchecked")&&(B.checkbox=i),{blockData:B,onConverted:(M,H)=>{new Zs(M,H).fix()}}}function fc(n){return n.textOnly?"text-only":n.checkbox?n.checkbox:n.ordered?"ordered":"unordered"}function HO(n){var e,o;if(n.checkbox||n.textOnly)return"";const t=(e=n.level)!=null?e:1;return n.ordered?`${nO(t,(o=n.start)!=null?o:1)}.`:oO(t)}function mf(n){return n==="checked"||n==="unchecked"}function C9(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 a=fc(r),d=fc(l);return a!==d&&(!mf(a)||!mf(d))||r.level>l.level}function A9(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 a=fc(r),d=fc(l);return a!==d&&(!mf(a)||!mf(d))||r.level>l.level}function jO(n,t,e,o,r){var s,l,a;const i=t;if(o==="text")return((s=Tn.convertTo)==null?void 0:s.call(Tn,n,t,e,"text",r))||"";if(o==="markdown"){let d=((l=Tn.convertTo)==null?void 0:l.call(Tn,n,t,e,"markdown",r))||"";i.checkbox==="checked"?d=`[x] ${d}`:i.checkbox==="unchecked"&&(d=`[ ] ${d}`),i.ordered?d=`${i.start}. ${d}`:d=`- ${d}`;const h=i.level||0;return d=(h>0?" ".repeat(h-1):"")+d,C9(n,t,e,r)&&(d=`${d}`),A9(n,t,e,r)&&(d=`${d}`,h<=1&&(d+=`
|
|
397
|
-
`)),d}if(o==="html"){let d=((a=Tn.convertTo)==null?void 0:a.call(Tn,n,t,e,"html",r))||"";d=d.replace("<p>","").replace("</p>",""),i.checkbox==="checked"?d=`<input type="checkbox" checked="checked" disabled="disabled" /> ${d}`:i.checkbox==="unchecked"&&(d=`<input type="checkbox" disabled="disabled" /> ${d}`);let h="ul";return i.ordered?(d=`<li value="${i.start}">${d}</li>`,h="ol"):d=`<li>${d}</li>`,C9(n,t,e,r)&&(d=`<${h}>${d}`),A9(n,t,e,r)&&(d=`${d}</${h}>`),d}return""}function b9(n){const t=w("label",["editor-check-list-wrapper"],null);n&&W(t,"editor-check-list-wrapper-checked");const e=w("span",["editor-check-box"],t);return w("span",["editor-check-box-inner"],e),t}function UO(n,t){const e=fc(t);if(e!=="text-only"){if(e==="checked"){n.append(b9(!0));return}if(e==="unchecked"){n.append(b9(!1));return}n.innerText=HO(t)}}function zO(n){const t=w("div",["list-container"],null),e=w("button",["list-marker"],t);return UO(e,n),t}function v9(n){let t=Zt(n);if(!t)return null;const e=Gs(n);for(;t!==e;){if(g(ke,t,"no next block"),Ht(t))return An(t)>An(n)?t:null;if(t=Zt(t),!t)return null}return null}function C0(n){const t=[];let e=v9(n);if(!e)return t;for(;e;){const o=Gs(e);t.push({block:e,children:C0(e)}),e=o}return t}function VO(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 y9(n,t){return An(t)!==1}function k9(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&&k9(n,o.children,r.groupId)})}function A0(n,t){if(!y9(n,t))return!1;const e=An(t);if(e===1)return!1;let o=K(),r=1,i=Zn(t);const s=e-1,l=c0(t);l&&(o=ac(l),r=mo(l)+1,i!=="text-only"&&(i=Zn(l)));const a=C0(t),d=n.getBlockData(t),h={...d,groupId:o,level:s,start:r,...l0(i)};n.updateBlockData(t,h),n.doc.beginBatchUpdate(),k9(n,a,d.groupId),n.doc.endBatchUpdate(),new Zs(n,t).fix();const A=v9(t);return A&&new Zs(n,A,{resetStart:!0,resetGroupId:!0}).fix(),!0}function mc(n,t){Fe(t);const e=n.getBlockData(t),o={id:K(),type:"text",text:e.text};e.heading&&(o.heading=e.heading),e.heading&&(o.heading=e.heading);const r=new hf(n,t),i=nt(t),s=bt(t);if(n.deleteBlock(t),Ba(n,i)&&!Yt(i)){const l=xe(i),a=Ce(n,l.id,0);n.updateBlockData(l,o,a)}else{const l=ph(o.id,0);n.insertBlock(at(i),s,o,l)}r.fix()}function WO(n){if(!n.selection.range.isCollapsed())return!1;const t=n.selection.focusedBlock;if(!Ht(t))return!1;const e=n.selection.range.focus;return!e.isSimple()||e.offset!==0?!1:An(t)===1?(mc(n,t),!0):(A0(n,t),!0)}const qO=S("list-block");function GO(n,t,e){g(qO,Ht(t),"not a list block");const o={...n.getBlockData(t),id:K()};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==null?void 0:o.checkbox)==="checked"&&(o.checkbox="unchecked"),o}function ZO(n){if(Fe(n),!af(n))return n;let t=Zi(n);for(;t;){if(!af(t))return t;t=Zi(t)}return null}function QO(n,t,e,o){const r=new Zs(n,o),i=mo(o)+1;Ql(n,t,e,{forceInsertAfter:!0,newBlockData:GO(n,o,{start:i})}),r.fix()}function YO(n){var s;if(n.selection.range.isCollapsed()){const l=n.selection.focusedBlock;if(Ht(l)&&ut(n,l)===0)return mc(n,l),!0}n.clearSelectedContents();const t=n.selection.focusedBlock;if(!Ht(t))return!1;const e=n.selection.range.focus;if(!e.isSimple())return!1;const o=e.offset,i=(s=o===ut(n,t)?ZO(t):t)!=null?s:t;return QO(n,t,o,i),!0}function w9(n){g(ke,Ht(n),"not a list block");const{level:t}=Gi(n);let e=ce(n);for(;e;){if(Ht(e)){const{level:o}=Gi(e);if(t===o)return e;if(o<t)return null}e=ce(e)}return null}function B9(n,t){return Fe(t),w9(t)?An(t)<KR:!1}function JO(n,t,e){let o=ce(t);g(ke,o,"no prev brother");const r=An(e);for(;o;){if(o===e)return null;if(Ht(o)&&An(o)===r+1)return o;o=ce(o)}return null}function E9(n,t){if(!B9(n,t))return!1;Fe(t);const e=w9(t);g(ke,e,"no list prev brother");const o=e,r=JO(n,t,o),i=An(o)+1;let s=K(),l=1,a=Zn(t);r&&(s=ac(r),l=mo(r)+1,a=Zn(r));const d=C0(t),p={...n.getBlockData(t),groupId:s,level:i,start:l,...l0(a)};return n.updateBlockData(t,p),n.doc.beginBatchUpdate(),VO(d).forEach(v=>{const B=n.getBlockData(v);n.updateBlockData(v,{...B,level:B.level+1})}),n.doc.endBatchUpdate(),!0}function KO(n,t,e){return t.length===0||!t.every(o=>Ht(o.block))?!1:e==="increase"?B9(n,t[0].block):y9(n,t[0].block)}function x9(n,t,e){if(!KO(n,t,e))return!1;const o=t[0].block,r=An(o),i=t.filter(d=>An(d.block)<=r),s=a9(o,{withSelf:!1}),l=new Set(i.map(d=>d.block)),a=s.filter(d=>!l.has(d));return n.undoManager.runInGroup(()=>{let d=null;a.length>0&&(d=new Zs(n,a[0])),i.forEach(h=>{e==="increase"?E9(n,h.block):A0(n,h.block)}),d==null||d.fix()}),!0}function XO(n,t){return E9(n,t)}function t_(n,t){return A0(n,t)}function e_(n){const t=n.selection.range.getSelectedBlocks();if(t.length>1)return x9(n,t,"increase"),!0;const e=t[0].block;if(!Ht(e))return!1;const o=new hf(n,e);return XO(n,e)&&(o.fix(),new Zs(n,e).fix()),!0}function n_(n){const t=n.selection.range.getSelectedBlocks();if(t.length>1)return x9(n,t,"decrease"),!0;const e=t[0].block;return Ht(e)?(t_(n,e),!0):!1}class o_{constructor(t){this.editor=t}handleBeforeKeyDown(t,e){const o=t.selection.range.getSelectedBlocks();if(o.length===0||!o.some(i=>Ht(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||!Ht(e.block)||_r(t,"Shift+Enter")?!1:this.editor.undoManager.runInGroup(()=>YO(this.editor))}handleBackspace(){return this.editor.undoManager.runInGroup(()=>WO(this.editor))}handleTab(t){return _r(t,"Shift+Tab")?this.editor.undoManager.runInGroup(()=>n_(this.editor)):this.editor.undoManager.runInGroup(()=>e_(this.editor))}}class r_{constructor(t){m(this,"effectedBlockIds",new Map);m(this,"handleBeforeClearSelection",()=>{this.effectedBlockIds.clear();const t=this.editor.selection.range.getSelectedBlocks();if(t.length===0)return;const e=new Set;t.forEach(r=>{const i=r.block;Ht(i)&&e.add(i)});const o=new Map;Array.from(e.values()).forEach(r=>{var a;const i=Cu(r),{start:s}=Gi(i);o.set(it(i),s);const l=(a=rO(r))!=null?a:r;o.set(it(l),s)}),this.effectedBlockIds=o});m(this,"handleAfterClearSelection",()=>{Array.from(this.effectedBlockIds.entries()).forEach(([t,e])=>{const o=this.editor.findBlockById(t);!o||f0(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 i_=S("customize-list-start-menu");class s_{constructor(t){m(this,"popup");m(this,"block",null);m(this,"show",(t,e)=>{const o=e.querySelector("div.list-container");g(i_,o,"list-block mark does not exist"),this.block=e,this.popup.manualShow(o,{theme:"light"})});m(this,"createDialogContent",()=>{const t=w("div",["customize-start-panel"],null);w("span",["customize-start-panel-title"],t,R.t("list.numberLabel"));const e=this.createNumericInput();t.appendChild(e);const o=w("button",["customize-start-panel-button"],t,R.t("list.confirm"));return this.editor.domEvents.addEventListener(t,"keydown",this.handleKeydown),this.editor.domEvents.addEventListener(o,"click",this.handleOk),t});m(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=mo(t);!o||!r||requestAnimationFrame(()=>{r.focus(),r.value=String(i)})});m(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(()=>{hc(this.editor,[o,...uc(o)],r,{resetGroupId:!0})}),this.popup.close("clickItem"))});m(this,"handleKeydown",(t,e)=>{const o=e;o.isComposing||(o.key==="Escape"?this.popup.close("cancelBar"):o.key==="Enter"&&this.handleOk())});this.editor=t,this.popup=new tu(this.createDialogContent()),this.popup.on("show",this.handleDialogShow)}destroy(){this.popup.destroy()}createNumericInput(){const t=w("input",["customize-start-panel-input"],null);t.type="number",t.min="1";const e=()=>{const r=t.value.replace(/[^\d]/g,"").replace(/^0+/,""),i=parseInt(r,10);i<=0||Number.isNaN(i)?t.value="":t.value=r};return this.editor.domEvents.addEventListener(t,"input",e),t}}function l_(n,t){return ac(n)===ac(t)}function c_(n,t){const e=l9(t);return e?l_(e,t)?mo(e)!==mo(t)-1:!0:!1}function a_(n,t){return Zi(t)?!0:mo(t)!==1}function u_(n,t){return Fe(t),[{id:"continue-numbering",name:R.t("list.continueList"),states:c_(n,t)?[]:["disabled"]},{id:"start-new-list",name:R.t("list.restartList"),states:a_(n,t)?[]:["disabled"]},{id:"set-numbering-value",name:R.t("list.changeNumber")}]}function d_(n,t,e){var o,r;if(Fe(t),e.id==="continue-numbering"){const i=l9(t);i&&hc(n,[t,...uc(t)],mo(i)+1,{resetGroupId:!0,groupId:ac(i)})}if(e.id==="start-new-list"&&n.undoManager.runInGroup(()=>{hc(n,[t,...uc(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 s_(n)).show(n,t)}}class h_{constructor(t){m(this,"menu");m(this,"handleClick",(t,e)=>{const o=Hl(e,"div.list-container");if(o&&this.editor.isWritable()){const r=et(o);g(ke,r,"no parent block"),Fe(r);const i=t.getBlockData(r);if(i&&i.checkbox){t.updateBlockData(r,{...i,checkbox:i.checkbox==="checked"?"unchecked":"checked"});return}if(Zn(r)==="unordered")return;this.menu.updateItems(this.getCommandItems(r)),this.menu.manualShow(o),this.activeList(o,!0)}});m(this,"handleMenuClose",()=>{var e;const t=(e=this.menu.tippyInstance)==null?void 0:e.reference;t&&this.activeList(t,!1)});m(this,"handleMenuClick",(t,e)=>{var r;const o=(r=this.menu.tippyInstance)==null?void 0:r.reference;if(o){const i=et(o);i&&d_(this.editor,i,e)}});this.editor=t,this.editor.addListener("click",this.handleClick),this.menu=new zs([]),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 u_(this.editor,t)}activeList(t,e){const o=et(t);!o||(e?(W(t,"active"),W(o,"active")):(ot(t,"active"),ot(o,"active")))}}class f_{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(!Ht(r)||!f9(r))return!1;if(e.key==="ArrowUp"||e.key==="ArrowLeft"){const i=Ts(r);return i&&t.selection.selectBlock(i,ut(t,i)),!0}if(e.key==="ArrowDown"||e.key==="ArrowRight"){const i=Ds(r);return i&&t.selection.selectBlock(i,0),!0}return(e.key==="Delete"||e.key==="Backspace"||e.key==="Escape")&&g9(t,r),!0}}function m_(n,t,e,o,r){tp(n,"list-block-init",()=>{setTimeout(()=>{n.input.addHandler(new f_(n)),n.input.addHandler(new o_(n)),n.addCustom("list-clear-selection-handler",()=>new r_(n)),n.addCustom("list-marker-menu",()=>new h_(n))})});const i=Tn.createBlockContent(n,t,e,o,r),s=r,{level:l,start:a,groupId:d}=s,h=fc(s);o.setAttribute("data-list-level",`${l}`),o.setAttribute("data-list-start",`${a||1}`),o.setAttribute("data-list-group-id",`${d}`),o.setAttribute("data-list-type",h);const p=zO(s);return o.insertBefore(p,i),s.viewAsMindmap?setTimeout(()=>{const A=n.getBlockById(r.id);A&&uf(n,A,{},{mindmapTools:h0,saveData:!1})}):setTimeout(()=>{const A=n.getBlockById(r.id);A&&m9(n,A)}),i}const g_={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"}},p_={list:{confirm:"Confirm",setStart:"Set number",continueList:"Continue numbering",restartList:"Start a new list",changeNumber:"Set numbering value",numberLabel:"Numbering order",mention:{tooltip:"Mention and notify users"}},mindmap:{viewAsMindMap:"View as MindMap",autoFit:"Auto zoom",fullScreen:"Full screen",close:"Close",exitFullscreen:"Exit full screen"}},C_={list:{confirm:"OK",setStart:"\u756A\u53F7\u3092\u8A2D\u5B9A",continueList:"\u9023\u756A\u3092\u8A2D\u5B9A",restartList:"\u65B0\u3057\u3044\u30EA\u30B9\u30C8\u3092\u4F5C\u6210",changeNumber:"\u756A\u53F7\u3092\u7DE8\u96C6",numberLabel:"\u756A\u53F7",mention:{tooltip:"\u30E1\u30F3\u30B7\u30E7\u30F3\u304A\u3088\u3073\u901A\u77E5"}},mindmap:{viewAsMindMap:"\u30DE\u30A4\u30F3\u30C9\u30DE\u30C3\u30D7\u3067\u8868\u793A",autoFit:"\u81EA\u52D5\u30D5\u30A3\u30C3\u30C8",fullScreen:"\u5168\u753B\u9762\u8868\u793A\u306E\u30AA\u30F3",close:"\u9589\u3058\u308B",exitFullscreen:"\u5168\u753B\u9762\u8868\u793A\u306E\u30AA\u30D5"}};R.mergeLang({"zh-CN":g_,"en-US":p_,"ja-JP":C_});const xnt="",I9={...Tn,blockType:"list",createBlockContent:m_,convertFrom:$O,convertTo:jO,handleDrop:DO,notify:EO},b0=S("paragraph");class A_{constructor(t){m(this,"id","BlockParagraphProvider");this.editor=t}isChecked(t,e){return!!(t[e]||t.level&&(t.ordered===!0&&!t.checkbox&&e==="ordered-list"||t.ordered===!1&&!t.checkbox&&e==="unordered-list")||e==="check-list"&&t.checkbox)}getAvailableCommands(t,e){const o=[],r={"unordered-list":[R.t("commands.unordered"),xo("CtrlOrCmd+Shift+L"),xL],"ordered-list":[R.t("commands.ordered"),xo("CtrlOrCmd+Shift+U"),EL],"check-list":[R.t("commands.check"),void 0,IL],link:[R.t("commands.link"),xo("CtrlOrCmd+K"),hv],quoted:[R.t("commands.quote"),void 0,TL]};if(tt(t,e)){const i=it(e),s=Dt(e),l=Do(t,e),a=t.getBlockData(e);Object.entries(r).forEach(([d,[h,p,A]])=>{const v=[];if(this.isChecked(a,d)&&v.push("checked"),d==="link"){if(!t.selection.range.isSimple())return;t.selection.range.getSelectedBlocks().length!==1&&v.push("disabled")}o.push({blockId:i,blockType:s,blockKind:l,id:d,name:h,desc:p,states:v,icon:A,groupIndex:600})})}return o}convertLink(t,e,o){g(b0,Ur(e.start),""),g(b0,Ur(e.start),"");const r="bottom-start",i=e.start.offset,s=e.end.offset,l=(v,B)=>{t.undoManager.runInGroup(()=>{try{const D=t.selection.range.isCollapsed();let x;if(D){x=Vr(t.getBlockText(o),s,v,{link:B}),t.setBlockText(o,x);return}x=fh(t.getBlockText(o),i,s,v),x=Ta(i,v.length,x,"link",B),t.setBlockText(o,x),t.selection.selectBlock(o,i+v.length),t.focus()}catch(D){b0.error(D)}})},a=()=>{t.selection.selectBlock(o,s),t.focus()},d=Nr(t,o,e)[0];if(!d)return;const h=zr(t,o,"link-button-anchor",d),p=t.getBlockText(o),A=Da(p,i);gu(t,{target:h,linkText:t.getSelectedText(),linkUrl:(A==null?void 0:A.link)||"",onFinished:l,onClose:a,placement:r})}convertToList(t,e,o){const r=th(t,e,"list",{offset:0,data:{listType:o}});r&&t.undoManager.runInGroup(()=>{const i=bt(e),s=nt(e);t.insertBlock(at(s),i,r.blockData),t.deleteBlock(e),t.focus()})}executeCommand(t,e,o,r){var a;if(!tt(t,e))return!1;const i=r.id,s=(a=r.states)==null?void 0:a.includes("checked");let l=!1;if(i==="unordered-list"&&(s?mc(t,e):this.convertToList(t,e,"unordered"),l=!0),i==="ordered-list"&&(s?mc(t,e):this.convertToList(t,e,"ordered"),l=!0),i==="check-list"&&(s?mc(t,e):this.convertToList(t,e,"unchecked"),l=!0),i==="quoted"){const h=t.getBlockData(e).quoted;t.updateBlockData(e,{quoted:h?void 0:!0}),t.focus(),l=!0}if(i==="link"){const d=sf(t);d.disableTextToolbar(),d.hide(),setTimeout(()=>{d.enableTextToolbar()},1e3),this.convertLink(t,o,e),l=!0}return l}}const b_={left:eu,right:Ip,center:Tp};class v_{constructor(t){m(this,"id","BlockAlignProvider");this.editor=t}applyAlignStyle(t,e,o){Object.keys(b_).includes(o)?t.updateBlockData(e,{align:o}):t.updateBlockData(e,{align:null})}isChecked(t,e){return t.align===e}getAvailableCommands(t,e,o){if(tt(t,e)){const r=it(e),i=Dt(e),s=Do(t,e),l=t.getBlockData(e),a=d=>{var p;const h=w("span",["toolbar-item-name-container"],null);for(const A of d.children)if((p=A.states)!=null&&p.includes("checked"))return h.innerHTML=A.icon||eu,h;return h.innerHTML=eu,h};return[{id:"align",name:R.t("commands.alignGroup"),blockId:r,blockType:i,blockKind:s,groupIndex:700,dropdown:!0,element:a,manualShowChildren:!0,childrenPlacement:"bottom-start",defaultCheckedChildren:["align-left"],children:[{id:"align-left",name:R.t("commands.alignLeft"),icon:eu,states:this.isChecked(l,"left")?["checked"]:[]},{id:"align-center",name:R.t("commands.alignCenter"),icon:Tp,states:this.isChecked(l,"center")?["checked"]:[]},{id:"align-right",name:R.t("commands.alignRight"),icon:Ip,states:this.isChecked(l,"right")?["checked"]:[]}],childrenType:"menu"}]}return[]}executeCommand(t,e,o,r){if(!tt(t,e))return!1;if(r.id.startsWith("align")){const i=r.id.replace(/^align-/,"");return this.applyAlignStyle(t,e,i),this.editor.focus(),!0}return!1}}function y_(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 La(n,o,e.start.offset).charType==="box"}const k_=S("toolbar-handler"),w_={id:"",name:"",type:"separator"};class gc{constructor(t){m(this,"toolbar");m(this,"toolbarType","object");m(this,"mouseDown",!1);m(this,"oldRange",null);m(this,"hoveringBlock",null);m(this,"hoveringTextChild",null);m(this,"_disableTextToolbar",!1);m(this,"handleButtonClick",(t,e)=>{this.toolbarType==="text"?(this.editor.editorCommandProviders.executeCommand(this.editor.selection.range,e,{}),this.showTextToolbar("click")):this.hoveringBlock&&ZR(this.editor,this.hoveringBlock,this.hoveringTextChild,e)});m(this,"handleClose",()=>{Op(this.editor)&&this.editor.focus()});m(this,"handleClosing",(t,e)=>{if(this.toolbarType==="object"){const o=rC(e);if(this.hoveringBlock===o)return!1}return!0});m(this,"handleDocumentMouseDown",t=>{t.button===0&&(document.addEventListener("mouseup",this.handleDocumentMouseUp),this.mouseDown=!0)});m(this,"handleDocumentMouseUp",()=>{document.removeEventListener("mouseup",this.handleDocumentMouseUp),this.mouseDown=!1,this.handleSelectionChange(this.editor)});m(this,"handleHoveringBlockChildChange",(t,e,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("fromHover");return}this.showObjectToolbar(r)}});m(this,"handleSelectionChange",Le.default(t=>{var o;if(g(k_,t===this.editor,"editor mismatch"),t.selection.range.isCollapsed()||this.mouseDown){if(this.toolbarType==="object"){const r=(o=this.toolbar.tippyInstance)==null?void 0:o.reference,i=this.editor.selection.focusedBlock;if(r&&Xt(r,i))return}this.toolbar.close("selectionChange"),this.oldRange=null;return}if(!this.editor.isWritable()){this.toolbar.close("selectionChange"),this.oldRange=null;return}if(t.selection.range.getSelectedBlocks().length===0){this.toolbar.close("selectionChange"),this.oldRange=null;return}this.oldRange&&this.oldRange.isEqual(t.selection.range)||(this.oldRange=t.selection.range,this.showTextToolbar("selectionChange"))},50));this.editor=t;const e=t.options.componentsOptions.popover;this.toolbar=new ru([],void 0,{tooltipId:t.clientId,id:"editor-toolbar",overflowBoundary:e==null?void 0:e.overflowBoundary,refuseOverflow:!0,padding:20}),this.toolbar.on("click",this.handleButtonClick),this.toolbar.on("close",this.handleClose),this.toolbar.on("closing",this.handleClosing),this.bindEvents(),t.addListener("selectionChanged",this.handleSelectionChange),Ae.get(t).addListener("childChange",this.handleHoveringBlockChildChange),Ae.get(t).addFilter(this),t.editorCommandProviders.registerCommandProvider(new YR(t)),t.editorCommandProviders.registerCommandProvider(new A_(t)),t.editorCommandProviders.registerCommandProvider(new v_(t))}disableTextToolbar(){this._disableTextToolbar=!0}enableTextToolbar(){this._disableTextToolbar=!1}hide(){this.toolbar.close("selectionChange")}destroy(){this.unbindEvents(),this.toolbar.destroy(),this.editor.removeListener("selectionChanged",this.handleSelectionChange),Ae.get(this.editor).removeListener("childChange",this.handleHoveringBlockChildChange)}isInBlock(t,e){return t!==this.hoveringBlock?!1:!!(e.target&&e.target instanceof Node&&this.toolbar.popper&&Xt(this.toolbar.popper,e.target))}bindEvents(){document.addEventListener("mousedown",this.handleDocumentMouseDown)}unbindEvents(){document.removeEventListener("mousedown",this.handleDocumentMouseDown)}update(t){this.showTextToolbar(t)}showTextToolbar(t){var D,x;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&&Me(r.block)){t==="click"&&this.showObjectToolbar(null);return}if(y_(this.editor))return;if(nt(r.block)===this.editor.rootContainer&&bt(r.block)===0){this.toolbar.close("selectionChange");return}const i=this.editor.editorCommandProviders.getCommands(this.editor.selection.range),s=new Map;i.forEach(_=>{const M=_.groupIndex,H=s.get(M);H?H.push(_):s.set(M,[_])});const l=[[]],a=Array.from(s.entries()).sort((_,M)=>_[0]-M[0]);for(let _=0;_<a.length;_++){const[,M]=a[_];if(M.length===0)continue;let H=l[l.length-1];H.length>0&&H[H.length-1].groupIndex!==M[M.length-1].groupIndex&&(H=[],l.push(H)),H.push(...rf(M))}if(l.length===0){this.toolbar.close("selectionChange");return}this.toolbarType="text";const d=[];if(l.forEach((_,M)=>{const H=_.sort((z,q)=>{var rt,ft;return((rt=z.order)!=null?rt:0)-((ft=q.order)!=null?ft:0)});d.push(...H),M!==l.length-1&&d.push(w_)}),d.length===0){this.toolbar.close("selectionChange");return}this.toolbar.updateItems(d);const h=o[o.length-1],p=!this.editor.selection.range.isReverse()&&h!==r,A=p?h:r,v=HR(this.editor,A),B=zr(this.editor,A.block,"editor-quick-menu",v);this.toolbar.manualShow(B,{placement:p?"bottom":"top",offset:[0,p?5:10]}),(x=(D=this.toolbar.tippyInstance)==null?void 0:D.popperInstance)==null||x.update()}showObjectToolbar(t){var l,a,d;if(!this.hoveringBlock||this.mouseDown)return;const e=this.hoveringBlock,o=this.hoveringTextChild,{commands:r,element:i}=WR(this.editor,e,o);if(!r.length||!i){this.toolbar.close("fromHover");return}this.toolbarType="object",this.toolbar.isVisible&&((a=(l=this.toolbar)==null?void 0:l.tippyInstance)==null?void 0:a.reference)!==i&&this.toolbar.close("fromHover");const s=()=>{let h;const p=i.getClientRects();if(p.length>1){if(h=o?p[p.length-1]:p[0],t)for(let A=0;A<p.length;A++){const v=p[A],B=new DOMRect(v.x-4,v.y-4,v.width+8,v.height+8);if(B.x<t.clientX&&t.clientX<B.right&&B.y<t.clientY&&t.clientY<B.bottom){h=v;break}}}else{if(h=i.getBoundingClientRect(),o){const A=o.getBoundingClientRect();return new DOMRect(A.x,A.y,A.width,A.height)}return new DOMRect(p[0].x,p[0].y,p[0].width,p[0].height)}if(t){const A=h.y,v=t.clientX;return new DOMRect(v,A,10,h.height)}return h};this.toolbar.updateItems(r),this.toolbar.isVisible||(this.toolbar.manualShow(i,{placement:o?"bottom":"top",getReferenceClientRect:s}),(d=this.toolbar.tippyInstance)!=null&&d.popper&&(this.toolbar.tippyInstance.popper.style.paddingTop="10px",this.toolbar.tippyInstance.popper.style.paddingBottom="5px"))}static register(t){return t.addCustom("toolbar-handler",e=>new gc(e))}static get(t){return t.getCustom("toolbar-handler")}}function gf(n,t,e){n.getBlockData(t).heading===e?n.updateBlockData(t,{heading:null}):n.updateBlockData(t,{heading:e})}function T9(n,t,e){["left","center","right"].includes(e)?n.updateBlockData(t,{align:e}):n.updateBlockData(t,{align:null})}function v0(n,t){const o=n.getBlockData(t).quoted;n.updateBlockData(t,{quoted:o?void 0:!0})}function y0(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 k0(n,t,e){if(!n.selection.range.focus.isSimple())return;const r=n.getBlockData(t);let i;switch(e){case"unordered-list":i=y0(r,"unordered-list")?void 0:"unordered";break;case"ordered-list":i=y0(r,"ordered-list")?void 0:"ordered";break;case"check-list":i=y0(r,"check-list")?void 0:"unchecked";break}if(i){const s=th(n,t,"list",{offset:0,data:{listType:i}});s&&n.undoManager.runInGroup(()=>{const l=bt(t),a=nt(t);n.deleteBlock(t),n.insertBlock(at(a),l,s.blockData)})}else mc(n,t)}const B_=Object.freeze(Object.defineProperty({__proto__:null,applyHeadingStyle:gf,applyAlignStyle:T9,applyQuoteStyle:v0,applyList:k0},Symbol.toStringTag,{value:"Module"})),E_=[bp,vp,yp,kp,wp,Bp,Ep,xp],x_={Unordered:gv,Ordered:pv,Checkbox:fv,Quote:mv};function D9(n,t){const e=n;e.blockOptions=t,e.itemType="insert-block",n.children&&n.children.forEach(o=>D9(o,t))}function I_(){return{name:"basic",insertBlockCommandItems:[{id:"text",icon:ou,name:R.t("commands.text"),order:0,group:"basics",value:"text"}]}}function w0(n=1){var r;const t={name:"basic",insertBlockCommandItems:[]};let e=lf();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:E_[o-1],name:R.t("quickMenu.basic.heading.title",{heading:String(o)}),order:o,group:"basics",value:String(o),subText:Cn(i)}),o++}return t}function T_(){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:R.t(`quickMenu.basic.${e.toLocaleLowerCase()}`),icon:x_[e],value:e.toLocaleLowerCase(),group:"basics",order:10+o,subText:Cn(r)})}),n}class S9{constructor(t){this.withPlainText=t}getCommands(){const t=I_(),e=w0(),o=T_();return[...this.withPlainText?t.insertBlockCommandItems||[]:[],...e.insertBlockCommandItems||[],...o.insertBlockCommandItems||[]]}updateBlock(t,e,o,r){const{value:i,id:s}=r;return s.startsWith("heading-")?gf(t,o,Number.parseInt(i!=null?i:"1",10)||1):i==="ordered"||i==="unordered"||i==="checkbox"?k0(t,o,{ordered:"ordered-list",unordered:"unordered-list",checkbox:"check-list"}[i]):i==="quote"&&v0(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=at(i),l=t.getBlockIndex(r);t.undoManager.runInGroup(()=>this.handleUpdateBlockCore(t,{item:e,containerId:s,blockIndex:l})),t.focus()}else o.from==="block-menu"&&(t.undoManager.runInGroup(()=>this.handleInsertEmptyBlockCore(t,{item:e,containerId:o.containerId,blockIndex:o.blockIndex})),t.focus());return null}}const L9={basics:100,system:200,common:300,thirdParty:400};class B0{constructor(){m(this,"dataUrl","");m(this,"error",null)}destroy(){}setDataUrl(t){this.error=null,this.dataUrl=t}setError(t){this.dataUrl="",this.error=t}}const D_=S("mathjax-converter"),S_="MathJax-script";async function L_(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 vs(e,S_)}function M_(){try{window.MathJax&&window.MathJax.texReset()}catch{}}async function M9(n,t){const e="mathjax2Svg";try{await Eo.lock(e),M_(),await L_(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 D_.error(o),o}finally{Eo.release(e)}}async function R9(n,t){const e=await M9(n,t);return e?await Tm(e,"image/svg+xml"):""}async function E0(n,t){const o=await M9(n,t),r=new File([o],"math.svg");return(await n.doc.uploadResource(r)).resourceId}const O9=S("edit-mathjax");class R_{constructor(){m(this,"editMathjaxPopup",null);m(this,"onChange",null);m(this,"tex","");m(this,"handleShow",()=>{setTimeout(()=>{this.getTextarea().focus()})});m(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))}});m(this,"handleKeyup",t=>{var e;t.isComposing||(t.key==="Escape"&&((e=this.editMathjaxPopup)==null||e.close("cancelBar")),this.handleChange(t.target.value))});m(this,"handleChange",Le.default(t=>{var e;(e=this.onChange)==null||e.call(this,t,!1)},300))}editMathjax(t,e,o){if(!this.editMathjaxPopup)this.editMathjaxPopup=new tu(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=w("textarea",["mathjax-editor-textarea"],null);return e.value=t,e.addEventListener("keyup",this.handleKeyup),e}getTextarea(){g(O9,this.editMathjaxPopup,"no exists mathjax editor popup");const t=this.editMathjaxPopup.content.querySelector("textarea");return g(O9,t,"no textarea"),t}destroy(){var t;this.onChange=null,(t=this.editMathjaxPopup)==null||t.removeAllListeners()}}function _9(n,t,e,o){n.addCustom("mathjax-editor",()=>new R_).editMathjax(t,e.trim(),o)}function F9(){return{insert:" ",attributes:{id:K(),box:!0,type:"math",tex:" ",src:"",created:Date.now()}}}function pf(n,t){const e=n.getBoxData(t),o=et(t);if(!o)return;const r=_s(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 Eo.lock("convertAndUploadMathjax");const a=await E0(n,s);n.updateBoxData({...e,tex:s,src:a})}catch(a){const d=n.getBoxData(t);n.addCustom(`mathjax-box-${d.id}`,()=>new B0).setError(a),n.updateBoxData({...e,tex:s,src:""})}finally{Eo.release("convertAndUploadMathjax"),l&&n.focus()}};_9(n,t,e.tex,i)}const P9=S("mathjax-box");function x0(n,t){n.selection.updateSelection(null);const e=t.target;!e||!(e instanceof HTMLElement)||n.domEvents.removeEventListener(e,null,x0)}async function O_(n,t,e){try{if(!t.tex.trim())return;const o=await R9(n,t.tex),r=n.findBoxById(t.id);if(!r)return;const i=Nm(r);i.innerHTML="";const s=w("img",["mathjax"],i);s.src=o,e.setDataUrl(o),n.domEvents.addEventListener(s,"load",x0)}catch(o){e.setError(o);const r=n.findBoxById(t.id);if(!r)return;const i=r.querySelector(".mathjax-tex-text");W(i,"mathjax-error"),i.innerText=o.message,n.selection.updateSelection(null)}}function __(n,t,e,o){const r=o,i=n.addCustom(`mathjax-box-${r.id}`,()=>new B0);if(r.src||i.dataUrl){const a=w("img",["mathjax"],e);a.src=n.doc.buildResourceUrl(r.src||i.dataUrl),n.domEvents.addEventListener(a,"load",x0);return}const s=["mathjax-tex-text"];let l=r.tex;l.trim()?i.error&&(l=i.error.message,s.push("mathjax-error")):l=R.t("mathjax.emptyText"),w("span",s,e,l),O_(n,r,i)}function F_(n,t){const e={id:K(),box:!0,type:"math",tex:t,src:"",created:Date.now()};return E0(n,t).then(o=>{if(!n.findBoxById(e.id))return;const i={...e,src:o};n.updateBoxData(i)}).catch(o=>{P9.error(`failed to convert and upload mathjax: ${JSON.stringify(o)}`)}),e}function P_(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 N_(n,t,e){const o=et(t);g(P9,o,"failed to get block"),!(n.readonly||!n.isBlockWritable(o))&&pf(n,t)}function $_(){return{abstract:R.t("mathjax.abstract")}}const I0={boxType:"math",updateBoxContent:__,convertFrom:F_,convertTo:P_,handleClickBox:N_,getBoxProperties:$_};async function H_(n,t,e){try{const o=t.embedData,r=await R9(n,o.mathjaxText),i=n.findBlockById(t.id);if(!i)return;const s=Lt(i);s.innerHTML="";const l=w("img",["mathjax"],s);l.src=r,e.setDataUrl(r)}catch(o){e.setError(o)}}function j_(n,t){if(n.readonly||!t.target||!(t.target instanceof Node))return;const e=et(t.target);if(!e||!Me(e)||fn(e)!=="math")return;const o=Lt(e),r=o.querySelector("img")||o.querySelector("span.mathjax-tex-text");if(!r||!Xt(r,t.target))return;const s=n.getBlockData(e).embedData;_9(n,r,s.mathjaxText,async l=>{const a=await E0(n,l),d={mathjaxText:l,src:a};n.updateEmbedData(e,d)})}function U_(n,t,e){const o=e.embedData,r=n.addCustom(`mathjax-block-${e.id}`,()=>new B0);if(n.domEvents.addEventListener(t,"click",j_),o.src||r.dataUrl){const i=w("img",["mathjax"],t);i.src=n.doc.buildResourceUrl(o.src||r.dataUrl);return}r.error,w("span",["mathjax-tex-text"],t,o.mathjaxText),H_(n,e,r)}function z_(n,t,e){if(!tt(n,t))return null;const o=n.getBlockString(t).trim();if(!o||!o.startsWith("$$")||!o.endsWith("$$"))return null;const r=wm(o,"$");if(!r)return null;const i={mathjaxText:r,src:""};return{blockData:{id:K(),type:"embed",embedType:"math",embedData:i}}}function V_(n){return{name:"Mathjax"}}function W_(n,t){const e=Lt(t);n.domEvents.removeAllListeners(e)}function q_(n,t,e,o){const r=t.embedData;return o==="html"?`<img src="${n.doc.buildResourceUrl(r.src,{withToken:!0})}" />`:o==="markdown"?`
|
|
397
|
+
`)),d}if(o==="html"){let d=((a=Tn.convertTo)==null?void 0:a.call(Tn,n,t,e,"html",r))||"";d=d.replace("<p>","").replace("</p>",""),i.checkbox==="checked"?d=`<input type="checkbox" checked="checked" disabled="disabled" /> ${d}`:i.checkbox==="unchecked"&&(d=`<input type="checkbox" disabled="disabled" /> ${d}`);let h="ul";return i.ordered?(d=`<li value="${i.start}">${d}</li>`,h="ol"):d=`<li>${d}</li>`,C9(n,t,e,r)&&(d=`<${h}>${d}`),A9(n,t,e,r)&&(d=`${d}</${h}>`),d}return""}function b9(n){const t=w("label",["editor-check-list-wrapper"],null);n&&W(t,"editor-check-list-wrapper-checked");const e=w("span",["editor-check-box"],t);return w("span",["editor-check-box-inner"],e),t}function UO(n,t){const e=fc(t);if(e!=="text-only"){if(e==="checked"){n.append(b9(!0));return}if(e==="unchecked"){n.append(b9(!1));return}n.innerText=HO(t)}}function zO(n){const t=w("div",["list-container"],null),e=w("button",["list-marker"],t);return UO(e,n),t}function v9(n){let t=Zt(n);if(!t)return null;const e=Gs(n);for(;t!==e;){if(g(ke,t,"no next block"),Ht(t))return An(t)>An(n)?t:null;if(t=Zt(t),!t)return null}return null}function C0(n){const t=[];let e=v9(n);if(!e)return t;for(;e;){const o=Gs(e);t.push({block:e,children:C0(e)}),e=o}return t}function VO(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 y9(n,t){return An(t)!==1}function k9(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&&k9(n,o.children,r.groupId)})}function A0(n,t){if(!y9(n,t))return!1;const e=An(t);if(e===1)return!1;let o=K(),r=1,i=Zn(t);const s=e-1,l=c0(t);l&&(o=ac(l),r=mo(l)+1,i!=="text-only"&&(i=Zn(l)));const a=C0(t),d=n.getBlockData(t),h={...d,groupId:o,level:s,start:r,...l0(i)};n.updateBlockData(t,h),n.doc.beginBatchUpdate(),k9(n,a,d.groupId),n.doc.endBatchUpdate(),new Zs(n,t).fix();const A=v9(t);return A&&new Zs(n,A,{resetStart:!0,resetGroupId:!0}).fix(),!0}function mc(n,t){Fe(t);const e=n.getBlockData(t),o={id:K(),type:"text",text:e.text};e.heading&&(o.heading=e.heading),e.heading&&(o.heading=e.heading);const r=new hf(n,t),i=nt(t),s=bt(t);if(n.deleteBlock(t),Ba(n,i)&&!Yt(i)){const l=xe(i),a=Ce(n,l.id,0);n.updateBlockData(l,o,a)}else{const l=ph(o.id,0);n.insertBlock(at(i),s,o,l)}r.fix()}function WO(n){if(!n.selection.range.isCollapsed())return!1;const t=n.selection.focusedBlock;if(!Ht(t))return!1;const e=n.selection.range.focus;return!e.isSimple()||e.offset!==0?!1:An(t)===1?(mc(n,t),!0):(A0(n,t),!0)}const qO=S("list-block");function GO(n,t,e){g(qO,Ht(t),"not a list block");const o={...n.getBlockData(t),id:K()};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==null?void 0:o.checkbox)==="checked"&&(o.checkbox="unchecked"),o}function ZO(n){if(Fe(n),!af(n))return n;let t=Zi(n);for(;t;){if(!af(t))return t;t=Zi(t)}return null}function QO(n,t,e,o){const r=new Zs(n,o),i=mo(o)+1;Ql(n,t,e,{forceInsertAfter:!0,newBlockData:GO(n,o,{start:i})}),r.fix()}function YO(n){var s;if(n.selection.range.isCollapsed()){const l=n.selection.focusedBlock;if(Ht(l)&&ut(n,l)===0)return mc(n,l),!0}n.clearSelectedContents();const t=n.selection.focusedBlock;if(!Ht(t))return!1;const e=n.selection.range.focus;if(!e.isSimple())return!1;const o=e.offset,i=(s=o===ut(n,t)?ZO(t):t)!=null?s:t;return QO(n,t,o,i),!0}function w9(n){g(ke,Ht(n),"not a list block");const{level:t}=Gi(n);let e=ce(n);for(;e;){if(Ht(e)){const{level:o}=Gi(e);if(t===o)return e;if(o<t)return null}e=ce(e)}return null}function B9(n,t){return Fe(t),w9(t)?An(t)<KR:!1}function JO(n,t,e){let o=ce(t);g(ke,o,"no prev brother");const r=An(e);for(;o;){if(o===e)return null;if(Ht(o)&&An(o)===r+1)return o;o=ce(o)}return null}function E9(n,t){if(!B9(n,t))return!1;Fe(t);const e=w9(t);g(ke,e,"no list prev brother");const o=e,r=JO(n,t,o),i=An(o)+1;let s=K(),l=1,a=Zn(t);r&&(s=ac(r),l=mo(r)+1,a=Zn(r));const d=C0(t),p={...n.getBlockData(t),groupId:s,level:i,start:l,...l0(a)};return n.updateBlockData(t,p),n.doc.beginBatchUpdate(),VO(d).forEach(v=>{const B=n.getBlockData(v);n.updateBlockData(v,{...B,level:B.level+1})}),n.doc.endBatchUpdate(),!0}function KO(n,t,e){return t.length===0||!t.every(o=>Ht(o.block))?!1:e==="increase"?B9(n,t[0].block):y9(n,t[0].block)}function x9(n,t,e){if(!KO(n,t,e))return!1;const o=t[0].block,r=An(o),i=t.filter(d=>An(d.block)<=r),s=a9(o,{withSelf:!1}),l=new Set(i.map(d=>d.block)),a=s.filter(d=>!l.has(d));return n.undoManager.runInGroup(()=>{let d=null;a.length>0&&(d=new Zs(n,a[0])),i.forEach(h=>{e==="increase"?E9(n,h.block):A0(n,h.block)}),d==null||d.fix()}),!0}function XO(n,t){return E9(n,t)}function t_(n,t){return A0(n,t)}function e_(n){const t=n.selection.range.getSelectedBlocks();if(t.length>1)return x9(n,t,"increase"),!0;const e=t[0].block;if(!Ht(e))return!1;const o=new hf(n,e);return XO(n,e)&&(o.fix(),new Zs(n,e).fix()),!0}function n_(n){const t=n.selection.range.getSelectedBlocks();if(t.length>1)return x9(n,t,"decrease"),!0;const e=t[0].block;return Ht(e)?(t_(n,e),!0):!1}class o_{constructor(t){this.editor=t}handleBeforeKeyDown(t,e){const o=t.selection.range.getSelectedBlocks();if(o.length===0||!o.some(i=>Ht(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||!Ht(e.block)||or(t,"Shift+Enter")?!1:this.editor.undoManager.runInGroup(()=>YO(this.editor))}handleBackspace(){return this.editor.undoManager.runInGroup(()=>WO(this.editor))}handleTab(t){return or(t,"Shift+Tab")?this.editor.undoManager.runInGroup(()=>n_(this.editor)):this.editor.undoManager.runInGroup(()=>e_(this.editor))}}class r_{constructor(t){m(this,"effectedBlockIds",new Map);m(this,"handleBeforeClearSelection",()=>{this.effectedBlockIds.clear();const t=this.editor.selection.range.getSelectedBlocks();if(t.length===0)return;const e=new Set;t.forEach(r=>{const i=r.block;Ht(i)&&e.add(i)});const o=new Map;Array.from(e.values()).forEach(r=>{var a;const i=Cu(r),{start:s}=Gi(i);o.set(it(i),s);const l=(a=rO(r))!=null?a:r;o.set(it(l),s)}),this.effectedBlockIds=o});m(this,"handleAfterClearSelection",()=>{Array.from(this.effectedBlockIds.entries()).forEach(([t,e])=>{const o=this.editor.findBlockById(t);!o||f0(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 i_=S("customize-list-start-menu");class s_{constructor(t){m(this,"popup");m(this,"block",null);m(this,"show",(t,e)=>{const o=e.querySelector("div.list-container");g(i_,o,"list-block mark does not exist"),this.block=e,this.popup.manualShow(o,{theme:"light"})});m(this,"createDialogContent",()=>{const t=w("div",["customize-start-panel"],null);w("span",["customize-start-panel-title"],t,R.t("list.numberLabel"));const e=this.createNumericInput();t.appendChild(e);const o=w("button",["customize-start-panel-button"],t,R.t("list.confirm"));return this.editor.domEvents.addEventListener(t,"keydown",this.handleKeydown),this.editor.domEvents.addEventListener(o,"click",this.handleOk),t});m(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=mo(t);!o||!r||requestAnimationFrame(()=>{r.focus(),r.value=String(i)})});m(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(()=>{hc(this.editor,[o,...uc(o)],r,{resetGroupId:!0})}),this.popup.close("clickItem"))});m(this,"handleKeydown",(t,e)=>{const o=e;o.isComposing||(o.key==="Escape"?this.popup.close("cancelBar"):o.key==="Enter"&&this.handleOk())});this.editor=t,this.popup=new tu(this.createDialogContent()),this.popup.on("show",this.handleDialogShow)}destroy(){this.popup.destroy()}createNumericInput(){const t=w("input",["customize-start-panel-input"],null);t.type="number",t.min="1";const e=()=>{const r=t.value.replace(/[^\d]/g,"").replace(/^0+/,""),i=parseInt(r,10);i<=0||Number.isNaN(i)?t.value="":t.value=r};return this.editor.domEvents.addEventListener(t,"input",e),t}}function l_(n,t){return ac(n)===ac(t)}function c_(n,t){const e=l9(t);return e?l_(e,t)?mo(e)!==mo(t)-1:!0:!1}function a_(n,t){return Zi(t)?!0:mo(t)!==1}function u_(n,t){return Fe(t),[{id:"continue-numbering",name:R.t("list.continueList"),states:c_(n,t)?[]:["disabled"]},{id:"start-new-list",name:R.t("list.restartList"),states:a_(n,t)?[]:["disabled"]},{id:"set-numbering-value",name:R.t("list.changeNumber")}]}function d_(n,t,e){var o,r;if(Fe(t),e.id==="continue-numbering"){const i=l9(t);i&&hc(n,[t,...uc(t)],mo(i)+1,{resetGroupId:!0,groupId:ac(i)})}if(e.id==="start-new-list"&&n.undoManager.runInGroup(()=>{hc(n,[t,...uc(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 s_(n)).show(n,t)}}class h_{constructor(t){m(this,"menu");m(this,"handleClick",(t,e)=>{const o=Hl(e,"div.list-container");if(o&&this.editor.isWritable()){const r=et(o);g(ke,r,"no parent block"),Fe(r);const i=t.getBlockData(r);if(i&&i.checkbox){t.updateBlockData(r,{...i,checkbox:i.checkbox==="checked"?"unchecked":"checked"});return}if(Zn(r)==="unordered")return;this.menu.updateItems(this.getCommandItems(r)),this.menu.manualShow(o),this.activeList(o,!0)}});m(this,"handleMenuClose",()=>{var e;const t=(e=this.menu.tippyInstance)==null?void 0:e.reference;t&&this.activeList(t,!1)});m(this,"handleMenuClick",(t,e)=>{var r;const o=(r=this.menu.tippyInstance)==null?void 0:r.reference;if(o){const i=et(o);i&&d_(this.editor,i,e)}});this.editor=t,this.editor.addListener("click",this.handleClick),this.menu=new zs([]),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 u_(this.editor,t)}activeList(t,e){const o=et(t);!o||(e?(W(t,"active"),W(o,"active")):(ot(t,"active"),ot(o,"active")))}}class f_{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(!Ht(r)||!f9(r))return!1;if(e.key==="ArrowUp"||e.key==="ArrowLeft"){const i=Ts(r);return i&&t.selection.selectBlock(i,ut(t,i)),!0}if(e.key==="ArrowDown"||e.key==="ArrowRight"){const i=Ds(r);return i&&t.selection.selectBlock(i,0),!0}return(e.key==="Delete"||e.key==="Backspace"||e.key==="Escape")&&g9(t,r),!0}}function m_(n,t,e,o,r){tp(n,"list-block-init",()=>{setTimeout(()=>{n.input.addHandler(new f_(n)),n.input.addHandler(new o_(n)),n.addCustom("list-clear-selection-handler",()=>new r_(n)),n.addCustom("list-marker-menu",()=>new h_(n))})});const i=Tn.createBlockContent(n,t,e,o,r),s=r,{level:l,start:a,groupId:d}=s,h=fc(s);o.setAttribute("data-list-level",`${l}`),o.setAttribute("data-list-start",`${a||1}`),o.setAttribute("data-list-group-id",`${d}`),o.setAttribute("data-list-type",h);const p=zO(s);return o.insertBefore(p,i),s.viewAsMindmap?setTimeout(()=>{const A=n.getBlockById(r.id);A&&uf(n,A,{},{mindmapTools:h0,saveData:!1})}):setTimeout(()=>{const A=n.getBlockById(r.id);A&&m9(n,A)}),i}const g_={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"}},p_={list:{confirm:"Confirm",setStart:"Set number",continueList:"Continue numbering",restartList:"Start a new list",changeNumber:"Set numbering value",numberLabel:"Numbering order",mention:{tooltip:"Mention and notify users"}},mindmap:{viewAsMindMap:"View as MindMap",autoFit:"Auto zoom",fullScreen:"Full screen",close:"Close",exitFullscreen:"Exit full screen"}},C_={list:{confirm:"OK",setStart:"\u756A\u53F7\u3092\u8A2D\u5B9A",continueList:"\u9023\u756A\u3092\u8A2D\u5B9A",restartList:"\u65B0\u3057\u3044\u30EA\u30B9\u30C8\u3092\u4F5C\u6210",changeNumber:"\u756A\u53F7\u3092\u7DE8\u96C6",numberLabel:"\u756A\u53F7",mention:{tooltip:"\u30E1\u30F3\u30B7\u30E7\u30F3\u304A\u3088\u3073\u901A\u77E5"}},mindmap:{viewAsMindMap:"\u30DE\u30A4\u30F3\u30C9\u30DE\u30C3\u30D7\u3067\u8868\u793A",autoFit:"\u81EA\u52D5\u30D5\u30A3\u30C3\u30C8",fullScreen:"\u5168\u753B\u9762\u8868\u793A\u306E\u30AA\u30F3",close:"\u9589\u3058\u308B",exitFullscreen:"\u5168\u753B\u9762\u8868\u793A\u306E\u30AA\u30D5"}};R.mergeLang({"zh-CN":g_,"en-US":p_,"ja-JP":C_});const xnt="",I9={...Tn,blockType:"list",createBlockContent:m_,convertFrom:$O,convertTo:jO,handleDrop:DO,notify:EO},b0=S("paragraph");class A_{constructor(t){m(this,"id","BlockParagraphProvider");this.editor=t}isChecked(t,e){return!!(t[e]||t.level&&(t.ordered===!0&&!t.checkbox&&e==="ordered-list"||t.ordered===!1&&!t.checkbox&&e==="unordered-list")||e==="check-list"&&t.checkbox)}getAvailableCommands(t,e){const o=[],r={"unordered-list":[R.t("commands.unordered"),xo("CtrlOrCmd+Shift+L"),xL],"ordered-list":[R.t("commands.ordered"),xo("CtrlOrCmd+Shift+U"),EL],"check-list":[R.t("commands.check"),void 0,IL],link:[R.t("commands.link"),xo("CtrlOrCmd+K"),hv],quoted:[R.t("commands.quote"),void 0,TL]};if(tt(t,e)){const i=it(e),s=Dt(e),l=Do(t,e),a=t.getBlockData(e);Object.entries(r).forEach(([d,[h,p,A]])=>{const v=[];if(this.isChecked(a,d)&&v.push("checked"),d==="link"){if(!t.selection.range.isSimple())return;t.selection.range.getSelectedBlocks().length!==1&&v.push("disabled")}o.push({blockId:i,blockType:s,blockKind:l,id:d,name:h,desc:p,states:v,icon:A,groupIndex:600})})}return o}convertLink(t,e,o){g(b0,Ur(e.start),""),g(b0,Ur(e.start),"");const r="bottom-start",i=e.start.offset,s=e.end.offset,l=(v,B)=>{t.undoManager.runInGroup(()=>{try{const D=t.selection.range.isCollapsed();let x;if(D){x=Vr(t.getBlockText(o),s,v,{link:B}),t.setBlockText(o,x);return}x=fh(t.getBlockText(o),i,s,v),x=Ta(i,v.length,x,"link",B),t.setBlockText(o,x),t.selection.selectBlock(o,i+v.length),t.focus()}catch(D){b0.error(D)}})},a=()=>{t.selection.selectBlock(o,s),t.focus()},d=Nr(t,o,e)[0];if(!d)return;const h=zr(t,o,"link-button-anchor",d),p=t.getBlockText(o),A=Da(p,i);gu(t,{target:h,linkText:t.getSelectedText(),linkUrl:(A==null?void 0:A.link)||"",onFinished:l,onClose:a,placement:r})}convertToList(t,e,o){const r=th(t,e,"list",{offset:0,data:{listType:o}});r&&t.undoManager.runInGroup(()=>{const i=bt(e),s=nt(e);t.insertBlock(at(s),i,r.blockData),t.deleteBlock(e),t.focus()})}executeCommand(t,e,o,r){var a;if(!tt(t,e))return!1;const i=r.id,s=(a=r.states)==null?void 0:a.includes("checked");let l=!1;if(i==="unordered-list"&&(s?mc(t,e):this.convertToList(t,e,"unordered"),l=!0),i==="ordered-list"&&(s?mc(t,e):this.convertToList(t,e,"ordered"),l=!0),i==="check-list"&&(s?mc(t,e):this.convertToList(t,e,"unchecked"),l=!0),i==="quoted"){const h=t.getBlockData(e).quoted;t.updateBlockData(e,{quoted:h?void 0:!0}),t.focus(),l=!0}if(i==="link"){const d=sf(t);d.disableTextToolbar(),d.hide(),setTimeout(()=>{d.enableTextToolbar()},1e3),this.convertLink(t,o,e),l=!0}return l}}const b_={left:eu,right:Ip,center:Tp};class v_{constructor(t){m(this,"id","BlockAlignProvider");this.editor=t}applyAlignStyle(t,e,o){Object.keys(b_).includes(o)?t.updateBlockData(e,{align:o}):t.updateBlockData(e,{align:null})}isChecked(t,e){return t.align===e}getAvailableCommands(t,e,o){if(tt(t,e)){const r=it(e),i=Dt(e),s=Do(t,e),l=t.getBlockData(e),a=d=>{var p;const h=w("span",["toolbar-item-name-container"],null);for(const A of d.children)if((p=A.states)!=null&&p.includes("checked"))return h.innerHTML=A.icon||eu,h;return h.innerHTML=eu,h};return[{id:"align",name:R.t("commands.alignGroup"),blockId:r,blockType:i,blockKind:s,groupIndex:700,dropdown:!0,element:a,manualShowChildren:!0,childrenPlacement:"bottom-start",defaultCheckedChildren:["align-left"],children:[{id:"align-left",name:R.t("commands.alignLeft"),icon:eu,states:this.isChecked(l,"left")?["checked"]:[]},{id:"align-center",name:R.t("commands.alignCenter"),icon:Tp,states:this.isChecked(l,"center")?["checked"]:[]},{id:"align-right",name:R.t("commands.alignRight"),icon:Ip,states:this.isChecked(l,"right")?["checked"]:[]}],childrenType:"menu"}]}return[]}executeCommand(t,e,o,r){if(!tt(t,e))return!1;if(r.id.startsWith("align")){const i=r.id.replace(/^align-/,"");return this.applyAlignStyle(t,e,i),this.editor.focus(),!0}return!1}}function y_(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 La(n,o,e.start.offset).charType==="box"}const k_=S("toolbar-handler"),w_={id:"",name:"",type:"separator"};class gc{constructor(t){m(this,"toolbar");m(this,"toolbarType","object");m(this,"mouseDown",!1);m(this,"oldRange",null);m(this,"hoveringBlock",null);m(this,"hoveringTextChild",null);m(this,"_disableTextToolbar",!1);m(this,"handleButtonClick",(t,e)=>{this.toolbarType==="text"?(this.editor.editorCommandProviders.executeCommand(this.editor.selection.range,e,{}),this.showTextToolbar("click")):this.hoveringBlock&&ZR(this.editor,this.hoveringBlock,this.hoveringTextChild,e)});m(this,"handleClose",()=>{Op(this.editor)&&this.editor.focus()});m(this,"handleClosing",(t,e)=>{if(this.toolbarType==="object"){const o=rC(e);if(this.hoveringBlock===o)return!1}return!0});m(this,"handleDocumentMouseDown",t=>{t.button===0&&(document.addEventListener("mouseup",this.handleDocumentMouseUp),this.mouseDown=!0)});m(this,"handleDocumentMouseUp",()=>{document.removeEventListener("mouseup",this.handleDocumentMouseUp),this.mouseDown=!1,this.handleSelectionChange(this.editor)});m(this,"handleHoveringBlockChildChange",(t,e,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("fromHover");return}this.showObjectToolbar(r)}});m(this,"handleSelectionChange",Le.default(t=>{var o;if(g(k_,t===this.editor,"editor mismatch"),t.selection.range.isCollapsed()||this.mouseDown){if(this.toolbarType==="object"){const r=(o=this.toolbar.tippyInstance)==null?void 0:o.reference,i=this.editor.selection.focusedBlock;if(r&&Xt(r,i))return}this.toolbar.close("selectionChange"),this.oldRange=null;return}if(!this.editor.isWritable()){this.toolbar.close("selectionChange"),this.oldRange=null;return}if(t.selection.range.getSelectedBlocks().length===0){this.toolbar.close("selectionChange"),this.oldRange=null;return}this.oldRange&&this.oldRange.isEqual(t.selection.range)||(this.oldRange=t.selection.range,this.showTextToolbar("selectionChange"))},50));this.editor=t;const e=t.options.componentsOptions.popover;this.toolbar=new ru([],void 0,{tooltipId:t.clientId,id:"editor-toolbar",overflowBoundary:e==null?void 0:e.overflowBoundary,refuseOverflow:!0,padding:20}),this.toolbar.on("click",this.handleButtonClick),this.toolbar.on("close",this.handleClose),this.toolbar.on("closing",this.handleClosing),this.bindEvents(),t.addListener("selectionChanged",this.handleSelectionChange),Ae.get(t).addListener("childChange",this.handleHoveringBlockChildChange),Ae.get(t).addFilter(this),t.editorCommandProviders.registerCommandProvider(new YR(t)),t.editorCommandProviders.registerCommandProvider(new A_(t)),t.editorCommandProviders.registerCommandProvider(new v_(t))}disableTextToolbar(){this._disableTextToolbar=!0}enableTextToolbar(){this._disableTextToolbar=!1}hide(){this.toolbar.close("selectionChange")}destroy(){this.unbindEvents(),this.toolbar.destroy(),this.editor.removeListener("selectionChanged",this.handleSelectionChange),Ae.get(this.editor).removeListener("childChange",this.handleHoveringBlockChildChange)}isInBlock(t,e){return t!==this.hoveringBlock?!1:!!(e.target&&e.target instanceof Node&&this.toolbar.popper&&Xt(this.toolbar.popper,e.target))}bindEvents(){document.addEventListener("mousedown",this.handleDocumentMouseDown)}unbindEvents(){document.removeEventListener("mousedown",this.handleDocumentMouseDown)}update(t){this.showTextToolbar(t)}showTextToolbar(t){var D,x;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&&Me(r.block)){t==="click"&&this.showObjectToolbar(null);return}if(y_(this.editor))return;if(nt(r.block)===this.editor.rootContainer&&bt(r.block)===0){this.toolbar.close("selectionChange");return}const i=this.editor.editorCommandProviders.getCommands(this.editor.selection.range),s=new Map;i.forEach(_=>{const M=_.groupIndex,H=s.get(M);H?H.push(_):s.set(M,[_])});const l=[[]],a=Array.from(s.entries()).sort((_,M)=>_[0]-M[0]);for(let _=0;_<a.length;_++){const[,M]=a[_];if(M.length===0)continue;let H=l[l.length-1];H.length>0&&H[H.length-1].groupIndex!==M[M.length-1].groupIndex&&(H=[],l.push(H)),H.push(...rf(M))}if(l.length===0){this.toolbar.close("selectionChange");return}this.toolbarType="text";const d=[];if(l.forEach((_,M)=>{const H=_.sort((z,q)=>{var rt,ft;return((rt=z.order)!=null?rt:0)-((ft=q.order)!=null?ft:0)});d.push(...H),M!==l.length-1&&d.push(w_)}),d.length===0){this.toolbar.close("selectionChange");return}this.toolbar.updateItems(d);const h=o[o.length-1],p=!this.editor.selection.range.isReverse()&&h!==r,A=p?h:r,v=HR(this.editor,A),B=zr(this.editor,A.block,"editor-quick-menu",v);this.toolbar.manualShow(B,{placement:p?"bottom":"top",offset:[0,p?5:10]}),(x=(D=this.toolbar.tippyInstance)==null?void 0:D.popperInstance)==null||x.update()}showObjectToolbar(t){var l,a,d;if(!this.hoveringBlock||this.mouseDown)return;const e=this.hoveringBlock,o=this.hoveringTextChild,{commands:r,element:i}=WR(this.editor,e,o);if(!r.length||!i){this.toolbar.close("fromHover");return}this.toolbarType="object",this.toolbar.isVisible&&((a=(l=this.toolbar)==null?void 0:l.tippyInstance)==null?void 0:a.reference)!==i&&this.toolbar.close("fromHover");const s=()=>{let h;const p=i.getClientRects();if(p.length>1){if(h=o?p[p.length-1]:p[0],t)for(let A=0;A<p.length;A++){const v=p[A],B=new DOMRect(v.x-4,v.y-4,v.width+8,v.height+8);if(B.x<t.clientX&&t.clientX<B.right&&B.y<t.clientY&&t.clientY<B.bottom){h=v;break}}}else{if(h=i.getBoundingClientRect(),o){const A=o.getBoundingClientRect();return new DOMRect(A.x,A.y,A.width,A.height)}return new DOMRect(p[0].x,p[0].y,p[0].width,p[0].height)}if(t){const A=h.y,v=t.clientX;return new DOMRect(v,A,10,h.height)}return h};this.toolbar.updateItems(r),this.toolbar.isVisible||(this.toolbar.manualShow(i,{placement:o?"bottom":"top",getReferenceClientRect:s}),(d=this.toolbar.tippyInstance)!=null&&d.popper&&(this.toolbar.tippyInstance.popper.style.paddingTop="10px",this.toolbar.tippyInstance.popper.style.paddingBottom="5px"))}static register(t){return t.addCustom("toolbar-handler",e=>new gc(e))}static get(t){return t.getCustom("toolbar-handler")}}function gf(n,t,e){n.getBlockData(t).heading===e?n.updateBlockData(t,{heading:null}):n.updateBlockData(t,{heading:e})}function T9(n,t,e){["left","center","right"].includes(e)?n.updateBlockData(t,{align:e}):n.updateBlockData(t,{align:null})}function v0(n,t){const o=n.getBlockData(t).quoted;n.updateBlockData(t,{quoted:o?void 0:!0})}function y0(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 k0(n,t,e){if(!n.selection.range.focus.isSimple())return;const r=n.getBlockData(t);let i;switch(e){case"unordered-list":i=y0(r,"unordered-list")?void 0:"unordered";break;case"ordered-list":i=y0(r,"ordered-list")?void 0:"ordered";break;case"check-list":i=y0(r,"check-list")?void 0:"unchecked";break}if(i){const s=th(n,t,"list",{offset:0,data:{listType:i}});s&&n.undoManager.runInGroup(()=>{const l=bt(t),a=nt(t);n.deleteBlock(t),n.insertBlock(at(a),l,s.blockData)})}else mc(n,t)}const B_=Object.freeze(Object.defineProperty({__proto__:null,applyHeadingStyle:gf,applyAlignStyle:T9,applyQuoteStyle:v0,applyList:k0},Symbol.toStringTag,{value:"Module"})),E_=[bp,vp,yp,kp,wp,Bp,Ep,xp],x_={Unordered:gv,Ordered:pv,Checkbox:fv,Quote:mv};function D9(n,t){const e=n;e.blockOptions=t,e.itemType="insert-block",n.children&&n.children.forEach(o=>D9(o,t))}function I_(){return{name:"basic",insertBlockCommandItems:[{id:"text",icon:ou,name:R.t("commands.text"),order:0,group:"basics",value:"text"}]}}function w0(n=1){var r;const t={name:"basic",insertBlockCommandItems:[]};let e=lf();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:E_[o-1],name:R.t("quickMenu.basic.heading.title",{heading:String(o)}),order:o,group:"basics",value:String(o),subText:Cn(i)}),o++}return t}function T_(){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:R.t(`quickMenu.basic.${e.toLocaleLowerCase()}`),icon:x_[e],value:e.toLocaleLowerCase(),group:"basics",order:10+o,subText:Cn(r)})}),n}class S9{constructor(t){this.withPlainText=t}getCommands(){const t=I_(),e=w0(),o=T_();return[...this.withPlainText?t.insertBlockCommandItems||[]:[],...e.insertBlockCommandItems||[],...o.insertBlockCommandItems||[]]}updateBlock(t,e,o,r){const{value:i,id:s}=r;return s.startsWith("heading-")?gf(t,o,Number.parseInt(i!=null?i:"1",10)||1):i==="ordered"||i==="unordered"||i==="checkbox"?k0(t,o,{ordered:"ordered-list",unordered:"unordered-list",checkbox:"check-list"}[i]):i==="quote"&&v0(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=at(i),l=t.getBlockIndex(r);t.undoManager.runInGroup(()=>this.handleUpdateBlockCore(t,{item:e,containerId:s,blockIndex:l})),t.focus()}else o.from==="block-menu"&&(t.undoManager.runInGroup(()=>this.handleInsertEmptyBlockCore(t,{item:e,containerId:o.containerId,blockIndex:o.blockIndex})),t.focus());return null}}const L9={basics:100,system:200,common:300,thirdParty:400};class B0{constructor(){m(this,"dataUrl","");m(this,"error",null)}destroy(){}setDataUrl(t){this.error=null,this.dataUrl=t}setError(t){this.dataUrl="",this.error=t}}const D_=S("mathjax-converter"),S_="MathJax-script";async function L_(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 vs(e,S_)}function M_(){try{window.MathJax&&window.MathJax.texReset()}catch{}}async function M9(n,t){const e="mathjax2Svg";try{await Eo.lock(e),M_(),await L_(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 D_.error(o),o}finally{Eo.release(e)}}async function R9(n,t){const e=await M9(n,t);return e?await Tm(e,"image/svg+xml"):""}async function E0(n,t){const o=await M9(n,t),r=new File([o],"math.svg");return(await n.doc.uploadResource(r)).resourceId}const O9=S("edit-mathjax");class R_{constructor(){m(this,"editMathjaxPopup",null);m(this,"onChange",null);m(this,"tex","");m(this,"handleShow",()=>{setTimeout(()=>{this.getTextarea().focus()})});m(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))}});m(this,"handleKeyup",t=>{var e;t.isComposing||(t.key==="Escape"&&((e=this.editMathjaxPopup)==null||e.close("cancelBar")),this.handleChange(t.target.value))});m(this,"handleChange",Le.default(t=>{var e;(e=this.onChange)==null||e.call(this,t,!1)},300))}editMathjax(t,e,o){if(!this.editMathjaxPopup)this.editMathjaxPopup=new tu(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=w("textarea",["mathjax-editor-textarea"],null);return e.value=t,e.addEventListener("keyup",this.handleKeyup),e}getTextarea(){g(O9,this.editMathjaxPopup,"no exists mathjax editor popup");const t=this.editMathjaxPopup.content.querySelector("textarea");return g(O9,t,"no textarea"),t}destroy(){var t;this.onChange=null,(t=this.editMathjaxPopup)==null||t.removeAllListeners()}}function _9(n,t,e,o){n.addCustom("mathjax-editor",()=>new R_).editMathjax(t,e.trim(),o)}function F9(){return{insert:" ",attributes:{id:K(),box:!0,type:"math",tex:" ",src:"",created:Date.now()}}}function pf(n,t){const e=n.getBoxData(t),o=et(t);if(!o)return;const r=_s(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 Eo.lock("convertAndUploadMathjax");const a=await E0(n,s);n.updateBoxData({...e,tex:s,src:a})}catch(a){const d=n.getBoxData(t);n.addCustom(`mathjax-box-${d.id}`,()=>new B0).setError(a),n.updateBoxData({...e,tex:s,src:""})}finally{Eo.release("convertAndUploadMathjax"),l&&n.focus()}};_9(n,t,e.tex,i)}const P9=S("mathjax-box");function x0(n,t){n.selection.updateSelection(null);const e=t.target;!e||!(e instanceof HTMLElement)||n.domEvents.removeEventListener(e,null,x0)}async function O_(n,t,e){try{if(!t.tex.trim())return;const o=await R9(n,t.tex),r=n.findBoxById(t.id);if(!r)return;const i=Nm(r);i.innerHTML="";const s=w("img",["mathjax"],i);s.src=o,e.setDataUrl(o),n.domEvents.addEventListener(s,"load",x0)}catch(o){e.setError(o);const r=n.findBoxById(t.id);if(!r)return;const i=r.querySelector(".mathjax-tex-text");W(i,"mathjax-error"),i.innerText=o.message,n.selection.updateSelection(null)}}function __(n,t,e,o){const r=o,i=n.addCustom(`mathjax-box-${r.id}`,()=>new B0);if(r.src||i.dataUrl){const a=w("img",["mathjax"],e);a.src=n.doc.buildResourceUrl(r.src||i.dataUrl),n.domEvents.addEventListener(a,"load",x0);return}const s=["mathjax-tex-text"];let l=r.tex;l.trim()?i.error&&(l=i.error.message,s.push("mathjax-error")):l=R.t("mathjax.emptyText"),w("span",s,e,l),O_(n,r,i)}function F_(n,t){const e={id:K(),box:!0,type:"math",tex:t,src:"",created:Date.now()};return E0(n,t).then(o=>{if(!n.findBoxById(e.id))return;const i={...e,src:o};n.updateBoxData(i)}).catch(o=>{P9.error(`failed to convert and upload mathjax: ${JSON.stringify(o)}`)}),e}function P_(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 N_(n,t,e){const o=et(t);g(P9,o,"failed to get block"),!(n.readonly||!n.isBlockWritable(o))&&pf(n,t)}function $_(){return{abstract:R.t("mathjax.abstract")}}const I0={boxType:"math",updateBoxContent:__,convertFrom:F_,convertTo:P_,handleClickBox:N_,getBoxProperties:$_};async function H_(n,t,e){try{const o=t.embedData,r=await R9(n,o.mathjaxText),i=n.findBlockById(t.id);if(!i)return;const s=Lt(i);s.innerHTML="";const l=w("img",["mathjax"],s);l.src=r,e.setDataUrl(r)}catch(o){e.setError(o)}}function j_(n,t){if(n.readonly||!t.target||!(t.target instanceof Node))return;const e=et(t.target);if(!e||!Me(e)||fn(e)!=="math")return;const o=Lt(e),r=o.querySelector("img")||o.querySelector("span.mathjax-tex-text");if(!r||!Xt(r,t.target))return;const s=n.getBlockData(e).embedData;_9(n,r,s.mathjaxText,async l=>{const a=await E0(n,l),d={mathjaxText:l,src:a};n.updateEmbedData(e,d)})}function U_(n,t,e){const o=e.embedData,r=n.addCustom(`mathjax-block-${e.id}`,()=>new B0);if(n.domEvents.addEventListener(t,"click",j_),o.src||r.dataUrl){const i=w("img",["mathjax"],t);i.src=n.doc.buildResourceUrl(o.src||r.dataUrl);return}r.error,w("span",["mathjax-tex-text"],t,o.mathjaxText),H_(n,e,r)}function z_(n,t,e){if(!tt(n,t))return null;const o=n.getBlockString(t).trim();if(!o||!o.startsWith("$$")||!o.endsWith("$$"))return null;const r=wm(o,"$");if(!r)return null;const i={mathjaxText:r,src:""};return{blockData:{id:K(),type:"embed",embedType:"math",embedData:i}}}function V_(n){return{name:"Mathjax"}}function W_(n,t){const e=Lt(t);n.domEvents.removeAllListeners(e)}function q_(n,t,e,o){const r=t.embedData;return o==="html"?`<img src="${n.doc.buildResourceUrl(r.src,{withToken:!0})}" />`:o==="markdown"?`
|
|
398
398
|
$$${r.mathjaxText}$$
|
|
399
|
-
`:r.mathjaxText}function G_(){return{abstract:R.t("mathjax.abstract")}}const N9={embedType:"math",createEmbedContent:U_,getOptions:V_,convertFrom:z_,handleDeleteBlock:W_,convertTo:q_,getBlockProperties:G_},Int="",Z_={mathjax:{emptyText:"\u7A7A\u7684\u516C\u5F0F",abstract:"\u516C\u5F0F"}},Q_={mathjax:{emptyText:"Empty formula",abstract:"Formula"}},Y_={mathjax:{emptyText:"\u6570\u5F0F\u306A\u3057",abstract:"\u6570\u5F0F"}};R.mergeLang({"zh-CN":Z_,"en-US":Q_,"ja-JP":Y_});function J_(n,t,e,o){const r=n.getBlockByIndex(t,e),i=n.getBlockText(r),{left:s}=In(i,o);if(!ie(s).endsWith("$$$$"))return!1;const a=o-4,d=o,h={id:K(),box:!0,type:"math",tex:" ",src:"",created:Date.now()};return n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,a,d-a),n.insertBoxToBlock(r,a,h),setTimeout(()=>{const p=n.getBoxById(h.id);pf(n,p)})}),!0}class K_{handleAfterInsertText(t,e,o,r,i){return!!(i===" "&&J_(t,e,o,r))}}const pc=S("inline-box-items");function X_(n,t,e){return n.undoManager.runInGroup(()=>{var s;let o=n.getBlockByIndex(t,e);he(n,o)||(o=n.insertTextBlock([],t,e));const r=F9();n.setBlockText(o,[r]);const i=(s=r.attributes)==null?void 0:s.id;return g(pc,i,"mathjax box id is empty"),setTimeout(()=>{const l=n.getBoxById(i);pf(n,l)},100),o})}function tF(n,t,e){let o=n.getBlockByIndex(t,e),r="bottom-start";return he(n,o)||(r="top-start"),gu(n,{target:o,linkText:"",linkUrl:"",onFinished:(l,a)=>{n.undoManager.runInGroup(()=>{try{he(n,o)||(o=n.insertTextBlock([],t,e));const d=co(l,{link:a}),h=co(" ",null),p=[d,h];n.insertTextToBlock(o,0,p),n.selection.selectBlock(o,rn(p)),n.focus()}catch(d){pc.error(d)}})},onClose:()=>{n.focus()},placement:r}),o}function eF(n,t,e){return n.undoManager.runInGroup(()=>{var l;const o=n.getBlockByIndex(t,e),r=n.selection.range;g(pc,Ur(r.start),"invalid block position");const i=F9();n.insertBoxToBlock(o,r.start.offset,i.attributes);const s=(l=i.attributes)==null?void 0:l.id;return g(pc,s,"mathjax box id is empty"),setTimeout(()=>{const a=n.getBoxById(s);pf(n,a)},100),o})}function nF(n,t,e){const o=n.getBlockByIndex(t,e),r=n.selection.range;g(pc,Ur(r.start),"invalid block position");const i=Nr(n,o,r);if(i.length===0)return;const s=i[0],l=zr(n,o,"quick-menu-inline-link",s);gu(n,{target:l,linkText:"",linkUrl:"",onFinished:(h,p)=>{n.undoManager.runInGroup(()=>{try{const A=n.getBlockText(o),v=Vr(A,r.start.offset,h,{link:p});n.setBlockText(o,v),n.selection.selectBlock(o,r.start.offset+h.length),n.focus()}catch(A){pc.error(A)}})},onClose:()=>{n.focus()},placement:"bottom-start"})}class $9{getCommands(){return[{id:"insert-math",name:R.t("quickMenu.inlineBox.math"),icon:OL,order:900,group:"common",subText:Cn("insert-math")},{id:"insert-link",name:R.t("quickMenu.inlineBox.link"),icon:hv,order:400,group:"common",subText:Cn("insert-link")}]}async handleUpdateBlockCore(t,e){switch(e.item.id){case"insert-math":return eF(t,e.containerId,e.blockIndex);case"insert-link":return nF(t,e.containerId,e.blockIndex);default:return null}}async handleInsertEmptyBlockCore(t,e){switch(e.item.id){case"insert-math":return X_(t,e.containerId,e.blockIndex);case"insert-link":return tF(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=at(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 oF(n,t={withPlainText:!1}){var i,s;const{withPlainText:e}=t,o=(s=(i=n.options.componentsOptions)==null?void 0:i.quickMenu)==null?void 0:s.commandProviders;if(!o)return[];const r=[];return[...o,new S9(e),new $9].forEach(l=>{const a=l.getCommands(n);r.push(...a.map(d=>({...d,itemType:"insert-block",commandProvider:l})))}),r}function rF(n,t={withPlainText:!1}){const e=[];return n.editorBlocks.forEach(o=>{if(!o.getOptions)return;const r=o.getOptions(n);!r.insertBlockCommandItems||(r.insertBlockCommandItems.forEach(i=>{D9(i,r)}),e.push(...r.insertBlockCommandItems))}),e.push(...oF(n,t)),e}function T0(n,t={withPlainText:!1}){const e=rF(n,t),o=new Map;e.forEach(s=>{var d;const l=(d=s.group)!=null?d:"";let a=o.get(l);a?a.items.push(s):(a={group:l,order:s.groupOrder||L9[l]||1e3,items:[s]},o.set(l,a))});const r=Array.from(o.values());r.sort((s,l)=>s.order-l.order),r.forEach(s=>{s.items.sort((l,a)=>{var d,h;return((d=l.order)!=null?d:0)-((h=a.order)!=null?h:0)})});const i=[];return r.forEach((s,l)=>{const a=`blockMenu.section.${s.group||"common"}`,d=R.t(a),h=d===a?s.group:d;i.push({id:`section-${l}`,name:h,type:"section",group:s.group,itemType:"insert-block"}),i.push(...s.items.map(p=>({...p})))}),i}function iF(n,t,e){const o=n.getFocusedBlock();if(!o)return;const r=n.getParentContainer(o),i=at(r);let l=n.getBlockIndex(o);if(he(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 H9=S("quick-menu"),sF={id:"quick-menu",trigger:["/"]},lF=5;class Cf{constructor(t,e=sF){m(this,"suggest");m(this,"items");m(this,"maxHeading");m(this,"firstEmptyOffset",-1);m(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,""),i=this.items.filter(s=>{if(s.type==="section")return!0;if(s.name.toLocaleLowerCase().indexOf(r)!==-1||EM(s).toLocaleLowerCase().indexOf(r)!==-1)return o.add(s.group),!0;const l=`blockMenu.section.${s.group||"common"}`,a=R.t(l),d=a===l?s.group:a;return(d==null?void 0:d.toLocaleLowerCase().indexOf(r))!==-1?(o.add(s.group),!0):!1}).filter(s=>s.type==="section"?o.has(s.group):!0);return i.length?this.firstEmptyOffset=-1:this.handleEmptySearch(),i}return this.items});m(this,"onClose",()=>{this.firstEmptyOffset=-1});m(this,"onShow",(t,e,o,r)=>{const i=this.editor.getBlockByIndex(e,o);if(!io(i)){const s=et(nt(i));if(s&&Dt(s)==="code")return!1}return!0});m(this,"onClickItem",(t,e)=>{const o=e;o.itemType==="insert-block"&&(g(H9,o.blockOptions||o.commandProvider,"invalid quick item, no block options or command provider"),g(H9,this.suggest.anchor,"invalid suggest, no anchor"),this.options.id==="empty-block-menu"&&this.editor.focus(),iF(this.editor,o,this.suggest.anchor))});this.editor=t,this.options=e,this.items=[],this.maxHeading=lf(),this.suggest=new Fp(t,{id:e.id||"quick-menu",trigger:e.trigger,needSpaceBeforeTrigger:!0,autoDeleteTrigger:!0,highlight:!0,onClose:this.onClose,onShow:this.onShow,onClickItem:this.onClickItem,queryItems:this.queryItems})}get menu(){return this.suggest.menu.menu}destroy(){this.suggest.destroy()}initMenuItems(){const t=T0(this.editor);this.items=t}refreshMenuItems(){let t=null,e=0;const o=lf();if(o!==this.maxHeading){const r=new S9,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}}handleEmptySearch(){const t=this.editor.selection.getFocusedPos();if(this.firstEmptyOffset===-1){if(t.isSimple()){const{offset:e}=t;this.firstEmptyOffset=e-1}}else if(t.isSimple()){const{offset:e}=t;e-this.firstEmptyOffset>lF&&(this.suggest.close(),this.firstEmptyOffset=-1)}}}class Af{constructor(t){m(this,"instance");m(this,"mousedown",!1);m(this,"currentInstance",null);m(this,"attributeName",[]);m(this,"attributeDesc","");m(this,"observer",null);m(this,"observerCallback",null);m(this,"createContent",t=>{let e="",o=0;for(;o<this.attributeName.length&&!e;)t.hasAttribute(this.attributeName[o])&&(e=t.getAttribute(this.attributeName[o])||""),o++;const r=t.getAttribute(this.attributeDesc);if(!r)return e;const i=w("div",[],null);return w("span",[],i,e),r&&w("span",["editor-tooltip-desc"],i,r),i});m(this,"handleDocumentMouseDown",()=>{this.mousedown=!0,this.editor.domEvents.addEventListener(document,"mouseup",this.handleDocumentMouseUp)});m(this,"handleDocumentMouseUp",()=>{this.mousedown=!1,this.editor.domEvents.removeEventListener(document,"mouseup",this.handleDocumentMouseUp)});m(this,"handleShown",t=>{this.currentInstance&&this.hide(),this.currentInstance=t,this.createObserver()});m(this,"handleHidden",()=>{this.destroyObserver(),this.currentInstance=null});m(this,"handleShow",t=>{var r;const e=t.reference;if(!e||!Xt(document.body,e)||window.isDragging||this.mousedown)return!1;const o=Number.parseInt((r=e.getAttribute("data-tooltip-hide-at"))!=null?r:"",10);if(o&&Date.now()-o<1e3)return!1;if(t.reference){const i={};if(t.reference.hasAttribute("data-editor-tooltip-placement")&&(i.placement=t.reference.getAttribute("data-editor-tooltip-placement")||"top"),t.reference.hasAttribute("data-editor-tooltip-offset-x")||t.reference.hasAttribute("data-editor-tooltip-offset-y")){const s=t.reference.getAttribute("data-editor-tooltip-offset-x"),l=t.reference.getAttribute("data-editor-tooltip-offset-y");i.offset=[s?Number.parseInt(s,10):0,l?Number.parseInt(l,10):0]}if(t.reference.hasAttribute("data-editor-tooltip-maxwidth")&&(i.maxWidth=Number.parseInt(t.reference.getAttribute("data-editor-tooltip-maxwidth")||"350",10)),t.reference.hasAttribute("data-editor-tooltip-allow-markdown")&&(i.allowHTML=!0),Object.keys(i).length&&t.setProps(i),t.reference.hasAttribute(`data-editor-tooltip-${this.editor.clientId}-dynamic`)){const s=t.reference.getAttribute(`data-editor-tooltip-${this.editor.clientId}-dynamic`);t.setContent(s||"")}}return!0});this.editor=t;const e=t.clientId;this.attributeName=[`data-editor-tooltip-${e}`,`data-editor-tooltip-${e}-dynamic`,"data-editor-tooltip-common"],this.attributeDesc=`data-editor-tooltip-desc-${e}`,this.instance=um.delegate(document.body,{theme:"editor-tooltip",maxWidth:400,delay:200,target:this.attributeName.map(o=>`[${o}]`).join(","),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=Le.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 cF={"text/style-bold":"bold","text/style-italic":"italic","text/style-underline":"underline","text/style-strikethrough":"line-through","text/style-code":"code","text/style-sub":"subscript","text/style-super":"superscript"};function aF(n,t){const e=new Set(Object.keys(cF)),o=t.filter(i=>e.has(i.id));return rf(o)}function bf(n,t){if(!n.isWritable())return!1;const e=n.selection.range,o=n.editorCommandProviders.getCommands(e),i=aF(n,o).find(s=>s.id===`text/${t}`);return i?(n.editorCommandProviders.executeCommand(e,i,{}),gc.get(n).update("selectionChange"),!0):!1}const D0={"CtrlOrCmd+B":n=>bf(n,"style-bold"),"CtrlOrCmd+I":n=>bf(n,"style-italic"),"CtrlOrCmd+U":n=>bf(n,"style-underline"),"CtrlOrCmd+D":n=>bf(n,"style-strikethrough")},uF={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",edit:"\u7F16\u8F91",remove:"\u53D6\u6D88\u94FE\u63A5"},commands:{unordered:"\u65E0\u5E8F\u5217\u8868",ordered:"\u6709\u5E8F\u5217\u8868",check:"\u5F85\u529E\u5217\u8868",link:"\u94FE\u63A5",quote:"\u5F15\u7528",alignLeft:"\u5DE6\u5BF9\u9F50",alignRight:"\u53F3\u5BF9\u9F50",alignCenter:"\u5C45\u4E2D\u5BF9\u9F50",alignGroup:"\u5BF9\u9F50\u65B9\u5F0F",heading:"\u6807\u9898 {name}",headingGroup:"\u6807\u9898\u6837\u5F0F",text:"\u6B63\u6587"}},dF={quickMenu:{basic:{heading:{title:"Title {heading}",space:"{markdown}space"},unordered:"Bulleted list",ordered:"Numbered list",checkbox:"To-do list",quote:"Quote"},inlineBox:{math:"Formula",link:"Link"}},link:{textLabel:"Text",urlLabel:"Link address",textPlaceholder:"Please enter text",urlPlaceholder:"Please enter link",submitText:"Confirm",cancelText:"Cancel",edit:"Edit",remove:"Remove link"},commands:{unordered:"Bulleted list",ordered:"Numberer list",check:"To-do list",link:"Link",quote:"Quote",alignLeft:"Align left",alignRight:"Align right",alignCenter:"Center text",alignGroup:"Alignment",heading:"Title {name}",headingGroup:"Text style",text:"Text"}},hF={quickMenu:{basic:{heading:{title:"\u898B\u51FA\u3057{heading}",space:"{markdown}\u30B9\u30DA\u30FC\u30B9"},unordered:"\u7B87\u6761\u66F8\u304D\u30EA\u30B9\u30C8",ordered:"\u756A\u53F7\u4ED8\u304D\u30EA\u30B9\u30C8",checkbox:"\u30D0\u30C3\u30AF\u30ED\u30B0",quote:"\u5F15\u7528"},inlineBox:{math:"\u6570\u5F0F",link:"URL"}},link:{textLabel:"\u30C6\u30AD\u30B9\u30C8",urlLabel:"URL",textPlaceholder:"\u30C6\u30AD\u30B9\u30C8\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",urlPlaceholder:"URL \u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",submitText:"OK",cancelText:"\u30AD\u30E3\u30F3\u30BB\u30EB",edit:"\u7DE8\u96C6",remove:"\u30EA\u30F3\u30AF\u3092\u89E3\u9664"},commands:{unordered:"\u7B87\u6761\u66F8\u304D\u30EA\u30B9\u30C8",ordered:"\u756A\u53F7\u4ED8\u304D\u30EA\u30B9\u30C8",check:"\u30D0\u30C3\u30AF\u30ED\u30B0",link:"URL",quote:"\u5F15\u7528",alignLeft:"\u5DE6\u63C3\u3048",alignRight:"\u53F3\u63C3\u3048",alignCenter:"\u4E2D\u592E\u63C3\u3048",alignGroup:"\u5BF9\u9F50\u65B9\u5F0F",heading:"\u898B\u51FA\u3057{name}",headingGroup:"\u30BF\u30A4\u30C8\u30EB\u30B9\u30BF\u30A4\u30EB",text:"\u672C\u6587"}};R.mergeLang({"zh-CN":uF,"en-US":dF,"ja-JP":hF});const Tnt="";function Qs(n,...t){const e=uo(...t);return e.classList.remove("editor-button"),e.classList.add("editor-text-button"),n.append(e),e}function j9(n){sf(n).hide();const e=n.getCustom("table-border-bar");e==null||e.closeToolbar()}function fF(n){return w("div",["insert-column-button","drop-marker"],n)}const mF=S("row-height");function U9(n){const t=Tt.fromTable(n),e=n.rows;g(mF,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,a=r+1;for(;a<e.length;){const d=e[a];if(d.cells.length!==0)break;i++,a++,l+=d.getBoundingClientRect().height}for(let d=0;d<i;d++)o[r+d]=l/i;r=a}return o}const gF=S("table-border-bar-dom"),pF=zi+ic+zi;function z9(n){const t=et(n.contentElement);g(gF,t,"no block");const o=te(t).querySelector(".table-border-bar-container.left"),r=Math.min(n.contentElement.offsetLeft+pF,n.rootElement.scrollLeft+zi);o&&(o.style.left=`${-r}px`)}const Qi=S("table-border-bar-dom");function Cc(n,t){g(Qi,Ve(t),"invalid table block");const e=_e(t),o=mr(n,t),r=te(t),i=(p,A,v)=>{const B=w("div",["button-root",A],p),D=w("div",["button-container",A],B);B.setAttribute(`data-${A}-index`,`${v}`),D.setAttribute(`data-editor-tooltip-${n.clientId}`,A==="left"?R.t("table.insertRow"):R.t("table.insertCol")),w("span",["insert-indicator"],D),fF(D)},{selectedRows:s,selectedColumns:l}=Np(n,t),a=()=>{const p=o.querySelector(".table-border-bar-container.top");g(Qi,p,"no top border bar container");const A=w("div",["table-border-bar-container","top"],null),v=w("div",["table-border-bar","top"],A),B=BR(e),x=Tt.fromTable(e).colCount;n.selection.range.isSimple()&&i(v,"top",0);for(let _=0;_<x;_++){const M=_===x-1?B[_]+2:B[_],H=w("span",["table-border-bar-cell","top"],v);l.has(_)&&H.classList.add("selected"),H.setAttribute("data-top-index",`${_}`),H.style.width=`${M}px`,n.selection.range.isSimple()&&i(v,"top",_+1)}Ca(p,A)},d=()=>{const p=r.querySelector(".table-border-bar-container.left");g(Qi,p,"no left border bar container");const A=w("div",["table-border-bar-container","left"],null),v=w("div",["table-border-bar","left"],A);w("span",["table-border-bar-cell","corner"],v);const B=U9(e);n.selection.range.isSimple()&&i(v,"left",0),Array.from(e.rows).forEach((D,x,_)=>{const M=w("span",["table-border-bar-cell","left"],v);s.has(x)&&M.classList.add("selected"),M.setAttribute("data-left-index",`${x}`);const H=x===_.length-1?B[x]+2:B[x];M.style.height=`${H}px`,n.selection.range.isSimple()&&i(v,"left",x+1)}),Ca(p,A)};a(),d();const h=n.findCustom(fr(t));h&&z9(h)}function V9(n,t){const e=t.target;if(!(e instanceof Element))return;const o=et(e);g(Qi,o&&Ve(o),"invalid table block"),Cc(n,o),n.selection.caret.update()}function vf(n,t){const e=t.target;if(!(e instanceof Element))return;const o=et(e);g(Qi,o&&Ve(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);Xv(n,o,i),Cc(n,o)}else if(r.classList.contains("left")){const i=parseInt(r.getAttribute("data-left-index")||"0",10);t9(n,o,i),Cc(n,o)}}}function yf(n,t){var s;j9(n),t.preventDefault(),t.stopPropagation();let e=null,o,r;const i=l=>{var a;if(l.target instanceof HTMLElement&&o&&e&&r!==void 0){const d=et(l.target),h=l.target.closest(".table-border-bar");if(d===e&&h){const p=parseInt((a=l.target.getAttribute(`data-${o}-index`))!=null?a:"0",10),A=Math.min(r,p),v=Math.abs(r-p)+1;xt(l.target,"top")&&o==="top"?NR(n,d,A,v,{reverse:!0}):xt(l.target,"left")&&o==="left"&&$R(n,d,A,v,{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&&xt(t.target,"table-border-bar-cell")&&(e=et(t.target),xt(t.target,"top")?o="top":xt(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 W9(n){const t=n.selection.range,e=lu(n,t);e&&Cc(n,e)}function CF(n,t){g(Qi,Ve(t),"invalid table block");const e=mr(n,t),o=te(t),r=w("div",["table-border-bar-container","top"],e),i=w("div",["table-border-bar-container","left"],o);Cc(n,t),n.domEvents.addEventListener(Lt(t),"scroll",V9),n.domEvents.addEventListener(r,"click",vf),n.domEvents.addEventListener(i,"click",vf),n.domEvents.addEventListener(r,"mousedown",yf),n.domEvents.addEventListener(i,"mousedown",yf),n.addListener("afterClearSelection",W9)}function q9(n,t){if(!n.isWritable())return;if(mr(n,t).querySelector(".table-border-bar-container")){Cc(n,t);return}CF(n,t)}function G9(n,t){g(Qi,Ve(t),"invalid table block");const e=mr(n,t),o=te(t),r=e.querySelectorAll(".table-border-bar-container"),i=o.querySelectorAll(".table-border-bar-container");r.forEach(s=>{n.domEvents.removeEventListener(s,"click",vf),n.domEvents.removeEventListener(s,"mousedown",yf),s.remove()}),i.forEach(s=>{n.domEvents.removeEventListener(s,"click",vf),n.domEvents.removeEventListener(s,"mousedown",yf),s.remove()}),n.domEvents.removeEventListener(Lt(t),"scroll",V9),n.addListener("afterClearSelection",W9)}function AF(n,t){g(Qi,Ve(t),"invalid table block");const o=mr(n,t).querySelector(".table-border-bar-container.top");return o?o.getBoundingClientRect().height:0}class bF{constructor(t,e){m(this,"toolbar");m(this,"handleSelectionChange",(t,e)=>{!t.isVisible||(e==="delete-columns"?(Vi(this.editor,this.tableBlock,!0,!0),Wi(this.editor,this.tableBlock,!0,!0)):e==="delete-rows"?(Vi(this.editor,this.tableBlock,!0,!1),Wi(this.editor,this.tableBlock,!0,!1)):(Vi(this.editor,this.tableBlock,!1),Wi(this.editor,this.tableBlock,!1)))});m(this,"handleClick",(t,e,o)=>{e.id==="delete-columns"?$p(this.editor.selection.range):e.id==="delete-rows"&&Hp(this.editor.selection.range)});m(this,"handleToolbarClose",()=>{this.tableBlock&&lu(this.editor,this.editor.selection.range)===this.tableBlock&&(Vi(this.editor,this.tableBlock,!1),Wi(this.editor,this.tableBlock,!1))});this.editor=t,this.tableBlock=e;const o=t.options.componentsOptions.popover;this.toolbar=new ru([],void 0,{id:"table-row-column-toolbar",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),this.toolbar.addListener("close",this.handleToolbarClose)}close(){this.toolbar.close("cancelBar")}update(){var r,i,s;const{selectedColumns:t,selectedRows:e}=Np(this.editor,this.tableBlock);if(!this.editor.isWritable())return;if(t.size>0&&e.size>0){this.toolbar.close("cancelBar");return}if(t.size===0&&e.size===0){this.toolbar.close("cancelBar");return}const o=Nr(this.editor,this.tableBlock,this.editor.selection.range)[0];if(!o){this.toolbar.close("cancelBar");return}if(t.size>0){const l={id:"delete-columns",name:R.t("table.deleteCol"),icon:yL};this.toolbar.updateItems([l]);const a=zr(this.editor,this.tableBlock,"table-row-column-delete",o);this.toolbar.manualShow(a,{placement:"top",offset:[0,5]})}else{const l={id:"delete-rows",name:R.t("table.deleteRow"),icon:vL};this.toolbar.updateItems([l]);const h=te(this.tableBlock).querySelector(".table-border-bar-container.left").getBoundingClientRect(),p=new DOMRect(Math.max(h.left,o.left-zi),o.top,zi,o.height),A=zr(this.editor,this.tableBlock,"table-row-column-delete",p);this.toolbar.manualShow(A,{placement:"left",offset:[0,5]});const v=this.editor.options.componentsOptions.popover;(r=this.toolbar.tippyInstance)==null||r.setProps({popperOptions:{modifiers:[{name:"flip",options:{boundary:v==null?void 0:v.overflowBoundary,fallbackPlacements:["left","right"]}}]}})}(s=(i=this.toolbar.tippyInstance)==null?void 0:i.popperInstance)==null||s.update()}destroy(){this.toolbar.destroy(),this.toolbar.removeAllListeners()}}const S0=S("table-border-bar");class vF{constructor(t,e){m(this,"toolbar");m(this,"resizeObserver");m(this,"handleReadonlyChanged",t=>{t.isWritable()?this.update():G9(this.editor,this.tableBlock)});m(this,"handleBlockUpdated",()=>{this.resizeObserver.disconnect(),setTimeout(()=>{const t=this.editor.getBlockById(it(this.tableBlock));this.resizeObserver.observe(_e(t))})});m(this,"handleScroll",()=>{this.toolbar.update()});m(this,"handleTableResize",()=>{!this.editor.isWritable()||(console.log("resize"),this.update())});this.editor=t,this.tableBlock=e,g(S0,this.tableBlock,"no table block"),S0.debug("create table border bar"),q9(this.editor,this.tableBlock),this.resizeObserver=new ResizeObserver(this.handleTableResize),this.resizeObserver.observe(_e(this.tableBlock)),this.toolbar=new bF(this.editor,this.tableBlock),this.editor.addListener("readonlyChanged",this.handleReadonlyChanged)}close(){this.toolbar.close()}destroy(){S0.debug("destroy table border bar"),this.resizeObserver.disconnect(),G9(this.editor,this.tableBlock),this.toolbar.destroy(),this.editor.removeListener("readonlyChanged",this.handleReadonlyChanged)}update(){q9(this.editor,this.tableBlock),this.toolbar.update()}}const yF=S("table-border-bar");class kF{constructor(t){m(this,"activeTableBar",null);m(this,"handleBlockDeleted",(t,e)=>{!this.activeTableBar||(e===this.activeTableBar.tableBlock||Xt(e,this.activeTableBar.tableBlock))&&(this.activeTableBar.destroy(),this.activeTableBar=null)});m(this,"handleSelectionChanged",t=>{var r;const e=t.selection.range,o=lu(t,e);((r=this.activeTableBar)==null?void 0:r.tableBlock)!==o&&this.activeTableBar&&this.hide(),o&&this.show(o)});m(this,"handleScroll",()=>{var t;(t=this.activeTableBar)==null||t.handleScroll()});this.editor=t,this.editor.addListener("blockDeleted",this.handleBlockDeleted),this.editor.addListener("selectionChanged",this.handleSelectionChanged)}destroy(){this.editor.removeListener("blockDeleted",this.handleBlockDeleted),this.editor.removeListener("selectionChanged",this.handleSelectionChanged)}show(t){this.activeTableBar?(this.activeTableBar.tableBlock!==t&&this.hide(),this.activeTableBar.update()):this.activeTableBar=new vF(this.editor,t)}update(){var t;(t=this.activeTableBar)==null||t.handleBlockUpdated()}closeToolbar(){var t;(t=this.activeTableBar)==null||t.close()}hide(){!this.activeTableBar||(g(yF,this.activeTableBar,"no active table bar"),this.activeTableBar.destroy(),this.activeTableBar=null)}}function Z9(n,t){const e=n.addCustom("table-border-bar",o=>new kF(o));t==="update"&&e.update()}const Mn=S("table-cell-menu"),wF="style-bg-color-";class BF{constructor(t){m(this,"activeTableBlock",null);m(this,"targetButton",null);m(this,"manualMenu",null);m(this,"colorPaletteItem",null);m(this,"handlePrevent",(t,e)=>{e.stopPropagation()});m(this,"handleReadonlyChanged",t=>{t.isWritable()||this.hide()});m(this,"handleSelectionChanged",t=>{const e=t.selection.range,o=lu(t,e);if(this.hide(),this.activeTableBlock!==o&&(this.activeTableBlock=o),this.activeTableBlock){const r=Tt.fromBlock(this.activeTableBlock),i=e.isReverse()?e.start:e.end;let s=null;i instanceof Mo?t.getBlockById(i.blockId)===this.activeTableBlock?s=r.getCellByContainerId(i.childContainerId):s=this.getCellByChildBlockId(r,i.blockId):s=this.getCellByChildBlockId(r,i.blockId),s&&this.editor.isWritable()&&this.showCellMenuButton(s)}});m(this,"handleBeforePopupPalette",()=>{var e;const t=this.getSelectedBkgColorIndex();(e=this.colorPaletteItem)==null||e.palette.setColor("backgroundColor",t)});m(this,"createBkgColorItem",()=>{const t=w("div",["cell-background-color-item"],null);w("span",[],t,R.t("table.cellBackground"));const e=this.getSelectedBkgColorIndex();w("button",["item-button"],t).setAttribute("data-color-index",`${e}`);const r=w("span",["item-sub-indicator"],t);return r.innerHTML=lv,t});m(this,"handleCommand",t=>{var r;g(Mn,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":Hp(Ov(this.editor,this.activeTableBlock,!1));break;case"delete-select-col":$p(Ov(this.editor,this.activeTableBlock,!0));break;case"merge-cell":Lv(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":qM(this.editor,this.activeTableBlock,o==="show-border");break;case"show-chart":JM(this.editor,this.activeTableBlock,o==="show-chart"),Yp(this.editor,this.activeTableBlock,{updateNow:!0});break}});m(this,"handleToolbarClose",()=>{this.targetButton&&ot(this.targetButton,"active"),this.activeTableBlock&&lu(this.editor,this.editor.selection.range)===this.activeTableBlock&&(Vi(this.editor,this.activeTableBlock,!1),Wi(this.editor,this.activeTableBlock,!1)),this.editor.focus()});m(this,"handleSelectionChange",(t,e)=>{!t.isVisible||(g(Mn,this.activeTableBlock,"no target table block"),e==="cell-background-color"&&this.handleBeforePopupPalette(),e==="delete-select-row"?(Vi(this.editor,this.activeTableBlock,!0,!1),Wi(this.editor,this.activeTableBlock,!0,!1)):e==="delete-select-col"?(Vi(this.editor,this.activeTableBlock,!0,!0),Wi(this.editor,this.activeTableBlock,!0,!0)):(Vi(this.editor,this.activeTableBlock,!1),Wi(this.editor,this.activeTableBlock,!1)))});m(this,"handleClick",(t,e)=>{var o;g(Mn,this.activeTableBlock,"no target table block"),g(Mn,this.targetButton,"no target button"),j9(this.editor),xt(this.targetButton,"active")?(ot(this.targetButton,"active"),(o=this.manualMenu)==null||o.close("clickItem")):(W(this.targetButton,"active"),this.manualMenu?this.manualMenu.updateItems(this.createCommandMenu()):(this.manualMenu=new zs(this.createCommandMenu()),this.manualMenu.on("click",(r,i)=>{var s;this.handleCommand(i),(s=this.manualMenu)==null||s.close("clickItem")}),this.manualMenu.on("selectionChange",this.handleSelectionChange),this.manualMenu.on("close",this.handleToolbarClose)),this.manualMenu.manualShow(this.targetButton,{placement:"right-start"})),e.stopPropagation()});this.editor=t,this.editor.addListener("selectionChanged",this.handleSelectionChanged),this.editor.addListener("readonlyChanged",this.handleReadonlyChanged)}destroy(){var t,e;this.activeTableBlock=null,this.targetButton=null,this.editor.removeListener("selectionChanged",this.handleSelectionChanged),this.editor.removeListener("readonlyChanged",this.handleReadonlyChanged),(t=this.manualMenu)==null||t.destroy(),(e=this.colorPaletteItem)==null||e.destroy()}hide(){var t;(t=this.manualMenu)==null||t.close("cancelBar"),this.targetButton&&(ot(this.targetButton,"active"),this.targetButton.style.display="none")}getCellByChildBlockId(t,e){let o=this.editor.getBlockById(e);for(;o;){const r=o.closest("td");g(Mn,r,"no parent cell");const i=et(r);if(g(Mn,i,"no parent block"),_e(i)===t.table)return t.getCellByCellElement(r);o=i}return g(Mn,!1,"filed to get cell by child block id"),null}createTargetButton(t){this.targetButton?t.querySelector(`:scope > .${qp}`)||t.appendChild(this.targetButton):(this.targetButton=w("button",[qp],t),this.targetButton.innerHTML=Qh,this.editor.domEvents.addEventListener(this.targetButton,"click",this.handleClick),this.editor.domEvents.addEventListener(this.targetButton,"mousedown",this.handlePrevent),this.editor.domEvents.addEventListener(this.targetButton,"dblclick",this.handlePrevent))}showCellMenuButton(t){this.createTargetButton(t.cell),g(Mn,this.targetButton,"no target button"),this.targetButton.style.display="inline-block"}handleSplitCell(){if(this.activeTableBlock){const t=Tt.fromBlock(this.activeTableBlock),e=this.editor.selection.range;if(e.isSimple()){const{col:o,row:r}=this.getCellByChildBlockId(t,e.start.blockId);Up(this.editor,this.activeTableBlock,{col:o,row:r})}else zp(this.editor.selection.range)}}getSelectedBkgColorIndex(){var r;g(Mn,this.activeTableBlock,"no target table block");const t=QM(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=at(i),l=e[`${s}_background`];if(l)o.add(Number.parseInt((r=l.substring(wF.length))!=null?r:"0",10));else{o.add(-1);break}}return o.size===1&&[...o][0]!==-1?[...o][0]:-1}createCommandMenu(){g(Mn,this.activeTableBlock,"no target table block");const t=this.editor.getBlockData(this.activeTableBlock),e=Sv(this.editor,this.activeTableBlock,this.editor.selection.range);let o=this.editor.selection.range;if(o.isSimple()){const h=Jr(this.editor,this.activeTableBlock,o.start);o=Ue(this.editor,{anchor:h,focus:h})}const r=Dv(this.editor,this.activeTableBlock,o),i=t.hasRowTitle,s=t.hasColTitle,l=t.isStripeStyle,a=t.noBorder,d=t.chart;return this.colorPaletteItem=new wv("cell-background-color",{color:!1}),this.colorPaletteItem.palette.on("onClick",(h,p)=>{var A;switch(g(Mn,this.activeTableBlock,"no target table block"),h){case"clearColor":Pv(this.editor,this.activeTableBlock,-1);break;case"backgroundColor":Pv(this.editor,this.activeTableBlock,p);break}(A=this.manualMenu)==null||A.close("clickItem")}),[{id:"cell-background-color",name:R.t("table.cellBackground"),element:this.createBkgColorItem(),children:[this.colorPaletteItem]},{id:"separator",name:"",type:"separator"},{id:"merge-cell",name:R.t("table.mergeCell"),states:e?[]:["disabled"]},{id:"split-cell",name:R.t("table.splitCell"),states:r?[]:["disabled"]},{id:"separator",name:"",type:"separator"},{id:"delete-select-row",name:R.t("table.deleteSelectRow")},{id:"delete-select-col",name:R.t("table.deleteSelectCol")},{id:"separator",name:"",type:"separator"},{id:"table-config",name:R.t("table.tableConfigKey"),children:[{id:"row-title",name:R.t("table.tableConfig.rowTitle"),states:i?["checked"]:[]},{id:"col-title",name:R.t("table.tableConfig.colTitle"),states:s?["checked"]:[]},{id:"stripe-style",name:R.t("table.tableConfig.stripeStyle"),states:l?["checked"]:[]},{id:"hide-border",name:a?R.t("table.tableConfig.showBorder"):R.t("table.tableConfig.hideBorder"),value:a?"show-border":"hide-border"},{id:"show-chart",name:d?R.t("table.tableConfig.hideChart"):R.t("table.tableConfig.showChart"),value:d?"hide-chart":"show-chart"}]}]}handleRowTitle(t){g(Mn,this.activeTableBlock,"no target table block"),t?zM(this.editor,this.activeTableBlock):UM(this.editor,this.activeTableBlock)}handleColTitle(t){g(Mn,this.activeTableBlock,"no target table block"),t?jM(this.editor,this.activeTableBlock):HM(this.editor,this.activeTableBlock)}handleStripeStyle(t){g(Mn,this.activeTableBlock,"no target table block"),t?WM(this.editor,this.activeTableBlock):VM(this.editor,this.activeTableBlock)}}function Q9(n){n.addCustom("table-cell-menu",t=>new BF(t))}const kf=S("table-container");function L0(n){const t=n.closest("td");return g(kf,t,"no parent cell for a table cell container"),t}function Y9(n){const t=_e(n);return Array.from(t.querySelectorAll(':scope > tbody > tr > td > [data-type="editor-container"].child'))}function M0(n,t,e,o){const r=Tt.fromBlock(n),i=r.getCellByContainerId(at(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(g(kf,l>=0,"not a valid child container"),l===0)return null;const a=s[l-1];return o!=null&&o.noWrap&&r.getCellByContainerId(at(a)).row!==i.row?null:a}if(e==="ArrowRight"){const s=r.getAllContainers(),l=s.indexOf(t);if(g(kf,l>=0,"not a valid child container"),l===s.length-1)return null;const a=s[l+1];return o!=null&&o.noWrap&&r.getCellByContainerId(at(a)).row!==i.row?null:a}g(kf,!1,`invalid navigation type: ${e}`)}const EF=12,xF=90,wf=23,J9=2;class IF{constructor(t){m(this,"scrollTableBlock",null);m(this,"autoScrollDir",null);m(this,"autoScrollTimer",null);m(this,"handleMouseDown",t=>{const e=document.elementFromPoint(t.clientX,t.clientY);if(e&&e instanceof HTMLElement){const o=et(e);if(o&&Xt(this.editor.rootContainer,o)){const r=Yr(o);r&&(this.scrollTableBlock=r,document.addEventListener("mousemove",this.handleAutoScroll))}}});m(this,"handleAutoScroll",QB.default(t=>{if(this.scrollTableBlock){const e=this.editor.getCustom(fr(this.scrollTableBlock)),o=e.rootElement,r=e.scrollOptions.parentContainer,i=o.getBoundingClientRect(),s=window.innerHeight-this.getBarFloatWindowBottom(e),l=r.getBoundingClientRect(),a=Math.min(l.bottom,s),d=Math.max(l.top,0);i.bottom>a&&t.clientY>=a?this.setAutoScroll("bottom"):i.top<d&&t.clientY<=d?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));m(this,"handleMouseUp",()=>{document.removeEventListener("mousemove",this.handleAutoScroll),setTimeout(()=>{this.scrollTableBlock=null})});m(this,"handleSelectionChanged",t=>{const e=t.selection.range;if(e.isCollapsed()&&e.isSimple()){const o=t.getBlockById(e.start.blockId),r=Yr(o);if(r){const i=t.getCustom(fr(r)),s=i.rootElement.getBoundingClientRect(),l=So(t,o,e.start);if(s.left>l.left){const a=e.start.offset===0?EF:J9;i.rootElement.scrollLeft-=s.left-l.left+a}else if(l.right>s.right){const a=e.start.offset===0?xF:J9;i.rootElement.scrollLeft+=l.right-s.right+a}}}else{const o=t.getBlockById(e.start.blockId),r=Yr(o),i=t.getBlockById(e.end.blockId),s=Yr(i);if(r&&r===s){const l=t.getCustom(fr(r)),a=l.rootElement.getBoundingClientRect();let d=null;if(e.isSimple())d=e.isReverse()?So(t,o,e.start):So(t,i,e.end);else{const h=L0(jr(t,e.start.childContainerId)),p=L0(jr(t,e.end.childContainerId));d=e.isReverse()?h.getBoundingClientRect():p.getBoundingClientRect()}a.left>d.left&&e.isReverse()?l.rootElement.scrollLeft-=a.left-d.left:a.right<d.right&&!e.isReverse()&&(l.rootElement.scrollLeft+=d.right-a.right)}}});m(this,"handleScroll",t=>{xv(t),this.editor.selection.caret.update()});m(this,"handleReset",t=>{xv(t),this.editor.selection.caret.update();const e=this.editor.findCustom("table-border-bar");e&&e.handleScroll(),z9(t)});this.editor=t,this.editor.addListener("selectionChanged",this.handleSelectionChanged),document.addEventListener("mousedown",this.handleMouseDown),document.addEventListener("mouseup",this.handleMouseUp)}getBarFloatWindowBottom(t){return t.scrollOptions.barFloatWindowBottom?typeof t.scrollOptions.barFloatWindowBottom=="number"?t.scrollOptions.barFloatWindowBottom:t.scrollOptions.barFloatWindowBottom():0}clearAutoScroll(){this.autoScrollTimer&&(clearInterval(this.autoScrollTimer),this.autoScrollTimer=null,this.autoScrollDir=null)}setAutoScroll(t){this.autoScrollDir&&this.autoScrollDir!==t&&this.clearAutoScroll(),this.autoScrollTimer||(this.autoScrollDir=t,this.autoScrollTimer=window.setInterval(()=>{if(this.scrollTableBlock){const e=this.editor.getCustom(fr(this.scrollTableBlock)),o=e.rootElement,r=e.scrollOptions.parentContainer,i=o.getBoundingClientRect(),s=r===document.documentElement?window.innerHeight:r.offsetHeight,l=window.innerHeight-this.getBarFloatWindowBottom(e),a=r.getBoundingClientRect(),d=Math.min(a.bottom,l),h=Math.max(a.top,0);this.autoScrollDir==="left"&&(o.scrollLeft-=wf,o.scrollLeft<=0&&this.clearAutoScroll()),this.autoScrollDir==="right"&&(o.scrollLeft+=wf,o.scrollLeft>=o.scrollWidth-o.offsetWidth&&this.clearAutoScroll()),this.autoScrollDir==="bottom"&&(r.scrollTop+=wf,(r.scrollTop>=r.scrollHeight-s||i.bottom<=d)&&this.clearAutoScroll()),this.autoScrollDir==="top"&&(r.scrollTop-=wf,(r.scrollTop<=0||i.top>=h)&&this.clearAutoScroll())}},100))}destroy(){document.removeEventListener("mousedown",this.handleMouseDown),document.removeEventListener("mouseup",this.handleMouseUp),this.editor.removeListener("selectionChanged",this.handleSelectionChanged)}}function K9(n){return n.addCustom("table-scroll-events",t=>new IF(t))}const gr=S("create-content");function X9(n,t,e){const o=new Yh(e),r=e.rows,i=e.cols;g(gr,r>=1,`invalid rows: ${r}`),g(gr,i>=1,`invalid cols: ${i}`),g(gr,e.children,"no table children");const s=w("table",[],null),l=e.colsWidth,a=w("colgroup",[],s);for(let p=0;p<o.colCount;p++){const A=w("col",[],a);l[p]&&(A.style.width=`${l[p]}px`)}const d=w("tbody",[],s);let h=0;for(let p=0;p<r;p++){const A=w("tr",[],d);for(let v=0;v<i;v++){const B=o.getCell({col:v,row:p});if(B.virtual)g(gr,B.colSpan>1||B.rowSpan>1,"virtual cell should have colSpan or rowSpan");else{const D=e.children[h],x=w("td",[],A);B.colSpan>1&&(x.colSpan=B.colSpan),B.rowSpan>1&&(x.rowSpan=B.rowSpan);const _=e[au(D)];_&&W(x,_),v===0&&e.hasColTitle&&W(x,Mv.COL_TITLE_ITEM),n.createChildContainer(t,x,D),h+=1}}}return g(gr,h===e.children.length,"container count mismatch"),e.noBorder&&W(s,"no-border"),e.chart&&W(s,"editor-table-chart"),e.isStripeStyle&&W(s,"stripe"),e.hasRowTitle&&W(s,"row-title"),e.hasColTitle&&W(s,"col-title"),s}function TF(n,t,e,o,r){g(gr,r.type==="table","not table data"),g(gr,at(e)===t[t.length-1].containerId,"invalid path");const i=r,s=Is(o,"div");try{const l=w("div",[],null);l.setAttribute("data-type","table-content");const a=X9(n,t,i);a.classList.add("drag-preview-element"),l.appendChild(a),Jv(n),n9(n),Z9(n,"create"),Q9(n),cL(n,Jp);const d=n.getComponentOptions("table"),h=n.addCustom(fr(o),()=>kR());h.init({parentElement:s,childElement:l,safeRightSpace:50,safeLeftSpace:40,parentContainer:Yt(e)?n.scrollContainer:e,locatingContainer:Yt(e)?(d==null?void 0:d.locatingContainer)||n.parent:e,paddingLeft:zi+ic,paddingTop:zi+ic,paddingBottom:ic/2,paddingRight:ic/2,barFloatWindowBottom:d==null?void 0:d.barFloatWindowBottom,isSetScale:d==null?void 0:d.isSetScale});const p=K9(n);h.on("scroll",p.handleReset),h.on("resize",p.handleReset),setTimeout(()=>{tR(n,o)})}catch{const a=`invalid table data: ${JSON.stringify(i)}`;gr.error(a);const d=w("div",["error"],s);d.innerText=a}return s}function DF(n,t,e){g(gr,e.type==="table","not table data");const o=e,r=Lt(t);try{const i=_e(t),s=Li(t),l=X9(n,s,o);l.classList.add("drag-preview-element"),i.insertAdjacentElement("afterend",l),i.remove(),Jv(n),n9(n),Z9(n,"update"),Q9(n),Jp(n,t)}catch{const s=`invalid table data: ${JSON.stringify(o)}`;gr.error(s);const l=w("div",["error"],r);l.innerText=s}}function SF(n,t){let e,o,r=!1;if([...t].every(A=>A==="|")?(o=t.length,e=Array(o).fill(""),r=!0):(e=wm(t,"|").split("|"),o=e.length),o<2)return null;const i=3,s=o,l=[];for(let A=0;A<3;A++)e.forEach(v=>{l.push(qr(n.doc,A===0?v:""))});const a=Array(s).fill(t0),d=l[r?0:s],h=n.doc.getContainerBlocks(d)[0].id;return{blockData:{id:K(),type:"table",rows:i,cols:s,children:l,colsWidth:a},focusBlockId:h}}function LF(n,t){const e=t.rows,o=t.cols;if(e<1||o<1)return null;const r=[];for(let d=0;d<e;d++)for(let h=0;h<o;h++)r.push(qr(n.doc));const i=Array(o).fill(t0),s=r[0],l=n.doc.getContainerBlocks(s)[0].id;return{blockData:{id:K(),type:"table",rows:e,cols:o,children:r,colsWidth:i},focusBlockId:l}}const t7=S("table-selection-to-doc");function MF(n,t){const{start:e,end:o,block:r}=t,i=Dt(r);g(t7,i==="table",`invalid block type: ${i}`);const s=n.getBlockData(r);if(e.isSimple()&&o.isSimple())return Fi(n.editorBlocks,n.doc.toJSON(),s);g(t7,!e.isSimple()&&!o.isSimple(),"invalid block pos type");const l=Tt.fromBlock(r),{fromCol:a,toCol:d,fromRow:h,toRow:p}=Uo(r,e,o),A={},v=[],B=n.doc.toJSON();let D={};l.sub({row:h,col:a},{row:p,col:d}).forEach((rt,ft)=>{rt.forEach((Bt,jt)=>{const Ut=Bt.containerId;if(v.indexOf(Ut)!==-1)return;v.push(Ut);let ne;if(Bt.virtual){const $e=l.getCellByContainerId(Bt.containerId),Rn=a+jt;let kr=$e.col+$e.colSpan-1;kr>d&&(kr=d);const vn=kr-Rn+1;vn>1&&(A[`${Ut}_colSpan`]=vn);const an=h+ft;let wr=$e.row+$e.rowSpan-1;wr>p&&(wr=p);const oi=wr-an+1;oi>1&&(A[`${Ut}_rowSpan`]=oi),ne=Wr()}else{if(ne=_g(n.editorBlocks,B,Ut),Bt.col+Bt.colSpan>d+1){const $e=d-Bt.col+1;$e>1&&(A[`${Ut}_colSpan`]=$e)}else Bt.colSpan>1&&(A[`${Ut}_colSpan`]=Bt.colSpan);if(Bt.row+Bt.rowSpan>p+1){const $e=p-Bt.row+1;$e>1&&(A[`${Ut}_rowSpan`]=$e)}else Bt.rowSpan>1&&(A[`${Ut}_rowSpan`]=Bt.rowSpan)}const{root:qe,...Yn}=ne.blocks;D={...D,...Yn,[Ut]:qe}})});const _=mu(_e(r)).slice(a,d+1);return{blocks:{root:[{id:K(),type:i,children:v,colsWidth:_,rows:p-h+1,cols:d-a+1,...A}],...D},meta:{},comments:{}}}function RF(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 OF(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 _F(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 FF(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 PF(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 a=!1;do{if(a=!1,!RF(n,l)){l.top--,a=!0;continue}if(!OF(n,l)){l.left--,a=!0;continue}if(!_F(n,l)){l.bottom++,a=!0;continue}if(!FF(n,l)){l.right++,a=!0;continue}}while(a);return l}function NF(n,t,e,o){if(e.custom!==void 0||o.custom!==void 0)return{anchor:e,focus:o};const r=Tt.fromBlock(t),i=r.map(H=>H.containerId),s=r.getCellByContainerId(e.childContainerId),l=r.getCellByContainerId(o.childContainerId),a=Math.min(s.row,l.row),d=Math.max(s.row,l.row),h=Math.min(s.col,l.col),p=Math.max(s.col,l.col),A=PF(i,{row:a,col:h},{row:d,col:p}),v=r.getCell({row:A.top,col:A.left}),B=r.getCell({row:A.bottom,col:A.right}),D=r.getCell({row:A.top,col:A.right}),x=r.getCell({row:A.bottom,col:A.left});let _,M;return s.row<=l.row?s.col<=l.col?(_=v,M=B):(_=D,M=x):s.col<l.col?(_=x,M=D):(_=B,M=v),console.log(`move ${_.col}, ${_.row}, -> ${M.col}, ${M.row}`),{anchor:fe(t,_.containerId),focus:fe(t,M.containerId)}}function e7(n,t,e){if(e.isSimple())return[_e(t).getBoundingClientRect()];const o=_e(t),r=o.getBoundingClientRect(),{fromCol:i,fromRow:s,toCol:l,toRow:a}=Uo(t,e.start,e.end),d=mu(o),h=d.slice(0,i).reduce((D,x)=>D+x,0),p=h+d.slice(i,l+1).reduce((D,x)=>D+x,0),A=U9(o);let v=A.slice(0,s).reduce((D,x)=>D+x,0);const B=v+A.slice(s,a+1).reduce((D,x)=>D+x,0);if(s===0){const D=AF(n,t);v-=D}return[new DOMRect(r.left+h,r.top+v,p-h,B-v)]}S("table-size");const $F=40;function Bf(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 HF(n,t,e){const o=Gm(n,e.container);return o!==void 0?o+Bf(t):$F*e.colSpan-Bf(t)}function jF(n,t,e,o){let r=0;const i=e.colCount;for(let s=0;s<i;s++){const l=e.getCell({col:s,row:o});if(l.virtual)continue;let a=HF(n,t,l);const d=b4(l.container,{withPadding:!0});d&&d>a&&(a=d),r+=a+Bf(t)}return r}function UF(n,t){const e=_e(t),o=Tt.fromTable(e);let r=0;for(let s=0;s<o.rowCount;s++)r=Math.max(r,jF(n,e,o,s));const i=Bf(e);return r+=i,r}const Kr=S("table-creator");async function zF(n,t){return n.undoManager.runInGroup(()=>{var a,d;const e=t.item,o=(a=e.colCount)!=null?a:5,r=(d=e.rowCount)!=null?d:3,i=LF(n,{cols:o,rows:r});if(!i)return null;const{blockData:s,focusBlockId:l}=i;return n.insertBlock(t.containerId,t.blockIndex,s,Ce(n,l,0))})}class VF{constructor(){m(this,"id","insert-table");m(this,"name","Create table");m(this,"element");m(this,"closeable",null);m(this,"colCount");m(this,"rowCount");m(this,"setCloseable",t=>{this.closeable=t});m(this,"destroy",()=>{this.closeable=null});m(this,"getTableCreatorCellId",(t,e)=>`table-creator-cell-${t}-${e}`);m(this,"handleTableCreatorClick",t=>{var A,v;t.preventDefault(),t.stopPropagation();const e=t.target;g(Kr,e instanceof HTMLElement,"invalid event target");const o=e.closest(".table-creator");g(Kr,o,"no table creator");const r=o.querySelectorAll(".active");if(r.length===0)return;const s=r[r.length-1].id;g(Kr,s,"no cell id");const l="table-creator-cell-";if(!s.startsWith(l))return;const d=s.substring(l.length).split("-");g(Kr,d.length===2,"invalid cell id");const h=Number.parseInt(d[0],10)+1,p=Number.parseInt(d[1],10)+1;Kr.debug(`${h}, ${p}`),this.colCount=p,this.rowCount=h,(A=this.closeable)==null||A.click(this,this.element),(v=this.closeable)==null||v.close("clickItem"),this.handleTableCreatorLeave()});m(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&&ot(r,"active")}});m(this,"handleTableCreatorCellEnter",t=>{const e=t.target;g(Kr,e instanceof HTMLElement,"invalid event target");const o=e.id,r="table-creator-cell-";g(Kr,o.startsWith(r),"invalid cell id");const s=o.substring(r.length).split("-");g(Kr,s.length===2,"invalid cell id");let l=Number.parseInt(s[0],10),a=Number.parseInt(s[1],10);l===0&&a===0&&(l=-1,a=-1);for(let d=0;d<9;d++)for(let h=0;h<9;h++){const p=this.getTableCreatorCellId(d,h),A=document.getElementById(p);g(Kr,A,"no cell"),d<=l&&h<=a?W(A,"active"):ot(A,"active")}});this.element=this.createTableCreatorElement()}createTableCreatorElement(){const t=w("div",["table-creator"],null),e=(o,r,i)=>{const s=w("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=w("div",["table-creator-row"],t);for(let i=0;i<9;i++)e(r,o,i).addEventListener("mouseenter",this.handleTableCreatorCellEnter)}return t}}function WF(){return new VF}function qF(n){const t=/[\u4e00-\u9fff\u3040-\u309f\u30a0-\u30ff\uac00-\ud7af]/g,e=n.match(t);return e?e.length:0}function n7(n){const t=qF(n);return n.length+t}function GF(n,t){const e=n7(n),o=t-e;return o>0?n+" ".repeat(o):n}function ZF(n,t,e,o,r){const i=t,s=new Yh(i);if(o==="markdown"||o==="text"){const l=x=>e.blocks[x].map((H,z)=>o==="markdown"?Eg(n,H,e,[...r,{containerId:x,blockIndex:z}]):vh(n,H,e,[...r,{containerId:x,blockIndex:z}])),a=x=>l(x).join(" ").replace(/\n/g," ").trim(),d=new Map,h=new Map;for(let x=0;x<s.colCount;x++){let _=0;for(let M=0;M<s.rowCount;M++){const H=s.getCell({row:M,col:x});let z="";H.virtual||(z=a(H.containerId)),d.set(`${M},${x}`,z),_=Math.max(_,n7(z))}h.set(x,_)}const p=x=>{const _=d.get(`${x.row},${x.col}`)||"",M=h.get(x.col)||0;return GF(_,M)},A=[];let v="|",B="|";for(let x=0;x<s.colCount;x++){const _=p({row:0,col:x});v+=` ${_} |`;const M="-".repeat((h.get(x)||0)+2);B+=`${M}|`}A.push(v),A.push(B);for(let x=1;x<s.rowCount;x++){let _="|";for(let M=0;M<s.colCount;M++){const H=p({row:x,col:M});_+=` ${H} |`}A.push(_)}return`${A.join(`
|
|
399
|
+
`:r.mathjaxText}function G_(){return{abstract:R.t("mathjax.abstract")}}const N9={embedType:"math",createEmbedContent:U_,getOptions:V_,convertFrom:z_,handleDeleteBlock:W_,convertTo:q_,getBlockProperties:G_},Int="",Z_={mathjax:{emptyText:"\u7A7A\u7684\u516C\u5F0F",abstract:"\u516C\u5F0F"}},Q_={mathjax:{emptyText:"Empty formula",abstract:"Formula"}},Y_={mathjax:{emptyText:"\u6570\u5F0F\u306A\u3057",abstract:"\u6570\u5F0F"}};R.mergeLang({"zh-CN":Z_,"en-US":Q_,"ja-JP":Y_});function J_(n,t,e,o){const r=n.getBlockByIndex(t,e),i=n.getBlockText(r),{left:s}=In(i,o);if(!ie(s).endsWith("$$$$"))return!1;const a=o-4,d=o,h={id:K(),box:!0,type:"math",tex:" ",src:"",created:Date.now()};return n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,a,d-a),n.insertBoxToBlock(r,a,h),setTimeout(()=>{const p=n.getBoxById(h.id);pf(n,p)})}),!0}class K_{handleAfterInsertText(t,e,o,r,i){return!!(i===" "&&J_(t,e,o,r))}}const pc=S("inline-box-items");function X_(n,t,e){return n.undoManager.runInGroup(()=>{var s;let o=n.getBlockByIndex(t,e);he(n,o)||(o=n.insertTextBlock([],t,e));const r=F9();n.setBlockText(o,[r]);const i=(s=r.attributes)==null?void 0:s.id;return g(pc,i,"mathjax box id is empty"),setTimeout(()=>{const l=n.getBoxById(i);pf(n,l)},100),o})}function tF(n,t,e){let o=n.getBlockByIndex(t,e),r="bottom-start";return he(n,o)||(r="top-start"),gu(n,{target:o,linkText:"",linkUrl:"",onFinished:(l,a)=>{n.undoManager.runInGroup(()=>{try{he(n,o)||(o=n.insertTextBlock([],t,e));const d=co(l,{link:a}),h=co(" ",null),p=[d,h];n.insertTextToBlock(o,0,p),n.selection.selectBlock(o,rn(p)),n.focus()}catch(d){pc.error(d)}})},onClose:()=>{n.focus()},placement:r}),o}function eF(n,t,e){return n.undoManager.runInGroup(()=>{var l;const o=n.getBlockByIndex(t,e),r=n.selection.range;g(pc,Ur(r.start),"invalid block position");const i=F9();n.insertBoxToBlock(o,r.start.offset,i.attributes);const s=(l=i.attributes)==null?void 0:l.id;return g(pc,s,"mathjax box id is empty"),setTimeout(()=>{const a=n.getBoxById(s);pf(n,a)},100),o})}function nF(n,t,e){const o=n.getBlockByIndex(t,e),r=n.selection.range;g(pc,Ur(r.start),"invalid block position");const i=Nr(n,o,r);if(i.length===0)return;const s=i[0],l=zr(n,o,"quick-menu-inline-link",s);gu(n,{target:l,linkText:"",linkUrl:"",onFinished:(h,p)=>{n.undoManager.runInGroup(()=>{try{const A=n.getBlockText(o),v=Vr(A,r.start.offset,h,{link:p});n.setBlockText(o,v),n.selection.selectBlock(o,r.start.offset+h.length),n.focus()}catch(A){pc.error(A)}})},onClose:()=>{n.focus()},placement:"bottom-start"})}class $9{getCommands(){return[{id:"insert-math",name:R.t("quickMenu.inlineBox.math"),icon:OL,order:900,group:"common",subText:Cn("insert-math")},{id:"insert-link",name:R.t("quickMenu.inlineBox.link"),icon:hv,order:400,group:"common",subText:Cn("insert-link")}]}async handleUpdateBlockCore(t,e){switch(e.item.id){case"insert-math":return eF(t,e.containerId,e.blockIndex);case"insert-link":return nF(t,e.containerId,e.blockIndex);default:return null}}async handleInsertEmptyBlockCore(t,e){switch(e.item.id){case"insert-math":return X_(t,e.containerId,e.blockIndex);case"insert-link":return tF(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=at(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 oF(n,t={withPlainText:!1}){var i,s;const{withPlainText:e}=t,o=(s=(i=n.options.componentsOptions)==null?void 0:i.quickMenu)==null?void 0:s.commandProviders;if(!o)return[];const r=[];return[...o,new S9(e),new $9].forEach(l=>{const a=l.getCommands(n);r.push(...a.map(d=>({...d,itemType:"insert-block",commandProvider:l})))}),r}function rF(n,t={withPlainText:!1}){const e=[];return n.editorBlocks.forEach(o=>{if(!o.getOptions)return;const r=o.getOptions(n);!r.insertBlockCommandItems||(r.insertBlockCommandItems.forEach(i=>{D9(i,r)}),e.push(...r.insertBlockCommandItems))}),e.push(...oF(n,t)),e}function T0(n,t={withPlainText:!1}){const e=rF(n,t),o=new Map;e.forEach(s=>{var d;const l=(d=s.group)!=null?d:"";let a=o.get(l);a?a.items.push(s):(a={group:l,order:s.groupOrder||L9[l]||1e3,items:[s]},o.set(l,a))});const r=Array.from(o.values());r.sort((s,l)=>s.order-l.order),r.forEach(s=>{s.items.sort((l,a)=>{var d,h;return((d=l.order)!=null?d:0)-((h=a.order)!=null?h:0)})});const i=[];return r.forEach((s,l)=>{const a=`blockMenu.section.${s.group||"common"}`,d=R.t(a),h=d===a?s.group:d;i.push({id:`section-${l}`,name:h,type:"section",group:s.group,itemType:"insert-block"}),i.push(...s.items.map(p=>({...p})))}),i}function iF(n,t,e){const o=n.getFocusedBlock();if(!o)return;const r=n.getParentContainer(o),i=at(r);let l=n.getBlockIndex(o);if(he(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 H9=S("quick-menu"),sF={id:"quick-menu",trigger:["/"]},lF=5;class Cf{constructor(t,e=sF){m(this,"suggest");m(this,"items");m(this,"maxHeading");m(this,"firstEmptyOffset",-1);m(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,""),i=this.items.filter(s=>{if(s.type==="section")return!0;if(s.name.toLocaleLowerCase().indexOf(r)!==-1||EM(s).toLocaleLowerCase().indexOf(r)!==-1)return o.add(s.group),!0;const l=`blockMenu.section.${s.group||"common"}`,a=R.t(l),d=a===l?s.group:a;return(d==null?void 0:d.toLocaleLowerCase().indexOf(r))!==-1?(o.add(s.group),!0):!1}).filter(s=>s.type==="section"?o.has(s.group):!0);return i.length?this.firstEmptyOffset=-1:this.handleEmptySearch(),i}return this.items});m(this,"onClose",()=>{this.firstEmptyOffset=-1});m(this,"onShow",(t,e,o,r)=>{const i=this.editor.getBlockByIndex(e,o);if(!io(i)){const s=et(nt(i));if(s&&Dt(s)==="code")return!1}return!0});m(this,"onClickItem",(t,e)=>{const o=e;o.itemType==="insert-block"&&(g(H9,o.blockOptions||o.commandProvider,"invalid quick item, no block options or command provider"),g(H9,this.suggest.anchor,"invalid suggest, no anchor"),this.options.id==="empty-block-menu"&&this.editor.focus(),iF(this.editor,o,this.suggest.anchor))});this.editor=t,this.options=e,this.items=[],this.maxHeading=lf(),this.suggest=new Fp(t,{id:e.id||"quick-menu",trigger:e.trigger,needSpaceBeforeTrigger:!0,autoDeleteTrigger:!0,highlight:!0,onClose:this.onClose,onShow:this.onShow,onClickItem:this.onClickItem,queryItems:this.queryItems})}get menu(){return this.suggest.menu.menu}destroy(){this.suggest.destroy()}initMenuItems(){const t=T0(this.editor);this.items=t}refreshMenuItems(){let t=null,e=0;const o=lf();if(o!==this.maxHeading){const r=new S9,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}}handleEmptySearch(){const t=this.editor.selection.getFocusedPos();if(this.firstEmptyOffset===-1){if(t.isSimple()){const{offset:e}=t;this.firstEmptyOffset=e-1}}else if(t.isSimple()){const{offset:e}=t;e-this.firstEmptyOffset>lF&&(this.suggest.close(),this.firstEmptyOffset=-1)}}}class Af{constructor(t){m(this,"instance");m(this,"mousedown",!1);m(this,"currentInstance",null);m(this,"attributeName",[]);m(this,"attributeDesc","");m(this,"observer",null);m(this,"observerCallback",null);m(this,"createContent",t=>{let e="",o=0;for(;o<this.attributeName.length&&!e;)t.hasAttribute(this.attributeName[o])&&(e=t.getAttribute(this.attributeName[o])||""),o++;const r=t.getAttribute(this.attributeDesc);if(!r)return e;const i=w("div",[],null);return w("span",[],i,e),r&&w("span",["editor-tooltip-desc"],i,r),i});m(this,"handleDocumentMouseDown",()=>{this.mousedown=!0,this.editor.domEvents.addEventListener(document,"mouseup",this.handleDocumentMouseUp)});m(this,"handleDocumentMouseUp",()=>{this.mousedown=!1,this.editor.domEvents.removeEventListener(document,"mouseup",this.handleDocumentMouseUp)});m(this,"handleShown",t=>{this.currentInstance&&this.hide(),this.currentInstance=t,this.createObserver()});m(this,"handleHidden",()=>{this.destroyObserver(),this.currentInstance=null});m(this,"handleShow",t=>{var r;const e=t.reference;if(!e||!Xt(document.body,e)||window.isDragging||this.mousedown)return!1;const o=Number.parseInt((r=e.getAttribute("data-tooltip-hide-at"))!=null?r:"",10);if(o&&Date.now()-o<1e3)return!1;if(t.reference){const i={};if(t.reference.hasAttribute("data-editor-tooltip-placement")&&(i.placement=t.reference.getAttribute("data-editor-tooltip-placement")||"top"),t.reference.hasAttribute("data-editor-tooltip-offset-x")||t.reference.hasAttribute("data-editor-tooltip-offset-y")){const s=t.reference.getAttribute("data-editor-tooltip-offset-x"),l=t.reference.getAttribute("data-editor-tooltip-offset-y");i.offset=[s?Number.parseInt(s,10):0,l?Number.parseInt(l,10):0]}if(t.reference.hasAttribute("data-editor-tooltip-maxwidth")&&(i.maxWidth=Number.parseInt(t.reference.getAttribute("data-editor-tooltip-maxwidth")||"350",10)),t.reference.hasAttribute("data-editor-tooltip-allow-markdown")&&(i.allowHTML=!0),Object.keys(i).length&&t.setProps(i),t.reference.hasAttribute(`data-editor-tooltip-${this.editor.clientId}-dynamic`)){const s=t.reference.getAttribute(`data-editor-tooltip-${this.editor.clientId}-dynamic`);t.setContent(s||"")}}return!0});this.editor=t;const e=t.clientId;this.attributeName=[`data-editor-tooltip-${e}`,`data-editor-tooltip-${e}-dynamic`,"data-editor-tooltip-common"],this.attributeDesc=`data-editor-tooltip-desc-${e}`,this.instance=um.delegate(document.body,{theme:"editor-tooltip",maxWidth:400,delay:200,target:this.attributeName.map(o=>`[${o}]`).join(","),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=Le.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 cF={"text/style-bold":"bold","text/style-italic":"italic","text/style-underline":"underline","text/style-strikethrough":"line-through","text/style-code":"code","text/style-sub":"subscript","text/style-super":"superscript"};function aF(n,t){const e=new Set(Object.keys(cF)),o=t.filter(i=>e.has(i.id));return rf(o)}function bf(n,t){if(!n.isWritable())return!1;const e=n.selection.range,o=n.editorCommandProviders.getCommands(e),i=aF(n,o).find(s=>s.id===`text/${t}`);return i?(n.editorCommandProviders.executeCommand(e,i,{}),gc.get(n).update("selectionChange"),!0):!1}const D0={"CtrlOrCmd+B":n=>bf(n,"style-bold"),"CtrlOrCmd+I":n=>bf(n,"style-italic"),"CtrlOrCmd+U":n=>bf(n,"style-underline"),"CtrlOrCmd+D":n=>bf(n,"style-strikethrough")},uF={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",edit:"\u7F16\u8F91",remove:"\u53D6\u6D88\u94FE\u63A5"},commands:{unordered:"\u65E0\u5E8F\u5217\u8868",ordered:"\u6709\u5E8F\u5217\u8868",check:"\u5F85\u529E\u5217\u8868",link:"\u94FE\u63A5",quote:"\u5F15\u7528",alignLeft:"\u5DE6\u5BF9\u9F50",alignRight:"\u53F3\u5BF9\u9F50",alignCenter:"\u5C45\u4E2D\u5BF9\u9F50",alignGroup:"\u5BF9\u9F50\u65B9\u5F0F",heading:"\u6807\u9898 {name}",headingGroup:"\u6807\u9898\u6837\u5F0F",text:"\u6B63\u6587"}},dF={quickMenu:{basic:{heading:{title:"Title {heading}",space:"{markdown}space"},unordered:"Bulleted list",ordered:"Numbered list",checkbox:"To-do list",quote:"Quote"},inlineBox:{math:"Formula",link:"Link"}},link:{textLabel:"Text",urlLabel:"Link address",textPlaceholder:"Please enter text",urlPlaceholder:"Please enter link",submitText:"Confirm",cancelText:"Cancel",edit:"Edit",remove:"Remove link"},commands:{unordered:"Bulleted list",ordered:"Numberer list",check:"To-do list",link:"Link",quote:"Quote",alignLeft:"Align left",alignRight:"Align right",alignCenter:"Center text",alignGroup:"Alignment",heading:"Title {name}",headingGroup:"Text style",text:"Text"}},hF={quickMenu:{basic:{heading:{title:"\u898B\u51FA\u3057{heading}",space:"{markdown}\u30B9\u30DA\u30FC\u30B9"},unordered:"\u7B87\u6761\u66F8\u304D\u30EA\u30B9\u30C8",ordered:"\u756A\u53F7\u4ED8\u304D\u30EA\u30B9\u30C8",checkbox:"\u30D0\u30C3\u30AF\u30ED\u30B0",quote:"\u5F15\u7528"},inlineBox:{math:"\u6570\u5F0F",link:"URL"}},link:{textLabel:"\u30C6\u30AD\u30B9\u30C8",urlLabel:"URL",textPlaceholder:"\u30C6\u30AD\u30B9\u30C8\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",urlPlaceholder:"URL \u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",submitText:"OK",cancelText:"\u30AD\u30E3\u30F3\u30BB\u30EB",edit:"\u7DE8\u96C6",remove:"\u30EA\u30F3\u30AF\u3092\u89E3\u9664"},commands:{unordered:"\u7B87\u6761\u66F8\u304D\u30EA\u30B9\u30C8",ordered:"\u756A\u53F7\u4ED8\u304D\u30EA\u30B9\u30C8",check:"\u30D0\u30C3\u30AF\u30ED\u30B0",link:"URL",quote:"\u5F15\u7528",alignLeft:"\u5DE6\u63C3\u3048",alignRight:"\u53F3\u63C3\u3048",alignCenter:"\u4E2D\u592E\u63C3\u3048",alignGroup:"\u5BF9\u9F50\u65B9\u5F0F",heading:"\u898B\u51FA\u3057{name}",headingGroup:"\u30BF\u30A4\u30C8\u30EB\u30B9\u30BF\u30A4\u30EB",text:"\u672C\u6587"}};R.mergeLang({"zh-CN":uF,"en-US":dF,"ja-JP":hF});const Tnt="";function Qs(n,...t){const e=uo(...t);return e.classList.remove("editor-button"),e.classList.add("editor-text-button"),n.append(e),e}function j9(n){sf(n).hide();const e=n.getCustom("table-border-bar");e==null||e.closeToolbar()}function fF(n){return w("div",["insert-column-button","drop-marker"],n)}const mF=S("row-height");function U9(n){const t=Tt.fromTable(n),e=n.rows;g(mF,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,a=r+1;for(;a<e.length;){const d=e[a];if(d.cells.length!==0)break;i++,a++,l+=d.getBoundingClientRect().height}for(let d=0;d<i;d++)o[r+d]=l/i;r=a}return o}const gF=S("table-border-bar-dom"),pF=zi+ic+zi;function z9(n){const t=et(n.contentElement);g(gF,t,"no block");const o=te(t).querySelector(".table-border-bar-container.left"),r=Math.min(n.contentElement.offsetLeft+pF,n.rootElement.scrollLeft+zi);o&&(o.style.left=`${-r}px`)}const Qi=S("table-border-bar-dom");function Cc(n,t){g(Qi,Ve(t),"invalid table block");const e=_e(t),o=gr(n,t),r=te(t),i=(p,A,v)=>{const B=w("div",["button-root",A],p),D=w("div",["button-container",A],B);B.setAttribute(`data-${A}-index`,`${v}`),D.setAttribute(`data-editor-tooltip-${n.clientId}`,A==="left"?R.t("table.insertRow"):R.t("table.insertCol")),w("span",["insert-indicator"],D),fF(D)},{selectedRows:s,selectedColumns:l}=Np(n,t),a=()=>{const p=o.querySelector(".table-border-bar-container.top");g(Qi,p,"no top border bar container");const A=w("div",["table-border-bar-container","top"],null),v=w("div",["table-border-bar","top"],A),B=BR(e),x=Tt.fromTable(e).colCount;n.selection.range.isSimple()&&i(v,"top",0);for(let _=0;_<x;_++){const M=_===x-1?B[_]+2:B[_],H=w("span",["table-border-bar-cell","top"],v);l.has(_)&&H.classList.add("selected"),H.setAttribute("data-top-index",`${_}`),H.style.width=`${M}px`,n.selection.range.isSimple()&&i(v,"top",_+1)}Ca(p,A)},d=()=>{const p=r.querySelector(".table-border-bar-container.left");g(Qi,p,"no left border bar container");const A=w("div",["table-border-bar-container","left"],null),v=w("div",["table-border-bar","left"],A);w("span",["table-border-bar-cell","corner"],v);const B=U9(e);n.selection.range.isSimple()&&i(v,"left",0),Array.from(e.rows).forEach((D,x,_)=>{const M=w("span",["table-border-bar-cell","left"],v);s.has(x)&&M.classList.add("selected"),M.setAttribute("data-left-index",`${x}`);const H=x===_.length-1?B[x]+2:B[x];M.style.height=`${H}px`,n.selection.range.isSimple()&&i(v,"left",x+1)}),Ca(p,A)};a(),d();const h=n.findCustom(mr(t));h&&z9(h)}function V9(n,t){const e=t.target;if(!(e instanceof Element))return;const o=et(e);g(Qi,o&&Ve(o),"invalid table block"),Cc(n,o),n.selection.caret.update()}function vf(n,t){const e=t.target;if(!(e instanceof Element))return;const o=et(e);g(Qi,o&&Ve(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);Xv(n,o,i),Cc(n,o)}else if(r.classList.contains("left")){const i=parseInt(r.getAttribute("data-left-index")||"0",10);t9(n,o,i),Cc(n,o)}}}function yf(n,t){var s;j9(n),t.preventDefault(),t.stopPropagation();let e=null,o,r;const i=l=>{var a;if(l.target instanceof HTMLElement&&o&&e&&r!==void 0){const d=et(l.target),h=l.target.closest(".table-border-bar");if(d===e&&h){const p=parseInt((a=l.target.getAttribute(`data-${o}-index`))!=null?a:"0",10),A=Math.min(r,p),v=Math.abs(r-p)+1;xt(l.target,"top")&&o==="top"?NR(n,d,A,v,{reverse:!0}):xt(l.target,"left")&&o==="left"&&$R(n,d,A,v,{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&&xt(t.target,"table-border-bar-cell")&&(e=et(t.target),xt(t.target,"top")?o="top":xt(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 W9(n){const t=n.selection.range,e=lu(n,t);e&&Cc(n,e)}function CF(n,t){g(Qi,Ve(t),"invalid table block");const e=gr(n,t),o=te(t),r=w("div",["table-border-bar-container","top"],e),i=w("div",["table-border-bar-container","left"],o);Cc(n,t),n.domEvents.addEventListener(Lt(t),"scroll",V9),n.domEvents.addEventListener(r,"click",vf),n.domEvents.addEventListener(i,"click",vf),n.domEvents.addEventListener(r,"mousedown",yf),n.domEvents.addEventListener(i,"mousedown",yf),n.addListener("afterClearSelection",W9)}function q9(n,t){if(!n.isWritable())return;if(gr(n,t).querySelector(".table-border-bar-container")){Cc(n,t);return}CF(n,t)}function G9(n,t){g(Qi,Ve(t),"invalid table block");const e=gr(n,t),o=te(t),r=e.querySelectorAll(".table-border-bar-container"),i=o.querySelectorAll(".table-border-bar-container");r.forEach(s=>{n.domEvents.removeEventListener(s,"click",vf),n.domEvents.removeEventListener(s,"mousedown",yf),s.remove()}),i.forEach(s=>{n.domEvents.removeEventListener(s,"click",vf),n.domEvents.removeEventListener(s,"mousedown",yf),s.remove()}),n.domEvents.removeEventListener(Lt(t),"scroll",V9),n.addListener("afterClearSelection",W9)}function AF(n,t){g(Qi,Ve(t),"invalid table block");const o=gr(n,t).querySelector(".table-border-bar-container.top");return o?o.getBoundingClientRect().height:0}class bF{constructor(t,e){m(this,"toolbar");m(this,"handleSelectionChange",(t,e)=>{!t.isVisible||(e==="delete-columns"?(Vi(this.editor,this.tableBlock,!0,!0),Wi(this.editor,this.tableBlock,!0,!0)):e==="delete-rows"?(Vi(this.editor,this.tableBlock,!0,!1),Wi(this.editor,this.tableBlock,!0,!1)):(Vi(this.editor,this.tableBlock,!1),Wi(this.editor,this.tableBlock,!1)))});m(this,"handleClick",(t,e,o)=>{e.id==="delete-columns"?$p(this.editor.selection.range):e.id==="delete-rows"&&Hp(this.editor.selection.range)});m(this,"handleToolbarClose",()=>{this.tableBlock&&lu(this.editor,this.editor.selection.range)===this.tableBlock&&(Vi(this.editor,this.tableBlock,!1),Wi(this.editor,this.tableBlock,!1))});this.editor=t,this.tableBlock=e;const o=t.options.componentsOptions.popover;this.toolbar=new ru([],void 0,{id:"table-row-column-toolbar",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),this.toolbar.addListener("close",this.handleToolbarClose)}close(){this.toolbar.close("cancelBar")}update(){var r,i,s;const{selectedColumns:t,selectedRows:e}=Np(this.editor,this.tableBlock);if(!this.editor.isWritable())return;if(t.size>0&&e.size>0){this.toolbar.close("cancelBar");return}if(t.size===0&&e.size===0){this.toolbar.close("cancelBar");return}const o=Nr(this.editor,this.tableBlock,this.editor.selection.range)[0];if(!o){this.toolbar.close("cancelBar");return}if(t.size>0){const l={id:"delete-columns",name:R.t("table.deleteCol"),icon:yL};this.toolbar.updateItems([l]);const a=zr(this.editor,this.tableBlock,"table-row-column-delete",o);this.toolbar.manualShow(a,{placement:"top",offset:[0,5]})}else{const l={id:"delete-rows",name:R.t("table.deleteRow"),icon:vL};this.toolbar.updateItems([l]);const h=te(this.tableBlock).querySelector(".table-border-bar-container.left").getBoundingClientRect(),p=new DOMRect(Math.max(h.left,o.left-zi),o.top,zi,o.height),A=zr(this.editor,this.tableBlock,"table-row-column-delete",p);this.toolbar.manualShow(A,{placement:"left",offset:[0,5]});const v=this.editor.options.componentsOptions.popover;(r=this.toolbar.tippyInstance)==null||r.setProps({popperOptions:{modifiers:[{name:"flip",options:{boundary:v==null?void 0:v.overflowBoundary,fallbackPlacements:["left","right"]}}]}})}(s=(i=this.toolbar.tippyInstance)==null?void 0:i.popperInstance)==null||s.update()}destroy(){this.toolbar.destroy(),this.toolbar.removeAllListeners()}}const S0=S("table-border-bar");class vF{constructor(t,e){m(this,"toolbar");m(this,"resizeObserver");m(this,"handleReadonlyChanged",t=>{t.isWritable()?this.update():G9(this.editor,this.tableBlock)});m(this,"handleBlockUpdated",()=>{this.resizeObserver.disconnect(),setTimeout(()=>{const t=this.editor.getBlockById(it(this.tableBlock));this.resizeObserver.observe(_e(t))})});m(this,"handleScroll",()=>{this.toolbar.update()});m(this,"handleTableResize",()=>{!this.editor.isWritable()||(console.log("resize"),this.update())});this.editor=t,this.tableBlock=e,g(S0,this.tableBlock,"no table block"),S0.debug("create table border bar"),q9(this.editor,this.tableBlock),this.resizeObserver=new ResizeObserver(this.handleTableResize),this.resizeObserver.observe(_e(this.tableBlock)),this.toolbar=new bF(this.editor,this.tableBlock),this.editor.addListener("readonlyChanged",this.handleReadonlyChanged)}close(){this.toolbar.close()}destroy(){S0.debug("destroy table border bar"),this.resizeObserver.disconnect(),G9(this.editor,this.tableBlock),this.toolbar.destroy(),this.editor.removeListener("readonlyChanged",this.handleReadonlyChanged)}update(){q9(this.editor,this.tableBlock),this.toolbar.update()}}const yF=S("table-border-bar");class kF{constructor(t){m(this,"activeTableBar",null);m(this,"handleBlockDeleted",(t,e)=>{!this.activeTableBar||(e===this.activeTableBar.tableBlock||Xt(e,this.activeTableBar.tableBlock))&&(this.activeTableBar.destroy(),this.activeTableBar=null)});m(this,"handleSelectionChanged",t=>{var r;const e=t.selection.range,o=lu(t,e);((r=this.activeTableBar)==null?void 0:r.tableBlock)!==o&&this.activeTableBar&&this.hide(),o&&this.show(o)});m(this,"handleScroll",()=>{var t;(t=this.activeTableBar)==null||t.handleScroll()});this.editor=t,this.editor.addListener("blockDeleted",this.handleBlockDeleted),this.editor.addListener("selectionChanged",this.handleSelectionChanged)}destroy(){this.editor.removeListener("blockDeleted",this.handleBlockDeleted),this.editor.removeListener("selectionChanged",this.handleSelectionChanged)}show(t){this.activeTableBar?(this.activeTableBar.tableBlock!==t&&this.hide(),this.activeTableBar.update()):this.activeTableBar=new vF(this.editor,t)}update(){var t;(t=this.activeTableBar)==null||t.handleBlockUpdated()}closeToolbar(){var t;(t=this.activeTableBar)==null||t.close()}hide(){!this.activeTableBar||(g(yF,this.activeTableBar,"no active table bar"),this.activeTableBar.destroy(),this.activeTableBar=null)}}function Z9(n,t){const e=n.addCustom("table-border-bar",o=>new kF(o));t==="update"&&e.update()}const Mn=S("table-cell-menu"),wF="style-bg-color-";class BF{constructor(t){m(this,"activeTableBlock",null);m(this,"targetButton",null);m(this,"manualMenu",null);m(this,"colorPaletteItem",null);m(this,"handlePrevent",(t,e)=>{e.stopPropagation()});m(this,"handleReadonlyChanged",t=>{t.isWritable()||this.hide()});m(this,"handleSelectionChanged",t=>{const e=t.selection.range,o=lu(t,e);if(this.hide(),this.activeTableBlock!==o&&(this.activeTableBlock=o),this.activeTableBlock){const r=Tt.fromBlock(this.activeTableBlock),i=e.isReverse()?e.start:e.end;let s=null;i instanceof Mo?t.getBlockById(i.blockId)===this.activeTableBlock?s=r.getCellByContainerId(i.childContainerId):s=this.getCellByChildBlockId(r,i.blockId):s=this.getCellByChildBlockId(r,i.blockId),s&&this.editor.isWritable()&&this.showCellMenuButton(s)}});m(this,"handleBeforePopupPalette",()=>{var e;const t=this.getSelectedBkgColorIndex();(e=this.colorPaletteItem)==null||e.palette.setColor("backgroundColor",t)});m(this,"createBkgColorItem",()=>{const t=w("div",["cell-background-color-item"],null);w("span",[],t,R.t("table.cellBackground"));const e=this.getSelectedBkgColorIndex();w("button",["item-button"],t).setAttribute("data-color-index",`${e}`);const r=w("span",["item-sub-indicator"],t);return r.innerHTML=lv,t});m(this,"handleCommand",t=>{var r;g(Mn,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":Hp(Ov(this.editor,this.activeTableBlock,!1));break;case"delete-select-col":$p(Ov(this.editor,this.activeTableBlock,!0));break;case"merge-cell":Lv(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":qM(this.editor,this.activeTableBlock,o==="show-border");break;case"show-chart":JM(this.editor,this.activeTableBlock,o==="show-chart"),Yp(this.editor,this.activeTableBlock,{updateNow:!0});break}});m(this,"handleToolbarClose",()=>{this.targetButton&&ot(this.targetButton,"active"),this.activeTableBlock&&lu(this.editor,this.editor.selection.range)===this.activeTableBlock&&(Vi(this.editor,this.activeTableBlock,!1),Wi(this.editor,this.activeTableBlock,!1)),this.editor.focus()});m(this,"handleSelectionChange",(t,e)=>{!t.isVisible||(g(Mn,this.activeTableBlock,"no target table block"),e==="cell-background-color"&&this.handleBeforePopupPalette(),e==="delete-select-row"?(Vi(this.editor,this.activeTableBlock,!0,!1),Wi(this.editor,this.activeTableBlock,!0,!1)):e==="delete-select-col"?(Vi(this.editor,this.activeTableBlock,!0,!0),Wi(this.editor,this.activeTableBlock,!0,!0)):(Vi(this.editor,this.activeTableBlock,!1),Wi(this.editor,this.activeTableBlock,!1)))});m(this,"handleClick",(t,e)=>{var o;g(Mn,this.activeTableBlock,"no target table block"),g(Mn,this.targetButton,"no target button"),j9(this.editor),xt(this.targetButton,"active")?(ot(this.targetButton,"active"),(o=this.manualMenu)==null||o.close("clickItem")):(W(this.targetButton,"active"),this.manualMenu?this.manualMenu.updateItems(this.createCommandMenu()):(this.manualMenu=new zs(this.createCommandMenu()),this.manualMenu.on("click",(r,i)=>{var s;this.handleCommand(i),(s=this.manualMenu)==null||s.close("clickItem")}),this.manualMenu.on("selectionChange",this.handleSelectionChange),this.manualMenu.on("close",this.handleToolbarClose)),this.manualMenu.manualShow(this.targetButton,{placement:"right-start"})),e.stopPropagation()});this.editor=t,this.editor.addListener("selectionChanged",this.handleSelectionChanged),this.editor.addListener("readonlyChanged",this.handleReadonlyChanged)}destroy(){var t,e;this.activeTableBlock=null,this.targetButton=null,this.editor.removeListener("selectionChanged",this.handleSelectionChanged),this.editor.removeListener("readonlyChanged",this.handleReadonlyChanged),(t=this.manualMenu)==null||t.destroy(),(e=this.colorPaletteItem)==null||e.destroy()}hide(){var t;(t=this.manualMenu)==null||t.close("cancelBar"),this.targetButton&&(ot(this.targetButton,"active"),this.targetButton.style.display="none")}getCellByChildBlockId(t,e){let o=this.editor.getBlockById(e);for(;o;){const r=o.closest("td");g(Mn,r,"no parent cell");const i=et(r);if(g(Mn,i,"no parent block"),_e(i)===t.table)return t.getCellByCellElement(r);o=i}return g(Mn,!1,"filed to get cell by child block id"),null}createTargetButton(t){this.targetButton?t.querySelector(`:scope > .${qp}`)||t.appendChild(this.targetButton):(this.targetButton=w("button",[qp],t),this.targetButton.innerHTML=Qh,this.editor.domEvents.addEventListener(this.targetButton,"click",this.handleClick),this.editor.domEvents.addEventListener(this.targetButton,"mousedown",this.handlePrevent),this.editor.domEvents.addEventListener(this.targetButton,"dblclick",this.handlePrevent))}showCellMenuButton(t){this.createTargetButton(t.cell),g(Mn,this.targetButton,"no target button"),this.targetButton.style.display="inline-block"}handleSplitCell(){if(this.activeTableBlock){const t=Tt.fromBlock(this.activeTableBlock),e=this.editor.selection.range;if(e.isSimple()){const{col:o,row:r}=this.getCellByChildBlockId(t,e.start.blockId);Up(this.editor,this.activeTableBlock,{col:o,row:r})}else zp(this.editor.selection.range)}}getSelectedBkgColorIndex(){var r;g(Mn,this.activeTableBlock,"no target table block");const t=QM(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=at(i),l=e[`${s}_background`];if(l)o.add(Number.parseInt((r=l.substring(wF.length))!=null?r:"0",10));else{o.add(-1);break}}return o.size===1&&[...o][0]!==-1?[...o][0]:-1}createCommandMenu(){g(Mn,this.activeTableBlock,"no target table block");const t=this.editor.getBlockData(this.activeTableBlock),e=Sv(this.editor,this.activeTableBlock,this.editor.selection.range);let o=this.editor.selection.range;if(o.isSimple()){const h=Jr(this.editor,this.activeTableBlock,o.start);o=Ue(this.editor,{anchor:h,focus:h})}const r=Dv(this.editor,this.activeTableBlock,o),i=t.hasRowTitle,s=t.hasColTitle,l=t.isStripeStyle,a=t.noBorder,d=t.chart;return this.colorPaletteItem=new wv("cell-background-color",{color:!1}),this.colorPaletteItem.palette.on("onClick",(h,p)=>{var A;switch(g(Mn,this.activeTableBlock,"no target table block"),h){case"clearColor":Pv(this.editor,this.activeTableBlock,-1);break;case"backgroundColor":Pv(this.editor,this.activeTableBlock,p);break}(A=this.manualMenu)==null||A.close("clickItem")}),[{id:"cell-background-color",name:R.t("table.cellBackground"),element:this.createBkgColorItem(),children:[this.colorPaletteItem]},{id:"separator",name:"",type:"separator"},{id:"merge-cell",name:R.t("table.mergeCell"),states:e?[]:["disabled"]},{id:"split-cell",name:R.t("table.splitCell"),states:r?[]:["disabled"]},{id:"separator",name:"",type:"separator"},{id:"delete-select-row",name:R.t("table.deleteSelectRow")},{id:"delete-select-col",name:R.t("table.deleteSelectCol")},{id:"separator",name:"",type:"separator"},{id:"table-config",name:R.t("table.tableConfigKey"),children:[{id:"row-title",name:R.t("table.tableConfig.rowTitle"),states:i?["checked"]:[]},{id:"col-title",name:R.t("table.tableConfig.colTitle"),states:s?["checked"]:[]},{id:"stripe-style",name:R.t("table.tableConfig.stripeStyle"),states:l?["checked"]:[]},{id:"hide-border",name:a?R.t("table.tableConfig.showBorder"):R.t("table.tableConfig.hideBorder"),value:a?"show-border":"hide-border"},{id:"show-chart",name:d?R.t("table.tableConfig.hideChart"):R.t("table.tableConfig.showChart"),value:d?"hide-chart":"show-chart"}]}]}handleRowTitle(t){g(Mn,this.activeTableBlock,"no target table block"),t?zM(this.editor,this.activeTableBlock):UM(this.editor,this.activeTableBlock)}handleColTitle(t){g(Mn,this.activeTableBlock,"no target table block"),t?jM(this.editor,this.activeTableBlock):HM(this.editor,this.activeTableBlock)}handleStripeStyle(t){g(Mn,this.activeTableBlock,"no target table block"),t?WM(this.editor,this.activeTableBlock):VM(this.editor,this.activeTableBlock)}}function Q9(n){n.addCustom("table-cell-menu",t=>new BF(t))}const kf=S("table-container");function L0(n){const t=n.closest("td");return g(kf,t,"no parent cell for a table cell container"),t}function Y9(n){const t=_e(n);return Array.from(t.querySelectorAll(':scope > tbody > tr > td > [data-type="editor-container"].child'))}function M0(n,t,e,o){const r=Tt.fromBlock(n),i=r.getCellByContainerId(at(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(g(kf,l>=0,"not a valid child container"),l===0)return null;const a=s[l-1];return o!=null&&o.noWrap&&r.getCellByContainerId(at(a)).row!==i.row?null:a}if(e==="ArrowRight"){const s=r.getAllContainers(),l=s.indexOf(t);if(g(kf,l>=0,"not a valid child container"),l===s.length-1)return null;const a=s[l+1];return o!=null&&o.noWrap&&r.getCellByContainerId(at(a)).row!==i.row?null:a}g(kf,!1,`invalid navigation type: ${e}`)}const EF=12,xF=90,wf=23,J9=2;class IF{constructor(t){m(this,"scrollTableBlock",null);m(this,"autoScrollDir",null);m(this,"autoScrollTimer",null);m(this,"handleMouseDown",t=>{const e=document.elementFromPoint(t.clientX,t.clientY);if(e&&e instanceof HTMLElement){const o=et(e);if(o&&Xt(this.editor.rootContainer,o)){const r=Yr(o);r&&(this.scrollTableBlock=r,document.addEventListener("mousemove",this.handleAutoScroll))}}});m(this,"handleAutoScroll",QB.default(t=>{if(this.scrollTableBlock){const e=this.editor.getCustom(mr(this.scrollTableBlock)),o=e.rootElement,r=e.scrollOptions.parentContainer,i=o.getBoundingClientRect(),s=window.innerHeight-this.getBarFloatWindowBottom(e),l=r.getBoundingClientRect(),a=Math.min(l.bottom,s),d=Math.max(l.top,0);i.bottom>a&&t.clientY>=a?this.setAutoScroll("bottom"):i.top<d&&t.clientY<=d?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));m(this,"handleMouseUp",()=>{document.removeEventListener("mousemove",this.handleAutoScroll),setTimeout(()=>{this.scrollTableBlock=null})});m(this,"handleSelectionChanged",t=>{const e=t.selection.range;if(e.isCollapsed()&&e.isSimple()){const o=t.getBlockById(e.start.blockId),r=Yr(o);if(r){const i=t.getCustom(mr(r)),s=i.rootElement.getBoundingClientRect(),l=So(t,o,e.start);if(s.left>l.left){const a=e.start.offset===0?EF:J9;i.rootElement.scrollLeft-=s.left-l.left+a}else if(l.right>s.right){const a=e.start.offset===0?xF:J9;i.rootElement.scrollLeft+=l.right-s.right+a}}}else{const o=t.getBlockById(e.start.blockId),r=Yr(o),i=t.getBlockById(e.end.blockId),s=Yr(i);if(r&&r===s){const l=t.getCustom(mr(r)),a=l.rootElement.getBoundingClientRect();let d=null;if(e.isSimple())d=e.isReverse()?So(t,o,e.start):So(t,i,e.end);else{const h=L0(jr(t,e.start.childContainerId)),p=L0(jr(t,e.end.childContainerId));d=e.isReverse()?h.getBoundingClientRect():p.getBoundingClientRect()}a.left>d.left&&e.isReverse()?l.rootElement.scrollLeft-=a.left-d.left:a.right<d.right&&!e.isReverse()&&(l.rootElement.scrollLeft+=d.right-a.right)}}});m(this,"handleScroll",t=>{xv(t),this.editor.selection.caret.update()});m(this,"handleReset",t=>{xv(t),this.editor.selection.caret.update();const e=this.editor.findCustom("table-border-bar");e&&e.handleScroll(),z9(t)});this.editor=t,this.editor.addListener("selectionChanged",this.handleSelectionChanged),document.addEventListener("mousedown",this.handleMouseDown),document.addEventListener("mouseup",this.handleMouseUp)}getBarFloatWindowBottom(t){return t.scrollOptions.barFloatWindowBottom?typeof t.scrollOptions.barFloatWindowBottom=="number"?t.scrollOptions.barFloatWindowBottom:t.scrollOptions.barFloatWindowBottom():0}clearAutoScroll(){this.autoScrollTimer&&(clearInterval(this.autoScrollTimer),this.autoScrollTimer=null,this.autoScrollDir=null)}setAutoScroll(t){this.autoScrollDir&&this.autoScrollDir!==t&&this.clearAutoScroll(),this.autoScrollTimer||(this.autoScrollDir=t,this.autoScrollTimer=window.setInterval(()=>{if(this.scrollTableBlock){const e=this.editor.getCustom(mr(this.scrollTableBlock)),o=e.rootElement,r=e.scrollOptions.parentContainer,i=o.getBoundingClientRect(),s=r===document.documentElement?window.innerHeight:r.offsetHeight,l=window.innerHeight-this.getBarFloatWindowBottom(e),a=r.getBoundingClientRect(),d=Math.min(a.bottom,l),h=Math.max(a.top,0);this.autoScrollDir==="left"&&(o.scrollLeft-=wf,o.scrollLeft<=0&&this.clearAutoScroll()),this.autoScrollDir==="right"&&(o.scrollLeft+=wf,o.scrollLeft>=o.scrollWidth-o.offsetWidth&&this.clearAutoScroll()),this.autoScrollDir==="bottom"&&(r.scrollTop+=wf,(r.scrollTop>=r.scrollHeight-s||i.bottom<=d)&&this.clearAutoScroll()),this.autoScrollDir==="top"&&(r.scrollTop-=wf,(r.scrollTop<=0||i.top>=h)&&this.clearAutoScroll())}},100))}destroy(){document.removeEventListener("mousedown",this.handleMouseDown),document.removeEventListener("mouseup",this.handleMouseUp),this.editor.removeListener("selectionChanged",this.handleSelectionChanged)}}function K9(n){return n.addCustom("table-scroll-events",t=>new IF(t))}const pr=S("create-content");function X9(n,t,e){const o=new Yh(e),r=e.rows,i=e.cols;g(pr,r>=1,`invalid rows: ${r}`),g(pr,i>=1,`invalid cols: ${i}`),g(pr,e.children,"no table children");const s=w("table",[],null),l=e.colsWidth,a=w("colgroup",[],s);for(let p=0;p<o.colCount;p++){const A=w("col",[],a);l[p]&&(A.style.width=`${l[p]}px`)}const d=w("tbody",[],s);let h=0;for(let p=0;p<r;p++){const A=w("tr",[],d);for(let v=0;v<i;v++){const B=o.getCell({col:v,row:p});if(B.virtual)g(pr,B.colSpan>1||B.rowSpan>1,"virtual cell should have colSpan or rowSpan");else{const D=e.children[h],x=w("td",[],A);B.colSpan>1&&(x.colSpan=B.colSpan),B.rowSpan>1&&(x.rowSpan=B.rowSpan);const _=e[au(D)];_&&W(x,_),v===0&&e.hasColTitle&&W(x,Mv.COL_TITLE_ITEM),n.createChildContainer(t,x,D),h+=1}}}return g(pr,h===e.children.length,"container count mismatch"),e.noBorder&&W(s,"no-border"),e.chart&&W(s,"editor-table-chart"),e.isStripeStyle&&W(s,"stripe"),e.hasRowTitle&&W(s,"row-title"),e.hasColTitle&&W(s,"col-title"),s}function TF(n,t,e,o,r){g(pr,r.type==="table","not table data"),g(pr,at(e)===t[t.length-1].containerId,"invalid path");const i=r,s=Is(o,"div");try{const l=w("div",[],null);l.setAttribute("data-type","table-content");const a=X9(n,t,i);a.classList.add("drag-preview-element"),l.appendChild(a),Jv(n),n9(n),Z9(n,"create"),Q9(n),cL(n,Jp);const d=n.getComponentOptions("table"),h=n.addCustom(mr(o),()=>kR());h.init({parentElement:s,childElement:l,safeRightSpace:50,safeLeftSpace:40,parentContainer:Yt(e)?n.scrollContainer:e,locatingContainer:Yt(e)?(d==null?void 0:d.locatingContainer)||n.parent:e,paddingLeft:zi+ic,paddingTop:zi+ic,paddingBottom:ic/2,paddingRight:ic/2,barFloatWindowBottom:d==null?void 0:d.barFloatWindowBottom,isSetScale:d==null?void 0:d.isSetScale});const p=K9(n);h.on("scroll",p.handleReset),h.on("resize",p.handleReset),setTimeout(()=>{tR(n,o)})}catch{const a=`invalid table data: ${JSON.stringify(i)}`;pr.error(a);const d=w("div",["error"],s);d.innerText=a}return s}function DF(n,t,e){g(pr,e.type==="table","not table data");const o=e,r=Lt(t);try{const i=_e(t),s=Li(t),l=X9(n,s,o);l.classList.add("drag-preview-element"),i.insertAdjacentElement("afterend",l),i.remove(),Jv(n),n9(n),Z9(n,"update"),Q9(n),Jp(n,t)}catch{const s=`invalid table data: ${JSON.stringify(o)}`;pr.error(s);const l=w("div",["error"],r);l.innerText=s}}function SF(n,t){let e,o,r=!1;if([...t].every(A=>A==="|")?(o=t.length,e=Array(o).fill(""),r=!0):(e=wm(t,"|").split("|"),o=e.length),o<2)return null;const i=3,s=o,l=[];for(let A=0;A<3;A++)e.forEach(v=>{l.push(qr(n.doc,A===0?v:""))});const a=Array(s).fill(t0),d=l[r?0:s],h=n.doc.getContainerBlocks(d)[0].id;return{blockData:{id:K(),type:"table",rows:i,cols:s,children:l,colsWidth:a},focusBlockId:h}}function LF(n,t){const e=t.rows,o=t.cols;if(e<1||o<1)return null;const r=[];for(let d=0;d<e;d++)for(let h=0;h<o;h++)r.push(qr(n.doc));const i=Array(o).fill(t0),s=r[0],l=n.doc.getContainerBlocks(s)[0].id;return{blockData:{id:K(),type:"table",rows:e,cols:o,children:r,colsWidth:i},focusBlockId:l}}const t7=S("table-selection-to-doc");function MF(n,t){const{start:e,end:o,block:r}=t,i=Dt(r);g(t7,i==="table",`invalid block type: ${i}`);const s=n.getBlockData(r);if(e.isSimple()&&o.isSimple())return Fi(n.editorBlocks,n.doc.toJSON(),s);g(t7,!e.isSimple()&&!o.isSimple(),"invalid block pos type");const l=Tt.fromBlock(r),{fromCol:a,toCol:d,fromRow:h,toRow:p}=Uo(r,e,o),A={},v=[],B=n.doc.toJSON();let D={};l.sub({row:h,col:a},{row:p,col:d}).forEach((rt,ft)=>{rt.forEach((Bt,jt)=>{const Ut=Bt.containerId;if(v.indexOf(Ut)!==-1)return;v.push(Ut);let ne;if(Bt.virtual){const $e=l.getCellByContainerId(Bt.containerId),Rn=a+jt;let wr=$e.col+$e.colSpan-1;wr>d&&(wr=d);const vn=wr-Rn+1;vn>1&&(A[`${Ut}_colSpan`]=vn);const an=h+ft;let Br=$e.row+$e.rowSpan-1;Br>p&&(Br=p);const oi=Br-an+1;oi>1&&(A[`${Ut}_rowSpan`]=oi),ne=Wr()}else{if(ne=_g(n.editorBlocks,B,Ut),Bt.col+Bt.colSpan>d+1){const $e=d-Bt.col+1;$e>1&&(A[`${Ut}_colSpan`]=$e)}else Bt.colSpan>1&&(A[`${Ut}_colSpan`]=Bt.colSpan);if(Bt.row+Bt.rowSpan>p+1){const $e=p-Bt.row+1;$e>1&&(A[`${Ut}_rowSpan`]=$e)}else Bt.rowSpan>1&&(A[`${Ut}_rowSpan`]=Bt.rowSpan)}const{root:qe,...Yn}=ne.blocks;D={...D,...Yn,[Ut]:qe}})});const _=mu(_e(r)).slice(a,d+1);return{blocks:{root:[{id:K(),type:i,children:v,colsWidth:_,rows:p-h+1,cols:d-a+1,...A}],...D},meta:{},comments:{}}}function RF(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 OF(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 _F(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 FF(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 PF(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 a=!1;do{if(a=!1,!RF(n,l)){l.top--,a=!0;continue}if(!OF(n,l)){l.left--,a=!0;continue}if(!_F(n,l)){l.bottom++,a=!0;continue}if(!FF(n,l)){l.right++,a=!0;continue}}while(a);return l}function NF(n,t,e,o){if(e.custom!==void 0||o.custom!==void 0)return{anchor:e,focus:o};const r=Tt.fromBlock(t),i=r.map(H=>H.containerId),s=r.getCellByContainerId(e.childContainerId),l=r.getCellByContainerId(o.childContainerId),a=Math.min(s.row,l.row),d=Math.max(s.row,l.row),h=Math.min(s.col,l.col),p=Math.max(s.col,l.col),A=PF(i,{row:a,col:h},{row:d,col:p}),v=r.getCell({row:A.top,col:A.left}),B=r.getCell({row:A.bottom,col:A.right}),D=r.getCell({row:A.top,col:A.right}),x=r.getCell({row:A.bottom,col:A.left});let _,M;return s.row<=l.row?s.col<=l.col?(_=v,M=B):(_=D,M=x):s.col<l.col?(_=x,M=D):(_=B,M=v),console.log(`move ${_.col}, ${_.row}, -> ${M.col}, ${M.row}`),{anchor:fe(t,_.containerId),focus:fe(t,M.containerId)}}function e7(n,t,e){if(e.isSimple())return[_e(t).getBoundingClientRect()];const o=_e(t),r=o.getBoundingClientRect(),{fromCol:i,fromRow:s,toCol:l,toRow:a}=Uo(t,e.start,e.end),d=mu(o),h=d.slice(0,i).reduce((D,x)=>D+x,0),p=h+d.slice(i,l+1).reduce((D,x)=>D+x,0),A=U9(o);let v=A.slice(0,s).reduce((D,x)=>D+x,0);const B=v+A.slice(s,a+1).reduce((D,x)=>D+x,0);if(s===0){const D=AF(n,t);v-=D}return[new DOMRect(r.left+h,r.top+v,p-h,B-v)]}S("table-size");const $F=40;function Bf(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 HF(n,t,e){const o=Gm(n,e.container);return o!==void 0?o+Bf(t):$F*e.colSpan-Bf(t)}function jF(n,t,e,o){let r=0;const i=e.colCount;for(let s=0;s<i;s++){const l=e.getCell({col:s,row:o});if(l.virtual)continue;let a=HF(n,t,l);const d=b4(l.container,{withPadding:!0});d&&d>a&&(a=d),r+=a+Bf(t)}return r}function UF(n,t){const e=_e(t),o=Tt.fromTable(e);let r=0;for(let s=0;s<o.rowCount;s++)r=Math.max(r,jF(n,e,o,s));const i=Bf(e);return r+=i,r}const Kr=S("table-creator");async function zF(n,t){return n.undoManager.runInGroup(()=>{var a,d;const e=t.item,o=(a=e.colCount)!=null?a:5,r=(d=e.rowCount)!=null?d:3,i=LF(n,{cols:o,rows:r});if(!i)return null;const{blockData:s,focusBlockId:l}=i;return n.insertBlock(t.containerId,t.blockIndex,s,Ce(n,l,0))})}class VF{constructor(){m(this,"id","insert-table");m(this,"name","Create table");m(this,"element");m(this,"closeable",null);m(this,"colCount");m(this,"rowCount");m(this,"setCloseable",t=>{this.closeable=t});m(this,"destroy",()=>{this.closeable=null});m(this,"getTableCreatorCellId",(t,e)=>`table-creator-cell-${t}-${e}`);m(this,"handleTableCreatorClick",t=>{var A,v;t.preventDefault(),t.stopPropagation();const e=t.target;g(Kr,e instanceof HTMLElement,"invalid event target");const o=e.closest(".table-creator");g(Kr,o,"no table creator");const r=o.querySelectorAll(".active");if(r.length===0)return;const s=r[r.length-1].id;g(Kr,s,"no cell id");const l="table-creator-cell-";if(!s.startsWith(l))return;const d=s.substring(l.length).split("-");g(Kr,d.length===2,"invalid cell id");const h=Number.parseInt(d[0],10)+1,p=Number.parseInt(d[1],10)+1;Kr.debug(`${h}, ${p}`),this.colCount=p,this.rowCount=h,(A=this.closeable)==null||A.click(this,this.element),(v=this.closeable)==null||v.close("clickItem"),this.handleTableCreatorLeave()});m(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&&ot(r,"active")}});m(this,"handleTableCreatorCellEnter",t=>{const e=t.target;g(Kr,e instanceof HTMLElement,"invalid event target");const o=e.id,r="table-creator-cell-";g(Kr,o.startsWith(r),"invalid cell id");const s=o.substring(r.length).split("-");g(Kr,s.length===2,"invalid cell id");let l=Number.parseInt(s[0],10),a=Number.parseInt(s[1],10);l===0&&a===0&&(l=-1,a=-1);for(let d=0;d<9;d++)for(let h=0;h<9;h++){const p=this.getTableCreatorCellId(d,h),A=document.getElementById(p);g(Kr,A,"no cell"),d<=l&&h<=a?W(A,"active"):ot(A,"active")}});this.element=this.createTableCreatorElement()}createTableCreatorElement(){const t=w("div",["table-creator"],null),e=(o,r,i)=>{const s=w("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=w("div",["table-creator-row"],t);for(let i=0;i<9;i++)e(r,o,i).addEventListener("mouseenter",this.handleTableCreatorCellEnter)}return t}}function WF(){return new VF}function qF(n){const t=/[\u4e00-\u9fff\u3040-\u309f\u30a0-\u30ff\uac00-\ud7af]/g,e=n.match(t);return e?e.length:0}function n7(n){const t=qF(n);return n.length+t}function GF(n,t){const e=n7(n),o=t-e;return o>0?n+" ".repeat(o):n}function ZF(n,t,e,o,r){const i=t,s=new Yh(i);if(o==="markdown"||o==="text"){const l=x=>e.blocks[x].map((H,z)=>o==="markdown"?Eg(n,H,e,[...r,{containerId:x,blockIndex:z}]):vh(n,H,e,[...r,{containerId:x,blockIndex:z}])),a=x=>l(x).join(" ").replace(/\n/g," ").trim(),d=new Map,h=new Map;for(let x=0;x<s.colCount;x++){let _=0;for(let M=0;M<s.rowCount;M++){const H=s.getCell({row:M,col:x});let z="";H.virtual||(z=a(H.containerId)),d.set(`${M},${x}`,z),_=Math.max(_,n7(z))}h.set(x,_)}const p=x=>{const _=d.get(`${x.row},${x.col}`)||"",M=h.get(x.col)||0;return GF(_,M)},A=[];let v="|",B="|";for(let x=0;x<s.colCount;x++){const _=p({row:0,col:x});v+=` ${_} |`;const M="-".repeat((h.get(x)||0)+2);B+=`${M}|`}A.push(v),A.push(B);for(let x=1;x<s.rowCount;x++){let _="|";for(let M=0;M<s.colCount;M++){const H=p({row:x,col:M});_+=` ${H} |`}A.push(_)}return`${A.join(`
|
|
400
400
|
`)}
|
|
401
401
|
`}if(o==="html"){const l=d=>e.blocks[d].map((A,v)=>Bg(n,A,e,[...r,{containerId:d,blockIndex:v}])).join(`
|
|
402
402
|
`),a=[];a.push("<table>");for(let d=0;d<s.rowCount;d++){let h="<tr>";for(let p=0;p<s.colCount;p++){const A=s.getCell({row:d,col:p});if(!A.virtual){const v=l(A.containerId);h+=`<td colSpan="${A.colSpan}" rowSpan="${A.rowSpan}">${v}</td>`}}h+="</tr>",a.push(h)}return a.push("</table>"),a.join(`
|
|
403
|
-
`)}return""}const Au=S("table-block");function QF(n){return 1}function YF(n){return!!n.closest(`.${qp}`)}function JF(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(YF(r)&&(i=r.closest("td"),g(Au,i instanceof HTMLTableCellElement,"invalid element")),i instanceof HTMLTableCellElement){const a=_e(t);if(Bv(a).indexOf(i)!==-1){const h=su(i),p=fe(t,at(h));return new rr(n,{anchor:p,focus:p})}}if(!Pr(r))return null;const s=r;if(Y9(t).indexOf(s)===-1)return null;const l=fe(t,at(s));return new rr(n,{anchor:l,focus:l})}function KF(n,t,e,o){return null}function XF(n,t){return n.getBoundingClientRect()}function o7(n,t,e,o){if(e.isSimple()){g(Au,o.isSimple(),"from is simple position but to is not simple position"),Au.debug("full select table"),W(t,"full-selected");return}g(Au,!o.isSimple(),"from is complex position but end is simple position");const r=Jr(n,t,e),i=Jr(n,t,o);g(Au,r.blockId===i.blockId,"only allow update one table selection"),GM(n,r,i).forEach(l=>{const a=L0(l);W(a,"selected")})}function tP(n){n.rootContainer.querySelectorAll('[data-type="editor-block"][data-block-type="table"]').forEach(t=>{ot(t,"full-selected"),t.querySelectorAll("td.selected").forEach(e=>{ot(e,"selected")})})}function eP(n,t){return Ev(t)?Y9(t):[]}function nP(n,t,e,o,r){return M0(t,e,o,r)}function oP(n,t){return UF(n,t)}function rP(n,t){return tt(n,t)?SF(n,n.getBlockString(t).trim()):null}function iP(n){return{name:"TableBlock",insertBlockCommandItems:[{id:"insert-table",name:R.t("table.title"),order:200,icon:_L,children:[WF()],group:"common",subText:Cn("insert-table")}],handleInsertEmptyBlock:zF}}function sP(n,t,e){return DF(n,t,e),setTimeout(()=>{const o=n.selection.range;o.isSimple()?n.selection.caret.update():o7(n,t,o.start,o.end)}),!0}function lP(n,t){let e=0;const{selectedColumns:o}=Np(n,t);if(o.size>0){const{fromCol:i,toCol:s}=Uo(t,n.selection.range.start,n.selection.range.end),l=Tt.fromBlock(t);(i!==0||s!==l.colCount-1)&&(e=60)}const r=e7(n,t,n.selection.range)[0];return new DOMRect(r.left,r.top+e,r.width,Math.max(r.height-e*2,0))}function cP(n,t){aL(n,Jp);const e=n.findCustom(fr(t));if(e){const o=K9(n);e.off("scroll",o.handleReset),e.off("resize",o.handleReset),e.destroy()}}function aP(){return{abstract:`${R.t("table.abstract")}`}}const Ef={blockType:"table",blockKind:"complex",enableKeyboardSelect:!0,createBlockContent:TF,getBlockTextLength:QF,getRangeFromPoint:JF,moveCaret:KF,getCaretRect:XF,updateSelection:o7,clearSelection:tP,getChildContainers:eP,getNextContainer:nP,getMinWidth:oP,getSelectedContainers:Zp,convertFrom:rP,convertTo:ZF,adjustSelectionPos:NF,getClientRects:e7,selectionToDoc:MF,getOptions:iP,getTextToolbarReferenceClient:lP,handleUpdateBlock:sP,handleDeleteBlock:cP,getBlockProperties:aP},uP={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"}},dP={table:{cellBackground:"Cell background color",deleteSelectRow:"Delete selected rows",deleteSelectCol:"Delete selected columns",mergeCell:"Merge cells",splitCell:"Split cell",tableConfigKey:"Table settings",deleteTable:"Delete table",insertCol:"Insert column",insertRow:"Insert row",deleteCol:"Delete column",deleteRow:"Delete row",tableConfig:{rowTitle:"Row header",colTitle:"Column header",stripeStyle:"Stripe style",hideBorder:"Hide border",showBorder:"Show border",showChart:"Show chart",hideChart:"Hide chart"},title:"Table",abstract:"Table"}},hP={table:{cellBackground:"\u30BB\u30EB\u306E\u80CC\u666F\u8272",deleteSelectRow:"\u9078\u629E\u3057\u305F\u884C\u3092\u524A\u9664",deleteSelectCol:"\u9078\u629E\u3057\u305F\u5217\u3092\u524A\u9664",mergeCell:"\u30BB\u30EB\u3092\u7D50\u5408",splitCell:"\u30BB\u30EB\u306E\u7D50\u5408\u3092\u89E3\u9664",tableConfigKey:"\u30C6\u30FC\u30D6\u30EB\u8A2D\u5B9A",deleteTable:"\u30C6\u30FC\u30D6\u30EB\u3092\u524A\u9664",insertCol:"\u5217\u3092\u633F\u5165",insertRow:"\u884C\u3092\u633F\u5165",deleteCol:"\u5217\u3092\u524A\u9664",deleteRow:"\u884C\u3092\u524A\u9664",tableConfig:{rowTitle:"\u884C\u898B\u51FA\u3057",colTitle:"\u5217\u898B\u51FA\u3057",stripeStyle:"\u7E1E\u6A21\u69D8",hideBorder:"\u67A0\u7DDA\u3092\u975E\u8868\u793A",showBorder:"\u67A0\u7DDA\u3092\u8868\u793A",showChart:"\u30B0\u30E9\u30D5\u3092\u8868\u793A",hideChart:"\u30B0\u30E9\u30D5\u3092\u975E\u8868\u793A"},title:"\u30C6\u30FC\u30D6\u30EB",abstract:"\u30C6\u30FC\u30D6\u30EB"}};R.mergeLang({"zh-CN":uP,"en-US":dP,"ja-JP":hP});const Snt="",r7=S("table");function i7(n,t){const e=Pp(t);if(!e)return;const o=et(e);g(r7,o&&Ve(o),"not a table block");const r=M0(o,e,"ArrowRight");if(!r){const s=Zt(o);return s?(n.selection.selectBlock(s,0),!0):i7(n,o)}const i=xe(r);return n.selection.selectBlock(i,0),!0}function fP(n){if(!n.isWritable())return!1;const t=n.getFocusedBlock();if(!!t)return i7(n,t)}function s7(n,t){const e=Pp(t);if(!e)return;const o=et(e);g(r7,o&&Ve(o),"not a table block");const r=M0(o,e,"ArrowLeft");if(!r){const s=ce(o);return s?(n.selection.selectBlock(s,ut(n,s)),!0):s7(n,o)}const i=Qe(r);return n.selection.selectBlock(i,ut(n,i)),!0}function mP(n){if(!n.isWritable())return!1;const t=n.getFocusedBlock();if(!!t)return s7(n,t)}const R0={Tab:fP,"Shift+Tab":mP};function gP(n,t,e,o){const r=n.getBlockByIndex(t,e);if(ut(n,r)!==o)return!1;const i=ie(n.getBlockText(r));if(![...i].every(h=>h==="|")||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:a,focusBlockId:d}=l;return a?(n.undoManager.runInGroup(()=>{var p;const h=n.insertBlock(t,e,a,Ce(n,d!=null?d:a.id,0));n.deleteBlock(r),(p=l.onConverted)==null||p.call(l,n,h)}),!0):!1}const pP={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"}}},CP={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 l7(n,t,e,o,r){if(r==="enter"&&gP(n,t,e,o))return!0;const i=n.getBlockByIndex(t,e),s=ie(In(n.getBlockText(i),o).left).trim(),l=r==="enter"?pP:CP;for(const[,a]of Object.entries(l)){if(!s.match(a.reg))continue;return!!n.undoManager.runInGroup(()=>{var B;const h=th(n,i,a.blockType,{offset:o,data:a.data});if(!h)return null;const{blockData:p,focusBlockId:A}=h;if(!p)return null;const v=n.insertBlock(t,e,p,Ce(n,A!=null?A:p.id,0));return n.deleteBlock(i),(B=h.onConverted)==null||B.call(h,n,v),{newBlock:v,focusBlockId:A}})}return!1}function AP(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},Ce(n,r,0))}),!0)}const bP={"#":1,"##":2,"###":3,"####":4,"#####":5,"######":6,"#######":7,"########":8};function vP(n,t,e,o){const r=n.getBlockByIndex(t,e),i=n.getBlockString(r,{boxReplacement:" "}).substring(0,o);let s=bP[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},Ce(n,r,0))}),!0}function yP(n,t,e,o){return!!(vP(n,t,e,o)||AP(n,t,e,o))}const kP=S("match-text-style");function wP(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 BP={"*":{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 EP(n,t,e,o){var A,v;const r=n.getBlockByIndex(t,e),i=n.getBlockText(r),{left:s}=In(i,o),l=fg(s),a=rn(s)-l.length,d=Object.entries(BP);for(const[B,D]of d){const x=wP(l,B);if(x===-1)continue;const _=a+x,M=o,H=B.length,z=ie(ze(i,_+H,M-_-H*2).middle);if(D.type==="style"){const q={};D.styles.forEach(ft=>{q[ft]=!0});const rt=Oi(z,q);n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,_,M-_),n.insertTextToBlock(r,_,rt)})}else if(D.type==="box")try{const q=(v=(A=n.editorBoxes.getBoxClass(D.boxType)).convertFrom)==null?void 0:v.call(A,n,z);if(!q)continue;n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,_,M-_),n.insertBoxToBlock(r,_,q)})}catch(q){kP.warn(`failed to convert to box, ${q.message}`);continue}return!0}const h=/\[([^\]]+)\]\((https?:\/\/\S+)\)\s*$/,p=l.match(h);if(p){const B=p.index,D=p[1],x=p[2],_=B,M=o,z={...Da(i,_),link:x};return n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,_,M-_),n.insertTextToBlock(r,_,Oi(D,z))}),!0}return!1}class xf{handleAfterInsertText(t,e,o,r,i){return!!(i===" "&&(yP(t,e,o,r)||EP(t,e,o,r)))}handleBeforeKeyDown(t,e){if(!t.selection.range.isSimple())return!1;const{containerId:r,blockIndex:i,offset:s}=t.getTextPosition();if(tt(t,t.getBlockByIndex(r,i))){if(_r(e,"Enter")){if(l7(t,r,i,s,"enter"))return!0}else if(_r(e,"Space")&&l7(t,r,i,s,"space"))return!0}return!1}}const xP={"en-US":{placeholder:{default:"Type / for commands",heading:"Title {heading}",list:"List",mention:"Quickly assign tasks and use @ to mention yourself or others",quote:"Quote",title:"Enter document title"}},"zh-CN":{placeholder:{default:"\u8F93\u5165\u300C/\u300D\u5FEB\u901F\u63D2\u5165",heading:"\u6807\u9898{heading}",list:"\u5217\u8868",mention:"\u5FEB\u901F\u5206\u914D\u4EFB\u52A1\uFF0C@\u63D0\u53CA\u81EA\u5DF1\u6216\u4ED6\u4EBA",quote:"\u5F15\u7528",title:"\u8BF7\u8F93\u5165\u6587\u6863\u6807\u9898"}},"ja-JP":{placeholder:{default:"\u300C/\u300D\u3092\u5165\u529B\u3057\u3066\u7D20\u65E9\u304F\u633F\u5165\u3059\u308B",heading:"\u898B\u51FA\u3057{heading}",list:"\u30EA\u30B9\u30C8",mention:"\u81EA\u5206\u3084\u30E1\u30F3\u30D0\u30FC\u3092\uFF20\u3057\u3001\u30BF\u30B9\u30AF\u3092\u7D20\u65E9\u304F\u5272\u308A\u5F53\u3066\u307E\u3059",quote:"\u5F15\u7528",title:"\u30BF\u30A4\u30C8\u30EB\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"}}};R.mergeLang(xP);function bu(n,t){const e=_i(n,t);return!!(e.text&&rn(e.text)===0&&!t.querySelector(".inputting-insertion"))}function c7(n,t){var o;Lt(t).removeAttribute("data-content-placeholder"),(o=t.querySelector("[data-type=block-tools] .block-placeholder-container"))==null||o.remove()}function If(n,t,e){var r;if(!bu(n,t)){c7(n,t);return}const o=Lt(t);if(typeof e=="string")o.setAttribute("data-content-placeholder",e);else{const i=te(t),s=(r=i.querySelector(".block-placeholder-container"))!=null?r:w("div",["block-placeholder-container"],i);s.innerHTML="",s.appendChild(e)}}function IP(n){const t=n.getAttribute("data-style-heading");return t?R.t("placeholder.heading",{heading:t}):n.getAttribute("data-style-quoted")?R.t("placeholder.quote"):null}function TP(n){const t=n.getAttribute("data-list-type");return t?t==="ordered"||t==="unordered"?R.t("placeholder.list"):R.t("placeholder.mention"):null}function a7(n){switch(Dt(n)){case"text":return IP(n);case"list":return TP(n);default:return null}}function DP(n){if(io(n))return!1;const t=et(nt(n));return t?Dt(t)==="code":!1}function SP(n){return!io(n)}function LP(n,t){var h,p;const e=n.selection.focusedBlock,o=Dt(e),r=t.contentPlaceholder||R.t("placeholder.default");let i=r;if(o&&ya(n,o)&&e){if(!n.isBlockWritable(e)||DP(e))return;SP(e)&&(i=R.t("placeholder.common.contentInTable")),i=(h=a7(e))!=null?h:i}const s=n.getFirstBlock(),l=Zt(s);if(!l)return;const a=Zt(l);if(a&&!t.addPlaceholderToAllCurrentEmptyBlock)return;if(!a&&bu(n,l)){If(n,l,(p=a7(l))!=null?p:r);return}const d=n.getFocusedBlock();!bu(n,d)||d!==s&&If(n,d,i)}function MP(n,t){var r,i;const e=n.getFirstBlock(),o=Lt(e);bu(n,e)?(o.setAttribute("data-title-placeholder",(r=t.titlePlaceholder)!=null?r:R.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 RP(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 OP(n,t){RP(n),n.selection.range.isCollapsed()&&(MP(n,t),LP(n,t))}const Ont="";function _P(n){for(let t=1;t<n.length;t++){const e=n[t];if(e.attributes&&Object.keys(e.attributes).length)return!0}return!1}const u7=S("enforce-title");class vu{constructor(t,e={headingLevel:1}){m(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(!vu.isDocumentTitleBlock(r,i)||!_r(e,"Enter"))return!1;let l=!1,a=null;Io(t.rootContainer)===2&&(a=Fr(t.rootContainer,1),ut(t,a)===0&&(l=!0));const d=t.getFirstBlock();return t.undoManager.runInGroup(()=>{t.breakTextBlock(d,s,{forceInsertAfter:!0}),l&&a&&t.deleteBlock(a)}),!0}handleChanged(t){var e,o;try{const r=t.doc.getContainerBlocks(at(t.rootContainer));g(u7,r.length>0,"root container is empty");const i=r[0];if(i.type!=="text"){const s=lr("",{heading:(e=this.options.headingLevel)!=null?e:1});t.insertBlock(at(t.rootContainer),0,s,t.selection.range.toDocRange());return}if(g(u7,i.text,"invalid text block"),_P(i.text)||i.quoted||i.heading!==this.options.headingLevel){const s=t.getBlockById(i.id),l=t.getBlockString(s),a=lr(l,{heading:(o=this.options.headingLevel)!=null?o:1,quoted:!1}),d=t.selection.focusedBlock;let h=t.selection.range;const p=t.insertBlock(at(t.rootContainer),0,a);d===s&&(h=Ce(t,a.id,ut(t,p))),Bh(t,s,h)}if(r.length>1)return;t.insertTextBlock("",at(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)||OP(t,this.options)}static isDocumentTitleBlock(t,e){return t==="root"&&e===0}}const d7=S("code-dom");function Yi(n){return Dt(n)==="code"}function h7(n,t,e){e.language?t.setAttribute("data-language",e.language):t.removeAttribute("data-language"),e.nowrap?ot(t,"wrap"):W(t,"wrap")}function O0(n){const t=n.closest("div[data-type=editor-block][data-block-type=code]");return g(d7,t,"no parent code block"),g(d7,Yi(t),"not a code block"),t}const yu={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 f7(n){const t=n.toLocaleLowerCase();let e="";return Object.entries(yu).forEach(([o,r])=>{(o===t||r.aliases.includes(t)||r.name.toLocaleLowerCase()===t)&&(e=o)}),e}function m7(n){const t=n.settingsProvider.getItem("editor-code-lang");return t!=null?t:"plain"}function FP(n,t){return n.settingsProvider.setItem("editor-code-lang",t)}const PP=S("convert-to-code");function NP(n,t){if(!tt(n,t))return null;const e={id:K(),type:"text",text:[]},o=K();n.doc.localInsertChildContainer(o,[e]);const r=n.getBlockData(t).text;g(PP,r,"no text");let i=ie(r);i.startsWith("```")&&(i=i.substring(3));const s=f7(i)||m7(n)||"plain";return{blockData:{id:K(),type:"code",language:s,children:[o]},focusBlockId:e.id}}const _nt="",_0=S("code-block-child-container");function Ac(n){g(_0,Yi(n),"not a code block");const e=Lt(n).querySelector(":scope > div.editor-code-root > div.code-text-root [data-type=editor-container].child");return g(_0,e,"no code text container"),e}function bc(n){g(_0,Yi(n),"not a code block");const e=Lt(n).querySelector(":scope > div.editor-code-root > div.code-caption-root [data-type=editor-container].child");return e||null}function Tf(n){const t=[Ac(n)],e=bc(n);return e&&t.push(e),t}function vc(n,t){if(!tt(n,t))return!1;const e=nt(t),o=et(e);return o?Yi(o)?e===Ac(o):Dt(t)==="code":!1}const F0=S("code-caption");function $P(n,t){if(n.readonly)return;const e=bc(t);if(e){const a=xe(e);n.selection.selectBlock(a,0);return}const o=qr(n.doc),r=n.getBlockData(t);g(F0,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=xe(s);n.selection.selectBlock(l,0)}function g7(n,t){const e=nt(t);if(Yt(e))return!1;const o=et(e);if(g(F0,o,"no parent block"),!Yi(o))return!1;const i=bc(o);return e===i}function HP(n,t){if(n.readonly||!bc(t))return;const o=Ac(t),r=Qe(o);n.selection.selectBlock(r,ut(n,r));const i=n.getBlockData(t);g(F0,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 jP=S("paste-in-table-block");class UP{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=nt(i);if(Yt(s))return!1;const l=et(s);if(g(jP,l,"no parent block"),!Yi(l)||g7(t,i))return!1;const a=o["text/x-ones-editor-doc"];let d=null;if(a){const p=Ma(t,a);d=Wr(p)}else d=o["text/plain"];if(!d)return!0;const h=d;return t.undoManager.runInGroup(()=>{t.clearSelectedContents(),t.insertDoc(i,r.offset,h)}),!0}}function zP(n){n.addCustom("code-block-paste-event",t=>new UP(t))}class VP{constructor(t){m(this,"id","CodeBlockCommandProvider");setTimeout(()=>{t.editorCommandProviders.registerCommandProvider(this)})}destroy(){}getAvailableCommands(){return[]}executeCommand(){return!1}filterCommands(t,e,o,r){if(vc(t,e))return[]}beforeExecuteCommand(t,e,o,r,i){return!!vc(t,e)}}function WP(n){n.addCustom("code-block-command-provider",t=>new VP(t))}const qP=S("code-caption-input-handler");function P0(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 g7(n,e)?e:null}function GP(n){const t=P0(n);if(!t)return!1;const e=O0(t),o=Zt(e);return o?(n.selection.selectBlock(o,0),!0):(n.insertTextBlock("",at(nt(e)),bt(e)+1),!0)}function ZP(n){const t=P0(n);if(!t)return!1;if(he(n,t)){const e=O0(t);return HP(n,e),!0}return!1}class N0{constructor(t){setTimeout(()=>{t.input.addHandler(this)})}destroy(){}handleBeforeKeyDown(t,e){return e.key==="Enter"?GP(t):e.key==="Backspace"?ZP(t):!1}async handleBeforePaste(t,e,o){const r=P0(t);if(!r)return!1;const i=o["text/plain"];if(!i)return!0;const s=Ma(t,i);return s&&t.undoManager.runInGroup(()=>{t.clearSelectedContents();const l=t.selection.range.start;g(qP,l.isSimple(),"not simple position"),t.insertTextToBlock(r,l.offset,s)}),!0}static init(t){t.addCustom("code-block-caption-input-handler",e=>new N0(e))}}function QP(n){const o=new DOMParser().parseFromString(n,"text/html").querySelector("svg");if(!o)return null;const r=o.getAttribute("viewBox");if(!r)return null;const i=r.split(" ");if(i.length===4){const s=i[2],l=i[3];return o.setAttribute("width",s),o.setAttribute("height",l),o.outerHTML}return null}function $0(n,t,e=!0){const o=new Image,r=document.createElement("canvas"),i=r.getContext("2d");if(!i){t(new Error("failed to get context"),null);return}o.onload=()=>{if(r.width=o.naturalWidth,r.height=o.naturalHeight,e&&(r.width===0||r.height===0)){const s=n.substring(26);if(s){const l=atob(s),a=QP(l);if(a){Tm(a,"image/svg+xml").then(d=>{$0(d,t,!1)});return}}t(null,null);return}i.drawImage(o,0,0),r.toBlob(s=>{t(null,s)},"image/png")},o.src=n}function YP(n){return new Promise((t,e)=>{$0(n,(o,r)=>{if(o){e(o);return}if(!r){e(new Error("Failed to get image blob"));return}t(r)})})}async function p7(n){const t=await jl(n);return new Promise((e,o)=>{$0(t,(r,i)=>{if(r){o(r);return}if(!i){o(new Error("Failed to get image blob"));return}e(i)})})}const C7="Untitled";function A7(n){const t=xe(n.rootContainer);return!t||!tt(n,t)?C7:n.getBlockString(t)||C7}function H0(){return Object.prototype.hasOwnProperty.bind(window,"isSecureContext")?window.isSecureContext:window.location.protocol==="https:"||window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"}function JP(n){let t;return n.forEach((e,o)=>{o.toLocaleLowerCase()==="content-type"&&(t=e)}),t!=null?t:""}async function b7(n){try{const t=await fetch(n,{credentials:"same-origin"}),e=await t.blob(),o=JP(t.headers).toLocaleLowerCase();let r="";if(o){const s=mm.default[o].extensions;s&&s.length>0&&(r=s[0])}return new File([e],`${Date.now()}.${r}`,{type:o})}catch{return null}}const KP=`
|
|
403
|
+
`)}return""}const Au=S("table-block");function QF(n){return 1}function YF(n){return!!n.closest(`.${qp}`)}function JF(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(YF(r)&&(i=r.closest("td"),g(Au,i instanceof HTMLTableCellElement,"invalid element")),i instanceof HTMLTableCellElement){const a=_e(t);if(Bv(a).indexOf(i)!==-1){const h=su(i),p=fe(t,at(h));return new ir(n,{anchor:p,focus:p})}}if(!Pr(r))return null;const s=r;if(Y9(t).indexOf(s)===-1)return null;const l=fe(t,at(s));return new ir(n,{anchor:l,focus:l})}function KF(n,t,e,o){return null}function XF(n,t){return n.getBoundingClientRect()}function o7(n,t,e,o){if(e.isSimple()){g(Au,o.isSimple(),"from is simple position but to is not simple position"),Au.debug("full select table"),W(t,"full-selected");return}g(Au,!o.isSimple(),"from is complex position but end is simple position");const r=Jr(n,t,e),i=Jr(n,t,o);g(Au,r.blockId===i.blockId,"only allow update one table selection"),GM(n,r,i).forEach(l=>{const a=L0(l);W(a,"selected")})}function tP(n){n.rootContainer.querySelectorAll('[data-type="editor-block"][data-block-type="table"]').forEach(t=>{ot(t,"full-selected"),t.querySelectorAll("td.selected").forEach(e=>{ot(e,"selected")})})}function eP(n,t){return Ev(t)?Y9(t):[]}function nP(n,t,e,o,r){return M0(t,e,o,r)}function oP(n,t){return UF(n,t)}function rP(n,t){return tt(n,t)?SF(n,n.getBlockString(t).trim()):null}function iP(n){return{name:"TableBlock",insertBlockCommandItems:[{id:"insert-table",name:R.t("table.title"),order:200,icon:_L,children:[WF()],group:"common",subText:Cn("insert-table")}],handleInsertEmptyBlock:zF}}function sP(n,t,e){return DF(n,t,e),setTimeout(()=>{const o=n.selection.range;o.isSimple()?n.selection.caret.update():o7(n,t,o.start,o.end)}),!0}function lP(n,t){let e=0;const{selectedColumns:o}=Np(n,t);if(o.size>0){const{fromCol:i,toCol:s}=Uo(t,n.selection.range.start,n.selection.range.end),l=Tt.fromBlock(t);(i!==0||s!==l.colCount-1)&&(e=60)}const r=e7(n,t,n.selection.range)[0];return new DOMRect(r.left,r.top+e,r.width,Math.max(r.height-e*2,0))}function cP(n,t){aL(n,Jp);const e=n.findCustom(mr(t));if(e){const o=K9(n);e.off("scroll",o.handleReset),e.off("resize",o.handleReset),e.destroy()}}function aP(){return{abstract:`${R.t("table.abstract")}`}}const Ef={blockType:"table",blockKind:"complex",enableKeyboardSelect:!0,createBlockContent:TF,getBlockTextLength:QF,getRangeFromPoint:JF,moveCaret:KF,getCaretRect:XF,updateSelection:o7,clearSelection:tP,getChildContainers:eP,getNextContainer:nP,getMinWidth:oP,getSelectedContainers:Zp,convertFrom:rP,convertTo:ZF,adjustSelectionPos:NF,getClientRects:e7,selectionToDoc:MF,getOptions:iP,getTextToolbarReferenceClient:lP,handleUpdateBlock:sP,handleDeleteBlock:cP,getBlockProperties:aP},uP={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"}},dP={table:{cellBackground:"Cell background color",deleteSelectRow:"Delete selected rows",deleteSelectCol:"Delete selected columns",mergeCell:"Merge cells",splitCell:"Split cell",tableConfigKey:"Table settings",deleteTable:"Delete table",insertCol:"Insert column",insertRow:"Insert row",deleteCol:"Delete column",deleteRow:"Delete row",tableConfig:{rowTitle:"Row header",colTitle:"Column header",stripeStyle:"Stripe style",hideBorder:"Hide border",showBorder:"Show border",showChart:"Show chart",hideChart:"Hide chart"},title:"Table",abstract:"Table"}},hP={table:{cellBackground:"\u30BB\u30EB\u306E\u80CC\u666F\u8272",deleteSelectRow:"\u9078\u629E\u3057\u305F\u884C\u3092\u524A\u9664",deleteSelectCol:"\u9078\u629E\u3057\u305F\u5217\u3092\u524A\u9664",mergeCell:"\u30BB\u30EB\u3092\u7D50\u5408",splitCell:"\u30BB\u30EB\u306E\u7D50\u5408\u3092\u89E3\u9664",tableConfigKey:"\u30C6\u30FC\u30D6\u30EB\u8A2D\u5B9A",deleteTable:"\u30C6\u30FC\u30D6\u30EB\u3092\u524A\u9664",insertCol:"\u5217\u3092\u633F\u5165",insertRow:"\u884C\u3092\u633F\u5165",deleteCol:"\u5217\u3092\u524A\u9664",deleteRow:"\u884C\u3092\u524A\u9664",tableConfig:{rowTitle:"\u884C\u898B\u51FA\u3057",colTitle:"\u5217\u898B\u51FA\u3057",stripeStyle:"\u7E1E\u6A21\u69D8",hideBorder:"\u67A0\u7DDA\u3092\u975E\u8868\u793A",showBorder:"\u67A0\u7DDA\u3092\u8868\u793A",showChart:"\u30B0\u30E9\u30D5\u3092\u8868\u793A",hideChart:"\u30B0\u30E9\u30D5\u3092\u975E\u8868\u793A"},title:"\u30C6\u30FC\u30D6\u30EB",abstract:"\u30C6\u30FC\u30D6\u30EB"}};R.mergeLang({"zh-CN":uP,"en-US":dP,"ja-JP":hP});const Snt="",r7=S("table");function i7(n,t){const e=Pp(t);if(!e)return;const o=et(e);g(r7,o&&Ve(o),"not a table block");const r=M0(o,e,"ArrowRight");if(!r){const s=Zt(o);return s?(n.selection.selectBlock(s,0),!0):i7(n,o)}const i=xe(r);return n.selection.selectBlock(i,0),!0}function fP(n){if(!n.isWritable())return!1;const t=n.getFocusedBlock();if(!!t)return i7(n,t)}function s7(n,t){const e=Pp(t);if(!e)return;const o=et(e);g(r7,o&&Ve(o),"not a table block");const r=M0(o,e,"ArrowLeft");if(!r){const s=ce(o);return s?(n.selection.selectBlock(s,ut(n,s)),!0):s7(n,o)}const i=Qe(r);return n.selection.selectBlock(i,ut(n,i)),!0}function mP(n){if(!n.isWritable())return!1;const t=n.getFocusedBlock();if(!!t)return s7(n,t)}const R0={Tab:fP,"Shift+Tab":mP};function gP(n,t,e,o){const r=n.getBlockByIndex(t,e);if(ut(n,r)!==o)return!1;const i=ie(n.getBlockText(r));if(![...i].every(h=>h==="|")||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:a,focusBlockId:d}=l;return a?(n.undoManager.runInGroup(()=>{var p;const h=n.insertBlock(t,e,a,Ce(n,d!=null?d:a.id,0));n.deleteBlock(r),(p=l.onConverted)==null||p.call(l,n,h)}),!0):!1}const pP={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"}}},CP={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 l7(n,t,e,o,r){if(r==="enter"&&gP(n,t,e,o))return!0;const i=n.getBlockByIndex(t,e),s=ie(In(n.getBlockText(i),o).left).trim(),l=r==="enter"?pP:CP;for(const[,a]of Object.entries(l)){if(!s.match(a.reg))continue;return!!n.undoManager.runInGroup(()=>{var B;const h=th(n,i,a.blockType,{offset:o,data:a.data});if(!h)return null;const{blockData:p,focusBlockId:A}=h;if(!p)return null;const v=n.insertBlock(t,e,p,Ce(n,A!=null?A:p.id,0));return n.deleteBlock(i),(B=h.onConverted)==null||B.call(h,n,v),{newBlock:v,focusBlockId:A}})}return!1}function AP(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},Ce(n,r,0))}),!0)}const bP={"#":1,"##":2,"###":3,"####":4,"#####":5,"######":6,"#######":7,"########":8};function vP(n,t,e,o){const r=n.getBlockByIndex(t,e),i=n.getBlockString(r,{boxReplacement:" "}).substring(0,o);let s=bP[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},Ce(n,r,0))}),!0}function yP(n,t,e,o){return!!(vP(n,t,e,o)||AP(n,t,e,o))}const kP=S("match-text-style");function wP(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 BP={"*":{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 EP(n,t,e,o){var A,v;const r=n.getBlockByIndex(t,e),i=n.getBlockText(r),{left:s}=In(i,o),l=fg(s),a=rn(s)-l.length,d=Object.entries(BP);for(const[B,D]of d){const x=wP(l,B);if(x===-1)continue;const _=a+x,M=o,H=B.length,z=ie(ze(i,_+H,M-_-H*2).middle);if(D.type==="style"){const q={};D.styles.forEach(ft=>{q[ft]=!0});const rt=Oi(z,q);n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,_,M-_),n.insertTextToBlock(r,_,rt)})}else if(D.type==="box")try{const q=(v=(A=n.editorBoxes.getBoxClass(D.boxType)).convertFrom)==null?void 0:v.call(A,n,z);if(!q)continue;n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,_,M-_),n.insertBoxToBlock(r,_,q)})}catch(q){kP.warn(`failed to convert to box, ${q.message}`);continue}return!0}const h=/\[([^\]]+)\]\((https?:\/\/\S+)\)\s*$/,p=l.match(h);if(p){const B=p.index,D=p[1],x=p[2],_=B,M=o,z={...Da(i,_),link:x};return n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,_,M-_),n.insertTextToBlock(r,_,Oi(D,z))}),!0}return!1}class xf{handleAfterInsertText(t,e,o,r,i){return!!(i===" "&&(yP(t,e,o,r)||EP(t,e,o,r)))}handleBeforeKeyDown(t,e){if(!t.selection.range.isSimple())return!1;const{containerId:r,blockIndex:i,offset:s}=t.getTextPosition();if(tt(t,t.getBlockByIndex(r,i))){if(or(e,"Enter")){if(l7(t,r,i,s,"enter"))return!0}else if(or(e,"Space")&&l7(t,r,i,s,"space"))return!0}return!1}}const xP={"en-US":{placeholder:{default:"Type / for commands",heading:"Title {heading}",list:"List",mention:"Quickly assign tasks and use @ to mention yourself or others",quote:"Quote",title:"Enter document title"}},"zh-CN":{placeholder:{default:"\u8F93\u5165\u300C/\u300D\u5FEB\u901F\u63D2\u5165",heading:"\u6807\u9898{heading}",list:"\u5217\u8868",mention:"\u5FEB\u901F\u5206\u914D\u4EFB\u52A1\uFF0C@\u63D0\u53CA\u81EA\u5DF1\u6216\u4ED6\u4EBA",quote:"\u5F15\u7528",title:"\u8BF7\u8F93\u5165\u6587\u6863\u6807\u9898"}},"ja-JP":{placeholder:{default:"\u300C/\u300D\u3092\u5165\u529B\u3057\u3066\u7D20\u65E9\u304F\u633F\u5165\u3059\u308B",heading:"\u898B\u51FA\u3057{heading}",list:"\u30EA\u30B9\u30C8",mention:"\u81EA\u5206\u3084\u30E1\u30F3\u30D0\u30FC\u3092\uFF20\u3057\u3001\u30BF\u30B9\u30AF\u3092\u7D20\u65E9\u304F\u5272\u308A\u5F53\u3066\u307E\u3059",quote:"\u5F15\u7528",title:"\u30BF\u30A4\u30C8\u30EB\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"}}};R.mergeLang(xP);function bu(n,t){const e=_i(n,t);return!!(e.text&&rn(e.text)===0&&!t.querySelector(".inputting-insertion"))}function c7(n,t){var o;Lt(t).removeAttribute("data-content-placeholder"),(o=t.querySelector("[data-type=block-tools] .block-placeholder-container"))==null||o.remove()}function If(n,t,e){var r;if(!bu(n,t)){c7(n,t);return}const o=Lt(t);if(typeof e=="string")o.setAttribute("data-content-placeholder",e);else{const i=te(t),s=(r=i.querySelector(".block-placeholder-container"))!=null?r:w("div",["block-placeholder-container"],i);s.innerHTML="",s.appendChild(e)}}function IP(n){const t=n.getAttribute("data-style-heading");return t?R.t("placeholder.heading",{heading:t}):n.getAttribute("data-style-quoted")?R.t("placeholder.quote"):null}function TP(n){const t=n.getAttribute("data-list-type");return t?t==="ordered"||t==="unordered"?R.t("placeholder.list"):R.t("placeholder.mention"):null}function a7(n){switch(Dt(n)){case"text":return IP(n);case"list":return TP(n);default:return null}}function DP(n){if(io(n))return!1;const t=et(nt(n));return t?Dt(t)==="code":!1}function SP(n){return!io(n)}function LP(n,t){var h,p;const e=n.selection.focusedBlock,o=Dt(e),r=t.contentPlaceholder||R.t("placeholder.default");let i=r;if(o&&ya(n,o)&&e){if(!n.isBlockWritable(e)||DP(e))return;SP(e)&&(i=R.t("placeholder.common.contentInTable")),i=(h=a7(e))!=null?h:i}const s=n.getFirstBlock(),l=Zt(s);if(!l)return;const a=Zt(l);if(a&&!t.addPlaceholderToAllCurrentEmptyBlock)return;if(!a&&bu(n,l)){If(n,l,(p=a7(l))!=null?p:r);return}const d=n.getFocusedBlock();!bu(n,d)||d!==s&&If(n,d,i)}function MP(n,t){var r,i;const e=n.getFirstBlock(),o=Lt(e);bu(n,e)?(o.setAttribute("data-title-placeholder",(r=t.titlePlaceholder)!=null?r:R.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 RP(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 OP(n,t){RP(n),n.selection.range.isCollapsed()&&(MP(n,t),LP(n,t))}const Ont="";function _P(n){for(let t=1;t<n.length;t++){const e=n[t];if(e.attributes&&Object.keys(e.attributes).length)return!0}return!1}const u7=S("enforce-title");class vu{constructor(t,e={headingLevel:1}){m(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(!vu.isDocumentTitleBlock(r,i)||!or(e,"Enter"))return!1;let l=!1,a=null;Io(t.rootContainer)===2&&(a=Fr(t.rootContainer,1),ut(t,a)===0&&(l=!0));const d=t.getFirstBlock();return t.undoManager.runInGroup(()=>{t.breakTextBlock(d,s,{forceInsertAfter:!0}),l&&a&&t.deleteBlock(a)}),!0}handleChanged(t){var e,o;try{const r=t.doc.getContainerBlocks(at(t.rootContainer));g(u7,r.length>0,"root container is empty");const i=r[0];if(i.type!=="text"){const s=cr("",{heading:(e=this.options.headingLevel)!=null?e:1});t.insertBlock(at(t.rootContainer),0,s,t.selection.range.toDocRange());return}if(g(u7,i.text,"invalid text block"),_P(i.text)||i.quoted||i.heading!==this.options.headingLevel){const s=t.getBlockById(i.id),l=t.getBlockString(s),a=cr(l,{heading:(o=this.options.headingLevel)!=null?o:1,quoted:!1}),d=t.selection.focusedBlock;let h=t.selection.range;const p=t.insertBlock(at(t.rootContainer),0,a);d===s&&(h=Ce(t,a.id,ut(t,p))),Bh(t,s,h)}if(r.length>1)return;t.insertTextBlock("",at(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)||OP(t,this.options)}static isDocumentTitleBlock(t,e){return t==="root"&&e===0}}const d7=S("code-dom");function Yi(n){return Dt(n)==="code"}function h7(n,t,e){e.language?t.setAttribute("data-language",e.language):t.removeAttribute("data-language"),e.nowrap?ot(t,"wrap"):W(t,"wrap")}function O0(n){const t=n.closest("div[data-type=editor-block][data-block-type=code]");return g(d7,t,"no parent code block"),g(d7,Yi(t),"not a code block"),t}const yu={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 f7(n){const t=n.toLocaleLowerCase();let e="";return Object.entries(yu).forEach(([o,r])=>{(o===t||r.aliases.includes(t)||r.name.toLocaleLowerCase()===t)&&(e=o)}),e}function m7(n){const t=n.settingsProvider.getItem("editor-code-lang");return t!=null?t:"plain"}function FP(n,t){return n.settingsProvider.setItem("editor-code-lang",t)}const PP=S("convert-to-code");function NP(n,t){if(!tt(n,t))return null;const e={id:K(),type:"text",text:[]},o=K();n.doc.localInsertChildContainer(o,[e]);const r=n.getBlockData(t).text;g(PP,r,"no text");let i=ie(r);i.startsWith("```")&&(i=i.substring(3));const s=f7(i)||m7(n)||"plain";return{blockData:{id:K(),type:"code",language:s,children:[o]},focusBlockId:e.id}}const _nt="",_0=S("code-block-child-container");function Ac(n){g(_0,Yi(n),"not a code block");const e=Lt(n).querySelector(":scope > div.editor-code-root > div.code-text-root [data-type=editor-container].child");return g(_0,e,"no code text container"),e}function bc(n){g(_0,Yi(n),"not a code block");const e=Lt(n).querySelector(":scope > div.editor-code-root > div.code-caption-root [data-type=editor-container].child");return e||null}function Tf(n){const t=[Ac(n)],e=bc(n);return e&&t.push(e),t}function vc(n,t){if(!tt(n,t))return!1;const e=nt(t),o=et(e);return o?Yi(o)?e===Ac(o):Dt(t)==="code":!1}const F0=S("code-caption");function $P(n,t){if(n.readonly)return;const e=bc(t);if(e){const a=xe(e);n.selection.selectBlock(a,0);return}const o=qr(n.doc),r=n.getBlockData(t);g(F0,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=xe(s);n.selection.selectBlock(l,0)}function g7(n,t){const e=nt(t);if(Yt(e))return!1;const o=et(e);if(g(F0,o,"no parent block"),!Yi(o))return!1;const i=bc(o);return e===i}function HP(n,t){if(n.readonly||!bc(t))return;const o=Ac(t),r=Qe(o);n.selection.selectBlock(r,ut(n,r));const i=n.getBlockData(t);g(F0,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 jP=S("paste-in-table-block");class UP{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=nt(i);if(Yt(s))return!1;const l=et(s);if(g(jP,l,"no parent block"),!Yi(l)||g7(t,i))return!1;const a=o["text/x-ones-editor-doc"];let d=null;if(a){const p=Ma(t,a);d=Wr(p)}else d=o["text/plain"];if(!d)return!0;const h=d;return t.undoManager.runInGroup(()=>{t.clearSelectedContents(),t.insertDoc(i,r.offset,h)}),!0}}function zP(n){n.addCustom("code-block-paste-event",t=>new UP(t))}class VP{constructor(t){m(this,"id","CodeBlockCommandProvider");setTimeout(()=>{t.editorCommandProviders.registerCommandProvider(this)})}destroy(){}getAvailableCommands(){return[]}executeCommand(){return!1}filterCommands(t,e,o,r){if(vc(t,e))return[]}beforeExecuteCommand(t,e,o,r,i){return!!vc(t,e)}}function WP(n){n.addCustom("code-block-command-provider",t=>new VP(t))}const qP=S("code-caption-input-handler");function P0(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 g7(n,e)?e:null}function GP(n){const t=P0(n);if(!t)return!1;const e=O0(t),o=Zt(e);return o?(n.selection.selectBlock(o,0),!0):(n.insertTextBlock("",at(nt(e)),bt(e)+1),!0)}function ZP(n){const t=P0(n);if(!t)return!1;if(he(n,t)){const e=O0(t);return HP(n,e),!0}return!1}class N0{constructor(t){setTimeout(()=>{t.input.addHandler(this)})}destroy(){}handleBeforeKeyDown(t,e){return e.key==="Enter"?or(e,"Shift+Enter")?!0:GP(t):e.key==="Backspace"?ZP(t):!1}async handleBeforePaste(t,e,o){const r=P0(t);if(!r)return!1;const i=o["text/plain"];if(!i)return!0;const s=Ma(t,i);return s&&t.undoManager.runInGroup(()=>{t.clearSelectedContents();const l=t.selection.range.start;g(qP,l.isSimple(),"not simple position"),t.insertTextToBlock(r,l.offset,s)}),!0}static init(t){t.addCustom("code-block-caption-input-handler",e=>new N0(e))}}function QP(n){const o=new DOMParser().parseFromString(n,"text/html").querySelector("svg");if(!o)return null;const r=o.getAttribute("viewBox");if(!r)return null;const i=r.split(" ");if(i.length===4){const s=i[2],l=i[3];return o.setAttribute("width",s),o.setAttribute("height",l),o.outerHTML}return null}function $0(n,t,e=!0){const o=new Image,r=document.createElement("canvas"),i=r.getContext("2d");if(!i){t(new Error("failed to get context"),null);return}o.onload=()=>{if(r.width=o.naturalWidth,r.height=o.naturalHeight,e&&(r.width===0||r.height===0)){const s=n.substring(26);if(s){const l=atob(s),a=QP(l);if(a){Tm(a,"image/svg+xml").then(d=>{$0(d,t,!1)});return}}t(null,null);return}i.drawImage(o,0,0),r.toBlob(s=>{t(null,s)},"image/png")},o.src=n}function YP(n){return new Promise((t,e)=>{$0(n,(o,r)=>{if(o){e(o);return}if(!r){e(new Error("Failed to get image blob"));return}t(r)})})}async function p7(n){const t=await jl(n);return new Promise((e,o)=>{$0(t,(r,i)=>{if(r){o(r);return}if(!i){o(new Error("Failed to get image blob"));return}e(i)})})}const C7="Untitled";function A7(n){const t=xe(n.rootContainer);return!t||!tt(n,t)?C7:n.getBlockString(t)||C7}function H0(){return Object.prototype.hasOwnProperty.bind(window,"isSecureContext")?window.isSecureContext:window.location.protocol==="https:"||window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"}function JP(n){let t;return n.forEach((e,o)=>{o.toLocaleLowerCase()==="content-type"&&(t=e)}),t!=null?t:""}async function b7(n){try{const t=await fetch(n,{credentials:"same-origin"}),e=await t.blob(),o=JP(t.headers).toLocaleLowerCase();let r="";if(o){const s=mm.default[o].extensions;s&&s.length>0&&(r=s[0])}return new File([e],`${Date.now()}.${r}`,{type:o})}catch{return null}}const KP=`
|
|
404
404
|
<svg fill="currentColor" focusable="false" viewBox="0 0 24 24" aria-hidden="true" tabindex="-1">
|
|
405
405
|
<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>
|
|
406
406
|
</svg>`,XP=`
|
|
@@ -411,16 +411,16 @@ $$${r.mathjaxText}$$
|
|
|
411
411
|
<svg width="24" height="24" viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
|
|
412
412
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M18.4388 7.11504H5.55388C5.24779 7.11504 5 6.86726 5 6.55388C5 6.24779 5.24779 6 5.55388 6H18.4388C18.7522 6 19 6.24779 19 6.55388C19 6.86726 18.7449 7.11504 18.4388 7.11504ZM18.4388 10.7225H5.55388C5.24779 10.7225 5 10.4748 5 10.1687C5 9.86257 5.24779 9.61478 5.55388 9.61478H18.4388C18.7522 9.61478 19 9.85528 19 10.1687C19 10.4748 18.7449 10.7225 18.4388 10.7225ZM18.4388 14.3373H5.55388C5.24779 14.3373 5 14.0895 5 13.7834C5 13.4701 5.24779 13.2223 5.55388 13.2223H18.4388C18.7522 13.2223 19 13.4701 19 13.7834C19 14.0895 18.7449 14.3373 18.4388 14.3373ZM12.8855 17.9448H5.55388C5.24779 17.9448 5 17.697 5 17.3909C5 17.0849 5.24779 16.8371 5.55388 16.8371H12.8855C13.1989 16.8371 13.4466 17.0849 13.4466 17.3909C13.4466 17.7043 13.1989 17.9448 12.8855 17.9448ZM21 14.7344V16.3013C21 17.486 20.4268 18.0593 19.2357 18.0593L17.5159 18.0593V18.8555C17.5159 19.2631 17.1019 19.4351 16.7771 19.1803L15.2866 18.0211C14.9045 17.7217 14.9045 17.3459 15.2866 17.0465L16.7771 15.8809C17.1019 15.6262 17.5159 15.8045 17.5159 16.2121V17.0083H19.1847C19.6943 17.0083 19.9554 16.7535 19.9554 16.2121V14.7344C19.9554 14.365 20.1465 14.1548 20.4777 14.1484C20.8153 14.1421 21 14.365 21 14.7344Z"/>
|
|
413
413
|
</svg>
|
|
414
|
-
`;function eN(n,t,e){const r={...n.getBlockData(t),language:e};n.updateBlockData(t,r),xn(n,t).forEach(s=>{pe(s).forEach(l=>{n.reloadBlock(l)})})}function nN(n,t,e){const r={...n.getBlockData(t),nowrap:e};n.updateBlockData(t,r)}const Ys=S("code-block-header"),oN=Object.entries(yu).map(([n,t])=>({id:n,name:t.name,language:t}));function v7(n,t,e){g(Ys,Yi(t),"not a code block");const o=xe(Ac(t));n.selection.selectBlock(o,0),e.focusToEditor&&n.focus()}function rN(n,t){if(t){const e=n,{editor:o,codeBlock:r}=e.custom;eN(o,r,t.id);const i=r.querySelector(".code-block-header .language-select .name-label");i.innerText=t.name,FP(o,t.id),o.focus()}}function iN(n,t,e){n.addCustom("code-header-language-select-dropdown",i=>{const s=new pL(oN,i.rootElement,{placeholder:R.t("code.search")});return s.onSelected=rN,s});const o=w("div",["language-select"],null);w("span",["name-label"],o,e);const r=w("span",["arrow-icon"],o);return r.innerHTML=KP,n.domEvents.addEventListener(o,"click",(i,s)=>{if(i.readonly)return;const a=s.target.closest(".language-select"),d=et(a);g(Ys,d,"no parent block"),g(Ys,Dt(d)==="code","not a code block");const h=i.getBlockData(d),p=i.getCustom("code-header-language-select-dropdown");p.custom={codeBlock:d,editor:i},p.setSelectedId(h.language),p.show(a),v7(i,d,{focusToEditor:!1}),W(t,"editing-language"),p.onHide=()=>{ot(t,"editing-language")}}),o}function sN(){return w("div",["code-header-spacer"],null)}function lN(n,t){const e=t.target,o=e.closest(".code-header-button");g(Ys,o,"no button");const r=et(e);g(Ys,r,"no parent block");const i=o.getAttribute("data-id");if(g(Ys,Dt(r)==="code","not a code block"),i==="wrap"){const s=n.getBlockData(r);nN(n,r,!s.nowrap);return}if(i==="copy"){v7(n,r,{focusToEditor:!0}),_h(n,r).then(()=>{const{onCodeCopyComplete:s}=n.getComponentOptions("code")||{};if(s){s();return}const l=o.getBoundingClientRect();CL(R.t("code.copySuccess"),{position:{x:l.x+l.width/2,y:l.bottom+30}})}).catch(s=>{Ys.error(s.message)});return}i==="caption"&&($P(n,r),setTimeout(()=>{n.focus()}))}function y7(n,t,e,o){const r=w("button",["code-header-button"],null);if(r.setAttribute("data-id",t),o){const i=w("span",["button-icon"],r);i.innerHTML=o,e&&r.setAttribute(`data-editor-tooltip-${n.clientId}`,e)}else if(e){const i=w("span",["button-label"],r);i.innerHTML=e}return n.domEvents.addEventListener(r,"click",lN),r}function cN(n,t,e){const o=te(t),r=w("div",["code-block-header"],o),i=yu[e.language]||yu[f7(e.language.toLocaleLowerCase())]||yu.plain;r.appendChild(iN(n,t,i.name)),r.appendChild(sN()),r.appendChild(y7(n,"wrap",R.t("code.wrap"),tN));const s=r.appendChild(y7(n,"copy",R.t("code.copy"),XP));H0()||(W(s,"disabled"),s.setAttribute("data-editor-tooltip-maxwidth","800"),s.setAttribute(`data-editor-tooltip-${n.clientId}`,R.t("copyCutProperty.unsafeEnvTips",{shortCut:xo("CtrlOrCmd+C"),operation:R.t("copyCutProperty.copy")})))}function aN(n,t){!t.target||setTimeout(()=>{n.selection.caret.update()})}function uN(n,t,e,o){N0.init(n);const r=o.children,i=Is(e,"div");i.setAttribute("data-language",o.language||"text"),h7(n,e,o);const s=w("div",["editor-code-root"],i),l=w("div",["code-text-root"],s),a=n.createChildContainer(t,l,r[0]);if(r.length===2){const d=w("div",["code-caption-root"],s);n.createChildContainer(t,d,r[1])}return n.domEvents.addEventListener(a,"scroll",aN),cN(n,e,o),i}async function dN(n){const t={id:K(),type:"text",text:[]},e=K();n.doc.localInsertChildContainer(e,[t]);const o=await m7(n);return{blockData:{id:K(),type:"code",language:o,children:[e]},focusBlockId:t.id}}const
|
|
414
|
+
`;function eN(n,t,e){const r={...n.getBlockData(t),language:e};n.updateBlockData(t,r),xn(n,t).forEach(s=>{pe(s).forEach(l=>{n.reloadBlock(l)})})}function nN(n,t,e){const r={...n.getBlockData(t),nowrap:e};n.updateBlockData(t,r)}const Ys=S("code-block-header"),oN=Object.entries(yu).map(([n,t])=>({id:n,name:t.name,language:t}));function v7(n,t,e){g(Ys,Yi(t),"not a code block");const o=xe(Ac(t));n.selection.selectBlock(o,0),e.focusToEditor&&n.focus()}function rN(n,t){if(t){const e=n,{editor:o,codeBlock:r}=e.custom;eN(o,r,t.id);const i=r.querySelector(".code-block-header .language-select .name-label");i.innerText=t.name,FP(o,t.id),o.focus()}}function iN(n,t,e){n.addCustom("code-header-language-select-dropdown",i=>{const s=new pL(oN,i.rootElement,{placeholder:R.t("code.search")});return s.onSelected=rN,s});const o=w("div",["language-select"],null);w("span",["name-label"],o,e);const r=w("span",["arrow-icon"],o);return r.innerHTML=KP,n.domEvents.addEventListener(o,"click",(i,s)=>{if(i.readonly)return;const a=s.target.closest(".language-select"),d=et(a);g(Ys,d,"no parent block"),g(Ys,Dt(d)==="code","not a code block");const h=i.getBlockData(d),p=i.getCustom("code-header-language-select-dropdown");p.custom={codeBlock:d,editor:i},p.setSelectedId(h.language),p.show(a),v7(i,d,{focusToEditor:!1}),W(t,"editing-language"),p.onHide=()=>{ot(t,"editing-language")}}),o}function sN(){return w("div",["code-header-spacer"],null)}function lN(n,t){const e=t.target,o=e.closest(".code-header-button");g(Ys,o,"no button");const r=et(e);g(Ys,r,"no parent block");const i=o.getAttribute("data-id");if(g(Ys,Dt(r)==="code","not a code block"),i==="wrap"){const s=n.getBlockData(r);nN(n,r,!s.nowrap);return}if(i==="copy"){v7(n,r,{focusToEditor:!0}),_h(n,r).then(()=>{const{onCodeCopyComplete:s}=n.getComponentOptions("code")||{};if(s){s();return}const l=o.getBoundingClientRect();CL(R.t("code.copySuccess"),{position:{x:l.x+l.width/2,y:l.bottom+30}})}).catch(s=>{Ys.error(s.message)});return}i==="caption"&&($P(n,r),setTimeout(()=>{n.focus()}))}function y7(n,t,e,o){const r=w("button",["code-header-button"],null);if(r.setAttribute("data-id",t),o){const i=w("span",["button-icon"],r);i.innerHTML=o,e&&r.setAttribute(`data-editor-tooltip-${n.clientId}`,e)}else if(e){const i=w("span",["button-label"],r);i.innerHTML=e}return n.domEvents.addEventListener(r,"click",lN),r}function cN(n,t,e){const o=te(t),r=w("div",["code-block-header"],o),i=yu[e.language]||yu[f7(e.language.toLocaleLowerCase())]||yu.plain;r.appendChild(iN(n,t,i.name)),r.appendChild(sN()),r.appendChild(y7(n,"wrap",R.t("code.wrap"),tN));const s=r.appendChild(y7(n,"copy",R.t("code.copy"),XP));H0()||(W(s,"disabled"),s.setAttribute("data-editor-tooltip-maxwidth","800"),s.setAttribute(`data-editor-tooltip-${n.clientId}`,R.t("copyCutProperty.unsafeEnvTips",{shortCut:xo("CtrlOrCmd+C"),operation:R.t("copyCutProperty.copy")})))}function aN(n,t){!t.target||setTimeout(()=>{n.selection.caret.update()})}function uN(n,t,e,o){N0.init(n);const r=o.children,i=Is(e,"div");i.setAttribute("data-language",o.language||"text"),h7(n,e,o);const s=w("div",["editor-code-root"],i),l=w("div",["code-text-root"],s),a=n.createChildContainer(t,l,r[0]);if(r.length===2){const d=w("div",["code-caption-root"],s);n.createChildContainer(t,d,r[1])}return n.domEvents.addEventListener(a,"scroll",aN),cN(n,e,o),i}async function dN(n){const t={id:K(),type:"text",text:[]},e=K();n.doc.localInsertChildContainer(e,[t]);const o=await m7(n);return{blockData:{id:K(),type:"code",language:o,children:[e]},focusBlockId:t.id}}const Cr=S("code-block");function hN(n,t,e,o,r){zP(n),WP(n),g(Cr,r.type==="code","invalid block data type");const i=r;return g(Cr,i.children,"invalid block data children"),g(Cr,i.children.length===1||i.children.length===2,"invalid block data children length"),uN(n,t,o,i)}function fN(n){return 1}function mN(n,t,e,o){const r=document.elementsFromPoint(e,o)[0];if(!r||!t.contains(r)||!n.contains(t)||!Pr(r))return null;const i=Tf(t);if(!Pr(r))return null;const s=r;if(i.indexOf(s)===-1||Io(s)>1)return null;const l=fe(t,at(s));return new ir(n,{anchor:l,focus:l})}function gN(n,t,e,o){return null}function pN(n,t){return n.getBoundingClientRect()}function CN(n,t,e,o){if(e.isSimple()){g(Cr,o.isSimple(),"from is simple position but to is not simple position"),Cr.debug("full select list"),W(t,"full-selected");return}g(Cr,!o.isSimple(),"from is complex position but end is simple position");const r=e,i=o;g(Cr,r.blockId===i.blockId,"only allow update one table selection"),Tf(t).forEach(l=>{const a=at(l);(a===r.childContainerId||a===i.childContainerId)&&W(l,"selected")})}function AN(n){n.rootContainer.querySelectorAll('[data-type="editor-block"][data-block-type="code"]').forEach(t=>{ot(t,"full-selected"),t.querySelectorAll("div[data-type=editor-container].child.selected").forEach(e=>{ot(e,"selected")})})}function bN(n,t){return Tf(t)}function vN(n,t,e,o,r){if(o==="ArrowDown"||o==="ArrowRight"){if(e===Ac(t))return bc(t)}else if(e===bc(t))return Ac(t);return null}function yN(n,t,e,o){const r=Tf(t),i=r.map(at),s=i.indexOf(e.childContainerId),l=i.indexOf(o.childContainerId);g(Cr,s!==-1,"invalid start pos"),g(Cr,l!==-1,"invalid end pos");const a=[r[s]];return s!==l&&a.push(r[l]),a}function kN(n,t,e){g(Cr,Yi(t),"invalid block type"),h7(n,t,e)}async function wN(n,t){const e=await dN(n);if(!e)return null;const{blockData:o,focusBlockId:r}=e;return n.focus(),n.insertBlock(t.containerId,t.blockIndex,o,Ce(n,r,0))}function BN(n){return{name:"CodeBlock",insertBlockCommandItems:[{id:"insert-code",name:R.t("code.title"),icon:ZL,order:300,group:"common",subText:Cn("insert-code")}],handleInsertEmptyBlock:wN}}function EN(){return{abstract:`${R.t("code.abstract")}`}}function xN(n,t,e,o){const r=t,i=a=>{const d=[];return e.blocks[a].forEach(p=>{var A;d.push(ie((A=p.text)!=null?A:[]))}),d.join(`
|
|
415
415
|
`)},s=i(r.children[0]),l=r.children[1]?i(r.children[1]):"";return o==="text"?`${s}
|
|
416
416
|
${l}`:o==="markdown"?`\`\`\`${r.language}
|
|
417
417
|
${s}
|
|
418
418
|
\`\`\`
|
|
419
419
|
${l}`:`<p><pre><code>${s}</code></pre></p>
|
|
420
420
|
<p>${l}</p>`}const Df={blockType:"code",blockKind:"complex",createBlockContent:hN,getBlockTextLength:fN,getRangeFromPoint:mN,moveCaret:gN,getCaretRect:pN,updateSelection:CN,clearSelection:AN,getChildContainers:bN,getNextContainer:vN,getSelectedContainers:yN,convertFrom:NP,handleBlockElementUpdated:kN,getOptions:BN,getBlockProperties:EN,convertTo:xN},j0={...Tn,blockType:"code-line"};class IN{constructor(t){m(this,"handleSelectionChange",()=>{const t=this.editor.selection;if(!t.range.isCollapsed())return;const e=t.focusedBlock;if(!vc(this.editor,e))return;const o=e,r=t.range.focus.offset,i=M4(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 k7(n,t){const e=n.split(`
|
|
421
|
-
`).map(s=>({id:K(),type:"text",text:Oi(s)})),o=K();return{blocks:{root:[{children:[o],type:"code",id:K(),...t}],[o]:e},meta:{},comments:{}}}class TN{handleBeforeCopy(t,e,o){const r=t.getFocusedBlock();if(!vc(t,r))return;const i=O0(r),s=t.getBlockData(i),{language:l,nowrap:a}=s;if(t.selection.range.isCollapsed()){const h=t.getBlockString(r);return k7(h,{language:l,nowrap:a})}const d=t.getSelectedText();return k7(d,{language:l,nowrap:a})}}function DN(n){if(!n.isWritable())return!1;const t=n.getFocusedBlock();if(!!vc(n,t)){if(n.selection.range.isCollapsed()){const e=n.selection.range.start;return n.insertTextToBlock(t,e.offset," "),!0}return n.undoManager.runInGroup(()=>{Ro(n).forEach(o=>{n.insertTextToBlock(o.block,0," ")})}),!0}}function SN(n){if(!n.isWritable())return!1;const t=n.getFocusedBlock();if(!vc(n,t))return;const e=[" "," "];return n.undoManager.runInGroup(()=>{Ro(n).forEach(r=>{const i=ie(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 LN(n){const t=n.getFocusedBlock(),e=nt(t);if(Yt(e))return;const o=et(e);if(!o||Dt(o)!=="code")return;const r=n.selection.range;if(!!r.isSimple()&&!MA(e,r))return Gg(n,e),!0}const MN={Tab:DN,"Shift+Tab":SN,"CtrlOrCmd+A":LN},ku=S("code-text-decorate");class Sf{decorateText(t,e,o){var v;if(g(ku,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=ie(s),a=t.doc.getBlockData(r.containerId,r.blockIndex),d=ua.default.tokenize(l,(v=ua.default.languages[a.language])!=null?v:ua.default.languages.plain),h=(B,D)=>{if(g(ku,B,"no token"),typeof B=="string")return[{insert:B,attributes:mt.default(D)}];g(ku,B instanceof ua.default.Token,"invalid token type");const x=B.content,_=mt.default(D);return _[`style-code-${B.type}`]=!0,typeof x=="string"?[{insert:x,attributes:_}]:Array.isArray(x)?x.map(z=>h(z,_)).flat():(g(ku,x instanceof ua.default.Token,"invalid token"),h(x,_))},A=d.map(B=>h(B,{})).flat();return g(ku,rn(A)===rn(s),"failed to highlight code, text length mismatch"),{text:A}}}const RN={code:{title:"\u4EE3\u7801",abstract:"\u4EE3\u7801",wrap:"\u6362\u884C",copy:"\u590D\u5236",caption:"\u8BF4\u660E",search:"\u8F93\u5165\u5173\u952E\u8BCD\u641C\u7D22",copySuccess:"\u590D\u5236\u6210\u529F"}},ON={code:{title:"Code",abstract:"Code",wrap:"Wrap",copy:"Copy",caption:"Caption",search:"Search",copySuccess:"Copied successfully"}},_N={code:{title:"\u30B3\u30FC\u30C9",abstract:"\u30B3\u30FC\u30C9",wrap:"\u6298\u308A\u8FD4\u3059",copy:"\u8907\u88FD",caption:"\u4F8B\u8A3C\u3059\u308B",search:"\u30AD\u30FC\u30EF\u30FC\u30C9\u3067\u691C\u7D22",copySuccess:"\u30B3\u30D4\u30FC\u3055\u308C\u307E\u3057\u305F"}};R.mergeLang({"zh-CN":RN,"en-US":ON,"ja-JP":_N});const FN=S("image-data"),w7=1e3,U0=400,PN=10;function yc(n){return n.src.startsWith("empty:")||!n.src}function NN(n){return n.src.startsWith("http:")||n.src.startsWith("https:")}function B7(n){return`${Pd.default(n)}_width`}function E7(n){return`${Pd.default(n)}_height`}function x7(n){return`${n}_flex`}function I7(n){let t=n.getBoundingClientRect().width;return t-=Number.parseFloat(window.getComputedStyle(n).paddingLeft)+Number.parseFloat(window.getComputedStyle(n).paddingRight),t}function wu(n){if(n.every(r=>typeof r.flex=="number"&&r.flex))return;const t=100,o=n.map(r=>{const i=r.height==="auto"?r.width/t:r.height/t;return r.width/i}).reduce((r,i)=>r+i,0);n.forEach(r=>{const i=r.height==="auto"?r.width/t:r.height/t,s=r.width/i;r.flex=s/o})}function kc(n){const t=(r,i)=>{r||(r=`empty:${i}`);const s=B7(r),l=E7(r),a=x7(i);let d=n[s],h=n[l],p=n[a];return typeof d=="string"&&(d=Number.parseInt(d,10)),typeof h=="string"&&(h=Number.parseInt(h,10)),typeof p=="string"&&(p=Number.parseInt(p,10)),d&&h?{src:r,width:d,height:h,flex:p,virtualSize:!1}:d&&!h?{src:r,width:d,height:"auto",flex:p,virtualSize:!1}:(d=w7,h=U0,{src:r,width:d,height:h,flex:p,virtualSize:!0})};let e=[];const o=n.src;return Array.isArray(o)?e=o.map(t):typeof o=="string"&&(e=o.split("|").map(t)),wu(e),e}function Vo(n){const t=n.embedData;return kc(n.embedData).length>1?100:t.widthPercent}function $N(n,t,e,o){const r=kc(t.embedData);if(r.length>1||o)return"100%";const i=Vo(t),s=n.rootContainer.getBoundingClientRect().width;if(i){const l=I7(e);return`${Math.min(s*i/100,l)}px`}return r[0].width?`${r[0].width}px`:"auto"}function cn(n,t){const o={src:n.map(r=>r.src).join("|"),widthPercent:t};return n.forEach((r,i)=>{if(r.width&&r.height&&!r.virtualSize){const l=r.src||`empty:${i}`,a=B7(l);o[a]=r.width;const d=E7(l);r.height!=="auto"&&(o[d]=r.height)}g(FN,r.flex,"no image flex");const s=x7(i);o[s]=r.flex}),o}function HN(n,t,e,o){const r=kc(t.embedData),i=r.length===1?n.rootContainer:e;if(r.length===1&&o)return`${U0}px`;if(r.some(h=>h.height==="auto"))return"auto";const s=Vo(t);if(!s)return"";let l=i.getBoundingClientRect().width*(s/100);if(l-=Number.parseFloat(window.getComputedStyle(i).paddingLeft)+Number.parseFloat(window.getComputedStyle(i).paddingRight),i===n.rootContainer&&i!==e&&(l=Math.min(l,I7(e))),r.length===1){const h=r[0];return h.virtualSize?"":`${h.height/(h.width/l)}px`}l-=(r.length-1)*PN;const a=r.reduce((h,p)=>h+p.flex,0);let d=0;for(const h of r){const A=l*h.flex/a/h.width*h.height;d=Math.max(A,d)}return`${d}px`}function jN(n){return n.reduce((e,o)=>e+o.flex,0)}function UN(n,t){w("div",["resize-gripper",t],n).setAttribute("data-resize-type",t)}function z0(n){return te(n).querySelector(".block-resizer")}function zN(n){const t=z0(n);t&&ot(t,"active")}function T7(n,t,e){const o=n.getBoundingClientRect(),r=t.getBoundingClientRect(),i=r.top-o.top,s=r.left-o.left,l=r.width,a=r.height;e.style.top=`${i}px`,e.style.left=`${s}px`,e.style.width=`${l}px`,e.style.height=`${a}px`}function VN(n,t,e,o){const r=z0(n);if(r)return W(r,"active"),T7(n,t,r),r;const i=te(n),s=w("div",["block-resizer"],i);return T7(n,t,s),e.resize.forEach(l=>{UN(s,l)}),s.addEventListener("mousedown",o),W(s,"active"),s}function V0(n,t){const e=z0(n);if(!e||!Xt(n,t))return;const o=n.getBoundingClientRect(),r=t.getBoundingClientRect(),i=r.top-o.top,s=r.left-o.left,l=r.width,a=r.height;e.style.top=`${i}px`,e.style.left=`${s}px`,e.style.width=`${l}px`,e.style.height=`${a}px`}const Fnt="",WN=S("block-resizer");class Bu extends ye.TypedEmitter{constructor(e,o){super();m(this,"resizableElement");m(this,"block",null);m(this,"startRect",null);m(this,"startPos",null);m(this,"resizeType",null);m(this,"enabled",!1);m(this,"handleMouseDown",e=>{e.preventDefault(),e.stopPropagation();const o=this.getResizableElement();if(!o||e.button!==0)return;const r=e.target;if(!r||!(r instanceof HTMLElement))return;const i=r.getAttribute("data-resize-type");!i||(this.bindEvents(),this.startRect=o.getBoundingClientRect(),this.startPos=e,this.resizeType=i,ga(window.getComputedStyle(r).cursor),this.block&&this.editor.selection.selectBlock(this.block,0))});m(this,"handleMouseMove",e=>{if(!this.startPos||!this.startRect||!this.resizeType||!this.getResizableElement()||!this.block)return;const r=e.x-this.startPos.x,i=e.y-this.startPos.y,s=this.startRect;let{top:l,left:a,right:d,bottom:h}=s;(this.resizeType==="bottom"||this.resizeType==="bottom-left"||this.resizeType==="bottom-right")&&(h+=i),(this.resizeType==="top"||this.resizeType==="top-left"||this.resizeType==="top-right")&&(l+=i),(this.resizeType==="left"||this.resizeType==="top-left"||this.resizeType==="bottom-left")&&(a+=r),(this.resizeType==="right"||this.resizeType==="top-right"||this.resizeType==="bottom-right")&&(d+=r);const p=d>a?d-a:0,A=h>l?h-l:0,v=new DOMRect(a,l,p,A);this.emit("resizing",this,v);const B=this.getResizableElement();B&&V0(this.block,B)});m(this,"handleMouseUp",e=>{if(e.button!==0)return;ga(""),this.unbindEvents(),this.emit("resized",this);const o=this.getResizableElement();!o||!this.block||V0(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||(zN(this.block),this.enabled=!1)}update(e,o){this.block=e,this.resizableElement=o,this.getResizableElement()&&this.enabled&&this.createResizer()}updateResizer(){const e=this.getResizableElement();e&&this.block&&V0(this.block,e)}getBlock(){return this.block}destroy(){}getResizableElement(){return this.resizableElement?this.resizableElement:this.block?Lt(this.block):null}createResizer(){const e=this.getResizableElement();!e||!this.block||(g(WN,Xt(this.block,e),"not a block child element"),VN(this.block,e,this.options,this.handleMouseDown))}bindEvents(){document.addEventListener("mousemove",this.handleMouseMove),document.addEventListener("mouseup",this.handleMouseUp)}unbindEvents(){document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp)}}const qN=S("image-dom");function D7(n){return n.querySelector(".uploading-progress-mask")}function GN(n){const t=D7(n);if(t)return t;const e=w("div",["uploading-progress-mask"],n),o=w("div",["uploading-progress-bar"],e);return w("div",["uploading-progress-bar-value"],o),o}function ZN(n){const e=GN(n).querySelector(".uploading-progress-bar-value");return g(qN,e,"no progress value"),e}function S7(n,t){const e=ZN(n);e.style.width=`${t}%`}function QN(n){var t;(t=D7(n))==null||t.remove()}function Eu(n,t,e,o){const r=e!=null?e:n.findBlockById(t.id);if(!r)return;const i=o||nt(r),s=!!r.querySelector(".images > .image-container.error, .images > .image-container.empty "),l=$N(n,t,i,s),a=HN(n,t,i,s),d=Lt(r);l==="auto"?d.style.width=l:(d.style.maxWidth=l,d.style.width="100%");const h=r.querySelector(".images");!h||(h.style.height=a||"none")}function YN(n){let t;return n.forEach((e,o)=>{o.toLocaleLowerCase()==="content-type"&&(t=e)}),t!=null?t:""}async function JN(n){try{const t=await fetch(n,{credentials:"same-origin"}),e=await t.blob(),o=YN(t.headers).toLocaleLowerCase();let r="";if(o){const s=mm.default[o].extensions;s&&s.length>0&&(r=s[0])}return new File([e],`${Date.now()}.${r}`,{type:o})}catch{return null}}function Ji(n,t){const e=typeof t=="string"?t:it(t);return n.getCustom(`image-${e}`)}function Lf(n,t){if(!t||!(t instanceof Node))return null;const e=et(t);return e?Ji(n,e):null}function Cr(n){return Array.from(n.querySelectorAll(".image-container"))}const W0=S("table-resize-drag-drop");class KN{constructor(t,e,o,r){m(this,"cursor","col-resize");m(this,"initWidths");this.editor=t,this.elem=e,this.data=o,this.mouseDownEvent=r;const i=this.data.block,l=Ji(this.editor,i).getImages(),a=this.data.splitterIndex;g(W0,a>=0&&a<l.length-1,`invalid splitter index: ${a}`);const h=Cr(i).map(p=>p.getBoundingClientRect().width);this.initWidths=h}onDragStart(t,e,o){if(!this.editor.isWritable())return;const r=this.data.block;Ji(this.editor,r).setResizing(!0)}onDragging(t,e,o,r,i){const s=this.data.block,l=Ji(this.editor,s),a=mt.default(l.getImages()),d=this.data.splitterIndex;g(W0,d>=0&&d<a.length-1,`invalid splitter index: ${d}`);const h=this.initWidths[d],p=this.initWidths[d+1];if(h+p<100)return;let A=r;h+A<50&&(A=50-h),p-A<50&&(A=p-50);const D=[...this.initWidths];D[d]+=A,D[d+1]-=A;const x=Cr(s);g(W0,x.length===a.length,"invalid image data");const _=D.reduce((z,q)=>z+q,0);for(let z=0;z<a.length;z++){const q=D[z]/_;a[z].flex=q,x[z].style.flexGrow=`${q}`}const M=mt.default(this.editor.getBlockData(s)),H=cn(a,Vo(M));M.embedData=H,Eu(this.editor,M,s,null)}onDragEnd(t,e,o,r,i){const s=this.data.block,l=Ji(this.editor,s),d=Cr(s).map(h=>Number.parseFloat(h.style.flexGrow));l.updateFlex(d),l.setResizing(!1)}}function L7(n){var t;return!n||!(n instanceof HTMLElement)?null:xt(n,"image-splitter")?n:(t=n.closest(".image-splitter"))!=null?t:null}function XN(n,t){var s;const e=L7(t.target);if(!e)return;const o=et(e);if(!o)return;Ji(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};km(new KN(n,e,i,t))}function t$(n,t){t.preventDefault(),t.stopPropagation();const e=L7(t.target);if(!e)return;const o=et(e);!o||Ji(n,o).resetFlex()}function e$(n,t,e,o){const r=w("div",["image-splitter"],e);w("div",["image-splitter-indicator"],r),r.setAttribute("data-index",`${o}`),n.domEvents.addEventListener(r,"mousedown",XN),n.domEvents.addEventListener(r,"dblclick",t$)}const n$=S("image-item");function M7(n){return!n||!(n instanceof Node)?null:et(n)}function R7(n){const t=M7(n);return t?Cr(t):[]}function q0(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 xu(n){const t=q0(n);return t?R7(n).indexOf(t):-1}async function o$(n,t){const e=Lf(n,t.target);if(!e)return;const o=xu(t.target);if(o===-1)return;const r=t.target;if(!(r instanceof HTMLImageElement))return;const i=e.getImages()[o];if(yc(i)||n.readonly||!e.isAutoFix()||(setTimeout(()=>{e.setAutoFix(!1)},400),i.height==="auto"&&e.fixImageSize(o,r),i.virtualSize&&e.fixImageSize(o,r),!i||!NN(i)||i.downloading))return;i.downloading=!0;const s=await JN(i.src);s?e.replaceImage(o,s):n$.warn(`failed to download image: ${i.src}`)}function r$(n,t,e){if(t.querySelector(".load-error"))return;const r=e.src.startsWith("http:")||e.src.startsWith("https:"),i=w("div",["load-error"],t),s=w("div",["error-icon"],i);s.innerHTML=av;const l=w("div",["error-message"],i);r?(l.innerHTML=R.t("image.load.remote.failed"),n.domEvents.addEventListener(i,"click",(a,d)=>{d.preventDefault(),d.target instanceof HTMLElement&&d.target.tagName==="A"&&window.open(e.src,"_blank")})):(l.innerHTML=R.t("image.load.failed"),n.domEvents.addEventListener(i,"click",(a,d)=>{d.preventDefault(),d.stopPropagation(),d.target instanceof HTMLElement&&d.target.tagName==="A"&&c$(a,d.target)}))}function G0(n,t){setTimeout(()=>{if(Xt(n.rootContainer,t)){const e=n.getBlockData(t);Eu(n,e,null,null)}})}function i$(n,t){const e=Lf(n,t.target);if(!e)return;const o=xu(t.target);if(o===-1)return;const r=e.getImages()[o];if(!r)return;const i=q0(t.target);if(!i)return;W(i,"error","error-load");const s=et(i);s&&G0(n,s),i.innerHTML="",r$(n,i,r)}function s$(n,t,e){if(t.querySelector(".upload-error"))return;const r=w("div",["upload-error"],t),i=w("div",["error-icon"],r);i.innerHTML=av;const s=w("div",["error-message"],r);s.innerHTML=R.t("image.upload.failed"),n.domEvents.addEventListener(r,"click",(l,a)=>{if(a.preventDefault(),!a.target||!(a.target instanceof Element)||a.target.tagName!=="A")return;const d=Lf(l,a.target),h=xu(a.target);!d||h===-1||d.replaceImage(h,e)})}function O7(n,t,e,o,r){const i=Cr(t)[e];!i||(W(i,"error","error-upload"),G0(n,t),i.innerHTML="",s$(n,i,r))}function _7(n,t,e,o,r,i,s){const l=w("div",["image-container"],e);if(l.setAttribute("data-src",o.src),s.length>1&&(l.style.flexShrink=`${o.flex}`,l.style.flexGrow=`${o.flex}`),i===r&&W(l,"active"),yc(o)){W(l,"empty");const d=w("div",["upload-image-icon"],l);return d.innerHTML=ML,l}const a=w("img",["editor-image"],l);if(a.src=n.doc.buildResourceUrl(o.src),n.domEvents.addEventListener(a,"load",o$),n.domEvents.addEventListener(a,"error",i$),o.src.startsWith("https:")||o.src.startsWith("http:")){const d=w("div",["image-warning"],l);d.innerHTML=cv,d.setAttribute(`data-editor-tooltip-${n.clientId}`,R.t("image.load.remote.tooltip"))}return l}function l$(n,t,e,o,r){const i=w("div",["images"],e);return o.forEach((s,l)=>{l>0&&e$(n,t,i,l-1),_7(n,t,i,s,l,r,o)}),o.length>1&&W(t,"multi"),i}function F7(n,t,e,o,r,i){const l=Array.from(t.querySelectorAll(".image-container"))[o];if(!l)return;const a=_7(n,t,null,e,o,r,i);l.insertAdjacentElement("beforebegin",a),l.remove(),G0(n,t)}function Iu(n,t){return Cr(n)[t]}function c$(n,t){const e=M7(t);if(!e)return;const o=xu(t);if(o===-1)return;const r=Lf(n,t);if(!r)return;const i=r.getImages()[o];F7(n,e,i,o,r.getSelectedIndex(),r.getImages())}function Wo(n){return Dt(n)==="embed"&&fn(n)==="image"}async function P7(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 a$(n){const t=await jl(n);return P7(t)}function N7(n){var o;let t="image/*";const e=(o=n.getComponentOptions("image"))==null?void 0:o.allowedMedias;return e&&(t=e.map(r=>`.${r}`).join(",")),t}function $7(n,t){var s;const{maxSize:e,allowedMedias:o,callbacks:r}=(s=n.getComponentOptions("image"))!=null?s:{};if(e&&t.size>e){const l=new Error("image is too large");throw l.code="MaxMediaSize",r!=null&&r.onError&&(r==null||r.onError(n,l)),l}const i=Aa(t.name);if(o&&!o.includes(i)){const l=new Error(`media file is not allowed: ${i}`);throw l.code="NotAllowedFile",r!=null&&r.onError&&(r==null||r.onError(n,l)),l}}function H7(n){return n.startsWith("image/")}const j7=S("image-object");class Ie{constructor(t,e){m(this,"images",[]);m(this,"selectedIndex",-1);m(this,"blockResizer");m(this,"resizing",!1);m(this,"parentContainerResizerObserver",null);m(this,"autoFix",!1);m(this,"handleMouseDown",async(t,e)=>{const o=xu(e.target);if(o===-1)return;const r=this.images[o];yc(r)||this.setSelectedIndex(o)});m(this,"handleRootContainerResize",()=>{this.handleEditorResize(this.editor.rootContainer)});m(this,"handleEditorResize",t=>{if(this.isEmpty()||this.resizing)return;const e=this.editor.findBlockById(this.blockData.id);!e||nt(e)===t&&Eu(this.editor,this.blockData,e,null)});m(this,"handleResizing",(t,e)=>{const o=this.editor.findBlockById(this.blockData.id);if(!o)return;this.autoFix||this.setAutoFix(!0);const i=this.editor.rootContainer.getBoundingClientRect().width,s=o.getBoundingClientRect();let l=e.width>s.width?s.width:e.width;l<50&&(l=50);const a=l*100/i;this.blockData.embedData.widthPercent=a,Eu(this.editor,this.blockData,o,null)});m(this,"handleResized",t=>{const e=this.editor.findBlockById(this.blockData.id);if(!e)return;const o=cn(this.images,Vo(this.blockData));this.editor.updateEmbedData(e,o),this.blockResizer.enableResize(e)});m(this,"fixImageSizes",Le.default(()=>{const t=this.editor.findBlockById(this.blockData.id);if(!t)return;const e=cn(this.images,Vo(this.blockData));this.editor.updateEmbedData(t,e)},1e3));this.editor=t,this.blockData=e,this.blockResizer=new Bu(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=kc(this.blockData.embedData)}destroy(){var t;this.blockResizer.removeAllListeners(),this.blockResizer.destroy(),this.editor.domEvents.removeEventListener(null,null,this.handleMouseDown),(t=this.parentContainerResizerObserver)==null||t.disconnect()}setAutoFix(t){this.autoFix=t}isAutoFix(){return this.autoFix}createContent(t,e,o){const r=l$(this.editor,e,o,this.images,this.selectedIndex);if(this.editor.domEvents.addEventListener(o,"mousedown",this.handleMouseDown),this.editor.addListener("resize",this.handleRootContainerResize),Lo(t)){const s=()=>{this.handleEditorResize(t)};this.parentContainerResizerObserver=new ResizeObserver(s),this.parentContainerResizerObserver.observe(t)}const i=()=>!!(this.images.length===1&&this.images[0].virtualSize);this.isEmpty()&&i()&&W(r,"empty"),Eu(this.editor,this.blockData,e,t),setTimeout(()=>{const s=this.editor.findBlockById(this.blockData.id);s&&this.blockResizer.update(s)})}getImages(){return this.images}getWidthPercent(){return Vo(this.blockData)}isEmpty(){return this.images.length===1&&yc(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=Iu(e,this.selectedIndex);r&&ot(r,"active")}this.selectedIndex=t;const o=Iu(e,t);o&&W(o,"active")}async requestUploadImage(t){const e=this.editor.findBlockById(this.blockData.id);if(!e)return;const o=Iu(e,t);if(xt(o,"error"))return;const r=N7(this.editor),i=await Ul(r);await this.replaceImage(t,i)}tryEnableResizer(){const t=this.editor.findBlockById(this.blockData.id);if(!t||!this.editor.isWritable())return;const e=Iu(t,0);!this.isEmpty()&&this.images.length===1&&!xt(e,"error")&&this.blockResizer.enableResize(t)}disableResizer(){this.blockResizer.disableResize()}fixImageSize(t,e){const o=this.images[t];yc(o)||(o.height==="auto"&&(o.height=e.height),o.width=e.naturalWidth,o.height=e.naturalHeight,o.virtualSize=!1,this.fixImageSizes())}removeImage(t){const e=this.editor.findBlockById(this.blockData.id);if(!e||t===-1||t>=this.images.length)return!1;const o=mt.default(this.images);if(o.splice(t,1),o.length===0)return this.editor.deleteBlock(e),!0;o[0].flex=NaN,wu(o),this.selectedIndex>=o.length&&(this.selectedIndex=o.length-1);const r=cn(o,Vo(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 jl(e),s=this.images[t];if(s.virtualSize){const{width:a,height:d}=await P7(i);s.width=a,s.height=d,s.virtualSize=!1;const h=cn(this.images,Vo(this.blockData));this.editor.updateEmbedData(o,h)}const l={...s,src:i};F7(this.editor,o,l,t,this.selectedIndex,this.images),setTimeout(()=>{this.blockResizer.update(o)})}catch(i){return O7(this.editor,o,t,i,e),!1}const r=Iu(o,t);if(!r)return!1;W(r,"uploading"),S7(r,0),W(o,"media-block-uploading");try{const i=await this.editor.doc.uploadResource(e,{onProgress:a=>{S7(r,a)}});ot(r,"uploading"),this.images[t].src=i.resourceId;const s=this.editor.findBlockById(this.blockData.id);if(!s)return!1;ot(s,"media-block-uploading");const l=cn(this.images,Vo(this.blockData));return this.editor.updateEmbedData(s,l),!0}catch(i){j7.error(i);const s=this.editor.findBlockById(this.blockData.id);return s&&(ot(r,"uploading"),QN(r),O7(this.editor,s,t,i,e),ot(s,"media-block-uploading")),!1}}updateFlex(t){const e=this.editor.findBlockById(this.blockData.id);if(!e)return;g(j7,t.length===this.images.length,"invalid flex");for(let r=0;r<this.images.length;r++)this.images[r].flex=t[r];const o=cn(this.images,Vo(this.blockData));this.editor.updateEmbedData(e,o)}resetFlex(){const t=this.editor.findBlockById(this.blockData.id);if(!t)return;const e=mt.default(this.images);e[0].flex=NaN,wu(e);const o=cn(e,Vo(this.blockData));this.editor.updateEmbedData(t,o)}setData(t){this.blockData=t,this.images=kc(t.embedData)}static create(t,e){const o=t.addCustom(`image-${e.id}`,()=>new Ie(t,e));return o.setData(e),o}static getImageObject(t,e){let o;return typeof e=="string"?o=e:o=it(e),t.getCustom(`image-${o}`)}}const Pnt="",Nnt="";function Mf(n){const t=te(n);let e=t.querySelector(":scope > .block-helper");return e||(e=w("div",["block-helper"],t),w("span",["helper-sizer"],e,"A")),e}function Z0(n,t,e){const o=Mf(n),i=Array.from(o.children).find(s=>{var a;return Number.parseInt((a=s.getAttribute("data-index"))!=null?a:"0",10)>e});o.insertBefore(t,i!=null?i:null)}const U7=40,u$=20;class d${findTargetBlock(t,e){const o=e.target;if(o&&o instanceof Element){const a=et(o);if(a&&Xt(t.rootContainer,a))return a}let r=e.clientX,i=e.clientY;const s=t.rootContainer.getBoundingClientRect().left;r<s&&s-r<U7&&(r+=U7);let l=document.elementFromPoint(r,i);if(l){const a=et(l);if(a&&Xt(t.rootContainer,a))return a}if(i-=u$,l=document.elementFromPoint(r,i),l){const a=et(l);if(a&&Xt(t.rootContainer,a))return a}return null}destroy(){}}class h$ extends Cf{constructor(e){super(e,{trigger:[],id:"empty-block-menu"});m(this,"currentBlock",null)}get isVisible(){return this.suggest.menu.isVisible}isInMenu(e){return this.menu.isInCommandBar(e)}show(){const o=this.editor.selection.focusedBlock;this.suggest.popup(o,0,"","")}setBlock(e){this.currentBlock=e}}function f$(n,t,e){const o=zm(n,t);if(!o)return[];const r=[];return Object.values(o).forEach(i=>{e!=null&&e.has(i.group)||r.push(...i.commands.map(s=>({...s,source:"block-command",blockMenuItemCustomData:i.group})))}),r}function Q0(n,t,e={withPlainText:!1}){const o=T0(n,e),r=i=>{i.forEach(s=>{s.source=t,s.children&&r(s.children)})};return r(o),o}function m$(n,t,e,o=!1){var d,h;const r=nt(t);let s=bt(t);he(n,t)||o||(s+=1);const l=at(r),a=e;return a.commandProvider?a.commandProvider.executeCommand(n,e,{from:"block-menu",containerId:l,blockIndex:s}):(h=(d=a.blockOptions)==null?void 0:d.handleInsertEmptyBlock)==null?void 0:h.call(d,n,{containerId:l,blockIndex:s,item:e})}function g$(n,t){const e=Do(n,t),o=n.getBlockData(t);return!(e!=="text"||o.heading)}class z7{constructor(t,e,o){m(this,"source","text-style");m(this,"id","text-style-item");m(this,"name","Text styles");m(this,"element");m(this,"createHeadingItemElement",(t,e,o)=>{var i;const r=w0();this.createItem("text",ou,e,g$(this.editor,t)),(i=r.insertBlockCommandItems)==null||i.forEach(s=>{s.id&&s.icon&&this.createItem(s.id,s.icon,e,o?o===Number(s.value):!1)})});m(this,"createListItemElement",(t,e,o)=>{const{checkbox:r,ordered:i}=o,l=Dt(t)==="list",a=l&&i===!1&&!r,d=l&&i,h=l&&!!r;this.createItem("unordered-list",gv,e,a),this.createItem("ordered-list",pv,e,d),this.createItem("check-list",fv,e,h)});m(this,"handleClick",(t,e)=>{var l,a;if(!e.target||!(e.target instanceof Node))return;const o=e.target instanceof Element?e.target:e.target.parentElement;if(!o)return;const r=o.closest(".text-style-item");if(!r)return;const i=r.id,s="heading-";if(i==="text"&&gf(t,this.block,null),i.startsWith(s)){const d=Number.parseInt(i.substring(s.length),10);d&&gf(t,this.block,d)}if(i==="blockquote"&&v0(t,this.block),i.startsWith("align")){const d=i.replace(/^align-/,"");T9(t,this.block,d)}(i==="unordered-list"||i==="ordered-list"||i==="check-list")&&k0(t,this.block,i),(a=(l=this.options).onAfterStyleItemClick)==null||a.call(l)});this.editor=t,this.block=e,this.options=o,this.element=this.createItemElement(t,e),t.domEvents.addEventListener(this.element,"click",this.handleClick)}createItemElement(t,e){const o=w("div",["text-styles"],null),r=w("div",["text-style-section"],o),i=t.getBlockData(e);if(!this.options.fromEmbed){const l=i.heading,a=i.quoted;this.createHeadingItemElement(e,r,l),this.createListItemElement(e,r,i),this.createItem("blockquote",mv,r,!!a)}const s=i.align||"left";return this.createItem("align-left",eu,r,s==="left"),this.createItem("align-center",Tp,r,s==="center"),this.createItem("align-right",Ip,r,s==="right"),o}createItem(t,e,o,r=!1){const i=["style-icon","text-style-item"];r&&i.push("active");const s=$l(e,i,o);s.id=t}}function V7(){return{source:"separator",type:"separator",id:`section-${K()}`,name:""}}const W7={copy:QL,cut:YL,delete:JL,"lock-block":KL,"unlock-block":XL,comment:nu},p$=["image","video"];function C$(n,t,e){const o=[],r=tt(n,t),i=Me(t)&&p$.includes(fn(t)),s=i&&(fn(t)!=="image"||fn(t)==="image"&&Cr(t).length===1);if(r?o.push(new z7(n,t,e)):i&&s&&o.push(new z7(n,t,{...e,fromEmbed:!0})),!he(n,t)){(r||i&&s)&&o.push(V7());const l=f$(n,t,new Set(["hovering-toolbar"]));l.sort((a,d)=>{var h,p;return((h=a.order)!=null?h:0)-((p=d.order)!=null?p:0)}),l.forEach(a=>{a.id in W7&&(a.icon=W7[a.id])}),o.push(...l)}return he(n,t)?o.push(...Q0(n,"insert-block")):o.push(V7(),{id:"insert-block-before",icon:tM,name:R.t("blockMenu.command.insertAbove"),children:Q0(n,"insert-block-before",{withPlainText:!0}),childrenMenuId:"quick-menu",source:"insert-block-before"},{id:"insert-block-after",icon:eM,name:R.t("blockMenu.command.insertAfter"),children:Q0(n,"insert-block",{withPlainText:!0}),source:"insert-block",childrenMenuId:"quick-menu"}),o}function A$(n,t,e){if(e.source==="block-command"){const o=e.blockMenuItemCustomData;u4(n,t,o,e)}else(e.source==="insert-block"||e.source==="insert-block-before")&&m$(n,t,e,e.source==="insert-block-before")}const b$=S("exclusive-block");function Y0(n,t,e,o){var l;W(t,"block-exclusive");const r=Qt(n,t),i=(l=r.getBlockProperties)==null?void 0:l.call(r,n,t),{abstract:s}=i||{};t.setAttribute("data-user-name",o),t.setAttribute("data-user-id",e),t.setAttribute("data-exclusive-tips",R.t("exclusive.tips",{editor:o,embedType:s||R.t("exclusive.fallbackAbstract")}))}function q7(n){ot(n,"block-exclusive"),n.removeAttribute("data-user-name"),n.removeAttribute("data-user-id"),n.removeAttribute("data-exclusive-tips")}function v$(n,t,e,o,r){b$.debug(`block ${it(t)} ${e?"exclusive":"unexclusive"}, ${o}, ${r}`),e?Y0(n,t,o,r):q7(t)}function Rf(n){return n.classList.contains("block-exclusive")}function G7(n,t){t.blockIds.forEach(e=>{const o=n.findBlockById(e);o&&v$(n,o,t.exclusive,t.userId,t.displayName)})}class Ki{constructor(t){m(this,"exclusiveBlockIds",new Set);m(this,"exclusiveBlockTimer",0);m(this,"remoteExclusiveBlockIds",new Map);m(this,"handleUserChanged",t=>{const e=new Set(t.map(r=>r.userId));Array.from(this.remoteExclusiveBlockIds.entries()).forEach(([r,i])=>{if(!e.has(i.userId)){this.remoteExclusiveBlockIds.delete(r);const s={...i,exclusive:!1};G7(this.editor,s)}});const o=Array.from(this.exclusiveBlockIds).map(r=>this.editor.findBlockById(r)).filter(r=>!!r);o.length>0&&this.broadcastExclusiveBlockMessage(o,!0)});this.editor=t,t.doc.registerCallback(this),t.doc.getRemoteUsers().addListener("change",this.handleUserChanged)}destroy(){this.stopExclusiveBlockTimer(),this.editor.doc.unregisterCallback(this),this.editor.doc.getRemoteUsers().addListener("change",this.handleUserChanged)}onCustomMessage(t){if(t.type==="exclusiveBlock"){const e=t;G7(this.editor,e),e.blockIds.forEach(o=>{e.exclusive?this.remoteExclusiveBlockIds.set(o,e):this.remoteExclusiveBlockIds.delete(o)})}}getExclusiveMessage(t){return this.remoteExclusiveBlockIds.get(t)}broadcastExclusiveBlockMessage(t,e){if(this.editor.readonly||t.length===0)return;const o=this.editor.doc.getUser(),r={type:"exclusiveBlock",userId:o.userId,displayName:o.displayName,blockIds:t.map(i=>it(i)),exclusive:e};this.editor.doc.broadcastMessage(r)}exclusiveBlock(t){this.exclusiveBlockIds.has(it(t))||(this.broadcastExclusiveBlockMessage([t],!0),this.exclusiveBlockIds.add(it(t)),this.exclusiveBlockIds.size===1&&this.startExclusiveBlockTimer())}unexclusiveBlock(t){!this.exclusiveBlockIds.has(it(t))||(this.exclusiveBlockIds.delete(it(t)),this.broadcastExclusiveBlockMessage([t],!1),this.exclusiveBlockIds.size===0&&this.stopExclusiveBlockTimer())}startExclusiveBlockTimer(){this.exclusiveBlockTimer=window.setInterval(()=>{Array.from(this.exclusiveBlockIds.keys()).forEach(t=>{this.broadcastExclusiveBlockMessage([this.editor.getBlockById(t)],!0)})},30*1e3)}stopExclusiveBlockTimer(){clearInterval(this.exclusiveBlockTimer),this.exclusiveBlockTimer=0}static get(t){return t.addCustom("exclusiveBlock",()=>new Ki(t))}static register(t){return this.get(t)}}function J0(n,t){Ki.get(n).exclusiveBlock(t)}function K0(n,t){Ki.get(n).unexclusiveBlock(t)}class Z7{writable(t,e){if(Rf(e))return!1}create(t,e,o,r,i){const s=Ki.get(t).getExclusiveMessage(i.id);s&&Y0(t,r,s.userId,s.displayName)}update(t,e,o,r,i){const s=Ki.get(t).getExclusiveMessage(i.id);s?Y0(t,r,s.userId,s.displayName):q7(r)}}const $nt="",y$={exclusive:{tips:"\u300C{editor}\u300D\u6B63\u5728\u7F16\u8F91\uFF0C\u300C{embedType}\u300D\u4E0D\u652F\u6301\u591A\u4EBA\u7F16\u8F91",fallbackAbstract:"\u8BE5 Block"}},k$={exclusive:{tips:"\u300C{editor}\u300Dis editing\uFF0C\u300C{embedType}\u300Ddoes not support multi-person editing",fallbackAbstract:"This Block"}},w$={exclusive:{tips:"\u300C{editor}\u300D\u306F\u7DE8\u96C6\u4E2D\u3067\u3059\u3002\u300C{embedType}\u300D\u306F\u8907\u6570\u4EBA\u3067\u540C\u6642\u7DE8\u96C6\u3067\u304D\u307E\u305B\u3093",fallbackAbstract:"\u3053\u306E\u8981\u7D20"}};R.mergeLang({"zh-CN":y$,"en-US":k$,"ja-JP":w$});function Tu(n,t){return n.getBlockData(t).lock}function Of(n,t){return!!Tu(n,t)}function Du(n,t){const e=Tu(n,t);return e?e.userId===n.doc.getUser().userId:!1}function X0(n,t){const e=Tu(n,t);return e?e.userId!==n.doc.getUser().userId:!1}function B$(n,t){if(n.readonly||!n.isBlockWritable(t)||Of(n,t)&&!Du(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 E$(n,t){if(!Du(n,t))return;const e={lock:null};n.updateBlockData(t,e)}const x$=10,I$=80;class t2{constructor(){m(this,"executeCommand",(t,e,o)=>{const r=o.data;if(!r||!r.blockId)return;const i=t.getBlockById(r.blockId);r.type==="lock"?B$(t,i):r.type==="unlock"&&E$(t,i)})}create(t,e,o,r,i){const s=i.lock;s&&(s.userId!==t.doc.getUser().userId?W(r,"locked-by-others"):W(r,"locked-by-self"))}update(t,e,o,r,i){const s=i.lock;if(s)if(s.userId!==t.doc.getUser().userId){W(r,"locked-by-others");const l=t.selection.focusedBlock;(l===r||Xt(r,l))&&(tt(t,r)||Dt(r)==="code")&&t.insertTextBlock("",at(o),bt(r)+1)}else W(r,"locked-by-self");else ot(r,"locked-by-others"),ot(r,"locked-by-self")}writable(t,e){if(X0(t,e))return!1;if(io(e))return;let o=xs(e);for(;o;){if(X0(t,o))return!1;o=xs(o)}}commands(t,e){const o=Of(t,e),r=Du(t,e),i=Rf(e),s={blockId:it(e),type:"lock"},l={id:"lock-block",name:"",data:s,order:10};if(o)if(r)l.id="unlock-block",l.name=R.t("locker.unlock"),s.type="unlock";else{const a=Tu(t,e);let d=(a==null?void 0:a.displayName)||"";const h=RC(d,x$,I$);(h==null?void 0:h.length)!==d.length&&(l.ellipsisTooltip=a==null?void 0:a.displayName,d=h||""),l.name=R.t("locker.lockedBy",{name:d}),l.states=["disabled"]}else i?(l.name=R.t("locker.lock"),l.states=["disabled"]):l.name=R.t("locker.lock");return{group:"block-locker",commands:[l],executeCommand:this.executeCommand}}}const Hnt="",T$={locker:{lock:"\u9501\u5B9A",unlock:"\u89E3\u9664\u9501\u5B9A",lockedBy:"\u88AB {name} \u9501\u5B9A"}},D$={locker:{lock:"Lock",unlock:"Unlock",lockedBy:"Locked by {name}"}},S$={locker:{lock:"\u30ED\u30C3\u30AF",unlock:"\u30ED\u30C3\u30AF\u89E3\u9664",lockedBy:"{name}\u304C\u30ED\u30C3\u30AF\u3057\u307E\u3057\u305F"}};R.mergeLang({"zh-CN":T$,"en-US":D$,"ja-JP":S$});class _f{async handleBeforePasteDoc(t,e){return Object.values(e.blocks).forEach(o=>{o.forEach(r=>{delete r.lock})}),!1}}const L$=S("standard-block-actions");class M${constructor(){m(this,"executeCommand",(t,e,o)=>{const r=o.data;try{const i=t.getBlockById(r);if(o.id==="delete"){t.deleteBlock(i);return}o.id==="copy"&&_h(t,i),o.id==="cut"&&(_h(t,i),t.deleteBlock(i))}catch(i){L$.error(`failed to execute block command: ${JSON.stringify(i)}`)}})}commands(t,e){const o=Of(t,e),r=o&&Du(t,e),i=it(e),s=H0(),l=Rf(e),a={id:"copy",name:R.t("blockMenu.command.copy"),data:i,order:1,states:s?[]:["disabled"],disableReason:s?void 0:R.t("copyCutProperty.unsafeEnvTips",{shortCut:xo("CtrlOrCmd+C"),operation:R.t("copyCutProperty.copy")})},d={id:"cut",name:R.t("blockMenu.command.cut"),data:i,order:2,states:o&&!r||!s||l?["disabled"]:[],disableReason:s?void 0:R.t("copyCutProperty.unsafeEnvTips",{shortCut:xo("CtrlOrCmd+X"),operation:R.t("copyCutProperty.cut")})},h={id:"delete",name:R.t("blockMenu.command.delete"),data:i,order:3,states:o&&!r||l?["disabled"]:[]};return{group:"standard-block-actions",commands:[a,d,h],executeCommand:this.executeCommand}}}const Q7=S("block-menu");class R${constructor(t){m(this,"menu");m(this,"currentBlock",null);m(this,"commandBlock",null);m(this,"handleShow",()=>{g(Q7,this.currentBlock,"no target block before show block menu");const t=C$(this.editor,this.currentBlock,{onAfterStyleItemClick:this.close});this.menu.updateItems(t),this.commandBlock=this.currentBlock});m(this,"handleClose",()=>{Op(this.editor)&&this.editor.focus()});m(this,"handleItemClick",(t,e)=>{g(Q7,this.commandBlock,"no command block before show block menu"),A$(this.editor,this.commandBlock,e),e.element||this.close()});m(this,"close",()=>{this.menu.close("clickItem")});this.editor=t,this.menu=new zs([],void 0,{id:"block-menu"}),this.menu.on("show",this.handleShow),this.menu.on("close",this.handleClose),this.menu.on("click",this.handleItemClick),t.blockHooks.push(new M$)}show(t,e){this.menu.manualShow(t,{placement:"bottom-start",...e})}isInMenu(t){return this.menu.isInCommandBar(t)}setBlock(t){this.currentBlock=t}get isVisible(){return this.menu.isVisible}destroy(){this.menu.destroy()}}const O$=1e3;async function _$(n,t){const{width:e}=n.rootContainer.getBoundingClientRect(),o=t.getBoundingClientRect();return o.width>e||o.height>=O$?"":(await Z5.default.toSvg(t)).replace(/margin-block:.*?;/,"").replace(/margin:.*?;/,"")}const F$=S("drag-preview-image");class P${constructor(t){m(this,"startPosition",null);m(this,"dragContainer",null);m(this,"handleDragStart",async(t,e)=>{const o=t.target;g(F$,o instanceof Element,`Invalid Drag target:${o}`);const{x:r,y:i}=t;this.startPosition={x:r,y:i};const s=w("div",["drag-image-container"],this.editor.rootContainer),l=w("img",["drag-image"],s),a=w("span",["drag-loading"],s);a.innerHTML=iM;const{x:d,width:h,height:p,y:A}=o.getBoundingClientRect(),v=this.editor.rootContainer.getBoundingClientRect(),B=e.getBoundingClientRect();s.style.left=`${d+h}px`,s.style.top=`${A+p}px`,s.style.width=`${Math.min(v.width/2,B.width)}px`,this.dragContainer=s;const x=await _$(this.editor,e);x?l.src=x:W(s,"drag-placeholder"),Am(s,{status:"loaded"})});m(this,"handleDrag",t=>{if(this.startPosition&&this.dragContainer){const{x:e,y:o}=t;if(e===0&&o===0){this.dragContainer.style.transition="transform 0.15s, opacity .15s",this.dragContainer.style.transform="",this.dragContainer.style.opacity="0";return}const{x:r,y:i}=this.startPosition,s=e-r,l=o-i;this.dragContainer.style.transform=`translate(${s}px, ${l}px)`}});m(this,"handleDragEnd",()=>{this.dragContainer&&(this.dragContainer.remove(),this.startPosition=null,this.dragContainer=null)});this.editor=t}}const Y7="drag-preview-element";function N$(n){if(xt(n,Y7))return n;const t=n.querySelector(`.${Y7}`);return t||(Me(n)?Lt(n):n)}const Ff=S("block-menu-drag-handler");function e2(n,t){return new DragEvent(t,{bubbles:!0,cancelable:!0,view:window,screenX:n.screenX,screenY:n.screenY,dataTransfer:new DataTransfer,clientX:n.clientX,clientY:n.clientY})}class $${constructor(t,e){m(this,"dragPreview");m(this,"autoScroll");m(this,"oldPos",{x:0,y:0});m(this,"handleMouseDown",t=>{const e=this.button.blockMenu.currentBlock;if(g(Ff,e,"no dragged block"),t.button!==0)return;if(!this.editor.isBlockWritable(e)){t.preventDefault(),t.stopPropagation();return}const{x:o,y:r}=t;this.oldPos={x:o,y:r},document.addEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.addEventListener("mousemove",this.handleDrag)});m(this,"handleDragStart",t=>{var s,l;const e=ro(this.button.buttonElement);this.autoScroll||(this.autoScroll=new Qd({scrollElement:e,trackMouseEvent:"mousemove",edge:{top:50,bottom:50}}));const o=this.button.blockMenu.currentBlock;g(Ff,o,"no dragged block"),(l=(s=Qt(this.editor,o)).notify)==null||l.call(s,this.editor,"beginDrag");const r=e2(t,"dragstart");V$(this.editor,r,o),window.isDragging=!0,this.button.buttonElement.style.opacity="0";const i=N$(o);this.dragPreview.handleDragStart(t,i),this.autoScroll.active(),W(o,"dragging"),W(this.editor.contentElement,"dragging")});m(this,"handleDrag",t=>{const{target:e,x:o,y:r}=t;if(this.oldPos.x===o&&this.oldPos.y===r)return;window.isDragging||this.handleDragStart(t),this.oldPos={x:o,y:r},g(Ff,e instanceof Element,"target is invalid"),this.dragPreview.handleDrag(t);const i=e2(t,"dragover");this.editor.contentElement.dispatchEvent(i)});m(this,"handleDragEnd",t=>{var r;const e=this.button.blockMenu.currentBlock;g(Ff,e,"no dragged block"),window.isDragging=!1,this.button.buttonElement.style.opacity="1",this.dragPreview.handleDragEnd(),(r=this.autoScroll)==null||r.inactive(),ot(e,"dragging"),ot(this.editor.contentElement,"dragging"),document.removeEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.removeEventListener("mousemove",this.handleDrag);const o=e2(t,"drop");this.editor.contentElement.dispatchEvent(o)});this.editor=t,this.button=e,this.button.buttonElement.addEventListener("mousedown",this.handleMouseDown),this.dragPreview=new P$(t)}destroy(){this.button.buttonElement.removeEventListener("mousedown",this.handleMouseDown)}}class Su{constructor(t){m(this,"highlightedBlockId","");m(this,"handleSelectionChange",()=>{this.clearHighlightedBlock()});this.editor=t,this.editor.addListener("selectionChanged",this.handleSelectionChange)}highlightBlock(t){this.clearHighlightedBlock(),this.highlightedBlockId=it(t),W(t,"highlighted")}clearHighlightedBlock(){if(this.highlightedBlockId){const t=this.editor.findBlockById(this.highlightedBlockId);t&&ot(t,"highlighted"),this.highlightedBlockId=""}}destroy(){}static register(t){return t.addCustom("editor-block-highlighter",()=>new Su(t))}static get(t){return t.getCustom("editor-block-highlighter")}}class J7{constructor(t){m(this,"buttonElement");m(this,"emptyBlockMenu");m(this,"blockMenu");m(this,"dragHandler");m(this,"handleHoverBlock",(t,e,o)=>{if(this.emptyBlockMenu.isVisible||this.blockMenu.isVisible||!this.editor.isWritable())return;const r=this.editor.getCustom("editor-tooltip");if(r&&r.visible()&&(r.hide(),this.buttonElement.setAttribute("data-tooltip-hide-at",`${Date.now()}`)),!t){this.buttonElement.parentElement&&(this.blockMenu.isInMenu(o.target)||this.buttonElement.remove());return}const i=Um(t);this.editor.getBlockIndex(i)===0&&this.editor.getBlockData(i).heading===1||(this.updateButton(i),Z0(i,this.buttonElement,Number.MAX_SAFE_INTEGER))});m(this,"handleButtonClick",()=>{if(this.buttonElement.getAttribute("data-type")==="move"){const o=this.blockMenu.currentBlock;if(!o)return;this.editor.selection.selectBlock(o,0),this.blockMenu.show(this.buttonElement,{placement:"bottom-end"}),setTimeout(()=>{Su.get(this.editor).highlightBlock(o)});return}const e=this.emptyBlockMenu.currentBlock;!e||(this.editor.selection.selectBlock(e,0),setTimeout(()=>{this.editor.focus(),this.updatePlaceholder(e),this.emptyBlockMenu.show()}))});m(this,"updatePlaceholder",t=>{Lt(t).setAttribute("data-content-placeholder",R.t("blockMenu.button.searchPlaceholder"))});m(this,"handleChanged",()=>{const t=this.emptyBlockMenu.currentBlock;if(!t)return;const e=he(this.editor,t)?"insert":"move";this.buttonElement.getAttribute("data-type")!==e&&this.setButtonType(e)});this.editor=t,this.buttonElement=this.createButton(),this.emptyBlockMenu=new h$(t),this.blockMenu=new R$(t),this.editor.addListener("docChanged",this.handleChanged),this.buttonElement.addEventListener("click",this.handleButtonClick),this.dragHandler=new $$(this.editor,this);const e=Ae.get(t);e.addListener("change",this.handleHoverBlock),e.addFinder(new d$),Su.register(this.editor)}destroy(){Ae.get(this.editor).removeListener("change",this.handleHoverBlock),this.buttonElement.removeEventListener("click",this.handleButtonClick),this.editor.removeListener("docChanged",this.handleChanged),this.emptyBlockMenu.destroy(),this.blockMenu.destroy(),this.buttonElement.remove(),this.dragHandler.destroy()}createButton(){const t=w("button",["block-button"],null);return t.setAttribute(`data-editor-tooltip-${this.editor.clientId}`,R.t("blockMenu.button.tips")),t.innerHTML=Cv,t}setButtonType(t){this.buttonElement.setAttribute("data-type",t);const e=`data-editor-tooltip-${this.editor.clientId}-dynamic`;this.buttonElement.hasAttribute(e)&&this.buttonElement.removeAttribute(e),t==="insert"?(this.buttonElement.innerHTML=rM,this.buttonElement.setAttribute(e,R.t("blockMenu.button.insertTips"))):(this.buttonElement.innerHTML=Cv,this.buttonElement.setAttribute(e,R.t("blockMenu.button.tips")))}updateButton(t){this.emptyBlockMenu.setBlock(t),this.blockMenu.setBlock(t),he(this.editor,t)?this.setButtonType("insert"):this.setButtonType("move")}}const H$={blockMenu:{section:{basics:"\u57FA\u7840",system:"\u7CFB\u7EDF",styles:"\u6837\u5F0F",common:"\u901A\u7528",actions:"\u64CD\u4F5C",thirdParty:"\u7B2C\u4E09\u65B9\u5185\u5BB9"},command:{insertAbove:"\u5728\u4E0A\u65B9\u63D2\u5165",insertAfter:"\u5728\u4E0B\u65B9\u63D2\u5165",copy:"\u590D\u5236",cut:"\u526A\u5207",delete:"\u5220\u9664"},button:{searchPlaceholder:"\u8F93\u5165\u5173\u952E\u8BCD\u641C\u7D22",tips:`\u957F\u6309\u62D6\u62FD
|
|
421
|
+
`).map(s=>({id:K(),type:"text",text:Oi(s)})),o=K();return{blocks:{root:[{children:[o],type:"code",id:K(),...t}],[o]:e},meta:{},comments:{}}}class TN{handleBeforeCopy(t,e,o){const r=t.getFocusedBlock();if(!vc(t,r))return;const i=O0(r),s=t.getBlockData(i),{language:l,nowrap:a}=s;if(t.selection.range.isCollapsed()){const h=t.getBlockString(r);return k7(h,{language:l,nowrap:a})}const d=t.getSelectedText();return k7(d,{language:l,nowrap:a})}}function DN(n){if(!n.isWritable())return!1;const t=n.getFocusedBlock();if(!!vc(n,t)){if(n.selection.range.isCollapsed()){const e=n.selection.range.start;return n.insertTextToBlock(t,e.offset," "),!0}return n.undoManager.runInGroup(()=>{Ro(n).forEach(o=>{n.insertTextToBlock(o.block,0," ")})}),!0}}function SN(n){if(!n.isWritable())return!1;const t=n.getFocusedBlock();if(!vc(n,t))return;const e=[" "," "];return n.undoManager.runInGroup(()=>{Ro(n).forEach(r=>{const i=ie(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 LN(n){const t=n.getFocusedBlock(),e=nt(t);if(Yt(e))return;const o=et(e);if(!o||Dt(o)!=="code")return;const r=n.selection.range;if(!!r.isSimple()&&!MA(e,r))return Gg(n,e),!0}const MN={Tab:DN,"Shift+Tab":SN,"CtrlOrCmd+A":LN},ku=S("code-text-decorate");class Sf{decorateText(t,e,o){var v;if(g(ku,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=ie(s),a=t.doc.getBlockData(r.containerId,r.blockIndex),d=ua.default.tokenize(l,(v=ua.default.languages[a.language])!=null?v:ua.default.languages.plain),h=(B,D)=>{if(g(ku,B,"no token"),typeof B=="string")return[{insert:B,attributes:mt.default(D)}];g(ku,B instanceof ua.default.Token,"invalid token type");const x=B.content,_=mt.default(D);return _[`style-code-${B.type}`]=!0,typeof x=="string"?[{insert:x,attributes:_}]:Array.isArray(x)?x.map(z=>h(z,_)).flat():(g(ku,x instanceof ua.default.Token,"invalid token"),h(x,_))},A=d.map(B=>h(B,{})).flat();return g(ku,rn(A)===rn(s),"failed to highlight code, text length mismatch"),{text:A}}}const RN={code:{title:"\u4EE3\u7801",abstract:"\u4EE3\u7801",wrap:"\u6362\u884C",copy:"\u590D\u5236",caption:"\u8BF4\u660E",search:"\u8F93\u5165\u5173\u952E\u8BCD\u641C\u7D22",copySuccess:"\u590D\u5236\u6210\u529F"}},ON={code:{title:"Code",abstract:"Code",wrap:"Wrap",copy:"Copy",caption:"Caption",search:"Search",copySuccess:"Copied successfully"}},_N={code:{title:"\u30B3\u30FC\u30C9",abstract:"\u30B3\u30FC\u30C9",wrap:"\u6298\u308A\u8FD4\u3059",copy:"\u8907\u88FD",caption:"\u4F8B\u8A3C\u3059\u308B",search:"\u30AD\u30FC\u30EF\u30FC\u30C9\u3067\u691C\u7D22",copySuccess:"\u30B3\u30D4\u30FC\u3055\u308C\u307E\u3057\u305F"}};R.mergeLang({"zh-CN":RN,"en-US":ON,"ja-JP":_N});const FN=S("image-data"),w7=1e3,U0=400,PN=10;function yc(n){return n.src.startsWith("empty:")||!n.src}function NN(n){return n.src.startsWith("http:")||n.src.startsWith("https:")}function B7(n){return`${Pd.default(n)}_width`}function E7(n){return`${Pd.default(n)}_height`}function x7(n){return`${n}_flex`}function I7(n){let t=n.getBoundingClientRect().width;return t-=Number.parseFloat(window.getComputedStyle(n).paddingLeft)+Number.parseFloat(window.getComputedStyle(n).paddingRight),t}function wu(n){if(n.every(r=>typeof r.flex=="number"&&r.flex))return;const t=100,o=n.map(r=>{const i=r.height==="auto"?r.width/t:r.height/t;return r.width/i}).reduce((r,i)=>r+i,0);n.forEach(r=>{const i=r.height==="auto"?r.width/t:r.height/t,s=r.width/i;r.flex=s/o})}function kc(n){const t=(r,i)=>{r||(r=`empty:${i}`);const s=B7(r),l=E7(r),a=x7(i);let d=n[s],h=n[l],p=n[a];return typeof d=="string"&&(d=Number.parseInt(d,10)),typeof h=="string"&&(h=Number.parseInt(h,10)),typeof p=="string"&&(p=Number.parseInt(p,10)),d&&h?{src:r,width:d,height:h,flex:p,virtualSize:!1}:d&&!h?{src:r,width:d,height:"auto",flex:p,virtualSize:!1}:(d=w7,h=U0,{src:r,width:d,height:h,flex:p,virtualSize:!0})};let e=[];const o=n.src;return Array.isArray(o)?e=o.map(t):typeof o=="string"&&(e=o.split("|").map(t)),wu(e),e}function Vo(n){const t=n.embedData;return kc(n.embedData).length>1?100:t.widthPercent}function $N(n,t,e,o){const r=kc(t.embedData);if(r.length>1||o)return"100%";const i=Vo(t),s=n.rootContainer.getBoundingClientRect().width;if(i){const l=I7(e);return`${Math.min(s*i/100,l)}px`}return r[0].width?`${r[0].width}px`:"auto"}function cn(n,t){const o={src:n.map(r=>r.src).join("|"),widthPercent:t};return n.forEach((r,i)=>{if(r.width&&r.height&&!r.virtualSize){const l=r.src||`empty:${i}`,a=B7(l);o[a]=r.width;const d=E7(l);r.height!=="auto"&&(o[d]=r.height)}g(FN,r.flex,"no image flex");const s=x7(i);o[s]=r.flex}),o}function HN(n,t,e,o){const r=kc(t.embedData),i=r.length===1?n.rootContainer:e;if(r.length===1&&o)return`${U0}px`;if(r.some(h=>h.height==="auto"))return"auto";const s=Vo(t);if(!s)return"";let l=i.getBoundingClientRect().width*(s/100);if(l-=Number.parseFloat(window.getComputedStyle(i).paddingLeft)+Number.parseFloat(window.getComputedStyle(i).paddingRight),i===n.rootContainer&&i!==e&&(l=Math.min(l,I7(e))),r.length===1){const h=r[0];return h.virtualSize?"":`${h.height/(h.width/l)}px`}l-=(r.length-1)*PN;const a=r.reduce((h,p)=>h+p.flex,0);let d=0;for(const h of r){const A=l*h.flex/a/h.width*h.height;d=Math.max(A,d)}return`${d}px`}function jN(n){return n.reduce((e,o)=>e+o.flex,0)}function UN(n,t){w("div",["resize-gripper",t],n).setAttribute("data-resize-type",t)}function z0(n){return te(n).querySelector(".block-resizer")}function zN(n){const t=z0(n);t&&ot(t,"active")}function T7(n,t,e){const o=n.getBoundingClientRect(),r=t.getBoundingClientRect(),i=r.top-o.top,s=r.left-o.left,l=r.width,a=r.height;e.style.top=`${i}px`,e.style.left=`${s}px`,e.style.width=`${l}px`,e.style.height=`${a}px`}function VN(n,t,e,o){const r=z0(n);if(r)return W(r,"active"),T7(n,t,r),r;const i=te(n),s=w("div",["block-resizer"],i);return T7(n,t,s),e.resize.forEach(l=>{UN(s,l)}),s.addEventListener("mousedown",o),W(s,"active"),s}function V0(n,t){const e=z0(n);if(!e||!Xt(n,t))return;const o=n.getBoundingClientRect(),r=t.getBoundingClientRect(),i=r.top-o.top,s=r.left-o.left,l=r.width,a=r.height;e.style.top=`${i}px`,e.style.left=`${s}px`,e.style.width=`${l}px`,e.style.height=`${a}px`}const Fnt="",WN=S("block-resizer");class Bu extends ye.TypedEmitter{constructor(e,o){super();m(this,"resizableElement");m(this,"block",null);m(this,"startRect",null);m(this,"startPos",null);m(this,"resizeType",null);m(this,"enabled",!1);m(this,"handleMouseDown",e=>{e.preventDefault(),e.stopPropagation();const o=this.getResizableElement();if(!o||e.button!==0)return;const r=e.target;if(!r||!(r instanceof HTMLElement))return;const i=r.getAttribute("data-resize-type");!i||(this.bindEvents(),this.startRect=o.getBoundingClientRect(),this.startPos=e,this.resizeType=i,ga(window.getComputedStyle(r).cursor),this.block&&this.editor.selection.selectBlock(this.block,0))});m(this,"handleMouseMove",e=>{if(!this.startPos||!this.startRect||!this.resizeType||!this.getResizableElement()||!this.block)return;const r=e.x-this.startPos.x,i=e.y-this.startPos.y,s=this.startRect;let{top:l,left:a,right:d,bottom:h}=s;(this.resizeType==="bottom"||this.resizeType==="bottom-left"||this.resizeType==="bottom-right")&&(h+=i),(this.resizeType==="top"||this.resizeType==="top-left"||this.resizeType==="top-right")&&(l+=i),(this.resizeType==="left"||this.resizeType==="top-left"||this.resizeType==="bottom-left")&&(a+=r),(this.resizeType==="right"||this.resizeType==="top-right"||this.resizeType==="bottom-right")&&(d+=r);const p=d>a?d-a:0,A=h>l?h-l:0,v=new DOMRect(a,l,p,A);this.emit("resizing",this,v);const B=this.getResizableElement();B&&V0(this.block,B)});m(this,"handleMouseUp",e=>{if(e.button!==0)return;ga(""),this.unbindEvents(),this.emit("resized",this);const o=this.getResizableElement();!o||!this.block||V0(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||(zN(this.block),this.enabled=!1)}update(e,o){this.block=e,this.resizableElement=o,this.getResizableElement()&&this.enabled&&this.createResizer()}updateResizer(){const e=this.getResizableElement();e&&this.block&&V0(this.block,e)}getBlock(){return this.block}destroy(){}getResizableElement(){return this.resizableElement?this.resizableElement:this.block?Lt(this.block):null}createResizer(){const e=this.getResizableElement();!e||!this.block||(g(WN,Xt(this.block,e),"not a block child element"),VN(this.block,e,this.options,this.handleMouseDown))}bindEvents(){document.addEventListener("mousemove",this.handleMouseMove),document.addEventListener("mouseup",this.handleMouseUp)}unbindEvents(){document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp)}}const qN=S("image-dom");function D7(n){return n.querySelector(".uploading-progress-mask")}function GN(n){const t=D7(n);if(t)return t;const e=w("div",["uploading-progress-mask"],n),o=w("div",["uploading-progress-bar"],e);return w("div",["uploading-progress-bar-value"],o),o}function ZN(n){const e=GN(n).querySelector(".uploading-progress-bar-value");return g(qN,e,"no progress value"),e}function S7(n,t){const e=ZN(n);e.style.width=`${t}%`}function QN(n){var t;(t=D7(n))==null||t.remove()}function Eu(n,t,e,o){const r=e!=null?e:n.findBlockById(t.id);if(!r)return;const i=o||nt(r),s=!!r.querySelector(".images > .image-container.error, .images > .image-container.empty "),l=$N(n,t,i,s),a=HN(n,t,i,s),d=Lt(r);l==="auto"?d.style.width=l:(d.style.maxWidth=l,d.style.width="100%");const h=r.querySelector(".images");!h||(h.style.height=a||"none")}function YN(n){let t;return n.forEach((e,o)=>{o.toLocaleLowerCase()==="content-type"&&(t=e)}),t!=null?t:""}async function JN(n){try{const t=await fetch(n,{credentials:"same-origin"}),e=await t.blob(),o=YN(t.headers).toLocaleLowerCase();let r="";if(o){const s=mm.default[o].extensions;s&&s.length>0&&(r=s[0])}return new File([e],`${Date.now()}.${r}`,{type:o})}catch{return null}}function Ji(n,t){const e=typeof t=="string"?t:it(t);return n.getCustom(`image-${e}`)}function Lf(n,t){if(!t||!(t instanceof Node))return null;const e=et(t);return e?Ji(n,e):null}function Ar(n){return Array.from(n.querySelectorAll(".image-container"))}const W0=S("table-resize-drag-drop");class KN{constructor(t,e,o,r){m(this,"cursor","col-resize");m(this,"initWidths");this.editor=t,this.elem=e,this.data=o,this.mouseDownEvent=r;const i=this.data.block,l=Ji(this.editor,i).getImages(),a=this.data.splitterIndex;g(W0,a>=0&&a<l.length-1,`invalid splitter index: ${a}`);const h=Ar(i).map(p=>p.getBoundingClientRect().width);this.initWidths=h}onDragStart(t,e,o){if(!this.editor.isWritable())return;const r=this.data.block;Ji(this.editor,r).setResizing(!0)}onDragging(t,e,o,r,i){const s=this.data.block,l=Ji(this.editor,s),a=mt.default(l.getImages()),d=this.data.splitterIndex;g(W0,d>=0&&d<a.length-1,`invalid splitter index: ${d}`);const h=this.initWidths[d],p=this.initWidths[d+1];if(h+p<100)return;let A=r;h+A<50&&(A=50-h),p-A<50&&(A=p-50);const D=[...this.initWidths];D[d]+=A,D[d+1]-=A;const x=Ar(s);g(W0,x.length===a.length,"invalid image data");const _=D.reduce((z,q)=>z+q,0);for(let z=0;z<a.length;z++){const q=D[z]/_;a[z].flex=q,x[z].style.flexGrow=`${q}`}const M=mt.default(this.editor.getBlockData(s)),H=cn(a,Vo(M));M.embedData=H,Eu(this.editor,M,s,null)}onDragEnd(t,e,o,r,i){const s=this.data.block,l=Ji(this.editor,s),d=Ar(s).map(h=>Number.parseFloat(h.style.flexGrow));l.updateFlex(d),l.setResizing(!1)}}function L7(n){var t;return!n||!(n instanceof HTMLElement)?null:xt(n,"image-splitter")?n:(t=n.closest(".image-splitter"))!=null?t:null}function XN(n,t){var s;const e=L7(t.target);if(!e)return;const o=et(e);if(!o)return;Ji(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};km(new KN(n,e,i,t))}function t$(n,t){t.preventDefault(),t.stopPropagation();const e=L7(t.target);if(!e)return;const o=et(e);!o||Ji(n,o).resetFlex()}function e$(n,t,e,o){const r=w("div",["image-splitter"],e);w("div",["image-splitter-indicator"],r),r.setAttribute("data-index",`${o}`),n.domEvents.addEventListener(r,"mousedown",XN),n.domEvents.addEventListener(r,"dblclick",t$)}const n$=S("image-item");function M7(n){return!n||!(n instanceof Node)?null:et(n)}function R7(n){const t=M7(n);return t?Ar(t):[]}function q0(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 xu(n){const t=q0(n);return t?R7(n).indexOf(t):-1}async function o$(n,t){const e=Lf(n,t.target);if(!e)return;const o=xu(t.target);if(o===-1)return;const r=t.target;if(!(r instanceof HTMLImageElement))return;const i=e.getImages()[o];if(yc(i)||n.readonly||!e.isAutoFix()||(setTimeout(()=>{e.setAutoFix(!1)},400),i.height==="auto"&&e.fixImageSize(o,r),i.virtualSize&&e.fixImageSize(o,r),!i||!NN(i)||i.downloading))return;i.downloading=!0;const s=await JN(i.src);s?e.replaceImage(o,s):n$.warn(`failed to download image: ${i.src}`)}function r$(n,t,e){if(t.querySelector(".load-error"))return;const r=e.src.startsWith("http:")||e.src.startsWith("https:"),i=w("div",["load-error"],t),s=w("div",["error-icon"],i);s.innerHTML=av;const l=w("div",["error-message"],i);r?(l.innerHTML=R.t("image.load.remote.failed"),n.domEvents.addEventListener(i,"click",(a,d)=>{d.preventDefault(),d.target instanceof HTMLElement&&d.target.tagName==="A"&&window.open(e.src,"_blank")})):(l.innerHTML=R.t("image.load.failed"),n.domEvents.addEventListener(i,"click",(a,d)=>{d.preventDefault(),d.stopPropagation(),d.target instanceof HTMLElement&&d.target.tagName==="A"&&c$(a,d.target)}))}function G0(n,t){setTimeout(()=>{if(Xt(n.rootContainer,t)){const e=n.getBlockData(t);Eu(n,e,null,null)}})}function i$(n,t){const e=Lf(n,t.target);if(!e)return;const o=xu(t.target);if(o===-1)return;const r=e.getImages()[o];if(!r)return;const i=q0(t.target);if(!i)return;W(i,"error","error-load");const s=et(i);s&&G0(n,s),i.innerHTML="",r$(n,i,r)}function s$(n,t,e){if(t.querySelector(".upload-error"))return;const r=w("div",["upload-error"],t),i=w("div",["error-icon"],r);i.innerHTML=av;const s=w("div",["error-message"],r);s.innerHTML=R.t("image.upload.failed"),n.domEvents.addEventListener(r,"click",(l,a)=>{if(a.preventDefault(),!a.target||!(a.target instanceof Element)||a.target.tagName!=="A")return;const d=Lf(l,a.target),h=xu(a.target);!d||h===-1||d.replaceImage(h,e)})}function O7(n,t,e,o,r){const i=Ar(t)[e];!i||(W(i,"error","error-upload"),G0(n,t),i.innerHTML="",s$(n,i,r))}function _7(n,t,e,o,r,i,s){const l=w("div",["image-container"],e);if(l.setAttribute("data-src",o.src),s.length>1&&(l.style.flexShrink=`${o.flex}`,l.style.flexGrow=`${o.flex}`),i===r&&W(l,"active"),yc(o)){W(l,"empty");const d=w("div",["upload-image-icon"],l);return d.innerHTML=ML,l}const a=w("img",["editor-image"],l);if(a.src=n.doc.buildResourceUrl(o.src),n.domEvents.addEventListener(a,"load",o$),n.domEvents.addEventListener(a,"error",i$),o.src.startsWith("https:")||o.src.startsWith("http:")){const d=w("div",["image-warning"],l);d.innerHTML=cv,d.setAttribute(`data-editor-tooltip-${n.clientId}`,R.t("image.load.remote.tooltip"))}return l}function l$(n,t,e,o,r){const i=w("div",["images"],e);return o.forEach((s,l)=>{l>0&&e$(n,t,i,l-1),_7(n,t,i,s,l,r,o)}),o.length>1&&W(t,"multi"),i}function F7(n,t,e,o,r,i){const l=Array.from(t.querySelectorAll(".image-container"))[o];if(!l)return;const a=_7(n,t,null,e,o,r,i);l.insertAdjacentElement("beforebegin",a),l.remove(),G0(n,t)}function Iu(n,t){return Ar(n)[t]}function c$(n,t){const e=M7(t);if(!e)return;const o=xu(t);if(o===-1)return;const r=Lf(n,t);if(!r)return;const i=r.getImages()[o];F7(n,e,i,o,r.getSelectedIndex(),r.getImages())}function Wo(n){return Dt(n)==="embed"&&fn(n)==="image"}async function P7(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 a$(n){const t=await jl(n);return P7(t)}function N7(n){var o;let t="image/*";const e=(o=n.getComponentOptions("image"))==null?void 0:o.allowedMedias;return e&&(t=e.map(r=>`.${r}`).join(",")),t}function $7(n,t){var s;const{maxSize:e,allowedMedias:o,callbacks:r}=(s=n.getComponentOptions("image"))!=null?s:{};if(e&&t.size>e){const l=new Error("image is too large");throw l.code="MaxMediaSize",r!=null&&r.onError&&(r==null||r.onError(n,l)),l}const i=Aa(t.name);if(o&&!o.includes(i)){const l=new Error(`media file is not allowed: ${i}`);throw l.code="NotAllowedFile",r!=null&&r.onError&&(r==null||r.onError(n,l)),l}}function H7(n){return n.startsWith("image/")}const j7=S("image-object");class Ie{constructor(t,e){m(this,"images",[]);m(this,"selectedIndex",-1);m(this,"blockResizer");m(this,"resizing",!1);m(this,"parentContainerResizerObserver",null);m(this,"autoFix",!1);m(this,"handleMouseDown",async(t,e)=>{const o=xu(e.target);if(o===-1)return;const r=this.images[o];yc(r)||this.setSelectedIndex(o)});m(this,"handleRootContainerResize",()=>{this.handleEditorResize(this.editor.rootContainer)});m(this,"handleEditorResize",t=>{if(this.isEmpty()||this.resizing)return;const e=this.editor.findBlockById(this.blockData.id);!e||nt(e)===t&&Eu(this.editor,this.blockData,e,null)});m(this,"handleResizing",(t,e)=>{const o=this.editor.findBlockById(this.blockData.id);if(!o)return;this.autoFix||this.setAutoFix(!0);const i=this.editor.rootContainer.getBoundingClientRect().width,s=o.getBoundingClientRect();let l=e.width>s.width?s.width:e.width;l<50&&(l=50);const a=l*100/i;this.blockData.embedData.widthPercent=a,Eu(this.editor,this.blockData,o,null)});m(this,"handleResized",t=>{const e=this.editor.findBlockById(this.blockData.id);if(!e)return;const o=cn(this.images,Vo(this.blockData));this.editor.updateEmbedData(e,o),this.blockResizer.enableResize(e)});m(this,"fixImageSizes",Le.default(()=>{const t=this.editor.findBlockById(this.blockData.id);if(!t)return;const e=cn(this.images,Vo(this.blockData));this.editor.updateEmbedData(t,e)},1e3));this.editor=t,this.blockData=e,this.blockResizer=new Bu(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=kc(this.blockData.embedData)}destroy(){var t;this.blockResizer.removeAllListeners(),this.blockResizer.destroy(),this.editor.domEvents.removeEventListener(null,null,this.handleMouseDown),(t=this.parentContainerResizerObserver)==null||t.disconnect()}setAutoFix(t){this.autoFix=t}isAutoFix(){return this.autoFix}createContent(t,e,o){const r=l$(this.editor,e,o,this.images,this.selectedIndex);if(this.editor.domEvents.addEventListener(o,"mousedown",this.handleMouseDown),this.editor.addListener("resize",this.handleRootContainerResize),Lo(t)){const s=()=>{this.handleEditorResize(t)};this.parentContainerResizerObserver=new ResizeObserver(s),this.parentContainerResizerObserver.observe(t)}const i=()=>!!(this.images.length===1&&this.images[0].virtualSize);this.isEmpty()&&i()&&W(r,"empty"),Eu(this.editor,this.blockData,e,t),setTimeout(()=>{const s=this.editor.findBlockById(this.blockData.id);s&&this.blockResizer.update(s)})}getImages(){return this.images}getWidthPercent(){return Vo(this.blockData)}isEmpty(){return this.images.length===1&&yc(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=Iu(e,this.selectedIndex);r&&ot(r,"active")}this.selectedIndex=t;const o=Iu(e,t);o&&W(o,"active")}async requestUploadImage(t){const e=this.editor.findBlockById(this.blockData.id);if(!e)return;const o=Iu(e,t);if(xt(o,"error"))return;const r=N7(this.editor),i=await Ul(r);await this.replaceImage(t,i)}tryEnableResizer(){const t=this.editor.findBlockById(this.blockData.id);if(!t||!this.editor.isWritable())return;const e=Iu(t,0);!this.isEmpty()&&this.images.length===1&&!xt(e,"error")&&this.blockResizer.enableResize(t)}disableResizer(){this.blockResizer.disableResize()}fixImageSize(t,e){const o=this.images[t];yc(o)||(o.height==="auto"&&(o.height=e.height),o.width=e.naturalWidth,o.height=e.naturalHeight,o.virtualSize=!1,this.fixImageSizes())}removeImage(t){const e=this.editor.findBlockById(this.blockData.id);if(!e||t===-1||t>=this.images.length)return!1;const o=mt.default(this.images);if(o.splice(t,1),o.length===0)return this.editor.deleteBlock(e),!0;o[0].flex=NaN,wu(o),this.selectedIndex>=o.length&&(this.selectedIndex=o.length-1);const r=cn(o,Vo(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 jl(e),s=this.images[t];if(s.virtualSize){const{width:a,height:d}=await P7(i);s.width=a,s.height=d,s.virtualSize=!1;const h=cn(this.images,Vo(this.blockData));this.editor.updateEmbedData(o,h)}const l={...s,src:i};F7(this.editor,o,l,t,this.selectedIndex,this.images),setTimeout(()=>{this.blockResizer.update(o)})}catch(i){return O7(this.editor,o,t,i,e),!1}const r=Iu(o,t);if(!r)return!1;W(r,"uploading"),S7(r,0),W(o,"media-block-uploading");try{const i=await this.editor.doc.uploadResource(e,{onProgress:a=>{S7(r,a)}});ot(r,"uploading"),this.images[t].src=i.resourceId;const s=this.editor.findBlockById(this.blockData.id);if(!s)return!1;ot(s,"media-block-uploading");const l=cn(this.images,Vo(this.blockData));return this.editor.updateEmbedData(s,l),!0}catch(i){j7.error(i);const s=this.editor.findBlockById(this.blockData.id);return s&&(ot(r,"uploading"),QN(r),O7(this.editor,s,t,i,e),ot(s,"media-block-uploading")),!1}}updateFlex(t){const e=this.editor.findBlockById(this.blockData.id);if(!e)return;g(j7,t.length===this.images.length,"invalid flex");for(let r=0;r<this.images.length;r++)this.images[r].flex=t[r];const o=cn(this.images,Vo(this.blockData));this.editor.updateEmbedData(e,o)}resetFlex(){const t=this.editor.findBlockById(this.blockData.id);if(!t)return;const e=mt.default(this.images);e[0].flex=NaN,wu(e);const o=cn(e,Vo(this.blockData));this.editor.updateEmbedData(t,o)}setData(t){this.blockData=t,this.images=kc(t.embedData)}static create(t,e){const o=t.addCustom(`image-${e.id}`,()=>new Ie(t,e));return o.setData(e),o}static getImageObject(t,e){let o;return typeof e=="string"?o=e:o=it(e),t.getCustom(`image-${o}`)}}const Pnt="",Nnt="";function Mf(n){const t=te(n);let e=t.querySelector(":scope > .block-helper");return e||(e=w("div",["block-helper"],t),w("span",["helper-sizer"],e,"A")),e}function Z0(n,t,e){const o=Mf(n),i=Array.from(o.children).find(s=>{var a;return Number.parseInt((a=s.getAttribute("data-index"))!=null?a:"0",10)>e});o.insertBefore(t,i!=null?i:null)}const U7=40,u$=20;class d${findTargetBlock(t,e){const o=e.target;if(o&&o instanceof Element){const a=et(o);if(a&&Xt(t.rootContainer,a))return a}let r=e.clientX,i=e.clientY;const s=t.rootContainer.getBoundingClientRect().left;r<s&&s-r<U7&&(r+=U7);let l=document.elementFromPoint(r,i);if(l){const a=et(l);if(a&&Xt(t.rootContainer,a))return a}if(i-=u$,l=document.elementFromPoint(r,i),l){const a=et(l);if(a&&Xt(t.rootContainer,a))return a}return null}destroy(){}}class h$ extends Cf{constructor(e){super(e,{trigger:[],id:"empty-block-menu"});m(this,"currentBlock",null)}get isVisible(){return this.suggest.menu.isVisible}isInMenu(e){return this.menu.isInCommandBar(e)}show(){const o=this.editor.selection.focusedBlock;this.suggest.popup(o,0,"","")}setBlock(e){this.currentBlock=e}}function f$(n,t,e){const o=zm(n,t);if(!o)return[];const r=[];return Object.values(o).forEach(i=>{e!=null&&e.has(i.group)||r.push(...i.commands.map(s=>({...s,source:"block-command",blockMenuItemCustomData:i.group})))}),r}function Q0(n,t,e={withPlainText:!1}){const o=T0(n,e),r=i=>{i.forEach(s=>{s.source=t,s.children&&r(s.children)})};return r(o),o}function m$(n,t,e,o=!1){var d,h;const r=nt(t);let s=bt(t);he(n,t)||o||(s+=1);const l=at(r),a=e;return a.commandProvider?a.commandProvider.executeCommand(n,e,{from:"block-menu",containerId:l,blockIndex:s}):(h=(d=a.blockOptions)==null?void 0:d.handleInsertEmptyBlock)==null?void 0:h.call(d,n,{containerId:l,blockIndex:s,item:e})}function g$(n,t){const e=Do(n,t),o=n.getBlockData(t);return!(e!=="text"||o.heading)}class z7{constructor(t,e,o){m(this,"source","text-style");m(this,"id","text-style-item");m(this,"name","Text styles");m(this,"element");m(this,"createHeadingItemElement",(t,e,o)=>{var i;const r=w0();this.createItem("text",ou,e,g$(this.editor,t)),(i=r.insertBlockCommandItems)==null||i.forEach(s=>{s.id&&s.icon&&this.createItem(s.id,s.icon,e,o?o===Number(s.value):!1)})});m(this,"createListItemElement",(t,e,o)=>{const{checkbox:r,ordered:i}=o,l=Dt(t)==="list",a=l&&i===!1&&!r,d=l&&i,h=l&&!!r;this.createItem("unordered-list",gv,e,a),this.createItem("ordered-list",pv,e,d),this.createItem("check-list",fv,e,h)});m(this,"handleClick",(t,e)=>{var l,a;if(!e.target||!(e.target instanceof Node))return;const o=e.target instanceof Element?e.target:e.target.parentElement;if(!o)return;const r=o.closest(".text-style-item");if(!r)return;const i=r.id,s="heading-";if(i==="text"&&gf(t,this.block,null),i.startsWith(s)){const d=Number.parseInt(i.substring(s.length),10);d&&gf(t,this.block,d)}if(i==="blockquote"&&v0(t,this.block),i.startsWith("align")){const d=i.replace(/^align-/,"");T9(t,this.block,d)}(i==="unordered-list"||i==="ordered-list"||i==="check-list")&&k0(t,this.block,i),(a=(l=this.options).onAfterStyleItemClick)==null||a.call(l)});this.editor=t,this.block=e,this.options=o,this.element=this.createItemElement(t,e),t.domEvents.addEventListener(this.element,"click",this.handleClick)}createItemElement(t,e){const o=w("div",["text-styles"],null),r=w("div",["text-style-section"],o),i=t.getBlockData(e);if(!this.options.fromEmbed){const l=i.heading,a=i.quoted;this.createHeadingItemElement(e,r,l),this.createListItemElement(e,r,i),this.createItem("blockquote",mv,r,!!a)}const s=i.align||"left";return this.createItem("align-left",eu,r,s==="left"),this.createItem("align-center",Tp,r,s==="center"),this.createItem("align-right",Ip,r,s==="right"),o}createItem(t,e,o,r=!1){const i=["style-icon","text-style-item"];r&&i.push("active");const s=$l(e,i,o);s.id=t}}function V7(){return{source:"separator",type:"separator",id:`section-${K()}`,name:""}}const W7={copy:QL,cut:YL,delete:JL,"lock-block":KL,"unlock-block":XL,comment:nu},p$=["image","video"];function C$(n,t,e){const o=[],r=tt(n,t),i=Me(t)&&p$.includes(fn(t)),s=i&&(fn(t)!=="image"||fn(t)==="image"&&Ar(t).length===1);if(r?o.push(new z7(n,t,e)):i&&s&&o.push(new z7(n,t,{...e,fromEmbed:!0})),!he(n,t)){(r||i&&s)&&o.push(V7());const l=f$(n,t,new Set(["hovering-toolbar"]));l.sort((a,d)=>{var h,p;return((h=a.order)!=null?h:0)-((p=d.order)!=null?p:0)}),l.forEach(a=>{a.id in W7&&(a.icon=W7[a.id])}),o.push(...l)}return he(n,t)?o.push(...Q0(n,"insert-block")):o.push(V7(),{id:"insert-block-before",icon:tM,name:R.t("blockMenu.command.insertAbove"),children:Q0(n,"insert-block-before",{withPlainText:!0}),childrenMenuId:"quick-menu",source:"insert-block-before"},{id:"insert-block-after",icon:eM,name:R.t("blockMenu.command.insertAfter"),children:Q0(n,"insert-block",{withPlainText:!0}),source:"insert-block",childrenMenuId:"quick-menu"}),o}function A$(n,t,e){if(e.source==="block-command"){const o=e.blockMenuItemCustomData;u4(n,t,o,e)}else(e.source==="insert-block"||e.source==="insert-block-before")&&m$(n,t,e,e.source==="insert-block-before")}const b$=S("exclusive-block");function Y0(n,t,e,o){var l;W(t,"block-exclusive");const r=Qt(n,t),i=(l=r.getBlockProperties)==null?void 0:l.call(r,n,t),{abstract:s}=i||{};t.setAttribute("data-user-name",o),t.setAttribute("data-user-id",e),t.setAttribute("data-exclusive-tips",R.t("exclusive.tips",{editor:o,embedType:s||R.t("exclusive.fallbackAbstract")}))}function q7(n){ot(n,"block-exclusive"),n.removeAttribute("data-user-name"),n.removeAttribute("data-user-id"),n.removeAttribute("data-exclusive-tips")}function v$(n,t,e,o,r){b$.debug(`block ${it(t)} ${e?"exclusive":"unexclusive"}, ${o}, ${r}`),e?Y0(n,t,o,r):q7(t)}function Rf(n){return n.classList.contains("block-exclusive")}function G7(n,t){t.blockIds.forEach(e=>{const o=n.findBlockById(e);o&&v$(n,o,t.exclusive,t.userId,t.displayName)})}class Ki{constructor(t){m(this,"exclusiveBlockIds",new Set);m(this,"exclusiveBlockTimer",0);m(this,"remoteExclusiveBlockIds",new Map);m(this,"handleUserChanged",t=>{const e=new Set(t.map(r=>r.userId));Array.from(this.remoteExclusiveBlockIds.entries()).forEach(([r,i])=>{if(!e.has(i.userId)){this.remoteExclusiveBlockIds.delete(r);const s={...i,exclusive:!1};G7(this.editor,s)}});const o=Array.from(this.exclusiveBlockIds).map(r=>this.editor.findBlockById(r)).filter(r=>!!r);o.length>0&&this.broadcastExclusiveBlockMessage(o,!0)});this.editor=t,t.doc.registerCallback(this),t.doc.getRemoteUsers().addListener("change",this.handleUserChanged)}destroy(){this.stopExclusiveBlockTimer(),this.editor.doc.unregisterCallback(this),this.editor.doc.getRemoteUsers().addListener("change",this.handleUserChanged)}onCustomMessage(t){if(t.type==="exclusiveBlock"){const e=t;G7(this.editor,e),e.blockIds.forEach(o=>{e.exclusive?this.remoteExclusiveBlockIds.set(o,e):this.remoteExclusiveBlockIds.delete(o)})}}getExclusiveMessage(t){return this.remoteExclusiveBlockIds.get(t)}broadcastExclusiveBlockMessage(t,e){if(this.editor.readonly||t.length===0)return;const o=this.editor.doc.getUser(),r={type:"exclusiveBlock",userId:o.userId,displayName:o.displayName,blockIds:t.map(i=>it(i)),exclusive:e};this.editor.doc.broadcastMessage(r)}exclusiveBlock(t){this.exclusiveBlockIds.has(it(t))||(this.broadcastExclusiveBlockMessage([t],!0),this.exclusiveBlockIds.add(it(t)),this.exclusiveBlockIds.size===1&&this.startExclusiveBlockTimer())}unexclusiveBlock(t){!this.exclusiveBlockIds.has(it(t))||(this.exclusiveBlockIds.delete(it(t)),this.broadcastExclusiveBlockMessage([t],!1),this.exclusiveBlockIds.size===0&&this.stopExclusiveBlockTimer())}startExclusiveBlockTimer(){this.exclusiveBlockTimer=window.setInterval(()=>{Array.from(this.exclusiveBlockIds.keys()).forEach(t=>{this.broadcastExclusiveBlockMessage([this.editor.getBlockById(t)],!0)})},30*1e3)}stopExclusiveBlockTimer(){clearInterval(this.exclusiveBlockTimer),this.exclusiveBlockTimer=0}static get(t){return t.addCustom("exclusiveBlock",()=>new Ki(t))}static register(t){return this.get(t)}}function J0(n,t){Ki.get(n).exclusiveBlock(t)}function K0(n,t){Ki.get(n).unexclusiveBlock(t)}class Z7{writable(t,e){if(Rf(e))return!1}create(t,e,o,r,i){const s=Ki.get(t).getExclusiveMessage(i.id);s&&Y0(t,r,s.userId,s.displayName)}update(t,e,o,r,i){const s=Ki.get(t).getExclusiveMessage(i.id);s?Y0(t,r,s.userId,s.displayName):q7(r)}}const $nt="",y$={exclusive:{tips:"\u300C{editor}\u300D\u6B63\u5728\u7F16\u8F91\uFF0C\u300C{embedType}\u300D\u4E0D\u652F\u6301\u591A\u4EBA\u7F16\u8F91",fallbackAbstract:"\u8BE5 Block"}},k$={exclusive:{tips:"\u300C{editor}\u300Dis editing\uFF0C\u300C{embedType}\u300Ddoes not support multi-person editing",fallbackAbstract:"This Block"}},w$={exclusive:{tips:"\u300C{editor}\u300D\u306F\u7DE8\u96C6\u4E2D\u3067\u3059\u3002\u300C{embedType}\u300D\u306F\u8907\u6570\u4EBA\u3067\u540C\u6642\u7DE8\u96C6\u3067\u304D\u307E\u305B\u3093",fallbackAbstract:"\u3053\u306E\u8981\u7D20"}};R.mergeLang({"zh-CN":y$,"en-US":k$,"ja-JP":w$});function Tu(n,t){return n.getBlockData(t).lock}function Of(n,t){return!!Tu(n,t)}function Du(n,t){const e=Tu(n,t);return e?e.userId===n.doc.getUser().userId:!1}function X0(n,t){const e=Tu(n,t);return e?e.userId!==n.doc.getUser().userId:!1}function B$(n,t){if(n.readonly||!n.isBlockWritable(t)||Of(n,t)&&!Du(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 E$(n,t){if(!Du(n,t))return;const e={lock:null};n.updateBlockData(t,e)}const x$=10,I$=80;class t2{constructor(){m(this,"executeCommand",(t,e,o)=>{const r=o.data;if(!r||!r.blockId)return;const i=t.getBlockById(r.blockId);r.type==="lock"?B$(t,i):r.type==="unlock"&&E$(t,i)})}create(t,e,o,r,i){const s=i.lock;s&&(s.userId!==t.doc.getUser().userId?W(r,"locked-by-others"):W(r,"locked-by-self"))}update(t,e,o,r,i){const s=i.lock;if(s)if(s.userId!==t.doc.getUser().userId){W(r,"locked-by-others");const l=t.selection.focusedBlock;(l===r||Xt(r,l))&&(tt(t,r)||Dt(r)==="code")&&t.insertTextBlock("",at(o),bt(r)+1)}else W(r,"locked-by-self");else ot(r,"locked-by-others"),ot(r,"locked-by-self")}writable(t,e){if(X0(t,e))return!1;if(io(e))return;let o=xs(e);for(;o;){if(X0(t,o))return!1;o=xs(o)}}commands(t,e){const o=Of(t,e),r=Du(t,e),i=Rf(e),s={blockId:it(e),type:"lock"},l={id:"lock-block",name:"",data:s,order:10};if(o)if(r)l.id="unlock-block",l.name=R.t("locker.unlock"),s.type="unlock";else{const a=Tu(t,e);let d=(a==null?void 0:a.displayName)||"";const h=RC(d,x$,I$);(h==null?void 0:h.length)!==d.length&&(l.ellipsisTooltip=a==null?void 0:a.displayName,d=h||""),l.name=R.t("locker.lockedBy",{name:d}),l.states=["disabled"]}else i?(l.name=R.t("locker.lock"),l.states=["disabled"]):l.name=R.t("locker.lock");return{group:"block-locker",commands:[l],executeCommand:this.executeCommand}}}const Hnt="",T$={locker:{lock:"\u9501\u5B9A",unlock:"\u89E3\u9664\u9501\u5B9A",lockedBy:"\u88AB {name} \u9501\u5B9A"}},D$={locker:{lock:"Lock",unlock:"Unlock",lockedBy:"Locked by {name}"}},S$={locker:{lock:"\u30ED\u30C3\u30AF",unlock:"\u30ED\u30C3\u30AF\u89E3\u9664",lockedBy:"{name}\u304C\u30ED\u30C3\u30AF\u3057\u307E\u3057\u305F"}};R.mergeLang({"zh-CN":T$,"en-US":D$,"ja-JP":S$});class _f{async handleBeforePasteDoc(t,e){return Object.values(e.blocks).forEach(o=>{o.forEach(r=>{delete r.lock})}),!1}}const L$=S("standard-block-actions");class M${constructor(){m(this,"executeCommand",(t,e,o)=>{const r=o.data;try{const i=t.getBlockById(r);if(o.id==="delete"){t.deleteBlock(i);return}o.id==="copy"&&_h(t,i),o.id==="cut"&&(_h(t,i),t.deleteBlock(i))}catch(i){L$.error(`failed to execute block command: ${JSON.stringify(i)}`)}})}commands(t,e){const o=Of(t,e),r=o&&Du(t,e),i=it(e),s=H0(),l=Rf(e),a={id:"copy",name:R.t("blockMenu.command.copy"),data:i,order:1,states:s?[]:["disabled"],disableReason:s?void 0:R.t("copyCutProperty.unsafeEnvTips",{shortCut:xo("CtrlOrCmd+C"),operation:R.t("copyCutProperty.copy")})},d={id:"cut",name:R.t("blockMenu.command.cut"),data:i,order:2,states:o&&!r||!s||l?["disabled"]:[],disableReason:s?void 0:R.t("copyCutProperty.unsafeEnvTips",{shortCut:xo("CtrlOrCmd+X"),operation:R.t("copyCutProperty.cut")})},h={id:"delete",name:R.t("blockMenu.command.delete"),data:i,order:3,states:o&&!r||l?["disabled"]:[]};return{group:"standard-block-actions",commands:[a,d,h],executeCommand:this.executeCommand}}}const Q7=S("block-menu");class R${constructor(t){m(this,"menu");m(this,"currentBlock",null);m(this,"commandBlock",null);m(this,"handleShow",()=>{g(Q7,this.currentBlock,"no target block before show block menu");const t=C$(this.editor,this.currentBlock,{onAfterStyleItemClick:this.close});this.menu.updateItems(t),this.commandBlock=this.currentBlock});m(this,"handleClose",()=>{Op(this.editor)&&this.editor.focus()});m(this,"handleItemClick",(t,e)=>{g(Q7,this.commandBlock,"no command block before show block menu"),A$(this.editor,this.commandBlock,e),e.element||this.close()});m(this,"close",()=>{this.menu.close("clickItem")});this.editor=t,this.menu=new zs([],void 0,{id:"block-menu"}),this.menu.on("show",this.handleShow),this.menu.on("close",this.handleClose),this.menu.on("click",this.handleItemClick),t.blockHooks.push(new M$)}show(t,e){this.menu.manualShow(t,{placement:"bottom-start",...e})}isInMenu(t){return this.menu.isInCommandBar(t)}setBlock(t){this.currentBlock=t}get isVisible(){return this.menu.isVisible}destroy(){this.menu.destroy()}}const O$=1e3;async function _$(n,t){const{width:e}=n.rootContainer.getBoundingClientRect(),o=t.getBoundingClientRect();return o.width>e||o.height>=O$?"":(await Z5.default.toSvg(t)).replace(/margin-block:.*?;/,"").replace(/margin:.*?;/,"")}const F$=S("drag-preview-image");class P${constructor(t){m(this,"startPosition",null);m(this,"dragContainer",null);m(this,"handleDragStart",async(t,e)=>{const o=t.target;g(F$,o instanceof Element,`Invalid Drag target:${o}`);const{x:r,y:i}=t;this.startPosition={x:r,y:i};const s=w("div",["drag-image-container"],this.editor.rootContainer),l=w("img",["drag-image"],s),a=w("span",["drag-loading"],s);a.innerHTML=iM;const{x:d,width:h,height:p,y:A}=o.getBoundingClientRect(),v=this.editor.rootContainer.getBoundingClientRect(),B=e.getBoundingClientRect();s.style.left=`${d+h}px`,s.style.top=`${A+p}px`,s.style.width=`${Math.min(v.width/2,B.width)}px`,this.dragContainer=s;const x=await _$(this.editor,e);x?l.src=x:W(s,"drag-placeholder"),Am(s,{status:"loaded"})});m(this,"handleDrag",t=>{if(this.startPosition&&this.dragContainer){const{x:e,y:o}=t;if(e===0&&o===0){this.dragContainer.style.transition="transform 0.15s, opacity .15s",this.dragContainer.style.transform="",this.dragContainer.style.opacity="0";return}const{x:r,y:i}=this.startPosition,s=e-r,l=o-i;this.dragContainer.style.transform=`translate(${s}px, ${l}px)`}});m(this,"handleDragEnd",()=>{this.dragContainer&&(this.dragContainer.remove(),this.startPosition=null,this.dragContainer=null)});this.editor=t}}const Y7="drag-preview-element";function N$(n){if(xt(n,Y7))return n;const t=n.querySelector(`.${Y7}`);return t||(Me(n)?Lt(n):n)}const Ff=S("block-menu-drag-handler");function e2(n,t){return new DragEvent(t,{bubbles:!0,cancelable:!0,view:window,screenX:n.screenX,screenY:n.screenY,dataTransfer:new DataTransfer,clientX:n.clientX,clientY:n.clientY})}class $${constructor(t,e){m(this,"dragPreview");m(this,"autoScroll");m(this,"oldPos",{x:0,y:0});m(this,"handleMouseDown",t=>{const e=this.button.blockMenu.currentBlock;if(g(Ff,e,"no dragged block"),t.button!==0)return;if(!this.editor.isBlockWritable(e)){t.preventDefault(),t.stopPropagation();return}const{x:o,y:r}=t;this.oldPos={x:o,y:r},document.addEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.addEventListener("mousemove",this.handleDrag)});m(this,"handleDragStart",t=>{var s,l;const e=ro(this.button.buttonElement);this.autoScroll||(this.autoScroll=new Qd({scrollElement:e,trackMouseEvent:"mousemove",edge:{top:50,bottom:50}}));const o=this.button.blockMenu.currentBlock;g(Ff,o,"no dragged block"),(l=(s=Qt(this.editor,o)).notify)==null||l.call(s,this.editor,"beginDrag");const r=e2(t,"dragstart");V$(this.editor,r,o),window.isDragging=!0,this.button.buttonElement.style.opacity="0";const i=N$(o);this.dragPreview.handleDragStart(t,i),this.autoScroll.active(),W(o,"dragging"),W(this.editor.contentElement,"dragging")});m(this,"handleDrag",t=>{const{target:e,x:o,y:r}=t;if(this.oldPos.x===o&&this.oldPos.y===r)return;window.isDragging||this.handleDragStart(t),this.oldPos={x:o,y:r},g(Ff,e instanceof Element,"target is invalid"),this.dragPreview.handleDrag(t);const i=e2(t,"dragover");this.editor.contentElement.dispatchEvent(i)});m(this,"handleDragEnd",t=>{var r;const e=this.button.blockMenu.currentBlock;g(Ff,e,"no dragged block"),window.isDragging=!1,this.button.buttonElement.style.opacity="1",this.dragPreview.handleDragEnd(),(r=this.autoScroll)==null||r.inactive(),ot(e,"dragging"),ot(this.editor.contentElement,"dragging"),document.removeEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.removeEventListener("mousemove",this.handleDrag);const o=e2(t,"drop");this.editor.contentElement.dispatchEvent(o)});this.editor=t,this.button=e,this.button.buttonElement.addEventListener("mousedown",this.handleMouseDown),this.dragPreview=new P$(t)}destroy(){this.button.buttonElement.removeEventListener("mousedown",this.handleMouseDown)}}class Su{constructor(t){m(this,"highlightedBlockId","");m(this,"handleSelectionChange",()=>{this.clearHighlightedBlock()});this.editor=t,this.editor.addListener("selectionChanged",this.handleSelectionChange)}highlightBlock(t){this.clearHighlightedBlock(),this.highlightedBlockId=it(t),W(t,"highlighted")}clearHighlightedBlock(){if(this.highlightedBlockId){const t=this.editor.findBlockById(this.highlightedBlockId);t&&ot(t,"highlighted"),this.highlightedBlockId=""}}destroy(){}static register(t){return t.addCustom("editor-block-highlighter",()=>new Su(t))}static get(t){return t.getCustom("editor-block-highlighter")}}class J7{constructor(t){m(this,"buttonElement");m(this,"emptyBlockMenu");m(this,"blockMenu");m(this,"dragHandler");m(this,"handleHoverBlock",(t,e,o)=>{if(this.emptyBlockMenu.isVisible||this.blockMenu.isVisible||!this.editor.isWritable())return;const r=this.editor.getCustom("editor-tooltip");if(r&&r.visible()&&(r.hide(),this.buttonElement.setAttribute("data-tooltip-hide-at",`${Date.now()}`)),!t){this.buttonElement.parentElement&&(this.blockMenu.isInMenu(o.target)||this.buttonElement.remove());return}const i=Um(t);this.editor.getBlockIndex(i)===0&&this.editor.getBlockData(i).heading===1||(this.updateButton(i),Z0(i,this.buttonElement,Number.MAX_SAFE_INTEGER))});m(this,"handleButtonClick",()=>{if(this.buttonElement.getAttribute("data-type")==="move"){const o=this.blockMenu.currentBlock;if(!o)return;this.editor.selection.selectBlock(o,0),this.blockMenu.show(this.buttonElement,{placement:"bottom-end"}),setTimeout(()=>{Su.get(this.editor).highlightBlock(o)});return}const e=this.emptyBlockMenu.currentBlock;!e||(this.editor.selection.selectBlock(e,0),setTimeout(()=>{this.editor.focus(),this.updatePlaceholder(e),this.emptyBlockMenu.show()}))});m(this,"updatePlaceholder",t=>{Lt(t).setAttribute("data-content-placeholder",R.t("blockMenu.button.searchPlaceholder"))});m(this,"handleChanged",()=>{const t=this.emptyBlockMenu.currentBlock;if(!t)return;const e=he(this.editor,t)?"insert":"move";this.buttonElement.getAttribute("data-type")!==e&&this.setButtonType(e)});this.editor=t,this.buttonElement=this.createButton(),this.emptyBlockMenu=new h$(t),this.blockMenu=new R$(t),this.editor.addListener("docChanged",this.handleChanged),this.buttonElement.addEventListener("click",this.handleButtonClick),this.dragHandler=new $$(this.editor,this);const e=Ae.get(t);e.addListener("change",this.handleHoverBlock),e.addFinder(new d$),Su.register(this.editor)}destroy(){Ae.get(this.editor).removeListener("change",this.handleHoverBlock),this.buttonElement.removeEventListener("click",this.handleButtonClick),this.editor.removeListener("docChanged",this.handleChanged),this.emptyBlockMenu.destroy(),this.blockMenu.destroy(),this.buttonElement.remove(),this.dragHandler.destroy()}createButton(){const t=w("button",["block-button"],null);return t.setAttribute(`data-editor-tooltip-${this.editor.clientId}`,R.t("blockMenu.button.tips")),t.innerHTML=Cv,t}setButtonType(t){this.buttonElement.setAttribute("data-type",t);const e=`data-editor-tooltip-${this.editor.clientId}-dynamic`;this.buttonElement.hasAttribute(e)&&this.buttonElement.removeAttribute(e),t==="insert"?(this.buttonElement.innerHTML=rM,this.buttonElement.setAttribute(e,R.t("blockMenu.button.insertTips"))):(this.buttonElement.innerHTML=Cv,this.buttonElement.setAttribute(e,R.t("blockMenu.button.tips")))}updateButton(t){this.emptyBlockMenu.setBlock(t),this.blockMenu.setBlock(t),he(this.editor,t)?this.setButtonType("insert"):this.setButtonType("move")}}const H$={blockMenu:{section:{basics:"\u57FA\u7840",system:"\u7CFB\u7EDF",styles:"\u6837\u5F0F",common:"\u901A\u7528",actions:"\u64CD\u4F5C",thirdParty:"\u7B2C\u4E09\u65B9\u5185\u5BB9"},command:{insertAbove:"\u5728\u4E0A\u65B9\u63D2\u5165",insertAfter:"\u5728\u4E0B\u65B9\u63D2\u5165",copy:"\u590D\u5236",cut:"\u526A\u5207",delete:"\u5220\u9664"},button:{searchPlaceholder:"\u8F93\u5165\u5173\u952E\u8BCD\u641C\u7D22",tips:`\u957F\u6309\u62D6\u62FD
|
|
422
422
|
\u70B9\u51FB\u6253\u5F00\u83DC\u5355`,insertTips:"\u70B9\u51FB\u6DFB\u52A0\u533A\u5757"}}},j$={blockMenu:{section:{basics:"Basic",system:"System",styles:"Styles",common:"Common",actions:"Actions",thirdParty:"Third-party content"},command:{insertAbove:"Insert above",insertAfter:"Insert below",copy:"Copy",cut:"Cut",delete:"Delete"},button:{searchPlaceholder:"Search",tips:`Hold to drag
|
|
423
|
-
Click to open the menu`,insertTips:"Click to add block"}}},U$={blockMenu:{section:{basics:"\u4E00\u822C",system:"\u30B7\u30B9\u30C6\u30E0",styles:"\u30B9\u30BF\u30A4\u30EB",common:"\u4E00\u822C",actions:"\u64CD\u4F5C",thirdParty:"\u5916\u90E8\u30B3\u30F3\u30C6\u30F3\u30C4"},command:{insertAbove:"\u4E0A\u306B\u633F\u5165",insertAfter:"\u4E0B\u306B\u633F\u5165",copy:"\u8907\u88FD",cut:"\u5207\u308B",delete:"\u524A\u9664"},button:{searchPlaceholder:"\u30AD\u30FC\u30EF\u30FC\u30C9\u3067\u691C\u7D22",tips:"\u3092\u30C9\u30E9\u30C3\u30B0\u3057\u3066\u30AF\u30EA\u30C3\u30AF\u3067\u30E1\u30CB\u30E5\u30FC\u3092\u8868\u793A",insertTips:"\u30AF\u30EA\u30C3\u30AF\u3057\u3066\u30D6\u30ED\u30C3\u30AF\u3092\u8FFD\u52A0"}}};R.mergeLang({"zh-CN":H$,"en-US":j$,"ja-JP":U$});const jnt="";class z${constructor(){m(this,"dragObject",null)}setData(t){this.dragObject=t}getData(){return this.dragObject}clearData(){this.dragObject=null}destroy(){}}function Pf(n){return n.addCustom("drag-data",()=>new z$)}function n2(n,t){if(!t)return null;const e=Pf(n).getData();return!e||e.editorId!==n.id?null:e}function K7(n,t){const e=n2(n,t);return e?n.findBlockById(e.blockId):null}function V$(n,t,e){if(!t.dataTransfer)return;const r=nt(e),i=at(r),s=it(e),l={type:"block",editorId:n.id,containerId:i,blockId:s};Pf(n).setData(l)}function W$(n,t,e,o,r){if(!t.dataTransfer)return;const s=nt(e),l=at(s),a=it(e),d={type:"custom",customType:o,editorId:n.id,containerId:l,blockId:a,data:r};Pf(n).setData(d)}function q$(n){Pf(n).clearData()}const G$=S("drop-indicator"),Nf=2;class Z${constructor(t){m(this,"indicator");m(this,"target",null);this.editor=t,this.indicator=w("div",["editor-drop-indicator"],this.editor.contentElement)}show(t,e){const o=this.getIndicatorRect(t,e),r=this.editor.rootElement.getBoundingClientRect(),i=o.top-r.top,s=o.left-r.left;this.indicator.style.top=`${i}px`,this.indicator.style.left=`${s}px`,this.indicator.style.width=`${o.width}px`,this.indicator.style.height=`${o.height}px`,this.indicator.style.display="",this.target={block:t,insertPos:e}}hide(){this.indicator.style.display="none",this.target=null}getIndicatorRect(t,e){if(typeof e!="string")return e.rect;if(e==="before"){const s=Ts(t);if(!s){g(G$,Lo(nt(t)),"block does not in a child container");const d=t.getBoundingClientRect();return new DOMRect(d.x,d.y,d.width,Nf)}const l=s.getBoundingClientRect(),a=t.getBoundingClientRect();return new DOMRect(l.x,(l.bottom+a.top)/2,l.width,Nf)}const o=Ds(t);if(!o){const s=t.getBoundingClientRect();return new DOMRect(s.x,s.bottom,s.width,Nf)}const r=t.getBoundingClientRect(),i=o.getBoundingClientRect();return new DOMRect(r.x,(r.bottom+i.top)/2,r.width,Nf)}}const Q$=S("find-drop-target");function Y$(n,t){const e=document.elementFromPoint(n,t);if(!e)return null;if(Pr(e)&&Lo(e))return e;const o=e.firstElementChild;return o&&Pr(o)&&Lo(o)?o:null}function J$(n,t){const s=t,l=n;for(let a=0;a<2;a++){const d=l+a*50;for(let h=0;h<5;h++){const p=s+h*8,A=document.elementFromPoint(d,p);if(A){const D=et(A);if(D)return D}if(h===0)continue;const v=s-h*8,B=document.elementFromPoint(d,v);if(B){const D=et(B);if(D)return D}}}return null}function K$(n,t,e){const o=document.elementFromPoint(t,e);if(o){const h=et(o);if(h&&!Mt(n,h))return h}const r=new Set,i=Y$(t,e);if(i){const h=i.getBoundingClientRect();e<h.top+h.height/2?r.add(xe(i)):r.add(Qe(i))}const s=J$(t,e);s&&r.add(s);const l=Array.from(r),a=h=>{for(let p=0;p<l.length;p++){const A=l[p];if(h!==A&&Xt(h,A))return!0}return!1},d=l.filter(h=>!a(h));return d.length>0?d[0]:null}function o2(n,t){if(n.readonly)return!1;const e=nt(t);if(Yt(e))return!0;const o=et(e);return g(Q$,o,"no parent block"),n.isBlockWritable(o)?o2(n,o):!1}const X$=S("drop-target");function tH(n,t){let e={};return/image/.test(t.type)?e=n.editorEmbeds.getEmbedClass("image"):/audio/.test(t.type)?e=n.editorEmbeds.getEmbedClass("audio"):/video/.test(t.type)&&(e=n.editorEmbeds.getEmbedClass("video")),g(X$,e,`unSupport file type ${t.type}`),e}async function X7(n,t,e,o){var i,s;let r=o;for(const l of t){const a=tH(n,l);a.getOptions&&await((s=(i=a.getOptions(n)).handleInsertEmptyEmbed)==null?void 0:s.call(i,n,{containerId:e,blockIndex:r,data:{file:l}}))&&(r+=1)}}class eH{constructor(t){m(this,"handleDrop",(t,e,o,r)=>{if(Array.isArray(e)){const i=e;if(i.length>0){const s=at(o);return X7(t,i,s,r),!0}}return!1});this.editor=t}}class Lu{constructor(t){m(this,"indicator");m(this,"lastDropOverResult");m(this,"handlers",[]);m(this,"handleDragOver",t=>{if(!this.editor.isWritable())return;const e=i=>{var d,h;const s=n2(this.editor,i.dataTransfer),l=K7(this.editor,i.dataTransfer),a=this.findTargetBlock(l,i.x,i.y);if(a&&Xt(this.editor.rootContainer,a)){const p=this.findInsertPos(l,a,i.x,i.y,(h=s!=null?s:(d=i.dataTransfer)==null?void 0:d.items)!=null?h:null);if(p)return this.indicator.show(a,p),"move"}return this.indicator.hide(),"none"},o=(i,s)=>{i.dataTransfer&&(i.dataTransfer.dropEffect=s),s==="move"&&i.preventDefault()};if(this.lastDropOverResult&&t.x===this.lastDropOverResult.x&&t.y===this.lastDropOverResult.y){const i=this.lastDropOverResult.dropEffect;o(t,i);return}const r=e(t);o(t,r),this.lastDropOverResult={x:t.x,y:t.y,dropEffect:r}});m(this,"handleDrop",t=>{var i,s;t.stopPropagation(),setTimeout(()=>{this.indicator.hide()});const e=n2(this.editor,t.dataTransfer),o=Array.from((s=(i=t.dataTransfer)==null?void 0:i.files)!=null?s:[]);if(!e&&o.length===0){t.dataTransfer&&(t.dataTransfer.dropEffect="none");return}const r=this.indicator.target;if(r){const{block:l,insertPos:a}=r,d=K7(this.editor,t.dataTransfer);this.editor.undoManager.runInGroup(()=>{const h=Qt(this.editor,l);if(h.handleDrop&&h.handleDrop(this.editor,l,e!=null?e:o,a,{isSourceBlock:!1,targetBlock:l})){t.preventDefault(),this.editor.focus();return}if(d){const p=Qt(this.editor,d);if(p.handleDrop&&p.handleDrop(this.editor,d,e!=null?e:o,a,{isSourceBlock:!0,targetBlock:l})){t.preventDefault(),this.editor.focus();return}}if(typeof a=="string"){const p=nt(l);let A=bt(l);a==="after"&&(A+=1),t.preventDefault();for(let v=0;v<this.handlers.length;v++)if(this.handlers[v].handleDrop(this.editor,d!=null?d:o,p,A)){this.editor.focus();return}if(d){const v=this.editor.getBlockData(d),B=Fi(this.editor.editorBlocks,this.editor.doc.toJSON(),v),[D]=this.editor.insertDocAt(p,A,B);this.editor.selection.selectBlock(D,0),Su.get(this.editor).highlightBlock(D),this.editor.deleteBlock(d),this.editor.focus()}}}),q$(this.editor)}});m(this,"handleDragLeave",()=>{this.indicator.hide()});this.editor=t,this.indicator=new Z$(this.editor),this.handlers.push(new eH(this.editor)),this.editor.contentElement.addEventListener("dragover",this.handleDragOver),this.editor.contentElement.addEventListener("dragleave",this.handleDragLeave),this.editor.contentElement.addEventListener("drop",this.handleDrop)}destroy(){this.editor.contentElement.removeEventListener("dragover",this.handleDragOver),this.editor.contentElement.removeEventListener("dragleave",this.handleDragLeave),this.editor.contentElement.removeEventListener("drop",this.handleDrop),this.handlers=[]}addHandler(t){this.handlers.push(t)}static register(t){return t.addCustom("drop-target",()=>new Lu(t))}static get(t){return t.getCustom("drop-target")}static find(t){return t.findCustom("drop-target")}canInsertAfter(t,e){return!(this.editor.readonly||Ds(e)===t&&t||!o2(this.editor,e))}canInsertBefore(t,e){return!(this.editor.readonly||Ts(e)===t&&t||!o2(this.editor,e)||Yt(nt(e))&&bt(e)===0)}canDrop(t,e){return t===null||t===e?!0:!Xt(t,e)}findTargetBlock(t,e,o){let r=K$(this.editor,e,o);if(!r||!Xt(this.editor.rootContainer,r))return null;const i=nt(r),s=et(i);return s&&Dt(s)==="code"&&(r=s),this.canDrop(t,r)?r:null}findInsertPos(t,e,o,r,i){let s=e;for(;s;){const a=Qt(this.editor,s);if(a.handleDropOver){const d=a.handleDropOver(this.editor,s,i,o,r);if(d)return d;if(d===!1)return null}s=xs(s)}if(t===e)return"";const l=e.getBoundingClientRect();if(l.top<=r&&r<=l.bottom){if(r<l.top+l.height/2){if(this.canInsertBefore(t,e))return"before";if(this.canInsertAfter(t,e))return"after"}else{if(this.canInsertAfter(t,e))return"after";if(this.canInsertBefore(t,e))return"before"}return""}return r<l.top&&this.canInsertBefore(t,e)?"before":l.bottom<r&&this.canInsertAfter(t,e)?"after":""}}function ty(n,t,e){const o=Ie.getImageObject(n,t),r=mt.default(o.getImages());if(r.length===1){n.deleteBlock(t);return}if(e===-1||e>=r.length)return;const i=jN(r);if(r.splice(e,1),r.length===1){const l=r[0],a=100*(l.flex/i);l.flex=1;const d=cn([l],a);n.updateEmbedData(t,d);return}r[0].flex=NaN,wu(r);const s=cn(r,o.getWidthPercent());n.updateEmbedData(t,s)}function nH(n,t,e,o){if(t.length===0||o==="after"||o==="before")return!1;let r=o.data;const i=Ie.getImageObject(n,e),s=mt.default(i.getImages()),l=[],a=[];t.forEach(p=>{H7(p.type)&&s.length+l.length<6?l.push(p):a.push(p)}),l.forEach(p=>{try{$7(n,p)}catch{return}const A={src:"",flex:1,width:0,height:0,virtualSize:!0};s.splice(r,0,A);const v=cn(s,i.getWidthPercent());n.updateEmbedData(e,v),i.replaceImage(r,p),r+=1});const d=n.getBlockIndex(e)+1,h=at(nt(e));return X7(n,a,h,d),!0}function oH(n,t,e,o,r){var s,l,a;if(Gd(e))return nH(n,e,t,o);if(e.type!=="custom"||e.customType!=="image"||!e.data)return;const i=e.data;if(r.isSourceBlock){const d=r.targetBlock,h=nt(d);let p=bt(d);o==="after"&&(p+=1);const v=100*(i.boundingRect.width/n.rootContainer.getBoundingClientRect().width),B=cn([i.image],v),D={id:K(),type:"embed",embedType:"image",embedData:B},x=(l=(s=n.options.componentsOptions)==null?void 0:s.image)==null?void 0:l.defaultAlign;x&&(D.align=x),n.insertBlock(at(h),p,D),ty(n,t,i.index),(a=n.findCustom("drag-handler"))==null||a.handleDragEnd()}else{if(typeof o=="string")return;const d=t;let h=o.data;const p=Ie.getImageObject(n,d),A=mt.default(p.getImages());h>A.length&&(h=A.length),n.undoManager.runInGroup(()=>{var B,D;p.setAutoFix(!0);const v=n.getBlockById(e.blockId);if(v===d){const x=i.index,_=h,M=i.image;if(x===_||_===x+1)return;let H=_;x<_?(A.splice(_,0,M),A.splice(x,1),H-=1):(A.splice(x,1),A.splice(_,0,M));const z=cn(A,p.getWidthPercent());n.updateEmbedData(d,z),p.setSelectedIndex(H),(B=n.findCustom("drag-handler"))==null||B.handleDragEnd()}else{A.splice(h,0,i.image),A[0].flex=NaN,wu(A);const x=cn(A,p.getWidthPercent());n.updateEmbedData(d,x),ty(n,v,i.index),(D=n.findCustom("drag-handler"))==null||D.handleDragEnd(),p.setSelectedIndex(h),n.selection.selectBlock(d,0)}})}return!0}const rH=2;function $f(n,t,e){const o=Cr(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,rH,r.height)}function iH(n,t,e,o,r){for(let i=0;i<e.length;i++){const l=e[i].getBoundingClientRect();if(o<=l.right)return o<=l.left+l.width/2?{rect:$f(n,t,i),data:i}:{rect:$f(n,t,i+1),data:i+1}}return o>e[e.length-1].getBoundingClientRect().right?{rect:$f(n,t,e.length),data:e.length}:{rect:$f(n,t,e.length),data:0}}function sH(n,t,e,o,r){const i=Cr(t);if(e instanceof DataTransferItemList){if(!Array.from(e).some(s=>H7(s.type))||i.length>=6)return}else{if((e==null?void 0:e.type)==="block"||i.length>=6&&(e==null?void 0:e.blockId)!==it(t))return;const s=it(t);if(i.length===1&&s===(e==null?void 0:e.blockId))return}return iH(n,t,i,o)}async function lH(n){return await Z5.default.toSvg(n)}function r2(n,t){return new DragEvent(t,{bubbles:!0,cancelable:!0,view:window,screenX:n.screenX,screenY:n.screenY,dataTransfer:new DataTransfer,clientX:n.clientX,clientY:n.clientY})}class cH{constructor(t){m(this,"img");m(this,"dragContainer",null);m(this,"autoScroll",null);m(this,"imageContainer",null);m(this,"startPosition",null);m(this,"handleMouseDown",t=>{const e=t.target;if(!e||!(e instanceof HTMLImageElement)||t.button!==0)return;const o=et(e);if(!o||!Wo(o)||!this.editor.isBlockWritable(o)||this.editor.readonly)return;const r=Ie.getImageObject(this.editor,o);if(this.imageContainer=q0(t.target),!this.imageContainer)return;const s=R7(t.target).indexOf(this.imageContainer);if(s===-1)return;const l=r.getImages()[s];if(!l)return;const{x:a,y:d}=t;this.startPosition={x:a,y:d};const h={image:l,index:s,boundingRect:this.imageContainer.getBoundingClientRect()},p=r2(t,"dragstart");W$(this.editor,p,o,"image",h),document.addEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.addEventListener("mousemove",this.handleDrag),t.preventDefault()});m(this,"handleDragStart",async t=>{if(!this.imageContainer)return;const e=et(this.imageContainer);if(!e)return;const{x:o,y:r}=t,{width:i,height:s}=t.target.getBoundingClientRect(),l=te(e),a=w("div",["drag-container"],l);a.style.left=`${o-i/4}px`,a.style.top=`${r-s/4}px`,a.style.width=`${Math.max(i/2,16)}px`,a.style.height=`${s/2}px`,this.dragContainer=a,W(this.editor.contentElement,"dragging");const d=ro(e);this.autoScroll=new Qd({scrollElement:d,trackMouseEvent:"mousemove",edge:{top:50,bottom:50}}),this.autoScroll.active();const h=w("img",["drag-target"],a),A=await lH(this.imageContainer);A&&(h.src=A)});m(this,"handleDrag",t=>{var i;const{x:e,y:o}=t;if(((i=this.startPosition)==null?void 0:i.x)===e&&this.startPosition.y===o)return;if(window.isDragging||(window.isDragging=!0,this.handleDragStart(t)),this.startPosition&&this.dragContainer){const{x:s,y:l}=t;if(s===0&&l===0){this.dragContainer.style.transform="",this.dragContainer.style.opacity="0";return}const{x:a,y:d}=this.startPosition,h=s-a,p=l-d;this.dragContainer.style.transform=`translate(${h}px, ${p}px)`,this.dragContainer.style.opacity="0.5"}const r=r2(t,"dragover");this.editor.contentElement.dispatchEvent(r)});m(this,"handleDragEnd",t=>{var e;if(window.isDragging=!1,this.dragContainer&&this.dragContainer.remove(),this.dragContainer=null,this.startPosition=null,this.imageContainer=null,(e=this.autoScroll)==null||e.inactive(),ot(this.editor.contentElement,"dragging"),document.removeEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.removeEventListener("mousemove",this.handleDrag),t){const o=r2(t,"drop");this.editor.contentElement.dispatchEvent(o)}});this.editor=t,this.editor.rootContainer.addEventListener("mousedown",this.handleMouseDown),this.img=new Image,this.img.src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"}destroy(){this.editor.rootContainer.removeEventListener("mousedown",this.handleMouseDown)}}class aH{constructor(t){m(this,"handleFocusBlockChanged",(t,e,o)=>{const i=this.editor.getFocusedBlock();if(i&&Wo(i)){const s=Ie.getImageObject(this.editor,i);s.getImages().length>0&&s.getSelectedIndex()===-1&&s.setSelectedIndex(0)}o&&Wo(o)&&Ie.getImageObject(this.editor,o).blockResizer.disableResize()});this.editor=t,this.editor.addListener("focusBlockChanged",this.handleFocusBlockChanged)}destroy(){this.editor.removeListener("focusBlockChanged",this.handleFocusBlockChanged)}}class uH{constructor(t){m(this,"currentResizer",null);m(this,"handleHoveringBlockChange",(t,e)=>{window.isDragging||(e&&this.disable(e),t&&(this.currentResizer=t,this.enable(t)))});this.editor=t,Ae.get(t).addListener("change",this.handleHoveringBlockChange)}destroy(){Ae.get(this.editor).removeListener("change",this.handleHoveringBlockChange)}disable(t){Wo(t)&&Ie.getImageObject(this.editor,t).disableResizer()}enable(t){if(Wo(t)){const e=Ie.getImageObject(this.editor,t);this.editor.isBlockWritable(t)&&e.tryEnableResizer()}}}const dH={image:{title:"\u56FE\u7247",upload:{failed:'<div class="line-1">\u56FE\u7247\u4E0A\u4F20\u5931\u8D25</div><div class="line-2">\u7F51\u7EDC\u670D\u52A1\u5F02\u5E38\uFF0C\u4F60\u53EF\u4EE5 <a href="" class="retry-upload">\u91CD\u8BD5</a></div>'},load:{failed:'<div class="line-1">\u56FE\u7247\u52A0\u8F7D\u5931\u8D25</div><div class="line-2">\u7F51\u7EDC\u670D\u52A1\u5F02\u5E38\uFF0C\u4F60\u53EF\u4EE5 <a href="" class="retry-upload">\u91CD\u8BD5</a></div>',remote:{failed:'<div class="line-1">\u56FE\u7247\u52A0\u8F7D\u5931\u8D25</div><div class="line-2">\u8BE5\u56FE\u7247\u6765\u81EA\u5916\u90E8\u94FE\u63A5\uFF0C\u5916\u90E8\u94FE\u63A5\u5DF2\u5931\u6548</div><div class="line-3">\u8BF7\u5C06\u539F\u56FE\u4FDD\u5B58\u5230\u672C\u5730\u540E\u4E0A\u4F20\uFF0C <a href="" class="retry-upload">\u6253\u5F00\u56FE\u7247\u94FE\u63A5</a></div>',tooltip:"\u8BE5\u56FE\u7247\u6765\u81EA\u5916\u90E8\u94FE\u63A5\uFF0C\u5982\u679C\u94FE\u63A5\u5931\u6548\u56FE\u7247\u5C06\u65E0\u6CD5\u67E5\u770B\uFF0C\u5EFA\u8BAE\u4FDD\u5B58\u5230\u672C\u5730\u540E\u6DFB\u52A0\u5230\u9875\u9762\u4E2D"}},abstract:"\u56FE\u7247"}},hH={image:{title:"Image",upload:{failed:'<div class="line-1">Image upload failed</div><div class="line-2">Network error, you can <a href="" class="retry-upload">Retry</a></div>'},load:{failed:'<div class="line-1">Image failed to load</div><div class="line-2">Network error, you can <a href="" class="retry-upload">Retry</a></div>',remote:{failed:'<div class="line-1">Failed to load image</div><div class="line-2">This picture is from an expired external link</div><div class="line-3">Please save the original image to local drives and upload it. <a href="" class="retry-upload">Open image link</a></div>',tooltip:"This picture is from an external link. If the link expires, the picture will not be available. It's recommended to save it to local drives and add it to the page."}},abstract:"Image"}},fH={image:{title:"\u753B\u50CF",upload:{failed:'<div class="line-1">\u753B\u50CF\u3092\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F</div><div class="line-2">\u304A\u4F7F\u3044\u306E\u30CD\u30C3\u30C8\u30EF\u30FC\u30AF\u63A5\u7D9A\u306B\u554F\u984C\u304C\u767A\u751F\u3057\u307E\u3057\u305F\u3002\u6B21\u306E\u64CD\u4F5C\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002 <a href="" class="retry-upload">\u518D\u8A66\u884C</a></div>'},load:{failed:'<div class="line-1">\u753B\u50CF\u3092\u8AAD\u307F\u8FBC\u3081\u307E\u305B\u3093\u3067\u3057\u305F</div><div class="line-2">\u304A\u4F7F\u3044\u306E\u30CD\u30C3\u30C8\u30EF\u30FC\u30AF\u63A5\u7D9A\u306B\u554F\u984C\u304C\u767A\u751F\u3057\u307E\u3057\u305F\u3002\u6B21\u306E\u64CD\u4F5C\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002 <a href="" class="retry-upload">\u518D\u8A66\u884C</a></div>',remote:{failed:'<div class="line-1">\u753B\u50CF\u3092\u8AAD\u307F\u8FBC\u3081\u307E\u305B\u3093\u3067\u3057\u305F</div><div class="line-2">\u3053\u306E\u753B\u50CF\u306B\u30EA\u30F3\u30AF\u3057\u3066\u3044\u308B URL \u304C\u7121\u52B9\u306B\u306A\u3063\u3066\u3044\u307E\u3059\u306E\u3067\u3001\u8868\u793A\u3067\u304D\u307E\u305B\u3093</div><div class="line-3">\u753B\u50CF\u3092\u30ED\u30FC\u30AB\u30EB\u306B\u4FDD\u5B58\u3057\u3066\u30A2\u30C3\u30D7\u30ED\u30FC\u30C0\u3057\u3066\u304F\u3060\u3055\u3044 <a href="" class="retry-upload">\u753B\u50CF\u30EA\u30F3\u30AF\u3092\u958B\u304F</a></div>',tooltip:"\u3053\u306E\u753B\u50CF\u306F\u5916\u90E8\u306B\u30EA\u30F3\u30AF\u3057\u3066\u3044\u308B\u305F\u3081\u3001\u30EA\u30F3\u30AF\u304C\u7121\u52B9\u306B\u306A\u308B\u3068\u3001\u8868\u793A\u3067\u304D\u306A\u304F\u306A\u308A\u307E\u3059\u306E\u3067\u3001\u30ED\u30FC\u30AB\u30EB\u306B\u4FDD\u5B58\u3057\u3001\u30DA\u30FC\u30B8\u306B\u633F\u5165\u3059\u308B\u3053\u3068\u3092\u304A\u52E7\u3081\u3057\u307E\u3059"}},abstract:"\u753B\u50CF"}};R.mergeLang({"zh-CN":dH,"en-US":hH,"ja-JP":fH});function mH(n,t,e,o){const r=n.getBlockByIndex(t,e),i=n.getBlockText(r),{left:s}=In(i,o),l=ie(s);let a=o;if(l.endsWith("![]()"))a-=5;else if(l.endsWith("![]"))a-=3;else return!1;const d=o;return Ul("image/*").then(h=>{n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,a,d-a);let p=e+1;ie(n.getBlockText(r)).trim()?(Ql(n,r,a,{forceInsertAfter:!0}),a===0&&(n.deleteBlock(r),p--)):(n.deleteBlock(r),p--),Vm(n,"image",t,p,{file:h})})}),!0}class gH{handleAfterInsertText(t,e,o,r,i){return!!(i===" "&&mH(t,e,o,r))}}function pH(n){const t=n.getFocusedBlock(),e=Ds(t);if(e&&Wo(e)){n.selection.selectBlock(e,0);const o=Ie.getImageObject(n,e);return o.getImages().length>0&&o.setSelectedIndex(0),!0}}function CH(n){const t=n.getFocusedBlock(),e=Ts(t);if(e&&Wo(e)){n.selection.selectBlock(e,0);const o=Ie.getImageObject(n,e);return o.getImages().length>0&&o.setSelectedIndex(0),!0}}function AH(n){const e=n.getFocusedBlock();if(e&&Wo(e)){const o=Ie.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 bH(n){const e=n.getFocusedBlock();if(e&&Wo(e)){const o=Ie.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 i2(n){const e=n.getFocusedBlock();if(e&&Wo(e)){const o=Ie.getImageObject(n,e);if(o.getImages().length>0){const i=o.getSelectedIndex();if(i!==-1)return o.removeImage(i),!0}}}const vH={ArrowLeft:AH,ArrowRight:bH,ArrowUp:CH,ArrowDown:pH,Delete:i2,Backspace:i2},yH=S("copy-image");function kH(n,t,e,o){const r=e.getImages()[o],i=e.getImages().length===1?e.getWidthPercent():r.flex*100,s=cn([r],i),l={id:K(),type:"embed",embedType:"image",embedData:s},a=n.options.componentsOptions.image;a!=null&&a.defaultAlign&&(l.align=a.defaultAlign);const d={blocks:{root:[l]},comments:{},meta:{}},h=document.createElement("canvas");h.width=t.naturalWidth,h.height=t.naturalHeight;const p=h.getContext("2d");if(!p)return;const A={},v={};try{p.drawImage(t,0,0,h.width,h.height);const z=h.toDataURL("image/png").replace(/^data:image\/(png|jpg);base64,/,""),q=Im(z),rt=new File([q],`${Date.now()}.png`,{type:"image/png"});A["image/png"]=rt}catch(H){yH.error(H)}Oh(n,d);const D=`<img src="${n.doc.buildResourceUrl(r.src,{withToken:!0})}" />`,x=Rh(D,d),_=Ra(n,d);A["text/plain"]=new Blob([_],{type:"text/plain"}),v["text/plain"]=_;const M=new Blob([x],{type:"text/html"});return A["text/html"]=M,v["text/html"]=x,[A,v]}function wH(n,t,e,o,r){const i=kH(n,t,e,o);if(!i)return;const[s,l]=i;if(s){const a=Object.entries(s).map(([d,h])=>({type:d,data:h}));return Sm(a).then(d=>{if(!d&&r){const h=r.clipboardData;h&&(h.setData("text/plain",l["text/plain"]),h.setData("text/html",l["text/html"]))}}),!0}}function ey(n,t){const e=n.selection.range;if(e.start.blockId!==e.end.blockId)return;const r=n.getFocusedBlock();if(r&&Wo(r)){const i=Ie.getImageObject(n,r);if(i.getImages().length>0){const l=i.getSelectedIndex();if(l!==-1){const d=Cr(r)[l].querySelector("img");if(d)return wH(n,d,i,l,t)}}}}class BH{constructor(t){this.editor=t,setTimeout(()=>{this.editor.input.addHandler(this)})}handleBeforeCopy(t,e,o){if(ey(t,e))return!0}handleBeforeCut(t,e){if(ey(t,e))return i2(t),!0}destroy(){}}class s2{constructor(t){this.editor=t,setTimeout(()=>{this.editor.input.addHandler(this)})}async handleAfterPasteDoc(t,e,o){return Object.values(e.blocks).forEach(r=>{r.forEach(i=>{if(i.type==="embed"&&i.embedType==="image"){const s=i.embedData;if(Array.isArray(s.src))return;if(s.src.startsWith("https:")||s.src.startsWith("http:")){const l=o.blockIdMap.get(i.id);l&&Ji(t,l).setAutoFix(!0)}}})}),!1}destroy(){}}const EH=S("image-embed");function xH(n,t,e,o,r,i){Ie.create(n,e).createContent(r,i,t),n.addCustom("image-select-handler",()=>new aH(n)),n.addCustom("image-copy-handler",()=>new BH(n)),setTimeout(()=>{n.addCustom("drag-handler",()=>new cH(n));const l=n.addCustom("image-resizer",()=>new uH(n)),a=e.embedData;yc(a)?l.disable(i):l.currentResizer===i&&l.enable(i)})}function IH(n,t,e,o){const r=t.embedData,i=kc(r);return o==="html"?i.map(s=>`<img src="${n.doc.buildResourceUrl(s.src,{withToken:!0})}">`).join(""):o==="markdown"?`${i.map(l=>`})`).join(`
|
|
423
|
+
Click to open the menu`,insertTips:"Click to add block"}}},U$={blockMenu:{section:{basics:"\u4E00\u822C",system:"\u30B7\u30B9\u30C6\u30E0",styles:"\u30B9\u30BF\u30A4\u30EB",common:"\u4E00\u822C",actions:"\u64CD\u4F5C",thirdParty:"\u5916\u90E8\u30B3\u30F3\u30C6\u30F3\u30C4"},command:{insertAbove:"\u4E0A\u306B\u633F\u5165",insertAfter:"\u4E0B\u306B\u633F\u5165",copy:"\u8907\u88FD",cut:"\u5207\u308B",delete:"\u524A\u9664"},button:{searchPlaceholder:"\u30AD\u30FC\u30EF\u30FC\u30C9\u3067\u691C\u7D22",tips:"\u3092\u30C9\u30E9\u30C3\u30B0\u3057\u3066\u30AF\u30EA\u30C3\u30AF\u3067\u30E1\u30CB\u30E5\u30FC\u3092\u8868\u793A",insertTips:"\u30AF\u30EA\u30C3\u30AF\u3057\u3066\u30D6\u30ED\u30C3\u30AF\u3092\u8FFD\u52A0"}}};R.mergeLang({"zh-CN":H$,"en-US":j$,"ja-JP":U$});const jnt="";class z${constructor(){m(this,"dragObject",null)}setData(t){this.dragObject=t}getData(){return this.dragObject}clearData(){this.dragObject=null}destroy(){}}function Pf(n){return n.addCustom("drag-data",()=>new z$)}function n2(n,t){if(!t)return null;const e=Pf(n).getData();return!e||e.editorId!==n.id?null:e}function K7(n,t){const e=n2(n,t);return e?n.findBlockById(e.blockId):null}function V$(n,t,e){if(!t.dataTransfer)return;const r=nt(e),i=at(r),s=it(e),l={type:"block",editorId:n.id,containerId:i,blockId:s};Pf(n).setData(l)}function W$(n,t,e,o,r){if(!t.dataTransfer)return;const s=nt(e),l=at(s),a=it(e),d={type:"custom",customType:o,editorId:n.id,containerId:l,blockId:a,data:r};Pf(n).setData(d)}function q$(n){Pf(n).clearData()}const G$=S("drop-indicator"),Nf=2;class Z${constructor(t){m(this,"indicator");m(this,"target",null);this.editor=t,this.indicator=w("div",["editor-drop-indicator"],this.editor.contentElement)}show(t,e){const o=this.getIndicatorRect(t,e),r=this.editor.rootElement.getBoundingClientRect(),i=o.top-r.top,s=o.left-r.left;this.indicator.style.top=`${i}px`,this.indicator.style.left=`${s}px`,this.indicator.style.width=`${o.width}px`,this.indicator.style.height=`${o.height}px`,this.indicator.style.display="",this.target={block:t,insertPos:e}}hide(){this.indicator.style.display="none",this.target=null}getIndicatorRect(t,e){if(typeof e!="string")return e.rect;if(e==="before"){const s=Ts(t);if(!s){g(G$,Lo(nt(t)),"block does not in a child container");const d=t.getBoundingClientRect();return new DOMRect(d.x,d.y,d.width,Nf)}const l=s.getBoundingClientRect(),a=t.getBoundingClientRect();return new DOMRect(l.x,(l.bottom+a.top)/2,l.width,Nf)}const o=Ds(t);if(!o){const s=t.getBoundingClientRect();return new DOMRect(s.x,s.bottom,s.width,Nf)}const r=t.getBoundingClientRect(),i=o.getBoundingClientRect();return new DOMRect(r.x,(r.bottom+i.top)/2,r.width,Nf)}}const Q$=S("find-drop-target");function Y$(n,t){const e=document.elementFromPoint(n,t);if(!e)return null;if(Pr(e)&&Lo(e))return e;const o=e.firstElementChild;return o&&Pr(o)&&Lo(o)?o:null}function J$(n,t){const s=t,l=n;for(let a=0;a<2;a++){const d=l+a*50;for(let h=0;h<5;h++){const p=s+h*8,A=document.elementFromPoint(d,p);if(A){const D=et(A);if(D)return D}if(h===0)continue;const v=s-h*8,B=document.elementFromPoint(d,v);if(B){const D=et(B);if(D)return D}}}return null}function K$(n,t,e){const o=document.elementFromPoint(t,e);if(o){const h=et(o);if(h&&!Mt(n,h))return h}const r=new Set,i=Y$(t,e);if(i){const h=i.getBoundingClientRect();e<h.top+h.height/2?r.add(xe(i)):r.add(Qe(i))}const s=J$(t,e);s&&r.add(s);const l=Array.from(r),a=h=>{for(let p=0;p<l.length;p++){const A=l[p];if(h!==A&&Xt(h,A))return!0}return!1},d=l.filter(h=>!a(h));return d.length>0?d[0]:null}function o2(n,t){if(n.readonly)return!1;const e=nt(t);if(Yt(e))return!0;const o=et(e);return g(Q$,o,"no parent block"),n.isBlockWritable(o)?o2(n,o):!1}const X$=S("drop-target");function tH(n,t){let e={};return/image/.test(t.type)?e=n.editorEmbeds.getEmbedClass("image"):/audio/.test(t.type)?e=n.editorEmbeds.getEmbedClass("audio"):/video/.test(t.type)&&(e=n.editorEmbeds.getEmbedClass("video")),g(X$,e,`unSupport file type ${t.type}`),e}async function X7(n,t,e,o){var i,s;let r=o;for(const l of t){const a=tH(n,l);a.getOptions&&await((s=(i=a.getOptions(n)).handleInsertEmptyEmbed)==null?void 0:s.call(i,n,{containerId:e,blockIndex:r,data:{file:l}}))&&(r+=1)}}class eH{constructor(t){m(this,"handleDrop",(t,e,o,r)=>{if(Array.isArray(e)){const i=e;if(i.length>0){const s=at(o);return X7(t,i,s,r),!0}}return!1});this.editor=t}}class Lu{constructor(t){m(this,"indicator");m(this,"lastDropOverResult");m(this,"handlers",[]);m(this,"handleDragOver",t=>{if(!this.editor.isWritable())return;const e=i=>{var d,h;const s=n2(this.editor,i.dataTransfer),l=K7(this.editor,i.dataTransfer),a=this.findTargetBlock(l,i.x,i.y);if(a&&Xt(this.editor.rootContainer,a)){const p=this.findInsertPos(l,a,i.x,i.y,(h=s!=null?s:(d=i.dataTransfer)==null?void 0:d.items)!=null?h:null);if(p)return this.indicator.show(a,p),"move"}return this.indicator.hide(),"none"},o=(i,s)=>{i.dataTransfer&&(i.dataTransfer.dropEffect=s),s==="move"&&i.preventDefault()};if(this.lastDropOverResult&&t.x===this.lastDropOverResult.x&&t.y===this.lastDropOverResult.y){const i=this.lastDropOverResult.dropEffect;o(t,i);return}const r=e(t);o(t,r),this.lastDropOverResult={x:t.x,y:t.y,dropEffect:r}});m(this,"handleDrop",t=>{var i,s;t.stopPropagation(),setTimeout(()=>{this.indicator.hide()});const e=n2(this.editor,t.dataTransfer),o=Array.from((s=(i=t.dataTransfer)==null?void 0:i.files)!=null?s:[]);if(!e&&o.length===0){t.dataTransfer&&(t.dataTransfer.dropEffect="none");return}const r=this.indicator.target;if(r){const{block:l,insertPos:a}=r,d=K7(this.editor,t.dataTransfer);this.editor.undoManager.runInGroup(()=>{const h=Qt(this.editor,l);if(h.handleDrop&&h.handleDrop(this.editor,l,e!=null?e:o,a,{isSourceBlock:!1,targetBlock:l})){t.preventDefault(),this.editor.focus();return}if(d){const p=Qt(this.editor,d);if(p.handleDrop&&p.handleDrop(this.editor,d,e!=null?e:o,a,{isSourceBlock:!0,targetBlock:l})){t.preventDefault(),this.editor.focus();return}}if(typeof a=="string"){const p=nt(l);let A=bt(l);a==="after"&&(A+=1),t.preventDefault();for(let v=0;v<this.handlers.length;v++)if(this.handlers[v].handleDrop(this.editor,d!=null?d:o,p,A)){this.editor.focus();return}if(d){const v=this.editor.getBlockData(d),B=Fi(this.editor.editorBlocks,this.editor.doc.toJSON(),v),[D]=this.editor.insertDocAt(p,A,B);this.editor.selection.selectBlock(D,0),Su.get(this.editor).highlightBlock(D),this.editor.deleteBlock(d),this.editor.focus()}}}),q$(this.editor)}});m(this,"handleDragLeave",()=>{this.indicator.hide()});this.editor=t,this.indicator=new Z$(this.editor),this.handlers.push(new eH(this.editor)),this.editor.contentElement.addEventListener("dragover",this.handleDragOver),this.editor.contentElement.addEventListener("dragleave",this.handleDragLeave),this.editor.contentElement.addEventListener("drop",this.handleDrop)}destroy(){this.editor.contentElement.removeEventListener("dragover",this.handleDragOver),this.editor.contentElement.removeEventListener("dragleave",this.handleDragLeave),this.editor.contentElement.removeEventListener("drop",this.handleDrop),this.handlers=[]}addHandler(t){this.handlers.push(t)}static register(t){return t.addCustom("drop-target",()=>new Lu(t))}static get(t){return t.getCustom("drop-target")}static find(t){return t.findCustom("drop-target")}canInsertAfter(t,e){return!(this.editor.readonly||Ds(e)===t&&t||!o2(this.editor,e))}canInsertBefore(t,e){return!(this.editor.readonly||Ts(e)===t&&t||!o2(this.editor,e)||Yt(nt(e))&&bt(e)===0)}canDrop(t,e){return t===null||t===e?!0:!Xt(t,e)}findTargetBlock(t,e,o){let r=K$(this.editor,e,o);if(!r||!Xt(this.editor.rootContainer,r))return null;const i=nt(r),s=et(i);return s&&Dt(s)==="code"&&(r=s),this.canDrop(t,r)?r:null}findInsertPos(t,e,o,r,i){let s=e;for(;s;){const a=Qt(this.editor,s);if(a.handleDropOver){const d=a.handleDropOver(this.editor,s,i,o,r);if(d)return d;if(d===!1)return null}s=xs(s)}if(t===e)return"";const l=e.getBoundingClientRect();if(l.top<=r&&r<=l.bottom){if(r<l.top+l.height/2){if(this.canInsertBefore(t,e))return"before";if(this.canInsertAfter(t,e))return"after"}else{if(this.canInsertAfter(t,e))return"after";if(this.canInsertBefore(t,e))return"before"}return""}return r<l.top&&this.canInsertBefore(t,e)?"before":l.bottom<r&&this.canInsertAfter(t,e)?"after":""}}function ty(n,t,e){const o=Ie.getImageObject(n,t),r=mt.default(o.getImages());if(r.length===1){n.deleteBlock(t);return}if(e===-1||e>=r.length)return;const i=jN(r);if(r.splice(e,1),r.length===1){const l=r[0],a=100*(l.flex/i);l.flex=1;const d=cn([l],a);n.updateEmbedData(t,d);return}r[0].flex=NaN,wu(r);const s=cn(r,o.getWidthPercent());n.updateEmbedData(t,s)}function nH(n,t,e,o){if(t.length===0||o==="after"||o==="before")return!1;let r=o.data;const i=Ie.getImageObject(n,e),s=mt.default(i.getImages()),l=[],a=[];t.forEach(p=>{H7(p.type)&&s.length+l.length<6?l.push(p):a.push(p)}),l.forEach(p=>{try{$7(n,p)}catch{return}const A={src:"",flex:1,width:0,height:0,virtualSize:!0};s.splice(r,0,A);const v=cn(s,i.getWidthPercent());n.updateEmbedData(e,v),i.replaceImage(r,p),r+=1});const d=n.getBlockIndex(e)+1,h=at(nt(e));return X7(n,a,h,d),!0}function oH(n,t,e,o,r){var s,l,a;if(Gd(e))return nH(n,e,t,o);if(e.type!=="custom"||e.customType!=="image"||!e.data)return;const i=e.data;if(r.isSourceBlock){const d=r.targetBlock,h=nt(d);let p=bt(d);o==="after"&&(p+=1);const v=100*(i.boundingRect.width/n.rootContainer.getBoundingClientRect().width),B=cn([i.image],v),D={id:K(),type:"embed",embedType:"image",embedData:B},x=(l=(s=n.options.componentsOptions)==null?void 0:s.image)==null?void 0:l.defaultAlign;x&&(D.align=x),n.insertBlock(at(h),p,D),ty(n,t,i.index),(a=n.findCustom("drag-handler"))==null||a.handleDragEnd()}else{if(typeof o=="string")return;const d=t;let h=o.data;const p=Ie.getImageObject(n,d),A=mt.default(p.getImages());h>A.length&&(h=A.length),n.undoManager.runInGroup(()=>{var B,D;p.setAutoFix(!0);const v=n.getBlockById(e.blockId);if(v===d){const x=i.index,_=h,M=i.image;if(x===_||_===x+1)return;let H=_;x<_?(A.splice(_,0,M),A.splice(x,1),H-=1):(A.splice(x,1),A.splice(_,0,M));const z=cn(A,p.getWidthPercent());n.updateEmbedData(d,z),p.setSelectedIndex(H),(B=n.findCustom("drag-handler"))==null||B.handleDragEnd()}else{A.splice(h,0,i.image),A[0].flex=NaN,wu(A);const x=cn(A,p.getWidthPercent());n.updateEmbedData(d,x),ty(n,v,i.index),(D=n.findCustom("drag-handler"))==null||D.handleDragEnd(),p.setSelectedIndex(h),n.selection.selectBlock(d,0)}})}return!0}const rH=2;function $f(n,t,e){const o=Ar(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,rH,r.height)}function iH(n,t,e,o,r){for(let i=0;i<e.length;i++){const l=e[i].getBoundingClientRect();if(o<=l.right)return o<=l.left+l.width/2?{rect:$f(n,t,i),data:i}:{rect:$f(n,t,i+1),data:i+1}}return o>e[e.length-1].getBoundingClientRect().right?{rect:$f(n,t,e.length),data:e.length}:{rect:$f(n,t,e.length),data:0}}function sH(n,t,e,o,r){const i=Ar(t);if(e instanceof DataTransferItemList){if(!Array.from(e).some(s=>H7(s.type))||i.length>=6)return}else{if((e==null?void 0:e.type)==="block"||i.length>=6&&(e==null?void 0:e.blockId)!==it(t))return;const s=it(t);if(i.length===1&&s===(e==null?void 0:e.blockId))return}return iH(n,t,i,o)}async function lH(n){return await Z5.default.toSvg(n)}function r2(n,t){return new DragEvent(t,{bubbles:!0,cancelable:!0,view:window,screenX:n.screenX,screenY:n.screenY,dataTransfer:new DataTransfer,clientX:n.clientX,clientY:n.clientY})}class cH{constructor(t){m(this,"img");m(this,"dragContainer",null);m(this,"autoScroll",null);m(this,"imageContainer",null);m(this,"startPosition",null);m(this,"handleMouseDown",t=>{const e=t.target;if(!e||!(e instanceof HTMLImageElement)||t.button!==0)return;const o=et(e);if(!o||!Wo(o)||!this.editor.isBlockWritable(o)||this.editor.readonly)return;const r=Ie.getImageObject(this.editor,o);if(this.imageContainer=q0(t.target),!this.imageContainer)return;const s=R7(t.target).indexOf(this.imageContainer);if(s===-1)return;const l=r.getImages()[s];if(!l)return;const{x:a,y:d}=t;this.startPosition={x:a,y:d};const h={image:l,index:s,boundingRect:this.imageContainer.getBoundingClientRect()},p=r2(t,"dragstart");W$(this.editor,p,o,"image",h),document.addEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.addEventListener("mousemove",this.handleDrag),t.preventDefault()});m(this,"handleDragStart",async t=>{if(!this.imageContainer)return;const e=et(this.imageContainer);if(!e)return;const{x:o,y:r}=t,{width:i,height:s}=t.target.getBoundingClientRect(),l=te(e),a=w("div",["drag-container"],l);a.style.left=`${o-i/4}px`,a.style.top=`${r-s/4}px`,a.style.width=`${Math.max(i/2,16)}px`,a.style.height=`${s/2}px`,this.dragContainer=a,W(this.editor.contentElement,"dragging");const d=ro(e);this.autoScroll=new Qd({scrollElement:d,trackMouseEvent:"mousemove",edge:{top:50,bottom:50}}),this.autoScroll.active();const h=w("img",["drag-target"],a),A=await lH(this.imageContainer);A&&(h.src=A)});m(this,"handleDrag",t=>{var i;const{x:e,y:o}=t;if(((i=this.startPosition)==null?void 0:i.x)===e&&this.startPosition.y===o)return;if(window.isDragging||(window.isDragging=!0,this.handleDragStart(t)),this.startPosition&&this.dragContainer){const{x:s,y:l}=t;if(s===0&&l===0){this.dragContainer.style.transform="",this.dragContainer.style.opacity="0";return}const{x:a,y:d}=this.startPosition,h=s-a,p=l-d;this.dragContainer.style.transform=`translate(${h}px, ${p}px)`,this.dragContainer.style.opacity="0.5"}const r=r2(t,"dragover");this.editor.contentElement.dispatchEvent(r)});m(this,"handleDragEnd",t=>{var e;if(window.isDragging=!1,this.dragContainer&&this.dragContainer.remove(),this.dragContainer=null,this.startPosition=null,this.imageContainer=null,(e=this.autoScroll)==null||e.inactive(),ot(this.editor.contentElement,"dragging"),document.removeEventListener("mouseup",this.handleDragEnd),this.editor.contentElement.removeEventListener("mousemove",this.handleDrag),t){const o=r2(t,"drop");this.editor.contentElement.dispatchEvent(o)}});this.editor=t,this.editor.rootContainer.addEventListener("mousedown",this.handleMouseDown),this.img=new Image,this.img.src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"}destroy(){this.editor.rootContainer.removeEventListener("mousedown",this.handleMouseDown)}}class aH{constructor(t){m(this,"handleFocusBlockChanged",(t,e,o)=>{const i=this.editor.getFocusedBlock();if(i&&Wo(i)){const s=Ie.getImageObject(this.editor,i);s.getImages().length>0&&s.getSelectedIndex()===-1&&s.setSelectedIndex(0)}o&&Wo(o)&&Ie.getImageObject(this.editor,o).blockResizer.disableResize()});this.editor=t,this.editor.addListener("focusBlockChanged",this.handleFocusBlockChanged)}destroy(){this.editor.removeListener("focusBlockChanged",this.handleFocusBlockChanged)}}class uH{constructor(t){m(this,"currentResizer",null);m(this,"handleHoveringBlockChange",(t,e)=>{window.isDragging||(e&&this.disable(e),t&&(this.currentResizer=t,this.enable(t)))});this.editor=t,Ae.get(t).addListener("change",this.handleHoveringBlockChange)}destroy(){Ae.get(this.editor).removeListener("change",this.handleHoveringBlockChange)}disable(t){Wo(t)&&Ie.getImageObject(this.editor,t).disableResizer()}enable(t){if(Wo(t)){const e=Ie.getImageObject(this.editor,t);this.editor.isBlockWritable(t)&&e.tryEnableResizer()}}}const dH={image:{title:"\u56FE\u7247",upload:{failed:'<div class="line-1">\u56FE\u7247\u4E0A\u4F20\u5931\u8D25</div><div class="line-2">\u7F51\u7EDC\u670D\u52A1\u5F02\u5E38\uFF0C\u4F60\u53EF\u4EE5 <a href="" class="retry-upload">\u91CD\u8BD5</a></div>'},load:{failed:'<div class="line-1">\u56FE\u7247\u52A0\u8F7D\u5931\u8D25</div><div class="line-2">\u7F51\u7EDC\u670D\u52A1\u5F02\u5E38\uFF0C\u4F60\u53EF\u4EE5 <a href="" class="retry-upload">\u91CD\u8BD5</a></div>',remote:{failed:'<div class="line-1">\u56FE\u7247\u52A0\u8F7D\u5931\u8D25</div><div class="line-2">\u8BE5\u56FE\u7247\u6765\u81EA\u5916\u90E8\u94FE\u63A5\uFF0C\u5916\u90E8\u94FE\u63A5\u5DF2\u5931\u6548</div><div class="line-3">\u8BF7\u5C06\u539F\u56FE\u4FDD\u5B58\u5230\u672C\u5730\u540E\u4E0A\u4F20\uFF0C <a href="" class="retry-upload">\u6253\u5F00\u56FE\u7247\u94FE\u63A5</a></div>',tooltip:"\u8BE5\u56FE\u7247\u6765\u81EA\u5916\u90E8\u94FE\u63A5\uFF0C\u5982\u679C\u94FE\u63A5\u5931\u6548\u56FE\u7247\u5C06\u65E0\u6CD5\u67E5\u770B\uFF0C\u5EFA\u8BAE\u4FDD\u5B58\u5230\u672C\u5730\u540E\u6DFB\u52A0\u5230\u9875\u9762\u4E2D"}},abstract:"\u56FE\u7247"}},hH={image:{title:"Image",upload:{failed:'<div class="line-1">Image upload failed</div><div class="line-2">Network error, you can <a href="" class="retry-upload">Retry</a></div>'},load:{failed:'<div class="line-1">Image failed to load</div><div class="line-2">Network error, you can <a href="" class="retry-upload">Retry</a></div>',remote:{failed:'<div class="line-1">Failed to load image</div><div class="line-2">This picture is from an expired external link</div><div class="line-3">Please save the original image to local drives and upload it. <a href="" class="retry-upload">Open image link</a></div>',tooltip:"This picture is from an external link. If the link expires, the picture will not be available. It's recommended to save it to local drives and add it to the page."}},abstract:"Image"}},fH={image:{title:"\u753B\u50CF",upload:{failed:'<div class="line-1">\u753B\u50CF\u3092\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F</div><div class="line-2">\u304A\u4F7F\u3044\u306E\u30CD\u30C3\u30C8\u30EF\u30FC\u30AF\u63A5\u7D9A\u306B\u554F\u984C\u304C\u767A\u751F\u3057\u307E\u3057\u305F\u3002\u6B21\u306E\u64CD\u4F5C\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002 <a href="" class="retry-upload">\u518D\u8A66\u884C</a></div>'},load:{failed:'<div class="line-1">\u753B\u50CF\u3092\u8AAD\u307F\u8FBC\u3081\u307E\u305B\u3093\u3067\u3057\u305F</div><div class="line-2">\u304A\u4F7F\u3044\u306E\u30CD\u30C3\u30C8\u30EF\u30FC\u30AF\u63A5\u7D9A\u306B\u554F\u984C\u304C\u767A\u751F\u3057\u307E\u3057\u305F\u3002\u6B21\u306E\u64CD\u4F5C\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002 <a href="" class="retry-upload">\u518D\u8A66\u884C</a></div>',remote:{failed:'<div class="line-1">\u753B\u50CF\u3092\u8AAD\u307F\u8FBC\u3081\u307E\u305B\u3093\u3067\u3057\u305F</div><div class="line-2">\u3053\u306E\u753B\u50CF\u306B\u30EA\u30F3\u30AF\u3057\u3066\u3044\u308B URL \u304C\u7121\u52B9\u306B\u306A\u3063\u3066\u3044\u307E\u3059\u306E\u3067\u3001\u8868\u793A\u3067\u304D\u307E\u305B\u3093</div><div class="line-3">\u753B\u50CF\u3092\u30ED\u30FC\u30AB\u30EB\u306B\u4FDD\u5B58\u3057\u3066\u30A2\u30C3\u30D7\u30ED\u30FC\u30C0\u3057\u3066\u304F\u3060\u3055\u3044 <a href="" class="retry-upload">\u753B\u50CF\u30EA\u30F3\u30AF\u3092\u958B\u304F</a></div>',tooltip:"\u3053\u306E\u753B\u50CF\u306F\u5916\u90E8\u306B\u30EA\u30F3\u30AF\u3057\u3066\u3044\u308B\u305F\u3081\u3001\u30EA\u30F3\u30AF\u304C\u7121\u52B9\u306B\u306A\u308B\u3068\u3001\u8868\u793A\u3067\u304D\u306A\u304F\u306A\u308A\u307E\u3059\u306E\u3067\u3001\u30ED\u30FC\u30AB\u30EB\u306B\u4FDD\u5B58\u3057\u3001\u30DA\u30FC\u30B8\u306B\u633F\u5165\u3059\u308B\u3053\u3068\u3092\u304A\u52E7\u3081\u3057\u307E\u3059"}},abstract:"\u753B\u50CF"}};R.mergeLang({"zh-CN":dH,"en-US":hH,"ja-JP":fH});function mH(n,t,e,o){const r=n.getBlockByIndex(t,e),i=n.getBlockText(r),{left:s}=In(i,o),l=ie(s);let a=o;if(l.endsWith("![]()"))a-=5;else if(l.endsWith("![]"))a-=3;else return!1;const d=o;return Ul("image/*").then(h=>{n.undoManager.runInGroup(()=>{n.deleteTextFromBlock(r,a,d-a);let p=e+1;ie(n.getBlockText(r)).trim()?(Ql(n,r,a,{forceInsertAfter:!0}),a===0&&(n.deleteBlock(r),p--)):(n.deleteBlock(r),p--),Vm(n,"image",t,p,{file:h})})}),!0}class gH{handleAfterInsertText(t,e,o,r,i){return!!(i===" "&&mH(t,e,o,r))}}function pH(n){const t=n.getFocusedBlock(),e=Ds(t);if(e&&Wo(e)){n.selection.selectBlock(e,0);const o=Ie.getImageObject(n,e);return o.getImages().length>0&&o.setSelectedIndex(0),!0}}function CH(n){const t=n.getFocusedBlock(),e=Ts(t);if(e&&Wo(e)){n.selection.selectBlock(e,0);const o=Ie.getImageObject(n,e);return o.getImages().length>0&&o.setSelectedIndex(0),!0}}function AH(n){const e=n.getFocusedBlock();if(e&&Wo(e)){const o=Ie.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 bH(n){const e=n.getFocusedBlock();if(e&&Wo(e)){const o=Ie.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 i2(n){const e=n.getFocusedBlock();if(e&&Wo(e)){const o=Ie.getImageObject(n,e);if(o.getImages().length>0){const i=o.getSelectedIndex();if(i!==-1)return o.removeImage(i),!0}}}const vH={ArrowLeft:AH,ArrowRight:bH,ArrowUp:CH,ArrowDown:pH,Delete:i2,Backspace:i2},yH=S("copy-image");function kH(n,t,e,o){const r=e.getImages()[o],i=e.getImages().length===1?e.getWidthPercent():r.flex*100,s=cn([r],i),l={id:K(),type:"embed",embedType:"image",embedData:s},a=n.options.componentsOptions.image;a!=null&&a.defaultAlign&&(l.align=a.defaultAlign);const d={blocks:{root:[l]},comments:{},meta:{}},h=document.createElement("canvas");h.width=t.naturalWidth,h.height=t.naturalHeight;const p=h.getContext("2d");if(!p)return;const A={},v={};try{p.drawImage(t,0,0,h.width,h.height);const z=h.toDataURL("image/png").replace(/^data:image\/(png|jpg);base64,/,""),q=Im(z),rt=new File([q],`${Date.now()}.png`,{type:"image/png"});A["image/png"]=rt}catch(H){yH.error(H)}Oh(n,d);const D=`<img src="${n.doc.buildResourceUrl(r.src,{withToken:!0})}" />`,x=Rh(D,d),_=Ra(n,d);A["text/plain"]=new Blob([_],{type:"text/plain"}),v["text/plain"]=_;const M=new Blob([x],{type:"text/html"});return A["text/html"]=M,v["text/html"]=x,[A,v]}function wH(n,t,e,o,r){const i=kH(n,t,e,o);if(!i)return;const[s,l]=i;if(s){const a=Object.entries(s).map(([d,h])=>({type:d,data:h}));return Sm(a).then(d=>{if(!d&&r){const h=r.clipboardData;h&&(h.setData("text/plain",l["text/plain"]),h.setData("text/html",l["text/html"]))}}),!0}}function ey(n,t){const e=n.selection.range;if(e.start.blockId!==e.end.blockId)return;const r=n.getFocusedBlock();if(r&&Wo(r)){const i=Ie.getImageObject(n,r);if(i.getImages().length>0){const l=i.getSelectedIndex();if(l!==-1){const d=Ar(r)[l].querySelector("img");if(d)return wH(n,d,i,l,t)}}}}class BH{constructor(t){this.editor=t,setTimeout(()=>{this.editor.input.addHandler(this)})}handleBeforeCopy(t,e,o){if(ey(t,e))return!0}handleBeforeCut(t,e){if(ey(t,e))return i2(t),!0}destroy(){}}class s2{constructor(t){this.editor=t,setTimeout(()=>{this.editor.input.addHandler(this)})}async handleAfterPasteDoc(t,e,o){return Object.values(e.blocks).forEach(r=>{r.forEach(i=>{if(i.type==="embed"&&i.embedType==="image"){const s=i.embedData;if(Array.isArray(s.src))return;if(s.src.startsWith("https:")||s.src.startsWith("http:")){const l=o.blockIdMap.get(i.id);l&&Ji(t,l).setAutoFix(!0)}}})}),!1}destroy(){}}const EH=S("image-embed");function xH(n,t,e,o,r,i){Ie.create(n,e).createContent(r,i,t),n.addCustom("image-select-handler",()=>new aH(n)),n.addCustom("image-copy-handler",()=>new BH(n)),setTimeout(()=>{n.addCustom("drag-handler",()=>new cH(n));const l=n.addCustom("image-resizer",()=>new uH(n)),a=e.embedData;yc(a)?l.disable(i):l.currentResizer===i&&l.enable(i)})}function IH(n,t,e,o){const r=t.embedData,i=kc(r);return o==="html"?i.map(s=>`<img src="${n.doc.buildResourceUrl(s.src,{withToken:!0})}">`).join(""):o==="markdown"?`${i.map(l=>`})`).join(`
|
|
424
424
|
`)}
|
|
425
425
|
`:i.map(s=>n.doc.buildResourceUrl(s.src,{withToken:!0})).join(`
|
|
426
426
|
`)}class TH{constructor(){m(this,"group","image");m(this,"commands",[])}executeCommand(t,e,o){if(o.id==="replace-image"){const{block:r,image:i}=o.data;Ie.getImageObject(t,r).replaceImage(0,i)}}}function DH(){return{blockCommands:{image:new TH},abstract:`${R.t("image.abstract")}`}}function SH(){return{name:"Image",insertEmbedCommandItems:[{id:"insert-image",name:R.t("image.abstract"),icon:SL,group:"common",subText:"/image",order:100}],handleInsertEmptyEmbed:async(n,t)=>{var v;let e;(v=t.data)!=null&&v.file&&(e=t.data.file);const o=N7(n);if(e=e!=null?e:await Ul(o),!e)return null;try{$7(n,e)}catch{return null}let r={width:w7,height:U0};try{r=await a$(e)}catch(B){EH.error(B)}const i=n.rootContainer.clientWidth,s=r.width<i?Math.min(100,r.width/i*100):100,l={src:"",width:r.width,height:r.height,flex:1,virtualSize:!1},a=cn([l],s),d={id:K(),type:"embed",embedType:"image",embedData:a},h=n.options.componentsOptions.image;h!=null&&h.defaultAlign&&(d.align=h.defaultAlign);const p=n.insertBlock(t.containerId,t.blockIndex,d);return Ie.getImageObject(n,p).replaceImage(0,e),p}}}function LH(n,t,e){var h;const{data:o}=e,r=n.getBlockString(t).trim();if(!o||o.embedType!=="image"||!tt(n,t))return null;const i=r.match(/^!\[[^\]]*\]\((?<filename>.*?)(?="|\))(?<optionalPart>".*")?\)/),s=(h=i==null?void 0:i.groups)==null?void 0:h.filename;if(!s)return null;const l={src:s},a={id:K(),type:"embed",embedType:"image",embedData:l};Ie.create(n,a).setAutoFix(!0);const d=n.options.componentsOptions.image.defaultAlign;return d&&(a.align=d),{blockData:a}}function MH(n,t){const e=it(t);n.destroyCustom(`image-${e}`)}const ny={embedType:"image",createEmbedContent:xH,convertTo:IH,convertFrom:LH,getBlockProperties:DH,getOptions:SH,handleDrop:oH,handleDropOver:sH,handleDeleteBlock:MH};class RH{constructor(t,e){m(this,"toolbar");m(this,"anchor",null);m(this,"item");m(this,"docs",null);m(this,"checkedId");m(this,"handlePasteSpecial",(t,e)=>{!e.data||(this.checkedId===e.id?this.checkedId=void 0:this.checkedId=e.id,this.onPasteSpecial(e.data),setTimeout(()=>{this.docs&&this.show(this.docs),this.editor.focus()}))});m(this,"handleClose",()=>{this.editor.focus()});m(this,"handleSelectionChange",()=>{this.handleClose()});this.editor=t,this.onPasteSpecial=e,this.item={id:"paste-special",name:"",icon:LL,dropdown:!0,manualShowChildren:!0,childrenPlacement:"bottom-start",childrenOffset:[-4,4],children:[]},this.toolbar=new ru([this.item],void 0,{id:"paste-special-button",tooltipId:this.editor.clientId,refuseOverflow:!0}),this.toolbar.addListener("click",this.handlePasteSpecial),this.toolbar.addListener("close",this.handleClose),this.editor.addListener("selectionChanged",this.handleSelectionChange)}show(t){this.docs=t;const e=this.editor,o=e.selection.range;if(!o.isCollapsed())return;const r=e.getBlockById(o.start.blockId);if(!tt(e,r))return;const i=Nr(e,r,o)[0];if(!i)return;this.anchor&&this.anchor.remove(),this.anchor=zr(e,r,"paste-special-button-anchor",i);const s=this.getCommandItems(t);this.item.children=s,this.toolbar.manualShow(this.anchor)}hide(){this.toolbar.close("selectionChange")}clearCheckedState(){this.checkedId=void 0}destroy(){this.toolbar.destroy(),this.editor.removeListener("selectionChanged",this.handleSelectionChange)}getCommandItems(t){const e=i=>({id:i,states:this.checkedId===i?["checked"]:void 0,name:R.t("pasteSpecial.originFormats"),data:t[i]}),o=[];let r=!0;return t["text/x-ones-editor-doc"]?o.push(e("text/x-ones-editor-doc")):t["text/office-html"]?o.push(e("text/office-html")):t["text/html"]?o.push(e("text/html")):t["text/plain"]&&(o.push(e("text/plain")),r=!1),t["text/plain"]&&(r&&o.push({id:"text/plain",states:this.checkedId==="text/plain"?["checked"]:void 0,name:R.t("pasteSpecial.plainText"),data:t["text/plain"]}),o.push({id:"text/markdown",states:this.checkedId==="text/markdown"?["checked"]:void 0,name:R.t("pasteSpecial.markdown"),data:t["text/markdown"]})),o}}const OH=S("paste-special");class l2{constructor(t){m(this,"button");m(this,"lastUndoAction",null);m(this,"event",null);m(this,"handlePasteSpecial",t=>{this.editor.undoManager.runInGroup(()=>{this.editor.undoManager.undoTo(this.lastUndoAction),this.editor.pasteDoc(t)})});this.editor=t,this.button=new RH(t,this.handlePasteSpecial)}destroy(){this.event=null,this.button.destroy()}handleChanged(t,e){this.event=null,this.button.hide()}async handleBeforePaste(t,e){return OH.debug("before paste"),this.lastUndoAction=t.undoManager.lastAction(),!1}async handleAfterPaste(t,e,o){if(Object.keys(o).length<=1)return!1;const r=t.selection.range;if(r.isCollapsed()){const i=t.getBlockById(r.start.blockId);if(!tt(t,i))return!1;this.button.clearCheckedState(),this.button.show(o),this.event=e}return!1}}const _H={pasteSpecial:{originFormats:"\u4FDD\u6301\u539F\u6837\u5F0F",plainText:"\u7C98\u8D34\u7EAF\u6587\u672C",markdown:"\u7C98\u8D34\u4E3A Markdown"}},FH={pasteSpecial:{originFormats:"Keep origin formats",plainText:"Paste as plain text",markdown:"Paste as markdown"}},PH={pasteSpecial:{originFormats:"\u5143\u306E\u30B9\u30BF\u30A4\u30EB\u3092\u7DAD\u6301\u3059\u308B",plainText:"\u30D7\u30EC\u30FC\u30F3\u30C6\u30AD\u30B9\u30C8\u3092\u8CBC\u308A\u4ED8\u3051\u308B",markdown:"Markdown \u3068\u3057\u3066\u8CBC\u308A\u4ED8\u3051"}};R.mergeLang({"zh-CN":_H,"en-US":FH,"ja-JP":PH});const Unt="",NH=S("html-to-doc");function $H(n){const t=new RegExp('(?<=<canvas data-editor-doc=")[\\s\\S]*(?=" id="ones-editor-doc">)',"g"),e=n.match(t);if(!e||!e.length)return null;const o=e[0],r=pa(o);return JSON.parse(r)}function HH(n){const t="ones-editor-doc::",e="::ones-editor-doc";let o=n.indexOf(t);if(o!==-1){o+=t.length;const i=n.indexOf(e,o);if(i!==-1){const s=n.substr(o,i-o);try{const l=pa(s);return JSON.parse(l)}catch(l){NH.error(`invalid doc data: ${l}, ${s}`)}}}const r=$H(n);return r||null}const oy="latex-b172fea480b",jH=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="${oy}" block>${t.formula}</span>`:n.render(t.formula,!0)}}),UH=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="${oy}">${t.formula}</span>`:n.render(t.formula,!1)}});var zH=(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:[jH(n),UH(n)]});function wc(n){const t=n.type;if(t==="link")return!!n.tokens.some(wc);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 VH(n){return!wc(n)}function WH(n){if(n.length===0)return[];if(n.length===1)return[n];const t=[];let e=[n[0]],o=wc(n[0]);for(let r=1;r<n.length;r++){const i=n[r];o===wc(i)?e.push(i):(t.push(e),e=[i],o=wc(i))}return t.push(e),t}function qH(n,t,e){const o=n.href;let r=e.tokensToText(n.tokens,t,e);return r.length===0&&(r=Oi(o,t)),r=hh(r,"link",o),r}let Mu;function c2(n){Mu||(Mu=document.createElement("textarea")),Mu.innerHTML=n;const t=Mu.childNodes.length===0?"":Mu.childNodes[0].nodeValue;return t!=null?t:""}function GH(n,t){const e=c2(n.text);return[co(e,{...t,"style-code":!0})]}function ZH(n,t,e){const r=n.tokens;return r?e.tokensToText(r,t,e):sg(c2(n.text),t)}const QH=S("token-to-text");function a2(n,t,e){return n.map(r=>r.type==="text"?ZH(r,t,e):r.type==="strong"?e.tokensToText(r.tokens,{...t,"style-bold":!0},e):r.type==="em"?e.tokensToText(r.tokens,{...t,"style-italic":!0},e):r.type==="del"?e.tokensToText(r.tokens,{...t,"style-strikethrough":!0},e):r.type==="link"?qH(r,t,e):r.type==="codespan"?GH(r,t):r.type==="br"?[{insert:" ",attributes:{id:K(),created:Date.now(),box:!0,type:"br"}}]:r.type==="escape"?sg(c2(r.text),t):r.type==="latex"?[{insert:" ",attributes:{id:K(),created:Date.now(),box:!0,type:"math",tex:r.formula}}]:(QH.warn(`unknown token in text: ${JSON.stringify(r)}`),[])).flat()}function YH(n,t){const e=a2(n.tokens,{},t);return[{id:K(),type:"text",text:e,heading:n.depth}]}function JH(n,t){const{text:e,children:o}=t.tokensToTextWithChildren(n.tokens,t),r=[];return e.length>0&&r.push({id:K(),type:"text",text:e}),r.push(...o),r}function KH(n,t){const{text:e,children:o}=t.tokensToTextWithChildren([n],t),r=[];return e.length>0&&r.push({id:K(),type:"text",text:e}),r.push(...o),r}function XH(n,t){const e=typeof n.start=="number"?n.start:1,o=n.ordered,r=K(),i=[];return n.items.forEach((l,a)=>{const d={...t,listLevel:t.listLevel+1},{text:h,children:p}=t.tokensToTextWithChildren(l.tokens,d);let A;typeof l.checked=="boolean"&&(A=l.checked?"checked":"unchecked");const v={id:K(),type:"list",groupId:r,ordered:o,checkbox:A,start:e+a,text:h,level:t.listLevel};i.push(v),i.push(...p)}),i}function tj(n,t){const e=t.tokensToBlocks(n.tokens,t);return e.forEach(o=>{o.quoted=!0}),e}const ry=100,ej=20,nj=600;function oj(n,t){const e=t.text;if(e){const o=ie(e);return Math.min(qd(o,n)+ej,nj)}return ry}function iy(n,t){let e=ry;return t.forEach(o=>{e=Math.max(e,oj(n,o))}),e}function rj(n,t){var l,a;const e=n.header.length,o=n.rows.length+1,r=[],i=Array(e).fill(100);for(let d=0;d<o;d++){let h;d===0?h=n.header:h=n.rows[d-1];for(let p=0;p<e;p++){const A=h[p],v=(l=A==null?void 0:A.tokens)!=null?l:[],B=K();r.push(B);let D;if(v.length===0)D=[mh()];else if(wc(v[0]))D=t.tokensToBlocks(A.tokens,t),D.length===0&&D.push(mh());else{const{text:x,children:_}=t.tokensToTextWithChildren(A.tokens,t);D=[{id:K(),type:"text",text:x},..._]}t.doc.blocks[B]=D,i[p]=Math.max(i[p],iy((a=t.font)!=null?a:"",D))}}return[{id:K(),type:"table",cols:e,rows:o,colsWidth:i,children:r}]}function ij(n){return[{id:K(),type:"embed",embedType:"hr",embedData:{}}]}function sj(n,t){var a;const e=n.text;if(!e)return[];try{const d=n.text,h=pa(d),p=JSON.parse(h);if(p){const{root:A,...v}=p.blocks;return t.doc.blocks={...t.doc.blocks,...v},A}}catch{}const o=(a=n.lang)!=null?a:"Plain Text";if(o==="mermaid")return[{id:K(),type:"embed",embedType:"mermaid",embedData:{mermaidText:e}}];if(o==="plantuml")return[{id:K(),type:"embed",embedType:"plantuml",embedData:{plantumlText:e}}];if(o==="flow"||o==="flowchart")return[{id:K(),type:"embed",embedType:"flowchart",embedData:{flowchartText:e}}];const i=e.split(`
|
|
@@ -469,10 +469,10 @@ ${s}
|
|
|
469
469
|
|
|
470
470
|
> ${o}
|
|
471
471
|
|
|
472
|
-
`}})}class yj{constructor(t){m(this,"_grid",[]);m(this,"_needFixSpanData",!1);Array.from(t.rows).forEach((e,o)=>{Array.from(e.cells).forEach(r=>{this._addCell(o,r)})})}_addCell(t,e){const o=this._getNextColIndex(t),r=e.colSpan,i=e.rowSpan;for(let s=0;s<i;s++)for(let l=0;l<r;l++){const a=t+s,d=o+l;if(this._getCell({row:a,col:d})){this._needFixSpanData=!0,console.warn(`invalid table data, cell data already exists, ${a}, ${d}`);continue}this._setCell({row:a,col:d},{cell:e,virtual:!(l===0&&s===0)})}}_getNextColIndex(t){const e=this._grid[t];if(!e)return 0;let o=0;for(let r=0;r<e.length;r++)if(e[r])o+=1;else return o;return o}_setCell(t,e){if(!(e.cell.colSpan===0||e.cell.rowSpan===0)){for(;this._grid.length<=t.row;)this._grid.push([]);for(let o=0;o<this._grid.length;o++){const r=this._grid[o];for(;r.length<=t.col;)r.push(null)}this._grid[t.row][t.col]=e}}_getCell(t){var o;const e=this._grid[t.row];return e&&(o=e[t.col])!=null?o:null}get rowCount(){return this._grid.length}get colCount(){return this._grid[0].length}getCellData(t){const e=this._getCell(t);return e||null}getCellSpan(t){const e=this._getCell(t);if(!e)return{colSpan:1,rowSpan:1};if(e.virtual)return{colSpan:1,rowSpan:1};const o=()=>{let l=t.col+1;for(;;){const a=this._getCell({row:t.row,col:l});if(!a||a.cell!==e.cell)return l-t.col;l+=1}},r=()=>{let l=t.row+1;for(;;){const a=this._getCell({row:l,col:t.col});if(!a||a.cell!==e.cell)return l-t.row;l+=1}},i=o(),s=r();return i!==e.cell.colSpan&&console.warn(`invalid colSpan: ${i} -> ${e.cell.colSpan}`),s!==e.cell.rowSpan&&console.warn(`invalid rowSpan: ${s} -> ${e.cell.rowSpan}`),{colSpan:i,rowSpan:s}}getColumnWidth(t){const r=Array(this.rowCount).fill(0).map((s,l)=>{const a=this.getCellData({row:l,col:t});if(a&&!a.virtual){const d=a.cell.getAttribute("width")||a.cell.style.width;if(d){if(d.endsWith("%")){const p=d.substr(0,d.length-1),A=Number.parseInt(p,10);if(A>0&&A<=100)return Math.floor(720*A/100)}const h=Number.parseInt(d,10);if(h)return h}return a.cell.getBoundingClientRect().width}return 1e9}),i=Math.min(...r);return i===1e9||Number.isNaN(i)||i<30?0:i}}function kj(n){return new yj(n)}function ay(n,t){var a;const e=kj(n),o=[],r={},i=e.rowCount,s=e.colCount,l=Array(s).fill(100);for(let d=0;d<i;d++)for(let h=0;h<s;h++){let p;const A=e.getCellData({row:d,col:h});if(A&&A.virtual)continue;A&&!A.virtual&&(p=t.htmlToBlocks(A.cell.innerHTML,t)),(!p||p.length===0)&&(p=[{id:K(),type:"text",text:[]}]);const v=K();o.push(v);const{colSpan:B,rowSpan:D}=e.getCellSpan({row:d,col:h});D>1&&(r[`${v}_rowSpan`]=D),B>1&&(r[`${v}_colSpan`]=B),t.doc.blocks[v]=p,A&&!A.virtual&&(l[h]=Math.max(l[h],iy((a=t.font)!=null?a:"",p)))}for(let d=0;d<e.colCount;d++)l[d]=e.getColumnWidth(d)||l[d];return o.length===0?[]:[{cols:e.colCount,rows:e.rowCount,id:K(),type:"table",children:o,...r,colsWidth:l}]}function uy(n,t){var e;if(n.tagName==="TABLE"){const o={blocks:{root:[]},meta:{},comments:{}},r=ay(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=Si(i),l=document.createElement("div");l.classList.add("highlight-text-wizdoc");const a=document.createElement("pre");l.appendChild(a),a.innerText=s,n.insertAdjacentElement("beforebegin",l),n.remove();return}Array.from(n.children).forEach(o=>uy(o,t))}function dy(n){if(n instanceof HTMLStyleElement){n.remove();return}Array.from(n.children).forEach(dy)}function hy(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(hy)}function wj(n,t){const e=Wd(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(hy),Array.from(e.children).forEach(r=>uy(r,t)),Array.from(e.children).forEach(dy),cy(e),EC(e)}const Xr=new YB.default;Xr.use(mj),Xr.use(gj),Xr.use(pj),Xr.use(Cj),Xr.use(Aj),Xr.use(bj),Xr.use(vj),Xr.use(FB.gfm);function Bj(n,t){const e=fy(n,t);if(!e)return[];const{root:o,...r}=e.blocks;return t.doc.blocks={...t.doc.blocks,...r},o}function fy(n,t){const e=Xr.turndown(n);return ly(e,{htmlToDoc:o=>my(o,t)})}function my(n,t){const e=wj(n,{font:t==null?void 0:t.font,htmlToBlocks:Bj});return fy(e)}function gy(n){return n.indexOf('xmlns:o="urn:schemas-microsoft-com:office:office"')!==-1}function jf(n){return["A","B","DEL","I","U","S","SPAN","SUB","SUP","FONT","BR"].indexOf(n.tagName)!==-1}function Ej(n){return["P","H1","H2","H3","H4","H5","H6","H7","H8","LI"].indexOf(n.tagName)!==-1}function py(n){return n.replace(/\r\n\s*/g,"").replace(/\n\s*/g,"").replace(/\r\s*/g,"")}function xj(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 Ij(n){return(n.tagName.toLocaleLowerCase()==="img"?[n]:Array.from(n.querySelectorAll("img"))).map(r=>({id:K(),type:"embed",embedType:"image",embedData:{src:r.src,width:r.width,height:r.height}}))}function Cy(n){var e;return Array.from(((e=n.getAttribute("style"))!=null?e:"").split(" ")).findIndex(o=>o.startsWith("level"))!==-1}function Tj(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 Ay(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 Dj(n,t){n.setAttribute("data-group-id",t)}function Sj(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(Cy(r)){const i=Tj(r);o!==i&&(e(0),o=i);const s=Ay(r);e(s);let l=t[`${s}`];l||(l=K(),t[`${s}`]=l),Dj(r,l)}})}function by(n){if(!Cy(n))return{};const t=Ay(n),e=n.getAttribute("data-group-id")||K();return{start:1,level:t,groupId:e,ordered:!0,type:"list"}}const Lj=S("office-list");function vy(n){return n instanceof HTMLOListElement||n instanceof HTMLUListElement}function Mj(n,t){g(Lj,vy(n),"not list group element");let e=!1,o=1;const r=K();n instanceof HTMLOListElement&&(e=!0,o=n.start);const i=n,s=[];let l;return Array.from(i.children).forEach(a=>{if(a instanceof HTMLLIElement){const h=by(a),p=t.textElementToBlocks(a,t);l||(l=h.level);const A=p[0];s.push({...A,type:"list",ordered:e,level:l,groupId:r,start:o}),o+=1,s.push(...p.slice(1));return}const d=t.blockElementToBlocks(a,t);s.push(...d)}),s}function yy(n,t){if(n.nodeName==="META")return[];if(n instanceof HTMLTableElement)return ay(n,t);if(vy(n))return[...Mj(n,t)];if(xj(n))return[...Ij(n)];if(Ej(n))return[...t.textElementToBlocks(n,t)];if(!n.children)return[];const e=[];return Array.from(n.children).forEach(o=>{const r=yy(o,t);e.push(...r)}),e}function ky(n,t){const e=[];return n.forEach(o=>{var r;if(o instanceof Element)if(jf(o)){const i=document.createElement("p");i.appendChild(o);const s=t.blockElementToBlocks(i,t);e.push(...s)}else{const i=t.blockElementToBlocks(o,t);e.push(...i)}else if(o instanceof Text){const i=lr(py((r=o.textContent)!=null?r:""));e.push(i)}}),e}function wy(n){const t=Array.from(n.children);for(let e=0;e<t.length;e++){const o=t[e];if(!jf(o))continue;let r=e+1;for(;r<t.length&&jf(t[r]);)r+=1;const i=document.createElement("p");o.insertAdjacentElement("beforebegin",i);for(let s=e;s<r;s++)i.appendChild(t[s]);e=r-1}}function Rj(n,t){const e=Wd(n);return wy(e),ky(Array.from(e.childNodes),t)}function Oj(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 _j(n,t){return t&&Object.keys(t).length>0?{insert:n,attributes:t}:{insert:n}}function Fj(n,t){if(n.nodeName==="B")return{...t,"style-bold":!0};if(n.nodeName==="I")return{...t,"style-italic":!0};if(n.nodeName==="U")return{...t,"style-underline":!0};if(n.nodeName==="S"||n.nodeName==="DEL")return{...t,"style-strikethrough":!0};if(n.nodeName==="SUB")return{...t,"style-sub":!0};if(n.nodeName==="SUP")return{...t,"style-super":!0};if(n.nodeName==="BR")return{...t,created:Date.now(),id:K(),box:!0,type:"br"};if(n.nodeName==="A"&&n.href){const o=n.href;if(o.startsWith("http:")||o.startsWith("https:"))return{...t,link:n.href}}const e={...t};return n instanceof HTMLSpanElement?(n.style.backgroundColor&&(e["inline-style-background-color"]=n.style.backgroundColor),n.style.color&&(e["inline-style-color"]=n.style.color),n.style.fontSize&&(e["inline-style-font-size"]=n.style.fontSize),n.style.fontFamily&&(e["inline-style-font-family"]=n.style.fontFamily),e):t}function By(n,t,e){var r;if(n instanceof HTMLSpanElement&&n.getAttribute("style")==="mso-list:Ignore")return;const o=Fj(n,t);if(n instanceof Text&&n.nodeValue||n.nodeName==="BR"){const i=py((r=n.nodeValue)!=null?r:" ");i&&e.push(_j(i,o));return}n.childNodes.length>0&&Array.from(n.childNodes).forEach(i=>{By(i,o,e)})}function Ey(n){return n instanceof Element?jf(n):!0}function d2(n){return!Ey(n)}function Pj(n){if(n.length===0)return[];if(n.length===1)return[n];const t=[];let e=[n[0]],o=d2(n[0]);for(let r=1;r<n.length;r++){const i=n[r];o===d2(i)?e.push(i):(t.push(e),e=[i],o=d2(i))}return t.push(e),t}function Nj(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=Pj(Array.from(n.childNodes)),r=[];return o.forEach((i,s)=>{if(Ey(i[0])){const l=[],a={};Array.from(n.childNodes).forEach(h=>{By(h,a,l)});let d={};s===0&&(d=by(n)),r.push({id:K(),type:"text",text:l,...d,...e,...Oj(n)})}i.forEach(l=>{const a=t.blockElementToBlocks(l,t);r.push(...a)})}),r}function $j(n,t){const e=Wd(n);Sj(e),wy(e);const o={blocks:{root:[]},meta:{},comments:{}},r={font:t==null?void 0:t.font,doc:o,blockElementToBlocks:yy,textElementToBlocks:Nj,htmlToBlocks:Rj},i=ky(Array.from(e.children),r);if(i.length!==0)return o.blocks.root=i,o}const Hj=S("html-to-doc");function xy(n,t){if(!n)return null;const e=HH(n);if(e)return e;if(gy(n)){const o=$j(n,t);if(o)return o}try{return my(n,t)}catch(o){Hj.error(o)}return null}class jj{async fromData(t,e){const o={},r=e.getData("text/html");if(r){const i=xy(r,{font:t.rootContainer});i&&(gy(r)?o["text/office-html"]=i:o["text/html"]=i)}return o}}class Uj{async fromData(t,e){const o=e.getData("text/plain");if(!o)return;const r=ly(o,{font:t.rootContainer,htmlToDoc:xy});if(!!r)return{"text/markdown":r}}}function zj(n){return/^([\d\w\u4e00-\u9fa5\s]*[\u4e00-\u9fa5\s]{1}|)((https|http|ftp)?:\/\/)[^\s]+/.test(n)}function Vj(n){const t=[],e=n.split(/https|http|ftp/)[0],o=n.substring(e.length).trim();if(e&&e.length){const i=co(e,null);t.push(i,co(" ",null))}const r=co(o,{link:o});return t.push(r,co(" ",null)),t}class Wj{async fromData(t,e,o){const{toPlainText:r=!1}=o||{},i={},s=e.getData("text/plain");if(s){const d={blocks:{root:s.replace(/\r\n/g,`
|
|
472
|
+
`}})}class yj{constructor(t){m(this,"_grid",[]);m(this,"_needFixSpanData",!1);Array.from(t.rows).forEach((e,o)=>{Array.from(e.cells).forEach(r=>{this._addCell(o,r)})})}_addCell(t,e){const o=this._getNextColIndex(t),r=e.colSpan,i=e.rowSpan;for(let s=0;s<i;s++)for(let l=0;l<r;l++){const a=t+s,d=o+l;if(this._getCell({row:a,col:d})){this._needFixSpanData=!0,console.warn(`invalid table data, cell data already exists, ${a}, ${d}`);continue}this._setCell({row:a,col:d},{cell:e,virtual:!(l===0&&s===0)})}}_getNextColIndex(t){const e=this._grid[t];if(!e)return 0;let o=0;for(let r=0;r<e.length;r++)if(e[r])o+=1;else return o;return o}_setCell(t,e){if(!(e.cell.colSpan===0||e.cell.rowSpan===0)){for(;this._grid.length<=t.row;)this._grid.push([]);for(let o=0;o<this._grid.length;o++){const r=this._grid[o];for(;r.length<=t.col;)r.push(null)}this._grid[t.row][t.col]=e}}_getCell(t){var o;const e=this._grid[t.row];return e&&(o=e[t.col])!=null?o:null}get rowCount(){return this._grid.length}get colCount(){return this._grid[0].length}getCellData(t){const e=this._getCell(t);return e||null}getCellSpan(t){const e=this._getCell(t);if(!e)return{colSpan:1,rowSpan:1};if(e.virtual)return{colSpan:1,rowSpan:1};const o=()=>{let l=t.col+1;for(;;){const a=this._getCell({row:t.row,col:l});if(!a||a.cell!==e.cell)return l-t.col;l+=1}},r=()=>{let l=t.row+1;for(;;){const a=this._getCell({row:l,col:t.col});if(!a||a.cell!==e.cell)return l-t.row;l+=1}},i=o(),s=r();return i!==e.cell.colSpan&&console.warn(`invalid colSpan: ${i} -> ${e.cell.colSpan}`),s!==e.cell.rowSpan&&console.warn(`invalid rowSpan: ${s} -> ${e.cell.rowSpan}`),{colSpan:i,rowSpan:s}}getColumnWidth(t){const r=Array(this.rowCount).fill(0).map((s,l)=>{const a=this.getCellData({row:l,col:t});if(a&&!a.virtual){const d=a.cell.getAttribute("width")||a.cell.style.width;if(d){if(d.endsWith("%")){const p=d.substr(0,d.length-1),A=Number.parseInt(p,10);if(A>0&&A<=100)return Math.floor(720*A/100)}const h=Number.parseInt(d,10);if(h)return h}return a.cell.getBoundingClientRect().width}return 1e9}),i=Math.min(...r);return i===1e9||Number.isNaN(i)||i<30?0:i}}function kj(n){return new yj(n)}function ay(n,t){var a;const e=kj(n),o=[],r={},i=e.rowCount,s=e.colCount,l=Array(s).fill(100);for(let d=0;d<i;d++)for(let h=0;h<s;h++){let p;const A=e.getCellData({row:d,col:h});if(A&&A.virtual)continue;A&&!A.virtual&&(p=t.htmlToBlocks(A.cell.innerHTML,t)),(!p||p.length===0)&&(p=[{id:K(),type:"text",text:[]}]);const v=K();o.push(v);const{colSpan:B,rowSpan:D}=e.getCellSpan({row:d,col:h});D>1&&(r[`${v}_rowSpan`]=D),B>1&&(r[`${v}_colSpan`]=B),t.doc.blocks[v]=p,A&&!A.virtual&&(l[h]=Math.max(l[h],iy((a=t.font)!=null?a:"",p)))}for(let d=0;d<e.colCount;d++)l[d]=e.getColumnWidth(d)||l[d];return o.length===0?[]:[{cols:e.colCount,rows:e.rowCount,id:K(),type:"table",children:o,...r,colsWidth:l}]}function uy(n,t){var e;if(n.tagName==="TABLE"){const o={blocks:{root:[]},meta:{},comments:{}},r=ay(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=Si(i),l=document.createElement("div");l.classList.add("highlight-text-wizdoc");const a=document.createElement("pre");l.appendChild(a),a.innerText=s,n.insertAdjacentElement("beforebegin",l),n.remove();return}Array.from(n.children).forEach(o=>uy(o,t))}function dy(n){if(n instanceof HTMLStyleElement){n.remove();return}Array.from(n.children).forEach(dy)}function hy(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(hy)}function wj(n,t){const e=Wd(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(hy),Array.from(e.children).forEach(r=>uy(r,t)),Array.from(e.children).forEach(dy),cy(e),EC(e)}const Xr=new YB.default;Xr.use(mj),Xr.use(gj),Xr.use(pj),Xr.use(Cj),Xr.use(Aj),Xr.use(bj),Xr.use(vj),Xr.use(FB.gfm);function Bj(n,t){const e=fy(n,t);if(!e)return[];const{root:o,...r}=e.blocks;return t.doc.blocks={...t.doc.blocks,...r},o}function fy(n,t){const e=Xr.turndown(n);return ly(e,{htmlToDoc:o=>my(o,t)})}function my(n,t){const e=wj(n,{font:t==null?void 0:t.font,htmlToBlocks:Bj});return fy(e)}function gy(n){return n.indexOf('xmlns:o="urn:schemas-microsoft-com:office:office"')!==-1}function jf(n){return["A","B","DEL","I","U","S","SPAN","SUB","SUP","FONT","BR"].indexOf(n.tagName)!==-1}function Ej(n){return["P","H1","H2","H3","H4","H5","H6","H7","H8","LI"].indexOf(n.tagName)!==-1}function py(n){return n.replace(/\r\n\s*/g,"").replace(/\n\s*/g,"").replace(/\r\s*/g,"")}function xj(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 Ij(n){return(n.tagName.toLocaleLowerCase()==="img"?[n]:Array.from(n.querySelectorAll("img"))).map(r=>({id:K(),type:"embed",embedType:"image",embedData:{src:r.src,width:r.width,height:r.height}}))}function Cy(n){var e;return Array.from(((e=n.getAttribute("style"))!=null?e:"").split(" ")).findIndex(o=>o.startsWith("level"))!==-1}function Tj(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 Ay(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 Dj(n,t){n.setAttribute("data-group-id",t)}function Sj(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(Cy(r)){const i=Tj(r);o!==i&&(e(0),o=i);const s=Ay(r);e(s);let l=t[`${s}`];l||(l=K(),t[`${s}`]=l),Dj(r,l)}})}function by(n){if(!Cy(n))return{};const t=Ay(n),e=n.getAttribute("data-group-id")||K();return{start:1,level:t,groupId:e,ordered:!0,type:"list"}}const Lj=S("office-list");function vy(n){return n instanceof HTMLOListElement||n instanceof HTMLUListElement}function Mj(n,t){g(Lj,vy(n),"not list group element");let e=!1,o=1;const r=K();n instanceof HTMLOListElement&&(e=!0,o=n.start);const i=n,s=[];let l;return Array.from(i.children).forEach(a=>{if(a instanceof HTMLLIElement){const h=by(a),p=t.textElementToBlocks(a,t);l||(l=h.level);const A=p[0];s.push({...A,type:"list",ordered:e,level:l,groupId:r,start:o}),o+=1,s.push(...p.slice(1));return}const d=t.blockElementToBlocks(a,t);s.push(...d)}),s}function yy(n,t){if(n.nodeName==="META")return[];if(n instanceof HTMLTableElement)return ay(n,t);if(vy(n))return[...Mj(n,t)];if(xj(n))return[...Ij(n)];if(Ej(n))return[...t.textElementToBlocks(n,t)];if(!n.children)return[];const e=[];return Array.from(n.children).forEach(o=>{const r=yy(o,t);e.push(...r)}),e}function ky(n,t){const e=[];return n.forEach(o=>{var r;if(o instanceof Element)if(jf(o)){const i=document.createElement("p");i.appendChild(o);const s=t.blockElementToBlocks(i,t);e.push(...s)}else{const i=t.blockElementToBlocks(o,t);e.push(...i)}else if(o instanceof Text){const i=cr(py((r=o.textContent)!=null?r:""));e.push(i)}}),e}function wy(n){const t=Array.from(n.children);for(let e=0;e<t.length;e++){const o=t[e];if(!jf(o))continue;let r=e+1;for(;r<t.length&&jf(t[r]);)r+=1;const i=document.createElement("p");o.insertAdjacentElement("beforebegin",i);for(let s=e;s<r;s++)i.appendChild(t[s]);e=r-1}}function Rj(n,t){const e=Wd(n);return wy(e),ky(Array.from(e.childNodes),t)}function Oj(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 _j(n,t){return t&&Object.keys(t).length>0?{insert:n,attributes:t}:{insert:n}}function Fj(n,t){if(n.nodeName==="B")return{...t,"style-bold":!0};if(n.nodeName==="I")return{...t,"style-italic":!0};if(n.nodeName==="U")return{...t,"style-underline":!0};if(n.nodeName==="S"||n.nodeName==="DEL")return{...t,"style-strikethrough":!0};if(n.nodeName==="SUB")return{...t,"style-sub":!0};if(n.nodeName==="SUP")return{...t,"style-super":!0};if(n.nodeName==="BR")return{...t,created:Date.now(),id:K(),box:!0,type:"br"};if(n.nodeName==="A"&&n.href){const o=n.href;if(o.startsWith("http:")||o.startsWith("https:"))return{...t,link:n.href}}const e={...t};return n instanceof HTMLSpanElement?(n.style.backgroundColor&&(e["inline-style-background-color"]=n.style.backgroundColor),n.style.color&&(e["inline-style-color"]=n.style.color),n.style.fontSize&&(e["inline-style-font-size"]=n.style.fontSize),n.style.fontFamily&&(e["inline-style-font-family"]=n.style.fontFamily),e):t}function By(n,t,e){var r;if(n instanceof HTMLSpanElement&&n.getAttribute("style")==="mso-list:Ignore")return;const o=Fj(n,t);if(n instanceof Text&&n.nodeValue||n.nodeName==="BR"){const i=py((r=n.nodeValue)!=null?r:" ");i&&e.push(_j(i,o));return}n.childNodes.length>0&&Array.from(n.childNodes).forEach(i=>{By(i,o,e)})}function Ey(n){return n instanceof Element?jf(n):!0}function d2(n){return!Ey(n)}function Pj(n){if(n.length===0)return[];if(n.length===1)return[n];const t=[];let e=[n[0]],o=d2(n[0]);for(let r=1;r<n.length;r++){const i=n[r];o===d2(i)?e.push(i):(t.push(e),e=[i],o=d2(i))}return t.push(e),t}function Nj(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=Pj(Array.from(n.childNodes)),r=[];return o.forEach((i,s)=>{if(Ey(i[0])){const l=[],a={};Array.from(n.childNodes).forEach(h=>{By(h,a,l)});let d={};s===0&&(d=by(n)),r.push({id:K(),type:"text",text:l,...d,...e,...Oj(n)})}i.forEach(l=>{const a=t.blockElementToBlocks(l,t);r.push(...a)})}),r}function $j(n,t){const e=Wd(n);Sj(e),wy(e);const o={blocks:{root:[]},meta:{},comments:{}},r={font:t==null?void 0:t.font,doc:o,blockElementToBlocks:yy,textElementToBlocks:Nj,htmlToBlocks:Rj},i=ky(Array.from(e.children),r);if(i.length!==0)return o.blocks.root=i,o}const Hj=S("html-to-doc");function xy(n,t){if(!n)return null;const e=HH(n);if(e)return e;if(gy(n)){const o=$j(n,t);if(o)return o}try{return my(n,t)}catch(o){Hj.error(o)}return null}class jj{async fromData(t,e){const o={},r=e.getData("text/html");if(r){const i=xy(r,{font:t.rootContainer});i&&(gy(r)?o["text/office-html"]=i:o["text/html"]=i)}return o}}class Uj{async fromData(t,e){const o=e.getData("text/plain");if(!o)return;const r=ly(o,{font:t.rootContainer,htmlToDoc:xy});if(!!r)return{"text/markdown":r}}}function zj(n){return/^([\d\w\u4e00-\u9fa5\s]*[\u4e00-\u9fa5\s]{1}|)((https|http|ftp)?:\/\/)[^\s]+/.test(n)}function Vj(n){const t=[],e=n.split(/https|http|ftp/)[0],o=n.substring(e.length).trim();if(e&&e.length){const i=co(e,null);t.push(i,co(" ",null))}const r=co(o,{link:o});return t.push(r,co(" ",null)),t}class Wj{async fromData(t,e,o){const{toPlainText:r=!1}=o||{},i={},s=e.getData("text/plain");if(s){const d={blocks:{root:s.replace(/\r\n/g,`
|
|
473
473
|
`).replace(/\r/g,`
|
|
474
474
|
`).split(`
|
|
475
|
-
`).map(h=>{const p={id:K(),type:"text"};if(zj(h)&&!r)return p.text=Vj(h),p;const A=h?[co(h,null)]:[];return p.text=A,p})},meta:{},comments:{}};i["text/plain"]=d}return i}}function qj(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 h2{constructor(t){t.dataConverter.addConverter(new jj),t.dataConverter.addConverter(new Wj),t.dataConverter.addConverter(new Uj)}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=qj(r.files);if(s.length>0&&!o["text/office-html"])return await this.handleInsertImages(t,s),!0}return!1}async handleInsertImages(t,e){const{start:o,end:r}=t.selection.range,i=t.selection.focusedBlock;let s=nt(i),a=bt(i);const d=et(s);if(d&&Dt(d)==="code")return;if(o.blockId===r.blockId&&Me(i))a+=1;else{t.clearSelectedContents();const{blockId:p}=t.selection.range.start,A=t.getBlockById(p);a=bt(A),s=nt(A),he(t,A)||(a+=1),Yt(s)&&a===0&&(a+=1)}const h=at(s);for(let p=0;p<e.length;p++){const A=e[p],v=await Vm(t,"image",h,a+p,{file:A});v&&a4(t,v,"image",{id:"replace-image",name:"Replace image",data:{block:v,image:A}})}}}class Gj extends ye.TypedEmitter{constructor(t){super(),this.editor=t}onUpdateBlockText(t,e,o){const r=this.editor.getCustom("find-dialog");if(!r||!r.isVisible())return;const i=Fr(jr(this.editor,t),e);!tt(this.editor,i)||!o.some(l=>l.insert||l.delete)||this.emit("onDocChanged",i)}onInsertBlock(t,e,o,r){Fr(jr(this.editor,t),e),this.emit("onDocInserted")}onDeleteBlock(t,e,o){const r=Fr(jr(this.editor,t),e);this.emit("onDocDeleted",r)}}function Iy(n){return Ze.isSafari&&!!n&&Date.now()-n<100}const Ty=S("highlight-data");class Uf{constructor(t){m(this,"data",new Map);this.editor=t}add(t,e,o){const r={id:K(),blockId:it(t),oldText:this.editor.getBlockText(t),start:e,end:o};return this.data.set(r.id,r),r}get(t){const e=this.data.get(t);return g(Ty,e,`no highligh data: ${t}`),e}remove(t){this.data.delete(t)}clearBlockData(t){Array.from(this.data.values()).forEach(e=>{e.blockId===t&&this.data.delete(e.id)})}destroy(){}static getData(t){return t.addCustom("highligh-data",()=>new Uf(t))}}function Zj(n,t,e,o,r){const s=Uf.getData(n).add(t,e,o);return r.setAttribute("data-highlight-id",s.id),s}function zf(n,t){const e=t.getAttribute("data-highlight-id");return g(Ty,e,"invalid highlight elem, no id"),Uf.getData(n).get(e)}const Bc=S("highligh-dom");function Qj(n){return xt(n,"editor-highlight")}function Ar(n){const t=n.rootContainer.querySelectorAll(".editor-highlight");return Array.from(t)}function Yj(n,t){g(Bc,t,"invalid block");const e=t.querySelectorAll(".editor-highlight");return Array.from(e)}function Jj(n){const t=n.rootContainer.querySelectorAll(".editor-replace-result-highlight");return Array.from(t)}function Vf(n){const t=n.querySelectorAll(".editor-highlight");return Array.from(t)}function Kj(n){Vf(n).forEach(t=>{t.remove()})}function ti(n){return Ar(n).length}function Xj(n,t){g(Bc,t>=0,`invalid highlight index: ${t}`);const e=Ar(n);return e.length===0?null:(g(Bc,t<e.length,`invalid highlight index: ${t}/${e.length}`),e[t])}function tU(n,t,{left:e,top:o,width:r,height:i},s){const l=["editor-highlight-child"];s&&l.push("editor-highlight-readonly");const a=w("div",l,n);a.style.top=`${o}px`,a.style.left=`${e}px`,a.style.width=`${r}px`,a.style.height=`${i}px`}function Dy(n,t,e,o,r){g(Bc,o>0,`invalid end: ${o}`);const i=te(t),s=t.getBoundingClientRect(),l=Nr(n,t,Ce(n,t,e,o)),d=w("div",[r==="find"?"editor-highlight":"editor-replace-result-highlight"],i);l.forEach(h=>{tU(d,t,{left:h.left-s.left,width:h.width,top:h.top-s.top,height:h.height})}),Zj(n,t,e,o,d)}function eU(n,t,e,o){return Dy(n,t,e,o,"find")}function Sy(n,t,e,o){return Dy(n,t,e,o,"replace")}function Wf(n,t){Ar(n).forEach(s=>{xt(s,"active")&&ot(s,"active")}),W(t,"active"),g(Bc,t.firstChild instanceof HTMLElement,"invalid highligh dom, invalid elem child");const o=t.firstChild;let i=o.getBoundingClientRect().y;i===0&&(i=o.getBoundingClientRect().y),ym(o,{elementToScroll:n.scrollContainer})}function Ru(n){const t=n.rootContainer.querySelector(".editor-highlight.active");return t||null}function Ly(n){return g(Bc,n,"no highlight elem"),xt(n,"editor-highlight-readonly")}const Ec=S("highligh-text");function My(n){Jj(n).forEach(e=>{e.remove()})}function qf(n,t){Ar(n).forEach(o=>{o.remove()}),t!=null&&t.keepReplaceResult||My(n)}function Ry(n,t,e){Yj(n,t).forEach(r=>{r.remove()}),e!=null&&e.keepReplaceResult||My(n)}function Ou(n){const t=Ru(n);if(!t)return-1;const o=Ar(n).indexOf(t);return g(Ec,o!==-1,`invalid highlight index: ${o}`),o}function nU(n){const t=Ar(n);if(t.length===0)return 0;const e=Ru(n);let o=e?t.indexOf(e):-1;!e||o===-1||o===t.length-1?o=0:o+=1;const r=t[o];return Wf(n,r),o}function oU(n){const t=Ar(n);if(t.length===0)return 0;const e=Ru(n);let o=e?t.indexOf(e):-1;!e||o===-1||o===0?o=t.length-1:o-=1;const r=t[o];return Wf(n,r),o}function f2(n,t){const e=Ar(n);e.length>0&&t<e.length&&Wf(n,e[t])}function rU(n,t,e){const o=Ru(n);if(!o)return!1;const r=et(o);if(g(Ec,r,"no parent block"),!n.isBlockWritable(r))return!1;const i=ti(n);let s=Ou(n);if(!Ly(o)&&n.isBlockWritable(r)){const d=zf(n,o),h=n.getBlockText(r),{start:p,end:A}=zf(n,o),[v,B]=ln.transformOffset(d.oldText,h,[p,A]),D=F4(h,v,B-v);if(ie(D).toLowerCase()!==t.toLowerCase())return!1;const x=fh(h,v,B,e);n.setBlockText(r,x),Kj(r),m2(n,r,t),e&&Sy(n,r,v,v+e.length)}const l=ti(n);s>=l?s=0:l>i&&(s+=1);const a=Xj(n,s);return a&&Wf(n,a),!0}function iU(n,t,e,o){if(!tt(n,t)||!n.isBlockWritable(t))return 0;const r=n.getBlockText(t);g(Ec,r,"no block text");const i={count:0},s=i6(r,e,o,i);return ie(r)===ie(s)?0:(n.setBlockText(t,s),i.count)}function sU(n,t,e){if(g(Ec,Qj(t),"not a highlight elem"),Ly(t))return;g(Ec,e>0,"invalid highlight length");const o=zf(n,t),r=et(t);g(Ec,r,"no parent block"),Sy(n,r,o.start,o.start+e)}function lU(n,t){Ar(n).forEach(o=>{sU(n,o,t)})}function cU(n,t,e){if(n.readonly)return 0;const o=i=>{let s=0;return pe(i).forEach(a=>{Mt(n,a)?xn(n,a).forEach(h=>{s+=o(h)}):s+=iU(n,a,t,e)}),s},r=o(n.rootContainer);return e.length>0&&lU(n,e.length),r}function aU(n){const t=n.selection.range.end,e=n.getBlockById(t.blockId),o=t.isSimple()?t.offset:1,r=Vf(e);for(let l=0;l<r.length;l++){const a=r[l],{end:d}=zf(n,a);if(d>=o)return a}const i=tg(n,{simpleBlockOnly:!0}),s=i.indexOf(e);if(s===-1)return null;for(let l=s+1;l<i.length;l++){const a=i[l],d=Vf(a);if(d.length>0)return d[0]}return null}function uU(n){const t=Ar(n),e=aU(n);return e?t.indexOf(e):0}function m2(n,t,e){if(!!e&&tt(n,t)){const o=n.getBlockText(t),r=mg(o,e);r.length>0&&r.forEach(({start:i,end:s})=>{eU(n,t,i,s)})}}function Oy(n,t){if(qf(n),!t)return;tg(n,{simpleBlockOnly:!0}).forEach(o=>{m2(n,o,t)})}class dU{constructor(t){m(this,"dialog",null);m(this,"root");m(this,"oldText","");m(this,"_compositionEndTime",0);m(this,"components");m(this,"handleFindChanged",()=>{this.doSearch({keepReplaceResult:!1,gotoFirstSearchResult:!0})});m(this,"handleCompositionEnd",()=>{this._compositionEndTime=Date.now(),this.handleFindChanged()});m(this,"handleDocChanged",t=>{setTimeout(()=>{Ry(this.editor,t),m2(this.editor,t,this.components.findInput.value);const e=ti(this.editor);t.querySelectorAll(".editor-highlight").length===e&&f2(this.editor,0);const o=Ou(this.editor);this.updateSearchStatus(o,e)})});m(this,"handleDocInserted",()=>{const t=setTimeout(()=>{clearTimeout(t),qf(this.editor,{keepReplaceResult:!0}),Oy(this.editor,this.components.findInput.value);const e=ti(this.editor),o=Ou(this.editor);this.updateSearchStatus(o,e),f2(this.editor,o)})});m(this,"handleDocDeleted",t=>{const e=setTimeout(()=>{if(!Vf(t).length){clearTimeout(e);return}Ry(this.editor,t);const r=ti(this.editor),i=Ou(this.editor);this.updateSearchStatus(i,r)})});m(this,"handleInput",t=>{if(t.isComposing||Iy(this._compositionEndTime)){this.doSearch.cancel();return}this.handleFindChanged()});m(this,"handleFind",()=>{this.findNext({keepSearchResult:!1})});m(this,"handleReplace",()=>{const t=this.components.findInput.value;if(!t||!Ru(this.editor))return;const o=this.components.replaceInput.value;if(t===o)return;if(rU(this.editor,t,o)){const i=Ou(this.editor),s=ti(this.editor);this.updateSearchStatus(i,s)}this.findNext({keepSearchResult:!0})});m(this,"handleReplaceAll",()=>{const t=this.components.findInput.value;if(!t)return;const e=this.components.replaceInput.value;if(t===e)return;cU(this.editor,t,e)>0&&(this.oldText="",this.doSearchNow({keepReplaceResult:!0,gotoFirstSearchResult:!0}),this.clearFind({keepReplaceResult:!0}))});m(this,"doSearch",Le.default(this.doSearchNow,300));this.editor=t;const e=w("div",["editor-find-dialog"],null),o=w("div",["editor-find-content"],e),r=w("div",["editor-find-dialog-row"],o),i=$l(rv,["editor-find-dialog-button-close"],e),s=w("label",["editor-find-dialog-label"],r,R.t("find.findLabel"));s.htmlFor="";const l=w("div",["editor-find-dialog-input-container"],r),a=w("input",["editor-find-dialog-input"],l);a.type="text",a.placeholder=R.t("find.findPlaceholder");const d=w("div",["editor-find-dialog-status"],l),h=$l(AL,["editor-find-dialog-icon-button"],d),p=w("div",["editor-find-dialog-curr"],d,"0/0"),A=$l(bL,["editor-find-dialog-icon-button"],d);let v;R.t("find.moreButton")?v=w("button",["editor-find-dialog-button"],r,R.t("find.moreButton")):v=$l(iv,["editor-find-dialog-icon-button-border"],r);const B=w("div",["editor-find-dialog-row"],o),D=w("label",["editor-find-dialog-label"],B,R.t("find.replaceLabel"));D.htmlFor="";const x=w("div",["editor-find-dialog-input-container"],B),_=w("input",["editor-find-dialog-input"],x);_.type="text",_.placeholder=R.t("find.replacePlaceholder");const M=w("div",["editor-find-dialog-row"],o);w("div",["editor-find-dialog-space"],M);const H=w("button",["editor-find-dialog-button"],M,R.t("find.findButton")),z=w("button",["editor-find-dialog-button"],M,R.t("find.replaceButton")),q=w("button",["editor-find-dialog-button"],M,R.t("find.replaceAllButton"));v.onclick=()=>{this.showReplace()},i.onclick=()=>{this.hide()},a.onkeydown=ft=>{if(ft.isComposing||Iy(this._compositionEndTime)){this.doSearch.cancel();return}bC(ft)?(this.doSearch.cancel(),this.doSearchNow({keepReplaceResult:!1,gotoFirstSearchResult:!0})):Em(ft)&&this.hide()},a.oninput=this.handleInput,a.onpaste=this.handleFindChanged,a.oncut=this.handleFindChanged,a.addEventListener("compositionend",this.handleCompositionEnd),a.maxLength=50,H.onclick=this.handleFind,z.onclick=this.handleReplace,q.onclick=this.handleReplaceAll,_.maxLength=50,A.onclick=()=>{this.gotoNext()},h.onclick=()=>{this.gotoPrev()},this.components={findInput:a,findPrev:h,findCurrent:p,findNext:A,replaceInput:_,findButton:H,replaceButton:z,replaceAllButton:q,closeButton:i,showReplaceButton:v,rowReplace:B,rowActions:M,statusContainer:d},this.root=e;const rt=new Gj(t);t.doc.registerCallback(rt),rt.addListener("onDocChanged",this.handleDocChanged),rt.addListener("onDocInserted",this.handleDocInserted),rt.addListener("onDocDeleted",this.handleDocDeleted)}findNext(t){this.doSearch.cancel(),this.doSearchNow({keepReplaceResult:t.keepSearchResult,gotoFirstSearchResult:!0})}doSearchNow(t){const e=this.components.findInput.value;if(e||this.clearFind(t),this.oldText===e){this.gotoNext();return}this.oldText=e,Oy(this.editor,e);const o=ti(this.editor),r=uU(this.editor);t.gotoFirstSearchResult&&f2(this.editor,r),this.updateSearchStatus(r,o)}gotoNext(){const t=ti(this.editor),e=nU(this.editor);this.updateSearchStatus(e,t)}gotoPrev(){const t=ti(this.editor),e=oU(this.editor);this.updateSearchStatus(e,t)}updateSearchStatus(t,e){if(this.oldText?this.components.statusContainer.style.display="flex":this.components.statusContainer.style.display="none",e===0)this.components.findCurrent.innerText="0/0",this.components.replaceAllButton.disabled=!0,this.components.replaceButton.disabled=!0,this.components.findButton.disabled=!0;else{this.components.findCurrent.innerText=`${t+1}/${e}`;const o=this.editor.readonly;this.components.replaceAllButton.disabled=o,this.components.replaceButton.disabled=o,this.components.findButton.disabled=!1}}clearFind(t){qf(this.editor),this.updateSearchStatus(0,0)}showFindOnly(){this.components.rowReplace.style.display="none",this.components.rowActions.style.display="none",this.components.showReplaceButton.style.display="flex"}showReplace(){this.components.rowReplace.style.display="flex",this.components.rowActions.style.display="flex",this.components.showReplaceButton.style.display="none",this.components.replaceInput.focus(),this.components.replaceInput.select()}hideSearchResult(){this.components.statusContainer.style.display="none"}showSearchResult(){this.components.statusContainer.style.display="flex"}show(t){const e=this.editor.getSelectedText();e.length>0&&e.length<50&&(this.components.findInput.value=e),this.root.style.display="flex",t!=null&&t.showFindAndReplace?(this.showReplace(),this.components.findInput.value&&setTimeout(()=>{this.components.replaceInput.focus()})):this.showFindOnly(),this.hideSearchResult(),this.oldText="",this.doSearchNow({keepReplaceResult:!1,gotoFirstSearchResult:!0});const o=this.editor.readonly;this.components.replaceButton.disabled=o,this.components.replaceAllButton.disabled=o,this.components.replaceInput.disabled=o,this.dialog||(this.dialog=new iu(this.root,{disablePageScroll:!1}));const r=this.editor.options.componentsOptions.findDialog,i=(r==null?void 0:r.popoverTarget)||this.editor.rootContainer,s=()=>{var p,A,v,B;const l=r==null?void 0:r.getReferenceClientRect;if(l&&((A=(p=this.dialog)==null?void 0:p.tippyInstance)==null?void 0:A.popper))return l(i,(B=(v=this.dialog)==null?void 0:v.tippyInstance)==null?void 0:B.popper);const a=i.getBoundingClientRect(),d=a.top<0?12:a.top+12,h=a.right-this.root.clientWidth-12;return new DOMRect(h,d,0,0)};this.dialog.show(i,{getReferenceClientRect:s}),setTimeout(()=>{this.components.findInput.focus(),this.components.findInput.select()},300)}hide(){var t;(t=this.dialog)==null||t.close("cancelBar"),qf(this.editor)}isVisible(){return this.dialog&&this.dialog.isVisible}research(){this.oldText="",this.doSearch({keepReplaceResult:!0,gotoFirstSearchResult:!1})}destroy(){var t;(t=this.dialog)==null||t.destroy()}}const hU={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"}},fU={find:{findLabel:"Search:",replaceLabel:"Replace:",findButton:"Search",replaceButton:"Replace",replaceAllButton:"Replace all",moreButton:"",findPlaceholder:"Search text in document",replacePlaceholder:"Replace with"}},mU={find:{findLabel:"\u691C\u7D22\uFF1A",replaceLabel:"\u7F6E\u63DB\uFF1A",findButton:"\u691C\u7D22",replaceButton:"\u7F6E\u63DB",replaceAllButton:"\u3059\u3079\u3066\u3092\u7F6E\u63DB",moreButton:"",findPlaceholder:"\u30C9\u30AD\u30E5\u30E1\u30F3\u30C8\u3092\u691C\u7D22",replacePlaceholder:"\u306B\u7F6E\u63DB"}};R.mergeLang({"zh-CN":hU,"en-US":fU,"ja-JP":mU});function _y(n){return n.addCustom("find-dialog",()=>new dU(n)).show(),!0}const Fy={"CtrlOrCmd+F":_y},znt="";function gU(n){_y(n)}function g2(n,t){return t.map(e=>{var i,s;const o=Qt(n,e),r=(i=o.getBlockProperties)==null?void 0:i.call(o,n,e);return Me(e)||Mt(n,e)?r!=null&&r.abstract?`[${r.abstract}]`:"":(s=r==null?void 0:r.abstract)!=null?s:""}).join(" ")}function Gf(n){const{editor:t,commentGroupId:e,abstract:o="text"}=n,r=K(),i=t.doc.getUser(),s=Date.now(),l=e!=null?e:r;return{id:r,groupId:l,userId:i.userId,displayName:i.displayName,avatarUrl:i.avatarUrl,abstract:o,created:s,modified:s}}function Py(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 p2(n,t,e){const o=g2(n,[t]),r=Gf({editor:n,abstract:o});Py(n,t,r);const i=Wr();return e.localCreateComment(r,i),r}const pU=S("standard-block-actions");class CU{constructor(t,e){m(this,"executeCommand",(t,e,o)=>{const r=o.data;try{this.editorComments.showCommentList();const i=t.getBlockById(r);p2(t,i,this.provider)}catch(i){pU.error(`failed to execute block command: ${JSON.stringify(i)}`)}});this.provider=t,this.editorComments=e}commands(t,e){const o=it(e);return{group:"block-comment-actions",commands:[{id:"comment",name:R.t("comment.quickMenuCommand"),data:o,order:100,states:t.readonly?["disabled"]:[]}],executeCommand:this.executeCommand}}}class AU{async handleBeforePasteDoc(t,e){return Object.values(e.blocks).forEach(o=>{o.forEach(r=>{delete r.comments,r.text&&r.text.forEach(i=>{if(i.attributes){const s=i.attributes;Object.keys(s).forEach(l=>{l.startsWith("comment-")&&delete s[l]})}})})}),!1}}var Jt=(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))(Jt||{});const C2="group-item-action",Ny="last-comment-item",bU="disabled",$y=500;function Js(n){return n.id!==n.groupId}function Hy(n,t=".comment-item-root"){return n.querySelectorAll(t).length}function vU(n){const t=n.closest(".comment-item-root");return t?t.id:null}function ei(n,t){n.setAttribute(C2,t)}function yU(n){return n.closest(`[${C2}]`)}function kU(n){var t;return(t=n.getAttribute(C2))!=null?t:""}function wU(n){return n.disabled||n.classList.contains(bU)}function jy(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 Uy(n){return Array.from(n.attributes).map(e=>e.name).filter(e=>e.startsWith("comment-")).map(e=>e.replace("comment-",""))}const zy=S("doc-comments");function Vy(n,t,e,o){if(t.comments){const i=t.comments;Array.isArray(i)&&i.forEach(s=>{o.has(s)||(o.add(s),e.push(s))})}t.text&&t.text.forEach(s=>{if(s.attributes){const l="comment-";Object.entries(s.attributes).forEach(([a,d])=>{if(a.startsWith(l)){const h=d;o.has(h)||(o.add(h),e.push(h))}})}});const r=t.children;!r||r.forEach(i=>{n.blocks[i].forEach(l=>{Vy(n,l,e,o)})})}function BU(n){const t=[],e=new Set;n.blocks.root.forEach(r=>{Vy(n,r,t,e)});const o=new Map;return t.forEach((r,i)=>o.set(r,i)),o}function EU(n){const t=new Map;n.forEach(r=>{if(Js(r)){const i=t.get(r.groupId);i?i.push(r):t.set(r.groupId,[r])}});const e=[];return n.forEach(r=>{var i;if(!Js(r)){const s=(i=t.get(r.id))!=null?i:[];t.delete(r.id);const l={...r,children:s};e.push(l)}}),Array.from(t.values()).forEach(r=>{const i=r[0],s=r.slice(1),l={...i,children:s};e.push(l)}),e}function Xi(n,t){const e=n.doc.toJSON(),o=BU(e);return EU(t.getComments()).filter(s=>o.has(s.groupId)).sort((s,l)=>{const a=o.get(s.groupId),d=o.get(l.groupId);return g(zy,a!==void 0,`comment not exists in doc, ${s.groupId}`),g(zy,d!==void 0,`comment not exists in doc, ${l.groupId}`),a-d})}function A2(n){const{children:t,...e}=n,o=[e];return t.forEach(r=>{o.push(r)}),o}function xU(n,t){return Xi(n,t).map(A2).reduce((r,i)=>i.length+r,0)}function b2(n,t){const e=[],o=n.getBlockById(t.blockId);if(tt(n,o)){const i=t.blockId,s=t.offset,l=n.getBlockById(i),a=n.getBlockText(l),d=Da(a,s);d&&Object.entries(d).forEach(([h,p])=>{h.startsWith("comment-")&&e.push(p)})}const r=o.attributes;for(let i=0;i<r.length;i++){const s=r[i];s.name.startsWith("comment-")&&e.push(s.value)}return e}function Wy(n){const t=n.selection.range;if(!t.isSimple())return[];if(t.start.blockId!==t.end.blockId)return[];if(t.isCollapsed())return b2(n,t.start);const{start:e,end:o}=t,r=b2(n,e),i=b2(n,o);return fm.default(r,i)}const IU=S("active-comments");function qy(n,t){n.rootContainer.querySelectorAll(`span.text.comment[comment-${t}],[data-type=editor-block].comment[comment-${t}]`).forEach(o=>{ot(o,"active")})}function Gy(n,t){const e=n.rootContainer.querySelector("span.text.comment.active,[data-type=editor-block].comment.active");if(!t)e&&Uy(e).forEach(r=>qy(n,r));else{const o=t.toLocaleLowerCase();if(e){const i=Uy(e);if(i.length===1&&i[0]===o)return;i.forEach(s=>qy(n,s))}const r=n.rootContainer.querySelectorAll(`span.text.comment[comment-${o}],[data-type=editor-block].comment[comment-${o}]`);if(r){r.forEach(s=>{W(s,"active")});const i=r[0];if(Es(i))n.selection.selectBlock(i,0);else if(Wy(n).indexOf(t)===-1){const l=et(i);g(IU,l,"block not found");const a=_s(l,i);n.selection.selectBlock(l,a.start)}n.focus()}}}const Vnt="";S("comment-editor");const{t:TU}=R,v2="comment-editor-readonly",_u="comment-editor-editing";class y2{constructor(t,e,o){m(this,"root");m(this,"components");m(this,"handleEditorBlur",()=>{this.inactiveEditor()});m(this,"handleEditorFocus",()=>{this.editor.readonly||this.activeEditor()});m(this,"activeEditor",()=>{xt(this.root,_u)||W(this.root,_u)});m(this,"inactiveEditor",()=>{ot(this.root,_u)});m(this,"handleInsertImg",async()=>{const{editor:t}=this.components,e=at(t.rootContainer),o=await Ul("image/*",{}),r={src:"",widthPercent:50},i={id:K(),type:"embed",embedType:"image",embedData:r},s=t.options.componentsOptions.image;s!=null&&s.defaultAlign&&(i.align=s.defaultAlign);const l=t.getFocusedBlock(),a=t.getBlockIndex(l),d=t.insertBlock(e,a+1,i);Ie.getImageObject(t,d).replaceImage(0,o)});m(this,"handleReadonlyChange",t=>{t.readonly?(ot(this.root,_u),W(this.root,v2)):(W(this.root,_u),ot(this.root,v2))});m(this,"setDoc",t=>{const{components:{editor:e}}=this;e.doc.externalDoc.setDoc(t)});m(this,"getDoc",()=>{const{components:{editor:t}}=this;return t.doc.toJSON()});m(this,"isEmpty",()=>gg(this.getDoc()));m(this,"edit",()=>{const{editor:t}=this.components;t.readonly=!1,_A(t),this.activeEditor()});m(this,"clear",()=>{const t=Wr();this.setDoc(t)});m(this,"readonly",()=>{const{editor:t}=this.components;t.readonly=!0});m(this,"destroy",()=>{const{root:t,components:{editor:e,insertImgButton:o}}=this;o.onclick=null,e.destroy(),t.remove()});this.mainEditor=t,this.commentsProvider=e,this.doc=o,this.root=w("div",["comment-editor",v2],null),this.components=this.createEditor()}createEditor(){const t=w("div",["comment-editor-root"],this.root),{commentsProvider:e,mainEditor:o}=this,r=e.createCommentEditor(t,new Xg(this.doc));r.readonly=!0,r.addListener("readonlyChanged",this.handleReadonlyChange),r.addListener("focus",this.handleEditorFocus),r.addListener("blur",this.handleEditorBlur);const i=Qs(this.root,"comment-editor-img",TU("comment.image"),DL,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 DU{constructor(t){m(this,"handleBeforeKeyDown",(t,e)=>{if(_r(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 SU{constructor(t,e,o){m(this,"handleBeforeKeyDown",(t,e)=>{if(_r(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 LU=`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
475
|
+
`).map(h=>{const p={id:K(),type:"text"};if(zj(h)&&!r)return p.text=Vj(h),p;const A=h?[co(h,null)]:[];return p.text=A,p})},meta:{},comments:{}};i["text/plain"]=d}return i}}function qj(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 h2{constructor(t){t.dataConverter.addConverter(new jj),t.dataConverter.addConverter(new Wj),t.dataConverter.addConverter(new Uj)}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=qj(r.files);if(s.length>0&&!o["text/office-html"])return await this.handleInsertImages(t,s),!0}return!1}async handleInsertImages(t,e){const{start:o,end:r}=t.selection.range,i=t.selection.focusedBlock;let s=nt(i),a=bt(i);const d=et(s);if(d&&Dt(d)==="code")return;if(o.blockId===r.blockId&&Me(i))a+=1;else{t.clearSelectedContents();const{blockId:p}=t.selection.range.start,A=t.getBlockById(p);a=bt(A),s=nt(A),he(t,A)||(a+=1),Yt(s)&&a===0&&(a+=1)}const h=at(s);for(let p=0;p<e.length;p++){const A=e[p],v=await Vm(t,"image",h,a+p,{file:A});v&&a4(t,v,"image",{id:"replace-image",name:"Replace image",data:{block:v,image:A}})}}}class Gj extends ye.TypedEmitter{constructor(t){super(),this.editor=t}onUpdateBlockText(t,e,o){const r=this.editor.getCustom("find-dialog");if(!r||!r.isVisible())return;const i=Fr(jr(this.editor,t),e);!tt(this.editor,i)||!o.some(l=>l.insert||l.delete)||this.emit("onDocChanged",i)}onInsertBlock(t,e,o,r){Fr(jr(this.editor,t),e),this.emit("onDocInserted")}onDeleteBlock(t,e,o){const r=Fr(jr(this.editor,t),e);this.emit("onDocDeleted",r)}}function Iy(n){return Ze.isSafari&&!!n&&Date.now()-n<100}const Ty=S("highlight-data");class Uf{constructor(t){m(this,"data",new Map);this.editor=t}add(t,e,o){const r={id:K(),blockId:it(t),oldText:this.editor.getBlockText(t),start:e,end:o};return this.data.set(r.id,r),r}get(t){const e=this.data.get(t);return g(Ty,e,`no highligh data: ${t}`),e}remove(t){this.data.delete(t)}clearBlockData(t){Array.from(this.data.values()).forEach(e=>{e.blockId===t&&this.data.delete(e.id)})}destroy(){}static getData(t){return t.addCustom("highligh-data",()=>new Uf(t))}}function Zj(n,t,e,o,r){const s=Uf.getData(n).add(t,e,o);return r.setAttribute("data-highlight-id",s.id),s}function zf(n,t){const e=t.getAttribute("data-highlight-id");return g(Ty,e,"invalid highlight elem, no id"),Uf.getData(n).get(e)}const Bc=S("highligh-dom");function Qj(n){return xt(n,"editor-highlight")}function br(n){const t=n.rootContainer.querySelectorAll(".editor-highlight");return Array.from(t)}function Yj(n,t){g(Bc,t,"invalid block");const e=t.querySelectorAll(".editor-highlight");return Array.from(e)}function Jj(n){const t=n.rootContainer.querySelectorAll(".editor-replace-result-highlight");return Array.from(t)}function Vf(n){const t=n.querySelectorAll(".editor-highlight");return Array.from(t)}function Kj(n){Vf(n).forEach(t=>{t.remove()})}function ti(n){return br(n).length}function Xj(n,t){g(Bc,t>=0,`invalid highlight index: ${t}`);const e=br(n);return e.length===0?null:(g(Bc,t<e.length,`invalid highlight index: ${t}/${e.length}`),e[t])}function tU(n,t,{left:e,top:o,width:r,height:i},s){const l=["editor-highlight-child"];s&&l.push("editor-highlight-readonly");const a=w("div",l,n);a.style.top=`${o}px`,a.style.left=`${e}px`,a.style.width=`${r}px`,a.style.height=`${i}px`}function Dy(n,t,e,o,r){g(Bc,o>0,`invalid end: ${o}`);const i=te(t),s=t.getBoundingClientRect(),l=Nr(n,t,Ce(n,t,e,o)),d=w("div",[r==="find"?"editor-highlight":"editor-replace-result-highlight"],i);l.forEach(h=>{tU(d,t,{left:h.left-s.left,width:h.width,top:h.top-s.top,height:h.height})}),Zj(n,t,e,o,d)}function eU(n,t,e,o){return Dy(n,t,e,o,"find")}function Sy(n,t,e,o){return Dy(n,t,e,o,"replace")}function Wf(n,t){br(n).forEach(s=>{xt(s,"active")&&ot(s,"active")}),W(t,"active"),g(Bc,t.firstChild instanceof HTMLElement,"invalid highligh dom, invalid elem child");const o=t.firstChild;let i=o.getBoundingClientRect().y;i===0&&(i=o.getBoundingClientRect().y),ym(o,{elementToScroll:n.scrollContainer})}function Ru(n){const t=n.rootContainer.querySelector(".editor-highlight.active");return t||null}function Ly(n){return g(Bc,n,"no highlight elem"),xt(n,"editor-highlight-readonly")}const Ec=S("highligh-text");function My(n){Jj(n).forEach(e=>{e.remove()})}function qf(n,t){br(n).forEach(o=>{o.remove()}),t!=null&&t.keepReplaceResult||My(n)}function Ry(n,t,e){Yj(n,t).forEach(r=>{r.remove()}),e!=null&&e.keepReplaceResult||My(n)}function Ou(n){const t=Ru(n);if(!t)return-1;const o=br(n).indexOf(t);return g(Ec,o!==-1,`invalid highlight index: ${o}`),o}function nU(n){const t=br(n);if(t.length===0)return 0;const e=Ru(n);let o=e?t.indexOf(e):-1;!e||o===-1||o===t.length-1?o=0:o+=1;const r=t[o];return Wf(n,r),o}function oU(n){const t=br(n);if(t.length===0)return 0;const e=Ru(n);let o=e?t.indexOf(e):-1;!e||o===-1||o===0?o=t.length-1:o-=1;const r=t[o];return Wf(n,r),o}function f2(n,t){const e=br(n);e.length>0&&t<e.length&&Wf(n,e[t])}function rU(n,t,e){const o=Ru(n);if(!o)return!1;const r=et(o);if(g(Ec,r,"no parent block"),!n.isBlockWritable(r))return!1;const i=ti(n);let s=Ou(n);if(!Ly(o)&&n.isBlockWritable(r)){const d=zf(n,o),h=n.getBlockText(r),{start:p,end:A}=zf(n,o),[v,B]=ln.transformOffset(d.oldText,h,[p,A]),D=F4(h,v,B-v);if(ie(D).toLowerCase()!==t.toLowerCase())return!1;const x=fh(h,v,B,e);n.setBlockText(r,x),Kj(r),m2(n,r,t),e&&Sy(n,r,v,v+e.length)}const l=ti(n);s>=l?s=0:l>i&&(s+=1);const a=Xj(n,s);return a&&Wf(n,a),!0}function iU(n,t,e,o){if(!tt(n,t)||!n.isBlockWritable(t))return 0;const r=n.getBlockText(t);g(Ec,r,"no block text");const i={count:0},s=i6(r,e,o,i);return ie(r)===ie(s)?0:(n.setBlockText(t,s),i.count)}function sU(n,t,e){if(g(Ec,Qj(t),"not a highlight elem"),Ly(t))return;g(Ec,e>0,"invalid highlight length");const o=zf(n,t),r=et(t);g(Ec,r,"no parent block"),Sy(n,r,o.start,o.start+e)}function lU(n,t){br(n).forEach(o=>{sU(n,o,t)})}function cU(n,t,e){if(n.readonly)return 0;const o=i=>{let s=0;return pe(i).forEach(a=>{Mt(n,a)?xn(n,a).forEach(h=>{s+=o(h)}):s+=iU(n,a,t,e)}),s},r=o(n.rootContainer);return e.length>0&&lU(n,e.length),r}function aU(n){const t=n.selection.range.end,e=n.getBlockById(t.blockId),o=t.isSimple()?t.offset:1,r=Vf(e);for(let l=0;l<r.length;l++){const a=r[l],{end:d}=zf(n,a);if(d>=o)return a}const i=tg(n,{simpleBlockOnly:!0}),s=i.indexOf(e);if(s===-1)return null;for(let l=s+1;l<i.length;l++){const a=i[l],d=Vf(a);if(d.length>0)return d[0]}return null}function uU(n){const t=br(n),e=aU(n);return e?t.indexOf(e):0}function m2(n,t,e){if(!!e&&tt(n,t)){const o=n.getBlockText(t),r=mg(o,e);r.length>0&&r.forEach(({start:i,end:s})=>{eU(n,t,i,s)})}}function Oy(n,t){if(qf(n),!t)return;tg(n,{simpleBlockOnly:!0}).forEach(o=>{m2(n,o,t)})}class dU{constructor(t){m(this,"dialog",null);m(this,"root");m(this,"oldText","");m(this,"_compositionEndTime",0);m(this,"components");m(this,"handleFindChanged",()=>{this.doSearch({keepReplaceResult:!1,gotoFirstSearchResult:!0})});m(this,"handleCompositionEnd",()=>{this._compositionEndTime=Date.now(),this.handleFindChanged()});m(this,"handleDocChanged",t=>{setTimeout(()=>{Ry(this.editor,t),m2(this.editor,t,this.components.findInput.value);const e=ti(this.editor);t.querySelectorAll(".editor-highlight").length===e&&f2(this.editor,0);const o=Ou(this.editor);this.updateSearchStatus(o,e)})});m(this,"handleDocInserted",()=>{const t=setTimeout(()=>{clearTimeout(t),qf(this.editor,{keepReplaceResult:!0}),Oy(this.editor,this.components.findInput.value);const e=ti(this.editor),o=Ou(this.editor);this.updateSearchStatus(o,e),f2(this.editor,o)})});m(this,"handleDocDeleted",t=>{const e=setTimeout(()=>{if(!Vf(t).length){clearTimeout(e);return}Ry(this.editor,t);const r=ti(this.editor),i=Ou(this.editor);this.updateSearchStatus(i,r)})});m(this,"handleInput",t=>{if(t.isComposing||Iy(this._compositionEndTime)){this.doSearch.cancel();return}this.handleFindChanged()});m(this,"handleFind",()=>{this.findNext({keepSearchResult:!1})});m(this,"handleReplace",()=>{const t=this.components.findInput.value;if(!t||!Ru(this.editor))return;const o=this.components.replaceInput.value;if(t===o)return;if(rU(this.editor,t,o)){const i=Ou(this.editor),s=ti(this.editor);this.updateSearchStatus(i,s)}this.findNext({keepSearchResult:!0})});m(this,"handleReplaceAll",()=>{const t=this.components.findInput.value;if(!t)return;const e=this.components.replaceInput.value;if(t===e)return;cU(this.editor,t,e)>0&&(this.oldText="",this.doSearchNow({keepReplaceResult:!0,gotoFirstSearchResult:!0}),this.clearFind({keepReplaceResult:!0}))});m(this,"doSearch",Le.default(this.doSearchNow,300));this.editor=t;const e=w("div",["editor-find-dialog"],null),o=w("div",["editor-find-content"],e),r=w("div",["editor-find-dialog-row"],o),i=$l(rv,["editor-find-dialog-button-close"],e),s=w("label",["editor-find-dialog-label"],r,R.t("find.findLabel"));s.htmlFor="";const l=w("div",["editor-find-dialog-input-container"],r),a=w("input",["editor-find-dialog-input"],l);a.type="text",a.placeholder=R.t("find.findPlaceholder");const d=w("div",["editor-find-dialog-status"],l),h=$l(AL,["editor-find-dialog-icon-button"],d),p=w("div",["editor-find-dialog-curr"],d,"0/0"),A=$l(bL,["editor-find-dialog-icon-button"],d);let v;R.t("find.moreButton")?v=w("button",["editor-find-dialog-button"],r,R.t("find.moreButton")):v=$l(iv,["editor-find-dialog-icon-button-border"],r);const B=w("div",["editor-find-dialog-row"],o),D=w("label",["editor-find-dialog-label"],B,R.t("find.replaceLabel"));D.htmlFor="";const x=w("div",["editor-find-dialog-input-container"],B),_=w("input",["editor-find-dialog-input"],x);_.type="text",_.placeholder=R.t("find.replacePlaceholder");const M=w("div",["editor-find-dialog-row"],o);w("div",["editor-find-dialog-space"],M);const H=w("button",["editor-find-dialog-button"],M,R.t("find.findButton")),z=w("button",["editor-find-dialog-button"],M,R.t("find.replaceButton")),q=w("button",["editor-find-dialog-button"],M,R.t("find.replaceAllButton"));v.onclick=()=>{this.showReplace()},i.onclick=()=>{this.hide()},a.onkeydown=ft=>{if(ft.isComposing||Iy(this._compositionEndTime)){this.doSearch.cancel();return}bC(ft)?(this.doSearch.cancel(),this.doSearchNow({keepReplaceResult:!1,gotoFirstSearchResult:!0})):Em(ft)&&this.hide()},a.oninput=this.handleInput,a.onpaste=this.handleFindChanged,a.oncut=this.handleFindChanged,a.addEventListener("compositionend",this.handleCompositionEnd),a.maxLength=50,H.onclick=this.handleFind,z.onclick=this.handleReplace,q.onclick=this.handleReplaceAll,_.maxLength=50,A.onclick=()=>{this.gotoNext()},h.onclick=()=>{this.gotoPrev()},this.components={findInput:a,findPrev:h,findCurrent:p,findNext:A,replaceInput:_,findButton:H,replaceButton:z,replaceAllButton:q,closeButton:i,showReplaceButton:v,rowReplace:B,rowActions:M,statusContainer:d},this.root=e;const rt=new Gj(t);t.doc.registerCallback(rt),rt.addListener("onDocChanged",this.handleDocChanged),rt.addListener("onDocInserted",this.handleDocInserted),rt.addListener("onDocDeleted",this.handleDocDeleted)}findNext(t){this.doSearch.cancel(),this.doSearchNow({keepReplaceResult:t.keepSearchResult,gotoFirstSearchResult:!0})}doSearchNow(t){const e=this.components.findInput.value;if(e||this.clearFind(t),this.oldText===e){this.gotoNext();return}this.oldText=e,Oy(this.editor,e);const o=ti(this.editor),r=uU(this.editor);t.gotoFirstSearchResult&&f2(this.editor,r),this.updateSearchStatus(r,o)}gotoNext(){const t=ti(this.editor),e=nU(this.editor);this.updateSearchStatus(e,t)}gotoPrev(){const t=ti(this.editor),e=oU(this.editor);this.updateSearchStatus(e,t)}updateSearchStatus(t,e){if(this.oldText?this.components.statusContainer.style.display="flex":this.components.statusContainer.style.display="none",e===0)this.components.findCurrent.innerText="0/0",this.components.replaceAllButton.disabled=!0,this.components.replaceButton.disabled=!0,this.components.findButton.disabled=!0;else{this.components.findCurrent.innerText=`${t+1}/${e}`;const o=this.editor.readonly;this.components.replaceAllButton.disabled=o,this.components.replaceButton.disabled=o,this.components.findButton.disabled=!1}}clearFind(t){qf(this.editor),this.updateSearchStatus(0,0)}showFindOnly(){this.components.rowReplace.style.display="none",this.components.rowActions.style.display="none",this.components.showReplaceButton.style.display="flex"}showReplace(){this.components.rowReplace.style.display="flex",this.components.rowActions.style.display="flex",this.components.showReplaceButton.style.display="none",this.components.replaceInput.focus(),this.components.replaceInput.select()}hideSearchResult(){this.components.statusContainer.style.display="none"}showSearchResult(){this.components.statusContainer.style.display="flex"}show(t){const e=this.editor.getSelectedText();e.length>0&&e.length<50&&(this.components.findInput.value=e),this.root.style.display="flex",t!=null&&t.showFindAndReplace?(this.showReplace(),this.components.findInput.value&&setTimeout(()=>{this.components.replaceInput.focus()})):this.showFindOnly(),this.hideSearchResult(),this.oldText="",this.doSearchNow({keepReplaceResult:!1,gotoFirstSearchResult:!0});const o=this.editor.readonly;this.components.replaceButton.disabled=o,this.components.replaceAllButton.disabled=o,this.components.replaceInput.disabled=o,this.dialog||(this.dialog=new iu(this.root,{disablePageScroll:!1}));const r=this.editor.options.componentsOptions.findDialog,i=(r==null?void 0:r.popoverTarget)||this.editor.rootContainer,s=()=>{var p,A,v,B;const l=r==null?void 0:r.getReferenceClientRect;if(l&&((A=(p=this.dialog)==null?void 0:p.tippyInstance)==null?void 0:A.popper))return l(i,(B=(v=this.dialog)==null?void 0:v.tippyInstance)==null?void 0:B.popper);const a=i.getBoundingClientRect(),d=a.top<0?12:a.top+12,h=a.right-this.root.clientWidth-12;return new DOMRect(h,d,0,0)};this.dialog.show(i,{getReferenceClientRect:s}),setTimeout(()=>{this.components.findInput.focus(),this.components.findInput.select()},300)}hide(){var t;(t=this.dialog)==null||t.close("cancelBar"),qf(this.editor)}isVisible(){return this.dialog&&this.dialog.isVisible}research(){this.oldText="",this.doSearch({keepReplaceResult:!0,gotoFirstSearchResult:!1})}destroy(){var t;(t=this.dialog)==null||t.destroy()}}const hU={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"}},fU={find:{findLabel:"Search:",replaceLabel:"Replace:",findButton:"Search",replaceButton:"Replace",replaceAllButton:"Replace all",moreButton:"",findPlaceholder:"Search text in document",replacePlaceholder:"Replace with"}},mU={find:{findLabel:"\u691C\u7D22\uFF1A",replaceLabel:"\u7F6E\u63DB\uFF1A",findButton:"\u691C\u7D22",replaceButton:"\u7F6E\u63DB",replaceAllButton:"\u3059\u3079\u3066\u3092\u7F6E\u63DB",moreButton:"",findPlaceholder:"\u30C9\u30AD\u30E5\u30E1\u30F3\u30C8\u3092\u691C\u7D22",replacePlaceholder:"\u306B\u7F6E\u63DB"}};R.mergeLang({"zh-CN":hU,"en-US":fU,"ja-JP":mU});function _y(n){return n.addCustom("find-dialog",()=>new dU(n)).show(),!0}const Fy={"CtrlOrCmd+F":_y},znt="";function gU(n){_y(n)}function g2(n,t){return t.map(e=>{var i,s;const o=Qt(n,e),r=(i=o.getBlockProperties)==null?void 0:i.call(o,n,e);return Me(e)||Mt(n,e)?r!=null&&r.abstract?`[${r.abstract}]`:"":(s=r==null?void 0:r.abstract)!=null?s:""}).join(" ")}function Gf(n){const{editor:t,commentGroupId:e,abstract:o="text"}=n,r=K(),i=t.doc.getUser(),s=Date.now(),l=e!=null?e:r;return{id:r,groupId:l,userId:i.userId,displayName:i.displayName,avatarUrl:i.avatarUrl,abstract:o,created:s,modified:s}}function Py(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 p2(n,t,e){const o=g2(n,[t]),r=Gf({editor:n,abstract:o});Py(n,t,r);const i=Wr();return e.localCreateComment(r,i),r}const pU=S("standard-block-actions");class CU{constructor(t,e){m(this,"executeCommand",(t,e,o)=>{const r=o.data;try{this.editorComments.showCommentList();const i=t.getBlockById(r);p2(t,i,this.provider)}catch(i){pU.error(`failed to execute block command: ${JSON.stringify(i)}`)}});this.provider=t,this.editorComments=e}commands(t,e){const o=it(e);return{group:"block-comment-actions",commands:[{id:"comment",name:R.t("comment.quickMenuCommand"),data:o,order:100,states:t.readonly?["disabled"]:[]}],executeCommand:this.executeCommand}}}class AU{async handleBeforePasteDoc(t,e){return Object.values(e.blocks).forEach(o=>{o.forEach(r=>{delete r.comments,r.text&&r.text.forEach(i=>{if(i.attributes){const s=i.attributes;Object.keys(s).forEach(l=>{l.startsWith("comment-")&&delete s[l]})}})})}),!1}}var Jt=(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))(Jt||{});const C2="group-item-action",Ny="last-comment-item",bU="disabled",$y=500;function Js(n){return n.id!==n.groupId}function Hy(n,t=".comment-item-root"){return n.querySelectorAll(t).length}function vU(n){const t=n.closest(".comment-item-root");return t?t.id:null}function ei(n,t){n.setAttribute(C2,t)}function yU(n){return n.closest(`[${C2}]`)}function kU(n){var t;return(t=n.getAttribute(C2))!=null?t:""}function wU(n){return n.disabled||n.classList.contains(bU)}function jy(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 Uy(n){return Array.from(n.attributes).map(e=>e.name).filter(e=>e.startsWith("comment-")).map(e=>e.replace("comment-",""))}const zy=S("doc-comments");function Vy(n,t,e,o){if(t.comments){const i=t.comments;Array.isArray(i)&&i.forEach(s=>{o.has(s)||(o.add(s),e.push(s))})}t.text&&t.text.forEach(s=>{if(s.attributes){const l="comment-";Object.entries(s.attributes).forEach(([a,d])=>{if(a.startsWith(l)){const h=d;o.has(h)||(o.add(h),e.push(h))}})}});const r=t.children;!r||r.forEach(i=>{n.blocks[i].forEach(l=>{Vy(n,l,e,o)})})}function BU(n){const t=[],e=new Set;n.blocks.root.forEach(r=>{Vy(n,r,t,e)});const o=new Map;return t.forEach((r,i)=>o.set(r,i)),o}function EU(n){const t=new Map;n.forEach(r=>{if(Js(r)){const i=t.get(r.groupId);i?i.push(r):t.set(r.groupId,[r])}});const e=[];return n.forEach(r=>{var i;if(!Js(r)){const s=(i=t.get(r.id))!=null?i:[];t.delete(r.id);const l={...r,children:s};e.push(l)}}),Array.from(t.values()).forEach(r=>{const i=r[0],s=r.slice(1),l={...i,children:s};e.push(l)}),e}function Xi(n,t){const e=n.doc.toJSON(),o=BU(e);return EU(t.getComments()).filter(s=>o.has(s.groupId)).sort((s,l)=>{const a=o.get(s.groupId),d=o.get(l.groupId);return g(zy,a!==void 0,`comment not exists in doc, ${s.groupId}`),g(zy,d!==void 0,`comment not exists in doc, ${l.groupId}`),a-d})}function A2(n){const{children:t,...e}=n,o=[e];return t.forEach(r=>{o.push(r)}),o}function xU(n,t){return Xi(n,t).map(A2).reduce((r,i)=>i.length+r,0)}function b2(n,t){const e=[],o=n.getBlockById(t.blockId);if(tt(n,o)){const i=t.blockId,s=t.offset,l=n.getBlockById(i),a=n.getBlockText(l),d=Da(a,s);d&&Object.entries(d).forEach(([h,p])=>{h.startsWith("comment-")&&e.push(p)})}const r=o.attributes;for(let i=0;i<r.length;i++){const s=r[i];s.name.startsWith("comment-")&&e.push(s.value)}return e}function Wy(n){const t=n.selection.range;if(!t.isSimple())return[];if(t.start.blockId!==t.end.blockId)return[];if(t.isCollapsed())return b2(n,t.start);const{start:e,end:o}=t,r=b2(n,e),i=b2(n,o);return fm.default(r,i)}const IU=S("active-comments");function qy(n,t){n.rootContainer.querySelectorAll(`span.text.comment[comment-${t}],[data-type=editor-block].comment[comment-${t}]`).forEach(o=>{ot(o,"active")})}function Gy(n,t){const e=n.rootContainer.querySelector("span.text.comment.active,[data-type=editor-block].comment.active");if(!t)e&&Uy(e).forEach(r=>qy(n,r));else{const o=t.toLocaleLowerCase();if(e){const i=Uy(e);if(i.length===1&&i[0]===o)return;i.forEach(s=>qy(n,s))}const r=n.rootContainer.querySelectorAll(`span.text.comment[comment-${o}],[data-type=editor-block].comment[comment-${o}]`);if(r){r.forEach(s=>{W(s,"active")});const i=r[0];if(Es(i))n.selection.selectBlock(i,0);else if(Wy(n).indexOf(t)===-1){const l=et(i);g(IU,l,"block not found");const a=_s(l,i);n.selection.selectBlock(l,a.start)}n.focus()}}}const Vnt="";S("comment-editor");const{t:TU}=R,v2="comment-editor-readonly",_u="comment-editor-editing";class y2{constructor(t,e,o){m(this,"root");m(this,"components");m(this,"handleEditorBlur",()=>{this.inactiveEditor()});m(this,"handleEditorFocus",()=>{this.editor.readonly||this.activeEditor()});m(this,"activeEditor",()=>{xt(this.root,_u)||W(this.root,_u)});m(this,"inactiveEditor",()=>{ot(this.root,_u)});m(this,"handleInsertImg",async()=>{const{editor:t}=this.components,e=at(t.rootContainer),o=await Ul("image/*",{}),r={src:"",widthPercent:50},i={id:K(),type:"embed",embedType:"image",embedData:r},s=t.options.componentsOptions.image;s!=null&&s.defaultAlign&&(i.align=s.defaultAlign);const l=t.getFocusedBlock(),a=t.getBlockIndex(l),d=t.insertBlock(e,a+1,i);Ie.getImageObject(t,d).replaceImage(0,o)});m(this,"handleReadonlyChange",t=>{t.readonly?(ot(this.root,_u),W(this.root,v2)):(W(this.root,_u),ot(this.root,v2))});m(this,"setDoc",t=>{const{components:{editor:e}}=this;e.doc.externalDoc.setDoc(t)});m(this,"getDoc",()=>{const{components:{editor:t}}=this;return t.doc.toJSON()});m(this,"isEmpty",()=>gg(this.getDoc()));m(this,"edit",()=>{const{editor:t}=this.components;t.readonly=!1,_A(t),this.activeEditor()});m(this,"clear",()=>{const t=Wr();this.setDoc(t)});m(this,"readonly",()=>{const{editor:t}=this.components;t.readonly=!0});m(this,"destroy",()=>{const{root:t,components:{editor:e,insertImgButton:o}}=this;o.onclick=null,e.destroy(),t.remove()});this.mainEditor=t,this.commentsProvider=e,this.doc=o,this.root=w("div",["comment-editor",v2],null),this.components=this.createEditor()}createEditor(){const t=w("div",["comment-editor-root"],this.root),{commentsProvider:e,mainEditor:o}=this,r=e.createCommentEditor(t,new Xg(this.doc));r.readonly=!0,r.addListener("readonlyChanged",this.handleReadonlyChange),r.addListener("focus",this.handleEditorFocus),r.addListener("blur",this.handleEditorBlur);const i=Qs(this.root,"comment-editor-img",TU("comment.image"),DL,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 DU{constructor(t){m(this,"handleBeforeKeyDown",(t,e)=>{if(or(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 SU{constructor(t,e,o){m(this,"handleBeforeKeyDown",(t,e)=>{if(or(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 LU=`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
476
476
|
<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>
|
|
477
477
|
</svg>`,MU=`<svg
|
|
478
478
|
fill="currentColor"
|
|
@@ -509,7 +509,7 @@ width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
|
|
509
509
|
<path d="M1.00098 12.9985L10.9995 2.99998" stroke="currentColor"/>
|
|
510
510
|
<path d="M11.9113 6.16809L13.7433 3.79209C13.946 3.52009 14.0473 3.26142 14.0473 3.01609V2.90409C14.0473 2.71209 13.994 2.56009 13.8873 2.44809C13.786 2.33609 13.6473 2.28009 13.4713 2.28009C13.2953 2.28009 13.1567 2.33876 13.0553 2.45609C12.954 2.57342 12.9033 2.73609 12.9033 2.94409V3.07209H11.8873V2.88009C11.8873 2.59209 11.9513 2.33609 12.0793 2.11209C12.2127 1.88809 12.402 1.71209 12.6473 1.58409C12.8927 1.45609 13.1807 1.39209 13.5113 1.39209C13.8313 1.39209 14.1113 1.45876 14.3513 1.59209C14.5967 1.72542 14.7833 1.90409 14.9113 2.12809C15.0447 2.35209 15.1113 2.60009 15.1113 2.87209V3.00809C15.1113 3.24809 15.0687 3.46942 14.9833 3.67209C14.898 3.87476 14.7727 4.08276 14.6073 4.29609L13.2313 6.08009H15.1113V7.00009H11.9113V6.16809Z" fill="currentColor"/>
|
|
511
511
|
</svg>
|
|
512
|
-
`,Ks=S("text-commands");function l8(n){const t={id:"more",name:R.t("commands.more"),icon:iv,childrenType:"menu",childrenPlacement:"bottom-start",manualShowChildren:!0,children:[]},e={"style-bold":[R.t("commands.bold"),xo("CtrlOrCmd+B"),hz],"style-italic":[R.t("commands.italic"),xo("CtrlOrCmd+I"),fz],"style-underline":[R.t("commands.underline"),xo("CtrlOrCmd+U"),mz],"style-strikethrough":[R.t("commands.strikethrough"),xo("CtrlOrCmd+D"),gz],"style-code":[R.t("commands.code"),void 0,pz]},o={"style-super":[R.t("commands.superscript"),void 0,Az],"style-sub":[R.t("commands.subscript"),void 0,Cz]};if(rn(n)===0){const l=Object.entries(e).map(([a,[d,h,p]])=>({id:a,name:d,icon:p,desc:h}));return t.children=Object.entries(o).map(([a,[d,h,p]])=>({id:a,name:d,icon:p,desc:h})),l.concat(t)}const r=uz(n);function i([l,[a,d,h]]){const p=r.get(l);return p!==void 0?{id:l,name:a,value:p,states:p===!0?["checked"]:void 0,icon:h,desc:d}:{id:l,name:a,icon:h,desc:d}}const s=Object.entries(e).map(i);return t.children=Object.entries(o).map(i),s.concat(t)}function bz(n,t){const e=it(t),o=Dt(t),r=Do(n,t);return l8([]).map(i=>({blockId:e,blockType:o,blockKind:r,...i,groupIndex:500}))}function vz(n,t,e){g(Ks,e.isSimple(),"nor a simple range");const{start:o,end:r}=e;g(Ks,o.isSimple(),"is not a simple block position"),g(Ks,r.isSimple(),"is not a simple block position"),g(Ks,tt(n,t),"invalid block type, not a text kind block");const i=it(t);g(Ks,o.blockId===i&&r.blockId===i,"invalid range");const s=n.getBlockText(t);let l=[];o.offset===r.offset?o.offset!==0&&(l=ze(s,o.offset-1,1).middle):l=ze(s,o.offset,r.offset-o.offset).middle;const a=Dt(t),d=Do(n,t);return l8(l).map((h,p)=>({blockId:i,blockType:a,blockKind:d,...h,groupIndex:500,order:p*100}))}function yz(n,t,e,o,r,i){if(!tt(n,t))return!1;if(!o.startsWith("style-"))return Ks.warn(`unknown command: ${o}`),!1;const s=r==null?void 0:r.value,l=typeof s;if(l!=="string"&&l!=="number"&&l!=="boolean"&&l!=="undefined")return Ks.warn(`invalid value type, accept string | number | boolean | undefined, current is ${l}`),!1;const a=dz(n,t,e,o,s);return n.focus(),i.result=a,!0}const kz=S("text-command-provider");class
|
|
512
|
+
`,Ks=S("text-commands");function l8(n){const t={id:"more",name:R.t("commands.more"),icon:iv,childrenType:"menu",childrenPlacement:"bottom-start",manualShowChildren:!0,children:[]},e={"style-bold":[R.t("commands.bold"),xo("CtrlOrCmd+B"),hz],"style-italic":[R.t("commands.italic"),xo("CtrlOrCmd+I"),fz],"style-underline":[R.t("commands.underline"),xo("CtrlOrCmd+U"),mz],"style-strikethrough":[R.t("commands.strikethrough"),xo("CtrlOrCmd+D"),gz],"style-code":[R.t("commands.code"),void 0,pz]},o={"style-super":[R.t("commands.superscript"),void 0,Az],"style-sub":[R.t("commands.subscript"),void 0,Cz]};if(rn(n)===0){const l=Object.entries(e).map(([a,[d,h,p]])=>({id:a,name:d,icon:p,desc:h}));return t.children=Object.entries(o).map(([a,[d,h,p]])=>({id:a,name:d,icon:p,desc:h})),l.concat(t)}const r=uz(n);function i([l,[a,d,h]]){const p=r.get(l);return p!==void 0?{id:l,name:a,value:p,states:p===!0?["checked"]:void 0,icon:h,desc:d}:{id:l,name:a,icon:h,desc:d}}const s=Object.entries(e).map(i);return t.children=Object.entries(o).map(i),s.concat(t)}function bz(n,t){const e=it(t),o=Dt(t),r=Do(n,t);return l8([]).map(i=>({blockId:e,blockType:o,blockKind:r,...i,groupIndex:500}))}function vz(n,t,e){g(Ks,e.isSimple(),"nor a simple range");const{start:o,end:r}=e;g(Ks,o.isSimple(),"is not a simple block position"),g(Ks,r.isSimple(),"is not a simple block position"),g(Ks,tt(n,t),"invalid block type, not a text kind block");const i=it(t);g(Ks,o.blockId===i&&r.blockId===i,"invalid range");const s=n.getBlockText(t);let l=[];o.offset===r.offset?o.offset!==0&&(l=ze(s,o.offset-1,1).middle):l=ze(s,o.offset,r.offset-o.offset).middle;const a=Dt(t),d=Do(n,t);return l8(l).map((h,p)=>({blockId:i,blockType:a,blockKind:d,...h,groupIndex:500,order:p*100}))}function yz(n,t,e,o,r,i){if(!tt(n,t))return!1;if(!o.startsWith("style-"))return Ks.warn(`unknown command: ${o}`),!1;const s=r==null?void 0:r.value,l=typeof s;if(l!=="string"&&l!=="number"&&l!=="boolean"&&l!=="undefined")return Ks.warn(`invalid value type, accept string | number | boolean | undefined, current is ${l}`),!1;const a=dz(n,t,e,o,s);return n.focus(),i.result=a,!0}const kz=S("text-command-provider");class vr{constructor(t){m(this,"id","TextCommandProvider");m(this,"emptyTextBlockAttributes",new Map);m(this,"colorItem");m(this,"updateButtonColor",()=>{const t=Ng(this.editor,this.getEmptyTextBlockColor);this.colorItem.updateButtonColor(t)});m(this,"handleChangeColor",(t,e)=>{if(t==="color"||t==="backgroundColor")G6(this.editor,t,e,this.setEmptyTextBlockColor);else{const o=["clearAll","clearColor","clearBackground"];Z6(this.editor,o[e],this.setEmptyTextBlockColor)}this.editor.focus()});m(this,"handleBeforePopupPalette",()=>{const t=Ng(this.editor,this.getEmptyTextBlockColor);this.colorItem.updatePaletteColor(t)});m(this,"getEmptyTextBlockColor",(t,e)=>{const o=this.getEmptyBlockTextAttributes(t,e);return hg(o)});m(this,"setEmptyTextBlockColor",(t,e,o,r)=>{var s;const i=(s=this.emptyTextBlockAttributes.get(e))!=null?s:{};t6(i,o,r),this.emptyTextBlockAttributes.set(e,i)});this.editor=t,this.colorItem=t.addCustom("text-color-item",()=>new yM(t)),this.colorItem.addListener("onClick",this.handleChangeColor),this.colorItem.addListener("beforePopup",this.handleBeforePopupPalette)}destroy(){this.colorItem.destroy()}getAvailableCommands(t,e,o){if(!tt(t,e))return[];let r;ut(t,e)===0?r=this.getCommandsOnEmptyText(t,e).map(vr.toTextCommand):r=vz(t,e,o).map(vr.toTextCommand),this.updateButtonColor();const s={...this.colorItem,blockId:it(e),blockKind:Do(t,e),blockType:Dt(e),groupIndex:500,order:350};return r.push(s),r}executeCommand(t,e,o,r,i,s){if(!tt(t,e))return!1;let l=i.value;l===void 0&&(l=!r.value);const a=vr.fromTextCommandId(r.id);if(a.startsWith("style-")){if(a==="style-font")return this.handleChangeColor(i.type,l),!0;if(ut(t,e)===0)return this.executeCommandOnEmptyText(e,r,{value:l})}return yz(t,e,o,a,{value:l},s)}executeCommandOnEmptyText(t,e,o){let r=this.emptyTextBlockAttributes.get(it(t));r||(r={},this.emptyTextBlockAttributes.set(it(t),r));const i=vr.fromTextCommandId(e.id),s=o.value;return s==null||s===!1?(delete r[i],!0):(r[i]=o.value,!0)}getCommandsOnEmptyText(t,e){const o=bz(t,e);return this.setCommandsStates(o,e)}setCommandsStates(t,e){var i;const o=it(e),r=(i=this.emptyTextBlockAttributes.get(o))!=null?i:{};return t.map(s=>{const l=r[s.id],a=l?["checked"]:void 0;return s.children&&(s.children=this.setCommandsStates(s.children,e)),{...s,value:l,states:a}})}getEmptyBlockTextAttributes(t,e){var r;const o=mt.default((r=this.emptyTextBlockAttributes.get(e))!=null?r:{});if(Array.from(Object.entries(o)).forEach(([i,s])=>{s||delete o[i]}),Object.keys(o).length!==0)return o}static toTextCommand(t){return t.children&&(t.children=t.children.map(vr.toTextCommand)),{...t,id:`text/${t.id}`}}static fromTextCommandId(t){const e="text/";return g(kz,t.startsWith(e),`invalid item id: ${t}`),t.substring(e.length)}static fromTextCommand(t){return{...t,id:this.fromTextCommandId(t.id)}}static toTextCommands(t){return t.map(vr.toTextCommand)}static fromTextCommands(t){return t.map(vr.fromTextCommand)}}function c8(n){const t=n.getCustom("toolbar-handler");t.disableTextToolbar(),t.hide(),setTimeout(()=>{t.enableTextToolbar()},300)}function wz(n){n.undoManager.canUndo()&&c8(n)}function Bz(n){n.undoManager.canRedo()&&c8(n)}const Ez={"CtrlOrCmd+Z":wz,"CtrlOrCmd+Shift+Z":Bz},xz={commands:{bold:"\u7C97\u4F53",italic:"\u659C\u4F53",underline:"\u4E0B\u5212\u7EBF",strikethrough:"\u5220\u9664\u7EBF",code:"\u884C\u5185\u4EE3\u7801",subscript:"\u4E0B\u6807",superscript:"\u4E0A\u6807",more:"\u66F4\u591A"}},Iz={commands:{bold:"Bold",italic:"Italic",underline:"Underline",strikethrough:"Strikethrough",code:"Inline code",subscript:"Subscript",superscript:"Superscript",more:"More"}},Tz={commands:{bold:"\u592A\u5B57",italic:"\u659C\u4F53",underline:"\u4E0B\u7DDA",strikethrough:"\u53D6\u308A\u6D88\u3057\u7DDA",code:"\u30A4\u30F3\u30E9\u30A4\u30F3\u30B3\u30FC\u30C9",subscript:"\u4E0B\u4ED8\u304D\u6587\u5B57",superscript:"\u4E0A\u4ED8\u304D\u6587\u5B57",more:"\u305D\u306E\u4ED6"}};R.mergeLang({"zh-CN":xz,"en-US":Iz,"ja-JP":Tz});var a8=(n=>(n.Card="card",n.Preview="preview",n))(a8||{});const Dz=`<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none">
|
|
513
513
|
<g clip-path="url(#clip0)">
|
|
514
514
|
<path d="M6.01 10.4886C5.85 10.4886 5.7 10.4286 5.58 10.3086L3.98 8.71859C3.35 8.07859 3 7.23859 3 6.34859C3 5.45859 3.35 4.60859 3.98 3.97859C5.29 2.66859 7.41 2.66859 8.72 3.97859L10.31 5.56859C10.55 5.80859 10.55 6.18859 10.31 6.42859C10.07 6.66859 9.69 6.66859 9.45 6.42859L7.86 4.83859C7.03 4.00859 5.68 4.00859 4.85 4.83859C4.45 5.23859 4.23 5.77859 4.23 6.34859C4.23 6.91859 4.45 7.44859 4.85 7.85859L6.44 9.44859C6.68 9.68859 6.68 10.0686 6.44 10.3086C6.32 10.4286 6.16 10.4886 6.01 10.4886ZM11.65 14.9986C10.79 14.9986 9.93 14.6686 9.28 14.0186L7.4 12.1386C7.16 11.8986 7.16 11.5186 7.4 11.2786C7.64 11.0386 8.02 11.0386 8.26 11.2786L10.14 13.1586C10.97 13.9886 12.32 13.9886 13.15 13.1586C13.55 12.7586 13.77 12.2186 13.77 11.6486C13.77 11.0786 13.55 10.5486 13.15 10.1386L11.28 8.25859C11.04 8.01859 11.04 7.63859 11.28 7.39859C11.52 7.15859 11.9 7.15859 12.14 7.39859L14.02 9.27859C14.65 9.90859 15 10.7486 15 11.6486C15 12.5386 14.65 13.3886 14.02 14.0186C13.37 14.6686 12.51 14.9986 11.65 14.9986Z" fill="#5587F0"/>
|
|
515
515
|
<path d="M10.88 10.8604C10.67 11.0704 10.32 11.0704 10.1 10.8604L7.64004 8.40039C7.43004 8.19039 7.43004 7.84039 7.64004 7.62039C7.85004 7.41039 8.20004 7.41039 8.42004 7.62039L10.88 10.0804C11.1 10.3004 11.1 10.6404 10.88 10.8604Z" fill="#5587F0"/>
|
|
@@ -593,7 +593,7 @@ width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
|
|
593
593
|
`:i.src?`[${i.fileName}](${n.doc.buildResourceUrl(i.src,{withToken:!0})})`:`[${i.fileName}]`}async function tV(n,t,e,o){const{onGetFileDownloadUrl:r}=n.getComponentOptions("file")||{},i=t.embedData,s=r?await r(n,i):void 0;return{blocks:{root:[{type:"embed",id:K(),embedType:"webpage",embedData:{src:s||i.src,title:i.fileName}}]},meta:{},comments:{}}}const eV={embedType:"office",createEmbedContent:Yz,getBlockProperties:Kz,convertTo:Xz,toStandardDoc:tV},nV={file:{abstract:"\u9644\u4EF6",commands:{download:"\u4E0B\u8F7D",toLink:"\u8F6C\u4E3A\u6807\u9898",toCard:"\u8F6C\u4E3A\u5361\u7247",comment:"\u6279\u6CE8"}}},oV={file:{abstract:"Attachment",commands:{download:"Download",toLink:"To Link",toCard:"To Card",comment:"Annotation"}}},rV={file:{abstract:"\u6DFB\u4ED8\u30D5\u30A1\u30A4\u30EB",commands:{download:"\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9",toLink:"\u30BF\u30A4\u30C8\u30EB\u306B\u5909\u63DB",toCard:"\u30AB\u30FC\u30C9\u306B\u5909\u63DB",comment:"\u6CE8\u91C8"}}};R.mergeLang({"zh-CN":nV,"en-US":oV,"ja-JP":rV});function iV(n){const t=/(\s|^)(http|https):\/\/[\w\-]+(\.[\w\-]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?$/;return t.test(n)?n.search(t):-1}function sV(n){const t=n.selection.range;if(!t.isCollapsed()||!t.isSimple())return;const{start:e}=t,o=n.getBlockById(e.blockId);if(!tt(n,o))return;const r=n.getBlockText(o),s=fg(r).slice(0,e.offset),l=iV(s);if(l===-1)return;const a=s.slice(l),d=s.length;let h=Ta(l,d-l,r,"link",a);return h=Vr(h,d," ",null),n.setBlockText(o,h),n.selection.selectBlock(o,d+1),!0}const lV={Space:sV},Knt="",cV={version:{latest:"\u6700\u65B0\u7248\u672C",insert:"{name} \u6DFB\u52A0",delete:"{name} \u5220\u9664",goBack:"\u8FD4\u56DE",revertVersion:"\u8FD8\u539F\u5185\u5BB9",play:"\u64AD\u653E\u5386\u53F2\u64CD\u4F5C",versionList:"\u5386\u53F2\u7248\u672C ({count})",unknown:"\u672A\u77E5\u7248\u672C",restoreFrom:"\u56DE\u6EDA\u81EA\u7248\u672C\u300C{from}\u300D",restoreInfo:"\u56DE\u6EDA\u7684\u7248\u672C\u6682\u4E0D\u652F\u6301\u4E0E\u4E0A\u4E00\u7248\u672C\u5BF9\u6BD4",versionInfoLeft:'<span class="text-1">\u5F53\u524D\u7248\u672C: </span><span class="name">{versionName}</span><span class="text-2"> \u4E0E</span>',versionInfoRight:'<span class="text-3">\u5BF9\u6BD4</span>',noSelectedVersion:"\u672A\u9009\u62E9\u7248\u672C",noMemoedVersion:"\u6682\u65E0\u5DF2\u5907\u6CE8\u7684\u5386\u53F2\u7248\u672C",noFilterVersion:"\u6682\u65E0\u5339\u914D\u7ED3\u679C",memo:"\u5907\u6CE8",revert:"\u56DE\u6EDA",filter:{all:"\u5168\u90E8",memoed:"\u5DF2\u5907\u6CE8",allVersions:"\u5168\u90E8\u5386\u53F2\u7248\u672C",memoVersions:"\u5DF2\u5907\u6CE8\u7684\u5386\u53F2\u7248\u672C"},textarea:{placeholder:"\u8BF7\u8F93\u5165\u7248\u672C\u5907\u6CE8"},tooltip:{help:`1. \u56DE\u6EDA\u7248\u672C\u4E0D\u652F\u6301\u4E0E\u56DE\u6EDA\u524D\u7248\u672C\u8FDB\u884C\u5BF9\u6BD4\uFF1B
|
|
594
594
|
2. \u82E5\u4E24\u4E2A\u7248\u672C\u4E4B\u95F4\u5B58\u5728\u56DE\u6EDA\u7248\u672C\uFF0C\u5219\u4E0D\u652F\u6301\u5BF9\u6BD4\u3002`,user:"\u7248\u672C\u53D1\u5E03\u8005\uFF1A{name}",auth:"\u6682\u65E0\u9875\u9762\u7F16\u8F91\u6743\u9650\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458"},dropdownHeader:"\u4EC5\u5C55\u793A\u53EF\u4E0E\u5F53\u524D\u7248\u672C\u8FDB\u884C\u5BF9\u6BD4\u7684\u5386\u53F2\u7248\u672C",dropdown:{header:"\u6240\u6709\u53EF\u5BF9\u6BD4\u7684\u7248\u672C"},noVersions:"\u6682\u65E0\u53EF\u5BF9\u6BD4\u7684\u7248\u672C",lastVersion:"\u4E0A\u4E00\u7248\u672C",filterMemoed:"\u7B5B\u9009\u5DF2\u5907\u6CE8\u7684\u7248\u672C"}},aV={version:{latest:"Latest",insert:"Added by {name}",delete:"Deleted by {name}",goBack:"Back",revertVersion:"Revert",play:"Play",versionList:"Historical versions ({count})",unknown:"Unknown version",restoreFrom:"Rolled back from version {from}",restoreInfo:"The rolled back version does not currently support comparison with the previous version.",versionInfoLeft:'<span class="text-1">Current version: </span><span class="name">{versionName}</span><span class="text-2"> Compare with</span>',versionInfoRight:'<span class="text-3"></span>',noSelectedVersion:"Not selected",noMemoedVersion:"No historical commented versions",noFilterVersion:"No result",memo:"Comment",revert:"Roll back",filter:{all:"All",memoed:"Commented",allVersions:"All historical versions",memoVersions:"Historical versions with comments"},textarea:{placeholder:"Enter comment"},tooltip:{help:`1. A rolled back version can't be compared with versions before it.
|
|
595
595
|
2. Versions can't be compared if there are rolled back versions between them.`,user:"Released by {name}",auth:"No edit permission for this page. Contact the admin."},dropdownHeader:"The list below only contains historical versions that can be compared with the current version",dropdown:{header:"All historical versions that can be compared"},noVersions:"No comparable versions available",lastVersion:"Previous version",filterMemoed:"Filter versions with comments"}},uV={version:{latest:"\u6700\u65B0",insert:"{name}\u304C\u8FFD\u52A0\u3057\u307E\u3057\u305F",delete:"{name}\u304C\u524A\u9664\u3057\u307E\u3057\u305F",goBack:"\u623B\u308B",revertVersion:"\u5185\u5BB9\u3092\u5FA9\u5143",play:"\u5C65\u6B74\u3092\u518D\u751F",versionList:"\u30D0\u30FC\u30B8\u30E7\u30F3\u5C65\u6B74 {count}",unknown:"\u672A\u77E5\u306E\u30D0\u30FC\u30B8\u30E7\u30F3",restoreFrom:"\u5FA9\u5143\u3055\u308C\u305F\u30D0\u30FC\u30B8\u30E7\u30F3\uFF1A{from}",restoreInfo:"\u5C65\u6B74\u30D0\u30FC\u30B8\u30E7\u30F3\u306F\u4EE5\u524D\u306E\u30D0\u30FC\u30B8\u30E7\u30F3\u3068\u6BD4\u8F03\u3067\u304D\u307E\u305B\u3093\u3002",versionInfoLeft:'<span class="text-1">\u73FE\u5728\u306E\u30D0\u30FC\u30B8\u30E7\u30F3\uFF1A</span><span class="name">{versionName}</span><span class="text-2"> \u3068</span>',versionInfoRight:'<span class="text-3">\u3092\u6BD4\u8F03\u3059\u308B</span>',noSelectedVersion:"\u672A\u9078\u629E",noMemoedVersion:"\u5099\u8003\u306E\u3042\u308B\u30D0\u30FC\u30B8\u30E7\u30F3\u306F\u3042\u308A\u307E\u305B\u3093",noFilterVersion:"\u4E00\u81F4\u3057\u305F\u7D50\u679C\u306F\u3042\u308A\u307E\u305B\u3093",memo:"\u5099\u8003",revert:"\u5FA9\u5143",filter:{all:"\u3059\u3079\u3066",memoed:"\u5099\u8003\u3042\u308A",allVersions:"\u3059\u3079\u3066",memoVersions:"\u5099\u8003\u3042\u308A"},textarea:{placeholder:"\u8AAC\u660E\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"},tooltip:{help:`1. \u5FA9\u5143\u3055\u308C\u305F\u30D0\u30FC\u30B8\u30E7\u30F3\u306F\u305D\u308C\u4EE5\u524D\u306E\u53E4\u3044\u30D0\u30FC\u30B8\u30E7\u30F3\u3068\u6BD4\u8F03\u3067\u304D\u307E\u305B\u3093\u3002
|
|
596
|
-
2. \u4E8C\u3064\u306E\u30D0\u30FC\u30B8\u30E7\u30F3\u306E\u9593\u306B\u5FA9\u5143\u3055\u308C\u305F\u30D0\u30FC\u30B8\u30E7\u30F3\u304C\u3042\u308B\u5834\u5408\u3001\u3053\u306E\u4E8C\u3064\u306E\u30D0\u30FC\u30B8\u30E7\u30F3\u306F\u6BD4\u8F03\u3067\u304D\u306A\u3044\u3053\u3068\u306B\u306A\u308A\u307E\u3059\u3002`,user:"\u30D0\u30FC\u30B8\u30E7\u30F3\u4F5C\u6210\u8005\uFF1A{name}",auth:"\u3053\u306E\u30B9\u30DA\u30FC\u30B9\u3092\u7DE8\u96C6\u3059\u308B\u6A29\u9650\u306F\u3042\u308A\u307E\u305B\u3093\u3002\u7BA1\u7406\u8005\u306B\u3054\u9023\u7D61\u304F\u3060\u3055\u3044\u3002"},dropdownHeader:"\u73FE\u5728\u306E\u30D0\u30FC\u30B8\u30E7\u30F3\u3068\u6BD4\u8F03\u3067\u304D\u308B\u30D0\u30FC\u30B8\u30E7\u30F3\u3060\u3051\u8868\u793A\u3055\u308C\u307E\u3059",dropdown:{header:"\u6BD4\u8F03\u53EF\u80FD\u306A\u30D0\u30FC\u30B8\u30E7\u30F3"},noVersions:"\u6BD4\u8F03\u53EF\u80FD\u306A\u30D0\u30FC\u30B8\u30E7\u30F3\u306F\u3042\u308A\u307E\u305B\u3093",lastVersion:"\u524D\u306E\u30D0\u30FC\u30B8\u30E7\u30F3",filterMemoed:"\u5099\u8003\u3042\u308A"}};R.mergeLang({"zh-CN":cV,"en-US":aV,"ja-JP":uV});var b8=(n=>(n.NEW="history-new",n.NEW_CHILD="history-new-child",n.DELETED="history-deleted",n.UPDATED="history-updated",n.HISTORY="history",n))(b8||{});const Ic="--op-color",Tc="--op-selected-color",Xnt="";class dV{constructor(t){m(this,"root");this.content=t;const e=w("div",["editor-dialog-root"],null);e.append(t),this.root=e}show(t=document.body){t.append(this.root)}hide(){this.root.remove()}destroy(){}}function Xs(n){var e;let t;if(n.version!==-1){const o=new Date((e=n.created)!=null?e:n.version);t=Rm(o,"YYYY-MM-DD hh:mm")}else t=R.t("version.latest");return t}function Xf(n){return n.source&&typeof n.source=="object"&&!!n.source.restore}const tot="";class hV{constructor(t,e){m(this,"textArea");m(this,"warning");m(this,"end",!1);m(this,"root");m(this,"handleBlur",()=>{var t,e;this.end||(e=(t=this.options)==null?void 0:t.onend)==null||e.call(t,this.textArea.value,!1)});m(this,"handleKeyDown",t=>{var e,o,r,i;t.isComposing||(t.key==="Enter"||t.key==="Tab"?(t.preventDefault(),(o=(e=this.options)==null?void 0:e.onend)==null||o.call(e,this.textArea.value,!1),this.end=!0):t.key==="Escape"&&(t.preventDefault(),(i=(r=this.options)==null?void 0:r.onend)==null||i.call(r,this.textArea.value,!0),this.end=!0))});m(this,"handleInput",t=>{const e=t.target,{value:o}=e;o.length>this.maxLength-10?this.warning.innerText=`${o.length}/${this.maxLength}`:this.warning.innerText="",this.autoSize()});var o,r;this.maxLength=t,this.options=e,this.root=w("div",["size-limit-textarea",...(o=e==null?void 0:e.classes)!=null?o:[]],null),this.textArea=w("textarea",["size-limit-textarea-input"],this.root),this.warning=w("div",["size-limit-textarea-warning"],this.root),this.textArea.addEventListener("input",this.handleInput),this.textArea.addEventListener("blur",this.handleBlur),this.textArea.addEventListener("keydown",this.handleKeyDown),this.textArea.maxLength=t,this.textArea.placeholder=(r=e==null?void 0:e.placeholder)!=null?r:""}destroy(){this.textArea.removeEventListener("input",this.handleInput),this.textArea.removeEventListener("blur",this.handleBlur),this.textArea.removeEventListener("keydown",this.handleKeyDown)}setValue(t){this.textArea.value=t,this.autoSize()}autoSize(){const t=Math.max(this.textArea.scrollHeight+2,60);this.textArea.style.height="auto",this.textArea.style.height=`${t}px`}resetSize(){this.textArea.style.height="auto";const t=Math.max(this.textArea.scrollHeight+2,60);this.textArea.style.height=`${t}px`}focus(){this.textArea.focus(),this.end=!1}}const eot="",{t:Qn}=R,v8=S("version-list");class fV{constructor(t){m(this,"versionsList");m(this,"versionsListHeader");m(this,"versionFilterToolbar");m(this,"memoInput",null);m(this,"selectedVersion",0);m(this,"handleClickVersionItem",t=>{const e=t.target,o=e.closest(".version-item");if(!this.isVersionElement(o))return;const r=xt(o,"active");if(r&&e.closest(".version-item-memo")&&this.options.enableEdit){this.editItemMemo(o);return}const i=this.getVersionFromElement(o);if(this.setActiveItem(o),e.closest(".add-memo-button")&&this.options.enableEdit){this.handleAddMemo(i,o);return}if(e.closest(".revert-button")&&this.options.enableEdit){this.handleRevert(i,o);return}if(r)return;const{onSelectVersion:s}=this.options;s(i)});m(this,"handleEndEditItemMemo",(t,e)=>{var r,i;const o=(r=this.memoInput)==null?void 0:r.root.closest(".version-item");if(this.isVersionElement(o)&&(ot(o,"editing"),!e)){const s=this.getVersionFromElement(o),l=t.replace(/[\n\r]+/g," ");if(((i=s.extra)==null?void 0:i.memo)!==l){s.extra={memo:l},this.options.versionHelper.updateVersionExtra(s.version,s.tagId,s.extra).then(()=>{var d,h;(h=(d=this.options).onMemoChanged)==null||h.call(d,s)});const a=o.querySelector(".version-item-memo");g(v8,a,"no memo element"),a.textContent=l}}setTimeout(()=>{var s;(s=this.memoInput)==null||s.root.remove()})});m(this,"handleRevert",(t,e)=>{const{onRevert:o}=this.options;o(t)});m(this,"handleFilterClick",(t,e)=>{let o=this.options.versions;e.id==="memoed"&&(o=o.filter(i=>{var s;return!!((s=i.extra)!=null&&s.memo)}));const r=this.createVersionItems(o,e.id);this.versionsList.innerHTML="",this.versionsList.append(r),this.versionFilterToolbar.updateItems(this.getFilterItems(e.id)),this.updateHeaderCount(o.length)});var d,h;this.options=t;const{versions:e}=t,o=w("div",["version-list-header"],null),r=Qn("version.versionList",{count:`${e.length}`});w("span",["version-count"],o,r);const i=w("div",["version-list-filter"],o);this.versionFilterToolbar=new aM(i,this.getFilterItems("all"),{tooltipId:"version-viewer"}),this.versionFilterToolbar.addListener("click",this.handleFilterClick),this.selectedVersion=t.selectedVersion||((d=e[0])==null?void 0:d.version)||-1;const s=w("div",["version-list-content"],null),l=this.createVersionItems(e,"all");s.append(l),this.versionsList=s,this.versionsListHeader=o,s.onclick=this.handleClickVersionItem;const a=this.activeVersion;a&&((h=this.options)==null||h.onSelectVersion(a))}getFilterItems(t){return[{id:"filter",name:Qn(t==="all"?"version.filter.all":"version.filter.memoed"),dropdown:!0,manualShowChildren:!0,childrenPlacement:"bottom-start",children:[{id:"all",states:t==="all"?["checked"]:[],name:Qn("version.filter.allVersions")},{id:"memoed",states:t==="memoed"?["checked"]:[],name:Qn("version.filter.memoVersions")}]}]}createVersionItems(t,e){const o=document.createDocumentFragment();if(t.length===0){const i=w("div",["version-list-empty"],o);return i.textContent=Qn("version.noMemoedVersion"),o}const r=(i,s,l,a=!1)=>{var x,_;const d=w("div",["version-item"],o);d.versionData=i,s&&W(d,"child"),i.version===this.selectedVersion&&W(d,"active");const h=w("div",["version-item-title"],d);w("div",["version-item-date"],h,Xs(i)),a&&w("div",["version-item-latest"],h,Qn("version.latest")),w("div",["spacer"],h);const p=w("div",["version-actions"],h),A=w("button",["add-memo-button"],p);if(A.textContent=Qn("version.memo"),this.options.enableEdit||(W(A,"disabled"),A.setAttribute("data-editor-tooltip-common",R.t("version.tooltip.auth"))),!a){const M=w("button",["revert-button"],p);M.textContent=Qn("version.revert"),this.options.enableEdit||(W(M,"disabled"),M.setAttribute("data-editor-tooltip-common",R.t("version.tooltip.auth")))}let v="";if(typeof i.source=="object"&&((x=i.source)==null?void 0:x.restore)){const M=i.source.restore,H=this.options.versions.find(q=>q.version==M),z=H?Xs(H):Qn("version.unknown");v=Qn("version.restoreFrom",{from:z})}w("div",["version-item-restore-from"],d,v),w("div",["version-item-memo"],d,((_=i.extra)==null?void 0:_.memo)||"");const B=w("ul",["version-item-authors"],d),D=M=>{const H=w("li",["version-item-author"],B),z=w("span",["version-item-author-mark"],H);z.style.background=this.options.getMarkColor(M),w("span",["version-item-author-name"],H,M.displayName).setAttribute("data-editor-tooltip-common",R.t("version.tooltip.user",{name:M.displayName}))};if(this.options.useCreatedBy)if(i.createdBy){const M=i.createdBy;D(M)}else i.authors&&i.authors.length>0&&i.authors.forEach(M=>{D(M)});else if(i.authors&&i.authors.length>0)i.authors.forEach(M=>{D(M)});else if(i.createdBy){const M=i.createdBy;D(M)}};return t.forEach((i,s)=>{r(i,!1,t,s===0),i.minorVersions&&i.minorVersions.length>0&&i.minorVersions.forEach(l=>{r(l,!0,t,!1)})}),o}isVersionElement(t){return t?xt(t,"version-item"):!1}getVersionFromElement(t){return t.versionData}get activeVersion(){return this.options.versions.find(t=>t.version===this.selectedVersion)}setActiveItem(t){if(xt(t,"active"))return;const e=this.versionsList.querySelector(".version-item.active");e&&ot(e,"active"),W(t,"active"),this.selectedVersion=this.getVersionFromElement(t).version}handleAddMemo(t,e){this.editItemMemo(e)}editItemMemo(t){var o;this.memoInput||(this.memoInput=new hV(256,{onend:this.handleEndEditItemMemo,classes:["memo-input"],placeholder:Qn("version.textarea.placeholder")}));const e=t.querySelector(".version-item-restore-from");g(v8,e,"no title element"),e.insertAdjacentElement("afterend",this.memoInput.root),W(t,"editing"),this.memoInput.setValue(((o=t.versionData.extra)==null?void 0:o.memo)||""),this.memoInput.resetSize(),this.memoInput.focus()}updateHeaderCount(t){const e=this.versionsListHeader.querySelector(".version-count");e&&(e.textContent=Qn("version.versionList",{count:`${t.toString()}`}))}getVersionItemByVersionNum(t){const e=Array.from(this.versionsList.children).find(o=>o.versionData.version===t);return this.isVersionElement(e)?e:null}selectVersionByVersionNum(t){const e=this.getVersionItemByVersionNum(t);return e?(this.setActiveItem(e),this.getVersionFromElement(e)):null}render(t){t.innerHTML="",t.append(this.versionsListHeader,this.versionsList)}destroy(){this.versionsList.onclick=null,this.versionFilterToolbar.destroy()}}class mV{constructor(t,e){this.doc=t,this.user=e}onDeleteBlock(t,e){this.doc.onDeleteBlock(t,e,this.user)}onInsertBlock(t,e,o){this.doc.onInsertBlock(t,e,o,this.user)}onUpdateBlockText(t,e,o){this.doc.onUpdateBlockText(t,e,o,this.user)}onUpdateBlockData(t,e,o){this.doc.onUpdateBlockData(t,e,o,this.user)}onCreateContainer(t,e){this.doc.onCreateContainer(t,e,this.user)}onCreateComment(){}onDeleteComment(){}onDeleteContainer(){}onUpdateComment(){}}async function gV(n,t,e){for(const o of e){const r=new mV(n,o.user);t.parseHistoryData(o,r)}}const bn=S("split-text-actions");function y8(n){return n.length>2?!1:n.length===1?n[0].insert!==void 0:(g(bn,n.length===2,`invalid text actions: ${JSON.stringify(n)}`),n[0].retain===void 0?!1:n[1].insert!==void 0)}function k8(n){return n.length>2?!1:n.length===1?n[0].delete!==void 0:(g(bn,n.length===2,`invalid text actions: ${JSON.stringify(n)}`),n[0].retain===void 0?!1:n[1].delete!==void 0)}function w8(n){return n.length>2?!1:n.length===1?n[0].insert===void 0&&n[0].delete===void 0&&n[0].attributes!==void 0:(g(bn,n.length===2,`invalid text actions: ${JSON.stringify(n)}`),n[0].retain===void 0?!1:n[1].attributes!==void 0)}function pV(n){const t=[],e=mt.default(n);if(e.length===0)return[];if(e.length===1)return[n];if(e.length===2&&(k8(n)||y8(n)||w8(n)))return[n];const o=(i,s)=>i>0?[{retain:i},s]:[s];let r=0;for(;e.length>0;){const i=e[0];if(i.retain!==void 0&&i.attributes===void 0){g(bn,i.retain>0,`invalid text op: ${JSON.stringify(i)}`),g(bn,e.length>1,`invalid text op: ${JSON.stringify(i)}`);const s=e[1];g(bn,s.delete||s.insert!==void 0||s.attributes!==void 0,`invalid next text op: ${JSON.stringify(s)}`),r+=i.retain,t.push(o(r,s)),s.delete!==void 0?r-=s.delete:s.insert!==void 0?r+=s.insert.length:(g(bn,s.attributes!==void 0,`invalid next text op: ${JSON.stringify(s)}`),g(bn,s.retain!==void 0,`invalid next text op: ${JSON.stringify(s)}`),r+=s.retain),e.splice(0,2)}else g(bn,i.delete||i.insert!==void 0||i.attributes!==void 0,`invalid next text op: ${JSON.stringify(i)}`),t.push(o(r,i)),e.shift(),i.retain!==void 0&&(g(bn,i.attributes!==void 0,`invalid next text op: ${JSON.stringify(i)}`),r+=i.retain),i.insert&&(r+=i.insert.length)}return t}function B8(n){if(g(bn,n.length===1||n.length===2,`not a single action op: ${JSON.stringify(n)}`),n.length===1)return 0;const t=n[0].retain;return g(bn,typeof t=="number"&&t>0,`invalid retain: ${JSON.stringify(n)}`),t}let E8=0;function CV(n,t,e){const o=E8;E8+=1;const r=ie(n);return{insert:" ",attributes:{box:!0,id:K(),type:"history-deleted-box",user:e,created:Date.now(),text:r,deletedOffset:t,deletedOrder:o}}}function AV(n,t,e){const o=B8(t),r=t.length===1?t[0].delete:t[1].delete;g(bn,typeof r=="number",`not a delete op: ${JSON.stringify(t)}`);const{left:i,middle:s,right:l}=ze(n,o,r),a=CV(s,o,e);return[...i,a,...l]}function bV(n,t,e){const o=B8(t),r=t.length===1?t[0].insert:t[1].insert;g(bn,typeof r=="string",`invalid insert op: ${JSON.stringify(t)}`);const i=t.length===1?t[0].attributes:t[1].attributes,l=hh([{insert:r,attributes:i}],"insertedBy",e);return Vr(n,o,l,null)}function vV(n,t,e){const o=pV(t);let r=n;for(const i of o)k8(i)?r=AV(r,i,e):y8(i)?r=bV(r,i,e):(g(bn,w8(i),`unknown op: ${JSON.stringify(i)}`),r=ln.apply(r,i));return r}const yV=S("history-update-block-text");function x8(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+=dh(r)}),t.sort((r,i)=>i.offset-r.offset),{deletedBoxes:t,newText:e}}function kV(n,t,e){let o=n;return t.forEach(r=>{const i=ln.transformCursor(r.offset,e,!1);o=Vr(o,i,[{insert:" ",attributes:r.boxData}],null)}),o}function wV(n){n.sort((t,e)=>t.boxData.deletedOffset!==e.boxData.deletedOffset?t.boxData.deletedOffset-e.boxData.deletedOffset:t.boxData.deletedOrder-e.boxData.deletedOrder)}function BV(n){if(n.length<=1)return n;const t=n[0].offset;n.forEach(e=>{g(yV,e.offset===t,`invalid boxes group, ${JSON.stringify(n)}`)}),wV(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 EV(n){let{newText:t,deletedBoxes:e}=x8(n);const o=new Map;return e.forEach(i=>{let s=o.get(i.offset);s||(s=[],o.set(i.offset,s)),s.push(i),s.sort((l,a)=>l.boxData.deletedOffset-a.boxData.deletedOffset)}),Array.from(o.values()).sort((i,s)=>s[0].offset-i[0].offset).forEach(i=>{const s=i[0].offset;BV(i).reverse().forEach(l=>{t=Vr(t,s,[{insert:" ",attributes:l.boxData}],null)})}),t}function xV(n,t,e){let{newText:o,deletedBoxes:r}=x8(n);return o=vV(o,t,e),o=kV(o,r,t),o=EV(o),o}const vr=S("history-doc");function yr(n){g(vr,!1,"no local actions for history doc")}class IV extends ha{constructor(t,e){super(),this.externalDoc=t,this.docObject=e}beginBatchUpdate(){return 0}endBatchUpdate(){return 0}toJSON(){return mt.default(this.docObject)}getContainerBlocks(t){return this.docObject.blocks[t]}getBlockData(t,e){const o=this.getContainerBlocks(t);g(vr,o,`no container data: ${t}`);const r=o[e];return g(vr,r,`no block data: ${e}`),r}localUpdateBlockText(){yr()}localUpdateBlockData(){yr()}localInsertBlock(){yr()}localDeleteBlock(){yr()}localInsertChildContainer(){yr()}localDeleteChildContainers(){yr()}uploadResource(){yr()}async addResources(t){yr()}getServerMeta(){var t,e,o;return(o=(e=(t=this.externalDoc).getServerMeta)==null?void 0:e.call(t))!=null?o:{}}buildResourceUrl(t){return this.externalDoc.buildResourceUrl(t)}request(){yr()}broadcastMessage(){yr()}getUser(){return{permission:"w",userId:"-",displayName:"-",avatarUrl:"-",rainbowIndex:0}}getRemoteUsers(){return new Ph}destroy(){this.clearCallbacks()}transformBlockIndex(t,e,o){const r=this.docObject.blocks[t];g(vr,r,`no container blocks: ${t}`);let i=0;for(let s=0;s<r.length;s++)if(!r[s].deletedBy){if(i===e)return s;i++}return o&&g(vr,!1,`invalid block index: ${e}, blocks: ${JSON.stringify(r)}`),g(vr,i===e,`invalid block index: ${e}, blocks: ${JSON.stringify(r)}`),r.length}onDeleteBlock(t,e,o){const r=this.transformBlockIndex(t,e,!0),s=this.docObject.blocks[t][r];g(vr,!s.deleted,`block has already deleted: ${t}/${e}`),s.deletedBy=o,this.callbacks.forEach(l=>{var a;return(a=l.onUpdateBlockData)==null?void 0:a.call(l,t,r,{insert:{},delete:[]},!0)})}onInsertBlock(t,e,o,r){const i=this.transformBlockIndex(t,e,!1),s=this.docObject.blocks[t],l=mt.default(o);l.insertedBy=r,s.splice(i,0,l),this.callbacks.forEach(a=>{var d;return(d=a.onInsertBlock)==null?void 0:d.call(a,t,i,l,!0)})}onUpdateBlockText(t,e,o,r){const i=this.transformBlockIndex(t,e,!0),l=this.docObject.blocks[t][i];g(vr,!l.deleted,`block has already deleted: ${t}/${e}`);const a=l.text;g(vr,a,`no text for block: ${JSON.stringify(l)}`);const d=xV(a,o,r);l.text=d,this.callbacks.forEach(h=>{var p;return(p=h.onUpdateBlockText)==null?void 0:p.call(h,t,i,o,!0)})}onUpdateBlockData(t,e,o,r){const i=this.transformBlockIndex(t,e,!0),s=this.docObject.blocks[t],l=s[i];g(vr,!l.deleted,`block has already deleted: ${t}/${e}`);const a=mt.default(l);a.updatedBy=r,o.delete.forEach(d=>delete a[d]),Object.entries(o.insert).forEach(([d,h])=>{a[d]=h}),s[i]=a,this.callbacks.forEach(d=>{var h;return(h=d.onUpdateBlockData)==null?void 0:h.call(d,t,i,o,!0)})}onCreateContainer(t,e,o){this.docObject.blocks[t]=mt.default(e),this.callbacks.forEach(r=>{var i;return(i=r.onInsertChildContainer)==null?void 0:i.call(r,t,e,!0)})}}const{t:I8}=R;function Dc(n,t){return t==="insert"?I8("version.insert",{name:n.displayName}):I8("version.delete",{name:n.displayName})}function tl(n,t){const{userId:e}=t;return["flag","selection"].reduce((r,i)=>{const s=n.getRemoteUsers().getFixedUserColor(e,i);return r[i]=s,r},{})}class TV{renderText(t,e,o){if(!o.box&&o.insertedBy){const r=o.insertedBy,{flag:i,selection:s}=tl(t.doc,o.insertedBy);return{classes:["history-inserted-text"],attributes:{"history-inserted-by":r.displayName,"data-op-description":Dc(r,"insert")},styles:{[Ic]:i,[Tc]:s}}}return{}}renderBlock(t,e,o){if(o.deletedBy){const r=o.deletedBy,{flag:i,selection:s}=tl(t.doc,r);return{classes:["history-deleted-block"],attributes:{"history-deleted-by":r.displayName,"data-op-description":Dc(r,"delete")},styles:{[Ic]:i,[Tc]:s}}}if(o.insertedBy){const r=o.insertedBy,{flag:i,selection:s}=tl(t.doc,r);return{classes:["history-inserted-block"],attributes:{"history-inserted-by":r.displayName,"data-op-description":Dc(r,"insert")},styles:{[Ic]:i,[Tc]:s}}}return{}}updateBlock(t,e,o,r){if(r.deletedBy){const i=r.deletedBy,{flag:s,selection:l}=tl(t.doc,i);W(o,"history-deleted-block"),Ud(o,{"history-inserted-by":i.displayName,"data-op-description":Dc(i,"delete")}),bm(o,{[Ic]:s,[Tc]:l});return}if(r.insertedBy){const i=r.insertedBy,{flag:s,selection:l}=tl(t.doc,i);W(o,"history-inserted-block"),Ud(o,{"history-inserted-by":i.displayName,"data-op-description":Dc(i,"insert")}),bm(o,{[Ic]:s,[Tc]:l})}}}const T8=S("history-deleted-box");function DV(n,t,e,o){const r=o;g(T8,r.text,`no text for text box data: ${JSON.stringify(o)}`),g(T8,typeof r.text=="string",`invalid text type for text box data: ${JSON.stringify(o)}`);const i=w("span",["history-deleted-box"],e,r.text),s=r.user,{flag:l,selection:a}=tl(n.doc,s);i.setAttribute("history-deleted-by",s.displayName),i.setAttribute("data-op-description",Dc(s,"delete")),i.style.setProperty(Ic,l),i.style.setProperty(Tc,a)}function SV(n,t,e,o){return t.text}const LV={boxType:"history-deleted-box",updateBoxContent:DV,convertTo:SV},not="",MV=S("versions-dropdown"),D8=(n,t)=>{if(!t)return n;let e="";const o=t.length,r=t.toLocaleLowerCase();let i=0;for(i=0;i<=n.length-o;i){let s=n.substring(i,i+o);if(s.toLocaleLowerCase()===r){i+=o;const l=n.charAt(i);let a=!1;s.endsWith(" ")&&(a=!0,s=s.trimEnd()),e+=`<span class="highlight">${s}${l===" "||a?" ":""}</span>`}else e+=n.charAt(i),i++}return i<n.length&&(e+=n.substring(i)),e};class RV{constructor(t,e){m(this,"dropdown");m(this,"versions",[]);m(this,"currentVersion",null);m(this,"compareWithVersion",null);m(this,"filterMemoed",!1);m(this,"keywords","");m(this,"createFilterMemoedFilterItem",t=>{const e=w("div",["filter-memoed-version-item"],null);t&&w("div",["filter-item-info"],e,R.t("version.dropdown.header"));const o=w("div",["filter-item-input-container"],e),r=w("input",["filter-item-input"],o);r.id="filter-item-input",r.type="checkbox";const i=w("label",["filter-item-label"],o,R.t("version.filterMemoed"));return i.htmlFor=r.id,r.onchange=this.handleInputChange,r.checked=this.filterMemoed,e});m(this,"filterItems",(t,e)=>{var i,s;if(this.keywords=e,!e)return!0;if(t.type==="section"||t.id==="last-version")return!1;const o=e.toLocaleLowerCase();if(t.name.toLocaleLowerCase().indexOf(o)!==-1)return!0;const r=t.data;return!!(r&&((i=r.extra)==null?void 0:i.memo)&&((s=r.extra)==null?void 0:s.memo.toLocaleLowerCase().indexOf(o))!==-1)});m(this,"handleClose",()=>{});m(this,"handleClear",()=>{this.options.onCompareWithVersion(null)});m(this,"handleClickItem",t=>{const e=t.data,o=Xs(e);this.dropdown.setText(o),this.options.onCompareWithVersion(e)});m(this,"handleInputChange",t=>{const e=t.target;this.filterMemoed=e.checked,this.resetItems()});this.options=e,this.dropdown=new Lp(t,{placeholder:R.t("version.noSelectedVersion"),emptyPlaceholder:R.t("version.noFilterVersion"),popupId:"versions-dropdown-popup",header:this.createHeader(),filter:this.filterItems,onClose:this.handleClose,onClickItem:this.handleClickItem,onClear:this.handleClear,highlight:!0})}createHeader(){const t=w("div",["versions-dropdown-header"],null),e=w("span",["versions-dropdown-header-info"],t);e.innerHTML=R.t("version.dropdownHeader");const o=w("span",["versions-dropdown-header-icon"],t);return o.setAttribute("data-editor-tooltip-common",R.t("version.tooltip.help")),o.setAttribute("data-editor-tooltip-placement","right"),o.innerHTML=dv,o.onclick=this.options.onHelp,t}setVersions(t){this.versions=t}setCurrentVersion(t,e){this.dropdown.setText(""),this.dropdown.setLabels([]),e&&(this.dropdown.setText(Xs(e)),(e.version===-1||e.version===this.versions[0].version)&&this.dropdown.setLabels([R.t("version.latest")])),this.currentVersion=t,this.compareWithVersion=e!=null?e:null,this.resetItems()}resetItems(){var A;if(this.versions.length===0)return;const t=this.currentVersion;if(!t)return;const e=t.version===-1?0:this.versions.findIndex(v=>v.version===t.version);g(MV,e!==-1,"version not found");const o=this.versions[0],r=v=>{var H;const B=v.data,D=w("div",["version-item-container"],null),x=w("div",["version-item-line1"],D),_=v.id==="last-version"?R.t("version.lastVersion"):Xs(B),M=w("div",["version-item-name"],x);if(this.keywords?M.innerHTML=D8(_,this.keywords):M.innerText=_,B.version===o.version&&w("div",["version-item-latest"],x,R.t("version.latest")),((H=B.extra)==null?void 0:H.memo)&&v.id!=="last-version"){const z=w("div",["version-item-line2"],D),q=w("div",["version-item-memo"],z,B.extra.memo);this.keywords?q.innerHTML=D8(B.extra.memo,this.keywords):q.innerText=B.extra.memo,q.setAttribute("data-editor-tooltip-common",B.extra.memo),q.setAttribute("data-editor-tooltip-placement","bottom")}return D.onclick=()=>{this.handleClickItem(v),this.dropdown.close()},D},i=[],s=this.versions[e+1],l=s&&!Xf(t);if(l){const v={id:"last-version",name:"Last version",data:s,element:r};i.push(v)}let a=e;for(let v=e-1;v>=0;v-=1){const B=this.versions[v];if(Xf(B))break;a=v}let d=e;if(!Xf(t))for(let v=e+1;v<this.versions.length;v+=1){const B=this.versions[v];if(d=v,Xf(B))break}let h=!1;const p=[];for(let v=a;v<=d;v+=1){const B=this.versions[v];if(B.version!==t.version&&B.version!==(s==null?void 0:s.version)&&(!this.filterMemoed||((A=B.extra)==null?void 0:A.memo))){h=!0;let D=Xs(B),x=`${B.version}`;v===e+1&&(D="Previous version",x="prev-version");const _={id:x,name:D,data:B,element:r};p.push(_)}}if((l||h||this.filterMemoed)&&i.push({id:"filter-memoed",type:"section",name:"",element:this.createFilterMemoedFilterItem(i.length>0&&l),states:["disabled"]}),i.push(...p),!h){const v={id:"no-versions",type:"section",name:"No versions",states:["disabled"],element:w("span",["version-item-empty"],null,R.t("version.noVersions"))};i.push(v)}this.dropdown.updateItems(i)}}class OV{constructor(t,e){m(this,"left");m(this,"right");m(this,"dropdown");const o=w("div",["version-info-container"],t);this.left=w("div",["version-info-left"],o),this.dropdown=new RV(o,e),this.right=w("div",["version-info-right"],o)}setVersion(t,e,o){const r=`<span class="version-item-latest">${R.t("version.latest")}</span>`,i=`${Xs(t)}${o?r:""}`;this.left.innerHTML=R.t("version.versionInfoLeft",{versionName:i}),this.right.innerHTML=R.t("version.versionInfoRight",{versionName:i}),this.dropdown.setCurrentVersion(t,e)}}const ts=S("version-dialog");class S8{constructor(t,e){m(this,"dialog",null);m(this,"oldViewer",null);m(this,"versionOptions");m(this,"versionList",null);m(this,"provider");m(this,"versions",[]);m(this,"components");m(this,"handleRevert",async t=>{var o,r,i;g(ts,this.versionList,"The versionList did not render");const e=t!=null?t:(o=this.versionList)==null?void 0:o.activeVersion;g(ts,e,`The version: ${e} is invalid`),!(((r=this.versionOptions)==null?void 0:r.onBeforeRevert)&&await this.versionOptions.onBeforeRevert(e))&&(await this.versionHelper.revertVersion(e.version),(i=this.dialog)==null||i.hide())});m(this,"handleSelectVersion",t=>{g(ts,t,`The version: ${t} is invalid`),this.viewVersion(t)});m(this,"handleCompareWithVersion",t=>{var o;const e=(o=this.versionList)==null?void 0:o.activeVersion;g(ts,e,"no active version"),this.viewVersion(e,t!=null?t:void 0)});m(this,"handleHelp",()=>{var t,e;(e=(t=this.versionOptions)==null?void 0:t.onHelp)==null||e.call(t)});m(this,"viewVersion",async(t,e)=>{var h,p;const o=this.versions[0].version===t.version;if(this.components.infoHeader.setVersion(t,e,o),this.oldViewer&&(this.oldViewer.destroy(),this.oldViewer=null),!this.versionList)return;(h=this.versionOptions)!=null&&h.onWillChangeVersion&&this.versionOptions.onWillChangeVersion(this,t);const r=e==null?void 0:e.version;let i,s;if(r){const A=Math.min(t.version,r),v=Math.max(t.version,r),B=await this.versionHelper.getHistoryData(v,A);i=B.doc,s=B.historyData}else i=await this.versionHelper.getVersion(t.version),s=[];const{editorContainer:l}=this.components;l.innerHTML="";const a=new IV(this.doc,i),d=this.provider.createHistoryEditor(l,a);d.editorBlockRenders.registerRender(new TV),d.editorBoxes.registerBoxClass(LV),W(d.rootElement,b8.HISTORY);try{await gV(a,this.versionHelper,s)}finally{this.oldViewer=d}(p=this.versionOptions)!=null&&p.onVersionChanged&&this.versionOptions.onVersionChanged(this,d,t)});m(this,"onMemoChanged",t=>{var e,o;(o=(e=this.versionOptions)==null?void 0:e.onMemoChanged)==null||o.call(e,t),this.components.infoHeader.dropdown.resetItems(),this.components.infoHeader.dropdown.setVersions(this.versions)});this.doc=t,this.provider=e;const o=w("div",["version-dialog"],null),r=w("div",["version-viewer"],o),i=new OV(r,{onCompareWithVersion:this.handleCompareWithVersion,onHelp:this.handleHelp}),s=w("div",["version-dialog-editor"],r),l=w("div",["version-list-root"],o);this.components={root:o,editorContainer:s,listContainer:l,infoHeader:i}}get versionHelper(){g(ts,this.doc.getVersionHelper,"Can not get getVersionHelper from doc");const t=this.doc.getVersionHelper();return g(ts,t,"current doc does not support version"),t}get editor(){return this.oldViewer}renderContent(t){var r,i;const{listContainer:e}=this.components;e.innerHTML="";const o=new fV({enableEdit:((r=this.versionOptions)==null?void 0:r.enableEdit)||!1,versions:t,versionHelper:this.versionHelper,useCreatedBy:(i=this.versionOptions)==null?void 0:i.useCreatedBy,onSelectVersion:this.handleSelectVersion,onRevert:this.handleRevert,onMemoChanged:this.onMemoChanged,getMarkColor:s=>{const{flag:l}=tl(this.doc,s);return l}});o.render(e),this.versionList=o}initViewVersion(){var t;if(g(ts,this.versionList,"no versionList"),(t=this.versionOptions)!=null&&t.initSelectedVersion){const{initSelectedVersion:e}=this.versionOptions,o=this.versionList.selectVersionByVersionNum(e);g(ts,o,`version ${e} not found`),this.viewVersion(o)}else{const e=this.versionList.activeVersion;e&&this.viewVersion(e)}}async show(t){if(this.versionOptions={...this.versionOptions,...t},this.versions=await this.versionHelper.getVersions(),this.versionOptions.onVersionsLoaded&&this.versionOptions.onVersionsLoaded(this,this.versions),this.components.infoHeader.dropdown.setVersions(this.versions),this.renderContent(this.versions),this.initViewVersion(),!this.dialog){const{root:e}=this.components;this.dialog=new dV(e)}this.dialog.show(t.container)}destroy(){var t,e;(t=this.dialog)==null||t.destroy(),(e=this.versionList)==null||e.destroy()}}const _V={expandCollapseButton:{expand:"\u5C55\u5F00",collapse:"\u6536\u8D77"}},FV={expandCollapseButton:{expand:"Expand",collapse:"Collapse"}},PV={expandCollapseButton:{expand:"\u5C55\u958B",collapse:"\u7E2E\u5C0F"}};R.mergeLang({"zh-CN":_V,"en-US":FV,"ja-JP":PV});const oot="",NV=S("heading-collapse");function D2(n){var e;const t=Number.parseInt((e=n.getAttribute("data-style-heading"))!=null?e:"",10);return g(NV,t,"not a heading block"),t}function go(n){return!!n.getAttribute("data-style-heading")}function $V(n){return!xt(n,"heading-collapsed")}function el(n){return xt(n,"heading-collapsed")}function L8(n){if(ce(n))return!1;const e=nt(n);return Yt(e)}const HV=S("heading-collapse");function S2(n){g(HV,go(n),"not a heading block");const t=[],e=D2(n);let o=Zt(n);for(;o&&!(go(o)&&D2(o)<=e);)t.push(o),o=Zt(o);return t}function M8(n,t,e=!1){const r=te(t).querySelector(".heading-collapse-button");r&&Ud(r,{[`data-editor-tooltip-${n.clientId}-dynamic`]:e?R.t("expandCollapseButton.expand"):R.t("expandCollapseButton.collapse")})}function R8(n,t){if(!io(t))return;n.selection.selectBlock(t,0);const e=S2(t);M8(n,t,!0),e.forEach(o=>{jC(o)}),W(t,"heading-collapsed")}function Sc(n,t){S2(t).forEach(o=>{UC(o)}),M8(n,t),ot(t,"heading-collapsed")}function jV(n,t){$V(t)?R8(n,t):Sc(n,t)}const UV=[bp,vp,yp,kp,wp,Bp,Ep,xp];function zV(n){const t=w("button",["heading-collapse-button"],null);return t.setAttribute(`data-editor-tooltip-${n.clientId}-dynamic`,R.t("expandCollapseButton.collapse")),t.innerHTML=Qh,t}function O8(n){return Mf(n).querySelector("button.heading-collapse-button")}function _8(n,t){O8(t)||L8(t)||!io(t)||Z0(t,zV(n),-1)}function VV(n){var t;(t=O8(n))==null||t.remove()}function F8(n,t){Mf(t).querySelector("button.heading-collapse-button")||_8(n,t)}function WV(n){const t=D2(n),e=w("button",["heading-marker"],null);return e.innerHTML=UV[t-1],e}function P8(n){return Mf(n).querySelector("button.heading-marker")}function L2(n){P8(n)||L8(n)||!io(n)||Z0(n,WV(n),1)}function N8(n){const t=P8(n);t==null||t.remove()}function $8(n){N8(n),go(n)&&L2(n)}class qV{handleDrop(t,e,o,r){if(Gd(e)||!go(e)||!el(e))return;const i=S2(e);i.unshift(e);const s=i.reverse();let l=null;return t.doc.beginBatchUpdate(),s.forEach((a,d,h)=>{const p=t.getBlockData(a),A=Fi(t.editorBlocks,t.doc.toJSON(),p),v=t.insertDocAt(o,r,A)[0];d===h.length-1&&(l=v)}),t.doc.endBatchUpdate(),t.doc.beginBatchUpdate(),s.forEach(a=>{t.deleteBlock(a)}),t.doc.endBatchUpdate(),l&&R8(t,l),!0}}const GV=S("heading-collapse");class M2{constructor(t){m(this,"handleLoad",()=>{this.showCollapseButtons()});m(this,"handleHoverBlock",(t,e)=>{e&&(ot(e,"hovering-heading"),go(e)&&Yt(nt(e))&&(L2(e),el(e)||VV(e))),t&&go(t)&&Yt(nt(t))&&(W(t,"hovering-heading"),this.editor.readonly||N8(t),_8(this.editor,t))});m(this,"handleClick",(t,e)=>{const o=Hl(e,"button.heading-collapse-button");if(!o)return;const r=et(o);!r||(g(GV,go(r),"not a heading block"),jV(this.editor,r),F8(this.editor,r))});this.editor=t,t.addListener("load",this.handleLoad),t.addListener("click",this.handleClick),Ae.get(t).addListener("change",this.handleHoverBlock),this.showCollapseButtons(),setTimeout(()=>{var o;(o=Lu.find(t))==null||o.addHandler(new qV)})}showCollapseButtons(){const t=pe(this.editor.rootContainer).filter(go);t.length!==0&&(t[0]===xe(this.editor.rootContainer)&&t.splice(0,1),t.forEach(L2))}destroy(){this.editor.removeListener("load",this.handleLoad),this.editor.removeListener("click",this.handleClick)}}function t1(n){const t=n.selection.range;if(t.isCollapsed()||t.start.blockId===t.end.blockId)return;const e=n.getBlockById(t.start.blockId),o=n.getBlockById(t.end.blockId);el(e)&&Sc(n,e),el(o)&&Sc(n,o)}function ZV(n){t1(n);const t=n.getFocusedBlock();!go(t)||el(t)&&Sc(n,t)}function QV(n){t1(n);const t=n.getFocusedBlock();if(!go(t))return;const e=n.selection.range.focus;!e.isSimple()||e.offset===ut(n,t)&&el(t)&&Sc(n,t)}function YV(n){t1(n);const t=n.getFocusedBlock();if(!go(t))return;const e=n.selection.range.focus;!e.isSimple()||e.offset===0&&el(t)&&Sc(n,t)}class JV{handleBeforeKeyDown(t,e){return Bm(e.key)&&t1(t),e.key==="Enter"?(ZV(t),!1):e.key==="Delete"?(QV(t),!1):(e.key==="Backspace"&&YV(t),!1)}}class KV{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(!go(o)){e&&e.delete.includes("heading")&&$8(o);return}xt(o,"hovering-heading")&&F8(this.editor,o),$8(o)}},100)}}function XV(n){return!!n.heading}function H8(n){var e;const t=n.heading;return(e=Number.parseInt(`${t}`,10))!=null?e:1}function j8(n,t,e){var i;const o=Ls(n,t.type);let r="";if(o.convertTo){const s=Wr();r=o.convertTo(n,t,s,"text",[{containerId:"root",blockIndex:0}]),r=r.replace(/\n/g,"").trim()}else r=ie((i=t.text)!=null?i:[]);return{parentNode:e,children:[],text:r,level:H8(t),block:t}}class Nu{constructor(t){m(this,"nodes",[]);this.editor=t}appendBlock(t){const e=this.findParent(H8(t),this.nodes);e?e.children.push(j8(this.editor,t,e)):this.nodes.push(j8(this.editor,t,null))}findParent(t,e){const o=e[e.length-1];if(!o||t<=1)return null;if(o.level===t-1)return o;const r=this.findParent(t,o.children);return r||(o.level<t?o:null)}static buildToc(t,e){const o=new Nu(t),r=e.blocks.root;for(let i=0;i<r.length;i++){const s=r[i];XV(s)&&o.appendBlock(s)}return o}}class es extends ye.TypedEmitter{constructor(e){super();m(this,"toc");m(this,"updateToc",Le.default(()=>{this.updateTocNow()},500));this.editor=e,e.doc.registerCallback(this),setTimeout(()=>{this.updateTocNow()}),this.toc=new Nu(this.editor)}destroy(){this.editor.doc.unregisterCallback(this)}isHeadingBlock(e){return!!e.heading}onInsertBlock(e,o,r,i){e==="root"&&this.isHeadingBlock(r)&&this.updateToc()}onDeleteBlock(e,o,r){e==="root"&&this.updateToc()}onUpdateBlockText(e,o,r,i){if(e!=="root")return;const s=this.editor.doc.getBlockData(e,o);this.isHeadingBlock(s)&&this.updateToc()}onUpdateBlockData(e,o,r,i){if(e!=="root")return;const s=this.editor.doc.getBlockData(e,o);this.isHeadingBlock(s)&&this.updateToc()}static register(e){return e.addCustom("editor-toc",()=>new es(e))}static get(e){return e.getCustom("editor-toc")}updateTocNow(){this.toc=Nu.buildToc(this.editor,this.editor.doc.toJSON()),this.emit("change",this.editor,this.toc)}}const rot="";function tW(n){return n.nodes.length===0?!0:n.nodes.length>1?!1:n.nodes[0].children.length===0}function U8(n,t){t.forEach(e=>{const o=w("div",["toc-node"],n),r=w("div",["toc-title"],o);if(w("span",["toc-text"],r,e.text).setAttribute("data-block-id",e.block.id),e.children.length>0){const s=w("div",["toc-children"],o);U8(s,e.children)}})}function eW(n,t){const e=Hl(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 z8(n,t,e){if(ot(t,"loading"),t.innerHTML="",tW(e)){w("div",["toc-empty-message"],t,R.t("toc.empty"));return}if(e.nodes.length>=1){const[o,...r]=e.nodes,i=[...o.children,...r];U8(t,i)}tp(n,"toc-click-handler",()=>{n.addListener("click",eW)})}class nW{constructor(t){m(this,"handleUpdateToc",(t,e)=>{Array.from(t.rootContainer.querySelectorAll('.embed-block[data-type="editor-block"][data-embed-type="toc"]')).forEach(r=>{const i=r.querySelector(".editor-toc-container");i&&z8(t,i,e)})});this.editor=t,es.register(t).addListener("change",this.handleUpdateToc)}destroy(){es.register(this.editor).removeListener("change",this.handleUpdateToc)}get toc(){return es.register(this.editor).toc}}function oW(n,t){const e=w("div",["editor-toc-container"],t),r=n.addCustom("init-editor-toc",()=>new nW(n)).toc;r.nodes.length===0?W(e,"loading"):z8(n,e,r)}function rW(n,t,e,o){return o==="markdown"?"[toc]":""}function iW(n,t,e){const{data:o}=e;if(!o||o.embedType!=="toc"||!tt(n,t))return null;const r={};return{blockData:{id:K(),type:"embed",embedType:"toc",embedData:r}}}const V8={embedType:"toc",createEmbedContent:oW,convertTo:rW,convertFrom:iW},sW={toc:{empty:"No Toc"}},lW={toc:{empty:"No Toc"}},cW={toc:{empty:"No Toc"}};R.mergeLang({"zh-CN":sW,"en-US":lW,"ja-JP":cW});function aW(n){return!!n.getAttribute("data-style-heading")}function R2(n,t){return aW(t)&&ut(n,t)>0}function uW(n){const t=ro(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=et(i[s]);if(l&&n.rootContainer.contains(l))return l}o+=10}return null}function O2(n,t){let e=t;for(;e&&!R2(n,e);)e=Zt(e);return e}function W8(n){if(ce(n))return!1;const e=nt(n);return Yt(e)}function e1(n,t){let e=t;for(;e&&!R2(n,e);)e=ce(e),e&&W8(e)&&(e=null);return e}const dW=.3;class hW extends ye.TypedEmitter{constructor(e){super();m(this,"scrollContainer");m(this,"scrollEventTarget");m(this,"scrollStatus",{curHeadingBlock:null,previousHeadingBlock:null,nextHeadingBlock:null});m(this,"handleScroll",Le.default(()=>{const e={curHeadingBlock:null,previousHeadingBlock:null,nextHeadingBlock:null};let o=uW(this.editor);if(o&&(o=Um(o)),!o||!this.scrollContainer){this.setStatus(e);return}if(W8(o)&&(o=Zt(o)),!o){this.setStatus(e);return}if(R2(this.editor,o)){e.curHeadingBlock=o,e.previousHeadingBlock=e1(this.editor,o),e.nextHeadingBlock=O2(this.editor,o),this.setStatus(e);return}const r=this.scrollContainer.getBoundingClientRect(),i=O2(this.editor,o);if(i){const l=i.getBoundingClientRect();if(l.top>r.top&&l.top<r.top+r.height*dW){e.curHeadingBlock=i,e.previousHeadingBlock=e1(this.editor,i),e.nextHeadingBlock=O2(this.editor,i),this.setStatus(e);return}e.nextHeadingBlock=i}const s=e1(this.editor,o);s&&(e.curHeadingBlock=s,e.previousHeadingBlock=e1(this.editor,s)),this.setStatus(e)},200));this.editor=e}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=ro(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),this.scrollStatus={curHeadingBlock:null,previousHeadingBlock:null,nextHeadingBlock:null})}destroy(){this.stop(),this.scrollEventTarget=void 0}}class _2{constructor(t,e){m(this,"suggest");m(this,"onClose",()=>{this.editor.focus()});m(this,"onShow",(t,e,o,r)=>{const i=this.editor.getBlockByIndex(e,o);if(!io(i)){const s=et(nt(i));if(s&&Dt(s)==="code")return!1}return!0});m(this,"onClickItem",(t,e,o)=>{const r=e.data,i={id:K(),type:"mention",box:!0,created:Date.now(),iconUrl:r.avatarUrl,text:r.displayName,mentionId:r.userId},s=this.editor.selection.range;if(!s.isCollapsed()||!s.isSimple())return;const l=s.focus,a=this.editor.getBlockById(l.blockId);this.editor.insertBoxToBlock(a,l.offset,i)});m(this,"queryItems",async(t,e)=>(await this.options.queryUsers(this.editor,e)).map(i=>{const s=Jd(i.displayName);return{id:i.userId,name:i.displayName,icon:i.avatarUrl?`<img src="${i.avatarUrl}" class="mention-user-avatar">`:`<span style="background: ${s}" class="mention-user-avatar-string">${Yd(i.displayName,1)}</span>`,element:i.element,data:i,subText:i.email}}));this.editor=t,this.options=e,this.suggest=new Fp(t,{id:"editor-mention",trigger:["@"],autoDeleteTrigger:!0,showLoading:!0,enableFirstBlock:e.enableFirstBlock,onShow:this.onShow,onClickItem:this.onClickItem,queryItems:this.queryItems,onClose:this.onClose})}destroy(){}}S("mathjax-box");function fW(n,t,e,o){const r=o,i=w("a",["mention-container"],e);w("span",["mention-name"],i,`@${r.text}`),i.setAttribute("data-mention-id",r.mentionId)}function mW(n,t,e){}function gW(n,t,e,o){return`@${t.text}`}function pW(){return{abstract:R.t("mention.abstract")}}const F2={boxType:"mention",updateBoxContent:fW,handleClickBox:mW,convertTo:gW,getBoxProperties:pW};function CW(n){const t=w("div",["mention-button-wrap"],null),e=uo("mention-button",R.t("list.mention.tooltip"),nM,[],n.clientId);return t.appendChild(e),t}class AW{constructor(t){m(this,"mentionButton");m(this,"handleHoveringBlock",t=>{var e;!this.editor.isWritable()||(t&&this.shouldBlockShowMention(t)?te(t).appendChild(this.mentionButton):(e=this.mentionButton)==null||e.remove())});m(this,"handleMouseDown",(t,e)=>{e.preventDefault(),e.stopPropagation();const o=et(this.mentionButton);if(!o||!tt(t,o))return;const r=t.selection.range.focus;if(!r.isSimple())return;let i;t.selection.focusedBlock!==o?i=ut(t,o):i=r.offset,setTimeout(()=>{const s=t.insertTextToBlock(o,i,"@");i+=1;const l=ie(In(s,i).left);this.editor.selection.selectBlock(o,i),this.editor.focus(),t.getCustom("mention").suggest.popup(o,i,l,"@")})});m(this,"destroy",()=>{Ae.get(this.editor).removeListener("change",this.handleHoveringBlock)});this.editor=t,this.mentionButton=CW(t),Ae.get(this.editor).addListener("change",this.handleHoveringBlock),t.domEvents.addEventListener(this.mentionButton,"mousedown",this.handleMouseDown)}shouldBlockShowMention(t){if(!tt(this.editor,t)||!Ht(t))return!1;const e=Zn(t);return!(e==="ordered"||e==="unordered")}}const iot="",bW={mention:{abstract:"\u6210\u5458"}},vW={mention:{abstract:"Member"}},yW={mention:{abstract:"\u30E1\u30F3\u30D0\u30FC"}};R.mergeLang({"zh-CN":bW,"en-US":vW,"ja-JP":yW});const kW={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"}},wW={templates:{title:"Choose a template",create:"New template",choose:"All templates",customizedMark:"Custom"}},BW={templates:{title:"\u30C6\u30F3\u30D7\u30EC\u30FC\u30C8\u3092\u9078\u629E",create:"\u30C6\u30F3\u30D7\u30EC\u30FC\u30C8\u3092\u65B0\u898F\u4F5C\u6210",choose:"\u30C6\u30F3\u30D7\u30EC\u30FC\u30C8\u4E00\u89A7",customizedMark:"\u30AB\u30B9\u30BF\u30E0"}};R.mergeLang({"zh-CN":kW,"en-US":wW,"ja-JP":BW});const sot="",EW="data:image/svg+xml;base64,Cjxzdmcgd2lkdGg9IjEyMCIgaGVpZ2h0PSIxMjAiIHZpZXdCb3g9IjAgMCAxMjAgMTIwIiBmaWxsPSJub25lIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgo8cmVjdCB3aWR0aD0iMTIwIiBoZWlnaHQ9IjEyMCIgZmlsbD0id2hpdGUiLz4KPHBhdGggZD0iTTQ4IDU5QzQ4IDU0LjU4MTcgNTEuNTgxNyA1MSA1NiA1MUg5M0M5OC41MjI4IDUxIDEwMyA1NS40NzcyIDEwMyA2MVY4OEMxMDMgOTEuODY2IDk5Ljg2NiA5NSA5NiA5NUg1NkM1MS41ODE3IDk1IDQ4IDkxLjQxODMgNDggODdWNTlaIiBmaWxsPSIjRDZFOUZBIi8+CjxwYXRoIGQ9Ik0xOCA2NEMxOCA2Mi4zNDMxIDE5LjM0MzEgNjEgMjEgNjFINTZDNjAuNDE4MyA2MSA2NCA2NC41ODE3IDY0IDY5VjgzQzY0IDg1LjIwOTEgNjIuMjA5MSA4NyA2MCA4N0gyNkMyMS41ODE3IDg3IDE4IDgzLjQxODMgMTggNzlWNjRaIiBmaWxsPSIjRUFFNEY2Ii8+CjxyZWN0IHg9IjI0IiB5PSIzMSIgd2lkdGg9IjY1IiBoZWlnaHQ9IjUwIiByeD0iNSIgZmlsbD0iIzk5QzdGMiIvPgo8cmVjdCB4PSIzMy41IiB5PSI0MyIgd2lkdGg9IjQ2IiBoZWlnaHQ9IjUiIHJ4PSIyLjUiIGZpbGw9IndoaXRlIi8+CjxyZWN0IHg9IjMzLjUiIHk9IjU0IiB3aWR0aD0iNDYiIGhlaWdodD0iNSIgcng9IjIuNSIgZmlsbD0id2hpdGUiLz4KPHJlY3QgeD0iMjQiIHk9IjMxIiB3aWR0aD0iNjUiIGhlaWdodD0iNTAiIHJ4PSI1IiBzdHJva2U9IiNGOEY4RjgiLz4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik01MCA4NS4yNjhDNTMuODI2MyA4My4wNTg5IDU1LjEzNzMgNzguMTY2MiA1Mi45MjgyIDc0LjMzOThMNjMuMzIwNSA2OC4zMzk4QzY4Ljg0MzMgNzcuOTA1NyA2NS41NjU4IDkwLjEzNzUgNTYgOTUuNjYwNEM0Ni40MzQxIDEwMS4xODMgMzQuMjAyMyA5Ny45MDU3IDI4LjY3OTQgODguMzM5OEwzOS4wNzE3IDgyLjMzOThDNDEuMjgwOSA4Ni4xNjYyIDQ2LjE3MzYgODcuNDc3MiA1MCA4NS4yNjhaIiBmaWxsPSIjQUI5M0RDIi8+CjxyZWN0IHg9IjU5IiB5PSI2NSIgd2lkdGg9IjQyIiBoZWlnaHQ9IjI4IiByeD0iNSIgZmlsbD0id2hpdGUiLz4KPHBhdGggZD0iTTYzIDg4VjczLjA4MDhDNjMgNzEuNzA5NiA2My4zNjE0IDcwLjY4NjcgNjQuMDg0MSA3MC4wMTJDNjQuODI4NyA2OS4zMzczIDY1Ljg1OCA2OSA2Ny4xNzIgNjlIOTIuODYwOUM5NS42MjAzIDY5IDk3IDcwLjM2MDMgOTcgNzMuMDgwOFY4OEg5My41MTc5TDg3LjM3NDkgODAuNjIyQzg3LjA5MDIgODAuMzE3MyA4Ni43NjE3IDgwLjA4ODggODYuMzg5NCA3OS45MzY0Qzg2LjAxNzEgNzkuNzg0MSA4NS42NDQ4IDc5LjcwNzkgODUuMjcyNSA3OS43MDc5Qzg0LjkwMDIgNzkuNzA3OSA4NC41Mjc5IDc5Ljc4NDEgODQuMTU1NiA3OS45MzY0QzgzLjgwNTIgODAuMDg4OCA4My40NTQ4IDgwLjMxNzMgODMuMTA0MyA4MC42MjJMNzYuNzMxNCA4Ni4yMzcxTDc0LjIwMTkgODMuOTUxOUM3My42MzI1IDgzLjQyOTYgNzMuMDA4NCA4My4xNjg0IDcyLjMyOTUgODMuMTY4NEM3MS42NTA2IDgzLjE2ODQgNzEuMDM3NCA4My40Mjk2IDcwLjQ4OTkgODMuOTUxOUw2Ni40NDkzIDg4SDYzWk03NC40NjQ3IDgwLjYyMkM3NS4zNjI2IDgwLjYyMiA3Ni4xNDAxIDgwLjI5NTUgNzYuNzk3MSA3OS42NDI2Qzc3LjQ3NiA3OC45ODk3IDc3LjgxNTUgNzguMjE3MSA3Ny44MTU1IDc3LjMyNDdDNzcuODE1NSA3Ni40MTA3IDc3LjQ3NiA3NS42MzggNzYuNzk3MSA3NS4wMDY5Qzc2LjE0MDEgNzQuMzU0IDc1LjM2MjYgNzQuMDE2NiA3NC40NjQ3IDczLjk5NDhDNzMuNTQ0OSA3My45NTEzIDcyLjc1NjUgNzQuMjY2OSA3Mi4wOTk1IDc0Ljk0MTZDNzEuNDQyNSA3NS42MTYzIDcxLjExNCA3Ni40MTA3IDcxLjExNCA3Ny4zMjQ3QzcxLjExNCA3OC4yMTcxIDcxLjQ0MjUgNzguOTg5NyA3Mi4wOTk1IDc5LjY0MjZDNzIuNzU2NSA4MC4yOTU1IDczLjU0NDkgODAuNjIyIDc0LjQ2NDcgODAuNjIyWiIgZmlsbD0iI0Y3RDA3RiIvPgo8Y2lyY2xlIGN4PSI5NSIgY3k9IjQyIiByPSIyIiBzdHJva2U9IiM1MEMzOTgiIHN0cm9rZS13aWR0aD0iMiIvPgo8cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTk0Ljc1MDEgMjQuNDY4N0wxMDAuNzgxIDI3LjkxNDlMOTQuNzE5IDMxLjQxNDlMOTQuNzUwMSAyNC40Njg3WiIgc3Ryb2tlPSIjNUNBNUVBIiBzdHJva2Utd2lkdGg9IjEuOCIvPgo8cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTEwNSAzOEMxMDUgMzguNTUyMyAxMDUuNDQ4IDM5IDEwNiAzOUMxMDYuNTUyIDM5IDEwNyAzOC41NTIzIDEwNyAzOFYzNkgxMDlDMTA5LjU1MiAzNiAxMTAgMzUuNTUyMyAxMTAgMzVDMTEwIDM0LjQ0NzcgMTA5LjU1MiAzNCAxMDkgMzRIMTA3VjMyQzEwNyAzMS40NDc3IDEwNi41NTIgMzEgMTA2IDMxQzEwNS40NDggMzEgMTA1IDMxLjQ0NzcgMTA1IDMyVjM0SDEwM0MxMDIuNDQ4IDM0IDEwMiAzNC40NDc3IDEwMiAzNUMxMDIgMzUuNTUyMyAxMDIuNDQ4IDM2IDEwMyAzNkgxMDVWMzhaIiBmaWxsPSIjQUI5M0RDIi8+Cjwvc3ZnPgo=",xW="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzcyIiBoZWlnaHQ9IjI3OSIgdmlld0JveD0iMCAwIDM3MiAyNzkiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMF8xMjU2XzM3MTY4KSI+CjxyZWN0IHdpZHRoPSIzNzIiIGhlaWdodD0iMjc5IiBmaWxsPSJ3aGl0ZSIvPgo8cmVjdCB4PSIzOS41NzQ1IiB5PSIzOS41NzQ3IiB3aWR0aD0iMTE4LjcyMyIgaGVpZ2h0PSIxNS44Mjk4IiByeD0iNy45MTQ4OSIgZmlsbD0iI0VBRjNGQyIvPgo8cmVjdCB4PSIzOS41NzQ1IiB5PSI3MS4yMzM5IiB3aWR0aD0iMjkyLjg1MSIgaGVpZ2h0PSI3LjkxNDg5IiByeD0iMy45NTc0NSIgZmlsbD0iI0VBRjNGQyIvPgo8cmVjdCB4PSIzOS41NzQ1IiB5PSI5MS4wMjE1IiB3aWR0aD0iMjkyLjg1MSIgaGVpZ2h0PSI3LjkxNDg5IiByeD0iMy45NTc0NSIgZmlsbD0iI0VBRjNGQyIvPgo8cmVjdCB4PSIzOS41NzQ1IiB5PSIxMTAuODA5IiB3aWR0aD0iMjkyLjg1MSIgaGVpZ2h0PSI3LjkxNDg5IiByeD0iMy45NTc0NSIgZmlsbD0iI0VBRjNGQyIvPgo8cmVjdCB4PSI0MC41NjM4IiB5PSIxMzUuNTQzIiB3aWR0aD0iMjkwLjg3MiIgaGVpZ2h0PSIxMDAuOTE1IiByeD0iMi45NjgwOSIgc3Ryb2tlPSIjRUFGM0ZDIiBzdHJva2Utd2lkdGg9IjEuOTc4NzIiLz4KPHBhdGggZD0iTTM5LjU3NDUgMTM4LjUxMUMzOS41NzQ1IDEzNi4zMjUgNDEuMzQ2MyAxMzQuNTUzIDQzLjUzMTkgMTM0LjU1M0gzMjguNDY4QzMzMC42NTQgMTM0LjU1MyAzMzIuNDI2IDEzNi4zMjUgMzMyLjQyNiAxMzguNTExVjE1Mi4zNjJIMzkuNTc0NVYxMzguNTExWiIgZmlsbD0iI0Q2RTlGQSIvPgo8cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTg3LjA2MzcgMTY5LjE4MUM4Ny4wNjM3IDE2Ny41NDIgODguMzkyNiAxNjYuMjEzIDkwLjAzMTggMTY2LjIxM0gzMTcuNTg1QzMxOS4yMjQgMTY2LjIxMyAzMjAuNTUzIDE2Ny41NDIgMzIwLjU1MyAxNjkuMTgxQzMyMC41NTMgMTcwLjgyIDMxOS4yMjQgMTcyLjE0OSAzMTcuNTg1IDE3Mi4xNDlIOTAuMDMxOEM4OC4zOTI2IDE3Mi4xNDkgODcuMDYzNyAxNzAuODIgODcuMDYzNyAxNjkuMTgxWk0xMDQuODcyIDE5Mi45MjZDMTA0Ljg3MiAxOTEuMjg2IDEwNi4yMDEgMTg5Ljk1NyAxMDcuODQgMTg5Ljk1N0gzMTcuNTg1QzMxOS4yMjQgMTg5Ljk1NyAzMjAuNTUzIDE5MS4yODYgMzIwLjU1MyAxOTIuOTI2QzMyMC41NTMgMTk0LjU2NSAzMTkuMjI0IDE5NS44OTQgMzE3LjU4NSAxOTUuODk0SDEwNy44NEMxMDYuMjAxIDE5NS44OTQgMTA0Ljg3MiAxOTQuNTY1IDEwNC44NzIgMTkyLjkyNlpNMTA3Ljg0IDIxMy43MDJDMTA2LjIwMSAyMTMuNzAyIDEwNC44NzIgMjE1LjAzMSAxMDQuODcyIDIxNi42N0MxMDQuODcyIDIxOC4zMDkgMTA2LjIwMSAyMTkuNjM4IDEwNy44NCAyMTkuNjM4SDMxNy41ODVDMzE5LjIyNCAyMTkuNjM4IDMyMC41NTMgMjE4LjMwOSAzMjAuNTUzIDIxNi42N0MzMjAuNTUzIDIxNS4wMzEgMzE5LjIyNCAyMTMuNzAyIDMxNy41ODUgMjEzLjcwMkgxMDcuODRaIiBmaWxsPSIjRDZFOUZBIi8+CjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJNNTEuNDQ2OCAxNjkuMTgxQzUxLjQ0NjggMTY3LjU0MiA1Mi43NzU2IDE2Ni4yMTMgNTQuNDE0OSAxNjYuMjEzSDYwLjM1MUM2MS45OTAzIDE2Ni4yMTMgNjMuMzE5MSAxNjcuNTQyIDYzLjMxOTEgMTY5LjE4MUM2My4zMTkxIDE3MC44MiA2MS45OTAzIDE3Mi4xNDkgNjAuMzUxIDE3Mi4xNDlINTQuNDE0OUM1Mi43NzU2IDE3Mi4xNDkgNTEuNDQ2OCAxNzAuODIgNTEuNDQ2OCAxNjkuMTgxWk01MS40NDY4IDE5Mi45MjZDNTEuNDQ2OCAxOTEuMjg2IDUyLjc3NTcgMTg5Ljk1NyA1NC40MTQ5IDE4OS45NTdINjAuMzUxMUM2MS45OTAzIDE4OS45NTcgNjMuMzE5MSAxOTEuMjg2IDYzLjMxOTEgMTkyLjkyNkM2My4zMTkxIDE5NC41NjUgNjEuOTkwMyAxOTUuODk0IDYwLjM1MTEgMTk1Ljg5NEg1NC40MTQ5QzUyLjc3NTcgMTk1Ljg5NCA1MS40NDY4IDE5NC41NjUgNTEuNDQ2OCAxOTIuOTI2Wk01NC40MTQ5IDIxMy43MDJDNTIuNzc1NyAyMTMuNzAyIDUxLjQ0NjggMjE1LjAzMSA1MS40NDY4IDIxNi42N0M1MS40NDY4IDIxOC4zMDkgNTIuNzc1NyAyMTkuNjM4IDU0LjQxNDkgMjE5LjYzOEg2MC4zNTExQzYxLjk5MDMgMjE5LjYzOCA2My4zMTkxIDIxOC4zMDkgNjMuMzE5MSAyMTYuNjdDNjMuMzE5MSAyMTUuMDMxIDYxLjk5MDMgMjEzLjcwMiA2MC4zNTExIDIxMy43MDJINTQuNDE0OVoiIGZpbGw9IiM5OUM3RjIiLz4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik02OS4yNTU0IDE2OS4xODFDNjkuMjU1NCAxNjcuNTQyIDcwLjU4NDMgMTY2LjIxMyA3Mi4yMjM1IDE2Ni4yMTNINzguMTU5N0M3OS43OTg5IDE2Ni4yMTMgODEuMTI3OCAxNjcuNTQyIDgxLjEyNzggMTY5LjE4MUM4MS4xMjc4IDE3MC44MiA3OS43OTg5IDE3Mi4xNDkgNzguMTU5NyAxNzIuMTQ5SDcyLjIyMzVDNzAuNTg0MyAxNzIuMTQ5IDY5LjI1NTQgMTcwLjgyIDY5LjI1NTQgMTY5LjE4MVpNNjkuMjU1NCAxOTIuOTI2QzY5LjI1NTQgMTkxLjI4NiA3MC41ODQyIDE4OS45NTcgNzIuMjIzNSAxODkuOTU3SDc4LjE1OTZDNzkuNzk4OSAxODkuOTU3IDgxLjEyNzcgMTkxLjI4NiA4MS4xMjc3IDE5Mi45MjZDODEuMTI3NyAxOTQuNTY1IDc5Ljc5ODkgMTk1Ljg5NCA3OC4xNTk2IDE5NS44OTRINzIuMjIzNUM3MC41ODQyIDE5NS44OTQgNjkuMjU1NCAxOTQuNTY1IDY5LjI1NTQgMTkyLjkyNlpNNzIuMjIzNSAyMTMuNzAyQzcwLjU4NDIgMjEzLjcwMiA2OS4yNTU0IDIxNS4wMzEgNjkuMjU1NCAyMTYuNjdDNjkuMjU1NCAyMTguMzA5IDcwLjU4NDIgMjE5LjYzOCA3Mi4yMjM1IDIxOS42MzhINzguMTU5NkM3OS43OTg5IDIxOS42MzggODEuMTI3NyAyMTguMzA5IDgxLjEyNzcgMjE2LjY3QzgxLjEyNzcgMjE1LjAzMSA3OS43OTg5IDIxMy43MDIgNzguMTU5NiAyMTMuNzAySDcyLjIyMzVaIiBmaWxsPSIjRjdEMDdGIi8+CjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJNOTAuMDMxOCAxODkuOTU4Qzg4LjM5MjYgMTg5Ljk1OCA4Ny4wNjM3IDE5MS4yODYgODcuMDYzNyAxOTIuOTI2Qzg3LjA2MzcgMTk0LjU2NSA4OC4zOTI2IDE5NS44OTQgOTAuMDMxOCAxOTUuODk0SDk1Ljk2OEM5Ny42MDcyIDE5NS44OTQgOTguOTM2MSAxOTQuNTY1IDk4LjkzNjEgMTkyLjkyNkM5OC45MzYxIDE5MS4yODYgOTcuNjA3MiAxODkuOTU4IDk1Ljk2OCAxODkuOTU4SDkwLjAzMThaTTkwLjAzMTkgMjEzLjcwMkM4OC4zOTI3IDIxMy43MDIgODcuMDYzOCAyMTUuMDMxIDg3LjA2MzggMjE2LjY3Qzg3LjA2MzggMjE4LjMwOSA4OC4zOTI3IDIxOS42MzggOTAuMDMxOSAyMTkuNjM4SDk1Ljk2ODFDOTcuNjA3MyAyMTkuNjM4IDk4LjkzNjIgMjE4LjMwOSA5OC45MzYyIDIxNi42N0M5OC45MzYyIDIxNS4wMzEgOTcuNjA3MyAyMTMuNzAyIDk1Ljk2ODEgMjEzLjcwMkg5MC4wMzE5WiIgZmlsbD0iIzkxRDlCRSIvPgo8L2c+CjxkZWZzPgo8Y2xpcFBhdGggaWQ9ImNsaXAwXzEyNTZfMzcxNjgiPgo8cmVjdCB3aWR0aD0iMzcyIiBoZWlnaHQ9IjI3OSIgZmlsbD0id2hpdGUiLz4KPC9jbGlwUGF0aD4KPC9kZWZzPgo8L3N2Zz4K",q8=S("templates");function P2(n){const t=n.rootElement.querySelector(":scope .editor-templates");if(!t)return null;const e=t.querySelector(":scope .editor-templates-cards");return g(q8,e,"no card container"),{root:t,cardContainer:e}}function IW(n){const t=P2(n);if(t)return t.cardContainer.innerHTML="",t;const e=w("div",["editor-templates"],n.rootElement);w("div",["editor-templates-title"],e,R.t("templates.title"));const o=w("div",["editor-templates-cards"],e);return{root:e,cardContainer:o}}function G8(n,t,e,o,r){var p;const i=(p=n.options.componentsOptions)==null?void 0:p.templates,s=w("div",["editor-template-card",...o],null),l=w("div",["editor-template-thumb-container"],s),a=w("img",["editor-template-thumb"],l);a.src=t,a.style.display="none",a.onerror=()=>{var v;const A=(v=i==null?void 0:i.placeHolderImageSrc)!=null?v:xW;a.src!==A&&(a.src=A)},a.onload=()=>{a.style.display=""};const d=w("div",["editor-template-name"],s),h=w("span",[],d,e);return i!=null&&i.showTemplateTitleAttr&&h.setAttribute("title",e),s.onclick=()=>r(s),s}function TW(n,t){return t.thumbnailUrl?t.thumbnailUrl:n.doc.buildResourceUrl("thumbnail.png")}function DW(n,t){const e=TW(n,t);return G8(n,e,t.name,[],async()=>{var r,i;const o=(r=n.options.componentsOptions)==null?void 0:r.templates;await((i=o==null?void 0:o.onApplyTemplate)==null?void 0:i.call(o,n,t)),es.register(n).updateToc()})}function SW(n,t){return G8(n,t,R.t("templates.choose"),["more"],()=>{var o,r;const e=(o=n.options.componentsOptions)==null?void 0:o.templates;(r=e==null?void 0:e.onChooseTemplate)==null||r.call(e,n)})}function LW(n,t){var p,A;const e=(p=n.options.componentsOptions)==null?void 0:p.templates;if(!e)return;const r=Qe(n.rootContainer).getBoundingClientRect().width;let i=1;const s=EW,l=P2(n);if(l){if(t!=null&&t.reset){const v=Array.from(l.cardContainer.children),B=l.cardContainer.firstElementChild;if(g(q8,B,"no first card"),xt(B,"new")||xt(B,"more"))return;const D=window.getComputedStyle(B),x=parseFloat(D.marginLeft),_=parseFloat(D.marginRight),M=B.getBoundingClientRect().width+x+_;i=Math.floor(r/M);const z=Math.max(1,i-1-1),q=v.length-1;v.forEach((rt,ft)=>{ft>z&&ft<q?rt.style.display="none":(ft>=q&&xt(rt,"more"),rt.style.display="")})}return}const a=e.templates,{cardContainer:d}=IW(n);a.forEach((v,B)=>{const D=DW(n,v);if(B>0&&B>=i&&(D.style.display="none"),d.appendChild(D),B===0){const x=window.getComputedStyle(D),_=parseFloat(x.marginLeft),M=parseFloat(x.marginRight),H=D.getBoundingClientRect().width+_+M;i=Math.floor(r/H)-1}});const h=SW(n,s);d.appendChild(h),(A=e==null?void 0:e.onTemplateChooserStatusChanged)==null||A.call(e,n,d,"visible")}const Z8=Le.default(LW,50);function MW(n){var o,r;const t=P2(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 RW(n){const t=n.blocks.root;if(t.length===0)return!0;if(t.length>5)return!1;const e=[...t];e[0].type==="text"&&e[0].heading&&e.splice(0,1);const o=r=>{var i;return r.type!=="text"&&r.type!=="list"?!1:r.text?((i=r.text)==null?void 0:i.length)===0:!0};return e.every(r=>o(r))}function n1(n,t){RW(n.doc.toJSON())?Z8(n,t):(Z8.cancel(),MW(n))}const OW=800;class _W{constructor(t){m(this,"longPressTimeout",0);m(this,"handleSelectionChange",()=>{});m(this,"handleLongPress",t=>{const e=t.touches[0],o=ih(this.editor,e.clientX,e.clientY);!o||console.log(o)});m(this,"handleTouchStart",t=>{t.touches.length===1&&(this.longPressTimeout=window.setTimeout(()=>{this.handleLongPress(t)},OW))});m(this,"handleTouchEnd",t=>{this.longPressTimeout&&(window.clearTimeout(this.longPressTimeout),this.longPressTimeout=0)});this.editor=t,this.editor.addListener("selectionChanged",this.handleSelectionChange),document.addEventListener("touchstart",this.handleTouchStart),document.addEventListener("touchend",this.handleTouchEnd)}destroy(){this.editor.removeListener("selectionChanged",this.handleSelectionChange),document.removeEventListener("touchstart",this.handleTouchStart),document.removeEventListener("touchend",this.handleTouchEnd)}}const FW=`<svg width="24" height="25" viewBox="0 0 24 25" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
596
|
+
2. \u4E8C\u3064\u306E\u30D0\u30FC\u30B8\u30E7\u30F3\u306E\u9593\u306B\u5FA9\u5143\u3055\u308C\u305F\u30D0\u30FC\u30B8\u30E7\u30F3\u304C\u3042\u308B\u5834\u5408\u3001\u3053\u306E\u4E8C\u3064\u306E\u30D0\u30FC\u30B8\u30E7\u30F3\u306F\u6BD4\u8F03\u3067\u304D\u306A\u3044\u3053\u3068\u306B\u306A\u308A\u307E\u3059\u3002`,user:"\u30D0\u30FC\u30B8\u30E7\u30F3\u4F5C\u6210\u8005\uFF1A{name}",auth:"\u3053\u306E\u30B9\u30DA\u30FC\u30B9\u3092\u7DE8\u96C6\u3059\u308B\u6A29\u9650\u306F\u3042\u308A\u307E\u305B\u3093\u3002\u7BA1\u7406\u8005\u306B\u3054\u9023\u7D61\u304F\u3060\u3055\u3044\u3002"},dropdownHeader:"\u73FE\u5728\u306E\u30D0\u30FC\u30B8\u30E7\u30F3\u3068\u6BD4\u8F03\u3067\u304D\u308B\u30D0\u30FC\u30B8\u30E7\u30F3\u3060\u3051\u8868\u793A\u3055\u308C\u307E\u3059",dropdown:{header:"\u6BD4\u8F03\u53EF\u80FD\u306A\u30D0\u30FC\u30B8\u30E7\u30F3"},noVersions:"\u6BD4\u8F03\u53EF\u80FD\u306A\u30D0\u30FC\u30B8\u30E7\u30F3\u306F\u3042\u308A\u307E\u305B\u3093",lastVersion:"\u524D\u306E\u30D0\u30FC\u30B8\u30E7\u30F3",filterMemoed:"\u5099\u8003\u3042\u308A"}};R.mergeLang({"zh-CN":cV,"en-US":aV,"ja-JP":uV});var b8=(n=>(n.NEW="history-new",n.NEW_CHILD="history-new-child",n.DELETED="history-deleted",n.UPDATED="history-updated",n.HISTORY="history",n))(b8||{});const Ic="--op-color",Tc="--op-selected-color",Xnt="";class dV{constructor(t){m(this,"root");this.content=t;const e=w("div",["editor-dialog-root"],null);e.append(t),this.root=e}show(t=document.body){t.append(this.root)}hide(){this.root.remove()}destroy(){}}function Xs(n){var e;let t;if(n.version!==-1){const o=new Date((e=n.created)!=null?e:n.version);t=Rm(o,"YYYY-MM-DD hh:mm")}else t=R.t("version.latest");return t}function Xf(n){return n.source&&typeof n.source=="object"&&!!n.source.restore}const tot="";class hV{constructor(t,e){m(this,"textArea");m(this,"warning");m(this,"end",!1);m(this,"root");m(this,"handleBlur",()=>{var t,e;this.end||(e=(t=this.options)==null?void 0:t.onend)==null||e.call(t,this.textArea.value,!1)});m(this,"handleKeyDown",t=>{var e,o,r,i;t.isComposing||(t.key==="Enter"||t.key==="Tab"?(t.preventDefault(),(o=(e=this.options)==null?void 0:e.onend)==null||o.call(e,this.textArea.value,!1),this.end=!0):t.key==="Escape"&&(t.preventDefault(),(i=(r=this.options)==null?void 0:r.onend)==null||i.call(r,this.textArea.value,!0),this.end=!0))});m(this,"handleInput",t=>{const e=t.target,{value:o}=e;o.length>this.maxLength-10?this.warning.innerText=`${o.length}/${this.maxLength}`:this.warning.innerText="",this.autoSize()});var o,r;this.maxLength=t,this.options=e,this.root=w("div",["size-limit-textarea",...(o=e==null?void 0:e.classes)!=null?o:[]],null),this.textArea=w("textarea",["size-limit-textarea-input"],this.root),this.warning=w("div",["size-limit-textarea-warning"],this.root),this.textArea.addEventListener("input",this.handleInput),this.textArea.addEventListener("blur",this.handleBlur),this.textArea.addEventListener("keydown",this.handleKeyDown),this.textArea.maxLength=t,this.textArea.placeholder=(r=e==null?void 0:e.placeholder)!=null?r:""}destroy(){this.textArea.removeEventListener("input",this.handleInput),this.textArea.removeEventListener("blur",this.handleBlur),this.textArea.removeEventListener("keydown",this.handleKeyDown)}setValue(t){this.textArea.value=t,this.autoSize()}autoSize(){const t=Math.max(this.textArea.scrollHeight+2,60);this.textArea.style.height="auto",this.textArea.style.height=`${t}px`}resetSize(){this.textArea.style.height="auto";const t=Math.max(this.textArea.scrollHeight+2,60);this.textArea.style.height=`${t}px`}focus(){this.textArea.focus(),this.end=!1}}const eot="",{t:Qn}=R,v8=S("version-list");class fV{constructor(t){m(this,"versionsList");m(this,"versionsListHeader");m(this,"versionFilterToolbar");m(this,"memoInput",null);m(this,"selectedVersion",0);m(this,"handleClickVersionItem",t=>{const e=t.target,o=e.closest(".version-item");if(!this.isVersionElement(o))return;const r=xt(o,"active");if(r&&e.closest(".version-item-memo")&&this.options.enableEdit){this.editItemMemo(o);return}const i=this.getVersionFromElement(o);if(this.setActiveItem(o),e.closest(".add-memo-button")&&this.options.enableEdit){this.handleAddMemo(i,o);return}if(e.closest(".revert-button")&&this.options.enableEdit){this.handleRevert(i,o);return}if(r)return;const{onSelectVersion:s}=this.options;s(i)});m(this,"handleEndEditItemMemo",(t,e)=>{var r,i;const o=(r=this.memoInput)==null?void 0:r.root.closest(".version-item");if(this.isVersionElement(o)&&(ot(o,"editing"),!e)){const s=this.getVersionFromElement(o),l=t.replace(/[\n\r]+/g," ");if(((i=s.extra)==null?void 0:i.memo)!==l){s.extra={memo:l},this.options.versionHelper.updateVersionExtra(s.version,s.tagId,s.extra).then(()=>{var d,h;(h=(d=this.options).onMemoChanged)==null||h.call(d,s)});const a=o.querySelector(".version-item-memo");g(v8,a,"no memo element"),a.textContent=l}}setTimeout(()=>{var s;(s=this.memoInput)==null||s.root.remove()})});m(this,"handleRevert",(t,e)=>{const{onRevert:o}=this.options;o(t)});m(this,"handleFilterClick",(t,e)=>{let o=this.options.versions;e.id==="memoed"&&(o=o.filter(i=>{var s;return!!((s=i.extra)!=null&&s.memo)}));const r=this.createVersionItems(o,e.id);this.versionsList.innerHTML="",this.versionsList.append(r),this.versionFilterToolbar.updateItems(this.getFilterItems(e.id)),this.updateHeaderCount(o.length)});var d,h;this.options=t;const{versions:e}=t,o=w("div",["version-list-header"],null),r=Qn("version.versionList",{count:`${e.length}`});w("span",["version-count"],o,r);const i=w("div",["version-list-filter"],o);this.versionFilterToolbar=new aM(i,this.getFilterItems("all"),{tooltipId:"version-viewer"}),this.versionFilterToolbar.addListener("click",this.handleFilterClick),this.selectedVersion=t.selectedVersion||((d=e[0])==null?void 0:d.version)||-1;const s=w("div",["version-list-content"],null),l=this.createVersionItems(e,"all");s.append(l),this.versionsList=s,this.versionsListHeader=o,s.onclick=this.handleClickVersionItem;const a=this.activeVersion;a&&((h=this.options)==null||h.onSelectVersion(a))}getFilterItems(t){return[{id:"filter",name:Qn(t==="all"?"version.filter.all":"version.filter.memoed"),dropdown:!0,manualShowChildren:!0,childrenPlacement:"bottom-start",children:[{id:"all",states:t==="all"?["checked"]:[],name:Qn("version.filter.allVersions")},{id:"memoed",states:t==="memoed"?["checked"]:[],name:Qn("version.filter.memoVersions")}]}]}createVersionItems(t,e){const o=document.createDocumentFragment();if(t.length===0){const i=w("div",["version-list-empty"],o);return i.textContent=Qn("version.noMemoedVersion"),o}const r=(i,s,l,a=!1)=>{var x,_;const d=w("div",["version-item"],o);d.versionData=i,s&&W(d,"child"),i.version===this.selectedVersion&&W(d,"active");const h=w("div",["version-item-title"],d);w("div",["version-item-date"],h,Xs(i)),a&&w("div",["version-item-latest"],h,Qn("version.latest")),w("div",["spacer"],h);const p=w("div",["version-actions"],h),A=w("button",["add-memo-button"],p);if(A.textContent=Qn("version.memo"),this.options.enableEdit||(W(A,"disabled"),A.setAttribute("data-editor-tooltip-common",R.t("version.tooltip.auth"))),!a){const M=w("button",["revert-button"],p);M.textContent=Qn("version.revert"),this.options.enableEdit||(W(M,"disabled"),M.setAttribute("data-editor-tooltip-common",R.t("version.tooltip.auth")))}let v="";if(typeof i.source=="object"&&((x=i.source)==null?void 0:x.restore)){const M=i.source.restore,H=this.options.versions.find(q=>q.version==M),z=H?Xs(H):Qn("version.unknown");v=Qn("version.restoreFrom",{from:z})}w("div",["version-item-restore-from"],d,v),w("div",["version-item-memo"],d,((_=i.extra)==null?void 0:_.memo)||"");const B=w("ul",["version-item-authors"],d),D=M=>{const H=w("li",["version-item-author"],B),z=w("span",["version-item-author-mark"],H);z.style.background=this.options.getMarkColor(M),w("span",["version-item-author-name"],H,M.displayName).setAttribute("data-editor-tooltip-common",R.t("version.tooltip.user",{name:M.displayName}))};if(this.options.useCreatedBy)if(i.createdBy){const M=i.createdBy;D(M)}else i.authors&&i.authors.length>0&&i.authors.forEach(M=>{D(M)});else if(i.authors&&i.authors.length>0)i.authors.forEach(M=>{D(M)});else if(i.createdBy){const M=i.createdBy;D(M)}};return t.forEach((i,s)=>{r(i,!1,t,s===0),i.minorVersions&&i.minorVersions.length>0&&i.minorVersions.forEach(l=>{r(l,!0,t,!1)})}),o}isVersionElement(t){return t?xt(t,"version-item"):!1}getVersionFromElement(t){return t.versionData}get activeVersion(){return this.options.versions.find(t=>t.version===this.selectedVersion)}setActiveItem(t){if(xt(t,"active"))return;const e=this.versionsList.querySelector(".version-item.active");e&&ot(e,"active"),W(t,"active"),this.selectedVersion=this.getVersionFromElement(t).version}handleAddMemo(t,e){this.editItemMemo(e)}editItemMemo(t){var o;this.memoInput||(this.memoInput=new hV(256,{onend:this.handleEndEditItemMemo,classes:["memo-input"],placeholder:Qn("version.textarea.placeholder")}));const e=t.querySelector(".version-item-restore-from");g(v8,e,"no title element"),e.insertAdjacentElement("afterend",this.memoInput.root),W(t,"editing"),this.memoInput.setValue(((o=t.versionData.extra)==null?void 0:o.memo)||""),this.memoInput.resetSize(),this.memoInput.focus()}updateHeaderCount(t){const e=this.versionsListHeader.querySelector(".version-count");e&&(e.textContent=Qn("version.versionList",{count:`${t.toString()}`}))}getVersionItemByVersionNum(t){const e=Array.from(this.versionsList.children).find(o=>o.versionData.version===t);return this.isVersionElement(e)?e:null}selectVersionByVersionNum(t){const e=this.getVersionItemByVersionNum(t);return e?(this.setActiveItem(e),this.getVersionFromElement(e)):null}render(t){t.innerHTML="",t.append(this.versionsListHeader,this.versionsList)}destroy(){this.versionsList.onclick=null,this.versionFilterToolbar.destroy()}}class mV{constructor(t,e){this.doc=t,this.user=e}onDeleteBlock(t,e){this.doc.onDeleteBlock(t,e,this.user)}onInsertBlock(t,e,o){this.doc.onInsertBlock(t,e,o,this.user)}onUpdateBlockText(t,e,o){this.doc.onUpdateBlockText(t,e,o,this.user)}onUpdateBlockData(t,e,o){this.doc.onUpdateBlockData(t,e,o,this.user)}onCreateContainer(t,e){this.doc.onCreateContainer(t,e,this.user)}onCreateComment(){}onDeleteComment(){}onDeleteContainer(){}onUpdateComment(){}}async function gV(n,t,e){for(const o of e){const r=new mV(n,o.user);t.parseHistoryData(o,r)}}const bn=S("split-text-actions");function y8(n){return n.length>2?!1:n.length===1?n[0].insert!==void 0:(g(bn,n.length===2,`invalid text actions: ${JSON.stringify(n)}`),n[0].retain===void 0?!1:n[1].insert!==void 0)}function k8(n){return n.length>2?!1:n.length===1?n[0].delete!==void 0:(g(bn,n.length===2,`invalid text actions: ${JSON.stringify(n)}`),n[0].retain===void 0?!1:n[1].delete!==void 0)}function w8(n){return n.length>2?!1:n.length===1?n[0].insert===void 0&&n[0].delete===void 0&&n[0].attributes!==void 0:(g(bn,n.length===2,`invalid text actions: ${JSON.stringify(n)}`),n[0].retain===void 0?!1:n[1].attributes!==void 0)}function pV(n){const t=[],e=mt.default(n);if(e.length===0)return[];if(e.length===1)return[n];if(e.length===2&&(k8(n)||y8(n)||w8(n)))return[n];const o=(i,s)=>i>0?[{retain:i},s]:[s];let r=0;for(;e.length>0;){const i=e[0];if(i.retain!==void 0&&i.attributes===void 0){g(bn,i.retain>0,`invalid text op: ${JSON.stringify(i)}`),g(bn,e.length>1,`invalid text op: ${JSON.stringify(i)}`);const s=e[1];g(bn,s.delete||s.insert!==void 0||s.attributes!==void 0,`invalid next text op: ${JSON.stringify(s)}`),r+=i.retain,t.push(o(r,s)),s.delete!==void 0?r-=s.delete:s.insert!==void 0?r+=s.insert.length:(g(bn,s.attributes!==void 0,`invalid next text op: ${JSON.stringify(s)}`),g(bn,s.retain!==void 0,`invalid next text op: ${JSON.stringify(s)}`),r+=s.retain),e.splice(0,2)}else g(bn,i.delete||i.insert!==void 0||i.attributes!==void 0,`invalid next text op: ${JSON.stringify(i)}`),t.push(o(r,i)),e.shift(),i.retain!==void 0&&(g(bn,i.attributes!==void 0,`invalid next text op: ${JSON.stringify(i)}`),r+=i.retain),i.insert&&(r+=i.insert.length)}return t}function B8(n){if(g(bn,n.length===1||n.length===2,`not a single action op: ${JSON.stringify(n)}`),n.length===1)return 0;const t=n[0].retain;return g(bn,typeof t=="number"&&t>0,`invalid retain: ${JSON.stringify(n)}`),t}let E8=0;function CV(n,t,e){const o=E8;E8+=1;const r=ie(n);return{insert:" ",attributes:{box:!0,id:K(),type:"history-deleted-box",user:e,created:Date.now(),text:r,deletedOffset:t,deletedOrder:o}}}function AV(n,t,e){const o=B8(t),r=t.length===1?t[0].delete:t[1].delete;g(bn,typeof r=="number",`not a delete op: ${JSON.stringify(t)}`);const{left:i,middle:s,right:l}=ze(n,o,r),a=CV(s,o,e);return[...i,a,...l]}function bV(n,t,e){const o=B8(t),r=t.length===1?t[0].insert:t[1].insert;g(bn,typeof r=="string",`invalid insert op: ${JSON.stringify(t)}`);const i=t.length===1?t[0].attributes:t[1].attributes,l=hh([{insert:r,attributes:i}],"insertedBy",e);return Vr(n,o,l,null)}function vV(n,t,e){const o=pV(t);let r=n;for(const i of o)k8(i)?r=AV(r,i,e):y8(i)?r=bV(r,i,e):(g(bn,w8(i),`unknown op: ${JSON.stringify(i)}`),r=ln.apply(r,i));return r}const yV=S("history-update-block-text");function x8(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+=dh(r)}),t.sort((r,i)=>i.offset-r.offset),{deletedBoxes:t,newText:e}}function kV(n,t,e){let o=n;return t.forEach(r=>{const i=ln.transformCursor(r.offset,e,!1);o=Vr(o,i,[{insert:" ",attributes:r.boxData}],null)}),o}function wV(n){n.sort((t,e)=>t.boxData.deletedOffset!==e.boxData.deletedOffset?t.boxData.deletedOffset-e.boxData.deletedOffset:t.boxData.deletedOrder-e.boxData.deletedOrder)}function BV(n){if(n.length<=1)return n;const t=n[0].offset;n.forEach(e=>{g(yV,e.offset===t,`invalid boxes group, ${JSON.stringify(n)}`)}),wV(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 EV(n){let{newText:t,deletedBoxes:e}=x8(n);const o=new Map;return e.forEach(i=>{let s=o.get(i.offset);s||(s=[],o.set(i.offset,s)),s.push(i),s.sort((l,a)=>l.boxData.deletedOffset-a.boxData.deletedOffset)}),Array.from(o.values()).sort((i,s)=>s[0].offset-i[0].offset).forEach(i=>{const s=i[0].offset;BV(i).reverse().forEach(l=>{t=Vr(t,s,[{insert:" ",attributes:l.boxData}],null)})}),t}function xV(n,t,e){let{newText:o,deletedBoxes:r}=x8(n);return o=vV(o,t,e),o=kV(o,r,t),o=EV(o),o}const yr=S("history-doc");function kr(n){g(yr,!1,"no local actions for history doc")}class IV extends ha{constructor(t,e){super(),this.externalDoc=t,this.docObject=e}beginBatchUpdate(){return 0}endBatchUpdate(){return 0}toJSON(){return mt.default(this.docObject)}getContainerBlocks(t){return this.docObject.blocks[t]}getBlockData(t,e){const o=this.getContainerBlocks(t);g(yr,o,`no container data: ${t}`);const r=o[e];return g(yr,r,`no block data: ${e}`),r}localUpdateBlockText(){kr()}localUpdateBlockData(){kr()}localInsertBlock(){kr()}localDeleteBlock(){kr()}localInsertChildContainer(){kr()}localDeleteChildContainers(){kr()}uploadResource(){kr()}async addResources(t){kr()}getServerMeta(){var t,e,o;return(o=(e=(t=this.externalDoc).getServerMeta)==null?void 0:e.call(t))!=null?o:{}}buildResourceUrl(t){return this.externalDoc.buildResourceUrl(t)}request(){kr()}broadcastMessage(){kr()}getUser(){return{permission:"w",userId:"-",displayName:"-",avatarUrl:"-",rainbowIndex:0}}getRemoteUsers(){return new Ph}destroy(){this.clearCallbacks()}transformBlockIndex(t,e,o){const r=this.docObject.blocks[t];g(yr,r,`no container blocks: ${t}`);let i=0;for(let s=0;s<r.length;s++)if(!r[s].deletedBy){if(i===e)return s;i++}return o&&g(yr,!1,`invalid block index: ${e}, blocks: ${JSON.stringify(r)}`),g(yr,i===e,`invalid block index: ${e}, blocks: ${JSON.stringify(r)}`),r.length}onDeleteBlock(t,e,o){const r=this.transformBlockIndex(t,e,!0),s=this.docObject.blocks[t][r];g(yr,!s.deleted,`block has already deleted: ${t}/${e}`),s.deletedBy=o,this.callbacks.forEach(l=>{var a;return(a=l.onUpdateBlockData)==null?void 0:a.call(l,t,r,{insert:{},delete:[]},!0)})}onInsertBlock(t,e,o,r){const i=this.transformBlockIndex(t,e,!1),s=this.docObject.blocks[t],l=mt.default(o);l.insertedBy=r,s.splice(i,0,l),this.callbacks.forEach(a=>{var d;return(d=a.onInsertBlock)==null?void 0:d.call(a,t,i,l,!0)})}onUpdateBlockText(t,e,o,r){const i=this.transformBlockIndex(t,e,!0),l=this.docObject.blocks[t][i];g(yr,!l.deleted,`block has already deleted: ${t}/${e}`);const a=l.text;g(yr,a,`no text for block: ${JSON.stringify(l)}`);const d=xV(a,o,r);l.text=d,this.callbacks.forEach(h=>{var p;return(p=h.onUpdateBlockText)==null?void 0:p.call(h,t,i,o,!0)})}onUpdateBlockData(t,e,o,r){const i=this.transformBlockIndex(t,e,!0),s=this.docObject.blocks[t],l=s[i];g(yr,!l.deleted,`block has already deleted: ${t}/${e}`);const a=mt.default(l);a.updatedBy=r,o.delete.forEach(d=>delete a[d]),Object.entries(o.insert).forEach(([d,h])=>{a[d]=h}),s[i]=a,this.callbacks.forEach(d=>{var h;return(h=d.onUpdateBlockData)==null?void 0:h.call(d,t,i,o,!0)})}onCreateContainer(t,e,o){this.docObject.blocks[t]=mt.default(e),this.callbacks.forEach(r=>{var i;return(i=r.onInsertChildContainer)==null?void 0:i.call(r,t,e,!0)})}}const{t:I8}=R;function Dc(n,t){return t==="insert"?I8("version.insert",{name:n.displayName}):I8("version.delete",{name:n.displayName})}function tl(n,t){const{userId:e}=t;return["flag","selection"].reduce((r,i)=>{const s=n.getRemoteUsers().getFixedUserColor(e,i);return r[i]=s,r},{})}class TV{renderText(t,e,o){if(!o.box&&o.insertedBy){const r=o.insertedBy,{flag:i,selection:s}=tl(t.doc,o.insertedBy);return{classes:["history-inserted-text"],attributes:{"history-inserted-by":r.displayName,"data-op-description":Dc(r,"insert")},styles:{[Ic]:i,[Tc]:s}}}return{}}renderBlock(t,e,o){if(o.deletedBy){const r=o.deletedBy,{flag:i,selection:s}=tl(t.doc,r);return{classes:["history-deleted-block"],attributes:{"history-deleted-by":r.displayName,"data-op-description":Dc(r,"delete")},styles:{[Ic]:i,[Tc]:s}}}if(o.insertedBy){const r=o.insertedBy,{flag:i,selection:s}=tl(t.doc,r);return{classes:["history-inserted-block"],attributes:{"history-inserted-by":r.displayName,"data-op-description":Dc(r,"insert")},styles:{[Ic]:i,[Tc]:s}}}return{}}updateBlock(t,e,o,r){if(r.deletedBy){const i=r.deletedBy,{flag:s,selection:l}=tl(t.doc,i);W(o,"history-deleted-block"),Ud(o,{"history-inserted-by":i.displayName,"data-op-description":Dc(i,"delete")}),bm(o,{[Ic]:s,[Tc]:l});return}if(r.insertedBy){const i=r.insertedBy,{flag:s,selection:l}=tl(t.doc,i);W(o,"history-inserted-block"),Ud(o,{"history-inserted-by":i.displayName,"data-op-description":Dc(i,"insert")}),bm(o,{[Ic]:s,[Tc]:l})}}}const T8=S("history-deleted-box");function DV(n,t,e,o){const r=o;g(T8,r.text,`no text for text box data: ${JSON.stringify(o)}`),g(T8,typeof r.text=="string",`invalid text type for text box data: ${JSON.stringify(o)}`);const i=w("span",["history-deleted-box"],e,r.text),s=r.user,{flag:l,selection:a}=tl(n.doc,s);i.setAttribute("history-deleted-by",s.displayName),i.setAttribute("data-op-description",Dc(s,"delete")),i.style.setProperty(Ic,l),i.style.setProperty(Tc,a)}function SV(n,t,e,o){return t.text}const LV={boxType:"history-deleted-box",updateBoxContent:DV,convertTo:SV},not="",MV=S("versions-dropdown"),D8=(n,t)=>{if(!t)return n;let e="";const o=t.length,r=t.toLocaleLowerCase();let i=0;for(i=0;i<=n.length-o;i){let s=n.substring(i,i+o);if(s.toLocaleLowerCase()===r){i+=o;const l=n.charAt(i);let a=!1;s.endsWith(" ")&&(a=!0,s=s.trimEnd()),e+=`<span class="highlight">${s}${l===" "||a?" ":""}</span>`}else e+=n.charAt(i),i++}return i<n.length&&(e+=n.substring(i)),e};class RV{constructor(t,e){m(this,"dropdown");m(this,"versions",[]);m(this,"currentVersion",null);m(this,"compareWithVersion",null);m(this,"filterMemoed",!1);m(this,"keywords","");m(this,"createFilterMemoedFilterItem",t=>{const e=w("div",["filter-memoed-version-item"],null);t&&w("div",["filter-item-info"],e,R.t("version.dropdown.header"));const o=w("div",["filter-item-input-container"],e),r=w("input",["filter-item-input"],o);r.id="filter-item-input",r.type="checkbox";const i=w("label",["filter-item-label"],o,R.t("version.filterMemoed"));return i.htmlFor=r.id,r.onchange=this.handleInputChange,r.checked=this.filterMemoed,e});m(this,"filterItems",(t,e)=>{var i,s;if(this.keywords=e,!e)return!0;if(t.type==="section"||t.id==="last-version")return!1;const o=e.toLocaleLowerCase();if(t.name.toLocaleLowerCase().indexOf(o)!==-1)return!0;const r=t.data;return!!(r&&((i=r.extra)==null?void 0:i.memo)&&((s=r.extra)==null?void 0:s.memo.toLocaleLowerCase().indexOf(o))!==-1)});m(this,"handleClose",()=>{});m(this,"handleClear",()=>{this.options.onCompareWithVersion(null)});m(this,"handleClickItem",t=>{const e=t.data,o=Xs(e);this.dropdown.setText(o),this.options.onCompareWithVersion(e)});m(this,"handleInputChange",t=>{const e=t.target;this.filterMemoed=e.checked,this.resetItems()});this.options=e,this.dropdown=new Lp(t,{placeholder:R.t("version.noSelectedVersion"),emptyPlaceholder:R.t("version.noFilterVersion"),popupId:"versions-dropdown-popup",header:this.createHeader(),filter:this.filterItems,onClose:this.handleClose,onClickItem:this.handleClickItem,onClear:this.handleClear,highlight:!0})}createHeader(){const t=w("div",["versions-dropdown-header"],null),e=w("span",["versions-dropdown-header-info"],t);e.innerHTML=R.t("version.dropdownHeader");const o=w("span",["versions-dropdown-header-icon"],t);return o.setAttribute("data-editor-tooltip-common",R.t("version.tooltip.help")),o.setAttribute("data-editor-tooltip-placement","right"),o.innerHTML=dv,o.onclick=this.options.onHelp,t}setVersions(t){this.versions=t}setCurrentVersion(t,e){this.dropdown.setText(""),this.dropdown.setLabels([]),e&&(this.dropdown.setText(Xs(e)),(e.version===-1||e.version===this.versions[0].version)&&this.dropdown.setLabels([R.t("version.latest")])),this.currentVersion=t,this.compareWithVersion=e!=null?e:null,this.resetItems()}resetItems(){var A;if(this.versions.length===0)return;const t=this.currentVersion;if(!t)return;const e=t.version===-1?0:this.versions.findIndex(v=>v.version===t.version);g(MV,e!==-1,"version not found");const o=this.versions[0],r=v=>{var H;const B=v.data,D=w("div",["version-item-container"],null),x=w("div",["version-item-line1"],D),_=v.id==="last-version"?R.t("version.lastVersion"):Xs(B),M=w("div",["version-item-name"],x);if(this.keywords?M.innerHTML=D8(_,this.keywords):M.innerText=_,B.version===o.version&&w("div",["version-item-latest"],x,R.t("version.latest")),((H=B.extra)==null?void 0:H.memo)&&v.id!=="last-version"){const z=w("div",["version-item-line2"],D),q=w("div",["version-item-memo"],z,B.extra.memo);this.keywords?q.innerHTML=D8(B.extra.memo,this.keywords):q.innerText=B.extra.memo,q.setAttribute("data-editor-tooltip-common",B.extra.memo),q.setAttribute("data-editor-tooltip-placement","bottom")}return D.onclick=()=>{this.handleClickItem(v),this.dropdown.close()},D},i=[],s=this.versions[e+1],l=s&&!Xf(t);if(l){const v={id:"last-version",name:"Last version",data:s,element:r};i.push(v)}let a=e;for(let v=e-1;v>=0;v-=1){const B=this.versions[v];if(Xf(B))break;a=v}let d=e;if(!Xf(t))for(let v=e+1;v<this.versions.length;v+=1){const B=this.versions[v];if(d=v,Xf(B))break}let h=!1;const p=[];for(let v=a;v<=d;v+=1){const B=this.versions[v];if(B.version!==t.version&&B.version!==(s==null?void 0:s.version)&&(!this.filterMemoed||((A=B.extra)==null?void 0:A.memo))){h=!0;let D=Xs(B),x=`${B.version}`;v===e+1&&(D="Previous version",x="prev-version");const _={id:x,name:D,data:B,element:r};p.push(_)}}if((l||h||this.filterMemoed)&&i.push({id:"filter-memoed",type:"section",name:"",element:this.createFilterMemoedFilterItem(i.length>0&&l),states:["disabled"]}),i.push(...p),!h){const v={id:"no-versions",type:"section",name:"No versions",states:["disabled"],element:w("span",["version-item-empty"],null,R.t("version.noVersions"))};i.push(v)}this.dropdown.updateItems(i)}}class OV{constructor(t,e){m(this,"left");m(this,"right");m(this,"dropdown");const o=w("div",["version-info-container"],t);this.left=w("div",["version-info-left"],o),this.dropdown=new RV(o,e),this.right=w("div",["version-info-right"],o)}setVersion(t,e,o){const r=`<span class="version-item-latest">${R.t("version.latest")}</span>`,i=`${Xs(t)}${o?r:""}`;this.left.innerHTML=R.t("version.versionInfoLeft",{versionName:i}),this.right.innerHTML=R.t("version.versionInfoRight",{versionName:i}),this.dropdown.setCurrentVersion(t,e)}}const ts=S("version-dialog");class S8{constructor(t,e){m(this,"dialog",null);m(this,"oldViewer",null);m(this,"versionOptions");m(this,"versionList",null);m(this,"provider");m(this,"versions",[]);m(this,"components");m(this,"handleRevert",async t=>{var o,r,i;g(ts,this.versionList,"The versionList did not render");const e=t!=null?t:(o=this.versionList)==null?void 0:o.activeVersion;g(ts,e,`The version: ${e} is invalid`),!(((r=this.versionOptions)==null?void 0:r.onBeforeRevert)&&await this.versionOptions.onBeforeRevert(e))&&(await this.versionHelper.revertVersion(e.version),(i=this.dialog)==null||i.hide())});m(this,"handleSelectVersion",t=>{g(ts,t,`The version: ${t} is invalid`),this.viewVersion(t)});m(this,"handleCompareWithVersion",t=>{var o;const e=(o=this.versionList)==null?void 0:o.activeVersion;g(ts,e,"no active version"),this.viewVersion(e,t!=null?t:void 0)});m(this,"handleHelp",()=>{var t,e;(e=(t=this.versionOptions)==null?void 0:t.onHelp)==null||e.call(t)});m(this,"viewVersion",async(t,e)=>{var h,p;const o=this.versions[0].version===t.version;if(this.components.infoHeader.setVersion(t,e,o),this.oldViewer&&(this.oldViewer.destroy(),this.oldViewer=null),!this.versionList)return;(h=this.versionOptions)!=null&&h.onWillChangeVersion&&this.versionOptions.onWillChangeVersion(this,t);const r=e==null?void 0:e.version;let i,s;if(r){const A=Math.min(t.version,r),v=Math.max(t.version,r),B=await this.versionHelper.getHistoryData(v,A);i=B.doc,s=B.historyData}else i=await this.versionHelper.getVersion(t.version),s=[];const{editorContainer:l}=this.components;l.innerHTML="";const a=new IV(this.doc,i),d=this.provider.createHistoryEditor(l,a);d.editorBlockRenders.registerRender(new TV),d.editorBoxes.registerBoxClass(LV),W(d.rootElement,b8.HISTORY);try{await gV(a,this.versionHelper,s)}finally{this.oldViewer=d}(p=this.versionOptions)!=null&&p.onVersionChanged&&this.versionOptions.onVersionChanged(this,d,t)});m(this,"onMemoChanged",t=>{var e,o;(o=(e=this.versionOptions)==null?void 0:e.onMemoChanged)==null||o.call(e,t),this.components.infoHeader.dropdown.resetItems(),this.components.infoHeader.dropdown.setVersions(this.versions)});this.doc=t,this.provider=e;const o=w("div",["version-dialog"],null),r=w("div",["version-viewer"],o),i=new OV(r,{onCompareWithVersion:this.handleCompareWithVersion,onHelp:this.handleHelp}),s=w("div",["version-dialog-editor"],r),l=w("div",["version-list-root"],o);this.components={root:o,editorContainer:s,listContainer:l,infoHeader:i}}get versionHelper(){g(ts,this.doc.getVersionHelper,"Can not get getVersionHelper from doc");const t=this.doc.getVersionHelper();return g(ts,t,"current doc does not support version"),t}get editor(){return this.oldViewer}renderContent(t){var r,i;const{listContainer:e}=this.components;e.innerHTML="";const o=new fV({enableEdit:((r=this.versionOptions)==null?void 0:r.enableEdit)||!1,versions:t,versionHelper:this.versionHelper,useCreatedBy:(i=this.versionOptions)==null?void 0:i.useCreatedBy,onSelectVersion:this.handleSelectVersion,onRevert:this.handleRevert,onMemoChanged:this.onMemoChanged,getMarkColor:s=>{const{flag:l}=tl(this.doc,s);return l}});o.render(e),this.versionList=o}initViewVersion(){var t;if(g(ts,this.versionList,"no versionList"),(t=this.versionOptions)!=null&&t.initSelectedVersion){const{initSelectedVersion:e}=this.versionOptions,o=this.versionList.selectVersionByVersionNum(e);g(ts,o,`version ${e} not found`),this.viewVersion(o)}else{const e=this.versionList.activeVersion;e&&this.viewVersion(e)}}async show(t){if(this.versionOptions={...this.versionOptions,...t},this.versions=await this.versionHelper.getVersions(),this.versionOptions.onVersionsLoaded&&this.versionOptions.onVersionsLoaded(this,this.versions),this.components.infoHeader.dropdown.setVersions(this.versions),this.renderContent(this.versions),this.initViewVersion(),!this.dialog){const{root:e}=this.components;this.dialog=new dV(e)}this.dialog.show(t.container)}destroy(){var t,e;(t=this.dialog)==null||t.destroy(),(e=this.versionList)==null||e.destroy()}}const _V={expandCollapseButton:{expand:"\u5C55\u5F00",collapse:"\u6536\u8D77"}},FV={expandCollapseButton:{expand:"Expand",collapse:"Collapse"}},PV={expandCollapseButton:{expand:"\u5C55\u958B",collapse:"\u7E2E\u5C0F"}};R.mergeLang({"zh-CN":_V,"en-US":FV,"ja-JP":PV});const oot="",NV=S("heading-collapse");function D2(n){var e;const t=Number.parseInt((e=n.getAttribute("data-style-heading"))!=null?e:"",10);return g(NV,t,"not a heading block"),t}function go(n){return!!n.getAttribute("data-style-heading")}function $V(n){return!xt(n,"heading-collapsed")}function el(n){return xt(n,"heading-collapsed")}function L8(n){if(ce(n))return!1;const e=nt(n);return Yt(e)}const HV=S("heading-collapse");function S2(n){g(HV,go(n),"not a heading block");const t=[],e=D2(n);let o=Zt(n);for(;o&&!(go(o)&&D2(o)<=e);)t.push(o),o=Zt(o);return t}function M8(n,t,e=!1){const r=te(t).querySelector(".heading-collapse-button");r&&Ud(r,{[`data-editor-tooltip-${n.clientId}-dynamic`]:e?R.t("expandCollapseButton.expand"):R.t("expandCollapseButton.collapse")})}function R8(n,t){if(!io(t))return;n.selection.selectBlock(t,0);const e=S2(t);M8(n,t,!0),e.forEach(o=>{jC(o)}),W(t,"heading-collapsed")}function Sc(n,t){S2(t).forEach(o=>{UC(o)}),M8(n,t),ot(t,"heading-collapsed")}function jV(n,t){$V(t)?R8(n,t):Sc(n,t)}const UV=[bp,vp,yp,kp,wp,Bp,Ep,xp];function zV(n){const t=w("button",["heading-collapse-button"],null);return t.setAttribute(`data-editor-tooltip-${n.clientId}-dynamic`,R.t("expandCollapseButton.collapse")),t.innerHTML=Qh,t}function O8(n){return Mf(n).querySelector("button.heading-collapse-button")}function _8(n,t){O8(t)||L8(t)||!io(t)||Z0(t,zV(n),-1)}function VV(n){var t;(t=O8(n))==null||t.remove()}function F8(n,t){Mf(t).querySelector("button.heading-collapse-button")||_8(n,t)}function WV(n){const t=D2(n),e=w("button",["heading-marker"],null);return e.innerHTML=UV[t-1],e}function P8(n){return Mf(n).querySelector("button.heading-marker")}function L2(n){P8(n)||L8(n)||!io(n)||Z0(n,WV(n),1)}function N8(n){const t=P8(n);t==null||t.remove()}function $8(n){N8(n),go(n)&&L2(n)}class qV{handleDrop(t,e,o,r){if(Gd(e)||!go(e)||!el(e))return;const i=S2(e);i.unshift(e);const s=i.reverse();let l=null;return t.doc.beginBatchUpdate(),s.forEach((a,d,h)=>{const p=t.getBlockData(a),A=Fi(t.editorBlocks,t.doc.toJSON(),p),v=t.insertDocAt(o,r,A)[0];d===h.length-1&&(l=v)}),t.doc.endBatchUpdate(),t.doc.beginBatchUpdate(),s.forEach(a=>{t.deleteBlock(a)}),t.doc.endBatchUpdate(),l&&R8(t,l),!0}}const GV=S("heading-collapse");class M2{constructor(t){m(this,"handleLoad",()=>{this.showCollapseButtons()});m(this,"handleHoverBlock",(t,e)=>{e&&(ot(e,"hovering-heading"),go(e)&&Yt(nt(e))&&(L2(e),el(e)||VV(e))),t&&go(t)&&Yt(nt(t))&&(W(t,"hovering-heading"),this.editor.readonly||N8(t),_8(this.editor,t))});m(this,"handleClick",(t,e)=>{const o=Hl(e,"button.heading-collapse-button");if(!o)return;const r=et(o);!r||(g(GV,go(r),"not a heading block"),jV(this.editor,r),F8(this.editor,r))});this.editor=t,t.addListener("load",this.handleLoad),t.addListener("click",this.handleClick),Ae.get(t).addListener("change",this.handleHoverBlock),this.showCollapseButtons(),setTimeout(()=>{var o;(o=Lu.find(t))==null||o.addHandler(new qV)})}showCollapseButtons(){const t=pe(this.editor.rootContainer).filter(go);t.length!==0&&(t[0]===xe(this.editor.rootContainer)&&t.splice(0,1),t.forEach(L2))}destroy(){this.editor.removeListener("load",this.handleLoad),this.editor.removeListener("click",this.handleClick)}}function t1(n){const t=n.selection.range;if(t.isCollapsed()||t.start.blockId===t.end.blockId)return;const e=n.getBlockById(t.start.blockId),o=n.getBlockById(t.end.blockId);el(e)&&Sc(n,e),el(o)&&Sc(n,o)}function ZV(n){t1(n);const t=n.getFocusedBlock();!go(t)||el(t)&&Sc(n,t)}function QV(n){t1(n);const t=n.getFocusedBlock();if(!go(t))return;const e=n.selection.range.focus;!e.isSimple()||e.offset===ut(n,t)&&el(t)&&Sc(n,t)}function YV(n){t1(n);const t=n.getFocusedBlock();if(!go(t))return;const e=n.selection.range.focus;!e.isSimple()||e.offset===0&&el(t)&&Sc(n,t)}class JV{handleBeforeKeyDown(t,e){return Bm(e.key)&&t1(t),e.key==="Enter"?(ZV(t),!1):e.key==="Delete"?(QV(t),!1):(e.key==="Backspace"&&YV(t),!1)}}class KV{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(!go(o)){e&&e.delete.includes("heading")&&$8(o);return}xt(o,"hovering-heading")&&F8(this.editor,o),$8(o)}},100)}}function XV(n){return!!n.heading}function H8(n){var e;const t=n.heading;return(e=Number.parseInt(`${t}`,10))!=null?e:1}function j8(n,t,e){var i;const o=Ls(n,t.type);let r="";if(o.convertTo){const s=Wr();r=o.convertTo(n,t,s,"text",[{containerId:"root",blockIndex:0}]),r=r.replace(/\n/g,"").trim()}else r=ie((i=t.text)!=null?i:[]);return{parentNode:e,children:[],text:r,level:H8(t),block:t}}class Nu{constructor(t){m(this,"nodes",[]);this.editor=t}appendBlock(t){const e=this.findParent(H8(t),this.nodes);e?e.children.push(j8(this.editor,t,e)):this.nodes.push(j8(this.editor,t,null))}findParent(t,e){const o=e[e.length-1];if(!o||t<=1)return null;if(o.level===t-1)return o;const r=this.findParent(t,o.children);return r||(o.level<t?o:null)}static buildToc(t,e){const o=new Nu(t),r=e.blocks.root;for(let i=0;i<r.length;i++){const s=r[i];XV(s)&&o.appendBlock(s)}return o}}class es extends ye.TypedEmitter{constructor(e){super();m(this,"toc");m(this,"updateToc",Le.default(()=>{this.updateTocNow()},500));this.editor=e,e.doc.registerCallback(this),setTimeout(()=>{this.updateTocNow()}),this.toc=new Nu(this.editor)}destroy(){this.editor.doc.unregisterCallback(this)}isHeadingBlock(e){return!!e.heading}onInsertBlock(e,o,r,i){e==="root"&&this.isHeadingBlock(r)&&this.updateToc()}onDeleteBlock(e,o,r){e==="root"&&this.updateToc()}onUpdateBlockText(e,o,r,i){if(e!=="root")return;const s=this.editor.doc.getBlockData(e,o);this.isHeadingBlock(s)&&this.updateToc()}onUpdateBlockData(e,o,r,i){if(e!=="root")return;const s=this.editor.doc.getBlockData(e,o);this.isHeadingBlock(s)&&this.updateToc()}static register(e){return e.addCustom("editor-toc",()=>new es(e))}static get(e){return e.getCustom("editor-toc")}updateTocNow(){this.toc=Nu.buildToc(this.editor,this.editor.doc.toJSON()),this.emit("change",this.editor,this.toc)}}const rot="";function tW(n){return n.nodes.length===0?!0:n.nodes.length>1?!1:n.nodes[0].children.length===0}function U8(n,t){t.forEach(e=>{const o=w("div",["toc-node"],n),r=w("div",["toc-title"],o);if(w("span",["toc-text"],r,e.text).setAttribute("data-block-id",e.block.id),e.children.length>0){const s=w("div",["toc-children"],o);U8(s,e.children)}})}function eW(n,t){const e=Hl(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 z8(n,t,e){if(ot(t,"loading"),t.innerHTML="",tW(e)){w("div",["toc-empty-message"],t,R.t("toc.empty"));return}if(e.nodes.length>=1){const[o,...r]=e.nodes,i=[...o.children,...r];U8(t,i)}tp(n,"toc-click-handler",()=>{n.addListener("click",eW)})}class nW{constructor(t){m(this,"handleUpdateToc",(t,e)=>{Array.from(t.rootContainer.querySelectorAll('.embed-block[data-type="editor-block"][data-embed-type="toc"]')).forEach(r=>{const i=r.querySelector(".editor-toc-container");i&&z8(t,i,e)})});this.editor=t,es.register(t).addListener("change",this.handleUpdateToc)}destroy(){es.register(this.editor).removeListener("change",this.handleUpdateToc)}get toc(){return es.register(this.editor).toc}}function oW(n,t){const e=w("div",["editor-toc-container"],t),r=n.addCustom("init-editor-toc",()=>new nW(n)).toc;r.nodes.length===0?W(e,"loading"):z8(n,e,r)}function rW(n,t,e,o){return o==="markdown"?"[toc]":""}function iW(n,t,e){const{data:o}=e;if(!o||o.embedType!=="toc"||!tt(n,t))return null;const r={};return{blockData:{id:K(),type:"embed",embedType:"toc",embedData:r}}}const V8={embedType:"toc",createEmbedContent:oW,convertTo:rW,convertFrom:iW},sW={toc:{empty:"No Toc"}},lW={toc:{empty:"No Toc"}},cW={toc:{empty:"No Toc"}};R.mergeLang({"zh-CN":sW,"en-US":lW,"ja-JP":cW});function aW(n){return!!n.getAttribute("data-style-heading")}function R2(n,t){return aW(t)&&ut(n,t)>0}function uW(n){const t=ro(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=et(i[s]);if(l&&n.rootContainer.contains(l))return l}o+=10}return null}function O2(n,t){let e=t;for(;e&&!R2(n,e);)e=Zt(e);return e}function W8(n){if(ce(n))return!1;const e=nt(n);return Yt(e)}function e1(n,t){let e=t;for(;e&&!R2(n,e);)e=ce(e),e&&W8(e)&&(e=null);return e}const dW=.3;class hW extends ye.TypedEmitter{constructor(e){super();m(this,"scrollContainer");m(this,"scrollEventTarget");m(this,"scrollStatus",{curHeadingBlock:null,previousHeadingBlock:null,nextHeadingBlock:null});m(this,"handleScroll",Le.default(()=>{const e={curHeadingBlock:null,previousHeadingBlock:null,nextHeadingBlock:null};let o=uW(this.editor);if(o&&(o=Um(o)),!o||!this.scrollContainer){this.setStatus(e);return}if(W8(o)&&(o=Zt(o)),!o){this.setStatus(e);return}if(R2(this.editor,o)){e.curHeadingBlock=o,e.previousHeadingBlock=e1(this.editor,o),e.nextHeadingBlock=O2(this.editor,o),this.setStatus(e);return}const r=this.scrollContainer.getBoundingClientRect(),i=O2(this.editor,o);if(i){const l=i.getBoundingClientRect();if(l.top>r.top&&l.top<r.top+r.height*dW){e.curHeadingBlock=i,e.previousHeadingBlock=e1(this.editor,i),e.nextHeadingBlock=O2(this.editor,i),this.setStatus(e);return}e.nextHeadingBlock=i}const s=e1(this.editor,o);s&&(e.curHeadingBlock=s,e.previousHeadingBlock=e1(this.editor,s)),this.setStatus(e)},200));this.editor=e}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=ro(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),this.scrollStatus={curHeadingBlock:null,previousHeadingBlock:null,nextHeadingBlock:null})}destroy(){this.stop(),this.scrollEventTarget=void 0}}class _2{constructor(t,e){m(this,"suggest");m(this,"onClose",()=>{this.editor.focus()});m(this,"onShow",(t,e,o,r)=>{const i=this.editor.getBlockByIndex(e,o);if(!io(i)){const s=et(nt(i));if(s&&Dt(s)==="code")return!1}return!0});m(this,"onClickItem",(t,e,o)=>{const r=e.data,i={id:K(),type:"mention",box:!0,created:Date.now(),iconUrl:r.avatarUrl,text:r.displayName,mentionId:r.userId},s=this.editor.selection.range;if(!s.isCollapsed()||!s.isSimple())return;const l=s.focus,a=this.editor.getBlockById(l.blockId);this.editor.insertBoxToBlock(a,l.offset,i)});m(this,"queryItems",async(t,e)=>(await this.options.queryUsers(this.editor,e)).map(i=>{const s=Jd(i.displayName);return{id:i.userId,name:i.displayName,icon:i.avatarUrl?`<img src="${i.avatarUrl}" class="mention-user-avatar">`:`<span style="background: ${s}" class="mention-user-avatar-string">${Yd(i.displayName,1)}</span>`,element:i.element,data:i,subText:i.email}}));this.editor=t,this.options=e,this.suggest=new Fp(t,{id:"editor-mention",trigger:["@"],autoDeleteTrigger:!0,showLoading:!0,enableFirstBlock:e.enableFirstBlock,onShow:this.onShow,onClickItem:this.onClickItem,queryItems:this.queryItems,onClose:this.onClose})}destroy(){}}S("mathjax-box");function fW(n,t,e,o){const r=o,i=w("a",["mention-container"],e);w("span",["mention-name"],i,`@${r.text}`),i.setAttribute("data-mention-id",r.mentionId)}function mW(n,t,e){}function gW(n,t,e,o){return`@${t.text}`}function pW(){return{abstract:R.t("mention.abstract")}}const F2={boxType:"mention",updateBoxContent:fW,handleClickBox:mW,convertTo:gW,getBoxProperties:pW};function CW(n){const t=w("div",["mention-button-wrap"],null),e=uo("mention-button",R.t("list.mention.tooltip"),nM,[],n.clientId);return t.appendChild(e),t}class AW{constructor(t){m(this,"mentionButton");m(this,"handleHoveringBlock",t=>{var e;!this.editor.isWritable()||(t&&this.shouldBlockShowMention(t)?te(t).appendChild(this.mentionButton):(e=this.mentionButton)==null||e.remove())});m(this,"handleMouseDown",(t,e)=>{e.preventDefault(),e.stopPropagation();const o=et(this.mentionButton);if(!o||!tt(t,o))return;const r=t.selection.range.focus;if(!r.isSimple())return;let i;t.selection.focusedBlock!==o?i=ut(t,o):i=r.offset,setTimeout(()=>{const s=t.insertTextToBlock(o,i,"@");i+=1;const l=ie(In(s,i).left);this.editor.selection.selectBlock(o,i),this.editor.focus(),t.getCustom("mention").suggest.popup(o,i,l,"@")})});m(this,"destroy",()=>{Ae.get(this.editor).removeListener("change",this.handleHoveringBlock)});this.editor=t,this.mentionButton=CW(t),Ae.get(this.editor).addListener("change",this.handleHoveringBlock),t.domEvents.addEventListener(this.mentionButton,"mousedown",this.handleMouseDown)}shouldBlockShowMention(t){if(!tt(this.editor,t)||!Ht(t))return!1;const e=Zn(t);return!(e==="ordered"||e==="unordered")}}const iot="",bW={mention:{abstract:"\u6210\u5458"}},vW={mention:{abstract:"Member"}},yW={mention:{abstract:"\u30E1\u30F3\u30D0\u30FC"}};R.mergeLang({"zh-CN":bW,"en-US":vW,"ja-JP":yW});const kW={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"}},wW={templates:{title:"Choose a template",create:"New template",choose:"All templates",customizedMark:"Custom"}},BW={templates:{title:"\u30C6\u30F3\u30D7\u30EC\u30FC\u30C8\u3092\u9078\u629E",create:"\u30C6\u30F3\u30D7\u30EC\u30FC\u30C8\u3092\u65B0\u898F\u4F5C\u6210",choose:"\u30C6\u30F3\u30D7\u30EC\u30FC\u30C8\u4E00\u89A7",customizedMark:"\u30AB\u30B9\u30BF\u30E0"}};R.mergeLang({"zh-CN":kW,"en-US":wW,"ja-JP":BW});const sot="",EW="data:image/svg+xml;base64,Cjxzdmcgd2lkdGg9IjEyMCIgaGVpZ2h0PSIxMjAiIHZpZXdCb3g9IjAgMCAxMjAgMTIwIiBmaWxsPSJub25lIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgo8cmVjdCB3aWR0aD0iMTIwIiBoZWlnaHQ9IjEyMCIgZmlsbD0id2hpdGUiLz4KPHBhdGggZD0iTTQ4IDU5QzQ4IDU0LjU4MTcgNTEuNTgxNyA1MSA1NiA1MUg5M0M5OC41MjI4IDUxIDEwMyA1NS40NzcyIDEwMyA2MVY4OEMxMDMgOTEuODY2IDk5Ljg2NiA5NSA5NiA5NUg1NkM1MS41ODE3IDk1IDQ4IDkxLjQxODMgNDggODdWNTlaIiBmaWxsPSIjRDZFOUZBIi8+CjxwYXRoIGQ9Ik0xOCA2NEMxOCA2Mi4zNDMxIDE5LjM0MzEgNjEgMjEgNjFINTZDNjAuNDE4MyA2MSA2NCA2NC41ODE3IDY0IDY5VjgzQzY0IDg1LjIwOTEgNjIuMjA5MSA4NyA2MCA4N0gyNkMyMS41ODE3IDg3IDE4IDgzLjQxODMgMTggNzlWNjRaIiBmaWxsPSIjRUFFNEY2Ii8+CjxyZWN0IHg9IjI0IiB5PSIzMSIgd2lkdGg9IjY1IiBoZWlnaHQ9IjUwIiByeD0iNSIgZmlsbD0iIzk5QzdGMiIvPgo8cmVjdCB4PSIzMy41IiB5PSI0MyIgd2lkdGg9IjQ2IiBoZWlnaHQ9IjUiIHJ4PSIyLjUiIGZpbGw9IndoaXRlIi8+CjxyZWN0IHg9IjMzLjUiIHk9IjU0IiB3aWR0aD0iNDYiIGhlaWdodD0iNSIgcng9IjIuNSIgZmlsbD0id2hpdGUiLz4KPHJlY3QgeD0iMjQiIHk9IjMxIiB3aWR0aD0iNjUiIGhlaWdodD0iNTAiIHJ4PSI1IiBzdHJva2U9IiNGOEY4RjgiLz4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik01MCA4NS4yNjhDNTMuODI2MyA4My4wNTg5IDU1LjEzNzMgNzguMTY2MiA1Mi45MjgyIDc0LjMzOThMNjMuMzIwNSA2OC4zMzk4QzY4Ljg0MzMgNzcuOTA1NyA2NS41NjU4IDkwLjEzNzUgNTYgOTUuNjYwNEM0Ni40MzQxIDEwMS4xODMgMzQuMjAyMyA5Ny45MDU3IDI4LjY3OTQgODguMzM5OEwzOS4wNzE3IDgyLjMzOThDNDEuMjgwOSA4Ni4xNjYyIDQ2LjE3MzYgODcuNDc3MiA1MCA4NS4yNjhaIiBmaWxsPSIjQUI5M0RDIi8+CjxyZWN0IHg9IjU5IiB5PSI2NSIgd2lkdGg9IjQyIiBoZWlnaHQ9IjI4IiByeD0iNSIgZmlsbD0id2hpdGUiLz4KPHBhdGggZD0iTTYzIDg4VjczLjA4MDhDNjMgNzEuNzA5NiA2My4zNjE0IDcwLjY4NjcgNjQuMDg0MSA3MC4wMTJDNjQuODI4NyA2OS4zMzczIDY1Ljg1OCA2OSA2Ny4xNzIgNjlIOTIuODYwOUM5NS42MjAzIDY5IDk3IDcwLjM2MDMgOTcgNzMuMDgwOFY4OEg5My41MTc5TDg3LjM3NDkgODAuNjIyQzg3LjA5MDIgODAuMzE3MyA4Ni43NjE3IDgwLjA4ODggODYuMzg5NCA3OS45MzY0Qzg2LjAxNzEgNzkuNzg0MSA4NS42NDQ4IDc5LjcwNzkgODUuMjcyNSA3OS43MDc5Qzg0LjkwMDIgNzkuNzA3OSA4NC41Mjc5IDc5Ljc4NDEgODQuMTU1NiA3OS45MzY0QzgzLjgwNTIgODAuMDg4OCA4My40NTQ4IDgwLjMxNzMgODMuMTA0MyA4MC42MjJMNzYuNzMxNCA4Ni4yMzcxTDc0LjIwMTkgODMuOTUxOUM3My42MzI1IDgzLjQyOTYgNzMuMDA4NCA4My4xNjg0IDcyLjMyOTUgODMuMTY4NEM3MS42NTA2IDgzLjE2ODQgNzEuMDM3NCA4My40Mjk2IDcwLjQ4OTkgODMuOTUxOUw2Ni40NDkzIDg4SDYzWk03NC40NjQ3IDgwLjYyMkM3NS4zNjI2IDgwLjYyMiA3Ni4xNDAxIDgwLjI5NTUgNzYuNzk3MSA3OS42NDI2Qzc3LjQ3NiA3OC45ODk3IDc3LjgxNTUgNzguMjE3MSA3Ny44MTU1IDc3LjMyNDdDNzcuODE1NSA3Ni40MTA3IDc3LjQ3NiA3NS42MzggNzYuNzk3MSA3NS4wMDY5Qzc2LjE0MDEgNzQuMzU0IDc1LjM2MjYgNzQuMDE2NiA3NC40NjQ3IDczLjk5NDhDNzMuNTQ0OSA3My45NTEzIDcyLjc1NjUgNzQuMjY2OSA3Mi4wOTk1IDc0Ljk0MTZDNzEuNDQyNSA3NS42MTYzIDcxLjExNCA3Ni40MTA3IDcxLjExNCA3Ny4zMjQ3QzcxLjExNCA3OC4yMTcxIDcxLjQ0MjUgNzguOTg5NyA3Mi4wOTk1IDc5LjY0MjZDNzIuNzU2NSA4MC4yOTU1IDczLjU0NDkgODAuNjIyIDc0LjQ2NDcgODAuNjIyWiIgZmlsbD0iI0Y3RDA3RiIvPgo8Y2lyY2xlIGN4PSI5NSIgY3k9IjQyIiByPSIyIiBzdHJva2U9IiM1MEMzOTgiIHN0cm9rZS13aWR0aD0iMiIvPgo8cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTk0Ljc1MDEgMjQuNDY4N0wxMDAuNzgxIDI3LjkxNDlMOTQuNzE5IDMxLjQxNDlMOTQuNzUwMSAyNC40Njg3WiIgc3Ryb2tlPSIjNUNBNUVBIiBzdHJva2Utd2lkdGg9IjEuOCIvPgo8cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTEwNSAzOEMxMDUgMzguNTUyMyAxMDUuNDQ4IDM5IDEwNiAzOUMxMDYuNTUyIDM5IDEwNyAzOC41NTIzIDEwNyAzOFYzNkgxMDlDMTA5LjU1MiAzNiAxMTAgMzUuNTUyMyAxMTAgMzVDMTEwIDM0LjQ0NzcgMTA5LjU1MiAzNCAxMDkgMzRIMTA3VjMyQzEwNyAzMS40NDc3IDEwNi41NTIgMzEgMTA2IDMxQzEwNS40NDggMzEgMTA1IDMxLjQ0NzcgMTA1IDMyVjM0SDEwM0MxMDIuNDQ4IDM0IDEwMiAzNC40NDc3IDEwMiAzNUMxMDIgMzUuNTUyMyAxMDIuNDQ4IDM2IDEwMyAzNkgxMDVWMzhaIiBmaWxsPSIjQUI5M0RDIi8+Cjwvc3ZnPgo=",xW="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzcyIiBoZWlnaHQ9IjI3OSIgdmlld0JveD0iMCAwIDM3MiAyNzkiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMF8xMjU2XzM3MTY4KSI+CjxyZWN0IHdpZHRoPSIzNzIiIGhlaWdodD0iMjc5IiBmaWxsPSJ3aGl0ZSIvPgo8cmVjdCB4PSIzOS41NzQ1IiB5PSIzOS41NzQ3IiB3aWR0aD0iMTE4LjcyMyIgaGVpZ2h0PSIxNS44Mjk4IiByeD0iNy45MTQ4OSIgZmlsbD0iI0VBRjNGQyIvPgo8cmVjdCB4PSIzOS41NzQ1IiB5PSI3MS4yMzM5IiB3aWR0aD0iMjkyLjg1MSIgaGVpZ2h0PSI3LjkxNDg5IiByeD0iMy45NTc0NSIgZmlsbD0iI0VBRjNGQyIvPgo8cmVjdCB4PSIzOS41NzQ1IiB5PSI5MS4wMjE1IiB3aWR0aD0iMjkyLjg1MSIgaGVpZ2h0PSI3LjkxNDg5IiByeD0iMy45NTc0NSIgZmlsbD0iI0VBRjNGQyIvPgo8cmVjdCB4PSIzOS41NzQ1IiB5PSIxMTAuODA5IiB3aWR0aD0iMjkyLjg1MSIgaGVpZ2h0PSI3LjkxNDg5IiByeD0iMy45NTc0NSIgZmlsbD0iI0VBRjNGQyIvPgo8cmVjdCB4PSI0MC41NjM4IiB5PSIxMzUuNTQzIiB3aWR0aD0iMjkwLjg3MiIgaGVpZ2h0PSIxMDAuOTE1IiByeD0iMi45NjgwOSIgc3Ryb2tlPSIjRUFGM0ZDIiBzdHJva2Utd2lkdGg9IjEuOTc4NzIiLz4KPHBhdGggZD0iTTM5LjU3NDUgMTM4LjUxMUMzOS41NzQ1IDEzNi4zMjUgNDEuMzQ2MyAxMzQuNTUzIDQzLjUzMTkgMTM0LjU1M0gzMjguNDY4QzMzMC42NTQgMTM0LjU1MyAzMzIuNDI2IDEzNi4zMjUgMzMyLjQyNiAxMzguNTExVjE1Mi4zNjJIMzkuNTc0NVYxMzguNTExWiIgZmlsbD0iI0Q2RTlGQSIvPgo8cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTg3LjA2MzcgMTY5LjE4MUM4Ny4wNjM3IDE2Ny41NDIgODguMzkyNiAxNjYuMjEzIDkwLjAzMTggMTY2LjIxM0gzMTcuNTg1QzMxOS4yMjQgMTY2LjIxMyAzMjAuNTUzIDE2Ny41NDIgMzIwLjU1MyAxNjkuMTgxQzMyMC41NTMgMTcwLjgyIDMxOS4yMjQgMTcyLjE0OSAzMTcuNTg1IDE3Mi4xNDlIOTAuMDMxOEM4OC4zOTI2IDE3Mi4xNDkgODcuMDYzNyAxNzAuODIgODcuMDYzNyAxNjkuMTgxWk0xMDQuODcyIDE5Mi45MjZDMTA0Ljg3MiAxOTEuMjg2IDEwNi4yMDEgMTg5Ljk1NyAxMDcuODQgMTg5Ljk1N0gzMTcuNTg1QzMxOS4yMjQgMTg5Ljk1NyAzMjAuNTUzIDE5MS4yODYgMzIwLjU1MyAxOTIuOTI2QzMyMC41NTMgMTk0LjU2NSAzMTkuMjI0IDE5NS44OTQgMzE3LjU4NSAxOTUuODk0SDEwNy44NEMxMDYuMjAxIDE5NS44OTQgMTA0Ljg3MiAxOTQuNTY1IDEwNC44NzIgMTkyLjkyNlpNMTA3Ljg0IDIxMy43MDJDMTA2LjIwMSAyMTMuNzAyIDEwNC44NzIgMjE1LjAzMSAxMDQuODcyIDIxNi42N0MxMDQuODcyIDIxOC4zMDkgMTA2LjIwMSAyMTkuNjM4IDEwNy44NCAyMTkuNjM4SDMxNy41ODVDMzE5LjIyNCAyMTkuNjM4IDMyMC41NTMgMjE4LjMwOSAzMjAuNTUzIDIxNi42N0MzMjAuNTUzIDIxNS4wMzEgMzE5LjIyNCAyMTMuNzAyIDMxNy41ODUgMjEzLjcwMkgxMDcuODRaIiBmaWxsPSIjRDZFOUZBIi8+CjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJNNTEuNDQ2OCAxNjkuMTgxQzUxLjQ0NjggMTY3LjU0MiA1Mi43NzU2IDE2Ni4yMTMgNTQuNDE0OSAxNjYuMjEzSDYwLjM1MUM2MS45OTAzIDE2Ni4yMTMgNjMuMzE5MSAxNjcuNTQyIDYzLjMxOTEgMTY5LjE4MUM2My4zMTkxIDE3MC44MiA2MS45OTAzIDE3Mi4xNDkgNjAuMzUxIDE3Mi4xNDlINTQuNDE0OUM1Mi43NzU2IDE3Mi4xNDkgNTEuNDQ2OCAxNzAuODIgNTEuNDQ2OCAxNjkuMTgxWk01MS40NDY4IDE5Mi45MjZDNTEuNDQ2OCAxOTEuMjg2IDUyLjc3NTcgMTg5Ljk1NyA1NC40MTQ5IDE4OS45NTdINjAuMzUxMUM2MS45OTAzIDE4OS45NTcgNjMuMzE5MSAxOTEuMjg2IDYzLjMxOTEgMTkyLjkyNkM2My4zMTkxIDE5NC41NjUgNjEuOTkwMyAxOTUuODk0IDYwLjM1MTEgMTk1Ljg5NEg1NC40MTQ5QzUyLjc3NTcgMTk1Ljg5NCA1MS40NDY4IDE5NC41NjUgNTEuNDQ2OCAxOTIuOTI2Wk01NC40MTQ5IDIxMy43MDJDNTIuNzc1NyAyMTMuNzAyIDUxLjQ0NjggMjE1LjAzMSA1MS40NDY4IDIxNi42N0M1MS40NDY4IDIxOC4zMDkgNTIuNzc1NyAyMTkuNjM4IDU0LjQxNDkgMjE5LjYzOEg2MC4zNTExQzYxLjk5MDMgMjE5LjYzOCA2My4zMTkxIDIxOC4zMDkgNjMuMzE5MSAyMTYuNjdDNjMuMzE5MSAyMTUuMDMxIDYxLjk5MDMgMjEzLjcwMiA2MC4zNTExIDIxMy43MDJINTQuNDE0OVoiIGZpbGw9IiM5OUM3RjIiLz4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik02OS4yNTU0IDE2OS4xODFDNjkuMjU1NCAxNjcuNTQyIDcwLjU4NDMgMTY2LjIxMyA3Mi4yMjM1IDE2Ni4yMTNINzguMTU5N0M3OS43OTg5IDE2Ni4yMTMgODEuMTI3OCAxNjcuNTQyIDgxLjEyNzggMTY5LjE4MUM4MS4xMjc4IDE3MC44MiA3OS43OTg5IDE3Mi4xNDkgNzguMTU5NyAxNzIuMTQ5SDcyLjIyMzVDNzAuNTg0MyAxNzIuMTQ5IDY5LjI1NTQgMTcwLjgyIDY5LjI1NTQgMTY5LjE4MVpNNjkuMjU1NCAxOTIuOTI2QzY5LjI1NTQgMTkxLjI4NiA3MC41ODQyIDE4OS45NTcgNzIuMjIzNSAxODkuOTU3SDc4LjE1OTZDNzkuNzk4OSAxODkuOTU3IDgxLjEyNzcgMTkxLjI4NiA4MS4xMjc3IDE5Mi45MjZDODEuMTI3NyAxOTQuNTY1IDc5Ljc5ODkgMTk1Ljg5NCA3OC4xNTk2IDE5NS44OTRINzIuMjIzNUM3MC41ODQyIDE5NS44OTQgNjkuMjU1NCAxOTQuNTY1IDY5LjI1NTQgMTkyLjkyNlpNNzIuMjIzNSAyMTMuNzAyQzcwLjU4NDIgMjEzLjcwMiA2OS4yNTU0IDIxNS4wMzEgNjkuMjU1NCAyMTYuNjdDNjkuMjU1NCAyMTguMzA5IDcwLjU4NDIgMjE5LjYzOCA3Mi4yMjM1IDIxOS42MzhINzguMTU5NkM3OS43OTg5IDIxOS42MzggODEuMTI3NyAyMTguMzA5IDgxLjEyNzcgMjE2LjY3QzgxLjEyNzcgMjE1LjAzMSA3OS43OTg5IDIxMy43MDIgNzguMTU5NiAyMTMuNzAySDcyLjIyMzVaIiBmaWxsPSIjRjdEMDdGIi8+CjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJNOTAuMDMxOCAxODkuOTU4Qzg4LjM5MjYgMTg5Ljk1OCA4Ny4wNjM3IDE5MS4yODYgODcuMDYzNyAxOTIuOTI2Qzg3LjA2MzcgMTk0LjU2NSA4OC4zOTI2IDE5NS44OTQgOTAuMDMxOCAxOTUuODk0SDk1Ljk2OEM5Ny42MDcyIDE5NS44OTQgOTguOTM2MSAxOTQuNTY1IDk4LjkzNjEgMTkyLjkyNkM5OC45MzYxIDE5MS4yODYgOTcuNjA3MiAxODkuOTU4IDk1Ljk2OCAxODkuOTU4SDkwLjAzMThaTTkwLjAzMTkgMjEzLjcwMkM4OC4zOTI3IDIxMy43MDIgODcuMDYzOCAyMTUuMDMxIDg3LjA2MzggMjE2LjY3Qzg3LjA2MzggMjE4LjMwOSA4OC4zOTI3IDIxOS42MzggOTAuMDMxOSAyMTkuNjM4SDk1Ljk2ODFDOTcuNjA3MyAyMTkuNjM4IDk4LjkzNjIgMjE4LjMwOSA5OC45MzYyIDIxNi42N0M5OC45MzYyIDIxNS4wMzEgOTcuNjA3MyAyMTMuNzAyIDk1Ljk2ODEgMjEzLjcwMkg5MC4wMzE5WiIgZmlsbD0iIzkxRDlCRSIvPgo8L2c+CjxkZWZzPgo8Y2xpcFBhdGggaWQ9ImNsaXAwXzEyNTZfMzcxNjgiPgo8cmVjdCB3aWR0aD0iMzcyIiBoZWlnaHQ9IjI3OSIgZmlsbD0id2hpdGUiLz4KPC9jbGlwUGF0aD4KPC9kZWZzPgo8L3N2Zz4K",q8=S("templates");function P2(n){const t=n.rootElement.querySelector(":scope .editor-templates");if(!t)return null;const e=t.querySelector(":scope .editor-templates-cards");return g(q8,e,"no card container"),{root:t,cardContainer:e}}function IW(n){const t=P2(n);if(t)return t.cardContainer.innerHTML="",t;const e=w("div",["editor-templates"],n.rootElement);w("div",["editor-templates-title"],e,R.t("templates.title"));const o=w("div",["editor-templates-cards"],e);return{root:e,cardContainer:o}}function G8(n,t,e,o,r){var p;const i=(p=n.options.componentsOptions)==null?void 0:p.templates,s=w("div",["editor-template-card",...o],null),l=w("div",["editor-template-thumb-container"],s),a=w("img",["editor-template-thumb"],l);a.src=t,a.style.display="none",a.onerror=()=>{var v;const A=(v=i==null?void 0:i.placeHolderImageSrc)!=null?v:xW;a.src!==A&&(a.src=A)},a.onload=()=>{a.style.display=""};const d=w("div",["editor-template-name"],s),h=w("span",[],d,e);return i!=null&&i.showTemplateTitleAttr&&h.setAttribute("title",e),s.onclick=()=>r(s),s}function TW(n,t){return t.thumbnailUrl?t.thumbnailUrl:n.doc.buildResourceUrl("thumbnail.png")}function DW(n,t){const e=TW(n,t);return G8(n,e,t.name,[],async()=>{var r,i;const o=(r=n.options.componentsOptions)==null?void 0:r.templates;await((i=o==null?void 0:o.onApplyTemplate)==null?void 0:i.call(o,n,t)),es.register(n).updateToc()})}function SW(n,t){return G8(n,t,R.t("templates.choose"),["more"],()=>{var o,r;const e=(o=n.options.componentsOptions)==null?void 0:o.templates;(r=e==null?void 0:e.onChooseTemplate)==null||r.call(e,n)})}function LW(n,t){var p,A;const e=(p=n.options.componentsOptions)==null?void 0:p.templates;if(!e)return;const r=Qe(n.rootContainer).getBoundingClientRect().width;let i=1;const s=EW,l=P2(n);if(l){if(t!=null&&t.reset){const v=Array.from(l.cardContainer.children),B=l.cardContainer.firstElementChild;if(g(q8,B,"no first card"),xt(B,"new")||xt(B,"more"))return;const D=window.getComputedStyle(B),x=parseFloat(D.marginLeft),_=parseFloat(D.marginRight),M=B.getBoundingClientRect().width+x+_;i=Math.floor(r/M);const z=Math.max(1,i-1-1),q=v.length-1;v.forEach((rt,ft)=>{ft>z&&ft<q?rt.style.display="none":(ft>=q&&xt(rt,"more"),rt.style.display="")})}return}const a=e.templates,{cardContainer:d}=IW(n);a.forEach((v,B)=>{const D=DW(n,v);if(B>0&&B>=i&&(D.style.display="none"),d.appendChild(D),B===0){const x=window.getComputedStyle(D),_=parseFloat(x.marginLeft),M=parseFloat(x.marginRight),H=D.getBoundingClientRect().width+_+M;i=Math.floor(r/H)-1}});const h=SW(n,s);d.appendChild(h),(A=e==null?void 0:e.onTemplateChooserStatusChanged)==null||A.call(e,n,d,"visible")}const Z8=Le.default(LW,50);function MW(n){var o,r;const t=P2(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 RW(n){const t=n.blocks.root;if(t.length===0)return!0;if(t.length>5)return!1;const e=[...t];e[0].type==="text"&&e[0].heading&&e.splice(0,1);const o=r=>{var i;return r.type!=="text"&&r.type!=="list"?!1:r.text?((i=r.text)==null?void 0:i.length)===0:!0};return e.every(r=>o(r))}function n1(n,t){RW(n.doc.toJSON())?Z8(n,t):(Z8.cancel(),MW(n))}const OW=800;class _W{constructor(t){m(this,"longPressTimeout",0);m(this,"handleSelectionChange",()=>{});m(this,"handleLongPress",t=>{const e=t.touches[0],o=ih(this.editor,e.clientX,e.clientY);!o||console.log(o)});m(this,"handleTouchStart",t=>{t.touches.length===1&&(this.longPressTimeout=window.setTimeout(()=>{this.handleLongPress(t)},OW))});m(this,"handleTouchEnd",t=>{this.longPressTimeout&&(window.clearTimeout(this.longPressTimeout),this.longPressTimeout=0)});this.editor=t,this.editor.addListener("selectionChanged",this.handleSelectionChange),document.addEventListener("touchstart",this.handleTouchStart),document.addEventListener("touchend",this.handleTouchEnd)}destroy(){this.editor.removeListener("selectionChanged",this.handleSelectionChange),document.removeEventListener("touchstart",this.handleTouchStart),document.removeEventListener("touchend",this.handleTouchEnd)}}const FW=`<svg width="24" height="25" viewBox="0 0 24 25" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
597
597
|
<g>
|
|
598
598
|
<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"/>
|
|
599
599
|
<animateTransform attributeType="xml" attributeName="transform" type="rotate" values="0 12 12.5;360 12 12.5" dur="2s" repeatCount="indefinite" />
|
|
@@ -725,9 +725,9 @@ width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
|
|
725
725
|
* Released under MIT license <https://lodash.com/license>
|
|
726
726
|
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
727
727
|
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
728
|
-
*/(function(n,t){(function(){var e,o="4.17.21",r=200,i="Unsupported core-js use. Try https://npms.io/search?q=ponyfill.",s="Expected a function",l="Invalid `variable` option passed into `_.template`",a="__lodash_hash_undefined__",d=500,h="__lodash_placeholder__",p=1,A=2,v=4,B=1,D=2,x=1,_=2,M=4,H=8,z=16,q=32,rt=64,ft=128,Bt=256,jt=512,Ut=30,ne="...",qe=800,Yn=16,$e=1,Rn=2,kr=3,vn=1/0,an=9007199254740991,wr=17976931348623157e292,oi=0/0,po=4294967295,X2=po-1,t3=po>>>1,e3=[["ary",ft],["bind",x],["bindKey",_],["curry",H],["curryRight",z],["flip",jt],["partial",q],["partialRight",rt],["rearg",Bt]],ns="[object Arguments]",nl="[object Array]",ol="[object AsyncFunction]",ri="[object Boolean]",Nt="[object Date]",Br="[object DOMException]",os="[object Error]",Fc="[object Function]",s1="[object GeneratorFunction]",un="[object Map]",rl="[object Number]",l1="[object Null]",Co="[object Object]",c1="[object Promise]",n3="[object Proxy]",il="[object RegExp]",be="[object Set]",sl="[object String]",ll="[object Symbol]",a1="[object Undefined]",cl="[object WeakMap]",u1="[object WeakSet]",al="[object ArrayBuffer]",rs="[object DataView]",ju="[object Float32Array]",Uu="[object Float64Array]",zu="[object Int8Array]",Vu="[object Int16Array]",Wu="[object Int32Array]",qu="[object Uint8Array]",Gu="[object Uint8ClampedArray]",Zu="[object Uint16Array]",Qu="[object Uint32Array]",o3=/\b__p \+= '';/g,r3=/\b(__p \+=) '' \+/g,i3=/(__e\(.*?\)|\b__t\)) \+\n'';/g,d1=/&(?:amp|lt|gt|quot|#39);/g,h1=/[&<>"']/g,s3=RegExp(d1.source),l3=RegExp(h1.source),c3=/<%-([\s\S]+?)%>/g,a3=/<%([\s\S]+?)%>/g,f1=/<%=([\s\S]+?)%>/g,u3=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,d3=/^\w*$/,h3=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Yu=/[\\^$.*+?()[\]{}|]/g,f3=RegExp(Yu.source),Ju=/^\s+/,m3=/\s/,g3=/\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,se=/\{\n\/\* \[wrapped with (.+)\] \*/,p3=/,? & /,C3=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g,m1=/[()=,{}\[\]\/\s]/,ul=/\\(\\)?/g,A3=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,Pc=/\w*$/,g1=/^[-+]0x[0-9a-f]+$/i,p1=/^0b[01]+$/i,b3=/^\[object .+?Constructor\]$/,v3=/^0o[0-7]+$/i,y3=/^(?:0|[1-9]\d*)$/,k3=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,Nc=/($^)/,w3=/['\n\r\u2028\u2029\\]/g,$c="\\ud800-\\udfff",B3="\\u0300-\\u036f",E3="\\ufe20-\\ufe2f",x3="\\u20d0-\\u20ff",C1=B3+E3+x3,Hc="\\u2700-\\u27bf",A1="a-z\\xdf-\\xf6\\xf8-\\xff",I3="\\xac\\xb1\\xd7\\xf7",T3="\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf",D3="\\u2000-\\u206f",Ao=" \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000",dl="A-Z\\xc0-\\xd6\\xd8-\\xde",Er="\\ufe0e\\ufe0f",He=I3+T3+D3+Ao,Ku="['\u2019]",S3="["+$c+"]",Go="["+He+"]",Zo="["+C1+"]",Xu="\\d+",jc="["+Hc+"]",td="["+A1+"]",ii="[^"+$c+He+Xu+Hc+A1+dl+"]",xr="\\ud83c[\\udffb-\\udfff]",ed="(?:"+Zo+"|"+xr+")",nd="[^"+$c+"]",is="(?:\\ud83c[\\udde6-\\uddff]){2}",od="[\\ud800-\\udbff][\\udc00-\\udfff]",ss="["+dl+"]",ls="\\u200d",b1="(?:"+td+"|"+ii+")",L3="(?:"+ss+"|"+ii+")",v1="(?:"+Ku+"(?:d|ll|m|re|s|t|ve))?",hl="(?:"+Ku+"(?:D|LL|M|RE|S|T|VE))?",Uc=ed+"?",si="["+Er+"]?",M3="(?:"+ls+"(?:"+[nd,is,od].join("|")+")"+si+Uc+")*",R3="\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",O3="\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])",rd=si+Uc+M3,y1="(?:"+[jc,is,od].join("|")+")"+rd,id="(?:"+[nd+Zo+"?",Zo,is,od,S3].join("|")+")",_3=RegExp(Ku,"g"),F3=RegExp(Zo,"g"),sd=RegExp(xr+"(?="+xr+")|"+id+rd,"g"),P3=RegExp([ss+"?"+td+"+"+v1+"(?="+[Go,ss,"$"].join("|")+")",L3+"+"+hl+"(?="+[Go,ss+b1,"$"].join("|")+")",ss+"?"+b1+"+"+v1,ss+"+"+hl,O3,R3,Xu,y1].join("|"),"g"),N3=RegExp("["+ls+$c+C1+Er+"]"),$3=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/,H3=["Array","Buffer","DataView","Date","Error","Float32Array","Float64Array","Function","Int8Array","Int16Array","Int32Array","Map","Math","Object","Promise","RegExp","Set","String","Symbol","TypeError","Uint8Array","Uint8ClampedArray","Uint16Array","Uint32Array","WeakMap","_","clearTimeout","isFinite","parseInt","setTimeout"],j3=-1,le={};le[ju]=le[Uu]=le[zu]=le[Vu]=le[Wu]=le[qu]=le[Gu]=le[Zu]=le[Qu]=!0,le[ns]=le[nl]=le[al]=le[ri]=le[rs]=le[Nt]=le[os]=le[Fc]=le[un]=le[rl]=le[Co]=le[il]=le[be]=le[sl]=le[cl]=!1;var oe={};oe[ns]=oe[nl]=oe[al]=oe[rs]=oe[ri]=oe[Nt]=oe[ju]=oe[Uu]=oe[zu]=oe[Vu]=oe[Wu]=oe[un]=oe[rl]=oe[Co]=oe[il]=oe[be]=oe[sl]=oe[ll]=oe[qu]=oe[Gu]=oe[Zu]=oe[Qu]=!0,oe[os]=oe[Fc]=oe[cl]=!1;var U3={\u00C0:"A",\u00C1:"A",\u00C2:"A",\u00C3:"A",\u00C4:"A",\u00C5:"A",\u00E0:"a",\u00E1:"a",\u00E2:"a",\u00E3:"a",\u00E4:"a",\u00E5:"a",\u00C7:"C",\u00E7:"c",\u00D0:"D",\u00F0:"d",\u00C8:"E",\u00C9:"E",\u00CA:"E",\u00CB:"E",\u00E8:"e",\u00E9:"e",\u00EA:"e",\u00EB:"e",\u00CC:"I",\u00CD:"I",\u00CE:"I",\u00CF:"I",\u00EC:"i",\u00ED:"i",\u00EE:"i",\u00EF:"i",\u00D1:"N",\u00F1:"n",\u00D2:"O",\u00D3:"O",\u00D4:"O",\u00D5:"O",\u00D6:"O",\u00D8:"O",\u00F2:"o",\u00F3:"o",\u00F4:"o",\u00F5:"o",\u00F6:"o",\u00F8:"o",\u00D9:"U",\u00DA:"U",\u00DB:"U",\u00DC:"U",\u00F9:"u",\u00FA:"u",\u00FB:"u",\u00FC:"u",\u00DD:"Y",\u00FD:"y",\u00FF:"y",\u00C6:"Ae",\u00E6:"ae",\u00DE:"Th",\u00FE:"th",\u00DF:"ss",\u0100:"A",\u0102:"A",\u0104:"A",\u0101:"a",\u0103:"a",\u0105:"a",\u0106:"C",\u0108:"C",\u010A:"C",\u010C:"C",\u0107:"c",\u0109:"c",\u010B:"c",\u010D:"c",\u010E:"D",\u0110:"D",\u010F:"d",\u0111:"d",\u0112:"E",\u0114:"E",\u0116:"E",\u0118:"E",\u011A:"E",\u0113:"e",\u0115:"e",\u0117:"e",\u0119:"e",\u011B:"e",\u011C:"G",\u011E:"G",\u0120:"G",\u0122:"G",\u011D:"g",\u011F:"g",\u0121:"g",\u0123:"g",\u0124:"H",\u0126:"H",\u0125:"h",\u0127:"h",\u0128:"I",\u012A:"I",\u012C:"I",\u012E:"I",\u0130:"I",\u0129:"i",\u012B:"i",\u012D:"i",\u012F:"i",\u0131:"i",\u0134:"J",\u0135:"j",\u0136:"K",\u0137:"k",\u0138:"k",\u0139:"L",\u013B:"L",\u013D:"L",\u013F:"L",\u0141:"L",\u013A:"l",\u013C:"l",\u013E:"l",\u0140:"l",\u0142:"l",\u0143:"N",\u0145:"N",\u0147:"N",\u014A:"N",\u0144:"n",\u0146:"n",\u0148:"n",\u014B:"n",\u014C:"O",\u014E:"O",\u0150:"O",\u014D:"o",\u014F:"o",\u0151:"o",\u0154:"R",\u0156:"R",\u0158:"R",\u0155:"r",\u0157:"r",\u0159:"r",\u015A:"S",\u015C:"S",\u015E:"S",\u0160:"S",\u015B:"s",\u015D:"s",\u015F:"s",\u0161:"s",\u0162:"T",\u0164:"T",\u0166:"T",\u0163:"t",\u0165:"t",\u0167:"t",\u0168:"U",\u016A:"U",\u016C:"U",\u016E:"U",\u0170:"U",\u0172:"U",\u0169:"u",\u016B:"u",\u016D:"u",\u016F:"u",\u0171:"u",\u0173:"u",\u0174:"W",\u0175:"w",\u0176:"Y",\u0177:"y",\u0178:"Y",\u0179:"Z",\u017B:"Z",\u017D:"Z",\u017A:"z",\u017C:"z",\u017E:"z",\u0132:"IJ",\u0133:"ij",\u0152:"Oe",\u0153:"oe",\u0149:"'n",\u017F:"s"},z3={"&":"&","<":"<",">":">",'"':""","'":"'"},V3={"&":"&","<":"<",">":">",""":'"',"'":"'"},W3={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"},k1=parseFloat,q3=parseInt,w1=typeof ar=="object"&&ar&&ar.Object===Object&&ar,G3=typeof self=="object"&&self&&self.Object===Object&&self,Ge=w1||G3||Function("return this")(),ld=t&&!t.nodeType&&t,li=ld&&!0&&n&&!n.nodeType&&n,zc=li&&li.exports===ld,fl=zc&&w1.process,On=function(){try{var N=li&&li.require&&li.require("util").types;return N||fl&&fl.binding&&fl.binding("util")}catch{}}(),cd=On&&On.isArrayBuffer,ad=On&&On.isDate,ud=On&&On.isMap,B1=On&&On.isRegExp,dd=On&&On.isSet,hd=On&&On.isTypedArray;function yn(N,G,V){switch(V.length){case 0:return N.call(G);case 1:return N.call(G,V[0]);case 2:return N.call(G,V[0],V[1]);case 3:return N.call(G,V[0],V[1],V[2])}return N.apply(G,V)}function Z3(N,G,V,ht){for(var Et=-1,Vt=N==null?0:N.length;++Et<Vt;){var we=N[Et];G(ht,we,V(we),N)}return ht}function _n(N,G){for(var V=-1,ht=N==null?0:N.length;++V<ht&&G(N[V],V,N)!==!1;);return N}function Q3(N,G){for(var V=N==null?0:N.length;V--&&G(N[V],V,N)!==!1;);return N}function E1(N,G){for(var V=-1,ht=N==null?0:N.length;++V<ht;)if(!G(N[V],V,N))return!1;return!0}function Qo(N,G){for(var V=-1,ht=N==null?0:N.length,Et=0,Vt=[];++V<ht;){var we=N[V];G(we,V,N)&&(Vt[Et++]=we)}return Vt}function Vc(N,G){var V=N==null?0:N.length;return!!V&&ci(N,G,0)>-1}function fd(N,G,V){for(var ht=-1,Et=N==null?0:N.length;++ht<Et;)if(V(G,N[ht]))return!0;return!1}function ue(N,G){for(var V=-1,ht=N==null?0:N.length,Et=Array(ht);++V<ht;)Et[V]=G(N[V],V,N);return Et}function Ir(N,G){for(var V=-1,ht=G.length,Et=N.length;++V<ht;)N[Et+V]=G[V];return N}function md(N,G,V,ht){var Et=-1,Vt=N==null?0:N.length;for(ht&&Vt&&(V=N[++Et]);++Et<Vt;)V=G(V,N[Et],Et,N);return V}function Y3(N,G,V,ht){var Et=N==null?0:N.length;for(ht&&Et&&(V=N[--Et]);Et--;)V=G(V,N[Et],Et,N);return V}function gd(N,G){for(var V=-1,ht=N==null?0:N.length;++V<ht;)if(G(N[V],V,N))return!0;return!1}var J3=qc("length");function x1(N){return N.split("")}function Jn(N){return N.match(C3)||[]}function pd(N,G,V){var ht;return V(N,function(Et,Vt,we){if(G(Et,Vt,we))return ht=Vt,!1}),ht}function ml(N,G,V,ht){for(var Et=N.length,Vt=V+(ht?1:-1);ht?Vt--:++Vt<Et;)if(G(N[Vt],Vt,N))return Vt;return-1}function ci(N,G,V){return G===G?Jc(N,G,V):ml(N,Yo,V)}function cs(N,G,V,ht){for(var Et=V-1,Vt=N.length;++Et<Vt;)if(ht(N[Et],G))return Et;return-1}function Yo(N){return N!==N}function Wc(N,G){var V=N==null?0:N.length;return V?Gc(N,G)/V:oi}function qc(N){return function(G){return G==null?e:G[N]}}function Cd(N){return function(G){return N==null?e:N[G]}}function gl(N,G,V,ht,Et){return Et(N,function(Vt,we,qt){V=ht?(ht=!1,Vt):G(V,Vt,we,qt)}),V}function I1(N,G){var V=N.length;for(N.sort(G);V--;)N[V]=N[V].value;return N}function Gc(N,G){for(var V,ht=-1,Et=N.length;++ht<Et;){var Vt=G(N[ht]);Vt!==e&&(V=V===e?Vt:V+Vt)}return V}function Zc(N,G){for(var V=-1,ht=Array(N);++V<N;)ht[V]=G(V);return ht}function pl(N,G){return ue(G,function(V){return[V,N[V]]})}function ai(N){return N&&N.slice(0,Kc(N)+1).replace(Ju,"")}function dn(N){return function(G){return N(G)}}function as(N,G){return ue(G,function(V){return N[V]})}function Jo(N,G){return N.has(G)}function Cl(N,G){for(var V=-1,ht=N.length;++V<ht&&ci(G,N[V],0)>-1;);return V}function Ad(N,G){for(var V=N.length;V--&&ci(G,N[V],0)>-1;);return V}function T1(N,G){for(var V=N.length,ht=0;V--;)N[V]===G&&++ht;return ht}var D1=Cd(U3),bd=Cd(z3);function S1(N){return"\\"+W3[N]}function L1(N,G){return N==null?e:N[G]}function ui(N){return N3.test(N)}function Qc(N){return $3.test(N)}function Al(N){for(var G,V=[];!(G=N.next()).done;)V.push(G.value);return V}function di(N){var G=-1,V=Array(N.size);return N.forEach(function(ht,Et){V[++G]=[Et,ht]}),V}function Yc(N,G){return function(V){return N(G(V))}}function Kn(N,G){for(var V=-1,ht=N.length,Et=0,Vt=[];++V<ht;){var we=N[V];(we===G||we===h)&&(N[V]=h,Vt[Et++]=V)}return Vt}function hi(N){var G=-1,V=Array(N.size);return N.forEach(function(ht){V[++G]=ht}),V}function bl(N){var G=-1,V=Array(N.size);return N.forEach(function(ht){V[++G]=[ht,ht]}),V}function Jc(N,G,V){for(var ht=V-1,Et=N.length;++ht<Et;)if(N[ht]===G)return ht;return-1}function M1(N,G,V){for(var ht=V+1;ht--;)if(N[ht]===G)return ht;return ht}function us(N){return ui(N)?vl(N):J3(N)}function Xn(N){return ui(N)?ta(N):x1(N)}function Kc(N){for(var G=N.length;G--&&m3.test(N.charAt(G)););return G}var Xc=Cd(V3);function vl(N){for(var G=sd.lastIndex=0;sd.test(N);)++G;return G}function ta(N){return N.match(sd)||[]}function R1(N){return N.match(P3)||[]}var ea=function N(G){G=G==null?Ge:fi.defaults(Ge.Object(),G,fi.pick(Ge,H3));var V=G.Array,ht=G.Date,Et=G.Error,Vt=G.Function,we=G.Math,qt=G.Object,na=G.RegExp,vd=G.String,kn=G.TypeError,yl=V.prototype,yd=Vt.prototype,mi=qt.prototype,kl=G["__core-js_shared__"],gi=yd.toString,Wt=mi.hasOwnProperty,O1=0,kd=function(){var c=/[^.]+$/.exec(kl&&kl.keys&&kl.keys.IE_PROTO||"");return c?"Symbol(src)_1."+c:""}(),wl=mi.toString,wd=gi.call(qt),_1=Ge._,F1=na("^"+gi.call(Wt).replace(Yu,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),pi=zc?G.Buffer:e,Ko=G.Symbol,Bl=G.Uint8Array,El=pi?pi.allocUnsafe:e,Tr=Yc(qt.getPrototypeOf,qt),xl=qt.create,Bd=mi.propertyIsEnumerable,Il=yl.splice,P1=Ko?Ko.isConcatSpreadable:e,Tl=Ko?Ko.iterator:e,Ci=Ko?Ko.toStringTag:e,Ai=function(){try{var c=Fl(qt,"defineProperty");return c({},"",{}),c}catch{}}(),N1=G.clearTimeout!==Ge.clearTimeout&&G.clearTimeout,$1=ht&&ht.now!==Ge.Date.now&&ht.now,H1=G.setTimeout!==Ge.setTimeout&&G.setTimeout,Dl=we.ceil,Sl=we.floor,Ll=qt.getOwnPropertySymbols,j1=pi?pi.isBuffer:e,Ed=G.isFinite,K3=yl.join,k=Yc(qt.keys,qt),T=we.max,L=we.min,F=ht.now,U=G.parseInt,j=we.random,Z=yl.reverse,J=Fl(G,"DataView"),lt=Fl(G,"Map"),pt=Fl(G,"Promise"),ct=Fl(G,"Set"),At=Fl(G,"WeakMap"),Gt=Fl(qt,"create"),Te=At&&new At,en={},Fn=Pl(J),bo=Pl(lt),X3=Pl(pt),t5=Pl(ct),de=Pl(At),re=Ko?Ko.prototype:e,ge=re?re.valueOf:e,vo=re?re.toString:e;function E(c){if(Be(c)&&!St(c)&&!(c instanceof Pt)){if(c instanceof Pn)return c;if(Wt.call(c,"__wrapped__"))return Fw(c)}return new Pn(c)}var Dr=function(){function c(){}return function(u){if(!ve(u))return{};if(xl)return xl(u);c.prototype=u;var f=new c;return c.prototype=e,f}}();function ds(){}function Pn(c,u){this.__wrapped__=c,this.__actions__=[],this.__chain__=!!u,this.__index__=0,this.__values__=e}E.templateSettings={escape:c3,evaluate:a3,interpolate:f1,variable:"",imports:{_:E}},E.prototype=ds.prototype,E.prototype.constructor=E,Pn.prototype=Dr(ds.prototype),Pn.prototype.constructor=Pn;function Pt(c){this.__wrapped__=c,this.__actions__=[],this.__dir__=1,this.__filtered__=!1,this.__iteratees__=[],this.__takeCount__=po,this.__views__=[]}function rQ(){var c=new Pt(this.__wrapped__);return c.__actions__=Nn(this.__actions__),c.__dir__=this.__dir__,c.__filtered__=this.__filtered__,c.__iteratees__=Nn(this.__iteratees__),c.__takeCount__=this.__takeCount__,c.__views__=Nn(this.__views__),c}function iQ(){if(this.__filtered__){var c=new Pt(this);c.__dir__=-1,c.__filtered__=!0}else c=this.clone(),c.__dir__*=-1;return c}function sQ(){var c=this.__wrapped__.value(),u=this.__dir__,f=St(c),C=u<0,y=f?c.length:0,I=AY(0,y,this.__views__),O=I.start,P=I.end,$=P-O,Q=C?P:O-1,Y=this.__iteratees__,X=Y.length,dt=0,Ct=L($,this.__takeCount__);if(!f||!C&&y==$&&Ct==$)return iw(c,this.__actions__);var yt=[];t:for(;$--&&dt<Ct;){Q+=u;for(var Ot=-1,kt=c[Q];++Ot<X;){var $t=Y[Ot],zt=$t.iteratee,no=$t.type,En=zt(kt);if(no==Rn)kt=En;else if(!En){if(no==$e)continue t;break t}}yt[dt++]=kt}return yt}Pt.prototype=Dr(ds.prototype),Pt.prototype.constructor=Pt;function Ml(c){var u=-1,f=c==null?0:c.length;for(this.clear();++u<f;){var C=c[u];this.set(C[0],C[1])}}function lQ(){this.__data__=Gt?Gt(null):{},this.size=0}function cQ(c){var u=this.has(c)&&delete this.__data__[c];return this.size-=u?1:0,u}function aQ(c){var u=this.__data__;if(Gt){var f=u[c];return f===a?e:f}return Wt.call(u,c)?u[c]:e}function uQ(c){var u=this.__data__;return Gt?u[c]!==e:Wt.call(u,c)}function dQ(c,u){var f=this.__data__;return this.size+=this.has(c)?0:1,f[c]=Gt&&u===e?a:u,this}Ml.prototype.clear=lQ,Ml.prototype.delete=cQ,Ml.prototype.get=aQ,Ml.prototype.has=uQ,Ml.prototype.set=dQ;function bi(c){var u=-1,f=c==null?0:c.length;for(this.clear();++u<f;){var C=c[u];this.set(C[0],C[1])}}function hQ(){this.__data__=[],this.size=0}function fQ(c){var u=this.__data__,f=U1(u,c);if(f<0)return!1;var C=u.length-1;return f==C?u.pop():Il.call(u,f,1),--this.size,!0}function mQ(c){var u=this.__data__,f=U1(u,c);return f<0?e:u[f][1]}function gQ(c){return U1(this.__data__,c)>-1}function pQ(c,u){var f=this.__data__,C=U1(f,c);return C<0?(++this.size,f.push([c,u])):f[C][1]=u,this}bi.prototype.clear=hQ,bi.prototype.delete=fQ,bi.prototype.get=mQ,bi.prototype.has=gQ,bi.prototype.set=pQ;function vi(c){var u=-1,f=c==null?0:c.length;for(this.clear();++u<f;){var C=c[u];this.set(C[0],C[1])}}function CQ(){this.size=0,this.__data__={hash:new Ml,map:new(lt||bi),string:new Ml}}function AQ(c){var u=tm(this,c).delete(c);return this.size-=u?1:0,u}function bQ(c){return tm(this,c).get(c)}function vQ(c){return tm(this,c).has(c)}function yQ(c,u){var f=tm(this,c),C=f.size;return f.set(c,u),this.size+=f.size==C?0:1,this}vi.prototype.clear=CQ,vi.prototype.delete=AQ,vi.prototype.get=bQ,vi.prototype.has=vQ,vi.prototype.set=yQ;function Rl(c){var u=-1,f=c==null?0:c.length;for(this.__data__=new vi;++u<f;)this.add(c[u])}function kQ(c){return this.__data__.set(c,a),this}function wQ(c){return this.__data__.has(c)}Rl.prototype.add=Rl.prototype.push=kQ,Rl.prototype.has=wQ;function Xo(c){var u=this.__data__=new bi(c);this.size=u.size}function BQ(){this.__data__=new bi,this.size=0}function EQ(c){var u=this.__data__,f=u.delete(c);return this.size=u.size,f}function xQ(c){return this.__data__.get(c)}function IQ(c){return this.__data__.has(c)}function TQ(c,u){var f=this.__data__;if(f instanceof bi){var C=f.__data__;if(!lt||C.length<r-1)return C.push([c,u]),this.size=++f.size,this;f=this.__data__=new vi(C)}return f.set(c,u),this.size=f.size,this}Xo.prototype.clear=BQ,Xo.prototype.delete=EQ,Xo.prototype.get=xQ,Xo.prototype.has=IQ,Xo.prototype.set=TQ;function Fk(c,u){var f=St(c),C=!f&&Nl(c),y=!f&&!C&&ps(c),I=!f&&!C&&!y&&sa(c),O=f||C||y||I,P=O?Zc(c.length,vd):[],$=P.length;for(var Q in c)(u||Wt.call(c,Q))&&!(O&&(Q=="length"||y&&(Q=="offset"||Q=="parent")||I&&(Q=="buffer"||Q=="byteLength"||Q=="byteOffset")||Bi(Q,$)))&&P.push(Q);return P}function Pk(c){var u=c.length;return u?c[d5(0,u-1)]:e}function DQ(c,u){return em(Nn(c),Ol(u,0,c.length))}function SQ(c){return em(Nn(c))}function e5(c,u,f){(f!==e&&!tr(c[u],f)||f===e&&!(u in c))&&yi(c,u,f)}function xd(c,u,f){var C=c[u];(!(Wt.call(c,u)&&tr(C,f))||f===e&&!(u in c))&&yi(c,u,f)}function U1(c,u){for(var f=c.length;f--;)if(tr(c[f][0],u))return f;return-1}function LQ(c,u,f,C){return hs(c,function(y,I,O){u(C,y,f(y),O)}),C}function Nk(c,u){return c&&Lr(u,Ke(u),c)}function MQ(c,u){return c&&Lr(u,Hn(u),c)}function yi(c,u,f){u=="__proto__"&&Ai?Ai(c,u,{configurable:!0,enumerable:!0,value:f,writable:!0}):c[u]=f}function n5(c,u){for(var f=-1,C=u.length,y=V(C),I=c==null;++f<C;)y[f]=I?e:F5(c,u[f]);return y}function Ol(c,u,f){return c===c&&(f!==e&&(c=c<=f?c:f),u!==e&&(c=c>=u?c:u)),c}function yo(c,u,f,C,y,I){var O,P=u&p,$=u&A,Q=u&v;if(f&&(O=y?f(c,C,y,I):f(c)),O!==e)return O;if(!ve(c))return c;var Y=St(c);if(Y){if(O=vY(c),!P)return Nn(c,O)}else{var X=hn(c),dt=X==Fc||X==s1;if(ps(c))return cw(c,P);if(X==Co||X==ns||dt&&!y){if(O=$||dt?{}:Iw(c),!P)return $?aY(c,MQ(O,c)):cY(c,Nk(O,c))}else{if(!oe[X])return y?c:{};O=yY(c,X,P)}}I||(I=new Xo);var Ct=I.get(c);if(Ct)return Ct;I.set(c,O),nB(c)?c.forEach(function(kt){O.add(yo(kt,u,f,kt,c,I))}):tB(c)&&c.forEach(function(kt,$t){O.set($t,yo(kt,u,f,$t,c,I))});var yt=Q?$?k5:y5:$?Hn:Ke,Ot=Y?e:yt(c);return _n(Ot||c,function(kt,$t){Ot&&($t=kt,kt=c[$t]),xd(O,$t,yo(kt,u,f,$t,c,I))}),O}function RQ(c){var u=Ke(c);return function(f){return $k(f,c,u)}}function $k(c,u,f){var C=f.length;if(c==null)return!C;for(c=qt(c);C--;){var y=f[C],I=u[y],O=c[y];if(O===e&&!(y in c)||!I(O))return!1}return!0}function Hk(c,u,f){if(typeof c!="function")throw new kn(s);return Rd(function(){c.apply(e,f)},u)}function Id(c,u,f,C){var y=-1,I=Vc,O=!0,P=c.length,$=[],Q=u.length;if(!P)return $;f&&(u=ue(u,dn(f))),C?(I=fd,O=!1):u.length>=r&&(I=Jo,O=!1,u=new Rl(u));t:for(;++y<P;){var Y=c[y],X=f==null?Y:f(Y);if(Y=C||Y!==0?Y:0,O&&X===X){for(var dt=Q;dt--;)if(u[dt]===X)continue t;$.push(Y)}else I(u,X,C)||$.push(Y)}return $}var hs=fw(Sr),jk=fw(r5,!0);function OQ(c,u){var f=!0;return hs(c,function(C,y,I){return f=!!u(C,y,I),f}),f}function z1(c,u,f){for(var C=-1,y=c.length;++C<y;){var I=c[C],O=u(I);if(O!=null&&(P===e?O===O&&!eo(O):f(O,P)))var P=O,$=I}return $}function _Q(c,u,f,C){var y=c.length;for(f=Rt(f),f<0&&(f=-f>y?0:y+f),C=C===e||C>y?y:Rt(C),C<0&&(C+=y),C=f>C?0:rB(C);f<C;)c[f++]=u;return c}function Uk(c,u){var f=[];return hs(c,function(C,y,I){u(C,y,I)&&f.push(C)}),f}function nn(c,u,f,C,y){var I=-1,O=c.length;for(f||(f=wY),y||(y=[]);++I<O;){var P=c[I];u>0&&f(P)?u>1?nn(P,u-1,f,C,y):Ir(y,P):C||(y[y.length]=P)}return y}var o5=mw(),zk=mw(!0);function Sr(c,u){return c&&o5(c,u,Ke)}function r5(c,u){return c&&zk(c,u,Ke)}function V1(c,u){return Qo(u,function(f){return Ei(c[f])})}function _l(c,u){u=ms(u,c);for(var f=0,C=u.length;c!=null&&f<C;)c=c[Mr(u[f++])];return f&&f==C?c:e}function Vk(c,u,f){var C=u(c);return St(c)?C:Ir(C,f(c))}function wn(c){return c==null?c===e?a1:l1:Ci&&Ci in qt(c)?CY(c):SY(c)}function i5(c,u){return c>u}function FQ(c,u){return c!=null&&Wt.call(c,u)}function PQ(c,u){return c!=null&&u in qt(c)}function NQ(c,u,f){return c>=L(u,f)&&c<T(u,f)}function s5(c,u,f){for(var C=f?fd:Vc,y=c[0].length,I=c.length,O=I,P=V(I),$=1/0,Q=[];O--;){var Y=c[O];O&&u&&(Y=ue(Y,dn(u))),$=L(Y.length,$),P[O]=!f&&(u||y>=120&&Y.length>=120)?new Rl(O&&Y):e}Y=c[0];var X=-1,dt=P[0];t:for(;++X<y&&Q.length<$;){var Ct=Y[X],yt=u?u(Ct):Ct;if(Ct=f||Ct!==0?Ct:0,!(dt?Jo(dt,yt):C(Q,yt,f))){for(O=I;--O;){var Ot=P[O];if(!(Ot?Jo(Ot,yt):C(c[O],yt,f)))continue t}dt&&dt.push(yt),Q.push(Ct)}}return Q}function $Q(c,u,f,C){return Sr(c,function(y,I,O){u(C,f(y),I,O)}),C}function Td(c,u,f){u=ms(u,c),c=Lw(c,u);var C=c==null?c:c[Mr(wo(u))];return C==null?e:yn(C,c,f)}function Wk(c){return Be(c)&&wn(c)==ns}function HQ(c){return Be(c)&&wn(c)==al}function jQ(c){return Be(c)&&wn(c)==Nt}function Dd(c,u,f,C,y){return c===u?!0:c==null||u==null||!Be(c)&&!Be(u)?c!==c&&u!==u:UQ(c,u,f,C,Dd,y)}function UQ(c,u,f,C,y,I){var O=St(c),P=St(u),$=O?nl:hn(c),Q=P?nl:hn(u);$=$==ns?Co:$,Q=Q==ns?Co:Q;var Y=$==Co,X=Q==Co,dt=$==Q;if(dt&&ps(c)){if(!ps(u))return!1;O=!0,Y=!1}if(dt&&!Y)return I||(I=new Xo),O||sa(c)?Bw(c,u,f,C,y,I):gY(c,u,$,f,C,y,I);if(!(f&B)){var Ct=Y&&Wt.call(c,"__wrapped__"),yt=X&&Wt.call(u,"__wrapped__");if(Ct||yt){var Ot=Ct?c.value():c,kt=yt?u.value():u;return I||(I=new Xo),y(Ot,kt,f,C,I)}}return dt?(I||(I=new Xo),pY(c,u,f,C,y,I)):!1}function zQ(c){return Be(c)&&hn(c)==un}function l5(c,u,f,C){var y=f.length,I=y,O=!C;if(c==null)return!I;for(c=qt(c);y--;){var P=f[y];if(O&&P[2]?P[1]!==c[P[0]]:!(P[0]in c))return!1}for(;++y<I;){P=f[y];var $=P[0],Q=c[$],Y=P[1];if(O&&P[2]){if(Q===e&&!($ in c))return!1}else{var X=new Xo;if(C)var dt=C(Q,Y,$,c,u,X);if(!(dt===e?Dd(Y,Q,B|D,C,X):dt))return!1}}return!0}function qk(c){if(!ve(c)||EY(c))return!1;var u=Ei(c)?F1:b3;return u.test(Pl(c))}function VQ(c){return Be(c)&&wn(c)==il}function WQ(c){return Be(c)&&hn(c)==be}function qQ(c){return Be(c)&&lm(c.length)&&!!le[wn(c)]}function Gk(c){return typeof c=="function"?c:c==null?jn:typeof c=="object"?St(c)?Yk(c[0],c[1]):Qk(c):gB(c)}function c5(c){if(!Md(c))return k(c);var u=[];for(var f in qt(c))Wt.call(c,f)&&f!="constructor"&&u.push(f);return u}function GQ(c){if(!ve(c))return DY(c);var u=Md(c),f=[];for(var C in c)C=="constructor"&&(u||!Wt.call(c,C))||f.push(C);return f}function a5(c,u){return c<u}function Zk(c,u){var f=-1,C=$n(c)?V(c.length):[];return hs(c,function(y,I,O){C[++f]=u(y,I,O)}),C}function Qk(c){var u=B5(c);return u.length==1&&u[0][2]?Dw(u[0][0],u[0][1]):function(f){return f===c||l5(f,c,u)}}function Yk(c,u){return x5(c)&&Tw(u)?Dw(Mr(c),u):function(f){var C=F5(f,c);return C===e&&C===u?P5(f,c):Dd(u,C,B|D)}}function W1(c,u,f,C,y){c!==u&&o5(u,function(I,O){if(y||(y=new Xo),ve(I))ZQ(c,u,O,f,W1,C,y);else{var P=C?C(T5(c,O),I,O+"",c,u,y):e;P===e&&(P=I),e5(c,O,P)}},Hn)}function ZQ(c,u,f,C,y,I,O){var P=T5(c,f),$=T5(u,f),Q=O.get($);if(Q){e5(c,f,Q);return}var Y=I?I(P,$,f+"",c,u,O):e,X=Y===e;if(X){var dt=St($),Ct=!dt&&ps($),yt=!dt&&!Ct&&sa($);Y=$,dt||Ct||yt?St(P)?Y=P:De(P)?Y=Nn(P):Ct?(X=!1,Y=cw($,!0)):yt?(X=!1,Y=aw($,!0)):Y=[]:Od($)||Nl($)?(Y=P,Nl(P)?Y=iB(P):(!ve(P)||Ei(P))&&(Y=Iw($))):X=!1}X&&(O.set($,Y),y(Y,$,C,I,O),O.delete($)),e5(c,f,Y)}function Jk(c,u){var f=c.length;if(!!f)return u+=u<0?f:0,Bi(u,f)?c[u]:e}function Kk(c,u,f){u.length?u=ue(u,function(I){return St(I)?function(O){return _l(O,I.length===1?I[0]:I)}:I}):u=[jn];var C=-1;u=ue(u,dn(vt()));var y=Zk(c,function(I,O,P){var $=ue(u,function(Q){return Q(I)});return{criteria:$,index:++C,value:I}});return I1(y,function(I,O){return lY(I,O,f)})}function QQ(c,u){return Xk(c,u,function(f,C){return P5(c,C)})}function Xk(c,u,f){for(var C=-1,y=u.length,I={};++C<y;){var O=u[C],P=_l(c,O);f(P,O)&&Sd(I,ms(O,c),P)}return I}function YQ(c){return function(u){return _l(u,c)}}function u5(c,u,f,C){var y=C?cs:ci,I=-1,O=u.length,P=c;for(c===u&&(u=Nn(u)),f&&(P=ue(c,dn(f)));++I<O;)for(var $=0,Q=u[I],Y=f?f(Q):Q;($=y(P,Y,$,C))>-1;)P!==c&&Il.call(P,$,1),Il.call(c,$,1);return c}function tw(c,u){for(var f=c?u.length:0,C=f-1;f--;){var y=u[f];if(f==C||y!==I){var I=y;Bi(y)?Il.call(c,y,1):m5(c,y)}}return c}function d5(c,u){return c+Sl(j()*(u-c+1))}function JQ(c,u,f,C){for(var y=-1,I=T(Dl((u-c)/(f||1)),0),O=V(I);I--;)O[C?I:++y]=c,c+=f;return O}function h5(c,u){var f="";if(!c||u<1||u>an)return f;do u%2&&(f+=c),u=Sl(u/2),u&&(c+=c);while(u);return f}function _t(c,u){return D5(Sw(c,u,jn),c+"")}function KQ(c){return Pk(la(c))}function XQ(c,u){var f=la(c);return em(f,Ol(u,0,f.length))}function Sd(c,u,f,C){if(!ve(c))return c;u=ms(u,c);for(var y=-1,I=u.length,O=I-1,P=c;P!=null&&++y<I;){var $=Mr(u[y]),Q=f;if($==="__proto__"||$==="constructor"||$==="prototype")return c;if(y!=O){var Y=P[$];Q=C?C(Y,$,P):e,Q===e&&(Q=ve(Y)?Y:Bi(u[y+1])?[]:{})}xd(P,$,Q),P=P[$]}return c}var ew=Te?function(c,u){return Te.set(c,u),c}:jn,tY=Ai?function(c,u){return Ai(c,"toString",{configurable:!0,enumerable:!1,value:$5(u),writable:!0})}:jn;function eY(c){return em(la(c))}function ko(c,u,f){var C=-1,y=c.length;u<0&&(u=-u>y?0:y+u),f=f>y?y:f,f<0&&(f+=y),y=u>f?0:f-u>>>0,u>>>=0;for(var I=V(y);++C<y;)I[C]=c[C+u];return I}function nY(c,u){var f;return hs(c,function(C,y,I){return f=u(C,y,I),!f}),!!f}function q1(c,u,f){var C=0,y=c==null?C:c.length;if(typeof u=="number"&&u===u&&y<=t3){for(;C<y;){var I=C+y>>>1,O=c[I];O!==null&&!eo(O)&&(f?O<=u:O<u)?C=I+1:y=I}return y}return f5(c,u,jn,f)}function f5(c,u,f,C){var y=0,I=c==null?0:c.length;if(I===0)return 0;u=f(u);for(var O=u!==u,P=u===null,$=eo(u),Q=u===e;y<I;){var Y=Sl((y+I)/2),X=f(c[Y]),dt=X!==e,Ct=X===null,yt=X===X,Ot=eo(X);if(O)var kt=C||yt;else Q?kt=yt&&(C||dt):P?kt=yt&&dt&&(C||!Ct):$?kt=yt&&dt&&!Ct&&(C||!Ot):Ct||Ot?kt=!1:kt=C?X<=u:X<u;kt?y=Y+1:I=Y}return L(I,X2)}function nw(c,u){for(var f=-1,C=c.length,y=0,I=[];++f<C;){var O=c[f],P=u?u(O):O;if(!f||!tr(P,$)){var $=P;I[y++]=O===0?0:O}}return I}function ow(c){return typeof c=="number"?c:eo(c)?oi:+c}function to(c){if(typeof c=="string")return c;if(St(c))return ue(c,to)+"";if(eo(c))return vo?vo.call(c):"";var u=c+"";return u=="0"&&1/c==-vn?"-0":u}function fs(c,u,f){var C=-1,y=Vc,I=c.length,O=!0,P=[],$=P;if(f)O=!1,y=fd;else if(I>=r){var Q=u?null:fY(c);if(Q)return hi(Q);O=!1,y=Jo,$=new Rl}else $=u?[]:P;t:for(;++C<I;){var Y=c[C],X=u?u(Y):Y;if(Y=f||Y!==0?Y:0,O&&X===X){for(var dt=$.length;dt--;)if($[dt]===X)continue t;u&&$.push(X),P.push(Y)}else y($,X,f)||($!==P&&$.push(X),P.push(Y))}return P}function m5(c,u){return u=ms(u,c),c=Lw(c,u),c==null||delete c[Mr(wo(u))]}function rw(c,u,f,C){return Sd(c,u,f(_l(c,u)),C)}function G1(c,u,f,C){for(var y=c.length,I=C?y:-1;(C?I--:++I<y)&&u(c[I],I,c););return f?ko(c,C?0:I,C?I+1:y):ko(c,C?I+1:0,C?y:I)}function iw(c,u){var f=c;return f instanceof Pt&&(f=f.value()),md(u,function(C,y){return y.func.apply(y.thisArg,Ir([C],y.args))},f)}function g5(c,u,f){var C=c.length;if(C<2)return C?fs(c[0]):[];for(var y=-1,I=V(C);++y<C;)for(var O=c[y],P=-1;++P<C;)P!=y&&(I[y]=Id(I[y]||O,c[P],u,f));return fs(nn(I,1),u,f)}function sw(c,u,f){for(var C=-1,y=c.length,I=u.length,O={};++C<y;){var P=C<I?u[C]:e;f(O,c[C],P)}return O}function p5(c){return De(c)?c:[]}function C5(c){return typeof c=="function"?c:jn}function ms(c,u){return St(c)?c:x5(c,u)?[c]:_w(Kt(c))}var oY=_t;function gs(c,u,f){var C=c.length;return f=f===e?C:f,!u&&f>=C?c:ko(c,u,f)}var lw=N1||function(c){return Ge.clearTimeout(c)};function cw(c,u){if(u)return c.slice();var f=c.length,C=El?El(f):new c.constructor(f);return c.copy(C),C}function A5(c){var u=new c.constructor(c.byteLength);return new Bl(u).set(new Bl(c)),u}function rY(c,u){var f=u?A5(c.buffer):c.buffer;return new c.constructor(f,c.byteOffset,c.byteLength)}function iY(c){var u=new c.constructor(c.source,Pc.exec(c));return u.lastIndex=c.lastIndex,u}function sY(c){return ge?qt(ge.call(c)):{}}function aw(c,u){var f=u?A5(c.buffer):c.buffer;return new c.constructor(f,c.byteOffset,c.length)}function uw(c,u){if(c!==u){var f=c!==e,C=c===null,y=c===c,I=eo(c),O=u!==e,P=u===null,$=u===u,Q=eo(u);if(!P&&!Q&&!I&&c>u||I&&O&&$&&!P&&!Q||C&&O&&$||!f&&$||!y)return 1;if(!C&&!I&&!Q&&c<u||Q&&f&&y&&!C&&!I||P&&f&&y||!O&&y||!$)return-1}return 0}function lY(c,u,f){for(var C=-1,y=c.criteria,I=u.criteria,O=y.length,P=f.length;++C<O;){var $=uw(y[C],I[C]);if($){if(C>=P)return $;var Q=f[C];return $*(Q=="desc"?-1:1)}}return c.index-u.index}function dw(c,u,f,C){for(var y=-1,I=c.length,O=f.length,P=-1,$=u.length,Q=T(I-O,0),Y=V($+Q),X=!C;++P<$;)Y[P]=u[P];for(;++y<O;)(X||y<I)&&(Y[f[y]]=c[y]);for(;Q--;)Y[P++]=c[y++];return Y}function hw(c,u,f,C){for(var y=-1,I=c.length,O=-1,P=f.length,$=-1,Q=u.length,Y=T(I-P,0),X=V(Y+Q),dt=!C;++y<Y;)X[y]=c[y];for(var Ct=y;++$<Q;)X[Ct+$]=u[$];for(;++O<P;)(dt||y<I)&&(X[Ct+f[O]]=c[y++]);return X}function Nn(c,u){var f=-1,C=c.length;for(u||(u=V(C));++f<C;)u[f]=c[f];return u}function Lr(c,u,f,C){var y=!f;f||(f={});for(var I=-1,O=u.length;++I<O;){var P=u[I],$=C?C(f[P],c[P],P,f,c):e;$===e&&($=c[P]),y?yi(f,P,$):xd(f,P,$)}return f}function cY(c,u){return Lr(c,E5(c),u)}function aY(c,u){return Lr(c,Ew(c),u)}function Z1(c,u){return function(f,C){var y=St(f)?Z3:LQ,I=u?u():{};return y(f,c,vt(C,2),I)}}function oa(c){return _t(function(u,f){var C=-1,y=f.length,I=y>1?f[y-1]:e,O=y>2?f[2]:e;for(I=c.length>3&&typeof I=="function"?(y--,I):e,O&&Bn(f[0],f[1],O)&&(I=y<3?e:I,y=1),u=qt(u);++C<y;){var P=f[C];P&&c(u,P,C,I)}return u})}function fw(c,u){return function(f,C){if(f==null)return f;if(!$n(f))return c(f,C);for(var y=f.length,I=u?y:-1,O=qt(f);(u?I--:++I<y)&&C(O[I],I,O)!==!1;);return f}}function mw(c){return function(u,f,C){for(var y=-1,I=qt(u),O=C(u),P=O.length;P--;){var $=O[c?P:++y];if(f(I[$],$,I)===!1)break}return u}}function uY(c,u,f){var C=u&x,y=Ld(c);function I(){var O=this&&this!==Ge&&this instanceof I?y:c;return O.apply(C?f:this,arguments)}return I}function gw(c){return function(u){u=Kt(u);var f=ui(u)?Xn(u):e,C=f?f[0]:u.charAt(0),y=f?gs(f,1).join(""):u.slice(1);return C[c]()+y}}function ra(c){return function(u){return md(fB(hB(u).replace(_3,"")),c,"")}}function Ld(c){return function(){var u=arguments;switch(u.length){case 0:return new c;case 1:return new c(u[0]);case 2:return new c(u[0],u[1]);case 3:return new c(u[0],u[1],u[2]);case 4:return new c(u[0],u[1],u[2],u[3]);case 5:return new c(u[0],u[1],u[2],u[3],u[4]);case 6:return new c(u[0],u[1],u[2],u[3],u[4],u[5]);case 7:return new c(u[0],u[1],u[2],u[3],u[4],u[5],u[6])}var f=Dr(c.prototype),C=c.apply(f,u);return ve(C)?C:f}}function dY(c,u,f){var C=Ld(c);function y(){for(var I=arguments.length,O=V(I),P=I,$=ia(y);P--;)O[P]=arguments[P];var Q=I<3&&O[0]!==$&&O[I-1]!==$?[]:Kn(O,$);if(I-=Q.length,I<f)return vw(c,u,Q1,y.placeholder,e,O,Q,e,e,f-I);var Y=this&&this!==Ge&&this instanceof y?C:c;return yn(Y,this,O)}return y}function pw(c){return function(u,f,C){var y=qt(u);if(!$n(u)){var I=vt(f,3);u=Ke(u),f=function(P){return I(y[P],P,y)}}var O=c(u,f,C);return O>-1?y[I?u[O]:O]:e}}function Cw(c){return wi(function(u){var f=u.length,C=f,y=Pn.prototype.thru;for(c&&u.reverse();C--;){var I=u[C];if(typeof I!="function")throw new kn(s);if(y&&!O&&X1(I)=="wrapper")var O=new Pn([],!0)}for(C=O?C:f;++C<f;){I=u[C];var P=X1(I),$=P=="wrapper"?w5(I):e;$&&I5($[0])&&$[1]==(ft|H|q|Bt)&&!$[4].length&&$[9]==1?O=O[X1($[0])].apply(O,$[3]):O=I.length==1&&I5(I)?O[P]():O.thru(I)}return function(){var Q=arguments,Y=Q[0];if(O&&Q.length==1&&St(Y))return O.plant(Y).value();for(var X=0,dt=f?u[X].apply(this,Q):Y;++X<f;)dt=u[X].call(this,dt);return dt}})}function Q1(c,u,f,C,y,I,O,P,$,Q){var Y=u&ft,X=u&x,dt=u&_,Ct=u&(H|z),yt=u&jt,Ot=dt?e:Ld(c);function kt(){for(var $t=arguments.length,zt=V($t),no=$t;no--;)zt[no]=arguments[no];if(Ct)var En=ia(kt),oo=T1(zt,En);if(C&&(zt=dw(zt,C,y,Ct)),I&&(zt=hw(zt,I,O,Ct)),$t-=oo,Ct&&$t<Q){var Se=Kn(zt,En);return vw(c,u,Q1,kt.placeholder,f,zt,Se,P,$,Q-$t)}var er=X?f:this,Ii=dt?er[c]:c;return $t=zt.length,P?zt=LY(zt,P):yt&&$t>1&&zt.reverse(),Y&&$<$t&&(zt.length=$),this&&this!==Ge&&this instanceof kt&&(Ii=Ot||Ld(Ii)),Ii.apply(er,zt)}return kt}function Aw(c,u){return function(f,C){return $Q(f,c,u(C),{})}}function Y1(c,u){return function(f,C){var y;if(f===e&&C===e)return u;if(f!==e&&(y=f),C!==e){if(y===e)return C;typeof f=="string"||typeof C=="string"?(f=to(f),C=to(C)):(f=ow(f),C=ow(C)),y=c(f,C)}return y}}function b5(c){return wi(function(u){return u=ue(u,dn(vt())),_t(function(f){var C=this;return c(u,function(y){return yn(y,C,f)})})})}function J1(c,u){u=u===e?" ":to(u);var f=u.length;if(f<2)return f?h5(u,c):u;var C=h5(u,Dl(c/us(u)));return ui(u)?gs(Xn(C),0,c).join(""):C.slice(0,c)}function hY(c,u,f,C){var y=u&x,I=Ld(c);function O(){for(var P=-1,$=arguments.length,Q=-1,Y=C.length,X=V(Y+$),dt=this&&this!==Ge&&this instanceof O?I:c;++Q<Y;)X[Q]=C[Q];for(;$--;)X[Q++]=arguments[++P];return yn(dt,y?f:this,X)}return O}function bw(c){return function(u,f,C){return C&&typeof C!="number"&&Bn(u,f,C)&&(f=C=e),u=xi(u),f===e?(f=u,u=0):f=xi(f),C=C===e?u<f?1:-1:xi(C),JQ(u,f,C,c)}}function K1(c){return function(u,f){return typeof u=="string"&&typeof f=="string"||(u=Bo(u),f=Bo(f)),c(u,f)}}function vw(c,u,f,C,y,I,O,P,$,Q){var Y=u&H,X=Y?O:e,dt=Y?e:O,Ct=Y?I:e,yt=Y?e:I;u|=Y?q:rt,u&=~(Y?rt:q),u&M||(u&=~(x|_));var Ot=[c,u,y,Ct,X,yt,dt,P,$,Q],kt=f.apply(e,Ot);return I5(c)&&Mw(kt,Ot),kt.placeholder=C,Rw(kt,c,u)}function v5(c){var u=we[c];return function(f,C){if(f=Bo(f),C=C==null?0:L(Rt(C),292),C&&Ed(f)){var y=(Kt(f)+"e").split("e"),I=u(y[0]+"e"+(+y[1]+C));return y=(Kt(I)+"e").split("e"),+(y[0]+"e"+(+y[1]-C))}return u(f)}}var fY=ct&&1/hi(new ct([,-0]))[1]==vn?function(c){return new ct(c)}:U5;function yw(c){return function(u){var f=hn(u);return f==un?di(u):f==be?bl(u):pl(u,c(u))}}function ki(c,u,f,C,y,I,O,P){var $=u&_;if(!$&&typeof c!="function")throw new kn(s);var Q=C?C.length:0;if(Q||(u&=~(q|rt),C=y=e),O=O===e?O:T(Rt(O),0),P=P===e?P:Rt(P),Q-=y?y.length:0,u&rt){var Y=C,X=y;C=y=e}var dt=$?e:w5(c),Ct=[c,u,f,C,y,Y,X,I,O,P];if(dt&&TY(Ct,dt),c=Ct[0],u=Ct[1],f=Ct[2],C=Ct[3],y=Ct[4],P=Ct[9]=Ct[9]===e?$?0:c.length:T(Ct[9]-Q,0),!P&&u&(H|z)&&(u&=~(H|z)),!u||u==x)var yt=uY(c,u,f);else u==H||u==z?yt=dY(c,u,P):(u==q||u==(x|q))&&!y.length?yt=hY(c,u,f,C):yt=Q1.apply(e,Ct);var Ot=dt?ew:Mw;return Rw(Ot(yt,Ct),c,u)}function kw(c,u,f,C){return c===e||tr(c,mi[f])&&!Wt.call(C,f)?u:c}function ww(c,u,f,C,y,I){return ve(c)&&ve(u)&&(I.set(u,c),W1(c,u,e,ww,I),I.delete(u)),c}function mY(c){return Od(c)?e:c}function Bw(c,u,f,C,y,I){var O=f&B,P=c.length,$=u.length;if(P!=$&&!(O&&$>P))return!1;var Q=I.get(c),Y=I.get(u);if(Q&&Y)return Q==u&&Y==c;var X=-1,dt=!0,Ct=f&D?new Rl:e;for(I.set(c,u),I.set(u,c);++X<P;){var yt=c[X],Ot=u[X];if(C)var kt=O?C(Ot,yt,X,u,c,I):C(yt,Ot,X,c,u,I);if(kt!==e){if(kt)continue;dt=!1;break}if(Ct){if(!gd(u,function($t,zt){if(!Jo(Ct,zt)&&(yt===$t||y(yt,$t,f,C,I)))return Ct.push(zt)})){dt=!1;break}}else if(!(yt===Ot||y(yt,Ot,f,C,I))){dt=!1;break}}return I.delete(c),I.delete(u),dt}function gY(c,u,f,C,y,I,O){switch(f){case rs:if(c.byteLength!=u.byteLength||c.byteOffset!=u.byteOffset)return!1;c=c.buffer,u=u.buffer;case al:return!(c.byteLength!=u.byteLength||!I(new Bl(c),new Bl(u)));case ri:case Nt:case rl:return tr(+c,+u);case os:return c.name==u.name&&c.message==u.message;case il:case sl:return c==u+"";case un:var P=di;case be:var $=C&B;if(P||(P=hi),c.size!=u.size&&!$)return!1;var Q=O.get(c);if(Q)return Q==u;C|=D,O.set(c,u);var Y=Bw(P(c),P(u),C,y,I,O);return O.delete(c),Y;case ll:if(ge)return ge.call(c)==ge.call(u)}return!1}function pY(c,u,f,C,y,I){var O=f&B,P=y5(c),$=P.length,Q=y5(u),Y=Q.length;if($!=Y&&!O)return!1;for(var X=$;X--;){var dt=P[X];if(!(O?dt in u:Wt.call(u,dt)))return!1}var Ct=I.get(c),yt=I.get(u);if(Ct&&yt)return Ct==u&&yt==c;var Ot=!0;I.set(c,u),I.set(u,c);for(var kt=O;++X<$;){dt=P[X];var $t=c[dt],zt=u[dt];if(C)var no=O?C(zt,$t,dt,u,c,I):C($t,zt,dt,c,u,I);if(!(no===e?$t===zt||y($t,zt,f,C,I):no)){Ot=!1;break}kt||(kt=dt=="constructor")}if(Ot&&!kt){var En=c.constructor,oo=u.constructor;En!=oo&&"constructor"in c&&"constructor"in u&&!(typeof En=="function"&&En instanceof En&&typeof oo=="function"&&oo instanceof oo)&&(Ot=!1)}return I.delete(c),I.delete(u),Ot}function wi(c){return D5(Sw(c,e,$w),c+"")}function y5(c){return Vk(c,Ke,E5)}function k5(c){return Vk(c,Hn,Ew)}var w5=Te?function(c){return Te.get(c)}:U5;function X1(c){for(var u=c.name+"",f=en[u],C=Wt.call(en,u)?f.length:0;C--;){var y=f[C],I=y.func;if(I==null||I==c)return y.name}return u}function ia(c){var u=Wt.call(E,"placeholder")?E:c;return u.placeholder}function vt(){var c=E.iteratee||H5;return c=c===H5?Gk:c,arguments.length?c(arguments[0],arguments[1]):c}function tm(c,u){var f=c.__data__;return BY(u)?f[typeof u=="string"?"string":"hash"]:f.map}function B5(c){for(var u=Ke(c),f=u.length;f--;){var C=u[f],y=c[C];u[f]=[C,y,Tw(y)]}return u}function Fl(c,u){var f=L1(c,u);return qk(f)?f:e}function CY(c){var u=Wt.call(c,Ci),f=c[Ci];try{c[Ci]=e;var C=!0}catch{}var y=wl.call(c);return C&&(u?c[Ci]=f:delete c[Ci]),y}var E5=Ll?function(c){return c==null?[]:(c=qt(c),Qo(Ll(c),function(u){return Bd.call(c,u)}))}:z5,Ew=Ll?function(c){for(var u=[];c;)Ir(u,E5(c)),c=Tr(c);return u}:z5,hn=wn;(J&&hn(new J(new ArrayBuffer(1)))!=rs||lt&&hn(new lt)!=un||pt&&hn(pt.resolve())!=c1||ct&&hn(new ct)!=be||At&&hn(new At)!=cl)&&(hn=function(c){var u=wn(c),f=u==Co?c.constructor:e,C=f?Pl(f):"";if(C)switch(C){case Fn:return rs;case bo:return un;case X3:return c1;case t5:return be;case de:return cl}return u});function AY(c,u,f){for(var C=-1,y=f.length;++C<y;){var I=f[C],O=I.size;switch(I.type){case"drop":c+=O;break;case"dropRight":u-=O;break;case"take":u=L(u,c+O);break;case"takeRight":c=T(c,u-O);break}}return{start:c,end:u}}function bY(c){var u=c.match(se);return u?u[1].split(p3):[]}function xw(c,u,f){u=ms(u,c);for(var C=-1,y=u.length,I=!1;++C<y;){var O=Mr(u[C]);if(!(I=c!=null&&f(c,O)))break;c=c[O]}return I||++C!=y?I:(y=c==null?0:c.length,!!y&&lm(y)&&Bi(O,y)&&(St(c)||Nl(c)))}function vY(c){var u=c.length,f=new c.constructor(u);return u&&typeof c[0]=="string"&&Wt.call(c,"index")&&(f.index=c.index,f.input=c.input),f}function Iw(c){return typeof c.constructor=="function"&&!Md(c)?Dr(Tr(c)):{}}function yY(c,u,f){var C=c.constructor;switch(u){case al:return A5(c);case ri:case Nt:return new C(+c);case rs:return rY(c,f);case ju:case Uu:case zu:case Vu:case Wu:case qu:case Gu:case Zu:case Qu:return aw(c,f);case un:return new C;case rl:case sl:return new C(c);case il:return iY(c);case be:return new C;case ll:return sY(c)}}function kY(c,u){var f=u.length;if(!f)return c;var C=f-1;return u[C]=(f>1?"& ":"")+u[C],u=u.join(f>2?", ":" "),c.replace(g3,`{
|
|
728
|
+
*/(function(n,t){(function(){var e,o="4.17.21",r=200,i="Unsupported core-js use. Try https://npms.io/search?q=ponyfill.",s="Expected a function",l="Invalid `variable` option passed into `_.template`",a="__lodash_hash_undefined__",d=500,h="__lodash_placeholder__",p=1,A=2,v=4,B=1,D=2,x=1,_=2,M=4,H=8,z=16,q=32,rt=64,ft=128,Bt=256,jt=512,Ut=30,ne="...",qe=800,Yn=16,$e=1,Rn=2,wr=3,vn=1/0,an=9007199254740991,Br=17976931348623157e292,oi=0/0,po=4294967295,X2=po-1,t3=po>>>1,e3=[["ary",ft],["bind",x],["bindKey",_],["curry",H],["curryRight",z],["flip",jt],["partial",q],["partialRight",rt],["rearg",Bt]],ns="[object Arguments]",nl="[object Array]",ol="[object AsyncFunction]",ri="[object Boolean]",Nt="[object Date]",Er="[object DOMException]",os="[object Error]",Fc="[object Function]",s1="[object GeneratorFunction]",un="[object Map]",rl="[object Number]",l1="[object Null]",Co="[object Object]",c1="[object Promise]",n3="[object Proxy]",il="[object RegExp]",be="[object Set]",sl="[object String]",ll="[object Symbol]",a1="[object Undefined]",cl="[object WeakMap]",u1="[object WeakSet]",al="[object ArrayBuffer]",rs="[object DataView]",ju="[object Float32Array]",Uu="[object Float64Array]",zu="[object Int8Array]",Vu="[object Int16Array]",Wu="[object Int32Array]",qu="[object Uint8Array]",Gu="[object Uint8ClampedArray]",Zu="[object Uint16Array]",Qu="[object Uint32Array]",o3=/\b__p \+= '';/g,r3=/\b(__p \+=) '' \+/g,i3=/(__e\(.*?\)|\b__t\)) \+\n'';/g,d1=/&(?:amp|lt|gt|quot|#39);/g,h1=/[&<>"']/g,s3=RegExp(d1.source),l3=RegExp(h1.source),c3=/<%-([\s\S]+?)%>/g,a3=/<%([\s\S]+?)%>/g,f1=/<%=([\s\S]+?)%>/g,u3=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,d3=/^\w*$/,h3=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Yu=/[\\^$.*+?()[\]{}|]/g,f3=RegExp(Yu.source),Ju=/^\s+/,m3=/\s/,g3=/\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,se=/\{\n\/\* \[wrapped with (.+)\] \*/,p3=/,? & /,C3=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g,m1=/[()=,{}\[\]\/\s]/,ul=/\\(\\)?/g,A3=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,Pc=/\w*$/,g1=/^[-+]0x[0-9a-f]+$/i,p1=/^0b[01]+$/i,b3=/^\[object .+?Constructor\]$/,v3=/^0o[0-7]+$/i,y3=/^(?:0|[1-9]\d*)$/,k3=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,Nc=/($^)/,w3=/['\n\r\u2028\u2029\\]/g,$c="\\ud800-\\udfff",B3="\\u0300-\\u036f",E3="\\ufe20-\\ufe2f",x3="\\u20d0-\\u20ff",C1=B3+E3+x3,Hc="\\u2700-\\u27bf",A1="a-z\\xdf-\\xf6\\xf8-\\xff",I3="\\xac\\xb1\\xd7\\xf7",T3="\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf",D3="\\u2000-\\u206f",Ao=" \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000",dl="A-Z\\xc0-\\xd6\\xd8-\\xde",xr="\\ufe0e\\ufe0f",He=I3+T3+D3+Ao,Ku="['\u2019]",S3="["+$c+"]",Go="["+He+"]",Zo="["+C1+"]",Xu="\\d+",jc="["+Hc+"]",td="["+A1+"]",ii="[^"+$c+He+Xu+Hc+A1+dl+"]",Ir="\\ud83c[\\udffb-\\udfff]",ed="(?:"+Zo+"|"+Ir+")",nd="[^"+$c+"]",is="(?:\\ud83c[\\udde6-\\uddff]){2}",od="[\\ud800-\\udbff][\\udc00-\\udfff]",ss="["+dl+"]",ls="\\u200d",b1="(?:"+td+"|"+ii+")",L3="(?:"+ss+"|"+ii+")",v1="(?:"+Ku+"(?:d|ll|m|re|s|t|ve))?",hl="(?:"+Ku+"(?:D|LL|M|RE|S|T|VE))?",Uc=ed+"?",si="["+xr+"]?",M3="(?:"+ls+"(?:"+[nd,is,od].join("|")+")"+si+Uc+")*",R3="\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",O3="\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])",rd=si+Uc+M3,y1="(?:"+[jc,is,od].join("|")+")"+rd,id="(?:"+[nd+Zo+"?",Zo,is,od,S3].join("|")+")",_3=RegExp(Ku,"g"),F3=RegExp(Zo,"g"),sd=RegExp(Ir+"(?="+Ir+")|"+id+rd,"g"),P3=RegExp([ss+"?"+td+"+"+v1+"(?="+[Go,ss,"$"].join("|")+")",L3+"+"+hl+"(?="+[Go,ss+b1,"$"].join("|")+")",ss+"?"+b1+"+"+v1,ss+"+"+hl,O3,R3,Xu,y1].join("|"),"g"),N3=RegExp("["+ls+$c+C1+xr+"]"),$3=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/,H3=["Array","Buffer","DataView","Date","Error","Float32Array","Float64Array","Function","Int8Array","Int16Array","Int32Array","Map","Math","Object","Promise","RegExp","Set","String","Symbol","TypeError","Uint8Array","Uint8ClampedArray","Uint16Array","Uint32Array","WeakMap","_","clearTimeout","isFinite","parseInt","setTimeout"],j3=-1,le={};le[ju]=le[Uu]=le[zu]=le[Vu]=le[Wu]=le[qu]=le[Gu]=le[Zu]=le[Qu]=!0,le[ns]=le[nl]=le[al]=le[ri]=le[rs]=le[Nt]=le[os]=le[Fc]=le[un]=le[rl]=le[Co]=le[il]=le[be]=le[sl]=le[cl]=!1;var oe={};oe[ns]=oe[nl]=oe[al]=oe[rs]=oe[ri]=oe[Nt]=oe[ju]=oe[Uu]=oe[zu]=oe[Vu]=oe[Wu]=oe[un]=oe[rl]=oe[Co]=oe[il]=oe[be]=oe[sl]=oe[ll]=oe[qu]=oe[Gu]=oe[Zu]=oe[Qu]=!0,oe[os]=oe[Fc]=oe[cl]=!1;var U3={\u00C0:"A",\u00C1:"A",\u00C2:"A",\u00C3:"A",\u00C4:"A",\u00C5:"A",\u00E0:"a",\u00E1:"a",\u00E2:"a",\u00E3:"a",\u00E4:"a",\u00E5:"a",\u00C7:"C",\u00E7:"c",\u00D0:"D",\u00F0:"d",\u00C8:"E",\u00C9:"E",\u00CA:"E",\u00CB:"E",\u00E8:"e",\u00E9:"e",\u00EA:"e",\u00EB:"e",\u00CC:"I",\u00CD:"I",\u00CE:"I",\u00CF:"I",\u00EC:"i",\u00ED:"i",\u00EE:"i",\u00EF:"i",\u00D1:"N",\u00F1:"n",\u00D2:"O",\u00D3:"O",\u00D4:"O",\u00D5:"O",\u00D6:"O",\u00D8:"O",\u00F2:"o",\u00F3:"o",\u00F4:"o",\u00F5:"o",\u00F6:"o",\u00F8:"o",\u00D9:"U",\u00DA:"U",\u00DB:"U",\u00DC:"U",\u00F9:"u",\u00FA:"u",\u00FB:"u",\u00FC:"u",\u00DD:"Y",\u00FD:"y",\u00FF:"y",\u00C6:"Ae",\u00E6:"ae",\u00DE:"Th",\u00FE:"th",\u00DF:"ss",\u0100:"A",\u0102:"A",\u0104:"A",\u0101:"a",\u0103:"a",\u0105:"a",\u0106:"C",\u0108:"C",\u010A:"C",\u010C:"C",\u0107:"c",\u0109:"c",\u010B:"c",\u010D:"c",\u010E:"D",\u0110:"D",\u010F:"d",\u0111:"d",\u0112:"E",\u0114:"E",\u0116:"E",\u0118:"E",\u011A:"E",\u0113:"e",\u0115:"e",\u0117:"e",\u0119:"e",\u011B:"e",\u011C:"G",\u011E:"G",\u0120:"G",\u0122:"G",\u011D:"g",\u011F:"g",\u0121:"g",\u0123:"g",\u0124:"H",\u0126:"H",\u0125:"h",\u0127:"h",\u0128:"I",\u012A:"I",\u012C:"I",\u012E:"I",\u0130:"I",\u0129:"i",\u012B:"i",\u012D:"i",\u012F:"i",\u0131:"i",\u0134:"J",\u0135:"j",\u0136:"K",\u0137:"k",\u0138:"k",\u0139:"L",\u013B:"L",\u013D:"L",\u013F:"L",\u0141:"L",\u013A:"l",\u013C:"l",\u013E:"l",\u0140:"l",\u0142:"l",\u0143:"N",\u0145:"N",\u0147:"N",\u014A:"N",\u0144:"n",\u0146:"n",\u0148:"n",\u014B:"n",\u014C:"O",\u014E:"O",\u0150:"O",\u014D:"o",\u014F:"o",\u0151:"o",\u0154:"R",\u0156:"R",\u0158:"R",\u0155:"r",\u0157:"r",\u0159:"r",\u015A:"S",\u015C:"S",\u015E:"S",\u0160:"S",\u015B:"s",\u015D:"s",\u015F:"s",\u0161:"s",\u0162:"T",\u0164:"T",\u0166:"T",\u0163:"t",\u0165:"t",\u0167:"t",\u0168:"U",\u016A:"U",\u016C:"U",\u016E:"U",\u0170:"U",\u0172:"U",\u0169:"u",\u016B:"u",\u016D:"u",\u016F:"u",\u0171:"u",\u0173:"u",\u0174:"W",\u0175:"w",\u0176:"Y",\u0177:"y",\u0178:"Y",\u0179:"Z",\u017B:"Z",\u017D:"Z",\u017A:"z",\u017C:"z",\u017E:"z",\u0132:"IJ",\u0133:"ij",\u0152:"Oe",\u0153:"oe",\u0149:"'n",\u017F:"s"},z3={"&":"&","<":"<",">":">",'"':""","'":"'"},V3={"&":"&","<":"<",">":">",""":'"',"'":"'"},W3={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"},k1=parseFloat,q3=parseInt,w1=typeof ur=="object"&&ur&&ur.Object===Object&&ur,G3=typeof self=="object"&&self&&self.Object===Object&&self,Ge=w1||G3||Function("return this")(),ld=t&&!t.nodeType&&t,li=ld&&!0&&n&&!n.nodeType&&n,zc=li&&li.exports===ld,fl=zc&&w1.process,On=function(){try{var N=li&&li.require&&li.require("util").types;return N||fl&&fl.binding&&fl.binding("util")}catch{}}(),cd=On&&On.isArrayBuffer,ad=On&&On.isDate,ud=On&&On.isMap,B1=On&&On.isRegExp,dd=On&&On.isSet,hd=On&&On.isTypedArray;function yn(N,G,V){switch(V.length){case 0:return N.call(G);case 1:return N.call(G,V[0]);case 2:return N.call(G,V[0],V[1]);case 3:return N.call(G,V[0],V[1],V[2])}return N.apply(G,V)}function Z3(N,G,V,ht){for(var Et=-1,Vt=N==null?0:N.length;++Et<Vt;){var we=N[Et];G(ht,we,V(we),N)}return ht}function _n(N,G){for(var V=-1,ht=N==null?0:N.length;++V<ht&&G(N[V],V,N)!==!1;);return N}function Q3(N,G){for(var V=N==null?0:N.length;V--&&G(N[V],V,N)!==!1;);return N}function E1(N,G){for(var V=-1,ht=N==null?0:N.length;++V<ht;)if(!G(N[V],V,N))return!1;return!0}function Qo(N,G){for(var V=-1,ht=N==null?0:N.length,Et=0,Vt=[];++V<ht;){var we=N[V];G(we,V,N)&&(Vt[Et++]=we)}return Vt}function Vc(N,G){var V=N==null?0:N.length;return!!V&&ci(N,G,0)>-1}function fd(N,G,V){for(var ht=-1,Et=N==null?0:N.length;++ht<Et;)if(V(G,N[ht]))return!0;return!1}function ue(N,G){for(var V=-1,ht=N==null?0:N.length,Et=Array(ht);++V<ht;)Et[V]=G(N[V],V,N);return Et}function Tr(N,G){for(var V=-1,ht=G.length,Et=N.length;++V<ht;)N[Et+V]=G[V];return N}function md(N,G,V,ht){var Et=-1,Vt=N==null?0:N.length;for(ht&&Vt&&(V=N[++Et]);++Et<Vt;)V=G(V,N[Et],Et,N);return V}function Y3(N,G,V,ht){var Et=N==null?0:N.length;for(ht&&Et&&(V=N[--Et]);Et--;)V=G(V,N[Et],Et,N);return V}function gd(N,G){for(var V=-1,ht=N==null?0:N.length;++V<ht;)if(G(N[V],V,N))return!0;return!1}var J3=qc("length");function x1(N){return N.split("")}function Jn(N){return N.match(C3)||[]}function pd(N,G,V){var ht;return V(N,function(Et,Vt,we){if(G(Et,Vt,we))return ht=Vt,!1}),ht}function ml(N,G,V,ht){for(var Et=N.length,Vt=V+(ht?1:-1);ht?Vt--:++Vt<Et;)if(G(N[Vt],Vt,N))return Vt;return-1}function ci(N,G,V){return G===G?Jc(N,G,V):ml(N,Yo,V)}function cs(N,G,V,ht){for(var Et=V-1,Vt=N.length;++Et<Vt;)if(ht(N[Et],G))return Et;return-1}function Yo(N){return N!==N}function Wc(N,G){var V=N==null?0:N.length;return V?Gc(N,G)/V:oi}function qc(N){return function(G){return G==null?e:G[N]}}function Cd(N){return function(G){return N==null?e:N[G]}}function gl(N,G,V,ht,Et){return Et(N,function(Vt,we,qt){V=ht?(ht=!1,Vt):G(V,Vt,we,qt)}),V}function I1(N,G){var V=N.length;for(N.sort(G);V--;)N[V]=N[V].value;return N}function Gc(N,G){for(var V,ht=-1,Et=N.length;++ht<Et;){var Vt=G(N[ht]);Vt!==e&&(V=V===e?Vt:V+Vt)}return V}function Zc(N,G){for(var V=-1,ht=Array(N);++V<N;)ht[V]=G(V);return ht}function pl(N,G){return ue(G,function(V){return[V,N[V]]})}function ai(N){return N&&N.slice(0,Kc(N)+1).replace(Ju,"")}function dn(N){return function(G){return N(G)}}function as(N,G){return ue(G,function(V){return N[V]})}function Jo(N,G){return N.has(G)}function Cl(N,G){for(var V=-1,ht=N.length;++V<ht&&ci(G,N[V],0)>-1;);return V}function Ad(N,G){for(var V=N.length;V--&&ci(G,N[V],0)>-1;);return V}function T1(N,G){for(var V=N.length,ht=0;V--;)N[V]===G&&++ht;return ht}var D1=Cd(U3),bd=Cd(z3);function S1(N){return"\\"+W3[N]}function L1(N,G){return N==null?e:N[G]}function ui(N){return N3.test(N)}function Qc(N){return $3.test(N)}function Al(N){for(var G,V=[];!(G=N.next()).done;)V.push(G.value);return V}function di(N){var G=-1,V=Array(N.size);return N.forEach(function(ht,Et){V[++G]=[Et,ht]}),V}function Yc(N,G){return function(V){return N(G(V))}}function Kn(N,G){for(var V=-1,ht=N.length,Et=0,Vt=[];++V<ht;){var we=N[V];(we===G||we===h)&&(N[V]=h,Vt[Et++]=V)}return Vt}function hi(N){var G=-1,V=Array(N.size);return N.forEach(function(ht){V[++G]=ht}),V}function bl(N){var G=-1,V=Array(N.size);return N.forEach(function(ht){V[++G]=[ht,ht]}),V}function Jc(N,G,V){for(var ht=V-1,Et=N.length;++ht<Et;)if(N[ht]===G)return ht;return-1}function M1(N,G,V){for(var ht=V+1;ht--;)if(N[ht]===G)return ht;return ht}function us(N){return ui(N)?vl(N):J3(N)}function Xn(N){return ui(N)?ta(N):x1(N)}function Kc(N){for(var G=N.length;G--&&m3.test(N.charAt(G)););return G}var Xc=Cd(V3);function vl(N){for(var G=sd.lastIndex=0;sd.test(N);)++G;return G}function ta(N){return N.match(sd)||[]}function R1(N){return N.match(P3)||[]}var ea=function N(G){G=G==null?Ge:fi.defaults(Ge.Object(),G,fi.pick(Ge,H3));var V=G.Array,ht=G.Date,Et=G.Error,Vt=G.Function,we=G.Math,qt=G.Object,na=G.RegExp,vd=G.String,kn=G.TypeError,yl=V.prototype,yd=Vt.prototype,mi=qt.prototype,kl=G["__core-js_shared__"],gi=yd.toString,Wt=mi.hasOwnProperty,O1=0,kd=function(){var c=/[^.]+$/.exec(kl&&kl.keys&&kl.keys.IE_PROTO||"");return c?"Symbol(src)_1."+c:""}(),wl=mi.toString,wd=gi.call(qt),_1=Ge._,F1=na("^"+gi.call(Wt).replace(Yu,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),pi=zc?G.Buffer:e,Ko=G.Symbol,Bl=G.Uint8Array,El=pi?pi.allocUnsafe:e,Dr=Yc(qt.getPrototypeOf,qt),xl=qt.create,Bd=mi.propertyIsEnumerable,Il=yl.splice,P1=Ko?Ko.isConcatSpreadable:e,Tl=Ko?Ko.iterator:e,Ci=Ko?Ko.toStringTag:e,Ai=function(){try{var c=Fl(qt,"defineProperty");return c({},"",{}),c}catch{}}(),N1=G.clearTimeout!==Ge.clearTimeout&&G.clearTimeout,$1=ht&&ht.now!==Ge.Date.now&&ht.now,H1=G.setTimeout!==Ge.setTimeout&&G.setTimeout,Dl=we.ceil,Sl=we.floor,Ll=qt.getOwnPropertySymbols,j1=pi?pi.isBuffer:e,Ed=G.isFinite,K3=yl.join,k=Yc(qt.keys,qt),T=we.max,L=we.min,F=ht.now,U=G.parseInt,j=we.random,Z=yl.reverse,J=Fl(G,"DataView"),lt=Fl(G,"Map"),pt=Fl(G,"Promise"),ct=Fl(G,"Set"),At=Fl(G,"WeakMap"),Gt=Fl(qt,"create"),Te=At&&new At,en={},Fn=Pl(J),bo=Pl(lt),X3=Pl(pt),t5=Pl(ct),de=Pl(At),re=Ko?Ko.prototype:e,ge=re?re.valueOf:e,vo=re?re.toString:e;function E(c){if(Be(c)&&!St(c)&&!(c instanceof Pt)){if(c instanceof Pn)return c;if(Wt.call(c,"__wrapped__"))return Fw(c)}return new Pn(c)}var Sr=function(){function c(){}return function(u){if(!ve(u))return{};if(xl)return xl(u);c.prototype=u;var f=new c;return c.prototype=e,f}}();function ds(){}function Pn(c,u){this.__wrapped__=c,this.__actions__=[],this.__chain__=!!u,this.__index__=0,this.__values__=e}E.templateSettings={escape:c3,evaluate:a3,interpolate:f1,variable:"",imports:{_:E}},E.prototype=ds.prototype,E.prototype.constructor=E,Pn.prototype=Sr(ds.prototype),Pn.prototype.constructor=Pn;function Pt(c){this.__wrapped__=c,this.__actions__=[],this.__dir__=1,this.__filtered__=!1,this.__iteratees__=[],this.__takeCount__=po,this.__views__=[]}function rQ(){var c=new Pt(this.__wrapped__);return c.__actions__=Nn(this.__actions__),c.__dir__=this.__dir__,c.__filtered__=this.__filtered__,c.__iteratees__=Nn(this.__iteratees__),c.__takeCount__=this.__takeCount__,c.__views__=Nn(this.__views__),c}function iQ(){if(this.__filtered__){var c=new Pt(this);c.__dir__=-1,c.__filtered__=!0}else c=this.clone(),c.__dir__*=-1;return c}function sQ(){var c=this.__wrapped__.value(),u=this.__dir__,f=St(c),C=u<0,y=f?c.length:0,I=AY(0,y,this.__views__),O=I.start,P=I.end,$=P-O,Q=C?P:O-1,Y=this.__iteratees__,X=Y.length,dt=0,Ct=L($,this.__takeCount__);if(!f||!C&&y==$&&Ct==$)return iw(c,this.__actions__);var yt=[];t:for(;$--&&dt<Ct;){Q+=u;for(var Ot=-1,kt=c[Q];++Ot<X;){var $t=Y[Ot],zt=$t.iteratee,no=$t.type,En=zt(kt);if(no==Rn)kt=En;else if(!En){if(no==$e)continue t;break t}}yt[dt++]=kt}return yt}Pt.prototype=Sr(ds.prototype),Pt.prototype.constructor=Pt;function Ml(c){var u=-1,f=c==null?0:c.length;for(this.clear();++u<f;){var C=c[u];this.set(C[0],C[1])}}function lQ(){this.__data__=Gt?Gt(null):{},this.size=0}function cQ(c){var u=this.has(c)&&delete this.__data__[c];return this.size-=u?1:0,u}function aQ(c){var u=this.__data__;if(Gt){var f=u[c];return f===a?e:f}return Wt.call(u,c)?u[c]:e}function uQ(c){var u=this.__data__;return Gt?u[c]!==e:Wt.call(u,c)}function dQ(c,u){var f=this.__data__;return this.size+=this.has(c)?0:1,f[c]=Gt&&u===e?a:u,this}Ml.prototype.clear=lQ,Ml.prototype.delete=cQ,Ml.prototype.get=aQ,Ml.prototype.has=uQ,Ml.prototype.set=dQ;function bi(c){var u=-1,f=c==null?0:c.length;for(this.clear();++u<f;){var C=c[u];this.set(C[0],C[1])}}function hQ(){this.__data__=[],this.size=0}function fQ(c){var u=this.__data__,f=U1(u,c);if(f<0)return!1;var C=u.length-1;return f==C?u.pop():Il.call(u,f,1),--this.size,!0}function mQ(c){var u=this.__data__,f=U1(u,c);return f<0?e:u[f][1]}function gQ(c){return U1(this.__data__,c)>-1}function pQ(c,u){var f=this.__data__,C=U1(f,c);return C<0?(++this.size,f.push([c,u])):f[C][1]=u,this}bi.prototype.clear=hQ,bi.prototype.delete=fQ,bi.prototype.get=mQ,bi.prototype.has=gQ,bi.prototype.set=pQ;function vi(c){var u=-1,f=c==null?0:c.length;for(this.clear();++u<f;){var C=c[u];this.set(C[0],C[1])}}function CQ(){this.size=0,this.__data__={hash:new Ml,map:new(lt||bi),string:new Ml}}function AQ(c){var u=tm(this,c).delete(c);return this.size-=u?1:0,u}function bQ(c){return tm(this,c).get(c)}function vQ(c){return tm(this,c).has(c)}function yQ(c,u){var f=tm(this,c),C=f.size;return f.set(c,u),this.size+=f.size==C?0:1,this}vi.prototype.clear=CQ,vi.prototype.delete=AQ,vi.prototype.get=bQ,vi.prototype.has=vQ,vi.prototype.set=yQ;function Rl(c){var u=-1,f=c==null?0:c.length;for(this.__data__=new vi;++u<f;)this.add(c[u])}function kQ(c){return this.__data__.set(c,a),this}function wQ(c){return this.__data__.has(c)}Rl.prototype.add=Rl.prototype.push=kQ,Rl.prototype.has=wQ;function Xo(c){var u=this.__data__=new bi(c);this.size=u.size}function BQ(){this.__data__=new bi,this.size=0}function EQ(c){var u=this.__data__,f=u.delete(c);return this.size=u.size,f}function xQ(c){return this.__data__.get(c)}function IQ(c){return this.__data__.has(c)}function TQ(c,u){var f=this.__data__;if(f instanceof bi){var C=f.__data__;if(!lt||C.length<r-1)return C.push([c,u]),this.size=++f.size,this;f=this.__data__=new vi(C)}return f.set(c,u),this.size=f.size,this}Xo.prototype.clear=BQ,Xo.prototype.delete=EQ,Xo.prototype.get=xQ,Xo.prototype.has=IQ,Xo.prototype.set=TQ;function Fk(c,u){var f=St(c),C=!f&&Nl(c),y=!f&&!C&&ps(c),I=!f&&!C&&!y&&sa(c),O=f||C||y||I,P=O?Zc(c.length,vd):[],$=P.length;for(var Q in c)(u||Wt.call(c,Q))&&!(O&&(Q=="length"||y&&(Q=="offset"||Q=="parent")||I&&(Q=="buffer"||Q=="byteLength"||Q=="byteOffset")||Bi(Q,$)))&&P.push(Q);return P}function Pk(c){var u=c.length;return u?c[d5(0,u-1)]:e}function DQ(c,u){return em(Nn(c),Ol(u,0,c.length))}function SQ(c){return em(Nn(c))}function e5(c,u,f){(f!==e&&!tr(c[u],f)||f===e&&!(u in c))&&yi(c,u,f)}function xd(c,u,f){var C=c[u];(!(Wt.call(c,u)&&tr(C,f))||f===e&&!(u in c))&&yi(c,u,f)}function U1(c,u){for(var f=c.length;f--;)if(tr(c[f][0],u))return f;return-1}function LQ(c,u,f,C){return hs(c,function(y,I,O){u(C,y,f(y),O)}),C}function Nk(c,u){return c&&Mr(u,Ke(u),c)}function MQ(c,u){return c&&Mr(u,Hn(u),c)}function yi(c,u,f){u=="__proto__"&&Ai?Ai(c,u,{configurable:!0,enumerable:!0,value:f,writable:!0}):c[u]=f}function n5(c,u){for(var f=-1,C=u.length,y=V(C),I=c==null;++f<C;)y[f]=I?e:F5(c,u[f]);return y}function Ol(c,u,f){return c===c&&(f!==e&&(c=c<=f?c:f),u!==e&&(c=c>=u?c:u)),c}function yo(c,u,f,C,y,I){var O,P=u&p,$=u&A,Q=u&v;if(f&&(O=y?f(c,C,y,I):f(c)),O!==e)return O;if(!ve(c))return c;var Y=St(c);if(Y){if(O=vY(c),!P)return Nn(c,O)}else{var X=hn(c),dt=X==Fc||X==s1;if(ps(c))return cw(c,P);if(X==Co||X==ns||dt&&!y){if(O=$||dt?{}:Iw(c),!P)return $?aY(c,MQ(O,c)):cY(c,Nk(O,c))}else{if(!oe[X])return y?c:{};O=yY(c,X,P)}}I||(I=new Xo);var Ct=I.get(c);if(Ct)return Ct;I.set(c,O),nB(c)?c.forEach(function(kt){O.add(yo(kt,u,f,kt,c,I))}):tB(c)&&c.forEach(function(kt,$t){O.set($t,yo(kt,u,f,$t,c,I))});var yt=Q?$?k5:y5:$?Hn:Ke,Ot=Y?e:yt(c);return _n(Ot||c,function(kt,$t){Ot&&($t=kt,kt=c[$t]),xd(O,$t,yo(kt,u,f,$t,c,I))}),O}function RQ(c){var u=Ke(c);return function(f){return $k(f,c,u)}}function $k(c,u,f){var C=f.length;if(c==null)return!C;for(c=qt(c);C--;){var y=f[C],I=u[y],O=c[y];if(O===e&&!(y in c)||!I(O))return!1}return!0}function Hk(c,u,f){if(typeof c!="function")throw new kn(s);return Rd(function(){c.apply(e,f)},u)}function Id(c,u,f,C){var y=-1,I=Vc,O=!0,P=c.length,$=[],Q=u.length;if(!P)return $;f&&(u=ue(u,dn(f))),C?(I=fd,O=!1):u.length>=r&&(I=Jo,O=!1,u=new Rl(u));t:for(;++y<P;){var Y=c[y],X=f==null?Y:f(Y);if(Y=C||Y!==0?Y:0,O&&X===X){for(var dt=Q;dt--;)if(u[dt]===X)continue t;$.push(Y)}else I(u,X,C)||$.push(Y)}return $}var hs=fw(Lr),jk=fw(r5,!0);function OQ(c,u){var f=!0;return hs(c,function(C,y,I){return f=!!u(C,y,I),f}),f}function z1(c,u,f){for(var C=-1,y=c.length;++C<y;){var I=c[C],O=u(I);if(O!=null&&(P===e?O===O&&!eo(O):f(O,P)))var P=O,$=I}return $}function _Q(c,u,f,C){var y=c.length;for(f=Rt(f),f<0&&(f=-f>y?0:y+f),C=C===e||C>y?y:Rt(C),C<0&&(C+=y),C=f>C?0:rB(C);f<C;)c[f++]=u;return c}function Uk(c,u){var f=[];return hs(c,function(C,y,I){u(C,y,I)&&f.push(C)}),f}function nn(c,u,f,C,y){var I=-1,O=c.length;for(f||(f=wY),y||(y=[]);++I<O;){var P=c[I];u>0&&f(P)?u>1?nn(P,u-1,f,C,y):Tr(y,P):C||(y[y.length]=P)}return y}var o5=mw(),zk=mw(!0);function Lr(c,u){return c&&o5(c,u,Ke)}function r5(c,u){return c&&zk(c,u,Ke)}function V1(c,u){return Qo(u,function(f){return Ei(c[f])})}function _l(c,u){u=ms(u,c);for(var f=0,C=u.length;c!=null&&f<C;)c=c[Rr(u[f++])];return f&&f==C?c:e}function Vk(c,u,f){var C=u(c);return St(c)?C:Tr(C,f(c))}function wn(c){return c==null?c===e?a1:l1:Ci&&Ci in qt(c)?CY(c):SY(c)}function i5(c,u){return c>u}function FQ(c,u){return c!=null&&Wt.call(c,u)}function PQ(c,u){return c!=null&&u in qt(c)}function NQ(c,u,f){return c>=L(u,f)&&c<T(u,f)}function s5(c,u,f){for(var C=f?fd:Vc,y=c[0].length,I=c.length,O=I,P=V(I),$=1/0,Q=[];O--;){var Y=c[O];O&&u&&(Y=ue(Y,dn(u))),$=L(Y.length,$),P[O]=!f&&(u||y>=120&&Y.length>=120)?new Rl(O&&Y):e}Y=c[0];var X=-1,dt=P[0];t:for(;++X<y&&Q.length<$;){var Ct=Y[X],yt=u?u(Ct):Ct;if(Ct=f||Ct!==0?Ct:0,!(dt?Jo(dt,yt):C(Q,yt,f))){for(O=I;--O;){var Ot=P[O];if(!(Ot?Jo(Ot,yt):C(c[O],yt,f)))continue t}dt&&dt.push(yt),Q.push(Ct)}}return Q}function $Q(c,u,f,C){return Lr(c,function(y,I,O){u(C,f(y),I,O)}),C}function Td(c,u,f){u=ms(u,c),c=Lw(c,u);var C=c==null?c:c[Rr(wo(u))];return C==null?e:yn(C,c,f)}function Wk(c){return Be(c)&&wn(c)==ns}function HQ(c){return Be(c)&&wn(c)==al}function jQ(c){return Be(c)&&wn(c)==Nt}function Dd(c,u,f,C,y){return c===u?!0:c==null||u==null||!Be(c)&&!Be(u)?c!==c&&u!==u:UQ(c,u,f,C,Dd,y)}function UQ(c,u,f,C,y,I){var O=St(c),P=St(u),$=O?nl:hn(c),Q=P?nl:hn(u);$=$==ns?Co:$,Q=Q==ns?Co:Q;var Y=$==Co,X=Q==Co,dt=$==Q;if(dt&&ps(c)){if(!ps(u))return!1;O=!0,Y=!1}if(dt&&!Y)return I||(I=new Xo),O||sa(c)?Bw(c,u,f,C,y,I):gY(c,u,$,f,C,y,I);if(!(f&B)){var Ct=Y&&Wt.call(c,"__wrapped__"),yt=X&&Wt.call(u,"__wrapped__");if(Ct||yt){var Ot=Ct?c.value():c,kt=yt?u.value():u;return I||(I=new Xo),y(Ot,kt,f,C,I)}}return dt?(I||(I=new Xo),pY(c,u,f,C,y,I)):!1}function zQ(c){return Be(c)&&hn(c)==un}function l5(c,u,f,C){var y=f.length,I=y,O=!C;if(c==null)return!I;for(c=qt(c);y--;){var P=f[y];if(O&&P[2]?P[1]!==c[P[0]]:!(P[0]in c))return!1}for(;++y<I;){P=f[y];var $=P[0],Q=c[$],Y=P[1];if(O&&P[2]){if(Q===e&&!($ in c))return!1}else{var X=new Xo;if(C)var dt=C(Q,Y,$,c,u,X);if(!(dt===e?Dd(Y,Q,B|D,C,X):dt))return!1}}return!0}function qk(c){if(!ve(c)||EY(c))return!1;var u=Ei(c)?F1:b3;return u.test(Pl(c))}function VQ(c){return Be(c)&&wn(c)==il}function WQ(c){return Be(c)&&hn(c)==be}function qQ(c){return Be(c)&&lm(c.length)&&!!le[wn(c)]}function Gk(c){return typeof c=="function"?c:c==null?jn:typeof c=="object"?St(c)?Yk(c[0],c[1]):Qk(c):gB(c)}function c5(c){if(!Md(c))return k(c);var u=[];for(var f in qt(c))Wt.call(c,f)&&f!="constructor"&&u.push(f);return u}function GQ(c){if(!ve(c))return DY(c);var u=Md(c),f=[];for(var C in c)C=="constructor"&&(u||!Wt.call(c,C))||f.push(C);return f}function a5(c,u){return c<u}function Zk(c,u){var f=-1,C=$n(c)?V(c.length):[];return hs(c,function(y,I,O){C[++f]=u(y,I,O)}),C}function Qk(c){var u=B5(c);return u.length==1&&u[0][2]?Dw(u[0][0],u[0][1]):function(f){return f===c||l5(f,c,u)}}function Yk(c,u){return x5(c)&&Tw(u)?Dw(Rr(c),u):function(f){var C=F5(f,c);return C===e&&C===u?P5(f,c):Dd(u,C,B|D)}}function W1(c,u,f,C,y){c!==u&&o5(u,function(I,O){if(y||(y=new Xo),ve(I))ZQ(c,u,O,f,W1,C,y);else{var P=C?C(T5(c,O),I,O+"",c,u,y):e;P===e&&(P=I),e5(c,O,P)}},Hn)}function ZQ(c,u,f,C,y,I,O){var P=T5(c,f),$=T5(u,f),Q=O.get($);if(Q){e5(c,f,Q);return}var Y=I?I(P,$,f+"",c,u,O):e,X=Y===e;if(X){var dt=St($),Ct=!dt&&ps($),yt=!dt&&!Ct&&sa($);Y=$,dt||Ct||yt?St(P)?Y=P:De(P)?Y=Nn(P):Ct?(X=!1,Y=cw($,!0)):yt?(X=!1,Y=aw($,!0)):Y=[]:Od($)||Nl($)?(Y=P,Nl(P)?Y=iB(P):(!ve(P)||Ei(P))&&(Y=Iw($))):X=!1}X&&(O.set($,Y),y(Y,$,C,I,O),O.delete($)),e5(c,f,Y)}function Jk(c,u){var f=c.length;if(!!f)return u+=u<0?f:0,Bi(u,f)?c[u]:e}function Kk(c,u,f){u.length?u=ue(u,function(I){return St(I)?function(O){return _l(O,I.length===1?I[0]:I)}:I}):u=[jn];var C=-1;u=ue(u,dn(vt()));var y=Zk(c,function(I,O,P){var $=ue(u,function(Q){return Q(I)});return{criteria:$,index:++C,value:I}});return I1(y,function(I,O){return lY(I,O,f)})}function QQ(c,u){return Xk(c,u,function(f,C){return P5(c,C)})}function Xk(c,u,f){for(var C=-1,y=u.length,I={};++C<y;){var O=u[C],P=_l(c,O);f(P,O)&&Sd(I,ms(O,c),P)}return I}function YQ(c){return function(u){return _l(u,c)}}function u5(c,u,f,C){var y=C?cs:ci,I=-1,O=u.length,P=c;for(c===u&&(u=Nn(u)),f&&(P=ue(c,dn(f)));++I<O;)for(var $=0,Q=u[I],Y=f?f(Q):Q;($=y(P,Y,$,C))>-1;)P!==c&&Il.call(P,$,1),Il.call(c,$,1);return c}function tw(c,u){for(var f=c?u.length:0,C=f-1;f--;){var y=u[f];if(f==C||y!==I){var I=y;Bi(y)?Il.call(c,y,1):m5(c,y)}}return c}function d5(c,u){return c+Sl(j()*(u-c+1))}function JQ(c,u,f,C){for(var y=-1,I=T(Dl((u-c)/(f||1)),0),O=V(I);I--;)O[C?I:++y]=c,c+=f;return O}function h5(c,u){var f="";if(!c||u<1||u>an)return f;do u%2&&(f+=c),u=Sl(u/2),u&&(c+=c);while(u);return f}function _t(c,u){return D5(Sw(c,u,jn),c+"")}function KQ(c){return Pk(la(c))}function XQ(c,u){var f=la(c);return em(f,Ol(u,0,f.length))}function Sd(c,u,f,C){if(!ve(c))return c;u=ms(u,c);for(var y=-1,I=u.length,O=I-1,P=c;P!=null&&++y<I;){var $=Rr(u[y]),Q=f;if($==="__proto__"||$==="constructor"||$==="prototype")return c;if(y!=O){var Y=P[$];Q=C?C(Y,$,P):e,Q===e&&(Q=ve(Y)?Y:Bi(u[y+1])?[]:{})}xd(P,$,Q),P=P[$]}return c}var ew=Te?function(c,u){return Te.set(c,u),c}:jn,tY=Ai?function(c,u){return Ai(c,"toString",{configurable:!0,enumerable:!1,value:$5(u),writable:!0})}:jn;function eY(c){return em(la(c))}function ko(c,u,f){var C=-1,y=c.length;u<0&&(u=-u>y?0:y+u),f=f>y?y:f,f<0&&(f+=y),y=u>f?0:f-u>>>0,u>>>=0;for(var I=V(y);++C<y;)I[C]=c[C+u];return I}function nY(c,u){var f;return hs(c,function(C,y,I){return f=u(C,y,I),!f}),!!f}function q1(c,u,f){var C=0,y=c==null?C:c.length;if(typeof u=="number"&&u===u&&y<=t3){for(;C<y;){var I=C+y>>>1,O=c[I];O!==null&&!eo(O)&&(f?O<=u:O<u)?C=I+1:y=I}return y}return f5(c,u,jn,f)}function f5(c,u,f,C){var y=0,I=c==null?0:c.length;if(I===0)return 0;u=f(u);for(var O=u!==u,P=u===null,$=eo(u),Q=u===e;y<I;){var Y=Sl((y+I)/2),X=f(c[Y]),dt=X!==e,Ct=X===null,yt=X===X,Ot=eo(X);if(O)var kt=C||yt;else Q?kt=yt&&(C||dt):P?kt=yt&&dt&&(C||!Ct):$?kt=yt&&dt&&!Ct&&(C||!Ot):Ct||Ot?kt=!1:kt=C?X<=u:X<u;kt?y=Y+1:I=Y}return L(I,X2)}function nw(c,u){for(var f=-1,C=c.length,y=0,I=[];++f<C;){var O=c[f],P=u?u(O):O;if(!f||!tr(P,$)){var $=P;I[y++]=O===0?0:O}}return I}function ow(c){return typeof c=="number"?c:eo(c)?oi:+c}function to(c){if(typeof c=="string")return c;if(St(c))return ue(c,to)+"";if(eo(c))return vo?vo.call(c):"";var u=c+"";return u=="0"&&1/c==-vn?"-0":u}function fs(c,u,f){var C=-1,y=Vc,I=c.length,O=!0,P=[],$=P;if(f)O=!1,y=fd;else if(I>=r){var Q=u?null:fY(c);if(Q)return hi(Q);O=!1,y=Jo,$=new Rl}else $=u?[]:P;t:for(;++C<I;){var Y=c[C],X=u?u(Y):Y;if(Y=f||Y!==0?Y:0,O&&X===X){for(var dt=$.length;dt--;)if($[dt]===X)continue t;u&&$.push(X),P.push(Y)}else y($,X,f)||($!==P&&$.push(X),P.push(Y))}return P}function m5(c,u){return u=ms(u,c),c=Lw(c,u),c==null||delete c[Rr(wo(u))]}function rw(c,u,f,C){return Sd(c,u,f(_l(c,u)),C)}function G1(c,u,f,C){for(var y=c.length,I=C?y:-1;(C?I--:++I<y)&&u(c[I],I,c););return f?ko(c,C?0:I,C?I+1:y):ko(c,C?I+1:0,C?y:I)}function iw(c,u){var f=c;return f instanceof Pt&&(f=f.value()),md(u,function(C,y){return y.func.apply(y.thisArg,Tr([C],y.args))},f)}function g5(c,u,f){var C=c.length;if(C<2)return C?fs(c[0]):[];for(var y=-1,I=V(C);++y<C;)for(var O=c[y],P=-1;++P<C;)P!=y&&(I[y]=Id(I[y]||O,c[P],u,f));return fs(nn(I,1),u,f)}function sw(c,u,f){for(var C=-1,y=c.length,I=u.length,O={};++C<y;){var P=C<I?u[C]:e;f(O,c[C],P)}return O}function p5(c){return De(c)?c:[]}function C5(c){return typeof c=="function"?c:jn}function ms(c,u){return St(c)?c:x5(c,u)?[c]:_w(Kt(c))}var oY=_t;function gs(c,u,f){var C=c.length;return f=f===e?C:f,!u&&f>=C?c:ko(c,u,f)}var lw=N1||function(c){return Ge.clearTimeout(c)};function cw(c,u){if(u)return c.slice();var f=c.length,C=El?El(f):new c.constructor(f);return c.copy(C),C}function A5(c){var u=new c.constructor(c.byteLength);return new Bl(u).set(new Bl(c)),u}function rY(c,u){var f=u?A5(c.buffer):c.buffer;return new c.constructor(f,c.byteOffset,c.byteLength)}function iY(c){var u=new c.constructor(c.source,Pc.exec(c));return u.lastIndex=c.lastIndex,u}function sY(c){return ge?qt(ge.call(c)):{}}function aw(c,u){var f=u?A5(c.buffer):c.buffer;return new c.constructor(f,c.byteOffset,c.length)}function uw(c,u){if(c!==u){var f=c!==e,C=c===null,y=c===c,I=eo(c),O=u!==e,P=u===null,$=u===u,Q=eo(u);if(!P&&!Q&&!I&&c>u||I&&O&&$&&!P&&!Q||C&&O&&$||!f&&$||!y)return 1;if(!C&&!I&&!Q&&c<u||Q&&f&&y&&!C&&!I||P&&f&&y||!O&&y||!$)return-1}return 0}function lY(c,u,f){for(var C=-1,y=c.criteria,I=u.criteria,O=y.length,P=f.length;++C<O;){var $=uw(y[C],I[C]);if($){if(C>=P)return $;var Q=f[C];return $*(Q=="desc"?-1:1)}}return c.index-u.index}function dw(c,u,f,C){for(var y=-1,I=c.length,O=f.length,P=-1,$=u.length,Q=T(I-O,0),Y=V($+Q),X=!C;++P<$;)Y[P]=u[P];for(;++y<O;)(X||y<I)&&(Y[f[y]]=c[y]);for(;Q--;)Y[P++]=c[y++];return Y}function hw(c,u,f,C){for(var y=-1,I=c.length,O=-1,P=f.length,$=-1,Q=u.length,Y=T(I-P,0),X=V(Y+Q),dt=!C;++y<Y;)X[y]=c[y];for(var Ct=y;++$<Q;)X[Ct+$]=u[$];for(;++O<P;)(dt||y<I)&&(X[Ct+f[O]]=c[y++]);return X}function Nn(c,u){var f=-1,C=c.length;for(u||(u=V(C));++f<C;)u[f]=c[f];return u}function Mr(c,u,f,C){var y=!f;f||(f={});for(var I=-1,O=u.length;++I<O;){var P=u[I],$=C?C(f[P],c[P],P,f,c):e;$===e&&($=c[P]),y?yi(f,P,$):xd(f,P,$)}return f}function cY(c,u){return Mr(c,E5(c),u)}function aY(c,u){return Mr(c,Ew(c),u)}function Z1(c,u){return function(f,C){var y=St(f)?Z3:LQ,I=u?u():{};return y(f,c,vt(C,2),I)}}function oa(c){return _t(function(u,f){var C=-1,y=f.length,I=y>1?f[y-1]:e,O=y>2?f[2]:e;for(I=c.length>3&&typeof I=="function"?(y--,I):e,O&&Bn(f[0],f[1],O)&&(I=y<3?e:I,y=1),u=qt(u);++C<y;){var P=f[C];P&&c(u,P,C,I)}return u})}function fw(c,u){return function(f,C){if(f==null)return f;if(!$n(f))return c(f,C);for(var y=f.length,I=u?y:-1,O=qt(f);(u?I--:++I<y)&&C(O[I],I,O)!==!1;);return f}}function mw(c){return function(u,f,C){for(var y=-1,I=qt(u),O=C(u),P=O.length;P--;){var $=O[c?P:++y];if(f(I[$],$,I)===!1)break}return u}}function uY(c,u,f){var C=u&x,y=Ld(c);function I(){var O=this&&this!==Ge&&this instanceof I?y:c;return O.apply(C?f:this,arguments)}return I}function gw(c){return function(u){u=Kt(u);var f=ui(u)?Xn(u):e,C=f?f[0]:u.charAt(0),y=f?gs(f,1).join(""):u.slice(1);return C[c]()+y}}function ra(c){return function(u){return md(fB(hB(u).replace(_3,"")),c,"")}}function Ld(c){return function(){var u=arguments;switch(u.length){case 0:return new c;case 1:return new c(u[0]);case 2:return new c(u[0],u[1]);case 3:return new c(u[0],u[1],u[2]);case 4:return new c(u[0],u[1],u[2],u[3]);case 5:return new c(u[0],u[1],u[2],u[3],u[4]);case 6:return new c(u[0],u[1],u[2],u[3],u[4],u[5]);case 7:return new c(u[0],u[1],u[2],u[3],u[4],u[5],u[6])}var f=Sr(c.prototype),C=c.apply(f,u);return ve(C)?C:f}}function dY(c,u,f){var C=Ld(c);function y(){for(var I=arguments.length,O=V(I),P=I,$=ia(y);P--;)O[P]=arguments[P];var Q=I<3&&O[0]!==$&&O[I-1]!==$?[]:Kn(O,$);if(I-=Q.length,I<f)return vw(c,u,Q1,y.placeholder,e,O,Q,e,e,f-I);var Y=this&&this!==Ge&&this instanceof y?C:c;return yn(Y,this,O)}return y}function pw(c){return function(u,f,C){var y=qt(u);if(!$n(u)){var I=vt(f,3);u=Ke(u),f=function(P){return I(y[P],P,y)}}var O=c(u,f,C);return O>-1?y[I?u[O]:O]:e}}function Cw(c){return wi(function(u){var f=u.length,C=f,y=Pn.prototype.thru;for(c&&u.reverse();C--;){var I=u[C];if(typeof I!="function")throw new kn(s);if(y&&!O&&X1(I)=="wrapper")var O=new Pn([],!0)}for(C=O?C:f;++C<f;){I=u[C];var P=X1(I),$=P=="wrapper"?w5(I):e;$&&I5($[0])&&$[1]==(ft|H|q|Bt)&&!$[4].length&&$[9]==1?O=O[X1($[0])].apply(O,$[3]):O=I.length==1&&I5(I)?O[P]():O.thru(I)}return function(){var Q=arguments,Y=Q[0];if(O&&Q.length==1&&St(Y))return O.plant(Y).value();for(var X=0,dt=f?u[X].apply(this,Q):Y;++X<f;)dt=u[X].call(this,dt);return dt}})}function Q1(c,u,f,C,y,I,O,P,$,Q){var Y=u&ft,X=u&x,dt=u&_,Ct=u&(H|z),yt=u&jt,Ot=dt?e:Ld(c);function kt(){for(var $t=arguments.length,zt=V($t),no=$t;no--;)zt[no]=arguments[no];if(Ct)var En=ia(kt),oo=T1(zt,En);if(C&&(zt=dw(zt,C,y,Ct)),I&&(zt=hw(zt,I,O,Ct)),$t-=oo,Ct&&$t<Q){var Se=Kn(zt,En);return vw(c,u,Q1,kt.placeholder,f,zt,Se,P,$,Q-$t)}var er=X?f:this,Ii=dt?er[c]:c;return $t=zt.length,P?zt=LY(zt,P):yt&&$t>1&&zt.reverse(),Y&&$<$t&&(zt.length=$),this&&this!==Ge&&this instanceof kt&&(Ii=Ot||Ld(Ii)),Ii.apply(er,zt)}return kt}function Aw(c,u){return function(f,C){return $Q(f,c,u(C),{})}}function Y1(c,u){return function(f,C){var y;if(f===e&&C===e)return u;if(f!==e&&(y=f),C!==e){if(y===e)return C;typeof f=="string"||typeof C=="string"?(f=to(f),C=to(C)):(f=ow(f),C=ow(C)),y=c(f,C)}return y}}function b5(c){return wi(function(u){return u=ue(u,dn(vt())),_t(function(f){var C=this;return c(u,function(y){return yn(y,C,f)})})})}function J1(c,u){u=u===e?" ":to(u);var f=u.length;if(f<2)return f?h5(u,c):u;var C=h5(u,Dl(c/us(u)));return ui(u)?gs(Xn(C),0,c).join(""):C.slice(0,c)}function hY(c,u,f,C){var y=u&x,I=Ld(c);function O(){for(var P=-1,$=arguments.length,Q=-1,Y=C.length,X=V(Y+$),dt=this&&this!==Ge&&this instanceof O?I:c;++Q<Y;)X[Q]=C[Q];for(;$--;)X[Q++]=arguments[++P];return yn(dt,y?f:this,X)}return O}function bw(c){return function(u,f,C){return C&&typeof C!="number"&&Bn(u,f,C)&&(f=C=e),u=xi(u),f===e?(f=u,u=0):f=xi(f),C=C===e?u<f?1:-1:xi(C),JQ(u,f,C,c)}}function K1(c){return function(u,f){return typeof u=="string"&&typeof f=="string"||(u=Bo(u),f=Bo(f)),c(u,f)}}function vw(c,u,f,C,y,I,O,P,$,Q){var Y=u&H,X=Y?O:e,dt=Y?e:O,Ct=Y?I:e,yt=Y?e:I;u|=Y?q:rt,u&=~(Y?rt:q),u&M||(u&=~(x|_));var Ot=[c,u,y,Ct,X,yt,dt,P,$,Q],kt=f.apply(e,Ot);return I5(c)&&Mw(kt,Ot),kt.placeholder=C,Rw(kt,c,u)}function v5(c){var u=we[c];return function(f,C){if(f=Bo(f),C=C==null?0:L(Rt(C),292),C&&Ed(f)){var y=(Kt(f)+"e").split("e"),I=u(y[0]+"e"+(+y[1]+C));return y=(Kt(I)+"e").split("e"),+(y[0]+"e"+(+y[1]-C))}return u(f)}}var fY=ct&&1/hi(new ct([,-0]))[1]==vn?function(c){return new ct(c)}:U5;function yw(c){return function(u){var f=hn(u);return f==un?di(u):f==be?bl(u):pl(u,c(u))}}function ki(c,u,f,C,y,I,O,P){var $=u&_;if(!$&&typeof c!="function")throw new kn(s);var Q=C?C.length:0;if(Q||(u&=~(q|rt),C=y=e),O=O===e?O:T(Rt(O),0),P=P===e?P:Rt(P),Q-=y?y.length:0,u&rt){var Y=C,X=y;C=y=e}var dt=$?e:w5(c),Ct=[c,u,f,C,y,Y,X,I,O,P];if(dt&&TY(Ct,dt),c=Ct[0],u=Ct[1],f=Ct[2],C=Ct[3],y=Ct[4],P=Ct[9]=Ct[9]===e?$?0:c.length:T(Ct[9]-Q,0),!P&&u&(H|z)&&(u&=~(H|z)),!u||u==x)var yt=uY(c,u,f);else u==H||u==z?yt=dY(c,u,P):(u==q||u==(x|q))&&!y.length?yt=hY(c,u,f,C):yt=Q1.apply(e,Ct);var Ot=dt?ew:Mw;return Rw(Ot(yt,Ct),c,u)}function kw(c,u,f,C){return c===e||tr(c,mi[f])&&!Wt.call(C,f)?u:c}function ww(c,u,f,C,y,I){return ve(c)&&ve(u)&&(I.set(u,c),W1(c,u,e,ww,I),I.delete(u)),c}function mY(c){return Od(c)?e:c}function Bw(c,u,f,C,y,I){var O=f&B,P=c.length,$=u.length;if(P!=$&&!(O&&$>P))return!1;var Q=I.get(c),Y=I.get(u);if(Q&&Y)return Q==u&&Y==c;var X=-1,dt=!0,Ct=f&D?new Rl:e;for(I.set(c,u),I.set(u,c);++X<P;){var yt=c[X],Ot=u[X];if(C)var kt=O?C(Ot,yt,X,u,c,I):C(yt,Ot,X,c,u,I);if(kt!==e){if(kt)continue;dt=!1;break}if(Ct){if(!gd(u,function($t,zt){if(!Jo(Ct,zt)&&(yt===$t||y(yt,$t,f,C,I)))return Ct.push(zt)})){dt=!1;break}}else if(!(yt===Ot||y(yt,Ot,f,C,I))){dt=!1;break}}return I.delete(c),I.delete(u),dt}function gY(c,u,f,C,y,I,O){switch(f){case rs:if(c.byteLength!=u.byteLength||c.byteOffset!=u.byteOffset)return!1;c=c.buffer,u=u.buffer;case al:return!(c.byteLength!=u.byteLength||!I(new Bl(c),new Bl(u)));case ri:case Nt:case rl:return tr(+c,+u);case os:return c.name==u.name&&c.message==u.message;case il:case sl:return c==u+"";case un:var P=di;case be:var $=C&B;if(P||(P=hi),c.size!=u.size&&!$)return!1;var Q=O.get(c);if(Q)return Q==u;C|=D,O.set(c,u);var Y=Bw(P(c),P(u),C,y,I,O);return O.delete(c),Y;case ll:if(ge)return ge.call(c)==ge.call(u)}return!1}function pY(c,u,f,C,y,I){var O=f&B,P=y5(c),$=P.length,Q=y5(u),Y=Q.length;if($!=Y&&!O)return!1;for(var X=$;X--;){var dt=P[X];if(!(O?dt in u:Wt.call(u,dt)))return!1}var Ct=I.get(c),yt=I.get(u);if(Ct&&yt)return Ct==u&&yt==c;var Ot=!0;I.set(c,u),I.set(u,c);for(var kt=O;++X<$;){dt=P[X];var $t=c[dt],zt=u[dt];if(C)var no=O?C(zt,$t,dt,u,c,I):C($t,zt,dt,c,u,I);if(!(no===e?$t===zt||y($t,zt,f,C,I):no)){Ot=!1;break}kt||(kt=dt=="constructor")}if(Ot&&!kt){var En=c.constructor,oo=u.constructor;En!=oo&&"constructor"in c&&"constructor"in u&&!(typeof En=="function"&&En instanceof En&&typeof oo=="function"&&oo instanceof oo)&&(Ot=!1)}return I.delete(c),I.delete(u),Ot}function wi(c){return D5(Sw(c,e,$w),c+"")}function y5(c){return Vk(c,Ke,E5)}function k5(c){return Vk(c,Hn,Ew)}var w5=Te?function(c){return Te.get(c)}:U5;function X1(c){for(var u=c.name+"",f=en[u],C=Wt.call(en,u)?f.length:0;C--;){var y=f[C],I=y.func;if(I==null||I==c)return y.name}return u}function ia(c){var u=Wt.call(E,"placeholder")?E:c;return u.placeholder}function vt(){var c=E.iteratee||H5;return c=c===H5?Gk:c,arguments.length?c(arguments[0],arguments[1]):c}function tm(c,u){var f=c.__data__;return BY(u)?f[typeof u=="string"?"string":"hash"]:f.map}function B5(c){for(var u=Ke(c),f=u.length;f--;){var C=u[f],y=c[C];u[f]=[C,y,Tw(y)]}return u}function Fl(c,u){var f=L1(c,u);return qk(f)?f:e}function CY(c){var u=Wt.call(c,Ci),f=c[Ci];try{c[Ci]=e;var C=!0}catch{}var y=wl.call(c);return C&&(u?c[Ci]=f:delete c[Ci]),y}var E5=Ll?function(c){return c==null?[]:(c=qt(c),Qo(Ll(c),function(u){return Bd.call(c,u)}))}:z5,Ew=Ll?function(c){for(var u=[];c;)Tr(u,E5(c)),c=Dr(c);return u}:z5,hn=wn;(J&&hn(new J(new ArrayBuffer(1)))!=rs||lt&&hn(new lt)!=un||pt&&hn(pt.resolve())!=c1||ct&&hn(new ct)!=be||At&&hn(new At)!=cl)&&(hn=function(c){var u=wn(c),f=u==Co?c.constructor:e,C=f?Pl(f):"";if(C)switch(C){case Fn:return rs;case bo:return un;case X3:return c1;case t5:return be;case de:return cl}return u});function AY(c,u,f){for(var C=-1,y=f.length;++C<y;){var I=f[C],O=I.size;switch(I.type){case"drop":c+=O;break;case"dropRight":u-=O;break;case"take":u=L(u,c+O);break;case"takeRight":c=T(c,u-O);break}}return{start:c,end:u}}function bY(c){var u=c.match(se);return u?u[1].split(p3):[]}function xw(c,u,f){u=ms(u,c);for(var C=-1,y=u.length,I=!1;++C<y;){var O=Rr(u[C]);if(!(I=c!=null&&f(c,O)))break;c=c[O]}return I||++C!=y?I:(y=c==null?0:c.length,!!y&&lm(y)&&Bi(O,y)&&(St(c)||Nl(c)))}function vY(c){var u=c.length,f=new c.constructor(u);return u&&typeof c[0]=="string"&&Wt.call(c,"index")&&(f.index=c.index,f.input=c.input),f}function Iw(c){return typeof c.constructor=="function"&&!Md(c)?Sr(Dr(c)):{}}function yY(c,u,f){var C=c.constructor;switch(u){case al:return A5(c);case ri:case Nt:return new C(+c);case rs:return rY(c,f);case ju:case Uu:case zu:case Vu:case Wu:case qu:case Gu:case Zu:case Qu:return aw(c,f);case un:return new C;case rl:case sl:return new C(c);case il:return iY(c);case be:return new C;case ll:return sY(c)}}function kY(c,u){var f=u.length;if(!f)return c;var C=f-1;return u[C]=(f>1?"& ":"")+u[C],u=u.join(f>2?", ":" "),c.replace(g3,`{
|
|
729
729
|
/* [wrapped with `+u+`] */
|
|
730
|
-
`)}function wY(c){return St(c)||Nl(c)||!!(P1&&c&&c[P1])}function Bi(c,u){var f=typeof c;return u=u==null?an:u,!!u&&(f=="number"||f!="symbol"&&y3.test(c))&&c>-1&&c%1==0&&c<u}function Bn(c,u,f){if(!ve(f))return!1;var C=typeof u;return(C=="number"?$n(f)&&Bi(u,f.length):C=="string"&&u in f)?tr(f[u],c):!1}function x5(c,u){if(St(c))return!1;var f=typeof c;return f=="number"||f=="symbol"||f=="boolean"||c==null||eo(c)?!0:d3.test(c)||!u3.test(c)||u!=null&&c in qt(u)}function BY(c){var u=typeof c;return u=="string"||u=="number"||u=="symbol"||u=="boolean"?c!=="__proto__":c===null}function I5(c){var u=X1(c),f=E[u];if(typeof f!="function"||!(u in Pt.prototype))return!1;if(c===f)return!0;var C=w5(f);return!!C&&c===C[0]}function EY(c){return!!kd&&kd in c}var xY=kl?Ei:V5;function Md(c){var u=c&&c.constructor,f=typeof u=="function"&&u.prototype||mi;return c===f}function Tw(c){return c===c&&!ve(c)}function Dw(c,u){return function(f){return f==null?!1:f[c]===u&&(u!==e||c in qt(f))}}function IY(c){var u=im(c,function(C){return f.size===d&&f.clear(),C}),f=u.cache;return u}function TY(c,u){var f=c[1],C=u[1],y=f|C,I=y<(x|_|ft),O=C==ft&&f==H||C==ft&&f==Bt&&c[7].length<=u[8]||C==(ft|Bt)&&u[7].length<=u[8]&&f==H;if(!(I||O))return c;C&x&&(c[2]=u[2],y|=f&x?0:M);var P=u[3];if(P){var $=c[3];c[3]=$?dw($,P,u[4]):P,c[4]=$?Kn(c[3],h):u[4]}return P=u[5],P&&($=c[5],c[5]=$?hw($,P,u[6]):P,c[6]=$?Kn(c[5],h):u[6]),P=u[7],P&&(c[7]=P),C&ft&&(c[8]=c[8]==null?u[8]:L(c[8],u[8])),c[9]==null&&(c[9]=u[9]),c[0]=u[0],c[1]=y,c}function DY(c){var u=[];if(c!=null)for(var f in qt(c))u.push(f);return u}function SY(c){return wl.call(c)}function Sw(c,u,f){return u=T(u===e?c.length-1:u,0),function(){for(var C=arguments,y=-1,I=T(C.length-u,0),O=V(I);++y<I;)O[y]=C[u+y];y=-1;for(var P=V(u+1);++y<u;)P[y]=C[y];return P[u]=f(O),yn(c,this,P)}}function Lw(c,u){return u.length<2?c:_l(c,ko(u,0,-1))}function LY(c,u){for(var f=c.length,C=L(u.length,f),y=Nn(c);C--;){var I=u[C];c[C]=Bi(I,f)?y[I]:e}return c}function T5(c,u){if(!(u==="constructor"&&typeof c[u]=="function")&&u!="__proto__")return c[u]}var Mw=Ow(ew),Rd=H1||function(c,u){return Ge.setTimeout(c,u)},D5=Ow(tY);function Rw(c,u,f){var C=u+"";return D5(c,kY(C,MY(bY(C),f)))}function Ow(c){var u=0,f=0;return function(){var C=F(),y=Yn-(C-f);if(f=C,y>0){if(++u>=qe)return arguments[0]}else u=0;return c.apply(e,arguments)}}function em(c,u){var f=-1,C=c.length,y=C-1;for(u=u===e?C:u;++f<u;){var I=d5(f,y),O=c[I];c[I]=c[f],c[f]=O}return c.length=u,c}var _w=IY(function(c){var u=[];return c.charCodeAt(0)===46&&u.push(""),c.replace(h3,function(f,C,y,I){u.push(y?I.replace(ul,"$1"):C||f)}),u});function Mr(c){if(typeof c=="string"||eo(c))return c;var u=c+"";return u=="0"&&1/c==-vn?"-0":u}function Pl(c){if(c!=null){try{return gi.call(c)}catch{}try{return c+""}catch{}}return""}function MY(c,u){return _n(e3,function(f){var C="_."+f[0];u&f[1]&&!Vc(c,C)&&c.push(C)}),c.sort()}function Fw(c){if(c instanceof Pt)return c.clone();var u=new Pn(c.__wrapped__,c.__chain__);return u.__actions__=Nn(c.__actions__),u.__index__=c.__index__,u.__values__=c.__values__,u}function RY(c,u,f){(f?Bn(c,u,f):u===e)?u=1:u=T(Rt(u),0);var C=c==null?0:c.length;if(!C||u<1)return[];for(var y=0,I=0,O=V(Dl(C/u));y<C;)O[I++]=ko(c,y,y+=u);return O}function OY(c){for(var u=-1,f=c==null?0:c.length,C=0,y=[];++u<f;){var I=c[u];I&&(y[C++]=I)}return y}function _Y(){var c=arguments.length;if(!c)return[];for(var u=V(c-1),f=arguments[0],C=c;C--;)u[C-1]=arguments[C];return Ir(St(f)?Nn(f):[f],nn(u,1))}var FY=_t(function(c,u){return De(c)?Id(c,nn(u,1,De,!0)):[]}),PY=_t(function(c,u){var f=wo(u);return De(f)&&(f=e),De(c)?Id(c,nn(u,1,De,!0),vt(f,2)):[]}),NY=_t(function(c,u){var f=wo(u);return De(f)&&(f=e),De(c)?Id(c,nn(u,1,De,!0),e,f):[]});function $Y(c,u,f){var C=c==null?0:c.length;return C?(u=f||u===e?1:Rt(u),ko(c,u<0?0:u,C)):[]}function HY(c,u,f){var C=c==null?0:c.length;return C?(u=f||u===e?1:Rt(u),u=C-u,ko(c,0,u<0?0:u)):[]}function jY(c,u){return c&&c.length?G1(c,vt(u,3),!0,!0):[]}function UY(c,u){return c&&c.length?G1(c,vt(u,3),!0):[]}function zY(c,u,f,C){var y=c==null?0:c.length;return y?(f&&typeof f!="number"&&Bn(c,u,f)&&(f=0,C=y),_Q(c,u,f,C)):[]}function Pw(c,u,f){var C=c==null?0:c.length;if(!C)return-1;var y=f==null?0:Rt(f);return y<0&&(y=T(C+y,0)),ml(c,vt(u,3),y)}function Nw(c,u,f){var C=c==null?0:c.length;if(!C)return-1;var y=C-1;return f!==e&&(y=Rt(f),y=f<0?T(C+y,0):L(y,C-1)),ml(c,vt(u,3),y,!0)}function $w(c){var u=c==null?0:c.length;return u?nn(c,1):[]}function VY(c){var u=c==null?0:c.length;return u?nn(c,vn):[]}function WY(c,u){var f=c==null?0:c.length;return f?(u=u===e?1:Rt(u),nn(c,u)):[]}function qY(c){for(var u=-1,f=c==null?0:c.length,C={};++u<f;){var y=c[u];C[y[0]]=y[1]}return C}function Hw(c){return c&&c.length?c[0]:e}function GY(c,u,f){var C=c==null?0:c.length;if(!C)return-1;var y=f==null?0:Rt(f);return y<0&&(y=T(C+y,0)),ci(c,u,y)}function ZY(c){var u=c==null?0:c.length;return u?ko(c,0,-1):[]}var QY=_t(function(c){var u=ue(c,p5);return u.length&&u[0]===c[0]?s5(u):[]}),YY=_t(function(c){var u=wo(c),f=ue(c,p5);return u===wo(f)?u=e:f.pop(),f.length&&f[0]===c[0]?s5(f,vt(u,2)):[]}),JY=_t(function(c){var u=wo(c),f=ue(c,p5);return u=typeof u=="function"?u:e,u&&f.pop(),f.length&&f[0]===c[0]?s5(f,e,u):[]});function KY(c,u){return c==null?"":K3.call(c,u)}function wo(c){var u=c==null?0:c.length;return u?c[u-1]:e}function XY(c,u,f){var C=c==null?0:c.length;if(!C)return-1;var y=C;return f!==e&&(y=Rt(f),y=y<0?T(C+y,0):L(y,C-1)),u===u?M1(c,u,y):ml(c,Yo,y,!0)}function tJ(c,u){return c&&c.length?Jk(c,Rt(u)):e}var eJ=_t(jw);function jw(c,u){return c&&c.length&&u&&u.length?u5(c,u):c}function nJ(c,u,f){return c&&c.length&&u&&u.length?u5(c,u,vt(f,2)):c}function oJ(c,u,f){return c&&c.length&&u&&u.length?u5(c,u,e,f):c}var rJ=wi(function(c,u){var f=c==null?0:c.length,C=n5(c,u);return tw(c,ue(u,function(y){return Bi(y,f)?+y:y}).sort(uw)),C});function iJ(c,u){var f=[];if(!(c&&c.length))return f;var C=-1,y=[],I=c.length;for(u=vt(u,3);++C<I;){var O=c[C];u(O,C,c)&&(f.push(O),y.push(C))}return tw(c,y),f}function S5(c){return c==null?c:Z.call(c)}function sJ(c,u,f){var C=c==null?0:c.length;return C?(f&&typeof f!="number"&&Bn(c,u,f)?(u=0,f=C):(u=u==null?0:Rt(u),f=f===e?C:Rt(f)),ko(c,u,f)):[]}function lJ(c,u){return q1(c,u)}function cJ(c,u,f){return f5(c,u,vt(f,2))}function aJ(c,u){var f=c==null?0:c.length;if(f){var C=q1(c,u);if(C<f&&tr(c[C],u))return C}return-1}function uJ(c,u){return q1(c,u,!0)}function dJ(c,u,f){return f5(c,u,vt(f,2),!0)}function hJ(c,u){var f=c==null?0:c.length;if(f){var C=q1(c,u,!0)-1;if(tr(c[C],u))return C}return-1}function fJ(c){return c&&c.length?nw(c):[]}function mJ(c,u){return c&&c.length?nw(c,vt(u,2)):[]}function gJ(c){var u=c==null?0:c.length;return u?ko(c,1,u):[]}function pJ(c,u,f){return c&&c.length?(u=f||u===e?1:Rt(u),ko(c,0,u<0?0:u)):[]}function CJ(c,u,f){var C=c==null?0:c.length;return C?(u=f||u===e?1:Rt(u),u=C-u,ko(c,u<0?0:u,C)):[]}function AJ(c,u){return c&&c.length?G1(c,vt(u,3),!1,!0):[]}function bJ(c,u){return c&&c.length?G1(c,vt(u,3)):[]}var vJ=_t(function(c){return fs(nn(c,1,De,!0))}),yJ=_t(function(c){var u=wo(c);return De(u)&&(u=e),fs(nn(c,1,De,!0),vt(u,2))}),kJ=_t(function(c){var u=wo(c);return u=typeof u=="function"?u:e,fs(nn(c,1,De,!0),e,u)});function wJ(c){return c&&c.length?fs(c):[]}function BJ(c,u){return c&&c.length?fs(c,vt(u,2)):[]}function EJ(c,u){return u=typeof u=="function"?u:e,c&&c.length?fs(c,e,u):[]}function L5(c){if(!(c&&c.length))return[];var u=0;return c=Qo(c,function(f){if(De(f))return u=T(f.length,u),!0}),Zc(u,function(f){return ue(c,qc(f))})}function Uw(c,u){if(!(c&&c.length))return[];var f=L5(c);return u==null?f:ue(f,function(C){return yn(u,e,C)})}var xJ=_t(function(c,u){return De(c)?Id(c,u):[]}),IJ=_t(function(c){return g5(Qo(c,De))}),TJ=_t(function(c){var u=wo(c);return De(u)&&(u=e),g5(Qo(c,De),vt(u,2))}),DJ=_t(function(c){var u=wo(c);return u=typeof u=="function"?u:e,g5(Qo(c,De),e,u)}),SJ=_t(L5);function LJ(c,u){return sw(c||[],u||[],xd)}function MJ(c,u){return sw(c||[],u||[],Sd)}var RJ=_t(function(c){var u=c.length,f=u>1?c[u-1]:e;return f=typeof f=="function"?(c.pop(),f):e,Uw(c,f)});function zw(c){var u=E(c);return u.__chain__=!0,u}function OJ(c,u){return u(c),c}function nm(c,u){return u(c)}var _J=wi(function(c){var u=c.length,f=u?c[0]:0,C=this.__wrapped__,y=function(I){return n5(I,c)};return u>1||this.__actions__.length||!(C instanceof Pt)||!Bi(f)?this.thru(y):(C=C.slice(f,+f+(u?1:0)),C.__actions__.push({func:nm,args:[y],thisArg:e}),new Pn(C,this.__chain__).thru(function(I){return u&&!I.length&&I.push(e),I}))});function FJ(){return zw(this)}function PJ(){return new Pn(this.value(),this.__chain__)}function NJ(){this.__values__===e&&(this.__values__=oB(this.value()));var c=this.__index__>=this.__values__.length,u=c?e:this.__values__[this.__index__++];return{done:c,value:u}}function $J(){return this}function HJ(c){for(var u,f=this;f instanceof ds;){var C=Fw(f);C.__index__=0,C.__values__=e,u?y.__wrapped__=C:u=C;var y=C;f=f.__wrapped__}return y.__wrapped__=c,u}function jJ(){var c=this.__wrapped__;if(c instanceof Pt){var u=c;return this.__actions__.length&&(u=new Pt(this)),u=u.reverse(),u.__actions__.push({func:nm,args:[S5],thisArg:e}),new Pn(u,this.__chain__)}return this.thru(S5)}function UJ(){return iw(this.__wrapped__,this.__actions__)}var zJ=Z1(function(c,u,f){Wt.call(c,f)?++c[f]:yi(c,f,1)});function VJ(c,u,f){var C=St(c)?E1:OQ;return f&&Bn(c,u,f)&&(u=e),C(c,vt(u,3))}function WJ(c,u){var f=St(c)?Qo:Uk;return f(c,vt(u,3))}var qJ=pw(Pw),GJ=pw(Nw);function ZJ(c,u){return nn(om(c,u),1)}function QJ(c,u){return nn(om(c,u),vn)}function YJ(c,u,f){return f=f===e?1:Rt(f),nn(om(c,u),f)}function Vw(c,u){var f=St(c)?_n:hs;return f(c,vt(u,3))}function Ww(c,u){var f=St(c)?Q3:jk;return f(c,vt(u,3))}var JJ=Z1(function(c,u,f){Wt.call(c,f)?c[f].push(u):yi(c,f,[u])});function KJ(c,u,f,C){c=$n(c)?c:la(c),f=f&&!C?Rt(f):0;var y=c.length;return f<0&&(f=T(y+f,0)),cm(c)?f<=y&&c.indexOf(u,f)>-1:!!y&&ci(c,u,f)>-1}var XJ=_t(function(c,u,f){var C=-1,y=typeof u=="function",I=$n(c)?V(c.length):[];return hs(c,function(O){I[++C]=y?yn(u,O,f):Td(O,u,f)}),I}),tK=Z1(function(c,u,f){yi(c,f,u)});function om(c,u){var f=St(c)?ue:Zk;return f(c,vt(u,3))}function eK(c,u,f,C){return c==null?[]:(St(u)||(u=u==null?[]:[u]),f=C?e:f,St(f)||(f=f==null?[]:[f]),Kk(c,u,f))}var nK=Z1(function(c,u,f){c[f?0:1].push(u)},function(){return[[],[]]});function oK(c,u,f){var C=St(c)?md:gl,y=arguments.length<3;return C(c,vt(u,4),f,y,hs)}function rK(c,u,f){var C=St(c)?Y3:gl,y=arguments.length<3;return C(c,vt(u,4),f,y,jk)}function iK(c,u){var f=St(c)?Qo:Uk;return f(c,sm(vt(u,3)))}function sK(c){var u=St(c)?Pk:KQ;return u(c)}function lK(c,u,f){(f?Bn(c,u,f):u===e)?u=1:u=Rt(u);var C=St(c)?DQ:XQ;return C(c,u)}function cK(c){var u=St(c)?SQ:eY;return u(c)}function aK(c){if(c==null)return 0;if($n(c))return cm(c)?us(c):c.length;var u=hn(c);return u==un||u==be?c.size:c5(c).length}function uK(c,u,f){var C=St(c)?gd:nY;return f&&Bn(c,u,f)&&(u=e),C(c,vt(u,3))}var dK=_t(function(c,u){if(c==null)return[];var f=u.length;return f>1&&Bn(c,u[0],u[1])?u=[]:f>2&&Bn(u[0],u[1],u[2])&&(u=[u[0]]),Kk(c,nn(u,1),[])}),rm=$1||function(){return Ge.Date.now()};function hK(c,u){if(typeof u!="function")throw new kn(s);return c=Rt(c),function(){if(--c<1)return u.apply(this,arguments)}}function qw(c,u,f){return u=f?e:u,u=c&&u==null?c.length:u,ki(c,ft,e,e,e,e,u)}function Gw(c,u){var f;if(typeof u!="function")throw new kn(s);return c=Rt(c),function(){return--c>0&&(f=u.apply(this,arguments)),c<=1&&(u=e),f}}var M5=_t(function(c,u,f){var C=x;if(f.length){var y=Kn(f,ia(M5));C|=q}return ki(c,C,u,f,y)}),Zw=_t(function(c,u,f){var C=x|_;if(f.length){var y=Kn(f,ia(Zw));C|=q}return ki(u,C,c,f,y)});function Qw(c,u,f){u=f?e:u;var C=ki(c,H,e,e,e,e,e,u);return C.placeholder=Qw.placeholder,C}function Yw(c,u,f){u=f?e:u;var C=ki(c,z,e,e,e,e,e,u);return C.placeholder=Yw.placeholder,C}function Jw(c,u,f){var C,y,I,O,P,$,Q=0,Y=!1,X=!1,dt=!0;if(typeof c!="function")throw new kn(s);u=Bo(u)||0,ve(f)&&(Y=!!f.leading,X="maxWait"in f,I=X?T(Bo(f.maxWait)||0,u):I,dt="trailing"in f?!!f.trailing:dt);function Ct(Se){var er=C,Ii=y;return C=y=e,Q=Se,O=c.apply(Ii,er),O}function yt(Se){return Q=Se,P=Rd($t,u),Y?Ct(Se):O}function Ot(Se){var er=Se-$,Ii=Se-Q,pB=u-er;return X?L(pB,I-Ii):pB}function kt(Se){var er=Se-$,Ii=Se-Q;return $===e||er>=u||er<0||X&&Ii>=I}function $t(){var Se=rm();if(kt(Se))return zt(Se);P=Rd($t,Ot(Se))}function zt(Se){return P=e,dt&&C?Ct(Se):(C=y=e,O)}function no(){P!==e&&lw(P),Q=0,C=$=y=P=e}function En(){return P===e?O:zt(rm())}function oo(){var Se=rm(),er=kt(Se);if(C=arguments,y=this,$=Se,er){if(P===e)return yt($);if(X)return lw(P),P=Rd($t,u),Ct($)}return P===e&&(P=Rd($t,u)),O}return oo.cancel=no,oo.flush=En,oo}var fK=_t(function(c,u){return Hk(c,1,u)}),mK=_t(function(c,u,f){return Hk(c,Bo(u)||0,f)});function gK(c){return ki(c,jt)}function im(c,u){if(typeof c!="function"||u!=null&&typeof u!="function")throw new kn(s);var f=function(){var C=arguments,y=u?u.apply(this,C):C[0],I=f.cache;if(I.has(y))return I.get(y);var O=c.apply(this,C);return f.cache=I.set(y,O)||I,O};return f.cache=new(im.Cache||vi),f}im.Cache=vi;function sm(c){if(typeof c!="function")throw new kn(s);return function(){var u=arguments;switch(u.length){case 0:return!c.call(this);case 1:return!c.call(this,u[0]);case 2:return!c.call(this,u[0],u[1]);case 3:return!c.call(this,u[0],u[1],u[2])}return!c.apply(this,u)}}function pK(c){return Gw(2,c)}var CK=oY(function(c,u){u=u.length==1&&St(u[0])?ue(u[0],dn(vt())):ue(nn(u,1),dn(vt()));var f=u.length;return _t(function(C){for(var y=-1,I=L(C.length,f);++y<I;)C[y]=u[y].call(this,C[y]);return yn(c,this,C)})}),R5=_t(function(c,u){var f=Kn(u,ia(R5));return ki(c,q,e,u,f)}),Kw=_t(function(c,u){var f=Kn(u,ia(Kw));return ki(c,rt,e,u,f)}),AK=wi(function(c,u){return ki(c,Bt,e,e,e,u)});function bK(c,u){if(typeof c!="function")throw new kn(s);return u=u===e?u:Rt(u),_t(c,u)}function vK(c,u){if(typeof c!="function")throw new kn(s);return u=u==null?0:T(Rt(u),0),_t(function(f){var C=f[u],y=gs(f,0,u);return C&&Ir(y,C),yn(c,this,y)})}function yK(c,u,f){var C=!0,y=!0;if(typeof c!="function")throw new kn(s);return ve(f)&&(C="leading"in f?!!f.leading:C,y="trailing"in f?!!f.trailing:y),Jw(c,u,{leading:C,maxWait:u,trailing:y})}function kK(c){return qw(c,1)}function wK(c,u){return R5(C5(u),c)}function BK(){if(!arguments.length)return[];var c=arguments[0];return St(c)?c:[c]}function EK(c){return yo(c,v)}function xK(c,u){return u=typeof u=="function"?u:e,yo(c,v,u)}function IK(c){return yo(c,p|v)}function TK(c,u){return u=typeof u=="function"?u:e,yo(c,p|v,u)}function DK(c,u){return u==null||$k(c,u,Ke(u))}function tr(c,u){return c===u||c!==c&&u!==u}var SK=K1(i5),LK=K1(function(c,u){return c>=u}),Nl=Wk(function(){return arguments}())?Wk:function(c){return Be(c)&&Wt.call(c,"callee")&&!Bd.call(c,"callee")},St=V.isArray,MK=cd?dn(cd):HQ;function $n(c){return c!=null&&lm(c.length)&&!Ei(c)}function De(c){return Be(c)&&$n(c)}function RK(c){return c===!0||c===!1||Be(c)&&wn(c)==ri}var ps=j1||V5,OK=ad?dn(ad):jQ;function _K(c){return Be(c)&&c.nodeType===1&&!Od(c)}function FK(c){if(c==null)return!0;if($n(c)&&(St(c)||typeof c=="string"||typeof c.splice=="function"||ps(c)||sa(c)||Nl(c)))return!c.length;var u=hn(c);if(u==un||u==be)return!c.size;if(Md(c))return!c5(c).length;for(var f in c)if(Wt.call(c,f))return!1;return!0}function PK(c,u){return Dd(c,u)}function NK(c,u,f){f=typeof f=="function"?f:e;var C=f?f(c,u):e;return C===e?Dd(c,u,e,f):!!C}function O5(c){if(!Be(c))return!1;var u=wn(c);return u==os||u==Br||typeof c.message=="string"&&typeof c.name=="string"&&!Od(c)}function $K(c){return typeof c=="number"&&Ed(c)}function Ei(c){if(!ve(c))return!1;var u=wn(c);return u==Fc||u==s1||u==ol||u==n3}function Xw(c){return typeof c=="number"&&c==Rt(c)}function lm(c){return typeof c=="number"&&c>-1&&c%1==0&&c<=an}function ve(c){var u=typeof c;return c!=null&&(u=="object"||u=="function")}function Be(c){return c!=null&&typeof c=="object"}var tB=ud?dn(ud):zQ;function HK(c,u){return c===u||l5(c,u,B5(u))}function jK(c,u,f){return f=typeof f=="function"?f:e,l5(c,u,B5(u),f)}function UK(c){return eB(c)&&c!=+c}function zK(c){if(xY(c))throw new Et(i);return qk(c)}function VK(c){return c===null}function WK(c){return c==null}function eB(c){return typeof c=="number"||Be(c)&&wn(c)==rl}function Od(c){if(!Be(c)||wn(c)!=Co)return!1;var u=Tr(c);if(u===null)return!0;var f=Wt.call(u,"constructor")&&u.constructor;return typeof f=="function"&&f instanceof f&&gi.call(f)==wd}var _5=B1?dn(B1):VQ;function qK(c){return Xw(c)&&c>=-an&&c<=an}var nB=dd?dn(dd):WQ;function cm(c){return typeof c=="string"||!St(c)&&Be(c)&&wn(c)==sl}function eo(c){return typeof c=="symbol"||Be(c)&&wn(c)==ll}var sa=hd?dn(hd):qQ;function GK(c){return c===e}function ZK(c){return Be(c)&&hn(c)==cl}function QK(c){return Be(c)&&wn(c)==u1}var YK=K1(a5),JK=K1(function(c,u){return c<=u});function oB(c){if(!c)return[];if($n(c))return cm(c)?Xn(c):Nn(c);if(Tl&&c[Tl])return Al(c[Tl]());var u=hn(c),f=u==un?di:u==be?hi:la;return f(c)}function xi(c){if(!c)return c===0?c:0;if(c=Bo(c),c===vn||c===-vn){var u=c<0?-1:1;return u*wr}return c===c?c:0}function Rt(c){var u=xi(c),f=u%1;return u===u?f?u-f:u:0}function rB(c){return c?Ol(Rt(c),0,po):0}function Bo(c){if(typeof c=="number")return c;if(eo(c))return oi;if(ve(c)){var u=typeof c.valueOf=="function"?c.valueOf():c;c=ve(u)?u+"":u}if(typeof c!="string")return c===0?c:+c;c=ai(c);var f=p1.test(c);return f||v3.test(c)?q3(c.slice(2),f?2:8):g1.test(c)?oi:+c}function iB(c){return Lr(c,Hn(c))}function KK(c){return c?Ol(Rt(c),-an,an):c===0?c:0}function Kt(c){return c==null?"":to(c)}var XK=oa(function(c,u){if(Md(u)||$n(u)){Lr(u,Ke(u),c);return}for(var f in u)Wt.call(u,f)&&xd(c,f,u[f])}),sB=oa(function(c,u){Lr(u,Hn(u),c)}),am=oa(function(c,u,f,C){Lr(u,Hn(u),c,C)}),tX=oa(function(c,u,f,C){Lr(u,Ke(u),c,C)}),eX=wi(n5);function nX(c,u){var f=Dr(c);return u==null?f:Nk(f,u)}var oX=_t(function(c,u){c=qt(c);var f=-1,C=u.length,y=C>2?u[2]:e;for(y&&Bn(u[0],u[1],y)&&(C=1);++f<C;)for(var I=u[f],O=Hn(I),P=-1,$=O.length;++P<$;){var Q=O[P],Y=c[Q];(Y===e||tr(Y,mi[Q])&&!Wt.call(c,Q))&&(c[Q]=I[Q])}return c}),rX=_t(function(c){return c.push(e,ww),yn(lB,e,c)});function iX(c,u){return pd(c,vt(u,3),Sr)}function sX(c,u){return pd(c,vt(u,3),r5)}function lX(c,u){return c==null?c:o5(c,vt(u,3),Hn)}function cX(c,u){return c==null?c:zk(c,vt(u,3),Hn)}function aX(c,u){return c&&Sr(c,vt(u,3))}function uX(c,u){return c&&r5(c,vt(u,3))}function dX(c){return c==null?[]:V1(c,Ke(c))}function hX(c){return c==null?[]:V1(c,Hn(c))}function F5(c,u,f){var C=c==null?e:_l(c,u);return C===e?f:C}function fX(c,u){return c!=null&&xw(c,u,FQ)}function P5(c,u){return c!=null&&xw(c,u,PQ)}var mX=Aw(function(c,u,f){u!=null&&typeof u.toString!="function"&&(u=wl.call(u)),c[u]=f},$5(jn)),gX=Aw(function(c,u,f){u!=null&&typeof u.toString!="function"&&(u=wl.call(u)),Wt.call(c,u)?c[u].push(f):c[u]=[f]},vt),pX=_t(Td);function Ke(c){return $n(c)?Fk(c):c5(c)}function Hn(c){return $n(c)?Fk(c,!0):GQ(c)}function CX(c,u){var f={};return u=vt(u,3),Sr(c,function(C,y,I){yi(f,u(C,y,I),C)}),f}function AX(c,u){var f={};return u=vt(u,3),Sr(c,function(C,y,I){yi(f,y,u(C,y,I))}),f}var bX=oa(function(c,u,f){W1(c,u,f)}),lB=oa(function(c,u,f,C){W1(c,u,f,C)}),vX=wi(function(c,u){var f={};if(c==null)return f;var C=!1;u=ue(u,function(I){return I=ms(I,c),C||(C=I.length>1),I}),Lr(c,k5(c),f),C&&(f=yo(f,p|A|v,mY));for(var y=u.length;y--;)m5(f,u[y]);return f});function yX(c,u){return cB(c,sm(vt(u)))}var kX=wi(function(c,u){return c==null?{}:QQ(c,u)});function cB(c,u){if(c==null)return{};var f=ue(k5(c),function(C){return[C]});return u=vt(u),Xk(c,f,function(C,y){return u(C,y[0])})}function wX(c,u,f){u=ms(u,c);var C=-1,y=u.length;for(y||(y=1,c=e);++C<y;){var I=c==null?e:c[Mr(u[C])];I===e&&(C=y,I=f),c=Ei(I)?I.call(c):I}return c}function BX(c,u,f){return c==null?c:Sd(c,u,f)}function EX(c,u,f,C){return C=typeof C=="function"?C:e,c==null?c:Sd(c,u,f,C)}var aB=yw(Ke),uB=yw(Hn);function xX(c,u,f){var C=St(c),y=C||ps(c)||sa(c);if(u=vt(u,4),f==null){var I=c&&c.constructor;y?f=C?new I:[]:ve(c)?f=Ei(I)?Dr(Tr(c)):{}:f={}}return(y?_n:Sr)(c,function(O,P,$){return u(f,O,P,$)}),f}function IX(c,u){return c==null?!0:m5(c,u)}function TX(c,u,f){return c==null?c:rw(c,u,C5(f))}function DX(c,u,f,C){return C=typeof C=="function"?C:e,c==null?c:rw(c,u,C5(f),C)}function la(c){return c==null?[]:as(c,Ke(c))}function SX(c){return c==null?[]:as(c,Hn(c))}function LX(c,u,f){return f===e&&(f=u,u=e),f!==e&&(f=Bo(f),f=f===f?f:0),u!==e&&(u=Bo(u),u=u===u?u:0),Ol(Bo(c),u,f)}function MX(c,u,f){return u=xi(u),f===e?(f=u,u=0):f=xi(f),c=Bo(c),NQ(c,u,f)}function RX(c,u,f){if(f&&typeof f!="boolean"&&Bn(c,u,f)&&(u=f=e),f===e&&(typeof u=="boolean"?(f=u,u=e):typeof c=="boolean"&&(f=c,c=e)),c===e&&u===e?(c=0,u=1):(c=xi(c),u===e?(u=c,c=0):u=xi(u)),c>u){var C=c;c=u,u=C}if(f||c%1||u%1){var y=j();return L(c+y*(u-c+k1("1e-"+((y+"").length-1))),u)}return d5(c,u)}var OX=ra(function(c,u,f){return u=u.toLowerCase(),c+(f?dB(u):u)});function dB(c){return N5(Kt(c).toLowerCase())}function hB(c){return c=Kt(c),c&&c.replace(k3,D1).replace(F3,"")}function _X(c,u,f){c=Kt(c),u=to(u);var C=c.length;f=f===e?C:Ol(Rt(f),0,C);var y=f;return f-=u.length,f>=0&&c.slice(f,y)==u}function FX(c){return c=Kt(c),c&&l3.test(c)?c.replace(h1,bd):c}function PX(c){return c=Kt(c),c&&f3.test(c)?c.replace(Yu,"\\$&"):c}var NX=ra(function(c,u,f){return c+(f?"-":"")+u.toLowerCase()}),$X=ra(function(c,u,f){return c+(f?" ":"")+u.toLowerCase()}),HX=gw("toLowerCase");function jX(c,u,f){c=Kt(c),u=Rt(u);var C=u?us(c):0;if(!u||C>=u)return c;var y=(u-C)/2;return J1(Sl(y),f)+c+J1(Dl(y),f)}function UX(c,u,f){c=Kt(c),u=Rt(u);var C=u?us(c):0;return u&&C<u?c+J1(u-C,f):c}function zX(c,u,f){c=Kt(c),u=Rt(u);var C=u?us(c):0;return u&&C<u?J1(u-C,f)+c:c}function VX(c,u,f){return f||u==null?u=0:u&&(u=+u),U(Kt(c).replace(Ju,""),u||0)}function WX(c,u,f){return(f?Bn(c,u,f):u===e)?u=1:u=Rt(u),h5(Kt(c),u)}function qX(){var c=arguments,u=Kt(c[0]);return c.length<3?u:u.replace(c[1],c[2])}var GX=ra(function(c,u,f){return c+(f?"_":"")+u.toLowerCase()});function ZX(c,u,f){return f&&typeof f!="number"&&Bn(c,u,f)&&(u=f=e),f=f===e?po:f>>>0,f?(c=Kt(c),c&&(typeof u=="string"||u!=null&&!_5(u))&&(u=to(u),!u&&ui(c))?gs(Xn(c),0,f):c.split(u,f)):[]}var QX=ra(function(c,u,f){return c+(f?" ":"")+N5(u)});function YX(c,u,f){return c=Kt(c),f=f==null?0:Ol(Rt(f),0,c.length),u=to(u),c.slice(f,f+u.length)==u}function JX(c,u,f){var C=E.templateSettings;f&&Bn(c,u,f)&&(u=e),c=Kt(c),u=am({},u,C,kw);var y=am({},u.imports,C.imports,kw),I=Ke(y),O=as(y,I),P,$,Q=0,Y=u.interpolate||Nc,X="__p += '",dt=na((u.escape||Nc).source+"|"+Y.source+"|"+(Y===f1?A3:Nc).source+"|"+(u.evaluate||Nc).source+"|$","g"),Ct="//# sourceURL="+(Wt.call(u,"sourceURL")?(u.sourceURL+"").replace(/\s/g," "):"lodash.templateSources["+ ++j3+"]")+`
|
|
730
|
+
`)}function wY(c){return St(c)||Nl(c)||!!(P1&&c&&c[P1])}function Bi(c,u){var f=typeof c;return u=u==null?an:u,!!u&&(f=="number"||f!="symbol"&&y3.test(c))&&c>-1&&c%1==0&&c<u}function Bn(c,u,f){if(!ve(f))return!1;var C=typeof u;return(C=="number"?$n(f)&&Bi(u,f.length):C=="string"&&u in f)?tr(f[u],c):!1}function x5(c,u){if(St(c))return!1;var f=typeof c;return f=="number"||f=="symbol"||f=="boolean"||c==null||eo(c)?!0:d3.test(c)||!u3.test(c)||u!=null&&c in qt(u)}function BY(c){var u=typeof c;return u=="string"||u=="number"||u=="symbol"||u=="boolean"?c!=="__proto__":c===null}function I5(c){var u=X1(c),f=E[u];if(typeof f!="function"||!(u in Pt.prototype))return!1;if(c===f)return!0;var C=w5(f);return!!C&&c===C[0]}function EY(c){return!!kd&&kd in c}var xY=kl?Ei:V5;function Md(c){var u=c&&c.constructor,f=typeof u=="function"&&u.prototype||mi;return c===f}function Tw(c){return c===c&&!ve(c)}function Dw(c,u){return function(f){return f==null?!1:f[c]===u&&(u!==e||c in qt(f))}}function IY(c){var u=im(c,function(C){return f.size===d&&f.clear(),C}),f=u.cache;return u}function TY(c,u){var f=c[1],C=u[1],y=f|C,I=y<(x|_|ft),O=C==ft&&f==H||C==ft&&f==Bt&&c[7].length<=u[8]||C==(ft|Bt)&&u[7].length<=u[8]&&f==H;if(!(I||O))return c;C&x&&(c[2]=u[2],y|=f&x?0:M);var P=u[3];if(P){var $=c[3];c[3]=$?dw($,P,u[4]):P,c[4]=$?Kn(c[3],h):u[4]}return P=u[5],P&&($=c[5],c[5]=$?hw($,P,u[6]):P,c[6]=$?Kn(c[5],h):u[6]),P=u[7],P&&(c[7]=P),C&ft&&(c[8]=c[8]==null?u[8]:L(c[8],u[8])),c[9]==null&&(c[9]=u[9]),c[0]=u[0],c[1]=y,c}function DY(c){var u=[];if(c!=null)for(var f in qt(c))u.push(f);return u}function SY(c){return wl.call(c)}function Sw(c,u,f){return u=T(u===e?c.length-1:u,0),function(){for(var C=arguments,y=-1,I=T(C.length-u,0),O=V(I);++y<I;)O[y]=C[u+y];y=-1;for(var P=V(u+1);++y<u;)P[y]=C[y];return P[u]=f(O),yn(c,this,P)}}function Lw(c,u){return u.length<2?c:_l(c,ko(u,0,-1))}function LY(c,u){for(var f=c.length,C=L(u.length,f),y=Nn(c);C--;){var I=u[C];c[C]=Bi(I,f)?y[I]:e}return c}function T5(c,u){if(!(u==="constructor"&&typeof c[u]=="function")&&u!="__proto__")return c[u]}var Mw=Ow(ew),Rd=H1||function(c,u){return Ge.setTimeout(c,u)},D5=Ow(tY);function Rw(c,u,f){var C=u+"";return D5(c,kY(C,MY(bY(C),f)))}function Ow(c){var u=0,f=0;return function(){var C=F(),y=Yn-(C-f);if(f=C,y>0){if(++u>=qe)return arguments[0]}else u=0;return c.apply(e,arguments)}}function em(c,u){var f=-1,C=c.length,y=C-1;for(u=u===e?C:u;++f<u;){var I=d5(f,y),O=c[I];c[I]=c[f],c[f]=O}return c.length=u,c}var _w=IY(function(c){var u=[];return c.charCodeAt(0)===46&&u.push(""),c.replace(h3,function(f,C,y,I){u.push(y?I.replace(ul,"$1"):C||f)}),u});function Rr(c){if(typeof c=="string"||eo(c))return c;var u=c+"";return u=="0"&&1/c==-vn?"-0":u}function Pl(c){if(c!=null){try{return gi.call(c)}catch{}try{return c+""}catch{}}return""}function MY(c,u){return _n(e3,function(f){var C="_."+f[0];u&f[1]&&!Vc(c,C)&&c.push(C)}),c.sort()}function Fw(c){if(c instanceof Pt)return c.clone();var u=new Pn(c.__wrapped__,c.__chain__);return u.__actions__=Nn(c.__actions__),u.__index__=c.__index__,u.__values__=c.__values__,u}function RY(c,u,f){(f?Bn(c,u,f):u===e)?u=1:u=T(Rt(u),0);var C=c==null?0:c.length;if(!C||u<1)return[];for(var y=0,I=0,O=V(Dl(C/u));y<C;)O[I++]=ko(c,y,y+=u);return O}function OY(c){for(var u=-1,f=c==null?0:c.length,C=0,y=[];++u<f;){var I=c[u];I&&(y[C++]=I)}return y}function _Y(){var c=arguments.length;if(!c)return[];for(var u=V(c-1),f=arguments[0],C=c;C--;)u[C-1]=arguments[C];return Tr(St(f)?Nn(f):[f],nn(u,1))}var FY=_t(function(c,u){return De(c)?Id(c,nn(u,1,De,!0)):[]}),PY=_t(function(c,u){var f=wo(u);return De(f)&&(f=e),De(c)?Id(c,nn(u,1,De,!0),vt(f,2)):[]}),NY=_t(function(c,u){var f=wo(u);return De(f)&&(f=e),De(c)?Id(c,nn(u,1,De,!0),e,f):[]});function $Y(c,u,f){var C=c==null?0:c.length;return C?(u=f||u===e?1:Rt(u),ko(c,u<0?0:u,C)):[]}function HY(c,u,f){var C=c==null?0:c.length;return C?(u=f||u===e?1:Rt(u),u=C-u,ko(c,0,u<0?0:u)):[]}function jY(c,u){return c&&c.length?G1(c,vt(u,3),!0,!0):[]}function UY(c,u){return c&&c.length?G1(c,vt(u,3),!0):[]}function zY(c,u,f,C){var y=c==null?0:c.length;return y?(f&&typeof f!="number"&&Bn(c,u,f)&&(f=0,C=y),_Q(c,u,f,C)):[]}function Pw(c,u,f){var C=c==null?0:c.length;if(!C)return-1;var y=f==null?0:Rt(f);return y<0&&(y=T(C+y,0)),ml(c,vt(u,3),y)}function Nw(c,u,f){var C=c==null?0:c.length;if(!C)return-1;var y=C-1;return f!==e&&(y=Rt(f),y=f<0?T(C+y,0):L(y,C-1)),ml(c,vt(u,3),y,!0)}function $w(c){var u=c==null?0:c.length;return u?nn(c,1):[]}function VY(c){var u=c==null?0:c.length;return u?nn(c,vn):[]}function WY(c,u){var f=c==null?0:c.length;return f?(u=u===e?1:Rt(u),nn(c,u)):[]}function qY(c){for(var u=-1,f=c==null?0:c.length,C={};++u<f;){var y=c[u];C[y[0]]=y[1]}return C}function Hw(c){return c&&c.length?c[0]:e}function GY(c,u,f){var C=c==null?0:c.length;if(!C)return-1;var y=f==null?0:Rt(f);return y<0&&(y=T(C+y,0)),ci(c,u,y)}function ZY(c){var u=c==null?0:c.length;return u?ko(c,0,-1):[]}var QY=_t(function(c){var u=ue(c,p5);return u.length&&u[0]===c[0]?s5(u):[]}),YY=_t(function(c){var u=wo(c),f=ue(c,p5);return u===wo(f)?u=e:f.pop(),f.length&&f[0]===c[0]?s5(f,vt(u,2)):[]}),JY=_t(function(c){var u=wo(c),f=ue(c,p5);return u=typeof u=="function"?u:e,u&&f.pop(),f.length&&f[0]===c[0]?s5(f,e,u):[]});function KY(c,u){return c==null?"":K3.call(c,u)}function wo(c){var u=c==null?0:c.length;return u?c[u-1]:e}function XY(c,u,f){var C=c==null?0:c.length;if(!C)return-1;var y=C;return f!==e&&(y=Rt(f),y=y<0?T(C+y,0):L(y,C-1)),u===u?M1(c,u,y):ml(c,Yo,y,!0)}function tJ(c,u){return c&&c.length?Jk(c,Rt(u)):e}var eJ=_t(jw);function jw(c,u){return c&&c.length&&u&&u.length?u5(c,u):c}function nJ(c,u,f){return c&&c.length&&u&&u.length?u5(c,u,vt(f,2)):c}function oJ(c,u,f){return c&&c.length&&u&&u.length?u5(c,u,e,f):c}var rJ=wi(function(c,u){var f=c==null?0:c.length,C=n5(c,u);return tw(c,ue(u,function(y){return Bi(y,f)?+y:y}).sort(uw)),C});function iJ(c,u){var f=[];if(!(c&&c.length))return f;var C=-1,y=[],I=c.length;for(u=vt(u,3);++C<I;){var O=c[C];u(O,C,c)&&(f.push(O),y.push(C))}return tw(c,y),f}function S5(c){return c==null?c:Z.call(c)}function sJ(c,u,f){var C=c==null?0:c.length;return C?(f&&typeof f!="number"&&Bn(c,u,f)?(u=0,f=C):(u=u==null?0:Rt(u),f=f===e?C:Rt(f)),ko(c,u,f)):[]}function lJ(c,u){return q1(c,u)}function cJ(c,u,f){return f5(c,u,vt(f,2))}function aJ(c,u){var f=c==null?0:c.length;if(f){var C=q1(c,u);if(C<f&&tr(c[C],u))return C}return-1}function uJ(c,u){return q1(c,u,!0)}function dJ(c,u,f){return f5(c,u,vt(f,2),!0)}function hJ(c,u){var f=c==null?0:c.length;if(f){var C=q1(c,u,!0)-1;if(tr(c[C],u))return C}return-1}function fJ(c){return c&&c.length?nw(c):[]}function mJ(c,u){return c&&c.length?nw(c,vt(u,2)):[]}function gJ(c){var u=c==null?0:c.length;return u?ko(c,1,u):[]}function pJ(c,u,f){return c&&c.length?(u=f||u===e?1:Rt(u),ko(c,0,u<0?0:u)):[]}function CJ(c,u,f){var C=c==null?0:c.length;return C?(u=f||u===e?1:Rt(u),u=C-u,ko(c,u<0?0:u,C)):[]}function AJ(c,u){return c&&c.length?G1(c,vt(u,3),!1,!0):[]}function bJ(c,u){return c&&c.length?G1(c,vt(u,3)):[]}var vJ=_t(function(c){return fs(nn(c,1,De,!0))}),yJ=_t(function(c){var u=wo(c);return De(u)&&(u=e),fs(nn(c,1,De,!0),vt(u,2))}),kJ=_t(function(c){var u=wo(c);return u=typeof u=="function"?u:e,fs(nn(c,1,De,!0),e,u)});function wJ(c){return c&&c.length?fs(c):[]}function BJ(c,u){return c&&c.length?fs(c,vt(u,2)):[]}function EJ(c,u){return u=typeof u=="function"?u:e,c&&c.length?fs(c,e,u):[]}function L5(c){if(!(c&&c.length))return[];var u=0;return c=Qo(c,function(f){if(De(f))return u=T(f.length,u),!0}),Zc(u,function(f){return ue(c,qc(f))})}function Uw(c,u){if(!(c&&c.length))return[];var f=L5(c);return u==null?f:ue(f,function(C){return yn(u,e,C)})}var xJ=_t(function(c,u){return De(c)?Id(c,u):[]}),IJ=_t(function(c){return g5(Qo(c,De))}),TJ=_t(function(c){var u=wo(c);return De(u)&&(u=e),g5(Qo(c,De),vt(u,2))}),DJ=_t(function(c){var u=wo(c);return u=typeof u=="function"?u:e,g5(Qo(c,De),e,u)}),SJ=_t(L5);function LJ(c,u){return sw(c||[],u||[],xd)}function MJ(c,u){return sw(c||[],u||[],Sd)}var RJ=_t(function(c){var u=c.length,f=u>1?c[u-1]:e;return f=typeof f=="function"?(c.pop(),f):e,Uw(c,f)});function zw(c){var u=E(c);return u.__chain__=!0,u}function OJ(c,u){return u(c),c}function nm(c,u){return u(c)}var _J=wi(function(c){var u=c.length,f=u?c[0]:0,C=this.__wrapped__,y=function(I){return n5(I,c)};return u>1||this.__actions__.length||!(C instanceof Pt)||!Bi(f)?this.thru(y):(C=C.slice(f,+f+(u?1:0)),C.__actions__.push({func:nm,args:[y],thisArg:e}),new Pn(C,this.__chain__).thru(function(I){return u&&!I.length&&I.push(e),I}))});function FJ(){return zw(this)}function PJ(){return new Pn(this.value(),this.__chain__)}function NJ(){this.__values__===e&&(this.__values__=oB(this.value()));var c=this.__index__>=this.__values__.length,u=c?e:this.__values__[this.__index__++];return{done:c,value:u}}function $J(){return this}function HJ(c){for(var u,f=this;f instanceof ds;){var C=Fw(f);C.__index__=0,C.__values__=e,u?y.__wrapped__=C:u=C;var y=C;f=f.__wrapped__}return y.__wrapped__=c,u}function jJ(){var c=this.__wrapped__;if(c instanceof Pt){var u=c;return this.__actions__.length&&(u=new Pt(this)),u=u.reverse(),u.__actions__.push({func:nm,args:[S5],thisArg:e}),new Pn(u,this.__chain__)}return this.thru(S5)}function UJ(){return iw(this.__wrapped__,this.__actions__)}var zJ=Z1(function(c,u,f){Wt.call(c,f)?++c[f]:yi(c,f,1)});function VJ(c,u,f){var C=St(c)?E1:OQ;return f&&Bn(c,u,f)&&(u=e),C(c,vt(u,3))}function WJ(c,u){var f=St(c)?Qo:Uk;return f(c,vt(u,3))}var qJ=pw(Pw),GJ=pw(Nw);function ZJ(c,u){return nn(om(c,u),1)}function QJ(c,u){return nn(om(c,u),vn)}function YJ(c,u,f){return f=f===e?1:Rt(f),nn(om(c,u),f)}function Vw(c,u){var f=St(c)?_n:hs;return f(c,vt(u,3))}function Ww(c,u){var f=St(c)?Q3:jk;return f(c,vt(u,3))}var JJ=Z1(function(c,u,f){Wt.call(c,f)?c[f].push(u):yi(c,f,[u])});function KJ(c,u,f,C){c=$n(c)?c:la(c),f=f&&!C?Rt(f):0;var y=c.length;return f<0&&(f=T(y+f,0)),cm(c)?f<=y&&c.indexOf(u,f)>-1:!!y&&ci(c,u,f)>-1}var XJ=_t(function(c,u,f){var C=-1,y=typeof u=="function",I=$n(c)?V(c.length):[];return hs(c,function(O){I[++C]=y?yn(u,O,f):Td(O,u,f)}),I}),tK=Z1(function(c,u,f){yi(c,f,u)});function om(c,u){var f=St(c)?ue:Zk;return f(c,vt(u,3))}function eK(c,u,f,C){return c==null?[]:(St(u)||(u=u==null?[]:[u]),f=C?e:f,St(f)||(f=f==null?[]:[f]),Kk(c,u,f))}var nK=Z1(function(c,u,f){c[f?0:1].push(u)},function(){return[[],[]]});function oK(c,u,f){var C=St(c)?md:gl,y=arguments.length<3;return C(c,vt(u,4),f,y,hs)}function rK(c,u,f){var C=St(c)?Y3:gl,y=arguments.length<3;return C(c,vt(u,4),f,y,jk)}function iK(c,u){var f=St(c)?Qo:Uk;return f(c,sm(vt(u,3)))}function sK(c){var u=St(c)?Pk:KQ;return u(c)}function lK(c,u,f){(f?Bn(c,u,f):u===e)?u=1:u=Rt(u);var C=St(c)?DQ:XQ;return C(c,u)}function cK(c){var u=St(c)?SQ:eY;return u(c)}function aK(c){if(c==null)return 0;if($n(c))return cm(c)?us(c):c.length;var u=hn(c);return u==un||u==be?c.size:c5(c).length}function uK(c,u,f){var C=St(c)?gd:nY;return f&&Bn(c,u,f)&&(u=e),C(c,vt(u,3))}var dK=_t(function(c,u){if(c==null)return[];var f=u.length;return f>1&&Bn(c,u[0],u[1])?u=[]:f>2&&Bn(u[0],u[1],u[2])&&(u=[u[0]]),Kk(c,nn(u,1),[])}),rm=$1||function(){return Ge.Date.now()};function hK(c,u){if(typeof u!="function")throw new kn(s);return c=Rt(c),function(){if(--c<1)return u.apply(this,arguments)}}function qw(c,u,f){return u=f?e:u,u=c&&u==null?c.length:u,ki(c,ft,e,e,e,e,u)}function Gw(c,u){var f;if(typeof u!="function")throw new kn(s);return c=Rt(c),function(){return--c>0&&(f=u.apply(this,arguments)),c<=1&&(u=e),f}}var M5=_t(function(c,u,f){var C=x;if(f.length){var y=Kn(f,ia(M5));C|=q}return ki(c,C,u,f,y)}),Zw=_t(function(c,u,f){var C=x|_;if(f.length){var y=Kn(f,ia(Zw));C|=q}return ki(u,C,c,f,y)});function Qw(c,u,f){u=f?e:u;var C=ki(c,H,e,e,e,e,e,u);return C.placeholder=Qw.placeholder,C}function Yw(c,u,f){u=f?e:u;var C=ki(c,z,e,e,e,e,e,u);return C.placeholder=Yw.placeholder,C}function Jw(c,u,f){var C,y,I,O,P,$,Q=0,Y=!1,X=!1,dt=!0;if(typeof c!="function")throw new kn(s);u=Bo(u)||0,ve(f)&&(Y=!!f.leading,X="maxWait"in f,I=X?T(Bo(f.maxWait)||0,u):I,dt="trailing"in f?!!f.trailing:dt);function Ct(Se){var er=C,Ii=y;return C=y=e,Q=Se,O=c.apply(Ii,er),O}function yt(Se){return Q=Se,P=Rd($t,u),Y?Ct(Se):O}function Ot(Se){var er=Se-$,Ii=Se-Q,pB=u-er;return X?L(pB,I-Ii):pB}function kt(Se){var er=Se-$,Ii=Se-Q;return $===e||er>=u||er<0||X&&Ii>=I}function $t(){var Se=rm();if(kt(Se))return zt(Se);P=Rd($t,Ot(Se))}function zt(Se){return P=e,dt&&C?Ct(Se):(C=y=e,O)}function no(){P!==e&&lw(P),Q=0,C=$=y=P=e}function En(){return P===e?O:zt(rm())}function oo(){var Se=rm(),er=kt(Se);if(C=arguments,y=this,$=Se,er){if(P===e)return yt($);if(X)return lw(P),P=Rd($t,u),Ct($)}return P===e&&(P=Rd($t,u)),O}return oo.cancel=no,oo.flush=En,oo}var fK=_t(function(c,u){return Hk(c,1,u)}),mK=_t(function(c,u,f){return Hk(c,Bo(u)||0,f)});function gK(c){return ki(c,jt)}function im(c,u){if(typeof c!="function"||u!=null&&typeof u!="function")throw new kn(s);var f=function(){var C=arguments,y=u?u.apply(this,C):C[0],I=f.cache;if(I.has(y))return I.get(y);var O=c.apply(this,C);return f.cache=I.set(y,O)||I,O};return f.cache=new(im.Cache||vi),f}im.Cache=vi;function sm(c){if(typeof c!="function")throw new kn(s);return function(){var u=arguments;switch(u.length){case 0:return!c.call(this);case 1:return!c.call(this,u[0]);case 2:return!c.call(this,u[0],u[1]);case 3:return!c.call(this,u[0],u[1],u[2])}return!c.apply(this,u)}}function pK(c){return Gw(2,c)}var CK=oY(function(c,u){u=u.length==1&&St(u[0])?ue(u[0],dn(vt())):ue(nn(u,1),dn(vt()));var f=u.length;return _t(function(C){for(var y=-1,I=L(C.length,f);++y<I;)C[y]=u[y].call(this,C[y]);return yn(c,this,C)})}),R5=_t(function(c,u){var f=Kn(u,ia(R5));return ki(c,q,e,u,f)}),Kw=_t(function(c,u){var f=Kn(u,ia(Kw));return ki(c,rt,e,u,f)}),AK=wi(function(c,u){return ki(c,Bt,e,e,e,u)});function bK(c,u){if(typeof c!="function")throw new kn(s);return u=u===e?u:Rt(u),_t(c,u)}function vK(c,u){if(typeof c!="function")throw new kn(s);return u=u==null?0:T(Rt(u),0),_t(function(f){var C=f[u],y=gs(f,0,u);return C&&Tr(y,C),yn(c,this,y)})}function yK(c,u,f){var C=!0,y=!0;if(typeof c!="function")throw new kn(s);return ve(f)&&(C="leading"in f?!!f.leading:C,y="trailing"in f?!!f.trailing:y),Jw(c,u,{leading:C,maxWait:u,trailing:y})}function kK(c){return qw(c,1)}function wK(c,u){return R5(C5(u),c)}function BK(){if(!arguments.length)return[];var c=arguments[0];return St(c)?c:[c]}function EK(c){return yo(c,v)}function xK(c,u){return u=typeof u=="function"?u:e,yo(c,v,u)}function IK(c){return yo(c,p|v)}function TK(c,u){return u=typeof u=="function"?u:e,yo(c,p|v,u)}function DK(c,u){return u==null||$k(c,u,Ke(u))}function tr(c,u){return c===u||c!==c&&u!==u}var SK=K1(i5),LK=K1(function(c,u){return c>=u}),Nl=Wk(function(){return arguments}())?Wk:function(c){return Be(c)&&Wt.call(c,"callee")&&!Bd.call(c,"callee")},St=V.isArray,MK=cd?dn(cd):HQ;function $n(c){return c!=null&&lm(c.length)&&!Ei(c)}function De(c){return Be(c)&&$n(c)}function RK(c){return c===!0||c===!1||Be(c)&&wn(c)==ri}var ps=j1||V5,OK=ad?dn(ad):jQ;function _K(c){return Be(c)&&c.nodeType===1&&!Od(c)}function FK(c){if(c==null)return!0;if($n(c)&&(St(c)||typeof c=="string"||typeof c.splice=="function"||ps(c)||sa(c)||Nl(c)))return!c.length;var u=hn(c);if(u==un||u==be)return!c.size;if(Md(c))return!c5(c).length;for(var f in c)if(Wt.call(c,f))return!1;return!0}function PK(c,u){return Dd(c,u)}function NK(c,u,f){f=typeof f=="function"?f:e;var C=f?f(c,u):e;return C===e?Dd(c,u,e,f):!!C}function O5(c){if(!Be(c))return!1;var u=wn(c);return u==os||u==Er||typeof c.message=="string"&&typeof c.name=="string"&&!Od(c)}function $K(c){return typeof c=="number"&&Ed(c)}function Ei(c){if(!ve(c))return!1;var u=wn(c);return u==Fc||u==s1||u==ol||u==n3}function Xw(c){return typeof c=="number"&&c==Rt(c)}function lm(c){return typeof c=="number"&&c>-1&&c%1==0&&c<=an}function ve(c){var u=typeof c;return c!=null&&(u=="object"||u=="function")}function Be(c){return c!=null&&typeof c=="object"}var tB=ud?dn(ud):zQ;function HK(c,u){return c===u||l5(c,u,B5(u))}function jK(c,u,f){return f=typeof f=="function"?f:e,l5(c,u,B5(u),f)}function UK(c){return eB(c)&&c!=+c}function zK(c){if(xY(c))throw new Et(i);return qk(c)}function VK(c){return c===null}function WK(c){return c==null}function eB(c){return typeof c=="number"||Be(c)&&wn(c)==rl}function Od(c){if(!Be(c)||wn(c)!=Co)return!1;var u=Dr(c);if(u===null)return!0;var f=Wt.call(u,"constructor")&&u.constructor;return typeof f=="function"&&f instanceof f&&gi.call(f)==wd}var _5=B1?dn(B1):VQ;function qK(c){return Xw(c)&&c>=-an&&c<=an}var nB=dd?dn(dd):WQ;function cm(c){return typeof c=="string"||!St(c)&&Be(c)&&wn(c)==sl}function eo(c){return typeof c=="symbol"||Be(c)&&wn(c)==ll}var sa=hd?dn(hd):qQ;function GK(c){return c===e}function ZK(c){return Be(c)&&hn(c)==cl}function QK(c){return Be(c)&&wn(c)==u1}var YK=K1(a5),JK=K1(function(c,u){return c<=u});function oB(c){if(!c)return[];if($n(c))return cm(c)?Xn(c):Nn(c);if(Tl&&c[Tl])return Al(c[Tl]());var u=hn(c),f=u==un?di:u==be?hi:la;return f(c)}function xi(c){if(!c)return c===0?c:0;if(c=Bo(c),c===vn||c===-vn){var u=c<0?-1:1;return u*Br}return c===c?c:0}function Rt(c){var u=xi(c),f=u%1;return u===u?f?u-f:u:0}function rB(c){return c?Ol(Rt(c),0,po):0}function Bo(c){if(typeof c=="number")return c;if(eo(c))return oi;if(ve(c)){var u=typeof c.valueOf=="function"?c.valueOf():c;c=ve(u)?u+"":u}if(typeof c!="string")return c===0?c:+c;c=ai(c);var f=p1.test(c);return f||v3.test(c)?q3(c.slice(2),f?2:8):g1.test(c)?oi:+c}function iB(c){return Mr(c,Hn(c))}function KK(c){return c?Ol(Rt(c),-an,an):c===0?c:0}function Kt(c){return c==null?"":to(c)}var XK=oa(function(c,u){if(Md(u)||$n(u)){Mr(u,Ke(u),c);return}for(var f in u)Wt.call(u,f)&&xd(c,f,u[f])}),sB=oa(function(c,u){Mr(u,Hn(u),c)}),am=oa(function(c,u,f,C){Mr(u,Hn(u),c,C)}),tX=oa(function(c,u,f,C){Mr(u,Ke(u),c,C)}),eX=wi(n5);function nX(c,u){var f=Sr(c);return u==null?f:Nk(f,u)}var oX=_t(function(c,u){c=qt(c);var f=-1,C=u.length,y=C>2?u[2]:e;for(y&&Bn(u[0],u[1],y)&&(C=1);++f<C;)for(var I=u[f],O=Hn(I),P=-1,$=O.length;++P<$;){var Q=O[P],Y=c[Q];(Y===e||tr(Y,mi[Q])&&!Wt.call(c,Q))&&(c[Q]=I[Q])}return c}),rX=_t(function(c){return c.push(e,ww),yn(lB,e,c)});function iX(c,u){return pd(c,vt(u,3),Lr)}function sX(c,u){return pd(c,vt(u,3),r5)}function lX(c,u){return c==null?c:o5(c,vt(u,3),Hn)}function cX(c,u){return c==null?c:zk(c,vt(u,3),Hn)}function aX(c,u){return c&&Lr(c,vt(u,3))}function uX(c,u){return c&&r5(c,vt(u,3))}function dX(c){return c==null?[]:V1(c,Ke(c))}function hX(c){return c==null?[]:V1(c,Hn(c))}function F5(c,u,f){var C=c==null?e:_l(c,u);return C===e?f:C}function fX(c,u){return c!=null&&xw(c,u,FQ)}function P5(c,u){return c!=null&&xw(c,u,PQ)}var mX=Aw(function(c,u,f){u!=null&&typeof u.toString!="function"&&(u=wl.call(u)),c[u]=f},$5(jn)),gX=Aw(function(c,u,f){u!=null&&typeof u.toString!="function"&&(u=wl.call(u)),Wt.call(c,u)?c[u].push(f):c[u]=[f]},vt),pX=_t(Td);function Ke(c){return $n(c)?Fk(c):c5(c)}function Hn(c){return $n(c)?Fk(c,!0):GQ(c)}function CX(c,u){var f={};return u=vt(u,3),Lr(c,function(C,y,I){yi(f,u(C,y,I),C)}),f}function AX(c,u){var f={};return u=vt(u,3),Lr(c,function(C,y,I){yi(f,y,u(C,y,I))}),f}var bX=oa(function(c,u,f){W1(c,u,f)}),lB=oa(function(c,u,f,C){W1(c,u,f,C)}),vX=wi(function(c,u){var f={};if(c==null)return f;var C=!1;u=ue(u,function(I){return I=ms(I,c),C||(C=I.length>1),I}),Mr(c,k5(c),f),C&&(f=yo(f,p|A|v,mY));for(var y=u.length;y--;)m5(f,u[y]);return f});function yX(c,u){return cB(c,sm(vt(u)))}var kX=wi(function(c,u){return c==null?{}:QQ(c,u)});function cB(c,u){if(c==null)return{};var f=ue(k5(c),function(C){return[C]});return u=vt(u),Xk(c,f,function(C,y){return u(C,y[0])})}function wX(c,u,f){u=ms(u,c);var C=-1,y=u.length;for(y||(y=1,c=e);++C<y;){var I=c==null?e:c[Rr(u[C])];I===e&&(C=y,I=f),c=Ei(I)?I.call(c):I}return c}function BX(c,u,f){return c==null?c:Sd(c,u,f)}function EX(c,u,f,C){return C=typeof C=="function"?C:e,c==null?c:Sd(c,u,f,C)}var aB=yw(Ke),uB=yw(Hn);function xX(c,u,f){var C=St(c),y=C||ps(c)||sa(c);if(u=vt(u,4),f==null){var I=c&&c.constructor;y?f=C?new I:[]:ve(c)?f=Ei(I)?Sr(Dr(c)):{}:f={}}return(y?_n:Lr)(c,function(O,P,$){return u(f,O,P,$)}),f}function IX(c,u){return c==null?!0:m5(c,u)}function TX(c,u,f){return c==null?c:rw(c,u,C5(f))}function DX(c,u,f,C){return C=typeof C=="function"?C:e,c==null?c:rw(c,u,C5(f),C)}function la(c){return c==null?[]:as(c,Ke(c))}function SX(c){return c==null?[]:as(c,Hn(c))}function LX(c,u,f){return f===e&&(f=u,u=e),f!==e&&(f=Bo(f),f=f===f?f:0),u!==e&&(u=Bo(u),u=u===u?u:0),Ol(Bo(c),u,f)}function MX(c,u,f){return u=xi(u),f===e?(f=u,u=0):f=xi(f),c=Bo(c),NQ(c,u,f)}function RX(c,u,f){if(f&&typeof f!="boolean"&&Bn(c,u,f)&&(u=f=e),f===e&&(typeof u=="boolean"?(f=u,u=e):typeof c=="boolean"&&(f=c,c=e)),c===e&&u===e?(c=0,u=1):(c=xi(c),u===e?(u=c,c=0):u=xi(u)),c>u){var C=c;c=u,u=C}if(f||c%1||u%1){var y=j();return L(c+y*(u-c+k1("1e-"+((y+"").length-1))),u)}return d5(c,u)}var OX=ra(function(c,u,f){return u=u.toLowerCase(),c+(f?dB(u):u)});function dB(c){return N5(Kt(c).toLowerCase())}function hB(c){return c=Kt(c),c&&c.replace(k3,D1).replace(F3,"")}function _X(c,u,f){c=Kt(c),u=to(u);var C=c.length;f=f===e?C:Ol(Rt(f),0,C);var y=f;return f-=u.length,f>=0&&c.slice(f,y)==u}function FX(c){return c=Kt(c),c&&l3.test(c)?c.replace(h1,bd):c}function PX(c){return c=Kt(c),c&&f3.test(c)?c.replace(Yu,"\\$&"):c}var NX=ra(function(c,u,f){return c+(f?"-":"")+u.toLowerCase()}),$X=ra(function(c,u,f){return c+(f?" ":"")+u.toLowerCase()}),HX=gw("toLowerCase");function jX(c,u,f){c=Kt(c),u=Rt(u);var C=u?us(c):0;if(!u||C>=u)return c;var y=(u-C)/2;return J1(Sl(y),f)+c+J1(Dl(y),f)}function UX(c,u,f){c=Kt(c),u=Rt(u);var C=u?us(c):0;return u&&C<u?c+J1(u-C,f):c}function zX(c,u,f){c=Kt(c),u=Rt(u);var C=u?us(c):0;return u&&C<u?J1(u-C,f)+c:c}function VX(c,u,f){return f||u==null?u=0:u&&(u=+u),U(Kt(c).replace(Ju,""),u||0)}function WX(c,u,f){return(f?Bn(c,u,f):u===e)?u=1:u=Rt(u),h5(Kt(c),u)}function qX(){var c=arguments,u=Kt(c[0]);return c.length<3?u:u.replace(c[1],c[2])}var GX=ra(function(c,u,f){return c+(f?"_":"")+u.toLowerCase()});function ZX(c,u,f){return f&&typeof f!="number"&&Bn(c,u,f)&&(u=f=e),f=f===e?po:f>>>0,f?(c=Kt(c),c&&(typeof u=="string"||u!=null&&!_5(u))&&(u=to(u),!u&&ui(c))?gs(Xn(c),0,f):c.split(u,f)):[]}var QX=ra(function(c,u,f){return c+(f?" ":"")+N5(u)});function YX(c,u,f){return c=Kt(c),f=f==null?0:Ol(Rt(f),0,c.length),u=to(u),c.slice(f,f+u.length)==u}function JX(c,u,f){var C=E.templateSettings;f&&Bn(c,u,f)&&(u=e),c=Kt(c),u=am({},u,C,kw);var y=am({},u.imports,C.imports,kw),I=Ke(y),O=as(y,I),P,$,Q=0,Y=u.interpolate||Nc,X="__p += '",dt=na((u.escape||Nc).source+"|"+Y.source+"|"+(Y===f1?A3:Nc).source+"|"+(u.evaluate||Nc).source+"|$","g"),Ct="//# sourceURL="+(Wt.call(u,"sourceURL")?(u.sourceURL+"").replace(/\s/g," "):"lodash.templateSources["+ ++j3+"]")+`
|
|
731
731
|
`;c.replace(dt,function(kt,$t,zt,no,En,oo){return zt||(zt=no),X+=c.slice(Q,oo).replace(w3,S1),$t&&(P=!0,X+=`' +
|
|
732
732
|
__e(`+$t+`) +
|
|
733
733
|
'`),En&&($=!0,X+=`';
|
|
@@ -744,10 +744,10 @@ __p += '`),zt&&(X+=`' +
|
|
|
744
744
|
function print() { __p += __j.call(arguments, '') }
|
|
745
745
|
`:`;
|
|
746
746
|
`)+X+`return __p
|
|
747
|
-
}`;var Ot=mB(function(){return Vt(I,Ct+"return "+X).apply(e,O)});if(Ot.source=X,O5(Ot))throw Ot;return Ot}function KX(c){return Kt(c).toLowerCase()}function XX(c){return Kt(c).toUpperCase()}function ttt(c,u,f){if(c=Kt(c),c&&(f||u===e))return ai(c);if(!c||!(u=to(u)))return c;var C=Xn(c),y=Xn(u),I=Cl(C,y),O=Ad(C,y)+1;return gs(C,I,O).join("")}function ett(c,u,f){if(c=Kt(c),c&&(f||u===e))return c.slice(0,Kc(c)+1);if(!c||!(u=to(u)))return c;var C=Xn(c),y=Ad(C,Xn(u))+1;return gs(C,0,y).join("")}function ntt(c,u,f){if(c=Kt(c),c&&(f||u===e))return c.replace(Ju,"");if(!c||!(u=to(u)))return c;var C=Xn(c),y=Cl(C,Xn(u));return gs(C,y).join("")}function ott(c,u){var f=Ut,C=ne;if(ve(u)){var y="separator"in u?u.separator:y;f="length"in u?Rt(u.length):f,C="omission"in u?to(u.omission):C}c=Kt(c);var I=c.length;if(ui(c)){var O=Xn(c);I=O.length}if(f>=I)return c;var P=f-us(C);if(P<1)return C;var $=O?gs(O,0,P).join(""):c.slice(0,P);if(y===e)return $+C;if(O&&(P+=$.length-P),_5(y)){if(c.slice(P).search(y)){var Q,Y=$;for(y.global||(y=na(y.source,Kt(Pc.exec(y))+"g")),y.lastIndex=0;Q=y.exec(Y);)var X=Q.index;$=$.slice(0,X===e?P:X)}}else if(c.indexOf(to(y),P)!=P){var dt=$.lastIndexOf(y);dt>-1&&($=$.slice(0,dt))}return $+C}function rtt(c){return c=Kt(c),c&&s3.test(c)?c.replace(d1,Xc):c}var itt=ra(function(c,u,f){return c+(f?" ":"")+u.toUpperCase()}),N5=gw("toUpperCase");function fB(c,u,f){return c=Kt(c),u=f?e:u,u===e?Qc(c)?R1(c):Jn(c):c.match(u)||[]}var mB=_t(function(c,u){try{return yn(c,e,u)}catch(f){return O5(f)?f:new Et(f)}}),stt=wi(function(c,u){return _n(u,function(f){f=Mr(f),yi(c,f,M5(c[f],c))}),c});function ltt(c){var u=c==null?0:c.length,f=vt();return c=u?ue(c,function(C){if(typeof C[1]!="function")throw new kn(s);return[f(C[0]),C[1]]}):[],_t(function(C){for(var y=-1;++y<u;){var I=c[y];if(yn(I[0],this,C))return yn(I[1],this,C)}})}function ctt(c){return RQ(yo(c,p))}function $5(c){return function(){return c}}function att(c,u){return c==null||c!==c?u:c}var utt=Cw(),dtt=Cw(!0);function jn(c){return c}function H5(c){return Gk(typeof c=="function"?c:yo(c,p))}function htt(c){return Qk(yo(c,p))}function ftt(c,u){return Yk(c,yo(u,p))}var mtt=_t(function(c,u){return function(f){return Td(f,c,u)}}),gtt=_t(function(c,u){return function(f){return Td(c,f,u)}});function j5(c,u,f){var C=Ke(u),y=V1(u,C);f==null&&!(ve(u)&&(y.length||!C.length))&&(f=u,u=c,c=this,y=V1(u,Ke(u)));var I=!(ve(f)&&"chain"in f)||!!f.chain,O=Ei(c);return _n(y,function(P){var $=u[P];c[P]=$,O&&(c.prototype[P]=function(){var Q=this.__chain__;if(I||Q){var Y=c(this.__wrapped__),X=Y.__actions__=Nn(this.__actions__);return X.push({func:$,args:arguments,thisArg:c}),Y.__chain__=Q,Y}return $.apply(c,Ir([this.value()],arguments))})}),c}function ptt(){return Ge._===this&&(Ge._=_1),this}function U5(){}function Ctt(c){return c=Rt(c),_t(function(u){return Jk(u,c)})}var Att=b5(ue),btt=b5(E1),vtt=b5(gd);function gB(c){return x5(c)?qc(Mr(c)):YQ(c)}function ytt(c){return function(u){return c==null?e:_l(c,u)}}var ktt=bw(),wtt=bw(!0);function z5(){return[]}function V5(){return!1}function Btt(){return{}}function Ett(){return""}function xtt(){return!0}function Itt(c,u){if(c=Rt(c),c<1||c>an)return[];var f=po,C=L(c,po);u=vt(u),c-=po;for(var y=Zc(C,u);++f<c;)u(f);return y}function Ttt(c){return St(c)?ue(c,Mr):eo(c)?[c]:Nn(_w(Kt(c)))}function Dtt(c){var u=++O1;return Kt(c)+u}var Stt=Y1(function(c,u){return c+u},0),Ltt=v5("ceil"),Mtt=Y1(function(c,u){return c/u},1),Rtt=v5("floor");function Ott(c){return c&&c.length?z1(c,jn,i5):e}function _tt(c,u){return c&&c.length?z1(c,vt(u,2),i5):e}function Ftt(c){return Wc(c,jn)}function Ptt(c,u){return Wc(c,vt(u,2))}function Ntt(c){return c&&c.length?z1(c,jn,a5):e}function $tt(c,u){return c&&c.length?z1(c,vt(u,2),a5):e}var Htt=Y1(function(c,u){return c*u},1),jtt=v5("round"),Utt=Y1(function(c,u){return c-u},0);function ztt(c){return c&&c.length?Gc(c,jn):0}function Vtt(c,u){return c&&c.length?Gc(c,vt(u,2)):0}return E.after=hK,E.ary=qw,E.assign=XK,E.assignIn=sB,E.assignInWith=am,E.assignWith=tX,E.at=eX,E.before=Gw,E.bind=M5,E.bindAll=stt,E.bindKey=Zw,E.castArray=BK,E.chain=zw,E.chunk=RY,E.compact=OY,E.concat=_Y,E.cond=ltt,E.conforms=ctt,E.constant=$5,E.countBy=zJ,E.create=nX,E.curry=Qw,E.curryRight=Yw,E.debounce=Jw,E.defaults=oX,E.defaultsDeep=rX,E.defer=fK,E.delay=mK,E.difference=FY,E.differenceBy=PY,E.differenceWith=NY,E.drop=$Y,E.dropRight=HY,E.dropRightWhile=jY,E.dropWhile=UY,E.fill=zY,E.filter=WJ,E.flatMap=ZJ,E.flatMapDeep=QJ,E.flatMapDepth=YJ,E.flatten=$w,E.flattenDeep=VY,E.flattenDepth=WY,E.flip=gK,E.flow=utt,E.flowRight=dtt,E.fromPairs=qY,E.functions=dX,E.functionsIn=hX,E.groupBy=JJ,E.initial=ZY,E.intersection=QY,E.intersectionBy=YY,E.intersectionWith=JY,E.invert=mX,E.invertBy=gX,E.invokeMap=XJ,E.iteratee=H5,E.keyBy=tK,E.keys=Ke,E.keysIn=Hn,E.map=om,E.mapKeys=CX,E.mapValues=AX,E.matches=htt,E.matchesProperty=ftt,E.memoize=im,E.merge=bX,E.mergeWith=lB,E.method=mtt,E.methodOf=gtt,E.mixin=j5,E.negate=sm,E.nthArg=Ctt,E.omit=vX,E.omitBy=yX,E.once=pK,E.orderBy=eK,E.over=Att,E.overArgs=CK,E.overEvery=btt,E.overSome=vtt,E.partial=R5,E.partialRight=Kw,E.partition=nK,E.pick=kX,E.pickBy=cB,E.property=gB,E.propertyOf=ytt,E.pull=eJ,E.pullAll=jw,E.pullAllBy=nJ,E.pullAllWith=oJ,E.pullAt=rJ,E.range=ktt,E.rangeRight=wtt,E.rearg=AK,E.reject=iK,E.remove=iJ,E.rest=bK,E.reverse=S5,E.sampleSize=lK,E.set=BX,E.setWith=EX,E.shuffle=cK,E.slice=sJ,E.sortBy=dK,E.sortedUniq=fJ,E.sortedUniqBy=mJ,E.split=ZX,E.spread=vK,E.tail=gJ,E.take=pJ,E.takeRight=CJ,E.takeRightWhile=AJ,E.takeWhile=bJ,E.tap=OJ,E.throttle=yK,E.thru=nm,E.toArray=oB,E.toPairs=aB,E.toPairsIn=uB,E.toPath=Ttt,E.toPlainObject=iB,E.transform=xX,E.unary=kK,E.union=vJ,E.unionBy=yJ,E.unionWith=kJ,E.uniq=wJ,E.uniqBy=BJ,E.uniqWith=EJ,E.unset=IX,E.unzip=L5,E.unzipWith=Uw,E.update=TX,E.updateWith=DX,E.values=la,E.valuesIn=SX,E.without=xJ,E.words=fB,E.wrap=wK,E.xor=IJ,E.xorBy=TJ,E.xorWith=DJ,E.zip=SJ,E.zipObject=LJ,E.zipObjectDeep=MJ,E.zipWith=RJ,E.entries=aB,E.entriesIn=uB,E.extend=sB,E.extendWith=am,j5(E,E),E.add=Stt,E.attempt=mB,E.camelCase=OX,E.capitalize=dB,E.ceil=Ltt,E.clamp=LX,E.clone=EK,E.cloneDeep=IK,E.cloneDeepWith=TK,E.cloneWith=xK,E.conformsTo=DK,E.deburr=hB,E.defaultTo=att,E.divide=Mtt,E.endsWith=_X,E.eq=tr,E.escape=FX,E.escapeRegExp=PX,E.every=VJ,E.find=qJ,E.findIndex=Pw,E.findKey=iX,E.findLast=GJ,E.findLastIndex=Nw,E.findLastKey=sX,E.floor=Rtt,E.forEach=Vw,E.forEachRight=Ww,E.forIn=lX,E.forInRight=cX,E.forOwn=aX,E.forOwnRight=uX,E.get=F5,E.gt=SK,E.gte=LK,E.has=fX,E.hasIn=P5,E.head=Hw,E.identity=jn,E.includes=KJ,E.indexOf=GY,E.inRange=MX,E.invoke=pX,E.isArguments=Nl,E.isArray=St,E.isArrayBuffer=MK,E.isArrayLike=$n,E.isArrayLikeObject=De,E.isBoolean=RK,E.isBuffer=ps,E.isDate=OK,E.isElement=_K,E.isEmpty=FK,E.isEqual=PK,E.isEqualWith=NK,E.isError=O5,E.isFinite=$K,E.isFunction=Ei,E.isInteger=Xw,E.isLength=lm,E.isMap=tB,E.isMatch=HK,E.isMatchWith=jK,E.isNaN=UK,E.isNative=zK,E.isNil=WK,E.isNull=VK,E.isNumber=eB,E.isObject=ve,E.isObjectLike=Be,E.isPlainObject=Od,E.isRegExp=_5,E.isSafeInteger=qK,E.isSet=nB,E.isString=cm,E.isSymbol=eo,E.isTypedArray=sa,E.isUndefined=GK,E.isWeakMap=ZK,E.isWeakSet=QK,E.join=KY,E.kebabCase=NX,E.last=wo,E.lastIndexOf=XY,E.lowerCase=$X,E.lowerFirst=HX,E.lt=YK,E.lte=JK,E.max=Ott,E.maxBy=_tt,E.mean=Ftt,E.meanBy=Ptt,E.min=Ntt,E.minBy=$tt,E.stubArray=z5,E.stubFalse=V5,E.stubObject=Btt,E.stubString=Ett,E.stubTrue=xtt,E.multiply=Htt,E.nth=tJ,E.noConflict=ptt,E.noop=U5,E.now=rm,E.pad=jX,E.padEnd=UX,E.padStart=zX,E.parseInt=VX,E.random=RX,E.reduce=oK,E.reduceRight=rK,E.repeat=WX,E.replace=qX,E.result=wX,E.round=jtt,E.runInContext=N,E.sample=sK,E.size=aK,E.snakeCase=GX,E.some=uK,E.sortedIndex=lJ,E.sortedIndexBy=cJ,E.sortedIndexOf=aJ,E.sortedLastIndex=uJ,E.sortedLastIndexBy=dJ,E.sortedLastIndexOf=hJ,E.startCase=QX,E.startsWith=YX,E.subtract=Utt,E.sum=ztt,E.sumBy=Vtt,E.template=JX,E.times=Itt,E.toFinite=xi,E.toInteger=Rt,E.toLength=rB,E.toLower=KX,E.toNumber=Bo,E.toSafeInteger=KK,E.toString=Kt,E.toUpper=XX,E.trim=ttt,E.trimEnd=ett,E.trimStart=ntt,E.truncate=ott,E.unescape=rtt,E.uniqueId=Dtt,E.upperCase=itt,E.upperFirst=N5,E.each=Vw,E.eachRight=Ww,E.first=Hw,j5(E,function(){var c={};return Sr(E,function(u,f){Wt.call(E.prototype,f)||(c[f]=u)}),c}(),{chain:!1}),E.VERSION=o,_n(["bind","bindKey","curry","curryRight","partial","partialRight"],function(c){E[c].placeholder=E}),_n(["drop","take"],function(c,u){Pt.prototype[c]=function(f){f=f===e?1:T(Rt(f),0);var C=this.__filtered__&&!u?new Pt(this):this.clone();return C.__filtered__?C.__takeCount__=L(f,C.__takeCount__):C.__views__.push({size:L(f,po),type:c+(C.__dir__<0?"Right":"")}),C},Pt.prototype[c+"Right"]=function(f){return this.reverse()[c](f).reverse()}}),_n(["filter","map","takeWhile"],function(c,u){var f=u+1,C=f==$e||f==kr;Pt.prototype[c]=function(y){var I=this.clone();return I.__iteratees__.push({iteratee:vt(y,3),type:f}),I.__filtered__=I.__filtered__||C,I}}),_n(["head","last"],function(c,u){var f="take"+(u?"Right":"");Pt.prototype[c]=function(){return this[f](1).value()[0]}}),_n(["initial","tail"],function(c,u){var f="drop"+(u?"":"Right");Pt.prototype[c]=function(){return this.__filtered__?new Pt(this):this[f](1)}}),Pt.prototype.compact=function(){return this.filter(jn)},Pt.prototype.find=function(c){return this.filter(c).head()},Pt.prototype.findLast=function(c){return this.reverse().find(c)},Pt.prototype.invokeMap=_t(function(c,u){return typeof c=="function"?new Pt(this):this.map(function(f){return Td(f,c,u)})}),Pt.prototype.reject=function(c){return this.filter(sm(vt(c)))},Pt.prototype.slice=function(c,u){c=Rt(c);var f=this;return f.__filtered__&&(c>0||u<0)?new Pt(f):(c<0?f=f.takeRight(-c):c&&(f=f.drop(c)),u!==e&&(u=Rt(u),f=u<0?f.dropRight(-u):f.take(u-c)),f)},Pt.prototype.takeRightWhile=function(c){return this.reverse().takeWhile(c).reverse()},Pt.prototype.toArray=function(){return this.take(po)},Sr(Pt.prototype,function(c,u){var f=/^(?:filter|find|map|reject)|While$/.test(u),C=/^(?:head|last)$/.test(u),y=E[C?"take"+(u=="last"?"Right":""):u],I=C||/^find/.test(u);!y||(E.prototype[u]=function(){var O=this.__wrapped__,P=C?[1]:arguments,$=O instanceof Pt,Q=P[0],Y=$||St(O),X=function($t){var zt=y.apply(E,Ir([$t],P));return C&&dt?zt[0]:zt};Y&&f&&typeof Q=="function"&&Q.length!=1&&($=Y=!1);var dt=this.__chain__,Ct=!!this.__actions__.length,yt=I&&!dt,Ot=$&&!Ct;if(!I&&Y){O=Ot?O:new Pt(this);var kt=c.apply(O,P);return kt.__actions__.push({func:nm,args:[X],thisArg:e}),new Pn(kt,dt)}return yt&&Ot?c.apply(this,P):(kt=this.thru(X),yt?C?kt.value()[0]:kt.value():kt)})}),_n(["pop","push","shift","sort","splice","unshift"],function(c){var u=yl[c],f=/^(?:push|sort|unshift)$/.test(c)?"tap":"thru",C=/^(?:pop|shift)$/.test(c);E.prototype[c]=function(){var y=arguments;if(C&&!this.__chain__){var I=this.value();return u.apply(St(I)?I:[],y)}return this[f](function(O){return u.apply(St(O)?O:[],y)})}}),Sr(Pt.prototype,function(c,u){var f=E[u];if(f){var C=f.name+"";Wt.call(en,C)||(en[C]=[]),en[C].push({name:u,func:f})}}),en[Q1(e,_).name]=[{name:"wrapper",func:e}],Pt.prototype.clone=rQ,Pt.prototype.reverse=iQ,Pt.prototype.value=sQ,E.prototype.at=_J,E.prototype.chain=FJ,E.prototype.commit=PJ,E.prototype.next=NJ,E.prototype.plant=HJ,E.prototype.reverse=jJ,E.prototype.toJSON=E.prototype.valueOf=E.prototype.value=UJ,E.prototype.first=E.prototype.head,Tl&&(E.prototype[Tl]=$J),E},fi=ea();li?((li.exports=fi)._=fi,ld._=fi):Ge._=fi}).call(ar)})(W2,W2.exports);const qq={mermaid:"https://mermaid-js.github.io/mermaid/",flowchart:"https://flowchart.js.org/",plantuml:"https://plantuml.com/"};class Gq extends x2{constructor(e,o,r,i){super(e,o,i);m(this,"group","hovering-toolbar");m(this,"_commands",[{id:"edit",name:R.t("graph.edit"),icon:Dp},{id:"add-comment",name:R.t("graph.comment"),icon:nu},{id:"separator",type:"separator",name:""},{id:"help",name:R.t("graph.help"),icon:dv}]);this.editor=e,this.block=o,this.graphType=r,this.properties=i}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(qq[this.graphType])}}function Zq(n,t,e,o){return{blockCommands:{"hovering-toolbar":new Gq(n,t,e,o)},abstract:W2.exports.capitalize(e)}}class q2{constructor(t,e,o){m(this,"editor");m(this,"logger");m(this,"editing",!1);this.graphType=e,this.codeEmbedDataKey=o,this.editor=t,this.logger=S(`embed-block-${this.graphType}`)}i18nt(t,e){return R.t(`graph.${t}`,e||{})}getContent(t){g(this.logger,t,"embed-element does not exist");const e=t.parentElement;return g(this.logger,e,"content-element does not exist"),e}getEmbed(t){const e=t.childNodes[0];return g(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);g(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=w("div",["graph-embed"],t),{embedData:r}=e,i=r[`${this.codeEmbedDataKey}`],s=r.src,l=w("div",["embed-graph-img-content"],o),a=w("img",["graph-embed-image"],l);a.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),i.onerror=()=>{this.updateImage(t,e,o,new Error("image load failed"))},s&&(i.src=s,i.onerror=()=>{this.errorBoundary(t,e,o)})}errorBoundary(t,e,o){t.innerHTML="";const r=w("div",["graph-error-content"],t),i=w("div",["graph-error-brand-icon"],r);i.innerHTML=Sp,w("div",["graph-error-title"],r,R.t("graph.errorTips",{EmbedName:this.graphType}));const s=w("div",["graph-error-sub-title"],r);w("span",[],s,R.t("graph.errorSubTips"));const l=w("span",["graph-error-retry-button"],s,R.t("graph.retry"));l.onclick=()=>{t.innerHTML="";const a=w("div",["embed-graph-img-content"],t),d=w("img",["graph-embed-image"],a);d.draggable=!1,this.updateImage(t,e,o,null)}}emptyContent(t){t.innerHTML="";const e=w("div",["graph-empty-content"],t),o=w("div",["graph-brand-icon"],e);o.innerHTML=Sp;const r=this.i18nt("empty",{EmbedName:this.graphType});w("div",["graph-empty-title"],e,r)}updateClasses(t,e,o){const r=t.querySelector("img.graph-embed-image"),i=et(t);if(o&&i&&e){const s=r.src;r.remove(),this.errorBoundary(t,e,s);return}e||this.emptyContent(t)}editGraph(t){this.editing=!0;const e=et(t);g(this.logger,e,`${this.graphType} block does not exist`),J0(this.editor,e);const o=t.querySelector(".graph-embed"),r=l=>{this.updateImage(o,l,null,null)},i=async l=>{try{if(this.editing=!1,K0(this.editor,e),r(l),!this.hasChanged(e,l))return;const d={src:await this.code2ResourceId(l),[`${this.codeEmbedDataKey}`]:l};this.editor.updateEmbedData(e,d)}catch(a){this.updateClasses(o,l,a);const d={src:"",[`${this.codeEmbedDataKey}`]:l};this.editor.updateEmbedData(e,d)}},s=this.editor.getBlockData(e);Wq(this.editor,e,{onChange:r,onEnd:i,codeValue:s.embedData[`${this.codeEmbedDataKey}`]})}getBlockProperties(t,e){return this.editing?{}:Zq(this.editor,t,this.graphType,{handleExecuteCommand:(o,r,i)=>{if(i.id==="edit"){if(!o.isBlockWritable(r))return!0;const s=Lt(r);return this.editGraph(s),!0}return i.id==="add-comment"?(o.readonly||Kf(o,r),!0):!1}})}hasChanged(t,e){return this.editor.getBlockData(t).embedData[`${this.codeEmbedDataKey}`]!==e}}const Qq="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js",Yq=["//cdnjs.cloudflare.com/ajax/libs/raphael/2.3.0/raphael.min.js","//cdnjs.cloudflare.com/ajax/libs/flowchart/1.15.0/flowchart.min.js"],Jq="https://www.plantuml.com/plantuml/svg",Kq=S("mermaid-helper"),Xq="wiz-editor-mermaid";async function lk(n,t){var B;const o=((B=(n.getComponentOptions("mermaid")||{}).cdn)==null?void 0:B.mermaid)||Qq;await vs(o,Xq);const r=window.mermaid;g(Kq,r,"Resource load failed: Mermaid javaScript resource injection failed");const i=K(),l=await new Promise((D,x)=>{try{r.mermaidAPI.render(i,t,_=>{setTimeout(()=>{D(_)})})}catch(_){_.message=_.str,x(_)}}),h=new DOMParser().parseFromString(l,"image/svg+xml").firstChild,p=h.style.maxWidth;return p&&h.setAttribute("width",p),new XMLSerializer().serializeToString(h)}async function tG(n,t){const e=await lk(n,t);return Dm(e,"image/svg+xml",`${K()}.svg`)}async function eG(n,t){const e=await lk(n,t),o=new Blob([e]),r=new File([o],`${K()}.svg`,{type:"image/svg+xml"});return(await n.doc.uploadResource(r)).resourceId}class Mc extends q2{constructor(t){super(t,"mermaid","mermaidText")}static get(t,e){return t.addCustom(`mermaid-${e.id}`,()=>new Mc(t))}code2ObjectUrl(t){return tG(this.editor,t)}code2ResourceId(t){return eG(this.editor,t)}destroy(){}}const nG={graph:{invalid:"\u65E0\u6548\u7684 {EmbedName} \u5185\u5BB9\uFF1A{message}",empty:"\u7A7A\u7684 {EmbedName}",edit:"\u7F16\u8F91",comment:"\u6279\u6CE8",help:"\u5E2E\u52A9",errorTips:"{EmbedName}\u52A0\u8F7D\u5931\u8D25",errorSubTips:"\u7F51\u7EDC\u670D\u52A1\u5F02\u5E38\uFF0C\u4F60\u53EF\u4EE5",retry:"\u91CD\u8BD5"}},oG={graph:{invalid:"Invalid {EmbedName} content: {message}",empty:"Empty {EmbedName}",edit:"Edit",comment:"Annotation",help:"Help",errorTips:"{EmbedName} loading failed",errorSubTips:"The network service is abnormal, you can",retry:"Try again"}},rG={graph:{invalid:"\u7121\u52B9\u306A{EmbedName}\uFF1A{message}",empty:"\u7A7A\u306E {EmbedName}",edit:"\u7DE8\u96C6",comment:"\u6CE8\u91C8",help:"\u30D8\u30EB\u30D7",errorTips:"{EmbedName} \u306E\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u306B\u5931\u6557\u3057\u307E\u3057\u305F",errorSubTips:"\u304A\u4F7F\u3044\u306E\u30CD\u30C3\u30C8\u30EF\u30FC\u30AF\u63A5\u7D9A\u306B\u554F\u984C\u304C\u767A\u751F\u3057\u307E\u3057\u305F\u3002\u6B21\u306E\u64CD\u4F5C\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002 ",retry:"\u518D\u8A66\u884C"}};R.mergeLang({"zh-CN":nG,"en-US":oG,"ja-JP":rG});function iG(n,t,e){Mc.get(n,e).createEmbedContent(t,e)}function sG(n,t,e){const o=Mc.get(n,n.getBlockData(t)),r=Lt(t);return o.updateEmbedContent(r,e),!0}function lG(n,t,e){const{data:o}=e,r=n.getBlockString(t).trim();if(!o||o.embedType!=="mermaid"||r!=="```mermaid"||!tt(n,t))return null;const i={src:"",mermaidText:""};return{blockData:{id:K(),type:"embed",embedType:"mermaid",embedData:i},onConverted:(a,d)=>{Mc.get(a,a.getBlockData(d)).editGraph(Lt(d))}}}function cG(n,t){return Mc.get(n,n.getBlockData(t)).getBlockProperties(t)}function aG(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`})`;if(i.mermaidText)return`\`\`\`mermaid\`\`\`
|
|
747
|
+
}`;var Ot=mB(function(){return Vt(I,Ct+"return "+X).apply(e,O)});if(Ot.source=X,O5(Ot))throw Ot;return Ot}function KX(c){return Kt(c).toLowerCase()}function XX(c){return Kt(c).toUpperCase()}function ttt(c,u,f){if(c=Kt(c),c&&(f||u===e))return ai(c);if(!c||!(u=to(u)))return c;var C=Xn(c),y=Xn(u),I=Cl(C,y),O=Ad(C,y)+1;return gs(C,I,O).join("")}function ett(c,u,f){if(c=Kt(c),c&&(f||u===e))return c.slice(0,Kc(c)+1);if(!c||!(u=to(u)))return c;var C=Xn(c),y=Ad(C,Xn(u))+1;return gs(C,0,y).join("")}function ntt(c,u,f){if(c=Kt(c),c&&(f||u===e))return c.replace(Ju,"");if(!c||!(u=to(u)))return c;var C=Xn(c),y=Cl(C,Xn(u));return gs(C,y).join("")}function ott(c,u){var f=Ut,C=ne;if(ve(u)){var y="separator"in u?u.separator:y;f="length"in u?Rt(u.length):f,C="omission"in u?to(u.omission):C}c=Kt(c);var I=c.length;if(ui(c)){var O=Xn(c);I=O.length}if(f>=I)return c;var P=f-us(C);if(P<1)return C;var $=O?gs(O,0,P).join(""):c.slice(0,P);if(y===e)return $+C;if(O&&(P+=$.length-P),_5(y)){if(c.slice(P).search(y)){var Q,Y=$;for(y.global||(y=na(y.source,Kt(Pc.exec(y))+"g")),y.lastIndex=0;Q=y.exec(Y);)var X=Q.index;$=$.slice(0,X===e?P:X)}}else if(c.indexOf(to(y),P)!=P){var dt=$.lastIndexOf(y);dt>-1&&($=$.slice(0,dt))}return $+C}function rtt(c){return c=Kt(c),c&&s3.test(c)?c.replace(d1,Xc):c}var itt=ra(function(c,u,f){return c+(f?" ":"")+u.toUpperCase()}),N5=gw("toUpperCase");function fB(c,u,f){return c=Kt(c),u=f?e:u,u===e?Qc(c)?R1(c):Jn(c):c.match(u)||[]}var mB=_t(function(c,u){try{return yn(c,e,u)}catch(f){return O5(f)?f:new Et(f)}}),stt=wi(function(c,u){return _n(u,function(f){f=Rr(f),yi(c,f,M5(c[f],c))}),c});function ltt(c){var u=c==null?0:c.length,f=vt();return c=u?ue(c,function(C){if(typeof C[1]!="function")throw new kn(s);return[f(C[0]),C[1]]}):[],_t(function(C){for(var y=-1;++y<u;){var I=c[y];if(yn(I[0],this,C))return yn(I[1],this,C)}})}function ctt(c){return RQ(yo(c,p))}function $5(c){return function(){return c}}function att(c,u){return c==null||c!==c?u:c}var utt=Cw(),dtt=Cw(!0);function jn(c){return c}function H5(c){return Gk(typeof c=="function"?c:yo(c,p))}function htt(c){return Qk(yo(c,p))}function ftt(c,u){return Yk(c,yo(u,p))}var mtt=_t(function(c,u){return function(f){return Td(f,c,u)}}),gtt=_t(function(c,u){return function(f){return Td(c,f,u)}});function j5(c,u,f){var C=Ke(u),y=V1(u,C);f==null&&!(ve(u)&&(y.length||!C.length))&&(f=u,u=c,c=this,y=V1(u,Ke(u)));var I=!(ve(f)&&"chain"in f)||!!f.chain,O=Ei(c);return _n(y,function(P){var $=u[P];c[P]=$,O&&(c.prototype[P]=function(){var Q=this.__chain__;if(I||Q){var Y=c(this.__wrapped__),X=Y.__actions__=Nn(this.__actions__);return X.push({func:$,args:arguments,thisArg:c}),Y.__chain__=Q,Y}return $.apply(c,Tr([this.value()],arguments))})}),c}function ptt(){return Ge._===this&&(Ge._=_1),this}function U5(){}function Ctt(c){return c=Rt(c),_t(function(u){return Jk(u,c)})}var Att=b5(ue),btt=b5(E1),vtt=b5(gd);function gB(c){return x5(c)?qc(Rr(c)):YQ(c)}function ytt(c){return function(u){return c==null?e:_l(c,u)}}var ktt=bw(),wtt=bw(!0);function z5(){return[]}function V5(){return!1}function Btt(){return{}}function Ett(){return""}function xtt(){return!0}function Itt(c,u){if(c=Rt(c),c<1||c>an)return[];var f=po,C=L(c,po);u=vt(u),c-=po;for(var y=Zc(C,u);++f<c;)u(f);return y}function Ttt(c){return St(c)?ue(c,Rr):eo(c)?[c]:Nn(_w(Kt(c)))}function Dtt(c){var u=++O1;return Kt(c)+u}var Stt=Y1(function(c,u){return c+u},0),Ltt=v5("ceil"),Mtt=Y1(function(c,u){return c/u},1),Rtt=v5("floor");function Ott(c){return c&&c.length?z1(c,jn,i5):e}function _tt(c,u){return c&&c.length?z1(c,vt(u,2),i5):e}function Ftt(c){return Wc(c,jn)}function Ptt(c,u){return Wc(c,vt(u,2))}function Ntt(c){return c&&c.length?z1(c,jn,a5):e}function $tt(c,u){return c&&c.length?z1(c,vt(u,2),a5):e}var Htt=Y1(function(c,u){return c*u},1),jtt=v5("round"),Utt=Y1(function(c,u){return c-u},0);function ztt(c){return c&&c.length?Gc(c,jn):0}function Vtt(c,u){return c&&c.length?Gc(c,vt(u,2)):0}return E.after=hK,E.ary=qw,E.assign=XK,E.assignIn=sB,E.assignInWith=am,E.assignWith=tX,E.at=eX,E.before=Gw,E.bind=M5,E.bindAll=stt,E.bindKey=Zw,E.castArray=BK,E.chain=zw,E.chunk=RY,E.compact=OY,E.concat=_Y,E.cond=ltt,E.conforms=ctt,E.constant=$5,E.countBy=zJ,E.create=nX,E.curry=Qw,E.curryRight=Yw,E.debounce=Jw,E.defaults=oX,E.defaultsDeep=rX,E.defer=fK,E.delay=mK,E.difference=FY,E.differenceBy=PY,E.differenceWith=NY,E.drop=$Y,E.dropRight=HY,E.dropRightWhile=jY,E.dropWhile=UY,E.fill=zY,E.filter=WJ,E.flatMap=ZJ,E.flatMapDeep=QJ,E.flatMapDepth=YJ,E.flatten=$w,E.flattenDeep=VY,E.flattenDepth=WY,E.flip=gK,E.flow=utt,E.flowRight=dtt,E.fromPairs=qY,E.functions=dX,E.functionsIn=hX,E.groupBy=JJ,E.initial=ZY,E.intersection=QY,E.intersectionBy=YY,E.intersectionWith=JY,E.invert=mX,E.invertBy=gX,E.invokeMap=XJ,E.iteratee=H5,E.keyBy=tK,E.keys=Ke,E.keysIn=Hn,E.map=om,E.mapKeys=CX,E.mapValues=AX,E.matches=htt,E.matchesProperty=ftt,E.memoize=im,E.merge=bX,E.mergeWith=lB,E.method=mtt,E.methodOf=gtt,E.mixin=j5,E.negate=sm,E.nthArg=Ctt,E.omit=vX,E.omitBy=yX,E.once=pK,E.orderBy=eK,E.over=Att,E.overArgs=CK,E.overEvery=btt,E.overSome=vtt,E.partial=R5,E.partialRight=Kw,E.partition=nK,E.pick=kX,E.pickBy=cB,E.property=gB,E.propertyOf=ytt,E.pull=eJ,E.pullAll=jw,E.pullAllBy=nJ,E.pullAllWith=oJ,E.pullAt=rJ,E.range=ktt,E.rangeRight=wtt,E.rearg=AK,E.reject=iK,E.remove=iJ,E.rest=bK,E.reverse=S5,E.sampleSize=lK,E.set=BX,E.setWith=EX,E.shuffle=cK,E.slice=sJ,E.sortBy=dK,E.sortedUniq=fJ,E.sortedUniqBy=mJ,E.split=ZX,E.spread=vK,E.tail=gJ,E.take=pJ,E.takeRight=CJ,E.takeRightWhile=AJ,E.takeWhile=bJ,E.tap=OJ,E.throttle=yK,E.thru=nm,E.toArray=oB,E.toPairs=aB,E.toPairsIn=uB,E.toPath=Ttt,E.toPlainObject=iB,E.transform=xX,E.unary=kK,E.union=vJ,E.unionBy=yJ,E.unionWith=kJ,E.uniq=wJ,E.uniqBy=BJ,E.uniqWith=EJ,E.unset=IX,E.unzip=L5,E.unzipWith=Uw,E.update=TX,E.updateWith=DX,E.values=la,E.valuesIn=SX,E.without=xJ,E.words=fB,E.wrap=wK,E.xor=IJ,E.xorBy=TJ,E.xorWith=DJ,E.zip=SJ,E.zipObject=LJ,E.zipObjectDeep=MJ,E.zipWith=RJ,E.entries=aB,E.entriesIn=uB,E.extend=sB,E.extendWith=am,j5(E,E),E.add=Stt,E.attempt=mB,E.camelCase=OX,E.capitalize=dB,E.ceil=Ltt,E.clamp=LX,E.clone=EK,E.cloneDeep=IK,E.cloneDeepWith=TK,E.cloneWith=xK,E.conformsTo=DK,E.deburr=hB,E.defaultTo=att,E.divide=Mtt,E.endsWith=_X,E.eq=tr,E.escape=FX,E.escapeRegExp=PX,E.every=VJ,E.find=qJ,E.findIndex=Pw,E.findKey=iX,E.findLast=GJ,E.findLastIndex=Nw,E.findLastKey=sX,E.floor=Rtt,E.forEach=Vw,E.forEachRight=Ww,E.forIn=lX,E.forInRight=cX,E.forOwn=aX,E.forOwnRight=uX,E.get=F5,E.gt=SK,E.gte=LK,E.has=fX,E.hasIn=P5,E.head=Hw,E.identity=jn,E.includes=KJ,E.indexOf=GY,E.inRange=MX,E.invoke=pX,E.isArguments=Nl,E.isArray=St,E.isArrayBuffer=MK,E.isArrayLike=$n,E.isArrayLikeObject=De,E.isBoolean=RK,E.isBuffer=ps,E.isDate=OK,E.isElement=_K,E.isEmpty=FK,E.isEqual=PK,E.isEqualWith=NK,E.isError=O5,E.isFinite=$K,E.isFunction=Ei,E.isInteger=Xw,E.isLength=lm,E.isMap=tB,E.isMatch=HK,E.isMatchWith=jK,E.isNaN=UK,E.isNative=zK,E.isNil=WK,E.isNull=VK,E.isNumber=eB,E.isObject=ve,E.isObjectLike=Be,E.isPlainObject=Od,E.isRegExp=_5,E.isSafeInteger=qK,E.isSet=nB,E.isString=cm,E.isSymbol=eo,E.isTypedArray=sa,E.isUndefined=GK,E.isWeakMap=ZK,E.isWeakSet=QK,E.join=KY,E.kebabCase=NX,E.last=wo,E.lastIndexOf=XY,E.lowerCase=$X,E.lowerFirst=HX,E.lt=YK,E.lte=JK,E.max=Ott,E.maxBy=_tt,E.mean=Ftt,E.meanBy=Ptt,E.min=Ntt,E.minBy=$tt,E.stubArray=z5,E.stubFalse=V5,E.stubObject=Btt,E.stubString=Ett,E.stubTrue=xtt,E.multiply=Htt,E.nth=tJ,E.noConflict=ptt,E.noop=U5,E.now=rm,E.pad=jX,E.padEnd=UX,E.padStart=zX,E.parseInt=VX,E.random=RX,E.reduce=oK,E.reduceRight=rK,E.repeat=WX,E.replace=qX,E.result=wX,E.round=jtt,E.runInContext=N,E.sample=sK,E.size=aK,E.snakeCase=GX,E.some=uK,E.sortedIndex=lJ,E.sortedIndexBy=cJ,E.sortedIndexOf=aJ,E.sortedLastIndex=uJ,E.sortedLastIndexBy=dJ,E.sortedLastIndexOf=hJ,E.startCase=QX,E.startsWith=YX,E.subtract=Utt,E.sum=ztt,E.sumBy=Vtt,E.template=JX,E.times=Itt,E.toFinite=xi,E.toInteger=Rt,E.toLength=rB,E.toLower=KX,E.toNumber=Bo,E.toSafeInteger=KK,E.toString=Kt,E.toUpper=XX,E.trim=ttt,E.trimEnd=ett,E.trimStart=ntt,E.truncate=ott,E.unescape=rtt,E.uniqueId=Dtt,E.upperCase=itt,E.upperFirst=N5,E.each=Vw,E.eachRight=Ww,E.first=Hw,j5(E,function(){var c={};return Lr(E,function(u,f){Wt.call(E.prototype,f)||(c[f]=u)}),c}(),{chain:!1}),E.VERSION=o,_n(["bind","bindKey","curry","curryRight","partial","partialRight"],function(c){E[c].placeholder=E}),_n(["drop","take"],function(c,u){Pt.prototype[c]=function(f){f=f===e?1:T(Rt(f),0);var C=this.__filtered__&&!u?new Pt(this):this.clone();return C.__filtered__?C.__takeCount__=L(f,C.__takeCount__):C.__views__.push({size:L(f,po),type:c+(C.__dir__<0?"Right":"")}),C},Pt.prototype[c+"Right"]=function(f){return this.reverse()[c](f).reverse()}}),_n(["filter","map","takeWhile"],function(c,u){var f=u+1,C=f==$e||f==wr;Pt.prototype[c]=function(y){var I=this.clone();return I.__iteratees__.push({iteratee:vt(y,3),type:f}),I.__filtered__=I.__filtered__||C,I}}),_n(["head","last"],function(c,u){var f="take"+(u?"Right":"");Pt.prototype[c]=function(){return this[f](1).value()[0]}}),_n(["initial","tail"],function(c,u){var f="drop"+(u?"":"Right");Pt.prototype[c]=function(){return this.__filtered__?new Pt(this):this[f](1)}}),Pt.prototype.compact=function(){return this.filter(jn)},Pt.prototype.find=function(c){return this.filter(c).head()},Pt.prototype.findLast=function(c){return this.reverse().find(c)},Pt.prototype.invokeMap=_t(function(c,u){return typeof c=="function"?new Pt(this):this.map(function(f){return Td(f,c,u)})}),Pt.prototype.reject=function(c){return this.filter(sm(vt(c)))},Pt.prototype.slice=function(c,u){c=Rt(c);var f=this;return f.__filtered__&&(c>0||u<0)?new Pt(f):(c<0?f=f.takeRight(-c):c&&(f=f.drop(c)),u!==e&&(u=Rt(u),f=u<0?f.dropRight(-u):f.take(u-c)),f)},Pt.prototype.takeRightWhile=function(c){return this.reverse().takeWhile(c).reverse()},Pt.prototype.toArray=function(){return this.take(po)},Lr(Pt.prototype,function(c,u){var f=/^(?:filter|find|map|reject)|While$/.test(u),C=/^(?:head|last)$/.test(u),y=E[C?"take"+(u=="last"?"Right":""):u],I=C||/^find/.test(u);!y||(E.prototype[u]=function(){var O=this.__wrapped__,P=C?[1]:arguments,$=O instanceof Pt,Q=P[0],Y=$||St(O),X=function($t){var zt=y.apply(E,Tr([$t],P));return C&&dt?zt[0]:zt};Y&&f&&typeof Q=="function"&&Q.length!=1&&($=Y=!1);var dt=this.__chain__,Ct=!!this.__actions__.length,yt=I&&!dt,Ot=$&&!Ct;if(!I&&Y){O=Ot?O:new Pt(this);var kt=c.apply(O,P);return kt.__actions__.push({func:nm,args:[X],thisArg:e}),new Pn(kt,dt)}return yt&&Ot?c.apply(this,P):(kt=this.thru(X),yt?C?kt.value()[0]:kt.value():kt)})}),_n(["pop","push","shift","sort","splice","unshift"],function(c){var u=yl[c],f=/^(?:push|sort|unshift)$/.test(c)?"tap":"thru",C=/^(?:pop|shift)$/.test(c);E.prototype[c]=function(){var y=arguments;if(C&&!this.__chain__){var I=this.value();return u.apply(St(I)?I:[],y)}return this[f](function(O){return u.apply(St(O)?O:[],y)})}}),Lr(Pt.prototype,function(c,u){var f=E[u];if(f){var C=f.name+"";Wt.call(en,C)||(en[C]=[]),en[C].push({name:u,func:f})}}),en[Q1(e,_).name]=[{name:"wrapper",func:e}],Pt.prototype.clone=rQ,Pt.prototype.reverse=iQ,Pt.prototype.value=sQ,E.prototype.at=_J,E.prototype.chain=FJ,E.prototype.commit=PJ,E.prototype.next=NJ,E.prototype.plant=HJ,E.prototype.reverse=jJ,E.prototype.toJSON=E.prototype.valueOf=E.prototype.value=UJ,E.prototype.first=E.prototype.head,Tl&&(E.prototype[Tl]=$J),E},fi=ea();li?((li.exports=fi)._=fi,ld._=fi):Ge._=fi}).call(ur)})(W2,W2.exports);const qq={mermaid:"https://mermaid-js.github.io/mermaid/",flowchart:"https://flowchart.js.org/",plantuml:"https://plantuml.com/"};class Gq extends x2{constructor(e,o,r,i){super(e,o,i);m(this,"group","hovering-toolbar");m(this,"_commands",[{id:"edit",name:R.t("graph.edit"),icon:Dp},{id:"add-comment",name:R.t("graph.comment"),icon:nu},{id:"separator",type:"separator",name:""},{id:"help",name:R.t("graph.help"),icon:dv}]);this.editor=e,this.block=o,this.graphType=r,this.properties=i}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(qq[this.graphType])}}function Zq(n,t,e,o){return{blockCommands:{"hovering-toolbar":new Gq(n,t,e,o)},abstract:W2.exports.capitalize(e)}}class q2{constructor(t,e,o){m(this,"editor");m(this,"logger");m(this,"editing",!1);this.graphType=e,this.codeEmbedDataKey=o,this.editor=t,this.logger=S(`embed-block-${this.graphType}`)}i18nt(t,e){return R.t(`graph.${t}`,e||{})}getContent(t){g(this.logger,t,"embed-element does not exist");const e=t.parentElement;return g(this.logger,e,"content-element does not exist"),e}getEmbed(t){const e=t.childNodes[0];return g(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);g(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=w("div",["graph-embed"],t),{embedData:r}=e,i=r[`${this.codeEmbedDataKey}`],s=r.src,l=w("div",["embed-graph-img-content"],o),a=w("img",["graph-embed-image"],l);a.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),i.onerror=()=>{this.updateImage(t,e,o,new Error("image load failed"))},s&&(i.src=s,i.onerror=()=>{this.errorBoundary(t,e,o)})}errorBoundary(t,e,o){t.innerHTML="";const r=w("div",["graph-error-content"],t),i=w("div",["graph-error-brand-icon"],r);i.innerHTML=Sp,w("div",["graph-error-title"],r,R.t("graph.errorTips",{EmbedName:this.graphType}));const s=w("div",["graph-error-sub-title"],r);w("span",[],s,R.t("graph.errorSubTips"));const l=w("span",["graph-error-retry-button"],s,R.t("graph.retry"));l.onclick=()=>{t.innerHTML="";const a=w("div",["embed-graph-img-content"],t),d=w("img",["graph-embed-image"],a);d.draggable=!1,this.updateImage(t,e,o,null)}}emptyContent(t){t.innerHTML="";const e=w("div",["graph-empty-content"],t),o=w("div",["graph-brand-icon"],e);o.innerHTML=Sp;const r=this.i18nt("empty",{EmbedName:this.graphType});w("div",["graph-empty-title"],e,r)}updateClasses(t,e,o){const r=t.querySelector("img.graph-embed-image"),i=et(t);if(o&&i&&e){const s=r.src;r.remove(),this.errorBoundary(t,e,s);return}e||this.emptyContent(t)}editGraph(t){this.editing=!0;const e=et(t);g(this.logger,e,`${this.graphType} block does not exist`),J0(this.editor,e);const o=t.querySelector(".graph-embed"),r=l=>{this.updateImage(o,l,null,null)},i=async l=>{try{if(this.editing=!1,K0(this.editor,e),r(l),!this.hasChanged(e,l))return;const d={src:await this.code2ResourceId(l),[`${this.codeEmbedDataKey}`]:l};this.editor.updateEmbedData(e,d)}catch(a){this.updateClasses(o,l,a);const d={src:"",[`${this.codeEmbedDataKey}`]:l};this.editor.updateEmbedData(e,d)}},s=this.editor.getBlockData(e);Wq(this.editor,e,{onChange:r,onEnd:i,codeValue:s.embedData[`${this.codeEmbedDataKey}`]})}getBlockProperties(t,e){return this.editing?{}:Zq(this.editor,t,this.graphType,{handleExecuteCommand:(o,r,i)=>{if(i.id==="edit"){if(!o.isBlockWritable(r))return!0;const s=Lt(r);return this.editGraph(s),!0}return i.id==="add-comment"?(o.readonly||Kf(o,r),!0):!1}})}hasChanged(t,e){return this.editor.getBlockData(t).embedData[`${this.codeEmbedDataKey}`]!==e}}const Qq="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js",Yq=["//cdnjs.cloudflare.com/ajax/libs/raphael/2.3.0/raphael.min.js","//cdnjs.cloudflare.com/ajax/libs/flowchart/1.15.0/flowchart.min.js"],Jq="https://www.plantuml.com/plantuml/svg",Kq=S("mermaid-helper"),Xq="wiz-editor-mermaid";async function lk(n,t){var B;const o=((B=(n.getComponentOptions("mermaid")||{}).cdn)==null?void 0:B.mermaid)||Qq;await vs(o,Xq);const r=window.mermaid;g(Kq,r,"Resource load failed: Mermaid javaScript resource injection failed");const i=K(),l=await new Promise((D,x)=>{try{r.mermaidAPI.render(i,t,_=>{setTimeout(()=>{D(_)})})}catch(_){_.message=_.str,x(_)}}),h=new DOMParser().parseFromString(l,"image/svg+xml").firstChild,p=h.style.maxWidth;return p&&h.setAttribute("width",p),new XMLSerializer().serializeToString(h)}async function tG(n,t){const e=await lk(n,t);return Dm(e,"image/svg+xml",`${K()}.svg`)}async function eG(n,t){const e=await lk(n,t),o=new Blob([e]),r=new File([o],`${K()}.svg`,{type:"image/svg+xml"});return(await n.doc.uploadResource(r)).resourceId}class Mc extends q2{constructor(t){super(t,"mermaid","mermaidText")}static get(t,e){return t.addCustom(`mermaid-${e.id}`,()=>new Mc(t))}code2ObjectUrl(t){return tG(this.editor,t)}code2ResourceId(t){return eG(this.editor,t)}destroy(){}}const nG={graph:{invalid:"\u65E0\u6548\u7684 {EmbedName} \u5185\u5BB9\uFF1A{message}",empty:"\u7A7A\u7684 {EmbedName}",edit:"\u7F16\u8F91",comment:"\u6279\u6CE8",help:"\u5E2E\u52A9",errorTips:"{EmbedName}\u52A0\u8F7D\u5931\u8D25",errorSubTips:"\u7F51\u7EDC\u670D\u52A1\u5F02\u5E38\uFF0C\u4F60\u53EF\u4EE5",retry:"\u91CD\u8BD5"}},oG={graph:{invalid:"Invalid {EmbedName} content: {message}",empty:"Empty {EmbedName}",edit:"Edit",comment:"Annotation",help:"Help",errorTips:"{EmbedName} loading failed",errorSubTips:"The network service is abnormal, you can",retry:"Try again"}},rG={graph:{invalid:"\u7121\u52B9\u306A{EmbedName}\uFF1A{message}",empty:"\u7A7A\u306E {EmbedName}",edit:"\u7DE8\u96C6",comment:"\u6CE8\u91C8",help:"\u30D8\u30EB\u30D7",errorTips:"{EmbedName} \u306E\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u306B\u5931\u6557\u3057\u307E\u3057\u305F",errorSubTips:"\u304A\u4F7F\u3044\u306E\u30CD\u30C3\u30C8\u30EF\u30FC\u30AF\u63A5\u7D9A\u306B\u554F\u984C\u304C\u767A\u751F\u3057\u307E\u3057\u305F\u3002\u6B21\u306E\u64CD\u4F5C\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002 ",retry:"\u518D\u8A66\u884C"}};R.mergeLang({"zh-CN":nG,"en-US":oG,"ja-JP":rG});function iG(n,t,e){Mc.get(n,e).createEmbedContent(t,e)}function sG(n,t,e){const o=Mc.get(n,n.getBlockData(t)),r=Lt(t);return o.updateEmbedContent(r,e),!0}function lG(n,t,e){const{data:o}=e,r=n.getBlockString(t).trim();if(!o||o.embedType!=="mermaid"||r!=="```mermaid"||!tt(n,t))return null;const i={src:"",mermaidText:""};return{blockData:{id:K(),type:"embed",embedType:"mermaid",embedData:i},onConverted:(a,d)=>{Mc.get(a,a.getBlockData(d)).editGraph(Lt(d))}}}function cG(n,t){return Mc.get(n,n.getBlockData(t)).getBlockProperties(t)}function aG(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`})`;if(i.mermaidText)return`\`\`\`mermaid\`\`\`
|
|
748
748
|
${i.mermaidText}
|
|
749
749
|
\`\`\`\`\`\``}return"[mermaid]"}const ck={embedType:"mermaid",convertFrom:lG,handleUpdateBlock:sG,createEmbedContent:iG,getBlockProperties:cG,convertTo:aG},ak=S("flowchart-helper");async function uG(n){var o;const t=n.getComponentOptions("flowchart")||{},e=((o=t==null?void 0:t.cdn)==null?void 0:o.flowchart)||Yq;for(let r=0;r<e.length;r+=1){const i=e[r];await vs(i,`flowchart-scripts-${r}`)}}async function uk(n,t){const e=w("div",["flowchart-chart-container"],document.body);e.id=`flowchart-${K()}`,await uG(n);const o=window.flowchart;g(ak,o,"flowchart resource does not exist"),o.parse(t).drawSVG(e.id);const i=e.firstElementChild;g(ak,i,"svg element non-existent");const l=new XMLSerializer().serializeToString(i);return e.remove(),l}async function dG(n,t){const e=await uk(n,t);return Dm(e,"image/svg+xml",`${Date.now()}.svg`)}async function hG(n,t){const e=await uk(n,t),o=new Blob([e]),r=new File([o],`${K()}.svg`,{type:"image/svg+xml"});return(await n.doc.uploadResource(r)).resourceId}class Rc extends q2{constructor(t){super(t,"flowchart","flowchartText")}static get(t,e){return t.addCustom(`flowchart-${e.id}`,()=>new Rc(t))}code2ObjectUrl(t){return dG(this.editor,t)}code2ResourceId(t){return hG(this.editor,t)}destroy(){}}function fG(n,t,e){Rc.get(n,e).createEmbedContent(t,e)}function mG(n,t,e){const o=Rc.get(n,e),r=Lt(t);return o.updateEmbedContent(r,e),!0}function gG(n,t,e){const{data:o}=e,r=n.getBlockString(t).trim();if(!o||o.embedType!=="flowchart"||r!=="```flowchart"||!tt(n,t))return null;const i={src:"",flowchartText:""};return{blockData:{id:K(),type:"embed",embedType:"flowchart",embedData:i},onConverted:(a,d)=>{Rc.get(a,a.getBlockData(d)).editGraph(Lt(d))}}}function pG(n,t){return Rc.get(n,n.getBlockData(t)).getBlockProperties(t)}function CG(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`})`;if(i.flowchartText)return`\`\`\`flowchart\`\`\`
|
|
750
750
|
${i.flowchartText}
|
|
751
751
|
\`\`\`\`\`\``}return"[flowchart]"}const dk={embedType:"flowchart",convertFrom:gG,handleUpdateBlock:mG,createEmbedContent:fG,getBlockProperties:pG,convertTo:CG},AG=S("plantuml-helper");function hk(n,t){var l;let o=((l=(n.getComponentOptions("plantuml")||{}).cdn)==null?void 0:l.plantuml)||Jq;o.endsWith("/")||(o+="/");const r=JB.default.encode(t);g(AG,r,r),o+=r;const s=new URLSearchParams(document.location.search).get("doc");return xm(o,{id:`${s}-${K()}`})}async function bG(n,t){try{const e=await H2(n,t);return(await n.doc.uploadResource(e)).resourceId}catch{return Promise.resolve(t)}}class Oc extends q2{constructor(t){super(t,"plantuml","plantumlText")}static get(t,e){return t.addCustom(`plantuml-${e.id}`,()=>new Oc(t))}code2ObjectUrl(t){return Promise.resolve(hk(this.editor,t))}code2ResourceId(t){const e=hk(this.editor,t);return bG(this.editor,e)}destroy(){}}function vG(n,t,e){Oc.get(n,e).createEmbedContent(t,e)}function yG(n,t,e){const o=Oc.get(n,e),r=Lt(t);return o.updateEmbedContent(r,e),!0}function kG(n,t,e){const{data:o}=e,r=n.getBlockString(t).trim();if(!o||o.embedType!=="plantuml"||r!=="```plantuml"||!tt(n,t))return null;const i={src:"",plantumlText:""};return{blockData:{id:K(),type:"embed",embedType:"plantuml",embedData:i},onConverted:(a,d)=>{Oc.get(a,a.getBlockData(d)).editGraph(Lt(d))}}}function wG(n,t){return Oc.get(n,n.getBlockData(t)).getBlockProperties(t)}function BG(n,t,e,o){const{embedData:r}=t,i=r;if(o==="html")return i.src?`<img src="${n.doc.buildResourceUrl(i.src,{withToken:!0})}" />`:i.flowchartText?`<div>${i.flowchartText}</div>`:"<p>[plantuml]</p>";if(o==="markdown"){if(i.src)return`})`;if(i.flowchartText)return`\`\`\`plantuml\`\`\`
|
|
752
752
|
${i.flowchartText}
|
|
753
|
-
\`\`\`\`\`\``}return"[plantuml]"}const fk={embedType:"plantuml",convertFrom:kG,handleUpdateBlock:yG,createEmbedContent:vG,getBlockProperties:wG,convertTo:BG},mot="",EG="hr",xG={dividingLine:{type:"\u5206\u5272\u7EBF",abstract:"\u5206\u5272\u7EBF"}},IG={dividingLine:{type:"Separation line",abstract:"Separation line"}},TG={dividingLine:{type:"\u533A\u5207\u308A\u7DDA",abstract:"\u533A\u5207\u308A\u7DDA"}};R.mergeLang({"zh-CN":xG,"en-US":IG,"ja-JP":TG});function DG(n,t){const e=w("div",["editor-embed-container"],t);w("hr",["editor-embed-hr"],e)}function SG(n,t,e,o){return o==="html"?"<hr />":o==="markdown"?"---":"------------"}function LG(){return{name:"hr",insertEmbedCommandItems:[{id:"insert-hr",name:R.t("dividingLine.type"),icon:GL,order:500,group:"common",subText:Cn("insert-hr")}],handleInsertEmptyEmbed:async(n,t)=>{const{containerId:e,blockIndex:o}=t;return n.insertEmbed(e,o,EG,{})}}}function MG(n,t,e){const{data:o}=e;if(!o||o.embedType!=="dividing-line"||!tt(n,t))return null;const r={};return{blockData:{id:K(),type:"embed",embedType:"hr",embedData:r}}}function RG(){return{abstract:R.t("dividingLine.abstract")}}const mk={embedType:"hr",createEmbedContent:DG,convertTo:SG,getOptions:LG,convertFrom:MG,getBlockProperties:RG},got="",pot="",OG={media:{upload:{failed:'<div class="line-1">{name}\u4E0A\u4F20\u5931\u8D25</div><div class="line-2">\u7F51\u7EDC\u670D\u52A1\u5F02\u5E38\uFF0C\u4F60\u53EF\u4EE5 <span class="retry-upload">\u91CD\u8BD5</span></div>'},load:{failed:'<div class="line-1">{name}\u52A0\u8F7D\u5931\u8D25</div><div class="line-2">\u7F51\u7EDC\u670D\u52A1\u5F02\u5E38\uFF0C\u4F60\u53EF\u4EE5 <span class="retry-upload">\u91CD\u8BD5</span></div>'},audio:{menuItem:"\u97F3\u9891",abstract:"\u97F3\u9891"},video:{menuItem:"\u89C6\u9891",abstract:"\u89C6\u9891"}}},_G={media:{upload:{failed:'<div class="line-1">{name} upload failed</div><div class="line-2">Network error, you can <span class="retry-upload">Retry</span></div>'},load:{failed:'<div class="line-1">{name} loading failed</div><div class="line-2">Network error, you can <span class="retry-upload">Retry</span></div>'},audio:{menuItem:"Audio",abstract:"Audio"},video:{menuItem:"Video",abstract:"Video"}}},FG={media:{upload:{failed:'<div class="line-1">{name}\u306E\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u306B\u5931\u6557\u3057\u307E\u3057\u305F</div><div class="line-2">\u304A\u4F7F\u3044\u306E\u30CD\u30C3\u30C8\u30EF\u30FC\u30AF\u63A5\u7D9A\u306B\u554F\u984C\u304C\u767A\u751F\u3057\u307E\u3057\u305F\u3002\u6B21\u306E\u64CD\u4F5C\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002 <span class="retry-upload">\u518D\u8A66\u884C</span></div>'},load:{failed:'<div class="line-1">{name}\u3092\u8AAD\u307F\u8FBC\u3081\u307E\u305B\u3093\u3067\u3057\u305F</div><div class="line-2">\u304A\u4F7F\u3044\u306E\u30CD\u30C3\u30C8\u30EF\u30FC\u30AF\u63A5\u7D9A\u306B\u554F\u984C\u304C\u767A\u751F\u3057\u307E\u3057\u305F\u3002\u6B21\u306E\u64CD\u4F5C\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002 <span class="retry-upload">\u518D\u8A66\u884C</span></div>'},audio:{menuItem:"\u97F3\u58F0",abstract:"\u97F3\u58F0"},video:{menuItem:"\u52D5\u753B",abstract:"\u52D5\u753B"}}};R.mergeLang({"zh-CN":OG,"en-US":_G,"ja-JP":FG});var qo=(n=>(n.AUDIO="audio",n.VIDEO="video",n))(qo||{}),$u=(n=>(n.Empty="empty",n.Progress="progress",n.Error="error",n))($u||{});const gk=10*1024*1024,PG=["wav","mp3","aac","ogg","webm","flac"],NG=["ogg","mp4","webm"],$G=()=>{};function pk(n){var h,p,A,v,B,D;const t=(h=n.getComponentOptions("media"))!=null?h:{},{allowedMedias:e,maxSize:o,callbacks:r}=t,i=(p=e==null?void 0:e.audio)!=null?p:PG,s=(A=e==null?void 0:e.video)!=null?A:NG,l=(v=o==null?void 0:o.audio)!=null?v:gk,a=(B=o==null?void 0:o.video)!=null?B:gk,d=(D=r==null?void 0:r.onError)!=null?D:$G;return{allowedMedias:{audio:i,video:s},maxSize:{audio:l,video:a},callbacks:{onError:d}}}function HG(n,t){const e=i=>i.map(s=>`.${s}`).join(","),{allowedMedias:o}=pk(n),r=o[t];return r?e(r):"*"}function jG(n,t,e){const{maxSize:o,callbacks:r,allowedMedias:i}=pk(t),{[e]:s}=o,{[e]:l}=i;if(s&&n.size>s){const d=new Error("media is too large");throw d.code=`MaxMediaSize-${e}`,r!=null&&r.onError&&(r==null||r.onError(t,d)),d}const a=Aa(n.name);if(l&&!l.includes(a)){const d=new Error(`media file is not allowed: ${a}`);throw d.code="NotAllowedFile",r!=null&&r.onError&&(r==null||r.onError(t,d)),d}}function UG(n){return n===$u.Empty||n===$u.Error}const Ne=S("media");class zG extends ye.TypedEmitter{constructor(e){super();m(this,"mediaContainer",null);m(this,"media",null);m(this,"abstract",null);m(this,"handleMediaLoadError",(e,o)=>{if(!o.target||!(o.target instanceof Node)||!(o.target instanceof Element?o.target:o.target.parentElement))return;const i=et(o.target);if(!i||!i.contains(this.mediaContainer))return;const s=this.renderError();this.updateMediaContent(s),this.emit("mediaError",e,"load_error",it(i))});m(this,"handleUploadFile",async e=>{g(Ne,this.abstract,"no abstract"),g(Ne,this.mediaContainer,"The media element not exist");const{editor:o}=this.options,r=et(this.mediaContainer);g(Ne,r,"The block element not exist");const i=o.getBlockData(r);try{const{resourceId:s}=await o.doc.uploadResource(e,{onProgress:p=>{this.renderProgress(p,e)}}),{name:l,type:a,size:d}=e,h={...i,embedData:{...i.embedData,src:s,fileName:l,fileSize:d,fileType:a}};o.updateBlockData(r,h)}catch(s){Ne.error(s),this.emit("mediaError",o,"upload_error",i.id),this.renderRetry(e)}ot(r,"media-block-uploading")});m(this,"destroy",()=>{this.mediaContainer=null});this.options=e}bindMediaEvent(){const{editor:e}=this.options;this.media&&e.domEvents.addEventListener(this.media,"error",this.handleMediaLoadError)}unbindMediaEvent(){const{editor:e}=this.options;this.media&&e.domEvents.removeEventListener(this.media,"error",this.handleMediaLoadError)}updateMediaContent(e){g(Ne,this.mediaContainer,"The media element not exist"),this.mediaContainer.innerHTML="",this.mediaContainer.append(e)}renderError(){g(Ne,this.abstract,"no abstract");const{editor:e,createMediaElement:o}=this.options,{mediaIcon:r,mediaName:i}=this.abstract;g(Ne,this.mediaContainer,"The media element not exist");const s=et(this.mediaContainer);g(Ne,s,"The block element not exist");const l=e.getBlockData(s),a=l.embedData.src,d=w("div",["media-error","embed-selected-content","embed-hover-content"],null),h=w("span",["media-error-icon"],d);h.innerHTML=r;const p=w("div",[],d);p.innerHTML=R.t("media.load.failed",{name:i}),d.appendChild(p);const A=p.querySelector(".retry-upload");return g(Ne,A,"The element not exist"),e.domEvents.addEventListener(A,"click",(v,B)=>{const D=w("div",["media-element"],null),x=this.getResourceUrl(a),_=o(v,D,l,x);this.unbindMediaEvent(),this.media=_,this.bindMediaEvent(),this.updateMediaContent(D)}),this.setFullScreen(),d}renderRetry(e){g(Ne,this.abstract,"no abstract");const{editor:o}=this.options,{mediaIcon:r,mediaName:i}=this.abstract,s=w("div",["media-error","embed-selected-content","embed-hover-content"],null),l=w("span",["media-error-icon"],s);l.innerHTML=r;const a=w("div",[],s);a.innerHTML=R.t("media.upload.failed",{name:i}),s.appendChild(a);const d=a.querySelector(".retry-upload");g(Ne,d,"The element not exist"),o.domEvents.addEventListener(d,"click",()=>{o.readonly||(g(Ne,this.abstract,"no abstract"),this.handleUploadFile(e))}),this.updateMediaContent(s),this.setFullScreen()}renderProgress(e,o){g(Ne,this.mediaContainer,"The media element not exist");const r=this.mediaContainer.querySelector(":scope .media-progress"),i=e===-1||e===100?100:e;if(r){const{updateProgressElement:s}=this.options;s(r,i)}else{const{createProgressElement:s}=this.options,l=et(this.mediaContainer);g(Ne,l,"The element not exist"),W(l,"media-block-uploading");const a=w("div",["media-progress"],null);s(a,i,o),this.updateMediaContent(a)}this.setFullScreen()}renderMediaElement(e){g(Ne,this.mediaContainer,"The media element not exist");const o=this.mediaContainer.querySelector(":scope > .media-element"),{createMediaElement:r,updateMediaElement:i,editor:s}=this.options,l=this.getResourceUrl(e.embedData.src);if(o){const a=i(s,o,e,l);this.unbindMediaEvent(),this.media=a,this.bindMediaEvent()}else{const a=w("div",["media-element"],null),d=r(s,a,e,l);this.unbindMediaEvent(),this.media=d,this.bindMediaEvent(),this.updateMediaContent(a)}}renderEmpty(e){g(Ne,this.abstract,"no abstract"),g(Ne,this.mediaContainer,"The media element not exist");const o=w("div",["media-empty","embed-selected-content","embed-hover-content"],this.mediaContainer);o.innerHTML=this.abstract.mediaIcon,this.updateMediaContent(o);const{editor:r}=this.options;r.findBlockById(e.id)&&this.emit("mediaError",r,"empty",e.id),this.setFullScreen()}getResourceUrl(e){const{editor:o}=this.options;return o.doc.buildResourceUrl(e)}setFullScreen(){g(Ne,this.mediaContainer,"The media element not exist"),W(this.mediaContainer,"full-screen")}removeFullScreen(){g(Ne,this.mediaContainer,"The media element not exist"),ot(this.mediaContainer,"full-screen")}updateBlockAlign(e,o){const r=et(o);g(Ne,r,"The block element not exist");const{align:i}=e;e.embedType==="video"&&(r.hasAttribute("data-style-align")&&r.removeAttribute("data-style-align"),r.setAttribute("data-style-align",i))}render(e,o){const{src:r}=e.embedData;(!this.mediaContainer||!o.contains(this.mediaContainer))&&(this.mediaContainer=w("div",["media"],o)),this.updateBlockAlign(e,o),UG(r)?r===$u.Empty&&this.renderEmpty(e):this.renderMediaElement(e)}setAbstract(e){this.abstract=e}}S("media-embed");const VG="left";class Ck{constructor(){m(this,"handleInsertEmptyEmbed",async(t,e)=>{var p;const{containerId:o,blockIndex:r}=e;let i;(p=e.data)!=null&&p.file&&(i=e.data.file);const s=HG(t,this.embedType);if(i=i!=null?i:await Ul(s,{}),!i)return null;const{mediaType:l}=this.getAbstract();try{jG(i,t,l)}catch{return null}const a={id:K(),type:"embed",embedType:this.embedType,embedData:{src:$u.Empty}};l==="video"&&(a.align=VG);const d=t.insertBlock(o,r,a);return await this.getMedia(t,a.id).handleUploadFile(i),d})}getMedia(t,e){const o=t.addCustom(`media-${e}`,()=>new zG({editor:t,createMediaElement:this.createMediaElement,updateMediaElement:this.updateMediaElement,createProgressElement:this.createProgressElement,updateProgressElement:this.updateProgressElement}));return o.setAbstract({...this.getAbstract()}),o}getOptions(){const{menuItem:t,mediaIcon:e,mediaName:o,order:r,group:i}=this.getAbstract();return{name:o,insertEmbedCommandItems:[{id:`insert-${this.embedType}`,name:t,icon:e,order:r,group:i,subText:Cn(`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=Lt(e);return i.render(o,s),!0}handleDeleteBlock(t,e){const o=e.id,r=this.getMedia(t,o);r.removeAllListeners(),r.destroy()}convertTo(t,e,o,r){const i=e.embedData,s=t.doc.buildResourceUrl(i.src,{withToken:!0});return r==="html"?`<${i.type} src="${s}" />`:r==="markdown"?``:s}}function Ak(n,t){const e=w("div",["uploading-progress-mask"],n),o=w("div",["uploading-progress-bar"],e),r=w("div",["uploading-progress-bar-value"],o);r.style.width=`${t}%`}function bk(n,t){const e=n.querySelector(".uploading-progress-bar-value");e&&(e.style.width=`${t}%`)}const WG=S("media-audio");class qG extends Ck{constructor(){super(...arguments);m(this,"embedType",qo.AUDIO);m(this,"updateProgressElement",bk);m(this,"createMediaElement",(e,o,r,i)=>{const s=w("div",["audio-container","embed-hover-content","embed-selected-content"],o),l=w("audio",[],s);return l.innerHTML="Your browser does not support the <code>audio</code> element.",l.controls=!0,l.src=i,setTimeout(()=>{this.getMedia(e,r.id).setFullScreen()}),l})}getAbstract(){return{mediaIcon:VL,mediaName:R.t(`media.${qo.AUDIO}.menuItem`),menuItem:R.t(`media.${qo.AUDIO}.menuItem`),order:800,mediaType:qo.AUDIO,group:"common"}}getBlockProperties(){return{abstract:`${R.t(`media.${qo.AUDIO}.abstract`)}`}}updateMediaElement(e,o,r,i){const s=o.querySelector(":scope .audio-container > audio");return g(WG,s,"The media element not exist"),s.src!==i&&(s.src=i),s}createProgressElement(e,o){const r=w("audio",[],e);r.innerHTML="Your browser does not support the <code>audio</code> element.",r.controls=!0,r.src="about:blank",Ak(e,o)}}const vk=new qG;S("video-resizer");function yk(n){return n&&Me(n)&&fn(n)==="video"}const GG=50;class G2{constructor(t){m(this,"currentResizableElement",null);m(this,"resizing",!1);m(this,"handleHoveringBlockChange",(t,e)=>{if(!this.resizing&&!window.isDragging&&(e&&yk(e)&&this.disableBlockResize(e),t&&yk(t))){const o=this.getVideoElement(t);if(!o)return;this.enableBlockResize(t,o)}});m(this,"handleResizing",(t,e)=>{if(this.resizing=!0,!this.currentResizableElement)return;const o=t.getBlock();if(!o)return;const r=o.getBoundingClientRect().width,i=Math.min(Math.max(e.width,GG),r);this.currentResizableElement.style.width=`${i}px`,this.currentResizableElement.style.pointerEvents="none"});m(this,"handleResized",t=>{this.resizing=!1;const e=t.getBlock();if(!this.currentResizableElement||!e)return;const o=this.editor.getBlockData(e),{width:r}=this.currentResizableElement.getBoundingClientRect();this.currentResizableElement.style.pointerEvents="auto",this.editor.updateBlockData(e,{...o,width:r})});this.editor=t,Ae.get(t).addListener("change",this.handleHoveringBlockChange)}destroy(){this.currentResizableElement=null,Ae.get(this.editor).removeListener("change",this.handleHoveringBlockChange)}getVideoElement(t){return Lt(t).querySelector(":scope .video-container > video")}updateResizer(t){const e=this.editor.findCustom(`${it(t)}-resizer`);e&&e.updateResizer()}disableBlockResize(t){const e=this.editor.findCustom(`${it(t)}-resizer`);e&&e.disableResize()}enableBlockResize(t,e){const o=this.editor.addCustom(`${it(t)}-resizer`,()=>new Bu(this.editor,{resize:["top-left","top-right","bottom-left","bottom-right"]}));o.enableResize(t,e),o.removeListener("resizing",this.handleResizing),o.removeListener("resized",this.handleResized),o.addListener("resizing",this.handleResizing),o.addListener("resized",this.handleResized),this.currentResizableElement=e}}const ZG=S("video");class QG extends Ck{constructor(){super(...arguments);m(this,"embedType",qo.VIDEO);m(this,"updateProgressElement",bk);m(this,"createMediaElement",(e,o,r,i)=>{const s=w("div",["video-container","embed-selected-content","drag-preview-element"],o),l=w("video",[],s);return l.innerHTML="Your browser does not support the <code>video</code> element.",l.controls=!0,l.src=i,l.addEventListener("canplay",()=>{e.addCustom("video-resizer",()=>new G2(e)),this.getMedia(e,r.id).removeListener("mediaError",this.handleMediaError),this.getMedia(e,r.id).addListener("mediaError",this.handleMediaError),this.getMedia(e,r.id).removeFullScreen()}),r.width&&(l.style.width=`${r.width}px`),l});m(this,"createProgressElement",(e,o,r)=>{const i=w("video",["progress-video"],e);i.innerHTML="Your browser does not support the <code>audio</code> element.",i.controls=!0,Ak(e,o),jl(r).then(s=>{const l=e.querySelector(".progress-video");l&&Hm(e)&&(l.src=s)})})}getAbstract(){return{mediaName:R.t(`media.${qo.VIDEO}.menuItem`),mediaIcon:WL,menuItem:R.t(`media.${qo.VIDEO}.menuItem`),order:700,mediaType:qo.VIDEO,group:"common"}}getBlockProperties(){return{abstract:`[${R.t(`media.${qo.VIDEO}.abstract`)}]`}}handleMediaError(e,o,r){const i=e.addCustom("video-resizer",()=>new G2(e)),s=e.getBlockById(r);i.disableBlockResize(s)}updateMediaElement(e,o,r,i){const s=o.querySelector(":scope .video-container > video");g(ZG,s,"The media element not exist"),s.src!==i&&(s.src=i),r.width?s.style.width=`${r.width}px`:s.style.width="";const l=e.getBlockById(r.id);return setTimeout(()=>{e.addCustom("video-resizer",()=>new G2(e)).updateResizer(l)}),s}}const kk=new QG,wk=[Ef,Df,j0,I9],Z2=[z2,J8,ck,dk,fk,N9,mk,kk,vk,ny,V8,eV],Bk=[I0,F2,f8];function YG(n,t,e){var r,i,s;const o=ja(n,t,{components:{blocks:[...wk,...((r=e==null?void 0:e.components)==null?void 0:r.blocks)||[]],embeds:[...Z2,...((i=e.components)==null?void 0:i.embeds)||[]],boxes:[...Bk,...((s=e.components)==null?void 0:s.boxes)||[]],textRenders:[new p0],options:{...e.componentsOptions}}});return o.readonly=!0,o.addCustom("heading-collapse",()=>new M2(o)),o.addCustom("editor-tooltip",()=>new Af(o)),o.addListener("clickLink",(l,a,d)=>{var p;if((p=e==null?void 0:e.events)!=null&&p.onClickLink){e.events.onClickLink(l,a,d);return}const h=d.getAttribute("link");h&&(l.readonly||a.ctrlKey||a.metaKey)&&window.open(h,"_blank")}),o}class Ek{constructor(t){this.createOptions=t,t.lang&&R.setLang(t.lang)}createHistoryEditor(t,e){return YG(t,e,this.createOptions)}}S("create-editor");function xk({root:n,childDoc:t,doc:e}){t.uploadResource=e.uploadResource.bind(e),t.buildResourceUrl=e.buildResourceUrl.bind(e);const o=ja(n,t,{shortcuts:[Mh],components:{blocks:[Ef,Df],decorators:[new Sf],embeds:[ny,z2,J8,ck,dk,fk,N9,mk,kk,vk],boxes:[I0,F2],options:{image:{defaultAlign:"left"}}}});return o.input.addHandler(new xf),o.input.addHandler(new l2(o)),o.input.addHandler(new h2(o)),o.input.addHandler(new sz(o)),o.input.addHandler(new _f),o.addCustom("image-paste-handler",()=>new s2(o)),o}function JG(n,t){const e=Array.from(n.rootContainer.querySelectorAll(`[comment-${t.toLocaleLowerCase()}="${t}"]`)),o=new Set;e.forEach(r=>{const i=et(r);i&&o.add(i)}),o.forEach(r=>{lz(n,r,t)})}class KG{constructor(t){m(this,"listeners",new Set);m(this,"doc");this.editor=t,this.doc=this.editor.doc.externalDoc,this.doc.registerCallback(this)}getComments(){return this.doc.getComments()}getComment(t){return this.doc.getComment(t)}getCommentDoc(t){return this.doc.getCommentDoc(t)}localCreateComment(t,e){this.doc.localCreateComment(t,e)}localDeleteComment(t){const e=this.getComment(t);this.doc.localDeleteComment(t);const o=e.groupId;this.getComments().filter(i=>i.groupId===o).length===0&&JG(this.editor,o)}localUpdateComment(t,e){this.doc.localUpdateComment(t,e)}onCreateComment(t,e){Array.from(this.listeners.values()).forEach(o=>o.onCreateComment(t,e))}onDeleteComment(t,e){Array.from(this.listeners.values()).forEach(o=>o.onDeleteComment(t,e))}onUpdateComment(t,e){Array.from(this.listeners.values()).forEach(o=>o.onUpdateComment(t,e))}addListener(t){this.listeners.add(t)}removeListener(t){this.listeners.delete(t)}createCommentEditor(t,e){var r,i;const o=xk({root:t,childDoc:e,doc:this.doc});if((r=this.editor.options.componentsOptions)!=null&&r.mention){const s=this.editor.options.componentsOptions.mention;o.addCustom("mention",()=>new _2(o,{...s,enableFirstBlock:!0}))}if((i=this.editor.options.componentsOptions)!=null&&i.comment){const s=this.editor.options.componentsOptions.comment;s.onCommentEditorClick&&o.addListener("click",s.onCommentEditorClick)}return o}allowEdit(t){return t.userId===this.doc.getUser().userId}}class XG{constructor(t,e){m(this,"listeners",new Set);this.editor=t,this.localDoc=e}get doc(){return this.localDoc.toJSON()}getComments(){return Object.values(this.doc.comments)}getComment(t){return this.doc.comments[t]}getCommentDoc(t){const e=this.doc.comments[t];return pp(e)}addListener(t){this.listeners.add(t)}removeListener(t){this.listeners.delete(t)}localCreateComment(t,e){}localDeleteComment(t){}localUpdateComment(t,e){}createCommentEditor(t,e){var r,i;const o=xk({root:t,childDoc:e,doc:this.localDoc});if((r=this.editor.options.componentsOptions)!=null&&r.mention){const s=this.editor.options.componentsOptions.mention;o.addCustom("mention",()=>new _2(o,{...s,enableFirstBlock:!0}))}if((i=this.editor.options.componentsOptions)!=null&&i.comment){const s=this.editor.options.componentsOptions.comment;s.onCommentEditorClick&&o.addListener("click",s.onCommentEditorClick)}return o}allowEdit(t){return t.userId===this.localDoc.getUser().userId}}const tZ={placeholder:{common:{title:"\u8BF7\u8F93\u5165\u6807\u9898",readonlyTitle:"\u8BF7\u8F93\u5165\u6807\u9898",content:"\u70B9\u51FB + \uFF0C\u6216\u8F93\u5165 / \u5FEB\u6377\u63D2\u5165\u7EC4\u4EF6",contentInTable:"\u8F93\u5165 / \u5FEB\u6377\u63D2\u5165\u7EC4\u4EF6"},local:{readonlyTitle:"\u672A\u547D\u540D"}},copyCutProperty:{copy:"\u590D\u5236",cut:"\u526A\u5207",unsafeEnvTips:"\u7531\u4E8E\u5F53\u524D http \u8BBF\u95EE\u73AF\u5883\u4E0B\u7684\u9650\u5236\uFF0C\u8BF7\u4F7F\u7528\u5FEB\u6377\u952E({shortCut}) {operation}"}},eZ={placeholder:{common:{title:"Enter a title",readonlyTitle:"Enter a title",content:"Click + or enter / to insert components quickly",contentInTable:"Enter / to insert components quickly"},local:{readonlyTitle:"Untitled"}},copyCutProperty:{copy:"Copy",cut:"Cut",unsafeEnvTips:"Due to the limitations of the current http access environment, please use the shortcut ({shortCut}) {operation}"}},nZ={placeholder:{common:{title:"\u30BF\u30A4\u30C8\u30EB\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",readonlyTitle:"\u30BF\u30A4\u30C8\u30EB\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",content:"\u300C+\u300D\u3092\u30AF\u30EA\u30C3\u30AF\u3059\u308B\u304B\u3001\u300C/\u300D\u3092\u5165\u529B\u3059\u308B\u3068\u3001\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8\u304C\u7D20\u65E9\u304F\u633F\u5165\u3067\u304D\u307E\u3059",contentInTable:"\u300C/\u300D\u3092\u5165\u529B\u3059\u308B\u3068\u3001\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8\u304C\u7D20\u65E9\u304F\u633F\u5165\u3067\u304D\u307E\u3059"},local:{readonlyTitle:"\u7121\u984C"}},copyCutProperty:{copy:"\u8907\u88FD",cut:"\u5207\u308B",unsafeEnvTips:"HTTP\u74B0\u5883\u306E\u5236\u7D04\u306B\u3088\u308A\u3001{operation}\u3059\u308B\u306B\u306F\u3001\u30B7\u30E7\u30FC\u30C8\u30AB\u30C3\u30C8({shortCut}) \u3092\u3054\u4F7F\u7528\u304F\u3060\u3055\u3044"}};R.mergeLang({"zh-CN":tZ,"en-US":eZ,"ja-JP":nZ});const oZ="UEsDBBQABgAIAAAAIQBk9WPugQEAACkGAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC0lMtqwzAQRfeF/oPRtsRKuiilxMmij2UbaArdKvI4EdULaZzH33fsJKYUJy5NsjHIM/feowHNcLw2OllCiMrZjA3SPkvASpcrO8/Yx/Sld8+SiMLmQjsLGdtAZOPR9dVwuvEQE1LbmLEFon/gPMoFGBFT58FSpXDBCKRjmHMv5JeYA7/t9++4dBbBYg8rDzYaPkEhSo3J85p+b0kC6MiSx21jlZUx4b1WUiDV+dLmv1J6u4SUlHVPXCgfb6iB8daEqnI4YKd7o9EElUMyEQFfhaEuvnIh57mTpSFletymhdMVhZLQ6Cs3H5yEGGnmRqcIxtMNIDVC2T1/G4csIzrzaTRXpJkE5+PgZJzGtPKDgAqaGR6chS3NDALRn38YjXUnRMSNhnh+gq1vdzwgkuASADvnToQVzN4vRvHDvBOkoNypmGk4P0Zj3QmBtIpg+z39VdQ2xyKps36AtNrCP669312Vuuf/9PKaRLI++X5QrcUc8pZsXi/60TcAAAD//wMAUEsDBBQABgAIAAAAIQAekRq37wAAAE4CAAALAAgCX3JlbHMvLnJlbHMgogQCKKAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAArJLBasMwDEDvg/2D0b1R2sEYo04vY9DbGNkHCFtJTBPb2GrX/v082NgCXelhR8vS05PQenOcRnXglF3wGpZVDYq9Cdb5XsNb+7x4AJWFvKUxeNZw4gyb5vZm/cojSSnKg4tZFYrPGgaR+IiYzcAT5SpE9uWnC2kiKc/UYySzo55xVdf3mH4zoJkx1dZqSFt7B6o9Rb6GHbrOGX4KZj+xlzMtkI/C3rJdxFTqk7gyjWop9SwabDAvJZyRYqwKGvC80ep6o7+nxYmFLAmhCYkv+3xmXBJa/ueK5hk/Nu8hWbRf4W8bnF1B8wEAAP//AwBQSwMEFAAGAAgAAAAhADPCW79BAQAA5wQAABwACAF3b3JkL19yZWxzL2RvY3VtZW50LnhtbC5yZWxzIKIEASigAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAArJQxT8MwEIV3JP5D5B07LVAQatoFkDqwQJFYneSSWI3tyL6Q9t9zojRNRYkYPN6z7r1P57Pny62uo09wXlmTsAmPWQQms7kyZcLe189X9yzyKE0ua2sgYTvwbLm4vJi/Qi2RmnylGh+Ri/EJqxCbByF8VoGWntsGDJ0U1mmJVLpSNDLbyBLENI5nwg092OLEM1rlCXOrnPLXuwb+422LQmXwaLNWg8EzEQKpF8hQuhIwYd/lXpxwMmPiPMN1SAaPu5qG2EPs67H4u5DxhTW4lmk9GEMvjUFMQ0KYVqfgaMeOEL00BjEJCZG1Hq3+oLQegvOjKhSCHl2LWUiaipxcrczmSPNj23UdT6XKW55ZLQ7HLzan5KctgjPyT8TbkIgdpG+ASHc0WN+BODarm6BP6BfFQTkgiJPvafEFAAD//wMAUEsDBBQABgAIAAAAIQBOMo6QFgYAAKYkAAARAAAAd29yZC9kb2N1bWVudC54bWzUWttu40QYvkfiHSJfLRKtz4eYTVeOD7uVQKoo+wCuPUmstT3WeNI0XC0XC1wguOBiuWClLgjBE4AEiIdZ0T28BTM+JM6h7cTZkm0vEnv+mW+++eb7/0yc3r13lsSdU4DyCKY9TtwXuA5IAxhG6bDHPfzM2zO4To79NPRjmIIeNwU5d+/g/ffuTswQBuMEpLhDINLcnGRBjxthnJk8nwcjkPj5fhIFCOZwgPcDmPBwMIgCwE8gCnlJEIXiKkMwAHlO5rP99NTPuQouOGNDC5E/IYMpoMIHIx9hcDbHEDcGUfkub6wCSS2AyAolcRVK3hhK4ymrFSClFRBhtYKktkNaszitHZK0iqS3Q5JXkYx2SCt2SlYNDjOQkuAAosTH5BYN+cRHj8bZHgHOfBydRHGEpwRT0GoYP0oftWBERs0QEjncGEHnExiCWA5rFNjjxig1q/F7s/GUulmOr97qEYhl/eUQpyoOxcp5BGKiBUzzUZTNMjxpi0aCoxrk9KpFnCZx3W+SiYzpcll5ckop54As9Cv9k7hkfjWiKDDsCIWYjWChsDhnzSQhLpxP3EqahrgiYwGpAaQVAC0AjAW/xjAqDD6YZyjFiRhTo8Ypd4XiRHNhRcY6tkymAZCDzSDUmkc+TRoryobb2fY+guNsjhZth3Y4L0ITehzYAKuyfzMl8+3IHI/8jNSmJDAPhylE/klMGBEzd4gfO8UO0FeyrfStuARnHVoIuANyfDmB4ZS+ZySimJmP/EPiHEV2dE+3La5oJcUf01a9+iOtJjkqhZ/2OEEQJE1z5FmTAwb+OMY04nUVRRfryFGjqZjwCBVvx3gaE4bmqR/3uAfAp2cukeNpDJVdYj8d1h1AuvfwmEb5KszPkMqX6tqDKc7JoFGUEi7Az7GVR35z4MTEBy/Pv3rz0w+0CZeBZZwrp6ajxIXBlMwaMT2l6wh9lUHMRcnejpjSDYrJoND2GksMGquOY+iu7exIY/m2ayyzaKwaqi4YNNd3obFy2zVWGDTW+7Il296uaoX6LmisMugkKIpouJqwI5202+5FjUFjTfQ8S7OMHWms33aNdQaNJd3qqoq8q5pq3HaNDRaNNcFzRafLoLGtaF2JdlzReDFSaFw1NTTeRMf1XBVLNcSux+KHnXOVBddQLEm6DVxVSxf6nubdPNfFPLNhCCqWdRxBOHARIj3wNCNf1YbIT46xj3CVi6WxA5jmMAb7MRzeWUqQtQhuGi6Mf/H4xxGIY/hhh3xbjMMXj5998BFDrsiSZnuiYjPoZLiC7fV3rVM+zTFI9uEY72eI1KA4baPWnZZyiYYu2oLFlK6u2C3OzqtyLURaytXME8Zvv//+9fOr8y8unj1lWKjqeroraMpWvliMFAutmoq9WDp9aJohGzrLN7o2M7asLrVj6MMbM8/8gBgqQyAH6BRwB5RlZ8l/1HgFrSO0NH29Wws7e5jGUQoa+zvbLgwuQ26YiBGX2SOvn39z8eWT0ik3tbAzvIzMuiuXbkRndSfW+1rRlb7nKExng00SeDuXXcK1qwiWJi99hmme4uiaRfNkJ1wXt2u78+Dr35+8+vPXJTeMSNVGxDuPOsiMyILRYahR/qMoxxBNSREuTbdox+vy4UGNem06MPB+8/0/L7/9ZdluM+JvV6SX539c/P0dg7eFru3alrhUs1VH6kuqPD/gULUcRVAdd51fFiM35m21L3ueJNOJGlwFQ1FFxZ0beQ3Xcrs3WkDV1FjA4qfrx8RZR4QYOSlko3JX0nFS9ozi07juJ8xih2HdVjy65mcDGlmyljCbK5rbf/H109fPf7u6FjfA2R5Rq47sCZq2JL/ueo5o2VfK//8oXf0g8K4rvcf0c4DrGX25v3TElmzV1foiLe47tfrGZf16xWbiLMlTh/yTCmauWA4CfDST+jopimUNjz8nwQnxhSQp9LmgOSLXqqFUWZoNP/EpIoYZaVfKLigajvD89gRiDJP5fQwGjegI+CEg8+oCfSRmDiDEjdvhGBe31XQBjKle1cmE9imaQxjcR/SnOJOeho4iHBCWslYM4ut1F5flD3P8/B+MDv4DAAD//wMAUEsDBBQABgAIAAAAIQC29GeY0gYAAMkgAAAVAAAAd29yZC90aGVtZS90aGVtZTEueG1s7FlLixtHEL4H8h+Guct6zehhrDXSSPJr1zbetYOPvVJrpq2eadHd2rUwhmCfcgkEnJBDDLnlEEIMMcTkkh9jsEmcH5HqHkkzLfXEj12DCbuCVT++qv66qrq6NHPh4v2YOkeYC8KSjls9V3EdnIzYmCRhx719MCy1XEdIlIwRZQnuuAss3Is7n392AZ2XEY6xA/KJOI86biTl7Hy5LEYwjMQ5NsMJzE0Yj5GELg/LY46OQW9My7VKpVGOEUlcJ0ExqL0xmZARdg6USndnpXxA4V8ihRoYUb6vVGNDQmPH06r6EgsRUO4cIdpxYZ0xOz7A96XrUCQkTHTciv5zyzsXymshKgtkc3JD/beUWwqMpzUtx8PDtaDn+V6ju9avAVRu4wbNQWPQWOvTADQawU5TLqbOZi3wltgcKG1adPeb/XrVwOf017fwXV99DLwGpU1vCz8cBpkNc6C06W/h/V671zf1a1DabGzhm5Vu32saeA2KKEmmW+iK36gHq92uIRNGL1vhbd8bNmtLeIYq56IrlU9kUazF6B7jQwBo5yJJEkcuZniCRoALECWHnDi7JIwg8GYoYQKGK7XKsFKH/+rj6Zb2KDqPUU46HRqJrSHFxxEjTmay414FrW4O8urFi5ePnr989PvLx49fPvp1ufa23GWUhHm5Nz9988/TL52/f/vxzZNv7XiRx7/+5avXf/z5X+qlQeu7Z6+fP3v1/dd//fzEAu9ydJiHH5AYC+c6PnZusRg2aFkAH/L3kziIEMlLdJNQoAQpGQt6ICMDfX2BKLLgeti04x0O6cIGvDS/ZxDej/hcEgvwWhQbwD3GaI9x656uqbXyVpgnoX1xPs/jbiF0ZFs72PDyYD6DuCc2lUGEDZo3KbgchTjB0lFzbIqxRewuIYZd98iIM8Em0rlLnB4iVpMckEMjmjKhyyQGvyxsBMHfhm327jg9Rm3q+/jIRMLZQNSmElPDjJfQXKLYyhjFNI/cRTKykdxf8JFhcCHB0yGmzBmMsRA2mRt8YdC9BmnG7vY9uohNJJdkakPuIsbyyD6bBhGKZ1bOJIny2CtiCiGKnJtMWkkw84SoPvgBJYXuvkOw4e63n+3bkIbsAaJm5tx2JDAzz+OCThC2Ke/y2EixXU6s0dGbh0Zo72JM0TEaY+zcvmLDs5lh84z01QiyymVss81VZMaq6idYQK2kihuLY4kwQnYfh6yAz95iI/EsUBIjXqT5+tQMmQFcdbE1XuloaqRSwtWhtZO4IWJjf4Vab0bICCvVF/Z4XXDDf+9yxkDm3gfI4PeWgcT+zrY5QNRYIAuYAwRVhi3dgojh/kxEHSctNrfKTcxDm7mhvFH0xCR5awW0Ufv4H6/2gQrj1Q9PLdjTqXfswJNUOkXJZLO+KcJtVjUB42Py6Rc1fTRPbmK4RyzQs5rmrKb539c0Ref5rJI5q2TOKhm7yEeoZLLiRT8CWj3o0Vriwqc+E0LpvlxQvCt02SPg7I+HMKg7Wmj9kGkWQXO5nIELOdJthzP5BZHRfoRmsExVrxCKpepQODMmoHDSw1bdaoLO4z02Tker1dVzTRBAMhuHwms1DmWaTEcbzewB3lq97oX6QeuKgJJ9HxK5xUwSdQuJ5mrwLST0zk6FRdvCoqXUF7LQX0uvwOXkIPVI3PdSRhBuENJj5adUfuXdU/d0kTHNbdcs22srrqfjaYNELtxMErkwjODy2Bw+ZV+3M5ca9JQptmk0Wx/D1yqJbOQGmpg95xjOXN0HNSM067gT+MkEzXgG+oTKVIiGSccdyaWhPySzzLiQfSSiFKan0v3HRGLuUBJDrOfdQJOMW7XWVHv8RMm1K5+e5fRX3sl4MsEjWTCSdWEuVWKdPSFYddgcSO9H42PnkM75LQSG8ptVZcAxEXJtzTHhueDOrLiRrpZH0Xjfkh1RRGcRWt4o+WSewnV7TSe3D810c1dmf7mZw1A56cS37tuF1EQuaRZcIOrWtOePj3fJ51hled9glabuzVzXXuW6olvi5BdCjlq2mEFNMbZQy0ZNaqdYEOSWW4dm0R1x2rfBZtSqC2JVV+re1ottdngPIr8P1eqcSqGpwq8WjoLVK8k0E+jRVXa5L505Jx33QcXvekHND0qVlj8oeXWvUmr53Xqp6/v16sCvVvq92kMwioziqp+uPYQf+3SxfG+vx7fe3cerUvvciMVlpuvgshbW7+6rteJ39w4Byzxo1IbtervXKLXr3WHJ6/dapXbQ6JX6jaDZH/YDv9UePnSdIw32uvXAawxapUY1CEpeo6Lot9qlplerdb1mtzXwug+Xtoadr75X5tW8dv4FAAD//wMAUEsDBBQABgAIAAAAIQDlI7CA9QMAAKALAAARAAAAd29yZC9zZXR0aW5ncy54bWy0Vttu2zgQfV9g/8HQ8zq6WHZsoU4R3zYp4nZRebHPlETZRHgRSMqu8/U7pETLu3ELp0VeEmrOzJkh53DoDx+/MdrbY6mI4FMvvAm8Hua5KAjfTr2/N6v+2OspjXiBqOB46h2x8j7e/f7bh0OisNbgpnpAwVXC8qm307pKfF/lO8yQuhEV5gCWQjKk4VNufYbkc131c8EqpElGKNFHPwqCkdfSiKlXS560FH1GcimUKLUJSURZkhy3/1yEvCZvE7IQec0w1zajLzGFGgRXO1Ipx8Z+lg3AnSPZ/2gTe0ad3yEMrtjuQcjiFHFNeSagkiLHSkGDGHUFEt4ljl8RnXLfQO52i5YKwsPArs4rH76NIHpFMMrxt7dxjFsOHyLPeUjxNp7RiYd0BxuOfq6YMwKF30YxdHWoI+t2pOg1PW6gJ5JJJJsb1DaY5cnjlguJMgrlQKN70Kuerc78hS2bf3YJOe/gIr8IwXqHpMIyBzXDFAgCzzdABtXBaFiIz0KntZSi5sUDRmD7LrwSQrcwKFCUqUYa8iZbiRjc/amXU4x4Q1/gEtVUb1CWalGB0x7B1m+jNnu+QxLlwJZWKAcdzwXXUlDnV5i0c5gjEmTeRtipYla1wqvlEzqKWp8haTOxgIEjBofznym0FgWMFAiV5PoumgBbTTg8L+H/iQRMWEkKvDFNSfWR4hVsJiUv+J4Xn2qlCTDaWfQLFfyoAMxN5i8go82xwiuMdA3H9k7JbGdWlFRrAqKQj7wAWb1bMlKWWEICAkJbg5yIFAd7zo1S3ysvKOwfcIZbPNiATJ9nQmvBHo7VDs761zpp9e+fyxme50K5xVe4YifXYBEHw8WyqdSgHRJEo9FicAkJV9Eyvr+EjJfBfDW7hMxm0WB+ewmZx6NJNLmILMPJ+GIFCyhiPL+IfHc/q0kc39qe+KcTYYl5dv+SbmWuVY81EXPEMklQb20eZt94ZPJ5RrjDMwzzFJ8jaZ05sN9vAMUQpStosANsc1hSEFUtcGnXdI3ktuNtPeRFK8y8TycuM26x/BMGZ9WgB4mq5ro4lzCO20jC9RNhzq7qLHVRHF6AMwim8Je9tOfUHc8h0SA/O3aekJWx9cW8P/9shIeR0veKoKn3sjOmRvlUpka1eI2qqhF/tg2nHiXbnQ5NmIavAn7S2Y9sG7VYZLGowewHys1mwbtddLbI2c78Bs426Gyxs8Wdbehsw842craRse1g3ElK+DPcQ7c09lJQKg64eOjwVyb3SuUERJAeWdY9PjcNRomCwVDBO6WFdNgfFgvjpBD5o3ls48Y+nIwXy8mg0XY4tO+btrMDjvYrLmdI4aJRt/tpffcvAAAA//8DAFBLAwQUAAYACAAAACEAQMH/8TkBAAAjAwAAFAAAAHdvcmQvd2ViU2V0dGluZ3MueG1snNJfT8IwEADwdxO/w9J36CCykIVBYgzGF2OifoDS3aCx7S294sBP720CYnhhvvT//XLXdrbYOZt8QiCDvhCjYSoS8BpL49eFeH9bDqYioah8qSx6KMQeSCzmtzezJm9g9Qox8klKWPGUO12ITYx1LiXpDThFQ6zB82aFwanI07CWToWPbT3Q6GoVzcpYE/dynKaZODDhGgWrymh4QL114GMXLwNYFtHTxtR01JprtAZDWQfUQMT1OPvjOWX8iRndXUDO6ICEVRxyMYeMOorDR2k3cvYXmPQDxhdApmHXz5geDMmR544p+znZyTHlmfO/ZM4Agn7E5JgH7V1bkdP509pjUCvLEr9RwtecdHDbcrZt1w35+Jx/LdbROPMFSwz3ARuCINtlZS02L8+PPJF/vvb8GwAA//8DAFBLAwQUAAYACAAAACEAOdtFTLkFAAAnWgAAEgAAAHdvcmQvbnVtYmVyaW5nLnhtbOyczW7qRhiG95V6D8j7xP8/oEOOwECV6rQ60knV9WAGsGKPrbGB0FV7Ke266q430EvpDfQWOuOxzZ9DbIMw5MwmDuP5Xs/3zjfDk0nCh48vvtdaQhy5AeoK8r0ktCBygomLZl3hp6fRnSW0ohigCfACBLvCGkbCx4dvv/mw6qCFP4aYdGwRDRR1VqHTFeZxHHZEMXLm0AfRve86OIiCaXzvBL4YTKeuA8VVgCeiIslS8l2IAwdGEdGxAVqCSEjlnJdyahMMViSYCmqiMwc4hi8bDbmyiC62RetQSKkhRDJU5EMptbKUIdJRHQhptYTIqA6U9HpKBckZ9ZSUQyWznpJ6qGTVUzooJ/+wwIMQInJzGmAfxOQlnok+wM+L8I4IhyB2x67nxmuiKRmZDHDRc40RkahcwVcnlRVM0Q8m0FMnmUrQFRYYddL4uzyeDr3D4tNLFoHL5M9CBoGz8CGKk8xFDD3iRYCiuRvmK9yvq0ZuzjOR5bEklr6X9VuFcsnl8tr2NGBWbgTLDD/13/fYyI8rylKJGaESeUSZIew+MxuJT6pw8+Ba1myZK5fcQDIB5UDAcGDJDT/TsFIN0dmsUKrjllwamQ6bFarjboyVS+5j+4PZEohgNQk9G0e09rcyCmenle13OFiEGzX3NLXHzSa0ojxQQSst/+0lGZ02mC9zEJK9yXc6jzMUYDD2yIhIMbdIPbaSGaBfybTSS/ItfGnRjUB4IPwCxlGMgRP/uPBbO68eSQERDiIiHQwJ/GDayFCnN40h7mMInmkXqoIiKt9ZAo+0jJS+ItuKINI7/sKL3U9wCb2ndQizPkmrR1tZr9gPveyeatvSUJE0dsdb0hsuuWTPSsaSdZZZL0JhIz9vHC88D8Z5/BN8yW/9++sfefv3TtbqwWnaPfyM6cVFNB3a3BU0hdrQmQM0S3iQviZ9xbwzTi+jAMURNTFyXFJgP5PelCCjJLpHLNpvcxGRn8ApIG6wx4+Tr25uJWuNfskalCRfMX2mmKSx75J8ukv//F7VJEu7nEkbO2T9bTuU0+3477e/q/ohK8alDDmevnqO9P+snL5hXUf6bJM7Mf2/qqavyNJ1pK83UvyKfrEt83j6RiPFr7QvthkeT99spPhV9Uq2PquR4lfNxrY+cQfg6DOO0p1ch+4Uua1LumWw/KvTXbsvGX1LS+O3p+sMdJc+r/xkXRPblYEZznY7dnC2Oz19znbV0udsx9mOsx1nuwunX5HtlDpsp2rKSB5ItdlOaxu2aitWbms+Xfzk7kIndzXW9OXwjsMchzkOc4Xpc5hroPg5zHGYuwWYU2vBXNvWTcsasvyLYW6+HmN38sMRpDN7pqbpmpabm09a4l0cek5XsI2BNVRNu8Y0hl/itZeP55MbxZ8BBjMMwnnhPH8FJ3y5rZakS0N5dAZ2fl9nfrlBw/5Is4b9s7x5XDM4VrWI7hepRZImtSVJYlUFUQxidwnP9JPGLcPmvkHMsjMbdMs4um8QazmzQbcMrPsGXccSuyKk3TfoOpbYFUHvvkHXscRuB4vpLl4HiwdqXxqw/KufcQ7aQ0Oib/2ZrfmEvv8zTn6ayU8z+WkmP818M31+mtlA8fPTTH6aeQvYRjG3Mrbplq0aZttm+VfHNsM2FG3YTk9Dt6frDNhWY7FybOPYtsmeYxvHNo5tHNsaTZ9jWwPFfzvYRk+8K2ObOVBHqmFpLP/q2NYb9CRTVtL47el679jGIe317DmkNVD6HNI4pHFI45DWaPoc0o5DGv2te3VIG/ZNc9QbsPyrQxrZGwzLlL/Kf/vgZ2sc2zi2cWx7M32ObQ0UP8c2jm1Xgm0owTWUffIKbdphtywjNZVDBWHsDbQwLPmf3VfC2BtPYVj2x+RFYQefD7gJM4+EsY2uMEw7EsY2iMKw5JMEXwljC6swLJvrojBWkIVhGcYlYezKIPrhfwAAAP//AwBQSwMEFAAGAAgAAAAhAPiVyO/8DgAA85kAAA8AAAB3b3JkL3N0eWxlcy54bWzsXd9zo0YSfr+q+x8oPSUPG/+QLTtbcVJr2T67btdxVt5L3eMIRhZnYHSA1uv89TczDAjUDKKHjuu8m6RqLQH9MczXX890A5qffvkSR95nnmahSM5GBz/sjzye+CIIk4ez0af7qzenIy/LWRKwSCT8bPTMs9EvP//9bz89vc3y54hnngRIsrexfzZa5vnq7d5e5i95zLIfxIoncudCpDHL5df0YS9m6eN69cYX8Yrl4TyMwvx573B/fzIyMGkfFLFYhD6/EP465kmu7fdSHklEkWTLcJWVaE990J5EGqxS4fMskxcdRwVezMKkgjk4AkBx6KciE4v8B3kxpkUaSpof7OtPcbQBOMYBHAKAic+/4DBODcaetKzjhAEOZ1LhhEENx60xNYCM4yCOy3Zkz7G6oth/e/OQiJTNI4kkOfJkN3saWP0rW6v+6I/y8J+lwwbCv+ALto7yTH1N71Lz1XzTf65Ekmfe01uW+WF4L9slweNQnuf6XZKFI7mHsyx/l4WsvvPSbFP7l+rAVks/y2ubz8MgHO2pk2Z/yJ2fWXQ2Ojwqt0xVIxrbIpY8lNt48mZ6W2/M2eiPpdk0l7hnI5a+mb1Thnvm2oq/tSteVd+Ko7a6R+pJqmtWiFzu5Yv3wn/kwSyXO85G++pUcuOnm7s0FKkU8tnoxx/NxhmPw+swCHhSOzBZhgH/fcmTTxkPNtt/u9JiNBt8sU7k5/HJRFMWZcHlF5+vlLTl3oSp3rtVBpE6eh1uTq7N/1uCHZg+a7Nfcqbim3ewDaGbj4I4VBZZ7WrbMddb166PQp1o/FInOnqpEx2/1IkmL3Wik5c60elLnUjD/JknCpOAfymECE8DUHfhWNSIxrGIDY1j0RIaxyIVNI5FCWgci6OjcSx+jMaxuCkCJxe+zQtrzj62eHs37u4xwg1395Dghrt7BHDD3R3w3XB3x3c33N3h3A13d/R2w90drPG4xVTLu5EyS/LBKlsIkSci517OvwxHY4nE0kkfDZ4a9HhKcpEEMEVkMwPxYDSf6e+7PUSL1H08z1U25omFtwgf1inPBjecJ595JLN2jwWBxCMETHm+Ti094uLTKV/wlCc+p3RsOtAoTLiXrOM5gW+u2AMZFk8C4u4rEUmCQuXQbJ0vlUhCAqeOmZ+K4U0TjCw+vA+z4X2lQLzzdRRxIqxbGhfTWMNzAw0zPDXQMMMzAw0zPDGocUbVRQaNqKcMGlGHGTSifiv8k6rfDBpRvxk0on4zaMP77T7MIx3i67OOg/61u2kkVJl+cDtm4UPC5ARg+HBjaqbeHUvZQ8pWS0+VkNth69eMPc+5CJ69e4oxrUKimtdrF5nKqw6T9fAObaBRiavCI5JXhUcksApvuMQ+yGmymqBd0+Qzs/U8bxWtRuol2hmL1sWEdrjaWD7cwzYCuArTjEwG7bAEHnyrprOKTorIt2nl8IZtsIbLajsqkTbPQBK0MhL+I00Yvn5e8VSmZY+Dka5EFIknHtAhzvJUFL5Wl/yhpqSX5C/j1ZJloc6VGhD9h/ryBr/3ga0GX9BdxMKEhrfLNzELI49uBnF9/+G9dy9WKs1UHUMDeC7yXMRkmKYS+N3vfP49TQPfySQ4eSa62ndE5SENNg0JBpkCSQRESHKaGSYhyRiq8f7Jn+eCpQEN2l3Ki2dqck6EOGPxqph0EGhLxsUnGX8IZkMa718sDVVdiEpU9yRgtbJhtp7/h/vDQ92t8EgqQ7+uc11/1FNdbU0HN3ya0IAbPkXQbMrhQfkvwcU24IZfbAOO6mKnEcuy0HoL1RmP6nJLPOrrHZ78GTwRiXSxjug6sAQk68ESkKwLRbSOk4zyijUe4QVrPOrrJXQZjUdQktN4/0jDgIwMDUbFhAajokGDUXGgwUgJGP6ETg1s+GM6NbDhz+oUYERTgBoYlZ+RDv9Ed3lqYFR+psGo/EyDUfmZBqPys/GFxxcLOQmmG2JqkFQ+V4OkG2iSnMcrkbL0mQjyMuIPjKBAWqDdpWKhXrYQSfEQNwGkqlFHhJPtAo6K5N/5nKxpCouyXQQVURZFQhDV1jYDjrZsPru2y0y/czG4CXcR8/lSRAFPLddkt5X58mzFfFOmB7f7epU934cPy9ybLatqfx1msr/TskzYG2a7T9jW55PDDrMPPAjXcdlQ+DLFZNzfWHt0w7h856XDeDOTaFge97SE55zsttzMkhuWJz0t4TlPe1pqnTYsu/RwwdLHVkc46fKfKsezON9JlxdVxq2n7XKkyrLNBU+6vKghFe+d76u7BZCdfpqx2/cTj90eoyI7CkZOdpTeurJDdAnsI/8cqpEdEzT1+aqnJ0Dc15PoXpHzt7Uo6vaNG079X+q6kROnJONeK864/42rRpSx92PvcGOH6B137BC9A5AdolckspqjQpIdpXdsskP0DlJ2CHS0giMCLlpBe1y0gvYu0QqiuESrAbMAO0Tv6YAdAi1UCIEW6oCZgh0CJVRg7iRUiIIWKoRACxVCoIUKJ2A4oUJ7nFChvYtQIYqLUCEKWqgQAi1UCIEWKoRACxVCoIXqOLe3mjsJFaKghQoh0EKFEGih6vniAKFCe5xQob2LUCGKi1AhClqoEAItVAiBFiqEQAsVQqCFCiFQQgXmTkKFKGihQgi0UCEEWqjFq4buQoX2OKFCexehQhQXoUIUtFAhBFqoEAItVAiBFiqEQAsVQqCECsydhApR0EKFEGihQgi0UPXNwgFChfY4oUJ7F6FCFBehQhS0UCEEWqgQAi1UCIEWKoRACxVCoIQKzJ2EClHQQoUQaKFCiC7/NLcobY/ZH+CrntYn9vvfujKN+lh/lbsONe4PVbbKjtX/XYRzIR691hcPxzrf6AcSzqNQ6BK15bZ6HVc/EoG68fnrtPsNnzr6wB9dMu9C6HumAPyoryWoqRx1uXzdEiR5R12eXrcEs86jruhbtwTD4FFX0NW6LB9KkcMRMO4KMzXjA4t5V7SumcMu7orRNUPYw12RuWYIO7grHtcMjz0VnLetj3v206R6vhQgdLljDeHEjtDllpCrMhxDYfQlzY7Qlz07Ql8a7QgoPq0weGLtUGiG7VBuVEOZYal2F6odAUs1RHCiGsC4Uw2hnKmGUG5Uw8CIpRoiYKl2D852BCeqAYw71RDKmWoI5UY1HMqwVEMELNUQAUv1wAHZCuNONYRyphpCuVENJ3dYqiEClmqIgKUaIjhRDWDcqYZQzlRDKDeqQZaMphoiYKmGCFiqIYIT1QDGnWoI5Uw1hOqiWldRGlSjGK6Z4yZhNUPcgFwzxAXnmqFDtlSzdsyWagiO2RLkquQcly3VSbMj9GXPjtCXRjsCik8rDJ5YOxSaYTuUG9W4bKmNaneh2hGwVOOyJSvVuGypk2pcttRJNS5bslONy5baqMZlS21UuwdnO4IT1bhsqZNqXLbUSTUuW7JTjcuW2qjGZUttVOOypTaqBw7IVhh3qnHZUifVuGzJTjUuW2qjGpcttVGNy5baqMZlS1aqcdlSJ9W4bKmTaly2ZKcaly21UY3LltqoxmVLbVTjsiUr1bhsqZNqXLbUSTUuW/ogTUKCn4CaxSzNPbrfi7tm2TJnw3+c8FOS8kxEn3ng0V7qe9RV7j01lr9S2Hq1O3l8LvtM/QJ67XWloPgFWAOoD7wJqmWqlLFqiWeW7jKbdYPN7Vr9Oc1kTm2O2d8/Pz8cT43UVsXSZFnxZqk8Rv1a0dloPNGvJKkvH9dqDTS2zoVpvTbZM43Z0fyqweb+8wFo8mbBLN2eOZM99avqYXBBifqxxZbtysnK7eVppkuWFns37l8eYwRu75+Lo/3ji8tG/zxyvrqV59fb1BfJOc/0t03XzdXvlHG1qJoRvyh+/On956gCr/ehZWE4qcRyrTrv3+yaNxaGa92pV4Vr3eNnZ6P7MOaZd8ufvI8iZon3nemkzJvOvje9rv/1VfjYdIP6T2HodeV0aDkbqd+9N0xtFpYrb5TXF5Yb60hTWx/OxVsOrd5i4hiNtxz28JamlP9kB7L7TxlBvir/GZuJQ2NhQr1toP+Mrf5jHgqh8Z/x6/GfUpVfl/9QxJojq6+Y6EbjK0evx1e0Rv5ffSWcFhfk7DPlSDzEZ46tPmMeAKPxmePX4zNaK19DfBnoGcUKs22eYcY6Gs+YvB7P0Ir4yzMeTqyeYTIyGs84eT2eUc70vppxZqCHnFo9xBS3aDzk9PV4iFbGq4gdhyfq/3bPKDfeh2oV8gtDZiPp6ek+vmSO+eYnxy0VIrN0UPXbN3rhoG3HsqwvZHGKchJVlbnafcTe7lzVKTvarOuYnaWtotRp9VrjtrtaKNszjwonkh9uEuXET2aV96KlwRdWQMn9Ux5FH1hxtFjZD434QmlP7j3Y1780ubV/XiyaYLVPdXXdCrDXbEzxtdtPimUUw+K1D2slUZWQW7pbv4M0tKd7+rC/zmTXzNQB2+1rVPS2W2l2egfeJphtRcdWHdhiovFwazy0B7y/KnlIQouim43QQyJCTZ3wmyV0SGkNSWhRBbMROiYi1BTuvl1C/xw1FmUpG3lHROSZ6PLqyXup4hOSxKJOZCPxmIhEU9r6phRITlVRuLFRNSGiygT/v6gaQlVRSbFRdUJElSn+fJOhkZyyorRho+yUiDKTwH9d6nqZAkaj/tXBp17ibptHvbGNvX5Pv5xe7k+vzoujTEFpdR7U0nt9nFoI2qyb9oe6raE+rJhftlD32eapmCr532GrPwPbqjDgdOaybOBwalVSM5eeLasu8iPOCqHVjpZfF2Ek916eXE4u9YNl2heu9MY58x8fUrFOgn43mKciyUTE9O+BbFx8FsaztX4oy3h2/bBWl9aLsFbuHDFdT9QXwZM3n2a0weUmUWXJVpes7cKFFWuRrZ//EnVv0eagCgKJSCof0mHb+JD+DByQ1HVoWNwMCNVTiNuUbfYMZayshbWUGZvMTS8Pfjw1CaxhrjlMHk/G002YNbF32WzoujzaSH1A52weiCyfh9zupJZHJql6a3eNFtd5k/3jy+Mp1iMPLq4uLhzGrKoPVZF08/vy2/2nn87d7G7ru/qgBXtrbFJm1F2XZB0XH8Jo68kfve+msi5Ha2MAwnZPKZafsp//BwAA//8DAFBLAwQUAAYACAAAACEAzJJQVH0BAADxAgAAEQAIAWRvY1Byb3BzL2NvcmUueG1sIKIEASigAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAjJLLTsMwEEX3SPxD5H1qJ+WlKE3FQ6yoQKIViJ2xJ60hsS17IPTvcZI2JYgFO4/n+GRy7Xz+VVfRJzivjJ6RZMJIBFoYqfR6RlbL2/iCRB65lrwyGmZkC57Mi+OjXNhMGAcPzlhwqMBHwaR9JuyMbBBtRqkXG6i5nwRCh2ZpXM0xlG5NLRfvfA00ZeyM1oBccuS0FcZ2MJKdUopBaT9c1QmkoFBBDRo9TSYJPbAIrvZ/Hug6P8ha4dbCn+i+OdBfXg1g0zSTZtqhYf6EPi/uHrtfjZVusxJAilyKDBVWUOT0sAwr//H6BgL77aEIa+GAo3HFQglnvCkxui9LJSBaeXAdvSfa7N9h2xgnffCMqoBJ8MIpi+FG+6+MNgJdcY+LcMWlAnm1LS5Pz9OzTvOr0bIOPlX7NoqkI4Yy3wXdDwUyCgFlfZz7ztP0+mZ5S4qUpUnMTuIpW7I0O00zxl7auUbnD8J6N8A/jdOMnYyNe0EfzfiRFt8AAAD//wMAUEsDBBQABgAIAAAAIQAiURHx1QEAAN4DAAAQAAgBZG9jUHJvcHMvYXBwLnhtbCCiBAEooAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJxTwW7bMAy9D9g/GLo3crKh6AJFxZBi6GFDA8Rtz5xMJ8JsSZDYINnXj7YTT9l2mk/vkfTTE0mp+2PXFgeMyXq3EvNZKQp0xtfW7VbiufpycyeKROBqaL3DlThhEvf6/Tu1iT5gJIupYAmXVmJPFJZSJrPHDtKM044zjY8dENO4k75prMEHb946dCQXZXkr8UjoaqxvwiQoRsXlgf5XtPam95deqlNgPa0q7EILhJrOYFZ7Oio5xVXlCdrKdqjnJccnpjaww6TnSo5AvfpYJ724U3JEar2HCIa4h3p++0HJjKvPIbTWAHF39Tdrok++oeJpsFz0/yuZlyi+xhbNW7R00mwjp+qrdaOREbCxCLsIYX92NzG1NdDimhugG2gTKvk7oB4R+uFuwPb+DrQ8oCEfi2R/8ngXovgOCfu2rcQBogVHYiwbyYDbkCjqylLL2hMfYF6WY/uxNzmC68KBDB4YX7sbTkhPDd+N/mF2npsdPIxWMzu5s8sZf6iufRfAcX/lhLjBP9JzqPxDvxrnHl4Hs6m/WtpvA5h+OJ/KfP5ZRm05ijUPdJrJFFCPfIPY9vr8r9thfan5O9Fv1Mv4XHnbZiV/wwpdYrwI0zvSvwAAAP//AwBQSwMEFAAGAAgAAAAhAIg/pb/hAAAAVQEAABgAKABjdXN0b21YbWwvaXRlbVByb3BzMS54bWwgoiQAKKAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAnJDBasMwEETvhf6D2bsiObFdEyyHuE4g19JCroq8tgWWZCS5tJT+e2V6So89LbPDzhu2OnzoKXlH55U1HNINgwSNtJ0yA4e31zMpIfFBmE5M1iAHY+FQPz5Und93IggfrMNLQJ3EhYrz0nL4ykvW5E87Rsr2nJLilDXkmKUNKTKWt8fnU8pY8Q1JRJsY4zmMIcx7Sr0cUQu/sTOaaPbWaRGidAO1fa8ktlYuGk2g25hA5RLx+qonqNc+v9cv2Pt7uVZbnPov5aZuk7KDE/P4CbSu6B/Uqu9eUf8AAAD//wMAUEsDBBQABgAIAAAAIQDBJ8sItgAAACEBAAATACgAY3VzdG9tWG1sL2l0ZW0xLnhtbCCiJAAooCAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACskE0OgjAQRq9CegCKLlgQfmKiWzEhcV/KAE3aGdIOBm5v1egJXE7mfS/zTdlsziYP8MEQVuKQZiIJrHBQlhAqgSSauuyLjlavISSRxlD0lZiZl0LKoGdwKqS0AMbdSN4pjqOfJI2j0XAmvTpAlscsy2Vvemto8mqZd/GR/UfVgQXNMHS823i2PN1Ondl4vgyGY7P2LWjRGoR0CzYGXuBVuQhHViT37wtyUZfyV7h+AgAA//8DAFBLAwQUAAYACAAAACEAdD85esIAAAAoAQAAHgAIAWN1c3RvbVhtbC9fcmVscy9pdGVtMS54bWwucmVscyCiBAEooAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIzPsYrDMAwG4P3g3sFob5zcUMoRp0spdDtKDroaR0lMY8tYamnfvuamK3ToKIn/+1G7vYVFXTGzp2igqWpQGB0NPk4Gfvv9agOKxcbBLhTRwB0Ztt3nR3vExUoJ8ewTq6JENjCLpG+t2c0YLFeUMJbLSDlYKWOedLLubCfUX3W91vm/Ad2TqQ6DgXwYGlD9PeE7No2jd7gjdwkY5UWFdhcWCqew/GQqjaq3eUIx4AXD36qpigm6a/XTf90DAAD//wMAUEsDBBQABgAIAAAAIQDrgGBMUwMAAI8OAAASAAAAd29yZC9mb250VGFibGUueG1szJbPb9MwFMfvSPwPUU7jwJqkXZdV66Y2WzQk2IEVAUc3cVqL2I7itF3/AA6IE+LI38C4gwb/DNPYf8FznLRZm25LQbBGzY9n+5vnT57f8+7+KQ21MY4F4aytm5uGrmHmcZ+wQVt/0XMf27omEsR8FHKG2/oUC31/7+GD3Ukr4CwRGoxnokW9tj5MkqhVqwlviCkSmzzCDBoDHlOUwGM8qFEUvxlFjz1OI5SQPglJMq1ZhtHUM5n4Lio8CIiHD7g3opgl6fhajENQ5EwMSSRytcld1CY89qOYe1gImDMNlR5FhM1kzMaSECVezAUPkk2YTOZRKgXDTSO9o+FcYKuagLUk0PTwaTUNO9OowciiDvGr6TRnOsQv6KznTEFA4GoSW7kfYkrljKjXejJgPEb9EJTgG2mAWUuF5Rm8lZf0FrrvZfGqTVoMURjwEj62DHKRNkWIcYFNaB2jsK0bW8bST6/Jjt4QxQJLmbRj40CZA0RJOM2tPvbAr4SMsWqNSOIN88Yxion0WTUJMoCGkegb8Fb1q+vKYsJyzN+tLNasT26pX7d4qY6tDGZmMQt94J01BWIJSI9QLLRjPNGec4pYKRYLjqZRBzwN+Ftw1yjFktO6jiVOdasQgaVoWB17e04km9syEfsmIoqH61Yj4qCQ9GOygoSbEpBHAzhYlUiICRGiEomOdNY6TGegSDSkwdjuVosN9bxTkcQBZoNXJAsKFCbHYM19vvz87vLrj2wyS5RMiBcIabhmRyklu1lGCY0SvgakbgFS3XbcbcftLEIym7dAknQrQnqWZy/tNTrCKmwWWF18P/t1/uXq09urbx9WEetCXMl4knGVnisQqx5X6XqyiivM6jhu3dmy1kFmVkS2kHO0jSOM0qSsOSePygAuJqmVDJsZvWyF/oUs5eMAjcLkxoQB+w8eovKSorzaWTNjUO7juMytgJxif/m7HsrSYamMN88XrjOzzPPFzu2Zs2q+OCH0ZFSaLS7O3v88/3gvskU2j0K5tWzbzadfOVv8WbnVNrrcn96PsGc86cUj3JtGeK1lkFcL7SkZDJPVNSNrvw+x8H8rR7bRKPAq226oovBvthuHEkenmD4caWmUbDfukD5u3XhlN2LvNwAAAP//AwBQSwECLQAUAAYACAAAACEAZPVj7oEBAAApBgAAEwAAAAAAAAAAAAAAAAAAAAAAW0NvbnRlbnRfVHlwZXNdLnhtbFBLAQItABQABgAIAAAAIQAekRq37wAAAE4CAAALAAAAAAAAAAAAAAAAALoDAABfcmVscy8ucmVsc1BLAQItABQABgAIAAAAIQAzwlu/QQEAAOcEAAAcAAAAAAAAAAAAAAAAANoGAAB3b3JkL19yZWxzL2RvY3VtZW50LnhtbC5yZWxzUEsBAi0AFAAGAAgAAAAhAE4yjpAWBgAApiQAABEAAAAAAAAAAAAAAAAAXQkAAHdvcmQvZG9jdW1lbnQueG1sUEsBAi0AFAAGAAgAAAAhALb0Z5jSBgAAySAAABUAAAAAAAAAAAAAAAAAog8AAHdvcmQvdGhlbWUvdGhlbWUxLnhtbFBLAQItABQABgAIAAAAIQDlI7CA9QMAAKALAAARAAAAAAAAAAAAAAAAAKcWAAB3b3JkL3NldHRpbmdzLnhtbFBLAQItABQABgAIAAAAIQBAwf/xOQEAACMDAAAUAAAAAAAAAAAAAAAAAMsaAAB3b3JkL3dlYlNldHRpbmdzLnhtbFBLAQItABQABgAIAAAAIQA520VMuQUAACdaAAASAAAAAAAAAAAAAAAAADYcAAB3b3JkL251bWJlcmluZy54bWxQSwECLQAUAAYACAAAACEA+JXI7/wOAADzmQAADwAAAAAAAAAAAAAAAAAfIgAAd29yZC9zdHlsZXMueG1sUEsBAi0AFAAGAAgAAAAhAMySUFR9AQAA8QIAABEAAAAAAAAAAAAAAAAASDEAAGRvY1Byb3BzL2NvcmUueG1sUEsBAi0AFAAGAAgAAAAhACJREfHVAQAA3gMAABAAAAAAAAAAAAAAAAAA/DMAAGRvY1Byb3BzL2FwcC54bWxQSwECLQAUAAYACAAAACEAiD+lv+EAAABVAQAAGAAAAAAAAAAAAAAAAAAHNwAAY3VzdG9tWG1sL2l0ZW1Qcm9wczEueG1sUEsBAi0AFAAGAAgAAAAhAMEnywi2AAAAIQEAABMAAAAAAAAAAAAAAAAARjgAAGN1c3RvbVhtbC9pdGVtMS54bWxQSwECLQAUAAYACAAAACEAdD85esIAAAAoAQAAHgAAAAAAAAAAAAAAAABVOQAAY3VzdG9tWG1sL19yZWxzL2l0ZW0xLnhtbC5yZWxzUEsBAi0AFAAGAAgAAAAhAOuAYExTAwAAjw4AABIAAAAAAAAAAAAAAAAAWzsAAHdvcmQvZm9udFRhYmxlLnhtbFBLBQYAAAAADwAPANQDAADePgAAAAA=",rZ=()=>Im(oZ);async function iZ(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 Ik(n,t){if(n.width&&n.height)return{width:n.width,height:n.height,buffer:t};const e=await jl(new File([t],"",{})),o=await iZ(e);return o.width===void 0||o.height===void 0?{width:345,height:230,buffer:t}:n.width||n.height?{width:n.width||o.width*n.height/o.height,height:n.height||o.height*n.width/o.width,buffer:t}:{width:o.width,height:o.height,buffer:t}}function sZ(n,t){let e=n.filter(s=>s!=null);const o=t-(e.length-1)*20,r=.87,i=e.reduce((s,l)=>s+l.width,0);return i>o&&(e=e.map(s=>({width:s.width*o/i,height:s.height*o/i,buffer:s.buffer}))),e.map(s=>({width:s.width*r,height:s.height*r,buffer:s.buffer}))}function Tk(n=[0,1,2,3,4,5,6,7],t=1){return n.map(e=>{let o;switch(e%3){case 0:o=gt.LevelFormat.DECIMAL;break;case 1:o=gt.LevelFormat.LOWER_LETTER;break;default:o=gt.LevelFormat.LOWER_ROMAN;break}return{level:e,format:o,text:`%${e+1}. `,alignment:gt.AlignmentType.START,start:t,style:{paragraph:{indent:{left:gt.convertInchesToTwip(.3*(e+1)),hanging:gt.convertInchesToTwip(.2)}}}}})}function lZ(){return[0,1,2,3,4,5,6,7].map(n=>{let t;switch(n%3){case 0:t="\u2022";break;case 1:t="\u25E6";break;default:t="\u25AA";break}return{level:n,format:gt.LevelFormat.BULLET,text:t,alignment:gt.AlignmentType.START,style:{paragraph:{indent:{left:gt.convertInchesToTwip(.3*(n+1)),hanging:gt.convertInchesToTwip(.2)}}}}})}function cZ(){return[0,1,2,3,4,5,6,7].map(n=>({level:n,format:gt.LevelFormat.BULLET,text:"\u2611",alignment:gt.AlignmentType.START,style:{paragraph:{indent:{left:gt.convertInchesToTwip(.3*(n+1)),hanging:gt.convertInchesToTwip(.2)}}}}))}function aZ(){return[0,1,2,3,4,5,6,7].map(n=>({level:n,format:gt.LevelFormat.BULLET,text:"\u2610",alignment:gt.AlignmentType.START,style:{paragraph:{indent:{left:gt.convertInchesToTwip(.3*(n+1)),hanging:gt.convertInchesToTwip(.2)}}}}))}var Hu=(n=>(n.NUMBERING="number-numbering-reference",n.BULLET="number-bullet-reference",n.CHECKED="checked-bullet-reference",n.UNCHECKED="unchecked-bullet-reference",n))(Hu||{});const uZ=[{levels:Tk(),reference:"number-numbering-reference"},{levels:lZ(),reference:"number-bullet-reference"},{levels:cZ(),reference:"checked-bullet-reference"},{levels:aZ(),reference:"unchecked-bullet-reference"}];function dZ(n){switch(n){case"style-color-0":return"d83931";case"style-color-1":return"de7802";case"style-color-2":return"dc9b04";case"style-color-3":return"2ea121";case"style-color-4":return"245bdb";case"style-color-5":return"6425d0";case"style-color-6":return"8f959e";default:return}}function hZ(n){switch(n){case"style-bg-color-1":case"style-bg-color-2":case"style-bg-color-8":case"style-bg-color-9":return"yellow";case"style-bg-color-0":case"style-bg-color-5":return"magenta";case"style-bg-color-3":return"green";case"style-bg-color-4":case"style-bg-color-11":return"blue";case"style-bg-color-6":return"lightGray";case"style-bg-color-7":return"red";case"style-bg-color-10":return"darkGreen";case"style-bg-color-12":return"darkMagenta";case"style-bg-color-13":return"darkGray";default:return}}function fZ(n){switch(n){case"style-bg-color-0":return"fbbab6";case"style-bg-color-1":return"ffdcb0";case"style-bg-color-2":return"fff7a0";case"style-bg-color-3":return"ceefc5";case"style-bg-color-4":return"d1ddfb";case"style-bg-color-5":return"d9cbf8";case"style-bg-color-6":return"eaeaea";case"style-bg-color-7":return"fe837c";case"style-bg-color-8":return"ffbd6a";case"style-bg-color-9":return"ffe662";case"style-bg-color-10":return"a8f393";case"style-bg-color-11":return"98b5ff";case"style-bg-color-12":return"b394f8";case"style-bg-color-13":return"b1b1b1";default:return}}const mZ=/rgb\((\d+),\s*(\d+),\s*(\d+)\)/;function Dk(n){if(typeof n=="string"&&n.length>0){if(n[0]==="#")return n.substring(1);const t=n.match(mZ);if(t){const e=s=>{let l=Number(s).toString(16);return l.length<2&&(l=`0${l}`),l},o=e(t[1]),r=e(t[2]),i=e(t[3]);return`${o}${r}${i}`}if(n==="red")return"FF0000";if(n==="green")return"00FF00";if(n==="blue")return"0000FF"}}function tn(n,t){if(n&&n.attributes&&n.attributes[t])return n.attributes[t];if(n&&n.attributes&&n.attributes.box&&n.attributes.inputType&&t==="style-underline")return!0}function Sk(n,t,e){for(let o=0;o<=e;++o){const r=`${t}${o}`;if(tn(n,r))return r}}function r1(n,t,e){n.attributes=n.attributes||{},n.attributes[t]=e}function Q2(n){return n==="image"||n==="drawio"||n==="plantuml"||n==="mermaid"||n==="flowchart"}function Lk(n){return n&&n.startsWith("//")?`https:${n}`:n&&!n.startsWith("http://")&&!n.startsWith("https://")?`https://${n}`:n}function gZ(n){const t=tn(n,"inlineStyle");if(t==null)return;const e=t.split(";");for(const o of e){const r=o.split(":");if(r.length!==2)continue;const i=r[0].trim().toLowerCase(),s=r[1].trim().toLowerCase();i==="font-size"&&r1(n,"inline-style-font-size",s),i==="color"&&r1(n,"inline-style-color",s),i==="background-color"&&r1(n,"inline-style-background-color",s),i==="font-family"&&r1(n,"inline-style-font-family",s)}}function pZ(n,t){if(t==null)return n==null?void 0:n.normal;if(n)return n[`heading${t}`]}function CZ(n){const t=`${tn(n,"inline-style-font-size")}`;if(t&&t.indexOf("px")>0)return+t.replace(/px/g,"")}function AZ(n){if(n.attributes&&n.attributes.box&&n.attributes.text)return` ${n.attributes.text} `;if(n.attributes&&n.attributes.box&&n.attributes.inputType)return n.attributes.value?`${n.attributes.value}`:" "}function bZ(n){if(n.attributes&&n.attributes.box&&n.attributes.text)return` @${n.attributes.text} `}function vZ(n){return tn(n,"inline-style-font-family")}function yZ(n){const t=tn(n,"inline-style-background-color");return Dk(t)}function kZ(n){const t=tn(n,"inline-style-color");return Dk(t)}function wZ(n){gZ(n);const t=tn(n,"type")==="mention";return{box:n.attributes&&n.attributes.box?n.attributes:void 0,inlineCode:!!tn(n,"style-code"),link:Lk(tn(n,"link")),size:CZ(n),text:t?bZ(n):AZ(n)||n.insert,bold:!!tn(n,"style-bold"),underline:!!tn(n,"style-underline"),italics:!!tn(n,"style-italic"),strike:!!tn(n,"style-strikethrough"),superScript:!!tn(n,"style-super"),subScript:!!tn(n,"style-sub"),math:tn(n,"type")==="math"?tn(n,"src"):void 0,mention:t,fontFamily:vZ(n),background:yZ(n),color:t?"338fe5":dZ(Sk(n,"style-color-",6))||kZ(n),highlight:Sk(n,"style-bg-color-",13)}}function BZ(){return[new gt.Paragraph({border:{top:{color:"auto",style:gt.BorderStyle.DASHED,size:4,space:1}},spacing:{before:300}}),new gt.Paragraph({spacing:{line:0}})]}function EZ(){return new gt.Paragraph({children:[new gt.TextRun({text:"[\u89C6\u9891\u6682\u4E0D\u652F\u6301\u5BFC\u51FA]",shading:{type:gt.ShadingType.CLEAR,color:"FFFFFF",fill:"CCCCCC"}})]})}function xZ(){return new gt.Paragraph({children:[new gt.TextRun({text:"[\u97F3\u9891\u6682\u4E0D\u652F\u6301\u5BFC\u51FA]",shading:{type:gt.ShadingType.CLEAR,color:"FFFFFF",fill:"CCCCCC"}})]})}function IZ(n,t){return new gt.Paragraph({children:[new gt.ExternalHyperlink({children:[new gt.TextRun({style:"Hyperlink",text:t||n})],link:n})]})}function Mk(n){if(n.heading!=null)return`Heading${n.heading}`}function Rk(n){if(n.alignment!=null){if(n.alignment==="center")return gt.AlignmentType.CENTER;if(n.alignment==="right")return gt.AlignmentType.RIGHT;if(n.alignment==="left")return gt.AlignmentType.LEFT}}function TZ(n){if(n.indent)return{left:gt.convertInchesToTwip(.3*n.indent-.2)};if(n.padding)return{left:gt.convertInchesToTwip(.3*n.padding)}}function DZ(n){return{type:gt.ShadingType.CLEAR,color:"FFFFFF",fill:n}}function SZ(n){const t=n.split(",");if(t.length!==0)return t[0].trim()}function Ok(n,t){let e;e=n.inlineCode?"InlineCode":void 0,e=n.link?"Hyperlink":e;const o=n.size||t,r=o!=null?Math.floor(o*1.5+.5):void 0;return new gt.TextRun({text:n.text,bold:n.bold||void 0,underline:n.underline?{type:gt.UnderlineType.SINGLE}:void 0,italics:n.italics||void 0,strike:n.strike||void 0,superScript:n.superScript||void 0,subScript:n.subScript||void 0,size:r,style:e,font:n.fontFamily?SZ(n.fontFamily):void 0,shading:n.background?DZ(n.background):void 0,color:n.color,highlight:hZ(n.highlight)})}function LZ(n,t){if(n.link)return new gt.ExternalHyperlink({children:[Ok(n,t)],link:n.link})}async function _k(n,t,e,o,r){const i=await r(n,t,e);if(i==null)return;const s=await Ik({width:o||0,height:0,src:e},i);return new gt.ImageRun({data:i,transformation:{width:s.width||100,height:s.height||20}})}function MZ(n){if(n.heading||n.heading)return n.heading}function RZ(n){if(n.align&&(n.align==="center"||n.align==="right"||n.align==="left"))return n.align}function OZ(n){if(n.textOnly===!0&&n.level!=null)return n.level}async function _Z(n,t){var o;const e=[];if(n.text&&Array.isArray(n.text)){for(let r=0;r<n.text.length;r++){const i=n.text[r];if(((o=i.attributes)==null?void 0:o.box)===!0&&t){const s=await t(i);if(s){n.text.splice(r+1,0,...s);continue}}e.push(wZ(i))}return e}}function FZ(n){if(n.type==="list"&&n.textOnly!==!0)return{checkbox:n.checkbox,groupId:n.groupId,ordered:!!n.ordered,level:n.level||1,start:n.start||0}}function PZ(n,t){if(n.type==="embed"&&n.embedType&&Q2(n.embedType)&&n.embedData&&n.embedData.src)return n.embedData.src.split("|").map(o=>{const r=t(o),i=n.embedData[`${r}_width`],s=n.embedData[`${r}_height`];return{src:o,width:i,height:s}})}function NZ(n){if(n.padding)return n.padding}function $Z(n){return!!(n.type==="embed"&&n.embedType&&Q2(n.embedType)&&n.embedData&&n.embedData.src)}async function i1(n,t,e){return{quoted:!!n.quoted,heading:MZ(n),alignment:RZ(n),indent:OZ(n),padding:NZ(n),texts:await _Z(n,e),list:FZ(n),images:PZ(n,t),border:$Z(n)}}async function HZ(n,t,e,o){const r=[];if(!n.children)return[];for(const i of n.children){const s=[];for(const l of t.blocks[i])s.push(await i1(l,e,o));r.push(s)}return r}const jZ=S("to-docx");function UZ(n,t){return Array(n).fill(0).map(()=>Array(t).fill(0).map(()=>({cellId:void 0,color:void 0,from:void 0,rowSpan:1,colSpan:1,width:0,originalWidth:void 0,align:void 0})))}function zZ(n,t,e,o){const r=!!n.hasColTitle,i=!!n.hasRowTitle,s=!!n.isStripeStyle,l="F5F8FB";for(let a=0;a<t;a++)for(let d=0;d<e;d++)(r&&d===0||i&&a===0||s&&a%2===1)&&(o[a][d].color=l)}function VZ(n){g(jZ,n.children,"no table children");const t=n.rows,e=n.cols,o=n.colsWidth;if(o)for(let s=0;s<o.length;s++)o[s]===0&&(o[s]=100);const r=UZ(t,e);let i=0;for(let s=0;s<t;++s)for(let l=0;l<e;++l){if(r[s][l].originalWidth=o?o[l]:void 0,r[s][l].from!==void 0)continue;const a=n.children[i];i+=1,r[s][l].cellId=a,r[s][l].color=fZ(n[`${a}_background`]),r[s][l].width=o?o[l]:100,r[s][l].align=n[`${a}_align`];const d=n[`${a}_rowSpan`]||1,h=n[`${a}_colSpan`]||1;if(r[s][l].rowSpan=d,r[s][l].colSpan=h,d>1||h>1){let p=0;for(let A=0;A<d;A++)for(let v=0;v<h;v++)A===0&&(p+=o?o[l+v]:80),!(A===0&&v===0)&&(r[s+A][l+v].from=[s,l]);r[s][l].width=p}}return zZ(n,t,e,r),r}async function WZ(n,t,e,o,r,i,s,l,a,d){async function h(v){if(l){const B=await l(r,i,v);if(B){await o.addDoc(n,B,d);return}}if(v.type==="text"||v.textOnly===!0){const B=await i1(v,s,a);await o.addTextBlock(B);return}if(v.type==="code"){const B=await HZ(v,e,s,a);await o.addCodeBlockObject(B);return}if(v.type==="list"&&v.textOnly!==!0){const B=await i1(v,s,a);await o.addListBlockObject(n,B);return}if(v.type==="embed"&&v.embedType){const B=v,D=B.embedData,x=B.embedType;if(Q2(x)){const _=await i1(v,s,a);await o.addImagesBlockObject(v,_,d)}else v.embedType==="hr"?o.addSeparatorBlock():v.embedType==="video"?o.addVideoPlaceholder():v.embedType==="audio"?o.addAudioPlaceholder():v.embedType==="webpage"?o.addHyperlinkParagraph(Lk(D.src),D.title):o.addOtherEmbedBlock(x,v.embedData);return}if(v.type==="table"){let B=[];if(v.colsWidth)B=v.colsWidth;else{const x=v.cols;B=new Array(x);for(let _=0;_<B.length;_++)B[_]=100;v.colsWidth=B}const D=VZ(v);await o.addTableMatrix(B,D,e),o.addEmptyParagraph()}}function p(v){const B=[];for(const{type:D,data:x}of v.embedData.exportSpec){if(D==="text"){const _={id:K(),text:[{insert:x}],type:"text"};B.push(_);continue}if(D==="image"){const _={id:K(),type:"embed",embedType:"image",align:"left",embedData:{src:x}};B.push(_);continue}if(D==="link"){const _={id:K(),type:"embed",embedType:"webpage",embedData:{src:x.url,title:x.title}};B.push(_);continue}}return B}function A(v){var B;return(B=v==null?void 0:v.embedData)!=null&&B.exportSpec?p(v):[v]}for(const v of t)for(const B of A(v))await h(B)}function qZ(){return{listMaxInst:1,listInstMap:{},listRefMap:{},levelConfigs:[]}}const GZ=S("to-docx");class ZZ{constructor(t,e,o,r,i,s){m(this,"paragraphs");this.appId=t,this.docId=e,this.state=o,this.readImageFunc=r,this.convertBlocksFunc=i,this.defaultFontSize=s,this.paragraphs=[]}async addTextBlock(t){this.paragraphs.push(new gt.Paragraph({heading:Mk(t),alignment:Rk(t),children:await this.paragraphsFromBlockTexts(t),indent:TZ(t)}))}async addEmptyImagePlaceHolder(){this.paragraphs.push(new gt.Paragraph({text:`[${R.t("docx.imageExportFailed")}]`,shading:{type:gt.ShadingType.CLEAR,color:"FFFFFF",fill:"CCCCCC"}}))}async paragraphsFromBlockTexts(t){if(t.texts==null)return;const e=pZ(this.defaultFontSize,t.heading),o=[];for(const r of t.texts){if(r.link){const i=LZ(r,e);i&&o.push(i);continue}if(r.box&&r.box.type&&r.box.type==="br"){o.push(new gt.TextRun({text:"",break:1}));continue}if(r.box&&r.box.type&&r.box.type==="image"){const i=await _k(this.appId,this.docId,r.box.src,r.box.width,this.readImageFunc);i&&o.push(i);continue}if(r.math){const i=await _k(this.appId,this.docId,r.math,0,this.readImageFunc);i&&o.push(i);continue}o.push(Ok(r,e))}return o}async addCodeBlockObject(t){for(const e of t)for(const o of e){const r={style:gt.BorderStyle.SINGLE,color:"#DEDEDE"};this.paragraphs.push(new gt.Paragraph({style:"Code",border:{left:{...r},right:{...r},top:{...r},bottom:{...r}},children:await this.paragraphsFromBlockTexts(o)}))}}async addListBlockObject(t,e){if(e.list==null)return;let o;const r=e.list.checkbox?`${t}-${e.list.groupId}-${e.list.checkbox}`:`${t}-${e.list.groupId}`;if(this.state.listInstMap[r])o=this.state.listInstMap[r];else if(o=this.state.listMaxInst,this.state.listMaxInst+=1,this.state.listInstMap[r]=o,e.list.start>0&&e.list.ordered){const s=`number-numbering-reference-${o}`,l=Tk([e.list.level-1],e.list.start);this.state.levelConfigs.push({levels:l,reference:s,inst:o}),this.state.listRefMap[r]=s}else e.list.ordered?this.state.listRefMap[r]=Hu.NUMBERING:e.list.checkbox&&e.list.checkbox==="checked"?this.state.listRefMap[r]=Hu.CHECKED:e.list.checkbox&&e.list.checkbox==="unchecked"?this.state.listRefMap[r]=Hu.UNCHECKED:this.state.listRefMap[r]=Hu.BULLET;const i=Mk(e);e.texts&&this.paragraphs.push(new gt.Paragraph({heading:i,children:await this.paragraphsFromBlockTexts(e),numbering:{reference:this.state.listRefMap[r],level:e.list.level-1,instance:o}}))}imageDimWithBufferToImageRun(t){return new gt.ImageRun({data:t.buffer,transformation:{width:t.width,height:t.height}})}async addImagesBlockObject(t,e,o){if(e.images==null){if(t.type==="embed"&&t.embedType==="image"){const{src:a}=t.embedData;a||this.addEmptyImagePlaceHolder()}return}const r=[],i=await Promise.all(e.images.map(async a=>{const d=await this.readImageFunc(this.appId,this.docId,a.src);if(d)return Ik(a,d);r.push(a.src)})),s=sZ(i,o),l={style:gt.BorderStyle.SINGLE,color:"#DEDEDE"};s.length&&this.paragraphs.push(new gt.Paragraph({border:e.border?{left:{...l},right:{...l},top:{...l},bottom:{...l}}:void 0,alignment:Rk(e)||gt.AlignmentType.CENTER,children:s.map(a=>this.imageDimWithBufferToImageRun(a)).flatMap((a,d,h)=>a==null?[]:h.length-1!==d?[a,new gt.TextRun({text:" "})]:a)})),r.forEach(a=>{this.addHyperlinkParagraph(a)})}addSeparatorBlock(){BZ().forEach(t=>this.paragraphs.push(t))}addEmptyParagraph(){this.paragraphs.push(new gt.Paragraph(""))}addVideoPlaceholder(){this.paragraphs.push(EZ())}addAudioPlaceholder(){this.paragraphs.push(xZ())}addHyperlinkParagraph(t,e){t!=null&&this.paragraphs.push(IZ(t,e))}async addTableMatrix(t,e,o){const r=t.map(i=>i!==0?i*15:1500);this.paragraphs.push(new gt.Table({rows:await this.generateTableRows(e,o),columnWidths:r}))}async generateRowCells(t,e){const o=[];for(const r of t){const i=r.cellId;if(i===void 0)continue;const s=r.width*.9;o.push(new gt.TableCell({children:await this.convertBlocksFunc(i,e.blocks[i],e,this.appId,this.docId,this.state,s),columnSpan:r.colSpan,rowSpan:r.rowSpan,width:{type:gt.WidthType.DXA,size:r.width*15},shading:r.color?{fill:r.color,type:gt.ShadingType.CLEAR,color:"auto"}:void 0}))}return o}async generateTableRows(t,e){const o=[];for(const r of t)o.push(new gt.TableRow({children:await this.generateRowCells(r,e)}));return o}async addDoc(t,e,o){const r=await this.convertBlocksFunc(t,e.blocks.root,e,this.appId,this.docId,this.state,o);r&&(this.paragraphs=this.paragraphs.concat(r))}async addOtherEmbedBlock(){}}class QZ{constructor(t,e,o,r,i,s,l,a){m(this,"convertBlocks",async(t,e,o,r,i,s,l=720)=>{const a=new ZZ(r,i,s,this.readImage,this.convertBlocks,this.defaultFontSize);return await WZ(t,e,o,a,r,i,this.md5HexFunc,this.getDocByBlock,this.getTextsByBox,l||720),a.paragraphs});this.templateData=t,this.docData=e,this.md5HexFunc=o,this.readImage=r,this.defaultFontSize=i,this.getDocByBlock=s,this.getTextsByBox=l,this.backgroundImageOptions=a}async convert(t,e){return this.snapshot2docx(this.docData,t,e)}async snapshot2docx(t,e,o){const r=new gt.ImportDotx,i=this.templateData?await r.extract(this.templateData):void 0,s=t.blocks.root;g(GZ,s,"data must have blocks");const l=qZ(),a=await this.convertBlocks("blocks",s,t,e,o,l),d=this.backgroundImageOptions?{default:new gt.Header({children:[new gt.Paragraph({children:[new gt.ImageRun(this.backgroundImageOptions)]})]})}:{},h=new gt.Document({numbering:{config:[...uZ,...l.levelConfigs]},sections:[{headers:d,children:a,properties:{page:{size:{width:12240,height:15840},margin:{top:1440,bottom:1440,left:1440,right:1440}}}}]},{template:i});return gt.Packer.toBlob(h)}}async function YZ(n,t,e,o){const r=n.doc.buildResourceUrl(o,{withToken:!0});let i=await b7(r);if(!i)return;if(i.type.indexOf("/svg")!==-1){const l=await p7(i);l&&(i=new File([l],i.name))}return await i.arrayBuffer()}async function JZ(n,t,e){const o=n.editorBlocks.getBlockClass(e.type);if(o.toStandardDoc)return o.toStandardDoc(n,e,t)}async function KZ(n,t){const e=t.attributes,o=n.editorBoxes.getBoxClass(e.type);if(o.toStandardText)return o.toStandardText(n,e)}async function XZ(n,t){let{template:e,download:o,backgroundImageOptions:r}=t!=null?t:{};e||(e=rZ());const i=n.doc.toJSON(),s=(p,A,v)=>YZ(n,p,A,v),l=async(p,A,v)=>JZ(n,i,v),a=async p=>KZ(n,p),h=await new QZ(e,i,Pd.default,s,void 0,l,a,r).convert("_appId","_docId");if(o){const p=URL.createObjectURL(h),A=document.createElement("a");A.setAttribute("download",`${A7(n)}.docx`),A.setAttribute("href",`${p}`),A.click(),A.remove()}return h}const Y2=S("create-editor");async function tQ(n,t){var s,l,a,d,h,p,A,v,B,D,x,_,M,H;g(Y2,n,"app does not exists"),t.lang&&R.setLang(t.lang),Di.level=(s=t.logLevel)!=null?s:da.DEBUG;const e=t.onReauth?async()=>{var ft;const z=t.user.userId,q=t.docId,rt=await((ft=t.onReauth)==null?void 0:ft.call(t,z,q,t.permission));return{userId:z,docId:q,permission:t.permission,appId:t.appId,token:rt,displayName:t.user.displayName,avatarUrl:t.user.avatarUrl}}:void 0,o={auth:{appId:t.appId,docId:t.docId,userId:t.user.userId,permission:t.permission,token:t.token,displayName:t.user.displayName,avatarUrl:t.user.avatarUrl},serverUrl:t.serverUrl,reauthFunc:e,disableLogout:t.disableLogout},r=await Xa.load(o),i=ja(n,r,{id:t.id,scrollContainer:t==null?void 0:t.scrollContainer,enableComments:t==null?void 0:t.enableComments,components:{blocks:[...wk,...((l=t==null?void 0:t.components)==null?void 0:l.blocks)||[]],embeds:[...Z2,...((a=t.components)==null?void 0:a.embeds)||[]],boxes:[...Bk,...((d=t.components)==null?void 0:d.boxes)||[]],commandProviders:[new Wp,...((h=t.components)==null?void 0:h.commandProviders)||[]],decorators:[new Sf,new Ap],insertions:[vg],blockHooks:[new t2,new Z7,...((p=t.components)==null?void 0:p.blockHooks)||[]],textRenders:[new s8,new p0],options:{...t.componentsOptions}},shortcuts:[Ez,MN,vH,R0,Fy,FO,D0,lV,Mh,...t.shortcuts||[]],colors:["#338FE5","#24B47E","#F0A100","#E52727","#9678D3","#2CB2AE","#EB6414","#8AAB3F"]});if(i.editorCommandProviders.registerCommandProvider(new br(i)),i.input.addHandler(new JV),i.input.addHandler(new xf),i.input.addHandler(new K_),i.input.addHandler(new gH),i.input.addHandler(new vu(i,{headingLevel:1,titlePlaceholder:R.t("placeholder.common.title"),contentPlaceholder:R.t("placeholder.common.content"),readonlyTitlePlaceholder:R.t("placeholder.common.readonlyTitle"),addPlaceholderToAllCurrentEmptyBlock:!0})),i.input.addHandler(new Cf(i,(A=t.componentsOptions)==null?void 0:A.quickMenu)),i.input.addHandler(new l2(i)),i.input.addHandler(new h2(i)),i.input.addHandler(new TN),i.input.addHandler(new _f),i.doc.registerCallback(new KV(i)),i.addCustom("remote-cursor",()=>new Qb(i)),i.addCustom("block-menu",z=>new J7(z)),i.addCustom("editor-tooltip",()=>new Af(i)),t!=null&&t.enableComments&&i.addCustom("editor-comments",z=>new i8(z,new KG(z))),i.addCustom("create-options",()=>new J5(i,t)),i.addCustom("drop-target",()=>new Lu(i)),i.addCustom("list-to-mindmap",()=>new df(i)),i.addCustom("list-to-mention",()=>new AW(i)),i.addCustom("mobile-helper",()=>new _W(i)),i.addCustom("code-caret",()=>new IN(i)),i.addCustom("image-paste-handler",()=>new s2(i)),(v=t.componentsOptions)!=null&&v.mention){const z=t.componentsOptions.mention;i.addCustom("mention",()=>new _2(i,z))}if(i.addCustom("heading-collapse",()=>new M2(i)),gc.register(i),Lu.register(i),es.register(i),Ki.register(i),i.addListener("clickLink",(z,q,rt)=>{var Bt;if((Bt=t==null?void 0:t.events)!=null&&Bt.onClickLink){t.events.onClickLink(z,q,rt);return}const ft=rt.getAttribute("link");ft&&(z.readonly||q.ctrlKey||q.metaKey)&&window.open(ft,"_blank")}),(D=(B=t.componentsOptions)==null?void 0:B.remoteCarets)!=null&&D.onUserChanged){const z=(_=(x=t.componentsOptions)==null?void 0:x.remoteCarets)==null?void 0:_.onUserChanged;i.doc.getRemoteUsers().on("change",q=>{z(i,q)})}return(H=(M=t.componentsOptions)==null?void 0:M.templates)!=null&&H.templates.length&&(i.addListener("docChanged",()=>{n1(i)}),i.addListener("resize",()=>{n1(i,{reset:!0})}),setTimeout(()=>{n1(i)},100)),i.doc.registerCallback({onError:async z=>{if(z.code==="ResetDoc"){Y2.error(`reset doc: ${z.message}`);const q=await Xa.load(o);i.doc.reset(q)}}}),i}function eQ(n){return n.toJSON!==void 0}async function nQ(n,t,e){var i,s,l,a,d;g(Y2,n,"app does not exists");const o=eQ(t)?t:new Xg(t,{serverUrl:e.serverUrl||""});e.lang&&R.setLang(e.lang);const r=ja(n,o,{id:e.id,scrollContainer:e==null?void 0:e.scrollContainer,components:{blocks:[Ef,Df,j0,I9],commandProviders:[new Wp],decorators:[new Sf,new Ap],embeds:[...Z2,...((i=e.components)==null?void 0:i.embeds)||[]],boxes:[I0,F2,f8,...((s=e.components)==null?void 0:s.boxes)||[]],insertions:[vg],blockHooks:[new t2,...((l=e.components)==null?void 0:l.blockHooks)||[]],textRenders:[new s8,new p0,...((a=e.components)==null?void 0:a.textRenders)||[]],options:{...e.componentsOptions}},shortcuts:[R0,Fy,D0,Mh]});return r.editorCommandProviders.registerCommandProvider(new br(r)),r.input.addHandler(new xf),r.input.addHandler(new vu(r,{headingLevel:1,titlePlaceholder:R.t("placeholder.common.title"),contentPlaceholder:R.t("placeholder.common.content"),readonlyTitlePlaceholder:R.t("placeholder.local.readonlyTitle"),addPlaceholderToAllCurrentEmptyBlock:!0})),r.input.addHandler(new Cf(r,(d=e.componentsOptions)==null?void 0:d.quickMenu)),r.input.addHandler(new l2(r)),r.input.addHandler(new h2(r)),r.input.addHandler(new _f),r.addCustom("block-menu",h=>new J7(h)),r.addCustom("editor-tooltip",()=>new Af(r)),r.addCustom("image-paste-handler",()=>new s2(r)),e!=null&&e.enableComments&&r.addCustom("editor-comments",h=>new i8(h,new XG(h,o))),r.addCustom("heading-collapse",()=>new M2(r)),r.addListener("clickLink",(h,p,A)=>{var B;if((B=e==null?void 0:e.events)!=null&&B.onClickLink){e.events.onClickLink(h,p,A);return}const v=A.getAttribute("link");v&&(h.readonly||p.ctrlKey||p.metaKey)&&window.open(v,"_blank")}),gc.register(r),r}function oQ(n,t){var a;const e=n.doc;if(!((a=e.getVersionHelper)==null?void 0:a.call(e)))throw new Error("the editor does not support to show versions");const r=n.getCustom("create-options");if(!r)throw new Error("the editor does not support to show versions");const i=r.getData(),s=new Ek(i),l=n.addCustom("version-dialog",()=>new S8(n.doc,s));return l.show(t),l}b.tippy=GB,b.AnchorBox=A6,b.AuthError=Wh,b.AuthHeader=Ka,b.AutoScroll=Qd,b.BaseURLHeader=qh,b.BasicCommands=B_,b.BlockExclusiveHook=Z7,b.BlockLockerHook=t2,b.BlockLockerPasteHandler=_f,b.BlockResizer=Bu,b.BrBox=m6,b.CodeBlock=Df,b.CodeLineBlock=j0,b.CodeTextDecorator=Sf,b.DefaultShortcuts=Mh,b.DocIdError=GS,b.DragDrop=dC,b.DrawioEmbed=z2,b.EditorBlocks=v4,b.EditorBoxes=p6,b.EditorCommandProviders=lb,b.EditorComplexBlockPosition=Mo,b.EditorComplexSelectionRange=rr,b.EditorDecorators=k6,b.EditorEmbeds=k4,b.EditorInsertions=y6,b.EditorSimpleBlockPosition=je,b.EditorSimpleSelectionRange=Ye,b.EmbedBlock=B4,b.EmbedBlockResizer=Pu,b.EnforceWithDocumentTitleHandler=vu,b.EventCallbacks=ha,b.FILL_CHAR=pI,b.FileExtError=ZS,b.GroupOrder=L9,b.HeadingBlockScrollListener=hW,b.ImageBox=C6,b.InlineBoxCommandProvider=$9,b.InputtingInsertion=b6,b.LocalDoc=Xg,b.LogLevel=da,b.Logger=Di,b.MIN_DISTANCE_THRESHOLD=aC,b.ManualCloseDialog=iu,b.ManualMenu=zs,b.ManualToolbar=ru,b.MarkdownInputHandler=xf,b.MaxUserError=dp,b.Mindmap=h0,b.OnesEditorAutoSuggest=Fp,b.OnesEditorCustomDataWrapper=J5,b.OnesEditorExclusiveBlock=Ki,b.OnesEditorHoveringBlock=Ae,b.OnesEditorQuickMenu=Cf,b.OnesEditorToc=Nu,b.OnesEditorTocProvider=es,b.OnesEditorToolbar=gc,b.OnesEditorTooltip=Af,b.OnesEditorVersionsDialog=S8,b.PermissionError=qS,b.Popup=tu,b.RemoteCarets=Qb,b.RemoteCaretsDecorator=Ap,b.RemoteCaretsInsertion=vg,b.RemoteUsers=Ph,b.RequestReloadError=Ja,b.RichText=ln,b.ShareDBDoc=Xa,b.ShareDBDocVersionsProvider=Ek,b.SimpleCache=X5,b.StandardEmbedBlockCommands=x2,b.TEXT_STYLE_BACKGROUND_COLOR_PREFIX=ug,b.TEXT_STYLE_COLOR_PREFIX=ag,b.TableBlock=Ef,b.TableBlockCommandProvider=Wp,b.TableShortcuts=R0,b.TextBlock=Tn,b.TextBox=f6,b.TextStyleShortcuts=D0,b.TocEmbed=V8,b.ZERO_WIDTH_SPACE_CHAR=fa,b.abbreviation=Yd,b.addAttribute=hh,b.addClass=W,b.addCommentToBlock=Kf,b.addDays=FE,b.addMetaToDoc=Oh,b.addMonths=_E,b.animateScrollTo=ym,b.applyPlaceholderToBlock=If,b.assert=g,b.autoShowHideTemplates=n1,b.blockToDoc=Qg,b.blockToHtml=Bg,b.blockToMarkdown=Eg,b.blockToText=vh,b.blocksToDoc=OT,b.clearAllSelection=e4,b.clientType=Ze,b.cloneBlock=Fi,b.cloneChildContainer=_g,b.cloneDoc=Fg,b.cloneText=o6,b.commentToShareDbComment=Cp,b.compareElement=jd,b.comparePosition=Ym,b.complexBlockAdjustSelectionPos=rh,b.complexBlockFindNearestChildBlock=T4,b.complexBlockGeFirstSimpleChild=Km,b.complexBlockGetAllChildContainers=xn,b.complexBlockGetBottomChildContainers=I4,b.complexBlockGetLastSimpleChild=zl,b.complexBlockGetSelectedContainers=Rs,b.complexBlockGetTopChildContainers=x4,b.containerToDoc=PA,b.continuousScroll=DC,b.convertBlockFrom=th,b.convertImageFileToPng=p7,b.convertImageSrcToPng=YP,b.copyBlockAttributes=_6,b.createBlockAnchor=zr,b.createBlockCaretAnchor=M4,b.createBlockContentElement=Is,b.createBlockElement=VC,b.createBlockSimpleDocRange=ph,b.createBlockSimpleRange=Ce,b.createBoxContentElement=GC,b.createBoxElement=WC,b.createBoxOp=Z4,b.createChildContainer=A4,b.createComplexBlockPosition=fe,b.createComplexDocPos=a6,b.createComplexDocRange=bI,b.createContainer=s6,b.createContainerElement=Wm,b.createDeleteOps=V4,b.createEditor=ja,b.createEditorSelectionRange=Ue,b.createElement=w,b.createEmptyContainer=qr,b.createEmptyDoc=Wr,b.createEmptyTextBlockData=mh,b.createExpandedRange=$d,b.createIconButton=$l,b.createImage=pm,b.createInsertOps=uh,b.createInsertionContentElement=YC,b.createInsertionElement=ZC,b.createLocalEditor=nQ,b.createOnesEditor=tQ,b.createRange=tC,b.createRichText=Oi,b.createRootContainer=C4,b.createSimpleBlockPosition=st,b.createSimpleDocPos=c6,b.createTextBlockData=lr,b.createTextButton=Qs,b.createTextOp=co,b.createTextWithReplaceSoftReturn=sg,b.daysAfter=Lm,b.deleteText=cg,b.diffDays=PE,b.disablePageScroll=wC,b.docToHtml=S6,b.docToHtmlFragment=yh,b.docToMarkdown=Ra,b.docToText=Ma,b.downloadImageToFile=b7,b.downloadObjectToFile=H2,b.downloadSvgToString=K8,b.editLink=gu,b.editorAddComment=az,b.editorAddTextAttribute=q6,b.editorAutoInsertBlock=F6,b.editorBreakTextBlock=Ql,b.editorClearCompositionText=O6,b.editorClearSelectedContents=Rg,b.editorCopyBlock=_h,b.editorDeleteBlock=Lg,b.editorDeleteBlockText=Dg,b.editorDeleteBlockWithoutChildren=Bh,b.editorDeleteChildContainer=fT,b.editorDeleteChildContainers=P6,b.editorFocusToBlock=Og,b.editorFocusToEnd=_A,b.editorGetBlockData=_i,b.editorGetBlockText=gn,b.editorGetBlockTextEx=Ah,b.editorGetBoxData=d6,b.editorHandleKeyboardEvent=jA,b.editorInsertBlock=Zl,b.editorInsertBoxToBlock=M6,b.editorInsertDoc=V6,b.editorInsertDocAt=Pg,b.editorInsertText=Tg,b.editorInsertTextToBlock=L6,b.editorInsertTextToBlockEx=Ig,b.editorMergeTextBlock=N6,b.editorMoveDown=rA,b.editorMoveEnd=mA,b.editorMoveHome=gA,b.editorMoveLeft=eA,b.editorMoveLineEnd=wA,b.editorMoveLineHome=kA,b.editorMovePageDown=DA,b.editorMovePageUp=TA,b.editorMoveRight=nA,b.editorMoveUp=oA,b.editorMoveWordEnd=dA,b.editorMoveWordLeft=uA,b.editorRangeClearColor=Z6,b.editorRangeGetColor=Ng,b.editorRangeSetColor=G6,b.editorRemoveTextAttribute=CT,b.editorReplaceBlockText=xh,b.editorReplaceContainer=W6,b.editorRunOnce=tp,b.editorSelectAll=OA,b.editorSelectContainer=Gg,b.editorSelectDown=iA,b.editorSelectEnd=Wg,b.editorSelectHome=pA,b.editorSelectLeft=sA,b.editorSelectLineEnd=yA,b.editorSelectLineHome=vA,b.editorSelectPageDown=LA,b.editorSelectPageUp=SA,b.editorSelectRight=lA,b.editorSelectUp=cA,b.editorSelectWordEnd=fA,b.editorSelectWordLeft=hA,b.editorSetTextColor=Yl,b.editorShowFindDialog=gU,b.editorToDocx=XZ,b.editorUpdateBlockData=Ih,b.editorUpdateCompositionText=R6,b.editorUpdateEmbedData=U6,b.enablePageScroll=BC,b.escapeHtmlText=sC,b.escapeRegExp=_m,b.escapeSpace=bE,b.exclusiveBlock=J0,b.executeBlockCommand=u4,b.executeEmbedBlockCommand=a4,b.executeRangeCommand=sb,b.fileToDataUrl=jl,b.findAfterOffsetNotType=Cg,b.findAllText=mg,b.findEventTargetBlock=rC,b.findInsertionById=QC,b.findNextOffset=FI,b.findNextVisibleSimpleBlock=hb,b.findPrevOffset=_I,b.findPrevOffsetNotType=pg,b.findPrevSimpleBlockBeforeChildContainer=E4,b.findPrevVisibleSimpleBlock=db,b.findTarget=Hl,b.findWordEnd=bg,b.findWordLeft=Ag,b.format=ba,b.formatBytes=SC,b.formatDate=Rm,b.fragmentToHtml=EC,b.fromBase64=pa,b.fromBase64ToBlob=Im,b.fromBase64ToUint8Array=SE,b.fromDocRange=Mi,b.fromNowString=Om,b.genId=K,b.getAllChildBlocks=tg,b.getAllQuickMenuItems=T0,b.getAllSelectedBlocks=Ro,b.getAttributesAt=Da,b.getBlockBackground=zC,b.getBlockByIndex=Fr,b.getBlockCaretRect=So,b.getBlockClass=Qt,b.getBlockClassByType=Ls,b.getBlockClientRects=Nr,b.getBlockCommandsWithHook=zm,b.getBlockContent=Lt,b.getBlockId=it,b.getBlockIndex=bt,b.getBlockInfo=Tu,b.getBlockKind=Do,b.getBlockMinWidth=o4,b.getBlockNearestRangeFromPoint=L4,b.getBlockOptions=ZE,b.getBlockPath=Li,b.getBlockProperties=s4,b.getBlockRangeFromPoint=ih,b.getBlockStyles=GE,b.getBlockTextLength=ut,b.getBlockTools=te,b.getBlockType=Dt,b.getBoxContent=Nm,b.getBoxId=qC,b.getBoxTypeFromElement=va,b.getChildBlockCount=Io,b.getChildBlocks=pe,b.getChildOffset=_s,b.getColorFromAttributes=hg,b.getColorFromContent=Jd,b.getComplexBlockClass=zn,b.getContainerBlockPath=m4,b.getContainerBlocks=t4,b.getContainerBlocksElement=nh,b.getContainerById=jr,b.getContainerId=at,b.getContainerMinWidth=Gm,b.getContainerToolsElement=XE,b.getContainerWidth=b4,b.getDistanceSquare=nr,b.getElementOffset=ma,b.getElementScale=ys,b.getEmbedType=fn,b.getExistsBlockTools=Xd,b.getExistsContainerById=f4,b.getFileExt=Aa,b.getFirstChildBlock=xe,b.getFirstClientRect=Hd,b.getHeadingMenuOptions=w0,b.getHorizontalPadding=Cm,b.getInsertionContent=$m,b.getLastChildBlock=Qe,b.getLastClientRect=bs,b.getListAllNextBrothers=uc,b.getLogger=S,b.getNextBlock=Zt,b.getNextValidOffset=Fs,b.getNextVisibleBlock=Ds,b.getOffsetInfoAfter=La,b.getOffsetInfoBefore=bh,b.getOpAt=Y4,b.getOpLength=dh,b.getParentBlock=et,b.getParentBlockExcludeSelf=xs,b.getParentBox=Pm,b.getParentContainer=nt,b.getPrevBlock=ce,b.getPrevValidOffset=Ri,b.getPrevVisibleBlock=Ts,b.getRangeCommands=rb,b.getRootBlock=Um,b.getScrollContainer=ro,b.getSpecialBlockCommands=l4,b.getStandardEmbedBlockProperties=I2,b.getTextAfterOffset=RI,b.getTextAttributes=xg,b.getTextBeforeOffset=OI,b.getTextBlockChild=eh,b.getTextBlockClass=KC,b.getTextBlockContentChildTextLength=lo,b.getTextBlockContentChildType=d4,b.getTextBlockContentChildren=or,b.getTextLength=rn,b.getTextOpLength=eg,b.getTextWidth=qd,b.getToolbar=sf,b.handleBlockElementUpdated=r4,b.hasAltOnly=EE,b.hasClass=xt,b.hasCtrlOrCmd=AC,b.hasCtrlOrCmdOnly=BE,b.hashCode=PC,b.hideBlock=jC,b.htmlToFragment=Wd,b.i18n=R,b.injectDocToHtmlFragment=Rh,b.injectStyle=cC,b.insertEmptyBlock=JE,b.insertEmptyEmbedBlock=Vm,b.insertText=Vr,b.intersectionCommands=$D,b.isBackspace=vC,b.isBlock=Es,b.isBlockLocked=Of,b.isBlockLockedByOthers=X0,b.isBlockLockedBySelf=Du,b.isBlockTools=HC,b.isBox=Fm,b.isCJK=gC,b.isChildContainer=Lo,b.isChildNode=Xt,b.isCollapsedRange=AI,b.isComplexBlockPosition=Qm,b.isComplexKindBlock=Mt,b.isContainer=Pr,b.isContainerSelectedAllChildBlocks=MA,b.isControlEvent=ws,b.isDelete=IE,b.isDraggingFiles=Gd,b.isElementVisible=vm,b.isEmbedBlock=Me,b.isEmptyContainer=Ba,b.isEmptyDoc=gg,b.isEmptyTextBlock=he,b.isEmptyTextBlockWithoutCompositionText=bu,b.isEnterOnly=bC,b.isEscape=Em,b.isExclusiveBlock=Rf,b.isFirefox=Vd,b.isFirstChildBlockInComplexBlock=Lx,b.isHighSurrogate=fE,b.isInBlock=Hm,b.isInBlockTools=Ss,b.isLetter=mC,b.isLowSurrogate=gm,b.isMatchShortcut=_r,b.isMoveForward=kE,b.isNavigationEvent=yE,b.isNavigationKey=CC,b.isNodeRemoved=nC,b.isNumber=fC,b.isPrintableKey=Bm,b.isRootBlock=io,b.isRootContainer=Yt,b.isSafari=pC,b.isSameDay=Mm,b.isSecureEnv=H0,b.isShiftEnter=xE,b.isShiftTab=DE,b.isShortcutEvent=wE,b.isSimpleBlock=qE,b.isSimpleBlockPosition=Ur,b.isSimplePos=l6,b.isSimpleRange=gh,b.isSpace=zd,b.isTab=TE,b.isTextBlockContentBoxChild=so,b.isTextBlockContentChild=ka,b.isTextBlockContentInsertionChild=Hr,b.isTextBlockContentTextChild=wa,b.isTextKindBlock=tt,b.isTextKindBlockType=ya,b.isToday=LC,b.isValidOffset=sn,b.isVisibleBlock=Kd,b.isYesterday=MC,b.loadJs=oC,b.loadJsPromise=vs,b.lockers=Eo,b.mergeCommands=rf,b.mergeDocs=$s,b.mergeOps=lg,b.mergeText=hI,b.multiSplitText=_4,b.overflowText=RC,b.parseShortcut=yC,b.patchNode=Ca,b.pointInRect=ks,b.rangeAddAttribute=Ta,b.rangeGetTextColor=n6,b.rangeRemoveAttribute=Wl,b.rangeSetTextColor=X4,b.rangeTransformText=J4,b.registerDragDrop=km,b.removeAttribute=dg,b.removeClass=ot,b.removeLastBr=cI,b.removePlaceholderFromBlock=c7,b.removeStyle=lC,b.replaceAll=NE,b.replaceAllCaseInsensitive=$E,b.replaceAllText=i6,b.replaceText=fh,b.requestDownload=Zd,b.resetListStart=hc,b.scrollable=TC,b.selectFile=Ul,b.selectedBlockToDoc=Dh,b.selectionToDoc=Sh,b.setAttributes=Ud,b.setClipboardData=Sm,b.setClipboardDataByEvent=OE,b.setColorToAttributes=t6,b.setDataset=Am,b.setDefaultCursor=ga,b.setStyles=bm,b.shareDBCommentToDocObject=pp,b.shareDBDocCommentToComment=Gb,b.shortcutToDisplayText=xo,b.showBlock=UC,b.showDocVersions=oQ,b.splitText=In,b.splitToThree=ze,b.stringToDataUrl=Tm,b.stringToObjectUrl=Dm,b.subText=F4,b.textNodeOffsetFromPoint=eC,b.titleFromEditor=A7,b.toBase64URL=Si,b.toMindmap=uf,b.toPlainText=ie,b.toPlainTextKeepLength=fg,b.trimChar=wm,b.unexclusiveBlock=K0,b.unicodeLength=mE,b.unicodeSubstr=gE,b.updateBlockSelection=n4,b.updateOpAttributes=r6,b.updateTextBlockContent=MI,b.updateUrl=xm;for(const n in ye)n!=="default"&&!b.hasOwnProperty(n)&&Object.defineProperty(b,n,{enumerable:!0,get:()=>ye[n]});Object.defineProperties(b,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
753
|
+
\`\`\`\`\`\``}return"[plantuml]"}const fk={embedType:"plantuml",convertFrom:kG,handleUpdateBlock:yG,createEmbedContent:vG,getBlockProperties:wG,convertTo:BG},mot="",EG="hr",xG={dividingLine:{type:"\u5206\u5272\u7EBF",abstract:"\u5206\u5272\u7EBF"}},IG={dividingLine:{type:"Separation line",abstract:"Separation line"}},TG={dividingLine:{type:"\u533A\u5207\u308A\u7DDA",abstract:"\u533A\u5207\u308A\u7DDA"}};R.mergeLang({"zh-CN":xG,"en-US":IG,"ja-JP":TG});function DG(n,t){const e=w("div",["editor-embed-container"],t);w("hr",["editor-embed-hr"],e)}function SG(n,t,e,o){return o==="html"?"<hr />":o==="markdown"?"---":"------------"}function LG(){return{name:"hr",insertEmbedCommandItems:[{id:"insert-hr",name:R.t("dividingLine.type"),icon:GL,order:500,group:"common",subText:Cn("insert-hr")}],handleInsertEmptyEmbed:async(n,t)=>{const{containerId:e,blockIndex:o}=t;return n.insertEmbed(e,o,EG,{})}}}function MG(n,t,e){const{data:o}=e;if(!o||o.embedType!=="dividing-line"||!tt(n,t))return null;const r={};return{blockData:{id:K(),type:"embed",embedType:"hr",embedData:r}}}function RG(){return{abstract:R.t("dividingLine.abstract")}}const mk={embedType:"hr",createEmbedContent:DG,convertTo:SG,getOptions:LG,convertFrom:MG,getBlockProperties:RG},got="",pot="",OG={media:{upload:{failed:'<div class="line-1">{name}\u4E0A\u4F20\u5931\u8D25</div><div class="line-2">\u7F51\u7EDC\u670D\u52A1\u5F02\u5E38\uFF0C\u4F60\u53EF\u4EE5 <span class="retry-upload">\u91CD\u8BD5</span></div>'},load:{failed:'<div class="line-1">{name}\u52A0\u8F7D\u5931\u8D25</div><div class="line-2">\u7F51\u7EDC\u670D\u52A1\u5F02\u5E38\uFF0C\u4F60\u53EF\u4EE5 <span class="retry-upload">\u91CD\u8BD5</span></div>'},audio:{menuItem:"\u97F3\u9891",abstract:"\u97F3\u9891"},video:{menuItem:"\u89C6\u9891",abstract:"\u89C6\u9891"}}},_G={media:{upload:{failed:'<div class="line-1">{name} upload failed</div><div class="line-2">Network error, you can <span class="retry-upload">Retry</span></div>'},load:{failed:'<div class="line-1">{name} loading failed</div><div class="line-2">Network error, you can <span class="retry-upload">Retry</span></div>'},audio:{menuItem:"Audio",abstract:"Audio"},video:{menuItem:"Video",abstract:"Video"}}},FG={media:{upload:{failed:'<div class="line-1">{name}\u306E\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u306B\u5931\u6557\u3057\u307E\u3057\u305F</div><div class="line-2">\u304A\u4F7F\u3044\u306E\u30CD\u30C3\u30C8\u30EF\u30FC\u30AF\u63A5\u7D9A\u306B\u554F\u984C\u304C\u767A\u751F\u3057\u307E\u3057\u305F\u3002\u6B21\u306E\u64CD\u4F5C\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002 <span class="retry-upload">\u518D\u8A66\u884C</span></div>'},load:{failed:'<div class="line-1">{name}\u3092\u8AAD\u307F\u8FBC\u3081\u307E\u305B\u3093\u3067\u3057\u305F</div><div class="line-2">\u304A\u4F7F\u3044\u306E\u30CD\u30C3\u30C8\u30EF\u30FC\u30AF\u63A5\u7D9A\u306B\u554F\u984C\u304C\u767A\u751F\u3057\u307E\u3057\u305F\u3002\u6B21\u306E\u64CD\u4F5C\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002 <span class="retry-upload">\u518D\u8A66\u884C</span></div>'},audio:{menuItem:"\u97F3\u58F0",abstract:"\u97F3\u58F0"},video:{menuItem:"\u52D5\u753B",abstract:"\u52D5\u753B"}}};R.mergeLang({"zh-CN":OG,"en-US":_G,"ja-JP":FG});var qo=(n=>(n.AUDIO="audio",n.VIDEO="video",n))(qo||{}),$u=(n=>(n.Empty="empty",n.Progress="progress",n.Error="error",n))($u||{});const gk=10*1024*1024,PG=["wav","mp3","aac","ogg","webm","flac"],NG=["ogg","mp4","webm"],$G=()=>{};function pk(n){var h,p,A,v,B,D;const t=(h=n.getComponentOptions("media"))!=null?h:{},{allowedMedias:e,maxSize:o,callbacks:r}=t,i=(p=e==null?void 0:e.audio)!=null?p:PG,s=(A=e==null?void 0:e.video)!=null?A:NG,l=(v=o==null?void 0:o.audio)!=null?v:gk,a=(B=o==null?void 0:o.video)!=null?B:gk,d=(D=r==null?void 0:r.onError)!=null?D:$G;return{allowedMedias:{audio:i,video:s},maxSize:{audio:l,video:a},callbacks:{onError:d}}}function HG(n,t){const e=i=>i.map(s=>`.${s}`).join(","),{allowedMedias:o}=pk(n),r=o[t];return r?e(r):"*"}function jG(n,t,e){const{maxSize:o,callbacks:r,allowedMedias:i}=pk(t),{[e]:s}=o,{[e]:l}=i;if(s&&n.size>s){const d=new Error("media is too large");throw d.code=`MaxMediaSize-${e}`,r!=null&&r.onError&&(r==null||r.onError(t,d)),d}const a=Aa(n.name);if(l&&!l.includes(a)){const d=new Error(`media file is not allowed: ${a}`);throw d.code="NotAllowedFile",r!=null&&r.onError&&(r==null||r.onError(t,d)),d}}function UG(n){return n===$u.Empty||n===$u.Error}const Ne=S("media");class zG extends ye.TypedEmitter{constructor(e){super();m(this,"mediaContainer",null);m(this,"media",null);m(this,"abstract",null);m(this,"handleMediaLoadError",(e,o)=>{if(!o.target||!(o.target instanceof Node)||!(o.target instanceof Element?o.target:o.target.parentElement))return;const i=et(o.target);if(!i||!i.contains(this.mediaContainer))return;const s=this.renderError();this.updateMediaContent(s),this.emit("mediaError",e,"load_error",it(i))});m(this,"handleUploadFile",async e=>{g(Ne,this.abstract,"no abstract"),g(Ne,this.mediaContainer,"The media element not exist");const{editor:o}=this.options,r=et(this.mediaContainer);g(Ne,r,"The block element not exist");const i=o.getBlockData(r);try{const{resourceId:s}=await o.doc.uploadResource(e,{onProgress:p=>{this.renderProgress(p,e)}}),{name:l,type:a,size:d}=e,h={...i,embedData:{...i.embedData,src:s,fileName:l,fileSize:d,fileType:a}};o.updateBlockData(r,h)}catch(s){Ne.error(s),this.emit("mediaError",o,"upload_error",i.id),this.renderRetry(e)}ot(r,"media-block-uploading")});m(this,"destroy",()=>{this.mediaContainer=null});this.options=e}bindMediaEvent(){const{editor:e}=this.options;this.media&&e.domEvents.addEventListener(this.media,"error",this.handleMediaLoadError)}unbindMediaEvent(){const{editor:e}=this.options;this.media&&e.domEvents.removeEventListener(this.media,"error",this.handleMediaLoadError)}updateMediaContent(e){g(Ne,this.mediaContainer,"The media element not exist"),this.mediaContainer.innerHTML="",this.mediaContainer.append(e)}renderError(){g(Ne,this.abstract,"no abstract");const{editor:e,createMediaElement:o}=this.options,{mediaIcon:r,mediaName:i}=this.abstract;g(Ne,this.mediaContainer,"The media element not exist");const s=et(this.mediaContainer);g(Ne,s,"The block element not exist");const l=e.getBlockData(s),a=l.embedData.src,d=w("div",["media-error","embed-selected-content","embed-hover-content"],null),h=w("span",["media-error-icon"],d);h.innerHTML=r;const p=w("div",[],d);p.innerHTML=R.t("media.load.failed",{name:i}),d.appendChild(p);const A=p.querySelector(".retry-upload");return g(Ne,A,"The element not exist"),e.domEvents.addEventListener(A,"click",(v,B)=>{const D=w("div",["media-element"],null),x=this.getResourceUrl(a),_=o(v,D,l,x);this.unbindMediaEvent(),this.media=_,this.bindMediaEvent(),this.updateMediaContent(D)}),this.setFullScreen(),d}renderRetry(e){g(Ne,this.abstract,"no abstract");const{editor:o}=this.options,{mediaIcon:r,mediaName:i}=this.abstract,s=w("div",["media-error","embed-selected-content","embed-hover-content"],null),l=w("span",["media-error-icon"],s);l.innerHTML=r;const a=w("div",[],s);a.innerHTML=R.t("media.upload.failed",{name:i}),s.appendChild(a);const d=a.querySelector(".retry-upload");g(Ne,d,"The element not exist"),o.domEvents.addEventListener(d,"click",()=>{o.readonly||(g(Ne,this.abstract,"no abstract"),this.handleUploadFile(e))}),this.updateMediaContent(s),this.setFullScreen()}renderProgress(e,o){g(Ne,this.mediaContainer,"The media element not exist");const r=this.mediaContainer.querySelector(":scope .media-progress"),i=e===-1||e===100?100:e;if(r){const{updateProgressElement:s}=this.options;s(r,i)}else{const{createProgressElement:s}=this.options,l=et(this.mediaContainer);g(Ne,l,"The element not exist"),W(l,"media-block-uploading");const a=w("div",["media-progress"],null);s(a,i,o),this.updateMediaContent(a)}this.setFullScreen()}renderMediaElement(e){g(Ne,this.mediaContainer,"The media element not exist");const o=this.mediaContainer.querySelector(":scope > .media-element"),{createMediaElement:r,updateMediaElement:i,editor:s}=this.options,l=this.getResourceUrl(e.embedData.src);if(o){const a=i(s,o,e,l);this.unbindMediaEvent(),this.media=a,this.bindMediaEvent()}else{const a=w("div",["media-element"],null),d=r(s,a,e,l);this.unbindMediaEvent(),this.media=d,this.bindMediaEvent(),this.updateMediaContent(a)}}renderEmpty(e){g(Ne,this.abstract,"no abstract"),g(Ne,this.mediaContainer,"The media element not exist");const o=w("div",["media-empty","embed-selected-content","embed-hover-content"],this.mediaContainer);o.innerHTML=this.abstract.mediaIcon,this.updateMediaContent(o);const{editor:r}=this.options;r.findBlockById(e.id)&&this.emit("mediaError",r,"empty",e.id),this.setFullScreen()}getResourceUrl(e){const{editor:o}=this.options;return o.doc.buildResourceUrl(e)}setFullScreen(){g(Ne,this.mediaContainer,"The media element not exist"),W(this.mediaContainer,"full-screen")}removeFullScreen(){g(Ne,this.mediaContainer,"The media element not exist"),ot(this.mediaContainer,"full-screen")}updateBlockAlign(e,o){const r=et(o);g(Ne,r,"The block element not exist");const{align:i}=e;e.embedType==="video"&&(r.hasAttribute("data-style-align")&&r.removeAttribute("data-style-align"),r.setAttribute("data-style-align",i))}render(e,o){const{src:r}=e.embedData;(!this.mediaContainer||!o.contains(this.mediaContainer))&&(this.mediaContainer=w("div",["media"],o)),this.updateBlockAlign(e,o),UG(r)?r===$u.Empty&&this.renderEmpty(e):this.renderMediaElement(e)}setAbstract(e){this.abstract=e}}S("media-embed");const VG="left";class Ck{constructor(){m(this,"handleInsertEmptyEmbed",async(t,e)=>{var p;const{containerId:o,blockIndex:r}=e;let i;(p=e.data)!=null&&p.file&&(i=e.data.file);const s=HG(t,this.embedType);if(i=i!=null?i:await Ul(s,{}),!i)return null;const{mediaType:l}=this.getAbstract();try{jG(i,t,l)}catch{return null}const a={id:K(),type:"embed",embedType:this.embedType,embedData:{src:$u.Empty}};l==="video"&&(a.align=VG);const d=t.insertBlock(o,r,a);return await this.getMedia(t,a.id).handleUploadFile(i),d})}getMedia(t,e){const o=t.addCustom(`media-${e}`,()=>new zG({editor:t,createMediaElement:this.createMediaElement,updateMediaElement:this.updateMediaElement,createProgressElement:this.createProgressElement,updateProgressElement:this.updateProgressElement}));return o.setAbstract({...this.getAbstract()}),o}getOptions(){const{menuItem:t,mediaIcon:e,mediaName:o,order:r,group:i}=this.getAbstract();return{name:o,insertEmbedCommandItems:[{id:`insert-${this.embedType}`,name:t,icon:e,order:r,group:i,subText:Cn(`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=Lt(e);return i.render(o,s),!0}handleDeleteBlock(t,e){const o=e.id,r=this.getMedia(t,o);r.removeAllListeners(),r.destroy()}convertTo(t,e,o,r){const i=e.embedData,s=t.doc.buildResourceUrl(i.src,{withToken:!0});return r==="html"?`<${i.type} src="${s}" />`:r==="markdown"?``:s}}function Ak(n,t){const e=w("div",["uploading-progress-mask"],n),o=w("div",["uploading-progress-bar"],e),r=w("div",["uploading-progress-bar-value"],o);r.style.width=`${t}%`}function bk(n,t){const e=n.querySelector(".uploading-progress-bar-value");e&&(e.style.width=`${t}%`)}const WG=S("media-audio");class qG extends Ck{constructor(){super(...arguments);m(this,"embedType",qo.AUDIO);m(this,"updateProgressElement",bk);m(this,"createMediaElement",(e,o,r,i)=>{const s=w("div",["audio-container","embed-hover-content","embed-selected-content"],o),l=w("audio",[],s);return l.innerHTML="Your browser does not support the <code>audio</code> element.",l.controls=!0,l.src=i,setTimeout(()=>{this.getMedia(e,r.id).setFullScreen()}),l})}getAbstract(){return{mediaIcon:VL,mediaName:R.t(`media.${qo.AUDIO}.menuItem`),menuItem:R.t(`media.${qo.AUDIO}.menuItem`),order:800,mediaType:qo.AUDIO,group:"common"}}getBlockProperties(){return{abstract:`${R.t(`media.${qo.AUDIO}.abstract`)}`}}updateMediaElement(e,o,r,i){const s=o.querySelector(":scope .audio-container > audio");return g(WG,s,"The media element not exist"),s.src!==i&&(s.src=i),s}createProgressElement(e,o){const r=w("audio",[],e);r.innerHTML="Your browser does not support the <code>audio</code> element.",r.controls=!0,r.src="about:blank",Ak(e,o)}}const vk=new qG;S("video-resizer");function yk(n){return n&&Me(n)&&fn(n)==="video"}const GG=50;class G2{constructor(t){m(this,"currentResizableElement",null);m(this,"resizing",!1);m(this,"handleHoveringBlockChange",(t,e)=>{if(!this.resizing&&!window.isDragging&&(e&&yk(e)&&this.disableBlockResize(e),t&&yk(t))){const o=this.getVideoElement(t);if(!o)return;this.enableBlockResize(t,o)}});m(this,"handleResizing",(t,e)=>{if(this.resizing=!0,!this.currentResizableElement)return;const o=t.getBlock();if(!o)return;const r=o.getBoundingClientRect().width,i=Math.min(Math.max(e.width,GG),r);this.currentResizableElement.style.width=`${i}px`,this.currentResizableElement.style.pointerEvents="none"});m(this,"handleResized",t=>{this.resizing=!1;const e=t.getBlock();if(!this.currentResizableElement||!e)return;const o=this.editor.getBlockData(e),{width:r}=this.currentResizableElement.getBoundingClientRect();this.currentResizableElement.style.pointerEvents="auto",this.editor.updateBlockData(e,{...o,width:r})});this.editor=t,Ae.get(t).addListener("change",this.handleHoveringBlockChange)}destroy(){this.currentResizableElement=null,Ae.get(this.editor).removeListener("change",this.handleHoveringBlockChange)}getVideoElement(t){return Lt(t).querySelector(":scope .video-container > video")}updateResizer(t){const e=this.editor.findCustom(`${it(t)}-resizer`);e&&e.updateResizer()}disableBlockResize(t){const e=this.editor.findCustom(`${it(t)}-resizer`);e&&e.disableResize()}enableBlockResize(t,e){const o=this.editor.addCustom(`${it(t)}-resizer`,()=>new Bu(this.editor,{resize:["top-left","top-right","bottom-left","bottom-right"]}));o.enableResize(t,e),o.removeListener("resizing",this.handleResizing),o.removeListener("resized",this.handleResized),o.addListener("resizing",this.handleResizing),o.addListener("resized",this.handleResized),this.currentResizableElement=e}}const ZG=S("video");class QG extends Ck{constructor(){super(...arguments);m(this,"embedType",qo.VIDEO);m(this,"updateProgressElement",bk);m(this,"createMediaElement",(e,o,r,i)=>{const s=w("div",["video-container","embed-selected-content","drag-preview-element"],o),l=w("video",[],s);return l.innerHTML="Your browser does not support the <code>video</code> element.",l.controls=!0,l.src=i,l.addEventListener("canplay",()=>{e.addCustom("video-resizer",()=>new G2(e)),this.getMedia(e,r.id).removeListener("mediaError",this.handleMediaError),this.getMedia(e,r.id).addListener("mediaError",this.handleMediaError),this.getMedia(e,r.id).removeFullScreen()}),r.width&&(l.style.width=`${r.width}px`),l});m(this,"createProgressElement",(e,o,r)=>{const i=w("video",["progress-video"],e);i.innerHTML="Your browser does not support the <code>audio</code> element.",i.controls=!0,Ak(e,o),jl(r).then(s=>{const l=e.querySelector(".progress-video");l&&Hm(e)&&(l.src=s)})})}getAbstract(){return{mediaName:R.t(`media.${qo.VIDEO}.menuItem`),mediaIcon:WL,menuItem:R.t(`media.${qo.VIDEO}.menuItem`),order:700,mediaType:qo.VIDEO,group:"common"}}getBlockProperties(){return{abstract:`[${R.t(`media.${qo.VIDEO}.abstract`)}]`}}handleMediaError(e,o,r){const i=e.addCustom("video-resizer",()=>new G2(e)),s=e.getBlockById(r);i.disableBlockResize(s)}updateMediaElement(e,o,r,i){const s=o.querySelector(":scope .video-container > video");g(ZG,s,"The media element not exist"),s.src!==i&&(s.src=i),r.width?s.style.width=`${r.width}px`:s.style.width="";const l=e.getBlockById(r.id);return setTimeout(()=>{e.addCustom("video-resizer",()=>new G2(e)).updateResizer(l)}),s}}const kk=new QG,wk=[Ef,Df,j0,I9],Z2=[z2,J8,ck,dk,fk,N9,mk,kk,vk,ny,V8,eV],Bk=[I0,F2,f8];function YG(n,t,e){var r,i,s;const o=ja(n,t,{components:{blocks:[...wk,...((r=e==null?void 0:e.components)==null?void 0:r.blocks)||[]],embeds:[...Z2,...((i=e.components)==null?void 0:i.embeds)||[]],boxes:[...Bk,...((s=e.components)==null?void 0:s.boxes)||[]],textRenders:[new p0],options:{...e.componentsOptions}}});return o.readonly=!0,o.addCustom("heading-collapse",()=>new M2(o)),o.addCustom("editor-tooltip",()=>new Af(o)),o.addListener("clickLink",(l,a,d)=>{var p;if((p=e==null?void 0:e.events)!=null&&p.onClickLink){e.events.onClickLink(l,a,d);return}const h=d.getAttribute("link");h&&(l.readonly||a.ctrlKey||a.metaKey)&&window.open(h,"_blank")}),o}class Ek{constructor(t){this.createOptions=t,t.lang&&R.setLang(t.lang)}createHistoryEditor(t,e){return YG(t,e,this.createOptions)}}S("create-editor");function xk({root:n,childDoc:t,doc:e}){t.uploadResource=e.uploadResource.bind(e),t.buildResourceUrl=e.buildResourceUrl.bind(e);const o=ja(n,t,{shortcuts:[Mh],components:{blocks:[Ef,Df],decorators:[new Sf],embeds:[ny,z2,J8,ck,dk,fk,N9,mk,kk,vk],boxes:[I0,F2],options:{image:{defaultAlign:"left"}}}});return o.input.addHandler(new xf),o.input.addHandler(new l2(o)),o.input.addHandler(new h2(o)),o.input.addHandler(new sz(o)),o.input.addHandler(new _f),o.addCustom("image-paste-handler",()=>new s2(o)),o}function JG(n,t){const e=Array.from(n.rootContainer.querySelectorAll(`[comment-${t.toLocaleLowerCase()}="${t}"]`)),o=new Set;e.forEach(r=>{const i=et(r);i&&o.add(i)}),o.forEach(r=>{lz(n,r,t)})}class KG{constructor(t){m(this,"listeners",new Set);m(this,"doc");this.editor=t,this.doc=this.editor.doc.externalDoc,this.doc.registerCallback(this)}getComments(){return this.doc.getComments()}getComment(t){return this.doc.getComment(t)}getCommentDoc(t){return this.doc.getCommentDoc(t)}localCreateComment(t,e){this.doc.localCreateComment(t,e)}localDeleteComment(t){const e=this.getComment(t);this.doc.localDeleteComment(t);const o=e.groupId;this.getComments().filter(i=>i.groupId===o).length===0&&JG(this.editor,o)}localUpdateComment(t,e){this.doc.localUpdateComment(t,e)}onCreateComment(t,e){Array.from(this.listeners.values()).forEach(o=>o.onCreateComment(t,e))}onDeleteComment(t,e){Array.from(this.listeners.values()).forEach(o=>o.onDeleteComment(t,e))}onUpdateComment(t,e){Array.from(this.listeners.values()).forEach(o=>o.onUpdateComment(t,e))}addListener(t){this.listeners.add(t)}removeListener(t){this.listeners.delete(t)}createCommentEditor(t,e){var r,i;const o=xk({root:t,childDoc:e,doc:this.doc});if((r=this.editor.options.componentsOptions)!=null&&r.mention){const s=this.editor.options.componentsOptions.mention;o.addCustom("mention",()=>new _2(o,{...s,enableFirstBlock:!0}))}if((i=this.editor.options.componentsOptions)!=null&&i.comment){const s=this.editor.options.componentsOptions.comment;s.onCommentEditorClick&&o.addListener("click",s.onCommentEditorClick)}return o}allowEdit(t){return t.userId===this.doc.getUser().userId}}class XG{constructor(t,e){m(this,"listeners",new Set);this.editor=t,this.localDoc=e}get doc(){return this.localDoc.toJSON()}getComments(){return Object.values(this.doc.comments)}getComment(t){return this.doc.comments[t]}getCommentDoc(t){const e=this.doc.comments[t];return pp(e)}addListener(t){this.listeners.add(t)}removeListener(t){this.listeners.delete(t)}localCreateComment(t,e){}localDeleteComment(t){}localUpdateComment(t,e){}createCommentEditor(t,e){var r,i;const o=xk({root:t,childDoc:e,doc:this.localDoc});if((r=this.editor.options.componentsOptions)!=null&&r.mention){const s=this.editor.options.componentsOptions.mention;o.addCustom("mention",()=>new _2(o,{...s,enableFirstBlock:!0}))}if((i=this.editor.options.componentsOptions)!=null&&i.comment){const s=this.editor.options.componentsOptions.comment;s.onCommentEditorClick&&o.addListener("click",s.onCommentEditorClick)}return o}allowEdit(t){return t.userId===this.localDoc.getUser().userId}}const tZ={placeholder:{common:{title:"\u8BF7\u8F93\u5165\u6807\u9898",readonlyTitle:"\u8BF7\u8F93\u5165\u6807\u9898",content:"\u70B9\u51FB + \uFF0C\u6216\u8F93\u5165 / \u5FEB\u6377\u63D2\u5165\u7EC4\u4EF6",contentInTable:"\u8F93\u5165 / \u5FEB\u6377\u63D2\u5165\u7EC4\u4EF6"},local:{readonlyTitle:"\u672A\u547D\u540D"}},copyCutProperty:{copy:"\u590D\u5236",cut:"\u526A\u5207",unsafeEnvTips:"\u7531\u4E8E\u5F53\u524D http \u8BBF\u95EE\u73AF\u5883\u4E0B\u7684\u9650\u5236\uFF0C\u8BF7\u4F7F\u7528\u5FEB\u6377\u952E({shortCut}) {operation}"}},eZ={placeholder:{common:{title:"Enter a title",readonlyTitle:"Enter a title",content:"Click + or enter / to insert components quickly",contentInTable:"Enter / to insert components quickly"},local:{readonlyTitle:"Untitled"}},copyCutProperty:{copy:"Copy",cut:"Cut",unsafeEnvTips:"Due to the limitations of the current http access environment, please use the shortcut ({shortCut}) {operation}"}},nZ={placeholder:{common:{title:"\u30BF\u30A4\u30C8\u30EB\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",readonlyTitle:"\u30BF\u30A4\u30C8\u30EB\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044",content:"\u300C+\u300D\u3092\u30AF\u30EA\u30C3\u30AF\u3059\u308B\u304B\u3001\u300C/\u300D\u3092\u5165\u529B\u3059\u308B\u3068\u3001\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8\u304C\u7D20\u65E9\u304F\u633F\u5165\u3067\u304D\u307E\u3059",contentInTable:"\u300C/\u300D\u3092\u5165\u529B\u3059\u308B\u3068\u3001\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8\u304C\u7D20\u65E9\u304F\u633F\u5165\u3067\u304D\u307E\u3059"},local:{readonlyTitle:"\u7121\u984C"}},copyCutProperty:{copy:"\u8907\u88FD",cut:"\u5207\u308B",unsafeEnvTips:"HTTP\u74B0\u5883\u306E\u5236\u7D04\u306B\u3088\u308A\u3001{operation}\u3059\u308B\u306B\u306F\u3001\u30B7\u30E7\u30FC\u30C8\u30AB\u30C3\u30C8({shortCut}) \u3092\u3054\u4F7F\u7528\u304F\u3060\u3055\u3044"}};R.mergeLang({"zh-CN":tZ,"en-US":eZ,"ja-JP":nZ});const oZ="UEsDBBQABgAIAAAAIQBk9WPugQEAACkGAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC0lMtqwzAQRfeF/oPRtsRKuiilxMmij2UbaArdKvI4EdULaZzH33fsJKYUJy5NsjHIM/feowHNcLw2OllCiMrZjA3SPkvASpcrO8/Yx/Sld8+SiMLmQjsLGdtAZOPR9dVwuvEQE1LbmLEFon/gPMoFGBFT58FSpXDBCKRjmHMv5JeYA7/t9++4dBbBYg8rDzYaPkEhSo3J85p+b0kC6MiSx21jlZUx4b1WUiDV+dLmv1J6u4SUlHVPXCgfb6iB8daEqnI4YKd7o9EElUMyEQFfhaEuvnIh57mTpSFletymhdMVhZLQ6Cs3H5yEGGnmRqcIxtMNIDVC2T1/G4csIzrzaTRXpJkE5+PgZJzGtPKDgAqaGR6chS3NDALRn38YjXUnRMSNhnh+gq1vdzwgkuASADvnToQVzN4vRvHDvBOkoNypmGk4P0Zj3QmBtIpg+z39VdQ2xyKps36AtNrCP669312Vuuf/9PKaRLI++X5QrcUc8pZsXi/60TcAAAD//wMAUEsDBBQABgAIAAAAIQAekRq37wAAAE4CAAALAAgCX3JlbHMvLnJlbHMgogQCKKAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAArJLBasMwDEDvg/2D0b1R2sEYo04vY9DbGNkHCFtJTBPb2GrX/v082NgCXelhR8vS05PQenOcRnXglF3wGpZVDYq9Cdb5XsNb+7x4AJWFvKUxeNZw4gyb5vZm/cojSSnKg4tZFYrPGgaR+IiYzcAT5SpE9uWnC2kiKc/UYySzo55xVdf3mH4zoJkx1dZqSFt7B6o9Rb6GHbrOGX4KZj+xlzMtkI/C3rJdxFTqk7gyjWop9SwabDAvJZyRYqwKGvC80ep6o7+nxYmFLAmhCYkv+3xmXBJa/ueK5hk/Nu8hWbRf4W8bnF1B8wEAAP//AwBQSwMEFAAGAAgAAAAhADPCW79BAQAA5wQAABwACAF3b3JkL19yZWxzL2RvY3VtZW50LnhtbC5yZWxzIKIEASigAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAArJQxT8MwEIV3JP5D5B07LVAQatoFkDqwQJFYneSSWI3tyL6Q9t9zojRNRYkYPN6z7r1P57Pny62uo09wXlmTsAmPWQQms7kyZcLe189X9yzyKE0ua2sgYTvwbLm4vJi/Qi2RmnylGh+Ri/EJqxCbByF8VoGWntsGDJ0U1mmJVLpSNDLbyBLENI5nwg092OLEM1rlCXOrnPLXuwb+422LQmXwaLNWg8EzEQKpF8hQuhIwYd/lXpxwMmPiPMN1SAaPu5qG2EPs67H4u5DxhTW4lmk9GEMvjUFMQ0KYVqfgaMeOEL00BjEJCZG1Hq3+oLQegvOjKhSCHl2LWUiaipxcrczmSPNj23UdT6XKW55ZLQ7HLzan5KctgjPyT8TbkIgdpG+ASHc0WN+BODarm6BP6BfFQTkgiJPvafEFAAD//wMAUEsDBBQABgAIAAAAIQBOMo6QFgYAAKYkAAARAAAAd29yZC9kb2N1bWVudC54bWzUWttu40QYvkfiHSJfLRKtz4eYTVeOD7uVQKoo+wCuPUmstT3WeNI0XC0XC1wguOBiuWClLgjBE4AEiIdZ0T28BTM+JM6h7cTZkm0vEnv+mW+++eb7/0yc3r13lsSdU4DyCKY9TtwXuA5IAxhG6bDHPfzM2zO4To79NPRjmIIeNwU5d+/g/ffuTswQBuMEpLhDINLcnGRBjxthnJk8nwcjkPj5fhIFCOZwgPcDmPBwMIgCwE8gCnlJEIXiKkMwAHlO5rP99NTPuQouOGNDC5E/IYMpoMIHIx9hcDbHEDcGUfkub6wCSS2AyAolcRVK3hhK4ymrFSClFRBhtYKktkNaszitHZK0iqS3Q5JXkYx2SCt2SlYNDjOQkuAAosTH5BYN+cRHj8bZHgHOfBydRHGEpwRT0GoYP0oftWBERs0QEjncGEHnExiCWA5rFNjjxig1q/F7s/GUulmOr97qEYhl/eUQpyoOxcp5BGKiBUzzUZTNMjxpi0aCoxrk9KpFnCZx3W+SiYzpcll5ckop54As9Cv9k7hkfjWiKDDsCIWYjWChsDhnzSQhLpxP3EqahrgiYwGpAaQVAC0AjAW/xjAqDD6YZyjFiRhTo8Ypd4XiRHNhRcY6tkymAZCDzSDUmkc+TRoryobb2fY+guNsjhZth3Y4L0ITehzYAKuyfzMl8+3IHI/8jNSmJDAPhylE/klMGBEzd4gfO8UO0FeyrfStuARnHVoIuANyfDmB4ZS+ZySimJmP/EPiHEV2dE+3La5oJcUf01a9+iOtJjkqhZ/2OEEQJE1z5FmTAwb+OMY04nUVRRfryFGjqZjwCBVvx3gaE4bmqR/3uAfAp2cukeNpDJVdYj8d1h1AuvfwmEb5KszPkMqX6tqDKc7JoFGUEi7Az7GVR35z4MTEBy/Pv3rz0w+0CZeBZZwrp6ajxIXBlMwaMT2l6wh9lUHMRcnejpjSDYrJoND2GksMGquOY+iu7exIY/m2ayyzaKwaqi4YNNd3obFy2zVWGDTW+7Il296uaoX6LmisMugkKIpouJqwI5202+5FjUFjTfQ8S7OMHWms33aNdQaNJd3qqoq8q5pq3HaNDRaNNcFzRafLoLGtaF2JdlzReDFSaFw1NTTeRMf1XBVLNcSux+KHnXOVBddQLEm6DVxVSxf6nubdPNfFPLNhCCqWdRxBOHARIj3wNCNf1YbIT46xj3CVi6WxA5jmMAb7MRzeWUqQtQhuGi6Mf/H4xxGIY/hhh3xbjMMXj5998BFDrsiSZnuiYjPoZLiC7fV3rVM+zTFI9uEY72eI1KA4baPWnZZyiYYu2oLFlK6u2C3OzqtyLURaytXME8Zvv//+9fOr8y8unj1lWKjqeroraMpWvliMFAutmoq9WDp9aJohGzrLN7o2M7asLrVj6MMbM8/8gBgqQyAH6BRwB5RlZ8l/1HgFrSO0NH29Wws7e5jGUQoa+zvbLgwuQ26YiBGX2SOvn39z8eWT0ik3tbAzvIzMuiuXbkRndSfW+1rRlb7nKExng00SeDuXXcK1qwiWJi99hmme4uiaRfNkJ1wXt2u78+Dr35+8+vPXJTeMSNVGxDuPOsiMyILRYahR/qMoxxBNSREuTbdox+vy4UGNem06MPB+8/0/L7/9ZdluM+JvV6SX539c/P0dg7eFru3alrhUs1VH6kuqPD/gULUcRVAdd51fFiM35m21L3ueJNOJGlwFQ1FFxZ0beQ3Xcrs3WkDV1FjA4qfrx8RZR4QYOSlko3JX0nFS9ozi07juJ8xih2HdVjy65mcDGlmyljCbK5rbf/H109fPf7u6FjfA2R5Rq47sCZq2JL/ueo5o2VfK//8oXf0g8K4rvcf0c4DrGX25v3TElmzV1foiLe47tfrGZf16xWbiLMlTh/yTCmauWA4CfDST+jopimUNjz8nwQnxhSQp9LmgOSLXqqFUWZoNP/EpIoYZaVfKLigajvD89gRiDJP5fQwGjegI+CEg8+oCfSRmDiDEjdvhGBe31XQBjKle1cmE9imaQxjcR/SnOJOeho4iHBCWslYM4ut1F5flD3P8/B+MDv4DAAD//wMAUEsDBBQABgAIAAAAIQC29GeY0gYAAMkgAAAVAAAAd29yZC90aGVtZS90aGVtZTEueG1s7FlLixtHEL4H8h+Guct6zehhrDXSSPJr1zbetYOPvVJrpq2eadHd2rUwhmCfcgkEnJBDDLnlEEIMMcTkkh9jsEmcH5HqHkkzLfXEj12DCbuCVT++qv66qrq6NHPh4v2YOkeYC8KSjls9V3EdnIzYmCRhx719MCy1XEdIlIwRZQnuuAss3Is7n392AZ2XEY6xA/KJOI86biTl7Hy5LEYwjMQ5NsMJzE0Yj5GELg/LY46OQW9My7VKpVGOEUlcJ0ExqL0xmZARdg6USndnpXxA4V8ihRoYUb6vVGNDQmPH06r6EgsRUO4cIdpxYZ0xOz7A96XrUCQkTHTciv5zyzsXymshKgtkc3JD/beUWwqMpzUtx8PDtaDn+V6ju9avAVRu4wbNQWPQWOvTADQawU5TLqbOZi3wltgcKG1adPeb/XrVwOf017fwXV99DLwGpU1vCz8cBpkNc6C06W/h/V671zf1a1DabGzhm5Vu32saeA2KKEmmW+iK36gHq92uIRNGL1vhbd8bNmtLeIYq56IrlU9kUazF6B7jQwBo5yJJEkcuZniCRoALECWHnDi7JIwg8GYoYQKGK7XKsFKH/+rj6Zb2KDqPUU46HRqJrSHFxxEjTmay414FrW4O8urFi5ePnr989PvLx49fPvp1ufa23GWUhHm5Nz9988/TL52/f/vxzZNv7XiRx7/+5avXf/z5X+qlQeu7Z6+fP3v1/dd//fzEAu9ydJiHH5AYC+c6PnZusRg2aFkAH/L3kziIEMlLdJNQoAQpGQt6ICMDfX2BKLLgeti04x0O6cIGvDS/ZxDej/hcEgvwWhQbwD3GaI9x656uqbXyVpgnoX1xPs/jbiF0ZFs72PDyYD6DuCc2lUGEDZo3KbgchTjB0lFzbIqxRewuIYZd98iIM8Em0rlLnB4iVpMckEMjmjKhyyQGvyxsBMHfhm327jg9Rm3q+/jIRMLZQNSmElPDjJfQXKLYyhjFNI/cRTKykdxf8JFhcCHB0yGmzBmMsRA2mRt8YdC9BmnG7vY9uohNJJdkakPuIsbyyD6bBhGKZ1bOJIny2CtiCiGKnJtMWkkw84SoPvgBJYXuvkOw4e63n+3bkIbsAaJm5tx2JDAzz+OCThC2Ke/y2EixXU6s0dGbh0Zo72JM0TEaY+zcvmLDs5lh84z01QiyymVss81VZMaq6idYQK2kihuLY4kwQnYfh6yAz95iI/EsUBIjXqT5+tQMmQFcdbE1XuloaqRSwtWhtZO4IWJjf4Vab0bICCvVF/Z4XXDDf+9yxkDm3gfI4PeWgcT+zrY5QNRYIAuYAwRVhi3dgojh/kxEHSctNrfKTcxDm7mhvFH0xCR5awW0Ufv4H6/2gQrj1Q9PLdjTqXfswJNUOkXJZLO+KcJtVjUB42Py6Rc1fTRPbmK4RyzQs5rmrKb539c0Ref5rJI5q2TOKhm7yEeoZLLiRT8CWj3o0Vriwqc+E0LpvlxQvCt02SPg7I+HMKg7Wmj9kGkWQXO5nIELOdJthzP5BZHRfoRmsExVrxCKpepQODMmoHDSw1bdaoLO4z02Tker1dVzTRBAMhuHwms1DmWaTEcbzewB3lq97oX6QeuKgJJ9HxK5xUwSdQuJ5mrwLST0zk6FRdvCoqXUF7LQX0uvwOXkIPVI3PdSRhBuENJj5adUfuXdU/d0kTHNbdcs22srrqfjaYNELtxMErkwjODy2Bw+ZV+3M5ca9JQptmk0Wx/D1yqJbOQGmpg95xjOXN0HNSM067gT+MkEzXgG+oTKVIiGSccdyaWhPySzzLiQfSSiFKan0v3HRGLuUBJDrOfdQJOMW7XWVHv8RMm1K5+e5fRX3sl4MsEjWTCSdWEuVWKdPSFYddgcSO9H42PnkM75LQSG8ptVZcAxEXJtzTHhueDOrLiRrpZH0Xjfkh1RRGcRWt4o+WSewnV7TSe3D810c1dmf7mZw1A56cS37tuF1EQuaRZcIOrWtOePj3fJ51hled9glabuzVzXXuW6olvi5BdCjlq2mEFNMbZQy0ZNaqdYEOSWW4dm0R1x2rfBZtSqC2JVV+re1ottdngPIr8P1eqcSqGpwq8WjoLVK8k0E+jRVXa5L505Jx33QcXvekHND0qVlj8oeXWvUmr53Xqp6/v16sCvVvq92kMwioziqp+uPYQf+3SxfG+vx7fe3cerUvvciMVlpuvgshbW7+6rteJ39w4Byzxo1IbtervXKLXr3WHJ6/dapXbQ6JX6jaDZH/YDv9UePnSdIw32uvXAawxapUY1CEpeo6Lot9qlplerdb1mtzXwug+Xtoadr75X5tW8dv4FAAD//wMAUEsDBBQABgAIAAAAIQDlI7CA9QMAAKALAAARAAAAd29yZC9zZXR0aW5ncy54bWy0Vttu2zgQfV9g/8HQ8zq6WHZsoU4R3zYp4nZRebHPlETZRHgRSMqu8/U7pETLu3ELp0VeEmrOzJkh53DoDx+/MdrbY6mI4FMvvAm8Hua5KAjfTr2/N6v+2OspjXiBqOB46h2x8j7e/f7bh0OisNbgpnpAwVXC8qm307pKfF/lO8yQuhEV5gCWQjKk4VNufYbkc131c8EqpElGKNFHPwqCkdfSiKlXS560FH1GcimUKLUJSURZkhy3/1yEvCZvE7IQec0w1zajLzGFGgRXO1Ipx8Z+lg3AnSPZ/2gTe0ad3yEMrtjuQcjiFHFNeSagkiLHSkGDGHUFEt4ljl8RnXLfQO52i5YKwsPArs4rH76NIHpFMMrxt7dxjFsOHyLPeUjxNp7RiYd0BxuOfq6YMwKF30YxdHWoI+t2pOg1PW6gJ5JJJJsb1DaY5cnjlguJMgrlQKN70Kuerc78hS2bf3YJOe/gIr8IwXqHpMIyBzXDFAgCzzdABtXBaFiIz0KntZSi5sUDRmD7LrwSQrcwKFCUqUYa8iZbiRjc/amXU4x4Q1/gEtVUb1CWalGB0x7B1m+jNnu+QxLlwJZWKAcdzwXXUlDnV5i0c5gjEmTeRtipYla1wqvlEzqKWp8haTOxgIEjBofznym0FgWMFAiV5PoumgBbTTg8L+H/iQRMWEkKvDFNSfWR4hVsJiUv+J4Xn2qlCTDaWfQLFfyoAMxN5i8go82xwiuMdA3H9k7JbGdWlFRrAqKQj7wAWb1bMlKWWEICAkJbg5yIFAd7zo1S3ysvKOwfcIZbPNiATJ9nQmvBHo7VDs761zpp9e+fyxme50K5xVe4YifXYBEHw8WyqdSgHRJEo9FicAkJV9Eyvr+EjJfBfDW7hMxm0WB+ewmZx6NJNLmILMPJ+GIFCyhiPL+IfHc/q0kc39qe+KcTYYl5dv+SbmWuVY81EXPEMklQb20eZt94ZPJ5RrjDMwzzFJ8jaZ05sN9vAMUQpStosANsc1hSEFUtcGnXdI3ktuNtPeRFK8y8TycuM26x/BMGZ9WgB4mq5ro4lzCO20jC9RNhzq7qLHVRHF6AMwim8Je9tOfUHc8h0SA/O3aekJWx9cW8P/9shIeR0veKoKn3sjOmRvlUpka1eI2qqhF/tg2nHiXbnQ5NmIavAn7S2Y9sG7VYZLGowewHys1mwbtddLbI2c78Bs426Gyxs8Wdbehsw842craRse1g3ElK+DPcQ7c09lJQKg64eOjwVyb3SuUERJAeWdY9PjcNRomCwVDBO6WFdNgfFgvjpBD5o3ls48Y+nIwXy8mg0XY4tO+btrMDjvYrLmdI4aJRt/tpffcvAAAA//8DAFBLAwQUAAYACAAAACEAQMH/8TkBAAAjAwAAFAAAAHdvcmQvd2ViU2V0dGluZ3MueG1snNJfT8IwEADwdxO/w9J36CCykIVBYgzGF2OifoDS3aCx7S294sBP720CYnhhvvT//XLXdrbYOZt8QiCDvhCjYSoS8BpL49eFeH9bDqYioah8qSx6KMQeSCzmtzezJm9g9Qox8klKWPGUO12ITYx1LiXpDThFQ6zB82aFwanI07CWToWPbT3Q6GoVzcpYE/dynKaZODDhGgWrymh4QL114GMXLwNYFtHTxtR01JprtAZDWQfUQMT1OPvjOWX8iRndXUDO6ICEVRxyMYeMOorDR2k3cvYXmPQDxhdApmHXz5geDMmR544p+znZyTHlmfO/ZM4Agn7E5JgH7V1bkdP509pjUCvLEr9RwtecdHDbcrZt1w35+Jx/LdbROPMFSwz3ARuCINtlZS02L8+PPJF/vvb8GwAA//8DAFBLAwQUAAYACAAAACEAOdtFTLkFAAAnWgAAEgAAAHdvcmQvbnVtYmVyaW5nLnhtbOyczW7qRhiG95V6D8j7xP8/oEOOwECV6rQ60knV9WAGsGKPrbGB0FV7Ke266q430EvpDfQWOuOxzZ9DbIMw5MwmDuP5Xs/3zjfDk0nCh48vvtdaQhy5AeoK8r0ktCBygomLZl3hp6fRnSW0ohigCfACBLvCGkbCx4dvv/mw6qCFP4aYdGwRDRR1VqHTFeZxHHZEMXLm0AfRve86OIiCaXzvBL4YTKeuA8VVgCeiIslS8l2IAwdGEdGxAVqCSEjlnJdyahMMViSYCmqiMwc4hi8bDbmyiC62RetQSKkhRDJU5EMptbKUIdJRHQhptYTIqA6U9HpKBckZ9ZSUQyWznpJ6qGTVUzooJ/+wwIMQInJzGmAfxOQlnok+wM+L8I4IhyB2x67nxmuiKRmZDHDRc40RkahcwVcnlRVM0Q8m0FMnmUrQFRYYddL4uzyeDr3D4tNLFoHL5M9CBoGz8CGKk8xFDD3iRYCiuRvmK9yvq0ZuzjOR5bEklr6X9VuFcsnl8tr2NGBWbgTLDD/13/fYyI8rylKJGaESeUSZIew+MxuJT6pw8+Ba1myZK5fcQDIB5UDAcGDJDT/TsFIN0dmsUKrjllwamQ6bFarjboyVS+5j+4PZEohgNQk9G0e09rcyCmenle13OFiEGzX3NLXHzSa0ojxQQSst/+0lGZ02mC9zEJK9yXc6jzMUYDD2yIhIMbdIPbaSGaBfybTSS/ItfGnRjUB4IPwCxlGMgRP/uPBbO68eSQERDiIiHQwJ/GDayFCnN40h7mMInmkXqoIiKt9ZAo+0jJS+ItuKINI7/sKL3U9wCb2ndQizPkmrR1tZr9gPveyeatvSUJE0dsdb0hsuuWTPSsaSdZZZL0JhIz9vHC88D8Z5/BN8yW/9++sfefv3TtbqwWnaPfyM6cVFNB3a3BU0hdrQmQM0S3iQviZ9xbwzTi+jAMURNTFyXFJgP5PelCCjJLpHLNpvcxGRn8ApIG6wx4+Tr25uJWuNfskalCRfMX2mmKSx75J8ukv//F7VJEu7nEkbO2T9bTuU0+3477e/q/ohK8alDDmevnqO9P+snL5hXUf6bJM7Mf2/qqavyNJ1pK83UvyKfrEt83j6RiPFr7QvthkeT99spPhV9Uq2PquR4lfNxrY+cQfg6DOO0p1ch+4Uua1LumWw/KvTXbsvGX1LS+O3p+sMdJc+r/xkXRPblYEZznY7dnC2Oz19znbV0udsx9mOsx1nuwunX5HtlDpsp2rKSB5ItdlOaxu2aitWbms+Xfzk7kIndzXW9OXwjsMchzkOc4Xpc5hroPg5zHGYuwWYU2vBXNvWTcsasvyLYW6+HmN38sMRpDN7pqbpmpabm09a4l0cek5XsI2BNVRNu8Y0hl/itZeP55MbxZ8BBjMMwnnhPH8FJ3y5rZakS0N5dAZ2fl9nfrlBw/5Is4b9s7x5XDM4VrWI7hepRZImtSVJYlUFUQxidwnP9JPGLcPmvkHMsjMbdMs4um8QazmzQbcMrPsGXccSuyKk3TfoOpbYFUHvvkHXscRuB4vpLl4HiwdqXxqw/KufcQ7aQ0Oib/2ZrfmEvv8zTn6ayU8z+WkmP818M31+mtlA8fPTTH6aeQvYRjG3Mrbplq0aZttm+VfHNsM2FG3YTk9Dt6frDNhWY7FybOPYtsmeYxvHNo5tHNsaTZ9jWwPFfzvYRk+8K2ObOVBHqmFpLP/q2NYb9CRTVtL47el679jGIe317DmkNVD6HNI4pHFI45DWaPoc0o5DGv2te3VIG/ZNc9QbsPyrQxrZGwzLlL/Kf/vgZ2sc2zi2cWx7M32ObQ0UP8c2jm1Xgm0owTWUffIKbdphtywjNZVDBWHsDbQwLPmf3VfC2BtPYVj2x+RFYQefD7gJM4+EsY2uMEw7EsY2iMKw5JMEXwljC6swLJvrojBWkIVhGcYlYezKIPrhfwAAAP//AwBQSwMEFAAGAAgAAAAhAPiVyO/8DgAA85kAAA8AAAB3b3JkL3N0eWxlcy54bWzsXd9zo0YSfr+q+x8oPSUPG/+QLTtbcVJr2T67btdxVt5L3eMIRhZnYHSA1uv89TczDAjUDKKHjuu8m6RqLQH9MczXX890A5qffvkSR95nnmahSM5GBz/sjzye+CIIk4ez0af7qzenIy/LWRKwSCT8bPTMs9EvP//9bz89vc3y54hnngRIsrexfzZa5vnq7d5e5i95zLIfxIoncudCpDHL5df0YS9m6eN69cYX8Yrl4TyMwvx573B/fzIyMGkfFLFYhD6/EP465kmu7fdSHklEkWTLcJWVaE990J5EGqxS4fMskxcdRwVezMKkgjk4AkBx6KciE4v8B3kxpkUaSpof7OtPcbQBOMYBHAKAic+/4DBODcaetKzjhAEOZ1LhhEENx60xNYCM4yCOy3Zkz7G6oth/e/OQiJTNI4kkOfJkN3saWP0rW6v+6I/y8J+lwwbCv+ALto7yTH1N71Lz1XzTf65Ekmfe01uW+WF4L9slweNQnuf6XZKFI7mHsyx/l4WsvvPSbFP7l+rAVks/y2ubz8MgHO2pk2Z/yJ2fWXQ2Ojwqt0xVIxrbIpY8lNt48mZ6W2/M2eiPpdk0l7hnI5a+mb1Thnvm2oq/tSteVd+Ko7a6R+pJqmtWiFzu5Yv3wn/kwSyXO85G++pUcuOnm7s0FKkU8tnoxx/NxhmPw+swCHhSOzBZhgH/fcmTTxkPNtt/u9JiNBt8sU7k5/HJRFMWZcHlF5+vlLTl3oSp3rtVBpE6eh1uTq7N/1uCHZg+a7Nfcqbim3ewDaGbj4I4VBZZ7WrbMddb166PQp1o/FInOnqpEx2/1IkmL3Wik5c60elLnUjD/JknCpOAfymECE8DUHfhWNSIxrGIDY1j0RIaxyIVNI5FCWgci6OjcSx+jMaxuCkCJxe+zQtrzj62eHs37u4xwg1395Dghrt7BHDD3R3w3XB3x3c33N3h3A13d/R2w90drPG4xVTLu5EyS/LBKlsIkSci517OvwxHY4nE0kkfDZ4a9HhKcpEEMEVkMwPxYDSf6e+7PUSL1H08z1U25omFtwgf1inPBjecJ595JLN2jwWBxCMETHm+Ti094uLTKV/wlCc+p3RsOtAoTLiXrOM5gW+u2AMZFk8C4u4rEUmCQuXQbJ0vlUhCAqeOmZ+K4U0TjCw+vA+z4X2lQLzzdRRxIqxbGhfTWMNzAw0zPDXQMMMzAw0zPDGocUbVRQaNqKcMGlGHGTSifiv8k6rfDBpRvxk0on4zaMP77T7MIx3i67OOg/61u2kkVJl+cDtm4UPC5ARg+HBjaqbeHUvZQ8pWS0+VkNth69eMPc+5CJ69e4oxrUKimtdrF5nKqw6T9fAObaBRiavCI5JXhUcksApvuMQ+yGmymqBd0+Qzs/U8bxWtRuol2hmL1sWEdrjaWD7cwzYCuArTjEwG7bAEHnyrprOKTorIt2nl8IZtsIbLajsqkTbPQBK0MhL+I00Yvn5e8VSmZY+Dka5EFIknHtAhzvJUFL5Wl/yhpqSX5C/j1ZJloc6VGhD9h/ryBr/3ga0GX9BdxMKEhrfLNzELI49uBnF9/+G9dy9WKs1UHUMDeC7yXMRkmKYS+N3vfP49TQPfySQ4eSa62ndE5SENNg0JBpkCSQRESHKaGSYhyRiq8f7Jn+eCpQEN2l3Ki2dqck6EOGPxqph0EGhLxsUnGX8IZkMa718sDVVdiEpU9yRgtbJhtp7/h/vDQ92t8EgqQ7+uc11/1FNdbU0HN3ya0IAbPkXQbMrhQfkvwcU24IZfbAOO6mKnEcuy0HoL1RmP6nJLPOrrHZ78GTwRiXSxjug6sAQk68ESkKwLRbSOk4zyijUe4QVrPOrrJXQZjUdQktN4/0jDgIwMDUbFhAajokGDUXGgwUgJGP6ETg1s+GM6NbDhz+oUYERTgBoYlZ+RDv9Ed3lqYFR+psGo/EyDUfmZBqPys/GFxxcLOQmmG2JqkFQ+V4OkG2iSnMcrkbL0mQjyMuIPjKBAWqDdpWKhXrYQSfEQNwGkqlFHhJPtAo6K5N/5nKxpCouyXQQVURZFQhDV1jYDjrZsPru2y0y/czG4CXcR8/lSRAFPLddkt5X58mzFfFOmB7f7epU934cPy9ybLatqfx1msr/TskzYG2a7T9jW55PDDrMPPAjXcdlQ+DLFZNzfWHt0w7h856XDeDOTaFge97SE55zsttzMkhuWJz0t4TlPe1pqnTYsu/RwwdLHVkc46fKfKsezON9JlxdVxq2n7XKkyrLNBU+6vKghFe+d76u7BZCdfpqx2/cTj90eoyI7CkZOdpTeurJDdAnsI/8cqpEdEzT1+aqnJ0Dc15PoXpHzt7Uo6vaNG079X+q6kROnJONeK864/42rRpSx92PvcGOH6B137BC9A5AdolckspqjQpIdpXdsskP0DlJ2CHS0giMCLlpBe1y0gvYu0QqiuESrAbMAO0Tv6YAdAi1UCIEW6oCZgh0CJVRg7iRUiIIWKoRACxVCoIUKJ2A4oUJ7nFChvYtQIYqLUCEKWqgQAi1UCIEWKoRACxVCoIXqOLe3mjsJFaKghQoh0EKFEGih6vniAKFCe5xQob2LUCGKi1AhClqoEAItVAiBFiqEQAsVQqCFCiFQQgXmTkKFKGihQgi0UCEEWqjFq4buQoX2OKFCexehQhQXoUIUtFAhBFqoEAItVAiBFiqEQAsVQqCECsydhApR0EKFEGihQgi0UPXNwgFChfY4oUJ7F6FCFBehQhS0UCEEWqgQAi1UCIEWKoRACxVCoIQKzJ2EClHQQoUQaKFCiC7/NLcobY/ZH+CrntYn9vvfujKN+lh/lbsONe4PVbbKjtX/XYRzIR691hcPxzrf6AcSzqNQ6BK15bZ6HVc/EoG68fnrtPsNnzr6wB9dMu9C6HumAPyoryWoqRx1uXzdEiR5R12eXrcEs86jruhbtwTD4FFX0NW6LB9KkcMRMO4KMzXjA4t5V7SumcMu7orRNUPYw12RuWYIO7grHtcMjz0VnLetj3v206R6vhQgdLljDeHEjtDllpCrMhxDYfQlzY7Qlz07Ql8a7QgoPq0weGLtUGiG7VBuVEOZYal2F6odAUs1RHCiGsC4Uw2hnKmGUG5Uw8CIpRoiYKl2D852BCeqAYw71RDKmWoI5UY1HMqwVEMELNUQAUv1wAHZCuNONYRyphpCuVENJ3dYqiEClmqIgKUaIjhRDWDcqYZQzlRDKDeqQZaMphoiYKmGCFiqIYIT1QDGnWoI5Uw1hOqiWldRGlSjGK6Z4yZhNUPcgFwzxAXnmqFDtlSzdsyWagiO2RLkquQcly3VSbMj9GXPjtCXRjsCik8rDJ5YOxSaYTuUG9W4bKmNaneh2hGwVOOyJSvVuGypk2pcttRJNS5bslONy5baqMZlS21UuwdnO4IT1bhsqZNqXLbUSTUuW7JTjcuW2qjGZUttVOOypTaqBw7IVhh3qnHZUifVuGzJTjUuW2qjGpcttVGNy5baqMZlS1aqcdlSJ9W4bKmTaly2ZKcaly21UY3LltqoxmVLbVTjsiUr1bhsqZNqXLbUSTUuW/ogTUKCn4CaxSzNPbrfi7tm2TJnw3+c8FOS8kxEn3ng0V7qe9RV7j01lr9S2Hq1O3l8LvtM/QJ67XWloPgFWAOoD7wJqmWqlLFqiWeW7jKbdYPN7Vr9Oc1kTm2O2d8/Pz8cT43UVsXSZFnxZqk8Rv1a0dloPNGvJKkvH9dqDTS2zoVpvTbZM43Z0fyqweb+8wFo8mbBLN2eOZM99avqYXBBifqxxZbtysnK7eVppkuWFns37l8eYwRu75+Lo/3ji8tG/zxyvrqV59fb1BfJOc/0t03XzdXvlHG1qJoRvyh+/On956gCr/ehZWE4qcRyrTrv3+yaNxaGa92pV4Vr3eNnZ6P7MOaZd8ufvI8iZon3nemkzJvOvje9rv/1VfjYdIP6T2HodeV0aDkbqd+9N0xtFpYrb5TXF5Yb60hTWx/OxVsOrd5i4hiNtxz28JamlP9kB7L7TxlBvir/GZuJQ2NhQr1toP+Mrf5jHgqh8Z/x6/GfUpVfl/9QxJojq6+Y6EbjK0evx1e0Rv5ffSWcFhfk7DPlSDzEZ46tPmMeAKPxmePX4zNaK19DfBnoGcUKs22eYcY6Gs+YvB7P0Ir4yzMeTqyeYTIyGs84eT2eUc70vppxZqCHnFo9xBS3aDzk9PV4iFbGq4gdhyfq/3bPKDfeh2oV8gtDZiPp6ek+vmSO+eYnxy0VIrN0UPXbN3rhoG3HsqwvZHGKchJVlbnafcTe7lzVKTvarOuYnaWtotRp9VrjtrtaKNszjwonkh9uEuXET2aV96KlwRdWQMn9Ux5FH1hxtFjZD434QmlP7j3Y1780ubV/XiyaYLVPdXXdCrDXbEzxtdtPimUUw+K1D2slUZWQW7pbv4M0tKd7+rC/zmTXzNQB2+1rVPS2W2l2egfeJphtRcdWHdhiovFwazy0B7y/KnlIQouim43QQyJCTZ3wmyV0SGkNSWhRBbMROiYi1BTuvl1C/xw1FmUpG3lHROSZ6PLqyXup4hOSxKJOZCPxmIhEU9r6phRITlVRuLFRNSGiygT/v6gaQlVRSbFRdUJElSn+fJOhkZyyorRho+yUiDKTwH9d6nqZAkaj/tXBp17ibptHvbGNvX5Pv5xe7k+vzoujTEFpdR7U0nt9nFoI2qyb9oe6raE+rJhftlD32eapmCr532GrPwPbqjDgdOaybOBwalVSM5eeLasu8iPOCqHVjpZfF2Ek916eXE4u9YNl2heu9MY58x8fUrFOgn43mKciyUTE9O+BbFx8FsaztX4oy3h2/bBWl9aLsFbuHDFdT9QXwZM3n2a0weUmUWXJVpes7cKFFWuRrZ//EnVv0eagCgKJSCof0mHb+JD+DByQ1HVoWNwMCNVTiNuUbfYMZayshbWUGZvMTS8Pfjw1CaxhrjlMHk/G002YNbF32WzoujzaSH1A52weiCyfh9zupJZHJql6a3eNFtd5k/3jy+Mp1iMPLq4uLhzGrKoPVZF08/vy2/2nn87d7G7ru/qgBXtrbFJm1F2XZB0XH8Jo68kfve+msi5Ha2MAwnZPKZafsp//BwAA//8DAFBLAwQUAAYACAAAACEAzJJQVH0BAADxAgAAEQAIAWRvY1Byb3BzL2NvcmUueG1sIKIEASigAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAjJLLTsMwEEX3SPxD5H1qJ+WlKE3FQ6yoQKIViJ2xJ60hsS17IPTvcZI2JYgFO4/n+GRy7Xz+VVfRJzivjJ6RZMJIBFoYqfR6RlbL2/iCRB65lrwyGmZkC57Mi+OjXNhMGAcPzlhwqMBHwaR9JuyMbBBtRqkXG6i5nwRCh2ZpXM0xlG5NLRfvfA00ZeyM1oBccuS0FcZ2MJKdUopBaT9c1QmkoFBBDRo9TSYJPbAIrvZ/Hug6P8ha4dbCn+i+OdBfXg1g0zSTZtqhYf6EPi/uHrtfjZVusxJAilyKDBVWUOT0sAwr//H6BgL77aEIa+GAo3HFQglnvCkxui9LJSBaeXAdvSfa7N9h2xgnffCMqoBJ8MIpi+FG+6+MNgJdcY+LcMWlAnm1LS5Pz9OzTvOr0bIOPlX7NoqkI4Yy3wXdDwUyCgFlfZz7ztP0+mZ5S4qUpUnMTuIpW7I0O00zxl7auUbnD8J6N8A/jdOMnYyNe0EfzfiRFt8AAAD//wMAUEsDBBQABgAIAAAAIQAiURHx1QEAAN4DAAAQAAgBZG9jUHJvcHMvYXBwLnhtbCCiBAEooAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJxTwW7bMAy9D9g/GLo3crKh6AJFxZBi6GFDA8Rtz5xMJ8JsSZDYINnXj7YTT9l2mk/vkfTTE0mp+2PXFgeMyXq3EvNZKQp0xtfW7VbiufpycyeKROBqaL3DlThhEvf6/Tu1iT5gJIupYAmXVmJPFJZSJrPHDtKM044zjY8dENO4k75prMEHb946dCQXZXkr8UjoaqxvwiQoRsXlgf5XtPam95deqlNgPa0q7EILhJrOYFZ7Oio5xVXlCdrKdqjnJccnpjaww6TnSo5AvfpYJ724U3JEar2HCIa4h3p++0HJjKvPIbTWAHF39Tdrok++oeJpsFz0/yuZlyi+xhbNW7R00mwjp+qrdaOREbCxCLsIYX92NzG1NdDimhugG2gTKvk7oB4R+uFuwPb+DrQ8oCEfi2R/8ngXovgOCfu2rcQBogVHYiwbyYDbkCjqylLL2hMfYF6WY/uxNzmC68KBDB4YX7sbTkhPDd+N/mF2npsdPIxWMzu5s8sZf6iufRfAcX/lhLjBP9JzqPxDvxrnHl4Hs6m/WtpvA5h+OJ/KfP5ZRm05ijUPdJrJFFCPfIPY9vr8r9thfan5O9Fv1Mv4XHnbZiV/wwpdYrwI0zvSvwAAAP//AwBQSwMEFAAGAAgAAAAhAIg/pb/hAAAAVQEAABgAKABjdXN0b21YbWwvaXRlbVByb3BzMS54bWwgoiQAKKAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAnJDBasMwEETvhf6D2bsiObFdEyyHuE4g19JCroq8tgWWZCS5tJT+e2V6So89LbPDzhu2OnzoKXlH55U1HNINgwSNtJ0yA4e31zMpIfFBmE5M1iAHY+FQPz5Und93IggfrMNLQJ3EhYrz0nL4ykvW5E87Rsr2nJLilDXkmKUNKTKWt8fnU8pY8Q1JRJsY4zmMIcx7Sr0cUQu/sTOaaPbWaRGidAO1fa8ktlYuGk2g25hA5RLx+qonqNc+v9cv2Pt7uVZbnPov5aZuk7KDE/P4CbSu6B/Uqu9eUf8AAAD//wMAUEsDBBQABgAIAAAAIQDBJ8sItgAAACEBAAATACgAY3VzdG9tWG1sL2l0ZW0xLnhtbCCiJAAooCAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACskE0OgjAQRq9CegCKLlgQfmKiWzEhcV/KAE3aGdIOBm5v1egJXE7mfS/zTdlsziYP8MEQVuKQZiIJrHBQlhAqgSSauuyLjlavISSRxlD0lZiZl0LKoGdwKqS0AMbdSN4pjqOfJI2j0XAmvTpAlscsy2Vvemto8mqZd/GR/UfVgQXNMHS823i2PN1Ondl4vgyGY7P2LWjRGoR0CzYGXuBVuQhHViT37wtyUZfyV7h+AgAA//8DAFBLAwQUAAYACAAAACEAdD85esIAAAAoAQAAHgAIAWN1c3RvbVhtbC9fcmVscy9pdGVtMS54bWwucmVscyCiBAEooAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIzPsYrDMAwG4P3g3sFob5zcUMoRp0spdDtKDroaR0lMY8tYamnfvuamK3ToKIn/+1G7vYVFXTGzp2igqWpQGB0NPk4Gfvv9agOKxcbBLhTRwB0Ztt3nR3vExUoJ8ewTq6JENjCLpG+t2c0YLFeUMJbLSDlYKWOedLLubCfUX3W91vm/Ad2TqQ6DgXwYGlD9PeE7No2jd7gjdwkY5UWFdhcWCqew/GQqjaq3eUIx4AXD36qpigm6a/XTf90DAAD//wMAUEsDBBQABgAIAAAAIQDrgGBMUwMAAI8OAAASAAAAd29yZC9mb250VGFibGUueG1szJbPb9MwFMfvSPwPUU7jwJqkXZdV66Y2WzQk2IEVAUc3cVqL2I7itF3/AA6IE+LI38C4gwb/DNPYf8FznLRZm25LQbBGzY9n+5vnT57f8+7+KQ21MY4F4aytm5uGrmHmcZ+wQVt/0XMf27omEsR8FHKG2/oUC31/7+GD3Ukr4CwRGoxnokW9tj5MkqhVqwlviCkSmzzCDBoDHlOUwGM8qFEUvxlFjz1OI5SQPglJMq1ZhtHUM5n4Lio8CIiHD7g3opgl6fhajENQ5EwMSSRytcld1CY89qOYe1gImDMNlR5FhM1kzMaSECVezAUPkk2YTOZRKgXDTSO9o+FcYKuagLUk0PTwaTUNO9OowciiDvGr6TRnOsQv6KznTEFA4GoSW7kfYkrljKjXejJgPEb9EJTgG2mAWUuF5Rm8lZf0FrrvZfGqTVoMURjwEj62DHKRNkWIcYFNaB2jsK0bW8bST6/Jjt4QxQJLmbRj40CZA0RJOM2tPvbAr4SMsWqNSOIN88Yxion0WTUJMoCGkegb8Fb1q+vKYsJyzN+tLNasT26pX7d4qY6tDGZmMQt94J01BWIJSI9QLLRjPNGec4pYKRYLjqZRBzwN+Ftw1yjFktO6jiVOdasQgaVoWB17e04km9syEfsmIoqH61Yj4qCQ9GOygoSbEpBHAzhYlUiICRGiEomOdNY6TGegSDSkwdjuVosN9bxTkcQBZoNXJAsKFCbHYM19vvz87vLrj2wyS5RMiBcIabhmRyklu1lGCY0SvgakbgFS3XbcbcftLEIym7dAknQrQnqWZy/tNTrCKmwWWF18P/t1/uXq09urbx9WEetCXMl4knGVnisQqx5X6XqyiivM6jhu3dmy1kFmVkS2kHO0jSOM0qSsOSePygAuJqmVDJsZvWyF/oUs5eMAjcLkxoQB+w8eovKSorzaWTNjUO7juMytgJxif/m7HsrSYamMN88XrjOzzPPFzu2Zs2q+OCH0ZFSaLS7O3v88/3gvskU2j0K5tWzbzadfOVv8WbnVNrrcn96PsGc86cUj3JtGeK1lkFcL7SkZDJPVNSNrvw+x8H8rR7bRKPAq226oovBvthuHEkenmD4caWmUbDfukD5u3XhlN2LvNwAAAP//AwBQSwECLQAUAAYACAAAACEAZPVj7oEBAAApBgAAEwAAAAAAAAAAAAAAAAAAAAAAW0NvbnRlbnRfVHlwZXNdLnhtbFBLAQItABQABgAIAAAAIQAekRq37wAAAE4CAAALAAAAAAAAAAAAAAAAALoDAABfcmVscy8ucmVsc1BLAQItABQABgAIAAAAIQAzwlu/QQEAAOcEAAAcAAAAAAAAAAAAAAAAANoGAAB3b3JkL19yZWxzL2RvY3VtZW50LnhtbC5yZWxzUEsBAi0AFAAGAAgAAAAhAE4yjpAWBgAApiQAABEAAAAAAAAAAAAAAAAAXQkAAHdvcmQvZG9jdW1lbnQueG1sUEsBAi0AFAAGAAgAAAAhALb0Z5jSBgAAySAAABUAAAAAAAAAAAAAAAAAog8AAHdvcmQvdGhlbWUvdGhlbWUxLnhtbFBLAQItABQABgAIAAAAIQDlI7CA9QMAAKALAAARAAAAAAAAAAAAAAAAAKcWAAB3b3JkL3NldHRpbmdzLnhtbFBLAQItABQABgAIAAAAIQBAwf/xOQEAACMDAAAUAAAAAAAAAAAAAAAAAMsaAAB3b3JkL3dlYlNldHRpbmdzLnhtbFBLAQItABQABgAIAAAAIQA520VMuQUAACdaAAASAAAAAAAAAAAAAAAAADYcAAB3b3JkL251bWJlcmluZy54bWxQSwECLQAUAAYACAAAACEA+JXI7/wOAADzmQAADwAAAAAAAAAAAAAAAAAfIgAAd29yZC9zdHlsZXMueG1sUEsBAi0AFAAGAAgAAAAhAMySUFR9AQAA8QIAABEAAAAAAAAAAAAAAAAASDEAAGRvY1Byb3BzL2NvcmUueG1sUEsBAi0AFAAGAAgAAAAhACJREfHVAQAA3gMAABAAAAAAAAAAAAAAAAAA/DMAAGRvY1Byb3BzL2FwcC54bWxQSwECLQAUAAYACAAAACEAiD+lv+EAAABVAQAAGAAAAAAAAAAAAAAAAAAHNwAAY3VzdG9tWG1sL2l0ZW1Qcm9wczEueG1sUEsBAi0AFAAGAAgAAAAhAMEnywi2AAAAIQEAABMAAAAAAAAAAAAAAAAARjgAAGN1c3RvbVhtbC9pdGVtMS54bWxQSwECLQAUAAYACAAAACEAdD85esIAAAAoAQAAHgAAAAAAAAAAAAAAAABVOQAAY3VzdG9tWG1sL19yZWxzL2l0ZW0xLnhtbC5yZWxzUEsBAi0AFAAGAAgAAAAhAOuAYExTAwAAjw4AABIAAAAAAAAAAAAAAAAAWzsAAHdvcmQvZm9udFRhYmxlLnhtbFBLBQYAAAAADwAPANQDAADePgAAAAA=",rZ=()=>Im(oZ);async function iZ(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 Ik(n,t){if(n.width&&n.height)return{width:n.width,height:n.height,buffer:t};const e=await jl(new File([t],"",{})),o=await iZ(e);return o.width===void 0||o.height===void 0?{width:345,height:230,buffer:t}:n.width||n.height?{width:n.width||o.width*n.height/o.height,height:n.height||o.height*n.width/o.width,buffer:t}:{width:o.width,height:o.height,buffer:t}}function sZ(n,t){let e=n.filter(s=>s!=null);const o=t-(e.length-1)*20,r=.87,i=e.reduce((s,l)=>s+l.width,0);return i>o&&(e=e.map(s=>({width:s.width*o/i,height:s.height*o/i,buffer:s.buffer}))),e.map(s=>({width:s.width*r,height:s.height*r,buffer:s.buffer}))}function Tk(n=[0,1,2,3,4,5,6,7],t=1){return n.map(e=>{let o;switch(e%3){case 0:o=gt.LevelFormat.DECIMAL;break;case 1:o=gt.LevelFormat.LOWER_LETTER;break;default:o=gt.LevelFormat.LOWER_ROMAN;break}return{level:e,format:o,text:`%${e+1}. `,alignment:gt.AlignmentType.START,start:t,style:{paragraph:{indent:{left:gt.convertInchesToTwip(.3*(e+1)),hanging:gt.convertInchesToTwip(.2)}}}}})}function lZ(){return[0,1,2,3,4,5,6,7].map(n=>{let t;switch(n%3){case 0:t="\u2022";break;case 1:t="\u25E6";break;default:t="\u25AA";break}return{level:n,format:gt.LevelFormat.BULLET,text:t,alignment:gt.AlignmentType.START,style:{paragraph:{indent:{left:gt.convertInchesToTwip(.3*(n+1)),hanging:gt.convertInchesToTwip(.2)}}}}})}function cZ(){return[0,1,2,3,4,5,6,7].map(n=>({level:n,format:gt.LevelFormat.BULLET,text:"\u2611",alignment:gt.AlignmentType.START,style:{paragraph:{indent:{left:gt.convertInchesToTwip(.3*(n+1)),hanging:gt.convertInchesToTwip(.2)}}}}))}function aZ(){return[0,1,2,3,4,5,6,7].map(n=>({level:n,format:gt.LevelFormat.BULLET,text:"\u2610",alignment:gt.AlignmentType.START,style:{paragraph:{indent:{left:gt.convertInchesToTwip(.3*(n+1)),hanging:gt.convertInchesToTwip(.2)}}}}))}var Hu=(n=>(n.NUMBERING="number-numbering-reference",n.BULLET="number-bullet-reference",n.CHECKED="checked-bullet-reference",n.UNCHECKED="unchecked-bullet-reference",n))(Hu||{});const uZ=[{levels:Tk(),reference:"number-numbering-reference"},{levels:lZ(),reference:"number-bullet-reference"},{levels:cZ(),reference:"checked-bullet-reference"},{levels:aZ(),reference:"unchecked-bullet-reference"}];function dZ(n){switch(n){case"style-color-0":return"d83931";case"style-color-1":return"de7802";case"style-color-2":return"dc9b04";case"style-color-3":return"2ea121";case"style-color-4":return"245bdb";case"style-color-5":return"6425d0";case"style-color-6":return"8f959e";default:return}}function hZ(n){switch(n){case"style-bg-color-1":case"style-bg-color-2":case"style-bg-color-8":case"style-bg-color-9":return"yellow";case"style-bg-color-0":case"style-bg-color-5":return"magenta";case"style-bg-color-3":return"green";case"style-bg-color-4":case"style-bg-color-11":return"blue";case"style-bg-color-6":return"lightGray";case"style-bg-color-7":return"red";case"style-bg-color-10":return"darkGreen";case"style-bg-color-12":return"darkMagenta";case"style-bg-color-13":return"darkGray";default:return}}function fZ(n){switch(n){case"style-bg-color-0":return"fbbab6";case"style-bg-color-1":return"ffdcb0";case"style-bg-color-2":return"fff7a0";case"style-bg-color-3":return"ceefc5";case"style-bg-color-4":return"d1ddfb";case"style-bg-color-5":return"d9cbf8";case"style-bg-color-6":return"eaeaea";case"style-bg-color-7":return"fe837c";case"style-bg-color-8":return"ffbd6a";case"style-bg-color-9":return"ffe662";case"style-bg-color-10":return"a8f393";case"style-bg-color-11":return"98b5ff";case"style-bg-color-12":return"b394f8";case"style-bg-color-13":return"b1b1b1";default:return}}const mZ=/rgb\((\d+),\s*(\d+),\s*(\d+)\)/;function Dk(n){if(typeof n=="string"&&n.length>0){if(n[0]==="#")return n.substring(1);const t=n.match(mZ);if(t){const e=s=>{let l=Number(s).toString(16);return l.length<2&&(l=`0${l}`),l},o=e(t[1]),r=e(t[2]),i=e(t[3]);return`${o}${r}${i}`}if(n==="red")return"FF0000";if(n==="green")return"00FF00";if(n==="blue")return"0000FF"}}function tn(n,t){if(n&&n.attributes&&n.attributes[t])return n.attributes[t];if(n&&n.attributes&&n.attributes.box&&n.attributes.inputType&&t==="style-underline")return!0}function Sk(n,t,e){for(let o=0;o<=e;++o){const r=`${t}${o}`;if(tn(n,r))return r}}function r1(n,t,e){n.attributes=n.attributes||{},n.attributes[t]=e}function Q2(n){return n==="image"||n==="drawio"||n==="plantuml"||n==="mermaid"||n==="flowchart"}function Lk(n){return n&&n.startsWith("//")?`https:${n}`:n&&!n.startsWith("http://")&&!n.startsWith("https://")?`https://${n}`:n}function gZ(n){const t=tn(n,"inlineStyle");if(t==null)return;const e=t.split(";");for(const o of e){const r=o.split(":");if(r.length!==2)continue;const i=r[0].trim().toLowerCase(),s=r[1].trim().toLowerCase();i==="font-size"&&r1(n,"inline-style-font-size",s),i==="color"&&r1(n,"inline-style-color",s),i==="background-color"&&r1(n,"inline-style-background-color",s),i==="font-family"&&r1(n,"inline-style-font-family",s)}}function pZ(n,t){if(t==null)return n==null?void 0:n.normal;if(n)return n[`heading${t}`]}function CZ(n){const t=`${tn(n,"inline-style-font-size")}`;if(t&&t.indexOf("px")>0)return+t.replace(/px/g,"")}function AZ(n){if(n.attributes&&n.attributes.box&&n.attributes.text)return` ${n.attributes.text} `;if(n.attributes&&n.attributes.box&&n.attributes.inputType)return n.attributes.value?`${n.attributes.value}`:" "}function bZ(n){if(n.attributes&&n.attributes.box&&n.attributes.text)return` @${n.attributes.text} `}function vZ(n){return tn(n,"inline-style-font-family")}function yZ(n){const t=tn(n,"inline-style-background-color");return Dk(t)}function kZ(n){const t=tn(n,"inline-style-color");return Dk(t)}function wZ(n){gZ(n);const t=tn(n,"type")==="mention";return{box:n.attributes&&n.attributes.box?n.attributes:void 0,inlineCode:!!tn(n,"style-code"),link:Lk(tn(n,"link")),size:CZ(n),text:t?bZ(n):AZ(n)||n.insert,bold:!!tn(n,"style-bold"),underline:!!tn(n,"style-underline"),italics:!!tn(n,"style-italic"),strike:!!tn(n,"style-strikethrough"),superScript:!!tn(n,"style-super"),subScript:!!tn(n,"style-sub"),math:tn(n,"type")==="math"?tn(n,"src"):void 0,mention:t,fontFamily:vZ(n),background:yZ(n),color:t?"338fe5":dZ(Sk(n,"style-color-",6))||kZ(n),highlight:Sk(n,"style-bg-color-",13)}}function BZ(){return[new gt.Paragraph({border:{top:{color:"auto",style:gt.BorderStyle.DASHED,size:4,space:1}},spacing:{before:300}}),new gt.Paragraph({spacing:{line:0}})]}function EZ(){return new gt.Paragraph({children:[new gt.TextRun({text:"[\u89C6\u9891\u6682\u4E0D\u652F\u6301\u5BFC\u51FA]",shading:{type:gt.ShadingType.CLEAR,color:"FFFFFF",fill:"CCCCCC"}})]})}function xZ(){return new gt.Paragraph({children:[new gt.TextRun({text:"[\u97F3\u9891\u6682\u4E0D\u652F\u6301\u5BFC\u51FA]",shading:{type:gt.ShadingType.CLEAR,color:"FFFFFF",fill:"CCCCCC"}})]})}function IZ(n,t){return new gt.Paragraph({children:[new gt.ExternalHyperlink({children:[new gt.TextRun({style:"Hyperlink",text:t||n})],link:n})]})}function Mk(n){if(n.heading!=null)return`Heading${n.heading}`}function Rk(n){if(n.alignment!=null){if(n.alignment==="center")return gt.AlignmentType.CENTER;if(n.alignment==="right")return gt.AlignmentType.RIGHT;if(n.alignment==="left")return gt.AlignmentType.LEFT}}function TZ(n){if(n.indent)return{left:gt.convertInchesToTwip(.3*n.indent-.2)};if(n.padding)return{left:gt.convertInchesToTwip(.3*n.padding)}}function DZ(n){return{type:gt.ShadingType.CLEAR,color:"FFFFFF",fill:n}}function SZ(n){const t=n.split(",");if(t.length!==0)return t[0].trim()}function Ok(n,t){let e;e=n.inlineCode?"InlineCode":void 0,e=n.link?"Hyperlink":e;const o=n.size||t,r=o!=null?Math.floor(o*1.5+.5):void 0;return new gt.TextRun({text:n.text,bold:n.bold||void 0,underline:n.underline?{type:gt.UnderlineType.SINGLE}:void 0,italics:n.italics||void 0,strike:n.strike||void 0,superScript:n.superScript||void 0,subScript:n.subScript||void 0,size:r,style:e,font:n.fontFamily?SZ(n.fontFamily):void 0,shading:n.background?DZ(n.background):void 0,color:n.color,highlight:hZ(n.highlight)})}function LZ(n,t){if(n.link)return new gt.ExternalHyperlink({children:[Ok(n,t)],link:n.link})}async function _k(n,t,e,o,r){const i=await r(n,t,e);if(i==null)return;const s=await Ik({width:o||0,height:0,src:e},i);return new gt.ImageRun({data:i,transformation:{width:s.width||100,height:s.height||20}})}function MZ(n){if(n.heading||n.heading)return n.heading}function RZ(n){if(n.align&&(n.align==="center"||n.align==="right"||n.align==="left"))return n.align}function OZ(n){if(n.textOnly===!0&&n.level!=null)return n.level}async function _Z(n,t){var o;const e=[];if(n.text&&Array.isArray(n.text)){for(let r=0;r<n.text.length;r++){const i=n.text[r];if(((o=i.attributes)==null?void 0:o.box)===!0&&t){const s=await t(i);if(s){n.text.splice(r+1,0,...s);continue}}e.push(wZ(i))}return e}}function FZ(n){if(n.type==="list"&&n.textOnly!==!0)return{checkbox:n.checkbox,groupId:n.groupId,ordered:!!n.ordered,level:n.level||1,start:n.start||0}}function PZ(n,t){if(n.type==="embed"&&n.embedType&&Q2(n.embedType)&&n.embedData&&n.embedData.src)return n.embedData.src.split("|").map(o=>{const r=t(o),i=n.embedData[`${r}_width`],s=n.embedData[`${r}_height`];return{src:o,width:i,height:s}})}function NZ(n){if(n.padding)return n.padding}function $Z(n){return!!(n.type==="embed"&&n.embedType&&Q2(n.embedType)&&n.embedData&&n.embedData.src)}async function i1(n,t,e){return{quoted:!!n.quoted,heading:MZ(n),alignment:RZ(n),indent:OZ(n),padding:NZ(n),texts:await _Z(n,e),list:FZ(n),images:PZ(n,t),border:$Z(n)}}async function HZ(n,t,e,o){const r=[];if(!n.children)return[];for(const i of n.children){const s=[];for(const l of t.blocks[i])s.push(await i1(l,e,o));r.push(s)}return r}const jZ=S("to-docx");function UZ(n,t){return Array(n).fill(0).map(()=>Array(t).fill(0).map(()=>({cellId:void 0,color:void 0,from:void 0,rowSpan:1,colSpan:1,width:0,originalWidth:void 0,align:void 0})))}function zZ(n,t,e,o){const r=!!n.hasColTitle,i=!!n.hasRowTitle,s=!!n.isStripeStyle,l="F5F8FB";for(let a=0;a<t;a++)for(let d=0;d<e;d++)(r&&d===0||i&&a===0||s&&a%2===1)&&(o[a][d].color=l)}function VZ(n){g(jZ,n.children,"no table children");const t=n.rows,e=n.cols,o=n.colsWidth;if(o)for(let s=0;s<o.length;s++)o[s]===0&&(o[s]=100);const r=UZ(t,e);let i=0;for(let s=0;s<t;++s)for(let l=0;l<e;++l){if(r[s][l].originalWidth=o?o[l]:void 0,r[s][l].from!==void 0)continue;const a=n.children[i];i+=1,r[s][l].cellId=a,r[s][l].color=fZ(n[`${a}_background`]),r[s][l].width=o?o[l]:100,r[s][l].align=n[`${a}_align`];const d=n[`${a}_rowSpan`]||1,h=n[`${a}_colSpan`]||1;if(r[s][l].rowSpan=d,r[s][l].colSpan=h,d>1||h>1){let p=0;for(let A=0;A<d;A++)for(let v=0;v<h;v++)A===0&&(p+=o?o[l+v]:80),!(A===0&&v===0)&&(r[s+A][l+v].from=[s,l]);r[s][l].width=p}}return zZ(n,t,e,r),r}async function WZ(n,t,e,o,r,i,s,l,a,d){async function h(v){if(l){const B=await l(r,i,v);if(B){await o.addDoc(n,B,d);return}}if(v.type==="text"||v.textOnly===!0){const B=await i1(v,s,a);await o.addTextBlock(B);return}if(v.type==="code"){const B=await HZ(v,e,s,a);await o.addCodeBlockObject(B);return}if(v.type==="list"&&v.textOnly!==!0){const B=await i1(v,s,a);await o.addListBlockObject(n,B);return}if(v.type==="embed"&&v.embedType){const B=v,D=B.embedData,x=B.embedType;if(Q2(x)){const _=await i1(v,s,a);await o.addImagesBlockObject(v,_,d)}else v.embedType==="hr"?o.addSeparatorBlock():v.embedType==="video"?o.addVideoPlaceholder():v.embedType==="audio"?o.addAudioPlaceholder():v.embedType==="webpage"?o.addHyperlinkParagraph(Lk(D.src),D.title):o.addOtherEmbedBlock(x,v.embedData);return}if(v.type==="table"){let B=[];if(v.colsWidth)B=v.colsWidth;else{const x=v.cols;B=new Array(x);for(let _=0;_<B.length;_++)B[_]=100;v.colsWidth=B}const D=VZ(v);await o.addTableMatrix(B,D,e),o.addEmptyParagraph()}}function p(v){const B=[];for(const{type:D,data:x}of v.embedData.exportSpec){if(D==="text"){const _={id:K(),text:[{insert:x}],type:"text"};B.push(_);continue}if(D==="image"){const _={id:K(),type:"embed",embedType:"image",align:"left",embedData:{src:x}};B.push(_);continue}if(D==="link"){const _={id:K(),type:"embed",embedType:"webpage",embedData:{src:x.url,title:x.title}};B.push(_);continue}}return B}function A(v){var B;return(B=v==null?void 0:v.embedData)!=null&&B.exportSpec?p(v):[v]}for(const v of t)for(const B of A(v))await h(B)}function qZ(){return{listMaxInst:1,listInstMap:{},listRefMap:{},levelConfigs:[]}}const GZ=S("to-docx");class ZZ{constructor(t,e,o,r,i,s){m(this,"paragraphs");this.appId=t,this.docId=e,this.state=o,this.readImageFunc=r,this.convertBlocksFunc=i,this.defaultFontSize=s,this.paragraphs=[]}async addTextBlock(t){this.paragraphs.push(new gt.Paragraph({heading:Mk(t),alignment:Rk(t),children:await this.paragraphsFromBlockTexts(t),indent:TZ(t)}))}async addEmptyImagePlaceHolder(){this.paragraphs.push(new gt.Paragraph({text:`[${R.t("docx.imageExportFailed")}]`,shading:{type:gt.ShadingType.CLEAR,color:"FFFFFF",fill:"CCCCCC"}}))}async paragraphsFromBlockTexts(t){if(t.texts==null)return;const e=pZ(this.defaultFontSize,t.heading),o=[];for(const r of t.texts){if(r.link){const i=LZ(r,e);i&&o.push(i);continue}if(r.box&&r.box.type&&r.box.type==="br"){o.push(new gt.TextRun({text:"",break:1}));continue}if(r.box&&r.box.type&&r.box.type==="image"){const i=await _k(this.appId,this.docId,r.box.src,r.box.width,this.readImageFunc);i&&o.push(i);continue}if(r.math){const i=await _k(this.appId,this.docId,r.math,0,this.readImageFunc);i&&o.push(i);continue}o.push(Ok(r,e))}return o}async addCodeBlockObject(t){for(const e of t)for(const o of e){const r={style:gt.BorderStyle.SINGLE,color:"#DEDEDE"};this.paragraphs.push(new gt.Paragraph({style:"Code",border:{left:{...r},right:{...r},top:{...r},bottom:{...r}},children:await this.paragraphsFromBlockTexts(o)}))}}async addListBlockObject(t,e){if(e.list==null)return;let o;const r=e.list.checkbox?`${t}-${e.list.groupId}-${e.list.checkbox}`:`${t}-${e.list.groupId}`;if(this.state.listInstMap[r])o=this.state.listInstMap[r];else if(o=this.state.listMaxInst,this.state.listMaxInst+=1,this.state.listInstMap[r]=o,e.list.start>0&&e.list.ordered){const s=`number-numbering-reference-${o}`,l=Tk([e.list.level-1],e.list.start);this.state.levelConfigs.push({levels:l,reference:s,inst:o}),this.state.listRefMap[r]=s}else e.list.ordered?this.state.listRefMap[r]=Hu.NUMBERING:e.list.checkbox&&e.list.checkbox==="checked"?this.state.listRefMap[r]=Hu.CHECKED:e.list.checkbox&&e.list.checkbox==="unchecked"?this.state.listRefMap[r]=Hu.UNCHECKED:this.state.listRefMap[r]=Hu.BULLET;const i=Mk(e);e.texts&&this.paragraphs.push(new gt.Paragraph({heading:i,children:await this.paragraphsFromBlockTexts(e),numbering:{reference:this.state.listRefMap[r],level:e.list.level-1,instance:o}}))}imageDimWithBufferToImageRun(t){return new gt.ImageRun({data:t.buffer,transformation:{width:t.width,height:t.height}})}async addImagesBlockObject(t,e,o){if(e.images==null){if(t.type==="embed"&&t.embedType==="image"){const{src:a}=t.embedData;a||this.addEmptyImagePlaceHolder()}return}const r=[],i=await Promise.all(e.images.map(async a=>{const d=await this.readImageFunc(this.appId,this.docId,a.src);if(d)return Ik(a,d);r.push(a.src)})),s=sZ(i,o),l={style:gt.BorderStyle.SINGLE,color:"#DEDEDE"};s.length&&this.paragraphs.push(new gt.Paragraph({border:e.border?{left:{...l},right:{...l},top:{...l},bottom:{...l}}:void 0,alignment:Rk(e)||gt.AlignmentType.CENTER,children:s.map(a=>this.imageDimWithBufferToImageRun(a)).flatMap((a,d,h)=>a==null?[]:h.length-1!==d?[a,new gt.TextRun({text:" "})]:a)})),r.forEach(a=>{this.addHyperlinkParagraph(a)})}addSeparatorBlock(){BZ().forEach(t=>this.paragraphs.push(t))}addEmptyParagraph(){this.paragraphs.push(new gt.Paragraph(""))}addVideoPlaceholder(){this.paragraphs.push(EZ())}addAudioPlaceholder(){this.paragraphs.push(xZ())}addHyperlinkParagraph(t,e){t!=null&&this.paragraphs.push(IZ(t,e))}async addTableMatrix(t,e,o){const r=t.map(i=>i!==0?i*15:1500);this.paragraphs.push(new gt.Table({rows:await this.generateTableRows(e,o),columnWidths:r}))}async generateRowCells(t,e){const o=[];for(const r of t){const i=r.cellId;if(i===void 0)continue;const s=r.width*.9;o.push(new gt.TableCell({children:await this.convertBlocksFunc(i,e.blocks[i],e,this.appId,this.docId,this.state,s),columnSpan:r.colSpan,rowSpan:r.rowSpan,width:{type:gt.WidthType.DXA,size:r.width*15},shading:r.color?{fill:r.color,type:gt.ShadingType.CLEAR,color:"auto"}:void 0}))}return o}async generateTableRows(t,e){const o=[];for(const r of t)o.push(new gt.TableRow({children:await this.generateRowCells(r,e)}));return o}async addDoc(t,e,o){const r=await this.convertBlocksFunc(t,e.blocks.root,e,this.appId,this.docId,this.state,o);r&&(this.paragraphs=this.paragraphs.concat(r))}async addOtherEmbedBlock(){}}class QZ{constructor(t,e,o,r,i,s,l,a){m(this,"convertBlocks",async(t,e,o,r,i,s,l=720)=>{const a=new ZZ(r,i,s,this.readImage,this.convertBlocks,this.defaultFontSize);return await WZ(t,e,o,a,r,i,this.md5HexFunc,this.getDocByBlock,this.getTextsByBox,l||720),a.paragraphs});this.templateData=t,this.docData=e,this.md5HexFunc=o,this.readImage=r,this.defaultFontSize=i,this.getDocByBlock=s,this.getTextsByBox=l,this.backgroundImageOptions=a}async convert(t,e){return this.snapshot2docx(this.docData,t,e)}async snapshot2docx(t,e,o){const r=new gt.ImportDotx,i=this.templateData?await r.extract(this.templateData):void 0,s=t.blocks.root;g(GZ,s,"data must have blocks");const l=qZ(),a=await this.convertBlocks("blocks",s,t,e,o,l),d=this.backgroundImageOptions?{default:new gt.Header({children:[new gt.Paragraph({children:[new gt.ImageRun(this.backgroundImageOptions)]})]})}:{},h=new gt.Document({numbering:{config:[...uZ,...l.levelConfigs]},sections:[{headers:d,children:a,properties:{page:{size:{width:12240,height:15840},margin:{top:1440,bottom:1440,left:1440,right:1440}}}}]},{template:i});return gt.Packer.toBlob(h)}}async function YZ(n,t,e,o){const r=n.doc.buildResourceUrl(o,{withToken:!0});let i=await b7(r);if(!i)return;if(i.type.indexOf("/svg")!==-1){const l=await p7(i);l&&(i=new File([l],i.name))}return await i.arrayBuffer()}async function JZ(n,t,e){const o=n.editorBlocks.getBlockClass(e.type);if(o.toStandardDoc)return o.toStandardDoc(n,e,t)}async function KZ(n,t){const e=t.attributes,o=n.editorBoxes.getBoxClass(e.type);if(o.toStandardText)return o.toStandardText(n,e)}async function XZ(n,t){let{template:e,download:o,backgroundImageOptions:r}=t!=null?t:{};e||(e=rZ());const i=n.doc.toJSON(),s=(p,A,v)=>YZ(n,p,A,v),l=async(p,A,v)=>JZ(n,i,v),a=async p=>KZ(n,p),h=await new QZ(e,i,Pd.default,s,void 0,l,a,r).convert("_appId","_docId");if(o){const p=URL.createObjectURL(h),A=document.createElement("a");A.setAttribute("download",`${A7(n)}.docx`),A.setAttribute("href",`${p}`),A.click(),A.remove()}return h}const Y2=S("create-editor");async function tQ(n,t){var s,l,a,d,h,p,A,v,B,D,x,_,M,H;g(Y2,n,"app does not exists"),t.lang&&R.setLang(t.lang),Di.level=(s=t.logLevel)!=null?s:da.DEBUG;const e=t.onReauth?async()=>{var ft;const z=t.user.userId,q=t.docId,rt=await((ft=t.onReauth)==null?void 0:ft.call(t,z,q,t.permission));return{userId:z,docId:q,permission:t.permission,appId:t.appId,token:rt,displayName:t.user.displayName,avatarUrl:t.user.avatarUrl}}:void 0,o={auth:{appId:t.appId,docId:t.docId,userId:t.user.userId,permission:t.permission,token:t.token,displayName:t.user.displayName,avatarUrl:t.user.avatarUrl},serverUrl:t.serverUrl,reauthFunc:e,disableLogout:t.disableLogout},r=await Xa.load(o),i=ja(n,r,{id:t.id,scrollContainer:t==null?void 0:t.scrollContainer,enableComments:t==null?void 0:t.enableComments,components:{blocks:[...wk,...((l=t==null?void 0:t.components)==null?void 0:l.blocks)||[]],embeds:[...Z2,...((a=t.components)==null?void 0:a.embeds)||[]],boxes:[...Bk,...((d=t.components)==null?void 0:d.boxes)||[]],commandProviders:[new Wp,...((h=t.components)==null?void 0:h.commandProviders)||[]],decorators:[new Sf,new Ap],insertions:[vg],blockHooks:[new t2,new Z7,...((p=t.components)==null?void 0:p.blockHooks)||[]],textRenders:[new s8,new p0],options:{...t.componentsOptions}},shortcuts:[Ez,MN,vH,R0,Fy,FO,D0,lV,Mh,...t.shortcuts||[]],colors:["#338FE5","#24B47E","#F0A100","#E52727","#9678D3","#2CB2AE","#EB6414","#8AAB3F"]});if(i.editorCommandProviders.registerCommandProvider(new vr(i)),i.input.addHandler(new JV),i.input.addHandler(new xf),i.input.addHandler(new K_),i.input.addHandler(new gH),i.input.addHandler(new vu(i,{headingLevel:1,titlePlaceholder:R.t("placeholder.common.title"),contentPlaceholder:R.t("placeholder.common.content"),readonlyTitlePlaceholder:R.t("placeholder.common.readonlyTitle"),addPlaceholderToAllCurrentEmptyBlock:!0})),i.input.addHandler(new Cf(i,(A=t.componentsOptions)==null?void 0:A.quickMenu)),i.input.addHandler(new l2(i)),i.input.addHandler(new h2(i)),i.input.addHandler(new TN),i.input.addHandler(new _f),i.doc.registerCallback(new KV(i)),i.addCustom("remote-cursor",()=>new Qb(i)),i.addCustom("block-menu",z=>new J7(z)),i.addCustom("editor-tooltip",()=>new Af(i)),t!=null&&t.enableComments&&i.addCustom("editor-comments",z=>new i8(z,new KG(z))),i.addCustom("create-options",()=>new J5(i,t)),i.addCustom("drop-target",()=>new Lu(i)),i.addCustom("list-to-mindmap",()=>new df(i)),i.addCustom("list-to-mention",()=>new AW(i)),i.addCustom("mobile-helper",()=>new _W(i)),i.addCustom("code-caret",()=>new IN(i)),i.addCustom("image-paste-handler",()=>new s2(i)),(v=t.componentsOptions)!=null&&v.mention){const z=t.componentsOptions.mention;i.addCustom("mention",()=>new _2(i,z))}if(i.addCustom("heading-collapse",()=>new M2(i)),gc.register(i),Lu.register(i),es.register(i),Ki.register(i),i.addListener("clickLink",(z,q,rt)=>{var Bt;if((Bt=t==null?void 0:t.events)!=null&&Bt.onClickLink){t.events.onClickLink(z,q,rt);return}const ft=rt.getAttribute("link");ft&&(z.readonly||q.ctrlKey||q.metaKey)&&window.open(ft,"_blank")}),(D=(B=t.componentsOptions)==null?void 0:B.remoteCarets)!=null&&D.onUserChanged){const z=(_=(x=t.componentsOptions)==null?void 0:x.remoteCarets)==null?void 0:_.onUserChanged;i.doc.getRemoteUsers().on("change",q=>{z(i,q)})}return(H=(M=t.componentsOptions)==null?void 0:M.templates)!=null&&H.templates.length&&(i.addListener("docChanged",()=>{n1(i)}),i.addListener("resize",()=>{n1(i,{reset:!0})}),setTimeout(()=>{n1(i)},100)),i.doc.registerCallback({onError:async z=>{if(z.code==="ResetDoc"){Y2.error(`reset doc: ${z.message}`);const q=await Xa.load(o);i.doc.reset(q)}}}),i}function eQ(n){return n.toJSON!==void 0}async function nQ(n,t,e){var i,s,l,a,d;g(Y2,n,"app does not exists");const o=eQ(t)?t:new Xg(t,{serverUrl:e.serverUrl||""});e.lang&&R.setLang(e.lang);const r=ja(n,o,{id:e.id,scrollContainer:e==null?void 0:e.scrollContainer,components:{blocks:[Ef,Df,j0,I9],commandProviders:[new Wp],decorators:[new Sf,new Ap],embeds:[...Z2,...((i=e.components)==null?void 0:i.embeds)||[]],boxes:[I0,F2,f8,...((s=e.components)==null?void 0:s.boxes)||[]],insertions:[vg],blockHooks:[new t2,...((l=e.components)==null?void 0:l.blockHooks)||[]],textRenders:[new s8,new p0,...((a=e.components)==null?void 0:a.textRenders)||[]],options:{...e.componentsOptions}},shortcuts:[R0,Fy,D0,Mh]});return r.editorCommandProviders.registerCommandProvider(new vr(r)),r.input.addHandler(new xf),r.input.addHandler(new vu(r,{headingLevel:1,titlePlaceholder:R.t("placeholder.common.title"),contentPlaceholder:R.t("placeholder.common.content"),readonlyTitlePlaceholder:R.t("placeholder.local.readonlyTitle"),addPlaceholderToAllCurrentEmptyBlock:!0})),r.input.addHandler(new Cf(r,(d=e.componentsOptions)==null?void 0:d.quickMenu)),r.input.addHandler(new l2(r)),r.input.addHandler(new h2(r)),r.input.addHandler(new _f),r.addCustom("block-menu",h=>new J7(h)),r.addCustom("editor-tooltip",()=>new Af(r)),r.addCustom("image-paste-handler",()=>new s2(r)),e!=null&&e.enableComments&&r.addCustom("editor-comments",h=>new i8(h,new XG(h,o))),r.addCustom("heading-collapse",()=>new M2(r)),r.addListener("clickLink",(h,p,A)=>{var B;if((B=e==null?void 0:e.events)!=null&&B.onClickLink){e.events.onClickLink(h,p,A);return}const v=A.getAttribute("link");v&&(h.readonly||p.ctrlKey||p.metaKey)&&window.open(v,"_blank")}),gc.register(r),r}function oQ(n,t){var a;const e=n.doc;if(!((a=e.getVersionHelper)==null?void 0:a.call(e)))throw new Error("the editor does not support to show versions");const r=n.getCustom("create-options");if(!r)throw new Error("the editor does not support to show versions");const i=r.getData(),s=new Ek(i),l=n.addCustom("version-dialog",()=>new S8(n.doc,s));return l.show(t),l}b.tippy=GB,b.AnchorBox=A6,b.AuthError=Wh,b.AuthHeader=Ka,b.AutoScroll=Qd,b.BaseURLHeader=qh,b.BasicCommands=B_,b.BlockExclusiveHook=Z7,b.BlockLockerHook=t2,b.BlockLockerPasteHandler=_f,b.BlockResizer=Bu,b.BrBox=m6,b.CodeBlock=Df,b.CodeLineBlock=j0,b.CodeTextDecorator=Sf,b.DefaultShortcuts=Mh,b.DocIdError=GS,b.DragDrop=dC,b.DrawioEmbed=z2,b.EditorBlocks=v4,b.EditorBoxes=p6,b.EditorCommandProviders=lb,b.EditorComplexBlockPosition=Mo,b.EditorComplexSelectionRange=ir,b.EditorDecorators=k6,b.EditorEmbeds=k4,b.EditorInsertions=y6,b.EditorSimpleBlockPosition=je,b.EditorSimpleSelectionRange=Ye,b.EmbedBlock=B4,b.EmbedBlockResizer=Pu,b.EnforceWithDocumentTitleHandler=vu,b.EventCallbacks=ha,b.FILL_CHAR=pI,b.FileExtError=ZS,b.GroupOrder=L9,b.HeadingBlockScrollListener=hW,b.ImageBox=C6,b.InlineBoxCommandProvider=$9,b.InputtingInsertion=b6,b.LocalDoc=Xg,b.LogLevel=da,b.Logger=Di,b.MIN_DISTANCE_THRESHOLD=aC,b.ManualCloseDialog=iu,b.ManualMenu=zs,b.ManualToolbar=ru,b.MarkdownInputHandler=xf,b.MaxUserError=dp,b.Mindmap=h0,b.OnesEditorAutoSuggest=Fp,b.OnesEditorCustomDataWrapper=J5,b.OnesEditorExclusiveBlock=Ki,b.OnesEditorHoveringBlock=Ae,b.OnesEditorQuickMenu=Cf,b.OnesEditorToc=Nu,b.OnesEditorTocProvider=es,b.OnesEditorToolbar=gc,b.OnesEditorTooltip=Af,b.OnesEditorVersionsDialog=S8,b.PermissionError=qS,b.Popup=tu,b.RemoteCarets=Qb,b.RemoteCaretsDecorator=Ap,b.RemoteCaretsInsertion=vg,b.RemoteUsers=Ph,b.RequestReloadError=Ja,b.RichText=ln,b.ShareDBDoc=Xa,b.ShareDBDocVersionsProvider=Ek,b.SimpleCache=X5,b.StandardEmbedBlockCommands=x2,b.TEXT_STYLE_BACKGROUND_COLOR_PREFIX=ug,b.TEXT_STYLE_COLOR_PREFIX=ag,b.TableBlock=Ef,b.TableBlockCommandProvider=Wp,b.TableShortcuts=R0,b.TextBlock=Tn,b.TextBox=f6,b.TextStyleShortcuts=D0,b.TocEmbed=V8,b.ZERO_WIDTH_SPACE_CHAR=fa,b.abbreviation=Yd,b.addAttribute=hh,b.addClass=W,b.addCommentToBlock=Kf,b.addDays=FE,b.addMetaToDoc=Oh,b.addMonths=_E,b.animateScrollTo=ym,b.applyPlaceholderToBlock=If,b.assert=g,b.autoShowHideTemplates=n1,b.blockToDoc=Qg,b.blockToHtml=Bg,b.blockToMarkdown=Eg,b.blockToText=vh,b.blocksToDoc=OT,b.clearAllSelection=e4,b.clientType=Ze,b.cloneBlock=Fi,b.cloneChildContainer=_g,b.cloneDoc=Fg,b.cloneText=o6,b.commentToShareDbComment=Cp,b.compareElement=jd,b.comparePosition=Ym,b.complexBlockAdjustSelectionPos=rh,b.complexBlockFindNearestChildBlock=T4,b.complexBlockGeFirstSimpleChild=Km,b.complexBlockGetAllChildContainers=xn,b.complexBlockGetBottomChildContainers=I4,b.complexBlockGetLastSimpleChild=zl,b.complexBlockGetSelectedContainers=Rs,b.complexBlockGetTopChildContainers=x4,b.containerToDoc=PA,b.continuousScroll=DC,b.convertBlockFrom=th,b.convertImageFileToPng=p7,b.convertImageSrcToPng=YP,b.copyBlockAttributes=_6,b.createBlockAnchor=zr,b.createBlockCaretAnchor=M4,b.createBlockContentElement=Is,b.createBlockElement=VC,b.createBlockSimpleDocRange=ph,b.createBlockSimpleRange=Ce,b.createBoxContentElement=GC,b.createBoxElement=WC,b.createBoxOp=Z4,b.createChildContainer=A4,b.createComplexBlockPosition=fe,b.createComplexDocPos=a6,b.createComplexDocRange=bI,b.createContainer=s6,b.createContainerElement=Wm,b.createDeleteOps=V4,b.createEditor=ja,b.createEditorSelectionRange=Ue,b.createElement=w,b.createEmptyContainer=qr,b.createEmptyDoc=Wr,b.createEmptyTextBlockData=mh,b.createExpandedRange=$d,b.createIconButton=$l,b.createImage=pm,b.createInsertOps=uh,b.createInsertionContentElement=YC,b.createInsertionElement=ZC,b.createLocalEditor=nQ,b.createOnesEditor=tQ,b.createRange=tC,b.createRichText=Oi,b.createRootContainer=C4,b.createSimpleBlockPosition=st,b.createSimpleDocPos=c6,b.createTextBlockData=cr,b.createTextButton=Qs,b.createTextOp=co,b.createTextWithReplaceSoftReturn=sg,b.daysAfter=Lm,b.deleteText=cg,b.diffDays=PE,b.disablePageScroll=wC,b.docToHtml=S6,b.docToHtmlFragment=yh,b.docToMarkdown=Ra,b.docToText=Ma,b.downloadImageToFile=b7,b.downloadObjectToFile=H2,b.downloadSvgToString=K8,b.editLink=gu,b.editorAddComment=az,b.editorAddTextAttribute=q6,b.editorAutoInsertBlock=F6,b.editorBreakTextBlock=Ql,b.editorClearCompositionText=O6,b.editorClearSelectedContents=Rg,b.editorCopyBlock=_h,b.editorDeleteBlock=Lg,b.editorDeleteBlockText=Dg,b.editorDeleteBlockWithoutChildren=Bh,b.editorDeleteChildContainer=fT,b.editorDeleteChildContainers=P6,b.editorFocusToBlock=Og,b.editorFocusToEnd=_A,b.editorGetBlockData=_i,b.editorGetBlockText=gn,b.editorGetBlockTextEx=Ah,b.editorGetBoxData=d6,b.editorHandleKeyboardEvent=jA,b.editorInsertBlock=Zl,b.editorInsertBoxToBlock=M6,b.editorInsertDoc=V6,b.editorInsertDocAt=Pg,b.editorInsertText=Tg,b.editorInsertTextToBlock=L6,b.editorInsertTextToBlockEx=Ig,b.editorMergeTextBlock=N6,b.editorMoveDown=rA,b.editorMoveEnd=mA,b.editorMoveHome=gA,b.editorMoveLeft=eA,b.editorMoveLineEnd=wA,b.editorMoveLineHome=kA,b.editorMovePageDown=DA,b.editorMovePageUp=TA,b.editorMoveRight=nA,b.editorMoveUp=oA,b.editorMoveWordEnd=dA,b.editorMoveWordLeft=uA,b.editorRangeClearColor=Z6,b.editorRangeGetColor=Ng,b.editorRangeSetColor=G6,b.editorRemoveTextAttribute=CT,b.editorReplaceBlockText=xh,b.editorReplaceContainer=W6,b.editorRunOnce=tp,b.editorSelectAll=OA,b.editorSelectContainer=Gg,b.editorSelectDown=iA,b.editorSelectEnd=Wg,b.editorSelectHome=pA,b.editorSelectLeft=sA,b.editorSelectLineEnd=yA,b.editorSelectLineHome=vA,b.editorSelectPageDown=LA,b.editorSelectPageUp=SA,b.editorSelectRight=lA,b.editorSelectUp=cA,b.editorSelectWordEnd=fA,b.editorSelectWordLeft=hA,b.editorSetTextColor=Yl,b.editorShowFindDialog=gU,b.editorToDocx=XZ,b.editorUpdateBlockData=Ih,b.editorUpdateCompositionText=R6,b.editorUpdateEmbedData=U6,b.enablePageScroll=BC,b.escapeHtmlText=sC,b.escapeRegExp=_m,b.escapeSpace=bE,b.exclusiveBlock=J0,b.executeBlockCommand=u4,b.executeEmbedBlockCommand=a4,b.executeRangeCommand=sb,b.fileToDataUrl=jl,b.findAfterOffsetNotType=Cg,b.findAllText=mg,b.findEventTargetBlock=rC,b.findInsertionById=QC,b.findNextOffset=FI,b.findNextVisibleSimpleBlock=hb,b.findPrevOffset=_I,b.findPrevOffsetNotType=pg,b.findPrevSimpleBlockBeforeChildContainer=E4,b.findPrevVisibleSimpleBlock=db,b.findTarget=Hl,b.findWordEnd=bg,b.findWordLeft=Ag,b.format=ba,b.formatBytes=SC,b.formatDate=Rm,b.fragmentToHtml=EC,b.fromBase64=pa,b.fromBase64ToBlob=Im,b.fromBase64ToUint8Array=SE,b.fromDocRange=Mi,b.fromNowString=Om,b.genId=K,b.getAllChildBlocks=tg,b.getAllQuickMenuItems=T0,b.getAllSelectedBlocks=Ro,b.getAttributesAt=Da,b.getBlockBackground=zC,b.getBlockByIndex=Fr,b.getBlockCaretRect=So,b.getBlockClass=Qt,b.getBlockClassByType=Ls,b.getBlockClientRects=Nr,b.getBlockCommandsWithHook=zm,b.getBlockContent=Lt,b.getBlockId=it,b.getBlockIndex=bt,b.getBlockInfo=Tu,b.getBlockKind=Do,b.getBlockMinWidth=o4,b.getBlockNearestRangeFromPoint=L4,b.getBlockOptions=ZE,b.getBlockPath=Li,b.getBlockProperties=s4,b.getBlockRangeFromPoint=ih,b.getBlockStyles=GE,b.getBlockTextLength=ut,b.getBlockTools=te,b.getBlockType=Dt,b.getBoxContent=Nm,b.getBoxId=qC,b.getBoxTypeFromElement=va,b.getChildBlockCount=Io,b.getChildBlocks=pe,b.getChildOffset=_s,b.getColorFromAttributes=hg,b.getColorFromContent=Jd,b.getComplexBlockClass=zn,b.getContainerBlockPath=m4,b.getContainerBlocks=t4,b.getContainerBlocksElement=nh,b.getContainerById=jr,b.getContainerId=at,b.getContainerMinWidth=Gm,b.getContainerToolsElement=XE,b.getContainerWidth=b4,b.getDistanceSquare=nr,b.getElementOffset=ma,b.getElementScale=ys,b.getEmbedType=fn,b.getExistsBlockTools=Xd,b.getExistsContainerById=f4,b.getFileExt=Aa,b.getFirstChildBlock=xe,b.getFirstClientRect=Hd,b.getHeadingMenuOptions=w0,b.getHorizontalPadding=Cm,b.getInsertionContent=$m,b.getLastChildBlock=Qe,b.getLastClientRect=bs,b.getListAllNextBrothers=uc,b.getLogger=S,b.getNextBlock=Zt,b.getNextValidOffset=Fs,b.getNextVisibleBlock=Ds,b.getOffsetInfoAfter=La,b.getOffsetInfoBefore=bh,b.getOpAt=Y4,b.getOpLength=dh,b.getParentBlock=et,b.getParentBlockExcludeSelf=xs,b.getParentBox=Pm,b.getParentContainer=nt,b.getPrevBlock=ce,b.getPrevValidOffset=Ri,b.getPrevVisibleBlock=Ts,b.getRangeCommands=rb,b.getRootBlock=Um,b.getScrollContainer=ro,b.getSpecialBlockCommands=l4,b.getStandardEmbedBlockProperties=I2,b.getTextAfterOffset=RI,b.getTextAttributes=xg,b.getTextBeforeOffset=OI,b.getTextBlockChild=eh,b.getTextBlockClass=KC,b.getTextBlockContentChildTextLength=lo,b.getTextBlockContentChildType=d4,b.getTextBlockContentChildren=rr,b.getTextLength=rn,b.getTextOpLength=eg,b.getTextWidth=qd,b.getToolbar=sf,b.handleBlockElementUpdated=r4,b.hasAltOnly=EE,b.hasClass=xt,b.hasCtrlOrCmd=AC,b.hasCtrlOrCmdOnly=BE,b.hashCode=PC,b.hideBlock=jC,b.htmlToFragment=Wd,b.i18n=R,b.injectDocToHtmlFragment=Rh,b.injectStyle=cC,b.insertEmptyBlock=JE,b.insertEmptyEmbedBlock=Vm,b.insertText=Vr,b.intersectionCommands=$D,b.isBackspace=vC,b.isBlock=Es,b.isBlockLocked=Of,b.isBlockLockedByOthers=X0,b.isBlockLockedBySelf=Du,b.isBlockTools=HC,b.isBox=Fm,b.isCJK=gC,b.isChildContainer=Lo,b.isChildNode=Xt,b.isCollapsedRange=AI,b.isComplexBlockPosition=Qm,b.isComplexKindBlock=Mt,b.isContainer=Pr,b.isContainerSelectedAllChildBlocks=MA,b.isControlEvent=ws,b.isDelete=IE,b.isDraggingFiles=Gd,b.isElementVisible=vm,b.isEmbedBlock=Me,b.isEmptyContainer=Ba,b.isEmptyDoc=gg,b.isEmptyTextBlock=he,b.isEmptyTextBlockWithoutCompositionText=bu,b.isEnterOnly=bC,b.isEscape=Em,b.isExclusiveBlock=Rf,b.isFirefox=Vd,b.isFirstChildBlockInComplexBlock=Lx,b.isHighSurrogate=fE,b.isInBlock=Hm,b.isInBlockTools=Ss,b.isLetter=mC,b.isLowSurrogate=gm,b.isMatchShortcut=or,b.isMoveForward=kE,b.isNavigationEvent=yE,b.isNavigationKey=CC,b.isNodeRemoved=nC,b.isNumber=fC,b.isPrintableKey=Bm,b.isRootBlock=io,b.isRootContainer=Yt,b.isSafari=pC,b.isSameDay=Mm,b.isSecureEnv=H0,b.isShiftEnter=xE,b.isShiftTab=DE,b.isShortcutEvent=wE,b.isSimpleBlock=qE,b.isSimpleBlockPosition=Ur,b.isSimplePos=l6,b.isSimpleRange=gh,b.isSpace=zd,b.isTab=TE,b.isTextBlockContentBoxChild=so,b.isTextBlockContentChild=ka,b.isTextBlockContentInsertionChild=Hr,b.isTextBlockContentTextChild=wa,b.isTextKindBlock=tt,b.isTextKindBlockType=ya,b.isToday=LC,b.isValidOffset=sn,b.isVisibleBlock=Kd,b.isYesterday=MC,b.loadJs=oC,b.loadJsPromise=vs,b.lockers=Eo,b.mergeCommands=rf,b.mergeDocs=$s,b.mergeOps=lg,b.mergeText=hI,b.multiSplitText=_4,b.overflowText=RC,b.parseShortcut=yC,b.patchNode=Ca,b.pointInRect=ks,b.rangeAddAttribute=Ta,b.rangeGetTextColor=n6,b.rangeRemoveAttribute=Wl,b.rangeSetTextColor=X4,b.rangeTransformText=J4,b.registerDragDrop=km,b.removeAttribute=dg,b.removeClass=ot,b.removeLastBr=cI,b.removePlaceholderFromBlock=c7,b.removeStyle=lC,b.replaceAll=NE,b.replaceAllCaseInsensitive=$E,b.replaceAllText=i6,b.replaceText=fh,b.requestDownload=Zd,b.resetListStart=hc,b.scrollable=TC,b.selectFile=Ul,b.selectedBlockToDoc=Dh,b.selectionToDoc=Sh,b.setAttributes=Ud,b.setClipboardData=Sm,b.setClipboardDataByEvent=OE,b.setColorToAttributes=t6,b.setDataset=Am,b.setDefaultCursor=ga,b.setStyles=bm,b.shareDBCommentToDocObject=pp,b.shareDBDocCommentToComment=Gb,b.shortcutToDisplayText=xo,b.showBlock=UC,b.showDocVersions=oQ,b.splitText=In,b.splitToThree=ze,b.stringToDataUrl=Tm,b.stringToObjectUrl=Dm,b.subText=F4,b.textNodeOffsetFromPoint=eC,b.titleFromEditor=A7,b.toBase64URL=Si,b.toMindmap=uf,b.toPlainText=ie,b.toPlainTextKeepLength=fg,b.trimChar=wm,b.unexclusiveBlock=K0,b.unicodeLength=mE,b.unicodeSubstr=gE,b.updateBlockSelection=n4,b.updateOpAttributes=r6,b.updateTextBlockContent=MI,b.updateUrl=xm;for(const n in ye)n!=="default"&&!b.hasOwnProperty(n)&&Object.defineProperty(b,n,{enumerable:!0,get:()=>ye[n]});Object.defineProperties(b,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|