kritzel-stencil 0.1.21 → 0.1.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/cjs/{default-line-tool.config-Bva9deYM.js → default-line-tool.config-DSutud0N.js} +22 -6
  2. package/dist/cjs/index.cjs.js +1 -1
  3. package/dist/cjs/kritzel-back-to-content_32.cjs.entry.js +39 -49
  4. package/dist/collection/classes/objects/text.class.js +19 -3
  5. package/dist/collection/classes/tools/text-tool.class.js +3 -3
  6. package/dist/collection/components/core/kritzel-engine/kritzel-engine.js +20 -34
  7. package/dist/collection/components/ui/kritzel-controls/kritzel-controls.js +17 -13
  8. package/dist/collection/constants/version.js +1 -1
  9. package/dist/components/index.js +1 -1
  10. package/dist/components/kritzel-controls.js +1 -1
  11. package/dist/components/kritzel-editor.js +1 -1
  12. package/dist/components/kritzel-engine.js +1 -1
  13. package/dist/components/kritzel-settings.js +1 -1
  14. package/dist/components/kritzel-tool-config.js +1 -1
  15. package/dist/components/p-B6WmB4Lk.js +1 -0
  16. package/dist/components/{p-CYX7RMRZ.js → p-BAVx6TLg.js} +1 -1
  17. package/dist/components/{p-Dmy0R-7y.js → p-BP6ggkYA.js} +1 -1
  18. package/dist/components/{p-BbHELXEC.js → p-CEHVU-Ri.js} +2 -2
  19. package/dist/components/{p-BsvZ2juR.js → p-DBUd8DTC.js} +1 -1
  20. package/dist/esm/{default-line-tool.config-DDIFE6oX.js → default-line-tool.config-_PqPRv7q.js} +22 -6
  21. package/dist/esm/index.js +2 -2
  22. package/dist/esm/kritzel-back-to-content_32.entry.js +39 -49
  23. package/dist/stencil/index.esm.js +1 -1
  24. package/dist/stencil/p-0472bdc3.entry.js +9 -0
  25. package/dist/stencil/p-_PqPRv7q.js +1 -0
  26. package/dist/stencil/stencil.esm.js +1 -1
  27. package/dist/types/components/ui/kritzel-controls/kritzel-controls.d.ts +1 -0
  28. package/dist/types/constants/version.d.ts +1 -1
  29. package/package.json +1 -1
  30. package/dist/components/p-DqtvAhfs.js +0 -1
  31. package/dist/stencil/p-3fc743ee.entry.js +0 -9
  32. package/dist/stencil/p-DDIFE6oX.js +0 -1
@@ -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-Cj-I2_Og.js";import{K as o}from"./p-D8W6LE-c.js";import{k as u,l as c,b as h,m as a,c as l,n as f,o as d,p,q as v,h as w,r as y,i as g,f as b,g as m,e as k,d as A,s as x,K as M,a as S,j as C}from"./p-Dmy0R-7y.js";import{K as $,d as E}from"./p-BGwkUUZk.js";import{O as T}from"./p-B0kd2rUI.js";import{K as U,d as j}from"./p-Cpb-fnoO.js";import{K as I}from"./p-n789Y3S-.js";import{K as O,a as _}from"./p-BX4JyoOd.js";import{K as z}from"./p-l10It7Nm.js";import{d as D}from"./p-JdxbP-1P.js";var P="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};class R extends u{touchStartTimeout=null;constructor(t){super(t)}handlePointerDown(t){"mouse"===t.pointerType&&c.isLeftClick(t)&&(this._core.store.state.isErasing=!0),"touch"!==t.pointerType&&"pen"!==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||"pen"===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||"pen"===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 F(t,n){return new Promise((function(e,r){let i;return L(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 L=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 W={},B={get exports(){return W},set exports(t){W=t}};!function(){var t,n,e={};B.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),p=r(u,s+=4),v=r(u,s+2),w=r(u,s+4);s+=6;var y=i(u,s+=8);s+=4,s+=p+v+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 p=new Uint8Array(s);e.inflateRaw(d,p),r[f]=p}}},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 p=o[u];d.push(f),f=e._writeHeader(l,f,u,p,0)}var v=0,w=f;for(var u in o)p=o[u],d.push(f),f=e._writeHeader(l,f,u,p,1,d[v++]);var y=f-w;return i(l,f,101010256),f+=4,s(l,f+=4,v),s(l,f+=2,v),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,p=o.strt,v=o.prev,w=0,y=0,g=0,b=0,m=0,k=0;for(f>2&&(p[k=e.F._hash(t,0)]=0),h=0;h<f;h++){if(m=k,h+1<f-2){k=e.F._hash(t,h+1);var A=h+1&32767;v[A]=p[k],p[k]=A}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,v,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(S,o.df0);o.dhst[$]++,b+=o.exb[C]+o.dxb[$],d[w]=M<<23|h-l,d[w+1]=S<<16|C<<8|$,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 p=0,v=0;v<d-2;v++){var w=n-h+v+32768&32767,y=w-r[w]+32768&32767;y>p&&(p=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,p,v,w,y,g,b=e.F.U,m=e.F._putsF,k=e.F._putsE;b.lhst[256]++,l=(a=e.F.getTrees())[0],f=a[1],d=a[2],p=a[3],v=a[4],w=a[5],y=a[6],g=a[7];var A=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=A<x&&A<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 $,E;if(1==C&&($=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),$=b.ltree,E=b.dtree,k(c,h,p-257),k(c,h+=5,v-1),k(c,h+=5,w-4),h+=4;for(var T=0;T<w;T++)k(c,h+3*T,b.itree[1+(b.ordr[T]<<1)]);h=e.F._codeTiny(y,b.itree,c,h+=3*w),h=e.F._codeTiny(g,b.itree,c,h)}for(var U=o,j=0;j<r;j+=2){for(var I=n[j],O=I>>>23,_=U+(8388607&I);U<_;)h=e.F._writeLit(s[U++],$,c,h);if(0!=O){var z=n[j+1],D=z>>16,P=z>>8&255,R=255&z;k(c,h=e.F._writeLit(257+P,$,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],U+=O}}h=e.F._writeLit(256,$,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,p=1,v=2;for(i[0]={lit:-1,f:l.f+f.f,l,r:f,d:0};p!=c-1;)l=d!=p&&(v==c||i[d].f<i[v].f)?i[d++]:i[v++],f=d!=p&&(v==c||i[d].f<i[v].f)?i[d++]:i[v++],i[p++]={lit:-1,f:l.f+f.f,l,r:f};var w=e.F.setDepth(i[p-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,p,v=0,w=0,y=0,g=0,b=0,m=0,k=0,A=0,x=0;0==v;)if(v=s(t,x,1),w=s(t,x+1,2),x+=3,0!=w){if(f&&(n=e.F._check(n,A+(1<<17))),1==w&&(d=l.flmap,p=l.fdmap,m=511,k=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,p=l.dmap,x=u(l.imap,(1<<S)-1,y+g,t,x,l.ttree);var $=i._copyOut(l.ttree,0,y,l.ltree);m=(1<<$)-1;var E=i._copyOut(l.ttree,y,g,l.dtree);k=(1<<E)-1,c(l.ltree,$),h(l.ltree,$,d),c(l.dtree,E),h(l.dtree,E,p)}for(;;){var T=d[a(t,x)&m];x+=15&T;var U=T>>>4;if(U>>>8==0)n[A++]=U;else{if(256==U)break;var j=A+U-254;if(U>264){var I=l.ldef[U-257];j=A+(I>>>3)+o(t,x,7&I),x+=7&I}var O=p[a(t,x)&k],_=l.ddef[O>>>4],z=(_>>>4)+s(t,x+=15&O,15&_);for(x+=15&_,f&&(n=e.F._check(n,A+(1<<17)));A<j;)n[A]=n[A++-z],n[A]=n[A++-z],n[A]=n[A++-z],n[A]=n[A++-z];A=j}}}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,A+P)),n.set(new r(t.buffer,t.byteOffset+D,P),A),x=D+P<<3,A+=P}return n.length==A?n:n.slice(0,A)},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 p=h+d;h<p;)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 N=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:W},[W]);const K=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 p=0;p<t;p+=4)h[p]=n[p],h[p+1]=n[p+1],h[p+2]=n[p+2],h[p+3]=n[p+3];if(16==f)for(p=0;p<t;p++)h[p]=n[p<<1]}else if(2==l){const t=i.tabs.tRNS;if(null==t){if(8==f)for(p=0;p<o;p++){var v=3*p;a[p]=255<<24|n[v+2]<<16|n[v+1]<<8|n[v]}if(16==f)for(p=0;p<o;p++)a[p]=255<<24|n[4+(v=6*p)]<<16|n[v+2]<<8|n[v]}else{var w=t[0];const e=t[1],r=t[2];if(8==f)for(p=0;p<o;p++){var y=p<<2;a[p]=255<<24|n[2+(v=3*p)]<<16|n[v+1]<<8|n[v],n[v]==w&&n[v+1]==e&&n[v+2]==r&&(h[y+3]=0)}if(16==f)for(p=0;p<o;p++)y=p<<2,a[p]=255<<24|n[4+(v=6*p)]<<16|n[v+2]<<8|n[v],d(n,v)==w&&d(n,v+2)==e&&d(n,v+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(p=0;p<e;p++){var k=3*(A=n[b+(p>>3)]>>7-(7&p)&1);h[y=m+p<<2]=t[k],h[y+1]=t[k+1],h[y+2]=t[k+2],h[y+3]=A<u?s[A]:255}}if(2==f)for(g=0;g<r;g++)for(b=g*c,m=g*e,p=0;p<e;p++)k=3*(A=n[b+(p>>2)]>>6-((3&p)<<1)&3),h[y=m+p<<2]=t[k],h[y+1]=t[k+1],h[y+2]=t[k+2],h[y+3]=A<u?s[A]:255;if(4==f)for(g=0;g<r;g++)for(b=g*c,m=g*e,p=0;p<e;p++)k=3*(A=n[b+(p>>1)]>>4-((1&p)<<2)&15),h[y=m+p<<2]=t[k],h[y+1]=t[k+1],h[y+2]=t[k+2],h[y+3]=A<u?s[A]:255;if(8==f)for(p=0;p<o;p++){var A;k=3*(A=n[p]),h[y=p<<2]=t[k],h[y+1]=t[k+1],h[y+2]=t[k+2],h[y+3]=A<u?s[A]:255}}else if(4==l){if(8==f)for(p=0;p<o;p++){var x=n[M=p<<1];h[y=p<<2]=x,h[y+1]=x,h[y+2]=x,h[y+3]=n[M+1]}if(16==f)for(p=0;p<o;p++){var M;x=n[M=p<<2],h[y=p<<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],p=[8,8,4,4,2,2,1];let v=0;for(;v<7;){const s=d[v],y=p[v];let g=0,b=0,m=l[v];for(;m<r;)m+=s,b++;let k=f[v];for(;k<e;)k+=y,g++;const A=Math.ceil(g*i/8);o(t,n,a,g,b);let x=0,M=l[v];for(;M<r;){let n=f[v],r=a+x*A<<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+A)),v+=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,p=0;if(3==n[0]&&0==n[1])return e||new r(0);const v=t.H,w=v.b,y=v.e,g=v.R,b=v.n,m=v.A,k=v.Z,A=v.m,x=null==e;for(x&&(e=new r(n.length>>>2<<5));0==o;)if(o=w(n,p,1),u=w(n,p+1,2),p+=3,0!=u){if(x&&(e=t.H.W(e,d+(1<<17))),1==u&&(i=A.J,s=A.h,l=511,f=31),2==u){c=y(n,p,5)+257,h=y(n,p+5,5)+1,a=y(n,p+10,4)+4,p+=14;let t=1;for(var M=0;M<38;M+=2)A.Q[M]=0,A.Q[M+1]=0;for(M=0;M<a;M++){const e=y(n,p+3*M,3);A.Q[1+(A.X[M]<<1)]=e,e>t&&(t=e)}p+=3*a,b(A.Q,t),m(A.Q,t,A.u),i=A.w,s=A.d,p=g(A.u,(1<<t)-1,c+h,n,p,A.v);const e=v.V(A.v,0,c,A.C);l=(1<<e)-1;const r=v.V(A.v,c,h,A.D);f=(1<<r)-1,b(A.C,e),m(A.C,e,i),b(A.D,r),m(A.D,r,s)}for(;;){const t=i[k(n,p)&l];p+=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=A.q[r-257];t=d+(e>>>3)+y(n,p,7&e),p+=7&e}const i=s[k(n,p)&f];p+=15&i;const o=A.c[i>>>4],u=(o>>>4)+w(n,p,15&o);for(p+=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&p&&(p+=8-(7&p));const i=4+(p>>>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),p=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),p=t[l]*d,v=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]=(p+g*n)*i,r[f+1]=(v+b*n)*i,r[f+2]=(w+m*n)*i}else if(2==c)p=t[l],v=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])&&p==g&&v==b&&w==m?(r[f]=0,r[f+1]=0,r[f+2]=0,r[f+3]=0):(r[f]=p,r[f+1]=v,r[f+2]=w,r[f+3]=d);else if(3==c){if(p=t[l],v=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])&&p==g&&v==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,p=0,v=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[p+y]=s[o+y];p+=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!=v&&((M=l.frames[l.frames.length-1]).data=e(l,d.slice(0,v),M.rect.width,M.rect.height),v=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[v+y]=s[o+y+4];v+=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),k=o+t-b-1;if("tEXt"==n)x=u.readASCII(s,b+1,k);else{var A=r(s.slice(b+2,b+2+k));x=u.readUTF8(A,0,A.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),k=t-((g=b+1)-o),0==e?x=u.readUTF8(s,g,k):(A=r(s.slice(g,g+k)),x=u.readUTF8(A,0,A.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!=v&&((M=l.frames[l.frames.length-1]).data=e(l,d.slice(0,v),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,p=f.rect.y,v=f.rect.width,w=f.rect.height,y=n(f.data,v,w,t);if(0!=l)for(var a=0;a<s;a++)c[a]=o[a];if(0==f.blend?h(y,v,w,o,e,r,d,p,0):1==f.blend&&h(y,v,w,o,e,r,d,p,1),i.push(o.buffer.slice(0)),0==f.dispose);else if(1==f.dispose)h(u,v,w,o,e,r,d,p,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}=K,{_bin:n}=K,e=K._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,p=0;p<a;p++){var v=o(l[f],l[p]);p!=f&&v<t&&(t=v,d=p)}}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]+(v=g[4*(3&u)+(3&m)])),s(t[f+1]+v),s(t[f+2]+v),s(t[f+3]+v)],d=0;let k=16777215;for(p=0;p<a;p++){const t=o(b,l[p]);t<k&&(k=t,d=p)}const A=l[d],x=[b[0]-A[0],b[1]-A[1],b[2]-A[2],b[3]-A[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,p=!1,v=33+(f?20:0);if(null!=o.sRGB&&(v+=13),null!=o.pHYs&&(v+=21),null!=o.iCCP&&(d=pako.deflate(o.iCCP),v+=21+d.length+4),3==t.ctype){for(var w=t.plte.length,y=0;y<w;y++)t.plte[y]>>>24!=255&&(p=!0);v+=8+3*w+4+(p?8+1*w+4:0)}for(var g=0;g<t.frames.length;g++)f&&(v+=38),v+=(A=t.frames[g]).cimg.length+12,0!=g&&(v+=4);v+=12;const b=new Uint8Array(v),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,p){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 k=0;for(g=0;g<t.frames.length;g++){var A=t.frames[g];f&&(c(b,l,26),l+=4,a(b,l,"fcTL"),l+=4,c(b,l,k++),l+=4,c(b,l,A.rect.width),l+=4,c(b,l,A.rect.height),l+=4,c(b,l,A.rect.x),l+=4,c(b,l,A.rect.y),l+=4,h(b,l,s[g]),l+=2,h(b,l,1e3),l+=2,b[l]=A.dispose,l++,b[l]=A.blend,l++,c(b,l,u(b,l-30,30)),l+=4);const n=A.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,k++),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],p=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,k=0;k<m;k+=4)g&=t[k+3]}const A=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 v=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 k=0,A=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[p=t*e+n]!=i[p]&&(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<A&&(A=f,k=t,v=o,w=u,y=h-o+1,g=l-u+1)}a=new Uint8Array(n[c-1-k]),1==k&&(u[c-1].dispose=2),h=new Uint8Array(y*g*4),t(a,e,r,h,y,g,-v,-w,0),b=t(l,e,r,h,y,g,-v,-w,3)?1:0,1==b?f(l,e,r,h,{x:v,y:w,width:y,height:g}):t(l,e,r,h,y,g,-v,-w,0)}else h=l.slice(0);u.push({rect:{x:v,y:w,width:y,height:g},img:h,blend:b,dispose:0})}if(i)for(c=0;c<u.length;c++){if(1==(v=u[c]).blend)continue;const t=v.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 p=0;p<u.length;p++){var v;d+=(v=u[p]).rect.width*v.rect.height}return u}(n,e,r,o,c,h),M={},S=[],C=[];if(0!=i){const t=[];for(k=0;k<x.length;k++)t.push(x[k].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=v(n,i);for(k=0;k<e.plte.length;k++)S.push(e.plte[k].est.rgba);let r=0;for(k=0;k<x.length;k++){const t=(E=x[k]).img.length;var $=new Uint8Array(e.inds.buffer,r>>2,t>>2);C.push($);const n=new Uint8Array(e.abuf,r,t);p&&u(E.img,E.rect.width,E.rect.height,S,n,$),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 T=E.rect.width;for(m=t.length,$=new Uint8Array(m),C.push($),k=0;k<m;k++){const n=t[k];if(0!=k&&n==t[k-1])$[k]=$[k-1];else if(k>T&&n==t[k-T])$[k]=$[k-T];else{let t=M[n];if(null==t&&(M[n]=t=S.length,S.push(n),S.length>=300))break;$[k]=t}}}const U=S.length;for(U<=256&&0==d&&(y=U<=2?1:U<=4?2:U<=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*(T=E.rect.width),r=4;if(U<=256&&0==d){e=Math.ceil(y*T/8);var j=new Uint8Array(e*t);const i=C[b];for(let n=0;n<t;n++){k=n*e;const t=n*T;if(8==y)for(var I=0;I<T;I++)j[k+I]=i[t+I];else if(4==y)for(I=0;I<T;I++)j[k+(I>>1)]|=i[t+I]<<4-4*(1&I);else if(2==y)for(I=0;I<T;I++)j[k+(I>>2)]|=i[t+I]<<6-2*(3&I);else if(1==y)for(I=0;I<T;I++)j[k+(I>>3)]|=i[t+I]<<7-1*(7&I)}n=j,w=3,r=1}else if(0==A&&1==x.length){j=new Uint8Array(T*t*3);const i=T*t;for(k=0;k<i;k++){const t=3*k,e=4*k;j[t]=n[e],j[t+1]=n[e+1],j[t+2]=n[e+2]}n=j,w=2,r=3,e=3*T}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,p=new c(n[s]),v=new h(p.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=v[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(p,e,r,m.img,o)):t(p,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=N;for(var l=0;l<h.length;l++){for(let s=0;s<n;s++)p(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 p(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 v(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),p=e[l+2]*(1/255),v=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),p=e[l+2]*(1/255),v=e[l+3]*(1/255);for(a=o;a.left;)a=g(a.est,f,d,p,v)<=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=k(t,i.i0,i.i1),i.est=A(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=k(t,h.i0,h.i1),h.est=A(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=A(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 k(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 A(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,p=0;if(0!=r)for(let t=0;t<16&&(f=l.multVec(a,f),p=Math.sqrt(l.dot(f,f)),f=l.sml(1/p,f),!(0!=t&&Math.abs(p-d)<1e-9));t++)d=p;const v=[i*c,s*c,o*c,u*c];return{Cov:h,q:v,e:f,L:d,eMq255:l.dot(l.sml(255,v),f),eMq:l.dot(f,v),rgba:(Math.round(255*v[3])<<24|Math.round(255*v[2])<<16|Math.round(255*v[1])<<8|Math.round(255*v[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]]};K.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)},K.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)},K.encode.compress=a,K.encode.dither=u,K.quantize=v,K.quantize.getKDtree=w,K.quantize.getNearest=y}();const H={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,p,v,w,y=f,g=0,b=0,m=0;function k(t){l.setUint16(b,t,!0),b+=2}function A(t){l.setUint32(b,t,!0),b+=4}function x(t){b+=t}k(19778),A(h),x(4),A(122),A(108),A(e),A(-r>>>0),k(1),k(32),A(3),A(c),A(2835),A(2835),x(8),A(16711680),A(65280),A(255),A(4278190080),A(1466527264),function t(){for(;g<r&&y>0;){for(w=122+g*u,d=0;d<i;)y--,p=o[m++],v=p>>>24,l.setUint32(w+d,p<<8|v),d+=4;g++}m<o.length?(y=f,setTimeout(t,H._dly)):n(a)}()},toBlob(t,n){this.toArrayBuffer(t,(t=>{n(new Blob([t],{type:"image/bmp"}))}))},_dly:9};var V={CHROME:"CHROME",FIREFOX:"FIREFOX",DESKTOP_SAFARI:"DESKTOP_SAFARI",IE:"IE",IOS:"IOS",ETC:"ETC"},Q={[V.CHROME]:16384,[V.FIREFOX]:11180,[V.DESKTOP_SAFARI]:16384,[V.IE]:8192,[V.IOS]:4096,[V.ETC]:8192};const Y="undefined"!=typeof window,X="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope,q=Y&&window.cordova&&window.cordova.require&&window.cordova.require("cordova/modulemapper"),G=(Y||X)&&(q&&q.getOriginalSymbol(window,"File")||"undefined"!=typeof File&&File),J=(Y||X)&&(q&&q.getOriginalSymbol(window,"FileReader")||"undefined"!=typeof FileReader&&FileReader);function Z(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 tt(t){return new Promise(((n,e)=>{const r=new J;r.onload=()=>n(r.result),r.onerror=t=>e(t),r.readAsDataURL(t)}))}function nt(t){return new Promise(((n,e)=>{const r=new Image;r.onload=()=>n(r),r.onerror=t=>e(t),r.src=t}))}function et(){if(void 0!==et.cachedResult)return et.cachedResult;let t=V.ETC;const{userAgent:n}=navigator;return/Chrom(e|ium)/i.test(n)?t=V.CHROME:/iP(ad|od|hone)/i.test(n)&&/WebKit/i.test(n)?t=V.IOS:/Safari/i.test(n)?t=V.DESKTOP_SAFARI:/Firefox/i.test(n)?t=V.FIREFOX:(/MSIE/i.test(n)||1==!!document.documentMode)&&(t=V.IE),et.cachedResult=t}function rt(t,n){const e=et(),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 it(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 st(t,n){const{width:e,height:r}=rt(t.width,t.height),[i,s]=it(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 ot(){return void 0!==ot.cachedResult||(ot.cachedResult=["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"undefined"!=typeof document&&"ontouchend"in document),ot.cachedResult}function ut(t,n={}){return new Promise((function(e,r){let i,s;var o=function(){try{return s=st(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 tt(t).then((function(t){try{return e=t,nt(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(ot()||[V.DESKTOP_SAFARI,V.MOBILE_SAFARI].includes(et()))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 ct(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=K.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=>H.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 p;return p=t.toDataURL(n,i),Z(p,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 ht(t){t.width=0,t.height=0}function at(){return new Promise((function(t,n){let e,r,i,s;return void 0!==at.cachedResult?t(at.cachedResult):Z("data:image/jpeg;base64,/9j/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAYAAAAAAAD/2wCEAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/AABEIAAEAAgMBEQACEQEDEQH/xABKAAEAAAAAAAAAAAAAAAAAAAALEAEAAAAAAAAAAAAAAAAAAAAAAQEAAAAAAAAAAAAAAAAAAAAAEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwA/8H//2Q==","test.jpg",Date.now()).then((function(o){try{return e=o,ut(e).then((function(o){try{return r=o[1],ct(r,e.type,e.name,e.lastModified).then((function(e){try{return i=e,ht(r),ut(i).then((function(e){try{return s=e[0],t(at.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 lt(t){return new Promise(((n,e)=>{const r=new J;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 ft(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]=it(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),ht(t)),o}function dt(t,n){const{width:e}=t,{height:r}=t,[i,s]=it(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),ht(t),i}function pt(t,n,e=0){return new Promise((function(r,i){let s,o,u,c,h,a,l,f,d,p,v,w,y,g,b,m,k,A,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(),ut(t,n).then(function(e){try{return[,c]=e,S(),h=ft(c,n),S(),new Promise((function(e,r){var i;if(!(i=n.exifOrientation))return lt(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(),at().then(function(e){try{return l=e?h:dt(h,a),S(),f=n.initialQuality||1,d=n.fileType||t.type,ct(l,d,t.name,t.lastModified,f).then(function(e){try{{if(p=e,S(),v=p.size>u,w=p.size>t.size,!v&&!w)return C(100),r(p);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,[k,A]=it(n,e),A.drawImage(x,0,0,n,e),f*="image/png"===d?.85:.95,ct(k,d,t.name,t.lastModified,f).then((function(t){try{return m=t,ht(x),x=k,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=p.size,b=g,x=l,M=!n.alwaysKeepResolution&&v,(s=function(t){for(;t;){if(t.then)return void t.then(s,i);try{if(t.pop){if(t.length)return t.pop()?$.call(this):t;t=a}else t=t.call(this)}catch(t){return i(t)}}}.bind(this))(a);function $(){return ht(x),ht(k),ht(h),ht(l),ht(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 vt;function wt(t,n){return new Promise(((e,r)=>{vt||(vt=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(vt);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 yt(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 G))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 pt(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 pt(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",wt(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=F(t,s))}catch(t){}return e(s)}}))}yt.getDataUrlFromFile=tt,yt.getFilefromDataUrl=Z,yt.loadImage=nt,yt.drawImageInCanvas=st,yt.drawFileInCanvas=ut,yt.canvasToFile=ct,yt.getExifOrientation=lt,yt.handleMaxWidthOrHeight=ft,yt.followExifOrientation=dt,yt.cleanupCanvasMemory=ht,yt.isAutoOrientationInBrowser=at,yt.approximateBelowMaximumCanvasSizeOfBrowser=rt,yt.copyExifWithoutOrientation=F,yt.getBrowserName=et,yt.version="2.0.2";class gt extends u{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]?yt(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=h.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 bt{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=U.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 mt=()=>new Map,kt=t=>{const n=mt();return t.forEach(((t,e)=>{n.set(e,t)})),n},At=(t,n,e)=>{let r=t.get(n);return void 0===r&&t.set(n,r=e()),r},xt=()=>new Set,Mt=t=>t[t.length-1],St=(t,n)=>{for(let e=0;e<n.length;e++)t.push(n[e])},Ct=Array.from,$t=(t,n)=>{for(let e=0;e<t.length;e++)if(!n(t[e],e,t))return!1;return!0},Et=(t,n)=>{for(let e=0;e<t.length;e++)if(n(t[e],e,t))return!0;return!1},Tt=Array.isArray;class Ut{constructor(){this._observers=mt()}on(t,n){return At(this._observers,t,xt).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 Ct((this._observers.get(t)||mt()).values()).forEach((t=>t(...n)))}destroy(){this._observers=mt()}}let jt=class{constructor(){this._observers=mt()}on(t,n){At(this._observers,t,xt).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 Ct((this._observers.get(t)||mt()).values()).forEach((t=>t(...n)))}destroy(){this._observers=mt()}};const It=Math.floor,Ot=Math.abs,_t=(t,n)=>t<n?t:n,zt=(t,n)=>t>n?t:n,Dt=Math.pow,Pt=t=>0!==t?t<0:1/t<0,Rt=64,Ft=128,Lt=127,Wt=Number.MAX_SAFE_INTEGER,Bt=Number.MIN_SAFE_INTEGER,Nt=Number.isInteger||(t=>"number"==typeof t&&isFinite(t)&&It(t)===t),Kt=String.fromCharCode,Ht=/^\s*/g,Vt=/([A-Z])/g,Qt=(t,n)=>(t=>t.replace(Ht,""))(t.replace(Vt,(t=>`${n}${(t=>t.toLowerCase())(t)}`))),Yt="undefined"!=typeof TextEncoder?new TextEncoder:null,Xt=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 qt="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});qt&&1===qt.decode(new Uint8Array).length&&(qt=null);let Gt=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}};const Jt=()=>new Gt,Zt=t=>{let n=t.cpos;for(let e=0;e<t.bufs.length;e++)n+=t.bufs[e].length;return n},tn=t=>{const n=new Uint8Array(Zt(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},nn=(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},en=nn,rn=(t,n)=>{for(;n>Lt;)nn(t,Ft|Lt&n),n=It(n/128);nn(t,Lt&n)},sn=(t,n)=>{const e=Pt(n);for(e&&(n=-n),nn(t,(n>63?Ft:0)|(e?Rt:0)|63&n),n=It(n/64);n>0;)nn(t,(n>Lt?Ft:0)|Lt&n),n=It(n/128)},on=new Uint8Array(3e4),un=on.length/3,cn=Yt&&Yt.encodeInto?(t,n)=>{if(n.length<un){const e=Yt.encodeInto(n,on).written||0;rn(t,e);for(let n=0;n<e;n++)nn(t,on[n])}else an(t,Xt(n))}:(t,n)=>{const e=unescape(encodeURIComponent(n)),r=e.length;rn(t,r);for(let n=0;n<r;n++)nn(t,e.codePointAt(n))},hn=(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(zt(2*e,s)),t.cbuf.set(n.subarray(i)),t.cpos=s)},an=(t,n)=>{rn(t,n.byteLength),hn(t,n)},ln=(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*zt(e,n)),t.cpos=0)})(t,n);const e=new DataView(t.cbuf.buffer,t.cpos,n);return t.cpos+=n,e},fn=new DataView(new ArrayBuffer(4)),dn=(t,n)=>{switch(typeof n){case"string":nn(t,119),cn(t,n);break;case"number":Nt(n)&&Ot(n)<=2147483647?(nn(t,125),sn(t,n)):(fn.setFloat32(0,e=n),fn.getFloat32(0)===e?(nn(t,124),((t,n)=>{ln(t,4).setFloat32(0,n,!1)})(t,n)):(nn(t,123),((t,n)=>{ln(t,8).setFloat64(0,n,!1)})(t,n)));break;case"bigint":nn(t,122),((t,n)=>{ln(t,8).setBigInt64(0,n,!1)})(t,n);break;case"object":if(null===n)nn(t,126);else if(Tt(n)){nn(t,117),rn(t,n.length);for(let e=0;e<n.length;e++)dn(t,n[e])}else if(n instanceof Uint8Array)nn(t,116),an(t,n);else{nn(t,118);const e=Object.keys(n);rn(t,e.length);for(let r=0;r<e.length;r++){const i=e[r];cn(t,i),dn(t,n[i])}}break;case"boolean":nn(t,n?120:121);break;default:nn(t,127)}var e};class pn extends Gt{constructor(t){super(),this.w=t,this.s=null,this.count=0}write(t){this.s===t?this.count++:(this.count>0&&rn(this,this.count-1),this.count=1,this.w(this,t),this.s=t)}}const vn=t=>{t.count>0&&(sn(t.encoder,1===t.count?t.s:-t.s),t.count>1&&rn(t.encoder,t.count-2))};class wn{constructor(){this.encoder=new Gt,this.s=0,this.count=0}write(t){this.s===t?this.count++:(vn(this),this.count=1,this.s=t)}toUint8Array(){return vn(this),tn(this.encoder)}}const yn=t=>{t.count>0&&(sn(t.encoder,2*t.diff+(1===t.count?0:1)),t.count>1&&rn(t.encoder,t.count-2))};class gn{constructor(){this.encoder=new Gt,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(yn(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return yn(this),tn(this.encoder)}}class bn{constructor(){this.sarr=[],this.s="",this.lensE=new wn}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 Gt;return this.sarr.push(this.s),this.s="",cn(t,this.sarr.join("")),hn(t,this.lensE.toUint8Array()),tn(t)}}const mn=t=>new Error(t),kn=()=>{throw mn("Method unimplemented")},An=()=>{throw mn("Unexpected case")},xn=mn("Unexpected end of array"),Mn=mn("Integer out of Range");let Sn=class{constructor(t){this.arr=t,this.pos=0}};const Cn=t=>new Sn(t),$n=t=>((t,n)=>{const e=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,n);return t.pos+=n,e})(t,Tn(t)),En=t=>t.arr[t.pos++],Tn=t=>{let n=0,e=1;const r=t.arr.length;for(;t.pos<r;){const r=t.arr[t.pos++];if(n+=(r&Lt)*e,e*=128,r<Ft)return n;if(n>Wt)throw Mn}throw xn},Un=t=>{let n=t.arr[t.pos++],e=63&n,r=64;const i=(n&Rt)>0?-1:1;if(!(n&Ft))return i*e;const s=t.arr.length;for(;t.pos<s;){if(n=t.arr[t.pos++],e+=(n&Lt)*r,r*=128,n<Ft)return i*e;if(e>Wt)throw Mn}throw xn},jn=qt?t=>qt.decode($n(t)):t=>{let n=Tn(t);if(0===n)return"";{let e=String.fromCodePoint(En(t));if(--n<100)for(;n--;)e+=String.fromCodePoint(En(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))}},In=(t,n)=>{const e=new DataView(t.arr.buffer,t.arr.byteOffset+t.pos,n);return t.pos+=n,e},On=[()=>{},()=>null,Un,t=>In(t,4).getFloat32(0,!1),t=>In(t,8).getFloat64(0,!1),t=>In(t,8).getBigInt64(0,!1),()=>!1,()=>!0,jn,t=>{const n=Tn(t),e={};for(let r=0;r<n;r++)e[jn(t)]=_n(t);return e},t=>{const n=Tn(t),e=[];for(let r=0;r<n;r++)e.push(_n(t));return e},$n],_n=t=>On[127-En(t)](t);class zn extends Sn{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?Tn(this)+1:-1),this.count--,this.s}}class Dn extends Sn{constructor(t){super(t),this.s=0,this.count=0}read(){if(0===this.count){this.s=Un(this);const t=Pt(this.s);this.count=1,t&&(this.s=-this.s,this.count=Tn(this)+2)}return this.count--,this.s}}class Pn extends Sn{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(0===this.count){const t=Un(this),n=1&t;this.diff=It(t/2),this.count=1,n&&(this.count=Tn(this)+2)}return this.s+=this.diff,this.count--,this.s}}class Rn{constructor(t){this.decoder=new Dn(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 Fn=crypto.getRandomValues.bind(crypto),Ln=()=>Fn(new Uint32Array(1))[0],Wn=[1e7]+-1e3+-4e3+-8e3+-1e11,Bn=()=>Wn.replace(/[018]/g,(t=>(t^Ln()&15>>t/4).toString(16))),Nn=Date.now,Kn=t=>new Promise(t);Promise.all.bind(Promise);let Hn=new class{constructor(){this.map=new Map}setItem(t,n){this.map.set(t,n)}getItem(t){return this.map.get(t)}},Vn=!0;try{"undefined"!=typeof localStorage&&localStorage&&(Hn=localStorage,Vn=!1)}catch(W){}const Qn=Hn,Yn=t=>Vn||addEventListener("storage",t),Xn=t=>Vn||removeEventListener("storage",t),qn=Symbol("Equality"),Gn=(t,n)=>t===n||!!t?.[qn]?.(n)||!1,Jn=Object.assign,Zn=Object.keys,te=(t,n)=>{const e=[];for(const r in t)e.push(n(t[r],r));return e},ne=t=>Zn(t).length,ee=(t,n)=>{for(const e in t)if(!n(t[e],e))return!1;return!0},re=(t,n)=>Object.prototype.hasOwnProperty.call(t,n),ie=Object.freeze,se=t=>{for(const n in t){const e=t[n];"object"!=typeof e&&"function"!=typeof e||se(t[n])}return ie(t)},oe=(t,n,e=0)=>{try{for(;e<t.length;e++)t[e](...n)}finally{e<t.length&&oe(t,n,e+1)}},ue=t=>t,ce=(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[qn])return t[qn](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)||!ce(t.get(e),n.get(e)))return!1;break;case void 0:case Object:if(ne(t)!==ne(n))return!1;for(const e in t)if(!re(t,e)||!ce(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(!ce(t[e],n[e]))return!1;break;default:return!1}return!0},he="undefined"!=typeof process&&process.release&&/node|io\.js/.test(process.release.name)&&"[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),ae="undefined"!=typeof window&&"undefined"!=typeof document&&!he;let le;const fe=t=>(()=>{if(void 0===le)if(he){le=mt();const t=process.argv;let n=null;for(let e=0;e<t.length;e++){const r=t[e];"-"===r[0]?(null!==n&&le.set(n,""),n=r):null!==n&&(le.set(n,r),n=null)}null!==n&&le.set(n,"")}else"object"==typeof location?(le=mt(),(location.search||"?").slice(1).split("&").forEach((t=>{if(0!==t.length){const[n,e]=t.split("=");le.set(`--${Qt(n,"-")}`,e),le.set(`-${Qt(n,"-")}`,e)}}))):le=mt();return le})().has(t),de=t=>{return void 0===(n=he?process.env[t.toUpperCase().replaceAll("-","_")]:Qn.getItem(t))?null:n;var n},pe=t=>fe("--"+t)||null!==de(t),ve=pe("production");var we;const ye=he&&(we=process.env.FORCE_COLOR,["true","1","2"].includes(we))||!fe("--no-colors")&&!pe("no-color")&&(!he||process.stdout.isTTY)&&(!he||fe("--color")||null!==de("COLORTERM")||(de("TERM")||"").includes("color")),ge=t=>new Uint8Array(t),be=t=>new Uint8Array(t),me=ae?t=>{let n="";for(let e=0;e<t.byteLength;e++)n+=Kt(t[e]);return btoa(n)}:t=>Buffer.from(t.buffer,t.byteOffset,t.byteLength).toString("base64"),ke=ae?t=>{const n=atob(t),e=ge(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 Ae{constructor(t,n){this.left=t,this.right=n}}const xe=(t,n)=>new Ae(t,n),Me=t=>t.next()>=.5,Se=(t,n,e)=>It(t.next()*(e+1-n)+n),Ce=(t,n,e)=>It(t.next()*(e+1-n)+n),$e=(t,n,e)=>Ce(t,n,e),Ee=t=>Kt($e(t,97,122)),Te=(t,n)=>n[$e(t,0,n.length-1)],Ue=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 Ie=(t,n)=>t===n||null!=t&&null!=n&&t.constructor===n.constructor&&(t[qn]?Gn(t,n):Tt(t)?$t(t,(t=>Et(n,(n=>Ie(t,n))))):!!(t=>"object"==typeof t)(t)&&ee(t,((t,e)=>Ie(t,n[e]))));class Oe{static _dilutes=!1;extends(t){let[n,e]=[this.shape,t.shape];return this.constructor._dilutes&&([e,n]=[n,e]),Ie(n,e)}equals(t){return this.constructor===t.constructor&&ce(this.shape,t.shape)}[Ue](){return!0}[qn](t){return this.equals(t)}validate(t){return this.check(t)}check(t,n){kn()}get nullable(){return cr(this,xr)}get optional(){return new Ke(this)}cast(t){return $r(t,this),t}expect(t){return $r(t,this),t}}class _e extends Oe{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 ze=(t,n=null)=>new _e(t,n);ze(_e);class De extends Oe{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 Pe=t=>new De(t);ze(De);class Re extends Oe{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 Fe=(...t)=>new Re(t),Le=ze(Re),We=RegExp.escape||(t=>t.replace(/[().|&,$^[\]]/g,(t=>"\\"+t))),Be=t=>gr.check(t)?[We(t)]:Le.check(t)?t.shape.map((t=>t+"")):yr.check(t)?["[+-]?\\d+.?\\d*"]:br.check(t)?[".*"]:hr.check(t)?t.shape.map(Be).flat(1):void An();ze(class extends Oe{constructor(t){super(),this.shape=t,this._r=new RegExp("^"+t.map(Be).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 Ne=Symbol("optional");class Ke extends Oe{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[Ne](){return!0}}const He=ze(Ke);ze(class extends Oe{check(t,n){return n?.extend(null,"never",typeof t),!1}});class Ve extends Oe{constructor(t,n=!1){super(),this.shape=t,this._isPartial=n}static _dilutes=!0;get partial(){return new Ve(this.shape,!0)}check(t,n){return null==t?(n?.extend(null,"object","null"),!1):ee(this.shape,((e,r)=>{const i=this._isPartial&&!re(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=ze(Ve),Ye=Pe((t=>null!=t&&(t.constructor===Object||null==t.constructor)));class Xe extends Oe{constructor(t,n){super(),this.shape={keys:t,values:n}}check(t,n){return null!=t&&ee(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 qe=(t,n)=>new Xe(t,n),Ge=ze(Xe);class Je extends Oe{constructor(t){super(),this.shape=t}check(t,n){return null!=t&&ee(this.shape,((e,r)=>{const i=e.check(t[r],n);return!i&&n?.extend(r.toString(),"Tuple",typeof e),i}))}}ze(Je);class Ze extends Oe{constructor(t){super(),this.shape=1===t.length?t[0]:new ur(t)}check(t,n){const e=Tt(t)&&$t(t,(t=>this.shape.check(t)));return!e&&n?.extend(null,"Array",""),e}}const tr=(...t)=>new Ze(t),nr=ze(Ze),er=Pe((t=>Tt(t)));class rr extends Oe{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}}ze(rr);const ir=((t,n=null)=>new rr(Oe,n))(),sr=ze(class extends Oe{constructor(t){super(),this.len=t.length-1,this.args=((...t)=>new Je(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}}),or=Pe((t=>"function"==typeof t));ze(class extends Oe{constructor(t){super(),this.shape=t}check(t,n){const e=$t(this.shape,(e=>e.check(t,n)));return!e&&n?.extend(null,"Intersectinon",typeof t),e}},(t=>t.shape.length>0));class ur extends Oe{static _dilutes=!0;constructor(t){super(),this.shape=t}check(t,n){const e=Et(this.shape,(e=>e.check(t,n)));return n?.extend(null,"Union",typeof t),e}}const cr=(...t)=>t.findIndex((t=>hr.check(t)))>=0?cr(...t.map((t=>Cr(t))).map((t=>hr.check(t)?t.shape:[t])).flat(1)):1===t.length?t[0]:new ur(t),hr=ze(ur),ar=()=>!0,lr=Pe(ar),fr=ze(De,(t=>t.shape===ar)),dr=Pe((t=>"bigint"==typeof t)),pr=Pe((t=>t===dr)),vr=Pe((t=>"symbol"==typeof t));Pe((t=>t===vr));const wr=Pe((t=>"number"==typeof t)),yr=Pe((t=>t===wr)),gr=Pe((t=>"string"==typeof t)),br=Pe((t=>t===gr)),mr=Pe((t=>"boolean"==typeof t)),kr=Pe((t=>t===mr)),Ar=Fe(void 0);ze(Re,(t=>1===t.shape.length&&void 0===t.shape[0])),Fe(void 0);const xr=Fe(null),Mr=ze(Re,(t=>1===t.shape.length&&null===t.shape[0]));ze(Uint8Array),ze(_e,(t=>t.shape===Uint8Array));const Sr=cr(wr,gr,xr,Ar,dr,mr,vr);(()=>{const t=tr(lr),n=qe(gr,lr),e=cr(wr,gr,xr,mr,t,n);t.shape=e,n.shape.values=e})();const Cr=t=>{if(ir.check(t))return t;if(Ye.check(t)){const n={};for(const e in t)n[e]=Cr(t[e]);return new Ve(n)}return er.check(t)?cr(...t.map(Cr)):Sr.check(t)?Fe(t):or.check(t)?ze(t):void An()},$r=ve?()=>{}:(t,n)=>{const e=new je;if(!n.check(t,e))throw mn(`Expected value to be of type ${n.constructor.name}.\n${e.toString()}`)};const Er=(Tr=lr,new class{constructor(t){this.patterns=[],this.$state=t}if(t,n){return this.patterns.push({if:Cr(t),h:n}),this}else(t){return this.if(lr,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 mn("Unhandled pattern")}}}(Tr)).if(yr,((t,n)=>Se(n,Bt,Wt))).if(br,((t,n)=>((t,n=0,e=20)=>{const r=$e(t,n,e);let i="";for(let n=0;n<r;n++)i+=Ee(t);return i})(n))).if(kr,((t,n)=>Me(n))).if(pr,((t,n)=>BigInt(Se(n,Bt,Wt)))).if(hr,((t,n)=>Ur(n,Te(n,t.shape)))).if(Qe,((t,n)=>{const e={};for(const r in t.shape){let i=t.shape[r];if(He.check(i)){if(Me(n))continue;i=i.shape}e[r]=Er(i,n)}return e})).if(nr,((t,n)=>{const e=[],r=Ce(n,0,42);for(let i=0;i<r;i++)e.push(Ur(n,t.shape));return e})).if(Le,((t,n)=>Te(n,t.shape))).if(Mr,(()=>null)).if(sr,((t,n)=>{const e=Ur(n,t.res);return()=>e})).if(fr,((t,n)=>Ur(n,Te(n,[wr,gr,xr,Ar,dr,mr,tr(wr),qe(cr("a","b","c"),wr)])))).if(Ge,((t,n)=>{const e={},r=Se(n,0,3);for(let i=0;i<r;i++){const r=Ur(n,t.shape.keys),i=Ur(n,t.shape.values);e[r]=i}return e})).done();var Tr;const Ur=(t,n)=>Er(Cr(n),t),jr="undefined"!=typeof document?document:{};Pe((t=>t.nodeType===zr)),"undefined"!=typeof DOMParser&&new DOMParser,Pe((t=>t.nodeType===Ir)),Pe((t=>t.nodeType===Or));const Ir=jr.ELEMENT_NODE,Or=jr.TEXT_NODE,_r=jr.DOCUMENT_NODE,zr=jr.DOCUMENT_FRAGMENT_NODE;Pe((t=>t.nodeType===_r));const Dr=Symbol,Pr=Dr(),Rr=Dr(),Fr=Dr(),Lr=Dr(),Wr=Dr(),Br=Dr(),Nr=Dr(),Kr=Dr(),Hr=Dr(),Vr={[Pr]:xe("font-weight","bold"),[Rr]:xe("font-weight","normal"),[Fr]:xe("color","blue"),[Wr]:xe("color","green"),[Lr]:xe("color","grey"),[Br]:xe("color","red"),[Nr]:xe("color","purple"),[Kr]:xe("color","orange"),[Hr]:xe("color","black")},Qr=ye?t=>{1===t.length&&t[0]?.constructor===Function&&(t=t[0]());const n=[],e=[],r=mt();let i=[],s=0;for(;s<t.length;s++){const i=t[s],o=Vr[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(Kr),Xr.forEach((n=>n.print(t)))},Xr=xt(),qr=t=>({[Symbol.iterator](){return this},next:t}),Gr=(t,n)=>qr((()=>{const{done:e,value:r}=t.next();return{done:e,value:e?void 0:n(r)}}));class Jr{constructor(t,n){this.clock=t,this.len=n}}class Zr{constructor(){this.clients=new Map}}const ti=(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])Vi(t,i,o.clock,o.len,e)}})),ni=(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=It((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)},ei=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=zt(r.len,i.clock+i.len-r.clock):(e<n&&(t[e]=i),e++)}t.length=e}))},ri=t=>{const n=new Zr;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++)St(s,t[n].clients.get(i)||[]);n.clients.set(i,s)}}));return ei(n),n},ii=(t,n,e,r)=>{At(t.clients,n,(()=>[])).push(new Jr(e,r))},si=(t,n)=>{rn(t.restEncoder,n.clients.size),Ct(n.clients.entries()).sort(((t,n)=>n[0]-t[0])).forEach((([n,e])=>{t.resetDsCurVal(),rn(t.restEncoder,n);const r=e.length;rn(t.restEncoder,r);for(let n=0;n<r;n++){const r=e[n];t.writeDsClock(r.clock),t.writeDsLen(r.len)}}))},oi=t=>{const n=new Zr,e=Tn(t.restDecoder);for(let r=0;r<e;r++){t.resetDsCurVal();const e=Tn(t.restDecoder),r=Tn(t.restDecoder);if(r>0){const i=At(n.clients,e,(()=>[]));for(let n=0;n<r;n++)i.push(new Jr(t.readDsClock(),t.readDsLen()))}}return n},ui=(t,n,e)=>{const r=new Zr,i=Tn(t.restDecoder);for(let s=0;s<i;s++){t.resetDsCurVal();const i=Tn(t.restDecoder),s=Tn(t.restDecoder),o=e.clients.get(i)||[],u=Fi(e,i);for(let e=0;e<s;e++){const e=t.readDsClock(),s=e+t.readDsLen();if(e<u){u<s&&ii(r,i,u,s-u);let t=Wi(o,e),c=o[t];for(!c.deleted&&c.id.clock<e&&(o.splice(t+1,0,Do(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,Do(n,c,s-c.id.clock)),c.delete(n))}else ii(r,i,e,s-e)}}if(r.clients.size>0){const t=new yi;return rn(t.restEncoder,0),si(t,r),t.toUint8Array()}return null},ci=Ln;class hi extends Ut{constructor({guid:t=Bn(),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=ci(),this.guid=t,this.collectionid=n,this.share=new Map,this.store=new Pi,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=Kn((t=>{this.on("load",(()=>{this.isLoaded=!0,t(this)}))}));const u=()=>Kn((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||Ji(t.parent.doc,(t=>{t.subdocsLoaded.add(this)}),null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(Ct(this.subdocs).map((t=>t.guid)))}transact(t,n=null){return Ji(this,t,n)}get(t,n=xs){const e=At(this.share,t,(()=>{const t=new n;return t._integrate(this,null),t})),r=e.constructor;if(n!==xs&&r!==n){if(r===xs){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,Ws)}getText(t=""){return this.get(t,so)}getMap(t=""){return this.get(t,Ns)}getXmlElement(t=""){return this.get(t,co)}getXmlFragment(t=""){return this.get(t,uo)}toJSON(){const t={};return this.share.forEach(((n,e)=>{t[e]=n.toJSON()})),t}destroy(){this.isDestroyed=!0,Ct(this.subdocs).forEach((t=>t.destroy()));const t=this._item;if(null!==t){this._item=null;const n=t.content;n.doc=new hi({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=t,Ji(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 ai{constructor(t){this.restDecoder=t}resetDsCurVal(){}readDsClock(){return Tn(this.restDecoder)}readDsLen(){return Tn(this.restDecoder)}}class li extends ai{readLeftID(){return Oi(Tn(this.restDecoder),Tn(this.restDecoder))}readRightID(){return Oi(Tn(this.restDecoder),Tn(this.restDecoder))}readClient(){return Tn(this.restDecoder)}readInfo(){return En(this.restDecoder)}readString(){return jn(this.restDecoder)}readParentInfo(){return 1===Tn(this.restDecoder)}readTypeRef(){return Tn(this.restDecoder)}readLen(){return Tn(this.restDecoder)}readAny(){return _n(this.restDecoder)}readBuf(){return(t=>{const n=ge(t.byteLength);return n.set(t),n})($n(this.restDecoder))}readJSON(){return JSON.parse(jn(this.restDecoder))}readKey(){return jn(this.restDecoder)}}class fi{constructor(t){this.dsCurrVal=0,this.restDecoder=t}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=Tn(this.restDecoder),this.dsCurrVal}readDsLen(){const t=Tn(this.restDecoder)+1;return this.dsCurrVal+=t,t}}class di extends fi{constructor(t){super(t),this.keys=[],Tn(t),this.keyClockDecoder=new Pn($n(t)),this.clientDecoder=new Dn($n(t)),this.leftClockDecoder=new Pn($n(t)),this.rightClockDecoder=new Pn($n(t)),this.infoDecoder=new zn($n(t),En),this.stringDecoder=new Rn($n(t)),this.parentInfoDecoder=new zn($n(t),En),this.typeRefDecoder=new Dn($n(t)),this.lenDecoder=new Dn($n(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 $n(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 pi{constructor(){this.restEncoder=Jt()}toUint8Array(){return tn(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){rn(this.restEncoder,t)}writeDsLen(t){rn(this.restEncoder,t)}}class vi extends pi{writeLeftID(t){rn(this.restEncoder,t.client),rn(this.restEncoder,t.clock)}writeRightID(t){rn(this.restEncoder,t.client),rn(this.restEncoder,t.clock)}writeClient(t){rn(this.restEncoder,t)}writeInfo(t){en(this.restEncoder,t)}writeString(t){cn(this.restEncoder,t)}writeParentInfo(t){rn(this.restEncoder,t?1:0)}writeTypeRef(t){rn(this.restEncoder,t)}writeLen(t){rn(this.restEncoder,t)}writeAny(t){dn(this.restEncoder,t)}writeBuf(t){an(this.restEncoder,t)}writeJSON(t){cn(this.restEncoder,JSON.stringify(t))}writeKey(t){cn(this.restEncoder,t)}}class wi{constructor(){this.restEncoder=Jt(),this.dsCurrVal=0}toUint8Array(){return tn(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){const n=t-this.dsCurrVal;this.dsCurrVal=t,rn(this.restEncoder,n)}writeDsLen(t){0===t&&An(),rn(this.restEncoder,t-1),this.dsCurrVal+=t}}class yi extends wi{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new gn,this.clientEncoder=new wn,this.leftClockEncoder=new gn,this.rightClockEncoder=new gn,this.infoEncoder=new pn(en),this.stringEncoder=new bn,this.parentInfoEncoder=new pn(en),this.typeRefEncoder=new wn,this.lenEncoder=new wn}toUint8Array(){const t=Jt();return rn(t,0),an(t,this.keyClockEncoder.toUint8Array()),an(t,this.clientEncoder.toUint8Array()),an(t,this.leftClockEncoder.toUint8Array()),an(t,this.rightClockEncoder.toUint8Array()),an(t,tn(this.infoEncoder)),an(t,this.stringEncoder.toUint8Array()),an(t,tn(this.parentInfoEncoder)),an(t,this.typeRefEncoder.toUint8Array()),an(t,this.lenEncoder.toUint8Array()),hn(t,tn(this.restEncoder)),tn(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){dn(this.restEncoder,t)}writeBuf(t){an(this.restEncoder,t)}writeJSON(t){dn(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 gi=(t,n,e)=>{const r=new Map;e.forEach(((t,e)=>{Fi(n,e)>t&&r.set(e,t)})),Ri(n).forEach(((t,n)=>{e.has(n)||r.set(n,0)})),rn(t.restEncoder,r.size),Ct(r.entries()).sort(((t,n)=>n[0]-t[0])).forEach((([e,r])=>{((t,n,e,r)=>{r=zt(r,n[0].id.clock);const i=Wi(n,r);rn(t.restEncoder,n.length-i),t.writeClient(e),rn(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)}))},bi=(t,n,e,r=di)=>{const i=Cn(n);((t,n,e,r=new di(t))=>{Ji(n,(t=>{t.local=!1;let n=!1;const e=t.doc,i=e.store,s=((t,n)=>{const e=mt(),r=Tn(t.restDecoder);for(let i=0;i<r;i++){const r=Tn(t.restDecoder),i=new Array(r),s=t.readClient();let o=Tn(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 po(Oi(s,o),n),o+=n;break}case 10:{const n=Tn(t.restDecoder);i[e]=new Bo(Oi(s,o),n),o+=n;break}default:{const u=!(192&r),c=new Fo(Oi(s,o),null,(r&Ft)===Ft?t.readLeftID():null,null,(r&Rt)===Rt?t.readRightID():null,u?t.readParentInfo()?n.get(t.readString()):t.readLeftID():null,!u||32&~r?null:t.readString(),Lo(t,r));i[e]=c,o+=c.length}}}}return e})(r,e),o=((t,n,e)=>{const r=[];let i=Ct(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 Pi,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!==Bo){const i=At(l,a.id.client,(()=>Fi(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,Fi(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 yi;return gi(t,u,new Map),rn(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<Fi(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=us([u.update,o.update])}}else i.pendingStructs=o;const c=ui(r,t,i);if(i.pendingDs){const n=new di(Cn(i.pendingDs));Tn(n.restDecoder);const e=ui(n,t,i);i.pendingDs=c&&e?us([c,e]):c||e}else i.pendingDs=c;if(n){const n=i.pendingStructs.update;i.pendingStructs=null,bi(t.doc,n)}}),e,!1)})(i,t,e,new r(i))},mi=(t,n,e)=>bi(t,n,e,li),ki=(t,n=new Uint8Array([0]),e=new yi)=>{((t,n,e=new Map)=>{gi(t,n.store,e),si(t,(t=>{const n=new Zr;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 Jr(i,s))}}r.length>0&&n.clients.set(e,r)})),n})(n.store))})(e,t,xi(n));const r=[e.toUint8Array()];if(t.store.pendingDs&&r.push(t.store.pendingDs),t.store.pendingStructs&&r.push(cs(t.store.pendingStructs.update,n)),r.length>1){if(e.constructor===vi)return ss(r.map(((t,n)=>0===n?t:fs(t))));if(e.constructor===yi)return us(r)}return r[0]},Ai=(t,n)=>ki(t,n,new vi),xi=t=>(t=>{const n=new Map,e=Tn(t.restDecoder);for(let r=0;r<e;r++){const e=Tn(t.restDecoder),r=Tn(t.restDecoder);n.set(e,r)}return n})(new ai(Cn(t))),Mi=(t,n)=>(rn(t.restEncoder,n.size),Ct(n.entries()).sort(((t,n)=>n[0]-t[0])).forEach((([n,e])=>{rn(t.restEncoder,n),rn(t.restEncoder,e)})),t),Si=t=>((t,n=new wi)=>(t instanceof Map?Mi(n,t):((t,n)=>{Mi(t,Ri(n.store))})(n,t),n.toUint8Array()))(t,new pi);class Ci{constructor(){this.l=[]}}const $i=()=>new Ci,Ei=(t,n)=>t.l.push(n),Ti=(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.")},Ui=(t,n,e)=>oe(t.l,[n,e]);class ji{constructor(t,n){this.client=t,this.clock=n}}const Ii=(t,n)=>t===n||null!==t&&null!==n&&t.client===n.client&&t.clock===n.clock,Oi=(t,n)=>new ji(t,n),_i=(t,n)=>{for(;null!==n;){if(n.parent===t)return!0;n=n.parent._item}return!1},zi=(t,n)=>void 0===n?!t.deleted:n.sv.has(t.id.client)&&(n.sv.get(t.id.client)||0)>t.id.clock&&!ni(n.ds,t.id),Di=(t,n)=>{const e=At(t.meta,Di,xt),r=t.doc.store;e.has(n)||(n.sv.forEach(((n,e)=>{n<Fi(r,e)&&Ki(t,Oi(e,n))})),ti(t,n.ds,(()=>{})),e.add(n))};class Pi{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const Ri=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},Fi=(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},Li=(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 An()}e.push(n)},Wi=(t,n)=>{let e=0,r=t.length-1,i=t[r],s=i.id.clock;if(s===n)return r;let o=It(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=It((e+r)/2)}throw An()},Bi=(t,n)=>{const e=t.clients.get(n.client);return e[Wi(e,n.clock)]},Ni=(t,n,e)=>{const r=Wi(n,e),i=n[r];return i.id.clock<e&&i instanceof Fo?(n.splice(r+1,0,Do(t,i,e-i.id.clock)),r+1):r},Ki=(t,n)=>{const e=t.doc.store.clients.get(n.client);return e[Ni(t,e,n.clock)]},Hi=(t,n,e)=>{const r=n.clients.get(e.client),i=Wi(r,e.clock),s=r[i];return e.clock!==s.id.clock+s.length-1&&s.constructor!==po&&r.splice(i+1,0,Do(t,s,e.clock-s.id.clock+1)),s},Vi=(t,n,e,r,i)=>{if(0===r)return;const s=e+r;let o,u=Ni(t,n,e);do{o=n[u++],s<o.id.clock+o.length&&Ni(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 Zr,this.beforeState=Ri(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)||(ei(n.deleteSet),((t,n)=>{gi(t,n.doc.store,n.beforeState)})(t,n),si(t,n.deleteSet),0)),Xi=(t,n,e)=>{const r=n._item;(null===r||r.id.clock<(t.beforeState.get(r.id.client)||0)&&!r.deleted)&&At(t.changed,n,xt).add(e)},qi=(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 Fo&&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},Gi=(t,n)=>{if(n<t.length){const e=t[n],r=e.doc,i=r.store,s=e.deleteSet,o=e._mergeStructs;try{ei(s),e.afterState=Ri(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(((n,r)=>{r._dEH.l.length>0&&(null===r._item||!r._item.deleted)&&((n=n.filter((t=>null===t.target._item||!t.target._item.deleted))).forEach((t=>{t.currentTarget=r,t._path=null})),n.sort(((t,n)=>t.path.length-n.path.length)),t.push((()=>{Ui(r._dEH,n,e)})))})),t.push((()=>r.emit("afterTransaction",[e,r]))),t.push((()=>{e._needFormattingCleanup&&eo(e)}))})),oe(t,[])}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=Wi(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 Fo&&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+Wi(r,e.clock+e.len-1)),n=r[t];t>0&&n.id.clock>=e.clock;n=r[t])t-=1+qi(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=zt(Wi(t,r),1);for(let n=t.length-1;n>=e;)n-=1+qi(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=Wi(r,e);s+1<r.length&&qi(r,s+1)>1||s>0&&qi(r,s)}if(e.local||e.afterState.get(r.clientID)===e.beforeState.get(r.clientID)||(((...t)=>{console.log(...Qr(t)),Xr.forEach((n=>n.print(t)))})(Kr,Pr,"[yjs] ",Rr,Br,"Changed the client-id because another client seems to be using it."),r.clientID=ci()),r.emit("afterTransactionCleanup",[e,r]),r._observers.has("update")){const t=new vi;Yi(t,e)&&r.emit("update",[t.toUint8Array(),e.origin,r,e])}if(r._observers.has("updateV2")){const t=new yi;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])):Gi(t,n+1)}}},Ji=(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&&Gi(i,0)}}return o};class Zi{constructor(t,n){this.insertions=n,this.deletions=t,this.meta=new Map}}const ts=(t,n,e)=>{ti(t,e.deletions,(e=>{e instanceof Fo&&n.scope.some((n=>n===t.doc||_i(n,e)))&&zo(e,!1)}))},ns=(t,n,e)=>{let r=null;const i=t.doc,s=t.scope;Ji(i,(e=>{for(;n.length>0&&null===t.currStackItem;){const r=i.store,o=n.pop(),u=new Set,c=[];let h=!1;ti(e,o.insertions,(t=>{if(t instanceof Fo){if(null!==t.redone){let{item:n,diff:i}=_o(r,t.id);i>0&&(n=Ki(e,Oi(n.id.client,n.id.clock+i))),t=n}!t.deleted&&s.some((n=>n===e.doc||_i(n,t)))&&c.push(t)}})),ti(e,o.deletions,(t=>{t instanceof Fo&&s.some((n=>n===e.doc||_i(n,t)))&&!ni(o.insertions,t.id)&&u.add(t)})),u.forEach((n=>{h=null!==Ro(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 es extends Ut{constructor(t,{captureTimeout:n=500,captureTransaction:e=()=>!0,deleteFilter:r=()=>!0,trackedOrigins:i=new Set([null]),ignoreRemoteMapChanges:s=!1,doc:o=(Tt(t)?t[0].doc:t instanceof hi?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 Zr;t.afterState.forEach(((n,e)=>{const r=t.beforeState.get(e)||0,s=n-r;s>0&&ii(i,e,r,s)}));const s=Nn();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=ri([n.deletions,t.deleteSet]),n.insertions=ri([n.insertions,i])}else r.push(new Zi(t.deleteSet,i)),o=!0;n||e||(this.lastChange=s),ti(t,t.deleteSet,(n=>{n instanceof Fo&&this.scope.some((e=>e===t.doc||_i(e,n)))&&zo(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=Tt(t)?t:[t]).forEach((t=>{n.has(t)||(n.add(t),(t instanceof xs?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=>ts(e,this,t))),this.undoStack=[]),n&&(this.redoStack.forEach((t=>ts(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=ns(this,this.undoStack,"undo")}finally{this.undoing=!1}return t}redo(){let t;this.redoing=!0;try{t=ns(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 rs{constructor(t,n){this.gen=function*(t){const n=Tn(t.restDecoder);for(let e=0;e<n;e++){const n=Tn(t.restDecoder),e=t.readClient();let r=Tn(t.restDecoder);for(let i=0;i<n;i++){const n=t.readInfo();if(10===n){const n=Tn(t.restDecoder);yield new Bo(Oi(e,r),n),r+=n}else if(31&n){const i=!(192&n),s=new Fo(Oi(e,r),null,(n&Ft)===Ft?t.readLeftID():null,null,(n&Rt)===Rt?t.readRightID():null,i?t.readParentInfo()?t.readString():t.readLeftID():null,!i||32&~n?null:t.readString(),Lo(t,n));yield s,r+=s.length}else{const n=t.readLen();yield new po(Oi(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===Bo);return this.curr}}class is{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}}const ss=t=>us(t,li,vi),os=(t,n)=>{if(t.constructor===po){const{client:e,clock:r}=t.id;return new po(Oi(e,r+n),t.length-n)}if(t.constructor===Bo){const{client:e,clock:r}=t.id;return new Bo(Oi(e,r+n),t.length-n)}{const e=t,{client:r,clock:i}=e.id;return new Fo(Oi(r,i+n),null,Oi(r,i+n-1),null,e.rightOrigin,e.parent,e.parentSub,e.content.splice(n))}},us=(t,n=di,e=yi)=>{if(1===t.length)return t[0];const r=t.map((t=>new n(Cn(t))));let i=r.map((t=>new rs(t,!0))),s=null;const o=new e,u=new is(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===Bo?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)as(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===Bo)s.struct.length=e.id.clock+e.length-s.struct.id.clock;else{as(u,s.struct,s.offset);const t=e.id.clock-s.struct.id.clock-s.struct.length;s={struct:new Bo(Oi(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===Bo?s.struct.length-=n:e=os(e,n)),s.struct.mergeWith(e)||(as(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!==Bo;e=t.next())as(u,s.struct,s.offset),s={struct:e,offset:0}}null!==s&&(as(u,s.struct,s.offset),s=null),ls(u);const c=r.map((t=>oi(t))),h=ri(c);return si(o,h),o.toUint8Array()},cs=(t,n,e=di,r=yi)=>{const i=xi(n),s=new r,o=new is(s),u=new e(Cn(t)),c=new rs(u,!1);for(;c.curr;){const t=c.curr,n=t.id.client,e=i.get(n)||0;if(c.curr.constructor!==Bo)if(t.id.clock+t.length>e)for(as(o,t,zt(e-t.id.clock,0)),c.next();c.curr&&c.curr.id.client===n;)as(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()}ls(o);const h=oi(u);return si(s,h),s.toUint8Array()},hs=t=>{t.written>0&&(t.clientStructs.push({written:t.written,restEncoder:tn(t.encoder.restEncoder)}),t.encoder.restEncoder=Jt(),t.written=0)},as=(t,n,e)=>{t.written>0&&t.currClient!==n.id.client&&hs(t),0===t.written&&(t.currClient=n.id.client,t.encoder.writeClient(n.id.client),rn(t.encoder.restEncoder,n.id.clock+e)),n.write(t.encoder,e),t.written++},ls=t=>{hs(t);const n=t.encoder.restEncoder;rn(n,t.clientStructs.length);for(let e=0;e<t.clientStructs.length;e++){const r=t.clientStructs[e];rn(n,r.written),hn(n,r.restEncoder)}},fs=t=>((t,n,e,r)=>{const i=new di(Cn(t)),s=new rs(i,!1),o=new r,u=new is(o);for(let t=s.curr;null!==t;t=s.next())as(u,n(t),0);ls(u);const c=oi(i);return si(o,c),o.toUint8Array()})(t,ue,0,vi),ds="You must not compute changes after the event-handler fired.";class ps{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=vs(this.currentTarget,this.target))}deletes(t){return ni(this.transaction.deleteSet,t.id)}get keys(){if(null===this._keys){if(0===this.transaction.doc._transactionCleanups.length)throw mn(ds);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=Mt(t.content.getContent())}else null!==t&&this.deletes(t)?(i="update",s=Mt(t.content.getContent())):(i="add",s=void 0)}else{if(!this.deletes(r))return;i="delete",s=Mt(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 mn(ds);const n=this.target,e=xt(),r=xt(),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 vs=(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},ws=()=>{Yr("Invalid access: Add Yjs type to a document before reading data.")};let ys=0;class gs{constructor(t,n){t.marker=!0,this.p=t,this.index=n,this.timestamp=ys++}}const bs=(t,n,e)=>{t.p.marker=!1,t.p=n,n.marker=!0,t.index=e,t.timestamp=ys++},ms=(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)=>Ot(n-t.index)<Ot(n-e.index)?t:e));let r=t._start,i=0;for(null!==e&&(r=e.p,i=e.index,(t=>{t.timestamp=ys++})(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&&Ot(e.index-i)<r.parent.length/80?(bs(e,r,i),e):((t,n,e)=>{if(t.length>=80){const r=t.reduce(((t,n)=>t.timestamp<n.timestamp?t:n));return bs(r,n,e),r}{const r=new gs(n,e);return t.push(r),r}})(t._searchMarker,r,i)},ks=(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=zt(n,i.index+e))}},As=(t,n,e)=>{const r=t,i=n.changedParentTypes;for(;At(i,t,(()=>[])).push(e),null!==t._item;)t=t._item.parent;Ui(r._eH,e,n)};class xs{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=$i(),this._dEH=$i(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,n){this.doc=t,this._item=n}_copy(){throw kn()}clone(){throw kn()}_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){Ei(this._eH,t)}observeDeep(t){Ei(this._dEH,t)}unobserve(t){Ti(this._eH,t)}unobserveDeep(t){Ti(this._dEH,t)}toJSON(){}}const Ms=(t,n,e)=>{t.doc??ws(),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},Ss=t=>{t.doc??ws();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},Cs=(t,n)=>{let e=0,r=t._start;for(t.doc??ws();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}},$s=(t,n)=>{const e=[];return Cs(t,((r,i)=>{e.push(n(r,i,t))})),e},Es=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}}}},Ts=(t,n)=>{t.doc??ws();const e=ms(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}},Us=(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 Fo(Oi(o,Fi(u,o)),i,i&&i.lastId,c,c&&c.id,n,null,new xo(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 Fo(Oi(o,Fi(u,o)),i,i&&i.lastId,c,c&&c.id,n,null,new vo(new Uint8Array(e))),i.integrate(t,0);break;case hi:i=new Fo(Oi(o,Fi(u,o)),i,i&&i.lastId,c,c&&c.id,n,null,new go(e)),i.integrate(t,0);break;default:if(!(e instanceof xs))throw new Error("Unexpected content type in insert operation");i=new Fo(Oi(o,Fi(u,o)),i,i&&i.lastId,c,c&&c.id,n,null,new Oo(e)),i.integrate(t,0)}}})),a()},js=()=>mn("Length exceeded!"),Is=(t,n,e,r)=>{if(e>n._length)throw js();if(0===e)return n._searchMarker&&ks(n._searchMarker,e,r.length),Us(t,n,null,r);const i=e,s=ms(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&&Ki(t,Oi(o.id.client,o.id.clock+e));break}e-=o.length}return n._searchMarker&&ks(n._searchMarker,i,r.length),Us(t,n,o,r)},Os=(t,n,e,r)=>{if(0===r)return;const i=e,s=r,o=ms(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&&Ki(t,Oi(u.id.client,u.id.clock+e)),e-=u.length);for(;r>0&&null!==u;)u.deleted||(r<u.length&&Ki(t,Oi(u.id.client,u.id.clock+r)),u.delete(t),r-=u.length),u=u.right;if(r>0)throw js();n._searchMarker&&ks(n._searchMarker,i,-s+r)},_s=(t,n,e)=>{const r=n._map.get(e);void 0!==r&&r.delete(t)},zs=(t,n,e,r)=>{const i=n._map.get(e)||null,s=t.doc,o=s.clientID;let u;if(null==r)u=new xo([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:u=new xo([r]);break;case Uint8Array:u=new vo(r);break;case hi:u=new go(r);break;default:if(!(r instanceof xs))throw new Error("Unexpected content type");u=new Oo(r)}new Fo(Oi(o,Fi(s.store,o)),i,i&&i.lastId,null,null,n,e,u).integrate(t,0)},Ds=(t,n)=>{t.doc??ws();const e=t._map.get(n);return void 0===e||e.deleted?void 0:e.content.getContent()[e.length-1]},Ps=t=>{const n={};return t.doc??ws(),t._map.forEach(((t,e)=>{t.deleted||(n[e]=t.content.getContent()[t.length-1])})),n},Rs=(t,n)=>{t.doc??ws();const e=t._map.get(n);return void 0!==e&&!e.deleted},Fs=t=>{return t.doc??ws(),n=t._map.entries(),e=t=>!t[1].deleted,qr((()=>{let t;do{t=n.next()}while(!t.done&&!e(t.value));return t}));var n,e};class Ls extends ps{}class Ws extends xs{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){const n=new Ws;return n.push(t),n}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Ws}clone(){const t=new Ws;return t.insert(0,this.toArray().map((t=>t instanceof xs?t.clone():t))),t}get length(){return this.doc??ws(),this._length}_callObserver(t,n){super._callObserver(t,n),As(this,t,new Ls(this,t))}insert(t,n){null!==this.doc?Ji(this.doc,(e=>{Is(e,this,t,n)})):this._prelimContent.splice(t,0,...n)}push(t){null!==this.doc?Ji(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;Us(t,n,r,e)})(n,this,t)})):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,n=1){null!==this.doc?Ji(this.doc,(e=>{Os(e,this,t,n)})):this._prelimContent.splice(t,n)}get(t){return Ts(this,t)}toArray(){return Ss(this)}slice(t=0,n=this.length){return Ms(this,t,n)}toJSON(){return this.map((t=>t instanceof xs?t.toJSON():t))}map(t){return $s(this,t)}forEach(t){Cs(this,t)}[Symbol.iterator](){return Es(this)}_write(t){t.writeTypeRef(Co)}}class Bs extends ps{constructor(t,n,e){super(t,n),this.keysChanged=e}}class Ns extends xs{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 Ns}clone(){const t=new Ns;return this.forEach(((n,e)=>{t.set(e,n instanceof xs?n.clone():n)})),t}_callObserver(t,n){As(this,t,new Bs(this,t,n))}toJSON(){this.doc??ws();const t={};return this._map.forEach(((n,e)=>{if(!n.deleted){const r=n.content.getContent()[n.length-1];t[e]=r instanceof xs?r.toJSON():r}})),t}get size(){return[...Fs(this)].length}keys(){return Gr(Fs(this),(t=>t[0]))}values(){return Gr(Fs(this),(t=>t[1].content.getContent()[t[1].length-1]))}entries(){return Gr(Fs(this),(t=>[t[0],t[1].content.getContent()[t[1].length-1]]))}forEach(t){this.doc??ws(),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?Ji(this.doc,(n=>{_s(n,this,t)})):this._prelimContent.delete(t)}set(t,n){return null!==this.doc?Ji(this.doc,(e=>{zs(e,this,t,n)})):this._prelimContent.set(t,n),n}get(t){return Ds(this,t)}has(t){return Rs(this,t)}clear(){null!==this.doc?Ji(this.doc,(t=>{this.forEach((function(n,e,r){_s(t,r,e)}))})):this._prelimContent.clear()}_write(t){t.writeTypeRef($o)}}const Ks=(t,n)=>t===n||"object"==typeof t&&"object"==typeof n&&t&&n&&((t,n)=>t===n||ne(t)===ne(n)&&ee(t,((t,e)=>(void 0!==t||re(n,e))&&Gn(n[e],t))))(t,n);class Hs{constructor(t,n,e,r){this.left=t,this.right=n,this.index=e,this.currentAttributes=r}forward(){null===this.right&&An(),this.right.content.constructor===mo?this.right.deleted||Xs(this.currentAttributes,this.right.content):this.right.deleted||(this.index+=this.right.length),this.left=this.right,this.right=this.right.right}}const Vs=(t,n,e)=>{for(;null!==n.right&&e>0;)n.right.content.constructor===mo?n.right.deleted||Xs(n.currentAttributes,n.right.content):n.right.deleted||(e<n.right.length&&Ki(t,Oi(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?ms(n,e):null;if(s){const n=new Hs(s.p.left,s.p,s.index,i);return Vs(t,n,e-s.index)}{const r=new Hs(null,n._start,0,i);return Vs(t,r,e)}},Ys=(t,n,e,r)=>{for(;null!==e.right&&(!0===e.right.deleted||e.right.content.constructor===mo&&Ks(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 Fo(Oi(s,Fi(i.store,s)),u,u&&u.lastId,c,c&&c.id,n,null,new mo(o,r));h.integrate(t,0),e.right=h,e.forward()}))},Xs=(t,n)=>{const{key:e,value:r}=n;null===r?t.delete(e):t.set(e,r)},qs=(t,n)=>{for(;null!==t.right&&(t.right.deleted||t.right.content.constructor===mo&&Ks(n[t.right.content.key]??null,t.right.content.value));)t.forward()},Gs=(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(!Ks(h,c)){o.set(u,h);const{left:r,right:a}=e;e.right=new Fo(Oi(s,Fi(i.store,s)),r,r&&r.lastId,a,a&&a.id,n,null,new mo(u,c)),e.right.integrate(t,0),e.forward()}}return o},Js=(t,n,e,r,i)=>{e.currentAttributes.forEach(((t,n)=>{void 0===i[n]&&(i[n]=null)}));const s=t.doc,o=s.clientID;qs(e,i);const u=Gs(t,n,e,i),c=r.constructor===String?new Mo(r):r instanceof xs?new Oo(r):new bo(r);let{left:h,right:a,index:l}=e;n._searchMarker&&ks(n._searchMarker,e.index,c.getLength()),a=new Fo(Oi(o,Fi(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)},Zs=(t,n,e,r,i)=>{const s=t.doc,o=s.clientID;qs(e,i);const u=Gs(t,n,e,i);t:for(;null!==e.right&&(r>0||u.size>0&&(e.right.deleted||e.right.content.constructor===mo));){if(!e.right.deleted)switch(e.right.content.constructor){case mo:{const{key:n,value:s}=e.right.content,o=i[n];if(void 0!==o){if(Ks(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&&Ki(t,Oi(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 Fo(Oi(o,Fi(s.store,o)),e.left,e.left&&e.left.lastId,e.right,e.right&&e.right.id,n,null,new Mo(i)),e.right.integrate(t,0),e.forward()}Ys(t,n,e,u)},to=(t,n,e,r,i)=>{let s=n;const o=mt();for(;s&&(!s.countable||s.deleted);){if(!s.deleted&&s.content.constructor===mo){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 mo:{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||Xs(i,e);break}}}n=n.right}return u},no=t=>{let n=0;return Ji(t.doc,(e=>{let r=t._start,i=t._start,s=mt();const o=kt(s);for(;i;)!1===i.deleted&&(i.content.constructor===mo?Xs(o,i.content):(n+=to(e,r,i,s,o),s=kt(o),r=i)),i=i.right})),n},eo=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&&Vi(t,e.store.clients.get(r),s,i,(t=>{t.deleted||t.content.constructor!==mo||t.constructor===po||n.add(t.parent)}))}Ji(e,(e=>{ti(t,t.deleteSet,(t=>{t instanceof po||!t.parent._hasFormatting||n.has(t.parent)||(t.content.constructor===mo?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===mo){const r=n.content.key;e.has(r)?n.delete(t):e.add(r)}n=n.left}})(e,t))}));for(const t of n)no(t)}))},ro=(t,n,e)=>{const r=e,i=kt(n.currentAttributes),s=n.right;for(;e>0&&null!==n.right;){if(!1===n.right.deleted)switch(n.right.content.constructor){case Oo:case bo:case Mo:e<n.right.length&&Ki(t,Oi(n.right.id.client,n.right.id.clock+e)),e-=n.right.length,n.right.delete(t)}n.forward()}s&&to(t,s,n.right,i,n.currentAttributes);const o=(n.left||n.right).parent;return o._searchMarker&&ks(o._searchMarker,n.index,-r+e),n};class io extends ps{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=[];Ji(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=Jn({},o))),c=0}n&&t.push(n),s=null}};for(;null!==i;){switch(i.content.constructor){case Oo:case bo: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 Mo: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 mo:{const{key:t,value:u}=i.content;if(this.adds(i)){if(!this.deletes(i)){const c=e.get(t)??null;Ks(c,u)?null!==u&&i.delete(n):("retain"===s&&a(),Ks(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;Ks(n,u)||("retain"===s&&a(),o[t]=n)}else if(!i.deleted){r.set(t,u);const e=o[t];void 0!==e&&(Ks(e,u)?null!==e&&i.delete(n):("retain"===s&&a(),null===u?delete o[t]:o[t]=u))}i.deleted||("insert"===s&&a(),Xs(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 so extends xs{constructor(t){super(),this._pending=void 0!==t?[()=>this.insert(0,t)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??ws(),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 so}clone(){const t=new so;return t.applyDelta(this.toDelta()),t}_callObserver(t,n){super._callObserver(t,n);const e=new io(this,t,n);As(this,t,e),!t.local&&this._hasFormatting&&(t._needFormattingCleanup=!0)}toString(){this.doc??ws();let t="",n=this._start;for(;null!==n;)!n.deleted&&n.countable&&n.content.constructor===Mo&&(t+=n.content.str),n=n.right;return t}toJSON(){return this.toString()}applyDelta(t,{sanitize:n=!0}={}){null!==this.doc?Ji(this.doc,(e=>{const r=new Hs(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)&&Js(e,this,r,o,s.attributes||{})}else void 0!==s.retain?Zs(e,this,r,s.retain,s.attributes||{}):void 0!==s.delete&&ro(e,r,s.delete)}})):this._pending.push((()=>this.applyDelta(t)))}toDelta(t,n,e){this.doc??ws();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(zi(o,t)||void 0!==n&&zi(o,n))switch(o.content.constructor){case Mo:{const r=i.get("ychange");void 0===t||zi(o,t)?void 0===n||zi(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 Oo:case bo:{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 mo:zi(o,t)&&(u(),Xs(i,o.content))}o=o.right}u()};return t||n?Ji(this.doc,(e=>{t&&Di(e,t),n&&Di(e,n),c()}),"cleanup"):c(),r}insert(t,n,e){if(n.length<=0)return;const r=this.doc;null!==r?Ji(r,(r=>{const i=Qs(r,this,t,!e);e||(e={},i.currentAttributes.forEach(((t,n)=>{e[n]=t}))),Js(r,this,i,n,e)})):this._pending.push((()=>this.insert(t,n,e)))}insertEmbed(t,n,e){const r=this.doc;null!==r?Ji(r,(r=>{const i=Qs(r,this,t,!e);Js(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?Ji(e,(e=>{ro(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?Ji(r,(r=>{const i=Qs(r,this,t,!1);null!==i.right&&Zs(r,this,i,n,e)})):this._pending.push((()=>this.format(t,n,e)))}removeAttribute(t){null!==this.doc?Ji(this.doc,(n=>{_s(n,this,t)})):this._pending.push((()=>this.removeAttribute(t)))}setAttribute(t,n){null!==this.doc?Ji(this.doc,(e=>{zs(e,this,t,n)})):this._pending.push((()=>this.setAttribute(t,n)))}getAttribute(t){return Ds(this,t)}getAttributes(){return Ps(this)}_write(t){t.writeTypeRef(Eo)}}class oo{constructor(t,n=()=>!0){this._filter=n,this._root=t,this._currentNode=t._start,this._firstCall=!0,t.doc??ws()}[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!==co&&n.constructor!==uo||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 uo extends xs{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 uo}clone(){const t=new uo;return t.insert(0,this.toArray().map((t=>t instanceof xs?t.clone():t))),t}get length(){return this.doc??ws(),null===this._prelimContent?this._length:this._prelimContent.length}createTreeWalker(t){return new oo(this,t)}querySelector(t){t=t.toUpperCase();const n=new oo(this,(n=>n.nodeName&&n.nodeName.toUpperCase()===t)).next();return n.done?null:n.value}querySelectorAll(t){return t=t.toUpperCase(),Ct(new oo(this,(n=>n.nodeName&&n.nodeName.toUpperCase()===t)))}_callObserver(t,n){As(this,t,new ho(this,n,t))}toString(){return $s(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),Cs(this,(i=>{r.insertBefore(i.toDOM(t,n,e),null)})),r}insert(t,n){null!==this.doc?Ji(this.doc,(e=>{Is(e,this,t,n)})):this._prelimContent.splice(t,0,...n)}insertAfter(t,n){if(null!==this.doc)Ji(this.doc,(e=>{Us(e,this,t&&t instanceof xs?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 mn("Reference item not found");e.splice(r,0,...n)}}delete(t,n=1){null!==this.doc?Ji(this.doc,(e=>{Os(e,this,t,n)})):this._prelimContent.splice(t,n)}toArray(){return Ss(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return Ts(this,t)}slice(t=0,n=this.length){return Ms(this,t,n)}forEach(t){Cs(this,t)}_write(t){t.writeTypeRef(Uo)}}class co extends uo{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 co(this.nodeName)}clone(){const t=new co(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 xs?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?Ji(this.doc,(n=>{_s(n,this,t)})):this._prelimAttrs.delete(t)}setAttribute(t,n){null!==this.doc?Ji(this.doc,(e=>{zs(e,this,t,n)})):this._prelimAttrs.set(t,n)}getAttribute(t){return Ds(this,t)}hasAttribute(t){return Rs(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&&zi(i,n)&&(e[r]=i.content.getContent()[i.length-1])})),e})(0,t):Ps(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 Cs(this,(i=>{r.appendChild(i.toDOM(t,n,e))})),void 0!==e&&e._createAssociation(r,this),r}_write(t){t.writeTypeRef(To),t.writeKey(this.nodeName)}}class ho extends ps{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 ao extends Ns{constructor(t){super(),this.hookName=t}_copy(){return new ao(this.hookName)}clone(){const t=new ao(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 lo extends so{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 lo}clone(){const t=new lo;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(Io)}}class fo{constructor(t,n){this.id=t,this.length=n}get deleted(){throw kn()}mergeWith(t){return!1}write(t,n,e){throw kn()}integrate(t,n){throw kn()}}class po extends fo{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),Li(t.doc.store,this)}write(t,n){t.writeInfo(0),t.writeLen(this.length-n)}getMissing(t,n){return null}}class vo{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new vo(this.content)}splice(t){throw kn()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeBuf(this.content)}getRef(){return 3}}class wo{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new wo(this.len)}splice(t){const n=new wo(this.len-t);return this.len=t,n}mergeWith(t){return this.len+=t.len,!0}integrate(t,n){ii(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 yo=(t,n)=>new hi({guid:t,...n,shouldLoad:n.shouldLoad||n.autoLoad||!1});class go{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 go(yo(this.doc.guid,this.opts))}splice(t){throw kn()}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 bo{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new bo(this.embed)}splice(t){throw kn()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeJSON(this.embed)}getRef(){return 5}}class mo{constructor(t,n){this.key=t,this.value=n}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new mo(this.key,this.value)}splice(t){throw kn()}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 ko{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new ko(this.arr)}splice(t){const n=new ko(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 Ao="development"===de("node_env");class xo{constructor(t){this.arr=t,Ao&&se(t)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new xo(this.arr)}splice(t){const n=new xo(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 Mo{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new Mo(this.str)}splice(t){const n=new Mo(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 So=[()=>new Ws,()=>new Ns,()=>new so,t=>new co(t.readKey()),()=>new uo,t=>new ao(t.readKey()),()=>new lo],Co=0,$o=1,Eo=2,To=3,Uo=4,jo=5,Io=6;class Oo{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new Oo(this.type._copy())}splice(t){throw kn()}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=Oi(r.client,r.clock+i)),e=Bi(t,r),i=r.clock-e.id.clock,r=e.redone}while(null!==r&&e instanceof Fo);return{item:e,diff:i}},zo=(t,n)=>{for(;null!==t&&t.keep!==n;)t.keep=n,t=t.parent._item},Do=(t,n,e)=>{const{client:r,clock:i}=n.id,s=new Fo(Oi(r,i+e),n,Oi(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=Oi(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},Po=(t,n)=>Et(t,(t=>ni(t.deletions,n))),Ro=(t,n,e,r,i,s)=>{const o=t.doc,u=o.store,c=o.clientID,h=n.redone;if(null!==h)return Ki(t,h);let a,l=n.parent._item,f=null;if(null!==l&&!0===l.deleted){if(null===l.redone&&(!e.has(l)||null===Ro(t,l,e,r,i,s)))return null;for(;null!==l.redone;)l=Ki(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:Ki(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:Ki(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||ni(r,f.right.id)||Po(s.undoStack,f.right.id)||Po(s.redoStack,f.right.id));)for(f=f.right;f.redone;)f=Ki(t,f.redone);if(f&&null!==f.right)return null}else f=d._map.get(n.parentSub)||null;const p=Fi(u,c),v=Oi(c,p),w=new Fo(v,f,f&&f.lastId,a,a&&a.id,d,n.parentSub,n.content.copy());return n.redone=v,zo(w,!0),w.integrate(t,0),w};class Fo extends fo{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>=Fi(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=Fi(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===ji&&this.id.client!==this.parent.client&&this.parent.clock>=Fi(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=Hi(t,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=Ki(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===po||this.right&&this.right.constructor===po)this.parent=null;else if(this.parent){if(this.parent.constructor===ji){const t=Bi(n,this.parent);this.parent=t.constructor===po?null:t.content.type}}else this.left&&this.left.constructor===Fo?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===Fo&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);return null}integrate(t,n){if(n>0&&(this.id.clock+=n,this.left=Hi(t,t.doc.store,Oi(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),Ii(this.origin,n.origin)){if(n.id.client<this.id.client)e=n,r.clear();else if(Ii(this.rightOrigin,n.rightOrigin))break}else{if(null===n.origin||!i.has(Bi(t.doc.store,n.origin)))break;r.has(Bi(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),Li(t.doc.store,this),this.content.integrate(t,this),Xi(t,this.parent,this.parentSub),(null!==this.parent._item&&this.parent._item.deleted||null!==this.parentSub&&null!==this.right)&&this.delete(t)}else new po(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:Oi(this.id.client,this.id.clock+this.length-1)}mergeWith(t){if(this.constructor===t.constructor&&Ii(t.origin,this.lastId)&&this.right===t&&Ii(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(),ii(t.deleteSet,this.id.client,this.id.clock,this.length),Xi(t,n,this.parentSub),this.content.delete(t)}}gc(t,n){if(!this.deleted)throw An();this.content.gc(t),n?((t,n,e)=>{const r=t.clients.get(n.id.client);r[Wi(r,n.id.clock)]=e})(t,this,new po(this.id,this.length)):this.content=new wo(this.length)}write(t,n){const e=n>0?Oi(this.id.client,this.id.clock+n-1):this.origin,r=this.rightOrigin,i=this.parentSub,s=31&this.content.getRef()|(null===e?0:Ft)|(null===r?0:Rt)|(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 An()})(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)):An();null!==i&&t.writeString(i)}this.content.write(t,n)}}const Lo=(t,n)=>Wo[31&n](t),Wo=[()=>{An()},t=>new wo(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 ko(e)},t=>new vo(t.readBuf()),t=>new Mo(t.readString()),t=>new bo(t.readJSON()),t=>new mo(t.readKey(),t.readJSON()),t=>new Oo(So[t.readTypeRef()](t)),t=>{const n=t.readLen(),e=[];for(let r=0;r<n;r++)e.push(t.readAny());return new xo(e)},t=>new go(yo(t.readString(),t.readAny())),()=>{An()}];class Bo extends fo{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor===t.constructor&&(this.length+=t.length,!0)}integrate(t,n){An()}write(t,n){t.writeInfo(10),rn(t.restEncoder,this.length-n)}getMissing(t,n){return null}}const No="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},Ko="__ $YJS$ __";!0===No[Ko]&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438"),No[Ko]=!0;const Ho=t=>Kn(((n,e)=>{t.onerror=t=>e(new Error(t.target.error)),t.onsuccess=t=>n(t.target.result)})),Vo=(t,n,e="readwrite")=>{const r=t.transaction(n,e);return n.map((t=>Go(r,t)))},Qo=(t,n)=>Ho(t.count(n)),Yo=(t,n)=>Ho(t.delete(n)),Xo=(t,n)=>Ho(t.add(n)),qo=(t,n,e,r="next")=>((t,n)=>Kn(((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))),Go=(t,n)=>t.objectStore(n),Jo="custom",Zo="updates",tu=(t,n=()=>{},e=()=>{})=>{const[r]=Vo(t.db,[Zo]);return(i=r,o=t._dbref,s=IDBKeyRange.lowerBound(o,false),Ho(i.getAll(s,undefined))).then((i=>{t._destroyed||(n(r),Ji(t.doc,(()=>{i.forEach((n=>mi(t.doc,n)))}),t,!1),e(r))})).then((()=>((t,n=null)=>((t,n)=>{let e=null;return qo(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 nu 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=>Kn(((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(mn(t.target.error)),r.onsuccess=t=>{const e=t.target.result;e.onversionchange=()=>{e.close()},n(e)}})))(t),this.whenSynced=Kn((t=>this.on("synced",(()=>t(this))))),this._db.then((t=>{this.db=t,tu(this,(t=>Xo(t,Ai(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]=Vo(this.db,[Zo]);Xo(n,t),++this._dbsize>=500&&(null!==this._storeTimeoutId&&clearTimeout(this._storeTimeoutId),this._storeTimeoutId=setTimeout((()=>{((t,n=!0)=>{tu(t).then((e=>{(n||t._dbsize>=500)&&Xo(e,Ai(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((()=>{Ho(indexedDB.deleteDatabase(this.name))}))}get(t){return this._db.then((n=>{const[e]=Vo(n,[Jo],"readonly");return((t,n)=>Ho(t.get(n)))(e,t)}))}set(t,n){return this._db.then((e=>{const[r]=Vo(e,[Jo]);return((t,n,e)=>Ho(t.put(n,e)))(r,n,t)}))}del(t){return this._db.then((n=>{const[e]=Vo(n,[Jo]);return Yo(e,t)}))}}class eu{provider;isConnected=!1;constructor(t,n,e){this.provider=new nu(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 ru=Math.floor,iu=127,su=Number.MAX_SAFE_INTEGER,ou="undefined"!=typeof TextEncoder?new TextEncoder:null,uu=ou?t=>ou.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 cu="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});cu&&1===cu.decode(new Uint8Array).length&&(cu=null);const hu=(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},au=(t,n)=>{for(;n>iu;)hu(t,128|iu&n),n=ru(n/128);hu(t,iu&n)},lu=new Uint8Array(3e4),fu=lu.length/3,du=ou&&ou.encodeInto?(t,n)=>{if(n.length<fu){const e=ou.encodeInto(n,lu).written||0;au(t,e);for(let n=0;n<e;n++)hu(t,lu[n])}else pu(t,uu(n))}:(t,n)=>{const e=unescape(encodeURIComponent(n)),r=e.length;au(t,r);for(let n=0;n<r;n++)hu(t,e.codePointAt(n))},pu=(t,n)=>{au(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)},vu=t=>new Error(t),wu=vu("Unexpected end of array"),yu=vu("Integer out of Range"),gu=t=>t.arr[t.pos++],bu=t=>{let n=0,e=1;const r=t.arr.length;for(;t.pos<r;){const r=t.arr[t.pos++];if(n+=(r&iu)*e,e*=128,r<128)return n;if(n>su)throw yu}throw wu},mu=cu?t=>cu.decode((t=>((t,n)=>{const e=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,n);return t.pos+=n,e})(t,bu(t)))(t)):t=>{let n=bu(t);if(0===n)return"";{let e=String.fromCodePoint(gu(t));if(--n<100)for(;n--;)e+=String.fromCodePoint(gu(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 ku;!function(t){t[t.Token=0]="Token",t[t.PermissionDenied=1]="PermissionDenied",t[t.Authenticated=2]="Authenticated"}(ku||(ku={}));const Au=t=>Array.from(t.entries()).map((([t,n])=>({clientId:t,...n})));var xu;async function Mu(t){return new Promise((n=>setTimeout(n,t)))}function Su(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"}(xu||(xu={}));const Cu=Math.floor,$u=128,Eu=127,Tu=Number.MAX_SAFE_INTEGER,Uu=()=>new Set,ju=Array.from,Iu="undefined"!=typeof TextEncoder?new TextEncoder:null,Ou=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 _u="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});_u&&1===_u.decode(new Uint8Array).length&&(_u=null);class zu{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const Du=()=>new zu,Pu=t=>{let n=t.cpos;for(let e=0;e<t.bufs.length;e++)n+=t.bufs[e].length;return n},Ru=t=>{const n=new Uint8Array(Pu(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},Fu=(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},Lu=(t,n)=>{for(;n>Eu;)Fu(t,$u|Eu&n),n=Cu(n/128);Fu(t,Eu&n)},Wu=new Uint8Array(3e4),Bu=Wu.length/3,Nu=Iu&&Iu.encodeInto?(t,n)=>{if(n.length<Bu){const e=Iu.encodeInto(n,Wu).written||0;Lu(t,e);for(let n=0;n<e;n++)Fu(t,Wu[n])}else Ku(t,Ou(n))}:(t,n)=>{const e=unescape(encodeURIComponent(n)),r=e.length;Lu(t,r);for(let n=0;n<r;n++)Fu(t,e.codePointAt(n))},Ku=(t,n)=>{Lu(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)},Hu=t=>new Error(t),Vu=Hu("Unexpected end of array"),Qu=Hu("Integer out of Range");class Yu{constructor(t){this.arr=t,this.pos=0}}const Xu=t=>new Yu(t),qu=t=>((t,n)=>{const e=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,n);return t.pos+=n,e})(t,Ju(t)),Gu=t=>t.arr[t.pos++],Ju=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<$u)return n;if(n>Tu)throw Qu}throw Vu},Zu=_u?t=>_u.decode(qu(t)):t=>{let n=Ju(t);if(0===n)return"";{let e=String.fromCodePoint(Gu(t));if(--n<100)for(;n--;)e+=String.fromCodePoint(Gu(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))}},tc=Date.now,nc=()=>new Map;class ec{constructor(){this._observers=nc()}on(t,n){((t,n,e)=>{let r=t.get(n);return void 0===r&&t.set(n,r=e()),r})(this._observers,t,Uu).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)||nc()).values()).forEach((t=>t(...n)))}destroy(){this._observers=nc()}}const rc=Object.keys,ic=t=>rc(t).length,sc=(t,n)=>Object.prototype.hasOwnProperty.call(t,n),oc=(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)||!oc(t.get(e),n.get(e)))return!1;break;case Object:if(ic(t)!==ic(n))return!1;for(const e in t)if(!sc(t,e)||!oc(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(!oc(t[e],n[e]))return!1;break;default:return!1}return!0};class uc extends ec{constructor(t){super(),this.doc=t,this.clientID=t.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval((()=>{const t=tc();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&&cc(this,n,"timeout")}),Cu(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:tc()});const s=[],o=[],u=[],c=[];null===t?c.push(n):null==i?null!=t&&s.push(n):(o.push(n),oc(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 cc=(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:tc()})}r.push(i)}}r.length>0&&(t.emit("change",[{added:[],updated:[],removed:r},e]),t.emit("update",[{added:[],updated:[],removed:r},e]))},hc=(t,n,e=t.states)=>{const r=n.length,i=Du();Lu(i,r);for(let s=0;s<r;s++){const r=n[s],o=e.get(r)||null,u=t.meta.get(r).clock;Lu(i,r),Lu(i,u),Nu(i,JSON.stringify(o))}return Ru(i)};class ac{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 lc{constructor(t){this.data=t,this.encoder=Du(),this.decoder=Xu(new Uint8Array(this.data))}peekVarString(){return(t=>{const n=t.pos,e=Zu(t);return t.pos=n,e})(this.decoder)}readVarUint(){return Ju(this.decoder)}readVarString(){return Zu(this.decoder)}readVarUint8Array(){return qu(this.decoder)}writeVarUint(t){return Lu(this.encoder,t)}writeVarString(t){return Nu(this.encoder,t)}writeVarUint8Array(t){return Ku(this.encoder,t)}length(){return Pu(this.encoder)}}var fc,dc;!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"}(fc||(fc={})),function(t){t.Connecting="connecting",t.Connected="connected",t.Disconnected="disconnected"}(dc||(dc={}));class pc{constructor(){this.encoder=Du()}get(t){return t.encoder}toUint8Array(){return Ru(this.encoder)}}class vc extends pc{constructor(){super(...arguments),this.type=fc.CLOSE,this.description="Ask the server to close the connection"}get(t){return Nu(this.encoder,t.documentName),Lu(this.encoder,this.type),this.encoder}}class wc extends ac{constructor(t){super(),this.messageQueue=[],this.configuration={url:"",autoConnect:!0,preserveTrailingSlash:!1,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=dc.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=dc.Connected,this.emit("status",{status:dc.Connected}),this.cancelWebsocketRetry=void 0,this.receivedOnOpenPayload=t}attach(t){this.configuration.providerMap.set(t.configuration.name,t),this.status===dc.Disconnected&&this.shouldConnect&&this.connect(),this.receivedOnOpenPayload&&this.status===dc.Connected&&t.onOpen(this.receivedOnOpenPayload)}detach(t){this.configuration.providerMap.has(t.configuration.name)&&(t.send(vc,{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===dc.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||Su,s=e.calculateDelay?e.calculateDelay(r,e):e.initialDelay;if(s&&await Mu(s),r.attemptNum<1&&e.initialJitter){const t=i(r,e);t&&await Mu(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 Mu(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=dc.Connecting,this.emit("status",{status:dc.Connecting}),this.connectionAttempt={resolve:t,reject:n}}))}onMessage(t){var n;this.resolveConnectionAttempt(),this.lastMessageReceived=tc();const e=new lc(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=dc.Connected,this.emit("status",{status:dc.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===dc.Connected&&this.lastMessageReceived&&(this.configuration.messageReconnectTimeout>=tc()-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(){if(this.configuration.preserveTrailingSlash)return this.configuration.url;let t=this.configuration.url;for(;"/"===t[t.length-1];)t=t.slice(0,t.length-1);return t}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)===xu.Open?this.webSocket.send(t):this.messageQueue.push(t)}onClose({event:t}){this.closeTries=0,this.cleanupWebSocket(),this.connectionAttempt&&this.rejectConnectionAttempt(),this.status=dc.Disconnected,this.emit("status",{status:dc.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 yc=(t,n,e)=>{try{mi(n,qu(t),e)}catch(t){console.error("Caught error while handling a Yjs update",t)}},gc=yc;class bc{constructor(t){this.message=t}apply(t,n){const{message:e}=this,r=e.readVarUint(),i=e.length();switch(r){case fc.Sync:this.applySyncMessage(t,n);break;case fc.Awareness:this.applyAwarenessMessage(t);break;case fc.Auth:this.applyAuthMessage(t);break;case fc.QueryAwareness:this.applyQueryAwarenessMessage(t);break;case fc.Stateless:t.receiveStateless(Zu(e.decoder));break;case fc.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&$u))return i*e;const s=t.arr.length;for(;t.pos<s;){if(n=t.arr[t.pos++],e+=(n&Eu)*r,r*=128,n<$u)return i*e;if(e>Tu)throw Qu}throw Vu})(e.decoder));break;case fc.CLOSE:const i={code:1e3,reason:Zu(e.decoder),target:t.configuration.websocketProvider.webSocket,type:"close"};t.onClose(),t.configuration.onClose({event:i}),t.forwardClose({event:i});break;default:throw new Error(`Can’t apply message of unknown type: ${r}`)}e.length()>i+1&&t.send(pc,{encoder:e.encoder})}applySyncMessage(t,n){const{message:e}=this;e.writeVarUint(fc.Sync);const r=((t,n,e,r)=>{const i=Ju(t);switch(i){case 0:((t,n,e)=>{((t,n,e)=>{Lu(t,1),Ku(t,Ai(n,e))})(n,e,qu(t))})(t,n,e);break;case 1:yc(t,e,r);break;case 2:gc(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=Xu(n),i=tc(),s=[],o=[],u=[],c=[],h=Ju(r);for(let n=0;n<h;n++){const n=Ju(r);let e=Ju(r);const h=JSON.parse(Zu(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&&(oc(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(bu(t)){case ku.Token:n();break;case ku.PermissionDenied:e(mu(t));break;case ku.Authenticated:r(mu(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(fc.Awareness),n.writeVarUint8Array(hc(t.awareness,Array.from(t.awareness.getStates().keys())))}}class mc{constructor(t,n={}){this.message=new t,this.encoder=this.message.get(n)}create(){return Ru(this.encoder)}send(t){null==t||t.send(this.create())}}class kc extends pc{constructor(){super(...arguments),this.type=fc.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 Nu(this.encoder,t.documentName),Lu(this.encoder,this.type),e=t.token,au(n=this.encoder,ku.Token),du(n,e),this.encoder}}class Ac extends pc{constructor(){super(...arguments),this.type=fc.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 Nu(this.encoder,t.documentName),Lu(this.encoder,this.type),n=void 0===t.states?hc(t.awareness,t.clients):hc(t.awareness,t.clients,t.states),Ku(this.encoder,n),this.encoder}}class xc extends pc{constructor(){super(...arguments),this.type=fc.Stateless,this.description="A stateless message"}get(t){var n;return Nu(this.encoder,t.documentName),Lu(this.encoder,this.type),Nu(this.encoder,null!==(n=t.payload)&&void 0!==n?n:""),this.encoder}}class Mc extends pc{constructor(){super(...arguments),this.type=fc.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 Nu(this.encoder,t.documentName),Lu(this.encoder,this.type),((t,n)=>{Lu(t,0);const e=Si(n);Ku(t,e)})(this.encoder,t.document),this.encoder}}class Sc extends pc{constructor(){super(...arguments),this.type=fc.Sync,this.description="A document update"}get(t){var n,e;return Nu(this.encoder,t.documentName),Lu(this.encoder,this.type),e=t.update,Lu(n=this.encoder,2),Ku(n,e),this.encoder}}class Cc extends Error{constructor(){super(...arguments),this.code=1001}}class $c extends ac{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 hi,this.configuration.awareness=void 0!==t.awareness?t.awareness:new uc(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:Au(this.awareness.getStates())})})),null===(e=this.awareness)||void 0===e||e.on("change",(()=>{this.emit("awarenessChange",{states:Au(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={}){t.websocketProvider||(this.manageSocket=!0,this.configuration.websocketProvider=new wc(t)),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(Mc,{document:this.document,documentName:this.configuration.name})}pageHide(){this.awareness&&cc(this.awareness,[this.document.clientID],"page hide")}registerEventListeners(){"undefined"!=typeof window&&"addEventListener"in window&&window.addEventListener("pagehide",this.boundPageHide)}sendStateless(t){this.send(xc,{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(kc,{token:null!=t?t:"",documentName:this.configuration.name})}documentUpdateHandler(t,n){n!==this&&(this.incrementUnsyncedChanges(),this.send(Sc,{update:t,documentName:this.configuration.name}))}awarenessUpdateHandler({added:t,updated:n,removed:e},r){const i=t.concat(n).concat(e);this.send(Ac,{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(Mc,{document:this.document,documentName:this.configuration.name}),this.awareness&&null!==this.awareness.getLocalState()&&this.send(Ac,{awareness:this.awareness,clients:[this.document.clientID],documentName:this.configuration.name})}send(t,n){if(!this._isAttached)return;const e=new mc(t,n);this.emit("outgoingMessage",{message:e.message}),e.send(this.configuration.websocketProvider)}onMessage(t){const n=new lc(t.data),e=n.readVarString();n.writeVarString(e),this.emit("message",{event:t,message:new lc(t.data)}),new bc(n).apply(this,!0)}onClose(){this.isAuthenticated=!1,this.synced=!1,this.awareness&&cc(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&&(cc(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 Cc(`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 Ec={providers:[eu]};class Tc{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 hi,this._workspacesMap=this._ydoc.getMap("workspaces");const e="kritzel-app-state",r=n??Ec;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 Uc{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(!Uc.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,p=c?.localY??t.endY;if(u&&t.hasStartArrow){const n=t.getArrowSize("start"),e=d-l,r=p-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-p,i=Math.sqrt(e*e+r*r);i>n&&(d+=e/i*n,p+=r/i*n)}return`M ${l-h} ${f-a} L ${d-h} ${p-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(Uc.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 Uc.isInstanceOf(t,"KritzelShape")?t.getClipPolygon():null}getPathClipPoint(t,n){return Uc.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 p)&&!(t instanceof l)&&t.isVisible}}const Ic=1e3,Oc=1e-4;var _c,zc,Dc,Pc={exports:{}},Rc=(_c||(_c=1,zc=Pc,Dc=Pc.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]",p="[object Date]",v="[object Error]",w="[object Function]",y="[object GeneratorFunction]",g="[object Map]",b="[object Number]",m="[object Object]",k="[object Promise]",A="[object RegExp]",x="[object Set]",M="[object String]",S="[object Symbol]",C="[object WeakMap]",$="[object ArrayBuffer]",E="[object DataView]",T="[object Float32Array]",U="[object Float64Array]",j="[object Int8Array]",I="[object Int16Array]",O="[object Int32Array]",_="[object Uint8Array]",z="[object Uint8ClampedArray]",D="[object Uint16Array]",R="[object Uint32Array]",F=/\b__p \+= '';/g,L=/\b(__p \+=) '' \+/g,W=/(__e\(.*?\)|\b__t\)) \+\n'';/g,B=/&(?:amp|lt|gt|quot|#39);/g,N=/[&<>"']/g,K=RegExp(B.source),H=RegExp(N.source),V=/<%-([\s\S]+?)%>/g,Q=/<%([\s\S]+?)%>/g,Y=/<%=([\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,pt=/^(?:0|[1-9]\d*)$/,vt=/[\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",kt="a-z\\xdf-\\xf6\\xf8-\\xff",At="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+"]",$t="["+bt+"]",Et="\\d+",Tt="["+mt+"]",Ut="["+kt+"]",jt="[^"+gt+Mt+Et+mt+kt+At+"]",It="\\ud83c[\\udffb-\\udfff]",Ot="[^"+gt+"]",_t="(?:\\ud83c[\\udde6-\\uddff]){2}",zt="[\\ud800-\\udbff][\\udc00-\\udfff]",Dt="["+At+"]",Pt="\\u200d",Rt="(?:"+Ut+"|"+jt+")",Ft="(?:"+Dt+"|"+jt+")",Lt="(?:['’](?:d|ll|m|re|s|t|ve))?",Wt="(?:['’](?:D|LL|M|RE|S|T|VE))?",Bt="(?:"+$t+"|"+It+")?",Nt="["+xt+"]?",Kt=Nt+Bt+"(?:"+Pt+"(?:"+[Ot,_t,zt].join("|")+")"+Nt+Bt+")*",Ht="(?:"+[Tt,_t,zt].join("|")+")"+Kt,Vt="(?:"+[Ot+$t+"?",$t,_t,zt,St].join("|")+")",Qt=RegExp("['’]","g"),Yt=RegExp($t,"g"),Xt=RegExp(It+"(?="+It+")|"+Vt+Kt,"g"),qt=RegExp([Dt+"?"+Ut+"+"+Lt+"(?="+[Ct,Dt,"$"].join("|")+")",Ft+"+"+Wt+"(?="+[Ct,Dt+Rt,"$"].join("|")+")",Dt+"?"+Rt+"+"+Lt,Dt+"+"+Wt,"\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])","\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",Et,Ht].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[T]=nn[U]=nn[j]=nn[I]=nn[O]=nn[_]=nn[z]=nn[D]=nn[R]=!0,nn[l]=nn[f]=nn[$]=nn[d]=nn[E]=nn[p]=nn[v]=nn[w]=nn[g]=nn[b]=nn[m]=nn[A]=nn[x]=nn[M]=nn[C]=!1;var en={};en[l]=en[f]=en[$]=en[E]=en[d]=en[p]=en[T]=en[U]=en[j]=en[I]=en[O]=en[g]=en[b]=en[m]=en[A]=en[x]=en[M]=en[S]=en[_]=en[z]=en[D]=en[R]=!0,en[v]=en[w]=en[C]=!1;var rn={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"},sn=parseFloat,on=parseInt,un="object"==typeof P&&P&&P.Object===Object&&P,cn="object"==typeof self&&self&&self.Object===Object&&self,hn=un||cn||Function("return this")(),an=Dc&&!Dc.nodeType&&Dc,ln=an&&zc&&!zc.nodeType&&zc,fn=ln&&ln.exports===an,dn=fn&&un.process,pn=function(){try{return ln&&ln.require&&ln.require("util").types||dn&&dn.binding&&dn.binding("util")}catch(t){}}(),vn=pn&&pn.isArrayBuffer,wn=pn&&pn.isDate,yn=pn&&pn.isMap,gn=pn&&pn.isRegExp,bn=pn&&pn.isSet,mn=pn&&pn.isTypedArray;function kn(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 An(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 $n(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 Tn(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 Un(t,n){for(var e=-1,r=n.length,i=t.length;++e<r;)t[i+e]=n[e];return t}function jn(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 In(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 _n=Wn("length");function zn(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,Fn,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 Fn(t){return t!=t}function Ln(t,n){var e=null==t?0:t.length;return e?Kn(t,n)/e:c}function Wn(n){return function(e){return null==e?t:e[n]}}function Bn(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 Hn(t,n){for(var e=-1,r=Array(t);++e<t;)r[e]=n(e);return r}function Vn(t){return t?t.slice(0,he(t)+1).replace(tt,""):t}function Qn(t){return function(n){return t(n)}}function Yn(t,n){return Tn(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=Bn({À:"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=Bn({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"});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):_n(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=Bn({"&amp;":"&","&lt;":"<","&gt;":">","&quot;":'"',"&#39;":"'"}),le=function P(nt){var gt,bt=(nt=null==nt?hn:le.defaults(hn.Object(),nt,le.pick(hn,Zt))).Array,mt=nt.Date,kt=nt.Error,At=nt.Function,xt=nt.Math,Mt=nt.Object,St=nt.RegExp,Ct=nt.String,$t=nt.TypeError,Et=bt.prototype,Tt=Mt.prototype,Ut=nt["__core-js_shared__"],jt=At.prototype.toString,It=Tt.hasOwnProperty,Ot=0,_t=(gt=/[^.]+$/.exec(Ut&&Ut.keys&&Ut.keys.IE_PROTO||""))?"Symbol(src)_1."+gt:"",zt=Tt.toString,Dt=jt.call(Mt),Pt=hn._,Rt=St("^"+jt.call(It).replace(J,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Ft=fn?nt.Buffer:t,Lt=nt.Symbol,Wt=nt.Uint8Array,Bt=Ft?Ft.allocUnsafe:t,Nt=re(Mt.getPrototypeOf,Mt),Kt=Mt.create,Ht=Tt.propertyIsEnumerable,Vt=Et.splice,Xt=Lt?Lt.isConcatSpreadable:t,Gt=Lt?Lt.iterator:t,rn=Lt?Lt.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,pn=xt.floor,_n=Mt.getOwnPropertySymbols,Bn=Ft?Ft.isBuffer:t,fe=nt.isFinite,de=Et.join,pe=re(Mt.keys,Mt),ve=xt.max,we=xt.min,ye=mt.now,ge=nt.parseInt,be=xt.random,me=Et.reverse,ke=us(nt,"DataView"),Ae=us(nt,"Map"),xe=us(nt,"Promise"),Me=us(nt,"Set"),Se=us(nt,"WeakMap"),Ce=us(Mt,"create"),$e=Se&&new Se,Ee={},Te=Os(ke),Ue=Os(Ae),je=Os(xe),Ie=Os(Me),Oe=Os(Se),_e=Lt?Lt.prototype:t,ze=_e?_e.valueOf:t,De=_e?_e.toString:t;function Pe(t){if(Go(t)&&!Lo(t)&&!(t instanceof We)){if(t instanceof Le)return t;if(It.call(t,"__wrapped__"))return _s(t)}return new Le(t)}var Re=function(){function n(){}return function(e){if(!qo(e))return{};if(Kt)return Kt(e);n.prototype=e;var r=new n;return n.prototype=t,r}}();function Fe(){}function Le(n,e){this.__wrapped__=n,this.__actions__=[],this.__chain__=!!e,this.__index__=0,this.__values__=t}function We(t){this.__wrapped__=t,this.__actions__=[],this.__dir__=1,this.__filtered__=!1,this.__iteratees__=[],this.__takeCount__=h,this.__views__=[]}function Be(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 He(t){var n=-1,e=null==t?0:t.length;for(this.__data__=new Ke;++n<e;)this.add(t[n])}function Ve(t){var n=this.__data__=new Ne(t);this.size=n.size}function Qe(t,n){var e=Lo(t),r=!e&&Fo(t),i=!e&&!r&&Ko(t),s=!e&&!r&&!i&&su(t),o=e||r||i||s,u=o?Hn(t.length,Ct):[],c=u.length;for(var h in t)!n&&!It.call(t,h)||o&&("length"==h||i&&("offset"==h||"parent"==h)||s&&("buffer"==h||"byteLength"==h||"byteOffset"==h)||ps(h,c))||u.push(h);return u}function Ye(n){var e=n.length;return e?n[Kr(0,e-1)]:t}function Xe(t,n){return Us(Si(t),ir(n,0,t.length))}function qe(t){return Us(Si(t))}function Ge(n,e,r){(r!==t&&!Do(n[e],r)||r===t&&!(e in n))&&er(n,e,r)}function Je(n,e,r){var i=n[e];It.call(n,e)&&Do(i,r)&&(r!==t||e in n)||er(n,e,r)}function Ze(t,n){for(var e=t.length;e--;)if(Do(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,$u(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:Au(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(!qo(n))return n;var f=Lo(n);if(f){if(u=function(t){var n=t.length,e=new t.constructor(n);return n&&"string"==typeof t[0]&&It.call(t,"index")&&(e.index=t.index,e.input=t.input),e}(n),!c)return Si(n,u)}else{var v=as(n),k=v==w||v==y;if(Ko(n))return bi(n,c);if(v==m||v==l||k&&!s){if(u=h||k?{}:fs(n),!c)return h?function(t,n){return Ci(t,hs(t),n)}(n,function(t,n){return t&&Ci(n,Eu(n),t)}(u,n)):function(t,n){return Ci(t,cs(t),n)}(n,nr(u,n))}else{if(!en[v])return s?n:{};u=function(t,n,e){var r=t.constructor;switch(n){case $:return mi(t);case d:case p: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 T:case U:case j:case I:case O:case _:case z:case D:case R:return ki(t,e);case g:return new r;case b:case M:return new r(t);case A: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 ze?Mt(ze.call(t)):{}}}(n,v,c)}}o||(o=new Ve);var C=o.get(n);if(C)return C;o.set(n,u),eu(n)?n.forEach((function(t){u.add(sr(t,e,r,t,n,o))})):Jo(n)&&n.forEach((function(t,i){u.set(i,sr(t,e,r,i,n,o))}));var P=f?t:(a?h?ts:Zi:h?Eu:$u)(n);return xn(P||n,(function(t,i){P&&(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 $t(n);return Cs((function(){e.apply(t,i)}),r)}function cr(t,n,e,r){var i=-1,s=$n,o=!0,u=t.length,c=[],h=n.length;if(!u)return c;e&&(n=Tn(n,Qn(e))),r?(s=En,o=!1):n.length>=200&&(s=Xn,o=!1,n=new He(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:V,evaluate:Q,interpolate:Y,variable:"",imports:{_:Pe}},(Pe.prototype=Fe.prototype).constructor=Pe,(Le.prototype=Re(Fe.prototype)).constructor=Le,(We.prototype=Re(Fe.prototype)).constructor=We,Be.prototype.clear=function(){this.__data__=Ce?Ce(null):{},this.size=0},Be.prototype.delete=function(t){var n=this.has(t)&&delete this.__data__[t];return this.size-=n?1:0,n},Be.prototype.get=function(n){var r=this.__data__;if(Ce){var i=r[n];return i===e?t:i}return It.call(r,n)?r[n]:t},Be.prototype.has=function(n){var e=this.__data__;return Ce?e[n]!==t:It.call(e,n)},Be.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():Vt.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 Be,map:new(Ae||Ne),string:new Be}},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},He.prototype.add=He.prototype.push=function(t){return this.__data__.set(t,e),this},He.prototype.has=function(t){return this.__data__.has(t)},Ve.prototype.clear=function(){this.__data__=new Ne,this.size=0},Ve.prototype.delete=function(t){var n=this.__data__,e=n.delete(t);return this.size=n.size,e},Ve.prototype.get=function(t){return this.__data__.get(t)},Ve.prototype.has=function(t){return this.__data__.has(t)},Ve.prototype.set=function(t,n){var e=this.__data__;if(e instanceof Ne){var r=e.__data__;if(!Ae||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=Ti(yr),ar=Ti(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&&!iu(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 pr(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?pr(u,n-1,e,r,i):Un(i,u):r||(i[i.length]=u)}return i}var vr=Ui(),wr=Ui(!0);function yr(t,n){return t&&vr(t,n,$u)}function gr(t,n){return t&&wr(t,n,$u)}function br(t,n){return Cn(n,(function(n){return Qo(t[n])}))}function mr(n,e){for(var r=0,i=(e=vi(e,n)).length;null!=n&&r<i;)n=n[Is(e[r++])];return r&&r==i?n:t}function kr(t,n,e){var r=n(t);return Lo(t)?r:Un(r,e(t))}function Ar(n){return null==n?n===t?"[object Undefined]":"[object Null]":rn&&rn in Mt(n)?function(n){var e=It.call(n,rn),r=n[rn];try{n[rn]=t;var i=!0}catch(t){}var s=zt.call(n);return i&&(e?n[rn]=r:delete n[rn]),s}(n):function(t){return zt.call(t)}(n)}function xr(t,n){return t>n}function Mr(t,n){return null!=t&&It.call(t,n)}function Sr(t,n){return null!=t&&n in Mt(t)}function Cr(n,e,r){for(var i=r?En:$n,s=n[0].length,o=n.length,u=o,c=bt(o),h=1/0,a=[];u--;){var l=n[u];u&&e&&(l=Tn(l,Qn(e))),h=we(l.length,h),c[u]=!r&&(e||s>=120&&l.length>=120)?new He(u&&l):t}l=n[0];var f=-1,d=c[0];t:for(;++f<s&&a.length<h;){var p=l[f],v=e?e(p):p;if(p=r||0!==p?p:0,!(d?Xn(d,v):i(a,v,r))){for(u=o;--u;){var w=c[u];if(!(w?Xn(w,v):i(n[u],v,r)))continue t}d&&d.push(v),a.push(p)}}return a}function $r(n,e,r){var i=null==(n=xs(n,e=vi(e,n)))?n:n[Is(Hs(e))];return null==i?t:kn(i,n,r)}function Er(t){return Go(t)&&Ar(t)==l}function Tr(n,e,r,i,s){return n===e||(null==n||null==e||!Go(n)&&!Go(e)?n!=n&&e!=e:function(n,e,r,i,s,o){var u=Lo(n),c=Lo(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,k=h==a;if(k&&Ko(n)){if(!Ko(e))return!1;u=!0,w=!1}if(k&&!w)return o||(o=new Ve),u||su(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 $:return!(t.byteLength!=n.byteLength||!s(new Wt(t),new Wt(n)));case d:case p:case b:return Do(+t,+n);case v:return t.name==n.name&&t.message==n.message;case A: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(ze)return ze.call(t)==ze.call(n)}return!1}(n,e,h,r,i,s,o);if(!(1&r)){var C=w&&It.call(n,"__wrapped__"),T=y&&It.call(e,"__wrapped__");if(C||T){var U=C?n.value():n,j=T?e.value():e;return o||(o=new Ve),s(U,j,r,i,o)}}return!!k&&(o||(o=new Ve),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:It.call(e,l)))return!1}var f=o.get(n),d=o.get(e);if(f&&d)return f==e&&d==n;var p=!0;o.set(n,e),o.set(e,n);for(var v=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)){p=!1;break}v||(v="constructor"==l)}if(p&&!v){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||(p=!1)}return o.delete(n),o.delete(e),p}(n,e,r,i,s,o))}(n,e,r,i,Tr,s))}function Ur(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 Ve;if(i)var d=i(a,l,h,n,e,f);if(!(d===t?Tr(l,a,3,i,f):d))return!1}}return!0}function jr(t){return!(!qo(t)||(n=t,_t&&_t in n))&&(Qo(t)?Rt:ft).test(Os(t));var n}function Ir(t){return"function"==typeof t?t:null==t?Zu:"object"==typeof t?Lo(t)?Pr(t[0],t[1]):Dr(t):cc(t)}function Or(t){if(!bs(t))return pe(t);var n=[];for(var e in Mt(t))It.call(t,e)&&"constructor"!=e&&n.push(e);return n}function _r(t,n){return t<n}function zr(t,n){var e=-1,r=Bo(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]?ks(n[0][0],n[0][1]):function(e){return e===t||Ur(e,t,n)}}function Pr(n,e){return ws(n)&&ms(e)?ks(Is(n),e):function(r){var i=Au(r,n);return i===t&&i===e?xu(r,n):Tr(e,i,3)}}function Rr(n,e,r,i,s){n!==e&&vr(e,(function(o,u){if(s||(s=new Ve),qo(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=Lo(h),p=!d&&Ko(h),v=!d&&!p&&su(h);l=h,d||p||v?Lo(c)?l=c:No(c)?l=Si(c):p?(f=!1,l=bi(h,!0)):v?(f=!1,l=ki(h,!0)):l=[]:tu(h)||Fo(h)?(l=c,Fo(c)?l=du(c):qo(c)&&!Qo(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)}}),Eu)}function Fr(n,e){var r=n.length;if(r)return ps(e+=e<0?r:0,r)?n[e]:t}function Lr(t,n,e){n=n.length?Tn(n,(function(t){return Lo(t)?function(n){return mr(n,1===t.length?t[0]:t)}:t})):[Zu];var r=-1;n=Tn(n,Qn(is()));var i=zr(t,(function(t){var e=Tn(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=Ai(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 Wr(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,vi(o,t),u)}return s}function Br(t,n,e,r){var i=r?Rn:Pn,s=-1,o=n.length,u=t;for(t===n&&(n=Si(n)),e&&(u=Tn(t,Qn(e)));++s<o;)for(var c=0,h=n[s],a=e?e(h):h;(c=i(u,a,c,r))>-1;)u!==t&&Vt.call(u,c,1),Vt.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;ps(i)?Vt.call(t,i,1):ui(t,i)}}return t}function Kr(t,n){return t+pn(be()*(n-t+1))}function Hr(t,n){var e="";if(!t||n<1||n>u)return e;do{n%2&&(e+=t),(n=pn(n/2))&&(t+=t)}while(n);return e}function Vr(t,n){return $s(As(t,n,Zu),t+"")}function Qr(t){return Ye(Du(t))}function Yr(t,n){var e=Du(t);return Us(e,ir(n,0,e.length))}function Xr(n,e,r,i){if(!qo(n))return n;for(var s=-1,o=(e=vi(e,n)).length,u=o-1,c=n;null!=c&&++s<o;){var h=Is(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=qo(l)?l:ps(e[s+1])?[]:{})}Je(c,h,a),c=c[h]}return n}var qr=$e?function(t,n){return $e.set(t,n),t}:Zu,Gr=un?function(t,n){return un(t,"toString",{configurable:!0,enumerable:!1,value:qu(n),writable:!0})}:Zu;function Jr(t){return Us(Du(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&&!iu(o)&&(e?o<=n:o<n)?r=s+1:i=s}return i}return ei(t,n,Zu,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=iu(e),a=e===t;s<o;){var l=pn((s+o)/2),f=r(n[l]),d=f!==t,p=null===f,v=f==f,w=iu(f);if(u)var y=i||v;else y=a?v&&(i||d):c?v&&d&&(i||!p):h?v&&d&&!p&&(i||!w):!p&&!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||!Do(u,c)){var c=u;s[i++]=0===o?0:o}}return s}function ii(t){return"number"==typeof t?t:iu(t)?c:+t}function si(t){if("string"==typeof t)return t;if(Lo(t))return Tn(t,si)+"";if(iu(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=$n,s=t.length,o=!0,u=[],c=u;if(e)o=!1,i=En;else if(s>=200){var h=n?null:Hi(t);if(h)return se(h);o=!1,i=Xn,c=new He}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){var e=-1,r=(n=vi(n,t)).length;if(!r)return!0;for(var i=null==t||"object"!=typeof t&&"function"!=typeof t;++e<r;){var s=n[e];if("string"==typeof s){if("__proto__"===s&&!It.call(t,"__proto__"))return!1;if("constructor"===s&&e+1<r&&"string"==typeof n[e+1]&&"prototype"===n[e+1]){if(i&&0===e)continue;return!1}}}var o=xs(t,n);return null==o||delete o[Is(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 We&&(e=e.value()),jn(n,(function(t,n){return n.func.apply(n.thisArg,Un([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(pr(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 No(t)?t:[]}function pi(t){return"function"==typeof t?t:Zu}function vi(t,n){return Lo(t)?t:ws(t,n)?[t]:js(pu(t))}var wi=Vr;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=Bt?Bt(e):new t.constructor(e);return t.copy(r),r}function mi(t){var n=new t.constructor(t.byteLength);return new Wt(n).set(new Wt(t)),n}function ki(t,n){var e=n?mi(t.buffer):t.buffer;return new t.constructor(e,t.byteOffset,t.length)}function Ai(n,e){if(n!==e){var r=n!==t,i=null===n,s=n==n,o=iu(n),u=e!==t,c=null===e,h=e==e,a=iu(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=ve(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=ve(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 $i(t,n){return function(e,r){var i=Lo(e)?An:tr,s=n?n():{};return i(e,t,is(r,2),s)}}function Ei(n){return Vr((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&&vs(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 Ti(t,n){return function(e,r){if(null==e)return e;if(!Bo(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 Ui(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 ji(n){return function(e){var r=ne(e=pu(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 Ii(t){return function(n){return jn(Qu(Fu(n).replace(Qt,"")),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 qo(r)?r:e}}function _i(n){return function(e,r,i){var s=Mt(e);if(!Bo(e)){var o=is(r,3);e=$u(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 zi(e){return Ji((function(r){var i=r.length,s=i,o=Le.prototype.thru;for(e&&r.reverse();s--;){var u=r[s];if("function"!=typeof u)throw new $t(n);if(o&&!c&&"wrapper"==es(u))var c=new Le([],!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&&Lo(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,p=2&e,v=24&e,w=512&e,y=p?t:Oi(n);return function s(){for(var g=arguments.length,b=bt(g),m=g;m--;)b[m]=arguments[m];if(v)var k=rs(s),A=function(t,n){for(var e=t.length,r=0;e--;)t[e]===n&&++r;return r}(b,k);if(i&&(b=xi(b,i,o,v)),u&&(b=Mi(b,u,c,v)),g-=A,v&&g<l){var x=ie(b,k);return Ni(n,e,Di,s.placeholder,r,b,x,h,a,l-g)}var M=d?r:this,S=p?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]=ps(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 Fi(t){return Ji((function(n){return n=Tn(n,Qn(is())),Vr((function(e){var r=this;return t(n,(function(t){return kn(t,r,e)}))}))}))}function Li(n,e){var r=(e=e===t?" ":si(e)).length;if(r<2)return r?Hr(e,n):e;var i=Hr(e,dn(n/ue(e)));return ne(e)?yi(ce(i),0,n).join(""):i.slice(0,n)}function Wi(n){return function(e,r,i){return i&&"number"!=typeof i&&vs(e,r,i)&&(r=i=t),e=hu(e),r===t?(r=e,e=0):r=hu(r),function(t,n,e,r){for(var i=-1,s=ve(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:hu(i),n)}}function Bi(t){return function(n,e){return"string"==typeof n&&"string"==typeof e||(n=fu(n),e=fu(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],p=r.apply(t,d);return ys(n)&&Ss(p,d),p.placeholder=s,Es(p,n,e)}function Ki(t){var n=xt[t];return function(t,e){if(t=fu(t),(e=null==e?0:we(au(e),292))&&fe(t)){var r=(pu(t)+"e").split("e");return+((r=(pu(n(r[0]+"e"+(+r[1]+e)))+"e").split("e"))[0]+"e"+(+r[1]-e))}return n(t)}}var Hi=Me&&1/se(new Me([,-0]))[1]==o?function(t){return new Me(t)}:ic;function Vi(t){return function(n){var e=as(n);return e==g?ee(n):e==x?oe(n):function(t,n){return Tn(n,(function(n){return[n,t[n]]}))}(n,t(n))}}function Qi(e,o,u,c,h,a,l,f){var d=2&o;if(!d&&"function"!=typeof e)throw new $t(n);var p=c?c.length:0;if(p||(o&=-97,c=h=t),l=l===t?l:ve(au(l),0),f=f===t?f:au(f),p-=h?h.length:0,64&o){var v=c,w=h;c=h=t}var y=d?t:ns(e),g=[e,o,u,c,h,v,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:ve(g[9]-p,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):kn(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 kn(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 Yi(n,e,r,i){return n===t||Do(n,Tt[r])&&!It.call(i,r)?e:n}function Xi(n,e,r,i,s,o){return qo(n)&&qo(e)&&(o.set(e,n),Rr(n,e,t,Xi,o),o.delete(e)),n}function qi(n){return tu(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,p=2&r?new He:t;for(o.set(n,e),o.set(e,n);++f<c;){var v=n[f],w=e[f];if(i)var y=u?i(w,v,f,e,n,o):i(v,w,f,n,e,o);if(y!==t){if(y)continue;d=!1;break}if(p){if(!On(e,(function(t,n){if(!Xn(p,n)&&(v===t||s(v,t,r,i,o)))return p.push(n)}))){d=!1;break}}else if(v!==w&&!s(v,w,r,i,o)){d=!1;break}}return o.delete(n),o.delete(e),d}function Ji(n){return $s(As(n,t,Ls),n+"")}function Zi(t){return kr(t,$u,cs)}function ts(t){return kr(t,Eu,hs)}var ns=$e?function(t){return $e.get(t)}:ic;function es(t){for(var n=t.name+"",e=Ee[n],r=It.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(It.call(Pe,"placeholder")?Pe:t).placeholder}function is(){var t=Pe.iteratee||tc;return t=t===tc?Ir: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=$u(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 jr(r)?r:t}var cs=_n?function(t){return null==t?[]:(t=Mt(t),Cn(_n(t),(function(n){return Ht.call(t,n)})))}:lc,hs=_n?function(t){for(var n=[];t;)Un(n,cs(t)),t=Nt(t);return n}:lc,as=Ar;function ls(t,n,e){for(var r=-1,i=(n=vi(n,t)).length,s=!1;++r<i;){var o=Is(n[r]);if(!(s=null!=t&&e(t,o)))break;t=t[o]}return s||++r!=i?s:!!(i=null==t?0:t.length)&&Xo(i)&&ps(o,i)&&(Lo(t)||Fo(t))}function fs(t){return"function"!=typeof t.constructor||bs(t)?{}:Re(Nt(t))}function ds(t){return Lo(t)||Fo(t)||!!(Xt&&t&&t[Xt])}function ps(t,n){var e=typeof t;return!!(n=null==n?u:n)&&("number"==e||"symbol"!=e&&pt.test(t))&&t>-1&&t%1==0&&t<n}function vs(t,n,e){if(!qo(e))return!1;var r=typeof n;return!!("number"==r?Bo(e)&&ps(n,e.length):"string"==r&&n in e)&&Do(e[n],t)}function ws(t,n){if(Lo(t))return!1;var e=typeof t;return!("number"!=e&&"symbol"!=e&&"boolean"!=e&&null!=t&&!iu(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 We.prototype))return!1;if(t===e)return!0;var r=ns(e);return!!r&&t===r[0]}(ke&&as(new ke(new ArrayBuffer(1)))!=E||Ae&&as(new Ae)!=g||xe&&as(xe.resolve())!=k||Me&&as(new Me)!=x||Se&&as(new Se)!=C)&&(as=function(n){var e=Ar(n),r=e==m?n.constructor:t,i=r?Os(r):"";if(i)switch(i){case Te:return E;case Ue:return g;case je:return k;case Ie:return x;case Oe:return C}return e});var gs=Ut?Qo:fc;function bs(t){var n=t&&t.constructor;return t===("function"==typeof n&&n.prototype||Tt)}function ms(t){return t==t&&!qo(t)}function ks(n,e){return function(r){return null!=r&&r[n]===e&&(e!==t||n in Mt(r))}}function As(n,e,r){return e=ve(e===t?n.length-1:e,0),function(){for(var t=arguments,i=-1,s=ve(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),kn(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=Ts(qr),Cs=ln||function(t,n){return hn.setTimeout(t,n)},$s=Ts(Gr);function Es(t,n,e){var r=n+"";return $s(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]&&!$n(t,r)&&t.push(r)})),t.sort()}(function(t){var n=t.match(rt);return n?n[1].split(it):[]}(r),e)))}function Ts(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 Us(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 js=function(){var t=Uo((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===n.size&&n.clear(),t})),n=t.cache;return t}();function Is(t){if("string"==typeof t||iu(t))return t;var n=t+"";return"0"==n&&1/t==-1/0?"-0":n}function Os(t){if(null!=t){try{return jt.call(t)}catch(t){}try{return t+""}catch(t){}}return""}function _s(t){if(t instanceof We)return t.clone();var n=new Le(t.__wrapped__,t.__chain__);return n.__actions__=Si(t.__actions__),n.__index__=t.__index__,n.__values__=t.__values__,n}var zs=Vr((function(t,n){return No(t)?cr(t,pr(n,1,No,!0)):[]})),Ds=Vr((function(n,e){var r=Hs(e);return No(r)&&(r=t),No(n)?cr(n,pr(e,1,No,!0),is(r,2)):[]})),Ps=Vr((function(n,e){var r=Hs(e);return No(r)&&(r=t),No(n)?cr(n,pr(e,1,No,!0),t,r):[]}));function Rs(t,n,e){var r=null==t?0:t.length;if(!r)return-1;var i=null==e?0:au(e);return i<0&&(i=ve(r+i,0)),Dn(t,is(n,3),i)}function Fs(n,e,r){var i=null==n?0:n.length;if(!i)return-1;var s=i-1;return r!==t&&(s=au(r),s=r<0?ve(i+s,0):we(s,i-1)),Dn(n,is(e,3),s,!0)}function Ls(t){return null!=t&&t.length?pr(t,1):[]}function Ws(n){return n&&n.length?n[0]:t}var Bs=Vr((function(t){var n=Tn(t,di);return n.length&&n[0]===t[0]?Cr(n):[]})),Ns=Vr((function(n){var e=Hs(n),r=Tn(n,di);return e===Hs(r)?e=t:r.pop(),r.length&&r[0]===n[0]?Cr(r,is(e,2)):[]})),Ks=Vr((function(n){var e=Hs(n),r=Tn(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=Vr(Qs);function Qs(t,n){return t&&t.length&&n&&n.length?Br(t,n):t}var Ys=Ji((function(t,n){var e=null==t?0:t.length,r=rr(t,n);return Nr(t,Tn(n,(function(t){return ps(t,e)?+t:t})).sort(Ai)),r}));function Xs(t){return null==t?t:me.call(t)}var qs=Vr((function(t){return oi(pr(t,1,No,!0))})),Gs=Vr((function(n){var e=Hs(n);return No(e)&&(e=t),oi(pr(n,1,No,!0),is(e,2))})),Js=Vr((function(n){var e=Hs(n);return e="function"==typeof e?e:t,oi(pr(n,1,No,!0),t,e)}));function Zs(t){if(!t||!t.length)return[];var n=0;return t=Cn(t,(function(t){if(No(t))return n=ve(t.length,n),!0})),Hn(n,(function(n){return Tn(t,Wn(n))}))}function to(n,e){if(!n||!n.length)return[];var r=Zs(n);return null==e?r:Tn(r,(function(n){return kn(e,t,n)}))}var no=Vr((function(t,n){return No(t)?cr(t,n):[]})),eo=Vr((function(t){return li(Cn(t,No))})),ro=Vr((function(n){var e=Hs(n);return No(e)&&(e=t),li(Cn(n,No),is(e,2))})),io=Vr((function(n){var e=Hs(n);return e="function"==typeof e?e:t,li(Cn(n,No),t,e)})),so=Vr(Zs),oo=Vr((function(n){var e=n.length,r=e>1?n[e-1]:t;return r="function"==typeof r?(n.pop(),r):t,to(n,r)}));function uo(t){var n=Pe(t);return n.__chain__=!0,n}function co(t,n){return n(t)}var ho=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 We&&ps(r)?((i=i.slice(r,+r+(e?1:0))).__actions__.push({func:co,args:[s],thisArg:t}),new Le(i,this.__chain__).thru((function(n){return e&&!n.length&&n.push(t),n}))):this.thru(s)})),ao=$i((function(t,n,e){It.call(t,e)?++t[e]:er(t,e,1)})),lo=_i(Rs),fo=_i(Fs);function po(t,n){return(Lo(t)?xn:hr)(t,is(n,3))}function vo(t,n){return(Lo(t)?Mn:ar)(t,is(n,3))}var wo=$i((function(t,n,e){It.call(t,e)?t[e].push(n):er(t,e,[n])})),yo=Vr((function(t,n,e){var r=-1,i="function"==typeof n,s=Bo(t)?bt(t.length):[];return hr(t,(function(t){s[++r]=i?kn(n,t,e):$r(t,n,e)})),s})),go=$i((function(t,n,e){er(t,e,n)}));function bo(t,n){return(Lo(t)?Tn:zr)(t,is(n,3))}var mo=$i((function(t,n,e){t[e?0:1].push(n)}),(function(){return[[],[]]})),ko=Vr((function(t,n){if(null==t)return[];var e=n.length;return e>1&&vs(t,n[0],n[1])?n=[]:e>2&&vs(n[0],n[1],n[2])&&(n=[n[0]]),Lr(t,pr(n,1),[])})),Ao=an||function(){return hn.Date.now()};function xo(n,e,r){return e=r?t:e,Qi(n,s,t,t,t,t,e=n&&null==e?n.length:e)}function Mo(e,r){var i;if("function"!=typeof r)throw new $t(n);return e=au(e),function(){return--e>0&&(i=r.apply(this,arguments)),e<=1&&(r=t),i}}var So=Vr((function(t,n,e){var r=1;if(e.length){var s=ie(e,rs(So));r|=i}return Qi(t,r,n,e,s)})),Co=Vr((function(t,n,e){var r=3;if(e.length){var s=ie(e,rs(Co));r|=i}return Qi(n,r,t,e,s)}));function $o(e,r,i){var s,o,u,c,h,a,l=0,f=!1,d=!1,p=!0;if("function"!=typeof e)throw new $t(n);function v(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=Ao();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,p&&s?v(n):(s=o=t,c)}function b(){var n=Ao(),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?v(t):c}(a);if(d)return gi(h),h=Cs(y,r),v(a)}return h===t&&(h=Cs(y,r)),c}return r=fu(r)||0,qo(i)&&(f=!!i.leading,u=(d="maxWait"in i)?ve(fu(i.maxWait)||0,r):u,p="trailing"in i?!!i.trailing:p),b.cancel=function(){h!==t&&gi(h),l=0,s=a=o=h=t},b.flush=function(){return h===t?c:g(Ao())},b}var Eo=Vr((function(t,n){return ur(t,1,n)})),To=Vr((function(t,n,e){return ur(t,fu(n)||0,e)}));function Uo(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new $t(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(Uo.Cache||Ke),r}function jo(t){if("function"!=typeof t)throw new $t(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)}}Uo.Cache=Ke;var Io=wi((function(t,n){var e=(n=1==n.length&&Lo(n[0])?Tn(n[0],Qn(is())):Tn(pr(n,1),Qn(is()))).length;return Vr((function(r){for(var i=-1,s=we(r.length,e);++i<s;)r[i]=n[i].call(this,r[i]);return kn(t,this,r)}))})),Oo=Vr((function(n,e){var r=ie(e,rs(Oo));return Qi(n,i,t,e,r)})),_o=Vr((function(n,e){var r=ie(e,rs(_o));return Qi(n,64,t,e,r)})),zo=Ji((function(n,e){return Qi(n,256,t,t,t,e)}));function Do(t,n){return t===n||t!=t&&n!=n}var Po=Bi(xr),Ro=Bi((function(t,n){return t>=n})),Fo=Er(function(){return arguments}())?Er:function(t){return Go(t)&&It.call(t,"callee")&&!Ht.call(t,"callee")},Lo=bt.isArray,Wo=vn?Qn(vn):function(t){return Go(t)&&Ar(t)==$};function Bo(t){return null!=t&&Xo(t.length)&&!Qo(t)}function No(t){return Go(t)&&Bo(t)}var Ko=Bn||fc,Ho=wn?Qn(wn):function(t){return Go(t)&&Ar(t)==p};function Vo(t){if(!Go(t))return!1;var n=Ar(t);return n==v||"[object DOMException]"==n||"string"==typeof t.message&&"string"==typeof t.name&&!tu(t)}function Qo(t){if(!qo(t))return!1;var n=Ar(t);return n==w||n==y||"[object AsyncFunction]"==n||"[object Proxy]"==n}function Yo(t){return"number"==typeof t&&t==au(t)}function Xo(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=u}function qo(t){var n=typeof t;return null!=t&&("object"==n||"function"==n)}function Go(t){return null!=t&&"object"==typeof t}var Jo=yn?Qn(yn):function(t){return Go(t)&&as(t)==g};function Zo(t){return"number"==typeof t||Go(t)&&Ar(t)==b}function tu(t){if(!Go(t)||Ar(t)!=m)return!1;var n=Nt(t);if(null===n)return!0;var e=It.call(n,"constructor")&&n.constructor;return"function"==typeof e&&e instanceof e&&jt.call(e)==Dt}var nu=gn?Qn(gn):function(t){return Go(t)&&Ar(t)==A},eu=bn?Qn(bn):function(t){return Go(t)&&as(t)==x};function ru(t){return"string"==typeof t||!Lo(t)&&Go(t)&&Ar(t)==M}function iu(t){return"symbol"==typeof t||Go(t)&&Ar(t)==S}var su=mn?Qn(mn):function(t){return Go(t)&&Xo(t.length)&&!!nn[Ar(t)]},ou=Bi(_r),uu=Bi((function(t,n){return t<=n}));function cu(t){if(!t)return[];if(Bo(t))return ru(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:Du)(t)}function hu(t){return t?(t=fu(t))===o||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0}function au(t){var n=hu(t),e=n%1;return n==n?e?n-e:n:0}function lu(t){return t?ir(au(t),0,h):0}function fu(t){if("number"==typeof t)return t;if(iu(t))return c;if(qo(t)){var n="function"==typeof t.valueOf?t.valueOf():t;t=qo(n)?n+"":n}if("string"!=typeof t)return 0===t?t:+t;t=Vn(t);var e=lt.test(t);return e||dt.test(t)?on(t.slice(2),e?2:8):at.test(t)?c:+t}function du(t){return Ci(t,Eu(t))}function pu(t){return null==t?"":si(t)}var vu=Ei((function(t,n){if(bs(n)||Bo(n))Ci(n,$u(n),t);else for(var e in n)It.call(n,e)&&Je(t,e,n[e])})),wu=Ei((function(t,n){Ci(n,Eu(n),t)})),yu=Ei((function(t,n,e,r){Ci(n,Eu(n),t,r)})),gu=Ei((function(t,n,e,r){Ci(n,$u(n),t,r)})),bu=Ji(rr),mu=Vr((function(n,e){n=Mt(n);var r=-1,i=e.length,s=i>2?e[2]:t;for(s&&vs(e[0],e[1],s)&&(i=1);++r<i;)for(var o=e[r],u=Eu(o),c=-1,h=u.length;++c<h;){var a=u[c],l=n[a];(l===t||Do(l,Tt[a])&&!It.call(n,a))&&(n[a]=o[a])}return n})),ku=Vr((function(n){return n.push(t,Xi),kn(Uu,t,n)}));function Au(n,e,r){var i=null==n?t:mr(n,e);return i===t?r:i}function xu(t,n){return null!=t&&ls(t,n,Sr)}var Mu=Pi((function(t,n,e){null!=n&&"function"!=typeof n.toString&&(n=zt.call(n)),t[n]=e}),qu(Zu)),Su=Pi((function(t,n,e){null!=n&&"function"!=typeof n.toString&&(n=zt.call(n)),It.call(t,n)?t[n].push(e):t[n]=[e]}),is),Cu=Vr($r);function $u(t){return Bo(t)?Qe(t):Or(t)}function Eu(t){return Bo(t)?Qe(t,!0):function(t){if(!qo(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&&It.call(t,r))&&e.push(r);return e}(t)}var Tu=Ei((function(t,n,e){Rr(t,n,e)})),Uu=Ei((function(t,n,e,r){Rr(t,n,e,r)})),ju=Ji((function(t,n){var e={};if(null==t)return e;var r=!1;n=Tn(n,(function(n){return n=vi(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})),Iu=Ji((function(t,n){return null==t?{}:function(t,n){return Wr(t,n,(function(n,e){return xu(t,e)}))}(t,n)}));function Ou(t,n){if(null==t)return{};var e=Tn(ts(t),(function(t){return[t]}));return n=is(n),Wr(t,e,(function(t,e){return n(t,e[0])}))}var _u=Vi($u),zu=Vi(Eu);function Du(t){return null==t?[]:Yn(t,$u(t))}var Pu=Ii((function(t,n,e){return n=n.toLowerCase(),t+(e?Ru(n):n)}));function Ru(t){return Vu(pu(t).toLowerCase())}function Fu(t){return(t=pu(t))&&t.replace(vt,Jn).replace(Yt,"")}var Lu=Ii((function(t,n,e){return t+(e?"-":"")+n.toLowerCase()})),Wu=Ii((function(t,n,e){return t+(e?" ":"")+n.toLowerCase()})),Bu=ji("toLowerCase"),Nu=Ii((function(t,n,e){return t+(e?"_":"")+n.toLowerCase()})),Ku=Ii((function(t,n,e){return t+(e?" ":"")+Vu(n)})),Hu=Ii((function(t,n,e){return t+(e?" ":"")+n.toUpperCase()})),Vu=ji("toUpperCase");function Qu(n,e,r){return n=pu(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 Yu=Vr((function(n,e){try{return kn(n,t,e)}catch(t){return Vo(t)?t:new kt(t)}})),Xu=Ji((function(t,n){return xn(n,(function(n){n=Is(n),er(t,n,So(t[n],t))})),t}));function qu(t){return function(){return t}}var Gu=zi(),Ju=zi(!0);function Zu(t){return t}function tc(t){return Ir("function"==typeof t?t:sr(t,1))}var nc=Vr((function(t,n){return function(e){return $r(e,t,n)}})),ec=Vr((function(t,n){return function(e){return $r(t,e,n)}}));function rc(t,n,e){var r=$u(n),i=br(n,r);null!=e||qo(n)&&(i.length||!r.length)||(e=n,n=t,t=this,i=br(n,$u(n)));var s=!(qo(e)&&"chain"in e&&!e.chain),o=Qo(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,Un([this.value()],arguments))})})),t}function ic(){}var sc=Fi(Tn),oc=Fi(Sn),uc=Fi(On);function cc(t){return ws(t)?Wn(Is(t)):function(t){return function(n){return mr(n,t)}}(t)}var hc=Wi(),ac=Wi(!0);function lc(){return[]}function fc(){return!1}var dc,pc=Ri((function(t,n){return t+n}),0),vc=Ki("ceil"),wc=Ri((function(t,n){return t/n}),1),yc=Ki("floor"),gc=Ri((function(t,n){return t*n}),1),bc=Ki("round"),mc=Ri((function(t,n){return t-n}),0);return Pe.after=function(t,e){if("function"!=typeof e)throw new $t(n);return t=au(t),function(){if(--t<1)return e.apply(this,arguments)}},Pe.ary=xo,Pe.assign=vu,Pe.assignIn=wu,Pe.assignInWith=yu,Pe.assignWith=gu,Pe.at=bu,Pe.before=Mo,Pe.bind=So,Pe.bindAll=Xu,Pe.bindKey=Co,Pe.castArray=function(){if(!arguments.length)return[];var t=arguments[0];return Lo(t)?t:[t]},Pe.chain=uo,Pe.chunk=function(n,e,r){e=(r?vs(n,e,r):e===t)?1:ve(au(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 Un(Lo(e)?Si(e):[e],pr(n,1))},Pe.cond=function(t){var e=null==t?0:t.length,r=is();return t=e?Tn(t,(function(t){if("function"!=typeof t[1])throw new $t(n);return[r(t[0]),t[1]]})):[],Vr((function(n){for(var r=-1;++r<e;){var i=t[r];if(kn(i[0],this,n))return kn(i[1],this,n)}}))},Pe.conforms=function(t){return function(t){var n=$u(t);return function(e){return or(e,t,n)}}(sr(t,1))},Pe.constant=qu,Pe.countBy=ao,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=Qi(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=Qi(e,16,t,t,t,t,t,r=i?t:r);return s.placeholder=n.placeholder,s},Pe.debounce=$o,Pe.defaults=mu,Pe.defaultsDeep=ku,Pe.defer=Eo,Pe.delay=To,Pe.difference=zs,Pe.differenceBy=Ds,Pe.differenceWith=Ps,Pe.drop=function(n,e,r){var i=null==n?0:n.length;return i?Zr(n,(e=r||e===t?1:au(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:au(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&&vs(n,e,r)&&(r=0,i=s),function(n,e,r,i){var s=n.length;for((r=au(r))<0&&(r=-r>s?0:s+r),(i=i===t||i>s?s:au(i))<0&&(i+=s),i=r>i?0:lu(i);r<i;)n[r++]=e;return n}(n,e,r,i)):[]},Pe.filter=function(t,n){return(Lo(t)?Cn:dr)(t,is(n,3))},Pe.flatMap=function(t,n){return pr(bo(t,n),1)},Pe.flatMapDeep=function(t,n){return pr(bo(t,n),o)},Pe.flatMapDepth=function(n,e,r){return r=r===t?1:au(r),pr(bo(n,e),r)},Pe.flatten=Ls,Pe.flattenDeep=function(t){return null!=t&&t.length?pr(t,o):[]},Pe.flattenDepth=function(n,e){return null!=n&&n.length?pr(n,e=e===t?1:au(e)):[]},Pe.flip=function(t){return Qi(t,512)},Pe.flow=Gu,Pe.flowRight=Ju,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,$u(t))},Pe.functionsIn=function(t){return null==t?[]:br(t,Eu(t))},Pe.groupBy=wo,Pe.initial=function(t){return null!=t&&t.length?Zr(t,0,-1):[]},Pe.intersection=Bs,Pe.intersectionBy=Ns,Pe.intersectionWith=Ks,Pe.invert=Mu,Pe.invertBy=Su,Pe.invokeMap=yo,Pe.iteratee=tc,Pe.keyBy=go,Pe.keys=$u,Pe.keysIn=Eu,Pe.map=bo,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=Uo,Pe.merge=Tu,Pe.mergeWith=Uu,Pe.method=nc,Pe.methodOf=ec,Pe.mixin=rc,Pe.negate=jo,Pe.nthArg=function(t){return t=au(t),Vr((function(n){return Fr(n,t)}))},Pe.omit=ju,Pe.omitBy=function(t,n){return Ou(t,jo(is(n)))},Pe.once=function(t){return Mo(2,t)},Pe.orderBy=function(n,e,r,i){return null==n?[]:(Lo(e)||(e=null==e?[]:[e]),Lo(r=i?t:r)||(r=null==r?[]:[r]),Lr(n,e,r))},Pe.over=sc,Pe.overArgs=Io,Pe.overEvery=oc,Pe.overSome=uc,Pe.partial=Oo,Pe.partialRight=_o,Pe.partition=mo,Pe.pick=Iu,Pe.pickBy=Ou,Pe.property=cc,Pe.propertyOf=function(n){return function(e){return null==n?t:mr(n,e)}},Pe.pull=Vs,Pe.pullAll=Qs,Pe.pullAllBy=function(t,n,e){return t&&t.length&&n&&n.length?Br(t,n,is(e,2)):t},Pe.pullAllWith=function(n,e,r){return n&&n.length&&e&&e.length?Br(n,e,t,r):n},Pe.pullAt=Ys,Pe.range=hc,Pe.rangeRight=ac,Pe.rearg=zo,Pe.reject=function(t,n){return(Lo(t)?Cn:dr)(t,jo(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 $t(n);return Vr(e,r=r===t?r:au(r))},Pe.reverse=Xs,Pe.sampleSize=function(n,e,r){return e=(r?vs(n,e,r):e===t)?1:au(e),(Lo(n)?Xe:Yr)(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(Lo(t)?qe:Jr)(t)},Pe.slice=function(n,e,r){var i=null==n?0:n.length;return i?(r&&"number"!=typeof r&&vs(n,e,r)?(e=0,r=i):(e=null==e?0:au(e),r=r===t?i:au(r)),Zr(n,e,r)):[]},Pe.sortBy=ko,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&&vs(n,e,r)&&(e=r=t),(r=r===t?h:r>>>0)?(n=pu(n))&&("string"==typeof e||null!=e&&!nu(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 $t(n);return e=null==e?0:ve(au(e),0),Vr((function(n){var r=n[e],i=yi(n,0,e);return r&&Un(i,r),kn(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:au(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:au(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 $t(n);return qo(r)&&(i="leading"in r?!!r.leading:i,s="trailing"in r?!!r.trailing:s),$o(t,e,{leading:i,maxWait:e,trailing:s})},Pe.thru=co,Pe.toArray=cu,Pe.toPairs=_u,Pe.toPairsIn=zu,Pe.toPath=function(t){return Lo(t)?Tn(t,Is):iu(t)?[t]:Si(js(pu(t)))},Pe.toPlainObject=du,Pe.transform=function(t,n,e){var r=Lo(t),i=r||Ko(t)||su(t);if(n=is(n,4),null==e){var s=t&&t.constructor;e=i?r?new s:[]:qo(t)&&Qo(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 xo(t,1)},Pe.union=qs,Pe.unionBy=Gs,Pe.unionWith=Js,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=Zs,Pe.unzipWith=to,Pe.update=function(t,n,e){return null==t?t:ci(t,n,pi(e))},Pe.updateWith=function(n,e,r,i){return i="function"==typeof i?i:t,null==n?n:ci(n,e,pi(r),i)},Pe.values=Du,Pe.valuesIn=function(t){return null==t?[]:Yn(t,Eu(t))},Pe.without=no,Pe.words=Qu,Pe.wrap=function(t,n){return Oo(pi(n),t)},Pe.xor=eo,Pe.xorBy=ro,Pe.xorWith=io,Pe.zip=so,Pe.zipObject=function(t,n){return fi(t||[],n||[],Je)},Pe.zipObjectDeep=function(t,n){return fi(t||[],n||[],Xr)},Pe.zipWith=oo,Pe.entries=_u,Pe.entriesIn=zu,Pe.extend=wu,Pe.extendWith=yu,rc(Pe,Pe),Pe.add=pc,Pe.attempt=Yu,Pe.camelCase=Pu,Pe.capitalize=Ru,Pe.ceil=vc,Pe.clamp=function(n,e,r){return r===t&&(r=e,e=t),r!==t&&(r=(r=fu(r))==r?r:0),e!==t&&(e=(e=fu(e))==e?e:0),ir(fu(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,$u(n))},Pe.deburr=Fu,Pe.defaultTo=function(t,n){return null==t||t!=t?n:t},Pe.divide=wc,Pe.endsWith=function(n,e,r){n=pu(n),e=si(e);var i=n.length,s=r=r===t?i:ir(au(r),0,i);return(r-=e.length)>=0&&n.slice(r,s)==e},Pe.eq=Do,Pe.escape=function(t){return(t=pu(t))&&H.test(t)?t.replace(N,Zn):t},Pe.escapeRegExp=function(t){return(t=pu(t))&&Z.test(t)?t.replace(J,"\\$&"):t},Pe.every=function(n,e,r){var i=Lo(n)?Sn:lr;return r&&vs(n,e,r)&&(e=t),i(n,is(e,3))},Pe.find=lo,Pe.findIndex=Rs,Pe.findKey=function(t,n){return zn(t,is(n,3),yr)},Pe.findLast=fo,Pe.findLastIndex=Fs,Pe.findLastKey=function(t,n){return zn(t,is(n,3),gr)},Pe.floor=yc,Pe.forEach=po,Pe.forEachRight=vo,Pe.forIn=function(t,n){return null==t?t:vr(t,is(n,3),Eu)},Pe.forInRight=function(t,n){return null==t?t:wr(t,is(n,3),Eu)},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=Au,Pe.gt=Po,Pe.gte=Ro,Pe.has=function(t,n){return null!=t&&ls(t,n,Mr)},Pe.hasIn=xu,Pe.head=Ws,Pe.identity=Zu,Pe.includes=function(t,n,e,r){t=Bo(t)?t:Du(t),e=e&&!r?au(e):0;var i=t.length;return e<0&&(e=ve(i+e,0)),ru(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:au(e);return i<0&&(i=ve(r+i,0)),Pn(t,n,i)},Pe.inRange=function(n,e,r){return e=hu(e),r===t?(r=e,e=0):r=hu(r),function(t,n,e){return t>=we(n,e)&&t<ve(n,e)}(n=fu(n),e,r)},Pe.invoke=Cu,Pe.isArguments=Fo,Pe.isArray=Lo,Pe.isArrayBuffer=Wo,Pe.isArrayLike=Bo,Pe.isArrayLikeObject=No,Pe.isBoolean=function(t){return!0===t||!1===t||Go(t)&&Ar(t)==d},Pe.isBuffer=Ko,Pe.isDate=Ho,Pe.isElement=function(t){return Go(t)&&1===t.nodeType&&!tu(t)},Pe.isEmpty=function(t){if(null==t)return!0;if(Bo(t)&&(Lo(t)||"string"==typeof t||"function"==typeof t.splice||Ko(t)||su(t)||Fo(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(It.call(t,e))return!1;return!0},Pe.isEqual=function(t,n){return Tr(t,n)},Pe.isEqualWith=function(n,e,r){var i=(r="function"==typeof r?r:t)?r(n,e):t;return i===t?Tr(n,e,t,r):!!i},Pe.isError=Vo,Pe.isFinite=function(t){return"number"==typeof t&&fe(t)},Pe.isFunction=Qo,Pe.isInteger=Yo,Pe.isLength=Xo,Pe.isMap=Jo,Pe.isMatch=function(t,n){return t===n||Ur(t,n,os(n))},Pe.isMatchWith=function(n,e,r){return r="function"==typeof r?r:t,Ur(n,e,os(e),r)},Pe.isNaN=function(t){return Zo(t)&&t!=+t},Pe.isNative=function(t){if(gs(t))throw new kt("Unsupported core-js use. Try https://npms.io/search?q=ponyfill.");return jr(t)},Pe.isNil=function(t){return null==t},Pe.isNull=function(t){return null===t},Pe.isNumber=Zo,Pe.isObject=qo,Pe.isObjectLike=Go,Pe.isPlainObject=tu,Pe.isRegExp=nu,Pe.isSafeInteger=function(t){return Yo(t)&&t>=-9007199254740991&&t<=u},Pe.isSet=eu,Pe.isString=ru,Pe.isSymbol=iu,Pe.isTypedArray=su,Pe.isUndefined=function(n){return n===t},Pe.isWeakMap=function(t){return Go(t)&&as(t)==C},Pe.isWeakSet=function(t){return Go(t)&&"[object WeakSet]"==Ar(t)},Pe.join=function(t,n){return null==t?"":de.call(t,n)},Pe.kebabCase=Lu,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=au(r))<0?ve(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,Fn,s,!0)},Pe.lowerCase=Wu,Pe.lowerFirst=Bu,Pe.lt=ou,Pe.lte=uu,Pe.max=function(n){return n&&n.length?fr(n,Zu,xr):t},Pe.maxBy=function(n,e){return n&&n.length?fr(n,is(e,2),xr):t},Pe.mean=function(t){return Ln(t,Zu)},Pe.meanBy=function(t,n){return Ln(t,is(n,2))},Pe.min=function(n){return n&&n.length?fr(n,Zu,_r):t},Pe.minBy=function(n,e){return n&&n.length?fr(n,is(e,2),_r):t},Pe.stubArray=lc,Pe.stubFalse=fc,Pe.stubObject=function(){return{}},Pe.stubString=function(){return""},Pe.stubTrue=function(){return!0},Pe.multiply=gc,Pe.nth=function(n,e){return n&&n.length?Fr(n,au(e)):t},Pe.noConflict=function(){return hn._===this&&(hn._=Pt),this},Pe.noop=ic,Pe.now=Ao,Pe.pad=function(t,n,e){t=pu(t);var r=(n=au(n))?ue(t):0;if(!n||r>=n)return t;var i=(n-r)/2;return Li(pn(i),e)+t+Li(dn(i),e)},Pe.padEnd=function(t,n,e){t=pu(t);var r=(n=au(n))?ue(t):0;return n&&r<n?t+Li(n-r,e):t},Pe.padStart=function(t,n,e){t=pu(t);var r=(n=au(n))?ue(t):0;return n&&r<n?Li(n-r,e)+t:t},Pe.parseInt=function(t,n,e){return e||null==n?n=0:n&&(n=+n),ge(pu(t).replace(tt,""),n||0)},Pe.random=function(n,e,r){if(r&&"boolean"!=typeof r&&vs(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=hu(n),e===t?(e=n,n=0):e=hu(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=Lo(t)?jn:Nn,i=arguments.length<3;return r(t,is(n,4),e,i,hr)},Pe.reduceRight=function(t,n,e){var r=Lo(t)?In:Nn,i=arguments.length<3;return r(t,is(n,4),e,i,ar)},Pe.repeat=function(n,e,r){return e=(r?vs(n,e,r):e===t)?1:au(e),Hr(pu(n),e)},Pe.replace=function(){var t=arguments,n=pu(t[0]);return t.length<3?n:n.replace(t[1],t[2])},Pe.result=function(n,e,r){var i=-1,s=(e=vi(e,n)).length;for(s||(s=1,n=t);++i<s;){var o=null==n?t:n[Is(e[i])];o===t&&(i=s,o=r),n=Qo(o)?o.call(n):o}return n},Pe.round=bc,Pe.runInContext=P,Pe.sample=function(t){return(Lo(t)?Ye:Qr)(t)},Pe.size=function(t){if(null==t)return 0;if(Bo(t))return ru(t)?ue(t):t.length;var n=as(t);return n==g||n==x?t.size:Or(t).length},Pe.snakeCase=Nu,Pe.some=function(n,e,r){var i=Lo(n)?On:ti;return r&&vs(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&&Do(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(Do(t[e],n))return e}return-1},Pe.startCase=Ku,Pe.startsWith=function(t,n,e){return t=pu(t),e=null==e?0:ir(au(e),0,t.length),n=si(n),t.slice(e,e+n.length)==n},Pe.subtract=mc,Pe.sum=function(t){return t&&t.length?Kn(t,Zu):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&&vs(n,e,r)&&(e=t),n=pu(n),e=yu({},e,i,Yi);var s,o,u=yu({},e.imports,i.imports,Yi),c=$u(u),h=Yn(u,c),a=0,l=e.interpolate||wt,f="__p += '",d=St((e.escape||wt).source+"|"+l.source+"|"+(l===Y?ct:wt).source+"|"+(e.evaluate||wt).source+"|$","g"),p="//# sourceURL="+(It.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 v=It.call(e,"variable")&&e.variable;if(v){if(ot.test(v))throw new kt("Invalid `variable` option passed into `_.template`")}else f="with (obj) {\n"+f+"\n}\n";f=(o?f.replace(F,""):f).replace(L,"$1").replace(W,"$1;"),f="function("+(v||"obj")+") {\n"+(v?"":"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=Yu((function(){return At(c,p+"return "+f).apply(t,h)}));if(w.source=f,Vo(w))throw w;return w},Pe.times=function(t,n){if((t=au(t))<1||t>u)return[];var e=h,r=we(t,h);n=is(n),t-=h;for(var i=Hn(r,n);++e<t;)n(e);return i},Pe.toFinite=hu,Pe.toInteger=au,Pe.toLength=lu,Pe.toLower=function(t){return pu(t).toLowerCase()},Pe.toNumber=fu,Pe.toSafeInteger=function(t){return t?ir(au(t),-9007199254740991,u):0===t?t:0},Pe.toString=pu,Pe.toUpper=function(t){return pu(t).toUpperCase()},Pe.trim=function(n,e,r){if((n=pu(n))&&(r||e===t))return Vn(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=pu(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=pu(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(qo(e)){var s="separator"in e?e.separator:s;r="length"in e?au(e.length):r,i="omission"in e?si(e.omission):i}var o=(n=pu(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),nu(s)){if(n.slice(c).search(s)){var a,l=h;for(s.global||(s=St(s.source,pu(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=pu(t))&&K.test(t)?t.replace(B,ae):t},Pe.uniqueId=function(t){var n=++Ot;return pu(t)+n},Pe.upperCase=Hu,Pe.upperFirst=Vu,Pe.each=po,Pe.eachRight=vo,Pe.first=Ws,rc(Pe,(dc={},yr(Pe,(function(t,n){It.call(Pe.prototype,n)||(dc[n]=t)})),dc),{chain:!1}),Pe.VERSION="4.17.23",xn(["bind","bindKey","curry","curryRight","partial","partialRight"],(function(t){Pe[t].placeholder=Pe})),xn(["drop","take"],(function(n,e){We.prototype[n]=function(r){r=r===t?1:ve(au(r),0);var i=this.__filtered__&&!e?new We(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},We.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;We.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":"");We.prototype[t]=function(){return this[e](1).value()[0]}})),xn(["initial","tail"],(function(t,n){var e="drop"+(n?"":"Right");We.prototype[t]=function(){return this.__filtered__?new We(this):this[e](1)}})),We.prototype.compact=function(){return this.filter(Zu)},We.prototype.find=function(t){return this.filter(t).head()},We.prototype.findLast=function(t){return this.reverse().find(t)},We.prototype.invokeMap=Vr((function(t,n){return"function"==typeof t?new We(this):this.map((function(e){return $r(e,t,n)}))})),We.prototype.reject=function(t){return this.filter(jo(is(t)))},We.prototype.slice=function(n,e){n=au(n);var r=this;return r.__filtered__&&(n>0||e<0)?new We(r):(n<0?r=r.takeRight(-n):n&&(r=r.drop(n)),e!==t&&(r=(e=au(e))<0?r.dropRight(-e):r.take(e-n)),r)},We.prototype.takeRightWhile=function(t){return this.reverse().takeWhile(t).reverse()},We.prototype.toArray=function(){return this.take(h)},yr(We.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 We,h=u[0],a=c||Lo(e),l=function(t){var n=s.apply(Pe,Un([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,p=c&&!this.__actions__.length;if(!o&&a){e=p?e:new We(this);var v=n.apply(e,u);return v.__actions__.push({func:co,args:[l],thisArg:t}),new Le(v,f)}return d&&p?n.apply(this,u):(v=this.thru(l),d?i?v.value()[0]:v.value():v)})})),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(Lo(i)?i:[],t)}return this[e]((function(e){return n.apply(Lo(e)?e:[],t)}))}})),yr(We.prototype,(function(t,n){var e=Pe[n];if(e){var r=e.name+"";It.call(Ee,r)||(Ee[r]=[]),Ee[r].push({name:n,func:e})}})),Ee[Di(t,2).name]=[{name:"wrapper",func:t}],We.prototype.clone=function(){var t=new We(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},We.prototype.reverse=function(){if(this.__filtered__){var t=new We(this);t.__dir__=-1,t.__filtered__=!0}else(t=this.clone()).__dir__*=-1;return t},We.prototype.value=function(){var t=this.__wrapped__.value(),n=this.__dir__,e=Lo(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=ve(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 p=[];t:for(;c--&&f<d;){for(var v=-1,w=t[h+=n];++v<l;){var y=a[v],g=y.type,b=(0,y.iteratee)(w);if(2==g)w=b;else if(!b){if(1==g)continue t;break t}}p[f++]=w}return p},Pe.prototype.at=ho,Pe.prototype.chain=function(){return uo(this)},Pe.prototype.commit=function(){return new Le(this.value(),this.__chain__)},Pe.prototype.next=function(){this.__values__===t&&(this.__values__=cu(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 Fe;){var i=_s(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 We){var e=n;return this.__actions__.length&&(e=new We(this)),(e=e.reverse()).__actions__.push({func:co,args:[Xs],thisArg:t}),new Le(e,this.__chain__)}return this.thru(Xs)},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(Pc.exports)),Pc.exports);
1
+ import{p as t,H as n,c as e,h as r,d as i,t as s}from"./p-Cj-I2_Og.js";import{K as o}from"./p-D8W6LE-c.js";import{k as u,l as c,b as a,m as h,c as l,n as f,o as d,p,q as v,h as w,r as y,i as g,f as b,g as m,e as k,d as A,s as x,K as M,a as S,j as C}from"./p-BP6ggkYA.js";import{K as $,d as E}from"./p-BGwkUUZk.js";import{O as T}from"./p-B0kd2rUI.js";import{K as U,d as j}from"./p-Cpb-fnoO.js";import{K as I}from"./p-n789Y3S-.js";import{K as O,a as _}from"./p-BX4JyoOd.js";import{K as z}from"./p-l10It7Nm.js";import{d as D}from"./p-JdxbP-1P.js";var P="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};class R extends u{touchStartTimeout=null;constructor(t){super(t)}handlePointerDown(t){"mouse"===t.pointerType&&c.isLeftClick(t)&&(this._core.store.state.isErasing=!0),"touch"!==t.pointerType&&"pen"!==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||"pen"===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||"pen"===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 F(t,n){return new Promise((function(e,r){let i;return L(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 L=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),a=s+c+2+12*r.getUint16(s+c,u);for(let t=s+c+2;t<a;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 W={},B={get exports(){return W},set exports(t){W=t}};!function(){var t,n,e={};B.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 a=r(u,s+=4);r(u,s+=2);var h=i(u,s+=2),l=i(u,s+=4);s+=4,s=l;for(var f=0;f<a;f++){i(u,s),s+=4,s+=4,s+=4,i(u,s+=4),h=i(u,s+=4);var d=i(u,s+=4),p=r(u,s+=4),v=r(u,s+2),w=r(u,s+4);s+=6;var y=i(u,s+=8);s+=4,s+=p+v+w,e._readLocal(u,y,o,h,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 a=u(t,n+=2);c(t,n+=2),c(t,n+=4),n+=4;var h=u(t,n+=8),l=u(t,n+=2),f=e.bin.readUTF8(t,n+=2,h);if(n+=h,n+=l,o)r[f]={size:s,csize:i};else{var d=new Uint8Array(t.buffer,n);if(0==a)r[f]=new Uint8Array(d.buffer.slice(n,n+i));else{if(8!=a)throw"unknown compression method: "+a;var p=new Uint8Array(s);e.inflateRaw(d,p),r[f]=p}}},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,a=t[u],h=e.crc.crc(a,0,a.length);o[u]={cpr:c,usize:a.length,crc:h,file:c?e.deflateRaw(a):a}}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 p=o[u];d.push(f),f=e._writeHeader(l,f,u,p,0)}var v=0,w=f;for(var u in o)p=o[u],d.push(f),f=e._writeHeader(l,f,u,p,1,d[v++]);var y=f-w;return i(l,f,101010256),f+=4,s(l,f+=4,v),s(l,f+=2,v),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,a=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,a.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(a,n),n+=a.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,a=0,h=r<<3,l=0,f=t.length;if(0==i){for(;a<f;)c(n,h,a+(M=Math.min(65535,f-a))==f?1:0),h=e.F._copyExact(t,a,M,n,h+8),a+=M;return h>>>3}var d=o.lits,p=o.strt,v=o.prev,w=0,y=0,g=0,b=0,m=0,k=0;for(f>2&&(p[k=e.F._hash(t,0)]=0),a=0;a<f;a++){if(m=k,a+1<f-2){k=e.F._hash(t,a+1);var A=a+1&32767;v[A]=p[k],p[k]=A}if(l<=a){(w>14e3||y>26697)&&f-a>100&&(l<a&&(d[w]=a-l,w+=2,l=a),h=e.F._writeBlock(a==f-1||l==f?1:0,d,w,b,t,g,a-g,n,h),w=y=b=0,g=a);var x=0;a<f-2&&(x=e.F._bestMatch(t,a,v,m,Math.min(s[2],f-a),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(S,o.df0);o.dhst[$]++,b+=o.exb[C]+o.dxb[$],d[w]=M<<23|a-l,d[w+1]=S<<16|C<<8|$,w+=2,l=a+M}else o.lhst[t[a]]++;y++}}for(g==a&&0!=t.length||(l<a&&(d[w]=a-l,w+=2,l=a),h=e.F._writeBlock(1,d,w,b,t,g,a-g,n,h),w=0,y=0,w=y=b=0,g=a);7&h;)h++;return h>>>3},e.F._bestMatch=function(t,n,r,i,s,o){var u=32767&n,c=r[u],a=u-c+32768&32767;if(c==u||i!=e.F._hash(t,n-a))return 0;for(var h=0,l=0,f=Math.min(32767,n);a<=f&&0!=--o&&c!=u;){if(0==h||t[n+h]==t[n+h-a]){var d=e.F._howLong(t,n,a);if(d>h){if(l=a,(h=d)>=s)break;a+2<d&&(d=a+2);for(var p=0,v=0;v<d-2;v++){var w=n-a+v+32768&32767,y=w-r[w]+32768&32767;y>p&&(p=y,c=w)}}}a+=(u=c)-(c=r[u])+32768&32767}return h<<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,a){var h,l,f,d,p,v,w,y,g,b=e.F.U,m=e.F._putsF,k=e.F._putsE;b.lhst[256]++,l=(h=e.F.getTrees())[0],f=h[1],d=h[2],p=h[3],v=h[4],w=h[5],y=h[6],g=h[7];var A=32+(a+3&7?8-(a+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=A<x&&A<M?0:x<M?1:2;if(m(c,a,t),m(c,a+1,C),a+=3,0==C){for(;7&a;)a++;a=e.F._copyExact(s,o,u,c,a)}else{var $,E;if(1==C&&($=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),$=b.ltree,E=b.dtree,k(c,a,p-257),k(c,a+=5,v-1),k(c,a+=5,w-4),a+=4;for(var T=0;T<w;T++)k(c,a+3*T,b.itree[1+(b.ordr[T]<<1)]);a=e.F._codeTiny(y,b.itree,c,a+=3*w),a=e.F._codeTiny(g,b.itree,c,a)}for(var U=o,j=0;j<r;j+=2){for(var I=n[j],O=I>>>23,_=U+(8388607&I);U<_;)a=e.F._writeLit(s[U++],$,c,a);if(0!=O){var z=n[j+1],D=z>>16,P=z>>8&255,R=255&z;k(c,a=e.F._writeLit(257+P,$,c,a),O-b.of0[P]),m(c,a=e.F._writeLit(R,E,c,a+=b.exb[P]),D-b.df0[R]),a+=b.dxb[R],U+=O}}a=e.F._writeLit(256,$,c,a)}return a},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 a=e.F._hufTree(t.ihst,t.itree,7),h=19;h>4&&0==t.itree[1+(t.ordr[h-1]<<1)];)h--;return[n,r,a,s,u,h,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;(a=Math.min(c+1-r>>>1,138))<11?n.push(17,a-3):n.push(18,a-11),r+=2*a-2}else if(i==u&&s==i&&o==i){for(c=r+5;c+2<e&&t[c+2]==i;)c+=2;var a=Math.min(c+1-r>>>1,6);n.push(16,a-3),r+=2*a-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,a=i.slice(0);if(0==c)return 0;if(1==c){var h=i[0].lit;return a=0==h?1:0,n[1+(h<<1)]=1,n[1+(a<<1)]=1,1}i.sort((function(t,n){return t.f-n.f}));var l=i[0],f=i[1],d=0,p=1,v=2;for(i[0]={lit:-1,f:l.f+f.f,l,r:f,d:0};p!=c-1;)l=d!=p&&(v==c||i[d].f<i[v].f)?i[d++]:i[v++],f=d!=p&&(v==c||i[d].f<i[v].f)?i[d++]:i[v++],i[p++]={lit:-1,f:l.f+f.f,l,r:f};var w=e.F.setDepth(i[p-1],0);for(w>r&&(e.F.restrictDepth(a,r,w),w=r),u=0;u<c;u++)n[1+(a[u].lit<<1)]=a[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,a=i.codes2map,h=i._get17,l=i.U,f=null==n;f&&(n=new r(t.length>>>2<<3));for(var d,p,v=0,w=0,y=0,g=0,b=0,m=0,k=0,A=0,x=0;0==v;)if(v=s(t,x,1),w=s(t,x+1,2),x+=3,0!=w){if(f&&(n=e.F._check(n,A+(1<<17))),1==w&&(d=l.flmap,p=l.fdmap,m=511,k=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),a(l.itree,S,l.imap),d=l.lmap,p=l.dmap,x=u(l.imap,(1<<S)-1,y+g,t,x,l.ttree);var $=i._copyOut(l.ttree,0,y,l.ltree);m=(1<<$)-1;var E=i._copyOut(l.ttree,y,g,l.dtree);k=(1<<E)-1,c(l.ltree,$),a(l.ltree,$,d),c(l.dtree,E),a(l.dtree,E,p)}for(;;){var T=d[h(t,x)&m];x+=15&T;var U=T>>>4;if(U>>>8==0)n[A++]=U;else{if(256==U)break;var j=A+U-254;if(U>264){var I=l.ldef[U-257];j=A+(I>>>3)+o(t,x,7&I),x+=7&I}var O=p[h(t,x)&k],_=l.ddef[O>>>4],z=(_>>>4)+s(t,x+=15&O,15&_);for(x+=15&_,f&&(n=e.F._check(n,A+(1<<17)));A<j;)n[A]=n[A++-z],n[A]=n[A++-z],n[A]=n[A++-z],n[A]=n[A++-z];A=j}}}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,A+P)),n.set(new r(t.buffer,t.byteOffset+D,P),A),x=D+P<<3,A+=P}return n.length==A?n:n.slice(0,A)},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,a=0;a<r;){var h=t[c(i,s)&n];s+=15&h;var l=h>>>4;if(l<=15)o[a]=l,a++;else{var f=0,d=0;16==l?(d=3+u(i,s,2),s+=2,f=o[a-1]):17==l?(d=3+u(i,s,3),s+=3):18==l&&(d=11+u(i,s,7),s+=7);for(var p=a+d;a<p;)o[a]=f,a++}}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,a=u.bl_count,h=0;h<=n;h++)a[h]=0;for(h=1;h<c;h+=2)a[t[h]]++;var l=u.next_code;for(r=0,a[0]=0,i=1;i<=n;i++)l[i]=r=r+a[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,a=n-u,h=t[o]<<a,l=h+(1<<a);h!=l;)r[s[h]>>>15-n]=c,h++},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 N=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:W},[W]);const K=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),a=new Uint8Array(4*o),h=new Uint32Array(a.buffer),{ctype:l}=i,{depth:f}=i,d=t.readUshort;if(6==l){const t=o<<2;if(8==f)for(var p=0;p<t;p+=4)a[p]=n[p],a[p+1]=n[p+1],a[p+2]=n[p+2],a[p+3]=n[p+3];if(16==f)for(p=0;p<t;p++)a[p]=n[p<<1]}else if(2==l){const t=i.tabs.tRNS;if(null==t){if(8==f)for(p=0;p<o;p++){var v=3*p;h[p]=255<<24|n[v+2]<<16|n[v+1]<<8|n[v]}if(16==f)for(p=0;p<o;p++)h[p]=255<<24|n[4+(v=6*p)]<<16|n[v+2]<<8|n[v]}else{var w=t[0];const e=t[1],r=t[2];if(8==f)for(p=0;p<o;p++){var y=p<<2;h[p]=255<<24|n[2+(v=3*p)]<<16|n[v+1]<<8|n[v],n[v]==w&&n[v+1]==e&&n[v+2]==r&&(a[y+3]=0)}if(16==f)for(p=0;p<o;p++)y=p<<2,h[p]=255<<24|n[4+(v=6*p)]<<16|n[v+2]<<8|n[v],d(n,v)==w&&d(n,v+2)==e&&d(n,v+4)==r&&(a[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(p=0;p<e;p++){var k=3*(A=n[b+(p>>3)]>>7-(7&p)&1);a[y=m+p<<2]=t[k],a[y+1]=t[k+1],a[y+2]=t[k+2],a[y+3]=A<u?s[A]:255}}if(2==f)for(g=0;g<r;g++)for(b=g*c,m=g*e,p=0;p<e;p++)k=3*(A=n[b+(p>>2)]>>6-((3&p)<<1)&3),a[y=m+p<<2]=t[k],a[y+1]=t[k+1],a[y+2]=t[k+2],a[y+3]=A<u?s[A]:255;if(4==f)for(g=0;g<r;g++)for(b=g*c,m=g*e,p=0;p<e;p++)k=3*(A=n[b+(p>>1)]>>4-((1&p)<<2)&15),a[y=m+p<<2]=t[k],a[y+1]=t[k+1],a[y+2]=t[k+2],a[y+3]=A<u?s[A]:255;if(8==f)for(p=0;p<o;p++){var A;k=3*(A=n[p]),a[y=p<<2]=t[k],a[y+1]=t[k+1],a[y+2]=t[k+2],a[y+3]=A<u?s[A]:255}}else if(4==l){if(8==f)for(p=0;p<o;p++){var x=n[M=p<<1];a[y=p<<2]=x,a[y+1]=x,a[y+2]=x,a[y+3]=n[M+1]}if(16==f)for(p=0;p<o;p++){var M;x=n[M=p<<2],a[y=p<<2]=x,a[y+1]=x,a[y+2]=x,a[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;h[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,h[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,h[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,h[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,h[r+S]=C<<24|x<<16|x<<8|x}return a}function e(t,n,e,u){const c=s(t),a=Math.ceil(e*c/8),h=new Uint8Array((a+1+t.interlace)*u);return n=t.tabs.CgBI?i(n,h):r(n,h),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),a=new Uint8Array(r*c);let h=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],p=[8,8,4,4,2,2,1];let v=0;for(;v<7;){const s=d[v],y=p[v];let g=0,b=0,m=l[v];for(;m<r;)m+=s,b++;let k=f[v];for(;k<e;)k+=y,g++;const A=Math.ceil(g*i/8);o(t,n,h,g,b);let x=0,M=l[v];for(;M<r;){let n=f[v],r=h+x*A<<3;for(;n<e;){var w;if(1==i&&(w=(w=t[r>>3])>>7-(7&r)&1,a[M*c+(n>>3)]|=w<<7-(7&n)),2==i&&(w=(w=t[r>>3])>>6-(7&r)&3,a[M*c+(n>>2)]|=w<<6-((3&n)<<1)),4==i&&(w=(w=t[r>>3])>>4-(7&r)&15,a[M*c+(n>>1)]|=w<<4-((1&n)<<2)),i>=8){const e=M*c+n*u;for(let n=0;n<u;n++)a[e+n]=t[(r>>3)+n]}r+=i,n+=y}x++,M+=s}g*b!=0&&(h+=b*(1+A)),v+=1}return a}(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,a=0,h=0,l=0,f=0,d=0,p=0;if(3==n[0]&&0==n[1])return e||new r(0);const v=t.H,w=v.b,y=v.e,g=v.R,b=v.n,m=v.A,k=v.Z,A=v.m,x=null==e;for(x&&(e=new r(n.length>>>2<<5));0==o;)if(o=w(n,p,1),u=w(n,p+1,2),p+=3,0!=u){if(x&&(e=t.H.W(e,d+(1<<17))),1==u&&(i=A.J,s=A.h,l=511,f=31),2==u){c=y(n,p,5)+257,a=y(n,p+5,5)+1,h=y(n,p+10,4)+4,p+=14;let t=1;for(var M=0;M<38;M+=2)A.Q[M]=0,A.Q[M+1]=0;for(M=0;M<h;M++){const e=y(n,p+3*M,3);A.Q[1+(A.X[M]<<1)]=e,e>t&&(t=e)}p+=3*h,b(A.Q,t),m(A.Q,t,A.u),i=A.w,s=A.d,p=g(A.u,(1<<t)-1,c+a,n,p,A.v);const e=v.V(A.v,0,c,A.C);l=(1<<e)-1;const r=v.V(A.v,c,a,A.D);f=(1<<r)-1,b(A.C,e),m(A.C,e,i),b(A.D,r),m(A.D,r,s)}for(;;){const t=i[k(n,p)&l];p+=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=A.q[r-257];t=d+(e>>>3)+y(n,p,7&e),p+=7&e}const i=s[k(n,p)&f];p+=15&i;const o=A.c[i>>>4],u=(o>>>4)+w(n,p,15&o);for(p+=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&p&&(p+=8-(7&p));const i=4+(p>>>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),p=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 a=0;for(;a<r;){const t=n[c(i,s)&e];s+=15&t;const r=t>>>4;if(r<=15)o[a]=r,a++;else{let t=0,n=0;16==r?(n=3+u(i,s,2),s+=2,t=o[a-1]):17==r?(n=3+u(i,s,3),s+=3):18==r&&(n=11+u(i,s,7),s+=7);const e=a+n;for(;a<e;)o[a]=t,a++}}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 a=r.j;for(var h=0;h<=e;h++)a[h]=0;for(h=1;h<i;h+=2)a[n[h]]++;const l=r.K;for(s=0,a[0]=0,o=1;o<=e;o++)s=s+a[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 a=c+(1<<u);for(;c!=a;)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 a,h;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(a=e+n*c,h=a+n+1,l=t[h-1],f=0,0==l)for(;f<c;f++)t[a+f]=t[h+f];else if(1==l){for(;f<o;f++)t[a+f]=t[h+f];for(;f<c;f++)t[a+f]=t[h+f]+t[a+f-o]}else if(2==l)for(;f<c;f++)t[a+f]=t[h+f]+t[a+f-c];else if(3==l){for(;f<o;f++)t[a+f]=t[h+f]+(t[a+f-c]>>>1);for(;f<c;f++)t[a+f]=t[h+f]+(t[a+f-c]+t[a+f-o]>>>1)}else{for(;f<o;f++)t[a+f]=t[h+f]+u(0,t[a+f-c],0);for(;f<c;f++)t[a+f]=t[h+f]+u(t[a+f-o],t[a+f-c],t[a+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 a(t,n,e,r,i,s,o,u,c){const a=Math.min(n,i),h=Math.min(e,s);let l=0,f=0;for(let e=0;e<h;e++)for(let s=0;s<a;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),p=t[l]*d,v=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]=(p+g*n)*i,r[f+1]=(v+b*n)*i,r[f+2]=(w+m*n)*i}else if(2==c)p=t[l],v=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])&&p==g&&v==b&&w==m?(r[f]=0,r[f+1]=0,r[f+2]=0,r[f+3]=0):(r[f]=p,r[f+1]=v,r[f+2]=w,r[f+3]=d);else if(3==c){if(p=t[l],v=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])&&p==g&&v==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,a=u.readUshort,h=u.readUint,l={tabs:{},frames:[]},f=new Uint8Array(s.length);let d,p=0,v=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[p+y]=s[o+y];p+=t}else if("acTL"==n)l.tabs[n]={num_frames:h(s,o),num_plays:h(s,o+4)},d=new Uint8Array(s.length);else if("fcTL"==n){0!=v&&((M=l.frames[l.frames.length-1]).data=e(l,d.slice(0,v),M.rect.width,M.rect.height),v=0);const t={x:h(s,o+12),y:h(s,o+16),width:h(s,o+4),height:h(s,o+8)};let n=a(s,o+22);n=a(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[v+y]=s[o+y+4];v+=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),k=o+t-b-1;if("tEXt"==n)x=u.readASCII(s,b+1,k);else{var A=r(s.slice(b+2,b+2+k));x=u.readUTF8(A,0,A.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),k=t-((g=b+1)-o),0==e?x=u.readUTF8(s,g,k):(A=r(s.slice(g,g+k)),x=u.readUTF8(A,0,A.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(a(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]=a(s,o):2==l.ctype&&(l.tabs[n]=[a(s,o),a(s,o+2),a(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]=[a(s,o)]:2==l.ctype||6==l.ctype?l.tabs[n]=[a(s,o),a(s,o+2),a(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!=v&&((M=l.frames[l.frames.length-1]).data=e(l,d.slice(0,v),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,p=f.rect.y,v=f.rect.width,w=f.rect.height,y=n(f.data,v,w,t);if(0!=l)for(var h=0;h<s;h++)c[h]=o[h];if(0==f.blend?a(y,v,w,o,e,r,d,p,0):1==f.blend&&a(y,v,w,o,e,r,d,p,1),i.push(o.buffer.slice(0)),0==f.dispose);else if(1==f.dispose)a(u,v,w,o,e,r,d,p,0);else if(2==f.dispose)for(h=0;h<s;h++)o[h]=c[h]}return i},_paeth:u,_copyTile:a,_bin:t}}();!function(){const{_copyTile:t}=K,{_bin:n}=K,e=K._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,a){null==a&&(a=1);const h=r.length,l=[];for(var f=0;f<h;f++){const t=r[f];l.push([t>>>0&255,t>>>8&255,t>>>16&255,t>>>24&255])}for(f=0;f<h;f++){let t=4294967295;for(var d=0,p=0;p<h;p++){var v=o(l[f],l[p]);p!=f&&v<t&&(t=v,d=p)}}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!=a?[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]+(v=g[4*(3&u)+(3&m)])),s(t[f+1]+v),s(t[f+2]+v),s(t[f+3]+v)],d=0;let k=16777215;for(p=0;p<h;p++){const t=o(b,l[p]);t<k&&(k=t,d=p)}const A=l[d],x=[b[0]-A[0],b[1]-A[1],b[2]-A[2],b[3]-A[3]];1==a&&(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,a=n.writeUshort,h=n.writeASCII;let l=8;const f=t.frames.length>1;let d,p=!1,v=33+(f?20:0);if(null!=o.sRGB&&(v+=13),null!=o.pHYs&&(v+=21),null!=o.iCCP&&(d=pako.deflate(o.iCCP),v+=21+d.length+4),3==t.ctype){for(var w=t.plte.length,y=0;y<w;y++)t.plte[y]>>>24!=255&&(p=!0);v+=8+3*w+4+(p?8+1*w+4:0)}for(var g=0;g<t.frames.length;g++)f&&(v+=38),v+=(A=t.frames[g]).cimg.length+12,0!=g&&(v+=4);v+=12;const b=new Uint8Array(v),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,h(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,h(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,h(b,l,"iCCP"),l+=4,h(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,h(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,h(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,h(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,p){for(c(b,l,w),l+=4,h(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 k=0;for(g=0;g<t.frames.length;g++){var A=t.frames[g];f&&(c(b,l,26),l+=4,h(b,l,"fcTL"),l+=4,c(b,l,k++),l+=4,c(b,l,A.rect.width),l+=4,c(b,l,A.rect.height),l+=4,c(b,l,A.rect.x),l+=4,c(b,l,A.rect.y),l+=4,a(b,l,s[g]),l+=2,a(b,l,1e3),l+=2,b[l]=A.dispose,l++,b[l]=A.blend,l++,c(b,l,u(b,l-30,30)),l+=4);const n=A.cimg;c(b,l,(w=n.length)+(0==g?0:4)),l+=4;const e=l;h(b,l,0==g?"IDAT":"fdAT"),l+=4,0!=g&&(c(b,l,k++),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,h(b,l,"IEND"),l+=4,c(b,l,u(b,l-4,4)),l+=4,b.buffer}function a(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 h(n,e,r,i,s){const o=s[0],c=s[1],a=s[2],h=s[3],d=s[4],p=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,k=0;k<m;k+=4)g&=t[k+3]}const A=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 a;let v=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 k=0,A=1e9;for(let t=0;t<m;t++){var h=new Uint8Array(n[c-1-t]);const i=new Uint32Array(n[c-1-t]);let o=e,u=r,a=-1,l=-1;for(let t=0;t<r;t++)for(let n=0;n<e;n++)d[p=t*e+n]!=i[p]&&(n<o&&(o=n),n>a&&(a=n),t<u&&(u=t),t>l&&(l=t));-1==a&&(o=u=a=l=0),s&&(!(1&~o)&&o--,!(1&~u)&&u--);const f=(a-o+1)*(l-u+1);f<A&&(A=f,k=t,v=o,w=u,y=a-o+1,g=l-u+1)}h=new Uint8Array(n[c-1-k]),1==k&&(u[c-1].dispose=2),a=new Uint8Array(y*g*4),t(h,e,r,a,y,g,-v,-w,0),b=t(l,e,r,a,y,g,-v,-w,3)?1:0,1==b?f(l,e,r,a,{x:v,y:w,width:y,height:g}):t(l,e,r,a,y,g,-v,-w,0)}else a=l.slice(0);u.push({rect:{x:v,y:w,width:y,height:g},img:a,blend:b,dispose:0})}if(i)for(c=0;c<u.length;c++){if(1==(v=u[c]).blend)continue;const t=v.rect,i=u[c-1].rect,o=Math.min(t.x,i.x),a=Math.min(t.y,i.y),h={x:o,y:a,width:Math.max(t.x+t.width,i.x+i.width)-o,height:Math.max(t.y+t.height,i.y+i.height)-a};u[c-1].dispose=1,c-1!=0&&l(n,e,r,u,c-1,h,s),l(n,e,r,u,c,h,s)}let d=0;if(1!=n.length)for(var p=0;p<u.length;p++){var v;d+=(v=u[p]).rect.width*v.rect.height}return u}(n,e,r,o,c,a),M={},S=[],C=[];if(0!=i){const t=[];for(k=0;k<x.length;k++)t.push(x[k].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=v(n,i);for(k=0;k<e.plte.length;k++)S.push(e.plte[k].est.rgba);let r=0;for(k=0;k<x.length;k++){const t=(E=x[k]).img.length;var $=new Uint8Array(e.inds.buffer,r>>2,t>>2);C.push($);const n=new Uint8Array(e.abuf,r,t);p&&u(E.img,E.rect.width,E.rect.height,S,n,$),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 T=E.rect.width;for(m=t.length,$=new Uint8Array(m),C.push($),k=0;k<m;k++){const n=t[k];if(0!=k&&n==t[k-1])$[k]=$[k-1];else if(k>T&&n==t[k-T])$[k]=$[k-T];else{let t=M[n];if(null==t&&(M[n]=t=S.length,S.push(n),S.length>=300))break;$[k]=t}}}const U=S.length;for(U<=256&&0==d&&(y=U<=2?1:U<=4?2:U<=16?4:8,y=Math.max(y,h)),b=0;b<x.length;b++){const t=(E=x[b]).rect.height;let n=E.img,e=4*(T=E.rect.width),r=4;if(U<=256&&0==d){e=Math.ceil(y*T/8);var j=new Uint8Array(e*t);const i=C[b];for(let n=0;n<t;n++){k=n*e;const t=n*T;if(8==y)for(var I=0;I<T;I++)j[k+I]=i[t+I];else if(4==y)for(I=0;I<T;I++)j[k+(I>>1)]|=i[t+I]<<4-4*(1&I);else if(2==y)for(I=0;I<T;I++)j[k+(I>>2)]|=i[t+I]<<6-2*(3&I);else if(1==y)for(I=0;I<T;I++)j[k+(I>>3)]|=i[t+I]<<7-1*(7&I)}n=j,w=3,r=1}else if(0==A&&1==x.length){j=new Uint8Array(T*t*3);const i=T*t;for(k=0;k<i;k++){const t=3*k,e=4*k;j[t]=n[e],j[t+1]=n[e+1],j[t+2]=n[e+2]}n=j,w=2,r=3,e=3*T}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,a=Uint32Array,h=new c(n[s-1]),l=new a(n[s-1]),d=s+1<n.length?new c(n[s+1]):null,p=new c(n[s]),v=new a(p.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,a=v[c];0==a||0==i[s-1].dispose&&l[c]==a&&(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(h,e,r,m.img,o.width,o.height,-o.x,-o.y,0),f(p,e,r,m.img,o)):t(p,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,a=[0,1,2,3,4];-1!=s?a=[s]:(n*r>5e5||1==e)&&(a=[0]),o&&(c={level:0});const h=N;for(var l=0;l<a.length;l++){for(let s=0;s<n;s++)p(i,t,s,r,e,a[l]);u.push(h.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 p(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 a=0;a<i;a++)t[c+a]=n[u+a];else t.set(new Uint8Array(n.buffer,u,i),c);else if(1==o){for(a=0;a<s;a++)t[c+a]=n[u+a];for(a=s;a<i;a++)t[c+a]=n[u+a]-n[u+a-s]+256&255}else if(0==r){for(a=0;a<s;a++)t[c+a]=n[u+a];if(2==o)for(a=s;a<i;a++)t[c+a]=n[u+a];if(3==o)for(a=s;a<i;a++)t[c+a]=n[u+a]-(n[u+a-s]>>1)+256&255;if(4==o)for(a=s;a<i;a++)t[c+a]=n[u+a]-e(n[u+a-s],0,0)+256&255}else{if(2==o)for(a=0;a<i;a++)t[c+a]=n[u+a]+256-n[u+a-i]&255;if(3==o){for(a=0;a<s;a++)t[c+a]=n[u+a]+256-(n[u+a-i]>>1)&255;for(a=s;a<i;a++)t[c+a]=n[u+a]+256-(n[u+a-i]+n[u+a-s]>>1)&255}if(4==o){for(a=0;a<s;a++)t[c+a]=n[u+a]+256-e(0,n[u+a-i],0)&255;for(a=s;a<i;a++)t[c+a]=n[u+a]+256-e(n[u+a-s],n[u+a-i],n[u+a-s-i])&255}}}function v(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,a=new Uint8Array(c>>2);let h;if(e.length<2e7)for(var l=0;l<c;l+=4)h=y(o,f=e[l]*(1/255),d=e[l+1]*(1/255),p=e[l+2]*(1/255),v=e[l+3]*(1/255)),a[l>>2]=h.ind,i[l>>2]=h.est.rgba;else for(l=0;l<c;l+=4){var f=e[l]*(1/255),d=e[l+1]*(1/255),p=e[l+2]*(1/255),v=e[l+3]*(1/255);for(h=o;h.left;)h=g(h.est,f,d,p,v)<=0?h.left:h.right;a[l>>2]=h.ind,i[l>>2]=h.est.rgba}return{abuf:r.buffer,inds:a,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=k(t,i.i0,i.i1),i.est=A(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 a={i0:u.i0,i1:c,bst:null,est:null,tdst:0,left:null,right:null};a.bst=k(t,a.i0,a.i1),a.est=A(a.bst);const h={i0:c,i1:u.i1,bst:null,est:null,tdst:0,left:null,right:null};for(h.bst={R:[],m:[],N:u.bst.N-a.bst.N},o=0;o<16;o++)h.bst.R[o]=u.bst.R[o]-a.bst.R[o];for(o=0;o<4;o++)h.bst.m[o]=u.bst.m[o]-a.bst.m[o];h.est=A(h.bst),u.left=a,u.right=h,s[i]=a,s.push(h)}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 a=y(u,n,e,r,i);return a.tdst<c.tdst?a: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 k(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 A(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,a=[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],h=a,l=x;let f=[Math.random(),Math.random(),Math.random(),Math.random()],d=0,p=0;if(0!=r)for(let t=0;t<16&&(f=l.multVec(h,f),p=Math.sqrt(l.dot(f,f)),f=l.sml(1/p,f),!(0!=t&&Math.abs(p-d)<1e-9));t++)d=p;const v=[i*c,s*c,o*c,u*c];return{Cov:a,q:v,e:f,L:d,eMq255:l.dot(l.sml(255,v),f),eMq:l.dot(f,v),rgba:(Math.round(255*v[3])<<24|Math.round(255*v[2])<<16|Math.round(255*v[1])<<8|Math.round(255*v[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]]};K.encode=function(t,n,e,r,i,s,o){null==r&&(r=0),null==o&&(o=!1);const u=h(t,n,e,r,[!1,!1,!1,0,o,!1]);return a(u,-1),c(u,n,e,i,s)},K.encodeLL=function(t,n,e,r,i,s,o,u){const h={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++)h.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 a(h,0,!0),c(h,n,e,o,u)},K.encode.compress=h,K.encode.dither=u,K.quantize=v,K.quantize.getKDtree=w,K.quantize.getNearest=y}();const H={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,a=122+c,h=new ArrayBuffer(a),l=new DataView(h),f=1<<20;let d,p,v,w,y=f,g=0,b=0,m=0;function k(t){l.setUint16(b,t,!0),b+=2}function A(t){l.setUint32(b,t,!0),b+=4}function x(t){b+=t}k(19778),A(a),x(4),A(122),A(108),A(e),A(-r>>>0),k(1),k(32),A(3),A(c),A(2835),A(2835),x(8),A(16711680),A(65280),A(255),A(4278190080),A(1466527264),function t(){for(;g<r&&y>0;){for(w=122+g*u,d=0;d<i;)y--,p=o[m++],v=p>>>24,l.setUint32(w+d,p<<8|v),d+=4;g++}m<o.length?(y=f,setTimeout(t,H._dly)):n(h)}()},toBlob(t,n){this.toArrayBuffer(t,(t=>{n(new Blob([t],{type:"image/bmp"}))}))},_dly:9};var V={CHROME:"CHROME",FIREFOX:"FIREFOX",DESKTOP_SAFARI:"DESKTOP_SAFARI",IE:"IE",IOS:"IOS",ETC:"ETC"},Q={[V.CHROME]:16384,[V.FIREFOX]:11180,[V.DESKTOP_SAFARI]:16384,[V.IE]:8192,[V.IOS]:4096,[V.ETC]:8192};const Y="undefined"!=typeof window,X="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope,q=Y&&window.cordova&&window.cordova.require&&window.cordova.require("cordova/modulemapper"),G=(Y||X)&&(q&&q.getOriginalSymbol(window,"File")||"undefined"!=typeof File&&File),J=(Y||X)&&(q&&q.getOriginalSymbol(window,"FileReader")||"undefined"!=typeof FileReader&&FileReader);function Z(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 a=new Blob([c],{type:s});a.name=n,a.lastModified=e,r(a)}))}function tt(t){return new Promise(((n,e)=>{const r=new J;r.onload=()=>n(r.result),r.onerror=t=>e(t),r.readAsDataURL(t)}))}function nt(t){return new Promise(((n,e)=>{const r=new Image;r.onload=()=>n(r),r.onerror=t=>e(t),r.src=t}))}function et(){if(void 0!==et.cachedResult)return et.cachedResult;let t=V.ETC;const{userAgent:n}=navigator;return/Chrom(e|ium)/i.test(n)?t=V.CHROME:/iP(ad|od|hone)/i.test(n)&&/WebKit/i.test(n)?t=V.IOS:/Safari/i.test(n)?t=V.DESKTOP_SAFARI:/Firefox/i.test(n)?t=V.FIREFOX:(/MSIE/i.test(n)||1==!!document.documentMode)&&(t=V.IE),et.cachedResult=t}function rt(t,n){const e=et(),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 it(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 st(t,n){const{width:e,height:r}=rt(t.width,t.height),[i,s]=it(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 ot(){return void 0!==ot.cachedResult||(ot.cachedResult=["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"undefined"!=typeof document&&"ontouchend"in document),ot.cachedResult}function ut(t,n={}){return new Promise((function(e,r){let i,s;var o=function(){try{return s=st(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 tt(t).then((function(t){try{return e=t,nt(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(ot()||[V.DESKTOP_SAFARI,V.MOBILE_SAFARI].includes(et()))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 ct(t,n,e,r,i=1){return new Promise((function(s,o){let u;if("image/png"===n){let a,h,l;return a=t.getContext("2d"),({data:h}=a.getImageData(0,0,t.width,t.height)),l=K.encode([h.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=>H.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 p;return p=t.toDataURL(n,i),Z(p,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 at(t){t.width=0,t.height=0}function ht(){return new Promise((function(t,n){let e,r,i,s;return void 0!==ht.cachedResult?t(ht.cachedResult):Z("data:image/jpeg;base64,/9j/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAYAAAAAAAD/2wCEAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/AABEIAAEAAgMBEQACEQEDEQH/xABKAAEAAAAAAAAAAAAAAAAAAAALEAEAAAAAAAAAAAAAAAAAAAAAAQEAAAAAAAAAAAAAAAAAAAAAEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwA/8H//2Q==","test.jpg",Date.now()).then((function(o){try{return e=o,ut(e).then((function(o){try{return r=o[1],ct(r,e.type,e.name,e.lastModified).then((function(e){try{return i=e,at(r),ut(i).then((function(e){try{return s=e[0],t(ht.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 lt(t){return new Promise(((n,e)=>{const r=new J;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 ft(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]=it(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),at(t)),o}function dt(t,n){const{width:e}=t,{height:r}=t,[i,s]=it(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),at(t),i}function pt(t,n,e=0){return new Promise((function(r,i){let s,o,u,c,a,h,l,f,d,p,v,w,y,g,b,m,k,A,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(),ut(t,n).then(function(e){try{return[,c]=e,S(),a=ft(c,n),S(),new Promise((function(e,r){var i;if(!(i=n.exifOrientation))return lt(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 h=e,S(),ht().then(function(e){try{return l=e?a:dt(a,h),S(),f=n.initialQuality||1,d=n.fileType||t.type,ct(l,d,t.name,t.lastModified,f).then(function(e){try{{if(p=e,S(),v=p.size>u,w=p.size>t.size,!v&&!w)return C(100),r(p);var s;function h(){if(o--&&(b>u||b>y)){let n,e;return n=M?.95*x.width:x.width,e=M?.95*x.height:x.height,[k,A]=it(n,e),A.drawImage(x,0,0,n,e),f*="image/png"===d?.85:.95,ct(k,d,t.name,t.lastModified,f).then((function(t){try{return m=t,at(x),x=k,b=m.size,C(Math.min(99,Math.floor((g-b)/(g-u)*100))),h}catch(t){return i(t)}}),i)}return[1]}return y=t.size,g=p.size,b=g,x=l,M=!n.alwaysKeepResolution&&v,(s=function(t){for(;t;){if(t.then)return void t.then(s,i);try{if(t.pop){if(t.length)return t.pop()?$.call(this):t;t=h}else t=t.call(this)}catch(t){return i(t)}}}.bind(this))(h);function $(){return at(x),at(k),at(a),at(l),at(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 vt;function wt(t,n){return new Promise(((e,r)=>{vt||(vt=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(vt);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 yt(t,n){return new Promise((function(e,r){let i,s,o,u,c,a;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 G))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(a="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope,!c||"function"!=typeof Worker||a)return pt(t,i).then(function(t){try{return s=t,f.call(this)}catch(t){return r(t)}}.bind(this),r);var h=function(){try{return f.call(this)}catch(t){return r(t)}}.bind(this),l=function(){try{return pt(t,i).then((function(t){try{return s=t,h()}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",wt(t,i).then((function(t){try{return s=t,h()}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=F(t,s))}catch(t){}return e(s)}}))}yt.getDataUrlFromFile=tt,yt.getFilefromDataUrl=Z,yt.loadImage=nt,yt.drawImageInCanvas=st,yt.drawFileInCanvas=ut,yt.canvasToFile=ct,yt.getExifOrientation=lt,yt.handleMaxWidthOrHeight=ft,yt.followExifOrientation=dt,yt.cleanupCanvasMemory=at,yt.isAutoOrientationInBrowser=ht,yt.approximateBelowMaximumCanvasSizeOfBrowser=rt,yt.copyExifWithoutOrientation=F,yt.getBrowserName=et,yt.version="2.0.2";class gt extends u{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]?yt(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=a.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",h.getTool("selection")),this._core.selectObjects([t]),this._core.engine.emitObjectsChange()}handleCancel(){this._core.store.setState("activeTool",h.getTool("selection"))}}class bt{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=U.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 mt=()=>new Map,kt=t=>{const n=mt();return t.forEach(((t,e)=>{n.set(e,t)})),n},At=(t,n,e)=>{let r=t.get(n);return void 0===r&&t.set(n,r=e()),r},xt=()=>new Set,Mt=t=>t[t.length-1],St=(t,n)=>{for(let e=0;e<n.length;e++)t.push(n[e])},Ct=Array.from,$t=(t,n)=>{for(let e=0;e<t.length;e++)if(!n(t[e],e,t))return!1;return!0},Et=(t,n)=>{for(let e=0;e<t.length;e++)if(n(t[e],e,t))return!0;return!1},Tt=Array.isArray;class Ut{constructor(){this._observers=mt()}on(t,n){return At(this._observers,t,xt).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 Ct((this._observers.get(t)||mt()).values()).forEach((t=>t(...n)))}destroy(){this._observers=mt()}}let jt=class{constructor(){this._observers=mt()}on(t,n){At(this._observers,t,xt).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 Ct((this._observers.get(t)||mt()).values()).forEach((t=>t(...n)))}destroy(){this._observers=mt()}};const It=Math.floor,Ot=Math.abs,_t=(t,n)=>t<n?t:n,zt=(t,n)=>t>n?t:n,Dt=Math.pow,Pt=t=>0!==t?t<0:1/t<0,Rt=64,Ft=128,Lt=127,Wt=Number.MAX_SAFE_INTEGER,Bt=Number.MIN_SAFE_INTEGER,Nt=Number.isInteger||(t=>"number"==typeof t&&isFinite(t)&&It(t)===t),Kt=String.fromCharCode,Ht=/^\s*/g,Vt=/([A-Z])/g,Qt=(t,n)=>(t=>t.replace(Ht,""))(t.replace(Vt,(t=>`${n}${(t=>t.toLowerCase())(t)}`))),Yt="undefined"!=typeof TextEncoder?new TextEncoder:null,Xt=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 qt="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});qt&&1===qt.decode(new Uint8Array).length&&(qt=null);let Gt=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}};const Jt=()=>new Gt,Zt=t=>{let n=t.cpos;for(let e=0;e<t.bufs.length;e++)n+=t.bufs[e].length;return n},tn=t=>{const n=new Uint8Array(Zt(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},nn=(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},en=nn,rn=(t,n)=>{for(;n>Lt;)nn(t,Ft|Lt&n),n=It(n/128);nn(t,Lt&n)},sn=(t,n)=>{const e=Pt(n);for(e&&(n=-n),nn(t,(n>63?Ft:0)|(e?Rt:0)|63&n),n=It(n/64);n>0;)nn(t,(n>Lt?Ft:0)|Lt&n),n=It(n/128)},on=new Uint8Array(3e4),un=on.length/3,cn=Yt&&Yt.encodeInto?(t,n)=>{if(n.length<un){const e=Yt.encodeInto(n,on).written||0;rn(t,e);for(let n=0;n<e;n++)nn(t,on[n])}else hn(t,Xt(n))}:(t,n)=>{const e=unescape(encodeURIComponent(n)),r=e.length;rn(t,r);for(let n=0;n<r;n++)nn(t,e.codePointAt(n))},an=(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(zt(2*e,s)),t.cbuf.set(n.subarray(i)),t.cpos=s)},hn=(t,n)=>{rn(t,n.byteLength),an(t,n)},ln=(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*zt(e,n)),t.cpos=0)})(t,n);const e=new DataView(t.cbuf.buffer,t.cpos,n);return t.cpos+=n,e},fn=new DataView(new ArrayBuffer(4)),dn=(t,n)=>{switch(typeof n){case"string":nn(t,119),cn(t,n);break;case"number":Nt(n)&&Ot(n)<=2147483647?(nn(t,125),sn(t,n)):(fn.setFloat32(0,e=n),fn.getFloat32(0)===e?(nn(t,124),((t,n)=>{ln(t,4).setFloat32(0,n,!1)})(t,n)):(nn(t,123),((t,n)=>{ln(t,8).setFloat64(0,n,!1)})(t,n)));break;case"bigint":nn(t,122),((t,n)=>{ln(t,8).setBigInt64(0,n,!1)})(t,n);break;case"object":if(null===n)nn(t,126);else if(Tt(n)){nn(t,117),rn(t,n.length);for(let e=0;e<n.length;e++)dn(t,n[e])}else if(n instanceof Uint8Array)nn(t,116),hn(t,n);else{nn(t,118);const e=Object.keys(n);rn(t,e.length);for(let r=0;r<e.length;r++){const i=e[r];cn(t,i),dn(t,n[i])}}break;case"boolean":nn(t,n?120:121);break;default:nn(t,127)}var e};class pn extends Gt{constructor(t){super(),this.w=t,this.s=null,this.count=0}write(t){this.s===t?this.count++:(this.count>0&&rn(this,this.count-1),this.count=1,this.w(this,t),this.s=t)}}const vn=t=>{t.count>0&&(sn(t.encoder,1===t.count?t.s:-t.s),t.count>1&&rn(t.encoder,t.count-2))};class wn{constructor(){this.encoder=new Gt,this.s=0,this.count=0}write(t){this.s===t?this.count++:(vn(this),this.count=1,this.s=t)}toUint8Array(){return vn(this),tn(this.encoder)}}const yn=t=>{t.count>0&&(sn(t.encoder,2*t.diff+(1===t.count?0:1)),t.count>1&&rn(t.encoder,t.count-2))};class gn{constructor(){this.encoder=new Gt,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(yn(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return yn(this),tn(this.encoder)}}class bn{constructor(){this.sarr=[],this.s="",this.lensE=new wn}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 Gt;return this.sarr.push(this.s),this.s="",cn(t,this.sarr.join("")),an(t,this.lensE.toUint8Array()),tn(t)}}const mn=t=>new Error(t),kn=()=>{throw mn("Method unimplemented")},An=()=>{throw mn("Unexpected case")},xn=mn("Unexpected end of array"),Mn=mn("Integer out of Range");let Sn=class{constructor(t){this.arr=t,this.pos=0}};const Cn=t=>new Sn(t),$n=t=>((t,n)=>{const e=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,n);return t.pos+=n,e})(t,Tn(t)),En=t=>t.arr[t.pos++],Tn=t=>{let n=0,e=1;const r=t.arr.length;for(;t.pos<r;){const r=t.arr[t.pos++];if(n+=(r&Lt)*e,e*=128,r<Ft)return n;if(n>Wt)throw Mn}throw xn},Un=t=>{let n=t.arr[t.pos++],e=63&n,r=64;const i=(n&Rt)>0?-1:1;if(!(n&Ft))return i*e;const s=t.arr.length;for(;t.pos<s;){if(n=t.arr[t.pos++],e+=(n&Lt)*r,r*=128,n<Ft)return i*e;if(e>Wt)throw Mn}throw xn},jn=qt?t=>qt.decode($n(t)):t=>{let n=Tn(t);if(0===n)return"";{let e=String.fromCodePoint(En(t));if(--n<100)for(;n--;)e+=String.fromCodePoint(En(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))}},In=(t,n)=>{const e=new DataView(t.arr.buffer,t.arr.byteOffset+t.pos,n);return t.pos+=n,e},On=[()=>{},()=>null,Un,t=>In(t,4).getFloat32(0,!1),t=>In(t,8).getFloat64(0,!1),t=>In(t,8).getBigInt64(0,!1),()=>!1,()=>!0,jn,t=>{const n=Tn(t),e={};for(let r=0;r<n;r++)e[jn(t)]=_n(t);return e},t=>{const n=Tn(t),e=[];for(let r=0;r<n;r++)e.push(_n(t));return e},$n],_n=t=>On[127-En(t)](t);class zn extends Sn{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?Tn(this)+1:-1),this.count--,this.s}}class Dn extends Sn{constructor(t){super(t),this.s=0,this.count=0}read(){if(0===this.count){this.s=Un(this);const t=Pt(this.s);this.count=1,t&&(this.s=-this.s,this.count=Tn(this)+2)}return this.count--,this.s}}class Pn extends Sn{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(0===this.count){const t=Un(this),n=1&t;this.diff=It(t/2),this.count=1,n&&(this.count=Tn(this)+2)}return this.s+=this.diff,this.count--,this.s}}class Rn{constructor(t){this.decoder=new Dn(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 Fn=crypto.getRandomValues.bind(crypto),Ln=()=>Fn(new Uint32Array(1))[0],Wn=[1e7]+-1e3+-4e3+-8e3+-1e11,Bn=()=>Wn.replace(/[018]/g,(t=>(t^Ln()&15>>t/4).toString(16))),Nn=Date.now,Kn=t=>new Promise(t);Promise.all.bind(Promise);let Hn=new class{constructor(){this.map=new Map}setItem(t,n){this.map.set(t,n)}getItem(t){return this.map.get(t)}},Vn=!0;try{"undefined"!=typeof localStorage&&localStorage&&(Hn=localStorage,Vn=!1)}catch(W){}const Qn=Hn,Yn=t=>Vn||addEventListener("storage",t),Xn=t=>Vn||removeEventListener("storage",t),qn=Symbol("Equality"),Gn=(t,n)=>t===n||!!t?.[qn]?.(n)||!1,Jn=Object.assign,Zn=Object.keys,te=(t,n)=>{const e=[];for(const r in t)e.push(n(t[r],r));return e},ne=t=>Zn(t).length,ee=(t,n)=>{for(const e in t)if(!n(t[e],e))return!1;return!0},re=(t,n)=>Object.prototype.hasOwnProperty.call(t,n),ie=Object.freeze,se=t=>{for(const n in t){const e=t[n];"object"!=typeof e&&"function"!=typeof e||se(t[n])}return ie(t)},oe=(t,n,e=0)=>{try{for(;e<t.length;e++)t[e](...n)}finally{e<t.length&&oe(t,n,e+1)}},ue=t=>t,ce=(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[qn])return t[qn](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)||!ce(t.get(e),n.get(e)))return!1;break;case void 0:case Object:if(ne(t)!==ne(n))return!1;for(const e in t)if(!re(t,e)||!ce(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(!ce(t[e],n[e]))return!1;break;default:return!1}return!0},ae="undefined"!=typeof process&&process.release&&/node|io\.js/.test(process.release.name)&&"[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),he="undefined"!=typeof window&&"undefined"!=typeof document&&!ae;let le;const fe=t=>(()=>{if(void 0===le)if(ae){le=mt();const t=process.argv;let n=null;for(let e=0;e<t.length;e++){const r=t[e];"-"===r[0]?(null!==n&&le.set(n,""),n=r):null!==n&&(le.set(n,r),n=null)}null!==n&&le.set(n,"")}else"object"==typeof location?(le=mt(),(location.search||"?").slice(1).split("&").forEach((t=>{if(0!==t.length){const[n,e]=t.split("=");le.set(`--${Qt(n,"-")}`,e),le.set(`-${Qt(n,"-")}`,e)}}))):le=mt();return le})().has(t),de=t=>{return void 0===(n=ae?process.env[t.toUpperCase().replaceAll("-","_")]:Qn.getItem(t))?null:n;var n},pe=t=>fe("--"+t)||null!==de(t),ve=pe("production");var we;const ye=ae&&(we=process.env.FORCE_COLOR,["true","1","2"].includes(we))||!fe("--no-colors")&&!pe("no-color")&&(!ae||process.stdout.isTTY)&&(!ae||fe("--color")||null!==de("COLORTERM")||(de("TERM")||"").includes("color")),ge=t=>new Uint8Array(t),be=t=>new Uint8Array(t),me=he?t=>{let n="";for(let e=0;e<t.byteLength;e++)n+=Kt(t[e]);return btoa(n)}:t=>Buffer.from(t.buffer,t.byteOffset,t.byteLength).toString("base64"),ke=he?t=>{const n=atob(t),e=ge(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 Ae{constructor(t,n){this.left=t,this.right=n}}const xe=(t,n)=>new Ae(t,n),Me=t=>t.next()>=.5,Se=(t,n,e)=>It(t.next()*(e+1-n)+n),Ce=(t,n,e)=>It(t.next()*(e+1-n)+n),$e=(t,n,e)=>Ce(t,n,e),Ee=t=>Kt($e(t,97,122)),Te=(t,n)=>n[$e(t,0,n.length-1)],Ue=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 Ie=(t,n)=>t===n||null!=t&&null!=n&&t.constructor===n.constructor&&(t[qn]?Gn(t,n):Tt(t)?$t(t,(t=>Et(n,(n=>Ie(t,n))))):!!(t=>"object"==typeof t)(t)&&ee(t,((t,e)=>Ie(t,n[e]))));class Oe{static _dilutes=!1;extends(t){let[n,e]=[this.shape,t.shape];return this.constructor._dilutes&&([e,n]=[n,e]),Ie(n,e)}equals(t){return this.constructor===t.constructor&&ce(this.shape,t.shape)}[Ue](){return!0}[qn](t){return this.equals(t)}validate(t){return this.check(t)}check(t,n){kn()}get nullable(){return cr(this,xr)}get optional(){return new Ke(this)}cast(t){return $r(t,this),t}expect(t){return $r(t,this),t}}class _e extends Oe{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 ze=(t,n=null)=>new _e(t,n);ze(_e);class De extends Oe{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 Pe=t=>new De(t);ze(De);class Re extends Oe{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 Fe=(...t)=>new Re(t),Le=ze(Re),We=RegExp.escape||(t=>t.replace(/[().|&,$^[\]]/g,(t=>"\\"+t))),Be=t=>gr.check(t)?[We(t)]:Le.check(t)?t.shape.map((t=>t+"")):yr.check(t)?["[+-]?\\d+.?\\d*"]:br.check(t)?[".*"]:ar.check(t)?t.shape.map(Be).flat(1):void An();ze(class extends Oe{constructor(t){super(),this.shape=t,this._r=new RegExp("^"+t.map(Be).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 Ne=Symbol("optional");class Ke extends Oe{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[Ne](){return!0}}const He=ze(Ke);ze(class extends Oe{check(t,n){return n?.extend(null,"never",typeof t),!1}});class Ve extends Oe{constructor(t,n=!1){super(),this.shape=t,this._isPartial=n}static _dilutes=!0;get partial(){return new Ve(this.shape,!0)}check(t,n){return null==t?(n?.extend(null,"object","null"),!1):ee(this.shape,((e,r)=>{const i=this._isPartial&&!re(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=ze(Ve),Ye=Pe((t=>null!=t&&(t.constructor===Object||null==t.constructor)));class Xe extends Oe{constructor(t,n){super(),this.shape={keys:t,values:n}}check(t,n){return null!=t&&ee(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 qe=(t,n)=>new Xe(t,n),Ge=ze(Xe);class Je extends Oe{constructor(t){super(),this.shape=t}check(t,n){return null!=t&&ee(this.shape,((e,r)=>{const i=e.check(t[r],n);return!i&&n?.extend(r.toString(),"Tuple",typeof e),i}))}}ze(Je);class Ze extends Oe{constructor(t){super(),this.shape=1===t.length?t[0]:new ur(t)}check(t,n){const e=Tt(t)&&$t(t,(t=>this.shape.check(t)));return!e&&n?.extend(null,"Array",""),e}}const tr=(...t)=>new Ze(t),nr=ze(Ze),er=Pe((t=>Tt(t)));class rr extends Oe{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}}ze(rr);const ir=((t,n=null)=>new rr(Oe,n))(),sr=ze(class extends Oe{constructor(t){super(),this.len=t.length-1,this.args=((...t)=>new Je(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}}),or=Pe((t=>"function"==typeof t));ze(class extends Oe{constructor(t){super(),this.shape=t}check(t,n){const e=$t(this.shape,(e=>e.check(t,n)));return!e&&n?.extend(null,"Intersectinon",typeof t),e}},(t=>t.shape.length>0));class ur extends Oe{static _dilutes=!0;constructor(t){super(),this.shape=t}check(t,n){const e=Et(this.shape,(e=>e.check(t,n)));return n?.extend(null,"Union",typeof t),e}}const cr=(...t)=>t.findIndex((t=>ar.check(t)))>=0?cr(...t.map((t=>Cr(t))).map((t=>ar.check(t)?t.shape:[t])).flat(1)):1===t.length?t[0]:new ur(t),ar=ze(ur),hr=()=>!0,lr=Pe(hr),fr=ze(De,(t=>t.shape===hr)),dr=Pe((t=>"bigint"==typeof t)),pr=Pe((t=>t===dr)),vr=Pe((t=>"symbol"==typeof t));Pe((t=>t===vr));const wr=Pe((t=>"number"==typeof t)),yr=Pe((t=>t===wr)),gr=Pe((t=>"string"==typeof t)),br=Pe((t=>t===gr)),mr=Pe((t=>"boolean"==typeof t)),kr=Pe((t=>t===mr)),Ar=Fe(void 0);ze(Re,(t=>1===t.shape.length&&void 0===t.shape[0])),Fe(void 0);const xr=Fe(null),Mr=ze(Re,(t=>1===t.shape.length&&null===t.shape[0]));ze(Uint8Array),ze(_e,(t=>t.shape===Uint8Array));const Sr=cr(wr,gr,xr,Ar,dr,mr,vr);(()=>{const t=tr(lr),n=qe(gr,lr),e=cr(wr,gr,xr,mr,t,n);t.shape=e,n.shape.values=e})();const Cr=t=>{if(ir.check(t))return t;if(Ye.check(t)){const n={};for(const e in t)n[e]=Cr(t[e]);return new Ve(n)}return er.check(t)?cr(...t.map(Cr)):Sr.check(t)?Fe(t):or.check(t)?ze(t):void An()},$r=ve?()=>{}:(t,n)=>{const e=new je;if(!n.check(t,e))throw mn(`Expected value to be of type ${n.constructor.name}.\n${e.toString()}`)};const Er=(Tr=lr,new class{constructor(t){this.patterns=[],this.$state=t}if(t,n){return this.patterns.push({if:Cr(t),h:n}),this}else(t){return this.if(lr,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 mn("Unhandled pattern")}}}(Tr)).if(yr,((t,n)=>Se(n,Bt,Wt))).if(br,((t,n)=>((t,n=0,e=20)=>{const r=$e(t,n,e);let i="";for(let n=0;n<r;n++)i+=Ee(t);return i})(n))).if(kr,((t,n)=>Me(n))).if(pr,((t,n)=>BigInt(Se(n,Bt,Wt)))).if(ar,((t,n)=>Ur(n,Te(n,t.shape)))).if(Qe,((t,n)=>{const e={};for(const r in t.shape){let i=t.shape[r];if(He.check(i)){if(Me(n))continue;i=i.shape}e[r]=Er(i,n)}return e})).if(nr,((t,n)=>{const e=[],r=Ce(n,0,42);for(let i=0;i<r;i++)e.push(Ur(n,t.shape));return e})).if(Le,((t,n)=>Te(n,t.shape))).if(Mr,(()=>null)).if(sr,((t,n)=>{const e=Ur(n,t.res);return()=>e})).if(fr,((t,n)=>Ur(n,Te(n,[wr,gr,xr,Ar,dr,mr,tr(wr),qe(cr("a","b","c"),wr)])))).if(Ge,((t,n)=>{const e={},r=Se(n,0,3);for(let i=0;i<r;i++){const r=Ur(n,t.shape.keys),i=Ur(n,t.shape.values);e[r]=i}return e})).done();var Tr;const Ur=(t,n)=>Er(Cr(n),t),jr="undefined"!=typeof document?document:{};Pe((t=>t.nodeType===zr)),"undefined"!=typeof DOMParser&&new DOMParser,Pe((t=>t.nodeType===Ir)),Pe((t=>t.nodeType===Or));const Ir=jr.ELEMENT_NODE,Or=jr.TEXT_NODE,_r=jr.DOCUMENT_NODE,zr=jr.DOCUMENT_FRAGMENT_NODE;Pe((t=>t.nodeType===_r));const Dr=Symbol,Pr=Dr(),Rr=Dr(),Fr=Dr(),Lr=Dr(),Wr=Dr(),Br=Dr(),Nr=Dr(),Kr=Dr(),Hr=Dr(),Vr={[Pr]:xe("font-weight","bold"),[Rr]:xe("font-weight","normal"),[Fr]:xe("color","blue"),[Wr]:xe("color","green"),[Lr]:xe("color","grey"),[Br]:xe("color","red"),[Nr]:xe("color","purple"),[Kr]:xe("color","orange"),[Hr]:xe("color","black")},Qr=ye?t=>{1===t.length&&t[0]?.constructor===Function&&(t=t[0]());const n=[],e=[],r=mt();let i=[],s=0;for(;s<t.length;s++){const i=t[s],o=Vr[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(Kr),Xr.forEach((n=>n.print(t)))},Xr=xt(),qr=t=>({[Symbol.iterator](){return this},next:t}),Gr=(t,n)=>qr((()=>{const{done:e,value:r}=t.next();return{done:e,value:e?void 0:n(r)}}));class Jr{constructor(t,n){this.clock=t,this.len=n}}class Zr{constructor(){this.clients=new Map}}const ti=(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])Vi(t,i,o.clock,o.len,e)}})),ni=(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=It((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)},ei=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=zt(r.len,i.clock+i.len-r.clock):(e<n&&(t[e]=i),e++)}t.length=e}))},ri=t=>{const n=new Zr;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++)St(s,t[n].clients.get(i)||[]);n.clients.set(i,s)}}));return ei(n),n},ii=(t,n,e,r)=>{At(t.clients,n,(()=>[])).push(new Jr(e,r))},si=(t,n)=>{rn(t.restEncoder,n.clients.size),Ct(n.clients.entries()).sort(((t,n)=>n[0]-t[0])).forEach((([n,e])=>{t.resetDsCurVal(),rn(t.restEncoder,n);const r=e.length;rn(t.restEncoder,r);for(let n=0;n<r;n++){const r=e[n];t.writeDsClock(r.clock),t.writeDsLen(r.len)}}))},oi=t=>{const n=new Zr,e=Tn(t.restDecoder);for(let r=0;r<e;r++){t.resetDsCurVal();const e=Tn(t.restDecoder),r=Tn(t.restDecoder);if(r>0){const i=At(n.clients,e,(()=>[]));for(let n=0;n<r;n++)i.push(new Jr(t.readDsClock(),t.readDsLen()))}}return n},ui=(t,n,e)=>{const r=new Zr,i=Tn(t.restDecoder);for(let s=0;s<i;s++){t.resetDsCurVal();const i=Tn(t.restDecoder),s=Tn(t.restDecoder),o=e.clients.get(i)||[],u=Fi(e,i);for(let e=0;e<s;e++){const e=t.readDsClock(),s=e+t.readDsLen();if(e<u){u<s&&ii(r,i,u,s-u);let t=Wi(o,e),c=o[t];for(!c.deleted&&c.id.clock<e&&(o.splice(t+1,0,Do(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,Do(n,c,s-c.id.clock)),c.delete(n))}else ii(r,i,e,s-e)}}if(r.clients.size>0){const t=new yi;return rn(t.restEncoder,0),si(t,r),t.toUint8Array()}return null},ci=Ln;class ai extends Ut{constructor({guid:t=Bn(),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=ci(),this.guid=t,this.collectionid=n,this.share=new Map,this.store=new Pi,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=Kn((t=>{this.on("load",(()=>{this.isLoaded=!0,t(this)}))}));const u=()=>Kn((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||Ji(t.parent.doc,(t=>{t.subdocsLoaded.add(this)}),null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(Ct(this.subdocs).map((t=>t.guid)))}transact(t,n=null){return Ji(this,t,n)}get(t,n=xs){const e=At(this.share,t,(()=>{const t=new n;return t._integrate(this,null),t})),r=e.constructor;if(n!==xs&&r!==n){if(r===xs){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,Ws)}getText(t=""){return this.get(t,so)}getMap(t=""){return this.get(t,Ns)}getXmlElement(t=""){return this.get(t,co)}getXmlFragment(t=""){return this.get(t,uo)}toJSON(){const t={};return this.share.forEach(((n,e)=>{t[e]=n.toJSON()})),t}destroy(){this.isDestroyed=!0,Ct(this.subdocs).forEach((t=>t.destroy()));const t=this._item;if(null!==t){this._item=null;const n=t.content;n.doc=new ai({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=t,Ji(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 hi{constructor(t){this.restDecoder=t}resetDsCurVal(){}readDsClock(){return Tn(this.restDecoder)}readDsLen(){return Tn(this.restDecoder)}}class li extends hi{readLeftID(){return Oi(Tn(this.restDecoder),Tn(this.restDecoder))}readRightID(){return Oi(Tn(this.restDecoder),Tn(this.restDecoder))}readClient(){return Tn(this.restDecoder)}readInfo(){return En(this.restDecoder)}readString(){return jn(this.restDecoder)}readParentInfo(){return 1===Tn(this.restDecoder)}readTypeRef(){return Tn(this.restDecoder)}readLen(){return Tn(this.restDecoder)}readAny(){return _n(this.restDecoder)}readBuf(){return(t=>{const n=ge(t.byteLength);return n.set(t),n})($n(this.restDecoder))}readJSON(){return JSON.parse(jn(this.restDecoder))}readKey(){return jn(this.restDecoder)}}class fi{constructor(t){this.dsCurrVal=0,this.restDecoder=t}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=Tn(this.restDecoder),this.dsCurrVal}readDsLen(){const t=Tn(this.restDecoder)+1;return this.dsCurrVal+=t,t}}class di extends fi{constructor(t){super(t),this.keys=[],Tn(t),this.keyClockDecoder=new Pn($n(t)),this.clientDecoder=new Dn($n(t)),this.leftClockDecoder=new Pn($n(t)),this.rightClockDecoder=new Pn($n(t)),this.infoDecoder=new zn($n(t),En),this.stringDecoder=new Rn($n(t)),this.parentInfoDecoder=new zn($n(t),En),this.typeRefDecoder=new Dn($n(t)),this.lenDecoder=new Dn($n(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 $n(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 pi{constructor(){this.restEncoder=Jt()}toUint8Array(){return tn(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){rn(this.restEncoder,t)}writeDsLen(t){rn(this.restEncoder,t)}}class vi extends pi{writeLeftID(t){rn(this.restEncoder,t.client),rn(this.restEncoder,t.clock)}writeRightID(t){rn(this.restEncoder,t.client),rn(this.restEncoder,t.clock)}writeClient(t){rn(this.restEncoder,t)}writeInfo(t){en(this.restEncoder,t)}writeString(t){cn(this.restEncoder,t)}writeParentInfo(t){rn(this.restEncoder,t?1:0)}writeTypeRef(t){rn(this.restEncoder,t)}writeLen(t){rn(this.restEncoder,t)}writeAny(t){dn(this.restEncoder,t)}writeBuf(t){hn(this.restEncoder,t)}writeJSON(t){cn(this.restEncoder,JSON.stringify(t))}writeKey(t){cn(this.restEncoder,t)}}class wi{constructor(){this.restEncoder=Jt(),this.dsCurrVal=0}toUint8Array(){return tn(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){const n=t-this.dsCurrVal;this.dsCurrVal=t,rn(this.restEncoder,n)}writeDsLen(t){0===t&&An(),rn(this.restEncoder,t-1),this.dsCurrVal+=t}}class yi extends wi{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new gn,this.clientEncoder=new wn,this.leftClockEncoder=new gn,this.rightClockEncoder=new gn,this.infoEncoder=new pn(en),this.stringEncoder=new bn,this.parentInfoEncoder=new pn(en),this.typeRefEncoder=new wn,this.lenEncoder=new wn}toUint8Array(){const t=Jt();return rn(t,0),hn(t,this.keyClockEncoder.toUint8Array()),hn(t,this.clientEncoder.toUint8Array()),hn(t,this.leftClockEncoder.toUint8Array()),hn(t,this.rightClockEncoder.toUint8Array()),hn(t,tn(this.infoEncoder)),hn(t,this.stringEncoder.toUint8Array()),hn(t,tn(this.parentInfoEncoder)),hn(t,this.typeRefEncoder.toUint8Array()),hn(t,this.lenEncoder.toUint8Array()),an(t,tn(this.restEncoder)),tn(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){dn(this.restEncoder,t)}writeBuf(t){hn(this.restEncoder,t)}writeJSON(t){dn(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 gi=(t,n,e)=>{const r=new Map;e.forEach(((t,e)=>{Fi(n,e)>t&&r.set(e,t)})),Ri(n).forEach(((t,n)=>{e.has(n)||r.set(n,0)})),rn(t.restEncoder,r.size),Ct(r.entries()).sort(((t,n)=>n[0]-t[0])).forEach((([e,r])=>{((t,n,e,r)=>{r=zt(r,n[0].id.clock);const i=Wi(n,r);rn(t.restEncoder,n.length-i),t.writeClient(e),rn(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)}))},bi=(t,n,e,r=di)=>{const i=Cn(n);((t,n,e,r=new di(t))=>{Ji(n,(t=>{t.local=!1;let n=!1;const e=t.doc,i=e.store,s=((t,n)=>{const e=mt(),r=Tn(t.restDecoder);for(let i=0;i<r;i++){const r=Tn(t.restDecoder),i=new Array(r),s=t.readClient();let o=Tn(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 po(Oi(s,o),n),o+=n;break}case 10:{const n=Tn(t.restDecoder);i[e]=new Bo(Oi(s,o),n),o+=n;break}default:{const u=!(192&r),c=new Fo(Oi(s,o),null,(r&Ft)===Ft?t.readLeftID():null,null,(r&Rt)===Rt?t.readRightID():null,u?t.readParentInfo()?n.get(t.readString()):t.readLeftID():null,!u||32&~r?null:t.readString(),Lo(t,r));i[e]=c,o+=c.length}}}}return e})(r,e),o=((t,n,e)=>{const r=[];let i=Ct(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 Pi,c=new Map,a=(t,n)=>{const e=c.get(t);(null==e||e>n)&&c.set(t,n)};let h=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(h.constructor!==Bo){const i=At(l,h.id.client,(()=>Fi(n,h.id.client)))-h.id.clock;if(i<0)r.push(h),a(h.id.client,h.id.clock-1),f();else{const s=h.getMissing(t,n);if(null!==s){r.push(h);const t=e.get(s)||{refs:[],i:0};if(t.refs.length!==t.i){h=t.refs[t.i++];continue}a(s,Fi(n,s)),f()}else(0===i||i<h.length)&&(h.integrate(t,i),l.set(h.id.client,h.id.clock+h.length))}}if(r.length>0)h=r.pop();else if(null!==o&&o.i<o.refs.length)h=o.refs[o.i++];else{if(o=s(),null===o)break;h=o.refs[o.i++]}}if(u.clients.size>0){const t=new yi;return gi(t,u,new Map),rn(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<Fi(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=us([u.update,o.update])}}else i.pendingStructs=o;const c=ui(r,t,i);if(i.pendingDs){const n=new di(Cn(i.pendingDs));Tn(n.restDecoder);const e=ui(n,t,i);i.pendingDs=c&&e?us([c,e]):c||e}else i.pendingDs=c;if(n){const n=i.pendingStructs.update;i.pendingStructs=null,bi(t.doc,n)}}),e,!1)})(i,t,e,new r(i))},mi=(t,n,e)=>bi(t,n,e,li),ki=(t,n=new Uint8Array([0]),e=new yi)=>{((t,n,e=new Map)=>{gi(t,n.store,e),si(t,(t=>{const n=new Zr;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 Jr(i,s))}}r.length>0&&n.clients.set(e,r)})),n})(n.store))})(e,t,xi(n));const r=[e.toUint8Array()];if(t.store.pendingDs&&r.push(t.store.pendingDs),t.store.pendingStructs&&r.push(cs(t.store.pendingStructs.update,n)),r.length>1){if(e.constructor===vi)return ss(r.map(((t,n)=>0===n?t:fs(t))));if(e.constructor===yi)return us(r)}return r[0]},Ai=(t,n)=>ki(t,n,new vi),xi=t=>(t=>{const n=new Map,e=Tn(t.restDecoder);for(let r=0;r<e;r++){const e=Tn(t.restDecoder),r=Tn(t.restDecoder);n.set(e,r)}return n})(new hi(Cn(t))),Mi=(t,n)=>(rn(t.restEncoder,n.size),Ct(n.entries()).sort(((t,n)=>n[0]-t[0])).forEach((([n,e])=>{rn(t.restEncoder,n),rn(t.restEncoder,e)})),t),Si=t=>((t,n=new wi)=>(t instanceof Map?Mi(n,t):((t,n)=>{Mi(t,Ri(n.store))})(n,t),n.toUint8Array()))(t,new pi);class Ci{constructor(){this.l=[]}}const $i=()=>new Ci,Ei=(t,n)=>t.l.push(n),Ti=(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.")},Ui=(t,n,e)=>oe(t.l,[n,e]);class ji{constructor(t,n){this.client=t,this.clock=n}}const Ii=(t,n)=>t===n||null!==t&&null!==n&&t.client===n.client&&t.clock===n.clock,Oi=(t,n)=>new ji(t,n),_i=(t,n)=>{for(;null!==n;){if(n.parent===t)return!0;n=n.parent._item}return!1},zi=(t,n)=>void 0===n?!t.deleted:n.sv.has(t.id.client)&&(n.sv.get(t.id.client)||0)>t.id.clock&&!ni(n.ds,t.id),Di=(t,n)=>{const e=At(t.meta,Di,xt),r=t.doc.store;e.has(n)||(n.sv.forEach(((n,e)=>{n<Fi(r,e)&&Ki(t,Oi(e,n))})),ti(t,n.ds,(()=>{})),e.add(n))};class Pi{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const Ri=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},Fi=(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},Li=(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 An()}e.push(n)},Wi=(t,n)=>{let e=0,r=t.length-1,i=t[r],s=i.id.clock;if(s===n)return r;let o=It(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=It((e+r)/2)}throw An()},Bi=(t,n)=>{const e=t.clients.get(n.client);return e[Wi(e,n.clock)]},Ni=(t,n,e)=>{const r=Wi(n,e),i=n[r];return i.id.clock<e&&i instanceof Fo?(n.splice(r+1,0,Do(t,i,e-i.id.clock)),r+1):r},Ki=(t,n)=>{const e=t.doc.store.clients.get(n.client);return e[Ni(t,e,n.clock)]},Hi=(t,n,e)=>{const r=n.clients.get(e.client),i=Wi(r,e.clock),s=r[i];return e.clock!==s.id.clock+s.length-1&&s.constructor!==po&&r.splice(i+1,0,Do(t,s,e.clock-s.id.clock+1)),s},Vi=(t,n,e,r,i)=>{if(0===r)return;const s=e+r;let o,u=Ni(t,n,e);do{o=n[u++],s<o.id.clock+o.length&&Ni(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 Zr,this.beforeState=Ri(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)||(ei(n.deleteSet),((t,n)=>{gi(t,n.doc.store,n.beforeState)})(t,n),si(t,n.deleteSet),0)),Xi=(t,n,e)=>{const r=n._item;(null===r||r.id.clock<(t.beforeState.get(r.id.client)||0)&&!r.deleted)&&At(t.changed,n,xt).add(e)},qi=(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 Fo&&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},Gi=(t,n)=>{if(n<t.length){const e=t[n],r=e.doc,i=r.store,s=e.deleteSet,o=e._mergeStructs;try{ei(s),e.afterState=Ri(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(((n,r)=>{r._dEH.l.length>0&&(null===r._item||!r._item.deleted)&&((n=n.filter((t=>null===t.target._item||!t.target._item.deleted))).forEach((t=>{t.currentTarget=r,t._path=null})),n.sort(((t,n)=>t.path.length-n.path.length)),t.push((()=>{Ui(r._dEH,n,e)})))})),t.push((()=>r.emit("afterTransaction",[e,r]))),t.push((()=>{e._needFormattingCleanup&&eo(e)}))})),oe(t,[])}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=Wi(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 Fo&&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+Wi(r,e.clock+e.len-1)),n=r[t];t>0&&n.id.clock>=e.clock;n=r[t])t-=1+qi(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=zt(Wi(t,r),1);for(let n=t.length-1;n>=e;)n-=1+qi(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=Wi(r,e);s+1<r.length&&qi(r,s+1)>1||s>0&&qi(r,s)}if(e.local||e.afterState.get(r.clientID)===e.beforeState.get(r.clientID)||(((...t)=>{console.log(...Qr(t)),Xr.forEach((n=>n.print(t)))})(Kr,Pr,"[yjs] ",Rr,Br,"Changed the client-id because another client seems to be using it."),r.clientID=ci()),r.emit("afterTransactionCleanup",[e,r]),r._observers.has("update")){const t=new vi;Yi(t,e)&&r.emit("update",[t.toUint8Array(),e.origin,r,e])}if(r._observers.has("updateV2")){const t=new yi;Yi(t,e)&&r.emit("updateV2",[t.toUint8Array(),e.origin,r,e])}const{subdocsAdded:u,subdocsLoaded:c,subdocsRemoved:a}=e;(u.size>0||a.size>0||c.size>0)&&(u.forEach((t=>{t.clientID=r.clientID,null==t.collectionid&&(t.collectionid=r.collectionid),r.subdocs.add(t)})),a.forEach((t=>r.subdocs.delete(t))),r.emit("subdocs",[{loaded:c,added:u,removed:a},r,e]),a.forEach((t=>t.destroy()))),t.length<=n+1?(r._transactionCleanups=[],r.emit("afterAllTransactions",[r,t])):Gi(t,n+1)}}},Ji=(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&&Gi(i,0)}}return o};class Zi{constructor(t,n){this.insertions=n,this.deletions=t,this.meta=new Map}}const ts=(t,n,e)=>{ti(t,e.deletions,(e=>{e instanceof Fo&&n.scope.some((n=>n===t.doc||_i(n,e)))&&zo(e,!1)}))},ns=(t,n,e)=>{let r=null;const i=t.doc,s=t.scope;Ji(i,(e=>{for(;n.length>0&&null===t.currStackItem;){const r=i.store,o=n.pop(),u=new Set,c=[];let a=!1;ti(e,o.insertions,(t=>{if(t instanceof Fo){if(null!==t.redone){let{item:n,diff:i}=_o(r,t.id);i>0&&(n=Ki(e,Oi(n.id.client,n.id.clock+i))),t=n}!t.deleted&&s.some((n=>n===e.doc||_i(n,t)))&&c.push(t)}})),ti(e,o.deletions,(t=>{t instanceof Fo&&s.some((n=>n===e.doc||_i(n,t)))&&!ni(o.insertions,t.id)&&u.add(t)})),u.forEach((n=>{a=null!==Ro(e,n,u,o.insertions,t.ignoreRemoteMapChanges,t)||a}));for(let n=c.length-1;n>=0;n--){const r=c[n];t.deleteFilter(r)&&(r.delete(e),a=!0)}t.currStackItem=a?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 es extends Ut{constructor(t,{captureTimeout:n=500,captureTransaction:e=()=>!0,deleteFilter:r=()=>!0,trackedOrigins:i=new Set([null]),ignoreRemoteMapChanges:s=!1,doc:o=(Tt(t)?t[0].doc:t instanceof ai?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 Zr;t.afterState.forEach(((n,e)=>{const r=t.beforeState.get(e)||0,s=n-r;s>0&&ii(i,e,r,s)}));const s=Nn();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=ri([n.deletions,t.deleteSet]),n.insertions=ri([n.insertions,i])}else r.push(new Zi(t.deleteSet,i)),o=!0;n||e||(this.lastChange=s),ti(t,t.deleteSet,(n=>{n instanceof Fo&&this.scope.some((e=>e===t.doc||_i(e,n)))&&zo(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=Tt(t)?t:[t]).forEach((t=>{n.has(t)||(n.add(t),(t instanceof xs?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=>ts(e,this,t))),this.undoStack=[]),n&&(this.redoStack.forEach((t=>ts(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=ns(this,this.undoStack,"undo")}finally{this.undoing=!1}return t}redo(){let t;this.redoing=!0;try{t=ns(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 rs{constructor(t,n){this.gen=function*(t){const n=Tn(t.restDecoder);for(let e=0;e<n;e++){const n=Tn(t.restDecoder),e=t.readClient();let r=Tn(t.restDecoder);for(let i=0;i<n;i++){const n=t.readInfo();if(10===n){const n=Tn(t.restDecoder);yield new Bo(Oi(e,r),n),r+=n}else if(31&n){const i=!(192&n),s=new Fo(Oi(e,r),null,(n&Ft)===Ft?t.readLeftID():null,null,(n&Rt)===Rt?t.readRightID():null,i?t.readParentInfo()?t.readString():t.readLeftID():null,!i||32&~n?null:t.readString(),Lo(t,n));yield s,r+=s.length}else{const n=t.readLen();yield new po(Oi(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===Bo);return this.curr}}class is{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}}const ss=t=>us(t,li,vi),os=(t,n)=>{if(t.constructor===po){const{client:e,clock:r}=t.id;return new po(Oi(e,r+n),t.length-n)}if(t.constructor===Bo){const{client:e,clock:r}=t.id;return new Bo(Oi(e,r+n),t.length-n)}{const e=t,{client:r,clock:i}=e.id;return new Fo(Oi(r,i+n),null,Oi(r,i+n-1),null,e.rightOrigin,e.parent,e.parentSub,e.content.splice(n))}},us=(t,n=di,e=yi)=>{if(1===t.length)return t[0];const r=t.map((t=>new n(Cn(t))));let i=r.map((t=>new rs(t,!0))),s=null;const o=new e,u=new is(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===Bo?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)hs(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===Bo)s.struct.length=e.id.clock+e.length-s.struct.id.clock;else{hs(u,s.struct,s.offset);const t=e.id.clock-s.struct.id.clock-s.struct.length;s={struct:new Bo(Oi(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===Bo?s.struct.length-=n:e=os(e,n)),s.struct.mergeWith(e)||(hs(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!==Bo;e=t.next())hs(u,s.struct,s.offset),s={struct:e,offset:0}}null!==s&&(hs(u,s.struct,s.offset),s=null),ls(u);const c=r.map((t=>oi(t))),a=ri(c);return si(o,a),o.toUint8Array()},cs=(t,n,e=di,r=yi)=>{const i=xi(n),s=new r,o=new is(s),u=new e(Cn(t)),c=new rs(u,!1);for(;c.curr;){const t=c.curr,n=t.id.client,e=i.get(n)||0;if(c.curr.constructor!==Bo)if(t.id.clock+t.length>e)for(hs(o,t,zt(e-t.id.clock,0)),c.next();c.curr&&c.curr.id.client===n;)hs(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()}ls(o);const a=oi(u);return si(s,a),s.toUint8Array()},as=t=>{t.written>0&&(t.clientStructs.push({written:t.written,restEncoder:tn(t.encoder.restEncoder)}),t.encoder.restEncoder=Jt(),t.written=0)},hs=(t,n,e)=>{t.written>0&&t.currClient!==n.id.client&&as(t),0===t.written&&(t.currClient=n.id.client,t.encoder.writeClient(n.id.client),rn(t.encoder.restEncoder,n.id.clock+e)),n.write(t.encoder,e),t.written++},ls=t=>{as(t);const n=t.encoder.restEncoder;rn(n,t.clientStructs.length);for(let e=0;e<t.clientStructs.length;e++){const r=t.clientStructs[e];rn(n,r.written),an(n,r.restEncoder)}},fs=t=>((t,n,e,r)=>{const i=new di(Cn(t)),s=new rs(i,!1),o=new r,u=new is(o);for(let t=s.curr;null!==t;t=s.next())hs(u,n(t),0);ls(u);const c=oi(i);return si(o,c),o.toUint8Array()})(t,ue,0,vi),ds="You must not compute changes after the event-handler fired.";class ps{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=vs(this.currentTarget,this.target))}deletes(t){return ni(this.transaction.deleteSet,t.id)}get keys(){if(null===this._keys){if(0===this.transaction.doc._transactionCleanups.length)throw mn(ds);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=Mt(t.content.getContent())}else null!==t&&this.deletes(t)?(i="update",s=Mt(t.content.getContent())):(i="add",s=void 0)}else{if(!this.deletes(r))return;i="delete",s=Mt(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 mn(ds);const n=this.target,e=xt(),r=xt(),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 vs=(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},ws=()=>{Yr("Invalid access: Add Yjs type to a document before reading data.")};let ys=0;class gs{constructor(t,n){t.marker=!0,this.p=t,this.index=n,this.timestamp=ys++}}const bs=(t,n,e)=>{t.p.marker=!1,t.p=n,n.marker=!0,t.index=e,t.timestamp=ys++},ms=(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)=>Ot(n-t.index)<Ot(n-e.index)?t:e));let r=t._start,i=0;for(null!==e&&(r=e.p,i=e.index,(t=>{t.timestamp=ys++})(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&&Ot(e.index-i)<r.parent.length/80?(bs(e,r,i),e):((t,n,e)=>{if(t.length>=80){const r=t.reduce(((t,n)=>t.timestamp<n.timestamp?t:n));return bs(r,n,e),r}{const r=new gs(n,e);return t.push(r),r}})(t._searchMarker,r,i)},ks=(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=zt(n,i.index+e))}},As=(t,n,e)=>{const r=t,i=n.changedParentTypes;for(;At(i,t,(()=>[])).push(e),null!==t._item;)t=t._item.parent;Ui(r._eH,e,n)};class xs{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=$i(),this._dEH=$i(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,n){this.doc=t,this._item=n}_copy(){throw kn()}clone(){throw kn()}_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){Ei(this._eH,t)}observeDeep(t){Ei(this._dEH,t)}unobserve(t){Ti(this._eH,t)}unobserveDeep(t){Ti(this._dEH,t)}toJSON(){}}const Ms=(t,n,e)=>{t.doc??ws(),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},Ss=t=>{t.doc??ws();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},Cs=(t,n)=>{let e=0,r=t._start;for(t.doc??ws();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}},$s=(t,n)=>{const e=[];return Cs(t,((r,i)=>{e.push(n(r,i,t))})),e},Es=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}}}},Ts=(t,n)=>{t.doc??ws();const e=ms(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}},Us=(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 a=[];const h=()=>{a.length>0&&(i=new Fo(Oi(o,Fi(u,o)),i,i&&i.lastId,c,c&&c.id,n,null,new xo(a)),i.integrate(t,0),a=[])};r.forEach((e=>{if(null===e)a.push(e);else switch(e.constructor){case Number:case Object:case Boolean:case Array:case String:a.push(e);break;default:switch(h(),e.constructor){case Uint8Array:case ArrayBuffer:i=new Fo(Oi(o,Fi(u,o)),i,i&&i.lastId,c,c&&c.id,n,null,new vo(new Uint8Array(e))),i.integrate(t,0);break;case ai:i=new Fo(Oi(o,Fi(u,o)),i,i&&i.lastId,c,c&&c.id,n,null,new go(e)),i.integrate(t,0);break;default:if(!(e instanceof xs))throw new Error("Unexpected content type in insert operation");i=new Fo(Oi(o,Fi(u,o)),i,i&&i.lastId,c,c&&c.id,n,null,new Oo(e)),i.integrate(t,0)}}})),h()},js=()=>mn("Length exceeded!"),Is=(t,n,e,r)=>{if(e>n._length)throw js();if(0===e)return n._searchMarker&&ks(n._searchMarker,e,r.length),Us(t,n,null,r);const i=e,s=ms(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&&Ki(t,Oi(o.id.client,o.id.clock+e));break}e-=o.length}return n._searchMarker&&ks(n._searchMarker,i,r.length),Us(t,n,o,r)},Os=(t,n,e,r)=>{if(0===r)return;const i=e,s=r,o=ms(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&&Ki(t,Oi(u.id.client,u.id.clock+e)),e-=u.length);for(;r>0&&null!==u;)u.deleted||(r<u.length&&Ki(t,Oi(u.id.client,u.id.clock+r)),u.delete(t),r-=u.length),u=u.right;if(r>0)throw js();n._searchMarker&&ks(n._searchMarker,i,-s+r)},_s=(t,n,e)=>{const r=n._map.get(e);void 0!==r&&r.delete(t)},zs=(t,n,e,r)=>{const i=n._map.get(e)||null,s=t.doc,o=s.clientID;let u;if(null==r)u=new xo([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:u=new xo([r]);break;case Uint8Array:u=new vo(r);break;case ai:u=new go(r);break;default:if(!(r instanceof xs))throw new Error("Unexpected content type");u=new Oo(r)}new Fo(Oi(o,Fi(s.store,o)),i,i&&i.lastId,null,null,n,e,u).integrate(t,0)},Ds=(t,n)=>{t.doc??ws();const e=t._map.get(n);return void 0===e||e.deleted?void 0:e.content.getContent()[e.length-1]},Ps=t=>{const n={};return t.doc??ws(),t._map.forEach(((t,e)=>{t.deleted||(n[e]=t.content.getContent()[t.length-1])})),n},Rs=(t,n)=>{t.doc??ws();const e=t._map.get(n);return void 0!==e&&!e.deleted},Fs=t=>{return t.doc??ws(),n=t._map.entries(),e=t=>!t[1].deleted,qr((()=>{let t;do{t=n.next()}while(!t.done&&!e(t.value));return t}));var n,e};class Ls extends ps{}class Ws extends xs{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){const n=new Ws;return n.push(t),n}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Ws}clone(){const t=new Ws;return t.insert(0,this.toArray().map((t=>t instanceof xs?t.clone():t))),t}get length(){return this.doc??ws(),this._length}_callObserver(t,n){super._callObserver(t,n),As(this,t,new Ls(this,t))}insert(t,n){null!==this.doc?Ji(this.doc,(e=>{Is(e,this,t,n)})):this._prelimContent.splice(t,0,...n)}push(t){null!==this.doc?Ji(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;Us(t,n,r,e)})(n,this,t)})):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,n=1){null!==this.doc?Ji(this.doc,(e=>{Os(e,this,t,n)})):this._prelimContent.splice(t,n)}get(t){return Ts(this,t)}toArray(){return Ss(this)}slice(t=0,n=this.length){return Ms(this,t,n)}toJSON(){return this.map((t=>t instanceof xs?t.toJSON():t))}map(t){return $s(this,t)}forEach(t){Cs(this,t)}[Symbol.iterator](){return Es(this)}_write(t){t.writeTypeRef(Co)}}class Bs extends ps{constructor(t,n,e){super(t,n),this.keysChanged=e}}class Ns extends xs{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 Ns}clone(){const t=new Ns;return this.forEach(((n,e)=>{t.set(e,n instanceof xs?n.clone():n)})),t}_callObserver(t,n){As(this,t,new Bs(this,t,n))}toJSON(){this.doc??ws();const t={};return this._map.forEach(((n,e)=>{if(!n.deleted){const r=n.content.getContent()[n.length-1];t[e]=r instanceof xs?r.toJSON():r}})),t}get size(){return[...Fs(this)].length}keys(){return Gr(Fs(this),(t=>t[0]))}values(){return Gr(Fs(this),(t=>t[1].content.getContent()[t[1].length-1]))}entries(){return Gr(Fs(this),(t=>[t[0],t[1].content.getContent()[t[1].length-1]]))}forEach(t){this.doc??ws(),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?Ji(this.doc,(n=>{_s(n,this,t)})):this._prelimContent.delete(t)}set(t,n){return null!==this.doc?Ji(this.doc,(e=>{zs(e,this,t,n)})):this._prelimContent.set(t,n),n}get(t){return Ds(this,t)}has(t){return Rs(this,t)}clear(){null!==this.doc?Ji(this.doc,(t=>{this.forEach((function(n,e,r){_s(t,r,e)}))})):this._prelimContent.clear()}_write(t){t.writeTypeRef($o)}}const Ks=(t,n)=>t===n||"object"==typeof t&&"object"==typeof n&&t&&n&&((t,n)=>t===n||ne(t)===ne(n)&&ee(t,((t,e)=>(void 0!==t||re(n,e))&&Gn(n[e],t))))(t,n);class Hs{constructor(t,n,e,r){this.left=t,this.right=n,this.index=e,this.currentAttributes=r}forward(){null===this.right&&An(),this.right.content.constructor===mo?this.right.deleted||Xs(this.currentAttributes,this.right.content):this.right.deleted||(this.index+=this.right.length),this.left=this.right,this.right=this.right.right}}const Vs=(t,n,e)=>{for(;null!==n.right&&e>0;)n.right.content.constructor===mo?n.right.deleted||Xs(n.currentAttributes,n.right.content):n.right.deleted||(e<n.right.length&&Ki(t,Oi(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?ms(n,e):null;if(s){const n=new Hs(s.p.left,s.p,s.index,i);return Vs(t,n,e-s.index)}{const r=new Hs(null,n._start,0,i);return Vs(t,r,e)}},Ys=(t,n,e,r)=>{for(;null!==e.right&&(!0===e.right.deleted||e.right.content.constructor===mo&&Ks(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,a=new Fo(Oi(s,Fi(i.store,s)),u,u&&u.lastId,c,c&&c.id,n,null,new mo(o,r));a.integrate(t,0),e.right=a,e.forward()}))},Xs=(t,n)=>{const{key:e,value:r}=n;null===r?t.delete(e):t.set(e,r)},qs=(t,n)=>{for(;null!==t.right&&(t.right.deleted||t.right.content.constructor===mo&&Ks(n[t.right.content.key]??null,t.right.content.value));)t.forward()},Gs=(t,n,e,r)=>{const i=t.doc,s=i.clientID,o=new Map;for(const u in r){const c=r[u],a=e.currentAttributes.get(u)??null;if(!Ks(a,c)){o.set(u,a);const{left:r,right:h}=e;e.right=new Fo(Oi(s,Fi(i.store,s)),r,r&&r.lastId,h,h&&h.id,n,null,new mo(u,c)),e.right.integrate(t,0),e.forward()}}return o},Js=(t,n,e,r,i)=>{e.currentAttributes.forEach(((t,n)=>{void 0===i[n]&&(i[n]=null)}));const s=t.doc,o=s.clientID;qs(e,i);const u=Gs(t,n,e,i),c=r.constructor===String?new Mo(r):r instanceof xs?new Oo(r):new bo(r);let{left:a,right:h,index:l}=e;n._searchMarker&&ks(n._searchMarker,e.index,c.getLength()),h=new Fo(Oi(o,Fi(s.store,o)),a,a&&a.lastId,h,h&&h.id,n,null,c),h.integrate(t,0),e.right=h,e.index=l,e.forward(),Ys(t,n,e,u)},Zs=(t,n,e,r,i)=>{const s=t.doc,o=s.clientID;qs(e,i);const u=Gs(t,n,e,i);t:for(;null!==e.right&&(r>0||u.size>0&&(e.right.deleted||e.right.content.constructor===mo));){if(!e.right.deleted)switch(e.right.content.constructor){case mo:{const{key:n,value:s}=e.right.content,o=i[n];if(void 0!==o){if(Ks(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&&Ki(t,Oi(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 Fo(Oi(o,Fi(s.store,o)),e.left,e.left&&e.left.lastId,e.right,e.right&&e.right.id,n,null,new Mo(i)),e.right.integrate(t,0),e.forward()}Ys(t,n,e,u)},to=(t,n,e,r,i)=>{let s=n;const o=mt();for(;s&&(!s.countable||s.deleted);){if(!s.deleted&&s.content.constructor===mo){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 mo:{const{key:s,value:a}=e,h=r.get(s)??null;o.get(s)===e&&h!==a||(n.delete(t),u++,c||(i.get(s)??null)!==a||h===a||(null===h?i.delete(s):i.set(s,h))),c||n.deleted||Xs(i,e);break}}}n=n.right}return u},no=t=>{let n=0;return Ji(t.doc,(e=>{let r=t._start,i=t._start,s=mt();const o=kt(s);for(;i;)!1===i.deleted&&(i.content.constructor===mo?Xs(o,i.content):(n+=to(e,r,i,s,o),s=kt(o),r=i)),i=i.right})),n},eo=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&&Vi(t,e.store.clients.get(r),s,i,(t=>{t.deleted||t.content.constructor!==mo||t.constructor===po||n.add(t.parent)}))}Ji(e,(e=>{ti(t,t.deleteSet,(t=>{t instanceof po||!t.parent._hasFormatting||n.has(t.parent)||(t.content.constructor===mo?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===mo){const r=n.content.key;e.has(r)?n.delete(t):e.add(r)}n=n.left}})(e,t))}));for(const t of n)no(t)}))},ro=(t,n,e)=>{const r=e,i=kt(n.currentAttributes),s=n.right;for(;e>0&&null!==n.right;){if(!1===n.right.deleted)switch(n.right.content.constructor){case Oo:case bo:case Mo:e<n.right.length&&Ki(t,Oi(n.right.id.client,n.right.id.clock+e)),e-=n.right.length,n.right.delete(t)}n.forward()}s&&to(t,s,n.right,i,n.currentAttributes);const o=(n.left||n.right).parent;return o._searchMarker&&ks(o._searchMarker,n.index,-r+e),n};class io extends ps{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=[];Ji(this.target.doc,(n=>{const e=new Map,r=new Map;let i=this.target._start,s=null;const o={};let u="",c=0,a=0;const h=()=>{if(null!==s){let n=null;switch(s){case"delete":a>0&&(n={delete:a}),a=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=Jn({},o))),c=0}n&&t.push(n),s=null}};for(;null!==i;){switch(i.content.constructor){case Oo:case bo:this.adds(i)?this.deletes(i)||(h(),s="insert",u=i.content.getContent()[0],h()):this.deletes(i)?("delete"!==s&&(h(),s="delete"),a+=1):i.deleted||("retain"!==s&&(h(),s="retain"),c+=1);break;case Mo:this.adds(i)?this.deletes(i)||("insert"!==s&&(h(),s="insert"),u+=i.content.str):this.deletes(i)?("delete"!==s&&(h(),s="delete"),a+=i.length):i.deleted||("retain"!==s&&(h(),s="retain"),c+=i.length);break;case mo:{const{key:t,value:u}=i.content;if(this.adds(i)){if(!this.deletes(i)){const c=e.get(t)??null;Ks(c,u)?null!==u&&i.delete(n):("retain"===s&&h(),Ks(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;Ks(n,u)||("retain"===s&&h(),o[t]=n)}else if(!i.deleted){r.set(t,u);const e=o[t];void 0!==e&&(Ks(e,u)?null!==e&&i.delete(n):("retain"===s&&h(),null===u?delete o[t]:o[t]=u))}i.deleted||("insert"===s&&h(),Xs(e,i.content));break}}i=i.right}for(h();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 so extends xs{constructor(t){super(),this._pending=void 0!==t?[()=>this.insert(0,t)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??ws(),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 so}clone(){const t=new so;return t.applyDelta(this.toDelta()),t}_callObserver(t,n){super._callObserver(t,n);const e=new io(this,t,n);As(this,t,e),!t.local&&this._hasFormatting&&(t._needFormattingCleanup=!0)}toString(){this.doc??ws();let t="",n=this._start;for(;null!==n;)!n.deleted&&n.countable&&n.content.constructor===Mo&&(t+=n.content.str),n=n.right;return t}toJSON(){return this.toString()}applyDelta(t,{sanitize:n=!0}={}){null!==this.doc?Ji(this.doc,(e=>{const r=new Hs(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)&&Js(e,this,r,o,s.attributes||{})}else void 0!==s.retain?Zs(e,this,r,s.retain,s.attributes||{}):void 0!==s.delete&&ro(e,r,s.delete)}})):this._pending.push((()=>this.applyDelta(t)))}toDelta(t,n,e){this.doc??ws();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(zi(o,t)||void 0!==n&&zi(o,n))switch(o.content.constructor){case Mo:{const r=i.get("ychange");void 0===t||zi(o,t)?void 0===n||zi(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 Oo:case bo:{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 mo:zi(o,t)&&(u(),Xs(i,o.content))}o=o.right}u()};return t||n?Ji(this.doc,(e=>{t&&Di(e,t),n&&Di(e,n),c()}),"cleanup"):c(),r}insert(t,n,e){if(n.length<=0)return;const r=this.doc;null!==r?Ji(r,(r=>{const i=Qs(r,this,t,!e);e||(e={},i.currentAttributes.forEach(((t,n)=>{e[n]=t}))),Js(r,this,i,n,e)})):this._pending.push((()=>this.insert(t,n,e)))}insertEmbed(t,n,e){const r=this.doc;null!==r?Ji(r,(r=>{const i=Qs(r,this,t,!e);Js(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?Ji(e,(e=>{ro(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?Ji(r,(r=>{const i=Qs(r,this,t,!1);null!==i.right&&Zs(r,this,i,n,e)})):this._pending.push((()=>this.format(t,n,e)))}removeAttribute(t){null!==this.doc?Ji(this.doc,(n=>{_s(n,this,t)})):this._pending.push((()=>this.removeAttribute(t)))}setAttribute(t,n){null!==this.doc?Ji(this.doc,(e=>{zs(e,this,t,n)})):this._pending.push((()=>this.setAttribute(t,n)))}getAttribute(t){return Ds(this,t)}getAttributes(){return Ps(this)}_write(t){t.writeTypeRef(Eo)}}class oo{constructor(t,n=()=>!0){this._filter=n,this._root=t,this._currentNode=t._start,this._firstCall=!0,t.doc??ws()}[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!==co&&n.constructor!==uo||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 uo extends xs{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 uo}clone(){const t=new uo;return t.insert(0,this.toArray().map((t=>t instanceof xs?t.clone():t))),t}get length(){return this.doc??ws(),null===this._prelimContent?this._length:this._prelimContent.length}createTreeWalker(t){return new oo(this,t)}querySelector(t){t=t.toUpperCase();const n=new oo(this,(n=>n.nodeName&&n.nodeName.toUpperCase()===t)).next();return n.done?null:n.value}querySelectorAll(t){return t=t.toUpperCase(),Ct(new oo(this,(n=>n.nodeName&&n.nodeName.toUpperCase()===t)))}_callObserver(t,n){As(this,t,new ao(this,n,t))}toString(){return $s(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),Cs(this,(i=>{r.insertBefore(i.toDOM(t,n,e),null)})),r}insert(t,n){null!==this.doc?Ji(this.doc,(e=>{Is(e,this,t,n)})):this._prelimContent.splice(t,0,...n)}insertAfter(t,n){if(null!==this.doc)Ji(this.doc,(e=>{Us(e,this,t&&t instanceof xs?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 mn("Reference item not found");e.splice(r,0,...n)}}delete(t,n=1){null!==this.doc?Ji(this.doc,(e=>{Os(e,this,t,n)})):this._prelimContent.splice(t,n)}toArray(){return Ss(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return Ts(this,t)}slice(t=0,n=this.length){return Ms(this,t,n)}forEach(t){Cs(this,t)}_write(t){t.writeTypeRef(Uo)}}class co extends uo{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 co(this.nodeName)}clone(){const t=new co(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 xs?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?Ji(this.doc,(n=>{_s(n,this,t)})):this._prelimAttrs.delete(t)}setAttribute(t,n){null!==this.doc?Ji(this.doc,(e=>{zs(e,this,t,n)})):this._prelimAttrs.set(t,n)}getAttribute(t){return Ds(this,t)}hasAttribute(t){return Rs(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&&zi(i,n)&&(e[r]=i.content.getContent()[i.length-1])})),e})(0,t):Ps(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 Cs(this,(i=>{r.appendChild(i.toDOM(t,n,e))})),void 0!==e&&e._createAssociation(r,this),r}_write(t){t.writeTypeRef(To),t.writeKey(this.nodeName)}}class ao extends ps{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 ho extends Ns{constructor(t){super(),this.hookName=t}_copy(){return new ho(this.hookName)}clone(){const t=new ho(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 lo extends so{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 lo}clone(){const t=new lo;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(Io)}}class fo{constructor(t,n){this.id=t,this.length=n}get deleted(){throw kn()}mergeWith(t){return!1}write(t,n,e){throw kn()}integrate(t,n){throw kn()}}class po extends fo{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),Li(t.doc.store,this)}write(t,n){t.writeInfo(0),t.writeLen(this.length-n)}getMissing(t,n){return null}}class vo{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new vo(this.content)}splice(t){throw kn()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeBuf(this.content)}getRef(){return 3}}class wo{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new wo(this.len)}splice(t){const n=new wo(this.len-t);return this.len=t,n}mergeWith(t){return this.len+=t.len,!0}integrate(t,n){ii(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 yo=(t,n)=>new ai({guid:t,...n,shouldLoad:n.shouldLoad||n.autoLoad||!1});class go{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 go(yo(this.doc.guid,this.opts))}splice(t){throw kn()}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 bo{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new bo(this.embed)}splice(t){throw kn()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeJSON(this.embed)}getRef(){return 5}}class mo{constructor(t,n){this.key=t,this.value=n}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new mo(this.key,this.value)}splice(t){throw kn()}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 ko{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new ko(this.arr)}splice(t){const n=new ko(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 Ao="development"===de("node_env");class xo{constructor(t){this.arr=t,Ao&&se(t)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new xo(this.arr)}splice(t){const n=new xo(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 Mo{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new Mo(this.str)}splice(t){const n=new Mo(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 So=[()=>new Ws,()=>new Ns,()=>new so,t=>new co(t.readKey()),()=>new uo,t=>new ho(t.readKey()),()=>new lo],Co=0,$o=1,Eo=2,To=3,Uo=4,jo=5,Io=6;class Oo{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new Oo(this.type._copy())}splice(t){throw kn()}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=Oi(r.client,r.clock+i)),e=Bi(t,r),i=r.clock-e.id.clock,r=e.redone}while(null!==r&&e instanceof Fo);return{item:e,diff:i}},zo=(t,n)=>{for(;null!==t&&t.keep!==n;)t.keep=n,t=t.parent._item},Do=(t,n,e)=>{const{client:r,clock:i}=n.id,s=new Fo(Oi(r,i+e),n,Oi(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=Oi(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},Po=(t,n)=>Et(t,(t=>ni(t.deletions,n))),Ro=(t,n,e,r,i,s)=>{const o=t.doc,u=o.store,c=o.clientID,a=n.redone;if(null!==a)return Ki(t,a);let h,l=n.parent._item,f=null;if(null!==l&&!0===l.deleted){if(null===l.redone&&(!e.has(l)||null===Ro(t,l,e,r,i,s)))return null;for(;null!==l.redone;)l=Ki(t,l.redone)}const d=null===l?n.parent:l.content.type;if(null===n.parentSub){for(f=n.left,h=n;null!==f;){let n=f;for(;null!==n&&n.parent._item!==l;)n=null===n.redone?null:Ki(t,n.redone);if(null!==n&&n.parent._item===l){f=n;break}f=f.left}for(;null!==h;){let n=h;for(;null!==n&&n.parent._item!==l;)n=null===n.redone?null:Ki(t,n.redone);if(null!==n&&n.parent._item===l){h=n;break}h=h.right}}else if(h=null,n.right&&!i){for(f=n;null!==f&&null!==f.right&&(f.right.redone||ni(r,f.right.id)||Po(s.undoStack,f.right.id)||Po(s.redoStack,f.right.id));)for(f=f.right;f.redone;)f=Ki(t,f.redone);if(f&&null!==f.right)return null}else f=d._map.get(n.parentSub)||null;const p=Fi(u,c),v=Oi(c,p),w=new Fo(v,f,f&&f.lastId,h,h&&h.id,d,n.parentSub,n.content.copy());return n.redone=v,zo(w,!0),w.integrate(t,0),w};class Fo extends fo{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>=Fi(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=Fi(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===ji&&this.id.client!==this.parent.client&&this.parent.clock>=Fi(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=Hi(t,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=Ki(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===po||this.right&&this.right.constructor===po)this.parent=null;else if(this.parent){if(this.parent.constructor===ji){const t=Bi(n,this.parent);this.parent=t.constructor===po?null:t.content.type}}else this.left&&this.left.constructor===Fo?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===Fo&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);return null}integrate(t,n){if(n>0&&(this.id.clock+=n,this.left=Hi(t,t.doc.store,Oi(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),Ii(this.origin,n.origin)){if(n.id.client<this.id.client)e=n,r.clear();else if(Ii(this.rightOrigin,n.rightOrigin))break}else{if(null===n.origin||!i.has(Bi(t.doc.store,n.origin)))break;r.has(Bi(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),Li(t.doc.store,this),this.content.integrate(t,this),Xi(t,this.parent,this.parentSub),(null!==this.parent._item&&this.parent._item.deleted||null!==this.parentSub&&null!==this.right)&&this.delete(t)}else new po(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:Oi(this.id.client,this.id.clock+this.length-1)}mergeWith(t){if(this.constructor===t.constructor&&Ii(t.origin,this.lastId)&&this.right===t&&Ii(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(),ii(t.deleteSet,this.id.client,this.id.clock,this.length),Xi(t,n,this.parentSub),this.content.delete(t)}}gc(t,n){if(!this.deleted)throw An();this.content.gc(t),n?((t,n,e)=>{const r=t.clients.get(n.id.client);r[Wi(r,n.id.clock)]=e})(t,this,new po(this.id,this.length)):this.content=new wo(this.length)}write(t,n){const e=n>0?Oi(this.id.client,this.id.clock+n-1):this.origin,r=this.rightOrigin,i=this.parentSub,s=31&this.content.getRef()|(null===e?0:Ft)|(null===r?0:Rt)|(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 An()})(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)):An();null!==i&&t.writeString(i)}this.content.write(t,n)}}const Lo=(t,n)=>Wo[31&n](t),Wo=[()=>{An()},t=>new wo(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 ko(e)},t=>new vo(t.readBuf()),t=>new Mo(t.readString()),t=>new bo(t.readJSON()),t=>new mo(t.readKey(),t.readJSON()),t=>new Oo(So[t.readTypeRef()](t)),t=>{const n=t.readLen(),e=[];for(let r=0;r<n;r++)e.push(t.readAny());return new xo(e)},t=>new go(yo(t.readString(),t.readAny())),()=>{An()}];class Bo extends fo{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor===t.constructor&&(this.length+=t.length,!0)}integrate(t,n){An()}write(t,n){t.writeInfo(10),rn(t.restEncoder,this.length-n)}getMissing(t,n){return null}}const No="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},Ko="__ $YJS$ __";!0===No[Ko]&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438"),No[Ko]=!0;const Ho=t=>Kn(((n,e)=>{t.onerror=t=>e(new Error(t.target.error)),t.onsuccess=t=>n(t.target.result)})),Vo=(t,n,e="readwrite")=>{const r=t.transaction(n,e);return n.map((t=>Go(r,t)))},Qo=(t,n)=>Ho(t.count(n)),Yo=(t,n)=>Ho(t.delete(n)),Xo=(t,n)=>Ho(t.add(n)),qo=(t,n,e,r="next")=>((t,n)=>Kn(((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))),Go=(t,n)=>t.objectStore(n),Jo="custom",Zo="updates",tu=(t,n=()=>{},e=()=>{})=>{const[r]=Vo(t.db,[Zo]);return(i=r,o=t._dbref,s=IDBKeyRange.lowerBound(o,false),Ho(i.getAll(s,undefined))).then((i=>{t._destroyed||(n(r),Ji(t.doc,(()=>{i.forEach((n=>mi(t.doc,n)))}),t,!1),e(r))})).then((()=>((t,n=null)=>((t,n)=>{let e=null;return qo(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 nu 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=>Kn(((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(mn(t.target.error)),r.onsuccess=t=>{const e=t.target.result;e.onversionchange=()=>{e.close()},n(e)}})))(t),this.whenSynced=Kn((t=>this.on("synced",(()=>t(this))))),this._db.then((t=>{this.db=t,tu(this,(t=>Xo(t,Ai(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]=Vo(this.db,[Zo]);Xo(n,t),++this._dbsize>=500&&(null!==this._storeTimeoutId&&clearTimeout(this._storeTimeoutId),this._storeTimeoutId=setTimeout((()=>{((t,n=!0)=>{tu(t).then((e=>{(n||t._dbsize>=500)&&Xo(e,Ai(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((()=>{Ho(indexedDB.deleteDatabase(this.name))}))}get(t){return this._db.then((n=>{const[e]=Vo(n,[Jo],"readonly");return((t,n)=>Ho(t.get(n)))(e,t)}))}set(t,n){return this._db.then((e=>{const[r]=Vo(e,[Jo]);return((t,n,e)=>Ho(t.put(n,e)))(r,n,t)}))}del(t){return this._db.then((n=>{const[e]=Vo(n,[Jo]);return Yo(e,t)}))}}class eu{provider;isConnected=!1;constructor(t,n,e){this.provider=new nu(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 ru=Math.floor,iu=127,su=Number.MAX_SAFE_INTEGER,ou="undefined"!=typeof TextEncoder?new TextEncoder:null,uu=ou?t=>ou.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 cu="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});cu&&1===cu.decode(new Uint8Array).length&&(cu=null);const au=(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},hu=(t,n)=>{for(;n>iu;)au(t,128|iu&n),n=ru(n/128);au(t,iu&n)},lu=new Uint8Array(3e4),fu=lu.length/3,du=ou&&ou.encodeInto?(t,n)=>{if(n.length<fu){const e=ou.encodeInto(n,lu).written||0;hu(t,e);for(let n=0;n<e;n++)au(t,lu[n])}else pu(t,uu(n))}:(t,n)=>{const e=unescape(encodeURIComponent(n)),r=e.length;hu(t,r);for(let n=0;n<r;n++)au(t,e.codePointAt(n))},pu=(t,n)=>{hu(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)},vu=t=>new Error(t),wu=vu("Unexpected end of array"),yu=vu("Integer out of Range"),gu=t=>t.arr[t.pos++],bu=t=>{let n=0,e=1;const r=t.arr.length;for(;t.pos<r;){const r=t.arr[t.pos++];if(n+=(r&iu)*e,e*=128,r<128)return n;if(n>su)throw yu}throw wu},mu=cu?t=>cu.decode((t=>((t,n)=>{const e=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,n);return t.pos+=n,e})(t,bu(t)))(t)):t=>{let n=bu(t);if(0===n)return"";{let e=String.fromCodePoint(gu(t));if(--n<100)for(;n--;)e+=String.fromCodePoint(gu(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 ku;!function(t){t[t.Token=0]="Token",t[t.PermissionDenied=1]="PermissionDenied",t[t.Authenticated=2]="Authenticated"}(ku||(ku={}));const Au=t=>Array.from(t.entries()).map((([t,n])=>({clientId:t,...n})));var xu;async function Mu(t){return new Promise((n=>setTimeout(n,t)))}function Su(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"}(xu||(xu={}));const Cu=Math.floor,$u=128,Eu=127,Tu=Number.MAX_SAFE_INTEGER,Uu=()=>new Set,ju=Array.from,Iu="undefined"!=typeof TextEncoder?new TextEncoder:null,Ou=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 _u="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});_u&&1===_u.decode(new Uint8Array).length&&(_u=null);class zu{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const Du=()=>new zu,Pu=t=>{let n=t.cpos;for(let e=0;e<t.bufs.length;e++)n+=t.bufs[e].length;return n},Ru=t=>{const n=new Uint8Array(Pu(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},Fu=(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},Lu=(t,n)=>{for(;n>Eu;)Fu(t,$u|Eu&n),n=Cu(n/128);Fu(t,Eu&n)},Wu=new Uint8Array(3e4),Bu=Wu.length/3,Nu=Iu&&Iu.encodeInto?(t,n)=>{if(n.length<Bu){const e=Iu.encodeInto(n,Wu).written||0;Lu(t,e);for(let n=0;n<e;n++)Fu(t,Wu[n])}else Ku(t,Ou(n))}:(t,n)=>{const e=unescape(encodeURIComponent(n)),r=e.length;Lu(t,r);for(let n=0;n<r;n++)Fu(t,e.codePointAt(n))},Ku=(t,n)=>{Lu(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)},Hu=t=>new Error(t),Vu=Hu("Unexpected end of array"),Qu=Hu("Integer out of Range");class Yu{constructor(t){this.arr=t,this.pos=0}}const Xu=t=>new Yu(t),qu=t=>((t,n)=>{const e=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,n);return t.pos+=n,e})(t,Ju(t)),Gu=t=>t.arr[t.pos++],Ju=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<$u)return n;if(n>Tu)throw Qu}throw Vu},Zu=_u?t=>_u.decode(qu(t)):t=>{let n=Ju(t);if(0===n)return"";{let e=String.fromCodePoint(Gu(t));if(--n<100)for(;n--;)e+=String.fromCodePoint(Gu(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))}},tc=Date.now,nc=()=>new Map;class ec{constructor(){this._observers=nc()}on(t,n){((t,n,e)=>{let r=t.get(n);return void 0===r&&t.set(n,r=e()),r})(this._observers,t,Uu).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)||nc()).values()).forEach((t=>t(...n)))}destroy(){this._observers=nc()}}const rc=Object.keys,ic=t=>rc(t).length,sc=(t,n)=>Object.prototype.hasOwnProperty.call(t,n),oc=(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)||!oc(t.get(e),n.get(e)))return!1;break;case Object:if(ic(t)!==ic(n))return!1;for(const e in t)if(!sc(t,e)||!oc(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(!oc(t[e],n[e]))return!1;break;default:return!1}return!0};class uc extends ec{constructor(t){super(),this.doc=t,this.clientID=t.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval((()=>{const t=tc();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&&cc(this,n,"timeout")}),Cu(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:tc()});const s=[],o=[],u=[],c=[];null===t?c.push(n):null==i?null!=t&&s.push(n):(o.push(n),oc(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 cc=(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:tc()})}r.push(i)}}r.length>0&&(t.emit("change",[{added:[],updated:[],removed:r},e]),t.emit("update",[{added:[],updated:[],removed:r},e]))},ac=(t,n,e=t.states)=>{const r=n.length,i=Du();Lu(i,r);for(let s=0;s<r;s++){const r=n[s],o=e.get(r)||null,u=t.meta.get(r).clock;Lu(i,r),Lu(i,u),Nu(i,JSON.stringify(o))}return Ru(i)};class hc{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 lc{constructor(t){this.data=t,this.encoder=Du(),this.decoder=Xu(new Uint8Array(this.data))}peekVarString(){return(t=>{const n=t.pos,e=Zu(t);return t.pos=n,e})(this.decoder)}readVarUint(){return Ju(this.decoder)}readVarString(){return Zu(this.decoder)}readVarUint8Array(){return qu(this.decoder)}writeVarUint(t){return Lu(this.encoder,t)}writeVarString(t){return Nu(this.encoder,t)}writeVarUint8Array(t){return Ku(this.encoder,t)}length(){return Pu(this.encoder)}}var fc,dc;!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"}(fc||(fc={})),function(t){t.Connecting="connecting",t.Connected="connected",t.Disconnected="disconnected"}(dc||(dc={}));class pc{constructor(){this.encoder=Du()}get(t){return t.encoder}toUint8Array(){return Ru(this.encoder)}}class vc extends pc{constructor(){super(...arguments),this.type=fc.CLOSE,this.description="Ask the server to close the connection"}get(t){return Nu(this.encoder,t.documentName),Lu(this.encoder,this.type),this.encoder}}class wc extends hc{constructor(t){super(),this.messageQueue=[],this.configuration={url:"",autoConnect:!0,preserveTrailingSlash:!1,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=dc.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=dc.Connected,this.emit("status",{status:dc.Connected}),this.cancelWebsocketRetry=void 0,this.receivedOnOpenPayload=t}attach(t){this.configuration.providerMap.set(t.configuration.name,t),this.status===dc.Disconnected&&this.shouldConnect&&this.connect(),this.receivedOnOpenPayload&&this.status===dc.Connected&&t.onOpen(this.receivedOnOpenPayload)}detach(t){this.configuration.providerMap.has(t.configuration.name)&&(t.send(vc,{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===dc.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||Su,s=e.calculateDelay?e.calculateDelay(r,e):e.initialDelay;if(s&&await Mu(s),r.attemptNum<1&&e.initialJitter){const t=i(r,e);t&&await Mu(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 Mu(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=dc.Connecting,this.emit("status",{status:dc.Connecting}),this.connectionAttempt={resolve:t,reject:n}}))}onMessage(t){var n;this.resolveConnectionAttempt(),this.lastMessageReceived=tc();const e=new lc(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=dc.Connected,this.emit("status",{status:dc.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===dc.Connected&&this.lastMessageReceived&&(this.configuration.messageReconnectTimeout>=tc()-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(){if(this.configuration.preserveTrailingSlash)return this.configuration.url;let t=this.configuration.url;for(;"/"===t[t.length-1];)t=t.slice(0,t.length-1);return t}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)===xu.Open?this.webSocket.send(t):this.messageQueue.push(t)}onClose({event:t}){this.closeTries=0,this.cleanupWebSocket(),this.connectionAttempt&&this.rejectConnectionAttempt(),this.status=dc.Disconnected,this.emit("status",{status:dc.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 yc=(t,n,e)=>{try{mi(n,qu(t),e)}catch(t){console.error("Caught error while handling a Yjs update",t)}},gc=yc;class bc{constructor(t){this.message=t}apply(t,n){const{message:e}=this,r=e.readVarUint(),i=e.length();switch(r){case fc.Sync:this.applySyncMessage(t,n);break;case fc.Awareness:this.applyAwarenessMessage(t);break;case fc.Auth:this.applyAuthMessage(t);break;case fc.QueryAwareness:this.applyQueryAwarenessMessage(t);break;case fc.Stateless:t.receiveStateless(Zu(e.decoder));break;case fc.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&$u))return i*e;const s=t.arr.length;for(;t.pos<s;){if(n=t.arr[t.pos++],e+=(n&Eu)*r,r*=128,n<$u)return i*e;if(e>Tu)throw Qu}throw Vu})(e.decoder));break;case fc.CLOSE:const i={code:1e3,reason:Zu(e.decoder),target:t.configuration.websocketProvider.webSocket,type:"close"};t.onClose(),t.configuration.onClose({event:i}),t.forwardClose({event:i});break;default:throw new Error(`Can’t apply message of unknown type: ${r}`)}e.length()>i+1&&t.send(pc,{encoder:e.encoder})}applySyncMessage(t,n){const{message:e}=this;e.writeVarUint(fc.Sync);const r=((t,n,e,r)=>{const i=Ju(t);switch(i){case 0:((t,n,e)=>{((t,n,e)=>{Lu(t,1),Ku(t,Ai(n,e))})(n,e,qu(t))})(t,n,e);break;case 1:yc(t,e,r);break;case 2:gc(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=Xu(n),i=tc(),s=[],o=[],u=[],c=[],a=Ju(r);for(let n=0;n<a;n++){const n=Ju(r);let e=Ju(r);const a=JSON.parse(Zu(r)),h=t.meta.get(n),l=t.states.get(n),f=void 0===h?0:h.clock;(f<e||f===e&&null===a&&t.states.has(n))&&(null===a?n===t.clientID&&null!=t.getLocalState()?e++:t.states.delete(n):t.states.set(n,a),t.meta.set(n,{clock:e,lastUpdated:i}),void 0===h&&null!==a?s.push(n):void 0!==h&&null===a?c.push(n):null!==a&&(oc(a,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(bu(t)){case ku.Token:n();break;case ku.PermissionDenied:e(mu(t));break;case ku.Authenticated:r(mu(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(fc.Awareness),n.writeVarUint8Array(ac(t.awareness,Array.from(t.awareness.getStates().keys())))}}class mc{constructor(t,n={}){this.message=new t,this.encoder=this.message.get(n)}create(){return Ru(this.encoder)}send(t){null==t||t.send(this.create())}}class kc extends pc{constructor(){super(...arguments),this.type=fc.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 Nu(this.encoder,t.documentName),Lu(this.encoder,this.type),e=t.token,hu(n=this.encoder,ku.Token),du(n,e),this.encoder}}class Ac extends pc{constructor(){super(...arguments),this.type=fc.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 Nu(this.encoder,t.documentName),Lu(this.encoder,this.type),n=void 0===t.states?ac(t.awareness,t.clients):ac(t.awareness,t.clients,t.states),Ku(this.encoder,n),this.encoder}}class xc extends pc{constructor(){super(...arguments),this.type=fc.Stateless,this.description="A stateless message"}get(t){var n;return Nu(this.encoder,t.documentName),Lu(this.encoder,this.type),Nu(this.encoder,null!==(n=t.payload)&&void 0!==n?n:""),this.encoder}}class Mc extends pc{constructor(){super(...arguments),this.type=fc.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 Nu(this.encoder,t.documentName),Lu(this.encoder,this.type),((t,n)=>{Lu(t,0);const e=Si(n);Ku(t,e)})(this.encoder,t.document),this.encoder}}class Sc extends pc{constructor(){super(...arguments),this.type=fc.Sync,this.description="A document update"}get(t){var n,e;return Nu(this.encoder,t.documentName),Lu(this.encoder,this.type),e=t.update,Lu(n=this.encoder,2),Ku(n,e),this.encoder}}class Cc extends Error{constructor(){super(...arguments),this.code=1001}}class $c extends hc{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 ai,this.configuration.awareness=void 0!==t.awareness?t.awareness:new uc(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:Au(this.awareness.getStates())})})),null===(e=this.awareness)||void 0===e||e.on("change",(()=>{this.emit("awarenessChange",{states:Au(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={}){t.websocketProvider||(this.manageSocket=!0,this.configuration.websocketProvider=new wc(t)),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(Mc,{document:this.document,documentName:this.configuration.name})}pageHide(){this.awareness&&cc(this.awareness,[this.document.clientID],"page hide")}registerEventListeners(){"undefined"!=typeof window&&"addEventListener"in window&&window.addEventListener("pagehide",this.boundPageHide)}sendStateless(t){this.send(xc,{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(kc,{token:null!=t?t:"",documentName:this.configuration.name})}documentUpdateHandler(t,n){n!==this&&(this.incrementUnsyncedChanges(),this.send(Sc,{update:t,documentName:this.configuration.name}))}awarenessUpdateHandler({added:t,updated:n,removed:e},r){const i=t.concat(n).concat(e);this.send(Ac,{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(Mc,{document:this.document,documentName:this.configuration.name}),this.awareness&&null!==this.awareness.getLocalState()&&this.send(Ac,{awareness:this.awareness,clients:[this.document.clientID],documentName:this.configuration.name})}send(t,n){if(!this._isAttached)return;const e=new mc(t,n);this.emit("outgoingMessage",{message:e.message}),e.send(this.configuration.websocketProvider)}onMessage(t){const n=new lc(t.data),e=n.readVarString();n.writeVarString(e),this.emit("message",{event:t,message:new lc(t.data)}),new bc(n).apply(this,!0)}onClose(){this.isAuthenticated=!1,this.synced=!1,this.awareness&&cc(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&&(cc(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 Cc(`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 Ec={providers:[eu]};class Tc{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 ai,this._workspacesMap=this._ydoc.getMap("workspaces");const e="kritzel-app-state",r=n??Ec;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 Uc{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(!Uc.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,a=t.edgeX,h=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&&(a=t.edgeX+n/r*t.arrowOffset,h=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,a=t.edgeX,h=t.edgeY,l=a-n*u,f=h-e*u;c=`${a},${h} ${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:a,solidLineEndY:h,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 a=n?t.x:0,h=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-a} ${r.start.y-h} Q ${r.control.x-a} ${r.control.y-h} ${r.end.x-a} ${r.end.y-h}`}let l=u?.localX??t.startX,f=u?.localY??t.startY,d=c?.localX??t.endX,p=c?.localY??t.endY;if(u&&t.hasStartArrow){const n=t.getArrowSize("start"),e=d-l,r=p-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-p,i=Math.sqrt(e*e+r*r);i>n&&(d+=e/i*n,p+=r/i*n)}return`M ${l-a} ${f-h} L ${d-a} ${p-h}`}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)),a=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?a/c:"start"===n?0:1}}computeCurvedClipInfo(t,n,e){if(Uc.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),a=this.approximateParameterForWorldPoint(t,u);return{localX:c.x,localY:c.y,worldX:u.x,worldY:u.y,t:a}}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),a=this.isPointInPathStroke(o.worldX,o.worldY,s,i);if(u&&!a){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=a,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 a=((t-e)*o+(n-r)*u)/c;a=Math.max(0,Math.min(1,a));const h=e+a*o,l=r+a*u;return Math.sqrt((t-h)*(t-h)+(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 Uc.isInstanceOf(t,"KritzelShape")?t.getClipPolygon():null}getPathClipPoint(t,n){return Uc.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 p)&&!(t instanceof l)&&t.isVisible}}const Ic=1e3,Oc=1e-4;var _c,zc,Dc,Pc={exports:{}},Rc=(_c||(_c=1,zc=Pc,Dc=Pc.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,a=4294967295,h=[["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]",p="[object Date]",v="[object Error]",w="[object Function]",y="[object GeneratorFunction]",g="[object Map]",b="[object Number]",m="[object Object]",k="[object Promise]",A="[object RegExp]",x="[object Set]",M="[object String]",S="[object Symbol]",C="[object WeakMap]",$="[object ArrayBuffer]",E="[object DataView]",T="[object Float32Array]",U="[object Float64Array]",j="[object Int8Array]",I="[object Int16Array]",O="[object Int32Array]",_="[object Uint8Array]",z="[object Uint8ClampedArray]",D="[object Uint16Array]",R="[object Uint32Array]",F=/\b__p \+= '';/g,L=/\b(__p \+=) '' \+/g,W=/(__e\(.*?\)|\b__t\)) \+\n'';/g,B=/&(?:amp|lt|gt|quot|#39);/g,N=/[&<>"']/g,K=RegExp(B.source),H=RegExp(N.source),V=/<%-([\s\S]+?)%>/g,Q=/<%([\s\S]+?)%>/g,Y=/<%=([\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,at=/\w*$/,ht=/^[-+]0x[0-9a-f]+$/i,lt=/^0b[01]+$/i,ft=/^\[object .+?Constructor\]$/,dt=/^0o[0-7]+$/i,pt=/^(?:0|[1-9]\d*)$/,vt=/[\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",kt="a-z\\xdf-\\xf6\\xf8-\\xff",At="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+"]",$t="["+bt+"]",Et="\\d+",Tt="["+mt+"]",Ut="["+kt+"]",jt="[^"+gt+Mt+Et+mt+kt+At+"]",It="\\ud83c[\\udffb-\\udfff]",Ot="[^"+gt+"]",_t="(?:\\ud83c[\\udde6-\\uddff]){2}",zt="[\\ud800-\\udbff][\\udc00-\\udfff]",Dt="["+At+"]",Pt="\\u200d",Rt="(?:"+Ut+"|"+jt+")",Ft="(?:"+Dt+"|"+jt+")",Lt="(?:['’](?:d|ll|m|re|s|t|ve))?",Wt="(?:['’](?:D|LL|M|RE|S|T|VE))?",Bt="(?:"+$t+"|"+It+")?",Nt="["+xt+"]?",Kt=Nt+Bt+"(?:"+Pt+"(?:"+[Ot,_t,zt].join("|")+")"+Nt+Bt+")*",Ht="(?:"+[Tt,_t,zt].join("|")+")"+Kt,Vt="(?:"+[Ot+$t+"?",$t,_t,zt,St].join("|")+")",Qt=RegExp("['’]","g"),Yt=RegExp($t,"g"),Xt=RegExp(It+"(?="+It+")|"+Vt+Kt,"g"),qt=RegExp([Dt+"?"+Ut+"+"+Lt+"(?="+[Ct,Dt,"$"].join("|")+")",Ft+"+"+Wt+"(?="+[Ct,Dt+Rt,"$"].join("|")+")",Dt+"?"+Rt+"+"+Lt,Dt+"+"+Wt,"\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])","\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",Et,Ht].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[T]=nn[U]=nn[j]=nn[I]=nn[O]=nn[_]=nn[z]=nn[D]=nn[R]=!0,nn[l]=nn[f]=nn[$]=nn[d]=nn[E]=nn[p]=nn[v]=nn[w]=nn[g]=nn[b]=nn[m]=nn[A]=nn[x]=nn[M]=nn[C]=!1;var en={};en[l]=en[f]=en[$]=en[E]=en[d]=en[p]=en[T]=en[U]=en[j]=en[I]=en[O]=en[g]=en[b]=en[m]=en[A]=en[x]=en[M]=en[S]=en[_]=en[z]=en[D]=en[R]=!0,en[v]=en[w]=en[C]=!1;var rn={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"},sn=parseFloat,on=parseInt,un="object"==typeof P&&P&&P.Object===Object&&P,cn="object"==typeof self&&self&&self.Object===Object&&self,an=un||cn||Function("return this")(),hn=Dc&&!Dc.nodeType&&Dc,ln=hn&&zc&&!zc.nodeType&&zc,fn=ln&&ln.exports===hn,dn=fn&&un.process,pn=function(){try{return ln&&ln.require&&ln.require("util").types||dn&&dn.binding&&dn.binding("util")}catch(t){}}(),vn=pn&&pn.isArrayBuffer,wn=pn&&pn.isDate,yn=pn&&pn.isMap,gn=pn&&pn.isRegExp,bn=pn&&pn.isSet,mn=pn&&pn.isTypedArray;function kn(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 An(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 $n(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 Tn(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 Un(t,n){for(var e=-1,r=n.length,i=t.length;++e<r;)t[i+e]=n[e];return t}function jn(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 In(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 _n=Wn("length");function zn(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,Fn,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 Fn(t){return t!=t}function Ln(t,n){var e=null==t?0:t.length;return e?Kn(t,n)/e:c}function Wn(n){return function(e){return null==e?t:e[n]}}function Bn(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 Hn(t,n){for(var e=-1,r=Array(t);++e<t;)r[e]=n(e);return r}function Vn(t){return t?t.slice(0,ae(t)+1).replace(tt,""):t}function Qn(t){return function(n){return t(n)}}function Yn(t,n){return Tn(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=Bn({À:"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=Bn({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"});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):_n(t)}function ce(t){return ne(t)?function(t){return t.match(Xt)||[]}(t):function(t){return t.split("")}(t)}function ae(t){for(var n=t.length;n--&&nt.test(t.charAt(n)););return n}var he=Bn({"&amp;":"&","&lt;":"<","&gt;":">","&quot;":'"',"&#39;":"'"}),le=function P(nt){var gt,bt=(nt=null==nt?an:le.defaults(an.Object(),nt,le.pick(an,Zt))).Array,mt=nt.Date,kt=nt.Error,At=nt.Function,xt=nt.Math,Mt=nt.Object,St=nt.RegExp,Ct=nt.String,$t=nt.TypeError,Et=bt.prototype,Tt=Mt.prototype,Ut=nt["__core-js_shared__"],jt=At.prototype.toString,It=Tt.hasOwnProperty,Ot=0,_t=(gt=/[^.]+$/.exec(Ut&&Ut.keys&&Ut.keys.IE_PROTO||""))?"Symbol(src)_1."+gt:"",zt=Tt.toString,Dt=jt.call(Mt),Pt=an._,Rt=St("^"+jt.call(It).replace(J,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Ft=fn?nt.Buffer:t,Lt=nt.Symbol,Wt=nt.Uint8Array,Bt=Ft?Ft.allocUnsafe:t,Nt=re(Mt.getPrototypeOf,Mt),Kt=Mt.create,Ht=Tt.propertyIsEnumerable,Vt=Et.splice,Xt=Lt?Lt.isConcatSpreadable:t,Gt=Lt?Lt.iterator:t,rn=Lt?Lt.toStringTag:t,un=function(){try{var t=us(Mt,"defineProperty");return t({},"",{}),t}catch(t){}}(),cn=nt.clearTimeout!==an.clearTimeout&&nt.clearTimeout,hn=mt&&mt.now!==an.Date.now&&mt.now,ln=nt.setTimeout!==an.setTimeout&&nt.setTimeout,dn=xt.ceil,pn=xt.floor,_n=Mt.getOwnPropertySymbols,Bn=Ft?Ft.isBuffer:t,fe=nt.isFinite,de=Et.join,pe=re(Mt.keys,Mt),ve=xt.max,we=xt.min,ye=mt.now,ge=nt.parseInt,be=xt.random,me=Et.reverse,ke=us(nt,"DataView"),Ae=us(nt,"Map"),xe=us(nt,"Promise"),Me=us(nt,"Set"),Se=us(nt,"WeakMap"),Ce=us(Mt,"create"),$e=Se&&new Se,Ee={},Te=Os(ke),Ue=Os(Ae),je=Os(xe),Ie=Os(Me),Oe=Os(Se),_e=Lt?Lt.prototype:t,ze=_e?_e.valueOf:t,De=_e?_e.toString:t;function Pe(t){if(Go(t)&&!Lo(t)&&!(t instanceof We)){if(t instanceof Le)return t;if(It.call(t,"__wrapped__"))return _s(t)}return new Le(t)}var Re=function(){function n(){}return function(e){if(!qo(e))return{};if(Kt)return Kt(e);n.prototype=e;var r=new n;return n.prototype=t,r}}();function Fe(){}function Le(n,e){this.__wrapped__=n,this.__actions__=[],this.__chain__=!!e,this.__index__=0,this.__values__=t}function We(t){this.__wrapped__=t,this.__actions__=[],this.__dir__=1,this.__filtered__=!1,this.__iteratees__=[],this.__takeCount__=a,this.__views__=[]}function Be(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 He(t){var n=-1,e=null==t?0:t.length;for(this.__data__=new Ke;++n<e;)this.add(t[n])}function Ve(t){var n=this.__data__=new Ne(t);this.size=n.size}function Qe(t,n){var e=Lo(t),r=!e&&Fo(t),i=!e&&!r&&Ko(t),s=!e&&!r&&!i&&su(t),o=e||r||i||s,u=o?Hn(t.length,Ct):[],c=u.length;for(var a in t)!n&&!It.call(t,a)||o&&("length"==a||i&&("offset"==a||"parent"==a)||s&&("buffer"==a||"byteLength"==a||"byteOffset"==a)||ps(a,c))||u.push(a);return u}function Ye(n){var e=n.length;return e?n[Kr(0,e-1)]:t}function Xe(t,n){return Us(Si(t),ir(n,0,t.length))}function qe(t){return Us(Si(t))}function Ge(n,e,r){(r!==t&&!Do(n[e],r)||r===t&&!(e in n))&&er(n,e,r)}function Je(n,e,r){var i=n[e];It.call(n,e)&&Do(i,r)&&(r!==t||e in n)||er(n,e,r)}function Ze(t,n){for(var e=t.length;e--;)if(Do(t[e][0],n))return e;return-1}function tr(t,n,e,r){return ar(t,(function(t,i,s){n(r,t,e(t),s)})),r}function nr(t,n){return t&&Ci(n,$u(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:Au(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,a=2&e,h=4&e;if(r&&(u=s?r(n,i,s,o):r(n)),u!==t)return u;if(!qo(n))return n;var f=Lo(n);if(f){if(u=function(t){var n=t.length,e=new t.constructor(n);return n&&"string"==typeof t[0]&&It.call(t,"index")&&(e.index=t.index,e.input=t.input),e}(n),!c)return Si(n,u)}else{var v=hs(n),k=v==w||v==y;if(Ko(n))return bi(n,c);if(v==m||v==l||k&&!s){if(u=a||k?{}:fs(n),!c)return a?function(t,n){return Ci(t,as(t),n)}(n,function(t,n){return t&&Ci(n,Eu(n),t)}(u,n)):function(t,n){return Ci(t,cs(t),n)}(n,nr(u,n))}else{if(!en[v])return s?n:{};u=function(t,n,e){var r=t.constructor;switch(n){case $:return mi(t);case d:case p: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 T:case U:case j:case I:case O:case _:case z:case D:case R:return ki(t,e);case g:return new r;case b:case M:return new r(t);case A:return function(t){var n=new t.constructor(t.source,at.exec(t));return n.lastIndex=t.lastIndex,n}(t);case x:return new r;case S:return ze?Mt(ze.call(t)):{}}}(n,v,c)}}o||(o=new Ve);var C=o.get(n);if(C)return C;o.set(n,u),eu(n)?n.forEach((function(t){u.add(sr(t,e,r,t,n,o))})):Jo(n)&&n.forEach((function(t,i){u.set(i,sr(t,e,r,i,n,o))}));var P=f?t:(h?a?ts:Zi:a?Eu:$u)(n);return xn(P||n,(function(t,i){P&&(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 $t(n);return Cs((function(){e.apply(t,i)}),r)}function cr(t,n,e,r){var i=-1,s=$n,o=!0,u=t.length,c=[],a=n.length;if(!u)return c;e&&(n=Tn(n,Qn(e))),r?(s=En,o=!1):n.length>=200&&(s=Xn,o=!1,n=new He(n));t:for(;++i<u;){var h=t[i],l=null==e?h:e(h);if(h=r||0!==h?h:0,o&&l==l){for(var f=a;f--;)if(n[f]===l)continue t;c.push(h)}else s(n,l,r)||c.push(h)}return c}Pe.templateSettings={escape:V,evaluate:Q,interpolate:Y,variable:"",imports:{_:Pe}},(Pe.prototype=Fe.prototype).constructor=Pe,(Le.prototype=Re(Fe.prototype)).constructor=Le,(We.prototype=Re(Fe.prototype)).constructor=We,Be.prototype.clear=function(){this.__data__=Ce?Ce(null):{},this.size=0},Be.prototype.delete=function(t){var n=this.has(t)&&delete this.__data__[t];return this.size-=n?1:0,n},Be.prototype.get=function(n){var r=this.__data__;if(Ce){var i=r[n];return i===e?t:i}return It.call(r,n)?r[n]:t},Be.prototype.has=function(n){var e=this.__data__;return Ce?e[n]!==t:It.call(e,n)},Be.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():Vt.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 Be,map:new(Ae||Ne),string:new Be}},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},He.prototype.add=He.prototype.push=function(t){return this.__data__.set(t,e),this},He.prototype.has=function(t){return this.__data__.has(t)},Ve.prototype.clear=function(){this.__data__=new Ne,this.size=0},Ve.prototype.delete=function(t){var n=this.__data__,e=n.delete(t);return this.size=n.size,e},Ve.prototype.get=function(t){return this.__data__.get(t)},Ve.prototype.has=function(t){return this.__data__.has(t)},Ve.prototype.set=function(t,n){var e=this.__data__;if(e instanceof Ne){var r=e.__data__;if(!Ae||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 ar=Ti(yr),hr=Ti(gr,!0);function lr(t,n){var e=!0;return ar(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&&!iu(u):r(u,c)))var c=u,a=o}return a}function dr(t,n){var e=[];return ar(t,(function(t,r,i){n(t,r,i)&&e.push(t)})),e}function pr(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?pr(u,n-1,e,r,i):Un(i,u):r||(i[i.length]=u)}return i}var vr=Ui(),wr=Ui(!0);function yr(t,n){return t&&vr(t,n,$u)}function gr(t,n){return t&&wr(t,n,$u)}function br(t,n){return Cn(n,(function(n){return Qo(t[n])}))}function mr(n,e){for(var r=0,i=(e=vi(e,n)).length;null!=n&&r<i;)n=n[Is(e[r++])];return r&&r==i?n:t}function kr(t,n,e){var r=n(t);return Lo(t)?r:Un(r,e(t))}function Ar(n){return null==n?n===t?"[object Undefined]":"[object Null]":rn&&rn in Mt(n)?function(n){var e=It.call(n,rn),r=n[rn];try{n[rn]=t;var i=!0}catch(t){}var s=zt.call(n);return i&&(e?n[rn]=r:delete n[rn]),s}(n):function(t){return zt.call(t)}(n)}function xr(t,n){return t>n}function Mr(t,n){return null!=t&&It.call(t,n)}function Sr(t,n){return null!=t&&n in Mt(t)}function Cr(n,e,r){for(var i=r?En:$n,s=n[0].length,o=n.length,u=o,c=bt(o),a=1/0,h=[];u--;){var l=n[u];u&&e&&(l=Tn(l,Qn(e))),a=we(l.length,a),c[u]=!r&&(e||s>=120&&l.length>=120)?new He(u&&l):t}l=n[0];var f=-1,d=c[0];t:for(;++f<s&&h.length<a;){var p=l[f],v=e?e(p):p;if(p=r||0!==p?p:0,!(d?Xn(d,v):i(h,v,r))){for(u=o;--u;){var w=c[u];if(!(w?Xn(w,v):i(n[u],v,r)))continue t}d&&d.push(v),h.push(p)}}return h}function $r(n,e,r){var i=null==(n=xs(n,e=vi(e,n)))?n:n[Is(Hs(e))];return null==i?t:kn(i,n,r)}function Er(t){return Go(t)&&Ar(t)==l}function Tr(n,e,r,i,s){return n===e||(null==n||null==e||!Go(n)&&!Go(e)?n!=n&&e!=e:function(n,e,r,i,s,o){var u=Lo(n),c=Lo(e),a=u?f:hs(n),h=c?f:hs(e),w=(a=a==l?m:a)==m,y=(h=h==l?m:h)==m,k=a==h;if(k&&Ko(n)){if(!Ko(e))return!1;u=!0,w=!1}if(k&&!w)return o||(o=new Ve),u||su(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 $:return!(t.byteLength!=n.byteLength||!s(new Wt(t),new Wt(n)));case d:case p:case b:return Do(+t,+n);case v:return t.name==n.name&&t.message==n.message;case A: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 a=Gi(u(t),u(n),r,i,s,o);return o.delete(t),a;case S:if(ze)return ze.call(t)==ze.call(n)}return!1}(n,e,a,r,i,s,o);if(!(1&r)){var C=w&&It.call(n,"__wrapped__"),T=y&&It.call(e,"__wrapped__");if(C||T){var U=C?n.value():n,j=T?e.value():e;return o||(o=new Ve),s(U,j,r,i,o)}}return!!k&&(o||(o=new Ve),function(n,e,r,i,s,o){var u=1&r,c=Zi(n),a=c.length;if(a!=Zi(e).length&&!u)return!1;for(var h=a;h--;){var l=c[h];if(!(u?l in e:It.call(e,l)))return!1}var f=o.get(n),d=o.get(e);if(f&&d)return f==e&&d==n;var p=!0;o.set(n,e),o.set(e,n);for(var v=u;++h<a;){var w=n[l=c[h]],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)){p=!1;break}v||(v="constructor"==l)}if(p&&!v){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||(p=!1)}return o.delete(n),o.delete(e),p}(n,e,r,i,s,o))}(n,e,r,i,Tr,s))}function Ur(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 a=(c=r[s])[0],h=n[a],l=c[1];if(u&&c[2]){if(h===t&&!(a in n))return!1}else{var f=new Ve;if(i)var d=i(h,l,a,n,e,f);if(!(d===t?Tr(l,h,3,i,f):d))return!1}}return!0}function jr(t){return!(!qo(t)||(n=t,_t&&_t in n))&&(Qo(t)?Rt:ft).test(Os(t));var n}function Ir(t){return"function"==typeof t?t:null==t?Zu:"object"==typeof t?Lo(t)?Pr(t[0],t[1]):Dr(t):cc(t)}function Or(t){if(!bs(t))return pe(t);var n=[];for(var e in Mt(t))It.call(t,e)&&"constructor"!=e&&n.push(e);return n}function _r(t,n){return t<n}function zr(t,n){var e=-1,r=Bo(t)?bt(t.length):[];return ar(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]?ks(n[0][0],n[0][1]):function(e){return e===t||Ur(e,t,n)}}function Pr(n,e){return ws(n)&&ms(e)?ks(Is(n),e):function(r){var i=Au(r,n);return i===t&&i===e?xu(r,n):Tr(e,i,3)}}function Rr(n,e,r,i,s){n!==e&&vr(e,(function(o,u){if(s||(s=new Ve),qo(o))!function(n,e,r,i,s,o,u){var c=Ms(n,r),a=Ms(e,r),h=u.get(a);if(h)Ge(n,r,h);else{var l=o?o(c,a,r+"",n,e,u):t,f=l===t;if(f){var d=Lo(a),p=!d&&Ko(a),v=!d&&!p&&su(a);l=a,d||p||v?Lo(c)?l=c:No(c)?l=Si(c):p?(f=!1,l=bi(a,!0)):v?(f=!1,l=ki(a,!0)):l=[]:tu(a)||Fo(a)?(l=c,Fo(c)?l=du(c):qo(c)&&!Qo(c)||(l=fs(a))):f=!1}f&&(u.set(a,l),s(l,a,i,o,u),u.delete(a)),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)}}),Eu)}function Fr(n,e){var r=n.length;if(r)return ps(e+=e<0?r:0,r)?n[e]:t}function Lr(t,n,e){n=n.length?Tn(n,(function(t){return Lo(t)?function(n){return mr(n,1===t.length?t[0]:t)}:t})):[Zu];var r=-1;n=Tn(n,Qn(is()));var i=zr(t,(function(t){var e=Tn(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=Ai(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 Wr(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,vi(o,t),u)}return s}function Br(t,n,e,r){var i=r?Rn:Pn,s=-1,o=n.length,u=t;for(t===n&&(n=Si(n)),e&&(u=Tn(t,Qn(e)));++s<o;)for(var c=0,a=n[s],h=e?e(a):a;(c=i(u,h,c,r))>-1;)u!==t&&Vt.call(u,c,1),Vt.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;ps(i)?Vt.call(t,i,1):ui(t,i)}}return t}function Kr(t,n){return t+pn(be()*(n-t+1))}function Hr(t,n){var e="";if(!t||n<1||n>u)return e;do{n%2&&(e+=t),(n=pn(n/2))&&(t+=t)}while(n);return e}function Vr(t,n){return $s(As(t,n,Zu),t+"")}function Qr(t){return Ye(Du(t))}function Yr(t,n){var e=Du(t);return Us(e,ir(n,0,e.length))}function Xr(n,e,r,i){if(!qo(n))return n;for(var s=-1,o=(e=vi(e,n)).length,u=o-1,c=n;null!=c&&++s<o;){var a=Is(e[s]),h=r;if("__proto__"===a||"constructor"===a||"prototype"===a)return n;if(s!=u){var l=c[a];(h=i?i(l,a,c):t)===t&&(h=qo(l)?l:ps(e[s+1])?[]:{})}Je(c,a,h),c=c[a]}return n}var qr=$e?function(t,n){return $e.set(t,n),t}:Zu,Gr=un?function(t,n){return un(t,"toString",{configurable:!0,enumerable:!1,value:qu(n),writable:!0})}:Zu;function Jr(t){return Us(Du(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 ar(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&&!iu(o)&&(e?o<=n:o<n)?r=s+1:i=s}return i}return ei(t,n,Zu,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,a=iu(e),h=e===t;s<o;){var l=pn((s+o)/2),f=r(n[l]),d=f!==t,p=null===f,v=f==f,w=iu(f);if(u)var y=i||v;else y=h?v&&(i||d):c?v&&d&&(i||!p):a?v&&d&&!p&&(i||!w):!p&&!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||!Do(u,c)){var c=u;s[i++]=0===o?0:o}}return s}function ii(t){return"number"==typeof t?t:iu(t)?c:+t}function si(t){if("string"==typeof t)return t;if(Lo(t))return Tn(t,si)+"";if(iu(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=$n,s=t.length,o=!0,u=[],c=u;if(e)o=!1,i=En;else if(s>=200){var a=n?null:Hi(t);if(a)return se(a);o=!1,i=Xn,c=new He}else c=n?[]:u;t:for(;++r<s;){var h=t[r],l=n?n(h):h;if(h=e||0!==h?h:0,o&&l==l){for(var f=c.length;f--;)if(c[f]===l)continue t;n&&c.push(l),u.push(h)}else i(c,l,e)||(c!==u&&c.push(l),u.push(h))}return u}function ui(t,n){var e=-1,r=(n=vi(n,t)).length;if(!r)return!0;for(var i=null==t||"object"!=typeof t&&"function"!=typeof t;++e<r;){var s=n[e];if("string"==typeof s){if("__proto__"===s&&!It.call(t,"__proto__"))return!1;if("constructor"===s&&e+1<r&&"string"==typeof n[e+1]&&"prototype"===n[e+1]){if(i&&0===e)continue;return!1}}}var o=xs(t,n);return null==o||delete o[Is(Hs(n))]}function ci(t,n,e,r){return Xr(t,n,e(mr(t,n)),r)}function ai(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 hi(t,n){var e=t;return e instanceof We&&(e=e.value()),jn(n,(function(t,n){return n.func.apply(n.thisArg,Un([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(pr(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 No(t)?t:[]}function pi(t){return"function"==typeof t?t:Zu}function vi(t,n){return Lo(t)?t:ws(t,n)?[t]:js(pu(t))}var wi=Vr;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 an.clearTimeout(t)};function bi(t,n){if(n)return t.slice();var e=t.length,r=Bt?Bt(e):new t.constructor(e);return t.copy(r),r}function mi(t){var n=new t.constructor(t.byteLength);return new Wt(n).set(new Wt(t)),n}function ki(t,n){var e=n?mi(t.buffer):t.buffer;return new t.constructor(e,t.byteOffset,t.length)}function Ai(n,e){if(n!==e){var r=n!==t,i=null===n,s=n==n,o=iu(n),u=e!==t,c=null===e,a=e==e,h=iu(e);if(!c&&!h&&!o&&n>e||o&&u&&a&&!c&&!h||i&&u&&a||!r&&a||!s)return 1;if(!i&&!o&&!h&&n<e||h&&r&&s&&!i&&!o||c&&r&&s||!u&&s||!a)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,a=ve(s-o,0),h=bt(c+a),l=!r;++u<c;)h[u]=n[u];for(;++i<o;)(l||i<s)&&(h[e[i]]=t[i]);for(;a--;)h[u++]=t[i++];return h}function Mi(t,n,e,r){for(var i=-1,s=t.length,o=-1,u=e.length,c=-1,a=n.length,h=ve(s-u,0),l=bt(h+a),f=!r;++i<h;)l[i]=t[i];for(var d=i;++c<a;)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],a=i?i(r[c],n[c],c,r,n):t;a===t&&(a=n[c]),s?er(r,c,a):Je(r,c,a)}return r}function $i(t,n){return function(e,r){var i=Lo(e)?An:tr,s=n?n():{};return i(e,t,is(r,2),s)}}function Ei(n){return Vr((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&&vs(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 Ti(t,n){return function(e,r){if(null==e)return e;if(!Bo(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 Ui(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 ji(n){return function(e){var r=ne(e=pu(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 Ii(t){return function(n){return jn(Qu(Fu(n).replace(Qt,"")),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 qo(r)?r:e}}function _i(n){return function(e,r,i){var s=Mt(e);if(!Bo(e)){var o=is(r,3);e=$u(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 zi(e){return Ji((function(r){var i=r.length,s=i,o=Le.prototype.thru;for(e&&r.reverse();s--;){var u=r[s];if("function"!=typeof u)throw new $t(n);if(o&&!c&&"wrapper"==es(u))var c=new Le([],!0)}for(s=c?s:i;++s<i;){var a=es(u=r[s]),h="wrapper"==a?ns(u):t;c=h&&ys(h[0])&&424==h[1]&&!h[4].length&&1==h[9]?c[es(h[0])].apply(c,h[3]):1==u.length&&ys(u)?c[a]():c.thru(u)}return function(){var t=arguments,n=t[0];if(c&&1==t.length&&Lo(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,a,h,l){var f=e&s,d=1&e,p=2&e,v=24&e,w=512&e,y=p?t:Oi(n);return function s(){for(var g=arguments.length,b=bt(g),m=g;m--;)b[m]=arguments[m];if(v)var k=rs(s),A=function(t,n){for(var e=t.length,r=0;e--;)t[e]===n&&++r;return r}(b,k);if(i&&(b=xi(b,i,o,v)),u&&(b=Mi(b,u,c,v)),g-=A,v&&g<l){var x=ie(b,k);return Ni(n,e,Di,s.placeholder,r,b,x,a,h,l-g)}var M=d?r:this,S=p?M[n]:n;return g=b.length,a?b=function(n,e){for(var r=n.length,i=we(e.length,r),s=Si(n);i--;){var o=e[i];n[i]=ps(o,r)?s[o]:t}return n}(b,a):w&&g>1&&b.reverse(),f&&h<g&&(b.length=h),this&&this!==an&&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 Fi(t){return Ji((function(n){return n=Tn(n,Qn(is())),Vr((function(e){var r=this;return t(n,(function(t){return kn(t,r,e)}))}))}))}function Li(n,e){var r=(e=e===t?" ":si(e)).length;if(r<2)return r?Hr(e,n):e;var i=Hr(e,dn(n/ue(e)));return ne(e)?yi(ce(i),0,n).join(""):i.slice(0,n)}function Wi(n){return function(e,r,i){return i&&"number"!=typeof i&&vs(e,r,i)&&(r=i=t),e=au(e),r===t?(r=e,e=0):r=au(r),function(t,n,e,r){for(var i=-1,s=ve(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:au(i),n)}}function Bi(t){return function(n,e){return"string"==typeof n&&"string"==typeof e||(n=fu(n),e=fu(e)),t(n,e)}}function Ni(n,e,r,s,o,u,c,a,h,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,a,h,l],p=r.apply(t,d);return ys(n)&&Ss(p,d),p.placeholder=s,Es(p,n,e)}function Ki(t){var n=xt[t];return function(t,e){if(t=fu(t),(e=null==e?0:we(hu(e),292))&&fe(t)){var r=(pu(t)+"e").split("e");return+((r=(pu(n(r[0]+"e"+(+r[1]+e)))+"e").split("e"))[0]+"e"+(+r[1]-e))}return n(t)}}var Hi=Me&&1/se(new Me([,-0]))[1]==o?function(t){return new Me(t)}:ic;function Vi(t){return function(n){var e=hs(n);return e==g?ee(n):e==x?oe(n):function(t,n){return Tn(n,(function(n){return[n,t[n]]}))}(n,t(n))}}function Qi(e,o,u,c,a,h,l,f){var d=2&o;if(!d&&"function"!=typeof e)throw new $t(n);var p=c?c.length:0;if(p||(o&=-97,c=a=t),l=l===t?l:ve(hu(l),0),f=f===t?f:hu(f),p-=a?a.length:0,64&o){var v=c,w=a;c=a=t}var y=d?t:ns(e),g=[e,o,u,c,a,v,w,h,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],a=g[4],!(f=g[9]=g[9]===t?d?0:e.length:ve(g[9]-p,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,a=rs(s);c--;)u[c]=arguments[c];var h=o<3&&u[0]!==a&&u[o-1]!==a?[]:ie(u,a);return(o-=h.length)<r?Ni(n,e,Di,s.placeholder,t,u,h,t,t,r-o):kn(this&&this!==an&&this instanceof s?i:n,this,u)}}(e,o,f):o!=i&&33!=o||a.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,a=r.length,h=bt(a+u),l=this&&this!==an&&this instanceof n?s:t;++c<a;)h[c]=r[c];for(;u--;)h[c++]=arguments[++o];return kn(l,i?e:this,h)}}(e,o,u,c);else var b=function(t,n,e){var r=1&n,i=Oi(t);return function n(){return(this&&this!==an&&this instanceof n?i:t).apply(r?e:this,arguments)}}(e,o,u);return Es((y?qr:Ss)(b,g),e,o)}function Yi(n,e,r,i){return n===t||Do(n,Tt[r])&&!It.call(i,r)?e:n}function Xi(n,e,r,i,s,o){return qo(n)&&qo(e)&&(o.set(e,n),Rr(n,e,t,Xi,o),o.delete(e)),n}function qi(n){return tu(n)?t:n}function Gi(n,e,r,i,s,o){var u=1&r,c=n.length,a=e.length;if(c!=a&&!(u&&a>c))return!1;var h=o.get(n),l=o.get(e);if(h&&l)return h==e&&l==n;var f=-1,d=!0,p=2&r?new He:t;for(o.set(n,e),o.set(e,n);++f<c;){var v=n[f],w=e[f];if(i)var y=u?i(w,v,f,e,n,o):i(v,w,f,n,e,o);if(y!==t){if(y)continue;d=!1;break}if(p){if(!On(e,(function(t,n){if(!Xn(p,n)&&(v===t||s(v,t,r,i,o)))return p.push(n)}))){d=!1;break}}else if(v!==w&&!s(v,w,r,i,o)){d=!1;break}}return o.delete(n),o.delete(e),d}function Ji(n){return $s(As(n,t,Ls),n+"")}function Zi(t){return kr(t,$u,cs)}function ts(t){return kr(t,Eu,as)}var ns=$e?function(t){return $e.get(t)}:ic;function es(t){for(var n=t.name+"",e=Ee[n],r=It.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(It.call(Pe,"placeholder")?Pe:t).placeholder}function is(){var t=Pe.iteratee||tc;return t=t===tc?Ir: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=$u(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 jr(r)?r:t}var cs=_n?function(t){return null==t?[]:(t=Mt(t),Cn(_n(t),(function(n){return Ht.call(t,n)})))}:lc,as=_n?function(t){for(var n=[];t;)Un(n,cs(t)),t=Nt(t);return n}:lc,hs=Ar;function ls(t,n,e){for(var r=-1,i=(n=vi(n,t)).length,s=!1;++r<i;){var o=Is(n[r]);if(!(s=null!=t&&e(t,o)))break;t=t[o]}return s||++r!=i?s:!!(i=null==t?0:t.length)&&Xo(i)&&ps(o,i)&&(Lo(t)||Fo(t))}function fs(t){return"function"!=typeof t.constructor||bs(t)?{}:Re(Nt(t))}function ds(t){return Lo(t)||Fo(t)||!!(Xt&&t&&t[Xt])}function ps(t,n){var e=typeof t;return!!(n=null==n?u:n)&&("number"==e||"symbol"!=e&&pt.test(t))&&t>-1&&t%1==0&&t<n}function vs(t,n,e){if(!qo(e))return!1;var r=typeof n;return!!("number"==r?Bo(e)&&ps(n,e.length):"string"==r&&n in e)&&Do(e[n],t)}function ws(t,n){if(Lo(t))return!1;var e=typeof t;return!("number"!=e&&"symbol"!=e&&"boolean"!=e&&null!=t&&!iu(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 We.prototype))return!1;if(t===e)return!0;var r=ns(e);return!!r&&t===r[0]}(ke&&hs(new ke(new ArrayBuffer(1)))!=E||Ae&&hs(new Ae)!=g||xe&&hs(xe.resolve())!=k||Me&&hs(new Me)!=x||Se&&hs(new Se)!=C)&&(hs=function(n){var e=Ar(n),r=e==m?n.constructor:t,i=r?Os(r):"";if(i)switch(i){case Te:return E;case Ue:return g;case je:return k;case Ie:return x;case Oe:return C}return e});var gs=Ut?Qo:fc;function bs(t){var n=t&&t.constructor;return t===("function"==typeof n&&n.prototype||Tt)}function ms(t){return t==t&&!qo(t)}function ks(n,e){return function(r){return null!=r&&r[n]===e&&(e!==t||n in Mt(r))}}function As(n,e,r){return e=ve(e===t?n.length-1:e,0),function(){for(var t=arguments,i=-1,s=ve(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),kn(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=Ts(qr),Cs=ln||function(t,n){return an.setTimeout(t,n)},$s=Ts(Gr);function Es(t,n,e){var r=n+"";return $s(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(h,(function(e){var r="_."+e[0];n&e[1]&&!$n(t,r)&&t.push(r)})),t.sort()}(function(t){var n=t.match(rt);return n?n[1].split(it):[]}(r),e)))}function Ts(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 Us(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 js=function(){var t=Uo((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===n.size&&n.clear(),t})),n=t.cache;return t}();function Is(t){if("string"==typeof t||iu(t))return t;var n=t+"";return"0"==n&&1/t==-1/0?"-0":n}function Os(t){if(null!=t){try{return jt.call(t)}catch(t){}try{return t+""}catch(t){}}return""}function _s(t){if(t instanceof We)return t.clone();var n=new Le(t.__wrapped__,t.__chain__);return n.__actions__=Si(t.__actions__),n.__index__=t.__index__,n.__values__=t.__values__,n}var zs=Vr((function(t,n){return No(t)?cr(t,pr(n,1,No,!0)):[]})),Ds=Vr((function(n,e){var r=Hs(e);return No(r)&&(r=t),No(n)?cr(n,pr(e,1,No,!0),is(r,2)):[]})),Ps=Vr((function(n,e){var r=Hs(e);return No(r)&&(r=t),No(n)?cr(n,pr(e,1,No,!0),t,r):[]}));function Rs(t,n,e){var r=null==t?0:t.length;if(!r)return-1;var i=null==e?0:hu(e);return i<0&&(i=ve(r+i,0)),Dn(t,is(n,3),i)}function Fs(n,e,r){var i=null==n?0:n.length;if(!i)return-1;var s=i-1;return r!==t&&(s=hu(r),s=r<0?ve(i+s,0):we(s,i-1)),Dn(n,is(e,3),s,!0)}function Ls(t){return null!=t&&t.length?pr(t,1):[]}function Ws(n){return n&&n.length?n[0]:t}var Bs=Vr((function(t){var n=Tn(t,di);return n.length&&n[0]===t[0]?Cr(n):[]})),Ns=Vr((function(n){var e=Hs(n),r=Tn(n,di);return e===Hs(r)?e=t:r.pop(),r.length&&r[0]===n[0]?Cr(r,is(e,2)):[]})),Ks=Vr((function(n){var e=Hs(n),r=Tn(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=Vr(Qs);function Qs(t,n){return t&&t.length&&n&&n.length?Br(t,n):t}var Ys=Ji((function(t,n){var e=null==t?0:t.length,r=rr(t,n);return Nr(t,Tn(n,(function(t){return ps(t,e)?+t:t})).sort(Ai)),r}));function Xs(t){return null==t?t:me.call(t)}var qs=Vr((function(t){return oi(pr(t,1,No,!0))})),Gs=Vr((function(n){var e=Hs(n);return No(e)&&(e=t),oi(pr(n,1,No,!0),is(e,2))})),Js=Vr((function(n){var e=Hs(n);return e="function"==typeof e?e:t,oi(pr(n,1,No,!0),t,e)}));function Zs(t){if(!t||!t.length)return[];var n=0;return t=Cn(t,(function(t){if(No(t))return n=ve(t.length,n),!0})),Hn(n,(function(n){return Tn(t,Wn(n))}))}function to(n,e){if(!n||!n.length)return[];var r=Zs(n);return null==e?r:Tn(r,(function(n){return kn(e,t,n)}))}var no=Vr((function(t,n){return No(t)?cr(t,n):[]})),eo=Vr((function(t){return li(Cn(t,No))})),ro=Vr((function(n){var e=Hs(n);return No(e)&&(e=t),li(Cn(n,No),is(e,2))})),io=Vr((function(n){var e=Hs(n);return e="function"==typeof e?e:t,li(Cn(n,No),t,e)})),so=Vr(Zs),oo=Vr((function(n){var e=n.length,r=e>1?n[e-1]:t;return r="function"==typeof r?(n.pop(),r):t,to(n,r)}));function uo(t){var n=Pe(t);return n.__chain__=!0,n}function co(t,n){return n(t)}var ao=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 We&&ps(r)?((i=i.slice(r,+r+(e?1:0))).__actions__.push({func:co,args:[s],thisArg:t}),new Le(i,this.__chain__).thru((function(n){return e&&!n.length&&n.push(t),n}))):this.thru(s)})),ho=$i((function(t,n,e){It.call(t,e)?++t[e]:er(t,e,1)})),lo=_i(Rs),fo=_i(Fs);function po(t,n){return(Lo(t)?xn:ar)(t,is(n,3))}function vo(t,n){return(Lo(t)?Mn:hr)(t,is(n,3))}var wo=$i((function(t,n,e){It.call(t,e)?t[e].push(n):er(t,e,[n])})),yo=Vr((function(t,n,e){var r=-1,i="function"==typeof n,s=Bo(t)?bt(t.length):[];return ar(t,(function(t){s[++r]=i?kn(n,t,e):$r(t,n,e)})),s})),go=$i((function(t,n,e){er(t,e,n)}));function bo(t,n){return(Lo(t)?Tn:zr)(t,is(n,3))}var mo=$i((function(t,n,e){t[e?0:1].push(n)}),(function(){return[[],[]]})),ko=Vr((function(t,n){if(null==t)return[];var e=n.length;return e>1&&vs(t,n[0],n[1])?n=[]:e>2&&vs(n[0],n[1],n[2])&&(n=[n[0]]),Lr(t,pr(n,1),[])})),Ao=hn||function(){return an.Date.now()};function xo(n,e,r){return e=r?t:e,Qi(n,s,t,t,t,t,e=n&&null==e?n.length:e)}function Mo(e,r){var i;if("function"!=typeof r)throw new $t(n);return e=hu(e),function(){return--e>0&&(i=r.apply(this,arguments)),e<=1&&(r=t),i}}var So=Vr((function(t,n,e){var r=1;if(e.length){var s=ie(e,rs(So));r|=i}return Qi(t,r,n,e,s)})),Co=Vr((function(t,n,e){var r=3;if(e.length){var s=ie(e,rs(Co));r|=i}return Qi(n,r,t,e,s)}));function $o(e,r,i){var s,o,u,c,a,h,l=0,f=!1,d=!1,p=!0;if("function"!=typeof e)throw new $t(n);function v(n){var r=s,i=o;return s=o=t,l=n,c=e.apply(i,r)}function w(n){var e=n-h;return h===t||e>=r||e<0||d&&n-l>=u}function y(){var t=Ao();if(w(t))return g(t);a=Cs(y,function(t){var n=r-(t-h);return d?we(n,u-(t-l)):n}(t))}function g(n){return a=t,p&&s?v(n):(s=o=t,c)}function b(){var n=Ao(),e=w(n);if(s=arguments,o=this,h=n,e){if(a===t)return function(t){return l=t,a=Cs(y,r),f?v(t):c}(h);if(d)return gi(a),a=Cs(y,r),v(h)}return a===t&&(a=Cs(y,r)),c}return r=fu(r)||0,qo(i)&&(f=!!i.leading,u=(d="maxWait"in i)?ve(fu(i.maxWait)||0,r):u,p="trailing"in i?!!i.trailing:p),b.cancel=function(){a!==t&&gi(a),l=0,s=h=o=a=t},b.flush=function(){return a===t?c:g(Ao())},b}var Eo=Vr((function(t,n){return ur(t,1,n)})),To=Vr((function(t,n,e){return ur(t,fu(n)||0,e)}));function Uo(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new $t(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(Uo.Cache||Ke),r}function jo(t){if("function"!=typeof t)throw new $t(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)}}Uo.Cache=Ke;var Io=wi((function(t,n){var e=(n=1==n.length&&Lo(n[0])?Tn(n[0],Qn(is())):Tn(pr(n,1),Qn(is()))).length;return Vr((function(r){for(var i=-1,s=we(r.length,e);++i<s;)r[i]=n[i].call(this,r[i]);return kn(t,this,r)}))})),Oo=Vr((function(n,e){var r=ie(e,rs(Oo));return Qi(n,i,t,e,r)})),_o=Vr((function(n,e){var r=ie(e,rs(_o));return Qi(n,64,t,e,r)})),zo=Ji((function(n,e){return Qi(n,256,t,t,t,e)}));function Do(t,n){return t===n||t!=t&&n!=n}var Po=Bi(xr),Ro=Bi((function(t,n){return t>=n})),Fo=Er(function(){return arguments}())?Er:function(t){return Go(t)&&It.call(t,"callee")&&!Ht.call(t,"callee")},Lo=bt.isArray,Wo=vn?Qn(vn):function(t){return Go(t)&&Ar(t)==$};function Bo(t){return null!=t&&Xo(t.length)&&!Qo(t)}function No(t){return Go(t)&&Bo(t)}var Ko=Bn||fc,Ho=wn?Qn(wn):function(t){return Go(t)&&Ar(t)==p};function Vo(t){if(!Go(t))return!1;var n=Ar(t);return n==v||"[object DOMException]"==n||"string"==typeof t.message&&"string"==typeof t.name&&!tu(t)}function Qo(t){if(!qo(t))return!1;var n=Ar(t);return n==w||n==y||"[object AsyncFunction]"==n||"[object Proxy]"==n}function Yo(t){return"number"==typeof t&&t==hu(t)}function Xo(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=u}function qo(t){var n=typeof t;return null!=t&&("object"==n||"function"==n)}function Go(t){return null!=t&&"object"==typeof t}var Jo=yn?Qn(yn):function(t){return Go(t)&&hs(t)==g};function Zo(t){return"number"==typeof t||Go(t)&&Ar(t)==b}function tu(t){if(!Go(t)||Ar(t)!=m)return!1;var n=Nt(t);if(null===n)return!0;var e=It.call(n,"constructor")&&n.constructor;return"function"==typeof e&&e instanceof e&&jt.call(e)==Dt}var nu=gn?Qn(gn):function(t){return Go(t)&&Ar(t)==A},eu=bn?Qn(bn):function(t){return Go(t)&&hs(t)==x};function ru(t){return"string"==typeof t||!Lo(t)&&Go(t)&&Ar(t)==M}function iu(t){return"symbol"==typeof t||Go(t)&&Ar(t)==S}var su=mn?Qn(mn):function(t){return Go(t)&&Xo(t.length)&&!!nn[Ar(t)]},ou=Bi(_r),uu=Bi((function(t,n){return t<=n}));function cu(t){if(!t)return[];if(Bo(t))return ru(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=hs(t);return(n==g?ee:n==x?se:Du)(t)}function au(t){return t?(t=fu(t))===o||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0}function hu(t){var n=au(t),e=n%1;return n==n?e?n-e:n:0}function lu(t){return t?ir(hu(t),0,a):0}function fu(t){if("number"==typeof t)return t;if(iu(t))return c;if(qo(t)){var n="function"==typeof t.valueOf?t.valueOf():t;t=qo(n)?n+"":n}if("string"!=typeof t)return 0===t?t:+t;t=Vn(t);var e=lt.test(t);return e||dt.test(t)?on(t.slice(2),e?2:8):ht.test(t)?c:+t}function du(t){return Ci(t,Eu(t))}function pu(t){return null==t?"":si(t)}var vu=Ei((function(t,n){if(bs(n)||Bo(n))Ci(n,$u(n),t);else for(var e in n)It.call(n,e)&&Je(t,e,n[e])})),wu=Ei((function(t,n){Ci(n,Eu(n),t)})),yu=Ei((function(t,n,e,r){Ci(n,Eu(n),t,r)})),gu=Ei((function(t,n,e,r){Ci(n,$u(n),t,r)})),bu=Ji(rr),mu=Vr((function(n,e){n=Mt(n);var r=-1,i=e.length,s=i>2?e[2]:t;for(s&&vs(e[0],e[1],s)&&(i=1);++r<i;)for(var o=e[r],u=Eu(o),c=-1,a=u.length;++c<a;){var h=u[c],l=n[h];(l===t||Do(l,Tt[h])&&!It.call(n,h))&&(n[h]=o[h])}return n})),ku=Vr((function(n){return n.push(t,Xi),kn(Uu,t,n)}));function Au(n,e,r){var i=null==n?t:mr(n,e);return i===t?r:i}function xu(t,n){return null!=t&&ls(t,n,Sr)}var Mu=Pi((function(t,n,e){null!=n&&"function"!=typeof n.toString&&(n=zt.call(n)),t[n]=e}),qu(Zu)),Su=Pi((function(t,n,e){null!=n&&"function"!=typeof n.toString&&(n=zt.call(n)),It.call(t,n)?t[n].push(e):t[n]=[e]}),is),Cu=Vr($r);function $u(t){return Bo(t)?Qe(t):Or(t)}function Eu(t){return Bo(t)?Qe(t,!0):function(t){if(!qo(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&&It.call(t,r))&&e.push(r);return e}(t)}var Tu=Ei((function(t,n,e){Rr(t,n,e)})),Uu=Ei((function(t,n,e,r){Rr(t,n,e,r)})),ju=Ji((function(t,n){var e={};if(null==t)return e;var r=!1;n=Tn(n,(function(n){return n=vi(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})),Iu=Ji((function(t,n){return null==t?{}:function(t,n){return Wr(t,n,(function(n,e){return xu(t,e)}))}(t,n)}));function Ou(t,n){if(null==t)return{};var e=Tn(ts(t),(function(t){return[t]}));return n=is(n),Wr(t,e,(function(t,e){return n(t,e[0])}))}var _u=Vi($u),zu=Vi(Eu);function Du(t){return null==t?[]:Yn(t,$u(t))}var Pu=Ii((function(t,n,e){return n=n.toLowerCase(),t+(e?Ru(n):n)}));function Ru(t){return Vu(pu(t).toLowerCase())}function Fu(t){return(t=pu(t))&&t.replace(vt,Jn).replace(Yt,"")}var Lu=Ii((function(t,n,e){return t+(e?"-":"")+n.toLowerCase()})),Wu=Ii((function(t,n,e){return t+(e?" ":"")+n.toLowerCase()})),Bu=ji("toLowerCase"),Nu=Ii((function(t,n,e){return t+(e?"_":"")+n.toLowerCase()})),Ku=Ii((function(t,n,e){return t+(e?" ":"")+Vu(n)})),Hu=Ii((function(t,n,e){return t+(e?" ":"")+n.toUpperCase()})),Vu=ji("toUpperCase");function Qu(n,e,r){return n=pu(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 Yu=Vr((function(n,e){try{return kn(n,t,e)}catch(t){return Vo(t)?t:new kt(t)}})),Xu=Ji((function(t,n){return xn(n,(function(n){n=Is(n),er(t,n,So(t[n],t))})),t}));function qu(t){return function(){return t}}var Gu=zi(),Ju=zi(!0);function Zu(t){return t}function tc(t){return Ir("function"==typeof t?t:sr(t,1))}var nc=Vr((function(t,n){return function(e){return $r(e,t,n)}})),ec=Vr((function(t,n){return function(e){return $r(t,e,n)}}));function rc(t,n,e){var r=$u(n),i=br(n,r);null!=e||qo(n)&&(i.length||!r.length)||(e=n,n=t,t=this,i=br(n,$u(n)));var s=!(qo(e)&&"chain"in e&&!e.chain),o=Qo(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,Un([this.value()],arguments))})})),t}function ic(){}var sc=Fi(Tn),oc=Fi(Sn),uc=Fi(On);function cc(t){return ws(t)?Wn(Is(t)):function(t){return function(n){return mr(n,t)}}(t)}var ac=Wi(),hc=Wi(!0);function lc(){return[]}function fc(){return!1}var dc,pc=Ri((function(t,n){return t+n}),0),vc=Ki("ceil"),wc=Ri((function(t,n){return t/n}),1),yc=Ki("floor"),gc=Ri((function(t,n){return t*n}),1),bc=Ki("round"),mc=Ri((function(t,n){return t-n}),0);return Pe.after=function(t,e){if("function"!=typeof e)throw new $t(n);return t=hu(t),function(){if(--t<1)return e.apply(this,arguments)}},Pe.ary=xo,Pe.assign=vu,Pe.assignIn=wu,Pe.assignInWith=yu,Pe.assignWith=gu,Pe.at=bu,Pe.before=Mo,Pe.bind=So,Pe.bindAll=Xu,Pe.bindKey=Co,Pe.castArray=function(){if(!arguments.length)return[];var t=arguments[0];return Lo(t)?t:[t]},Pe.chain=uo,Pe.chunk=function(n,e,r){e=(r?vs(n,e,r):e===t)?1:ve(hu(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 Un(Lo(e)?Si(e):[e],pr(n,1))},Pe.cond=function(t){var e=null==t?0:t.length,r=is();return t=e?Tn(t,(function(t){if("function"!=typeof t[1])throw new $t(n);return[r(t[0]),t[1]]})):[],Vr((function(n){for(var r=-1;++r<e;){var i=t[r];if(kn(i[0],this,n))return kn(i[1],this,n)}}))},Pe.conforms=function(t){return function(t){var n=$u(t);return function(e){return or(e,t,n)}}(sr(t,1))},Pe.constant=qu,Pe.countBy=ho,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=Qi(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=Qi(e,16,t,t,t,t,t,r=i?t:r);return s.placeholder=n.placeholder,s},Pe.debounce=$o,Pe.defaults=mu,Pe.defaultsDeep=ku,Pe.defer=Eo,Pe.delay=To,Pe.difference=zs,Pe.differenceBy=Ds,Pe.differenceWith=Ps,Pe.drop=function(n,e,r){var i=null==n?0:n.length;return i?Zr(n,(e=r||e===t?1:hu(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:hu(e)))<0?0:e):[]},Pe.dropRightWhile=function(t,n){return t&&t.length?ai(t,is(n,3),!0,!0):[]},Pe.dropWhile=function(t,n){return t&&t.length?ai(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&&vs(n,e,r)&&(r=0,i=s),function(n,e,r,i){var s=n.length;for((r=hu(r))<0&&(r=-r>s?0:s+r),(i=i===t||i>s?s:hu(i))<0&&(i+=s),i=r>i?0:lu(i);r<i;)n[r++]=e;return n}(n,e,r,i)):[]},Pe.filter=function(t,n){return(Lo(t)?Cn:dr)(t,is(n,3))},Pe.flatMap=function(t,n){return pr(bo(t,n),1)},Pe.flatMapDeep=function(t,n){return pr(bo(t,n),o)},Pe.flatMapDepth=function(n,e,r){return r=r===t?1:hu(r),pr(bo(n,e),r)},Pe.flatten=Ls,Pe.flattenDeep=function(t){return null!=t&&t.length?pr(t,o):[]},Pe.flattenDepth=function(n,e){return null!=n&&n.length?pr(n,e=e===t?1:hu(e)):[]},Pe.flip=function(t){return Qi(t,512)},Pe.flow=Gu,Pe.flowRight=Ju,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,$u(t))},Pe.functionsIn=function(t){return null==t?[]:br(t,Eu(t))},Pe.groupBy=wo,Pe.initial=function(t){return null!=t&&t.length?Zr(t,0,-1):[]},Pe.intersection=Bs,Pe.intersectionBy=Ns,Pe.intersectionWith=Ks,Pe.invert=Mu,Pe.invertBy=Su,Pe.invokeMap=yo,Pe.iteratee=tc,Pe.keyBy=go,Pe.keys=$u,Pe.keysIn=Eu,Pe.map=bo,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=Uo,Pe.merge=Tu,Pe.mergeWith=Uu,Pe.method=nc,Pe.methodOf=ec,Pe.mixin=rc,Pe.negate=jo,Pe.nthArg=function(t){return t=hu(t),Vr((function(n){return Fr(n,t)}))},Pe.omit=ju,Pe.omitBy=function(t,n){return Ou(t,jo(is(n)))},Pe.once=function(t){return Mo(2,t)},Pe.orderBy=function(n,e,r,i){return null==n?[]:(Lo(e)||(e=null==e?[]:[e]),Lo(r=i?t:r)||(r=null==r?[]:[r]),Lr(n,e,r))},Pe.over=sc,Pe.overArgs=Io,Pe.overEvery=oc,Pe.overSome=uc,Pe.partial=Oo,Pe.partialRight=_o,Pe.partition=mo,Pe.pick=Iu,Pe.pickBy=Ou,Pe.property=cc,Pe.propertyOf=function(n){return function(e){return null==n?t:mr(n,e)}},Pe.pull=Vs,Pe.pullAll=Qs,Pe.pullAllBy=function(t,n,e){return t&&t.length&&n&&n.length?Br(t,n,is(e,2)):t},Pe.pullAllWith=function(n,e,r){return n&&n.length&&e&&e.length?Br(n,e,t,r):n},Pe.pullAt=Ys,Pe.range=ac,Pe.rangeRight=hc,Pe.rearg=zo,Pe.reject=function(t,n){return(Lo(t)?Cn:dr)(t,jo(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 $t(n);return Vr(e,r=r===t?r:hu(r))},Pe.reverse=Xs,Pe.sampleSize=function(n,e,r){return e=(r?vs(n,e,r):e===t)?1:hu(e),(Lo(n)?Xe:Yr)(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(Lo(t)?qe:Jr)(t)},Pe.slice=function(n,e,r){var i=null==n?0:n.length;return i?(r&&"number"!=typeof r&&vs(n,e,r)?(e=0,r=i):(e=null==e?0:hu(e),r=r===t?i:hu(r)),Zr(n,e,r)):[]},Pe.sortBy=ko,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&&vs(n,e,r)&&(e=r=t),(r=r===t?a:r>>>0)?(n=pu(n))&&("string"==typeof e||null!=e&&!nu(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 $t(n);return e=null==e?0:ve(hu(e),0),Vr((function(n){var r=n[e],i=yi(n,0,e);return r&&Un(i,r),kn(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:hu(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:hu(e)))<0?0:e,i):[]},Pe.takeRightWhile=function(t,n){return t&&t.length?ai(t,is(n,3),!1,!0):[]},Pe.takeWhile=function(t,n){return t&&t.length?ai(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 $t(n);return qo(r)&&(i="leading"in r?!!r.leading:i,s="trailing"in r?!!r.trailing:s),$o(t,e,{leading:i,maxWait:e,trailing:s})},Pe.thru=co,Pe.toArray=cu,Pe.toPairs=_u,Pe.toPairsIn=zu,Pe.toPath=function(t){return Lo(t)?Tn(t,Is):iu(t)?[t]:Si(js(pu(t)))},Pe.toPlainObject=du,Pe.transform=function(t,n,e){var r=Lo(t),i=r||Ko(t)||su(t);if(n=is(n,4),null==e){var s=t&&t.constructor;e=i?r?new s:[]:qo(t)&&Qo(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 xo(t,1)},Pe.union=qs,Pe.unionBy=Gs,Pe.unionWith=Js,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=Zs,Pe.unzipWith=to,Pe.update=function(t,n,e){return null==t?t:ci(t,n,pi(e))},Pe.updateWith=function(n,e,r,i){return i="function"==typeof i?i:t,null==n?n:ci(n,e,pi(r),i)},Pe.values=Du,Pe.valuesIn=function(t){return null==t?[]:Yn(t,Eu(t))},Pe.without=no,Pe.words=Qu,Pe.wrap=function(t,n){return Oo(pi(n),t)},Pe.xor=eo,Pe.xorBy=ro,Pe.xorWith=io,Pe.zip=so,Pe.zipObject=function(t,n){return fi(t||[],n||[],Je)},Pe.zipObjectDeep=function(t,n){return fi(t||[],n||[],Xr)},Pe.zipWith=oo,Pe.entries=_u,Pe.entriesIn=zu,Pe.extend=wu,Pe.extendWith=yu,rc(Pe,Pe),Pe.add=pc,Pe.attempt=Yu,Pe.camelCase=Pu,Pe.capitalize=Ru,Pe.ceil=vc,Pe.clamp=function(n,e,r){return r===t&&(r=e,e=t),r!==t&&(r=(r=fu(r))==r?r:0),e!==t&&(e=(e=fu(e))==e?e:0),ir(fu(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,$u(n))},Pe.deburr=Fu,Pe.defaultTo=function(t,n){return null==t||t!=t?n:t},Pe.divide=wc,Pe.endsWith=function(n,e,r){n=pu(n),e=si(e);var i=n.length,s=r=r===t?i:ir(hu(r),0,i);return(r-=e.length)>=0&&n.slice(r,s)==e},Pe.eq=Do,Pe.escape=function(t){return(t=pu(t))&&H.test(t)?t.replace(N,Zn):t},Pe.escapeRegExp=function(t){return(t=pu(t))&&Z.test(t)?t.replace(J,"\\$&"):t},Pe.every=function(n,e,r){var i=Lo(n)?Sn:lr;return r&&vs(n,e,r)&&(e=t),i(n,is(e,3))},Pe.find=lo,Pe.findIndex=Rs,Pe.findKey=function(t,n){return zn(t,is(n,3),yr)},Pe.findLast=fo,Pe.findLastIndex=Fs,Pe.findLastKey=function(t,n){return zn(t,is(n,3),gr)},Pe.floor=yc,Pe.forEach=po,Pe.forEachRight=vo,Pe.forIn=function(t,n){return null==t?t:vr(t,is(n,3),Eu)},Pe.forInRight=function(t,n){return null==t?t:wr(t,is(n,3),Eu)},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=Au,Pe.gt=Po,Pe.gte=Ro,Pe.has=function(t,n){return null!=t&&ls(t,n,Mr)},Pe.hasIn=xu,Pe.head=Ws,Pe.identity=Zu,Pe.includes=function(t,n,e,r){t=Bo(t)?t:Du(t),e=e&&!r?hu(e):0;var i=t.length;return e<0&&(e=ve(i+e,0)),ru(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:hu(e);return i<0&&(i=ve(r+i,0)),Pn(t,n,i)},Pe.inRange=function(n,e,r){return e=au(e),r===t?(r=e,e=0):r=au(r),function(t,n,e){return t>=we(n,e)&&t<ve(n,e)}(n=fu(n),e,r)},Pe.invoke=Cu,Pe.isArguments=Fo,Pe.isArray=Lo,Pe.isArrayBuffer=Wo,Pe.isArrayLike=Bo,Pe.isArrayLikeObject=No,Pe.isBoolean=function(t){return!0===t||!1===t||Go(t)&&Ar(t)==d},Pe.isBuffer=Ko,Pe.isDate=Ho,Pe.isElement=function(t){return Go(t)&&1===t.nodeType&&!tu(t)},Pe.isEmpty=function(t){if(null==t)return!0;if(Bo(t)&&(Lo(t)||"string"==typeof t||"function"==typeof t.splice||Ko(t)||su(t)||Fo(t)))return!t.length;var n=hs(t);if(n==g||n==x)return!t.size;if(bs(t))return!Or(t).length;for(var e in t)if(It.call(t,e))return!1;return!0},Pe.isEqual=function(t,n){return Tr(t,n)},Pe.isEqualWith=function(n,e,r){var i=(r="function"==typeof r?r:t)?r(n,e):t;return i===t?Tr(n,e,t,r):!!i},Pe.isError=Vo,Pe.isFinite=function(t){return"number"==typeof t&&fe(t)},Pe.isFunction=Qo,Pe.isInteger=Yo,Pe.isLength=Xo,Pe.isMap=Jo,Pe.isMatch=function(t,n){return t===n||Ur(t,n,os(n))},Pe.isMatchWith=function(n,e,r){return r="function"==typeof r?r:t,Ur(n,e,os(e),r)},Pe.isNaN=function(t){return Zo(t)&&t!=+t},Pe.isNative=function(t){if(gs(t))throw new kt("Unsupported core-js use. Try https://npms.io/search?q=ponyfill.");return jr(t)},Pe.isNil=function(t){return null==t},Pe.isNull=function(t){return null===t},Pe.isNumber=Zo,Pe.isObject=qo,Pe.isObjectLike=Go,Pe.isPlainObject=tu,Pe.isRegExp=nu,Pe.isSafeInteger=function(t){return Yo(t)&&t>=-9007199254740991&&t<=u},Pe.isSet=eu,Pe.isString=ru,Pe.isSymbol=iu,Pe.isTypedArray=su,Pe.isUndefined=function(n){return n===t},Pe.isWeakMap=function(t){return Go(t)&&hs(t)==C},Pe.isWeakSet=function(t){return Go(t)&&"[object WeakSet]"==Ar(t)},Pe.join=function(t,n){return null==t?"":de.call(t,n)},Pe.kebabCase=Lu,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=hu(r))<0?ve(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,Fn,s,!0)},Pe.lowerCase=Wu,Pe.lowerFirst=Bu,Pe.lt=ou,Pe.lte=uu,Pe.max=function(n){return n&&n.length?fr(n,Zu,xr):t},Pe.maxBy=function(n,e){return n&&n.length?fr(n,is(e,2),xr):t},Pe.mean=function(t){return Ln(t,Zu)},Pe.meanBy=function(t,n){return Ln(t,is(n,2))},Pe.min=function(n){return n&&n.length?fr(n,Zu,_r):t},Pe.minBy=function(n,e){return n&&n.length?fr(n,is(e,2),_r):t},Pe.stubArray=lc,Pe.stubFalse=fc,Pe.stubObject=function(){return{}},Pe.stubString=function(){return""},Pe.stubTrue=function(){return!0},Pe.multiply=gc,Pe.nth=function(n,e){return n&&n.length?Fr(n,hu(e)):t},Pe.noConflict=function(){return an._===this&&(an._=Pt),this},Pe.noop=ic,Pe.now=Ao,Pe.pad=function(t,n,e){t=pu(t);var r=(n=hu(n))?ue(t):0;if(!n||r>=n)return t;var i=(n-r)/2;return Li(pn(i),e)+t+Li(dn(i),e)},Pe.padEnd=function(t,n,e){t=pu(t);var r=(n=hu(n))?ue(t):0;return n&&r<n?t+Li(n-r,e):t},Pe.padStart=function(t,n,e){t=pu(t);var r=(n=hu(n))?ue(t):0;return n&&r<n?Li(n-r,e)+t:t},Pe.parseInt=function(t,n,e){return e||null==n?n=0:n&&(n=+n),ge(pu(t).replace(tt,""),n||0)},Pe.random=function(n,e,r){if(r&&"boolean"!=typeof r&&vs(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=au(n),e===t?(e=n,n=0):e=au(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=Lo(t)?jn:Nn,i=arguments.length<3;return r(t,is(n,4),e,i,ar)},Pe.reduceRight=function(t,n,e){var r=Lo(t)?In:Nn,i=arguments.length<3;return r(t,is(n,4),e,i,hr)},Pe.repeat=function(n,e,r){return e=(r?vs(n,e,r):e===t)?1:hu(e),Hr(pu(n),e)},Pe.replace=function(){var t=arguments,n=pu(t[0]);return t.length<3?n:n.replace(t[1],t[2])},Pe.result=function(n,e,r){var i=-1,s=(e=vi(e,n)).length;for(s||(s=1,n=t);++i<s;){var o=null==n?t:n[Is(e[i])];o===t&&(i=s,o=r),n=Qo(o)?o.call(n):o}return n},Pe.round=bc,Pe.runInContext=P,Pe.sample=function(t){return(Lo(t)?Ye:Qr)(t)},Pe.size=function(t){if(null==t)return 0;if(Bo(t))return ru(t)?ue(t):t.length;var n=hs(t);return n==g||n==x?t.size:Or(t).length},Pe.snakeCase=Nu,Pe.some=function(n,e,r){var i=Lo(n)?On:ti;return r&&vs(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&&Do(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(Do(t[e],n))return e}return-1},Pe.startCase=Ku,Pe.startsWith=function(t,n,e){return t=pu(t),e=null==e?0:ir(hu(e),0,t.length),n=si(n),t.slice(e,e+n.length)==n},Pe.subtract=mc,Pe.sum=function(t){return t&&t.length?Kn(t,Zu):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&&vs(n,e,r)&&(e=t),n=pu(n),e=yu({},e,i,Yi);var s,o,u=yu({},e.imports,i.imports,Yi),c=$u(u),a=Yn(u,c),h=0,l=e.interpolate||wt,f="__p += '",d=St((e.escape||wt).source+"|"+l.source+"|"+(l===Y?ct:wt).source+"|"+(e.evaluate||wt).source+"|$","g"),p="//# sourceURL="+(It.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(h,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'"),h=c+t.length,t})),f+="';\n";var v=It.call(e,"variable")&&e.variable;if(v){if(ot.test(v))throw new kt("Invalid `variable` option passed into `_.template`")}else f="with (obj) {\n"+f+"\n}\n";f=(o?f.replace(F,""):f).replace(L,"$1").replace(W,"$1;"),f="function("+(v||"obj")+") {\n"+(v?"":"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=Yu((function(){return At(c,p+"return "+f).apply(t,a)}));if(w.source=f,Vo(w))throw w;return w},Pe.times=function(t,n){if((t=hu(t))<1||t>u)return[];var e=a,r=we(t,a);n=is(n),t-=a;for(var i=Hn(r,n);++e<t;)n(e);return i},Pe.toFinite=au,Pe.toInteger=hu,Pe.toLength=lu,Pe.toLower=function(t){return pu(t).toLowerCase()},Pe.toNumber=fu,Pe.toSafeInteger=function(t){return t?ir(hu(t),-9007199254740991,u):0===t?t:0},Pe.toString=pu,Pe.toUpper=function(t){return pu(t).toUpperCase()},Pe.trim=function(n,e,r){if((n=pu(n))&&(r||e===t))return Vn(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=pu(n))&&(r||e===t))return n.slice(0,ae(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=pu(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(qo(e)){var s="separator"in e?e.separator:s;r="length"in e?hu(e.length):r,i="omission"in e?si(e.omission):i}var o=(n=pu(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 a=u?yi(u,0,c).join(""):n.slice(0,c);if(s===t)return a+i;if(u&&(c+=a.length-c),nu(s)){if(n.slice(c).search(s)){var h,l=a;for(s.global||(s=St(s.source,pu(at.exec(s))+"g")),s.lastIndex=0;h=s.exec(l);)var f=h.index;a=a.slice(0,f===t?c:f)}}else if(n.indexOf(si(s),c)!=c){var d=a.lastIndexOf(s);d>-1&&(a=a.slice(0,d))}return a+i},Pe.unescape=function(t){return(t=pu(t))&&K.test(t)?t.replace(B,he):t},Pe.uniqueId=function(t){var n=++Ot;return pu(t)+n},Pe.upperCase=Hu,Pe.upperFirst=Vu,Pe.each=po,Pe.eachRight=vo,Pe.first=Ws,rc(Pe,(dc={},yr(Pe,(function(t,n){It.call(Pe.prototype,n)||(dc[n]=t)})),dc),{chain:!1}),Pe.VERSION="4.17.23",xn(["bind","bindKey","curry","curryRight","partial","partialRight"],(function(t){Pe[t].placeholder=Pe})),xn(["drop","take"],(function(n,e){We.prototype[n]=function(r){r=r===t?1:ve(hu(r),0);var i=this.__filtered__&&!e?new We(this):this.clone();return i.__filtered__?i.__takeCount__=we(r,i.__takeCount__):i.__views__.push({size:we(r,a),type:n+(i.__dir__<0?"Right":"")}),i},We.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;We.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":"");We.prototype[t]=function(){return this[e](1).value()[0]}})),xn(["initial","tail"],(function(t,n){var e="drop"+(n?"":"Right");We.prototype[t]=function(){return this.__filtered__?new We(this):this[e](1)}})),We.prototype.compact=function(){return this.filter(Zu)},We.prototype.find=function(t){return this.filter(t).head()},We.prototype.findLast=function(t){return this.reverse().find(t)},We.prototype.invokeMap=Vr((function(t,n){return"function"==typeof t?new We(this):this.map((function(e){return $r(e,t,n)}))})),We.prototype.reject=function(t){return this.filter(jo(is(t)))},We.prototype.slice=function(n,e){n=hu(n);var r=this;return r.__filtered__&&(n>0||e<0)?new We(r):(n<0?r=r.takeRight(-n):n&&(r=r.drop(n)),e!==t&&(r=(e=hu(e))<0?r.dropRight(-e):r.take(e-n)),r)},We.prototype.takeRightWhile=function(t){return this.reverse().takeWhile(t).reverse()},We.prototype.toArray=function(){return this.take(a)},yr(We.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 We,a=u[0],h=c||Lo(e),l=function(t){var n=s.apply(Pe,Un([t],u));return i&&f?n[0]:n};h&&r&&"function"==typeof a&&1!=a.length&&(c=h=!1);var f=this.__chain__,d=o&&!f,p=c&&!this.__actions__.length;if(!o&&h){e=p?e:new We(this);var v=n.apply(e,u);return v.__actions__.push({func:co,args:[l],thisArg:t}),new Le(v,f)}return d&&p?n.apply(this,u):(v=this.thru(l),d?i?v.value()[0]:v.value():v)})})),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(Lo(i)?i:[],t)}return this[e]((function(e){return n.apply(Lo(e)?e:[],t)}))}})),yr(We.prototype,(function(t,n){var e=Pe[n];if(e){var r=e.name+"";It.call(Ee,r)||(Ee[r]=[]),Ee[r].push({name:n,func:e})}})),Ee[Di(t,2).name]=[{name:"wrapper",func:t}],We.prototype.clone=function(){var t=new We(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},We.prototype.reverse=function(){if(this.__filtered__){var t=new We(this);t.__dir__=-1,t.__filtered__=!0}else(t=this.clone()).__dir__*=-1;return t},We.prototype.value=function(){var t=this.__wrapped__.value(),n=this.__dir__,e=Lo(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=ve(t,n-o)}}return{start:t,end:n}}(0,i,this.__views__),o=s.start,u=s.end,c=u-o,a=r?u:o-1,h=this.__iteratees__,l=h.length,f=0,d=we(c,this.__takeCount__);if(!e||!r&&i==c&&d==c)return hi(t,this.__actions__);var p=[];t:for(;c--&&f<d;){for(var v=-1,w=t[a+=n];++v<l;){var y=h[v],g=y.type,b=(0,y.iteratee)(w);if(2==g)w=b;else if(!b){if(1==g)continue t;break t}}p[f++]=w}return p},Pe.prototype.at=ao,Pe.prototype.chain=function(){return uo(this)},Pe.prototype.commit=function(){return new Le(this.value(),this.__chain__)},Pe.prototype.next=function(){this.__values__===t&&(this.__values__=cu(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 Fe;){var i=_s(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 We){var e=n;return this.__actions__.length&&(e=new We(this)),(e=e.reverse()).__actions__.push({func:co,args:[Xs],thisArg:t}),new Le(e,this.__chain__)}return this.thru(Xs)},Pe.prototype.toJSON=Pe.prototype.valueOf=Pe.prototype.value=function(){return hi(this.__wrapped__,this.__actions__)},Pe.prototype.first=Pe.prototype.head,Gt&&(Pe.prototype[Gt]=function(){return this}),Pe}();ln?((ln.exports=le)._=le,hn._=le):an._=le}.call(Pc.exports)),Pc.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-Cj-I2_Og.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 Fc{_core;_debounceUpdate;_debounceEndScaling;_animationFrameId=null;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=Rc.debounce((()=>{this._core.updateWorkspaceViewport(this._core.store.state.translateX,this._core.store.state.translateY,this._core.store.state.scale)}),300),this._debounceEndScaling=Rc.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(this.cancelViewportAnimation(),"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||"pen"===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.isSelecting&&(this._core.store.state.isSelecting=!1,this._core.store.state.objects.remove((t=>t instanceof d)),this._core.store.allNonSelectionObjects.forEach((t=>{t.isSelected=!1}))),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||"pen"===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&&"pen"!==t.pointerType||0===this._core.store.state.pointers.size&&this._debounceEndScaling()}handleWheel(t){this.cancelViewportAnimation(),t.ctrlKey?this.handleZoom(t):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,0!==t.deltaX&&(this._core.store.state.translateX-=.8*t.deltaX),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()}cancelViewportAnimation(){null!==this._animationFrameId&&(cancelAnimationFrame(this._animationFrameId),this._animationFrameId=null)}animateViewportTo(t,n,e,r=150){this.cancelViewportAnimation();const i=this._core.store.state.translateX,s=this._core.store.state.translateY,o=this._core.store.state.scale,u=performance.now(),c=h=>{const a=Math.min((h-u)/r,1),l=1-Math.pow(1-a,3);this._core.store.state.translateX=i+(t-i)*l,this._core.store.state.translateY=s+(n-s)*l,this._core.store.state.scale=o+(e-o)*l,this._core.store.state.hasViewportChanged=!0,this._core.rerender(),a<1?this._animationFrameId=requestAnimationFrame(c):(this._animationFrameId=null,this._debounceUpdate())};this._animationFrameId=requestAnimationFrame(c)}centerFitNearestContent(t=20){const n=this._core.store.allNonSelectionObjects;if(0===n.length)return!1;const e=-this._core.store.state.translateX/this._core.store.state.scale+this._core.store.state.viewportWidth/2/this._core.store.state.scale,r=-this._core.store.state.translateY/this._core.store.state.scale+this._core.store.state.viewportHeight/2/this._core.store.state.scale,i=n.map((t=>{const n=t.rotatedBoundingBox,i=n.y+n.height/2;return{obj:t,distance:Math.sqrt(Math.pow(n.x+n.width/2-e,2)+Math.pow(i-r,2))}}));i.sort(((t,n)=>t.distance-n.distance));const s=i.slice(0,t).map((t=>t.obj));let o=1/0,u=1/0,c=-1/0,h=-1/0;for(const t of s){const n=t.rotatedBoundingBox;o=Math.min(o,n.x),u=Math.min(u,n.y),c=Math.max(c,n.x+n.width),h=Math.max(h,n.y+n.height)}const a=c-o,l=h-u,f=o+a/2,d=u+l/2,p=Math.min(this._core.store.state.viewportWidth/(1.1*a),this._core.store.state.viewportHeight/(1.1*l),this._core.store.state.scaleMax),v=Math.max(p,this._core.store.state.scaleMin);return this.animateViewportTo(this._core.store.state.viewportWidth/2-f*v,this._core.store.state.viewportHeight/2-d*v,v),!0}}class Lc extends v{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 Wc extends v{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 p)&&!(e instanceof d)){const t=p.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 Bc={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"},lockDrawingScale:!0};class Nc extends y{__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 Nc(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 Kc{_core;constructor(t){this._core=t}revive(t){if(t&&"object"==typeof t){if(t.__class__){let n;switch(t.__class__){case"KritzelPath":n=S.create(this._core).deserialize(t);break;case"KritzelLine":n=l.create(this._core).deserialize(t);break;case"KritzelText":n=M.create(this._core,t.fontSize,t.fontFamily).deserialize(t);break;case"KritzelShape":n=x.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=h.create(this._core).deserialize(t);break;case"KritzelCustomElement":n=Nc.create(this._core).deserialize(t);break;case"KritzelSelectionGroup":n=p.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 k(this._core);break;case"KritzelEraserTool":n=new R(this._core);break;case"KritzelImageTool":n=new gt(this._core);break;case"KritzelSelectionTool":n=new w(this._core);break;case"KritzelTextTool":n=new m(this._core);break;case"KritzelLineTool":n=new b(this._core);break;case"KritzelShapeTool":n=new g(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 Hc{bounds;capacity;objects=[];children=null;_size=0;get size(){return this._size}constructor(t,n=16){this.bounds=t,this.capacity=n}reset(){this.objects=[],this.children=null,this._size=0}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),this._size++,!0;null===this.children&&this.subdivide();for(const n of this.children)if(n.insert(t))return this._size++,!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){let n=0;const e=this.objects.findIndex((n=>t(n)));if(-1!==e&&(this.objects.splice(e,1),n++),null!==this.children)for(const e of this.children)n+=e.remove(t);return this._size-=n,n}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 Hc({x:t,y:n,z:e,width:s,height:o},this.capacity),new Hc({x:t+s,y:n,z:e,width:s,height:o},this.capacity),new Hc({x:t,y:n+o,z:e,width:s,height:o},this.capacity),new Hc({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 Vc{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}}get totalCount(){return this.quadtree.size}constructor(){this.quadtree=new Hc({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 Kc(t),this._ydoc=new hi,this._objectsMap=this._ydoc.getMap("objects");const r=`kritzel-workspace-${n}`,i=e??Ec;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 es([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 p?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 p||t instanceof d))).map((t=>t.zIndex)))+1}get totalObjectCount(){return this._state.objects.totalCount}get allObjects(){return this._state.objects.allObjects()}get objectsInViewport(){return this._state.objects.query({x:-this._state.translateX/this._state.scale,y:-this._state.translateY/this._state.scale,z:this._state.scale,width:this._state.viewportWidth/this._state.scale,height:this._state.viewportHeight/this._state.scale,depth:100}).filter((t=>!(t instanceof p||t instanceof d))).sort(((t,n)=>t.zIndex-n.zIndex))}get allNonSelectionObjects(){return this._state.objects.allObjects().filter((t=>!(t instanceof p||t instanceof d)))}get selectedObjects(){return this.allObjects.filter((t=>!(t instanceof p))).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 p));return t.length>0?t[0]:null}get activeText(){const t=this._state.objects.filter((t=>t instanceof M&&t.isEditing));return t.length>0?t[0]:null}get activeShape(){const t=this._state.objects.filter((t=>t instanceof x&&t.isEditing));return t.length>0?t[0]:null}get currentPath(){const t=this._state.objects.filter((t=>t instanceof S&&!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 Vc}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-global-pointer-cursor")),this._targetElement=t,this._targetElement&&this._targetElement.style.setProperty("--kritzel-global-pointer-cursor",bt.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=bt.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 Xc{_kritzelEngine;_store;_syncConfig;_appStateMap;_anchorManager;_cursorManager;_themeManager;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}get themeManager(){return this._themeManager}constructor(t){this._kritzelEngine=t,this._store=new Qc(Bc),this._appStateMap=new Tc,this._anchorManager=new jc(this),this._cursorManager=new Yc(this),this._themeManager=new O(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(T.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 Vc;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()}getObjectsInViewport(){return 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 instanceof p||t instanceof d))).sort(((t,n)=>t.zIndex-n.zIndex))}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.engine.viewport?.cancelPendingUpdates(),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&&this._store.state.workspaces.some((t=>t.id===r.id))&&(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){const e=[];for(const r in n)n.hasOwnProperty(r)&&(t[r]=n[r],e.push(r));t.onAfterUpdate(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 v=p.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),v.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(),v.isSelected=!0,1===e.length&&(v.rotation=e[0].rotation),this.addSelectionGroup(v),s&&(void 0!==t&&void 0!==n?v.updatePosition(t,n):v.centerInViewport(),this.engine.viewport.centerFitInViewport(v)),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=p.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=p.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=p.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 p||t instanceof d||t instanceof $)));if(t.length>0){const n=p.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 p)),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 qc=(()=>{let t=0;return()=>(t+=1,`u${`0000${(Math.random()*36**4|0).toString(36)}`.slice(-4)}${t}`)})();function Gc(t){const n=[];for(let e=0,r=t.length;e<r;e++)n.push(t[e]);return n}let Jc=null;function Zc(t={}){return Jc||(t.includeStyleProperties?(Jc=t.includeStyleProperties,Jc):(Jc=Gc(window.getComputedStyle(document.documentElement)),Jc))}function th(t,n){const e=(t.ownerDocument.defaultView||window).getComputedStyle(t).getPropertyValue(n);return e?parseFloat(e.replace("px","")):0}function nh(t,n={}){return{width:n.width||function(t){const n=th(t,"border-left-width"),e=th(t,"border-right-width");return t.clientWidth+n+e}(t),height:n.height||function(t){const n=th(t,"border-top-width"),e=th(t,"border-bottom-width");return t.clientHeight+n+e}(t)}}const eh=16384;function rh(t){return new Promise(((n,e)=>{const r=new Image;r.onload=()=>{r.decode().then((()=>{requestAnimationFrame((()=>n(r)))}))},r.onerror=e,r.crossOrigin="anonymous",r.decoding="async",r.src=t}))}const ih=(t,n)=>{if(t instanceof n)return!0;const e=Object.getPrototypeOf(t);return null!==e&&(e.constructor.name===n.name||ih(e,n))};function sh(t,n,e,r){const i=window.getComputedStyle(t,e),s=i.getPropertyValue("content");if(""===s||"none"===s)return;const o=qc();try{n.className=`${n.className} ${o}`}catch(t){return}const u=document.createElement("style");u.appendChild(function(t,n,e,r){const i=`.${t}:${n}`,s=e.cssText?function(t){const n=t.getPropertyValue("content");return`${t.cssText} content: '${n.replace(/'|"/g,"")}';`}(e):function(t,n){return Zc(n).map((n=>`${n}: ${t.getPropertyValue(n)}${t.getPropertyPriority(n)?" !important":""};`)).join(" ")}(e,r);return document.createTextNode(`${i}{${s}}`)}(o,e,i,r)),n.appendChild(u)}const oh="application/font-woff",uh="image/jpeg",ch={woff:oh,woff2:oh,ttf:"application/font-truetype",eot:"application/vnd.ms-fontobject",png:"image/png",jpg:uh,jpeg:uh,gif:"image/gif",tiff:"image/tiff",svg:"image/svg+xml",webp:"image/webp"};function hh(t){const n=function(t){const n=/\.([^./]*?)$/g.exec(t);return n?n[1]:""}(t).toLowerCase();return ch[n]||""}function ah(t){return-1!==t.search(/^(data:)/)}async function lh(t,n,e){const r=await fetch(t,n);if(404===r.status)throw new Error(`Resource "${r.url}" not found`);const i=await r.blob();return new Promise(((t,n)=>{const s=new FileReader;s.onerror=n,s.onloadend=()=>{try{t(e({res:r,result:s.result}))}catch(t){n(t)}},s.readAsDataURL(i)}))}const fh={};async function dh(t,n,e){const r=function(t,n,e){let r=t.replace(/\?.*/,"");return e&&(r=t),/ttf|otf|eot|woff2?/i.test(r)&&(r=r.replace(/.*\//,"")),n?`[${n}]${r}`:r}(t,n,e.includeQueryParams);if(null!=fh[r])return fh[r];let i;e.cacheBust&&(t+=(/\?/.test(t)?"&":"?")+(new Date).getTime());try{const r=await lh(t,e.fetchRequestInit,(({res:t,result:e})=>(n||(n=t.headers.get("Content-Type")||""),function(t){return t.split(/,/)[1]}(e))));i=function(t,n){return`data:${n};base64,${t}`}(r,n)}catch(n){i=e.imagePlaceholder||"";let r=`Failed to fetch resource: ${t}`;n&&(r="string"==typeof n?n:n.message),r&&console.warn(r)}return fh[r]=i,i}const ph=t=>null!=t.tagName&&"SLOT"===t.tagName.toUpperCase(),vh=t=>null!=t.tagName&&"SVG"===t.tagName.toUpperCase();async function wh(t,n,e){return e||!n.filter||n.filter(t)?Promise.resolve(t).then((t=>async function(t,n){return ih(t,HTMLCanvasElement)?async function(t){const n=t.toDataURL();return"data:,"===n?t.cloneNode(!1):rh(n)}(t):ih(t,HTMLVideoElement)?async function(t,n){if(t.currentSrc){const n=document.createElement("canvas"),e=n.getContext("2d");return n.width=t.clientWidth,n.height=t.clientHeight,null==e||e.drawImage(t,0,0,n.width,n.height),rh(n.toDataURL())}const e=t.poster,r=hh(e);return rh(await dh(e,r,n))}(t,n):ih(t,HTMLIFrameElement)?async function(t,n){var e;try{if(null===(e=null==t?void 0:t.contentDocument)||void 0===e?void 0:e.body)return await wh(t.contentDocument.body,n,!0)}catch(t){}return t.cloneNode(!1)}(t,n):t.cloneNode(vh(t))}(t,n))).then((e=>async function(t,n,e){var r,i;if(vh(n))return n;let s=[];return s=ph(t)&&t.assignedNodes?Gc(t.assignedNodes()):ih(t,HTMLIFrameElement)&&(null===(r=t.contentDocument)||void 0===r?void 0:r.body)?Gc(t.contentDocument.body.childNodes):Gc((null!==(i=t.shadowRoot)&&void 0!==i?i:t).childNodes),0===s.length||ih(t,HTMLVideoElement)||await s.reduce(((t,r)=>t.then((()=>wh(r,e))).then((t=>{t&&n.appendChild(t)}))),Promise.resolve()),n}(t,e,n))).then((e=>function(t,n,e){return ih(n,Element)&&(function(t,n,e){const r=n.style;if(!r)return;const i=window.getComputedStyle(t);i.cssText?(r.cssText=i.cssText,r.transformOrigin=i.transformOrigin):Zc(e).forEach((e=>{let s=i.getPropertyValue(e);if("font-size"===e&&s.endsWith("px")){const t=Math.floor(parseFloat(s.substring(0,s.length-2)))-.1;s=`${t}px`}ih(t,HTMLIFrameElement)&&"display"===e&&"inline"===s&&(s="block"),"d"===e&&n.getAttribute("d")&&(s=`path(${n.getAttribute("d")})`),r.setProperty(e,s,i.getPropertyPriority(e))}))}(t,n,e),function(t,n,e){sh(t,n,":before",e),sh(t,n,":after",e)}(t,n,e),function(t,n){ih(t,HTMLTextAreaElement)&&(n.innerHTML=t.value),ih(t,HTMLInputElement)&&n.setAttribute("value",t.value)}(t,n),function(t,n){if(ih(t,HTMLSelectElement)){const e=Array.from(n.children).find((n=>t.value===n.getAttribute("value")));e&&e.setAttribute("selected","")}}(t,n)),n}(t,e,n))).then((t=>async function(t,n){const e=t.querySelectorAll?t.querySelectorAll("use"):[];if(0===e.length)return t;const r={};for(let i=0;i<e.length;i++){const s=e[i].getAttribute("xlink:href");if(s){const e=t.querySelector(s),i=document.querySelector(s);e||!i||r[s]||(r[s]=await wh(i,n,!0))}}const i=Object.values(r);if(i.length){const n="http://www.w3.org/1999/xhtml",e=document.createElementNS(n,"svg");e.setAttribute("xmlns",n),e.style.position="absolute",e.style.width="0",e.style.height="0",e.style.overflow="hidden",e.style.display="none";const r=document.createElementNS(n,"defs");e.appendChild(r);for(let t=0;t<i.length;t++)r.appendChild(i[t]);t.appendChild(e)}return t}(t,n))):null}const yh=/url\((['"]?)([^'"]+?)\1\)/g,gh=/url\([^)]+\)\s*format\((["']?)([^"']+)\1\)/g,bh=/src:\s*(?:url\([^)]+\)\s*format\([^)]+\)[,;]\s*)+/g;function mh(t){return-1!==t.search(yh)}async function kh(t,n,e){if(!mh(t))return t;const r=function(t,{preferredFontFormat:n}){return n?t.replace(bh,(t=>{for(;;){const[e,,r]=gh.exec(t)||[];if(!r)return"";if(r===n)return`src: ${e};`}})):t}(t,e),i=function(t){const n=[];return t.replace(yh,((t,e,r)=>(n.push(r),t))),n.filter((t=>!ah(t)))}(r);return i.reduce(((t,r)=>t.then((t=>async function(t,n,e,r){try{const i=e?function(t,n){if(t.match(/^[a-z]+:\/\//i))return t;if(t.match(/^\/\//))return window.location.protocol+t;if(t.match(/^[a-z]+:/i))return t;const e=document.implementation.createHTMLDocument(),r=e.createElement("base"),i=e.createElement("a");return e.head.appendChild(r),e.body.appendChild(i),n&&(r.href=n),i.href=t,i.href}(n,e):n,s=hh(n);let o;return o=await dh(i,s,r),t.replace(function(t){const n=t.replace(/([.*+?^${}()|\[\]\/\\])/g,"\\$1");return new RegExp(`(url\\(['"]?)(${n})(['"]?\\))`,"g")}(n),`$1${o}$3`)}catch(t){}return t}(t,r,n,e)))),Promise.resolve(r))}async function Ah(t,n,e){var r;const i=null===(r=n.style)||void 0===r?void 0:r.getPropertyValue(t);if(i){const r=await kh(i,null,e);return n.style.setProperty(t,r,n.style.getPropertyPriority(t)),!0}return!1}async function xh(t,n){ih(t,Element)&&(await async function(t,n){await Ah("background",t,n)||await Ah("background-image",t,n),await Ah("mask",t,n)||await Ah("-webkit-mask",t,n)||await Ah("mask-image",t,n)||await Ah("-webkit-mask-image",t,n)}(t,n),await async function(t,n){const e=ih(t,HTMLImageElement);if((!e||ah(t.src))&&(!ih(t,SVGImageElement)||ah(t.href.baseVal)))return;const r=e?t.src:t.href.baseVal,i=await dh(r,hh(r),n);await new Promise(((r,s)=>{t.onload=r,t.onerror=n.onImageErrorHandler?(...t)=>{try{r(n.onImageErrorHandler(...t))}catch(t){s(t)}}:s;const o=t;o.decode&&(o.decode=r),"lazy"===o.loading&&(o.loading="eager"),e?(t.srcset="",t.src=i):t.href.baseVal=i}))}(t,n),await async function(t,n){const e=Gc(t.childNodes).map((t=>xh(t,n)));await Promise.all(e).then((()=>t))}(t,n))}const Mh={};async function Sh(t){let n=Mh[t];if(null!=n)return n;const e=await fetch(t);return n={url:t,cssText:await e.text()},Mh[t]=n,n}async function Ch(t,n){let e=t.cssText;const r=/url\(["']?([^"')]+)["']?\)/g,i=(e.match(/url\([^)]+\)/g)||[]).map((async i=>{let s=i.replace(r,"$1");return s.startsWith("https://")||(s=new URL(s,t.url).href),lh(s,n.fetchRequestInit,(({result:t})=>(e=e.replace(i,`url(${t})`),[i,t])))}));return Promise.all(i).then((()=>e))}function $h(t){if(null==t)return[];const n=[];let e=t.replace(/(\/\*[\s\S]*?\*\/)/gi,"");const r=new RegExp("((@.*?keyframes [\\s\\S]*?){([\\s\\S]*?}\\s*?)})","gi");for(;;){const t=r.exec(e);if(null===t)break;n.push(t[0])}e=e.replace(r,"");const i=/@import[\s\S]*?url\([^)]*\)[\s\S]*?;/gi,s=new RegExp("((\\s*?(?:\\/\\*[\\s\\S]*?\\*\\/)?\\s*?@media[\\s\\S]*?){([\\s\\S]*?)}\\s*?})|(([\\s\\S]*?){([\\s\\S]*?)})","gi");for(;;){let t=i.exec(e);if(null===t){if(t=s.exec(e),null===t)break;i.lastIndex=s.lastIndex}else s.lastIndex=i.lastIndex;n.push(t[0])}return n}function Eh(t){return t.trim().replace(/["']/g,"")}async function Th(t,n){const e=await async function(t,n){if(null==t.ownerDocument)throw new Error("Provided element is not within a Document");const e=Gc(t.ownerDocument.styleSheets),r=await async function(t,n){const e=[],r=[];return t.forEach((e=>{if("cssRules"in e)try{Gc(e.cssRules||[]).forEach(((t,i)=>{if(t.type===CSSRule.IMPORT_RULE){let s=i+1;const o=Sh(t.href).then((t=>Ch(t,n))).then((t=>$h(t).forEach((t=>{try{e.insertRule(t,t.startsWith("@import")?s+=1:e.cssRules.length)}catch(n){console.error("Error inserting rule from remote css",{rule:t,error:n})}})))).catch((t=>{console.error("Error loading remote css",t.toString())}));r.push(o)}}))}catch(i){const s=t.find((t=>null==t.href))||document.styleSheets[0];null!=e.href&&r.push(Sh(e.href).then((t=>Ch(t,n))).then((t=>$h(t).forEach((t=>{s.insertRule(t,s.cssRules.length)})))).catch((t=>{console.error("Error loading remote stylesheet",t)}))),console.error("Error inlining remote css file",i)}})),Promise.all(r).then((()=>(t.forEach((t=>{if("cssRules"in t)try{Gc(t.cssRules||[]).forEach((t=>{e.push(t)}))}catch(n){console.error(`Error while reading CSS rules from ${t.href}`,n)}})),e)))}(e,n);return function(t){return t.filter((t=>t.type===CSSRule.FONT_FACE_RULE)).filter((t=>mh(t.style.getPropertyValue("src"))))}(r)}(t,n),r=function(t){const n=new Set;return function t(e){(e.style.fontFamily||getComputedStyle(e).fontFamily).split(",").forEach((t=>{n.add(Eh(t))})),Array.from(e.children).forEach((n=>{n instanceof HTMLElement&&t(n)}))}(t),n}(t);return(await Promise.all(e.filter((t=>r.has(Eh(t.style.fontFamily)))).map((t=>kh(t.cssText,t.parentStyleSheet?t.parentStyleSheet.href:null,n))))).join("\n")}async function Uh(t,n={}){const{width:e,height:r}=nh(t,n),i=await wh(t,n,!0);return await async function(t,n){const e=null!=n.fontEmbedCSS?n.fontEmbedCSS:n.skipFonts?null:await Th(t,n);if(e){const n=document.createElement("style"),r=document.createTextNode(e);n.appendChild(r),t.firstChild?t.insertBefore(n,t.firstChild):t.appendChild(n)}}(i,n),await xh(i,n),function(t,n){const{style:e}=t;n.backgroundColor&&(e.backgroundColor=n.backgroundColor),n.width&&(e.width=`${n.width}px`),n.height&&(e.height=`${n.height}px`);const r=n.style;null!=r&&Object.keys(r).forEach((t=>{e[t]=r[t]}))}(i,n),await async function(t,n,e){const r="http://www.w3.org/2000/svg",i=document.createElementNS(r,"svg"),s=document.createElementNS(r,"foreignObject");return i.setAttribute("width",`${n}`),i.setAttribute("height",`${e}`),i.setAttribute("viewBox",`0 0 ${n} ${e}`),s.setAttribute("width","100%"),s.setAttribute("height","100%"),s.setAttribute("x","0"),s.setAttribute("y","0"),s.setAttribute("externalResourcesRequired","true"),i.appendChild(s),s.appendChild(t),async function(t){return Promise.resolve().then((()=>(new XMLSerializer).serializeToString(t))).then(encodeURIComponent).then((t=>`data:image/svg+xml;charset=utf-8,${t}`))}(i)}(i,e,r)}const jh=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=Ic;validateScaleMax(t){t>Ic?(console.warn("scaleMax cannot be greater than 1000."),this.scaleMax=Ic,this.core.store.state.scaleMax=this.scaleMax):this.core.store.state.scaleMax=t}scaleMin=Oc;validateScaleMin(t){t<Oc?(console.warn("scaleMin cannot be less than 0.0001."),this.scaleMin=Oc,this.core.store.state.scaleMin=this.scaleMin):this.core.store.state.scaleMin=t}cursorTarget;onCursorTargetChange(t){this.core.cursorManager.setTargetElement(t||document.body)}lockDrawingScale=!0;onLockDrawingScaleChange(t){this.core.store.state.lockDrawingScale=t}theme="light";onThemeChange(t){this.core.themeManager.setTheme(t)}isEngineReady;activeToolChange;objectsSelectionChange;workspacesChange;longpress;objectsChange;undoStateChange;objectsInViewportChange;forceUpdate=0;async triggerSelectionChange(){this.objectsSelectionChange.emit()}handleWheel(t){this.core.store.isDisabled||(this.core.store.state.isContextMenuVisible&&this.hideContextMenu(),this.viewport.handleWheel(t),this.core.store.state?.activeTool?.handleWheel(t))}handlePointerDown(t){this.core.store.isDisabled||(z.isTouchDevice()&&c.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=Rc.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&&"pen"!==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 u))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 backToContent(){return this.viewport.centerFitNearestContent(20)}async getCopiedObjects(){return this.core.store.state.copiedObjects||[]}async getScreenshot(t="png"){if(!this.host)return null;const n={objects:this.core.store.state.objects,activeWorkspace:this.core.store.state.activeWorkspace,workspaces:this.core.store.state.workspaces,activeTool:this.core.store.state.activeTool,isReady:this.core.store.state.isReady,translateX:this.core.store.state.translateX,translateY:this.core.store.state.translateY,scale:this.core.store.state.scale},e={filter:t=>!("KRITZEL-CONTEXT-MENU"===t.tagName||t.classList&&t.classList.contains("debug-panel"))};let r;try{r="svg"===t?await Uh(this.host,e):await async function(t,n={}){return(await async function(t,n={}){const{width:e,height:r}=nh(t,n),i=await Uh(t,n),s=await rh(i),o=document.createElement("canvas"),u=o.getContext("2d"),c=n.pixelRatio||function(){let t,n;try{n=process}catch(t){}const e=n&&n.env?n.env.devicePixelRatio:null;return e&&(t=parseInt(e,10),Number.isNaN(t)&&(t=1)),t||window.devicePixelRatio||1}(),h=n.canvasWidth||e,a=n.canvasHeight||r;return o.width=h*c,o.height=a*c,n.skipAutoScale||function(t){(t.width>eh||t.height>eh)&&(t.width>eh&&t.height>eh?t.width>t.height?(t.height*=eh/t.width,t.width=eh):(t.width*=eh/t.height,t.height=eh):t.width>eh?(t.height*=eh/t.width,t.width=eh):(t.width*=eh/t.height,t.height=eh))}(o),o.style.width=`${h}`,o.style.height=`${a}`,n.backgroundColor&&(u.fillStyle=n.backgroundColor,u.fillRect(0,0,o.width,o.height)),u.drawImage(s,0,0,o.width,o.height),o}(t,n)).toDataURL()}(this.host,e)}finally{this.core.store.state.objects=n.objects,this.core.store.state.activeWorkspace=n.activeWorkspace,this.core.store.state.workspaces=n.workspaces,this.core.store.state.activeTool=n.activeTool,this.core.store.state.isReady=n.isReady,this.core.store.state.translateX=n.translateX,this.core.store.state.translateY=n.translateY,this.core.store.state.scale=n.scale,this.core.rerender()}return r}async exportViewportAsPng(){try{const t=`${this.core.store.state?.activeWorkspace?.name||"workspace"}-${(new Date).toISOString().replace(/[:.]/g,"-")}.png`,n=await this.getScreenshot("png"),e=document.createElement("a");e.download=t,e.href=n,e.click()}catch(t){console.error("Failed to export viewport as PNG:",t)}}async exportViewportAsSvg(){try{const t=`${this.core.store.state?.activeWorkspace?.name||"workspace"}-${(new Date).toISOString().replace(/[:.]/g,"-")}.svg`,n=await this.getScreenshot("svg"),e=document.createElement("a");e.download=t,e.href=n,e.click()}catch(t){console.error("Failed to export viewport as SVG:",t)}}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;_lastHadSelectionGroup=!1;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.objectsInViewportChange=e(this,"objectsInViewportChange"),this.core=new Xc(this)}disconnectedCallback(){this.throttledPointerMoveMulti.cancel(),this.core.cursorManager.cleanup()}componentWillLoad(){this.validateScaleMax(this.scaleMax),this.validateScaleMin(this.scaleMin),this.core.store.state.lockDrawingScale=this.lockDrawingScale}async componentDidLoad(){this.contextMenuHandler=new Wc(this.core,this.globalContextMenuItems,this.objectContextMenuItems),this.keyHandler=new Lc(this.core),this.viewport=new Fc(this.core,this.host),this.core.cursorManager.setTargetElement(this.cursorTarget||document.body),this.core.cursorManager.setShadowRoot(this.host.shadowRoot);const t=this.host.closest("kritzel-editor");this.core.themeManager.setTargetElement(t||this.host),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,n=null!==this.core.store.selectionGroup;this.objectsChange.emit(this.core.store.allObjects),this.undoStateChange.emit(t),this._lastHadSelectionGroup!==n&&(this._lastHadSelectionGroup=n,this.objectsSelectionChange.emit())}_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),C.forceHideKeyboard(),this.core.rerender()}render(){const t=O.getStoredTheme(),n=window.getComputedStyle(this.host).getPropertyValue("--kritzel-selection-handle-size").trim()||"6px",e=parseFloat(n),s=2*e<14?14:e,o=this.core.store.state.viewportWidth/2+this.core.store.state.translateX,u=this.core.store.state.viewportHeight/2+this.core.store.state.translateY,c=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(),this.core.store.totalObjectCount>0&&this.objectsInViewportChange.emit(c),r(i,{key:"26d2ef50f28fb809d046b60dff6e977dec53fc8c"},this.core.store.state.debugInfo.showViewportInfo&&r("div",{key:"bbacc63967672c6934d1c90913139f1f96e532cb",class:"debug-panel"},r("div",{key:"59d46ef1a1a8dffe7b1bd97b0df3c77fdd095d97"},"ActiveWorkspaceId: ",this.core.store.state?.activeWorkspace?.id),r("div",{key:"d6bc9b3c6076540ccfec4fd2ef3b3e2edf08d524"},"ActiveWorkspaceName: ",this.core.store.state?.activeWorkspace?.name),r("div",{key:"12e229d893933a01bbfdd038e1bd14eee198b34e"},"TranslateX: ",this.core.store.state?.translateX),r("div",{key:"9caf69c342d545a478bb4945aa7b2c37ea77561f"},"TranslateY: ",this.core.store.state?.translateY),r("div",{key:"123f6b17777475f4de32872b940abd3b7ffe6d78"},"ViewportWidth: ",this.core.store.state?.viewportWidth),r("div",{key:"463c70e208dad8572317bbde0df0f4b149674a7d"},"ViewportHeight: ",this.core.store.state?.viewportHeight),r("div",{key:"82deb6d97ae66c86431b32582114f81bcd83e5ae"},"PointerCount: ",this.core.store.state.pointers.size),r("div",{key:"be32ffe65da2fc92f556ac037afa5b50c27cedd2"},"Scale: ",this.core.store.state?.scale),r("div",{key:"53029e75a8972f670ef0fa427549415fd8be7986"},"ActiveTool: ",this.core.store.state?.activeTool?.name),r("div",{key:"27517882d278f0df7df59858a9219d356e5bbd8d"},"HasViewportChanged: ",this.core.store.state?.hasViewportChanged?"true":"false"),r("div",{key:"616611f9ad570741c9be3eabd0c78dc978c16c4f"},"IsEnabled: ",this.core.store.state?.isEnabled?"true":"false"),r("div",{key:"318a17d0b0d7eb2a58233c76063cc72e87782f1b"},"IsScaling: ",this.core.store.state?.isScaling?"true":"false"),r("div",{key:"45c92f5cc524338b5c0cab5f5123faf0296e7484"},"IsPanning: ",this.core.store.state?.isPanning?"true":"false"),r("div",{key:"4b295ddaf8eb9e49547430c839a9ba50daacd42e"},"IsSelecting: ",this.isSelecting?"true":"false"),r("div",{key:"eef9039260d0f1ffa23102aee0f18ebd90111738"},"IsSelectionActive: ",this.isSelectionActive?"true":"false"),r("div",{key:"1a22a4a93ddab249532fe40640f1fa7bbb485d76"},"IsResizeHandleSelected: ",this.core.store.state.isResizeHandleSelected?"true":"false"),r("div",{key:"094daef63fffab66051e1c65392baac58d8f3eca"},"IsRotationHandleSelected: ",this.core.store.state.isRotationHandleSelected?"true":"false"),r("div",{key:"dae17ba3dec0ededdfb873eda4081fb51cea0c52"},"IsRotationHandleHovered: ",this.core.store.state.isRotationHandleHovered?"true":"false"),r("div",{key:"11b4c3fb7fef201e6a98a58f586e1c717f255af4"},"IsDrawing: ",this.core.store.state.isDrawing?"true":"false"),r("div",{key:"ac7b98f441747b90f047069b9e7eac2ac5194eec"},"IsWriting: ",this.core.store.state.isWriting?"true":"false"),r("div",{key:"eb2285428d88835319c68ff26cb99e1e631cba82"},"IsPointerDown: ",this.core.store.isPointerDown?"true":"false"),r("div",{key:"d32cb23e569a84b16a50b98d2e3d778c6462c88c"},"PointerX: ",this.core.store.state?.pointerX),r("div",{key:"0b4fafde05bb83d4046b103015a4f008c5b268d8"},"PointerY: ",this.core.store.state?.pointerY),r("div",{key:"0083eb1e81cd1d0552e0fa2d6cca147e14e0bd86"},"SelectedObjects: ",this.core.store.selectionGroup?.objects.length||0),r("div",{key:"232f452fd89d22db9e4aaf8e6d3b672f934422a5"},"ViewportCenter: (",o.toFixed(2),", ",u.toFixed(2),")")),r("div",{key:"66a0d3a6ac62153acf6ed1b7c57b3ae77daa3c5e",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})`}},c?.map((n=>r("div",{key:n.id,id:n.id,class:"object",style:{transform:n?.transformationMatrix,transformOrigin:"top left",position:"absolute",zIndex:n.zIndex.toString(),pointerEvents:this.core.store.state.isScaling?"none":"auto"}},Uc.isInstanceOf(n,"KritzelPath")&&r("svg",{xmlns:"http://www.w3.org/2000/svg",style:{height:n?.totalHeight+"px",width:n?.totalWidth+"px",left:"0",top:"0",position:"absolute",transform:0!==n.rotationDegrees?`rotate(${n.rotationDegrees}deg)`:void 0,transformOrigin:0!==n.rotationDegrees?`${n.totalWidth/2}px ${n.totalHeight/2}px`:void 0,opacity:n.markedForRemoval?"0.5":n.opacity.toString(),pointerEvents:n.markedForRemoval?"none":"auto"}},r("svg",{ref:t=>n.mount(t),xmlns:"http://www.w3.org/2000/svg",style:{overflow:"visible"},viewBox:n?.viewBox},r("path",{d:n?.d,fill:_.resolveThemeColor(n.fill,t),stroke:_.resolveThemeColor(n?.stroke,t),"shape-rendering":n.isLowRes()?"optimizeSpeed":"auto"}))),Uc.isInstanceOf(n,"KritzelLine")&&r("svg",{xmlns:"http://www.w3.org/2000/svg",style:{height:n?.totalHeight+"px",width:n?.totalWidth+"px",left:"0",top:"0",position:"absolute",transform:0!==n.rotationDegrees?`rotate(${n.rotationDegrees}deg)`:void 0,transformOrigin:0!==n.rotationDegrees?`${n.totalWidth/2}px ${n.totalHeight/2}px`:void 0,opacity:n.markedForRemoval?"0.5":n.opacity.toString(),pointerEvents:n.markedForRemoval?"none":"auto"}},r("svg",{ref:t=>n.mount(t),xmlns:"http://www.w3.org/2000/svg",style:{overflow:"visible"},viewBox:n?.viewBox},(n.hasStartArrow||n.hasEndArrow)&&r("defs",null,n.hasStartArrow&&r("marker",{id:n.startMarkerId,markerWidth:n.getArrowSize("start"),markerHeight:n.getArrowSize("start"),refX:0,refY:n.getArrowSize("start")/2,orient:"auto-start-reverse",markerUnits:"userSpaceOnUse"},r("path",{d:n.getArrowPath(n.arrows?.start?.style),fill:n.getArrowFill("start"),transform:`scale(${n.getArrowSize("start")/10})`})),n.hasEndArrow&&r("marker",{id:n.endMarkerId,markerWidth:n.getArrowSize("end"),markerHeight:n.getArrowSize("end"),refX:0,refY:n.getArrowSize("end")/2,orient:"auto",markerUnits:"userSpaceOnUse"},r("path",{d:n.getArrowPath(n.arrows?.end?.style),fill:n.getArrowFill("end"),transform:`scale(${n.getArrowSize("end")/10})`}))),r("path",{d:this.core.anchorManager.computeClippedLinePath(n),fill:"none",stroke:"transparent","stroke-width":Math.max(n?.strokeWidth||0,10),"stroke-linecap":"round"}),r("path",{d:this.core.anchorManager.computeClippedLinePath(n),fill:"none",stroke:_.resolveThemeColor(n?.stroke,t),"stroke-width":n?.strokeWidth,"stroke-linecap":"round","marker-start":n.hasStartArrow?`url(#${n.startMarkerId})`:void 0,"marker-end":n.hasEndArrow?`url(#${n.endMarkerId})`:void 0}))),Uc.isInstanceOf(n,"KritzelImage")&&r("div",{style:{position:"absolute",left:"0",top:"0",width:n.totalWidth+"px",height:n.totalHeight+"px",transform:0!==n.rotationDegrees?`rotate(${n.rotationDegrees}deg)`:void 0,transformOrigin:0!==n.rotationDegrees?`${n.totalWidth/2}px ${n.totalHeight/2}px`:void 0,opacity:n.markedForRemoval?"0.5":n.opacity.toString(),pointerEvents:n.markedForRemoval?"none":"auto",backgroundColor:_.resolveThemeColor(n.backgroundColor,t),borderColor:_.resolveThemeColor(n.borderColor,t),borderWidth:n.borderWidth+"px",borderStyle:"solid",padding:n.padding+"px",overflow:"visible"}},r("img",{ref:t=>n.mount(t),src:n.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()})),Uc.isInstanceOf(n,"KritzelCustomElement")&&r("div",{style:{position:"absolute",left:"0",top:"0",width:n.totalWidth+"px",height:n.totalHeight+"px",transform:0!==n.rotationDegrees?`rotate(${n.rotationDegrees}deg)`:void 0,transformOrigin:0!==n.rotationDegrees?`${n.totalWidth/2}px ${n.totalHeight/2}px`:void 0,opacity:n.markedForRemoval?"0.5":n.opacity.toString(),pointerEvents:n.markedForRemoval?"none":"auto",backgroundColor:_.resolveThemeColor(n.backgroundColor,t),borderColor:_.resolveThemeColor(n.borderColor,t),borderWidth:n.borderWidth+"px",borderStyle:"solid",padding:n.padding+"px",overflow:"visible"}},r("div",{ref:t=>n.mount(t),style:{width:"100%",height:"100%",pointerEvents:"auto",overflow:"hidden",display:"block"}})),Uc.isInstanceOf(n,"KritzelSelectionGroup")&&!this.core.displaySelectionLineUI(n)&&r("div",{style:{position:"absolute",left:"0",top:"0",width:n.totalWidth+"px",height:n.totalHeight+"px",transform:0!==n.rotationDegrees?`rotate(${n.rotationDegrees}deg)`:void 0,transformOrigin:0!==n.rotationDegrees?`${n.totalWidth/2}px ${n.totalHeight/2}px`:void 0,opacity:n.markedForRemoval?"0.5":n.opacity.toString(),pointerEvents:n.markedForRemoval?"none":"auto"}},r("div",{ref:t=>n.mount(t),style:{width:"100%",height:"100%"}})),Uc.isInstanceOf(n,"KritzelSelectionBox")&&r("div",{style:{position:"absolute",left:"0",top:"0",width:n.totalWidth+"px",height:n.totalHeight+"px",transform:0!==n.rotationDegrees?`rotate(${n.rotationDegrees}deg)`:void 0,transformOrigin:0!==n.rotationDegrees?`${n.totalWidth/2}px ${n.totalHeight/2}px`:void 0,opacity:n.markedForRemoval?"0.5":n.opacity.toString(),pointerEvents:n.markedForRemoval?"none":"auto",backgroundColor:_.resolveThemeColor(n.backgroundColor,t),borderColor:_.resolveThemeColor(n.borderColor,t),borderWidth:n.borderWidth+"px",borderStyle:"solid"}},r("div",{ref:t=>n.mount(t),style:{width:"100%",height:"100%"}})),Uc.isInstanceOf(n,"KritzelText")&&r("div",{style:{position:"absolute",left:"0",top:"0",width:n.totalWidth+"px",height:n.totalHeight+"px",transform:0!==n.rotationDegrees?`rotate(${n.rotationDegrees}deg)`:void 0,transformOrigin:0!==n.rotationDegrees?`${n.totalWidth/2}px ${n.totalHeight/2}px`:void 0,opacity:n.markedForRemoval?"0.5":n.opacity.toString(),pointerEvents:n.markedForRemoval?"none":"auto"}},r("div",{id:"text-object",ref:t=>n.mount(t),onPointerDown:t=>n.handlePointerDown(t),onPointerMove:t=>n.handlePointerMove(t),onPointerUp:t=>n.handlePointerUp(t),style:{minWidth:n.initialWidth+"px",minHeight:n.initialHeight+"px",maxWidth:"500px",height:"auto",width:"max-content",transformOrigin:"top left",transform:`scale(${n.scaleFactor})`,backgroundColor:_.resolveThemeColor(n.backgroundColor,t),overflow:"visible",textRendering:this.core.store.state.isScaling||this.core.store.state.isPanning?"optimizeSpeed":"auto"}})),Uc.isInstanceOf(n,"KritzelShape")&&r("div",{style:{position:"absolute",left:"0",top:"0",width:n.totalWidth+"px",height:n.totalHeight+"px",transform:0!==n.rotationDegrees?`rotate(${n.rotationDegrees}deg)`:void 0,transformOrigin:0!==n.rotationDegrees?`${n.totalWidth/2}px ${n.totalHeight/2}px`:void 0,opacity:n.markedForRemoval?"0.5":n.opacity.toString(),pointerEvents:n.markedForRemoval?"none":"auto"}},r("div",{ref:t=>n.mount(t),onPointerDown:t=>n.handlePointerDown(t),onPointerMove:t=>n.handlePointerMove(t),onPointerUp:t=>n.handlePointerUp(t),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:n.viewBox,preserveAspectRatio:"none"},r("path",{d:n.getSvgPath(),fill:_.resolveThemeColor(n.fillColor,t),stroke:_.resolveThemeColor(n.strokeColor,t),"stroke-width":n.strokeWidth})),r("div",{ref:t=>n.mountTextEditor(t),style:{position:"absolute",top:"0",left:"0",width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",textAlign:"center",overflow:"hidden",pointerEvents:n.isEditing?"auto":"none"}}))),this.core.store.state.debugInfo.showObjectInfo&&n.isDebugInfoVisible&&r("div",{style:{pointerEvents:"none",position:"absolute",left:`${n.totalWidth}px`,top:"0",zIndex:(n.zIndex+2).toString()}},r("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"Id: ",n.id),r("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"width: ",n.width),r("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"height: ",n.height),r("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"translateX: ",n.translateX),r("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"translateY: ",n.translateY),r("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"rotationDegrees: ",n.rotationDegrees),r("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"zIndex: ",n.zIndex)),(this.core.displaySelectionGroupUI(n)||this.core.displaySelectionLineUI(n))&&r("svg",{xmlns:"http://www.w3.org/2000/svg",style:{zIndex:(n.zIndex+1).toString(),height:n?.totalHeight.toString(),width:n?.totalWidth.toString(),left:"0",top:"0",position:"absolute",transform:`rotate(${n.rotationDegrees}deg)`,transformOrigin:`${n.totalWidth/2}px ${n.totalHeight/2}px`,overflow:"visible",pointerEvents:"none"}},this.core.displaySelectionGroupUI(n)&&r("g",{class:"selection-group-ui",style:{pointerEvents:"none"}},r("g",{class:"selection-group-borders"},r("line",{x1:"0",y1:"0",x2:n.totalWidth,y2:"0",style:{stroke:"var(--kritzel-selection-border-color, #007AFF)",strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${n.scale} / ${this.core.store.state?.scale})`,strokeLinecap:"square"}}),r("line",{x1:"0",y1:"0",x2:"0",y2:n.totalHeight,style:{stroke:"var(--kritzel-selection-border-color, #007AFF)",strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${n.scale} / ${this.core.store.state?.scale})`,strokeLinecap:"square"}}),r("line",{x1:"0",y1:n.totalHeight,x2:n.totalWidth,y2:n.totalHeight,style:{stroke:"var(--kritzel-selection-border-color, #007AFF)",strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${n.scale} / ${this.core.store.state?.scale})`,strokeLinecap:"square"}}),r("line",{x1:n.totalWidth,y1:"0",x2:n.totalWidth,y2:n.totalHeight,style:{stroke:"var(--kritzel-selection-border-color, #007AFF)",strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${n.scale} / ${this.core.store.state?.scale})`,strokeLinecap:"square"}})),!this.isSelecting&&r("g",{class:"selection-group-handles",style:{pointerEvents:"auto"}},r("rect",{class:"resize-handle top-left",x:""+-(e-1)*n.scale/this.core.store.state?.scale,y:""+-(e-1)*n.scale/this.core.store.state?.scale,width:""+2*(e-1)*n.scale/this.core.store.state?.scale,height:""+2*(e-1)*n.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #ffffff)",stroke:"var(--kritzel-selection-handle-stroke-color, #007AFF)",strokeWidth:`calc(2px * ${n.scale} / ${this.core.store.state?.scale})`,paintOrder:"fill"}}),r("rect",{class:"resize-handle-overlay top-left",x:""+-s*n.scale/this.core.store.state?.scale,y:""+-s*n.scale/this.core.store.state?.scale,width:""+2*s*n.scale/this.core.store.state?.scale,height:""+2*s*n.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}),r("rect",{class:"resize-handle top-right",x:""+(n.totalWidth-(e-1)*n.scale/this.core.store.state?.scale),y:""+-(e-1)*n.scale/this.core.store.state?.scale,width:""+2*(e-1)*n.scale/this.core.store.state?.scale,height:""+2*(e-1)*n.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #ffffff)",stroke:"var(--kritzel-selection-handle-stroke-color, #007AFF)",strokeWidth:`calc(2px * ${n.scale} / ${this.core.store.state?.scale})`,paintOrder:"fill"}}),r("rect",{class:"resize-handle-overlay top-right",x:""+(n.totalWidth-s*n.scale/this.core.store.state?.scale),y:""+-s*n.scale/this.core.store.state?.scale,width:""+2*s*n.scale/this.core.store.state?.scale,height:""+2*s*n.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}),r("rect",{class:"resize-handle bottom-left",x:""+-(e-1)*n.scale/this.core.store.state?.scale,y:""+(n.totalHeight-(e-1)*n.scale/this.core.store.state?.scale),width:""+2*(e-1)*n.scale/this.core.store.state?.scale,height:""+2*(e-1)*n.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #ffffff)",stroke:"var(--kritzel-selection-handle-stroke-color, #007AFF)",strokeWidth:`calc(2px * ${n.scale} / ${this.core.store.state?.scale})`,paintOrder:"fill"}}),r("rect",{class:"resize-handle-overlay bottom-left",x:""+-s*n.scale/this.core.store.state?.scale,y:""+(n.totalHeight-s*n.scale/this.core.store.state?.scale),width:""+2*s*n.scale/this.core.store.state?.scale,height:""+2*s*n.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}),r("rect",{class:"resize-handle bottom-right",x:""+(n.totalWidth-(e-1)*n.scale/this.core.store.state?.scale),y:""+(n.totalHeight-(e-1)*n.scale/this.core.store.state?.scale),width:""+2*(e-1)*n.scale/this.core.store.state?.scale,height:""+2*(e-1)*n.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #ffffff)",stroke:"var(--kritzel-selection-handle-stroke-color, #007AFF)",strokeWidth:`calc(2px * ${n.scale} / ${this.core.store.state?.scale})`,paintOrder:"fill"}}),r("rect",{class:"resize-handle-overlay bottom-right",x:""+(n.totalWidth-s*n.scale/this.core.store.state?.scale),y:""+(n.totalHeight-s*n.scale/this.core.store.state?.scale),width:""+2*s*n.scale/this.core.store.state?.scale,height:""+2*s*n.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}),r("line",{x1:n.totalWidth/2,y1:"0",x2:n.totalWidth/2,y2:-15*n.scale/this.core.store.state?.scale,style:{stroke:"var(--kritzel-selection-border-color, #007AFF)",strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${n.scale} / ${this.core.store.state?.scale})`}}),r("circle",{class:"rotation-handle",cx:n.totalWidth/2,cy:-15*n.scale/this.core.store.state?.scale,r:""+(e-1)*n.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #ffffff)",stroke:"var(--kritzel-selection-handle-stroke-color, #007AFF)",strokeWidth:`calc(2px * ${n.scale} / ${this.core.store.state?.scale})`,paintOrder:"fill"}}),r("circle",{class:"rotation-handle-overlay",cx:n.totalWidth/2,cy:-15*n.scale/this.core.store.state?.scale,r:""+s*n.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}))),this.core.displaySelectionLineUI(n)&&Uc.isInstanceOf(n,"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(n,!0),style:{stroke:"var(--kritzel-selection-border-color, #007AFF)",strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${n.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:n.startX-n.x,cy:n.startY-n.y,r:""+(e-1)*n.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #000000)",stroke:"var(--kritzel-selection-handle-stroke-color, #007AFF)",strokeWidth:`calc(2px * ${n.scale} / ${this.core.store.state?.scale})`,paintOrder:"fill"}}),r("circle",{class:"selection-line-handle-overlay start",cx:n.startX-n.x,cy:n.startY-n.y,r:""+s*n.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}),r("circle",{class:"selection-line-handle center",cx:void 0!==n.controlX?(n.startX+2*n.controlX+n.endX)/4-n.x:(n.startX-n.x+n.endX-n.x)/2,cy:void 0!==n.controlY?(n.startY+2*n.controlY+n.endY)/4-n.y:(n.startY-n.y+n.endY-n.y)/2,r:""+(e-1)*n.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #000000)",stroke:"var(--kritzel-selection-handle-stroke-color, #007AFF)",strokeWidth:`calc(2px * ${n.scale} / ${this.core.store.state?.scale})`,paintOrder:"fill"}}),r("circle",{class:"selection-line-handle-overlay center",cx:void 0!==n.controlX?(n.startX+2*n.controlX+n.endX)/4-n.x:(n.startX-n.x+n.endX-n.x)/2,cy:void 0!==n.controlY?(n.startY+2*n.controlY+n.endY)/4-n.y:(n.startY-n.y+n.endY-n.y)/2,r:""+s*n.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}),r("circle",{class:"selection-line-handle end",cx:n.endX-n.x,cy:n.endY-n.y,r:""+(e-1)*n.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #000000)",stroke:"var(--kritzel-selection-handle-stroke-color, #007AFF)",strokeWidth:`calc(2px * ${n.scale} / ${this.core.store.state?.scale})`,paintOrder:"fill"}}),r("circle",{class:"selection-line-handle-overlay end",cx:n.endX-n.x,cy:n.endY-n.y,r:""+s*n.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:"b9171dfffeb4a88bc4ad9a7b0196a18f5427183f",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 R&&!this.core.store.state.isScaling&&r("kritzel-cursor-trail",{key:"d3ce01397575891a78449128020a212345332d06",core:this.core}))}static get watchers(){return{workspace:[{onWorkspaceChange:0}],scaleMax:[{validateScaleMax:0}],scaleMin:[{validateScaleMin:0}],cursorTarget:[{onCursorTargetChange:0}],lockDrawingScale:[{onLockDrawingScaleChange:0}],theme:[{onThemeChange: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],lockDrawingScale:[4,"lock-drawing-scale"],theme:[1],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],backToContent:[64],getCopiedObjects:[64],getScreenshot:[64],exportViewportAsPng:[64],exportViewportAsSvg:[64],createWorkspace:[64],updateWorkspace:[64],deleteWorkspace:[64],getWorkspaces:[64],getActiveWorkspace:[64]},[[1,"wheel","handleWheel"],[0,"pointerdown","handlePointerDown"],[0,"pointermove","handlePointerMove"],[0,"pointerup","handlePointerUp"],[0,"pointercancel","handlePointerCancel"],[1,"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}],lockDrawingScale:[{onLockDrawingScaleChange:0}],theme:[{onThemeChange:0}]}]);function Ih(){"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),jh);break;case"kritzel-context-menu":customElements.get(s(t))||E();break;case"kritzel-cursor-trail":customElements.get(s(t))||D();break;case"kritzel-icon":customElements.get(s(t))||j()}}))}export{he as A,_t as B,Dt as C,wc as D,gt as E,bt as F,Tc as G,$c as H,eu as I,jc as J,R as K,Ic as L,Oc as M,Ih as N,jt as O,jh as P,an as a,$n as b,mi as c,Si as d,Ai as e,Jt as f,Cn as g,xt as h,ke as i,me as j,be as k,Xn as l,jn as m,It as n,Yn as o,Nn as p,ce as q,Tn as r,At as s,tn as t,cn as u,Qn as v,rn as w,te as x,Ut as y,Zt as z}
9
+ */class Fc{_core;_debounceUpdate;_debounceEndScaling;_animationFrameId=null;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=Rc.debounce((()=>{this._core.updateWorkspaceViewport(this._core.store.state.translateX,this._core.store.state.translateY,this._core.store.state.scale)}),300),this._debounceEndScaling=Rc.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(this.cancelViewportAnimation(),"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||"pen"===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.isSelecting&&(this._core.store.state.isSelecting=!1,this._core.store.state.objects.remove((t=>t instanceof d)),this._core.store.allNonSelectionObjects.forEach((t=>{t.isSelected=!1}))),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||"pen"===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,a=this._core.store.state.scale*c;if(a>this._core.store.state.scaleMax||a<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=a,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&&"pen"!==t.pointerType||0===this._core.store.state.pointers.size&&this._debounceEndScaling()}handleWheel(t){this.cancelViewportAnimation(),t.ctrlKey?this.handleZoom(t):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,0!==t.deltaX&&(this._core.store.state.translateX-=.8*t.deltaX),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()}cancelViewportAnimation(){null!==this._animationFrameId&&(cancelAnimationFrame(this._animationFrameId),this._animationFrameId=null)}animateViewportTo(t,n,e,r=150){this.cancelViewportAnimation();const i=this._core.store.state.translateX,s=this._core.store.state.translateY,o=this._core.store.state.scale,u=performance.now(),c=a=>{const h=Math.min((a-u)/r,1),l=1-Math.pow(1-h,3);this._core.store.state.translateX=i+(t-i)*l,this._core.store.state.translateY=s+(n-s)*l,this._core.store.state.scale=o+(e-o)*l,this._core.store.state.hasViewportChanged=!0,this._core.rerender(),h<1?this._animationFrameId=requestAnimationFrame(c):(this._animationFrameId=null,this._debounceUpdate())};this._animationFrameId=requestAnimationFrame(c)}centerFitNearestContent(t=20){const n=this._core.store.allNonSelectionObjects;if(0===n.length)return!1;const e=-this._core.store.state.translateX/this._core.store.state.scale+this._core.store.state.viewportWidth/2/this._core.store.state.scale,r=-this._core.store.state.translateY/this._core.store.state.scale+this._core.store.state.viewportHeight/2/this._core.store.state.scale,i=n.map((t=>{const n=t.rotatedBoundingBox,i=n.y+n.height/2;return{obj:t,distance:Math.sqrt(Math.pow(n.x+n.width/2-e,2)+Math.pow(i-r,2))}}));i.sort(((t,n)=>t.distance-n.distance));const s=i.slice(0,t).map((t=>t.obj));let o=1/0,u=1/0,c=-1/0,a=-1/0;for(const t of s){const n=t.rotatedBoundingBox;o=Math.min(o,n.x),u=Math.min(u,n.y),c=Math.max(c,n.x+n.width),a=Math.max(a,n.y+n.height)}const h=c-o,l=a-u,f=o+h/2,d=u+l/2,p=Math.min(this._core.store.state.viewportWidth/(1.1*h),this._core.store.state.viewportHeight/(1.1*l),this._core.store.state.scaleMax),v=Math.max(p,this._core.store.state.scaleMin);return this.animateViewportTo(this._core.store.state.viewportWidth/2-f*v,this._core.store.state.viewportHeight/2-d*v,v),!0}}class Lc extends v{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=h.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 Wc extends v{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 p)&&!(e instanceof d)){const t=p.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 Bc={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"},lockDrawingScale:!0};class Nc extends y{__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 Nc(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 Kc{_core;constructor(t){this._core=t}revive(t){if(t&&"object"==typeof t){if(t.__class__){let n;switch(t.__class__){case"KritzelPath":n=S.create(this._core).deserialize(t);break;case"KritzelLine":n=l.create(this._core).deserialize(t);break;case"KritzelText":n=M.create(this._core,t.fontSize,t.fontFamily).deserialize(t);break;case"KritzelShape":n=x.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=a.create(this._core).deserialize(t);break;case"KritzelCustomElement":n=Nc.create(this._core).deserialize(t);break;case"KritzelSelectionGroup":n=p.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 k(this._core);break;case"KritzelEraserTool":n=new R(this._core);break;case"KritzelImageTool":n=new gt(this._core);break;case"KritzelSelectionTool":n=new w(this._core);break;case"KritzelTextTool":n=new m(this._core);break;case"KritzelLineTool":n=new b(this._core);break;case"KritzelShapeTool":n=new g(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 Hc{bounds;capacity;objects=[];children=null;_size=0;get size(){return this._size}constructor(t,n=16){this.bounds=t,this.capacity=n}reset(){this.objects=[],this.children=null,this._size=0}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),this._size++,!0;null===this.children&&this.subdivide();for(const n of this.children)if(n.insert(t))return this._size++,!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){let n=0;const e=this.objects.findIndex((n=>t(n)));if(-1!==e&&(this.objects.splice(e,1),n++),null!==this.children)for(const e of this.children)n+=e.remove(t);return this._size-=n,n}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 Hc({x:t,y:n,z:e,width:s,height:o},this.capacity),new Hc({x:t+s,y:n,z:e,width:s,height:o},this.capacity),new Hc({x:t,y:n+o,z:e,width:s,height:o},this.capacity),new Hc({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 Vc{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}}get totalCount(){return this.quadtree.size}constructor(){this.quadtree=new Hc({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 Kc(t),this._ydoc=new ai,this._objectsMap=this._ydoc.getMap("objects");const r=`kritzel-workspace-${n}`,i=e??Ec;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 es([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 p?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 p||t instanceof d))).map((t=>t.zIndex)))+1}get totalObjectCount(){return this._state.objects.totalCount}get allObjects(){return this._state.objects.allObjects()}get objectsInViewport(){return this._state.objects.query({x:-this._state.translateX/this._state.scale,y:-this._state.translateY/this._state.scale,z:this._state.scale,width:this._state.viewportWidth/this._state.scale,height:this._state.viewportHeight/this._state.scale,depth:100}).filter((t=>!(t instanceof p||t instanceof d))).sort(((t,n)=>t.zIndex-n.zIndex))}get allNonSelectionObjects(){return this._state.objects.allObjects().filter((t=>!(t instanceof p||t instanceof d)))}get selectedObjects(){return this.allObjects.filter((t=>!(t instanceof p))).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 p));return t.length>0?t[0]:null}get activeText(){const t=this._state.objects.filter((t=>t instanceof M&&t.isEditing));return t.length>0?t[0]:null}get activeShape(){const t=this._state.objects.filter((t=>t instanceof x&&t.isEditing));return t.length>0?t[0]:null}get currentPath(){const t=this._state.objects.filter((t=>t instanceof S&&!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 Vc}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-global-pointer-cursor")),this._targetElement=t,this._targetElement&&this._targetElement.style.setProperty("--kritzel-global-pointer-cursor",bt.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=bt.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 Xc{_kritzelEngine;_store;_syncConfig;_appStateMap;_anchorManager;_cursorManager;_themeManager;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}get themeManager(){return this._themeManager}constructor(t){this._kritzelEngine=t,this._store=new Qc(Bc),this._appStateMap=new Tc,this._anchorManager=new jc(this),this._cursorManager=new Yc(this),this._themeManager=new O(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(T.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 Vc;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()}getObjectsInViewport(){return 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 instanceof p||t instanceof d))).sort(((t,n)=>t.zIndex-n.zIndex))}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.engine.viewport?.cancelPendingUpdates(),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&&this._store.state.workspaces.some((t=>t.id===r.id))&&(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){const e=[];for(const r in n)n.hasOwnProperty(r)&&(t[r]=n[r],e.push(r));t.onAfterUpdate(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,a;void 0!==t&&void 0!==n?(c=t,a=n):s?(c=o,a=u):(c=o+25/this._store.state.scale,a=u+25/this._store.state.scale);const f=c-o,d=a-u;this.removeSelectionGroup(),this.removeSelectionBox();const v=p.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),v.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(),v.isSelected=!0,1===e.length&&(v.rotation=e[0].rotation),this.addSelectionGroup(v),s&&(void 0!==t&&void 0!==n?v.updatePosition(t,n):v.centerInViewport(),this.engine.viewport.centerFitInViewport(v)),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",h.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=p.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=p.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=p.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 p||t instanceof d||t instanceof $)));if(t.length>0){const n=p.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",h.getTool("selection")),this.rerender()}}clearSelection(){this.removeSelectionGroup(),this._store.state.objects.remove((t=>t instanceof d||t instanceof p)),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",h.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 qc=(()=>{let t=0;return()=>(t+=1,`u${`0000${(Math.random()*36**4|0).toString(36)}`.slice(-4)}${t}`)})();function Gc(t){const n=[];for(let e=0,r=t.length;e<r;e++)n.push(t[e]);return n}let Jc=null;function Zc(t={}){return Jc||(t.includeStyleProperties?(Jc=t.includeStyleProperties,Jc):(Jc=Gc(window.getComputedStyle(document.documentElement)),Jc))}function ta(t,n){const e=(t.ownerDocument.defaultView||window).getComputedStyle(t).getPropertyValue(n);return e?parseFloat(e.replace("px","")):0}function na(t,n={}){return{width:n.width||function(t){const n=ta(t,"border-left-width"),e=ta(t,"border-right-width");return t.clientWidth+n+e}(t),height:n.height||function(t){const n=ta(t,"border-top-width"),e=ta(t,"border-bottom-width");return t.clientHeight+n+e}(t)}}const ea=16384;function ra(t){return new Promise(((n,e)=>{const r=new Image;r.onload=()=>{r.decode().then((()=>{requestAnimationFrame((()=>n(r)))}))},r.onerror=e,r.crossOrigin="anonymous",r.decoding="async",r.src=t}))}const ia=(t,n)=>{if(t instanceof n)return!0;const e=Object.getPrototypeOf(t);return null!==e&&(e.constructor.name===n.name||ia(e,n))};function sa(t,n,e,r){const i=window.getComputedStyle(t,e),s=i.getPropertyValue("content");if(""===s||"none"===s)return;const o=qc();try{n.className=`${n.className} ${o}`}catch(t){return}const u=document.createElement("style");u.appendChild(function(t,n,e,r){const i=`.${t}:${n}`,s=e.cssText?function(t){const n=t.getPropertyValue("content");return`${t.cssText} content: '${n.replace(/'|"/g,"")}';`}(e):function(t,n){return Zc(n).map((n=>`${n}: ${t.getPropertyValue(n)}${t.getPropertyPriority(n)?" !important":""};`)).join(" ")}(e,r);return document.createTextNode(`${i}{${s}}`)}(o,e,i,r)),n.appendChild(u)}const oa="application/font-woff",ua="image/jpeg",ca={woff:oa,woff2:oa,ttf:"application/font-truetype",eot:"application/vnd.ms-fontobject",png:"image/png",jpg:ua,jpeg:ua,gif:"image/gif",tiff:"image/tiff",svg:"image/svg+xml",webp:"image/webp"};function aa(t){const n=function(t){const n=/\.([^./]*?)$/g.exec(t);return n?n[1]:""}(t).toLowerCase();return ca[n]||""}function ha(t){return-1!==t.search(/^(data:)/)}async function la(t,n,e){const r=await fetch(t,n);if(404===r.status)throw new Error(`Resource "${r.url}" not found`);const i=await r.blob();return new Promise(((t,n)=>{const s=new FileReader;s.onerror=n,s.onloadend=()=>{try{t(e({res:r,result:s.result}))}catch(t){n(t)}},s.readAsDataURL(i)}))}const fa={};async function da(t,n,e){const r=function(t,n,e){let r=t.replace(/\?.*/,"");return e&&(r=t),/ttf|otf|eot|woff2?/i.test(r)&&(r=r.replace(/.*\//,"")),n?`[${n}]${r}`:r}(t,n,e.includeQueryParams);if(null!=fa[r])return fa[r];let i;e.cacheBust&&(t+=(/\?/.test(t)?"&":"?")+(new Date).getTime());try{const r=await la(t,e.fetchRequestInit,(({res:t,result:e})=>(n||(n=t.headers.get("Content-Type")||""),function(t){return t.split(/,/)[1]}(e))));i=function(t,n){return`data:${n};base64,${t}`}(r,n)}catch(n){i=e.imagePlaceholder||"";let r=`Failed to fetch resource: ${t}`;n&&(r="string"==typeof n?n:n.message),r&&console.warn(r)}return fa[r]=i,i}const pa=t=>null!=t.tagName&&"SLOT"===t.tagName.toUpperCase(),va=t=>null!=t.tagName&&"SVG"===t.tagName.toUpperCase();async function wa(t,n,e){return e||!n.filter||n.filter(t)?Promise.resolve(t).then((t=>async function(t,n){return ia(t,HTMLCanvasElement)?async function(t){const n=t.toDataURL();return"data:,"===n?t.cloneNode(!1):ra(n)}(t):ia(t,HTMLVideoElement)?async function(t,n){if(t.currentSrc){const n=document.createElement("canvas"),e=n.getContext("2d");return n.width=t.clientWidth,n.height=t.clientHeight,null==e||e.drawImage(t,0,0,n.width,n.height),ra(n.toDataURL())}const e=t.poster,r=aa(e);return ra(await da(e,r,n))}(t,n):ia(t,HTMLIFrameElement)?async function(t,n){var e;try{if(null===(e=null==t?void 0:t.contentDocument)||void 0===e?void 0:e.body)return await wa(t.contentDocument.body,n,!0)}catch(t){}return t.cloneNode(!1)}(t,n):t.cloneNode(va(t))}(t,n))).then((e=>async function(t,n,e){var r,i;if(va(n))return n;let s=[];return s=pa(t)&&t.assignedNodes?Gc(t.assignedNodes()):ia(t,HTMLIFrameElement)&&(null===(r=t.contentDocument)||void 0===r?void 0:r.body)?Gc(t.contentDocument.body.childNodes):Gc((null!==(i=t.shadowRoot)&&void 0!==i?i:t).childNodes),0===s.length||ia(t,HTMLVideoElement)||await s.reduce(((t,r)=>t.then((()=>wa(r,e))).then((t=>{t&&n.appendChild(t)}))),Promise.resolve()),n}(t,e,n))).then((e=>function(t,n,e){return ia(n,Element)&&(function(t,n,e){const r=n.style;if(!r)return;const i=window.getComputedStyle(t);i.cssText?(r.cssText=i.cssText,r.transformOrigin=i.transformOrigin):Zc(e).forEach((e=>{let s=i.getPropertyValue(e);if("font-size"===e&&s.endsWith("px")){const t=Math.floor(parseFloat(s.substring(0,s.length-2)))-.1;s=`${t}px`}ia(t,HTMLIFrameElement)&&"display"===e&&"inline"===s&&(s="block"),"d"===e&&n.getAttribute("d")&&(s=`path(${n.getAttribute("d")})`),r.setProperty(e,s,i.getPropertyPriority(e))}))}(t,n,e),function(t,n,e){sa(t,n,":before",e),sa(t,n,":after",e)}(t,n,e),function(t,n){ia(t,HTMLTextAreaElement)&&(n.innerHTML=t.value),ia(t,HTMLInputElement)&&n.setAttribute("value",t.value)}(t,n),function(t,n){if(ia(t,HTMLSelectElement)){const e=Array.from(n.children).find((n=>t.value===n.getAttribute("value")));e&&e.setAttribute("selected","")}}(t,n)),n}(t,e,n))).then((t=>async function(t,n){const e=t.querySelectorAll?t.querySelectorAll("use"):[];if(0===e.length)return t;const r={};for(let i=0;i<e.length;i++){const s=e[i].getAttribute("xlink:href");if(s){const e=t.querySelector(s),i=document.querySelector(s);e||!i||r[s]||(r[s]=await wa(i,n,!0))}}const i=Object.values(r);if(i.length){const n="http://www.w3.org/1999/xhtml",e=document.createElementNS(n,"svg");e.setAttribute("xmlns",n),e.style.position="absolute",e.style.width="0",e.style.height="0",e.style.overflow="hidden",e.style.display="none";const r=document.createElementNS(n,"defs");e.appendChild(r);for(let t=0;t<i.length;t++)r.appendChild(i[t]);t.appendChild(e)}return t}(t,n))):null}const ya=/url\((['"]?)([^'"]+?)\1\)/g,ga=/url\([^)]+\)\s*format\((["']?)([^"']+)\1\)/g,ba=/src:\s*(?:url\([^)]+\)\s*format\([^)]+\)[,;]\s*)+/g;function ma(t){return-1!==t.search(ya)}async function ka(t,n,e){if(!ma(t))return t;const r=function(t,{preferredFontFormat:n}){return n?t.replace(ba,(t=>{for(;;){const[e,,r]=ga.exec(t)||[];if(!r)return"";if(r===n)return`src: ${e};`}})):t}(t,e),i=function(t){const n=[];return t.replace(ya,((t,e,r)=>(n.push(r),t))),n.filter((t=>!ha(t)))}(r);return i.reduce(((t,r)=>t.then((t=>async function(t,n,e,r){try{const i=e?function(t,n){if(t.match(/^[a-z]+:\/\//i))return t;if(t.match(/^\/\//))return window.location.protocol+t;if(t.match(/^[a-z]+:/i))return t;const e=document.implementation.createHTMLDocument(),r=e.createElement("base"),i=e.createElement("a");return e.head.appendChild(r),e.body.appendChild(i),n&&(r.href=n),i.href=t,i.href}(n,e):n,s=aa(n);let o;return o=await da(i,s,r),t.replace(function(t){const n=t.replace(/([.*+?^${}()|\[\]\/\\])/g,"\\$1");return new RegExp(`(url\\(['"]?)(${n})(['"]?\\))`,"g")}(n),`$1${o}$3`)}catch(t){}return t}(t,r,n,e)))),Promise.resolve(r))}async function Aa(t,n,e){var r;const i=null===(r=n.style)||void 0===r?void 0:r.getPropertyValue(t);if(i){const r=await ka(i,null,e);return n.style.setProperty(t,r,n.style.getPropertyPriority(t)),!0}return!1}async function xa(t,n){ia(t,Element)&&(await async function(t,n){await Aa("background",t,n)||await Aa("background-image",t,n),await Aa("mask",t,n)||await Aa("-webkit-mask",t,n)||await Aa("mask-image",t,n)||await Aa("-webkit-mask-image",t,n)}(t,n),await async function(t,n){const e=ia(t,HTMLImageElement);if((!e||ha(t.src))&&(!ia(t,SVGImageElement)||ha(t.href.baseVal)))return;const r=e?t.src:t.href.baseVal,i=await da(r,aa(r),n);await new Promise(((r,s)=>{t.onload=r,t.onerror=n.onImageErrorHandler?(...t)=>{try{r(n.onImageErrorHandler(...t))}catch(t){s(t)}}:s;const o=t;o.decode&&(o.decode=r),"lazy"===o.loading&&(o.loading="eager"),e?(t.srcset="",t.src=i):t.href.baseVal=i}))}(t,n),await async function(t,n){const e=Gc(t.childNodes).map((t=>xa(t,n)));await Promise.all(e).then((()=>t))}(t,n))}const Ma={};async function Sa(t){let n=Ma[t];if(null!=n)return n;const e=await fetch(t);return n={url:t,cssText:await e.text()},Ma[t]=n,n}async function Ca(t,n){let e=t.cssText;const r=/url\(["']?([^"')]+)["']?\)/g,i=(e.match(/url\([^)]+\)/g)||[]).map((async i=>{let s=i.replace(r,"$1");return s.startsWith("https://")||(s=new URL(s,t.url).href),la(s,n.fetchRequestInit,(({result:t})=>(e=e.replace(i,`url(${t})`),[i,t])))}));return Promise.all(i).then((()=>e))}function $a(t){if(null==t)return[];const n=[];let e=t.replace(/(\/\*[\s\S]*?\*\/)/gi,"");const r=new RegExp("((@.*?keyframes [\\s\\S]*?){([\\s\\S]*?}\\s*?)})","gi");for(;;){const t=r.exec(e);if(null===t)break;n.push(t[0])}e=e.replace(r,"");const i=/@import[\s\S]*?url\([^)]*\)[\s\S]*?;/gi,s=new RegExp("((\\s*?(?:\\/\\*[\\s\\S]*?\\*\\/)?\\s*?@media[\\s\\S]*?){([\\s\\S]*?)}\\s*?})|(([\\s\\S]*?){([\\s\\S]*?)})","gi");for(;;){let t=i.exec(e);if(null===t){if(t=s.exec(e),null===t)break;i.lastIndex=s.lastIndex}else s.lastIndex=i.lastIndex;n.push(t[0])}return n}function Ea(t){return t.trim().replace(/["']/g,"")}async function Ta(t,n){const e=await async function(t,n){if(null==t.ownerDocument)throw new Error("Provided element is not within a Document");const e=Gc(t.ownerDocument.styleSheets),r=await async function(t,n){const e=[],r=[];return t.forEach((e=>{if("cssRules"in e)try{Gc(e.cssRules||[]).forEach(((t,i)=>{if(t.type===CSSRule.IMPORT_RULE){let s=i+1;const o=Sa(t.href).then((t=>Ca(t,n))).then((t=>$a(t).forEach((t=>{try{e.insertRule(t,t.startsWith("@import")?s+=1:e.cssRules.length)}catch(n){console.error("Error inserting rule from remote css",{rule:t,error:n})}})))).catch((t=>{console.error("Error loading remote css",t.toString())}));r.push(o)}}))}catch(i){const s=t.find((t=>null==t.href))||document.styleSheets[0];null!=e.href&&r.push(Sa(e.href).then((t=>Ca(t,n))).then((t=>$a(t).forEach((t=>{s.insertRule(t,s.cssRules.length)})))).catch((t=>{console.error("Error loading remote stylesheet",t)}))),console.error("Error inlining remote css file",i)}})),Promise.all(r).then((()=>(t.forEach((t=>{if("cssRules"in t)try{Gc(t.cssRules||[]).forEach((t=>{e.push(t)}))}catch(n){console.error(`Error while reading CSS rules from ${t.href}`,n)}})),e)))}(e,n);return function(t){return t.filter((t=>t.type===CSSRule.FONT_FACE_RULE)).filter((t=>ma(t.style.getPropertyValue("src"))))}(r)}(t,n),r=function(t){const n=new Set;return function t(e){(e.style.fontFamily||getComputedStyle(e).fontFamily).split(",").forEach((t=>{n.add(Ea(t))})),Array.from(e.children).forEach((n=>{n instanceof HTMLElement&&t(n)}))}(t),n}(t);return(await Promise.all(e.filter((t=>r.has(Ea(t.style.fontFamily)))).map((t=>ka(t.cssText,t.parentStyleSheet?t.parentStyleSheet.href:null,n))))).join("\n")}async function Ua(t,n={}){const{width:e,height:r}=na(t,n),i=await wa(t,n,!0);return await async function(t,n){const e=null!=n.fontEmbedCSS?n.fontEmbedCSS:n.skipFonts?null:await Ta(t,n);if(e){const n=document.createElement("style"),r=document.createTextNode(e);n.appendChild(r),t.firstChild?t.insertBefore(n,t.firstChild):t.appendChild(n)}}(i,n),await xa(i,n),function(t,n){const{style:e}=t;n.backgroundColor&&(e.backgroundColor=n.backgroundColor),n.width&&(e.width=`${n.width}px`),n.height&&(e.height=`${n.height}px`);const r=n.style;null!=r&&Object.keys(r).forEach((t=>{e[t]=r[t]}))}(i,n),await async function(t,n,e){const r="http://www.w3.org/2000/svg",i=document.createElementNS(r,"svg"),s=document.createElementNS(r,"foreignObject");return i.setAttribute("width",`${n}`),i.setAttribute("height",`${e}`),i.setAttribute("viewBox",`0 0 ${n} ${e}`),s.setAttribute("width","100%"),s.setAttribute("height","100%"),s.setAttribute("x","0"),s.setAttribute("y","0"),s.setAttribute("externalResourcesRequired","true"),i.appendChild(s),s.appendChild(t),async function(t){return Promise.resolve().then((()=>(new XMLSerializer).serializeToString(t))).then(encodeURIComponent).then((t=>`data:image/svg+xml;charset=utf-8,${t}`))}(i)}(i,e,r)}const ja=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=Ic;validateScaleMax(t){t>Ic?(console.warn("scaleMax cannot be greater than 1000."),this.scaleMax=Ic,this.core.store.state.scaleMax=this.scaleMax):this.core.store.state.scaleMax=t}scaleMin=Oc;validateScaleMin(t){t<Oc?(console.warn("scaleMin cannot be less than 0.0001."),this.scaleMin=Oc,this.core.store.state.scaleMin=this.scaleMin):this.core.store.state.scaleMin=t}cursorTarget;onCursorTargetChange(t){this.core.cursorManager.setTargetElement(t||document.body)}lockDrawingScale=!0;onLockDrawingScaleChange(t){this.core.store.state.lockDrawingScale=t}theme="light";onThemeChange(t){this.core.themeManager.setTheme(t)}isEngineReady;activeToolChange;objectsSelectionChange;workspacesChange;longpress;objectsChange;undoStateChange;objectsInViewportChange;forceUpdate=0;async triggerSelectionChange(){this.objectsSelectionChange.emit()}handleWheel(t){this.core.store.isDisabled||(this.core.store.state.isContextMenuVisible&&this.hideContextMenu(),this.viewport.handleWheel(t),this.core.store.state?.activeTool?.handleWheel(t))}handlePointerDown(t){this.core.store.isDisabled||(z.isTouchDevice()&&c.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=Rc.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.hasPointerCapture(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.hasPointerCapture(t.pointerId)&&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&&"pen"!==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 u))return console.error(`Failed to register tool "${t}": Tool class must be a constructor function`),null;const r=h.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",h.getTool("selection")),this.core.deselectAllObjects(),this.core.selectObjects(t)}async selectAllObjectsInViewport(){this.core.store.state.activeTool?.onDeactivate(),this.core.store.setState("activeTool",h.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 backToContent(){return this.viewport.centerFitNearestContent(20)}async getCopiedObjects(){return this.core.store.state.copiedObjects||[]}async getScreenshot(t="png"){if(!this.host)return null;const n={objects:this.core.store.state.objects,activeWorkspace:this.core.store.state.activeWorkspace,workspaces:this.core.store.state.workspaces,activeTool:this.core.store.state.activeTool,isReady:this.core.store.state.isReady,translateX:this.core.store.state.translateX,translateY:this.core.store.state.translateY,scale:this.core.store.state.scale},e={filter:t=>!("KRITZEL-CONTEXT-MENU"===t.tagName||t.classList&&t.classList.contains("debug-panel"))};let r;try{r="svg"===t?await Ua(this.host,e):await async function(t,n={}){return(await async function(t,n={}){const{width:e,height:r}=na(t,n),i=await Ua(t,n),s=await ra(i),o=document.createElement("canvas"),u=o.getContext("2d"),c=n.pixelRatio||function(){let t,n;try{n=process}catch(t){}const e=n&&n.env?n.env.devicePixelRatio:null;return e&&(t=parseInt(e,10),Number.isNaN(t)&&(t=1)),t||window.devicePixelRatio||1}(),a=n.canvasWidth||e,h=n.canvasHeight||r;return o.width=a*c,o.height=h*c,n.skipAutoScale||function(t){(t.width>ea||t.height>ea)&&(t.width>ea&&t.height>ea?t.width>t.height?(t.height*=ea/t.width,t.width=ea):(t.width*=ea/t.height,t.height=ea):t.width>ea?(t.height*=ea/t.width,t.width=ea):(t.width*=ea/t.height,t.height=ea))}(o),o.style.width=`${a}`,o.style.height=`${h}`,n.backgroundColor&&(u.fillStyle=n.backgroundColor,u.fillRect(0,0,o.width,o.height)),u.drawImage(s,0,0,o.width,o.height),o}(t,n)).toDataURL()}(this.host,e)}finally{this.core.store.state.objects=n.objects,this.core.store.state.activeWorkspace=n.activeWorkspace,this.core.store.state.workspaces=n.workspaces,this.core.store.state.activeTool=n.activeTool,this.core.store.state.isReady=n.isReady,this.core.store.state.translateX=n.translateX,this.core.store.state.translateY=n.translateY,this.core.store.state.scale=n.scale,this.core.rerender()}return r}async exportViewportAsPng(){try{const t=`${this.core.store.state?.activeWorkspace?.name||"workspace"}-${(new Date).toISOString().replace(/[:.]/g,"-")}.png`,n=await this.getScreenshot("png"),e=document.createElement("a");e.download=t,e.href=n,e.click()}catch(t){console.error("Failed to export viewport as PNG:",t)}}async exportViewportAsSvg(){try{const t=`${this.core.store.state?.activeWorkspace?.name||"workspace"}-${(new Date).toISOString().replace(/[:.]/g,"-")}.svg`,n=await this.getScreenshot("svg"),e=document.createElement("a");e.download=t,e.href=n,e.click()}catch(t){console.error("Failed to export viewport as SVG:",t)}}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;_lastHadSelectionGroup=!1;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.objectsInViewportChange=e(this,"objectsInViewportChange"),this.core=new Xc(this)}disconnectedCallback(){this.throttledPointerMoveMulti.cancel(),this.core.cursorManager.cleanup()}componentWillLoad(){this.validateScaleMax(this.scaleMax),this.validateScaleMin(this.scaleMin),this.core.store.state.lockDrawingScale=this.lockDrawingScale}async componentDidLoad(){this.contextMenuHandler=new Wc(this.core,this.globalContextMenuItems,this.objectContextMenuItems),this.keyHandler=new Lc(this.core),this.viewport=new Fc(this.core,this.host),this.core.cursorManager.setTargetElement(this.cursorTarget||document.body),this.core.cursorManager.setShadowRoot(this.host.shadowRoot);const t=this.host.closest("kritzel-editor");this.core.themeManager.setTargetElement(t||this.host),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,n=null!==this.core.store.selectionGroup;this.objectsChange.emit(this.core.store.allObjects),this.undoStateChange.emit(t),this._lastHadSelectionGroup!==n&&(this._lastHadSelectionGroup=n,this.objectsSelectionChange.emit())}_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),C.forceHideKeyboard(),this.core.rerender()}render(){const t=O.getStoredTheme(),n=window.getComputedStyle(this.host).getPropertyValue("--kritzel-selection-handle-size").trim()||"6px",e=parseFloat(n),s=2*e<14?14:e,o=this.core.store.state.viewportWidth/2+this.core.store.state.translateX,u=this.core.store.state.viewportHeight/2+this.core.store.state.translateY,c=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(),this.core.store.totalObjectCount>0&&this.objectsInViewportChange.emit(c),r(i,{key:"6cc974d4e3fdcfe1b185a014fa9eb6b1243dde91"},this.core.store.state.debugInfo.showViewportInfo&&r("div",{key:"8f8ac08f2d643b664e2b39fbaf50e0c474c5255d",class:"debug-panel"},r("div",{key:"79ad4f3db958d8b17b2efdb3a1a6ab24d81bb436"},"ActiveWorkspaceId: ",this.core.store.state?.activeWorkspace?.id),r("div",{key:"0cdaa6abeebc865eec1c3026d5fd38e00bd388a7"},"ActiveWorkspaceName: ",this.core.store.state?.activeWorkspace?.name),r("div",{key:"125ca4bb69ca2fcc647bd55e9cb8c4072fbaa600"},"TranslateX: ",this.core.store.state?.translateX),r("div",{key:"02aee9b8359b9cdefa2f54afc26d328dab984ea3"},"TranslateY: ",this.core.store.state?.translateY),r("div",{key:"8398e28a5c70318dace386182633088e5e3267d5"},"ViewportWidth: ",this.core.store.state?.viewportWidth),r("div",{key:"0e17a7fbf96acbe1cbf2769b0fa853eaf7fb6f3b"},"ViewportHeight: ",this.core.store.state?.viewportHeight),r("div",{key:"d214e66618d2c38ca94154e7b06f681d815ffadc"},"PointerCount: ",this.core.store.state.pointers.size),r("div",{key:"35695f7f82605bf6ba0fd512f814a7da723f623c"},"Scale: ",this.core.store.state?.scale),r("div",{key:"6935c9e5cedb8f7bd6d81a5d02b383fbb0e4d3a2"},"ActiveTool: ",this.core.store.state?.activeTool?.name),r("div",{key:"6a7490a07ca3019157d6a4b10b9164d3a504c4c0"},"HasViewportChanged: ",this.core.store.state?.hasViewportChanged?"true":"false"),r("div",{key:"ba70d5d01cad9e0fb6e80a4955e3361723af3531"},"IsEnabled: ",this.core.store.state?.isEnabled?"true":"false"),r("div",{key:"be3a408762c8bada64224c4da92baf987ae62f6d"},"IsScaling: ",this.core.store.state?.isScaling?"true":"false"),r("div",{key:"9cf44848dbcb7e8b1a40618db1ee6cf019e01720"},"IsPanning: ",this.core.store.state?.isPanning?"true":"false"),r("div",{key:"b53633b5c099b338089294c897cfbc32973d360d"},"IsSelecting: ",this.isSelecting?"true":"false"),r("div",{key:"0cab012a88532c69ba0aeb1daa7646e91c4f029d"},"IsSelectionActive: ",this.isSelectionActive?"true":"false"),r("div",{key:"1c47bfd56352b70a8eafb771470d9912240e9885"},"IsResizeHandleSelected: ",this.core.store.state.isResizeHandleSelected?"true":"false"),r("div",{key:"1147a866a58f3d50c8751fc02f6614e899b13bc0"},"IsRotationHandleSelected: ",this.core.store.state.isRotationHandleSelected?"true":"false"),r("div",{key:"a308df3601fd5ba49741f2efbc3d262059daed2d"},"IsRotationHandleHovered: ",this.core.store.state.isRotationHandleHovered?"true":"false"),r("div",{key:"af5ceafa9bb39c2e2085815c691198f7a0b48017"},"IsDrawing: ",this.core.store.state.isDrawing?"true":"false"),r("div",{key:"8abffd4f1e3e7b174ee5e5e9070fc0ca0703d1aa"},"IsWriting: ",this.core.store.state.isWriting?"true":"false"),r("div",{key:"e127318f52e25d65b323d3325b02a0125864c3be"},"IsPointerDown: ",this.core.store.isPointerDown?"true":"false"),r("div",{key:"b8f21b1a1bd674f7403e3096e7cb52e629b2df89"},"PointerX: ",this.core.store.state?.pointerX),r("div",{key:"892abdc68df061495f88ceea2037766b537f82ab"},"PointerY: ",this.core.store.state?.pointerY),r("div",{key:"04f08e11cb67cedf31900d01803960caaa0a5a0b"},"SelectedObjects: ",this.core.store.selectionGroup?.objects.length||0),r("div",{key:"6a6efb9f05cb70eaff83cea1a22e1151a08e2ec9"},"ViewportCenter: (",o.toFixed(2),", ",u.toFixed(2),")")),r("div",{key:"c9e2392f43cf54b57f0fb49a361d47a2c4156ca3",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})`}},c?.map((n=>r("div",{key:n.id,id:n.id,class:"object",style:{transform:n?.transformationMatrix,transformOrigin:"top left",position:"absolute",zIndex:n.zIndex.toString(),pointerEvents:this.core.store.state.isScaling?"none":"auto"}},Uc.isInstanceOf(n,"KritzelPath")&&r("svg",{ref:t=>n.mount(t),xmlns:"http://www.w3.org/2000/svg",style:{height:n?.totalHeight+"px",width:n?.totalWidth+"px",left:"0",top:"0",position:"absolute",transform:0!==n.rotationDegrees?`rotate(${n.rotationDegrees}deg)`:void 0,transformOrigin:0!==n.rotationDegrees?`${n.totalWidth/2}px ${n.totalHeight/2}px`:void 0,opacity:n.markedForRemoval?"0.5":n.opacity.toString(),pointerEvents:n.markedForRemoval?"none":"auto",overflow:"visible"},viewBox:n?.viewBox},r("path",{d:n?.d,fill:_.resolveThemeColor(n.fill,t),stroke:_.resolveThemeColor(n?.stroke,t),"shape-rendering":n.isLowRes()?"optimizeSpeed":"auto"})),Uc.isInstanceOf(n,"KritzelLine")&&r("svg",{ref:t=>n.mount(t),xmlns:"http://www.w3.org/2000/svg",style:{height:n?.totalHeight+"px",width:n?.totalWidth+"px",left:"0",top:"0",position:"absolute",transform:0!==n.rotationDegrees?`rotate(${n.rotationDegrees}deg)`:void 0,transformOrigin:0!==n.rotationDegrees?`${n.totalWidth/2}px ${n.totalHeight/2}px`:void 0,opacity:n.markedForRemoval?"0.5":n.opacity.toString(),pointerEvents:n.markedForRemoval?"none":"auto",overflow:"visible"},viewBox:n?.viewBox},(n.hasStartArrow||n.hasEndArrow)&&r("defs",null,n.hasStartArrow&&r("marker",{id:n.startMarkerId,markerWidth:n.getArrowSize("start"),markerHeight:n.getArrowSize("start"),refX:0,refY:n.getArrowSize("start")/2,orient:"auto-start-reverse",markerUnits:"userSpaceOnUse"},r("path",{d:n.getArrowPath(n.arrows?.start?.style),fill:n.getArrowFill("start"),transform:`scale(${n.getArrowSize("start")/10})`})),n.hasEndArrow&&r("marker",{id:n.endMarkerId,markerWidth:n.getArrowSize("end"),markerHeight:n.getArrowSize("end"),refX:0,refY:n.getArrowSize("end")/2,orient:"auto",markerUnits:"userSpaceOnUse"},r("path",{d:n.getArrowPath(n.arrows?.end?.style),fill:n.getArrowFill("end"),transform:`scale(${n.getArrowSize("end")/10})`}))),r("path",{d:this.core.anchorManager.computeClippedLinePath(n),fill:"none",stroke:"transparent","stroke-width":Math.max(n?.strokeWidth||0,10),"stroke-linecap":"round"}),r("path",{d:this.core.anchorManager.computeClippedLinePath(n),fill:"none",stroke:_.resolveThemeColor(n?.stroke,t),"stroke-width":n?.strokeWidth,"stroke-linecap":"round","marker-start":n.hasStartArrow?`url(#${n.startMarkerId})`:void 0,"marker-end":n.hasEndArrow?`url(#${n.endMarkerId})`:void 0})),Uc.isInstanceOf(n,"KritzelImage")&&r("img",{ref:t=>n.mount(t),src:n.src,style:{position:"absolute",left:"0",top:"0",width:n.totalWidth+"px",height:n.totalHeight+"px",transform:0!==n.rotationDegrees?`rotate(${n.rotationDegrees}deg)`:void 0,transformOrigin:0!==n.rotationDegrees?`${n.totalWidth/2}px ${n.totalHeight/2}px`:void 0,opacity:n.markedForRemoval?"0.5":n.opacity.toString(),pointerEvents:n.markedForRemoval?"none":"auto",backgroundColor:_.resolveThemeColor(n.backgroundColor,t),borderColor:_.resolveThemeColor(n.borderColor,t),borderWidth:n.borderWidth+"px",borderStyle:"solid",padding:n.padding+"px",overflow:"visible",userSelect:"none",imageRendering:this.core.store.state.isScaling||this.core.store.state.isPanning?"pixelated":"auto"},draggable:!1,onDragStart:t=>t.preventDefault()}),Uc.isInstanceOf(n,"KritzelCustomElement")&&r("div",{ref:t=>n.mount(t),style:{position:"absolute",left:"0",top:"0",width:n.totalWidth+"px",height:n.totalHeight+"px",transform:0!==n.rotationDegrees?`rotate(${n.rotationDegrees}deg)`:void 0,transformOrigin:0!==n.rotationDegrees?`${n.totalWidth/2}px ${n.totalHeight/2}px`:void 0,opacity:n.markedForRemoval?"0.5":n.opacity.toString(),pointerEvents:n.markedForRemoval?"none":"auto",backgroundColor:_.resolveThemeColor(n.backgroundColor,t),borderColor:_.resolveThemeColor(n.borderColor,t),borderWidth:n.borderWidth+"px",borderStyle:"solid",padding:n.padding+"px",overflow:"hidden",display:"block"}}),Uc.isInstanceOf(n,"KritzelSelectionGroup")&&!this.core.displaySelectionLineUI(n)&&r("div",{ref:t=>n.mount(t),style:{position:"absolute",left:"0",top:"0",width:n.totalWidth+"px",height:n.totalHeight+"px",transform:0!==n.rotationDegrees?`rotate(${n.rotationDegrees}deg)`:void 0,transformOrigin:0!==n.rotationDegrees?`${n.totalWidth/2}px ${n.totalHeight/2}px`:void 0,opacity:n.markedForRemoval?"0.5":n.opacity.toString(),pointerEvents:n.markedForRemoval?"none":"auto"}}),Uc.isInstanceOf(n,"KritzelSelectionBox")&&r("div",{ref:t=>n.mount(t),style:{position:"absolute",left:"0",top:"0",width:n.totalWidth+"px",height:n.totalHeight+"px",transform:0!==n.rotationDegrees?`rotate(${n.rotationDegrees}deg)`:void 0,transformOrigin:0!==n.rotationDegrees?`${n.totalWidth/2}px ${n.totalHeight/2}px`:void 0,opacity:n.markedForRemoval?"0.5":n.opacity.toString(),pointerEvents:n.markedForRemoval?"none":"auto",backgroundColor:_.resolveThemeColor(n.backgroundColor,t),borderColor:_.resolveThemeColor(n.borderColor,t),borderWidth:n.borderWidth+"px",borderStyle:"solid"}}),Uc.isInstanceOf(n,"KritzelText")&&r("div",{style:{position:"absolute",left:"0",top:"0",width:n.totalWidth+"px",height:n.totalHeight+"px",transform:0!==n.rotationDegrees?`rotate(${n.rotationDegrees}deg)`:void 0,transformOrigin:0!==n.rotationDegrees?`${n.totalWidth/2}px ${n.totalHeight/2}px`:void 0,opacity:n.markedForRemoval?"0.5":n.opacity.toString(),pointerEvents:n.markedForRemoval?"none":"auto"}},r("div",{id:"text-object",ref:t=>n.mount(t),onPointerDown:t=>n.handlePointerDown(t),onPointerMove:t=>n.handlePointerMove(t),onPointerUp:t=>n.handlePointerUp(t),style:{minWidth:n.initialWidth+"px",minHeight:n.initialHeight+"px",maxWidth:"500px",height:"auto",width:"max-content",transformOrigin:"top left",transform:`scale(${n.scaleFactor})`,backgroundColor:_.resolveThemeColor(n.backgroundColor,t),overflow:"visible"}})),Uc.isInstanceOf(n,"KritzelShape")&&r("div",{ref:t=>n.mount(t),onPointerDown:t=>n.handlePointerDown(t),onPointerMove:t=>n.handlePointerMove(t),onPointerUp:t=>n.handlePointerUp(t),style:{position:"absolute",left:"0",top:"0",width:n.totalWidth+"px",height:n.totalHeight+"px",transform:0!==n.rotationDegrees?`rotate(${n.rotationDegrees}deg)`:void 0,transformOrigin:0!==n.rotationDegrees?`${n.totalWidth/2}px ${n.totalHeight/2}px`:void 0,opacity:n.markedForRemoval?"0.5":n.opacity.toString(),pointerEvents:n.markedForRemoval?"none":"auto",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:n.viewBox,preserveAspectRatio:"none"},r("path",{d:n.getSvgPath(),fill:_.resolveThemeColor(n.fillColor,t),stroke:_.resolveThemeColor(n.strokeColor,t),"stroke-width":n.strokeWidth})),r("div",{ref:t=>n.mountTextEditor(t),style:{position:"absolute",top:"0",left:"0",width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",textAlign:"center",overflow:"hidden",pointerEvents:n.isEditing?"auto":"none"}})),this.core.store.state.debugInfo.showObjectInfo&&n.isDebugInfoVisible&&r("div",{style:{pointerEvents:"none",position:"absolute",left:`${n.totalWidth}px`,top:"0",zIndex:(n.zIndex+2).toString()}},r("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"Id: ",n.id),r("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"width: ",n.width),r("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"height: ",n.height),r("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"translateX: ",n.translateX),r("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"translateY: ",n.translateY),r("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"rotationDegrees: ",n.rotationDegrees),r("div",{style:{whiteSpace:"nowrap",fontSize:"10px"}},"zIndex: ",n.zIndex)),(this.core.displaySelectionGroupUI(n)||this.core.displaySelectionLineUI(n))&&r("svg",{xmlns:"http://www.w3.org/2000/svg",style:{zIndex:(n.zIndex+1).toString(),height:n?.totalHeight.toString(),width:n?.totalWidth.toString(),left:"0",top:"0",position:"absolute",transform:`rotate(${n.rotationDegrees}deg)`,transformOrigin:`${n.totalWidth/2}px ${n.totalHeight/2}px`,overflow:"visible",pointerEvents:"none"}},this.core.displaySelectionGroupUI(n)&&r("g",{class:"selection-group-ui",style:{pointerEvents:"none"}},r("g",{class:"selection-group-borders"},r("line",{x1:"0",y1:"0",x2:n.totalWidth,y2:"0",style:{stroke:"var(--kritzel-selection-border-color, #007AFF)",strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${n.scale} / ${this.core.store.state?.scale})`,strokeLinecap:"square"}}),r("line",{x1:"0",y1:"0",x2:"0",y2:n.totalHeight,style:{stroke:"var(--kritzel-selection-border-color, #007AFF)",strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${n.scale} / ${this.core.store.state?.scale})`,strokeLinecap:"square"}}),r("line",{x1:"0",y1:n.totalHeight,x2:n.totalWidth,y2:n.totalHeight,style:{stroke:"var(--kritzel-selection-border-color, #007AFF)",strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${n.scale} / ${this.core.store.state?.scale})`,strokeLinecap:"square"}}),r("line",{x1:n.totalWidth,y1:"0",x2:n.totalWidth,y2:n.totalHeight,style:{stroke:"var(--kritzel-selection-border-color, #007AFF)",strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${n.scale} / ${this.core.store.state?.scale})`,strokeLinecap:"square"}})),!this.isSelecting&&r("g",{class:"selection-group-handles",style:{pointerEvents:"auto"}},r("rect",{class:"resize-handle top-left",x:""+-(e-1)*n.scale/this.core.store.state?.scale,y:""+-(e-1)*n.scale/this.core.store.state?.scale,width:""+2*(e-1)*n.scale/this.core.store.state?.scale,height:""+2*(e-1)*n.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #ffffff)",stroke:"var(--kritzel-selection-handle-stroke-color, #007AFF)",strokeWidth:`calc(2px * ${n.scale} / ${this.core.store.state?.scale})`,paintOrder:"fill"}}),r("rect",{class:"resize-handle-overlay top-left",x:""+-s*n.scale/this.core.store.state?.scale,y:""+-s*n.scale/this.core.store.state?.scale,width:""+2*s*n.scale/this.core.store.state?.scale,height:""+2*s*n.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}),r("rect",{class:"resize-handle top-right",x:""+(n.totalWidth-(e-1)*n.scale/this.core.store.state?.scale),y:""+-(e-1)*n.scale/this.core.store.state?.scale,width:""+2*(e-1)*n.scale/this.core.store.state?.scale,height:""+2*(e-1)*n.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #ffffff)",stroke:"var(--kritzel-selection-handle-stroke-color, #007AFF)",strokeWidth:`calc(2px * ${n.scale} / ${this.core.store.state?.scale})`,paintOrder:"fill"}}),r("rect",{class:"resize-handle-overlay top-right",x:""+(n.totalWidth-s*n.scale/this.core.store.state?.scale),y:""+-s*n.scale/this.core.store.state?.scale,width:""+2*s*n.scale/this.core.store.state?.scale,height:""+2*s*n.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}),r("rect",{class:"resize-handle bottom-left",x:""+-(e-1)*n.scale/this.core.store.state?.scale,y:""+(n.totalHeight-(e-1)*n.scale/this.core.store.state?.scale),width:""+2*(e-1)*n.scale/this.core.store.state?.scale,height:""+2*(e-1)*n.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #ffffff)",stroke:"var(--kritzel-selection-handle-stroke-color, #007AFF)",strokeWidth:`calc(2px * ${n.scale} / ${this.core.store.state?.scale})`,paintOrder:"fill"}}),r("rect",{class:"resize-handle-overlay bottom-left",x:""+-s*n.scale/this.core.store.state?.scale,y:""+(n.totalHeight-s*n.scale/this.core.store.state?.scale),width:""+2*s*n.scale/this.core.store.state?.scale,height:""+2*s*n.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}),r("rect",{class:"resize-handle bottom-right",x:""+(n.totalWidth-(e-1)*n.scale/this.core.store.state?.scale),y:""+(n.totalHeight-(e-1)*n.scale/this.core.store.state?.scale),width:""+2*(e-1)*n.scale/this.core.store.state?.scale,height:""+2*(e-1)*n.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #ffffff)",stroke:"var(--kritzel-selection-handle-stroke-color, #007AFF)",strokeWidth:`calc(2px * ${n.scale} / ${this.core.store.state?.scale})`,paintOrder:"fill"}}),r("rect",{class:"resize-handle-overlay bottom-right",x:""+(n.totalWidth-s*n.scale/this.core.store.state?.scale),y:""+(n.totalHeight-s*n.scale/this.core.store.state?.scale),width:""+2*s*n.scale/this.core.store.state?.scale,height:""+2*s*n.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}),r("line",{x1:n.totalWidth/2,y1:"0",x2:n.totalWidth/2,y2:-15*n.scale/this.core.store.state?.scale,style:{stroke:"var(--kritzel-selection-border-color, #007AFF)",strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${n.scale} / ${this.core.store.state?.scale})`}}),r("circle",{class:"rotation-handle",cx:n.totalWidth/2,cy:-15*n.scale/this.core.store.state?.scale,r:""+(e-1)*n.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #ffffff)",stroke:"var(--kritzel-selection-handle-stroke-color, #007AFF)",strokeWidth:`calc(2px * ${n.scale} / ${this.core.store.state?.scale})`,paintOrder:"fill"}}),r("circle",{class:"rotation-handle-overlay",cx:n.totalWidth/2,cy:-15*n.scale/this.core.store.state?.scale,r:""+s*n.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}))),this.core.displaySelectionLineUI(n)&&Uc.isInstanceOf(n,"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(n,!0),style:{stroke:"var(--kritzel-selection-border-color, #007AFF)",strokeWidth:`calc(var(--kritzel-selection-border-width, 2px) * ${n.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:n.startX-n.x,cy:n.startY-n.y,r:""+(e-1)*n.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #000000)",stroke:"var(--kritzel-selection-handle-stroke-color, #007AFF)",strokeWidth:`calc(2px * ${n.scale} / ${this.core.store.state?.scale})`,paintOrder:"fill"}}),r("circle",{class:"selection-line-handle-overlay start",cx:n.startX-n.x,cy:n.startY-n.y,r:""+s*n.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}),r("circle",{class:"selection-line-handle center",cx:void 0!==n.controlX?(n.startX+2*n.controlX+n.endX)/4-n.x:(n.startX-n.x+n.endX-n.x)/2,cy:void 0!==n.controlY?(n.startY+2*n.controlY+n.endY)/4-n.y:(n.startY-n.y+n.endY-n.y)/2,r:""+(e-1)*n.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #000000)",stroke:"var(--kritzel-selection-handle-stroke-color, #007AFF)",strokeWidth:`calc(2px * ${n.scale} / ${this.core.store.state?.scale})`,paintOrder:"fill"}}),r("circle",{class:"selection-line-handle-overlay center",cx:void 0!==n.controlX?(n.startX+2*n.controlX+n.endX)/4-n.x:(n.startX-n.x+n.endX-n.x)/2,cy:void 0!==n.controlY?(n.startY+2*n.controlY+n.endY)/4-n.y:(n.startY-n.y+n.endY-n.y)/2,r:""+s*n.scale/this.core.store.state?.scale,style:{fill:"transparent",paintOrder:"fill"}}),r("circle",{class:"selection-line-handle end",cx:n.endX-n.x,cy:n.endY-n.y,r:""+(e-1)*n.scale/this.core.store.state?.scale,style:{fill:"var(--kritzel-selection-handle-color, #000000)",stroke:"var(--kritzel-selection-handle-stroke-color, #007AFF)",strokeWidth:`calc(2px * ${n.scale} / ${this.core.store.state?.scale})`,paintOrder:"fill"}}),r("circle",{class:"selection-line-handle-overlay end",cx:n.endX-n.x,cy:n.endY-n.y,r:""+s*n.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:"307012661cd1021e7e3c3db48f1671700f5de91b",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 R&&!this.core.store.state.isScaling&&r("kritzel-cursor-trail",{key:"bd48d2a8e7c83e2c5d80c92548b00720650391ab",core:this.core}))}static get watchers(){return{workspace:[{onWorkspaceChange:0}],scaleMax:[{validateScaleMax:0}],scaleMin:[{validateScaleMin:0}],cursorTarget:[{onCursorTargetChange:0}],lockDrawingScale:[{onLockDrawingScaleChange:0}],theme:[{onThemeChange: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],lockDrawingScale:[4,"lock-drawing-scale"],theme:[1],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],backToContent:[64],getCopiedObjects:[64],getScreenshot:[64],exportViewportAsPng:[64],exportViewportAsSvg:[64],createWorkspace:[64],updateWorkspace:[64],deleteWorkspace:[64],getWorkspaces:[64],getActiveWorkspace:[64]},[[1,"wheel","handleWheel"],[0,"pointerdown","handlePointerDown"],[0,"pointermove","handlePointerMove"],[0,"pointerup","handlePointerUp"],[0,"pointercancel","handlePointerCancel"],[1,"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}],lockDrawingScale:[{onLockDrawingScaleChange:0}],theme:[{onThemeChange:0}]}]);function Ia(){"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),ja);break;case"kritzel-context-menu":customElements.get(s(t))||E();break;case"kritzel-cursor-trail":customElements.get(s(t))||D();break;case"kritzel-icon":customElements.get(s(t))||j()}}))}export{ae as A,_t as B,Dt as C,wc as D,gt as E,bt as F,Tc as G,$c as H,eu as I,jc as J,R as K,Ic as L,Oc as M,Ia as N,jt as O,ja as P,hn as a,$n as b,mi as c,Si as d,Ai as e,Jt as f,Cn as g,xt as h,ke as i,me as j,be as k,Xn as l,jn as m,It as n,Yn as o,Nn as p,ce as q,Tn as r,At as s,tn as t,cn as u,Qn as v,rn as w,te as x,Ut as y,Zt as z}