File size: 138,756 Bytes
1853f66
 
 
 
 
 
 
1
2
3
4
5
6
7
8
import{S as Se,i as Pe,s as Te,B as Nn,C as Cn,D as Mn,E as Un,f as X,t as Z,H as Nr,I as Cr,J as en,k as oe,K as Bt,a as _e,l as se,m as te,L as Xt,h as $,c as ge,n as D,b as ie,F as J,A as Ee,q as lt,r as ut,u as Dn,v as ke,w as xe,x as Oe,y as Ie,G as Ve,o as Pt,M as Et,N as me,O as vt,P as Mr,Q as er,R as to,T as no,U as ro,V as io,W as oo,g as ct,d as ft,X as so,e as Xe,Y as ao,Z as lo}from"../../chunks/index-6327f5df.js";import{w as mt}from"../../chunks/index-55ea88a7.js";var uo=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},Ae={},C={};Object.defineProperty(C,"__esModule",{value:!0});var co=Object.defineProperty,fo=Object.defineProperties,ho=Object.getOwnPropertyDescriptors,Yt=Object.getOwnPropertySymbols,Ur=Object.prototype.hasOwnProperty,Dr=Object.prototype.propertyIsEnumerable,tr=(e,t,n)=>t in e?co(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Tt=(e,t)=>{for(var n in t||(t={}))Ur.call(t,n)&&tr(e,n,t[n]);if(Yt)for(var n of Yt(t))Dr.call(t,n)&&tr(e,n,t[n]);return e},tn=(e,t)=>fo(e,ho(t)),po=(e,t)=>{var n={};for(var r in e)Ur.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Yt)for(var r of Yt(e))t.indexOf(r)<0&&Dr.call(e,r)&&(n[r]=e[r]);return n},mo=(e,t,n)=>new Promise((r,i)=>{var o=l=>{try{a(n.next(l))}catch(u){i(u)}},s=l=>{try{a(n.throw(l))}catch(u){i(u)}},a=l=>l.done?r(l.value):Promise.resolve(l.value).then(o,s);a((n=n.apply(e,t)).next())});function _o(e,t=e){}function go(e,t,n=t){}function vo(e){}function yo(e,t){}function Be(e,t){throw new Error(t)}function F(e,t="Expected value to be non-nullable"){return e}var zr=(e=>(e[e.UPDATE_PRESENCE=100]="UPDATE_PRESENCE",e[e.BROADCAST_EVENT=103]="BROADCAST_EVENT",e[e.FETCH_STORAGE=200]="FETCH_STORAGE",e[e.UPDATE_STORAGE=201]="UPDATE_STORAGE",e))(zr||{}),$r=(e=>(e[e.INIT=0]="INIT",e[e.SET_PARENT_KEY=1]="SET_PARENT_KEY",e[e.CREATE_LIST=2]="CREATE_LIST",e[e.UPDATE_OBJECT=3]="UPDATE_OBJECT",e[e.CREATE_OBJECT=4]="CREATE_OBJECT",e[e.DELETE_CRDT=5]="DELETE_CRDT",e[e.DELETE_OBJECT_KEY=6]="DELETE_OBJECT_KEY",e[e.CREATE_MAP=7]="CREATE_MAP",e[e.CREATE_REGISTER=8]="CREATE_REGISTER",e))($r||{}),Kr=(e=>(e[e.OBJECT=0]="OBJECT",e[e.LIST=1]="LIST",e[e.MAP=2]="MAP",e[e.REGISTER=3]="REGISTER",e))(Kr||{});function wo(e){return e.type===0&&!Fr(e)}function Fr(e){return e.parentId!==void 0&&e.parentKey!==void 0}var Hr=(e=>(e[e.UPDATE_PRESENCE=100]="UPDATE_PRESENCE",e[e.USER_JOINED=101]="USER_JOINED",e[e.USER_LEFT=102]="USER_LEFT",e[e.BROADCASTED_EVENT=103]="BROADCASTED_EVENT",e[e.ROOM_STATE=104]="ROOM_STATE",e[e.INITIAL_STORAGE_STATE=200]="INITIAL_STORAGE_STATE",e[e.UPDATE_STORAGE=201]="UPDATE_STORAGE",e))(Hr||{});function bo(e){return e==="my-presence"||e==="others"||e==="event"||e==="error"||e==="connection"||e==="history"}var Vr=(e=>(e[e.CLOSE_ABNORMAL=1006]="CLOSE_ABNORMAL",e[e.INVALID_MESSAGE_FORMAT=4e3]="INVALID_MESSAGE_FORMAT",e[e.NOT_ALLOWED=4001]="NOT_ALLOWED",e[e.MAX_NUMBER_OF_MESSAGES_PER_SECONDS=4002]="MAX_NUMBER_OF_MESSAGES_PER_SECONDS",e[e.MAX_NUMBER_OF_CONCURRENT_CONNECTIONS=4003]="MAX_NUMBER_OF_CONCURRENT_CONNECTIONS",e[e.MAX_NUMBER_OF_MESSAGES_PER_DAY_PER_APP=4004]="MAX_NUMBER_OF_MESSAGES_PER_DAY_PER_APP",e[e.MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM=4005]="MAX_NUMBER_OF_CONCURRENT_CONNECTIONS_PER_ROOM",e[e.CLOSE_WITHOUT_RETRY=4999]="CLOSE_WITHOUT_RETRY",e))(Vr||{}),et=32,zn=126;function Ne(e,t){return e!==void 0&&t!==void 0?qt(Br(ht(e),ht(t))):e!==void 0?ko(e):t!==void 0?Eo(t):qt([et+1])}function Eo(e){const t=[],n=ht(e);for(let r=0;r<n.length;r++){const i=n[r];if(i<=et+1){if(t.push(et),n.length-1===r){t.push(zn);break}}else{t.push(i-1);break}}return qt(t)}function ko(e){const t=[],n=ht(e);for(let r=0;r<n.length;r++){const i=n[r];if(i===zn){if(t.push(i),n.length-1===r){t.push(et+1);break}}else{t.push(i+1);break}}return qt(t)}function Br(e,t){let n=0;const r=[];for(;;){const i=e[n]||et,o=t[n]||zn;if(i>o)throw new Error(`Impossible to generate position between ${e} and ${t}`);if(i===o){r.push(i),n++;continue}if(o-i===1){r.push(i),r.push(...Br(e.slice(n+1),[]));break}const s=o+i>>1;r.push(s);break}return r}function ht(e){const t=[];for(let n=0;n<e.length;n++)t.push(e.charCodeAt(n));return t}function qt(e){return String.fromCharCode(...e)}function Xr(e,t){const n=ht(e),r=ht(t),i=Math.max(n.length,r.length);for(let o=0;o<i;o++){const s=n[o]===void 0?et:n[o],a=r[o]===void 0?et:r[o];if(s!==a)return s-a}throw new Error(`Impossible to compare similar position "${e}" and "${t}"`)}function nr(e,t){return Object.freeze({type:"HasParent",node:e,key:t})}var rr=Object.freeze({type:"NoParent"});function ir(e){return Object.freeze({type:"Orphaned",oldKey:e})}var nn=class{constructor(){this._parent=rr}_getParentKeyOrThrow(){switch(this.parent.type){case"HasParent":return this.parent.key;case"NoParent":throw new Error("Parent key is missing");case"Orphaned":return this.parent.oldKey;default:return Be(this.parent,"Unknown state")}}get _pool(){return this.__pool}get roomId(){return this.__pool?this.__pool.roomId:null}get _id(){return this.__id}get parent(){return this._parent}get _parentNode(){switch(this.parent.type){case"HasParent":return this.parent.node;case"NoParent":return null;case"Orphaned":return null;default:return Be(this.parent,"Unknown state")}}get _parentKey(){switch(this.parent.type){case"HasParent":return this.parent.key;case"NoParent":return null;case"Orphaned":return this.parent.oldKey;default:return Be(this.parent,"Unknown state")}}_apply(e,t){switch(e.type){case 5:return this.parent.type==="HasParent"?this.parent.node._detachChild(this):{modified:!1}}return{modified:!1}}_setParentLink(e,t){switch(this.parent.type){case"HasParent":if(this.parent.node!==e)throw new Error("Cannot set parent: node already has a parent");this._parent=nr(e,t);return;case"Orphaned":case"NoParent":{this._parent=nr(e,t);return}default:return Be(this.parent,"Unknown state")}}_attach(e,t){if(this.__id||this.__pool)throw new Error("Cannot attach node: already attached");t.addNode(e,this),this.__id=e,this.__pool=t}_detach(){switch(this.__pool&&this.__id&&this.__pool.deleteNode(this.__id),this.parent.type){case"HasParent":{this._parent=ir(this.parent.key);break}case"NoParent":{this._parent=rr;break}case"Orphaned":{this._parent=ir(this.parent.oldKey);break}default:Be(this.parent,"Unknown state")}this.__pool=void 0}invalidate(){this._cachedImmutable!==void 0&&(this._cachedImmutable=void 0,this.parent.type==="HasParent"&&this.parent.node.invalidate())}toImmutable(){return this._cachedImmutable===void 0&&(this._cachedImmutable=this._toImmutable()),this._cachedImmutable}},Fe=class extends nn{constructor(e){super(),this._data=e}get data(){return this._data}static _deserialize([e,t],n,r){const i=new Fe(t.data);return i._attach(e,r),i}_toOps(e,t,n){if(this._id===void 0)throw new Error("Cannot serialize register if parentId or parentKey is undefined");return[{type:8,opId:n==null?void 0:n.generateOpId(),id:this._id,parentId:e,parentKey:t,data:this.data}]}_serialize(){if(this.parent.type!=="HasParent")throw new Error("Cannot serialize LiveRegister if parent is missing");return{type:3,parentId:F(this.parent.node._id,"Parent node expected to have ID"),parentKey:this.parent.key,data:this.data}}_attachChild(e){throw new Error("Method not implemented.")}_detachChild(e){throw new Error("Method not implemented.")}_apply(e,t){return super._apply(e,t)}_toImmutable(){return this._data}},qe=class extends nn{constructor(e){if(super(),this.unacknowledgedSet=new Map,e){const t=[];for(const n of e){const r=ot(n[1]);r._setParentLink(this,n[0]),t.push([n[0],r])}this._map=new Map(t)}else this._map=new Map}_toOps(e,t,n){if(this._id===void 0)throw new Error("Cannot serialize item is not attached");const r=[],i={id:this._id,opId:n==null?void 0:n.generateOpId(),type:7,parentId:e,parentKey:t};r.push(i);for(const[o,s]of this._map)r.push(...s._toOps(this._id,o,n));return r}static _deserialize([e,t],n,r){const i=new qe;i._attach(e,r);const o=n.get(e);if(o===void 0)return i;for(const[s,a]of o){const l=jr([s,a],n,r);l._setParentLink(i,a.parentKey),i._map.set(a.parentKey,l),i.invalidate()}return i}_attach(e,t){super._attach(e,t);for(const[n,r]of this._map)ae(r)&&r._attach(t.generateId(),t)}_attachChild(e,t){if(this._pool===void 0)throw new Error("Can't attach child if managed pool is not present");const{id:n,parentKey:r,opId:i}=e,o=r,s=yt(e);if(this._pool.getNode(n)!==void 0)return{modified:!1};if(t===2){const u=this.unacknowledgedSet.get(o);if(u===i)return this.unacknowledgedSet.delete(o),{modified:!1};if(u!==void 0)return{modified:!1}}else t===1&&this.unacknowledgedSet.delete(o);const a=this._map.get(o);let l;if(a){const u=F(this._id);l=a._toOps(u,o),a._detach()}else l=[{type:5,id:n}];return s._setParentLink(this,o),s._attach(n,this._pool),this._map.set(o,s),this.invalidate(),{modified:{node:this,type:"LiveMap",updates:{[o]:{type:"update"}}},reverse:l}}_detach(){super._detach();for(const e of this._map.values())e._detach()}_detachChild(e){const t=F(this._id),n=F(e._parentKey),r=e._toOps(t,n,this._pool);for(const[o,s]of this._map)s===e&&(this._map.delete(o),this.invalidate());return e._detach(),{modified:{node:this,type:"LiveMap",updates:{[n]:{type:"delete"}}},reverse:r}}_serialize(){if(this.parent.type!=="HasParent")throw new Error("Cannot serialize LiveMap if parent is missing");return{type:2,parentId:F(this.parent.node._id,"Parent node expected to have ID"),parentKey:this.parent.key}}get(e){const t=this._map.get(e);if(t!==void 0)return Ze(t)}set(e,t){const n=this._map.get(e);n&&n._detach();const r=ot(t);if(r._setParentLink(this,e),this._map.set(e,r),this.invalidate(),this._pool&&this._id){const i=this._pool.generateId();r._attach(i,this._pool);const o=new Map;o.set(this._id,{node:this,type:"LiveMap",updates:{[e]:{type:"update"}}});const s=r._toOps(this._id,e,this._pool);this.unacknowledgedSet.set(e,F(s[0].opId)),this._pool.dispatch(r._toOps(this._id,e,this._pool),n?n._toOps(this._id,e):[{type:5,id:i}],o)}}get size(){return this._map.size}has(e){return this._map.has(e)}delete(e){const t=this._map.get(e);if(t===void 0)return!1;if(t._detach(),this._map.delete(e),this.invalidate(),this._pool&&t._id){const n=F(this._id),r=new Map;r.set(n,{node:this,type:"LiveMap",updates:{[e]:{type:"delete"}}}),this._pool.dispatch([{type:5,id:t._id,opId:this._pool.generateOpId()}],t._toOps(n,e),r)}return!0}entries(){const e=this._map.entries();return{[Symbol.iterator](){return this},next(){const t=e.next();if(t.done)return{done:!0,value:void 0};const r=t.value[0],i=Ze(t.value[1]);return{value:[r,i]}}}}[Symbol.iterator](){return this.entries()}keys(){return this._map.keys()}values(){const e=this._map.values();return{[Symbol.iterator](){return this},next(){const t=e.next();return t.done?{done:!0,value:void 0}:{value:Ze(t.value)}}}}forEach(e){for(const t of this)e(t[1],t[0],this)}toImmutable(){return super.toImmutable()}_toImmutable(){const e=new Map;for(const[t,n]of this._map)e.set(t,n.toImmutable());return $n(e)}},je=class extends nn{constructor(e={}){super(),this._propToLastUpdate=new Map;for(const t in e){const n=e[t];n!==void 0&&ae(n)&&n._setParentLink(this,t)}this._map=new Map(Object.entries(e))}_toOps(e,t,n){if(this._id===void 0)throw new Error("Cannot serialize item is not attached");const r=n==null?void 0:n.generateOpId(),i=[],o=e!==void 0&&t!==void 0?{type:4,id:this._id,opId:r,parentId:e,parentKey:t,data:{}}:{type:4,id:this._id,opId:r,data:{}};i.push(o);for(const[s,a]of this._map)ae(a)?i.push(...a._toOps(this._id,s,n)):o.data[s]=a;return i}static _deserialize([e,t],n,r){const i=new je(t.data);return i._attach(e,r),this._deserializeChildren(i,n,r)}static _deserializeChildren(e,t,n){const r=t.get(F(e._id));if(r===void 0)return e;for(const[i,o]of r){const s=Io([i,o],t,n);$t(s)&&s._setParentLink(e,o.parentKey),e._map.set(o.parentKey,s),e.invalidate()}return e}_attach(e,t){super._attach(e,t);for(const[n,r]of this._map)ae(r)&&r._attach(t.generateId(),t)}_attachChild(e,t){if(this._pool===void 0)throw new Error("Can't attach child if managed pool is not present");const{id:n,opId:r,parentKey:i}=e,o=Yr(e);if(this._pool.getNode(n)!==void 0)return this._propToLastUpdate.get(i)===r&&this._propToLastUpdate.delete(i),{modified:!1};if(t===0)this._propToLastUpdate.set(i,F(r));else if(this._propToLastUpdate.get(i)!==void 0)return this._propToLastUpdate.get(i)===r?(this._propToLastUpdate.delete(i),{modified:!1}):{modified:!1};const s=F(this._id),a=this._map.get(i);let l;return ae(a)?(l=a._toOps(s,i),a._detach()):a===void 0?l=[{type:6,id:s,key:i}]:l=[{type:3,id:s,data:{[i]:a}}],this._map.set(i,o),this.invalidate(),$t(o)&&(o._setParentLink(this,i),o._attach(n,this._pool)),{reverse:l,modified:{node:this,type:"LiveObject",updates:{[i]:{type:"update"}}}}}_detachChild(e){if(e){const t=F(this._id),n=F(e._parentKey),r=e._toOps(t,n,this._pool);for(const[o,s]of this._map)s===e&&(this._map.delete(o),this.invalidate());return e._detach(),{modified:{node:this,type:"LiveObject",updates:{[n]:{type:"delete"}}},reverse:r}}return{modified:!1}}_detach(){super._detach();for(const e of this._map.values())ae(e)&&e._detach()}_apply(e,t){return e.type===3?this._applyUpdate(e,t):e.type===6?this._applyDeleteObjectKey(e):super._apply(e,t)}_serialize(){const e={};for(const[t,n]of this._map)ae(n)||(e[t]=n);return this.parent.type==="HasParent"&&this.parent.node._id?{type:0,parentId:this.parent.node._id,parentKey:this.parent.key,data:e}:{type:0,data:e}}_applyUpdate(e,t){let n=!1;const r=F(this._id),i=[],o={type:3,id:r,data:{}};i.push(o);for(const a in e.data){const l=this._map.get(a);ae(l)?(i.push(...l._toOps(r,a)),l._detach()):l!==void 0?o.data[a]=l:l===void 0&&i.push({type:6,id:r,key:a})}const s={};for(const a in e.data){const l=e.data[a];if(l===void 0)continue;if(t)this._propToLastUpdate.set(a,F(e.opId));else if(this._propToLastUpdate.get(a)===void 0)n=!0;else if(this._propToLastUpdate.get(a)===e.opId){this._propToLastUpdate.delete(a);continue}else continue;const u=this._map.get(a);ae(u)&&u._detach(),n=!0,s[a]={type:"update"},this._map.set(a,l),this.invalidate()}return Object.keys(o.data).length!==0&&i.unshift(o),n?{modified:{node:this,type:"LiveObject",updates:s},reverse:i}:{modified:!1}}_applyDeleteObjectKey(e){const t=e.key;if(this._map.has(t)===!1)return{modified:!1};if(this._propToLastUpdate.get(t)!==void 0)return{modified:!1};const n=this._map.get(t),r=F(this._id);let i=[];return ae(n)?(i=n._toOps(r,e.key),n._detach()):n!==void 0&&(i=[{type:3,id:r,data:{[t]:n}}]),this._map.delete(t),this.invalidate(),{modified:{node:this,type:"LiveObject",updates:{[e.key]:{type:"delete"}}},reverse:i}}toObject(){return Co(this._map)}set(e,t){this.update({[e]:t})}get(e){return this._map.get(e)}delete(e){const t=e,n=this._map.get(t);if(n===void 0)return;if(this._pool===void 0||this._id===void 0){ae(n)&&n._detach(),this._map.delete(t),this.invalidate();return}let r;ae(n)?(n._detach(),r=n._toOps(this._id,t)):r=[{type:3,data:{[t]:n},id:this._id}],this._map.delete(t),this.invalidate();const i=new Map;i.set(this._id,{node:this,type:"LiveObject",updates:{[e]:{type:"delete"}}}),this._pool.dispatch([{type:6,key:t,id:this._id,opId:this._pool.generateOpId()}],r,i)}update(e){if(this._pool===void 0||this._id===void 0){for(const l in e){const u=e[l];if(u===void 0)continue;const c=this._map.get(l);ae(c)&&c._detach(),ae(u)&&u._setParentLink(this,l),this._map.set(l,u),this.invalidate()}return}const t=[],n=[],r=this._pool.generateOpId(),i={},o={id:this._id,type:3,data:{}},s={};for(const l in e){const u=e[l];if(u===void 0)continue;const c=this._map.get(l);if(ae(c)?(n.push(...c._toOps(this._id,l)),c._detach()):c===void 0?n.push({type:6,id:this._id,key:l}):o.data[l]=c,ae(u)){u._setParentLink(this,l),u._attach(this._pool.generateId(),this._pool);const d=u._toOps(this._id,l,this._pool),p=d.find(_=>_.parentId===this._id);p&&this._propToLastUpdate.set(l,F(p.opId)),t.push(...d)}else i[l]=u,this._propToLastUpdate.set(l,r);this._map.set(l,u),this.invalidate(),s[l]={type:"update"}}Object.keys(o.data).length!==0&&n.unshift(o),Object.keys(i).length!==0&&t.unshift({opId:r,id:this._id,type:3,data:i});const a=new Map;a.set(this._id,{node:this,type:"LiveObject",updates:s}),this._pool.dispatch(t,n,a)}toImmutable(){return super.toImmutable()}_toImmutable(){const e={};for(const[t,n]of this._map)e[t]=$t(n)?n.toImmutable():n;return e}},$n=e=>e;function xo(e){return e.filter(t=>t!=null)}function Oo(e){const t=Tt({},e);return Object.keys(e).forEach(n=>{const r=n;t[r]===void 0&&delete t[r]}),t}function yt(e){return ot(Yr(e))}function Yr(e){switch(e.type){case 8:return e.data;case 4:return new je(e.data);case 7:return new qe;case 2:return new Ge;default:return Be(e,"Unknown creation Op")}}function qr(e,t){return e===t?!0:e.parent.type==="HasParent"?qr(e.parent.node,t):!1}function jr([e,t],n,r){switch(t.type){case 0:return je._deserialize([e,t],n,r);case 1:return Ge._deserialize([e,t],n,r);case 2:return qe._deserialize([e,t],n,r);case 3:return Fe._deserialize([e,t],n,r);default:throw new Error("Unexpected CRDT type")}}function Io([e,t],n,r){switch(t.type){case 0:return je._deserialize([e,t],n,r);case 1:return Ge._deserialize([e,t],n,r);case 2:return qe._deserialize([e,t],n,r);case 3:return t.data;default:throw new Error("Unexpected CRDT type")}}function $t(e){return Gr(e)||So(e)||Jr(e)}function ae(e){return $t(e)||Po(e)}function Gr(e){return e instanceof Ge}function So(e){return e instanceof qe}function Jr(e){return e instanceof je}function Po(e){return e instanceof Fe}function Ze(e){return e instanceof Fe?e.data:e instanceof Ge||e instanceof qe||e instanceof je?e:Be(e,"Unknown AbstractCrdt")}function ot(e){return e instanceof je||e instanceof qe||e instanceof Ge?e:new Fe(e)}function To(e,t){const n=[];return e.forEach((r,i)=>{t.get(i)||n.push({type:5,id:i})}),t.forEach((r,i)=>{const o=e.get(i);if(o)r.type===0&&(o.type!==0||JSON.stringify(r.data)!==JSON.stringify(o.data))&&n.push({type:3,id:i,data:r.data}),r.parentKey!==o.parentKey&&n.push({type:1,id:i,parentKey:F(r.parentKey,"Parent key must not be missing")});else switch(r.type){case 3:n.push({type:8,id:i,parentId:r.parentId,parentKey:r.parentKey,data:r.data});break;case 1:n.push({type:2,id:i,parentId:r.parentId,parentKey:r.parentKey});break;case 0:n.push(r.parentId?{type:4,id:i,parentId:r.parentId,parentKey:r.parentKey,data:r.data}:{type:4,id:i,data:r.data});break;case 2:n.push({type:7,id:i,parentId:r.parentId,parentKey:r.parentKey});break}}),n}function Ao(e,t){const n=e.updates;for(const[r,i]of Zr(t.updates))n[r]=i;return tn(Tt({},t),{updates:n})}function Lo(e,t){const n=e.updates;for(const[r,i]of Zr(t.updates))n[r]=i;return tn(Tt({},t),{updates:n})}function Ro(e,t){const n=e.updates;return tn(Tt({},t),{updates:n.concat(t.updates)})}function No(e,t){return e?e.type==="LiveObject"&&t.type==="LiveObject"?Ao(e,t):e.type==="LiveMap"&&t.type==="LiveMap"?Lo(e,t):e.type==="LiveList"&&t.type==="LiveList"?Ro(e,t):t:t}function or(e){const t=typeof e;return e==null||t==="string"||t==="boolean"||t==="number"||Array.isArray(e)||Kn(e)}function Kn(e){return e!==null&&typeof e=="object"&&Object.prototype.toString.call(e)==="[object Object]"}function Wr(e,t=""){if(!or)return{path:t||"root",value:e};if(typeof e!="object"||e===null)return!1;for(const[n,r]of Object.entries(e)){const i=t?t+"."+n:n;if(!or(r))return{path:i,value:r};if(typeof r=="object"){const o=Wr(r,i);if(o)return o}}return!1}function Co(e){const t={};for(const[n,r]of e)t[n]=r;return t}function Zr(e){return Object.entries(e)}function Qr(e){try{return JSON.parse(e)}catch{return}}function ei(e){try{const t=e.replace(/-/g,"+").replace(/_/g,"/");return decodeURIComponent(atob(t).split("").map(function(r){return"%"+("00"+r.charCodeAt(0).toString(16)).slice(-2)}).join(""))}catch{return atob(e)}}function Mo(e,t){return Xr(e._getParentKeyOrThrow(),t._getParentKeyOrThrow())}var Ge=class extends nn{constructor(e=[]){super(),this._items=[],this._implicitlyDeletedItems=new WeakSet,this._unacknowledgedSets=new Map;let t;for(let n=0;n<e.length;n++){const r=Ne(t),i=ot(e[n]);i._setParentLink(this,r),this._items.push(i),t=r}}static _deserialize([e],t,n){const r=new Ge;r._attach(e,n);const i=t.get(e);if(i===void 0)return r;for(const[o,s]of i){const a=jr([o,s],t,n);a._setParentLink(r,s.parentKey),r._insertAndSort(a)}return r}_toOps(e,t,n){if(this._id===void 0)throw new Error("Cannot serialize item is not attached");const r=[],i={id:this._id,opId:n==null?void 0:n.generateOpId(),type:2,parentId:e,parentKey:t};r.push(i);for(const o of this._items)r.push(...o._toOps(this._id,o._getParentKeyOrThrow(),n));return r}_insertAndSort(e){this._items.push(e),this._sortItems()}_sortItems(){this._items.sort(Mo),this.invalidate()}_indexOfPosition(e){return this._items.findIndex(t=>t._getParentKeyOrThrow()===e)}_attach(e,t){super._attach(e,t);for(const n of this._items)n._attach(t.generateId(),t)}_detach(){super._detach();for(const e of this._items)e._detach()}_applySetRemote(e){if(this._pool===void 0)throw new Error("Can't attach child if managed pool is not present");const{id:t,parentKey:n}=e,r=yt(e);r._attach(t,this._pool),r._setParentLink(this,n);const i=e.deletedId,o=this._indexOfPosition(n);if(o!==-1){const s=this._items[o];if(s._id===i)return s._detach(),this._items[o]=r,{modified:G(this,[rt(o,r)]),reverse:[]};{this._implicitlyDeletedItems.add(s),this._items[o]=r;const a=[rt(o,r)],l=this._detachItemAssociatedToSetOperation(e.deletedId);return l&&a.push(l),{modified:G(this,a),reverse:[]}}}else{const s=[],a=this._detachItemAssociatedToSetOperation(e.deletedId);return a&&s.push(a),this._insertAndSort(r),s.push(Re(this._indexOfPosition(n),r)),{reverse:[],modified:G(this,s)}}}_applySetAck(e){if(this._pool===void 0)throw new Error("Can't attach child if managed pool is not present");const t=[],n=this._detachItemAssociatedToSetOperation(e.deletedId);n&&t.push(n);const r=this._unacknowledgedSets.get(e.parentKey);if(r!==void 0){if(r!==e.opId)return t.length===0?{modified:!1}:{modified:G(this,t),reverse:[]};this._unacknowledgedSets.delete(e.parentKey)}const i=this._indexOfPosition(e.parentKey),o=this._items.find(s=>s._id===e.id);if(o!==void 0){if(o._parentKey===e.parentKey)return{modified:t.length>0?G(this,t):!1,reverse:[]};i!==-1&&(this._implicitlyDeletedItems.add(this._items[i]),this._items.splice(i,1),t.push(Rt(i)));const s=this._items.indexOf(o);o._setParentLink(this,e.parentKey),this._sortItems();const a=this._items.indexOf(o);return a!==s&&t.push(Je(s,a,o)),{modified:t.length>0?G(this,t):!1,reverse:[]}}else{const s=this._pool.getNode(e.id);if(s&&this._implicitlyDeletedItems.has(s)){s._setParentLink(this,e.parentKey),this._implicitlyDeletedItems.delete(s),this._insertAndSort(s);const a=this._items.indexOf(s);return{modified:G(this,[i===-1?Re(a,s):rt(a,s),...t]),reverse:[]}}else{i!==-1&&this._items.splice(i,1);const{newItem:a,newIndex:l}=this._createAttachItemAndSort(e,e.parentKey);return{modified:G(this,[i===-1?Re(l,a):rt(l,a),...t]),reverse:[]}}}}_detachItemAssociatedToSetOperation(e){if(e===void 0||this._pool===void 0)return null;const t=this._pool.getNode(e);if(t===void 0)return null;const n=this._detachChild(t);return n.modified===!1?null:n.modified.updates[0]}_applyRemoteInsert(e){if(this._pool===void 0)throw new Error("Can't attach child if managed pool is not present");const t=e.parentKey,n=this._indexOfPosition(t);n!==-1&&this._shiftItemPosition(n,t);const{newItem:r,newIndex:i}=this._createAttachItemAndSort(e,t);return{modified:G(this,[Re(i,r)]),reverse:[]}}_applyInsertAck(e){const t=this._items.find(i=>i._id===e.id),n=e.parentKey,r=this._indexOfPosition(n);if(t){if(t._parentKey===n)return{modified:!1};{const i=this._items.indexOf(t);r!==-1&&this._shiftItemPosition(r,n),t._setParentLink(this,n),this._sortItems();const o=this._indexOfPosition(n);return o===i?{modified:!1}:{modified:G(this,[Je(i,o,t)]),reverse:[]}}}else{const i=F(this._pool).getNode(e.id);if(i&&this._implicitlyDeletedItems.has(i)){i._setParentLink(this,n),this._implicitlyDeletedItems.delete(i),this._insertAndSort(i);const o=this._indexOfPosition(n);return{modified:G(this,[Re(o,i)]),reverse:[]}}else{r!==-1&&this._shiftItemPosition(r,n);const{newItem:o,newIndex:s}=this._createAttachItemAndSort(e,n);return{modified:G(this,[Re(s,o)]),reverse:[]}}}}_applyInsertUndoRedo(e){var t;const{id:n,parentKey:r}=e,i=yt(e);if(((t=this._pool)==null?void 0:t.getNode(n))!==void 0)return{modified:!1};i._attach(n,F(this._pool)),i._setParentLink(this,r);const o=this._indexOfPosition(r);let s=r;if(o!==-1){const l=this._items[o]?this._items[o]._getParentKeyOrThrow():void 0,u=this._items[o+1]?this._items[o+1]._getParentKeyOrThrow():void 0;s=Ne(l,u),i._setParentLink(this,s)}this._insertAndSort(i);const a=this._indexOfPosition(s);return{modified:G(this,[Re(a,i)]),reverse:[{type:5,id:n}]}}_applySetUndoRedo(e){var t;const{id:n,parentKey:r}=e,i=yt(e);if(((t=this._pool)==null?void 0:t.getNode(n))!==void 0)return{modified:!1};this._unacknowledgedSets.set(r,F(e.opId));const o=this._indexOfPosition(r);i._attach(n,F(this._pool)),i._setParentLink(this,r);const s=r;if(o!==-1){const a=this._items[o];a._detach(),this._items[o]=i;const l=a._toOps(F(this._id),r,this._pool);pn(l,e.id);const u=[rt(o,i)],c=this._detachItemAssociatedToSetOperation(e.deletedId);return c&&u.push(c),{modified:G(this,u),reverse:l}}else{this._insertAndSort(i),this._detachItemAssociatedToSetOperation(e.deletedId);const a=this._indexOfPosition(s);return{reverse:[{type:5,id:n}],modified:G(this,[Re(a,i)])}}}_attachChild(e,t){if(this._pool===void 0)throw new Error("Can't attach child if managed pool is not present");let n;return e.intent==="set"?t===1?n=this._applySetRemote(e):t===2?n=this._applySetAck(e):n=this._applySetUndoRedo(e):t===1?n=this._applyRemoteInsert(e):t===2?n=this._applyInsertAck(e):n=this._applyInsertUndoRedo(e),n.modified!==!1&&this.invalidate(),n}_detachChild(e){if(e){const t=F(e._parentKey),n=e._toOps(F(this._id),t,this._pool),r=this._items.indexOf(e);return r===-1?{modified:!1}:(this._items.splice(r,1),this.invalidate(),e._detach(),{modified:G(this,[Rt(r)]),reverse:n})}return{modified:!1}}_applySetChildKeyRemote(e,t){var n;if(this._implicitlyDeletedItems.has(t)){this._implicitlyDeletedItems.delete(t),t._setParentLink(this,e),this._insertAndSort(t);const o=this._items.indexOf(t);return{modified:G(this,[Re(o,t)]),reverse:[]}}const r=t._parentKey;if(e===r)return{modified:!1};const i=this._indexOfPosition(e);if(i===-1){const o=this._items.indexOf(t);t._setParentLink(this,e),this._sortItems();const s=this._items.indexOf(t);return s===o?{modified:!1}:{modified:G(this,[Je(o,s,t)]),reverse:[]}}else{this._items[i]._setParentLink(this,Ne(e,(n=this._items[i+1])==null?void 0:n._getParentKeyOrThrow()));const o=this._items.indexOf(t);t._setParentLink(this,e),this._sortItems();const s=this._items.indexOf(t);return s===o?{modified:!1}:{modified:G(this,[Je(o,s,t)]),reverse:[]}}}_applySetChildKeyAck(e,t){var n,r;const i=F(t._parentKey);if(this._implicitlyDeletedItems.has(t)){const o=this._indexOfPosition(e);return this._implicitlyDeletedItems.delete(t),o!==-1&&this._items[o]._setParentLink(this,Ne(e,(n=this._items[o+1])==null?void 0:n._getParentKeyOrThrow())),t._setParentLink(this,e),this._insertAndSort(t),{modified:!1}}else{if(e===i)return{modified:!1};const o=this._items.indexOf(t),s=this._indexOfPosition(e);s!==-1&&this._items[s]._setParentLink(this,Ne(e,(r=this._items[s+1])==null?void 0:r._getParentKeyOrThrow())),t._setParentLink(this,e),this._sortItems();const a=this._items.indexOf(t);return o===a?{modified:!1}:{modified:G(this,[Je(o,a,t)]),reverse:[]}}}_applySetChildKeyUndoRedo(e,t){var n;const r=F(t._parentKey),i=this._items.indexOf(t),o=this._indexOfPosition(e);o!==-1&&this._items[o]._setParentLink(this,Ne(e,(n=this._items[o+1])==null?void 0:n._getParentKeyOrThrow())),t._setParentLink(this,e),this._sortItems();const s=this._items.indexOf(t);return i===s?{modified:!1}:{modified:G(this,[Je(i,s,t)]),reverse:[{type:1,id:F(t._id),parentKey:r}]}}_setChildKey(e,t,n){return n===1?this._applySetChildKeyRemote(e,t):n===2?this._applySetChildKeyAck(e,t):this._applySetChildKeyUndoRedo(e,t)}_apply(e,t){return super._apply(e,t)}_serialize(){if(this.parent.type!=="HasParent")throw new Error("Cannot serialize LiveList if parent is missing");return{type:1,parentId:F(this.parent.node._id,"Parent node expected to have ID"),parentKey:this.parent.key}}get length(){return this._items.length}push(e){return this.insert(e,this.length)}insert(e,t){if(t<0||t>this._items.length)throw new Error(`Cannot insert list item at index "${t}". index should be between 0 and ${this._items.length}`);const n=this._items[t-1]?this._items[t-1]._getParentKeyOrThrow():void 0,r=this._items[t]?this._items[t]._getParentKeyOrThrow():void 0,i=Ne(n,r),o=ot(e);if(o._setParentLink(this,i),this._insertAndSort(o),this._pool&&this._id){const s=this._pool.generateId();o._attach(s,this._pool),this._pool.dispatch(o._toOps(this._id,i,this._pool),[{type:5,id:s}],new Map([[this._id,G(this,[Re(t,o)])]]))}}move(e,t){if(t<0)throw new Error("targetIndex cannot be less than 0");if(t>=this._items.length)throw new Error("targetIndex cannot be greater or equal than the list length");if(e<0)throw new Error("index cannot be less than 0");if(e>=this._items.length)throw new Error("index cannot be greater or equal than the list length");let n=null,r=null;e<t?(r=t===this._items.length-1?void 0:this._items[t+1]._getParentKeyOrThrow(),n=this._items[t]._getParentKeyOrThrow()):(r=this._items[t]._getParentKeyOrThrow(),n=t===0?void 0:this._items[t-1]._getParentKeyOrThrow());const i=Ne(n,r),o=this._items[e],s=o._getParentKeyOrThrow();if(o._setParentLink(this,i),this._sortItems(),this._pool&&this._id){const a=new Map([[this._id,G(this,[Je(e,t,o)])]]);this._pool.dispatch([{type:1,id:F(o._id),opId:this._pool.generateOpId(),parentKey:i}],[{type:1,id:F(o._id),parentKey:s}],a)}}delete(e){if(e<0||e>=this._items.length)throw new Error(`Cannot delete list item at index "${e}". index should be between 0 and ${this._items.length-1}`);const t=this._items[e];if(t._detach(),this._items.splice(e,1),this.invalidate(),this._pool){const n=t._id;if(n){const r=new Map;r.set(F(this._id),G(this,[Rt(e)])),this._pool.dispatch([{id:n,opId:this._pool.generateOpId(),type:5}],t._toOps(F(this._id),t._getParentKeyOrThrow()),r)}}}clear(){if(this._pool){const e=[],t=[],n=[];for(const i of this._items){i._detach();const o=i._id;o&&(e.push({type:5,id:o,opId:this._pool.generateOpId()}),t.push(...i._toOps(F(this._id),i._getParentKeyOrThrow())),n.push(Rt(0)))}this._items=[],this.invalidate();const r=new Map;r.set(F(this._id),G(this,n)),this._pool.dispatch(e,t,r)}else{for(const e of this._items)e._detach();this._items=[],this.invalidate()}}set(e,t){if(e<0||e>=this._items.length)throw new Error(`Cannot set list item at index "${e}". index should be between 0 and ${this._items.length-1}`);const n=this._items[e],r=n._getParentKeyOrThrow(),i=n._id;n._detach();const o=ot(t);if(o._setParentLink(this,r),this._items[e]=o,this.invalidate(),this._pool&&this._id){const s=this._pool.generateId();o._attach(s,this._pool);const a=new Map;a.set(this._id,G(this,[rt(e,o)]));const l=o._toOps(this._id,r,this._pool);pn(l,i),this._unacknowledgedSets.set(r,F(l[0].opId));const u=n._toOps(this._id,r,void 0);pn(u,s),this._pool.dispatch(l,u,a)}}toArray(){return this._items.map(e=>Ze(e))}every(e){return this.toArray().every(e)}filter(e){return this.toArray().filter(e)}find(e){return this.toArray().find(e)}findIndex(e){return this.toArray().findIndex(e)}forEach(e){return this.toArray().forEach(e)}get(e){if(!(e<0||e>=this._items.length))return Ze(this._items[e])}indexOf(e,t){return this.toArray().indexOf(e,t)}lastIndexOf(e,t){return this.toArray().lastIndexOf(e,t)}map(e){return this._items.map((t,n)=>e(Ze(t),n))}some(e){return this.toArray().some(e)}[Symbol.iterator](){return new Uo(this._items)}_createAttachItemAndSort(e,t){const n=yt(e);n._attach(e.id,F(this._pool)),n._setParentLink(this,t),this._insertAndSort(n);const r=this._indexOfPosition(t);return{newItem:n,newIndex:r}}_shiftItemPosition(e,t){var n;const r=Ne(t,this._items.length>e+1?(n=this._items[e+1])==null?void 0:n._getParentKeyOrThrow():void 0);this._items[e]._setParentLink(this,r)}toImmutable(){return super.toImmutable()}_toImmutable(){return this._items.map(t=>t.toImmutable())}},Uo=class{constructor(e){this._innerIterator=e[Symbol.iterator]()}[Symbol.iterator](){return this}next(){const e=this._innerIterator.next();return e.done?{done:!0,value:void 0}:{value:Ze(e.value)}}};function G(e,t){return{node:e,type:"LiveList",updates:t}}function rt(e,t){return{index:e,type:"set",item:t instanceof Fe?t.data:t}}function Rt(e){return{index:e,type:"delete"}}function Re(e,t){return{index:e,type:"insert",item:t instanceof Fe?t.data:t}}function Je(e,t,n){return{index:t,type:"move",previousIndex:e,item:n instanceof Fe?n.data:n}}function pn(e,t){if(e.length===0)throw new Error("Internal error. Serialized LiveStructure should have at least 1 operation");const n=e[0];n.intent="set",n.deletedId=t}var Do=["websocket:presence","websocket:storage","room:read","room:write","rooms:read","rooms:write"];function zo(e){if(!Kn(e))return!1;const{iat:t,exp:n}=e;return typeof t=="number"&&typeof n=="number"}function $o(e){const t=Date.now()/1e3;return t>e.exp-300||t<e.iat+300}function Ko(e){return Do.includes(e)}function ti(e){return Array.isArray(e)&&e.every(t=>typeof t=="string")}function ni(e){return typeof e.appId=="string"&&e.roomId===void 0&&ti(e.scopes)}function Fn(e){return typeof e.appId=="string"&&typeof e.roomId=="string"&&typeof e.actor=="number"&&(e.id===void 0||typeof e.id=="string")&&ti(e.scopes)&&(e.maxConnectionsPerRoom===void 0||typeof e.maxConnectionsPerRoom=="number")}function Fo(e){return ni(e)||Fn(e)}function Ho(e){const t=e.split(".");if(t.length!==3)throw new Error("Authentication error: invalid JWT token");const n=Qr(ei(t[1]));if(n&&zo(n))return n;throw new Error("Authentication error: missing JWT metadata")}function Vo(e){const t=Ho(e);if(t&&Fn(t))return po(t,["maxConnections"]);throw new Error("Authentication error: we expected a room token but did not get one. Hint: if you are using a callback, ensure the room is passed when creating the token. For more information: https://liveblocks.io/docs/api-reference/liveblocks-client#createClientCallback")}function Bo(e){return Object.defineProperty(e,"count",{value:e.length,enumerable:!1}),Object.defineProperty(e,"toArray",{value:()=>e,enumerable:!1}),$n(e)}function ri(e){return e===null||typeof e=="string"||typeof e=="number"||typeof e=="boolean"}function ii(e){return Array.isArray(e)}function Xo(e){return!ri(e)&&!ii(e)}C.__spreadValues=Tt;C.__spreadProps=tn;C.__async=mo;C.deprecate=_o;C.deprecateIf=go;C.throwUsageError=vo;C.errorIf=yo;C.assertNever=Be;C.nn=F;C.ClientMsgCode=zr;C.OpCode=$r;C.CrdtType=Kr;C.isRootCrdt=wo;C.isChildCrdt=Fr;C.ServerMsgCode=Hr;C.isRoomEventName=bo;C.WebsocketCloseCodes=Vr;C.LiveRegister=Fe;C.makePosition=Ne;C.comparePosition=Xr;C.LiveList=Ge;C.LiveMap=qe;C.LiveObject=je;C.freeze=$n;C.compact=xo;C.compactObject=Oo;C.isSameNodeOrChildOf=qr;C.isLiveNode=ae;C.isLiveList=Gr;C.isLiveObject=Jr;C.getTreesDiffOperations=To;C.mergeStorageUpdates=No;C.isPlainObject=Kn;C.findNonSerializableValue=Wr;C.tryParseJson=Qr;C.b64decode=ei;C.isTokenExpired=$o;C.isScope=Ko;C.isAppOnlyAuthToken=ni;C.isRoomAuthToken=Fn;C.isAuthToken=Fo;C.parseRoomAuthToken=Vo;C.asArrayWithLegacyMethods=Bo;C.isJsonScalar=ri;C.isJsonArray=ii;C.isJsonObject=Xo;Object.defineProperty(Ae,"__esModule",{value:!0});var L=C;function De(){const e=new Set,t=new Set;function n(s){return t.add(s),()=>t.delete(s)}function r(s){return e.add(s),()=>e.delete(s)}function i(s){e.forEach(a=>a(s)),e.clear(),t.forEach(a=>a(s))}function o(){e.clear(),t.clear()}return{notify:i,subscribe:n,subscribeOnce:r,clear:o,observable:{subscribe:n,subscribeOnce:r}}}function oi(e,t){let n=!1;const r=L.__spreadValues.call(void 0,{},e);return Object.keys(t).forEach(i=>{const o=i,s=t[o];r[o]!==s&&(s===void 0?delete r[o]:r[o]=s,n=!0)}),n?r:e}var rn=class{constructor(){this._ev=De()}get didInvalidate(){return this._ev.observable}invalidate(){this._cache!==void 0&&(this._cache=void 0,this._ev.notify())}get current(){var e;return(e=this._cache)!=null?e:this._cache=this._toImmutable()}},Yo=class extends rn{constructor(e){super(),this._me=L.freeze.call(void 0,L.compactObject.call(void 0,e))}_toImmutable(){return this._me}patch(e){const t=this._me,n=oi(t,e);t!==n&&(this._me=L.freeze.call(void 0,n),this.invalidate())}};function qo(e,t){return L.freeze.call(void 0,L.compactObject.call(void 0,L.__spreadProps.call(void 0,L.__spreadValues.call(void 0,{},e),{presence:t})))}var jo=class extends rn{constructor(){super(),this._connections={},this._presences={},this._users={}}_toImmutable(){const e=L.compact.call(void 0,Object.keys(this._presences).map(t=>this.getUser(Number(t))));return L.asArrayWithLegacyMethods.call(void 0,e)}clearOthers(){this._connections={},this._presences={},this._users={},this.invalidate()}_getUser(e){const t=this._connections[e],n=this._presences[e];if(t!==void 0&&n!==void 0)return qo(t,n)}getUser(e){const t=this._users[e];if(t)return t;const n=this._getUser(e);if(n)return this._users[e]=n,n}_invalidateUser(e){this._users[e]!==void 0&&delete this._users[e],this.invalidate()}setConnection(e,t,n){this._connections[e]=L.freeze.call(void 0,{connectionId:e,id:t,info:n}),this._presences[e]!==void 0&&this._invalidateUser(e)}removeConnection(e){delete this._connections[e],delete this._presences[e],this._invalidateUser(e)}setOther(e,t){this._presences[e]=L.freeze.call(void 0,L.compactObject.call(void 0,t)),this._connections[e]!==void 0&&this._invalidateUser(e)}patchOther(e,t){const n=this._presences[e];if(n===void 0)return;const r=oi(n,t);n!==r&&(this._presences[e]=L.freeze.call(void 0,r),this._invalidateUser(e))}},Go=class extends rn{constructor(e){super(),this._value=L.freeze.call(void 0,L.compactObject.call(void 0,e))}_toImmutable(){return this._value}set(e){this._value=L.freeze.call(void 0,e),this.invalidate()}},Jo=class extends rn{constructor(e,t){super(),this._refs=e,this._refs.forEach(n=>{n.didInvalidate.subscribe(()=>this.invalidate())}),this._transform=t}_toImmutable(){return this._transform(this._refs[0].current,this._refs[1].current)}},mn=[250,500,1e3,2e3,4e3,8e3,1e4],_n=[2e3,3e4,6e4,3e5],Wo=3e4,Zo=2e3;function Qo(e){let t=0;return()=>`${e}:${t++}`}function gn(e){return e.state==="open"||e.state==="connecting"}function es(e,t,n){var r;const i=f=>f(),o=(r=t.unstable_batchedUpdates)!=null?r:i,s={roomId:t.roomId,getNode:f=>e.nodes.get(f),addNode:(f,g)=>void e.nodes.set(f,g),deleteNode:f=>void e.nodes.delete(f),generateId:()=>`${x()}:${e.clock++}`,generateOpId:()=>`${x()}:${e.opClock++}`,dispatch(f,g,y){const E=e.activeBatch;E?(E.ops.push(...f),y.forEach((A,ee)=>{E.updates.storageUpdates.set(ee,L.mergeStorageUpdates.call(void 0,E.updates.storageUpdates.get(ee),A))}),E.reverseOps.push(...g)):o(()=>{I(g,i),e.redoStack=[],Jn(f),S({storageUpdates:y},i)})}},a={customEvent:De(),me:De(),others:De(),error:De(),connection:De(),storage:De(),history:De(),storageDidLoad:De()},l=n||{authenticate(f,g){const y=e.token,E=y!==null&&L.parseRoomAuthToken.call(void 0,y);if(E&&!L.isTokenExpired.call(void 0,E)){const A=g(y);V(E,A)}else return f(t.roomId).then(({token:A})=>{if(e.connection.current.state!=="authenticating")return;const ee=L.parseRoomAuthToken.call(void 0,A),j=g(A);V(ee,j),e.token=A}).catch(A=>Q())},send(f){if(e.socket===null)throw new Error("Can't send message if socket is null");e.socket.send(JSON.stringify(f))},delayFlush(f){return setTimeout(ye,f)},startHeartbeatInterval(){return setInterval(ue,Wo)},schedulePongTimeout(){return setTimeout(ve,Zo)},scheduleReconnect(f){return setTimeout(R,f)}},u=new Jo([e.connection,e.me],(f,g)=>gn(f)?{connectionId:f.id,id:f.userId,info:f.userInfo,presence:g}:null);function c(f,g){if(f.items.length===0)throw new Error("Internal error: cannot load storage without items");e.root?p(f.items,g):e.root=_(f.items);for(const y in e.initialStorage)e.root.get(y)===void 0&&e.root.set(y,e.initialStorage[y])}function d(f){const g=new Map;let y=null;for(const[E,A]of f)if(L.isRootCrdt.call(void 0,A))y=[E,A];else{const ee=[E,A],j=g.get(A.parentId);j!==void 0?j.push(ee):g.set(A.parentId,[ee])}if(y===null)throw new Error("Root can't be null");return[y,g]}function p(f,g){if(!e.root)return;const y=new Map;e.nodes.forEach((ee,j)=>{y.set(j,ee._serialize())});const E=L.getTreesDiffOperations.call(void 0,y,new Map(f)),A=H(E,!1);S(A.updates,g)}function _(f){const[g,y]=d(f);return L.LiveObject._deserialize(g,y,s)}function b(f,g){e.undoStack.length>=50&&e.undoStack.shift(),e.undoStack.push(f),P(g)}function I(f,g){e.pausedHistory!==null?e.pausedHistory.unshift(...f):b(f,g)}function S({storageUpdates:f=new Map,presence:g=!1,others:y=[]},E){E(()=>{if(y.length>0){const A=e.others.current;for(const ee of y)a.others.notify({others:A,event:ee})}if(g&&a.me.notify(e.me.current),f.size>0){const A=Array.from(f.values());a.storage.notify(A)}})}function x(){const f=e.connection.current;if(gn(f))return f.id;if(e.lastConnectionId!==null)return e.lastConnectionId;throw new Error("Internal. Tried to get connection id but connection was never open")}function H(f,g){const y={reverse:[],updates:{storageUpdates:new Map,presence:!1}},E=new Set;for(const A of f)if(A.type==="presence"){const ee={type:"presence",data:{}};for(const j in A.data)ee.data[j]=e.me.current[j];if(e.me.patch(A.data),e.buffer.me===null)e.buffer.me={type:"partial",data:A.data};else for(const j in A.data)e.buffer.me.data[j]=A.data[j];y.reverse.unshift(ee),y.updates.presence=!0}else{let ee;A.opId||(A.opId=s.generateOpId()),g?ee=0:ee=e.offlineOperations.delete(L.nn.call(void 0,A.opId))?2:1;const j=N(A,ee);if(j.modified){const dn=j.modified.node.parent.type==="HasParent"?L.nn.call(void 0,j.modified.node.parent.node._id,"Expected parent node to have an ID"):void 0;(!dn||!E.has(dn))&&(y.updates.storageUpdates.set(L.nn.call(void 0,j.modified.node._id),L.mergeStorageUpdates.call(void 0,y.updates.storageUpdates.get(L.nn.call(void 0,j.modified.node._id)),j.modified)),y.reverse.unshift(...j.reverse)),(A.type===2||A.type===7||A.type===4)&&E.add(L.nn.call(void 0,j.modified.node._id))}}return y}function N(f,g){switch(f.type){case 6:case 3:case 5:{const y=e.nodes.get(f.id);return y===void 0?{modified:!1}:y._apply(f,g===0)}case 1:{const y=e.nodes.get(f.id);return y===void 0?{modified:!1}:y.parent.type==="HasParent"&&L.isLiveList.call(void 0,y.parent.node)?y.parent.node._setChildKey(f.parentKey,y,g):{modified:!1}}case 4:case 2:case 7:case 8:{if(f.parentId===void 0)return{modified:!1};const y=e.nodes.get(f.parentId);return y===void 0?{modified:!1}:y._attachChild(f,g)}}}function m(f,g){return a.storage.subscribe(y=>{const E=y.filter(A=>L.isSameNodeOrChildOf.call(void 0,A.node,f));E.length>0&&g(E)})}function T(f,g){return a.storage.subscribe(y=>{for(const E of y)E.node._id===f._id&&g(E.node)})}function k(f,g,y){if(typeof f=="string"&&L.isRoomEventName.call(void 0,f)){if(typeof g!="function")throw new Error("Second argument must be a callback function");const E=g;switch(f){case"event":return a.customEvent.subscribe(E);case"my-presence":return a.me.subscribe(E);case"others":{const A=E;return a.others.subscribe(({others:ee,event:j})=>A(ee,j))}case"error":return a.error.subscribe(E);case"connection":return a.connection.subscribe(E);case"storage":return a.storage.subscribe(E);case"history":return a.history.subscribe(E);default:return L.assertNever.call(void 0,f,"Unknown event")}}if(g===void 0||typeof f=="function")if(typeof f=="function"){const E=f;return a.storage.subscribe(E)}else throw new Error("Please specify a listener callback");if(L.isLiveNode.call(void 0,f)){const E=f;return y!=null&&y.isDeep?m(E,g):T(E,g)}throw new Error(`"${f}" is not a valid event name`)}function w(){return e.connection.current.state}function R(){var f,g,y,E;if(e.connection.current.state!=="closed"&&e.connection.current.state!=="unavailable")return null;const A=os(t.authentication,(g=(f=t.polyfills)==null?void 0:f.fetch)!=null?g:t.fetchPolyfill),ee=is(t.liveblocksServer,(E=(y=t.polyfills)==null?void 0:y.WebSocket)!=null?E:t.WebSocketPolyfill);ne({state:"authenticating"},o),l.authenticate(A,ee)}function K(f,g){const y={};e.buffer.me===null&&(e.buffer.me={type:"partial",data:{}});for(const E in f){const A=f[E];A!==void 0&&(e.buffer.me.data[E]=A,y[E]=e.me.current[E])}e.me.patch(f),e.activeBatch?(g!=null&&g.addToHistory&&e.activeBatch.reverseOps.push({type:"presence",data:y}),e.activeBatch.updates.presence=!0):(ye(),o(()=>{g!=null&&g.addToHistory&&I([{type:"presence",data:y}],i),S({presence:!0},i)}))}function V(f,g){g.addEventListener("message",B),g.addEventListener("open",he),g.addEventListener("close",Y),g.addEventListener("error",le),ne({state:"connecting",id:f.actor,userInfo:f.info,userId:f.id},o),e.idFactory=Qo(f.actor),e.socket=g}function Q(f){e.token=null,ne({state:"unavailable"},o),e.numberOfRetry++,e.timeoutHandles.reconnect=l.scheduleReconnect(re())}function q(f){f==="visible"&&e.connection.current.state==="open"&&ue()}function fe(f){if(f.targetActor!==void 0){const y=e.others.getUser(f.actor);e.others.setOther(f.actor,f.data);const E=e.others.getUser(f.actor);if(y===void 0&&E!==void 0)return{type:"enter",user:E}}else e.others.patchOther(f.actor,f.data);const g=e.others.getUser(f.actor);if(g)return{type:"update",updates:f.data,user:g}}function h(f){const g=e.others.getUser(f.actor);return g?(e.others.removeConnection(f.actor),{type:"leave",user:g}):null}function O(f){for(const g in f.users){const y=f.users[g],E=Number(g);e.others.setConnection(E,y.id,y.info)}return{type:"reset"}}function v(){e.connection.current.state==="unavailable"&&nt()}function P(f){f(()=>{a.history.notify({canUndo:Zn(),canRedo:Qn()})})}function M(f){e.others.setConnection(f.actor,f.id,f.info),e.buffer.messages.push({type:100,data:e.me.current,targetActor:f.actor}),ye();const g=e.others.getUser(f.actor);return g?{type:"enter",user:g}:void 0}function U(f){return L.isJsonObject.call(void 0,f)?f:null}function z(f){const g=L.tryParseJson.call(void 0,f);return g===void 0?null:L.isJsonArray.call(void 0,g)?L.compact.call(void 0,g.map(y=>U(y))):L.compact.call(void 0,[U(g)])}function B(f){if(f.data==="pong"){clearTimeout(e.timeoutHandles.pongTimeout);return}const g=z(f.data);if(g===null||g.length===0)return;const y={storageUpdates:new Map,others:[]};o(()=>{for(const E of g)switch(E.type){case 101:{const A=M(E);A&&y.others.push(A);break}case 100:{const A=fe(E);A&&y.others.push(A);break}case 103:{a.customEvent.notify({connectionId:E.actor,event:E.event});break}case 102:{const A=h(E);A&&y.others.push(A);break}case 104:{y.others.push(O(E));break}case 200:{const A=new Map(e.offlineOperations);c(E,i),Ki(A,i),hn==null||hn(),a.storageDidLoad.notify();break}case 201:{H(E.ops,!1).updates.storageUpdates.forEach((ee,j)=>{y.storageUpdates.set(j,L.mergeStorageUpdates.call(void 0,y.storageUpdates.get(j),ee))});break}}S(y,i)})}function Y(f){e.socket=null,clearTimeout(e.timeoutHandles.pongTimeout),clearInterval(e.intervalHandles.heartbeat),e.timeoutHandles.flush&&clearTimeout(e.timeoutHandles.flush),clearTimeout(e.timeoutHandles.reconnect),e.others.clearOthers(),o(()=>{if(S({others:[{type:"reset"}]},i),f.code>=4e3&&f.code<=4100){ne({state:"failed"},i);const g=new rs(f.reason,f.code);a.error.notify(g);const y=re(!0);e.numberOfRetry++,ne({state:"unavailable"},i),e.timeoutHandles.reconnect=l.scheduleReconnect(y)}else if(f.code===4999)ne({state:"closed"},i);else{const g=re();e.numberOfRetry++,ne({state:"unavailable"},i),e.timeoutHandles.reconnect=l.scheduleReconnect(g)}})}function ne(f,g){e.connection.set(f),g(()=>{a.connection.notify(f.state)})}function re(f=!1){return f?_n[e.numberOfRetry<_n.length?e.numberOfRetry:_n.length-1]:mn[e.numberOfRetry<mn.length?e.numberOfRetry:mn.length-1]}function le(){}function he(){clearInterval(e.intervalHandles.heartbeat),e.intervalHandles.heartbeat=l.startHeartbeatInterval(),e.connection.current.state==="connecting"&&(ne(L.__spreadProps.call(void 0,L.__spreadValues.call(void 0,{},e.connection.current),{state:"open"}),o),e.numberOfRetry=0,e.lastConnectionId!==void 0&&(e.buffer.me={type:"full",data:L.__spreadValues.call(void 0,{},e.me.current)},ye()),e.lastConnectionId=e.connection.current.id,e.root&&e.buffer.messages.push({type:200}),ye())}function ue(){e.socket!==null&&(clearTimeout(e.timeoutHandles.pongTimeout),e.timeoutHandles.pongTimeout=l.schedulePongTimeout(),e.socket.readyState===e.socket.OPEN&&e.socket.send("ping"))}function ve(){nt()}function nt(){e.socket&&(e.socket.removeEventListener("open",he),e.socket.removeEventListener("message",B),e.socket.removeEventListener("close",Y),e.socket.removeEventListener("error",le),e.socket.close(),e.socket=null),ne({state:"unavailable"},o),clearTimeout(e.timeoutHandles.pongTimeout),e.timeoutHandles.flush&&clearTimeout(e.timeoutHandles.flush),clearTimeout(e.timeoutHandles.reconnect),clearInterval(e.intervalHandles.heartbeat),R()}function Ki(f,g){if(f.size===0)return;const y=[],E=Array.from(f.values()),A=H(E,!0);y.push({type:201,ops:E}),S(A.updates,g),l.send(y)}function ye(){const f=e.buffer.storageOperations;if(f.length>0&&f.forEach(E=>{e.offlineOperations.set(L.nn.call(void 0,E.opId),E)}),e.socket===null||e.socket.readyState!==e.socket.OPEN){e.buffer.storageOperations=[];return}const g=Date.now();if(g-e.lastFlushTime>t.throttleDelay){const E=Fi(e);if(E.length===0)return;l.send(E),e.buffer={messages:[],storageOperations:[],me:null},e.lastFlushTime=g}else e.timeoutHandles.flush!==null&&clearTimeout(e.timeoutHandles.flush),e.timeoutHandles.flush=l.delayFlush(t.throttleDelay-(g-e.lastFlushTime))}function Fi(f){const g=[];f.buffer.me&&g.push(f.buffer.me.type==="full"?{type:100,targetActor:-1,data:f.buffer.me.data}:{type:100,data:f.buffer.me.data});for(const y of f.buffer.messages)g.push(y);return f.buffer.storageOperations.length>0&&g.push({type:201,ops:f.buffer.storageOperations}),g}function Hi(){e.socket&&(e.socket.removeEventListener("open",he),e.socket.removeEventListener("message",B),e.socket.removeEventListener("close",Y),e.socket.removeEventListener("error",le),e.socket.close(),e.socket=null),o(()=>{ne({state:"closed"},i),e.timeoutHandles.flush&&clearTimeout(e.timeoutHandles.flush),clearTimeout(e.timeoutHandles.reconnect),clearTimeout(e.timeoutHandles.pongTimeout),clearInterval(e.intervalHandles.heartbeat),e.others.clearOthers(),S({others:[{type:"reset"}]},i),Object.values(a).forEach(f=>f.clear())})}function Vi(){return e.me.current}function Bi(){return e.others.current}function Xi(f,g={shouldQueueEventIfNotReady:!1}){e.socket===null&&!g.shouldQueueEventIfNotReady||(e.buffer.messages.push({type:103,event:f}),ye())}function Jn(f){e.buffer.storageOperations.push(...f),ye()}let fn=null,hn=null;function Wn(){return fn===null&&(e.buffer.messages.push({type:200}),ye(),fn=new Promise(f=>hn=f)),fn}function Yi(){const f=e.root;return f!==void 0?f:(Wn(),null)}function qi(){return L.__async.call(void 0,this,null,function*(){return e.root?Promise.resolve({root:e.root}):(yield Wn(),{root:L.nn.call(void 0,e.root)})})}function ji(){if(e.activeBatch)throw new Error("undo is not allowed during a batch");const f=e.undoStack.pop();if(f===void 0)return;e.pausedHistory=null;const g=H(f,!0);o(()=>{S(g.updates,i),e.redoStack.push(g.reverse),P(i)});for(const y of f)y.type!=="presence"&&e.buffer.storageOperations.push(y);ye()}function Zn(){return e.undoStack.length>0}function Gi(){if(e.activeBatch)throw new Error("redo is not allowed during a batch");const f=e.redoStack.pop();if(f===void 0)return;e.pausedHistory=null;const g=H(f,!0);o(()=>{S(g.updates,i),e.undoStack.push(g.reverse),P(i)});for(const y of f)y.type!=="presence"&&e.buffer.storageOperations.push(y);ye()}function Qn(){return e.redoStack.length>0}function Ji(f){if(e.activeBatch)return f();let g;return o(()=>{e.activeBatch={ops:[],updates:{storageUpdates:new Map,presence:!1,others:[]},reverseOps:[]};try{g=f()}finally{const y=e.activeBatch;e.activeBatch=null,y.reverseOps.length>0&&I(y.reverseOps,i),y.ops.length>0&&(e.redoStack=[]),y.ops.length>0&&Jn(y.ops),S(y.updates,i),ye()}}),g}function Wi(){e.pausedHistory=[]}function Zi(){const f=e.pausedHistory;e.pausedHistory=null,f!==null&&f.length>0&&b(f,o)}function Qi(){e.socket&&(e.socket=null)}function eo(f){Y(f)}return{onClose:Y,onMessage:B,authenticationSuccess:V,heartbeat:ue,onNavigatorOnline:v,simulateSocketClose:Qi,simulateSendCloseEvent:eo,onVisibilityChange:q,getUndoStack:()=>e.undoStack,getItemsCount:()=>e.nodes.size,connect:R,disconnect:Hi,subscribe:k,updatePresence:K,broadcastEvent:Xi,batch:Ji,undo:ji,redo:Gi,canUndo:Zn,canRedo:Qn,pauseHistory:Wi,resumeHistory:Zi,getStorage:qi,getStorageSnapshot:Yi,events:{customEvent:a.customEvent.observable,others:a.others.observable,me:a.me.observable,error:a.error.observable,connection:a.connection.observable,storage:a.storage.observable,history:a.history.observable,storageDidLoad:a.storageDidLoad.observable},getConnectionState:w,isSelfAware:()=>gn(e.connection.current),getSelf:()=>u.current,getPresence:Vi,getOthers:Bi}}function ts(e,t){const n=new jo,r=new Go({state:"closed"});return{token:null,lastConnectionId:null,socket:null,numberOfRetry:0,lastFlushTime:0,timeoutHandles:{flush:null,reconnect:0,pongTimeout:0},buffer:{me:{type:"full",data:e},messages:[],storageOperations:[]},intervalHandles:{heartbeat:0},connection:r,me:new Yo(e),others:n,initialStorage:t,idFactory:null,clock:0,opClock:0,nodes:new Map,root:void 0,undoStack:[],redoStack:[],pausedHistory:null,activeBatch:null,offlineOperations:new Map}}function ns(e,t){const{initialPresence:n,initialStorage:r}=e,i=ts(typeof n=="function"?n(t.roomId):n,typeof r=="function"?r(t.roomId):r),o=es(i,t),s={id:t.roomId,getConnectionState:o.getConnectionState,isSelfAware:o.isSelfAware,getSelf:o.getSelf,subscribe:o.subscribe,getPresence:o.getPresence,updatePresence:o.updatePresence,getOthers:o.getOthers,broadcastEvent:o.broadcastEvent,getStorage:o.getStorage,getStorageSnapshot:o.getStorageSnapshot,events:o.events,batch:o.batch,history:{undo:o.undo,redo:o.redo,canUndo:o.canUndo,canRedo:o.canRedo,pause:o.pauseHistory,resume:o.resumeHistory},__INTERNAL_DO_NOT_USE:{simulateCloseWebsocket:o.simulateSocketClose,simulateSendCloseEvent:o.simulateSendCloseEvent}};return{connect:o.connect,disconnect:o.disconnect,onNavigatorOnline:o.onNavigatorOnline,onVisibilityChange:o.onVisibilityChange,room:s}}var rs=class extends Error{constructor(e,t){super(e),this.code=t}};function is(e,t){if(typeof window>"u"&&t===void 0)throw new Error("To use Liveblocks client in a non-dom environment, you need to provide a WebSocket polyfill.");const n=t||WebSocket;return r=>new n(`${e}/?token=${r}&version=0.18.3`)}function os(e,t){if(e.type==="public"){if(typeof window>"u"&&t===void 0)throw new Error("To use Liveblocks client in a non-dom environment with a publicApiKey, you need to provide a fetch polyfill.");return n=>sr(t||fetch,e.url,{room:n,publicApiKey:e.publicApiKey})}if(e.type==="private"){if(typeof window>"u"&&t===void 0)throw new Error("To use Liveblocks client in a non-dom environment with a url as auth endpoint, you need to provide a fetch polyfill.");return n=>sr(t||fetch,e.url,{room:n})}if(e.type==="custom")return n=>L.__async.call(void 0,this,null,function*(){const r=yield e.callback(n);if(!r||!r.token)throw new Error('Authentication error. We expect the authentication callback to return a token, but it does not. Hint: the return value should look like: { token: "..." }');return r});throw new Error("Internal error. Unexpected authentication type")}function sr(e,t,n){return L.__async.call(void 0,this,null,function*(){const r=yield e(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!r.ok)throw new vn(`Expected a status 200 but got ${r.status} when doing a POST request on "${t}"`);let i;try{i=yield r.json()}catch(s){throw new vn(`Expected a JSON response when doing a POST request on "${t}". ${s}`)}if(!L.isPlainObject.call(void 0,i)||typeof i.token!="string")throw new vn(`Expected a JSON response of the form \`{ token: "..." }\` when doing a POST request on "${t}", but got ${JSON.stringify(i)}`);const{token:o}=i;return{token:o}})}var vn=class extends Error{constructor(e){super(e)}};function ss(e){const t=e,n=as(e),r=new Map;function i(a){const l=r.get(a);return l?l.room:null}function o(a,l){var u,c;let d=r.get(a);if(d)return d.room;if(L.deprecateIf.call(void 0,l.initialPresence===null||l.initialPresence===void 0,"Please provide an initial presence value for the current user when entering the room."),d=ns({initialPresence:(u=l.initialPresence)!=null?u:{},initialStorage:l.initialStorage},{roomId:a,throttleDelay:n,polyfills:t.polyfills,WebSocketPolyfill:t.WebSocketPolyfill,fetchPolyfill:t.fetchPolyfill,unstable_batchedUpdates:l==null?void 0:l.unstable_batchedUpdates,liveblocksServer:(t==null?void 0:t.liveblocksServer)||"wss://api.liveblocks.io/v6",authentication:ls(t,a)}),r.set(a,d),!l.DO_NOT_USE_withoutConnecting){if(typeof atob>"u"){if(((c=t.polyfills)==null?void 0:c.atob)===void 0)throw new Error("You need to polyfill atob to use the client in your environment. Please follow the instructions at https://liveblocks.io/docs/errors/liveblocks-client/atob-polyfill");uo.atob=t.polyfills.atob}d.connect()}return d.room}function s(a){const l=r.get(a);l&&(l.disconnect(),r.delete(a))}return typeof window<"u"&&typeof window.addEventListener<"u"&&window.addEventListener("online",()=>{for(const[,a]of r)a.onNavigatorOnline()}),typeof document<"u"&&document.addEventListener("visibilitychange",()=>{for(const[,a]of r)a.onVisibilityChange(document.visibilityState)}),{getRoom:i,enter:o,leave:s}}function as(e){if(e.throttle===void 0)return 100;if(typeof e.throttle!="number"||e.throttle<80||e.throttle>1e3)throw new Error("throttle should be a number between 80 and 1000.");return e.throttle}function ls(e,t){const{publicApiKey:n,authEndpoint:r}=e;if(r!==void 0&&n!==void 0)throw new Error("You cannot use both publicApiKey and authEndpoint. Please use either publicApiKey or authEndpoint, but not both. For more information: https://liveblocks.io/docs/api-reference/liveblocks-client#createClient");if(typeof n=="string"){if(n.startsWith("sk_"))throw new Error("Invalid publicApiKey. You are using the secret key which is not supported. Please use the public key instead. For more information: https://liveblocks.io/docs/api-reference/liveblocks-client#createClientPublicKey");if(!n.startsWith("pk_"))throw new Error("Invalid key. Please use the public key format: pk_<public key>. For more information: https://liveblocks.io/docs/api-reference/liveblocks-client#createClientPublicKey");return{type:"public",publicApiKey:n,url:us(e,t)}}if(typeof r=="string")return{type:"private",url:r};if(typeof r=="function")return{type:"custom",callback:r};throw r!==void 0?new Error("authEndpoint must be a string or a function. For more information: https://liveblocks.io/docs/api-reference/liveblocks-client#createClientAuthEndpoint"):new Error("Invalid Liveblocks client options. For more information: https://liveblocks.io/docs/api-reference/liveblocks-client#createClient")}function us(e,t){return e.publicAuthorizeEndpoint?e.publicAuthorizeEndpoint.replace("{roomId}",t):`https://api.liveblocks.io/v2/rooms/${encodeURIComponent(t)}/public/authorize`}function cs(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!Object.is(e[n],t[n]))return!1;return!0}function fs(e,t){if(typeof e!="object"||e===null||typeof t!="object"||t===null||Object.prototype.toString.call(e)!=="[object Object]"||Object.prototype.toString.call(t)!=="[object Object]")return!1;const n=Object.keys(e);return n.length!==Object.keys(t).length?!1:n.every(r=>Object.prototype.hasOwnProperty.call(t,r)&&Object.is(e[r],t[r]))}function hs(e,t){if(Object.is(e,t))return!0;const n=Array.isArray(e),r=Array.isArray(t);return n||r?!n||!r?!1:cs(e,t):fs(e,t)}Ae.LiveList=L.LiveList;Ae.LiveMap=L.LiveMap;Ae.LiveObject=L.LiveObject;Ae.createClient=ss;Ae.shallow=hs;Ae.LiveList;Ae.LiveMap;const ds=Ae.LiveObject,ps=Ae.createClient;Ae.shallow;const si=Symbol(),ai=Symbol();function ms(e){let t;const n=e[2].default,r=Nn(n,e,e[1],null);return{c(){r&&r.c()},l(i){r&&r.l(i)},m(i,o){r&&r.m(i,o),t=!0},p(i,[o]){r&&r.p&&(!t||o&2)&&Cn(r,n,i,i[1],t?Un(n,i[1],o,null):Mn(i[1]),null)},i(i){t||(X(r,i),t=!0)},o(i){Z(r,i),t=!1},d(i){r&&r.d(i)}}}function _s(e,t,n){let{$$slots:r={},$$scope:i}=t,{client:o}=t;if(!o)throw new Error("LiveblocksProvider requires a client");return Nr(si,o),e.$$set=s=>{"client"in s&&n(0,o=s.client),"$$scope"in s&&n(1,i=s.$$scope)},[o,i,r]}class gs extends Se{constructor(t){super(),Pe(this,t,_s,ms,Te,{client:0})}}function vs(e){let t;const n=e[3].default,r=Nn(n,e,e[2],null);return{c(){r&&r.c()},l(i){r&&r.l(i)},m(i,o){r&&r.m(i,o),t=!0},p(i,[o]){r&&r.p&&(!t||o&4)&&Cn(r,n,i,i[2],t?Un(n,i[2],o,null):Mn(i[2]),null)},i(i){t||(X(r,i),t=!0)},o(i){Z(r,i),t=!1},d(i){r&&r.d(i)}}}function ys(e,t,n){let{$$slots:r={},$$scope:i}=t,{id:o}=t,{defaultPresence:s=()=>({})}=t;if(!o)throw new Error("RoomProvider requires an id");const a=Cr(si);if(a){const l=a.enter(o,s());Nr(ai,l),en(()=>{a.leave(o)})}return e.$$set=l=>{"id"in l&&n(0,o=l.id),"defaultPresence"in l&&n(1,s=l.defaultPresence),"$$scope"in l&&n(2,i=l.$$scope)},[o,s,i,r]}class ws extends Se{constructor(t){super(),Pe(this,t,ys,vs,Te,{id:0,defaultPresence:1})}}function ar(e){let t,n,r;return{c(){t=oe("div"),n=lt(e[2]),this.h()},l(i){t=se(i,"DIV",{class:!0,style:!0});var o=te(t);n=ut(o,e[2]),o.forEach($),this.h()},h(){D(t,"class","absolute right-0 text-4xl col-start-2 row-start-2"),D(t,"style",r=`text-shadow: 0px 5px 5px ${e[1]}`)},m(i,o){ie(i,t,o),J(t,n)},p(i,o){o&4&&Dn(n,i[2]),o&2&&r!==(r=`text-shadow: 0px 5px 5px ${i[1]}`)&&D(t,"style",r)},d(i){i&&$(t)}}}function bs(e){let t,n,r,i,o,s=e[2]&&ar(e);return{c(){t=oe("div"),n=Bt("svg"),r=Bt("path"),i=_e(),s&&s.c(),this.h()},l(a){t=se(a,"DIV",{class:!0,style:!0});var l=te(t);n=Xt(l,"svg",{class:!0,width:!0,viewBox:!0,fill:!0,xmlns:!0});var u=te(n);r=Xt(u,"path",{d:!0,fill:!0}),te(r).forEach($),u.forEach($),i=ge(l),s&&s.l(l),l.forEach($),this.h()},h(){D(r,"d","M0.91603 0.916054L7.09131 14.9234L8.89871 8.89873L14.9234 7.09133L0.91603 0.916054Z"),D(r,"fill","#FFB800"),D(n,"class","block z-0 col-span-2 row-span-2"),D(n,"width","40"),D(n,"viewBox","0 0 15 15"),D(n,"fill","currentColor"),D(n,"xmlns","http://www.w3.org/2000/svg"),D(t,"class","cursor svelte-14ka0w3"),D(t,"style",o=`transform: translateX(${e[3].x}px) translateY(${e[3].y}px) scale(${e[0].k});`)},m(a,l){ie(a,t,l),J(t,n),J(n,r),J(t,i),s&&s.m(t,null)},p(a,[l]){a[2]?s?s.p(a,l):(s=ar(a),s.c(),s.m(t,null)):s&&(s.d(1),s=null),l&9&&o!==(o=`transform: translateX(${a[3].x}px) translateY(${a[3].y}px) scale(${a[0].k});`)&&D(t,"style",o)},i:Ee,o:Ee,d(a){a&&$(t),s&&s.d()}}}function Es(e,t,n){let r,{transform:i}=t,{color:o=""}=t,{emoji:s}=t,{position:a={x:0,y:0}}=t;return e.$$set=l=>{"transform"in l&&n(0,i=l.transform),"color"in l&&n(1,o=l.color),"emoji"in l&&n(2,s=l.emoji),"position"in l&&n(4,a=l.position)},e.$$.update=()=>{e.$$.dirty&17&&n(3,r={x:i.applyX(a.x),y:i.applyY(a.y)})},[i,o,s,r,a]}class ks extends Se{constructor(t){super(),Pe(this,t,Es,bs,Te,{transform:0,color:1,emoji:2,position:4})}}function xs(e){let t,n;return{c(){t=Bt("svg"),n=Bt("path"),this.h()},l(r){t=Xt(r,"svg",{xmlns:!0,fill:!0,width:!0,viewBox:!0,class:!0});var i=te(t);n=Xt(i,"path",{fill:!0,d:!0}),te(n).forEach($),i.forEach($),this.h()},h(){D(n,"fill","currentColor"),D(n,"d","M20 12a8 8 0 0 1-8 8v4a12 12 0 0 0 12-12h-4Zm-2-5.3a8 8 0 0 1 2 5.3h4c0-3-1.1-5.8-3-8l-3 2.7Z"),D(t,"xmlns","http://www.w3.org/2000/svg"),D(t,"fill","none"),D(t,"width","50"),D(t,"viewBox","0 0 24 24"),D(t,"class","animate-spin max-w-[1rem] inline-block")},m(r,i){ie(r,t,i),J(t,n)},p:Ee,i:Ee,o:Ee,d(r){r&&$(t)}}}class Os extends Se{constructor(t){super(),Pe(this,t,null,xs,Te,{})}}function Is(e){let t,n,r,i,o,s,a,l,u,c,d,p,_;return i=new Os({}),{c(){t=oe("div"),n=oe("div"),r=_e(),ke(i.$$.fragment),o=_e(),s=oe("h2"),a=lt("Click to paint"),l=_e(),u=oe("div"),c=lt(e[2]),this.h()},l(b){t=se(b,"DIV",{class:!0,style:!0});var I=te(t);n=se(I,"DIV",{class:!0}),te(n).forEach($),r=ge(I),xe(i.$$.fragment,I),o=ge(I),s=se(I,"H2",{class:!0});var S=te(s);a=ut(S,"Click to paint"),S.forEach($),l=ge(I),u=se(I,"DIV",{class:!0});var x=te(u);c=ut(x,e[2]),x.forEach($),I.forEach($),this.h()},h(){D(n,"class","small-frame z-0 flex relative svelte-nchges"),D(s,"class","text-lg"),D(u,"class","absolute bottom-0 font-bold"),D(t,"class",d="frame z-0 flex relative "+(e[3]?"":"pointer-events-none touch-none")+" "+(e[4]?"cursor-grabbing":"cursor-grab")+" svelte-nchges"),D(t,"style",p=`transform: translateX(${e[5].x}px) translateY(${e[5].y}px) scale(${e[0].k});
			background-image: linear-gradient(${e[1]}, rgba(255,255,255,0));
			color: ${e[1]};
	`)},m(b,I){ie(b,t,I),J(t,n),J(t,r),Oe(i,t,null),J(t,o),J(t,s),J(s,a),J(t,l),J(t,u),J(u,c),_=!0},p(b,[I]){(!_||I&4)&&Dn(c,b[2]),(!_||I&24&&d!==(d="frame z-0 flex relative "+(b[3]?"":"pointer-events-none touch-none")+" "+(b[4]?"cursor-grabbing":"cursor-grab")+" svelte-nchges"))&&D(t,"class",d),(!_||I&35&&p!==(p=`transform: translateX(${b[5].x}px) translateY(${b[5].y}px) scale(${b[0].k});
			background-image: linear-gradient(${b[1]}, rgba(255,255,255,0));
			color: ${b[1]};
	`))&&D(t,"style",p)},i(b){_||(X(i.$$.fragment,b),_=!0)},o(b){Z(i.$$.fragment,b),_=!1},d(b){b&&$(t),Ie(i)}}}function Ss(e,t,n){let r,{transform:i}=t,{color:o=""}=t,{position:s={x:0,y:0}}=t,{prompt:a=""}=t,{interactive:l=!1}=t,{isDragging:u=!1}=t;return e.$$set=c=>{"transform"in c&&n(0,i=c.transform),"color"in c&&n(1,o=c.color),"position"in c&&n(6,s=c.position),"prompt"in c&&n(2,a=c.prompt),"interactive"in c&&n(3,l=c.interactive),"isDragging"in c&&n(4,u=c.isDragging)},e.$$.update=()=>{e.$$.dirty&65&&n(5,r={x:i.applyX(s.x),y:i.applyY(s.y)})},[i,o,a,l,u,r,s]}class li extends Se{constructor(t){super(),Pe(this,t,Ss,Is,Te,{transform:0,color:1,position:6,prompt:2,interactive:3,isDragging:4})}}var Ps={value:()=>{}};function on(){for(var e=0,t=arguments.length,n={},r;e<t;++e){if(!(r=arguments[e]+"")||r in n||/[\s.]/.test(r))throw new Error("illegal type: "+r);n[r]=[]}return new Kt(n)}function Kt(e){this._=e}function Ts(e,t){return e.trim().split(/^|\s+/).map(function(n){var r="",i=n.indexOf(".");if(i>=0&&(r=n.slice(i+1),n=n.slice(0,i)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:r}})}Kt.prototype=on.prototype={constructor:Kt,on:function(e,t){var n=this._,r=Ts(e+"",n),i,o=-1,s=r.length;if(arguments.length<2){for(;++o<s;)if((i=(e=r[o]).type)&&(i=As(n[i],e.name)))return i;return}if(t!=null&&typeof t!="function")throw new Error("invalid callback: "+t);for(;++o<s;)if(i=(e=r[o]).type)n[i]=lr(n[i],e.name,t);else if(t==null)for(i in n)n[i]=lr(n[i],e.name,null);return this},copy:function(){var e={},t=this._;for(var n in t)e[n]=t[n].slice();return new Kt(e)},call:function(e,t){if((i=arguments.length-2)>0)for(var n=new Array(i),r=0,i,o;r<i;++r)n[r]=arguments[r+2];if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(o=this._[e],r=0,i=o.length;r<i;++r)o[r].value.apply(t,n)},apply:function(e,t,n){if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(var r=this._[e],i=0,o=r.length;i<o;++i)r[i].value.apply(t,n)}};function As(e,t){for(var n=0,r=e.length,i;n<r;++n)if((i=e[n]).name===t)return i.value}function lr(e,t,n){for(var r=0,i=e.length;r<i;++r)if(e[r].name===t){e[r]=Ps,e=e.slice(0,r).concat(e.slice(r+1));break}return n!=null&&e.push({name:t,value:n}),e}var xn="http://www.w3.org/1999/xhtml";const ur={svg:"http://www.w3.org/2000/svg",xhtml:xn,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function sn(e){var t=e+="",n=t.indexOf(":");return n>=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),ur.hasOwnProperty(t)?{space:ur[t],local:e}:e}function Ls(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===xn&&t.documentElement.namespaceURI===xn?t.createElement(e):t.createElementNS(n,e)}}function Rs(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function ui(e){var t=sn(e);return(t.local?Rs:Ls)(t)}function Ns(){}function Hn(e){return e==null?Ns:function(){return this.querySelector(e)}}function Cs(e){typeof e!="function"&&(e=Hn(e));for(var t=this._groups,n=t.length,r=new Array(n),i=0;i<n;++i)for(var o=t[i],s=o.length,a=r[i]=new Array(s),l,u,c=0;c<s;++c)(l=o[c])&&(u=e.call(l,l.__data__,c,o))&&("__data__"in l&&(u.__data__=l.__data__),a[c]=u);return new de(r,this._parents)}function Ms(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function Us(){return[]}function ci(e){return e==null?Us:function(){return this.querySelectorAll(e)}}function Ds(e){return function(){return Ms(e.apply(this,arguments))}}function zs(e){typeof e=="function"?e=Ds(e):e=ci(e);for(var t=this._groups,n=t.length,r=[],i=[],o=0;o<n;++o)for(var s=t[o],a=s.length,l,u=0;u<a;++u)(l=s[u])&&(r.push(e.call(l,l.__data__,u,s)),i.push(l));return new de(r,i)}function fi(e){return function(){return this.matches(e)}}function hi(e){return function(t){return t.matches(e)}}var $s=Array.prototype.find;function Ks(e){return function(){return $s.call(this.children,e)}}function Fs(){return this.firstElementChild}function Hs(e){return this.select(e==null?Fs:Ks(typeof e=="function"?e:hi(e)))}var Vs=Array.prototype.filter;function Bs(){return Array.from(this.children)}function Xs(e){return function(){return Vs.call(this.children,e)}}function Ys(e){return this.selectAll(e==null?Bs:Xs(typeof e=="function"?e:hi(e)))}function qs(e){typeof e!="function"&&(e=fi(e));for(var t=this._groups,n=t.length,r=new Array(n),i=0;i<n;++i)for(var o=t[i],s=o.length,a=r[i]=[],l,u=0;u<s;++u)(l=o[u])&&e.call(l,l.__data__,u,o)&&a.push(l);return new de(r,this._parents)}function di(e){return new Array(e.length)}function js(){return new de(this._enter||this._groups.map(di),this._parents)}function jt(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}jt.prototype={constructor:jt,appendChild:function(e){return this._parent.insertBefore(e,this._next)},insertBefore:function(e,t){return this._parent.insertBefore(e,t)},querySelector:function(e){return this._parent.querySelector(e)},querySelectorAll:function(e){return this._parent.querySelectorAll(e)}};function Gs(e){return function(){return e}}function Js(e,t,n,r,i,o){for(var s=0,a,l=t.length,u=o.length;s<u;++s)(a=t[s])?(a.__data__=o[s],r[s]=a):n[s]=new jt(e,o[s]);for(;s<l;++s)(a=t[s])&&(i[s]=a)}function Ws(e,t,n,r,i,o,s){var a,l,u=new Map,c=t.length,d=o.length,p=new Array(c),_;for(a=0;a<c;++a)(l=t[a])&&(p[a]=_=s.call(l,l.__data__,a,t)+"",u.has(_)?i[a]=l:u.set(_,l));for(a=0;a<d;++a)_=s.call(e,o[a],a,o)+"",(l=u.get(_))?(r[a]=l,l.__data__=o[a],u.delete(_)):n[a]=new jt(e,o[a]);for(a=0;a<c;++a)(l=t[a])&&u.get(p[a])===l&&(i[a]=l)}function Zs(e){return e.__data__}function Qs(e,t){if(!arguments.length)return Array.from(this,Zs);var n=t?Ws:Js,r=this._parents,i=this._groups;typeof e!="function"&&(e=Gs(e));for(var o=i.length,s=new Array(o),a=new Array(o),l=new Array(o),u=0;u<o;++u){var c=r[u],d=i[u],p=d.length,_=ea(e.call(c,c&&c.__data__,u,r)),b=_.length,I=a[u]=new Array(b),S=s[u]=new Array(b),x=l[u]=new Array(p);n(c,d,I,S,x,_,t);for(var H=0,N=0,m,T;H<b;++H)if(m=I[H]){for(H>=N&&(N=H+1);!(T=S[N])&&++N<b;);m._next=T||null}}return s=new de(s,r),s._enter=a,s._exit=l,s}function ea(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function ta(){return new de(this._exit||this._groups.map(di),this._parents)}function na(e,t,n){var r=this.enter(),i=this,o=this.exit();return typeof e=="function"?(r=e(r),r&&(r=r.selection())):r=r.append(e+""),t!=null&&(i=t(i),i&&(i=i.selection())),n==null?o.remove():n(o),r&&i?r.merge(i).order():i}function ra(e){for(var t=e.selection?e.selection():e,n=this._groups,r=t._groups,i=n.length,o=r.length,s=Math.min(i,o),a=new Array(i),l=0;l<s;++l)for(var u=n[l],c=r[l],d=u.length,p=a[l]=new Array(d),_,b=0;b<d;++b)(_=u[b]||c[b])&&(p[b]=_);for(;l<i;++l)a[l]=n[l];return new de(a,this._parents)}function ia(){for(var e=this._groups,t=-1,n=e.length;++t<n;)for(var r=e[t],i=r.length-1,o=r[i],s;--i>=0;)(s=r[i])&&(o&&s.compareDocumentPosition(o)^4&&o.parentNode.insertBefore(s,o),o=s);return this}function oa(e){e||(e=sa);function t(d,p){return d&&p?e(d.__data__,p.__data__):!d-!p}for(var n=this._groups,r=n.length,i=new Array(r),o=0;o<r;++o){for(var s=n[o],a=s.length,l=i[o]=new Array(a),u,c=0;c<a;++c)(u=s[c])&&(l[c]=u);l.sort(t)}return new de(i,this._parents).order()}function sa(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function aa(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function la(){return Array.from(this)}function ua(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],i=0,o=r.length;i<o;++i){var s=r[i];if(s)return s}return null}function ca(){let e=0;for(const t of this)++e;return e}function fa(){return!this.node()}function ha(e){for(var t=this._groups,n=0,r=t.length;n<r;++n)for(var i=t[n],o=0,s=i.length,a;o<s;++o)(a=i[o])&&e.call(a,a.__data__,o,i);return this}function da(e){return function(){this.removeAttribute(e)}}function pa(e){return function(){this.removeAttributeNS(e.space,e.local)}}function ma(e,t){return function(){this.setAttribute(e,t)}}function _a(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function ga(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function va(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttributeNS(e.space,e.local):this.setAttributeNS(e.space,e.local,n)}}function ya(e,t){var n=sn(e);if(arguments.length<2){var r=this.node();return n.local?r.getAttributeNS(n.space,n.local):r.getAttribute(n)}return this.each((t==null?n.local?pa:da:typeof t=="function"?n.local?va:ga:n.local?_a:ma)(n,t))}function pi(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function wa(e){return function(){this.style.removeProperty(e)}}function ba(e,t,n){return function(){this.style.setProperty(e,t,n)}}function Ea(e,t,n){return function(){var r=t.apply(this,arguments);r==null?this.style.removeProperty(e):this.style.setProperty(e,r,n)}}function ka(e,t,n){return arguments.length>1?this.each((t==null?wa:typeof t=="function"?Ea:ba)(e,t,n==null?"":n)):dt(this.node(),e)}function dt(e,t){return e.style.getPropertyValue(t)||pi(e).getComputedStyle(e,null).getPropertyValue(t)}function xa(e){return function(){delete this[e]}}function Oa(e,t){return function(){this[e]=t}}function Ia(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function Sa(e,t){return arguments.length>1?this.each((t==null?xa:typeof t=="function"?Ia:Oa)(e,t)):this.node()[e]}function mi(e){return e.trim().split(/^|\s+/)}function Vn(e){return e.classList||new _i(e)}function _i(e){this._node=e,this._names=mi(e.getAttribute("class")||"")}_i.prototype={add:function(e){var t=this._names.indexOf(e);t<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function gi(e,t){for(var n=Vn(e),r=-1,i=t.length;++r<i;)n.add(t[r])}function vi(e,t){for(var n=Vn(e),r=-1,i=t.length;++r<i;)n.remove(t[r])}function Pa(e){return function(){gi(this,e)}}function Ta(e){return function(){vi(this,e)}}function Aa(e,t){return function(){(t.apply(this,arguments)?gi:vi)(this,e)}}function La(e,t){var n=mi(e+"");if(arguments.length<2){for(var r=Vn(this.node()),i=-1,o=n.length;++i<o;)if(!r.contains(n[i]))return!1;return!0}return this.each((typeof t=="function"?Aa:t?Pa:Ta)(n,t))}function Ra(){this.textContent=""}function Na(e){return function(){this.textContent=e}}function Ca(e){return function(){var t=e.apply(this,arguments);this.textContent=t==null?"":t}}function Ma(e){return arguments.length?this.each(e==null?Ra:(typeof e=="function"?Ca:Na)(e)):this.node().textContent}function Ua(){this.innerHTML=""}function Da(e){return function(){this.innerHTML=e}}function za(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t==null?"":t}}function $a(e){return arguments.length?this.each(e==null?Ua:(typeof e=="function"?za:Da)(e)):this.node().innerHTML}function Ka(){this.nextSibling&&this.parentNode.appendChild(this)}function Fa(){return this.each(Ka)}function Ha(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function Va(){return this.each(Ha)}function Ba(e){var t=typeof e=="function"?e:ui(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function Xa(){return null}function Ya(e,t){var n=typeof e=="function"?e:ui(e),r=t==null?Xa:typeof t=="function"?t:Hn(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),r.apply(this,arguments)||null)})}function qa(){var e=this.parentNode;e&&e.removeChild(this)}function ja(){return this.each(qa)}function Ga(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function Ja(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function Wa(e){return this.select(e?Ja:Ga)}function Za(e){return arguments.length?this.property("__data__",e):this.node().__data__}function Qa(e){return function(t){e.call(this,t,this.__data__)}}function el(e){return e.trim().split(/^|\s+/).map(function(t){var n="",r=t.indexOf(".");return r>=0&&(n=t.slice(r+1),t=t.slice(0,r)),{type:t,name:n}})}function tl(e){return function(){var t=this.__on;if(!!t){for(var n=0,r=-1,i=t.length,o;n<i;++n)o=t[n],(!e.type||o.type===e.type)&&o.name===e.name?this.removeEventListener(o.type,o.listener,o.options):t[++r]=o;++r?t.length=r:delete this.__on}}}function nl(e,t,n){return function(){var r=this.__on,i,o=Qa(t);if(r){for(var s=0,a=r.length;s<a;++s)if((i=r[s]).type===e.type&&i.name===e.name){this.removeEventListener(i.type,i.listener,i.options),this.addEventListener(i.type,i.listener=o,i.options=n),i.value=t;return}}this.addEventListener(e.type,o,n),i={type:e.type,name:e.name,value:t,listener:o,options:n},r?r.push(i):this.__on=[i]}}function rl(e,t,n){var r=el(e+""),i,o=r.length,s;if(arguments.length<2){var a=this.node().__on;if(a){for(var l=0,u=a.length,c;l<u;++l)for(i=0,c=a[l];i<o;++i)if((s=r[i]).type===c.type&&s.name===c.name)return c.value}return}for(a=t?nl:tl,i=0;i<o;++i)this.each(a(r[i],t,n));return this}function yi(e,t,n){var r=pi(e),i=r.CustomEvent;typeof i=="function"?i=new i(t,n):(i=r.document.createEvent("Event"),n?(i.initEvent(t,n.bubbles,n.cancelable),i.detail=n.detail):i.initEvent(t,!1,!1)),e.dispatchEvent(i)}function il(e,t){return function(){return yi(this,e,t)}}function ol(e,t){return function(){return yi(this,e,t.apply(this,arguments))}}function sl(e,t){return this.each((typeof t=="function"?ol:il)(e,t))}function*al(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],i=0,o=r.length,s;i<o;++i)(s=r[i])&&(yield s)}var wi=[null];function de(e,t){this._groups=e,this._parents=t}function At(){return new de([[document.documentElement]],wi)}function ll(){return this}de.prototype=At.prototype={constructor:de,select:Cs,selectAll:zs,selectChild:Hs,selectChildren:Ys,filter:qs,data:Qs,enter:js,exit:ta,join:na,merge:ra,selection:ll,order:ia,sort:oa,call:aa,nodes:la,node:ua,size:ca,empty:fa,each:ha,attr:ya,style:ka,property:Sa,classed:La,text:Ma,html:$a,raise:Fa,lower:Va,append:Ba,insert:Ya,remove:ja,clone:Wa,datum:Za,on:rl,dispatch:sl,[Symbol.iterator]:al};function we(e){return typeof e=="string"?new de([[document.querySelector(e)]],[document.documentElement]):new de([[e]],wi)}function ul(e){let t;for(;t=e.sourceEvent;)e=t;return e}function ze(e,t){if(e=ul(e),t===void 0&&(t=e.currentTarget),t){var n=t.ownerSVGElement||t;if(n.createSVGPoint){var r=n.createSVGPoint();return r.x=e.clientX,r.y=e.clientY,r=r.matrixTransform(t.getScreenCTM().inverse()),[r.x,r.y]}if(t.getBoundingClientRect){var i=t.getBoundingClientRect();return[e.clientX-i.left-t.clientLeft,e.clientY-i.top-t.clientTop]}}return[e.pageX,e.pageY]}const cl={passive:!1},kt={capture:!0,passive:!1};function yn(e){e.stopImmediatePropagation()}function st(e){e.preventDefault(),e.stopImmediatePropagation()}function bi(e){var t=e.document.documentElement,n=we(e).on("dragstart.drag",st,kt);"onselectstart"in t?n.on("selectstart.drag",st,kt):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect="none")}function Ei(e,t){var n=e.document.documentElement,r=we(e).on("dragstart.drag",null);t&&(r.on("click.drag",st,kt),setTimeout(function(){r.on("click.drag",null)},0)),"onselectstart"in n?r.on("selectstart.drag",null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}const Nt=e=>()=>e;function On(e,{sourceEvent:t,subject:n,target:r,identifier:i,active:o,x:s,y:a,dx:l,dy:u,dispatch:c}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:i,enumerable:!0,configurable:!0},active:{value:o,enumerable:!0,configurable:!0},x:{value:s,enumerable:!0,configurable:!0},y:{value:a,enumerable:!0,configurable:!0},dx:{value:l,enumerable:!0,configurable:!0},dy:{value:u,enumerable:!0,configurable:!0},_:{value:c}})}On.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function fl(e){return!e.ctrlKey&&!e.button}function hl(){return this.parentNode}function dl(e,t){return t==null?{x:e.x,y:e.y}:t}function pl(){return navigator.maxTouchPoints||"ontouchstart"in this}function ml(){var e=fl,t=hl,n=dl,r=pl,i={},o=on("start","drag","end"),s=0,a,l,u,c,d=0;function p(m){m.on("mousedown.drag",_).filter(r).on("touchstart.drag",S).on("touchmove.drag",x,cl).on("touchend.drag touchcancel.drag",H).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function _(m,T){if(!(c||!e.call(this,m,T))){var k=N(this,t.call(this,m,T),m,T,"mouse");!k||(we(m.view).on("mousemove.drag",b,kt).on("mouseup.drag",I,kt),bi(m.view),yn(m),u=!1,a=m.clientX,l=m.clientY,k("start",m))}}function b(m){if(st(m),!u){var T=m.clientX-a,k=m.clientY-l;u=T*T+k*k>d}i.mouse("drag",m)}function I(m){we(m.view).on("mousemove.drag mouseup.drag",null),Ei(m.view,u),st(m),i.mouse("end",m)}function S(m,T){if(!!e.call(this,m,T)){var k=m.changedTouches,w=t.call(this,m,T),R=k.length,K,V;for(K=0;K<R;++K)(V=N(this,w,m,T,k[K].identifier,k[K]))&&(yn(m),V("start",m,k[K]))}}function x(m){var T=m.changedTouches,k=T.length,w,R;for(w=0;w<k;++w)(R=i[T[w].identifier])&&(st(m),R("drag",m,T[w]))}function H(m){var T=m.changedTouches,k=T.length,w,R;for(c&&clearTimeout(c),c=setTimeout(function(){c=null},500),w=0;w<k;++w)(R=i[T[w].identifier])&&(yn(m),R("end",m,T[w]))}function N(m,T,k,w,R,K){var V=o.copy(),Q=ze(K||k,T),q,fe,h;if((h=n.call(m,new On("beforestart",{sourceEvent:k,target:p,identifier:R,active:s,x:Q[0],y:Q[1],dx:0,dy:0,dispatch:V}),w))!=null)return q=h.x-Q[0]||0,fe=h.y-Q[1]||0,function O(v,P,M){var U=Q,z;switch(v){case"start":i[R]=O,z=s++;break;case"end":delete i[R],--s;case"drag":Q=ze(M||P,T),z=s;break}V.call(v,m,new On(v,{sourceEvent:P,subject:h,target:p,identifier:R,active:z,x:Q[0]+q,y:Q[1]+fe,dx:Q[0]-U[0],dy:Q[1]-U[1],dispatch:V}),w)}}return p.filter=function(m){return arguments.length?(e=typeof m=="function"?m:Nt(!!m),p):e},p.container=function(m){return arguments.length?(t=typeof m=="function"?m:Nt(m),p):t},p.subject=function(m){return arguments.length?(n=typeof m=="function"?m:Nt(m),p):n},p.touchable=function(m){return arguments.length?(r=typeof m=="function"?m:Nt(!!m),p):r},p.on=function(){var m=o.on.apply(o,arguments);return m===o?p:m},p.clickDistance=function(m){return arguments.length?(d=(m=+m)*m,p):Math.sqrt(d)},p}function _l(e){return new Promise(t=>{const n=new Image;n.onload=async()=>{const r=n.width,i=n.height,o=document.createElement("canvas");o.width=r,o.height=i,o.getContext("2d").drawImage(n,0,0,r,i);const a=await new Promise(l=>o.toBlob(l,"image/jpeg",.95));t(a)},n.src=e})}async function gl(e,t){const n=vl(t),r="https://huggingface.co/uploads",o=`color-palette-${crypto.randomUUID().split("-")[0]}-${n}.jpeg`,s=new File([e],o,{type:"image/jpeg"});console.log("uploading image",s);const l=await(await fetch(r,{method:"POST",headers:{"Content-Type":s.type,"X-Requested-With":"XMLHttpRequest"},body:s})).text();return console.log("uploaded images",l),l}function it(e,t=32){return e%t<t/2?e-e%t:e+t-e%t}function vl(e){return e?e.toString().toLowerCase().replace(/\s+/g,"-").replace(/[^\w\-]+/g,"").replace(/\-\-+/g,"-").replace(/^-+/,"").replace(/-+$/,""):""}function Bn(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function ki(e,t){var n=Object.create(e.prototype);for(var r in t)n[r]=t[r];return n}function Lt(){}var xt=.7,Gt=1/xt,at="\\s*([+-]?\\d+)\\s*",Ot="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",Ce="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",yl=/^#([0-9a-f]{3,8})$/,wl=new RegExp(`^rgb\\(${at},${at},${at}\\)$`),bl=new RegExp(`^rgb\\(${Ce},${Ce},${Ce}\\)$`),El=new RegExp(`^rgba\\(${at},${at},${at},${Ot}\\)$`),kl=new RegExp(`^rgba\\(${Ce},${Ce},${Ce},${Ot}\\)$`),xl=new RegExp(`^hsl\\(${Ot},${Ce},${Ce}\\)$`),Ol=new RegExp(`^hsla\\(${Ot},${Ce},${Ce},${Ot}\\)$`),cr={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};Bn(Lt,It,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:fr,formatHex:fr,formatHex8:Il,formatHsl:Sl,formatRgb:hr,toString:hr});function fr(){return this.rgb().formatHex()}function Il(){return this.rgb().formatHex8()}function Sl(){return xi(this).formatHsl()}function hr(){return this.rgb().formatRgb()}function It(e){var t,n;return e=(e+"").trim().toLowerCase(),(t=yl.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?dr(t):n===3?new ce(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?Ct(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?Ct(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=wl.exec(e))?new ce(t[1],t[2],t[3],1):(t=bl.exec(e))?new ce(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=El.exec(e))?Ct(t[1],t[2],t[3],t[4]):(t=kl.exec(e))?Ct(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=xl.exec(e))?_r(t[1],t[2]/100,t[3]/100,1):(t=Ol.exec(e))?_r(t[1],t[2]/100,t[3]/100,t[4]):cr.hasOwnProperty(e)?dr(cr[e]):e==="transparent"?new ce(NaN,NaN,NaN,0):null}function dr(e){return new ce(e>>16&255,e>>8&255,e&255,1)}function Ct(e,t,n,r){return r<=0&&(e=t=n=NaN),new ce(e,t,n,r)}function Pl(e){return e instanceof Lt||(e=It(e)),e?(e=e.rgb(),new ce(e.r,e.g,e.b,e.opacity)):new ce}function In(e,t,n,r){return arguments.length===1?Pl(e):new ce(e,t,n,r==null?1:r)}function ce(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}Bn(ce,In,ki(Lt,{brighter(e){return e=e==null?Gt:Math.pow(Gt,e),new ce(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?xt:Math.pow(xt,e),new ce(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new ce(Qe(this.r),Qe(this.g),Qe(this.b),Jt(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:pr,formatHex:pr,formatHex8:Tl,formatRgb:mr,toString:mr}));function pr(){return`#${We(this.r)}${We(this.g)}${We(this.b)}`}function Tl(){return`#${We(this.r)}${We(this.g)}${We(this.b)}${We((isNaN(this.opacity)?1:this.opacity)*255)}`}function mr(){const e=Jt(this.opacity);return`${e===1?"rgb(":"rgba("}${Qe(this.r)}, ${Qe(this.g)}, ${Qe(this.b)}${e===1?")":`, ${e})`}`}function Jt(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function Qe(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function We(e){return e=Qe(e),(e<16?"0":"")+e.toString(16)}function _r(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new be(e,t,n,r)}function xi(e){if(e instanceof be)return new be(e.h,e.s,e.l,e.opacity);if(e instanceof Lt||(e=It(e)),!e)return new be;if(e instanceof be)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,i=Math.min(t,n,r),o=Math.max(t,n,r),s=NaN,a=o-i,l=(o+i)/2;return a?(t===o?s=(n-r)/a+(n<r)*6:n===o?s=(r-t)/a+2:s=(t-n)/a+4,a/=l<.5?o+i:2-o-i,s*=60):a=l>0&&l<1?0:s,new be(s,a,l,e.opacity)}function Al(e,t,n,r){return arguments.length===1?xi(e):new be(e,t,n,r==null?1:r)}function be(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}Bn(be,Al,ki(Lt,{brighter(e){return e=e==null?Gt:Math.pow(Gt,e),new be(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?xt:Math.pow(xt,e),new be(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*t,i=2*n-r;return new ce(wn(e>=240?e-240:e+120,i,r),wn(e,i,r),wn(e<120?e+240:e-120,i,r),this.opacity)},clamp(){return new be(gr(this.h),Mt(this.s),Mt(this.l),Jt(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const e=Jt(this.opacity);return`${e===1?"hsl(":"hsla("}${gr(this.h)}, ${Mt(this.s)*100}%, ${Mt(this.l)*100}%${e===1?")":`, ${e})`}`}}));function gr(e){return e=(e||0)%360,e<0?e+360:e}function Mt(e){return Math.max(0,Math.min(1,e||0))}function wn(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}const Oi=e=>()=>e;function Ll(e,t){return function(n){return e+n*t}}function Rl(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(r){return Math.pow(e+r*t,n)}}function Nl(e){return(e=+e)==1?Ii:function(t,n){return n-t?Rl(t,n,e):Oi(isNaN(t)?n:t)}}function Ii(e,t){var n=t-e;return n?Ll(e,n):Oi(isNaN(e)?t:e)}const vr=function e(t){var n=Nl(t);function r(i,o){var s=n((i=In(i)).r,(o=In(o)).r),a=n(i.g,o.g),l=n(i.b,o.b),u=Ii(i.opacity,o.opacity);return function(c){return i.r=s(c),i.g=a(c),i.b=l(c),i.opacity=u(c),i+""}}return r.gamma=e,r}(1);function He(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}var Sn=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,bn=new RegExp(Sn.source,"g");function Cl(e){return function(){return e}}function Ml(e){return function(t){return e(t)+""}}function Ul(e,t){var n=Sn.lastIndex=bn.lastIndex=0,r,i,o,s=-1,a=[],l=[];for(e=e+"",t=t+"";(r=Sn.exec(e))&&(i=bn.exec(t));)(o=i.index)>n&&(o=t.slice(n,o),a[s]?a[s]+=o:a[++s]=o),(r=r[0])===(i=i[0])?a[s]?a[s]+=i:a[++s]=i:(a[++s]=null,l.push({i:s,x:He(r,i)})),n=bn.lastIndex;return n<t.length&&(o=t.slice(n),a[s]?a[s]+=o:a[++s]=o),a.length<2?l[0]?Ml(l[0].x):Cl(t):(t=l.length,function(u){for(var c=0,d;c<t;++c)a[(d=l[c]).i]=d.x(u);return a.join("")})}var yr=180/Math.PI,Pn={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function Si(e,t,n,r,i,o){var s,a,l;return(s=Math.sqrt(e*e+t*t))&&(e/=s,t/=s),(l=e*n+t*r)&&(n-=e*l,r-=t*l),(a=Math.sqrt(n*n+r*r))&&(n/=a,r/=a,l/=a),e*r<t*n&&(e=-e,t=-t,l=-l,s=-s),{translateX:i,translateY:o,rotate:Math.atan2(t,e)*yr,skewX:Math.atan(l)*yr,scaleX:s,scaleY:a}}var Ut;function Dl(e){const t=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return t.isIdentity?Pn:Si(t.a,t.b,t.c,t.d,t.e,t.f)}function zl(e){return e==null||(Ut||(Ut=document.createElementNS("http://www.w3.org/2000/svg","g")),Ut.setAttribute("transform",e),!(e=Ut.transform.baseVal.consolidate()))?Pn:(e=e.matrix,Si(e.a,e.b,e.c,e.d,e.e,e.f))}function Pi(e,t,n,r){function i(u){return u.length?u.pop()+" ":""}function o(u,c,d,p,_,b){if(u!==d||c!==p){var I=_.push("translate(",null,t,null,n);b.push({i:I-4,x:He(u,d)},{i:I-2,x:He(c,p)})}else(d||p)&&_.push("translate("+d+t+p+n)}function s(u,c,d,p){u!==c?(u-c>180?c+=360:c-u>180&&(u+=360),p.push({i:d.push(i(d)+"rotate(",null,r)-2,x:He(u,c)})):c&&d.push(i(d)+"rotate("+c+r)}function a(u,c,d,p){u!==c?p.push({i:d.push(i(d)+"skewX(",null,r)-2,x:He(u,c)}):c&&d.push(i(d)+"skewX("+c+r)}function l(u,c,d,p,_,b){if(u!==d||c!==p){var I=_.push(i(_)+"scale(",null,",",null,")");b.push({i:I-4,x:He(u,d)},{i:I-2,x:He(c,p)})}else(d!==1||p!==1)&&_.push(i(_)+"scale("+d+","+p+")")}return function(u,c){var d=[],p=[];return u=e(u),c=e(c),o(u.translateX,u.translateY,c.translateX,c.translateY,d,p),s(u.rotate,c.rotate,d,p),a(u.skewX,c.skewX,d,p),l(u.scaleX,u.scaleY,c.scaleX,c.scaleY,d,p),u=c=null,function(_){for(var b=-1,I=p.length,S;++b<I;)d[(S=p[b]).i]=S.x(_);return d.join("")}}}var $l=Pi(Dl,"px, ","px)","deg)"),Kl=Pi(zl,", ",")",")"),Fl=1e-12;function wr(e){return((e=Math.exp(e))+1/e)/2}function Hl(e){return((e=Math.exp(e))-1/e)/2}function Vl(e){return((e=Math.exp(2*e))-1)/(e+1)}const Bl=function e(t,n,r){function i(o,s){var a=o[0],l=o[1],u=o[2],c=s[0],d=s[1],p=s[2],_=c-a,b=d-l,I=_*_+b*b,S,x;if(I<Fl)x=Math.log(p/u)/t,S=function(w){return[a+w*_,l+w*b,u*Math.exp(t*w*x)]};else{var H=Math.sqrt(I),N=(p*p-u*u+r*I)/(2*u*n*H),m=(p*p-u*u-r*I)/(2*p*n*H),T=Math.log(Math.sqrt(N*N+1)-N),k=Math.log(Math.sqrt(m*m+1)-m);x=(k-T)/t,S=function(w){var R=w*x,K=wr(T),V=u/(n*H)*(K*Vl(t*R+T)-Hl(T));return[a+V*_,l+V*b,u*K/wr(t*R+T)]}}return S.duration=x*1e3*t/Math.SQRT2,S}return i.rho=function(o){var s=Math.max(.001,+o),a=s*s,l=a*a;return e(s,a,l)},i}(Math.SQRT2,2,4);var pt=0,wt=0,_t=0,Ti=1e3,Wt,bt,Zt=0,tt=0,an=0,St=typeof performance=="object"&&performance.now?performance:Date,Ai=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function Xn(){return tt||(Ai(Xl),tt=St.now()+an)}function Xl(){tt=0}function Qt(){this._call=this._time=this._next=null}Qt.prototype=Li.prototype={constructor:Qt,restart:function(e,t,n){if(typeof e!="function")throw new TypeError("callback is not a function");n=(n==null?Xn():+n)+(t==null?0:+t),!this._next&&bt!==this&&(bt?bt._next=this:Wt=this,bt=this),this._call=e,this._time=n,Tn()},stop:function(){this._call&&(this._call=null,this._time=1/0,Tn())}};function Li(e,t,n){var r=new Qt;return r.restart(e,t,n),r}function Yl(){Xn(),++pt;for(var e=Wt,t;e;)(t=tt-e._time)>=0&&e._call.call(void 0,t),e=e._next;--pt}function br(){tt=(Zt=St.now())+an,pt=wt=0;try{Yl()}finally{pt=0,jl(),tt=0}}function ql(){var e=St.now(),t=e-Zt;t>Ti&&(an-=t,Zt=e)}function jl(){for(var e,t=Wt,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:Wt=n);bt=e,Tn(r)}function Tn(e){if(!pt){wt&&(wt=clearTimeout(wt));var t=e-tt;t>24?(e<1/0&&(wt=setTimeout(br,e-St.now()-an)),_t&&(_t=clearInterval(_t))):(_t||(Zt=St.now(),_t=setInterval(ql,Ti)),pt=1,Ai(br))}}function Er(e,t,n){var r=new Qt;return t=t==null?0:+t,r.restart(i=>{r.stop(),e(i+t)},t,n),r}var Gl=on("start","end","cancel","interrupt"),Jl=[],Ri=0,kr=1,An=2,Ft=3,xr=4,Ln=5,Ht=6;function ln(e,t,n,r,i,o){var s=e.__transition;if(!s)e.__transition={};else if(n in s)return;Wl(e,n,{name:t,index:r,group:i,on:Gl,tween:Jl,time:o.time,delay:o.delay,duration:o.duration,ease:o.ease,timer:null,state:Ri})}function Yn(e,t){var n=Le(e,t);if(n.state>Ri)throw new Error("too late; already scheduled");return n}function Me(e,t){var n=Le(e,t);if(n.state>Ft)throw new Error("too late; already running");return n}function Le(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function Wl(e,t,n){var r=e.__transition,i;r[t]=n,n.timer=Li(o,0,n.time);function o(u){n.state=kr,n.timer.restart(s,n.delay,n.time),n.delay<=u&&s(u-n.delay)}function s(u){var c,d,p,_;if(n.state!==kr)return l();for(c in r)if(_=r[c],_.name===n.name){if(_.state===Ft)return Er(s);_.state===xr?(_.state=Ht,_.timer.stop(),_.on.call("interrupt",e,e.__data__,_.index,_.group),delete r[c]):+c<t&&(_.state=Ht,_.timer.stop(),_.on.call("cancel",e,e.__data__,_.index,_.group),delete r[c])}if(Er(function(){n.state===Ft&&(n.state=xr,n.timer.restart(a,n.delay,n.time),a(u))}),n.state=An,n.on.call("start",e,e.__data__,n.index,n.group),n.state===An){for(n.state=Ft,i=new Array(p=n.tween.length),c=0,d=-1;c<p;++c)(_=n.tween[c].value.call(e,e.__data__,n.index,n.group))&&(i[++d]=_);i.length=d+1}}function a(u){for(var c=u<n.duration?n.ease.call(null,u/n.duration):(n.timer.restart(l),n.state=Ln,1),d=-1,p=i.length;++d<p;)i[d].call(e,c);n.state===Ln&&(n.on.call("end",e,e.__data__,n.index,n.group),l())}function l(){n.state=Ht,n.timer.stop(),delete r[t];for(var u in r)return;delete e.__transition}}function Vt(e,t){var n=e.__transition,r,i,o=!0,s;if(!!n){t=t==null?null:t+"";for(s in n){if((r=n[s]).name!==t){o=!1;continue}i=r.state>An&&r.state<Ln,r.state=Ht,r.timer.stop(),r.on.call(i?"interrupt":"cancel",e,e.__data__,r.index,r.group),delete n[s]}o&&delete e.__transition}}function Zl(e){return this.each(function(){Vt(this,e)})}function Ql(e,t){var n,r;return function(){var i=Me(this,e),o=i.tween;if(o!==n){r=n=o;for(var s=0,a=r.length;s<a;++s)if(r[s].name===t){r=r.slice(),r.splice(s,1);break}}i.tween=r}}function eu(e,t,n){var r,i;if(typeof n!="function")throw new Error;return function(){var o=Me(this,e),s=o.tween;if(s!==r){i=(r=s).slice();for(var a={name:t,value:n},l=0,u=i.length;l<u;++l)if(i[l].name===t){i[l]=a;break}l===u&&i.push(a)}o.tween=i}}function tu(e,t){var n=this._id;if(e+="",arguments.length<2){for(var r=Le(this.node(),n).tween,i=0,o=r.length,s;i<o;++i)if((s=r[i]).name===e)return s.value;return null}return this.each((t==null?Ql:eu)(n,e,t))}function qn(e,t,n){var r=e._id;return e.each(function(){var i=Me(this,r);(i.value||(i.value={}))[t]=n.apply(this,arguments)}),function(i){return Le(i,r).value[t]}}function Ni(e,t){var n;return(typeof t=="number"?He:t instanceof It?vr:(n=It(t))?(t=n,vr):Ul)(e,t)}function nu(e){return function(){this.removeAttribute(e)}}function ru(e){return function(){this.removeAttributeNS(e.space,e.local)}}function iu(e,t,n){var r,i=n+"",o;return function(){var s=this.getAttribute(e);return s===i?null:s===r?o:o=t(r=s,n)}}function ou(e,t,n){var r,i=n+"",o;return function(){var s=this.getAttributeNS(e.space,e.local);return s===i?null:s===r?o:o=t(r=s,n)}}function su(e,t,n){var r,i,o;return function(){var s,a=n(this),l;return a==null?void this.removeAttribute(e):(s=this.getAttribute(e),l=a+"",s===l?null:s===r&&l===i?o:(i=l,o=t(r=s,a)))}}function au(e,t,n){var r,i,o;return function(){var s,a=n(this),l;return a==null?void this.removeAttributeNS(e.space,e.local):(s=this.getAttributeNS(e.space,e.local),l=a+"",s===l?null:s===r&&l===i?o:(i=l,o=t(r=s,a)))}}function lu(e,t){var n=sn(e),r=n==="transform"?Kl:Ni;return this.attrTween(e,typeof t=="function"?(n.local?au:su)(n,r,qn(this,"attr."+e,t)):t==null?(n.local?ru:nu)(n):(n.local?ou:iu)(n,r,t))}function uu(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function cu(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function fu(e,t){var n,r;function i(){var o=t.apply(this,arguments);return o!==r&&(n=(r=o)&&cu(e,o)),n}return i._value=t,i}function hu(e,t){var n,r;function i(){var o=t.apply(this,arguments);return o!==r&&(n=(r=o)&&uu(e,o)),n}return i._value=t,i}function du(e,t){var n="attr."+e;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(t==null)return this.tween(n,null);if(typeof t!="function")throw new Error;var r=sn(e);return this.tween(n,(r.local?fu:hu)(r,t))}function pu(e,t){return function(){Yn(this,e).delay=+t.apply(this,arguments)}}function mu(e,t){return t=+t,function(){Yn(this,e).delay=t}}function _u(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?pu:mu)(t,e)):Le(this.node(),t).delay}function gu(e,t){return function(){Me(this,e).duration=+t.apply(this,arguments)}}function vu(e,t){return t=+t,function(){Me(this,e).duration=t}}function yu(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?gu:vu)(t,e)):Le(this.node(),t).duration}function wu(e,t){if(typeof t!="function")throw new Error;return function(){Me(this,e).ease=t}}function bu(e){var t=this._id;return arguments.length?this.each(wu(t,e)):Le(this.node(),t).ease}function Eu(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!="function")throw new Error;Me(this,e).ease=n}}function ku(e){if(typeof e!="function")throw new Error;return this.each(Eu(this._id,e))}function xu(e){typeof e!="function"&&(e=fi(e));for(var t=this._groups,n=t.length,r=new Array(n),i=0;i<n;++i)for(var o=t[i],s=o.length,a=r[i]=[],l,u=0;u<s;++u)(l=o[u])&&e.call(l,l.__data__,u,o)&&a.push(l);return new Ke(r,this._parents,this._name,this._id)}function Ou(e){if(e._id!==this._id)throw new Error;for(var t=this._groups,n=e._groups,r=t.length,i=n.length,o=Math.min(r,i),s=new Array(r),a=0;a<o;++a)for(var l=t[a],u=n[a],c=l.length,d=s[a]=new Array(c),p,_=0;_<c;++_)(p=l[_]||u[_])&&(d[_]=p);for(;a<r;++a)s[a]=t[a];return new Ke(s,this._parents,this._name,this._id)}function Iu(e){return(e+"").trim().split(/^|\s+/).every(function(t){var n=t.indexOf(".");return n>=0&&(t=t.slice(0,n)),!t||t==="start"})}function Su(e,t,n){var r,i,o=Iu(t)?Yn:Me;return function(){var s=o(this,e),a=s.on;a!==r&&(i=(r=a).copy()).on(t,n),s.on=i}}function Pu(e,t){var n=this._id;return arguments.length<2?Le(this.node(),n).on.on(e):this.each(Su(n,e,t))}function Tu(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function Au(){return this.on("end.remove",Tu(this._id))}function Lu(e){var t=this._name,n=this._id;typeof e!="function"&&(e=Hn(e));for(var r=this._groups,i=r.length,o=new Array(i),s=0;s<i;++s)for(var a=r[s],l=a.length,u=o[s]=new Array(l),c,d,p=0;p<l;++p)(c=a[p])&&(d=e.call(c,c.__data__,p,a))&&("__data__"in c&&(d.__data__=c.__data__),u[p]=d,ln(u[p],t,n,p,u,Le(c,n)));return new Ke(o,this._parents,t,n)}function Ru(e){var t=this._name,n=this._id;typeof e!="function"&&(e=ci(e));for(var r=this._groups,i=r.length,o=[],s=[],a=0;a<i;++a)for(var l=r[a],u=l.length,c,d=0;d<u;++d)if(c=l[d]){for(var p=e.call(c,c.__data__,d,l),_,b=Le(c,n),I=0,S=p.length;I<S;++I)(_=p[I])&&ln(_,t,n,I,p,b);o.push(p),s.push(c)}return new Ke(o,s,t,n)}var Nu=At.prototype.constructor;function Cu(){return new Nu(this._groups,this._parents)}function Mu(e,t){var n,r,i;return function(){var o=dt(this,e),s=(this.style.removeProperty(e),dt(this,e));return o===s?null:o===n&&s===r?i:i=t(n=o,r=s)}}function Ci(e){return function(){this.style.removeProperty(e)}}function Uu(e,t,n){var r,i=n+"",o;return function(){var s=dt(this,e);return s===i?null:s===r?o:o=t(r=s,n)}}function Du(e,t,n){var r,i,o;return function(){var s=dt(this,e),a=n(this),l=a+"";return a==null&&(l=a=(this.style.removeProperty(e),dt(this,e))),s===l?null:s===r&&l===i?o:(i=l,o=t(r=s,a))}}function zu(e,t){var n,r,i,o="style."+t,s="end."+o,a;return function(){var l=Me(this,e),u=l.on,c=l.value[o]==null?a||(a=Ci(t)):void 0;(u!==n||i!==c)&&(r=(n=u).copy()).on(s,i=c),l.on=r}}function $u(e,t,n){var r=(e+="")=="transform"?$l:Ni;return t==null?this.styleTween(e,Mu(e,r)).on("end.style."+e,Ci(e)):typeof t=="function"?this.styleTween(e,Du(e,r,qn(this,"style."+e,t))).each(zu(this._id,e)):this.styleTween(e,Uu(e,r,t),n).on("end.style."+e,null)}function Ku(e,t,n){return function(r){this.style.setProperty(e,t.call(this,r),n)}}function Fu(e,t,n){var r,i;function o(){var s=t.apply(this,arguments);return s!==i&&(r=(i=s)&&Ku(e,s,n)),r}return o._value=t,o}function Hu(e,t,n){var r="style."+(e+="");if(arguments.length<2)return(r=this.tween(r))&&r._value;if(t==null)return this.tween(r,null);if(typeof t!="function")throw new Error;return this.tween(r,Fu(e,t,n==null?"":n))}function Vu(e){return function(){this.textContent=e}}function Bu(e){return function(){var t=e(this);this.textContent=t==null?"":t}}function Xu(e){return this.tween("text",typeof e=="function"?Bu(qn(this,"text",e)):Vu(e==null?"":e+""))}function Yu(e){return function(t){this.textContent=e.call(this,t)}}function qu(e){var t,n;function r(){var i=e.apply(this,arguments);return i!==n&&(t=(n=i)&&Yu(i)),t}return r._value=e,r}function ju(e){var t="text";if(arguments.length<1)return(t=this.tween(t))&&t._value;if(e==null)return this.tween(t,null);if(typeof e!="function")throw new Error;return this.tween(t,qu(e))}function Gu(){for(var e=this._name,t=this._id,n=Mi(),r=this._groups,i=r.length,o=0;o<i;++o)for(var s=r[o],a=s.length,l,u=0;u<a;++u)if(l=s[u]){var c=Le(l,t);ln(l,e,n,u,s,{time:c.time+c.delay+c.duration,delay:0,duration:c.duration,ease:c.ease})}return new Ke(r,this._parents,e,n)}function Ju(){var e,t,n=this,r=n._id,i=n.size();return new Promise(function(o,s){var a={value:s},l={value:function(){--i===0&&o()}};n.each(function(){var u=Me(this,r),c=u.on;c!==e&&(t=(e=c).copy(),t._.cancel.push(a),t._.interrupt.push(a),t._.end.push(l)),u.on=t}),i===0&&o()})}var Wu=0;function Ke(e,t,n,r){this._groups=e,this._parents=t,this._name=n,this._id=r}function Mi(){return++Wu}var Ue=At.prototype;Ke.prototype={constructor:Ke,select:Lu,selectAll:Ru,selectChild:Ue.selectChild,selectChildren:Ue.selectChildren,filter:xu,merge:Ou,selection:Cu,transition:Gu,call:Ue.call,nodes:Ue.nodes,node:Ue.node,size:Ue.size,empty:Ue.empty,each:Ue.each,on:Pu,attr:lu,attrTween:du,style:$u,styleTween:Hu,text:Xu,textTween:ju,remove:Au,tween:tu,delay:_u,duration:yu,ease:bu,easeVarying:ku,end:Ju,[Symbol.iterator]:Ue[Symbol.iterator]};function Zu(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var Qu={time:null,delay:0,duration:250,ease:Zu};function ec(e,t){for(var n;!(n=e.__transition)||!(n=n[t]);)if(!(e=e.parentNode))throw new Error(`transition ${t} not found`);return n}function tc(e){var t,n;e instanceof Ke?(t=e._id,e=e._name):(t=Mi(),(n=Qu).time=Xn(),e=e==null?null:e+"");for(var r=this._groups,i=r.length,o=0;o<i;++o)for(var s=r[o],a=s.length,l,u=0;u<a;++u)(l=s[u])&&ln(l,e,t,u,s,n||ec(l,t));return new Ke(r,this._parents,e,t)}At.prototype.interrupt=Zl;At.prototype.transition=tc;const Dt=e=>()=>e;function nc(e,{sourceEvent:t,target:n,transform:r,dispatch:i}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:r,enumerable:!0,configurable:!0},_:{value:i}})}function $e(e,t,n){this.k=e,this.x=t,this.y=n}$e.prototype={constructor:$e,scale:function(e){return e===1?this:new $e(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new $e(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var jn=new $e(1,0,0);$e.prototype;function En(e){e.stopImmediatePropagation()}function gt(e){e.preventDefault(),e.stopImmediatePropagation()}function rc(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function ic(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function Or(){return this.__zoom||jn}function oc(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function sc(){return navigator.maxTouchPoints||"ontouchstart"in this}function ac(e,t,n){var r=e.invertX(t[0][0])-n[0][0],i=e.invertX(t[1][0])-n[1][0],o=e.invertY(t[0][1])-n[0][1],s=e.invertY(t[1][1])-n[1][1];return e.translate(i>r?(r+i)/2:Math.min(0,r)||Math.max(0,i),s>o?(o+s)/2:Math.min(0,o)||Math.max(0,s))}function lc(){var e=rc,t=ic,n=ac,r=oc,i=sc,o=[0,1/0],s=[[-1/0,-1/0],[1/0,1/0]],a=250,l=Bl,u=on("start","zoom","end"),c,d,p,_=500,b=150,I=0,S=10;function x(h){h.property("__zoom",Or).on("wheel.zoom",R,{passive:!1}).on("mousedown.zoom",K).on("dblclick.zoom",V).filter(i).on("touchstart.zoom",Q).on("touchmove.zoom",q).on("touchend.zoom touchcancel.zoom",fe).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}x.transform=function(h,O,v,P){var M=h.selection?h.selection():h;M.property("__zoom",Or),h!==M?T(h,O,v,P):M.interrupt().each(function(){k(this,arguments).event(P).start().zoom(null,typeof O=="function"?O.apply(this,arguments):O).end()})},x.scaleBy=function(h,O,v,P){x.scaleTo(h,function(){var M=this.__zoom.k,U=typeof O=="function"?O.apply(this,arguments):O;return M*U},v,P)},x.scaleTo=function(h,O,v,P){x.transform(h,function(){var M=t.apply(this,arguments),U=this.__zoom,z=v==null?m(M):typeof v=="function"?v.apply(this,arguments):v,B=U.invert(z),Y=typeof O=="function"?O.apply(this,arguments):O;return n(N(H(U,Y),z,B),M,s)},v,P)},x.translateBy=function(h,O,v,P){x.transform(h,function(){return n(this.__zoom.translate(typeof O=="function"?O.apply(this,arguments):O,typeof v=="function"?v.apply(this,arguments):v),t.apply(this,arguments),s)},null,P)},x.translateTo=function(h,O,v,P,M){x.transform(h,function(){var U=t.apply(this,arguments),z=this.__zoom,B=P==null?m(U):typeof P=="function"?P.apply(this,arguments):P;return n(jn.translate(B[0],B[1]).scale(z.k).translate(typeof O=="function"?-O.apply(this,arguments):-O,typeof v=="function"?-v.apply(this,arguments):-v),U,s)},P,M)};function H(h,O){return O=Math.max(o[0],Math.min(o[1],O)),O===h.k?h:new $e(O,h.x,h.y)}function N(h,O,v){var P=O[0]-v[0]*h.k,M=O[1]-v[1]*h.k;return P===h.x&&M===h.y?h:new $e(h.k,P,M)}function m(h){return[(+h[0][0]+ +h[1][0])/2,(+h[0][1]+ +h[1][1])/2]}function T(h,O,v,P){h.on("start.zoom",function(){k(this,arguments).event(P).start()}).on("interrupt.zoom end.zoom",function(){k(this,arguments).event(P).end()}).tween("zoom",function(){var M=this,U=arguments,z=k(M,U).event(P),B=t.apply(M,U),Y=v==null?m(B):typeof v=="function"?v.apply(M,U):v,ne=Math.max(B[1][0]-B[0][0],B[1][1]-B[0][1]),re=M.__zoom,le=typeof O=="function"?O.apply(M,U):O,he=l(re.invert(Y).concat(ne/re.k),le.invert(Y).concat(ne/le.k));return function(ue){if(ue===1)ue=le;else{var ve=he(ue),nt=ne/ve[2];ue=new $e(nt,Y[0]-ve[0]*nt,Y[1]-ve[1]*nt)}z.zoom(null,ue)}})}function k(h,O,v){return!v&&h.__zooming||new w(h,O)}function w(h,O){this.that=h,this.args=O,this.active=0,this.sourceEvent=null,this.extent=t.apply(h,O),this.taps=0}w.prototype={event:function(h){return h&&(this.sourceEvent=h),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(h,O){return this.mouse&&h!=="mouse"&&(this.mouse[1]=O.invert(this.mouse[0])),this.touch0&&h!=="touch"&&(this.touch0[1]=O.invert(this.touch0[0])),this.touch1&&h!=="touch"&&(this.touch1[1]=O.invert(this.touch1[0])),this.that.__zoom=O,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(h){var O=we(this.that).datum();u.call(h,this.that,new nc(h,{sourceEvent:this.sourceEvent,target:x,type:h,transform:this.that.__zoom,dispatch:u}),O)}};function R(h,...O){if(!e.apply(this,arguments))return;var v=k(this,O).event(h),P=this.__zoom,M=Math.max(o[0],Math.min(o[1],P.k*Math.pow(2,r.apply(this,arguments)))),U=ze(h);if(v.wheel)(v.mouse[0][0]!==U[0]||v.mouse[0][1]!==U[1])&&(v.mouse[1]=P.invert(v.mouse[0]=U)),clearTimeout(v.wheel);else{if(P.k===M)return;v.mouse=[U,P.invert(U)],Vt(this),v.start()}gt(h),v.wheel=setTimeout(z,b),v.zoom("mouse",n(N(H(P,M),v.mouse[0],v.mouse[1]),v.extent,s));function z(){v.wheel=null,v.end()}}function K(h,...O){if(p||!e.apply(this,arguments))return;var v=h.currentTarget,P=k(this,O,!0).event(h),M=we(h.view).on("mousemove.zoom",Y,!0).on("mouseup.zoom",ne,!0),U=ze(h,v),z=h.clientX,B=h.clientY;bi(h.view),En(h),P.mouse=[U,this.__zoom.invert(U)],Vt(this),P.start();function Y(re){if(gt(re),!P.moved){var le=re.clientX-z,he=re.clientY-B;P.moved=le*le+he*he>I}P.event(re).zoom("mouse",n(N(P.that.__zoom,P.mouse[0]=ze(re,v),P.mouse[1]),P.extent,s))}function ne(re){M.on("mousemove.zoom mouseup.zoom",null),Ei(re.view,P.moved),gt(re),P.event(re).end()}}function V(h,...O){if(!!e.apply(this,arguments)){var v=this.__zoom,P=ze(h.changedTouches?h.changedTouches[0]:h,this),M=v.invert(P),U=v.k*(h.shiftKey?.5:2),z=n(N(H(v,U),P,M),t.apply(this,O),s);gt(h),a>0?we(this).transition().duration(a).call(T,z,P,h):we(this).call(x.transform,z,P,h)}}function Q(h,...O){if(!!e.apply(this,arguments)){var v=h.touches,P=v.length,M=k(this,O,h.changedTouches.length===P).event(h),U,z,B,Y;for(En(h),z=0;z<P;++z)B=v[z],Y=ze(B,this),Y=[Y,this.__zoom.invert(Y),B.identifier],M.touch0?!M.touch1&&M.touch0[2]!==Y[2]&&(M.touch1=Y,M.taps=0):(M.touch0=Y,U=!0,M.taps=1+!!c);c&&(c=clearTimeout(c)),U&&(M.taps<2&&(d=Y[0],c=setTimeout(function(){c=null},_)),Vt(this),M.start())}}function q(h,...O){if(!!this.__zooming){var v=k(this,O).event(h),P=h.changedTouches,M=P.length,U,z,B,Y;for(gt(h),U=0;U<M;++U)z=P[U],B=ze(z,this),v.touch0&&v.touch0[2]===z.identifier?v.touch0[0]=B:v.touch1&&v.touch1[2]===z.identifier&&(v.touch1[0]=B);if(z=v.that.__zoom,v.touch1){var ne=v.touch0[0],re=v.touch0[1],le=v.touch1[0],he=v.touch1[1],ue=(ue=le[0]-ne[0])*ue+(ue=le[1]-ne[1])*ue,ve=(ve=he[0]-re[0])*ve+(ve=he[1]-re[1])*ve;z=H(z,Math.sqrt(ue/ve)),B=[(ne[0]+le[0])/2,(ne[1]+le[1])/2],Y=[(re[0]+he[0])/2,(re[1]+he[1])/2]}else if(v.touch0)B=v.touch0[0],Y=v.touch0[1];else return;v.zoom("touch",n(N(z,B,Y),v.extent,s))}}function fe(h,...O){if(!!this.__zooming){var v=k(this,O).event(h),P=h.changedTouches,M=P.length,U,z;for(En(h),p&&clearTimeout(p),p=setTimeout(function(){p=null},_),U=0;U<M;++U)z=P[U],v.touch0&&v.touch0[2]===z.identifier?delete v.touch0:v.touch1&&v.touch1[2]===z.identifier&&delete v.touch1;if(v.touch1&&!v.touch0&&(v.touch0=v.touch1,delete v.touch1),v.touch0)v.touch0[1]=this.__zoom.invert(v.touch0[0]);else if(v.end(),v.taps===2&&(z=ze(z,this),Math.hypot(d[0]-z[0],d[1]-z[1])<S)){var B=we(this).on("dblclick.zoom");B&&B.apply(this,arguments)}}}return x.wheelDelta=function(h){return arguments.length?(r=typeof h=="function"?h:Dt(+h),x):r},x.filter=function(h){return arguments.length?(e=typeof h=="function"?h:Dt(!!h),x):e},x.touchable=function(h){return arguments.length?(i=typeof h=="function"?h:Dt(!!h),x):i},x.extent=function(h){return arguments.length?(t=typeof h=="function"?h:Dt([[+h[0][0],+h[0][1]],[+h[1][0],+h[1][1]]]),x):t},x.scaleExtent=function(h){return arguments.length?(o[0]=+h[0],o[1]=+h[1],x):[o[0],o[1]]},x.translateExtent=function(h){return arguments.length?(s[0][0]=+h[0][0],s[1][0]=+h[1][0],s[0][1]=+h[0][1],s[1][1]=+h[1][1],x):[[s[0][0],s[0][1]],[s[1][0],s[1][1]]]},x.constrain=function(h){return arguments.length?(n=h,x):n},x.duration=function(h){return arguments.length?(a=+h,x):a},x.interpolate=function(h){return arguments.length?(l=h,x):l},x.on=function(){var h=u.on.apply(u,arguments);return h===u?x:h},x.clickDistance=function(h){return arguments.length?(I=(h=+h)*h,x):Math.sqrt(I)},x.tapDistance=function(h){return arguments.length?(S=+h,x):S},x}const pe=mt(""),Rn=mt(jn);function un(){const e=Cr(ai);if(!e)throw new Error("Use RoomProvider as parent with id prop");return e}function cn(){const e=un(),{subscribe:t,set:n}=mt();function r(o){e.updatePresence(o)}const i=e.subscribe("my-presence",o=>{n(o)});return en(()=>{i()}),{subscribe:t,update:r}}function uc(){const e=un(),t=mt(),n=e.subscribe("others",r=>{t.set(r)});return en(n),t}function cc(){const e=un(),t=mt();async function n(){const{root:r}=await e.getStorage();t.set(r)}return n(),t}function Ui(e,t){const n=un(),r=cc(),i=mt();let o=()=>{};const s=r.subscribe(a=>{!a||(a.get(e)||a.set(e,new ds(t)),i.set(a.get(e)),o(),o=n.subscribe(a.get(e),l=>{i.set(l)}))});return en(s),i}function fc(e){let t,n,r;return n=new li({props:{color:e[1],position:e[3],prompt:e[6],transform:e[0],isDragging:e[5],interactive:e[2]}}),{c(){t=oe("div"),ke(n.$$.fragment)},l(i){t=se(i,"DIV",{});var o=te(t);xe(n.$$.fragment,o),o.forEach($)},m(i,o){ie(i,t,o),Oe(n,t,null),e[9](t),r=!0},p(i,[o]){const s={};o&2&&(s.color=i[1]),o&8&&(s.position=i[3]),o&64&&(s.prompt=i[6]),o&1&&(s.transform=i[0]),o&32&&(s.isDragging=i[5]),o&4&&(s.interactive=i[2]),n.$set(s)},i(i){r||(X(n.$$.fragment,i),r=!0)},o(i){Z(n.$$.fragment,i),r=!1},d(i){i&&$(t),Ie(n),e[9](null)}}}function hc(e,t,n){let r,i;const o=cn();Ve(e,o,_=>n(8,i=_));let{transform:s}=t,{color:a="black"}=t,{interactive:l=!1}=t,u={x:768,y:768},c,d=!1;Pt(()=>{function _(x){n(5,d=!0)}function b(x){const H=it(s.invertX(x.x)-256),N=it(s.invertY(x.y)-512/2);n(3,u={x:H,y:N})}function I(x){n(5,d=!1);const H=it(s.invertX(x.x)-512/2),N=it(s.invertY(x.y)-512/2);o.update({frame:{x:H,y:N}})}const S=ml().on("start",_).on("drag",b).on("end",I);we(c).call(S)});function p(_){Et[_?"unshift":"push"](()=>{c=_,n(4,c)})}return e.$$set=_=>{"transform"in _&&n(0,s=_.transform),"color"in _&&n(1,a=_.color),"interactive"in _&&n(2,l=_.interactive)},e.$$.update=()=>{e.$$.dirty&256&&n(6,r=i==null?void 0:i.currentPrompt)},[s,a,l,u,c,d,r,o,i,p]}class dc extends Se{constructor(t){super(),Pe(this,t,hc,fc,Te,{transform:0,color:1,interactive:2})}}const pc="wss://spaces.huggingface.tech/huggingface-projects/stable-diffusion-multiplayer/gradio/queue/join",mc="https://hf.space/embed/huggingface-projects/stable-diffusion-multiplayer/uploads";function _c(e){let t,n,r,i;const o=e[8].default,s=Nn(o,e,e[7],null);return{c(){t=oe("div"),n=oe("canvas"),r=_e(),s&&s.c(),this.h()},l(a){t=se(a,"DIV",{class:!0});var l=te(t);n=se(l,"CANVAS",{width:!0,height:!0,class:!0}),te(n).forEach($),r=ge(l),s&&s.l(l),l.forEach($),this.h()},h(){D(n,"width",e[4]),D(n,"height",e[3]),D(n,"class","absolute top-0 left-0 bg-white svelte-6dcxg7"),D(t,"class","absolute top-0 left-0 right-0 bottom-0 overflow-hidden z-0 bg-gray-800")},m(a,l){ie(a,t,l),J(t,n),e[9](n),J(t,r),s&&s.m(t,null),e[10](t),i=!0},p(a,[l]){s&&s.p&&(!i||l&128)&&Cn(s,o,a,a[7],i?Un(o,a[7],l,null):Mn(a[7]),null)},i(a){i||(X(s,a),i=!0)},o(a){Z(s,a),i=!1},d(a){a&&$(t),e[9](null),s&&s.d(a),e[10](null)}}}function gc(e,t,n){let r,i;Ve(e,Rn,w=>n(12,r=w));let{$$slots:o={},$$scope:s}=t;const a=cn(),l=Ui("promptImgStorage");Ve(e,l,w=>n(6,i=w));const u=512*4,c=512*4;let{value:d}=t,p,_;const b=new Set;function I(w){return w?Object.values(w).sort((K,V)=>K.date-V.date).filter(({id:K})=>!b.has(K)):[]}let S=[];Pt(()=>{const w=c/p.clientWidth,R=.1,K=3,V=lc().scaleExtent([1/w/K,1]).translateExtent([[-c*R,-u*R],[c*(1+R),u*(1+R)]]).tapDistance(10).on("zoom",H),Q=we(d.parentElement).call(V).call(V.scaleTo,1/w/2).on("pointermove",N).on("pointerleave",m);_=d.getContext("2d");function q(){console.log("zoom reset");const fe=c/p.clientWidth;V.scaleExtent([1/fe/K,1]),Q.call(V.scaleTo,1/fe/2)}return window.addEventListener("resize",q),()=>{window.removeEventListener("resize",q)}});function x(w){Promise.all(w.map(({imgURL:R,position:K,id:V})=>new Promise(Q=>{const q=new Image;q.crossOrigin="anonymous",q.onload=()=>{const h={img:q,position:K,id:V};_.drawImage(q,K.x,K.y,q.width,q.height),Q(h)};const fe=R.split("/");q.src=`${mc}/${fe.slice(3).join("/")}`}))).then(R=>{R.forEach(({img:K,position:V,id:Q})=>{b.add(Q),_.drawImage(K,V.x,V.y,K.width,K.height)})})}function H(w){const R=me(Rn,r=w.transform,r);n(0,d.style.transform=`translate(${R.x}px, ${R.y}px) scale(${R.k})`,d)}function N(w){w.preventDefault();const R=it(r.invertX(w.clientX)),K=it(r.invertY(w.clientY));a.update({cursor:{x:R,y:K}})}function m(){a.update({cursor:null})}function T(w){Et[w?"unshift":"push"](()=>{d=w,n(0,d)})}function k(w){Et[w?"unshift":"push"](()=>{p=w,n(1,p)})}return e.$$set=w=>{"value"in w&&n(0,d=w.value),"$$scope"in w&&n(7,s=w.$$scope)},e.$$.update=()=>{e.$$.dirty&64&&n(5,S=I(i==null?void 0:i.toObject())),e.$$.dirty&32&&S&&x(S)},[d,p,l,u,c,S,i,s,o,T,k]}class vc extends Se{constructor(t){super(),Pe(this,t,gc,_c,Te,{value:0})}}function yc(e){let t,n,r,i,o,s,a,l,u;return{c(){t=oe("div"),n=oe("button"),r=oe("span"),i=lt("+"),o=_e(),s=oe("span"),a=lt("Paint"),this.h()},l(c){t=se(c,"DIV",{class:!0});var d=te(t);n=se(d,"BUTTON",{class:!0,title:!0});var p=te(n);r=se(p,"SPAN",{class:!0});var _=te(r);i=ut(_,"+"),_.forEach($),o=ge(p),s=se(p,"SPAN",{});var b=te(s);a=ut(b,"Paint"),b.forEach($),p.forEach($),d.forEach($),this.h()},h(){D(r,"class","rounded-sm h-6 w-6 flex justify-center items-center border-2 border-dashed border-violet-700 mr-2"),D(n,"class","button-paint bg-violet-100 text-violet-900 svelte-15omrbl"),D(n,"title","New Paint Frame"),D(t,"class","grid grid-cols-1 gap-3 w-max mx-auto")},m(c,d){ie(c,t,d),J(t,n),J(n,r),J(r,i),J(n,o),J(n,s),J(s,a),l||(u=vt(n,"click",e[1]),l=!0)},p:Ee,i:Ee,o:Ee,d(c){c&&$(t),l=!1,u()}}}function wc(e){const t=Mr(),n=i=>{i.preventDefault(),i.key==="Enter"&&t("paintMode",{mode:"paint"})};return Pt(()=>(window.addEventListener("keyup",n),()=>{window.removeEventListener("keyup",n)})),[t,()=>t("paintMode",{mode:"paint"})]}class bc extends Se{constructor(t){super(),Pe(this,t,wc,yc,Te,{})}}function Ec(e){let t,n,r,i;return{c(){t=oe("form"),n=oe("input"),this.h()},l(o){t=se(o,"FORM",{class:!0});var s=te(t);n=se(s,"INPUT",{class:!0,placeholder:!0,title:!0,type:!0,name:!0}),s.forEach($),this.h()},h(){D(n,"class","input svelte-1pw1u5k"),D(n,"placeholder","Type a prompt..."),D(n,"title","Input prompt to generate image and obtain palette"),D(n,"type","text"),D(n,"name","prompt"),D(t,"class","fixed w-screen top-0 left-0 bottom-0 right-0 max-h-screen z-50 flex items-center justify-center bg-black bg-opacity-80 px-3")},m(o,s){ie(o,t,s),J(t,n),e[5](n),er(n,e[0]),r||(i=[vt(n,"input",e[6]),vt(n,"click",to(e[4])),vt(t,"submit",no(e[3])),vt(t,"click",e[7])],r=!0)},p(o,[s]){s&1&&n.value!==o[0]&&er(n,o[0])},i:Ee,o:Ee,d(o){o&&$(t),e[5](null),r=!1,ro(i)}}}function kc(e,t,n){const r=Mr();let i,o;const s=cn(),a=_=>{_.key==="Escape"&&(r("close"),s.update({currentPrompt:"",isPrompting:!1}))};Pt(()=>(o.focus(),window.addEventListener("keyup",a),()=>{window.removeEventListener("keyup",a)}));function l(){i.trim()!==""&&r("prompt",i)}function u(_){io.call(this,e,_)}function c(_){Et[_?"unshift":"push"](()=>{o=_,n(1,o)})}function d(){i=this.value,n(0,i)}const p=()=>r("close");return e.$$.update=()=>{e.$$.dirty&1&&s.update({currentPrompt:i,isPrompting:!0})},[i,o,r,l,u,c,d,p]}class xc extends Se{constructor(t){super(),Pe(this,t,kc,Ec,Te,{})}}var Di={},zi={},Gn={exports:{}},W=String,$i=function(){return{isColorSupported:!1,reset:W,bold:W,dim:W,italic:W,underline:W,inverse:W,hidden:W,strikethrough:W,black:W,red:W,green:W,yellow:W,blue:W,magenta:W,cyan:W,white:W,gray:W,bgBlack:W,bgRed:W,bgGreen:W,bgYellow:W,bgBlue:W,bgMagenta:W,bgCyan:W,bgWhite:W}};Gn.exports=$i();Gn.exports.createColors=$i;(function(e){Object.defineProperty(e,"__esModule",{value:!0});function t(l,u){for(var c in u)Object.defineProperty(l,c,{enumerable:!0,get:u[c]})}t(e,{dim:()=>s,default:()=>a});const n=r(Gn.exports);function r(l){return l&&l.__esModule?l:{default:l}}let i=new Set;function o(l,u,c){typeof process<"u"&&process.env.JEST_WORKER_ID||c&&i.has(c)||(c&&i.add(c),console.warn(""),u.forEach(d=>console.warn(l,"-",d)))}function s(l){return n.default.dim(l)}const a={info(l,u){o(n.default.bold(n.default.cyan("info")),...Array.isArray(l)?[l]:[u,l])},warn(l,u){o(n.default.bold(n.default.yellow("warn")),...Array.isArray(l)?[l]:[u,l])},risk(l,u){o(n.default.bold(n.default.magenta("risk")),...Array.isArray(l)?[l]:[u,l])}}})(zi);(function(e){Object.defineProperty(e,"__esModule",{value:!0}),Object.defineProperty(e,"default",{enumerable:!0,get:()=>i});const t=n(zi);function n(o){return o&&o.__esModule?o:{default:o}}function r({version:o,from:s,to:a}){t.default.warn(`${s}-color-renamed`,[`As of Tailwind CSS ${o}, \`${s}\` has been renamed to \`${a}\`.`,"Update your configuration file to silence this warning."])}const i={inherit:"inherit",current:"currentColor",transparent:"transparent",black:"#000",white:"#fff",slate:{50:"#f8fafc",100:"#f1f5f9",200:"#e2e8f0",300:"#cbd5e1",400:"#94a3b8",500:"#64748b",600:"#475569",700:"#334155",800:"#1e293b",900:"#0f172a"},gray:{50:"#f9fafb",100:"#f3f4f6",200:"#e5e7eb",300:"#d1d5db",400:"#9ca3af",500:"#6b7280",600:"#4b5563",700:"#374151",800:"#1f2937",900:"#111827"},zinc:{50:"#fafafa",100:"#f4f4f5",200:"#e4e4e7",300:"#d4d4d8",400:"#a1a1aa",500:"#71717a",600:"#52525b",700:"#3f3f46",800:"#27272a",900:"#18181b"},neutral:{50:"#fafafa",100:"#f5f5f5",200:"#e5e5e5",300:"#d4d4d4",400:"#a3a3a3",500:"#737373",600:"#525252",700:"#404040",800:"#262626",900:"#171717"},stone:{50:"#fafaf9",100:"#f5f5f4",200:"#e7e5e4",300:"#d6d3d1",400:"#a8a29e",500:"#78716c",600:"#57534e",700:"#44403c",800:"#292524",900:"#1c1917"},red:{50:"#fef2f2",100:"#fee2e2",200:"#fecaca",300:"#fca5a5",400:"#f87171",500:"#ef4444",600:"#dc2626",700:"#b91c1c",800:"#991b1b",900:"#7f1d1d"},orange:{50:"#fff7ed",100:"#ffedd5",200:"#fed7aa",300:"#fdba74",400:"#fb923c",500:"#f97316",600:"#ea580c",700:"#c2410c",800:"#9a3412",900:"#7c2d12"},amber:{50:"#fffbeb",100:"#fef3c7",200:"#fde68a",300:"#fcd34d",400:"#fbbf24",500:"#f59e0b",600:"#d97706",700:"#b45309",800:"#92400e",900:"#78350f"},yellow:{50:"#fefce8",100:"#fef9c3",200:"#fef08a",300:"#fde047",400:"#facc15",500:"#eab308",600:"#ca8a04",700:"#a16207",800:"#854d0e",900:"#713f12"},lime:{50:"#f7fee7",100:"#ecfccb",200:"#d9f99d",300:"#bef264",400:"#a3e635",500:"#84cc16",600:"#65a30d",700:"#4d7c0f",800:"#3f6212",900:"#365314"},green:{50:"#f0fdf4",100:"#dcfce7",200:"#bbf7d0",300:"#86efac",400:"#4ade80",500:"#22c55e",600:"#16a34a",700:"#15803d",800:"#166534",900:"#14532d"},emerald:{50:"#ecfdf5",100:"#d1fae5",200:"#a7f3d0",300:"#6ee7b7",400:"#34d399",500:"#10b981",600:"#059669",700:"#047857",800:"#065f46",900:"#064e3b"},teal:{50:"#f0fdfa",100:"#ccfbf1",200:"#99f6e4",300:"#5eead4",400:"#2dd4bf",500:"#14b8a6",600:"#0d9488",700:"#0f766e",800:"#115e59",900:"#134e4a"},cyan:{50:"#ecfeff",100:"#cffafe",200:"#a5f3fc",300:"#67e8f9",400:"#22d3ee",500:"#06b6d4",600:"#0891b2",700:"#0e7490",800:"#155e75",900:"#164e63"},sky:{50:"#f0f9ff",100:"#e0f2fe",200:"#bae6fd",300:"#7dd3fc",400:"#38bdf8",500:"#0ea5e9",600:"#0284c7",700:"#0369a1",800:"#075985",900:"#0c4a6e"},blue:{50:"#eff6ff",100:"#dbeafe",200:"#bfdbfe",300:"#93c5fd",400:"#60a5fa",500:"#3b82f6",600:"#2563eb",700:"#1d4ed8",800:"#1e40af",900:"#1e3a8a"},indigo:{50:"#eef2ff",100:"#e0e7ff",200:"#c7d2fe",300:"#a5b4fc",400:"#818cf8",500:"#6366f1",600:"#4f46e5",700:"#4338ca",800:"#3730a3",900:"#312e81"},violet:{50:"#f5f3ff",100:"#ede9fe",200:"#ddd6fe",300:"#c4b5fd",400:"#a78bfa",500:"#8b5cf6",600:"#7c3aed",700:"#6d28d9",800:"#5b21b6",900:"#4c1d95"},purple:{50:"#faf5ff",100:"#f3e8ff",200:"#e9d5ff",300:"#d8b4fe",400:"#c084fc",500:"#a855f7",600:"#9333ea",700:"#7e22ce",800:"#6b21a8",900:"#581c87"},fuchsia:{50:"#fdf4ff",100:"#fae8ff",200:"#f5d0fe",300:"#f0abfc",400:"#e879f9",500:"#d946ef",600:"#c026d3",700:"#a21caf",800:"#86198f",900:"#701a75"},pink:{50:"#fdf2f8",100:"#fce7f3",200:"#fbcfe8",300:"#f9a8d4",400:"#f472b6",500:"#ec4899",600:"#db2777",700:"#be185d",800:"#9d174d",900:"#831843"},rose:{50:"#fff1f2",100:"#ffe4e6",200:"#fecdd3",300:"#fda4af",400:"#fb7185",500:"#f43f5e",600:"#e11d48",700:"#be123c",800:"#9f1239",900:"#881337"},get lightBlue(){return r({version:"v2.2",from:"lightBlue",to:"sky"}),this.sky},get warmGray(){return r({version:"v3.0",from:"warmGray",to:"stone"}),this.stone},get trueGray(){return r({version:"v3.0",from:"trueGray",to:"neutral"}),this.neutral},get coolGray(){return r({version:"v3.0",from:"coolGray",to:"gray"}),this.gray},get blueGray(){return r({version:"v3.0",from:"blueGray",to:"slate"}),this.slate}}})(Di);let kn=Di;var Oc=(kn.__esModule?kn:{default:kn}).default;const Ye=Object.values(Oc).filter(e=>typeof e=="object").map(e=>e[200]).slice(0,18),zt=["\u{1F436}","\u{1F431}","\u{1F42D}","\u{1F439}","\u{1F430}","\u{1F98A}","\u{1F43B}","\u{1F43C}","\u{1F428}","\u{1F42F}","\u{1F981}","\u{1F42E}","\u{1F432}","\u{1F31A}","\u{1F31D}","\u{1F31E}","\u{1F31B}","\u{1F31C}"];let Ic=(e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce((t,n)=>(n&=63,n<36?t+=n.toString(36):n<62?t+=(n-26).toString(36).toUpperCase():n>62?t+="-":t+="_",t),"");function Ir(e,t,n){const r=e.slice();return r[20]=t[n].connectionId,r[21]=t[n].presence,r}function Sr(e){let t,n;return t=new xc({}),t.$on("prompt",e[11]),t.$on("close",e[10]),{c(){ke(t.$$.fragment)},l(r){xe(t.$$.fragment,r)},m(r,i){Oe(t,r,i),n=!0},p:Ee,i(r){n||(X(t.$$.fragment,r),n=!0)},o(r){Z(t.$$.fragment,r),n=!1},d(r){Ie(t,r)}}}function Pr(e){let t=[],n=new Map,r,i,o=[...e[5]];const s=a=>a[20];for(let a=0;a<o.length;a+=1){let l=Ir(e,o,a),u=s(l);n.set(u,t[a]=Lr(u,l))}return{c(){for(let a=0;a<t.length;a+=1)t[a].c();r=Xe()},l(a){for(let l=0;l<t.length;l+=1)t[l].l(a);r=Xe()},m(a,l){for(let u=0;u<t.length;u+=1)t[u].m(a,l);ie(a,r,l),i=!0},p(a,l){l&48&&(o=[...a[5]],ct(),t=ao(t,l,s,1,a,o,n,r.parentNode,lo,Lr,r,Ir),ft())},i(a){if(!i){for(let l=0;l<o.length;l+=1)X(t[l]);i=!0}},o(a){for(let l=0;l<t.length;l+=1)Z(t[l]);i=!1},d(a){for(let l=0;l<t.length;l+=1)t[l].d(a);a&&$(r)}}}function Tr(e){var r,i;let t,n;return t=new li({props:{color:Ye[1+e[20]%(Ye.length-1)],position:(r=e[21])==null?void 0:r.frame,prompt:(i=e[21])==null?void 0:i.currentPrompt,transform:e[4]}}),{c(){ke(t.$$.fragment)},l(o){xe(t.$$.fragment,o)},m(o,s){Oe(t,o,s),n=!0},p(o,s){var l,u;const a={};s&32&&(a.color=Ye[1+o[20]%(Ye.length-1)]),s&32&&(a.position=(l=o[21])==null?void 0:l.frame),s&32&&(a.prompt=(u=o[21])==null?void 0:u.currentPrompt),s&16&&(a.transform=o[4]),t.$set(a)},i(o){n||(X(t.$$.fragment,o),n=!0)},o(o){Z(t.$$.fragment,o),n=!1},d(o){Ie(t,o)}}}function Ar(e){var r;let t,n;return t=new ks({props:{emoji:zt[1+e[20]%(zt.length-1)],color:Ye[1+e[20]%(Ye.length-1)],position:(r=e[21])==null?void 0:r.cursor,transform:e[4]}}),{c(){ke(t.$$.fragment)},l(i){xe(t.$$.fragment,i)},m(i,o){Oe(t,i,o),n=!0},p(i,o){var a;const s={};o&32&&(s.emoji=zt[1+i[20]%(zt.length-1)]),o&32&&(s.color=Ye[1+i[20]%(Ye.length-1)]),o&32&&(s.position=(a=i[21])==null?void 0:a.cursor),o&16&&(s.transform=i[4]),t.$set(s)},i(i){n||(X(t.$$.fragment,i),n=!0)},o(i){Z(t.$$.fragment,i),n=!1},d(i){Ie(t,i)}}}function Lr(e,t){var l,u,c;let n,r,i,o,s=((l=t[21])==null?void 0:l.isPrompting)&&((u=t[21])==null?void 0:u.frame)&&Tr(t),a=((c=t[21])==null?void 0:c.cursor)&&Ar(t);return{key:e,first:null,c(){n=Xe(),s&&s.c(),r=_e(),a&&a.c(),i=Xe(),this.h()},l(d){n=Xe(),s&&s.l(d),r=ge(d),a&&a.l(d),i=Xe(),this.h()},h(){this.first=n},m(d,p){ie(d,n,p),s&&s.m(d,p),ie(d,r,p),a&&a.m(d,p),ie(d,i,p),o=!0},p(d,p){var _,b,I;t=d,((_=t[21])==null?void 0:_.isPrompting)&&((b=t[21])==null?void 0:b.frame)?s?(s.p(t,p),p&32&&X(s,1)):(s=Tr(t),s.c(),X(s,1),s.m(r.parentNode,r)):s&&(ct(),Z(s,1,1,()=>{s=null}),ft()),(I=t[21])!=null&&I.cursor?a?(a.p(t,p),p&32&&X(a,1)):(a=Ar(t),a.c(),X(a,1),a.m(i.parentNode,i)):a&&(ct(),Z(a,1,1,()=>{a=null}),ft())},i(d){o||(X(s),X(a),o=!0)},o(d){Z(s),Z(a),o=!1},d(d){d&&$(n),s&&s.d(d),d&&$(r),a&&a.d(d),d&&$(i)}}}function Sc(e){let t,n,r,i,o,s,a,l,u,c,d,p,_,b,I,S=e[0]&&Sr(e);function x(m){e[14](m)}let H={};e[1]!==void 0&&(H.value=e[1]),s=new vc({props:H}),Et.push(()=>oo(s,"value",x)),c=new dc({props:{transform:e[4],interactive:!e[2]}});let N=e[5]&&Pr(e);return b=new bc({}),b.$on("paintMode",e[9]),{c(){t=oe("div"),n=lt(e[3]),r=_e(),S&&S.c(),i=_e(),o=oe("div"),ke(s.$$.fragment),l=_e(),u=oe("main"),ke(c.$$.fragment),d=_e(),N&&N.c(),p=_e(),_=oe("div"),ke(b.$$.fragment),this.h()},l(m){t=se(m,"DIV",{class:!0});var T=te(t);n=ut(T,e[3]),T.forEach($),r=ge(m),S&&S.l(m),i=ge(m),o=se(m,"DIV",{class:!0});var k=te(o);xe(s.$$.fragment,k),l=ge(k),u=se(k,"MAIN",{class:!0});var w=te(u);xe(c.$$.fragment,w),d=ge(w),N&&N.l(w),w.forEach($),k.forEach($),p=ge(m),_=se(m,"DIV",{class:!0});var R=te(_);xe(b.$$.fragment,R),R.forEach($),this.h()},h(){D(t,"class","text touch-none pointer-events-none"),D(u,"class","z-10 relative"),D(o,"class","fixed top-0 left-0 z-0 w-screen h-screen"),D(_,"class","fixed bottom-0 left-0 right-0 z-10 my-2")},m(m,T){ie(m,t,T),J(t,n),ie(m,r,T),S&&S.m(m,T),ie(m,i,T),ie(m,o,T),Oe(s,o,null),J(o,l),J(o,u),Oe(c,u,null),J(u,d),N&&N.m(u,null),ie(m,p,T),ie(m,_,T),Oe(b,_,null),I=!0},p(m,[T]){(!I||T&8)&&Dn(n,m[3]),m[0]?S?(S.p(m,T),T&1&&X(S,1)):(S=Sr(m),S.c(),X(S,1),S.m(i.parentNode,i)):S&&(ct(),Z(S,1,1,()=>{S=null}),ft());const k={};!a&&T&2&&(a=!0,k.value=m[1],so(()=>a=!1)),s.$set(k);const w={};T&16&&(w.transform=m[4]),T&4&&(w.interactive=!m[2]),c.$set(w),m[5]?N?(N.p(m,T),T&32&&X(N,1)):(N=Pr(m),N.c(),X(N,1),N.m(u,null)):N&&(ct(),Z(N,1,1,()=>{N=null}),ft())},i(m){I||(X(S),X(s.$$.fragment,m),X(c.$$.fragment,m),X(N),X(b.$$.fragment,m),I=!0)},o(m){Z(S),Z(s.$$.fragment,m),Z(c.$$.fragment,m),Z(N),Z(b.$$.fragment,m),I=!1},d(m){m&&$(t),m&&$(r),S&&S.d(m),m&&$(i),m&&$(o),Ie(s),Ie(c),N&&N.d(),m&&$(p),m&&$(_),Ie(b)}}}function Pc({position:e}){return`${e.x}_${e.y}`}function Tc(e,t,n){let r,i,o,s,a,l;Ve(e,pe,k=>n(3,i=k)),Ve(e,Rn,k=>n(4,a=k));const u=cn();Ve(e,u,k=>n(13,s=k));const c=uc();Ve(e,c,k=>n(5,l=k));const d={cursor:null,frame:null,isPrompting:!1,isLoading:!1,isMoving:!0,currentPrompt:""};u.update(d);const p=Ui("promptImgStorage");Ve(e,p,k=>n(12,o=k));function _(k){return k?Object.values(k).sort((R,K)=>R.date-K.date):[]}let b=!1,I;function S(k){k.detail.mode=="paint"&&!r&&(n(0,b=!0),u.update({isPrompting:!0}))}function x(){n(0,b=!1)}function H(k){m(),n(0,b=!1)}function N(k){const w=document.createElement("canvas");w.width=512,w.height=512;const R=w.getContext("2d");return R.save(),R.clearRect(0,0,512,512),R.globalCompositeOperation="source-over",R.drawImage(I,k.x,k.y,512,512,0,0,512,512),R.restore(),w.toDataURL("image/png")}async function m(){if(r)return;me(pe,i="Pending",i);const k=s.currentPrompt,w=s.frame;console.log("Generating...",k,w),u.update({isPrompting:!0,isLoading:!0});const R=crypto.randomUUID(),K={fn_index:0,data:[N(w),k,.75,7.5,30,"patchmatch"],session_hash:R};console.log("payload",K);const V=new WebSocket(pc);V.onclose=Q=>{Q.wasClean||(me(pe,i="Error",i),u.update({isPrompting:!1,isLoading:!1}))},V.onmessage=async function(Q){try{const q=JSON.parse(Q.data);switch(me(pe,i="",i),q.msg){case"send_data":me(pe,i="Sending Data",i),V.send(JSON.stringify(K));break;case"queue_full":me(pe,i="Queue full",i),V.close(),u.update({isPrompting:!1});return;case"estimation":const{rank:fe,queue_size:h}=q;me(pe,i=`On queue ${fe}/${h}`,i);break;case"process_generating":me(pe,i=q.success?"Generating":"Error",i);break;case"process_completed":try{const O=q.output.data[0];if(q.output.data[1])throw new Error("Potential NFSW content, please try again");const P=await _l(O),M=await gl(P,k),U={prompt:k,imgURL:M,position:w,date:new Date().getTime(),id:Ic()},z=Pc(U);o.set(z,U),console.log(M),me(pe,i=q.success?"Complete":"Error",i)}catch(O){const v=O;me(pe,i=v==null?void 0:v.message,i)}V.close(),u.update({isPrompting:!1});return;case"process_starts":me(pe,i="Processing",i);break}}catch(q){console.error(q),me(pe,i="Error",i)}}}function T(k){I=k,n(1,I)}return e.$$.update=()=>{e.$$.dirty&4096&&_(o==null?void 0:o.toObject()),e.$$.dirty&8192&&n(2,r=(s==null?void 0:s.isPrompting)||!1)},[b,I,r,i,a,l,u,c,p,S,x,H,o,s,T]}class Ac extends Se{constructor(t){super(),Pe(this,t,Tc,Sc,Te,{})}}function Rr(e){let t,n;return t=new gs({props:{client:e[2],$$slots:{default:[Rc]},$$scope:{ctx:e}}}),{c(){ke(t.$$.fragment)},l(r){xe(t.$$.fragment,r)},m(r,i){Oe(t,r,i),n=!0},p(r,i){const o={};i&4&&(o.client=r[2]),i&9&&(o.$$scope={dirty:i,ctx:r}),t.$set(o)},i(r){n||(X(t.$$.fragment,r),n=!0)},o(r){Z(t.$$.fragment,r),n=!1},d(r){Ie(t,r)}}}function Lc(e){let t,n;return t=new Ac({}),{c(){ke(t.$$.fragment)},l(r){xe(t.$$.fragment,r)},m(r,i){Oe(t,r,i),n=!0},i(r){n||(X(t.$$.fragment,r),n=!0)},o(r){Z(t.$$.fragment,r),n=!1},d(r){Ie(t,r)}}}function Rc(e){let t,n;return t=new ws({props:{id:e[0],$$slots:{default:[Lc]},$$scope:{ctx:e}}}),{c(){ke(t.$$.fragment)},l(r){xe(t.$$.fragment,r)},m(r,i){Oe(t,r,i),n=!0},p(r,i){const o={};i&1&&(o.id=r[0]),i&8&&(o.$$scope={dirty:i,ctx:r}),t.$set(o)},i(r){n||(X(t.$$.fragment,r),n=!0)},o(r){Z(t.$$.fragment,r),n=!1},d(r){Ie(t,r)}}}function Nc(e){let t,n,r=e[1]&&Rr(e);return{c(){r&&r.c(),t=Xe()},l(i){r&&r.l(i),t=Xe()},m(i,o){r&&r.m(i,o),ie(i,t,o),n=!0},p(i,[o]){i[1]?r?(r.p(i,o),o&2&&X(r,1)):(r=Rr(i),r.c(),X(r,1),r.m(t.parentNode,t)):r&&(ct(),Z(r,1,1,()=>{r=null}),ft())},i(i){n||(X(r),n=!0)},o(i){Z(r),n=!1},d(i){r&&r.d(i),i&&$(t)}}}const Dc=!0;function Cc(e,t,n){let r,i=!1,o;return Pt(()=>{n(0,r="multiplayer-SD"),n(2,o=ps({publicApiKey:"pk_test_JlUZGH3kQmhmZQiqU2l8eIi5"})),n(1,i=!0)}),[r,i,o]}class zc extends Se{constructor(t){super(),Pe(this,t,Cc,Nc,Te,{})}}export{zc as default,Dc as prerender};