kritzel-stencil 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/kritzel-color_24.cjs.entry.js +17 -57
- package/dist/collection/classes/core/viewport.class.js +3 -43
- package/dist/collection/collection-manifest.json +1 -1
- package/dist/collection/components/core/kritzel-cursor-trail/kritzel-cursor-trail.js +1 -1
- package/dist/collection/components/core/kritzel-editor/kritzel-editor.js +1 -1
- package/dist/collection/components/shared/kritzel-color/kritzel-color.js +2 -2
- package/dist/collection/components/shared/kritzel-color-palette/kritzel-color-palette.js +1 -1
- package/dist/collection/components/shared/kritzel-font/kritzel-font.js +1 -1
- package/dist/collection/components/shared/kritzel-font-size/kritzel-font-size.js +1 -1
- package/dist/collection/components/shared/kritzel-line-endings/kritzel-line-endings.js +2 -2
- package/dist/collection/components/shared/kritzel-shape-fill/kritzel-shape-fill.js +2 -2
- package/dist/collection/components/ui/kritzel-controls/kritzel-controls.css +4 -4
- package/dist/collection/components/ui/kritzel-controls/kritzel-controls.js +2 -2
- package/dist/components/index.js +1 -1
- package/dist/components/kritzel-color-palette.js +1 -1
- package/dist/components/kritzel-color.js +1 -1
- package/dist/components/kritzel-controls.js +1 -1
- package/dist/components/kritzel-cursor-trail.js +1 -1
- package/dist/components/kritzel-editor.js +1 -1
- package/dist/components/kritzel-engine.js +1 -1
- package/dist/components/kritzel-font-size.js +1 -1
- package/dist/components/kritzel-font.js +1 -1
- package/dist/components/kritzel-line-endings.js +1 -1
- package/dist/components/kritzel-shape-fill.js +1 -1
- package/dist/components/kritzel-stroke-size.js +1 -1
- package/dist/components/kritzel-tool-config.js +1 -1
- package/dist/components/{p-CSGeDE4f.js → p-BlUr7oVq.js} +1 -1
- package/dist/components/{p-BbqT9o1F.js → p-CNneo_RD.js} +1 -1
- package/dist/components/p-CkpOndCn.js +1 -0
- package/dist/components/{p-CyHZWbkS.js → p-CzjSdJio.js} +1 -1
- package/dist/components/{p-D8GeJNUv.js → p-DLijNISu.js} +1 -1
- package/dist/components/{p-B8QjTqOY.js → p-DMJI6opm.js} +1 -1
- package/dist/components/{p-B3P64-gH.js → p-DwJUC6cw.js} +2 -2
- package/dist/components/{p-BF6MdW17.js → p-FOxrXeq4.js} +1 -1
- package/dist/components/{p-CbuHMNa9.js → p-S5GeUsJP.js} +1 -1
- package/dist/components/{p-BnidlyU0.js → p-e1r5dgeP.js} +1 -1
- package/dist/components/{p-ClMFs3KI.js → p-pKbfOI5a.js} +1 -1
- package/dist/esm/kritzel-color_24.entry.js +17 -57
- package/dist/stencil/p-361ebc7e.entry.js +9 -0
- package/dist/stencil/stencil.esm.js +1 -1
- package/dist/types/classes/core/viewport.class.d.ts +0 -6
- package/package.json +1 -1
- package/dist/components/p-8iEiCuEN.js +0 -1
- package/dist/stencil/p-caf30edb.entry.js +0 -9
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{p as t,H as n,c as e,h as r,d as i,t as s}from"./p-BxS4Pdpz.js";import{K as o}from"./p-D8W6LE-c.js";import{j as u,k as c,l as h,m as a,b as l,n as f,o as d,p as v,q as p,g as w,h as y,e as g,f as b,d as m,c as A,r as k,K as x,a as M,i as S}from"./p-DOF5fWDU.js";import{K as C,d as U}from"./p-Cnpk2hfo.js";import{O as E}from"./p-B0kd2rUI.js";import{K as j,d as T}from"./p-DgCGSL2Q.js";import{K as I}from"./p-n789Y3S-.js";import{K as _}from"./p-l10It7Nm.js";import{d as O}from"./p-CSGeDE4f.js";var z="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};class $ extends u{__class__="KritzelImage";src="";maxWidth=300;maxHeight=300;maxCompressionSize=300;isDebugInfoVisible=!0;constructor(t){super(),this.src=t?.src||"",this.x=t?.x||0,this.y=t?.y||0,this.translateX=t?.translateX||0,this.translateY=t?.translateY||0,this.scale=t?.scale||1}static create(t){const n=new $;return n._core=t,n.id=n.generateId(),n.workspaceId=t.store.state.activeWorkspace.id,n.x=0,n.y=0,n.translateX=0,n.translateY=0,n.scale=n._core.store.state.scale,n.zIndex=t.store.currentZIndex,n}resize(t,n,e,r){if(e<=1||r<=1)return;const i=r/this.height;this.width=this.width*i,this.height=this.height*i,this.translateX=t,this.translateY=n,this._core.store.state.objects.update(this)}calculateScaledDimensions(t){let n=t.width,e=t.height;if(t.width>this.maxWidth||t.height>this.maxHeight){const r=Math.min(this.maxWidth/t.width,this.maxHeight/t.height);n=t.width*r,e=t.height*r}return{scaledWidth:n,scaledHeight:e}}}class D extends c{touchStartTimeout=null;constructor(t){super(t)}handlePointerDown(t){"mouse"===t.pointerType&&h.isLeftClick(t)&&(this._core.store.state.isErasing=!0),"touch"===t.pointerType&&(this.touchStartTimeout=setTimeout((()=>{1!==this._core.store.state.pointers.size||this._core.store.state.isScaling||(this._core.store.state.isErasing=!0)}),80))}handlePointerMove(t){if("mouse"===t.pointerType&&this._core.store.state.isErasing){const n=this._core.getObjectsFromPointerEvent(t,".object");if(0===n.length)return;const e=this._core.store.state.pointerX,r=this._core.store.state.pointerY;n.forEach((t=>{t.markedForRemoval=t.hitTest(e,r)})),this._core.rerender()}if("touch"===t.pointerType&&1===this._core.store.state.pointers.size&&this._core.store.state.isErasing){const n=this._core.store.state.host?.shadowRoot;if(!n)return;const e=this._core.getObjectsFromPointerEvent(t,".object");if(0===e.length)return;const r=this._core.store.state.pointerX,i=this._core.store.state.pointerY;e.forEach((t=>{t.markedForRemoval=t.hitTest(r,i)})),this._core.rerender()}}handlePointerUp(t){if("mouse"===t.pointerType&&this._core.store.state.isErasing){const t=this._core.store.allObjects.filter((t=>t.markedForRemoval));t.forEach((t=>{t.markedForRemoval=!1,this._core.removeObject(t)})),t.length>0&&this._core.rerender(),this._core.store.state.isErasing=!1,this._core.engine.emitObjectsChange()}if("touch"===t.pointerType&&(clearTimeout(this.touchStartTimeout),this._core.store.state.isErasing)){const t=this._core.store.allObjects.filter((t=>t.markedForRemoval));t.forEach((t=>{t.markedForRemoval=!1,this._core.removeObject(t)})),t.length>0&&this._core.rerender(),this._core.store.state.isErasing=!1,this._core.engine.emitObjectsChange()}}}function P(t,n){return new Promise((function(e,r){let i;return R(t).then((function(t){try{return i=t,e(new Blob([n.slice(0,2),i,n.slice(2)],{type:"image/jpeg"}))}catch(t){return r(t)}}),r)}))}const R=t=>new Promise(((n,e)=>{const r=new FileReader;r.addEventListener("load",(({target:{result:t}})=>{const r=new DataView(t);let i=0;if(65496!==r.getUint16(i))return e("not a valid JPEG");for(i+=2;;){const s=r.getUint16(i);if(65498===s)break;const o=r.getUint16(i+2);if(65505===s&&1165519206===r.getUint32(i+4)){const s=i+10;let u;switch(r.getUint16(s)){case 18761:u=!0;break;case 19789:u=!1;break;default:return e("TIFF header contains invalid endian")}if(42!==r.getUint16(s+2,u))return e("TIFF header contains invalid version");const c=r.getUint32(s+4,u),h=s+c+2+12*r.getUint16(s+c,u);for(let t=s+c+2;t<h;t+=12)if(274==r.getUint16(t,u)){if(3!==r.getUint16(t+2,u))return e("Orientation data type is invalid");if(1!==r.getUint32(t+4,u))return e("Orientation data count is invalid");r.setUint16(t+8,1,u);break}return n(t.slice(i,i+2+o))}i+=2+o}return n(new Blob)})),r.readAsArrayBuffer(t)}));var B={},W={get exports(){return B},set exports(t){B=t}};!function(){var t,n,e={};W.exports=e,e.parse=function(t,n){for(var r=e.bin.readUshort,i=e.bin.readUint,s=0,o={},u=new Uint8Array(t),c=u.length-4;101010256!=i(u,c);)c--;s=c,s+=4;var h=r(u,s+=4);r(u,s+=2);var a=i(u,s+=2),l=i(u,s+=4);s+=4,s=l;for(var f=0;f<h;f++){i(u,s),s+=4,s+=4,s+=4,i(u,s+=4),a=i(u,s+=4);var d=i(u,s+=4),v=r(u,s+=4),p=r(u,s+2),w=r(u,s+4);s+=6;var y=i(u,s+=8);s+=4,s+=v+p+w,e._readLocal(u,y,o,a,d,n)}return o},e._readLocal=function(t,n,r,i,s,o){var u=e.bin.readUshort,c=e.bin.readUint;c(t,n),u(t,n+=4),u(t,n+=2);var h=u(t,n+=2);c(t,n+=2),c(t,n+=4),n+=4;var a=u(t,n+=8),l=u(t,n+=2),f=e.bin.readUTF8(t,n+=2,a);if(n+=a,n+=l,o)r[f]={size:s,csize:i};else{var d=new Uint8Array(t.buffer,n);if(0==h)r[f]=new Uint8Array(d.buffer.slice(n,n+i));else{if(8!=h)throw"unknown compression method: "+h;var v=new Uint8Array(s);e.inflateRaw(d,v),r[f]=v}}},e.inflateRaw=function(t,n){return e.F.inflate(t,n)},e.inflate=function(t,n){return e.inflateRaw(new Uint8Array(t.buffer,t.byteOffset+2,t.length-6),n)},e.deflate=function(t,n){null==n&&(n={level:6});var r=0,i=new Uint8Array(50+Math.floor(1.1*t.length));i[r]=120,i[r+1]=156,r=e.F.deflateRaw(t,i,r+=2,n.level);var s=e.adler(t,0,t.length);return i[r+0]=s>>>24&255,i[r+1]=s>>>16&255,i[r+2]=s>>>8&255,i[r+3]=s>>>0&255,new Uint8Array(i.buffer,0,r+4)},e.deflateRaw=function(t,n){null==n&&(n={level:6});var r=new Uint8Array(50+Math.floor(1.1*t.length)),i=e.F.deflateRaw(t,r,i,n.level);return new Uint8Array(r.buffer,0,i)},e.encode=function(t,n){null==n&&(n=!1);var r=0,i=e.bin.writeUint,s=e.bin.writeUshort,o={};for(var u in t){var c=!e._noNeed(u)&&!n,h=t[u],a=e.crc.crc(h,0,h.length);o[u]={cpr:c,usize:h.length,crc:a,file:c?e.deflateRaw(h):h}}for(var u in o)r+=o[u].file.length+30+46+2*e.bin.sizeUTF8(u);r+=22;var l=new Uint8Array(r),f=0,d=[];for(var u in o){var v=o[u];d.push(f),f=e._writeHeader(l,f,u,v,0)}var p=0,w=f;for(var u in o)v=o[u],d.push(f),f=e._writeHeader(l,f,u,v,1,d[p++]);var y=f-w;return i(l,f,101010256),f+=4,s(l,f+=4,p),s(l,f+=2,p),i(l,f+=2,y),i(l,f+=4,w),f+=4,f+=2,l.buffer},e._noNeed=function(t){var n=t.split(".").pop().toLowerCase();return-1!="png,jpg,jpeg,zip".indexOf(n)},e._writeHeader=function(t,n,r,i,s,o){var u=e.bin.writeUint,c=e.bin.writeUshort,h=i.file;return u(t,n,0==s?67324752:33639248),n+=4,1==s&&(n+=2),c(t,n,20),c(t,n+=2,0),c(t,n+=2,i.cpr?8:0),u(t,n+=2,0),u(t,n+=4,i.crc),u(t,n+=4,h.length),u(t,n+=4,i.usize),c(t,n+=4,e.bin.sizeUTF8(r)),c(t,n+=2,0),n+=2,1==s&&(n+=2,n+=2,u(t,n+=6,o),n+=4),n+=e.bin.writeUTF8(t,n,r),0==s&&(t.set(h,n),n+=h.length),n},e.crc={table:function(){for(var t=new Uint32Array(256),n=0;n<256;n++){for(var e=n,r=0;r<8;r++)1&e?e=3988292384^e>>>1:e>>>=1;t[n]=e}return t}(),update:function(t,n,r,i){for(var s=0;s<i;s++)t=e.crc.table[255&(t^n[r+s])]^t>>>8;return t},crc:function(t,n,r){return 4294967295^e.crc.update(4294967295,t,n,r)}},e.adler=function(t,n,e){for(var r=1,i=0,s=n,o=n+e;s<o;){for(var u=Math.min(s+5552,o);s<u;)i+=r+=t[s++];r%=65521,i%=65521}return i<<16|r},e.bin={readUshort:function(t,n){return t[n]|t[n+1]<<8},writeUshort:function(t,n,e){t[n]=255&e,t[n+1]=e>>8&255},readUint:function(t,n){return 16777216*t[n+3]+(t[n+2]<<16|t[n+1]<<8|t[n])},writeUint:function(t,n,e){t[n]=255&e,t[n+1]=e>>8&255,t[n+2]=e>>16&255,t[n+3]=e>>24&255},readASCII:function(t,n,e){for(var r="",i=0;i<e;i++)r+=String.fromCharCode(t[n+i]);return r},writeASCII:function(t,n,e){for(var r=0;r<e.length;r++)t[n+r]=e.charCodeAt(r)},pad:function(t){return t.length<2?"0"+t:t},readUTF8:function(t,n,r){for(var i,s="",o=0;o<r;o++)s+="%"+e.bin.pad(t[n+o].toString(16));try{i=decodeURIComponent(s)}catch(i){return e.bin.readASCII(t,n,r)}return i},writeUTF8:function(t,n,e){for(var r=e.length,i=0,s=0;s<r;s++){var o=e.charCodeAt(s);if(4294967168&o)if(4294965248&o)if(4294901760&o){if(4292870144&o)throw"e";t[n+i]=240|o>>18,t[n+i+1]=128|o>>12&63,t[n+i+2]=128|o>>6&63,t[n+i+3]=128|63&o,i+=4}else t[n+i]=224|o>>12,t[n+i+1]=128|o>>6&63,t[n+i+2]=128|63&o,i+=3;else t[n+i]=192|o>>6,t[n+i+1]=128|63&o,i+=2;else t[n+i]=o,i++}return i},sizeUTF8:function(t){for(var n=t.length,e=0,r=0;r<n;r++){var i=t.charCodeAt(r);if(4294967168&i)if(4294965248&i)if(4294901760&i){if(4292870144&i)throw"e";e+=4}else e+=3;else e+=2;else e++}return e}},e.F={},e.F.deflateRaw=function(t,n,r,i){var s=[[0,0,0,0,0],[4,4,8,4,0],[4,5,16,8,0],[4,6,16,16,0],[4,10,16,32,0],[8,16,32,32,0],[8,16,128,128,0],[8,32,128,256,0],[32,128,258,1024,1],[32,258,258,4096,1]][i],o=e.F.U,u=e.F._goodIndex,c=e.F._putsE,h=0,a=r<<3,l=0,f=t.length;if(0==i){for(;h<f;)c(n,a,h+(M=Math.min(65535,f-h))==f?1:0),a=e.F._copyExact(t,h,M,n,a+8),h+=M;return a>>>3}var d=o.lits,v=o.strt,p=o.prev,w=0,y=0,g=0,b=0,m=0,A=0;for(f>2&&(v[A=e.F._hash(t,0)]=0),h=0;h<f;h++){if(m=A,h+1<f-2){A=e.F._hash(t,h+1);var k=h+1&32767;p[k]=v[A],v[A]=k}if(l<=h){(w>14e3||y>26697)&&f-h>100&&(l<h&&(d[w]=h-l,w+=2,l=h),a=e.F._writeBlock(h==f-1||l==f?1:0,d,w,b,t,g,h-g,n,a),w=y=b=0,g=h);var x=0;h<f-2&&(x=e.F._bestMatch(t,h,p,m,Math.min(s[2],f-h),s[3]));var M=x>>>16,S=65535&x;if(0!=x){S=65535&x;var C=u(M=x>>>16,o.of0);o.lhst[257+C]++;var U=u(S,o.df0);o.dhst[U]++,b+=o.exb[C]+o.dxb[U],d[w]=M<<23|h-l,d[w+1]=S<<16|C<<8|U,w+=2,l=h+M}else o.lhst[t[h]]++;y++}}for(g==h&&0!=t.length||(l<h&&(d[w]=h-l,w+=2,l=h),a=e.F._writeBlock(1,d,w,b,t,g,h-g,n,a),w=0,y=0,w=y=b=0,g=h);7&a;)a++;return a>>>3},e.F._bestMatch=function(t,n,r,i,s,o){var u=32767&n,c=r[u],h=u-c+32768&32767;if(c==u||i!=e.F._hash(t,n-h))return 0;for(var a=0,l=0,f=Math.min(32767,n);h<=f&&0!=--o&&c!=u;){if(0==a||t[n+a]==t[n+a-h]){var d=e.F._howLong(t,n,h);if(d>a){if(l=h,(a=d)>=s)break;h+2<d&&(d=h+2);for(var v=0,p=0;p<d-2;p++){var w=n-h+p+32768&32767,y=w-r[w]+32768&32767;y>v&&(v=y,c=w)}}}h+=(u=c)-(c=r[u])+32768&32767}return a<<16|l},e.F._howLong=function(t,n,e){if(t[n]!=t[n-e]||t[n+1]!=t[n+1-e]||t[n+2]!=t[n+2-e])return 0;var r=n,i=Math.min(t.length,n+258);for(n+=3;n<i&&t[n]==t[n-e];)n++;return n-r},e.F._hash=function(t,n){return(t[n]<<8|t[n+1])+(t[n+2]<<4)&65535},e.saved=0,e.F._writeBlock=function(t,n,r,i,s,o,u,c,h){var a,l,f,d,v,p,w,y,g,b=e.F.U,m=e.F._putsF,A=e.F._putsE;b.lhst[256]++,l=(a=e.F.getTrees())[0],f=a[1],d=a[2],v=a[3],p=a[4],w=a[5],y=a[6],g=a[7];var k=32+(h+3&7?8-(h+3&7):0)+(u<<3),x=i+e.F.contSize(b.fltree,b.lhst)+e.F.contSize(b.fdtree,b.dhst),M=i+e.F.contSize(b.ltree,b.lhst)+e.F.contSize(b.dtree,b.dhst);M+=14+3*w+e.F.contSize(b.itree,b.ihst)+(2*b.ihst[16]+3*b.ihst[17]+7*b.ihst[18]);for(var S=0;S<286;S++)b.lhst[S]=0;for(S=0;S<30;S++)b.dhst[S]=0;for(S=0;S<19;S++)b.ihst[S]=0;var C=k<x&&k<M?0:x<M?1:2;if(m(c,h,t),m(c,h+1,C),h+=3,0==C){for(;7&h;)h++;h=e.F._copyExact(s,o,u,c,h)}else{var U,E;if(1==C&&(U=b.fltree,E=b.fdtree),2==C){e.F.makeCodes(b.ltree,l),e.F.revCodes(b.ltree,l),e.F.makeCodes(b.dtree,f),e.F.revCodes(b.dtree,f),e.F.makeCodes(b.itree,d),e.F.revCodes(b.itree,d),U=b.ltree,E=b.dtree,A(c,h,v-257),A(c,h+=5,p-1),A(c,h+=5,w-4),h+=4;for(var j=0;j<w;j++)A(c,h+3*j,b.itree[1+(b.ordr[j]<<1)]);h=e.F._codeTiny(y,b.itree,c,h+=3*w),h=e.F._codeTiny(g,b.itree,c,h)}for(var T=o,I=0;I<r;I+=2){for(var _=n[I],O=_>>>23,z=T+(8388607&_);T<z;)h=e.F._writeLit(s[T++],U,c,h);if(0!=O){var $=n[I+1],D=$>>16,P=$>>8&255,R=255&$;A(c,h=e.F._writeLit(257+P,U,c,h),O-b.of0[P]),m(c,h=e.F._writeLit(R,E,c,h+=b.exb[P]),D-b.df0[R]),h+=b.dxb[R],T+=O}}h=e.F._writeLit(256,U,c,h)}return h},e.F._copyExact=function(t,n,e,r,i){var s=i>>>3;return r[s]=e,r[s+1]=e>>>8,r[s+2]=255-r[s],r[s+3]=255-r[s+1],s+=4,r.set(new Uint8Array(t.buffer,n,e),s),i+(e+4<<3)},e.F.getTrees=function(){for(var t=e.F.U,n=e.F._hufTree(t.lhst,t.ltree,15),r=e.F._hufTree(t.dhst,t.dtree,15),i=[],s=e.F._lenCodes(t.ltree,i),o=[],u=e.F._lenCodes(t.dtree,o),c=0;c<i.length;c+=2)t.ihst[i[c]]++;for(c=0;c<o.length;c+=2)t.ihst[o[c]]++;for(var h=e.F._hufTree(t.ihst,t.itree,7),a=19;a>4&&0==t.itree[1+(t.ordr[a-1]<<1)];)a--;return[n,r,h,s,u,a,i,o]},e.F.getSecond=function(t){for(var n=[],e=0;e<t.length;e+=2)n.push(t[e+1]);return n},e.F.nonZero=function(t){for(var n="",e=0;e<t.length;e+=2)0!=t[e+1]&&(n+=(e>>1)+",");return n},e.F.contSize=function(t,n){for(var e=0,r=0;r<n.length;r++)e+=n[r]*t[1+(r<<1)];return e},e.F._codeTiny=function(t,n,r,i){for(var s=0;s<t.length;s+=2){var o=t[s],u=t[s+1];i=e.F._writeLit(o,n,r,i);var c=16==o?2:17==o?3:7;o>15&&(e.F._putsE(r,i,u,c),i+=c)}return i},e.F._lenCodes=function(t,n){for(var e=t.length;2!=e&&0==t[e-1];)e-=2;for(var r=0;r<e;r+=2){var i=t[r+1],s=r+3<e?t[r+3]:-1,o=r+5<e?t[r+5]:-1,u=0==r?-1:t[r-1];if(0==i&&s==i&&o==i){for(var c=r+5;c+2<e&&t[c+2]==i;)c+=2;(h=Math.min(c+1-r>>>1,138))<11?n.push(17,h-3):n.push(18,h-11),r+=2*h-2}else if(i==u&&s==i&&o==i){for(c=r+5;c+2<e&&t[c+2]==i;)c+=2;var h=Math.min(c+1-r>>>1,6);n.push(16,h-3),r+=2*h-2}else n.push(i,0)}return e>>>1},e.F._hufTree=function(t,n,r){var i=[],s=t.length,o=n.length,u=0;for(u=0;u<o;u+=2)n[u]=0,n[u+1]=0;for(u=0;u<s;u++)0!=t[u]&&i.push({lit:u,f:t[u]});var c=i.length,h=i.slice(0);if(0==c)return 0;if(1==c){var a=i[0].lit;return h=0==a?1:0,n[1+(a<<1)]=1,n[1+(h<<1)]=1,1}i.sort((function(t,n){return t.f-n.f}));var l=i[0],f=i[1],d=0,v=1,p=2;for(i[0]={lit:-1,f:l.f+f.f,l,r:f,d:0};v!=c-1;)l=d!=v&&(p==c||i[d].f<i[p].f)?i[d++]:i[p++],f=d!=v&&(p==c||i[d].f<i[p].f)?i[d++]:i[p++],i[v++]={lit:-1,f:l.f+f.f,l,r:f};var w=e.F.setDepth(i[v-1],0);for(w>r&&(e.F.restrictDepth(h,r,w),w=r),u=0;u<c;u++)n[1+(h[u].lit<<1)]=h[u].d;return w},e.F.setDepth=function(t,n){return-1!=t.lit?(t.d=n,n):Math.max(e.F.setDepth(t.l,n+1),e.F.setDepth(t.r,n+1))},e.F.restrictDepth=function(t,n,e){var r=0,i=1<<e-n,s=0;for(t.sort((function(t,n){return n.d==t.d?t.f-n.f:n.d-t.d})),r=0;r<t.length&&t[r].d>n;r++){var o=t[r].d;t[r].d=n,s+=i-(1<<e-o)}for(s>>>=e-n;s>0;)(o=t[r].d)<n?(t[r].d++,s-=1<<n-o-1):r++;for(;r>=0;r--)t[r].d==n&&s<0&&(t[r].d--,s++);0!=s&&console.log("debt left")},e.F._goodIndex=function(t,n){var e=0;return n[16|e]<=t&&(e|=16),n[8|e]<=t&&(e|=8),n[4|e]<=t&&(e|=4),n[2|e]<=t&&(e|=2),n[1|e]<=t&&(e|=1),e},e.F._writeLit=function(t,n,r,i){return e.F._putsF(r,i,n[t<<1]),i+n[1+(t<<1)]},e.F.inflate=function(t,n){var r=Uint8Array;if(3==t[0]&&0==t[1])return n||new r(0);var i=e.F,s=i._bitsF,o=i._bitsE,u=i._decodeTiny,c=i.makeCodes,h=i.codes2map,a=i._get17,l=i.U,f=null==n;f&&(n=new r(t.length>>>2<<3));for(var d,v,p=0,w=0,y=0,g=0,b=0,m=0,A=0,k=0,x=0;0==p;)if(p=s(t,x,1),w=s(t,x+1,2),x+=3,0!=w){if(f&&(n=e.F._check(n,k+(1<<17))),1==w&&(d=l.flmap,v=l.fdmap,m=511,A=31),2==w){y=o(t,x,5)+257,g=o(t,x+5,5)+1,b=o(t,x+10,4)+4,x+=14;for(var M=0;M<38;M+=2)l.itree[M]=0,l.itree[M+1]=0;var S=1;for(M=0;M<b;M++){var C=o(t,x+3*M,3);l.itree[1+(l.ordr[M]<<1)]=C,C>S&&(S=C)}x+=3*b,c(l.itree,S),h(l.itree,S,l.imap),d=l.lmap,v=l.dmap,x=u(l.imap,(1<<S)-1,y+g,t,x,l.ttree);var U=i._copyOut(l.ttree,0,y,l.ltree);m=(1<<U)-1;var E=i._copyOut(l.ttree,y,g,l.dtree);A=(1<<E)-1,c(l.ltree,U),h(l.ltree,U,d),c(l.dtree,E),h(l.dtree,E,v)}for(;;){var j=d[a(t,x)&m];x+=15&j;var T=j>>>4;if(T>>>8==0)n[k++]=T;else{if(256==T)break;var I=k+T-254;if(T>264){var _=l.ldef[T-257];I=k+(_>>>3)+o(t,x,7&_),x+=7&_}var O=v[a(t,x)&A],z=l.ddef[O>>>4],$=(z>>>4)+s(t,x+=15&O,15&z);for(x+=15&z,f&&(n=e.F._check(n,k+(1<<17)));k<I;)n[k]=n[k++-$],n[k]=n[k++-$],n[k]=n[k++-$],n[k]=n[k++-$];k=I}}}else{7&x&&(x+=8-(7&x));var D=4+(x>>>3),P=t[D-4]|t[D-3]<<8;f&&(n=e.F._check(n,k+P)),n.set(new r(t.buffer,t.byteOffset+D,P),k),x=D+P<<3,k+=P}return n.length==k?n:n.slice(0,k)},e.F._check=function(t,n){var e=t.length;if(n<=e)return t;var r=new Uint8Array(Math.max(e<<1,n));return r.set(t,0),r},e.F._decodeTiny=function(t,n,r,i,s,o){for(var u=e.F._bitsE,c=e.F._get17,h=0;h<r;){var a=t[c(i,s)&n];s+=15&a;var l=a>>>4;if(l<=15)o[h]=l,h++;else{var f=0,d=0;16==l?(d=3+u(i,s,2),s+=2,f=o[h-1]):17==l?(d=3+u(i,s,3),s+=3):18==l&&(d=11+u(i,s,7),s+=7);for(var v=h+d;h<v;)o[h]=f,h++}}return s},e.F._copyOut=function(t,n,e,r){for(var i=0,s=0,o=r.length>>>1;s<e;){var u=t[s+n];r[s<<1]=0,r[1+(s<<1)]=u,u>i&&(i=u),s++}for(;s<o;)r[s<<1]=0,r[1+(s<<1)]=0,s++;return i},e.F.makeCodes=function(t,n){for(var r,i,s,o,u=e.F.U,c=t.length,h=u.bl_count,a=0;a<=n;a++)h[a]=0;for(a=1;a<c;a+=2)h[t[a]]++;var l=u.next_code;for(r=0,h[0]=0,i=1;i<=n;i++)l[i]=r=r+h[i-1]<<1;for(s=0;s<c;s+=2)0!=(o=t[s+1])&&(t[s]=l[o],l[o]++)},e.F.codes2map=function(t,n,r){for(var i=t.length,s=e.F.U.rev15,o=0;o<i;o+=2)if(0!=t[o+1])for(var u=t[o+1],c=o>>1<<4|u,h=n-u,a=t[o]<<h,l=a+(1<<h);a!=l;)r[s[a]>>>15-n]=c,a++},e.F.revCodes=function(t,n){for(var r=e.F.U.rev15,i=15-n,s=0;s<t.length;s+=2)t[s]=r[t[s]<<n-t[s+1]]>>>i},e.F._putsE=function(t,n,e){var r=n>>>3;t[r]|=e<<=7&n,t[r+1]|=e>>>8},e.F._putsF=function(t,n,e){var r=n>>>3;t[r]|=e<<=7&n,t[r+1]|=e>>>8,t[r+2]|=e>>>16},e.F._bitsE=function(t,n,e){return(t[n>>>3]|t[1+(n>>>3)]<<8)>>>(7&n)&(1<<e)-1},e.F._bitsF=function(t,n,e){return(t[n>>>3]|t[1+(n>>>3)]<<8|t[2+(n>>>3)]<<16)>>>(7&n)&(1<<e)-1},e.F._get17=function(t,n){return(t[n>>>3]|t[1+(n>>>3)]<<8|t[2+(n>>>3)]<<16)>>>(7&n)},e.F._get25=function(t,n){return(t[n>>>3]|t[1+(n>>>3)]<<8|t[2+(n>>>3)]<<16|t[3+(n>>>3)]<<24)>>>(7&n)},e.F.U=(t=Uint16Array,n=Uint32Array,{next_code:new t(16),bl_count:new t(16),ordr:[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],of0:[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,999,999,999],exb:[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0],ldef:new t(32),df0:[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,65535,65535],dxb:[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0],ddef:new n(32),flmap:new t(512),fltree:[],fdmap:new t(32),fdtree:[],lmap:new t(32768),ltree:[],ttree:[],dmap:new t(32768),dtree:[],imap:new t(512),itree:[],rev15:new t(32768),lhst:new n(286),dhst:new n(30),ihst:new n(19),lits:new n(15e3),strt:new t(65536),prev:new t(32768)}),function(){for(var t=e.F.U,n=0;n<32768;n++){var r=n;r=(4278255360&(r=(4042322160&(r=(3435973836&(r=(2863311530&r)>>>1|(1431655765&r)<<1))>>>2|(858993459&r)<<2))>>>4|(252645135&r)<<4))>>>8|(16711935&r)<<8,t.rev15[n]=(r>>>16|r<<16)>>>17}function i(t,n,e){for(;0!=n--;)t.push(0,e)}for(n=0;n<32;n++)t.ldef[n]=t.of0[n]<<3|t.exb[n],t.ddef[n]=t.df0[n]<<4|t.dxb[n];i(t.fltree,144,8),i(t.fltree,112,9),i(t.fltree,24,7),i(t.fltree,8,8),e.F.makeCodes(t.fltree,9),e.F.codes2map(t.fltree,9,t.flmap),e.F.revCodes(t.fltree,9),i(t.fdtree,32,5),e.F.makeCodes(t.fdtree,5),e.F.codes2map(t.fdtree,5,t.fdmap),e.F.revCodes(t.fdtree,5),i(t.itree,19,0),i(t.ltree,286,0),i(t.dtree,30,0),i(t.ttree,320,0)}()}();var L=function(t,n){return n.forEach((function(n){n&&"string"!=typeof n&&!Array.isArray(n)&&Object.keys(n).forEach((function(e){if("default"!==e&&!(e in t)){var r=Object.getOwnPropertyDescriptor(n,e);Object.defineProperty(t,e,r.get?r:{enumerable:!0,get:function(){return n[e]}})}}))})),Object.freeze(t)}({__proto__:null,default:B},[B]);const F=function(){var t={nextZero(t,n){for(;0!=t[n];)n++;return n},readUshort:(t,n)=>t[n]<<8|t[n+1],writeUshort(t,n,e){t[n]=e>>8&255,t[n+1]=255&e},readUint:(t,n)=>16777216*t[n]+(t[n+1]<<16|t[n+2]<<8|t[n+3]),writeUint(t,n,e){t[n]=e>>24&255,t[n+1]=e>>16&255,t[n+2]=e>>8&255,t[n+3]=255&e},readASCII(t,n,e){let r="";for(let i=0;i<e;i++)r+=String.fromCharCode(t[n+i]);return r},writeASCII(t,n,e){for(let r=0;r<e.length;r++)t[n+r]=e.charCodeAt(r)},readBytes(t,n,e){const r=[];for(let i=0;i<e;i++)r.push(t[n+i]);return r},pad:t=>t.length<2?`0${t}`:t,readUTF8(n,e,r){let i,s="";for(let i=0;i<r;i++)s+=`%${t.pad(n[e+i].toString(16))}`;try{i=decodeURIComponent(s)}catch(i){return t.readASCII(n,e,r)}return i}};function n(n,e,r,i){const o=e*r,u=s(i),c=Math.ceil(e*u/8),h=new Uint8Array(4*o),a=new Uint32Array(h.buffer),{ctype:l}=i,{depth:f}=i,d=t.readUshort;if(6==l){const t=o<<2;if(8==f)for(var v=0;v<t;v+=4)h[v]=n[v],h[v+1]=n[v+1],h[v+2]=n[v+2],h[v+3]=n[v+3];if(16==f)for(v=0;v<t;v++)h[v]=n[v<<1]}else if(2==l){const t=i.tabs.tRNS;if(null==t){if(8==f)for(v=0;v<o;v++){var p=3*v;a[v]=255<<24|n[p+2]<<16|n[p+1]<<8|n[p]}if(16==f)for(v=0;v<o;v++)a[v]=255<<24|n[4+(p=6*v)]<<16|n[p+2]<<8|n[p]}else{var w=t[0];const e=t[1],r=t[2];if(8==f)for(v=0;v<o;v++){var y=v<<2;a[v]=255<<24|n[2+(p=3*v)]<<16|n[p+1]<<8|n[p],n[p]==w&&n[p+1]==e&&n[p+2]==r&&(h[y+3]=0)}if(16==f)for(v=0;v<o;v++)y=v<<2,a[v]=255<<24|n[4+(p=6*v)]<<16|n[p+2]<<8|n[p],d(n,p)==w&&d(n,p+2)==e&&d(n,p+4)==r&&(h[y+3]=0)}}else if(3==l){const t=i.tabs.PLTE,s=i.tabs.tRNS,u=s?s.length:0;if(1==f)for(var g=0;g<r;g++){var b=g*c,m=g*e;for(v=0;v<e;v++){var A=3*(k=n[b+(v>>3)]>>7-(7&v)&1);h[y=m+v<<2]=t[A],h[y+1]=t[A+1],h[y+2]=t[A+2],h[y+3]=k<u?s[k]:255}}if(2==f)for(g=0;g<r;g++)for(b=g*c,m=g*e,v=0;v<e;v++)A=3*(k=n[b+(v>>2)]>>6-((3&v)<<1)&3),h[y=m+v<<2]=t[A],h[y+1]=t[A+1],h[y+2]=t[A+2],h[y+3]=k<u?s[k]:255;if(4==f)for(g=0;g<r;g++)for(b=g*c,m=g*e,v=0;v<e;v++)A=3*(k=n[b+(v>>1)]>>4-((1&v)<<2)&15),h[y=m+v<<2]=t[A],h[y+1]=t[A+1],h[y+2]=t[A+2],h[y+3]=k<u?s[k]:255;if(8==f)for(v=0;v<o;v++){var k;A=3*(k=n[v]),h[y=v<<2]=t[A],h[y+1]=t[A+1],h[y+2]=t[A+2],h[y+3]=k<u?s[k]:255}}else if(4==l){if(8==f)for(v=0;v<o;v++){var x=n[M=v<<1];h[y=v<<2]=x,h[y+1]=x,h[y+2]=x,h[y+3]=n[M+1]}if(16==f)for(v=0;v<o;v++){var M;x=n[M=v<<2],h[y=v<<2]=x,h[y+1]=x,h[y+2]=x,h[y+3]=n[M+2]}}else if(0==l)for(w=i.tabs.tRNS?i.tabs.tRNS:-1,g=0;g<r;g++){const t=g*c,r=g*e;if(1==f)for(var S=0;S<e;S++){var C=(x=255*(n[t+(S>>>3)]>>>7-(7&S)&1))==255*w?0:255;a[r+S]=C<<24|x<<16|x<<8|x}else if(2==f)for(S=0;S<e;S++)C=(x=85*(n[t+(S>>>2)]>>>6-((3&S)<<1)&3))==85*w?0:255,a[r+S]=C<<24|x<<16|x<<8|x;else if(4==f)for(S=0;S<e;S++)C=(x=17*(n[t+(S>>>1)]>>>4-((1&S)<<2)&15))==17*w?0:255,a[r+S]=C<<24|x<<16|x<<8|x;else if(8==f)for(S=0;S<e;S++)C=(x=n[t+S])==w?0:255,a[r+S]=C<<24|x<<16|x<<8|x;else if(16==f)for(S=0;S<e;S++)x=n[t+(S<<1)],C=d(n,t+(S<<1))==w?0:255,a[r+S]=C<<24|x<<16|x<<8|x}return h}function e(t,n,e,u){const c=s(t),h=Math.ceil(e*c/8),a=new Uint8Array((h+1+t.interlace)*u);return n=t.tabs.CgBI?i(n,a):r(n,a),0==t.interlace?n=o(n,t,0,e,u):1==t.interlace&&(n=function(t,n){const e=n.width,r=n.height,i=s(n),u=i>>3,c=Math.ceil(e*i/8),h=new Uint8Array(r*c);let a=0;const l=[0,0,4,0,2,0,1],f=[0,4,0,2,0,1,0],d=[8,8,8,4,4,2,2],v=[8,8,4,4,2,2,1];let p=0;for(;p<7;){const s=d[p],y=v[p];let g=0,b=0,m=l[p];for(;m<r;)m+=s,b++;let A=f[p];for(;A<e;)A+=y,g++;const k=Math.ceil(g*i/8);o(t,n,a,g,b);let x=0,M=l[p];for(;M<r;){let n=f[p],r=a+x*k<<3;for(;n<e;){var w;if(1==i&&(w=(w=t[r>>3])>>7-(7&r)&1,h[M*c+(n>>3)]|=w<<7-(7&n)),2==i&&(w=(w=t[r>>3])>>6-(7&r)&3,h[M*c+(n>>2)]|=w<<6-((3&n)<<1)),4==i&&(w=(w=t[r>>3])>>4-(7&r)&15,h[M*c+(n>>1)]|=w<<4-((1&n)<<2)),i>=8){const e=M*c+n*u;for(let n=0;n<u;n++)h[e+n]=t[(r>>3)+n]}r+=i,n+=y}x++,M+=s}g*b!=0&&(a+=b*(1+k)),p+=1}return h}(n,t)),n}function r(t,n){return i(new Uint8Array(t.buffer,2,t.length-6),n)}var i=function(){const t={H:{}};return t.H.N=function(n,e){const r=Uint8Array;let i,s,o=0,u=0,c=0,h=0,a=0,l=0,f=0,d=0,v=0;if(3==n[0]&&0==n[1])return e||new r(0);const p=t.H,w=p.b,y=p.e,g=p.R,b=p.n,m=p.A,A=p.Z,k=p.m,x=null==e;for(x&&(e=new r(n.length>>>2<<5));0==o;)if(o=w(n,v,1),u=w(n,v+1,2),v+=3,0!=u){if(x&&(e=t.H.W(e,d+(1<<17))),1==u&&(i=k.J,s=k.h,l=511,f=31),2==u){c=y(n,v,5)+257,h=y(n,v+5,5)+1,a=y(n,v+10,4)+4,v+=14;let t=1;for(var M=0;M<38;M+=2)k.Q[M]=0,k.Q[M+1]=0;for(M=0;M<a;M++){const e=y(n,v+3*M,3);k.Q[1+(k.X[M]<<1)]=e,e>t&&(t=e)}v+=3*a,b(k.Q,t),m(k.Q,t,k.u),i=k.w,s=k.d,v=g(k.u,(1<<t)-1,c+h,n,v,k.v);const e=p.V(k.v,0,c,k.C);l=(1<<e)-1;const r=p.V(k.v,c,h,k.D);f=(1<<r)-1,b(k.C,e),m(k.C,e,i),b(k.D,r),m(k.D,r,s)}for(;;){const t=i[A(n,v)&l];v+=15&t;const r=t>>>4;if(r>>>8==0)e[d++]=r;else{if(256==r)break;{let t=d+r-254;if(r>264){const e=k.q[r-257];t=d+(e>>>3)+y(n,v,7&e),v+=7&e}const i=s[A(n,v)&f];v+=15&i;const o=k.c[i>>>4],u=(o>>>4)+w(n,v,15&o);for(v+=15&o;d<t;)e[d]=e[d++-u],e[d]=e[d++-u],e[d]=e[d++-u],e[d]=e[d++-u];d=t}}}}else{7&v&&(v+=8-(7&v));const i=4+(v>>>3),s=n[i-4]|n[i-3]<<8;x&&(e=t.H.W(e,d+s)),e.set(new r(n.buffer,n.byteOffset+i,s),d),v=i+s<<3,d+=s}return e.length==d?e:e.slice(0,d)},t.H.W=function(t,n){const e=t.length;if(n<=e)return t;const r=new Uint8Array(e<<1);return r.set(t,0),r},t.H.R=function(n,e,r,i,s,o){const u=t.H.e,c=t.H.Z;let h=0;for(;h<r;){const t=n[c(i,s)&e];s+=15&t;const r=t>>>4;if(r<=15)o[h]=r,h++;else{let t=0,n=0;16==r?(n=3+u(i,s,2),s+=2,t=o[h-1]):17==r?(n=3+u(i,s,3),s+=3):18==r&&(n=11+u(i,s,7),s+=7);const e=h+n;for(;h<e;)o[h]=t,h++}}return s},t.H.V=function(t,n,e,r){let i=0,s=0;const o=r.length>>>1;for(;s<e;){const e=t[s+n];r[s<<1]=0,r[1+(s<<1)]=e,e>i&&(i=e),s++}for(;s<o;)r[s<<1]=0,r[1+(s<<1)]=0,s++;return i},t.H.n=function(n,e){const r=t.H.m,i=n.length;let s,o,u,c;const h=r.j;for(var a=0;a<=e;a++)h[a]=0;for(a=1;a<i;a+=2)h[n[a]]++;const l=r.K;for(s=0,h[0]=0,o=1;o<=e;o++)s=s+h[o-1]<<1,l[o]=s;for(u=0;u<i;u+=2)c=n[u+1],0!=c&&(n[u]=l[c],l[c]++)},t.H.A=function(n,e,r){const i=n.length,s=t.H.m.r;for(let t=0;t<i;t+=2)if(0!=n[t+1]){const i=n[t+1],o=t>>1<<4|i,u=e-i;let c=n[t]<<u;const h=c+(1<<u);for(;c!=h;)r[s[c]>>>15-e]=o,c++}},t.H.l=function(n,e){const r=t.H.m.r,i=15-e;for(let t=0;t<n.length;t+=2)n[t]=r[n[t]<<e-n[t+1]]>>>i},t.H.M=function(t,n,e){const r=n>>>3;t[r]|=e<<=7&n,t[r+1]|=e>>>8},t.H.I=function(t,n,e){const r=n>>>3;t[r]|=e<<=7&n,t[r+1]|=e>>>8,t[r+2]|=e>>>16},t.H.e=function(t,n,e){return(t[n>>>3]|t[1+(n>>>3)]<<8)>>>(7&n)&(1<<e)-1},t.H.b=function(t,n,e){return(t[n>>>3]|t[1+(n>>>3)]<<8|t[2+(n>>>3)]<<16)>>>(7&n)&(1<<e)-1},t.H.Z=function(t,n){return(t[n>>>3]|t[1+(n>>>3)]<<8|t[2+(n>>>3)]<<16)>>>(7&n)},t.H.i=function(t,n){return(t[n>>>3]|t[1+(n>>>3)]<<8|t[2+(n>>>3)]<<16|t[3+(n>>>3)]<<24)>>>(7&n)},t.H.m=function(){const t=Uint16Array,n=Uint32Array;return{K:new t(16),j:new t(16),X:[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],S:[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,999,999,999],T:[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0],q:new t(32),p:[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,65535,65535],z:[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0],c:new n(32),J:new t(512),_:[],h:new t(32),$:[],w:new t(32768),C:[],v:[],d:new t(32768),D:[],u:new t(512),Q:[],r:new t(32768),s:new n(286),Y:new n(30),a:new n(19),t:new n(15e3),k:new t(65536),g:new t(32768)}}(),function(){const n=t.H.m;for(var e=0;e<32768;e++){let t=e;t=(2863311530&t)>>>1|(1431655765&t)<<1,t=(3435973836&t)>>>2|(858993459&t)<<2,t=(4042322160&t)>>>4|(252645135&t)<<4,t=(4278255360&t)>>>8|(16711935&t)<<8,n.r[e]=(t>>>16|t<<16)>>>17}function r(t,n,e){for(;0!=n--;)t.push(0,e)}for(e=0;e<32;e++)n.q[e]=n.S[e]<<3|n.T[e],n.c[e]=n.p[e]<<4|n.z[e];r(n._,144,8),r(n._,112,9),r(n._,24,7),r(n._,8,8),t.H.n(n._,9),t.H.A(n._,9,n.J),t.H.l(n._,9),r(n.$,32,5),t.H.n(n.$,5),t.H.A(n.$,5,n.h),t.H.l(n.$,5),r(n.Q,19,0),r(n.C,286,0),r(n.D,30,0),r(n.v,320,0)}(),t.H.N}();function s(t){return[1,null,3,1,2,null,4][t.ctype]*t.depth}function o(t,n,e,r,i){let o=s(n);const c=Math.ceil(r*o/8);let h,a;o=Math.ceil(o/8);let l=t[e],f=0;if(l>1&&(t[e]=[0,0,1][l-2]),3==l)for(f=o;f<c;f++)t[f+1]=t[f+1]+(t[f+1-o]>>>1)&255;for(let n=0;n<i;n++)if(h=e+n*c,a=h+n+1,l=t[a-1],f=0,0==l)for(;f<c;f++)t[h+f]=t[a+f];else if(1==l){for(;f<o;f++)t[h+f]=t[a+f];for(;f<c;f++)t[h+f]=t[a+f]+t[h+f-o]}else if(2==l)for(;f<c;f++)t[h+f]=t[a+f]+t[h+f-c];else if(3==l){for(;f<o;f++)t[h+f]=t[a+f]+(t[h+f-c]>>>1);for(;f<c;f++)t[h+f]=t[a+f]+(t[h+f-c]+t[h+f-o]>>>1)}else{for(;f<o;f++)t[h+f]=t[a+f]+u(0,t[h+f-c],0);for(;f<c;f++)t[h+f]=t[a+f]+u(t[h+f-o],t[h+f-c],t[h+f-o-c])}return t}function u(t,n,e){const r=t+n-e,i=r-t,s=r-n,o=r-e;return i*i<=s*s&&i*i<=o*o?t:s*s<=o*o?n:e}function c(n,e,r){r.width=t.readUint(n,e),r.height=t.readUint(n,e+=4),r.depth=n[e+=4],e++,r.ctype=n[e],e++,r.compress=n[e],e++,r.filter=n[e],e++,r.interlace=n[e],e++}function h(t,n,e,r,i,s,o,u,c){const h=Math.min(n,i),a=Math.min(e,s);let l=0,f=0;for(let e=0;e<a;e++)for(let s=0;s<h;s++)if(o>=0&&u>=0?(l=e*n+s<<2,f=(u+e)*i+o+s<<2):(l=(-u+e)*n-o+s<<2,f=e*i+s<<2),0==c)r[f]=t[l],r[f+1]=t[l+1],r[f+2]=t[l+2],r[f+3]=t[l+3];else if(1==c){var d=t[l+3]*(1/255),v=t[l]*d,p=t[l+1]*d,w=t[l+2]*d,y=r[f+3]*(1/255),g=r[f]*y,b=r[f+1]*y,m=r[f+2]*y;const n=1-d,e=d+y*n,i=0==e?0:1/e;r[f+3]=255*e,r[f+0]=(v+g*n)*i,r[f+1]=(p+b*n)*i,r[f+2]=(w+m*n)*i}else if(2==c)v=t[l],p=t[l+1],w=t[l+2],g=r[f],b=r[f+1],m=r[f+2],(d=t[l+3])==(y=r[f+3])&&v==g&&p==b&&w==m?(r[f]=0,r[f+1]=0,r[f+2]=0,r[f+3]=0):(r[f]=v,r[f+1]=p,r[f+2]=w,r[f+3]=d);else if(3==c){if(v=t[l],p=t[l+1],w=t[l+2],g=r[f],b=r[f+1],m=r[f+2],(d=t[l+3])==(y=r[f+3])&&v==g&&p==b&&w==m)continue;if(d<220&&y>20)return!1}return!0}return{decode:function(n){const s=new Uint8Array(n);let o=8;const u=t,h=u.readUshort,a=u.readUint,l={tabs:{},frames:[]},f=new Uint8Array(s.length);let d,v=0,p=0;const w=[137,80,78,71,13,10,26,10];for(var y=0;y<8;y++)if(s[y]!=w[y])throw"The input is not a PNG file!";for(;o<s.length;){const t=u.readUint(s,o);o+=4;const n=u.readASCII(s,o,4);if(o+=4,"IHDR"==n)c(s,o,l);else if("iCCP"==n){for(var g=o;0!=s[g];)g++;u.readASCII(s,o,g-o);const e=s.slice(g+2,o+t);let c=null;try{c=r(e)}catch(t){c=i(e)}l.tabs[n]=c}else if("CgBI"==n)l.tabs[n]=s.slice(o,o+4);else if("IDAT"==n){for(y=0;y<t;y++)f[v+y]=s[o+y];v+=t}else if("acTL"==n)l.tabs[n]={num_frames:a(s,o),num_plays:a(s,o+4)},d=new Uint8Array(s.length);else if("fcTL"==n){0!=p&&((M=l.frames[l.frames.length-1]).data=e(l,d.slice(0,p),M.rect.width,M.rect.height),p=0);const t={x:a(s,o+12),y:a(s,o+16),width:a(s,o+4),height:a(s,o+8)};let n=h(s,o+22);n=h(s,o+20)/(0==n?100:n);const r={rect:t,delay:Math.round(1e3*n),dispose:s[o+24],blend:s[o+25]};l.frames.push(r)}else if("fdAT"==n){for(y=0;y<t-4;y++)d[p+y]=s[o+y+4];p+=t-4}else if("pHYs"==n)l.tabs[n]=[u.readUint(s,o),u.readUint(s,o+4),s[o+8]];else if("cHRM"==n)for(l.tabs[n]=[],y=0;y<8;y++)l.tabs[n].push(u.readUint(s,o+4*y));else if("tEXt"==n||"zTXt"==n){null==l.tabs[n]&&(l.tabs[n]={});var b=u.nextZero(s,o),m=u.readASCII(s,o,b-o),A=o+t-b-1;if("tEXt"==n)x=u.readASCII(s,b+1,A);else{var k=r(s.slice(b+2,b+2+A));x=u.readUTF8(k,0,k.length)}l.tabs[n][m]=x}else if("iTXt"==n){null==l.tabs[n]&&(l.tabs[n]={}),b=0,b=u.nextZero(s,g=o),m=u.readASCII(s,g,b-g);const e=s[g=b+1];var x;b=u.nextZero(s,g+=2),u.readASCII(s,g,b-g),b=u.nextZero(s,g=b+1),u.readUTF8(s,g,b-g),A=t-((g=b+1)-o),0==e?x=u.readUTF8(s,g,A):(k=r(s.slice(g,g+A)),x=u.readUTF8(k,0,k.length)),l.tabs[n][m]=x}else if("PLTE"==n)l.tabs[n]=u.readBytes(s,o,t);else if("hIST"==n){const t=l.tabs.PLTE.length/3;for(l.tabs[n]=[],y=0;y<t;y++)l.tabs[n].push(h(s,o+2*y))}else if("tRNS"==n)3==l.ctype?l.tabs[n]=u.readBytes(s,o,t):0==l.ctype?l.tabs[n]=h(s,o):2==l.ctype&&(l.tabs[n]=[h(s,o),h(s,o+2),h(s,o+4)]);else if("gAMA"==n)l.tabs[n]=u.readUint(s,o)/1e5;else if("sRGB"==n)l.tabs[n]=s[o];else if("bKGD"==n)0==l.ctype||4==l.ctype?l.tabs[n]=[h(s,o)]:2==l.ctype||6==l.ctype?l.tabs[n]=[h(s,o),h(s,o+2),h(s,o+4)]:3==l.ctype&&(l.tabs[n]=s[o]);else if("IEND"==n)break;o+=t,u.readUint(s,o),o+=4}var M;return 0!=p&&((M=l.frames[l.frames.length-1]).data=e(l,d.slice(0,p),M.rect.width,M.rect.height)),l.data=e(l,f,l.width,l.height),delete l.compress,delete l.interlace,delete l.filter,l},toRGBA8:function(t){const e=t.width,r=t.height;if(null==t.tabs.acTL)return[n(t.data,e,r,t).buffer];const i=[];null==t.frames[0].data&&(t.frames[0].data=t.data);const s=e*r*4,o=new Uint8Array(s),u=new Uint8Array(s),c=new Uint8Array(s);for(let l=0;l<t.frames.length;l++){const f=t.frames[l],d=f.rect.x,v=f.rect.y,p=f.rect.width,w=f.rect.height,y=n(f.data,p,w,t);if(0!=l)for(var a=0;a<s;a++)c[a]=o[a];if(0==f.blend?h(y,p,w,o,e,r,d,v,0):1==f.blend&&h(y,p,w,o,e,r,d,v,1),i.push(o.buffer.slice(0)),0==f.dispose);else if(1==f.dispose)h(u,p,w,o,e,r,d,v,0);else if(2==f.dispose)for(a=0;a<s;a++)o[a]=c[a]}return i},_paeth:u,_copyTile:h,_bin:t}}();!function(){const{_copyTile:t}=F,{_bin:n}=F,e=F._paeth;var r={table:function(){const t=new Uint32Array(256);for(let n=0;n<256;n++){let e=n;for(let t=0;t<8;t++)1&e?e=3988292384^e>>>1:e>>>=1;t[n]=e}return t}(),update(t,n,e,i){for(let s=0;s<i;s++)t=r.table[255&(t^n[e+s])]^t>>>8;return t},crc:(t,n,e)=>4294967295^r.update(4294967295,t,n,e)};function i(t,n,e,r){n[e]+=t[0]*r>>4,n[e+1]+=t[1]*r>>4,n[e+2]+=t[2]*r>>4,n[e+3]+=t[3]*r>>4}function s(t){return Math.max(0,Math.min(255,t))}function o(t,n){const e=t[0]-n[0],r=t[1]-n[1],i=t[2]-n[2],s=t[3]-n[3];return e*e+r*r+i*i+s*s}function u(t,n,e,r,u,c,h){null==h&&(h=1);const a=r.length,l=[];for(var f=0;f<a;f++){const t=r[f];l.push([t>>>0&255,t>>>8&255,t>>>16&255,t>>>24&255])}for(f=0;f<a;f++){let t=4294967295;for(var d=0,v=0;v<a;v++){var p=o(l[f],l[v]);v!=f&&p<t&&(t=p,d=v)}}const w=new Uint32Array(u.buffer),y=new Int16Array(n*e*4),g=[0,8,2,10,12,4,14,6,3,11,1,9,15,7,13,5];for(f=0;f<g.length;f++)g[f]=255*((g[f]+.5)/16-.5);for(let u=0;u<e;u++)for(let m=0;m<n;m++){var b;f=4*(u*n+m),b=2!=h?[s(t[f]+y[f]),s(t[f+1]+y[f+1]),s(t[f+2]+y[f+2]),s(t[f+3]+y[f+3])]:[s(t[f]+(p=g[4*(3&u)+(3&m)])),s(t[f+1]+p),s(t[f+2]+p),s(t[f+3]+p)],d=0;let A=16777215;for(v=0;v<a;v++){const t=o(b,l[v]);t<A&&(A=t,d=v)}const k=l[d],x=[b[0]-k[0],b[1]-k[1],b[2]-k[2],b[3]-k[3]];1==h&&(m!=n-1&&i(x,y,f+4,7),u!=e-1&&(0!=m&&i(x,y,f+4*n-4,3),i(x,y,f+4*n,5),m!=n-1&&i(x,y,f+4*n+4,1))),c[f>>2]=d,w[f>>2]=r[d]}}function c(t,e,i,s,o){null==o&&(o={});const{crc:u}=r,c=n.writeUint,h=n.writeUshort,a=n.writeASCII;let l=8;const f=t.frames.length>1;let d,v=!1,p=33+(f?20:0);if(null!=o.sRGB&&(p+=13),null!=o.pHYs&&(p+=21),null!=o.iCCP&&(d=pako.deflate(o.iCCP),p+=21+d.length+4),3==t.ctype){for(var w=t.plte.length,y=0;y<w;y++)t.plte[y]>>>24!=255&&(v=!0);p+=8+3*w+4+(v?8+1*w+4:0)}for(var g=0;g<t.frames.length;g++)f&&(p+=38),p+=(k=t.frames[g]).cimg.length+12,0!=g&&(p+=4);p+=12;const b=new Uint8Array(p),m=[137,80,78,71,13,10,26,10];for(y=0;y<8;y++)b[y]=m[y];if(c(b,l,13),l+=4,a(b,l,"IHDR"),l+=4,c(b,l,e),l+=4,c(b,l,i),l+=4,b[l]=t.depth,l++,b[l]=t.ctype,l++,b[l]=0,l++,b[l]=0,l++,b[l]=0,l++,c(b,l,u(b,l-17,17)),l+=4,null!=o.sRGB&&(c(b,l,1),l+=4,a(b,l,"sRGB"),l+=4,b[l]=o.sRGB,l++,c(b,l,u(b,l-5,5)),l+=4),null!=o.iCCP){const t=13+d.length;c(b,l,t),l+=4,a(b,l,"iCCP"),l+=4,a(b,l,"ICC profile"),l+=11,l+=2,b.set(d,l),l+=d.length,c(b,l,u(b,l-(t+4),t+4)),l+=4}if(null!=o.pHYs&&(c(b,l,9),l+=4,a(b,l,"pHYs"),l+=4,c(b,l,o.pHYs[0]),l+=4,c(b,l,o.pHYs[1]),l+=4,b[l]=o.pHYs[2],l++,c(b,l,u(b,l-13,13)),l+=4),f&&(c(b,l,8),l+=4,a(b,l,"acTL"),l+=4,c(b,l,t.frames.length),l+=4,c(b,l,null!=o.loop?o.loop:0),l+=4,c(b,l,u(b,l-12,12)),l+=4),3==t.ctype){for(c(b,l,3*(w=t.plte.length)),l+=4,a(b,l,"PLTE"),l+=4,y=0;y<w;y++){const n=3*y,e=t.plte[y],r=e>>>8&255,i=e>>>16&255;b[l+n+0]=255&e,b[l+n+1]=r,b[l+n+2]=i}if(l+=3*w,c(b,l,u(b,l-3*w-4,3*w+4)),l+=4,v){for(c(b,l,w),l+=4,a(b,l,"tRNS"),l+=4,y=0;y<w;y++)b[l+y]=t.plte[y]>>>24&255;l+=w,c(b,l,u(b,l-w-4,w+4)),l+=4}}let A=0;for(g=0;g<t.frames.length;g++){var k=t.frames[g];f&&(c(b,l,26),l+=4,a(b,l,"fcTL"),l+=4,c(b,l,A++),l+=4,c(b,l,k.rect.width),l+=4,c(b,l,k.rect.height),l+=4,c(b,l,k.rect.x),l+=4,c(b,l,k.rect.y),l+=4,h(b,l,s[g]),l+=2,h(b,l,1e3),l+=2,b[l]=k.dispose,l++,b[l]=k.blend,l++,c(b,l,u(b,l-30,30)),l+=4);const n=k.cimg;c(b,l,(w=n.length)+(0==g?0:4)),l+=4;const e=l;a(b,l,0==g?"IDAT":"fdAT"),l+=4,0!=g&&(c(b,l,A++),l+=4),b.set(n,l),l+=w,c(b,l,u(b,e,l-e)),l+=4}return c(b,l,0),l+=4,a(b,l,"IEND"),l+=4,c(b,l,u(b,l-4,4)),l+=4,b.buffer}function h(t,n,e){for(let r=0;r<t.frames.length;r++){const i=t.frames[r],s=i.rect.height,o=new Uint8Array(s*i.bpl+s);i.cimg=d(i.img,s,i.bpp,i.bpl,o,n,e)}}function a(n,e,r,i,s){const o=s[0],c=s[1],h=s[2],a=s[3],d=s[4],v=s[5];let w=6,y=8,g=255;for(var b=0;b<n.length;b++){const t=new Uint8Array(n[b]);for(var m=t.length,A=0;A<m;A+=4)g&=t[A+3]}const k=255!=g,x=function(n,e,r,i,s,o){const u=[];for(var c=0;c<n.length;c++){const l=new Uint8Array(n[c]),d=new Uint32Array(l.buffer);var h;let p=0,w=0,y=e,g=r,b=i?1:0;if(0!=c){const m=o||i||1==c||0!=u[c-2].dispose?1:2;let A=0,k=1e9;for(let t=0;t<m;t++){var a=new Uint8Array(n[c-1-t]);const i=new Uint32Array(n[c-1-t]);let o=e,u=r,h=-1,l=-1;for(let t=0;t<r;t++)for(let n=0;n<e;n++)d[v=t*e+n]!=i[v]&&(n<o&&(o=n),n>h&&(h=n),t<u&&(u=t),t>l&&(l=t));-1==h&&(o=u=h=l=0),s&&(!(1&~o)&&o--,!(1&~u)&&u--);const f=(h-o+1)*(l-u+1);f<k&&(k=f,A=t,p=o,w=u,y=h-o+1,g=l-u+1)}a=new Uint8Array(n[c-1-A]),1==A&&(u[c-1].dispose=2),h=new Uint8Array(y*g*4),t(a,e,r,h,y,g,-p,-w,0),b=t(l,e,r,h,y,g,-p,-w,3)?1:0,1==b?f(l,e,r,h,{x:p,y:w,width:y,height:g}):t(l,e,r,h,y,g,-p,-w,0)}else h=l.slice(0);u.push({rect:{x:p,y:w,width:y,height:g},img:h,blend:b,dispose:0})}if(i)for(c=0;c<u.length;c++){if(1==(p=u[c]).blend)continue;const t=p.rect,i=u[c-1].rect,o=Math.min(t.x,i.x),h=Math.min(t.y,i.y),a={x:o,y:h,width:Math.max(t.x+t.width,i.x+i.width)-o,height:Math.max(t.y+t.height,i.y+i.height)-h};u[c-1].dispose=1,c-1!=0&&l(n,e,r,u,c-1,a,s),l(n,e,r,u,c,a,s)}let d=0;if(1!=n.length)for(var v=0;v<u.length;v++){var p;d+=(p=u[v]).rect.width*p.rect.height}return u}(n,e,r,o,c,h),M={},S=[],C=[];if(0!=i){const t=[];for(A=0;A<x.length;A++)t.push(x[A].img.buffer);const n=function(t){let n=0;for(var e=0;e<t.length;e++)n+=t[e].byteLength;const r=new Uint8Array(n);let i=0;for(e=0;e<t.length;e++){const n=new Uint8Array(t[e]),s=n.length;for(let t=0;t<s;t+=4){let e=n[t],s=n[t+1],o=n[t+2];const u=n[t+3];0==u&&(e=s=o=0),r[i+t]=e,r[i+t+1]=s,r[i+t+2]=o,r[i+t+3]=u}i+=s}return r.buffer}(t),e=p(n,i);for(A=0;A<e.plte.length;A++)S.push(e.plte[A].est.rgba);let r=0;for(A=0;A<x.length;A++){const t=(E=x[A]).img.length;var U=new Uint8Array(e.inds.buffer,r>>2,t>>2);C.push(U);const n=new Uint8Array(e.abuf,r,t);v&&u(E.img,E.rect.width,E.rect.height,S,n,U),E.img.set(n),r+=t}}else for(b=0;b<x.length;b++){var E=x[b];const t=new Uint32Array(E.img.buffer);var j=E.rect.width;for(m=t.length,U=new Uint8Array(m),C.push(U),A=0;A<m;A++){const n=t[A];if(0!=A&&n==t[A-1])U[A]=U[A-1];else if(A>j&&n==t[A-j])U[A]=U[A-j];else{let t=M[n];if(null==t&&(M[n]=t=S.length,S.push(n),S.length>=300))break;U[A]=t}}}const T=S.length;for(T<=256&&0==d&&(y=T<=2?1:T<=4?2:T<=16?4:8,y=Math.max(y,a)),b=0;b<x.length;b++){const t=(E=x[b]).rect.height;let n=E.img,e=4*(j=E.rect.width),r=4;if(T<=256&&0==d){e=Math.ceil(y*j/8);var I=new Uint8Array(e*t);const i=C[b];for(let n=0;n<t;n++){A=n*e;const t=n*j;if(8==y)for(var _=0;_<j;_++)I[A+_]=i[t+_];else if(4==y)for(_=0;_<j;_++)I[A+(_>>1)]|=i[t+_]<<4-4*(1&_);else if(2==y)for(_=0;_<j;_++)I[A+(_>>2)]|=i[t+_]<<6-2*(3&_);else if(1==y)for(_=0;_<j;_++)I[A+(_>>3)]|=i[t+_]<<7-1*(7&_)}n=I,w=3,r=1}else if(0==k&&1==x.length){I=new Uint8Array(j*t*3);const i=j*t;for(A=0;A<i;A++){const t=3*A,e=4*A;I[t]=n[e],I[t+1]=n[e+1],I[t+2]=n[e+2]}n=I,w=2,r=3,e=3*j}E.img=n,E.bpl=e,E.bpp=r}return{ctype:w,depth:y,plte:S,frames:x}}function l(n,e,r,i,s,o,u){const c=Uint8Array,h=Uint32Array,a=new c(n[s-1]),l=new h(n[s-1]),d=s+1<n.length?new c(n[s+1]):null,v=new c(n[s]),p=new h(v.buffer);let w=e,y=r,g=-1,b=-1;for(let t=0;t<o.height;t++)for(let n=0;n<o.width;n++){const r=o.x+n,u=o.y+t,c=u*e+r,h=p[c];0==h||0==i[s-1].dispose&&l[c]==h&&(null==d||0!=d[4*c+3])||(r<w&&(w=r),r>g&&(g=r),u<y&&(y=u),u>b&&(b=u))}-1==g&&(w=y=g=b=0),u&&(!(1&~w)&&w--,!(1&~y)&&y--);const m=i[s];m.rect=o={x:w,y,width:g-w+1,height:b-y+1},m.blend=1,m.img=new Uint8Array(o.width*o.height*4),0==i[s-1].dispose?(t(a,e,r,m.img,o.width,o.height,-o.x,-o.y,0),f(v,e,r,m.img,o)):t(v,e,r,m.img,o.width,o.height,-o.x,-o.y,0)}function f(n,e,r,i,s){t(n,e,r,i,s.width,s.height,-s.x,-s.y,2)}function d(t,n,e,r,i,s,o){const u=[];let c,h=[0,1,2,3,4];-1!=s?h=[s]:(n*r>5e5||1==e)&&(h=[0]),o&&(c={level:0});const a=L;for(var l=0;l<h.length;l++){for(let s=0;s<n;s++)v(i,t,s,r,e,h[l]);u.push(a.deflate(i,c))}let f,d=1e9;for(l=0;l<u.length;l++)u[l].length<d&&(f=l,d=u[l].length);return u[f]}function v(t,n,r,i,s,o){const u=r*i;let c=u+r;if(t[c]=o,c++,0==o)if(i<500)for(var h=0;h<i;h++)t[c+h]=n[u+h];else t.set(new Uint8Array(n.buffer,u,i),c);else if(1==o){for(h=0;h<s;h++)t[c+h]=n[u+h];for(h=s;h<i;h++)t[c+h]=n[u+h]-n[u+h-s]+256&255}else if(0==r){for(h=0;h<s;h++)t[c+h]=n[u+h];if(2==o)for(h=s;h<i;h++)t[c+h]=n[u+h];if(3==o)for(h=s;h<i;h++)t[c+h]=n[u+h]-(n[u+h-s]>>1)+256&255;if(4==o)for(h=s;h<i;h++)t[c+h]=n[u+h]-e(n[u+h-s],0,0)+256&255}else{if(2==o)for(h=0;h<i;h++)t[c+h]=n[u+h]+256-n[u+h-i]&255;if(3==o){for(h=0;h<s;h++)t[c+h]=n[u+h]+256-(n[u+h-i]>>1)&255;for(h=s;h<i;h++)t[c+h]=n[u+h]+256-(n[u+h-i]+n[u+h-s]>>1)&255}if(4==o){for(h=0;h<s;h++)t[c+h]=n[u+h]+256-e(0,n[u+h-i],0)&255;for(h=s;h<i;h++)t[c+h]=n[u+h]+256-e(n[u+h-s],n[u+h-i],n[u+h-s-i])&255}}}function p(t,n){const e=new Uint8Array(t),r=e.slice(0),i=new Uint32Array(r.buffer),s=w(r,n),o=s[0],u=s[1],c=e.length,h=new Uint8Array(c>>2);let a;if(e.length<2e7)for(var l=0;l<c;l+=4)a=y(o,f=e[l]*(1/255),d=e[l+1]*(1/255),v=e[l+2]*(1/255),p=e[l+3]*(1/255)),h[l>>2]=a.ind,i[l>>2]=a.est.rgba;else for(l=0;l<c;l+=4){var f=e[l]*(1/255),d=e[l+1]*(1/255),v=e[l+2]*(1/255),p=e[l+3]*(1/255);for(a=o;a.left;)a=g(a.est,f,d,v,p)<=0?a.left:a.right;h[l>>2]=a.ind,i[l>>2]=a.est.rgba}return{abuf:r.buffer,inds:h,plte:u}}function w(t,n,e){null==e&&(e=1e-4);const r=new Uint32Array(t.buffer),i={i0:0,i1:t.length,bst:null,est:null,tdst:0,left:null,right:null};i.bst=A(t,i.i0,i.i1),i.est=k(i.bst);const s=[i];for(;s.length<n;){let n=0,i=0;for(var o=0;o<s.length;o++)s[o].est.L>n&&(n=s[o].est.L,i=o);if(n<e)break;const u=s[i],c=b(t,r,u.i0,u.i1,u.est.e,u.est.eMq255);if(u.i0>=c||u.i1<=c){u.est.L=0;continue}const h={i0:u.i0,i1:c,bst:null,est:null,tdst:0,left:null,right:null};h.bst=A(t,h.i0,h.i1),h.est=k(h.bst);const a={i0:c,i1:u.i1,bst:null,est:null,tdst:0,left:null,right:null};for(a.bst={R:[],m:[],N:u.bst.N-h.bst.N},o=0;o<16;o++)a.bst.R[o]=u.bst.R[o]-h.bst.R[o];for(o=0;o<4;o++)a.bst.m[o]=u.bst.m[o]-h.bst.m[o];a.est=k(a.bst),u.left=h,u.right=a,s[i]=h,s.push(a)}for(s.sort(((t,n)=>n.bst.N-t.bst.N)),o=0;o<s.length;o++)s[o].ind=o;return[i,s]}function y(t,n,e,r,i){if(null==t.left)return t.tdst=function(t,n,e,r,i){const s=n-t[0],o=e-t[1],u=r-t[2],c=i-t[3];return s*s+o*o+u*u+c*c}(t.est.q,n,e,r,i),t;const s=g(t.est,n,e,r,i);let o=t.left,u=t.right;s>0&&(o=t.right,u=t.left);const c=y(o,n,e,r,i);if(c.tdst<=s*s)return c;const h=y(u,n,e,r,i);return h.tdst<c.tdst?h:c}function g(t,n,e,r,i){const{e:s}=t;return s[0]*n+s[1]*e+s[2]*r+s[3]*i-t.eMq}function b(t,n,e,r,i,s){for(r-=4;e<r;){for(;m(t,e,i)<=s;)e+=4;for(;m(t,r,i)>s;)r-=4;if(e>=r)break;const o=n[e>>2];n[e>>2]=n[r>>2],n[r>>2]=o,e+=4,r-=4}for(;m(t,e,i)>s;)e-=4;return e+4}function m(t,n,e){return t[n]*e[0]+t[n+1]*e[1]+t[n+2]*e[2]+t[n+3]*e[3]}function A(t,n,e){const r=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],i=[0,0,0,0],s=e-n>>2;for(let s=n;s<e;s+=4){const n=t[s]*(1/255),e=t[s+1]*(1/255),o=t[s+2]*(1/255),u=t[s+3]*(1/255);i[0]+=n,i[1]+=e,i[2]+=o,i[3]+=u,r[0]+=n*n,r[1]+=n*e,r[2]+=n*o,r[3]+=n*u,r[5]+=e*e,r[6]+=e*o,r[7]+=e*u,r[10]+=o*o,r[11]+=o*u,r[15]+=u*u}return r[4]=r[1],r[8]=r[2],r[9]=r[6],r[12]=r[3],r[13]=r[7],r[14]=r[11],{R:r,m:i,N:s}}function k(t){const{R:n}=t,{m:e}=t,{N:r}=t,i=e[0],s=e[1],o=e[2],u=e[3],c=0==r?0:1/r,h=[n[0]-i*i*c,n[1]-i*s*c,n[2]-i*o*c,n[3]-i*u*c,n[4]-s*i*c,n[5]-s*s*c,n[6]-s*o*c,n[7]-s*u*c,n[8]-o*i*c,n[9]-o*s*c,n[10]-o*o*c,n[11]-o*u*c,n[12]-u*i*c,n[13]-u*s*c,n[14]-u*o*c,n[15]-u*u*c],a=h,l=x;let f=[Math.random(),Math.random(),Math.random(),Math.random()],d=0,v=0;if(0!=r)for(let t=0;t<16&&(f=l.multVec(a,f),v=Math.sqrt(l.dot(f,f)),f=l.sml(1/v,f),!(0!=t&&Math.abs(v-d)<1e-9));t++)d=v;const p=[i*c,s*c,o*c,u*c];return{Cov:h,q:p,e:f,L:d,eMq255:l.dot(l.sml(255,p),f),eMq:l.dot(f,p),rgba:(Math.round(255*p[3])<<24|Math.round(255*p[2])<<16|Math.round(255*p[1])<<8|Math.round(255*p[0]))>>>0}}var x={multVec:(t,n)=>[t[0]*n[0]+t[1]*n[1]+t[2]*n[2]+t[3]*n[3],t[4]*n[0]+t[5]*n[1]+t[6]*n[2]+t[7]*n[3],t[8]*n[0]+t[9]*n[1]+t[10]*n[2]+t[11]*n[3],t[12]*n[0]+t[13]*n[1]+t[14]*n[2]+t[15]*n[3]],dot:(t,n)=>t[0]*n[0]+t[1]*n[1]+t[2]*n[2]+t[3]*n[3],sml:(t,n)=>[t*n[0],t*n[1],t*n[2],t*n[3]]};F.encode=function(t,n,e,r,i,s,o){null==r&&(r=0),null==o&&(o=!1);const u=a(t,n,e,r,[!1,!1,!1,0,o,!1]);return h(u,-1),c(u,n,e,i,s)},F.encodeLL=function(t,n,e,r,i,s,o,u){const a={ctype:0+(1==r?0:2)+(0==i?0:4),depth:s,frames:[]},l=(r+i)*s,f=l*n;for(let r=0;r<t.length;r++)a.frames.push({rect:{x:0,y:0,width:n,height:e},img:new Uint8Array(t[r]),blend:0,dispose:1,bpp:Math.ceil(l/8),bpl:Math.ceil(f/8)});return h(a,0,!0),c(a,n,e,o,u)},F.encode.compress=a,F.encode.dither=u,F.quantize=p,F.quantize.getKDtree=w,F.quantize.getNearest=y}();const N={toArrayBuffer(t,n){const e=t.width,r=t.height,i=e<<2,s=t.getContext("2d").getImageData(0,0,e,r),o=new Uint32Array(s.data.buffer),u=(32*e+31)/32<<2,c=u*r,h=122+c,a=new ArrayBuffer(h),l=new DataView(a),f=1<<20;let d,v,p,w,y=f,g=0,b=0,m=0;function A(t){l.setUint16(b,t,!0),b+=2}function k(t){l.setUint32(b,t,!0),b+=4}function x(t){b+=t}A(19778),k(h),x(4),k(122),k(108),k(e),k(-r>>>0),A(1),A(32),k(3),k(c),k(2835),k(2835),x(8),k(16711680),k(65280),k(255),k(4278190080),k(1466527264),function t(){for(;g<r&&y>0;){for(w=122+g*u,d=0;d<i;)y--,v=o[m++],p=v>>>24,l.setUint32(w+d,v<<8|p),d+=4;g++}m<o.length?(y=f,setTimeout(t,N._dly)):n(a)}()},toBlob(t,n){this.toArrayBuffer(t,(t=>{n(new Blob([t],{type:"image/bmp"}))}))},_dly:9};var K={CHROME:"CHROME",FIREFOX:"FIREFOX",DESKTOP_SAFARI:"DESKTOP_SAFARI",IE:"IE",IOS:"IOS",ETC:"ETC"},Q={[K.CHROME]:16384,[K.FIREFOX]:11180,[K.DESKTOP_SAFARI]:16384,[K.IE]:8192,[K.IOS]:4096,[K.ETC]:8192};const Y="undefined"!=typeof window,H="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope,V=Y&&window.cordova&&window.cordova.require&&window.cordova.require("cordova/modulemapper"),X=(Y||H)&&(V&&V.getOriginalSymbol(window,"File")||"undefined"!=typeof File&&File),q=(Y||H)&&(V&&V.getOriginalSymbol(window,"FileReader")||"undefined"!=typeof FileReader&&FileReader);function G(t,n,e=Date.now()){return new Promise((r=>{const i=t.split(","),s=i[0].match(/:(.*?);/)[1],o=globalThis.atob(i[1]);let u=o.length;const c=new Uint8Array(u);for(;u--;)c[u]=o.charCodeAt(u);const h=new Blob([c],{type:s});h.name=n,h.lastModified=e,r(h)}))}function J(t){return new Promise(((n,e)=>{const r=new q;r.onload=()=>n(r.result),r.onerror=t=>e(t),r.readAsDataURL(t)}))}function Z(t){return new Promise(((n,e)=>{const r=new Image;r.onload=()=>n(r),r.onerror=t=>e(t),r.src=t}))}function tt(){if(void 0!==tt.cachedResult)return tt.cachedResult;let t=K.ETC;const{userAgent:n}=navigator;return/Chrom(e|ium)/i.test(n)?t=K.CHROME:/iP(ad|od|hone)/i.test(n)&&/WebKit/i.test(n)?t=K.IOS:/Safari/i.test(n)?t=K.DESKTOP_SAFARI:/Firefox/i.test(n)?t=K.FIREFOX:(/MSIE/i.test(n)||1==!!document.documentMode)&&(t=K.IE),tt.cachedResult=t}function nt(t,n){const e=tt(),r=Q[e];let i=t,s=n,o=i*s;const u=i>s?s/i:i/s;for(;o>r*r;){const t=(r+i)/2,n=(r+s)/2;t<n?(s=n,i=n*u):(s=t*u,i=t),o=i*s}return{width:i,height:s}}function et(t,n){let e,r;try{if(e=new OffscreenCanvas(t,n),r=e.getContext("2d"),null===r)throw new Error("getContext of OffscreenCanvas returns null")}catch(t){e=document.createElement("canvas"),r=e.getContext("2d")}return e.width=t,e.height=n,[e,r]}function rt(t,n){const{width:e,height:r}=nt(t.width,t.height),[i,s]=et(e,r);return n&&/jpe?g/.test(n)&&(s.fillStyle="white",s.fillRect(0,0,i.width,i.height)),s.drawImage(t,0,0,i.width,i.height),i}function it(){return void 0!==it.cachedResult||(it.cachedResult=["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"undefined"!=typeof document&&"ontouchend"in document),it.cachedResult}function st(t,n={}){return new Promise((function(e,r){let i,s;var o=function(){try{return s=rt(i,n.fileType||t.type),e([i,s])}catch(t){return r(t)}},u=function(){try{var n=function(t){try{throw t}catch(t){return r(t)}};try{let e;return J(t).then((function(t){try{return e=t,Z(e).then((function(t){try{return i=t,function(){try{return o()}catch(t){return r(t)}}()}catch(t){return n(t)}}),n)}catch(t){return n(t)}}),n)}catch(t){n(t)}}catch(t){return r(t)}};try{if(it()||[K.DESKTOP_SAFARI,K.MOBILE_SAFARI].includes(tt()))throw new Error("Skip createImageBitmap on IOS and Safari");return createImageBitmap(t).then((function(t){try{return i=t,o()}catch(t){return u()}}),u)}catch(t){u()}}))}function ot(t,n,e,r,i=1){return new Promise((function(s,o){let u;if("image/png"===n){let h,a,l;return h=t.getContext("2d"),({data:a}=h.getImageData(0,0,t.width,t.height)),l=F.encode([a.buffer],t.width,t.height,4096*i),u=new Blob([l],{type:n}),u.name=e,u.lastModified=r,c.call(this)}{if("image/bmp"===n)return new Promise((n=>N.toBlob(t,n))).then(function(t){try{return u=t,u.name=e,u.lastModified=r,f.call(this)}catch(t){return o(t)}}.bind(this),o);{if("function"==typeof OffscreenCanvas&&t instanceof OffscreenCanvas)return t.convertToBlob({type:n,quality:i}).then(function(t){try{return u=t,u.name=e,u.lastModified=r,d.call(this)}catch(t){return o(t)}}.bind(this),o);{let v;return v=t.toDataURL(n,i),G(v,e,r).then(function(t){try{return u=t,d.call(this)}catch(t){return o(t)}}.bind(this),o)}function d(){return f.call(this)}}function f(){return c.call(this)}}function c(){return s(u)}}))}function ut(t){t.width=0,t.height=0}function ct(){return new Promise((function(t,n){let e,r,i,s;return void 0!==ct.cachedResult?t(ct.cachedResult):G("data:image/jpeg;base64,/9j/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAYAAAAAAAD/2wCEAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/AABEIAAEAAgMBEQACEQEDEQH/xABKAAEAAAAAAAAAAAAAAAAAAAALEAEAAAAAAAAAAAAAAAAAAAAAAQEAAAAAAAAAAAAAAAAAAAAAEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwA/8H//2Q==","test.jpg",Date.now()).then((function(o){try{return e=o,st(e).then((function(o){try{return r=o[1],ot(r,e.type,e.name,e.lastModified).then((function(e){try{return i=e,ut(r),st(i).then((function(e){try{return s=e[0],t(ct.cachedResult=1===s.width&&2===s.height)}catch(t){return n(t)}}),n)}catch(t){return n(t)}}),n)}catch(t){return n(t)}}),n)}catch(t){return n(t)}}),n)}))}function ht(t){return new Promise(((n,e)=>{const r=new q;r.onload=t=>{const e=new DataView(t.target.result);if(65496!=e.getUint16(0,!1))return n(-2);const r=e.byteLength;let i=2;for(;i<r;){if(e.getUint16(i+2,!1)<=8)return n(-1);const t=e.getUint16(i,!1);if(i+=2,65505==t){if(1165519206!=e.getUint32(i+=2,!1))return n(-1);const t=18761==e.getUint16(i+=6,!1);i+=e.getUint32(i+4,t);const r=e.getUint16(i,t);i+=2;for(let s=0;s<r;s++)if(274==e.getUint16(i+12*s,t))return n(e.getUint16(i+12*s+8,t))}else{if(65280&~t)break;i+=e.getUint16(i,!1)}}return n(-1)},r.onerror=t=>e(t),r.readAsArrayBuffer(t)}))}function at(t,n){const{width:e}=t,{height:r}=t,{maxWidthOrHeight:i}=n;let s,o=t;return isFinite(i)&&(e>i||r>i)&&([o,s]=et(e,r),e>r?(o.width=i,o.height=r/e*i):(o.width=e/r*i,o.height=i),s.drawImage(t,0,0,o.width,o.height),ut(t)),o}function lt(t,n){const{width:e}=t,{height:r}=t,[i,s]=et(e,r);switch(n>4&&n<9?(i.width=r,i.height=e):(i.width=e,i.height=r),n){case 2:s.transform(-1,0,0,1,e,0);break;case 3:s.transform(-1,0,0,-1,e,r);break;case 4:s.transform(1,0,0,-1,0,r);break;case 5:s.transform(0,1,1,0,0,0);break;case 6:s.transform(0,1,-1,0,r,0);break;case 7:s.transform(0,-1,-1,0,r,e);break;case 8:s.transform(0,-1,1,0,0,e)}return s.drawImage(t,0,0,e,r),ut(t),i}function ft(t,n,e=0){return new Promise((function(r,i){let s,o,u,c,h,a,l,f,d,v,p,w,y,g,b,m,A,k,x,M;function S(t=5){if(n.signal&&n.signal.aborted)throw n.signal.reason;s+=t,n.onProgress(Math.min(s,100))}function C(t){if(n.signal&&n.signal.aborted)throw n.signal.reason;s=Math.min(Math.max(t,s),100),n.onProgress(s)}return s=e,o=n.maxIteration||10,u=1024*n.maxSizeMB*1024,S(),st(t,n).then(function(e){try{return[,c]=e,S(),h=at(c,n),S(),new Promise((function(e,r){var i;if(!(i=n.exifOrientation))return ht(t).then(function(t){try{return i=t,s.call(this)}catch(t){return r(t)}}.bind(this),r);function s(){return e(i)}return s.call(this)})).then(function(e){try{return a=e,S(),ct().then(function(e){try{return l=e?h:lt(h,a),S(),f=n.initialQuality||1,d=n.fileType||t.type,ot(l,d,t.name,t.lastModified,f).then(function(e){try{{if(v=e,S(),p=v.size>u,w=v.size>t.size,!p&&!w)return C(100),r(v);var s;function a(){if(o--&&(b>u||b>y)){let n,e;return n=M?.95*x.width:x.width,e=M?.95*x.height:x.height,[A,k]=et(n,e),k.drawImage(x,0,0,n,e),f*="image/png"===d?.85:.95,ot(A,d,t.name,t.lastModified,f).then((function(t){try{return m=t,ut(x),x=A,b=m.size,C(Math.min(99,Math.floor((g-b)/(g-u)*100))),a}catch(t){return i(t)}}),i)}return[1]}return y=t.size,g=v.size,b=g,x=l,M=!n.alwaysKeepResolution&&p,(s=function(t){for(;t;){if(t.then)return void t.then(s,i);try{if(t.pop){if(t.length)return t.pop()?U.call(this):t;t=a}else t=t.call(this)}catch(t){return i(t)}}}.bind(this))(a);function U(){return ut(x),ut(A),ut(h),ut(l),ut(c),C(100),r(m)}}}catch(E){return i(E)}}.bind(this),i)}catch(t){return i(t)}}.bind(this),i)}catch(t){return i(t)}}.bind(this),i)}catch(t){return i(t)}}.bind(this),i)}))}let dt;function vt(t,n){return new Promise(((e,r)=>{dt||(dt=function(){const t=[];return t.push("\nlet scriptImported = false\nself.addEventListener('message', async (e) => {\n const { file, id, imageCompressionLibUrl, options } = e.data\n options.onProgress = (progress) => self.postMessage({ progress, id })\n try {\n if (!scriptImported) {\n // console.log('[worker] importScripts', imageCompressionLibUrl)\n self.importScripts(imageCompressionLibUrl)\n scriptImported = true\n }\n // console.log('[worker] self', self)\n const compressedFile = await imageCompression(file, options)\n self.postMessage({ file: compressedFile, id })\n } catch (e) {\n // console.error('[worker] error', e)\n self.postMessage({ error: e.message + '\\n' + e.stack, id })\n }\n})\n"),URL.createObjectURL(new Blob(t))}());const i=new Worker(dt);i.addEventListener("message",(function(t){if(n.signal&&n.signal.aborted)i.terminate();else if(void 0===t.data.progress){if(t.data.error)return r(new Error(t.data.error)),void i.terminate();e(t.data.file),i.terminate()}else n.onProgress(t.data.progress)})),i.addEventListener("error",r),n.signal&&n.signal.addEventListener("abort",(()=>{r(n.signal.reason),i.terminate()})),i.postMessage({file:t,imageCompressionLibUrl:n.libURL,options:{...n,onProgress:void 0,signal:void 0}})}))}function pt(t,n){return new Promise((function(e,r){let i,s,o,u,c,h;if(i={...n},o=0,({onProgress:u}=i),i.maxSizeMB=i.maxSizeMB||Number.POSITIVE_INFINITY,c="boolean"!=typeof i.useWebWorker||i.useWebWorker,delete i.useWebWorker,i.onProgress=t=>{o=t,"function"==typeof u&&u(o)},!(t instanceof Blob||t instanceof X))return r(new Error("The file given is not an instance of Blob or File"));if(!/^image/.test(t.type))return r(new Error("The file given is not an image"));if(h="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope,!c||"function"!=typeof Worker||h)return ft(t,i).then(function(t){try{return s=t,f.call(this)}catch(t){return r(t)}}.bind(this),r);var a=function(){try{return f.call(this)}catch(t){return r(t)}}.bind(this),l=function(){try{return ft(t,i).then((function(t){try{return s=t,a()}catch(t){return r(t)}}),r)}catch(t){return r(t)}};try{return i.libURL=i.libURL||"https://cdn.jsdelivr.net/npm/browser-image-compression@2.0.2/dist/browser-image-compression.js",vt(t,i).then((function(t){try{return s=t,a()}catch(t){return l()}}),l)}catch(t){l()}function f(){try{s.name=t.name,s.lastModified=t.lastModified}catch(t){}try{i.preserveExif&&"image/jpeg"===t.type&&(!i.fileType||i.fileType&&i.fileType===t.type)&&(s=P(t,s))}catch(t){}return e(s)}}))}pt.getDataUrlFromFile=J,pt.getFilefromDataUrl=G,pt.loadImage=Z,pt.drawImageInCanvas=rt,pt.drawFileInCanvas=st,pt.canvasToFile=ot,pt.getExifOrientation=ht,pt.handleMaxWidthOrHeight=at,pt.followExifOrientation=lt,pt.cleanupCanvasMemory=ut,pt.isAutoOrientationInBrowser=ct,pt.approximateBelowMaximumCanvasSizeOfBrowser=nt,pt.copyExifWithoutOrientation=P,pt.getBrowserName=tt,pt.version="2.0.2";class wt extends c{fileInput=null;maxCompressionSize=300;constructor(t){super(t),this.setupFileInput()}onActivate(){this.openFilePicker()}openFilePicker(){this._core.store.isDisabled||this.fileInput.click()}setupFileInput(){this.fileInput=document.createElement("input"),this.fileInput.type="file",this.fileInput.accept="image/*",this.fileInput.style.display="none",this.fileInput.addEventListener("change",this.handleFileSelect.bind(this)),this.fileInput.addEventListener("cancel",this.handleCancel.bind(this)),document.body.appendChild(this.fileInput)}handleFileSelect(t){const n=t.target;n.files&&n.files[0]?pt(n.files[0],{maxWidthOrHeight:this.maxCompressionSize}).then((t=>{this.readFile(t)})).catch((t=>{console.error("Error during image compression or processing:",t),this.handleCancel()})):(console.info("File selection cancelled by user."),this.handleCancel()),n&&(n.value="")}readFile(t){const n=new FileReader;n.onload=t=>{const n=new Image;n.src=t.target?.result,n.onload=()=>this.createKritzelImage(n)},n.readAsDataURL(t)}createKritzelImage(t){const n=$.create(this._core),{scaledWidth:e,scaledHeight:r}=n.calculateScaledDimensions(t);return n.src=t.src,n.width=e,n.height=r,n.zIndex=this._core.store.currentZIndex,n.centerInViewport(),this.addImageToStore(n),n}addImageToStore(t){this._core.addObject(t),this._core.store.setState("activeTool",a.getTool("selection")),this._core.selectObjects([t]),this._core.engine.emitObjectsChange()}handleCancel(){this._core.store.setState("activeTool",a.getTool("selection"))}}class yt{static _pointerCursor=null;static getPointerCursor(){return this._pointerCursor||(this._pointerCursor=this.getCursor({iconName:"pointer"})),this._pointerCursor}static getCursor(t){const n="default"===t.iconName?"mouse-pointer":t.iconName,e=j.get(n);if(!e)return console.warn(`Icon "${n}" not found in registry.`),"auto";const r=t.size||24,i=t.rotation||0,s=t.color||"black",o=t.hotspot||("default"===t.iconName?{x:4,y:4}:{x:r/2,y:r/2});let u=e.replace(/width="\d+"/,`width="${r}"`).replace(/height="\d+"/,`height="${r}"`).replace(/currentColor/g,s);const c=r/2;return`url('data:image/svg+xml;charset=utf-8,${encodeURIComponent(`\n <svg xmlns="http://www.w3.org/2000/svg" width="${r}" height="${r}" viewBox="0 0 ${r} ${r}">\n <g transform="rotate(${i} ${c} ${c})">\n ${u}\n </g>\n </svg>\n `.replace(/\s+/g," ").trim()).replace(/'/g,"%27").replace(/"/g,"%22")}') ${o.x} ${o.y}, auto`}}const gt=()=>new Map,bt=t=>{const n=gt();return t.forEach(((t,e)=>{n.set(e,t)})),n},mt=(t,n,e)=>{let r=t.get(n);return void 0===r&&t.set(n,r=e()),r},At=()=>new Set,kt=t=>t[t.length-1],xt=(t,n)=>{for(let e=0;e<n.length;e++)t.push(n[e])},Mt=Array.from,St=(t,n)=>{for(let e=0;e<t.length;e++)if(!n(t[e],e,t))return!1;return!0},Ct=(t,n)=>{for(let e=0;e<t.length;e++)if(n(t[e],e,t))return!0;return!1},Ut=Array.isArray;class Et{constructor(){this._observers=gt()}on(t,n){return mt(this._observers,t,At).add(n),n}once(t,n){const e=(...r)=>{this.off(t,e),n(...r)};this.on(t,e)}off(t,n){const e=this._observers.get(t);void 0!==e&&(e.delete(n),0===e.size&&this._observers.delete(t))}emit(t,n){return Mt((this._observers.get(t)||gt()).values()).forEach((t=>t(...n)))}destroy(){this._observers=gt()}}let jt=class{constructor(){this._observers=gt()}on(t,n){mt(this._observers,t,At).add(n)}once(t,n){const e=(...r)=>{this.off(t,e),n(...r)};this.on(t,e)}off(t,n){const e=this._observers.get(t);void 0!==e&&(e.delete(n),0===e.size&&this._observers.delete(t))}emit(t,n){return Mt((this._observers.get(t)||gt()).values()).forEach((t=>t(...n)))}destroy(){this._observers=gt()}};const Tt=Math.floor,It=Math.abs,_t=(t,n)=>t<n?t:n,Ot=(t,n)=>t>n?t:n,zt=Math.pow,$t=t=>0!==t?t<0:1/t<0,Dt=64,Pt=128,Rt=127,Bt=Number.MAX_SAFE_INTEGER,Wt=Number.MIN_SAFE_INTEGER,Lt=Number.isInteger||(t=>"number"==typeof t&&isFinite(t)&&Tt(t)===t),Ft=String.fromCharCode,Nt=/^\s*/g,Kt=/([A-Z])/g,Qt=(t,n)=>(t=>t.replace(Nt,""))(t.replace(Kt,(t=>`${n}${(t=>t.toLowerCase())(t)}`))),Yt="undefined"!=typeof TextEncoder?new TextEncoder:null,Ht=Yt?t=>Yt.encode(t):t=>{const n=unescape(encodeURIComponent(t)),e=n.length,r=new Uint8Array(e);for(let t=0;t<e;t++)r[t]=n.codePointAt(t);return r};let Vt="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});Vt&&1===Vt.decode(new Uint8Array).length&&(Vt=null);let Xt=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}};const qt=()=>new Xt,Gt=t=>{let n=t.cpos;for(let e=0;e<t.bufs.length;e++)n+=t.bufs[e].length;return n},Jt=t=>{const n=new Uint8Array(Gt(t));let e=0;for(let r=0;r<t.bufs.length;r++){const i=t.bufs[r];n.set(i,e),e+=i.length}return n.set(new Uint8Array(t.cbuf.buffer,0,t.cpos),e),n},Zt=(t,n)=>{const e=t.cbuf.length;t.cpos===e&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(2*e),t.cpos=0),t.cbuf[t.cpos++]=n},tn=Zt,nn=(t,n)=>{for(;n>Rt;)Zt(t,Pt|Rt&n),n=Tt(n/128);Zt(t,Rt&n)},en=(t,n)=>{const e=$t(n);for(e&&(n=-n),Zt(t,(n>63?Pt:0)|(e?Dt:0)|63&n),n=Tt(n/64);n>0;)Zt(t,(n>Rt?Pt:0)|Rt&n),n=Tt(n/128)},rn=new Uint8Array(3e4),sn=rn.length/3,on=Yt&&Yt.encodeInto?(t,n)=>{if(n.length<sn){const e=Yt.encodeInto(n,rn).written||0;nn(t,e);for(let n=0;n<e;n++)Zt(t,rn[n])}else cn(t,Ht(n))}:(t,n)=>{const e=unescape(encodeURIComponent(n)),r=e.length;nn(t,r);for(let n=0;n<r;n++)Zt(t,e.codePointAt(n))},un=(t,n)=>{const e=t.cbuf.length,r=t.cpos,i=_t(e-r,n.length),s=n.length-i;t.cbuf.set(n.subarray(0,i),r),t.cpos+=i,s>0&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(Ot(2*e,s)),t.cbuf.set(n.subarray(i)),t.cpos=s)},cn=(t,n)=>{nn(t,n.byteLength),un(t,n)},hn=(t,n)=>{((t,n)=>{const e=t.cbuf.length;e-t.cpos<n&&(t.bufs.push(new Uint8Array(t.cbuf.buffer,0,t.cpos)),t.cbuf=new Uint8Array(2*Ot(e,n)),t.cpos=0)})(t,n);const e=new DataView(t.cbuf.buffer,t.cpos,n);return t.cpos+=n,e},an=new DataView(new ArrayBuffer(4)),ln=(t,n)=>{switch(typeof n){case"string":Zt(t,119),on(t,n);break;case"number":Lt(n)&&It(n)<=2147483647?(Zt(t,125),en(t,n)):(an.setFloat32(0,e=n),an.getFloat32(0)===e?(Zt(t,124),((t,n)=>{hn(t,4).setFloat32(0,n,!1)})(t,n)):(Zt(t,123),((t,n)=>{hn(t,8).setFloat64(0,n,!1)})(t,n)));break;case"bigint":Zt(t,122),((t,n)=>{hn(t,8).setBigInt64(0,n,!1)})(t,n);break;case"object":if(null===n)Zt(t,126);else if(Ut(n)){Zt(t,117),nn(t,n.length);for(let e=0;e<n.length;e++)ln(t,n[e])}else if(n instanceof Uint8Array)Zt(t,116),cn(t,n);else{Zt(t,118);const e=Object.keys(n);nn(t,e.length);for(let r=0;r<e.length;r++){const i=e[r];on(t,i),ln(t,n[i])}}break;case"boolean":Zt(t,n?120:121);break;default:Zt(t,127)}var e};class fn extends Xt{constructor(t){super(),this.w=t,this.s=null,this.count=0}write(t){this.s===t?this.count++:(this.count>0&&nn(this,this.count-1),this.count=1,this.w(this,t),this.s=t)}}const dn=t=>{t.count>0&&(en(t.encoder,1===t.count?t.s:-t.s),t.count>1&&nn(t.encoder,t.count-2))};class vn{constructor(){this.encoder=new Xt,this.s=0,this.count=0}write(t){this.s===t?this.count++:(dn(this),this.count=1,this.s=t)}toUint8Array(){return dn(this),Jt(this.encoder)}}const pn=t=>{t.count>0&&(en(t.encoder,2*t.diff+(1===t.count?0:1)),t.count>1&&nn(t.encoder,t.count-2))};class wn{constructor(){this.encoder=new Xt,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(pn(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return pn(this),Jt(this.encoder)}}class yn{constructor(){this.sarr=[],this.s="",this.lensE=new vn}write(t){this.s+=t,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(t.length)}toUint8Array(){const t=new Xt;return this.sarr.push(this.s),this.s="",on(t,this.sarr.join("")),un(t,this.lensE.toUint8Array()),Jt(t)}}const gn=t=>new Error(t),bn=()=>{throw gn("Method unimplemented")},mn=()=>{throw gn("Unexpected case")},An=gn("Unexpected end of array"),kn=gn("Integer out of Range");let xn=class{constructor(t){this.arr=t,this.pos=0}};const Mn=t=>new xn(t),Sn=t=>((t,n)=>{const e=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,n);return t.pos+=n,e})(t,Un(t)),Cn=t=>t.arr[t.pos++],Un=t=>{let n=0,e=1;const r=t.arr.length;for(;t.pos<r;){const r=t.arr[t.pos++];if(n+=(r&Rt)*e,e*=128,r<Pt)return n;if(n>Bt)throw kn}throw An},En=t=>{let n=t.arr[t.pos++],e=63&n,r=64;const i=(n&Dt)>0?-1:1;if(!(n&Pt))return i*e;const s=t.arr.length;for(;t.pos<s;){if(n=t.arr[t.pos++],e+=(n&Rt)*r,r*=128,n<Pt)return i*e;if(e>Bt)throw kn}throw An},jn=Vt?t=>Vt.decode(Sn(t)):t=>{let n=Un(t);if(0===n)return"";{let e=String.fromCodePoint(Cn(t));if(--n<100)for(;n--;)e+=String.fromCodePoint(Cn(t));else for(;n>0;){const r=n<1e4?n:1e4,i=t.arr.subarray(t.pos,t.pos+r);t.pos+=r,e+=String.fromCodePoint.apply(null,i),n-=r}return decodeURIComponent(escape(e))}},Tn=(t,n)=>{const e=new DataView(t.arr.buffer,t.arr.byteOffset+t.pos,n);return t.pos+=n,e},In=[()=>{},()=>null,En,t=>Tn(t,4).getFloat32(0,!1),t=>Tn(t,8).getFloat64(0,!1),t=>Tn(t,8).getBigInt64(0,!1),()=>!1,()=>!0,jn,t=>{const n=Un(t),e={};for(let r=0;r<n;r++)e[jn(t)]=_n(t);return e},t=>{const n=Un(t),e=[];for(let r=0;r<n;r++)e.push(_n(t));return e},Sn],_n=t=>In[127-Cn(t)](t);class On extends xn{constructor(t,n){super(t),this.reader=n,this.s=null,this.count=0}read(){return 0===this.count&&(this.s=this.reader(this),this.count=this.pos!==this.arr.length?Un(this)+1:-1),this.count--,this.s}}class zn extends xn{constructor(t){super(t),this.s=0,this.count=0}read(){if(0===this.count){this.s=En(this);const t=$t(this.s);this.count=1,t&&(this.s=-this.s,this.count=Un(this)+2)}return this.count--,this.s}}class $n extends xn{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(0===this.count){const t=En(this),n=1&t;this.diff=Tt(t/2),this.count=1,n&&(this.count=Un(this)+2)}return this.s+=this.diff,this.count--,this.s}}class Dn{constructor(t){this.decoder=new zn(t),this.str=jn(this.decoder),this.spos=0}read(){const t=this.spos+this.decoder.read(),n=this.str.slice(this.spos,t);return this.spos=t,n}}const Pn=crypto.getRandomValues.bind(crypto),Rn=()=>Pn(new Uint32Array(1))[0],Bn=[1e7]+-1e3+-4e3+-8e3+-1e11,Wn=()=>Bn.replace(/[018]/g,(t=>(t^Rn()&15>>t/4).toString(16))),Ln=Date.now,Fn=t=>new Promise(t);Promise.all.bind(Promise);let Nn=new class{constructor(){this.map=new Map}setItem(t,n){this.map.set(t,n)}getItem(t){return this.map.get(t)}},Kn=!0;try{"undefined"!=typeof localStorage&&localStorage&&(Nn=localStorage,Kn=!1)}catch(B){}const Qn=Nn,Yn=t=>Kn||addEventListener("storage",t),Hn=t=>Kn||removeEventListener("storage",t),Vn=Symbol("Equality"),Xn=(t,n)=>t===n||!!t?.[Vn]?.(n)||!1,qn=Object.assign,Gn=Object.keys,Jn=(t,n)=>{const e=[];for(const r in t)e.push(n(t[r],r));return e},Zn=t=>Gn(t).length,te=(t,n)=>{for(const e in t)if(!n(t[e],e))return!1;return!0},ne=(t,n)=>Object.prototype.hasOwnProperty.call(t,n),ee=Object.freeze,re=t=>{for(const n in t){const e=t[n];"object"!=typeof e&&"function"!=typeof e||re(t[n])}return ee(t)},ie=(t,n,e=0)=>{try{for(;e<t.length;e++)t[e](...n)}finally{e<t.length&&ie(t,n,e+1)}},se=t=>t,oe=(t,n)=>{if(t===n)return!0;if(null==t||null==n||t.constructor!==n.constructor&&(t.constructor||Object)!==(n.constructor||Object))return!1;if(null!=t[Vn])return t[Vn](n);switch(t.constructor){case ArrayBuffer:t=new Uint8Array(t),n=new Uint8Array(n);case Uint8Array:if(t.byteLength!==n.byteLength)return!1;for(let e=0;e<t.length;e++)if(t[e]!==n[e])return!1;break;case Set:if(t.size!==n.size)return!1;for(const e of t)if(!n.has(e))return!1;break;case Map:if(t.size!==n.size)return!1;for(const e of t.keys())if(!n.has(e)||!oe(t.get(e),n.get(e)))return!1;break;case void 0:case Object:if(Zn(t)!==Zn(n))return!1;for(const e in t)if(!ne(t,e)||!oe(t[e],n[e]))return!1;break;case Array:if(t.length!==n.length)return!1;for(let e=0;e<t.length;e++)if(!oe(t[e],n[e]))return!1;break;default:return!1}return!0},ue="undefined"!=typeof process&&process.release&&/node|io\.js/.test(process.release.name)&&"[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),ce="undefined"!=typeof window&&"undefined"!=typeof document&&!ue;let he;const ae=t=>(()=>{if(void 0===he)if(ue){he=gt();const t=process.argv;let n=null;for(let e=0;e<t.length;e++){const r=t[e];"-"===r[0]?(null!==n&&he.set(n,""),n=r):null!==n&&(he.set(n,r),n=null)}null!==n&&he.set(n,"")}else"object"==typeof location?(he=gt(),(location.search||"?").slice(1).split("&").forEach((t=>{if(0!==t.length){const[n,e]=t.split("=");he.set(`--${Qt(n,"-")}`,e),he.set(`-${Qt(n,"-")}`,e)}}))):he=gt();return he})().has(t),le=t=>{return void 0===(n=ue?process.env[t.toUpperCase().replaceAll("-","_")]:Qn.getItem(t))?null:n;var n},fe=t=>ae("--"+t)||null!==le(t),de=fe("production");var ve;const pe=ue&&(ve=process.env.FORCE_COLOR,["true","1","2"].includes(ve))||!ae("--no-colors")&&!fe("no-color")&&(!ue||process.stdout.isTTY)&&(!ue||ae("--color")||null!==le("COLORTERM")||(le("TERM")||"").includes("color")),we=t=>new Uint8Array(t),ye=t=>new Uint8Array(t),ge=ce?t=>{let n="";for(let e=0;e<t.byteLength;e++)n+=Ft(t[e]);return btoa(n)}:t=>Buffer.from(t.buffer,t.byteOffset,t.byteLength).toString("base64"),be=ce?t=>{const n=atob(t),e=we(n.length);for(let t=0;t<n.length;t++)e[t]=n.charCodeAt(t);return e}:t=>{const n=Buffer.from(t,"base64");return((t,n,e)=>new Uint8Array(t,n,e))(n.buffer,n.byteOffset,n.byteLength)};class me{constructor(t,n){this.left=t,this.right=n}}const Ae=(t,n)=>new me(t,n),ke=t=>t.next()>=.5,xe=(t,n,e)=>Tt(t.next()*(e+1-n)+n),Me=(t,n,e)=>Tt(t.next()*(e+1-n)+n),Se=(t,n,e)=>Me(t,n,e),Ce=t=>Ft(Se(t,97,122)),Ue=(t,n)=>n[Se(t,0,n.length-1)],Ee=Symbol("0schema");class je{constructor(){this._rerrs=[]}extend(t,n,e,r=null){this._rerrs.push({path:t,expected:n,has:e,message:r})}toString(){const t=[];for(let e=this._rerrs.length-1;e>0;e--){const r=this._rerrs[e];t.push((n=" ",(t=>{const e=new Array(t);for(let r=0;r<t;r++)e[r]=n;return e})(2*(this._rerrs.length-e)).join("")+`${null!=r.path?`[${r.path}] `:""}${r.has} doesn't match ${r.expected}. ${r.message}`))}var n;return t.join("\n")}}const Te=(t,n)=>t===n||null!=t&&null!=n&&t.constructor===n.constructor&&(t[Vn]?Xn(t,n):Ut(t)?St(t,(t=>Ct(n,(n=>Te(t,n))))):!!(t=>"object"==typeof t)(t)&&te(t,((t,e)=>Te(t,n[e]))));class Ie{static _dilutes=!1;extends(t){let[n,e]=[this.shape,t.shape];return this.constructor._dilutes&&([e,n]=[n,e]),Te(n,e)}equals(t){return this.constructor===t.constructor&&oe(this.shape,t.shape)}[Ee](){return!0}[Vn](t){return this.equals(t)}validate(t){return this.check(t)}check(t,n){bn()}get nullable(){return or(this,Ar)}get optional(){return new Fe(this)}cast(t){return Sr(t,this),t}expect(t){return Sr(t,this),t}}class _e extends Ie{constructor(t,n){super(),this.shape=t,this._c=n}check(t,n){const e=t?.constructor===this.shape&&(null==this._c||this._c(t));return!e&&n?.extend(null,this.shape.name,t?.constructor.name,t?.constructor!==this.shape?"Constructor match failed":"Check failed"),e}}const Oe=(t,n=null)=>new _e(t,n);Oe(_e);class ze extends Ie{constructor(t){super(),this.shape=t}check(t,n){const e=this.shape(t);return!e&&n?.extend(null,"custom prop",t?.constructor.name,"failed to check custom prop"),e}}const $e=t=>new ze(t);Oe(ze);class De extends Ie{constructor(t){super(),this.shape=t}check(t,n){const e=this.shape.some((n=>n===t));return!e&&n?.extend(null,this.shape.join(" | "),t.toString()),e}}const Pe=(...t)=>new De(t),Re=Oe(De),Be=RegExp.escape||(t=>t.replace(/[().|&,$^[\]]/g,(t=>"\\"+t))),We=t=>wr.check(t)?[Be(t)]:Re.check(t)?t.shape.map((t=>t+"")):pr.check(t)?["[+-]?\\d+.?\\d*"]:yr.check(t)?[".*"]:ur.check(t)?t.shape.map(We).flat(1):void mn();Oe(class extends Ie{constructor(t){super(),this.shape=t,this._r=new RegExp("^"+t.map(We).map((t=>`(${t.join("|")})`)).join("")+"$")}check(t,n){const e=null!=this._r.exec(t);return!e&&n?.extend(null,this._r.toString(),t.toString(),"String doesn't match string template."),e}});const Le=Symbol("optional");class Fe extends Ie{constructor(t){super(),this.shape=t}check(t,n){const e=void 0===t||this.shape.check(t);return!e&&n?.extend(null,"undefined (optional)","()"),e}get[Le](){return!0}}const Ne=Oe(Fe);Oe(class extends Ie{check(t,n){return n?.extend(null,"never",typeof t),!1}});class Ke extends Ie{constructor(t,n=!1){super(),this.shape=t,this._isPartial=n}static _dilutes=!0;get partial(){return new Ke(this.shape,!0)}check(t,n){return null==t?(n?.extend(null,"object","null"),!1):te(this.shape,((e,r)=>{const i=this._isPartial&&!ne(t,r)||e.check(t[r],n);return!i&&n?.extend(r.toString(),e.toString(),typeof t[r],"Object property does not match"),i}))}}const Qe=Oe(Ke),Ye=$e((t=>null!=t&&(t.constructor===Object||null==t.constructor)));class He extends Ie{constructor(t,n){super(),this.shape={keys:t,values:n}}check(t,n){return null!=t&&te(t,((e,r)=>{const i=this.shape.keys.check(r,n);return!i&&n?.extend(r+"","Record",typeof t,i?"Key doesn't match schema":"Value doesn't match value"),i&&this.shape.values.check(e,n)}))}}const Ve=(t,n)=>new He(t,n),Xe=Oe(He);class qe extends Ie{constructor(t){super(),this.shape=t}check(t,n){return null!=t&&te(this.shape,((e,r)=>{const i=e.check(t[r],n);return!i&&n?.extend(r.toString(),"Tuple",typeof e),i}))}}Oe(qe);class Ge extends Ie{constructor(t){super(),this.shape=1===t.length?t[0]:new sr(t)}check(t,n){const e=Ut(t)&&St(t,(t=>this.shape.check(t)));return!e&&n?.extend(null,"Array",""),e}}const Je=(...t)=>new Ge(t),Ze=Oe(Ge),tr=$e((t=>Ut(t)));class nr extends Ie{constructor(t,n){super(),this.shape=t,this._c=n}check(t,n){const e=t instanceof this.shape&&(null==this._c||this._c(t));return!e&&n?.extend(null,this.shape.name,t?.constructor.name),e}}Oe(nr);const er=((t,n=null)=>new nr(Ie,n))(),rr=Oe(class extends Ie{constructor(t){super(),this.len=t.length-1,this.args=((...t)=>new qe(t))(...t.slice(-1)),this.res=t[this.len]}check(t,n){const e=t.constructor===Function&&t.length<=this.len;return!e&&n?.extend(null,"function",typeof t),e}}),ir=$e((t=>"function"==typeof t));Oe(class extends Ie{constructor(t){super(),this.shape=t}check(t,n){const e=St(this.shape,(e=>e.check(t,n)));return!e&&n?.extend(null,"Intersectinon",typeof t),e}},(t=>t.shape.length>0));class sr extends Ie{static _dilutes=!0;constructor(t){super(),this.shape=t}check(t,n){const e=Ct(this.shape,(e=>e.check(t,n)));return n?.extend(null,"Union",typeof t),e}}const or=(...t)=>t.findIndex((t=>ur.check(t)))>=0?or(...t.map((t=>Mr(t))).map((t=>ur.check(t)?t.shape:[t])).flat(1)):1===t.length?t[0]:new sr(t),ur=Oe(sr),cr=()=>!0,hr=$e(cr),ar=Oe(ze,(t=>t.shape===cr)),lr=$e((t=>"bigint"==typeof t)),fr=$e((t=>t===lr)),dr=$e((t=>"symbol"==typeof t));$e((t=>t===dr));const vr=$e((t=>"number"==typeof t)),pr=$e((t=>t===vr)),wr=$e((t=>"string"==typeof t)),yr=$e((t=>t===wr)),gr=$e((t=>"boolean"==typeof t)),br=$e((t=>t===gr)),mr=Pe(void 0);Oe(De,(t=>1===t.shape.length&&void 0===t.shape[0])),Pe(void 0);const Ar=Pe(null),kr=Oe(De,(t=>1===t.shape.length&&null===t.shape[0]));Oe(Uint8Array),Oe(_e,(t=>t.shape===Uint8Array));const xr=or(vr,wr,Ar,mr,lr,gr,dr);(()=>{const t=Je(hr),n=Ve(wr,hr),e=or(vr,wr,Ar,gr,t,n);t.shape=e,n.shape.values=e})();const Mr=t=>{if(er.check(t))return t;if(Ye.check(t)){const n={};for(const e in t)n[e]=Mr(t[e]);return new Ke(n)}return tr.check(t)?or(...t.map(Mr)):xr.check(t)?Pe(t):ir.check(t)?Oe(t):void mn()},Sr=de?()=>{}:(t,n)=>{const e=new je;if(!n.check(t,e))throw gn(`Expected value to be of type ${n.constructor.name}.\n${e.toString()}`)};const Cr=(Ur=hr,new class{constructor(t){this.patterns=[],this.$state=t}if(t,n){return this.patterns.push({if:Mr(t),h:n}),this}else(t){return this.if(hr,t)}done(){return(t,n)=>{for(let e=0;e<this.patterns.length;e++){const r=this.patterns[e];if(r.if.check(t))return r.h(t,n)}throw gn("Unhandled pattern")}}}(Ur)).if(pr,((t,n)=>xe(n,Wt,Bt))).if(yr,((t,n)=>((t,n=0,e=20)=>{const r=Se(t,n,e);let i="";for(let n=0;n<r;n++)i+=Ce(t);return i})(n))).if(br,((t,n)=>ke(n))).if(fr,((t,n)=>BigInt(xe(n,Wt,Bt)))).if(ur,((t,n)=>Er(n,Ue(n,t.shape)))).if(Qe,((t,n)=>{const e={};for(const r in t.shape){let i=t.shape[r];if(Ne.check(i)){if(ke(n))continue;i=i.shape}e[r]=Cr(i,n)}return e})).if(Ze,((t,n)=>{const e=[],r=Me(n,0,42);for(let i=0;i<r;i++)e.push(Er(n,t.shape));return e})).if(Re,((t,n)=>Ue(n,t.shape))).if(kr,(()=>null)).if(rr,((t,n)=>{const e=Er(n,t.res);return()=>e})).if(ar,((t,n)=>Er(n,Ue(n,[vr,wr,Ar,mr,lr,gr,Je(vr),Ve(or("a","b","c"),vr)])))).if(Xe,((t,n)=>{const e={},r=xe(n,0,3);for(let i=0;i<r;i++){const r=Er(n,t.shape.keys),i=Er(n,t.shape.values);e[r]=i}return e})).done();var Ur;const Er=(t,n)=>Cr(Mr(n),t),jr="undefined"!=typeof document?document:{};$e((t=>t.nodeType===Or)),"undefined"!=typeof DOMParser&&new DOMParser,$e((t=>t.nodeType===Tr)),$e((t=>t.nodeType===Ir));const Tr=jr.ELEMENT_NODE,Ir=jr.TEXT_NODE,_r=jr.DOCUMENT_NODE,Or=jr.DOCUMENT_FRAGMENT_NODE;$e((t=>t.nodeType===_r));const zr=Symbol,$r=zr(),Dr=zr(),Pr=zr(),Rr=zr(),Br=zr(),Wr=zr(),Lr=zr(),Fr=zr(),Nr=zr(),Kr={[$r]:Ae("font-weight","bold"),[Dr]:Ae("font-weight","normal"),[Pr]:Ae("color","blue"),[Br]:Ae("color","green"),[Rr]:Ae("color","grey"),[Wr]:Ae("color","red"),[Lr]:Ae("color","purple"),[Fr]:Ae("color","orange"),[Nr]:Ae("color","black")},Qr=pe?t=>{1===t.length&&t[0]?.constructor===Function&&(t=t[0]());const n=[],e=[],r=gt();let i=[],s=0;for(;s<t.length;s++){const i=t[s],o=Kr[i];if(void 0!==o)r.set(o.left,o.right);else{if(void 0===i)break;if(i.constructor!==String&&i.constructor!==Number)break;{const t=((t,n)=>{const e=[];for(const[r,i]of t)e.push(n(i,r));return e})(r,((t,n)=>`${n}:${t};`)).join("");s>0||t.length>0?(n.push("%c"+i),e.push(t)):n.push(i)}}}for(s>0&&(i=e,i.unshift(n.join("")));s<t.length;s++){const n=t[s];n instanceof Symbol||i.push(n)}return i}:t=>{1===t.length&&t[0]?.constructor===Function&&(t=t[0]());const n=[],e=[];let r=0;for(;r<t.length;r++){const e=t[r];if(void 0===e)break;if(e.constructor===String||e.constructor===Number)n.push(e);else if(e.constructor===Object)break}for(r>0&&e.push(n.join(""));r<t.length;r++){const n=t[r];n instanceof Symbol||e.push(n)}return e},Yr=(...t)=>{console.warn(...Qr(t)),t.unshift(Fr),Hr.forEach((n=>n.print(t)))},Hr=At(),Vr=t=>({[Symbol.iterator](){return this},next:t}),Xr=(t,n)=>Vr((()=>{const{done:e,value:r}=t.next();return{done:e,value:e?void 0:n(r)}}));class qr{constructor(t,n){this.clock=t,this.len=n}}class Gr{constructor(){this.clients=new Map}}const Jr=(t,n,e)=>n.clients.forEach(((n,r)=>{const i=t.doc.store.clients.get(r);if(null!=i){const r=i[i.length-1],s=r.id.clock+r.length;for(let r=0,o=n[r];r<n.length&&o.clock<s;o=n[++r])Ki(t,i,o.clock,o.len,e)}})),Zr=(t,n)=>{const e=t.clients.get(n.client);return void 0!==e&&null!==((t,n)=>{let e=0,r=t.length-1;for(;e<=r;){const i=Tt((e+r)/2),s=t[i],o=s.clock;if(o<=n){if(n<o+s.len)return i;e=i+1}else r=i-1}return null})(e,n.clock)},ti=t=>{t.clients.forEach((t=>{let n,e;for(t.sort(((t,n)=>t.clock-n.clock)),n=1,e=1;n<t.length;n++){const r=t[e-1],i=t[n];r.clock+r.len>=i.clock?r.len=Ot(r.len,i.clock+i.len-r.clock):(e<n&&(t[e]=i),e++)}t.length=e}))},ni=t=>{const n=new Gr;for(let e=0;e<t.length;e++)t[e].clients.forEach(((r,i)=>{if(!n.clients.has(i)){const s=r.slice();for(let n=e+1;n<t.length;n++)xt(s,t[n].clients.get(i)||[]);n.clients.set(i,s)}}));return ti(n),n},ei=(t,n,e,r)=>{mt(t.clients,n,(()=>[])).push(new qr(e,r))},ri=(t,n)=>{nn(t.restEncoder,n.clients.size),Mt(n.clients.entries()).sort(((t,n)=>n[0]-t[0])).forEach((([n,e])=>{t.resetDsCurVal(),nn(t.restEncoder,n);const r=e.length;nn(t.restEncoder,r);for(let n=0;n<r;n++){const r=e[n];t.writeDsClock(r.clock),t.writeDsLen(r.len)}}))},ii=t=>{const n=new Gr,e=Un(t.restDecoder);for(let r=0;r<e;r++){t.resetDsCurVal();const e=Un(t.restDecoder),r=Un(t.restDecoder);if(r>0){const i=mt(n.clients,e,(()=>[]));for(let n=0;n<r;n++)i.push(new qr(t.readDsClock(),t.readDsLen()))}}return n},si=(t,n,e)=>{const r=new Gr,i=Un(t.restDecoder);for(let s=0;s<i;s++){t.resetDsCurVal();const i=Un(t.restDecoder),s=Un(t.restDecoder),o=e.clients.get(i)||[],u=Pi(e,i);for(let e=0;e<s;e++){const e=t.readDsClock(),s=e+t.readDsLen();if(e<u){u<s&&ei(r,i,u,s-u);let t=Bi(o,e),c=o[t];for(!c.deleted&&c.id.clock<e&&(o.splice(t+1,0,zo(n,c,e-c.id.clock)),t++);t<o.length&&(c=o[t++],c.id.clock<s);)c.deleted||(s<c.id.clock+c.length&&o.splice(t,0,zo(n,c,s-c.id.clock)),c.delete(n))}else ei(r,i,e,s-e)}}if(r.clients.size>0){const t=new pi;return nn(t.restEncoder,0),ri(t,r),t.toUint8Array()}return null},oi=Rn;class ui extends Et{constructor({guid:t=Wn(),collectionid:n=null,gc:e=!0,gcFilter:r=()=>!0,meta:i=null,autoLoad:s=!1,shouldLoad:o=!0}={}){super(),this.gc=e,this.gcFilter=r,this.clientID=oi(),this.guid=t,this.collectionid=n,this.share=new Map,this.store=new $i,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=o,this.autoLoad=s,this.meta=i,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=Fn((t=>{this.on("load",(()=>{this.isLoaded=!0,t(this)}))}));const u=()=>Fn((t=>{const n=e=>{void 0!==e&&!0!==e||(this.off("sync",n),t())};this.on("sync",n)}));this.on("sync",(t=>{!1===t&&this.isSynced&&(this.whenSynced=u()),this.isSynced=void 0===t||!0===t,this.isSynced&&!this.isLoaded&&this.emit("load",[this])})),this.whenSynced=u()}load(){const t=this._item;null===t||this.shouldLoad||qi(t.parent.doc,(t=>{t.subdocsLoaded.add(this)}),null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(Mt(this.subdocs).map((t=>t.guid)))}transact(t,n=null){return qi(this,t,n)}get(t,n=As){const e=mt(this.share,t,(()=>{const t=new n;return t._integrate(this,null),t})),r=e.constructor;if(n!==As&&r!==n){if(r===As){const r=new n;r._map=e._map,e._map.forEach((t=>{for(;null!==t;t=t.left)t.parent=r})),r._start=e._start;for(let t=r._start;null!==t;t=t.right)t.parent=r;return r._length=e._length,this.share.set(t,r),r._integrate(this,null),r}throw new Error(`Type with the name ${t} has already been defined with a different constructor`)}return e}getArray(t=""){return this.get(t,Bs)}getText(t=""){return this.get(t,ro)}getMap(t=""){return this.get(t,Ls)}getXmlElement(t=""){return this.get(t,oo)}getXmlFragment(t=""){return this.get(t,so)}toJSON(){const t={};return this.share.forEach(((n,e)=>{t[e]=n.toJSON()})),t}destroy(){this.isDestroyed=!0,Mt(this.subdocs).forEach((t=>t.destroy()));const t=this._item;if(null!==t){this._item=null;const n=t.content;n.doc=new ui({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=t,qi(t.parent.doc,(e=>{t.deleted||e.subdocsAdded.add(n.doc),e.subdocsRemoved.add(this)}),null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}}class ci{constructor(t){this.restDecoder=t}resetDsCurVal(){}readDsClock(){return Un(this.restDecoder)}readDsLen(){return Un(this.restDecoder)}}class hi extends ci{readLeftID(){return Ii(Un(this.restDecoder),Un(this.restDecoder))}readRightID(){return Ii(Un(this.restDecoder),Un(this.restDecoder))}readClient(){return Un(this.restDecoder)}readInfo(){return Cn(this.restDecoder)}readString(){return jn(this.restDecoder)}readParentInfo(){return 1===Un(this.restDecoder)}readTypeRef(){return Un(this.restDecoder)}readLen(){return Un(this.restDecoder)}readAny(){return _n(this.restDecoder)}readBuf(){return(t=>{const n=we(t.byteLength);return n.set(t),n})(Sn(this.restDecoder))}readJSON(){return JSON.parse(jn(this.restDecoder))}readKey(){return jn(this.restDecoder)}}class ai{constructor(t){this.dsCurrVal=0,this.restDecoder=t}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=Un(this.restDecoder),this.dsCurrVal}readDsLen(){const t=Un(this.restDecoder)+1;return this.dsCurrVal+=t,t}}class li extends ai{constructor(t){super(t),this.keys=[],Un(t),this.keyClockDecoder=new $n(Sn(t)),this.clientDecoder=new zn(Sn(t)),this.leftClockDecoder=new $n(Sn(t)),this.rightClockDecoder=new $n(Sn(t)),this.infoDecoder=new On(Sn(t),Cn),this.stringDecoder=new Dn(Sn(t)),this.parentInfoDecoder=new On(Sn(t),Cn),this.typeRefDecoder=new zn(Sn(t)),this.lenDecoder=new zn(Sn(t))}readLeftID(){return new ji(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new ji(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return 1===this.parentInfoDecoder.read()}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return _n(this.restDecoder)}readBuf(){return Sn(this.restDecoder)}readJSON(){return _n(this.restDecoder)}readKey(){const t=this.keyClockDecoder.read();if(t<this.keys.length)return this.keys[t];{const t=this.stringDecoder.read();return this.keys.push(t),t}}}class fi{constructor(){this.restEncoder=qt()}toUint8Array(){return Jt(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){nn(this.restEncoder,t)}writeDsLen(t){nn(this.restEncoder,t)}}class di extends fi{writeLeftID(t){nn(this.restEncoder,t.client),nn(this.restEncoder,t.clock)}writeRightID(t){nn(this.restEncoder,t.client),nn(this.restEncoder,t.clock)}writeClient(t){nn(this.restEncoder,t)}writeInfo(t){tn(this.restEncoder,t)}writeString(t){on(this.restEncoder,t)}writeParentInfo(t){nn(this.restEncoder,t?1:0)}writeTypeRef(t){nn(this.restEncoder,t)}writeLen(t){nn(this.restEncoder,t)}writeAny(t){ln(this.restEncoder,t)}writeBuf(t){cn(this.restEncoder,t)}writeJSON(t){on(this.restEncoder,JSON.stringify(t))}writeKey(t){on(this.restEncoder,t)}}class vi{constructor(){this.restEncoder=qt(),this.dsCurrVal=0}toUint8Array(){return Jt(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){const n=t-this.dsCurrVal;this.dsCurrVal=t,nn(this.restEncoder,n)}writeDsLen(t){0===t&&mn(),nn(this.restEncoder,t-1),this.dsCurrVal+=t}}class pi extends vi{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new wn,this.clientEncoder=new vn,this.leftClockEncoder=new wn,this.rightClockEncoder=new wn,this.infoEncoder=new fn(tn),this.stringEncoder=new yn,this.parentInfoEncoder=new fn(tn),this.typeRefEncoder=new vn,this.lenEncoder=new vn}toUint8Array(){const t=qt();return nn(t,0),cn(t,this.keyClockEncoder.toUint8Array()),cn(t,this.clientEncoder.toUint8Array()),cn(t,this.leftClockEncoder.toUint8Array()),cn(t,this.rightClockEncoder.toUint8Array()),cn(t,Jt(this.infoEncoder)),cn(t,this.stringEncoder.toUint8Array()),cn(t,Jt(this.parentInfoEncoder)),cn(t,this.typeRefEncoder.toUint8Array()),cn(t,this.lenEncoder.toUint8Array()),un(t,Jt(this.restEncoder)),Jt(t)}writeLeftID(t){this.clientEncoder.write(t.client),this.leftClockEncoder.write(t.clock)}writeRightID(t){this.clientEncoder.write(t.client),this.rightClockEncoder.write(t.clock)}writeClient(t){this.clientEncoder.write(t)}writeInfo(t){this.infoEncoder.write(t)}writeString(t){this.stringEncoder.write(t)}writeParentInfo(t){this.parentInfoEncoder.write(t?1:0)}writeTypeRef(t){this.typeRefEncoder.write(t)}writeLen(t){this.lenEncoder.write(t)}writeAny(t){ln(this.restEncoder,t)}writeBuf(t){cn(this.restEncoder,t)}writeJSON(t){ln(this.restEncoder,t)}writeKey(t){const n=this.keyMap.get(t);void 0===n?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(t)):this.keyClockEncoder.write(n)}}const wi=(t,n,e)=>{const r=new Map;e.forEach(((t,e)=>{Pi(n,e)>t&&r.set(e,t)})),Di(n).forEach(((t,n)=>{e.has(n)||r.set(n,0)})),nn(t.restEncoder,r.size),Mt(r.entries()).sort(((t,n)=>n[0]-t[0])).forEach((([e,r])=>{((t,n,e,r)=>{r=Ot(r,n[0].id.clock);const i=Bi(n,r);nn(t.restEncoder,n.length-i),t.writeClient(e),nn(t.restEncoder,r);const s=n[i];s.write(t,r-s.id.clock);for(let e=i+1;e<n.length;e++)n[e].write(t,0)})(t,n.clients.get(e),e,r)}))},yi=(t,n,e,r=li)=>{const i=Mn(n);((t,n,e,r=new li(t))=>{qi(n,(t=>{t.local=!1;let n=!1;const e=t.doc,i=e.store,s=((t,n)=>{const e=gt(),r=Un(t.restDecoder);for(let i=0;i<r;i++){const r=Un(t.restDecoder),i=new Array(r),s=t.readClient();let o=Un(t.restDecoder);e.set(s,{i:0,refs:i});for(let e=0;e<r;e++){const r=t.readInfo();switch(31&r){case 0:{const n=t.readLen();i[e]=new lo(Ii(s,o),n),o+=n;break}case 10:{const n=Un(t.restDecoder);i[e]=new Wo(Ii(s,o),n),o+=n;break}default:{const u=!(192&r),c=new Po(Ii(s,o),null,(r&Pt)===Pt?t.readLeftID():null,null,(r&Dt)===Dt?t.readRightID():null,u?t.readParentInfo()?n.get(t.readString()):t.readLeftID():null,!u||32&~r?null:t.readString(),Ro(t,r));i[e]=c,o+=c.length}}}}return e})(r,e),o=((t,n,e)=>{const r=[];let i=Mt(e.keys()).sort(((t,n)=>t-n));if(0===i.length)return null;const s=()=>{if(0===i.length)return null;let t=e.get(i[i.length-1]);for(;t.refs.length===t.i;){if(i.pop(),!(i.length>0))return null;t=e.get(i[i.length-1])}return t};let o=s();if(null===o)return null;const u=new $i,c=new Map,h=(t,n)=>{const e=c.get(t);(null==e||e>n)&&c.set(t,n)};let a=o.refs[o.i++];const l=new Map,f=()=>{for(const t of r){const n=t.id.client,r=e.get(n);r?(r.i--,u.clients.set(n,r.refs.slice(r.i)),e.delete(n),r.i=0,r.refs=[]):u.clients.set(n,[t]),i=i.filter((t=>t!==n))}r.length=0};for(;;){if(a.constructor!==Wo){const i=mt(l,a.id.client,(()=>Pi(n,a.id.client)))-a.id.clock;if(i<0)r.push(a),h(a.id.client,a.id.clock-1),f();else{const s=a.getMissing(t,n);if(null!==s){r.push(a);const t=e.get(s)||{refs:[],i:0};if(t.refs.length!==t.i){a=t.refs[t.i++];continue}h(s,Pi(n,s)),f()}else(0===i||i<a.length)&&(a.integrate(t,i),l.set(a.id.client,a.id.clock+a.length))}}if(r.length>0)a=r.pop();else if(null!==o&&o.i<o.refs.length)a=o.refs[o.i++];else{if(o=s(),null===o)break;a=o.refs[o.i++]}}if(u.clients.size>0){const t=new pi;return wi(t,u,new Map),nn(t.restEncoder,0),{missing:c,update:t.toUint8Array()}}return null})(t,i,s),u=i.pendingStructs;if(u){for(const[t,e]of u.missing)if(e<Pi(i,t)){n=!0;break}if(o){for(const[t,n]of o.missing){const e=u.missing.get(t);(null==e||e>n)&&u.missing.set(t,n)}u.update=ss([u.update,o.update])}}else i.pendingStructs=o;const c=si(r,t,i);if(i.pendingDs){const n=new li(Mn(i.pendingDs));Un(n.restDecoder);const e=si(n,t,i);i.pendingDs=c&&e?ss([c,e]):c||e}else i.pendingDs=c;if(n){const n=i.pendingStructs.update;i.pendingStructs=null,yi(t.doc,n)}}),e,!1)})(i,t,e,new r(i))},gi=(t,n,e)=>yi(t,n,e,hi),bi=(t,n=new Uint8Array([0]),e=new pi)=>{((t,n,e=new Map)=>{wi(t,n.store,e),ri(t,(t=>{const n=new Gr;return t.clients.forEach(((t,e)=>{const r=[];for(let n=0;n<t.length;n++){const e=t[n];if(e.deleted){const i=e.id.clock;let s=e.length;if(n+1<t.length)for(let e=t[n+1];n+1<t.length&&e.deleted;e=t[1+ ++n])s+=e.length;r.push(new qr(i,s))}}r.length>0&&n.clients.set(e,r)})),n})(n.store))})(e,t,Ai(n));const r=[e.toUint8Array()];if(t.store.pendingDs&&r.push(t.store.pendingDs),t.store.pendingStructs&&r.push(os(t.store.pendingStructs.update,n)),r.length>1){if(e.constructor===di)return rs(r.map(((t,n)=>0===n?t:as(t))));if(e.constructor===pi)return ss(r)}return r[0]},mi=(t,n)=>bi(t,n,new di),Ai=t=>(t=>{const n=new Map,e=Un(t.restDecoder);for(let r=0;r<e;r++){const e=Un(t.restDecoder),r=Un(t.restDecoder);n.set(e,r)}return n})(new ci(Mn(t))),ki=(t,n)=>(nn(t.restEncoder,n.size),Mt(n.entries()).sort(((t,n)=>n[0]-t[0])).forEach((([n,e])=>{nn(t.restEncoder,n),nn(t.restEncoder,e)})),t),xi=t=>((t,n=new vi)=>(t instanceof Map?ki(n,t):((t,n)=>{ki(t,Di(n.store))})(n,t),n.toUint8Array()))(t,new fi);class Mi{constructor(){this.l=[]}}const Si=()=>new Mi,Ci=(t,n)=>t.l.push(n),Ui=(t,n)=>{const e=t.l,r=e.length;t.l=e.filter((t=>n!==t)),r===t.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},Ei=(t,n,e)=>ie(t.l,[n,e]);class ji{constructor(t,n){this.client=t,this.clock=n}}const Ti=(t,n)=>t===n||null!==t&&null!==n&&t.client===n.client&&t.clock===n.clock,Ii=(t,n)=>new ji(t,n),_i=(t,n)=>{for(;null!==n;){if(n.parent===t)return!0;n=n.parent._item}return!1},Oi=(t,n)=>void 0===n?!t.deleted:n.sv.has(t.id.client)&&(n.sv.get(t.id.client)||0)>t.id.clock&&!Zr(n.ds,t.id),zi=(t,n)=>{const e=mt(t.meta,zi,At),r=t.doc.store;e.has(n)||(n.sv.forEach(((n,e)=>{n<Pi(r,e)&&Fi(t,Ii(e,n))})),Jr(t,n.ds,(()=>{})),e.add(n))};class $i{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const Di=t=>{const n=new Map;return t.clients.forEach(((t,e)=>{const r=t[t.length-1];n.set(e,r.id.clock+r.length)})),n},Pi=(t,n)=>{const e=t.clients.get(n);if(void 0===e)return 0;const r=e[e.length-1];return r.id.clock+r.length},Ri=(t,n)=>{let e=t.clients.get(n.id.client);if(void 0===e)e=[],t.clients.set(n.id.client,e);else{const t=e[e.length-1];if(t.id.clock+t.length!==n.id.clock)throw mn()}e.push(n)},Bi=(t,n)=>{let e=0,r=t.length-1,i=t[r],s=i.id.clock;if(s===n)return r;let o=Tt(n/(s+i.length-1)*r);for(;e<=r;){if(i=t[o],s=i.id.clock,s<=n){if(n<s+i.length)return o;e=o+1}else r=o-1;o=Tt((e+r)/2)}throw mn()},Wi=(t,n)=>{const e=t.clients.get(n.client);return e[Bi(e,n.clock)]},Li=(t,n,e)=>{const r=Bi(n,e),i=n[r];return i.id.clock<e&&i instanceof Po?(n.splice(r+1,0,zo(t,i,e-i.id.clock)),r+1):r},Fi=(t,n)=>{const e=t.doc.store.clients.get(n.client);return e[Li(t,e,n.clock)]},Ni=(t,n,e)=>{const r=n.clients.get(e.client),i=Bi(r,e.clock),s=r[i];return e.clock!==s.id.clock+s.length-1&&s.constructor!==lo&&r.splice(i+1,0,zo(t,s,e.clock-s.id.clock+1)),s},Ki=(t,n,e,r,i)=>{if(0===r)return;const s=e+r;let o,u=Li(t,n,e);do{o=n[u++],s<o.id.clock+o.length&&Li(t,n,s),i(o)}while(u<n.length&&n[u].id.clock<s)};class Qi{constructor(t,n,e){this.doc=t,this.deleteSet=new Gr,this.beforeState=Di(t.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=n,this.meta=new Map,this.local=e,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}}const Yi=(t,n)=>!(0===n.deleteSet.clients.size&&!(t=>{for(const[r,i]of t)if(e=i,n.beforeState.get(r)!==e)return!0;var e;return!1})(n.afterState)||(ti(n.deleteSet),((t,n)=>{wi(t,n.doc.store,n.beforeState)})(t,n),ri(t,n.deleteSet),0)),Hi=(t,n,e)=>{const r=n._item;(null===r||r.id.clock<(t.beforeState.get(r.id.client)||0)&&!r.deleted)&&mt(t.changed,n,At).add(e)},Vi=(t,n)=>{let e=t[n],r=t[n-1],i=n;for(;i>0&&r.deleted===e.deleted&&r.constructor===e.constructor&&r.mergeWith(e);e=r,r=t[--i-1])e instanceof Po&&null!==e.parentSub&&e.parent._map.get(e.parentSub)===e&&e.parent._map.set(e.parentSub,r);const s=n-i;return s&&t.splice(n+1-s,s),s},Xi=(t,n)=>{if(n<t.length){const e=t[n],r=e.doc,i=r.store,s=e.deleteSet,o=e._mergeStructs;try{ti(s),e.afterState=Di(e.doc.store),r.emit("beforeObserverCalls",[e,r]);const t=[];e.changed.forEach(((n,r)=>t.push((()=>{null!==r._item&&r._item.deleted||r._callObserver(e,n)})))),t.push((()=>{e.changedParentTypes.forEach(((t,n)=>{n._dEH.l.length>0&&(null===n._item||!n._item.deleted)&&((t=t.filter((t=>null===t.target._item||!t.target._item.deleted))).forEach((t=>{t.currentTarget=n,t._path=null})),t.sort(((t,n)=>t.path.length-n.path.length)),Ei(n._dEH,t,e))}))})),t.push((()=>r.emit("afterTransaction",[e,r]))),ie(t,[]),e._needFormattingCleanup&&to(e)}finally{r.gc&&((t,n,e)=>{for(const[r,i]of t.clients.entries()){const t=n.clients.get(r);for(let r=i.length-1;r>=0;r--){const s=i[r],o=s.clock+s.len;for(let r=Bi(t,s.clock),i=t[r];r<t.length&&i.id.clock<o;i=t[++r]){const i=t[r];if(s.clock+s.len<=i.id.clock)break;i instanceof Po&&i.deleted&&!i.keep&&e(i)&&i.gc(n,!1)}}}})(s,i,r.gcFilter),((t,n)=>{t.clients.forEach(((t,e)=>{const r=n.clients.get(e);for(let n=t.length-1;n>=0;n--){const e=t[n];for(let t=_t(r.length-1,1+Bi(r,e.clock+e.len-1)),n=r[t];t>0&&n.id.clock>=e.clock;n=r[t])t-=1+Vi(r,t)}}))})(s,i),e.afterState.forEach(((t,n)=>{const r=e.beforeState.get(n)||0;if(r!==t){const t=i.clients.get(n),e=Ot(Bi(t,r),1);for(let n=t.length-1;n>=e;)n-=1+Vi(t,n)}}));for(let t=o.length-1;t>=0;t--){const{client:n,clock:e}=o[t].id,r=i.clients.get(n),s=Bi(r,e);s+1<r.length&&Vi(r,s+1)>1||s>0&&Vi(r,s)}if(e.local||e.afterState.get(r.clientID)===e.beforeState.get(r.clientID)||(((...t)=>{console.log(...Qr(t)),Hr.forEach((n=>n.print(t)))})(Fr,$r,"[yjs] ",Dr,Wr,"Changed the client-id because another client seems to be using it."),r.clientID=oi()),r.emit("afterTransactionCleanup",[e,r]),r._observers.has("update")){const t=new di;Yi(t,e)&&r.emit("update",[t.toUint8Array(),e.origin,r,e])}if(r._observers.has("updateV2")){const t=new pi;Yi(t,e)&&r.emit("updateV2",[t.toUint8Array(),e.origin,r,e])}const{subdocsAdded:u,subdocsLoaded:c,subdocsRemoved:h}=e;(u.size>0||h.size>0||c.size>0)&&(u.forEach((t=>{t.clientID=r.clientID,null==t.collectionid&&(t.collectionid=r.collectionid),r.subdocs.add(t)})),h.forEach((t=>r.subdocs.delete(t))),r.emit("subdocs",[{loaded:c,added:u,removed:h},r,e]),h.forEach((t=>t.destroy()))),t.length<=n+1?(r._transactionCleanups=[],r.emit("afterAllTransactions",[r,t])):Xi(t,n+1)}}},qi=(t,n,e=null,r=!0)=>{const i=t._transactionCleanups;let s=!1,o=null;null===t._transaction&&(s=!0,t._transaction=new Qi(t,e,r),i.push(t._transaction),1===i.length&&t.emit("beforeAllTransactions",[t]),t.emit("beforeTransaction",[t._transaction,t]));try{o=n(t._transaction)}finally{if(s){const n=t._transaction===i[0];t._transaction=null,n&&Xi(i,0)}}return o};class Gi{constructor(t,n){this.insertions=n,this.deletions=t,this.meta=new Map}}const Ji=(t,n,e)=>{Jr(t,e.deletions,(e=>{e instanceof Po&&n.scope.some((n=>n===t.doc||_i(n,e)))&&Oo(e,!1)}))},Zi=(t,n,e)=>{let r=null;const i=t.doc,s=t.scope;qi(i,(e=>{for(;n.length>0&&null===t.currStackItem;){const r=i.store,o=n.pop(),u=new Set,c=[];let h=!1;Jr(e,o.insertions,(t=>{if(t instanceof Po){if(null!==t.redone){let{item:n,diff:i}=_o(r,t.id);i>0&&(n=Fi(e,Ii(n.id.client,n.id.clock+i))),t=n}!t.deleted&&s.some((n=>n===e.doc||_i(n,t)))&&c.push(t)}})),Jr(e,o.deletions,(t=>{t instanceof Po&&s.some((n=>n===e.doc||_i(n,t)))&&!Zr(o.insertions,t.id)&&u.add(t)})),u.forEach((n=>{h=null!==Do(e,n,u,o.insertions,t.ignoreRemoteMapChanges,t)||h}));for(let n=c.length-1;n>=0;n--){const r=c[n];t.deleteFilter(r)&&(r.delete(e),h=!0)}t.currStackItem=h?o:null}e.changed.forEach(((t,n)=>{t.has(null)&&n._searchMarker&&(n._searchMarker.length=0)})),r=e}),t);const o=t.currStackItem;return null!=o&&(t.emit("stack-item-popped",[{stackItem:o,type:e,changedParentTypes:r.changedParentTypes,origin:t},t]),t.currStackItem=null),o};class ts extends Et{constructor(t,{captureTimeout:n=500,captureTransaction:e=()=>!0,deleteFilter:r=()=>!0,trackedOrigins:i=new Set([null]),ignoreRemoteMapChanges:s=!1,doc:o=(Ut(t)?t[0].doc:t instanceof ui?t:t.doc)}={}){super(),this.scope=[],this.doc=o,this.addToScope(t),this.deleteFilter=r,i.add(this),this.trackedOrigins=i,this.captureTransaction=e,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=s,this.captureTimeout=n,this.afterTransactionHandler=t=>{if(!(this.captureTransaction(t)&&this.scope.some((n=>t.changedParentTypes.has(n)||n===this.doc))&&(this.trackedOrigins.has(t.origin)||t.origin&&this.trackedOrigins.has(t.origin.constructor))))return;const n=this.undoing,e=this.redoing,r=n?this.redoStack:this.undoStack;n?this.stopCapturing():e||this.clear(!1,!0);const i=new Gr;t.afterState.forEach(((n,e)=>{const r=t.beforeState.get(e)||0,s=n-r;s>0&&ei(i,e,r,s)}));const s=Ln();let o=!1;if(this.lastChange>0&&s-this.lastChange<this.captureTimeout&&r.length>0&&!n&&!e){const n=r[r.length-1];n.deletions=ni([n.deletions,t.deleteSet]),n.insertions=ni([n.insertions,i])}else r.push(new Gi(t.deleteSet,i)),o=!0;n||e||(this.lastChange=s),Jr(t,t.deleteSet,(n=>{n instanceof Po&&this.scope.some((e=>e===t.doc||_i(e,n)))&&Oo(n,!0)}));this.emit(o?"stack-item-added":"stack-item-updated",[{stackItem:r[r.length-1],origin:t.origin,type:n?"redo":"undo",changedParentTypes:t.changedParentTypes},this])},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",(()=>{this.destroy()}))}addToScope(t){const n=new Set(this.scope);(t=Ut(t)?t:[t]).forEach((t=>{n.has(t)||(n.add(t),(t instanceof As?t.doc!==this.doc:t!==this.doc)&&Yr("[yjs#509] Not same Y.Doc"),this.scope.push(t))}))}addTrackedOrigin(t){this.trackedOrigins.add(t)}removeTrackedOrigin(t){this.trackedOrigins.delete(t)}clear(t=!0,n=!0){(t&&this.canUndo()||n&&this.canRedo())&&this.doc.transact((e=>{t&&(this.undoStack.forEach((t=>Ji(e,this,t))),this.undoStack=[]),n&&(this.redoStack.forEach((t=>Ji(e,this,t))),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:t,redoStackCleared:n}])}))}stopCapturing(){this.lastChange=0}undo(){let t;this.undoing=!0;try{t=Zi(this,this.undoStack,"undo")}finally{this.undoing=!1}return t}redo(){let t;this.redoing=!0;try{t=Zi(this,this.redoStack,"redo")}finally{this.redoing=!1}return t}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off("afterTransaction",this.afterTransactionHandler),super.destroy()}}class ns{constructor(t,n){this.gen=function*(t){const n=Un(t.restDecoder);for(let e=0;e<n;e++){const n=Un(t.restDecoder),e=t.readClient();let r=Un(t.restDecoder);for(let i=0;i<n;i++){const n=t.readInfo();if(10===n){const n=Un(t.restDecoder);yield new Wo(Ii(e,r),n),r+=n}else if(31&n){const i=!(192&n),s=new Po(Ii(e,r),null,(n&Pt)===Pt?t.readLeftID():null,null,(n&Dt)===Dt?t.readRightID():null,i?t.readParentInfo()?t.readString():t.readLeftID():null,!i||32&~n?null:t.readString(),Ro(t,n));yield s,r+=s.length}else{const n=t.readLen();yield new lo(Ii(e,r),n),r+=n}}}}(t),this.curr=null,this.done=!1,this.filterSkips=n,this.next()}next(){do{this.curr=this.gen.next().value||null}while(this.filterSkips&&null!==this.curr&&this.curr.constructor===Wo);return this.curr}}class es{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}}const rs=t=>ss(t,hi,di),is=(t,n)=>{if(t.constructor===lo){const{client:e,clock:r}=t.id;return new lo(Ii(e,r+n),t.length-n)}if(t.constructor===Wo){const{client:e,clock:r}=t.id;return new Wo(Ii(e,r+n),t.length-n)}{const e=t,{client:r,clock:i}=e.id;return new Po(Ii(r,i+n),null,Ii(r,i+n-1),null,e.rightOrigin,e.parent,e.parentSub,e.content.splice(n))}},ss=(t,n=li,e=pi)=>{if(1===t.length)return t[0];const r=t.map((t=>new n(Mn(t))));let i=r.map((t=>new ns(t,!0))),s=null;const o=new e,u=new es(o);for(;i=i.filter((t=>null!==t.curr)),i.sort(((t,n)=>{if(t.curr.id.client===n.curr.id.client){const e=t.curr.id.clock-n.curr.id.clock;return 0===e?t.curr.constructor===n.curr.constructor?0:t.curr.constructor===Wo?1:-1:e}return n.curr.id.client-t.curr.id.client})),0!==i.length;){const t=i[0],n=t.curr.id.client;if(null!==s){let e=t.curr,r=!1;for(;null!==e&&e.id.clock+e.length<=s.struct.id.clock+s.struct.length&&e.id.client>=s.struct.id.client;)e=t.next(),r=!0;if(null===e||e.id.client!==n||r&&e.id.clock>s.struct.id.clock+s.struct.length)continue;if(n!==s.struct.id.client)cs(u,s.struct,s.offset),s={struct:e,offset:0},t.next();else if(s.struct.id.clock+s.struct.length<e.id.clock)if(s.struct.constructor===Wo)s.struct.length=e.id.clock+e.length-s.struct.id.clock;else{cs(u,s.struct,s.offset);const t=e.id.clock-s.struct.id.clock-s.struct.length;s={struct:new Wo(Ii(n,s.struct.id.clock+s.struct.length),t),offset:0}}else{const n=s.struct.id.clock+s.struct.length-e.id.clock;n>0&&(s.struct.constructor===Wo?s.struct.length-=n:e=is(e,n)),s.struct.mergeWith(e)||(cs(u,s.struct,s.offset),s={struct:e,offset:0},t.next())}}else s={struct:t.curr,offset:0},t.next();for(let e=t.curr;null!==e&&e.id.client===n&&e.id.clock===s.struct.id.clock+s.struct.length&&e.constructor!==Wo;e=t.next())cs(u,s.struct,s.offset),s={struct:e,offset:0}}null!==s&&(cs(u,s.struct,s.offset),s=null),hs(u);const c=r.map((t=>ii(t))),h=ni(c);return ri(o,h),o.toUint8Array()},os=(t,n,e=li,r=pi)=>{const i=Ai(n),s=new r,o=new es(s),u=new e(Mn(t)),c=new ns(u,!1);for(;c.curr;){const t=c.curr,n=t.id.client,e=i.get(n)||0;if(c.curr.constructor!==Wo)if(t.id.clock+t.length>e)for(cs(o,t,Ot(e-t.id.clock,0)),c.next();c.curr&&c.curr.id.client===n;)cs(o,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===n&&c.curr.id.clock+c.curr.length<=e;)c.next();else c.next()}hs(o);const h=ii(u);return ri(s,h),s.toUint8Array()},us=t=>{t.written>0&&(t.clientStructs.push({written:t.written,restEncoder:Jt(t.encoder.restEncoder)}),t.encoder.restEncoder=qt(),t.written=0)},cs=(t,n,e)=>{t.written>0&&t.currClient!==n.id.client&&us(t),0===t.written&&(t.currClient=n.id.client,t.encoder.writeClient(n.id.client),nn(t.encoder.restEncoder,n.id.clock+e)),n.write(t.encoder,e),t.written++},hs=t=>{us(t);const n=t.encoder.restEncoder;nn(n,t.clientStructs.length);for(let e=0;e<t.clientStructs.length;e++){const r=t.clientStructs[e];nn(n,r.written),un(n,r.restEncoder)}},as=t=>((t,n,e,r)=>{const i=new li(Mn(t)),s=new ns(i,!1),o=new r,u=new es(o);for(let t=s.curr;null!==t;t=s.next())cs(u,n(t),0);hs(u);const c=ii(i);return ri(o,c),o.toUint8Array()})(t,se,0,di),ls="You must not compute changes after the event-handler fired.";class fs{constructor(t,n){this.target=t,this.currentTarget=t,this.transaction=n,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=ds(this.currentTarget,this.target))}deletes(t){return Zr(this.transaction.deleteSet,t.id)}get keys(){if(null===this._keys){if(0===this.transaction.doc._transactionCleanups.length)throw gn(ls);const t=new Map,n=this.target;this.transaction.changed.get(n).forEach((e=>{if(null!==e){const r=n._map.get(e);let i,s;if(this.adds(r)){let t=r.left;for(;null!==t&&this.adds(t);)t=t.left;if(this.deletes(r)){if(null===t||!this.deletes(t))return;i="delete",s=kt(t.content.getContent())}else null!==t&&this.deletes(t)?(i="update",s=kt(t.content.getContent())):(i="add",s=void 0)}else{if(!this.deletes(r))return;i="delete",s=kt(r.content.getContent())}t.set(e,{action:i,oldValue:s})}})),this._keys=t}return this._keys}get delta(){return this.changes.delta}adds(t){return t.id.clock>=(this.transaction.beforeState.get(t.id.client)||0)}get changes(){let t=this._changes;if(null===t){if(0===this.transaction.doc._transactionCleanups.length)throw gn(ls);const n=this.target,e=At(),r=At(),i=[];if(t={added:e,deleted:r,delta:i,keys:this.keys},this.transaction.changed.get(n).has(null)){let t=null;const s=()=>{t&&i.push(t)};for(let i=n._start;null!==i;i=i.right)i.deleted?this.deletes(i)&&!this.adds(i)&&(null!==t&&void 0!==t.delete||(s(),t={delete:0}),t.delete+=i.length,r.add(i)):this.adds(i)?(null!==t&&void 0!==t.insert||(s(),t={insert:[]}),t.insert=t.insert.concat(i.content.getContent()),e.add(i)):(null!==t&&void 0!==t.retain||(s(),t={retain:0}),t.retain+=i.length);null!==t&&void 0===t.retain&&s()}this._changes=t}return t}}const ds=(t,n)=>{const e=[];for(;null!==n._item&&n!==t;){if(null!==n._item.parentSub)e.unshift(n._item.parentSub);else{let t=0,r=n._item.parent._start;for(;r!==n._item&&null!==r;)!r.deleted&&r.countable&&(t+=r.length),r=r.right;e.unshift(t)}n=n._item.parent}return e},vs=()=>{Yr("Invalid access: Add Yjs type to a document before reading data.")};let ps=0;class ws{constructor(t,n){t.marker=!0,this.p=t,this.index=n,this.timestamp=ps++}}const ys=(t,n,e)=>{t.p.marker=!1,t.p=n,n.marker=!0,t.index=e,t.timestamp=ps++},gs=(t,n)=>{if(null===t._start||0===n||null===t._searchMarker)return null;const e=0===t._searchMarker.length?null:t._searchMarker.reduce(((t,e)=>It(n-t.index)<It(n-e.index)?t:e));let r=t._start,i=0;for(null!==e&&(r=e.p,i=e.index,(t=>{t.timestamp=ps++})(e));null!==r.right&&i<n;){if(!r.deleted&&r.countable){if(n<i+r.length)break;i+=r.length}r=r.right}for(;null!==r.left&&i>n;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);for(;null!==r.left&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);return null!==e&&It(e.index-i)<r.parent.length/80?(ys(e,r,i),e):((t,n,e)=>{if(t.length>=80){const r=t.reduce(((t,n)=>t.timestamp<n.timestamp?t:n));return ys(r,n,e),r}{const r=new ws(n,e);return t.push(r),r}})(t._searchMarker,r,i)},bs=(t,n,e)=>{for(let r=t.length-1;r>=0;r--){const i=t[r];if(e>0){let n=i.p;for(n.marker=!1;n&&(n.deleted||!n.countable);)n=n.left,n&&!n.deleted&&n.countable&&(i.index-=n.length);if(null===n||!0===n.marker){t.splice(r,1);continue}i.p=n,n.marker=!0}(n<i.index||e>0&&n===i.index)&&(i.index=Ot(n,i.index+e))}},ms=(t,n,e)=>{const r=t,i=n.changedParentTypes;for(;mt(i,t,(()=>[])).push(e),null!==t._item;)t=t._item.parent;Ei(r._eH,e,n)};class As{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=Si(),this._dEH=Si(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,n){this.doc=t,this._item=n}_copy(){throw bn()}clone(){throw bn()}_write(t){}get _first(){let t=this._start;for(;null!==t&&t.deleted;)t=t.right;return t}_callObserver(t,n){!t.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(t){Ci(this._eH,t)}observeDeep(t){Ci(this._dEH,t)}unobserve(t){Ui(this._eH,t)}unobserveDeep(t){Ui(this._dEH,t)}toJSON(){}}const ks=(t,n,e)=>{t.doc??vs(),n<0&&(n=t._length+n),e<0&&(e=t._length+e);let r=e-n;const i=[];let s=t._start;for(;null!==s&&r>0;){if(s.countable&&!s.deleted){const t=s.content.getContent();if(t.length<=n)n-=t.length;else{for(let e=n;e<t.length&&r>0;e++)i.push(t[e]),r--;n=0}}s=s.right}return i},xs=t=>{t.doc??vs();const n=[];let e=t._start;for(;null!==e;){if(e.countable&&!e.deleted){const t=e.content.getContent();for(let e=0;e<t.length;e++)n.push(t[e])}e=e.right}return n},Ms=(t,n)=>{let e=0,r=t._start;for(t.doc??vs();null!==r;){if(r.countable&&!r.deleted){const i=r.content.getContent();for(let r=0;r<i.length;r++)n(i[r],e++,t)}r=r.right}},Ss=(t,n)=>{const e=[];return Ms(t,((r,i)=>{e.push(n(r,i,t))})),e},Cs=t=>{let n=t._start,e=null,r=0;return{[Symbol.iterator](){return this},next:()=>{if(null===e){for(;null!==n&&n.deleted;)n=n.right;if(null===n)return{done:!0,value:void 0};e=n.content.getContent(),r=0,n=n.right}const t=e[r++];return e.length<=r&&(e=null),{done:!1,value:t}}}},Us=(t,n)=>{t.doc??vs();const e=gs(t,n);let r=t._start;for(null!==e&&(r=e.p,n-=e.index);null!==r;r=r.right)if(!r.deleted&&r.countable){if(n<r.length)return r.content.getContent()[n];n-=r.length}},Es=(t,n,e,r)=>{let i=e;const s=t.doc,o=s.clientID,u=s.store,c=null===e?n._start:e.right;let h=[];const a=()=>{h.length>0&&(i=new Po(Ii(o,Pi(u,o)),i,i&&i.lastId,c,c&&c.id,n,null,new Ao(h)),i.integrate(t,0),h=[])};r.forEach((e=>{if(null===e)h.push(e);else switch(e.constructor){case Number:case Object:case Boolean:case Array:case String:h.push(e);break;default:switch(a(),e.constructor){case Uint8Array:case ArrayBuffer:i=new Po(Ii(o,Pi(u,o)),i,i&&i.lastId,c,c&&c.id,n,null,new fo(new Uint8Array(e))),i.integrate(t,0);break;case ui:i=new Po(Ii(o,Pi(u,o)),i,i&&i.lastId,c,c&&c.id,n,null,new wo(e)),i.integrate(t,0);break;default:if(!(e instanceof As))throw new Error("Unexpected content type in insert operation");i=new Po(Ii(o,Pi(u,o)),i,i&&i.lastId,c,c&&c.id,n,null,new Io(e)),i.integrate(t,0)}}})),a()},js=()=>gn("Length exceeded!"),Ts=(t,n,e,r)=>{if(e>n._length)throw js();if(0===e)return n._searchMarker&&bs(n._searchMarker,e,r.length),Es(t,n,null,r);const i=e,s=gs(n,e);let o=n._start;for(null!==s&&(o=s.p,0==(e-=s.index)&&(o=o.prev,e+=o&&o.countable&&!o.deleted?o.length:0));null!==o;o=o.right)if(!o.deleted&&o.countable){if(e<=o.length){e<o.length&&Fi(t,Ii(o.id.client,o.id.clock+e));break}e-=o.length}return n._searchMarker&&bs(n._searchMarker,i,r.length),Es(t,n,o,r)},Is=(t,n,e,r)=>{if(0===r)return;const i=e,s=r,o=gs(n,e);let u=n._start;for(null!==o&&(u=o.p,e-=o.index);null!==u&&e>0;u=u.right)!u.deleted&&u.countable&&(e<u.length&&Fi(t,Ii(u.id.client,u.id.clock+e)),e-=u.length);for(;r>0&&null!==u;)u.deleted||(r<u.length&&Fi(t,Ii(u.id.client,u.id.clock+r)),u.delete(t),r-=u.length),u=u.right;if(r>0)throw js();n._searchMarker&&bs(n._searchMarker,i,-s+r)},_s=(t,n,e)=>{const r=n._map.get(e);void 0!==r&&r.delete(t)},Os=(t,n,e,r)=>{const i=n._map.get(e)||null,s=t.doc,o=s.clientID;let u;if(null==r)u=new Ao([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:u=new Ao([r]);break;case Uint8Array:u=new fo(r);break;case ui:u=new wo(r);break;default:if(!(r instanceof As))throw new Error("Unexpected content type");u=new Io(r)}new Po(Ii(o,Pi(s.store,o)),i,i&&i.lastId,null,null,n,e,u).integrate(t,0)},zs=(t,n)=>{t.doc??vs();const e=t._map.get(n);return void 0===e||e.deleted?void 0:e.content.getContent()[e.length-1]},$s=t=>{const n={};return t.doc??vs(),t._map.forEach(((t,e)=>{t.deleted||(n[e]=t.content.getContent()[t.length-1])})),n},Ds=(t,n)=>{t.doc??vs();const e=t._map.get(n);return void 0!==e&&!e.deleted},Ps=t=>{return t.doc??vs(),n=t._map.entries(),e=t=>!t[1].deleted,Vr((()=>{let t;do{t=n.next()}while(!t.done&&!e(t.value));return t}));var n,e};class Rs extends fs{}class Bs extends As{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){const n=new Bs;return n.push(t),n}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Bs}clone(){const t=new Bs;return t.insert(0,this.toArray().map((t=>t instanceof As?t.clone():t))),t}get length(){return this.doc??vs(),this._length}_callObserver(t,n){super._callObserver(t,n),ms(this,t,new Rs(this,t))}insert(t,n){null!==this.doc?qi(this.doc,(e=>{Ts(e,this,t,n)})):this._prelimContent.splice(t,0,...n)}push(t){null!==this.doc?qi(this.doc,(n=>{((t,n,e)=>{let r=(n._searchMarker||[]).reduce(((t,n)=>n.index>t.index?n:t),{index:0,p:n._start}).p;if(r)for(;r.right;)r=r.right;Es(t,n,r,e)})(n,this,t)})):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,n=1){null!==this.doc?qi(this.doc,(e=>{Is(e,this,t,n)})):this._prelimContent.splice(t,n)}get(t){return Us(this,t)}toArray(){return xs(this)}slice(t=0,n=this.length){return ks(this,t,n)}toJSON(){return this.map((t=>t instanceof As?t.toJSON():t))}map(t){return Ss(this,t)}forEach(t){Ms(this,t)}[Symbol.iterator](){return Cs(this)}_write(t){t.writeTypeRef(Mo)}}class Ws extends fs{constructor(t,n,e){super(t,n),this.keysChanged=e}}class Ls extends As{constructor(t){super(),this._prelimContent=null,this._prelimContent=void 0===t?new Map:new Map(t)}_integrate(t,n){super._integrate(t,n),this._prelimContent.forEach(((t,n)=>{this.set(n,t)})),this._prelimContent=null}_copy(){return new Ls}clone(){const t=new Ls;return this.forEach(((n,e)=>{t.set(e,n instanceof As?n.clone():n)})),t}_callObserver(t,n){ms(this,t,new Ws(this,t,n))}toJSON(){this.doc??vs();const t={};return this._map.forEach(((n,e)=>{if(!n.deleted){const r=n.content.getContent()[n.length-1];t[e]=r instanceof As?r.toJSON():r}})),t}get size(){return[...Ps(this)].length}keys(){return Xr(Ps(this),(t=>t[0]))}values(){return Xr(Ps(this),(t=>t[1].content.getContent()[t[1].length-1]))}entries(){return Xr(Ps(this),(t=>[t[0],t[1].content.getContent()[t[1].length-1]]))}forEach(t){this.doc??vs(),this._map.forEach(((n,e)=>{n.deleted||t(n.content.getContent()[n.length-1],e,this)}))}[Symbol.iterator](){return this.entries()}delete(t){null!==this.doc?qi(this.doc,(n=>{_s(n,this,t)})):this._prelimContent.delete(t)}set(t,n){return null!==this.doc?qi(this.doc,(e=>{Os(e,this,t,n)})):this._prelimContent.set(t,n),n}get(t){return zs(this,t)}has(t){return Ds(this,t)}clear(){null!==this.doc?qi(this.doc,(t=>{this.forEach((function(n,e,r){_s(t,r,e)}))})):this._prelimContent.clear()}_write(t){t.writeTypeRef(So)}}const Fs=(t,n)=>t===n||"object"==typeof t&&"object"==typeof n&&t&&n&&((t,n)=>t===n||Zn(t)===Zn(n)&&te(t,((t,e)=>(void 0!==t||ne(n,e))&&Xn(n[e],t))))(t,n);class Ns{constructor(t,n,e,r){this.left=t,this.right=n,this.index=e,this.currentAttributes=r}forward(){null===this.right&&mn(),this.right.content.constructor===go?this.right.deleted||Hs(this.currentAttributes,this.right.content):this.right.deleted||(this.index+=this.right.length),this.left=this.right,this.right=this.right.right}}const Ks=(t,n,e)=>{for(;null!==n.right&&e>0;)n.right.content.constructor===go?n.right.deleted||Hs(n.currentAttributes,n.right.content):n.right.deleted||(e<n.right.length&&Fi(t,Ii(n.right.id.client,n.right.id.clock+e)),n.index+=n.right.length,e-=n.right.length),n.left=n.right,n.right=n.right.right;return n},Qs=(t,n,e,r)=>{const i=new Map,s=r?gs(n,e):null;if(s){const n=new Ns(s.p.left,s.p,s.index,i);return Ks(t,n,e-s.index)}{const r=new Ns(null,n._start,0,i);return Ks(t,r,e)}},Ys=(t,n,e,r)=>{for(;null!==e.right&&(!0===e.right.deleted||e.right.content.constructor===go&&Fs(r.get(e.right.content.key),e.right.content.value));)e.right.deleted||r.delete(e.right.content.key),e.forward();const i=t.doc,s=i.clientID;r.forEach(((r,o)=>{const u=e.left,c=e.right,h=new Po(Ii(s,Pi(i.store,s)),u,u&&u.lastId,c,c&&c.id,n,null,new go(o,r));h.integrate(t,0),e.right=h,e.forward()}))},Hs=(t,n)=>{const{key:e,value:r}=n;null===r?t.delete(e):t.set(e,r)},Vs=(t,n)=>{for(;null!==t.right&&(t.right.deleted||t.right.content.constructor===go&&Fs(n[t.right.content.key]??null,t.right.content.value));)t.forward()},Xs=(t,n,e,r)=>{const i=t.doc,s=i.clientID,o=new Map;for(const u in r){const c=r[u],h=e.currentAttributes.get(u)??null;if(!Fs(h,c)){o.set(u,h);const{left:r,right:a}=e;e.right=new Po(Ii(s,Pi(i.store,s)),r,r&&r.lastId,a,a&&a.id,n,null,new go(u,c)),e.right.integrate(t,0),e.forward()}}return o},qs=(t,n,e,r,i)=>{e.currentAttributes.forEach(((t,n)=>{void 0===i[n]&&(i[n]=null)}));const s=t.doc,o=s.clientID;Vs(e,i);const u=Xs(t,n,e,i),c=r.constructor===String?new ko(r):r instanceof As?new Io(r):new yo(r);let{left:h,right:a,index:l}=e;n._searchMarker&&bs(n._searchMarker,e.index,c.getLength()),a=new Po(Ii(o,Pi(s.store,o)),h,h&&h.lastId,a,a&&a.id,n,null,c),a.integrate(t,0),e.right=a,e.index=l,e.forward(),Ys(t,n,e,u)},Gs=(t,n,e,r,i)=>{const s=t.doc,o=s.clientID;Vs(e,i);const u=Xs(t,n,e,i);t:for(;null!==e.right&&(r>0||u.size>0&&(e.right.deleted||e.right.content.constructor===go));){if(!e.right.deleted)switch(e.right.content.constructor){case go:{const{key:n,value:s}=e.right.content,o=i[n];if(void 0!==o){if(Fs(o,s))u.delete(n);else{if(0===r)break t;u.set(n,s)}e.right.delete(t)}else e.currentAttributes.set(n,s);break}default:r<e.right.length&&Fi(t,Ii(e.right.id.client,e.right.id.clock+r)),r-=e.right.length}e.forward()}if(r>0){let i="";for(;r>0;r--)i+="\n";e.right=new Po(Ii(o,Pi(s.store,o)),e.left,e.left&&e.left.lastId,e.right,e.right&&e.right.id,n,null,new ko(i)),e.right.integrate(t,0),e.forward()}Ys(t,n,e,u)},Js=(t,n,e,r,i)=>{let s=n;const o=gt();for(;s&&(!s.countable||s.deleted);){if(!s.deleted&&s.content.constructor===go){const t=s.content;o.set(t.key,t)}s=s.right}let u=0,c=!1;for(;n!==s;){if(e===n&&(c=!0),!n.deleted){const e=n.content;switch(e.constructor){case go:{const{key:s,value:h}=e,a=r.get(s)??null;o.get(s)===e&&a!==h||(n.delete(t),u++,c||(i.get(s)??null)!==h||a===h||(null===a?i.delete(s):i.set(s,a))),c||n.deleted||Hs(i,e);break}}}n=n.right}return u},Zs=t=>{let n=0;return qi(t.doc,(e=>{let r=t._start,i=t._start,s=gt();const o=bt(s);for(;i;)!1===i.deleted&&(i.content.constructor===go?Hs(o,i.content):(n+=Js(e,r,i,s,o),s=bt(o),r=i)),i=i.right})),n},to=t=>{const n=new Set,e=t.doc;for(const[r,i]of t.afterState.entries()){const s=t.beforeState.get(r)||0;i!==s&&Ki(t,e.store.clients.get(r),s,i,(t=>{t.deleted||t.content.constructor!==go||t.constructor===lo||n.add(t.parent)}))}qi(e,(e=>{Jr(t,t.deleteSet,(t=>{t instanceof lo||!t.parent._hasFormatting||n.has(t.parent)||(t.content.constructor===go?n.add(t.parent):((t,n)=>{for(;n&&n.right&&(n.right.deleted||!n.right.countable);)n=n.right;const e=new Set;for(;n&&(n.deleted||!n.countable);){if(!n.deleted&&n.content.constructor===go){const r=n.content.key;e.has(r)?n.delete(t):e.add(r)}n=n.left}})(e,t))}));for(const t of n)Zs(t)}))},no=(t,n,e)=>{const r=e,i=bt(n.currentAttributes),s=n.right;for(;e>0&&null!==n.right;){if(!1===n.right.deleted)switch(n.right.content.constructor){case Io:case yo:case ko:e<n.right.length&&Fi(t,Ii(n.right.id.client,n.right.id.clock+e)),e-=n.right.length,n.right.delete(t)}n.forward()}s&&Js(t,s,n.right,i,n.currentAttributes);const o=(n.left||n.right).parent;return o._searchMarker&&bs(o._searchMarker,n.index,-r+e),n};class eo extends fs{constructor(t,n,e){super(t,n),this.childListChanged=!1,this.keysChanged=new Set,e.forEach((t=>{null===t?this.childListChanged=!0:this.keysChanged.add(t)}))}get changes(){if(null===this._changes){const t={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=t}return this._changes}get delta(){if(null===this._delta){const t=[];qi(this.target.doc,(n=>{const e=new Map,r=new Map;let i=this.target._start,s=null;const o={};let u="",c=0,h=0;const a=()=>{if(null!==s){let n=null;switch(s){case"delete":h>0&&(n={delete:h}),h=0;break;case"insert":("object"==typeof u||u.length>0)&&(n={insert:u},e.size>0&&(n.attributes={},e.forEach(((t,e)=>{null!==t&&(n.attributes[e]=t)})))),u="";break;case"retain":c>0&&(n={retain:c},(t=>{for(const n in t)return!1;return!0})(o)||(n.attributes=qn({},o))),c=0}n&&t.push(n),s=null}};for(;null!==i;){switch(i.content.constructor){case Io:case yo:this.adds(i)?this.deletes(i)||(a(),s="insert",u=i.content.getContent()[0],a()):this.deletes(i)?("delete"!==s&&(a(),s="delete"),h+=1):i.deleted||("retain"!==s&&(a(),s="retain"),c+=1);break;case ko:this.adds(i)?this.deletes(i)||("insert"!==s&&(a(),s="insert"),u+=i.content.str):this.deletes(i)?("delete"!==s&&(a(),s="delete"),h+=i.length):i.deleted||("retain"!==s&&(a(),s="retain"),c+=i.length);break;case go:{const{key:t,value:u}=i.content;if(this.adds(i)){if(!this.deletes(i)){const c=e.get(t)??null;Fs(c,u)?null!==u&&i.delete(n):("retain"===s&&a(),Fs(u,r.get(t)??null)?delete o[t]:o[t]=u)}}else if(this.deletes(i)){r.set(t,u);const n=e.get(t)??null;Fs(n,u)||("retain"===s&&a(),o[t]=n)}else if(!i.deleted){r.set(t,u);const e=o[t];void 0!==e&&(Fs(e,u)?null!==e&&i.delete(n):("retain"===s&&a(),null===u?delete o[t]:o[t]=u))}i.deleted||("insert"===s&&a(),Hs(e,i.content));break}}i=i.right}for(a();t.length>0;){const n=t[t.length-1];if(void 0===n.retain||void 0!==n.attributes)break;t.pop()}})),this._delta=t}return this._delta}}class ro extends As{constructor(t){super(),this._pending=void 0!==t?[()=>this.insert(0,t)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??vs(),this._length}_integrate(t,n){super._integrate(t,n);try{this._pending.forEach((t=>t()))}catch(t){console.error(t)}this._pending=null}_copy(){return new ro}clone(){const t=new ro;return t.applyDelta(this.toDelta()),t}_callObserver(t,n){super._callObserver(t,n);const e=new eo(this,t,n);ms(this,t,e),!t.local&&this._hasFormatting&&(t._needFormattingCleanup=!0)}toString(){this.doc??vs();let t="",n=this._start;for(;null!==n;)!n.deleted&&n.countable&&n.content.constructor===ko&&(t+=n.content.str),n=n.right;return t}toJSON(){return this.toString()}applyDelta(t,{sanitize:n=!0}={}){null!==this.doc?qi(this.doc,(e=>{const r=new Ns(null,this._start,0,new Map);for(let i=0;i<t.length;i++){const s=t[i];if(void 0!==s.insert){const o=n||"string"!=typeof s.insert||i!==t.length-1||null!==r.right||"\n"!==s.insert.slice(-1)?s.insert:s.insert.slice(0,-1);("string"!=typeof o||o.length>0)&&qs(e,this,r,o,s.attributes||{})}else void 0!==s.retain?Gs(e,this,r,s.retain,s.attributes||{}):void 0!==s.delete&&no(e,r,s.delete)}})):this._pending.push((()=>this.applyDelta(t)))}toDelta(t,n,e){this.doc??vs();const r=[],i=new Map;let s="",o=this._start;function u(){if(s.length>0){const t={};let n=!1;i.forEach(((e,r)=>{n=!0,t[r]=e}));const e={insert:s};n&&(e.attributes=t),r.push(e),s=""}}const c=()=>{for(;null!==o;){if(Oi(o,t)||void 0!==n&&Oi(o,n))switch(o.content.constructor){case ko:{const r=i.get("ychange");void 0===t||Oi(o,t)?void 0===n||Oi(o,n)?void 0!==r&&(u(),i.delete("ychange")):void 0!==r&&r.user===o.id.client&&"added"===r.type||(u(),i.set("ychange",e?e("added",o.id):{type:"added"})):void 0!==r&&r.user===o.id.client&&"removed"===r.type||(u(),i.set("ychange",e?e("removed",o.id):{type:"removed"})),s+=o.content.str;break}case Io:case yo:{u();const t={insert:o.content.getContent()[0]};if(i.size>0){const n={};t.attributes=n,i.forEach(((t,e)=>{n[e]=t}))}r.push(t);break}case go:Oi(o,t)&&(u(),Hs(i,o.content))}o=o.right}u()};return t||n?qi(this.doc,(e=>{t&&zi(e,t),n&&zi(e,n),c()}),"cleanup"):c(),r}insert(t,n,e){if(n.length<=0)return;const r=this.doc;null!==r?qi(r,(r=>{const i=Qs(r,this,t,!e);e||(e={},i.currentAttributes.forEach(((t,n)=>{e[n]=t}))),qs(r,this,i,n,e)})):this._pending.push((()=>this.insert(t,n,e)))}insertEmbed(t,n,e){const r=this.doc;null!==r?qi(r,(r=>{const i=Qs(r,this,t,!e);qs(r,this,i,n,e||{})})):this._pending.push((()=>this.insertEmbed(t,n,e||{})))}delete(t,n){if(0===n)return;const e=this.doc;null!==e?qi(e,(e=>{no(e,Qs(e,this,t,!0),n)})):this._pending.push((()=>this.delete(t,n)))}format(t,n,e){if(0===n)return;const r=this.doc;null!==r?qi(r,(r=>{const i=Qs(r,this,t,!1);null!==i.right&&Gs(r,this,i,n,e)})):this._pending.push((()=>this.format(t,n,e)))}removeAttribute(t){null!==this.doc?qi(this.doc,(n=>{_s(n,this,t)})):this._pending.push((()=>this.removeAttribute(t)))}setAttribute(t,n){null!==this.doc?qi(this.doc,(e=>{Os(e,this,t,n)})):this._pending.push((()=>this.setAttribute(t,n)))}getAttribute(t){return zs(this,t)}getAttributes(){return $s(this)}_write(t){t.writeTypeRef(Co)}}class io{constructor(t,n=()=>!0){this._filter=n,this._root=t,this._currentNode=t._start,this._firstCall=!0,t.doc??vs()}[Symbol.iterator](){return this}next(){let t=this._currentNode,n=t&&t.content&&t.content.type;if(null!==t&&(!this._firstCall||t.deleted||!this._filter(n)))do{if(n=t.content.type,t.deleted||n.constructor!==oo&&n.constructor!==so||null===n._start)for(;null!==t;){const n=t.next;if(null!==n){t=n;break}t=t.parent===this._root?null:t.parent._item}else t=n._start}while(null!==t&&(t.deleted||!this._filter(t.content.type)));return this._firstCall=!1,null===t?{value:void 0,done:!0}:(this._currentNode=t,{value:t.content.type,done:!1})}}class so extends As{constructor(){super(),this._prelimContent=[]}get firstChild(){const t=this._first;return t?t.content.getContent()[0]:null}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new so}clone(){const t=new so;return t.insert(0,this.toArray().map((t=>t instanceof As?t.clone():t))),t}get length(){return this.doc??vs(),null===this._prelimContent?this._length:this._prelimContent.length}createTreeWalker(t){return new io(this,t)}querySelector(t){t=t.toUpperCase();const n=new io(this,(n=>n.nodeName&&n.nodeName.toUpperCase()===t)).next();return n.done?null:n.value}querySelectorAll(t){return t=t.toUpperCase(),Mt(new io(this,(n=>n.nodeName&&n.nodeName.toUpperCase()===t)))}_callObserver(t,n){ms(this,t,new uo(this,n,t))}toString(){return Ss(this,(t=>t.toString())).join("")}toJSON(){return this.toString()}toDOM(t=document,n={},e){const r=t.createDocumentFragment();return void 0!==e&&e._createAssociation(r,this),Ms(this,(i=>{r.insertBefore(i.toDOM(t,n,e),null)})),r}insert(t,n){null!==this.doc?qi(this.doc,(e=>{Ts(e,this,t,n)})):this._prelimContent.splice(t,0,...n)}insertAfter(t,n){if(null!==this.doc)qi(this.doc,(e=>{Es(e,this,t&&t instanceof As?t._item:t,n)}));else{const e=this._prelimContent,r=null===t?0:e.findIndex((n=>n===t))+1;if(0===r&&null!==t)throw gn("Reference item not found");e.splice(r,0,...n)}}delete(t,n=1){null!==this.doc?qi(this.doc,(e=>{Is(e,this,t,n)})):this._prelimContent.splice(t,n)}toArray(){return xs(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return Us(this,t)}slice(t=0,n=this.length){return ks(this,t,n)}forEach(t){Ms(this,t)}_write(t){t.writeTypeRef(Eo)}}class oo extends so{constructor(t="UNDEFINED"){super(),this.nodeName=t,this._prelimAttrs=new Map}get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_integrate(t,n){super._integrate(t,n),this._prelimAttrs.forEach(((t,n)=>{this.setAttribute(n,t)})),this._prelimAttrs=null}_copy(){return new oo(this.nodeName)}clone(){const t=new oo(this.nodeName);return((t,n)=>{for(const e in t)n(t[e],e)})(this.getAttributes(),((n,e)=>{t.setAttribute(e,n)})),t.insert(0,this.toArray().map((t=>t instanceof As?t.clone():t))),t}toString(){const t=this.getAttributes(),n=[],e=[];for(const n in t)e.push(n);e.sort();const r=e.length;for(let i=0;i<r;i++){const r=e[i];n.push(r+'="'+t[r]+'"')}const i=this.nodeName.toLocaleLowerCase();return`<${i}${n.length>0?" "+n.join(" "):""}>${super.toString()}</${i}>`}removeAttribute(t){null!==this.doc?qi(this.doc,(n=>{_s(n,this,t)})):this._prelimAttrs.delete(t)}setAttribute(t,n){null!==this.doc?qi(this.doc,(e=>{Os(e,this,t,n)})):this._prelimAttrs.set(t,n)}getAttribute(t){return zs(this,t)}hasAttribute(t){return Ds(this,t)}getAttributes(t){return t?((t,n)=>{const e={};return this._map.forEach(((t,r)=>{let i=t;for(;null!==i&&(!n.sv.has(i.id.client)||i.id.clock>=(n.sv.get(i.id.client)||0));)i=i.left;null!==i&&Oi(i,n)&&(e[r]=i.content.getContent()[i.length-1])})),e})(0,t):$s(this)}toDOM(t=document,n={},e){const r=t.createElement(this.nodeName),i=this.getAttributes();for(const t in i){const n=i[t];"string"==typeof n&&r.setAttribute(t,n)}return Ms(this,(i=>{r.appendChild(i.toDOM(t,n,e))})),void 0!==e&&e._createAssociation(r,this),r}_write(t){t.writeTypeRef(Uo),t.writeKey(this.nodeName)}}class uo extends fs{constructor(t,n,e){super(t,e),this.childListChanged=!1,this.attributesChanged=new Set,n.forEach((t=>{null===t?this.childListChanged=!0:this.attributesChanged.add(t)}))}}class co extends Ls{constructor(t){super(),this.hookName=t}_copy(){return new co(this.hookName)}clone(){const t=new co(this.hookName);return this.forEach(((n,e)=>{t.set(e,n)})),t}toDOM(t=document,n={},e){const r=n[this.hookName];let i;return i=void 0!==r?r.createDom(this):document.createElement(this.hookName),i.setAttribute("data-yjs-hook",this.hookName),void 0!==e&&e._createAssociation(i,this),i}_write(t){t.writeTypeRef(jo),t.writeKey(this.hookName)}}class ho extends ro{get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_copy(){return new ho}clone(){const t=new ho;return t.applyDelta(this.toDelta()),t}toDOM(t=document,n,e){const r=t.createTextNode(this.toString());return void 0!==e&&e._createAssociation(r,this),r}toString(){return this.toDelta().map((t=>{const n=[];for(const e in t.attributes){const r=[];for(const n in t.attributes[e])r.push({key:n,value:t.attributes[e][n]});r.sort(((t,n)=>t.key<n.key?-1:1)),n.push({nodeName:e,attrs:r})}n.sort(((t,n)=>t.nodeName<n.nodeName?-1:1));let e="";for(let t=0;t<n.length;t++){const r=n[t];e+=`<${r.nodeName}`;for(let t=0;t<r.attrs.length;t++){const n=r.attrs[t];e+=` ${n.key}="${n.value}"`}e+=">"}e+=t.insert;for(let t=n.length-1;t>=0;t--)e+=`</${n[t].nodeName}>`;return e})).join("")}toJSON(){return this.toString()}_write(t){t.writeTypeRef(To)}}class ao{constructor(t,n){this.id=t,this.length=n}get deleted(){throw bn()}mergeWith(t){return!1}write(t,n,e){throw bn()}integrate(t,n){throw bn()}}class lo extends ao{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor===t.constructor&&(this.length+=t.length,!0)}integrate(t,n){n>0&&(this.id.clock+=n,this.length-=n),Ri(t.doc.store,this)}write(t,n){t.writeInfo(0),t.writeLen(this.length-n)}getMissing(t,n){return null}}class fo{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new fo(this.content)}splice(t){throw bn()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeBuf(this.content)}getRef(){return 3}}class vo{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new vo(this.len)}splice(t){const n=new vo(this.len-t);return this.len=t,n}mergeWith(t){return this.len+=t.len,!0}integrate(t,n){ei(t.deleteSet,n.id.client,n.id.clock,this.len),n.markDeleted()}delete(t){}gc(t){}write(t,n){t.writeLen(this.len-n)}getRef(){return 1}}const po=(t,n)=>new ui({guid:t,...n,shouldLoad:n.shouldLoad||n.autoLoad||!1});class wo{constructor(t){t._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=t;const n={};this.opts=n,t.gc||(n.gc=!1),t.autoLoad&&(n.autoLoad=!0),null!==t.meta&&(n.meta=t.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new wo(po(this.doc.guid,this.opts))}splice(t){throw bn()}mergeWith(t){return!1}integrate(t,n){this.doc._item=n,t.subdocsAdded.add(this.doc),this.doc.shouldLoad&&t.subdocsLoaded.add(this.doc)}delete(t){t.subdocsAdded.has(this.doc)?t.subdocsAdded.delete(this.doc):t.subdocsRemoved.add(this.doc)}gc(t){}write(t,n){t.writeString(this.doc.guid),t.writeAny(this.opts)}getRef(){return 9}}class yo{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new yo(this.embed)}splice(t){throw bn()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeJSON(this.embed)}getRef(){return 5}}class go{constructor(t,n){this.key=t,this.value=n}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new go(this.key,this.value)}splice(t){throw bn()}mergeWith(t){return!1}integrate(t,n){const e=n.parent;e._searchMarker=null,e._hasFormatting=!0}delete(t){}gc(t){}write(t,n){t.writeKey(this.key),t.writeJSON(this.value)}getRef(){return 6}}class bo{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new bo(this.arr)}splice(t){const n=new bo(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){const e=this.arr.length;t.writeLen(e-n);for(let r=n;r<e;r++){const n=this.arr[r];t.writeString(void 0===n?"undefined":JSON.stringify(n))}}getRef(){return 2}}const mo="development"===le("node_env");class Ao{constructor(t){this.arr=t,mo&&re(t)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Ao(this.arr)}splice(t){const n=new Ao(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){const e=this.arr.length;t.writeLen(e-n);for(let r=n;r<e;r++)t.writeAny(this.arr[r])}getRef(){return 8}}class ko{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new ko(this.str)}splice(t){const n=new ko(this.str.slice(t));this.str=this.str.slice(0,t);const e=this.str.charCodeAt(t-1);return e>=55296&&e<=56319&&(this.str=this.str.slice(0,t-1)+"�",n.str="�"+n.str.slice(1)),n}mergeWith(t){return this.str+=t.str,!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeString(0===n?this.str:this.str.slice(n))}getRef(){return 4}}const xo=[()=>new Bs,()=>new Ls,()=>new ro,t=>new oo(t.readKey()),()=>new so,t=>new co(t.readKey()),()=>new ho],Mo=0,So=1,Co=2,Uo=3,Eo=4,jo=5,To=6;class Io{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new Io(this.type._copy())}splice(t){throw bn()}mergeWith(t){return!1}integrate(t,n){this.type._integrate(t.doc,n)}delete(t){let n=this.type._start;for(;null!==n;)n.deleted?n.id.clock<(t.beforeState.get(n.id.client)||0)&&t._mergeStructs.push(n):n.delete(t),n=n.right;this.type._map.forEach((n=>{n.deleted?n.id.clock<(t.beforeState.get(n.id.client)||0)&&t._mergeStructs.push(n):n.delete(t)})),t.changed.delete(this.type)}gc(t){let n=this.type._start;for(;null!==n;)n.gc(t,!0),n=n.right;this.type._start=null,this.type._map.forEach((n=>{for(;null!==n;)n.gc(t,!0),n=n.left})),this.type._map=new Map}write(t,n){this.type._write(t)}getRef(){return 7}}const _o=(t,n)=>{let e,r=n,i=0;do{i>0&&(r=Ii(r.client,r.clock+i)),e=Wi(t,r),i=r.clock-e.id.clock,r=e.redone}while(null!==r&&e instanceof Po);return{item:e,diff:i}},Oo=(t,n)=>{for(;null!==t&&t.keep!==n;)t.keep=n,t=t.parent._item},zo=(t,n,e)=>{const{client:r,clock:i}=n.id,s=new Po(Ii(r,i+e),n,Ii(r,i+e-1),n.right,n.rightOrigin,n.parent,n.parentSub,n.content.splice(e));return n.deleted&&s.markDeleted(),n.keep&&(s.keep=!0),null!==n.redone&&(s.redone=Ii(n.redone.client,n.redone.clock+e)),n.right=s,null!==s.right&&(s.right.left=s),t._mergeStructs.push(s),null!==s.parentSub&&null===s.right&&s.parent._map.set(s.parentSub,s),n.length=e,s},$o=(t,n)=>Ct(t,(t=>Zr(t.deletions,n))),Do=(t,n,e,r,i,s)=>{const o=t.doc,u=o.store,c=o.clientID,h=n.redone;if(null!==h)return Fi(t,h);let a,l=n.parent._item,f=null;if(null!==l&&!0===l.deleted){if(null===l.redone&&(!e.has(l)||null===Do(t,l,e,r,i,s)))return null;for(;null!==l.redone;)l=Fi(t,l.redone)}const d=null===l?n.parent:l.content.type;if(null===n.parentSub){for(f=n.left,a=n;null!==f;){let n=f;for(;null!==n&&n.parent._item!==l;)n=null===n.redone?null:Fi(t,n.redone);if(null!==n&&n.parent._item===l){f=n;break}f=f.left}for(;null!==a;){let n=a;for(;null!==n&&n.parent._item!==l;)n=null===n.redone?null:Fi(t,n.redone);if(null!==n&&n.parent._item===l){a=n;break}a=a.right}}else if(a=null,n.right&&!i){for(f=n;null!==f&&null!==f.right&&(f.right.redone||Zr(r,f.right.id)||$o(s.undoStack,f.right.id)||$o(s.redoStack,f.right.id));)for(f=f.right;f.redone;)f=Fi(t,f.redone);if(f&&null!==f.right)return null}else f=d._map.get(n.parentSub)||null;const v=Pi(u,c),p=Ii(c,v),w=new Po(p,f,f&&f.lastId,a,a&&a.id,d,n.parentSub,n.content.copy());return n.redone=p,Oo(w,!0),w.integrate(t,0),w};class Po extends ao{constructor(t,n,e,r,i,s,o,u){super(t,u.getLength()),this.origin=e,this.left=n,this.right=r,this.rightOrigin=i,this.parent=s,this.parentSub=o,this.redone=null,this.content=u,this.info=this.content.isCountable()?2:0}set marker(t){(8&this.info)>0!==t&&(this.info^=8)}get marker(){return(8&this.info)>0}get keep(){return(1&this.info)>0}set keep(t){this.keep!==t&&(this.info^=1)}get countable(){return(2&this.info)>0}get deleted(){return(4&this.info)>0}set deleted(t){this.deleted!==t&&(this.info^=4)}markDeleted(){this.info|=4}getMissing(t,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=Pi(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=Pi(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===ji&&this.id.client!==this.parent.client&&this.parent.clock>=Pi(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=Ni(t,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=Fi(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===lo||this.right&&this.right.constructor===lo)this.parent=null;else if(this.parent){if(this.parent.constructor===ji){const t=Wi(n,this.parent);this.parent=t.constructor===lo?null:t.content.type}}else this.left&&this.left.constructor===Po?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===Po&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);return null}integrate(t,n){if(n>0&&(this.id.clock+=n,this.left=Ni(t,t.doc.store,Ii(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(n),this.length-=n),this.parent){if(!this.left&&(!this.right||null!==this.right.left)||this.left&&this.left.right!==this.right){let n,e=this.left;if(null!==e)n=e.right;else if(null!==this.parentSub)for(n=this.parent._map.get(this.parentSub)||null;null!==n&&null!==n.left;)n=n.left;else n=this.parent._start;const r=new Set,i=new Set;for(;null!==n&&n!==this.right;){if(i.add(n),r.add(n),Ti(this.origin,n.origin)){if(n.id.client<this.id.client)e=n,r.clear();else if(Ti(this.rightOrigin,n.rightOrigin))break}else{if(null===n.origin||!i.has(Wi(t.doc.store,n.origin)))break;r.has(Wi(t.doc.store,n.origin))||(e=n,r.clear())}n=n.right}this.left=e}if(null!==this.left)this.right=this.left.right,this.left.right=this;else{let t;if(null!==this.parentSub)for(t=this.parent._map.get(this.parentSub)||null;null!==t&&null!==t.left;)t=t.left;else t=this.parent._start,this.parent._start=this;this.right=t}null!==this.right?this.right.left=this:null!==this.parentSub&&(this.parent._map.set(this.parentSub,this),null!==this.left&&this.left.delete(t)),null===this.parentSub&&this.countable&&!this.deleted&&(this.parent._length+=this.length),Ri(t.doc.store,this),this.content.integrate(t,this),Hi(t,this.parent,this.parentSub),(null!==this.parent._item&&this.parent._item.deleted||null!==this.parentSub&&null!==this.right)&&this.delete(t)}else new lo(this.id,this.length).integrate(t,0)}get next(){let t=this.right;for(;null!==t&&t.deleted;)t=t.right;return t}get prev(){let t=this.left;for(;null!==t&&t.deleted;)t=t.left;return t}get lastId(){return 1===this.length?this.id:Ii(this.id.client,this.id.clock+this.length-1)}mergeWith(t){if(this.constructor===t.constructor&&Ti(t.origin,this.lastId)&&this.right===t&&Ti(this.rightOrigin,t.rightOrigin)&&this.id.client===t.id.client&&this.id.clock+this.length===t.id.clock&&this.deleted===t.deleted&&null===this.redone&&null===t.redone&&this.content.constructor===t.content.constructor&&this.content.mergeWith(t.content)){const n=this.parent._searchMarker;return n&&n.forEach((n=>{n.p===t&&(n.p=this,!this.deleted&&this.countable&&(n.index-=this.length))})),t.keep&&(this.keep=!0),this.right=t.right,null!==this.right&&(this.right.left=this),this.length+=t.length,!0}return!1}delete(t){if(!this.deleted){const n=this.parent;this.countable&&null===this.parentSub&&(n._length-=this.length),this.markDeleted(),ei(t.deleteSet,this.id.client,this.id.clock,this.length),Hi(t,n,this.parentSub),this.content.delete(t)}}gc(t,n){if(!this.deleted)throw mn();this.content.gc(t),n?((t,n,e)=>{const r=t.clients.get(n.id.client);r[Bi(r,n.id.clock)]=e})(t,this,new lo(this.id,this.length)):this.content=new vo(this.length)}write(t,n){const e=n>0?Ii(this.id.client,this.id.clock+n-1):this.origin,r=this.rightOrigin,i=this.parentSub,s=31&this.content.getRef()|(null===e?0:Pt)|(null===r?0:Dt)|(null===i?0:32);if(t.writeInfo(s),null!==e&&t.writeLeftID(e),null!==r&&t.writeRightID(r),null===e&&null===r){const n=this.parent;if(void 0!==n._item){const e=n._item;if(null===e){const e=(t=>{for(const[n,e]of t.doc.share.entries())if(e===t)return n;throw mn()})(n);t.writeParentInfo(!0),t.writeString(e)}else t.writeParentInfo(!1),t.writeLeftID(e.id)}else n.constructor===String?(t.writeParentInfo(!0),t.writeString(n)):n.constructor===ji?(t.writeParentInfo(!1),t.writeLeftID(n)):mn();null!==i&&t.writeString(i)}this.content.write(t,n)}}const Ro=(t,n)=>Bo[31&n](t),Bo=[()=>{mn()},t=>new vo(t.readLen()),t=>{const n=t.readLen(),e=[];for(let r=0;r<n;r++){const n=t.readString();e.push("undefined"===n?void 0:JSON.parse(n))}return new bo(e)},t=>new fo(t.readBuf()),t=>new ko(t.readString()),t=>new yo(t.readJSON()),t=>new go(t.readKey(),t.readJSON()),t=>new Io(xo[t.readTypeRef()](t)),t=>{const n=t.readLen(),e=[];for(let r=0;r<n;r++)e.push(t.readAny());return new Ao(e)},t=>new wo(po(t.readString(),t.readAny())),()=>{mn()}];class Wo extends ao{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor===t.constructor&&(this.length+=t.length,!0)}integrate(t,n){mn()}write(t,n){t.writeInfo(10),nn(t.restEncoder,this.length-n)}getMissing(t,n){return null}}const Lo="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},Fo="__ $YJS$ __";!0===Lo[Fo]&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438"),Lo[Fo]=!0;const No=t=>Fn(((n,e)=>{t.onerror=t=>e(new Error(t.target.error)),t.onsuccess=t=>n(t.target.result)})),Ko=(t,n,e="readwrite")=>{const r=t.transaction(n,e);return n.map((t=>Xo(r,t)))},Qo=(t,n)=>No(t.count(n)),Yo=(t,n)=>No(t.delete(n)),Ho=(t,n)=>No(t.add(n)),Vo=(t,n,e,r="next")=>((t,n)=>Fn(((e,r)=>{t.onerror=r,t.onsuccess=async t=>{const r=t.target.result;if(null===r||!1===await n(r))return e();r.continue()}})))(t.openKeyCursor(n,r),(t=>e(t.key))),Xo=(t,n)=>t.objectStore(n),qo="custom",Go="updates",Jo=(t,n=()=>{},e=()=>{})=>{const[r]=Ko(t.db,[Go]);return(i=r,o=t._dbref,s=IDBKeyRange.lowerBound(o,false),No(i.getAll(s,undefined))).then((i=>{t._destroyed||(n(r),qi(t.doc,(()=>{i.forEach((n=>gi(t.doc,n)))}),t,!1),e(r))})).then((()=>((t,n=null)=>((t,n)=>{let e=null;return Vo(t,n,(t=>(e=t,!1)),"prev").then((()=>e))})(t,n))(r).then((n=>{t._dbref=n+1})))).then((()=>Qo(r).then((n=>{t._dbsize=n})))).then((()=>r));var i,s,o};class Zo extends jt{constructor(t,n){super(),this.doc=n,this.name=t,this._dbref=0,this._dbsize=0,this._destroyed=!1,this.db=null,this.synced=!1,this._db=(t=>Fn(((n,e)=>{const r=indexedDB.open(t);r.onupgradeneeded=t=>(t=>[["updates",{autoIncrement:!0}],["custom"]].forEach((n=>t.createObjectStore.apply(t,n))))(t.target.result),r.onerror=t=>e(gn(t.target.error)),r.onsuccess=t=>{const e=t.target.result;e.onversionchange=()=>{e.close()},n(e)}})))(t),this.whenSynced=Fn((t=>this.on("synced",(()=>t(this))))),this._db.then((t=>{this.db=t,Jo(this,(t=>Ho(t,mi(n))),(()=>{if(this._destroyed)return this;this.synced=!0,this.emit("synced",[this])}))})),this._storeTimeout=1e3,this._storeTimeoutId=null,this._storeUpdate=(t,n)=>{if(this.db&&n!==this){const[n]=Ko(this.db,[Go]);Ho(n,t),++this._dbsize>=500&&(null!==this._storeTimeoutId&&clearTimeout(this._storeTimeoutId),this._storeTimeoutId=setTimeout((()=>{((t,n=!0)=>{Jo(t).then((e=>{(n||t._dbsize>=500)&&Ho(e,mi(t.doc)).then((()=>Yo(e,IDBKeyRange.upperBound(t._dbref,!0)))).then((()=>Qo(e).then((n=>{t._dbsize=n}))))}))})(this,!1),this._storeTimeoutId=null}),this._storeTimeout))}},n.on("update",this._storeUpdate),this.destroy=this.destroy.bind(this),n.on("destroy",this.destroy)}destroy(){return this._storeTimeoutId&&clearTimeout(this._storeTimeoutId),this.doc.off("update",this._storeUpdate),this.doc.off("destroy",this.destroy),this._destroyed=!0,this._db.then((t=>{t.close()}))}clearData(){return this.destroy().then((()=>{No(indexedDB.deleteDatabase(this.name))}))}get(t){return this._db.then((n=>{const[e]=Ko(n,[qo],"readonly");return((t,n)=>No(t.get(n)))(e,t)}))}set(t,n){return this._db.then((e=>{const[r]=Ko(e,[qo]);return((t,n,e)=>No(t.put(n,e)))(r,n,t)}))}del(t){return this._db.then((n=>{const[e]=Ko(n,[qo]);return Yo(e,t)}))}}class tu{provider;isConnected=!1;constructor(t,n,e){this.provider=new Zo(e?.name||t,n)}async connect(){if(!this.isConnected)return new Promise((t=>{this.provider.on("synced",(()=>{this.isConnected=!0,t()}))}))}disconnect(){this.isConnected=!1}destroy(){this.provider&&this.provider.destroy(),this.isConnected=!1}}const nu=Math.floor,eu=127,ru=Number.MAX_SAFE_INTEGER,iu="undefined"!=typeof TextEncoder?new TextEncoder:null,su=iu?t=>iu.encode(t):t=>{const n=unescape(encodeURIComponent(t)),e=n.length,r=new Uint8Array(e);for(let t=0;t<e;t++)r[t]=n.codePointAt(t);return r};let ou="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});ou&&1===ou.decode(new Uint8Array).length&&(ou=null);const uu=(t,n)=>{const e=t.cbuf.length;t.cpos===e&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(2*e),t.cpos=0),t.cbuf[t.cpos++]=n},cu=(t,n)=>{for(;n>eu;)uu(t,128|eu&n),n=nu(n/128);uu(t,eu&n)},hu=new Uint8Array(3e4),au=hu.length/3,lu=iu&&iu.encodeInto?(t,n)=>{if(n.length<au){const e=iu.encodeInto(n,hu).written||0;cu(t,e);for(let n=0;n<e;n++)uu(t,hu[n])}else fu(t,su(n))}:(t,n)=>{const e=unescape(encodeURIComponent(n)),r=e.length;cu(t,r);for(let n=0;n<r;n++)uu(t,e.codePointAt(n))},fu=(t,n)=>{cu(t,n.byteLength),((t,n)=>{const e=t.cbuf.length,r=t.cpos,i=((t,n)=>t<n?t:n)(e-r,n.length),s=n.length-i;t.cbuf.set(n.subarray(0,i),r),t.cpos+=i,s>0&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(((t,n)=>t>n?t:n)(2*e,s)),t.cbuf.set(n.subarray(i)),t.cpos=s)})(t,n)},du=t=>new Error(t),vu=du("Unexpected end of array"),pu=du("Integer out of Range"),wu=t=>t.arr[t.pos++],yu=t=>{let n=0,e=1;const r=t.arr.length;for(;t.pos<r;){const r=t.arr[t.pos++];if(n+=(r&eu)*e,e*=128,r<128)return n;if(n>ru)throw pu}throw vu},gu=ou?t=>ou.decode((t=>((t,n)=>{const e=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,n);return t.pos+=n,e})(t,yu(t)))(t)):t=>{let n=yu(t);if(0===n)return"";{let e=String.fromCodePoint(wu(t));if(--n<100)for(;n--;)e+=String.fromCodePoint(wu(t));else for(;n>0;){const r=n<1e4?n:1e4,i=t.arr.subarray(t.pos,t.pos+r);t.pos+=r,e+=String.fromCodePoint.apply(null,i),n-=r}return decodeURIComponent(escape(e))}};var bu;!function(t){t[t.Token=0]="Token",t[t.PermissionDenied=1]="PermissionDenied",t[t.Authenticated=2]="Authenticated"}(bu||(bu={}));const mu=t=>Array.from(t.entries()).map((([t,n])=>({clientId:t,...n})));var Au;async function ku(t){return new Promise((n=>setTimeout(n,t)))}function xu(t,n){let e=n.delay;if(0===e)return 0;if(n.factor&&(e*=Math.pow(n.factor,t.attemptNum-1),0!==n.maxDelay&&(e=Math.min(e,n.maxDelay))),n.jitter){const t=Math.ceil(n.minDelay),r=Math.floor(e);e=Math.floor(Math.random()*(r-t+1))+t}return Math.round(e)}!function(t){t[t.Connecting=0]="Connecting",t[t.Open=1]="Open",t[t.Closing=2]="Closing",t[t.Closed=3]="Closed"}(Au||(Au={}));const Mu=Math.floor,Su=128,Cu=127,Uu=Number.MAX_SAFE_INTEGER,Eu=()=>new Set,ju=Array.from,Tu="undefined"!=typeof TextEncoder?new TextEncoder:null,Iu=Tu?t=>Tu.encode(t):t=>{const n=unescape(encodeURIComponent(t)),e=n.length,r=new Uint8Array(e);for(let t=0;t<e;t++)r[t]=n.codePointAt(t);return r};let _u="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});_u&&1===_u.decode(new Uint8Array).length&&(_u=null);class Ou{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const zu=()=>new Ou,$u=t=>{let n=t.cpos;for(let e=0;e<t.bufs.length;e++)n+=t.bufs[e].length;return n},Du=t=>{const n=new Uint8Array($u(t));let e=0;for(let r=0;r<t.bufs.length;r++){const i=t.bufs[r];n.set(i,e),e+=i.length}return n.set(new Uint8Array(t.cbuf.buffer,0,t.cpos),e),n},Pu=(t,n)=>{const e=t.cbuf.length;t.cpos===e&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(2*e),t.cpos=0),t.cbuf[t.cpos++]=n},Ru=(t,n)=>{for(;n>Cu;)Pu(t,Su|Cu&n),n=Mu(n/128);Pu(t,Cu&n)},Bu=new Uint8Array(3e4),Wu=Bu.length/3,Lu=Tu&&Tu.encodeInto?(t,n)=>{if(n.length<Wu){const e=Tu.encodeInto(n,Bu).written||0;Ru(t,e);for(let n=0;n<e;n++)Pu(t,Bu[n])}else Fu(t,Iu(n))}:(t,n)=>{const e=unescape(encodeURIComponent(n)),r=e.length;Ru(t,r);for(let n=0;n<r;n++)Pu(t,e.codePointAt(n))},Fu=(t,n)=>{Ru(t,n.byteLength),((t,n)=>{const e=t.cbuf.length,r=t.cpos,i=((t,n)=>t<n?t:n)(e-r,n.length),s=n.length-i;t.cbuf.set(n.subarray(0,i),r),t.cpos+=i,s>0&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(((t,n)=>t>n?t:n)(2*e,s)),t.cbuf.set(n.subarray(i)),t.cpos=s)})(t,n)},Nu=t=>new Error(t),Ku=Nu("Unexpected end of array"),Qu=Nu("Integer out of Range");class Yu{constructor(t){this.arr=t,this.pos=0}}const Hu=t=>new Yu(t),Vu=t=>((t,n)=>{const e=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,n);return t.pos+=n,e})(t,qu(t)),Xu=t=>t.arr[t.pos++],qu=t=>{let n=0,e=1;const r=t.arr.length;for(;t.pos<r;){const r=t.arr[t.pos++];if(n+=(r&Cu)*e,e*=128,r<Su)return n;if(n>Uu)throw Qu}throw Ku},Gu=_u?t=>_u.decode(Vu(t)):t=>{let n=qu(t);if(0===n)return"";{let e=String.fromCodePoint(Xu(t));if(--n<100)for(;n--;)e+=String.fromCodePoint(Xu(t));else for(;n>0;){const r=n<1e4?n:1e4,i=t.arr.subarray(t.pos,t.pos+r);t.pos+=r,e+=String.fromCodePoint.apply(null,i),n-=r}return decodeURIComponent(escape(e))}},Ju=Date.now,Zu=()=>new Map;class tc{constructor(){this._observers=Zu()}on(t,n){((t,n,e)=>{let r=t.get(n);return void 0===r&&t.set(n,r=e()),r})(this._observers,t,Eu).add(n)}once(t,n){const e=(...r)=>{this.off(t,e),n(...r)};this.on(t,e)}off(t,n){const e=this._observers.get(t);void 0!==e&&(e.delete(n),0===e.size&&this._observers.delete(t))}emit(t,n){return ju((this._observers.get(t)||Zu()).values()).forEach((t=>t(...n)))}destroy(){this._observers=Zu()}}const nc=Object.keys,ec=t=>nc(t).length,rc=(t,n)=>Object.prototype.hasOwnProperty.call(t,n),ic=(t,n)=>{if(null==t||null==n)return((t,n)=>t===n)(t,n);if(t.constructor!==n.constructor)return!1;if(t===n)return!0;switch(t.constructor){case ArrayBuffer:t=new Uint8Array(t),n=new Uint8Array(n);case Uint8Array:if(t.byteLength!==n.byteLength)return!1;for(let e=0;e<t.length;e++)if(t[e]!==n[e])return!1;break;case Set:if(t.size!==n.size)return!1;for(const e of t)if(!n.has(e))return!1;break;case Map:if(t.size!==n.size)return!1;for(const e of t.keys())if(!n.has(e)||!ic(t.get(e),n.get(e)))return!1;break;case Object:if(ec(t)!==ec(n))return!1;for(const e in t)if(!rc(t,e)||!ic(t[e],n[e]))return!1;break;case Array:if(t.length!==n.length)return!1;for(let e=0;e<t.length;e++)if(!ic(t[e],n[e]))return!1;break;default:return!1}return!0};class sc extends tc{constructor(t){super(),this.doc=t,this.clientID=t.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval((()=>{const t=Ju();null!==this.getLocalState()&&15e3<=t-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());const n=[];this.meta.forEach(((e,r)=>{r!==this.clientID&&3e4<=t-e.lastUpdated&&this.states.has(r)&&n.push(r)})),n.length>0&&oc(this,n,"timeout")}),Mu(3e3)),t.on("destroy",(()=>{this.destroy()})),this.setLocalState({})}destroy(){this.emit("destroy",[this]),this.setLocalState(null),super.destroy(),clearInterval(this._checkInterval)}getLocalState(){return this.states.get(this.clientID)||null}setLocalState(t){const n=this.clientID,e=this.meta.get(n),r=void 0===e?0:e.clock+1,i=this.states.get(n);null===t?this.states.delete(n):this.states.set(n,t),this.meta.set(n,{clock:r,lastUpdated:Ju()});const s=[],o=[],u=[],c=[];null===t?c.push(n):null==i?null!=t&&s.push(n):(o.push(n),ic(i,t)||u.push(n)),(s.length>0||u.length>0||c.length>0)&&this.emit("change",[{added:s,updated:u,removed:c},"local"]),this.emit("update",[{added:s,updated:o,removed:c},"local"])}setLocalStateField(t,n){const e=this.getLocalState();null!==e&&this.setLocalState({...e,[t]:n})}getStates(){return this.states}}const oc=(t,n,e)=>{const r=[];for(let e=0;e<n.length;e++){const i=n[e];if(t.states.has(i)){if(t.states.delete(i),i===t.clientID){const n=t.meta.get(i);t.meta.set(i,{clock:n.clock+1,lastUpdated:Ju()})}r.push(i)}}r.length>0&&(t.emit("change",[{added:[],updated:[],removed:r},e]),t.emit("update",[{added:[],updated:[],removed:r},e]))},uc=(t,n,e=t.states)=>{const r=n.length,i=zu();Ru(i,r);for(let s=0;s<r;s++){const r=n[s],o=e.get(r)||null,u=t.meta.get(r).clock;Ru(i,r),Ru(i,u),Lu(i,JSON.stringify(o))}return Du(i)};class cc{constructor(){this.callbacks={}}on(t,n){return this.callbacks[t]||(this.callbacks[t]=[]),this.callbacks[t].push(n),this}emit(t,...n){const e=this.callbacks[t];return e&&e.forEach((t=>t.apply(this,n))),this}off(t,n){const e=this.callbacks[t];return e&&(n?this.callbacks[t]=e.filter((t=>t!==n)):delete this.callbacks[t]),this}removeAllListeners(){this.callbacks={}}}class hc{constructor(t){this.data=t,this.encoder=zu(),this.decoder=Hu(new Uint8Array(this.data))}peekVarString(){return(t=>{const n=t.pos,e=Gu(t);return t.pos=n,e})(this.decoder)}readVarUint(){return qu(this.decoder)}readVarString(){return Gu(this.decoder)}readVarUint8Array(){return Vu(this.decoder)}writeVarUint(t){return Ru(this.encoder,t)}writeVarString(t){return Lu(this.encoder,t)}writeVarUint8Array(t){return Fu(this.encoder,t)}length(){return $u(this.encoder)}}var ac,lc;!function(t){t[t.Sync=0]="Sync",t[t.Awareness=1]="Awareness",t[t.Auth=2]="Auth",t[t.QueryAwareness=3]="QueryAwareness",t[t.Stateless=5]="Stateless",t[t.CLOSE=7]="CLOSE",t[t.SyncStatus=8]="SyncStatus"}(ac||(ac={})),function(t){t.Connecting="connecting",t.Connected="connected",t.Disconnected="disconnected"}(lc||(lc={}));class fc{constructor(){this.encoder=zu()}get(t){return t.encoder}toUint8Array(){return Du(this.encoder)}}class dc extends fc{constructor(){super(...arguments),this.type=ac.CLOSE,this.description="Ask the server to close the connection"}get(t){return Lu(this.encoder,t.documentName),Ru(this.encoder,this.type),this.encoder}}class vc extends cc{constructor(t){super(),this.messageQueue=[],this.configuration={url:"",autoConnect:!0,document:void 0,WebSocketPolyfill:void 0,messageReconnectTimeout:3e4,delay:1e3,initialDelay:0,factor:2,maxAttempts:0,minDelay:1e3,maxDelay:3e4,jitter:!0,timeout:0,onOpen:()=>null,onConnect:()=>null,onMessage:()=>null,onOutgoingMessage:()=>null,onStatus:()=>null,onDisconnect:()=>null,onClose:()=>null,onDestroy:()=>null,onAwarenessUpdate:()=>null,onAwarenessChange:()=>null,handleTimeout:null,providerMap:new Map},this.webSocket=null,this.webSocketHandlers={},this.shouldConnect=!0,this.status=lc.Disconnected,this.lastMessageReceived=0,this.identifier=0,this.intervals={connectionChecker:null},this.connectionAttempt=null,this.receivedOnOpenPayload=void 0,this.closeTries=0,this.setConfiguration(t),this.configuration.WebSocketPolyfill=t.WebSocketPolyfill?t.WebSocketPolyfill:WebSocket,this.on("open",this.configuration.onOpen),this.on("open",this.onOpen.bind(this)),this.on("connect",this.configuration.onConnect),this.on("message",this.configuration.onMessage),this.on("outgoingMessage",this.configuration.onOutgoingMessage),this.on("status",this.configuration.onStatus),this.on("disconnect",this.configuration.onDisconnect),this.on("close",this.configuration.onClose),this.on("destroy",this.configuration.onDestroy),this.on("awarenessUpdate",this.configuration.onAwarenessUpdate),this.on("awarenessChange",this.configuration.onAwarenessChange),this.on("close",this.onClose.bind(this)),this.on("message",this.onMessage.bind(this)),this.intervals.connectionChecker=setInterval(this.checkConnection.bind(this),this.configuration.messageReconnectTimeout/10),this.shouldConnect&&this.connect()}async onOpen(t){this.status=lc.Connected,this.emit("status",{status:lc.Connected}),this.cancelWebsocketRetry=void 0,this.receivedOnOpenPayload=t}attach(t){this.configuration.providerMap.set(t.configuration.name,t),this.status===lc.Disconnected&&this.shouldConnect&&this.connect(),this.receivedOnOpenPayload&&this.status===lc.Connected&&t.onOpen(this.receivedOnOpenPayload)}detach(t){this.configuration.providerMap.has(t.configuration.name)&&(t.send(dc,{documentName:t.configuration.name}),this.configuration.providerMap.delete(t.configuration.name))}setConfiguration(t={}){this.configuration={...this.configuration,...t},this.configuration.autoConnect||(this.shouldConnect=!1)}async connect(){if(this.status===lc.Connected)return;this.cancelWebsocketRetry&&(this.cancelWebsocketRetry(),this.cancelWebsocketRetry=void 0),this.receivedOnOpenPayload=void 0,this.shouldConnect=!0;const{retryPromise:t,cancelFunc:n}=(()=>{let t=!1;const n=async function(t,n){const e=function(t){return t||(t={}),{delay:void 0===t.delay?200:t.delay,initialDelay:void 0===t.initialDelay?0:t.initialDelay,minDelay:void 0===t.minDelay?0:t.minDelay,maxDelay:void 0===t.maxDelay?0:t.maxDelay,factor:void 0===t.factor?0:t.factor,maxAttempts:void 0===t.maxAttempts?3:t.maxAttempts,timeout:void 0===t.timeout?0:t.timeout,jitter:!0===t.jitter,initialJitter:!0===t.initialJitter,handleError:void 0===t.handleError?null:t.handleError,handleTimeout:void 0===t.handleTimeout?null:t.handleTimeout,beforeAttempt:void 0===t.beforeAttempt?null:t.beforeAttempt,calculateDelay:void 0===t.calculateDelay?null:t.calculateDelay}}(n);for(const t of["delay","initialDelay","minDelay","maxDelay","maxAttempts","timeout"]){const n=e[t];if(!Number.isInteger(n)||n<0)throw new Error(`Value for ${t} must be an integer greater than or equal to 0`)}if(e.factor.constructor!==Number||e.factor<0)throw new Error("Value for factor must be a number greater than or equal to 0");if(e.delay<e.minDelay)throw new Error(`delay cannot be less than minDelay (delay: ${e.delay}, minDelay: ${e.minDelay}`);const r={attemptNum:0,attemptsRemaining:e.maxAttempts?e.maxAttempts:-1,aborted:!1,abort(){r.aborted=!0}},i=e.calculateDelay||xu,s=e.calculateDelay?e.calculateDelay(r,e):e.initialDelay;if(s&&await ku(s),r.attemptNum<1&&e.initialJitter){const t=i(r,e);t&&await ku(t)}return async function n(){if(e.beforeAttempt&&e.beforeAttempt(r,e),r.aborted){const t=new Error("Attempt aborted");throw t.code="ATTEMPT_ABORTED",t}const s=async t=>{if(e.handleError&&await e.handleError(t,r,e),r.aborted||0===r.attemptsRemaining)throw t;r.attemptNum++;const s=i(r,e);return s&&await ku(s),n()};return r.attemptsRemaining>0&&r.attemptsRemaining--,e.timeout?new Promise(((n,i)=>{const o=setTimeout((()=>{if(e.handleTimeout)try{n(e.handleTimeout(r,e))}catch(t){i(t)}else{const t=new Error(`Retry timeout (attemptNum: ${r.attemptNum}, timeout: ${e.timeout})`);t.code="ATTEMPT_TIMEOUT",i(t)}}),e.timeout);t(r,e).then((t=>{clearTimeout(o),n(t)})).catch((t=>{clearTimeout(o),s(t).then(n).catch(i)}))})):t(r,e).catch(s)}()}(this.createWebSocketConnection.bind(this),{delay:this.configuration.delay,initialDelay:this.configuration.initialDelay,factor:this.configuration.factor,maxAttempts:this.configuration.maxAttempts,minDelay:this.configuration.minDelay,maxDelay:this.configuration.maxDelay,jitter:this.configuration.jitter,timeout:this.configuration.timeout,handleTimeout:this.configuration.handleTimeout,beforeAttempt:n=>{this.shouldConnect&&!t||n.abort()}}).catch((t=>{if(t&&"ATTEMPT_ABORTED"!==t.code)throw t}));return{retryPromise:n,cancelFunc:()=>{t=!0}}})();return this.cancelWebsocketRetry=n,t}attachWebSocketListeners(t,n){const{identifier:e}=t;this.webSocketHandlers[e]={message:t=>this.emit("message",t),close:t=>this.emit("close",{event:t}),open:t=>this.emit("open",t),error:t=>{n(t)}};const r=this.webSocketHandlers[t.identifier];Object.keys(r).forEach((n=>{t.addEventListener(n,r[n])}))}cleanupWebSocket(){if(!this.webSocket)return;const{identifier:t}=this.webSocket,n=this.webSocketHandlers[t];Object.keys(n).forEach((e=>{var r;null===(r=this.webSocket)||void 0===r||r.removeEventListener(e,n[e]),delete this.webSocketHandlers[t]})),this.webSocket.close(),this.webSocket=null}createWebSocketConnection(){return new Promise(((t,n)=>{this.webSocket&&(this.messageQueue=[],this.cleanupWebSocket()),this.lastMessageReceived=0,this.identifier+=1;const e=new this.configuration.WebSocketPolyfill(this.url);e.binaryType="arraybuffer",e.identifier=this.identifier,this.attachWebSocketListeners(e,n),this.webSocket=e,this.status=lc.Connecting,this.emit("status",{status:lc.Connecting}),this.connectionAttempt={resolve:t,reject:n}}))}onMessage(t){var n;this.resolveConnectionAttempt(),this.lastMessageReceived=Ju();const e=new hc(t.data).peekVarString();null===(n=this.configuration.providerMap.get(e))||void 0===n||n.onMessage(t)}resolveConnectionAttempt(){this.connectionAttempt&&(this.connectionAttempt.resolve(),this.connectionAttempt=null,this.status=lc.Connected,this.emit("status",{status:lc.Connected}),this.emit("connect"),this.messageQueue.forEach((t=>this.send(t))),this.messageQueue=[])}stopConnectionAttempt(){this.connectionAttempt=null}rejectConnectionAttempt(){var t;null===(t=this.connectionAttempt)||void 0===t||t.reject(),this.connectionAttempt=null}checkConnection(){var t;this.status===lc.Connected&&this.lastMessageReceived&&(this.configuration.messageReconnectTimeout>=Ju()-this.lastMessageReceived||(this.closeTries+=1,this.closeTries>2?(this.onClose({event:{code:4408,reason:"forced"}}),this.closeTries=0):(null===(t=this.webSocket)||void 0===t||t.close(),this.messageQueue=[])))}get serverUrl(){for(;"/"===this.configuration.url[this.configuration.url.length-1];)return this.configuration.url.slice(0,this.configuration.url.length-1);return this.configuration.url}get url(){return this.serverUrl}disconnect(){if(this.shouldConnect=!1,null!==this.webSocket)try{this.webSocket.close(),this.messageQueue=[]}catch(t){console.error(t)}}send(t){var n;(null===(n=this.webSocket)||void 0===n?void 0:n.readyState)===Au.Open?this.webSocket.send(t):this.messageQueue.push(t)}onClose({event:t}){this.closeTries=0,this.cleanupWebSocket(),this.connectionAttempt&&this.rejectConnectionAttempt(),this.status=lc.Disconnected,this.emit("status",{status:lc.Disconnected}),this.emit("disconnect",{event:t}),!this.cancelWebsocketRetry&&this.shouldConnect&&setTimeout((()=>{this.connect()}),this.configuration.delay)}destroy(){this.emit("destroy"),clearInterval(this.intervals.connectionChecker),this.stopConnectionAttempt(),this.disconnect(),this.removeAllListeners(),this.cleanupWebSocket()}}const pc=(t,n,e)=>{try{gi(n,Vu(t),e)}catch(t){console.error("Caught error while handling a Yjs update",t)}},wc=pc;class yc{constructor(t){this.message=t}apply(t,n){const{message:e}=this,r=e.readVarUint(),i=e.length();switch(r){case ac.Sync:this.applySyncMessage(t,n);break;case ac.Awareness:this.applyAwarenessMessage(t);break;case ac.Auth:this.applyAuthMessage(t);break;case ac.QueryAwareness:this.applyQueryAwarenessMessage(t);break;case ac.Stateless:t.receiveStateless(Gu(e.decoder));break;case ac.SyncStatus:this.applySyncStatusMessage(t,1===(t=>{let n=t.arr[t.pos++],e=63&n,r=64;const i=(64&n)>0?-1:1;if(!(n&Su))return i*e;const s=t.arr.length;for(;t.pos<s;){if(n=t.arr[t.pos++],e+=(n&Cu)*r,r*=128,n<Su)return i*e;if(e>Uu)throw Qu}throw Ku})(e.decoder));break;case ac.CLOSE:const i={code:1e3,reason:Gu(e.decoder),target:t.configuration.websocketProvider.webSocket,type:"close"};t.onClose(),t.configuration.onClose({event:i}),t.forwardClose(i);break;default:throw new Error(`Can’t apply message of unknown type: ${r}`)}e.length()>i+1&&t.send(fc,{encoder:e.encoder})}applySyncMessage(t,n){const{message:e}=this;e.writeVarUint(ac.Sync);const r=((t,n,e,r)=>{const i=qu(t);switch(i){case 0:((t,n,e)=>{((t,n,e)=>{Ru(t,1),Fu(t,mi(n,e))})(n,e,Vu(t))})(t,n,e);break;case 1:pc(t,e,r);break;case 2:wc(t,e,r);break;default:throw new Error("Unknown message type")}return i})(e.decoder,e.encoder,t.document,t);n&&1===r&&(t.synced=!0)}applySyncStatusMessage(t,n){n&&t.decrementUnsyncedChanges()}applyAwarenessMessage(t){if(!t.awareness)return;const{message:n}=this;((t,n,e)=>{const r=Hu(n),i=Ju(),s=[],o=[],u=[],c=[],h=qu(r);for(let n=0;n<h;n++){const n=qu(r);let e=qu(r);const h=JSON.parse(Gu(r)),a=t.meta.get(n),l=t.states.get(n),f=void 0===a?0:a.clock;(f<e||f===e&&null===h&&t.states.has(n))&&(null===h?n===t.clientID&&null!=t.getLocalState()?e++:t.states.delete(n):t.states.set(n,h),t.meta.set(n,{clock:e,lastUpdated:i}),void 0===a&&null!==h?s.push(n):void 0!==a&&null===h?c.push(n):null!==h&&(ic(h,l)||u.push(n),o.push(n)))}(s.length>0||u.length>0||c.length>0)&&t.emit("change",[{added:s,updated:u,removed:c},e]),(s.length>0||o.length>0||c.length>0)&&t.emit("update",[{added:s,updated:o,removed:c},e])})(t.awareness,n.readVarUint8Array(),t)}applyAuthMessage(t){const{message:n}=this;((t,n,e,r)=>{switch(yu(t)){case bu.Token:n();break;case bu.PermissionDenied:e(gu(t));break;case bu.Authenticated:r(gu(t))}})(n.decoder,t.sendToken.bind(t),t.permissionDeniedHandler.bind(t),t.authenticatedHandler.bind(t))}applyQueryAwarenessMessage(t){if(!t.awareness)return;const{message:n}=this;n.writeVarUint(ac.Awareness),n.writeVarUint8Array(uc(t.awareness,Array.from(t.awareness.getStates().keys())))}}class gc{constructor(t,n={}){this.message=new t,this.encoder=this.message.get(n)}create(){return Du(this.encoder)}send(t){null==t||t.send(this.create())}}class bc extends fc{constructor(){super(...arguments),this.type=ac.Auth,this.description="Authentication"}get(t){if(void 0===t.token)throw new Error("The authentication message requires `token` as an argument.");var n,e;return Lu(this.encoder,t.documentName),Ru(this.encoder,this.type),e=t.token,cu(n=this.encoder,bu.Token),lu(n,e),this.encoder}}class mc extends fc{constructor(){super(...arguments),this.type=ac.Awareness,this.description="Awareness states update"}get(t){if(void 0===t.awareness)throw new Error("The awareness message requires awareness as an argument");if(void 0===t.clients)throw new Error("The awareness message requires clients as an argument");let n;return Lu(this.encoder,t.documentName),Ru(this.encoder,this.type),n=void 0===t.states?uc(t.awareness,t.clients):uc(t.awareness,t.clients,t.states),Fu(this.encoder,n),this.encoder}}class Ac extends fc{constructor(){super(...arguments),this.type=ac.Stateless,this.description="A stateless message"}get(t){var n;return Lu(this.encoder,t.documentName),Ru(this.encoder,this.type),Lu(this.encoder,null!==(n=t.payload)&&void 0!==n?n:""),this.encoder}}class kc extends fc{constructor(){super(...arguments),this.type=ac.Sync,this.description="First sync step"}get(t){if(void 0===t.document)throw new Error("The sync step one message requires document as an argument");return Lu(this.encoder,t.documentName),Ru(this.encoder,this.type),((t,n)=>{Ru(t,0);const e=xi(n);Fu(t,e)})(this.encoder,t.document),this.encoder}}class xc extends fc{constructor(){super(...arguments),this.type=ac.Sync,this.description="A document update"}get(t){var n,e;return Lu(this.encoder,t.documentName),Ru(this.encoder,this.type),e=t.update,Ru(n=this.encoder,2),Fu(n,e),this.encoder}}class Mc extends Error{constructor(){super(...arguments),this.code=1001}}class Sc extends cc{constructor(t){var n,e,r;super(),this.configuration={name:"",document:void 0,awareness:void 0,token:null,forceSyncInterval:!1,onAuthenticated:()=>null,onAuthenticationFailed:()=>null,onOpen:()=>null,onConnect:()=>null,onMessage:()=>null,onOutgoingMessage:()=>null,onSynced:()=>null,onStatus:()=>null,onDisconnect:()=>null,onClose:()=>null,onDestroy:()=>null,onAwarenessUpdate:()=>null,onAwarenessChange:()=>null,onStateless:()=>null,onUnsyncedChanges:()=>null},this.isSynced=!1,this.unsyncedChanges=0,this.isAuthenticated=!1,this.authorizedScope=void 0,this.manageSocket=!1,this._isAttached=!1,this.intervals={forceSync:null},this.boundDocumentUpdateHandler=this.documentUpdateHandler.bind(this),this.boundAwarenessUpdateHandler=this.awarenessUpdateHandler.bind(this),this.boundPageHide=this.pageHide.bind(this),this.boundOnOpen=this.onOpen.bind(this),this.boundOnClose=this.onClose.bind(this),this.forwardConnect=()=>this.emit("connect"),this.forwardStatus=t=>this.emit("status",t),this.forwardClose=t=>this.emit("close",t),this.forwardDisconnect=t=>this.emit("disconnect",t),this.forwardDestroy=()=>this.emit("destroy"),this.setConfiguration(t),this.configuration.document=t.document?t.document:new ui,this.configuration.awareness=void 0!==t.awareness?t.awareness:new sc(this.document),this.on("open",this.configuration.onOpen),this.on("message",this.configuration.onMessage),this.on("outgoingMessage",this.configuration.onOutgoingMessage),this.on("synced",this.configuration.onSynced),this.on("destroy",this.configuration.onDestroy),this.on("awarenessUpdate",this.configuration.onAwarenessUpdate),this.on("awarenessChange",this.configuration.onAwarenessChange),this.on("stateless",this.configuration.onStateless),this.on("unsyncedChanges",this.configuration.onUnsyncedChanges),this.on("authenticated",this.configuration.onAuthenticated),this.on("authenticationFailed",this.configuration.onAuthenticationFailed),null===(n=this.awareness)||void 0===n||n.on("update",(()=>{this.emit("awarenessUpdate",{states:mu(this.awareness.getStates())})})),null===(e=this.awareness)||void 0===e||e.on("change",(()=>{this.emit("awarenessChange",{states:mu(this.awareness.getStates())})})),this.document.on("update",this.boundDocumentUpdateHandler),null===(r=this.awareness)||void 0===r||r.on("update",this.boundAwarenessUpdateHandler),this.registerEventListeners(),this.configuration.forceSyncInterval&&"number"==typeof this.configuration.forceSyncInterval&&(this.intervals.forceSync=setInterval(this.forceSync.bind(this),this.configuration.forceSyncInterval)),this.manageSocket&&this.attach()}setConfiguration(t={}){if(!t.websocketProvider){const n=t;this.manageSocket=!0,this.configuration.websocketProvider=new vc({url:n.url})}this.configuration={...this.configuration,...t}}get document(){return this.configuration.document}get isAttached(){return this._isAttached}get awareness(){return this.configuration.awareness}get hasUnsyncedChanges(){return this.unsyncedChanges>0}resetUnsyncedChanges(){this.unsyncedChanges=1,this.emit("unsyncedChanges",{number:this.unsyncedChanges})}incrementUnsyncedChanges(){this.unsyncedChanges+=1,this.emit("unsyncedChanges",{number:this.unsyncedChanges})}decrementUnsyncedChanges(){this.unsyncedChanges>0&&(this.unsyncedChanges-=1),0===this.unsyncedChanges&&(this.synced=!0),this.emit("unsyncedChanges",{number:this.unsyncedChanges})}forceSync(){this.resetUnsyncedChanges(),this.send(kc,{document:this.document,documentName:this.configuration.name})}pageHide(){this.awareness&&oc(this.awareness,[this.document.clientID],"page hide")}registerEventListeners(){"undefined"!=typeof window&&"addEventListener"in window&&window.addEventListener("pagehide",this.boundPageHide)}sendStateless(t){this.send(Ac,{documentName:this.configuration.name,payload:t})}async sendToken(){let t;try{t=await this.getToken()}catch(t){return void this.permissionDeniedHandler(`Failed to get token during sendToken(): ${t}`)}this.send(bc,{token:null!=t?t:"",documentName:this.configuration.name})}documentUpdateHandler(t,n){n!==this&&(this.incrementUnsyncedChanges(),this.send(xc,{update:t,documentName:this.configuration.name}))}awarenessUpdateHandler({added:t,updated:n,removed:e},r){const i=t.concat(n).concat(e);this.send(mc,{awareness:this.awareness,clients:i,documentName:this.configuration.name})}get synced(){return this.isSynced}set synced(t){this.isSynced!==t&&(this.isSynced=t,t&&this.emit("synced",{state:t}))}receiveStateless(t){this.emit("stateless",{payload:t})}async connect(){if(this.manageSocket)return this.configuration.websocketProvider.connect();console.warn("HocuspocusProvider::connect() is deprecated and does not do anything. Please connect/disconnect on the websocketProvider, or attach/deattach providers.")}disconnect(){if(this.manageSocket)return this.configuration.websocketProvider.disconnect();console.warn("HocuspocusProvider::disconnect() is deprecated and does not do anything. Please connect/disconnect on the websocketProvider, or attach/deattach providers.")}async onOpen(t){this.isAuthenticated=!1,this.emit("open",{event:t}),await this.sendToken(),this.startSync()}async getToken(){return"function"==typeof this.configuration.token?await this.configuration.token():this.configuration.token}startSync(){this.resetUnsyncedChanges(),this.send(kc,{document:this.document,documentName:this.configuration.name}),this.awareness&&null!==this.awareness.getLocalState()&&this.send(mc,{awareness:this.awareness,clients:[this.document.clientID],documentName:this.configuration.name})}send(t,n){if(!this._isAttached)return;const e=new gc(t,n);this.emit("outgoingMessage",{message:e.message}),e.send(this.configuration.websocketProvider)}onMessage(t){const n=new hc(t.data),e=n.readVarString();n.writeVarString(e),this.emit("message",{event:t,message:new hc(t.data)}),new yc(n).apply(this,!0)}onClose(){this.isAuthenticated=!1,this.synced=!1,this.awareness&&oc(this.awareness,Array.from(this.awareness.getStates().keys()).filter((t=>t!==this.document.clientID)),this)}destroy(){this.emit("destroy"),this.intervals.forceSync&&clearInterval(this.intervals.forceSync),this.awareness&&(oc(this.awareness,[this.document.clientID],"provider destroy"),this.awareness.off("update",this.boundAwarenessUpdateHandler),this.awareness.destroy()),this.document.off("update",this.boundDocumentUpdateHandler),this.removeAllListeners(),this.detach(),this.manageSocket&&this.configuration.websocketProvider.destroy(),"undefined"!=typeof window&&"removeEventListener"in window&&window.removeEventListener("pagehide",this.boundPageHide)}detach(){this.configuration.websocketProvider.off("connect",this.configuration.onConnect),this.configuration.websocketProvider.off("connect",this.forwardConnect),this.configuration.websocketProvider.off("status",this.forwardStatus),this.configuration.websocketProvider.off("status",this.configuration.onStatus),this.configuration.websocketProvider.off("open",this.boundOnOpen),this.configuration.websocketProvider.off("close",this.boundOnClose),this.configuration.websocketProvider.off("close",this.configuration.onClose),this.configuration.websocketProvider.off("close",this.forwardClose),this.configuration.websocketProvider.off("disconnect",this.configuration.onDisconnect),this.configuration.websocketProvider.off("disconnect",this.forwardDisconnect),this.configuration.websocketProvider.off("destroy",this.configuration.onDestroy),this.configuration.websocketProvider.off("destroy",this.forwardDestroy),this.configuration.websocketProvider.detach(this),this._isAttached=!1}attach(){this._isAttached||(this.configuration.websocketProvider.on("connect",this.configuration.onConnect),this.configuration.websocketProvider.on("connect",this.forwardConnect),this.configuration.websocketProvider.on("status",this.configuration.onStatus),this.configuration.websocketProvider.on("status",this.forwardStatus),this.configuration.websocketProvider.on("open",this.boundOnOpen),this.configuration.websocketProvider.on("close",this.boundOnClose),this.configuration.websocketProvider.on("close",this.configuration.onClose),this.configuration.websocketProvider.on("close",this.forwardClose),this.configuration.websocketProvider.on("disconnect",this.configuration.onDisconnect),this.configuration.websocketProvider.on("disconnect",this.forwardDisconnect),this.configuration.websocketProvider.on("destroy",this.configuration.onDestroy),this.configuration.websocketProvider.on("destroy",this.forwardDestroy),this.configuration.websocketProvider.attach(this),this._isAttached=!0)}permissionDeniedHandler(t){this.emit("authenticationFailed",{reason:t}),this.isAuthenticated=!1}authenticatedHandler(t){this.isAuthenticated=!0,this.authorizedScope=t,this.emit("authenticated",{scope:t})}setAwarenessField(t,n){if(!this.awareness)throw new Mc(`Cannot set awareness field "${t}" to ${JSON.stringify(n)}. You have disabled Awareness for this provider by explicitly passing awareness: null in the provider configuration.`);this.awareness.setLocalStateField(t,n)}}const Cc={providers:[tu]};class Uc{map;_ydoc=null;_workspacesMap=null;_providers=[];_core=null;_isReady=!1;_onRemoteChangeCallback=null;get isReady(){return this._isReady}constructor(){this.map=new Map}onRemoteChange(t){this._onRemoteChangeCallback=t}async initialize(t,n){this._core=t,this._ydoc=new ui,this._workspacesMap=this._ydoc.getMap("workspaces");const e="kritzel-app-state",r=n??Cc;for(const t of r.providers){let n;n="function"==typeof t?new t(e,this._ydoc):t.create(e,this._ydoc),this._providers.push(n)}this._workspacesMap.observe((t=>{this.handleWorkspacesChange(t)})),await Promise.all(this._providers.map((t=>t.connect()))),this._isReady=!0,this.loadFromYjs()}handleWorkspacesChange(t){if("local"===t.transaction.origin)return void this._core?.rerender();const n=Array.from(t.keysChanged),e=[],r=[];n.forEach((n=>{const i=t.changes.keys.get(n);if(i&&"delete"===i.action)r.push(n);else{const t=this._workspacesMap.get(n);if(t){const n=this.reviveWorkspace(t);e.push(n)}}})),r.forEach((t=>{this.map.delete(t)})),e.forEach((t=>{this.map.set(t.id,t)})),this._core?.store&&(this._core.store.state.workspaces=this.allWorkspaces()),this._onRemoteChangeCallback&&this._onRemoteChangeCallback(),this._core?.rerender()}reviveWorkspace(t){const n=new I(t.id,t.name,t.viewport);return n._core=this._core,n.createdAt=new Date(t.createdAt),n.updatedAt=new Date(t.updatedAt),n}transaction(t){this._ydoc&&this._ydoc.transact(t,"local")}loadFromYjs(){this._workspacesMap&&(this.map.clear(),this._workspacesMap.forEach(((t,n)=>{const e=this.reviveWorkspace(t);this.map.set(n,e)})))}reset(){this.map.clear(),this._ydoc.transact((()=>{this._workspacesMap.clear()}),"local")}insert(t){if(!t.id)return!1;if(this.map.set(t.id,t),this._workspacesMap){const n=t.serialize();this._ydoc.transact((()=>{this._workspacesMap.set(t.id,n)}),"local")}return!0}update(t){if(!t.id||!this.map.has(t.id))return!1;if(this.map.set(t.id,t),this._workspacesMap){const n=t.serialize();this._ydoc.transact((()=>{this._workspacesMap.set(t.id,n)}),"local")}return!0}remove(t){const n=Array.from(this.map.values()).find(t);return!!n&&(this.map.delete(n.id),this._workspacesMap&&this._ydoc.transact((()=>{this._workspacesMap.delete(n.id)}),"local"),!0)}get(t){return this.map.get(t)}allWorkspaces(){return Array.from(this.map.values())}filter(t){return Array.from(this.map.values()).filter(t)}find(t){return Array.from(this.map.values()).find(t)}has(t){return this.map.has(t)}destroy(){this._providers.forEach((t=>t.disconnect())),this._providers=[],this.map.clear(),this._workspacesMap=null,this._ydoc&&(this._ydoc.destroy(),this._ydoc=null),this._isReady=!1}}class Ec{static isInstanceOf(t,n){return!!t&&t.__class__===n}}class jc{_core;_anchorIndex=new Map;constructor(t){this._core=t}setAnchor(t,n,e){const r=this.getLineById(t);if(!r)return;if("start"===n&&r.endAnchor?.objectId===e)return;if("end"===n&&r.startAnchor?.objectId===e)return;this.removeAnchor(t,n);const i={objectId:e};"start"===n?r.startAnchor=i:r.endAnchor=i,this.addToIndex(e,t,n),this.snapEndpointToObject(r,n,e),this._core.store.state.objects.update(r)}removeAnchor(t,n){const e=this.getLineById(t);if(!e)return;const r="start"===n?e.startAnchor:e.endAnchor;r&&(this.removeFromIndex(r.objectId,t,n),"start"===n?e.startAnchor=void 0:e.endAnchor=void 0)}getAnchor(t,n){const e=this.getLineById(t);return e?("start"===n?e.startAnchor:e.endAnchor)??null:null}getLinesAnchoredTo(t){const n=this._anchorIndex.get(t);return n?Array.from(n):[]}updateAnchorsForObject(t){const n=this.getLinesAnchoredTo(t);if(0!==n.length&&this.getObjectById(t))for(const e of n){const n=this.getLineById(e.lineId);n&&this.snapEndpointToObject(n,e.endpoint,t)}}snapEndpointToObject(t,n,e){const r=this.getObjectById(e);if(!r)return;const i=this.worldToLineLocal(t,r.centerX,r.centerY);t.updateEndpoint(n,i.x,i.y)}worldToLineLocal(t,n,e){const r=n-t.centerX,i=e-t.centerY,s=Math.cos(-t.rotation),o=Math.sin(-t.rotation);return{x:(r*s-i*o+t.totalWidth/2/t.scale)*t.scale+t.x,y:(r*o+i*s+t.totalHeight/2/t.scale)*t.scale+t.y}}findSnapTarget(t,n,e,r){let i=null,s=-1/0;const o=this._core.store.allNonSelectionObjects;for(const u of o){if(u.id===e)continue;if(r&&u.id===r)continue;if(!this.isAnchorable(u))continue;const o=u.rotatedPolygon;f.isPointInPolygon({x:t,y:n},[o.topLeft,o.topRight,o.bottomRight,o.bottomLeft])&&u.zIndex>s&&(s=u.zIndex,i={objectId:u.id,centerX:u.centerX,centerY:u.centerY})}return i}setSnapCandidate(t){this._core.store.state.snapCandidate=t,this._core.rerender()}getSnapCandidate(){return this._core.store.state.snapCandidate??null}clearSnapCandidate(){this._core.store.state.snapCandidate=null,this._core.rerender()}getAnchorLinesRenderData(){const t=this._core.store.selectionGroup;if(!t||1!==t.objects.length)return null;const n=t.objects[0];if(!Ec.isInstanceOf(n,"KritzelLine"))return null;const e=n,r=this.computeAnchorVisualization(e,"start"),i=this.computeAnchorVisualization(e,"end");if(!r&&!i)return null;const s=this._core.store.state.scale,o=e.strokeWidth/e.scale,u=""+2/s,c=Math.max(2*o,4/s);return{lineStrokeWidth:o,indicatorStrokeWidth:u,dashArray:`${c} ${c}`,indicatorRadius:8/s,startAnchorViz:r,endAnchorViz:i}}getSnapIndicatorRenderData(){const t=this.getSnapCandidate();if(!t)return null;const n=this._core.store.state.scale,e=8/n,r=""+2/n,i=t.lineStrokeWidth?`${t.lineStrokeWidth}`:""+4/n,s=Math.max(2*(t.lineStrokeWidth||4/n),4/n),o=`${s} ${s}`,u=t.lineStroke||"#000000";let c,h=t.edgeX,a=t.edgeY;if(t.arrowOffset&&void 0!==t.edgeX&&void 0!==t.edgeY){const n=t.lineEndpointX-t.edgeX,e=t.lineEndpointY-t.edgeY,r=Math.sqrt(n*n+e*e);r>t.arrowOffset&&(h=t.edgeX+n/r*t.arrowOffset,a=t.edgeY+e/r*t.arrowOffset);const i=t.edgeX-t.lineEndpointX,s=t.edgeY-t.lineEndpointY,o=Math.sqrt(i*i+s*s);if(o>0){const n=i/o,e=s/o,r=-e,u=t.arrowOffset,h=t.edgeX,a=t.edgeY,l=h-n*u,f=a-e*u;c=`${h},${a} ${l+r*u/2},${f+n*u/2} ${l-r*u/2},${f-n*u/2}`}}return{indicatorRadius:e,indicatorStrokeWidth:r,lineStrokeWidth:i,dashArray:o,lineStroke:u,centerX:t.centerX,centerY:t.centerY,lineEndpointX:t.lineEndpointX,lineEndpointY:t.lineEndpointY,edgeX:t.edgeX,edgeY:t.edgeY,arrowOffset:t.arrowOffset,arrowStyle:t.arrowStyle,arrowFill:t.arrowFill,solidLineEndX:h,solidLineEndY:a,arrowPoints:c,snapLinePath:(()=>{if(void 0!==t.controlX&&void 0!==t.controlY&&void 0!==t.t){const n="start"===t.endpoint?1-t.t:t.t;if(n>=1)return;const e=this.extractQuadraticSegment({x:t.lineEndpointX,y:t.lineEndpointY},{x:t.controlX,y:t.controlY},{x:t.centerX,y:t.centerY},n,1);return`M ${e.start.x} ${e.start.y} Q ${e.control.x} ${e.control.y} ${e.end.x} ${e.end.y}`}})()}}handleObjectDeleted(t){const n=this.getLinesAnchoredTo(t);for(const t of n){this.removeAnchor(t.lineId,t.endpoint);const n=this.getLineById(t.lineId);n&&this._core.store.state.objects.update(n)}this._anchorIndex.delete(t)}handleLineDeleted(t){const n=this.getLineById(t);n&&(n.startAnchor&&this.removeFromIndex(n.startAnchor.objectId,t,"start"),n.endAnchor&&this.removeFromIndex(n.endAnchor.objectId,t,"end"))}rebuildIndex(){this._anchorIndex.clear();const t=this._core.store.allObjects;for(const n of t)n instanceof l&&(n.startAnchor&&this.addToIndex(n.startAnchor.objectId,n.id,"start"),n.endAnchor&&this.addToIndex(n.endAnchor.objectId,n.id,"end"))}addToIndex(t,n,e){this._anchorIndex.has(t)||this._anchorIndex.set(t,new Set);const r=this._anchorIndex.get(t);for(const t of r)if(t.lineId===n&&t.endpoint===e)return;r.add({lineId:n,endpoint:e})}removeFromIndex(t,n,e){const r=this._anchorIndex.get(t);if(r){for(const t of r)if(t.lineId===n&&t.endpoint===e){r.delete(t);break}0===r.size&&this._anchorIndex.delete(t)}}getLineById(t){const n=this._core.store.state.objects.filter((n=>n.id===t));if(0===n.length)return null;const e=n[0];return e instanceof l?e:null}getObjectById(t){const n=this._core.store.state.objects.filter((n=>n.id===t));return n.length>0?n[0]:null}findAnchorTarget(t,n){const e="start"===n?t.startAnchor:t.endAnchor;return e?this._core.store.allNonSelectionObjects.find((t=>t.id===e.objectId))??null:null}computeAnchorVisualization(t,n){if(!("start"===n?t.startAnchor:t.endAnchor))return null;const e=this.findAnchorTarget(t,n);if(!e)return null;const r=this.computeAnchorClipInfo(t,n,e);return r?{edgeX:r.worldX,edgeY:r.worldY,centerX:e.centerX,centerY:e.centerY,pathD:this.buildAnchorPath(t,n,r,e)??void 0}:null}computeClippedLinePath(t,n=!1){const e=this.getSnapCandidate(),r=this._core.store.selectionGroup,i=e&&r&&1===r.objects.length&&r.objects[0].id===t.id;if(!t.startAnchor&&!t.endAnchor&&!i)return n?void 0!==t.controlX&&void 0!==t.controlY?`M ${t.startX-t.x} ${t.startY-t.y} Q ${t.controlX-t.x} ${t.controlY-t.y} ${t.endX-t.x} ${t.endY-t.y}`:`M ${t.startX-t.x} ${t.startY-t.y} L ${t.endX-t.x} ${t.endY-t.y}`:t.d;const s=t.startAnchor?this.findAnchorTarget(t,"start"):null,o=t.endAnchor?this.findAnchorTarget(t,"end"):null;let u=s?this.computeAnchorClipInfo(t,"start",s):null,c=o?this.computeAnchorClipInfo(t,"end",o):null;if(i&&void 0!==e.edgeX&&void 0!==e.edgeY){const n=this.lineWorldToLocal(t,e.edgeX,e.edgeY),r={worldX:e.edgeX,worldY:e.edgeY,localX:n.x,localY:n.y,t:e.t};"start"===e.endpoint?u=r:c=r}const h=n?t.x:0,a=n?t.y:0;if(void 0!==t.controlX&&void 0!==t.controlY){let n=u?.t??0,e=c?.t??1;if(u&&t.hasStartArrow){const e=t.getArrowSize("start"),r=this.evaluateDerivativeSpeedAtT(t,n);r>0&&(n+=e/r)}if(c&&t.hasEndArrow){const n=t.getArrowSize("end"),r=this.evaluateDerivativeSpeedAtT(t,e);r>0&&(e-=n/r)}if(n<0&&(n=0),e>1&&(e=1),e<=n){const t=(n+e)/2;n=t,e=t}const r=this.extractQuadraticSegment({x:t.startX,y:t.startY},{x:t.controlX,y:t.controlY},{x:t.endX,y:t.endY},n,e);return`M ${r.start.x-h} ${r.start.y-a} Q ${r.control.x-h} ${r.control.y-a} ${r.end.x-h} ${r.end.y-a}`}let l=u?.localX??t.startX,f=u?.localY??t.startY,d=c?.localX??t.endX,v=c?.localY??t.endY;if(u&&t.hasStartArrow){const n=t.getArrowSize("start"),e=d-l,r=v-f,i=Math.sqrt(e*e+r*r);i>n&&(l+=e/i*n,f+=r/i*n)}if(c&&t.hasEndArrow){const n=t.getArrowSize("end"),e=l-d,r=f-v,i=Math.sqrt(e*e+r*r);i>n&&(d+=e/i*n,v+=r/i*n)}return`M ${l-h} ${f-a} L ${d-h} ${v-a}`}computeAnchorClipInfo(t,n,e){return void 0!==t.controlX&&void 0!==t.controlY?this.computeCurvedClipInfo(t,n,e):this.computeStraightClipInfo(t,n,e)}computeStraightClipInfo(t,n,e){const r="start"===n?this.lineLocalToWorld(t,t.endX,t.endY):this.lineLocalToWorld(t,t.startX,t.startY),i=this.getPathClipPoint(e,r);if(i){const e=this.lineWorldToLocal(t,i.x,i.y),r=Math.sqrt(Math.pow(t.endX-t.startX,2)+Math.pow(t.endY-t.startY,2)),s=Math.sqrt(Math.pow(e.x-t.startX,2)+Math.pow(e.y-t.startY,2));return{localX:e.x,localY:e.y,worldX:i.x,worldY:i.y,t:r>0?s/r:"start"===n?0:1}}const s=this.getClipPolygonForObject(e);let o;if(o=s?f.getLinePointsArrayIntersection(r,{x:e.centerX,y:e.centerY},s):f.getLinePolygonIntersection(r,{x:e.centerX,y:e.centerY},e.rotatedPolygon),!o)return null;const u=this.lineWorldToLocal(t,o.x,o.y),c=Math.sqrt(Math.pow(t.endX-t.startX,2)+Math.pow(t.endY-t.startY,2)),h=Math.sqrt(Math.pow(u.x-t.startX,2)+Math.pow(u.y-t.startY,2));return{localX:u.x,localY:u.y,worldX:o.x,worldY:o.y,t:c>0?h/c:"start"===n?0:1}}computeCurvedClipInfo(t,n,e){if(Ec.isInstanceOf(e,"KritzelPath"))return this.findCurveExitPointForPath(t,n,e);const r=this.getClipPolygonForObject(e),i=r??this.getPolygonPoints(e.rotatedPolygon),s=this.findCurveExitPoint(t,n,i);if(s)return s;const o="start"===n?this.lineLocalToWorld(t,t.endX,t.endY):this.lineLocalToWorld(t,t.startX,t.startY);let u;if(u=r?f.getLinePointsArrayIntersection(o,{x:e.centerX,y:e.centerY},r):f.getLinePolygonIntersection(o,{x:e.centerX,y:e.centerY},e.rotatedPolygon),!u)return null;const c=this.lineWorldToLocal(t,u.x,u.y),h=this.approximateParameterForWorldPoint(t,u);return{localX:c.x,localY:c.y,worldX:u.x,worldY:u.y,t:h}}findCurveExitPoint(t,n,e){const r="start"===n?0:1,i=this.evaluateLineAtT(t,r);let s=f.isPointInPolygon({x:i.worldX,y:i.worldY},e),o=r;for(let r=1;r<=64;r++){const i="start"===n?r/64:1-r/64,u=this.evaluateLineAtT(t,i),c=f.isPointInPolygon({x:u.worldX,y:u.worldY},e);if(s&&!c){const n=this.refineCurveExitParameter(t,e,o,i),r=this.evaluateLineAtT(t,n);return{localX:r.localX,localY:r.localY,worldX:r.worldX,worldY:r.worldY,t:n}}s=c,o=i}return null}findCurveExitPointForPath(t,n,e){const r="start"===n?0:1,i=e.strokeWidth/e.scale/2,s=this.getPathAdjustedPoints(e);if(s.length<1)return null;const o=this.evaluateLineAtT(t,r);let u=this.isPointInPathStroke(o.worldX,o.worldY,s,i),c=r;for(let e=1;e<=64;e++){const r="start"===n?e/64:1-e/64,o=this.evaluateLineAtT(t,r),h=this.isPointInPathStroke(o.worldX,o.worldY,s,i);if(u&&!h){const n=this.refineCurveExitParameterForPath(t,s,i,c,r),e=this.evaluateLineAtT(t,n);return{localX:e.localX,localY:e.localY,worldX:e.worldX,worldY:e.worldY,t:n}}u=h,c=r}return null}refineCurveExitParameterForPath(t,n,e,r,i){let s=r,o=i;for(let r=0;r<8;r++){const r=(s+o)/2,i=this.evaluateLineAtT(t,r);this.isPointInPathStroke(i.worldX,i.worldY,n,e)?s=r:o=r}return(s+o)/2}getPathAdjustedPoints(t){return this.computePathAdjustedPoints(t)}computePathAdjustedPoints(t){if(!t.points?.length)return[];const n=t.rotation,e=Math.cos(n),r=Math.sin(n),i=t.points.map((t=>t[0])),s=t.points.map((t=>t[1])),o={x:(Math.min(...i)+Math.max(...i))/2,y:(Math.min(...s)+Math.max(...s))/2},{x:u,y:c}=o;return t.points.map((([t,n])=>{const i=t-u,s=n-c;return[u+i*e-s*r,c+i*r+s*e]})).map((([n,e])=>[Math.abs(n-t.x)/t.scale+t.translateX,Math.abs(e-t.y)/t.scale+t.translateY]))}isPointInPathStroke(t,n,e,r){if(1===e.length){const i=e[0],s=t-i[0],o=n-i[1];return Math.sqrt(s*s+o*o)<=r}for(let i=0;i<e.length-1;i++){const s=e[i],o=e[i+1];if(this.pointToSegmentDistance(t,n,s[0],s[1],o[0],o[1])<=r)return!0}return!1}pointToSegmentDistance(t,n,e,r,i,s){const o=i-e,u=s-r,c=o*o+u*u;if(0===c)return Math.sqrt((t-e)*(t-e)+(n-r)*(n-r));let h=((t-e)*o+(n-r)*u)/c;h=Math.max(0,Math.min(1,h));const a=e+h*o,l=r+h*u;return Math.sqrt((t-a)*(t-a)+(n-l)*(n-l))}refineCurveExitParameter(t,n,e,r){let i=e,s=r;for(let e=0;e<8;e++){const e=(i+s)/2,r=this.evaluateLineAtT(t,e);f.isPointInPolygon({x:r.worldX,y:r.worldY},n)?i=e:s=e}return(i+s)/2}approximateParameterForWorldPoint(t,n){let e=0,r=1/0;for(let i=0;i<=80;i++){const s=i/80,o=this.evaluateLineAtT(t,s),u=Math.hypot(o.worldX-n.x,o.worldY-n.y);u<r&&(r=u,e=s)}return e}evaluateLineAtT(t,n){const e=Math.max(0,Math.min(1,n));let r,i;if(void 0!==t.controlX&&void 0!==t.controlY){const n=1-e;r=n*n*t.startX+2*n*e*t.controlX+e*e*t.endX,i=n*n*t.startY+2*n*e*t.controlY+e*e*t.endY}else r=t.startX+(t.endX-t.startX)*e,i=t.startY+(t.endY-t.startY)*e;const s=this.lineLocalToWorld(t,r,i);return{t:e,localX:r,localY:i,worldX:s.x,worldY:s.y}}evaluateDerivativeSpeedAtT(t,n){const e=Math.max(0,Math.min(1,n));if(void 0!==t.controlX&&void 0!==t.controlY){const n=t.controlX,r=t.controlY,i=2*(1-e)*(n-t.startX)+2*e*(t.endX-n),s=2*(1-e)*(r-t.startY)+2*e*(t.endY-r);return Math.sqrt(i*i+s*s)}{const n=t.endX-t.startX,e=t.endY-t.startY;return Math.sqrt(n*n+e*e)}}extractQuadraticSegment(t,n,e,r,i){let s=Math.max(0,Math.min(1,r)),o=Math.max(0,Math.min(1,i));if(o<s){const t=s;s=o,o=t}let u={start:t,control:n,end:e};if(s>0){u=this.splitQuadraticSegment(u,s).right;const t=1-s;o=t>0?(o-s)/t:1}return o<1&&(u=this.splitQuadraticSegment(u,o).left),u}splitQuadraticSegment(t,n){const e=Math.max(0,Math.min(1,n)),r=t.start,i=t.control,s=t.end,o=this.lerpPoint(r,i,e),u=this.lerpPoint(i,s,e),c=this.lerpPoint(o,u,e);return{left:{start:r,control:o,end:c},right:{start:c,control:u,end:s}}}lerpPoint(t,n,e){return{x:t.x+(n.x-t.x)*e,y:t.y+(n.y-t.y)*e}}buildAnchorPath(t,n,e,r){if(void 0===t.controlX||void 0===t.controlY||void 0===e.t)return`M ${e.worldX} ${e.worldY} L ${r.centerX} ${r.centerY}`;const i="start"===n?0:e.t,s="start"===n?e.t:1;if(s<=i)return`M ${e.worldX} ${e.worldY} L ${r.centerX} ${r.centerY}`;const o=this.extractQuadraticSegment({x:t.startX,y:t.startY},{x:t.controlX,y:t.controlY},{x:t.endX,y:t.endY},i,s);return this.buildWorldQuadraticPath(t,o,"start"===n)}buildWorldQuadraticPath(t,n,e=!1){const r=e?n.end:n.start,i=e?n.start:n.end,s=n.control,o=this.lineLocalToWorld(t,r.x,r.y),u=this.lineLocalToWorld(t,s.x,s.y),c=this.lineLocalToWorld(t,i.x,i.y);return`M ${o.x} ${o.y} Q ${u.x} ${u.y} ${c.x} ${c.y}`}getPolygonPoints(t){return[t.topLeft,t.topRight,t.bottomRight,t.bottomLeft]}getClipPolygonForObject(t){return Ec.isInstanceOf(t,"KritzelShape")?t.getClipPolygon():null}getPathClipPoint(t,n){return Ec.isInstanceOf(t,"KritzelPath")?t.getClipPoint(n):null}lineLocalToWorld(t,n,e){const r=n-t.x,i=e-t.y,s=t.totalWidth/2,o=t.totalHeight/2,u=Math.cos(t.rotation),c=Math.sin(t.rotation);return{x:((r-s)*u-(i-o)*c+s)/t.scale+t.translateX,y:((r-s)*c+(i-o)*u+o)/t.scale+t.translateY}}lineWorldToLocal(t,n,e){const r=(n-t.translateX)*t.scale,i=(e-t.translateY)*t.scale,s=t.totalWidth/2,o=t.totalHeight/2,u=Math.cos(-t.rotation),c=Math.sin(-t.rotation);return{x:(r-s)*u-(i-o)*c+s+t.x,y:(r-s)*c+(i-o)*u+o+t.y}}isAnchorable(t){return!(t instanceof d||t instanceof v)&&!(t instanceof l)&&t.isVisible}}const Tc=1e3,Ic=1e-4;var _c,Oc,zc,$c={exports:{}},Dc=(_c||(_c=1,Oc=$c,zc=$c.exports,function(){var t,n="Expected a function",e="__lodash_hash_undefined__",r="__lodash_placeholder__",i=32,s=128,o=1/0,u=9007199254740991,c=NaN,h=4294967295,a=[["ary",s],["bind",1],["bindKey",2],["curry",8],["curryRight",16],["flip",512],["partial",i],["partialRight",64],["rearg",256]],l="[object Arguments]",f="[object Array]",d="[object Boolean]",v="[object Date]",p="[object Error]",w="[object Function]",y="[object GeneratorFunction]",g="[object Map]",b="[object Number]",m="[object Object]",A="[object Promise]",k="[object RegExp]",x="[object Set]",M="[object String]",S="[object Symbol]",C="[object WeakMap]",U="[object ArrayBuffer]",E="[object DataView]",j="[object Float32Array]",T="[object Float64Array]",I="[object Int8Array]",_="[object Int16Array]",O="[object Int32Array]",$="[object Uint8Array]",D="[object Uint8ClampedArray]",P="[object Uint16Array]",R="[object Uint32Array]",B=/\b__p \+= '';/g,W=/\b(__p \+=) '' \+/g,L=/(__e\(.*?\)|\b__t\)) \+\n'';/g,F=/&(?:amp|lt|gt|quot|#39);/g,N=/[&<>"']/g,K=RegExp(F.source),Q=RegExp(N.source),Y=/<%-([\s\S]+?)%>/g,H=/<%([\s\S]+?)%>/g,V=/<%=([\s\S]+?)%>/g,X=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,q=/^\w*$/,G=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,J=/[\\^$.*+?()[\]{}|]/g,Z=RegExp(J.source),tt=/^\s+/,nt=/\s/,et=/\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,rt=/\{\n\/\* \[wrapped with (.+)\] \*/,it=/,? & /,st=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g,ot=/[()=,{}\[\]\/\s]/,ut=/\\(\\)?/g,ct=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,ht=/\w*$/,at=/^[-+]0x[0-9a-f]+$/i,lt=/^0b[01]+$/i,ft=/^\[object .+?Constructor\]$/,dt=/^0o[0-7]+$/i,vt=/^(?:0|[1-9]\d*)$/,pt=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,wt=/($^)/,yt=/['\n\r\u2028\u2029\\]/g,gt="\\ud800-\\udfff",bt="\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff",mt="\\u2700-\\u27bf",At="a-z\\xdf-\\xf6\\xf8-\\xff",kt="A-Z\\xc0-\\xd6\\xd8-\\xde",xt="\\ufe0e\\ufe0f",Mt="\\xac\\xb1\\xd7\\xf7\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf\\u2000-\\u206f \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000",St="["+gt+"]",Ct="["+Mt+"]",Ut="["+bt+"]",Et="\\d+",jt="["+mt+"]",Tt="["+At+"]",It="[^"+gt+Mt+Et+mt+At+kt+"]",_t="\\ud83c[\\udffb-\\udfff]",Ot="[^"+gt+"]",zt="(?:\\ud83c[\\udde6-\\uddff]){2}",$t="[\\ud800-\\udbff][\\udc00-\\udfff]",Dt="["+kt+"]",Pt="\\u200d",Rt="(?:"+Tt+"|"+It+")",Bt="(?:"+Dt+"|"+It+")",Wt="(?:['’](?:d|ll|m|re|s|t|ve))?",Lt="(?:['’](?:D|LL|M|RE|S|T|VE))?",Ft="(?:"+Ut+"|"+_t+")?",Nt="["+xt+"]?",Kt=Nt+Ft+"(?:"+Pt+"(?:"+[Ot,zt,$t].join("|")+")"+Nt+Ft+")*",Qt="(?:"+[jt,zt,$t].join("|")+")"+Kt,Yt="(?:"+[Ot+Ut+"?",Ut,zt,$t,St].join("|")+")",Ht=RegExp("['’]","g"),Vt=RegExp(Ut,"g"),Xt=RegExp(_t+"(?="+_t+")|"+Yt+Kt,"g"),qt=RegExp([Dt+"?"+Tt+"+"+Wt+"(?="+[Ct,Dt,"$"].join("|")+")",Bt+"+"+Lt+"(?="+[Ct,Dt+Rt,"$"].join("|")+")",Dt+"?"+Rt+"+"+Wt,Dt+"+"+Lt,"\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])","\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",Et,Qt].join("|"),"g"),Gt=RegExp("["+Pt+gt+bt+xt+"]"),Jt=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/,Zt=["Array","Buffer","DataView","Date","Error","Float32Array","Float64Array","Function","Int8Array","Int16Array","Int32Array","Map","Math","Object","Promise","RegExp","Set","String","Symbol","TypeError","Uint8Array","Uint8ClampedArray","Uint16Array","Uint32Array","WeakMap","_","clearTimeout","isFinite","parseInt","setTimeout"],tn=-1,nn={};nn[j]=nn[T]=nn[I]=nn[_]=nn[O]=nn[$]=nn[D]=nn[P]=nn[R]=!0,nn[l]=nn[f]=nn[U]=nn[d]=nn[E]=nn[v]=nn[p]=nn[w]=nn[g]=nn[b]=nn[m]=nn[k]=nn[x]=nn[M]=nn[C]=!1;var en={};en[l]=en[f]=en[U]=en[E]=en[d]=en[v]=en[j]=en[T]=en[I]=en[_]=en[O]=en[g]=en[b]=en[m]=en[k]=en[x]=en[M]=en[S]=en[$]=en[D]=en[P]=en[R]=!0,en[p]=en[w]=en[C]=!1;var rn={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"},sn=parseFloat,on=parseInt,un="object"==typeof z&&z&&z.Object===Object&&z,cn="object"==typeof self&&self&&self.Object===Object&&self,hn=un||cn||Function("return this")(),an=zc&&!zc.nodeType&&zc,ln=an&&Oc&&!Oc.nodeType&&Oc,fn=ln&&ln.exports===an,dn=fn&&un.process,vn=function(){try{return ln&&ln.require&&ln.require("util").types||dn&&dn.binding&&dn.binding("util")}catch(t){}}(),pn=vn&&vn.isArrayBuffer,wn=vn&&vn.isDate,yn=vn&&vn.isMap,gn=vn&&vn.isRegExp,bn=vn&&vn.isSet,mn=vn&&vn.isTypedArray;function An(t,n,e){switch(e.length){case 0:return t.call(n);case 1:return t.call(n,e[0]);case 2:return t.call(n,e[0],e[1]);case 3:return t.call(n,e[0],e[1],e[2])}return t.apply(n,e)}function kn(t,n,e,r){for(var i=-1,s=null==t?0:t.length;++i<s;){var o=t[i];n(r,o,e(o),t)}return r}function xn(t,n){for(var e=-1,r=null==t?0:t.length;++e<r&&!1!==n(t[e],e,t););return t}function Mn(t,n){for(var e=null==t?0:t.length;e--&&!1!==n(t[e],e,t););return t}function Sn(t,n){for(var e=-1,r=null==t?0:t.length;++e<r;)if(!n(t[e],e,t))return!1;return!0}function Cn(t,n){for(var e=-1,r=null==t?0:t.length,i=0,s=[];++e<r;){var o=t[e];n(o,e,t)&&(s[i++]=o)}return s}function Un(t,n){return!(null==t||!t.length)&&Pn(t,n,0)>-1}function En(t,n,e){for(var r=-1,i=null==t?0:t.length;++r<i;)if(e(n,t[r]))return!0;return!1}function jn(t,n){for(var e=-1,r=null==t?0:t.length,i=Array(r);++e<r;)i[e]=n(t[e],e,t);return i}function Tn(t,n){for(var e=-1,r=n.length,i=t.length;++e<r;)t[i+e]=n[e];return t}function In(t,n,e,r){var i=-1,s=null==t?0:t.length;for(r&&s&&(e=t[++i]);++i<s;)e=n(e,t[i],i,t);return e}function _n(t,n,e,r){var i=null==t?0:t.length;for(r&&i&&(e=t[--i]);i--;)e=n(e,t[i],i,t);return e}function On(t,n){for(var e=-1,r=null==t?0:t.length;++e<r;)if(n(t[e],e,t))return!0;return!1}var zn=Ln("length");function $n(t,n,e){var r;return e(t,(function(t,e,i){if(n(t,e,i))return r=e,!1})),r}function Dn(t,n,e,r){for(var i=t.length,s=e+(r?1:-1);r?s--:++s<i;)if(n(t[s],s,t))return s;return-1}function Pn(t,n,e){return n==n?function(t,n,e){for(var r=e-1,i=t.length;++r<i;)if(t[r]===n)return r;return-1}(t,n,e):Dn(t,Bn,e)}function Rn(t,n,e,r){for(var i=e-1,s=t.length;++i<s;)if(r(t[i],n))return i;return-1}function Bn(t){return t!=t}function Wn(t,n){var e=null==t?0:t.length;return e?Kn(t,n)/e:c}function Ln(n){return function(e){return null==e?t:e[n]}}function Fn(n){return function(e){return null==n?t:n[e]}}function Nn(t,n,e,r,i){return i(t,(function(t,i,s){e=r?(r=!1,t):n(e,t,i,s)})),e}function Kn(n,e){for(var r,i=-1,s=n.length;++i<s;){var o=e(n[i]);o!==t&&(r=r===t?o:r+o)}return r}function Qn(t,n){for(var e=-1,r=Array(t);++e<t;)r[e]=n(e);return r}function Yn(t){return t?t.slice(0,he(t)+1).replace(tt,""):t}function Hn(t){return function(n){return t(n)}}function Vn(t,n){return jn(n,(function(n){return t[n]}))}function Xn(t,n){return t.has(n)}function qn(t,n){for(var e=-1,r=t.length;++e<r&&Pn(n,t[e],0)>-1;);return e}function Gn(t,n){for(var e=t.length;e--&&Pn(n,t[e],0)>-1;);return e}var Jn=Fn({À:"A",Á:"A",Â:"A",Ã:"A",Ä:"A",Å:"A",à:"a",á:"a",â:"a",ã:"a",ä:"a",å:"a",Ç:"C",ç:"c",Ð:"D",ð:"d",È:"E",É:"E",Ê:"E",Ë:"E",è:"e",é:"e",ê:"e",ë:"e",Ì:"I",Í:"I",Î:"I",Ï:"I",ì:"i",í:"i",î:"i",ï:"i",Ñ:"N",ñ:"n",Ò:"O",Ó:"O",Ô:"O",Õ:"O",Ö:"O",Ø:"O",ò:"o",ó:"o",ô:"o",õ:"o",ö:"o",ø:"o",Ù:"U",Ú:"U",Û:"U",Ü:"U",ù:"u",ú:"u",û:"u",ü:"u",Ý:"Y",ý:"y",ÿ:"y",Æ:"Ae",æ:"ae",Þ:"Th",þ:"th",ß:"ss",Ā:"A",Ă:"A",Ą:"A",ā:"a",ă:"a",ą:"a",Ć:"C",Ĉ:"C",Ċ:"C",Č:"C",ć:"c",ĉ:"c",ċ:"c",č:"c",Ď:"D",Đ:"D",ď:"d",đ:"d",Ē:"E",Ĕ:"E",Ė:"E",Ę:"E",Ě:"E",ē:"e",ĕ:"e",ė:"e",ę:"e",ě:"e",Ĝ:"G",Ğ:"G",Ġ:"G",Ģ:"G",ĝ:"g",ğ:"g",ġ:"g",ģ:"g",Ĥ:"H",Ħ:"H",ĥ:"h",ħ:"h",Ĩ:"I",Ī:"I",Ĭ:"I",Į:"I",İ:"I",ĩ:"i",ī:"i",ĭ:"i",į:"i",ı:"i",Ĵ:"J",ĵ:"j",Ķ:"K",ķ:"k",ĸ:"k",Ĺ:"L",Ļ:"L",Ľ:"L",Ŀ:"L",Ł:"L",ĺ:"l",ļ:"l",ľ:"l",ŀ:"l",ł:"l",Ń:"N",Ņ:"N",Ň:"N",Ŋ:"N",ń:"n",ņ:"n",ň:"n",ŋ:"n",Ō:"O",Ŏ:"O",Ő:"O",ō:"o",ŏ:"o",ő:"o",Ŕ:"R",Ŗ:"R",Ř:"R",ŕ:"r",ŗ:"r",ř:"r",Ś:"S",Ŝ:"S",Ş:"S",Š:"S",ś:"s",ŝ:"s",ş:"s",š:"s",Ţ:"T",Ť:"T",Ŧ:"T",ţ:"t",ť:"t",ŧ:"t",Ũ:"U",Ū:"U",Ŭ:"U",Ů:"U",Ű:"U",Ų:"U",ũ:"u",ū:"u",ŭ:"u",ů:"u",ű:"u",ų:"u",Ŵ:"W",ŵ:"w",Ŷ:"Y",ŷ:"y",Ÿ:"Y",Ź:"Z",Ż:"Z",Ž:"Z",ź:"z",ż:"z",ž:"z",IJ:"IJ",ij:"ij",Œ:"Oe",œ:"oe",ʼn:"'n",ſ:"s"}),Zn=Fn({"&":"&","<":"<",">":">",'"':""","'":"'"});function te(t){return"\\"+rn[t]}function ne(t){return Gt.test(t)}function ee(t){var n=-1,e=Array(t.size);return t.forEach((function(t,r){e[++n]=[r,t]})),e}function re(t,n){return function(e){return t(n(e))}}function ie(t,n){for(var e=-1,i=t.length,s=0,o=[];++e<i;){var u=t[e];u!==n&&u!==r||(t[e]=r,o[s++]=e)}return o}function se(t){var n=-1,e=Array(t.size);return t.forEach((function(t){e[++n]=t})),e}function oe(t){var n=-1,e=Array(t.size);return t.forEach((function(t){e[++n]=[t,t]})),e}function ue(t){return ne(t)?function(t){for(var n=Xt.lastIndex=0;Xt.test(t);)++n;return n}(t):zn(t)}function ce(t){return ne(t)?function(t){return t.match(Xt)||[]}(t):function(t){return t.split("")}(t)}function he(t){for(var n=t.length;n--&&nt.test(t.charAt(n)););return n}var ae=Fn({"&":"&","<":"<",">":">",""":'"',"'":"'"}),le=function z(nt){var gt,bt=(nt=null==nt?hn:le.defaults(hn.Object(),nt,le.pick(hn,Zt))).Array,mt=nt.Date,At=nt.Error,kt=nt.Function,xt=nt.Math,Mt=nt.Object,St=nt.RegExp,Ct=nt.String,Ut=nt.TypeError,Et=bt.prototype,jt=Mt.prototype,Tt=nt["__core-js_shared__"],It=kt.prototype.toString,_t=jt.hasOwnProperty,Ot=0,zt=(gt=/[^.]+$/.exec(Tt&&Tt.keys&&Tt.keys.IE_PROTO||""))?"Symbol(src)_1."+gt:"",$t=jt.toString,Dt=It.call(Mt),Pt=hn._,Rt=St("^"+It.call(_t).replace(J,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Bt=fn?nt.Buffer:t,Wt=nt.Symbol,Lt=nt.Uint8Array,Ft=Bt?Bt.allocUnsafe:t,Nt=re(Mt.getPrototypeOf,Mt),Kt=Mt.create,Qt=jt.propertyIsEnumerable,Yt=Et.splice,Xt=Wt?Wt.isConcatSpreadable:t,Gt=Wt?Wt.iterator:t,rn=Wt?Wt.toStringTag:t,un=function(){try{var t=us(Mt,"defineProperty");return t({},"",{}),t}catch(t){}}(),cn=nt.clearTimeout!==hn.clearTimeout&&nt.clearTimeout,an=mt&&mt.now!==hn.Date.now&&mt.now,ln=nt.setTimeout!==hn.setTimeout&&nt.setTimeout,dn=xt.ceil,vn=xt.floor,zn=Mt.getOwnPropertySymbols,Fn=Bt?Bt.isBuffer:t,fe=nt.isFinite,de=Et.join,ve=re(Mt.keys,Mt),pe=xt.max,we=xt.min,ye=mt.now,ge=nt.parseInt,be=xt.random,me=Et.reverse,Ae=us(nt,"DataView"),ke=us(nt,"Map"),xe=us(nt,"Promise"),Me=us(nt,"Set"),Se=us(nt,"WeakMap"),Ce=us(Mt,"create"),Ue=Se&&new Se,Ee={},je=$s(Ae),Te=$s(ke),Ie=$s(xe),_e=$s(Me),Oe=$s(Se),ze=Wt?Wt.prototype:t,$e=ze?ze.valueOf:t,De=ze?ze.toString:t;function Pe(t){if(Zo(t)&&!Fo(t)&&!(t instanceof Le)){if(t instanceof We)return t;if(_t.call(t,"__wrapped__"))return Ds(t)}return new We(t)}var Re=function(){function n(){}return function(e){if(!Jo(e))return{};if(Kt)return Kt(e);n.prototype=e;var r=new n;return n.prototype=t,r}}();function Be(){}function We(n,e){this.__wrapped__=n,this.__actions__=[],this.__chain__=!!e,this.__index__=0,this.__values__=t}function Le(t){this.__wrapped__=t,this.__actions__=[],this.__dir__=1,this.__filtered__=!1,this.__iteratees__=[],this.__takeCount__=h,this.__views__=[]}function Fe(t){var n=-1,e=null==t?0:t.length;for(this.clear();++n<e;){var r=t[n];this.set(r[0],r[1])}}function Ne(t){var n=-1,e=null==t?0:t.length;for(this.clear();++n<e;){var r=t[n];this.set(r[0],r[1])}}function Ke(t){var n=-1,e=null==t?0:t.length;for(this.clear();++n<e;){var r=t[n];this.set(r[0],r[1])}}function Qe(t){var n=-1,e=null==t?0:t.length;for(this.__data__=new Ke;++n<e;)this.add(t[n])}function Ye(t){var n=this.__data__=new Ne(t);this.size=n.size}function He(t,n){var e=Fo(t),r=!e&&Lo(t),i=!e&&!r&&Yo(t),s=!e&&!r&&!i&&uu(t),o=e||r||i||s,u=o?Qn(t.length,Ct):[],c=u.length;for(var h in t)!n&&!_t.call(t,h)||o&&("length"==h||i&&("offset"==h||"parent"==h)||s&&("buffer"==h||"byteLength"==h||"byteOffset"==h)||vs(h,c))||u.push(h);return u}function Ve(n){var e=n.length;return e?n[Kr(0,e-1)]:t}function Xe(t,n){return Ts(Si(t),ir(n,0,t.length))}function qe(t){return Ts(Si(t))}function Ge(n,e,r){(r!==t&&!Ro(n[e],r)||r===t&&!(e in n))&&er(n,e,r)}function Je(n,e,r){var i=n[e];_t.call(n,e)&&Ro(i,r)&&(r!==t||e in n)||er(n,e,r)}function Ze(t,n){for(var e=t.length;e--;)if(Ro(t[e][0],n))return e;return-1}function tr(t,n,e,r){return hr(t,(function(t,i,s){n(r,t,e(t),s)})),r}function nr(t,n){return t&&Ci(n,ju(n),t)}function er(t,n,e){"__proto__"==n&&un?un(t,n,{configurable:!0,enumerable:!0,value:e,writable:!0}):t[n]=e}function rr(n,e){for(var r=-1,i=e.length,s=bt(i),o=null==n;++r<i;)s[r]=o?t:Mu(n,e[r]);return s}function ir(n,e,r){return n==n&&(r!==t&&(n=n<=r?n:r),e!==t&&(n=n>=e?n:e)),n}function sr(n,e,r,i,s,o){var u,c=1&e,h=2&e,a=4&e;if(r&&(u=s?r(n,i,s,o):r(n)),u!==t)return u;if(!Jo(n))return n;var f=Fo(n);if(f){if(u=function(t){var n=t.length,e=new t.constructor(n);return n&&"string"==typeof t[0]&&_t.call(t,"index")&&(e.index=t.index,e.input=t.input),e}(n),!c)return Si(n,u)}else{var p=as(n),A=p==w||p==y;if(Yo(n))return bi(n,c);if(p==m||p==l||A&&!s){if(u=h||A?{}:fs(n),!c)return h?function(t,n){return Ci(t,hs(t),n)}(n,function(t,n){return t&&Ci(n,Tu(n),t)}(u,n)):function(t,n){return Ci(t,cs(t),n)}(n,nr(u,n))}else{if(!en[p])return s?n:{};u=function(t,n,e){var r=t.constructor;switch(n){case U:return mi(t);case d:case v:return new r(+t);case E:return function(t,n){var e=n?mi(t.buffer):t.buffer;return new t.constructor(e,t.byteOffset,t.byteLength)}(t,e);case j:case T:case I:case _:case O:case $:case D:case P:case R:return Ai(t,e);case g:return new r;case b:case M:return new r(t);case k:return function(t){var n=new t.constructor(t.source,ht.exec(t));return n.lastIndex=t.lastIndex,n}(t);case x:return new r;case S:return $e?Mt($e.call(t)):{}}}(n,p,c)}}o||(o=new Ye);var C=o.get(n);if(C)return C;o.set(n,u),iu(n)?n.forEach((function(t){u.add(sr(t,e,r,t,n,o))})):tu(n)&&n.forEach((function(t,i){u.set(i,sr(t,e,r,i,n,o))}));var z=f?t:(a?h?ts:Zi:h?Tu:ju)(n);return xn(z||n,(function(t,i){z&&(t=n[i=t]),Je(u,i,sr(t,e,r,i,n,o))})),u}function or(n,e,r){var i=r.length;if(null==n)return!i;for(n=Mt(n);i--;){var s=r[i],o=n[s];if(o===t&&!(s in n)||!(0,e[s])(o))return!1}return!0}function ur(e,r,i){if("function"!=typeof e)throw new Ut(n);return Cs((function(){e.apply(t,i)}),r)}function cr(t,n,e,r){var i=-1,s=Un,o=!0,u=t.length,c=[],h=n.length;if(!u)return c;e&&(n=jn(n,Hn(e))),r?(s=En,o=!1):n.length>=200&&(s=Xn,o=!1,n=new Qe(n));t:for(;++i<u;){var a=t[i],l=null==e?a:e(a);if(a=r||0!==a?a:0,o&&l==l){for(var f=h;f--;)if(n[f]===l)continue t;c.push(a)}else s(n,l,r)||c.push(a)}return c}Pe.templateSettings={escape:Y,evaluate:H,interpolate:V,variable:"",imports:{_:Pe}},(Pe.prototype=Be.prototype).constructor=Pe,(We.prototype=Re(Be.prototype)).constructor=We,(Le.prototype=Re(Be.prototype)).constructor=Le,Fe.prototype.clear=function(){this.__data__=Ce?Ce(null):{},this.size=0},Fe.prototype.delete=function(t){var n=this.has(t)&&delete this.__data__[t];return this.size-=n?1:0,n},Fe.prototype.get=function(n){var r=this.__data__;if(Ce){var i=r[n];return i===e?t:i}return _t.call(r,n)?r[n]:t},Fe.prototype.has=function(n){var e=this.__data__;return Ce?e[n]!==t:_t.call(e,n)},Fe.prototype.set=function(n,r){var i=this.__data__;return this.size+=this.has(n)?0:1,i[n]=Ce&&r===t?e:r,this},Ne.prototype.clear=function(){this.__data__=[],this.size=0},Ne.prototype.delete=function(t){var n=this.__data__,e=Ze(n,t);return!(e<0||(e==n.length-1?n.pop():Yt.call(n,e,1),--this.size,0))},Ne.prototype.get=function(n){var e=this.__data__,r=Ze(e,n);return r<0?t:e[r][1]},Ne.prototype.has=function(t){return Ze(this.__data__,t)>-1},Ne.prototype.set=function(t,n){var e=this.__data__,r=Ze(e,t);return r<0?(++this.size,e.push([t,n])):e[r][1]=n,this},Ke.prototype.clear=function(){this.size=0,this.__data__={hash:new Fe,map:new(ke||Ne),string:new Fe}},Ke.prototype.delete=function(t){var n=ss(this,t).delete(t);return this.size-=n?1:0,n},Ke.prototype.get=function(t){return ss(this,t).get(t)},Ke.prototype.has=function(t){return ss(this,t).has(t)},Ke.prototype.set=function(t,n){var e=ss(this,t),r=e.size;return e.set(t,n),this.size+=e.size==r?0:1,this},Qe.prototype.add=Qe.prototype.push=function(t){return this.__data__.set(t,e),this},Qe.prototype.has=function(t){return this.__data__.has(t)},Ye.prototype.clear=function(){this.__data__=new Ne,this.size=0},Ye.prototype.delete=function(t){var n=this.__data__,e=n.delete(t);return this.size=n.size,e},Ye.prototype.get=function(t){return this.__data__.get(t)},Ye.prototype.has=function(t){return this.__data__.has(t)},Ye.prototype.set=function(t,n){var e=this.__data__;if(e instanceof Ne){var r=e.__data__;if(!ke||r.length<199)return r.push([t,n]),this.size=++e.size,this;e=this.__data__=new Ke(r)}return e.set(t,n),this.size=e.size,this};var hr=ji(yr),ar=ji(gr,!0);function lr(t,n){var e=!0;return hr(t,(function(t,r,i){return e=!!n(t,r,i)})),e}function fr(n,e,r){for(var i=-1,s=n.length;++i<s;){var o=n[i],u=e(o);if(null!=u&&(c===t?u==u&&!ou(u):r(u,c)))var c=u,h=o}return h}function dr(t,n){var e=[];return hr(t,(function(t,r,i){n(t,r,i)&&e.push(t)})),e}function vr(t,n,e,r,i){var s=-1,o=t.length;for(e||(e=ds),i||(i=[]);++s<o;){var u=t[s];n>0&&e(u)?n>1?vr(u,n-1,e,r,i):Tn(i,u):r||(i[i.length]=u)}return i}var pr=Ti(),wr=Ti(!0);function yr(t,n){return t&&pr(t,n,ju)}function gr(t,n){return t&&wr(t,n,ju)}function br(t,n){return Cn(n,(function(n){return Xo(t[n])}))}function mr(n,e){for(var r=0,i=(e=pi(e,n)).length;null!=n&&r<i;)n=n[zs(e[r++])];return r&&r==i?n:t}function Ar(t,n,e){var r=n(t);return Fo(t)?r:Tn(r,e(t))}function kr(n){return null==n?n===t?"[object Undefined]":"[object Null]":rn&&rn in Mt(n)?function(n){var e=_t.call(n,rn),r=n[rn];try{n[rn]=t;var i=!0}catch(t){}var s=$t.call(n);return i&&(e?n[rn]=r:delete n[rn]),s}(n):function(t){return $t.call(t)}(n)}function xr(t,n){return t>n}function Mr(t,n){return null!=t&&_t.call(t,n)}function Sr(t,n){return null!=t&&n in Mt(t)}function Cr(n,e,r){for(var i=r?En:Un,s=n[0].length,o=n.length,u=o,c=bt(o),h=1/0,a=[];u--;){var l=n[u];u&&e&&(l=jn(l,Hn(e))),h=we(l.length,h),c[u]=!r&&(e||s>=120&&l.length>=120)?new Qe(u&&l):t}l=n[0];var f=-1,d=c[0];t:for(;++f<s&&a.length<h;){var v=l[f],p=e?e(v):v;if(v=r||0!==v?v:0,!(d?Xn(d,p):i(a,p,r))){for(u=o;--u;){var w=c[u];if(!(w?Xn(w,p):i(n[u],p,r)))continue t}d&&d.push(p),a.push(v)}}return a}function Ur(n,e,r){var i=null==(n=xs(n,e=pi(e,n)))?n:n[zs(Hs(e))];return null==i?t:An(i,n,r)}function Er(t){return Zo(t)&&kr(t)==l}function jr(n,e,r,i,s){return n===e||(null==n||null==e||!Zo(n)&&!Zo(e)?n!=n&&e!=e:function(n,e,r,i,s,o){var u=Fo(n),c=Fo(e),h=u?f:as(n),a=c?f:as(e),w=(h=h==l?m:h)==m,y=(a=a==l?m:a)==m,A=h==a;if(A&&Yo(n)){if(!Yo(e))return!1;u=!0,w=!1}if(A&&!w)return o||(o=new Ye),u||uu(n)?Gi(n,e,r,i,s,o):function(t,n,e,r,i,s,o){switch(e){case E:if(t.byteLength!=n.byteLength||t.byteOffset!=n.byteOffset)return!1;t=t.buffer,n=n.buffer;case U:return!(t.byteLength!=n.byteLength||!s(new Lt(t),new Lt(n)));case d:case v:case b:return Ro(+t,+n);case p:return t.name==n.name&&t.message==n.message;case k:case M:return t==n+"";case g:var u=ee;case x:if(u||(u=se),t.size!=n.size&&!(1&r))return!1;var c=o.get(t);if(c)return c==n;r|=2,o.set(t,n);var h=Gi(u(t),u(n),r,i,s,o);return o.delete(t),h;case S:if($e)return $e.call(t)==$e.call(n)}return!1}(n,e,h,r,i,s,o);if(!(1&r)){var C=w&&_t.call(n,"__wrapped__"),j=y&&_t.call(e,"__wrapped__");if(C||j){var T=C?n.value():n,I=j?e.value():e;return o||(o=new Ye),s(T,I,r,i,o)}}return!!A&&(o||(o=new Ye),function(n,e,r,i,s,o){var u=1&r,c=Zi(n),h=c.length;if(h!=Zi(e).length&&!u)return!1;for(var a=h;a--;){var l=c[a];if(!(u?l in e:_t.call(e,l)))return!1}var f=o.get(n),d=o.get(e);if(f&&d)return f==e&&d==n;var v=!0;o.set(n,e),o.set(e,n);for(var p=u;++a<h;){var w=n[l=c[a]],y=e[l];if(i)var g=u?i(y,w,l,e,n,o):i(w,y,l,n,e,o);if(!(g===t?w===y||s(w,y,r,i,o):g)){v=!1;break}p||(p="constructor"==l)}if(v&&!p){var b=n.constructor,m=e.constructor;b==m||!("constructor"in n)||!("constructor"in e)||"function"==typeof b&&b instanceof b&&"function"==typeof m&&m instanceof m||(v=!1)}return o.delete(n),o.delete(e),v}(n,e,r,i,s,o))}(n,e,r,i,jr,s))}function Tr(n,e,r,i){var s=r.length,o=s,u=!i;if(null==n)return!o;for(n=Mt(n);s--;){var c=r[s];if(u&&c[2]?c[1]!==n[c[0]]:!(c[0]in n))return!1}for(;++s<o;){var h=(c=r[s])[0],a=n[h],l=c[1];if(u&&c[2]){if(a===t&&!(h in n))return!1}else{var f=new Ye;if(i)var d=i(a,l,h,n,e,f);if(!(d===t?jr(l,a,3,i,f):d))return!1}}return!0}function Ir(t){return!(!Jo(t)||(n=t,zt&&zt in n))&&(Xo(t)?Rt:ft).test($s(t));var n}function _r(t){return"function"==typeof t?t:null==t?nc:"object"==typeof t?Fo(t)?Pr(t[0],t[1]):Dr(t):ac(t)}function Or(t){if(!bs(t))return ve(t);var n=[];for(var e in Mt(t))_t.call(t,e)&&"constructor"!=e&&n.push(e);return n}function zr(t,n){return t<n}function $r(t,n){var e=-1,r=Ko(t)?bt(t.length):[];return hr(t,(function(t,i,s){r[++e]=n(t,i,s)})),r}function Dr(t){var n=os(t);return 1==n.length&&n[0][2]?As(n[0][0],n[0][1]):function(e){return e===t||Tr(e,t,n)}}function Pr(n,e){return ws(n)&&ms(e)?As(zs(n),e):function(r){var i=Mu(r,n);return i===t&&i===e?Su(r,n):jr(e,i,3)}}function Rr(n,e,r,i,s){n!==e&&pr(e,(function(o,u){if(s||(s=new Ye),Jo(o))!function(n,e,r,i,s,o,u){var c=Ms(n,r),h=Ms(e,r),a=u.get(h);if(a)Ge(n,r,a);else{var l=o?o(c,h,r+"",n,e,u):t,f=l===t;if(f){var d=Fo(h),v=!d&&Yo(h),p=!d&&!v&&uu(h);l=h,d||v||p?Fo(c)?l=c:Qo(c)?l=Si(c):v?(f=!1,l=bi(h,!0)):p?(f=!1,l=Ai(h,!0)):l=[]:eu(h)||Lo(h)?(l=c,Lo(c)?l=pu(c):Jo(c)&&!Xo(c)||(l=fs(h))):f=!1}f&&(u.set(h,l),s(l,h,i,o,u),u.delete(h)),Ge(n,r,l)}}(n,e,u,r,Rr,i,s);else{var c=i?i(Ms(n,u),o,u+"",n,e,s):t;c===t&&(c=o),Ge(n,u,c)}}),Tu)}function Br(n,e){var r=n.length;if(r)return vs(e+=e<0?r:0,r)?n[e]:t}function Wr(t,n,e){n=n.length?jn(n,(function(t){return Fo(t)?function(n){return mr(n,1===t.length?t[0]:t)}:t})):[nc];var r=-1;n=jn(n,Hn(is()));var i=$r(t,(function(t){var e=jn(n,(function(n){return n(t)}));return{criteria:e,index:++r,value:t}}));return function(t){var n=t.length;for(t.sort((function(t,n){return function(t,n,e){for(var r=-1,i=t.criteria,s=n.criteria,o=i.length,u=e.length;++r<o;){var c=ki(i[r],s[r]);if(c)return r>=u?c:c*("desc"==e[r]?-1:1)}return t.index-n.index}(t,n,e)}));n--;)t[n]=t[n].value;return t}(i)}function Lr(t,n,e){for(var r=-1,i=n.length,s={};++r<i;){var o=n[r],u=mr(t,o);e(u,o)&&Xr(s,pi(o,t),u)}return s}function Fr(t,n,e,r){var i=r?Rn:Pn,s=-1,o=n.length,u=t;for(t===n&&(n=Si(n)),e&&(u=jn(t,Hn(e)));++s<o;)for(var c=0,h=n[s],a=e?e(h):h;(c=i(u,a,c,r))>-1;)u!==t&&Yt.call(u,c,1),Yt.call(t,c,1);return t}function Nr(t,n){for(var e=t?n.length:0,r=e-1;e--;){var i=n[e];if(e==r||i!==s){var s=i;vs(i)?Yt.call(t,i,1):ui(t,i)}}return t}function Kr(t,n){return t+vn(be()*(n-t+1))}function Qr(t,n){var e="";if(!t||n<1||n>u)return e;do{n%2&&(e+=t),(n=vn(n/2))&&(t+=t)}while(n);return e}function Yr(t,n){return Us(ks(t,n,nc),t+"")}function Hr(t){return Ve(Ru(t))}function Vr(t,n){var e=Ru(t);return Ts(e,ir(n,0,e.length))}function Xr(n,e,r,i){if(!Jo(n))return n;for(var s=-1,o=(e=pi(e,n)).length,u=o-1,c=n;null!=c&&++s<o;){var h=zs(e[s]),a=r;if("__proto__"===h||"constructor"===h||"prototype"===h)return n;if(s!=u){var l=c[h];(a=i?i(l,h,c):t)===t&&(a=Jo(l)?l:vs(e[s+1])?[]:{})}Je(c,h,a),c=c[h]}return n}var qr=Ue?function(t,n){return Ue.set(t,n),t}:nc,Gr=un?function(t,n){return un(t,"toString",{configurable:!0,enumerable:!1,value:Ju(n),writable:!0})}:nc;function Jr(t){return Ts(Ru(t))}function Zr(t,n,e){var r=-1,i=t.length;n<0&&(n=-n>i?0:i+n),(e=e>i?i:e)<0&&(e+=i),i=n>e?0:e-n>>>0,n>>>=0;for(var s=bt(i);++r<i;)s[r]=t[r+n];return s}function ti(t,n){var e;return hr(t,(function(t,r,i){return!(e=n(t,r,i))})),!!e}function ni(t,n,e){var r=0,i=null==t?r:t.length;if("number"==typeof n&&n==n&&i<=2147483647){for(;r<i;){var s=r+i>>>1,o=t[s];null!==o&&!ou(o)&&(e?o<=n:o<n)?r=s+1:i=s}return i}return ei(t,n,nc,e)}function ei(n,e,r,i){var s=0,o=null==n?0:n.length;if(0===o)return 0;for(var u=(e=r(e))!=e,c=null===e,h=ou(e),a=e===t;s<o;){var l=vn((s+o)/2),f=r(n[l]),d=f!==t,v=null===f,p=f==f,w=ou(f);if(u)var y=i||p;else y=a?p&&(i||d):c?p&&d&&(i||!v):h?p&&d&&!v&&(i||!w):!v&&!w&&(i?f<=e:f<e);y?s=l+1:o=l}return we(o,4294967294)}function ri(t,n){for(var e=-1,r=t.length,i=0,s=[];++e<r;){var o=t[e],u=n?n(o):o;if(!e||!Ro(u,c)){var c=u;s[i++]=0===o?0:o}}return s}function ii(t){return"number"==typeof t?t:ou(t)?c:+t}function si(t){if("string"==typeof t)return t;if(Fo(t))return jn(t,si)+"";if(ou(t))return De?De.call(t):"";var n=t+"";return"0"==n&&1/t==-1/0?"-0":n}function oi(t,n,e){var r=-1,i=Un,s=t.length,o=!0,u=[],c=u;if(e)o=!1,i=En;else if(s>=200){var h=n?null:Qi(t);if(h)return se(h);o=!1,i=Xn,c=new Qe}else c=n?[]:u;t:for(;++r<s;){var a=t[r],l=n?n(a):a;if(a=e||0!==a?a:0,o&&l==l){for(var f=c.length;f--;)if(c[f]===l)continue t;n&&c.push(l),u.push(a)}else i(c,l,e)||(c!==u&&c.push(l),u.push(a))}return u}function ui(t,n){return null==(t=xs(t,n=pi(n,t)))||delete t[zs(Hs(n))]}function ci(t,n,e,r){return Xr(t,n,e(mr(t,n)),r)}function hi(t,n,e,r){for(var i=t.length,s=r?i:-1;(r?s--:++s<i)&&n(t[s],s,t););return e?Zr(t,r?0:s,r?s+1:i):Zr(t,r?s+1:0,r?i:s)}function ai(t,n){var e=t;return e instanceof Le&&(e=e.value()),In(n,(function(t,n){return n.func.apply(n.thisArg,Tn([t],n.args))}),e)}function li(t,n,e){var r=t.length;if(r<2)return r?oi(t[0]):[];for(var i=-1,s=bt(r);++i<r;)for(var o=t[i],u=-1;++u<r;)u!=i&&(s[i]=cr(s[i]||o,t[u],n,e));return oi(vr(s,1),n,e)}function fi(n,e,r){for(var i=-1,s=n.length,o=e.length,u={};++i<s;)r(u,n[i],i<o?e[i]:t);return u}function di(t){return Qo(t)?t:[]}function vi(t){return"function"==typeof t?t:nc}function pi(t,n){return Fo(t)?t:ws(t,n)?[t]:Os(wu(t))}var wi=Yr;function yi(n,e,r){var i=n.length;return r=r===t?i:r,!e&&r>=i?n:Zr(n,e,r)}var gi=cn||function(t){return hn.clearTimeout(t)};function bi(t,n){if(n)return t.slice();var e=t.length,r=Ft?Ft(e):new t.constructor(e);return t.copy(r),r}function mi(t){var n=new t.constructor(t.byteLength);return new Lt(n).set(new Lt(t)),n}function Ai(t,n){var e=n?mi(t.buffer):t.buffer;return new t.constructor(e,t.byteOffset,t.length)}function ki(n,e){if(n!==e){var r=n!==t,i=null===n,s=n==n,o=ou(n),u=e!==t,c=null===e,h=e==e,a=ou(e);if(!c&&!a&&!o&&n>e||o&&u&&h&&!c&&!a||i&&u&&h||!r&&h||!s)return 1;if(!i&&!o&&!a&&n<e||a&&r&&s&&!i&&!o||c&&r&&s||!u&&s||!h)return-1}return 0}function xi(t,n,e,r){for(var i=-1,s=t.length,o=e.length,u=-1,c=n.length,h=pe(s-o,0),a=bt(c+h),l=!r;++u<c;)a[u]=n[u];for(;++i<o;)(l||i<s)&&(a[e[i]]=t[i]);for(;h--;)a[u++]=t[i++];return a}function Mi(t,n,e,r){for(var i=-1,s=t.length,o=-1,u=e.length,c=-1,h=n.length,a=pe(s-u,0),l=bt(a+h),f=!r;++i<a;)l[i]=t[i];for(var d=i;++c<h;)l[d+c]=n[c];for(;++o<u;)(f||i<s)&&(l[d+e[o]]=t[i++]);return l}function Si(t,n){var e=-1,r=t.length;for(n||(n=bt(r));++e<r;)n[e]=t[e];return n}function Ci(n,e,r,i){var s=!r;r||(r={});for(var o=-1,u=e.length;++o<u;){var c=e[o],h=i?i(r[c],n[c],c,r,n):t;h===t&&(h=n[c]),s?er(r,c,h):Je(r,c,h)}return r}function Ui(t,n){return function(e,r){var i=Fo(e)?kn:tr,s=n?n():{};return i(e,t,is(r,2),s)}}function Ei(n){return Yr((function(e,r){var i=-1,s=r.length,o=s>1?r[s-1]:t,u=s>2?r[2]:t;for(o=n.length>3&&"function"==typeof o?(s--,o):t,u&&ps(r[0],r[1],u)&&(o=s<3?t:o,s=1),e=Mt(e);++i<s;){var c=r[i];c&&n(e,c,i,o)}return e}))}function ji(t,n){return function(e,r){if(null==e)return e;if(!Ko(e))return t(e,r);for(var i=e.length,s=n?i:-1,o=Mt(e);(n?s--:++s<i)&&!1!==r(o[s],s,o););return e}}function Ti(t){return function(n,e,r){for(var i=-1,s=Mt(n),o=r(n),u=o.length;u--;){var c=o[t?u:++i];if(!1===e(s[c],c,s))break}return n}}function Ii(n){return function(e){var r=ne(e=wu(e))?ce(e):t,i=r?r[0]:e.charAt(0),s=r?yi(r,1).join(""):e.slice(1);return i[n]()+s}}function _i(t){return function(n){return In(Xu(Lu(n).replace(Ht,"")),t,"")}}function Oi(t){return function(){var n=arguments;switch(n.length){case 0:return new t;case 1:return new t(n[0]);case 2:return new t(n[0],n[1]);case 3:return new t(n[0],n[1],n[2]);case 4:return new t(n[0],n[1],n[2],n[3]);case 5:return new t(n[0],n[1],n[2],n[3],n[4]);case 6:return new t(n[0],n[1],n[2],n[3],n[4],n[5]);case 7:return new t(n[0],n[1],n[2],n[3],n[4],n[5],n[6])}var e=Re(t.prototype),r=t.apply(e,n);return Jo(r)?r:e}}function zi(n){return function(e,r,i){var s=Mt(e);if(!Ko(e)){var o=is(r,3);e=ju(e),r=function(t){return o(s[t],t,s)}}var u=n(e,r,i);return u>-1?s[o?e[u]:u]:t}}function $i(e){return Ji((function(r){var i=r.length,s=i,o=We.prototype.thru;for(e&&r.reverse();s--;){var u=r[s];if("function"!=typeof u)throw new Ut(n);if(o&&!c&&"wrapper"==es(u))var c=new We([],!0)}for(s=c?s:i;++s<i;){var h=es(u=r[s]),a="wrapper"==h?ns(u):t;c=a&&ys(a[0])&&424==a[1]&&!a[4].length&&1==a[9]?c[es(a[0])].apply(c,a[3]):1==u.length&&ys(u)?c[h]():c.thru(u)}return function(){var t=arguments,n=t[0];if(c&&1==t.length&&Fo(n))return c.plant(n).value();for(var e=0,s=i?r[e].apply(this,t):n;++e<i;)s=r[e].call(this,s);return s}}))}function Di(n,e,r,i,o,u,c,h,a,l){var f=e&s,d=1&e,v=2&e,p=24&e,w=512&e,y=v?t:Oi(n);return function s(){for(var g=arguments.length,b=bt(g),m=g;m--;)b[m]=arguments[m];if(p)var A=rs(s),k=function(t,n){for(var e=t.length,r=0;e--;)t[e]===n&&++r;return r}(b,A);if(i&&(b=xi(b,i,o,p)),u&&(b=Mi(b,u,c,p)),g-=k,p&&g<l){var x=ie(b,A);return Ni(n,e,Di,s.placeholder,r,b,x,h,a,l-g)}var M=d?r:this,S=v?M[n]:n;return g=b.length,h?b=function(n,e){for(var r=n.length,i=we(e.length,r),s=Si(n);i--;){var o=e[i];n[i]=vs(o,r)?s[o]:t}return n}(b,h):w&&g>1&&b.reverse(),f&&a<g&&(b.length=a),this&&this!==hn&&this instanceof s&&(S=y||Oi(S)),S.apply(M,b)}}function Pi(t,n){return function(e,r){return function(t,n,e,r){return yr(t,(function(t,i,s){n(r,e(t),i,s)})),r}(e,t,n(r),{})}}function Ri(n,e){return function(r,i){var s;if(r===t&&i===t)return e;if(r!==t&&(s=r),i!==t){if(s===t)return i;"string"==typeof r||"string"==typeof i?(r=si(r),i=si(i)):(r=ii(r),i=ii(i)),s=n(r,i)}return s}}function Bi(t){return Ji((function(n){return n=jn(n,Hn(is())),Yr((function(e){var r=this;return t(n,(function(t){return An(t,r,e)}))}))}))}function Wi(n,e){var r=(e=e===t?" ":si(e)).length;if(r<2)return r?Qr(e,n):e;var i=Qr(e,dn(n/ue(e)));return ne(e)?yi(ce(i),0,n).join(""):i.slice(0,n)}function Li(n){return function(e,r,i){return i&&"number"!=typeof i&&ps(e,r,i)&&(r=i=t),e=lu(e),r===t?(r=e,e=0):r=lu(r),function(t,n,e,r){for(var i=-1,s=pe(dn((n-t)/(e||1)),0),o=bt(s);s--;)o[r?s:++i]=t,t+=e;return o}(e,r,i=i===t?e<r?1:-1:lu(i),n)}}function Fi(t){return function(n,e){return"string"==typeof n&&"string"==typeof e||(n=vu(n),e=vu(e)),t(n,e)}}function Ni(n,e,r,s,o,u,c,h,a,l){var f=8&e;e|=f?i:64,4&(e&=~(f?64:i))||(e&=-4);var d=[n,e,o,f?u:t,f?c:t,f?t:u,f?t:c,h,a,l],v=r.apply(t,d);return ys(n)&&Ss(v,d),v.placeholder=s,Es(v,n,e)}function Ki(t){var n=xt[t];return function(t,e){if(t=vu(t),(e=null==e?0:we(fu(e),292))&&fe(t)){var r=(wu(t)+"e").split("e");return+((r=(wu(n(r[0]+"e"+(+r[1]+e)))+"e").split("e"))[0]+"e"+(+r[1]-e))}return n(t)}}var Qi=Me&&1/se(new Me([,-0]))[1]==o?function(t){return new Me(t)}:oc;function Yi(t){return function(n){var e=as(n);return e==g?ee(n):e==x?oe(n):function(t,n){return jn(n,(function(n){return[n,t[n]]}))}(n,t(n))}}function Hi(e,o,u,c,h,a,l,f){var d=2&o;if(!d&&"function"!=typeof e)throw new Ut(n);var v=c?c.length:0;if(v||(o&=-97,c=h=t),l=l===t?l:pe(fu(l),0),f=f===t?f:fu(f),v-=h?h.length:0,64&o){var p=c,w=h;c=h=t}var y=d?t:ns(e),g=[e,o,u,c,h,p,w,a,l,f];if(y&&function(t,n){var e=t[1],i=n[1],o=e|i;if(!(o<131||(i==s&&8==e||i==s&&256==e&&t[7].length<=n[8]||384==i&&n[7].length<=n[8]&&8==e)))return t;1&i&&(t[2]=n[2],o|=1&e?0:4);var u=n[3];if(u){var c=t[3];t[3]=c?xi(c,u,n[4]):u,t[4]=c?ie(t[3],r):n[4]}(u=n[5])&&(t[5]=(c=t[5])?Mi(c,u,n[6]):u,t[6]=c?ie(t[5],r):n[6]),(u=n[7])&&(t[7]=u),i&s&&(t[8]=null==t[8]?n[8]:we(t[8],n[8])),null==t[9]&&(t[9]=n[9]),t[0]=n[0],t[1]=o}(g,y),e=g[0],o=g[1],u=g[2],c=g[3],h=g[4],!(f=g[9]=g[9]===t?d?0:e.length:pe(g[9]-v,0))&&24&o&&(o&=-25),o&&1!=o)b=8==o||16==o?function(n,e,r){var i=Oi(n);return function s(){for(var o=arguments.length,u=bt(o),c=o,h=rs(s);c--;)u[c]=arguments[c];var a=o<3&&u[0]!==h&&u[o-1]!==h?[]:ie(u,h);return(o-=a.length)<r?Ni(n,e,Di,s.placeholder,t,u,a,t,t,r-o):An(this&&this!==hn&&this instanceof s?i:n,this,u)}}(e,o,f):o!=i&&33!=o||h.length?Di.apply(t,g):function(t,n,e,r){var i=1&n,s=Oi(t);return function n(){for(var o=-1,u=arguments.length,c=-1,h=r.length,a=bt(h+u),l=this&&this!==hn&&this instanceof n?s:t;++c<h;)a[c]=r[c];for(;u--;)a[c++]=arguments[++o];return An(l,i?e:this,a)}}(e,o,u,c);else var b=function(t,n,e){var r=1&n,i=Oi(t);return function n(){return(this&&this!==hn&&this instanceof n?i:t).apply(r?e:this,arguments)}}(e,o,u);return Es((y?qr:Ss)(b,g),e,o)}function Vi(n,e,r,i){return n===t||Ro(n,jt[r])&&!_t.call(i,r)?e:n}function Xi(n,e,r,i,s,o){return Jo(n)&&Jo(e)&&(o.set(e,n),Rr(n,e,t,Xi,o),o.delete(e)),n}function qi(n){return eu(n)?t:n}function Gi(n,e,r,i,s,o){var u=1&r,c=n.length,h=e.length;if(c!=h&&!(u&&h>c))return!1;var a=o.get(n),l=o.get(e);if(a&&l)return a==e&&l==n;var f=-1,d=!0,v=2&r?new Qe:t;for(o.set(n,e),o.set(e,n);++f<c;){var p=n[f],w=e[f];if(i)var y=u?i(w,p,f,e,n,o):i(p,w,f,n,e,o);if(y!==t){if(y)continue;d=!1;break}if(v){if(!On(e,(function(t,n){if(!Xn(v,n)&&(p===t||s(p,t,r,i,o)))return v.push(n)}))){d=!1;break}}else if(p!==w&&!s(p,w,r,i,o)){d=!1;break}}return o.delete(n),o.delete(e),d}function Ji(n){return Us(ks(n,t,Fs),n+"")}function Zi(t){return Ar(t,ju,cs)}function ts(t){return Ar(t,Tu,hs)}var ns=Ue?function(t){return Ue.get(t)}:oc;function es(t){for(var n=t.name+"",e=Ee[n],r=_t.call(Ee,n)?e.length:0;r--;){var i=e[r],s=i.func;if(null==s||s==t)return i.name}return n}function rs(t){return(_t.call(Pe,"placeholder")?Pe:t).placeholder}function is(){var t=Pe.iteratee||ec;return t=t===ec?_r:t,arguments.length?t(arguments[0],arguments[1]):t}function ss(t,n){var e=t.__data__;return function(t){var n=typeof t;return"string"==n||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==t:null===t}(n)?e["string"==typeof n?"string":"hash"]:e.map}function os(t){for(var n=ju(t),e=n.length;e--;){var r=n[e],i=t[r];n[e]=[r,i,ms(i)]}return n}function us(n,e){var r=function(n,e){return null==n?t:n[e]}(n,e);return Ir(r)?r:t}var cs=zn?function(t){return null==t?[]:(t=Mt(t),Cn(zn(t),(function(n){return Qt.call(t,n)})))}:dc,hs=zn?function(t){for(var n=[];t;)Tn(n,cs(t)),t=Nt(t);return n}:dc,as=kr;function ls(t,n,e){for(var r=-1,i=(n=pi(n,t)).length,s=!1;++r<i;){var o=zs(n[r]);if(!(s=null!=t&&e(t,o)))break;t=t[o]}return s||++r!=i?s:!!(i=null==t?0:t.length)&&Go(i)&&vs(o,i)&&(Fo(t)||Lo(t))}function fs(t){return"function"!=typeof t.constructor||bs(t)?{}:Re(Nt(t))}function ds(t){return Fo(t)||Lo(t)||!!(Xt&&t&&t[Xt])}function vs(t,n){var e=typeof t;return!!(n=null==n?u:n)&&("number"==e||"symbol"!=e&&vt.test(t))&&t>-1&&t%1==0&&t<n}function ps(t,n,e){if(!Jo(e))return!1;var r=typeof n;return!!("number"==r?Ko(e)&&vs(n,e.length):"string"==r&&n in e)&&Ro(e[n],t)}function ws(t,n){if(Fo(t))return!1;var e=typeof t;return!("number"!=e&&"symbol"!=e&&"boolean"!=e&&null!=t&&!ou(t))||q.test(t)||!X.test(t)||null!=n&&t in Mt(n)}function ys(t){var n=es(t),e=Pe[n];if("function"!=typeof e||!(n in Le.prototype))return!1;if(t===e)return!0;var r=ns(e);return!!r&&t===r[0]}(Ae&&as(new Ae(new ArrayBuffer(1)))!=E||ke&&as(new ke)!=g||xe&&as(xe.resolve())!=A||Me&&as(new Me)!=x||Se&&as(new Se)!=C)&&(as=function(n){var e=kr(n),r=e==m?n.constructor:t,i=r?$s(r):"";if(i)switch(i){case je:return E;case Te:return g;case Ie:return A;case _e:return x;case Oe:return C}return e});var gs=Tt?Xo:vc;function bs(t){var n=t&&t.constructor;return t===("function"==typeof n&&n.prototype||jt)}function ms(t){return t==t&&!Jo(t)}function As(n,e){return function(r){return null!=r&&r[n]===e&&(e!==t||n in Mt(r))}}function ks(n,e,r){return e=pe(e===t?n.length-1:e,0),function(){for(var t=arguments,i=-1,s=pe(t.length-e,0),o=bt(s);++i<s;)o[i]=t[e+i];i=-1;for(var u=bt(e+1);++i<e;)u[i]=t[i];return u[e]=r(o),An(n,this,u)}}function xs(t,n){return n.length<2?t:mr(t,Zr(n,0,-1))}function Ms(t,n){if(("constructor"!==n||"function"!=typeof t[n])&&"__proto__"!=n)return t[n]}var Ss=js(qr),Cs=ln||function(t,n){return hn.setTimeout(t,n)},Us=js(Gr);function Es(t,n,e){var r=n+"";return Us(t,function(t,n){var e=n.length;if(!e)return t;var r=e-1;return n[r]=(e>1?"& ":"")+n[r],n=n.join(e>2?", ":" "),t.replace(et,"{\n/* [wrapped with "+n+"] */\n")}(r,function(t,n){return xn(a,(function(e){var r="_."+e[0];n&e[1]&&!Un(t,r)&&t.push(r)})),t.sort()}(function(t){var n=t.match(rt);return n?n[1].split(it):[]}(r),e)))}function js(n){var e=0,r=0;return function(){var i=ye(),s=16-(i-r);if(r=i,s>0){if(++e>=800)return arguments[0]}else e=0;return n.apply(t,arguments)}}function Ts(n,e){var r=-1,i=n.length,s=i-1;for(e=e===t?i:e;++r<e;){var o=Kr(r,s),u=n[o];n[o]=n[r],n[r]=u}return n.length=e,n}var Is,_s,Os=(Is=_o((function(t){var n=[];return 46===t.charCodeAt(0)&&n.push(""),t.replace(G,(function(t,e,r,i){n.push(r?i.replace(ut,"$1"):e||t)})),n}),(function(t){return 500===_s.size&&_s.clear(),t})),_s=Is.cache,Is);function zs(t){if("string"==typeof t||ou(t))return t;var n=t+"";return"0"==n&&1/t==-1/0?"-0":n}function $s(t){if(null!=t){try{return It.call(t)}catch(t){}try{return t+""}catch(t){}}return""}function Ds(t){if(t instanceof Le)return t.clone();var n=new We(t.__wrapped__,t.__chain__);return n.__actions__=Si(t.__actions__),n.__index__=t.__index__,n.__values__=t.__values__,n}var Ps=Yr((function(t,n){return Qo(t)?cr(t,vr(n,1,Qo,!0)):[]})),Rs=Yr((function(n,e){var r=Hs(e);return Qo(r)&&(r=t),Qo(n)?cr(n,vr(e,1,Qo,!0),is(r,2)):[]})),Bs=Yr((function(n,e){var r=Hs(e);return Qo(r)&&(r=t),Qo(n)?cr(n,vr(e,1,Qo,!0),t,r):[]}));function Ws(t,n,e){var r=null==t?0:t.length;if(!r)return-1;var i=null==e?0:fu(e);return i<0&&(i=pe(r+i,0)),Dn(t,is(n,3),i)}function Ls(n,e,r){var i=null==n?0:n.length;if(!i)return-1;var s=i-1;return r!==t&&(s=fu(r),s=r<0?pe(i+s,0):we(s,i-1)),Dn(n,is(e,3),s,!0)}function Fs(t){return null!=t&&t.length?vr(t,1):[]}function Ns(n){return n&&n.length?n[0]:t}var Ks=Yr((function(t){var n=jn(t,di);return n.length&&n[0]===t[0]?Cr(n):[]})),Qs=Yr((function(n){var e=Hs(n),r=jn(n,di);return e===Hs(r)?e=t:r.pop(),r.length&&r[0]===n[0]?Cr(r,is(e,2)):[]})),Ys=Yr((function(n){var e=Hs(n),r=jn(n,di);return(e="function"==typeof e?e:t)&&r.pop(),r.length&&r[0]===n[0]?Cr(r,t,e):[]}));function Hs(n){var e=null==n?0:n.length;return e?n[e-1]:t}var Vs=Yr(Xs);function Xs(t,n){return t&&t.length&&n&&n.length?Fr(t,n):t}var qs=Ji((function(t,n){var e=null==t?0:t.length,r=rr(t,n);return Nr(t,jn(n,(function(t){return vs(t,e)?+t:t})).sort(ki)),r}));function Gs(t){return null==t?t:me.call(t)}var Js=Yr((function(t){return oi(vr(t,1,Qo,!0))})),Zs=Yr((function(n){var e=Hs(n);return Qo(e)&&(e=t),oi(vr(n,1,Qo,!0),is(e,2))})),to=Yr((function(n){var e=Hs(n);return e="function"==typeof e?e:t,oi(vr(n,1,Qo,!0),t,e)}));function no(t){if(!t||!t.length)return[];var n=0;return t=Cn(t,(function(t){if(Qo(t))return n=pe(t.length,n),!0})),Qn(n,(function(n){return jn(t,Ln(n))}))}function eo(n,e){if(!n||!n.length)return[];var r=no(n);return null==e?r:jn(r,(function(n){return An(e,t,n)}))}var ro=Yr((function(t,n){return Qo(t)?cr(t,n):[]})),io=Yr((function(t){return li(Cn(t,Qo))})),so=Yr((function(n){var e=Hs(n);return Qo(e)&&(e=t),li(Cn(n,Qo),is(e,2))})),oo=Yr((function(n){var e=Hs(n);return e="function"==typeof e?e:t,li(Cn(n,Qo),t,e)})),uo=Yr(no),co=Yr((function(n){var e=n.length,r=e>1?n[e-1]:t;return r="function"==typeof r?(n.pop(),r):t,eo(n,r)}));function ho(t){var n=Pe(t);return n.__chain__=!0,n}function ao(t,n){return n(t)}var lo=Ji((function(n){var e=n.length,r=e?n[0]:0,i=this.__wrapped__,s=function(t){return rr(t,n)};return!(e>1||this.__actions__.length)&&i instanceof Le&&vs(r)?((i=i.slice(r,+r+(e?1:0))).__actions__.push({func:ao,args:[s],thisArg:t}),new We(i,this.__chain__).thru((function(n){return e&&!n.length&&n.push(t),n}))):this.thru(s)})),fo=Ui((function(t,n,e){_t.call(t,e)?++t[e]:er(t,e,1)})),vo=zi(Ws),po=zi(Ls);function wo(t,n){return(Fo(t)?xn:hr)(t,is(n,3))}function yo(t,n){return(Fo(t)?Mn:ar)(t,is(n,3))}var go=Ui((function(t,n,e){_t.call(t,e)?t[e].push(n):er(t,e,[n])})),bo=Yr((function(t,n,e){var r=-1,i="function"==typeof n,s=Ko(t)?bt(t.length):[];return hr(t,(function(t){s[++r]=i?An(n,t,e):Ur(t,n,e)})),s})),mo=Ui((function(t,n,e){er(t,e,n)}));function Ao(t,n){return(Fo(t)?jn:$r)(t,is(n,3))}var ko=Ui((function(t,n,e){t[e?0:1].push(n)}),(function(){return[[],[]]})),xo=Yr((function(t,n){if(null==t)return[];var e=n.length;return e>1&&ps(t,n[0],n[1])?n=[]:e>2&&ps(n[0],n[1],n[2])&&(n=[n[0]]),Wr(t,vr(n,1),[])})),Mo=an||function(){return hn.Date.now()};function So(n,e,r){return e=r?t:e,Hi(n,s,t,t,t,t,e=n&&null==e?n.length:e)}function Co(e,r){var i;if("function"!=typeof r)throw new Ut(n);return e=fu(e),function(){return--e>0&&(i=r.apply(this,arguments)),e<=1&&(r=t),i}}var Uo=Yr((function(t,n,e){var r=1;if(e.length){var s=ie(e,rs(Uo));r|=i}return Hi(t,r,n,e,s)})),Eo=Yr((function(t,n,e){var r=3;if(e.length){var s=ie(e,rs(Eo));r|=i}return Hi(n,r,t,e,s)}));function jo(e,r,i){var s,o,u,c,h,a,l=0,f=!1,d=!1,v=!0;if("function"!=typeof e)throw new Ut(n);function p(n){var r=s,i=o;return s=o=t,l=n,c=e.apply(i,r)}function w(n){var e=n-a;return a===t||e>=r||e<0||d&&n-l>=u}function y(){var t=Mo();if(w(t))return g(t);h=Cs(y,function(t){var n=r-(t-a);return d?we(n,u-(t-l)):n}(t))}function g(n){return h=t,v&&s?p(n):(s=o=t,c)}function b(){var n=Mo(),e=w(n);if(s=arguments,o=this,a=n,e){if(h===t)return function(t){return l=t,h=Cs(y,r),f?p(t):c}(a);if(d)return gi(h),h=Cs(y,r),p(a)}return h===t&&(h=Cs(y,r)),c}return r=vu(r)||0,Jo(i)&&(f=!!i.leading,u=(d="maxWait"in i)?pe(vu(i.maxWait)||0,r):u,v="trailing"in i?!!i.trailing:v),b.cancel=function(){h!==t&&gi(h),l=0,s=a=o=h=t},b.flush=function(){return h===t?c:g(Mo())},b}var To=Yr((function(t,n){return ur(t,1,n)})),Io=Yr((function(t,n,e){return ur(t,vu(n)||0,e)}));function _o(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new Ut(n);var r=function(){var n=arguments,i=e?e.apply(this,n):n[0],s=r.cache;if(s.has(i))return s.get(i);var o=t.apply(this,n);return r.cache=s.set(i,o)||s,o};return r.cache=new(_o.Cache||Ke),r}function Oo(t){if("function"!=typeof t)throw new Ut(n);return function(){var n=arguments;switch(n.length){case 0:return!t.call(this);case 1:return!t.call(this,n[0]);case 2:return!t.call(this,n[0],n[1]);case 3:return!t.call(this,n[0],n[1],n[2])}return!t.apply(this,n)}}_o.Cache=Ke;var zo=wi((function(t,n){var e=(n=1==n.length&&Fo(n[0])?jn(n[0],Hn(is())):jn(vr(n,1),Hn(is()))).length;return Yr((function(r){for(var i=-1,s=we(r.length,e);++i<s;)r[i]=n[i].call(this,r[i]);return An(t,this,r)}))})),$o=Yr((function(n,e){var r=ie(e,rs($o));return Hi(n,i,t,e,r)})),Do=Yr((function(n,e){var r=ie(e,rs(Do));return Hi(n,64,t,e,r)})),Po=Ji((function(n,e){return Hi(n,256,t,t,t,e)}));function Ro(t,n){return t===n||t!=t&&n!=n}var Bo=Fi(xr),Wo=Fi((function(t,n){return t>=n})),Lo=Er(function(){return arguments}())?Er:function(t){return Zo(t)&&_t.call(t,"callee")&&!Qt.call(t,"callee")},Fo=bt.isArray,No=pn?Hn(pn):function(t){return Zo(t)&&kr(t)==U};function Ko(t){return null!=t&&Go(t.length)&&!Xo(t)}function Qo(t){return Zo(t)&&Ko(t)}var Yo=Fn||vc,Ho=wn?Hn(wn):function(t){return Zo(t)&&kr(t)==v};function Vo(t){if(!Zo(t))return!1;var n=kr(t);return n==p||"[object DOMException]"==n||"string"==typeof t.message&&"string"==typeof t.name&&!eu(t)}function Xo(t){if(!Jo(t))return!1;var n=kr(t);return n==w||n==y||"[object AsyncFunction]"==n||"[object Proxy]"==n}function qo(t){return"number"==typeof t&&t==fu(t)}function Go(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=u}function Jo(t){var n=typeof t;return null!=t&&("object"==n||"function"==n)}function Zo(t){return null!=t&&"object"==typeof t}var tu=yn?Hn(yn):function(t){return Zo(t)&&as(t)==g};function nu(t){return"number"==typeof t||Zo(t)&&kr(t)==b}function eu(t){if(!Zo(t)||kr(t)!=m)return!1;var n=Nt(t);if(null===n)return!0;var e=_t.call(n,"constructor")&&n.constructor;return"function"==typeof e&&e instanceof e&&It.call(e)==Dt}var ru=gn?Hn(gn):function(t){return Zo(t)&&kr(t)==k},iu=bn?Hn(bn):function(t){return Zo(t)&&as(t)==x};function su(t){return"string"==typeof t||!Fo(t)&&Zo(t)&&kr(t)==M}function ou(t){return"symbol"==typeof t||Zo(t)&&kr(t)==S}var uu=mn?Hn(mn):function(t){return Zo(t)&&Go(t.length)&&!!nn[kr(t)]},cu=Fi(zr),hu=Fi((function(t,n){return t<=n}));function au(t){if(!t)return[];if(Ko(t))return su(t)?ce(t):Si(t);if(Gt&&t[Gt])return function(t){for(var n,e=[];!(n=t.next()).done;)e.push(n.value);return e}(t[Gt]());var n=as(t);return(n==g?ee:n==x?se:Ru)(t)}function lu(t){return t?(t=vu(t))===o||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0}function fu(t){var n=lu(t),e=n%1;return n==n?e?n-e:n:0}function du(t){return t?ir(fu(t),0,h):0}function vu(t){if("number"==typeof t)return t;if(ou(t))return c;if(Jo(t)){var n="function"==typeof t.valueOf?t.valueOf():t;t=Jo(n)?n+"":n}if("string"!=typeof t)return 0===t?t:+t;t=Yn(t);var e=lt.test(t);return e||dt.test(t)?on(t.slice(2),e?2:8):at.test(t)?c:+t}function pu(t){return Ci(t,Tu(t))}function wu(t){return null==t?"":si(t)}var yu=Ei((function(t,n){if(bs(n)||Ko(n))Ci(n,ju(n),t);else for(var e in n)_t.call(n,e)&&Je(t,e,n[e])})),gu=Ei((function(t,n){Ci(n,Tu(n),t)})),bu=Ei((function(t,n,e,r){Ci(n,Tu(n),t,r)})),mu=Ei((function(t,n,e,r){Ci(n,ju(n),t,r)})),Au=Ji(rr),ku=Yr((function(n,e){n=Mt(n);var r=-1,i=e.length,s=i>2?e[2]:t;for(s&&ps(e[0],e[1],s)&&(i=1);++r<i;)for(var o=e[r],u=Tu(o),c=-1,h=u.length;++c<h;){var a=u[c],l=n[a];(l===t||Ro(l,jt[a])&&!_t.call(n,a))&&(n[a]=o[a])}return n})),xu=Yr((function(n){return n.push(t,Xi),An(_u,t,n)}));function Mu(n,e,r){var i=null==n?t:mr(n,e);return i===t?r:i}function Su(t,n){return null!=t&&ls(t,n,Sr)}var Cu=Pi((function(t,n,e){null!=n&&"function"!=typeof n.toString&&(n=$t.call(n)),t[n]=e}),Ju(nc)),Uu=Pi((function(t,n,e){null!=n&&"function"!=typeof n.toString&&(n=$t.call(n)),_t.call(t,n)?t[n].push(e):t[n]=[e]}),is),Eu=Yr(Ur);function ju(t){return Ko(t)?He(t):Or(t)}function Tu(t){return Ko(t)?He(t,!0):function(t){if(!Jo(t))return function(t){var n=[];if(null!=t)for(var e in Mt(t))n.push(e);return n}(t);var n=bs(t),e=[];for(var r in t)("constructor"!=r||!n&&_t.call(t,r))&&e.push(r);return e}(t)}var Iu=Ei((function(t,n,e){Rr(t,n,e)})),_u=Ei((function(t,n,e,r){Rr(t,n,e,r)})),Ou=Ji((function(t,n){var e={};if(null==t)return e;var r=!1;n=jn(n,(function(n){return n=pi(n,t),r||(r=n.length>1),n})),Ci(t,ts(t),e),r&&(e=sr(e,7,qi));for(var i=n.length;i--;)ui(e,n[i]);return e})),zu=Ji((function(t,n){return null==t?{}:function(t,n){return Lr(t,n,(function(n,e){return Su(t,e)}))}(t,n)}));function $u(t,n){if(null==t)return{};var e=jn(ts(t),(function(t){return[t]}));return n=is(n),Lr(t,e,(function(t,e){return n(t,e[0])}))}var Du=Yi(ju),Pu=Yi(Tu);function Ru(t){return null==t?[]:Vn(t,ju(t))}var Bu=_i((function(t,n,e){return n=n.toLowerCase(),t+(e?Wu(n):n)}));function Wu(t){return Vu(wu(t).toLowerCase())}function Lu(t){return(t=wu(t))&&t.replace(pt,Jn).replace(Vt,"")}var Fu=_i((function(t,n,e){return t+(e?"-":"")+n.toLowerCase()})),Nu=_i((function(t,n,e){return t+(e?" ":"")+n.toLowerCase()})),Ku=Ii("toLowerCase"),Qu=_i((function(t,n,e){return t+(e?"_":"")+n.toLowerCase()})),Yu=_i((function(t,n,e){return t+(e?" ":"")+Vu(n)})),Hu=_i((function(t,n,e){return t+(e?" ":"")+n.toUpperCase()})),Vu=Ii("toUpperCase");function Xu(n,e,r){return n=wu(n),(e=r?t:e)===t?function(t){return Jt.test(t)}(n)?function(t){return t.match(qt)||[]}(n):function(t){return t.match(st)||[]}(n):n.match(e)||[]}var qu=Yr((function(n,e){try{return An(n,t,e)}catch(t){return Vo(t)?t:new At(t)}})),Gu=Ji((function(t,n){return xn(n,(function(n){n=zs(n),er(t,n,Uo(t[n],t))})),t}));function Ju(t){return function(){return t}}var Zu=$i(),tc=$i(!0);function nc(t){return t}function ec(t){return _r("function"==typeof t?t:sr(t,1))}var rc=Yr((function(t,n){return function(e){return Ur(e,t,n)}})),ic=Yr((function(t,n){return function(e){return Ur(t,e,n)}}));function sc(t,n,e){var r=ju(n),i=br(n,r);null!=e||Jo(n)&&(i.length||!r.length)||(e=n,n=t,t=this,i=br(n,ju(n)));var s=!(Jo(e)&&"chain"in e&&!e.chain),o=Xo(t);return xn(i,(function(e){var r=n[e];t[e]=r,o&&(t.prototype[e]=function(){var n=this.__chain__;if(s||n){var e=t(this.__wrapped__);return(e.__actions__=Si(this.__actions__)).push({func:r,args:arguments,thisArg:t}),e.__chain__=n,e}return r.apply(t,Tn([this.value()],arguments))})})),t}function oc(){}var uc=Bi(jn),cc=Bi(Sn),hc=Bi(On);function ac(t){return ws(t)?Ln(zs(t)):function(t){return function(n){return mr(n,t)}}(t)}var lc=Li(),fc=Li(!0);function dc(){return[]}function vc(){return!1}var pc,wc=Ri((function(t,n){return t+n}),0),yc=Ki("ceil"),gc=Ri((function(t,n){return t/n}),1),bc=Ki("floor"),mc=Ri((function(t,n){return t*n}),1),Ac=Ki("round"),kc=Ri((function(t,n){return t-n}),0);return Pe.after=function(t,e){if("function"!=typeof e)throw new Ut(n);return t=fu(t),function(){if(--t<1)return e.apply(this,arguments)}},Pe.ary=So,Pe.assign=yu,Pe.assignIn=gu,Pe.assignInWith=bu,Pe.assignWith=mu,Pe.at=Au,Pe.before=Co,Pe.bind=Uo,Pe.bindAll=Gu,Pe.bindKey=Eo,Pe.castArray=function(){if(!arguments.length)return[];var t=arguments[0];return Fo(t)?t:[t]},Pe.chain=ho,Pe.chunk=function(n,e,r){e=(r?ps(n,e,r):e===t)?1:pe(fu(e),0);var i=null==n?0:n.length;if(!i||e<1)return[];for(var s=0,o=0,u=bt(dn(i/e));s<i;)u[o++]=Zr(n,s,s+=e);return u},Pe.compact=function(t){for(var n=-1,e=null==t?0:t.length,r=0,i=[];++n<e;){var s=t[n];s&&(i[r++]=s)}return i},Pe.concat=function(){var t=arguments.length;if(!t)return[];for(var n=bt(t-1),e=arguments[0],r=t;r--;)n[r-1]=arguments[r];return Tn(Fo(e)?Si(e):[e],vr(n,1))},Pe.cond=function(t){var e=null==t?0:t.length,r=is();return t=e?jn(t,(function(t){if("function"!=typeof t[1])throw new Ut(n);return[r(t[0]),t[1]]})):[],Yr((function(n){for(var r=-1;++r<e;){var i=t[r];if(An(i[0],this,n))return An(i[1],this,n)}}))},Pe.conforms=function(t){return function(t){var n=ju(t);return function(e){return or(e,t,n)}}(sr(t,1))},Pe.constant=Ju,Pe.countBy=fo,Pe.create=function(t,n){var e=Re(t);return null==n?e:nr(e,n)},Pe.curry=function n(e,r,i){var s=Hi(e,8,t,t,t,t,t,r=i?t:r);return s.placeholder=n.placeholder,s},Pe.curryRight=function n(e,r,i){var s=Hi(e,16,t,t,t,t,t,r=i?t:r);return s.placeholder=n.placeholder,s},Pe.debounce=jo,Pe.defaults=ku,Pe.defaultsDeep=xu,Pe.defer=To,Pe.delay=Io,Pe.difference=Ps,Pe.differenceBy=Rs,Pe.differenceWith=Bs,Pe.drop=function(n,e,r){var i=null==n?0:n.length;return i?Zr(n,(e=r||e===t?1:fu(e))<0?0:e,i):[]},Pe.dropRight=function(n,e,r){var i=null==n?0:n.length;return i?Zr(n,0,(e=i-(e=r||e===t?1:fu(e)))<0?0:e):[]},Pe.dropRightWhile=function(t,n){return t&&t.length?hi(t,is(n,3),!0,!0):[]},Pe.dropWhile=function(t,n){return t&&t.length?hi(t,is(n,3),!0):[]},Pe.fill=function(n,e,r,i){var s=null==n?0:n.length;return s?(r&&"number"!=typeof r&&ps(n,e,r)&&(r=0,i=s),function(n,e,r,i){var s=n.length;for((r=fu(r))<0&&(r=-r>s?0:s+r),(i=i===t||i>s?s:fu(i))<0&&(i+=s),i=r>i?0:du(i);r<i;)n[r++]=e;return n}(n,e,r,i)):[]},Pe.filter=function(t,n){return(Fo(t)?Cn:dr)(t,is(n,3))},Pe.flatMap=function(t,n){return vr(Ao(t,n),1)},Pe.flatMapDeep=function(t,n){return vr(Ao(t,n),o)},Pe.flatMapDepth=function(n,e,r){return r=r===t?1:fu(r),vr(Ao(n,e),r)},Pe.flatten=Fs,Pe.flattenDeep=function(t){return null!=t&&t.length?vr(t,o):[]},Pe.flattenDepth=function(n,e){return null!=n&&n.length?vr(n,e=e===t?1:fu(e)):[]},Pe.flip=function(t){return Hi(t,512)},Pe.flow=Zu,Pe.flowRight=tc,Pe.fromPairs=function(t){for(var n=-1,e=null==t?0:t.length,r={};++n<e;){var i=t[n];r[i[0]]=i[1]}return r},Pe.functions=function(t){return null==t?[]:br(t,ju(t))},Pe.functionsIn=function(t){return null==t?[]:br(t,Tu(t))},Pe.groupBy=go,Pe.initial=function(t){return null!=t&&t.length?Zr(t,0,-1):[]},Pe.intersection=Ks,Pe.intersectionBy=Qs,Pe.intersectionWith=Ys,Pe.invert=Cu,Pe.invertBy=Uu,Pe.invokeMap=bo,Pe.iteratee=ec,Pe.keyBy=mo,Pe.keys=ju,Pe.keysIn=Tu,Pe.map=Ao,Pe.mapKeys=function(t,n){var e={};return n=is(n,3),yr(t,(function(t,r,i){er(e,n(t,r,i),t)})),e},Pe.mapValues=function(t,n){var e={};return n=is(n,3),yr(t,(function(t,r,i){er(e,r,n(t,r,i))})),e},Pe.matches=function(t){return Dr(sr(t,1))},Pe.matchesProperty=function(t,n){return Pr(t,sr(n,1))},Pe.memoize=_o,Pe.merge=Iu,Pe.mergeWith=_u,Pe.method=rc,Pe.methodOf=ic,Pe.mixin=sc,Pe.negate=Oo,Pe.nthArg=function(t){return t=fu(t),Yr((function(n){return Br(n,t)}))},Pe.omit=Ou,Pe.omitBy=function(t,n){return $u(t,Oo(is(n)))},Pe.once=function(t){return Co(2,t)},Pe.orderBy=function(n,e,r,i){return null==n?[]:(Fo(e)||(e=null==e?[]:[e]),Fo(r=i?t:r)||(r=null==r?[]:[r]),Wr(n,e,r))},Pe.over=uc,Pe.overArgs=zo,Pe.overEvery=cc,Pe.overSome=hc,Pe.partial=$o,Pe.partialRight=Do,Pe.partition=ko,Pe.pick=zu,Pe.pickBy=$u,Pe.property=ac,Pe.propertyOf=function(n){return function(e){return null==n?t:mr(n,e)}},Pe.pull=Vs,Pe.pullAll=Xs,Pe.pullAllBy=function(t,n,e){return t&&t.length&&n&&n.length?Fr(t,n,is(e,2)):t},Pe.pullAllWith=function(n,e,r){return n&&n.length&&e&&e.length?Fr(n,e,t,r):n},Pe.pullAt=qs,Pe.range=lc,Pe.rangeRight=fc,Pe.rearg=Po,Pe.reject=function(t,n){return(Fo(t)?Cn:dr)(t,Oo(is(n,3)))},Pe.remove=function(t,n){var e=[];if(!t||!t.length)return e;var r=-1,i=[],s=t.length;for(n=is(n,3);++r<s;){var o=t[r];n(o,r,t)&&(e.push(o),i.push(r))}return Nr(t,i),e},Pe.rest=function(e,r){if("function"!=typeof e)throw new Ut(n);return Yr(e,r=r===t?r:fu(r))},Pe.reverse=Gs,Pe.sampleSize=function(n,e,r){return e=(r?ps(n,e,r):e===t)?1:fu(e),(Fo(n)?Xe:Vr)(n,e)},Pe.set=function(t,n,e){return null==t?t:Xr(t,n,e)},Pe.setWith=function(n,e,r,i){return i="function"==typeof i?i:t,null==n?n:Xr(n,e,r,i)},Pe.shuffle=function(t){return(Fo(t)?qe:Jr)(t)},Pe.slice=function(n,e,r){var i=null==n?0:n.length;return i?(r&&"number"!=typeof r&&ps(n,e,r)?(e=0,r=i):(e=null==e?0:fu(e),r=r===t?i:fu(r)),Zr(n,e,r)):[]},Pe.sortBy=xo,Pe.sortedUniq=function(t){return t&&t.length?ri(t):[]},Pe.sortedUniqBy=function(t,n){return t&&t.length?ri(t,is(n,2)):[]},Pe.split=function(n,e,r){return r&&"number"!=typeof r&&ps(n,e,r)&&(e=r=t),(r=r===t?h:r>>>0)?(n=wu(n))&&("string"==typeof e||null!=e&&!ru(e))&&!(e=si(e))&&ne(n)?yi(ce(n),0,r):n.split(e,r):[]},Pe.spread=function(t,e){if("function"!=typeof t)throw new Ut(n);return e=null==e?0:pe(fu(e),0),Yr((function(n){var r=n[e],i=yi(n,0,e);return r&&Tn(i,r),An(t,this,i)}))},Pe.tail=function(t){var n=null==t?0:t.length;return n?Zr(t,1,n):[]},Pe.take=function(n,e,r){return n&&n.length?Zr(n,0,(e=r||e===t?1:fu(e))<0?0:e):[]},Pe.takeRight=function(n,e,r){var i=null==n?0:n.length;return i?Zr(n,(e=i-(e=r||e===t?1:fu(e)))<0?0:e,i):[]},Pe.takeRightWhile=function(t,n){return t&&t.length?hi(t,is(n,3),!1,!0):[]},Pe.takeWhile=function(t,n){return t&&t.length?hi(t,is(n,3)):[]},Pe.tap=function(t,n){return n(t),t},Pe.throttle=function(t,e,r){var i=!0,s=!0;if("function"!=typeof t)throw new Ut(n);return Jo(r)&&(i="leading"in r?!!r.leading:i,s="trailing"in r?!!r.trailing:s),jo(t,e,{leading:i,maxWait:e,trailing:s})},Pe.thru=ao,Pe.toArray=au,Pe.toPairs=Du,Pe.toPairsIn=Pu,Pe.toPath=function(t){return Fo(t)?jn(t,zs):ou(t)?[t]:Si(Os(wu(t)))},Pe.toPlainObject=pu,Pe.transform=function(t,n,e){var r=Fo(t),i=r||Yo(t)||uu(t);if(n=is(n,4),null==e){var s=t&&t.constructor;e=i?r?new s:[]:Jo(t)&&Xo(s)?Re(Nt(t)):{}}return(i?xn:yr)(t,(function(t,r,i){return n(e,t,r,i)})),e},Pe.unary=function(t){return So(t,1)},Pe.union=Js,Pe.unionBy=Zs,Pe.unionWith=to,Pe.uniq=function(t){return t&&t.length?oi(t):[]},Pe.uniqBy=function(t,n){return t&&t.length?oi(t,is(n,2)):[]},Pe.uniqWith=function(n,e){return e="function"==typeof e?e:t,n&&n.length?oi(n,t,e):[]},Pe.unset=function(t,n){return null==t||ui(t,n)},Pe.unzip=no,Pe.unzipWith=eo,Pe.update=function(t,n,e){return null==t?t:ci(t,n,vi(e))},Pe.updateWith=function(n,e,r,i){return i="function"==typeof i?i:t,null==n?n:ci(n,e,vi(r),i)},Pe.values=Ru,Pe.valuesIn=function(t){return null==t?[]:Vn(t,Tu(t))},Pe.without=ro,Pe.words=Xu,Pe.wrap=function(t,n){return $o(vi(n),t)},Pe.xor=io,Pe.xorBy=so,Pe.xorWith=oo,Pe.zip=uo,Pe.zipObject=function(t,n){return fi(t||[],n||[],Je)},Pe.zipObjectDeep=function(t,n){return fi(t||[],n||[],Xr)},Pe.zipWith=co,Pe.entries=Du,Pe.entriesIn=Pu,Pe.extend=gu,Pe.extendWith=bu,sc(Pe,Pe),Pe.add=wc,Pe.attempt=qu,Pe.camelCase=Bu,Pe.capitalize=Wu,Pe.ceil=yc,Pe.clamp=function(n,e,r){return r===t&&(r=e,e=t),r!==t&&(r=(r=vu(r))==r?r:0),e!==t&&(e=(e=vu(e))==e?e:0),ir(vu(n),e,r)},Pe.clone=function(t){return sr(t,4)},Pe.cloneDeep=function(t){return sr(t,5)},Pe.cloneDeepWith=function(n,e){return sr(n,5,e="function"==typeof e?e:t)},Pe.cloneWith=function(n,e){return sr(n,4,e="function"==typeof e?e:t)},Pe.conformsTo=function(t,n){return null==n||or(t,n,ju(n))},Pe.deburr=Lu,Pe.defaultTo=function(t,n){return null==t||t!=t?n:t},Pe.divide=gc,Pe.endsWith=function(n,e,r){n=wu(n),e=si(e);var i=n.length,s=r=r===t?i:ir(fu(r),0,i);return(r-=e.length)>=0&&n.slice(r,s)==e},Pe.eq=Ro,Pe.escape=function(t){return(t=wu(t))&&Q.test(t)?t.replace(N,Zn):t},Pe.escapeRegExp=function(t){return(t=wu(t))&&Z.test(t)?t.replace(J,"\\$&"):t},Pe.every=function(n,e,r){var i=Fo(n)?Sn:lr;return r&&ps(n,e,r)&&(e=t),i(n,is(e,3))},Pe.find=vo,Pe.findIndex=Ws,Pe.findKey=function(t,n){return $n(t,is(n,3),yr)},Pe.findLast=po,Pe.findLastIndex=Ls,Pe.findLastKey=function(t,n){return $n(t,is(n,3),gr)},Pe.floor=bc,Pe.forEach=wo,Pe.forEachRight=yo,Pe.forIn=function(t,n){return null==t?t:pr(t,is(n,3),Tu)},Pe.forInRight=function(t,n){return null==t?t:wr(t,is(n,3),Tu)},Pe.forOwn=function(t,n){return t&&yr(t,is(n,3))},Pe.forOwnRight=function(t,n){return t&&gr(t,is(n,3))},Pe.get=Mu,Pe.gt=Bo,Pe.gte=Wo,Pe.has=function(t,n){return null!=t&&ls(t,n,Mr)},Pe.hasIn=Su,Pe.head=Ns,Pe.identity=nc,Pe.includes=function(t,n,e,r){t=Ko(t)?t:Ru(t),e=e&&!r?fu(e):0;var i=t.length;return e<0&&(e=pe(i+e,0)),su(t)?e<=i&&t.indexOf(n,e)>-1:!!i&&Pn(t,n,e)>-1},Pe.indexOf=function(t,n,e){var r=null==t?0:t.length;if(!r)return-1;var i=null==e?0:fu(e);return i<0&&(i=pe(r+i,0)),Pn(t,n,i)},Pe.inRange=function(n,e,r){return e=lu(e),r===t?(r=e,e=0):r=lu(r),function(t,n,e){return t>=we(n,e)&&t<pe(n,e)}(n=vu(n),e,r)},Pe.invoke=Eu,Pe.isArguments=Lo,Pe.isArray=Fo,Pe.isArrayBuffer=No,Pe.isArrayLike=Ko,Pe.isArrayLikeObject=Qo,Pe.isBoolean=function(t){return!0===t||!1===t||Zo(t)&&kr(t)==d},Pe.isBuffer=Yo,Pe.isDate=Ho,Pe.isElement=function(t){return Zo(t)&&1===t.nodeType&&!eu(t)},Pe.isEmpty=function(t){if(null==t)return!0;if(Ko(t)&&(Fo(t)||"string"==typeof t||"function"==typeof t.splice||Yo(t)||uu(t)||Lo(t)))return!t.length;var n=as(t);if(n==g||n==x)return!t.size;if(bs(t))return!Or(t).length;for(var e in t)if(_t.call(t,e))return!1;return!0},Pe.isEqual=function(t,n){return jr(t,n)},Pe.isEqualWith=function(n,e,r){var i=(r="function"==typeof r?r:t)?r(n,e):t;return i===t?jr(n,e,t,r):!!i},Pe.isError=Vo,Pe.isFinite=function(t){return"number"==typeof t&&fe(t)},Pe.isFunction=Xo,Pe.isInteger=qo,Pe.isLength=Go,Pe.isMap=tu,Pe.isMatch=function(t,n){return t===n||Tr(t,n,os(n))},Pe.isMatchWith=function(n,e,r){return r="function"==typeof r?r:t,Tr(n,e,os(e),r)},Pe.isNaN=function(t){return nu(t)&&t!=+t},Pe.isNative=function(t){if(gs(t))throw new At("Unsupported core-js use. Try https://npms.io/search?q=ponyfill.");return Ir(t)},Pe.isNil=function(t){return null==t},Pe.isNull=function(t){return null===t},Pe.isNumber=nu,Pe.isObject=Jo,Pe.isObjectLike=Zo,Pe.isPlainObject=eu,Pe.isRegExp=ru,Pe.isSafeInteger=function(t){return qo(t)&&t>=-9007199254740991&&t<=u},Pe.isSet=iu,Pe.isString=su,Pe.isSymbol=ou,Pe.isTypedArray=uu,Pe.isUndefined=function(n){return n===t},Pe.isWeakMap=function(t){return Zo(t)&&as(t)==C},Pe.isWeakSet=function(t){return Zo(t)&&"[object WeakSet]"==kr(t)},Pe.join=function(t,n){return null==t?"":de.call(t,n)},Pe.kebabCase=Fu,Pe.last=Hs,Pe.lastIndexOf=function(n,e,r){var i=null==n?0:n.length;if(!i)return-1;var s=i;return r!==t&&(s=(s=fu(r))<0?pe(i+s,0):we(s,i-1)),e==e?function(t,n,e){for(var r=e+1;r--;)if(t[r]===n)return r;return r}(n,e,s):Dn(n,Bn,s,!0)},Pe.lowerCase=Nu,Pe.lowerFirst=Ku,Pe.lt=cu,Pe.lte=hu,Pe.max=function(n){return n&&n.length?fr(n,nc,xr):t},Pe.maxBy=function(n,e){return n&&n.length?fr(n,is(e,2),xr):t},Pe.mean=function(t){return Wn(t,nc)},Pe.meanBy=function(t,n){return Wn(t,is(n,2))},Pe.min=function(n){return n&&n.length?fr(n,nc,zr):t},Pe.minBy=function(n,e){return n&&n.length?fr(n,is(e,2),zr):t},Pe.stubArray=dc,Pe.stubFalse=vc,Pe.stubObject=function(){return{}},Pe.stubString=function(){return""},Pe.stubTrue=function(){return!0},Pe.multiply=mc,Pe.nth=function(n,e){return n&&n.length?Br(n,fu(e)):t},Pe.noConflict=function(){return hn._===this&&(hn._=Pt),this},Pe.noop=oc,Pe.now=Mo,Pe.pad=function(t,n,e){t=wu(t);var r=(n=fu(n))?ue(t):0;if(!n||r>=n)return t;var i=(n-r)/2;return Wi(vn(i),e)+t+Wi(dn(i),e)},Pe.padEnd=function(t,n,e){t=wu(t);var r=(n=fu(n))?ue(t):0;return n&&r<n?t+Wi(n-r,e):t},Pe.padStart=function(t,n,e){t=wu(t);var r=(n=fu(n))?ue(t):0;return n&&r<n?Wi(n-r,e)+t:t},Pe.parseInt=function(t,n,e){return e||null==n?n=0:n&&(n=+n),ge(wu(t).replace(tt,""),n||0)},Pe.random=function(n,e,r){if(r&&"boolean"!=typeof r&&ps(n,e,r)&&(e=r=t),r===t&&("boolean"==typeof e?(r=e,e=t):"boolean"==typeof n&&(r=n,n=t)),n===t&&e===t?(n=0,e=1):(n=lu(n),e===t?(e=n,n=0):e=lu(e)),n>e){var i=n;n=e,e=i}if(r||n%1||e%1){var s=be();return we(n+s*(e-n+sn("1e-"+((s+"").length-1))),e)}return Kr(n,e)},Pe.reduce=function(t,n,e){var r=Fo(t)?In:Nn,i=arguments.length<3;return r(t,is(n,4),e,i,hr)},Pe.reduceRight=function(t,n,e){var r=Fo(t)?_n:Nn,i=arguments.length<3;return r(t,is(n,4),e,i,ar)},Pe.repeat=function(n,e,r){return e=(r?ps(n,e,r):e===t)?1:fu(e),Qr(wu(n),e)},Pe.replace=function(){var t=arguments,n=wu(t[0]);return t.length<3?n:n.replace(t[1],t[2])},Pe.result=function(n,e,r){var i=-1,s=(e=pi(e,n)).length;for(s||(s=1,n=t);++i<s;){var o=null==n?t:n[zs(e[i])];o===t&&(i=s,o=r),n=Xo(o)?o.call(n):o}return n},Pe.round=Ac,Pe.runInContext=z,Pe.sample=function(t){return(Fo(t)?Ve:Hr)(t)},Pe.size=function(t){if(null==t)return 0;if(Ko(t))return su(t)?ue(t):t.length;var n=as(t);return n==g||n==x?t.size:Or(t).length},Pe.snakeCase=Qu,Pe.some=function(n,e,r){var i=Fo(n)?On:ti;return r&&ps(n,e,r)&&(e=t),i(n,is(e,3))},Pe.sortedIndex=function(t,n){return ni(t,n)},Pe.sortedIndexBy=function(t,n,e){return ei(t,n,is(e,2))},Pe.sortedIndexOf=function(t,n){var e=null==t?0:t.length;if(e){var r=ni(t,n);if(r<e&&Ro(t[r],n))return r}return-1},Pe.sortedLastIndex=function(t,n){return ni(t,n,!0)},Pe.sortedLastIndexBy=function(t,n,e){return ei(t,n,is(e,2),!0)},Pe.sortedLastIndexOf=function(t,n){if(null!=t&&t.length){var e=ni(t,n,!0)-1;if(Ro(t[e],n))return e}return-1},Pe.startCase=Yu,Pe.startsWith=function(t,n,e){return t=wu(t),e=null==e?0:ir(fu(e),0,t.length),n=si(n),t.slice(e,e+n.length)==n},Pe.subtract=kc,Pe.sum=function(t){return t&&t.length?Kn(t,nc):0},Pe.sumBy=function(t,n){return t&&t.length?Kn(t,is(n,2)):0},Pe.template=function(n,e,r){var i=Pe.templateSettings;r&&ps(n,e,r)&&(e=t),n=wu(n),e=bu({},e,i,Vi);var s,o,u=bu({},e.imports,i.imports,Vi),c=ju(u),h=Vn(u,c),a=0,l=e.interpolate||wt,f="__p += '",d=St((e.escape||wt).source+"|"+l.source+"|"+(l===V?ct:wt).source+"|"+(e.evaluate||wt).source+"|$","g"),v="//# sourceURL="+(_t.call(e,"sourceURL")?(e.sourceURL+"").replace(/\s/g," "):"lodash.templateSources["+ ++tn+"]")+"\n";n.replace(d,(function(t,e,r,i,u,c){return r||(r=i),f+=n.slice(a,c).replace(yt,te),e&&(s=!0,f+="' +\n__e("+e+") +\n'"),u&&(o=!0,f+="';\n"+u+";\n__p += '"),r&&(f+="' +\n((__t = ("+r+")) == null ? '' : __t) +\n'"),a=c+t.length,t})),f+="';\n";var p=_t.call(e,"variable")&&e.variable;if(p){if(ot.test(p))throw new At("Invalid `variable` option passed into `_.template`")}else f="with (obj) {\n"+f+"\n}\n";f=(o?f.replace(B,""):f).replace(W,"$1").replace(L,"$1;"),f="function("+(p||"obj")+") {\n"+(p?"":"obj || (obj = {});\n")+"var __t, __p = ''"+(s?", __e = _.escape":"")+(o?", __j = Array.prototype.join;\nfunction print() { __p += __j.call(arguments, '') }\n":";\n")+f+"return __p\n}";var w=qu((function(){return kt(c,v+"return "+f).apply(t,h)}));if(w.source=f,Vo(w))throw w;return w},Pe.times=function(t,n){if((t=fu(t))<1||t>u)return[];var e=h,r=we(t,h);n=is(n),t-=h;for(var i=Qn(r,n);++e<t;)n(e);return i},Pe.toFinite=lu,Pe.toInteger=fu,Pe.toLength=du,Pe.toLower=function(t){return wu(t).toLowerCase()},Pe.toNumber=vu,Pe.toSafeInteger=function(t){return t?ir(fu(t),-9007199254740991,u):0===t?t:0},Pe.toString=wu,Pe.toUpper=function(t){return wu(t).toUpperCase()},Pe.trim=function(n,e,r){if((n=wu(n))&&(r||e===t))return Yn(n);if(!n||!(e=si(e)))return n;var i=ce(n),s=ce(e);return yi(i,qn(i,s),Gn(i,s)+1).join("")},Pe.trimEnd=function(n,e,r){if((n=wu(n))&&(r||e===t))return n.slice(0,he(n)+1);if(!n||!(e=si(e)))return n;var i=ce(n);return yi(i,0,Gn(i,ce(e))+1).join("")},Pe.trimStart=function(n,e,r){if((n=wu(n))&&(r||e===t))return n.replace(tt,"");if(!n||!(e=si(e)))return n;var i=ce(n);return yi(i,qn(i,ce(e))).join("")},Pe.truncate=function(n,e){var r=30,i="...";if(Jo(e)){var s="separator"in e?e.separator:s;r="length"in e?fu(e.length):r,i="omission"in e?si(e.omission):i}var o=(n=wu(n)).length;if(ne(n)){var u=ce(n);o=u.length}if(r>=o)return n;var c=r-ue(i);if(c<1)return i;var h=u?yi(u,0,c).join(""):n.slice(0,c);if(s===t)return h+i;if(u&&(c+=h.length-c),ru(s)){if(n.slice(c).search(s)){var a,l=h;for(s.global||(s=St(s.source,wu(ht.exec(s))+"g")),s.lastIndex=0;a=s.exec(l);)var f=a.index;h=h.slice(0,f===t?c:f)}}else if(n.indexOf(si(s),c)!=c){var d=h.lastIndexOf(s);d>-1&&(h=h.slice(0,d))}return h+i},Pe.unescape=function(t){return(t=wu(t))&&K.test(t)?t.replace(F,ae):t},Pe.uniqueId=function(t){var n=++Ot;return wu(t)+n},Pe.upperCase=Hu,Pe.upperFirst=Vu,Pe.each=wo,Pe.eachRight=yo,Pe.first=Ns,sc(Pe,(pc={},yr(Pe,(function(t,n){_t.call(Pe.prototype,n)||(pc[n]=t)})),pc),{chain:!1}),Pe.VERSION="4.17.21",xn(["bind","bindKey","curry","curryRight","partial","partialRight"],(function(t){Pe[t].placeholder=Pe})),xn(["drop","take"],(function(n,e){Le.prototype[n]=function(r){r=r===t?1:pe(fu(r),0);var i=this.__filtered__&&!e?new Le(this):this.clone();return i.__filtered__?i.__takeCount__=we(r,i.__takeCount__):i.__views__.push({size:we(r,h),type:n+(i.__dir__<0?"Right":"")}),i},Le.prototype[n+"Right"]=function(t){return this.reverse()[n](t).reverse()}})),xn(["filter","map","takeWhile"],(function(t,n){var e=n+1,r=1==e||3==e;Le.prototype[t]=function(t){var n=this.clone();return n.__iteratees__.push({iteratee:is(t,3),type:e}),n.__filtered__=n.__filtered__||r,n}})),xn(["head","last"],(function(t,n){var e="take"+(n?"Right":"");Le.prototype[t]=function(){return this[e](1).value()[0]}})),xn(["initial","tail"],(function(t,n){var e="drop"+(n?"":"Right");Le.prototype[t]=function(){return this.__filtered__?new Le(this):this[e](1)}})),Le.prototype.compact=function(){return this.filter(nc)},Le.prototype.find=function(t){return this.filter(t).head()},Le.prototype.findLast=function(t){return this.reverse().find(t)},Le.prototype.invokeMap=Yr((function(t,n){return"function"==typeof t?new Le(this):this.map((function(e){return Ur(e,t,n)}))})),Le.prototype.reject=function(t){return this.filter(Oo(is(t)))},Le.prototype.slice=function(n,e){n=fu(n);var r=this;return r.__filtered__&&(n>0||e<0)?new Le(r):(n<0?r=r.takeRight(-n):n&&(r=r.drop(n)),e!==t&&(r=(e=fu(e))<0?r.dropRight(-e):r.take(e-n)),r)},Le.prototype.takeRightWhile=function(t){return this.reverse().takeWhile(t).reverse()},Le.prototype.toArray=function(){return this.take(h)},yr(Le.prototype,(function(n,e){var r=/^(?:filter|find|map|reject)|While$/.test(e),i=/^(?:head|last)$/.test(e),s=Pe[i?"take"+("last"==e?"Right":""):e],o=i||/^find/.test(e);s&&(Pe.prototype[e]=function(){var e=this.__wrapped__,u=i?[1]:arguments,c=e instanceof Le,h=u[0],a=c||Fo(e),l=function(t){var n=s.apply(Pe,Tn([t],u));return i&&f?n[0]:n};a&&r&&"function"==typeof h&&1!=h.length&&(c=a=!1);var f=this.__chain__,d=o&&!f,v=c&&!this.__actions__.length;if(!o&&a){e=v?e:new Le(this);var p=n.apply(e,u);return p.__actions__.push({func:ao,args:[l],thisArg:t}),new We(p,f)}return d&&v?n.apply(this,u):(p=this.thru(l),d?i?p.value()[0]:p.value():p)})})),xn(["pop","push","shift","sort","splice","unshift"],(function(t){var n=Et[t],e=/^(?:push|sort|unshift)$/.test(t)?"tap":"thru",r=/^(?:pop|shift)$/.test(t);Pe.prototype[t]=function(){var t=arguments;if(r&&!this.__chain__){var i=this.value();return n.apply(Fo(i)?i:[],t)}return this[e]((function(e){return n.apply(Fo(e)?e:[],t)}))}})),yr(Le.prototype,(function(t,n){var e=Pe[n];if(e){var r=e.name+"";_t.call(Ee,r)||(Ee[r]=[]),Ee[r].push({name:n,func:e})}})),Ee[Di(t,2).name]=[{name:"wrapper",func:t}],Le.prototype.clone=function(){var t=new Le(this.__wrapped__);return t.__actions__=Si(this.__actions__),t.__dir__=this.__dir__,t.__filtered__=this.__filtered__,t.__iteratees__=Si(this.__iteratees__),t.__takeCount__=this.__takeCount__,t.__views__=Si(this.__views__),t},Le.prototype.reverse=function(){if(this.__filtered__){var t=new Le(this);t.__dir__=-1,t.__filtered__=!0}else(t=this.clone()).__dir__*=-1;return t},Le.prototype.value=function(){var t=this.__wrapped__.value(),n=this.__dir__,e=Fo(t),r=n<0,i=e?t.length:0,s=function(t,n,e){for(var r=-1,i=e.length;++r<i;){var s=e[r],o=s.size;switch(s.type){case"drop":t+=o;break;case"dropRight":n-=o;break;case"take":n=we(n,t+o);break;case"takeRight":t=pe(t,n-o)}}return{start:t,end:n}}(0,i,this.__views__),o=s.start,u=s.end,c=u-o,h=r?u:o-1,a=this.__iteratees__,l=a.length,f=0,d=we(c,this.__takeCount__);if(!e||!r&&i==c&&d==c)return ai(t,this.__actions__);var v=[];t:for(;c--&&f<d;){for(var p=-1,w=t[h+=n];++p<l;){var y=a[p],g=y.type,b=(0,y.iteratee)(w);if(2==g)w=b;else if(!b){if(1==g)continue t;break t}}v[f++]=w}return v},Pe.prototype.at=lo,Pe.prototype.chain=function(){return ho(this)},Pe.prototype.commit=function(){return new We(this.value(),this.__chain__)},Pe.prototype.next=function(){this.__values__===t&&(this.__values__=au(this.value()));var n=this.__index__>=this.__values__.length;return{done:n,value:n?t:this.__values__[this.__index__++]}},Pe.prototype.plant=function(n){for(var e,r=this;r instanceof Be;){var i=Ds(r);i.__index__=0,i.__values__=t,e?s.__wrapped__=i:e=i;var s=i;r=r.__wrapped__}return s.__wrapped__=n,e},Pe.prototype.reverse=function(){var n=this.__wrapped__;if(n instanceof Le){var e=n;return this.__actions__.length&&(e=new Le(this)),(e=e.reverse()).__actions__.push({func:ao,args:[Gs],thisArg:t}),new We(e,this.__chain__)}return this.thru(Gs)},Pe.prototype.toJSON=Pe.prototype.valueOf=Pe.prototype.value=function(){return ai(this.__wrapped__,this.__actions__)},Pe.prototype.first=Pe.prototype.head,Gt&&(Pe.prototype[Gt]=function(){return this}),Pe}();ln?((ln.exports=le)._=le,an._=le):hn._=le}.call($c.exports)),$c.exports);
|
|
1
|
+
import{p as t,H as n,c as e,h as r,d as i,t as s}from"./p-BxS4Pdpz.js";import{K as o}from"./p-D8W6LE-c.js";import{j as u,k as c,l as h,m as a,b as l,n as f,o as d,p as v,q as p,g as w,h as y,e as g,f as b,d as m,c as A,r as k,K as x,a as M,i as S}from"./p-DOF5fWDU.js";import{K as C,d as U}from"./p-Cnpk2hfo.js";import{O as E}from"./p-B0kd2rUI.js";import{K as j,d as T}from"./p-DgCGSL2Q.js";import{K as I}from"./p-n789Y3S-.js";import{K as O}from"./p-l10It7Nm.js";import{d as _}from"./p-BlUr7oVq.js";var z="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};class $ extends u{__class__="KritzelImage";src="";maxWidth=300;maxHeight=300;maxCompressionSize=300;isDebugInfoVisible=!0;constructor(t){super(),this.src=t?.src||"",this.x=t?.x||0,this.y=t?.y||0,this.translateX=t?.translateX||0,this.translateY=t?.translateY||0,this.scale=t?.scale||1}static create(t){const n=new $;return n._core=t,n.id=n.generateId(),n.workspaceId=t.store.state.activeWorkspace.id,n.x=0,n.y=0,n.translateX=0,n.translateY=0,n.scale=n._core.store.state.scale,n.zIndex=t.store.currentZIndex,n}resize(t,n,e,r){if(e<=1||r<=1)return;const i=r/this.height;this.width=this.width*i,this.height=this.height*i,this.translateX=t,this.translateY=n,this._core.store.state.objects.update(this)}calculateScaledDimensions(t){let n=t.width,e=t.height;if(t.width>this.maxWidth||t.height>this.maxHeight){const r=Math.min(this.maxWidth/t.width,this.maxHeight/t.height);n=t.width*r,e=t.height*r}return{scaledWidth:n,scaledHeight:e}}}class D extends c{touchStartTimeout=null;constructor(t){super(t)}handlePointerDown(t){"mouse"===t.pointerType&&h.isLeftClick(t)&&(this._core.store.state.isErasing=!0),"touch"===t.pointerType&&(this.touchStartTimeout=setTimeout((()=>{1!==this._core.store.state.pointers.size||this._core.store.state.isScaling||(this._core.store.state.isErasing=!0)}),80))}handlePointerMove(t){if("mouse"===t.pointerType&&this._core.store.state.isErasing){const n=this._core.getObjectsFromPointerEvent(t,".object");if(0===n.length)return;const e=this._core.store.state.pointerX,r=this._core.store.state.pointerY;n.forEach((t=>{t.markedForRemoval=t.hitTest(e,r)})),this._core.rerender()}if("touch"===t.pointerType&&1===this._core.store.state.pointers.size&&this._core.store.state.isErasing){const n=this._core.store.state.host?.shadowRoot;if(!n)return;const e=this._core.getObjectsFromPointerEvent(t,".object");if(0===e.length)return;const r=this._core.store.state.pointerX,i=this._core.store.state.pointerY;e.forEach((t=>{t.markedForRemoval=t.hitTest(r,i)})),this._core.rerender()}}handlePointerUp(t){if("mouse"===t.pointerType&&this._core.store.state.isErasing){const t=this._core.store.allObjects.filter((t=>t.markedForRemoval));t.forEach((t=>{t.markedForRemoval=!1,this._core.removeObject(t)})),t.length>0&&this._core.rerender(),this._core.store.state.isErasing=!1,this._core.engine.emitObjectsChange()}if("touch"===t.pointerType&&(clearTimeout(this.touchStartTimeout),this._core.store.state.isErasing)){const t=this._core.store.allObjects.filter((t=>t.markedForRemoval));t.forEach((t=>{t.markedForRemoval=!1,this._core.removeObject(t)})),t.length>0&&this._core.rerender(),this._core.store.state.isErasing=!1,this._core.engine.emitObjectsChange()}}}function P(t,n){return new Promise((function(e,r){let i;return R(t).then((function(t){try{return i=t,e(new Blob([n.slice(0,2),i,n.slice(2)],{type:"image/jpeg"}))}catch(t){return r(t)}}),r)}))}const R=t=>new Promise(((n,e)=>{const r=new FileReader;r.addEventListener("load",(({target:{result:t}})=>{const r=new DataView(t);let i=0;if(65496!==r.getUint16(i))return e("not a valid JPEG");for(i+=2;;){const s=r.getUint16(i);if(65498===s)break;const o=r.getUint16(i+2);if(65505===s&&1165519206===r.getUint32(i+4)){const s=i+10;let u;switch(r.getUint16(s)){case 18761:u=!0;break;case 19789:u=!1;break;default:return e("TIFF header contains invalid endian")}if(42!==r.getUint16(s+2,u))return e("TIFF header contains invalid version");const c=r.getUint32(s+4,u),h=s+c+2+12*r.getUint16(s+c,u);for(let t=s+c+2;t<h;t+=12)if(274==r.getUint16(t,u)){if(3!==r.getUint16(t+2,u))return e("Orientation data type is invalid");if(1!==r.getUint32(t+4,u))return e("Orientation data count is invalid");r.setUint16(t+8,1,u);break}return n(t.slice(i,i+2+o))}i+=2+o}return n(new Blob)})),r.readAsArrayBuffer(t)}));var B={},W={get exports(){return B},set exports(t){B=t}};!function(){var t,n,e={};W.exports=e,e.parse=function(t,n){for(var r=e.bin.readUshort,i=e.bin.readUint,s=0,o={},u=new Uint8Array(t),c=u.length-4;101010256!=i(u,c);)c--;s=c,s+=4;var h=r(u,s+=4);r(u,s+=2);var a=i(u,s+=2),l=i(u,s+=4);s+=4,s=l;for(var f=0;f<h;f++){i(u,s),s+=4,s+=4,s+=4,i(u,s+=4),a=i(u,s+=4);var d=i(u,s+=4),v=r(u,s+=4),p=r(u,s+2),w=r(u,s+4);s+=6;var y=i(u,s+=8);s+=4,s+=v+p+w,e._readLocal(u,y,o,a,d,n)}return o},e._readLocal=function(t,n,r,i,s,o){var u=e.bin.readUshort,c=e.bin.readUint;c(t,n),u(t,n+=4),u(t,n+=2);var h=u(t,n+=2);c(t,n+=2),c(t,n+=4),n+=4;var a=u(t,n+=8),l=u(t,n+=2),f=e.bin.readUTF8(t,n+=2,a);if(n+=a,n+=l,o)r[f]={size:s,csize:i};else{var d=new Uint8Array(t.buffer,n);if(0==h)r[f]=new Uint8Array(d.buffer.slice(n,n+i));else{if(8!=h)throw"unknown compression method: "+h;var v=new Uint8Array(s);e.inflateRaw(d,v),r[f]=v}}},e.inflateRaw=function(t,n){return e.F.inflate(t,n)},e.inflate=function(t,n){return e.inflateRaw(new Uint8Array(t.buffer,t.byteOffset+2,t.length-6),n)},e.deflate=function(t,n){null==n&&(n={level:6});var r=0,i=new Uint8Array(50+Math.floor(1.1*t.length));i[r]=120,i[r+1]=156,r=e.F.deflateRaw(t,i,r+=2,n.level);var s=e.adler(t,0,t.length);return i[r+0]=s>>>24&255,i[r+1]=s>>>16&255,i[r+2]=s>>>8&255,i[r+3]=s>>>0&255,new Uint8Array(i.buffer,0,r+4)},e.deflateRaw=function(t,n){null==n&&(n={level:6});var r=new Uint8Array(50+Math.floor(1.1*t.length)),i=e.F.deflateRaw(t,r,i,n.level);return new Uint8Array(r.buffer,0,i)},e.encode=function(t,n){null==n&&(n=!1);var r=0,i=e.bin.writeUint,s=e.bin.writeUshort,o={};for(var u in t){var c=!e._noNeed(u)&&!n,h=t[u],a=e.crc.crc(h,0,h.length);o[u]={cpr:c,usize:h.length,crc:a,file:c?e.deflateRaw(h):h}}for(var u in o)r+=o[u].file.length+30+46+2*e.bin.sizeUTF8(u);r+=22;var l=new Uint8Array(r),f=0,d=[];for(var u in o){var v=o[u];d.push(f),f=e._writeHeader(l,f,u,v,0)}var p=0,w=f;for(var u in o)v=o[u],d.push(f),f=e._writeHeader(l,f,u,v,1,d[p++]);var y=f-w;return i(l,f,101010256),f+=4,s(l,f+=4,p),s(l,f+=2,p),i(l,f+=2,y),i(l,f+=4,w),f+=4,f+=2,l.buffer},e._noNeed=function(t){var n=t.split(".").pop().toLowerCase();return-1!="png,jpg,jpeg,zip".indexOf(n)},e._writeHeader=function(t,n,r,i,s,o){var u=e.bin.writeUint,c=e.bin.writeUshort,h=i.file;return u(t,n,0==s?67324752:33639248),n+=4,1==s&&(n+=2),c(t,n,20),c(t,n+=2,0),c(t,n+=2,i.cpr?8:0),u(t,n+=2,0),u(t,n+=4,i.crc),u(t,n+=4,h.length),u(t,n+=4,i.usize),c(t,n+=4,e.bin.sizeUTF8(r)),c(t,n+=2,0),n+=2,1==s&&(n+=2,n+=2,u(t,n+=6,o),n+=4),n+=e.bin.writeUTF8(t,n,r),0==s&&(t.set(h,n),n+=h.length),n},e.crc={table:function(){for(var t=new Uint32Array(256),n=0;n<256;n++){for(var e=n,r=0;r<8;r++)1&e?e=3988292384^e>>>1:e>>>=1;t[n]=e}return t}(),update:function(t,n,r,i){for(var s=0;s<i;s++)t=e.crc.table[255&(t^n[r+s])]^t>>>8;return t},crc:function(t,n,r){return 4294967295^e.crc.update(4294967295,t,n,r)}},e.adler=function(t,n,e){for(var r=1,i=0,s=n,o=n+e;s<o;){for(var u=Math.min(s+5552,o);s<u;)i+=r+=t[s++];r%=65521,i%=65521}return i<<16|r},e.bin={readUshort:function(t,n){return t[n]|t[n+1]<<8},writeUshort:function(t,n,e){t[n]=255&e,t[n+1]=e>>8&255},readUint:function(t,n){return 16777216*t[n+3]+(t[n+2]<<16|t[n+1]<<8|t[n])},writeUint:function(t,n,e){t[n]=255&e,t[n+1]=e>>8&255,t[n+2]=e>>16&255,t[n+3]=e>>24&255},readASCII:function(t,n,e){for(var r="",i=0;i<e;i++)r+=String.fromCharCode(t[n+i]);return r},writeASCII:function(t,n,e){for(var r=0;r<e.length;r++)t[n+r]=e.charCodeAt(r)},pad:function(t){return t.length<2?"0"+t:t},readUTF8:function(t,n,r){for(var i,s="",o=0;o<r;o++)s+="%"+e.bin.pad(t[n+o].toString(16));try{i=decodeURIComponent(s)}catch(i){return e.bin.readASCII(t,n,r)}return i},writeUTF8:function(t,n,e){for(var r=e.length,i=0,s=0;s<r;s++){var o=e.charCodeAt(s);if(4294967168&o)if(4294965248&o)if(4294901760&o){if(4292870144&o)throw"e";t[n+i]=240|o>>18,t[n+i+1]=128|o>>12&63,t[n+i+2]=128|o>>6&63,t[n+i+3]=128|63&o,i+=4}else t[n+i]=224|o>>12,t[n+i+1]=128|o>>6&63,t[n+i+2]=128|63&o,i+=3;else t[n+i]=192|o>>6,t[n+i+1]=128|63&o,i+=2;else t[n+i]=o,i++}return i},sizeUTF8:function(t){for(var n=t.length,e=0,r=0;r<n;r++){var i=t.charCodeAt(r);if(4294967168&i)if(4294965248&i)if(4294901760&i){if(4292870144&i)throw"e";e+=4}else e+=3;else e+=2;else e++}return e}},e.F={},e.F.deflateRaw=function(t,n,r,i){var s=[[0,0,0,0,0],[4,4,8,4,0],[4,5,16,8,0],[4,6,16,16,0],[4,10,16,32,0],[8,16,32,32,0],[8,16,128,128,0],[8,32,128,256,0],[32,128,258,1024,1],[32,258,258,4096,1]][i],o=e.F.U,u=e.F._goodIndex,c=e.F._putsE,h=0,a=r<<3,l=0,f=t.length;if(0==i){for(;h<f;)c(n,a,h+(M=Math.min(65535,f-h))==f?1:0),a=e.F._copyExact(t,h,M,n,a+8),h+=M;return a>>>3}var d=o.lits,v=o.strt,p=o.prev,w=0,y=0,g=0,b=0,m=0,A=0;for(f>2&&(v[A=e.F._hash(t,0)]=0),h=0;h<f;h++){if(m=A,h+1<f-2){A=e.F._hash(t,h+1);var k=h+1&32767;p[k]=v[A],v[A]=k}if(l<=h){(w>14e3||y>26697)&&f-h>100&&(l<h&&(d[w]=h-l,w+=2,l=h),a=e.F._writeBlock(h==f-1||l==f?1:0,d,w,b,t,g,h-g,n,a),w=y=b=0,g=h);var x=0;h<f-2&&(x=e.F._bestMatch(t,h,p,m,Math.min(s[2],f-h),s[3]));var M=x>>>16,S=65535&x;if(0!=x){S=65535&x;var C=u(M=x>>>16,o.of0);o.lhst[257+C]++;var U=u(S,o.df0);o.dhst[U]++,b+=o.exb[C]+o.dxb[U],d[w]=M<<23|h-l,d[w+1]=S<<16|C<<8|U,w+=2,l=h+M}else o.lhst[t[h]]++;y++}}for(g==h&&0!=t.length||(l<h&&(d[w]=h-l,w+=2,l=h),a=e.F._writeBlock(1,d,w,b,t,g,h-g,n,a),w=0,y=0,w=y=b=0,g=h);7&a;)a++;return a>>>3},e.F._bestMatch=function(t,n,r,i,s,o){var u=32767&n,c=r[u],h=u-c+32768&32767;if(c==u||i!=e.F._hash(t,n-h))return 0;for(var a=0,l=0,f=Math.min(32767,n);h<=f&&0!=--o&&c!=u;){if(0==a||t[n+a]==t[n+a-h]){var d=e.F._howLong(t,n,h);if(d>a){if(l=h,(a=d)>=s)break;h+2<d&&(d=h+2);for(var v=0,p=0;p<d-2;p++){var w=n-h+p+32768&32767,y=w-r[w]+32768&32767;y>v&&(v=y,c=w)}}}h+=(u=c)-(c=r[u])+32768&32767}return a<<16|l},e.F._howLong=function(t,n,e){if(t[n]!=t[n-e]||t[n+1]!=t[n+1-e]||t[n+2]!=t[n+2-e])return 0;var r=n,i=Math.min(t.length,n+258);for(n+=3;n<i&&t[n]==t[n-e];)n++;return n-r},e.F._hash=function(t,n){return(t[n]<<8|t[n+1])+(t[n+2]<<4)&65535},e.saved=0,e.F._writeBlock=function(t,n,r,i,s,o,u,c,h){var a,l,f,d,v,p,w,y,g,b=e.F.U,m=e.F._putsF,A=e.F._putsE;b.lhst[256]++,l=(a=e.F.getTrees())[0],f=a[1],d=a[2],v=a[3],p=a[4],w=a[5],y=a[6],g=a[7];var k=32+(h+3&7?8-(h+3&7):0)+(u<<3),x=i+e.F.contSize(b.fltree,b.lhst)+e.F.contSize(b.fdtree,b.dhst),M=i+e.F.contSize(b.ltree,b.lhst)+e.F.contSize(b.dtree,b.dhst);M+=14+3*w+e.F.contSize(b.itree,b.ihst)+(2*b.ihst[16]+3*b.ihst[17]+7*b.ihst[18]);for(var S=0;S<286;S++)b.lhst[S]=0;for(S=0;S<30;S++)b.dhst[S]=0;for(S=0;S<19;S++)b.ihst[S]=0;var C=k<x&&k<M?0:x<M?1:2;if(m(c,h,t),m(c,h+1,C),h+=3,0==C){for(;7&h;)h++;h=e.F._copyExact(s,o,u,c,h)}else{var U,E;if(1==C&&(U=b.fltree,E=b.fdtree),2==C){e.F.makeCodes(b.ltree,l),e.F.revCodes(b.ltree,l),e.F.makeCodes(b.dtree,f),e.F.revCodes(b.dtree,f),e.F.makeCodes(b.itree,d),e.F.revCodes(b.itree,d),U=b.ltree,E=b.dtree,A(c,h,v-257),A(c,h+=5,p-1),A(c,h+=5,w-4),h+=4;for(var j=0;j<w;j++)A(c,h+3*j,b.itree[1+(b.ordr[j]<<1)]);h=e.F._codeTiny(y,b.itree,c,h+=3*w),h=e.F._codeTiny(g,b.itree,c,h)}for(var T=o,I=0;I<r;I+=2){for(var O=n[I],_=O>>>23,z=T+(8388607&O);T<z;)h=e.F._writeLit(s[T++],U,c,h);if(0!=_){var $=n[I+1],D=$>>16,P=$>>8&255,R=255&$;A(c,h=e.F._writeLit(257+P,U,c,h),_-b.of0[P]),m(c,h=e.F._writeLit(R,E,c,h+=b.exb[P]),D-b.df0[R]),h+=b.dxb[R],T+=_}}h=e.F._writeLit(256,U,c,h)}return h},e.F._copyExact=function(t,n,e,r,i){var s=i>>>3;return r[s]=e,r[s+1]=e>>>8,r[s+2]=255-r[s],r[s+3]=255-r[s+1],s+=4,r.set(new Uint8Array(t.buffer,n,e),s),i+(e+4<<3)},e.F.getTrees=function(){for(var t=e.F.U,n=e.F._hufTree(t.lhst,t.ltree,15),r=e.F._hufTree(t.dhst,t.dtree,15),i=[],s=e.F._lenCodes(t.ltree,i),o=[],u=e.F._lenCodes(t.dtree,o),c=0;c<i.length;c+=2)t.ihst[i[c]]++;for(c=0;c<o.length;c+=2)t.ihst[o[c]]++;for(var h=e.F._hufTree(t.ihst,t.itree,7),a=19;a>4&&0==t.itree[1+(t.ordr[a-1]<<1)];)a--;return[n,r,h,s,u,a,i,o]},e.F.getSecond=function(t){for(var n=[],e=0;e<t.length;e+=2)n.push(t[e+1]);return n},e.F.nonZero=function(t){for(var n="",e=0;e<t.length;e+=2)0!=t[e+1]&&(n+=(e>>1)+",");return n},e.F.contSize=function(t,n){for(var e=0,r=0;r<n.length;r++)e+=n[r]*t[1+(r<<1)];return e},e.F._codeTiny=function(t,n,r,i){for(var s=0;s<t.length;s+=2){var o=t[s],u=t[s+1];i=e.F._writeLit(o,n,r,i);var c=16==o?2:17==o?3:7;o>15&&(e.F._putsE(r,i,u,c),i+=c)}return i},e.F._lenCodes=function(t,n){for(var e=t.length;2!=e&&0==t[e-1];)e-=2;for(var r=0;r<e;r+=2){var i=t[r+1],s=r+3<e?t[r+3]:-1,o=r+5<e?t[r+5]:-1,u=0==r?-1:t[r-1];if(0==i&&s==i&&o==i){for(var c=r+5;c+2<e&&t[c+2]==i;)c+=2;(h=Math.min(c+1-r>>>1,138))<11?n.push(17,h-3):n.push(18,h-11),r+=2*h-2}else if(i==u&&s==i&&o==i){for(c=r+5;c+2<e&&t[c+2]==i;)c+=2;var h=Math.min(c+1-r>>>1,6);n.push(16,h-3),r+=2*h-2}else n.push(i,0)}return e>>>1},e.F._hufTree=function(t,n,r){var i=[],s=t.length,o=n.length,u=0;for(u=0;u<o;u+=2)n[u]=0,n[u+1]=0;for(u=0;u<s;u++)0!=t[u]&&i.push({lit:u,f:t[u]});var c=i.length,h=i.slice(0);if(0==c)return 0;if(1==c){var a=i[0].lit;return h=0==a?1:0,n[1+(a<<1)]=1,n[1+(h<<1)]=1,1}i.sort((function(t,n){return t.f-n.f}));var l=i[0],f=i[1],d=0,v=1,p=2;for(i[0]={lit:-1,f:l.f+f.f,l,r:f,d:0};v!=c-1;)l=d!=v&&(p==c||i[d].f<i[p].f)?i[d++]:i[p++],f=d!=v&&(p==c||i[d].f<i[p].f)?i[d++]:i[p++],i[v++]={lit:-1,f:l.f+f.f,l,r:f};var w=e.F.setDepth(i[v-1],0);for(w>r&&(e.F.restrictDepth(h,r,w),w=r),u=0;u<c;u++)n[1+(h[u].lit<<1)]=h[u].d;return w},e.F.setDepth=function(t,n){return-1!=t.lit?(t.d=n,n):Math.max(e.F.setDepth(t.l,n+1),e.F.setDepth(t.r,n+1))},e.F.restrictDepth=function(t,n,e){var r=0,i=1<<e-n,s=0;for(t.sort((function(t,n){return n.d==t.d?t.f-n.f:n.d-t.d})),r=0;r<t.length&&t[r].d>n;r++){var o=t[r].d;t[r].d=n,s+=i-(1<<e-o)}for(s>>>=e-n;s>0;)(o=t[r].d)<n?(t[r].d++,s-=1<<n-o-1):r++;for(;r>=0;r--)t[r].d==n&&s<0&&(t[r].d--,s++);0!=s&&console.log("debt left")},e.F._goodIndex=function(t,n){var e=0;return n[16|e]<=t&&(e|=16),n[8|e]<=t&&(e|=8),n[4|e]<=t&&(e|=4),n[2|e]<=t&&(e|=2),n[1|e]<=t&&(e|=1),e},e.F._writeLit=function(t,n,r,i){return e.F._putsF(r,i,n[t<<1]),i+n[1+(t<<1)]},e.F.inflate=function(t,n){var r=Uint8Array;if(3==t[0]&&0==t[1])return n||new r(0);var i=e.F,s=i._bitsF,o=i._bitsE,u=i._decodeTiny,c=i.makeCodes,h=i.codes2map,a=i._get17,l=i.U,f=null==n;f&&(n=new r(t.length>>>2<<3));for(var d,v,p=0,w=0,y=0,g=0,b=0,m=0,A=0,k=0,x=0;0==p;)if(p=s(t,x,1),w=s(t,x+1,2),x+=3,0!=w){if(f&&(n=e.F._check(n,k+(1<<17))),1==w&&(d=l.flmap,v=l.fdmap,m=511,A=31),2==w){y=o(t,x,5)+257,g=o(t,x+5,5)+1,b=o(t,x+10,4)+4,x+=14;for(var M=0;M<38;M+=2)l.itree[M]=0,l.itree[M+1]=0;var S=1;for(M=0;M<b;M++){var C=o(t,x+3*M,3);l.itree[1+(l.ordr[M]<<1)]=C,C>S&&(S=C)}x+=3*b,c(l.itree,S),h(l.itree,S,l.imap),d=l.lmap,v=l.dmap,x=u(l.imap,(1<<S)-1,y+g,t,x,l.ttree);var U=i._copyOut(l.ttree,0,y,l.ltree);m=(1<<U)-1;var E=i._copyOut(l.ttree,y,g,l.dtree);A=(1<<E)-1,c(l.ltree,U),h(l.ltree,U,d),c(l.dtree,E),h(l.dtree,E,v)}for(;;){var j=d[a(t,x)&m];x+=15&j;var T=j>>>4;if(T>>>8==0)n[k++]=T;else{if(256==T)break;var I=k+T-254;if(T>264){var O=l.ldef[T-257];I=k+(O>>>3)+o(t,x,7&O),x+=7&O}var _=v[a(t,x)&A],z=l.ddef[_>>>4],$=(z>>>4)+s(t,x+=15&_,15&z);for(x+=15&z,f&&(n=e.F._check(n,k+(1<<17)));k<I;)n[k]=n[k++-$],n[k]=n[k++-$],n[k]=n[k++-$],n[k]=n[k++-$];k=I}}}else{7&x&&(x+=8-(7&x));var D=4+(x>>>3),P=t[D-4]|t[D-3]<<8;f&&(n=e.F._check(n,k+P)),n.set(new r(t.buffer,t.byteOffset+D,P),k),x=D+P<<3,k+=P}return n.length==k?n:n.slice(0,k)},e.F._check=function(t,n){var e=t.length;if(n<=e)return t;var r=new Uint8Array(Math.max(e<<1,n));return r.set(t,0),r},e.F._decodeTiny=function(t,n,r,i,s,o){for(var u=e.F._bitsE,c=e.F._get17,h=0;h<r;){var a=t[c(i,s)&n];s+=15&a;var l=a>>>4;if(l<=15)o[h]=l,h++;else{var f=0,d=0;16==l?(d=3+u(i,s,2),s+=2,f=o[h-1]):17==l?(d=3+u(i,s,3),s+=3):18==l&&(d=11+u(i,s,7),s+=7);for(var v=h+d;h<v;)o[h]=f,h++}}return s},e.F._copyOut=function(t,n,e,r){for(var i=0,s=0,o=r.length>>>1;s<e;){var u=t[s+n];r[s<<1]=0,r[1+(s<<1)]=u,u>i&&(i=u),s++}for(;s<o;)r[s<<1]=0,r[1+(s<<1)]=0,s++;return i},e.F.makeCodes=function(t,n){for(var r,i,s,o,u=e.F.U,c=t.length,h=u.bl_count,a=0;a<=n;a++)h[a]=0;for(a=1;a<c;a+=2)h[t[a]]++;var l=u.next_code;for(r=0,h[0]=0,i=1;i<=n;i++)l[i]=r=r+h[i-1]<<1;for(s=0;s<c;s+=2)0!=(o=t[s+1])&&(t[s]=l[o],l[o]++)},e.F.codes2map=function(t,n,r){for(var i=t.length,s=e.F.U.rev15,o=0;o<i;o+=2)if(0!=t[o+1])for(var u=t[o+1],c=o>>1<<4|u,h=n-u,a=t[o]<<h,l=a+(1<<h);a!=l;)r[s[a]>>>15-n]=c,a++},e.F.revCodes=function(t,n){for(var r=e.F.U.rev15,i=15-n,s=0;s<t.length;s+=2)t[s]=r[t[s]<<n-t[s+1]]>>>i},e.F._putsE=function(t,n,e){var r=n>>>3;t[r]|=e<<=7&n,t[r+1]|=e>>>8},e.F._putsF=function(t,n,e){var r=n>>>3;t[r]|=e<<=7&n,t[r+1]|=e>>>8,t[r+2]|=e>>>16},e.F._bitsE=function(t,n,e){return(t[n>>>3]|t[1+(n>>>3)]<<8)>>>(7&n)&(1<<e)-1},e.F._bitsF=function(t,n,e){return(t[n>>>3]|t[1+(n>>>3)]<<8|t[2+(n>>>3)]<<16)>>>(7&n)&(1<<e)-1},e.F._get17=function(t,n){return(t[n>>>3]|t[1+(n>>>3)]<<8|t[2+(n>>>3)]<<16)>>>(7&n)},e.F._get25=function(t,n){return(t[n>>>3]|t[1+(n>>>3)]<<8|t[2+(n>>>3)]<<16|t[3+(n>>>3)]<<24)>>>(7&n)},e.F.U=(t=Uint16Array,n=Uint32Array,{next_code:new t(16),bl_count:new t(16),ordr:[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],of0:[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,999,999,999],exb:[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0],ldef:new t(32),df0:[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,65535,65535],dxb:[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0],ddef:new n(32),flmap:new t(512),fltree:[],fdmap:new t(32),fdtree:[],lmap:new t(32768),ltree:[],ttree:[],dmap:new t(32768),dtree:[],imap:new t(512),itree:[],rev15:new t(32768),lhst:new n(286),dhst:new n(30),ihst:new n(19),lits:new n(15e3),strt:new t(65536),prev:new t(32768)}),function(){for(var t=e.F.U,n=0;n<32768;n++){var r=n;r=(4278255360&(r=(4042322160&(r=(3435973836&(r=(2863311530&r)>>>1|(1431655765&r)<<1))>>>2|(858993459&r)<<2))>>>4|(252645135&r)<<4))>>>8|(16711935&r)<<8,t.rev15[n]=(r>>>16|r<<16)>>>17}function i(t,n,e){for(;0!=n--;)t.push(0,e)}for(n=0;n<32;n++)t.ldef[n]=t.of0[n]<<3|t.exb[n],t.ddef[n]=t.df0[n]<<4|t.dxb[n];i(t.fltree,144,8),i(t.fltree,112,9),i(t.fltree,24,7),i(t.fltree,8,8),e.F.makeCodes(t.fltree,9),e.F.codes2map(t.fltree,9,t.flmap),e.F.revCodes(t.fltree,9),i(t.fdtree,32,5),e.F.makeCodes(t.fdtree,5),e.F.codes2map(t.fdtree,5,t.fdmap),e.F.revCodes(t.fdtree,5),i(t.itree,19,0),i(t.ltree,286,0),i(t.dtree,30,0),i(t.ttree,320,0)}()}();var L=function(t,n){return n.forEach((function(n){n&&"string"!=typeof n&&!Array.isArray(n)&&Object.keys(n).forEach((function(e){if("default"!==e&&!(e in t)){var r=Object.getOwnPropertyDescriptor(n,e);Object.defineProperty(t,e,r.get?r:{enumerable:!0,get:function(){return n[e]}})}}))})),Object.freeze(t)}({__proto__:null,default:B},[B]);const F=function(){var t={nextZero(t,n){for(;0!=t[n];)n++;return n},readUshort:(t,n)=>t[n]<<8|t[n+1],writeUshort(t,n,e){t[n]=e>>8&255,t[n+1]=255&e},readUint:(t,n)=>16777216*t[n]+(t[n+1]<<16|t[n+2]<<8|t[n+3]),writeUint(t,n,e){t[n]=e>>24&255,t[n+1]=e>>16&255,t[n+2]=e>>8&255,t[n+3]=255&e},readASCII(t,n,e){let r="";for(let i=0;i<e;i++)r+=String.fromCharCode(t[n+i]);return r},writeASCII(t,n,e){for(let r=0;r<e.length;r++)t[n+r]=e.charCodeAt(r)},readBytes(t,n,e){const r=[];for(let i=0;i<e;i++)r.push(t[n+i]);return r},pad:t=>t.length<2?`0${t}`:t,readUTF8(n,e,r){let i,s="";for(let i=0;i<r;i++)s+=`%${t.pad(n[e+i].toString(16))}`;try{i=decodeURIComponent(s)}catch(i){return t.readASCII(n,e,r)}return i}};function n(n,e,r,i){const o=e*r,u=s(i),c=Math.ceil(e*u/8),h=new Uint8Array(4*o),a=new Uint32Array(h.buffer),{ctype:l}=i,{depth:f}=i,d=t.readUshort;if(6==l){const t=o<<2;if(8==f)for(var v=0;v<t;v+=4)h[v]=n[v],h[v+1]=n[v+1],h[v+2]=n[v+2],h[v+3]=n[v+3];if(16==f)for(v=0;v<t;v++)h[v]=n[v<<1]}else if(2==l){const t=i.tabs.tRNS;if(null==t){if(8==f)for(v=0;v<o;v++){var p=3*v;a[v]=255<<24|n[p+2]<<16|n[p+1]<<8|n[p]}if(16==f)for(v=0;v<o;v++)a[v]=255<<24|n[4+(p=6*v)]<<16|n[p+2]<<8|n[p]}else{var w=t[0];const e=t[1],r=t[2];if(8==f)for(v=0;v<o;v++){var y=v<<2;a[v]=255<<24|n[2+(p=3*v)]<<16|n[p+1]<<8|n[p],n[p]==w&&n[p+1]==e&&n[p+2]==r&&(h[y+3]=0)}if(16==f)for(v=0;v<o;v++)y=v<<2,a[v]=255<<24|n[4+(p=6*v)]<<16|n[p+2]<<8|n[p],d(n,p)==w&&d(n,p+2)==e&&d(n,p+4)==r&&(h[y+3]=0)}}else if(3==l){const t=i.tabs.PLTE,s=i.tabs.tRNS,u=s?s.length:0;if(1==f)for(var g=0;g<r;g++){var b=g*c,m=g*e;for(v=0;v<e;v++){var A=3*(k=n[b+(v>>3)]>>7-(7&v)&1);h[y=m+v<<2]=t[A],h[y+1]=t[A+1],h[y+2]=t[A+2],h[y+3]=k<u?s[k]:255}}if(2==f)for(g=0;g<r;g++)for(b=g*c,m=g*e,v=0;v<e;v++)A=3*(k=n[b+(v>>2)]>>6-((3&v)<<1)&3),h[y=m+v<<2]=t[A],h[y+1]=t[A+1],h[y+2]=t[A+2],h[y+3]=k<u?s[k]:255;if(4==f)for(g=0;g<r;g++)for(b=g*c,m=g*e,v=0;v<e;v++)A=3*(k=n[b+(v>>1)]>>4-((1&v)<<2)&15),h[y=m+v<<2]=t[A],h[y+1]=t[A+1],h[y+2]=t[A+2],h[y+3]=k<u?s[k]:255;if(8==f)for(v=0;v<o;v++){var k;A=3*(k=n[v]),h[y=v<<2]=t[A],h[y+1]=t[A+1],h[y+2]=t[A+2],h[y+3]=k<u?s[k]:255}}else if(4==l){if(8==f)for(v=0;v<o;v++){var x=n[M=v<<1];h[y=v<<2]=x,h[y+1]=x,h[y+2]=x,h[y+3]=n[M+1]}if(16==f)for(v=0;v<o;v++){var M;x=n[M=v<<2],h[y=v<<2]=x,h[y+1]=x,h[y+2]=x,h[y+3]=n[M+2]}}else if(0==l)for(w=i.tabs.tRNS?i.tabs.tRNS:-1,g=0;g<r;g++){const t=g*c,r=g*e;if(1==f)for(var S=0;S<e;S++){var C=(x=255*(n[t+(S>>>3)]>>>7-(7&S)&1))==255*w?0:255;a[r+S]=C<<24|x<<16|x<<8|x}else if(2==f)for(S=0;S<e;S++)C=(x=85*(n[t+(S>>>2)]>>>6-((3&S)<<1)&3))==85*w?0:255,a[r+S]=C<<24|x<<16|x<<8|x;else if(4==f)for(S=0;S<e;S++)C=(x=17*(n[t+(S>>>1)]>>>4-((1&S)<<2)&15))==17*w?0:255,a[r+S]=C<<24|x<<16|x<<8|x;else if(8==f)for(S=0;S<e;S++)C=(x=n[t+S])==w?0:255,a[r+S]=C<<24|x<<16|x<<8|x;else if(16==f)for(S=0;S<e;S++)x=n[t+(S<<1)],C=d(n,t+(S<<1))==w?0:255,a[r+S]=C<<24|x<<16|x<<8|x}return h}function e(t,n,e,u){const c=s(t),h=Math.ceil(e*c/8),a=new Uint8Array((h+1+t.interlace)*u);return n=t.tabs.CgBI?i(n,a):r(n,a),0==t.interlace?n=o(n,t,0,e,u):1==t.interlace&&(n=function(t,n){const e=n.width,r=n.height,i=s(n),u=i>>3,c=Math.ceil(e*i/8),h=new Uint8Array(r*c);let a=0;const l=[0,0,4,0,2,0,1],f=[0,4,0,2,0,1,0],d=[8,8,8,4,4,2,2],v=[8,8,4,4,2,2,1];let p=0;for(;p<7;){const s=d[p],y=v[p];let g=0,b=0,m=l[p];for(;m<r;)m+=s,b++;let A=f[p];for(;A<e;)A+=y,g++;const k=Math.ceil(g*i/8);o(t,n,a,g,b);let x=0,M=l[p];for(;M<r;){let n=f[p],r=a+x*k<<3;for(;n<e;){var w;if(1==i&&(w=(w=t[r>>3])>>7-(7&r)&1,h[M*c+(n>>3)]|=w<<7-(7&n)),2==i&&(w=(w=t[r>>3])>>6-(7&r)&3,h[M*c+(n>>2)]|=w<<6-((3&n)<<1)),4==i&&(w=(w=t[r>>3])>>4-(7&r)&15,h[M*c+(n>>1)]|=w<<4-((1&n)<<2)),i>=8){const e=M*c+n*u;for(let n=0;n<u;n++)h[e+n]=t[(r>>3)+n]}r+=i,n+=y}x++,M+=s}g*b!=0&&(a+=b*(1+k)),p+=1}return h}(n,t)),n}function r(t,n){return i(new Uint8Array(t.buffer,2,t.length-6),n)}var i=function(){const t={H:{}};return t.H.N=function(n,e){const r=Uint8Array;let i,s,o=0,u=0,c=0,h=0,a=0,l=0,f=0,d=0,v=0;if(3==n[0]&&0==n[1])return e||new r(0);const p=t.H,w=p.b,y=p.e,g=p.R,b=p.n,m=p.A,A=p.Z,k=p.m,x=null==e;for(x&&(e=new r(n.length>>>2<<5));0==o;)if(o=w(n,v,1),u=w(n,v+1,2),v+=3,0!=u){if(x&&(e=t.H.W(e,d+(1<<17))),1==u&&(i=k.J,s=k.h,l=511,f=31),2==u){c=y(n,v,5)+257,h=y(n,v+5,5)+1,a=y(n,v+10,4)+4,v+=14;let t=1;for(var M=0;M<38;M+=2)k.Q[M]=0,k.Q[M+1]=0;for(M=0;M<a;M++){const e=y(n,v+3*M,3);k.Q[1+(k.X[M]<<1)]=e,e>t&&(t=e)}v+=3*a,b(k.Q,t),m(k.Q,t,k.u),i=k.w,s=k.d,v=g(k.u,(1<<t)-1,c+h,n,v,k.v);const e=p.V(k.v,0,c,k.C);l=(1<<e)-1;const r=p.V(k.v,c,h,k.D);f=(1<<r)-1,b(k.C,e),m(k.C,e,i),b(k.D,r),m(k.D,r,s)}for(;;){const t=i[A(n,v)&l];v+=15&t;const r=t>>>4;if(r>>>8==0)e[d++]=r;else{if(256==r)break;{let t=d+r-254;if(r>264){const e=k.q[r-257];t=d+(e>>>3)+y(n,v,7&e),v+=7&e}const i=s[A(n,v)&f];v+=15&i;const o=k.c[i>>>4],u=(o>>>4)+w(n,v,15&o);for(v+=15&o;d<t;)e[d]=e[d++-u],e[d]=e[d++-u],e[d]=e[d++-u],e[d]=e[d++-u];d=t}}}}else{7&v&&(v+=8-(7&v));const i=4+(v>>>3),s=n[i-4]|n[i-3]<<8;x&&(e=t.H.W(e,d+s)),e.set(new r(n.buffer,n.byteOffset+i,s),d),v=i+s<<3,d+=s}return e.length==d?e:e.slice(0,d)},t.H.W=function(t,n){const e=t.length;if(n<=e)return t;const r=new Uint8Array(e<<1);return r.set(t,0),r},t.H.R=function(n,e,r,i,s,o){const u=t.H.e,c=t.H.Z;let h=0;for(;h<r;){const t=n[c(i,s)&e];s+=15&t;const r=t>>>4;if(r<=15)o[h]=r,h++;else{let t=0,n=0;16==r?(n=3+u(i,s,2),s+=2,t=o[h-1]):17==r?(n=3+u(i,s,3),s+=3):18==r&&(n=11+u(i,s,7),s+=7);const e=h+n;for(;h<e;)o[h]=t,h++}}return s},t.H.V=function(t,n,e,r){let i=0,s=0;const o=r.length>>>1;for(;s<e;){const e=t[s+n];r[s<<1]=0,r[1+(s<<1)]=e,e>i&&(i=e),s++}for(;s<o;)r[s<<1]=0,r[1+(s<<1)]=0,s++;return i},t.H.n=function(n,e){const r=t.H.m,i=n.length;let s,o,u,c;const h=r.j;for(var a=0;a<=e;a++)h[a]=0;for(a=1;a<i;a+=2)h[n[a]]++;const l=r.K;for(s=0,h[0]=0,o=1;o<=e;o++)s=s+h[o-1]<<1,l[o]=s;for(u=0;u<i;u+=2)c=n[u+1],0!=c&&(n[u]=l[c],l[c]++)},t.H.A=function(n,e,r){const i=n.length,s=t.H.m.r;for(let t=0;t<i;t+=2)if(0!=n[t+1]){const i=n[t+1],o=t>>1<<4|i,u=e-i;let c=n[t]<<u;const h=c+(1<<u);for(;c!=h;)r[s[c]>>>15-e]=o,c++}},t.H.l=function(n,e){const r=t.H.m.r,i=15-e;for(let t=0;t<n.length;t+=2)n[t]=r[n[t]<<e-n[t+1]]>>>i},t.H.M=function(t,n,e){const r=n>>>3;t[r]|=e<<=7&n,t[r+1]|=e>>>8},t.H.I=function(t,n,e){const r=n>>>3;t[r]|=e<<=7&n,t[r+1]|=e>>>8,t[r+2]|=e>>>16},t.H.e=function(t,n,e){return(t[n>>>3]|t[1+(n>>>3)]<<8)>>>(7&n)&(1<<e)-1},t.H.b=function(t,n,e){return(t[n>>>3]|t[1+(n>>>3)]<<8|t[2+(n>>>3)]<<16)>>>(7&n)&(1<<e)-1},t.H.Z=function(t,n){return(t[n>>>3]|t[1+(n>>>3)]<<8|t[2+(n>>>3)]<<16)>>>(7&n)},t.H.i=function(t,n){return(t[n>>>3]|t[1+(n>>>3)]<<8|t[2+(n>>>3)]<<16|t[3+(n>>>3)]<<24)>>>(7&n)},t.H.m=function(){const t=Uint16Array,n=Uint32Array;return{K:new t(16),j:new t(16),X:[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],S:[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,999,999,999],T:[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0],q:new t(32),p:[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,65535,65535],z:[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0],c:new n(32),J:new t(512),_:[],h:new t(32),$:[],w:new t(32768),C:[],v:[],d:new t(32768),D:[],u:new t(512),Q:[],r:new t(32768),s:new n(286),Y:new n(30),a:new n(19),t:new n(15e3),k:new t(65536),g:new t(32768)}}(),function(){const n=t.H.m;for(var e=0;e<32768;e++){let t=e;t=(2863311530&t)>>>1|(1431655765&t)<<1,t=(3435973836&t)>>>2|(858993459&t)<<2,t=(4042322160&t)>>>4|(252645135&t)<<4,t=(4278255360&t)>>>8|(16711935&t)<<8,n.r[e]=(t>>>16|t<<16)>>>17}function r(t,n,e){for(;0!=n--;)t.push(0,e)}for(e=0;e<32;e++)n.q[e]=n.S[e]<<3|n.T[e],n.c[e]=n.p[e]<<4|n.z[e];r(n._,144,8),r(n._,112,9),r(n._,24,7),r(n._,8,8),t.H.n(n._,9),t.H.A(n._,9,n.J),t.H.l(n._,9),r(n.$,32,5),t.H.n(n.$,5),t.H.A(n.$,5,n.h),t.H.l(n.$,5),r(n.Q,19,0),r(n.C,286,0),r(n.D,30,0),r(n.v,320,0)}(),t.H.N}();function s(t){return[1,null,3,1,2,null,4][t.ctype]*t.depth}function o(t,n,e,r,i){let o=s(n);const c=Math.ceil(r*o/8);let h,a;o=Math.ceil(o/8);let l=t[e],f=0;if(l>1&&(t[e]=[0,0,1][l-2]),3==l)for(f=o;f<c;f++)t[f+1]=t[f+1]+(t[f+1-o]>>>1)&255;for(let n=0;n<i;n++)if(h=e+n*c,a=h+n+1,l=t[a-1],f=0,0==l)for(;f<c;f++)t[h+f]=t[a+f];else if(1==l){for(;f<o;f++)t[h+f]=t[a+f];for(;f<c;f++)t[h+f]=t[a+f]+t[h+f-o]}else if(2==l)for(;f<c;f++)t[h+f]=t[a+f]+t[h+f-c];else if(3==l){for(;f<o;f++)t[h+f]=t[a+f]+(t[h+f-c]>>>1);for(;f<c;f++)t[h+f]=t[a+f]+(t[h+f-c]+t[h+f-o]>>>1)}else{for(;f<o;f++)t[h+f]=t[a+f]+u(0,t[h+f-c],0);for(;f<c;f++)t[h+f]=t[a+f]+u(t[h+f-o],t[h+f-c],t[h+f-o-c])}return t}function u(t,n,e){const r=t+n-e,i=r-t,s=r-n,o=r-e;return i*i<=s*s&&i*i<=o*o?t:s*s<=o*o?n:e}function c(n,e,r){r.width=t.readUint(n,e),r.height=t.readUint(n,e+=4),r.depth=n[e+=4],e++,r.ctype=n[e],e++,r.compress=n[e],e++,r.filter=n[e],e++,r.interlace=n[e],e++}function h(t,n,e,r,i,s,o,u,c){const h=Math.min(n,i),a=Math.min(e,s);let l=0,f=0;for(let e=0;e<a;e++)for(let s=0;s<h;s++)if(o>=0&&u>=0?(l=e*n+s<<2,f=(u+e)*i+o+s<<2):(l=(-u+e)*n-o+s<<2,f=e*i+s<<2),0==c)r[f]=t[l],r[f+1]=t[l+1],r[f+2]=t[l+2],r[f+3]=t[l+3];else if(1==c){var d=t[l+3]*(1/255),v=t[l]*d,p=t[l+1]*d,w=t[l+2]*d,y=r[f+3]*(1/255),g=r[f]*y,b=r[f+1]*y,m=r[f+2]*y;const n=1-d,e=d+y*n,i=0==e?0:1/e;r[f+3]=255*e,r[f+0]=(v+g*n)*i,r[f+1]=(p+b*n)*i,r[f+2]=(w+m*n)*i}else if(2==c)v=t[l],p=t[l+1],w=t[l+2],g=r[f],b=r[f+1],m=r[f+2],(d=t[l+3])==(y=r[f+3])&&v==g&&p==b&&w==m?(r[f]=0,r[f+1]=0,r[f+2]=0,r[f+3]=0):(r[f]=v,r[f+1]=p,r[f+2]=w,r[f+3]=d);else if(3==c){if(v=t[l],p=t[l+1],w=t[l+2],g=r[f],b=r[f+1],m=r[f+2],(d=t[l+3])==(y=r[f+3])&&v==g&&p==b&&w==m)continue;if(d<220&&y>20)return!1}return!0}return{decode:function(n){const s=new Uint8Array(n);let o=8;const u=t,h=u.readUshort,a=u.readUint,l={tabs:{},frames:[]},f=new Uint8Array(s.length);let d,v=0,p=0;const w=[137,80,78,71,13,10,26,10];for(var y=0;y<8;y++)if(s[y]!=w[y])throw"The input is not a PNG file!";for(;o<s.length;){const t=u.readUint(s,o);o+=4;const n=u.readASCII(s,o,4);if(o+=4,"IHDR"==n)c(s,o,l);else if("iCCP"==n){for(var g=o;0!=s[g];)g++;u.readASCII(s,o,g-o);const e=s.slice(g+2,o+t);let c=null;try{c=r(e)}catch(t){c=i(e)}l.tabs[n]=c}else if("CgBI"==n)l.tabs[n]=s.slice(o,o+4);else if("IDAT"==n){for(y=0;y<t;y++)f[v+y]=s[o+y];v+=t}else if("acTL"==n)l.tabs[n]={num_frames:a(s,o),num_plays:a(s,o+4)},d=new Uint8Array(s.length);else if("fcTL"==n){0!=p&&((M=l.frames[l.frames.length-1]).data=e(l,d.slice(0,p),M.rect.width,M.rect.height),p=0);const t={x:a(s,o+12),y:a(s,o+16),width:a(s,o+4),height:a(s,o+8)};let n=h(s,o+22);n=h(s,o+20)/(0==n?100:n);const r={rect:t,delay:Math.round(1e3*n),dispose:s[o+24],blend:s[o+25]};l.frames.push(r)}else if("fdAT"==n){for(y=0;y<t-4;y++)d[p+y]=s[o+y+4];p+=t-4}else if("pHYs"==n)l.tabs[n]=[u.readUint(s,o),u.readUint(s,o+4),s[o+8]];else if("cHRM"==n)for(l.tabs[n]=[],y=0;y<8;y++)l.tabs[n].push(u.readUint(s,o+4*y));else if("tEXt"==n||"zTXt"==n){null==l.tabs[n]&&(l.tabs[n]={});var b=u.nextZero(s,o),m=u.readASCII(s,o,b-o),A=o+t-b-1;if("tEXt"==n)x=u.readASCII(s,b+1,A);else{var k=r(s.slice(b+2,b+2+A));x=u.readUTF8(k,0,k.length)}l.tabs[n][m]=x}else if("iTXt"==n){null==l.tabs[n]&&(l.tabs[n]={}),b=0,b=u.nextZero(s,g=o),m=u.readASCII(s,g,b-g);const e=s[g=b+1];var x;b=u.nextZero(s,g+=2),u.readASCII(s,g,b-g),b=u.nextZero(s,g=b+1),u.readUTF8(s,g,b-g),A=t-((g=b+1)-o),0==e?x=u.readUTF8(s,g,A):(k=r(s.slice(g,g+A)),x=u.readUTF8(k,0,k.length)),l.tabs[n][m]=x}else if("PLTE"==n)l.tabs[n]=u.readBytes(s,o,t);else if("hIST"==n){const t=l.tabs.PLTE.length/3;for(l.tabs[n]=[],y=0;y<t;y++)l.tabs[n].push(h(s,o+2*y))}else if("tRNS"==n)3==l.ctype?l.tabs[n]=u.readBytes(s,o,t):0==l.ctype?l.tabs[n]=h(s,o):2==l.ctype&&(l.tabs[n]=[h(s,o),h(s,o+2),h(s,o+4)]);else if("gAMA"==n)l.tabs[n]=u.readUint(s,o)/1e5;else if("sRGB"==n)l.tabs[n]=s[o];else if("bKGD"==n)0==l.ctype||4==l.ctype?l.tabs[n]=[h(s,o)]:2==l.ctype||6==l.ctype?l.tabs[n]=[h(s,o),h(s,o+2),h(s,o+4)]:3==l.ctype&&(l.tabs[n]=s[o]);else if("IEND"==n)break;o+=t,u.readUint(s,o),o+=4}var M;return 0!=p&&((M=l.frames[l.frames.length-1]).data=e(l,d.slice(0,p),M.rect.width,M.rect.height)),l.data=e(l,f,l.width,l.height),delete l.compress,delete l.interlace,delete l.filter,l},toRGBA8:function(t){const e=t.width,r=t.height;if(null==t.tabs.acTL)return[n(t.data,e,r,t).buffer];const i=[];null==t.frames[0].data&&(t.frames[0].data=t.data);const s=e*r*4,o=new Uint8Array(s),u=new Uint8Array(s),c=new Uint8Array(s);for(let l=0;l<t.frames.length;l++){const f=t.frames[l],d=f.rect.x,v=f.rect.y,p=f.rect.width,w=f.rect.height,y=n(f.data,p,w,t);if(0!=l)for(var a=0;a<s;a++)c[a]=o[a];if(0==f.blend?h(y,p,w,o,e,r,d,v,0):1==f.blend&&h(y,p,w,o,e,r,d,v,1),i.push(o.buffer.slice(0)),0==f.dispose);else if(1==f.dispose)h(u,p,w,o,e,r,d,v,0);else if(2==f.dispose)for(a=0;a<s;a++)o[a]=c[a]}return i},_paeth:u,_copyTile:h,_bin:t}}();!function(){const{_copyTile:t}=F,{_bin:n}=F,e=F._paeth;var r={table:function(){const t=new Uint32Array(256);for(let n=0;n<256;n++){let e=n;for(let t=0;t<8;t++)1&e?e=3988292384^e>>>1:e>>>=1;t[n]=e}return t}(),update(t,n,e,i){for(let s=0;s<i;s++)t=r.table[255&(t^n[e+s])]^t>>>8;return t},crc:(t,n,e)=>4294967295^r.update(4294967295,t,n,e)};function i(t,n,e,r){n[e]+=t[0]*r>>4,n[e+1]+=t[1]*r>>4,n[e+2]+=t[2]*r>>4,n[e+3]+=t[3]*r>>4}function s(t){return Math.max(0,Math.min(255,t))}function o(t,n){const e=t[0]-n[0],r=t[1]-n[1],i=t[2]-n[2],s=t[3]-n[3];return e*e+r*r+i*i+s*s}function u(t,n,e,r,u,c,h){null==h&&(h=1);const a=r.length,l=[];for(var f=0;f<a;f++){const t=r[f];l.push([t>>>0&255,t>>>8&255,t>>>16&255,t>>>24&255])}for(f=0;f<a;f++){let t=4294967295;for(var d=0,v=0;v<a;v++){var p=o(l[f],l[v]);v!=f&&p<t&&(t=p,d=v)}}const w=new Uint32Array(u.buffer),y=new Int16Array(n*e*4),g=[0,8,2,10,12,4,14,6,3,11,1,9,15,7,13,5];for(f=0;f<g.length;f++)g[f]=255*((g[f]+.5)/16-.5);for(let u=0;u<e;u++)for(let m=0;m<n;m++){var b;f=4*(u*n+m),b=2!=h?[s(t[f]+y[f]),s(t[f+1]+y[f+1]),s(t[f+2]+y[f+2]),s(t[f+3]+y[f+3])]:[s(t[f]+(p=g[4*(3&u)+(3&m)])),s(t[f+1]+p),s(t[f+2]+p),s(t[f+3]+p)],d=0;let A=16777215;for(v=0;v<a;v++){const t=o(b,l[v]);t<A&&(A=t,d=v)}const k=l[d],x=[b[0]-k[0],b[1]-k[1],b[2]-k[2],b[3]-k[3]];1==h&&(m!=n-1&&i(x,y,f+4,7),u!=e-1&&(0!=m&&i(x,y,f+4*n-4,3),i(x,y,f+4*n,5),m!=n-1&&i(x,y,f+4*n+4,1))),c[f>>2]=d,w[f>>2]=r[d]}}function c(t,e,i,s,o){null==o&&(o={});const{crc:u}=r,c=n.writeUint,h=n.writeUshort,a=n.writeASCII;let l=8;const f=t.frames.length>1;let d,v=!1,p=33+(f?20:0);if(null!=o.sRGB&&(p+=13),null!=o.pHYs&&(p+=21),null!=o.iCCP&&(d=pako.deflate(o.iCCP),p+=21+d.length+4),3==t.ctype){for(var w=t.plte.length,y=0;y<w;y++)t.plte[y]>>>24!=255&&(v=!0);p+=8+3*w+4+(v?8+1*w+4:0)}for(var g=0;g<t.frames.length;g++)f&&(p+=38),p+=(k=t.frames[g]).cimg.length+12,0!=g&&(p+=4);p+=12;const b=new Uint8Array(p),m=[137,80,78,71,13,10,26,10];for(y=0;y<8;y++)b[y]=m[y];if(c(b,l,13),l+=4,a(b,l,"IHDR"),l+=4,c(b,l,e),l+=4,c(b,l,i),l+=4,b[l]=t.depth,l++,b[l]=t.ctype,l++,b[l]=0,l++,b[l]=0,l++,b[l]=0,l++,c(b,l,u(b,l-17,17)),l+=4,null!=o.sRGB&&(c(b,l,1),l+=4,a(b,l,"sRGB"),l+=4,b[l]=o.sRGB,l++,c(b,l,u(b,l-5,5)),l+=4),null!=o.iCCP){const t=13+d.length;c(b,l,t),l+=4,a(b,l,"iCCP"),l+=4,a(b,l,"ICC profile"),l+=11,l+=2,b.set(d,l),l+=d.length,c(b,l,u(b,l-(t+4),t+4)),l+=4}if(null!=o.pHYs&&(c(b,l,9),l+=4,a(b,l,"pHYs"),l+=4,c(b,l,o.pHYs[0]),l+=4,c(b,l,o.pHYs[1]),l+=4,b[l]=o.pHYs[2],l++,c(b,l,u(b,l-13,13)),l+=4),f&&(c(b,l,8),l+=4,a(b,l,"acTL"),l+=4,c(b,l,t.frames.length),l+=4,c(b,l,null!=o.loop?o.loop:0),l+=4,c(b,l,u(b,l-12,12)),l+=4),3==t.ctype){for(c(b,l,3*(w=t.plte.length)),l+=4,a(b,l,"PLTE"),l+=4,y=0;y<w;y++){const n=3*y,e=t.plte[y],r=e>>>8&255,i=e>>>16&255;b[l+n+0]=255&e,b[l+n+1]=r,b[l+n+2]=i}if(l+=3*w,c(b,l,u(b,l-3*w-4,3*w+4)),l+=4,v){for(c(b,l,w),l+=4,a(b,l,"tRNS"),l+=4,y=0;y<w;y++)b[l+y]=t.plte[y]>>>24&255;l+=w,c(b,l,u(b,l-w-4,w+4)),l+=4}}let A=0;for(g=0;g<t.frames.length;g++){var k=t.frames[g];f&&(c(b,l,26),l+=4,a(b,l,"fcTL"),l+=4,c(b,l,A++),l+=4,c(b,l,k.rect.width),l+=4,c(b,l,k.rect.height),l+=4,c(b,l,k.rect.x),l+=4,c(b,l,k.rect.y),l+=4,h(b,l,s[g]),l+=2,h(b,l,1e3),l+=2,b[l]=k.dispose,l++,b[l]=k.blend,l++,c(b,l,u(b,l-30,30)),l+=4);const n=k.cimg;c(b,l,(w=n.length)+(0==g?0:4)),l+=4;const e=l;a(b,l,0==g?"IDAT":"fdAT"),l+=4,0!=g&&(c(b,l,A++),l+=4),b.set(n,l),l+=w,c(b,l,u(b,e,l-e)),l+=4}return c(b,l,0),l+=4,a(b,l,"IEND"),l+=4,c(b,l,u(b,l-4,4)),l+=4,b.buffer}function h(t,n,e){for(let r=0;r<t.frames.length;r++){const i=t.frames[r],s=i.rect.height,o=new Uint8Array(s*i.bpl+s);i.cimg=d(i.img,s,i.bpp,i.bpl,o,n,e)}}function a(n,e,r,i,s){const o=s[0],c=s[1],h=s[2],a=s[3],d=s[4],v=s[5];let w=6,y=8,g=255;for(var b=0;b<n.length;b++){const t=new Uint8Array(n[b]);for(var m=t.length,A=0;A<m;A+=4)g&=t[A+3]}const k=255!=g,x=function(n,e,r,i,s,o){const u=[];for(var c=0;c<n.length;c++){const l=new Uint8Array(n[c]),d=new Uint32Array(l.buffer);var h;let p=0,w=0,y=e,g=r,b=i?1:0;if(0!=c){const m=o||i||1==c||0!=u[c-2].dispose?1:2;let A=0,k=1e9;for(let t=0;t<m;t++){var a=new Uint8Array(n[c-1-t]);const i=new Uint32Array(n[c-1-t]);let o=e,u=r,h=-1,l=-1;for(let t=0;t<r;t++)for(let n=0;n<e;n++)d[v=t*e+n]!=i[v]&&(n<o&&(o=n),n>h&&(h=n),t<u&&(u=t),t>l&&(l=t));-1==h&&(o=u=h=l=0),s&&(!(1&~o)&&o--,!(1&~u)&&u--);const f=(h-o+1)*(l-u+1);f<k&&(k=f,A=t,p=o,w=u,y=h-o+1,g=l-u+1)}a=new Uint8Array(n[c-1-A]),1==A&&(u[c-1].dispose=2),h=new Uint8Array(y*g*4),t(a,e,r,h,y,g,-p,-w,0),b=t(l,e,r,h,y,g,-p,-w,3)?1:0,1==b?f(l,e,r,h,{x:p,y:w,width:y,height:g}):t(l,e,r,h,y,g,-p,-w,0)}else h=l.slice(0);u.push({rect:{x:p,y:w,width:y,height:g},img:h,blend:b,dispose:0})}if(i)for(c=0;c<u.length;c++){if(1==(p=u[c]).blend)continue;const t=p.rect,i=u[c-1].rect,o=Math.min(t.x,i.x),h=Math.min(t.y,i.y),a={x:o,y:h,width:Math.max(t.x+t.width,i.x+i.width)-o,height:Math.max(t.y+t.height,i.y+i.height)-h};u[c-1].dispose=1,c-1!=0&&l(n,e,r,u,c-1,a,s),l(n,e,r,u,c,a,s)}let d=0;if(1!=n.length)for(var v=0;v<u.length;v++){var p;d+=(p=u[v]).rect.width*p.rect.height}return u}(n,e,r,o,c,h),M={},S=[],C=[];if(0!=i){const t=[];for(A=0;A<x.length;A++)t.push(x[A].img.buffer);const n=function(t){let n=0;for(var e=0;e<t.length;e++)n+=t[e].byteLength;const r=new Uint8Array(n);let i=0;for(e=0;e<t.length;e++){const n=new Uint8Array(t[e]),s=n.length;for(let t=0;t<s;t+=4){let e=n[t],s=n[t+1],o=n[t+2];const u=n[t+3];0==u&&(e=s=o=0),r[i+t]=e,r[i+t+1]=s,r[i+t+2]=o,r[i+t+3]=u}i+=s}return r.buffer}(t),e=p(n,i);for(A=0;A<e.plte.length;A++)S.push(e.plte[A].est.rgba);let r=0;for(A=0;A<x.length;A++){const t=(E=x[A]).img.length;var U=new Uint8Array(e.inds.buffer,r>>2,t>>2);C.push(U);const n=new Uint8Array(e.abuf,r,t);v&&u(E.img,E.rect.width,E.rect.height,S,n,U),E.img.set(n),r+=t}}else for(b=0;b<x.length;b++){var E=x[b];const t=new Uint32Array(E.img.buffer);var j=E.rect.width;for(m=t.length,U=new Uint8Array(m),C.push(U),A=0;A<m;A++){const n=t[A];if(0!=A&&n==t[A-1])U[A]=U[A-1];else if(A>j&&n==t[A-j])U[A]=U[A-j];else{let t=M[n];if(null==t&&(M[n]=t=S.length,S.push(n),S.length>=300))break;U[A]=t}}}const T=S.length;for(T<=256&&0==d&&(y=T<=2?1:T<=4?2:T<=16?4:8,y=Math.max(y,a)),b=0;b<x.length;b++){const t=(E=x[b]).rect.height;let n=E.img,e=4*(j=E.rect.width),r=4;if(T<=256&&0==d){e=Math.ceil(y*j/8);var I=new Uint8Array(e*t);const i=C[b];for(let n=0;n<t;n++){A=n*e;const t=n*j;if(8==y)for(var O=0;O<j;O++)I[A+O]=i[t+O];else if(4==y)for(O=0;O<j;O++)I[A+(O>>1)]|=i[t+O]<<4-4*(1&O);else if(2==y)for(O=0;O<j;O++)I[A+(O>>2)]|=i[t+O]<<6-2*(3&O);else if(1==y)for(O=0;O<j;O++)I[A+(O>>3)]|=i[t+O]<<7-1*(7&O)}n=I,w=3,r=1}else if(0==k&&1==x.length){I=new Uint8Array(j*t*3);const i=j*t;for(A=0;A<i;A++){const t=3*A,e=4*A;I[t]=n[e],I[t+1]=n[e+1],I[t+2]=n[e+2]}n=I,w=2,r=3,e=3*j}E.img=n,E.bpl=e,E.bpp=r}return{ctype:w,depth:y,plte:S,frames:x}}function l(n,e,r,i,s,o,u){const c=Uint8Array,h=Uint32Array,a=new c(n[s-1]),l=new h(n[s-1]),d=s+1<n.length?new c(n[s+1]):null,v=new c(n[s]),p=new h(v.buffer);let w=e,y=r,g=-1,b=-1;for(let t=0;t<o.height;t++)for(let n=0;n<o.width;n++){const r=o.x+n,u=o.y+t,c=u*e+r,h=p[c];0==h||0==i[s-1].dispose&&l[c]==h&&(null==d||0!=d[4*c+3])||(r<w&&(w=r),r>g&&(g=r),u<y&&(y=u),u>b&&(b=u))}-1==g&&(w=y=g=b=0),u&&(!(1&~w)&&w--,!(1&~y)&&y--);const m=i[s];m.rect=o={x:w,y,width:g-w+1,height:b-y+1},m.blend=1,m.img=new Uint8Array(o.width*o.height*4),0==i[s-1].dispose?(t(a,e,r,m.img,o.width,o.height,-o.x,-o.y,0),f(v,e,r,m.img,o)):t(v,e,r,m.img,o.width,o.height,-o.x,-o.y,0)}function f(n,e,r,i,s){t(n,e,r,i,s.width,s.height,-s.x,-s.y,2)}function d(t,n,e,r,i,s,o){const u=[];let c,h=[0,1,2,3,4];-1!=s?h=[s]:(n*r>5e5||1==e)&&(h=[0]),o&&(c={level:0});const a=L;for(var l=0;l<h.length;l++){for(let s=0;s<n;s++)v(i,t,s,r,e,h[l]);u.push(a.deflate(i,c))}let f,d=1e9;for(l=0;l<u.length;l++)u[l].length<d&&(f=l,d=u[l].length);return u[f]}function v(t,n,r,i,s,o){const u=r*i;let c=u+r;if(t[c]=o,c++,0==o)if(i<500)for(var h=0;h<i;h++)t[c+h]=n[u+h];else t.set(new Uint8Array(n.buffer,u,i),c);else if(1==o){for(h=0;h<s;h++)t[c+h]=n[u+h];for(h=s;h<i;h++)t[c+h]=n[u+h]-n[u+h-s]+256&255}else if(0==r){for(h=0;h<s;h++)t[c+h]=n[u+h];if(2==o)for(h=s;h<i;h++)t[c+h]=n[u+h];if(3==o)for(h=s;h<i;h++)t[c+h]=n[u+h]-(n[u+h-s]>>1)+256&255;if(4==o)for(h=s;h<i;h++)t[c+h]=n[u+h]-e(n[u+h-s],0,0)+256&255}else{if(2==o)for(h=0;h<i;h++)t[c+h]=n[u+h]+256-n[u+h-i]&255;if(3==o){for(h=0;h<s;h++)t[c+h]=n[u+h]+256-(n[u+h-i]>>1)&255;for(h=s;h<i;h++)t[c+h]=n[u+h]+256-(n[u+h-i]+n[u+h-s]>>1)&255}if(4==o){for(h=0;h<s;h++)t[c+h]=n[u+h]+256-e(0,n[u+h-i],0)&255;for(h=s;h<i;h++)t[c+h]=n[u+h]+256-e(n[u+h-s],n[u+h-i],n[u+h-s-i])&255}}}function p(t,n){const e=new Uint8Array(t),r=e.slice(0),i=new Uint32Array(r.buffer),s=w(r,n),o=s[0],u=s[1],c=e.length,h=new Uint8Array(c>>2);let a;if(e.length<2e7)for(var l=0;l<c;l+=4)a=y(o,f=e[l]*(1/255),d=e[l+1]*(1/255),v=e[l+2]*(1/255),p=e[l+3]*(1/255)),h[l>>2]=a.ind,i[l>>2]=a.est.rgba;else for(l=0;l<c;l+=4){var f=e[l]*(1/255),d=e[l+1]*(1/255),v=e[l+2]*(1/255),p=e[l+3]*(1/255);for(a=o;a.left;)a=g(a.est,f,d,v,p)<=0?a.left:a.right;h[l>>2]=a.ind,i[l>>2]=a.est.rgba}return{abuf:r.buffer,inds:h,plte:u}}function w(t,n,e){null==e&&(e=1e-4);const r=new Uint32Array(t.buffer),i={i0:0,i1:t.length,bst:null,est:null,tdst:0,left:null,right:null};i.bst=A(t,i.i0,i.i1),i.est=k(i.bst);const s=[i];for(;s.length<n;){let n=0,i=0;for(var o=0;o<s.length;o++)s[o].est.L>n&&(n=s[o].est.L,i=o);if(n<e)break;const u=s[i],c=b(t,r,u.i0,u.i1,u.est.e,u.est.eMq255);if(u.i0>=c||u.i1<=c){u.est.L=0;continue}const h={i0:u.i0,i1:c,bst:null,est:null,tdst:0,left:null,right:null};h.bst=A(t,h.i0,h.i1),h.est=k(h.bst);const a={i0:c,i1:u.i1,bst:null,est:null,tdst:0,left:null,right:null};for(a.bst={R:[],m:[],N:u.bst.N-h.bst.N},o=0;o<16;o++)a.bst.R[o]=u.bst.R[o]-h.bst.R[o];for(o=0;o<4;o++)a.bst.m[o]=u.bst.m[o]-h.bst.m[o];a.est=k(a.bst),u.left=h,u.right=a,s[i]=h,s.push(a)}for(s.sort(((t,n)=>n.bst.N-t.bst.N)),o=0;o<s.length;o++)s[o].ind=o;return[i,s]}function y(t,n,e,r,i){if(null==t.left)return t.tdst=function(t,n,e,r,i){const s=n-t[0],o=e-t[1],u=r-t[2],c=i-t[3];return s*s+o*o+u*u+c*c}(t.est.q,n,e,r,i),t;const s=g(t.est,n,e,r,i);let o=t.left,u=t.right;s>0&&(o=t.right,u=t.left);const c=y(o,n,e,r,i);if(c.tdst<=s*s)return c;const h=y(u,n,e,r,i);return h.tdst<c.tdst?h:c}function g(t,n,e,r,i){const{e:s}=t;return s[0]*n+s[1]*e+s[2]*r+s[3]*i-t.eMq}function b(t,n,e,r,i,s){for(r-=4;e<r;){for(;m(t,e,i)<=s;)e+=4;for(;m(t,r,i)>s;)r-=4;if(e>=r)break;const o=n[e>>2];n[e>>2]=n[r>>2],n[r>>2]=o,e+=4,r-=4}for(;m(t,e,i)>s;)e-=4;return e+4}function m(t,n,e){return t[n]*e[0]+t[n+1]*e[1]+t[n+2]*e[2]+t[n+3]*e[3]}function A(t,n,e){const r=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],i=[0,0,0,0],s=e-n>>2;for(let s=n;s<e;s+=4){const n=t[s]*(1/255),e=t[s+1]*(1/255),o=t[s+2]*(1/255),u=t[s+3]*(1/255);i[0]+=n,i[1]+=e,i[2]+=o,i[3]+=u,r[0]+=n*n,r[1]+=n*e,r[2]+=n*o,r[3]+=n*u,r[5]+=e*e,r[6]+=e*o,r[7]+=e*u,r[10]+=o*o,r[11]+=o*u,r[15]+=u*u}return r[4]=r[1],r[8]=r[2],r[9]=r[6],r[12]=r[3],r[13]=r[7],r[14]=r[11],{R:r,m:i,N:s}}function k(t){const{R:n}=t,{m:e}=t,{N:r}=t,i=e[0],s=e[1],o=e[2],u=e[3],c=0==r?0:1/r,h=[n[0]-i*i*c,n[1]-i*s*c,n[2]-i*o*c,n[3]-i*u*c,n[4]-s*i*c,n[5]-s*s*c,n[6]-s*o*c,n[7]-s*u*c,n[8]-o*i*c,n[9]-o*s*c,n[10]-o*o*c,n[11]-o*u*c,n[12]-u*i*c,n[13]-u*s*c,n[14]-u*o*c,n[15]-u*u*c],a=h,l=x;let f=[Math.random(),Math.random(),Math.random(),Math.random()],d=0,v=0;if(0!=r)for(let t=0;t<16&&(f=l.multVec(a,f),v=Math.sqrt(l.dot(f,f)),f=l.sml(1/v,f),!(0!=t&&Math.abs(v-d)<1e-9));t++)d=v;const p=[i*c,s*c,o*c,u*c];return{Cov:h,q:p,e:f,L:d,eMq255:l.dot(l.sml(255,p),f),eMq:l.dot(f,p),rgba:(Math.round(255*p[3])<<24|Math.round(255*p[2])<<16|Math.round(255*p[1])<<8|Math.round(255*p[0]))>>>0}}var x={multVec:(t,n)=>[t[0]*n[0]+t[1]*n[1]+t[2]*n[2]+t[3]*n[3],t[4]*n[0]+t[5]*n[1]+t[6]*n[2]+t[7]*n[3],t[8]*n[0]+t[9]*n[1]+t[10]*n[2]+t[11]*n[3],t[12]*n[0]+t[13]*n[1]+t[14]*n[2]+t[15]*n[3]],dot:(t,n)=>t[0]*n[0]+t[1]*n[1]+t[2]*n[2]+t[3]*n[3],sml:(t,n)=>[t*n[0],t*n[1],t*n[2],t*n[3]]};F.encode=function(t,n,e,r,i,s,o){null==r&&(r=0),null==o&&(o=!1);const u=a(t,n,e,r,[!1,!1,!1,0,o,!1]);return h(u,-1),c(u,n,e,i,s)},F.encodeLL=function(t,n,e,r,i,s,o,u){const a={ctype:0+(1==r?0:2)+(0==i?0:4),depth:s,frames:[]},l=(r+i)*s,f=l*n;for(let r=0;r<t.length;r++)a.frames.push({rect:{x:0,y:0,width:n,height:e},img:new Uint8Array(t[r]),blend:0,dispose:1,bpp:Math.ceil(l/8),bpl:Math.ceil(f/8)});return h(a,0,!0),c(a,n,e,o,u)},F.encode.compress=a,F.encode.dither=u,F.quantize=p,F.quantize.getKDtree=w,F.quantize.getNearest=y}();const N={toArrayBuffer(t,n){const e=t.width,r=t.height,i=e<<2,s=t.getContext("2d").getImageData(0,0,e,r),o=new Uint32Array(s.data.buffer),u=(32*e+31)/32<<2,c=u*r,h=122+c,a=new ArrayBuffer(h),l=new DataView(a),f=1<<20;let d,v,p,w,y=f,g=0,b=0,m=0;function A(t){l.setUint16(b,t,!0),b+=2}function k(t){l.setUint32(b,t,!0),b+=4}function x(t){b+=t}A(19778),k(h),x(4),k(122),k(108),k(e),k(-r>>>0),A(1),A(32),k(3),k(c),k(2835),k(2835),x(8),k(16711680),k(65280),k(255),k(4278190080),k(1466527264),function t(){for(;g<r&&y>0;){for(w=122+g*u,d=0;d<i;)y--,v=o[m++],p=v>>>24,l.setUint32(w+d,v<<8|p),d+=4;g++}m<o.length?(y=f,setTimeout(t,N._dly)):n(a)}()},toBlob(t,n){this.toArrayBuffer(t,(t=>{n(new Blob([t],{type:"image/bmp"}))}))},_dly:9};var K={CHROME:"CHROME",FIREFOX:"FIREFOX",DESKTOP_SAFARI:"DESKTOP_SAFARI",IE:"IE",IOS:"IOS",ETC:"ETC"},Q={[K.CHROME]:16384,[K.FIREFOX]:11180,[K.DESKTOP_SAFARI]:16384,[K.IE]:8192,[K.IOS]:4096,[K.ETC]:8192};const Y="undefined"!=typeof window,H="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope,V=Y&&window.cordova&&window.cordova.require&&window.cordova.require("cordova/modulemapper"),X=(Y||H)&&(V&&V.getOriginalSymbol(window,"File")||"undefined"!=typeof File&&File),q=(Y||H)&&(V&&V.getOriginalSymbol(window,"FileReader")||"undefined"!=typeof FileReader&&FileReader);function G(t,n,e=Date.now()){return new Promise((r=>{const i=t.split(","),s=i[0].match(/:(.*?);/)[1],o=globalThis.atob(i[1]);let u=o.length;const c=new Uint8Array(u);for(;u--;)c[u]=o.charCodeAt(u);const h=new Blob([c],{type:s});h.name=n,h.lastModified=e,r(h)}))}function J(t){return new Promise(((n,e)=>{const r=new q;r.onload=()=>n(r.result),r.onerror=t=>e(t),r.readAsDataURL(t)}))}function Z(t){return new Promise(((n,e)=>{const r=new Image;r.onload=()=>n(r),r.onerror=t=>e(t),r.src=t}))}function tt(){if(void 0!==tt.cachedResult)return tt.cachedResult;let t=K.ETC;const{userAgent:n}=navigator;return/Chrom(e|ium)/i.test(n)?t=K.CHROME:/iP(ad|od|hone)/i.test(n)&&/WebKit/i.test(n)?t=K.IOS:/Safari/i.test(n)?t=K.DESKTOP_SAFARI:/Firefox/i.test(n)?t=K.FIREFOX:(/MSIE/i.test(n)||1==!!document.documentMode)&&(t=K.IE),tt.cachedResult=t}function nt(t,n){const e=tt(),r=Q[e];let i=t,s=n,o=i*s;const u=i>s?s/i:i/s;for(;o>r*r;){const t=(r+i)/2,n=(r+s)/2;t<n?(s=n,i=n*u):(s=t*u,i=t),o=i*s}return{width:i,height:s}}function et(t,n){let e,r;try{if(e=new OffscreenCanvas(t,n),r=e.getContext("2d"),null===r)throw new Error("getContext of OffscreenCanvas returns null")}catch(t){e=document.createElement("canvas"),r=e.getContext("2d")}return e.width=t,e.height=n,[e,r]}function rt(t,n){const{width:e,height:r}=nt(t.width,t.height),[i,s]=et(e,r);return n&&/jpe?g/.test(n)&&(s.fillStyle="white",s.fillRect(0,0,i.width,i.height)),s.drawImage(t,0,0,i.width,i.height),i}function it(){return void 0!==it.cachedResult||(it.cachedResult=["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"undefined"!=typeof document&&"ontouchend"in document),it.cachedResult}function st(t,n={}){return new Promise((function(e,r){let i,s;var o=function(){try{return s=rt(i,n.fileType||t.type),e([i,s])}catch(t){return r(t)}},u=function(){try{var n=function(t){try{throw t}catch(t){return r(t)}};try{let e;return J(t).then((function(t){try{return e=t,Z(e).then((function(t){try{return i=t,function(){try{return o()}catch(t){return r(t)}}()}catch(t){return n(t)}}),n)}catch(t){return n(t)}}),n)}catch(t){n(t)}}catch(t){return r(t)}};try{if(it()||[K.DESKTOP_SAFARI,K.MOBILE_SAFARI].includes(tt()))throw new Error("Skip createImageBitmap on IOS and Safari");return createImageBitmap(t).then((function(t){try{return i=t,o()}catch(t){return u()}}),u)}catch(t){u()}}))}function ot(t,n,e,r,i=1){return new Promise((function(s,o){let u;if("image/png"===n){let h,a,l;return h=t.getContext("2d"),({data:a}=h.getImageData(0,0,t.width,t.height)),l=F.encode([a.buffer],t.width,t.height,4096*i),u=new Blob([l],{type:n}),u.name=e,u.lastModified=r,c.call(this)}{if("image/bmp"===n)return new Promise((n=>N.toBlob(t,n))).then(function(t){try{return u=t,u.name=e,u.lastModified=r,f.call(this)}catch(t){return o(t)}}.bind(this),o);{if("function"==typeof OffscreenCanvas&&t instanceof OffscreenCanvas)return t.convertToBlob({type:n,quality:i}).then(function(t){try{return u=t,u.name=e,u.lastModified=r,d.call(this)}catch(t){return o(t)}}.bind(this),o);{let v;return v=t.toDataURL(n,i),G(v,e,r).then(function(t){try{return u=t,d.call(this)}catch(t){return o(t)}}.bind(this),o)}function d(){return f.call(this)}}function f(){return c.call(this)}}function c(){return s(u)}}))}function ut(t){t.width=0,t.height=0}function ct(){return new Promise((function(t,n){let e,r,i,s;return void 0!==ct.cachedResult?t(ct.cachedResult):G("data:image/jpeg;base64,/9j/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAYAAAAAAAD/2wCEAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/AABEIAAEAAgMBEQACEQEDEQH/xABKAAEAAAAAAAAAAAAAAAAAAAALEAEAAAAAAAAAAAAAAAAAAAAAAQEAAAAAAAAAAAAAAAAAAAAAEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwA/8H//2Q==","test.jpg",Date.now()).then((function(o){try{return e=o,st(e).then((function(o){try{return r=o[1],ot(r,e.type,e.name,e.lastModified).then((function(e){try{return i=e,ut(r),st(i).then((function(e){try{return s=e[0],t(ct.cachedResult=1===s.width&&2===s.height)}catch(t){return n(t)}}),n)}catch(t){return n(t)}}),n)}catch(t){return n(t)}}),n)}catch(t){return n(t)}}),n)}))}function ht(t){return new Promise(((n,e)=>{const r=new q;r.onload=t=>{const e=new DataView(t.target.result);if(65496!=e.getUint16(0,!1))return n(-2);const r=e.byteLength;let i=2;for(;i<r;){if(e.getUint16(i+2,!1)<=8)return n(-1);const t=e.getUint16(i,!1);if(i+=2,65505==t){if(1165519206!=e.getUint32(i+=2,!1))return n(-1);const t=18761==e.getUint16(i+=6,!1);i+=e.getUint32(i+4,t);const r=e.getUint16(i,t);i+=2;for(let s=0;s<r;s++)if(274==e.getUint16(i+12*s,t))return n(e.getUint16(i+12*s+8,t))}else{if(65280&~t)break;i+=e.getUint16(i,!1)}}return n(-1)},r.onerror=t=>e(t),r.readAsArrayBuffer(t)}))}function at(t,n){const{width:e}=t,{height:r}=t,{maxWidthOrHeight:i}=n;let s,o=t;return isFinite(i)&&(e>i||r>i)&&([o,s]=et(e,r),e>r?(o.width=i,o.height=r/e*i):(o.width=e/r*i,o.height=i),s.drawImage(t,0,0,o.width,o.height),ut(t)),o}function lt(t,n){const{width:e}=t,{height:r}=t,[i,s]=et(e,r);switch(n>4&&n<9?(i.width=r,i.height=e):(i.width=e,i.height=r),n){case 2:s.transform(-1,0,0,1,e,0);break;case 3:s.transform(-1,0,0,-1,e,r);break;case 4:s.transform(1,0,0,-1,0,r);break;case 5:s.transform(0,1,1,0,0,0);break;case 6:s.transform(0,1,-1,0,r,0);break;case 7:s.transform(0,-1,-1,0,r,e);break;case 8:s.transform(0,-1,1,0,0,e)}return s.drawImage(t,0,0,e,r),ut(t),i}function ft(t,n,e=0){return new Promise((function(r,i){let s,o,u,c,h,a,l,f,d,v,p,w,y,g,b,m,A,k,x,M;function S(t=5){if(n.signal&&n.signal.aborted)throw n.signal.reason;s+=t,n.onProgress(Math.min(s,100))}function C(t){if(n.signal&&n.signal.aborted)throw n.signal.reason;s=Math.min(Math.max(t,s),100),n.onProgress(s)}return s=e,o=n.maxIteration||10,u=1024*n.maxSizeMB*1024,S(),st(t,n).then(function(e){try{return[,c]=e,S(),h=at(c,n),S(),new Promise((function(e,r){var i;if(!(i=n.exifOrientation))return ht(t).then(function(t){try{return i=t,s.call(this)}catch(t){return r(t)}}.bind(this),r);function s(){return e(i)}return s.call(this)})).then(function(e){try{return a=e,S(),ct().then(function(e){try{return l=e?h:lt(h,a),S(),f=n.initialQuality||1,d=n.fileType||t.type,ot(l,d,t.name,t.lastModified,f).then(function(e){try{{if(v=e,S(),p=v.size>u,w=v.size>t.size,!p&&!w)return C(100),r(v);var s;function a(){if(o--&&(b>u||b>y)){let n,e;return n=M?.95*x.width:x.width,e=M?.95*x.height:x.height,[A,k]=et(n,e),k.drawImage(x,0,0,n,e),f*="image/png"===d?.85:.95,ot(A,d,t.name,t.lastModified,f).then((function(t){try{return m=t,ut(x),x=A,b=m.size,C(Math.min(99,Math.floor((g-b)/(g-u)*100))),a}catch(t){return i(t)}}),i)}return[1]}return y=t.size,g=v.size,b=g,x=l,M=!n.alwaysKeepResolution&&p,(s=function(t){for(;t;){if(t.then)return void t.then(s,i);try{if(t.pop){if(t.length)return t.pop()?U.call(this):t;t=a}else t=t.call(this)}catch(t){return i(t)}}}.bind(this))(a);function U(){return ut(x),ut(A),ut(h),ut(l),ut(c),C(100),r(m)}}}catch(E){return i(E)}}.bind(this),i)}catch(t){return i(t)}}.bind(this),i)}catch(t){return i(t)}}.bind(this),i)}catch(t){return i(t)}}.bind(this),i)}))}let dt;function vt(t,n){return new Promise(((e,r)=>{dt||(dt=function(){const t=[];return t.push("\nlet scriptImported = false\nself.addEventListener('message', async (e) => {\n const { file, id, imageCompressionLibUrl, options } = e.data\n options.onProgress = (progress) => self.postMessage({ progress, id })\n try {\n if (!scriptImported) {\n // console.log('[worker] importScripts', imageCompressionLibUrl)\n self.importScripts(imageCompressionLibUrl)\n scriptImported = true\n }\n // console.log('[worker] self', self)\n const compressedFile = await imageCompression(file, options)\n self.postMessage({ file: compressedFile, id })\n } catch (e) {\n // console.error('[worker] error', e)\n self.postMessage({ error: e.message + '\\n' + e.stack, id })\n }\n})\n"),URL.createObjectURL(new Blob(t))}());const i=new Worker(dt);i.addEventListener("message",(function(t){if(n.signal&&n.signal.aborted)i.terminate();else if(void 0===t.data.progress){if(t.data.error)return r(new Error(t.data.error)),void i.terminate();e(t.data.file),i.terminate()}else n.onProgress(t.data.progress)})),i.addEventListener("error",r),n.signal&&n.signal.addEventListener("abort",(()=>{r(n.signal.reason),i.terminate()})),i.postMessage({file:t,imageCompressionLibUrl:n.libURL,options:{...n,onProgress:void 0,signal:void 0}})}))}function pt(t,n){return new Promise((function(e,r){let i,s,o,u,c,h;if(i={...n},o=0,({onProgress:u}=i),i.maxSizeMB=i.maxSizeMB||Number.POSITIVE_INFINITY,c="boolean"!=typeof i.useWebWorker||i.useWebWorker,delete i.useWebWorker,i.onProgress=t=>{o=t,"function"==typeof u&&u(o)},!(t instanceof Blob||t instanceof X))return r(new Error("The file given is not an instance of Blob or File"));if(!/^image/.test(t.type))return r(new Error("The file given is not an image"));if(h="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope,!c||"function"!=typeof Worker||h)return ft(t,i).then(function(t){try{return s=t,f.call(this)}catch(t){return r(t)}}.bind(this),r);var a=function(){try{return f.call(this)}catch(t){return r(t)}}.bind(this),l=function(){try{return ft(t,i).then((function(t){try{return s=t,a()}catch(t){return r(t)}}),r)}catch(t){return r(t)}};try{return i.libURL=i.libURL||"https://cdn.jsdelivr.net/npm/browser-image-compression@2.0.2/dist/browser-image-compression.js",vt(t,i).then((function(t){try{return s=t,a()}catch(t){return l()}}),l)}catch(t){l()}function f(){try{s.name=t.name,s.lastModified=t.lastModified}catch(t){}try{i.preserveExif&&"image/jpeg"===t.type&&(!i.fileType||i.fileType&&i.fileType===t.type)&&(s=P(t,s))}catch(t){}return e(s)}}))}pt.getDataUrlFromFile=J,pt.getFilefromDataUrl=G,pt.loadImage=Z,pt.drawImageInCanvas=rt,pt.drawFileInCanvas=st,pt.canvasToFile=ot,pt.getExifOrientation=ht,pt.handleMaxWidthOrHeight=at,pt.followExifOrientation=lt,pt.cleanupCanvasMemory=ut,pt.isAutoOrientationInBrowser=ct,pt.approximateBelowMaximumCanvasSizeOfBrowser=nt,pt.copyExifWithoutOrientation=P,pt.getBrowserName=tt,pt.version="2.0.2";class wt extends c{fileInput=null;maxCompressionSize=300;constructor(t){super(t),this.setupFileInput()}onActivate(){this.openFilePicker()}openFilePicker(){this._core.store.isDisabled||this.fileInput.click()}setupFileInput(){this.fileInput=document.createElement("input"),this.fileInput.type="file",this.fileInput.accept="image/*",this.fileInput.style.display="none",this.fileInput.addEventListener("change",this.handleFileSelect.bind(this)),this.fileInput.addEventListener("cancel",this.handleCancel.bind(this)),document.body.appendChild(this.fileInput)}handleFileSelect(t){const n=t.target;n.files&&n.files[0]?pt(n.files[0],{maxWidthOrHeight:this.maxCompressionSize}).then((t=>{this.readFile(t)})).catch((t=>{console.error("Error during image compression or processing:",t),this.handleCancel()})):(console.info("File selection cancelled by user."),this.handleCancel()),n&&(n.value="")}readFile(t){const n=new FileReader;n.onload=t=>{const n=new Image;n.src=t.target?.result,n.onload=()=>this.createKritzelImage(n)},n.readAsDataURL(t)}createKritzelImage(t){const n=$.create(this._core),{scaledWidth:e,scaledHeight:r}=n.calculateScaledDimensions(t);return n.src=t.src,n.width=e,n.height=r,n.zIndex=this._core.store.currentZIndex,n.centerInViewport(),this.addImageToStore(n),n}addImageToStore(t){this._core.addObject(t),this._core.store.setState("activeTool",a.getTool("selection")),this._core.selectObjects([t]),this._core.engine.emitObjectsChange()}handleCancel(){this._core.store.setState("activeTool",a.getTool("selection"))}}class yt{static _pointerCursor=null;static getPointerCursor(){return this._pointerCursor||(this._pointerCursor=this.getCursor({iconName:"pointer"})),this._pointerCursor}static getCursor(t){const n="default"===t.iconName?"mouse-pointer":t.iconName,e=j.get(n);if(!e)return console.warn(`Icon "${n}" not found in registry.`),"auto";const r=t.size||24,i=t.rotation||0,s=t.color||"black",o=t.hotspot||("default"===t.iconName?{x:4,y:4}:{x:r/2,y:r/2});let u=e.replace(/width="\d+"/,`width="${r}"`).replace(/height="\d+"/,`height="${r}"`).replace(/currentColor/g,s);const c=r/2;return`url('data:image/svg+xml;charset=utf-8,${encodeURIComponent(`\n <svg xmlns="http://www.w3.org/2000/svg" width="${r}" height="${r}" viewBox="0 0 ${r} ${r}">\n <g transform="rotate(${i} ${c} ${c})">\n ${u}\n </g>\n </svg>\n `.replace(/\s+/g," ").trim()).replace(/'/g,"%27").replace(/"/g,"%22")}') ${o.x} ${o.y}, auto`}}const gt=()=>new Map,bt=t=>{const n=gt();return t.forEach(((t,e)=>{n.set(e,t)})),n},mt=(t,n,e)=>{let r=t.get(n);return void 0===r&&t.set(n,r=e()),r},At=()=>new Set,kt=t=>t[t.length-1],xt=(t,n)=>{for(let e=0;e<n.length;e++)t.push(n[e])},Mt=Array.from,St=(t,n)=>{for(let e=0;e<t.length;e++)if(!n(t[e],e,t))return!1;return!0},Ct=(t,n)=>{for(let e=0;e<t.length;e++)if(n(t[e],e,t))return!0;return!1},Ut=Array.isArray;class Et{constructor(){this._observers=gt()}on(t,n){return mt(this._observers,t,At).add(n),n}once(t,n){const e=(...r)=>{this.off(t,e),n(...r)};this.on(t,e)}off(t,n){const e=this._observers.get(t);void 0!==e&&(e.delete(n),0===e.size&&this._observers.delete(t))}emit(t,n){return Mt((this._observers.get(t)||gt()).values()).forEach((t=>t(...n)))}destroy(){this._observers=gt()}}let jt=class{constructor(){this._observers=gt()}on(t,n){mt(this._observers,t,At).add(n)}once(t,n){const e=(...r)=>{this.off(t,e),n(...r)};this.on(t,e)}off(t,n){const e=this._observers.get(t);void 0!==e&&(e.delete(n),0===e.size&&this._observers.delete(t))}emit(t,n){return Mt((this._observers.get(t)||gt()).values()).forEach((t=>t(...n)))}destroy(){this._observers=gt()}};const Tt=Math.floor,It=Math.abs,Ot=(t,n)=>t<n?t:n,_t=(t,n)=>t>n?t:n,zt=Math.pow,$t=t=>0!==t?t<0:1/t<0,Dt=64,Pt=128,Rt=127,Bt=Number.MAX_SAFE_INTEGER,Wt=Number.MIN_SAFE_INTEGER,Lt=Number.isInteger||(t=>"number"==typeof t&&isFinite(t)&&Tt(t)===t),Ft=String.fromCharCode,Nt=/^\s*/g,Kt=/([A-Z])/g,Qt=(t,n)=>(t=>t.replace(Nt,""))(t.replace(Kt,(t=>`${n}${(t=>t.toLowerCase())(t)}`))),Yt="undefined"!=typeof TextEncoder?new TextEncoder:null,Ht=Yt?t=>Yt.encode(t):t=>{const n=unescape(encodeURIComponent(t)),e=n.length,r=new Uint8Array(e);for(let t=0;t<e;t++)r[t]=n.codePointAt(t);return r};let Vt="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});Vt&&1===Vt.decode(new Uint8Array).length&&(Vt=null);let Xt=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}};const qt=()=>new Xt,Gt=t=>{let n=t.cpos;for(let e=0;e<t.bufs.length;e++)n+=t.bufs[e].length;return n},Jt=t=>{const n=new Uint8Array(Gt(t));let e=0;for(let r=0;r<t.bufs.length;r++){const i=t.bufs[r];n.set(i,e),e+=i.length}return n.set(new Uint8Array(t.cbuf.buffer,0,t.cpos),e),n},Zt=(t,n)=>{const e=t.cbuf.length;t.cpos===e&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(2*e),t.cpos=0),t.cbuf[t.cpos++]=n},tn=Zt,nn=(t,n)=>{for(;n>Rt;)Zt(t,Pt|Rt&n),n=Tt(n/128);Zt(t,Rt&n)},en=(t,n)=>{const e=$t(n);for(e&&(n=-n),Zt(t,(n>63?Pt:0)|(e?Dt:0)|63&n),n=Tt(n/64);n>0;)Zt(t,(n>Rt?Pt:0)|Rt&n),n=Tt(n/128)},rn=new Uint8Array(3e4),sn=rn.length/3,on=Yt&&Yt.encodeInto?(t,n)=>{if(n.length<sn){const e=Yt.encodeInto(n,rn).written||0;nn(t,e);for(let n=0;n<e;n++)Zt(t,rn[n])}else cn(t,Ht(n))}:(t,n)=>{const e=unescape(encodeURIComponent(n)),r=e.length;nn(t,r);for(let n=0;n<r;n++)Zt(t,e.codePointAt(n))},un=(t,n)=>{const e=t.cbuf.length,r=t.cpos,i=Ot(e-r,n.length),s=n.length-i;t.cbuf.set(n.subarray(0,i),r),t.cpos+=i,s>0&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(_t(2*e,s)),t.cbuf.set(n.subarray(i)),t.cpos=s)},cn=(t,n)=>{nn(t,n.byteLength),un(t,n)},hn=(t,n)=>{((t,n)=>{const e=t.cbuf.length;e-t.cpos<n&&(t.bufs.push(new Uint8Array(t.cbuf.buffer,0,t.cpos)),t.cbuf=new Uint8Array(2*_t(e,n)),t.cpos=0)})(t,n);const e=new DataView(t.cbuf.buffer,t.cpos,n);return t.cpos+=n,e},an=new DataView(new ArrayBuffer(4)),ln=(t,n)=>{switch(typeof n){case"string":Zt(t,119),on(t,n);break;case"number":Lt(n)&&It(n)<=2147483647?(Zt(t,125),en(t,n)):(an.setFloat32(0,e=n),an.getFloat32(0)===e?(Zt(t,124),((t,n)=>{hn(t,4).setFloat32(0,n,!1)})(t,n)):(Zt(t,123),((t,n)=>{hn(t,8).setFloat64(0,n,!1)})(t,n)));break;case"bigint":Zt(t,122),((t,n)=>{hn(t,8).setBigInt64(0,n,!1)})(t,n);break;case"object":if(null===n)Zt(t,126);else if(Ut(n)){Zt(t,117),nn(t,n.length);for(let e=0;e<n.length;e++)ln(t,n[e])}else if(n instanceof Uint8Array)Zt(t,116),cn(t,n);else{Zt(t,118);const e=Object.keys(n);nn(t,e.length);for(let r=0;r<e.length;r++){const i=e[r];on(t,i),ln(t,n[i])}}break;case"boolean":Zt(t,n?120:121);break;default:Zt(t,127)}var e};class fn extends Xt{constructor(t){super(),this.w=t,this.s=null,this.count=0}write(t){this.s===t?this.count++:(this.count>0&&nn(this,this.count-1),this.count=1,this.w(this,t),this.s=t)}}const dn=t=>{t.count>0&&(en(t.encoder,1===t.count?t.s:-t.s),t.count>1&&nn(t.encoder,t.count-2))};class vn{constructor(){this.encoder=new Xt,this.s=0,this.count=0}write(t){this.s===t?this.count++:(dn(this),this.count=1,this.s=t)}toUint8Array(){return dn(this),Jt(this.encoder)}}const pn=t=>{t.count>0&&(en(t.encoder,2*t.diff+(1===t.count?0:1)),t.count>1&&nn(t.encoder,t.count-2))};class wn{constructor(){this.encoder=new Xt,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(pn(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return pn(this),Jt(this.encoder)}}class yn{constructor(){this.sarr=[],this.s="",this.lensE=new vn}write(t){this.s+=t,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(t.length)}toUint8Array(){const t=new Xt;return this.sarr.push(this.s),this.s="",on(t,this.sarr.join("")),un(t,this.lensE.toUint8Array()),Jt(t)}}const gn=t=>new Error(t),bn=()=>{throw gn("Method unimplemented")},mn=()=>{throw gn("Unexpected case")},An=gn("Unexpected end of array"),kn=gn("Integer out of Range");let xn=class{constructor(t){this.arr=t,this.pos=0}};const Mn=t=>new xn(t),Sn=t=>((t,n)=>{const e=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,n);return t.pos+=n,e})(t,Un(t)),Cn=t=>t.arr[t.pos++],Un=t=>{let n=0,e=1;const r=t.arr.length;for(;t.pos<r;){const r=t.arr[t.pos++];if(n+=(r&Rt)*e,e*=128,r<Pt)return n;if(n>Bt)throw kn}throw An},En=t=>{let n=t.arr[t.pos++],e=63&n,r=64;const i=(n&Dt)>0?-1:1;if(!(n&Pt))return i*e;const s=t.arr.length;for(;t.pos<s;){if(n=t.arr[t.pos++],e+=(n&Rt)*r,r*=128,n<Pt)return i*e;if(e>Bt)throw kn}throw An},jn=Vt?t=>Vt.decode(Sn(t)):t=>{let n=Un(t);if(0===n)return"";{let e=String.fromCodePoint(Cn(t));if(--n<100)for(;n--;)e+=String.fromCodePoint(Cn(t));else for(;n>0;){const r=n<1e4?n:1e4,i=t.arr.subarray(t.pos,t.pos+r);t.pos+=r,e+=String.fromCodePoint.apply(null,i),n-=r}return decodeURIComponent(escape(e))}},Tn=(t,n)=>{const e=new DataView(t.arr.buffer,t.arr.byteOffset+t.pos,n);return t.pos+=n,e},In=[()=>{},()=>null,En,t=>Tn(t,4).getFloat32(0,!1),t=>Tn(t,8).getFloat64(0,!1),t=>Tn(t,8).getBigInt64(0,!1),()=>!1,()=>!0,jn,t=>{const n=Un(t),e={};for(let r=0;r<n;r++)e[jn(t)]=On(t);return e},t=>{const n=Un(t),e=[];for(let r=0;r<n;r++)e.push(On(t));return e},Sn],On=t=>In[127-Cn(t)](t);class _n extends xn{constructor(t,n){super(t),this.reader=n,this.s=null,this.count=0}read(){return 0===this.count&&(this.s=this.reader(this),this.count=this.pos!==this.arr.length?Un(this)+1:-1),this.count--,this.s}}class zn extends xn{constructor(t){super(t),this.s=0,this.count=0}read(){if(0===this.count){this.s=En(this);const t=$t(this.s);this.count=1,t&&(this.s=-this.s,this.count=Un(this)+2)}return this.count--,this.s}}class $n extends xn{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(0===this.count){const t=En(this),n=1&t;this.diff=Tt(t/2),this.count=1,n&&(this.count=Un(this)+2)}return this.s+=this.diff,this.count--,this.s}}class Dn{constructor(t){this.decoder=new zn(t),this.str=jn(this.decoder),this.spos=0}read(){const t=this.spos+this.decoder.read(),n=this.str.slice(this.spos,t);return this.spos=t,n}}const Pn=crypto.getRandomValues.bind(crypto),Rn=()=>Pn(new Uint32Array(1))[0],Bn=[1e7]+-1e3+-4e3+-8e3+-1e11,Wn=()=>Bn.replace(/[018]/g,(t=>(t^Rn()&15>>t/4).toString(16))),Ln=Date.now,Fn=t=>new Promise(t);Promise.all.bind(Promise);let Nn=new class{constructor(){this.map=new Map}setItem(t,n){this.map.set(t,n)}getItem(t){return this.map.get(t)}},Kn=!0;try{"undefined"!=typeof localStorage&&localStorage&&(Nn=localStorage,Kn=!1)}catch(B){}const Qn=Nn,Yn=t=>Kn||addEventListener("storage",t),Hn=t=>Kn||removeEventListener("storage",t),Vn=Symbol("Equality"),Xn=(t,n)=>t===n||!!t?.[Vn]?.(n)||!1,qn=Object.assign,Gn=Object.keys,Jn=(t,n)=>{const e=[];for(const r in t)e.push(n(t[r],r));return e},Zn=t=>Gn(t).length,te=(t,n)=>{for(const e in t)if(!n(t[e],e))return!1;return!0},ne=(t,n)=>Object.prototype.hasOwnProperty.call(t,n),ee=Object.freeze,re=t=>{for(const n in t){const e=t[n];"object"!=typeof e&&"function"!=typeof e||re(t[n])}return ee(t)},ie=(t,n,e=0)=>{try{for(;e<t.length;e++)t[e](...n)}finally{e<t.length&&ie(t,n,e+1)}},se=t=>t,oe=(t,n)=>{if(t===n)return!0;if(null==t||null==n||t.constructor!==n.constructor&&(t.constructor||Object)!==(n.constructor||Object))return!1;if(null!=t[Vn])return t[Vn](n);switch(t.constructor){case ArrayBuffer:t=new Uint8Array(t),n=new Uint8Array(n);case Uint8Array:if(t.byteLength!==n.byteLength)return!1;for(let e=0;e<t.length;e++)if(t[e]!==n[e])return!1;break;case Set:if(t.size!==n.size)return!1;for(const e of t)if(!n.has(e))return!1;break;case Map:if(t.size!==n.size)return!1;for(const e of t.keys())if(!n.has(e)||!oe(t.get(e),n.get(e)))return!1;break;case void 0:case Object:if(Zn(t)!==Zn(n))return!1;for(const e in t)if(!ne(t,e)||!oe(t[e],n[e]))return!1;break;case Array:if(t.length!==n.length)return!1;for(let e=0;e<t.length;e++)if(!oe(t[e],n[e]))return!1;break;default:return!1}return!0},ue="undefined"!=typeof process&&process.release&&/node|io\.js/.test(process.release.name)&&"[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),ce="undefined"!=typeof window&&"undefined"!=typeof document&&!ue;let he;const ae=t=>(()=>{if(void 0===he)if(ue){he=gt();const t=process.argv;let n=null;for(let e=0;e<t.length;e++){const r=t[e];"-"===r[0]?(null!==n&&he.set(n,""),n=r):null!==n&&(he.set(n,r),n=null)}null!==n&&he.set(n,"")}else"object"==typeof location?(he=gt(),(location.search||"?").slice(1).split("&").forEach((t=>{if(0!==t.length){const[n,e]=t.split("=");he.set(`--${Qt(n,"-")}`,e),he.set(`-${Qt(n,"-")}`,e)}}))):he=gt();return he})().has(t),le=t=>{return void 0===(n=ue?process.env[t.toUpperCase().replaceAll("-","_")]:Qn.getItem(t))?null:n;var n},fe=t=>ae("--"+t)||null!==le(t),de=fe("production");var ve;const pe=ue&&(ve=process.env.FORCE_COLOR,["true","1","2"].includes(ve))||!ae("--no-colors")&&!fe("no-color")&&(!ue||process.stdout.isTTY)&&(!ue||ae("--color")||null!==le("COLORTERM")||(le("TERM")||"").includes("color")),we=t=>new Uint8Array(t),ye=t=>new Uint8Array(t),ge=ce?t=>{let n="";for(let e=0;e<t.byteLength;e++)n+=Ft(t[e]);return btoa(n)}:t=>Buffer.from(t.buffer,t.byteOffset,t.byteLength).toString("base64"),be=ce?t=>{const n=atob(t),e=we(n.length);for(let t=0;t<n.length;t++)e[t]=n.charCodeAt(t);return e}:t=>{const n=Buffer.from(t,"base64");return((t,n,e)=>new Uint8Array(t,n,e))(n.buffer,n.byteOffset,n.byteLength)};class me{constructor(t,n){this.left=t,this.right=n}}const Ae=(t,n)=>new me(t,n),ke=t=>t.next()>=.5,xe=(t,n,e)=>Tt(t.next()*(e+1-n)+n),Me=(t,n,e)=>Tt(t.next()*(e+1-n)+n),Se=(t,n,e)=>Me(t,n,e),Ce=t=>Ft(Se(t,97,122)),Ue=(t,n)=>n[Se(t,0,n.length-1)],Ee=Symbol("0schema");class je{constructor(){this._rerrs=[]}extend(t,n,e,r=null){this._rerrs.push({path:t,expected:n,has:e,message:r})}toString(){const t=[];for(let e=this._rerrs.length-1;e>0;e--){const r=this._rerrs[e];t.push((n=" ",(t=>{const e=new Array(t);for(let r=0;r<t;r++)e[r]=n;return e})(2*(this._rerrs.length-e)).join("")+`${null!=r.path?`[${r.path}] `:""}${r.has} doesn't match ${r.expected}. ${r.message}`))}var n;return t.join("\n")}}const Te=(t,n)=>t===n||null!=t&&null!=n&&t.constructor===n.constructor&&(t[Vn]?Xn(t,n):Ut(t)?St(t,(t=>Ct(n,(n=>Te(t,n))))):!!(t=>"object"==typeof t)(t)&&te(t,((t,e)=>Te(t,n[e]))));class Ie{static _dilutes=!1;extends(t){let[n,e]=[this.shape,t.shape];return this.constructor._dilutes&&([e,n]=[n,e]),Te(n,e)}equals(t){return this.constructor===t.constructor&&oe(this.shape,t.shape)}[Ee](){return!0}[Vn](t){return this.equals(t)}validate(t){return this.check(t)}check(t,n){bn()}get nullable(){return or(this,Ar)}get optional(){return new Fe(this)}cast(t){return Sr(t,this),t}expect(t){return Sr(t,this),t}}class Oe extends Ie{constructor(t,n){super(),this.shape=t,this._c=n}check(t,n){const e=t?.constructor===this.shape&&(null==this._c||this._c(t));return!e&&n?.extend(null,this.shape.name,t?.constructor.name,t?.constructor!==this.shape?"Constructor match failed":"Check failed"),e}}const _e=(t,n=null)=>new Oe(t,n);_e(Oe);class ze extends Ie{constructor(t){super(),this.shape=t}check(t,n){const e=this.shape(t);return!e&&n?.extend(null,"custom prop",t?.constructor.name,"failed to check custom prop"),e}}const $e=t=>new ze(t);_e(ze);class De extends Ie{constructor(t){super(),this.shape=t}check(t,n){const e=this.shape.some((n=>n===t));return!e&&n?.extend(null,this.shape.join(" | "),t.toString()),e}}const Pe=(...t)=>new De(t),Re=_e(De),Be=RegExp.escape||(t=>t.replace(/[().|&,$^[\]]/g,(t=>"\\"+t))),We=t=>wr.check(t)?[Be(t)]:Re.check(t)?t.shape.map((t=>t+"")):pr.check(t)?["[+-]?\\d+.?\\d*"]:yr.check(t)?[".*"]:ur.check(t)?t.shape.map(We).flat(1):void mn();_e(class extends Ie{constructor(t){super(),this.shape=t,this._r=new RegExp("^"+t.map(We).map((t=>`(${t.join("|")})`)).join("")+"$")}check(t,n){const e=null!=this._r.exec(t);return!e&&n?.extend(null,this._r.toString(),t.toString(),"String doesn't match string template."),e}});const Le=Symbol("optional");class Fe extends Ie{constructor(t){super(),this.shape=t}check(t,n){const e=void 0===t||this.shape.check(t);return!e&&n?.extend(null,"undefined (optional)","()"),e}get[Le](){return!0}}const Ne=_e(Fe);_e(class extends Ie{check(t,n){return n?.extend(null,"never",typeof t),!1}});class Ke extends Ie{constructor(t,n=!1){super(),this.shape=t,this._isPartial=n}static _dilutes=!0;get partial(){return new Ke(this.shape,!0)}check(t,n){return null==t?(n?.extend(null,"object","null"),!1):te(this.shape,((e,r)=>{const i=this._isPartial&&!ne(t,r)||e.check(t[r],n);return!i&&n?.extend(r.toString(),e.toString(),typeof t[r],"Object property does not match"),i}))}}const Qe=_e(Ke),Ye=$e((t=>null!=t&&(t.constructor===Object||null==t.constructor)));class He extends Ie{constructor(t,n){super(),this.shape={keys:t,values:n}}check(t,n){return null!=t&&te(t,((e,r)=>{const i=this.shape.keys.check(r,n);return!i&&n?.extend(r+"","Record",typeof t,i?"Key doesn't match schema":"Value doesn't match value"),i&&this.shape.values.check(e,n)}))}}const Ve=(t,n)=>new He(t,n),Xe=_e(He);class qe extends Ie{constructor(t){super(),this.shape=t}check(t,n){return null!=t&&te(this.shape,((e,r)=>{const i=e.check(t[r],n);return!i&&n?.extend(r.toString(),"Tuple",typeof e),i}))}}_e(qe);class Ge extends Ie{constructor(t){super(),this.shape=1===t.length?t[0]:new sr(t)}check(t,n){const e=Ut(t)&&St(t,(t=>this.shape.check(t)));return!e&&n?.extend(null,"Array",""),e}}const Je=(...t)=>new Ge(t),Ze=_e(Ge),tr=$e((t=>Ut(t)));class nr extends Ie{constructor(t,n){super(),this.shape=t,this._c=n}check(t,n){const e=t instanceof this.shape&&(null==this._c||this._c(t));return!e&&n?.extend(null,this.shape.name,t?.constructor.name),e}}_e(nr);const er=((t,n=null)=>new nr(Ie,n))(),rr=_e(class extends Ie{constructor(t){super(),this.len=t.length-1,this.args=((...t)=>new qe(t))(...t.slice(-1)),this.res=t[this.len]}check(t,n){const e=t.constructor===Function&&t.length<=this.len;return!e&&n?.extend(null,"function",typeof t),e}}),ir=$e((t=>"function"==typeof t));_e(class extends Ie{constructor(t){super(),this.shape=t}check(t,n){const e=St(this.shape,(e=>e.check(t,n)));return!e&&n?.extend(null,"Intersectinon",typeof t),e}},(t=>t.shape.length>0));class sr extends Ie{static _dilutes=!0;constructor(t){super(),this.shape=t}check(t,n){const e=Ct(this.shape,(e=>e.check(t,n)));return n?.extend(null,"Union",typeof t),e}}const or=(...t)=>t.findIndex((t=>ur.check(t)))>=0?or(...t.map((t=>Mr(t))).map((t=>ur.check(t)?t.shape:[t])).flat(1)):1===t.length?t[0]:new sr(t),ur=_e(sr),cr=()=>!0,hr=$e(cr),ar=_e(ze,(t=>t.shape===cr)),lr=$e((t=>"bigint"==typeof t)),fr=$e((t=>t===lr)),dr=$e((t=>"symbol"==typeof t));$e((t=>t===dr));const vr=$e((t=>"number"==typeof t)),pr=$e((t=>t===vr)),wr=$e((t=>"string"==typeof t)),yr=$e((t=>t===wr)),gr=$e((t=>"boolean"==typeof t)),br=$e((t=>t===gr)),mr=Pe(void 0);_e(De,(t=>1===t.shape.length&&void 0===t.shape[0])),Pe(void 0);const Ar=Pe(null),kr=_e(De,(t=>1===t.shape.length&&null===t.shape[0]));_e(Uint8Array),_e(Oe,(t=>t.shape===Uint8Array));const xr=or(vr,wr,Ar,mr,lr,gr,dr);(()=>{const t=Je(hr),n=Ve(wr,hr),e=or(vr,wr,Ar,gr,t,n);t.shape=e,n.shape.values=e})();const Mr=t=>{if(er.check(t))return t;if(Ye.check(t)){const n={};for(const e in t)n[e]=Mr(t[e]);return new Ke(n)}return tr.check(t)?or(...t.map(Mr)):xr.check(t)?Pe(t):ir.check(t)?_e(t):void mn()},Sr=de?()=>{}:(t,n)=>{const e=new je;if(!n.check(t,e))throw gn(`Expected value to be of type ${n.constructor.name}.\n${e.toString()}`)};const Cr=(Ur=hr,new class{constructor(t){this.patterns=[],this.$state=t}if(t,n){return this.patterns.push({if:Mr(t),h:n}),this}else(t){return this.if(hr,t)}done(){return(t,n)=>{for(let e=0;e<this.patterns.length;e++){const r=this.patterns[e];if(r.if.check(t))return r.h(t,n)}throw gn("Unhandled pattern")}}}(Ur)).if(pr,((t,n)=>xe(n,Wt,Bt))).if(yr,((t,n)=>((t,n=0,e=20)=>{const r=Se(t,n,e);let i="";for(let n=0;n<r;n++)i+=Ce(t);return i})(n))).if(br,((t,n)=>ke(n))).if(fr,((t,n)=>BigInt(xe(n,Wt,Bt)))).if(ur,((t,n)=>Er(n,Ue(n,t.shape)))).if(Qe,((t,n)=>{const e={};for(const r in t.shape){let i=t.shape[r];if(Ne.check(i)){if(ke(n))continue;i=i.shape}e[r]=Cr(i,n)}return e})).if(Ze,((t,n)=>{const e=[],r=Me(n,0,42);for(let i=0;i<r;i++)e.push(Er(n,t.shape));return e})).if(Re,((t,n)=>Ue(n,t.shape))).if(kr,(()=>null)).if(rr,((t,n)=>{const e=Er(n,t.res);return()=>e})).if(ar,((t,n)=>Er(n,Ue(n,[vr,wr,Ar,mr,lr,gr,Je(vr),Ve(or("a","b","c"),vr)])))).if(Xe,((t,n)=>{const e={},r=xe(n,0,3);for(let i=0;i<r;i++){const r=Er(n,t.shape.keys),i=Er(n,t.shape.values);e[r]=i}return e})).done();var Ur;const Er=(t,n)=>Cr(Mr(n),t),jr="undefined"!=typeof document?document:{};$e((t=>t.nodeType===_r)),"undefined"!=typeof DOMParser&&new DOMParser,$e((t=>t.nodeType===Tr)),$e((t=>t.nodeType===Ir));const Tr=jr.ELEMENT_NODE,Ir=jr.TEXT_NODE,Or=jr.DOCUMENT_NODE,_r=jr.DOCUMENT_FRAGMENT_NODE;$e((t=>t.nodeType===Or));const zr=Symbol,$r=zr(),Dr=zr(),Pr=zr(),Rr=zr(),Br=zr(),Wr=zr(),Lr=zr(),Fr=zr(),Nr=zr(),Kr={[$r]:Ae("font-weight","bold"),[Dr]:Ae("font-weight","normal"),[Pr]:Ae("color","blue"),[Br]:Ae("color","green"),[Rr]:Ae("color","grey"),[Wr]:Ae("color","red"),[Lr]:Ae("color","purple"),[Fr]:Ae("color","orange"),[Nr]:Ae("color","black")},Qr=pe?t=>{1===t.length&&t[0]?.constructor===Function&&(t=t[0]());const n=[],e=[],r=gt();let i=[],s=0;for(;s<t.length;s++){const i=t[s],o=Kr[i];if(void 0!==o)r.set(o.left,o.right);else{if(void 0===i)break;if(i.constructor!==String&&i.constructor!==Number)break;{const t=((t,n)=>{const e=[];for(const[r,i]of t)e.push(n(i,r));return e})(r,((t,n)=>`${n}:${t};`)).join("");s>0||t.length>0?(n.push("%c"+i),e.push(t)):n.push(i)}}}for(s>0&&(i=e,i.unshift(n.join("")));s<t.length;s++){const n=t[s];n instanceof Symbol||i.push(n)}return i}:t=>{1===t.length&&t[0]?.constructor===Function&&(t=t[0]());const n=[],e=[];let r=0;for(;r<t.length;r++){const e=t[r];if(void 0===e)break;if(e.constructor===String||e.constructor===Number)n.push(e);else if(e.constructor===Object)break}for(r>0&&e.push(n.join(""));r<t.length;r++){const n=t[r];n instanceof Symbol||e.push(n)}return e},Yr=(...t)=>{console.warn(...Qr(t)),t.unshift(Fr),Hr.forEach((n=>n.print(t)))},Hr=At(),Vr=t=>({[Symbol.iterator](){return this},next:t}),Xr=(t,n)=>Vr((()=>{const{done:e,value:r}=t.next();return{done:e,value:e?void 0:n(r)}}));class qr{constructor(t,n){this.clock=t,this.len=n}}class Gr{constructor(){this.clients=new Map}}const Jr=(t,n,e)=>n.clients.forEach(((n,r)=>{const i=t.doc.store.clients.get(r);if(null!=i){const r=i[i.length-1],s=r.id.clock+r.length;for(let r=0,o=n[r];r<n.length&&o.clock<s;o=n[++r])Ki(t,i,o.clock,o.len,e)}})),Zr=(t,n)=>{const e=t.clients.get(n.client);return void 0!==e&&null!==((t,n)=>{let e=0,r=t.length-1;for(;e<=r;){const i=Tt((e+r)/2),s=t[i],o=s.clock;if(o<=n){if(n<o+s.len)return i;e=i+1}else r=i-1}return null})(e,n.clock)},ti=t=>{t.clients.forEach((t=>{let n,e;for(t.sort(((t,n)=>t.clock-n.clock)),n=1,e=1;n<t.length;n++){const r=t[e-1],i=t[n];r.clock+r.len>=i.clock?r.len=_t(r.len,i.clock+i.len-r.clock):(e<n&&(t[e]=i),e++)}t.length=e}))},ni=t=>{const n=new Gr;for(let e=0;e<t.length;e++)t[e].clients.forEach(((r,i)=>{if(!n.clients.has(i)){const s=r.slice();for(let n=e+1;n<t.length;n++)xt(s,t[n].clients.get(i)||[]);n.clients.set(i,s)}}));return ti(n),n},ei=(t,n,e,r)=>{mt(t.clients,n,(()=>[])).push(new qr(e,r))},ri=(t,n)=>{nn(t.restEncoder,n.clients.size),Mt(n.clients.entries()).sort(((t,n)=>n[0]-t[0])).forEach((([n,e])=>{t.resetDsCurVal(),nn(t.restEncoder,n);const r=e.length;nn(t.restEncoder,r);for(let n=0;n<r;n++){const r=e[n];t.writeDsClock(r.clock),t.writeDsLen(r.len)}}))},ii=t=>{const n=new Gr,e=Un(t.restDecoder);for(let r=0;r<e;r++){t.resetDsCurVal();const e=Un(t.restDecoder),r=Un(t.restDecoder);if(r>0){const i=mt(n.clients,e,(()=>[]));for(let n=0;n<r;n++)i.push(new qr(t.readDsClock(),t.readDsLen()))}}return n},si=(t,n,e)=>{const r=new Gr,i=Un(t.restDecoder);for(let s=0;s<i;s++){t.resetDsCurVal();const i=Un(t.restDecoder),s=Un(t.restDecoder),o=e.clients.get(i)||[],u=Pi(e,i);for(let e=0;e<s;e++){const e=t.readDsClock(),s=e+t.readDsLen();if(e<u){u<s&&ei(r,i,u,s-u);let t=Bi(o,e),c=o[t];for(!c.deleted&&c.id.clock<e&&(o.splice(t+1,0,zo(n,c,e-c.id.clock)),t++);t<o.length&&(c=o[t++],c.id.clock<s);)c.deleted||(s<c.id.clock+c.length&&o.splice(t,0,zo(n,c,s-c.id.clock)),c.delete(n))}else ei(r,i,e,s-e)}}if(r.clients.size>0){const t=new pi;return nn(t.restEncoder,0),ri(t,r),t.toUint8Array()}return null},oi=Rn;class ui extends Et{constructor({guid:t=Wn(),collectionid:n=null,gc:e=!0,gcFilter:r=()=>!0,meta:i=null,autoLoad:s=!1,shouldLoad:o=!0}={}){super(),this.gc=e,this.gcFilter=r,this.clientID=oi(),this.guid=t,this.collectionid=n,this.share=new Map,this.store=new $i,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=o,this.autoLoad=s,this.meta=i,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=Fn((t=>{this.on("load",(()=>{this.isLoaded=!0,t(this)}))}));const u=()=>Fn((t=>{const n=e=>{void 0!==e&&!0!==e||(this.off("sync",n),t())};this.on("sync",n)}));this.on("sync",(t=>{!1===t&&this.isSynced&&(this.whenSynced=u()),this.isSynced=void 0===t||!0===t,this.isSynced&&!this.isLoaded&&this.emit("load",[this])})),this.whenSynced=u()}load(){const t=this._item;null===t||this.shouldLoad||qi(t.parent.doc,(t=>{t.subdocsLoaded.add(this)}),null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(Mt(this.subdocs).map((t=>t.guid)))}transact(t,n=null){return qi(this,t,n)}get(t,n=As){const e=mt(this.share,t,(()=>{const t=new n;return t._integrate(this,null),t})),r=e.constructor;if(n!==As&&r!==n){if(r===As){const r=new n;r._map=e._map,e._map.forEach((t=>{for(;null!==t;t=t.left)t.parent=r})),r._start=e._start;for(let t=r._start;null!==t;t=t.right)t.parent=r;return r._length=e._length,this.share.set(t,r),r._integrate(this,null),r}throw new Error(`Type with the name ${t} has already been defined with a different constructor`)}return e}getArray(t=""){return this.get(t,Bs)}getText(t=""){return this.get(t,ro)}getMap(t=""){return this.get(t,Ls)}getXmlElement(t=""){return this.get(t,oo)}getXmlFragment(t=""){return this.get(t,so)}toJSON(){const t={};return this.share.forEach(((n,e)=>{t[e]=n.toJSON()})),t}destroy(){this.isDestroyed=!0,Mt(this.subdocs).forEach((t=>t.destroy()));const t=this._item;if(null!==t){this._item=null;const n=t.content;n.doc=new ui({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=t,qi(t.parent.doc,(e=>{t.deleted||e.subdocsAdded.add(n.doc),e.subdocsRemoved.add(this)}),null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}}class ci{constructor(t){this.restDecoder=t}resetDsCurVal(){}readDsClock(){return Un(this.restDecoder)}readDsLen(){return Un(this.restDecoder)}}class hi extends ci{readLeftID(){return Ii(Un(this.restDecoder),Un(this.restDecoder))}readRightID(){return Ii(Un(this.restDecoder),Un(this.restDecoder))}readClient(){return Un(this.restDecoder)}readInfo(){return Cn(this.restDecoder)}readString(){return jn(this.restDecoder)}readParentInfo(){return 1===Un(this.restDecoder)}readTypeRef(){return Un(this.restDecoder)}readLen(){return Un(this.restDecoder)}readAny(){return On(this.restDecoder)}readBuf(){return(t=>{const n=we(t.byteLength);return n.set(t),n})(Sn(this.restDecoder))}readJSON(){return JSON.parse(jn(this.restDecoder))}readKey(){return jn(this.restDecoder)}}class ai{constructor(t){this.dsCurrVal=0,this.restDecoder=t}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=Un(this.restDecoder),this.dsCurrVal}readDsLen(){const t=Un(this.restDecoder)+1;return this.dsCurrVal+=t,t}}class li extends ai{constructor(t){super(t),this.keys=[],Un(t),this.keyClockDecoder=new $n(Sn(t)),this.clientDecoder=new zn(Sn(t)),this.leftClockDecoder=new $n(Sn(t)),this.rightClockDecoder=new $n(Sn(t)),this.infoDecoder=new _n(Sn(t),Cn),this.stringDecoder=new Dn(Sn(t)),this.parentInfoDecoder=new _n(Sn(t),Cn),this.typeRefDecoder=new zn(Sn(t)),this.lenDecoder=new zn(Sn(t))}readLeftID(){return new ji(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new ji(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return 1===this.parentInfoDecoder.read()}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return On(this.restDecoder)}readBuf(){return Sn(this.restDecoder)}readJSON(){return On(this.restDecoder)}readKey(){const t=this.keyClockDecoder.read();if(t<this.keys.length)return this.keys[t];{const t=this.stringDecoder.read();return this.keys.push(t),t}}}class fi{constructor(){this.restEncoder=qt()}toUint8Array(){return Jt(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){nn(this.restEncoder,t)}writeDsLen(t){nn(this.restEncoder,t)}}class di extends fi{writeLeftID(t){nn(this.restEncoder,t.client),nn(this.restEncoder,t.clock)}writeRightID(t){nn(this.restEncoder,t.client),nn(this.restEncoder,t.clock)}writeClient(t){nn(this.restEncoder,t)}writeInfo(t){tn(this.restEncoder,t)}writeString(t){on(this.restEncoder,t)}writeParentInfo(t){nn(this.restEncoder,t?1:0)}writeTypeRef(t){nn(this.restEncoder,t)}writeLen(t){nn(this.restEncoder,t)}writeAny(t){ln(this.restEncoder,t)}writeBuf(t){cn(this.restEncoder,t)}writeJSON(t){on(this.restEncoder,JSON.stringify(t))}writeKey(t){on(this.restEncoder,t)}}class vi{constructor(){this.restEncoder=qt(),this.dsCurrVal=0}toUint8Array(){return Jt(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){const n=t-this.dsCurrVal;this.dsCurrVal=t,nn(this.restEncoder,n)}writeDsLen(t){0===t&&mn(),nn(this.restEncoder,t-1),this.dsCurrVal+=t}}class pi extends vi{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new wn,this.clientEncoder=new vn,this.leftClockEncoder=new wn,this.rightClockEncoder=new wn,this.infoEncoder=new fn(tn),this.stringEncoder=new yn,this.parentInfoEncoder=new fn(tn),this.typeRefEncoder=new vn,this.lenEncoder=new vn}toUint8Array(){const t=qt();return nn(t,0),cn(t,this.keyClockEncoder.toUint8Array()),cn(t,this.clientEncoder.toUint8Array()),cn(t,this.leftClockEncoder.toUint8Array()),cn(t,this.rightClockEncoder.toUint8Array()),cn(t,Jt(this.infoEncoder)),cn(t,this.stringEncoder.toUint8Array()),cn(t,Jt(this.parentInfoEncoder)),cn(t,this.typeRefEncoder.toUint8Array()),cn(t,this.lenEncoder.toUint8Array()),un(t,Jt(this.restEncoder)),Jt(t)}writeLeftID(t){this.clientEncoder.write(t.client),this.leftClockEncoder.write(t.clock)}writeRightID(t){this.clientEncoder.write(t.client),this.rightClockEncoder.write(t.clock)}writeClient(t){this.clientEncoder.write(t)}writeInfo(t){this.infoEncoder.write(t)}writeString(t){this.stringEncoder.write(t)}writeParentInfo(t){this.parentInfoEncoder.write(t?1:0)}writeTypeRef(t){this.typeRefEncoder.write(t)}writeLen(t){this.lenEncoder.write(t)}writeAny(t){ln(this.restEncoder,t)}writeBuf(t){cn(this.restEncoder,t)}writeJSON(t){ln(this.restEncoder,t)}writeKey(t){const n=this.keyMap.get(t);void 0===n?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(t)):this.keyClockEncoder.write(n)}}const wi=(t,n,e)=>{const r=new Map;e.forEach(((t,e)=>{Pi(n,e)>t&&r.set(e,t)})),Di(n).forEach(((t,n)=>{e.has(n)||r.set(n,0)})),nn(t.restEncoder,r.size),Mt(r.entries()).sort(((t,n)=>n[0]-t[0])).forEach((([e,r])=>{((t,n,e,r)=>{r=_t(r,n[0].id.clock);const i=Bi(n,r);nn(t.restEncoder,n.length-i),t.writeClient(e),nn(t.restEncoder,r);const s=n[i];s.write(t,r-s.id.clock);for(let e=i+1;e<n.length;e++)n[e].write(t,0)})(t,n.clients.get(e),e,r)}))},yi=(t,n,e,r=li)=>{const i=Mn(n);((t,n,e,r=new li(t))=>{qi(n,(t=>{t.local=!1;let n=!1;const e=t.doc,i=e.store,s=((t,n)=>{const e=gt(),r=Un(t.restDecoder);for(let i=0;i<r;i++){const r=Un(t.restDecoder),i=new Array(r),s=t.readClient();let o=Un(t.restDecoder);e.set(s,{i:0,refs:i});for(let e=0;e<r;e++){const r=t.readInfo();switch(31&r){case 0:{const n=t.readLen();i[e]=new lo(Ii(s,o),n),o+=n;break}case 10:{const n=Un(t.restDecoder);i[e]=new Wo(Ii(s,o),n),o+=n;break}default:{const u=!(192&r),c=new Po(Ii(s,o),null,(r&Pt)===Pt?t.readLeftID():null,null,(r&Dt)===Dt?t.readRightID():null,u?t.readParentInfo()?n.get(t.readString()):t.readLeftID():null,!u||32&~r?null:t.readString(),Ro(t,r));i[e]=c,o+=c.length}}}}return e})(r,e),o=((t,n,e)=>{const r=[];let i=Mt(e.keys()).sort(((t,n)=>t-n));if(0===i.length)return null;const s=()=>{if(0===i.length)return null;let t=e.get(i[i.length-1]);for(;t.refs.length===t.i;){if(i.pop(),!(i.length>0))return null;t=e.get(i[i.length-1])}return t};let o=s();if(null===o)return null;const u=new $i,c=new Map,h=(t,n)=>{const e=c.get(t);(null==e||e>n)&&c.set(t,n)};let a=o.refs[o.i++];const l=new Map,f=()=>{for(const t of r){const n=t.id.client,r=e.get(n);r?(r.i--,u.clients.set(n,r.refs.slice(r.i)),e.delete(n),r.i=0,r.refs=[]):u.clients.set(n,[t]),i=i.filter((t=>t!==n))}r.length=0};for(;;){if(a.constructor!==Wo){const i=mt(l,a.id.client,(()=>Pi(n,a.id.client)))-a.id.clock;if(i<0)r.push(a),h(a.id.client,a.id.clock-1),f();else{const s=a.getMissing(t,n);if(null!==s){r.push(a);const t=e.get(s)||{refs:[],i:0};if(t.refs.length!==t.i){a=t.refs[t.i++];continue}h(s,Pi(n,s)),f()}else(0===i||i<a.length)&&(a.integrate(t,i),l.set(a.id.client,a.id.clock+a.length))}}if(r.length>0)a=r.pop();else if(null!==o&&o.i<o.refs.length)a=o.refs[o.i++];else{if(o=s(),null===o)break;a=o.refs[o.i++]}}if(u.clients.size>0){const t=new pi;return wi(t,u,new Map),nn(t.restEncoder,0),{missing:c,update:t.toUint8Array()}}return null})(t,i,s),u=i.pendingStructs;if(u){for(const[t,e]of u.missing)if(e<Pi(i,t)){n=!0;break}if(o){for(const[t,n]of o.missing){const e=u.missing.get(t);(null==e||e>n)&&u.missing.set(t,n)}u.update=ss([u.update,o.update])}}else i.pendingStructs=o;const c=si(r,t,i);if(i.pendingDs){const n=new li(Mn(i.pendingDs));Un(n.restDecoder);const e=si(n,t,i);i.pendingDs=c&&e?ss([c,e]):c||e}else i.pendingDs=c;if(n){const n=i.pendingStructs.update;i.pendingStructs=null,yi(t.doc,n)}}),e,!1)})(i,t,e,new r(i))},gi=(t,n,e)=>yi(t,n,e,hi),bi=(t,n=new Uint8Array([0]),e=new pi)=>{((t,n,e=new Map)=>{wi(t,n.store,e),ri(t,(t=>{const n=new Gr;return t.clients.forEach(((t,e)=>{const r=[];for(let n=0;n<t.length;n++){const e=t[n];if(e.deleted){const i=e.id.clock;let s=e.length;if(n+1<t.length)for(let e=t[n+1];n+1<t.length&&e.deleted;e=t[1+ ++n])s+=e.length;r.push(new qr(i,s))}}r.length>0&&n.clients.set(e,r)})),n})(n.store))})(e,t,Ai(n));const r=[e.toUint8Array()];if(t.store.pendingDs&&r.push(t.store.pendingDs),t.store.pendingStructs&&r.push(os(t.store.pendingStructs.update,n)),r.length>1){if(e.constructor===di)return rs(r.map(((t,n)=>0===n?t:as(t))));if(e.constructor===pi)return ss(r)}return r[0]},mi=(t,n)=>bi(t,n,new di),Ai=t=>(t=>{const n=new Map,e=Un(t.restDecoder);for(let r=0;r<e;r++){const e=Un(t.restDecoder),r=Un(t.restDecoder);n.set(e,r)}return n})(new ci(Mn(t))),ki=(t,n)=>(nn(t.restEncoder,n.size),Mt(n.entries()).sort(((t,n)=>n[0]-t[0])).forEach((([n,e])=>{nn(t.restEncoder,n),nn(t.restEncoder,e)})),t),xi=t=>((t,n=new vi)=>(t instanceof Map?ki(n,t):((t,n)=>{ki(t,Di(n.store))})(n,t),n.toUint8Array()))(t,new fi);class Mi{constructor(){this.l=[]}}const Si=()=>new Mi,Ci=(t,n)=>t.l.push(n),Ui=(t,n)=>{const e=t.l,r=e.length;t.l=e.filter((t=>n!==t)),r===t.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},Ei=(t,n,e)=>ie(t.l,[n,e]);class ji{constructor(t,n){this.client=t,this.clock=n}}const Ti=(t,n)=>t===n||null!==t&&null!==n&&t.client===n.client&&t.clock===n.clock,Ii=(t,n)=>new ji(t,n),Oi=(t,n)=>{for(;null!==n;){if(n.parent===t)return!0;n=n.parent._item}return!1},_i=(t,n)=>void 0===n?!t.deleted:n.sv.has(t.id.client)&&(n.sv.get(t.id.client)||0)>t.id.clock&&!Zr(n.ds,t.id),zi=(t,n)=>{const e=mt(t.meta,zi,At),r=t.doc.store;e.has(n)||(n.sv.forEach(((n,e)=>{n<Pi(r,e)&&Fi(t,Ii(e,n))})),Jr(t,n.ds,(()=>{})),e.add(n))};class $i{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const Di=t=>{const n=new Map;return t.clients.forEach(((t,e)=>{const r=t[t.length-1];n.set(e,r.id.clock+r.length)})),n},Pi=(t,n)=>{const e=t.clients.get(n);if(void 0===e)return 0;const r=e[e.length-1];return r.id.clock+r.length},Ri=(t,n)=>{let e=t.clients.get(n.id.client);if(void 0===e)e=[],t.clients.set(n.id.client,e);else{const t=e[e.length-1];if(t.id.clock+t.length!==n.id.clock)throw mn()}e.push(n)},Bi=(t,n)=>{let e=0,r=t.length-1,i=t[r],s=i.id.clock;if(s===n)return r;let o=Tt(n/(s+i.length-1)*r);for(;e<=r;){if(i=t[o],s=i.id.clock,s<=n){if(n<s+i.length)return o;e=o+1}else r=o-1;o=Tt((e+r)/2)}throw mn()},Wi=(t,n)=>{const e=t.clients.get(n.client);return e[Bi(e,n.clock)]},Li=(t,n,e)=>{const r=Bi(n,e),i=n[r];return i.id.clock<e&&i instanceof Po?(n.splice(r+1,0,zo(t,i,e-i.id.clock)),r+1):r},Fi=(t,n)=>{const e=t.doc.store.clients.get(n.client);return e[Li(t,e,n.clock)]},Ni=(t,n,e)=>{const r=n.clients.get(e.client),i=Bi(r,e.clock),s=r[i];return e.clock!==s.id.clock+s.length-1&&s.constructor!==lo&&r.splice(i+1,0,zo(t,s,e.clock-s.id.clock+1)),s},Ki=(t,n,e,r,i)=>{if(0===r)return;const s=e+r;let o,u=Li(t,n,e);do{o=n[u++],s<o.id.clock+o.length&&Li(t,n,s),i(o)}while(u<n.length&&n[u].id.clock<s)};class Qi{constructor(t,n,e){this.doc=t,this.deleteSet=new Gr,this.beforeState=Di(t.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=n,this.meta=new Map,this.local=e,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}}const Yi=(t,n)=>!(0===n.deleteSet.clients.size&&!(t=>{for(const[r,i]of t)if(e=i,n.beforeState.get(r)!==e)return!0;var e;return!1})(n.afterState)||(ti(n.deleteSet),((t,n)=>{wi(t,n.doc.store,n.beforeState)})(t,n),ri(t,n.deleteSet),0)),Hi=(t,n,e)=>{const r=n._item;(null===r||r.id.clock<(t.beforeState.get(r.id.client)||0)&&!r.deleted)&&mt(t.changed,n,At).add(e)},Vi=(t,n)=>{let e=t[n],r=t[n-1],i=n;for(;i>0&&r.deleted===e.deleted&&r.constructor===e.constructor&&r.mergeWith(e);e=r,r=t[--i-1])e instanceof Po&&null!==e.parentSub&&e.parent._map.get(e.parentSub)===e&&e.parent._map.set(e.parentSub,r);const s=n-i;return s&&t.splice(n+1-s,s),s},Xi=(t,n)=>{if(n<t.length){const e=t[n],r=e.doc,i=r.store,s=e.deleteSet,o=e._mergeStructs;try{ti(s),e.afterState=Di(e.doc.store),r.emit("beforeObserverCalls",[e,r]);const t=[];e.changed.forEach(((n,r)=>t.push((()=>{null!==r._item&&r._item.deleted||r._callObserver(e,n)})))),t.push((()=>{e.changedParentTypes.forEach(((t,n)=>{n._dEH.l.length>0&&(null===n._item||!n._item.deleted)&&((t=t.filter((t=>null===t.target._item||!t.target._item.deleted))).forEach((t=>{t.currentTarget=n,t._path=null})),t.sort(((t,n)=>t.path.length-n.path.length)),Ei(n._dEH,t,e))}))})),t.push((()=>r.emit("afterTransaction",[e,r]))),ie(t,[]),e._needFormattingCleanup&&to(e)}finally{r.gc&&((t,n,e)=>{for(const[r,i]of t.clients.entries()){const t=n.clients.get(r);for(let r=i.length-1;r>=0;r--){const s=i[r],o=s.clock+s.len;for(let r=Bi(t,s.clock),i=t[r];r<t.length&&i.id.clock<o;i=t[++r]){const i=t[r];if(s.clock+s.len<=i.id.clock)break;i instanceof Po&&i.deleted&&!i.keep&&e(i)&&i.gc(n,!1)}}}})(s,i,r.gcFilter),((t,n)=>{t.clients.forEach(((t,e)=>{const r=n.clients.get(e);for(let n=t.length-1;n>=0;n--){const e=t[n];for(let t=Ot(r.length-1,1+Bi(r,e.clock+e.len-1)),n=r[t];t>0&&n.id.clock>=e.clock;n=r[t])t-=1+Vi(r,t)}}))})(s,i),e.afterState.forEach(((t,n)=>{const r=e.beforeState.get(n)||0;if(r!==t){const t=i.clients.get(n),e=_t(Bi(t,r),1);for(let n=t.length-1;n>=e;)n-=1+Vi(t,n)}}));for(let t=o.length-1;t>=0;t--){const{client:n,clock:e}=o[t].id,r=i.clients.get(n),s=Bi(r,e);s+1<r.length&&Vi(r,s+1)>1||s>0&&Vi(r,s)}if(e.local||e.afterState.get(r.clientID)===e.beforeState.get(r.clientID)||(((...t)=>{console.log(...Qr(t)),Hr.forEach((n=>n.print(t)))})(Fr,$r,"[yjs] ",Dr,Wr,"Changed the client-id because another client seems to be using it."),r.clientID=oi()),r.emit("afterTransactionCleanup",[e,r]),r._observers.has("update")){const t=new di;Yi(t,e)&&r.emit("update",[t.toUint8Array(),e.origin,r,e])}if(r._observers.has("updateV2")){const t=new pi;Yi(t,e)&&r.emit("updateV2",[t.toUint8Array(),e.origin,r,e])}const{subdocsAdded:u,subdocsLoaded:c,subdocsRemoved:h}=e;(u.size>0||h.size>0||c.size>0)&&(u.forEach((t=>{t.clientID=r.clientID,null==t.collectionid&&(t.collectionid=r.collectionid),r.subdocs.add(t)})),h.forEach((t=>r.subdocs.delete(t))),r.emit("subdocs",[{loaded:c,added:u,removed:h},r,e]),h.forEach((t=>t.destroy()))),t.length<=n+1?(r._transactionCleanups=[],r.emit("afterAllTransactions",[r,t])):Xi(t,n+1)}}},qi=(t,n,e=null,r=!0)=>{const i=t._transactionCleanups;let s=!1,o=null;null===t._transaction&&(s=!0,t._transaction=new Qi(t,e,r),i.push(t._transaction),1===i.length&&t.emit("beforeAllTransactions",[t]),t.emit("beforeTransaction",[t._transaction,t]));try{o=n(t._transaction)}finally{if(s){const n=t._transaction===i[0];t._transaction=null,n&&Xi(i,0)}}return o};class Gi{constructor(t,n){this.insertions=n,this.deletions=t,this.meta=new Map}}const Ji=(t,n,e)=>{Jr(t,e.deletions,(e=>{e instanceof Po&&n.scope.some((n=>n===t.doc||Oi(n,e)))&&_o(e,!1)}))},Zi=(t,n,e)=>{let r=null;const i=t.doc,s=t.scope;qi(i,(e=>{for(;n.length>0&&null===t.currStackItem;){const r=i.store,o=n.pop(),u=new Set,c=[];let h=!1;Jr(e,o.insertions,(t=>{if(t instanceof Po){if(null!==t.redone){let{item:n,diff:i}=Oo(r,t.id);i>0&&(n=Fi(e,Ii(n.id.client,n.id.clock+i))),t=n}!t.deleted&&s.some((n=>n===e.doc||Oi(n,t)))&&c.push(t)}})),Jr(e,o.deletions,(t=>{t instanceof Po&&s.some((n=>n===e.doc||Oi(n,t)))&&!Zr(o.insertions,t.id)&&u.add(t)})),u.forEach((n=>{h=null!==Do(e,n,u,o.insertions,t.ignoreRemoteMapChanges,t)||h}));for(let n=c.length-1;n>=0;n--){const r=c[n];t.deleteFilter(r)&&(r.delete(e),h=!0)}t.currStackItem=h?o:null}e.changed.forEach(((t,n)=>{t.has(null)&&n._searchMarker&&(n._searchMarker.length=0)})),r=e}),t);const o=t.currStackItem;return null!=o&&(t.emit("stack-item-popped",[{stackItem:o,type:e,changedParentTypes:r.changedParentTypes,origin:t},t]),t.currStackItem=null),o};class ts extends Et{constructor(t,{captureTimeout:n=500,captureTransaction:e=()=>!0,deleteFilter:r=()=>!0,trackedOrigins:i=new Set([null]),ignoreRemoteMapChanges:s=!1,doc:o=(Ut(t)?t[0].doc:t instanceof ui?t:t.doc)}={}){super(),this.scope=[],this.doc=o,this.addToScope(t),this.deleteFilter=r,i.add(this),this.trackedOrigins=i,this.captureTransaction=e,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=s,this.captureTimeout=n,this.afterTransactionHandler=t=>{if(!(this.captureTransaction(t)&&this.scope.some((n=>t.changedParentTypes.has(n)||n===this.doc))&&(this.trackedOrigins.has(t.origin)||t.origin&&this.trackedOrigins.has(t.origin.constructor))))return;const n=this.undoing,e=this.redoing,r=n?this.redoStack:this.undoStack;n?this.stopCapturing():e||this.clear(!1,!0);const i=new Gr;t.afterState.forEach(((n,e)=>{const r=t.beforeState.get(e)||0,s=n-r;s>0&&ei(i,e,r,s)}));const s=Ln();let o=!1;if(this.lastChange>0&&s-this.lastChange<this.captureTimeout&&r.length>0&&!n&&!e){const n=r[r.length-1];n.deletions=ni([n.deletions,t.deleteSet]),n.insertions=ni([n.insertions,i])}else r.push(new Gi(t.deleteSet,i)),o=!0;n||e||(this.lastChange=s),Jr(t,t.deleteSet,(n=>{n instanceof Po&&this.scope.some((e=>e===t.doc||Oi(e,n)))&&_o(n,!0)}));this.emit(o?"stack-item-added":"stack-item-updated",[{stackItem:r[r.length-1],origin:t.origin,type:n?"redo":"undo",changedParentTypes:t.changedParentTypes},this])},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",(()=>{this.destroy()}))}addToScope(t){const n=new Set(this.scope);(t=Ut(t)?t:[t]).forEach((t=>{n.has(t)||(n.add(t),(t instanceof As?t.doc!==this.doc:t!==this.doc)&&Yr("[yjs#509] Not same Y.Doc"),this.scope.push(t))}))}addTrackedOrigin(t){this.trackedOrigins.add(t)}removeTrackedOrigin(t){this.trackedOrigins.delete(t)}clear(t=!0,n=!0){(t&&this.canUndo()||n&&this.canRedo())&&this.doc.transact((e=>{t&&(this.undoStack.forEach((t=>Ji(e,this,t))),this.undoStack=[]),n&&(this.redoStack.forEach((t=>Ji(e,this,t))),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:t,redoStackCleared:n}])}))}stopCapturing(){this.lastChange=0}undo(){let t;this.undoing=!0;try{t=Zi(this,this.undoStack,"undo")}finally{this.undoing=!1}return t}redo(){let t;this.redoing=!0;try{t=Zi(this,this.redoStack,"redo")}finally{this.redoing=!1}return t}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off("afterTransaction",this.afterTransactionHandler),super.destroy()}}class ns{constructor(t,n){this.gen=function*(t){const n=Un(t.restDecoder);for(let e=0;e<n;e++){const n=Un(t.restDecoder),e=t.readClient();let r=Un(t.restDecoder);for(let i=0;i<n;i++){const n=t.readInfo();if(10===n){const n=Un(t.restDecoder);yield new Wo(Ii(e,r),n),r+=n}else if(31&n){const i=!(192&n),s=new Po(Ii(e,r),null,(n&Pt)===Pt?t.readLeftID():null,null,(n&Dt)===Dt?t.readRightID():null,i?t.readParentInfo()?t.readString():t.readLeftID():null,!i||32&~n?null:t.readString(),Ro(t,n));yield s,r+=s.length}else{const n=t.readLen();yield new lo(Ii(e,r),n),r+=n}}}}(t),this.curr=null,this.done=!1,this.filterSkips=n,this.next()}next(){do{this.curr=this.gen.next().value||null}while(this.filterSkips&&null!==this.curr&&this.curr.constructor===Wo);return this.curr}}class es{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}}const rs=t=>ss(t,hi,di),is=(t,n)=>{if(t.constructor===lo){const{client:e,clock:r}=t.id;return new lo(Ii(e,r+n),t.length-n)}if(t.constructor===Wo){const{client:e,clock:r}=t.id;return new Wo(Ii(e,r+n),t.length-n)}{const e=t,{client:r,clock:i}=e.id;return new Po(Ii(r,i+n),null,Ii(r,i+n-1),null,e.rightOrigin,e.parent,e.parentSub,e.content.splice(n))}},ss=(t,n=li,e=pi)=>{if(1===t.length)return t[0];const r=t.map((t=>new n(Mn(t))));let i=r.map((t=>new ns(t,!0))),s=null;const o=new e,u=new es(o);for(;i=i.filter((t=>null!==t.curr)),i.sort(((t,n)=>{if(t.curr.id.client===n.curr.id.client){const e=t.curr.id.clock-n.curr.id.clock;return 0===e?t.curr.constructor===n.curr.constructor?0:t.curr.constructor===Wo?1:-1:e}return n.curr.id.client-t.curr.id.client})),0!==i.length;){const t=i[0],n=t.curr.id.client;if(null!==s){let e=t.curr,r=!1;for(;null!==e&&e.id.clock+e.length<=s.struct.id.clock+s.struct.length&&e.id.client>=s.struct.id.client;)e=t.next(),r=!0;if(null===e||e.id.client!==n||r&&e.id.clock>s.struct.id.clock+s.struct.length)continue;if(n!==s.struct.id.client)cs(u,s.struct,s.offset),s={struct:e,offset:0},t.next();else if(s.struct.id.clock+s.struct.length<e.id.clock)if(s.struct.constructor===Wo)s.struct.length=e.id.clock+e.length-s.struct.id.clock;else{cs(u,s.struct,s.offset);const t=e.id.clock-s.struct.id.clock-s.struct.length;s={struct:new Wo(Ii(n,s.struct.id.clock+s.struct.length),t),offset:0}}else{const n=s.struct.id.clock+s.struct.length-e.id.clock;n>0&&(s.struct.constructor===Wo?s.struct.length-=n:e=is(e,n)),s.struct.mergeWith(e)||(cs(u,s.struct,s.offset),s={struct:e,offset:0},t.next())}}else s={struct:t.curr,offset:0},t.next();for(let e=t.curr;null!==e&&e.id.client===n&&e.id.clock===s.struct.id.clock+s.struct.length&&e.constructor!==Wo;e=t.next())cs(u,s.struct,s.offset),s={struct:e,offset:0}}null!==s&&(cs(u,s.struct,s.offset),s=null),hs(u);const c=r.map((t=>ii(t))),h=ni(c);return ri(o,h),o.toUint8Array()},os=(t,n,e=li,r=pi)=>{const i=Ai(n),s=new r,o=new es(s),u=new e(Mn(t)),c=new ns(u,!1);for(;c.curr;){const t=c.curr,n=t.id.client,e=i.get(n)||0;if(c.curr.constructor!==Wo)if(t.id.clock+t.length>e)for(cs(o,t,_t(e-t.id.clock,0)),c.next();c.curr&&c.curr.id.client===n;)cs(o,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===n&&c.curr.id.clock+c.curr.length<=e;)c.next();else c.next()}hs(o);const h=ii(u);return ri(s,h),s.toUint8Array()},us=t=>{t.written>0&&(t.clientStructs.push({written:t.written,restEncoder:Jt(t.encoder.restEncoder)}),t.encoder.restEncoder=qt(),t.written=0)},cs=(t,n,e)=>{t.written>0&&t.currClient!==n.id.client&&us(t),0===t.written&&(t.currClient=n.id.client,t.encoder.writeClient(n.id.client),nn(t.encoder.restEncoder,n.id.clock+e)),n.write(t.encoder,e),t.written++},hs=t=>{us(t);const n=t.encoder.restEncoder;nn(n,t.clientStructs.length);for(let e=0;e<t.clientStructs.length;e++){const r=t.clientStructs[e];nn(n,r.written),un(n,r.restEncoder)}},as=t=>((t,n,e,r)=>{const i=new li(Mn(t)),s=new ns(i,!1),o=new r,u=new es(o);for(let t=s.curr;null!==t;t=s.next())cs(u,n(t),0);hs(u);const c=ii(i);return ri(o,c),o.toUint8Array()})(t,se,0,di),ls="You must not compute changes after the event-handler fired.";class fs{constructor(t,n){this.target=t,this.currentTarget=t,this.transaction=n,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=ds(this.currentTarget,this.target))}deletes(t){return Zr(this.transaction.deleteSet,t.id)}get keys(){if(null===this._keys){if(0===this.transaction.doc._transactionCleanups.length)throw gn(ls);const t=new Map,n=this.target;this.transaction.changed.get(n).forEach((e=>{if(null!==e){const r=n._map.get(e);let i,s;if(this.adds(r)){let t=r.left;for(;null!==t&&this.adds(t);)t=t.left;if(this.deletes(r)){if(null===t||!this.deletes(t))return;i="delete",s=kt(t.content.getContent())}else null!==t&&this.deletes(t)?(i="update",s=kt(t.content.getContent())):(i="add",s=void 0)}else{if(!this.deletes(r))return;i="delete",s=kt(r.content.getContent())}t.set(e,{action:i,oldValue:s})}})),this._keys=t}return this._keys}get delta(){return this.changes.delta}adds(t){return t.id.clock>=(this.transaction.beforeState.get(t.id.client)||0)}get changes(){let t=this._changes;if(null===t){if(0===this.transaction.doc._transactionCleanups.length)throw gn(ls);const n=this.target,e=At(),r=At(),i=[];if(t={added:e,deleted:r,delta:i,keys:this.keys},this.transaction.changed.get(n).has(null)){let t=null;const s=()=>{t&&i.push(t)};for(let i=n._start;null!==i;i=i.right)i.deleted?this.deletes(i)&&!this.adds(i)&&(null!==t&&void 0!==t.delete||(s(),t={delete:0}),t.delete+=i.length,r.add(i)):this.adds(i)?(null!==t&&void 0!==t.insert||(s(),t={insert:[]}),t.insert=t.insert.concat(i.content.getContent()),e.add(i)):(null!==t&&void 0!==t.retain||(s(),t={retain:0}),t.retain+=i.length);null!==t&&void 0===t.retain&&s()}this._changes=t}return t}}const ds=(t,n)=>{const e=[];for(;null!==n._item&&n!==t;){if(null!==n._item.parentSub)e.unshift(n._item.parentSub);else{let t=0,r=n._item.parent._start;for(;r!==n._item&&null!==r;)!r.deleted&&r.countable&&(t+=r.length),r=r.right;e.unshift(t)}n=n._item.parent}return e},vs=()=>{Yr("Invalid access: Add Yjs type to a document before reading data.")};let ps=0;class ws{constructor(t,n){t.marker=!0,this.p=t,this.index=n,this.timestamp=ps++}}const ys=(t,n,e)=>{t.p.marker=!1,t.p=n,n.marker=!0,t.index=e,t.timestamp=ps++},gs=(t,n)=>{if(null===t._start||0===n||null===t._searchMarker)return null;const e=0===t._searchMarker.length?null:t._searchMarker.reduce(((t,e)=>It(n-t.index)<It(n-e.index)?t:e));let r=t._start,i=0;for(null!==e&&(r=e.p,i=e.index,(t=>{t.timestamp=ps++})(e));null!==r.right&&i<n;){if(!r.deleted&&r.countable){if(n<i+r.length)break;i+=r.length}r=r.right}for(;null!==r.left&&i>n;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);for(;null!==r.left&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);return null!==e&&It(e.index-i)<r.parent.length/80?(ys(e,r,i),e):((t,n,e)=>{if(t.length>=80){const r=t.reduce(((t,n)=>t.timestamp<n.timestamp?t:n));return ys(r,n,e),r}{const r=new ws(n,e);return t.push(r),r}})(t._searchMarker,r,i)},bs=(t,n,e)=>{for(let r=t.length-1;r>=0;r--){const i=t[r];if(e>0){let n=i.p;for(n.marker=!1;n&&(n.deleted||!n.countable);)n=n.left,n&&!n.deleted&&n.countable&&(i.index-=n.length);if(null===n||!0===n.marker){t.splice(r,1);continue}i.p=n,n.marker=!0}(n<i.index||e>0&&n===i.index)&&(i.index=_t(n,i.index+e))}},ms=(t,n,e)=>{const r=t,i=n.changedParentTypes;for(;mt(i,t,(()=>[])).push(e),null!==t._item;)t=t._item.parent;Ei(r._eH,e,n)};class As{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=Si(),this._dEH=Si(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,n){this.doc=t,this._item=n}_copy(){throw bn()}clone(){throw bn()}_write(t){}get _first(){let t=this._start;for(;null!==t&&t.deleted;)t=t.right;return t}_callObserver(t,n){!t.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(t){Ci(this._eH,t)}observeDeep(t){Ci(this._dEH,t)}unobserve(t){Ui(this._eH,t)}unobserveDeep(t){Ui(this._dEH,t)}toJSON(){}}const ks=(t,n,e)=>{t.doc??vs(),n<0&&(n=t._length+n),e<0&&(e=t._length+e);let r=e-n;const i=[];let s=t._start;for(;null!==s&&r>0;){if(s.countable&&!s.deleted){const t=s.content.getContent();if(t.length<=n)n-=t.length;else{for(let e=n;e<t.length&&r>0;e++)i.push(t[e]),r--;n=0}}s=s.right}return i},xs=t=>{t.doc??vs();const n=[];let e=t._start;for(;null!==e;){if(e.countable&&!e.deleted){const t=e.content.getContent();for(let e=0;e<t.length;e++)n.push(t[e])}e=e.right}return n},Ms=(t,n)=>{let e=0,r=t._start;for(t.doc??vs();null!==r;){if(r.countable&&!r.deleted){const i=r.content.getContent();for(let r=0;r<i.length;r++)n(i[r],e++,t)}r=r.right}},Ss=(t,n)=>{const e=[];return Ms(t,((r,i)=>{e.push(n(r,i,t))})),e},Cs=t=>{let n=t._start,e=null,r=0;return{[Symbol.iterator](){return this},next:()=>{if(null===e){for(;null!==n&&n.deleted;)n=n.right;if(null===n)return{done:!0,value:void 0};e=n.content.getContent(),r=0,n=n.right}const t=e[r++];return e.length<=r&&(e=null),{done:!1,value:t}}}},Us=(t,n)=>{t.doc??vs();const e=gs(t,n);let r=t._start;for(null!==e&&(r=e.p,n-=e.index);null!==r;r=r.right)if(!r.deleted&&r.countable){if(n<r.length)return r.content.getContent()[n];n-=r.length}},Es=(t,n,e,r)=>{let i=e;const s=t.doc,o=s.clientID,u=s.store,c=null===e?n._start:e.right;let h=[];const a=()=>{h.length>0&&(i=new Po(Ii(o,Pi(u,o)),i,i&&i.lastId,c,c&&c.id,n,null,new Ao(h)),i.integrate(t,0),h=[])};r.forEach((e=>{if(null===e)h.push(e);else switch(e.constructor){case Number:case Object:case Boolean:case Array:case String:h.push(e);break;default:switch(a(),e.constructor){case Uint8Array:case ArrayBuffer:i=new Po(Ii(o,Pi(u,o)),i,i&&i.lastId,c,c&&c.id,n,null,new fo(new Uint8Array(e))),i.integrate(t,0);break;case ui:i=new Po(Ii(o,Pi(u,o)),i,i&&i.lastId,c,c&&c.id,n,null,new wo(e)),i.integrate(t,0);break;default:if(!(e instanceof As))throw new Error("Unexpected content type in insert operation");i=new Po(Ii(o,Pi(u,o)),i,i&&i.lastId,c,c&&c.id,n,null,new Io(e)),i.integrate(t,0)}}})),a()},js=()=>gn("Length exceeded!"),Ts=(t,n,e,r)=>{if(e>n._length)throw js();if(0===e)return n._searchMarker&&bs(n._searchMarker,e,r.length),Es(t,n,null,r);const i=e,s=gs(n,e);let o=n._start;for(null!==s&&(o=s.p,0==(e-=s.index)&&(o=o.prev,e+=o&&o.countable&&!o.deleted?o.length:0));null!==o;o=o.right)if(!o.deleted&&o.countable){if(e<=o.length){e<o.length&&Fi(t,Ii(o.id.client,o.id.clock+e));break}e-=o.length}return n._searchMarker&&bs(n._searchMarker,i,r.length),Es(t,n,o,r)},Is=(t,n,e,r)=>{if(0===r)return;const i=e,s=r,o=gs(n,e);let u=n._start;for(null!==o&&(u=o.p,e-=o.index);null!==u&&e>0;u=u.right)!u.deleted&&u.countable&&(e<u.length&&Fi(t,Ii(u.id.client,u.id.clock+e)),e-=u.length);for(;r>0&&null!==u;)u.deleted||(r<u.length&&Fi(t,Ii(u.id.client,u.id.clock+r)),u.delete(t),r-=u.length),u=u.right;if(r>0)throw js();n._searchMarker&&bs(n._searchMarker,i,-s+r)},Os=(t,n,e)=>{const r=n._map.get(e);void 0!==r&&r.delete(t)},_s=(t,n,e,r)=>{const i=n._map.get(e)||null,s=t.doc,o=s.clientID;let u;if(null==r)u=new Ao([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:u=new Ao([r]);break;case Uint8Array:u=new fo(r);break;case ui:u=new wo(r);break;default:if(!(r instanceof As))throw new Error("Unexpected content type");u=new Io(r)}new Po(Ii(o,Pi(s.store,o)),i,i&&i.lastId,null,null,n,e,u).integrate(t,0)},zs=(t,n)=>{t.doc??vs();const e=t._map.get(n);return void 0===e||e.deleted?void 0:e.content.getContent()[e.length-1]},$s=t=>{const n={};return t.doc??vs(),t._map.forEach(((t,e)=>{t.deleted||(n[e]=t.content.getContent()[t.length-1])})),n},Ds=(t,n)=>{t.doc??vs();const e=t._map.get(n);return void 0!==e&&!e.deleted},Ps=t=>{return t.doc??vs(),n=t._map.entries(),e=t=>!t[1].deleted,Vr((()=>{let t;do{t=n.next()}while(!t.done&&!e(t.value));return t}));var n,e};class Rs extends fs{}class Bs extends As{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){const n=new Bs;return n.push(t),n}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Bs}clone(){const t=new Bs;return t.insert(0,this.toArray().map((t=>t instanceof As?t.clone():t))),t}get length(){return this.doc??vs(),this._length}_callObserver(t,n){super._callObserver(t,n),ms(this,t,new Rs(this,t))}insert(t,n){null!==this.doc?qi(this.doc,(e=>{Ts(e,this,t,n)})):this._prelimContent.splice(t,0,...n)}push(t){null!==this.doc?qi(this.doc,(n=>{((t,n,e)=>{let r=(n._searchMarker||[]).reduce(((t,n)=>n.index>t.index?n:t),{index:0,p:n._start}).p;if(r)for(;r.right;)r=r.right;Es(t,n,r,e)})(n,this,t)})):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,n=1){null!==this.doc?qi(this.doc,(e=>{Is(e,this,t,n)})):this._prelimContent.splice(t,n)}get(t){return Us(this,t)}toArray(){return xs(this)}slice(t=0,n=this.length){return ks(this,t,n)}toJSON(){return this.map((t=>t instanceof As?t.toJSON():t))}map(t){return Ss(this,t)}forEach(t){Ms(this,t)}[Symbol.iterator](){return Cs(this)}_write(t){t.writeTypeRef(Mo)}}class Ws extends fs{constructor(t,n,e){super(t,n),this.keysChanged=e}}class Ls extends As{constructor(t){super(),this._prelimContent=null,this._prelimContent=void 0===t?new Map:new Map(t)}_integrate(t,n){super._integrate(t,n),this._prelimContent.forEach(((t,n)=>{this.set(n,t)})),this._prelimContent=null}_copy(){return new Ls}clone(){const t=new Ls;return this.forEach(((n,e)=>{t.set(e,n instanceof As?n.clone():n)})),t}_callObserver(t,n){ms(this,t,new Ws(this,t,n))}toJSON(){this.doc??vs();const t={};return this._map.forEach(((n,e)=>{if(!n.deleted){const r=n.content.getContent()[n.length-1];t[e]=r instanceof As?r.toJSON():r}})),t}get size(){return[...Ps(this)].length}keys(){return Xr(Ps(this),(t=>t[0]))}values(){return Xr(Ps(this),(t=>t[1].content.getContent()[t[1].length-1]))}entries(){return Xr(Ps(this),(t=>[t[0],t[1].content.getContent()[t[1].length-1]]))}forEach(t){this.doc??vs(),this._map.forEach(((n,e)=>{n.deleted||t(n.content.getContent()[n.length-1],e,this)}))}[Symbol.iterator](){return this.entries()}delete(t){null!==this.doc?qi(this.doc,(n=>{Os(n,this,t)})):this._prelimContent.delete(t)}set(t,n){return null!==this.doc?qi(this.doc,(e=>{_s(e,this,t,n)})):this._prelimContent.set(t,n),n}get(t){return zs(this,t)}has(t){return Ds(this,t)}clear(){null!==this.doc?qi(this.doc,(t=>{this.forEach((function(n,e,r){Os(t,r,e)}))})):this._prelimContent.clear()}_write(t){t.writeTypeRef(So)}}const Fs=(t,n)=>t===n||"object"==typeof t&&"object"==typeof n&&t&&n&&((t,n)=>t===n||Zn(t)===Zn(n)&&te(t,((t,e)=>(void 0!==t||ne(n,e))&&Xn(n[e],t))))(t,n);class Ns{constructor(t,n,e,r){this.left=t,this.right=n,this.index=e,this.currentAttributes=r}forward(){null===this.right&&mn(),this.right.content.constructor===go?this.right.deleted||Hs(this.currentAttributes,this.right.content):this.right.deleted||(this.index+=this.right.length),this.left=this.right,this.right=this.right.right}}const Ks=(t,n,e)=>{for(;null!==n.right&&e>0;)n.right.content.constructor===go?n.right.deleted||Hs(n.currentAttributes,n.right.content):n.right.deleted||(e<n.right.length&&Fi(t,Ii(n.right.id.client,n.right.id.clock+e)),n.index+=n.right.length,e-=n.right.length),n.left=n.right,n.right=n.right.right;return n},Qs=(t,n,e,r)=>{const i=new Map,s=r?gs(n,e):null;if(s){const n=new Ns(s.p.left,s.p,s.index,i);return Ks(t,n,e-s.index)}{const r=new Ns(null,n._start,0,i);return Ks(t,r,e)}},Ys=(t,n,e,r)=>{for(;null!==e.right&&(!0===e.right.deleted||e.right.content.constructor===go&&Fs(r.get(e.right.content.key),e.right.content.value));)e.right.deleted||r.delete(e.right.content.key),e.forward();const i=t.doc,s=i.clientID;r.forEach(((r,o)=>{const u=e.left,c=e.right,h=new Po(Ii(s,Pi(i.store,s)),u,u&&u.lastId,c,c&&c.id,n,null,new go(o,r));h.integrate(t,0),e.right=h,e.forward()}))},Hs=(t,n)=>{const{key:e,value:r}=n;null===r?t.delete(e):t.set(e,r)},Vs=(t,n)=>{for(;null!==t.right&&(t.right.deleted||t.right.content.constructor===go&&Fs(n[t.right.content.key]??null,t.right.content.value));)t.forward()},Xs=(t,n,e,r)=>{const i=t.doc,s=i.clientID,o=new Map;for(const u in r){const c=r[u],h=e.currentAttributes.get(u)??null;if(!Fs(h,c)){o.set(u,h);const{left:r,right:a}=e;e.right=new Po(Ii(s,Pi(i.store,s)),r,r&&r.lastId,a,a&&a.id,n,null,new go(u,c)),e.right.integrate(t,0),e.forward()}}return o},qs=(t,n,e,r,i)=>{e.currentAttributes.forEach(((t,n)=>{void 0===i[n]&&(i[n]=null)}));const s=t.doc,o=s.clientID;Vs(e,i);const u=Xs(t,n,e,i),c=r.constructor===String?new ko(r):r instanceof As?new Io(r):new yo(r);let{left:h,right:a,index:l}=e;n._searchMarker&&bs(n._searchMarker,e.index,c.getLength()),a=new Po(Ii(o,Pi(s.store,o)),h,h&&h.lastId,a,a&&a.id,n,null,c),a.integrate(t,0),e.right=a,e.index=l,e.forward(),Ys(t,n,e,u)},Gs=(t,n,e,r,i)=>{const s=t.doc,o=s.clientID;Vs(e,i);const u=Xs(t,n,e,i);t:for(;null!==e.right&&(r>0||u.size>0&&(e.right.deleted||e.right.content.constructor===go));){if(!e.right.deleted)switch(e.right.content.constructor){case go:{const{key:n,value:s}=e.right.content,o=i[n];if(void 0!==o){if(Fs(o,s))u.delete(n);else{if(0===r)break t;u.set(n,s)}e.right.delete(t)}else e.currentAttributes.set(n,s);break}default:r<e.right.length&&Fi(t,Ii(e.right.id.client,e.right.id.clock+r)),r-=e.right.length}e.forward()}if(r>0){let i="";for(;r>0;r--)i+="\n";e.right=new Po(Ii(o,Pi(s.store,o)),e.left,e.left&&e.left.lastId,e.right,e.right&&e.right.id,n,null,new ko(i)),e.right.integrate(t,0),e.forward()}Ys(t,n,e,u)},Js=(t,n,e,r,i)=>{let s=n;const o=gt();for(;s&&(!s.countable||s.deleted);){if(!s.deleted&&s.content.constructor===go){const t=s.content;o.set(t.key,t)}s=s.right}let u=0,c=!1;for(;n!==s;){if(e===n&&(c=!0),!n.deleted){const e=n.content;switch(e.constructor){case go:{const{key:s,value:h}=e,a=r.get(s)??null;o.get(s)===e&&a!==h||(n.delete(t),u++,c||(i.get(s)??null)!==h||a===h||(null===a?i.delete(s):i.set(s,a))),c||n.deleted||Hs(i,e);break}}}n=n.right}return u},Zs=t=>{let n=0;return qi(t.doc,(e=>{let r=t._start,i=t._start,s=gt();const o=bt(s);for(;i;)!1===i.deleted&&(i.content.constructor===go?Hs(o,i.content):(n+=Js(e,r,i,s,o),s=bt(o),r=i)),i=i.right})),n},to=t=>{const n=new Set,e=t.doc;for(const[r,i]of t.afterState.entries()){const s=t.beforeState.get(r)||0;i!==s&&Ki(t,e.store.clients.get(r),s,i,(t=>{t.deleted||t.content.constructor!==go||t.constructor===lo||n.add(t.parent)}))}qi(e,(e=>{Jr(t,t.deleteSet,(t=>{t instanceof lo||!t.parent._hasFormatting||n.has(t.parent)||(t.content.constructor===go?n.add(t.parent):((t,n)=>{for(;n&&n.right&&(n.right.deleted||!n.right.countable);)n=n.right;const e=new Set;for(;n&&(n.deleted||!n.countable);){if(!n.deleted&&n.content.constructor===go){const r=n.content.key;e.has(r)?n.delete(t):e.add(r)}n=n.left}})(e,t))}));for(const t of n)Zs(t)}))},no=(t,n,e)=>{const r=e,i=bt(n.currentAttributes),s=n.right;for(;e>0&&null!==n.right;){if(!1===n.right.deleted)switch(n.right.content.constructor){case Io:case yo:case ko:e<n.right.length&&Fi(t,Ii(n.right.id.client,n.right.id.clock+e)),e-=n.right.length,n.right.delete(t)}n.forward()}s&&Js(t,s,n.right,i,n.currentAttributes);const o=(n.left||n.right).parent;return o._searchMarker&&bs(o._searchMarker,n.index,-r+e),n};class eo extends fs{constructor(t,n,e){super(t,n),this.childListChanged=!1,this.keysChanged=new Set,e.forEach((t=>{null===t?this.childListChanged=!0:this.keysChanged.add(t)}))}get changes(){if(null===this._changes){const t={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=t}return this._changes}get delta(){if(null===this._delta){const t=[];qi(this.target.doc,(n=>{const e=new Map,r=new Map;let i=this.target._start,s=null;const o={};let u="",c=0,h=0;const a=()=>{if(null!==s){let n=null;switch(s){case"delete":h>0&&(n={delete:h}),h=0;break;case"insert":("object"==typeof u||u.length>0)&&(n={insert:u},e.size>0&&(n.attributes={},e.forEach(((t,e)=>{null!==t&&(n.attributes[e]=t)})))),u="";break;case"retain":c>0&&(n={retain:c},(t=>{for(const n in t)return!1;return!0})(o)||(n.attributes=qn({},o))),c=0}n&&t.push(n),s=null}};for(;null!==i;){switch(i.content.constructor){case Io:case yo:this.adds(i)?this.deletes(i)||(a(),s="insert",u=i.content.getContent()[0],a()):this.deletes(i)?("delete"!==s&&(a(),s="delete"),h+=1):i.deleted||("retain"!==s&&(a(),s="retain"),c+=1);break;case ko:this.adds(i)?this.deletes(i)||("insert"!==s&&(a(),s="insert"),u+=i.content.str):this.deletes(i)?("delete"!==s&&(a(),s="delete"),h+=i.length):i.deleted||("retain"!==s&&(a(),s="retain"),c+=i.length);break;case go:{const{key:t,value:u}=i.content;if(this.adds(i)){if(!this.deletes(i)){const c=e.get(t)??null;Fs(c,u)?null!==u&&i.delete(n):("retain"===s&&a(),Fs(u,r.get(t)??null)?delete o[t]:o[t]=u)}}else if(this.deletes(i)){r.set(t,u);const n=e.get(t)??null;Fs(n,u)||("retain"===s&&a(),o[t]=n)}else if(!i.deleted){r.set(t,u);const e=o[t];void 0!==e&&(Fs(e,u)?null!==e&&i.delete(n):("retain"===s&&a(),null===u?delete o[t]:o[t]=u))}i.deleted||("insert"===s&&a(),Hs(e,i.content));break}}i=i.right}for(a();t.length>0;){const n=t[t.length-1];if(void 0===n.retain||void 0!==n.attributes)break;t.pop()}})),this._delta=t}return this._delta}}class ro extends As{constructor(t){super(),this._pending=void 0!==t?[()=>this.insert(0,t)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??vs(),this._length}_integrate(t,n){super._integrate(t,n);try{this._pending.forEach((t=>t()))}catch(t){console.error(t)}this._pending=null}_copy(){return new ro}clone(){const t=new ro;return t.applyDelta(this.toDelta()),t}_callObserver(t,n){super._callObserver(t,n);const e=new eo(this,t,n);ms(this,t,e),!t.local&&this._hasFormatting&&(t._needFormattingCleanup=!0)}toString(){this.doc??vs();let t="",n=this._start;for(;null!==n;)!n.deleted&&n.countable&&n.content.constructor===ko&&(t+=n.content.str),n=n.right;return t}toJSON(){return this.toString()}applyDelta(t,{sanitize:n=!0}={}){null!==this.doc?qi(this.doc,(e=>{const r=new Ns(null,this._start,0,new Map);for(let i=0;i<t.length;i++){const s=t[i];if(void 0!==s.insert){const o=n||"string"!=typeof s.insert||i!==t.length-1||null!==r.right||"\n"!==s.insert.slice(-1)?s.insert:s.insert.slice(0,-1);("string"!=typeof o||o.length>0)&&qs(e,this,r,o,s.attributes||{})}else void 0!==s.retain?Gs(e,this,r,s.retain,s.attributes||{}):void 0!==s.delete&&no(e,r,s.delete)}})):this._pending.push((()=>this.applyDelta(t)))}toDelta(t,n,e){this.doc??vs();const r=[],i=new Map;let s="",o=this._start;function u(){if(s.length>0){const t={};let n=!1;i.forEach(((e,r)=>{n=!0,t[r]=e}));const e={insert:s};n&&(e.attributes=t),r.push(e),s=""}}const c=()=>{for(;null!==o;){if(_i(o,t)||void 0!==n&&_i(o,n))switch(o.content.constructor){case ko:{const r=i.get("ychange");void 0===t||_i(o,t)?void 0===n||_i(o,n)?void 0!==r&&(u(),i.delete("ychange")):void 0!==r&&r.user===o.id.client&&"added"===r.type||(u(),i.set("ychange",e?e("added",o.id):{type:"added"})):void 0!==r&&r.user===o.id.client&&"removed"===r.type||(u(),i.set("ychange",e?e("removed",o.id):{type:"removed"})),s+=o.content.str;break}case Io:case yo:{u();const t={insert:o.content.getContent()[0]};if(i.size>0){const n={};t.attributes=n,i.forEach(((t,e)=>{n[e]=t}))}r.push(t);break}case go:_i(o,t)&&(u(),Hs(i,o.content))}o=o.right}u()};return t||n?qi(this.doc,(e=>{t&&zi(e,t),n&&zi(e,n),c()}),"cleanup"):c(),r}insert(t,n,e){if(n.length<=0)return;const r=this.doc;null!==r?qi(r,(r=>{const i=Qs(r,this,t,!e);e||(e={},i.currentAttributes.forEach(((t,n)=>{e[n]=t}))),qs(r,this,i,n,e)})):this._pending.push((()=>this.insert(t,n,e)))}insertEmbed(t,n,e){const r=this.doc;null!==r?qi(r,(r=>{const i=Qs(r,this,t,!e);qs(r,this,i,n,e||{})})):this._pending.push((()=>this.insertEmbed(t,n,e||{})))}delete(t,n){if(0===n)return;const e=this.doc;null!==e?qi(e,(e=>{no(e,Qs(e,this,t,!0),n)})):this._pending.push((()=>this.delete(t,n)))}format(t,n,e){if(0===n)return;const r=this.doc;null!==r?qi(r,(r=>{const i=Qs(r,this,t,!1);null!==i.right&&Gs(r,this,i,n,e)})):this._pending.push((()=>this.format(t,n,e)))}removeAttribute(t){null!==this.doc?qi(this.doc,(n=>{Os(n,this,t)})):this._pending.push((()=>this.removeAttribute(t)))}setAttribute(t,n){null!==this.doc?qi(this.doc,(e=>{_s(e,this,t,n)})):this._pending.push((()=>this.setAttribute(t,n)))}getAttribute(t){return zs(this,t)}getAttributes(){return $s(this)}_write(t){t.writeTypeRef(Co)}}class io{constructor(t,n=()=>!0){this._filter=n,this._root=t,this._currentNode=t._start,this._firstCall=!0,t.doc??vs()}[Symbol.iterator](){return this}next(){let t=this._currentNode,n=t&&t.content&&t.content.type;if(null!==t&&(!this._firstCall||t.deleted||!this._filter(n)))do{if(n=t.content.type,t.deleted||n.constructor!==oo&&n.constructor!==so||null===n._start)for(;null!==t;){const n=t.next;if(null!==n){t=n;break}t=t.parent===this._root?null:t.parent._item}else t=n._start}while(null!==t&&(t.deleted||!this._filter(t.content.type)));return this._firstCall=!1,null===t?{value:void 0,done:!0}:(this._currentNode=t,{value:t.content.type,done:!1})}}class so extends As{constructor(){super(),this._prelimContent=[]}get firstChild(){const t=this._first;return t?t.content.getContent()[0]:null}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new so}clone(){const t=new so;return t.insert(0,this.toArray().map((t=>t instanceof As?t.clone():t))),t}get length(){return this.doc??vs(),null===this._prelimContent?this._length:this._prelimContent.length}createTreeWalker(t){return new io(this,t)}querySelector(t){t=t.toUpperCase();const n=new io(this,(n=>n.nodeName&&n.nodeName.toUpperCase()===t)).next();return n.done?null:n.value}querySelectorAll(t){return t=t.toUpperCase(),Mt(new io(this,(n=>n.nodeName&&n.nodeName.toUpperCase()===t)))}_callObserver(t,n){ms(this,t,new uo(this,n,t))}toString(){return Ss(this,(t=>t.toString())).join("")}toJSON(){return this.toString()}toDOM(t=document,n={},e){const r=t.createDocumentFragment();return void 0!==e&&e._createAssociation(r,this),Ms(this,(i=>{r.insertBefore(i.toDOM(t,n,e),null)})),r}insert(t,n){null!==this.doc?qi(this.doc,(e=>{Ts(e,this,t,n)})):this._prelimContent.splice(t,0,...n)}insertAfter(t,n){if(null!==this.doc)qi(this.doc,(e=>{Es(e,this,t&&t instanceof As?t._item:t,n)}));else{const e=this._prelimContent,r=null===t?0:e.findIndex((n=>n===t))+1;if(0===r&&null!==t)throw gn("Reference item not found");e.splice(r,0,...n)}}delete(t,n=1){null!==this.doc?qi(this.doc,(e=>{Is(e,this,t,n)})):this._prelimContent.splice(t,n)}toArray(){return xs(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return Us(this,t)}slice(t=0,n=this.length){return ks(this,t,n)}forEach(t){Ms(this,t)}_write(t){t.writeTypeRef(Eo)}}class oo extends so{constructor(t="UNDEFINED"){super(),this.nodeName=t,this._prelimAttrs=new Map}get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_integrate(t,n){super._integrate(t,n),this._prelimAttrs.forEach(((t,n)=>{this.setAttribute(n,t)})),this._prelimAttrs=null}_copy(){return new oo(this.nodeName)}clone(){const t=new oo(this.nodeName);return((t,n)=>{for(const e in t)n(t[e],e)})(this.getAttributes(),((n,e)=>{t.setAttribute(e,n)})),t.insert(0,this.toArray().map((t=>t instanceof As?t.clone():t))),t}toString(){const t=this.getAttributes(),n=[],e=[];for(const n in t)e.push(n);e.sort();const r=e.length;for(let i=0;i<r;i++){const r=e[i];n.push(r+'="'+t[r]+'"')}const i=this.nodeName.toLocaleLowerCase();return`<${i}${n.length>0?" "+n.join(" "):""}>${super.toString()}</${i}>`}removeAttribute(t){null!==this.doc?qi(this.doc,(n=>{Os(n,this,t)})):this._prelimAttrs.delete(t)}setAttribute(t,n){null!==this.doc?qi(this.doc,(e=>{_s(e,this,t,n)})):this._prelimAttrs.set(t,n)}getAttribute(t){return zs(this,t)}hasAttribute(t){return Ds(this,t)}getAttributes(t){return t?((t,n)=>{const e={};return this._map.forEach(((t,r)=>{let i=t;for(;null!==i&&(!n.sv.has(i.id.client)||i.id.clock>=(n.sv.get(i.id.client)||0));)i=i.left;null!==i&&_i(i,n)&&(e[r]=i.content.getContent()[i.length-1])})),e})(0,t):$s(this)}toDOM(t=document,n={},e){const r=t.createElement(this.nodeName),i=this.getAttributes();for(const t in i){const n=i[t];"string"==typeof n&&r.setAttribute(t,n)}return Ms(this,(i=>{r.appendChild(i.toDOM(t,n,e))})),void 0!==e&&e._createAssociation(r,this),r}_write(t){t.writeTypeRef(Uo),t.writeKey(this.nodeName)}}class uo extends fs{constructor(t,n,e){super(t,e),this.childListChanged=!1,this.attributesChanged=new Set,n.forEach((t=>{null===t?this.childListChanged=!0:this.attributesChanged.add(t)}))}}class co extends Ls{constructor(t){super(),this.hookName=t}_copy(){return new co(this.hookName)}clone(){const t=new co(this.hookName);return this.forEach(((n,e)=>{t.set(e,n)})),t}toDOM(t=document,n={},e){const r=n[this.hookName];let i;return i=void 0!==r?r.createDom(this):document.createElement(this.hookName),i.setAttribute("data-yjs-hook",this.hookName),void 0!==e&&e._createAssociation(i,this),i}_write(t){t.writeTypeRef(jo),t.writeKey(this.hookName)}}class ho extends ro{get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_copy(){return new ho}clone(){const t=new ho;return t.applyDelta(this.toDelta()),t}toDOM(t=document,n,e){const r=t.createTextNode(this.toString());return void 0!==e&&e._createAssociation(r,this),r}toString(){return this.toDelta().map((t=>{const n=[];for(const e in t.attributes){const r=[];for(const n in t.attributes[e])r.push({key:n,value:t.attributes[e][n]});r.sort(((t,n)=>t.key<n.key?-1:1)),n.push({nodeName:e,attrs:r})}n.sort(((t,n)=>t.nodeName<n.nodeName?-1:1));let e="";for(let t=0;t<n.length;t++){const r=n[t];e+=`<${r.nodeName}`;for(let t=0;t<r.attrs.length;t++){const n=r.attrs[t];e+=` ${n.key}="${n.value}"`}e+=">"}e+=t.insert;for(let t=n.length-1;t>=0;t--)e+=`</${n[t].nodeName}>`;return e})).join("")}toJSON(){return this.toString()}_write(t){t.writeTypeRef(To)}}class ao{constructor(t,n){this.id=t,this.length=n}get deleted(){throw bn()}mergeWith(t){return!1}write(t,n,e){throw bn()}integrate(t,n){throw bn()}}class lo extends ao{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor===t.constructor&&(this.length+=t.length,!0)}integrate(t,n){n>0&&(this.id.clock+=n,this.length-=n),Ri(t.doc.store,this)}write(t,n){t.writeInfo(0),t.writeLen(this.length-n)}getMissing(t,n){return null}}class fo{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new fo(this.content)}splice(t){throw bn()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeBuf(this.content)}getRef(){return 3}}class vo{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new vo(this.len)}splice(t){const n=new vo(this.len-t);return this.len=t,n}mergeWith(t){return this.len+=t.len,!0}integrate(t,n){ei(t.deleteSet,n.id.client,n.id.clock,this.len),n.markDeleted()}delete(t){}gc(t){}write(t,n){t.writeLen(this.len-n)}getRef(){return 1}}const po=(t,n)=>new ui({guid:t,...n,shouldLoad:n.shouldLoad||n.autoLoad||!1});class wo{constructor(t){t._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=t;const n={};this.opts=n,t.gc||(n.gc=!1),t.autoLoad&&(n.autoLoad=!0),null!==t.meta&&(n.meta=t.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new wo(po(this.doc.guid,this.opts))}splice(t){throw bn()}mergeWith(t){return!1}integrate(t,n){this.doc._item=n,t.subdocsAdded.add(this.doc),this.doc.shouldLoad&&t.subdocsLoaded.add(this.doc)}delete(t){t.subdocsAdded.has(this.doc)?t.subdocsAdded.delete(this.doc):t.subdocsRemoved.add(this.doc)}gc(t){}write(t,n){t.writeString(this.doc.guid),t.writeAny(this.opts)}getRef(){return 9}}class yo{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new yo(this.embed)}splice(t){throw bn()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeJSON(this.embed)}getRef(){return 5}}class go{constructor(t,n){this.key=t,this.value=n}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new go(this.key,this.value)}splice(t){throw bn()}mergeWith(t){return!1}integrate(t,n){const e=n.parent;e._searchMarker=null,e._hasFormatting=!0}delete(t){}gc(t){}write(t,n){t.writeKey(this.key),t.writeJSON(this.value)}getRef(){return 6}}class bo{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new bo(this.arr)}splice(t){const n=new bo(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){const e=this.arr.length;t.writeLen(e-n);for(let r=n;r<e;r++){const n=this.arr[r];t.writeString(void 0===n?"undefined":JSON.stringify(n))}}getRef(){return 2}}const mo="development"===le("node_env");class Ao{constructor(t){this.arr=t,mo&&re(t)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Ao(this.arr)}splice(t){const n=new Ao(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){const e=this.arr.length;t.writeLen(e-n);for(let r=n;r<e;r++)t.writeAny(this.arr[r])}getRef(){return 8}}class ko{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new ko(this.str)}splice(t){const n=new ko(this.str.slice(t));this.str=this.str.slice(0,t);const e=this.str.charCodeAt(t-1);return e>=55296&&e<=56319&&(this.str=this.str.slice(0,t-1)+"�",n.str="�"+n.str.slice(1)),n}mergeWith(t){return this.str+=t.str,!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeString(0===n?this.str:this.str.slice(n))}getRef(){return 4}}const xo=[()=>new Bs,()=>new Ls,()=>new ro,t=>new oo(t.readKey()),()=>new so,t=>new co(t.readKey()),()=>new ho],Mo=0,So=1,Co=2,Uo=3,Eo=4,jo=5,To=6;class Io{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new Io(this.type._copy())}splice(t){throw bn()}mergeWith(t){return!1}integrate(t,n){this.type._integrate(t.doc,n)}delete(t){let n=this.type._start;for(;null!==n;)n.deleted?n.id.clock<(t.beforeState.get(n.id.client)||0)&&t._mergeStructs.push(n):n.delete(t),n=n.right;this.type._map.forEach((n=>{n.deleted?n.id.clock<(t.beforeState.get(n.id.client)||0)&&t._mergeStructs.push(n):n.delete(t)})),t.changed.delete(this.type)}gc(t){let n=this.type._start;for(;null!==n;)n.gc(t,!0),n=n.right;this.type._start=null,this.type._map.forEach((n=>{for(;null!==n;)n.gc(t,!0),n=n.left})),this.type._map=new Map}write(t,n){this.type._write(t)}getRef(){return 7}}const Oo=(t,n)=>{let e,r=n,i=0;do{i>0&&(r=Ii(r.client,r.clock+i)),e=Wi(t,r),i=r.clock-e.id.clock,r=e.redone}while(null!==r&&e instanceof Po);return{item:e,diff:i}},_o=(t,n)=>{for(;null!==t&&t.keep!==n;)t.keep=n,t=t.parent._item},zo=(t,n,e)=>{const{client:r,clock:i}=n.id,s=new Po(Ii(r,i+e),n,Ii(r,i+e-1),n.right,n.rightOrigin,n.parent,n.parentSub,n.content.splice(e));return n.deleted&&s.markDeleted(),n.keep&&(s.keep=!0),null!==n.redone&&(s.redone=Ii(n.redone.client,n.redone.clock+e)),n.right=s,null!==s.right&&(s.right.left=s),t._mergeStructs.push(s),null!==s.parentSub&&null===s.right&&s.parent._map.set(s.parentSub,s),n.length=e,s},$o=(t,n)=>Ct(t,(t=>Zr(t.deletions,n))),Do=(t,n,e,r,i,s)=>{const o=t.doc,u=o.store,c=o.clientID,h=n.redone;if(null!==h)return Fi(t,h);let a,l=n.parent._item,f=null;if(null!==l&&!0===l.deleted){if(null===l.redone&&(!e.has(l)||null===Do(t,l,e,r,i,s)))return null;for(;null!==l.redone;)l=Fi(t,l.redone)}const d=null===l?n.parent:l.content.type;if(null===n.parentSub){for(f=n.left,a=n;null!==f;){let n=f;for(;null!==n&&n.parent._item!==l;)n=null===n.redone?null:Fi(t,n.redone);if(null!==n&&n.parent._item===l){f=n;break}f=f.left}for(;null!==a;){let n=a;for(;null!==n&&n.parent._item!==l;)n=null===n.redone?null:Fi(t,n.redone);if(null!==n&&n.parent._item===l){a=n;break}a=a.right}}else if(a=null,n.right&&!i){for(f=n;null!==f&&null!==f.right&&(f.right.redone||Zr(r,f.right.id)||$o(s.undoStack,f.right.id)||$o(s.redoStack,f.right.id));)for(f=f.right;f.redone;)f=Fi(t,f.redone);if(f&&null!==f.right)return null}else f=d._map.get(n.parentSub)||null;const v=Pi(u,c),p=Ii(c,v),w=new Po(p,f,f&&f.lastId,a,a&&a.id,d,n.parentSub,n.content.copy());return n.redone=p,_o(w,!0),w.integrate(t,0),w};class Po extends ao{constructor(t,n,e,r,i,s,o,u){super(t,u.getLength()),this.origin=e,this.left=n,this.right=r,this.rightOrigin=i,this.parent=s,this.parentSub=o,this.redone=null,this.content=u,this.info=this.content.isCountable()?2:0}set marker(t){(8&this.info)>0!==t&&(this.info^=8)}get marker(){return(8&this.info)>0}get keep(){return(1&this.info)>0}set keep(t){this.keep!==t&&(this.info^=1)}get countable(){return(2&this.info)>0}get deleted(){return(4&this.info)>0}set deleted(t){this.deleted!==t&&(this.info^=4)}markDeleted(){this.info|=4}getMissing(t,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=Pi(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=Pi(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===ji&&this.id.client!==this.parent.client&&this.parent.clock>=Pi(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=Ni(t,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=Fi(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===lo||this.right&&this.right.constructor===lo)this.parent=null;else if(this.parent){if(this.parent.constructor===ji){const t=Wi(n,this.parent);this.parent=t.constructor===lo?null:t.content.type}}else this.left&&this.left.constructor===Po?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===Po&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);return null}integrate(t,n){if(n>0&&(this.id.clock+=n,this.left=Ni(t,t.doc.store,Ii(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(n),this.length-=n),this.parent){if(!this.left&&(!this.right||null!==this.right.left)||this.left&&this.left.right!==this.right){let n,e=this.left;if(null!==e)n=e.right;else if(null!==this.parentSub)for(n=this.parent._map.get(this.parentSub)||null;null!==n&&null!==n.left;)n=n.left;else n=this.parent._start;const r=new Set,i=new Set;for(;null!==n&&n!==this.right;){if(i.add(n),r.add(n),Ti(this.origin,n.origin)){if(n.id.client<this.id.client)e=n,r.clear();else if(Ti(this.rightOrigin,n.rightOrigin))break}else{if(null===n.origin||!i.has(Wi(t.doc.store,n.origin)))break;r.has(Wi(t.doc.store,n.origin))||(e=n,r.clear())}n=n.right}this.left=e}if(null!==this.left)this.right=this.left.right,this.left.right=this;else{let t;if(null!==this.parentSub)for(t=this.parent._map.get(this.parentSub)||null;null!==t&&null!==t.left;)t=t.left;else t=this.parent._start,this.parent._start=this;this.right=t}null!==this.right?this.right.left=this:null!==this.parentSub&&(this.parent._map.set(this.parentSub,this),null!==this.left&&this.left.delete(t)),null===this.parentSub&&this.countable&&!this.deleted&&(this.parent._length+=this.length),Ri(t.doc.store,this),this.content.integrate(t,this),Hi(t,this.parent,this.parentSub),(null!==this.parent._item&&this.parent._item.deleted||null!==this.parentSub&&null!==this.right)&&this.delete(t)}else new lo(this.id,this.length).integrate(t,0)}get next(){let t=this.right;for(;null!==t&&t.deleted;)t=t.right;return t}get prev(){let t=this.left;for(;null!==t&&t.deleted;)t=t.left;return t}get lastId(){return 1===this.length?this.id:Ii(this.id.client,this.id.clock+this.length-1)}mergeWith(t){if(this.constructor===t.constructor&&Ti(t.origin,this.lastId)&&this.right===t&&Ti(this.rightOrigin,t.rightOrigin)&&this.id.client===t.id.client&&this.id.clock+this.length===t.id.clock&&this.deleted===t.deleted&&null===this.redone&&null===t.redone&&this.content.constructor===t.content.constructor&&this.content.mergeWith(t.content)){const n=this.parent._searchMarker;return n&&n.forEach((n=>{n.p===t&&(n.p=this,!this.deleted&&this.countable&&(n.index-=this.length))})),t.keep&&(this.keep=!0),this.right=t.right,null!==this.right&&(this.right.left=this),this.length+=t.length,!0}return!1}delete(t){if(!this.deleted){const n=this.parent;this.countable&&null===this.parentSub&&(n._length-=this.length),this.markDeleted(),ei(t.deleteSet,this.id.client,this.id.clock,this.length),Hi(t,n,this.parentSub),this.content.delete(t)}}gc(t,n){if(!this.deleted)throw mn();this.content.gc(t),n?((t,n,e)=>{const r=t.clients.get(n.id.client);r[Bi(r,n.id.clock)]=e})(t,this,new lo(this.id,this.length)):this.content=new vo(this.length)}write(t,n){const e=n>0?Ii(this.id.client,this.id.clock+n-1):this.origin,r=this.rightOrigin,i=this.parentSub,s=31&this.content.getRef()|(null===e?0:Pt)|(null===r?0:Dt)|(null===i?0:32);if(t.writeInfo(s),null!==e&&t.writeLeftID(e),null!==r&&t.writeRightID(r),null===e&&null===r){const n=this.parent;if(void 0!==n._item){const e=n._item;if(null===e){const e=(t=>{for(const[n,e]of t.doc.share.entries())if(e===t)return n;throw mn()})(n);t.writeParentInfo(!0),t.writeString(e)}else t.writeParentInfo(!1),t.writeLeftID(e.id)}else n.constructor===String?(t.writeParentInfo(!0),t.writeString(n)):n.constructor===ji?(t.writeParentInfo(!1),t.writeLeftID(n)):mn();null!==i&&t.writeString(i)}this.content.write(t,n)}}const Ro=(t,n)=>Bo[31&n](t),Bo=[()=>{mn()},t=>new vo(t.readLen()),t=>{const n=t.readLen(),e=[];for(let r=0;r<n;r++){const n=t.readString();e.push("undefined"===n?void 0:JSON.parse(n))}return new bo(e)},t=>new fo(t.readBuf()),t=>new ko(t.readString()),t=>new yo(t.readJSON()),t=>new go(t.readKey(),t.readJSON()),t=>new Io(xo[t.readTypeRef()](t)),t=>{const n=t.readLen(),e=[];for(let r=0;r<n;r++)e.push(t.readAny());return new Ao(e)},t=>new wo(po(t.readString(),t.readAny())),()=>{mn()}];class Wo extends ao{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor===t.constructor&&(this.length+=t.length,!0)}integrate(t,n){mn()}write(t,n){t.writeInfo(10),nn(t.restEncoder,this.length-n)}getMissing(t,n){return null}}const Lo="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},Fo="__ $YJS$ __";!0===Lo[Fo]&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438"),Lo[Fo]=!0;const No=t=>Fn(((n,e)=>{t.onerror=t=>e(new Error(t.target.error)),t.onsuccess=t=>n(t.target.result)})),Ko=(t,n,e="readwrite")=>{const r=t.transaction(n,e);return n.map((t=>Xo(r,t)))},Qo=(t,n)=>No(t.count(n)),Yo=(t,n)=>No(t.delete(n)),Ho=(t,n)=>No(t.add(n)),Vo=(t,n,e,r="next")=>((t,n)=>Fn(((e,r)=>{t.onerror=r,t.onsuccess=async t=>{const r=t.target.result;if(null===r||!1===await n(r))return e();r.continue()}})))(t.openKeyCursor(n,r),(t=>e(t.key))),Xo=(t,n)=>t.objectStore(n),qo="custom",Go="updates",Jo=(t,n=()=>{},e=()=>{})=>{const[r]=Ko(t.db,[Go]);return(i=r,o=t._dbref,s=IDBKeyRange.lowerBound(o,false),No(i.getAll(s,undefined))).then((i=>{t._destroyed||(n(r),qi(t.doc,(()=>{i.forEach((n=>gi(t.doc,n)))}),t,!1),e(r))})).then((()=>((t,n=null)=>((t,n)=>{let e=null;return Vo(t,n,(t=>(e=t,!1)),"prev").then((()=>e))})(t,n))(r).then((n=>{t._dbref=n+1})))).then((()=>Qo(r).then((n=>{t._dbsize=n})))).then((()=>r));var i,s,o};class Zo extends jt{constructor(t,n){super(),this.doc=n,this.name=t,this._dbref=0,this._dbsize=0,this._destroyed=!1,this.db=null,this.synced=!1,this._db=(t=>Fn(((n,e)=>{const r=indexedDB.open(t);r.onupgradeneeded=t=>(t=>[["updates",{autoIncrement:!0}],["custom"]].forEach((n=>t.createObjectStore.apply(t,n))))(t.target.result),r.onerror=t=>e(gn(t.target.error)),r.onsuccess=t=>{const e=t.target.result;e.onversionchange=()=>{e.close()},n(e)}})))(t),this.whenSynced=Fn((t=>this.on("synced",(()=>t(this))))),this._db.then((t=>{this.db=t,Jo(this,(t=>Ho(t,mi(n))),(()=>{if(this._destroyed)return this;this.synced=!0,this.emit("synced",[this])}))})),this._storeTimeout=1e3,this._storeTimeoutId=null,this._storeUpdate=(t,n)=>{if(this.db&&n!==this){const[n]=Ko(this.db,[Go]);Ho(n,t),++this._dbsize>=500&&(null!==this._storeTimeoutId&&clearTimeout(this._storeTimeoutId),this._storeTimeoutId=setTimeout((()=>{((t,n=!0)=>{Jo(t).then((e=>{(n||t._dbsize>=500)&&Ho(e,mi(t.doc)).then((()=>Yo(e,IDBKeyRange.upperBound(t._dbref,!0)))).then((()=>Qo(e).then((n=>{t._dbsize=n}))))}))})(this,!1),this._storeTimeoutId=null}),this._storeTimeout))}},n.on("update",this._storeUpdate),this.destroy=this.destroy.bind(this),n.on("destroy",this.destroy)}destroy(){return this._storeTimeoutId&&clearTimeout(this._storeTimeoutId),this.doc.off("update",this._storeUpdate),this.doc.off("destroy",this.destroy),this._destroyed=!0,this._db.then((t=>{t.close()}))}clearData(){return this.destroy().then((()=>{No(indexedDB.deleteDatabase(this.name))}))}get(t){return this._db.then((n=>{const[e]=Ko(n,[qo],"readonly");return((t,n)=>No(t.get(n)))(e,t)}))}set(t,n){return this._db.then((e=>{const[r]=Ko(e,[qo]);return((t,n,e)=>No(t.put(n,e)))(r,n,t)}))}del(t){return this._db.then((n=>{const[e]=Ko(n,[qo]);return Yo(e,t)}))}}class tu{provider;isConnected=!1;constructor(t,n,e){this.provider=new Zo(e?.name||t,n)}async connect(){if(!this.isConnected)return new Promise((t=>{this.provider.on("synced",(()=>{this.isConnected=!0,t()}))}))}disconnect(){this.isConnected=!1}destroy(){this.provider&&this.provider.destroy(),this.isConnected=!1}}const nu=Math.floor,eu=127,ru=Number.MAX_SAFE_INTEGER,iu="undefined"!=typeof TextEncoder?new TextEncoder:null,su=iu?t=>iu.encode(t):t=>{const n=unescape(encodeURIComponent(t)),e=n.length,r=new Uint8Array(e);for(let t=0;t<e;t++)r[t]=n.codePointAt(t);return r};let ou="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});ou&&1===ou.decode(new Uint8Array).length&&(ou=null);const uu=(t,n)=>{const e=t.cbuf.length;t.cpos===e&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(2*e),t.cpos=0),t.cbuf[t.cpos++]=n},cu=(t,n)=>{for(;n>eu;)uu(t,128|eu&n),n=nu(n/128);uu(t,eu&n)},hu=new Uint8Array(3e4),au=hu.length/3,lu=iu&&iu.encodeInto?(t,n)=>{if(n.length<au){const e=iu.encodeInto(n,hu).written||0;cu(t,e);for(let n=0;n<e;n++)uu(t,hu[n])}else fu(t,su(n))}:(t,n)=>{const e=unescape(encodeURIComponent(n)),r=e.length;cu(t,r);for(let n=0;n<r;n++)uu(t,e.codePointAt(n))},fu=(t,n)=>{cu(t,n.byteLength),((t,n)=>{const e=t.cbuf.length,r=t.cpos,i=((t,n)=>t<n?t:n)(e-r,n.length),s=n.length-i;t.cbuf.set(n.subarray(0,i),r),t.cpos+=i,s>0&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(((t,n)=>t>n?t:n)(2*e,s)),t.cbuf.set(n.subarray(i)),t.cpos=s)})(t,n)},du=t=>new Error(t),vu=du("Unexpected end of array"),pu=du("Integer out of Range"),wu=t=>t.arr[t.pos++],yu=t=>{let n=0,e=1;const r=t.arr.length;for(;t.pos<r;){const r=t.arr[t.pos++];if(n+=(r&eu)*e,e*=128,r<128)return n;if(n>ru)throw pu}throw vu},gu=ou?t=>ou.decode((t=>((t,n)=>{const e=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,n);return t.pos+=n,e})(t,yu(t)))(t)):t=>{let n=yu(t);if(0===n)return"";{let e=String.fromCodePoint(wu(t));if(--n<100)for(;n--;)e+=String.fromCodePoint(wu(t));else for(;n>0;){const r=n<1e4?n:1e4,i=t.arr.subarray(t.pos,t.pos+r);t.pos+=r,e+=String.fromCodePoint.apply(null,i),n-=r}return decodeURIComponent(escape(e))}};var bu;!function(t){t[t.Token=0]="Token",t[t.PermissionDenied=1]="PermissionDenied",t[t.Authenticated=2]="Authenticated"}(bu||(bu={}));const mu=t=>Array.from(t.entries()).map((([t,n])=>({clientId:t,...n})));var Au;async function ku(t){return new Promise((n=>setTimeout(n,t)))}function xu(t,n){let e=n.delay;if(0===e)return 0;if(n.factor&&(e*=Math.pow(n.factor,t.attemptNum-1),0!==n.maxDelay&&(e=Math.min(e,n.maxDelay))),n.jitter){const t=Math.ceil(n.minDelay),r=Math.floor(e);e=Math.floor(Math.random()*(r-t+1))+t}return Math.round(e)}!function(t){t[t.Connecting=0]="Connecting",t[t.Open=1]="Open",t[t.Closing=2]="Closing",t[t.Closed=3]="Closed"}(Au||(Au={}));const Mu=Math.floor,Su=128,Cu=127,Uu=Number.MAX_SAFE_INTEGER,Eu=()=>new Set,ju=Array.from,Tu="undefined"!=typeof TextEncoder?new TextEncoder:null,Iu=Tu?t=>Tu.encode(t):t=>{const n=unescape(encodeURIComponent(t)),e=n.length,r=new Uint8Array(e);for(let t=0;t<e;t++)r[t]=n.codePointAt(t);return r};let Ou="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});Ou&&1===Ou.decode(new Uint8Array).length&&(Ou=null);class _u{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const zu=()=>new _u,$u=t=>{let n=t.cpos;for(let e=0;e<t.bufs.length;e++)n+=t.bufs[e].length;return n},Du=t=>{const n=new Uint8Array($u(t));let e=0;for(let r=0;r<t.bufs.length;r++){const i=t.bufs[r];n.set(i,e),e+=i.length}return n.set(new Uint8Array(t.cbuf.buffer,0,t.cpos),e),n},Pu=(t,n)=>{const e=t.cbuf.length;t.cpos===e&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(2*e),t.cpos=0),t.cbuf[t.cpos++]=n},Ru=(t,n)=>{for(;n>Cu;)Pu(t,Su|Cu&n),n=Mu(n/128);Pu(t,Cu&n)},Bu=new Uint8Array(3e4),Wu=Bu.length/3,Lu=Tu&&Tu.encodeInto?(t,n)=>{if(n.length<Wu){const e=Tu.encodeInto(n,Bu).written||0;Ru(t,e);for(let n=0;n<e;n++)Pu(t,Bu[n])}else Fu(t,Iu(n))}:(t,n)=>{const e=unescape(encodeURIComponent(n)),r=e.length;Ru(t,r);for(let n=0;n<r;n++)Pu(t,e.codePointAt(n))},Fu=(t,n)=>{Ru(t,n.byteLength),((t,n)=>{const e=t.cbuf.length,r=t.cpos,i=((t,n)=>t<n?t:n)(e-r,n.length),s=n.length-i;t.cbuf.set(n.subarray(0,i),r),t.cpos+=i,s>0&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(((t,n)=>t>n?t:n)(2*e,s)),t.cbuf.set(n.subarray(i)),t.cpos=s)})(t,n)},Nu=t=>new Error(t),Ku=Nu("Unexpected end of array"),Qu=Nu("Integer out of Range");class Yu{constructor(t){this.arr=t,this.pos=0}}const Hu=t=>new Yu(t),Vu=t=>((t,n)=>{const e=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,n);return t.pos+=n,e})(t,qu(t)),Xu=t=>t.arr[t.pos++],qu=t=>{let n=0,e=1;const r=t.arr.length;for(;t.pos<r;){const r=t.arr[t.pos++];if(n+=(r&Cu)*e,e*=128,r<Su)return n;if(n>Uu)throw Qu}throw Ku},Gu=Ou?t=>Ou.decode(Vu(t)):t=>{let n=qu(t);if(0===n)return"";{let e=String.fromCodePoint(Xu(t));if(--n<100)for(;n--;)e+=String.fromCodePoint(Xu(t));else for(;n>0;){const r=n<1e4?n:1e4,i=t.arr.subarray(t.pos,t.pos+r);t.pos+=r,e+=String.fromCodePoint.apply(null,i),n-=r}return decodeURIComponent(escape(e))}},Ju=Date.now,Zu=()=>new Map;class tc{constructor(){this._observers=Zu()}on(t,n){((t,n,e)=>{let r=t.get(n);return void 0===r&&t.set(n,r=e()),r})(this._observers,t,Eu).add(n)}once(t,n){const e=(...r)=>{this.off(t,e),n(...r)};this.on(t,e)}off(t,n){const e=this._observers.get(t);void 0!==e&&(e.delete(n),0===e.size&&this._observers.delete(t))}emit(t,n){return ju((this._observers.get(t)||Zu()).values()).forEach((t=>t(...n)))}destroy(){this._observers=Zu()}}const nc=Object.keys,ec=t=>nc(t).length,rc=(t,n)=>Object.prototype.hasOwnProperty.call(t,n),ic=(t,n)=>{if(null==t||null==n)return((t,n)=>t===n)(t,n);if(t.constructor!==n.constructor)return!1;if(t===n)return!0;switch(t.constructor){case ArrayBuffer:t=new Uint8Array(t),n=new Uint8Array(n);case Uint8Array:if(t.byteLength!==n.byteLength)return!1;for(let e=0;e<t.length;e++)if(t[e]!==n[e])return!1;break;case Set:if(t.size!==n.size)return!1;for(const e of t)if(!n.has(e))return!1;break;case Map:if(t.size!==n.size)return!1;for(const e of t.keys())if(!n.has(e)||!ic(t.get(e),n.get(e)))return!1;break;case Object:if(ec(t)!==ec(n))return!1;for(const e in t)if(!rc(t,e)||!ic(t[e],n[e]))return!1;break;case Array:if(t.length!==n.length)return!1;for(let e=0;e<t.length;e++)if(!ic(t[e],n[e]))return!1;break;default:return!1}return!0};class sc extends tc{constructor(t){super(),this.doc=t,this.clientID=t.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval((()=>{const t=Ju();null!==this.getLocalState()&&15e3<=t-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());const n=[];this.meta.forEach(((e,r)=>{r!==this.clientID&&3e4<=t-e.lastUpdated&&this.states.has(r)&&n.push(r)})),n.length>0&&oc(this,n,"timeout")}),Mu(3e3)),t.on("destroy",(()=>{this.destroy()})),this.setLocalState({})}destroy(){this.emit("destroy",[this]),this.setLocalState(null),super.destroy(),clearInterval(this._checkInterval)}getLocalState(){return this.states.get(this.clientID)||null}setLocalState(t){const n=this.clientID,e=this.meta.get(n),r=void 0===e?0:e.clock+1,i=this.states.get(n);null===t?this.states.delete(n):this.states.set(n,t),this.meta.set(n,{clock:r,lastUpdated:Ju()});const s=[],o=[],u=[],c=[];null===t?c.push(n):null==i?null!=t&&s.push(n):(o.push(n),ic(i,t)||u.push(n)),(s.length>0||u.length>0||c.length>0)&&this.emit("change",[{added:s,updated:u,removed:c},"local"]),this.emit("update",[{added:s,updated:o,removed:c},"local"])}setLocalStateField(t,n){const e=this.getLocalState();null!==e&&this.setLocalState({...e,[t]:n})}getStates(){return this.states}}const oc=(t,n,e)=>{const r=[];for(let e=0;e<n.length;e++){const i=n[e];if(t.states.has(i)){if(t.states.delete(i),i===t.clientID){const n=t.meta.get(i);t.meta.set(i,{clock:n.clock+1,lastUpdated:Ju()})}r.push(i)}}r.length>0&&(t.emit("change",[{added:[],updated:[],removed:r},e]),t.emit("update",[{added:[],updated:[],removed:r},e]))},uc=(t,n,e=t.states)=>{const r=n.length,i=zu();Ru(i,r);for(let s=0;s<r;s++){const r=n[s],o=e.get(r)||null,u=t.meta.get(r).clock;Ru(i,r),Ru(i,u),Lu(i,JSON.stringify(o))}return Du(i)};class cc{constructor(){this.callbacks={}}on(t,n){return this.callbacks[t]||(this.callbacks[t]=[]),this.callbacks[t].push(n),this}emit(t,...n){const e=this.callbacks[t];return e&&e.forEach((t=>t.apply(this,n))),this}off(t,n){const e=this.callbacks[t];return e&&(n?this.callbacks[t]=e.filter((t=>t!==n)):delete this.callbacks[t]),this}removeAllListeners(){this.callbacks={}}}class hc{constructor(t){this.data=t,this.encoder=zu(),this.decoder=Hu(new Uint8Array(this.data))}peekVarString(){return(t=>{const n=t.pos,e=Gu(t);return t.pos=n,e})(this.decoder)}readVarUint(){return qu(this.decoder)}readVarString(){return Gu(this.decoder)}readVarUint8Array(){return Vu(this.decoder)}writeVarUint(t){return Ru(this.encoder,t)}writeVarString(t){return Lu(this.encoder,t)}writeVarUint8Array(t){return Fu(this.encoder,t)}length(){return $u(this.encoder)}}var ac,lc;!function(t){t[t.Sync=0]="Sync",t[t.Awareness=1]="Awareness",t[t.Auth=2]="Auth",t[t.QueryAwareness=3]="QueryAwareness",t[t.Stateless=5]="Stateless",t[t.CLOSE=7]="CLOSE",t[t.SyncStatus=8]="SyncStatus"}(ac||(ac={})),function(t){t.Connecting="connecting",t.Connected="connected",t.Disconnected="disconnected"}(lc||(lc={}));class fc{constructor(){this.encoder=zu()}get(t){return t.encoder}toUint8Array(){return Du(this.encoder)}}class dc extends fc{constructor(){super(...arguments),this.type=ac.CLOSE,this.description="Ask the server to close the connection"}get(t){return Lu(this.encoder,t.documentName),Ru(this.encoder,this.type),this.encoder}}class vc extends cc{constructor(t){super(),this.messageQueue=[],this.configuration={url:"",autoConnect:!0,document:void 0,WebSocketPolyfill:void 0,messageReconnectTimeout:3e4,delay:1e3,initialDelay:0,factor:2,maxAttempts:0,minDelay:1e3,maxDelay:3e4,jitter:!0,timeout:0,onOpen:()=>null,onConnect:()=>null,onMessage:()=>null,onOutgoingMessage:()=>null,onStatus:()=>null,onDisconnect:()=>null,onClose:()=>null,onDestroy:()=>null,onAwarenessUpdate:()=>null,onAwarenessChange:()=>null,handleTimeout:null,providerMap:new Map},this.webSocket=null,this.webSocketHandlers={},this.shouldConnect=!0,this.status=lc.Disconnected,this.lastMessageReceived=0,this.identifier=0,this.intervals={connectionChecker:null},this.connectionAttempt=null,this.receivedOnOpenPayload=void 0,this.closeTries=0,this.setConfiguration(t),this.configuration.WebSocketPolyfill=t.WebSocketPolyfill?t.WebSocketPolyfill:WebSocket,this.on("open",this.configuration.onOpen),this.on("open",this.onOpen.bind(this)),this.on("connect",this.configuration.onConnect),this.on("message",this.configuration.onMessage),this.on("outgoingMessage",this.configuration.onOutgoingMessage),this.on("status",this.configuration.onStatus),this.on("disconnect",this.configuration.onDisconnect),this.on("close",this.configuration.onClose),this.on("destroy",this.configuration.onDestroy),this.on("awarenessUpdate",this.configuration.onAwarenessUpdate),this.on("awarenessChange",this.configuration.onAwarenessChange),this.on("close",this.onClose.bind(this)),this.on("message",this.onMessage.bind(this)),this.intervals.connectionChecker=setInterval(this.checkConnection.bind(this),this.configuration.messageReconnectTimeout/10),this.shouldConnect&&this.connect()}async onOpen(t){this.status=lc.Connected,this.emit("status",{status:lc.Connected}),this.cancelWebsocketRetry=void 0,this.receivedOnOpenPayload=t}attach(t){this.configuration.providerMap.set(t.configuration.name,t),this.status===lc.Disconnected&&this.shouldConnect&&this.connect(),this.receivedOnOpenPayload&&this.status===lc.Connected&&t.onOpen(this.receivedOnOpenPayload)}detach(t){this.configuration.providerMap.has(t.configuration.name)&&(t.send(dc,{documentName:t.configuration.name}),this.configuration.providerMap.delete(t.configuration.name))}setConfiguration(t={}){this.configuration={...this.configuration,...t},this.configuration.autoConnect||(this.shouldConnect=!1)}async connect(){if(this.status===lc.Connected)return;this.cancelWebsocketRetry&&(this.cancelWebsocketRetry(),this.cancelWebsocketRetry=void 0),this.receivedOnOpenPayload=void 0,this.shouldConnect=!0;const{retryPromise:t,cancelFunc:n}=(()=>{let t=!1;const n=async function(t,n){const e=function(t){return t||(t={}),{delay:void 0===t.delay?200:t.delay,initialDelay:void 0===t.initialDelay?0:t.initialDelay,minDelay:void 0===t.minDelay?0:t.minDelay,maxDelay:void 0===t.maxDelay?0:t.maxDelay,factor:void 0===t.factor?0:t.factor,maxAttempts:void 0===t.maxAttempts?3:t.maxAttempts,timeout:void 0===t.timeout?0:t.timeout,jitter:!0===t.jitter,initialJitter:!0===t.initialJitter,handleError:void 0===t.handleError?null:t.handleError,handleTimeout:void 0===t.handleTimeout?null:t.handleTimeout,beforeAttempt:void 0===t.beforeAttempt?null:t.beforeAttempt,calculateDelay:void 0===t.calculateDelay?null:t.calculateDelay}}(n);for(const t of["delay","initialDelay","minDelay","maxDelay","maxAttempts","timeout"]){const n=e[t];if(!Number.isInteger(n)||n<0)throw new Error(`Value for ${t} must be an integer greater than or equal to 0`)}if(e.factor.constructor!==Number||e.factor<0)throw new Error("Value for factor must be a number greater than or equal to 0");if(e.delay<e.minDelay)throw new Error(`delay cannot be less than minDelay (delay: ${e.delay}, minDelay: ${e.minDelay}`);const r={attemptNum:0,attemptsRemaining:e.maxAttempts?e.maxAttempts:-1,aborted:!1,abort(){r.aborted=!0}},i=e.calculateDelay||xu,s=e.calculateDelay?e.calculateDelay(r,e):e.initialDelay;if(s&&await ku(s),r.attemptNum<1&&e.initialJitter){const t=i(r,e);t&&await ku(t)}return async function n(){if(e.beforeAttempt&&e.beforeAttempt(r,e),r.aborted){const t=new Error("Attempt aborted");throw t.code="ATTEMPT_ABORTED",t}const s=async t=>{if(e.handleError&&await e.handleError(t,r,e),r.aborted||0===r.attemptsRemaining)throw t;r.attemptNum++;const s=i(r,e);return s&&await ku(s),n()};return r.attemptsRemaining>0&&r.attemptsRemaining--,e.timeout?new Promise(((n,i)=>{const o=setTimeout((()=>{if(e.handleTimeout)try{n(e.handleTimeout(r,e))}catch(t){i(t)}else{const t=new Error(`Retry timeout (attemptNum: ${r.attemptNum}, timeout: ${e.timeout})`);t.code="ATTEMPT_TIMEOUT",i(t)}}),e.timeout);t(r,e).then((t=>{clearTimeout(o),n(t)})).catch((t=>{clearTimeout(o),s(t).then(n).catch(i)}))})):t(r,e).catch(s)}()}(this.createWebSocketConnection.bind(this),{delay:this.configuration.delay,initialDelay:this.configuration.initialDelay,factor:this.configuration.factor,maxAttempts:this.configuration.maxAttempts,minDelay:this.configuration.minDelay,maxDelay:this.configuration.maxDelay,jitter:this.configuration.jitter,timeout:this.configuration.timeout,handleTimeout:this.configuration.handleTimeout,beforeAttempt:n=>{this.shouldConnect&&!t||n.abort()}}).catch((t=>{if(t&&"ATTEMPT_ABORTED"!==t.code)throw t}));return{retryPromise:n,cancelFunc:()=>{t=!0}}})();return this.cancelWebsocketRetry=n,t}attachWebSocketListeners(t,n){const{identifier:e}=t;this.webSocketHandlers[e]={message:t=>this.emit("message",t),close:t=>this.emit("close",{event:t}),open:t=>this.emit("open",t),error:t=>{n(t)}};const r=this.webSocketHandlers[t.identifier];Object.keys(r).forEach((n=>{t.addEventListener(n,r[n])}))}cleanupWebSocket(){if(!this.webSocket)return;const{identifier:t}=this.webSocket,n=this.webSocketHandlers[t];Object.keys(n).forEach((e=>{var r;null===(r=this.webSocket)||void 0===r||r.removeEventListener(e,n[e]),delete this.webSocketHandlers[t]})),this.webSocket.close(),this.webSocket=null}createWebSocketConnection(){return new Promise(((t,n)=>{this.webSocket&&(this.messageQueue=[],this.cleanupWebSocket()),this.lastMessageReceived=0,this.identifier+=1;const e=new this.configuration.WebSocketPolyfill(this.url);e.binaryType="arraybuffer",e.identifier=this.identifier,this.attachWebSocketListeners(e,n),this.webSocket=e,this.status=lc.Connecting,this.emit("status",{status:lc.Connecting}),this.connectionAttempt={resolve:t,reject:n}}))}onMessage(t){var n;this.resolveConnectionAttempt(),this.lastMessageReceived=Ju();const e=new hc(t.data).peekVarString();null===(n=this.configuration.providerMap.get(e))||void 0===n||n.onMessage(t)}resolveConnectionAttempt(){this.connectionAttempt&&(this.connectionAttempt.resolve(),this.connectionAttempt=null,this.status=lc.Connected,this.emit("status",{status:lc.Connected}),this.emit("connect"),this.messageQueue.forEach((t=>this.send(t))),this.messageQueue=[])}stopConnectionAttempt(){this.connectionAttempt=null}rejectConnectionAttempt(){var t;null===(t=this.connectionAttempt)||void 0===t||t.reject(),this.connectionAttempt=null}checkConnection(){var t;this.status===lc.Connected&&this.lastMessageReceived&&(this.configuration.messageReconnectTimeout>=Ju()-this.lastMessageReceived||(this.closeTries+=1,this.closeTries>2?(this.onClose({event:{code:4408,reason:"forced"}}),this.closeTries=0):(null===(t=this.webSocket)||void 0===t||t.close(),this.messageQueue=[])))}get serverUrl(){for(;"/"===this.configuration.url[this.configuration.url.length-1];)return this.configuration.url.slice(0,this.configuration.url.length-1);return this.configuration.url}get url(){return this.serverUrl}disconnect(){if(this.shouldConnect=!1,null!==this.webSocket)try{this.webSocket.close(),this.messageQueue=[]}catch(t){console.error(t)}}send(t){var n;(null===(n=this.webSocket)||void 0===n?void 0:n.readyState)===Au.Open?this.webSocket.send(t):this.messageQueue.push(t)}onClose({event:t}){this.closeTries=0,this.cleanupWebSocket(),this.connectionAttempt&&this.rejectConnectionAttempt(),this.status=lc.Disconnected,this.emit("status",{status:lc.Disconnected}),this.emit("disconnect",{event:t}),!this.cancelWebsocketRetry&&this.shouldConnect&&setTimeout((()=>{this.connect()}),this.configuration.delay)}destroy(){this.emit("destroy"),clearInterval(this.intervals.connectionChecker),this.stopConnectionAttempt(),this.disconnect(),this.removeAllListeners(),this.cleanupWebSocket()}}const pc=(t,n,e)=>{try{gi(n,Vu(t),e)}catch(t){console.error("Caught error while handling a Yjs update",t)}},wc=pc;class yc{constructor(t){this.message=t}apply(t,n){const{message:e}=this,r=e.readVarUint(),i=e.length();switch(r){case ac.Sync:this.applySyncMessage(t,n);break;case ac.Awareness:this.applyAwarenessMessage(t);break;case ac.Auth:this.applyAuthMessage(t);break;case ac.QueryAwareness:this.applyQueryAwarenessMessage(t);break;case ac.Stateless:t.receiveStateless(Gu(e.decoder));break;case ac.SyncStatus:this.applySyncStatusMessage(t,1===(t=>{let n=t.arr[t.pos++],e=63&n,r=64;const i=(64&n)>0?-1:1;if(!(n&Su))return i*e;const s=t.arr.length;for(;t.pos<s;){if(n=t.arr[t.pos++],e+=(n&Cu)*r,r*=128,n<Su)return i*e;if(e>Uu)throw Qu}throw Ku})(e.decoder));break;case ac.CLOSE:const i={code:1e3,reason:Gu(e.decoder),target:t.configuration.websocketProvider.webSocket,type:"close"};t.onClose(),t.configuration.onClose({event:i}),t.forwardClose(i);break;default:throw new Error(`Can’t apply message of unknown type: ${r}`)}e.length()>i+1&&t.send(fc,{encoder:e.encoder})}applySyncMessage(t,n){const{message:e}=this;e.writeVarUint(ac.Sync);const r=((t,n,e,r)=>{const i=qu(t);switch(i){case 0:((t,n,e)=>{((t,n,e)=>{Ru(t,1),Fu(t,mi(n,e))})(n,e,Vu(t))})(t,n,e);break;case 1:pc(t,e,r);break;case 2:wc(t,e,r);break;default:throw new Error("Unknown message type")}return i})(e.decoder,e.encoder,t.document,t);n&&1===r&&(t.synced=!0)}applySyncStatusMessage(t,n){n&&t.decrementUnsyncedChanges()}applyAwarenessMessage(t){if(!t.awareness)return;const{message:n}=this;((t,n,e)=>{const r=Hu(n),i=Ju(),s=[],o=[],u=[],c=[],h=qu(r);for(let n=0;n<h;n++){const n=qu(r);let e=qu(r);const h=JSON.parse(Gu(r)),a=t.meta.get(n),l=t.states.get(n),f=void 0===a?0:a.clock;(f<e||f===e&&null===h&&t.states.has(n))&&(null===h?n===t.clientID&&null!=t.getLocalState()?e++:t.states.delete(n):t.states.set(n,h),t.meta.set(n,{clock:e,lastUpdated:i}),void 0===a&&null!==h?s.push(n):void 0!==a&&null===h?c.push(n):null!==h&&(ic(h,l)||u.push(n),o.push(n)))}(s.length>0||u.length>0||c.length>0)&&t.emit("change",[{added:s,updated:u,removed:c},e]),(s.length>0||o.length>0||c.length>0)&&t.emit("update",[{added:s,updated:o,removed:c},e])})(t.awareness,n.readVarUint8Array(),t)}applyAuthMessage(t){const{message:n}=this;((t,n,e,r)=>{switch(yu(t)){case bu.Token:n();break;case bu.PermissionDenied:e(gu(t));break;case bu.Authenticated:r(gu(t))}})(n.decoder,t.sendToken.bind(t),t.permissionDeniedHandler.bind(t),t.authenticatedHandler.bind(t))}applyQueryAwarenessMessage(t){if(!t.awareness)return;const{message:n}=this;n.writeVarUint(ac.Awareness),n.writeVarUint8Array(uc(t.awareness,Array.from(t.awareness.getStates().keys())))}}class gc{constructor(t,n={}){this.message=new t,this.encoder=this.message.get(n)}create(){return Du(this.encoder)}send(t){null==t||t.send(this.create())}}class bc extends fc{constructor(){super(...arguments),this.type=ac.Auth,this.description="Authentication"}get(t){if(void 0===t.token)throw new Error("The authentication message requires `token` as an argument.");var n,e;return Lu(this.encoder,t.documentName),Ru(this.encoder,this.type),e=t.token,cu(n=this.encoder,bu.Token),lu(n,e),this.encoder}}class mc extends fc{constructor(){super(...arguments),this.type=ac.Awareness,this.description="Awareness states update"}get(t){if(void 0===t.awareness)throw new Error("The awareness message requires awareness as an argument");if(void 0===t.clients)throw new Error("The awareness message requires clients as an argument");let n;return Lu(this.encoder,t.documentName),Ru(this.encoder,this.type),n=void 0===t.states?uc(t.awareness,t.clients):uc(t.awareness,t.clients,t.states),Fu(this.encoder,n),this.encoder}}class Ac extends fc{constructor(){super(...arguments),this.type=ac.Stateless,this.description="A stateless message"}get(t){var n;return Lu(this.encoder,t.documentName),Ru(this.encoder,this.type),Lu(this.encoder,null!==(n=t.payload)&&void 0!==n?n:""),this.encoder}}class kc extends fc{constructor(){super(...arguments),this.type=ac.Sync,this.description="First sync step"}get(t){if(void 0===t.document)throw new Error("The sync step one message requires document as an argument");return Lu(this.encoder,t.documentName),Ru(this.encoder,this.type),((t,n)=>{Ru(t,0);const e=xi(n);Fu(t,e)})(this.encoder,t.document),this.encoder}}class xc extends fc{constructor(){super(...arguments),this.type=ac.Sync,this.description="A document update"}get(t){var n,e;return Lu(this.encoder,t.documentName),Ru(this.encoder,this.type),e=t.update,Ru(n=this.encoder,2),Fu(n,e),this.encoder}}class Mc extends Error{constructor(){super(...arguments),this.code=1001}}class Sc extends cc{constructor(t){var n,e,r;super(),this.configuration={name:"",document:void 0,awareness:void 0,token:null,forceSyncInterval:!1,onAuthenticated:()=>null,onAuthenticationFailed:()=>null,onOpen:()=>null,onConnect:()=>null,onMessage:()=>null,onOutgoingMessage:()=>null,onSynced:()=>null,onStatus:()=>null,onDisconnect:()=>null,onClose:()=>null,onDestroy:()=>null,onAwarenessUpdate:()=>null,onAwarenessChange:()=>null,onStateless:()=>null,onUnsyncedChanges:()=>null},this.isSynced=!1,this.unsyncedChanges=0,this.isAuthenticated=!1,this.authorizedScope=void 0,this.manageSocket=!1,this._isAttached=!1,this.intervals={forceSync:null},this.boundDocumentUpdateHandler=this.documentUpdateHandler.bind(this),this.boundAwarenessUpdateHandler=this.awarenessUpdateHandler.bind(this),this.boundPageHide=this.pageHide.bind(this),this.boundOnOpen=this.onOpen.bind(this),this.boundOnClose=this.onClose.bind(this),this.forwardConnect=()=>this.emit("connect"),this.forwardStatus=t=>this.emit("status",t),this.forwardClose=t=>this.emit("close",t),this.forwardDisconnect=t=>this.emit("disconnect",t),this.forwardDestroy=()=>this.emit("destroy"),this.setConfiguration(t),this.configuration.document=t.document?t.document:new ui,this.configuration.awareness=void 0!==t.awareness?t.awareness:new sc(this.document),this.on("open",this.configuration.onOpen),this.on("message",this.configuration.onMessage),this.on("outgoingMessage",this.configuration.onOutgoingMessage),this.on("synced",this.configuration.onSynced),this.on("destroy",this.configuration.onDestroy),this.on("awarenessUpdate",this.configuration.onAwarenessUpdate),this.on("awarenessChange",this.configuration.onAwarenessChange),this.on("stateless",this.configuration.onStateless),this.on("unsyncedChanges",this.configuration.onUnsyncedChanges),this.on("authenticated",this.configuration.onAuthenticated),this.on("authenticationFailed",this.configuration.onAuthenticationFailed),null===(n=this.awareness)||void 0===n||n.on("update",(()=>{this.emit("awarenessUpdate",{states:mu(this.awareness.getStates())})})),null===(e=this.awareness)||void 0===e||e.on("change",(()=>{this.emit("awarenessChange",{states:mu(this.awareness.getStates())})})),this.document.on("update",this.boundDocumentUpdateHandler),null===(r=this.awareness)||void 0===r||r.on("update",this.boundAwarenessUpdateHandler),this.registerEventListeners(),this.configuration.forceSyncInterval&&"number"==typeof this.configuration.forceSyncInterval&&(this.intervals.forceSync=setInterval(this.forceSync.bind(this),this.configuration.forceSyncInterval)),this.manageSocket&&this.attach()}setConfiguration(t={}){if(!t.websocketProvider){const n=t;this.manageSocket=!0,this.configuration.websocketProvider=new vc({url:n.url})}this.configuration={...this.configuration,...t}}get document(){return this.configuration.document}get isAttached(){return this._isAttached}get awareness(){return this.configuration.awareness}get hasUnsyncedChanges(){return this.unsyncedChanges>0}resetUnsyncedChanges(){this.unsyncedChanges=1,this.emit("unsyncedChanges",{number:this.unsyncedChanges})}incrementUnsyncedChanges(){this.unsyncedChanges+=1,this.emit("unsyncedChanges",{number:this.unsyncedChanges})}decrementUnsyncedChanges(){this.unsyncedChanges>0&&(this.unsyncedChanges-=1),0===this.unsyncedChanges&&(this.synced=!0),this.emit("unsyncedChanges",{number:this.unsyncedChanges})}forceSync(){this.resetUnsyncedChanges(),this.send(kc,{document:this.document,documentName:this.configuration.name})}pageHide(){this.awareness&&oc(this.awareness,[this.document.clientID],"page hide")}registerEventListeners(){"undefined"!=typeof window&&"addEventListener"in window&&window.addEventListener("pagehide",this.boundPageHide)}sendStateless(t){this.send(Ac,{documentName:this.configuration.name,payload:t})}async sendToken(){let t;try{t=await this.getToken()}catch(t){return void this.permissionDeniedHandler(`Failed to get token during sendToken(): ${t}`)}this.send(bc,{token:null!=t?t:"",documentName:this.configuration.name})}documentUpdateHandler(t,n){n!==this&&(this.incrementUnsyncedChanges(),this.send(xc,{update:t,documentName:this.configuration.name}))}awarenessUpdateHandler({added:t,updated:n,removed:e},r){const i=t.concat(n).concat(e);this.send(mc,{awareness:this.awareness,clients:i,documentName:this.configuration.name})}get synced(){return this.isSynced}set synced(t){this.isSynced!==t&&(this.isSynced=t,t&&this.emit("synced",{state:t}))}receiveStateless(t){this.emit("stateless",{payload:t})}async connect(){if(this.manageSocket)return this.configuration.websocketProvider.connect();console.warn("HocuspocusProvider::connect() is deprecated and does not do anything. Please connect/disconnect on the websocketProvider, or attach/deattach providers.")}disconnect(){if(this.manageSocket)return this.configuration.websocketProvider.disconnect();console.warn("HocuspocusProvider::disconnect() is deprecated and does not do anything. Please connect/disconnect on the websocketProvider, or attach/deattach providers.")}async onOpen(t){this.isAuthenticated=!1,this.emit("open",{event:t}),await this.sendToken(),this.startSync()}async getToken(){return"function"==typeof this.configuration.token?await this.configuration.token():this.configuration.token}startSync(){this.resetUnsyncedChanges(),this.send(kc,{document:this.document,documentName:this.configuration.name}),this.awareness&&null!==this.awareness.getLocalState()&&this.send(mc,{awareness:this.awareness,clients:[this.document.clientID],documentName:this.configuration.name})}send(t,n){if(!this._isAttached)return;const e=new gc(t,n);this.emit("outgoingMessage",{message:e.message}),e.send(this.configuration.websocketProvider)}onMessage(t){const n=new hc(t.data),e=n.readVarString();n.writeVarString(e),this.emit("message",{event:t,message:new hc(t.data)}),new yc(n).apply(this,!0)}onClose(){this.isAuthenticated=!1,this.synced=!1,this.awareness&&oc(this.awareness,Array.from(this.awareness.getStates().keys()).filter((t=>t!==this.document.clientID)),this)}destroy(){this.emit("destroy"),this.intervals.forceSync&&clearInterval(this.intervals.forceSync),this.awareness&&(oc(this.awareness,[this.document.clientID],"provider destroy"),this.awareness.off("update",this.boundAwarenessUpdateHandler),this.awareness.destroy()),this.document.off("update",this.boundDocumentUpdateHandler),this.removeAllListeners(),this.detach(),this.manageSocket&&this.configuration.websocketProvider.destroy(),"undefined"!=typeof window&&"removeEventListener"in window&&window.removeEventListener("pagehide",this.boundPageHide)}detach(){this.configuration.websocketProvider.off("connect",this.configuration.onConnect),this.configuration.websocketProvider.off("connect",this.forwardConnect),this.configuration.websocketProvider.off("status",this.forwardStatus),this.configuration.websocketProvider.off("status",this.configuration.onStatus),this.configuration.websocketProvider.off("open",this.boundOnOpen),this.configuration.websocketProvider.off("close",this.boundOnClose),this.configuration.websocketProvider.off("close",this.configuration.onClose),this.configuration.websocketProvider.off("close",this.forwardClose),this.configuration.websocketProvider.off("disconnect",this.configuration.onDisconnect),this.configuration.websocketProvider.off("disconnect",this.forwardDisconnect),this.configuration.websocketProvider.off("destroy",this.configuration.onDestroy),this.configuration.websocketProvider.off("destroy",this.forwardDestroy),this.configuration.websocketProvider.detach(this),this._isAttached=!1}attach(){this._isAttached||(this.configuration.websocketProvider.on("connect",this.configuration.onConnect),this.configuration.websocketProvider.on("connect",this.forwardConnect),this.configuration.websocketProvider.on("status",this.configuration.onStatus),this.configuration.websocketProvider.on("status",this.forwardStatus),this.configuration.websocketProvider.on("open",this.boundOnOpen),this.configuration.websocketProvider.on("close",this.boundOnClose),this.configuration.websocketProvider.on("close",this.configuration.onClose),this.configuration.websocketProvider.on("close",this.forwardClose),this.configuration.websocketProvider.on("disconnect",this.configuration.onDisconnect),this.configuration.websocketProvider.on("disconnect",this.forwardDisconnect),this.configuration.websocketProvider.on("destroy",this.configuration.onDestroy),this.configuration.websocketProvider.on("destroy",this.forwardDestroy),this.configuration.websocketProvider.attach(this),this._isAttached=!0)}permissionDeniedHandler(t){this.emit("authenticationFailed",{reason:t}),this.isAuthenticated=!1}authenticatedHandler(t){this.isAuthenticated=!0,this.authorizedScope=t,this.emit("authenticated",{scope:t})}setAwarenessField(t,n){if(!this.awareness)throw new Mc(`Cannot set awareness field "${t}" to ${JSON.stringify(n)}. You have disabled Awareness for this provider by explicitly passing awareness: null in the provider configuration.`);this.awareness.setLocalStateField(t,n)}}const Cc={providers:[tu]};class Uc{map;_ydoc=null;_workspacesMap=null;_providers=[];_core=null;_isReady=!1;_onRemoteChangeCallback=null;get isReady(){return this._isReady}constructor(){this.map=new Map}onRemoteChange(t){this._onRemoteChangeCallback=t}async initialize(t,n){this._core=t,this._ydoc=new ui,this._workspacesMap=this._ydoc.getMap("workspaces");const e="kritzel-app-state",r=n??Cc;for(const t of r.providers){let n;n="function"==typeof t?new t(e,this._ydoc):t.create(e,this._ydoc),this._providers.push(n)}this._workspacesMap.observe((t=>{this.handleWorkspacesChange(t)})),await Promise.all(this._providers.map((t=>t.connect()))),this._isReady=!0,this.loadFromYjs()}handleWorkspacesChange(t){if("local"===t.transaction.origin)return void this._core?.rerender();const n=Array.from(t.keysChanged),e=[],r=[];n.forEach((n=>{const i=t.changes.keys.get(n);if(i&&"delete"===i.action)r.push(n);else{const t=this._workspacesMap.get(n);if(t){const n=this.reviveWorkspace(t);e.push(n)}}})),r.forEach((t=>{this.map.delete(t)})),e.forEach((t=>{this.map.set(t.id,t)})),this._core?.store&&(this._core.store.state.workspaces=this.allWorkspaces()),this._onRemoteChangeCallback&&this._onRemoteChangeCallback(),this._core?.rerender()}reviveWorkspace(t){const n=new I(t.id,t.name,t.viewport);return n._core=this._core,n.createdAt=new Date(t.createdAt),n.updatedAt=new Date(t.updatedAt),n}transaction(t){this._ydoc&&this._ydoc.transact(t,"local")}loadFromYjs(){this._workspacesMap&&(this.map.clear(),this._workspacesMap.forEach(((t,n)=>{const e=this.reviveWorkspace(t);this.map.set(n,e)})))}reset(){this.map.clear(),this._ydoc.transact((()=>{this._workspacesMap.clear()}),"local")}insert(t){if(!t.id)return!1;if(this.map.set(t.id,t),this._workspacesMap){const n=t.serialize();this._ydoc.transact((()=>{this._workspacesMap.set(t.id,n)}),"local")}return!0}update(t){if(!t.id||!this.map.has(t.id))return!1;if(this.map.set(t.id,t),this._workspacesMap){const n=t.serialize();this._ydoc.transact((()=>{this._workspacesMap.set(t.id,n)}),"local")}return!0}remove(t){const n=Array.from(this.map.values()).find(t);return!!n&&(this.map.delete(n.id),this._workspacesMap&&this._ydoc.transact((()=>{this._workspacesMap.delete(n.id)}),"local"),!0)}get(t){return this.map.get(t)}allWorkspaces(){return Array.from(this.map.values())}filter(t){return Array.from(this.map.values()).filter(t)}find(t){return Array.from(this.map.values()).find(t)}has(t){return this.map.has(t)}destroy(){this._providers.forEach((t=>t.disconnect())),this._providers=[],this.map.clear(),this._workspacesMap=null,this._ydoc&&(this._ydoc.destroy(),this._ydoc=null),this._isReady=!1}}class Ec{static isInstanceOf(t,n){return!!t&&t.__class__===n}}class jc{_core;_anchorIndex=new Map;constructor(t){this._core=t}setAnchor(t,n,e){const r=this.getLineById(t);if(!r)return;if("start"===n&&r.endAnchor?.objectId===e)return;if("end"===n&&r.startAnchor?.objectId===e)return;this.removeAnchor(t,n);const i={objectId:e};"start"===n?r.startAnchor=i:r.endAnchor=i,this.addToIndex(e,t,n),this.snapEndpointToObject(r,n,e),this._core.store.state.objects.update(r)}removeAnchor(t,n){const e=this.getLineById(t);if(!e)return;const r="start"===n?e.startAnchor:e.endAnchor;r&&(this.removeFromIndex(r.objectId,t,n),"start"===n?e.startAnchor=void 0:e.endAnchor=void 0)}getAnchor(t,n){const e=this.getLineById(t);return e?("start"===n?e.startAnchor:e.endAnchor)??null:null}getLinesAnchoredTo(t){const n=this._anchorIndex.get(t);return n?Array.from(n):[]}updateAnchorsForObject(t){const n=this.getLinesAnchoredTo(t);if(0!==n.length&&this.getObjectById(t))for(const e of n){const n=this.getLineById(e.lineId);n&&this.snapEndpointToObject(n,e.endpoint,t)}}snapEndpointToObject(t,n,e){const r=this.getObjectById(e);if(!r)return;const i=this.worldToLineLocal(t,r.centerX,r.centerY);t.updateEndpoint(n,i.x,i.y)}worldToLineLocal(t,n,e){const r=n-t.centerX,i=e-t.centerY,s=Math.cos(-t.rotation),o=Math.sin(-t.rotation);return{x:(r*s-i*o+t.totalWidth/2/t.scale)*t.scale+t.x,y:(r*o+i*s+t.totalHeight/2/t.scale)*t.scale+t.y}}findSnapTarget(t,n,e,r){let i=null,s=-1/0;const o=this._core.store.allNonSelectionObjects;for(const u of o){if(u.id===e)continue;if(r&&u.id===r)continue;if(!this.isAnchorable(u))continue;const o=u.rotatedPolygon;f.isPointInPolygon({x:t,y:n},[o.topLeft,o.topRight,o.bottomRight,o.bottomLeft])&&u.zIndex>s&&(s=u.zIndex,i={objectId:u.id,centerX:u.centerX,centerY:u.centerY})}return i}setSnapCandidate(t){this._core.store.state.snapCandidate=t,this._core.rerender()}getSnapCandidate(){return this._core.store.state.snapCandidate??null}clearSnapCandidate(){this._core.store.state.snapCandidate=null,this._core.rerender()}getAnchorLinesRenderData(){const t=this._core.store.selectionGroup;if(!t||1!==t.objects.length)return null;const n=t.objects[0];if(!Ec.isInstanceOf(n,"KritzelLine"))return null;const e=n,r=this.computeAnchorVisualization(e,"start"),i=this.computeAnchorVisualization(e,"end");if(!r&&!i)return null;const s=this._core.store.state.scale,o=e.strokeWidth/e.scale,u=""+2/s,c=Math.max(2*o,4/s);return{lineStrokeWidth:o,indicatorStrokeWidth:u,dashArray:`${c} ${c}`,indicatorRadius:8/s,startAnchorViz:r,endAnchorViz:i}}getSnapIndicatorRenderData(){const t=this.getSnapCandidate();if(!t)return null;const n=this._core.store.state.scale,e=8/n,r=""+2/n,i=t.lineStrokeWidth?`${t.lineStrokeWidth}`:""+4/n,s=Math.max(2*(t.lineStrokeWidth||4/n),4/n),o=`${s} ${s}`,u=t.lineStroke||"#000000";let c,h=t.edgeX,a=t.edgeY;if(t.arrowOffset&&void 0!==t.edgeX&&void 0!==t.edgeY){const n=t.lineEndpointX-t.edgeX,e=t.lineEndpointY-t.edgeY,r=Math.sqrt(n*n+e*e);r>t.arrowOffset&&(h=t.edgeX+n/r*t.arrowOffset,a=t.edgeY+e/r*t.arrowOffset);const i=t.edgeX-t.lineEndpointX,s=t.edgeY-t.lineEndpointY,o=Math.sqrt(i*i+s*s);if(o>0){const n=i/o,e=s/o,r=-e,u=t.arrowOffset,h=t.edgeX,a=t.edgeY,l=h-n*u,f=a-e*u;c=`${h},${a} ${l+r*u/2},${f+n*u/2} ${l-r*u/2},${f-n*u/2}`}}return{indicatorRadius:e,indicatorStrokeWidth:r,lineStrokeWidth:i,dashArray:o,lineStroke:u,centerX:t.centerX,centerY:t.centerY,lineEndpointX:t.lineEndpointX,lineEndpointY:t.lineEndpointY,edgeX:t.edgeX,edgeY:t.edgeY,arrowOffset:t.arrowOffset,arrowStyle:t.arrowStyle,arrowFill:t.arrowFill,solidLineEndX:h,solidLineEndY:a,arrowPoints:c,snapLinePath:(()=>{if(void 0!==t.controlX&&void 0!==t.controlY&&void 0!==t.t){const n="start"===t.endpoint?1-t.t:t.t;if(n>=1)return;const e=this.extractQuadraticSegment({x:t.lineEndpointX,y:t.lineEndpointY},{x:t.controlX,y:t.controlY},{x:t.centerX,y:t.centerY},n,1);return`M ${e.start.x} ${e.start.y} Q ${e.control.x} ${e.control.y} ${e.end.x} ${e.end.y}`}})()}}handleObjectDeleted(t){const n=this.getLinesAnchoredTo(t);for(const t of n){this.removeAnchor(t.lineId,t.endpoint);const n=this.getLineById(t.lineId);n&&this._core.store.state.objects.update(n)}this._anchorIndex.delete(t)}handleLineDeleted(t){const n=this.getLineById(t);n&&(n.startAnchor&&this.removeFromIndex(n.startAnchor.objectId,t,"start"),n.endAnchor&&this.removeFromIndex(n.endAnchor.objectId,t,"end"))}rebuildIndex(){this._anchorIndex.clear();const t=this._core.store.allObjects;for(const n of t)n instanceof l&&(n.startAnchor&&this.addToIndex(n.startAnchor.objectId,n.id,"start"),n.endAnchor&&this.addToIndex(n.endAnchor.objectId,n.id,"end"))}addToIndex(t,n,e){this._anchorIndex.has(t)||this._anchorIndex.set(t,new Set);const r=this._anchorIndex.get(t);for(const t of r)if(t.lineId===n&&t.endpoint===e)return;r.add({lineId:n,endpoint:e})}removeFromIndex(t,n,e){const r=this._anchorIndex.get(t);if(r){for(const t of r)if(t.lineId===n&&t.endpoint===e){r.delete(t);break}0===r.size&&this._anchorIndex.delete(t)}}getLineById(t){const n=this._core.store.state.objects.filter((n=>n.id===t));if(0===n.length)return null;const e=n[0];return e instanceof l?e:null}getObjectById(t){const n=this._core.store.state.objects.filter((n=>n.id===t));return n.length>0?n[0]:null}findAnchorTarget(t,n){const e="start"===n?t.startAnchor:t.endAnchor;return e?this._core.store.allNonSelectionObjects.find((t=>t.id===e.objectId))??null:null}computeAnchorVisualization(t,n){if(!("start"===n?t.startAnchor:t.endAnchor))return null;const e=this.findAnchorTarget(t,n);if(!e)return null;const r=this.computeAnchorClipInfo(t,n,e);return r?{edgeX:r.worldX,edgeY:r.worldY,centerX:e.centerX,centerY:e.centerY,pathD:this.buildAnchorPath(t,n,r,e)??void 0}:null}computeClippedLinePath(t,n=!1){const e=this.getSnapCandidate(),r=this._core.store.selectionGroup,i=e&&r&&1===r.objects.length&&r.objects[0].id===t.id;if(!t.startAnchor&&!t.endAnchor&&!i)return n?void 0!==t.controlX&&void 0!==t.controlY?`M ${t.startX-t.x} ${t.startY-t.y} Q ${t.controlX-t.x} ${t.controlY-t.y} ${t.endX-t.x} ${t.endY-t.y}`:`M ${t.startX-t.x} ${t.startY-t.y} L ${t.endX-t.x} ${t.endY-t.y}`:t.d;const s=t.startAnchor?this.findAnchorTarget(t,"start"):null,o=t.endAnchor?this.findAnchorTarget(t,"end"):null;let u=s?this.computeAnchorClipInfo(t,"start",s):null,c=o?this.computeAnchorClipInfo(t,"end",o):null;if(i&&void 0!==e.edgeX&&void 0!==e.edgeY){const n=this.lineWorldToLocal(t,e.edgeX,e.edgeY),r={worldX:e.edgeX,worldY:e.edgeY,localX:n.x,localY:n.y,t:e.t};"start"===e.endpoint?u=r:c=r}const h=n?t.x:0,a=n?t.y:0;if(void 0!==t.controlX&&void 0!==t.controlY){let n=u?.t??0,e=c?.t??1;if(u&&t.hasStartArrow){const e=t.getArrowSize("start"),r=this.evaluateDerivativeSpeedAtT(t,n);r>0&&(n+=e/r)}if(c&&t.hasEndArrow){const n=t.getArrowSize("end"),r=this.evaluateDerivativeSpeedAtT(t,e);r>0&&(e-=n/r)}if(n<0&&(n=0),e>1&&(e=1),e<=n){const t=(n+e)/2;n=t,e=t}const r=this.extractQuadraticSegment({x:t.startX,y:t.startY},{x:t.controlX,y:t.controlY},{x:t.endX,y:t.endY},n,e);return`M ${r.start.x-h} ${r.start.y-a} Q ${r.control.x-h} ${r.control.y-a} ${r.end.x-h} ${r.end.y-a}`}let l=u?.localX??t.startX,f=u?.localY??t.startY,d=c?.localX??t.endX,v=c?.localY??t.endY;if(u&&t.hasStartArrow){const n=t.getArrowSize("start"),e=d-l,r=v-f,i=Math.sqrt(e*e+r*r);i>n&&(l+=e/i*n,f+=r/i*n)}if(c&&t.hasEndArrow){const n=t.getArrowSize("end"),e=l-d,r=f-v,i=Math.sqrt(e*e+r*r);i>n&&(d+=e/i*n,v+=r/i*n)}return`M ${l-h} ${f-a} L ${d-h} ${v-a}`}computeAnchorClipInfo(t,n,e){return void 0!==t.controlX&&void 0!==t.controlY?this.computeCurvedClipInfo(t,n,e):this.computeStraightClipInfo(t,n,e)}computeStraightClipInfo(t,n,e){const r="start"===n?this.lineLocalToWorld(t,t.endX,t.endY):this.lineLocalToWorld(t,t.startX,t.startY),i=this.getPathClipPoint(e,r);if(i){const e=this.lineWorldToLocal(t,i.x,i.y),r=Math.sqrt(Math.pow(t.endX-t.startX,2)+Math.pow(t.endY-t.startY,2)),s=Math.sqrt(Math.pow(e.x-t.startX,2)+Math.pow(e.y-t.startY,2));return{localX:e.x,localY:e.y,worldX:i.x,worldY:i.y,t:r>0?s/r:"start"===n?0:1}}const s=this.getClipPolygonForObject(e);let o;if(o=s?f.getLinePointsArrayIntersection(r,{x:e.centerX,y:e.centerY},s):f.getLinePolygonIntersection(r,{x:e.centerX,y:e.centerY},e.rotatedPolygon),!o)return null;const u=this.lineWorldToLocal(t,o.x,o.y),c=Math.sqrt(Math.pow(t.endX-t.startX,2)+Math.pow(t.endY-t.startY,2)),h=Math.sqrt(Math.pow(u.x-t.startX,2)+Math.pow(u.y-t.startY,2));return{localX:u.x,localY:u.y,worldX:o.x,worldY:o.y,t:c>0?h/c:"start"===n?0:1}}computeCurvedClipInfo(t,n,e){if(Ec.isInstanceOf(e,"KritzelPath"))return this.findCurveExitPointForPath(t,n,e);const r=this.getClipPolygonForObject(e),i=r??this.getPolygonPoints(e.rotatedPolygon),s=this.findCurveExitPoint(t,n,i);if(s)return s;const o="start"===n?this.lineLocalToWorld(t,t.endX,t.endY):this.lineLocalToWorld(t,t.startX,t.startY);let u;if(u=r?f.getLinePointsArrayIntersection(o,{x:e.centerX,y:e.centerY},r):f.getLinePolygonIntersection(o,{x:e.centerX,y:e.centerY},e.rotatedPolygon),!u)return null;const c=this.lineWorldToLocal(t,u.x,u.y),h=this.approximateParameterForWorldPoint(t,u);return{localX:c.x,localY:c.y,worldX:u.x,worldY:u.y,t:h}}findCurveExitPoint(t,n,e){const r="start"===n?0:1,i=this.evaluateLineAtT(t,r);let s=f.isPointInPolygon({x:i.worldX,y:i.worldY},e),o=r;for(let r=1;r<=64;r++){const i="start"===n?r/64:1-r/64,u=this.evaluateLineAtT(t,i),c=f.isPointInPolygon({x:u.worldX,y:u.worldY},e);if(s&&!c){const n=this.refineCurveExitParameter(t,e,o,i),r=this.evaluateLineAtT(t,n);return{localX:r.localX,localY:r.localY,worldX:r.worldX,worldY:r.worldY,t:n}}s=c,o=i}return null}findCurveExitPointForPath(t,n,e){const r="start"===n?0:1,i=e.strokeWidth/e.scale/2,s=this.getPathAdjustedPoints(e);if(s.length<1)return null;const o=this.evaluateLineAtT(t,r);let u=this.isPointInPathStroke(o.worldX,o.worldY,s,i),c=r;for(let e=1;e<=64;e++){const r="start"===n?e/64:1-e/64,o=this.evaluateLineAtT(t,r),h=this.isPointInPathStroke(o.worldX,o.worldY,s,i);if(u&&!h){const n=this.refineCurveExitParameterForPath(t,s,i,c,r),e=this.evaluateLineAtT(t,n);return{localX:e.localX,localY:e.localY,worldX:e.worldX,worldY:e.worldY,t:n}}u=h,c=r}return null}refineCurveExitParameterForPath(t,n,e,r,i){let s=r,o=i;for(let r=0;r<8;r++){const r=(s+o)/2,i=this.evaluateLineAtT(t,r);this.isPointInPathStroke(i.worldX,i.worldY,n,e)?s=r:o=r}return(s+o)/2}getPathAdjustedPoints(t){return this.computePathAdjustedPoints(t)}computePathAdjustedPoints(t){if(!t.points?.length)return[];const n=t.rotation,e=Math.cos(n),r=Math.sin(n),i=t.points.map((t=>t[0])),s=t.points.map((t=>t[1])),o={x:(Math.min(...i)+Math.max(...i))/2,y:(Math.min(...s)+Math.max(...s))/2},{x:u,y:c}=o;return t.points.map((([t,n])=>{const i=t-u,s=n-c;return[u+i*e-s*r,c+i*r+s*e]})).map((([n,e])=>[Math.abs(n-t.x)/t.scale+t.translateX,Math.abs(e-t.y)/t.scale+t.translateY]))}isPointInPathStroke(t,n,e,r){if(1===e.length){const i=e[0],s=t-i[0],o=n-i[1];return Math.sqrt(s*s+o*o)<=r}for(let i=0;i<e.length-1;i++){const s=e[i],o=e[i+1];if(this.pointToSegmentDistance(t,n,s[0],s[1],o[0],o[1])<=r)return!0}return!1}pointToSegmentDistance(t,n,e,r,i,s){const o=i-e,u=s-r,c=o*o+u*u;if(0===c)return Math.sqrt((t-e)*(t-e)+(n-r)*(n-r));let h=((t-e)*o+(n-r)*u)/c;h=Math.max(0,Math.min(1,h));const a=e+h*o,l=r+h*u;return Math.sqrt((t-a)*(t-a)+(n-l)*(n-l))}refineCurveExitParameter(t,n,e,r){let i=e,s=r;for(let e=0;e<8;e++){const e=(i+s)/2,r=this.evaluateLineAtT(t,e);f.isPointInPolygon({x:r.worldX,y:r.worldY},n)?i=e:s=e}return(i+s)/2}approximateParameterForWorldPoint(t,n){let e=0,r=1/0;for(let i=0;i<=80;i++){const s=i/80,o=this.evaluateLineAtT(t,s),u=Math.hypot(o.worldX-n.x,o.worldY-n.y);u<r&&(r=u,e=s)}return e}evaluateLineAtT(t,n){const e=Math.max(0,Math.min(1,n));let r,i;if(void 0!==t.controlX&&void 0!==t.controlY){const n=1-e;r=n*n*t.startX+2*n*e*t.controlX+e*e*t.endX,i=n*n*t.startY+2*n*e*t.controlY+e*e*t.endY}else r=t.startX+(t.endX-t.startX)*e,i=t.startY+(t.endY-t.startY)*e;const s=this.lineLocalToWorld(t,r,i);return{t:e,localX:r,localY:i,worldX:s.x,worldY:s.y}}evaluateDerivativeSpeedAtT(t,n){const e=Math.max(0,Math.min(1,n));if(void 0!==t.controlX&&void 0!==t.controlY){const n=t.controlX,r=t.controlY,i=2*(1-e)*(n-t.startX)+2*e*(t.endX-n),s=2*(1-e)*(r-t.startY)+2*e*(t.endY-r);return Math.sqrt(i*i+s*s)}{const n=t.endX-t.startX,e=t.endY-t.startY;return Math.sqrt(n*n+e*e)}}extractQuadraticSegment(t,n,e,r,i){let s=Math.max(0,Math.min(1,r)),o=Math.max(0,Math.min(1,i));if(o<s){const t=s;s=o,o=t}let u={start:t,control:n,end:e};if(s>0){u=this.splitQuadraticSegment(u,s).right;const t=1-s;o=t>0?(o-s)/t:1}return o<1&&(u=this.splitQuadraticSegment(u,o).left),u}splitQuadraticSegment(t,n){const e=Math.max(0,Math.min(1,n)),r=t.start,i=t.control,s=t.end,o=this.lerpPoint(r,i,e),u=this.lerpPoint(i,s,e),c=this.lerpPoint(o,u,e);return{left:{start:r,control:o,end:c},right:{start:c,control:u,end:s}}}lerpPoint(t,n,e){return{x:t.x+(n.x-t.x)*e,y:t.y+(n.y-t.y)*e}}buildAnchorPath(t,n,e,r){if(void 0===t.controlX||void 0===t.controlY||void 0===e.t)return`M ${e.worldX} ${e.worldY} L ${r.centerX} ${r.centerY}`;const i="start"===n?0:e.t,s="start"===n?e.t:1;if(s<=i)return`M ${e.worldX} ${e.worldY} L ${r.centerX} ${r.centerY}`;const o=this.extractQuadraticSegment({x:t.startX,y:t.startY},{x:t.controlX,y:t.controlY},{x:t.endX,y:t.endY},i,s);return this.buildWorldQuadraticPath(t,o,"start"===n)}buildWorldQuadraticPath(t,n,e=!1){const r=e?n.end:n.start,i=e?n.start:n.end,s=n.control,o=this.lineLocalToWorld(t,r.x,r.y),u=this.lineLocalToWorld(t,s.x,s.y),c=this.lineLocalToWorld(t,i.x,i.y);return`M ${o.x} ${o.y} Q ${u.x} ${u.y} ${c.x} ${c.y}`}getPolygonPoints(t){return[t.topLeft,t.topRight,t.bottomRight,t.bottomLeft]}getClipPolygonForObject(t){return Ec.isInstanceOf(t,"KritzelShape")?t.getClipPolygon():null}getPathClipPoint(t,n){return Ec.isInstanceOf(t,"KritzelPath")?t.getClipPoint(n):null}lineLocalToWorld(t,n,e){const r=n-t.x,i=e-t.y,s=t.totalWidth/2,o=t.totalHeight/2,u=Math.cos(t.rotation),c=Math.sin(t.rotation);return{x:((r-s)*u-(i-o)*c+s)/t.scale+t.translateX,y:((r-s)*c+(i-o)*u+o)/t.scale+t.translateY}}lineWorldToLocal(t,n,e){const r=(n-t.translateX)*t.scale,i=(e-t.translateY)*t.scale,s=t.totalWidth/2,o=t.totalHeight/2,u=Math.cos(-t.rotation),c=Math.sin(-t.rotation);return{x:(r-s)*u-(i-o)*c+s+t.x,y:(r-s)*c+(i-o)*u+o+t.y}}isAnchorable(t){return!(t instanceof d||t instanceof v)&&!(t instanceof l)&&t.isVisible}}const Tc=1e3,Ic=1e-4;var Oc,_c,zc,$c={exports:{}},Dc=(Oc||(Oc=1,_c=$c,zc=$c.exports,function(){var t,n="Expected a function",e="__lodash_hash_undefined__",r="__lodash_placeholder__",i=32,s=128,o=1/0,u=9007199254740991,c=NaN,h=4294967295,a=[["ary",s],["bind",1],["bindKey",2],["curry",8],["curryRight",16],["flip",512],["partial",i],["partialRight",64],["rearg",256]],l="[object Arguments]",f="[object Array]",d="[object Boolean]",v="[object Date]",p="[object Error]",w="[object Function]",y="[object GeneratorFunction]",g="[object Map]",b="[object Number]",m="[object Object]",A="[object Promise]",k="[object RegExp]",x="[object Set]",M="[object String]",S="[object Symbol]",C="[object WeakMap]",U="[object ArrayBuffer]",E="[object DataView]",j="[object Float32Array]",T="[object Float64Array]",I="[object Int8Array]",O="[object Int16Array]",_="[object Int32Array]",$="[object Uint8Array]",D="[object Uint8ClampedArray]",P="[object Uint16Array]",R="[object Uint32Array]",B=/\b__p \+= '';/g,W=/\b(__p \+=) '' \+/g,L=/(__e\(.*?\)|\b__t\)) \+\n'';/g,F=/&(?:amp|lt|gt|quot|#39);/g,N=/[&<>"']/g,K=RegExp(F.source),Q=RegExp(N.source),Y=/<%-([\s\S]+?)%>/g,H=/<%([\s\S]+?)%>/g,V=/<%=([\s\S]+?)%>/g,X=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,q=/^\w*$/,G=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,J=/[\\^$.*+?()[\]{}|]/g,Z=RegExp(J.source),tt=/^\s+/,nt=/\s/,et=/\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,rt=/\{\n\/\* \[wrapped with (.+)\] \*/,it=/,? & /,st=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g,ot=/[()=,{}\[\]\/\s]/,ut=/\\(\\)?/g,ct=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,ht=/\w*$/,at=/^[-+]0x[0-9a-f]+$/i,lt=/^0b[01]+$/i,ft=/^\[object .+?Constructor\]$/,dt=/^0o[0-7]+$/i,vt=/^(?:0|[1-9]\d*)$/,pt=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,wt=/($^)/,yt=/['\n\r\u2028\u2029\\]/g,gt="\\ud800-\\udfff",bt="\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff",mt="\\u2700-\\u27bf",At="a-z\\xdf-\\xf6\\xf8-\\xff",kt="A-Z\\xc0-\\xd6\\xd8-\\xde",xt="\\ufe0e\\ufe0f",Mt="\\xac\\xb1\\xd7\\xf7\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf\\u2000-\\u206f \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000",St="["+gt+"]",Ct="["+Mt+"]",Ut="["+bt+"]",Et="\\d+",jt="["+mt+"]",Tt="["+At+"]",It="[^"+gt+Mt+Et+mt+At+kt+"]",Ot="\\ud83c[\\udffb-\\udfff]",_t="[^"+gt+"]",zt="(?:\\ud83c[\\udde6-\\uddff]){2}",$t="[\\ud800-\\udbff][\\udc00-\\udfff]",Dt="["+kt+"]",Pt="\\u200d",Rt="(?:"+Tt+"|"+It+")",Bt="(?:"+Dt+"|"+It+")",Wt="(?:['’](?:d|ll|m|re|s|t|ve))?",Lt="(?:['’](?:D|LL|M|RE|S|T|VE))?",Ft="(?:"+Ut+"|"+Ot+")?",Nt="["+xt+"]?",Kt=Nt+Ft+"(?:"+Pt+"(?:"+[_t,zt,$t].join("|")+")"+Nt+Ft+")*",Qt="(?:"+[jt,zt,$t].join("|")+")"+Kt,Yt="(?:"+[_t+Ut+"?",Ut,zt,$t,St].join("|")+")",Ht=RegExp("['’]","g"),Vt=RegExp(Ut,"g"),Xt=RegExp(Ot+"(?="+Ot+")|"+Yt+Kt,"g"),qt=RegExp([Dt+"?"+Tt+"+"+Wt+"(?="+[Ct,Dt,"$"].join("|")+")",Bt+"+"+Lt+"(?="+[Ct,Dt+Rt,"$"].join("|")+")",Dt+"?"+Rt+"+"+Wt,Dt+"+"+Lt,"\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])","\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",Et,Qt].join("|"),"g"),Gt=RegExp("["+Pt+gt+bt+xt+"]"),Jt=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/,Zt=["Array","Buffer","DataView","Date","Error","Float32Array","Float64Array","Function","Int8Array","Int16Array","Int32Array","Map","Math","Object","Promise","RegExp","Set","String","Symbol","TypeError","Uint8Array","Uint8ClampedArray","Uint16Array","Uint32Array","WeakMap","_","clearTimeout","isFinite","parseInt","setTimeout"],tn=-1,nn={};nn[j]=nn[T]=nn[I]=nn[O]=nn[_]=nn[$]=nn[D]=nn[P]=nn[R]=!0,nn[l]=nn[f]=nn[U]=nn[d]=nn[E]=nn[v]=nn[p]=nn[w]=nn[g]=nn[b]=nn[m]=nn[k]=nn[x]=nn[M]=nn[C]=!1;var en={};en[l]=en[f]=en[U]=en[E]=en[d]=en[v]=en[j]=en[T]=en[I]=en[O]=en[_]=en[g]=en[b]=en[m]=en[k]=en[x]=en[M]=en[S]=en[$]=en[D]=en[P]=en[R]=!0,en[p]=en[w]=en[C]=!1;var rn={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"},sn=parseFloat,on=parseInt,un="object"==typeof z&&z&&z.Object===Object&&z,cn="object"==typeof self&&self&&self.Object===Object&&self,hn=un||cn||Function("return this")(),an=zc&&!zc.nodeType&&zc,ln=an&&_c&&!_c.nodeType&&_c,fn=ln&&ln.exports===an,dn=fn&&un.process,vn=function(){try{return ln&&ln.require&&ln.require("util").types||dn&&dn.binding&&dn.binding("util")}catch(t){}}(),pn=vn&&vn.isArrayBuffer,wn=vn&&vn.isDate,yn=vn&&vn.isMap,gn=vn&&vn.isRegExp,bn=vn&&vn.isSet,mn=vn&&vn.isTypedArray;function An(t,n,e){switch(e.length){case 0:return t.call(n);case 1:return t.call(n,e[0]);case 2:return t.call(n,e[0],e[1]);case 3:return t.call(n,e[0],e[1],e[2])}return t.apply(n,e)}function kn(t,n,e,r){for(var i=-1,s=null==t?0:t.length;++i<s;){var o=t[i];n(r,o,e(o),t)}return r}function xn(t,n){for(var e=-1,r=null==t?0:t.length;++e<r&&!1!==n(t[e],e,t););return t}function Mn(t,n){for(var e=null==t?0:t.length;e--&&!1!==n(t[e],e,t););return t}function Sn(t,n){for(var e=-1,r=null==t?0:t.length;++e<r;)if(!n(t[e],e,t))return!1;return!0}function Cn(t,n){for(var e=-1,r=null==t?0:t.length,i=0,s=[];++e<r;){var o=t[e];n(o,e,t)&&(s[i++]=o)}return s}function Un(t,n){return!(null==t||!t.length)&&Pn(t,n,0)>-1}function En(t,n,e){for(var r=-1,i=null==t?0:t.length;++r<i;)if(e(n,t[r]))return!0;return!1}function jn(t,n){for(var e=-1,r=null==t?0:t.length,i=Array(r);++e<r;)i[e]=n(t[e],e,t);return i}function Tn(t,n){for(var e=-1,r=n.length,i=t.length;++e<r;)t[i+e]=n[e];return t}function In(t,n,e,r){var i=-1,s=null==t?0:t.length;for(r&&s&&(e=t[++i]);++i<s;)e=n(e,t[i],i,t);return e}function On(t,n,e,r){var i=null==t?0:t.length;for(r&&i&&(e=t[--i]);i--;)e=n(e,t[i],i,t);return e}function _n(t,n){for(var e=-1,r=null==t?0:t.length;++e<r;)if(n(t[e],e,t))return!0;return!1}var zn=Ln("length");function $n(t,n,e){var r;return e(t,(function(t,e,i){if(n(t,e,i))return r=e,!1})),r}function Dn(t,n,e,r){for(var i=t.length,s=e+(r?1:-1);r?s--:++s<i;)if(n(t[s],s,t))return s;return-1}function Pn(t,n,e){return n==n?function(t,n,e){for(var r=e-1,i=t.length;++r<i;)if(t[r]===n)return r;return-1}(t,n,e):Dn(t,Bn,e)}function Rn(t,n,e,r){for(var i=e-1,s=t.length;++i<s;)if(r(t[i],n))return i;return-1}function Bn(t){return t!=t}function Wn(t,n){var e=null==t?0:t.length;return e?Kn(t,n)/e:c}function Ln(n){return function(e){return null==e?t:e[n]}}function Fn(n){return function(e){return null==n?t:n[e]}}function Nn(t,n,e,r,i){return i(t,(function(t,i,s){e=r?(r=!1,t):n(e,t,i,s)})),e}function Kn(n,e){for(var r,i=-1,s=n.length;++i<s;){var o=e(n[i]);o!==t&&(r=r===t?o:r+o)}return r}function Qn(t,n){for(var e=-1,r=Array(t);++e<t;)r[e]=n(e);return r}function Yn(t){return t?t.slice(0,he(t)+1).replace(tt,""):t}function Hn(t){return function(n){return t(n)}}function Vn(t,n){return jn(n,(function(n){return t[n]}))}function Xn(t,n){return t.has(n)}function qn(t,n){for(var e=-1,r=t.length;++e<r&&Pn(n,t[e],0)>-1;);return e}function Gn(t,n){for(var e=t.length;e--&&Pn(n,t[e],0)>-1;);return e}var Jn=Fn({À:"A",Á:"A",Â:"A",Ã:"A",Ä:"A",Å:"A",à:"a",á:"a",â:"a",ã:"a",ä:"a",å:"a",Ç:"C",ç:"c",Ð:"D",ð:"d",È:"E",É:"E",Ê:"E",Ë:"E",è:"e",é:"e",ê:"e",ë:"e",Ì:"I",Í:"I",Î:"I",Ï:"I",ì:"i",í:"i",î:"i",ï:"i",Ñ:"N",ñ:"n",Ò:"O",Ó:"O",Ô:"O",Õ:"O",Ö:"O",Ø:"O",ò:"o",ó:"o",ô:"o",õ:"o",ö:"o",ø:"o",Ù:"U",Ú:"U",Û:"U",Ü:"U",ù:"u",ú:"u",û:"u",ü:"u",Ý:"Y",ý:"y",ÿ:"y",Æ:"Ae",æ:"ae",Þ:"Th",þ:"th",ß:"ss",Ā:"A",Ă:"A",Ą:"A",ā:"a",ă:"a",ą:"a",Ć:"C",Ĉ:"C",Ċ:"C",Č:"C",ć:"c",ĉ:"c",ċ:"c",č:"c",Ď:"D",Đ:"D",ď:"d",đ:"d",Ē:"E",Ĕ:"E",Ė:"E",Ę:"E",Ě:"E",ē:"e",ĕ:"e",ė:"e",ę:"e",ě:"e",Ĝ:"G",Ğ:"G",Ġ:"G",Ģ:"G",ĝ:"g",ğ:"g",ġ:"g",ģ:"g",Ĥ:"H",Ħ:"H",ĥ:"h",ħ:"h",Ĩ:"I",Ī:"I",Ĭ:"I",Į:"I",İ:"I",ĩ:"i",ī:"i",ĭ:"i",į:"i",ı:"i",Ĵ:"J",ĵ:"j",Ķ:"K",ķ:"k",ĸ:"k",Ĺ:"L",Ļ:"L",Ľ:"L",Ŀ:"L",Ł:"L",ĺ:"l",ļ:"l",ľ:"l",ŀ:"l",ł:"l",Ń:"N",Ņ:"N",Ň:"N",Ŋ:"N",ń:"n",ņ:"n",ň:"n",ŋ:"n",Ō:"O",Ŏ:"O",Ő:"O",ō:"o",ŏ:"o",ő:"o",Ŕ:"R",Ŗ:"R",Ř:"R",ŕ:"r",ŗ:"r",ř:"r",Ś:"S",Ŝ:"S",Ş:"S",Š:"S",ś:"s",ŝ:"s",ş:"s",š:"s",Ţ:"T",Ť:"T",Ŧ:"T",ţ:"t",ť:"t",ŧ:"t",Ũ:"U",Ū:"U",Ŭ:"U",Ů:"U",Ű:"U",Ų:"U",ũ:"u",ū:"u",ŭ:"u",ů:"u",ű:"u",ų:"u",Ŵ:"W",ŵ:"w",Ŷ:"Y",ŷ:"y",Ÿ:"Y",Ź:"Z",Ż:"Z",Ž:"Z",ź:"z",ż:"z",ž:"z",IJ:"IJ",ij:"ij",Œ:"Oe",œ:"oe",ʼn:"'n",ſ:"s"}),Zn=Fn({"&":"&","<":"<",">":">",'"':""","'":"'"});function te(t){return"\\"+rn[t]}function ne(t){return Gt.test(t)}function ee(t){var n=-1,e=Array(t.size);return t.forEach((function(t,r){e[++n]=[r,t]})),e}function re(t,n){return function(e){return t(n(e))}}function ie(t,n){for(var e=-1,i=t.length,s=0,o=[];++e<i;){var u=t[e];u!==n&&u!==r||(t[e]=r,o[s++]=e)}return o}function se(t){var n=-1,e=Array(t.size);return t.forEach((function(t){e[++n]=t})),e}function oe(t){var n=-1,e=Array(t.size);return t.forEach((function(t){e[++n]=[t,t]})),e}function ue(t){return ne(t)?function(t){for(var n=Xt.lastIndex=0;Xt.test(t);)++n;return n}(t):zn(t)}function ce(t){return ne(t)?function(t){return t.match(Xt)||[]}(t):function(t){return t.split("")}(t)}function he(t){for(var n=t.length;n--&&nt.test(t.charAt(n)););return n}var ae=Fn({"&":"&","<":"<",">":">",""":'"',"'":"'"}),le=function z(nt){var gt,bt=(nt=null==nt?hn:le.defaults(hn.Object(),nt,le.pick(hn,Zt))).Array,mt=nt.Date,At=nt.Error,kt=nt.Function,xt=nt.Math,Mt=nt.Object,St=nt.RegExp,Ct=nt.String,Ut=nt.TypeError,Et=bt.prototype,jt=Mt.prototype,Tt=nt["__core-js_shared__"],It=kt.prototype.toString,Ot=jt.hasOwnProperty,_t=0,zt=(gt=/[^.]+$/.exec(Tt&&Tt.keys&&Tt.keys.IE_PROTO||""))?"Symbol(src)_1."+gt:"",$t=jt.toString,Dt=It.call(Mt),Pt=hn._,Rt=St("^"+It.call(Ot).replace(J,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Bt=fn?nt.Buffer:t,Wt=nt.Symbol,Lt=nt.Uint8Array,Ft=Bt?Bt.allocUnsafe:t,Nt=re(Mt.getPrototypeOf,Mt),Kt=Mt.create,Qt=jt.propertyIsEnumerable,Yt=Et.splice,Xt=Wt?Wt.isConcatSpreadable:t,Gt=Wt?Wt.iterator:t,rn=Wt?Wt.toStringTag:t,un=function(){try{var t=us(Mt,"defineProperty");return t({},"",{}),t}catch(t){}}(),cn=nt.clearTimeout!==hn.clearTimeout&&nt.clearTimeout,an=mt&&mt.now!==hn.Date.now&&mt.now,ln=nt.setTimeout!==hn.setTimeout&&nt.setTimeout,dn=xt.ceil,vn=xt.floor,zn=Mt.getOwnPropertySymbols,Fn=Bt?Bt.isBuffer:t,fe=nt.isFinite,de=Et.join,ve=re(Mt.keys,Mt),pe=xt.max,we=xt.min,ye=mt.now,ge=nt.parseInt,be=xt.random,me=Et.reverse,Ae=us(nt,"DataView"),ke=us(nt,"Map"),xe=us(nt,"Promise"),Me=us(nt,"Set"),Se=us(nt,"WeakMap"),Ce=us(Mt,"create"),Ue=Se&&new Se,Ee={},je=$s(Ae),Te=$s(ke),Ie=$s(xe),Oe=$s(Me),_e=$s(Se),ze=Wt?Wt.prototype:t,$e=ze?ze.valueOf:t,De=ze?ze.toString:t;function Pe(t){if(Zo(t)&&!Fo(t)&&!(t instanceof Le)){if(t instanceof We)return t;if(Ot.call(t,"__wrapped__"))return Ds(t)}return new We(t)}var Re=function(){function n(){}return function(e){if(!Jo(e))return{};if(Kt)return Kt(e);n.prototype=e;var r=new n;return n.prototype=t,r}}();function Be(){}function We(n,e){this.__wrapped__=n,this.__actions__=[],this.__chain__=!!e,this.__index__=0,this.__values__=t}function Le(t){this.__wrapped__=t,this.__actions__=[],this.__dir__=1,this.__filtered__=!1,this.__iteratees__=[],this.__takeCount__=h,this.__views__=[]}function Fe(t){var n=-1,e=null==t?0:t.length;for(this.clear();++n<e;){var r=t[n];this.set(r[0],r[1])}}function Ne(t){var n=-1,e=null==t?0:t.length;for(this.clear();++n<e;){var r=t[n];this.set(r[0],r[1])}}function Ke(t){var n=-1,e=null==t?0:t.length;for(this.clear();++n<e;){var r=t[n];this.set(r[0],r[1])}}function Qe(t){var n=-1,e=null==t?0:t.length;for(this.__data__=new Ke;++n<e;)this.add(t[n])}function Ye(t){var n=this.__data__=new Ne(t);this.size=n.size}function He(t,n){var e=Fo(t),r=!e&&Lo(t),i=!e&&!r&&Yo(t),s=!e&&!r&&!i&&uu(t),o=e||r||i||s,u=o?Qn(t.length,Ct):[],c=u.length;for(var h in t)!n&&!Ot.call(t,h)||o&&("length"==h||i&&("offset"==h||"parent"==h)||s&&("buffer"==h||"byteLength"==h||"byteOffset"==h)||vs(h,c))||u.push(h);return u}function Ve(n){var e=n.length;return e?n[Kr(0,e-1)]:t}function Xe(t,n){return Ts(Si(t),ir(n,0,t.length))}function qe(t){return Ts(Si(t))}function Ge(n,e,r){(r!==t&&!Ro(n[e],r)||r===t&&!(e in n))&&er(n,e,r)}function Je(n,e,r){var i=n[e];Ot.call(n,e)&&Ro(i,r)&&(r!==t||e in n)||er(n,e,r)}function Ze(t,n){for(var e=t.length;e--;)if(Ro(t[e][0],n))return e;return-1}function tr(t,n,e,r){return hr(t,(function(t,i,s){n(r,t,e(t),s)})),r}function nr(t,n){return t&&Ci(n,ju(n),t)}function er(t,n,e){"__proto__"==n&&un?un(t,n,{configurable:!0,enumerable:!0,value:e,writable:!0}):t[n]=e}function rr(n,e){for(var r=-1,i=e.length,s=bt(i),o=null==n;++r<i;)s[r]=o?t:Mu(n,e[r]);return s}function ir(n,e,r){return n==n&&(r!==t&&(n=n<=r?n:r),e!==t&&(n=n>=e?n:e)),n}function sr(n,e,r,i,s,o){var u,c=1&e,h=2&e,a=4&e;if(r&&(u=s?r(n,i,s,o):r(n)),u!==t)return u;if(!Jo(n))return n;var f=Fo(n);if(f){if(u=function(t){var n=t.length,e=new t.constructor(n);return n&&"string"==typeof t[0]&&Ot.call(t,"index")&&(e.index=t.index,e.input=t.input),e}(n),!c)return Si(n,u)}else{var p=as(n),A=p==w||p==y;if(Yo(n))return bi(n,c);if(p==m||p==l||A&&!s){if(u=h||A?{}:fs(n),!c)return h?function(t,n){return Ci(t,hs(t),n)}(n,function(t,n){return t&&Ci(n,Tu(n),t)}(u,n)):function(t,n){return Ci(t,cs(t),n)}(n,nr(u,n))}else{if(!en[p])return s?n:{};u=function(t,n,e){var r=t.constructor;switch(n){case U:return mi(t);case d:case v:return new r(+t);case E:return function(t,n){var e=n?mi(t.buffer):t.buffer;return new t.constructor(e,t.byteOffset,t.byteLength)}(t,e);case j:case T:case I:case O:case _:case $:case D:case P:case R:return Ai(t,e);case g:return new r;case b:case M:return new r(t);case k:return function(t){var n=new t.constructor(t.source,ht.exec(t));return n.lastIndex=t.lastIndex,n}(t);case x:return new r;case S:return $e?Mt($e.call(t)):{}}}(n,p,c)}}o||(o=new Ye);var C=o.get(n);if(C)return C;o.set(n,u),iu(n)?n.forEach((function(t){u.add(sr(t,e,r,t,n,o))})):tu(n)&&n.forEach((function(t,i){u.set(i,sr(t,e,r,i,n,o))}));var z=f?t:(a?h?ts:Zi:h?Tu:ju)(n);return xn(z||n,(function(t,i){z&&(t=n[i=t]),Je(u,i,sr(t,e,r,i,n,o))})),u}function or(n,e,r){var i=r.length;if(null==n)return!i;for(n=Mt(n);i--;){var s=r[i],o=n[s];if(o===t&&!(s in n)||!(0,e[s])(o))return!1}return!0}function ur(e,r,i){if("function"!=typeof e)throw new Ut(n);return Cs((function(){e.apply(t,i)}),r)}function cr(t,n,e,r){var i=-1,s=Un,o=!0,u=t.length,c=[],h=n.length;if(!u)return c;e&&(n=jn(n,Hn(e))),r?(s=En,o=!1):n.length>=200&&(s=Xn,o=!1,n=new Qe(n));t:for(;++i<u;){var a=t[i],l=null==e?a:e(a);if(a=r||0!==a?a:0,o&&l==l){for(var f=h;f--;)if(n[f]===l)continue t;c.push(a)}else s(n,l,r)||c.push(a)}return c}Pe.templateSettings={escape:Y,evaluate:H,interpolate:V,variable:"",imports:{_:Pe}},(Pe.prototype=Be.prototype).constructor=Pe,(We.prototype=Re(Be.prototype)).constructor=We,(Le.prototype=Re(Be.prototype)).constructor=Le,Fe.prototype.clear=function(){this.__data__=Ce?Ce(null):{},this.size=0},Fe.prototype.delete=function(t){var n=this.has(t)&&delete this.__data__[t];return this.size-=n?1:0,n},Fe.prototype.get=function(n){var r=this.__data__;if(Ce){var i=r[n];return i===e?t:i}return Ot.call(r,n)?r[n]:t},Fe.prototype.has=function(n){var e=this.__data__;return Ce?e[n]!==t:Ot.call(e,n)},Fe.prototype.set=function(n,r){var i=this.__data__;return this.size+=this.has(n)?0:1,i[n]=Ce&&r===t?e:r,this},Ne.prototype.clear=function(){this.__data__=[],this.size=0},Ne.prototype.delete=function(t){var n=this.__data__,e=Ze(n,t);return!(e<0||(e==n.length-1?n.pop():Yt.call(n,e,1),--this.size,0))},Ne.prototype.get=function(n){var e=this.__data__,r=Ze(e,n);return r<0?t:e[r][1]},Ne.prototype.has=function(t){return Ze(this.__data__,t)>-1},Ne.prototype.set=function(t,n){var e=this.__data__,r=Ze(e,t);return r<0?(++this.size,e.push([t,n])):e[r][1]=n,this},Ke.prototype.clear=function(){this.size=0,this.__data__={hash:new Fe,map:new(ke||Ne),string:new Fe}},Ke.prototype.delete=function(t){var n=ss(this,t).delete(t);return this.size-=n?1:0,n},Ke.prototype.get=function(t){return ss(this,t).get(t)},Ke.prototype.has=function(t){return ss(this,t).has(t)},Ke.prototype.set=function(t,n){var e=ss(this,t),r=e.size;return e.set(t,n),this.size+=e.size==r?0:1,this},Qe.prototype.add=Qe.prototype.push=function(t){return this.__data__.set(t,e),this},Qe.prototype.has=function(t){return this.__data__.has(t)},Ye.prototype.clear=function(){this.__data__=new Ne,this.size=0},Ye.prototype.delete=function(t){var n=this.__data__,e=n.delete(t);return this.size=n.size,e},Ye.prototype.get=function(t){return this.__data__.get(t)},Ye.prototype.has=function(t){return this.__data__.has(t)},Ye.prototype.set=function(t,n){var e=this.__data__;if(e instanceof Ne){var r=e.__data__;if(!ke||r.length<199)return r.push([t,n]),this.size=++e.size,this;e=this.__data__=new Ke(r)}return e.set(t,n),this.size=e.size,this};var hr=ji(yr),ar=ji(gr,!0);function lr(t,n){var e=!0;return hr(t,(function(t,r,i){return e=!!n(t,r,i)})),e}function fr(n,e,r){for(var i=-1,s=n.length;++i<s;){var o=n[i],u=e(o);if(null!=u&&(c===t?u==u&&!ou(u):r(u,c)))var c=u,h=o}return h}function dr(t,n){var e=[];return hr(t,(function(t,r,i){n(t,r,i)&&e.push(t)})),e}function vr(t,n,e,r,i){var s=-1,o=t.length;for(e||(e=ds),i||(i=[]);++s<o;){var u=t[s];n>0&&e(u)?n>1?vr(u,n-1,e,r,i):Tn(i,u):r||(i[i.length]=u)}return i}var pr=Ti(),wr=Ti(!0);function yr(t,n){return t&&pr(t,n,ju)}function gr(t,n){return t&&wr(t,n,ju)}function br(t,n){return Cn(n,(function(n){return Xo(t[n])}))}function mr(n,e){for(var r=0,i=(e=pi(e,n)).length;null!=n&&r<i;)n=n[zs(e[r++])];return r&&r==i?n:t}function Ar(t,n,e){var r=n(t);return Fo(t)?r:Tn(r,e(t))}function kr(n){return null==n?n===t?"[object Undefined]":"[object Null]":rn&&rn in Mt(n)?function(n){var e=Ot.call(n,rn),r=n[rn];try{n[rn]=t;var i=!0}catch(t){}var s=$t.call(n);return i&&(e?n[rn]=r:delete n[rn]),s}(n):function(t){return $t.call(t)}(n)}function xr(t,n){return t>n}function Mr(t,n){return null!=t&&Ot.call(t,n)}function Sr(t,n){return null!=t&&n in Mt(t)}function Cr(n,e,r){for(var i=r?En:Un,s=n[0].length,o=n.length,u=o,c=bt(o),h=1/0,a=[];u--;){var l=n[u];u&&e&&(l=jn(l,Hn(e))),h=we(l.length,h),c[u]=!r&&(e||s>=120&&l.length>=120)?new Qe(u&&l):t}l=n[0];var f=-1,d=c[0];t:for(;++f<s&&a.length<h;){var v=l[f],p=e?e(v):v;if(v=r||0!==v?v:0,!(d?Xn(d,p):i(a,p,r))){for(u=o;--u;){var w=c[u];if(!(w?Xn(w,p):i(n[u],p,r)))continue t}d&&d.push(p),a.push(v)}}return a}function Ur(n,e,r){var i=null==(n=xs(n,e=pi(e,n)))?n:n[zs(Hs(e))];return null==i?t:An(i,n,r)}function Er(t){return Zo(t)&&kr(t)==l}function jr(n,e,r,i,s){return n===e||(null==n||null==e||!Zo(n)&&!Zo(e)?n!=n&&e!=e:function(n,e,r,i,s,o){var u=Fo(n),c=Fo(e),h=u?f:as(n),a=c?f:as(e),w=(h=h==l?m:h)==m,y=(a=a==l?m:a)==m,A=h==a;if(A&&Yo(n)){if(!Yo(e))return!1;u=!0,w=!1}if(A&&!w)return o||(o=new Ye),u||uu(n)?Gi(n,e,r,i,s,o):function(t,n,e,r,i,s,o){switch(e){case E:if(t.byteLength!=n.byteLength||t.byteOffset!=n.byteOffset)return!1;t=t.buffer,n=n.buffer;case U:return!(t.byteLength!=n.byteLength||!s(new Lt(t),new Lt(n)));case d:case v:case b:return Ro(+t,+n);case p:return t.name==n.name&&t.message==n.message;case k:case M:return t==n+"";case g:var u=ee;case x:if(u||(u=se),t.size!=n.size&&!(1&r))return!1;var c=o.get(t);if(c)return c==n;r|=2,o.set(t,n);var h=Gi(u(t),u(n),r,i,s,o);return o.delete(t),h;case S:if($e)return $e.call(t)==$e.call(n)}return!1}(n,e,h,r,i,s,o);if(!(1&r)){var C=w&&Ot.call(n,"__wrapped__"),j=y&&Ot.call(e,"__wrapped__");if(C||j){var T=C?n.value():n,I=j?e.value():e;return o||(o=new Ye),s(T,I,r,i,o)}}return!!A&&(o||(o=new Ye),function(n,e,r,i,s,o){var u=1&r,c=Zi(n),h=c.length;if(h!=Zi(e).length&&!u)return!1;for(var a=h;a--;){var l=c[a];if(!(u?l in e:Ot.call(e,l)))return!1}var f=o.get(n),d=o.get(e);if(f&&d)return f==e&&d==n;var v=!0;o.set(n,e),o.set(e,n);for(var p=u;++a<h;){var w=n[l=c[a]],y=e[l];if(i)var g=u?i(y,w,l,e,n,o):i(w,y,l,n,e,o);if(!(g===t?w===y||s(w,y,r,i,o):g)){v=!1;break}p||(p="constructor"==l)}if(v&&!p){var b=n.constructor,m=e.constructor;b==m||!("constructor"in n)||!("constructor"in e)||"function"==typeof b&&b instanceof b&&"function"==typeof m&&m instanceof m||(v=!1)}return o.delete(n),o.delete(e),v}(n,e,r,i,s,o))}(n,e,r,i,jr,s))}function Tr(n,e,r,i){var s=r.length,o=s,u=!i;if(null==n)return!o;for(n=Mt(n);s--;){var c=r[s];if(u&&c[2]?c[1]!==n[c[0]]:!(c[0]in n))return!1}for(;++s<o;){var h=(c=r[s])[0],a=n[h],l=c[1];if(u&&c[2]){if(a===t&&!(h in n))return!1}else{var f=new Ye;if(i)var d=i(a,l,h,n,e,f);if(!(d===t?jr(l,a,3,i,f):d))return!1}}return!0}function Ir(t){return!(!Jo(t)||(n=t,zt&&zt in n))&&(Xo(t)?Rt:ft).test($s(t));var n}function Or(t){return"function"==typeof t?t:null==t?nc:"object"==typeof t?Fo(t)?Pr(t[0],t[1]):Dr(t):ac(t)}function _r(t){if(!bs(t))return ve(t);var n=[];for(var e in Mt(t))Ot.call(t,e)&&"constructor"!=e&&n.push(e);return n}function zr(t,n){return t<n}function $r(t,n){var e=-1,r=Ko(t)?bt(t.length):[];return hr(t,(function(t,i,s){r[++e]=n(t,i,s)})),r}function Dr(t){var n=os(t);return 1==n.length&&n[0][2]?As(n[0][0],n[0][1]):function(e){return e===t||Tr(e,t,n)}}function Pr(n,e){return ws(n)&&ms(e)?As(zs(n),e):function(r){var i=Mu(r,n);return i===t&&i===e?Su(r,n):jr(e,i,3)}}function Rr(n,e,r,i,s){n!==e&&pr(e,(function(o,u){if(s||(s=new Ye),Jo(o))!function(n,e,r,i,s,o,u){var c=Ms(n,r),h=Ms(e,r),a=u.get(h);if(a)Ge(n,r,a);else{var l=o?o(c,h,r+"",n,e,u):t,f=l===t;if(f){var d=Fo(h),v=!d&&Yo(h),p=!d&&!v&&uu(h);l=h,d||v||p?Fo(c)?l=c:Qo(c)?l=Si(c):v?(f=!1,l=bi(h,!0)):p?(f=!1,l=Ai(h,!0)):l=[]:eu(h)||Lo(h)?(l=c,Lo(c)?l=pu(c):Jo(c)&&!Xo(c)||(l=fs(h))):f=!1}f&&(u.set(h,l),s(l,h,i,o,u),u.delete(h)),Ge(n,r,l)}}(n,e,u,r,Rr,i,s);else{var c=i?i(Ms(n,u),o,u+"",n,e,s):t;c===t&&(c=o),Ge(n,u,c)}}),Tu)}function Br(n,e){var r=n.length;if(r)return vs(e+=e<0?r:0,r)?n[e]:t}function Wr(t,n,e){n=n.length?jn(n,(function(t){return Fo(t)?function(n){return mr(n,1===t.length?t[0]:t)}:t})):[nc];var r=-1;n=jn(n,Hn(is()));var i=$r(t,(function(t){var e=jn(n,(function(n){return n(t)}));return{criteria:e,index:++r,value:t}}));return function(t){var n=t.length;for(t.sort((function(t,n){return function(t,n,e){for(var r=-1,i=t.criteria,s=n.criteria,o=i.length,u=e.length;++r<o;){var c=ki(i[r],s[r]);if(c)return r>=u?c:c*("desc"==e[r]?-1:1)}return t.index-n.index}(t,n,e)}));n--;)t[n]=t[n].value;return t}(i)}function Lr(t,n,e){for(var r=-1,i=n.length,s={};++r<i;){var o=n[r],u=mr(t,o);e(u,o)&&Xr(s,pi(o,t),u)}return s}function Fr(t,n,e,r){var i=r?Rn:Pn,s=-1,o=n.length,u=t;for(t===n&&(n=Si(n)),e&&(u=jn(t,Hn(e)));++s<o;)for(var c=0,h=n[s],a=e?e(h):h;(c=i(u,a,c,r))>-1;)u!==t&&Yt.call(u,c,1),Yt.call(t,c,1);return t}function Nr(t,n){for(var e=t?n.length:0,r=e-1;e--;){var i=n[e];if(e==r||i!==s){var s=i;vs(i)?Yt.call(t,i,1):ui(t,i)}}return t}function Kr(t,n){return t+vn(be()*(n-t+1))}function Qr(t,n){var e="";if(!t||n<1||n>u)return e;do{n%2&&(e+=t),(n=vn(n/2))&&(t+=t)}while(n);return e}function Yr(t,n){return Us(ks(t,n,nc),t+"")}function Hr(t){return Ve(Ru(t))}function Vr(t,n){var e=Ru(t);return Ts(e,ir(n,0,e.length))}function Xr(n,e,r,i){if(!Jo(n))return n;for(var s=-1,o=(e=pi(e,n)).length,u=o-1,c=n;null!=c&&++s<o;){var h=zs(e[s]),a=r;if("__proto__"===h||"constructor"===h||"prototype"===h)return n;if(s!=u){var l=c[h];(a=i?i(l,h,c):t)===t&&(a=Jo(l)?l:vs(e[s+1])?[]:{})}Je(c,h,a),c=c[h]}return n}var qr=Ue?function(t,n){return Ue.set(t,n),t}:nc,Gr=un?function(t,n){return un(t,"toString",{configurable:!0,enumerable:!1,value:Ju(n),writable:!0})}:nc;function Jr(t){return Ts(Ru(t))}function Zr(t,n,e){var r=-1,i=t.length;n<0&&(n=-n>i?0:i+n),(e=e>i?i:e)<0&&(e+=i),i=n>e?0:e-n>>>0,n>>>=0;for(var s=bt(i);++r<i;)s[r]=t[r+n];return s}function ti(t,n){var e;return hr(t,(function(t,r,i){return!(e=n(t,r,i))})),!!e}function ni(t,n,e){var r=0,i=null==t?r:t.length;if("number"==typeof n&&n==n&&i<=2147483647){for(;r<i;){var s=r+i>>>1,o=t[s];null!==o&&!ou(o)&&(e?o<=n:o<n)?r=s+1:i=s}return i}return ei(t,n,nc,e)}function ei(n,e,r,i){var s=0,o=null==n?0:n.length;if(0===o)return 0;for(var u=(e=r(e))!=e,c=null===e,h=ou(e),a=e===t;s<o;){var l=vn((s+o)/2),f=r(n[l]),d=f!==t,v=null===f,p=f==f,w=ou(f);if(u)var y=i||p;else y=a?p&&(i||d):c?p&&d&&(i||!v):h?p&&d&&!v&&(i||!w):!v&&!w&&(i?f<=e:f<e);y?s=l+1:o=l}return we(o,4294967294)}function ri(t,n){for(var e=-1,r=t.length,i=0,s=[];++e<r;){var o=t[e],u=n?n(o):o;if(!e||!Ro(u,c)){var c=u;s[i++]=0===o?0:o}}return s}function ii(t){return"number"==typeof t?t:ou(t)?c:+t}function si(t){if("string"==typeof t)return t;if(Fo(t))return jn(t,si)+"";if(ou(t))return De?De.call(t):"";var n=t+"";return"0"==n&&1/t==-1/0?"-0":n}function oi(t,n,e){var r=-1,i=Un,s=t.length,o=!0,u=[],c=u;if(e)o=!1,i=En;else if(s>=200){var h=n?null:Qi(t);if(h)return se(h);o=!1,i=Xn,c=new Qe}else c=n?[]:u;t:for(;++r<s;){var a=t[r],l=n?n(a):a;if(a=e||0!==a?a:0,o&&l==l){for(var f=c.length;f--;)if(c[f]===l)continue t;n&&c.push(l),u.push(a)}else i(c,l,e)||(c!==u&&c.push(l),u.push(a))}return u}function ui(t,n){return null==(t=xs(t,n=pi(n,t)))||delete t[zs(Hs(n))]}function ci(t,n,e,r){return Xr(t,n,e(mr(t,n)),r)}function hi(t,n,e,r){for(var i=t.length,s=r?i:-1;(r?s--:++s<i)&&n(t[s],s,t););return e?Zr(t,r?0:s,r?s+1:i):Zr(t,r?s+1:0,r?i:s)}function ai(t,n){var e=t;return e instanceof Le&&(e=e.value()),In(n,(function(t,n){return n.func.apply(n.thisArg,Tn([t],n.args))}),e)}function li(t,n,e){var r=t.length;if(r<2)return r?oi(t[0]):[];for(var i=-1,s=bt(r);++i<r;)for(var o=t[i],u=-1;++u<r;)u!=i&&(s[i]=cr(s[i]||o,t[u],n,e));return oi(vr(s,1),n,e)}function fi(n,e,r){for(var i=-1,s=n.length,o=e.length,u={};++i<s;)r(u,n[i],i<o?e[i]:t);return u}function di(t){return Qo(t)?t:[]}function vi(t){return"function"==typeof t?t:nc}function pi(t,n){return Fo(t)?t:ws(t,n)?[t]:_s(wu(t))}var wi=Yr;function yi(n,e,r){var i=n.length;return r=r===t?i:r,!e&&r>=i?n:Zr(n,e,r)}var gi=cn||function(t){return hn.clearTimeout(t)};function bi(t,n){if(n)return t.slice();var e=t.length,r=Ft?Ft(e):new t.constructor(e);return t.copy(r),r}function mi(t){var n=new t.constructor(t.byteLength);return new Lt(n).set(new Lt(t)),n}function Ai(t,n){var e=n?mi(t.buffer):t.buffer;return new t.constructor(e,t.byteOffset,t.length)}function ki(n,e){if(n!==e){var r=n!==t,i=null===n,s=n==n,o=ou(n),u=e!==t,c=null===e,h=e==e,a=ou(e);if(!c&&!a&&!o&&n>e||o&&u&&h&&!c&&!a||i&&u&&h||!r&&h||!s)return 1;if(!i&&!o&&!a&&n<e||a&&r&&s&&!i&&!o||c&&r&&s||!u&&s||!h)return-1}return 0}function xi(t,n,e,r){for(var i=-1,s=t.length,o=e.length,u=-1,c=n.length,h=pe(s-o,0),a=bt(c+h),l=!r;++u<c;)a[u]=n[u];for(;++i<o;)(l||i<s)&&(a[e[i]]=t[i]);for(;h--;)a[u++]=t[i++];return a}function Mi(t,n,e,r){for(var i=-1,s=t.length,o=-1,u=e.length,c=-1,h=n.length,a=pe(s-u,0),l=bt(a+h),f=!r;++i<a;)l[i]=t[i];for(var d=i;++c<h;)l[d+c]=n[c];for(;++o<u;)(f||i<s)&&(l[d+e[o]]=t[i++]);return l}function Si(t,n){var e=-1,r=t.length;for(n||(n=bt(r));++e<r;)n[e]=t[e];return n}function Ci(n,e,r,i){var s=!r;r||(r={});for(var o=-1,u=e.length;++o<u;){var c=e[o],h=i?i(r[c],n[c],c,r,n):t;h===t&&(h=n[c]),s?er(r,c,h):Je(r,c,h)}return r}function Ui(t,n){return function(e,r){var i=Fo(e)?kn:tr,s=n?n():{};return i(e,t,is(r,2),s)}}function Ei(n){return Yr((function(e,r){var i=-1,s=r.length,o=s>1?r[s-1]:t,u=s>2?r[2]:t;for(o=n.length>3&&"function"==typeof o?(s--,o):t,u&&ps(r[0],r[1],u)&&(o=s<3?t:o,s=1),e=Mt(e);++i<s;){var c=r[i];c&&n(e,c,i,o)}return e}))}function ji(t,n){return function(e,r){if(null==e)return e;if(!Ko(e))return t(e,r);for(var i=e.length,s=n?i:-1,o=Mt(e);(n?s--:++s<i)&&!1!==r(o[s],s,o););return e}}function Ti(t){return function(n,e,r){for(var i=-1,s=Mt(n),o=r(n),u=o.length;u--;){var c=o[t?u:++i];if(!1===e(s[c],c,s))break}return n}}function Ii(n){return function(e){var r=ne(e=wu(e))?ce(e):t,i=r?r[0]:e.charAt(0),s=r?yi(r,1).join(""):e.slice(1);return i[n]()+s}}function Oi(t){return function(n){return In(Xu(Lu(n).replace(Ht,"")),t,"")}}function _i(t){return function(){var n=arguments;switch(n.length){case 0:return new t;case 1:return new t(n[0]);case 2:return new t(n[0],n[1]);case 3:return new t(n[0],n[1],n[2]);case 4:return new t(n[0],n[1],n[2],n[3]);case 5:return new t(n[0],n[1],n[2],n[3],n[4]);case 6:return new t(n[0],n[1],n[2],n[3],n[4],n[5]);case 7:return new t(n[0],n[1],n[2],n[3],n[4],n[5],n[6])}var e=Re(t.prototype),r=t.apply(e,n);return Jo(r)?r:e}}function zi(n){return function(e,r,i){var s=Mt(e);if(!Ko(e)){var o=is(r,3);e=ju(e),r=function(t){return o(s[t],t,s)}}var u=n(e,r,i);return u>-1?s[o?e[u]:u]:t}}function $i(e){return Ji((function(r){var i=r.length,s=i,o=We.prototype.thru;for(e&&r.reverse();s--;){var u=r[s];if("function"!=typeof u)throw new Ut(n);if(o&&!c&&"wrapper"==es(u))var c=new We([],!0)}for(s=c?s:i;++s<i;){var h=es(u=r[s]),a="wrapper"==h?ns(u):t;c=a&&ys(a[0])&&424==a[1]&&!a[4].length&&1==a[9]?c[es(a[0])].apply(c,a[3]):1==u.length&&ys(u)?c[h]():c.thru(u)}return function(){var t=arguments,n=t[0];if(c&&1==t.length&&Fo(n))return c.plant(n).value();for(var e=0,s=i?r[e].apply(this,t):n;++e<i;)s=r[e].call(this,s);return s}}))}function Di(n,e,r,i,o,u,c,h,a,l){var f=e&s,d=1&e,v=2&e,p=24&e,w=512&e,y=v?t:_i(n);return function s(){for(var g=arguments.length,b=bt(g),m=g;m--;)b[m]=arguments[m];if(p)var A=rs(s),k=function(t,n){for(var e=t.length,r=0;e--;)t[e]===n&&++r;return r}(b,A);if(i&&(b=xi(b,i,o,p)),u&&(b=Mi(b,u,c,p)),g-=k,p&&g<l){var x=ie(b,A);return Ni(n,e,Di,s.placeholder,r,b,x,h,a,l-g)}var M=d?r:this,S=v?M[n]:n;return g=b.length,h?b=function(n,e){for(var r=n.length,i=we(e.length,r),s=Si(n);i--;){var o=e[i];n[i]=vs(o,r)?s[o]:t}return n}(b,h):w&&g>1&&b.reverse(),f&&a<g&&(b.length=a),this&&this!==hn&&this instanceof s&&(S=y||_i(S)),S.apply(M,b)}}function Pi(t,n){return function(e,r){return function(t,n,e,r){return yr(t,(function(t,i,s){n(r,e(t),i,s)})),r}(e,t,n(r),{})}}function Ri(n,e){return function(r,i){var s;if(r===t&&i===t)return e;if(r!==t&&(s=r),i!==t){if(s===t)return i;"string"==typeof r||"string"==typeof i?(r=si(r),i=si(i)):(r=ii(r),i=ii(i)),s=n(r,i)}return s}}function Bi(t){return Ji((function(n){return n=jn(n,Hn(is())),Yr((function(e){var r=this;return t(n,(function(t){return An(t,r,e)}))}))}))}function Wi(n,e){var r=(e=e===t?" ":si(e)).length;if(r<2)return r?Qr(e,n):e;var i=Qr(e,dn(n/ue(e)));return ne(e)?yi(ce(i),0,n).join(""):i.slice(0,n)}function Li(n){return function(e,r,i){return i&&"number"!=typeof i&&ps(e,r,i)&&(r=i=t),e=lu(e),r===t?(r=e,e=0):r=lu(r),function(t,n,e,r){for(var i=-1,s=pe(dn((n-t)/(e||1)),0),o=bt(s);s--;)o[r?s:++i]=t,t+=e;return o}(e,r,i=i===t?e<r?1:-1:lu(i),n)}}function Fi(t){return function(n,e){return"string"==typeof n&&"string"==typeof e||(n=vu(n),e=vu(e)),t(n,e)}}function Ni(n,e,r,s,o,u,c,h,a,l){var f=8&e;e|=f?i:64,4&(e&=~(f?64:i))||(e&=-4);var d=[n,e,o,f?u:t,f?c:t,f?t:u,f?t:c,h,a,l],v=r.apply(t,d);return ys(n)&&Ss(v,d),v.placeholder=s,Es(v,n,e)}function Ki(t){var n=xt[t];return function(t,e){if(t=vu(t),(e=null==e?0:we(fu(e),292))&&fe(t)){var r=(wu(t)+"e").split("e");return+((r=(wu(n(r[0]+"e"+(+r[1]+e)))+"e").split("e"))[0]+"e"+(+r[1]-e))}return n(t)}}var Qi=Me&&1/se(new Me([,-0]))[1]==o?function(t){return new Me(t)}:oc;function Yi(t){return function(n){var e=as(n);return e==g?ee(n):e==x?oe(n):function(t,n){return jn(n,(function(n){return[n,t[n]]}))}(n,t(n))}}function Hi(e,o,u,c,h,a,l,f){var d=2&o;if(!d&&"function"!=typeof e)throw new Ut(n);var v=c?c.length:0;if(v||(o&=-97,c=h=t),l=l===t?l:pe(fu(l),0),f=f===t?f:fu(f),v-=h?h.length:0,64&o){var p=c,w=h;c=h=t}var y=d?t:ns(e),g=[e,o,u,c,h,p,w,a,l,f];if(y&&function(t,n){var e=t[1],i=n[1],o=e|i;if(!(o<131||(i==s&&8==e||i==s&&256==e&&t[7].length<=n[8]||384==i&&n[7].length<=n[8]&&8==e)))return t;1&i&&(t[2]=n[2],o|=1&e?0:4);var u=n[3];if(u){var c=t[3];t[3]=c?xi(c,u,n[4]):u,t[4]=c?ie(t[3],r):n[4]}(u=n[5])&&(t[5]=(c=t[5])?Mi(c,u,n[6]):u,t[6]=c?ie(t[5],r):n[6]),(u=n[7])&&(t[7]=u),i&s&&(t[8]=null==t[8]?n[8]:we(t[8],n[8])),null==t[9]&&(t[9]=n[9]),t[0]=n[0],t[1]=o}(g,y),e=g[0],o=g[1],u=g[2],c=g[3],h=g[4],!(f=g[9]=g[9]===t?d?0:e.length:pe(g[9]-v,0))&&24&o&&(o&=-25),o&&1!=o)b=8==o||16==o?function(n,e,r){var i=_i(n);return function s(){for(var o=arguments.length,u=bt(o),c=o,h=rs(s);c--;)u[c]=arguments[c];var a=o<3&&u[0]!==h&&u[o-1]!==h?[]:ie(u,h);return(o-=a.length)<r?Ni(n,e,Di,s.placeholder,t,u,a,t,t,r-o):An(this&&this!==hn&&this instanceof s?i:n,this,u)}}(e,o,f):o!=i&&33!=o||h.length?Di.apply(t,g):function(t,n,e,r){var i=1&n,s=_i(t);return function n(){for(var o=-1,u=arguments.length,c=-1,h=r.length,a=bt(h+u),l=this&&this!==hn&&this instanceof n?s:t;++c<h;)a[c]=r[c];for(;u--;)a[c++]=arguments[++o];return An(l,i?e:this,a)}}(e,o,u,c);else var b=function(t,n,e){var r=1&n,i=_i(t);return function n(){return(this&&this!==hn&&this instanceof n?i:t).apply(r?e:this,arguments)}}(e,o,u);return Es((y?qr:Ss)(b,g),e,o)}function Vi(n,e,r,i){return n===t||Ro(n,jt[r])&&!Ot.call(i,r)?e:n}function Xi(n,e,r,i,s,o){return Jo(n)&&Jo(e)&&(o.set(e,n),Rr(n,e,t,Xi,o),o.delete(e)),n}function qi(n){return eu(n)?t:n}function Gi(n,e,r,i,s,o){var u=1&r,c=n.length,h=e.length;if(c!=h&&!(u&&h>c))return!1;var a=o.get(n),l=o.get(e);if(a&&l)return a==e&&l==n;var f=-1,d=!0,v=2&r?new Qe:t;for(o.set(n,e),o.set(e,n);++f<c;){var p=n[f],w=e[f];if(i)var y=u?i(w,p,f,e,n,o):i(p,w,f,n,e,o);if(y!==t){if(y)continue;d=!1;break}if(v){if(!_n(e,(function(t,n){if(!Xn(v,n)&&(p===t||s(p,t,r,i,o)))return v.push(n)}))){d=!1;break}}else if(p!==w&&!s(p,w,r,i,o)){d=!1;break}}return o.delete(n),o.delete(e),d}function Ji(n){return Us(ks(n,t,Fs),n+"")}function Zi(t){return Ar(t,ju,cs)}function ts(t){return Ar(t,Tu,hs)}var ns=Ue?function(t){return Ue.get(t)}:oc;function es(t){for(var n=t.name+"",e=Ee[n],r=Ot.call(Ee,n)?e.length:0;r--;){var i=e[r],s=i.func;if(null==s||s==t)return i.name}return n}function rs(t){return(Ot.call(Pe,"placeholder")?Pe:t).placeholder}function is(){var t=Pe.iteratee||ec;return t=t===ec?Or:t,arguments.length?t(arguments[0],arguments[1]):t}function ss(t,n){var e=t.__data__;return function(t){var n=typeof t;return"string"==n||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==t:null===t}(n)?e["string"==typeof n?"string":"hash"]:e.map}function os(t){for(var n=ju(t),e=n.length;e--;){var r=n[e],i=t[r];n[e]=[r,i,ms(i)]}return n}function us(n,e){var r=function(n,e){return null==n?t:n[e]}(n,e);return Ir(r)?r:t}var cs=zn?function(t){return null==t?[]:(t=Mt(t),Cn(zn(t),(function(n){return Qt.call(t,n)})))}:dc,hs=zn?function(t){for(var n=[];t;)Tn(n,cs(t)),t=Nt(t);return n}:dc,as=kr;function ls(t,n,e){for(var r=-1,i=(n=pi(n,t)).length,s=!1;++r<i;){var o=zs(n[r]);if(!(s=null!=t&&e(t,o)))break;t=t[o]}return s||++r!=i?s:!!(i=null==t?0:t.length)&&Go(i)&&vs(o,i)&&(Fo(t)||Lo(t))}function fs(t){return"function"!=typeof t.constructor||bs(t)?{}:Re(Nt(t))}function ds(t){return Fo(t)||Lo(t)||!!(Xt&&t&&t[Xt])}function vs(t,n){var e=typeof t;return!!(n=null==n?u:n)&&("number"==e||"symbol"!=e&&vt.test(t))&&t>-1&&t%1==0&&t<n}function ps(t,n,e){if(!Jo(e))return!1;var r=typeof n;return!!("number"==r?Ko(e)&&vs(n,e.length):"string"==r&&n in e)&&Ro(e[n],t)}function ws(t,n){if(Fo(t))return!1;var e=typeof t;return!("number"!=e&&"symbol"!=e&&"boolean"!=e&&null!=t&&!ou(t))||q.test(t)||!X.test(t)||null!=n&&t in Mt(n)}function ys(t){var n=es(t),e=Pe[n];if("function"!=typeof e||!(n in Le.prototype))return!1;if(t===e)return!0;var r=ns(e);return!!r&&t===r[0]}(Ae&&as(new Ae(new ArrayBuffer(1)))!=E||ke&&as(new ke)!=g||xe&&as(xe.resolve())!=A||Me&&as(new Me)!=x||Se&&as(new Se)!=C)&&(as=function(n){var e=kr(n),r=e==m?n.constructor:t,i=r?$s(r):"";if(i)switch(i){case je:return E;case Te:return g;case Ie:return A;case Oe:return x;case _e:return C}return e});var gs=Tt?Xo:vc;function bs(t){var n=t&&t.constructor;return t===("function"==typeof n&&n.prototype||jt)}function ms(t){return t==t&&!Jo(t)}function As(n,e){return function(r){return null!=r&&r[n]===e&&(e!==t||n in Mt(r))}}function ks(n,e,r){return e=pe(e===t?n.length-1:e,0),function(){for(var t=arguments,i=-1,s=pe(t.length-e,0),o=bt(s);++i<s;)o[i]=t[e+i];i=-1;for(var u=bt(e+1);++i<e;)u[i]=t[i];return u[e]=r(o),An(n,this,u)}}function xs(t,n){return n.length<2?t:mr(t,Zr(n,0,-1))}function Ms(t,n){if(("constructor"!==n||"function"!=typeof t[n])&&"__proto__"!=n)return t[n]}var Ss=js(qr),Cs=ln||function(t,n){return hn.setTimeout(t,n)},Us=js(Gr);function Es(t,n,e){var r=n+"";return Us(t,function(t,n){var e=n.length;if(!e)return t;var r=e-1;return n[r]=(e>1?"& ":"")+n[r],n=n.join(e>2?", ":" "),t.replace(et,"{\n/* [wrapped with "+n+"] */\n")}(r,function(t,n){return xn(a,(function(e){var r="_."+e[0];n&e[1]&&!Un(t,r)&&t.push(r)})),t.sort()}(function(t){var n=t.match(rt);return n?n[1].split(it):[]}(r),e)))}function js(n){var e=0,r=0;return function(){var i=ye(),s=16-(i-r);if(r=i,s>0){if(++e>=800)return arguments[0]}else e=0;return n.apply(t,arguments)}}function Ts(n,e){var r=-1,i=n.length,s=i-1;for(e=e===t?i:e;++r<e;){var o=Kr(r,s),u=n[o];n[o]=n[r],n[r]=u}return n.length=e,n}var Is,Os,_s=(Is=Oo((function(t){var n=[];return 46===t.charCodeAt(0)&&n.push(""),t.replace(G,(function(t,e,r,i){n.push(r?i.replace(ut,"$1"):e||t)})),n}),(function(t){return 500===Os.size&&Os.clear(),t})),Os=Is.cache,Is);function zs(t){if("string"==typeof t||ou(t))return t;var n=t+"";return"0"==n&&1/t==-1/0?"-0":n}function $s(t){if(null!=t){try{return It.call(t)}catch(t){}try{return t+""}catch(t){}}return""}function Ds(t){if(t instanceof Le)return t.clone();var n=new We(t.__wrapped__,t.__chain__);return n.__actions__=Si(t.__actions__),n.__index__=t.__index__,n.__values__=t.__values__,n}var Ps=Yr((function(t,n){return Qo(t)?cr(t,vr(n,1,Qo,!0)):[]})),Rs=Yr((function(n,e){var r=Hs(e);return Qo(r)&&(r=t),Qo(n)?cr(n,vr(e,1,Qo,!0),is(r,2)):[]})),Bs=Yr((function(n,e){var r=Hs(e);return Qo(r)&&(r=t),Qo(n)?cr(n,vr(e,1,Qo,!0),t,r):[]}));function Ws(t,n,e){var r=null==t?0:t.length;if(!r)return-1;var i=null==e?0:fu(e);return i<0&&(i=pe(r+i,0)),Dn(t,is(n,3),i)}function Ls(n,e,r){var i=null==n?0:n.length;if(!i)return-1;var s=i-1;return r!==t&&(s=fu(r),s=r<0?pe(i+s,0):we(s,i-1)),Dn(n,is(e,3),s,!0)}function Fs(t){return null!=t&&t.length?vr(t,1):[]}function Ns(n){return n&&n.length?n[0]:t}var Ks=Yr((function(t){var n=jn(t,di);return n.length&&n[0]===t[0]?Cr(n):[]})),Qs=Yr((function(n){var e=Hs(n),r=jn(n,di);return e===Hs(r)?e=t:r.pop(),r.length&&r[0]===n[0]?Cr(r,is(e,2)):[]})),Ys=Yr((function(n){var e=Hs(n),r=jn(n,di);return(e="function"==typeof e?e:t)&&r.pop(),r.length&&r[0]===n[0]?Cr(r,t,e):[]}));function Hs(n){var e=null==n?0:n.length;return e?n[e-1]:t}var Vs=Yr(Xs);function Xs(t,n){return t&&t.length&&n&&n.length?Fr(t,n):t}var qs=Ji((function(t,n){var e=null==t?0:t.length,r=rr(t,n);return Nr(t,jn(n,(function(t){return vs(t,e)?+t:t})).sort(ki)),r}));function Gs(t){return null==t?t:me.call(t)}var Js=Yr((function(t){return oi(vr(t,1,Qo,!0))})),Zs=Yr((function(n){var e=Hs(n);return Qo(e)&&(e=t),oi(vr(n,1,Qo,!0),is(e,2))})),to=Yr((function(n){var e=Hs(n);return e="function"==typeof e?e:t,oi(vr(n,1,Qo,!0),t,e)}));function no(t){if(!t||!t.length)return[];var n=0;return t=Cn(t,(function(t){if(Qo(t))return n=pe(t.length,n),!0})),Qn(n,(function(n){return jn(t,Ln(n))}))}function eo(n,e){if(!n||!n.length)return[];var r=no(n);return null==e?r:jn(r,(function(n){return An(e,t,n)}))}var ro=Yr((function(t,n){return Qo(t)?cr(t,n):[]})),io=Yr((function(t){return li(Cn(t,Qo))})),so=Yr((function(n){var e=Hs(n);return Qo(e)&&(e=t),li(Cn(n,Qo),is(e,2))})),oo=Yr((function(n){var e=Hs(n);return e="function"==typeof e?e:t,li(Cn(n,Qo),t,e)})),uo=Yr(no),co=Yr((function(n){var e=n.length,r=e>1?n[e-1]:t;return r="function"==typeof r?(n.pop(),r):t,eo(n,r)}));function ho(t){var n=Pe(t);return n.__chain__=!0,n}function ao(t,n){return n(t)}var lo=Ji((function(n){var e=n.length,r=e?n[0]:0,i=this.__wrapped__,s=function(t){return rr(t,n)};return!(e>1||this.__actions__.length)&&i instanceof Le&&vs(r)?((i=i.slice(r,+r+(e?1:0))).__actions__.push({func:ao,args:[s],thisArg:t}),new We(i,this.__chain__).thru((function(n){return e&&!n.length&&n.push(t),n}))):this.thru(s)})),fo=Ui((function(t,n,e){Ot.call(t,e)?++t[e]:er(t,e,1)})),vo=zi(Ws),po=zi(Ls);function wo(t,n){return(Fo(t)?xn:hr)(t,is(n,3))}function yo(t,n){return(Fo(t)?Mn:ar)(t,is(n,3))}var go=Ui((function(t,n,e){Ot.call(t,e)?t[e].push(n):er(t,e,[n])})),bo=Yr((function(t,n,e){var r=-1,i="function"==typeof n,s=Ko(t)?bt(t.length):[];return hr(t,(function(t){s[++r]=i?An(n,t,e):Ur(t,n,e)})),s})),mo=Ui((function(t,n,e){er(t,e,n)}));function Ao(t,n){return(Fo(t)?jn:$r)(t,is(n,3))}var ko=Ui((function(t,n,e){t[e?0:1].push(n)}),(function(){return[[],[]]})),xo=Yr((function(t,n){if(null==t)return[];var e=n.length;return e>1&&ps(t,n[0],n[1])?n=[]:e>2&&ps(n[0],n[1],n[2])&&(n=[n[0]]),Wr(t,vr(n,1),[])})),Mo=an||function(){return hn.Date.now()};function So(n,e,r){return e=r?t:e,Hi(n,s,t,t,t,t,e=n&&null==e?n.length:e)}function Co(e,r){var i;if("function"!=typeof r)throw new Ut(n);return e=fu(e),function(){return--e>0&&(i=r.apply(this,arguments)),e<=1&&(r=t),i}}var Uo=Yr((function(t,n,e){var r=1;if(e.length){var s=ie(e,rs(Uo));r|=i}return Hi(t,r,n,e,s)})),Eo=Yr((function(t,n,e){var r=3;if(e.length){var s=ie(e,rs(Eo));r|=i}return Hi(n,r,t,e,s)}));function jo(e,r,i){var s,o,u,c,h,a,l=0,f=!1,d=!1,v=!0;if("function"!=typeof e)throw new Ut(n);function p(n){var r=s,i=o;return s=o=t,l=n,c=e.apply(i,r)}function w(n){var e=n-a;return a===t||e>=r||e<0||d&&n-l>=u}function y(){var t=Mo();if(w(t))return g(t);h=Cs(y,function(t){var n=r-(t-a);return d?we(n,u-(t-l)):n}(t))}function g(n){return h=t,v&&s?p(n):(s=o=t,c)}function b(){var n=Mo(),e=w(n);if(s=arguments,o=this,a=n,e){if(h===t)return function(t){return l=t,h=Cs(y,r),f?p(t):c}(a);if(d)return gi(h),h=Cs(y,r),p(a)}return h===t&&(h=Cs(y,r)),c}return r=vu(r)||0,Jo(i)&&(f=!!i.leading,u=(d="maxWait"in i)?pe(vu(i.maxWait)||0,r):u,v="trailing"in i?!!i.trailing:v),b.cancel=function(){h!==t&&gi(h),l=0,s=a=o=h=t},b.flush=function(){return h===t?c:g(Mo())},b}var To=Yr((function(t,n){return ur(t,1,n)})),Io=Yr((function(t,n,e){return ur(t,vu(n)||0,e)}));function Oo(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new Ut(n);var r=function(){var n=arguments,i=e?e.apply(this,n):n[0],s=r.cache;if(s.has(i))return s.get(i);var o=t.apply(this,n);return r.cache=s.set(i,o)||s,o};return r.cache=new(Oo.Cache||Ke),r}function _o(t){if("function"!=typeof t)throw new Ut(n);return function(){var n=arguments;switch(n.length){case 0:return!t.call(this);case 1:return!t.call(this,n[0]);case 2:return!t.call(this,n[0],n[1]);case 3:return!t.call(this,n[0],n[1],n[2])}return!t.apply(this,n)}}Oo.Cache=Ke;var zo=wi((function(t,n){var e=(n=1==n.length&&Fo(n[0])?jn(n[0],Hn(is())):jn(vr(n,1),Hn(is()))).length;return Yr((function(r){for(var i=-1,s=we(r.length,e);++i<s;)r[i]=n[i].call(this,r[i]);return An(t,this,r)}))})),$o=Yr((function(n,e){var r=ie(e,rs($o));return Hi(n,i,t,e,r)})),Do=Yr((function(n,e){var r=ie(e,rs(Do));return Hi(n,64,t,e,r)})),Po=Ji((function(n,e){return Hi(n,256,t,t,t,e)}));function Ro(t,n){return t===n||t!=t&&n!=n}var Bo=Fi(xr),Wo=Fi((function(t,n){return t>=n})),Lo=Er(function(){return arguments}())?Er:function(t){return Zo(t)&&Ot.call(t,"callee")&&!Qt.call(t,"callee")},Fo=bt.isArray,No=pn?Hn(pn):function(t){return Zo(t)&&kr(t)==U};function Ko(t){return null!=t&&Go(t.length)&&!Xo(t)}function Qo(t){return Zo(t)&&Ko(t)}var Yo=Fn||vc,Ho=wn?Hn(wn):function(t){return Zo(t)&&kr(t)==v};function Vo(t){if(!Zo(t))return!1;var n=kr(t);return n==p||"[object DOMException]"==n||"string"==typeof t.message&&"string"==typeof t.name&&!eu(t)}function Xo(t){if(!Jo(t))return!1;var n=kr(t);return n==w||n==y||"[object AsyncFunction]"==n||"[object Proxy]"==n}function qo(t){return"number"==typeof t&&t==fu(t)}function Go(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=u}function Jo(t){var n=typeof t;return null!=t&&("object"==n||"function"==n)}function Zo(t){return null!=t&&"object"==typeof t}var tu=yn?Hn(yn):function(t){return Zo(t)&&as(t)==g};function nu(t){return"number"==typeof t||Zo(t)&&kr(t)==b}function eu(t){if(!Zo(t)||kr(t)!=m)return!1;var n=Nt(t);if(null===n)return!0;var e=Ot.call(n,"constructor")&&n.constructor;return"function"==typeof e&&e instanceof e&&It.call(e)==Dt}var ru=gn?Hn(gn):function(t){return Zo(t)&&kr(t)==k},iu=bn?Hn(bn):function(t){return Zo(t)&&as(t)==x};function su(t){return"string"==typeof t||!Fo(t)&&Zo(t)&&kr(t)==M}function ou(t){return"symbol"==typeof t||Zo(t)&&kr(t)==S}var uu=mn?Hn(mn):function(t){return Zo(t)&&Go(t.length)&&!!nn[kr(t)]},cu=Fi(zr),hu=Fi((function(t,n){return t<=n}));function au(t){if(!t)return[];if(Ko(t))return su(t)?ce(t):Si(t);if(Gt&&t[Gt])return function(t){for(var n,e=[];!(n=t.next()).done;)e.push(n.value);return e}(t[Gt]());var n=as(t);return(n==g?ee:n==x?se:Ru)(t)}function lu(t){return t?(t=vu(t))===o||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0}function fu(t){var n=lu(t),e=n%1;return n==n?e?n-e:n:0}function du(t){return t?ir(fu(t),0,h):0}function vu(t){if("number"==typeof t)return t;if(ou(t))return c;if(Jo(t)){var n="function"==typeof t.valueOf?t.valueOf():t;t=Jo(n)?n+"":n}if("string"!=typeof t)return 0===t?t:+t;t=Yn(t);var e=lt.test(t);return e||dt.test(t)?on(t.slice(2),e?2:8):at.test(t)?c:+t}function pu(t){return Ci(t,Tu(t))}function wu(t){return null==t?"":si(t)}var yu=Ei((function(t,n){if(bs(n)||Ko(n))Ci(n,ju(n),t);else for(var e in n)Ot.call(n,e)&&Je(t,e,n[e])})),gu=Ei((function(t,n){Ci(n,Tu(n),t)})),bu=Ei((function(t,n,e,r){Ci(n,Tu(n),t,r)})),mu=Ei((function(t,n,e,r){Ci(n,ju(n),t,r)})),Au=Ji(rr),ku=Yr((function(n,e){n=Mt(n);var r=-1,i=e.length,s=i>2?e[2]:t;for(s&&ps(e[0],e[1],s)&&(i=1);++r<i;)for(var o=e[r],u=Tu(o),c=-1,h=u.length;++c<h;){var a=u[c],l=n[a];(l===t||Ro(l,jt[a])&&!Ot.call(n,a))&&(n[a]=o[a])}return n})),xu=Yr((function(n){return n.push(t,Xi),An(Ou,t,n)}));function Mu(n,e,r){var i=null==n?t:mr(n,e);return i===t?r:i}function Su(t,n){return null!=t&&ls(t,n,Sr)}var Cu=Pi((function(t,n,e){null!=n&&"function"!=typeof n.toString&&(n=$t.call(n)),t[n]=e}),Ju(nc)),Uu=Pi((function(t,n,e){null!=n&&"function"!=typeof n.toString&&(n=$t.call(n)),Ot.call(t,n)?t[n].push(e):t[n]=[e]}),is),Eu=Yr(Ur);function ju(t){return Ko(t)?He(t):_r(t)}function Tu(t){return Ko(t)?He(t,!0):function(t){if(!Jo(t))return function(t){var n=[];if(null!=t)for(var e in Mt(t))n.push(e);return n}(t);var n=bs(t),e=[];for(var r in t)("constructor"!=r||!n&&Ot.call(t,r))&&e.push(r);return e}(t)}var Iu=Ei((function(t,n,e){Rr(t,n,e)})),Ou=Ei((function(t,n,e,r){Rr(t,n,e,r)})),_u=Ji((function(t,n){var e={};if(null==t)return e;var r=!1;n=jn(n,(function(n){return n=pi(n,t),r||(r=n.length>1),n})),Ci(t,ts(t),e),r&&(e=sr(e,7,qi));for(var i=n.length;i--;)ui(e,n[i]);return e})),zu=Ji((function(t,n){return null==t?{}:function(t,n){return Lr(t,n,(function(n,e){return Su(t,e)}))}(t,n)}));function $u(t,n){if(null==t)return{};var e=jn(ts(t),(function(t){return[t]}));return n=is(n),Lr(t,e,(function(t,e){return n(t,e[0])}))}var Du=Yi(ju),Pu=Yi(Tu);function Ru(t){return null==t?[]:Vn(t,ju(t))}var Bu=Oi((function(t,n,e){return n=n.toLowerCase(),t+(e?Wu(n):n)}));function Wu(t){return Vu(wu(t).toLowerCase())}function Lu(t){return(t=wu(t))&&t.replace(pt,Jn).replace(Vt,"")}var Fu=Oi((function(t,n,e){return t+(e?"-":"")+n.toLowerCase()})),Nu=Oi((function(t,n,e){return t+(e?" ":"")+n.toLowerCase()})),Ku=Ii("toLowerCase"),Qu=Oi((function(t,n,e){return t+(e?"_":"")+n.toLowerCase()})),Yu=Oi((function(t,n,e){return t+(e?" ":"")+Vu(n)})),Hu=Oi((function(t,n,e){return t+(e?" ":"")+n.toUpperCase()})),Vu=Ii("toUpperCase");function Xu(n,e,r){return n=wu(n),(e=r?t:e)===t?function(t){return Jt.test(t)}(n)?function(t){return t.match(qt)||[]}(n):function(t){return t.match(st)||[]}(n):n.match(e)||[]}var qu=Yr((function(n,e){try{return An(n,t,e)}catch(t){return Vo(t)?t:new At(t)}})),Gu=Ji((function(t,n){return xn(n,(function(n){n=zs(n),er(t,n,Uo(t[n],t))})),t}));function Ju(t){return function(){return t}}var Zu=$i(),tc=$i(!0);function nc(t){return t}function ec(t){return Or("function"==typeof t?t:sr(t,1))}var rc=Yr((function(t,n){return function(e){return Ur(e,t,n)}})),ic=Yr((function(t,n){return function(e){return Ur(t,e,n)}}));function sc(t,n,e){var r=ju(n),i=br(n,r);null!=e||Jo(n)&&(i.length||!r.length)||(e=n,n=t,t=this,i=br(n,ju(n)));var s=!(Jo(e)&&"chain"in e&&!e.chain),o=Xo(t);return xn(i,(function(e){var r=n[e];t[e]=r,o&&(t.prototype[e]=function(){var n=this.__chain__;if(s||n){var e=t(this.__wrapped__);return(e.__actions__=Si(this.__actions__)).push({func:r,args:arguments,thisArg:t}),e.__chain__=n,e}return r.apply(t,Tn([this.value()],arguments))})})),t}function oc(){}var uc=Bi(jn),cc=Bi(Sn),hc=Bi(_n);function ac(t){return ws(t)?Ln(zs(t)):function(t){return function(n){return mr(n,t)}}(t)}var lc=Li(),fc=Li(!0);function dc(){return[]}function vc(){return!1}var pc,wc=Ri((function(t,n){return t+n}),0),yc=Ki("ceil"),gc=Ri((function(t,n){return t/n}),1),bc=Ki("floor"),mc=Ri((function(t,n){return t*n}),1),Ac=Ki("round"),kc=Ri((function(t,n){return t-n}),0);return Pe.after=function(t,e){if("function"!=typeof e)throw new Ut(n);return t=fu(t),function(){if(--t<1)return e.apply(this,arguments)}},Pe.ary=So,Pe.assign=yu,Pe.assignIn=gu,Pe.assignInWith=bu,Pe.assignWith=mu,Pe.at=Au,Pe.before=Co,Pe.bind=Uo,Pe.bindAll=Gu,Pe.bindKey=Eo,Pe.castArray=function(){if(!arguments.length)return[];var t=arguments[0];return Fo(t)?t:[t]},Pe.chain=ho,Pe.chunk=function(n,e,r){e=(r?ps(n,e,r):e===t)?1:pe(fu(e),0);var i=null==n?0:n.length;if(!i||e<1)return[];for(var s=0,o=0,u=bt(dn(i/e));s<i;)u[o++]=Zr(n,s,s+=e);return u},Pe.compact=function(t){for(var n=-1,e=null==t?0:t.length,r=0,i=[];++n<e;){var s=t[n];s&&(i[r++]=s)}return i},Pe.concat=function(){var t=arguments.length;if(!t)return[];for(var n=bt(t-1),e=arguments[0],r=t;r--;)n[r-1]=arguments[r];return Tn(Fo(e)?Si(e):[e],vr(n,1))},Pe.cond=function(t){var e=null==t?0:t.length,r=is();return t=e?jn(t,(function(t){if("function"!=typeof t[1])throw new Ut(n);return[r(t[0]),t[1]]})):[],Yr((function(n){for(var r=-1;++r<e;){var i=t[r];if(An(i[0],this,n))return An(i[1],this,n)}}))},Pe.conforms=function(t){return function(t){var n=ju(t);return function(e){return or(e,t,n)}}(sr(t,1))},Pe.constant=Ju,Pe.countBy=fo,Pe.create=function(t,n){var e=Re(t);return null==n?e:nr(e,n)},Pe.curry=function n(e,r,i){var s=Hi(e,8,t,t,t,t,t,r=i?t:r);return s.placeholder=n.placeholder,s},Pe.curryRight=function n(e,r,i){var s=Hi(e,16,t,t,t,t,t,r=i?t:r);return s.placeholder=n.placeholder,s},Pe.debounce=jo,Pe.defaults=ku,Pe.defaultsDeep=xu,Pe.defer=To,Pe.delay=Io,Pe.difference=Ps,Pe.differenceBy=Rs,Pe.differenceWith=Bs,Pe.drop=function(n,e,r){var i=null==n?0:n.length;return i?Zr(n,(e=r||e===t?1:fu(e))<0?0:e,i):[]},Pe.dropRight=function(n,e,r){var i=null==n?0:n.length;return i?Zr(n,0,(e=i-(e=r||e===t?1:fu(e)))<0?0:e):[]},Pe.dropRightWhile=function(t,n){return t&&t.length?hi(t,is(n,3),!0,!0):[]},Pe.dropWhile=function(t,n){return t&&t.length?hi(t,is(n,3),!0):[]},Pe.fill=function(n,e,r,i){var s=null==n?0:n.length;return s?(r&&"number"!=typeof r&&ps(n,e,r)&&(r=0,i=s),function(n,e,r,i){var s=n.length;for((r=fu(r))<0&&(r=-r>s?0:s+r),(i=i===t||i>s?s:fu(i))<0&&(i+=s),i=r>i?0:du(i);r<i;)n[r++]=e;return n}(n,e,r,i)):[]},Pe.filter=function(t,n){return(Fo(t)?Cn:dr)(t,is(n,3))},Pe.flatMap=function(t,n){return vr(Ao(t,n),1)},Pe.flatMapDeep=function(t,n){return vr(Ao(t,n),o)},Pe.flatMapDepth=function(n,e,r){return r=r===t?1:fu(r),vr(Ao(n,e),r)},Pe.flatten=Fs,Pe.flattenDeep=function(t){return null!=t&&t.length?vr(t,o):[]},Pe.flattenDepth=function(n,e){return null!=n&&n.length?vr(n,e=e===t?1:fu(e)):[]},Pe.flip=function(t){return Hi(t,512)},Pe.flow=Zu,Pe.flowRight=tc,Pe.fromPairs=function(t){for(var n=-1,e=null==t?0:t.length,r={};++n<e;){var i=t[n];r[i[0]]=i[1]}return r},Pe.functions=function(t){return null==t?[]:br(t,ju(t))},Pe.functionsIn=function(t){return null==t?[]:br(t,Tu(t))},Pe.groupBy=go,Pe.initial=function(t){return null!=t&&t.length?Zr(t,0,-1):[]},Pe.intersection=Ks,Pe.intersectionBy=Qs,Pe.intersectionWith=Ys,Pe.invert=Cu,Pe.invertBy=Uu,Pe.invokeMap=bo,Pe.iteratee=ec,Pe.keyBy=mo,Pe.keys=ju,Pe.keysIn=Tu,Pe.map=Ao,Pe.mapKeys=function(t,n){var e={};return n=is(n,3),yr(t,(function(t,r,i){er(e,n(t,r,i),t)})),e},Pe.mapValues=function(t,n){var e={};return n=is(n,3),yr(t,(function(t,r,i){er(e,r,n(t,r,i))})),e},Pe.matches=function(t){return Dr(sr(t,1))},Pe.matchesProperty=function(t,n){return Pr(t,sr(n,1))},Pe.memoize=Oo,Pe.merge=Iu,Pe.mergeWith=Ou,Pe.method=rc,Pe.methodOf=ic,Pe.mixin=sc,Pe.negate=_o,Pe.nthArg=function(t){return t=fu(t),Yr((function(n){return Br(n,t)}))},Pe.omit=_u,Pe.omitBy=function(t,n){return $u(t,_o(is(n)))},Pe.once=function(t){return Co(2,t)},Pe.orderBy=function(n,e,r,i){return null==n?[]:(Fo(e)||(e=null==e?[]:[e]),Fo(r=i?t:r)||(r=null==r?[]:[r]),Wr(n,e,r))},Pe.over=uc,Pe.overArgs=zo,Pe.overEvery=cc,Pe.overSome=hc,Pe.partial=$o,Pe.partialRight=Do,Pe.partition=ko,Pe.pick=zu,Pe.pickBy=$u,Pe.property=ac,Pe.propertyOf=function(n){return function(e){return null==n?t:mr(n,e)}},Pe.pull=Vs,Pe.pullAll=Xs,Pe.pullAllBy=function(t,n,e){return t&&t.length&&n&&n.length?Fr(t,n,is(e,2)):t},Pe.pullAllWith=function(n,e,r){return n&&n.length&&e&&e.length?Fr(n,e,t,r):n},Pe.pullAt=qs,Pe.range=lc,Pe.rangeRight=fc,Pe.rearg=Po,Pe.reject=function(t,n){return(Fo(t)?Cn:dr)(t,_o(is(n,3)))},Pe.remove=function(t,n){var e=[];if(!t||!t.length)return e;var r=-1,i=[],s=t.length;for(n=is(n,3);++r<s;){var o=t[r];n(o,r,t)&&(e.push(o),i.push(r))}return Nr(t,i),e},Pe.rest=function(e,r){if("function"!=typeof e)throw new Ut(n);return Yr(e,r=r===t?r:fu(r))},Pe.reverse=Gs,Pe.sampleSize=function(n,e,r){return e=(r?ps(n,e,r):e===t)?1:fu(e),(Fo(n)?Xe:Vr)(n,e)},Pe.set=function(t,n,e){return null==t?t:Xr(t,n,e)},Pe.setWith=function(n,e,r,i){return i="function"==typeof i?i:t,null==n?n:Xr(n,e,r,i)},Pe.shuffle=function(t){return(Fo(t)?qe:Jr)(t)},Pe.slice=function(n,e,r){var i=null==n?0:n.length;return i?(r&&"number"!=typeof r&&ps(n,e,r)?(e=0,r=i):(e=null==e?0:fu(e),r=r===t?i:fu(r)),Zr(n,e,r)):[]},Pe.sortBy=xo,Pe.sortedUniq=function(t){return t&&t.length?ri(t):[]},Pe.sortedUniqBy=function(t,n){return t&&t.length?ri(t,is(n,2)):[]},Pe.split=function(n,e,r){return r&&"number"!=typeof r&&ps(n,e,r)&&(e=r=t),(r=r===t?h:r>>>0)?(n=wu(n))&&("string"==typeof e||null!=e&&!ru(e))&&!(e=si(e))&&ne(n)?yi(ce(n),0,r):n.split(e,r):[]},Pe.spread=function(t,e){if("function"!=typeof t)throw new Ut(n);return e=null==e?0:pe(fu(e),0),Yr((function(n){var r=n[e],i=yi(n,0,e);return r&&Tn(i,r),An(t,this,i)}))},Pe.tail=function(t){var n=null==t?0:t.length;return n?Zr(t,1,n):[]},Pe.take=function(n,e,r){return n&&n.length?Zr(n,0,(e=r||e===t?1:fu(e))<0?0:e):[]},Pe.takeRight=function(n,e,r){var i=null==n?0:n.length;return i?Zr(n,(e=i-(e=r||e===t?1:fu(e)))<0?0:e,i):[]},Pe.takeRightWhile=function(t,n){return t&&t.length?hi(t,is(n,3),!1,!0):[]},Pe.takeWhile=function(t,n){return t&&t.length?hi(t,is(n,3)):[]},Pe.tap=function(t,n){return n(t),t},Pe.throttle=function(t,e,r){var i=!0,s=!0;if("function"!=typeof t)throw new Ut(n);return Jo(r)&&(i="leading"in r?!!r.leading:i,s="trailing"in r?!!r.trailing:s),jo(t,e,{leading:i,maxWait:e,trailing:s})},Pe.thru=ao,Pe.toArray=au,Pe.toPairs=Du,Pe.toPairsIn=Pu,Pe.toPath=function(t){return Fo(t)?jn(t,zs):ou(t)?[t]:Si(_s(wu(t)))},Pe.toPlainObject=pu,Pe.transform=function(t,n,e){var r=Fo(t),i=r||Yo(t)||uu(t);if(n=is(n,4),null==e){var s=t&&t.constructor;e=i?r?new s:[]:Jo(t)&&Xo(s)?Re(Nt(t)):{}}return(i?xn:yr)(t,(function(t,r,i){return n(e,t,r,i)})),e},Pe.unary=function(t){return So(t,1)},Pe.union=Js,Pe.unionBy=Zs,Pe.unionWith=to,Pe.uniq=function(t){return t&&t.length?oi(t):[]},Pe.uniqBy=function(t,n){return t&&t.length?oi(t,is(n,2)):[]},Pe.uniqWith=function(n,e){return e="function"==typeof e?e:t,n&&n.length?oi(n,t,e):[]},Pe.unset=function(t,n){return null==t||ui(t,n)},Pe.unzip=no,Pe.unzipWith=eo,Pe.update=function(t,n,e){return null==t?t:ci(t,n,vi(e))},Pe.updateWith=function(n,e,r,i){return i="function"==typeof i?i:t,null==n?n:ci(n,e,vi(r),i)},Pe.values=Ru,Pe.valuesIn=function(t){return null==t?[]:Vn(t,Tu(t))},Pe.without=ro,Pe.words=Xu,Pe.wrap=function(t,n){return $o(vi(n),t)},Pe.xor=io,Pe.xorBy=so,Pe.xorWith=oo,Pe.zip=uo,Pe.zipObject=function(t,n){return fi(t||[],n||[],Je)},Pe.zipObjectDeep=function(t,n){return fi(t||[],n||[],Xr)},Pe.zipWith=co,Pe.entries=Du,Pe.entriesIn=Pu,Pe.extend=gu,Pe.extendWith=bu,sc(Pe,Pe),Pe.add=wc,Pe.attempt=qu,Pe.camelCase=Bu,Pe.capitalize=Wu,Pe.ceil=yc,Pe.clamp=function(n,e,r){return r===t&&(r=e,e=t),r!==t&&(r=(r=vu(r))==r?r:0),e!==t&&(e=(e=vu(e))==e?e:0),ir(vu(n),e,r)},Pe.clone=function(t){return sr(t,4)},Pe.cloneDeep=function(t){return sr(t,5)},Pe.cloneDeepWith=function(n,e){return sr(n,5,e="function"==typeof e?e:t)},Pe.cloneWith=function(n,e){return sr(n,4,e="function"==typeof e?e:t)},Pe.conformsTo=function(t,n){return null==n||or(t,n,ju(n))},Pe.deburr=Lu,Pe.defaultTo=function(t,n){return null==t||t!=t?n:t},Pe.divide=gc,Pe.endsWith=function(n,e,r){n=wu(n),e=si(e);var i=n.length,s=r=r===t?i:ir(fu(r),0,i);return(r-=e.length)>=0&&n.slice(r,s)==e},Pe.eq=Ro,Pe.escape=function(t){return(t=wu(t))&&Q.test(t)?t.replace(N,Zn):t},Pe.escapeRegExp=function(t){return(t=wu(t))&&Z.test(t)?t.replace(J,"\\$&"):t},Pe.every=function(n,e,r){var i=Fo(n)?Sn:lr;return r&&ps(n,e,r)&&(e=t),i(n,is(e,3))},Pe.find=vo,Pe.findIndex=Ws,Pe.findKey=function(t,n){return $n(t,is(n,3),yr)},Pe.findLast=po,Pe.findLastIndex=Ls,Pe.findLastKey=function(t,n){return $n(t,is(n,3),gr)},Pe.floor=bc,Pe.forEach=wo,Pe.forEachRight=yo,Pe.forIn=function(t,n){return null==t?t:pr(t,is(n,3),Tu)},Pe.forInRight=function(t,n){return null==t?t:wr(t,is(n,3),Tu)},Pe.forOwn=function(t,n){return t&&yr(t,is(n,3))},Pe.forOwnRight=function(t,n){return t&&gr(t,is(n,3))},Pe.get=Mu,Pe.gt=Bo,Pe.gte=Wo,Pe.has=function(t,n){return null!=t&&ls(t,n,Mr)},Pe.hasIn=Su,Pe.head=Ns,Pe.identity=nc,Pe.includes=function(t,n,e,r){t=Ko(t)?t:Ru(t),e=e&&!r?fu(e):0;var i=t.length;return e<0&&(e=pe(i+e,0)),su(t)?e<=i&&t.indexOf(n,e)>-1:!!i&&Pn(t,n,e)>-1},Pe.indexOf=function(t,n,e){var r=null==t?0:t.length;if(!r)return-1;var i=null==e?0:fu(e);return i<0&&(i=pe(r+i,0)),Pn(t,n,i)},Pe.inRange=function(n,e,r){return e=lu(e),r===t?(r=e,e=0):r=lu(r),function(t,n,e){return t>=we(n,e)&&t<pe(n,e)}(n=vu(n),e,r)},Pe.invoke=Eu,Pe.isArguments=Lo,Pe.isArray=Fo,Pe.isArrayBuffer=No,Pe.isArrayLike=Ko,Pe.isArrayLikeObject=Qo,Pe.isBoolean=function(t){return!0===t||!1===t||Zo(t)&&kr(t)==d},Pe.isBuffer=Yo,Pe.isDate=Ho,Pe.isElement=function(t){return Zo(t)&&1===t.nodeType&&!eu(t)},Pe.isEmpty=function(t){if(null==t)return!0;if(Ko(t)&&(Fo(t)||"string"==typeof t||"function"==typeof t.splice||Yo(t)||uu(t)||Lo(t)))return!t.length;var n=as(t);if(n==g||n==x)return!t.size;if(bs(t))return!_r(t).length;for(var e in t)if(Ot.call(t,e))return!1;return!0},Pe.isEqual=function(t,n){return jr(t,n)},Pe.isEqualWith=function(n,e,r){var i=(r="function"==typeof r?r:t)?r(n,e):t;return i===t?jr(n,e,t,r):!!i},Pe.isError=Vo,Pe.isFinite=function(t){return"number"==typeof t&&fe(t)},Pe.isFunction=Xo,Pe.isInteger=qo,Pe.isLength=Go,Pe.isMap=tu,Pe.isMatch=function(t,n){return t===n||Tr(t,n,os(n))},Pe.isMatchWith=function(n,e,r){return r="function"==typeof r?r:t,Tr(n,e,os(e),r)},Pe.isNaN=function(t){return nu(t)&&t!=+t},Pe.isNative=function(t){if(gs(t))throw new At("Unsupported core-js use. Try https://npms.io/search?q=ponyfill.");return Ir(t)},Pe.isNil=function(t){return null==t},Pe.isNull=function(t){return null===t},Pe.isNumber=nu,Pe.isObject=Jo,Pe.isObjectLike=Zo,Pe.isPlainObject=eu,Pe.isRegExp=ru,Pe.isSafeInteger=function(t){return qo(t)&&t>=-9007199254740991&&t<=u},Pe.isSet=iu,Pe.isString=su,Pe.isSymbol=ou,Pe.isTypedArray=uu,Pe.isUndefined=function(n){return n===t},Pe.isWeakMap=function(t){return Zo(t)&&as(t)==C},Pe.isWeakSet=function(t){return Zo(t)&&"[object WeakSet]"==kr(t)},Pe.join=function(t,n){return null==t?"":de.call(t,n)},Pe.kebabCase=Fu,Pe.last=Hs,Pe.lastIndexOf=function(n,e,r){var i=null==n?0:n.length;if(!i)return-1;var s=i;return r!==t&&(s=(s=fu(r))<0?pe(i+s,0):we(s,i-1)),e==e?function(t,n,e){for(var r=e+1;r--;)if(t[r]===n)return r;return r}(n,e,s):Dn(n,Bn,s,!0)},Pe.lowerCase=Nu,Pe.lowerFirst=Ku,Pe.lt=cu,Pe.lte=hu,Pe.max=function(n){return n&&n.length?fr(n,nc,xr):t},Pe.maxBy=function(n,e){return n&&n.length?fr(n,is(e,2),xr):t},Pe.mean=function(t){return Wn(t,nc)},Pe.meanBy=function(t,n){return Wn(t,is(n,2))},Pe.min=function(n){return n&&n.length?fr(n,nc,zr):t},Pe.minBy=function(n,e){return n&&n.length?fr(n,is(e,2),zr):t},Pe.stubArray=dc,Pe.stubFalse=vc,Pe.stubObject=function(){return{}},Pe.stubString=function(){return""},Pe.stubTrue=function(){return!0},Pe.multiply=mc,Pe.nth=function(n,e){return n&&n.length?Br(n,fu(e)):t},Pe.noConflict=function(){return hn._===this&&(hn._=Pt),this},Pe.noop=oc,Pe.now=Mo,Pe.pad=function(t,n,e){t=wu(t);var r=(n=fu(n))?ue(t):0;if(!n||r>=n)return t;var i=(n-r)/2;return Wi(vn(i),e)+t+Wi(dn(i),e)},Pe.padEnd=function(t,n,e){t=wu(t);var r=(n=fu(n))?ue(t):0;return n&&r<n?t+Wi(n-r,e):t},Pe.padStart=function(t,n,e){t=wu(t);var r=(n=fu(n))?ue(t):0;return n&&r<n?Wi(n-r,e)+t:t},Pe.parseInt=function(t,n,e){return e||null==n?n=0:n&&(n=+n),ge(wu(t).replace(tt,""),n||0)},Pe.random=function(n,e,r){if(r&&"boolean"!=typeof r&&ps(n,e,r)&&(e=r=t),r===t&&("boolean"==typeof e?(r=e,e=t):"boolean"==typeof n&&(r=n,n=t)),n===t&&e===t?(n=0,e=1):(n=lu(n),e===t?(e=n,n=0):e=lu(e)),n>e){var i=n;n=e,e=i}if(r||n%1||e%1){var s=be();return we(n+s*(e-n+sn("1e-"+((s+"").length-1))),e)}return Kr(n,e)},Pe.reduce=function(t,n,e){var r=Fo(t)?In:Nn,i=arguments.length<3;return r(t,is(n,4),e,i,hr)},Pe.reduceRight=function(t,n,e){var r=Fo(t)?On:Nn,i=arguments.length<3;return r(t,is(n,4),e,i,ar)},Pe.repeat=function(n,e,r){return e=(r?ps(n,e,r):e===t)?1:fu(e),Qr(wu(n),e)},Pe.replace=function(){var t=arguments,n=wu(t[0]);return t.length<3?n:n.replace(t[1],t[2])},Pe.result=function(n,e,r){var i=-1,s=(e=pi(e,n)).length;for(s||(s=1,n=t);++i<s;){var o=null==n?t:n[zs(e[i])];o===t&&(i=s,o=r),n=Xo(o)?o.call(n):o}return n},Pe.round=Ac,Pe.runInContext=z,Pe.sample=function(t){return(Fo(t)?Ve:Hr)(t)},Pe.size=function(t){if(null==t)return 0;if(Ko(t))return su(t)?ue(t):t.length;var n=as(t);return n==g||n==x?t.size:_r(t).length},Pe.snakeCase=Qu,Pe.some=function(n,e,r){var i=Fo(n)?_n:ti;return r&&ps(n,e,r)&&(e=t),i(n,is(e,3))},Pe.sortedIndex=function(t,n){return ni(t,n)},Pe.sortedIndexBy=function(t,n,e){return ei(t,n,is(e,2))},Pe.sortedIndexOf=function(t,n){var e=null==t?0:t.length;if(e){var r=ni(t,n);if(r<e&&Ro(t[r],n))return r}return-1},Pe.sortedLastIndex=function(t,n){return ni(t,n,!0)},Pe.sortedLastIndexBy=function(t,n,e){return ei(t,n,is(e,2),!0)},Pe.sortedLastIndexOf=function(t,n){if(null!=t&&t.length){var e=ni(t,n,!0)-1;if(Ro(t[e],n))return e}return-1},Pe.startCase=Yu,Pe.startsWith=function(t,n,e){return t=wu(t),e=null==e?0:ir(fu(e),0,t.length),n=si(n),t.slice(e,e+n.length)==n},Pe.subtract=kc,Pe.sum=function(t){return t&&t.length?Kn(t,nc):0},Pe.sumBy=function(t,n){return t&&t.length?Kn(t,is(n,2)):0},Pe.template=function(n,e,r){var i=Pe.templateSettings;r&&ps(n,e,r)&&(e=t),n=wu(n),e=bu({},e,i,Vi);var s,o,u=bu({},e.imports,i.imports,Vi),c=ju(u),h=Vn(u,c),a=0,l=e.interpolate||wt,f="__p += '",d=St((e.escape||wt).source+"|"+l.source+"|"+(l===V?ct:wt).source+"|"+(e.evaluate||wt).source+"|$","g"),v="//# sourceURL="+(Ot.call(e,"sourceURL")?(e.sourceURL+"").replace(/\s/g," "):"lodash.templateSources["+ ++tn+"]")+"\n";n.replace(d,(function(t,e,r,i,u,c){return r||(r=i),f+=n.slice(a,c).replace(yt,te),e&&(s=!0,f+="' +\n__e("+e+") +\n'"),u&&(o=!0,f+="';\n"+u+";\n__p += '"),r&&(f+="' +\n((__t = ("+r+")) == null ? '' : __t) +\n'"),a=c+t.length,t})),f+="';\n";var p=Ot.call(e,"variable")&&e.variable;if(p){if(ot.test(p))throw new At("Invalid `variable` option passed into `_.template`")}else f="with (obj) {\n"+f+"\n}\n";f=(o?f.replace(B,""):f).replace(W,"$1").replace(L,"$1;"),f="function("+(p||"obj")+") {\n"+(p?"":"obj || (obj = {});\n")+"var __t, __p = ''"+(s?", __e = _.escape":"")+(o?", __j = Array.prototype.join;\nfunction print() { __p += __j.call(arguments, '') }\n":";\n")+f+"return __p\n}";var w=qu((function(){return kt(c,v+"return "+f).apply(t,h)}));if(w.source=f,Vo(w))throw w;return w},Pe.times=function(t,n){if((t=fu(t))<1||t>u)return[];var e=h,r=we(t,h);n=is(n),t-=h;for(var i=Qn(r,n);++e<t;)n(e);return i},Pe.toFinite=lu,Pe.toInteger=fu,Pe.toLength=du,Pe.toLower=function(t){return wu(t).toLowerCase()},Pe.toNumber=vu,Pe.toSafeInteger=function(t){return t?ir(fu(t),-9007199254740991,u):0===t?t:0},Pe.toString=wu,Pe.toUpper=function(t){return wu(t).toUpperCase()},Pe.trim=function(n,e,r){if((n=wu(n))&&(r||e===t))return Yn(n);if(!n||!(e=si(e)))return n;var i=ce(n),s=ce(e);return yi(i,qn(i,s),Gn(i,s)+1).join("")},Pe.trimEnd=function(n,e,r){if((n=wu(n))&&(r||e===t))return n.slice(0,he(n)+1);if(!n||!(e=si(e)))return n;var i=ce(n);return yi(i,0,Gn(i,ce(e))+1).join("")},Pe.trimStart=function(n,e,r){if((n=wu(n))&&(r||e===t))return n.replace(tt,"");if(!n||!(e=si(e)))return n;var i=ce(n);return yi(i,qn(i,ce(e))).join("")},Pe.truncate=function(n,e){var r=30,i="...";if(Jo(e)){var s="separator"in e?e.separator:s;r="length"in e?fu(e.length):r,i="omission"in e?si(e.omission):i}var o=(n=wu(n)).length;if(ne(n)){var u=ce(n);o=u.length}if(r>=o)return n;var c=r-ue(i);if(c<1)return i;var h=u?yi(u,0,c).join(""):n.slice(0,c);if(s===t)return h+i;if(u&&(c+=h.length-c),ru(s)){if(n.slice(c).search(s)){var a,l=h;for(s.global||(s=St(s.source,wu(ht.exec(s))+"g")),s.lastIndex=0;a=s.exec(l);)var f=a.index;h=h.slice(0,f===t?c:f)}}else if(n.indexOf(si(s),c)!=c){var d=h.lastIndexOf(s);d>-1&&(h=h.slice(0,d))}return h+i},Pe.unescape=function(t){return(t=wu(t))&&K.test(t)?t.replace(F,ae):t},Pe.uniqueId=function(t){var n=++_t;return wu(t)+n},Pe.upperCase=Hu,Pe.upperFirst=Vu,Pe.each=wo,Pe.eachRight=yo,Pe.first=Ns,sc(Pe,(pc={},yr(Pe,(function(t,n){Ot.call(Pe.prototype,n)||(pc[n]=t)})),pc),{chain:!1}),Pe.VERSION="4.17.21",xn(["bind","bindKey","curry","curryRight","partial","partialRight"],(function(t){Pe[t].placeholder=Pe})),xn(["drop","take"],(function(n,e){Le.prototype[n]=function(r){r=r===t?1:pe(fu(r),0);var i=this.__filtered__&&!e?new Le(this):this.clone();return i.__filtered__?i.__takeCount__=we(r,i.__takeCount__):i.__views__.push({size:we(r,h),type:n+(i.__dir__<0?"Right":"")}),i},Le.prototype[n+"Right"]=function(t){return this.reverse()[n](t).reverse()}})),xn(["filter","map","takeWhile"],(function(t,n){var e=n+1,r=1==e||3==e;Le.prototype[t]=function(t){var n=this.clone();return n.__iteratees__.push({iteratee:is(t,3),type:e}),n.__filtered__=n.__filtered__||r,n}})),xn(["head","last"],(function(t,n){var e="take"+(n?"Right":"");Le.prototype[t]=function(){return this[e](1).value()[0]}})),xn(["initial","tail"],(function(t,n){var e="drop"+(n?"":"Right");Le.prototype[t]=function(){return this.__filtered__?new Le(this):this[e](1)}})),Le.prototype.compact=function(){return this.filter(nc)},Le.prototype.find=function(t){return this.filter(t).head()},Le.prototype.findLast=function(t){return this.reverse().find(t)},Le.prototype.invokeMap=Yr((function(t,n){return"function"==typeof t?new Le(this):this.map((function(e){return Ur(e,t,n)}))})),Le.prototype.reject=function(t){return this.filter(_o(is(t)))},Le.prototype.slice=function(n,e){n=fu(n);var r=this;return r.__filtered__&&(n>0||e<0)?new Le(r):(n<0?r=r.takeRight(-n):n&&(r=r.drop(n)),e!==t&&(r=(e=fu(e))<0?r.dropRight(-e):r.take(e-n)),r)},Le.prototype.takeRightWhile=function(t){return this.reverse().takeWhile(t).reverse()},Le.prototype.toArray=function(){return this.take(h)},yr(Le.prototype,(function(n,e){var r=/^(?:filter|find|map|reject)|While$/.test(e),i=/^(?:head|last)$/.test(e),s=Pe[i?"take"+("last"==e?"Right":""):e],o=i||/^find/.test(e);s&&(Pe.prototype[e]=function(){var e=this.__wrapped__,u=i?[1]:arguments,c=e instanceof Le,h=u[0],a=c||Fo(e),l=function(t){var n=s.apply(Pe,Tn([t],u));return i&&f?n[0]:n};a&&r&&"function"==typeof h&&1!=h.length&&(c=a=!1);var f=this.__chain__,d=o&&!f,v=c&&!this.__actions__.length;if(!o&&a){e=v?e:new Le(this);var p=n.apply(e,u);return p.__actions__.push({func:ao,args:[l],thisArg:t}),new We(p,f)}return d&&v?n.apply(this,u):(p=this.thru(l),d?i?p.value()[0]:p.value():p)})})),xn(["pop","push","shift","sort","splice","unshift"],(function(t){var n=Et[t],e=/^(?:push|sort|unshift)$/.test(t)?"tap":"thru",r=/^(?:pop|shift)$/.test(t);Pe.prototype[t]=function(){var t=arguments;if(r&&!this.__chain__){var i=this.value();return n.apply(Fo(i)?i:[],t)}return this[e]((function(e){return n.apply(Fo(e)?e:[],t)}))}})),yr(Le.prototype,(function(t,n){var e=Pe[n];if(e){var r=e.name+"";Ot.call(Ee,r)||(Ee[r]=[]),Ee[r].push({name:n,func:e})}})),Ee[Di(t,2).name]=[{name:"wrapper",func:t}],Le.prototype.clone=function(){var t=new Le(this.__wrapped__);return t.__actions__=Si(this.__actions__),t.__dir__=this.__dir__,t.__filtered__=this.__filtered__,t.__iteratees__=Si(this.__iteratees__),t.__takeCount__=this.__takeCount__,t.__views__=Si(this.__views__),t},Le.prototype.reverse=function(){if(this.__filtered__){var t=new Le(this);t.__dir__=-1,t.__filtered__=!0}else(t=this.clone()).__dir__*=-1;return t},Le.prototype.value=function(){var t=this.__wrapped__.value(),n=this.__dir__,e=Fo(t),r=n<0,i=e?t.length:0,s=function(t,n,e){for(var r=-1,i=e.length;++r<i;){var s=e[r],o=s.size;switch(s.type){case"drop":t+=o;break;case"dropRight":n-=o;break;case"take":n=we(n,t+o);break;case"takeRight":t=pe(t,n-o)}}return{start:t,end:n}}(0,i,this.__views__),o=s.start,u=s.end,c=u-o,h=r?u:o-1,a=this.__iteratees__,l=a.length,f=0,d=we(c,this.__takeCount__);if(!e||!r&&i==c&&d==c)return ai(t,this.__actions__);var v=[];t:for(;c--&&f<d;){for(var p=-1,w=t[h+=n];++p<l;){var y=a[p],g=y.type,b=(0,y.iteratee)(w);if(2==g)w=b;else if(!b){if(1==g)continue t;break t}}v[f++]=w}return v},Pe.prototype.at=lo,Pe.prototype.chain=function(){return ho(this)},Pe.prototype.commit=function(){return new We(this.value(),this.__chain__)},Pe.prototype.next=function(){this.__values__===t&&(this.__values__=au(this.value()));var n=this.__index__>=this.__values__.length;return{done:n,value:n?t:this.__values__[this.__index__++]}},Pe.prototype.plant=function(n){for(var e,r=this;r instanceof Be;){var i=Ds(r);i.__index__=0,i.__values__=t,e?s.__wrapped__=i:e=i;var s=i;r=r.__wrapped__}return s.__wrapped__=n,e},Pe.prototype.reverse=function(){var n=this.__wrapped__;if(n instanceof Le){var e=n;return this.__actions__.length&&(e=new Le(this)),(e=e.reverse()).__actions__.push({func:ao,args:[Gs],thisArg:t}),new We(e,this.__chain__)}return this.thru(Gs)},Pe.prototype.toJSON=Pe.prototype.valueOf=Pe.prototype.value=function(){return ai(this.__wrapped__,this.__actions__)},Pe.prototype.first=Pe.prototype.head,Gt&&(Pe.prototype[Gt]=function(){return this}),Pe}();ln?((ln.exports=le)._=le,an._=le):hn._=le}.call($c.exports)),$c.exports);
|
|
2
2
|
/**
|
|
3
3
|
* @license
|
|
4
4
|
* Lodash <https://lodash.com/>
|
|
@@ -6,4 +6,4 @@ import{p as t,H as n,c as e,h as r,d as i,t as s}from"./p-BxS4Pdpz.js";import{K
|
|
|
6
6
|
* Released under MIT license <https://lodash.com/license>
|
|
7
7
|
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
8
8
|
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
9
|
-
*/class Pc{_core;_debounceUpdate;_debounceEndScaling;_velocityX=0;_velocityY=0;_panRafId=null;_friction=.92;_minVelocity=.5;initialTouchDistance=0;startX=0;startY=0;constructor(t,n){this._core=t,this._core.store.state.host=n,this._core.store.state.viewportWidth=n.clientWidth,this._core.store.state.viewportHeight=n.clientHeight,this._core.store.state.startX=0,this._core.store.state.startY=0,this._core.store.state.translateX=0,this._core.store.state.translateY=0,this._debounceUpdate=Dc.debounce((()=>{this._core.updateWorkspaceViewport(this._core.store.state.translateX,this._core.store.state.translateY,this._core.store.state.scale)}),300),this._debounceEndScaling=Dc.debounce((()=>{this._core.store.state.isScaling=!1,this._core.rerender()}),100)}cancelPendingUpdates(){this._debounceUpdate.cancel()}handleResize(){this._core.store.state.viewportWidth=this._core.store.state.host.clientWidth,this._core.store.state.viewportHeight=this._core.store.state.host.clientHeight,this._core.store.state.hasViewportChanged=!0,this._core.rerender()}handlePointerDown(t){if("mouse"===t.pointerType){const n=t.clientX-this._core.store.offsetX,e=t.clientY-this._core.store.offsetY;t.button===o.Right&&(this._core.store.state.isPanning=!0,this._core.store.state.startX=n,this._core.store.state.startY=e)}if("touch"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values());if(2===t.length){const n=this._core.store.currentPath;n&&this._core.store.state.objects.remove((t=>t.id===n.id)),this._core.store.state.isScaling=!0;const e=t[0].clientX-this._core.store.offsetX,r=t[0].clientY-this._core.store.offsetY,i=t[1].clientX-this._core.store.offsetX,s=t[1].clientY-this._core.store.offsetY;this.initialTouchDistance=Math.sqrt(Math.pow(e-i,2)+Math.pow(r-s,2)),this.startX=(e+i)/2,this.startY=(r+s)/2,this._core.rerender()}}}handlePointerMove(t){if("mouse"===t.pointerType){const n=this._core.store.state.host.getBoundingClientRect(),e=t.clientX-n.left,r=t.clientY-n.top;if(this._core.store.state.pointerX=(e-this._core.store.state.translateX)/this._core.store.state.scale,this._core.store.state.pointerY=(r-this._core.store.state.translateY)/this._core.store.state.scale,this._core.store.state.isPanning){const t=r-this._core.store.state.startY;this._core.store.state.translateX+=e-this._core.store.state.startX,this._core.store.state.translateY+=t,this._core.store.state.startX=e,this._core.store.state.startY=r,this._core.store.state.hasViewportChanged=!0,this._core.store.state.skipContextMenu=!0,this._core.rerender(),this._debounceUpdate()}}if("touch"===t.pointerType){const n=this._core.store.state.host.getBoundingClientRect(),e=t.clientY-n.top;this._core.store.state.pointerX=(t.clientX-n.left-this._core.store.state.translateX)/this._core.store.state.scale,this._core.store.state.pointerY=(e-this._core.store.state.translateY)/this._core.store.state.scale;const r=Array.from(this._core.store.state.pointers.values());if(2===r.length){const t=r[0].clientX-this._core.store.offsetX,n=r[0].clientY-this._core.store.offsetY,e=r[1].clientX-this._core.store.offsetX,i=r[1].clientY-this._core.store.offsetY,s=Math.sqrt(Math.pow(t-e,2)+Math.pow(n-i,2)),o=(t+e)/2,u=(n+i)/2,c=s/this.initialTouchDistance,h=this._core.store.state.scale*c;if(h>this._core.store.state.scaleMax||h<this._core.store.state.scaleMin)this._core.store.state.translateX=this._core.store.state.translateX+o-this.startX,this._core.store.state.translateY=this._core.store.state.translateY+u-this.startY;else{const t=(u-this._core.store.state.translateY)*(c-1);this._core.store.state.translateX=this._core.store.state.translateX+o-this.startX-(o-this._core.store.state.translateX)*(c-1),this._core.store.state.translateY=this._core.store.state.translateY+u-this.startY-t,this._core.store.state.scale=h,this.initialTouchDistance=s}this.startX=o,this.startY=u,this._core.store.state.hasViewportChanged=!0,this._core.rerender(),this._debounceUpdate()}}}handlePointerUp(t){"mouse"===t.pointerType&&this._core.store.state.isPanning&&(this._core.store.state.isPanning=!1,this._core.rerender()),"touch"===t.pointerType&&0===this._core.store.state.pointers.size&&this._debounceEndScaling()}handleWheel(t){t.preventDefault(),!0===t.ctrlKey&&Math.abs(t.deltaY)>0&&0===Math.abs(t.deltaX)&&this.handleZoom(t),t.ctrlKey||this.handlePan(t)}centerInViewport(t){const{scale:n,viewportWidth:e,viewportHeight:r}=this._core.store.state,{x:i,y:s,width:o,height:u}=t.rotatedBoundingBox,c=s+u/2;this._core.store.state.translateX=e/2-(i+o/2)*n,this._core.store.state.translateY=r/2-c*n,this._core.store.state.hasViewportChanged=!0,this._core.rerender(),this._debounceUpdate()}centerFitInViewport(t){const n=Math.min(this._core.store.state.viewportWidth/(1.1*t.rotatedBoundingBox.width),this._core.store.state.viewportHeight/(1.1*t.rotatedBoundingBox.height),this._core.store.state.scaleMax),e=Math.max(n,this._core.store.state.scaleMin);this._core.store.state.scale=e,this.centerInViewport(t)}handleZoom(t){this._core.store.state.isScaling=!0;const n=this._core.store.state.host.getBoundingClientRect(),e=t.clientX-n.left,r=t.clientY-n.top;this._core.store.state.pointerX=(e-this._core.store.state.translateX)/this._core.store.state.scale,this._core.store.state.pointerY=(r-this._core.store.state.translateY)/this._core.store.state.scale;const i=Math.max(.8,Math.min(1.2,1+-.012*t.deltaY)),s=Math.min(this._core.store.state.scaleMax,Math.max(this._core.store.state.scaleMin,this._core.store.state.scale*i)),o=s/this._core.store.state.scale,u=(e-this._core.store.state.translateX)*(o-1),c=(r-this._core.store.state.translateY)*(o-1);this._core.store.state.scale=s,this._core.store.state.translateX=this._core.store.state.translateX-u,this._core.store.state.translateY=this._core.store.state.translateY-c,this._core.store.state.hasViewportChanged=!0,this._core.rerender(),this._debounceUpdate(),this._debounceEndScaling()}handlePan(t){let n=t.deltaX,e=t.deltaY;1===t.deltaMode?(n*=16,e*=16):2===t.deltaMode&&(n*=window.innerWidth,e*=window.innerHeight),this._velocityX=.8*-n,this._velocityY=.8*-e,null===this._panRafId&&this._animatePan()}_animatePan(){this._core.store.state.translateX+=this._velocityX,this._core.store.state.translateY+=this._velocityY,this._core.store.state.hasViewportChanged=!0,this._core.rerender(),this._velocityX*=this._friction,this._velocityY*=this._friction,Math.abs(this._velocityX)>this._minVelocity||Math.abs(this._velocityY)>this._minVelocity?this._panRafId=requestAnimationFrame((()=>this._animatePan())):(this._velocityX=0,this._velocityY=0,this._panRafId=null,this._debounceUpdate())}}class Rc extends p{shortcuts=[{key:"Escape",condition:t=>!!t.store.selectionGroup,action:t=>t.clearSelection()},{key:"Delete",condition:t=>!!t.store.selectionGroup,action:t=>t.delete()},{key:"z",ctrl:!0,action:t=>t.undo()},{key:"y",ctrl:!0,action:t=>t.redo()},{key:"s",ctrl:!0,action:()=>this.switchTool("selection")},{key:"b",ctrl:!0,action:()=>this.switchTool("brush")},{key:"e",ctrl:!0,action:()=>this.switchTool("eraser")},{key:"i",ctrl:!0,action:()=>this.switchTool("image")},{key:"x",ctrl:!0,action:()=>this.switchTool("text")},{key:"c",ctrl:!0,condition:t=>!!t.store.selectionGroup,action:t=>{t.copy(),t.rerender()}},{key:"v",ctrl:!0,condition:t=>!!t.store.state.copiedObjects&&!t.store.activeText,action:t=>t.paste()},{key:"+",ctrl:!0,condition:t=>!!t.store.selectionGroup,action:t=>t.bringForward()},{key:"-",ctrl:!0,condition:t=>!!t.store.selectionGroup,action:t=>t.sendBackward()},{key:"*",shift:!0,condition:t=>!!t.store.selectionGroup,action:t=>t.bringToFront()},{key:"_",shift:!0,condition:t=>!!t.store.selectionGroup,action:t=>t.sendToBack()},{key:"g",ctrl:!0,condition:t=>!!t.store.selectionGroup&&t.store.selectionGroup.objects.length>=2,action:t=>t.group()},{key:"G",ctrl:!0,shift:!0,condition:t=>!!t.store.selectionGroup,action:t=>t.ungroup()}];constructor(t){super(t)}switchTool(t){const n=a.getTool(t);this._core.store.setState("activeTool",n),this._core.deselectAllObjects(),n.onActivate()}handleKeyDown(t){this._core.store.state.isCtrlKeyPressed=t.ctrlKey;const n=this.shortcuts.find((n=>n.key===t.key&&!!n.ctrl===t.ctrlKey&&!!n.shift===t.shiftKey&&(!n.condition||n.condition(this._core))));n&&(t.preventDefault(),n.action(this._core))}handleKeyUp(t){this._core.store.state.isCtrlKeyPressed=t.ctrlKey}}class Bc extends p{globalContextMenuItems=[];objectContextMenuItems=[];constructor(t,n,e){super(t),this.globalContextMenuItems=n,this.objectContextMenuItems=e}handleContextMenu(t){if(!(this._core.store.state.activeTool instanceof w))return;if(this._core.store.state.skipContextMenu)return void(this._core.store.state.skipContextMenu=!1);const n=this._core.store.state.activeTool;n?.moveHandler?.cancelPendingDrag(),this._core.store.selectionBox&&(this._core.store.state.objects.remove((t=>t instanceof d)),this._core.store.state.isSelecting=!1);const e=this._core.getObjectFromPointerEvent(t,".object");if(e&&!(e instanceof v)&&!(e instanceof d)){const t=v.create(this._core);t.addOrRemove(e),t.isSelected=!0,t.rotation=e.rotation,this._core.store.state.isSelecting=!1,this._core.store.selectionGroup&&this._core.removeSelectionGroup(),this._core.addSelectionGroup(t),this._core.rerender()}this._core.store.state.contextMenuItems=this._core.store.selectionGroup?this.objectContextMenuItems:this.globalContextMenuItems;let r=t.clientX-this._core.store.offsetX,i=t.clientY-this._core.store.offsetY;const s=10;r+150>window.innerWidth-s&&(r=window.innerWidth-150-s),i+200>window.innerHeight-s&&(i=window.innerHeight-200-s),r=Math.max(s,r),i=Math.max(s,i),this._core.store.state.contextMenuX=r,this._core.store.state.contextMenuY=i,this._core.store.state.isContextMenuVisible=!0,this._core.store.state.isEnabled=!1,this._core.rerender()}}const Wc={activeWorkspace:null,activeTool:null,copiedObjects:null,objects:null,snapCandidate:null,resizeHandleType:null,lineHandleType:null,hasViewportChanged:!1,hasObjectsChanged:!1,isReady:!1,isEnabled:!0,isScaling:!1,isPanning:!1,isSelecting:!1,isResizing:!1,isResizeHandleHovered:!1,isResizeHandleSelected:!1,isRotating:!1,isRotationHandleHovered:!1,isRotationHandleSelected:!1,isLineHandleSelected:!1,isLineHandleDragging:!1,isDragging:!1,isDrawing:!1,isErasing:!1,isWriting:!1,isCtrlKeyPressed:!1,isContextMenuVisible:!1,contextMenuItems:[],contextMenuX:0,contextMenuY:0,skipContextMenu:!1,debugInfo:{showObjectInfo:!1,showViewportInfo:!1},host:null,pointerX:0,pointerY:0,scale:1,scaleMax:1,scaleMin:1,startX:0,startY:0,translateX:0,translateXMax:400,translateXMin:0,translateY:0,translateYMax:400,translateYMin:0,viewportWidth:0,viewportHeight:0,longTouchTimeout:null,longTouchDelay:300,pointers:new Map,workspaces:[],cursor:{icon:"default",iconActive:"default"}};class Lc extends u{__class__="KritzelCustomElement";element;isInteractive=!0;constructor(t){super(),t&&(this.translateX=t.translateX||0,this.translateY=t.translateY||0,this.scale=t.scale||1,this.element=t.element,this.height=t.height||0,this.width=t.width||0)}static create(t,n){const e=new Lc(n);return e._core=t,e.id=e.generateId(),e.workspaceId=t.store.state.activeWorkspace.id,e}mount(t){null!==t&&(this.isMounted&&this.elementRef===t&&this.element.parentElement===t||(this.elementRef=t,this.isMounted=!0,this.elementRef.innerHTML="",this.elementRef.appendChild(this.element)))}resize(t,n,e,r){e<=1||r<=1||(this.width=e,this.height=r,this.translateX=t,this.translateY=n,this.element&&(this.element.style.width=`${e}px`,this.element.style.height=`${r}px`),this._core.store.state.objects.update(this))}copy(){const t=Object.create(Object.getPrototypeOf(this));return Object.assign(t,this),t.id=this.generateId(),t.isMounted=!1,t.element=this.element.cloneNode(!0),t}}class Fc{_core;constructor(t){this._core=t}revive(t){if(t&&"object"==typeof t){if(t.__class__){let n;switch(t.__class__){case"KritzelPath":n=M.create(this._core).deserialize(t);break;case"KritzelLine":n=l.create(this._core).deserialize(t);break;case"KritzelText":n=x.create(this._core,t.fontSize,t.fontFamily).deserialize(t);break;case"KritzelShape":n=k.create(this._core,{shapeType:t.shapeType,fillColor:t.fillColor,strokeColor:t.strokeColor,strokeWidth:t.strokeWidth,fontSize:t.fontSize,fontFamily:t.fontFamily,fontColor:t.fontColor}).deserialize(t);break;case"KritzelImage":n=$.create(this._core).deserialize(t);break;case"KritzelCustomElement":n=Lc.create(this._core).deserialize(t);break;case"KritzelSelectionGroup":n=v.create(this._core).deserialize(t);break;case"KritzelGroup":n=A.create(this._core).deserialize(t);break;case"KritzelWorkspace":n=I.create(this._core,t).deserialize(t);break;case"KritzelBrushTool":n=new m(this._core);break;case"KritzelEraserTool":n=new D(this._core);break;case"KritzelImageTool":n=new wt(this._core);break;case"KritzelSelectionTool":n=new w(this._core);break;case"KritzelTextTool":n=new b(this._core);break;case"KritzelLineTool":n=new g(this._core);break;case"KritzelShapeTool":n=new y(this._core);break;default:n=t}return n}const n=Array.isArray(t)?[]:{};for(const e in t)Object.prototype.hasOwnProperty.call(t,e)&&(n[e]=this.revive(t[e]));return n}return t}}class Nc{bounds;capacity;objects=[];children=null;constructor(t,n=16){this.bounds=t,this.capacity=n}reset(){this.objects=[],this.children=null}insert(t){if(!this.intersects(t.rotatedBoundingBox,this.bounds))return!1;if(this.objects.length<this.capacity&&null===this.children)return this.objects.push(t),!0;null===this.children&&this.subdivide();for(const n of this.children)if(n.insert(t))return!0;return!1}update(t){const n=this.objects.findIndex((n=>n.id===t.id));if(-1!==n)return this.objects[n]=t,!0;if(null!==this.children)for(const n of this.children)if(n.update(t))return!0;return!1}remove(t){const n=this.objects.findIndex((n=>t(n)));if(-1!==n&&this.objects.splice(n,1),null!==this.children)for(const n of this.children)n.remove(t)}query(t){const n=[];if(!this.intersects(t,this.bounds))return n;for(const e of this.objects)this.intersects(e.rotatedBoundingBox,t)&&n.push(e);if(null!==this.children)for(const e of this.children)n.push(...e.query(t));return n}filter(t){const n=this.objects.filter((n=>t(n)));if(null!==this.children)for(const e of this.children)n.push(...e.filter(t));return n}allObjects(){const t=[...this.objects];if(null!==this.children)for(const n of this.children)t.push(...n.allObjects());return t}subdivide(){const{x:t,y:n,z:e,width:r,height:i}=this.bounds,s=r/2,o=i/2;this.children=[new Nc({x:t,y:n,z:e,width:s,height:o},this.capacity),new Nc({x:t+s,y:n,z:e,width:s,height:o},this.capacity),new Nc({x:t,y:n+o,z:e,width:s,height:o},this.capacity),new Nc({x:t+s,y:n+o,z:e,width:s,height:o},this.capacity)]}intersects(t,n){return!(t.x>=n.x+n.width||t.x+t.width<=n.x||t.y>=n.y+n.height||t.y+t.height<=n.y)}}class Kc{quadtree;_ydoc=null;_objectsMap=null;_providers=[];_undoManager=null;_reviver=null;_core=null;_workspaceId=null;_isReady=!1;_temporaryItemsCount=0;get isReady(){return this._isReady}get undoManager(){return this._undoManager}get workspaceId(){return this._workspaceId}get undoState(){return{canUndo:!!this._undoManager&&this._undoManager.canUndo(),canRedo:!!this._undoManager&&this._undoManager.canRedo(),undoStackSize:this._undoManager?this._undoManager.undoStack.length:0,redoStackSize:this._undoManager?this._undoManager.redoStack.length:0}}constructor(){this.quadtree=new Nc({x:-1/0,y:-1/0,z:0,width:1/0,height:1/0},8)}async initialize(t,n,e){this._core=t,this._workspaceId=n,this._reviver=new Fc(t),this._ydoc=new ui,this._objectsMap=this._ydoc.getMap("objects");const r=`kritzel-workspace-${n}`,i=e??Cc;for(const t of i.providers){let n;n="function"==typeof t?new t(r,this._ydoc):t.create(r,this._ydoc),this._providers.push(n)}this._undoManager=new ts([this._objectsMap],{captureTimeout:200,trackedOrigins:new Set(["local","temporary"]),ignoreRemoteMapChanges:!0}),this._undoManager.on("stack-item-added",(t=>{"undo"===t.type&&"temporary"===t.origin&&this._temporaryItemsCount++})),this._undoManager.on("stack-item-popped",(t=>{"undo"===t.type&&"temporary"===t.origin&&this._temporaryItemsCount>0&&this._temporaryItemsCount--})),this._objectsMap.observe((t=>{this.handleObjectsChange(t)})),await Promise.all(this._providers.map((t=>t.connect()))),this._isReady=!0,this.loadFromYjs()}handleObjectsChange(t){if("local"===t.transaction.origin||"temporary"===t.transaction.origin)return void this._core?.rerender();const n=Array.from(t.keysChanged),e=[],r=[],i=[];n.forEach((n=>{const s=t.changes.keys.get(n);if(s&&"delete"===s.action)i.push(n);else{const t=this._objectsMap.get(n);if(t){const n=this._reviver.revive(t);n instanceof v?r.push(n):e.push(n)}}})),i.forEach((t=>{this.quadtree.remove((n=>n.id===t))})),e.forEach((t=>{const n=this.quadtree.filter((n=>n.id===t.id)).length>0;n?this.quadtree.update(t):this.quadtree.insert(t)})),r.forEach((t=>{const n=this.quadtree.filter((n=>n.id===t.id)).length>0;n?this.quadtree.update(t):this.quadtree.insert(t)})),this._core?.rerender()}transaction(t){this._ydoc&&this._ydoc.transact(t,"local")}loadFromYjs(){this._objectsMap&&this._reviver&&(this.quadtree.reset(),this._objectsMap.forEach((t=>{const n=this._reviver.revive(t);this.quadtree.insert(n)})))}reset(){this.quadtree.reset(),this._ydoc.transact((()=>{this._objectsMap.clear()}),"local")}insert(t){if(!t.id)return!1;if(this.quadtree.insert(t),this._objectsMap&&this.isPersistable(t)){const n=t.serialize();this._ydoc.transact((()=>{this._objectsMap.set(t.id,n)}),"local")}return!0}update(t,n={}){if(!t.id)return!1;const e=this.quadtree.filter((n=>n.id===t.id)).length>0;if(!e)return!1;if(this.quadtree.update(t),this._objectsMap&&this.isPersistable(t)){const e=t.serialize();this._ydoc.transact((()=>{this._objectsMap.set(t.id,e)}),n.temporary?"temporary":"local")}return!0}remove(t){const n=this.quadtree.filter(t);for(const t of n)this.quadtree.remove((n=>n.id===t.id)),this._objectsMap&&this.isPersistable(t)&&this._ydoc.transact((()=>{this._objectsMap.delete(t.id)}),"local")}filter(t){return this.quadtree.filter(t)}allObjects(){return this.quadtree.allObjects()}query(t){return this.quadtree.query(t)}isPersistable(t){return!(t instanceof d)}undo(){this._undoManager&&this._undoManager.canUndo()&&(this._undoManager.undo(),this._core.engine.emitObjectsChange())}redo(){this._undoManager&&this._undoManager.canRedo()&&(this._undoManager.redo(),this._core.engine.emitObjectsChange())}canUndo(){return!!this._undoManager&&this._undoManager.canUndo()}canRedo(){return!!this._undoManager&&this._undoManager.canRedo()}clearHistory(){this._undoManager&&(this._undoManager.clear(),this._temporaryItemsCount=0)}consolidateTemporaryItems(){if(!this._undoManager||0===this._temporaryItemsCount)return;const t=this._undoManager.undoStack.length;if(0===t)return void(this._temporaryItemsCount=0);this._undoManager.stopCapturing();const n=Math.min(this._temporaryItemsCount,t);if(n>1){for(let t=0;t<n;t++)this._undoManager.canUndo()&&this._undoManager.undo();this._ydoc.transact((()=>{for(let t=n-1;t>=0;t--)this._undoManager.canRedo()&&this._undoManager.redo()}),"local")}this._temporaryItemsCount=0}clearTemporaryItems(){if(!this._undoManager||0===this._temporaryItemsCount)return;const t=Math.min(this._temporaryItemsCount,this._undoManager.undoStack.length);for(let n=0;n<t;n++)this._undoManager.undoStack.length>0&&this._undoManager.undoStack.pop();this._temporaryItemsCount=0}destroy(){this._providers.forEach((t=>t.destroy())),this._providers=[],this._ydoc&&this._ydoc.destroy()}}class Qc{_state;_listeners=new Map;get state(){return this._state}get currentZIndex(){return Math.max(0,...this._state.objects.filter((t=>!(t instanceof v||t instanceof d))).map((t=>t.zIndex)))+1}get allObjects(){return this._state.objects.allObjects()}get allNonSelectionObjects(){return this._state.objects.allObjects().filter((t=>!(t instanceof v||t instanceof d)))}get selectedObjects(){return this.allObjects.filter((t=>!(t instanceof v))).filter((t=>t.isSelected))}get selectionBox(){const t=this._state.objects.filter((t=>t instanceof d));return t.length>0?t[0]:null}get selectionGroup(){const t=this._state.objects.filter((t=>t instanceof v));return t.length>0?t[0]:null}get activeText(){const t=this._state.objects.filter((t=>t instanceof x&&t.isEditing));return t.length>0?t[0]:null}get activeShape(){const t=this._state.objects.filter((t=>t instanceof k&&t.isEditing));return t.length>0?t[0]:null}get currentPath(){const t=this._state.objects.filter((t=>t instanceof M&&!1===t.isCompleted));return t.length>0?t[0]:null}get currentLine(){const t=this._state.objects.filter((t=>t instanceof l&&!1===t.isCompleted));return t.length>0?t[0]:null}get offsetX(){return this._state.host.getBoundingClientRect().left}get offsetY(){return this._state.host.getBoundingClientRect().top}get isDisabled(){return!1===this._state.isEnabled||!1===this._state.isReady||null===this._state.activeWorkspace}get isPointerDown(){return this._state.pointers.size>0}constructor(t){this._state=t,this._state.objects=new Kc}onStateChange(t,n){this._listeners.has(t)||this._listeners.set(t,new Set),this._listeners.get(t).add(n)}getState(t){return this._state[t]}setState(t,n){const e=this._state[t];e!==n&&(this._state[t]=n,this._listeners.has(t)&&this._listeners.get(t).forEach((r=>r(n,e,String(t)))))}}class Yc{_core;_targetElement=null;_shadowRoot=null;constructor(t){this._core=t}setTargetElement(t){this._targetElement&&(this._targetElement.style.cursor="",this._targetElement.style.removeProperty("--kritzel-pointer-cursor")),this._targetElement=t,this._targetElement&&this._targetElement.style.setProperty("--kritzel-pointer-cursor",yt.getPointerCursor())}getTargetElement(){return this._targetElement}setShadowRoot(t){this._shadowRoot=t}resetToDefault(){this._core.store.state.cursor={icon:"default",iconActive:"default"}}updateHoverState(t){if(this._core.store.isPointerDown)return;if(!this._shadowRoot)return;const n=this._shadowRoot.elementsFromPoint(t.clientX,t.clientY);if(!n||0===n.length)return;const e=n.find((t=>t.classList.contains("resize-handle-overlay")));if(e){const t=this._core.store.selectionGroup,n=t?.rotationDegrees??0,r=e.classList.contains("top-left"),i=e.classList.contains("bottom-right");this._core.store.state.cursor={icon:"move-vertical",rotation:n+(r||i?-45:45)}}else this._core.store.state.cursor=n.find((t=>t.classList.contains("rotation-handle-overlay")))||n.find((t=>t.classList.contains("selection-line-handle-overlay")))?{icon:"hand",iconActive:"hand-grab"}:{icon:"default",iconActive:"default"}}applyCursor(){const t=this._core.store.state,n=this._core.store.isPointerDown,e=t.cursor?.icon,r=t.cursor?.iconActive??e,i=t.cursor?.rotation,s=yt.getCursor({iconName:n?r:e,rotation:i});this._targetElement&&(this._targetElement.style.cursor=s)}cleanup(){this._targetElement&&(this._targetElement.style.cursor="",this._targetElement.style.removeProperty("--kritzel-pointer-cursor")),this._targetElement=null,this._shadowRoot=null}}class Hc{_kritzelEngine;_store;_syncConfig;_appStateMap;_anchorManager;_cursorManager;get engine(){return this._kritzelEngine}get store(){return this._store}get appStateMap(){return this._appStateMap}get anchorManager(){return this._anchorManager}get cursorManager(){return this._cursorManager}constructor(t){this._kritzelEngine=t,this._store=new Qc(Wc),this._appStateMap=new Uc,this._anchorManager=new jc(this),this._cursorManager=new Yc(this)}setSyncConfig(t){this._syncConfig=t}async initializeYjs(){await this._appStateMap.initialize(this,this._syncConfig)}loadWorkspacesFromAppState(){return this._appStateMap.allWorkspaces()}saveWorkspaceToAppState(t){this._appStateMap.has(t.id)?this._appStateMap.update(t):this._appStateMap.insert(t)}deleteWorkspaceFromAppState(t){this._appStateMap.remove((n=>n.id===t))}async initializeWorkspace(t){const n=this.loadWorkspacesFromAppState(),e=n.length>0?[...n].sort(((t,n)=>n.updatedAt.getTime()-t.updatedAt.getTime()))[0]:null,r=localStorage.getItem("kritzel-active-workspace-id"),i=r?n.find((t=>t.id===r)):null;let s;t?(s=t,n.find((n=>n.id===t.id))||(s._core=this,this.saveWorkspaceToAppState(s))):i?s=i:e?s=e:(s=new I(E.generateUUID(),"New Workspace"),s._core=this,this.saveWorkspaceToAppState(s)),localStorage.setItem("kritzel-active-workspace-id",s.id),this._store.state.objects&&this._store.state.objects.isReady&&this._store.state.objects.destroy();const o=new Kc;this._store.state.objects=o,this._store.state.activeWorkspace=s,this._store.state.workspaces=this.loadWorkspacesFromAppState();const u=s.viewport??{translateX:0,translateY:0,scale:1};this._store.state.translateX=u.translateX??0,this._store.state.translateY=u.translateY??0,this._store.state.scale=u.scale??1,await o.initialize(this,s.id,this._syncConfig),this._anchorManager.rebuildIndex(),this.engine.emitObjectsChange(),this.rerender()}rerender(){this._kritzelEngine&&this._kritzelEngine.forceUpdate++}findObjectById(t){for(const n of this._store.allObjects)if(n.id===t)return n;return null}getWorkspaces(){return this.loadWorkspacesFromAppState()}createWorkspace(t){t._core=this,t.createdAt=new Date,t.updatedAt=new Date,this.saveWorkspaceToAppState(t),this._store.state.workspaces=this.loadWorkspacesFromAppState()}updateWorkspace(t){t.updatedAt=new Date,this.saveWorkspaceToAppState(t);const n=this._store.state.workspaces,e=n.findIndex((n=>n.id===t.id));-1!==e&&(n[e]=t,this._store.state.workspaces=n)}deleteWorkspace(t){this._store.state.activeWorkspace?.id===t.id&&this._store.state.objects?.destroy(),this.deleteWorkspaceFromAppState(t.id),this._store.state.workspaces=this.loadWorkspacesFromAppState(),window.indexedDB.deleteDatabase(`kritzel-workspace-${t.id}`)}updateWorkspaceViewport(t,n,e){const r=this._store.state.activeWorkspace;r&&(r.viewport={translateX:t,translateY:n,scale:e},r.updatedAt=new Date,this.saveWorkspaceToAppState(r))}addObject(t){this._store.state.objects.insert(t)}removeObject(t,n=!1){t instanceof A&&!n&&[...t.children].forEach((t=>{this.removeObject(t)})),t instanceof l?this._anchorManager.handleLineDeleted(t.id):this._anchorManager.handleObjectDeleted(t.id),t.isMounted=!1,this._store.state.objects.remove((n=>n.id===t.id))}updateObject(t,n){for(const e in n)n.hasOwnProperty(e)&&(t[e]=n[e]);this._store.state.objects.update(t)}addSelectionGroup(t){this.removeSelectionGroup(),this.removeSelectionBox(),this._store.state.objects.insert(t),this._kritzelEngine.triggerSelectionChange()}removeSelectionGroup(){const t=this._store.selectionGroup;t&&(this._store.state.objects.remove((n=>n.id===t.id)),this._kritzelEngine.triggerSelectionChange())}removeSelectionBox(){const t=this._store.selectionBox;t&&this._store.state.objects.remove((n=>n.id===t.id))}deselectAllObjects(){this.removeSelectionGroup(),this.rerender()}delete(){const t=this._store.selectionGroup;t&&(t.objects.forEach((t=>this.removeObject(t))),this.removeSelectionGroup(),this.rerender())}undo(){this._store.state.objects?.undo()}redo(){this._store.state.objects?.redo()}deleteObject(t){const n=this.findObjectById(t);n&&(this.removeObject(n),this.rerender())}copy(){const t=this._store.selectionGroup;if(t){const n=new Map,e=t.objects.sort(((t,n)=>t.zIndex-n.zIndex)).map((t=>{const e=t.copy();return n.set(e.id,t.id),e}));this._store.state.copiedObjects=e,this._store.state.copiedObjectIdMapping=n}}paste(t,n){const e=this._store.state.copiedObjects;if(!e||0===e.length)return;const r=this._store.state.activeWorkspace,i=this._store.state.copiedObjectIdMapping,s=e.some((t=>t.workspaceId!==r.id)),o=Math.min(...e.map((t=>t.translateX))),u=Math.min(...e.map((t=>t.translateY)));let c,h;void 0!==t&&void 0!==n?(c=t,h=n):s?(c=o,h=u):(c=o+25/this._store.state.scale,h=u+25/this._store.state.scale);const f=c-o,d=h-u;this.removeSelectionGroup(),this.removeSelectionBox();const p=v.create(this),w=new Map;i&&i.forEach(((t,n)=>{w.set(t,n)})),e.forEach(((t,n)=>{if(t.workspaceId!==r.id&&(t.workspaceId=r.id),t.updatePosition(t.translateX+f,t.translateY+d),t.zIndex=this._store.currentZIndex+n,t instanceof A){const e=t._pendingChildren;e&&(e.forEach(((t,e)=>{t.workspaceId!==r.id&&(t.workspaceId=r.id),t.updatePosition(t.translateX+f,t.translateY+d),t.zIndex=this._store.currentZIndex+n+e,this.addObject(t)})),delete t._pendingChildren,t.finalize())}this.addObject(t),p.addOrRemove(t)})),e.forEach((t=>{if(t instanceof l){let n=!1;t.startAnchor&&w.has(t.startAnchor.objectId)&&(t.startAnchor={objectId:w.get(t.startAnchor.objectId)},n=!0),t.endAnchor&&w.has(t.endAnchor.objectId)&&(t.endAnchor={objectId:w.get(t.endAnchor.objectId)},n=!0),n&&this._store.state.objects.update(t)}})),this._anchorManager.rebuildIndex(),p.isSelected=!0,1===e.length&&(p.rotation=e[0].rotation),this.addSelectionGroup(p),s&&(void 0!==t&&void 0!==n?p.updatePosition(t,n):p.centerInViewport(),this.engine.viewport.centerFitInViewport(p)),this._store.state.isSelecting=!1;const y=this._store.selectionGroup;if(y){const t=new Map,n=y.objects.sort(((t,n)=>t.zIndex-n.zIndex)).map((n=>{const e=n.copy();return t.set(e.id,n.id),e}));this._store.state.copiedObjects=n,this._store.state.copiedObjectIdMapping=t}this._store.setState("activeTool",a.getTool("selection")),this.engine.emitObjectsChange(),this.rerender()}bringForward(t){const n=this._store.selectionGroup,e=t?[t]:n?.objects||[],r=this._store.allNonSelectionObjects.filter((t=>-1===e.findIndex((n=>n.id===t.id)))),i=r.length>0?Math.max(...r.map((t=>t.zIndex)))+1:0;e.forEach((t=>{t.zIndex!==i&&this.updateObject(t,{zIndex:t.zIndex+1})})),this.rerender()}sendBackward(t){const n=this._store.selectionGroup,e=t?[t]:n?.objects||[],r=this._store.allNonSelectionObjects.filter((t=>-1===e.findIndex((n=>n.id===t.id)))),i=r.length>0?Math.min(...r.map((t=>t.zIndex)))-1:0;e.forEach((t=>{t.zIndex!==i&&this.updateObject(t,{zIndex:t.zIndex-1})})),this.rerender()}bringToFront(t){const n=this._store.selectionGroup,e=t?[t]:n?.objects||[],r=this._store.allNonSelectionObjects.filter((t=>-1===e.findIndex((n=>n.id===t.id)))),i=Math.max(...r.map((t=>t.zIndex)))+1;e.forEach((t=>{this.updateObject(t,{zIndex:i})})),this.rerender()}sendToBack(t){const n=this._store.selectionGroup,e=t?[t]:n?.objects||[],r=this._store.allNonSelectionObjects.filter((t=>-1===e.findIndex((n=>n.id===t.id)))),i=Math.min(...r.map((t=>t.zIndex)))-1;e.forEach((t=>{this.updateObject(t,{zIndex:i})})),this.rerender()}group(){const t=this._store.selectionGroup;if(!t||t.objects.length<2)return;const n=A.createFromObjects(this,t.objects);this.addObject(n),this.removeSelectionGroup();const e=v.create(this);e.addOrRemove(n),e.isSelected=!0,e.rotation=n.rotation,this.addSelectionGroup(e),this.engine.emitObjectsChange(),this.rerender()}ungroup(){const t=this._store.selectionGroup;if(!t)return;const n=t.objects.filter((t=>t instanceof A));if(0===n.length)return;const e=[],r=t.objects.filter((t=>!(t instanceof A)));n.forEach((t=>{const n=t.ungroup();e.push(...n),this.removeObject(t,!0)})),this.removeSelectionGroup();const i=v.create(this);[...e,...r].forEach((t=>{i.addOrRemove(t)})),i.isSelected=!0,this.addSelectionGroup(i),this.engine.emitObjectsChange(),this.rerender()}selectObjects(t){if(0===t.length)return;const n=v.create(this);t.forEach((t=>{t.isSelected=!1,n.addOrRemove(t)})),n.isSelected=!0,1===t.length&&(n.rotation=n.objects[0].rotation),this.addSelectionGroup(n),this.rerender()}selectAllObjectsInViewport(){const t=this._store.state.objects.query({x:-this._store.state.translateX/this._store.state.scale,y:-this._store.state.translateY/this._store.state.scale,z:this._store.state.scale,width:this._store.state.viewportWidth/this._store.state.scale,height:this._store.state.viewportHeight/this._store.state.scale,depth:100}).filter((t=>t.isInViewport())).filter((t=>!(t instanceof v||t instanceof d||t instanceof C)));if(t.length>0){const n=v.create(this);t.forEach((t=>{t.isSelected=!1,n.addOrRemove(t)})),n.isSelected=!0,this._store.state.isSelecting=!1,1===t.length&&(n.rotation=n.objects[0].rotation),this.addSelectionGroup(n),this._store.setState("activeTool",a.getTool("selection")),this.rerender()}}clearSelection(){this.removeSelectionGroup(),this._store.state.objects.remove((t=>t instanceof d||t instanceof v)),this._store.state.isSelecting=!1,this._store.state.isResizeHandleSelected=!1,this._store.state.isRotationHandleSelected=!1,this._store.state.isLineHandleSelected=!1,this._store.state.isLineHandleDragging=!1,this._store.state.lineHandleType=null,this.rerender()}resetActiveText(){const t=this._store.activeText;t&&(t.isEmpty?this.deleteObject(t.id):t.save())}resetActiveShape(){const t=this._store.activeShape;t&&t.save()}getObjectFromPointerEvent(t,n=".object"){const e=this._store.state.host?.shadowRoot;if(!e)return null;const r=t.clientX,i=t.clientY,s=e.elementFromPoint(r,i);if(!s)return null;const o=s.closest(n);if(o){const t=this._store.allObjects.find((t=>o.id===t.id)),n=t?.hitTest(r,i);return n?t:null}return null}getObjectsFromPointerEvent(t,n=".object"){const e=this._store.state.host?.shadowRoot;if(!e)return[];const r=e.elementsFromPoint(t.clientX,t.clientY);if(!r||0===r.length)return[];const i=new Set;return r.forEach((t=>{const e=t.closest(n);e&&e.id&&i.add(e.id)})),i.size>0?this._store.allObjects.filter((t=>i.has(t.id))).sort(((t,n)=>n.zIndex-t.zIndex)):[]}getElementsAtPoint(t,n){const e=this._store.state.host?.shadowRoot;if(!e)return[];const r=e.elementsFromPoint(t.clientX,t.clientY);return r&&0!==r.length?r.filter((t=>t.matches(n))):[]}isPointerOverElement(t,n){return this.getElementsAtPoint(t,n).length>0}getCanvasPoint(t){if(!this._store.state.host)return{x:0,y:0};const n=this._store.state.host.getBoundingClientRect();return{x:(t.clientX-n.left-this._store.state.translateX)/this._store.state.scale,y:(t.clientY-n.top-this._store.state.translateY)/this._store.state.scale}}beforeWorkspaceChange(){this._kritzelEngine.viewport?.cancelPendingUpdates(),this._store.state.activeWorkspace&&this.updateWorkspaceViewport(this._store.state.translateX,this._store.state.translateY,this._store.state.scale),this.resetActiveText(),this.clearSelection(),this._store.setState("activeTool",a.getTool("selection"))}displaySelectionGroupUI(t){if(!t.isSelected)return!1;const n=this._store.selectionGroup;return n?n.objects.length>1||(1!==n.objects.length||!(n.objects[0]instanceof l)):!(t instanceof l)}displaySelectionLineUI(t){if(!(t instanceof l))return!1;const n=this._store.selectionGroup;if(!n)return t.isSelected;if(!n.isSelected)return!1;if(1===n.objects.length){const e=n.objects[0];return e instanceof l&&e.id===t.id}return!1}}const Vc=t(class extends n{get host(){return this}workspace;syncConfig;onWorkspaceChange(t){const n=this.core.store.state.activeWorkspace?.id,e=t?.id;n!==e&&(this.core.beforeWorkspaceChange(),this.core.initializeWorkspace(t))}activeTool;globalContextMenuItems;objectContextMenuItems;scaleMax=Tc;validateScaleMax(t){t>Tc?(console.warn("scaleMax cannot be greater than 1000."),this.scaleMax=Tc,this.core.store.state.scaleMax=this.scaleMax):this.core.store.state.scaleMax=t}scaleMin=Ic;validateScaleMin(t){t<Ic?(console.warn("scaleMin cannot be less than 0.0001."),this.scaleMin=Ic,this.core.store.state.scaleMin=this.scaleMin):this.core.store.state.scaleMin=t}cursorTarget;onCursorTargetChange(t){this.core.cursorManager.setTargetElement(t||document.body)}isEngineReady;activeToolChange;objectsSelectionChange;workspacesChange;longpress;objectsChange;undoStateChange;forceUpdate=0;async triggerSelectionChange(){this.objectsSelectionChange.emit()}throttledWheel=Dc.throttle((t=>{this.viewport.handleWheel(t),this.core.store.state?.activeTool?.handleWheel(t)}),16);handleWheel(t){this.core.store.isDisabled||(this.core.store.state.isContextMenuVisible&&this.hideContextMenu(),this.throttledWheel(t))}handlePointerDown(t){this.core.store.isDisabled||(_.isTouchDevice()&&h.onLongPress(t,(t=>this.longpress.emit(t))),this.host.setPointerCapture(t.pointerId),this.core.store.state.pointers.set(t.pointerId,t),this.viewport.handlePointerDown(t),this.core.store.state?.activeTool?.handlePointerDown(t))}throttledPointerMoveMulti=Dc.throttle((t=>{this.viewport.handlePointerMove(t),this.core.store.state?.activeTool?.handlePointerMove(t)}),16);handlePointerMove(t){this.core.store.isDisabled||(this.core.store.state.pointers.has(t.pointerId)&&this.core.store.state.pointers.set(t.pointerId,t),this.core.store.state.pointers.size>1&&this.throttledPointerMoveMulti(t),this.core.cursorManager.updateHoverState(t),this.viewport.handlePointerMove(t),this.core.store.state?.activeTool?.handlePointerMove(t))}handlePointerUp(t){this.core.store.isDisabled||(this.core.store.state.pointers.delete(t.pointerId),this.host.releasePointerCapture(t.pointerId),0===this.core.store.state.pointers.size&&this.core.cursorManager.resetToDefault(),this.viewport.handlePointerUp(t),this.core.store.state?.activeTool?.handlePointerUp(t))}handlePointerCancel(t){this.core.store.isDisabled||(this.host.releasePointerCapture(t.pointerId),this.core.store.state.pointers.delete(t.pointerId),0===this.core.store.state.pointers.size&&this.core.cursorManager.resetToDefault(),this.viewport.handlePointerUp(t),this.core.store.state?.activeTool?.handlePointerUp(t))}handleLongPress(t){this.contextMenuHandler.handleContextMenu(t.detail)}handleContextMenu(t){t.preventDefault(),this.core.store.isDisabled||"touch"!==t.pointerType&&this.contextMenuHandler.handleContextMenu(t)}handleResize(){this.viewport.handleResize()}handleKeyDown(t){this.core.store.isDisabled||this.keyHandler.handleKeyDown(t)}handleKeyUp(t){this.core.store.isDisabled||this.keyHandler.handleKeyUp(t)}preventDoubleTapZoomOnTouchDevices(t){t.preventDefault()}async registerTool(t,n,e){if("function"!=typeof n||!(n.prototype instanceof c))return console.error(`Failed to register tool "${t}": Tool class must be a constructor function`),null;const r=a.registerTool(t,n,this.core);return e&&Object.entries(e).forEach((([t,n])=>{r[t]=n})),Promise.resolve(r)}async changeActiveTool(t){this.core.store.state.activeTool!==t&&(this.core.store.state.activeTool?.onDeactivate(),this.core.store.setState("activeTool",t),this.core.deselectAllObjects(),t?.onActivate())}async disable(){this.core.store.state.isEnabled=!1,this.core.rerender()}async enable(){this.core.store.state.isEnabled=!0,this.core.rerender()}async delete(){this.core.delete()}async copy(){this.core.copy()}async paste(t,n){this.core.paste(t,n)}async bringForward(t){this.core.bringForward(t)}async sendBackward(t){this.core.sendBackward(t)}async bringToFront(t){this.core.bringToFront(t)}async sendToBack(t){this.core.sendToBack(t)}async group(){this.core.group()}async ungroup(){this.core.ungroup()}async undo(){this.core.undo()}async redo(){this.core.redo()}async hideContextMenu(){this.core.store.state.pointers.clear(),this.core.store.state.isContextMenuVisible=!1,this.core.store.state.objects.remove((t=>t instanceof d)),this.core.store.state.isSelecting=!1,this.core.store.state.isEnabled=!0,this.core.rerender()}async getObjectById(t){return this.core.store.allObjects.find((n=>n.id===t))||null}async addObject(t){return this.core.deselectAllObjects(),t.id=t.generateId(),t._core=this.core,t.scale=t.scale?t.scale:this.core.store.state.scale,t.zIndex=this.core.store.currentZIndex,this.core.addObject(t),this.core.rerender(),t}async updateObject(t,n){return this.core.deselectAllObjects(),this.core.updateObject(t,n),this.core.rerender(),t}async removeObject(t){return this.core.deselectAllObjects(),this.core.store.state.objects.remove((n=>n.id===t.id)),this.core.rerender(),t}async getSelectedObjects(){const t=this.core.store.selectionGroup;return t?t.objects:[]}async selectObjects(t){this.core.store.state.activeTool?.onDeactivate(),this.core.store.setState("activeTool",a.getTool("selection")),this.core.deselectAllObjects(),this.core.selectObjects(t)}async selectAllObjectsInViewport(){this.core.store.state.activeTool?.onDeactivate(),this.core.store.setState("activeTool",a.getTool("selection")),this.core.deselectAllObjects(),this.core.selectAllObjectsInViewport()}async clearSelection(){this.core.clearSelection()}async centerObjectInViewport(t){return t.centerInViewport(),this.core.updateObject(t,t),this.core.rerender(),t}async getCopiedObjects(){return this.core.store.state.copiedObjects||[]}async createWorkspace(t){return await this.core.createWorkspace(t),this.workspacesChange.emit(this.core.store.state.workspaces),t}async updateWorkspace(t){await this.core.updateWorkspace(t),this.workspacesChange.emit(this.core.store.state.workspaces)}async deleteWorkspace(t){await this.core.deleteWorkspace(t),this.workspacesChange.emit(this.core.store.state.workspaces)}async getWorkspaces(){return await this.core.getWorkspaces()}async getActiveWorkspace(){return this.core.store.state.activeWorkspace}core;viewport;contextMenuHandler;keyHandler;contextMenuElement=null;get isSelecting(){return this.core.store.state.activeTool instanceof w&&this.core.store.state.isSelecting}get isSelectionActive(){return this.core.store.state.activeTool instanceof w&&null!==this.core.store.selectionGroup}constructor(t){super(),!1!==t&&this.__registerHost(),this.__attachShadow(),this.isEngineReady=e(this,"isEngineReady"),this.activeToolChange=e(this,"activeToolChange"),this.objectsSelectionChange=e(this,"objectsSelectionChange"),this.workspacesChange=e(this,"workspacesChange"),this.longpress=e(this,"longpress"),this.objectsChange=e(this,"objectsChange"),this.undoStateChange=e(this,"undoStateChange"),this.core=new Hc(this)}disconnectedCallback(){this.throttledWheel.cancel(),this.throttledPointerMoveMulti.cancel(),this.core.cursorManager.cleanup()}componentWillLoad(){this.validateScaleMax(this.scaleMax),this.validateScaleMin(this.scaleMin)}async componentDidLoad(){this.contextMenuHandler=new Bc(this.core,this.globalContextMenuItems,this.objectContextMenuItems),this.keyHandler=new Rc(this.core),this.viewport=new Pc(this.core,this.host),this.core.cursorManager.setTargetElement(this.cursorTarget||document.body),this.core.cursorManager.setShadowRoot(this.host.shadowRoot),this.syncConfig&&this.core.setSyncConfig(this.syncConfig),await this.core.initializeYjs(),await this.core.initializeWorkspace(this.workspace),this.core.appStateMap.onRemoteChange((()=>{this.workspacesChange.emit(this.core.store.state.workspaces)})),this._registerStateChangeListeners(),!1===this.core.store.state.isReady&&(this.core.store.state.isReady=!0,this.isEngineReady.emit(this.core.store.state))}emitObjectsChange(){const t=this.core.store.state.objects.undoState;this.objectsChange.emit(this.core.store.allObjects),this.undoStateChange.emit(t)}_registerStateChangeListeners(){this.core.store.onStateChange("activeTool",this._handleActiveToolChange.bind(this))}_handleActiveToolChange(t){t instanceof w||(this.core.clearSelection(),this.core.store.state.objects.remove((t=>t instanceof d)),this.core.store.state.isSelecting=!1,this.core.store.state.isResizeHandleSelected=!1,this.core.store.state.isRotationHandleSelected=!1),this.core.store.state.skipContextMenu=!1,this.core.store.state.copiedObjects=null,this.activeToolChange.emit(t),S.forceHideKeyboard(),this.core.rerender()}render(){const t=window.getComputedStyle(this.host).getPropertyValue("--kritzel-selection-handle-size").trim()||"6px",n=parseFloat(t),e=2*n<14?14:n,s=this.core.store.state.viewportWidth/2+this.core.store.state.translateX,o=this.core.store.state.viewportHeight/2+this.core.store.state.translateY,u=this.core.store.state.objects.query({x:-this.core.store.state.translateX/this.core.store.state.scale,y:-this.core.store.state.translateY/this.core.store.state.scale,z:this.core.store.state.scale,width:this.core.store.state.viewportWidth/this.core.store.state.scale,height:this.core.store.state.viewportHeight/this.core.store.state.scale,depth:100}).sort(((t,n)=>t.zIndex-n.zIndex));return this.core.cursorManager.applyCursor(),r(i,{key:"49fbba9ba7044acb82cb23627bf08435f8683b80"},this.core.store.state.debugInfo.showViewportInfo&&r("div",{key:"7e18e66bdbae71ec35a6ea14bfdcd735e537a37b",class:"debug-panel"},r("div",{key:"562ff35d3803b80f3c02c075741f1c4b81ba0739"},"ActiveWorkspaceId: ",this.core.store.state?.activeWorkspace?.id),r("div",{key:"82d08ac0527017c9f3674e1d551a071b0002477e"},"ActiveWorkspaceName: ",this.core.store.state?.activeWorkspace?.name),r("div",{key:"e4e3b8c6f18714dbf141a900768b2fb78ef8ec3a"},"TranslateX: ",this.core.store.state?.translateX),r("div",{key:"68823a22db98800c7ec7b18770f38f03dd53f826"},"TranslateY: ",this.core.store.state?.translateY),r("div",{key:"4683676eca0796b927ac8c10fe9ea48770366ee5"},"ViewportWidth: ",this.core.store.state?.viewportWidth),r("div",{key:"fcbd728c4483f06cffe1e9d581399a9619b3c172"},"ViewportHeight: ",this.core.store.state?.viewportHeight),r("div",{key:"f713005a414bd05b187327b5ffa021c51f227d97"},"PointerCount: ",this.core.store.state.pointers.size),r("div",{key:"fdb4892c0b5df0a599d4e457d656ca8e71086033"},"Scale: ",this.core.store.state?.scale),r("div",{key:"7c1ceb6398ceccb891d5854a731467771d88e688"},"ActiveTool: ",this.core.store.state?.activeTool?.name),r("div",{key:"fddfb8b396ab095dd99158b32bf4c9a06745c65f"},"HasViewportChanged: ",this.core.store.state?.hasViewportChanged?"true":"false"),r("div",{key:"8b807879e83bada98ff44a9124dddc7e7f8d8516"},"IsEnabled: ",this.core.store.state?.isEnabled?"true":"false"),r("div",{key:"93827fa7bf4c27db8b3165a1d2be5d0cde5a65b6"},"IsScaling: ",this.core.store.state?.isScaling?"true":"false"),r("div",{key:"923455fb261bc9aa8d6cd22c74894e41dc6a2f93"},"IsPanning: ",this.core.store.state?.isPanning?"true":"false"),r("div",{key:"33579a767be0a80bed4a177da9577e6304d4900c"},"IsSelecting: ",this.isSelecting?"true":"false"),r("div",{key:"950c340bf725d7c8c92a51c61066c1aa7d09aa41"},"IsSelectionActive: ",this.isSelectionActive?"true":"false"),r("div",{key:"2a8ce1e6d68ea030f42521b25615bf60a1a8267e"},"IsResizeHandleSelected: ",this.core.store.state.isResizeHandleSelected?"true":"false"),r("div",{key:"9fd5a4b1a842c9aa178dc98dc9a210cf7d947615"},"IsRotationHandleSelected: ",this.core.store.state.isRotationHandleSelected?"true":"false"),r("div",{key:"81f9c6f9f5c38b48db1faaa8da08476cd747e906"},"IsRotationHandleHovered: ",this.core.store.state.isRotationHandleHovered?"true":"false"),r("div",{key:"bbea182105ab1f1856d8ffe7ee6dae2c96cefbae"},"IsDrawing: ",this.core.store.state.isDrawing?"true":"false"),r("div",{key:"0e57b3b517fc6f4780a6bf8b13a18e7d595e2e91"},"IsWriting: ",this.core.store.state.isWriting?"true":"false"),r("div",{key:"5be12fd92b4ccb6890680e725aea0f29fa16eda4"},"IsPointerDown: ",this.core.store.isPointerDown?"true":"false"),r("div",{key:"51402f4730b8e482ee534bb83944c50462d895af"},"PointerX: ",this.core.store.state?.pointerX),r("div",{key:"dddf5bed76a1755aec71ae7f30eab8dd0c39fdb0"},"PointerY: ",this.core.store.state?.pointerY),r("div",{key:"367166d068f34090eb895116d8ac1ddd3ab5aaad"},"SelectedObjects: ",this.core.store.selectionGroup?.objects.length||0),r("div",{key:"e88d10e302e4ff3e8cb877a509a883e2cffcc067"},"ViewportCenter: (",s.toFixed(2),", ",o.toFixed(2),")")),r("div",{key:"12bf294a8640947230611690f71b8c8116e861f4",id:"origin",class:"origin",style:{transform:`matrix(${this.core.store.state?.scale}, 0, 0, ${this.core.store.state?.scale}, ${this.core.store.state?.translateX}, ${this.core.store.state?.translateY})`}},u?.map((t=>r("div",{key:t.id,style:{transform:t?.transformationMatrix,transformOrigin:"top left",position:"absolute",pointerEvents:this.core.store.state.isScaling?"none":"auto"}},r("svg",{xmlns:"http://www.w3.org/2000/svg",id:t.id,class:"object",style:{zIndex:t.zIndex.toString(),height:t?.totalHeight+"px",width:t?.totalWidth+"px",left:"0",top:"0",position:"absolute",transform:0!==t.rotationDegrees?`rotate(${t.rotationDegrees}deg)`:void 0,transformOrigin:0!==t.rotationDegrees?`${t.totalWidth/2}px ${t.totalHeight/2}px`:void 0,opacity:t.markedForRemoval?"0.5":t.opacity.toString(),pointerEvents:t.markedForRemoval?"none":"auto"}},Ec.isInstanceOf(t,"KritzelPath")&&r("svg",{ref:n=>t.mount(n),xmlns:"http://www.w3.org/2000/svg",style:{overflow:"visible"},viewBox:t?.viewBox},r("path",{d:t?.d,fill:t.fill,stroke:t?.stroke,"shape-rendering":t.isLowRes()?"optimizeSpeed":"auto"})),Ec.isInstanceOf(t,"KritzelLine")&&r("svg",{ref:n=>t.mount(n),xmlns:"http://www.w3.org/2000/svg",style:{overflow:"visible"},viewBox:t?.viewBox},r("defs",null,t.hasStartArrow&&r("marker",{id:t.startMarkerId,markerWidth:t.getArrowSize("start"),markerHeight:t.getArrowSize("start"),refX:0,refY:t.getArrowSize("start")/2,orient:"auto-start-reverse",markerUnits:"userSpaceOnUse"},r("path",{d:t.getArrowPath(t.arrows?.start?.style),fill:t.getArrowFill("start"),transform:`scale(${t.getArrowSize("start")/10})`})),t.hasEndArrow&&r("marker",{id:t.endMarkerId,markerWidth:t.getArrowSize("end"),markerHeight:t.getArrowSize("end"),refX:0,refY:t.getArrowSize("end")/2,orient:"auto",markerUnits:"userSpaceOnUse"},r("path",{d:t.getArrowPath(t.arrows?.end?.style),fill:t.getArrowFill("end"),transform:`scale(${t.getArrowSize("end")/10})`}))),r("path",{d:this.core.anchorManager.computeClippedLinePath(t),fill:"none",stroke:"transparent","stroke-width":Math.max(t?.strokeWidth||0,10),"stroke-linecap":"round"}),r("path",{d:this.core.anchorManager.computeClippedLinePath(t),fill:"none",stroke:t?.stroke,"stroke-width":t?.strokeWidth,"stroke-linecap":"round","marker-start":t.hasStartArrow?`url(#${t.startMarkerId})`:void 0,"marker-end":t.hasEndArrow?`url(#${t.endMarkerId})`:void 0})),r("foreignObject",{x:"0",y:"0",width:t.totalWidth.toString(),height:t.totalHeight.toString(),style:{minHeight:"0",minWidth:"0",backgroundColor:t.backgroundColor,borderColor:t.borderColor,borderWidth:t.borderWidth+"px",borderStyle:"solid",padding:t.padding+"px",overflow:"visible",display:Ec.isInstanceOf(t,"KritzelLine")||Ec.isInstanceOf(t,"KritzelPath")?"none":"block"}},Ec.isInstanceOf(t,"KritzelImage")&&r("img",{ref:n=>t.mount(n),src:t.src,style:{width:"100%",height:"100%",userSelect:"none",pointerEvents:"none",imageRendering:this.core.store.state.isScaling||this.core.store.state.isPanning?"pixelated":"auto"},draggable:!1,onDragStart:t=>t.preventDefault()}),Ec.isInstanceOf(t,"KritzelText")&&r("div",{id:"text-object",ref:n=>t.mount(n),onPointerDown:n=>t.handlePointerDown(n),onPointerMove:n=>t.handlePointerMove(n),onPointerUp:n=>t.handlePointerUp(n),style:{minWidth:t.initialWidth+"px",minHeight:t.initialHeight+"px",maxWidth:"500px",height:"auto",width:"max-content",transformOrigin:"top left",transform:`scale(${t.scaleFactor})`,backgroundColor:t.backgroundColor,overflow:"visible",textRendering:this.core.store.state.isScaling||this.core.store.state.isPanning?"optimizeSpeed":"auto"}}),Ec.isInstanceOf(t,"KritzelShape")&&r("div",{ref:n=>t.mount(n),onPointerDown:n=>t.handlePointerDown(n),onPointerMove:n=>t.handlePointerMove(n),onPointerUp:n=>t.handlePointerUp(n),style:{width:"100%",height:"100%",position:"relative",overflow:"visible"}},r("svg",{xmlns:"http://www.w3.org/2000/svg",style:{position:"absolute",top:"0",left:"0",width:"100%",height:"100%",overflow:"visible",pointerEvents:"none"},viewBox:t.viewBox,preserveAspectRatio:"none"},r("path",{d:t.getSvgPath(),fill:t.fillColor,stroke:t.strokeColor,"stroke-width":t.strokeWidth})),r("div",{ref:n=>t.mountTextEditor(n),style:{position:"absolute",top:"0",left:"0",width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",textAlign:"center",overflow:"hidden",pointerEvents:t.isEditing?"auto":"none"}})),Ec.isInstanceOf(t,"KritzelCustomElement")&&r("div",{ref:n=>t.mount(n),style:{width:"100%",height:"100%",pointerEvents:"auto",overflow:"hidden",display:"block"}}),Ec.isInstanceOf(t,"KritzelSelectionGroup")&&!this.core.displaySelectionLineUI(t)&&r("div",{ref:n=>t.mount(n),style:{width:"100%",height:"100%"}}),Ec.isInstanceOf(t,"KritzelSelectionBox")&&r("div",{ref:n=>t.mount(n),style:{width:"100%",height:"100%",backgroundColor:_.isFirefox()?t.backgroundColor:"transparent",borderWidth:_.isFirefox()?t.borderWidth+"px":"0",borderStyle:_.isFirefox()?"solid":"none",borderColor:_.isFirefox()?t.borderColor:"transparent"}}))),this.core.store.state.debugInfo.showObjectInfo&&t.isDebugInfoVisible&&r("div",{style:{pointerEvents:"none",position:"absolute",left:`${t.totalWidth}px`,top:"0",zIndex:(t.zIndex+2).toString()}},r("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"Id: ",t.id),r("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"width: ",t.width),r("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"height: ",t.height),r("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"translateX: ",t.translateX),r("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"translateY: ",t.translateY),r("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"rotationDegrees: ",t.rotationDegrees),r("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"zIndex: ",t.zIndex)),r("svg",{xmlns:"http://www.w3.org/2000/svg",style:{zIndex:(t.zIndex+1).toString(),height:t?.totalHeight.toString(),width:t?.totalWidth.toString(),left:"0",top:"0",position:"absolute",transform:`rotate(${t.rotationDegrees}deg)`,transformOrigin:`${t.totalWidth/2}px ${t.totalHeight/2}px`,overflow:"visible",pointerEvents:"none"}},this.core.displaySelectionGroupUI(t)&&r("g",{class:"selection-group-ui",style:{pointerEvents:"none"}},r("g",{class:"selection-group-borders"},r("line",{x1:"0",y1:"0",x2:t.totalWidth,y2:"0",style:{stroke:"var(--kritzel-selection-border-color, #007AFF)",strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${t.scale} / ${this.core.store.state?.scale})`,strokeLinecap:"square"}}),r("line",{x1:"0",y1:"0",x2:"0",y2:t.totalHeight,style:{stroke:"var(--kritzel-selection-border-color, #007AFF)",strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${t.scale} / ${this.core.store.state?.scale})`,strokeLinecap:"square"}}),r("line",{x1:"0",y1:t.totalHeight,x2:t.totalWidth,y2:t.totalHeight,style:{stroke:"var(--kritzel-selection-border-color, #007AFF)",strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${t.scale} / ${this.core.store.state?.scale})`,strokeLinecap:"square"}}),r("line",{x1:t.totalWidth,y1:"0",x2:t.totalWidth,y2:t.totalHeight,style:{stroke:"var(--kritzel-selection-border-color, #007AFF)",strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${t.scale} / ${this.core.store.state?.scale})`,strokeLinecap:"square"}})),!this.isSelecting&&r("g",{class:"selection-group-handles",style:{pointerEvents:"auto"}},r("circle",{class:"resize-handle top-left",cx:"0",cy:"0",r:""+n*t.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #000000)",paintOrder:"fill"}}),r("circle",{class:"resize-handle-overlay top-left",cx:"0",cy:"0",r:""+e*t.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}),r("circle",{class:"resize-handle top-right",cx:t.totalWidth,cy:"0",r:""+n*t.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #000000)",paintOrder:"fill"}}),r("circle",{class:"resize-handle-overlay top-right",cx:t.totalWidth,cy:"0",r:""+e*t.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}),r("circle",{class:"resize-handle bottom-left",cx:"0",cy:t.totalHeight,r:""+n*t.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #000000)",paintOrder:"fill"}}),r("circle",{class:"resize-handle-overlay bottom-left",cx:"0",cy:t.totalHeight,r:""+e*t.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}),r("circle",{class:"resize-handle bottom-right",cx:t.totalWidth,cy:t.totalHeight,r:""+n*t.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #000000)",paintOrder:"fill"}}),r("circle",{class:"resize-handle-overlay bottom-right",cx:t.totalWidth,cy:t.totalHeight,r:""+e*t.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}),r("line",{x1:t.totalWidth/2,y1:"0",x2:t.totalWidth/2,y2:-15*t.scale/this.core.store.state?.scale,style:{stroke:"var(--kritzel-selection-border-color, #007AFF)",strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${t.scale} / ${this.core.store.state?.scale})`}}),r("circle",{class:"rotation-handle",cx:t.totalWidth/2,cy:-15*t.scale/this.core.store.state?.scale,r:""+n*t.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #000000)",paintOrder:"fill"}}),r("circle",{class:"rotation-handle-overlay",cx:t.totalWidth/2,cy:-15*t.scale/this.core.store.state?.scale,r:""+e*t.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}))),this.core.displaySelectionLineUI(t)&&Ec.isInstanceOf(t,"KritzelLine")&&r("g",{class:"selection-line-ui",style:{pointerEvents:"none"}},r("g",{class:"selection-line-borders"},r("path",{class:"selection-line-border",d:this.core.anchorManager.computeClippedLinePath(t,!0),style:{stroke:"var(--kritzel-selection-border-color, #007AFF)",strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${t.scale} / ${this.core.store.state?.scale})`,strokeLinecap:"round",fill:"none"}})),!this.isSelecting&&r("g",{class:"selection-line-handles",style:{pointerEvents:"auto"}},r("circle",{class:"selection-line-handle start",cx:t.startX-t.x,cy:t.startY-t.y,r:""+n*t.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #000000)",paintOrder:"fill"}}),r("circle",{class:"selection-line-handle-overlay start",cx:t.startX-t.x,cy:t.startY-t.y,r:""+e*t.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}),r("circle",{class:"selection-line-handle center",cx:void 0!==t.controlX?(t.startX+2*t.controlX+t.endX)/4-t.x:(t.startX-t.x+t.endX-t.x)/2,cy:void 0!==t.controlY?(t.startY+2*t.controlY+t.endY)/4-t.y:(t.startY-t.y+t.endY-t.y)/2,r:""+n*t.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #000000)",paintOrder:"fill"}}),r("circle",{class:"selection-line-handle-overlay center",cx:void 0!==t.controlX?(t.startX+2*t.controlX+t.endX)/4-t.x:(t.startX-t.x+t.endX-t.x)/2,cy:void 0!==t.controlY?(t.startY+2*t.controlY+t.endY)/4-t.y:(t.startY-t.y+t.endY-t.y)/2,r:""+e*t.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}),r("circle",{class:"selection-line-handle end",cx:t.endX-t.x,cy:t.endY-t.y,r:""+n*t.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #000000)",paintOrder:"fill"}}),r("circle",{class:"selection-line-handle-overlay end",cx:t.endX-t.x,cy:t.endY-t.y,r:""+e*t.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}))))))),(()=>{const t=this.core.anchorManager.getAnchorLinesRenderData();return t?r("svg",{xmlns:"http://www.w3.org/2000/svg",class:"anchor-lines",style:{position:"absolute",left:"0",top:"0",width:"1px",height:"1px",pointerEvents:"none",zIndex:"9998",overflow:"visible"}},t.startAnchorViz&&r("g",{class:"anchor-line-start"},t.startAnchorViz.pathD?r("path",{d:t.startAnchorViz.pathD,style:{stroke:"var(--kritzel-snap-line-stroke, rgba(0, 0, 0, 0.3))",strokeWidth:`${t.lineStrokeWidth}`,strokeDasharray:t.dashArray,strokeLinecap:"round",fill:"none"}}):r("line",{x1:t.startAnchorViz.edgeX,y1:t.startAnchorViz.edgeY,x2:t.startAnchorViz.centerX,y2:t.startAnchorViz.centerY,style:{stroke:"var(--kritzel-snap-line-stroke, rgba(0, 0, 0, 0.3))",strokeWidth:`${t.lineStrokeWidth}`,strokeDasharray:t.dashArray,strokeLinecap:"round"}}),r("circle",{cx:t.startAnchorViz.centerX,cy:t.startAnchorViz.centerY,r:t.indicatorRadius,style:{fill:"var(--kritzel-snap-indicator-fill, rgba(0, 0, 0))",stroke:"var(--kritzel-snap-indicator-stroke, #007bff)",strokeWidth:t.indicatorStrokeWidth}})),t.endAnchorViz&&r("g",{class:"anchor-line-end"},t.endAnchorViz.pathD?r("path",{d:t.endAnchorViz.pathD,style:{stroke:"var(--kritzel-snap-line-stroke, rgba(0, 0, 0, 0.2))",strokeWidth:`${t.lineStrokeWidth}`,strokeDasharray:t.dashArray,strokeLinecap:"round",fill:"none"}}):r("line",{x1:t.endAnchorViz.edgeX,y1:t.endAnchorViz.edgeY,x2:t.endAnchorViz.centerX,y2:t.endAnchorViz.centerY,style:{stroke:"var(--kritzel-snap-line-stroke, rgba(0, 0, 0, 0.2))",strokeWidth:`${t.lineStrokeWidth}`,strokeDasharray:t.dashArray,strokeLinecap:"round"}}),r("circle",{cx:t.endAnchorViz.centerX,cy:t.endAnchorViz.centerY,r:t.indicatorRadius,style:{fill:"var(--kritzel-snap-indicator-fill, rgba(59, 130, 246, 0.3))",stroke:"var(--kritzel-snap-indicator-stroke, #007bff)",strokeWidth:t.indicatorStrokeWidth}}))):null})(),(()=>{const t=this.core.anchorManager.getSnapIndicatorRenderData();return t?r("svg",{xmlns:"http://www.w3.org/2000/svg",class:"snap-indicator",style:{position:"absolute",left:"0",top:"0",width:"1px",height:"1px",pointerEvents:"none",zIndex:"9999",overflow:"visible"}},r("g",null,t.snapLinePath?r("path",{d:t.snapLinePath,fill:"none",style:{stroke:"var(--kritzel-snap-line-stroke, rgba(0, 0, 0, 0.2))",strokeWidth:t.lineStrokeWidth,strokeDasharray:t.dashArray,strokeLinecap:"round"}}):void 0!==t.edgeX&&void 0!==t.edgeY&&r("line",{x1:t.edgeX,y1:t.edgeY,x2:t.centerX,y2:t.centerY,style:{stroke:"var(--kritzel-snap-line-stroke, rgba(0, 0, 0, 0.2))",strokeWidth:t.lineStrokeWidth,strokeDasharray:t.dashArray,strokeLinecap:"round"}}),r("circle",{cx:t.centerX,cy:t.centerY,r:t.indicatorRadius,style:{fill:"var(--kritzel-snap-indicator-fill, rgba(59, 130, 246, 0.3))",stroke:"var(--kritzel-snap-indicator-stroke, #007bff)",strokeWidth:t.indicatorStrokeWidth}}))):null})()),this.core.store.state.isContextMenuVisible&&r("kritzel-context-menu",{key:"9d17520994c59b7eca2940d1a05f4f150b790767",class:"context-menu",ref:t=>this.contextMenuElement=t,items:this.core.store.state.contextMenuItems,objects:this.core.store.selectionGroup?.objects||[],style:{position:"fixed",left:`${this.core.store.state.contextMenuX}px`,top:`${this.core.store.state.contextMenuY}px`,zIndex:"10002"},onActionSelected:t=>{t.detail.action({x:(-this.core.store.state.translateX+this.core.store.state.contextMenuX)/this.core.store.state.scale,y:(-this.core.store.state.translateY+this.core.store.state.contextMenuY)/this.core.store.state.scale},this.core.store.selectionGroup?.objects),this.hideContextMenu()},onClose:()=>this.hideContextMenu()}),this.core.store.state?.activeTool instanceof D&&!this.core.store.state.isScaling&&r("kritzel-cursor-trail",{key:"b86989f2a710324e420994f74bd8c4990cc52060",core:this.core}))}static get watchers(){return{workspace:[{onWorkspaceChange:0}],scaleMax:[{validateScaleMax:0}],scaleMin:[{validateScaleMin:0}],cursorTarget:[{onCursorTargetChange:0}]}}static get style(){return":host{display:block;position:relative;height:100%;width:100%;overflow:hidden;background-color:var(--kritzel-engine-background-color, #ffffff)}:host,:host *{touch-action:none;user-select:none}.ProseMirror{outline:none}p,h1,h2,h3,h4,h5,h6,blockquote,pre{margin:0;padding:0}.debug-panel{position:absolute;pointer-events:none;top:0;right:0}.origin{position:relative;top:0;left:0;height:0;width:0;pointer-events:none;-webkit-transform-origin:top left;-moz-transform-origin:top left;transform-origin:top left;overflow:visible}.object{overflow:visible}.PlaygroundEditorTheme__quote{margin:0;margin-left:20px;margin-bottom:10px;font-size:15px;color:rgb(101, 103, 107);border-left-color:rgb(206, 208, 212);border-left-width:4px;border-left-style:solid;padding-left:16px}"}},[513,"kritzel-engine",{workspace:[16],syncConfig:[16],activeTool:[16],globalContextMenuItems:[16],objectContextMenuItems:[16],scaleMax:[1026,"scale-max"],scaleMin:[1026,"scale-min"],cursorTarget:[16],forceUpdate:[32],triggerSelectionChange:[64],registerTool:[64],changeActiveTool:[64],disable:[64],enable:[64],delete:[64],copy:[64],paste:[64],bringForward:[64],sendBackward:[64],bringToFront:[64],sendToBack:[64],group:[64],ungroup:[64],undo:[64],redo:[64],hideContextMenu:[64],getObjectById:[64],addObject:[64],updateObject:[64],removeObject:[64],getSelectedObjects:[64],selectObjects:[64],selectAllObjectsInViewport:[64],clearSelection:[64],centerObjectInViewport:[64],getCopiedObjects:[64],createWorkspace:[64],updateWorkspace:[64],deleteWorkspace:[64],getWorkspaces:[64],getActiveWorkspace:[64]},[[0,"wheel","handleWheel"],[0,"pointerdown","handlePointerDown"],[0,"pointermove","handlePointerMove"],[0,"pointerup","handlePointerUp"],[0,"pointercancel","handlePointerCancel"],[0,"longpress","handleLongPress"],[0,"contextmenu","handleContextMenu"],[9,"resize","handleResize"],[8,"keydown","handleKeyDown"],[8,"keyup","handleKeyUp"],[4,"dblclick","preventDoubleTapZoomOnTouchDevices"]],{workspace:[{onWorkspaceChange:0}],scaleMax:[{validateScaleMax:0}],scaleMin:[{validateScaleMin:0}],cursorTarget:[{onCursorTargetChange:0}]}]);function Xc(){"undefined"!=typeof customElements&&["kritzel-engine","kritzel-context-menu","kritzel-cursor-trail","kritzel-icon"].forEach((t=>{switch(t){case"kritzel-engine":customElements.get(s(t))||customElements.define(s(t),Vc);break;case"kritzel-context-menu":customElements.get(s(t))||U();break;case"kritzel-cursor-trail":customElements.get(s(t))||O();break;case"kritzel-icon":customElements.get(s(t))||T()}}))}export{ue as A,_t as B,zt as C,vc as D,D as E,wt as F,yt as G,Sc as H,tu as I,Uc as J,$ as K,jc as L,Tc as M,Ic as N,jt as O,Xc as P,Vc as Q,cn as a,Sn as b,gi as c,xi as d,mi as e,qt as f,Mn as g,At as h,be as i,ge as j,ye as k,Hn as l,jn as m,Tt as n,Yn as o,Ln as p,oe as q,Un as r,mt as s,Jt as t,on as u,Qn as v,nn as w,Jn as x,Et as y,Gt as z}
|
|
9
|
+
*/class Pc{_core;_debounceUpdate;_debounceEndScaling;initialTouchDistance=0;startX=0;startY=0;constructor(t,n){this._core=t,this._core.store.state.host=n,this._core.store.state.viewportWidth=n.clientWidth,this._core.store.state.viewportHeight=n.clientHeight,this._core.store.state.startX=0,this._core.store.state.startY=0,this._core.store.state.translateX=0,this._core.store.state.translateY=0,this._debounceUpdate=Dc.debounce((()=>{this._core.updateWorkspaceViewport(this._core.store.state.translateX,this._core.store.state.translateY,this._core.store.state.scale)}),300),this._debounceEndScaling=Dc.debounce((()=>{this._core.store.state.isScaling=!1,this._core.rerender()}),100)}cancelPendingUpdates(){this._debounceUpdate.cancel()}handleResize(){this._core.store.state.viewportWidth=this._core.store.state.host.clientWidth,this._core.store.state.viewportHeight=this._core.store.state.host.clientHeight,this._core.store.state.hasViewportChanged=!0,this._core.rerender()}handlePointerDown(t){if("mouse"===t.pointerType){const n=t.clientX-this._core.store.offsetX,e=t.clientY-this._core.store.offsetY;t.button===o.Right&&(this._core.store.state.isPanning=!0,this._core.store.state.startX=n,this._core.store.state.startY=e)}if("touch"===t.pointerType){const t=Array.from(this._core.store.state.pointers.values());if(2===t.length){const n=this._core.store.currentPath;n&&this._core.store.state.objects.remove((t=>t.id===n.id)),this._core.store.state.isScaling=!0;const e=t[0].clientX-this._core.store.offsetX,r=t[0].clientY-this._core.store.offsetY,i=t[1].clientX-this._core.store.offsetX,s=t[1].clientY-this._core.store.offsetY;this.initialTouchDistance=Math.sqrt(Math.pow(e-i,2)+Math.pow(r-s,2)),this.startX=(e+i)/2,this.startY=(r+s)/2,this._core.rerender()}}}handlePointerMove(t){if("mouse"===t.pointerType){const n=this._core.store.state.host.getBoundingClientRect(),e=t.clientX-n.left,r=t.clientY-n.top;if(this._core.store.state.pointerX=(e-this._core.store.state.translateX)/this._core.store.state.scale,this._core.store.state.pointerY=(r-this._core.store.state.translateY)/this._core.store.state.scale,this._core.store.state.isPanning){const t=r-this._core.store.state.startY;this._core.store.state.translateX+=e-this._core.store.state.startX,this._core.store.state.translateY+=t,this._core.store.state.startX=e,this._core.store.state.startY=r,this._core.store.state.hasViewportChanged=!0,this._core.store.state.skipContextMenu=!0,this._core.rerender(),this._debounceUpdate()}}if("touch"===t.pointerType){const n=this._core.store.state.host.getBoundingClientRect(),e=t.clientY-n.top;this._core.store.state.pointerX=(t.clientX-n.left-this._core.store.state.translateX)/this._core.store.state.scale,this._core.store.state.pointerY=(e-this._core.store.state.translateY)/this._core.store.state.scale;const r=Array.from(this._core.store.state.pointers.values());if(2===r.length){const t=r[0].clientX-this._core.store.offsetX,n=r[0].clientY-this._core.store.offsetY,e=r[1].clientX-this._core.store.offsetX,i=r[1].clientY-this._core.store.offsetY,s=Math.sqrt(Math.pow(t-e,2)+Math.pow(n-i,2)),o=(t+e)/2,u=(n+i)/2,c=s/this.initialTouchDistance,h=this._core.store.state.scale*c;if(h>this._core.store.state.scaleMax||h<this._core.store.state.scaleMin)this._core.store.state.translateX=this._core.store.state.translateX+o-this.startX,this._core.store.state.translateY=this._core.store.state.translateY+u-this.startY;else{const t=(u-this._core.store.state.translateY)*(c-1);this._core.store.state.translateX=this._core.store.state.translateX+o-this.startX-(o-this._core.store.state.translateX)*(c-1),this._core.store.state.translateY=this._core.store.state.translateY+u-this.startY-t,this._core.store.state.scale=h,this.initialTouchDistance=s}this.startX=o,this.startY=u,this._core.store.state.hasViewportChanged=!0,this._core.rerender(),this._debounceUpdate()}}}handlePointerUp(t){"mouse"===t.pointerType&&this._core.store.state.isPanning&&(this._core.store.state.isPanning=!1,this._core.rerender()),"touch"===t.pointerType&&0===this._core.store.state.pointers.size&&this._debounceEndScaling()}handleWheel(t){t.preventDefault(),!0===t.ctrlKey&&Math.abs(t.deltaY)>0&&0===Math.abs(t.deltaX)&&this.handleZoom(t),t.ctrlKey||this.handlePan(t)}centerInViewport(t){const{scale:n,viewportWidth:e,viewportHeight:r}=this._core.store.state,{x:i,y:s,width:o,height:u}=t.rotatedBoundingBox,c=s+u/2;this._core.store.state.translateX=e/2-(i+o/2)*n,this._core.store.state.translateY=r/2-c*n,this._core.store.state.hasViewportChanged=!0,this._core.rerender(),this._debounceUpdate()}centerFitInViewport(t){const n=Math.min(this._core.store.state.viewportWidth/(1.1*t.rotatedBoundingBox.width),this._core.store.state.viewportHeight/(1.1*t.rotatedBoundingBox.height),this._core.store.state.scaleMax),e=Math.max(n,this._core.store.state.scaleMin);this._core.store.state.scale=e,this.centerInViewport(t)}handleZoom(t){this._core.store.state.isScaling=!0;const n=this._core.store.state.host.getBoundingClientRect(),e=t.clientX-n.left,r=t.clientY-n.top;this._core.store.state.pointerX=(e-this._core.store.state.translateX)/this._core.store.state.scale,this._core.store.state.pointerY=(r-this._core.store.state.translateY)/this._core.store.state.scale;const i=Math.max(.8,Math.min(1.2,1+-.012*t.deltaY)),s=Math.min(this._core.store.state.scaleMax,Math.max(this._core.store.state.scaleMin,this._core.store.state.scale*i)),o=s/this._core.store.state.scale,u=(e-this._core.store.state.translateX)*(o-1),c=(r-this._core.store.state.translateY)*(o-1);this._core.store.state.scale=s,this._core.store.state.translateX=this._core.store.state.translateX-u,this._core.store.state.translateY=this._core.store.state.translateY-c,this._core.store.state.hasViewportChanged=!0,this._core.rerender(),this._debounceUpdate(),this._debounceEndScaling()}handlePan(t){this._core.store.state.translateX=this._core.store.state.translateX-.8*t.deltaX,this._core.store.state.translateY=this._core.store.state.translateY-.8*t.deltaY,this._core.store.state.hasViewportChanged=!0,this._core.rerender(),this._debounceUpdate()}}class Rc extends p{shortcuts=[{key:"Escape",condition:t=>!!t.store.selectionGroup,action:t=>t.clearSelection()},{key:"Delete",condition:t=>!!t.store.selectionGroup,action:t=>t.delete()},{key:"z",ctrl:!0,action:t=>t.undo()},{key:"y",ctrl:!0,action:t=>t.redo()},{key:"s",ctrl:!0,action:()=>this.switchTool("selection")},{key:"b",ctrl:!0,action:()=>this.switchTool("brush")},{key:"e",ctrl:!0,action:()=>this.switchTool("eraser")},{key:"i",ctrl:!0,action:()=>this.switchTool("image")},{key:"x",ctrl:!0,action:()=>this.switchTool("text")},{key:"c",ctrl:!0,condition:t=>!!t.store.selectionGroup,action:t=>{t.copy(),t.rerender()}},{key:"v",ctrl:!0,condition:t=>!!t.store.state.copiedObjects&&!t.store.activeText,action:t=>t.paste()},{key:"+",ctrl:!0,condition:t=>!!t.store.selectionGroup,action:t=>t.bringForward()},{key:"-",ctrl:!0,condition:t=>!!t.store.selectionGroup,action:t=>t.sendBackward()},{key:"*",shift:!0,condition:t=>!!t.store.selectionGroup,action:t=>t.bringToFront()},{key:"_",shift:!0,condition:t=>!!t.store.selectionGroup,action:t=>t.sendToBack()},{key:"g",ctrl:!0,condition:t=>!!t.store.selectionGroup&&t.store.selectionGroup.objects.length>=2,action:t=>t.group()},{key:"G",ctrl:!0,shift:!0,condition:t=>!!t.store.selectionGroup,action:t=>t.ungroup()}];constructor(t){super(t)}switchTool(t){const n=a.getTool(t);this._core.store.setState("activeTool",n),this._core.deselectAllObjects(),n.onActivate()}handleKeyDown(t){this._core.store.state.isCtrlKeyPressed=t.ctrlKey;const n=this.shortcuts.find((n=>n.key===t.key&&!!n.ctrl===t.ctrlKey&&!!n.shift===t.shiftKey&&(!n.condition||n.condition(this._core))));n&&(t.preventDefault(),n.action(this._core))}handleKeyUp(t){this._core.store.state.isCtrlKeyPressed=t.ctrlKey}}class Bc extends p{globalContextMenuItems=[];objectContextMenuItems=[];constructor(t,n,e){super(t),this.globalContextMenuItems=n,this.objectContextMenuItems=e}handleContextMenu(t){if(!(this._core.store.state.activeTool instanceof w))return;if(this._core.store.state.skipContextMenu)return void(this._core.store.state.skipContextMenu=!1);const n=this._core.store.state.activeTool;n?.moveHandler?.cancelPendingDrag(),this._core.store.selectionBox&&(this._core.store.state.objects.remove((t=>t instanceof d)),this._core.store.state.isSelecting=!1);const e=this._core.getObjectFromPointerEvent(t,".object");if(e&&!(e instanceof v)&&!(e instanceof d)){const t=v.create(this._core);t.addOrRemove(e),t.isSelected=!0,t.rotation=e.rotation,this._core.store.state.isSelecting=!1,this._core.store.selectionGroup&&this._core.removeSelectionGroup(),this._core.addSelectionGroup(t),this._core.rerender()}this._core.store.state.contextMenuItems=this._core.store.selectionGroup?this.objectContextMenuItems:this.globalContextMenuItems;let r=t.clientX-this._core.store.offsetX,i=t.clientY-this._core.store.offsetY;const s=10;r+150>window.innerWidth-s&&(r=window.innerWidth-150-s),i+200>window.innerHeight-s&&(i=window.innerHeight-200-s),r=Math.max(s,r),i=Math.max(s,i),this._core.store.state.contextMenuX=r,this._core.store.state.contextMenuY=i,this._core.store.state.isContextMenuVisible=!0,this._core.store.state.isEnabled=!1,this._core.rerender()}}const Wc={activeWorkspace:null,activeTool:null,copiedObjects:null,objects:null,snapCandidate:null,resizeHandleType:null,lineHandleType:null,hasViewportChanged:!1,hasObjectsChanged:!1,isReady:!1,isEnabled:!0,isScaling:!1,isPanning:!1,isSelecting:!1,isResizing:!1,isResizeHandleHovered:!1,isResizeHandleSelected:!1,isRotating:!1,isRotationHandleHovered:!1,isRotationHandleSelected:!1,isLineHandleSelected:!1,isLineHandleDragging:!1,isDragging:!1,isDrawing:!1,isErasing:!1,isWriting:!1,isCtrlKeyPressed:!1,isContextMenuVisible:!1,contextMenuItems:[],contextMenuX:0,contextMenuY:0,skipContextMenu:!1,debugInfo:{showObjectInfo:!1,showViewportInfo:!1},host:null,pointerX:0,pointerY:0,scale:1,scaleMax:1,scaleMin:1,startX:0,startY:0,translateX:0,translateXMax:400,translateXMin:0,translateY:0,translateYMax:400,translateYMin:0,viewportWidth:0,viewportHeight:0,longTouchTimeout:null,longTouchDelay:300,pointers:new Map,workspaces:[],cursor:{icon:"default",iconActive:"default"}};class Lc extends u{__class__="KritzelCustomElement";element;isInteractive=!0;constructor(t){super(),t&&(this.translateX=t.translateX||0,this.translateY=t.translateY||0,this.scale=t.scale||1,this.element=t.element,this.height=t.height||0,this.width=t.width||0)}static create(t,n){const e=new Lc(n);return e._core=t,e.id=e.generateId(),e.workspaceId=t.store.state.activeWorkspace.id,e}mount(t){null!==t&&(this.isMounted&&this.elementRef===t&&this.element.parentElement===t||(this.elementRef=t,this.isMounted=!0,this.elementRef.innerHTML="",this.elementRef.appendChild(this.element)))}resize(t,n,e,r){e<=1||r<=1||(this.width=e,this.height=r,this.translateX=t,this.translateY=n,this.element&&(this.element.style.width=`${e}px`,this.element.style.height=`${r}px`),this._core.store.state.objects.update(this))}copy(){const t=Object.create(Object.getPrototypeOf(this));return Object.assign(t,this),t.id=this.generateId(),t.isMounted=!1,t.element=this.element.cloneNode(!0),t}}class Fc{_core;constructor(t){this._core=t}revive(t){if(t&&"object"==typeof t){if(t.__class__){let n;switch(t.__class__){case"KritzelPath":n=M.create(this._core).deserialize(t);break;case"KritzelLine":n=l.create(this._core).deserialize(t);break;case"KritzelText":n=x.create(this._core,t.fontSize,t.fontFamily).deserialize(t);break;case"KritzelShape":n=k.create(this._core,{shapeType:t.shapeType,fillColor:t.fillColor,strokeColor:t.strokeColor,strokeWidth:t.strokeWidth,fontSize:t.fontSize,fontFamily:t.fontFamily,fontColor:t.fontColor}).deserialize(t);break;case"KritzelImage":n=$.create(this._core).deserialize(t);break;case"KritzelCustomElement":n=Lc.create(this._core).deserialize(t);break;case"KritzelSelectionGroup":n=v.create(this._core).deserialize(t);break;case"KritzelGroup":n=A.create(this._core).deserialize(t);break;case"KritzelWorkspace":n=I.create(this._core,t).deserialize(t);break;case"KritzelBrushTool":n=new m(this._core);break;case"KritzelEraserTool":n=new D(this._core);break;case"KritzelImageTool":n=new wt(this._core);break;case"KritzelSelectionTool":n=new w(this._core);break;case"KritzelTextTool":n=new b(this._core);break;case"KritzelLineTool":n=new g(this._core);break;case"KritzelShapeTool":n=new y(this._core);break;default:n=t}return n}const n=Array.isArray(t)?[]:{};for(const e in t)Object.prototype.hasOwnProperty.call(t,e)&&(n[e]=this.revive(t[e]));return n}return t}}class Nc{bounds;capacity;objects=[];children=null;constructor(t,n=16){this.bounds=t,this.capacity=n}reset(){this.objects=[],this.children=null}insert(t){if(!this.intersects(t.rotatedBoundingBox,this.bounds))return!1;if(this.objects.length<this.capacity&&null===this.children)return this.objects.push(t),!0;null===this.children&&this.subdivide();for(const n of this.children)if(n.insert(t))return!0;return!1}update(t){const n=this.objects.findIndex((n=>n.id===t.id));if(-1!==n)return this.objects[n]=t,!0;if(null!==this.children)for(const n of this.children)if(n.update(t))return!0;return!1}remove(t){const n=this.objects.findIndex((n=>t(n)));if(-1!==n&&this.objects.splice(n,1),null!==this.children)for(const n of this.children)n.remove(t)}query(t){const n=[];if(!this.intersects(t,this.bounds))return n;for(const e of this.objects)this.intersects(e.rotatedBoundingBox,t)&&n.push(e);if(null!==this.children)for(const e of this.children)n.push(...e.query(t));return n}filter(t){const n=this.objects.filter((n=>t(n)));if(null!==this.children)for(const e of this.children)n.push(...e.filter(t));return n}allObjects(){const t=[...this.objects];if(null!==this.children)for(const n of this.children)t.push(...n.allObjects());return t}subdivide(){const{x:t,y:n,z:e,width:r,height:i}=this.bounds,s=r/2,o=i/2;this.children=[new Nc({x:t,y:n,z:e,width:s,height:o},this.capacity),new Nc({x:t+s,y:n,z:e,width:s,height:o},this.capacity),new Nc({x:t,y:n+o,z:e,width:s,height:o},this.capacity),new Nc({x:t+s,y:n+o,z:e,width:s,height:o},this.capacity)]}intersects(t,n){return!(t.x>=n.x+n.width||t.x+t.width<=n.x||t.y>=n.y+n.height||t.y+t.height<=n.y)}}class Kc{quadtree;_ydoc=null;_objectsMap=null;_providers=[];_undoManager=null;_reviver=null;_core=null;_workspaceId=null;_isReady=!1;_temporaryItemsCount=0;get isReady(){return this._isReady}get undoManager(){return this._undoManager}get workspaceId(){return this._workspaceId}get undoState(){return{canUndo:!!this._undoManager&&this._undoManager.canUndo(),canRedo:!!this._undoManager&&this._undoManager.canRedo(),undoStackSize:this._undoManager?this._undoManager.undoStack.length:0,redoStackSize:this._undoManager?this._undoManager.redoStack.length:0}}constructor(){this.quadtree=new Nc({x:-1/0,y:-1/0,z:0,width:1/0,height:1/0},8)}async initialize(t,n,e){this._core=t,this._workspaceId=n,this._reviver=new Fc(t),this._ydoc=new ui,this._objectsMap=this._ydoc.getMap("objects");const r=`kritzel-workspace-${n}`,i=e??Cc;for(const t of i.providers){let n;n="function"==typeof t?new t(r,this._ydoc):t.create(r,this._ydoc),this._providers.push(n)}this._undoManager=new ts([this._objectsMap],{captureTimeout:200,trackedOrigins:new Set(["local","temporary"]),ignoreRemoteMapChanges:!0}),this._undoManager.on("stack-item-added",(t=>{"undo"===t.type&&"temporary"===t.origin&&this._temporaryItemsCount++})),this._undoManager.on("stack-item-popped",(t=>{"undo"===t.type&&"temporary"===t.origin&&this._temporaryItemsCount>0&&this._temporaryItemsCount--})),this._objectsMap.observe((t=>{this.handleObjectsChange(t)})),await Promise.all(this._providers.map((t=>t.connect()))),this._isReady=!0,this.loadFromYjs()}handleObjectsChange(t){if("local"===t.transaction.origin||"temporary"===t.transaction.origin)return void this._core?.rerender();const n=Array.from(t.keysChanged),e=[],r=[],i=[];n.forEach((n=>{const s=t.changes.keys.get(n);if(s&&"delete"===s.action)i.push(n);else{const t=this._objectsMap.get(n);if(t){const n=this._reviver.revive(t);n instanceof v?r.push(n):e.push(n)}}})),i.forEach((t=>{this.quadtree.remove((n=>n.id===t))})),e.forEach((t=>{const n=this.quadtree.filter((n=>n.id===t.id)).length>0;n?this.quadtree.update(t):this.quadtree.insert(t)})),r.forEach((t=>{const n=this.quadtree.filter((n=>n.id===t.id)).length>0;n?this.quadtree.update(t):this.quadtree.insert(t)})),this._core?.rerender()}transaction(t){this._ydoc&&this._ydoc.transact(t,"local")}loadFromYjs(){this._objectsMap&&this._reviver&&(this.quadtree.reset(),this._objectsMap.forEach((t=>{const n=this._reviver.revive(t);this.quadtree.insert(n)})))}reset(){this.quadtree.reset(),this._ydoc.transact((()=>{this._objectsMap.clear()}),"local")}insert(t){if(!t.id)return!1;if(this.quadtree.insert(t),this._objectsMap&&this.isPersistable(t)){const n=t.serialize();this._ydoc.transact((()=>{this._objectsMap.set(t.id,n)}),"local")}return!0}update(t,n={}){if(!t.id)return!1;const e=this.quadtree.filter((n=>n.id===t.id)).length>0;if(!e)return!1;if(this.quadtree.update(t),this._objectsMap&&this.isPersistable(t)){const e=t.serialize();this._ydoc.transact((()=>{this._objectsMap.set(t.id,e)}),n.temporary?"temporary":"local")}return!0}remove(t){const n=this.quadtree.filter(t);for(const t of n)this.quadtree.remove((n=>n.id===t.id)),this._objectsMap&&this.isPersistable(t)&&this._ydoc.transact((()=>{this._objectsMap.delete(t.id)}),"local")}filter(t){return this.quadtree.filter(t)}allObjects(){return this.quadtree.allObjects()}query(t){return this.quadtree.query(t)}isPersistable(t){return!(t instanceof d)}undo(){this._undoManager&&this._undoManager.canUndo()&&(this._undoManager.undo(),this._core.engine.emitObjectsChange())}redo(){this._undoManager&&this._undoManager.canRedo()&&(this._undoManager.redo(),this._core.engine.emitObjectsChange())}canUndo(){return!!this._undoManager&&this._undoManager.canUndo()}canRedo(){return!!this._undoManager&&this._undoManager.canRedo()}clearHistory(){this._undoManager&&(this._undoManager.clear(),this._temporaryItemsCount=0)}consolidateTemporaryItems(){if(!this._undoManager||0===this._temporaryItemsCount)return;const t=this._undoManager.undoStack.length;if(0===t)return void(this._temporaryItemsCount=0);this._undoManager.stopCapturing();const n=Math.min(this._temporaryItemsCount,t);if(n>1){for(let t=0;t<n;t++)this._undoManager.canUndo()&&this._undoManager.undo();this._ydoc.transact((()=>{for(let t=n-1;t>=0;t--)this._undoManager.canRedo()&&this._undoManager.redo()}),"local")}this._temporaryItemsCount=0}clearTemporaryItems(){if(!this._undoManager||0===this._temporaryItemsCount)return;const t=Math.min(this._temporaryItemsCount,this._undoManager.undoStack.length);for(let n=0;n<t;n++)this._undoManager.undoStack.length>0&&this._undoManager.undoStack.pop();this._temporaryItemsCount=0}destroy(){this._providers.forEach((t=>t.destroy())),this._providers=[],this._ydoc&&this._ydoc.destroy()}}class Qc{_state;_listeners=new Map;get state(){return this._state}get currentZIndex(){return Math.max(0,...this._state.objects.filter((t=>!(t instanceof v||t instanceof d))).map((t=>t.zIndex)))+1}get allObjects(){return this._state.objects.allObjects()}get allNonSelectionObjects(){return this._state.objects.allObjects().filter((t=>!(t instanceof v||t instanceof d)))}get selectedObjects(){return this.allObjects.filter((t=>!(t instanceof v))).filter((t=>t.isSelected))}get selectionBox(){const t=this._state.objects.filter((t=>t instanceof d));return t.length>0?t[0]:null}get selectionGroup(){const t=this._state.objects.filter((t=>t instanceof v));return t.length>0?t[0]:null}get activeText(){const t=this._state.objects.filter((t=>t instanceof x&&t.isEditing));return t.length>0?t[0]:null}get activeShape(){const t=this._state.objects.filter((t=>t instanceof k&&t.isEditing));return t.length>0?t[0]:null}get currentPath(){const t=this._state.objects.filter((t=>t instanceof M&&!1===t.isCompleted));return t.length>0?t[0]:null}get currentLine(){const t=this._state.objects.filter((t=>t instanceof l&&!1===t.isCompleted));return t.length>0?t[0]:null}get offsetX(){return this._state.host.getBoundingClientRect().left}get offsetY(){return this._state.host.getBoundingClientRect().top}get isDisabled(){return!1===this._state.isEnabled||!1===this._state.isReady||null===this._state.activeWorkspace}get isPointerDown(){return this._state.pointers.size>0}constructor(t){this._state=t,this._state.objects=new Kc}onStateChange(t,n){this._listeners.has(t)||this._listeners.set(t,new Set),this._listeners.get(t).add(n)}getState(t){return this._state[t]}setState(t,n){const e=this._state[t];e!==n&&(this._state[t]=n,this._listeners.has(t)&&this._listeners.get(t).forEach((r=>r(n,e,String(t)))))}}class Yc{_core;_targetElement=null;_shadowRoot=null;constructor(t){this._core=t}setTargetElement(t){this._targetElement&&(this._targetElement.style.cursor="",this._targetElement.style.removeProperty("--kritzel-pointer-cursor")),this._targetElement=t,this._targetElement&&this._targetElement.style.setProperty("--kritzel-pointer-cursor",yt.getPointerCursor())}getTargetElement(){return this._targetElement}setShadowRoot(t){this._shadowRoot=t}resetToDefault(){this._core.store.state.cursor={icon:"default",iconActive:"default"}}updateHoverState(t){if(this._core.store.isPointerDown)return;if(!this._shadowRoot)return;const n=this._shadowRoot.elementsFromPoint(t.clientX,t.clientY);if(!n||0===n.length)return;const e=n.find((t=>t.classList.contains("resize-handle-overlay")));if(e){const t=this._core.store.selectionGroup,n=t?.rotationDegrees??0,r=e.classList.contains("top-left"),i=e.classList.contains("bottom-right");this._core.store.state.cursor={icon:"move-vertical",rotation:n+(r||i?-45:45)}}else this._core.store.state.cursor=n.find((t=>t.classList.contains("rotation-handle-overlay")))||n.find((t=>t.classList.contains("selection-line-handle-overlay")))?{icon:"hand",iconActive:"hand-grab"}:{icon:"default",iconActive:"default"}}applyCursor(){const t=this._core.store.state,n=this._core.store.isPointerDown,e=t.cursor?.icon,r=t.cursor?.iconActive??e,i=t.cursor?.rotation,s=yt.getCursor({iconName:n?r:e,rotation:i});this._targetElement&&(this._targetElement.style.cursor=s)}cleanup(){this._targetElement&&(this._targetElement.style.cursor="",this._targetElement.style.removeProperty("--kritzel-pointer-cursor")),this._targetElement=null,this._shadowRoot=null}}class Hc{_kritzelEngine;_store;_syncConfig;_appStateMap;_anchorManager;_cursorManager;get engine(){return this._kritzelEngine}get store(){return this._store}get appStateMap(){return this._appStateMap}get anchorManager(){return this._anchorManager}get cursorManager(){return this._cursorManager}constructor(t){this._kritzelEngine=t,this._store=new Qc(Wc),this._appStateMap=new Uc,this._anchorManager=new jc(this),this._cursorManager=new Yc(this)}setSyncConfig(t){this._syncConfig=t}async initializeYjs(){await this._appStateMap.initialize(this,this._syncConfig)}loadWorkspacesFromAppState(){return this._appStateMap.allWorkspaces()}saveWorkspaceToAppState(t){this._appStateMap.has(t.id)?this._appStateMap.update(t):this._appStateMap.insert(t)}deleteWorkspaceFromAppState(t){this._appStateMap.remove((n=>n.id===t))}async initializeWorkspace(t){const n=this.loadWorkspacesFromAppState(),e=n.length>0?[...n].sort(((t,n)=>n.updatedAt.getTime()-t.updatedAt.getTime()))[0]:null,r=localStorage.getItem("kritzel-active-workspace-id"),i=r?n.find((t=>t.id===r)):null;let s;t?(s=t,n.find((n=>n.id===t.id))||(s._core=this,this.saveWorkspaceToAppState(s))):i?s=i:e?s=e:(s=new I(E.generateUUID(),"New Workspace"),s._core=this,this.saveWorkspaceToAppState(s)),localStorage.setItem("kritzel-active-workspace-id",s.id),this._store.state.objects&&this._store.state.objects.isReady&&this._store.state.objects.destroy();const o=new Kc;this._store.state.objects=o,this._store.state.activeWorkspace=s,this._store.state.workspaces=this.loadWorkspacesFromAppState();const u=s.viewport??{translateX:0,translateY:0,scale:1};this._store.state.translateX=u.translateX??0,this._store.state.translateY=u.translateY??0,this._store.state.scale=u.scale??1,await o.initialize(this,s.id,this._syncConfig),this._anchorManager.rebuildIndex(),this.engine.emitObjectsChange(),this.rerender()}rerender(){this._kritzelEngine&&this._kritzelEngine.forceUpdate++}findObjectById(t){for(const n of this._store.allObjects)if(n.id===t)return n;return null}getWorkspaces(){return this.loadWorkspacesFromAppState()}createWorkspace(t){t._core=this,t.createdAt=new Date,t.updatedAt=new Date,this.saveWorkspaceToAppState(t),this._store.state.workspaces=this.loadWorkspacesFromAppState()}updateWorkspace(t){t.updatedAt=new Date,this.saveWorkspaceToAppState(t);const n=this._store.state.workspaces,e=n.findIndex((n=>n.id===t.id));-1!==e&&(n[e]=t,this._store.state.workspaces=n)}deleteWorkspace(t){this._store.state.activeWorkspace?.id===t.id&&this._store.state.objects?.destroy(),this.deleteWorkspaceFromAppState(t.id),this._store.state.workspaces=this.loadWorkspacesFromAppState(),window.indexedDB.deleteDatabase(`kritzel-workspace-${t.id}`)}updateWorkspaceViewport(t,n,e){const r=this._store.state.activeWorkspace;r&&(r.viewport={translateX:t,translateY:n,scale:e},r.updatedAt=new Date,this.saveWorkspaceToAppState(r))}addObject(t){this._store.state.objects.insert(t)}removeObject(t,n=!1){t instanceof A&&!n&&[...t.children].forEach((t=>{this.removeObject(t)})),t instanceof l?this._anchorManager.handleLineDeleted(t.id):this._anchorManager.handleObjectDeleted(t.id),t.isMounted=!1,this._store.state.objects.remove((n=>n.id===t.id))}updateObject(t,n){for(const e in n)n.hasOwnProperty(e)&&(t[e]=n[e]);this._store.state.objects.update(t)}addSelectionGroup(t){this.removeSelectionGroup(),this.removeSelectionBox(),this._store.state.objects.insert(t),this._kritzelEngine.triggerSelectionChange()}removeSelectionGroup(){const t=this._store.selectionGroup;t&&(this._store.state.objects.remove((n=>n.id===t.id)),this._kritzelEngine.triggerSelectionChange())}removeSelectionBox(){const t=this._store.selectionBox;t&&this._store.state.objects.remove((n=>n.id===t.id))}deselectAllObjects(){this.removeSelectionGroup(),this.rerender()}delete(){const t=this._store.selectionGroup;t&&(t.objects.forEach((t=>this.removeObject(t))),this.removeSelectionGroup(),this.rerender())}undo(){this._store.state.objects?.undo()}redo(){this._store.state.objects?.redo()}deleteObject(t){const n=this.findObjectById(t);n&&(this.removeObject(n),this.rerender())}copy(){const t=this._store.selectionGroup;if(t){const n=new Map,e=t.objects.sort(((t,n)=>t.zIndex-n.zIndex)).map((t=>{const e=t.copy();return n.set(e.id,t.id),e}));this._store.state.copiedObjects=e,this._store.state.copiedObjectIdMapping=n}}paste(t,n){const e=this._store.state.copiedObjects;if(!e||0===e.length)return;const r=this._store.state.activeWorkspace,i=this._store.state.copiedObjectIdMapping,s=e.some((t=>t.workspaceId!==r.id)),o=Math.min(...e.map((t=>t.translateX))),u=Math.min(...e.map((t=>t.translateY)));let c,h;void 0!==t&&void 0!==n?(c=t,h=n):s?(c=o,h=u):(c=o+25/this._store.state.scale,h=u+25/this._store.state.scale);const f=c-o,d=h-u;this.removeSelectionGroup(),this.removeSelectionBox();const p=v.create(this),w=new Map;i&&i.forEach(((t,n)=>{w.set(t,n)})),e.forEach(((t,n)=>{if(t.workspaceId!==r.id&&(t.workspaceId=r.id),t.updatePosition(t.translateX+f,t.translateY+d),t.zIndex=this._store.currentZIndex+n,t instanceof A){const e=t._pendingChildren;e&&(e.forEach(((t,e)=>{t.workspaceId!==r.id&&(t.workspaceId=r.id),t.updatePosition(t.translateX+f,t.translateY+d),t.zIndex=this._store.currentZIndex+n+e,this.addObject(t)})),delete t._pendingChildren,t.finalize())}this.addObject(t),p.addOrRemove(t)})),e.forEach((t=>{if(t instanceof l){let n=!1;t.startAnchor&&w.has(t.startAnchor.objectId)&&(t.startAnchor={objectId:w.get(t.startAnchor.objectId)},n=!0),t.endAnchor&&w.has(t.endAnchor.objectId)&&(t.endAnchor={objectId:w.get(t.endAnchor.objectId)},n=!0),n&&this._store.state.objects.update(t)}})),this._anchorManager.rebuildIndex(),p.isSelected=!0,1===e.length&&(p.rotation=e[0].rotation),this.addSelectionGroup(p),s&&(void 0!==t&&void 0!==n?p.updatePosition(t,n):p.centerInViewport(),this.engine.viewport.centerFitInViewport(p)),this._store.state.isSelecting=!1;const y=this._store.selectionGroup;if(y){const t=new Map,n=y.objects.sort(((t,n)=>t.zIndex-n.zIndex)).map((n=>{const e=n.copy();return t.set(e.id,n.id),e}));this._store.state.copiedObjects=n,this._store.state.copiedObjectIdMapping=t}this._store.setState("activeTool",a.getTool("selection")),this.engine.emitObjectsChange(),this.rerender()}bringForward(t){const n=this._store.selectionGroup,e=t?[t]:n?.objects||[],r=this._store.allNonSelectionObjects.filter((t=>-1===e.findIndex((n=>n.id===t.id)))),i=r.length>0?Math.max(...r.map((t=>t.zIndex)))+1:0;e.forEach((t=>{t.zIndex!==i&&this.updateObject(t,{zIndex:t.zIndex+1})})),this.rerender()}sendBackward(t){const n=this._store.selectionGroup,e=t?[t]:n?.objects||[],r=this._store.allNonSelectionObjects.filter((t=>-1===e.findIndex((n=>n.id===t.id)))),i=r.length>0?Math.min(...r.map((t=>t.zIndex)))-1:0;e.forEach((t=>{t.zIndex!==i&&this.updateObject(t,{zIndex:t.zIndex-1})})),this.rerender()}bringToFront(t){const n=this._store.selectionGroup,e=t?[t]:n?.objects||[],r=this._store.allNonSelectionObjects.filter((t=>-1===e.findIndex((n=>n.id===t.id)))),i=Math.max(...r.map((t=>t.zIndex)))+1;e.forEach((t=>{this.updateObject(t,{zIndex:i})})),this.rerender()}sendToBack(t){const n=this._store.selectionGroup,e=t?[t]:n?.objects||[],r=this._store.allNonSelectionObjects.filter((t=>-1===e.findIndex((n=>n.id===t.id)))),i=Math.min(...r.map((t=>t.zIndex)))-1;e.forEach((t=>{this.updateObject(t,{zIndex:i})})),this.rerender()}group(){const t=this._store.selectionGroup;if(!t||t.objects.length<2)return;const n=A.createFromObjects(this,t.objects);this.addObject(n),this.removeSelectionGroup();const e=v.create(this);e.addOrRemove(n),e.isSelected=!0,e.rotation=n.rotation,this.addSelectionGroup(e),this.engine.emitObjectsChange(),this.rerender()}ungroup(){const t=this._store.selectionGroup;if(!t)return;const n=t.objects.filter((t=>t instanceof A));if(0===n.length)return;const e=[],r=t.objects.filter((t=>!(t instanceof A)));n.forEach((t=>{const n=t.ungroup();e.push(...n),this.removeObject(t,!0)})),this.removeSelectionGroup();const i=v.create(this);[...e,...r].forEach((t=>{i.addOrRemove(t)})),i.isSelected=!0,this.addSelectionGroup(i),this.engine.emitObjectsChange(),this.rerender()}selectObjects(t){if(0===t.length)return;const n=v.create(this);t.forEach((t=>{t.isSelected=!1,n.addOrRemove(t)})),n.isSelected=!0,1===t.length&&(n.rotation=n.objects[0].rotation),this.addSelectionGroup(n),this.rerender()}selectAllObjectsInViewport(){const t=this._store.state.objects.query({x:-this._store.state.translateX/this._store.state.scale,y:-this._store.state.translateY/this._store.state.scale,z:this._store.state.scale,width:this._store.state.viewportWidth/this._store.state.scale,height:this._store.state.viewportHeight/this._store.state.scale,depth:100}).filter((t=>t.isInViewport())).filter((t=>!(t instanceof v||t instanceof d||t instanceof C)));if(t.length>0){const n=v.create(this);t.forEach((t=>{t.isSelected=!1,n.addOrRemove(t)})),n.isSelected=!0,this._store.state.isSelecting=!1,1===t.length&&(n.rotation=n.objects[0].rotation),this.addSelectionGroup(n),this._store.setState("activeTool",a.getTool("selection")),this.rerender()}}clearSelection(){this.removeSelectionGroup(),this._store.state.objects.remove((t=>t instanceof d||t instanceof v)),this._store.state.isSelecting=!1,this._store.state.isResizeHandleSelected=!1,this._store.state.isRotationHandleSelected=!1,this._store.state.isLineHandleSelected=!1,this._store.state.isLineHandleDragging=!1,this._store.state.lineHandleType=null,this.rerender()}resetActiveText(){const t=this._store.activeText;t&&(t.isEmpty?this.deleteObject(t.id):t.save())}resetActiveShape(){const t=this._store.activeShape;t&&t.save()}getObjectFromPointerEvent(t,n=".object"){const e=this._store.state.host?.shadowRoot;if(!e)return null;const r=t.clientX,i=t.clientY,s=e.elementFromPoint(r,i);if(!s)return null;const o=s.closest(n);if(o){const t=this._store.allObjects.find((t=>o.id===t.id)),n=t?.hitTest(r,i);return n?t:null}return null}getObjectsFromPointerEvent(t,n=".object"){const e=this._store.state.host?.shadowRoot;if(!e)return[];const r=e.elementsFromPoint(t.clientX,t.clientY);if(!r||0===r.length)return[];const i=new Set;return r.forEach((t=>{const e=t.closest(n);e&&e.id&&i.add(e.id)})),i.size>0?this._store.allObjects.filter((t=>i.has(t.id))).sort(((t,n)=>n.zIndex-t.zIndex)):[]}getElementsAtPoint(t,n){const e=this._store.state.host?.shadowRoot;if(!e)return[];const r=e.elementsFromPoint(t.clientX,t.clientY);return r&&0!==r.length?r.filter((t=>t.matches(n))):[]}isPointerOverElement(t,n){return this.getElementsAtPoint(t,n).length>0}getCanvasPoint(t){if(!this._store.state.host)return{x:0,y:0};const n=this._store.state.host.getBoundingClientRect();return{x:(t.clientX-n.left-this._store.state.translateX)/this._store.state.scale,y:(t.clientY-n.top-this._store.state.translateY)/this._store.state.scale}}beforeWorkspaceChange(){this._kritzelEngine.viewport?.cancelPendingUpdates(),this._store.state.activeWorkspace&&this.updateWorkspaceViewport(this._store.state.translateX,this._store.state.translateY,this._store.state.scale),this.resetActiveText(),this.clearSelection(),this._store.setState("activeTool",a.getTool("selection"))}displaySelectionGroupUI(t){if(!t.isSelected)return!1;const n=this._store.selectionGroup;return n?n.objects.length>1||(1!==n.objects.length||!(n.objects[0]instanceof l)):!(t instanceof l)}displaySelectionLineUI(t){if(!(t instanceof l))return!1;const n=this._store.selectionGroup;if(!n)return t.isSelected;if(!n.isSelected)return!1;if(1===n.objects.length){const e=n.objects[0];return e instanceof l&&e.id===t.id}return!1}}const Vc=t(class extends n{get host(){return this}workspace;syncConfig;onWorkspaceChange(t){const n=this.core.store.state.activeWorkspace?.id,e=t?.id;n!==e&&(this.core.beforeWorkspaceChange(),this.core.initializeWorkspace(t))}activeTool;globalContextMenuItems;objectContextMenuItems;scaleMax=Tc;validateScaleMax(t){t>Tc?(console.warn("scaleMax cannot be greater than 1000."),this.scaleMax=Tc,this.core.store.state.scaleMax=this.scaleMax):this.core.store.state.scaleMax=t}scaleMin=Ic;validateScaleMin(t){t<Ic?(console.warn("scaleMin cannot be less than 0.0001."),this.scaleMin=Ic,this.core.store.state.scaleMin=this.scaleMin):this.core.store.state.scaleMin=t}cursorTarget;onCursorTargetChange(t){this.core.cursorManager.setTargetElement(t||document.body)}isEngineReady;activeToolChange;objectsSelectionChange;workspacesChange;longpress;objectsChange;undoStateChange;forceUpdate=0;async triggerSelectionChange(){this.objectsSelectionChange.emit()}throttledWheel=Dc.throttle((t=>{this.viewport.handleWheel(t),this.core.store.state?.activeTool?.handleWheel(t)}),16);handleWheel(t){this.core.store.isDisabled||(this.core.store.state.isContextMenuVisible&&this.hideContextMenu(),this.throttledWheel(t))}handlePointerDown(t){this.core.store.isDisabled||(O.isTouchDevice()&&h.onLongPress(t,(t=>this.longpress.emit(t))),this.host.setPointerCapture(t.pointerId),this.core.store.state.pointers.set(t.pointerId,t),this.viewport.handlePointerDown(t),this.core.store.state?.activeTool?.handlePointerDown(t))}throttledPointerMoveMulti=Dc.throttle((t=>{this.viewport.handlePointerMove(t),this.core.store.state?.activeTool?.handlePointerMove(t)}),16);handlePointerMove(t){this.core.store.isDisabled||(this.core.store.state.pointers.has(t.pointerId)&&this.core.store.state.pointers.set(t.pointerId,t),this.core.store.state.pointers.size>1&&this.throttledPointerMoveMulti(t),this.core.cursorManager.updateHoverState(t),this.viewport.handlePointerMove(t),this.core.store.state?.activeTool?.handlePointerMove(t))}handlePointerUp(t){this.core.store.isDisabled||(this.core.store.state.pointers.delete(t.pointerId),this.host.releasePointerCapture(t.pointerId),0===this.core.store.state.pointers.size&&this.core.cursorManager.resetToDefault(),this.viewport.handlePointerUp(t),this.core.store.state?.activeTool?.handlePointerUp(t))}handlePointerCancel(t){this.core.store.isDisabled||(this.host.releasePointerCapture(t.pointerId),this.core.store.state.pointers.delete(t.pointerId),0===this.core.store.state.pointers.size&&this.core.cursorManager.resetToDefault(),this.viewport.handlePointerUp(t),this.core.store.state?.activeTool?.handlePointerUp(t))}handleLongPress(t){this.contextMenuHandler.handleContextMenu(t.detail)}handleContextMenu(t){t.preventDefault(),this.core.store.isDisabled||"touch"!==t.pointerType&&this.contextMenuHandler.handleContextMenu(t)}handleResize(){this.viewport.handleResize()}handleKeyDown(t){this.core.store.isDisabled||this.keyHandler.handleKeyDown(t)}handleKeyUp(t){this.core.store.isDisabled||this.keyHandler.handleKeyUp(t)}preventDoubleTapZoomOnTouchDevices(t){t.preventDefault()}async registerTool(t,n,e){if("function"!=typeof n||!(n.prototype instanceof c))return console.error(`Failed to register tool "${t}": Tool class must be a constructor function`),null;const r=a.registerTool(t,n,this.core);return e&&Object.entries(e).forEach((([t,n])=>{r[t]=n})),Promise.resolve(r)}async changeActiveTool(t){this.core.store.state.activeTool!==t&&(this.core.store.state.activeTool?.onDeactivate(),this.core.store.setState("activeTool",t),this.core.deselectAllObjects(),t?.onActivate())}async disable(){this.core.store.state.isEnabled=!1,this.core.rerender()}async enable(){this.core.store.state.isEnabled=!0,this.core.rerender()}async delete(){this.core.delete()}async copy(){this.core.copy()}async paste(t,n){this.core.paste(t,n)}async bringForward(t){this.core.bringForward(t)}async sendBackward(t){this.core.sendBackward(t)}async bringToFront(t){this.core.bringToFront(t)}async sendToBack(t){this.core.sendToBack(t)}async group(){this.core.group()}async ungroup(){this.core.ungroup()}async undo(){this.core.undo()}async redo(){this.core.redo()}async hideContextMenu(){this.core.store.state.pointers.clear(),this.core.store.state.isContextMenuVisible=!1,this.core.store.state.objects.remove((t=>t instanceof d)),this.core.store.state.isSelecting=!1,this.core.store.state.isEnabled=!0,this.core.rerender()}async getObjectById(t){return this.core.store.allObjects.find((n=>n.id===t))||null}async addObject(t){return this.core.deselectAllObjects(),t.id=t.generateId(),t._core=this.core,t.scale=t.scale?t.scale:this.core.store.state.scale,t.zIndex=this.core.store.currentZIndex,this.core.addObject(t),this.core.rerender(),t}async updateObject(t,n){return this.core.deselectAllObjects(),this.core.updateObject(t,n),this.core.rerender(),t}async removeObject(t){return this.core.deselectAllObjects(),this.core.store.state.objects.remove((n=>n.id===t.id)),this.core.rerender(),t}async getSelectedObjects(){const t=this.core.store.selectionGroup;return t?t.objects:[]}async selectObjects(t){this.core.store.state.activeTool?.onDeactivate(),this.core.store.setState("activeTool",a.getTool("selection")),this.core.deselectAllObjects(),this.core.selectObjects(t)}async selectAllObjectsInViewport(){this.core.store.state.activeTool?.onDeactivate(),this.core.store.setState("activeTool",a.getTool("selection")),this.core.deselectAllObjects(),this.core.selectAllObjectsInViewport()}async clearSelection(){this.core.clearSelection()}async centerObjectInViewport(t){return t.centerInViewport(),this.core.updateObject(t,t),this.core.rerender(),t}async getCopiedObjects(){return this.core.store.state.copiedObjects||[]}async createWorkspace(t){return await this.core.createWorkspace(t),this.workspacesChange.emit(this.core.store.state.workspaces),t}async updateWorkspace(t){await this.core.updateWorkspace(t),this.workspacesChange.emit(this.core.store.state.workspaces)}async deleteWorkspace(t){await this.core.deleteWorkspace(t),this.workspacesChange.emit(this.core.store.state.workspaces)}async getWorkspaces(){return await this.core.getWorkspaces()}async getActiveWorkspace(){return this.core.store.state.activeWorkspace}core;viewport;contextMenuHandler;keyHandler;contextMenuElement=null;get isSelecting(){return this.core.store.state.activeTool instanceof w&&this.core.store.state.isSelecting}get isSelectionActive(){return this.core.store.state.activeTool instanceof w&&null!==this.core.store.selectionGroup}constructor(t){super(),!1!==t&&this.__registerHost(),this.__attachShadow(),this.isEngineReady=e(this,"isEngineReady"),this.activeToolChange=e(this,"activeToolChange"),this.objectsSelectionChange=e(this,"objectsSelectionChange"),this.workspacesChange=e(this,"workspacesChange"),this.longpress=e(this,"longpress"),this.objectsChange=e(this,"objectsChange"),this.undoStateChange=e(this,"undoStateChange"),this.core=new Hc(this)}disconnectedCallback(){this.throttledWheel.cancel(),this.throttledPointerMoveMulti.cancel(),this.core.cursorManager.cleanup()}componentWillLoad(){this.validateScaleMax(this.scaleMax),this.validateScaleMin(this.scaleMin)}async componentDidLoad(){this.contextMenuHandler=new Bc(this.core,this.globalContextMenuItems,this.objectContextMenuItems),this.keyHandler=new Rc(this.core),this.viewport=new Pc(this.core,this.host),this.core.cursorManager.setTargetElement(this.cursorTarget||document.body),this.core.cursorManager.setShadowRoot(this.host.shadowRoot),this.syncConfig&&this.core.setSyncConfig(this.syncConfig),await this.core.initializeYjs(),await this.core.initializeWorkspace(this.workspace),this.core.appStateMap.onRemoteChange((()=>{this.workspacesChange.emit(this.core.store.state.workspaces)})),this._registerStateChangeListeners(),!1===this.core.store.state.isReady&&(this.core.store.state.isReady=!0,this.isEngineReady.emit(this.core.store.state))}emitObjectsChange(){const t=this.core.store.state.objects.undoState;this.objectsChange.emit(this.core.store.allObjects),this.undoStateChange.emit(t)}_registerStateChangeListeners(){this.core.store.onStateChange("activeTool",this._handleActiveToolChange.bind(this))}_handleActiveToolChange(t){t instanceof w||(this.core.clearSelection(),this.core.store.state.objects.remove((t=>t instanceof d)),this.core.store.state.isSelecting=!1,this.core.store.state.isResizeHandleSelected=!1,this.core.store.state.isRotationHandleSelected=!1),this.core.store.state.skipContextMenu=!1,this.core.store.state.copiedObjects=null,this.activeToolChange.emit(t),S.forceHideKeyboard(),this.core.rerender()}render(){const t=window.getComputedStyle(this.host).getPropertyValue("--kritzel-selection-handle-size").trim()||"6px",n=parseFloat(t),e=2*n<14?14:n,s=this.core.store.state.viewportWidth/2+this.core.store.state.translateX,o=this.core.store.state.viewportHeight/2+this.core.store.state.translateY,u=this.core.store.state.objects.query({x:-this.core.store.state.translateX/this.core.store.state.scale,y:-this.core.store.state.translateY/this.core.store.state.scale,z:this.core.store.state.scale,width:this.core.store.state.viewportWidth/this.core.store.state.scale,height:this.core.store.state.viewportHeight/this.core.store.state.scale,depth:100}).sort(((t,n)=>t.zIndex-n.zIndex));return this.core.cursorManager.applyCursor(),r(i,{key:"49fbba9ba7044acb82cb23627bf08435f8683b80"},this.core.store.state.debugInfo.showViewportInfo&&r("div",{key:"7e18e66bdbae71ec35a6ea14bfdcd735e537a37b",class:"debug-panel"},r("div",{key:"562ff35d3803b80f3c02c075741f1c4b81ba0739"},"ActiveWorkspaceId: ",this.core.store.state?.activeWorkspace?.id),r("div",{key:"82d08ac0527017c9f3674e1d551a071b0002477e"},"ActiveWorkspaceName: ",this.core.store.state?.activeWorkspace?.name),r("div",{key:"e4e3b8c6f18714dbf141a900768b2fb78ef8ec3a"},"TranslateX: ",this.core.store.state?.translateX),r("div",{key:"68823a22db98800c7ec7b18770f38f03dd53f826"},"TranslateY: ",this.core.store.state?.translateY),r("div",{key:"4683676eca0796b927ac8c10fe9ea48770366ee5"},"ViewportWidth: ",this.core.store.state?.viewportWidth),r("div",{key:"fcbd728c4483f06cffe1e9d581399a9619b3c172"},"ViewportHeight: ",this.core.store.state?.viewportHeight),r("div",{key:"f713005a414bd05b187327b5ffa021c51f227d97"},"PointerCount: ",this.core.store.state.pointers.size),r("div",{key:"fdb4892c0b5df0a599d4e457d656ca8e71086033"},"Scale: ",this.core.store.state?.scale),r("div",{key:"7c1ceb6398ceccb891d5854a731467771d88e688"},"ActiveTool: ",this.core.store.state?.activeTool?.name),r("div",{key:"fddfb8b396ab095dd99158b32bf4c9a06745c65f"},"HasViewportChanged: ",this.core.store.state?.hasViewportChanged?"true":"false"),r("div",{key:"8b807879e83bada98ff44a9124dddc7e7f8d8516"},"IsEnabled: ",this.core.store.state?.isEnabled?"true":"false"),r("div",{key:"93827fa7bf4c27db8b3165a1d2be5d0cde5a65b6"},"IsScaling: ",this.core.store.state?.isScaling?"true":"false"),r("div",{key:"923455fb261bc9aa8d6cd22c74894e41dc6a2f93"},"IsPanning: ",this.core.store.state?.isPanning?"true":"false"),r("div",{key:"33579a767be0a80bed4a177da9577e6304d4900c"},"IsSelecting: ",this.isSelecting?"true":"false"),r("div",{key:"950c340bf725d7c8c92a51c61066c1aa7d09aa41"},"IsSelectionActive: ",this.isSelectionActive?"true":"false"),r("div",{key:"2a8ce1e6d68ea030f42521b25615bf60a1a8267e"},"IsResizeHandleSelected: ",this.core.store.state.isResizeHandleSelected?"true":"false"),r("div",{key:"9fd5a4b1a842c9aa178dc98dc9a210cf7d947615"},"IsRotationHandleSelected: ",this.core.store.state.isRotationHandleSelected?"true":"false"),r("div",{key:"81f9c6f9f5c38b48db1faaa8da08476cd747e906"},"IsRotationHandleHovered: ",this.core.store.state.isRotationHandleHovered?"true":"false"),r("div",{key:"bbea182105ab1f1856d8ffe7ee6dae2c96cefbae"},"IsDrawing: ",this.core.store.state.isDrawing?"true":"false"),r("div",{key:"0e57b3b517fc6f4780a6bf8b13a18e7d595e2e91"},"IsWriting: ",this.core.store.state.isWriting?"true":"false"),r("div",{key:"5be12fd92b4ccb6890680e725aea0f29fa16eda4"},"IsPointerDown: ",this.core.store.isPointerDown?"true":"false"),r("div",{key:"51402f4730b8e482ee534bb83944c50462d895af"},"PointerX: ",this.core.store.state?.pointerX),r("div",{key:"dddf5bed76a1755aec71ae7f30eab8dd0c39fdb0"},"PointerY: ",this.core.store.state?.pointerY),r("div",{key:"367166d068f34090eb895116d8ac1ddd3ab5aaad"},"SelectedObjects: ",this.core.store.selectionGroup?.objects.length||0),r("div",{key:"e88d10e302e4ff3e8cb877a509a883e2cffcc067"},"ViewportCenter: (",s.toFixed(2),", ",o.toFixed(2),")")),r("div",{key:"12bf294a8640947230611690f71b8c8116e861f4",id:"origin",class:"origin",style:{transform:`matrix(${this.core.store.state?.scale}, 0, 0, ${this.core.store.state?.scale}, ${this.core.store.state?.translateX}, ${this.core.store.state?.translateY})`}},u?.map((t=>r("div",{key:t.id,style:{transform:t?.transformationMatrix,transformOrigin:"top left",position:"absolute",pointerEvents:this.core.store.state.isScaling?"none":"auto"}},r("svg",{xmlns:"http://www.w3.org/2000/svg",id:t.id,class:"object",style:{zIndex:t.zIndex.toString(),height:t?.totalHeight+"px",width:t?.totalWidth+"px",left:"0",top:"0",position:"absolute",transform:0!==t.rotationDegrees?`rotate(${t.rotationDegrees}deg)`:void 0,transformOrigin:0!==t.rotationDegrees?`${t.totalWidth/2}px ${t.totalHeight/2}px`:void 0,opacity:t.markedForRemoval?"0.5":t.opacity.toString(),pointerEvents:t.markedForRemoval?"none":"auto"}},Ec.isInstanceOf(t,"KritzelPath")&&r("svg",{ref:n=>t.mount(n),xmlns:"http://www.w3.org/2000/svg",style:{overflow:"visible"},viewBox:t?.viewBox},r("path",{d:t?.d,fill:t.fill,stroke:t?.stroke,"shape-rendering":t.isLowRes()?"optimizeSpeed":"auto"})),Ec.isInstanceOf(t,"KritzelLine")&&r("svg",{ref:n=>t.mount(n),xmlns:"http://www.w3.org/2000/svg",style:{overflow:"visible"},viewBox:t?.viewBox},r("defs",null,t.hasStartArrow&&r("marker",{id:t.startMarkerId,markerWidth:t.getArrowSize("start"),markerHeight:t.getArrowSize("start"),refX:0,refY:t.getArrowSize("start")/2,orient:"auto-start-reverse",markerUnits:"userSpaceOnUse"},r("path",{d:t.getArrowPath(t.arrows?.start?.style),fill:t.getArrowFill("start"),transform:`scale(${t.getArrowSize("start")/10})`})),t.hasEndArrow&&r("marker",{id:t.endMarkerId,markerWidth:t.getArrowSize("end"),markerHeight:t.getArrowSize("end"),refX:0,refY:t.getArrowSize("end")/2,orient:"auto",markerUnits:"userSpaceOnUse"},r("path",{d:t.getArrowPath(t.arrows?.end?.style),fill:t.getArrowFill("end"),transform:`scale(${t.getArrowSize("end")/10})`}))),r("path",{d:this.core.anchorManager.computeClippedLinePath(t),fill:"none",stroke:"transparent","stroke-width":Math.max(t?.strokeWidth||0,10),"stroke-linecap":"round"}),r("path",{d:this.core.anchorManager.computeClippedLinePath(t),fill:"none",stroke:t?.stroke,"stroke-width":t?.strokeWidth,"stroke-linecap":"round","marker-start":t.hasStartArrow?`url(#${t.startMarkerId})`:void 0,"marker-end":t.hasEndArrow?`url(#${t.endMarkerId})`:void 0})),r("foreignObject",{x:"0",y:"0",width:t.totalWidth.toString(),height:t.totalHeight.toString(),style:{minHeight:"0",minWidth:"0",backgroundColor:t.backgroundColor,borderColor:t.borderColor,borderWidth:t.borderWidth+"px",borderStyle:"solid",padding:t.padding+"px",overflow:"visible",display:Ec.isInstanceOf(t,"KritzelLine")||Ec.isInstanceOf(t,"KritzelPath")?"none":"block"}},Ec.isInstanceOf(t,"KritzelImage")&&r("img",{ref:n=>t.mount(n),src:t.src,style:{width:"100%",height:"100%",userSelect:"none",pointerEvents:"none",imageRendering:this.core.store.state.isScaling||this.core.store.state.isPanning?"pixelated":"auto"},draggable:!1,onDragStart:t=>t.preventDefault()}),Ec.isInstanceOf(t,"KritzelText")&&r("div",{id:"text-object",ref:n=>t.mount(n),onPointerDown:n=>t.handlePointerDown(n),onPointerMove:n=>t.handlePointerMove(n),onPointerUp:n=>t.handlePointerUp(n),style:{minWidth:t.initialWidth+"px",minHeight:t.initialHeight+"px",maxWidth:"500px",height:"auto",width:"max-content",transformOrigin:"top left",transform:`scale(${t.scaleFactor})`,backgroundColor:t.backgroundColor,overflow:"visible",textRendering:this.core.store.state.isScaling||this.core.store.state.isPanning?"optimizeSpeed":"auto"}}),Ec.isInstanceOf(t,"KritzelShape")&&r("div",{ref:n=>t.mount(n),onPointerDown:n=>t.handlePointerDown(n),onPointerMove:n=>t.handlePointerMove(n),onPointerUp:n=>t.handlePointerUp(n),style:{width:"100%",height:"100%",position:"relative",overflow:"visible"}},r("svg",{xmlns:"http://www.w3.org/2000/svg",style:{position:"absolute",top:"0",left:"0",width:"100%",height:"100%",overflow:"visible",pointerEvents:"none"},viewBox:t.viewBox,preserveAspectRatio:"none"},r("path",{d:t.getSvgPath(),fill:t.fillColor,stroke:t.strokeColor,"stroke-width":t.strokeWidth})),r("div",{ref:n=>t.mountTextEditor(n),style:{position:"absolute",top:"0",left:"0",width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",textAlign:"center",overflow:"hidden",pointerEvents:t.isEditing?"auto":"none"}})),Ec.isInstanceOf(t,"KritzelCustomElement")&&r("div",{ref:n=>t.mount(n),style:{width:"100%",height:"100%",pointerEvents:"auto",overflow:"hidden",display:"block"}}),Ec.isInstanceOf(t,"KritzelSelectionGroup")&&!this.core.displaySelectionLineUI(t)&&r("div",{ref:n=>t.mount(n),style:{width:"100%",height:"100%"}}),Ec.isInstanceOf(t,"KritzelSelectionBox")&&r("div",{ref:n=>t.mount(n),style:{width:"100%",height:"100%",backgroundColor:O.isFirefox()?t.backgroundColor:"transparent",borderWidth:O.isFirefox()?t.borderWidth+"px":"0",borderStyle:O.isFirefox()?"solid":"none",borderColor:O.isFirefox()?t.borderColor:"transparent"}}))),this.core.store.state.debugInfo.showObjectInfo&&t.isDebugInfoVisible&&r("div",{style:{pointerEvents:"none",position:"absolute",left:`${t.totalWidth}px`,top:"0",zIndex:(t.zIndex+2).toString()}},r("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"Id: ",t.id),r("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"width: ",t.width),r("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"height: ",t.height),r("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"translateX: ",t.translateX),r("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"translateY: ",t.translateY),r("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"rotationDegrees: ",t.rotationDegrees),r("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"zIndex: ",t.zIndex)),r("svg",{xmlns:"http://www.w3.org/2000/svg",style:{zIndex:(t.zIndex+1).toString(),height:t?.totalHeight.toString(),width:t?.totalWidth.toString(),left:"0",top:"0",position:"absolute",transform:`rotate(${t.rotationDegrees}deg)`,transformOrigin:`${t.totalWidth/2}px ${t.totalHeight/2}px`,overflow:"visible",pointerEvents:"none"}},this.core.displaySelectionGroupUI(t)&&r("g",{class:"selection-group-ui",style:{pointerEvents:"none"}},r("g",{class:"selection-group-borders"},r("line",{x1:"0",y1:"0",x2:t.totalWidth,y2:"0",style:{stroke:"var(--kritzel-selection-border-color, #007AFF)",strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${t.scale} / ${this.core.store.state?.scale})`,strokeLinecap:"square"}}),r("line",{x1:"0",y1:"0",x2:"0",y2:t.totalHeight,style:{stroke:"var(--kritzel-selection-border-color, #007AFF)",strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${t.scale} / ${this.core.store.state?.scale})`,strokeLinecap:"square"}}),r("line",{x1:"0",y1:t.totalHeight,x2:t.totalWidth,y2:t.totalHeight,style:{stroke:"var(--kritzel-selection-border-color, #007AFF)",strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${t.scale} / ${this.core.store.state?.scale})`,strokeLinecap:"square"}}),r("line",{x1:t.totalWidth,y1:"0",x2:t.totalWidth,y2:t.totalHeight,style:{stroke:"var(--kritzel-selection-border-color, #007AFF)",strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${t.scale} / ${this.core.store.state?.scale})`,strokeLinecap:"square"}})),!this.isSelecting&&r("g",{class:"selection-group-handles",style:{pointerEvents:"auto"}},r("circle",{class:"resize-handle top-left",cx:"0",cy:"0",r:""+n*t.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #000000)",paintOrder:"fill"}}),r("circle",{class:"resize-handle-overlay top-left",cx:"0",cy:"0",r:""+e*t.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}),r("circle",{class:"resize-handle top-right",cx:t.totalWidth,cy:"0",r:""+n*t.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #000000)",paintOrder:"fill"}}),r("circle",{class:"resize-handle-overlay top-right",cx:t.totalWidth,cy:"0",r:""+e*t.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}),r("circle",{class:"resize-handle bottom-left",cx:"0",cy:t.totalHeight,r:""+n*t.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #000000)",paintOrder:"fill"}}),r("circle",{class:"resize-handle-overlay bottom-left",cx:"0",cy:t.totalHeight,r:""+e*t.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}),r("circle",{class:"resize-handle bottom-right",cx:t.totalWidth,cy:t.totalHeight,r:""+n*t.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #000000)",paintOrder:"fill"}}),r("circle",{class:"resize-handle-overlay bottom-right",cx:t.totalWidth,cy:t.totalHeight,r:""+e*t.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}),r("line",{x1:t.totalWidth/2,y1:"0",x2:t.totalWidth/2,y2:-15*t.scale/this.core.store.state?.scale,style:{stroke:"var(--kritzel-selection-border-color, #007AFF)",strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${t.scale} / ${this.core.store.state?.scale})`}}),r("circle",{class:"rotation-handle",cx:t.totalWidth/2,cy:-15*t.scale/this.core.store.state?.scale,r:""+n*t.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #000000)",paintOrder:"fill"}}),r("circle",{class:"rotation-handle-overlay",cx:t.totalWidth/2,cy:-15*t.scale/this.core.store.state?.scale,r:""+e*t.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}))),this.core.displaySelectionLineUI(t)&&Ec.isInstanceOf(t,"KritzelLine")&&r("g",{class:"selection-line-ui",style:{pointerEvents:"none"}},r("g",{class:"selection-line-borders"},r("path",{class:"selection-line-border",d:this.core.anchorManager.computeClippedLinePath(t,!0),style:{stroke:"var(--kritzel-selection-border-color, #007AFF)",strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${t.scale} / ${this.core.store.state?.scale})`,strokeLinecap:"round",fill:"none"}})),!this.isSelecting&&r("g",{class:"selection-line-handles",style:{pointerEvents:"auto"}},r("circle",{class:"selection-line-handle start",cx:t.startX-t.x,cy:t.startY-t.y,r:""+n*t.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #000000)",paintOrder:"fill"}}),r("circle",{class:"selection-line-handle-overlay start",cx:t.startX-t.x,cy:t.startY-t.y,r:""+e*t.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}),r("circle",{class:"selection-line-handle center",cx:void 0!==t.controlX?(t.startX+2*t.controlX+t.endX)/4-t.x:(t.startX-t.x+t.endX-t.x)/2,cy:void 0!==t.controlY?(t.startY+2*t.controlY+t.endY)/4-t.y:(t.startY-t.y+t.endY-t.y)/2,r:""+n*t.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #000000)",paintOrder:"fill"}}),r("circle",{class:"selection-line-handle-overlay center",cx:void 0!==t.controlX?(t.startX+2*t.controlX+t.endX)/4-t.x:(t.startX-t.x+t.endX-t.x)/2,cy:void 0!==t.controlY?(t.startY+2*t.controlY+t.endY)/4-t.y:(t.startY-t.y+t.endY-t.y)/2,r:""+e*t.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}),r("circle",{class:"selection-line-handle end",cx:t.endX-t.x,cy:t.endY-t.y,r:""+n*t.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #000000)",paintOrder:"fill"}}),r("circle",{class:"selection-line-handle-overlay end",cx:t.endX-t.x,cy:t.endY-t.y,r:""+e*t.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}))))))),(()=>{const t=this.core.anchorManager.getAnchorLinesRenderData();return t?r("svg",{xmlns:"http://www.w3.org/2000/svg",class:"anchor-lines",style:{position:"absolute",left:"0",top:"0",width:"1px",height:"1px",pointerEvents:"none",zIndex:"9998",overflow:"visible"}},t.startAnchorViz&&r("g",{class:"anchor-line-start"},t.startAnchorViz.pathD?r("path",{d:t.startAnchorViz.pathD,style:{stroke:"var(--kritzel-snap-line-stroke, rgba(0, 0, 0, 0.3))",strokeWidth:`${t.lineStrokeWidth}`,strokeDasharray:t.dashArray,strokeLinecap:"round",fill:"none"}}):r("line",{x1:t.startAnchorViz.edgeX,y1:t.startAnchorViz.edgeY,x2:t.startAnchorViz.centerX,y2:t.startAnchorViz.centerY,style:{stroke:"var(--kritzel-snap-line-stroke, rgba(0, 0, 0, 0.3))",strokeWidth:`${t.lineStrokeWidth}`,strokeDasharray:t.dashArray,strokeLinecap:"round"}}),r("circle",{cx:t.startAnchorViz.centerX,cy:t.startAnchorViz.centerY,r:t.indicatorRadius,style:{fill:"var(--kritzel-snap-indicator-fill, rgba(0, 0, 0))",stroke:"var(--kritzel-snap-indicator-stroke, #007bff)",strokeWidth:t.indicatorStrokeWidth}})),t.endAnchorViz&&r("g",{class:"anchor-line-end"},t.endAnchorViz.pathD?r("path",{d:t.endAnchorViz.pathD,style:{stroke:"var(--kritzel-snap-line-stroke, rgba(0, 0, 0, 0.2))",strokeWidth:`${t.lineStrokeWidth}`,strokeDasharray:t.dashArray,strokeLinecap:"round",fill:"none"}}):r("line",{x1:t.endAnchorViz.edgeX,y1:t.endAnchorViz.edgeY,x2:t.endAnchorViz.centerX,y2:t.endAnchorViz.centerY,style:{stroke:"var(--kritzel-snap-line-stroke, rgba(0, 0, 0, 0.2))",strokeWidth:`${t.lineStrokeWidth}`,strokeDasharray:t.dashArray,strokeLinecap:"round"}}),r("circle",{cx:t.endAnchorViz.centerX,cy:t.endAnchorViz.centerY,r:t.indicatorRadius,style:{fill:"var(--kritzel-snap-indicator-fill, rgba(59, 130, 246, 0.3))",stroke:"var(--kritzel-snap-indicator-stroke, #007bff)",strokeWidth:t.indicatorStrokeWidth}}))):null})(),(()=>{const t=this.core.anchorManager.getSnapIndicatorRenderData();return t?r("svg",{xmlns:"http://www.w3.org/2000/svg",class:"snap-indicator",style:{position:"absolute",left:"0",top:"0",width:"1px",height:"1px",pointerEvents:"none",zIndex:"9999",overflow:"visible"}},r("g",null,t.snapLinePath?r("path",{d:t.snapLinePath,fill:"none",style:{stroke:"var(--kritzel-snap-line-stroke, rgba(0, 0, 0, 0.2))",strokeWidth:t.lineStrokeWidth,strokeDasharray:t.dashArray,strokeLinecap:"round"}}):void 0!==t.edgeX&&void 0!==t.edgeY&&r("line",{x1:t.edgeX,y1:t.edgeY,x2:t.centerX,y2:t.centerY,style:{stroke:"var(--kritzel-snap-line-stroke, rgba(0, 0, 0, 0.2))",strokeWidth:t.lineStrokeWidth,strokeDasharray:t.dashArray,strokeLinecap:"round"}}),r("circle",{cx:t.centerX,cy:t.centerY,r:t.indicatorRadius,style:{fill:"var(--kritzel-snap-indicator-fill, rgba(59, 130, 246, 0.3))",stroke:"var(--kritzel-snap-indicator-stroke, #007bff)",strokeWidth:t.indicatorStrokeWidth}}))):null})()),this.core.store.state.isContextMenuVisible&&r("kritzel-context-menu",{key:"9d17520994c59b7eca2940d1a05f4f150b790767",class:"context-menu",ref:t=>this.contextMenuElement=t,items:this.core.store.state.contextMenuItems,objects:this.core.store.selectionGroup?.objects||[],style:{position:"fixed",left:`${this.core.store.state.contextMenuX}px`,top:`${this.core.store.state.contextMenuY}px`,zIndex:"10002"},onActionSelected:t=>{t.detail.action({x:(-this.core.store.state.translateX+this.core.store.state.contextMenuX)/this.core.store.state.scale,y:(-this.core.store.state.translateY+this.core.store.state.contextMenuY)/this.core.store.state.scale},this.core.store.selectionGroup?.objects),this.hideContextMenu()},onClose:()=>this.hideContextMenu()}),this.core.store.state?.activeTool instanceof D&&!this.core.store.state.isScaling&&r("kritzel-cursor-trail",{key:"b86989f2a710324e420994f74bd8c4990cc52060",core:this.core}))}static get watchers(){return{workspace:[{onWorkspaceChange:0}],scaleMax:[{validateScaleMax:0}],scaleMin:[{validateScaleMin:0}],cursorTarget:[{onCursorTargetChange:0}]}}static get style(){return":host{display:block;position:relative;height:100%;width:100%;overflow:hidden;background-color:var(--kritzel-engine-background-color, #ffffff)}:host,:host *{touch-action:none;user-select:none}.ProseMirror{outline:none}p,h1,h2,h3,h4,h5,h6,blockquote,pre{margin:0;padding:0}.debug-panel{position:absolute;pointer-events:none;top:0;right:0}.origin{position:relative;top:0;left:0;height:0;width:0;pointer-events:none;-webkit-transform-origin:top left;-moz-transform-origin:top left;transform-origin:top left;overflow:visible}.object{overflow:visible}.PlaygroundEditorTheme__quote{margin:0;margin-left:20px;margin-bottom:10px;font-size:15px;color:rgb(101, 103, 107);border-left-color:rgb(206, 208, 212);border-left-width:4px;border-left-style:solid;padding-left:16px}"}},[513,"kritzel-engine",{workspace:[16],syncConfig:[16],activeTool:[16],globalContextMenuItems:[16],objectContextMenuItems:[16],scaleMax:[1026,"scale-max"],scaleMin:[1026,"scale-min"],cursorTarget:[16],forceUpdate:[32],triggerSelectionChange:[64],registerTool:[64],changeActiveTool:[64],disable:[64],enable:[64],delete:[64],copy:[64],paste:[64],bringForward:[64],sendBackward:[64],bringToFront:[64],sendToBack:[64],group:[64],ungroup:[64],undo:[64],redo:[64],hideContextMenu:[64],getObjectById:[64],addObject:[64],updateObject:[64],removeObject:[64],getSelectedObjects:[64],selectObjects:[64],selectAllObjectsInViewport:[64],clearSelection:[64],centerObjectInViewport:[64],getCopiedObjects:[64],createWorkspace:[64],updateWorkspace:[64],deleteWorkspace:[64],getWorkspaces:[64],getActiveWorkspace:[64]},[[0,"wheel","handleWheel"],[0,"pointerdown","handlePointerDown"],[0,"pointermove","handlePointerMove"],[0,"pointerup","handlePointerUp"],[0,"pointercancel","handlePointerCancel"],[0,"longpress","handleLongPress"],[0,"contextmenu","handleContextMenu"],[9,"resize","handleResize"],[8,"keydown","handleKeyDown"],[8,"keyup","handleKeyUp"],[4,"dblclick","preventDoubleTapZoomOnTouchDevices"]],{workspace:[{onWorkspaceChange:0}],scaleMax:[{validateScaleMax:0}],scaleMin:[{validateScaleMin:0}],cursorTarget:[{onCursorTargetChange:0}]}]);function Xc(){"undefined"!=typeof customElements&&["kritzel-engine","kritzel-context-menu","kritzel-cursor-trail","kritzel-icon"].forEach((t=>{switch(t){case"kritzel-engine":customElements.get(s(t))||customElements.define(s(t),Vc);break;case"kritzel-context-menu":customElements.get(s(t))||U();break;case"kritzel-cursor-trail":customElements.get(s(t))||_();break;case"kritzel-icon":customElements.get(s(t))||T()}}))}export{ue as A,Ot as B,zt as C,vc as D,D as E,wt as F,yt as G,Sc as H,tu as I,Uc as J,$ as K,jc as L,Tc as M,Ic as N,jt as O,Xc as P,Vc as Q,cn as a,Sn as b,gi as c,xi as d,mi as e,qt as f,Mn as g,At as h,be as i,ge as j,ye as k,Hn as l,jn as m,Tt as n,Yn as o,Ln as p,oe as q,Un as r,mt as s,Jt as t,on as u,Qn as v,nn as w,Jn as x,Et as y,Gt as z}
|