@ones-editor/editor 0.0.3-beta.243 → 0.0.3-beta.245
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)`;t+=i.horizontalOffset,o+=i.verticalOffset;const p=h.getMaxHorizontalScroll(),C=h.getHorizontalScroll();t>p&&(t=p);const v=t-C,B=h.getMaxVerticalScroll(),S=h.getVerticalScroll();i.verticalOffset||(S<o?o-=h.getClientHeight()*3/4:o-=h.getClientHeight()*1/4),o>B&&(o=B);const x=o-S,_=Math.abs(Math.round(v/1e3*i.speed)),M=Math.abs(Math.round(x/1e3*i.speed));let H=_>M?_:M;return H<i.minDuration?H=i.minDuration:H>i.maxDuration&&(H=i.maxDuration),new Promise((z,Z)=>{v===0&&x===0&&z(!0),$r.remove(h.element,!0);let ee;const fe=()=>{qt(),cancelAnimationFrame(ee),z(!1)};$r.add(h.element,fe);const ve=Rn=>Rn.preventDefault(),ze=i.cancelOnUserAction?fe:ve,He=i.cancelOnUserAction?{passive:!0}:{passive:!1},Ke=["wheel","touchstart","keydown","mousedown"],qt=()=>{Ke.forEach(Rn=>{h.element.removeEventListener(Rn,ze,He)})};Ke.forEach(Rn=>{h.element.addEventListener(Rn,ze,He)});const Jn=Date.now(),Ht=()=>{const Rn=Date.now()-Jn,Tr=Rn/H,kn=Math.round(C+v*i.easing(Tr)),un=Math.round(S+x*i.easing(Tr));Rn<H&&(kn!==t||un!==o)?(h.scrollTo(kn,un),ee=requestAnimationFrame(Ht)):(h.scrollTo(t,o),cancelAnimationFrame(ee),qt(),$r.remove(h.element,!1),z(!0))};ee=requestAnimationFrame(Ht)})}function ks(n,e,t){return n.left<=e&&e<=n.right&&n.top<=t&&t<=n.bottom}function qE(n){const e="\xA0";if(!n)return"";if(n===" ")return e;let t=n;return t.startsWith(" ")&&(t=e+t.substr(1)),t.endsWith(" ")&&(t=t.substr(0,t.length-1)+e),t=t.replace(/ {2}/g,` ${e}`),t}function w5(n){if(!/["'&<>]/.exec(n))return n;const o={'"':""","'":"'","&":"&","<":"<",">":">"};return n.split("").map(l=>o[l]||l).join("")}function B5(n){const e=document.getElementById(n);e&&e.remove()}function E5(n,e){const t=document.getElementById(e);if(t)return t.textContent=n,t;const o=document.createElement("style");return o.id=e,o.textContent=n,document.head.append(o),o}function ka(n){const e="custom-cursor-style";if(n){const t=`body * { cursor: ${n} !important}`;E5(t,e)}else B5(e)}const x5=3,I5=D("drag-drop");class T5{constructor(e){m(this,"dragStarted",!1);m(this,"mouseDownEvent",null);m(this,"_dragOffsetX",0);m(this,"_dragOffsetY",0);m(this,"handleMouseDown",e=>{e.preventDefault(),e.stopPropagation(),this.mouseDownEvent=e;const t=this.options.elem.getBoundingClientRect();this._dragOffsetX=this.mouseDownEvent.x-t.left,this._dragOffsetY=this.mouseDownEvent.y-t.top,this.bindEvents()});m(this,"handleMouseMove",e=>{var i;e.preventDefault(),e.stopPropagation(),g(I5,this.mouseDownEvent,"no mouse down event");const t=e.x-this.mouseDownEvent.x,o=e.y-this.mouseDownEvent.y;if(this.dragStarted){this.onDragging(e,t,o);return}const r=(i=this.options.minThreshold)!=null?i:x5;(Math.abs(t)>=r||Math.abs(o)>=r)&&this.onDragStart(this.mouseDownEvent)});m(this,"handleMouseUp",e=>{if(e.button===0){g(I5,this.mouseDownEvent,"no mouse down event");const t=e.x-this.mouseDownEvent.x,o=e.y-this.mouseDownEvent.y;this.onDragEnd(e,t,o),e.preventDefault(),e.stopPropagation()}});this.options=e,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(e){this.dragStarted=!0,this.options.cursor&&ka(this.options.cursor),this.options.onDragStart(this,e,this.options.elem)}onDragging(e,t,o){this.options.onDragging(this,e,this.options.elem,t,o)}onDragEnd(e,t,o){this.options.cursor&&ka(null),this.dragStarted&&this.options.onDragEnd(this,e,this.options.elem,t,o),this.unbindEvents(),this.dragStarted=!1}destroy(){this.unbindEvents(),this.untrackEvents()}}function Fm(n){return new T5(n)}const GE=D("character");function S5(n,e){for(let t=0;t<e.length;t++){const o=e[t][0],r=e[t].length>1?e[t][1]:null;if(r===null&&n===o||r!==null&&n>=o&&n<=r)return!0}return!1}function D5(n){const e=n.charAt(0);return e>="0"&&e<="9"}function L5(n){const e=n.charAt(0);return e>="a"&&e<="z"||e>="A"&&e<="Z"||e.toUpperCase()!==e.toLowerCase()?!0:RegExp(/^\p{L}/,"u").test(e)}function rh(n){const e=[[9,13],[32],[160]];return S5(n.charCodeAt(0),e)}function M5(n){const e=[[12352,12687],[13056,13183],[13312,15661],[19968,40959],[63744,64255],[44032,55215]];return S5(n.charCodeAt(0),e)}function Pm(n,e){let t=e;return g(GE,t.length===1,"invalid char length"),t==="]"&&(t="\\]"),t==="\\"&&(t="\\\\"),n.replace(new RegExp(`^[${t}]+|[${t}]+$`,"g"),"")}const Hr=navigator.userAgent;function zl(){const n=navigator.userAgent.toLowerCase();return n.indexOf("safari")!==-1&&!(n.indexOf("chrome")>-1)}function wa(){return navigator.userAgent.toLowerCase().indexOf("firefox")>-1}const Zt={isAndroid:!!Hr.match(/Android/i),isIOS:!!Hr.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/i),isIPad:!!Hr.match(/iPad/i),isIPhone:!!Hr.match(/iPhone/i),isLinux:!!Hr.match(/Linux/i),isMac:!!Hr.match(/Macintosh/i),isMobile:!!Hr.match(/AppleWebKit.*Mobile.*/i),isWindows:!!Hr.match(/Window/i),isIe:!!Hr.match(/msie|trident/i),isSafari:zl(),isFirefox:wa(),isMobileSafari:!1};Zt.isMobileSafari=Zt.isMobile&&Zt.isSafari;function Nm(n){return n?n.length===1||n==="Process"||n==="Unidentified"&&Zt.isAndroid:!1}function R5(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 ZE(n){return R5(n.key)}function QE(n){switch(n){case"ArrowUp":case"ArrowLeft":case"Home":case"PageUp":return!0;default:return!1}}function ws(n){return n.ctrlKey||n.altKey||n.shiftKey||n.metaKey}function YE(n){return n.key?!!(n.ctrlKey||n.metaKey||n.altKey):!1}function O5(n){return Zt.isMac?n.metaKey&&!n.ctrlKey:!n.metaKey&&n.ctrlKey}function JE(n){return O5(n)&&!n.altKey&&!n.shiftKey}function KE(n){return!n.metaKey&&!n.ctrlKey&&!n.shiftKey&&n.altKey}function _5(n){return!ws(n)&&n.key==="Enter"}function XE(n){return n.key==="Enter"&&n.shiftKey&&!n.altKey&&!n.ctrlKey&&!n.metaKey}function $m(n){return!ws(n)&&n.key==="Escape"}function ex(n){return!ws(n)&&n.key==="Delete"}function F5(n){return!ws(n)&&n.key==="Backspace"}function tx(n){return!ws(n)&&n.key==="Tab"}function nx(n){return n.shiftKey&&n.key==="Tab"&&!n.ctrlKey&&!n.metaKey}function so(n){if(!n)return"";if(Zt.isMac){const e=n.replace("CtrlOrCmd","\u2318").replace("Shift","\u21E7").replace("Ctrl","\u2303").replace("Alt","\u2325").replace(/\+(?!$)/gm,""),t={"\u2318":4,"\u21E7":3,"\u2325":2,"\u2303":1};return e.split(/(?=[\s\S])/u).sort((r,i)=>{var a,d;const s=(a=t[r])!=null?a:5,l=(d=t[i])!=null?d:5;return s-l}).map(r=>r in t?`${r}+`:r).join("")}return n.replace("CtrlOrCmd","Ctrl")}function P5(n){const e={ctrl:!1,alt:!1,shift:!1,cmd:!1,key:""},t=n.toLocaleUpperCase().split("+");for(let o=0;o<t.length;o++){const r=t[o];r==="CTRL"||r==="CONTROL"?e.ctrl=!0:r==="ALT"||r==="OPTION"?e.alt=!0:r==="SHIFT"?e.shift=!0:r==="CMD"||r==="COMMAND"?e.cmd=!0:r==="CMDORCTRL"||r==="CTRLORCMD"?Zt.isMac?e.cmd=!0:e.ctrl=!0:r==="SPACE"?e.key=" ":e.key=r.substring(0,1)+r.substring(1).toLocaleLowerCase()}return e}function rr(n,e){const t=P5(e);return t.ctrl!==n.ctrlKey||t.alt!==n.altKey||t.shift!==n.shiftKey||Zt.isMac&&t.cmd!==n.metaKey?!1:t.key.length===1?t.key===n.key.toUpperCase():t.key.toUpperCase()===n.key.toUpperCase()}function Hm(n,e){return TB.stringifyUrl({url:n,query:e})}function Ri(n){return typeof n=="string"?ga.Base64.encode(n,!0):ga.Base64.fromUint8Array(n,!0)}function Ba(n){return ga.Base64.decode(n)}function ox(n){return ga.Base64.toUint8Array(n)}function jm(n){return new Blob([ga.Base64.toUint8Array(n)])}const rx=Li.init([Li.classModule,Li.styleModule,Li.datasetModule,Li.attributesModule,Li.propsModule]);function Ea(n,e){const t=Li.toVNode(n),o=Li.toVNode(e);rx(t,o)}async function Um(n,e){const t=new FileReader,o=new Promise((i,s)=>{t.onload=i,t.onerror=s});return t.readAsDataURL(new Blob([n],{type:e})),await o,t.result}async function Vl(n){const e=new FileReader,t=new Promise((r,i)=>{e.onload=r,e.onerror=i});return e.readAsDataURL(n),await t,e.result}function ix(n,...e){const t=n.tagName.toLowerCase();for(let o=0,r=e.length;o<r;o++)if(t===e[o].toLowerCase())return!0;return!1}function lo(n,e){let t=n;for(;t;){const o=window.getComputedStyle(t);if(e!=null&&e.horizontal){if(/auto|scroll/i.test(o.overflowX))break}else if(/auto|scroll/i.test(o.overflowY))break;t=t.parentElement}return(!t||ix(t,"body"))&&(t=document.documentElement),t}function N5(n){n.preventDefault(),n.stopPropagation()}function $5(n){if(document.querySelector(`.editor-disable-scroll[data-scroll-id="${n}"]`))return;const e=k("div",["editor-disable-scroll"],null);e.setAttribute("data-scroll-id",n),e.addEventListener("wheel",N5,{passive:!1}),document.body.appendChild(e)}function H5(n){const e=document.querySelector(`.editor-disable-scroll[data-scroll-id="${n}"]`);e&&(e.removeEventListener("wheel",N5),e.remove())}function zm(n,e,t){const o=new Blob([n]),r=new File([o],t,{type:e});return URL.createObjectURL(r)}function ih(n){const e=document.createElement("template");if("content"in e)return e.innerHTML=n,document.importNode(e.content,!0);const t=document.createDocumentFragment(),o=document.createElement("div");for(o.innerHTML=n;o.firstChild;)t.appendChild(o.firstChild);return t}function j5(n){const e=document.createElement("div");return e.appendChild(n),e.innerHTML}function U5(n){let e=n.getPropertyValue("font");if(e)return e;const t=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 e=`${t} ${o} ${r} ${i} ${s}`.replace(/ +/g," ").trim(),e}function sh(n,e){const o=(sh.canvas||(sh.canvas=document.createElement("canvas"))).getContext("2d");return o?(typeof e=="string"?e?o.font=e:o.font=U5(window.getComputedStyle(document.body)):e instanceof Element&&(o.font=U5(window.getComputedStyle(e))),o.measureText(n).width+4):200}const sx=D("editor-clipboard");async function lx(n,e){if(e.clipboardData){const t=e.clipboardData;for(const o of n)t.setData(o.type,o.data);return!0}return!1}async function Vm(n){try{const e={};n.forEach(o=>{e[o.type]=o.data});const t=new ClipboardItem(e);return await navigator.clipboard.write([t]),!0}catch(e){return sx.error(e),!1}}function Wl(n,e){return new Promise((t,o)=>{const r=document.createElement("input");r.type="file",r.style.display="none",e!=null&&e.multiple&&(r.multiple=!0),r.accept=n,r.onchange=()=>{const i=r.files;if(i){const s=e!=null&&e.multiple?Array.from(i):i[0];t(s)}r.remove()},r.onerror=i=>{o(i),r.remove()},r.click()})}function lh(n){return Array.isArray(n)?n.every(e=>e instanceof File):!1}function xa(n){const e=n;if(!e)return"";const t=e.lastIndexOf(".");return t===-1?"":e.slice(t+1)}function ch(n,e){const t=document.createElement("a");t.setAttribute("download",`${e||""}`),t.setAttribute("href",`${n}`),t.click(),t.remove()}const z5=D("auto-scroll");function V5(n,e){return!(n.scrollHeight===n.clientHeight||e==="top"&&n.scrollTop===0||e==="bottom"&&n.scrollTop+n.clientHeight===n.scrollHeight||e==="left"&&n.scrollLeft===0||e==="right"&&n.scrollLeft+n.clientWidth===n.scrollWidth)}function W5(n,{direction:e,step:t}){let o=null;const r=e==="left"||e==="right",i=()=>V5(n,e)?(r?e==="left"?n.scrollLeft=Math.max(n.scrollLeft-t,0):n.scrollLeft=Math.min(n.scrollLeft+t,n.scrollWidth):e==="top"?n.scrollTop=Math.max(n.scrollTop-t,0):n.scrollTop=Math.min(n.scrollTop+t,n.scrollHeight),o=requestAnimationFrame(i),o):(z5.debug("No need for scroll"),null);return o=requestAnimationFrame(i),()=>{o&&cancelAnimationFrame(o)}}class ah{constructor(e){m(this,"cancelScroll",null);m(this,"options");m(this,"scrollDomInfo");m(this,"scrolling",!1);m(this,"getScrollingDirection",e=>{const{x:t,y:o}=e,{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&&t<=s+a.left?"left":a.right&&t>=l-a.right?"right":null});m(this,"handleMouseMove",e=>{var s;const{scrollElement:t,step:o=10,onDirectionChange:r}=this.options,i=this.getScrollingDirection(e);if(i){if(this.scrolling)return;z5.debug(`scroll direction: ${i}`),this.cancelScroll=W5(t,{direction:i,step:o}),r==null||r(i),this.scrolling=!0}else(s=this.cancelScroll)==null||s.call(this),this.scrolling=!1});this.options=e,this.scrollDomInfo=this.getScrollDomInfo()}getScrollDomInfo(){const{scrollElement:e}=this.options,t=e.getBoundingClientRect(),o=t.top,r=t.left,i=t.bottom,s=t.right;return{left:r,top:o,right:s,bottom:i}}active(){const{trackMouseEvent:e="mousemove"}=this.options;window.addEventListener(e,this.handleMouseMove,!0)}inactive(){var t;const{trackMouseEvent:e="mousemove"}=this.options;window.removeEventListener(e,this.handleMouseMove,!0),(t=this.cancelScroll)==null||t.call(this),this.scrolling=!1}}function q5(n,e){if(n===0)return"0 Bytes";const t=1024,o=e||2,r=["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"],i=Math.floor(Math.log(n)/Math.log(t));return`${parseFloat((n/t**i).toFixed(o))} ${r[i]}`}function Ia(n,e){let t=`${n}`;const o=e-t.length;for(let r=0;r<o;r++)t=`0${t}`;return t}const{t:Bs}=L;function Wm(n,e){const t=new Date(n).getTime()+864e5*e;return new Date(t)}function cx(n,e){const t=n,o=Math.floor(e/12),r=e-o*12;return o&&t.setFullYear(t.getFullYear()+o),r&&t.setMonth(t.getMonth()+r),t}function ax(n,e){return Wm(n,e)}function qm(n,e){const t=new Date(n),o=new Date(e);return t.getDate()===o.getDate()&&t.getMonth()===o.getMonth()&&t.getFullYear()===o.getFullYear()}function G5(n){const e=new Date,t=new Date(n);return qm(e,t)}function Z5(n){const e=Wm(new Date,-1);return qm(e,n)}function ux(n,e){return Math.round((n.getTime()-e.getTime())/864e5)}function Gm(n,e){const t=new Date(n);if(e){const o=t.getFullYear(),r=t.getMonth()+1,i=t.getDate(),s=t.getHours(),l=t.getMinutes();let a=e;return a=a.replace("YYYY",`${o}`),a=a.replace("MM",Ia(r,2)),a=a.replace("DD",Ia(i,2)),a=a.replace("M",`${r}`),a=a.replace("D",`${i}`),a=a.replace("hh",Ia(s,2)),a=a.replace("mm",Ia(l,2)),a=a.replace("h",`${s}`),a=a.replace("m",`${l}`),a}return n.toLocaleDateString()}function Zm(n,e){const t=new Date(n),o=new Date;if(t.getTime()-o.getTime()>10*1e3)return L.t("date.dateFromFuture");if(G5(t)){const i=(o.getTime()-n.getTime())/1e3;if(i<10*60)return Bs("date.dateJustNow");if(i<60*60)return Bs("date.dateMinutesAgo",{num:`${Math.floor(i/60)}`});const s=Math.floor(i/60/60);return s===1?Bs("date.date1HourAgo"):Bs("date.dateHoursAgo",{num:`${s}`})}if(Z5(n))return Bs("date.dateYesterday");const r=Math.floor((o.getTime()-n.getTime())/1e3/24/60/60)+1;return r<14?Bs("date.dateDaysAgo",{num:`${r}`}):r<28?Bs("date.dateWeeksAgo",{num:`${Math.round(r/7)}`}):Gm(n,e)}function Qm(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function dx(n,e,t){return n.replace(new RegExp(Qm(e),"g"),t)}function hx(n,e,t){return n.replace(new RegExp(Qm(e),"gi"),t)}function Q5(n,e,t){const r=document.createElement("canvas").getContext("2d");if(!r)return null;if(r.font=String(e),r.measureText(n).width>t){let s=0,l=0;for(;l<t;)l=r.measureText(n.slice(0,s)).width,s++;return`${n.slice(0,s-2)}...`}return n}const Y5=/[\u3040-\u30ff\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff\uff66-\uff9f\uAC00-\uD7AF]/,J5=" -\x7F0-9!-/:-@[-`{-~\u0370-\u03FF\u0400-\u04FF",fx=new RegExp(`[${J5}]`),mx=new RegExp(`([^(${J5})])`,"g"),K5=/(\ud83c[\udf00-\udfff])|(\ud83d[\udc00-\ude4f\ude80-\udeff])|[\u2600-\u2B55]/;function X5(n){return n.length===0?0:n.split("").reduce((e,t)=>{const o=(e<<5)-e+t.charCodeAt(0);return o&o},0)}function gx(n,e=1){var o,r;return(r=((o=Array.from(n))==null?void 0:o.filter(i=>Y5.test(i))).slice(-e))==null?void 0:r.join("")}function px(n,e=1){var r;const t=Array.from((r=n==null?void 0:n.replace(mx,""))==null?void 0:r.split(/\s/));return t.reduce((i,s,l)=>{var a,d;return l===t.length-1&&i.length<e?`${i}${(a=s==null?void 0:s.slice(0,e-i.length))!=null?a:""}`:`${i}${(d=s[0])!=null?d:""}`},"").slice(0,e)}function Cx(n,e=1){var o,r;return(r=((o=Array.from(n))==null?void 0:o.filter(i=>K5.test(i))).slice(-e))==null?void 0:r.join("")}function bx(n,e=1){var t,o;return(o=(t=Array.from(n))==null?void 0:t.slice(0,e))==null?void 0:o.join("")}function uh(n,e=1){if(!n||n.length===0)return"";const t=Y5.test(n),o=fx.test(n),r=K5.test(n);switch(!0){case t:return gx(n,e);case o:return px(n,e);case r:return Cx(n,e);default:return bx(n,e)}}var e4=(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))(e4||{});function dh(n){const e=Object.values(e4),t=Math.abs(typeof n=="string"&&n.trim()?X5(n.trim()):0)%e.length;return e[t]}const t4=D("container-children");function mt(n){const e=Array.from(n.querySelectorAll(":scope > .container-blocks > div[data-type=editor-block]"));return g(t4,e.length>0,"container have not any child block"),e}function yt(n){const e=n.querySelector(":scope > .container-blocks > div[data-type=editor-block]");return g(t4,e,"container have not any child block"),e}function Qt(n){const e=mt(n);return e[e.length-1]}function To(n){return mt(n).length}function jr(n,e){return mt(n)[e]}const So=D("block-dom");function Es(n){return n instanceof HTMLDivElement?n.getAttribute("data-type")==="editor-block":!1}function n4(n){return n instanceof HTMLElement&&n.getAttribute("data-type")==="block-tools"}function o4(n){W(n,"block-hidden")}function r4(n){re(n,"block-hidden")}function hh(n){return!xe(n,"block-hidden")}function ie(n){const{id:e}=n;return g(So,e,"no block id"),e}function Se(n){const e=n.getAttribute("data-block-type");return g(So,e,"invalid block dom, no data-type"),e}function ne(n){const e=n instanceof Element?n:n.parentElement;if(!e)return null;const t=e.closest("div[data-type=editor-block]");return t||null}function xs(n){const e=n instanceof Element?n:n.parentElement;if(!e)return null;const t=e.closest("div[data-type=editor-block]:not(:scope)");return t||null}function oe(n){const e=n.closest("div[data-type=editor-container]");return g(So,e,"failed to get block container"),e}function Le(n){const e=n.querySelector(":scope >div[data-type=block-content]");return g(So,e,"no block content"),e}function tt(n){let e=n.querySelector(":scope >div[data-type=block-tools]");return e||(e=k("div",[],n),e.setAttribute("data-type","block-tools")),g(So,e,"no block tools"),e}function fh(n){const e=n.querySelector(":scope >div[data-type=block-tools]");return e||null}function i4(n){let e=n.querySelector(":scope > div[data-type=block-background]");return e||(e=k("div",[],n),e.setAttribute("data-type","block-background")),e}function s4(n,e,t){const o=n.editorDecorators.decorateBlock(e,t),{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,e,t);return l.classes&&W(s,...l.classes),l.attributes&&Object.entries(l.attributes).forEach(([a,d])=>{s.setAttribute(a,d)}),l.styles&&Object.entries(l.styles).forEach(([a,d])=>{s.style.setProperty(a,d)}),s}function Is(n,e){const t=k(e,[],null);return t.setAttribute("data-type","block-content"),n&&n.appendChild(t),t}function l4(n){const e=k("span",[`${n.type}-box`],null);return e.setAttribute("data-type","editor-box"),e.setAttribute("data-box-type",n.type),e.id=n.id,e}function Ta(n){const e=n.getAttribute("data-box-type");return g(So,e,"not a valid box element, no type"),e}function Ym(n){return n instanceof HTMLSpanElement?n.getAttribute("data-type")==="editor-box":!1}function c4(n){const{id:e}=n;return g(So,e,"no box id"),e}function Jm(n){const e=n instanceof Element?n:n.parentElement;if(!e)return null;const t=e.closest("span[data-type=editor-box]");return t||null}function a4(n){n.innerHTML="",k("span",["box-space-start"],n,va);const e=k("span",[],n);return e.setAttribute("data-type","box-content"),k("span",["box-space-start"],n,va),e}function Km(n){const e=n.querySelector("span[data-type=box-content]");return g(So,e,"invalid box dom, no content"),e}function u4(n,e){const t=k("span",[`${n}-insertion`],null);return t.setAttribute("data-type","editor-insertion"),t.setAttribute("data-insertion-id",e),t}function d4(n,e){return n.rootContainer.querySelector(`[data-insertion-id=${e}]`)}function h4(n){n.innerHTML="",k("span",["insertion-space-start"],n,va);const e=k("span",[],n);return e.setAttribute("data-type","insertion-content"),k("span",["insertion-space-start"],n,va),e}function Xm(n){const e=n.querySelector("span[data-type=insertion-content]");return g(So,e,"invalid insertion-child dom, no content"),e}function at(n){let e=n.previousElementSibling;for(;e;){if(Es(e))return e;e=e.nextElementSibling}return null}function Qe(n){let e=n.nextElementSibling;for(;e;){if(Es(e))return e;e=e.nextElementSibling}return null}function Ts(n){let e=n.previousElementSibling;for(;e;){if(Es(e)&&hh(e))return e;e=e.previousElementSibling}return null}function Ss(n){let e=n.nextElementSibling;for(;e;){if(Es(e)&&hh(e))return e;e=e.nextElementSibling}return null}function Ae(n){const e=oe(n),o=mt(e).indexOf(n);return g(So,o!==-1,"invalid block & container dom, failed to get block index"),o}function eg(n){return!n||!(n instanceof Node)?!1:!!ne(n)}function Ds(n){if(!eg(n))return!1;const e=n,t=e instanceof Element?e:e.parentElement;return t?!!t.closest("div[data-type=block-tools]"):!1}const f4=D("block-class");function Ye(n,e){return n.editorBlocks.getBlockClass(Se(e))}function m4(n,e){const t=n.editorBlocks.getBlockClass(Se(e));return g(f4,t.blockKind==="text",`is not a text block, ${t.blockType}`),t}function zn(n,e){const t=n.editorBlocks.getBlockClass(Se(e));return g(f4,t.blockKind==="complex",`is not a text block, ${t.blockType}`),t}function Ls(n,e){return n.editorBlocks.getBlockClass(e)}function te(n,e){return Ye(n,e).blockKind==="text"}function Sa(n,e){return n.editorBlocks.getBlockClass(e).blockKind==="text"}function Me(n,e){return Ye(n,e).blockKind==="complex"}function Ax(n,e){return!Me(n,e)}function Do(n,e){return Ye(n,e).blockKind}function Lo(n,e,t){return Ye(n,e).getCaretRect(e,t)}const g4=D("container");function Ur(n){return n.getAttribute("data-type")==="editor-container"}function Ge(n){return xe(n,"root")}function Mo(n){return xe(n,"child")}function ce(n){const e=n.getAttribute("data-container-id");return g(g4,e,"no id for container"),Ge(n)&&g(g4,e==="root",`invalid root container id, : ${e}`),e}function p4(n,e){const t=ce(n);return e.getContainerBlocks(t)}const tg=D("block");function ue(n,e){return Ye(n,e).getBlockTextLength(e)}function C4(n){n.editorBlocks.forEach(e=>{e.clearSelection(n)})}function b4(n,e,t,o){Ye(n,e).updateSelection(n,e,t,o)}function ng(n){for(;;){const e=oe(n);if(Ge(e))return n;const t=ne(e);g(tg,t,"no parent block exists for child container"),n=t}}function A4(n,e){const t=Ye(n,e);if(!!t.getMinWidth)return t.getMinWidth(n,e)}function v4(n,e,t){const o=Ye(n,e);o.handleBlockElementUpdated&&o.handleBlockElementUpdated(n,e,t)}function mh(n,e,t,o){try{const r=Ls(n,t).convertFrom;return r?r(n,e,o):null}catch{return tg.debug(`unsupported block type: ${t}`),null}}function zr(n,e,t){const o=Ye(n,e);return o.getClientRects?o.getClientRects(n,e,t):[e.getBoundingClientRect()]}function vx(n,e){const t=Ye(n,e);if(t.getBlockStyles)return t.getBlockStyles(n,e);const o=n.getBlockData(e),r=Object.fromEntries(Object.entries(o).filter(([i])=>i.startsWith("style-")));return Object.entries(r).forEach(([,i])=>{const s=typeof i;g(tg,s==="string"||s==="number"||s==="boolean","invalid style value")}),r}function ut(n,e){return Do(n,e)==="text"?ue(n,e)===0:!1}const y4=D("block-path");function Oi(n){const e=[];let t=n;for(;t;){const o=oe(t);if(e.unshift({containerId:ce(o),blockIndex:Ae(t)}),Ge(o))return e;const r=ne(o);g(y4,r,"no parent block"),t=r}return g(y4,!1,"no parent block"),[]}function yx(n,e){var r,i;const t=Ye(n,e);return(i=(r=t.getOptions)==null?void 0:r.call(t,n))!=null?i:{name:Se(e)}}function co(n){return Ge(oe(n))}function k4(n,e){var r;const t=Ye(n,e);return(r=t.getBlockProperties)==null?void 0:r.call(t,n,e)}function og(n,e){var i,s;const t=Ye(n,e),o=(i=t.getBlockProperties)==null?void 0:i.call(t,n,e);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,e);a&&(r[a.group]=a)}return r}function kx(n,e,t){var s,l,a,d;const o=Ye(n,e),r=(s=o.getBlockProperties)==null?void 0:s.call(o,n,e);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,e);p&&(i[p.group]=p)}return(d=(a=i[t])==null?void 0:a.commands)!=null?d:[]}function w4(n,e,t){let o=e;for(;o;){const r=kx(n,o,t);if(r.length>0)return{element:Le(o),commands:r};if(co(o))break;o=xs(o)}return{element:null,commands:[]}}const B4=D("embed-block-common");function It(n){return Se(n)==="embed"}function mn(n){g(B4,It(n),"not an embed block");const e=n.getAttribute("data-embed-type");return g(B4,e,"no embed data type"),e}function wx(n,e){return n.editorEmbeds.getEmbedClass(mn(e))}function Ms(n,e){return n.editorEmbeds.getEmbedClass(e)}async function rg(n,e,t,o,r){const i=Ms(n,e);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:t,blockIndex:o,data:r})}function Bx(n,e,t,o,r){var l,a;const i=(a=(l=Ls(n,e)).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:t,blockIndex:o,data:r})}const Ex=D("execute-block-command");function E4(n,e,t,o){var d;g(Ex,It(e),"not a embed block");const r=mn(e),i=Ms(n,r);if(!i.getOptions)return;const s=(d=i.getBlockProperties)==null?void 0:d.call(i,n,e),l=s==null?void 0:s.blockCommands;if(!l)return;const a=Object.entries(l);for(const h of a)if(h[0]===t)return h[1].executeCommand(n,e,o)}function x4(n,e,t,o){const r=og(n,e);if(!r)return;const i=Object.entries(r);for(const s of i)if(s[0]===t)return s[1].executeCommand(n,e,o)}const Vr=D("text-block-child");function Da(n){return n.tagName==="SPAN"}function ao(n){return g(Vr,Da(n),"not a valid text child"),n.getAttribute("data-type")==="editor-box"}function Wr(n){return g(Vr,Da(n),"not a valid text child"),n.getAttribute("data-type")==="editor-insertion"}function La(n){return!ao(n)&&!Wr(n)}function I4(n){return g(Vr,Da(n),"not a valid text child"),ao(n)?"box":Wr(n)?"insertion":"text"}function uo(n){const e=I4(n);return e==="insertion"?0:e==="box"?1:(g(Vr,n.textContent!==null,"text block content is undefined"),g(Vr,n.textContent.length>=0,"text block content length is negative"),n.textContent.length)}function ir(n){const e=Le(n),t=Array.from(e.children);return t.forEach(o=>{g(Vr,Da(o),"not a valid text child")}),t}function gh(n,e){const t=ir(n);let o=0;for(let r=0;r<t.length;r++){const i=t[r],s=uo(i);if(o+s<e){o+=s;continue}if(o===e)return{prev:t[r-1],next:i,offset:0};if(o+s===e)return{prev:i,next:t[r+1],offset:0};const l=e-o;return g(Vr,l>0,"invalid offset value"),g(Vr,!ao(i),"invalid box child"),{prev:i,next:i,offset:l}}g(Vr,!1,`invalid block child at position: ${e}`)}const T4=D("element");function ig(n,e,t){const o=k("div",[e],n);return o.setAttribute("data-type","editor-container"),o.setAttribute("data-container-id",t),k("div",["container-blocks"],o),o}function sr(n,e){const t=n.rootElement.querySelector(`[data-container-id=${e}]`);return g(T4,t,`no container: ${e}`),t}function ph(n,e){return n.rootElement.querySelector(`[data-container-id=${e}]`)}function Ch(n){const e=n.querySelector(":scope > .container-blocks");return g(T4,e,"no container blocks element"),e}function xx(n){let e=n.querySelector(":scope > .container-tools");return e||(e=k("div",["container-tools"],n)),e}const Ix=D("child-container-path");function S4(n){if(Ge(n))return[];const e=ne(n);return g(Ix,e,"no parent block"),Oi(e)}const D4=D("load-blocks");function sg(n,e,t){const o=ce(e),r=p4(e,n.doc);g(D4,r.length>0,"no blocks in container");const i=document.createDocumentFragment();r.forEach((l,a)=>{const d=n.editorBlocks.createBlock([...t,{containerId:o,blockIndex:a}],e,l);i.appendChild(d)}),Ch(e).appendChild(i)}function Tx(n,e,t){const o=Ch(n);if(e===0)return o.insertBefore(t,o.firstChild),t;const r=mt(n);return g(D4,e>=0&&e<=r.length,"invalid block index"),e===r.length?o.appendChild(t):o.insertBefore(t,r[e]),t}function Sx(n,e,t,o){const r=S4(e);r.push({containerId:ce(e),blockIndex:t});const i=n.editorBlocks.createBlock(r,e,o);return Tx(e,t,i),i}const L4=D("root-container");class Dx{constructor(e,t){m(this,"resizeObserver");m(this,"handleContextMenu",e=>{});m(this,"handleResize",()=>{try{this.editor.selection.updateSelection(null),this.editor.emit("resize",this.editor)}catch(e){L4.warn(`failed to update selection while container resizing: ${e.message}`)}});m(this,"handleClick",e=>{this.editor.emit("click",this.editor,e);const t=e.target;if(!Ds(t)&&(e.detail===1&&this.editor.input.focus(),e.detail===3&&this.editor.selectionHandler.handleTripleClick(e),e.detail===1&&e.button===0)){const o=document.elementFromPoint(e.clientX,e.clientY);if(o&&et(this.rootContainer,o)){const r=ne(o);r&&et(r,o)&&this.handleBlockClick(e,r,o)}}});m(this,"handleBlockClick",(e,t,o)=>{var s,l;if(!te(this.editor,t))return;const r=Jm(o);if(r){const a=ne(r);g(L4,a,"no parent block"),(l=(s=this.editor.editorBoxes.getBoxClass(Ta(r)))==null?void 0:s.handleClickBox)==null||l.call(s,this.editor,r,e);return}const i=o.closest("span.text.link");i&&ir(t).indexOf(i)!==-1&&this.editor.emit("clickLink",this.editor,e,i)});m(this,"handleDblClick",e=>{Ds(e.target)||this.editor.selectionHandler.handleDblClick(e)});m(this,"handleMouseDown",e=>{const t=e.target;if(!!t&&t instanceof Node&&!Ds(t)){if(t instanceof HTMLElement&&t.draggable){this.editor.selectionHandler.handleMouseDown(e,{autoScroll:!1}),this.editor.selectionHandler.stopSelection(),this.editor.input.focus();return}e.button===0&&(document.addEventListener("mousemove",this.handleMouseMove),document.addEventListener("mouseup",this.handleMouseUp),this.editor.selectionHandler.handleMouseDown(e,{autoScroll:!0})),Zt.isMobileSafari||(e.preventDefault(),this.editor.input.focus()),e.button===2&&e.stopPropagation()}});m(this,"handleMouseMove",e=>{this.editor.selectionHandler.handleMouseMove(e)});m(this,"handleMouseUp",e=>{e.button===0&&(this.editor.selectionHandler.handleMouseUp(e),document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp))});this.editor=e,this.rootContainer=t,this.editor=e,this.resizeObserver=new bs(this.handleResize),this.bindEvents(t)}bindEvents(e){this.resizeObserver.observe(e);const t=this.editor.rootElement;t.onmousedown=this.handleMouseDown,t.ondblclick=this.handleDblClick,t.onclick=this.handleClick,t.oncontextmenu=this.handleContextMenu}unbindEvents(){this.resizeObserver.disconnect();const e=this.editor.rootElement;e.onmousedown=null,e.ondblclick=null,e.onclick=null,e.oncontextmenu=null}destroy(){this.unbindEvents()}reload(){const e=this.editor.selection.range,t=Ch(this.rootContainer);t.innerHTML="",sg(this.editor,this.rootContainer,[]);const o=this.editor.findBlockById(e.start.blockId);if(o)this.editor.selection.selectBlock(o,0);else{const r=yt(this.rootContainer);this.editor.selection.selectBlock(r,0)}}}function M4(n){const e=ig(n.contentElement,"root","root");return n.rootContainer=e,sg(n,e,[]),new Dx(n,e)}function R4(n,e,t,o){const r=ph(n,o);if(r)return t.appendChild(r),setTimeout(()=>{n.emit("containerRemount",n,o)}),r;const i=ig(t,"child",o);return sg(n,i,e),i}function O4(n,e){const t=n.getBoundingClientRect().width;return e.withPadding?t:t-Mm(n)}function lg(n,e){let t=Number.MAX_SAFE_INTEGER;const o=mt(e);for(let i=0;i<o.length;i++){const s=o[i],l=A4(n,s);l&&(t=Math.min(t,l))}return t===Number.MAX_SAFE_INTEGER?void 0:t+Mm(e)}function Ma(n,e){const t=mt(e);return t.length!==1?!1:ut(n,t[0])}const Lx=D("complex-block-position");class Ro{constructor(e,t,o){m(this,"blockId");m(this,"childContainerId");m(this,"custom");e instanceof HTMLElement?this.blockId=ie(e):(g(Lx,typeof e=="string",`not a valid block id: ${e}`),this.blockId=e),this.childContainerId=t,o!==void 0&&(this.custom=o)}isSimple(){return!1}}const Mx=D("simple-block-position");class Ut{constructor(e,t,o){m(this,"blockId");m(this,"offset");m(this,"type");e instanceof HTMLElement?this.blockId=ie(e):(g(Mx,typeof e=="string",`not a valid block id: ${e}`),this.blockId=e),this.offset=t,this.type=o}isSimple(){return!0}}const cg=D("editor-position");function se(n,e,t){return new Ut(n,e,t)}function ft(n,e,t){return new Ro(n,e,t)}function qr(n){return n instanceof Ut}function ql(n){return n instanceof Ro}function ag(n,e,t){if(qr(e)&&qr(t)){const o=e,r=t;if(o.blockId===r.blockId)return o.offset-r.offset;const i=n.getBlockById(e.blockId),s=n.getBlockById(t.blockId);return g(cg,i!==s,"comparePosition: blocks are the same"),th(i,s)}if(ql(e)&&ql(t)){const o=e,r=t;if(o.childContainerId===r.childContainerId)return 0;const i=n.getContainerById(o.childContainerId),s=n.getContainerById(r.childContainerId);return g(cg,i!==s,"comparePosition: containers are the same"),th(i,s)}return g(cg,!1,"invalid "),0}const bh=D("simple-range");class Yt{constructor(e,t){m(this,"editor");m(this,"_anchor");m(this,"_focus");m(this,"reverse");this.editor=e,this._anchor=t.anchor,this._focus=t.focus,this.reverse=ag(this.editor,this._anchor,this._focus)>0}isCollapsed(){return this.start.blockId===this.end.blockId&&this.start.offset===this.end.offset}isEqual(e){if(!(e instanceof Yt))return!1;const t=e,{start:o,end:r}=t;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:e}=this,t=e.getBlockById(this.start.blockId),o=e.getBlockById(this.end.blockId);g(bh,t,"no start block"),g(bh,o,"no end block");const r=oe(t),i=oe(o);g(bh,r===i,"invalid range");const s=[];if(t===o)s.push({block:t,start:this.start,end:this.end});else{const l=Ae(t),a=Ae(o);g(bh,l<a,"invalid range, start > index"),s.push({block:t,start:this.start,end:se(t,ue(this.editor,t),"end")});const d=mt(r);for(let h=l+1;h<a;h+=1){const p=d[h];s.push({block:p,start:se(p,0,"home"),end:se(p,ue(this.editor,p),"end")})}s.push({block:o,start:se(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 Yt(this.editor,this)}toDocRange(){return{anchor:this.anchor,focus:this.focus}}static from(e,t){return new Yt(e,t)}}D("unknown-block");function Rx(n,e,t,o,r){W(o,"unknown-block");const i=Is(o,"div");return i.innerText=`unknown block (${r.type}): ${JSON.stringify(r)}`,i}function Ox(n){return 1}function _x(n,e,t,o){return null}function Fx(n,e,t,o){const r=document.elementsFromPoint(t,o)[0];if(!r||!e.contains(r)||!n.contains(e))return null;const i=ie(e),s=se(i,0,"home"),l=se(i,1,"end");return new Yt(n,{anchor:s,focus:l})}function Px(n,e){const o=Le(n).getBoundingClientRect();return new DOMRect(o.left+o.width/2,o.top,1,o.height)}function Nx(n,e,t,o){W(e,"selected")}function $x(n){n.rootContainer.querySelectorAll("div.unknown-block[data-type=editor-block]").forEach(e=>{re(e,"selected")})}function Hx(n,e,t,o){return`[unknown block, ${e.type}]`}const jx={blockType:"unknown-block",blockKind:"embed",createBlockContent:Rx,getBlockTextLength:Ox,getRangeFromPoint:Fx,moveCaret:_x,getCaretRect:Px,updateSelection:Nx,clearSelection:$x,convertTo:Hx},ug=D("editor-blocks");class _4{constructor(e){m(this,"blocks",new Map);this.editor=e}registerBlockClass(e){const t=e.blockType,o=this.blocks.get(t);g(ug,!o,`duplicated block type: ${t}`),this.blocks.set(t,e)}getBlockClass(e){const t=this.blocks.get(e);return g(ug,t,`unknown block type: ${e}`),t}hasBlock(e){return this.blocks.has(e)}createBlock(e,t,o){const r=s4(this.editor,e,o);let i;this.hasBlock(o.type)?i=this.getBlockClass(o.type):i=this.registerUnknownBlock(o.type);const s=i.createBlockContent(this.editor,e,t,r,o);return s.parentElement!==r&&(ug.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,e,t,r,o)}),r}forEach(e){this.blocks.forEach(e)}registerUnknownBlock(e){const t={...jx,blockType:e};return this.editor.editorBlocks.registerBlockClass(t),t}}const F4=D("editor-embeds");class P4{constructor(e){m(this,"objects",new Map);this.editor=e}registerEmbedClass(e){const t=e.embedType,o=this.objects.get(t);g(F4,!o,`duplicated embed object type: ${t}`),this.objects.set(t,e)}getEmbedClass(e){const t=this.objects.get(e);return g(F4,t,`unknown embed type: ${e}`),t}getEmbedClassFromBlock(e){return this.getEmbedClass(mn(e))}forEach(e){this.objects.forEach(e)}}const N4=D("embed-block");function Ux(n,e,t,o,r){const i=Is(o,"div");g(N4,r.type==="embed",`not an embed data: ${JSON.stringify(r)}`);const s=r;return g(N4,s.embedType&&s.embedData,`not an embed data: ${JSON.stringify(s)}`),n.editorEmbeds.getEmbedClass(s.embedType).createEmbedContent(n,i,s,e,t,o),o.setAttribute("data-embed-type",s.embedType),i}function zx(n){return 1}function Vx(n,e,t,o){return null}function Wx(n,e,t,o){const r=document.elementsFromPoint(t,o)[0];if(!r||!e.contains(r)||!n.contains(e))return null;const i=ie(e),s=se(i,0,"home"),l=se(i,1,"end");return new Yt(n,{anchor:s,focus:l})}function qx(n,e){const o=Le(n).getBoundingClientRect();return new DOMRect(o.left+o.width/2,o.top,1,o.height)}function Gx(n,e,t,o){W(e,"selected")}function Zx(n){n.rootContainer.querySelectorAll("div.embed-block[data-type=editor-block][data-block-type=embed]").forEach(e=>{re(e,"selected")})}function Qx(n,e,t){let o=null;return n.editorEmbeds.forEach(r=>{var s,l;const i=(l=(s=r.convertFrom)==null?void 0:s.call(r,n,e,t))!=null?l:null;i&&(o=i)}),o}function Yx(n,e,t,o){const r=Ms(n,e.embedType);return r.convertTo?r.convertTo(n,e,t,o):""}function Jx(n,e){const t=wx(n,e);return t.getBlockProperties?t.getBlockProperties(n,e):{}}function Kx(n){const e=new Map,t=[];return n.editorEmbeds.forEach(o=>{if(o.getOptions){const r=o.getOptions(n);r.insertEmbedCommandItems&&r.insertEmbedCommandItems.forEach(i=>{t.push(i),e.set(i.id,o)})}}),{name:"EmbedBlock",insertBlockCommandItems:t,async handleInsertEmptyBlock(o,r){const i=e.get(r.item.id);if(!i||!i.getOptions)return null;const s=i.getOptions(o);return s.handleInsertEmptyEmbed?s.handleInsertEmptyEmbed(o,r):null}}}function Xx(n,e,t,o){const r=mn(e),i=Ms(n,r);!i.handleDeleteBlock||i.handleDeleteBlock(n,e,t,o)}function eI(n,e,t){const o=mn(e),r=Ms(n,o);return r.handleUpdateBlock?r.handleUpdateBlock(n,e,t):!1}function tI(n,e,t,o,r){const i=mn(e),s=Ms(n,i);if(s.handleDropOver)return s.handleDropOver(n,e,t,o,r)}function nI(n,e,t,o,r){const i=mn(e),s=Ms(n,i);if(s.handleDrop&&n.isWritable())return s.handleDrop(n,e,t,o,r)}async function oI(n,e,t){const o=e.embedType,r=n.editorEmbeds.getEmbedClass(o);if(r.toStandardDoc){const i=n.getBlockById(e.id),s=Oi(i);return r.toStandardDoc(n,e,t,s)}}const $4={blockType:"embed",blockKind:"embed",createBlockContent:Ux,getBlockTextLength:zx,getRangeFromPoint:Wx,moveCaret:Vx,getCaretRect:qx,updateSelection:Gx,clearSelection:Zx,convertFrom:Qx,convertTo:Yx,getBlockProperties:Jx,getOptions:Kx,handleDeleteBlock:Xx,handleUpdateBlock:eI,handleDropOver:tI,handleDrop:nI,toStandardDoc:oI},gn=D("complex-block-helper");function pn(n,e,t){return zn(n,e).getChildContainers(n,e,t)}function Gl(n,e,t,o){return t.isSimple()?(g(gn,o.isSimple(),"invalid start and end position"),pn(n,e)):(g(gn,!t.isSimple(),"invalid start pos"),g(gn,!o.isSimple(),"invalid end pos"),zn(n,e).getSelectedContainers(n,e,t,o))}function rI(n,e){if(Ae(e)!==0)return!1;const t=ne(oe(e));if(!t)return!1;g(gn,Me(n,t),"not a complex block");const o=oe(e),i=pn(n,t).indexOf(o);return g(gn,i>=0,"not valid child container"),i===0}function dg(n,e,t){const o=pn(n,e,t);if(o.length===0)return null;const r=o[0];if(!r)return null;const i=yt(r);return Me(n,i)?dg(n,i,t):i}function Zl(n,e,t){const o=pn(n,e,t);if(o.length===0)return null;const r=o[o.length-1];if(!r)return null;const i=Qt(r);return Me(n,i)?Zl(n,i,t):i}function H4(n,e){g(gn,Mo(e),"not a child container");const t=ne(e);g(gn,t,"no parent block"),g(gn,Me(n,t),"not a complex block");const o=pn(n,t),r=o.indexOf(e);if(g(gn,r!==-1,"child container not found"),r===0){const l=at(t);return l?Me(n,l)?Zl(n,l):l:null}const i=o[r-1],s=Qt(i);return Me(n,s)?Zl(n,s):s}function j4(n,e){g(gn,Me(n,e),"not a complex block");const t=pn(n,e);if(g(gn,t.length>0,"no child container"),t.length===1)return t;const o=t[0],r=o.getBoundingClientRect();let i=r.left,s=r.right;const l=[o];for(let a=1;a<t.length;a++){const d=t[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 U4(n,e){g(gn,Me(n,e),"not a complex block");const t=pn(n,e);if(g(gn,t.length>0,"no child container"),t.length===1)return t;const o=t[t.length-1],r=o.getBoundingClientRect();let i=r.left,s=r.right;const l=[o];for(let a=t.length-2;a>=0;a--){const d=t[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 z4(n,e,t,o){const r=e.getBoundingClientRect(),i=o<r.top,s=i?j4(n,e):U4(n,e);let l=s[0],a=or(l.getBoundingClientRect(),t,o);for(let d=1;d<s.length;d++){const h=s[d],p=h.getBoundingClientRect(),C=or(p,t,o);C<a&&(l=h,a=C)}return i?yt(l):Qt(l)}function Ah(n,e,t,o){const r=ie(e);g(gn,r===t.blockId,"invalid start pos"),g(gn,r===o.blockId,"invalid end pos");const i=zn(n,e);return i.adjustSelectionPos?i.adjustSelectionPos(n,e,t,o):{anchor:t,focus:o}}class lr{constructor(e,t){m(this,"editor");m(this,"reverse");m(this,"_anchor");m(this,"_focus");this.editor=e,this._anchor=t.anchor,this._focus=t.focus,this.reverse=ag(this.editor,this._anchor,this._focus)>0}isCollapsed(){return!1}isEqual(e){if(!(e instanceof lr))return!1;const t=e,{anchor:o,focus:r}=t;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 e=this.start,t=this.end;return[{block:this.editor.getBlockById(e.blockId),start:e,end:t}]}getAnchorPos(){return this._anchor}getFocusedPos(){return this._focus}getSelectedContainers(){const e=this.editor.getBlockById(this._anchor.blockId);return Gl(this.editor,e,this.start,this.end)}clone(){return new lr(this.editor,this)}toDocRange(){return{anchor:this._anchor,focus:this._focus}}}const iI=D("selection-range");function zt(n,e){const{anchor:t,focus:o}=e;return t instanceof Ut&&o instanceof Ut?new Yt(n,{anchor:t,focus:o}):(g(iI,t instanceof Ro&&o instanceof Ro,"start position type does not math end type"),new lr(n,{anchor:t,focus:o}))}function kt(n,e,t,o){const r=new Ut(e,t,"normal"),i=new Ut(e,o!=null?o:t,"normal");return zt(n,{anchor:r,focus:i})}function sI(n){return!!n.anchor.childContainerId}function _i(n,e){var r,i;if(sI(e)){const s=ft(e.anchor.blockId,e.anchor.childContainerId,(r=e.anchor)==null?void 0:r.custom),l=ft(e.focus.blockId,e.focus.childContainerId,(i=e.focus)==null?void 0:i.custom);return zt(n,{anchor:s,focus:l})}const t=se(e.anchor.blockId,e.anchor.offset,"normal"),o=se(e.focus.blockId,e.focus.offset,"normal");return zt(n,{anchor:t,focus:o})}const V4=D("range-from-point");function vh(n,e,t){const o=[0,-8,8];for(let r=0;r<o.length;r++){const i=document.elementsFromPoint(e,t+o[r])[0];if(!i)continue;const s=i.getBoundingClientRect();if(i.clientWidth&&i.clientHeight&&r===0&&(s.left+i.clientWidth<e||s.top+i.clientHeight<t))return V4.debug("click on scrollbar, out of element rect"),null;if(!n.rootContainer.contains(i))continue;const l=ne(i);if(!l||!n.contains(l))continue;const a=Ye(n,l).getRangeFromPoint(n,l,e,t+o[r]);if(a)return a}return null}function W4(n,e,t,o){const r=e.getBoundingClientRect();if(o<=r.top){const a=yt(e),d=Ye(n,a).getRangeFromPoint(n,a,t,a.getBoundingClientRect().top+4);if(d!=null&&d.isSimple())return Yt.from(n,d);const h=se(a,0,"home");return new Yt(n,{anchor:h,focus:h})}const i=Qt(e),s=Ye(n,i).getRangeFromPoint(n,i,t,i.getBoundingClientRect().bottom-4);if(s!=null&&s.isSimple())return Yt.from(n,s);const l=se(i,ue(n,i),"end");return new Yt(n,{anchor:l,focus:l})}function q4(n,e,t){const o=vh(n,e,t);if(o){if(o instanceof Yt)return o;g(V4,o instanceof lr,`invalid range type: ${typeof o}`);const a=o,d=n.getContainerById(a.start.childContainerId);return W4(n,d,e,t)}const r=document.elementsFromPoint(e,t)[0];if(!r)return null;const{children:i}=r,s=Array.from(i).filter(a=>Ur(a));if(s.length===0)return null;const l=s.reduce((a,d)=>{const h=a.getBoundingClientRect(),p=d.getBoundingClientRect();return or(h,e,t)>or(p,e,t)?d:a});return W4(n,l,e,t)}function hg(n,e){const t=[];return mt(e).forEach(r=>{t.push(r),Me(n,r)&&pn(n,r).forEach(s=>{t.push(...hg(n,s))})}),t}function fg(n,e){let t=hg(n,n.rootContainer);return e!=null&&e.simpleBlockOnly&&(t=t.filter(o=>!Me(n,o))),t}function cr(n,e){const t=n.selection.range.getSelectedBlocks(),o=[];for(const r of t)o.push(r),Me(n,r.block)&&Gl(n,r.block,r.start,r.end).forEach(s=>{const a=hg(n,s).map(d=>({block:d,start:se(d,0,"home"),end:se(d,ue(n,d),"home")}));o.push(...a)});return e!=null&&e.simpleBlockOnly?o.filter(r=>!Me(n,r.block)):o}const Xne="",Jt=D("text-range");function lI(n,e){const t=(i,s)=>{if(Wr(i))return g(Jt,s===0,`invalid offset for insertion child: ${s}`),{child:i,container:i,offset:2};if(ao(i))return g(Jt,s===0||s===1,`invalid offset for box: ${s}`),{child:i,container:i,offset:s===0?1:2};const l=i.firstChild;return g(Jt,l,"no child node for text child"),g(Jt,l instanceof Text||l instanceof HTMLBRElement,`invalid child for text child, ${l.nodeName}`),l instanceof HTMLBRElement?(g(Jt,s>=0&&s<=0,"invalid offset for text child"),{child:i,container:l,offset:s}):(g(Jt,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=uo(s);if(e===o)return[t(s,0)];if(e<o+l)return[t(s,e-o)];if(e===o+l){const a=[];a.push(t(s,uo(s)));const d=r[i+1];return d&&a.push(t(d,0)),a}o+=l}g(Jt,!1,"failed to get range info")}function cI(n,e,t){if(e===t?g(Jt,Wr(n),"only insertion child can be zero offset"):g(Jt,e<t,`invalid start & end: ${e}, ${t}`),Wr(n)){g(Jt,e===t,`invalid insertion child range offset: ${e}, ${t}`),g(Jt,e===0,`invalid insertion child range start: ${e}`);const i=n;return g(Jt,i.children.length===3,`invalid insertion dom, children.length = ${i.children.length}`),Xd(i,1,i,2)}if(ao(n)){g(Jt,e+1===t,`invalid box child range offset: ${e}, ${t}`),g(Jt,e===0,`invalid box child range start: ${e}`);const i=n;return g(Jt,i.children.length===3,`invalid box dom, children.length = ${i.children.length}`),Xd(i,1,i,2)}const o=uo(n);g(Jt,t<=o,`invalid child end: ${t}, ${o}`);const r=n.firstChild;return g(Jt,r instanceof Text,"invalid block text child"),g(Jt,r.data.length>=t,`invalid range end: ${t}, ${r.data.length}`),Xd(r,e,r,t)}const Oo=D("caret-rect");function aI(n,e){if(Ym(e)){const t=e,o=Km(t);if(t.getAttribute("data-box-type")==="br"){const r=Le(n),i=Number.parseFloat(window.getComputedStyle(r).lineHeight)||o.getBoundingClientRect().height,s=Array.from(o.getClientRects());g(Oo,s.length>0,"no box client rects");const l=r.getBoundingClientRect(),a=s[0],d=new DOMRect(l.left,a.bottom,1,i);return s.push(d),s}return o.getClientRects()}return Xm(e).getClientRects()}function Vn(n,e){var l,a,d;const t=lI(n,e.offset);if(t[1]&&t[0].child!==((l=t[1])==null?void 0:l.child)){if(e.type==="end"){const p=vs(t[0].child);return new DOMRect(p.right,p.top,1,p.height)}g(Oo,t[1],"invalid ranges");const h=eh(t[1].child);return new DOMRect(h.left,h.top,1,h.height)}let r=t[0];if(g(Oo,t.length>=1,"failed to get block range"),t.length===1)r=t[0];else{if(g(Oo,t.length>=2,`invalid range info length: ${t.length}`),Wr(t[t.length-1].child)){r=t[t.length-1];const h=r.child,C=Xm(h).getClientRects();g(Oo,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)}e.type==="home"?r=t[1]:e.type==="end"||La(t[0].child)?r=t[0]:La(t[1].child)&&(r=t[1])}if(r.container instanceof HTMLBRElement){g(Oo,e.offset===0,"invalid offset for empty block text");const h=r.container.parentElement;g(Oo,h,"invalid br parent");const p=h.getBoundingClientRect();return new DOMRect(p.left,p.top,1,p.height)}const i=C5(r.container,r.offset),s=Array.from(i.getClientRects());if(s.length===0){g(Oo,!La(r.child),"only box or insertion child range has zero client rect"),g(Oo,r.offset===1||r.offset===2,"invalid offset for box or insertion child");const h=r.child,p=aI(n,h);if(g(Oo,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 e.type==="end"||r.offset===2?new DOMRect(C.right,C.y,1,C.height):new DOMRect(C.x,C.y,1,C.height)}if(wa()||zl()){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,S)=>{if(v[0].top!==s[0].top&&v[0].top===B.top){const{x,y:_,height:M}=p[S];s.push(new DOMRect(x,_,0,M))}})}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,S)=>{if(v[0].top!==s[0].top&&v[0].top===B.top){const{x,y:_,height:M}=p[S];s.length===1&&s.unshift(new DOMRect(x,_,0,M))}})}}return g(Oo,s.length>0,"no client rects for range"),e.type==="home"?s[s.length-1]:s[0]}const uI=D("core");function Gr(n,e,t,o){const r=tt(e);let i=r.querySelector(`.block-anchor[data-id=${t}]`);i||(i=k("div",["block-anchor"],r),i.setAttribute("data-id",t));const s=o!=null?o:e.getBoundingClientRect(),l=e.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 G4(n,e,t,o){g(uI,te(n,e),"not a text kind block");const r=Vn(e,se(e,t,"normal")),i=e.getBoundingClientRect(),s=tt(e);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 Ra(n){const e=ir(n);let t=0;return e.forEach(o=>{t+=uo(o)}),t}const Z4=D("box");function Oa(n){return!n.attributes||!n.attributes.box?!1:(g(Z4,n.attributes.box===!0,`invalid op attribute box property, ${n.attributes.box}`),g(Z4,n.attributes.type,`no box type: ${JSON.stringify(n)}`),!0)}const Q4=D("rich-text-length");function mg(n){return g(Q4,typeof n.insert=="string","op.insert is not string"),n.insert.length}function sn(n){let e=0;return n.forEach(t=>{t.insert&&(g(Q4,typeof t.insert=="string","op.insert is not string"),e+=mg(t))}),e}const ar=D("split-text");function Tn(n,e,t){if(n=me.default(n),e===0)return{left:[],right:n};if(e===-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=mg(i);if(o+s<e)o+=s;else{if(o+s===e)return{left:n.slice(0,r+1),right:n.slice(r+1)};{g(ar,o+s>e,`invalid offset, ${o}, ${s}, ${e}`);const l=e-o,a=me.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 t&&(t.sourceOp=i),{left:h,right:d}}}}throw new Error(`invalid split offset: ${e}, ${JSON.stringify(n)}`)}function Vt(n,e,t){g(ar,e>=0,"invalid offset, < 0"),g(ar,t>0,"invalid length, <= 0"),g(ar,e+t<=sn(n),"invalid offset + length < text length");const{left:o,right:r}=Tn(n,e+t),{left:i,right:s}=Tn(o,e);return{left:i,middle:s,right:r}}function Y4(n,e){const t=Array.from(new Set(e)).sort((i,s)=>i-s),o=[];let r=n;for(let i=t.length-1;i>=0;i--){const s=t[i],{left:l,right:a}=Tn(r,s);r=l,o.unshift(a)}return r.length>0&&o.unshift(r),o}function J4(n,e,t){return Vt(n,e,t).middle}const Ql=D("text-block-content");function dI(n,e,t,o,r){if(g(Ql,o,"no text for block"),o.length===0&&(!r||r.size===0)){t.innerHTML="<span><br></span>";return}const i=[];r&&i.push(...r.keys());const s=p=>n.editorInsertions.createInsertion(t,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=Y4(o,i);for(let p=0;p<h.length;p++){l(a,d);const C=h[p];d+=sn(C);for(let v=0;v<C.length;v++){const B=C[v];if(Oa(B)){g(Ql,B.attributes,`op is not an valid box: ${JSON.stringify(B)}`);const x=n.editorBoxes.createBox(t,B.attributes);g(Ql,x instanceof HTMLSpanElement,`invalid box element: ${x.tagName}`),a.appendChild(x);continue}g(Ql,B.insert,`no insert in op: ${JSON.stringify(B)}`);const S=k("span",["text"],a,B.insert);if(B.attributes){const x=n.editorBlockRenders.renderText(e,B.attributes);x.classes&&W(S,...x.classes),x.attributes&&Object.entries(x.attributes).forEach(([_,M])=>{S.setAttribute(_,M)}),x.styles&&Object.entries(x.styles).forEach(([_,M])=>{S.style.setProperty(_,M)})}a.appendChild(S)}}l(a,d),t.innerHTML="",t.appendChild(a)}function yh(n,e,t,o,r){const{text:i,insertions:s}=n.editorDecorators.decorateText(e,r),l=n.compositingText;if(l){const a=n.selection.range.start;g(Ql,a.isSimple(),"not an simple position while compositing"),a.blockId===t&&s.set(a.offset,[{type:"inputting",id:K(),text:l}])}return dI(n,e,o,i,s)}function hI(n){const e=n.rootContainer.querySelectorAll('span[data-type="editor-insertion"].inputting-insertion');e.length&&Ql.debug(`remove ${e.length} temp composition span`),Array.from(e).forEach(t=>t.remove())}const ur=D("client-rects");function fI(n){const e=ir(n);let t=0;const o=[];for(let r=0;r<e.length;r++){const i=e[r],s=uo(i);o.push({child:i,startBlockOffset:t,endBlockOffset:t+s}),t+=s}return o}function mI(n,e,t,o){g(ur,t<o,`invalid from & to: ${t}, ${o}`);const r=ue(n,e);g(ur,t>=0&&o>=0&&t<=r&&o<=r,`invalid offset: ${t}, ${o}, length: ${r}`);const i=fI(e),s=i.findIndex(v=>v.startBlockOffset<=t&&t<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:t-v.startBlockOffset,endChildOffset:o-v.startBlockOffset}]}const a=[],d=i[s],h={child:d.child,startChildOffset:t-d.startBlockOffset,endChildOffset:uo(d.child)};a.push(h);for(let v=s+1;v<l;v++){const B=i[v],S={child:B.child,startChildOffset:0,endChildOffset:B.endBlockOffset-B.startBlockOffset};a.push(S)}const p=i[l],C={child:p.child,startChildOffset:0,endChildOffset:o-p.startBlockOffset};return a.push(C),a}function gI(n){const e=(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=>e(o,i)));const t=[];return n=n.filter(o=>t.find(r=>r.left===o.left&&r.top===o.top&&r.width===o.width&&r.height===o.height)?!1:(t.push(o),!0)),n}function K4(n,e,t,o){if(ue(n,e)===0){const h=Le(e).getBoundingClientRect();return[new DOMRect(h.left,h.top,4,h.height)]}const r=t.offset,i=o.offset;if(r===i)return[Vn(e,t)];const l=mI(n,e,r,i).map(d=>cI(d.child,d.startChildOffset,d.endChildOffset)),a=[];return l.forEach(d=>{const h=gI(Array.from(d.getClientRects()));a.push(...h)}),a}function pI(n,e,t){g(ur,t instanceof Yt,"invalid range");const o=t.start,r=t.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===ie(e),"only allow update one text block selection"),K4(n,e,o,r)}const gg=D("selection-background");function CI(n,e,t,o){g(gg,t.isSimple(),"text block only allow simple position"),g(gg,o.isSimple(),"text block only allow simple position"),g(gg,t.blockId===o.blockId,"only allow update one text block selection");const r=t.offset,i=o.offset;if(r===i&&(ue(n,e)!==0||n.selection.range.isCollapsed()))return;const s=K4(n,e,t,o),l=e.getBoundingClientRect(),a=io(e),d=i4(e);d.innerHTML="",s.forEach(h=>{const p=k("div",["editor-selection-background"],d);p.style.left=`${(h.left-l.left-e.clientLeft)/a}px`,p.style.top=`${(h.top-l.top-e.clientTop)/a}px`,p.style.width=`${h.width/a}px`,p.style.height=`${h.height/a}px`})}function bI(n){n.rootContainer.querySelectorAll("div[data-type=block-background]").forEach(e=>{e.remove()})}const Rs=D("text-offset"),X4="\u200D";function Os(n,e){const t=ir(n);let o=0;for(let r=0;r<t.length;r++){const i=t[r],s=uo(i);if(i===e){const l=o+s;return{start:o,end:l}}o+=s}g(Rs,!1,"can not find child in children")}function ln(n,e){g(Rs,e>=0,`invalid offset: ${e}`);const t=gh(n,e),{prev:o,next:r,offset:i}=t;if(!o&&!r&&g(Rs,!1,"invalid offset, no prev & next child at offset"),o!==r)return!0;const s=o;if(g(Rs,s,"no child"),ao(s))return g(Rs,i===0||i===1,`invalid box child offset: ${i}`),!0;const l=s.textContent;g(Rs,l,"no content for text child");const a=l.charAt(i-1),d=l.charAt(i);return!(a===X4||d===X4||Dm(l[i]))}function Fi(n,e){if(e===0)return 0;const t=e-1;if(ln(n,t))return t;let o=t-1;for(;!ln(n,o);)o-=1;return o}function _s(n,e){const t=Ra(n);if(g(Rs,e>=0&&e<=t,`invalid offset: ${e}, ${t}`),e===t)return t;const o=e+1;if(ln(n,o))return o;let r=o+1;for(;!ln(n,r);)r+=1;return r}const Fs=D("line-breaker");function _a(n){const e=a=>{const d=eh(a);return vs(a).top>d.top+d.height/2},t=(a,d)=>{const h=vs(a),p=eh(d);return Math.floor(p.left)<Math.floor(h.right)},o=(a,d)=>{const h=vs(a),p=vs(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(Wr(d)){const x=d,_=l[a+1];if(!_)break;const M=l[a-1];if(M&&o(M,x)&&i.push({offset:s,type:"betweenChild",childInfo:{prevChild:M,nextChild:x,wrap:"nextWrapped",prevWrapped:e(M),nextWrapped:e(x)}}),t(x,_)){i.push({offset:s,type:"betweenChild",childInfo:{prevChild:M,nextChild:x,wrap:"nowrap",prevWrapped:e(M),nextWrapped:e(x)}});continue}continue}if(ao(d)){const x=d,_=l[a+1];if(!_)break;const M=l[a-1];if(M&&o(M,x)&&i.push({offset:s,type:"betweenChild",childInfo:{prevChild:M,nextChild:x,wrap:"nextWrapped",prevWrapped:e(M),nextWrapped:e(x)}}),t(x,_)){s+=1,i.push({offset:s,type:"betweenChild",childInfo:{prevChild:M,nextChild:d,wrap:"nowrap",prevWrapped:e(M),nextWrapped:e(d)}});continue}s+=1;continue}const h=d,p=h.getClientRects();if(g(Fs,p.length>0,"invalid text child dom"),p.length===1){const x=l[a+1];if(!x)break;if(t(h,x)){s+=uo(h),i.push({offset:s,type:"betweenChild",childInfo:{prevChild:h,nextChild:x,wrap:"nowrap",prevWrapped:e(h),nextWrapped:e(x)}});continue}s+=uo(h);continue}const C=h.firstChild;g(Fs,C,"invalid text child, no text node"),g(Fs,C instanceof Text,`invalid text child, not a valid text node: ${typeof C}`);const v=document.createRange(),B=document.createRange(),S=uo(h);g(Fs,C.data.length===S,"text node data length not equal child text length");for(let x=0;x<C.data.length;x++){if(!ln(n,s+x))continue;v.setStart(C,x);const _=v.getClientRects();if(g(Fs,_.length>=1,"invalid text node, no client rects"),r(_)){const ee=s+x;i.push({offset:ee,type:"textBreakWord",childInfo:{prevChild:d,nextChild:d,wrap:"nowrap",prevWrapped:e(d),nextWrapped:e(d)}});continue}let M=x+1;ln(n,s+M)||(M=x+2),B.setStart(C,M);const H=B.getClientRects(),z=_[0],Z=H[0];if(Math.floor(Z.left)<Math.floor(z.right))if(wa()||zl()){i.push({offset:zl()?s+M:s+x,type:"textBreakWord",childInfo:{prevChild:d,nextChild:d,wrap:"nowrap",prevWrapped:e(d),nextWrapped:e(d)}});continue}else g(Fs,!1,"span pre-wrap should not has a line-wrap by white space")}s+=S}return i}function pg(n,e){const t=_a(n);for(let o=0;o<t.length;o++){const{offset:r,type:i}=t[o];if(e.offset<r)return{lineIndex:o,lineBreaks:t};if(e.offset===r&&e.type==="end")return{lineIndex:o,lineBreaks:t}}return g(Fs,e.offset<=Ra(n),"invalid position, offset > block length"),{lineIndex:t.length,lineBreaks:t}}const AI=D("line-offset");function Cg(n){const e=_a(n),t=[];let o=0;for(let r=0;r<e.length;r++){const i=e[r];t.push({start:o,end:i.offset}),o=i.offset}return t.push({start:o,end:Ra(n)}),t}function kh(n,e){const t=Cg(n);return g(AI,e>=0&&e<t.length,`invalid line index: ${e}, ${t.length}`),t[e]}function e6(n,e){const{lineIndex:t}=pg(n,e);return kh(n,t)}function vI(n){const e=Cg(n),t=n.getBoundingClientRect(),o=[];return e.forEach(({start:r,end:i})=>{const s=se(n,r,"home");let l=Vn(n,s);const a=se(n,i,"end"),d=Vn(n,a);l.top+l.height/2<d.top&&(l=new DOMRect(t.left-1e4,d.top,1,d.height));const h=new DOMRect(l.left,d.top,d.left-l.left,d.height),p=new DOMRect(t.left,d.top,t.width,d.height);o.push({start:r,end:i,rect:p,contentRect:h})}),o}function yI(n,e,t){const r=vI(n).find(s=>ks(s.rect,e,t));if(!r)return null;const i=r.contentRect;return e-i.left<i.right-e?se(n,r.start,"home"):se(n,r.end,"end")}function t6(n,e,t){const o=Vn(n,e),r=Vn(n,t),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 n6(n){return Cg(n).length}const Ps=D("find-text-position");function o6(n,e){const{start:t,end:o}=kh(n,e),r=ie(n),i=Vn(n,se(r,t,"home"));if(!(Vn(n,se(r,o,"end")).top>i.top+i.height/2))return!1;const a=gh(n,t);return g(Ps,a.next,"no next child at offset"),g(Ps,!La(a.next),"next child is not text child"),!0}function kI(n,e){const t=ie(n);g(Ps,o6(n,e),"line is not wrapped");const{start:o,end:r}=kh(n,e),i=se(t,o,"home");for(let s=o+1;s<=r;s+=1){let l="normal";s===o?l="home":s===r&&(l="end");const a=se(t,s,l);if(!t6(n,i,a))return s-1}return g(Ps,!1,"failed to find wrapped offset"),0}function wh(n,e,t,o,r,i,s){g(Ps,te(n,e),`not a text kind block: ${Se(e)}`);const{start:l,end:a}=kh(e,t);let d=l;const h=ie(e);if(e===o&&o6(e,t)){const x=kI(e,t);(i==="up"||i==="down"&&t6(e,r,se(h,l,"home")))&&(d=x+1)}let p=Number.MAX_SAFE_INTEGER;const C=Lo(n,o,r),v=s!=null?s:C.left+C.width/2,B=C.top+C.height/2;let S=se(h,d,"home");for(let x=d;x<=a;x++){if(!ln(e,x))continue;let _="normal";x===l?_="home":x===a&&(_="end");const M=se(h,x,_),H=Vn(e,M),z=or(H,v,B);z<p&&(p=z,S=M)}return S}function wI(n,e,t,o,r){return g(Ps,te(n,e),"not a text block"),wh(n,e,n6(e)-1,t,o,"up",r)}function BI(n,e,t,o,r){return g(Ps,te(n,e),"not a text block"),wh(n,e,0,t,o,"down",r)}function EI(n,e,t,o){const{lineIndex:r}=pg(e,t);if(r===n6(e)-1)return null;const i=wh(n,e,r+1,e,t,"down",o);return i||null}function xI(n,e){if(e.offset===0)return null;const t=_a(n),o=t.find(r=>r.offset===e.offset);if(!o){const r=Fi(n,e.offset);return t.find(s=>s.offset===r)?{offset:r,type:"home"}:{offset:r,type:"normal"}}if(o.type==="betweenChild"){if(e.type==="home"&&o.childInfo.wrap==="nowrap")return{offset:e.offset,type:"end"};if(o.childInfo.prevWrapped)return{offset:Fi(n,e.offset),type:"normal"}}return{offset:Fi(n,e.offset),type:"normal"}}function II(n,e){const t=Ra(n);if(e.offset===t)return null;const o=_a(n),r=o.find(i=>i.offset===e.offset);if(!r){const i=_s(n,e.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"&&e.type==="end"?{offset:e.offset,type:"home"}:{offset:_s(n,e.offset),type:"home"}:{offset:_s(n,e.offset),type:"normal"}}function TI(n,e,t,o){const{lineIndex:r}=pg(e,t);if(r===0)return null;const i=wh(n,e,r-1,e,t,"up",o);return i||null}const SI=D("move-caret");function DI(n,e,t,o){if(o==="ArrowLeft"){const r=xI(e,t);return r?se(ie(e),r.offset,r.type):null}if(o==="ArrowRight"){const r=II(e,t);return r?se(ie(e),r.offset,r.type):null}if(o==="ArrowUp"){const r=TI(n,e,t,n.selection.getSuggestedCaretX());return r?se(ie(e),r.offset,r.type):null}if(o==="ArrowDown"){const r=EI(n,e,t,n.selection.getSuggestedCaretX());return r?se(ie(e),r.offset,r.type):null}g(SI,!1,`invalid navigation direction: ${o}`)}const bg=D("text-range");function LI(n){const e=[];return ir(n).forEach(o=>{const r=Array.from(o.getClientRects()).map(i=>({rect:i,child:o}));e.push(...r)}),e}function MI(n,e,t){const o=LI(n);for(let r=1;r<o.length;r++){const i=o[r-1],s=o[r];if(e>=i.rect.right&&e<=s.rect.left&&t>=i.rect.top&&t<=i.rect.bottom&&t>=s.rect.top&&t<=s.rect.bottom)return Os(n,s.child).start}return null}function RI(n,e,t,o){const r=document.elementsFromPoint(t,o)[0];if(!r||!e.contains(r)||!n.contains(e))return null;const i=r.closest("div[data-type=block-content]>span");if(!i){const _=e.getBoundingClientRect();if(!ks(_,t,o))return null;const M=MI(e,t,o);if(M!==null){const z=se(e,M,"normal");return new Yt(n,{anchor:z,focus:z})}const H=yI(e,t,o);return H?new Yt(n,{anchor:H,focus:H}):null}const s=ir(e);g(bg,s.indexOf(i)!==-1,"failed to find child in children");const l=Os(e,i);g(bg,l,"failed to get child offset");const{start:a}=l;let d,h;Wr(i)||ao(i)?(d=a,h=0):(g(bg,i.firstChild instanceof Text,"child is not text"),d=a+b5(i.firstChild,t,o),h=0);const p=ie(e),v=_a(e).find(_=>_.offset===d);let B="normal";if(v){const _=se(p,d,"home"),M=se(p,d,"end"),H=Vn(e,_),z=Vn(e,M),Z=or(H,t,o),ee=or(z,t,o);B=Z<ee?"home":"end"}const S=se(p,d,B);let x;return h&&(x=se(p,d+h,B)),new Yt(n,{anchor:S,focus:x!=null?x:S})}const OI=D("create-text-op");function ho(n,e){g(OI,n,"text is empty");const t={insert:n};return e&&Object.keys(e).length>0&&(t.attributes=e),t}function Ag(n,e){if(n.length===0)return[];if(n.indexOf(`
|
|
15
|
+
animateScrollTo(scrollToElement:Element, options)`;t+=i.horizontalOffset,o+=i.verticalOffset;const p=h.getMaxHorizontalScroll(),C=h.getHorizontalScroll();t>p&&(t=p);const v=t-C,B=h.getMaxVerticalScroll(),S=h.getVerticalScroll();i.verticalOffset||(S<o?o-=h.getClientHeight()*3/4:o-=h.getClientHeight()*1/4),o>B&&(o=B);const x=o-S,_=Math.abs(Math.round(v/1e3*i.speed)),M=Math.abs(Math.round(x/1e3*i.speed));let H=_>M?_:M;return H<i.minDuration?H=i.minDuration:H>i.maxDuration&&(H=i.maxDuration),new Promise((z,Z)=>{v===0&&x===0&&z(!0),$r.remove(h.element,!0);let ee;const fe=()=>{qt(),cancelAnimationFrame(ee),z(!1)};$r.add(h.element,fe);const ve=Rn=>Rn.preventDefault(),ze=i.cancelOnUserAction?fe:ve,He=i.cancelOnUserAction?{passive:!0}:{passive:!1},Ke=["wheel","touchstart","keydown","mousedown"],qt=()=>{Ke.forEach(Rn=>{h.element.removeEventListener(Rn,ze,He)})};Ke.forEach(Rn=>{h.element.addEventListener(Rn,ze,He)});const Jn=Date.now(),Ht=()=>{const Rn=Date.now()-Jn,Tr=Rn/H,kn=Math.round(C+v*i.easing(Tr)),un=Math.round(S+x*i.easing(Tr));Rn<H&&(kn!==t||un!==o)?(h.scrollTo(kn,un),ee=requestAnimationFrame(Ht)):(h.scrollTo(t,o),cancelAnimationFrame(ee),qt(),$r.remove(h.element,!1),z(!0))};ee=requestAnimationFrame(Ht)})}function ks(n,e,t){return n.left<=e&&e<=n.right&&n.top<=t&&t<=n.bottom}function qE(n){const e="\xA0";if(!n)return"";if(n===" ")return e;let t=n;return t.startsWith(" ")&&(t=e+t.substr(1)),t.endsWith(" ")&&(t=t.substr(0,t.length-1)+e),t=t.replace(/ {2}/g,` ${e}`),t}function w5(n){if(!/["'&<>]/.exec(n))return n;const o={'"':""","'":"'","&":"&","<":"<",">":">"};return n.split("").map(l=>o[l]||l).join("")}function B5(n){const e=document.getElementById(n);e&&e.remove()}function E5(n,e){const t=document.getElementById(e);if(t)return t.textContent=n,t;const o=document.createElement("style");return o.id=e,o.textContent=n,document.head.append(o),o}function ka(n){const e="custom-cursor-style";if(n){const t=`body * { cursor: ${n} !important}`;E5(t,e)}else B5(e)}const x5=3,I5=D("drag-drop");class T5{constructor(e){m(this,"dragStarted",!1);m(this,"mouseDownEvent",null);m(this,"_dragOffsetX",0);m(this,"_dragOffsetY",0);m(this,"handleMouseDown",e=>{e.preventDefault(),e.stopPropagation(),this.mouseDownEvent=e;const t=this.options.elem.getBoundingClientRect();this._dragOffsetX=this.mouseDownEvent.x-t.left,this._dragOffsetY=this.mouseDownEvent.y-t.top,this.bindEvents()});m(this,"handleMouseMove",e=>{var i;e.preventDefault(),e.stopPropagation(),g(I5,this.mouseDownEvent,"no mouse down event");const t=e.x-this.mouseDownEvent.x,o=e.y-this.mouseDownEvent.y;if(this.dragStarted){this.onDragging(e,t,o);return}const r=(i=this.options.minThreshold)!=null?i:x5;(Math.abs(t)>=r||Math.abs(o)>=r)&&this.onDragStart(this.mouseDownEvent)});m(this,"handleMouseUp",e=>{if(e.button===0){g(I5,this.mouseDownEvent,"no mouse down event");const t=e.x-this.mouseDownEvent.x,o=e.y-this.mouseDownEvent.y;this.onDragEnd(e,t,o),e.preventDefault(),e.stopPropagation()}});this.options=e,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(e){this.dragStarted=!0,this.options.cursor&&ka(this.options.cursor),this.options.onDragStart(this,e,this.options.elem)}onDragging(e,t,o){this.options.onDragging(this,e,this.options.elem,t,o)}onDragEnd(e,t,o){this.options.cursor&&ka(null),this.dragStarted&&this.options.onDragEnd(this,e,this.options.elem,t,o),this.unbindEvents(),this.dragStarted=!1}destroy(){this.unbindEvents(),this.untrackEvents()}}function Fm(n){return new T5(n)}const GE=D("character");function S5(n,e){for(let t=0;t<e.length;t++){const o=e[t][0],r=e[t].length>1?e[t][1]:null;if(r===null&&n===o||r!==null&&n>=o&&n<=r)return!0}return!1}function D5(n){const e=n.charAt(0);return e>="0"&&e<="9"}function L5(n){const e=n.charAt(0);return e>="a"&&e<="z"||e>="A"&&e<="Z"||e.toUpperCase()!==e.toLowerCase()?!0:RegExp(/^\p{L}/,"u").test(e)}function rh(n){const e=[[9,13],[32],[160]];return S5(n.charCodeAt(0),e)}function M5(n){const e=[[12352,12687],[13056,13183],[13312,15661],[19968,40959],[63744,64255],[44032,55215]];return S5(n.charCodeAt(0),e)}function Pm(n,e){let t=e;return g(GE,t.length===1,"invalid char length"),t==="]"&&(t="\\]"),t==="\\"&&(t="\\\\"),n.replace(new RegExp(`^[${t}]+|[${t}]+$`,"g"),"")}const Hr=navigator.userAgent;function zl(){const n=navigator.userAgent.toLowerCase();return n.indexOf("safari")!==-1&&!(n.indexOf("chrome")>-1)}function wa(){return navigator.userAgent.toLowerCase().indexOf("firefox")>-1}const Zt={isAndroid:!!Hr.match(/Android/i),isIOS:!!Hr.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/i),isIPad:!!Hr.match(/iPad/i),isIPhone:!!Hr.match(/iPhone/i),isLinux:!!Hr.match(/Linux/i),isMac:!!Hr.match(/Macintosh/i),isMobile:!!Hr.match(/AppleWebKit.*Mobile.*/i),isWindows:!!Hr.match(/Window/i),isIe:!!Hr.match(/msie|trident/i),isSafari:zl(),isFirefox:wa(),isMobileSafari:!1};Zt.isMobileSafari=Zt.isMobile&&Zt.isSafari;function Nm(n){return n?n.length===1||n==="Process"||n==="Unidentified"&&Zt.isAndroid:!1}function R5(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 ZE(n){return R5(n.key)}function QE(n){switch(n){case"ArrowUp":case"ArrowLeft":case"Home":case"PageUp":return!0;default:return!1}}function ws(n){return n.ctrlKey||n.altKey||n.shiftKey||n.metaKey}function YE(n){return n.key?!!(n.ctrlKey||n.metaKey||n.altKey):!1}function O5(n){return Zt.isMac?n.metaKey&&!n.ctrlKey:!n.metaKey&&n.ctrlKey}function JE(n){return O5(n)&&!n.altKey&&!n.shiftKey}function KE(n){return!n.metaKey&&!n.ctrlKey&&!n.shiftKey&&n.altKey}function _5(n){return!ws(n)&&n.key==="Enter"}function XE(n){return n.key==="Enter"&&n.shiftKey&&!n.altKey&&!n.ctrlKey&&!n.metaKey}function $m(n){return!ws(n)&&n.key==="Escape"}function ex(n){return!ws(n)&&n.key==="Delete"}function F5(n){return!ws(n)&&n.key==="Backspace"}function tx(n){return!ws(n)&&n.key==="Tab"}function nx(n){return n.shiftKey&&n.key==="Tab"&&!n.ctrlKey&&!n.metaKey}function so(n){if(!n)return"";if(Zt.isMac){const e=n.replace("CtrlOrCmd","\u2318").replace("Shift","\u21E7").replace("Ctrl","\u2303").replace("Alt","\u2325").replace(/\+(?!$)/gm,""),t={"\u2318":4,"\u21E7":3,"\u2325":2,"\u2303":1};return e.split(/(?=[\s\S])/u).sort((r,i)=>{var a,d;const s=(a=t[r])!=null?a:5,l=(d=t[i])!=null?d:5;return s-l}).map(r=>r in t?`${r}+`:r).join("")}return n.replace("CtrlOrCmd","Ctrl")}function P5(n){const e={ctrl:!1,alt:!1,shift:!1,cmd:!1,key:""},t=n.toLocaleUpperCase().split("+");for(let o=0;o<t.length;o++){const r=t[o];r==="CTRL"||r==="CONTROL"?e.ctrl=!0:r==="ALT"||r==="OPTION"?e.alt=!0:r==="SHIFT"?e.shift=!0:r==="CMD"||r==="COMMAND"?e.cmd=!0:r==="CMDORCTRL"||r==="CTRLORCMD"?Zt.isMac?e.cmd=!0:e.ctrl=!0:r==="SPACE"?e.key=" ":e.key=r.substring(0,1)+r.substring(1).toLocaleLowerCase()}return e}function rr(n,e){const t=P5(e);return t.ctrl!==n.ctrlKey||t.alt!==n.altKey||t.shift!==n.shiftKey||Zt.isMac&&t.cmd!==n.metaKey?!1:t.key.length===1?t.key===n.key.toUpperCase():t.key.toUpperCase()===n.key.toUpperCase()}function Hm(n,e){return TB.stringifyUrl({url:n,query:e})}function Ri(n){return typeof n=="string"?ga.Base64.encode(n,!0):ga.Base64.fromUint8Array(n,!0)}function Ba(n){return ga.Base64.decode(n)}function ox(n){return ga.Base64.toUint8Array(n)}function jm(n){return new Blob([ga.Base64.toUint8Array(n)])}const rx=Li.init([Li.classModule,Li.styleModule,Li.datasetModule,Li.attributesModule,Li.propsModule]);function Ea(n,e){const t=Li.toVNode(n),o=Li.toVNode(e);rx(t,o)}async function Um(n,e){const t=new FileReader,o=new Promise((i,s)=>{t.onload=i,t.onerror=s});return t.readAsDataURL(new Blob([n],{type:e})),await o,t.result}async function Vl(n){const e=new FileReader,t=new Promise((r,i)=>{e.onload=r,e.onerror=i});return e.readAsDataURL(n),await t,e.result}function ix(n,...e){const t=n.tagName.toLowerCase();for(let o=0,r=e.length;o<r;o++)if(t===e[o].toLowerCase())return!0;return!1}function lo(n,e){let t=n;for(;t;){const o=window.getComputedStyle(t);if(e!=null&&e.horizontal){if(/auto|scroll/i.test(o.overflowX))break}else if(/auto|scroll/i.test(o.overflowY))break;t=t.parentElement}return(!t||ix(t,"body"))&&(t=document.documentElement),t}function N5(n){n.preventDefault(),n.stopPropagation()}function $5(n){if(document.querySelector(`.editor-disable-scroll[data-scroll-id="${n}"]`))return;const e=k("div",["editor-disable-scroll"],null);e.setAttribute("data-scroll-id",n),e.addEventListener("wheel",N5,{passive:!1}),document.body.appendChild(e)}function H5(n){const e=document.querySelector(`.editor-disable-scroll[data-scroll-id="${n}"]`);e&&(e.removeEventListener("wheel",N5),e.remove())}function zm(n,e,t){const o=new Blob([n]),r=new File([o],t,{type:e});return URL.createObjectURL(r)}function ih(n){const e=document.createElement("template");if("content"in e)return e.innerHTML=n,document.importNode(e.content,!0);const t=document.createDocumentFragment(),o=document.createElement("div");for(o.innerHTML=n;o.firstChild;)t.appendChild(o.firstChild);return t}function j5(n){const e=document.createElement("div");return e.appendChild(n),e.innerHTML}function U5(n){let e=n.getPropertyValue("font");if(e)return e;const t=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 e=`${t} ${o} ${r} ${i} ${s}`.replace(/ +/g," ").trim(),e}function sh(n,e){const o=(sh.canvas||(sh.canvas=document.createElement("canvas"))).getContext("2d");return o?(typeof e=="string"?e?o.font=e:o.font=U5(window.getComputedStyle(document.body)):e instanceof Element&&(o.font=U5(window.getComputedStyle(e))),o.measureText(n).width+4):200}const sx=D("editor-clipboard");async function lx(n,e){if(e.clipboardData){const t=e.clipboardData;for(const o of n)t.setData(o.type,o.data);return!0}return!1}async function Vm(n){try{const e={};n.forEach(o=>{e[o.type]=o.data});const t=new ClipboardItem(e);return await navigator.clipboard.write([t]),!0}catch(e){return sx.error(e),!1}}function Wl(n,e){return new Promise((t,o)=>{const r=document.createElement("input");r.type="file",r.style.display="none",e!=null&&e.multiple&&(r.multiple=!0),r.accept=n,r.onchange=()=>{const i=r.files;if(i){const s=e!=null&&e.multiple?Array.from(i):i[0];t(s)}r.remove()},r.onerror=i=>{o(i),r.remove()},r.click()})}function lh(n){return Array.isArray(n)?n.every(e=>e instanceof File):!1}function xa(n){const e=n;if(!e)return"";const t=e.lastIndexOf(".");return t===-1?"":e.slice(t+1)}function ch(n,e){const t=document.createElement("a");t.setAttribute("download",`${e||""}`),t.setAttribute("href",`${n}`),t.click(),t.remove()}const z5=D("auto-scroll");function V5(n,e){return!(n.scrollHeight===n.clientHeight||e==="top"&&n.scrollTop===0||e==="bottom"&&n.scrollTop+n.clientHeight===n.scrollHeight||e==="left"&&n.scrollLeft===0||e==="right"&&n.scrollLeft+n.clientWidth===n.scrollWidth)}function W5(n,{direction:e,step:t}){let o=null;const r=e==="left"||e==="right",i=()=>V5(n,e)?(r?e==="left"?n.scrollLeft=Math.max(n.scrollLeft-t,0):n.scrollLeft=Math.min(n.scrollLeft+t,n.scrollWidth):e==="top"?n.scrollTop=Math.max(n.scrollTop-t,0):n.scrollTop=Math.min(n.scrollTop+t,n.scrollHeight),o=requestAnimationFrame(i),o):(z5.debug("No need for scroll"),null);return o=requestAnimationFrame(i),()=>{o&&cancelAnimationFrame(o)}}class ah{constructor(e){m(this,"cancelScroll",null);m(this,"options");m(this,"scrollDomInfo");m(this,"scrolling",!1);m(this,"getScrollingDirection",e=>{const{x:t,y:o}=e,{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&&t<=s+a.left?"left":a.right&&t>=l-a.right?"right":null});m(this,"handleMouseMove",e=>{var s;const{scrollElement:t,step:o=10,onDirectionChange:r}=this.options,i=this.getScrollingDirection(e);if(i){if(this.scrolling)return;z5.debug(`scroll direction: ${i}`),this.cancelScroll=W5(t,{direction:i,step:o}),r==null||r(i),this.scrolling=!0}else(s=this.cancelScroll)==null||s.call(this),this.scrolling=!1});this.options=e,this.scrollDomInfo=this.getScrollDomInfo()}getScrollDomInfo(){const{scrollElement:e}=this.options,t=e.getBoundingClientRect(),o=t.top,r=t.left,i=t.bottom,s=t.right;return{left:r,top:o,right:s,bottom:i}}active(){const{trackMouseEvent:e="mousemove"}=this.options;window.addEventListener(e,this.handleMouseMove,!0)}inactive(){var t;const{trackMouseEvent:e="mousemove"}=this.options;window.removeEventListener(e,this.handleMouseMove,!0),(t=this.cancelScroll)==null||t.call(this),this.scrolling=!1}}function q5(n,e){if(n===0)return"0 Bytes";const t=1024,o=e||2,r=["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"],i=Math.floor(Math.log(n)/Math.log(t));return`${parseFloat((n/t**i).toFixed(o))} ${r[i]}`}function Ia(n,e){let t=`${n}`;const o=e-t.length;for(let r=0;r<o;r++)t=`0${t}`;return t}const{t:Bs}=L;function Wm(n,e){const t=new Date(n).getTime()+864e5*e;return new Date(t)}function cx(n,e){const t=n,o=Math.floor(e/12),r=e-o*12;return o&&t.setFullYear(t.getFullYear()+o),r&&t.setMonth(t.getMonth()+r),t}function ax(n,e){return Wm(n,e)}function qm(n,e){const t=new Date(n),o=new Date(e);return t.getDate()===o.getDate()&&t.getMonth()===o.getMonth()&&t.getFullYear()===o.getFullYear()}function G5(n){const e=new Date,t=new Date(n);return qm(e,t)}function Z5(n){const e=Wm(new Date,-1);return qm(e,n)}function ux(n,e){return Math.round((n.getTime()-e.getTime())/864e5)}function Gm(n,e){const t=new Date(n);if(e){const o=t.getFullYear(),r=t.getMonth()+1,i=t.getDate(),s=t.getHours(),l=t.getMinutes();let a=e;return a=a.replace("YYYY",`${o}`),a=a.replace("MM",Ia(r,2)),a=a.replace("DD",Ia(i,2)),a=a.replace("M",`${r}`),a=a.replace("D",`${i}`),a=a.replace("hh",Ia(s,2)),a=a.replace("mm",Ia(l,2)),a=a.replace("h",`${s}`),a=a.replace("m",`${l}`),a}return n.toLocaleDateString()}function Zm(n,e){const t=new Date(n),o=new Date;if(t.getTime()-o.getTime()>10*1e3)return L.t("date.dateFromFuture");if(G5(t)){const i=(o.getTime()-n.getTime())/1e3;if(i<10*60)return Bs("date.dateJustNow");if(i<60*60)return Bs("date.dateMinutesAgo",{num:`${Math.floor(i/60)}`});const s=Math.floor(i/60/60);return s===1?Bs("date.date1HourAgo"):Bs("date.dateHoursAgo",{num:`${s}`})}if(Z5(n))return Bs("date.dateYesterday");const r=Math.floor((o.getTime()-n.getTime())/1e3/24/60/60)+1;return r<14?Bs("date.dateDaysAgo",{num:`${r}`}):r<28?Bs("date.dateWeeksAgo",{num:`${Math.round(r/7)}`}):Gm(n,e)}function Qm(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function dx(n,e,t){return n.replace(new RegExp(Qm(e),"g"),t)}function hx(n,e,t){return n.replace(new RegExp(Qm(e),"gi"),t)}function Q5(n,e,t){const r=document.createElement("canvas").getContext("2d");if(!r)return null;if(r.font=String(e),r.measureText(n).width>t){let s=0,l=0;for(;l<t;)l=r.measureText(n.slice(0,s)).width,s++;return`${n.slice(0,s-2)}...`}return n}const Y5=/[\u3040-\u30ff\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff\uff66-\uff9f\uAC00-\uD7AF]/,J5=" -\x7F0-9!-/:-@[-`{-~\u0370-\u03FF\u0400-\u04FF",fx=new RegExp(`[${J5}]`),mx=new RegExp(`([^(${J5})])`,"g"),K5=/(\ud83c[\udf00-\udfff])|(\ud83d[\udc00-\ude4f\ude80-\udeff])|[\u2600-\u2B55]/;function X5(n){return n.length===0?0:n.split("").reduce((e,t)=>{const o=(e<<5)-e+t.charCodeAt(0);return o&o},0)}function gx(n,e=1){var o,r;return(r=((o=Array.from(n))==null?void 0:o.filter(i=>Y5.test(i))).slice(-e))==null?void 0:r.join("")}function px(n,e=1){var r;const t=Array.from((r=n==null?void 0:n.replace(mx,""))==null?void 0:r.split(/\s/));return t.reduce((i,s,l)=>{var a,d;return l===t.length-1&&i.length<e?`${i}${(a=s==null?void 0:s.slice(0,e-i.length))!=null?a:""}`:`${i}${(d=s[0])!=null?d:""}`},"").slice(0,e)}function Cx(n,e=1){var o,r;return(r=((o=Array.from(n))==null?void 0:o.filter(i=>K5.test(i))).slice(-e))==null?void 0:r.join("")}function bx(n,e=1){var t,o;return(o=(t=Array.from(n))==null?void 0:t.slice(0,e))==null?void 0:o.join("")}function uh(n,e=1){if(!n||n.length===0)return"";const t=Y5.test(n),o=fx.test(n),r=K5.test(n);switch(!0){case t:return gx(n,e);case o:return px(n,e);case r:return Cx(n,e);default:return bx(n,e)}}var e4=(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))(e4||{});function dh(n){const e=Object.values(e4),t=Math.abs(typeof n=="string"&&n.trim()?X5(n.trim()):0)%e.length;return e[t]}const t4=D("container-children");function mt(n){const e=Array.from(n.querySelectorAll(":scope > .container-blocks > div[data-type=editor-block]"));return g(t4,e.length>0,"container have not any child block"),e}function yt(n){const e=n.querySelector(":scope > .container-blocks > div[data-type=editor-block]");return g(t4,e,"container have not any child block"),e}function Qt(n){const e=mt(n);return e[e.length-1]}function To(n){return mt(n).length}function jr(n,e){return mt(n)[e]}const So=D("block-dom");function Es(n){return n instanceof HTMLDivElement?n.getAttribute("data-type")==="editor-block":!1}function n4(n){return n instanceof HTMLElement&&n.getAttribute("data-type")==="block-tools"}function o4(n){W(n,"block-hidden")}function r4(n){re(n,"block-hidden")}function hh(n){return!xe(n,"block-hidden")}function ie(n){const{id:e}=n;return g(So,e,"no block id"),e}function Se(n){const e=n.getAttribute("data-block-type");return g(So,e,"invalid block dom, no data-type"),e}function ne(n){const e=n instanceof Element?n:n.parentElement;if(!e)return null;const t=e.closest("div[data-type=editor-block]");return t||null}function xs(n){const e=n instanceof Element?n:n.parentElement;if(!e)return null;const t=e.closest("div[data-type=editor-block]:not(:scope)");return t||null}function oe(n){const e=n.closest("div[data-type=editor-container]");return g(So,e,"failed to get block container"),e}function Le(n){const e=n.querySelector(":scope >div[data-type=block-content]");return g(So,e,"no block content"),e}function tt(n){let e=n.querySelector(":scope >div[data-type=block-tools]");return e||(e=k("div",[],n),e.setAttribute("data-type","block-tools")),g(So,e,"no block tools"),e}function fh(n){const e=n.querySelector(":scope >div[data-type=block-tools]");return e||null}function i4(n){let e=n.querySelector(":scope > div[data-type=block-background]");return e||(e=k("div",[],n),e.setAttribute("data-type","block-background")),e}function s4(n,e,t){const o=n.editorDecorators.decorateBlock(e,t),{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,e,t);return l.classes&&W(s,...l.classes),l.attributes&&Object.entries(l.attributes).forEach(([a,d])=>{s.setAttribute(a,d)}),l.styles&&Object.entries(l.styles).forEach(([a,d])=>{s.style.setProperty(a,d)}),s}function Is(n,e){const t=k(e,[],null);return t.setAttribute("data-type","block-content"),n&&n.appendChild(t),t}function l4(n){const e=k("span",[`${n.type}-box`],null);return e.setAttribute("data-type","editor-box"),e.setAttribute("data-box-type",n.type),e.id=n.id,e}function Ta(n){const e=n.getAttribute("data-box-type");return g(So,e,"not a valid box element, no type"),e}function Ym(n){return n instanceof HTMLSpanElement?n.getAttribute("data-type")==="editor-box":!1}function c4(n){const{id:e}=n;return g(So,e,"no box id"),e}function Jm(n){const e=n instanceof Element?n:n.parentElement;if(!e)return null;const t=e.closest("span[data-type=editor-box]");return t||null}function a4(n){n.innerHTML="",k("span",["box-space-start"],n,va);const e=k("span",[],n);return e.setAttribute("data-type","box-content"),k("span",["box-space-start"],n,va),e}function Km(n){const e=n.querySelector("span[data-type=box-content]");return g(So,e,"invalid box dom, no content"),e}function u4(n,e){const t=k("span",[`${n}-insertion`],null);return t.setAttribute("data-type","editor-insertion"),t.setAttribute("data-insertion-id",e),t}function d4(n,e){return n.rootContainer.querySelector(`[data-insertion-id=${e}]`)}function h4(n){n.innerHTML="",k("span",["insertion-space-start"],n,va);const e=k("span",[],n);return e.setAttribute("data-type","insertion-content"),k("span",["insertion-space-start"],n,va),e}function Xm(n){const e=n.querySelector("span[data-type=insertion-content]");return g(So,e,"invalid insertion-child dom, no content"),e}function at(n){let e=n.previousElementSibling;for(;e;){if(Es(e))return e;e=e.nextElementSibling}return null}function Qe(n){let e=n.nextElementSibling;for(;e;){if(Es(e))return e;e=e.nextElementSibling}return null}function Ts(n){let e=n.previousElementSibling;for(;e;){if(Es(e)&&hh(e))return e;e=e.previousElementSibling}return null}function Ss(n){let e=n.nextElementSibling;for(;e;){if(Es(e)&&hh(e))return e;e=e.nextElementSibling}return null}function Ae(n){const e=oe(n),o=mt(e).indexOf(n);return g(So,o!==-1,"invalid block & container dom, failed to get block index"),o}function eg(n){return!n||!(n instanceof Node)?!1:!!ne(n)}function Ds(n){if(!eg(n))return!1;const e=n,t=e instanceof Element?e:e.parentElement;return t?!!t.closest("div[data-type=block-tools]"):!1}const f4=D("block-class");function Ye(n,e){return n.editorBlocks.getBlockClass(Se(e))}function m4(n,e){const t=n.editorBlocks.getBlockClass(Se(e));return g(f4,t.blockKind==="text",`is not a text block, ${t.blockType}`),t}function zn(n,e){const t=n.editorBlocks.getBlockClass(Se(e));return g(f4,t.blockKind==="complex",`is not a text block, ${t.blockType}`),t}function Ls(n,e){return n.editorBlocks.getBlockClass(e)}function te(n,e){return Ye(n,e).blockKind==="text"}function Sa(n,e){return n.editorBlocks.getBlockClass(e).blockKind==="text"}function Me(n,e){return Ye(n,e).blockKind==="complex"}function Ax(n,e){return!Me(n,e)}function Do(n,e){return Ye(n,e).blockKind}function Lo(n,e,t){return Ye(n,e).getCaretRect(e,t)}const g4=D("container");function Ur(n){return n.getAttribute("data-type")==="editor-container"}function Ge(n){return xe(n,"root")}function Mo(n){return xe(n,"child")}function ce(n){const e=n.getAttribute("data-container-id");return g(g4,e,"no id for container"),Ge(n)&&g(g4,e==="root",`invalid root container id, : ${e}`),e}function p4(n,e){const t=ce(n);return e.getContainerBlocks(t)}const tg=D("block");function ue(n,e){return Ye(n,e).getBlockTextLength(e)}function C4(n){n.editorBlocks.forEach(e=>{e.clearSelection(n)})}function b4(n,e,t,o){Ye(n,e).updateSelection(n,e,t,o)}function ng(n){for(;;){const e=oe(n);if(Ge(e))return n;const t=ne(e);g(tg,t,"no parent block exists for child container"),n=t}}function A4(n,e){const t=Ye(n,e);if(!!t.getMinWidth)return t.getMinWidth(n,e)}function v4(n,e,t){const o=Ye(n,e);o.handleBlockElementUpdated&&o.handleBlockElementUpdated(n,e,t)}function mh(n,e,t,o){try{const r=Ls(n,t).convertFrom;return r?r(n,e,o):null}catch{return tg.debug(`unsupported block type: ${t}`),null}}function zr(n,e,t){const o=Ye(n,e);return o.getClientRects?o.getClientRects(n,e,t):[e.getBoundingClientRect()]}function vx(n,e){const t=Ye(n,e);if(t.getBlockStyles)return t.getBlockStyles(n,e);const o=n.getBlockData(e),r=Object.fromEntries(Object.entries(o).filter(([i])=>i.startsWith("style-")));return Object.entries(r).forEach(([,i])=>{const s=typeof i;g(tg,s==="string"||s==="number"||s==="boolean","invalid style value")}),r}function ut(n,e){return Do(n,e)==="text"?ue(n,e)===0:!1}const y4=D("block-path");function Oi(n){const e=[];let t=n;for(;t;){const o=oe(t);if(e.unshift({containerId:ce(o),blockIndex:Ae(t)}),Ge(o))return e;const r=ne(o);g(y4,r,"no parent block"),t=r}return g(y4,!1,"no parent block"),[]}function yx(n,e){var r,i;const t=Ye(n,e);return(i=(r=t.getOptions)==null?void 0:r.call(t,n))!=null?i:{name:Se(e)}}function co(n){return Ge(oe(n))}function k4(n,e){var r;const t=Ye(n,e);return(r=t.getBlockProperties)==null?void 0:r.call(t,n,e)}function og(n,e){var i,s;const t=Ye(n,e),o=(i=t.getBlockProperties)==null?void 0:i.call(t,n,e);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,e);a&&(r[a.group]=a)}return r}function kx(n,e,t){var s,l,a,d;const o=Ye(n,e),r=(s=o.getBlockProperties)==null?void 0:s.call(o,n,e);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,e);p&&(i[p.group]=p)}return(d=(a=i[t])==null?void 0:a.commands)!=null?d:[]}function w4(n,e,t){let o=e;for(;o;){const r=kx(n,o,t);if(r.length>0)return{element:Le(o),commands:r};if(co(o))break;o=xs(o)}return{element:null,commands:[]}}const B4=D("embed-block-common");function It(n){return Se(n)==="embed"}function mn(n){g(B4,It(n),"not an embed block");const e=n.getAttribute("data-embed-type");return g(B4,e,"no embed data type"),e}function wx(n,e){return n.editorEmbeds.getEmbedClass(mn(e))}function Ms(n,e){return n.editorEmbeds.getEmbedClass(e)}async function rg(n,e,t,o,r){const i=Ms(n,e);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:t,blockIndex:o,data:r})}function Bx(n,e,t,o,r){var l,a;const i=(a=(l=Ls(n,e)).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:t,blockIndex:o,data:r})}const Ex=D("execute-block-command");function E4(n,e,t,o){var d;g(Ex,It(e),"not a embed block");const r=mn(e),i=Ms(n,r);if(!i.getOptions)return;const s=(d=i.getBlockProperties)==null?void 0:d.call(i,n,e),l=s==null?void 0:s.blockCommands;if(!l)return;const a=Object.entries(l);for(const h of a)if(h[0]===t)return h[1].executeCommand(n,e,o)}function x4(n,e,t,o){const r=og(n,e);if(!r)return;const i=Object.entries(r);for(const s of i)if(s[0]===t)return s[1].executeCommand(n,e,o)}const Vr=D("text-block-child");function Da(n){return n.tagName==="SPAN"}function ao(n){return g(Vr,Da(n),"not a valid text child"),n.getAttribute("data-type")==="editor-box"}function Wr(n){return g(Vr,Da(n),"not a valid text child"),n.getAttribute("data-type")==="editor-insertion"}function La(n){return!ao(n)&&!Wr(n)}function I4(n){return g(Vr,Da(n),"not a valid text child"),ao(n)?"box":Wr(n)?"insertion":"text"}function uo(n){const e=I4(n);return e==="insertion"?0:e==="box"?1:(g(Vr,n.textContent!==null,"text block content is undefined"),g(Vr,n.textContent.length>=0,"text block content length is negative"),n.textContent.length)}function ir(n){const e=Le(n),t=Array.from(e.children);return t.forEach(o=>{g(Vr,Da(o),"not a valid text child")}),t}function gh(n,e){const t=ir(n);let o=0;for(let r=0;r<t.length;r++){const i=t[r],s=uo(i);if(o+s<e){o+=s;continue}if(o===e)return{prev:t[r-1],next:i,offset:0};if(o+s===e)return{prev:i,next:t[r+1],offset:0};const l=e-o;return g(Vr,l>0,"invalid offset value"),g(Vr,!ao(i),"invalid box child"),{prev:i,next:i,offset:l}}g(Vr,!1,`invalid block child at position: ${e}`)}const T4=D("element");function ig(n,e,t){const o=k("div",[e],n);return o.setAttribute("data-type","editor-container"),o.setAttribute("data-container-id",t),k("div",["container-blocks"],o),o}function sr(n,e){const t=n.rootElement.querySelector(`[data-container-id=${e}]`);return g(T4,t,`no container: ${e}`),t}function ph(n,e){return n.rootElement.querySelector(`[data-container-id=${e}]`)}function Ch(n){const e=n.querySelector(":scope > .container-blocks");return g(T4,e,"no container blocks element"),e}function xx(n){let e=n.querySelector(":scope > .container-tools");return e||(e=k("div",["container-tools"],n)),e}const Ix=D("child-container-path");function S4(n){if(Ge(n))return[];const e=ne(n);return g(Ix,e,"no parent block"),Oi(e)}const D4=D("load-blocks");function sg(n,e,t){const o=ce(e),r=p4(e,n.doc);g(D4,r.length>0,"no blocks in container");const i=document.createDocumentFragment();r.forEach((l,a)=>{const d=n.editorBlocks.createBlock([...t,{containerId:o,blockIndex:a}],e,l);i.appendChild(d)}),Ch(e).appendChild(i)}function Tx(n,e,t){const o=Ch(n);if(e===0)return o.insertBefore(t,o.firstChild),t;const r=mt(n);return g(D4,e>=0&&e<=r.length,"invalid block index"),e===r.length?o.appendChild(t):o.insertBefore(t,r[e]),t}function Sx(n,e,t,o){const r=S4(e);r.push({containerId:ce(e),blockIndex:t});const i=n.editorBlocks.createBlock(r,e,o);return Tx(e,t,i),i}const L4=D("root-container");class Dx{constructor(e,t){m(this,"resizeObserver");m(this,"handleContextMenu",e=>{});m(this,"handleResize",()=>{try{this.editor.selection.updateSelection(null),this.editor.emit("resize",this.editor)}catch(e){L4.warn(`failed to update selection while container resizing: ${e.message}`)}});m(this,"handleClick",e=>{this.editor.emit("click",this.editor,e);const t=e.target;if(!Ds(t)&&(e.detail===1&&this.editor.input.focus(),e.detail===3&&this.editor.selectionHandler.handleTripleClick(e),e.detail===1&&e.button===0)){const o=document.elementFromPoint(e.clientX,e.clientY);if(o&&et(this.rootContainer,o)){const r=ne(o);r&&et(r,o)&&this.handleBlockClick(e,r,o)}}});m(this,"handleBlockClick",(e,t,o)=>{var s,l;if(!te(this.editor,t))return;const r=Jm(o);if(r){const a=ne(r);g(L4,a,"no parent block"),(l=(s=this.editor.editorBoxes.getBoxClass(Ta(r)))==null?void 0:s.handleClickBox)==null||l.call(s,this.editor,r,e);return}const i=o.closest("span.text.link");i&&ir(t).indexOf(i)!==-1&&this.editor.emit("clickLink",this.editor,e,i)});m(this,"handleDblClick",e=>{Ds(e.target)||this.editor.selectionHandler.handleDblClick(e)});m(this,"handleMouseDown",e=>{const t=e.target;if(!!t&&t instanceof Node&&!Ds(t)){if(t instanceof HTMLElement&&t.draggable){this.editor.selectionHandler.handleMouseDown(e,{autoScroll:!1}),this.editor.selectionHandler.stopSelection(),this.editor.input.focus();return}e.button===0&&(document.addEventListener("mousemove",this.handleMouseMove),document.addEventListener("mouseup",this.handleMouseUp),this.editor.selectionHandler.handleMouseDown(e,{autoScroll:!0})),Zt.isMobileSafari||(e.preventDefault(),this.editor.input.focus()),e.button===2&&e.stopPropagation()}});m(this,"handleMouseMove",e=>{this.editor.selectionHandler.handleMouseMove(e)});m(this,"handleMouseUp",e=>{e.button===0&&(this.editor.selectionHandler.handleMouseUp(e),document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp))});this.editor=e,this.rootContainer=t,this.editor=e,this.resizeObserver=new bs(this.handleResize),this.bindEvents(t)}bindEvents(e){this.resizeObserver.observe(e);const t=this.editor.rootElement;t.onmousedown=this.handleMouseDown,t.ondblclick=this.handleDblClick,t.onclick=this.handleClick,t.oncontextmenu=this.handleContextMenu}unbindEvents(){this.resizeObserver.disconnect();const e=this.editor.rootElement;e.onmousedown=null,e.ondblclick=null,e.onclick=null,e.oncontextmenu=null}destroy(){this.unbindEvents()}reload(){const e=this.editor.selection.range,t=Ch(this.rootContainer);t.innerHTML="",sg(this.editor,this.rootContainer,[]);const o=this.editor.findBlockById(e.start.blockId);if(o)this.editor.selection.selectBlock(o,0);else{const r=yt(this.rootContainer);this.editor.selection.selectBlock(r,0)}}}function M4(n){const e=ig(n.contentElement,"root","root");return n.rootContainer=e,sg(n,e,[]),new Dx(n,e)}function R4(n,e,t,o){const r=ph(n,o);if(r)return t.appendChild(r),setTimeout(()=>{n.emit("containerRemount",n,o)}),r;const i=ig(t,"child",o);return sg(n,i,e),i}function O4(n,e){const t=n.getBoundingClientRect().width;return e.withPadding?t:t-Mm(n)}function lg(n,e){let t=Number.MAX_SAFE_INTEGER;const o=mt(e);for(let i=0;i<o.length;i++){const s=o[i],l=A4(n,s);l&&(t=Math.min(t,l))}return t===Number.MAX_SAFE_INTEGER?void 0:t+Mm(e)}function Ma(n,e){const t=mt(e);return t.length!==1?!1:ut(n,t[0])}const Lx=D("complex-block-position");class Ro{constructor(e,t,o){m(this,"blockId");m(this,"childContainerId");m(this,"custom");e instanceof HTMLElement?this.blockId=ie(e):(g(Lx,typeof e=="string",`not a valid block id: ${e}`),this.blockId=e),this.childContainerId=t,o!==void 0&&(this.custom=o)}isSimple(){return!1}}const Mx=D("simple-block-position");class Ut{constructor(e,t,o){m(this,"blockId");m(this,"offset");m(this,"type");e instanceof HTMLElement?this.blockId=ie(e):(g(Mx,typeof e=="string",`not a valid block id: ${e}`),this.blockId=e),this.offset=t,this.type=o}isSimple(){return!0}}const cg=D("editor-position");function se(n,e,t){return new Ut(n,e,t)}function ft(n,e,t){return new Ro(n,e,t)}function qr(n){return n instanceof Ut}function ql(n){return n instanceof Ro}function ag(n,e,t){if(qr(e)&&qr(t)){const o=e,r=t;if(o.blockId===r.blockId)return o.offset-r.offset;const i=n.getBlockById(e.blockId),s=n.getBlockById(t.blockId);return g(cg,i!==s,"comparePosition: blocks are the same"),th(i,s)}if(ql(e)&&ql(t)){const o=e,r=t;if(o.childContainerId===r.childContainerId)return 0;const i=n.getContainerById(o.childContainerId),s=n.getContainerById(r.childContainerId);return g(cg,i!==s,"comparePosition: containers are the same"),th(i,s)}return g(cg,!1,"invalid "),0}const bh=D("simple-range");class Yt{constructor(e,t){m(this,"editor");m(this,"_anchor");m(this,"_focus");m(this,"reverse");this.editor=e,this._anchor=t.anchor,this._focus=t.focus,this.reverse=ag(this.editor,this._anchor,this._focus)>0}isCollapsed(){return this.start.blockId===this.end.blockId&&this.start.offset===this.end.offset}isEqual(e){if(!(e instanceof Yt))return!1;const t=e,{start:o,end:r}=t;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:e}=this,t=e.getBlockById(this.start.blockId),o=e.getBlockById(this.end.blockId);g(bh,t,"no start block"),g(bh,o,"no end block");const r=oe(t),i=oe(o);g(bh,r===i,"invalid range");const s=[];if(t===o)s.push({block:t,start:this.start,end:this.end});else{const l=Ae(t),a=Ae(o);g(bh,l<a,"invalid range, start > index"),s.push({block:t,start:this.start,end:se(t,ue(this.editor,t),"end")});const d=mt(r);for(let h=l+1;h<a;h+=1){const p=d[h];s.push({block:p,start:se(p,0,"home"),end:se(p,ue(this.editor,p),"end")})}s.push({block:o,start:se(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 Yt(this.editor,this)}toDocRange(){return{anchor:this.anchor,focus:this.focus}}static from(e,t){return new Yt(e,t)}}D("unknown-block");function Rx(n,e,t,o,r){W(o,"unknown-block");const i=Is(o,"div");return i.innerText=`unknown block (${r.type}): ${JSON.stringify(r)}`,i}function Ox(n){return 1}function _x(n,e,t,o){return null}function Fx(n,e,t,o){const r=document.elementsFromPoint(t,o)[0];if(!r||!e.contains(r)||!n.contains(e))return null;const i=ie(e),s=se(i,0,"home"),l=se(i,1,"end");return new Yt(n,{anchor:s,focus:l})}function Px(n,e){const o=Le(n).getBoundingClientRect();return new DOMRect(o.left+o.width/2,o.top,1,o.height)}function Nx(n,e,t,o){W(e,"selected")}function $x(n){n.rootContainer.querySelectorAll("div.unknown-block[data-type=editor-block]").forEach(e=>{re(e,"selected")})}function Hx(n,e,t,o){return`[unknown block, ${e.type}]`}const jx={blockType:"unknown-block",blockKind:"embed",createBlockContent:Rx,getBlockTextLength:Ox,getRangeFromPoint:Fx,moveCaret:_x,getCaretRect:Px,updateSelection:Nx,clearSelection:$x,convertTo:Hx},ug=D("editor-blocks");class _4{constructor(e){m(this,"blocks",new Map);this.editor=e}registerBlockClass(e){const t=e.blockType,o=this.blocks.get(t);g(ug,!o,`duplicated block type: ${t}`),this.blocks.set(t,e)}getBlockClass(e){const t=this.blocks.get(e);return g(ug,t,`unknown block type: ${e}`),t}hasBlock(e){return this.blocks.has(e)}createBlock(e,t,o){const r=s4(this.editor,e,o);let i;this.hasBlock(o.type)?i=this.getBlockClass(o.type):i=this.registerUnknownBlock(o.type);const s=i.createBlockContent(this.editor,e,t,r,o);return s.parentElement!==r&&(ug.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,e,t,r,o)}),r}forEach(e){this.blocks.forEach(e)}registerUnknownBlock(e){const t={...jx,blockType:e};return this.editor.editorBlocks.registerBlockClass(t),t}}const F4=D("editor-embeds");class P4{constructor(e){m(this,"objects",new Map);this.editor=e}registerEmbedClass(e){const t=e.embedType,o=this.objects.get(t);g(F4,!o,`duplicated embed object type: ${t}`),this.objects.set(t,e)}getEmbedClass(e){const t=this.objects.get(e);return g(F4,t,`unknown embed type: ${e}`),t}getEmbedClassFromBlock(e){return this.getEmbedClass(mn(e))}forEach(e){this.objects.forEach(e)}}const N4=D("embed-block");function Ux(n,e,t,o,r){const i=Is(o,"div");g(N4,r.type==="embed",`not an embed data: ${JSON.stringify(r)}`);const s=r;return g(N4,s.embedType&&s.embedData,`not an embed data: ${JSON.stringify(s)}`),n.editorEmbeds.getEmbedClass(s.embedType).createEmbedContent(n,i,s,e,t,o),o.setAttribute("data-embed-type",s.embedType),i}function zx(n){return 1}function Vx(n,e,t,o){return null}function Wx(n,e,t,o){const r=document.elementsFromPoint(t,o)[0];if(!r||!e.contains(r)||!n.contains(e))return null;const i=ie(e),s=se(i,0,"home"),l=se(i,1,"end");return new Yt(n,{anchor:s,focus:l})}function qx(n,e){const o=Le(n).getBoundingClientRect();return new DOMRect(o.left+o.width/2,o.top,1,o.height)}function Gx(n,e,t,o){W(e,"selected")}function Zx(n){n.rootContainer.querySelectorAll("div.embed-block[data-type=editor-block][data-block-type=embed]").forEach(e=>{re(e,"selected")})}function Qx(n,e,t){let o=null;return n.editorEmbeds.forEach(r=>{var s,l;const i=(l=(s=r.convertFrom)==null?void 0:s.call(r,n,e,t))!=null?l:null;i&&(o=i)}),o}function Yx(n,e,t,o){const r=Ms(n,e.embedType);return r.convertTo?r.convertTo(n,e,t,o):""}function Jx(n,e){const t=wx(n,e);return t.getBlockProperties?t.getBlockProperties(n,e):{}}function Kx(n){const e=new Map,t=[];return n.editorEmbeds.forEach(o=>{if(o.getOptions){const r=o.getOptions(n);r.insertEmbedCommandItems&&r.insertEmbedCommandItems.forEach(i=>{t.push(i),e.set(i.id,o)})}}),{name:"EmbedBlock",insertBlockCommandItems:t,async handleInsertEmptyBlock(o,r){const i=e.get(r.item.id);if(!i||!i.getOptions)return null;const s=i.getOptions(o);return s.handleInsertEmptyEmbed?s.handleInsertEmptyEmbed(o,r):null}}}function Xx(n,e,t,o){const r=mn(e),i=Ms(n,r);!i.handleDeleteBlock||i.handleDeleteBlock(n,e,t,o)}function eI(n,e,t){const o=mn(e),r=Ms(n,o);return r.handleUpdateBlock?r.handleUpdateBlock(n,e,t):!1}function tI(n,e,t,o,r){const i=mn(e),s=Ms(n,i);if(s.handleDropOver)return s.handleDropOver(n,e,t,o,r)}function nI(n,e,t,o,r){const i=mn(e),s=Ms(n,i);if(s.handleDrop&&n.isWritable())return s.handleDrop(n,e,t,o,r)}async function oI(n,e,t){const o=e.embedType,r=n.editorEmbeds.getEmbedClass(o);if(r.toStandardDoc){const i=n.getBlockById(e.id),s=Oi(i);return r.toStandardDoc(n,e,t,s)}}const $4={blockType:"embed",blockKind:"embed",createBlockContent:Ux,getBlockTextLength:zx,getRangeFromPoint:Wx,moveCaret:Vx,getCaretRect:qx,updateSelection:Gx,clearSelection:Zx,convertFrom:Qx,convertTo:Yx,getBlockProperties:Jx,getOptions:Kx,handleDeleteBlock:Xx,handleUpdateBlock:eI,handleDropOver:tI,handleDrop:nI,toStandardDoc:oI},gn=D("complex-block-helper");function pn(n,e,t){return zn(n,e).getChildContainers(n,e,t)}function Gl(n,e,t,o){return t.isSimple()?(g(gn,o.isSimple(),"invalid start and end position"),pn(n,e)):(g(gn,!t.isSimple(),"invalid start pos"),g(gn,!o.isSimple(),"invalid end pos"),zn(n,e).getSelectedContainers(n,e,t,o))}function rI(n,e){if(Ae(e)!==0)return!1;const t=ne(oe(e));if(!t)return!1;g(gn,Me(n,t),"not a complex block");const o=oe(e),i=pn(n,t).indexOf(o);return g(gn,i>=0,"not valid child container"),i===0}function dg(n,e,t){const o=pn(n,e,t);if(o.length===0)return null;const r=o[0];if(!r)return null;const i=yt(r);return Me(n,i)?dg(n,i,t):i}function Zl(n,e,t){const o=pn(n,e,t);if(o.length===0)return null;const r=o[o.length-1];if(!r)return null;const i=Qt(r);return Me(n,i)?Zl(n,i,t):i}function H4(n,e){g(gn,Mo(e),"not a child container");const t=ne(e);g(gn,t,"no parent block"),g(gn,Me(n,t),"not a complex block");const o=pn(n,t),r=o.indexOf(e);if(g(gn,r!==-1,"child container not found"),r===0){const l=at(t);return l?Me(n,l)?Zl(n,l):l:null}const i=o[r-1],s=Qt(i);return Me(n,s)?Zl(n,s):s}function j4(n,e){g(gn,Me(n,e),"not a complex block");const t=pn(n,e);if(g(gn,t.length>0,"no child container"),t.length===1)return t;const o=t[0],r=o.getBoundingClientRect();let i=r.left,s=r.right;const l=[o];for(let a=1;a<t.length;a++){const d=t[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 U4(n,e){g(gn,Me(n,e),"not a complex block");const t=pn(n,e);if(g(gn,t.length>0,"no child container"),t.length===1)return t;const o=t[t.length-1],r=o.getBoundingClientRect();let i=r.left,s=r.right;const l=[o];for(let a=t.length-2;a>=0;a--){const d=t[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 z4(n,e,t,o){const r=e.getBoundingClientRect(),i=o<r.top,s=i?j4(n,e):U4(n,e);let l=s[0],a=or(l.getBoundingClientRect(),t,o);for(let d=1;d<s.length;d++){const h=s[d],p=h.getBoundingClientRect(),C=or(p,t,o);C<a&&(l=h,a=C)}return i?yt(l):Qt(l)}function Ah(n,e,t,o){const r=ie(e);g(gn,r===t.blockId,"invalid start pos"),g(gn,r===o.blockId,"invalid end pos");const i=zn(n,e);return i.adjustSelectionPos?i.adjustSelectionPos(n,e,t,o):{anchor:t,focus:o}}class lr{constructor(e,t){m(this,"editor");m(this,"reverse");m(this,"_anchor");m(this,"_focus");this.editor=e,this._anchor=t.anchor,this._focus=t.focus,this.reverse=ag(this.editor,this._anchor,this._focus)>0}isCollapsed(){return!1}isEqual(e){if(!(e instanceof lr))return!1;const t=e,{anchor:o,focus:r}=t;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 e=this.start,t=this.end;return[{block:this.editor.getBlockById(e.blockId),start:e,end:t}]}getAnchorPos(){return this._anchor}getFocusedPos(){return this._focus}getSelectedContainers(){const e=this.editor.getBlockById(this._anchor.blockId);return Gl(this.editor,e,this.start,this.end)}clone(){return new lr(this.editor,this)}toDocRange(){return{anchor:this._anchor,focus:this._focus}}}const iI=D("selection-range");function zt(n,e){const{anchor:t,focus:o}=e;return t instanceof Ut&&o instanceof Ut?new Yt(n,{anchor:t,focus:o}):(g(iI,t instanceof Ro&&o instanceof Ro,"start position type does not math end type"),new lr(n,{anchor:t,focus:o}))}function kt(n,e,t,o){const r=new Ut(e,t,"normal"),i=new Ut(e,o!=null?o:t,"normal");return zt(n,{anchor:r,focus:i})}function sI(n){return!!n.anchor.childContainerId}function _i(n,e){var r,i;if(sI(e)){const s=ft(e.anchor.blockId,e.anchor.childContainerId,(r=e.anchor)==null?void 0:r.custom),l=ft(e.focus.blockId,e.focus.childContainerId,(i=e.focus)==null?void 0:i.custom);return zt(n,{anchor:s,focus:l})}const t=se(e.anchor.blockId,e.anchor.offset,"normal"),o=se(e.focus.blockId,e.focus.offset,"normal");return zt(n,{anchor:t,focus:o})}const V4=D("range-from-point");function vh(n,e,t){const o=[0,-8,8];for(let r=0;r<o.length;r++){const i=document.elementsFromPoint(e,t+o[r])[0];if(!i)continue;const s=i.getBoundingClientRect();if(i.clientWidth&&i.clientHeight&&r===0&&(s.left+i.clientWidth<e||s.top+i.clientHeight<t))return V4.debug("click on scrollbar, out of element rect"),null;if(!n.rootContainer.contains(i))continue;const l=ne(i);if(!l||!n.contains(l))continue;const a=Ye(n,l).getRangeFromPoint(n,l,e,t+o[r]);if(a)return a}return null}function W4(n,e,t,o){const r=e.getBoundingClientRect();if(o<=r.top){const a=yt(e),d=Ye(n,a).getRangeFromPoint(n,a,t,a.getBoundingClientRect().top+4);if(d!=null&&d.isSimple())return Yt.from(n,d);const h=se(a,0,"home");return new Yt(n,{anchor:h,focus:h})}const i=Qt(e),s=Ye(n,i).getRangeFromPoint(n,i,t,i.getBoundingClientRect().bottom-4);if(s!=null&&s.isSimple())return Yt.from(n,s);const l=se(i,ue(n,i),"end");return new Yt(n,{anchor:l,focus:l})}function q4(n,e,t){const o=vh(n,e,t);if(o){if(o instanceof Yt)return o;g(V4,o instanceof lr,`invalid range type: ${typeof o}`);const a=o,d=n.getContainerById(a.start.childContainerId);return W4(n,d,e,t)}const r=document.elementsFromPoint(e,t)[0];if(!r)return null;const{children:i}=r,s=Array.from(i).filter(a=>Ur(a));if(s.length===0)return null;const l=s.reduce((a,d)=>{const h=a.getBoundingClientRect(),p=d.getBoundingClientRect();return or(h,e,t)>or(p,e,t)?d:a});return W4(n,l,e,t)}function hg(n,e){const t=[];return mt(e).forEach(r=>{t.push(r),Me(n,r)&&pn(n,r).forEach(s=>{t.push(...hg(n,s))})}),t}function fg(n,e){let t=hg(n,n.rootContainer);return e!=null&&e.simpleBlockOnly&&(t=t.filter(o=>!Me(n,o))),t}function cr(n,e){const t=n.selection.range.getSelectedBlocks(),o=[];for(const r of t)o.push(r),Me(n,r.block)&&Gl(n,r.block,r.start,r.end).forEach(s=>{const a=hg(n,s).map(d=>({block:d,start:se(d,0,"home"),end:se(d,ue(n,d),"home")}));o.push(...a)});return e!=null&&e.simpleBlockOnly?o.filter(r=>!Me(n,r.block)):o}const Xne="",Jt=D("text-range");function lI(n,e){const t=(i,s)=>{if(Wr(i))return g(Jt,s===0,`invalid offset for insertion child: ${s}`),{child:i,container:i,offset:2};if(ao(i))return g(Jt,s===0||s===1,`invalid offset for box: ${s}`),{child:i,container:i,offset:s===0?1:2};const l=i.firstChild;return g(Jt,l,"no child node for text child"),g(Jt,l instanceof Text||l instanceof HTMLBRElement,`invalid child for text child, ${l.nodeName}`),l instanceof HTMLBRElement?(g(Jt,s>=0&&s<=0,"invalid offset for text child"),{child:i,container:l,offset:s}):(g(Jt,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=uo(s);if(e===o)return[t(s,0)];if(e<o+l)return[t(s,e-o)];if(e===o+l){const a=[];a.push(t(s,uo(s)));const d=r[i+1];return d&&a.push(t(d,0)),a}o+=l}g(Jt,!1,"failed to get range info")}function cI(n,e,t){if(e===t?g(Jt,Wr(n),"only insertion child can be zero offset"):g(Jt,e<t,`invalid start & end: ${e}, ${t}`),Wr(n)){g(Jt,e===t,`invalid insertion child range offset: ${e}, ${t}`),g(Jt,e===0,`invalid insertion child range start: ${e}`);const i=n;return g(Jt,i.children.length===3,`invalid insertion dom, children.length = ${i.children.length}`),Xd(i,1,i,2)}if(ao(n)){g(Jt,e+1===t,`invalid box child range offset: ${e}, ${t}`),g(Jt,e===0,`invalid box child range start: ${e}`);const i=n;return g(Jt,i.children.length===3,`invalid box dom, children.length = ${i.children.length}`),Xd(i,1,i,2)}const o=uo(n);g(Jt,t<=o,`invalid child end: ${t}, ${o}`);const r=n.firstChild;return g(Jt,r instanceof Text,"invalid block text child"),g(Jt,r.data.length>=t,`invalid range end: ${t}, ${r.data.length}`),Xd(r,e,r,t)}const Oo=D("caret-rect");function aI(n,e){if(Ym(e)){const t=e,o=Km(t);if(t.getAttribute("data-box-type")==="br"){const r=Le(n),i=Number.parseFloat(window.getComputedStyle(r).lineHeight)||o.getBoundingClientRect().height,s=Array.from(o.getClientRects());g(Oo,s.length>0,"no box client rects");const l=r.getBoundingClientRect(),a=s[0],d=new DOMRect(l.left,a.bottom,1,i);return s.push(d),s}return o.getClientRects()}return Xm(e).getClientRects()}function Vn(n,e){var l,a,d;const t=lI(n,e.offset);if(t[1]&&t[0].child!==((l=t[1])==null?void 0:l.child)){if(e.type==="end"){const p=vs(t[0].child);return new DOMRect(p.right,p.top,1,p.height)}g(Oo,t[1],"invalid ranges");const h=eh(t[1].child);return new DOMRect(h.left,h.top,1,h.height)}let r=t[0];if(g(Oo,t.length>=1,"failed to get block range"),t.length===1)r=t[0];else{if(g(Oo,t.length>=2,`invalid range info length: ${t.length}`),Wr(t[t.length-1].child)){r=t[t.length-1];const h=r.child,C=Xm(h).getClientRects();g(Oo,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)}e.type==="home"?r=t[1]:e.type==="end"||La(t[0].child)?r=t[0]:La(t[1].child)&&(r=t[1])}if(r.container instanceof HTMLBRElement){g(Oo,e.offset===0,"invalid offset for empty block text");const h=r.container.parentElement;g(Oo,h,"invalid br parent");const p=h.getBoundingClientRect();return new DOMRect(p.left,p.top,1,p.height)}const i=C5(r.container,r.offset),s=Array.from(i.getClientRects());if(s.length===0){g(Oo,!La(r.child),"only box or insertion child range has zero client rect"),g(Oo,r.offset===1||r.offset===2,"invalid offset for box or insertion child");const h=r.child,p=aI(n,h);if(g(Oo,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 e.type==="end"||r.offset===2?new DOMRect(C.right,C.y,1,C.height):new DOMRect(C.x,C.y,1,C.height)}if(wa()||zl()){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,S)=>{if(Math.floor(v[0].top)!==Math.floor(s[0].top)&&Math.floor(v[0].top)===Math.floor(B.top)){const{x,y:_,height:M}=p[S];s.length===1&&e.type==="home"&&s.push(new DOMRect(x,_,0,M))}})}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,S)=>{if(Math.floor(v[0].top)!==Math.floor(s[0].top)&&Math.floor(v[0].top)===Math.floor(B.top)){const{y:x,height:_,right:M}=p[S];s.length===1&&e.type==="end"&&s.unshift(new DOMRect(M,x,0,_))}})}}return g(Oo,s.length>0,"no client rects for range"),e.type==="home"?s[s.length-1]:s[0]}const uI=D("core");function Gr(n,e,t,o){const r=tt(e);let i=r.querySelector(`.block-anchor[data-id=${t}]`);i||(i=k("div",["block-anchor"],r),i.setAttribute("data-id",t));const s=o!=null?o:e.getBoundingClientRect(),l=e.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 G4(n,e,t,o){g(uI,te(n,e),"not a text kind block");const r=Vn(e,se(e,t,"normal")),i=e.getBoundingClientRect(),s=tt(e);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 Ra(n){const e=ir(n);let t=0;return e.forEach(o=>{t+=uo(o)}),t}const Z4=D("box");function Oa(n){return!n.attributes||!n.attributes.box?!1:(g(Z4,n.attributes.box===!0,`invalid op attribute box property, ${n.attributes.box}`),g(Z4,n.attributes.type,`no box type: ${JSON.stringify(n)}`),!0)}const Q4=D("rich-text-length");function mg(n){return g(Q4,typeof n.insert=="string","op.insert is not string"),n.insert.length}function sn(n){let e=0;return n.forEach(t=>{t.insert&&(g(Q4,typeof t.insert=="string","op.insert is not string"),e+=mg(t))}),e}const ar=D("split-text");function Tn(n,e,t){if(n=me.default(n),e===0)return{left:[],right:n};if(e===-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=mg(i);if(o+s<e)o+=s;else{if(o+s===e)return{left:n.slice(0,r+1),right:n.slice(r+1)};{g(ar,o+s>e,`invalid offset, ${o}, ${s}, ${e}`);const l=e-o,a=me.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 t&&(t.sourceOp=i),{left:h,right:d}}}}throw new Error(`invalid split offset: ${e}, ${JSON.stringify(n)}`)}function Vt(n,e,t){g(ar,e>=0,"invalid offset, < 0"),g(ar,t>0,"invalid length, <= 0"),g(ar,e+t<=sn(n),"invalid offset + length < text length");const{left:o,right:r}=Tn(n,e+t),{left:i,right:s}=Tn(o,e);return{left:i,middle:s,right:r}}function Y4(n,e){const t=Array.from(new Set(e)).sort((i,s)=>i-s),o=[];let r=n;for(let i=t.length-1;i>=0;i--){const s=t[i],{left:l,right:a}=Tn(r,s);r=l,o.unshift(a)}return r.length>0&&o.unshift(r),o}function J4(n,e,t){return Vt(n,e,t).middle}const Ql=D("text-block-content");function dI(n,e,t,o,r){if(g(Ql,o,"no text for block"),o.length===0&&(!r||r.size===0)){t.innerHTML="<span><br></span>";return}const i=[];r&&i.push(...r.keys());const s=p=>n.editorInsertions.createInsertion(t,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=Y4(o,i);for(let p=0;p<h.length;p++){l(a,d);const C=h[p];d+=sn(C);for(let v=0;v<C.length;v++){const B=C[v];if(Oa(B)){g(Ql,B.attributes,`op is not an valid box: ${JSON.stringify(B)}`);const x=n.editorBoxes.createBox(t,B.attributes);g(Ql,x instanceof HTMLSpanElement,`invalid box element: ${x.tagName}`),a.appendChild(x);continue}g(Ql,B.insert,`no insert in op: ${JSON.stringify(B)}`);const S=k("span",["text"],a,B.insert);if(B.attributes){const x=n.editorBlockRenders.renderText(e,B.attributes);x.classes&&W(S,...x.classes),x.attributes&&Object.entries(x.attributes).forEach(([_,M])=>{S.setAttribute(_,M)}),x.styles&&Object.entries(x.styles).forEach(([_,M])=>{S.style.setProperty(_,M)})}a.appendChild(S)}}l(a,d),t.innerHTML="",t.appendChild(a)}function yh(n,e,t,o,r){const{text:i,insertions:s}=n.editorDecorators.decorateText(e,r),l=n.compositingText;if(l){const a=n.selection.range.start;g(Ql,a.isSimple(),"not an simple position while compositing"),a.blockId===t&&s.set(a.offset,[{type:"inputting",id:K(),text:l}])}return dI(n,e,o,i,s)}function hI(n){const e=n.rootContainer.querySelectorAll('span[data-type="editor-insertion"].inputting-insertion');e.length&&Ql.debug(`remove ${e.length} temp composition span`),Array.from(e).forEach(t=>t.remove())}const ur=D("client-rects");function fI(n){const e=ir(n);let t=0;const o=[];for(let r=0;r<e.length;r++){const i=e[r],s=uo(i);o.push({child:i,startBlockOffset:t,endBlockOffset:t+s}),t+=s}return o}function mI(n,e,t,o){g(ur,t<o,`invalid from & to: ${t}, ${o}`);const r=ue(n,e);g(ur,t>=0&&o>=0&&t<=r&&o<=r,`invalid offset: ${t}, ${o}, length: ${r}`);const i=fI(e),s=i.findIndex(v=>v.startBlockOffset<=t&&t<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:t-v.startBlockOffset,endChildOffset:o-v.startBlockOffset}]}const a=[],d=i[s],h={child:d.child,startChildOffset:t-d.startBlockOffset,endChildOffset:uo(d.child)};a.push(h);for(let v=s+1;v<l;v++){const B=i[v],S={child:B.child,startChildOffset:0,endChildOffset:B.endBlockOffset-B.startBlockOffset};a.push(S)}const p=i[l],C={child:p.child,startChildOffset:0,endChildOffset:o-p.startBlockOffset};return a.push(C),a}function gI(n){const e=(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=>e(o,i)));const t=[];return n=n.filter(o=>t.find(r=>r.left===o.left&&r.top===o.top&&r.width===o.width&&r.height===o.height)?!1:(t.push(o),!0)),n}function K4(n,e,t,o){if(ue(n,e)===0){const h=Le(e).getBoundingClientRect();return[new DOMRect(h.left,h.top,4,h.height)]}const r=t.offset,i=o.offset;if(r===i)return[Vn(e,t)];const l=mI(n,e,r,i).map(d=>cI(d.child,d.startChildOffset,d.endChildOffset)),a=[];return l.forEach(d=>{const h=gI(Array.from(d.getClientRects()));a.push(...h)}),a}function pI(n,e,t){g(ur,t instanceof Yt,"invalid range");const o=t.start,r=t.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===ie(e),"only allow update one text block selection"),K4(n,e,o,r)}const gg=D("selection-background");function CI(n,e,t,o){g(gg,t.isSimple(),"text block only allow simple position"),g(gg,o.isSimple(),"text block only allow simple position"),g(gg,t.blockId===o.blockId,"only allow update one text block selection");const r=t.offset,i=o.offset;if(r===i&&(ue(n,e)!==0||n.selection.range.isCollapsed()))return;const s=K4(n,e,t,o),l=e.getBoundingClientRect(),a=io(e),d=i4(e);d.innerHTML="",s.forEach(h=>{const p=k("div",["editor-selection-background"],d);p.style.left=`${(h.left-l.left-e.clientLeft)/a}px`,p.style.top=`${(h.top-l.top-e.clientTop)/a}px`,p.style.width=`${h.width/a}px`,p.style.height=`${h.height/a}px`})}function bI(n){n.rootContainer.querySelectorAll("div[data-type=block-background]").forEach(e=>{e.remove()})}const Rs=D("text-offset"),X4="\u200D";function Os(n,e){const t=ir(n);let o=0;for(let r=0;r<t.length;r++){const i=t[r],s=uo(i);if(i===e){const l=o+s;return{start:o,end:l}}o+=s}g(Rs,!1,"can not find child in children")}function ln(n,e){g(Rs,e>=0,`invalid offset: ${e}`);const t=gh(n,e),{prev:o,next:r,offset:i}=t;if(!o&&!r&&g(Rs,!1,"invalid offset, no prev & next child at offset"),o!==r)return!0;const s=o;if(g(Rs,s,"no child"),ao(s))return g(Rs,i===0||i===1,`invalid box child offset: ${i}`),!0;const l=s.textContent;g(Rs,l,"no content for text child");const a=l.charAt(i-1),d=l.charAt(i);return!(a===X4||d===X4||Dm(l[i]))}function Fi(n,e){if(e===0)return 0;const t=e-1;if(ln(n,t))return t;let o=t-1;for(;!ln(n,o);)o-=1;return o}function _s(n,e){const t=Ra(n);if(g(Rs,e>=0&&e<=t,`invalid offset: ${e}, ${t}`),e===t)return t;const o=e+1;if(ln(n,o))return o;let r=o+1;for(;!ln(n,r);)r+=1;return r}const Fs=D("line-breaker");function _a(n){const e=a=>{const d=eh(a);return vs(a).top>d.top+d.height/2},t=(a,d)=>{const h=vs(a),p=eh(d);return Math.floor(p.left)<Math.floor(h.right)},o=(a,d)=>{const h=vs(a),p=vs(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 Math.floor(d.right)-Math.floor(h.left)>10},i=[];let s=0;const l=ir(n);for(let a=0;a<l.length;a++){const d=l[a];if(Wr(d)){const x=d,_=l[a+1];if(!_)break;const M=l[a-1];if(M&&o(M,x)&&i.push({offset:s,type:"betweenChild",childInfo:{prevChild:M,nextChild:x,wrap:"nextWrapped",prevWrapped:e(M),nextWrapped:e(x)}}),t(x,_)){i.push({offset:s,type:"betweenChild",childInfo:{prevChild:M,nextChild:x,wrap:"nowrap",prevWrapped:e(M),nextWrapped:e(x)}});continue}continue}if(ao(d)){const x=d,_=l[a+1];if(!_)break;const M=l[a-1];if(M&&o(M,x)&&i.push({offset:s,type:"betweenChild",childInfo:{prevChild:M,nextChild:x,wrap:"nextWrapped",prevWrapped:e(M),nextWrapped:e(x)}}),t(x,_)){s+=1,i.push({offset:s,type:"betweenChild",childInfo:{prevChild:M,nextChild:d,wrap:"nowrap",prevWrapped:e(M),nextWrapped:e(d)}});continue}s+=1;continue}const h=d,p=h.getClientRects();if(g(Fs,p.length>0,"invalid text child dom"),p.length===1){const x=l[a+1];if(!x)break;if(t(h,x)){s+=uo(h),i.push({offset:s,type:"betweenChild",childInfo:{prevChild:h,nextChild:x,wrap:"nowrap",prevWrapped:e(h),nextWrapped:e(x)}});continue}s+=uo(h);continue}const C=h.firstChild;g(Fs,C,"invalid text child, no text node"),g(Fs,C instanceof Text,`invalid text child, not a valid text node: ${typeof C}`);const v=document.createRange(),B=document.createRange(),S=uo(h);g(Fs,C.data.length===S,"text node data length not equal child text length");for(let x=0;x<C.data.length;x++){if(!ln(n,s+x))continue;v.setStart(C,x);const _=v.getClientRects();if(g(Fs,_.length>=1,"invalid text node, no client rects"),r(_)){const ee=s+x;i.push({offset:ee,type:"textBreakWord",childInfo:{prevChild:d,nextChild:d,wrap:"nowrap",prevWrapped:e(d),nextWrapped:e(d)}});continue}let M=x+1;ln(n,s+M)||(M=x+2),B.setStart(C,M);const H=B.getClientRects(),z=_[0],Z=H[0];if(Math.floor(Z.left)<Math.floor(z.right))if(wa()||zl()){i.push({offset:zl()?s+M:s+x,type:"textBreakWord",childInfo:{prevChild:d,nextChild:d,wrap:"nowrap",prevWrapped:e(d),nextWrapped:e(d)}});continue}else g(Fs,!1,"span pre-wrap should not has a line-wrap by white space")}s+=S}return i}function pg(n,e){const t=_a(n);for(let o=0;o<t.length;o++){const{offset:r,type:i}=t[o];if(e.offset<r)return{lineIndex:o,lineBreaks:t};if(e.offset===r&&e.type==="end")return{lineIndex:o,lineBreaks:t}}return g(Fs,e.offset<=Ra(n),"invalid position, offset > block length"),{lineIndex:t.length,lineBreaks:t}}const AI=D("line-offset");function Cg(n){const e=_a(n),t=[];let o=0;for(let r=0;r<e.length;r++){const i=e[r];t.push({start:o,end:i.offset}),o=i.offset}return t.push({start:o,end:Ra(n)}),t}function kh(n,e){const t=Cg(n);return g(AI,e>=0&&e<t.length,`invalid line index: ${e}, ${t.length}`),t[e]}function e6(n,e){const{lineIndex:t}=pg(n,e);return kh(n,t)}function vI(n){const e=Cg(n),t=n.getBoundingClientRect(),o=[];return e.forEach(({start:r,end:i})=>{const s=se(n,r,"home");let l=Vn(n,s);const a=se(n,i,"end"),d=Vn(n,a);l.top+l.height/2<d.top&&(l=new DOMRect(t.left-1e4,d.top,1,d.height));const h=new DOMRect(l.left,d.top,d.left-l.left,d.height),p=new DOMRect(t.left,d.top,t.width,d.height);o.push({start:r,end:i,rect:p,contentRect:h})}),o}function yI(n,e,t){const r=vI(n).find(s=>ks(s.rect,e,t));if(!r)return null;const i=r.contentRect;return e-i.left<i.right-e?se(n,r.start,"home"):se(n,r.end,"end")}function t6(n,e,t){const o=Vn(n,e),r=Vn(n,t),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 n6(n){return Cg(n).length}const Ps=D("find-text-position");function o6(n,e){const{start:t,end:o}=kh(n,e),r=ie(n),i=Vn(n,se(r,t,"home"));if(!(Vn(n,se(r,o,"end")).top>i.top+i.height/2))return!1;const a=gh(n,t);return g(Ps,a.next,"no next child at offset"),g(Ps,!La(a.next),"next child is not text child"),!0}function kI(n,e){const t=ie(n);g(Ps,o6(n,e),"line is not wrapped");const{start:o,end:r}=kh(n,e),i=se(t,o,"home");for(let s=o+1;s<=r;s+=1){let l="normal";s===o?l="home":s===r&&(l="end");const a=se(t,s,l);if(!t6(n,i,a))return s-1}return g(Ps,!1,"failed to find wrapped offset"),0}function wh(n,e,t,o,r,i,s){g(Ps,te(n,e),`not a text kind block: ${Se(e)}`);const{start:l,end:a}=kh(e,t);let d=l;const h=ie(e);if(e===o&&o6(e,t)){const x=kI(e,t);(i==="up"||i==="down"&&t6(e,r,se(h,l,"home")))&&(d=x+1)}let p=Number.MAX_SAFE_INTEGER;const C=Lo(n,o,r),v=s!=null?s:C.left+C.width/2,B=C.top+C.height/2;let S=se(h,d,"home");for(let x=d;x<=a;x++){if(!ln(e,x))continue;let _="normal";x===l?_="home":x===a&&(_="end");const M=se(h,x,_),H=Vn(e,M),z=or(H,v,B);z<p&&(p=z,S=M)}return S}function wI(n,e,t,o,r){return g(Ps,te(n,e),"not a text block"),wh(n,e,n6(e)-1,t,o,"up",r)}function BI(n,e,t,o,r){return g(Ps,te(n,e),"not a text block"),wh(n,e,0,t,o,"down",r)}function EI(n,e,t,o){const{lineIndex:r}=pg(e,t);if(r===n6(e)-1)return null;const i=wh(n,e,r+1,e,t,"down",o);return i||null}function xI(n,e){if(e.offset===0)return null;const t=_a(n),o=t.find(r=>r.offset===e.offset);if(!o){const r=Fi(n,e.offset);return t.find(s=>s.offset===r)?{offset:r,type:"home"}:{offset:r,type:"normal"}}if(o.type==="betweenChild"){if(e.type==="home"&&o.childInfo.wrap==="nowrap")return{offset:e.offset,type:"end"};if(o.childInfo.prevWrapped)return{offset:Fi(n,e.offset),type:"normal"}}return{offset:Fi(n,e.offset),type:"normal"}}function II(n,e){const t=Ra(n);if(e.offset===t)return null;const o=_a(n),r=o.find(i=>i.offset===e.offset);if(!r){const i=_s(n,e.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"&&e.type==="end"?{offset:e.offset,type:"home"}:{offset:_s(n,e.offset),type:"home"}:{offset:_s(n,e.offset),type:"normal"}}function TI(n,e,t,o){const{lineIndex:r}=pg(e,t);if(r===0)return null;const i=wh(n,e,r-1,e,t,"up",o);return i||null}const SI=D("move-caret");function DI(n,e,t,o){if(o==="ArrowLeft"){const r=xI(e,t);return r?se(ie(e),r.offset,r.type):null}if(o==="ArrowRight"){const r=II(e,t);return r?se(ie(e),r.offset,r.type):null}if(o==="ArrowUp"){const r=TI(n,e,t,n.selection.getSuggestedCaretX());return r?se(ie(e),r.offset,r.type):null}if(o==="ArrowDown"){const r=EI(n,e,t,n.selection.getSuggestedCaretX());return r?se(ie(e),r.offset,r.type):null}g(SI,!1,`invalid navigation direction: ${o}`)}const bg=D("text-range");function LI(n){const e=[];return ir(n).forEach(o=>{const r=Array.from(o.getClientRects()).map(i=>({rect:i,child:o}));e.push(...r)}),e}function MI(n,e,t){const o=LI(n);for(let r=1;r<o.length;r++){const i=o[r-1],s=o[r];if(e>=i.rect.right&&e<=s.rect.left&&t>=i.rect.top&&t<=i.rect.bottom&&t>=s.rect.top&&t<=s.rect.bottom)return Os(n,s.child).start}return null}function RI(n,e,t,o){const r=document.elementsFromPoint(t,o)[0];if(!r||!e.contains(r)||!n.contains(e))return null;const i=r.closest("div[data-type=block-content]>span");if(!i){const _=e.getBoundingClientRect();if(!ks(_,t,o))return null;const M=MI(e,t,o);if(M!==null){const z=se(e,M,"normal");return new Yt(n,{anchor:z,focus:z})}const H=yI(e,t,o);return H?new Yt(n,{anchor:H,focus:H}):null}const s=ir(e);g(bg,s.indexOf(i)!==-1,"failed to find child in children");const l=Os(e,i);g(bg,l,"failed to get child offset");const{start:a}=l;let d,h;Wr(i)||ao(i)?(d=a,h=0):(g(bg,i.firstChild instanceof Text,"child is not text"),d=a+b5(i.firstChild,t,o),h=0);const p=ie(e),v=_a(e).find(_=>_.offset===d);let B="normal";if(v){const _=se(p,d,"home"),M=se(p,d,"end"),H=Vn(e,_),z=Vn(e,M),Z=or(H,t,o),ee=or(z,t,o);B=Z<ee?"home":"end"}const S=se(p,d,B);let x;return h&&(x=se(p,d+h,B)),new Yt(n,{anchor:S,focus:x!=null?x:S})}const OI=D("create-text-op");function ho(n,e){g(OI,n,"text is empty");const t={insert:n};return e&&Object.keys(e).length>0&&(t.attributes=e),t}function Ag(n,e){if(n.length===0)return[];if(n.indexOf(`
|
|
16
16
|
`)===-1)return[ho(n,e)];const t=n.replace(/\r\n/g,`
|
|
17
17
|
`).replace(/\r/g,`
|
|
18
18
|
`).replace(/\n/g," "),o=[];return t&&o.push(ho(t,e)),o}const Bh=D("merge-ops");function vg(n){if(n.length<=1)return n;const e=(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(Bh,i.attributes===void 0,"op2.attributes is not undefined"),!0):(g(Bh,r.attributes&&i.attributes,"op1.attributes && op2.attributes is undefined"),pa.default(r.attributes,i.attributes)),t=[];let o=n[0];t.push(o);for(let r=1;r<n.length;r+=1){const i=n[r];e(o,i)?(g(Bh,typeof o.insert=="string","before.insert is not string"),g(Bh,typeof i.insert=="string","op.insert is not string"),o.insert+=i.insert):(t.push(i),o=i)}return t}function _I(n){let e;for(e=n.length-1;e>=0;e--){const t=n[e];if(!t.attributes||!t.attributes.box||t.attributes.type!=="br")break}return e===n.length-1?n:n.slice(0,e+1)}const r6=D("delete-text");function yg(n,e,t){const{left:o,right:r}=Vt(n,e,t),i=[...o,...r];return vg(i)}function i6(n,e){g(r6,n>=0,`invalid offset: ${n}`),g(r6,e>=1,`invalid delete count: ${e}`);const t=[];return n!==0&&t.push({retain:n}),t.push({delete:e}),t}const s6=D("delta");function l6(n,e){const t=new rn.default(n),o=new rn.default(e);return t.diff(o).ops}function FI(n,e,t){return new rn.default(e).transformPosition(n,!t)}function PI(n){g(s6,n,"ops is null or undefined");for(let e=0;e<n.length;e++){const t=n[e];if(t.insert===null||t.insert===void 0||t.retain!==void 0||t.delete!==void 0)return!1}return!0}function NI(n,e){const t=new rn.default(n),o=new rn.default(e);return t.compose(o).ops}class cn{static ensureValidText(e){g(s6,PI(e),`text is not a valid text, ${JSON.stringify(e)}`)}static diff(e,t){return this.ensureValidText(e),this.ensureValidText(t),l6(e,t)}static transformCursor(e,t,o){return FI(e,t,o)}static transformOffset(e,t,o){const r=l6(e,t),i=new rn.default(r);return o.map(s=>i.transformPosition(s))}static apply(e,t){this.ensureValidText(e);const o=NI(e,t);return this.ensureValidText(o),o}}const c6=D("insert-text");function Zr(n,e,t,o){g(c6,t,`invalid text to insert: ${t}`);const{left:r,right:i}=Tn(n,e),s=typeof t=="string"?[ho(t,o)]:t,l=[...r,...s,...i];return vg(l)}function a6(n){return{insert:" ",attributes:n}}function Eh(n,e,t){if(g(c6,n>=0,`invalid offset: ${n}`),e.length===0)return[];const o=[];if(n>0&&o.push({retain:n}),typeof e!="string")return o.push(...e),o;const i={insert:e.replaceAll(`\r
|