@ones-editor/editor 0.0.3-beta.232 → 0.0.3-beta.234

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