@ones-editor/editor 0.0.3-beta.235 → 0.0.3-beta.236
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
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(),C=h.getHorizontalScroll();e>p&&(e=p);const v=e-C,B=h.getMaxVerticalScroll(),D=h.getVerticalScroll();i.verticalOffset||(D<o?o-=h.getClientHeight()*3/4:o-=h.getClientHeight()*1/4),o>B&&(o=B);const x=o-D,_=Math.abs(Math.round(v/1e3*i.speed)),R=Math.abs(Math.round(x/1e3*i.speed));let H=_>R?_:R;return H<i.minDuration?H=i.minDuration:H>i.maxDuration&&(H=i.maxDuration),new Promise((z,Q)=>{v===0&&x===0&&z(!0),Hr.remove(h.element,!0);let tt;const ft=()=>{qe(),cancelAnimationFrame(tt),z(!1)};Hr.add(h.element,ft);const vt=Rn=>Rn.preventDefault(),zt=i.cancelOnUserAction?ft:vt,Ht=i.cancelOnUserAction?{passive:!0}:{passive:!1},Kt=["wheel","touchstart","keydown","mousedown"],qe=()=>{Kt.forEach(Rn=>{h.element.removeEventListener(Rn,zt,Ht)})};Kt.forEach(Rn=>{h.element.addEventListener(Rn,zt,Ht)});const Yn=Date.now(),He=()=>{const Rn=Date.now()-Yn,Dr=Rn/H,kn=Math.round(C+v*i.easing(Dr)),an=Math.round(D+x*i.easing(Dr));Rn<H&&(kn!==e||an!==o)?(h.scrollTo(kn,an),tt=requestAnimationFrame(He)):(h.scrollTo(e,o),cancelAnimationFrame(tt),qe(),Hr.remove(h.element,!1),z(!0))};tt=requestAnimationFrame(He)})}function Bs(n,t,e){return n.left<=t&&t<=n.right&&n.top<=e&&e<=n.bottom}function QE(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 x5(n){if(!/["'&<>]/.exec(n))return n;const o={'"':""","'":"'","&":"&","<":"<",">":">"};return n.split("").map(l=>o[l]||l).join("")}function I5(n){const t=document.getElementById(n);t&&t.remove()}function T5(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 wa(n){const t="custom-cursor-style";if(n){const e=`body * { cursor: ${n} !important}`;T5(e,t)}else I5(t)}const D5=3,S5=S("drag-drop");class L5{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(S5,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:D5;(Math.abs(e)>=r||Math.abs(o)>=r)&&this.onDragStart(this.mouseDownEvent)});m(this,"handleMouseUp",t=>{if(t.button===0){g(S5,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&&wa(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&&wa(null),this.dragStarted&&this.options.onDragEnd(this,t,this.options.elem,e,o),this.unbindEvents(),this.dragStarted=!1}destroy(){this.unbindEvents(),this.untrackEvents()}}function Nm(n){return new L5(n)}const YE=S("character");function M5(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 R5(n){const t=n.charAt(0);return t>="0"&&t<="9"}function O5(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 lh(n){const t=[[9,13],[32],[160]];return M5(n.charCodeAt(0),t)}function _5(n){const t=[[12352,12687],[13056,13183],[13312,15661],[19968,40959],[63744,64255],[44032,55215]];return M5(n.charCodeAt(0),t)}function $m(n,t){let e=t;return g(YE,e.length===1,"invalid char length"),e==="]"&&(e="\\]"),e==="\\"&&(e="\\\\"),n.replace(new RegExp(`^[${e}]+|[${e}]+$`,"g"),"")}const jr=navigator.userAgent;function Vl(){const n=navigator.userAgent.toLowerCase();return n.indexOf("safari")!==-1&&!(n.indexOf("chrome")>-1)}function Ba(){return navigator.userAgent.toLowerCase().indexOf("firefox")>-1}const Ze={isAndroid:!!jr.match(/Android/i),isIOS:!!jr.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/i),isIPad:!!jr.match(/iPad/i),isIPhone:!!jr.match(/iPhone/i),isLinux:!!jr.match(/Linux/i),isMac:!!jr.match(/Macintosh/i),isMobile:!!jr.match(/AppleWebKit.*Mobile.*/i),isWindows:!!jr.match(/Window/i),isIe:!!jr.match(/msie|trident/i),isSafari:Vl(),isFirefox:Ba(),isMobileSafari:!1};Ze.isMobileSafari=Ze.isMobile&&Ze.isSafari;function Hm(n){return n?n.length===1||n==="Process"||n==="Unidentified"&&Ze.isAndroid:!1}function F5(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 JE(n){return F5(n.key)}function KE(n){switch(n){case"ArrowUp":case"ArrowLeft":case"Home":case"PageUp":return!0;default:return!1}}function Es(n){return n.ctrlKey||n.altKey||n.shiftKey||n.metaKey}function XE(n){return n.key?!!(n.ctrlKey||n.metaKey||n.altKey):!1}function P5(n){return Ze.isMac?n.metaKey&&!n.ctrlKey:!n.metaKey&&n.ctrlKey}function tx(n){return P5(n)&&!n.altKey&&!n.shiftKey}function ex(n){return!n.metaKey&&!n.ctrlKey&&!n.shiftKey&&n.altKey}function N5(n){return!Es(n)&&n.key==="Enter"}function nx(n){return n.key==="Enter"&&n.shiftKey&&!n.altKey&&!n.ctrlKey&&!n.metaKey}function jm(n){return!Es(n)&&n.key==="Escape"}function ox(n){return!Es(n)&&n.key==="Delete"}function $5(n){return!Es(n)&&n.key==="Backspace"}function rx(n){return!Es(n)&&n.key==="Tab"}function ix(n){return n.shiftKey&&n.key==="Tab"&&!n.ctrlKey&&!n.metaKey}function io(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 H5(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 rr(n,t){const e=H5(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 Um(n,t){return LB.stringifyUrl({url:n,query:t})}function Oi(n){return typeof n=="string"?pa.Base64.encode(n,!0):pa.Base64.fromUint8Array(n,!0)}function Ea(n){return pa.Base64.decode(n)}function sx(n){return pa.Base64.toUint8Array(n)}function zm(n){return new Blob([pa.Base64.toUint8Array(n)])}const lx=Mi.init([Mi.classModule,Mi.styleModule,Mi.datasetModule,Mi.attributesModule,Mi.propsModule]);function xa(n,t){const e=Mi.toVNode(n),o=Mi.toVNode(t);lx(e,o)}async function Vm(n,t){const e=new FileReader,o=new Promise((i,s)=>{e.onload=i,e.onerror=s});return e.readAsDataURL(new Blob([n],{type:t})),await o,e.result}async function Wl(n){const t=new FileReader,e=new Promise((r,i)=>{t.onload=r,t.onerror=i});return t.readAsDataURL(n),await e,t.result}function cx(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 so(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||cx(e,"body"))&&(e=document.documentElement),e}function j5(n){n.preventDefault(),n.stopPropagation()}function U5(n){if(document.querySelector(`.editor-disable-scroll[data-scroll-id="${n}"]`))return;const t=k("div",["editor-disable-scroll"],null);t.setAttribute("data-scroll-id",n),t.addEventListener("wheel",j5,{passive:!1}),document.body.appendChild(t)}function z5(n){const t=document.querySelector(`.editor-disable-scroll[data-scroll-id="${n}"]`);t&&(t.removeEventListener("wheel",j5),t.remove())}function Wm(n,t,e){const o=new Blob([n]),r=new File([o],e,{type:t});return URL.createObjectURL(r)}function ch(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 V5(n){const t=document.createElement("div");return t.appendChild(n),t.innerHTML}function W5(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 ah(n,t){const o=(ah.canvas||(ah.canvas=document.createElement("canvas"))).getContext("2d");return o?(typeof t=="string"?t?o.font=t:o.font=W5(window.getComputedStyle(document.body)):t instanceof Element&&(o.font=W5(window.getComputedStyle(t))),o.measureText(n).width+4):200}const ax=S("editor-clipboard");async function ux(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 qm(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 ax.error(t),!1}}function ql(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 uh(n){return Array.isArray(n)?n.every(t=>t instanceof File):!1}function Ia(n){const t=n;if(!t)return"";const e=t.lastIndexOf(".");return e===-1?"":t.slice(e+1)}function dh(n,t){const e=document.createElement("a");e.setAttribute("download",`${t||""}`),e.setAttribute("href",`${n}`),e.click(),e.remove()}const q5=S("auto-scroll");function G5(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 Z5(n,{direction:t,step:e}){let o=null;const r=t==="left"||t==="right",i=()=>G5(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):(q5.debug("No need for scroll"),null);return o=requestAnimationFrame(i),()=>{o&&cancelAnimationFrame(o)}}class hh{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;q5.debug(`scroll direction: ${i}`),this.cancelScroll=Z5(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 Q5(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 Ta(n,t){let e=`${n}`;const o=t-e.length;for(let r=0;r<o;r++)e=`0${e}`;return e}const{t:xs}=L;function Gm(n,t){const e=new Date(n).getTime()+864e5*t;return new Date(e)}function dx(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 hx(n,t){return Gm(n,t)}function Zm(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 Y5(n){const t=new Date,e=new Date(n);return Zm(t,e)}function J5(n){const t=Gm(new Date,-1);return Zm(t,n)}function fx(n,t){return Math.round((n.getTime()-t.getTime())/864e5)}function Qm(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",Ta(r,2)),a=a.replace("DD",Ta(i,2)),a=a.replace("M",`${r}`),a=a.replace("D",`${i}`),a=a.replace("hh",Ta(s,2)),a=a.replace("mm",Ta(l,2)),a=a.replace("h",`${s}`),a=a.replace("m",`${l}`),a}return n.toLocaleDateString()}function Ym(n,t){const e=new Date(n),o=new Date;if(e.getTime()-o.getTime()>10*1e3)return L.t("date.dateFromFuture");if(Y5(e)){const i=(o.getTime()-n.getTime())/1e3;if(i<10*60)return xs("date.dateJustNow");if(i<60*60)return xs("date.dateMinutesAgo",{num:`${Math.floor(i/60)}`});const s=Math.floor(i/60/60);return s===1?xs("date.date1HourAgo"):xs("date.dateHoursAgo",{num:`${s}`})}if(J5(n))return xs("date.dateYesterday");const r=Math.floor((o.getTime()-n.getTime())/1e3/24/60/60)+1;return r<14?xs("date.dateDaysAgo",{num:`${r}`}):r<28?xs("date.dateWeeksAgo",{num:`${Math.round(r/7)}`}):Qm(n,t)}function Jm(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function mx(n,t,e){return n.replace(new RegExp(Jm(t),"g"),e)}function gx(n,t,e){return n.replace(new RegExp(Jm(t),"gi"),e)}function K5(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 X5=/[\u3040-\u30ff\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff\uff66-\uff9f\uAC00-\uD7AF]/,t4=" -\x7F0-9!-/:-@[-`{-~\u0370-\u03FF\u0400-\u04FF",px=new RegExp(`[${t4}]`),Cx=new RegExp(`([^(${t4})])`,"g"),e4=/(\ud83c[\udf00-\udfff])|(\ud83d[\udc00-\ude4f\ude80-\udeff])|[\u2600-\u2B55]/;function n4(n){return n.length===0?0:n.split("").reduce((t,e)=>{const o=(t<<5)-t+e.charCodeAt(0);return o&o},0)}function Ax(n,t=1){var o,r;return(r=((o=Array.from(n))==null?void 0:o.filter(i=>X5.test(i))).slice(-t))==null?void 0:r.join("")}function bx(n,t=1){var r;const e=Array.from((r=n==null?void 0:n.replace(Cx,""))==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 vx(n,t=1){var o,r;return(r=((o=Array.from(n))==null?void 0:o.filter(i=>e4.test(i))).slice(-t))==null?void 0:r.join("")}function yx(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 fh(n,t=1){if(!n||n.length===0)return"";const e=X5.test(n),o=px.test(n),r=e4.test(n);switch(!0){case e:return Ax(n,t);case o:return bx(n,t);case r:return vx(n,t);default:return yx(n,t)}}var o4=(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))(o4||{});function mh(n){const t=Object.values(o4),e=Math.abs(typeof n=="string"&&n.trim()?n4(n.trim()):0)%t.length;return t[e]}const r4=S("container-children");function me(n){const t=Array.from(n.querySelectorAll(":scope > .container-blocks > div[data-type=editor-block]"));return g(r4,t.length>0,"container have not any child block"),t}function ye(n){const t=n.querySelector(":scope > .container-blocks > div[data-type=editor-block]");return g(r4,t,"container have not any child block"),t}function Qe(n){const t=me(n);return t[t.length-1]}function Do(n){return me(n).length}function Ur(n,t){return me(n)[t]}const So=S("block-dom");function Is(n){return n instanceof HTMLDivElement?n.getAttribute("data-type")==="editor-block":!1}function i4(n){return n instanceof HTMLElement&&n.getAttribute("data-type")==="block-tools"}function s4(n){W(n,"block-hidden")}function l4(n){rt(n,"block-hidden")}function gh(n){return!xt(n,"block-hidden")}function it(n){const{id:t}=n;return g(So,t,"no block id"),t}function Dt(n){const t=n.getAttribute("data-block-type");return g(So,t,"invalid block dom, no data-type"),t}function nt(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 Ts(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 ot(n){const t=n.closest("div[data-type=editor-container]");return g(So,t,"failed to get block container"),t}function Lt(n){const t=n.querySelector(":scope >div[data-type=block-content]");return g(So,t,"no block content"),t}function ee(n){let t=n.querySelector(":scope >div[data-type=block-tools]");return t||(t=k("div",[],n),t.setAttribute("data-type","block-tools")),g(So,t,"no block tools"),t}function ph(n){const t=n.querySelector(":scope >div[data-type=block-tools]");return t||null}function c4(n){let t=n.querySelector(":scope > div[data-type=block-background]");return t||(t=k("div",[],n),t.setAttribute("data-type","block-background")),t}function a4(n,t,e){const o=n.editorDecorators.decorateBlock(t,e),{id:r,type:i}=o;g(So,r,"no block id");const s=k("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 Ds(n,t){const e=k(t,[],null);return e.setAttribute("data-type","block-content"),n&&n.appendChild(e),e}function u4(n){const t=k("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 Da(n){const t=n.getAttribute("data-box-type");return g(So,t,"not a valid box element, no type"),t}function Km(n){return n instanceof HTMLSpanElement?n.getAttribute("data-type")==="editor-box":!1}function d4(n){const{id:t}=n;return g(So,t,"no box id"),t}function Xm(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 h4(n){n.innerHTML="",k("span",["box-space-start"],n,ya);const t=k("span",[],n);return t.setAttribute("data-type","box-content"),k("span",["box-space-start"],n,ya),t}function tg(n){const t=n.querySelector("span[data-type=box-content]");return g(So,t,"invalid box dom, no content"),t}function f4(n,t){const e=k("span",[`${n}-insertion`],null);return e.setAttribute("data-type","editor-insertion"),e.setAttribute("data-insertion-id",t),e}function m4(n,t){return n.rootContainer.querySelector(`[data-insertion-id=${t}]`)}function g4(n){n.innerHTML="",k("span",["insertion-space-start"],n,ya);const t=k("span",[],n);return t.setAttribute("data-type","insertion-content"),k("span",["insertion-space-start"],n,ya),t}function eg(n){const t=n.querySelector("span[data-type=insertion-content]");return g(So,t,"invalid insertion-child dom, no content"),t}function ae(n){let t=n.previousElementSibling;for(;t;){if(Is(t))return t;t=t.nextElementSibling}return null}function Qt(n){let t=n.nextElementSibling;for(;t;){if(Is(t))return t;t=t.nextElementSibling}return null}function Ss(n){let t=n.previousElementSibling;for(;t;){if(Is(t)&&gh(t))return t;t=t.previousElementSibling}return null}function Ls(n){let t=n.nextElementSibling;for(;t;){if(Is(t)&&gh(t))return t;t=t.nextElementSibling}return null}function bt(n){const t=ot(n),o=me(t).indexOf(n);return g(So,o!==-1,"invalid block & container dom, failed to get block index"),o}function ng(n){return!n||!(n instanceof Node)?!1:!!nt(n)}function Ms(n){if(!ng(n))return!1;const t=n,e=t instanceof Element?t:t.parentElement;return e?!!e.closest("div[data-type=block-tools]"):!1}const p4=S("block-class");function Yt(n,t){return n.editorBlocks.getBlockClass(Dt(t))}function C4(n,t){const e=n.editorBlocks.getBlockClass(Dt(t));return g(p4,e.blockKind==="text",`is not a text block, ${e.blockType}`),e}function zn(n,t){const e=n.editorBlocks.getBlockClass(Dt(t));return g(p4,e.blockKind==="complex",`is not a text block, ${e.blockType}`),e}function Rs(n,t){return n.editorBlocks.getBlockClass(t)}function et(n,t){return Yt(n,t).blockKind==="text"}function Sa(n,t){return n.editorBlocks.getBlockClass(t).blockKind==="text"}function Mt(n,t){return Yt(n,t).blockKind==="complex"}function kx(n,t){return!Mt(n,t)}function Lo(n,t){return Yt(n,t).blockKind}function Mo(n,t,e){return Yt(n,t).getCaretRect(t,e)}const A4=S("container");function zr(n){return n.getAttribute("data-type")==="editor-container"}function Gt(n){return xt(n,"root")}function Ro(n){return xt(n,"child")}function ct(n){const t=n.getAttribute("data-container-id");return g(A4,t,"no id for container"),Gt(n)&&g(A4,t==="root",`invalid root container id, : ${t}`),t}function b4(n,t){const e=ct(n);return t.getContainerBlocks(e)}const og=S("block");function ut(n,t){return Yt(n,t).getBlockTextLength(t)}function v4(n){n.editorBlocks.forEach(t=>{t.clearSelection(n)})}function y4(n,t,e,o){Yt(n,t).updateSelection(n,t,e,o)}function rg(n){for(;;){const t=ot(n);if(Gt(t))return n;const e=nt(t);g(og,e,"no parent block exists for child container"),n=e}}function k4(n,t){const e=Yt(n,t);if(!!e.getMinWidth)return e.getMinWidth(n,t)}function w4(n,t,e){const o=Yt(n,t);o.handleBlockElementUpdated&&o.handleBlockElementUpdated(n,t,e)}function Ch(n,t,e,o){try{const r=Rs(n,e).convertFrom;return r?r(n,t,o):null}catch{return og.debug(`unsupported block type: ${e}`),null}}function Vr(n,t,e){const o=Yt(n,t);return o.getClientRects?o.getClientRects(n,t,e):[t.getBoundingClientRect()]}function wx(n,t){const e=Yt(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(og,s==="string"||s==="number"||s==="boolean","invalid style value")}),r}function ue(n,t){return Lo(n,t)==="text"?ut(n,t)===0:!1}const B4=S("block-path");function _i(n){const t=[];let e=n;for(;e;){const o=ot(e);if(t.unshift({containerId:ct(o),blockIndex:bt(e)}),Gt(o))return t;const r=nt(o);g(B4,r,"no parent block"),e=r}return g(B4,!1,"no parent block"),[]}function Bx(n,t){var r,i;const e=Yt(n,t);return(i=(r=e.getOptions)==null?void 0:r.call(e,n))!=null?i:{name:Dt(t)}}function lo(n){return Gt(ot(n))}function E4(n,t){var r;const e=Yt(n,t);return(r=e.getBlockProperties)==null?void 0:r.call(e,n,t)}function ig(n,t){var i,s;const e=Yt(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 Ex(n,t,e){var s,l,a,d;const o=Yt(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 x4(n,t,e){let o=t;for(;o;){const r=Ex(n,o,e);if(r.length>0)return{element:Lt(o),commands:r};if(lo(o))break;o=Ts(o)}return{element:null,commands:[]}}const I4=S("embed-block-common");function Ie(n){return Dt(n)==="embed"}function fn(n){g(I4,Ie(n),"not an embed block");const t=n.getAttribute("data-embed-type");return g(I4,t,"no embed data type"),t}function xx(n,t){return n.editorEmbeds.getEmbedClass(fn(t))}function Os(n,t){return n.editorEmbeds.getEmbedClass(t)}async function sg(n,t,e,o,r){const i=Os(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 Ix(n,t,e,o,r){var l,a;const i=(a=(l=Rs(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 Tx=S("execute-block-command");function T4(n,t,e,o){var d;g(Tx,Ie(t),"not a embed block");const r=fn(t),i=Os(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 D4(n,t,e,o){const r=ig(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 Wr=S("text-block-child");function La(n){return n.tagName==="SPAN"}function co(n){return g(Wr,La(n),"not a valid text child"),n.getAttribute("data-type")==="editor-box"}function qr(n){return g(Wr,La(n),"not a valid text child"),n.getAttribute("data-type")==="editor-insertion"}function Ma(n){return!co(n)&&!qr(n)}function S4(n){return g(Wr,La(n),"not a valid text child"),co(n)?"box":qr(n)?"insertion":"text"}function ao(n){const t=S4(n);return t==="insertion"?0:t==="box"?1:(g(Wr,n.textContent!==null,"text block content is undefined"),g(Wr,n.textContent.length>=0,"text block content length is negative"),n.textContent.length)}function ir(n){const t=Lt(n),e=Array.from(t.children);return e.forEach(o=>{g(Wr,La(o),"not a valid text child")}),e}function Ah(n,t){const e=ir(n);let o=0;for(let r=0;r<e.length;r++){const i=e[r],s=ao(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(Wr,l>0,"invalid offset value"),g(Wr,!co(i),"invalid box child"),{prev:i,next:i,offset:l}}g(Wr,!1,`invalid block child at position: ${t}`)}const L4=S("element");function lg(n,t,e){const o=k("div",[t],n);return o.setAttribute("data-type","editor-container"),o.setAttribute("data-container-id",e),k("div",["container-blocks"],o),o}function sr(n,t){const e=n.rootElement.querySelector(`[data-container-id=${t}]`);return g(L4,e,`no container: ${t}`),e}function bh(n,t){return n.rootElement.querySelector(`[data-container-id=${t}`)}function vh(n){const t=n.querySelector(":scope > .container-blocks");return g(L4,t,"no container blocks element"),t}function Dx(n){let t=n.querySelector(":scope > .container-tools");return t||(t=k("div",["container-tools"],n)),t}const Sx=S("child-container-path");function M4(n){if(Gt(n))return[];const t=nt(n);return g(Sx,t,"no parent block"),_i(t)}const R4=S("load-blocks");function cg(n,t,e){const o=ct(t),r=b4(t,n.doc);g(R4,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)}),vh(t).appendChild(i)}function Lx(n,t,e){const o=vh(n);if(t===0)return o.insertBefore(e,o.firstChild),e;const r=me(n);return g(R4,t>=0&&t<=r.length,"invalid block index"),t===r.length?o.appendChild(e):o.insertBefore(e,r[t]),e}function Mx(n,t,e,o){const r=M4(t);r.push({containerId:ct(t),blockIndex:e});const i=n.editorBlocks.createBlock(r,t,o);return Lx(t,e,i),i}const O4=S("root-container");class Rx{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){O4.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(!Ms(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&&te(this.rootContainer,o)){const r=nt(o);r&&te(r,o)&&this.handleBlockClick(t,r,o)}}});m(this,"handleBlockClick",(t,e,o)=>{var s,l;if(!et(this.editor,e))return;const r=Xm(o);if(r){const a=nt(r);g(O4,a,"no parent block"),(l=(s=this.editor.editorBoxes.getBoxClass(Da(r)))==null?void 0:s.handleClickBox)==null||l.call(s,this.editor,r,t);return}const i=o.closest("span.text.link");i&&ir(e).indexOf(i)!==-1&&this.editor.emit("clickLink",this.editor,t,i)});m(this,"handleDblClick",t=>{Ms(t.target)||this.editor.selectionHandler.handleDblClick(t)});m(this,"handleMouseDown",t=>{const e=t.target;if(!!e&&e instanceof Node&&!Ms(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 vs(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=vh(this.rootContainer);e.innerHTML="",cg(this.editor,this.rootContainer,[]);const o=this.editor.findBlockById(t.start.blockId);if(o)this.editor.selection.selectBlock(o,0);else{const r=ye(this.rootContainer);this.editor.selection.selectBlock(r,0)}}}function _4(n){const t=lg(n.contentElement,"root","root");return n.rootContainer=t,cg(n,t,[]),new Rx(n,t)}function F4(n,t,e,o){const r=bh(n,o);if(r)return e.appendChild(r),setTimeout(()=>{n.emit("containerRemount",n,o)}),r;const i=lg(e,"child",o);return cg(n,i,t),i}function P4(n,t){const e=n.getBoundingClientRect().width;return t.withPadding?e:e-Om(n)}function ag(n,t){let e=Number.MAX_SAFE_INTEGER;const o=me(t);for(let i=0;i<o.length;i++){const s=o[i],l=k4(n,s);l&&(e=Math.min(e,l))}return e===Number.MAX_SAFE_INTEGER?void 0:e+Om(t)}function Ra(n,t){const e=me(t);return e.length!==1?!1:ue(n,e[0])}const Ox=S("complex-block-position");class Oo{constructor(t,e,o){m(this,"blockId");m(this,"childContainerId");m(this,"custom");t instanceof HTMLElement?this.blockId=it(t):(g(Ox,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 _x=S("simple-block-position");class Ue{constructor(t,e,o){m(this,"blockId");m(this,"offset");m(this,"type");t instanceof HTMLElement?this.blockId=it(t):(g(_x,typeof t=="string",`not a valid block id: ${t}`),this.blockId=t),this.offset=e,this.type=o}isSimple(){return!0}}const ug=S("editor-position");function st(n,t,e){return new Ue(n,t,e)}function fe(n,t,e){return new Oo(n,t,e)}function Gr(n){return n instanceof Ue}function Gl(n){return n instanceof Oo}function dg(n,t,e){if(Gr(t)&&Gr(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(ug,i!==s,"comparePosition: blocks are the same"),rh(i,s)}if(Gl(t)&&Gl(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(ug,i!==s,"comparePosition: containers are the same"),rh(i,s)}return g(ug,!1,"invalid "),0}const yh=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=dg(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(yh,e,"no start block"),g(yh,o,"no end block");const r=ot(e),i=ot(o);g(yh,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(yh,l<a,"invalid range, start > index"),s.push({block:e,start:this.start,end:st(e,ut(this.editor,e),"end")});const d=me(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 Fx(n,t,e,o,r){W(o,"unknown-block");const i=Ds(o,"div");return i.innerText=`unknown block (${r.type}): ${JSON.stringify(r)}`,i}function Px(n){return 1}function Nx(n,t,e,o){return null}function $x(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 Hx(n,t){const o=Lt(n).getBoundingClientRect();return new DOMRect(o.left+o.width/2,o.top,1,o.height)}function jx(n,t,e,o){W(t,"selected")}function Ux(n){n.rootContainer.querySelectorAll("div.unknown-block[data-type=editor-block]").forEach(t=>{rt(t,"selected")})}function zx(n,t,e,o){return`[unknown block, ${t.type}]`}const Vx={blockType:"unknown-block",blockKind:"embed",createBlockContent:Fx,getBlockTextLength:Px,getRangeFromPoint:$x,moveCaret:Nx,getCaretRect:Hx,updateSelection:jx,clearSelection:Ux,convertTo:zx},hg=S("editor-blocks");class N4{constructor(t){m(this,"blocks",new Map);this.editor=t}registerBlockClass(t){const e=t.blockType,o=this.blocks.get(e);g(hg,!o,`duplicated block type: ${e}`),this.blocks.set(e,t)}getBlockClass(t){const e=this.blocks.get(t);return g(hg,e,`unknown block type: ${t}`),e}hasBlock(t){return this.blocks.has(t)}createBlock(t,e,o){const r=a4(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&&(hg.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={...Vx,blockType:t};return this.editor.editorBlocks.registerBlockClass(e),e}}const $4=S("editor-embeds");class H4{constructor(t){m(this,"objects",new Map);this.editor=t}registerEmbedClass(t){const e=t.embedType,o=this.objects.get(e);g($4,!o,`duplicated embed object type: ${e}`),this.objects.set(e,t)}getEmbedClass(t){const e=this.objects.get(t);return g($4,e,`unknown embed type: ${t}`),e}getEmbedClassFromBlock(t){return this.getEmbedClass(fn(t))}forEach(t){this.objects.forEach(t)}}const j4=S("embed-block");function Wx(n,t,e,o,r){const i=Ds(o,"div");g(j4,r.type==="embed",`not an embed data: ${JSON.stringify(r)}`);const s=r;return g(j4,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 qx(n){return 1}function Gx(n,t,e,o){return null}function Zx(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 Qx(n,t){const o=Lt(n).getBoundingClientRect();return new DOMRect(o.left+o.width/2,o.top,1,o.height)}function Yx(n,t,e,o){W(t,"selected")}function Jx(n){n.rootContainer.querySelectorAll("div.embed-block[data-type=editor-block][data-block-type=embed]").forEach(t=>{rt(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 Xx(n,t,e,o){const r=Os(n,t.embedType);return r.convertTo?r.convertTo(n,t,e,o):""}function tI(n,t){const e=xx(n,t);return e.getBlockProperties?e.getBlockProperties(n,t):{}}function eI(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 nI(n,t,e,o){const r=fn(t),i=Os(n,r);!i.handleDeleteBlock||i.handleDeleteBlock(n,t,e,o)}function oI(n,t,e){const o=fn(t),r=Os(n,o);return r.handleUpdateBlock?r.handleUpdateBlock(n,t,e):!1}function rI(n,t,e,o,r){const i=fn(t),s=Os(n,i);if(s.handleDropOver)return s.handleDropOver(n,t,e,o,r)}function iI(n,t,e,o,r){const i=fn(t),s=Os(n,i);if(s.handleDrop&&n.isWritable())return s.handleDrop(n,t,e,o,r)}async function sI(n,t,e){const o=t.embedType,r=n.editorEmbeds.getEmbedClass(o);if(r.toStandardDoc){const i=n.getBlockById(t.id),s=_i(i);return r.toStandardDoc(n,t,e,s)}}const U4={blockType:"embed",blockKind:"embed",createBlockContent:Wx,getBlockTextLength:qx,getRangeFromPoint:Zx,moveCaret:Gx,getCaretRect:Qx,updateSelection:Yx,clearSelection:Jx,convertFrom:Kx,convertTo:Xx,getBlockProperties:tI,getOptions:eI,handleDeleteBlock:nI,handleUpdateBlock:oI,handleDropOver:rI,handleDrop:iI,toStandardDoc:sI},mn=S("complex-block-helper");function gn(n,t,e){return zn(n,t).getChildContainers(n,t,e)}function Zl(n,t,e,o){return e.isSimple()?(g(mn,o.isSimple(),"invalid start and end position"),gn(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 lI(n,t){if(bt(t)!==0)return!1;const e=nt(ot(t));if(!e)return!1;g(mn,Mt(n,e),"not a complex block");const o=ot(t),i=gn(n,e).indexOf(o);return g(mn,i>=0,"not valid child container"),i===0}function fg(n,t,e){const o=gn(n,t,e);if(o.length===0)return null;const r=o[0];if(!r)return null;const i=ye(r);return Mt(n,i)?fg(n,i,e):i}function Ql(n,t,e){const o=gn(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)?Ql(n,i,e):i}function z4(n,t){g(mn,Ro(t),"not a child container");const e=nt(t);g(mn,e,"no parent block"),g(mn,Mt(n,e),"not a complex block");const o=gn(n,e),r=o.indexOf(t);if(g(mn,r!==-1,"child container not found"),r===0){const l=ae(e);return l?Mt(n,l)?Ql(n,l):l:null}const i=o[r-1],s=Qe(i);return Mt(n,s)?Ql(n,s):s}function V4(n,t){g(mn,Mt(n,t),"not a complex block");const e=gn(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 W4(n,t){g(mn,Mt(n,t),"not a complex block");const e=gn(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 q4(n,t,e,o){const r=t.getBoundingClientRect(),i=o<r.top,s=i?V4(n,t):W4(n,t);let l=s[0],a=or(l.getBoundingClientRect(),e,o);for(let d=1;d<s.length;d++){const h=s[d],p=h.getBoundingClientRect(),C=or(p,e,o);C<a&&(l=h,a=C)}return i?ye(l):Qe(l)}function kh(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 lr{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=dg(this.editor,this._anchor,this._focus)>0}isCollapsed(){return!1}isEqual(t){if(!(t instanceof lr))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 Zl(this.editor,t,this.start,this.end)}clone(){return new lr(this.editor,this)}toDocRange(){return{anchor:this._anchor,focus:this._focus}}}const cI=S("selection-range");function ze(n,t){const{anchor:e,focus:o}=t;return e instanceof Ue&&o instanceof Ue?new Ye(n,{anchor:e,focus:o}):(g(cI,e instanceof Oo&&o instanceof Oo,"start position type does not math end type"),new lr(n,{anchor:e,focus:o}))}function ke(n,t,e,o){const r=new Ue(t,e,"normal"),i=new Ue(t,o!=null?o:e,"normal");return ze(n,{anchor:r,focus:i})}function aI(n){return!!n.anchor.childContainerId}function Fi(n,t){var r,i;if(aI(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 ze(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 ze(n,{anchor:e,focus:o})}const G4=S("range-from-point");function wh(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 G4.debug("click on scrollbar, out of element rect"),null;if(!n.rootContainer.contains(i))continue;const l=nt(i);if(!l||!n.contains(l))continue;const a=Yt(n,l).getRangeFromPoint(n,l,t,e+o[r]);if(a)return a}return null}function Z4(n,t,e,o){const r=t.getBoundingClientRect();if(o<=r.top){const a=ye(t),d=Yt(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=Yt(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 Q4(n,t,e){const o=wh(n,t,e);if(o){if(o instanceof Ye)return o;g(G4,o instanceof lr,`invalid range type: ${typeof o}`);const a=o,d=n.getContainerById(a.start.childContainerId);return Z4(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=>zr(a));if(s.length===0)return null;const l=s.reduce((a,d)=>{const h=a.getBoundingClientRect(),p=d.getBoundingClientRect();return or(h,t,e)>or(p,t,e)?d:a});return Z4(n,l,t,e)}function mg(n,t){const e=[];return me(t).forEach(r=>{e.push(r),Mt(n,r)&&gn(n,r).forEach(s=>{e.push(...mg(n,s))})}),e}function gg(n,t){let e=mg(n,n.rootContainer);return t!=null&&t.simpleBlockOnly&&(e=e.filter(o=>!Mt(n,o))),e}function cr(n,t){const e=n.selection.range.getSelectedBlocks(),o=[];for(const r of e)o.push(r),Mt(n,r.block)&&Zl(n,r.block,r.start,r.end).forEach(s=>{const a=mg(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 sot="",Je=S("text-range");function uI(n,t){const e=(i,s)=>{if(qr(i))return g(Je,s===0,`invalid offset for insertion child: ${s}`),{child:i,container:i,offset:2};if(co(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=ir(n);for(let i=0;i<r.length;i++){const s=r[i],l=ao(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,ao(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 dI(n,t,e){if(t===e?g(Je,qr(n),"only insertion child can be zero offset"):g(Je,t<e,`invalid start & end: ${t}, ${e}`),qr(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}`),nh(i,1,i,2)}if(co(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}`),nh(i,1,i,2)}const o=ao(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}`),nh(r,t,r,e)}const _o=S("caret-rect");function hI(n,t){if(Km(t)){const e=t,o=tg(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(_o,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 eg(t).getClientRects()}function Vn(n,t){var l,a,d;const e=uI(n,t.offset);if(e[1]&&e[0].child!==((l=e[1])==null?void 0:l.child)){if(t.type==="end"){const p=ks(e[0].child);return new DOMRect(p.right,p.top,1,p.height)}g(_o,e[1],"invalid ranges");const h=oh(e[1].child);return new DOMRect(h.left,h.top,1,h.height)}let r=e[0];if(g(_o,e.length>=1,"failed to get block range"),e.length===1)r=e[0];else{if(g(_o,e.length>=2,`invalid range info length: ${e.length}`),qr(e[e.length-1].child)){r=e[e.length-1];const h=r.child,C=eg(h).getClientRects();g(_o,C.length>=1,"no client rects for box content");const v=C[C.length-1];return new DOMRect(v.right,v.y,1,v.height)}t.type==="home"?r=e[1]:t.type==="end"||Ma(e[0].child)?r=e[0]:Ma(e[1].child)&&(r=e[1])}if(r.container instanceof HTMLBRElement){g(_o,t.offset===0,"invalid offset for empty block text");const h=r.container.parentElement;g(_o,h,"invalid br parent");const p=h.getBoundingClientRect();return new DOMRect(p.left,p.top,1,p.height)}const i=v5(r.container,r.offset),s=Array.from(i.getClientRects());if(s.length===0){g(_o,!Ma(r.child),"only box or insertion child range has zero client rect"),g(_o,r.offset===1||r.offset===2,"invalid offset for box or insertion child");const h=r.child,p=hI(n,h);if(g(_o,p.length>=1,"no client rects for box content"),r.offset===1){const v=p[0];return new DOMRect(v.x,v.y,1,v.height)}const C=p[p.length-1];return t.type==="end"||r.offset===2?new DOMRect(C.right,C.y,1,C.height):new DOMRect(C.x,C.y,1,C.height)}if(Ba()||Vl()){const h=document.createRange();h.selectNodeContents(r.container);const p=h.getClientRects();if(r.container.nodeType===Node.TEXT_NODE&&r.offset<((d=(a=r.container.textContent)==null?void 0:a.length)!=null?d:0)){const C=document.createRange();C.setStart(r.container,r.offset+1);const v=C.getClientRects();Array.from(p).forEach((B,D)=>{if(v[0].top!==s[0].top&&v[0].top===B.top){const{x,y:_,height:R}=p[D];s.push(new DOMRect(x,_,0,R))}})}if(r.container.nodeType===Node.TEXT_NODE&&r.offset>0){const C=document.createRange();C.setStart(r.container,r.offset-1);const v=C.getClientRects();Array.from(p).forEach((B,D)=>{if(v[0].top!==s[0].top&&v[0].top===B.top){const{x,y:_,height:R}=p[D];s.length===1&&s.unshift(new DOMRect(x,_,0,R))}})}}return g(_o,s.length>0,"no client rects for range"),t.type==="home"?s[s.length-1]:s[0]}const fI=S("core");function Zr(n,t,e,o){const r=ee(t);let i=r.querySelector(`.block-anchor[data-id=${e}]`);i||(i=k("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 Y4(n,t,e,o){g(fI,et(n,t),"not a text kind block");const r=Vn(t,st(t,e,"normal")),i=t.getBoundingClientRect(),s=ee(t);let l=s.querySelector(`.block-anchor[data-id=${o}]`);l||(l=k("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 Oa(n){const t=ir(n);let e=0;return t.forEach(o=>{e+=ao(o)}),e}const J4=S("box");function _a(n){return!n.attributes||!n.attributes.box?!1:(g(J4,n.attributes.box===!0,`invalid op attribute box property, ${n.attributes.box}`),g(J4,n.attributes.type,`no box type: ${JSON.stringify(n)}`),!0)}const K4=S("rich-text-length");function pg(n){return g(K4,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(K4,typeof e.insert=="string","op.insert is not string"),t+=pg(e))}),t}const ar=S("split-text");function Tn(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(ar,typeof i=="object",`invalid op type, ${typeof i}`),g(ar,typeof i.insert=="string",`invalid op.insert type, ${typeof i.insert}`);const s=pg(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(ar,o+s>t,`invalid offset, ${o}, ${s}, ${t}`);const l=t-o,a=mt.default(i);g(ar,a.insert,"no copied.insert"),g(ar,typeof a.insert=="string","invalid copied.insert type"),a.insert=a.insert.substr(0,l),i.insert=i.insert.substr(l),a.insert===""&&g(ar,!1,"invalid copied.insert, is empty string"),i.insert===""&&g(ar,!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 Ve(n,t,e){g(ar,t>=0,"invalid offset, < 0"),g(ar,e>0,"invalid length, <= 0"),g(ar,t+e<=rn(n),"invalid offset + length < text length");const{left:o,right:r}=Tn(n,t+e),{left:i,right:s}=Tn(o,t);return{left:i,middle:s,right:r}}function X4(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}=Tn(r,s);r=l,o.unshift(a)}return r.length>0&&o.unshift(r),o}function t6(n,t,e){return Ve(n,t,e).middle}const Yl=S("text-block-content");function mI(n,t,e,o,r){if(g(Yl,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,C)=>{const v=r==null?void 0:r.get(C);v&&(v.forEach(B=>{p.appendChild(s(B))}),r==null||r.delete(C))},a=document.createDocumentFragment();let d=0;const h=X4(o,i);for(let p=0;p<h.length;p++){l(a,d);const C=h[p];d+=rn(C);for(let v=0;v<C.length;v++){const B=C[v];if(_a(B)){g(Yl,B.attributes,`op is not an valid box: ${JSON.stringify(B)}`);const x=n.editorBoxes.createBox(e,B.attributes);g(Yl,x instanceof HTMLSpanElement,`invalid box element: ${x.tagName}`),a.appendChild(x);continue}g(Yl,B.insert,`no insert in op: ${JSON.stringify(B)}`);const D=k("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(([_,R])=>{D.setAttribute(_,R)}),x.styles&&Object.entries(x.styles).forEach(([_,R])=>{D.style.setProperty(_,R)})}a.appendChild(D)}}l(a,d),e.innerHTML="",e.appendChild(a)}function Bh(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(Yl,a.isSimple(),"not an simple position while compositing"),a.blockId===e&&s.set(a.offset,[{type:"inputting",id:K(),text:l}])}return mI(n,t,o,i,s)}function gI(n){const t=n.rootContainer.querySelectorAll('span[data-type="editor-insertion"].inputting-insertion');t.length&&Yl.debug(`remove ${t.length} temp composition span`),Array.from(t).forEach(e=>e.remove())}const ur=S("client-rects");function pI(n){const t=ir(n);let e=0;const o=[];for(let r=0;r<t.length;r++){const i=t[r],s=ao(i);o.push({child:i,startBlockOffset:e,endBlockOffset:e+s}),e+=s}return o}function CI(n,t,e,o){g(ur,e<o,`invalid from & to: ${e}, ${o}`);const r=ut(n,t);g(ur,e>=0&&o>=0&&e<=r&&o<=r,`invalid offset: ${e}, ${o}, length: ${r}`);const i=pI(t),s=i.findIndex(v=>v.startBlockOffset<=e&&e<v.endBlockOffset),l=i.findIndex(v=>v.startBlockOffset<o&&o<=v.endBlockOffset);if(g(ur,s!==-1,"failed to find start child"),g(ur,l!==-1,"failed to find end child"),g(ur,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:ao(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],C={child:p.child,startChildOffset:0,endChildOffset:o-p.startBlockOffset};return a.push(C),a}function AI(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 e6(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=CI(n,t,r,i).map(d=>dI(d.child,d.startChildOffset,d.endChildOffset)),a=[];return l.forEach(d=>{const h=AI(Array.from(d.getClientRects()));a.push(...h)}),a}function bI(n,t,e){g(ur,e instanceof Ye,"invalid range");const o=e.start,r=e.end;return g(ur,o.isSimple(),"text block only allow simple position"),g(ur,r.isSimple(),"text block only allow simple position"),g(ur,o.blockId===r.blockId,"only allow update one text block selection"),g(ur,o.blockId===it(t),"only allow update one text block selection"),e6(n,t,o,r)}const Cg=S("selection-background");function vI(n,t,e,o){g(Cg,e.isSimple(),"text block only allow simple position"),g(Cg,o.isSimple(),"text block only allow simple position"),g(Cg,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=e6(n,t,e,o),l=t.getBoundingClientRect(),a=ro(t),d=c4(t);d.innerHTML="",s.forEach(h=>{const p=k("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 yI(n){n.rootContainer.querySelectorAll("div[data-type=block-background]").forEach(t=>{t.remove()})}const _s=S("text-offset"),n6="\u200D";function Fs(n,t){const e=ir(n);let o=0;for(let r=0;r<e.length;r++){const i=e[r],s=ao(i);if(i===t){const l=o+s;return{start:o,end:l}}o+=s}g(_s,!1,"can not find child in children")}function sn(n,t){g(_s,t>=0,`invalid offset: ${t}`);const e=Ah(n,t),{prev:o,next:r,offset:i}=e;if(!o&&!r&&g(_s,!1,"invalid offset, no prev & next child at offset"),o!==r)return!0;const s=o;if(g(_s,s,"no child"),co(s))return g(_s,i===0||i===1,`invalid box child offset: ${i}`),!0;const l=s.textContent;g(_s,l,"no content for text child");const a=l.charAt(i-1),d=l.charAt(i);return!(a===n6||d===n6||Mm(l[i]))}function Pi(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 Ps(n,t){const e=Oa(n);if(g(_s,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 Ns=S("line-breaker");function Fa(n){const t=a=>{const d=oh(a);return ks(a).top>d.top+d.height/2},e=(a,d)=>{const h=ks(a),p=oh(d);return Math.floor(p.left)<Math.floor(h.right)},o=(a,d)=>{const h=ks(a),p=ks(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=ir(n);for(let a=0;a<l.length;a++){const d=l[a];if(qr(d)){const x=d,_=l[a+1];if(!_)break;const R=l[a-1];if(R&&o(R,x)&&i.push({offset:s,type:"betweenChild",childInfo:{prevChild:R,nextChild:x,wrap:"nextWrapped",prevWrapped:t(R),nextWrapped:t(x)}}),e(x,_)){i.push({offset:s,type:"betweenChild",childInfo:{prevChild:R,nextChild:x,wrap:"nowrap",prevWrapped:t(R),nextWrapped:t(x)}});continue}continue}if(co(d)){const x=d,_=l[a+1];if(!_)break;const R=l[a-1];if(R&&o(R,x)&&i.push({offset:s,type:"betweenChild",childInfo:{prevChild:R,nextChild:x,wrap:"nextWrapped",prevWrapped:t(R),nextWrapped:t(x)}}),e(x,_)){s+=1,i.push({offset:s,type:"betweenChild",childInfo:{prevChild:R,nextChild:d,wrap:"nowrap",prevWrapped:t(R),nextWrapped:t(d)}});continue}s+=1;continue}const h=d,p=h.getClientRects();if(g(Ns,p.length>0,"invalid text child dom"),p.length===1){const x=l[a+1];if(!x)break;if(e(h,x)){s+=ao(h),i.push({offset:s,type:"betweenChild",childInfo:{prevChild:h,nextChild:x,wrap:"nowrap",prevWrapped:t(h),nextWrapped:t(x)}});continue}s+=ao(h);continue}const C=h.firstChild;g(Ns,C,"invalid text child, no text node"),g(Ns,C instanceof Text,`invalid text child, not a valid text node: ${typeof C}`);const v=document.createRange(),B=document.createRange(),D=ao(h);g(Ns,C.data.length===D,"text node data length not equal child text length");for(let x=0;x<C.data.length;x++){if(!sn(n,s+x))continue;v.setStart(C,x);const _=v.getClientRects();if(g(Ns,_.length>=1,"invalid text node, no client rects"),r(_)){const tt=s+x;i.push({offset:tt,type:"textBreakWord",childInfo:{prevChild:d,nextChild:d,wrap:"nowrap",prevWrapped:t(d),nextWrapped:t(d)}});continue}let R=x+1;sn(n,s+R)||(R=x+2),B.setStart(C,R);const H=B.getClientRects(),z=_[0];if(H[0].left<z.right)if(Ba()||Vl()){i.push({offset:Vl()?s+R:s+x,type:"textBreakWord",childInfo:{prevChild:d,nextChild:d,wrap:"nowrap",prevWrapped:t(d),nextWrapped:t(d)}});continue}else g(Ns,!1,"span pre-wrap should not has a line-wrap by white space")}s+=D}return i}function Ag(n,t){const e=Fa(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(Ns,t.offset<=Oa(n),"invalid position, offset > block length"),{lineIndex:e.length,lineBreaks:e}}const kI=S("line-offset");function bg(n){const t=Fa(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:Oa(n)}),e}function Eh(n,t){const e=bg(n);return g(kI,t>=0&&t<e.length,`invalid line index: ${t}, ${e.length}`),e[t]}function o6(n,t){const{lineIndex:e}=Ag(n,t);return Eh(n,e)}function wI(n){const t=bg(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 BI(n,t,e){const r=wI(n).find(s=>Bs(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 r6(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 i6(n){return bg(n).length}const $s=S("find-text-position");function s6(n,t){const{start:e,end:o}=Eh(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=Ah(n,e);return g($s,a.next,"no next child at offset"),g($s,!Ma(a.next),"next child is not text child"),!0}function EI(n,t){const e=it(n);g($s,s6(n,t),"line is not wrapped");const{start:o,end:r}=Eh(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(!r6(n,i,a))return s-1}return g($s,!1,"failed to find wrapped offset"),0}function xh(n,t,e,o,r,i,s){g($s,et(n,t),`not a text kind block: ${Dt(t)}`);const{start:l,end:a}=Eh(t,e);let d=l;const h=it(t);if(t===o&&s6(t,e)){const x=EI(t,e);(i==="up"||i==="down"&&r6(t,r,st(h,l,"home")))&&(d=x+1)}let p=Number.MAX_SAFE_INTEGER;const C=Mo(n,o,r),v=s!=null?s:C.left+C.width/2,B=C.top+C.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 R=st(h,x,_),H=Vn(t,R),z=or(H,v,B);z<p&&(p=z,D=R)}return D}function xI(n,t,e,o,r){return g($s,et(n,t),"not a text block"),xh(n,t,i6(t)-1,e,o,"up",r)}function II(n,t,e,o,r){return g($s,et(n,t),"not a text block"),xh(n,t,0,e,o,"down",r)}function TI(n,t,e,o){const{lineIndex:r}=Ag(t,e);if(r===i6(t)-1)return null;const i=xh(n,t,r+1,t,e,"down",o);return i||null}function DI(n,t){if(t.offset===0)return null;const e=Fa(n),o=e.find(r=>r.offset===t.offset);if(!o){const r=Pi(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:Pi(n,t.offset),type:"normal"}}return{offset:Pi(n,t.offset),type:"normal"}}function SI(n,t){const e=Oa(n);if(t.offset===e)return null;const o=Fa(n),r=o.find(i=>i.offset===t.offset);if(!r){const i=Ps(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:Ps(n,t.offset),type:"home"}:{offset:Ps(n,t.offset),type:"normal"}}function LI(n,t,e,o){const{lineIndex:r}=Ag(t,e);if(r===0)return null;const i=xh(n,t,r-1,t,e,"up",o);return i||null}const MI=S("move-caret");function RI(n,t,e,o){if(o==="ArrowLeft"){const r=DI(t,e);return r?st(it(t),r.offset,r.type):null}if(o==="ArrowRight"){const r=SI(t,e);return r?st(it(t),r.offset,r.type):null}if(o==="ArrowUp"){const r=LI(n,t,e,n.selection.getSuggestedCaretX());return r?st(it(t),r.offset,r.type):null}if(o==="ArrowDown"){const r=TI(n,t,e,n.selection.getSuggestedCaretX());return r?st(it(t),r.offset,r.type):null}g(MI,!1,`invalid navigation direction: ${o}`)}const vg=S("text-range");function OI(n){const t=[];return ir(n).forEach(o=>{const r=Array.from(o.getClientRects()).map(i=>({rect:i,child:o}));t.push(...r)}),t}function _I(n,t,e){const o=OI(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 Fs(n,s.child).start}return null}function FI(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(!Bs(_,e,o))return null;const R=_I(t,e,o);if(R!==null){const z=st(t,R,"normal");return new Ye(n,{anchor:z,focus:z})}const H=BI(t,e,o);return H?new Ye(n,{anchor:H,focus:H}):null}const s=ir(t);g(vg,s.indexOf(i)!==-1,"failed to find child in children");const l=Fs(t,i);g(vg,l,"failed to get child offset");const{start:a}=l;let d,h;qr(i)||co(i)?(d=a,h=0):(g(vg,i.firstChild instanceof Text,"child is not text"),d=a+y5(i.firstChild,e,o),h=0);const p=it(t),v=Fa(t).find(_=>_.offset===d);let B="normal";if(v){const _=st(p,d,"home"),R=st(p,d,"end"),H=Vn(t,_),z=Vn(t,R),Q=or(H,e,o),tt=or(z,e,o);B=Q<tt?"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 PI=S("create-text-op");function uo(n,t){g(PI,n,"text is empty");const e={insert:n};return t&&Object.keys(t).length>0&&(e.attributes=t),e}function yg(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(),C=h.getHorizontalScroll();e>p&&(e=p);const v=e-C,B=h.getMaxVerticalScroll(),D=h.getVerticalScroll();i.verticalOffset||(D<o?o-=h.getClientHeight()*3/4:o-=h.getClientHeight()*1/4),o>B&&(o=B);const x=o-D,_=Math.abs(Math.round(v/1e3*i.speed)),R=Math.abs(Math.round(x/1e3*i.speed));let H=_>R?_:R;return H<i.minDuration?H=i.minDuration:H>i.maxDuration&&(H=i.maxDuration),new Promise((z,Q)=>{v===0&&x===0&&z(!0),Hr.remove(h.element,!0);let tt;const ft=()=>{qe(),cancelAnimationFrame(tt),z(!1)};Hr.add(h.element,ft);const vt=Rn=>Rn.preventDefault(),zt=i.cancelOnUserAction?ft:vt,Ht=i.cancelOnUserAction?{passive:!0}:{passive:!1},Kt=["wheel","touchstart","keydown","mousedown"],qe=()=>{Kt.forEach(Rn=>{h.element.removeEventListener(Rn,zt,Ht)})};Kt.forEach(Rn=>{h.element.addEventListener(Rn,zt,Ht)});const Yn=Date.now(),He=()=>{const Rn=Date.now()-Yn,Dr=Rn/H,kn=Math.round(C+v*i.easing(Dr)),an=Math.round(D+x*i.easing(Dr));Rn<H&&(kn!==e||an!==o)?(h.scrollTo(kn,an),tt=requestAnimationFrame(He)):(h.scrollTo(e,o),cancelAnimationFrame(tt),qe(),Hr.remove(h.element,!1),z(!0))};tt=requestAnimationFrame(He)})}function Bs(n,t,e){return n.left<=t&&t<=n.right&&n.top<=e&&e<=n.bottom}function QE(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 x5(n){if(!/["'&<>]/.exec(n))return n;const o={'"':""","'":"'","&":"&","<":"<",">":">"};return n.split("").map(l=>o[l]||l).join("")}function I5(n){const t=document.getElementById(n);t&&t.remove()}function T5(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 wa(n){const t="custom-cursor-style";if(n){const e=`body * { cursor: ${n} !important}`;T5(e,t)}else I5(t)}const D5=3,S5=S("drag-drop");class L5{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(S5,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:D5;(Math.abs(e)>=r||Math.abs(o)>=r)&&this.onDragStart(this.mouseDownEvent)});m(this,"handleMouseUp",t=>{if(t.button===0){g(S5,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&&wa(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&&wa(null),this.dragStarted&&this.options.onDragEnd(this,t,this.options.elem,e,o),this.unbindEvents(),this.dragStarted=!1}destroy(){this.unbindEvents(),this.untrackEvents()}}function Nm(n){return new L5(n)}const YE=S("character");function M5(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 R5(n){const t=n.charAt(0);return t>="0"&&t<="9"}function O5(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 lh(n){const t=[[9,13],[32],[160]];return M5(n.charCodeAt(0),t)}function _5(n){const t=[[12352,12687],[13056,13183],[13312,15661],[19968,40959],[63744,64255],[44032,55215]];return M5(n.charCodeAt(0),t)}function $m(n,t){let e=t;return g(YE,e.length===1,"invalid char length"),e==="]"&&(e="\\]"),e==="\\"&&(e="\\\\"),n.replace(new RegExp(`^[${e}]+|[${e}]+$`,"g"),"")}const jr=navigator.userAgent;function Vl(){const n=navigator.userAgent.toLowerCase();return n.indexOf("safari")!==-1&&!(n.indexOf("chrome")>-1)}function Ba(){return navigator.userAgent.toLowerCase().indexOf("firefox")>-1}const Ze={isAndroid:!!jr.match(/Android/i),isIOS:!!jr.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/i),isIPad:!!jr.match(/iPad/i),isIPhone:!!jr.match(/iPhone/i),isLinux:!!jr.match(/Linux/i),isMac:!!jr.match(/Macintosh/i),isMobile:!!jr.match(/AppleWebKit.*Mobile.*/i),isWindows:!!jr.match(/Window/i),isIe:!!jr.match(/msie|trident/i),isSafari:Vl(),isFirefox:Ba(),isMobileSafari:!1};Ze.isMobileSafari=Ze.isMobile&&Ze.isSafari;function Hm(n){return n?n.length===1||n==="Process"||n==="Unidentified"&&Ze.isAndroid:!1}function F5(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 JE(n){return F5(n.key)}function KE(n){switch(n){case"ArrowUp":case"ArrowLeft":case"Home":case"PageUp":return!0;default:return!1}}function Es(n){return n.ctrlKey||n.altKey||n.shiftKey||n.metaKey}function XE(n){return n.key?!!(n.ctrlKey||n.metaKey||n.altKey):!1}function P5(n){return Ze.isMac?n.metaKey&&!n.ctrlKey:!n.metaKey&&n.ctrlKey}function tx(n){return P5(n)&&!n.altKey&&!n.shiftKey}function ex(n){return!n.metaKey&&!n.ctrlKey&&!n.shiftKey&&n.altKey}function N5(n){return!Es(n)&&n.key==="Enter"}function nx(n){return n.key==="Enter"&&n.shiftKey&&!n.altKey&&!n.ctrlKey&&!n.metaKey}function jm(n){return!Es(n)&&n.key==="Escape"}function ox(n){return!Es(n)&&n.key==="Delete"}function $5(n){return!Es(n)&&n.key==="Backspace"}function rx(n){return!Es(n)&&n.key==="Tab"}function ix(n){return n.shiftKey&&n.key==="Tab"&&!n.ctrlKey&&!n.metaKey}function io(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 H5(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 rr(n,t){const e=H5(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 Um(n,t){return LB.stringifyUrl({url:n,query:t})}function Oi(n){return typeof n=="string"?pa.Base64.encode(n,!0):pa.Base64.fromUint8Array(n,!0)}function Ea(n){return pa.Base64.decode(n)}function sx(n){return pa.Base64.toUint8Array(n)}function zm(n){return new Blob([pa.Base64.toUint8Array(n)])}const lx=Mi.init([Mi.classModule,Mi.styleModule,Mi.datasetModule,Mi.attributesModule,Mi.propsModule]);function xa(n,t){const e=Mi.toVNode(n),o=Mi.toVNode(t);lx(e,o)}async function Vm(n,t){const e=new FileReader,o=new Promise((i,s)=>{e.onload=i,e.onerror=s});return e.readAsDataURL(new Blob([n],{type:t})),await o,e.result}async function Wl(n){const t=new FileReader,e=new Promise((r,i)=>{t.onload=r,t.onerror=i});return t.readAsDataURL(n),await e,t.result}function cx(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 so(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||cx(e,"body"))&&(e=document.documentElement),e}function j5(n){n.preventDefault(),n.stopPropagation()}function U5(n){if(document.querySelector(`.editor-disable-scroll[data-scroll-id="${n}"]`))return;const t=k("div",["editor-disable-scroll"],null);t.setAttribute("data-scroll-id",n),t.addEventListener("wheel",j5,{passive:!1}),document.body.appendChild(t)}function z5(n){const t=document.querySelector(`.editor-disable-scroll[data-scroll-id="${n}"]`);t&&(t.removeEventListener("wheel",j5),t.remove())}function Wm(n,t,e){const o=new Blob([n]),r=new File([o],e,{type:t});return URL.createObjectURL(r)}function ch(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 V5(n){const t=document.createElement("div");return t.appendChild(n),t.innerHTML}function W5(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 ah(n,t){const o=(ah.canvas||(ah.canvas=document.createElement("canvas"))).getContext("2d");return o?(typeof t=="string"?t?o.font=t:o.font=W5(window.getComputedStyle(document.body)):t instanceof Element&&(o.font=W5(window.getComputedStyle(t))),o.measureText(n).width+4):200}const ax=S("editor-clipboard");async function ux(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 qm(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 ax.error(t),!1}}function ql(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 uh(n){return Array.isArray(n)?n.every(t=>t instanceof File):!1}function Ia(n){const t=n;if(!t)return"";const e=t.lastIndexOf(".");return e===-1?"":t.slice(e+1)}function dh(n,t){const e=document.createElement("a");e.setAttribute("download",`${t||""}`),e.setAttribute("href",`${n}`),e.click(),e.remove()}const q5=S("auto-scroll");function G5(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 Z5(n,{direction:t,step:e}){let o=null;const r=t==="left"||t==="right",i=()=>G5(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):(q5.debug("No need for scroll"),null);return o=requestAnimationFrame(i),()=>{o&&cancelAnimationFrame(o)}}class hh{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;q5.debug(`scroll direction: ${i}`),this.cancelScroll=Z5(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 Q5(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 Ta(n,t){let e=`${n}`;const o=t-e.length;for(let r=0;r<o;r++)e=`0${e}`;return e}const{t:xs}=L;function Gm(n,t){const e=new Date(n).getTime()+864e5*t;return new Date(e)}function dx(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 hx(n,t){return Gm(n,t)}function Zm(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 Y5(n){const t=new Date,e=new Date(n);return Zm(t,e)}function J5(n){const t=Gm(new Date,-1);return Zm(t,n)}function fx(n,t){return Math.round((n.getTime()-t.getTime())/864e5)}function Qm(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",Ta(r,2)),a=a.replace("DD",Ta(i,2)),a=a.replace("M",`${r}`),a=a.replace("D",`${i}`),a=a.replace("hh",Ta(s,2)),a=a.replace("mm",Ta(l,2)),a=a.replace("h",`${s}`),a=a.replace("m",`${l}`),a}return n.toLocaleDateString()}function Ym(n,t){const e=new Date(n),o=new Date;if(e.getTime()-o.getTime()>10*1e3)return L.t("date.dateFromFuture");if(Y5(e)){const i=(o.getTime()-n.getTime())/1e3;if(i<10*60)return xs("date.dateJustNow");if(i<60*60)return xs("date.dateMinutesAgo",{num:`${Math.floor(i/60)}`});const s=Math.floor(i/60/60);return s===1?xs("date.date1HourAgo"):xs("date.dateHoursAgo",{num:`${s}`})}if(J5(n))return xs("date.dateYesterday");const r=Math.floor((o.getTime()-n.getTime())/1e3/24/60/60)+1;return r<14?xs("date.dateDaysAgo",{num:`${r}`}):r<28?xs("date.dateWeeksAgo",{num:`${Math.round(r/7)}`}):Qm(n,t)}function Jm(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function mx(n,t,e){return n.replace(new RegExp(Jm(t),"g"),e)}function gx(n,t,e){return n.replace(new RegExp(Jm(t),"gi"),e)}function K5(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 X5=/[\u3040-\u30ff\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff\uff66-\uff9f\uAC00-\uD7AF]/,t4=" -\x7F0-9!-/:-@[-`{-~\u0370-\u03FF\u0400-\u04FF",px=new RegExp(`[${t4}]`),Cx=new RegExp(`([^(${t4})])`,"g"),e4=/(\ud83c[\udf00-\udfff])|(\ud83d[\udc00-\ude4f\ude80-\udeff])|[\u2600-\u2B55]/;function n4(n){return n.length===0?0:n.split("").reduce((t,e)=>{const o=(t<<5)-t+e.charCodeAt(0);return o&o},0)}function Ax(n,t=1){var o,r;return(r=((o=Array.from(n))==null?void 0:o.filter(i=>X5.test(i))).slice(-t))==null?void 0:r.join("")}function bx(n,t=1){var r;const e=Array.from((r=n==null?void 0:n.replace(Cx,""))==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 vx(n,t=1){var o,r;return(r=((o=Array.from(n))==null?void 0:o.filter(i=>e4.test(i))).slice(-t))==null?void 0:r.join("")}function yx(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 fh(n,t=1){if(!n||n.length===0)return"";const e=X5.test(n),o=px.test(n),r=e4.test(n);switch(!0){case e:return Ax(n,t);case o:return bx(n,t);case r:return vx(n,t);default:return yx(n,t)}}var o4=(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))(o4||{});function mh(n){const t=Object.values(o4),e=Math.abs(typeof n=="string"&&n.trim()?n4(n.trim()):0)%t.length;return t[e]}const r4=S("container-children");function me(n){const t=Array.from(n.querySelectorAll(":scope > .container-blocks > div[data-type=editor-block]"));return g(r4,t.length>0,"container have not any child block"),t}function ye(n){const t=n.querySelector(":scope > .container-blocks > div[data-type=editor-block]");return g(r4,t,"container have not any child block"),t}function Qe(n){const t=me(n);return t[t.length-1]}function Do(n){return me(n).length}function Ur(n,t){return me(n)[t]}const So=S("block-dom");function Is(n){return n instanceof HTMLDivElement?n.getAttribute("data-type")==="editor-block":!1}function i4(n){return n instanceof HTMLElement&&n.getAttribute("data-type")==="block-tools"}function s4(n){W(n,"block-hidden")}function l4(n){rt(n,"block-hidden")}function gh(n){return!xt(n,"block-hidden")}function it(n){const{id:t}=n;return g(So,t,"no block id"),t}function Dt(n){const t=n.getAttribute("data-block-type");return g(So,t,"invalid block dom, no data-type"),t}function nt(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 Ts(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 ot(n){const t=n.closest("div[data-type=editor-container]");return g(So,t,"failed to get block container"),t}function Lt(n){const t=n.querySelector(":scope >div[data-type=block-content]");return g(So,t,"no block content"),t}function ee(n){let t=n.querySelector(":scope >div[data-type=block-tools]");return t||(t=k("div",[],n),t.setAttribute("data-type","block-tools")),g(So,t,"no block tools"),t}function ph(n){const t=n.querySelector(":scope >div[data-type=block-tools]");return t||null}function c4(n){let t=n.querySelector(":scope > div[data-type=block-background]");return t||(t=k("div",[],n),t.setAttribute("data-type","block-background")),t}function a4(n,t,e){const o=n.editorDecorators.decorateBlock(t,e),{id:r,type:i}=o;g(So,r,"no block id");const s=k("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 Ds(n,t){const e=k(t,[],null);return e.setAttribute("data-type","block-content"),n&&n.appendChild(e),e}function u4(n){const t=k("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 Da(n){const t=n.getAttribute("data-box-type");return g(So,t,"not a valid box element, no type"),t}function Km(n){return n instanceof HTMLSpanElement?n.getAttribute("data-type")==="editor-box":!1}function d4(n){const{id:t}=n;return g(So,t,"no box id"),t}function Xm(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 h4(n){n.innerHTML="",k("span",["box-space-start"],n,ya);const t=k("span",[],n);return t.setAttribute("data-type","box-content"),k("span",["box-space-start"],n,ya),t}function tg(n){const t=n.querySelector("span[data-type=box-content]");return g(So,t,"invalid box dom, no content"),t}function f4(n,t){const e=k("span",[`${n}-insertion`],null);return e.setAttribute("data-type","editor-insertion"),e.setAttribute("data-insertion-id",t),e}function m4(n,t){return n.rootContainer.querySelector(`[data-insertion-id=${t}]`)}function g4(n){n.innerHTML="",k("span",["insertion-space-start"],n,ya);const t=k("span",[],n);return t.setAttribute("data-type","insertion-content"),k("span",["insertion-space-start"],n,ya),t}function eg(n){const t=n.querySelector("span[data-type=insertion-content]");return g(So,t,"invalid insertion-child dom, no content"),t}function ae(n){let t=n.previousElementSibling;for(;t;){if(Is(t))return t;t=t.nextElementSibling}return null}function Qt(n){let t=n.nextElementSibling;for(;t;){if(Is(t))return t;t=t.nextElementSibling}return null}function Ss(n){let t=n.previousElementSibling;for(;t;){if(Is(t)&&gh(t))return t;t=t.previousElementSibling}return null}function Ls(n){let t=n.nextElementSibling;for(;t;){if(Is(t)&&gh(t))return t;t=t.nextElementSibling}return null}function bt(n){const t=ot(n),o=me(t).indexOf(n);return g(So,o!==-1,"invalid block & container dom, failed to get block index"),o}function ng(n){return!n||!(n instanceof Node)?!1:!!nt(n)}function Ms(n){if(!ng(n))return!1;const t=n,e=t instanceof Element?t:t.parentElement;return e?!!e.closest("div[data-type=block-tools]"):!1}const p4=S("block-class");function Yt(n,t){return n.editorBlocks.getBlockClass(Dt(t))}function C4(n,t){const e=n.editorBlocks.getBlockClass(Dt(t));return g(p4,e.blockKind==="text",`is not a text block, ${e.blockType}`),e}function zn(n,t){const e=n.editorBlocks.getBlockClass(Dt(t));return g(p4,e.blockKind==="complex",`is not a text block, ${e.blockType}`),e}function Rs(n,t){return n.editorBlocks.getBlockClass(t)}function et(n,t){return Yt(n,t).blockKind==="text"}function Sa(n,t){return n.editorBlocks.getBlockClass(t).blockKind==="text"}function Mt(n,t){return Yt(n,t).blockKind==="complex"}function kx(n,t){return!Mt(n,t)}function Lo(n,t){return Yt(n,t).blockKind}function Mo(n,t,e){return Yt(n,t).getCaretRect(t,e)}const A4=S("container");function zr(n){return n.getAttribute("data-type")==="editor-container"}function Gt(n){return xt(n,"root")}function Ro(n){return xt(n,"child")}function ct(n){const t=n.getAttribute("data-container-id");return g(A4,t,"no id for container"),Gt(n)&&g(A4,t==="root",`invalid root container id, : ${t}`),t}function b4(n,t){const e=ct(n);return t.getContainerBlocks(e)}const og=S("block");function ut(n,t){return Yt(n,t).getBlockTextLength(t)}function v4(n){n.editorBlocks.forEach(t=>{t.clearSelection(n)})}function y4(n,t,e,o){Yt(n,t).updateSelection(n,t,e,o)}function rg(n){for(;;){const t=ot(n);if(Gt(t))return n;const e=nt(t);g(og,e,"no parent block exists for child container"),n=e}}function k4(n,t){const e=Yt(n,t);if(!!e.getMinWidth)return e.getMinWidth(n,t)}function w4(n,t,e){const o=Yt(n,t);o.handleBlockElementUpdated&&o.handleBlockElementUpdated(n,t,e)}function Ch(n,t,e,o){try{const r=Rs(n,e).convertFrom;return r?r(n,t,o):null}catch{return og.debug(`unsupported block type: ${e}`),null}}function Vr(n,t,e){const o=Yt(n,t);return o.getClientRects?o.getClientRects(n,t,e):[t.getBoundingClientRect()]}function wx(n,t){const e=Yt(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(og,s==="string"||s==="number"||s==="boolean","invalid style value")}),r}function ue(n,t){return Lo(n,t)==="text"?ut(n,t)===0:!1}const B4=S("block-path");function _i(n){const t=[];let e=n;for(;e;){const o=ot(e);if(t.unshift({containerId:ct(o),blockIndex:bt(e)}),Gt(o))return t;const r=nt(o);g(B4,r,"no parent block"),e=r}return g(B4,!1,"no parent block"),[]}function Bx(n,t){var r,i;const e=Yt(n,t);return(i=(r=e.getOptions)==null?void 0:r.call(e,n))!=null?i:{name:Dt(t)}}function lo(n){return Gt(ot(n))}function E4(n,t){var r;const e=Yt(n,t);return(r=e.getBlockProperties)==null?void 0:r.call(e,n,t)}function ig(n,t){var i,s;const e=Yt(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 Ex(n,t,e){var s,l,a,d;const o=Yt(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 x4(n,t,e){let o=t;for(;o;){const r=Ex(n,o,e);if(r.length>0)return{element:Lt(o),commands:r};if(lo(o))break;o=Ts(o)}return{element:null,commands:[]}}const I4=S("embed-block-common");function Ie(n){return Dt(n)==="embed"}function fn(n){g(I4,Ie(n),"not an embed block");const t=n.getAttribute("data-embed-type");return g(I4,t,"no embed data type"),t}function xx(n,t){return n.editorEmbeds.getEmbedClass(fn(t))}function Os(n,t){return n.editorEmbeds.getEmbedClass(t)}async function sg(n,t,e,o,r){const i=Os(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 Ix(n,t,e,o,r){var l,a;const i=(a=(l=Rs(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 Tx=S("execute-block-command");function T4(n,t,e,o){var d;g(Tx,Ie(t),"not a embed block");const r=fn(t),i=Os(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 D4(n,t,e,o){const r=ig(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 Wr=S("text-block-child");function La(n){return n.tagName==="SPAN"}function co(n){return g(Wr,La(n),"not a valid text child"),n.getAttribute("data-type")==="editor-box"}function qr(n){return g(Wr,La(n),"not a valid text child"),n.getAttribute("data-type")==="editor-insertion"}function Ma(n){return!co(n)&&!qr(n)}function S4(n){return g(Wr,La(n),"not a valid text child"),co(n)?"box":qr(n)?"insertion":"text"}function ao(n){const t=S4(n);return t==="insertion"?0:t==="box"?1:(g(Wr,n.textContent!==null,"text block content is undefined"),g(Wr,n.textContent.length>=0,"text block content length is negative"),n.textContent.length)}function ir(n){const t=Lt(n),e=Array.from(t.children);return e.forEach(o=>{g(Wr,La(o),"not a valid text child")}),e}function Ah(n,t){const e=ir(n);let o=0;for(let r=0;r<e.length;r++){const i=e[r],s=ao(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(Wr,l>0,"invalid offset value"),g(Wr,!co(i),"invalid box child"),{prev:i,next:i,offset:l}}g(Wr,!1,`invalid block child at position: ${t}`)}const L4=S("element");function lg(n,t,e){const o=k("div",[t],n);return o.setAttribute("data-type","editor-container"),o.setAttribute("data-container-id",e),k("div",["container-blocks"],o),o}function sr(n,t){const e=n.rootElement.querySelector(`[data-container-id=${t}]`);return g(L4,e,`no container: ${t}`),e}function bh(n,t){return n.rootElement.querySelector(`[data-container-id=${t}]`)}function vh(n){const t=n.querySelector(":scope > .container-blocks");return g(L4,t,"no container blocks element"),t}function Dx(n){let t=n.querySelector(":scope > .container-tools");return t||(t=k("div",["container-tools"],n)),t}const Sx=S("child-container-path");function M4(n){if(Gt(n))return[];const t=nt(n);return g(Sx,t,"no parent block"),_i(t)}const R4=S("load-blocks");function cg(n,t,e){const o=ct(t),r=b4(t,n.doc);g(R4,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)}),vh(t).appendChild(i)}function Lx(n,t,e){const o=vh(n);if(t===0)return o.insertBefore(e,o.firstChild),e;const r=me(n);return g(R4,t>=0&&t<=r.length,"invalid block index"),t===r.length?o.appendChild(e):o.insertBefore(e,r[t]),e}function Mx(n,t,e,o){const r=M4(t);r.push({containerId:ct(t),blockIndex:e});const i=n.editorBlocks.createBlock(r,t,o);return Lx(t,e,i),i}const O4=S("root-container");class Rx{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){O4.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(!Ms(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&&te(this.rootContainer,o)){const r=nt(o);r&&te(r,o)&&this.handleBlockClick(t,r,o)}}});m(this,"handleBlockClick",(t,e,o)=>{var s,l;if(!et(this.editor,e))return;const r=Xm(o);if(r){const a=nt(r);g(O4,a,"no parent block"),(l=(s=this.editor.editorBoxes.getBoxClass(Da(r)))==null?void 0:s.handleClickBox)==null||l.call(s,this.editor,r,t);return}const i=o.closest("span.text.link");i&&ir(e).indexOf(i)!==-1&&this.editor.emit("clickLink",this.editor,t,i)});m(this,"handleDblClick",t=>{Ms(t.target)||this.editor.selectionHandler.handleDblClick(t)});m(this,"handleMouseDown",t=>{const e=t.target;if(!!e&&e instanceof Node&&!Ms(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 vs(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=vh(this.rootContainer);e.innerHTML="",cg(this.editor,this.rootContainer,[]);const o=this.editor.findBlockById(t.start.blockId);if(o)this.editor.selection.selectBlock(o,0);else{const r=ye(this.rootContainer);this.editor.selection.selectBlock(r,0)}}}function _4(n){const t=lg(n.contentElement,"root","root");return n.rootContainer=t,cg(n,t,[]),new Rx(n,t)}function F4(n,t,e,o){const r=bh(n,o);if(r)return e.appendChild(r),setTimeout(()=>{n.emit("containerRemount",n,o)}),r;const i=lg(e,"child",o);return cg(n,i,t),i}function P4(n,t){const e=n.getBoundingClientRect().width;return t.withPadding?e:e-Om(n)}function ag(n,t){let e=Number.MAX_SAFE_INTEGER;const o=me(t);for(let i=0;i<o.length;i++){const s=o[i],l=k4(n,s);l&&(e=Math.min(e,l))}return e===Number.MAX_SAFE_INTEGER?void 0:e+Om(t)}function Ra(n,t){const e=me(t);return e.length!==1?!1:ue(n,e[0])}const Ox=S("complex-block-position");class Oo{constructor(t,e,o){m(this,"blockId");m(this,"childContainerId");m(this,"custom");t instanceof HTMLElement?this.blockId=it(t):(g(Ox,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 _x=S("simple-block-position");class Ue{constructor(t,e,o){m(this,"blockId");m(this,"offset");m(this,"type");t instanceof HTMLElement?this.blockId=it(t):(g(_x,typeof t=="string",`not a valid block id: ${t}`),this.blockId=t),this.offset=e,this.type=o}isSimple(){return!0}}const ug=S("editor-position");function st(n,t,e){return new Ue(n,t,e)}function fe(n,t,e){return new Oo(n,t,e)}function Gr(n){return n instanceof Ue}function Gl(n){return n instanceof Oo}function dg(n,t,e){if(Gr(t)&&Gr(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(ug,i!==s,"comparePosition: blocks are the same"),rh(i,s)}if(Gl(t)&&Gl(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(ug,i!==s,"comparePosition: containers are the same"),rh(i,s)}return g(ug,!1,"invalid "),0}const yh=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=dg(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(yh,e,"no start block"),g(yh,o,"no end block");const r=ot(e),i=ot(o);g(yh,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(yh,l<a,"invalid range, start > index"),s.push({block:e,start:this.start,end:st(e,ut(this.editor,e),"end")});const d=me(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 Fx(n,t,e,o,r){W(o,"unknown-block");const i=Ds(o,"div");return i.innerText=`unknown block (${r.type}): ${JSON.stringify(r)}`,i}function Px(n){return 1}function Nx(n,t,e,o){return null}function $x(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 Hx(n,t){const o=Lt(n).getBoundingClientRect();return new DOMRect(o.left+o.width/2,o.top,1,o.height)}function jx(n,t,e,o){W(t,"selected")}function Ux(n){n.rootContainer.querySelectorAll("div.unknown-block[data-type=editor-block]").forEach(t=>{rt(t,"selected")})}function zx(n,t,e,o){return`[unknown block, ${t.type}]`}const Vx={blockType:"unknown-block",blockKind:"embed",createBlockContent:Fx,getBlockTextLength:Px,getRangeFromPoint:$x,moveCaret:Nx,getCaretRect:Hx,updateSelection:jx,clearSelection:Ux,convertTo:zx},hg=S("editor-blocks");class N4{constructor(t){m(this,"blocks",new Map);this.editor=t}registerBlockClass(t){const e=t.blockType,o=this.blocks.get(e);g(hg,!o,`duplicated block type: ${e}`),this.blocks.set(e,t)}getBlockClass(t){const e=this.blocks.get(t);return g(hg,e,`unknown block type: ${t}`),e}hasBlock(t){return this.blocks.has(t)}createBlock(t,e,o){const r=a4(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&&(hg.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={...Vx,blockType:t};return this.editor.editorBlocks.registerBlockClass(e),e}}const $4=S("editor-embeds");class H4{constructor(t){m(this,"objects",new Map);this.editor=t}registerEmbedClass(t){const e=t.embedType,o=this.objects.get(e);g($4,!o,`duplicated embed object type: ${e}`),this.objects.set(e,t)}getEmbedClass(t){const e=this.objects.get(t);return g($4,e,`unknown embed type: ${t}`),e}getEmbedClassFromBlock(t){return this.getEmbedClass(fn(t))}forEach(t){this.objects.forEach(t)}}const j4=S("embed-block");function Wx(n,t,e,o,r){const i=Ds(o,"div");g(j4,r.type==="embed",`not an embed data: ${JSON.stringify(r)}`);const s=r;return g(j4,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 qx(n){return 1}function Gx(n,t,e,o){return null}function Zx(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 Qx(n,t){const o=Lt(n).getBoundingClientRect();return new DOMRect(o.left+o.width/2,o.top,1,o.height)}function Yx(n,t,e,o){W(t,"selected")}function Jx(n){n.rootContainer.querySelectorAll("div.embed-block[data-type=editor-block][data-block-type=embed]").forEach(t=>{rt(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 Xx(n,t,e,o){const r=Os(n,t.embedType);return r.convertTo?r.convertTo(n,t,e,o):""}function tI(n,t){const e=xx(n,t);return e.getBlockProperties?e.getBlockProperties(n,t):{}}function eI(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 nI(n,t,e,o){const r=fn(t),i=Os(n,r);!i.handleDeleteBlock||i.handleDeleteBlock(n,t,e,o)}function oI(n,t,e){const o=fn(t),r=Os(n,o);return r.handleUpdateBlock?r.handleUpdateBlock(n,t,e):!1}function rI(n,t,e,o,r){const i=fn(t),s=Os(n,i);if(s.handleDropOver)return s.handleDropOver(n,t,e,o,r)}function iI(n,t,e,o,r){const i=fn(t),s=Os(n,i);if(s.handleDrop&&n.isWritable())return s.handleDrop(n,t,e,o,r)}async function sI(n,t,e){const o=t.embedType,r=n.editorEmbeds.getEmbedClass(o);if(r.toStandardDoc){const i=n.getBlockById(t.id),s=_i(i);return r.toStandardDoc(n,t,e,s)}}const U4={blockType:"embed",blockKind:"embed",createBlockContent:Wx,getBlockTextLength:qx,getRangeFromPoint:Zx,moveCaret:Gx,getCaretRect:Qx,updateSelection:Yx,clearSelection:Jx,convertFrom:Kx,convertTo:Xx,getBlockProperties:tI,getOptions:eI,handleDeleteBlock:nI,handleUpdateBlock:oI,handleDropOver:rI,handleDrop:iI,toStandardDoc:sI},mn=S("complex-block-helper");function gn(n,t,e){return zn(n,t).getChildContainers(n,t,e)}function Zl(n,t,e,o){return e.isSimple()?(g(mn,o.isSimple(),"invalid start and end position"),gn(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 lI(n,t){if(bt(t)!==0)return!1;const e=nt(ot(t));if(!e)return!1;g(mn,Mt(n,e),"not a complex block");const o=ot(t),i=gn(n,e).indexOf(o);return g(mn,i>=0,"not valid child container"),i===0}function fg(n,t,e){const o=gn(n,t,e);if(o.length===0)return null;const r=o[0];if(!r)return null;const i=ye(r);return Mt(n,i)?fg(n,i,e):i}function Ql(n,t,e){const o=gn(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)?Ql(n,i,e):i}function z4(n,t){g(mn,Ro(t),"not a child container");const e=nt(t);g(mn,e,"no parent block"),g(mn,Mt(n,e),"not a complex block");const o=gn(n,e),r=o.indexOf(t);if(g(mn,r!==-1,"child container not found"),r===0){const l=ae(e);return l?Mt(n,l)?Ql(n,l):l:null}const i=o[r-1],s=Qe(i);return Mt(n,s)?Ql(n,s):s}function V4(n,t){g(mn,Mt(n,t),"not a complex block");const e=gn(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 W4(n,t){g(mn,Mt(n,t),"not a complex block");const e=gn(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 q4(n,t,e,o){const r=t.getBoundingClientRect(),i=o<r.top,s=i?V4(n,t):W4(n,t);let l=s[0],a=or(l.getBoundingClientRect(),e,o);for(let d=1;d<s.length;d++){const h=s[d],p=h.getBoundingClientRect(),C=or(p,e,o);C<a&&(l=h,a=C)}return i?ye(l):Qe(l)}function kh(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 lr{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=dg(this.editor,this._anchor,this._focus)>0}isCollapsed(){return!1}isEqual(t){if(!(t instanceof lr))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 Zl(this.editor,t,this.start,this.end)}clone(){return new lr(this.editor,this)}toDocRange(){return{anchor:this._anchor,focus:this._focus}}}const cI=S("selection-range");function ze(n,t){const{anchor:e,focus:o}=t;return e instanceof Ue&&o instanceof Ue?new Ye(n,{anchor:e,focus:o}):(g(cI,e instanceof Oo&&o instanceof Oo,"start position type does not math end type"),new lr(n,{anchor:e,focus:o}))}function ke(n,t,e,o){const r=new Ue(t,e,"normal"),i=new Ue(t,o!=null?o:e,"normal");return ze(n,{anchor:r,focus:i})}function aI(n){return!!n.anchor.childContainerId}function Fi(n,t){var r,i;if(aI(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 ze(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 ze(n,{anchor:e,focus:o})}const G4=S("range-from-point");function wh(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 G4.debug("click on scrollbar, out of element rect"),null;if(!n.rootContainer.contains(i))continue;const l=nt(i);if(!l||!n.contains(l))continue;const a=Yt(n,l).getRangeFromPoint(n,l,t,e+o[r]);if(a)return a}return null}function Z4(n,t,e,o){const r=t.getBoundingClientRect();if(o<=r.top){const a=ye(t),d=Yt(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=Yt(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 Q4(n,t,e){const o=wh(n,t,e);if(o){if(o instanceof Ye)return o;g(G4,o instanceof lr,`invalid range type: ${typeof o}`);const a=o,d=n.getContainerById(a.start.childContainerId);return Z4(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=>zr(a));if(s.length===0)return null;const l=s.reduce((a,d)=>{const h=a.getBoundingClientRect(),p=d.getBoundingClientRect();return or(h,t,e)>or(p,t,e)?d:a});return Z4(n,l,t,e)}function mg(n,t){const e=[];return me(t).forEach(r=>{e.push(r),Mt(n,r)&&gn(n,r).forEach(s=>{e.push(...mg(n,s))})}),e}function gg(n,t){let e=mg(n,n.rootContainer);return t!=null&&t.simpleBlockOnly&&(e=e.filter(o=>!Mt(n,o))),e}function cr(n,t){const e=n.selection.range.getSelectedBlocks(),o=[];for(const r of e)o.push(r),Mt(n,r.block)&&Zl(n,r.block,r.start,r.end).forEach(s=>{const a=mg(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 sot="",Je=S("text-range");function uI(n,t){const e=(i,s)=>{if(qr(i))return g(Je,s===0,`invalid offset for insertion child: ${s}`),{child:i,container:i,offset:2};if(co(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=ir(n);for(let i=0;i<r.length;i++){const s=r[i],l=ao(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,ao(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 dI(n,t,e){if(t===e?g(Je,qr(n),"only insertion child can be zero offset"):g(Je,t<e,`invalid start & end: ${t}, ${e}`),qr(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}`),nh(i,1,i,2)}if(co(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}`),nh(i,1,i,2)}const o=ao(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}`),nh(r,t,r,e)}const _o=S("caret-rect");function hI(n,t){if(Km(t)){const e=t,o=tg(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(_o,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 eg(t).getClientRects()}function Vn(n,t){var l,a,d;const e=uI(n,t.offset);if(e[1]&&e[0].child!==((l=e[1])==null?void 0:l.child)){if(t.type==="end"){const p=ks(e[0].child);return new DOMRect(p.right,p.top,1,p.height)}g(_o,e[1],"invalid ranges");const h=oh(e[1].child);return new DOMRect(h.left,h.top,1,h.height)}let r=e[0];if(g(_o,e.length>=1,"failed to get block range"),e.length===1)r=e[0];else{if(g(_o,e.length>=2,`invalid range info length: ${e.length}`),qr(e[e.length-1].child)){r=e[e.length-1];const h=r.child,C=eg(h).getClientRects();g(_o,C.length>=1,"no client rects for box content");const v=C[C.length-1];return new DOMRect(v.right,v.y,1,v.height)}t.type==="home"?r=e[1]:t.type==="end"||Ma(e[0].child)?r=e[0]:Ma(e[1].child)&&(r=e[1])}if(r.container instanceof HTMLBRElement){g(_o,t.offset===0,"invalid offset for empty block text");const h=r.container.parentElement;g(_o,h,"invalid br parent");const p=h.getBoundingClientRect();return new DOMRect(p.left,p.top,1,p.height)}const i=v5(r.container,r.offset),s=Array.from(i.getClientRects());if(s.length===0){g(_o,!Ma(r.child),"only box or insertion child range has zero client rect"),g(_o,r.offset===1||r.offset===2,"invalid offset for box or insertion child");const h=r.child,p=hI(n,h);if(g(_o,p.length>=1,"no client rects for box content"),r.offset===1){const v=p[0];return new DOMRect(v.x,v.y,1,v.height)}const C=p[p.length-1];return t.type==="end"||r.offset===2?new DOMRect(C.right,C.y,1,C.height):new DOMRect(C.x,C.y,1,C.height)}if(Ba()||Vl()){const h=document.createRange();h.selectNodeContents(r.container);const p=h.getClientRects();if(r.container.nodeType===Node.TEXT_NODE&&r.offset<((d=(a=r.container.textContent)==null?void 0:a.length)!=null?d:0)){const C=document.createRange();C.setStart(r.container,r.offset+1);const v=C.getClientRects();Array.from(p).forEach((B,D)=>{if(v[0].top!==s[0].top&&v[0].top===B.top){const{x,y:_,height:R}=p[D];s.push(new DOMRect(x,_,0,R))}})}if(r.container.nodeType===Node.TEXT_NODE&&r.offset>0){const C=document.createRange();C.setStart(r.container,r.offset-1);const v=C.getClientRects();Array.from(p).forEach((B,D)=>{if(v[0].top!==s[0].top&&v[0].top===B.top){const{x,y:_,height:R}=p[D];s.length===1&&s.unshift(new DOMRect(x,_,0,R))}})}}return g(_o,s.length>0,"no client rects for range"),t.type==="home"?s[s.length-1]:s[0]}const fI=S("core");function Zr(n,t,e,o){const r=ee(t);let i=r.querySelector(`.block-anchor[data-id=${e}]`);i||(i=k("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 Y4(n,t,e,o){g(fI,et(n,t),"not a text kind block");const r=Vn(t,st(t,e,"normal")),i=t.getBoundingClientRect(),s=ee(t);let l=s.querySelector(`.block-anchor[data-id=${o}]`);l||(l=k("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 Oa(n){const t=ir(n);let e=0;return t.forEach(o=>{e+=ao(o)}),e}const J4=S("box");function _a(n){return!n.attributes||!n.attributes.box?!1:(g(J4,n.attributes.box===!0,`invalid op attribute box property, ${n.attributes.box}`),g(J4,n.attributes.type,`no box type: ${JSON.stringify(n)}`),!0)}const K4=S("rich-text-length");function pg(n){return g(K4,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(K4,typeof e.insert=="string","op.insert is not string"),t+=pg(e))}),t}const ar=S("split-text");function Tn(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(ar,typeof i=="object",`invalid op type, ${typeof i}`),g(ar,typeof i.insert=="string",`invalid op.insert type, ${typeof i.insert}`);const s=pg(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(ar,o+s>t,`invalid offset, ${o}, ${s}, ${t}`);const l=t-o,a=mt.default(i);g(ar,a.insert,"no copied.insert"),g(ar,typeof a.insert=="string","invalid copied.insert type"),a.insert=a.insert.substr(0,l),i.insert=i.insert.substr(l),a.insert===""&&g(ar,!1,"invalid copied.insert, is empty string"),i.insert===""&&g(ar,!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 Ve(n,t,e){g(ar,t>=0,"invalid offset, < 0"),g(ar,e>0,"invalid length, <= 0"),g(ar,t+e<=rn(n),"invalid offset + length < text length");const{left:o,right:r}=Tn(n,t+e),{left:i,right:s}=Tn(o,t);return{left:i,middle:s,right:r}}function X4(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}=Tn(r,s);r=l,o.unshift(a)}return r.length>0&&o.unshift(r),o}function t6(n,t,e){return Ve(n,t,e).middle}const Yl=S("text-block-content");function mI(n,t,e,o,r){if(g(Yl,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,C)=>{const v=r==null?void 0:r.get(C);v&&(v.forEach(B=>{p.appendChild(s(B))}),r==null||r.delete(C))},a=document.createDocumentFragment();let d=0;const h=X4(o,i);for(let p=0;p<h.length;p++){l(a,d);const C=h[p];d+=rn(C);for(let v=0;v<C.length;v++){const B=C[v];if(_a(B)){g(Yl,B.attributes,`op is not an valid box: ${JSON.stringify(B)}`);const x=n.editorBoxes.createBox(e,B.attributes);g(Yl,x instanceof HTMLSpanElement,`invalid box element: ${x.tagName}`),a.appendChild(x);continue}g(Yl,B.insert,`no insert in op: ${JSON.stringify(B)}`);const D=k("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(([_,R])=>{D.setAttribute(_,R)}),x.styles&&Object.entries(x.styles).forEach(([_,R])=>{D.style.setProperty(_,R)})}a.appendChild(D)}}l(a,d),e.innerHTML="",e.appendChild(a)}function Bh(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(Yl,a.isSimple(),"not an simple position while compositing"),a.blockId===e&&s.set(a.offset,[{type:"inputting",id:K(),text:l}])}return mI(n,t,o,i,s)}function gI(n){const t=n.rootContainer.querySelectorAll('span[data-type="editor-insertion"].inputting-insertion');t.length&&Yl.debug(`remove ${t.length} temp composition span`),Array.from(t).forEach(e=>e.remove())}const ur=S("client-rects");function pI(n){const t=ir(n);let e=0;const o=[];for(let r=0;r<t.length;r++){const i=t[r],s=ao(i);o.push({child:i,startBlockOffset:e,endBlockOffset:e+s}),e+=s}return o}function CI(n,t,e,o){g(ur,e<o,`invalid from & to: ${e}, ${o}`);const r=ut(n,t);g(ur,e>=0&&o>=0&&e<=r&&o<=r,`invalid offset: ${e}, ${o}, length: ${r}`);const i=pI(t),s=i.findIndex(v=>v.startBlockOffset<=e&&e<v.endBlockOffset),l=i.findIndex(v=>v.startBlockOffset<o&&o<=v.endBlockOffset);if(g(ur,s!==-1,"failed to find start child"),g(ur,l!==-1,"failed to find end child"),g(ur,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:ao(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],C={child:p.child,startChildOffset:0,endChildOffset:o-p.startBlockOffset};return a.push(C),a}function AI(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 e6(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=CI(n,t,r,i).map(d=>dI(d.child,d.startChildOffset,d.endChildOffset)),a=[];return l.forEach(d=>{const h=AI(Array.from(d.getClientRects()));a.push(...h)}),a}function bI(n,t,e){g(ur,e instanceof Ye,"invalid range");const o=e.start,r=e.end;return g(ur,o.isSimple(),"text block only allow simple position"),g(ur,r.isSimple(),"text block only allow simple position"),g(ur,o.blockId===r.blockId,"only allow update one text block selection"),g(ur,o.blockId===it(t),"only allow update one text block selection"),e6(n,t,o,r)}const Cg=S("selection-background");function vI(n,t,e,o){g(Cg,e.isSimple(),"text block only allow simple position"),g(Cg,o.isSimple(),"text block only allow simple position"),g(Cg,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=e6(n,t,e,o),l=t.getBoundingClientRect(),a=ro(t),d=c4(t);d.innerHTML="",s.forEach(h=>{const p=k("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 yI(n){n.rootContainer.querySelectorAll("div[data-type=block-background]").forEach(t=>{t.remove()})}const _s=S("text-offset"),n6="\u200D";function Fs(n,t){const e=ir(n);let o=0;for(let r=0;r<e.length;r++){const i=e[r],s=ao(i);if(i===t){const l=o+s;return{start:o,end:l}}o+=s}g(_s,!1,"can not find child in children")}function sn(n,t){g(_s,t>=0,`invalid offset: ${t}`);const e=Ah(n,t),{prev:o,next:r,offset:i}=e;if(!o&&!r&&g(_s,!1,"invalid offset, no prev & next child at offset"),o!==r)return!0;const s=o;if(g(_s,s,"no child"),co(s))return g(_s,i===0||i===1,`invalid box child offset: ${i}`),!0;const l=s.textContent;g(_s,l,"no content for text child");const a=l.charAt(i-1),d=l.charAt(i);return!(a===n6||d===n6||Mm(l[i]))}function Pi(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 Ps(n,t){const e=Oa(n);if(g(_s,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 Ns=S("line-breaker");function Fa(n){const t=a=>{const d=oh(a);return ks(a).top>d.top+d.height/2},e=(a,d)=>{const h=ks(a),p=oh(d);return Math.floor(p.left)<Math.floor(h.right)},o=(a,d)=>{const h=ks(a),p=ks(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=ir(n);for(let a=0;a<l.length;a++){const d=l[a];if(qr(d)){const x=d,_=l[a+1];if(!_)break;const R=l[a-1];if(R&&o(R,x)&&i.push({offset:s,type:"betweenChild",childInfo:{prevChild:R,nextChild:x,wrap:"nextWrapped",prevWrapped:t(R),nextWrapped:t(x)}}),e(x,_)){i.push({offset:s,type:"betweenChild",childInfo:{prevChild:R,nextChild:x,wrap:"nowrap",prevWrapped:t(R),nextWrapped:t(x)}});continue}continue}if(co(d)){const x=d,_=l[a+1];if(!_)break;const R=l[a-1];if(R&&o(R,x)&&i.push({offset:s,type:"betweenChild",childInfo:{prevChild:R,nextChild:x,wrap:"nextWrapped",prevWrapped:t(R),nextWrapped:t(x)}}),e(x,_)){s+=1,i.push({offset:s,type:"betweenChild",childInfo:{prevChild:R,nextChild:d,wrap:"nowrap",prevWrapped:t(R),nextWrapped:t(d)}});continue}s+=1;continue}const h=d,p=h.getClientRects();if(g(Ns,p.length>0,"invalid text child dom"),p.length===1){const x=l[a+1];if(!x)break;if(e(h,x)){s+=ao(h),i.push({offset:s,type:"betweenChild",childInfo:{prevChild:h,nextChild:x,wrap:"nowrap",prevWrapped:t(h),nextWrapped:t(x)}});continue}s+=ao(h);continue}const C=h.firstChild;g(Ns,C,"invalid text child, no text node"),g(Ns,C instanceof Text,`invalid text child, not a valid text node: ${typeof C}`);const v=document.createRange(),B=document.createRange(),D=ao(h);g(Ns,C.data.length===D,"text node data length not equal child text length");for(let x=0;x<C.data.length;x++){if(!sn(n,s+x))continue;v.setStart(C,x);const _=v.getClientRects();if(g(Ns,_.length>=1,"invalid text node, no client rects"),r(_)){const tt=s+x;i.push({offset:tt,type:"textBreakWord",childInfo:{prevChild:d,nextChild:d,wrap:"nowrap",prevWrapped:t(d),nextWrapped:t(d)}});continue}let R=x+1;sn(n,s+R)||(R=x+2),B.setStart(C,R);const H=B.getClientRects(),z=_[0];if(H[0].left<z.right)if(Ba()||Vl()){i.push({offset:Vl()?s+R:s+x,type:"textBreakWord",childInfo:{prevChild:d,nextChild:d,wrap:"nowrap",prevWrapped:t(d),nextWrapped:t(d)}});continue}else g(Ns,!1,"span pre-wrap should not has a line-wrap by white space")}s+=D}return i}function Ag(n,t){const e=Fa(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(Ns,t.offset<=Oa(n),"invalid position, offset > block length"),{lineIndex:e.length,lineBreaks:e}}const kI=S("line-offset");function bg(n){const t=Fa(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:Oa(n)}),e}function Eh(n,t){const e=bg(n);return g(kI,t>=0&&t<e.length,`invalid line index: ${t}, ${e.length}`),e[t]}function o6(n,t){const{lineIndex:e}=Ag(n,t);return Eh(n,e)}function wI(n){const t=bg(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 BI(n,t,e){const r=wI(n).find(s=>Bs(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 r6(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 i6(n){return bg(n).length}const $s=S("find-text-position");function s6(n,t){const{start:e,end:o}=Eh(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=Ah(n,e);return g($s,a.next,"no next child at offset"),g($s,!Ma(a.next),"next child is not text child"),!0}function EI(n,t){const e=it(n);g($s,s6(n,t),"line is not wrapped");const{start:o,end:r}=Eh(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(!r6(n,i,a))return s-1}return g($s,!1,"failed to find wrapped offset"),0}function xh(n,t,e,o,r,i,s){g($s,et(n,t),`not a text kind block: ${Dt(t)}`);const{start:l,end:a}=Eh(t,e);let d=l;const h=it(t);if(t===o&&s6(t,e)){const x=EI(t,e);(i==="up"||i==="down"&&r6(t,r,st(h,l,"home")))&&(d=x+1)}let p=Number.MAX_SAFE_INTEGER;const C=Mo(n,o,r),v=s!=null?s:C.left+C.width/2,B=C.top+C.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 R=st(h,x,_),H=Vn(t,R),z=or(H,v,B);z<p&&(p=z,D=R)}return D}function xI(n,t,e,o,r){return g($s,et(n,t),"not a text block"),xh(n,t,i6(t)-1,e,o,"up",r)}function II(n,t,e,o,r){return g($s,et(n,t),"not a text block"),xh(n,t,0,e,o,"down",r)}function TI(n,t,e,o){const{lineIndex:r}=Ag(t,e);if(r===i6(t)-1)return null;const i=xh(n,t,r+1,t,e,"down",o);return i||null}function DI(n,t){if(t.offset===0)return null;const e=Fa(n),o=e.find(r=>r.offset===t.offset);if(!o){const r=Pi(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:Pi(n,t.offset),type:"normal"}}return{offset:Pi(n,t.offset),type:"normal"}}function SI(n,t){const e=Oa(n);if(t.offset===e)return null;const o=Fa(n),r=o.find(i=>i.offset===t.offset);if(!r){const i=Ps(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:Ps(n,t.offset),type:"home"}:{offset:Ps(n,t.offset),type:"normal"}}function LI(n,t,e,o){const{lineIndex:r}=Ag(t,e);if(r===0)return null;const i=xh(n,t,r-1,t,e,"up",o);return i||null}const MI=S("move-caret");function RI(n,t,e,o){if(o==="ArrowLeft"){const r=DI(t,e);return r?st(it(t),r.offset,r.type):null}if(o==="ArrowRight"){const r=SI(t,e);return r?st(it(t),r.offset,r.type):null}if(o==="ArrowUp"){const r=LI(n,t,e,n.selection.getSuggestedCaretX());return r?st(it(t),r.offset,r.type):null}if(o==="ArrowDown"){const r=TI(n,t,e,n.selection.getSuggestedCaretX());return r?st(it(t),r.offset,r.type):null}g(MI,!1,`invalid navigation direction: ${o}`)}const vg=S("text-range");function OI(n){const t=[];return ir(n).forEach(o=>{const r=Array.from(o.getClientRects()).map(i=>({rect:i,child:o}));t.push(...r)}),t}function _I(n,t,e){const o=OI(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 Fs(n,s.child).start}return null}function FI(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(!Bs(_,e,o))return null;const R=_I(t,e,o);if(R!==null){const z=st(t,R,"normal");return new Ye(n,{anchor:z,focus:z})}const H=BI(t,e,o);return H?new Ye(n,{anchor:H,focus:H}):null}const s=ir(t);g(vg,s.indexOf(i)!==-1,"failed to find child in children");const l=Fs(t,i);g(vg,l,"failed to get child offset");const{start:a}=l;let d,h;qr(i)||co(i)?(d=a,h=0):(g(vg,i.firstChild instanceof Text,"child is not text"),d=a+y5(i.firstChild,e,o),h=0);const p=it(t),v=Fa(t).find(_=>_.offset===d);let B="normal";if(v){const _=st(p,d,"home"),R=st(p,d,"end"),H=Vn(t,_),z=Vn(t,R),Q=or(H,e,o),tt=or(z,e,o);B=Q<tt?"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 PI=S("create-text-op");function uo(n,t){g(PI,n,"text is empty");const e={insert:n};return t&&Object.keys(t).length>0&&(e.attributes=t),e}function yg(n,t){if(n.length===0)return[];if(n.indexOf(`
|
|
16
16
|
`)===-1)return[uo(n,t)];const e=n.replace(/\r\n/g,`
|
|
17
17
|
`).replace(/\r/g,`
|
|
18
18
|
`).replace(/\n/g," "),o=[];return e&&o.push(uo(e,t)),o}const Ih=S("merge-ops");function kg(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(Ih,i.attributes===void 0,"op2.attributes is not undefined"),!0):(g(Ih,r.attributes&&i.attributes,"op1.attributes && op2.attributes is undefined"),Ca.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(Ih,typeof o.insert=="string","before.insert is not string"),g(Ih,typeof i.insert=="string","op.insert is not string"),o.insert+=i.insert):(e.push(i),o=i)}return e}function NI(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 l6=S("delete-text");function wg(n,t,e){const{left:o,right:r}=Ve(n,t,e),i=[...o,...r];return kg(i)}function c6(n,t){g(l6,n>=0,`invalid offset: ${n}`),g(l6,t>=1,`invalid delete count: ${t}`);const e=[];return n!==0&&e.push({retain:n}),e.push({delete:t}),e}const a6=S("delta");function u6(n,t){const e=new on.default(n),o=new on.default(t);return e.diff(o).ops}function $I(n,t,e){return new on.default(t).transformPosition(n,!e)}function HI(n){g(a6,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 jI(n,t){const e=new on.default(n),o=new on.default(t);return e.compose(o).ops}class ln{static ensureValidText(t){g(a6,HI(t),`text is not a valid text, ${JSON.stringify(t)}`)}static diff(t,e){return this.ensureValidText(t),this.ensureValidText(e),u6(t,e)}static transformCursor(t,e,o){return $I(t,e,o)}static transformOffset(t,e,o){const r=u6(t,e),i=new on.default(r);return o.map(s=>i.transformPosition(s))}static apply(t,e){this.ensureValidText(t);const o=jI(t,e);return this.ensureValidText(o),o}}const d6=S("insert-text");function Qr(n,t,e,o){g(d6,e,`invalid text to insert: ${e}`);const{left:r,right:i}=Tn(n,t),s=typeof e=="string"?[uo(e,o)]:e,l=[...r,...s,...i];return kg(l)}function h6(n){return{insert:" ",attributes:n}}function Th(n,t,e){if(g(d6,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
|
|
@@ -490,7 +490,7 @@ ${s}
|
|
|
490
490
|
`}})}class dU{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),C=Number.parseInt(p,10);if(C>0&&C<=100)return Math.floor(720*C/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 hU(n){return new dU(n)}function xy(n,t){var a;const e=hU(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 C=e.getCellData({row:d,col:h});if(C&&C.virtual)continue;C&&!C.virtual&&(p=t.htmlToBlocks(C.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,C&&!C.virtual&&(l[h]=Math.max(l[h],ky((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 Iy(n,t){var e;if(n.tagName==="TABLE"){const o={blocks:{root:[]},meta:{},comments:{}},r=xy(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=Oi(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=>Iy(o,t))}function Ty(n){if(n instanceof HTMLStyleElement){n.remove();return}Array.from(n.children).forEach(Ty)}function Dy(n){if(n instanceof HTMLElement){if(n.style.display==="none"){n.remove();return}if(n.style.visibility==="hidden"){n.remove();return}}Array.from(n.children).forEach(Dy)}function fU(n,t){const e=ch(n);return e.querySelectorAll("td.js-line-number").forEach(r=>r.remove()),e.querySelectorAll("div.copy-button").forEach(r=>r.remove()),e.querySelectorAll("div.code-copy-button").forEach(r=>r.remove()),e.querySelectorAll("noscript").forEach(r=>r.remove()),Array.from(e.children).forEach(Dy),Array.from(e.children).forEach(r=>Iy(r,t)),Array.from(e.children).forEach(Ty),Ey(e),V5(e)}const Br=new cE.default;Br.use(oU),Br.use(rU),Br.use(iU),Br.use(sU),Br.use(lU),Br.use(cU),Br.use(aU),Br.use(uU),Br.use(ZB.gfm);function mU(n,t){const e=Sy(n,t);if(!e)return[];const{root:o,...r}=e.blocks;return t.doc.blocks={...t.doc.blocks,...r},o}function Sy(n,t){const e=Br.turndown(n);return By(e,{htmlToDoc:o=>Ly(o,t)})}function Ly(n,t){const e=fU(n,{font:t==null?void 0:t.font,htmlToBlocks:mU});return Sy(e)}function My(n){return n.indexOf('xmlns:o="urn:schemas-microsoft-com:office:office"')!==-1}function o1(n){return["A","B","DEL","I","U","S","SPAN","SUB","SUP","FONT","BR"].indexOf(n.tagName)!==-1}function gU(n){return["P","H1","H2","H3","H4","H5","H6","H7","H8","LI"].indexOf(n.tagName)!==-1}function Ry(n){return n.replace(/\r\n\s*/g,"").replace(/\n\s*/g,"").replace(/\r\s*/g,"")}function pU(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 CU(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 Oy(n){var e;return Array.from(((e=n.getAttribute("style"))!=null?e:"").split(" ")).findIndex(o=>o.startsWith("level"))!==-1}function AU(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 _y(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 bU(n,t){n.setAttribute("data-group-id",t)}function vU(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(Oy(r)){const i=AU(r);o!==i&&(e(0),o=i);const s=_y(r);e(s);let l=t[`${s}`];l||(l=K(),t[`${s}`]=l),bU(r,l)}})}function Fy(n){if(!Oy(n))return{};const t=_y(n),e=n.getAttribute("data-group-id")||K();return{start:1,level:t,groupId:e,ordered:!0,type:"list"}}const yU=S("office-list");function Py(n){return n instanceof HTMLOListElement||n instanceof HTMLUListElement}function kU(n,t){g(yU,Py(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=Fy(a),p=t.textElementToBlocks(a,t);l||(l=h.level);const C=p[0];s.push({...C,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 Ny(n,t){if(n.nodeName==="META")return[];if(n instanceof HTMLTableElement)return xy(n,t);if(Py(n))return[...kU(n,t)];if(pU(n))return[...CU(n)];if(gU(n))return[...t.textElementToBlocks(n,t)];if(!n.children)return[];const e=[];return Array.from(n.children).forEach(o=>{const r=Ny(o,t);e.push(...r)}),e}function $y(n,t){const e=[];return n.forEach(o=>{var r;if(o instanceof Element)if(o1(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=dr(Ry((r=o.textContent)!=null?r:""));e.push(i)}}),e}function Hy(n){const t=Array.from(n.children);for(let e=0;e<t.length;e++){const o=t[e];if(!o1(o))continue;let r=e+1;for(;r<t.length&&o1(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 wU(n,t){const e=ch(n);return Hy(e),$y(Array.from(e.childNodes),t)}function BU(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 EU(n,t){return t&&Object.keys(t).length>0?{insert:n,attributes:t}:{insert:n}}function xU(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 jy(n,t,e){var r;if(n instanceof HTMLSpanElement&&n.getAttribute("style")==="mso-list:Ignore")return;const o=xU(n,t);if(n instanceof Text&&n.nodeValue||n.nodeName==="BR"){const i=Ry((r=n.nodeValue)!=null?r:" ");i&&e.push(EU(i,o));return}n.childNodes.length>0&&Array.from(n.childNodes).forEach(i=>{jy(i,o,e)})}function Uy(n){return n instanceof Element?o1(n):!0}function I2(n){return!Uy(n)}function IU(n){if(n.length===0)return[];if(n.length===1)return[n];const t=[];let e=[n[0]],o=I2(n[0]);for(let r=1;r<n.length;r++){const i=n[r];o===I2(i)?e.push(i):(t.push(e),e=[i],o=I2(i))}return t.push(e),t}function TU(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=IU(Array.from(n.childNodes)),r=[];return o.forEach((i,s)=>{if(Uy(i[0])){const l=[],a={};Array.from(n.childNodes).forEach(h=>{jy(h,a,l)});let d={};s===0&&(d=Fy(n)),r.push({id:K(),type:"text",text:l,...d,...e,...BU(n)})}i.forEach(l=>{const a=t.blockElementToBlocks(l,t);r.push(...a)})}),r}function DU(n,t){const e=ch(n);vU(e),Hy(e);const o={blocks:{root:[]},meta:{},comments:{}},r={font:t==null?void 0:t.font,doc:o,blockElementToBlocks:Ny,textElementToBlocks:TU,htmlToBlocks:wU},i=$y(Array.from(e.children),r);if(i.length!==0)return o.blocks.root=i,o}const SU=S("html-to-doc");function zy(n,t){if(!n)return null;const e=Dj(n);if(e)return e;if(My(n)){const o=DU(n,t);if(o)return o}try{return Ly(n,t)}catch(o){SU.error(o)}return null}class LU{async fromData(t,e){const o={},r=e.getData("text/html");if(r){const i=zy(r,{font:t.rootContainer});i&&(My(r)?o["text/office-html"]=i:o["text/html"]=i)}return o}}class MU{async fromData(t,e){const o=e.getData("text/plain");if(!o)return;const r=By(o,{font:t.rootContainer,htmlToDoc:zy});if(!!r)return{"text/markdown":r}}}function RU(n){return/^([\d\w\u4e00-\u9fa5\s]*[\u4e00-\u9fa5\s]{1}|)((https|http|ftp)?:\/\/)[^\s]+/.test(n)}function OU(n){const t=[],e=n.split(/https|http|ftp/)[0],o=n.substring(e.length).trim();if(e&&e.length){const i=uo(e,null);t.push(i,uo(" ",null))}const r=uo(o,{link:o});return t.push(r,uo(" ",null)),t}class _U{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,`
|
|
491
491
|
`).replace(/\r/g,`
|
|
492
492
|
`).split(`
|
|
493
|
-
`).map(h=>{const p={id:K(),type:"text"};if(RU(h)&&!r)return p.text=OU(h),p;const C=h?[uo(h,null)]:[];return p.text=C,p})},meta:{},comments:{}};i["text/plain"]=d}return i}}function FU(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 T2{constructor(t){t.dataConverter.addConverter(new LU),t.dataConverter.addConverter(new _U),t.dataConverter.addConverter(new MU)}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=FU(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=ot(i),a=bt(i);const d=nt(s);if(d&&Dt(d)==="code")return;if(o.blockId===r.blockId&&Ie(i))a+=1;else{t.clearSelectedContents();const{blockId:p}=t.selection.range.start,C=t.getBlockById(p);a=bt(C),s=ot(C),ue(t,C)||(a+=1),Gt(s)&&a===0&&(a+=1)}const h=ct(s);for(let p=0;p<e.length;p++){const C=e[p],v=await sg(t,"image",h,a+p,{file:C});v&&T4(t,v,"image",{id:"replace-image",name:"Replace image",data:{block:v,image:C}})}}}class PU extends ve.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=Ur(sr(this.editor,t),e);!et(this.editor,i)||!o.some(l=>l.insert||l.delete)||this.emit("onDocChanged",i)}onInsertBlock(t,e,o,r){Ur(sr(this.editor,t),e),this.emit("onDocInserted")}onDeleteBlock(t,e,o){const r=Ur(sr(this.editor,t),e);this.emit("onDocDeleted",r)}}function Vy(n){return Ze.isSafari&&!!n&&Date.now()-n<100}const Wy=S("highlight-data");class r1{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(Wy,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 r1(t))}}function NU(n,t,e,o,r){const s=r1.getData(n).add(t,e,o);return r.setAttribute("data-highlight-id",s.id),s}function i1(n,t){const e=t.getAttribute("data-highlight-id");return g(Wy,e,"invalid highlight elem, no id"),r1.getData(n).get(e)}const Lc=S("highligh-dom");function $U(n){return xt(n,"editor-highlight")}function Er(n){const t=n.rootContainer.querySelectorAll(".editor-highlight");return Array.from(t)}function HU(n,t){g(Lc,t,"invalid block");const e=t.querySelectorAll(".editor-highlight");return Array.from(e)}function jU(n){const t=n.rootContainer.querySelectorAll(".editor-replace-result-highlight");return Array.from(t)}function s1(n){const t=n.querySelectorAll(".editor-highlight");return Array.from(t)}function UU(n){s1(n).forEach(t=>{t.remove()})}function ri(n){return Er(n).length}function zU(n,t){g(Lc,t>=0,`invalid highlight index: ${t}`);const e=Er(n);return e.length===0?null:(g(Lc,t<e.length,`invalid highlight index: ${t}/${e.length}`),e[t])}function VU(n,t,{left:e,top:o,width:r,height:i},s){const l=["editor-highlight-child"];s&&l.push("editor-highlight-readonly");const a=k("div",l,n);a.style.top=`${o}px`,a.style.left=`${e}px`,a.style.width=`${r}px`,a.style.height=`${i}px`}function qy(n,t,e,o,r){g(Lc,o>0,`invalid end: ${o}`);const i=ee(t),s=t.getBoundingClientRect(),l=Vr(n,t,ke(n,t,e,o)),d=k("div",[r==="find"?"editor-highlight":"editor-replace-result-highlight"],i);l.forEach(h=>{VU(d,t,{left:h.left-s.left,width:h.width,top:h.top-s.top,height:h.height})}),NU(n,t,e,o,d)}function WU(n,t,e,o){return qy(n,t,e,o,"find")}function Gy(n,t,e,o){return qy(n,t,e,o,"replace")}function l1(n,t){Er(n).forEach(s=>{xt(s,"active")&&rt(s,"active")}),W(t,"active"),g(Lc,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),sh(o,{elementToScroll:n.scrollContainer})}function qu(n){const t=n.rootContainer.querySelector(".editor-highlight.active");return t||null}function Zy(n){return g(Lc,n,"no highlight elem"),xt(n,"editor-highlight-readonly")}const Mc=S("highligh-text");function Qy(n){jU(n).forEach(e=>{e.remove()})}function c1(n,t){Er(n).forEach(o=>{o.remove()}),t!=null&&t.keepReplaceResult||Qy(n)}function Yy(n,t,e){HU(n,t).forEach(r=>{r.remove()}),e!=null&&e.keepReplaceResult||Qy(n)}function Gu(n){const t=qu(n);if(!t)return-1;const o=Er(n).indexOf(t);return g(Mc,o!==-1,`invalid highlight index: ${o}`),o}function qU(n){const t=Er(n);if(t.length===0)return 0;const e=qu(n);let o=e?t.indexOf(e):-1;!e||o===-1||o===t.length-1?o=0:o+=1;const r=t[o];return l1(n,r),o}function GU(n){const t=Er(n);if(t.length===0)return 0;const e=qu(n);let o=e?t.indexOf(e):-1;!e||o===-1||o===0?o=t.length-1:o-=1;const r=t[o];return l1(n,r),o}function D2(n,t){const e=Er(n);e.length>0&&t<e.length&&l1(n,e[t])}function ZU(n,t,e){const o=qu(n);if(!o)return!1;const r=nt(o);if(g(Mc,r,"no parent block"),!n.isBlockWritable(r))return!1;const i=ri(n);let s=Gu(n);if(!Zy(o)&&n.isBlockWritable(r)){const d=i1(n,o),h=n.getBlockText(r),{start:p,end:C}=i1(n,o),[v,B]=ln.transformOffset(d.oldText,h,[p,C]),D=t6(h,v,B-v);if(se(D).toLowerCase()!==t.toLowerCase())return!1;const x=Lh(h,v,B,e);n.setBlockText(r,x),UU(r),S2(n,r,t),e&&Gy(n,r,v,v+e.length)}const l=ri(n);s>=l?s=0:l>i&&(s+=1);const a=zU(n,s);return a&&l1(n,a),!0}function QU(n,t,e,o){if(!et(n,t)||!n.isBlockWritable(t))return 0;const r=n.getBlockText(t);g(Mc,r,"no block text");const i={count:0},s=w6(r,e,o,i);return se(r)===se(s)?0:(n.setBlockText(t,s),i.count)}function YU(n,t,e){if(g(Mc,$U(t),"not a highlight elem"),Zy(t))return;g(Mc,e>0,"invalid highlight length");const o=i1(n,t),r=nt(t);g(Mc,r,"no parent block"),Gy(n,r,o.start,o.start+e)}function JU(n,t){Er(n).forEach(o=>{YU(n,o,t)})}function KU(n,t,e){if(n.readonly)return 0;const o=i=>{let s=0;return me(i).forEach(a=>{Mt(n,a)?gn(n,a).forEach(h=>{s+=o(h)}):s+=QU(n,a,t,e)}),s},r=o(n.rootContainer);return e.length>0&&JU(n,e.length),r}function XU(n){const t=n.selection.range.end,e=n.getBlockById(t.blockId),o=t.isSimple()?t.offset:1,r=s1(e);for(let l=0;l<r.length;l++){const a=r[l],{end:d}=i1(n,a);if(d>=o)return a}const i=gg(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=s1(a);if(d.length>0)return d[0]}return null}function tz(n){const t=Er(n),e=XU(n);return e?t.indexOf(e):0}function S2(n,t,e){if(!!e&&et(n,t)){const o=n.getBlockText(t),r=Dg(o,e);r.length>0&&r.forEach(({start:i,end:s})=>{WU(n,t,i,s)})}}function Jy(n,t){if(c1(n),!t)return;gg(n,{simpleBlockOnly:!0}).forEach(o=>{S2(n,o,t)})}class ez{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(()=>{Yy(this.editor,t),S2(this.editor,t,this.components.findInput.value);const e=ri(this.editor);t.querySelectorAll(".editor-highlight").length===e&&D2(this.editor,0);const o=Gu(this.editor);this.updateSearchStatus(o,e)})});m(this,"handleDocInserted",()=>{const t=setTimeout(()=>{clearTimeout(t),c1(this.editor,{keepReplaceResult:!0}),Jy(this.editor,this.components.findInput.value);const e=ri(this.editor),o=Gu(this.editor);this.updateSearchStatus(o,e),D2(this.editor,o)})});m(this,"handleDocDeleted",t=>{const e=setTimeout(()=>{if(!s1(t).length){clearTimeout(e);return}Yy(this.editor,t);const r=ri(this.editor),i=Gu(this.editor);this.updateSearchStatus(i,r)})});m(this,"handleInput",t=>{if(t.isComposing||Vy(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||!qu(this.editor))return;const o=this.components.replaceInput.value;if(t===o)return;if(ZU(this.editor,t,o)){const i=Gu(this.editor),s=ri(this.editor);this.updateSearchStatus(i,s)}o&&this.findNext({keepSearchResult:!0})});m(this,"handleReplaceAll",()=>{const t=this.components.findInput.value;if(!t)return;const e=this.components.replaceInput.value;t!==e&&this.editor.undoManager.runInGroup(()=>{KU(this.editor,t,e)>0&&(this.oldText="",this.doSearchNow({keepReplaceResult:!0,gotoFirstSearchResult:!0}),this.clearFind({keepReplaceResult:!0}))})});m(this,"doSearch",Me.default(this.doSearchNow,300));this.editor=t;const e=k("div",["editor-find-dialog"],null),o=k("div",["editor-find-content"],e),r=k("div",["editor-find-dialog-row"],o),i=Ul(gv,["editor-find-dialog-button-close"],e),s=k("label",["editor-find-dialog-label"],r,L.t("find.findLabel"));s.htmlFor="";const l=k("div",["editor-find-dialog-input-container"],r),a=k("input",["editor-find-dialog-input"],l);a.type="text",a.placeholder=L.t("find.findPlaceholder");const d=k("div",["editor-find-dialog-status"],l),h=Ul(GL,["editor-find-dialog-icon-button"],d),p=k("div",["editor-find-dialog-curr"],d,"0/0"),C=Ul(ZL,["editor-find-dialog-icon-button"],d);let v;L.t("find.moreButton")?v=k("button",["editor-find-dialog-button"],r,L.t("find.moreButton")):v=Ul(pv,["editor-find-dialog-icon-button-border"],r);const B=k("div",["editor-find-dialog-row"],o),D=k("label",["editor-find-dialog-label"],B,L.t("find.replaceLabel"));D.htmlFor="";const x=k("div",["editor-find-dialog-input-container"],B),_=k("input",["editor-find-dialog-input"],x);_.type="text",_.placeholder=L.t("find.replacePlaceholder");const R=k("div",["editor-find-dialog-row"],o);k("div",["editor-find-dialog-space"],R);const H=k("button",["editor-find-dialog-button"],R,L.t("find.findButton")),z=k("button",["editor-find-dialog-button"],R,L.t("find.replaceButton")),Q=k("button",["editor-find-dialog-button"],R,L.t("find.replaceAllButton"));v.onclick=()=>{this.showReplace()},i.onclick=()=>{this.hide()},a.onkeydown=ft=>{if(ft.isComposing||Vy(this._compositionEndTime)){this.doSearch.cancel();return}N5(ft)?(this.doSearch.cancel(),this.doSearchNow({keepReplaceResult:!1,gotoFirstSearchResult:!0})):jm(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,C.onclick=()=>{this.gotoNext()},h.onclick=()=>{this.gotoPrev()},this.components={findInput:a,findPrev:h,findCurrent:p,findNext:C,replaceInput:_,findButton:H,replaceButton:z,replaceAllButton:Q,closeButton:i,showReplaceButton:v,rowReplace:B,rowActions:R,statusContainer:d},this.root=e;const tt=new PU(t);t.doc.registerCallback(tt),tt.addListener("onDocChanged",this.handleDocChanged),tt.addListener("onDocInserted",this.handleDocInserted),tt.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,Jy(this.editor,e);const o=ri(this.editor),r=tz(this.editor);t.gotoFirstSearchResult&&D2(this.editor,r),this.updateSearchStatus(r,o)}gotoNext(){const t=ri(this.editor),e=qU(this.editor);this.updateSearchStatus(e,t)}gotoPrev(){const t=ri(this.editor),e=GU(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){c1(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 gu(this.root,{disablePageScroll:!1}));const r=this.editor.options.componentsOptions.findDialog,i=(r==null?void 0:r.popoverTarget)||this.editor.rootContainer,s=()=>{var p,C,v,B;const l=r==null?void 0:r.getReferenceClientRect;if(l&&((C=(p=this.dialog)==null?void 0:p.tippyInstance)==null?void 0:C.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"),c1(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 nz={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"}},oz={find:{findLabel:"Search:",replaceLabel:"Replace:",findButton:"Search",replaceButton:"Replace",replaceAllButton:"Replace all",moreButton:"",findPlaceholder:"Search text in document",replacePlaceholder:"Replace with"}},rz={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"}};L.mergeLang({"zh-CN":nz,"en-US":oz,"ja-JP":rz});function Ky(n){return n.addCustom("find-dialog",()=>new ez(n)).show(),!0}const Xy={"CtrlOrCmd+F":Ky},jot="";function iz(n){Ky(n)}function L2(n,t){return t.map(e=>{var i,s;const o=Yt(n,e),r=(i=o.getBlockProperties)==null?void 0:i.call(o,n,e);return Ie(e)||Mt(n,e)?r!=null&&r.abstract?`[${r.abstract}]`:"":(s=r==null?void 0:r.abstract)!=null?s:""}).join(" ")}function a1(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 t8(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 M2(n,t,e){const o=L2(n,[t]),r=a1({editor:n,abstract:o});t8(n,t,r);const i=Yr();return e.localCreateComment(r,i),r}const sz=S("standard-block-actions");class lz{constructor(t,e){m(this,"executeCommand",(t,e,o)=>{const r=o.data;try{this.editorComments.showCommentList();const i=t.getBlockById(r);M2(t,i,this.provider)}catch(i){sz.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:L.t("comment.quickMenuCommand"),data:o,order:100,states:t.readonly?["disabled"]:[]}],executeCommand:this.executeCommand}}}class cz{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 R2="group-item-action",e8="last-comment-item",az="disabled",n8=500;function Xs(n){return n.id!==n.groupId}function o8(n,t=".comment-item-root"){return n.querySelectorAll(t).length}function uz(n){const t=n.closest(".comment-item-root");return t?t.id:null}function ii(n,t){n.setAttribute(R2,t)}function dz(n){return n.closest(`[${R2}]`)}function hz(n){var t;return(t=n.getAttribute(R2))!=null?t:""}function fz(n){return n.disabled||n.classList.contains(az)}function r8(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 i8(n){return Array.from(n.attributes).map(e=>e.name).filter(e=>e.startsWith("comment-")).map(e=>e.replace("comment-",""))}const s8=S("doc-comments");function l8(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=>{l8(n,l,e,o)})})}function mz(n){const t=[],e=new Set;n.blocks.root.forEach(r=>{l8(n,r,t,e)});const o=new Map;return t.forEach((r,i)=>o.set(r,i)),o}function gz(n){const t=new Map;n.forEach(r=>{if(Xs(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(!Xs(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 es(n,t){const e=n.doc.toJSON(),o=mz(e);return gz(t.getComments()).filter(s=>o.has(s.groupId)).sort((s,l)=>{const a=o.get(s.groupId),d=o.get(l.groupId);return g(s8,a!==void 0,`comment not exists in doc, ${s.groupId}`),g(s8,d!==void 0,`comment not exists in doc, ${l.groupId}`),a-d})}function O2(n){const{children:t,...e}=n,o=[e];return t.forEach(r=>{o.push(r)}),o}function pz(n,t){return es(n,t).map(O2).reduce((r,i)=>i.length+r,0)}function _2(n,t){const e=[],o=n.getBlockById(t.blockId);if(et(n,o)){const i=t.blockId,s=t.offset,l=n.getBlockById(i),a=n.getBlockText(l),d=Na(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 c8(n){const t=n.selection.range;if(!t.isSimple())return[];if(t.start.blockId!==t.end.blockId)return[];if(t.isCollapsed())return _2(n,t.start);const{start:e,end:o}=t,r=_2(n,e),i=_2(n,o);return Dm.default(r,i)}const Cz=S("active-comments");function a8(n,t){n.rootContainer.querySelectorAll(`span.text.comment[comment-${t}],[data-type=editor-block].comment[comment-${t}]`).forEach(o=>{rt(o,"active")})}function u8(n,t,e){const o=n.rootContainer.querySelector("span.text.comment.active,[data-type=editor-block].comment.active");if(!t)o&&i8(o).forEach(i=>a8(n,i));else{const r=t.toLocaleLowerCase();if(o){const s=i8(o);if(s.length===1&&s[0]===r)return;s.forEach(l=>a8(n,l))}const i=n.rootContainer.querySelectorAll(`span.text.comment[comment-${r}],[data-type=editor-block].comment[comment-${r}]`);if(i.length){i.forEach(l=>{W(l,"active")});const s=i[0];if(Is(s)){const l=st(s,0,"normal");n.selection.setSelection(l,void 0,{noScroll:e==="next"})}else if(c8(n).indexOf(t)===-1){const a=nt(s);g(Cz,a,"block not found");const d=Fs(a,s),h=st(a,d.start,"normal");n.selection.setSelection(h,void 0,{noScroll:e==="next"})}if(n.focus(),e==="next"){const l=s.getBoundingClientRect(),a=n.scrollContainer.clientHeight;l.top>a/2&&sh(s,{elementToScroll:n.scrollContainer,verticalOffset:-n.scrollContainer.clientHeight/2})}}}}const Uot="";S("comment-editor");const{t:Az}=L,F2="comment-editor-readonly",Zu="comment-editor-editing";class P2{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,Zu)||W(this.root,Zu)});m(this,"inactiveEditor",()=>{rt(this.root,Zu)});m(this,"handleInsertImg",async()=>{const{editor:t}=this.components,e=ct(t.rootContainer),o=await ql("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);Te.getImageObject(t,d).replaceImage(0,o)});m(this,"handleReadonlyChange",t=>{t.readonly?(rt(this.root,Zu),W(this.root,F2)):(W(this.root,Zu),rt(this.root,F2))});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",()=>Sg(this.getDoc()));m(this,"edit",()=>{const{editor:t}=this.components;t.readonly=!1,ip(t),this.activeEditor()});m(this,"clear",()=>{const t=Yr();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=k("div",["comment-editor",F2],null),this.components=this.createEditor()}createEditor(){const t=k("div",["comment-editor-root"],this.root),{commentsProvider:e,mainEditor:o}=this,r=e.createCommentEditor(t,new hp(this.doc));r.readonly=!0,r.addListener("readonlyChanged",this.handleReadonlyChange),r.addListener("focus",this.handleEditorFocus),r.addListener("blur",this.handleEditorBlur);const i=Ys(this.root,"comment-editor-img",Az("comment.image"),rM,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 bz{constructor(t){m(this,"handleBeforeKeyDown",(t,e)=>{if(rr(e,"Enter")){const{quickReply:o,updateLastCommentItem:r}=this.groupItem;return o.getReplyEditor().isEmpty()?(o.hideReplyEditor(),!0):(o.reply(),r(),!0)}return!1});this.groupItem=t}}class vz{constructor(t,e,o){m(this,"handleBeforeKeyDown",(t,e)=>{if(rr(e,"Enter")){const{quickReply:o}=this.groupItem,{comment:r,getCommentEditor:i}=this.commentItem,s=i();if(s.isEmpty())this.commentsProvider.localDeleteComment(r.id);else{const l=s.getDoc();this.commentsProvider.localUpdateComment(r,l),s.readonly()}return o.show(),!0}return!1});this.commentsProvider=t,this.groupItem=e,this.commentItem=o}}const yz=`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
493
|
+
`).map(h=>{const p={id:K(),type:"text"};if(RU(h)&&!r)return p.text=OU(h),p;const C=h?[uo(h,null)]:[];return p.text=C,p})},meta:{},comments:{}};i["text/plain"]=d}return i}}function FU(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 T2{constructor(t){t.dataConverter.addConverter(new LU),t.dataConverter.addConverter(new _U),t.dataConverter.addConverter(new MU)}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=FU(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=ot(i),a=bt(i);const d=nt(s);if(d&&Dt(d)==="code")return;if(o.blockId===r.blockId&&Ie(i))a+=1;else{t.clearSelectedContents();const{blockId:p}=t.selection.range.start,C=t.getBlockById(p);a=bt(C),s=ot(C),ue(t,C)||(a+=1),Gt(s)&&a===0&&(a+=1)}const h=ct(s);for(let p=0;p<e.length;p++){const C=e[p],v=await sg(t,"image",h,a+p,{file:C});v&&T4(t,v,"image",{id:"replace-image",name:"Replace image",data:{block:v,image:C}})}}}class PU extends ve.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=Ur(sr(this.editor,t),e);!et(this.editor,i)||!o.some(l=>l.insert||l.delete)||this.emit("onDocChanged",i)}onInsertBlock(t,e,o,r){Ur(sr(this.editor,t),e),this.emit("onDocInserted")}onDeleteBlock(t,e,o){const r=Ur(sr(this.editor,t),e);this.emit("onDocDeleted",r)}}function Vy(n){return Ze.isSafari&&!!n&&Date.now()-n<100}const Wy=S("highlight-data");class r1{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(Wy,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 r1(t))}}function NU(n,t,e,o,r){const s=r1.getData(n).add(t,e,o);return r.setAttribute("data-highlight-id",s.id),s}function i1(n,t){const e=t.getAttribute("data-highlight-id");return g(Wy,e,"invalid highlight elem, no id"),r1.getData(n).get(e)}const Lc=S("highligh-dom");function $U(n){return xt(n,"editor-highlight")}function Er(n){const t=n.rootContainer.querySelectorAll(".editor-highlight");return Array.from(t)}function HU(n,t){g(Lc,t,"invalid block");const e=t.querySelectorAll(".editor-highlight");return Array.from(e)}function jU(n){const t=n.rootContainer.querySelectorAll(".editor-replace-result-highlight");return Array.from(t)}function s1(n){const t=n.querySelectorAll(".editor-highlight");return Array.from(t)}function UU(n){s1(n).forEach(t=>{t.remove()})}function ri(n){return Er(n).length}function zU(n,t){g(Lc,t>=0,`invalid highlight index: ${t}`);const e=Er(n);return e.length===0?null:(g(Lc,t<e.length,`invalid highlight index: ${t}/${e.length}`),e[t])}function VU(n,t,{left:e,top:o,width:r,height:i},s){const l=["editor-highlight-child"];s&&l.push("editor-highlight-readonly");const a=k("div",l,n);a.style.top=`${o}px`,a.style.left=`${e}px`,a.style.width=`${r}px`,a.style.height=`${i}px`}function qy(n,t,e,o,r){g(Lc,o>0,`invalid end: ${o}`);const i=ee(t),s=t.getBoundingClientRect(),l=Vr(n,t,ke(n,t,e,o)),d=k("div",[r==="find"?"editor-highlight":"editor-replace-result-highlight"],i);l.forEach(h=>{VU(d,t,{left:h.left-s.left,width:h.width,top:h.top-s.top,height:h.height})}),NU(n,t,e,o,d)}function WU(n,t,e,o){return qy(n,t,e,o,"find")}function Gy(n,t,e,o){return qy(n,t,e,o,"replace")}function l1(n,t){Er(n).forEach(s=>{xt(s,"active")&&rt(s,"active")}),W(t,"active"),g(Lc,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),sh(o,{elementToScroll:n.scrollContainer})}function qu(n){const t=n.rootContainer.querySelector(".editor-highlight.active");return t||null}function Zy(n){return g(Lc,n,"no highlight elem"),xt(n,"editor-highlight-readonly")}const Mc=S("highligh-text");function Qy(n){jU(n).forEach(e=>{e.remove()})}function c1(n,t){Er(n).forEach(o=>{o.remove()}),t!=null&&t.keepReplaceResult||Qy(n)}function Yy(n,t,e){HU(n,t).forEach(r=>{r.remove()}),e!=null&&e.keepReplaceResult||Qy(n)}function Gu(n){const t=qu(n);if(!t)return-1;const o=Er(n).indexOf(t);return g(Mc,o!==-1,`invalid highlight index: ${o}`),o}function qU(n){const t=Er(n);if(t.length===0)return 0;const e=qu(n);let o=e?t.indexOf(e):-1;!e||o===-1||o===t.length-1?o=0:o+=1;const r=t[o];return l1(n,r),o}function GU(n){const t=Er(n);if(t.length===0)return 0;const e=qu(n);let o=e?t.indexOf(e):-1;!e||o===-1||o===0?o=t.length-1:o-=1;const r=t[o];return l1(n,r),o}function D2(n,t){const e=Er(n);e.length>0&&t<e.length&&l1(n,e[t])}function ZU(n,t,e){const o=qu(n);if(!o)return!1;const r=nt(o);if(g(Mc,r,"no parent block"),!n.isBlockWritable(r))return!1;const i=ri(n);let s=Gu(n);if(!Zy(o)&&n.isBlockWritable(r)){const d=i1(n,o),h=n.getBlockText(r),{start:p,end:C}=i1(n,o),[v,B]=ln.transformOffset(d.oldText,h,[p,C]),D=t6(h,v,B-v);if(se(D).toLowerCase()!==t.toLowerCase())return!1;const x=Lh(h,v,B,e);n.setBlockText(r,x),UU(r),S2(n,r,t),e&&Gy(n,r,v,v+e.length)}const l=ri(n);s>=l?s=0:l>i&&(s+=1);const a=zU(n,s);return a&&l1(n,a),!0}function QU(n,t,e,o){if(!et(n,t)||!n.isBlockWritable(t))return 0;const r=n.getBlockText(t);g(Mc,r,"no block text");const i={count:0},s=w6(r,e,o,i);return se(r)===se(s)?0:(n.setBlockText(t,s),i.count)}function YU(n,t,e){if(g(Mc,$U(t),"not a highlight elem"),Zy(t))return;g(Mc,e>0,"invalid highlight length");const o=i1(n,t),r=nt(t);g(Mc,r,"no parent block"),Gy(n,r,o.start,o.start+e)}function JU(n,t){Er(n).forEach(o=>{YU(n,o,t)})}function KU(n,t,e){if(n.readonly)return 0;const o=i=>{let s=0;return me(i).forEach(a=>{Mt(n,a)?gn(n,a).forEach(h=>{s+=o(h)}):s+=QU(n,a,t,e)}),s},r=o(n.rootContainer);return e.length>0&&JU(n,e.length),r}function XU(n){const t=n.selection.range.end,e=n.getBlockById(t.blockId),o=t.isSimple()?t.offset:1,r=s1(e);for(let l=0;l<r.length;l++){const a=r[l],{end:d}=i1(n,a);if(d>=o)return a}const i=gg(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=s1(a);if(d.length>0)return d[0]}return null}function tz(n){const t=Er(n),e=XU(n);return e?t.indexOf(e):0}function S2(n,t,e){if(!!e&&et(n,t)){const o=n.getBlockText(t),r=Dg(o,e);r.length>0&&r.forEach(({start:i,end:s})=>{WU(n,t,i,s)})}}function Jy(n,t){if(c1(n),!t)return;gg(n,{simpleBlockOnly:!0}).forEach(o=>{S2(n,o,t)})}class ez{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(()=>{Yy(this.editor,t),S2(this.editor,t,this.components.findInput.value);const e=ri(this.editor);t.querySelectorAll(".editor-highlight").length===e&&D2(this.editor,0);const o=Gu(this.editor);this.updateSearchStatus(o,e)})});m(this,"handleDocInserted",()=>{const t=setTimeout(()=>{clearTimeout(t),c1(this.editor,{keepReplaceResult:!0}),Jy(this.editor,this.components.findInput.value);const e=ri(this.editor),o=Gu(this.editor);this.updateSearchStatus(o,e),D2(this.editor,o)})});m(this,"handleDocDeleted",t=>{const e=setTimeout(()=>{if(!s1(t).length){clearTimeout(e);return}Yy(this.editor,t);const r=ri(this.editor),i=Gu(this.editor);this.updateSearchStatus(i,r)})});m(this,"handleInput",t=>{if(t.isComposing||Vy(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||!qu(this.editor))return;const o=this.components.replaceInput.value;if(t===o)return;if(ZU(this.editor,t,o)){const i=Gu(this.editor),s=ri(this.editor);this.updateSearchStatus(i,s)}o&&this.findNext({keepSearchResult:!0})});m(this,"handleReplaceAll",()=>{const t=this.components.findInput.value;if(!t)return;const e=this.components.replaceInput.value;t!==e&&this.editor.undoManager.runInGroup(()=>{KU(this.editor,t,e)>0&&(this.oldText="",this.doSearchNow({keepReplaceResult:!0,gotoFirstSearchResult:!0}),this.clearFind({keepReplaceResult:!0}))})});m(this,"doSearch",Me.default(this.doSearchNow,300));this.editor=t;const e=k("div",["editor-find-dialog"],null),o=k("div",["editor-find-content"],e),r=k("div",["editor-find-dialog-row"],o),i=Ul(gv,["editor-find-dialog-button-close"],e),s=k("label",["editor-find-dialog-label"],r,L.t("find.findLabel"));s.htmlFor="";const l=k("div",["editor-find-dialog-input-container"],r),a=k("input",["editor-find-dialog-input"],l);a.type="text",a.placeholder=L.t("find.findPlaceholder");const d=k("div",["editor-find-dialog-status"],l),h=Ul(GL,["editor-find-dialog-icon-button"],d),p=k("div",["editor-find-dialog-curr"],d,"0/0"),C=Ul(ZL,["editor-find-dialog-icon-button"],d);let v;L.t("find.moreButton")?v=k("button",["editor-find-dialog-button"],r,L.t("find.moreButton")):v=Ul(pv,["editor-find-dialog-icon-button-border"],r);const B=k("div",["editor-find-dialog-row"],o),D=k("label",["editor-find-dialog-label"],B,L.t("find.replaceLabel"));D.htmlFor="";const x=k("div",["editor-find-dialog-input-container"],B),_=k("input",["editor-find-dialog-input"],x);_.type="text",_.placeholder=L.t("find.replacePlaceholder");const R=k("div",["editor-find-dialog-row"],o);k("div",["editor-find-dialog-space"],R);const H=k("button",["editor-find-dialog-button"],R,L.t("find.findButton")),z=k("button",["editor-find-dialog-button"],R,L.t("find.replaceButton")),Q=k("button",["editor-find-dialog-button"],R,L.t("find.replaceAllButton"));v.onclick=()=>{this.showReplace()},i.onclick=()=>{this.hide()},a.onkeydown=ft=>{if(ft.isComposing||Vy(this._compositionEndTime)){this.doSearch.cancel();return}N5(ft)?(this.doSearch.cancel(),this.doSearchNow({keepReplaceResult:!1,gotoFirstSearchResult:!0})):jm(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,C.onclick=()=>{this.gotoNext()},h.onclick=()=>{this.gotoPrev()},this.components={findInput:a,findPrev:h,findCurrent:p,findNext:C,replaceInput:_,findButton:H,replaceButton:z,replaceAllButton:Q,closeButton:i,showReplaceButton:v,rowReplace:B,rowActions:R,statusContainer:d},this.root=e;const tt=new PU(t);t.doc.registerCallback(tt),tt.addListener("onDocChanged",this.handleDocChanged),tt.addListener("onDocInserted",this.handleDocInserted),tt.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,Jy(this.editor,e);const o=ri(this.editor),r=tz(this.editor);t.gotoFirstSearchResult&&D2(this.editor,r),this.updateSearchStatus(r,o)}gotoNext(){const t=ri(this.editor),e=qU(this.editor);this.updateSearchStatus(e,t)}gotoPrev(){const t=ri(this.editor),e=GU(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){c1(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 gu(this.root,{disablePageScroll:!1}));const r=this.editor.options.componentsOptions.findDialog,i=(r==null?void 0:r.popoverTarget)||this.editor.rootContainer,s=()=>{var p,C,v,B;const l=r==null?void 0:r.getReferenceClientRect;if(l&&((C=(p=this.dialog)==null?void 0:p.tippyInstance)==null?void 0:C.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"),c1(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 nz={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"}},oz={find:{findLabel:"Search:",replaceLabel:"Replace:",findButton:"Search",replaceButton:"Replace",replaceAllButton:"Replace all",moreButton:"",findPlaceholder:"Search text in document",replacePlaceholder:"Replace with"}},rz={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"}};L.mergeLang({"zh-CN":nz,"en-US":oz,"ja-JP":rz});function Ky(n){return n.addCustom("find-dialog",()=>new ez(n)).show(),!0}const Xy={"CtrlOrCmd+F":Ky},jot="";function iz(n){Ky(n)}function L2(n,t){return t.map(e=>{var i,s;const o=Yt(n,e),r=(i=o.getBlockProperties)==null?void 0:i.call(o,n,e);return Ie(e)||Mt(n,e)?r!=null&&r.abstract?`[${r.abstract}]`:"":(s=r==null?void 0:r.abstract)!=null?s:""}).join(" ")}function a1(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 t8(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 M2(n,t,e){const o=L2(n,[t]),r=a1({editor:n,abstract:o});t8(n,t,r);const i=Yr();return e.localCreateComment(r,i),r}const sz=S("standard-block-actions");class lz{constructor(t,e){m(this,"executeCommand",(t,e,o)=>{const r=o.data;try{this.editorComments.showCommentList();const i=t.getBlockById(r);M2(t,i,this.provider)}catch(i){sz.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:L.t("comment.quickMenuCommand"),data:o,order:100,states:t.readonly?["disabled"]:[]}],executeCommand:this.executeCommand}}}class cz{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 R2="group-item-action",e8="last-comment-item",az="disabled",n8=500;function Xs(n){return n.id!==n.groupId}function o8(n,t=".comment-item-root"){return n.querySelectorAll(t).length}function uz(n){const t=n.closest(".comment-item-root");return t?t.id:null}function ii(n,t){n.setAttribute(R2,t)}function dz(n){return n.closest(`[${R2}]`)}function hz(n){var t;return(t=n.getAttribute(R2))!=null?t:""}function fz(n){return n.disabled||n.classList.contains(az)}function r8(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 i8(n){return Array.from(n.attributes).map(e=>e.name).filter(e=>e.startsWith("comment-")).map(e=>e.replace("comment-",""))}const s8=S("doc-comments");function l8(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=>{l8(n,l,e,o)})})}function mz(n){const t=[],e=new Set;n.blocks.root.forEach(r=>{l8(n,r,t,e)});const o=new Map;return t.forEach((r,i)=>o.set(r,i)),o}function gz(n){const t=new Map;n.forEach(r=>{if(Xs(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(!Xs(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 es(n,t){const e=n.doc.toJSON(),o=mz(e);return gz(t.getComments()).filter(s=>o.has(s.groupId)).sort((s,l)=>{const a=o.get(s.groupId),d=o.get(l.groupId);return g(s8,a!==void 0,`comment not exists in doc, ${s.groupId}`),g(s8,d!==void 0,`comment not exists in doc, ${l.groupId}`),a-d})}function O2(n){const{children:t,...e}=n,o=[e];return t.forEach(r=>{o.push(r)}),o}function pz(n,t){return es(n,t).map(O2).reduce((r,i)=>i.length+r,0)}function _2(n,t){const e=[],o=n.getBlockById(t.blockId);if(et(n,o)){const i=t.blockId,s=t.offset,l=n.getBlockById(i),a=n.getBlockText(l),d=Na(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 c8(n){const t=n.selection.range;if(!t.isSimple())return[];if(t.start.blockId!==t.end.blockId)return[];if(t.isCollapsed())return _2(n,t.start);const{start:e,end:o}=t,r=_2(n,e),i=_2(n,o);return Dm.default(r,i)}const Cz=S("active-comments");function a8(n,t){n.rootContainer.querySelectorAll(`span.text.comment[comment-${t}],[data-type=editor-block].comment[comment-${t}]`).forEach(o=>{rt(o,"active")})}function u8(n,t,e){const o=n.rootContainer.querySelector("span.text.comment.active,[data-type=editor-block].comment.active");if(!t)o&&i8(o).forEach(i=>a8(n,i));else{const r=t.toLocaleLowerCase();if(o){const s=i8(o);if(s.length===1&&s[0]===r)return;s.forEach(l=>a8(n,l))}const i=n.rootContainer.querySelectorAll(`span.text.comment[comment-${r}],[data-type=editor-block].comment[comment-${r}]`);if(i.length){i.forEach(l=>{W(l,"active")});const s=i[0];if(Is(s)){const l=st(s,0,"normal");n.selection.setSelection(l,void 0,{noScroll:e==="next"})}else if(c8(n).indexOf(t)===-1){const a=nt(s);g(Cz,a,"block not found");const d=Fs(a,s),h=st(a,d.start,"normal");n.selection.setSelection(h,void 0,{noScroll:e==="next"})}if(n.focus(),e==="next"){const l=s.getBoundingClientRect(),a=n.scrollContainer.clientHeight;l.top>a/2&&sh(s,{elementToScroll:n.scrollContainer,verticalOffset:-n.scrollContainer.clientHeight/2})}}}}const Uot="";S("comment-editor");const{t:Az}=L,F2="comment-editor-readonly",Zu="comment-editor-editing";class P2{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,Zu)||W(this.root,Zu)});m(this,"inactiveEditor",()=>{rt(this.root,Zu)});m(this,"handleInsertImg",async()=>{const{editor:t}=this.components,e=ct(t.rootContainer),o=await ql("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);Te.getImageObject(t,d).replaceImage(0,o)});m(this,"handleReadonlyChange",t=>{t.readonly?(rt(this.root,Zu),W(this.root,F2)):(W(this.root,Zu),rt(this.root,F2))});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",()=>Sg(this.getDoc()));m(this,"edit",()=>{const{editor:t}=this.components;t.readonly=!1,ip(t),this.activeEditor()});m(this,"clear",()=>{const t=Yr();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=k("div",["comment-editor",F2],null),this.components=this.createEditor()}createEditor(){const t=k("div",["comment-editor-root"],this.root),{commentsProvider:e,mainEditor:o}=this,r=e.createCommentEditor(t,new hp(this.doc));r.readonly=!0,r.addListener("readonlyChanged",this.handleReadonlyChange),r.addListener("focus",this.handleEditorFocus),r.addListener("blur",this.handleEditorBlur);const i=Ys(this.root,"comment-editor-img",Az("comment.image"),rM,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 bz{constructor(t){m(this,"handleBeforeKeyDown",(t,e)=>{if(rr(e,"Enter")){const{quickReply:o,updateLastCommentItem:r}=this.groupItem;return o.getReplyEditor().isEmpty()?(o.hideReplyEditor(),!0):(o.reply(),r(),!0)}return!1});this.groupItem=t}}class vz{constructor(t,e,o){m(this,"handleBeforeKeyDown",(t,e)=>{if(rr(e,"Enter")){const{quickReply:o}=this.groupItem,{comment:r,getCommentEditor:i}=this.commentItem,s=i();if(s.isEmpty())this.commentsProvider.localDeleteComment(r.id);else{const l=s.getDoc();this.commentsProvider.localUpdateComment(r,l),s.readonly()}return o.show(),!0}return!1});this.commentsProvider=t,this.groupItem=e,this.commentItem=o}}const yz=`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
494
494
|
<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>
|
|
495
495
|
</svg>`,kz=`<svg
|
|
496
496
|
fill="currentColor"
|
|
@@ -500,7 +500,7 @@ width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
|
|
500
500
|
<path d="M2.00218 11.0005L8.00341 4.99923L14.0046 11.0005" stroke="currentColor" fill="transparent" stroke-width="1.5" stroke-linejoin="bevel"/>
|
|
501
501
|
</svg>`,xz=`<svg width="17" height="16" viewBox="0 0 17 16" xmlns="http://www.w3.org/2000/svg">
|
|
502
502
|
<path d="M14.0029 4.99933L8.00172 11.0006L2.00049 4.99933" stroke="currentColor" fill="transparent" stroke-width="1.5" stroke-linejoin="bevel"/>
|
|
503
|
-
</svg>`,qot="",u1="reply-editor-editing",{t:N2}=L;class Iz{constructor(t,e,o,r){m(this,"root");m(this,"components");m(this,"handleFocus",()=>{const{replyEditor:t,okButton:e}=this.components;t.isEmpty()&&(e.disabled=!0)});m(this,"handleDocChange",()=>{const{replyEditor:t,okButton:e}=this.components,o=t.getDoc();Sg(o)?e.disabled=!0:e.disabled=!1});m(this,"getReplyEditor",()=>this.components.replyEditor);m(this,"showReplyEditor",()=>{xt(this.root,u1)||(W(this.root,u1),this.components.replyEditor.edit())});m(this,"hideReplyEditor",()=>{!xt(this.root,u1)||rt(this.root,u1)});m(this,"reply",()=>{const{mainEditor:t,comment:e,components:{replyEditor:o},commentsProvider:r}=this,i=o.getDoc(),s=a1({editor:t,commentGroupId:e.groupId});r.localCreateComment(s,i),this.hideReplyEditor(),o.clear()});m(this,"cancel",()=>{const{replyEditor:t}=this.components;this.hideReplyEditor(),t.clear()});m(this,"hide",()=>{xt(this.root,"hidden")||W(this.root,"hidden")});m(this,"show",()=>{rt(this.root,"hidden")});this.mainEditor=t,this.commentsProvider=e,this.comment=o,this.groupItem=r,this.root=k("div",["comment-quick-reply"],null),this.components=this.createQuickReply()}createQuickReply(){const{commentsProvider:t}=this,e=Ys(this.root,Jt.QuickReply,N2("comment.placeholder"));ii(e,Jt.QuickReply),e.classList.add("quick-reply-button");const o=k("div",["quick-reply-editor"],this.root),r=Yr(),i=new P2(this.mainEditor,t,r);i.editor.addListener("docChanged",this.handleDocChange),i.editor.addListener("focus",this.handleFocus),i.editor.input.addHandler(new bz(this.groupItem)),o.append(i.root);const s=k("div",["reply-editor-actions"],o),l=mo(Jt.QuickReplyCancel,N2("common.cancel"));ii(l,Jt.QuickReplyCancel);const a=mo(Jt.QuickReplyOk,N2("comment.send"),void 0,["primary","disabled"]);return ii(a,Jt.QuickReplyOk),s.append(l,a),this.hideReplyEditor(),{replyTextButton:e,replyEditor:i,replyEditorContainer:o,okButton:a}}}const si=S("comment-group-item");class Tz extends ve.TypedEmitter{constructor(e,o,r,i){super();m(this,"root");m(this,"header");m(this,"mainItem");m(this,"childrenList");m(this,"resizeObserver");m(this,"quickReply");m(this,"createRoot",()=>k("div",["comment-group-item-root"],null));m(this,"createChildrenList",()=>{const e=k("div",["comment-children-list-container"],this.root);return new Bz({editor:this.editor,commentsProvider:this.commentsProvider,comments:this.comment.children,parent:e,groupList:this.groupList,groupItem:this})});m(this,"updateLastCommentItem",()=>{const e=Array.from(this.root.querySelectorAll(":scope .comment-item-root"));g(si,e.length!==0,"current group item not exist comment-item"),e.forEach(r=>{rt(r,e8)});const o=e[e.length-1];W(o,e8)});m(this,"updateSwitchButton",()=>{const e=this.root.querySelector(':scope .editor-text-button[group-item-action="switch-up"]'),o=this.root.querySelector(':scope .editor-text-button[group-item-action="switch-down"]');g(si,e,"switchUpButton not exist"),g(si,o,"switchDownButton not exist"),rt(o,"disabled"),rt(e,"disabled"),this.root.previousElementSibling===null&&W(e,"disabled"),this.root.nextElementSibling===null&&W(o,"disabled")});m(this,"handleReadonlyChanged",e=>{e.readonly?W(this.root,"readonly"):rt(this.root,"readonly")});m(this,"handleResize",()=>{this.emit("resize")});this.editor=e,this.commentsProvider=o,this.comment=r,this.groupList=i,this.root=this.createRoot(),this.header=this.createHeader(),this.mainItem=this.createItem(),this.childrenList=this.createChildrenList(),this.quickReply=this.createQuickReply(),this.editor.on("readonlyChanged",this.handleReadonlyChanged),this.resizeObserver=new vs(this.handleResize),this.resizeObserver.observe(this.root),this.updateLastCommentItem()}get commentCount(){return o8(this.root)}createQuickReply(){const{editor:e,commentsProvider:o,comment:r}=this,i=new Iz(e,o,r,this);return this.root.append(i.root),i}createHeader(){const{comment:e}=this,o=k("div",["comment-item-head"],this.root),r=k("span",["item-head-quote"],o);r.innerText=e.abstract;const i=k("span",["item-head-switch"],o),s=Ys(i,Jt.SwitchUp,"up",Ez),l=Ys(i,Jt.SwitchDown,"down",xz);return ii(s,Jt.SwitchUp),ii(l,Jt.SwitchDown),o}createItem(){const e=k("div",["comment-item-container"],this.root),{editor:o,commentsProvider:r,comment:i,groupList:s}=this,l=new f8({mainEditor:o,commentsProvider:r,comment:i,groupList:s,groupItem:this});return e.appendChild(l.root),l}findCommentItem(e){return e?e===this.mainItem.comment.id?this.mainItem:this.childrenList.items.find(o=>o.comment.id===e):null}handleCreateComment(e){return g(si,Xs(e),"invalid comment, not a child comment"),g(si,e.groupId===this.comment.id,"invalid comment, not a child comment"),this.childrenList.createItem(e)}handleUpdateChildComment(e){g(si,e.groupId===this.mainItem.comment.id,"invalid child comment");const o=this.childrenList.findItem(e.id);if(!o){si.error(`can't find child comment item: ${e.id}`);return}o.reloadDoc()}handleUpdateMainComment(e){g(si,e.id===this.mainItem.comment.id,"invalid comment"),this.mainItem.reloadDoc()}deleteMainComment(e){g(si,e===this.mainItem.comment.id,"invalid comment"),this.mainItem.destroy()}edit(){this.mainItem.edit()}destroy(){this.mainItem.destroy(),this.childrenList.destroy(),this.root.remove(),this.resizeObserver.disconnect(),this.removeAllListeners(),this.editor.removeListener("readonlyChanged",this.handleReadonlyChanged)}}const Dz=S("arrange=items"),g8=20;function p8(n,t){const e=n.rootContainer.querySelector(`[comment-${t.toLocaleLowerCase()}=${t}`);if(!e)return-1;const o=n.scrollContainer.getBoundingClientRect(),r=n.scrollContainer.scrollTop;return e.getBoundingClientRect().top-o.top+r}function C8(n,t){return Number.parseInt(t.root.style.top,10)}function A8(n,t,e,o){let r=0;e&&(r=t.indexOf(e),r===-1&&(r=0));for(let i=r;i<t.length;i++){const s=t[i],l=s.comment,a=p8(n,l.groupId);if(s.root.setAttribute("data-target-top",a.toString()),i===r){if(o!==void 0){const p=t[0];p.root.style.top=`${o}px`}else s.root.style.top=`${a}px`;continue}const d=t[i-1],h=C8(n,d)+d.root.getBoundingClientRect().height;h>a?s.root.style.top=`${h+g8}px`:s.root.style.top=`${a}px`}for(let i=r-1;i>=0;i--){const s=t[i],l=s.comment,a=p8(n,l.groupId);s.root.setAttribute("data-target-top",a.toString());const d=s.root.getBoundingClientRect(),h=a+d.height,p=t[i+1];g(Dz,p,"no next item");const C=C8(n,p);C<h?s.root.style.top=`${C-d.height-g8}px`:s.root.style.top=`${a}px`}setTimeout(()=>{n.scrollContainer.dispatchEvent(new Event("scroll"))},350)}const d1=S("comment-group-item-handler");class Sz{constructor(t,e){m(this,"handleSwitchUp",t=>{const e=Math.max(0,t-1);this.groupList.setActiveItem(e,"prev"),this.groupList.updateItemsLayout()});m(this,"handleSwitchDown",t=>{const e=Math.min(t+1,this.groupList.items.length);this.groupList.setActiveItem(e,"next"),this.groupList.updateItemsLayout()});m(this,"handleQuickReply",t=>{const{quickReply:e}=t;e.showReplyEditor()});m(this,"handleQuickReplyOk",t=>{const{quickReply:e}=t;e.reply(),t.updateLastCommentItem()});m(this,"handleQuickReplyCancel",t=>{const{quickReply:e}=t;e.cancel()});m(this,"handleCommentItemReply",(t,e)=>{const o=t.findCommentItem(e);g(d1,o,`the commentItem: ${e} not exist `);const{quickReply:r}=t;r.show(),r.showReplyEditor();const{comment:i}=o,s=r.getReplyEditor(),l=s.editor.getFocusedBlock(),a={type:"mention",id:K(),box:!0,created:Date.now(),text:i.displayName,iconUrl:i.avatarUrl,mentionId:i.userId};s.editor.insertBoxToBlock(l,0,a)});m(this,"handleCommentItemMore",t=>{const{quickReply:e}=t;e.hideReplyEditor(),e.getReplyEditor().clear()});m(this,"handleCommentItemOk",(t,e)=>{const o=t.findCommentItem(e);g(d1,o,`the commentItem: ${e} not exist `);const{quickReply:r}=t,{comment:i,getCommentEditor:s}=o,l=s(),a=l.getDoc();this.commentsProvider.localUpdateComment(i,a),l.readonly(),r.show()});m(this,"handleCommentItemCancel",(t,e)=>{var a,d;const o=t.findCommentItem(e);g(d1,o,`the commentItem: ${e} not exist `);const r=this.commentsProvider.getComment(o.comment.id);let i=!1;if((a=r.blocks)!=null&&a.length||(i=!0),((d=r.blocks)==null?void 0:d.length)===1){const h=r.blocks[0];i=!!h.text&&rn(h.text)===0}if(i){this.commentsProvider.localDeleteComment(o.comment.id);return}const{quickReply:s}=t,l=o.getCommentEditor();l.setDoc(o.doc),l.readonly(),s.show()});m(this,"handleCommentItemEdit",t=>{const e=this.groupList.findItem(t.comment.groupId);if(!e)return;const{quickReply:o}=e;t.getCommentEditor().edit(),o.hide()});m(this,"handleCommentItemDelete",t=>{const e=this.groupList.findItem(t.comment.groupId);if(!e)return;const{quickReply:o}=e,{comment:r}=t;this.commentsProvider.localDeleteComment(r.id),o.show()});m(this,"execute",(t,e,o,r)=>{const i=dz(t);if(!i||fz(i))return;const s=hz(i);switch(s){case Jt.SwitchUp:this.handleSwitchUp(r);break;case Jt.SwitchDown:this.handleSwitchDown(r);break;case Jt.CommentItemReply:this.handleCommentItemReply(e,o);break;case Jt.CommentItemMore:this.handleCommentItemMore(e);break;case Jt.CommentItemOk:this.handleCommentItemOk(e,o);break;case Jt.CommentItemCancel:this.handleCommentItemCancel(e,o);break;case Jt.CommentItemDelete:break;case Jt.CommentItemEdit:break;case Jt.QuickReply:this.handleQuickReply(e);break;case Jt.QuickReplyOk:this.handleQuickReplyOk(e);break;case Jt.QuickReplyCancel:this.handleQuickReplyCancel(e);break;default:const l=s;d1.debug(`not implement handler for ${l}`)}});this.groupList=t,this.commentsProvider=e}destroy(){}}const h1=S("comment-group-list");class Lz extends Qu{constructor(e,o,r){super(e,o,r,es(e,o),{});m(this,"groupItemHandlers");m(this,"findGroupItem",e=>this.items.find(o=>o.comment.groupId===e));m(this,"handleContainerClick",e=>{if(!e.target||!(e.target instanceof Element))return;const o=e.target.closest(".comment-group-item-root");if(!o)return;const r=uz(e.target),i=this.items.findIndex(s=>s.root===o);if(i!==-1){this.setActiveItem(i);const{groupItemHandlers:s}=this;s.execute(e.target,this.items[i],r,i)}});m(this,"handleSelectionChanged",()=>{setTimeout(()=>{var o;const e=c8(this.editor);if(e.length>0){if(((o=this.activeItem)==null?void 0:o.comment.id)&&e.includes(this.activeItem.comment.id))return;const r=e[0],i=this.items.findIndex(s=>s.comment.groupId===r);this.setActiveItem(i),this.emit("selectionOnComment")}else this.setActiveItem(-1)})});m(this,"handleEditorResize",()=>{this.updateItemsLayout()});m(this,"handleDocChanged",()=>{this.updateComments()});m(this,"handleItemResize",()=>{this.updateItemsLayout()});m(this,"handleScroll",e=>{if(e.deltaY>=0||this.editor.scrollContainer.scrollTop!==0)return;const o=document.elementFromPoint(e.clientX,e.clientY);if(!o||!(o instanceof HTMLElement)||!this.editor.scrollContainer.contains(o))return;const r=this.container.querySelector(".comment-group-item-root");if(!r)return;const i=Number.parseFloat(r.style.top),s=Number.parseFloat(r.getAttribute("data-target-top")||"0");!Number.isNaN(i)&&!Number.isNaN(s)&&i<s&&A8(this.editor,this.items,null,Math.min(i+(0-e.deltaY)*3,s))});m(this,"updateGroupItemSwitch",()=>{const e=this.activeItem;g(h1,e,"invalid activeItem"),e.updateSwitchButton()});m(this,"updateComments",Me.default(()=>{const e=es(this.editor,this.commentsProvider);let o=!1;for(let r=0;r<e.length;r++){const i=e[r];if(!this.findGroupItem(i.groupId)){this.handleCreateComment(i,!1),o=!0;continue}}for(let r=this.items.length-1;r>=0;r--){const i=this.items[r];e.findIndex(s=>s.groupId===i.comment.groupId)===-1&&(this.deleteItem(i.comment.id),o=!0)}o&&(this.updateItemsLayout(),this.emit("commentCountChanged"))},100));this.updateItemsLayout(),this.bindEvents(),this.editor.addListener("selectionChanged",this.handleSelectionChanged),this.editor.addListener("resize",this.handleEditorResize),this.editor.addListener("docChanged",this.handleDocChanged),this.editor.scrollContainer.addEventListener("wheel",this.handleScroll,{passive:!1}),this.items.forEach(i=>i.addListener("resize",this.handleItemResize)),this.groupItemHandlers=new Sz(this,o)}destroy(){this.editor.removeListener("selectionChanged",this.handleSelectionChanged),this.editor.removeListener("resize",this.handleEditorResize),this.editor.removeListener("docChanged",this.handleDocChanged),this.editor.scrollContainer.removeEventListener("wheel",this.handleScroll),super.destroy(),this.unbindEvents(),this.removeAllListeners()}updateItemsLayout(){A8(this.editor,this.items,this.activeItem)}bindEvents(){this.container.addEventListener("click",this.handleContainerClick)}unbindEvents(){this.container.removeEventListener("click",this.handleContainerClick)}createItem(e,o){const r=new Tz(this.editor,this.commentsProvider,e,this);return o==="insert"&&(W(r.root,"no-animation"),r.root.style.opacity="0",setTimeout(()=>{rt(r.root,"no-animation"),r.root.style.opacity="1"},150)),r}findInsertPos(e){const r=es(this.editor,this.commentsProvider).findIndex(i=>i.id===e.id);return r===-1||r>this.items.length?-1:r}insertItem(e,o){const r=super.insertItem(e);return r?(o!=null&&o.active&&this.setActiveItem(this.items.indexOf(r)),this.updateItemsLayout(),r.addListener("resize",this.handleItemResize),r):null}setActiveItem(e,o){if(g(h1,e>=-1&&e<this.items.length,`invalid index: ${e}`),e===this.activeIndex)return;const r=this.container.querySelector(".comment-group-item-root.active");if(r&&rt(r,"active"),e!==-1){const i=this.items[e];W(i.root,"active"),this.updateItemsLayout(),this.updateGroupItemSwitch()}this.emit("activeItemChanged",e,o)}get activeIndex(){const e=this.container.querySelector(".comment-group-item-root.active");return e?this.items.findIndex(o=>o.root===e):-1}get activeItem(){const e=this.activeIndex;return e===-1?null:this.items[e]}handleCreateComment(e,o){if(Xs(e)){const l=this.findGroupItem(e.groupId);l&&l.childrenList.insertItem(e)}const r=this.findItem(e.id);g(h1,!r,"comment group item has already exists");const i={children:[],...e};g(h1,i.children,"not a comment group");const s=this.insertItem(i,{active:o});!s||o&&setTimeout(()=>{const l=this.items.indexOf(s);this.setActiveItem(l),s.edit(),s.quickReply.hide()})}handleDeleteComment(e){for(let o=0;o<this.items.length;o++){const r=this.items[o];if(r.comment.id===e){r.childrenList.items.length===0?(this.deleteItem(r.comment.id),this.updateItemsLayout()):r.deleteMainComment(e);return}if(r.childrenList.deleteItem(e)){r.commentCount===0&&(this.deleteItem(r.comment.id),this.updateItemsLayout());return}}}handleUpdateComment(e){if(Xs(e)){const r=this.commentsProvider.getComment(e.groupId),i=this.findItem(r.id);i&&i.handleUpdateChildComment(e);return}const o=this.findItem(e.id);o&&o.handleUpdateMainComment(e)}}const Mz="comment-mini";S("comment-list");class Rz extends ve.TypedEmitter{constructor(e,o){super();m(this,"root");m(this,"groupsContainer");m(this,"list");m(this,"handleSelectionOnComment",()=>{this.emit("onSelectComment")});m(this,"updateCommentCount",()=>{var o,r;const e=pz(this.editor,this.commentsProvider);(r=(o=this.commentOptions)==null?void 0:o.onCommentCountChange)==null||r.call(o,e)});m(this,"handleActiveItemChanged",(e,o)=>{var i,s;const r=this.list.activeItem;u8(this.editor,(s=(i=r==null?void 0:r.comment)==null?void 0:i.groupId)!=null?s:"",o)});m(this,"handleItemLayoutUpdated",()=>{var o,r;const e=xt(this.root,Mz);(r=(o=this.commentOptions)==null?void 0:o.onUpdateLayout)==null||r.call(o,this.editor,{expand:e})});this.editor=e,this.commentsProvider=o,this.root=k("div",["editor-web-comment-root"],null),this.groupsContainer=k("div",["comment-groups-container"],this.root),this.list=this.createList(),this.commentsProvider.addListener(this),this.list.addListener("activeItemChanged",this.handleActiveItemChanged),this.list.addListener("itemLayoutUpdated",this.handleItemLayoutUpdated),this.list.addListener("selectionOnComment",this.handleSelectionOnComment),this.list.addListener("commentCountChanged",this.updateCommentCount),this.updateCommentCount()}get commentOptions(){return this.editor.getComponentOptions("comment")}destroy(){this.list.removeAllListeners(),this.commentsProvider.removeListener(this),this.list.destroy(),this.root.remove()}onCreateComment(e,o){const r=this.commentsProvider.getComment(e);this.list.handleCreateComment(r,o),this.updateCommentCount()}onDeleteComment(e,o){this.list.handleDeleteComment(e),this.updateCommentCount()}onUpdateComment(e,o){const r=this.commentsProvider.getComment(e);this.list.handleUpdateComment(r)}createList(){return new Lz(this.editor,this.commentsProvider,this.groupsContainer)}show(e){var o;if(rt(this.root,"hidden"),e){const r=this.list.findItemIndex(e);this.list.setActiveItem(r)}(o=this.commentOptions)==null||o.controller.showCommentList()}hide(){W(this.root,"hidden")}}class Oz extends Qu{constructor({editor:t,parent:e,commentsProvider:o,comments:r}){super(t,o,e,r,{})}findInsertPos(){return this.items.length}createItem(t){const{editor:e,commentsProvider:o}=this;return new m8(e,o,t)}destroy(){this.items.forEach(t=>{t.destroy()})}}const f1=S("mobile-comment-group-item"),_z=20;class Fz extends ve.TypedEmitter{constructor(e,o,r){super();m(this,"root");m(this,"childrenList");m(this,"mainItem");m(this,"scroller");m(this,"createRoot",()=>k("div",["mobile-group-item-root"],null));m(this,"createMainItem",e=>{const{editor:o,commentsProvider:r,comment:i}=this,s=new m8(o,r,i);return e.append(s.root),s});m(this,"createChildrenList",e=>{const{editor:o,commentsProvider:r,comment:i}=this,s=k("div",["mobile-comment-children-list-container"],e);return new Oz({editor:o,commentsProvider:r,comments:i.children,parent:s})});m(this,"handleTouchEnd",()=>{var i;const{scroller:e}=this,{pullThreshold:o=_z}=(i=this.editor.getComponentOptions("comment"))!=null?i:{};let r=null;if(e.y>e.minScrollY+o?(r=this.root.previousElementSibling,r||this.emit("onReachTop")):e.y<e.maxScrollY-o&&(r=this.root.nextElementSibling,r||this.emit("onReachBottom")),r){const s=r.id;this.emit("onSwitchGroup",s,n8)}});m(this,"refreshScroller",()=>{this.scroller.refresh()});this.editor=e,this.commentsProvider=o,this.comment=r,this.root=k("div",["mobile-group-item-root"],null),this.root.id=r.groupId;const i=k("div",["mobile-group-item"],this.root),s=k("div",["mobile-group-item-space"],null),l=k("div",["mobile-group-item-abstract"],null);l.textContent=r.abstract;const a=k("div",["mobile-group-item-list-container"],null);this.mainItem=this.createMainItem(a),this.childrenList=this.createChildrenList(a),i.append(s,l,a),this.scroller=new c5.default(this.root,{stopPropagation:!0,click:!0}),this.scroller.on("touchEnd",this.handleTouchEnd)}get commentCount(){return o8(this.root,".mobile-group-item")}handleUpdateChildComment(e){g(f1,e.groupId===this.mainItem.comment.id,"invalid child comment");const o=this.childrenList.findItem(e.id);if(!o){f1.error(`can't find child comment item: ${e.id}`);return}o.reloadDoc()}handleUpdateMainComment(e){g(f1,e.id===this.mainItem.comment.id,"invalid comment"),this.mainItem.reloadDoc()}deleteMainComment(e){g(f1,e===this.mainItem.comment.id,"invalid comment"),this.mainItem.destroy()}destroy(){this.mainItem.destroy(),this.childrenList.destroy(),this.scroller.off("touchEnd",this.handleTouchEnd),this.scroller.destroy(),this.root.remove(),this.removeAllListeners()}}const $2=S("mobile-group-list");class Pz extends Qu{constructor(e,o,r,i){super(e,o,r,es(e,o),{});m(this,"scroller");m(this,"refreshScroller",()=>{this.scroller.refresh(),this.items.forEach(e=>{e.refreshScroller()})});m(this,"deleteItem",e=>{if(this.items.length<=1)return super.deleteItem(e);const o=this.findItemIndex(e);let r=null;return o===0?r=this.items[o+1].root.id:r=this.items[o-1].root.id,super.deleteItem(e)?(this.scrollToGroup(r,n8),!0):!1});m(this,"setupGroupItem",e=>{e.on("onSwitchGroup",this.scrollToGroup),e.on("onReachBottom",this.handleReachBottom),e.on("onReachTop",this.handleReachTop),e.refreshScroller()});m(this,"handleReachBottom",()=>{this.emit("onReachBottom")});m(this,"handleReachTop",()=>{this.emit("onReachTop")});m(this,"scrollToGroup",(e,o=0)=>{const r=this.findGroupItem(e);g($2,r,"invalid scroll target"),this.scroller.scrollToElement(r.root,o,!1,!1),u8(this.editor,r.comment.groupId)});m(this,"findGroupItem",e=>this.items.find(o=>o.comment.groupId===e));m(this,"handleDocChanged",()=>{this.updateComments()});m(this,"updateComments",Me.default(()=>{const e=es(this.editor,this.commentsProvider);for(let o=0;o<e.length;o++){const r=e[o];if(!this.findGroupItem(r.groupId)){this.handleCreateComment(r,!1);continue}}for(let o=this.items.length-1;o>=0;o--){const r=this.items[o];e.findIndex(i=>i.groupId===r.comment.groupId)===-1&&this.deleteItem(r.comment.id)}},100));this.scroller=new c5.default(i),this.scroller.disable(),this.editor.addListener("docChanged",this.handleDocChanged),this.items.forEach(this.setupGroupItem)}createItem(e){return new Fz(this.editor,this.commentsProvider,e)}insertItem(e){const o=super.insertItem(e);return o?(this.setupGroupItem(o),o):null}findInsertPos(e){const r=es(this.editor,this.commentsProvider).findIndex(i=>i.id===e.id);return r===-1||r>this.items.length?-1:r}setActiveItem(e){this.scrollToGroup(e)}handleCreateComment(e,o){if(Xs(e)){const s=this.findGroupItem(e.groupId);s&&s.childrenList.insertItem(e)}const r=this.findItem(e.id);g($2,!r,"comment group item has already exists");const i={children:[],...e};g($2,i.children,"not a comment group"),this.insertItem(i),this.scroller.refresh()}handleDeleteComment(e){for(let o=0;o<this.items.length;o++){const r=this.items[o];if(r.comment.id===e){r.childrenList.items.length===0?this.deleteItem(r.comment.id):r.deleteMainComment(e);return}if(r.childrenList.deleteItem(e)){r.commentCount===0&&this.deleteItem(r.comment.id);return}}}handleUpdateComment(e){if(Xs(e)){const r=this.commentsProvider.getComment(e.groupId),i=this.findItem(r.id);i&&i.handleUpdateChildComment(e);return}const o=this.findItem(e.id);o&&o.handleUpdateMainComment(e)}destroy(){this.editor.removeListener("docChanged",this.handleDocChanged),this.scroller.destroy(),this.items.forEach(e=>e.destroy())}}const Nz=S("mobile-comment-list"),{t:b8}=L;class $z extends ve.TypedEmitter{constructor(e,o){super();m(this,"root");m(this,"list");m(this,"mask");m(this,"pullInfoContainer");m(this,"handleRootClick",e=>{const o=e.target;g(Nz,o instanceof Element,"invalid target"),!(o.closest(".mobile-group-item-abstract")||o.closest(".mobile-group-item-list-container"))&&(this.hide(),this.emit("onCommentListClose"))});m(this,"hidePullInfo",Me.default(()=>{rt(this.pullInfoContainer,"active")},1e3*3));m(this,"handleReachBottom",()=>{this.showPullInfo("bottom")});m(this,"handleReachTop",()=>{this.showPullInfo("top")});m(this,"show",e=>{var o;rt(this.root,"hidden"),W(document.documentElement,"disabled-scroll"),(o=this.commentOptions)==null||o.controller.showCommentList(),queueMicrotask(()=>{this.list.refreshScroller(),e&&this.list.setActiveItem(e)})});m(this,"hide",()=>{W(this.root,"hidden"),rt(document.documentElement,"disabled-scroll")});this.editor=e,this.commentsProvider=o,this.root=k("div",["editor-mobile-comments-root"],null),this.mask=k("div",["mobile-comment-mask"],this.root);const r=k("div",["mobile-comment-groups-container"],this.root),i=k("div",["mobile-comment-groups-scroll-container"],r);this.list=new Pz(this.editor,this.commentsProvider,i,r),this.pullInfoContainer=this.createPullInfo(),this.commentsProvider.addListener(this),this.list.on("onReachBottom",this.handleReachBottom),this.list.on("onReachTop",this.handleReachTop),this.root.onclick=this.handleRootClick}onCreateComment(e,o){const r=this.commentsProvider.getComment(e);this.list.handleCreateComment(r,o)}onDeleteComment(e,o){this.list.handleDeleteComment(e)}onUpdateComment(e,o){const r=this.commentsProvider.getComment(e);this.list.handleUpdateComment(r)}get commentOptions(){return this.editor.getComponentOptions("comment")}createPullInfo(){const e=k("div",["mobile-comment-pull-info-container"],this.root);return k("div",["mobile-comment-pull-info"],e),e}showPullInfo(e){const o=b8(e==="bottom"?"comment.isLast":"comment.isFirst");this.pullInfoContainer.firstElementChild.textContent=o,W(this.pullInfoContainer,"active"),this.hidePullInfo()}destroy(){this.list.removeAllListeners(),this.list.destroy(),this.root.onclick=null}}function v8(n,t){const e=es(n,t),o=new Map;for(const r of e){const i=r8(n,r.groupId);if(!!i)if(o.has(i)){const s=o.get(i);O2(r).forEach(a=>{s==null||s.commentIds.add(a.id)})}else{const s=O2(r),l=new Set(s.map(a=>a.id));o.set(i,{commentIds:l,firstComment:r})}}return Array.from(o.entries()).map(([r,i])=>({blockId:r,...i}))}const Hz=S("mini-group-item");class jz{constructor(t,e){m(this,"root");m(this,"blockId");m(this,"comment");m(this,"miniCommentItem");m(this,"updateCommentItemCount",()=>{this.miniCommentItem.updateCount(this.commentCount)});this.editor=t,this.commentGroup=e,this.root=k("div",["mini-group-item"],null),this.comment=e.firstComment,this.miniCommentItem=new wz(this.comment.id,this.root),this.blockId=this.getBlockId(),setTimeout(()=>{this.alignToBlock()}),this.updateCommentItemCount()}getBlockId(){return r8(this.editor,this.comment.groupId)}get commentCount(){return this.commentGroup.commentIds.size}alignToBlock(){const t=this.getBlockId();if(!t)return;const e=this.editor.getBlockById(t);g(Hz,e,`The blockId: ${t} not exist in doc`);const o=this.editor.scrollContainer.getBoundingClientRect(),r=this.editor.scrollContainer.scrollTop,s=e.getBoundingClientRect().top-o.top+r;requestAnimationFrame(()=>{this.root.style.transform=`translateY(${s}px)`})}destroy(){this.root.remove()}}class Uz extends Qu{constructor(e,o,r){super(e,o,r,v8(e,o),{});m(this,"fixListOps",Me.default(()=>{this.items.forEach(e=>{e.alignToBlock()})},100));m(this,"handleDocChanged",Me.default(()=>{this.updateMiniCommentsGroup()},100));m(this,"updateMiniCommentsGroup",()=>{const e=v8(this.editor,this.commentsProvider);this.reloadList(e)});this.editor=e,this.commentsProvider=o,this.editor.addListener("docChanged",this.handleDocChanged),this.editor.addListener("resize",this.fixListOps)}createItem(e){return new jz(this.editor,e)}findInsertPos(){return-1}handleCreateComment(e,o){this.updateMiniCommentsGroup()}handleDeleteComment(e){this.updateMiniCommentsGroup()}destroy(){this.editor.removeListener("docChanged",this.handleDocChanged),super.destroy(),this.removeAllListeners()}}const zz=S("mini-comments-list");class Vz extends ve.TypedEmitter{constructor(e,o){super();m(this,"list");m(this,"root");m(this,"createList",()=>{const e=k("div",["comment-groups-container"],this.root);return this.editor.domEvents.addEventListener(e,"click",this.handleListContainerClick),new Uz(this.editor,this.commentsProvider,e)});m(this,"handleListContainerClick",(e,o)=>{const r=o.target;g(zz,r instanceof HTMLElement,"The target is not a valid html element");const i=r.closest(".mini-comment-item");i&&this.emit("onItemClick",i.id)});this.editor=e,this.commentsProvider=o,this.root=k("div",["editor-mini-comment-root"],null),this.list=this.createList(),this.commentsProvider.addListener(this)}onCreateComment(e,o){const r=this.commentsProvider.getComment(e);this.list.handleCreateComment(r,o)}onDeleteComment(e,o){this.list.handleDeleteComment(e)}onUpdateComment(e,o){}show(){rt(this.root,"hidden")}hide(){W(this.root,"hidden")}destroy(){this.list.destroy(),this.removeAllListeners()}}function y8(n,t,e){if(!t.start.isSimple()||!t.end.isSimple())return;const o=t.block,r=ke(n,o,t.start.offset,t.end.offset),i=`comment-${e.id.toLocaleLowerCase()}`,s=e.id;uA(n,o,r,i,s)}function Wz(n,t,e){const o=cr(n).map(s=>s.block),r=L2(n,o),i=a1({editor:n,abstract:r});return n.undoManager.runInGroup(()=>{cr(n,{simpleBlockOnly:!0}).forEach(a=>{!et(n,a.block)||y8(n,a,i)});const l=Yr();e.localCreateComment(i,l)}),i}class qz{constructor(t,e){m(this,"id","CommentsCommandProvider");this.provider=t,this.editorComments=e}getAvailableCommands(t,e,o){const r=t.selection.range;if(et(t,e)&&!o.isCollapsed()&&r.isSimple()){const i=it(e),s=Dt(e),l=Lo(t,e);return[{id:"add-comment",name:L.t("comment.command"),blockId:i,blockType:s,blockKind:l,groupIndex:1e3,icon:cc}]}return[]}hideToolbar(t){const e=t.findCustom("toolbar-handler");e==null||e.disableTextToolbar(),e==null||e.hide(),setTimeout(()=>{e==null||e.enableTextToolbar()},300)}executeRangeCommand(t,e,o,r,i){if(o.id==="add-comment"){this.editorComments.showCommentList();const s=Wz(t,e,this.provider);return i["add-comment"]=s,this.hideToolbar(t),!0}return!1}}class k8{constructor(t,e){m(this,"commentList",null);m(this,"mobileCommentList",null);m(this,"miniCommentList");m(this,"showComment",(t,e)=>{var o,r;t==="mini"&&this.miniCommentList.show(),t==="mobile"&&((o=this.mobileCommentList)==null||o.show(e)),t==="web"&&((r=this.commentList)==null||r.show(e))});m(this,"showCommentList",t=>{this.isMobile?this.showComment("mobile",t):this.showComment("web",t)});m(this,"handleCommentListClose",()=>{this.showComment("mini")});m(this,"handleOnSelectComment",()=>{this.showComment("web")});m(this,"handleMiniCommentItemClick",t=>{this.showCommentList(t)});this.editor=t,this.provider=e,t.editorCommandProviders.registerCommandProvider(new qz(e,this)),t.blockHooks.push(new lz(this.provider,this)),this.isMobile?(this.mobileCommentList=new $z(this.editor,this.provider),this.mobileCommentList.on("onCommentListClose",this.handleCommentListClose)):(this.commentList=new Rz(this.editor,this.provider),this.commentList.on("onSelectComment",this.handleOnSelectComment)),this.miniCommentList=new Vz(this.editor,this.provider),this.miniCommentList.on("onItemClick",this.handleMiniCommentItemClick),this.editor.input.addHandler(new cz)}get commentProvider(){return this.provider}get isMobile(){return Ze.isMobile}destroy(){var t,e;(t=this.commentList)==null||t.destroy(),(e=this.mobileCommentList)==null||e.destroy(),this.miniCommentList.destroy()}mount(t){var e;t.container&&this.commentList&&t.container.append((e=this.commentList)==null?void 0:e.root),t.miniContainer&&t.miniContainer.append(this.miniCommentList.root),t.mobileContainer&&this.mobileCommentList&&t.mobileContainer.append(this.mobileCommentList.root)}}const Got="",Gz={comment:{count:"\u6279\u6CE8 ({num})",hide:"\u9690\u85CF\u6279\u6CE8",show:"\u663E\u793A\u6279\u6CE8",reply:"\u56DE\u590D",quicklyReply:"\u56DE\u590D...",send:"\u786E\u8BA4",placeholder:"\u6DFB\u52A0\u6279\u6CE8...",replyPlaceholder:"\u56DE\u590D\u6216@\u4ED6\u4EBA",edit:"\u7F16\u8F91",delete:"\u5220\u9664",image:"\u56FE\u7247",sendTitle:"\u6309Enter\u53D1\u9001\u6279\u6CE8",replyTitle:"\u6309Enter\u56DE\u590D\u6279\u6CE8",isFirst:"\u5DF2\u7ECF\u662F\u7B2C\u4E00\u6761\u6279\u6CE8",isLast:"\u5DF2\u7ECF\u662F\u6700\u540E\u4E00\u6761\u6279\u6CE8",more:"\u66F4\u591A",comment:"\u6279\u6CE8",command:"\u6279\u6CE8",quickMenuCommand:"\u6DFB\u52A0\u6279\u6CE8"}},Zz={comment:{count:"Annotations ({num})",hide:"Hide Annotations",show:"Show Annotations",reply:"Reply",quicklyReply:"Reply...",send:"Confirm",placeholder:"Add a annotation...",replyPlaceholder:"Add annotations or @ others",edit:"Edit",delete:"Delete",image:"Image",sendTitle:"Press Enter to post annotation",replyTitle:"Press Enter to reply to annotation",isFirst:"This is already the first comment",isLast:"This is already the last comment",more:"More",comment:"Annotation",command:"Annotation",quickMenuCommand:"Add annotation"}},Qz={comment:{count:"\u6CE8\u91C8 ({num})",hide:"\u6CE8\u91C8\u3092\u975E\u8868\u793A",show:"\u6CE8\u91C8\u3092\u8868\u793A",reply:"\u8FD4\u4FE1",quicklyReply:"\u8FD4\u4FE1...",send:"\u78BA\u8A8D",placeholder:"\u6CE8\u91C8\u3092\u8FFD\u52A0...",replyPlaceholder:"\u8FD4\u4FE1\u307E\u305F\u306F\u30E1\u30F3\u30B7\u30E7\u30F3(@)",edit:"\u7DE8\u96C6",delete:"\u524A\u9664",image:"\u753B\u50CF",sendTitle:"Enter\u3092\u62BC\u3057\u3066\u6CE8\u91C8\u3092\u9001\u4FE1",replyTitle:"Enter\u3092\u62BC\u3057\u3066\u6CE8\u91C8\u3092\u8FD4\u4FE1",isFirst:"\u6700\u521D\u306E\u6CE8\u91C8\u3067\u3059",isLast:"\u6700\u5F8C\u306E\u6CE8\u91C8\u3067\u3059",more:"\u305D\u306E\u4ED6",comment:"\u6CE8\u91C8",command:"\u6CE8\u91C8",quickMenuCommand:"\u6CE8\u91C8\u3092\u8FFD\u52A0"}};L.mergeLang({"zh-CN":Gz,"en-US":Zz,"ja-JP":Qz});class w8{renderText(t,e,o){const r=[],i={};return Object.entries(o).forEach(([s,l])=>{s.startsWith("comment-")&&(r.push("comment"),i[s]=l)}),{classes:r,attributes:i}}renderBlock(t,e,o){const r=o.comments;if(!r||r.length===0)return{};const i=["comment"],s={};return r.forEach(l=>{s[`comment-${l.toLocaleLowerCase()}`]=l}),{classes:i,attributes:s}}updateBlock(t,e,o,r){const i=r.comments;rt(o,"comment"),Array.from(o.attributes).forEach(s=>{s.name.startsWith("comment-")&&o.removeAttribute(s.name)}),!(!i||i.length===0)&&(W(o,"comment"),i.forEach(s=>{o.setAttribute(`comment-${s.toLocaleLowerCase()}`,s)}))}}class Yz{constructor(t){m(this,"handleUpdateCompositionText",(t,e,o,r,i)=>{const s=t.getFocusedBlock(),l=t.getFirstBlock();s===l&&this.applyPlaceholder(t)});m(this,"handleSelectionChange",t=>{this.applyPlaceholder(t)});m(this,"applyPlaceholder",t=>{const e=t.getFirstBlock();Zf(t,e,L.t("comment.replyPlaceholder"))});this.applyPlaceholder(t),t.addListener("selectionChanged",this.handleSelectionChange)}}function Jz(n,t,e){const o=n.getBlockData(t),r=o.comments;if((r==null?void 0:r.indexOf(e))!==-1){const s=new Set(r);s.delete(e),n.updateBlockData(t,{comments:Array.from(s)})}const i=o.text;if(!!i&&et(n,t)){const s=xg(i,`comment-${e.toLocaleLowerCase()}`,e);Ca.default(i,s)||n.setBlockText(t,s)}}const Kz=S("editor-comment");function Xz(n){const t=n.getCustom("editor-comments");if(g(Kz,t,"the editor comment not exist"),t.showCommentList(),n.selection.range.isCollapsed()){const s=n.selection.startBlock,l=_i(s);if(l.length>=2){const{containerId:a}=l[l.length-1],d=nt(sr(n,a));if(d&&Dt(d)==="code"){M2(n,d,t.commentProvider);return}}M2(n,s,t.commentProvider);return}const e=cr(n,{simpleBlockOnly:!0}),o=e.map(s=>s.block),r=L2(n,o),i=a1({editor:n,abstract:r});n.undoManager.runInGroup(()=>{e.forEach(l=>{et(n,l.block)?y8(n,l,i):t8(n,l.block,i)});const s=Yr();t.commentProvider.localCreateComment(i,s)})}const H2=S("text-styles");function tV(n){const t=o=>{if(!o.attributes)return new Map;const r=Object.entries(o.attributes).filter(([i])=>!!i.startsWith("style-"));return new Map(r)};if(n.length===0)return new Map;let e=t(n[0]);for(let o=1;o<n.length;o++){const r=t(n[o]);e=new Map(Array.from(e.entries()).filter(([i,s])=>r.get(i)===s))}return e}function eV(n,t,e,o,r){g(H2,e.isSimple(),"invalid range");const{start:i,end:s}=e;g(H2,i.blockId===s.blockId&&i.blockId===it(t),"invalid range"),g(H2,o.startsWith("style-"),"invalid style");let a=n.getBlockText(t);return o==="style-sub"?a=Jl(i.offset,s.offset-i.offset,a,"style-super",r,{ignoreValue:!0}):o==="style-super"&&(a=Jl(i.offset,s.offset-i.offset,a,"style-sub",r,{ignoreValue:!0})),r===!1||r===void 0||r===null?a=Jl(i.offset,s.offset-i.offset,a,o,void 0,{ignoreValue:!0}):a=Pa(i.offset,s.offset-i.offset,a,o,r),n.setBlockText(t,a),a}const nV=`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
503
|
+
</svg>`,qot="",u1="reply-editor-editing",{t:N2}=L;class Iz{constructor(t,e,o,r){m(this,"root");m(this,"components");m(this,"handleFocus",()=>{const{replyEditor:t,okButton:e}=this.components;t.isEmpty()&&(e.disabled=!0)});m(this,"handleDocChange",()=>{const{replyEditor:t,okButton:e}=this.components,o=t.getDoc();Sg(o)?e.disabled=!0:e.disabled=!1});m(this,"getReplyEditor",()=>this.components.replyEditor);m(this,"showReplyEditor",()=>{xt(this.root,u1)||(W(this.root,u1),this.components.replyEditor.edit())});m(this,"hideReplyEditor",()=>{!xt(this.root,u1)||rt(this.root,u1)});m(this,"reply",()=>{const{mainEditor:t,comment:e,components:{replyEditor:o},commentsProvider:r}=this,i=o.getDoc(),s=a1({editor:t,commentGroupId:e.groupId});r.localCreateComment(s,i),this.hideReplyEditor(),o.clear()});m(this,"cancel",()=>{const{replyEditor:t}=this.components;this.hideReplyEditor(),t.clear()});m(this,"hide",()=>{xt(this.root,"hidden")||W(this.root,"hidden")});m(this,"show",()=>{rt(this.root,"hidden")});this.mainEditor=t,this.commentsProvider=e,this.comment=o,this.groupItem=r,this.root=k("div",["comment-quick-reply"],null),this.components=this.createQuickReply()}createQuickReply(){const{commentsProvider:t}=this,e=Ys(this.root,Jt.QuickReply,N2("comment.placeholder"));ii(e,Jt.QuickReply),e.classList.add("quick-reply-button");const o=k("div",["quick-reply-editor"],this.root),r=Yr(),i=new P2(this.mainEditor,t,r);i.editor.addListener("docChanged",this.handleDocChange),i.editor.addListener("focus",this.handleFocus),i.editor.input.addHandler(new bz(this.groupItem)),o.append(i.root);const s=k("div",["reply-editor-actions"],o),l=mo(Jt.QuickReplyCancel,N2("common.cancel"));ii(l,Jt.QuickReplyCancel);const a=mo(Jt.QuickReplyOk,N2("comment.send"),void 0,["primary","disabled"]);return ii(a,Jt.QuickReplyOk),s.append(l,a),this.hideReplyEditor(),{replyTextButton:e,replyEditor:i,replyEditorContainer:o,okButton:a}}}const si=S("comment-group-item");class Tz extends ve.TypedEmitter{constructor(e,o,r,i){super();m(this,"root");m(this,"header");m(this,"mainItem");m(this,"childrenList");m(this,"resizeObserver");m(this,"quickReply");m(this,"createRoot",()=>k("div",["comment-group-item-root"],null));m(this,"createChildrenList",()=>{const e=k("div",["comment-children-list-container"],this.root);return new Bz({editor:this.editor,commentsProvider:this.commentsProvider,comments:this.comment.children,parent:e,groupList:this.groupList,groupItem:this})});m(this,"updateLastCommentItem",()=>{const e=Array.from(this.root.querySelectorAll(":scope .comment-item-root"));g(si,e.length!==0,"current group item not exist comment-item"),e.forEach(r=>{rt(r,e8)});const o=e[e.length-1];W(o,e8)});m(this,"updateSwitchButton",()=>{const e=this.root.querySelector(':scope .editor-text-button[group-item-action="switch-up"]'),o=this.root.querySelector(':scope .editor-text-button[group-item-action="switch-down"]');g(si,e,"switchUpButton not exist"),g(si,o,"switchDownButton not exist"),rt(o,"disabled"),rt(e,"disabled"),this.root.previousElementSibling===null&&W(e,"disabled"),this.root.nextElementSibling===null&&W(o,"disabled")});m(this,"handleReadonlyChanged",e=>{e.readonly?W(this.root,"readonly"):rt(this.root,"readonly")});m(this,"handleResize",()=>{this.emit("resize")});this.editor=e,this.commentsProvider=o,this.comment=r,this.groupList=i,this.root=this.createRoot(),this.header=this.createHeader(),this.mainItem=this.createItem(),this.childrenList=this.createChildrenList(),this.quickReply=this.createQuickReply(),this.editor.on("readonlyChanged",this.handleReadonlyChanged),this.resizeObserver=new vs(this.handleResize),this.resizeObserver.observe(this.root),this.updateLastCommentItem()}get commentCount(){return o8(this.root)}createQuickReply(){const{editor:e,commentsProvider:o,comment:r}=this,i=new Iz(e,o,r,this);return this.root.append(i.root),i}createHeader(){const{comment:e}=this,o=k("div",["comment-item-head"],this.root),r=k("span",["item-head-quote"],o);r.innerText=e.abstract;const i=k("span",["item-head-switch"],o),s=Ys(i,Jt.SwitchUp,"up",Ez),l=Ys(i,Jt.SwitchDown,"down",xz);return ii(s,Jt.SwitchUp),ii(l,Jt.SwitchDown),o}createItem(){const e=k("div",["comment-item-container"],this.root),{editor:o,commentsProvider:r,comment:i,groupList:s}=this,l=new f8({mainEditor:o,commentsProvider:r,comment:i,groupList:s,groupItem:this});return e.appendChild(l.root),l}findCommentItem(e){return e?e===this.mainItem.comment.id?this.mainItem:this.childrenList.items.find(o=>o.comment.id===e):null}handleCreateComment(e){return g(si,Xs(e),"invalid comment, not a child comment"),g(si,e.groupId===this.comment.id,"invalid comment, not a child comment"),this.childrenList.createItem(e)}handleUpdateChildComment(e){g(si,e.groupId===this.mainItem.comment.id,"invalid child comment");const o=this.childrenList.findItem(e.id);if(!o){si.error(`can't find child comment item: ${e.id}`);return}o.reloadDoc()}handleUpdateMainComment(e){g(si,e.id===this.mainItem.comment.id,"invalid comment"),this.mainItem.reloadDoc()}deleteMainComment(e){g(si,e===this.mainItem.comment.id,"invalid comment"),this.mainItem.destroy()}edit(){this.mainItem.edit()}destroy(){this.mainItem.destroy(),this.childrenList.destroy(),this.root.remove(),this.resizeObserver.disconnect(),this.removeAllListeners(),this.editor.removeListener("readonlyChanged",this.handleReadonlyChanged)}}const Dz=S("arrange=items"),g8=20;function p8(n,t){const e=n.rootContainer.querySelector(`[comment-${t.toLocaleLowerCase()}=${t}]`);if(!e)return-1;const o=n.scrollContainer.getBoundingClientRect(),r=n.scrollContainer.scrollTop;return e.getBoundingClientRect().top-o.top+r}function C8(n,t){return Number.parseInt(t.root.style.top,10)}function A8(n,t,e,o){let r=0;e&&(r=t.indexOf(e),r===-1&&(r=0));for(let i=r;i<t.length;i++){const s=t[i],l=s.comment,a=p8(n,l.groupId);if(s.root.setAttribute("data-target-top",a.toString()),i===r){if(o!==void 0){const p=t[0];p.root.style.top=`${o}px`}else s.root.style.top=`${a}px`;continue}const d=t[i-1],h=C8(n,d)+d.root.getBoundingClientRect().height;h>a?s.root.style.top=`${h+g8}px`:s.root.style.top=`${a}px`}for(let i=r-1;i>=0;i--){const s=t[i],l=s.comment,a=p8(n,l.groupId);s.root.setAttribute("data-target-top",a.toString());const d=s.root.getBoundingClientRect(),h=a+d.height,p=t[i+1];g(Dz,p,"no next item");const C=C8(n,p);C<h?s.root.style.top=`${C-d.height-g8}px`:s.root.style.top=`${a}px`}setTimeout(()=>{n.scrollContainer.dispatchEvent(new Event("scroll"))},350)}const d1=S("comment-group-item-handler");class Sz{constructor(t,e){m(this,"handleSwitchUp",t=>{const e=Math.max(0,t-1);this.groupList.setActiveItem(e,"prev"),this.groupList.updateItemsLayout()});m(this,"handleSwitchDown",t=>{const e=Math.min(t+1,this.groupList.items.length);this.groupList.setActiveItem(e,"next"),this.groupList.updateItemsLayout()});m(this,"handleQuickReply",t=>{const{quickReply:e}=t;e.showReplyEditor()});m(this,"handleQuickReplyOk",t=>{const{quickReply:e}=t;e.reply(),t.updateLastCommentItem()});m(this,"handleQuickReplyCancel",t=>{const{quickReply:e}=t;e.cancel()});m(this,"handleCommentItemReply",(t,e)=>{const o=t.findCommentItem(e);g(d1,o,`the commentItem: ${e} not exist `);const{quickReply:r}=t;r.show(),r.showReplyEditor();const{comment:i}=o,s=r.getReplyEditor(),l=s.editor.getFocusedBlock(),a={type:"mention",id:K(),box:!0,created:Date.now(),text:i.displayName,iconUrl:i.avatarUrl,mentionId:i.userId};s.editor.insertBoxToBlock(l,0,a)});m(this,"handleCommentItemMore",t=>{const{quickReply:e}=t;e.hideReplyEditor(),e.getReplyEditor().clear()});m(this,"handleCommentItemOk",(t,e)=>{const o=t.findCommentItem(e);g(d1,o,`the commentItem: ${e} not exist `);const{quickReply:r}=t,{comment:i,getCommentEditor:s}=o,l=s(),a=l.getDoc();this.commentsProvider.localUpdateComment(i,a),l.readonly(),r.show()});m(this,"handleCommentItemCancel",(t,e)=>{var a,d;const o=t.findCommentItem(e);g(d1,o,`the commentItem: ${e} not exist `);const r=this.commentsProvider.getComment(o.comment.id);let i=!1;if((a=r.blocks)!=null&&a.length||(i=!0),((d=r.blocks)==null?void 0:d.length)===1){const h=r.blocks[0];i=!!h.text&&rn(h.text)===0}if(i){this.commentsProvider.localDeleteComment(o.comment.id);return}const{quickReply:s}=t,l=o.getCommentEditor();l.setDoc(o.doc),l.readonly(),s.show()});m(this,"handleCommentItemEdit",t=>{const e=this.groupList.findItem(t.comment.groupId);if(!e)return;const{quickReply:o}=e;t.getCommentEditor().edit(),o.hide()});m(this,"handleCommentItemDelete",t=>{const e=this.groupList.findItem(t.comment.groupId);if(!e)return;const{quickReply:o}=e,{comment:r}=t;this.commentsProvider.localDeleteComment(r.id),o.show()});m(this,"execute",(t,e,o,r)=>{const i=dz(t);if(!i||fz(i))return;const s=hz(i);switch(s){case Jt.SwitchUp:this.handleSwitchUp(r);break;case Jt.SwitchDown:this.handleSwitchDown(r);break;case Jt.CommentItemReply:this.handleCommentItemReply(e,o);break;case Jt.CommentItemMore:this.handleCommentItemMore(e);break;case Jt.CommentItemOk:this.handleCommentItemOk(e,o);break;case Jt.CommentItemCancel:this.handleCommentItemCancel(e,o);break;case Jt.CommentItemDelete:break;case Jt.CommentItemEdit:break;case Jt.QuickReply:this.handleQuickReply(e);break;case Jt.QuickReplyOk:this.handleQuickReplyOk(e);break;case Jt.QuickReplyCancel:this.handleQuickReplyCancel(e);break;default:const l=s;d1.debug(`not implement handler for ${l}`)}});this.groupList=t,this.commentsProvider=e}destroy(){}}const h1=S("comment-group-list");class Lz extends Qu{constructor(e,o,r){super(e,o,r,es(e,o),{});m(this,"groupItemHandlers");m(this,"findGroupItem",e=>this.items.find(o=>o.comment.groupId===e));m(this,"handleContainerClick",e=>{if(!e.target||!(e.target instanceof Element))return;const o=e.target.closest(".comment-group-item-root");if(!o)return;const r=uz(e.target),i=this.items.findIndex(s=>s.root===o);if(i!==-1){this.setActiveItem(i);const{groupItemHandlers:s}=this;s.execute(e.target,this.items[i],r,i)}});m(this,"handleSelectionChanged",()=>{setTimeout(()=>{var o;const e=c8(this.editor);if(e.length>0){if(((o=this.activeItem)==null?void 0:o.comment.id)&&e.includes(this.activeItem.comment.id))return;const r=e[0],i=this.items.findIndex(s=>s.comment.groupId===r);this.setActiveItem(i),this.emit("selectionOnComment")}else this.setActiveItem(-1)})});m(this,"handleEditorResize",()=>{this.updateItemsLayout()});m(this,"handleDocChanged",()=>{this.updateComments()});m(this,"handleItemResize",()=>{this.updateItemsLayout()});m(this,"handleScroll",e=>{if(e.deltaY>=0||this.editor.scrollContainer.scrollTop!==0)return;const o=document.elementFromPoint(e.clientX,e.clientY);if(!o||!(o instanceof HTMLElement)||!this.editor.scrollContainer.contains(o))return;const r=this.container.querySelector(".comment-group-item-root");if(!r)return;const i=Number.parseFloat(r.style.top),s=Number.parseFloat(r.getAttribute("data-target-top")||"0");!Number.isNaN(i)&&!Number.isNaN(s)&&i<s&&A8(this.editor,this.items,null,Math.min(i+(0-e.deltaY)*3,s))});m(this,"updateGroupItemSwitch",()=>{const e=this.activeItem;g(h1,e,"invalid activeItem"),e.updateSwitchButton()});m(this,"updateComments",Me.default(()=>{const e=es(this.editor,this.commentsProvider);let o=!1;for(let r=0;r<e.length;r++){const i=e[r];if(!this.findGroupItem(i.groupId)){this.handleCreateComment(i,!1),o=!0;continue}}for(let r=this.items.length-1;r>=0;r--){const i=this.items[r];e.findIndex(s=>s.groupId===i.comment.groupId)===-1&&(this.deleteItem(i.comment.id),o=!0)}o&&(this.updateItemsLayout(),this.emit("commentCountChanged"))},100));this.updateItemsLayout(),this.bindEvents(),this.editor.addListener("selectionChanged",this.handleSelectionChanged),this.editor.addListener("resize",this.handleEditorResize),this.editor.addListener("docChanged",this.handleDocChanged),this.editor.scrollContainer.addEventListener("wheel",this.handleScroll,{passive:!1}),this.items.forEach(i=>i.addListener("resize",this.handleItemResize)),this.groupItemHandlers=new Sz(this,o)}destroy(){this.editor.removeListener("selectionChanged",this.handleSelectionChanged),this.editor.removeListener("resize",this.handleEditorResize),this.editor.removeListener("docChanged",this.handleDocChanged),this.editor.scrollContainer.removeEventListener("wheel",this.handleScroll),super.destroy(),this.unbindEvents(),this.removeAllListeners()}updateItemsLayout(){A8(this.editor,this.items,this.activeItem)}bindEvents(){this.container.addEventListener("click",this.handleContainerClick)}unbindEvents(){this.container.removeEventListener("click",this.handleContainerClick)}createItem(e,o){const r=new Tz(this.editor,this.commentsProvider,e,this);return o==="insert"&&(W(r.root,"no-animation"),r.root.style.opacity="0",setTimeout(()=>{rt(r.root,"no-animation"),r.root.style.opacity="1"},150)),r}findInsertPos(e){const r=es(this.editor,this.commentsProvider).findIndex(i=>i.id===e.id);return r===-1||r>this.items.length?-1:r}insertItem(e,o){const r=super.insertItem(e);return r?(o!=null&&o.active&&this.setActiveItem(this.items.indexOf(r)),this.updateItemsLayout(),r.addListener("resize",this.handleItemResize),r):null}setActiveItem(e,o){if(g(h1,e>=-1&&e<this.items.length,`invalid index: ${e}`),e===this.activeIndex)return;const r=this.container.querySelector(".comment-group-item-root.active");if(r&&rt(r,"active"),e!==-1){const i=this.items[e];W(i.root,"active"),this.updateItemsLayout(),this.updateGroupItemSwitch()}this.emit("activeItemChanged",e,o)}get activeIndex(){const e=this.container.querySelector(".comment-group-item-root.active");return e?this.items.findIndex(o=>o.root===e):-1}get activeItem(){const e=this.activeIndex;return e===-1?null:this.items[e]}handleCreateComment(e,o){if(Xs(e)){const l=this.findGroupItem(e.groupId);l&&l.childrenList.insertItem(e)}const r=this.findItem(e.id);g(h1,!r,"comment group item has already exists");const i={children:[],...e};g(h1,i.children,"not a comment group");const s=this.insertItem(i,{active:o});!s||o&&setTimeout(()=>{const l=this.items.indexOf(s);this.setActiveItem(l),s.edit(),s.quickReply.hide()})}handleDeleteComment(e){for(let o=0;o<this.items.length;o++){const r=this.items[o];if(r.comment.id===e){r.childrenList.items.length===0?(this.deleteItem(r.comment.id),this.updateItemsLayout()):r.deleteMainComment(e);return}if(r.childrenList.deleteItem(e)){r.commentCount===0&&(this.deleteItem(r.comment.id),this.updateItemsLayout());return}}}handleUpdateComment(e){if(Xs(e)){const r=this.commentsProvider.getComment(e.groupId),i=this.findItem(r.id);i&&i.handleUpdateChildComment(e);return}const o=this.findItem(e.id);o&&o.handleUpdateMainComment(e)}}const Mz="comment-mini";S("comment-list");class Rz extends ve.TypedEmitter{constructor(e,o){super();m(this,"root");m(this,"groupsContainer");m(this,"list");m(this,"handleSelectionOnComment",()=>{this.emit("onSelectComment")});m(this,"updateCommentCount",()=>{var o,r;const e=pz(this.editor,this.commentsProvider);(r=(o=this.commentOptions)==null?void 0:o.onCommentCountChange)==null||r.call(o,e)});m(this,"handleActiveItemChanged",(e,o)=>{var i,s;const r=this.list.activeItem;u8(this.editor,(s=(i=r==null?void 0:r.comment)==null?void 0:i.groupId)!=null?s:"",o)});m(this,"handleItemLayoutUpdated",()=>{var o,r;const e=xt(this.root,Mz);(r=(o=this.commentOptions)==null?void 0:o.onUpdateLayout)==null||r.call(o,this.editor,{expand:e})});this.editor=e,this.commentsProvider=o,this.root=k("div",["editor-web-comment-root"],null),this.groupsContainer=k("div",["comment-groups-container"],this.root),this.list=this.createList(),this.commentsProvider.addListener(this),this.list.addListener("activeItemChanged",this.handleActiveItemChanged),this.list.addListener("itemLayoutUpdated",this.handleItemLayoutUpdated),this.list.addListener("selectionOnComment",this.handleSelectionOnComment),this.list.addListener("commentCountChanged",this.updateCommentCount),this.updateCommentCount()}get commentOptions(){return this.editor.getComponentOptions("comment")}destroy(){this.list.removeAllListeners(),this.commentsProvider.removeListener(this),this.list.destroy(),this.root.remove()}onCreateComment(e,o){const r=this.commentsProvider.getComment(e);this.list.handleCreateComment(r,o),this.updateCommentCount()}onDeleteComment(e,o){this.list.handleDeleteComment(e),this.updateCommentCount()}onUpdateComment(e,o){const r=this.commentsProvider.getComment(e);this.list.handleUpdateComment(r)}createList(){return new Lz(this.editor,this.commentsProvider,this.groupsContainer)}show(e){var o;if(rt(this.root,"hidden"),e){const r=this.list.findItemIndex(e);this.list.setActiveItem(r)}(o=this.commentOptions)==null||o.controller.showCommentList()}hide(){W(this.root,"hidden")}}class Oz extends Qu{constructor({editor:t,parent:e,commentsProvider:o,comments:r}){super(t,o,e,r,{})}findInsertPos(){return this.items.length}createItem(t){const{editor:e,commentsProvider:o}=this;return new m8(e,o,t)}destroy(){this.items.forEach(t=>{t.destroy()})}}const f1=S("mobile-comment-group-item"),_z=20;class Fz extends ve.TypedEmitter{constructor(e,o,r){super();m(this,"root");m(this,"childrenList");m(this,"mainItem");m(this,"scroller");m(this,"createRoot",()=>k("div",["mobile-group-item-root"],null));m(this,"createMainItem",e=>{const{editor:o,commentsProvider:r,comment:i}=this,s=new m8(o,r,i);return e.append(s.root),s});m(this,"createChildrenList",e=>{const{editor:o,commentsProvider:r,comment:i}=this,s=k("div",["mobile-comment-children-list-container"],e);return new Oz({editor:o,commentsProvider:r,comments:i.children,parent:s})});m(this,"handleTouchEnd",()=>{var i;const{scroller:e}=this,{pullThreshold:o=_z}=(i=this.editor.getComponentOptions("comment"))!=null?i:{};let r=null;if(e.y>e.minScrollY+o?(r=this.root.previousElementSibling,r||this.emit("onReachTop")):e.y<e.maxScrollY-o&&(r=this.root.nextElementSibling,r||this.emit("onReachBottom")),r){const s=r.id;this.emit("onSwitchGroup",s,n8)}});m(this,"refreshScroller",()=>{this.scroller.refresh()});this.editor=e,this.commentsProvider=o,this.comment=r,this.root=k("div",["mobile-group-item-root"],null),this.root.id=r.groupId;const i=k("div",["mobile-group-item"],this.root),s=k("div",["mobile-group-item-space"],null),l=k("div",["mobile-group-item-abstract"],null);l.textContent=r.abstract;const a=k("div",["mobile-group-item-list-container"],null);this.mainItem=this.createMainItem(a),this.childrenList=this.createChildrenList(a),i.append(s,l,a),this.scroller=new c5.default(this.root,{stopPropagation:!0,click:!0}),this.scroller.on("touchEnd",this.handleTouchEnd)}get commentCount(){return o8(this.root,".mobile-group-item")}handleUpdateChildComment(e){g(f1,e.groupId===this.mainItem.comment.id,"invalid child comment");const o=this.childrenList.findItem(e.id);if(!o){f1.error(`can't find child comment item: ${e.id}`);return}o.reloadDoc()}handleUpdateMainComment(e){g(f1,e.id===this.mainItem.comment.id,"invalid comment"),this.mainItem.reloadDoc()}deleteMainComment(e){g(f1,e===this.mainItem.comment.id,"invalid comment"),this.mainItem.destroy()}destroy(){this.mainItem.destroy(),this.childrenList.destroy(),this.scroller.off("touchEnd",this.handleTouchEnd),this.scroller.destroy(),this.root.remove(),this.removeAllListeners()}}const $2=S("mobile-group-list");class Pz extends Qu{constructor(e,o,r,i){super(e,o,r,es(e,o),{});m(this,"scroller");m(this,"refreshScroller",()=>{this.scroller.refresh(),this.items.forEach(e=>{e.refreshScroller()})});m(this,"deleteItem",e=>{if(this.items.length<=1)return super.deleteItem(e);const o=this.findItemIndex(e);let r=null;return o===0?r=this.items[o+1].root.id:r=this.items[o-1].root.id,super.deleteItem(e)?(this.scrollToGroup(r,n8),!0):!1});m(this,"setupGroupItem",e=>{e.on("onSwitchGroup",this.scrollToGroup),e.on("onReachBottom",this.handleReachBottom),e.on("onReachTop",this.handleReachTop),e.refreshScroller()});m(this,"handleReachBottom",()=>{this.emit("onReachBottom")});m(this,"handleReachTop",()=>{this.emit("onReachTop")});m(this,"scrollToGroup",(e,o=0)=>{const r=this.findGroupItem(e);g($2,r,"invalid scroll target"),this.scroller.scrollToElement(r.root,o,!1,!1),u8(this.editor,r.comment.groupId)});m(this,"findGroupItem",e=>this.items.find(o=>o.comment.groupId===e));m(this,"handleDocChanged",()=>{this.updateComments()});m(this,"updateComments",Me.default(()=>{const e=es(this.editor,this.commentsProvider);for(let o=0;o<e.length;o++){const r=e[o];if(!this.findGroupItem(r.groupId)){this.handleCreateComment(r,!1);continue}}for(let o=this.items.length-1;o>=0;o--){const r=this.items[o];e.findIndex(i=>i.groupId===r.comment.groupId)===-1&&this.deleteItem(r.comment.id)}},100));this.scroller=new c5.default(i),this.scroller.disable(),this.editor.addListener("docChanged",this.handleDocChanged),this.items.forEach(this.setupGroupItem)}createItem(e){return new Fz(this.editor,this.commentsProvider,e)}insertItem(e){const o=super.insertItem(e);return o?(this.setupGroupItem(o),o):null}findInsertPos(e){const r=es(this.editor,this.commentsProvider).findIndex(i=>i.id===e.id);return r===-1||r>this.items.length?-1:r}setActiveItem(e){this.scrollToGroup(e)}handleCreateComment(e,o){if(Xs(e)){const s=this.findGroupItem(e.groupId);s&&s.childrenList.insertItem(e)}const r=this.findItem(e.id);g($2,!r,"comment group item has already exists");const i={children:[],...e};g($2,i.children,"not a comment group"),this.insertItem(i),this.scroller.refresh()}handleDeleteComment(e){for(let o=0;o<this.items.length;o++){const r=this.items[o];if(r.comment.id===e){r.childrenList.items.length===0?this.deleteItem(r.comment.id):r.deleteMainComment(e);return}if(r.childrenList.deleteItem(e)){r.commentCount===0&&this.deleteItem(r.comment.id);return}}}handleUpdateComment(e){if(Xs(e)){const r=this.commentsProvider.getComment(e.groupId),i=this.findItem(r.id);i&&i.handleUpdateChildComment(e);return}const o=this.findItem(e.id);o&&o.handleUpdateMainComment(e)}destroy(){this.editor.removeListener("docChanged",this.handleDocChanged),this.scroller.destroy(),this.items.forEach(e=>e.destroy())}}const Nz=S("mobile-comment-list"),{t:b8}=L;class $z extends ve.TypedEmitter{constructor(e,o){super();m(this,"root");m(this,"list");m(this,"mask");m(this,"pullInfoContainer");m(this,"handleRootClick",e=>{const o=e.target;g(Nz,o instanceof Element,"invalid target"),!(o.closest(".mobile-group-item-abstract")||o.closest(".mobile-group-item-list-container"))&&(this.hide(),this.emit("onCommentListClose"))});m(this,"hidePullInfo",Me.default(()=>{rt(this.pullInfoContainer,"active")},1e3*3));m(this,"handleReachBottom",()=>{this.showPullInfo("bottom")});m(this,"handleReachTop",()=>{this.showPullInfo("top")});m(this,"show",e=>{var o;rt(this.root,"hidden"),W(document.documentElement,"disabled-scroll"),(o=this.commentOptions)==null||o.controller.showCommentList(),queueMicrotask(()=>{this.list.refreshScroller(),e&&this.list.setActiveItem(e)})});m(this,"hide",()=>{W(this.root,"hidden"),rt(document.documentElement,"disabled-scroll")});this.editor=e,this.commentsProvider=o,this.root=k("div",["editor-mobile-comments-root"],null),this.mask=k("div",["mobile-comment-mask"],this.root);const r=k("div",["mobile-comment-groups-container"],this.root),i=k("div",["mobile-comment-groups-scroll-container"],r);this.list=new Pz(this.editor,this.commentsProvider,i,r),this.pullInfoContainer=this.createPullInfo(),this.commentsProvider.addListener(this),this.list.on("onReachBottom",this.handleReachBottom),this.list.on("onReachTop",this.handleReachTop),this.root.onclick=this.handleRootClick}onCreateComment(e,o){const r=this.commentsProvider.getComment(e);this.list.handleCreateComment(r,o)}onDeleteComment(e,o){this.list.handleDeleteComment(e)}onUpdateComment(e,o){const r=this.commentsProvider.getComment(e);this.list.handleUpdateComment(r)}get commentOptions(){return this.editor.getComponentOptions("comment")}createPullInfo(){const e=k("div",["mobile-comment-pull-info-container"],this.root);return k("div",["mobile-comment-pull-info"],e),e}showPullInfo(e){const o=b8(e==="bottom"?"comment.isLast":"comment.isFirst");this.pullInfoContainer.firstElementChild.textContent=o,W(this.pullInfoContainer,"active"),this.hidePullInfo()}destroy(){this.list.removeAllListeners(),this.list.destroy(),this.root.onclick=null}}function v8(n,t){const e=es(n,t),o=new Map;for(const r of e){const i=r8(n,r.groupId);if(!!i)if(o.has(i)){const s=o.get(i);O2(r).forEach(a=>{s==null||s.commentIds.add(a.id)})}else{const s=O2(r),l=new Set(s.map(a=>a.id));o.set(i,{commentIds:l,firstComment:r})}}return Array.from(o.entries()).map(([r,i])=>({blockId:r,...i}))}const Hz=S("mini-group-item");class jz{constructor(t,e){m(this,"root");m(this,"blockId");m(this,"comment");m(this,"miniCommentItem");m(this,"updateCommentItemCount",()=>{this.miniCommentItem.updateCount(this.commentCount)});this.editor=t,this.commentGroup=e,this.root=k("div",["mini-group-item"],null),this.comment=e.firstComment,this.miniCommentItem=new wz(this.comment.id,this.root),this.blockId=this.getBlockId(),setTimeout(()=>{this.alignToBlock()}),this.updateCommentItemCount()}getBlockId(){return r8(this.editor,this.comment.groupId)}get commentCount(){return this.commentGroup.commentIds.size}alignToBlock(){const t=this.getBlockId();if(!t)return;const e=this.editor.getBlockById(t);g(Hz,e,`The blockId: ${t} not exist in doc`);const o=this.editor.scrollContainer.getBoundingClientRect(),r=this.editor.scrollContainer.scrollTop,s=e.getBoundingClientRect().top-o.top+r;requestAnimationFrame(()=>{this.root.style.transform=`translateY(${s}px)`})}destroy(){this.root.remove()}}class Uz extends Qu{constructor(e,o,r){super(e,o,r,v8(e,o),{});m(this,"fixListOps",Me.default(()=>{this.items.forEach(e=>{e.alignToBlock()})},100));m(this,"handleDocChanged",Me.default(()=>{this.updateMiniCommentsGroup()},100));m(this,"updateMiniCommentsGroup",()=>{const e=v8(this.editor,this.commentsProvider);this.reloadList(e)});this.editor=e,this.commentsProvider=o,this.editor.addListener("docChanged",this.handleDocChanged),this.editor.addListener("resize",this.fixListOps)}createItem(e){return new jz(this.editor,e)}findInsertPos(){return-1}handleCreateComment(e,o){this.updateMiniCommentsGroup()}handleDeleteComment(e){this.updateMiniCommentsGroup()}destroy(){this.editor.removeListener("docChanged",this.handleDocChanged),super.destroy(),this.removeAllListeners()}}const zz=S("mini-comments-list");class Vz extends ve.TypedEmitter{constructor(e,o){super();m(this,"list");m(this,"root");m(this,"createList",()=>{const e=k("div",["comment-groups-container"],this.root);return this.editor.domEvents.addEventListener(e,"click",this.handleListContainerClick),new Uz(this.editor,this.commentsProvider,e)});m(this,"handleListContainerClick",(e,o)=>{const r=o.target;g(zz,r instanceof HTMLElement,"The target is not a valid html element");const i=r.closest(".mini-comment-item");i&&this.emit("onItemClick",i.id)});this.editor=e,this.commentsProvider=o,this.root=k("div",["editor-mini-comment-root"],null),this.list=this.createList(),this.commentsProvider.addListener(this)}onCreateComment(e,o){const r=this.commentsProvider.getComment(e);this.list.handleCreateComment(r,o)}onDeleteComment(e,o){this.list.handleDeleteComment(e)}onUpdateComment(e,o){}show(){rt(this.root,"hidden")}hide(){W(this.root,"hidden")}destroy(){this.list.destroy(),this.removeAllListeners()}}function y8(n,t,e){if(!t.start.isSimple()||!t.end.isSimple())return;const o=t.block,r=ke(n,o,t.start.offset,t.end.offset),i=`comment-${e.id.toLocaleLowerCase()}`,s=e.id;uA(n,o,r,i,s)}function Wz(n,t,e){const o=cr(n).map(s=>s.block),r=L2(n,o),i=a1({editor:n,abstract:r});return n.undoManager.runInGroup(()=>{cr(n,{simpleBlockOnly:!0}).forEach(a=>{!et(n,a.block)||y8(n,a,i)});const l=Yr();e.localCreateComment(i,l)}),i}class qz{constructor(t,e){m(this,"id","CommentsCommandProvider");this.provider=t,this.editorComments=e}getAvailableCommands(t,e,o){const r=t.selection.range;if(et(t,e)&&!o.isCollapsed()&&r.isSimple()){const i=it(e),s=Dt(e),l=Lo(t,e);return[{id:"add-comment",name:L.t("comment.command"),blockId:i,blockType:s,blockKind:l,groupIndex:1e3,icon:cc}]}return[]}hideToolbar(t){const e=t.findCustom("toolbar-handler");e==null||e.disableTextToolbar(),e==null||e.hide(),setTimeout(()=>{e==null||e.enableTextToolbar()},300)}executeRangeCommand(t,e,o,r,i){if(o.id==="add-comment"){this.editorComments.showCommentList();const s=Wz(t,e,this.provider);return i["add-comment"]=s,this.hideToolbar(t),!0}return!1}}class k8{constructor(t,e){m(this,"commentList",null);m(this,"mobileCommentList",null);m(this,"miniCommentList");m(this,"showComment",(t,e)=>{var o,r;t==="mini"&&this.miniCommentList.show(),t==="mobile"&&((o=this.mobileCommentList)==null||o.show(e)),t==="web"&&((r=this.commentList)==null||r.show(e))});m(this,"showCommentList",t=>{this.isMobile?this.showComment("mobile",t):this.showComment("web",t)});m(this,"handleCommentListClose",()=>{this.showComment("mini")});m(this,"handleOnSelectComment",()=>{this.showComment("web")});m(this,"handleMiniCommentItemClick",t=>{this.showCommentList(t)});this.editor=t,this.provider=e,t.editorCommandProviders.registerCommandProvider(new qz(e,this)),t.blockHooks.push(new lz(this.provider,this)),this.isMobile?(this.mobileCommentList=new $z(this.editor,this.provider),this.mobileCommentList.on("onCommentListClose",this.handleCommentListClose)):(this.commentList=new Rz(this.editor,this.provider),this.commentList.on("onSelectComment",this.handleOnSelectComment)),this.miniCommentList=new Vz(this.editor,this.provider),this.miniCommentList.on("onItemClick",this.handleMiniCommentItemClick),this.editor.input.addHandler(new cz)}get commentProvider(){return this.provider}get isMobile(){return Ze.isMobile}destroy(){var t,e;(t=this.commentList)==null||t.destroy(),(e=this.mobileCommentList)==null||e.destroy(),this.miniCommentList.destroy()}mount(t){var e;t.container&&this.commentList&&t.container.append((e=this.commentList)==null?void 0:e.root),t.miniContainer&&t.miniContainer.append(this.miniCommentList.root),t.mobileContainer&&this.mobileCommentList&&t.mobileContainer.append(this.mobileCommentList.root)}}const Got="",Gz={comment:{count:"\u6279\u6CE8 ({num})",hide:"\u9690\u85CF\u6279\u6CE8",show:"\u663E\u793A\u6279\u6CE8",reply:"\u56DE\u590D",quicklyReply:"\u56DE\u590D...",send:"\u786E\u8BA4",placeholder:"\u6DFB\u52A0\u6279\u6CE8...",replyPlaceholder:"\u56DE\u590D\u6216@\u4ED6\u4EBA",edit:"\u7F16\u8F91",delete:"\u5220\u9664",image:"\u56FE\u7247",sendTitle:"\u6309Enter\u53D1\u9001\u6279\u6CE8",replyTitle:"\u6309Enter\u56DE\u590D\u6279\u6CE8",isFirst:"\u5DF2\u7ECF\u662F\u7B2C\u4E00\u6761\u6279\u6CE8",isLast:"\u5DF2\u7ECF\u662F\u6700\u540E\u4E00\u6761\u6279\u6CE8",more:"\u66F4\u591A",comment:"\u6279\u6CE8",command:"\u6279\u6CE8",quickMenuCommand:"\u6DFB\u52A0\u6279\u6CE8"}},Zz={comment:{count:"Annotations ({num})",hide:"Hide Annotations",show:"Show Annotations",reply:"Reply",quicklyReply:"Reply...",send:"Confirm",placeholder:"Add a annotation...",replyPlaceholder:"Add annotations or @ others",edit:"Edit",delete:"Delete",image:"Image",sendTitle:"Press Enter to post annotation",replyTitle:"Press Enter to reply to annotation",isFirst:"This is already the first comment",isLast:"This is already the last comment",more:"More",comment:"Annotation",command:"Annotation",quickMenuCommand:"Add annotation"}},Qz={comment:{count:"\u6CE8\u91C8 ({num})",hide:"\u6CE8\u91C8\u3092\u975E\u8868\u793A",show:"\u6CE8\u91C8\u3092\u8868\u793A",reply:"\u8FD4\u4FE1",quicklyReply:"\u8FD4\u4FE1...",send:"\u78BA\u8A8D",placeholder:"\u6CE8\u91C8\u3092\u8FFD\u52A0...",replyPlaceholder:"\u8FD4\u4FE1\u307E\u305F\u306F\u30E1\u30F3\u30B7\u30E7\u30F3(@)",edit:"\u7DE8\u96C6",delete:"\u524A\u9664",image:"\u753B\u50CF",sendTitle:"Enter\u3092\u62BC\u3057\u3066\u6CE8\u91C8\u3092\u9001\u4FE1",replyTitle:"Enter\u3092\u62BC\u3057\u3066\u6CE8\u91C8\u3092\u8FD4\u4FE1",isFirst:"\u6700\u521D\u306E\u6CE8\u91C8\u3067\u3059",isLast:"\u6700\u5F8C\u306E\u6CE8\u91C8\u3067\u3059",more:"\u305D\u306E\u4ED6",comment:"\u6CE8\u91C8",command:"\u6CE8\u91C8",quickMenuCommand:"\u6CE8\u91C8\u3092\u8FFD\u52A0"}};L.mergeLang({"zh-CN":Gz,"en-US":Zz,"ja-JP":Qz});class w8{renderText(t,e,o){const r=[],i={};return Object.entries(o).forEach(([s,l])=>{s.startsWith("comment-")&&(r.push("comment"),i[s]=l)}),{classes:r,attributes:i}}renderBlock(t,e,o){const r=o.comments;if(!r||r.length===0)return{};const i=["comment"],s={};return r.forEach(l=>{s[`comment-${l.toLocaleLowerCase()}`]=l}),{classes:i,attributes:s}}updateBlock(t,e,o,r){const i=r.comments;rt(o,"comment"),Array.from(o.attributes).forEach(s=>{s.name.startsWith("comment-")&&o.removeAttribute(s.name)}),!(!i||i.length===0)&&(W(o,"comment"),i.forEach(s=>{o.setAttribute(`comment-${s.toLocaleLowerCase()}`,s)}))}}class Yz{constructor(t){m(this,"handleUpdateCompositionText",(t,e,o,r,i)=>{const s=t.getFocusedBlock(),l=t.getFirstBlock();s===l&&this.applyPlaceholder(t)});m(this,"handleSelectionChange",t=>{this.applyPlaceholder(t)});m(this,"applyPlaceholder",t=>{const e=t.getFirstBlock();Zf(t,e,L.t("comment.replyPlaceholder"))});this.applyPlaceholder(t),t.addListener("selectionChanged",this.handleSelectionChange)}}function Jz(n,t,e){const o=n.getBlockData(t),r=o.comments;if((r==null?void 0:r.indexOf(e))!==-1){const s=new Set(r);s.delete(e),n.updateBlockData(t,{comments:Array.from(s)})}const i=o.text;if(!!i&&et(n,t)){const s=xg(i,`comment-${e.toLocaleLowerCase()}`,e);Ca.default(i,s)||n.setBlockText(t,s)}}const Kz=S("editor-comment");function Xz(n){const t=n.getCustom("editor-comments");if(g(Kz,t,"the editor comment not exist"),t.showCommentList(),n.selection.range.isCollapsed()){const s=n.selection.startBlock,l=_i(s);if(l.length>=2){const{containerId:a}=l[l.length-1],d=nt(sr(n,a));if(d&&Dt(d)==="code"){M2(n,d,t.commentProvider);return}}M2(n,s,t.commentProvider);return}const e=cr(n,{simpleBlockOnly:!0}),o=e.map(s=>s.block),r=L2(n,o),i=a1({editor:n,abstract:r});n.undoManager.runInGroup(()=>{e.forEach(l=>{et(n,l.block)?y8(n,l,i):t8(n,l.block,i)});const s=Yr();t.commentProvider.localCreateComment(i,s)})}const H2=S("text-styles");function tV(n){const t=o=>{if(!o.attributes)return new Map;const r=Object.entries(o.attributes).filter(([i])=>!!i.startsWith("style-"));return new Map(r)};if(n.length===0)return new Map;let e=t(n[0]);for(let o=1;o<n.length;o++){const r=t(n[o]);e=new Map(Array.from(e.entries()).filter(([i,s])=>r.get(i)===s))}return e}function eV(n,t,e,o,r){g(H2,e.isSimple(),"invalid range");const{start:i,end:s}=e;g(H2,i.blockId===s.blockId&&i.blockId===it(t),"invalid range"),g(H2,o.startsWith("style-"),"invalid style");let a=n.getBlockText(t);return o==="style-sub"?a=Jl(i.offset,s.offset-i.offset,a,"style-super",r,{ignoreValue:!0}):o==="style-super"&&(a=Jl(i.offset,s.offset-i.offset,a,"style-sub",r,{ignoreValue:!0})),r===!1||r===void 0||r===null?a=Jl(i.offset,s.offset-i.offset,a,o,void 0,{ignoreValue:!0}):a=Pa(i.offset,s.offset-i.offset,a,o,r),n.setBlockText(t,a),a}const nV=`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
504
504
|
<line x1="3.5" y1="0.5" x2="3.5" y2="15.5" stroke="currentColor"/>
|
|
505
505
|
<path d="M4 8L7.5 8C9.433 8 11 6.433 11 4.5V4.5C11 2.567 9.433 1 7.5 1L4 1" stroke="currentColor"/>
|
|
506
506
|
<path d="M4 15L9.5 15C11.433 15 13 13.433 13 11.5V11.5C13 9.567 11.433 8 9.5 8L4 8" stroke="currentColor"/>
|