@wangeditor-next/yjs 0.1.30 → 0.1.32-beta.0

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.
Files changed (3) hide show
  1. package/dist/index.js +1442 -2
  2. package/dist/index.mjs +1407 -2
  3. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -1,2 +1,1407 @@
1
- import*as t from"yjs";import{Text as r,Node as n,Element as e,Path as i,Editor as o,Transforms as u}from"slate";var a,c,f="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},s={};function l(){if(c)return a;c=1;var t=function(t){return t&&t.Math===Math&&t};return a=t("object"==typeof globalThis&&globalThis)||t("object"==typeof window&&window)||t("object"==typeof self&&self)||t("object"==typeof f&&f)||t("object"==typeof a&&a)||function(){return this}()||Function("return this")()}var v,d,p,h,g,y,b,m,w={};function O(){return d?v:(d=1,v=function(t){try{return!!t()}catch(t){return!0}})}function S(){if(h)return p;h=1;var t=O();return p=!t((function(){return 7!==Object.defineProperty({},1,{get:function(){return 7}})[1]}))}function x(){if(y)return g;y=1;var t=O();return g=!t((function(){var t=function(){}.bind();return"function"!=typeof t||t.hasOwnProperty("prototype")}))}function E(){if(m)return b;m=1;var t=x(),r=Function.prototype.call;return b=t?r.bind(r):function(){return r.apply(r,arguments)},b}var j,T,P,R,A,k,C,L,F,_,M,D,I,z,N,W,X,G,B,U,Y,V,$,q,H,J,K,Q,Z,tt,rt,nt,et,it,ot,ut,at,ct,ft,st,lt,vt={};function dt(){if(j)return vt;j=1;var t={}.propertyIsEnumerable,r=Object.getOwnPropertyDescriptor,n=r&&!t.call({1:2},1);return vt.f=n?function(t){var n=r(this,t);return!!n&&n.enumerable}:t,vt}function pt(){return P?T:(P=1,T=function(t,r){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:r}})}function ht(){if(A)return R;A=1;var t=x(),r=Function.prototype,n=r.call,e=t&&r.bind.bind(n,n);return R=t?e:function(t){return function(){return n.apply(t,arguments)}},R}function gt(){if(C)return k;C=1;var t=ht(),r=t({}.toString),n=t("".slice);return k=function(t){return n(r(t),8,-1)}}function yt(){if(F)return L;F=1;var t=ht(),r=O(),n=gt(),e=Object,i=t("".split);return L=r((function(){return!e("z").propertyIsEnumerable(0)}))?function(t){return"String"===n(t)?i(t,""):e(t)}:e}function bt(){return M?_:(M=1,_=function(t){return null==t})}function mt(){if(I)return D;I=1;var t=bt(),r=TypeError;return D=function(n){if(t(n))throw new r("Can't call method on "+n);return n}}function wt(){if(N)return z;N=1;var t=yt(),r=mt();return z=function(n){return t(r(n))}}function Ot(){if(X)return W;X=1;var t="object"==typeof document&&document.all;return W=void 0===t&&void 0!==t?function(r){return"function"==typeof r||r===t}:function(t){return"function"==typeof t}}function St(){if(B)return G;B=1;var t=Ot();return G=function(r){return"object"==typeof r?null!==r:t(r)}}function xt(){if(Y)return U;Y=1;var t=l(),r=Ot();return U=function(n,e){return arguments.length<2?(i=t[n],r(i)?i:void 0):t[n]&&t[n][e];var i},U}function Et(){if($)return V;$=1;var t=ht();return V=t({}.isPrototypeOf)}function jt(){if(K)return J;K=1;var t,r,n=l(),e=function(){if(H)return q;H=1;var t=l().navigator,r=t&&t.userAgent;return q=r?String(r):""}(),i=n.process,o=n.Deno,u=i&&i.versions||o&&o.version,a=u&&u.v8;return a&&(r=(t=a.split("."))[0]>0&&t[0]<4?1:+(t[0]+t[1])),!r&&e&&(!(t=e.match(/Edge\/(\d+)/))||t[1]>=74)&&(t=e.match(/Chrome\/(\d+)/))&&(r=+t[1]),J=r}function Tt(){if(Z)return Q;Z=1;var t=jt(),r=O(),n=l().String;return Q=!!Object.getOwnPropertySymbols&&!r((function(){var r=Symbol("symbol detection");return!n(r)||!(Object(r)instanceof Symbol)||!Symbol.sham&&t&&t<41}))}function Pt(){if(rt)return tt;rt=1;var t=Tt();return tt=t&&!Symbol.sham&&"symbol"==typeof Symbol.iterator}function Rt(){if(et)return nt;et=1;var t=xt(),r=Ot(),n=Et(),e=Pt(),i=Object;return nt=e?function(t){return"symbol"==typeof t}:function(e){var o=t("Symbol");return r(o)&&n(o.prototype,i(e))}}function At(){if(ot)return it;ot=1;var t=String;return it=function(r){try{return t(r)}catch(t){return"Object"}}}function kt(){if(at)return ut;at=1;var t=Ot(),r=At(),n=TypeError;return ut=function(e){if(t(e))return e;throw new n(r(e)+" is not a function")}}function Ct(){if(ft)return ct;ft=1;var t=kt(),r=bt();return ct=function(n,e){var i=n[e];return r(i)?void 0:t(i)}}function Lt(){if(lt)return st;lt=1;var t=E(),r=Ot(),n=St(),e=TypeError;return st=function(i,o){var u,a;if("string"===o&&r(u=i.toString)&&!n(a=t(u,i)))return a;if(r(u=i.valueOf)&&!n(a=t(u,i)))return a;if("string"!==o&&r(u=i.toString)&&!n(a=t(u,i)))return a;throw new e("Can't convert object to primitive value")}}var Ft,_t,Mt,Dt,It,zt,Nt,Wt,Xt,Gt,Bt,Ut,Yt,Vt,$t,qt,Ht,Jt,Kt,Qt,Zt,tr,rr,nr,er={exports:{}};function ir(){return _t?Ft:(_t=1,Ft=!1)}function or(){if(Dt)return Mt;Dt=1;var t=l(),r=Object.defineProperty;return Mt=function(n,e){try{r(t,n,{value:e,configurable:!0,writable:!0})}catch(r){t[n]=e}return e}}function ur(){if(It)return er.exports;It=1;var t=ir(),r=l(),n=or(),e="__core-js_shared__",i=er.exports=r[e]||n(e,{});return(i.versions||(i.versions=[])).push({version:"3.38.1",mode:t?"pure":"global",copyright:"© 2014-2024 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.38.1/LICENSE",source:"https://github.com/zloirock/core-js"}),er.exports}function ar(){if(Nt)return zt;Nt=1;var t=ur();return zt=function(r,n){return t[r]||(t[r]=n||{})}}function cr(){if(Xt)return Wt;Xt=1;var t=mt(),r=Object;return Wt=function(n){return r(t(n))}}function fr(){if(Bt)return Gt;Bt=1;var t=ht(),r=cr(),n=t({}.hasOwnProperty);return Gt=Object.hasOwn||function(t,e){return n(r(t),e)}}function sr(){if(Yt)return Ut;Yt=1;var t=ht(),r=0,n=Math.random(),e=t(1..toString);return Ut=function(t){return"Symbol("+(void 0===t?"":t)+")_"+e(++r+n,36)}}function lr(){if($t)return Vt;$t=1;var t=l(),r=ar(),n=fr(),e=sr(),i=Tt(),o=Pt(),u=t.Symbol,a=r("wks"),c=o?u.for||u:u&&u.withoutSetter||e;return Vt=function(t){return n(a,t)||(a[t]=i&&n(u,t)?u[t]:c("Symbol."+t)),a[t]}}function vr(){if(Ht)return qt;Ht=1;var t=E(),r=St(),n=Rt(),e=Ct(),i=Lt(),o=lr(),u=TypeError,a=o("toPrimitive");return qt=function(o,c){if(!r(o)||n(o))return o;var f,s=e(o,a);if(s){if(void 0===c&&(c="default"),f=t(s,o,c),!r(f)||n(f))return f;throw new u("Can't convert object to primitive value")}return void 0===c&&(c="number"),i(o,c)}}function dr(){if(Kt)return Jt;Kt=1;var t=vr(),r=Rt();return Jt=function(n){var e=t(n,"string");return r(e)?e:e+""}}function pr(){if(Zt)return Qt;Zt=1;var t=l(),r=St(),n=t.document,e=r(n)&&r(n.createElement);return Qt=function(t){return e?n.createElement(t):{}}}function hr(){if(rr)return tr;rr=1;var t=S(),r=O(),n=pr();return tr=!t&&!r((function(){return 7!==Object.defineProperty(n("div"),"a",{get:function(){return 7}}).a}))}function gr(){if(nr)return w;nr=1;var t=S(),r=E(),n=dt(),e=pt(),i=wt(),o=dr(),u=fr(),a=hr(),c=Object.getOwnPropertyDescriptor;return w.f=t?c:function(t,f){if(t=i(t),f=o(f),a)try{return c(t,f)}catch(t){}if(u(t,f))return e(!r(n.f,t,f),t[f])},w}var yr,br,mr,wr,Or,Sr,xr,Er={};function jr(){if(br)return yr;br=1;var t=S(),r=O();return yr=t&&r((function(){return 42!==Object.defineProperty((function(){}),"prototype",{value:42,writable:!1}).prototype}))}function Tr(){if(wr)return mr;wr=1;var t=St(),r=String,n=TypeError;return mr=function(e){if(t(e))return e;throw new n(r(e)+" is not an object")}}function Pr(){if(Or)return Er;Or=1;var t=S(),r=hr(),n=jr(),e=Tr(),i=dr(),o=TypeError,u=Object.defineProperty,a=Object.getOwnPropertyDescriptor,c="enumerable",f="configurable",s="writable";return Er.f=t?n?function(t,r,n){if(e(t),r=i(r),e(n),"function"==typeof t&&"prototype"===r&&"value"in n&&s in n&&!n[s]){var o=a(t,r);o&&o[s]&&(t[r]=n.value,n={configurable:f in n?n[f]:o[f],enumerable:c in n?n[c]:o[c],writable:!1})}return u(t,r,n)}:u:function(t,n,a){if(e(t),n=i(n),e(a),r)try{return u(t,n,a)}catch(t){}if("get"in a||"set"in a)throw new o("Accessors not supported");return"value"in a&&(t[n]=a.value),t},Er}function Rr(){if(xr)return Sr;xr=1;var t=S(),r=Pr(),n=pt();return Sr=t?function(t,e,i){return r.f(t,e,n(1,i))}:function(t,r,n){return t[r]=n,t}}var Ar,kr,Cr,Lr,Fr,_r,Mr,Dr,Ir,zr,Nr,Wr,Xr,Gr,Br,Ur={exports:{}};function Yr(){if(kr)return Ar;kr=1;var t=S(),r=fr(),n=Function.prototype,e=t&&Object.getOwnPropertyDescriptor,i=r(n,"name"),o=i&&"something"===function(){}.name,u=i&&(!t||t&&e(n,"name").configurable);return Ar={EXISTS:i,PROPER:o,CONFIGURABLE:u}}function Vr(){if(Lr)return Cr;Lr=1;var t=ht(),r=Ot(),n=ur(),e=t(Function.toString);return r(n.inspectSource)||(n.inspectSource=function(t){return e(t)}),Cr=n.inspectSource}function $r(){if(_r)return Fr;_r=1;var t=l(),r=Ot(),n=t.WeakMap;return Fr=r(n)&&/native code/.test(String(n))}function qr(){if(Dr)return Mr;Dr=1;var t=ar(),r=sr(),n=t("keys");return Mr=function(t){return n[t]||(n[t]=r(t))}}function Hr(){return zr?Ir:(zr=1,Ir={})}function Jr(){if(Wr)return Nr;Wr=1;var t,r,n,e=$r(),i=l(),o=St(),u=Rr(),a=fr(),c=ur(),f=qr(),s=Hr(),v="Object already initialized",d=i.TypeError,p=i.WeakMap;if(e||c.state){var h=c.state||(c.state=new p);h.get=h.get,h.has=h.has,h.set=h.set,t=function(t,r){if(h.has(t))throw new d(v);return r.facade=t,h.set(t,r),r},r=function(t){return h.get(t)||{}},n=function(t){return h.has(t)}}else{var g=f("state");s[g]=!0,t=function(t,r){if(a(t,g))throw new d(v);return r.facade=t,u(t,g,r),r},r=function(t){return a(t,g)?t[g]:{}},n=function(t){return a(t,g)}}return Nr={set:t,get:r,has:n,enforce:function(e){return n(e)?r(e):t(e,{})},getterFor:function(t){return function(n){var e;if(!o(n)||(e=r(n)).type!==t)throw new d("Incompatible receiver, "+t+" required");return e}}}}function Kr(){if(Xr)return Ur.exports;Xr=1;var t=ht(),r=O(),n=Ot(),e=fr(),i=S(),o=Yr().CONFIGURABLE,u=Vr(),a=Jr(),c=a.enforce,f=a.get,s=String,l=Object.defineProperty,v=t("".slice),d=t("".replace),p=t([].join),h=i&&!r((function(){return 8!==l((function(){}),"length",{value:8}).length})),g=String(String).split("String"),y=Ur.exports=function(t,r,n){"Symbol("===v(s(r),0,7)&&(r="["+d(s(r),/^Symbol\(([^)]*)\).*$/,"$1")+"]"),n&&n.getter&&(r="get "+r),n&&n.setter&&(r="set "+r),(!e(t,"name")||o&&t.name!==r)&&(i?l(t,"name",{value:r,configurable:!0}):t.name=r),h&&n&&e(n,"arity")&&t.length!==n.arity&&l(t,"length",{value:n.arity});try{n&&e(n,"constructor")&&n.constructor?i&&l(t,"prototype",{writable:!1}):t.prototype&&(t.prototype=void 0)}catch(t){}var u=c(t);return e(u,"source")||(u.source=p(g,"string"==typeof r?r:"")),t};return Function.prototype.toString=y((function(){return n(this)&&f(this).source||u(this)}),"toString"),Ur.exports}function Qr(){if(Br)return Gr;Br=1;var t=Ot(),r=Pr(),n=Kr(),e=or();return Gr=function(i,o,u,a){a||(a={});var c=a.enumerable,f=void 0!==a.name?a.name:o;if(t(u)&&n(u,f,a),a.global)c?i[o]=u:e(o,u);else{try{a.unsafe?i[o]&&(c=!0):delete i[o]}catch(t){}c?i[o]=u:r.f(i,o,{value:u,enumerable:!1,configurable:!a.nonConfigurable,writable:!a.nonWritable})}return i}}var Zr,tn,rn,nn,en,on,un,an,cn,fn,sn,ln,vn,dn,pn,hn,gn,yn={};function bn(){if(nn)return rn;nn=1;var t=function(){if(tn)return Zr;tn=1;var t=Math.ceil,r=Math.floor;return Zr=Math.trunc||function(n){var e=+n;return(e>0?r:t)(e)}}();return rn=function(r){var n=+r;return n!=n||0===n?0:t(n)}}function mn(){if(on)return en;on=1;var t=bn(),r=Math.max,n=Math.min;return en=function(e,i){var o=t(e);return o<0?r(o+i,0):n(o,i)}}function wn(){if(an)return un;an=1;var t=bn(),r=Math.min;return un=function(n){var e=t(n);return e>0?r(e,9007199254740991):0}}function On(){if(fn)return cn;fn=1;var t=wn();return cn=function(r){return t(r.length)}}function Sn(){if(ln)return sn;ln=1;var t=wt(),r=mn(),n=On(),e=function(e){return function(i,o,u){var a=t(i),c=n(a);if(0===c)return!e&&-1;var f,s=r(u,c);if(e&&o!=o){for(;c>s;)if((f=a[s++])!=f)return!0}else for(;c>s;s++)if((e||s in a)&&a[s]===o)return e||s||0;return!e&&-1}};return sn={includes:e(!0),indexOf:e(!1)}}function xn(){if(dn)return vn;dn=1;var t=ht(),r=fr(),n=wt(),e=Sn().indexOf,i=Hr(),o=t([].push);return vn=function(t,u){var a,c=n(t),f=0,s=[];for(a in c)!r(i,a)&&r(c,a)&&o(s,a);for(;u.length>f;)r(c,a=u[f++])&&(~e(s,a)||o(s,a));return s}}function En(){return hn?pn:(hn=1,pn=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"])}function jn(){if(gn)return yn;gn=1;var t=xn(),r=En().concat("length","prototype");return yn.f=Object.getOwnPropertyNames||function(n){return t(n,r)},yn}var Tn,Pn,Rn,An,kn,Cn,Ln,Fn,_n,Mn,Dn,In,zn,Nn,Wn,Xn,Gn,Bn,Un,Yn,Vn,$n,qn,Hn,Jn,Kn,Qn,Zn,te,re,ne={};function ee(){return Tn||(Tn=1,ne.f=Object.getOwnPropertySymbols),ne}function ie(){if(Rn)return Pn;Rn=1;var t=xt(),r=ht(),n=jn(),e=ee(),i=Tr(),o=r([].concat);return Pn=t("Reflect","ownKeys")||function(t){var r=n.f(i(t)),u=e.f;return u?o(r,u(t)):r}}function oe(){if(kn)return An;kn=1;var t=fr(),r=ie(),n=gr(),e=Pr();return An=function(i,o,u){for(var a=r(o),c=e.f,f=n.f,s=0;s<a.length;s++){var l=a[s];t(i,l)||u&&t(u,l)||c(i,l,f(o,l))}}}function ue(){if(Ln)return Cn;Ln=1;var t=O(),r=Ot(),n=/#|\.prototype\./,e=function(n,e){var c=o[i(n)];return c===a||c!==u&&(r(e)?t(e):!!e)},i=e.normalize=function(t){return String(t).replace(n,".").toLowerCase()},o=e.data={},u=e.NATIVE="N",a=e.POLYFILL="P";return Cn=e}function ae(){if(_n)return Fn;_n=1;var t=l(),r=gr().f,n=Rr(),e=Qr(),i=or(),o=oe(),u=ue();return Fn=function(a,c){var f,s,l,v,d,p=a.target,h=a.global,g=a.stat;if(f=h?t:g?t[p]||i(p,{}):t[p]&&t[p].prototype)for(s in c){if(v=c[s],l=a.dontCallGetSet?(d=r(f,s))&&d.value:f[s],!u(h?s:p+(g?".":"#")+s,a.forced)&&void 0!==l){if(typeof v==typeof l)continue;o(v,l)}(a.sham||l&&l.sham)&&n(v,"sham",!0),e(f,s,v,a)}}}function ce(){if(Dn)return Mn;Dn=1;var t=gt(),r=ht();return Mn=function(n){if("Function"===t(n))return r(n)}}function fe(){if(zn)return In;zn=1;var t=ce(),r=kt(),n=x(),e=t(t.bind);return In=function(t,i){return r(t),void 0===i?t:n?e(t,i):function(){return t.apply(i,arguments)}},In}function se(){if(Wn)return Nn;Wn=1;var t=gt();return Nn=Array.isArray||function(r){return"Array"===t(r)}}function le(){if(Gn)return Xn;Gn=1;var t={};return t[lr()("toStringTag")]="z",Xn="[object z]"===String(t)}function ve(){if(Un)return Bn;Un=1;var t=le(),r=Ot(),n=gt(),e=lr()("toStringTag"),i=Object,o="Arguments"===n(function(){return arguments}());return Bn=t?n:function(t){var u,a,c;return void 0===t?"Undefined":null===t?"Null":"string"==typeof(a=function(t,r){try{return t[r]}catch(t){}}(u=i(t),e))?a:o?n(u):"Object"===(c=n(u))&&r(u.callee)?"Arguments":c}}function de(){if(Vn)return Yn;Vn=1;var t=ht(),r=O(),n=Ot(),e=ve(),i=xt(),o=Vr(),u=function(){},a=i("Reflect","construct"),c=/^\s*(?:class|function)\b/,f=t(c.exec),s=!c.test(u),l=function(t){if(!n(t))return!1;try{return a(u,[],t),!0}catch(t){return!1}},v=function(t){if(!n(t))return!1;switch(e(t)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return s||!!f(c,o(t))}catch(t){return!0}};return v.sham=!0,Yn=!a||r((function(){var t;return l(l.call)||!l(Object)||!l((function(){t=!0}))||t}))?v:l}function pe(){if(qn)return $n;qn=1;var t=se(),r=de(),n=St(),e=lr()("species"),i=Array;return $n=function(o){var u;return t(o)&&(u=o.constructor,(r(u)&&(u===i||t(u.prototype))||n(u)&&null===(u=u[e]))&&(u=void 0)),void 0===u?i:u}}function he(){if(Jn)return Hn;Jn=1;var t=pe();return Hn=function(r,n){return new(t(r))(0===n?0:n)}}function ge(){if(Qn)return Kn;Qn=1;var t=fe(),r=ht(),n=yt(),e=cr(),i=On(),o=he(),u=r([].push),a=function(r){var a=1===r,c=2===r,f=3===r,s=4===r,l=6===r,v=7===r,d=5===r||l;return function(p,h,g,y){for(var b,m,w=e(p),O=n(w),S=i(O),x=t(h,g),E=0,j=y||o,T=a?j(p,S):c||v?j(p,0):void 0;S>E;E++)if((d||E in O)&&(m=x(b=O[E],E,w),r))if(a)T[E]=m;else if(m)switch(r){case 3:return!0;case 5:return b;case 6:return E;case 2:u(T,b)}else switch(r){case 4:return!1;case 7:u(T,b)}return l?-1:f||s?s:T}};return Kn={forEach:a(0),map:a(1),filter:a(2),some:a(3),every:a(4),find:a(5),findIndex:a(6),filterReject:a(7)}}function ye(){if(te)return Zn;te=1;var t=O(),r=lr(),n=jt(),e=r("species");return Zn=function(r){return n>=51||!t((function(){var t=[];return(t.constructor={})[e]=function(){return{foo:1}},1!==t[r](Boolean).foo}))}}!function(){if(re)return s;re=1;var t=ae(),r=ge().filter;t({target:"Array",proto:!0,forced:!ye()("filter")},{filter:function(t){return r(this,t,arguments.length>1?arguments[1]:void 0)}})}();var be,me,we,Oe,Se,xe,Ee,je,Te,Pe,Re,Ae,ke,Ce,Le,Fe,_e,Me,De,Ie={};function ze(){if(me)return be;me=1;var t=E(),r=Tr(),n=Ct();return be=function(e,i,o){var u,a;r(e);try{if(!(u=n(e,"return"))){if("throw"===i)throw o;return o}u=t(u,e)}catch(t){a=!0,u=t}if("throw"===i)throw o;if(a)throw u;return r(u),o}}function Ne(){if(Oe)return we;Oe=1;var t=Tr(),r=ze();return we=function(n,e,i,o){try{return o?e(t(i)[0],i[1]):e(i)}catch(t){r(n,"throw",t)}}}function We(){return xe?Se:(xe=1,Se={})}function Xe(){if(je)return Ee;je=1;var t=lr(),r=We(),n=t("iterator"),e=Array.prototype;return Ee=function(t){return void 0!==t&&(r.Array===t||e[n]===t)}}function Ge(){if(Pe)return Te;Pe=1;var t=S(),r=Pr(),n=pt();return Te=function(e,i,o){t?r.f(e,i,n(0,o)):e[i]=o}}function Be(){if(Ae)return Re;Ae=1;var t=ve(),r=Ct(),n=bt(),e=We(),i=lr()("iterator");return Re=function(o){if(!n(o))return r(o,i)||r(o,"@@iterator")||e[t(o)]}}function Ue(){if(Ce)return ke;Ce=1;var t=E(),r=kt(),n=Tr(),e=At(),i=Be(),o=TypeError;return ke=function(u,a){var c=arguments.length<2?i(u):a;if(r(c))return n(t(c,u));throw new o(e(u)+" is not iterable")},ke}function Ye(){if(Me)return _e;Me=1;var t=lr()("iterator"),r=!1;try{var n=0,e={next:function(){return{done:!!n++}},return:function(){r=!0}};e[t]=function(){return this},Array.from(e,(function(){throw 2}))}catch(t){}return _e=function(n,e){try{if(!e&&!r)return!1}catch(t){return!1}var i=!1;try{var o={};o[t]=function(){return{next:function(){return{done:i=!0}}}},n(o)}catch(t){}return i}}!function(){if(De)return Ie;De=1;var t=ae(),r=function(){if(Fe)return Le;Fe=1;var t=fe(),r=E(),n=cr(),e=Ne(),i=Xe(),o=de(),u=On(),a=Ge(),c=Ue(),f=Be(),s=Array;return Le=function(l){var v=n(l),d=o(this),p=arguments.length,h=p>1?arguments[1]:void 0,g=void 0!==h;g&&(h=t(h,p>2?arguments[2]:void 0));var y,b,m,w,O,S,x=f(v),E=0;if(!x||this===s&&i(x))for(y=u(v),b=d?new this(y):s(y);y>E;E++)S=g?h(v[E],E):v[E],a(b,E,S);else for(b=d?new this:[],O=(w=c(v,x)).next;!(m=r(O,w)).done;E++)S=g?e(w,h,[m.value,E],!0):m.value,a(b,E,S);return b.length=E,b},Le}();t({target:"Array",stat:!0,forced:!Ye()((function(t){Array.from(t)}))},{from:r})}();var Ve,$e,qe,He,Je,Ke,Qe,Ze,ti,ri,ni,ei,ii,oi,ui,ai,ci,fi,si,li,vi,di,pi,hi,gi,yi,bi,mi,wi,Oi,Si,xi,Ei,ji={};function Ti(){if($e)return Ve;$e=1;var t=xn(),r=En();return Ve=Object.keys||function(n){return t(n,r)}}function Pi(){if(qe)return ji;qe=1;var t=S(),r=jr(),n=Pr(),e=Tr(),i=wt(),o=Ti();return ji.f=t&&!r?Object.defineProperties:function(t,r){e(t);for(var u,a=i(r),c=o(r),f=c.length,s=0;f>s;)n.f(t,u=c[s++],a[u]);return t},ji}function Ri(){if(Je)return He;Je=1;var t=xt();return He=t("document","documentElement")}function Ai(){if(Qe)return Ke;Qe=1;var t,r=Tr(),n=Pi(),e=En(),i=Hr(),o=Ri(),u=pr(),a=qr(),c="prototype",f="script",s=a("IE_PROTO"),l=function(){},v=function(t){return"<"+f+">"+t+"</"+f+">"},d=function(t){t.write(v("")),t.close();var r=t.parentWindow.Object;return t=null,r},p=function(){try{t=new ActiveXObject("htmlfile")}catch(t){}var r,n,i;p="undefined"!=typeof document?document.domain&&t?d(t):(n=u("iframe"),i="java"+f+":",n.style.display="none",o.appendChild(n),n.src=String(i),(r=n.contentWindow.document).open(),r.write(v("document.F=Object")),r.close(),r.F):d(t);for(var a=e.length;a--;)delete p[c][e[a]];return p()};return i[s]=!0,Ke=Object.create||function(t,e){var i;return null!==t?(l[c]=r(t),i=new l,l[c]=null,i[s]=t):i=p(),void 0===e?i:n.f(i,e)}}function ki(){if(ti)return Ze;ti=1;var t=lr(),r=Ai(),n=Pr().f,e=t("unscopables"),i=Array.prototype;return void 0===i[e]&&n(i,e,{configurable:!0,value:r(null)}),Ze=function(t){i[e][t]=!0}}function Ci(){if(ii)return ei;ii=1;var t=fr(),r=Ot(),n=cr(),e=qr(),i=function(){if(ni)return ri;ni=1;var t=O();return ri=!t((function(){function t(){}return t.prototype.constructor=null,Object.getPrototypeOf(new t)!==t.prototype}))}(),o=e("IE_PROTO"),u=Object,a=u.prototype;return ei=i?u.getPrototypeOf:function(e){var i=n(e);if(t(i,o))return i[o];var c=i.constructor;return r(c)&&i instanceof c?c.prototype:i instanceof u?a:null}}function Li(){if(ui)return oi;ui=1;var t,r,n,e=O(),i=Ot(),o=St(),u=Ai(),a=Ci(),c=Qr(),f=lr(),s=ir(),l=f("iterator"),v=!1;return[].keys&&("next"in(n=[].keys())?(r=a(a(n)))!==Object.prototype&&(t=r):v=!0),!o(t)||e((function(){var r={};return t[l].call(r)!==r}))?t={}:s&&(t=u(t)),i(t[l])||c(t,l,(function(){return this})),oi={IteratorPrototype:t,BUGGY_SAFARI_ITERATORS:v}}function Fi(){if(ci)return ai;ci=1;var t=Pr().f,r=fr(),n=lr()("toStringTag");return ai=function(e,i,o){e&&!o&&(e=e.prototype),e&&!r(e,n)&&t(e,n,{configurable:!0,value:i})}}function _i(){if(pi)return di;pi=1;var t=St();return di=function(r){return t(r)||null===r}}function Mi(){if(gi)return hi;gi=1;var t=_i(),r=String,n=TypeError;return hi=function(e){if(t(e))return e;throw new n("Can't set "+r(e)+" as a prototype")}}function Di(){if(bi)return yi;bi=1;var t=function(){if(vi)return li;vi=1;var t=ht(),r=kt();return li=function(n,e,i){try{return t(r(Object.getOwnPropertyDescriptor(n,e)[i]))}catch(t){}}}(),r=St(),n=mt(),e=Mi();return yi=Object.setPrototypeOf||("__proto__"in{}?function(){var i,o=!1,u={};try{(i=t(Object.prototype,"__proto__","set"))(u,[]),o=u instanceof Array}catch(t){}return function(t,u){return n(t),e(u),r(t)?(o?i(t,u):t.__proto__=u,t):t}}():void 0)}function Ii(){if(wi)return mi;wi=1;var t=ae(),r=E(),n=ir(),e=Yr(),i=Ot(),o=function(){if(si)return fi;si=1;var t=Li().IteratorPrototype,r=Ai(),n=pt(),e=Fi(),i=We(),o=function(){return this};return fi=function(u,a,c,f){var s=a+" Iterator";return u.prototype=r(t,{next:n(+!f,c)}),e(u,s,!1,!0),i[s]=o,u}}(),u=Ci(),a=Di(),c=Fi(),f=Rr(),s=Qr(),l=lr(),v=We(),d=Li(),p=e.PROPER,h=e.CONFIGURABLE,g=d.IteratorPrototype,y=d.BUGGY_SAFARI_ITERATORS,b=l("iterator"),m="keys",w="values",O="entries",S=function(){return this};return mi=function(e,l,d,x,E,j,T){o(d,l,x);var P,R,A,k=function(t){if(t===E&&M)return M;if(!y&&t&&t in F)return F[t];switch(t){case m:case w:case O:return function(){return new d(this,t)}}return function(){return new d(this)}},C=l+" Iterator",L=!1,F=e.prototype,_=F[b]||F["@@iterator"]||E&&F[E],M=!y&&_||k(E),D="Array"===l&&F.entries||_;if(D&&(P=u(D.call(new e)))!==Object.prototype&&P.next&&(n||u(P)===g||(a?a(P,g):i(P[b])||s(P,b,S)),c(P,C,!0,!0),n&&(v[C]=S)),p&&E===w&&_&&_.name!==w&&(!n&&h?f(F,"name",w):(L=!0,M=function(){return r(_,this)})),E)if(R={values:k(w),keys:j?M:k(m),entries:k(O)},T)for(A in R)(y||L||!(A in F))&&s(F,A,R[A]);else t({target:l,proto:!0,forced:y||L},R);return n&&!T||F[b]===M||s(F,b,M,{name:E}),v[l]=M,R}}function zi(){return Si?Oi:(Si=1,Oi=function(t,r){return{value:t,done:r}})}function Ni(){if(Ei)return xi;Ei=1;var t=wt(),r=ki(),n=We(),e=Jr(),i=Pr().f,o=Ii(),u=zi(),a=ir(),c=S(),f="Array Iterator",s=e.set,l=e.getterFor(f);xi=o(Array,"Array",(function(r,n){s(this,{type:f,target:t(r),index:0,kind:n})}),(function(){var t=l(this),r=t.target,n=t.index++;if(!r||n>=r.length)return t.target=null,u(void 0,!0);switch(t.kind){case"keys":return u(n,!1);case"values":return u(r[n],!1)}return u([n,r[n]],!1)}),"values");var v=n.Arguments=n.Array;if(r("keys"),r("values"),r("entries"),!a&&c&&"values"!==v.name)try{i(v,"name",{value:"values"})}catch(t){}return xi}Ni();var Wi,Xi,Gi,Bi={};function Ui(){if(Xi)return Wi;Xi=1;var t=fe(),r=E(),n=Tr(),e=At(),i=Xe(),o=On(),u=Et(),a=Ue(),c=Be(),f=ze(),s=TypeError,l=function(t,r){this.stopped=t,this.result=r},v=l.prototype;return Wi=function(d,p,h){var g,y,b,m,w,O,S,x=h&&h.that,E=!(!h||!h.AS_ENTRIES),j=!(!h||!h.IS_RECORD),T=!(!h||!h.IS_ITERATOR),P=!(!h||!h.INTERRUPTED),R=t(p,x),A=function(t){return g&&f(g,"normal",t),new l(!0,t)},k=function(t){return E?(n(t),P?R(t[0],t[1],A):R(t[0],t[1])):P?R(t,A):R(t)};if(j)g=d.iterator;else if(T)g=d;else{if(!(y=c(d)))throw new s(e(d)+" is not iterable");if(i(y)){for(b=0,m=o(d);m>b;b++)if((w=k(d[b]))&&u(v,w))return w;return new l(!1)}g=a(d,y)}for(O=j?d.next:g.next;!(S=r(O,g)).done;){try{w=k(S.value)}catch(t){f(g,"throw",t)}if("object"==typeof w&&w&&u(v,w))return w}return new l(!1)}}!function(){if(Gi)return Bi;Gi=1;var t=ae(),r=Ui(),n=Ge();t({target:"Object",stat:!0},{fromEntries:function(t){var e={};return r(t,(function(t,r){n(e,t,r)}),{AS_ENTRIES:!0}),e}})}();var Yi,Vi,$i,qi={};!function(){if($i)return qi;$i=1;var t=le(),r=Qr(),n=function(){if(Vi)return Yi;Vi=1;var t=le(),r=ve();return Yi=t?{}.toString:function(){return"[object "+r(this)+"]"}}();t||r(Object.prototype,"toString",n,{unsafe:!0})}();var Hi,Ji,Ki,Qi,Zi,to,ro,no,eo,io,oo,uo,ao,co,fo,so,lo,vo,po,ho,go,yo,bo,mo,wo,Oo,So={exports:{}},xo={};function Eo(){if(Ji)return Hi;Ji=1;var t=ht();return Hi=t([].slice)}function jo(){if(Ki)return xo;Ki=1;var t=gt(),r=wt(),n=jn().f,e=Eo(),i="object"==typeof window&&window&&Object.getOwnPropertyNames?Object.getOwnPropertyNames(window):[];return xo.f=function(o){return i&&"Window"===t(o)?function(t){try{return n(t)}catch(t){return e(i)}}(o):n(r(o))},xo}function To(){if(ro)return to;ro=1;var t=O(),r=St(),n=gt(),e=function(){if(Zi)return Qi;Zi=1;var t=O();return Qi=t((function(){if("function"==typeof ArrayBuffer){var t=new ArrayBuffer(8);Object.isExtensible(t)&&Object.defineProperty(t,"a",{value:8})}}))}(),i=Object.isExtensible,o=t((function(){}));return to=o||e?function(t){return!!r(t)&&((!e||"ArrayBuffer"!==n(t))&&(!i||i(t)))}:i}function Po(){if(eo)return no;eo=1;var t=O();return no=!t((function(){return Object.isExtensible(Object.preventExtensions({}))}))}function Ro(){if(io)return So.exports;io=1;var t=ae(),r=ht(),n=Hr(),e=St(),i=fr(),o=Pr().f,u=jn(),a=jo(),c=To(),f=sr(),s=Po(),l=!1,v=f("meta"),d=0,p=function(t){o(t,v,{value:{objectID:"O"+d++,weakData:{}}})},h=So.exports={enable:function(){h.enable=function(){},l=!0;var n=u.f,e=r([].splice),i={};i[v]=1,n(i).length&&(u.f=function(t){for(var r=n(t),i=0,o=r.length;i<o;i++)if(r[i]===v){e(r,i,1);break}return r},t({target:"Object",stat:!0,forced:!0},{getOwnPropertyNames:a.f}))},fastKey:function(t,r){if(!e(t))return"symbol"==typeof t?t:("string"==typeof t?"S":"P")+t;if(!i(t,v)){if(!c(t))return"F";if(!r)return"E";p(t)}return t[v].objectID},getWeakData:function(t,r){if(!i(t,v)){if(!c(t))return!0;if(!r)return!1;p(t)}return t[v].weakData},onFreeze:function(t){return s&&l&&c(t)&&!i(t,v)&&p(t),t}};return n[v]=!0,So.exports}function Ao(){if(uo)return oo;uo=1;var t=Et(),r=TypeError;return oo=function(n,e){if(t(e,n))return n;throw new r("Incorrect invocation")}}function ko(){if(co)return ao;co=1;var t=Ot(),r=St(),n=Di();return ao=function(e,i,o){var u,a;return n&&t(u=i.constructor)&&u!==o&&r(a=u.prototype)&&a!==o.prototype&&n(e,a),e}}function Co(){if(so)return fo;so=1;var t=ae(),r=l(),n=ht(),e=ue(),i=Qr(),o=Ro(),u=Ui(),a=Ao(),c=Ot(),f=bt(),s=St(),v=O(),d=Ye(),p=Fi(),h=ko();return fo=function(l,g,y){var b=-1!==l.indexOf("Map"),m=-1!==l.indexOf("Weak"),w=b?"set":"add",O=r[l],S=O&&O.prototype,x=O,E={},j=function(t){var r=n(S[t]);i(S,t,"add"===t?function(t){return r(this,0===t?0:t),this}:"delete"===t?function(t){return!(m&&!s(t))&&r(this,0===t?0:t)}:"get"===t?function(t){return m&&!s(t)?void 0:r(this,0===t?0:t)}:"has"===t?function(t){return!(m&&!s(t))&&r(this,0===t?0:t)}:function(t,n){return r(this,0===t?0:t,n),this})};if(e(l,!c(O)||!(m||S.forEach&&!v((function(){(new O).entries().next()})))))x=y.getConstructor(g,l,b,w),o.enable();else if(e(l,!0)){var T=new x,P=T[w](m?{}:-0,1)!==T,R=v((function(){T.has(1)})),A=d((function(t){new O(t)})),k=!m&&v((function(){for(var t=new O,r=5;r--;)t[w](r,r);return!t.has(-0)}));A||((x=g((function(t,r){a(t,S);var n=h(new O,t,x);return f(r)||u(r,n[w],{that:n,AS_ENTRIES:b}),n}))).prototype=S,S.constructor=x),(R||k)&&(j("delete"),j("has"),b&&j("get")),(k||P)&&j(w),m&&S.clear&&delete S.clear}return E[l]=x,t({global:!0,constructor:!0,forced:x!==O},E),p(x,l),m||y.setStrong(x,l,b),x}}function Lo(){if(vo)return lo;vo=1;var t=Kr(),r=Pr();return lo=function(n,e,i){return i.get&&t(i.get,e,{getter:!0}),i.set&&t(i.set,e,{setter:!0}),r.f(n,e,i)}}function Fo(){if(ho)return po;ho=1;var t=Qr();return po=function(r,n,e){for(var i in n)t(r,i,n[i],e);return r}}function _o(){if(yo)return go;yo=1;var t=xt(),r=Lo(),n=lr(),e=S(),i=n("species");return go=function(n){var o=t(n);e&&o&&!o[i]&&r(o,i,{configurable:!0,get:function(){return this}})}}Oo||(Oo=1,wo||(wo=1,Co()("Set",(function(t){return function(){return t(this,arguments.length?arguments[0]:void 0)}}),function(){if(mo)return bo;mo=1;var t=Ai(),r=Lo(),n=Fo(),e=fe(),i=Ao(),o=bt(),u=Ui(),a=Ii(),c=zi(),f=_o(),s=S(),l=Ro().fastKey,v=Jr(),d=v.set,p=v.getterFor;return bo={getConstructor:function(a,c,f,v){var h=a((function(r,n){i(r,g),d(r,{type:c,index:t(null),first:null,last:null,size:0}),s||(r.size=0),o(n)||u(n,r[v],{that:r,AS_ENTRIES:f})})),g=h.prototype,y=p(c),b=function(t,r,n){var e,i,o=y(t),u=m(t,r);return u?u.value=n:(o.last=u={index:i=l(r,!0),key:r,value:n,previous:e=o.last,next:null,removed:!1},o.first||(o.first=u),e&&(e.next=u),s?o.size++:t.size++,"F"!==i&&(o.index[i]=u)),t},m=function(t,r){var n,e=y(t),i=l(r);if("F"!==i)return e.index[i];for(n=e.first;n;n=n.next)if(n.key===r)return n};return n(g,{clear:function(){for(var r=y(this),n=r.first;n;)n.removed=!0,n.previous&&(n.previous=n.previous.next=null),n=n.next;r.first=r.last=null,r.index=t(null),s?r.size=0:this.size=0},delete:function(t){var r=this,n=y(r),e=m(r,t);if(e){var i=e.next,o=e.previous;delete n.index[e.index],e.removed=!0,o&&(o.next=i),i&&(i.previous=o),n.first===e&&(n.first=i),n.last===e&&(n.last=o),s?n.size--:r.size--}return!!e},forEach:function(t){for(var r,n=y(this),i=e(t,arguments.length>1?arguments[1]:void 0);r=r?r.next:n.first;)for(i(r.value,r.key,this);r&&r.removed;)r=r.previous},has:function(t){return!!m(this,t)}}),n(g,f?{get:function(t){var r=m(this,t);return r&&r.value},set:function(t,r){return b(this,0===t?0:t,r)}}:{add:function(t){return b(this,t=0===t?0:t,t)}}),s&&r(g,"size",{configurable:!0,get:function(){return y(this).size}}),h},setStrong:function(t,r,n){var e=r+" Iterator",i=p(r),o=p(e);a(t,r,(function(t,r){d(this,{type:e,target:t,state:i(t),kind:r,last:null})}),(function(){for(var t=o(this),r=t.kind,n=t.last;n&&n.removed;)n=n.previous;return t.target&&(t.last=n=n?n.next:t.state.first)?c("keys"===r?n.key:"values"===r?n.value:[n.key,n.value],!1):(t.target=null,c(void 0,!0))}),n?"entries":"values",!n,!0),f(r)}},bo}())));var Mo,Do,Io,zo,No,Wo={};function Xo(){if(Do)return Mo;Do=1;var t=ve(),r=String;return Mo=function(n){if("Symbol"===t(n))throw new TypeError("Cannot convert a Symbol value to a string");return r(n)}}!function(){if(No)return Wo;No=1;var t=function(){if(zo)return Io;zo=1;var t=ht(),r=bn(),n=Xo(),e=mt(),i=t("".charAt),o=t("".charCodeAt),u=t("".slice),a=function(t){return function(a,c){var f,s,l=n(e(a)),v=r(c),d=l.length;return v<0||v>=d?t?"":void 0:(f=o(l,v))<55296||f>56319||v+1===d||(s=o(l,v+1))<56320||s>57343?t?i(l,v):f:t?u(l,v,v+2):s-56320+(f-55296<<10)+65536}};return Io={codeAt:a(!1),charAt:a(!0)}}().charAt,r=Xo(),n=Jr(),e=Ii(),i=zi(),o="String Iterator",u=n.set,a=n.getterFor(o);e(String,"String",(function(t){u(this,{type:o,string:r(t),index:0})}),(function(){var r,n=a(this),e=n.string,o=n.index;return o>=e.length?i(void 0,!0):(r=t(e,o),n.index+=r.length,i(r,!1))}))}();var Go,Bo,Uo,Yo,Vo,$o={};!function(){if(Vo)return $o;Vo=1;var t=ae(),r=function(){if(Bo)return Go;Bo=1;var t=ht(),r=mt(),n=Xo(),e=/"/g,i=t("".replace);return Go=function(t,o,u,a){var c=n(r(t)),f="<"+o;return""!==u&&(f+=" "+u+'="'+i(n(a),e,"&quot;")+'"'),f+">"+c+"</"+o+">"}}(),n=function(){if(Yo)return Uo;Yo=1;var t=O();return Uo=function(r){return t((function(){var t=""[r]('"');return t!==t.toLowerCase()||t.split('"').length>3}))}}();t({target:"String",proto:!0,forced:n("anchor")},{anchor:function(t){return r(this,"a","name",t)}})}();var qo,Ho,Jo,Ko,Qo={};function Zo(){if(Ho)return qo;Ho=1;var t=ht(),r=Fo(),n=Ro().getWeakData,e=Ao(),i=Tr(),o=bt(),u=St(),a=Ui(),c=ge(),f=fr(),s=Jr(),l=s.set,v=s.getterFor,d=c.find,p=c.findIndex,h=t([].splice),g=0,y=function(t){return t.frozen||(t.frozen=new b)},b=function(){this.entries=[]},m=function(t,r){return d(t.entries,(function(t){return t[0]===r}))};return b.prototype={get:function(t){var r=m(this,t);if(r)return r[1]},has:function(t){return!!m(this,t)},set:function(t,r){var n=m(this,t);n?n[1]=r:this.entries.push([t,r])},delete:function(t){var r=p(this.entries,(function(r){return r[0]===t}));return~r&&h(this.entries,r,1),!!~r}},qo={getConstructor:function(t,c,s,d){var p=t((function(t,r){e(t,h),l(t,{type:c,id:g++,frozen:null}),o(r)||a(r,t[d],{that:t,AS_ENTRIES:s})})),h=p.prototype,b=v(c),m=function(t,r,e){var o=b(t),u=n(i(r),!0);return!0===u?y(o).set(r,e):u[o.id]=e,t};return r(h,{delete:function(t){var r=b(this);if(!u(t))return!1;var e=n(t);return!0===e?y(r).delete(t):e&&f(e,r.id)&&delete e[r.id]},has:function(t){var r=b(this);if(!u(t))return!1;var e=n(t);return!0===e?y(r).has(t):e&&f(e,r.id)}}),r(h,s?{get:function(t){var r=b(this);if(u(t)){var e=n(t);if(!0===e)return y(r).get(t);if(e)return e[r.id]}},set:function(t,r){return m(this,t,r)}}:{add:function(t){return m(this,t,!0)}}),p}}}Ko||(Ko=1,function(){if(Jo)return Qo;Jo=1;var t,r=Po(),n=l(),e=ht(),i=Fo(),o=Ro(),u=Co(),a=Zo(),c=St(),f=Jr().enforce,s=O(),v=$r(),d=Object,p=Array.isArray,h=d.isExtensible,g=d.isFrozen,y=d.isSealed,b=d.freeze,m=d.seal,w=!n.ActiveXObject&&"ActiveXObject"in n,S=function(t){return function(){return t(this,arguments.length?arguments[0]:void 0)}},x=u("WeakMap",S,a),E=x.prototype,j=e(E.set);if(v)if(w){t=a.getConstructor(S,"WeakMap",!0),o.enable();var T=e(E.delete),P=e(E.has),R=e(E.get);i(E,{delete:function(r){if(c(r)&&!h(r)){var n=f(this);return n.frozen||(n.frozen=new t),T(this,r)||n.frozen.delete(r)}return T(this,r)},has:function(r){if(c(r)&&!h(r)){var n=f(this);return n.frozen||(n.frozen=new t),P(this,r)||n.frozen.has(r)}return P(this,r)},get:function(r){if(c(r)&&!h(r)){var n=f(this);return n.frozen||(n.frozen=new t),P(this,r)?R(this,r):n.frozen.get(r)}return R(this,r)},set:function(r,n){if(c(r)&&!h(r)){var e=f(this);e.frozen||(e.frozen=new t),P(this,r)?j(this,r,n):e.frozen.set(r,n)}else j(this,r,n);return this}})}else r&&s((function(){var t=b([]);return j(new x,t,1),!g(t)}))&&i(E,{set:function(t,r){var n;return p(t)&&(g(t)?n=b:y(t)&&(n=m)),j(this,t,r),n&&n(t),this}})}());var tu,ru,nu,eu,iu,ou,uu,au,cu,fu={};function su(){return ru?tu:(ru=1,tu={CSSRuleList:0,CSSStyleDeclaration:0,CSSValueList:0,ClientRectList:0,DOMRectList:0,DOMStringList:0,DOMTokenList:1,DataTransferItemList:0,FileList:0,HTMLAllCollection:0,HTMLCollection:0,HTMLFormElement:0,HTMLSelectElement:0,MediaList:0,MimeTypeArray:0,NamedNodeMap:0,NodeList:1,PaintRequestList:0,Plugin:0,PluginArray:0,SVGLengthList:0,SVGNumberList:0,SVGPathSegList:0,SVGPointList:0,SVGStringList:0,SVGTransformList:0,SourceBufferList:0,StyleSheetList:0,TextTrackCueList:0,TextTrackList:0,TouchList:0})}function lu(){if(eu)return nu;eu=1;var t=pr()("span").classList,r=t&&t.constructor&&t.constructor.prototype;return nu=r===Object.prototype?void 0:r}!function(){if(cu)return fu;cu=1;var t=l(),r=su(),n=lu(),e=function(){if(au)return uu;au=1;var t=ge().forEach,r=function(){if(ou)return iu;ou=1;var t=O();return iu=function(r,n){var e=[][r];return!!e&&t((function(){e.call(null,n||function(){return 1},1)}))}}()("forEach");return uu=r?[].forEach:function(r){return t(this,r,arguments.length>1?arguments[1]:void 0)},uu}(),i=Rr(),o=function(t){if(t&&t.forEach!==e)try{i(t,"forEach",e)}catch(r){t.forEach=e}};for(var u in r)r[u]&&o(t[u]&&t[u].prototype);o(n)}();var vu,du={};!function(){if(vu)return du;vu=1;var t=l(),r=su(),n=lu(),e=Ni(),i=Rr(),o=Fi(),u=lr()("iterator"),a=e.values,c=function(t,n){if(t){if(t[u]!==a)try{i(t,u,a)}catch(r){t[u]=a}if(o(t,n,!0),r[n])for(var c in e)if(t[c]!==e[c])try{i(t,c,e[c])}catch(r){t[c]=e[c]}}};for(var f in r)c(t[f]&&t[f].prototype,f);c(n,"DOMTokenList")}();var pu=function(){return pu=Object.assign||function(t){for(var r,n=1,e=arguments.length;n<e;n++)for(var i in r=arguments[n])Object.prototype.hasOwnProperty.call(r,i)&&(t[i]=r[i]);return t},pu.apply(this,arguments)};function hu(t,r){var n={};for(var e in t)Object.prototype.hasOwnProperty.call(t,e)&&r.indexOf(e)<0&&(n[e]=t[e]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(e=Object.getOwnPropertySymbols(t);i<e.length;i++)r.indexOf(e[i])<0&&Object.prototype.propertyIsEnumerable.call(t,e[i])&&(n[e[i]]=t[e[i]])}return n}function gu(t){var r="function"==typeof Symbol&&Symbol.iterator,n=r&&t[r],e=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&e>=t.length&&(t=void 0),{value:t&&t[e++],done:!t}}};throw new TypeError(r?"Object is not iterable.":"Symbol.iterator is not defined.")}function yu(t,r){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var e,i,o=n.call(t),u=[];try{for(;(void 0===r||r-- >0)&&!(e=o.next()).done;)u.push(e.value)}catch(t){i={error:t}}finally{try{e&&!e.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return u}function bu(t,r,n){if(n||2===arguments.length)for(var e,i=0,o=r.length;i<o;i++)!e&&i in r||(e||(e=Array.prototype.slice.call(r,0,i)),e[i]=r[i]);return t.concat(e||Array.prototype.slice.call(r))}"function"==typeof SuppressedError&&SuppressedError;var mu,wu,Ou,Su={};function xu(){if(wu)return mu;wu=1;var t=TypeError;return mu=function(r){if(r>9007199254740991)throw t("Maximum allowed index exceeded");return r}}!function(){if(Ou)return Su;Ou=1;var t=ae(),r=O(),n=se(),e=St(),i=cr(),o=On(),u=xu(),a=Ge(),c=he(),f=ye(),s=lr(),l=jt(),v=s("isConcatSpreadable"),d=l>=51||!r((function(){var t=[];return t[v]=!1,t.concat()[0]!==t})),p=function(t){if(!e(t))return!1;var r=t[v];return void 0!==r?!!r:n(t)};t({target:"Array",proto:!0,arity:1,forced:!d||!f("concat")},{concat:function(t){var r,n,e,f,s,l=i(this),v=c(l,0),d=0;for(r=-1,e=arguments.length;r<e;r++)if(p(s=-1===r?l:arguments[r]))for(f=o(s),u(d+f),n=0;n<f;n++,d++)n in s&&a(v,d,s[n]);else u(d+1),a(v,d++,s);return v.length=d,v}})}();var Eu,ju={};!function(){if(Eu)return ju;Eu=1;var t=ae(),r=ge().map;t({target:"Array",proto:!0,forced:!ye()("map")},{map:function(t){return r(this,t,arguments.length>1?arguments[1]:void 0)}})}();var Tu,Pu={};!function(){if(Tu)return Pu;Tu=1;var t=ae(),r=se(),n=de(),e=St(),i=mn(),o=On(),u=wt(),a=Ge(),c=lr(),f=ye(),s=Eo(),l=f("slice"),v=c("species"),d=Array,p=Math.max;t({target:"Array",proto:!0,forced:!l},{slice:function(t,c){var f,l,h,g=u(this),y=o(g),b=i(t,y),m=i(void 0===c?y:c,y);if(r(g)&&(f=g.constructor,(n(f)&&(f===d||r(f.prototype))||e(f)&&null===(f=f[v]))&&(f=void 0),f===d||void 0===f))return s(g,b,m);for(l=new(void 0===f?d:f)(p(m-b,0)),h=0;b<m;b++,h++)b in g&&a(l,h,g[b]);return l.length=h,l}})}();var Ru,Au,ku,Cu={};!function(){if(ku)return Cu;ku=1;var t=ae(),r=function(){if(Au)return Ru;Au=1;var t=S(),r=ht(),n=E(),e=O(),i=Ti(),o=ee(),u=dt(),a=cr(),c=yt(),f=Object.assign,s=Object.defineProperty,l=r([].concat);return Ru=!f||e((function(){if(t&&1!==f({b:1},f(s({},"a",{enumerable:!0,get:function(){s(this,"b",{value:3,enumerable:!1})}}),{b:2})).b)return!0;var r={},n={},e=Symbol("assign detection"),o="abcdefghijklmnopqrst";return r[e]=7,o.split("").forEach((function(t){n[t]=t})),7!==f({},r)[e]||i(f({},n)).join("")!==o}))?function(r,e){for(var f=a(r),s=arguments.length,v=1,d=o.f,p=u.f;s>v;)for(var h,g=c(arguments[v++]),y=d?l(i(g),d(g)):i(g),b=y.length,m=0;b>m;)h=y[m++],t&&!n(p,g,h)||(f[h]=g[h]);return f}:f,Ru}();t({target:"Object",stat:!0,arity:2,forced:Object.assign!==r},{assign:r})}();var Lu,Fu,_u,Mu={};!function(){if(_u)return Mu;_u=1;var t=ae(),r=function(){if(Fu)return Lu;Fu=1;var t=S(),r=O(),n=ht(),e=Ci(),i=Ti(),o=wt(),u=n(dt().f),a=n([].push),c=t&&r((function(){var t=Object.create(null);return t[2]=2,!u(t,2)})),f=function(r){return function(n){for(var f,s=o(n),l=i(s),v=c&&null===e(s),d=l.length,p=0,h=[];d>p;)f=l[p++],t&&!(v?f in s:u(s,f))||a(h,r?[f,s[f]]:s[f]);return h}};return Lu={entries:f(!0),values:f(!1)}}().entries;t({target:"Object",stat:!0},{entries:function(t){return r(t)}})}();var Du,Iu,zu,Nu,Wu,Xu={};function Gu(){if(Nu)return zu;Nu=1;var t=E(),r=fr(),n=Et(),e=function(){if(Iu)return Du;Iu=1;var t=Tr();return Du=function(){var r=t(this),n="";return r.hasIndices&&(n+="d"),r.global&&(n+="g"),r.ignoreCase&&(n+="i"),r.multiline&&(n+="m"),r.dotAll&&(n+="s"),r.unicode&&(n+="u"),r.unicodeSets&&(n+="v"),r.sticky&&(n+="y"),n}}(),i=RegExp.prototype;return zu=function(o){var u=o.flags;return void 0!==u||"flags"in i||r(o,"flags")||!n(i,o)?u:t(e,o)}}!function(){if(Wu)return Xu;Wu=1;var t=Yr().PROPER,r=Qr(),n=Tr(),e=Xo(),i=O(),o=Gu(),u="toString",a=RegExp.prototype,c=a[u],f=i((function(){return"/a/b"!==c.call({source:"a",flags:"b"})})),s=t&&c.name!==u;(f||s)&&r(a,u,(function(){var t=n(this);return"/"+e(t.source)+"/"+e(o(t))}),{unsafe:!0})}();var Bu,Uu,Yu,Vu,$u,qu,Hu,Ju={};function Ku(){if(Vu)return Yu;Vu=1;var t=function(){if(Uu)return Bu;Uu=1;var t=St(),r=gt(),n=lr()("match");return Bu=function(e){var i;return t(e)&&(void 0!==(i=e[n])?!!i:"RegExp"===r(e))}}(),r=TypeError;return Yu=function(n){if(t(n))throw new r("The method doesn't accept regular expressions");return n}}!function(){if(Hu)return Ju;Hu=1;var t,r=ae(),n=ce(),e=gr().f,i=wn(),o=Xo(),u=Ku(),a=mt(),c=function(){if(qu)return $u;qu=1;var t=lr()("match");return $u=function(r){var n=/./;try{"/./"[r](n)}catch(e){try{return n[t]=!1,"/./"[r](n)}catch(t){}}return!1}}(),f=ir(),s=n("".slice),l=Math.min,v=c("startsWith");r({target:"String",proto:!0,forced:!!(f||v||(t=e(String.prototype,"startsWith"),!t||t.writable))&&!v},{startsWith:function(t){var r=o(a(this));u(t);var n=i(l(arguments.length>1?arguments[1]:void 0,r.length)),e=o(t);return s(r,n,n+e.length)===e}})}();var Qu,Zu={};function ta(t){return"[object Object]"===Object.prototype.toString.call(t)}function ra(t){if(!ta(t))return!1;var r=t.constructor;if(void 0===r)return!0;var n=r.prototype;return!1!==ta(n)&&!Object.prototype.hasOwnProperty.call(n,"isPrototypeOfOf")}function na(t,r){for(var n in t){var e=t[n],i=r[n];if(ra(e)&&ra(i)){if(!na(e,i))return!1}else if(Array.isArray(e)&&Array.isArray(i)){if(e.length!==i.length)return!1;for(var o=0;o<e.length;o+=1)if(e[o]!==i[o])return!1}else if(e!==i)return!1}for(var n in r)if(void 0===t[n]&&void 0!==r[n])return!1;return!0}function ea(t){for(var r=[],n=1;n<arguments.length;n++)r[n-1]=arguments[n];return Object.fromEntries(Object.entries(t).filter((function(t){var n=yu(t,1)[0];return r.includes(n)})))}function ia(t){return function(t){var r,n,e,i,o=[];try{for(var u=gu(t),a=u.next();!a.done;a=u.next()){var c=a.value;if("string"!=typeof c.insert||0!==c.insert.length){var f=o[o.length-1];f&&"string"==typeof f.insert&&"string"==typeof c.insert&&(f.attributes===c.attributes||!f.attributes==!c.attributes&&na(null!==(e=f.attributes)&&void 0!==e?e:{},null!==(i=c.attributes)&&void 0!==i?i:{}))?f.insert+=c.insert:o.push(c)}}}catch(t){r={error:t}}finally{try{a&&!a.done&&(n=u.return)&&n.call(u)}finally{if(r)throw r.error}}return o}(t.toDelta())}function oa(t){var r=t.insert;return"string"==typeof r?r.length:1}function ua(t){return t.reduce((function(t,r){return t+oa(r)}),0)}function aa(t,r,n){if(n<1)return[];for(var e=0,i=[],o=r+n,u=0;u<t.length&&!(e>=o);u+=1){var a=t[u],c=oa(a);if(e+c<=r)e+=c;else if("string"==typeof a.insert){var f=Math.max(0,r-e),s=Math.min(c,c-(e+c-o));i.push(pu(pu({},a),{insert:a.insert.slice(f,s)})),e+=c}else e+=c,i.push(a)}return i}function ca(t){return t?r.isText(t)?t.text.length:1:0}function fa(n,e,i){var o;if(0===i.length)throw new Error("Path has to a have a length >= 1");if(r.isText(e))throw new Error("Cannot descent into slate text");var u=yu(i),a=u[0],c=u.slice(1),f=function(t,r){return t.children.slice(0,r).reduce((function(t,r){return t+ca(r)}),0)}(e,a),s=e.children[a],l=ia(n),v=ca(s),d=aa(l,f,v);if(d.length>1)throw new Error("Path doesn't match yText, yTarget spans multiple nodes");var p=null===(o=d[0])||void 0===o?void 0:o.insert;if(c.length>0){if(!(p instanceof t.XmlText))throw new Error("Path doesn't match yText, cannot descent into non-yText");return fa(p,s,c)}return{yParent:n,textRange:{start:f,end:f+v},yTarget:p instanceof t.XmlText?p:void 0,slateParent:e,slateTarget:s,targetDelta:d}}function sa(t,n,e){void 0===e&&(e={});for(var i=e.assoc,o=void 0===i?0:i,u=e.insert,a=void 0!==u&&u,c=0,f=0,s=0;s<t.children.length;s+=1){var l=t.children[s],v=r.isText(l)?l.text.length:1;v>0&&(f=s);var d=c+v;if(v>0&&(o>=0?d>n:d>=n))return[s,n-c];c+=v}if(n>c+(a?1:0))throw new Error("yOffset out of bounds");if(a)return[t.children.length,0];var p=t.children[f];return[f,r.isText(p)?p.text.length:1]}function la(n,e,i){for(var o=[i];o[0]!==n;){var u=o[0].parent;if(!u)throw new Error("yText isn't a descendant of root element");if(!(u instanceof t.XmlText))throw new Error("Unexpected y parent type");o.unshift(u)}if(o.length<2)return[];var a=e;return o.reduce((function(t,n,e){var i,u,c=o[e+1];if(!c)return t;var f=0,s=ia(n);try{for(var l=gu(s),v=l.next();!v.done;v=l.next()){var d=v.value;if(d.insert===c)break;f+="string"==typeof d.insert?d.insert.length:1}}catch(t){i={error:t}}finally{try{v&&!v.done&&(u=l.return)&&u.call(l)}finally{if(i)throw i.error}}if(r.isText(a))throw new Error("Cannot descent into slate text");var p=yu(sa(a,f),1)[0];return a=a.children[p],t.concat(p)}),[])}function va(t){if(!t.doc)throw new Error("shared type isn't attached to a document")}!function(){if(Qu)return Zu;Qu=1;var t=ae(),r=Sn().includes,n=O(),e=ki();t({target:"Array",proto:!0,forced:n((function(){return!Array(1).includes()}))},{includes:function(t){return r(this,t,arguments.length>1?arguments[1]:void 0)}}),e("includes")}();var da="__slateYjsStoredPosition_";function pa(r,n,e){var i=fa(r,n,e.path),o=i.yTarget,u=i.yParent,a=i.textRange;if(o)throw new Error("Slate point points to a non-text element inside sharedRoot");var c=a.start+e.offset;return t.createRelativePositionFromTypeIndex(u,c,c===a.end?-1:0)}function ha(i,o,u){if(!i.doc)throw new Error("sharedRoot isn't attach to a yDoc");var a=t.createAbsolutePositionFromRelativePosition(u,i.doc);return a&&function(i,o,u){var a=u.type,c=u.index,f=u.assoc;if(!(a instanceof t.XmlText))throw new Error("Absolute position points to a non-XMLText");var s=la(i,o,a),l=n.get(o,s);if(r.isText(l)||!e.isElement(l))throw new Error("Absolute position doesn't match slateRoot, cannot descent into text and EditorRoot");var v=yu(sa(l,c,{assoc:f}),2),d=v[0],p=v[1],h=l.children[d];return r.isText(h)?{path:bu(bu([],yu(s),!1),[d],!1),offset:p}:null}(i,o,a)}function ga(r,n,e){r.setAttribute(da+n,t.encodeRelativePosition(e))}function ya(t,r,n){return Object.fromEntries(Object.entries(t).filter((function(t){var e=yu(t,2)[1];return e.type===r&&(!n||(e.assoc>=0?e.index>=n.start&&e.index<n.end:e.index>n.start&&e.index>=n.end))})))}function ba(r,n,e){var i;void 0===e&&(e="");var o=((i={})[e]=ya(r,n),i);return ia(n).forEach((function(n,i){var u=n.insert;u instanceof t.XmlText&&Object.assign(o,ba(r,u,e?"".concat(e,".").concat(i):i.toString()))})),o}function ma(r,n,e,i){void 0===i&&(i=0);var o=function(r){return va(r),Object.fromEntries(Object.entries(r.getAttributes()).filter((function(t){return yu(t,1)[0].startsWith(da)})).map((function(n){var e=yu(n,2),i=e[0],o=e[1];return[i.slice(da.length),t.createAbsolutePositionFromRelativePosition(t.decodeRelativePosition(o),r.doc)]})).filter((function(t){return yu(t,2)[1]})))}(r),u={"":ya(o,n,{start:i,end:i+ua(e)})};return e.forEach((function(r,n){var e=r.insert;e instanceof t.XmlText&&Object.assign(u,ba(o,e,n.toString()))})),u}function wa(r,n,e,i,o,u,a){void 0===o&&(o=0),void 0===u&&(u=0),void 0===a&&(a="");var c=e[a];c&&Object.entries(c).forEach((function(e){var i=yu(e,2),a=i[0],c=i[1];ga(r,a,t.createRelativePositionFromTypeIndex(n,c.index-u+o,c.assoc))})),i.forEach((function(n,i){var o=n.insert;o instanceof t.XmlText&&wa(r,o,e,ia(o),0,0,a?"".concat(a,".").concat(i):i.toString())}))}function Oa(t,r,n){return{anchor:pa(t,r,n.anchor),focus:pa(t,r,n.focus)}}function Sa(t,r,n){var e=ha(t,r,n.anchor);if(!e)return null;var i=ha(t,r,n.focus);return i?{anchor:e,focus:i}:null}var xa,Ea,ja,Ta,Pa,Ra,Aa,ka,Ca={},La={};function Fa(){if(xa)return La;xa=1;var t=lr();return La.f=t,La}function _a(){if(ja)return Ea;ja=1;var t=l();return Ea=t}function Ma(){if(ka)return Ca;ka=1;var t=ae(),r=l(),n=E(),e=ht(),i=ir(),o=S(),u=Tt(),a=O(),c=fr(),f=Et(),s=Tr(),v=wt(),d=dr(),p=Xo(),h=pt(),g=Ai(),y=Ti(),b=jn(),m=jo(),w=ee(),x=gr(),j=Pr(),T=Pi(),P=dt(),R=Qr(),A=Lo(),k=ar(),C=qr(),L=Hr(),F=sr(),_=lr(),M=Fa(),D=function(){if(Pa)return Ta;Pa=1;var t=_a(),r=fr(),n=Fa(),e=Pr().f;return Ta=function(i){var o=t.Symbol||(t.Symbol={});r(o,i)||e(o,i,{value:n.f(i)})}}(),I=function(){if(Aa)return Ra;Aa=1;var t=E(),r=xt(),n=lr(),e=Qr();return Ra=function(){var i=r("Symbol"),o=i&&i.prototype,u=o&&o.valueOf,a=n("toPrimitive");o&&!o[a]&&e(o,a,(function(r){return t(u,this)}),{arity:1})}}(),z=Fi(),N=Jr(),W=ge().forEach,X=C("hidden"),G="Symbol",B="prototype",U=N.set,Y=N.getterFor(G),V=Object[B],$=r.Symbol,q=$&&$[B],H=r.RangeError,J=r.TypeError,K=r.QObject,Q=x.f,Z=j.f,tt=m.f,rt=P.f,nt=e([].push),et=k("symbols"),it=k("op-symbols"),ot=k("wks"),ut=!K||!K[B]||!K[B].findChild,at=function(t,r,n){var e=Q(V,r);e&&delete V[r],Z(t,r,n),e&&t!==V&&Z(V,r,e)},ct=o&&a((function(){return 7!==g(Z({},"a",{get:function(){return Z(this,"a",{value:7}).a}})).a}))?at:Z,ft=function(t,r){var n=et[t]=g(q);return U(n,{type:G,tag:t,description:r}),o||(n.description=r),n},st=function(t,r,n){t===V&&st(it,r,n),s(t);var e=d(r);return s(n),c(et,e)?(n.enumerable?(c(t,X)&&t[X][e]&&(t[X][e]=!1),n=g(n,{enumerable:h(0,!1)})):(c(t,X)||Z(t,X,h(1,g(null))),t[X][e]=!0),ct(t,e,n)):Z(t,e,n)},lt=function(t,r){s(t);var e=v(r),i=y(e).concat(bt(e));return W(i,(function(r){o&&!n(vt,e,r)||st(t,r,e[r])})),t},vt=function(t){var r=d(t),e=n(rt,this,r);return!(this===V&&c(et,r)&&!c(it,r))&&(!(e||!c(this,r)||!c(et,r)||c(this,X)&&this[X][r])||e)},gt=function(t,r){var n=v(t),e=d(r);if(n!==V||!c(et,e)||c(it,e)){var i=Q(n,e);return!i||!c(et,e)||c(n,X)&&n[X][e]||(i.enumerable=!0),i}},yt=function(t){var r=tt(v(t)),n=[];return W(r,(function(t){c(et,t)||c(L,t)||nt(n,t)})),n},bt=function(t){var r=t===V,n=tt(r?it:v(t)),e=[];return W(n,(function(t){!c(et,t)||r&&!c(V,t)||nt(e,et[t])})),e};return u||($=function(){if(f(q,this))throw new J("Symbol is not a constructor");var t=arguments.length&&void 0!==arguments[0]?p(arguments[0]):void 0,e=F(t),i=function(t){var o=void 0===this?r:this;o===V&&n(i,it,t),c(o,X)&&c(o[X],e)&&(o[X][e]=!1);var u=h(1,t);try{ct(o,e,u)}catch(t){if(!(t instanceof H))throw t;at(o,e,u)}};return o&&ut&&ct(V,e,{configurable:!0,set:i}),ft(e,t)},R(q=$[B],"toString",(function(){return Y(this).tag})),R($,"withoutSetter",(function(t){return ft(F(t),t)})),P.f=vt,j.f=st,T.f=lt,x.f=gt,b.f=m.f=yt,w.f=bt,M.f=function(t){return ft(_(t),t)},o&&(A(q,"description",{configurable:!0,get:function(){return Y(this).description}}),i||R(V,"propertyIsEnumerable",vt,{unsafe:!0}))),t({global:!0,constructor:!0,wrap:!0,forced:!u,sham:!u},{Symbol:$}),W(y(ot),(function(t){D(t)})),t({target:G,stat:!0,forced:!u},{useSetter:function(){ut=!0},useSimple:function(){ut=!1}}),t({target:"Object",stat:!0,forced:!u,sham:!o},{create:function(t,r){return void 0===r?g(t):lt(g(t),r)},defineProperty:st,defineProperties:lt,getOwnPropertyDescriptor:gt}),t({target:"Object",stat:!0,forced:!u},{getOwnPropertyNames:yt}),I(),z($,G),L[X]=!0,Ca}var Da,Ia,za,Na={};function Wa(){if(Ia)return Da;Ia=1;var t=Tt();return Da=t&&!!Symbol.for&&!!Symbol.keyFor}var Xa,Ga={};var Ba,Ua,Ya,Va,$a,qa={};function Ha(){if($a)return qa;$a=1;var t=ae(),r=xt(),n=function(){if(Ua)return Ba;Ua=1;var t=x(),r=Function.prototype,n=r.apply,e=r.call;return Ba="object"==typeof Reflect&&Reflect.apply||(t?e.bind(n):function(){return e.apply(n,arguments)}),Ba}(),e=E(),i=ht(),o=O(),u=Ot(),a=Rt(),c=Eo(),f=function(){if(Va)return Ya;Va=1;var t=ht(),r=se(),n=Ot(),e=gt(),i=Xo(),o=t([].push);return Ya=function(t){if(n(t))return t;if(r(t)){for(var u=t.length,a=[],c=0;c<u;c++){var f=t[c];"string"==typeof f?o(a,f):"number"!=typeof f&&"Number"!==e(f)&&"String"!==e(f)||o(a,i(f))}var s=a.length,l=!0;return function(t,n){if(l)return l=!1,n;if(r(this))return n;for(var e=0;e<s;e++)if(a[e]===t)return n}}}}(),s=Tt(),l=String,v=r("JSON","stringify"),d=i(/./.exec),p=i("".charAt),h=i("".charCodeAt),g=i("".replace),y=i(1..toString),b=/[\uD800-\uDFFF]/g,m=/^[\uD800-\uDBFF]$/,w=/^[\uDC00-\uDFFF]$/,S=!s||o((function(){var t=r("Symbol")("stringify detection");return"[null]"!==v([t])||"{}"!==v({a:t})||"{}"!==v(Object(t))})),j=o((function(){return'"\\udf06\\ud834"'!==v("\udf06\ud834")||'"\\udead"'!==v("\udead")})),T=function(t,r){var i=c(arguments),o=f(r);if(u(o)||void 0!==t&&!a(t))return i[1]=function(t,r){if(u(o)&&(r=e(o,this,l(t),r)),!a(r))return r},n(v,null,i)},P=function(t,r,n){var e=p(n,r-1),i=p(n,r+1);return d(m,t)&&!d(w,i)||d(w,t)&&!d(m,e)?"\\u"+y(h(t,0),16):t};return v&&t({target:"JSON",stat:!0,arity:3,forced:S||j},{stringify:function(t,r,e){var i=c(arguments),o=n(S?T:v,null,i);return j&&"string"==typeof o?g(o,b,P):o}}),qa}var Ja,Ka,Qa={};Ka||(Ka=1,Ma(),function(){if(za)return Na;za=1;var t=ae(),r=xt(),n=fr(),e=Xo(),i=ar(),o=Wa(),u=i("string-to-symbol-registry"),a=i("symbol-to-string-registry");t({target:"Symbol",stat:!0,forced:!o},{for:function(t){var i=e(t);if(n(u,i))return u[i];var o=r("Symbol")(i);return u[i]=o,a[o]=i,o}})}(),function(){if(Xa)return Ga;Xa=1;var t=ae(),r=fr(),n=Rt(),e=At(),i=ar(),o=Wa(),u=i("symbol-to-string-registry");t({target:"Symbol",stat:!0,forced:!o},{keyFor:function(t){if(!n(t))throw new TypeError(e(t)+" is not a symbol");if(r(u,t))return u[t]}})}(),Ha(),function(){if(Ja)return Qa;Ja=1;var t=ae(),r=Tt(),n=O(),e=ee(),i=cr();t({target:"Object",stat:!0,forced:!r||n((function(){e.f(1)}))},{getOwnPropertySymbols:function(t){var r=e.f;return r?r(i(t)):[]}})}());var Za,tc={};!function(){if(Za)return tc;Za=1;var t=ae(),r=S(),n=l(),e=ht(),i=fr(),o=Ot(),u=Et(),a=Xo(),c=Lo(),f=oe(),s=n.Symbol,v=s&&s.prototype;if(r&&o(s)&&(!("description"in v)||void 0!==s().description)){var d={},p=function(){var t=arguments.length<1||void 0===arguments[0]?void 0:a(arguments[0]),r=u(v,this)?new s(t):void 0===t?s():s(t);return""===t&&(d[r]=!0),r};f(p,s),p.prototype=v,v.constructor=p;var h="Symbol(description detection)"===String(s("description detection")),g=e(v.valueOf),y=e(v.toString),b=/^Symbol\((.*)\)[^)]+$/,m=e("".replace),w=e("".slice);c(v,"description",{configurable:!0,get:function(){var t=g(this);if(i(d,t))return"";var r=y(t),n=h?w(r,7,-1):m(r,b,"$1");return""===n?void 0:n}}),t({global:!0,constructor:!0,forced:!0},{Symbol:p})}}();var rc,nc;nc||(nc=1,rc||(rc=1,Co()("WeakSet",(function(t){return function(){return t(this,arguments.length?arguments[0]:void 0)}}),Zo())));var ec,ic={};function oc(t){return function(t){for(var r=[],n=1;n<arguments.length;n++)r[n-1]=arguments[n];return Object.fromEntries(Object.entries(t).filter((function(t){var n=yu(t,1)[0];return!r.includes(n)})))}(t,r.isText(t)?"text":"children")}function uc(t){var r=ia(t),n=r.length>0?r.map(ac):[{text:""}];return pu(pu({},t.getAttributes()),{children:n})}function ac(t){return"string"==typeof t.insert?pu(pu({},t.attributes),{text:t.insert}):uc(t.insert)}function cc(t){return t.map((function(t){return r.isText(t)?{insert:t.text,attributes:oc(t)}:{insert:fc(t)}}))}function fc(r){var n=r.children,e=hu(r,["children"]),i=new t.XmlText;return Object.entries(e).forEach((function(t){var r=yu(t,2),n=r[0],e=r[1];i.setAttribute(n,e)})),i.applyDelta(cc(n),{sanitize:!1}),i}function sc(e,o,u){var a=u.target,c=u.changes,f=u.delta;if(!(a instanceof t.XmlText))throw new Error("Unexpected target node type");var s=[],l=la(e,o,a),v=n.get(o,l);if(r.isText(v))throw new Error("Cannot apply yTextEvent to text node");var d=Array.from(c.keys.entries());if(l.length>0&&d.length>0){var p=Object.fromEntries(d.map((function(t){var r=yu(t,2),n=r[0];return[n,"delete"===r[1].action?null:a.getAttribute(n)]}))),h=Object.fromEntries(d.map((function(t){var r=yu(t,1)[0];return[r,v[r]]})));s.push({type:"set_node",newProperties:p,properties:h,path:l})}return f.length>0&&s.push.apply(s,bu([],yu(function(t,n,e){var o=[],u=e.reduce((function(t,r){return"retain"in r?t+r.retain:"delete"in r?t+r.delete:t}),0);return e.reverse().forEach((function(e){var a,c;if("attributes"in e&&"retain"in e)for(var f=yu(sa(t,u-e.retain),2),s=f[0],l=f[1],v=yu(sa(t,u,{assoc:-1}),2),d=v[0],p=v[1],h=d;h>=s;h-=1){var g=t.children[h],y=bu(bu([],yu(n),!1),[h],!1);if(r.isText(g)){var b=e.attributes,m=ea.apply(void 0,bu([t],yu(Object.keys(e.attributes)),!1));if(h===s||h===d){var w=h===s?l:0;if((x=h===d?p:g.text.length)!==g.text.length&&o.push({type:"split_node",path:y,position:x,properties:oc(g)}),0!==w){o.push({type:"split_node",path:y,position:w,properties:(c=pu(pu({},oc(g)),b),Object.fromEntries(Object.entries(c).filter((function(t){return null!==yu(t,2)[1]}))))});continue}}o.push({type:"set_node",newProperties:b,path:y,properties:m})}}if("retain"in e&&(u-=e.retain),"delete"in e){var O=yu(sa(t,u-e.delete),2),S=(s=O[0],l=O[1],yu(sa(t,u,{assoc:-1}),2));for(d=S[0],h=0===(p=S[1])?d-1:d;h>=s;h-=1)if(g=t.children[h],y=bu(bu([],yu(n),!1),[h],!1),!r.isText(g)||h!==s&&h!==d)o.push({type:"remove_node",node:g,path:y}),u-=ca(g);else{w=h===s?l:0;var x=h===d?p:g.text.length;o.push({type:"remove_text",offset:w,text:g.text.slice(w,x),path:y}),u-=x-w}}else if("insert"in e){var E=yu(sa(t,u,{insert:!0}),2),j=(h=E[0],E[1]);if(g=t.children[h],y=bu(bu([],yu(n),!1),[h],!1),r.isText(g)){var T=o[o.length-1],P=null!=T&&"insert_node"===T.type?T.node:oc(g),R=[];if(null==T||"insert_node"!==T.type&&"insert_text"!==T.type&&"split_node"!==T.type&&"set_node"!==T.type||(R=T.path),"string"==typeof e.insert&&na(null!==(a=e.attributes)&&void 0!==a?a:{},P)&&i.equals(y,R))return o.push({type:"insert_text",offset:j,text:e.insert,path:y});var A=ac(e);return 0===j?o.push({type:"insert_node",path:y,node:A}):(j<g.text.length&&o.push({type:"split_node",path:y,position:j,properties:oc(g)}),o.push({type:"insert_node",path:i.next(y),node:A}))}return o.push({type:"insert_node",path:y,node:ac(e)})}})),o}(v,l,f)),!1)),s}function lc(r,n,e){o.withoutNormalizing(n,(function(){e.forEach((function(e){(function(r,n,e){if(e instanceof t.YTextEvent)return sc(r,n,e);throw new Error("Unexpected Y event type")})(r,n,e).forEach((function(t){n.apply(t)}))}))}))}function vc(t){return t.map((function(t){return"string"==typeof t.insert?t:pu(pu({},t),{insert:dc(t.insert)})}))}function dc(r){var n=new t.XmlText,e=r.getAttributes();return Object.entries(e).forEach((function(t){var r=yu(t,2),e=r[0],i=r[1];n.setAttribute(e,i)})),n.applyDelta(vc(ia(r)),{sanitize:!1}),n}!function(){if(ec)return ic;ec=1;var t=ae(),r=cr(),n=Ti();t({target:"Object",stat:!0,forced:O()((function(){n(1)}))},{keys:function(t){return n(r(t))}})}();var pc={insert_node:function(t,n,e){var i=fa(t,n,e.path),o=i.yParent,u=i.textRange;if(r.isText(e.node))return o.insert(u.start,e.node.text,oc(e.node));o.insertEmbed(u.start,fc(e.node))},remove_node:function(t,r,n){var e=fa(t,r,n.path),i=e.yParent,o=e.textRange;i.delete(o.start,o.end-o.start)},set_node:function(t,r,n){var e=fa(t,r,n.path),i=e.yTarget,o=e.textRange,u=e.yParent;if(i)return Object.entries(n.newProperties).forEach((function(t){var r=yu(t,2),n=r[0],e=r[1];if(null===e)return i.removeAttribute(n);i.setAttribute(n,e)})),Object.entries(n.properties).forEach((function(t){var r=yu(t,1)[0];Object.prototype.hasOwnProperty.call(n.newProperties,r)||i.removeAttribute(r)}));var a=Object.fromEntries(Object.keys(n.properties).map((function(t){return[t,null]}))),c=pu(pu({},a),n.newProperties);u.format(o.start,o.end-o.start,c)},merge_node:function(t,e,o){var u=fa(t,e,o.path),a=fa(u.yParent,u.slateParent,i.previous(o.path.slice(-1)));if(!u.yTarget!=!a.yTarget)throw new Error("Cannot merge y text with y element");if(!a.yTarget||!u.yTarget){var c=u.yParent,f=u.textRange,s=u.slateTarget;if(!s)throw new Error("Expected Slate target node for merge op.");var l=n.get(e,i.previous(o.path));if(!r.isText(l))throw new Error("Path points to Y.Text but not a Slate text node.");var v=oc(s),d=oc(l),p=Object.keys(v).reduce((function(t,r){var n;return r in d?t:pu(pu({},t),((n={})[r]=null,n))}),{});return c.format(f.start,f.end-f.start,pu(pu({},p),d))}var h=a.yTarget.length,g=ia(u.yTarget),y=vc(g),b=ma(t,u.yTarget,g,h),m=bu([{retain:h}],yu(y),!1);a.yTarget.applyDelta(m,{sanitize:!1}),u.yParent.delete(u.textRange.start,u.textRange.end-u.textRange.start),wa(t,a.yTarget,b,y,h)},move_node:function(t,e,o){var u=i.parent(o.newPath),a=o.newPath[o.newPath.length-1],c=n.get(e,u);if(r.isText(c))throw new Error("Cannot move slate node into text element");var f=bu(bu([],yu(u),!1),[Math.min(a,c.children.length)],!1),s=fa(t,e,o.path),l=fa(t,e,f),v=vc(s.targetDelta),d=ma(t,s.yParent,s.targetDelta);s.yParent.delete(s.textRange.start,s.textRange.end-s.textRange.start);var p=ua(ia(l.yParent)),h=Math.min(l.textRange.start,p),g=bu([{retain:h}],yu(v),!1);l.yParent.applyDelta(g,{sanitize:!1}),wa(t,l.yParent,d,v,h,s.textRange.start)},split_node:function(n,e,i){var o=fa(n,e,i.path);if(!o.slateTarget)throw new Error("Y target without corresponding slate node");if(!o.yTarget){if(!r.isText(o.slateTarget))throw new Error("Mismatch node type between y target and slate node");var u={};return o.targetDelta.forEach((function(t){t.attributes&&Object.keys(t.attributes).forEach((function(t){u[t]=null}))})),o.yParent.format(o.textRange.start,o.textRange.end-o.textRange.start,pu(pu({},u),i.properties))}if(r.isText(o.slateTarget))throw new Error("Mismatch node type between y target and slate node");var a=fa(o.yTarget,o.slateTarget,[i.position]),c=o.slateTarget.children.slice(0,i.position).reduce((function(t,r){return t+ca(r)}),0),f=o.slateTarget.children.reduce((function(t,r){return t+ca(r)}),0),s=aa(ia(o.yTarget),c,f-c),l=vc(s),v=ma(n,o.yTarget,s,c),d=new t.XmlText;d.applyDelta(l,{sanitize:!1}),Object.entries(i.properties).forEach((function(t){var r=yu(t,2),n=r[0],e=r[1];d.setAttribute(n,e)})),o.yTarget.delete(a.textRange.start,o.yTarget.length-a.textRange.start),o.yParent.insertEmbed(o.textRange.end,d),wa(n,d,v,l,0,c)}};var hc=pu(pu(pu({},{insert_text:function(t,e,i){var o=fa(t,e,i.path),u=o.yParent,a=o.textRange,c=n.get(e,i.path);if(!r.isText(c))throw new Error("Cannot insert text into non-text node");u.insert(a.start+i.offset,i.text,oc(c))},remove_text:function(t,r,n){var e=fa(t,r,n.path),i=e.yParent,o=e.textRange;i.delete(o.start+n.offset,n.text.length)}}),pc),{set_selection:function(){}});var gc=Symbol("slate-yjs-operation"),yc=Symbol("slate-yjs-position-storage"),bc=new WeakMap,mc=new WeakMap,wc=new WeakSet,Oc={isYjsEditor:function(r){return o.isEditor(r)&&r.sharedRoot instanceof t.XmlText&&"localOrigin"in r&&"positionStorageOrigin"in r&&"function"==typeof r.applyRemoteEvents&&"function"==typeof r.storeLocalChange&&"function"==typeof r.flushLocalChanges&&"function"==typeof r.isLocalOrigin&&"function"==typeof r.connect&&"function"==typeof r.disconnect},localChanges:function(t){var r;return null!==(r=mc.get(t))&&void 0!==r?r:[]},applyRemoteEvents:function(t,r,n){t.applyRemoteEvents(r,n)},storeLocalChange:function(t,r){t.storeLocalChange(r)},flushLocalChanges:function(t){t.flushLocalChanges()},connected:function(t){return wc.has(t)},connect:function(t){t.connect()},disconnect:function(t){t.disconnect()},isLocal:function(t){return t.isLocalOrigin(Oc.origin(t))},origin:function(t){var r=bc.get(t);return void 0!==r?r:t.localOrigin},withOrigin:function(t,r,n){var e=Oc.origin(t);bc.set(t,r),n(),bc.set(t,e)},storePosition:function(t,r,n){var e=t.sharedRoot,i=t.positionStorageOrigin;va(e);var o=pa(e,t,n);e.doc.transact((function(){ga(e,r,o)}),i)},removeStoredPosition:function(t,r){var n=t.sharedRoot,e=t.positionStorageOrigin;va(n),n.doc.transact((function(){!function(t,r){t.removeAttribute(da+r)}(n,r)}),e)},position:function(r,n){var e=function(r,n){var e=r.getAttribute(da+n);return e?t.decodeRelativePosition(e):null}(r.sharedRoot,n);if(e)return ha(r.sharedRoot,r,e)},storedPositionsRelative:function(r){return n=r.sharedRoot,Object.fromEntries(Object.entries(n.getAttributes()).filter((function(t){return yu(t,1)[0].startsWith(da)})).map((function(r){var n=yu(r,2),e=n[0],i=n[1];return[e.slice(da.length),t.createRelativePositionFromJSON(i)]})));var n}};function Sc(t,r){return void 0===r&&(r={}),function(n){var e,i,u=n;u.sharedRoot=t,u.localOrigin=null!==(e=r.localOrigin)&&void 0!==e?e:gc,u.positionStorageOrigin=null!==(i=r.positionStorageOrigin)&&void 0!==i?i:yc,u.applyRemoteEvents=function(t,r){Oc.flushLocalChanges(u),o.withoutNormalizing(u,(function(){Oc.withOrigin(u,r,(function(){lc(u.sharedRoot,u,t)}))}))},u.isLocalOrigin=function(t){return t===u.localOrigin};var a=function(t,r){u.isLocalOrigin(r.origin)||Oc.applyRemoteEvents(u,t,r.origin)},c=null;r.autoConnect&&(c=setTimeout((function(){c=null,Oc.connect(u)}))),u.connect=function(){if(Oc.connected(u))throw new Error("already connected");u.sharedRoot.observeDeep(a);var t=uc(u.sharedRoot);u.children=t.children,wc.add(u),o.normalize(n,{force:!0}),n.operations.length||n.onChange()},u.disconnect=function(){c&&clearTimeout(c),Oc.flushLocalChanges(u),u.sharedRoot.unobserveDeep(a),wc.delete(u)},u.storeLocalChange=function(t){mc.set(u,bu(bu([],yu(Oc.localChanges(u)),!1),[{op:t,doc:n.children,origin:Oc.origin(u)}],!1))},u.flushLocalChanges=function(){va(u.sharedRoot);var t=Oc.localChanges(u);mc.delete(u);var r=[];t.forEach((function(t){var n=r[r.length-1];if(n&&n[0].origin===t.origin)return n.push(t);r.push([t])})),r.forEach((function(t){va(u.sharedRoot),u.sharedRoot.doc.transact((function(){t.forEach((function(t){va(u.sharedRoot),function(t,r,n){var e=hc[n.type];if(!e)throw new Error("Unknown operation: ".concat(n.type));e(t,r,n)}(u.sharedRoot,{children:t.doc},t.op)}))}),t[0].origin)}))};var f=u.apply,s=u.onChange;return u.apply=function(t){Oc.connected(u)&&Oc.isLocal(u)&&Oc.storeLocalChange(u,t),f(t)},u.onChange=function(){Oc.connected(u)&&Oc.flushLocalChanges(u),s()},u}}var xc=new WeakMap,Ec={isCursorEditor:function(t){return Oc.isYjsEditor(t)&&t.awareness&&"string"==typeof t.cursorDataField&&"string"==typeof t.selectionStateField&&"function"==typeof t.sendCursorPosition&&"function"==typeof t.sendCursorData},sendCursorPosition:function(t,r){void 0===r&&(r=t.selection),t.sendCursorPosition(r)},sendCursorData:function(t,r){t.sendCursorData(r)},on:function(t,r,n){var e;if("change"===r){var i=null!==(e=xc.get(t))&&void 0!==e?e:new Set;i.add(n),t&&xc.set(t,i)}},off:function(t,r,n){if("change"===r){var e=xc.get(t);e&&e.delete(n)}},cursorState:function(t,r){var n;if(r===t.awareness.clientID||!Oc.connected(t))return null;var e=t.awareness.getStates().get(r);return e?{relativeSelection:null!==(n=e[t.selectionStateField])&&void 0!==n?n:null,data:e[t.cursorDataField],clientId:r}:null},cursorStates:function(t){return Oc.connected(t)?Object.fromEntries(Array.from(t.awareness.getStates().entries(),(function(r){var n=yu(r,2),e=n[0],i=n[1];return e!==t.awareness.clientID&&i?[e,{relativeSelection:i[t.selectionStateField],data:i[t.cursorDataField]}]:null})).filter(Array.isArray)):{}}};function jc(r,n){return void 0===n&&(n={}),function(e){var i=n.cursorStateField,o=void 0===i?"selection":i,u=n.cursorDataField,a=void 0===u?"data":u,c=n.autoSend,f=void 0===c||c,s=n.data,l=e;l.awareness=r,l.cursorDataField=a,l.selectionStateField=o,l.sendCursorData=function(t){l.awareness.setLocalStateField(l.cursorDataField,t)},l.sendCursorPosition=function(r){var n=l.awareness.getLocalState(),e=null==n?void 0:n[o];if(r){var i=Oa(l.sharedRoot,l,r),u=i.anchor,a=i.focus;e&&t.compareRelativePositions(u,e)&&t.compareRelativePositions(a,e)||l.awareness.setLocalStateField(l.selectionStateField,{anchor:u,focus:a})}else e&&l.awareness.setLocalStateField(l.selectionStateField,null)};var v=function(t){var r=xc.get(l);if(r){var n=l.awareness.clientID,e={added:t.added.filter((function(t){return t!==n})),removed:t.removed.filter((function(t){return t!==n})),updated:t.updated.filter((function(t){return t!==n}))};(e.added.length>0||e.removed.length>0||e.updated.length>0)&&r.forEach((function(t){return t(e)}))}},d=l.connect,p=l.disconnect;return l.connect=function(){if(d(),l.awareness.on("change",v),v({removed:[],added:Array.from(l.awareness.getStates().keys()),updated:[]}),f){s&&Ec.sendCursorData(l,s);var t=l.onChange;l.onChange=function(){t(),Oc.connected(l)&&Ec.sendCursorPosition(l)}}},l.disconnect=function(){l.awareness.off("change",v),v({removed:Array.from(l.awareness.getStates().keys()),added:[],updated:[]}),p()},l}}var Tc=new WeakMap,Pc=Symbol("slate-yjs-history-without-saving"),Rc={isYHistoryEditor:function(r){return Oc.isYjsEditor(r)&&r.undoManager instanceof t.UndoManager&&"function"==typeof r.undo&&"function"==typeof r.redo&&"withoutSavingOrigin"in r},canUndo:function(t){return t.undoManager.undoStack.length>0},canRedo:function(t){return t.undoManager.redoStack.length>0},isSaving:function(t){return t.undoManager.trackedOrigins.has(Oc.origin(t))},withoutSaving:function(t,r){Oc.withOrigin(t,t.withoutSavingOrigin,r)}};function Ac(r){return void 0===r&&(r={}),function(n){var e=n,i=r.withoutSavingOrigin,o=void 0===i?Pc:i,a=r.trackedOrigins,c=void 0===a?new Set([e.localOrigin]):a,f=hu(r,["withoutSavingOrigin","trackedOrigins"]),s=new t.UndoManager(e.sharedRoot,pu({trackedOrigins:c},f));e.undoManager=s,e.withoutSavingOrigin=o;var l=e.onChange,v=e.isLocalOrigin;e.onChange=function(){l(),Tc.set(e,e.selection&&Oa(e.sharedRoot,e,e.selection))},e.isLocalOrigin=function(t){return t===e.withoutSavingOrigin||v(t)};var d=function(t){var r=t.stackItem;r.meta.set("selection",e.selection&&Oa(e.sharedRoot,e,e.selection)),r.meta.set("selectionBefore",Tc.get(e))},p=function(t){t.stackItem.meta.set("selection",e.selection&&Oa(e.sharedRoot,e,e.selection))},h=function(t){var r=t.stackItem,n="undo"===t.type?e.undoManager.redoStack:e.undoManager.undoStack,i=n[n.length-1];i&&(i.meta.set("selection",r.meta.get("selectionBefore")),i.meta.set("selectionBefore",r.meta.get("selection")));var o=r.meta.get("selectionBefore");if(o){var a=Sa(e.sharedRoot,e,o);a&&u.select(e,a)}},g=e.connect,y=e.disconnect;return e.connect=function(){g(),e.undoManager.on("stack-item-added",d),e.undoManager.on("stack-item-popped",h),e.undoManager.on("stack-item-updated",p)},e.disconnect=function(){e.undoManager.off("stack-item-added",d),e.undoManager.off("stack-item-popped",h),e.undoManager.off("stack-item-updated",p),y()},e.undo=function(){Oc.connected(e)&&(Oc.flushLocalChanges(e),e.undoManager.undo())},e.redo=function(){Oc.connected(e)&&(Oc.flushLocalChanges(e),e.undoManager.redo())},e}}export{Ec as CursorEditor,Rc as YHistoryEditor,Oc as YjsEditor,ha as relativePositionToSlatePoint,Sa as relativeRangeToSlateRange,cc as slateNodesToInsertDelta,pa as slatePointToRelativePosition,Oa as slateRangeToRelativeRange,jc as withCursors,Ac as withYHistory,Sc as withYjs,uc as yTextToSlateElement};
2
- //# sourceMappingURL=index.mjs.map
1
+ import * as Y from 'yjs';
2
+ import { Text, Node, Element, Path, Editor, Transforms } from 'slate';
3
+
4
+ /******************************************************************************
5
+ Copyright (c) Microsoft Corporation.
6
+
7
+ Permission to use, copy, modify, and/or distribute this software for any
8
+ purpose with or without fee is hereby granted.
9
+
10
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
11
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
13
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
15
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16
+ PERFORMANCE OF THIS SOFTWARE.
17
+ ***************************************************************************** */
18
+ /* global Reflect, Promise, SuppressedError, Symbol */
19
+
20
+
21
+ var __assign = function() {
22
+ __assign = Object.assign || function __assign(t) {
23
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
24
+ s = arguments[i];
25
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
26
+ }
27
+ return t;
28
+ };
29
+ return __assign.apply(this, arguments);
30
+ };
31
+
32
+ function __rest(s, e) {
33
+ var t = {};
34
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
35
+ t[p] = s[p];
36
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
37
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
38
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
39
+ t[p[i]] = s[p[i]];
40
+ }
41
+ return t;
42
+ }
43
+
44
+ function __values(o) {
45
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
46
+ if (m) return m.call(o);
47
+ if (o && typeof o.length === "number") return {
48
+ next: function () {
49
+ if (o && i >= o.length) o = void 0;
50
+ return { value: o && o[i++], done: !o };
51
+ }
52
+ };
53
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
54
+ }
55
+
56
+ function __read(o, n) {
57
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
58
+ if (!m) return o;
59
+ var i = m.call(o), r, ar = [], e;
60
+ try {
61
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
62
+ }
63
+ catch (error) { e = { error: error }; }
64
+ finally {
65
+ try {
66
+ if (r && !r.done && (m = i["return"])) m.call(i);
67
+ }
68
+ finally { if (e) throw e.error; }
69
+ }
70
+ return ar;
71
+ }
72
+
73
+ function __spreadArray(to, from, pack) {
74
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
75
+ if (ar || !(i in from)) {
76
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
77
+ ar[i] = from[i];
78
+ }
79
+ }
80
+ return to.concat(ar || Array.prototype.slice.call(from));
81
+ }
82
+
83
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
84
+ var e = new Error(message);
85
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
86
+ };
87
+
88
+ function isObject(o) {
89
+ return Object.prototype.toString.call(o) === '[object Object]';
90
+ }
91
+ function isPlainObject(o) {
92
+ if (!isObject(o)) {
93
+ return false;
94
+ }
95
+ // If has modified constructor
96
+ var ctor = o.constructor;
97
+ if (ctor === undefined) {
98
+ return true;
99
+ }
100
+ // If has modified prototype
101
+ var prot = ctor.prototype;
102
+ if (isObject(prot) === false) {
103
+ return false;
104
+ }
105
+ // If constructor does not have an Object-specific method
106
+ if (Object.prototype.hasOwnProperty.call(prot, 'isPrototypeOfOf')) {
107
+ return false;
108
+ }
109
+ // Most likely a plain Object
110
+ return true;
111
+ }
112
+ // Slates deep equality function: https://github.com/ianstormtaylor/slate/blob/68aff89e892fe15a16314398ff052ade6068900b/packages/slate/src/utils/deep-equal.ts#L13
113
+ // We have to match slates deepEquals behavior to merge insert deltas in the same way slate does.
114
+ function deepEquals(node, another) {
115
+ // eslint-disable-next-line guard-for-in
116
+ for (var key in node) {
117
+ var a = node[key];
118
+ var b = another[key];
119
+ if (isPlainObject(a) && isPlainObject(b)) {
120
+ if (!deepEquals(a, b)) {
121
+ return false;
122
+ }
123
+ }
124
+ else if (Array.isArray(a) && Array.isArray(b)) {
125
+ if (a.length !== b.length) {
126
+ return false;
127
+ }
128
+ for (var i = 0; i < a.length; i += 1) {
129
+ if (a[i] !== b[i]) {
130
+ return false;
131
+ }
132
+ }
133
+ }
134
+ else if (a !== b) {
135
+ return false;
136
+ }
137
+ }
138
+ for (var key in another) {
139
+ if (node[key] === undefined && another[key] !== undefined) {
140
+ return false;
141
+ }
142
+ }
143
+ return true;
144
+ }
145
+ function pick(obj) {
146
+ var keys = [];
147
+ for (var _i = 1; _i < arguments.length; _i++) {
148
+ keys[_i - 1] = arguments[_i];
149
+ }
150
+ return Object.fromEntries(Object.entries(obj).filter(function (_a) {
151
+ var _b = __read(_a, 1), key = _b[0];
152
+ return keys.includes(key);
153
+ }));
154
+ }
155
+ function omit(obj) {
156
+ var keys = [];
157
+ for (var _i = 1; _i < arguments.length; _i++) {
158
+ keys[_i - 1] = arguments[_i];
159
+ }
160
+ return Object.fromEntries(Object.entries(obj).filter(function (_a) {
161
+ var _b = __read(_a, 1), key = _b[0];
162
+ return !keys.includes(key);
163
+ }));
164
+ }
165
+ function omitNullEntries(obj) {
166
+ return Object.fromEntries(Object.entries(obj).filter(function (_a) {
167
+ var _b = __read(_a, 2), value = _b[1];
168
+ return value !== null;
169
+ }));
170
+ }
171
+
172
+ function normalizeInsertDelta(delta) {
173
+ var e_1, _a;
174
+ var _b, _c;
175
+ var normalized = [];
176
+ try {
177
+ for (var delta_1 = __values(delta), delta_1_1 = delta_1.next(); !delta_1_1.done; delta_1_1 = delta_1.next()) {
178
+ var element = delta_1_1.value;
179
+ if (typeof element.insert === 'string' && element.insert.length === 0) {
180
+ continue;
181
+ }
182
+ var prev = normalized[normalized.length - 1];
183
+ if (!prev || typeof prev.insert !== 'string' || typeof element.insert !== 'string') {
184
+ normalized.push(element);
185
+ continue;
186
+ }
187
+ var merge = prev.attributes === element.attributes
188
+ || (!prev.attributes === !element.attributes
189
+ && deepEquals((_b = prev.attributes) !== null && _b !== void 0 ? _b : {}, (_c = element.attributes) !== null && _c !== void 0 ? _c : {}));
190
+ if (merge) {
191
+ prev.insert += element.insert;
192
+ continue;
193
+ }
194
+ normalized.push(element);
195
+ }
196
+ }
197
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
198
+ finally {
199
+ try {
200
+ if (delta_1_1 && !delta_1_1.done && (_a = delta_1.return)) _a.call(delta_1);
201
+ }
202
+ finally { if (e_1) throw e_1.error; }
203
+ }
204
+ return normalized;
205
+ }
206
+ function yTextToInsertDelta(yText) {
207
+ return normalizeInsertDelta(yText.toDelta());
208
+ }
209
+ function getInsertLength(_a) {
210
+ var insert = _a.insert;
211
+ return typeof insert === 'string' ? insert.length : 1;
212
+ }
213
+ function getInsertDeltaLength(delta) {
214
+ return delta.reduce(function (curr, element) { return curr + getInsertLength(element); }, 0);
215
+ }
216
+ function sliceInsertDelta(delta, start, length) {
217
+ if (length < 1) {
218
+ return [];
219
+ }
220
+ var currentOffset = 0;
221
+ var sliced = [];
222
+ var end = start + length;
223
+ for (var i = 0; i < delta.length; i += 1) {
224
+ if (currentOffset >= end) {
225
+ break;
226
+ }
227
+ var element = delta[i];
228
+ var elementLength = getInsertLength(element);
229
+ if (currentOffset + elementLength <= start) {
230
+ currentOffset += elementLength;
231
+ continue;
232
+ }
233
+ if (typeof element.insert !== 'string') {
234
+ currentOffset += elementLength;
235
+ sliced.push(element);
236
+ continue;
237
+ }
238
+ var startOffset = Math.max(0, start - currentOffset);
239
+ var endOffset = Math.min(elementLength, elementLength - (currentOffset + elementLength - end));
240
+ sliced.push(__assign(__assign({}, element), { insert: element.insert.slice(startOffset, endOffset) }));
241
+ currentOffset += elementLength;
242
+ }
243
+ return sliced;
244
+ }
245
+
246
+ function getSlateNodeYLength(node) {
247
+ if (!node) {
248
+ return 0;
249
+ }
250
+ return Text.isText(node) ? node.text.length : 1;
251
+ }
252
+ function slatePathOffsetToYOffset(element, pathOffset) {
253
+ return element.children
254
+ .slice(0, pathOffset)
255
+ .reduce(function (yOffset, node) { return yOffset + getSlateNodeYLength(node); }, 0);
256
+ }
257
+ function getYTarget(yRoot, slateRoot, path) {
258
+ var _a;
259
+ if (path.length === 0) {
260
+ throw new Error('Path has to a have a length >= 1');
261
+ }
262
+ if (Text.isText(slateRoot)) {
263
+ throw new Error('Cannot descent into slate text');
264
+ }
265
+ var _b = __read(path), pathOffset = _b[0], childPath = _b.slice(1);
266
+ var yOffset = slatePathOffsetToYOffset(slateRoot, pathOffset);
267
+ var targetNode = slateRoot.children[pathOffset];
268
+ var delta = yTextToInsertDelta(yRoot);
269
+ var targetLength = getSlateNodeYLength(targetNode);
270
+ var targetDelta = sliceInsertDelta(delta, yOffset, targetLength);
271
+ if (targetDelta.length > 1) {
272
+ throw new Error("Path doesn't match yText, yTarget spans multiple nodes");
273
+ }
274
+ var yTarget = (_a = targetDelta[0]) === null || _a === void 0 ? void 0 : _a.insert;
275
+ if (childPath.length > 0) {
276
+ if (!(yTarget instanceof Y.XmlText)) {
277
+ throw new Error("Path doesn't match yText, cannot descent into non-yText");
278
+ }
279
+ return getYTarget(yTarget, targetNode, childPath);
280
+ }
281
+ return {
282
+ yParent: yRoot,
283
+ textRange: { start: yOffset, end: yOffset + targetLength },
284
+ yTarget: yTarget instanceof Y.XmlText ? yTarget : undefined,
285
+ slateParent: slateRoot,
286
+ slateTarget: targetNode,
287
+ targetDelta: targetDelta,
288
+ };
289
+ }
290
+ function yOffsetToSlateOffsets(parent, yOffset, opts) {
291
+ if (opts === void 0) { opts = {}; }
292
+ var _a = opts.assoc, assoc = _a === void 0 ? 0 : _a, _b = opts.insert, insert = _b === void 0 ? false : _b;
293
+ var currentOffset = 0;
294
+ var lastNonEmptyPathOffset = 0;
295
+ for (var pathOffset = 0; pathOffset < parent.children.length; pathOffset += 1) {
296
+ var child_1 = parent.children[pathOffset];
297
+ var nodeLength = Text.isText(child_1) ? child_1.text.length : 1;
298
+ if (nodeLength > 0) {
299
+ lastNonEmptyPathOffset = pathOffset;
300
+ }
301
+ var endOffset = currentOffset + nodeLength;
302
+ if (nodeLength > 0 && (assoc >= 0 ? endOffset > yOffset : endOffset >= yOffset)) {
303
+ return [pathOffset, yOffset - currentOffset];
304
+ }
305
+ currentOffset += nodeLength;
306
+ }
307
+ if (yOffset > currentOffset + (insert ? 1 : 0)) {
308
+ throw new Error('yOffset out of bounds');
309
+ }
310
+ if (insert) {
311
+ return [parent.children.length, 0];
312
+ }
313
+ var child = parent.children[lastNonEmptyPathOffset];
314
+ var textOffset = Text.isText(child) ? child.text.length : 1;
315
+ return [lastNonEmptyPathOffset, textOffset];
316
+ }
317
+ function getSlatePath(sharedRoot, slateRoot, yText) {
318
+ var yNodePath = [yText];
319
+ while (yNodePath[0] !== sharedRoot) {
320
+ var yParent = yNodePath[0].parent;
321
+ if (!yParent) {
322
+ throw new Error("yText isn't a descendant of root element");
323
+ }
324
+ if (!(yParent instanceof Y.XmlText)) {
325
+ throw new Error('Unexpected y parent type');
326
+ }
327
+ yNodePath.unshift(yParent);
328
+ }
329
+ if (yNodePath.length < 2) {
330
+ return [];
331
+ }
332
+ var slateParent = slateRoot;
333
+ return yNodePath.reduce(function (path, yParent, idx) {
334
+ var e_1, _a;
335
+ var yChild = yNodePath[idx + 1];
336
+ if (!yChild) {
337
+ return path;
338
+ }
339
+ var yOffset = 0;
340
+ var currentDelta = yTextToInsertDelta(yParent);
341
+ try {
342
+ for (var currentDelta_1 = __values(currentDelta), currentDelta_1_1 = currentDelta_1.next(); !currentDelta_1_1.done; currentDelta_1_1 = currentDelta_1.next()) {
343
+ var element = currentDelta_1_1.value;
344
+ if (element.insert === yChild) {
345
+ break;
346
+ }
347
+ yOffset += typeof element.insert === 'string' ? element.insert.length : 1;
348
+ }
349
+ }
350
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
351
+ finally {
352
+ try {
353
+ if (currentDelta_1_1 && !currentDelta_1_1.done && (_a = currentDelta_1.return)) _a.call(currentDelta_1);
354
+ }
355
+ finally { if (e_1) throw e_1.error; }
356
+ }
357
+ if (Text.isText(slateParent)) {
358
+ throw new Error('Cannot descent into slate text');
359
+ }
360
+ var _b = __read(yOffsetToSlateOffsets(slateParent, yOffset), 1), pathOffset = _b[0];
361
+ slateParent = slateParent.children[pathOffset];
362
+ return path.concat(pathOffset);
363
+ }, []);
364
+ }
365
+
366
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
367
+ function assertDocumentAttachment(sharedType) {
368
+ if (!sharedType.doc) {
369
+ throw new Error("shared type isn't attached to a document");
370
+ }
371
+ }
372
+
373
+ var STORED_POSITION_PREFIX = '__slateYjsStoredPosition_';
374
+ function slatePointToRelativePosition(sharedRoot, slateRoot, point) {
375
+ var _a = getYTarget(sharedRoot, slateRoot, point.path), yTarget = _a.yTarget, yParent = _a.yParent, textRange = _a.textRange;
376
+ if (yTarget) {
377
+ throw new Error('Slate point points to a non-text element inside sharedRoot');
378
+ }
379
+ var index = textRange.start + point.offset;
380
+ return Y.createRelativePositionFromTypeIndex(yParent, index, index === textRange.end ? -1 : 0);
381
+ }
382
+ function absolutePositionToSlatePoint(sharedRoot, slateRoot, _a) {
383
+ var type = _a.type, index = _a.index, assoc = _a.assoc;
384
+ if (!(type instanceof Y.XmlText)) {
385
+ throw new Error('Absolute position points to a non-XMLText');
386
+ }
387
+ var parentPath = getSlatePath(sharedRoot, slateRoot, type);
388
+ var parent = Node.get(slateRoot, parentPath);
389
+ if (Text.isText(parent) || !Element.isElement(parent)) {
390
+ throw new Error("Absolute position doesn't match slateRoot, cannot descent into text and EditorRoot");
391
+ }
392
+ var _b = __read(yOffsetToSlateOffsets(parent, index, {
393
+ assoc: assoc,
394
+ }), 2), pathOffset = _b[0], textOffset = _b[1];
395
+ var target = parent.children[pathOffset];
396
+ if (!Text.isText(target)) {
397
+ return null;
398
+ }
399
+ return { path: __spreadArray(__spreadArray([], __read(parentPath), false), [pathOffset], false), offset: textOffset };
400
+ }
401
+ function relativePositionToSlatePoint(sharedRoot, slateRoot, pos) {
402
+ if (!sharedRoot.doc) {
403
+ throw new Error("sharedRoot isn't attach to a yDoc");
404
+ }
405
+ var absPos = Y.createAbsolutePositionFromRelativePosition(pos, sharedRoot.doc);
406
+ return absPos && absolutePositionToSlatePoint(sharedRoot, slateRoot, absPos);
407
+ }
408
+ function getStoredPosition(sharedRoot, key) {
409
+ var rawPosition = sharedRoot.getAttribute(STORED_POSITION_PREFIX + key);
410
+ if (!rawPosition) {
411
+ return null;
412
+ }
413
+ return Y.decodeRelativePosition(rawPosition);
414
+ }
415
+ function getStoredPositions(sharedRoot) {
416
+ return Object.fromEntries(Object.entries(sharedRoot.getAttributes())
417
+ .filter(function (_a) {
418
+ var _b = __read(_a, 1), key = _b[0];
419
+ return key.startsWith(STORED_POSITION_PREFIX);
420
+ })
421
+ .map(function (_a) {
422
+ var _b = __read(_a, 2), key = _b[0], position = _b[1];
423
+ return [
424
+ key.slice(STORED_POSITION_PREFIX.length),
425
+ Y.createRelativePositionFromJSON(position),
426
+ ];
427
+ }));
428
+ }
429
+ function getStoredPositionsAbsolute(sharedRoot) {
430
+ assertDocumentAttachment(sharedRoot);
431
+ return Object.fromEntries(Object.entries(sharedRoot.getAttributes())
432
+ .filter(function (_a) {
433
+ var _b = __read(_a, 1), key = _b[0];
434
+ return key.startsWith(STORED_POSITION_PREFIX);
435
+ })
436
+ .map(function (_a) {
437
+ var _b = __read(_a, 2), key = _b[0], position = _b[1];
438
+ return [
439
+ key.slice(STORED_POSITION_PREFIX.length),
440
+ Y.createAbsolutePositionFromRelativePosition(Y.decodeRelativePosition(position), sharedRoot.doc),
441
+ ];
442
+ })
443
+ .filter(function (_a) {
444
+ var _b = __read(_a, 2), position = _b[1];
445
+ return position;
446
+ }));
447
+ }
448
+ function removeStoredPosition(sharedRoot, key) {
449
+ sharedRoot.removeAttribute(STORED_POSITION_PREFIX + key);
450
+ }
451
+ function setStoredPosition(sharedRoot, key, position) {
452
+ sharedRoot.setAttribute(STORED_POSITION_PREFIX + key, Y.encodeRelativePosition(position));
453
+ }
454
+ function getAbsolutePositionsInTextRange(absolutePositions, yTarget, textRange) {
455
+ return Object.fromEntries(Object.entries(absolutePositions).filter(function (_a) {
456
+ var _b = __read(_a, 2), position = _b[1];
457
+ if (position.type !== yTarget) {
458
+ return false;
459
+ }
460
+ if (!textRange) {
461
+ return true;
462
+ }
463
+ return position.assoc >= 0
464
+ ? position.index >= textRange.start && position.index < textRange.end
465
+ : position.index > textRange.start && position.index >= textRange.end;
466
+ }));
467
+ }
468
+ function getAbsolutePositionsInYText(absolutePositions, yText, parentPath) {
469
+ var _a;
470
+ if (parentPath === void 0) { parentPath = ''; }
471
+ var positions = (_a = {},
472
+ _a[parentPath] = getAbsolutePositionsInTextRange(absolutePositions, yText),
473
+ _a);
474
+ var insertDelta = yTextToInsertDelta(yText);
475
+ insertDelta.forEach(function (_a, i) {
476
+ var insert = _a.insert;
477
+ if (insert instanceof Y.XmlText) {
478
+ Object.assign(positions, getAbsolutePositionsInYText(absolutePositions, insert, parentPath ? "".concat(parentPath, ".").concat(i) : i.toString()));
479
+ }
480
+ });
481
+ return positions;
482
+ }
483
+ function getStoredPositionsInDeltaAbsolute(sharedRoot, yText, delta, deltaOffset) {
484
+ if (deltaOffset === void 0) { deltaOffset = 0; }
485
+ var absolutePositions = getStoredPositionsAbsolute(sharedRoot);
486
+ var positions = {
487
+ '': getAbsolutePositionsInTextRange(absolutePositions, yText, {
488
+ start: deltaOffset,
489
+ end: deltaOffset + getInsertDeltaLength(delta),
490
+ }),
491
+ };
492
+ delta.forEach(function (_a, i) {
493
+ var insert = _a.insert;
494
+ if (insert instanceof Y.XmlText) {
495
+ Object.assign(positions, getAbsolutePositionsInYText(absolutePositions, insert, i.toString()));
496
+ }
497
+ });
498
+ return positions;
499
+ }
500
+ function restoreStoredPositionsWithDeltaAbsolute(sharedRoot, yText, absolutePositions, delta, newDeltaOffset, previousDeltaOffset, path) {
501
+ if (newDeltaOffset === void 0) { newDeltaOffset = 0; }
502
+ if (previousDeltaOffset === void 0) { previousDeltaOffset = 0; }
503
+ if (path === void 0) { path = ''; }
504
+ var toRestore = absolutePositions[path];
505
+ if (toRestore) {
506
+ Object.entries(toRestore).forEach(function (_a) {
507
+ var _b = __read(_a, 2), key = _b[0], position = _b[1];
508
+ setStoredPosition(sharedRoot, key, Y.createRelativePositionFromTypeIndex(yText, position.index - previousDeltaOffset + newDeltaOffset, position.assoc));
509
+ });
510
+ }
511
+ delta.forEach(function (_a, i) {
512
+ var insert = _a.insert;
513
+ if (insert instanceof Y.XmlText) {
514
+ restoreStoredPositionsWithDeltaAbsolute(sharedRoot, insert, absolutePositions, yTextToInsertDelta(insert), 0, 0, path ? "".concat(path, ".").concat(i) : i.toString());
515
+ }
516
+ });
517
+ }
518
+ function slateRangeToRelativeRange(sharedRoot, slateRoot, range) {
519
+ return {
520
+ anchor: slatePointToRelativePosition(sharedRoot, slateRoot, range.anchor),
521
+ focus: slatePointToRelativePosition(sharedRoot, slateRoot, range.focus),
522
+ };
523
+ }
524
+ function relativeRangeToSlateRange(sharedRoot, slateRoot, range) {
525
+ var anchor = relativePositionToSlatePoint(sharedRoot, slateRoot, range.anchor);
526
+ if (!anchor) {
527
+ return null;
528
+ }
529
+ var focus = relativePositionToSlatePoint(sharedRoot, slateRoot, range.focus);
530
+ if (!focus) {
531
+ return null;
532
+ }
533
+ return { anchor: anchor, focus: focus };
534
+ }
535
+
536
+ function getProperties(node) {
537
+ return omit(node, (Text.isText(node) ? 'text' : 'children'));
538
+ }
539
+
540
+ function yTextToSlateElement(yText) {
541
+ var delta = yTextToInsertDelta(yText);
542
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
543
+ var children = delta.length > 0 ? delta.map(deltaInsertToSlateNode) : [{ text: '' }];
544
+ // @ts-ignore
545
+ return __assign(__assign({}, yText.getAttributes()), { children: children });
546
+ }
547
+ function deltaInsertToSlateNode(insert) {
548
+ if (typeof insert.insert === 'string') {
549
+ return __assign(__assign({}, insert.attributes), { text: insert.insert });
550
+ }
551
+ return yTextToSlateElement(insert.insert);
552
+ }
553
+ function slateNodesToInsertDelta(nodes) {
554
+ return nodes.map(function (node) {
555
+ if (Text.isText(node)) {
556
+ return { insert: node.text, attributes: getProperties(node) };
557
+ }
558
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
559
+ return { insert: slateElementToYText(node) };
560
+ });
561
+ }
562
+ function slateElementToYText(_a) {
563
+ var children = _a.children, attributes = __rest(_a, ["children"]);
564
+ var yElement = new Y.XmlText();
565
+ Object.entries(attributes).forEach(function (_a) {
566
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
567
+ yElement.setAttribute(key, value);
568
+ });
569
+ yElement.applyDelta(slateNodesToInsertDelta(children), { sanitize: false });
570
+ return yElement;
571
+ }
572
+
573
+ function applyDelta(node, slatePath, delta) {
574
+ var ops = [];
575
+ var yOffset = delta.reduce(function (length, change) {
576
+ if ('retain' in change) {
577
+ return length + change.retain;
578
+ }
579
+ if ('delete' in change) {
580
+ return length + change.delete;
581
+ }
582
+ return length;
583
+ }, 0);
584
+ // Apply changes in reverse order to avoid path changes.
585
+ delta.reverse().forEach(function (change) {
586
+ var _a;
587
+ if ('attributes' in change && 'retain' in change) {
588
+ var _b = __read(yOffsetToSlateOffsets(node, yOffset - change.retain), 2), startPathOffset = _b[0], startTextOffset = _b[1];
589
+ var _c = __read(yOffsetToSlateOffsets(node, yOffset, { assoc: -1 }), 2), endPathOffset = _c[0], endTextOffset = _c[1];
590
+ for (var pathOffset = endPathOffset; pathOffset >= startPathOffset; pathOffset -= 1) {
591
+ var child = node.children[pathOffset];
592
+ var childPath = __spreadArray(__spreadArray([], __read(slatePath), false), [pathOffset], false);
593
+ if (!Text.isText(child)) {
594
+ // Ignore attribute updates on non-text nodes (which are backed by Y.XmlText)
595
+ // to be consistent with deltaInsertToSlateNode. Y.XmlText attributes don't show
596
+ // up in deltas but in key changes (YEvent.changes.keys).
597
+ continue;
598
+ }
599
+ var newProperties = change.attributes;
600
+ var properties = pick.apply(void 0, __spreadArray([node], __read(Object.keys(change.attributes)), false));
601
+ if (pathOffset === startPathOffset || pathOffset === endPathOffset) {
602
+ var start = pathOffset === startPathOffset ? startTextOffset : 0;
603
+ var end = pathOffset === endPathOffset ? endTextOffset : child.text.length;
604
+ if (end !== child.text.length) {
605
+ ops.push({
606
+ type: 'split_node',
607
+ path: childPath,
608
+ position: end,
609
+ properties: getProperties(child),
610
+ });
611
+ }
612
+ if (start !== 0) {
613
+ ops.push({
614
+ type: 'split_node',
615
+ path: childPath,
616
+ position: start,
617
+ properties: omitNullEntries(__assign(__assign({}, getProperties(child)), newProperties)),
618
+ });
619
+ continue;
620
+ }
621
+ }
622
+ ops.push({
623
+ type: 'set_node',
624
+ newProperties: newProperties,
625
+ path: childPath,
626
+ properties: properties,
627
+ });
628
+ }
629
+ }
630
+ if ('retain' in change) {
631
+ yOffset -= change.retain;
632
+ }
633
+ if ('delete' in change) {
634
+ var _d = __read(yOffsetToSlateOffsets(node, yOffset - change.delete), 2), startPathOffset = _d[0], startTextOffset = _d[1];
635
+ var _e = __read(yOffsetToSlateOffsets(node, yOffset, { assoc: -1 }), 2), endPathOffset = _e[0], endTextOffset = _e[1];
636
+ for (var pathOffset = endTextOffset === 0 ? endPathOffset - 1 : endPathOffset; pathOffset >= startPathOffset; pathOffset -= 1) {
637
+ var child = node.children[pathOffset];
638
+ var childPath = __spreadArray(__spreadArray([], __read(slatePath), false), [pathOffset], false);
639
+ if (Text.isText(child)
640
+ && (pathOffset === startPathOffset || pathOffset === endPathOffset)) {
641
+ var start = pathOffset === startPathOffset ? startTextOffset : 0;
642
+ var end = pathOffset === endPathOffset ? endTextOffset : child.text.length;
643
+ ops.push({
644
+ type: 'remove_text',
645
+ offset: start,
646
+ text: child.text.slice(start, end),
647
+ path: childPath,
648
+ });
649
+ yOffset -= end - start;
650
+ continue;
651
+ }
652
+ ops.push({
653
+ type: 'remove_node',
654
+ node: child,
655
+ path: childPath,
656
+ });
657
+ yOffset -= getSlateNodeYLength(child);
658
+ }
659
+ return;
660
+ }
661
+ if ('insert' in change) {
662
+ var _f = __read(yOffsetToSlateOffsets(node, yOffset, {
663
+ insert: true,
664
+ }), 2), pathOffset = _f[0], textOffset = _f[1];
665
+ var child = node.children[pathOffset];
666
+ var childPath = __spreadArray(__spreadArray([], __read(slatePath), false), [pathOffset], false);
667
+ if (Text.isText(child)) {
668
+ var lastOp = ops[ops.length - 1];
669
+ /**
670
+ * The props that exist at the current path
671
+ * Since we're not actually using slate to update the node
672
+ * this is a simulation
673
+ */
674
+ var currentProps = lastOp != null && lastOp.type === 'insert_node' ? lastOp.node : getProperties(child);
675
+ var lastPath = [];
676
+ if (lastOp != null
677
+ && (lastOp.type === 'insert_node'
678
+ || lastOp.type === 'insert_text'
679
+ || lastOp.type === 'split_node'
680
+ || lastOp.type === 'set_node')) {
681
+ lastPath = lastOp.path;
682
+ }
683
+ /**
684
+ * If the insert is a string and the attributes are the same as the
685
+ * props at the current path, we can just insert a text node
686
+ */
687
+ if (typeof change.insert === 'string'
688
+ && deepEquals((_a = change.attributes) !== null && _a !== void 0 ? _a : {}, currentProps)
689
+ && Path.equals(childPath, lastPath)) {
690
+ return ops.push({
691
+ type: 'insert_text',
692
+ offset: textOffset,
693
+ text: change.insert,
694
+ path: childPath,
695
+ });
696
+ }
697
+ var toInsert = deltaInsertToSlateNode(change);
698
+ if (textOffset === 0) {
699
+ return ops.push({
700
+ type: 'insert_node',
701
+ path: childPath,
702
+ node: toInsert,
703
+ });
704
+ }
705
+ return ops.push({
706
+ type: 'insert_node',
707
+ path: Path.next(childPath),
708
+ node: toInsert,
709
+ });
710
+ }
711
+ return ops.push({
712
+ type: 'insert_node',
713
+ path: childPath,
714
+ node: deltaInsertToSlateNode(change),
715
+ });
716
+ }
717
+ });
718
+ return ops;
719
+ }
720
+ function translateYTextEvent(sharedRoot, editor, event) {
721
+ var target = event.target, changes = event.changes;
722
+ var delta = event.delta;
723
+ if (!(target instanceof Y.XmlText)) {
724
+ throw new Error('Unexpected target node type');
725
+ }
726
+ var ops = [];
727
+ var slatePath = getSlatePath(sharedRoot, editor, target);
728
+ var targetElement = Node.get(editor, slatePath);
729
+ if (Text.isText(targetElement)) {
730
+ throw new Error('Cannot apply yTextEvent to text node');
731
+ }
732
+ var keyChanges = Array.from(changes.keys.entries());
733
+ if (slatePath.length > 0 && keyChanges.length > 0) {
734
+ var newProperties = Object.fromEntries(keyChanges.map(function (_a) {
735
+ var _b = __read(_a, 2), key = _b[0], info = _b[1];
736
+ return [
737
+ key,
738
+ info.action === 'delete' ? null : target.getAttribute(key),
739
+ ];
740
+ }));
741
+ var properties = Object.fromEntries(keyChanges.map(function (_a) {
742
+ var _b = __read(_a, 1), key = _b[0];
743
+ return [key, targetElement[key]];
744
+ }));
745
+ ops.push({
746
+ type: 'set_node',
747
+ newProperties: newProperties,
748
+ properties: properties,
749
+ path: slatePath,
750
+ });
751
+ }
752
+ if (delta.length > 0) {
753
+ ops.push.apply(ops, __spreadArray([], __read(applyDelta(targetElement, slatePath, delta)), false));
754
+ }
755
+ return ops;
756
+ }
757
+
758
+ /**
759
+ * Translate a yjs event into slate operations. The editor state has to match the
760
+ * yText state before the event occurred.
761
+ *
762
+ * @param sharedType
763
+ * @param op
764
+ */
765
+ function translateYjsEvent(sharedRoot, editor, event) {
766
+ if (event instanceof Y.YTextEvent) {
767
+ return translateYTextEvent(sharedRoot, editor, event);
768
+ }
769
+ throw new Error('Unexpected Y event type');
770
+ }
771
+ /**
772
+ * Translates yjs events into slate operations and applies them to the editor. The
773
+ * editor state has to match the yText state before the events occurred.
774
+ *
775
+ * @param sharedRoot
776
+ * @param editor
777
+ * @param events
778
+ */
779
+ function applyYjsEvents(sharedRoot, editor, events) {
780
+ Editor.withoutNormalizing(editor, function () {
781
+ events.forEach(function (event) {
782
+ translateYjsEvent(sharedRoot, editor, event).forEach(function (op) {
783
+ editor.apply(op);
784
+ });
785
+ });
786
+ });
787
+ }
788
+
789
+ function insertNode(sharedRoot, slateRoot, op) {
790
+ var _a = getYTarget(sharedRoot, slateRoot, op.path), yParent = _a.yParent, textRange = _a.textRange;
791
+ if (Text.isText(op.node)) {
792
+ return yParent.insert(textRange.start, op.node.text, getProperties(op.node));
793
+ }
794
+ yParent.insertEmbed(textRange.start, slateElementToYText(op.node));
795
+ }
796
+
797
+ function cloneInsertDeltaDeep(delta) {
798
+ return delta.map(function (element) {
799
+ if (typeof element.insert === 'string') {
800
+ return element;
801
+ }
802
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
803
+ return __assign(__assign({}, element), { insert: cloneDeep(element.insert) });
804
+ });
805
+ }
806
+ function cloneDeep(yText) {
807
+ var clone = new Y.XmlText();
808
+ var attributes = yText.getAttributes();
809
+ Object.entries(attributes).forEach(function (_a) {
810
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
811
+ clone.setAttribute(key, value);
812
+ });
813
+ clone.applyDelta(cloneInsertDeltaDeep(yTextToInsertDelta(yText)), {
814
+ sanitize: false,
815
+ });
816
+ return clone;
817
+ }
818
+
819
+ function mergeNode(sharedRoot, slateRoot, op) {
820
+ var target = getYTarget(sharedRoot, slateRoot, op.path);
821
+ var prev = getYTarget(target.yParent, target.slateParent, Path.previous(op.path.slice(-1)));
822
+ if (!target.yTarget !== !prev.yTarget) {
823
+ throw new Error('Cannot merge y text with y element');
824
+ }
825
+ if (!prev.yTarget || !target.yTarget) {
826
+ var parent_1 = target.yParent, textRange = target.textRange, slateTarget = target.slateTarget;
827
+ if (!slateTarget) {
828
+ throw new Error('Expected Slate target node for merge op.');
829
+ }
830
+ var prevSibling = Node.get(slateRoot, Path.previous(op.path));
831
+ if (!Text.isText(prevSibling)) {
832
+ throw new Error('Path points to Y.Text but not a Slate text node.');
833
+ }
834
+ var targetProps = getProperties(slateTarget);
835
+ var prevSiblingProps_1 = getProperties(prevSibling);
836
+ var unsetProps = Object.keys(targetProps).reduce(function (acc, key) {
837
+ var _a;
838
+ var prevSiblingHasProp = key in prevSiblingProps_1;
839
+ return prevSiblingHasProp ? acc : __assign(__assign({}, acc), (_a = {}, _a[key] = null, _a));
840
+ }, {});
841
+ return parent_1.format(textRange.start, textRange.end - textRange.start, __assign(__assign({}, unsetProps), prevSiblingProps_1));
842
+ }
843
+ var deltaApplyYOffset = prev.yTarget.length;
844
+ var targetDelta = yTextToInsertDelta(target.yTarget);
845
+ var clonedDelta = cloneInsertDeltaDeep(targetDelta);
846
+ var storedPositions = getStoredPositionsInDeltaAbsolute(sharedRoot, target.yTarget, targetDelta, deltaApplyYOffset);
847
+ var applyDelta = __spreadArray([{ retain: deltaApplyYOffset }], __read(clonedDelta), false);
848
+ prev.yTarget.applyDelta(applyDelta, {
849
+ sanitize: false,
850
+ });
851
+ target.yParent.delete(target.textRange.start, target.textRange.end - target.textRange.start);
852
+ restoreStoredPositionsWithDeltaAbsolute(sharedRoot, prev.yTarget, storedPositions, clonedDelta, deltaApplyYOffset);
853
+ }
854
+
855
+ function moveNode(sharedRoot, slateRoot, op) {
856
+ var newParentPath = Path.parent(op.newPath);
857
+ var newPathOffset = op.newPath[op.newPath.length - 1];
858
+ var parent = Node.get(slateRoot, newParentPath);
859
+ if (Text.isText(parent)) {
860
+ throw new Error('Cannot move slate node into text element');
861
+ }
862
+ var normalizedNewPath = __spreadArray(__spreadArray([], __read(newParentPath), false), [Math.min(newPathOffset, parent.children.length)], false);
863
+ var origin = getYTarget(sharedRoot, slateRoot, op.path);
864
+ var target = getYTarget(sharedRoot, slateRoot, normalizedNewPath);
865
+ var insertDelta = cloneInsertDeltaDeep(origin.targetDelta);
866
+ var storedPositions = getStoredPositionsInDeltaAbsolute(sharedRoot, origin.yParent, origin.targetDelta);
867
+ origin.yParent.delete(origin.textRange.start, origin.textRange.end - origin.textRange.start);
868
+ var targetLength = getInsertDeltaLength(yTextToInsertDelta(target.yParent));
869
+ var deltaApplyYOffset = Math.min(target.textRange.start, targetLength);
870
+ var applyDelta = __spreadArray([{ retain: deltaApplyYOffset }], __read(insertDelta), false);
871
+ target.yParent.applyDelta(applyDelta, { sanitize: false });
872
+ restoreStoredPositionsWithDeltaAbsolute(sharedRoot, target.yParent, storedPositions, insertDelta, deltaApplyYOffset, origin.textRange.start);
873
+ }
874
+
875
+ function removeNode(sharedRoot, slateRoot, op) {
876
+ var _a = getYTarget(sharedRoot, slateRoot, op.path), parent = _a.yParent, textRange = _a.textRange;
877
+ parent.delete(textRange.start, textRange.end - textRange.start);
878
+ }
879
+
880
+ function setNode(sharedRoot, slateRoot, op) {
881
+ var _a = getYTarget(sharedRoot, slateRoot, op.path), yTarget = _a.yTarget, textRange = _a.textRange, yParent = _a.yParent;
882
+ if (yTarget) {
883
+ Object.entries(op.newProperties).forEach(function (_a) {
884
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
885
+ if (value === null) {
886
+ return yTarget.removeAttribute(key);
887
+ }
888
+ yTarget.setAttribute(key, value);
889
+ });
890
+ return Object.entries(op.properties).forEach(function (_a) {
891
+ var _b = __read(_a, 1), key = _b[0];
892
+ if (!Object.prototype.hasOwnProperty.call(op.newProperties, key)) {
893
+ yTarget.removeAttribute(key);
894
+ }
895
+ });
896
+ }
897
+ var unset = Object.fromEntries(Object.keys(op.properties).map(function (key) { return [key, null]; }));
898
+ var newProperties = __assign(__assign({}, unset), op.newProperties);
899
+ yParent.format(textRange.start, textRange.end - textRange.start, newProperties);
900
+ }
901
+
902
+ function splitNode(sharedRoot, slateRoot, op) {
903
+ var target = getYTarget(sharedRoot, slateRoot, op.path);
904
+ if (!target.slateTarget) {
905
+ throw new Error('Y target without corresponding slate node');
906
+ }
907
+ if (!target.yTarget) {
908
+ if (!Text.isText(target.slateTarget)) {
909
+ throw new Error('Mismatch node type between y target and slate node');
910
+ }
911
+ var unset_1 = {};
912
+ target.targetDelta.forEach(function (element) {
913
+ if (element.attributes) {
914
+ Object.keys(element.attributes).forEach(function (key) {
915
+ unset_1[key] = null;
916
+ });
917
+ }
918
+ });
919
+ return target.yParent.format(target.textRange.start, target.textRange.end - target.textRange.start, __assign(__assign({}, unset_1), op.properties));
920
+ }
921
+ if (Text.isText(target.slateTarget)) {
922
+ throw new Error('Mismatch node type between y target and slate node');
923
+ }
924
+ var splitTarget = getYTarget(target.yTarget, target.slateTarget, [op.position]);
925
+ var ySplitOffset = target.slateTarget.children
926
+ .slice(0, op.position)
927
+ .reduce(function (length, child) { return length + getSlateNodeYLength(child); }, 0);
928
+ // @ts-ignore
929
+ var length = target.slateTarget.children.reduce(function (current, child) { return current + getSlateNodeYLength(child); }, 0);
930
+ var splitDelta = sliceInsertDelta(yTextToInsertDelta(target.yTarget), ySplitOffset, length - ySplitOffset);
931
+ var clonedDelta = cloneInsertDeltaDeep(splitDelta);
932
+ var storedPositions = getStoredPositionsInDeltaAbsolute(sharedRoot, target.yTarget, splitDelta, ySplitOffset);
933
+ var toInsert = new Y.XmlText();
934
+ toInsert.applyDelta(clonedDelta, {
935
+ sanitize: false,
936
+ });
937
+ Object.entries(op.properties).forEach(function (_a) {
938
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
939
+ toInsert.setAttribute(key, value);
940
+ });
941
+ target.yTarget.delete(splitTarget.textRange.start, target.yTarget.length - splitTarget.textRange.start);
942
+ target.yParent.insertEmbed(target.textRange.end, toInsert);
943
+ restoreStoredPositionsWithDeltaAbsolute(sharedRoot, toInsert, storedPositions, clonedDelta, 0, ySplitOffset);
944
+ }
945
+
946
+ var NODE_MAPPER = {
947
+ insert_node: insertNode,
948
+ remove_node: removeNode,
949
+ set_node: setNode,
950
+ merge_node: mergeNode,
951
+ move_node: moveNode,
952
+ split_node: splitNode,
953
+ };
954
+
955
+ function insertText(sharedRoot, slateRoot, op) {
956
+ var _a = getYTarget(sharedRoot, slateRoot, op.path), target = _a.yParent, textRange = _a.textRange;
957
+ var targetNode = Node.get(slateRoot, op.path);
958
+ if (!Text.isText(targetNode)) {
959
+ throw new Error('Cannot insert text into non-text node');
960
+ }
961
+ target.insert(textRange.start + op.offset, op.text, getProperties(targetNode));
962
+ }
963
+
964
+ function removeText(sharedRoot, slateRoot, op) {
965
+ var _a = getYTarget(sharedRoot, slateRoot, op.path), target = _a.yParent, textRange = _a.textRange;
966
+ target.delete(textRange.start + op.offset, op.text.length);
967
+ }
968
+
969
+ var TEXT_MAPPER = {
970
+ insert_text: insertText,
971
+ remove_text: removeText,
972
+ };
973
+
974
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
975
+ var NOOP = function () { };
976
+ var opMappers = __assign(__assign(__assign({}, TEXT_MAPPER), NODE_MAPPER), { set_selection: NOOP });
977
+ function applySlateOp(sharedRoot, slateRoot, op) {
978
+ var apply = opMappers[op.type];
979
+ if (!apply) {
980
+ throw new Error("Unknown operation: ".concat(op.type));
981
+ }
982
+ apply(sharedRoot, slateRoot, op);
983
+ }
984
+
985
+ var DEFAULT_LOCAL_ORIGIN = Symbol('slate-yjs-operation');
986
+ var DEFAULT_POSITION_STORAGE_ORIGIN = Symbol('slate-yjs-position-storage');
987
+ var ORIGIN = new WeakMap();
988
+ var LOCAL_CHANGES = new WeakMap();
989
+ var CONNECTED = new WeakSet();
990
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
991
+ var YjsEditor = {
992
+ isYjsEditor: function (value) {
993
+ return (Editor.isEditor(value)
994
+ && value.sharedRoot instanceof Y.XmlText
995
+ && 'localOrigin' in value
996
+ && 'positionStorageOrigin' in value
997
+ && typeof value.applyRemoteEvents === 'function'
998
+ && typeof value.storeLocalChange === 'function'
999
+ && typeof value.flushLocalChanges === 'function'
1000
+ && typeof value.isLocalOrigin === 'function'
1001
+ && typeof value.connect === 'function'
1002
+ && typeof value.disconnect === 'function');
1003
+ },
1004
+ localChanges: function (editor) {
1005
+ var _a;
1006
+ return (_a = LOCAL_CHANGES.get(editor)) !== null && _a !== void 0 ? _a : [];
1007
+ },
1008
+ applyRemoteEvents: function (editor, events, origin) {
1009
+ editor.applyRemoteEvents(events, origin);
1010
+ },
1011
+ storeLocalChange: function (editor, op) {
1012
+ editor.storeLocalChange(op);
1013
+ },
1014
+ flushLocalChanges: function (editor) {
1015
+ editor.flushLocalChanges();
1016
+ },
1017
+ connected: function (editor) {
1018
+ return CONNECTED.has(editor);
1019
+ },
1020
+ connect: function (editor) {
1021
+ editor.connect();
1022
+ },
1023
+ disconnect: function (editor) {
1024
+ editor.disconnect();
1025
+ },
1026
+ isLocal: function (editor) {
1027
+ return editor.isLocalOrigin(YjsEditor.origin(editor));
1028
+ },
1029
+ origin: function (editor) {
1030
+ var origin = ORIGIN.get(editor);
1031
+ return origin !== undefined ? origin : editor.localOrigin;
1032
+ },
1033
+ withOrigin: function (editor, origin, fn) {
1034
+ var prev = YjsEditor.origin(editor);
1035
+ ORIGIN.set(editor, origin);
1036
+ fn();
1037
+ ORIGIN.set(editor, prev);
1038
+ },
1039
+ storePosition: function (editor, key, point) {
1040
+ var sharedRoot = editor.sharedRoot, locationStorageOrigin = editor.positionStorageOrigin;
1041
+ assertDocumentAttachment(sharedRoot);
1042
+ var position = slatePointToRelativePosition(sharedRoot, editor, point);
1043
+ sharedRoot.doc.transact(function () {
1044
+ setStoredPosition(sharedRoot, key, position);
1045
+ }, locationStorageOrigin);
1046
+ },
1047
+ removeStoredPosition: function (editor, key) {
1048
+ var sharedRoot = editor.sharedRoot, locationStorageOrigin = editor.positionStorageOrigin;
1049
+ assertDocumentAttachment(sharedRoot);
1050
+ sharedRoot.doc.transact(function () {
1051
+ removeStoredPosition(sharedRoot, key);
1052
+ }, locationStorageOrigin);
1053
+ },
1054
+ position: function (editor, key) {
1055
+ var position = getStoredPosition(editor.sharedRoot, key);
1056
+ if (!position) {
1057
+ return undefined;
1058
+ }
1059
+ return relativePositionToSlatePoint(editor.sharedRoot, editor, position);
1060
+ },
1061
+ storedPositionsRelative: function (editor) {
1062
+ return getStoredPositions(editor.sharedRoot);
1063
+ },
1064
+ };
1065
+ function withYjs(sharedRoot, options) {
1066
+ if (options === void 0) { options = {}; }
1067
+ return function (editor) {
1068
+ var _a, _b;
1069
+ var e = editor;
1070
+ e.sharedRoot = sharedRoot;
1071
+ e.localOrigin = (_a = options.localOrigin) !== null && _a !== void 0 ? _a : DEFAULT_LOCAL_ORIGIN;
1072
+ e.positionStorageOrigin = (_b = options.positionStorageOrigin) !== null && _b !== void 0 ? _b : DEFAULT_POSITION_STORAGE_ORIGIN;
1073
+ e.applyRemoteEvents = function (events, origin) {
1074
+ YjsEditor.flushLocalChanges(e);
1075
+ Editor.withoutNormalizing(e, function () {
1076
+ YjsEditor.withOrigin(e, origin, function () {
1077
+ applyYjsEvents(e.sharedRoot, e, events);
1078
+ });
1079
+ });
1080
+ };
1081
+ e.isLocalOrigin = function (origin) { return origin === e.localOrigin; };
1082
+ var handleYEvents = function (events, transaction) {
1083
+ if (e.isLocalOrigin(transaction.origin)) {
1084
+ return;
1085
+ }
1086
+ YjsEditor.applyRemoteEvents(e, events, transaction.origin);
1087
+ };
1088
+ var autoConnectTimeoutId = null;
1089
+ if (options.autoConnect) {
1090
+ autoConnectTimeoutId = setTimeout(function () {
1091
+ autoConnectTimeoutId = null;
1092
+ YjsEditor.connect(e);
1093
+ });
1094
+ }
1095
+ e.connect = function () {
1096
+ if (YjsEditor.connected(e)) {
1097
+ throw new Error('already connected');
1098
+ }
1099
+ e.sharedRoot.observeDeep(handleYEvents);
1100
+ var content = yTextToSlateElement(e.sharedRoot);
1101
+ e.children = content.children;
1102
+ CONNECTED.add(e);
1103
+ Editor.normalize(editor, { force: true });
1104
+ if (!editor.operations.length) {
1105
+ editor.onChange();
1106
+ }
1107
+ };
1108
+ e.disconnect = function () {
1109
+ if (autoConnectTimeoutId) {
1110
+ clearTimeout(autoConnectTimeoutId);
1111
+ }
1112
+ YjsEditor.flushLocalChanges(e);
1113
+ e.sharedRoot.unobserveDeep(handleYEvents);
1114
+ CONNECTED.delete(e);
1115
+ };
1116
+ e.storeLocalChange = function (op) {
1117
+ LOCAL_CHANGES.set(e, __spreadArray(__spreadArray([], __read(YjsEditor.localChanges(e)), false), [
1118
+ { op: op, doc: editor.children, origin: YjsEditor.origin(e) },
1119
+ ], false));
1120
+ };
1121
+ e.flushLocalChanges = function () {
1122
+ assertDocumentAttachment(e.sharedRoot);
1123
+ var localChanges = YjsEditor.localChanges(e);
1124
+ LOCAL_CHANGES.delete(e);
1125
+ var txGroups = [];
1126
+ localChanges.forEach(function (change) {
1127
+ var currentGroup = txGroups[txGroups.length - 1];
1128
+ if (currentGroup && currentGroup[0].origin === change.origin) {
1129
+ return currentGroup.push(change);
1130
+ }
1131
+ txGroups.push([change]);
1132
+ });
1133
+ txGroups.forEach(function (txGroup) {
1134
+ assertDocumentAttachment(e.sharedRoot);
1135
+ e.sharedRoot.doc.transact(function () {
1136
+ txGroup.forEach(function (change) {
1137
+ assertDocumentAttachment(e.sharedRoot);
1138
+ // @ts-ignore
1139
+ applySlateOp(e.sharedRoot, { children: change.doc }, change.op);
1140
+ });
1141
+ }, txGroup[0].origin);
1142
+ });
1143
+ };
1144
+ var apply = e.apply, onChange = e.onChange;
1145
+ e.apply = function (op) {
1146
+ if (YjsEditor.connected(e) && YjsEditor.isLocal(e)) {
1147
+ YjsEditor.storeLocalChange(e, op);
1148
+ }
1149
+ apply(op);
1150
+ };
1151
+ e.onChange = function () {
1152
+ if (YjsEditor.connected(e)) {
1153
+ YjsEditor.flushLocalChanges(e);
1154
+ }
1155
+ onChange();
1156
+ };
1157
+ return e;
1158
+ };
1159
+ }
1160
+
1161
+ var CURSOR_CHANGE_EVENT_LISTENERS = new WeakMap();
1162
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
1163
+ var CursorEditor = {
1164
+ isCursorEditor: function (value) {
1165
+ return (YjsEditor.isYjsEditor(value)
1166
+ && value.awareness
1167
+ && typeof value.cursorDataField === 'string'
1168
+ && typeof value.selectionStateField === 'string'
1169
+ && typeof value.sendCursorPosition === 'function'
1170
+ && typeof value.sendCursorData === 'function');
1171
+ },
1172
+ sendCursorPosition: function (editor, range) {
1173
+ if (range === void 0) { range = editor.selection; }
1174
+ editor.sendCursorPosition(range);
1175
+ },
1176
+ sendCursorData: function (editor, data) {
1177
+ editor.sendCursorData(data);
1178
+ },
1179
+ on: function (editor, event, handler) {
1180
+ var _a;
1181
+ if (event !== 'change') {
1182
+ return;
1183
+ }
1184
+ var listeners = (_a = CURSOR_CHANGE_EVENT_LISTENERS.get(editor)) !== null && _a !== void 0 ? _a : new Set();
1185
+ listeners.add(handler);
1186
+ if (editor) {
1187
+ CURSOR_CHANGE_EVENT_LISTENERS.set(editor, listeners);
1188
+ }
1189
+ },
1190
+ off: function (editor, event, listener) {
1191
+ if (event !== 'change') {
1192
+ return;
1193
+ }
1194
+ var listeners = CURSOR_CHANGE_EVENT_LISTENERS.get(editor);
1195
+ if (listeners) {
1196
+ listeners.delete(listener);
1197
+ }
1198
+ },
1199
+ cursorState: function (editor, clientId) {
1200
+ var _a;
1201
+ if (clientId === editor.awareness.clientID || !YjsEditor.connected(editor)) {
1202
+ return null;
1203
+ }
1204
+ var state = editor.awareness.getStates().get(clientId);
1205
+ if (!state) {
1206
+ return null;
1207
+ }
1208
+ return {
1209
+ relativeSelection: (_a = state[editor.selectionStateField]) !== null && _a !== void 0 ? _a : null,
1210
+ data: state[editor.cursorDataField],
1211
+ clientId: clientId,
1212
+ };
1213
+ },
1214
+ cursorStates: function (editor) {
1215
+ if (!YjsEditor.connected(editor)) {
1216
+ return {};
1217
+ }
1218
+ return Object.fromEntries(Array.from(editor.awareness.getStates().entries(), function (_a) {
1219
+ var _b = __read(_a, 2), id = _b[0], state = _b[1];
1220
+ // Ignore own state
1221
+ if (id === editor.awareness.clientID || !state) {
1222
+ return null;
1223
+ }
1224
+ return [
1225
+ id,
1226
+ {
1227
+ relativeSelection: state[editor.selectionStateField],
1228
+ data: state[editor.cursorDataField],
1229
+ },
1230
+ ];
1231
+ }).filter(Array.isArray));
1232
+ },
1233
+ };
1234
+ function withCursors(awareness, options) {
1235
+ if (options === void 0) { options = {}; }
1236
+ return function (editor) {
1237
+ var _a = options.cursorStateField, selectionStateField = _a === void 0 ? 'selection' : _a, _b = options.cursorDataField, cursorDataField = _b === void 0 ? 'data' : _b, _c = options.autoSend, autoSend = _c === void 0 ? true : _c, data = options.data;
1238
+ var e = editor;
1239
+ e.awareness = awareness;
1240
+ e.cursorDataField = cursorDataField;
1241
+ e.selectionStateField = selectionStateField;
1242
+ e.sendCursorData = function (cursorData) {
1243
+ e.awareness.setLocalStateField(e.cursorDataField, cursorData);
1244
+ };
1245
+ e.sendCursorPosition = function (range) {
1246
+ var localState = e.awareness.getLocalState();
1247
+ var currentRange = localState === null || localState === void 0 ? void 0 : localState[selectionStateField];
1248
+ if (!range) {
1249
+ if (currentRange) {
1250
+ e.awareness.setLocalStateField(e.selectionStateField, null);
1251
+ }
1252
+ return;
1253
+ }
1254
+ var _a = slateRangeToRelativeRange(e.sharedRoot, e, range), anchor = _a.anchor, focus = _a.focus;
1255
+ if (!currentRange
1256
+ || !Y.compareRelativePositions(anchor, currentRange)
1257
+ || !Y.compareRelativePositions(focus, currentRange)) {
1258
+ e.awareness.setLocalStateField(e.selectionStateField, { anchor: anchor, focus: focus });
1259
+ }
1260
+ };
1261
+ var awarenessChangeListener = function (yEvent) {
1262
+ var listeners = CURSOR_CHANGE_EVENT_LISTENERS.get(e);
1263
+ if (!listeners) {
1264
+ return;
1265
+ }
1266
+ var localId = e.awareness.clientID;
1267
+ var event = {
1268
+ added: yEvent.added.filter(function (id) { return id !== localId; }),
1269
+ removed: yEvent.removed.filter(function (id) { return id !== localId; }),
1270
+ updated: yEvent.updated.filter(function (id) { return id !== localId; }),
1271
+ };
1272
+ if (event.added.length > 0 || event.removed.length > 0 || event.updated.length > 0) {
1273
+ listeners.forEach(function (listener) { return listener(event); });
1274
+ }
1275
+ };
1276
+ var connect = e.connect, disconnect = e.disconnect;
1277
+ e.connect = function () {
1278
+ connect();
1279
+ e.awareness.on('change', awarenessChangeListener);
1280
+ awarenessChangeListener({
1281
+ removed: [],
1282
+ added: Array.from(e.awareness.getStates().keys()),
1283
+ updated: [],
1284
+ });
1285
+ if (autoSend) {
1286
+ if (data) {
1287
+ CursorEditor.sendCursorData(e, data);
1288
+ }
1289
+ var onChange_1 = e.onChange;
1290
+ e.onChange = function () {
1291
+ onChange_1();
1292
+ if (YjsEditor.connected(e)) {
1293
+ CursorEditor.sendCursorPosition(e);
1294
+ }
1295
+ };
1296
+ }
1297
+ };
1298
+ e.disconnect = function () {
1299
+ e.awareness.off('change', awarenessChangeListener);
1300
+ awarenessChangeListener({
1301
+ removed: Array.from(e.awareness.getStates().keys()),
1302
+ added: [],
1303
+ updated: [],
1304
+ });
1305
+ disconnect();
1306
+ };
1307
+ return e;
1308
+ };
1309
+ }
1310
+
1311
+ var LAST_SELECTION = new WeakMap();
1312
+ var DEFAULT_WITHOUT_SAVING_ORIGIN = Symbol('slate-yjs-history-without-saving');
1313
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
1314
+ var YHistoryEditor = {
1315
+ isYHistoryEditor: function (value) {
1316
+ return (YjsEditor.isYjsEditor(value)
1317
+ && value.undoManager instanceof Y.UndoManager
1318
+ && typeof value.undo === 'function'
1319
+ && typeof value.redo === 'function'
1320
+ && 'withoutSavingOrigin' in value);
1321
+ },
1322
+ canUndo: function (editor) {
1323
+ return editor.undoManager.undoStack.length > 0;
1324
+ },
1325
+ canRedo: function (editor) {
1326
+ return editor.undoManager.redoStack.length > 0;
1327
+ },
1328
+ isSaving: function (editor) {
1329
+ return editor.undoManager.trackedOrigins.has(YjsEditor.origin(editor));
1330
+ },
1331
+ withoutSaving: function (editor, fn) {
1332
+ YjsEditor.withOrigin(editor, editor.withoutSavingOrigin, fn);
1333
+ },
1334
+ };
1335
+ function withYHistory(options) {
1336
+ if (options === void 0) { options = {}; }
1337
+ return function (editor) {
1338
+ var e = editor;
1339
+ // 将 trackedOrigins 的初始化放到 editor 被传入之后
1340
+ var _a = options.withoutSavingOrigin, withoutSavingOrigin = _a === void 0 ? DEFAULT_WITHOUT_SAVING_ORIGIN : _a, _b = options.trackedOrigins, trackedOrigins = _b === void 0 ? new Set([e.localOrigin]) : _b, restOptions = __rest(options, ["withoutSavingOrigin", "trackedOrigins"]);
1341
+ var undoManager = new Y.UndoManager(e.sharedRoot, __assign({ trackedOrigins: trackedOrigins }, restOptions));
1342
+ e.undoManager = undoManager;
1343
+ e.withoutSavingOrigin = withoutSavingOrigin;
1344
+ var onChange = e.onChange, isLocalOrigin = e.isLocalOrigin;
1345
+ e.onChange = function () {
1346
+ onChange();
1347
+ LAST_SELECTION.set(e, e.selection && slateRangeToRelativeRange(e.sharedRoot, e, e.selection));
1348
+ };
1349
+ e.isLocalOrigin = function (origin) { return origin === e.withoutSavingOrigin || isLocalOrigin(origin); };
1350
+ var handleStackItemAdded = function (_a) {
1351
+ var stackItem = _a.stackItem;
1352
+ stackItem.meta.set('selection', e.selection && slateRangeToRelativeRange(e.sharedRoot, e, e.selection));
1353
+ stackItem.meta.set('selectionBefore', LAST_SELECTION.get(e));
1354
+ };
1355
+ var handleStackItemUpdated = function (_a) {
1356
+ var stackItem = _a.stackItem;
1357
+ stackItem.meta.set('selection', e.selection && slateRangeToRelativeRange(e.sharedRoot, e, e.selection));
1358
+ };
1359
+ var handleStackItemPopped = function (_a) {
1360
+ var stackItem = _a.stackItem, type = _a.type;
1361
+ // TODO: Change once https://github.com/yjs/yjs/issues/353 is resolved
1362
+ var inverseStack = type === 'undo' ? e.undoManager.redoStack : e.undoManager.undoStack;
1363
+ var inverseItem = inverseStack[inverseStack.length - 1];
1364
+ if (inverseItem) {
1365
+ inverseItem.meta.set('selection', stackItem.meta.get('selectionBefore'));
1366
+ inverseItem.meta.set('selectionBefore', stackItem.meta.get('selection'));
1367
+ }
1368
+ var relativeSelection = stackItem.meta.get('selectionBefore');
1369
+ if (!relativeSelection) {
1370
+ return;
1371
+ }
1372
+ var selection = relativeRangeToSlateRange(e.sharedRoot, e, relativeSelection);
1373
+ if (!selection) {
1374
+ return;
1375
+ }
1376
+ Transforms.select(e, selection);
1377
+ };
1378
+ var connect = e.connect, disconnect = e.disconnect;
1379
+ e.connect = function () {
1380
+ connect();
1381
+ e.undoManager.on('stack-item-added', handleStackItemAdded);
1382
+ e.undoManager.on('stack-item-popped', handleStackItemPopped);
1383
+ e.undoManager.on('stack-item-updated', handleStackItemUpdated);
1384
+ };
1385
+ e.disconnect = function () {
1386
+ e.undoManager.off('stack-item-added', handleStackItemAdded);
1387
+ e.undoManager.off('stack-item-popped', handleStackItemPopped);
1388
+ e.undoManager.off('stack-item-updated', handleStackItemUpdated);
1389
+ disconnect();
1390
+ };
1391
+ e.undo = function () {
1392
+ if (YjsEditor.connected(e)) {
1393
+ YjsEditor.flushLocalChanges(e);
1394
+ e.undoManager.undo();
1395
+ }
1396
+ };
1397
+ e.redo = function () {
1398
+ if (YjsEditor.connected(e)) {
1399
+ YjsEditor.flushLocalChanges(e);
1400
+ e.undoManager.redo();
1401
+ }
1402
+ };
1403
+ return e;
1404
+ };
1405
+ }
1406
+
1407
+ export { CursorEditor, YHistoryEditor, YjsEditor, relativePositionToSlatePoint, relativeRangeToSlateRange, slateNodesToInsertDelta, slatePointToRelativePosition, slateRangeToRelativeRange, withCursors, withYHistory, withYjs, yTextToSlateElement };