File size: 154,149 Bytes
8518cc4
1
2
import{S as pe,i as me,s as _e,B as zn,C as Hn,D as Kn,E as Fn,f as M,t as B,H as Br,I as Xr,J as on,K as Ie,L as Se,m as U,h as x,n as g,b as Y,F,A as ge,k as q,v as le,a as he,l as j,w as ue,c as de,x as ce,y as fe,q as Ze,r as Qe,u as sn,g as ze,d as He,M as Xe,N as At,G as Te,O as Vn,o as Lt,P as Et,Q as ke,R as ho,T as or,U as po,e as We,V as mo,W as _o}from"../../chunks/index-9b9f3ff6.js";import{w as et}from"../../chunks/index-8910d5bb.js";var go=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},Re={},z={};Object.defineProperty(z,"__esModule",{value:!0});var vo=Object.defineProperty,yo=Object.defineProperties,wo=Object.getOwnPropertyDescriptors,Jt=Object.getOwnPropertySymbols,Yr=Object.prototype.hasOwnProperty,qr=Object.prototype.propertyIsEnumerable,sr=(e,t,n)=>t in e?vo(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ct=(e,t)=>{for(var n in t||(t={}))Yr.call(t,n)&&sr(e,n,t[n]);if(Jt)for(var n of Jt(t))qr.call(t,n)&&sr(e,n,t[n]);return e},an=(e,t)=>yo(e,wo(t)),bo=(e,t)=>{var n={};for(var r in e)Yr.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Jt)for(var r of Jt(e))t.indexOf(r)<0&&qr.call(e,r)&&(n[r]=e[r]);return n},ko=(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 Eo(e,t=e){}function xo(e,t,n=t){}function Oo(e){}function Io(e,t){}function Je(e,t){throw new Error(t)}function G(e,t="Expected value to be non-nullable"){return e}var jr=(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))(jr||{}),Gr=(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))(Gr||{}),Jr=(e=>(e[e.OBJECT=0]="OBJECT",e[e.LIST=1]="LIST",e[e.MAP=2]="MAP",e[e.REGISTER=3]="REGISTER",e))(Jr||{});function So(e){return e.type===0&&!Wr(e)}function Wr(e){return e.parentId!==void 0&&e.parentKey!==void 0}var Zr=(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))(Zr||{});function Po(e){return e==="my-presence"||e==="others"||e==="event"||e==="error"||e==="connection"||e==="history"}var Qr=(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))(Qr||{}),lt=32,Bn=126;function Ue(e,t){return e!==void 0&&t!==void 0?Wt(ei(mt(e),mt(t))):e!==void 0?Ao(e):t!==void 0?To(t):Wt([lt+1])}function To(e){const t=[],n=mt(e);for(let r=0;r<n.length;r++){const i=n[r];if(i<=lt+1){if(t.push(lt),n.length-1===r){t.push(Bn);break}}else{t.push(i-1);break}}return Wt(t)}function Ao(e){const t=[],n=mt(e);for(let r=0;r<n.length;r++){const i=n[r];if(i===Bn){if(t.push(i),n.length-1===r){t.push(lt+1);break}}else{t.push(i+1);break}}return Wt(t)}function ei(e,t){let n=0;const r=[];for(;;){const i=e[n]||lt,o=t[n]||Bn;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(...ei(e.slice(n+1),[]));break}const s=o+i>>1;r.push(s);break}return r}function mt(e){const t=[];for(let n=0;n<e.length;n++)t.push(e.charCodeAt(n));return t}function Wt(e){return String.fromCharCode(...e)}function ti(e,t){const n=mt(e),r=mt(t),i=Math.max(n.length,r.length);for(let o=0;o<i;o++){const s=n[o]===void 0?lt:n[o],a=r[o]===void 0?lt:r[o];if(s!==a)return s-a}throw new Error(`Impossible to compare similar position "${e}" and "${t}"`)}function ar(e,t){return Object.freeze({type:"HasParent",node:e,key:t})}var lr=Object.freeze({type:"NoParent"});function ur(e){return Object.freeze({type:"Orphaned",oldKey:e})}var ln=class{constructor(){this._parent=lr}_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 Je(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 Je(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 Je(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=ar(e,t);return;case"Orphaned":case"NoParent":{this._parent=ar(e,t);return}default:return Je(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=ur(this.parent.key);break}case"NoParent":{this._parent=lr;break}case"Orphaned":{this._parent=ur(this.parent.oldKey);break}default:Je(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}},je=class extends ln{constructor(e){super(),this._data=e}get data(){return this._data}static _deserialize([e,t],n,r){const i=new je(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:G(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}},tt=class extends ln{constructor(e){if(super(),this.unacknowledgedSet=new Map,e){const t=[];for(const n of e){const r=ht(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 tt;i._attach(e,r);const o=n.get(e);if(o===void 0)return i;for(const[s,a]of o){const l=ii([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)ve(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=wt(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=G(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=G(this._id),n=G(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:G(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 st(t)}set(e,t){const n=this._map.get(e);n&&n._detach();const r=ht(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,G(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=G(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=st(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:st(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 Xn(e)}},nt=class extends ln{constructor(e={}){super(),this._propToLastUpdate=new Map;for(const t in e){const n=e[t];n!==void 0&&ve(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)ve(a)?i.push(...a._toOps(this._id,s,n)):o.data[s]=a;return i}static _deserialize([e,t],n,r){const i=new nt(t.data);return i._attach(e,r),this._deserializeChildren(i,n,r)}static _deserializeChildren(e,t,n){const r=t.get(G(e._id));if(r===void 0)return e;for(const[i,o]of r){const s=No([i,o],t,n);Bt(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)ve(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=ni(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,G(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=G(this._id),a=this._map.get(i);let l;return ve(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(),Bt(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=G(this._id),n=G(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())ve(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)ve(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=G(this._id),i=[],o={type:3,id:r,data:{}};i.push(o);for(const a in e.data){const l=this._map.get(a);ve(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,G(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);ve(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=G(this._id);let i=[];return ve(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 Ko(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){ve(n)&&n._detach(),this._map.delete(t),this.invalidate();return}let r;ve(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);ve(c)&&c._detach(),ve(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(ve(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,ve(u)){u._setParentLink(this,l),u._attach(this._pool.generateId(),this._pool);const p=u._toOps(this._id,l,this._pool),d=p.find(m=>m.parentId===this._id);d&&this._propToLastUpdate.set(l,G(d.opId)),t.push(...p)}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]=Bt(n)?n.toImmutable():n;return e}},Xn=e=>e;function Lo(e){return e.filter(t=>t!=null)}function Co(e){const t=Ct({},e);return Object.keys(e).forEach(n=>{const r=n;t[r]===void 0&&delete t[r]}),t}function wt(e){return ht(ni(e))}function ni(e){switch(e.type){case 8:return e.data;case 4:return new nt(e.data);case 7:return new tt;case 2:return new rt;default:return Je(e,"Unknown creation Op")}}function ri(e,t){return e===t?!0:e.parent.type==="HasParent"?ri(e.parent.node,t):!1}function ii([e,t],n,r){switch(t.type){case 0:return nt._deserialize([e,t],n,r);case 1:return rt._deserialize([e,t],n,r);case 2:return tt._deserialize([e,t],n,r);case 3:return je._deserialize([e,t],n,r);default:throw new Error("Unexpected CRDT type")}}function No([e,t],n,r){switch(t.type){case 0:return nt._deserialize([e,t],n,r);case 1:return rt._deserialize([e,t],n,r);case 2:return tt._deserialize([e,t],n,r);case 3:return t.data;default:throw new Error("Unexpected CRDT type")}}function Bt(e){return oi(e)||Ro(e)||si(e)}function ve(e){return Bt(e)||$o(e)}function oi(e){return e instanceof rt}function Ro(e){return e instanceof tt}function si(e){return e instanceof nt}function $o(e){return e instanceof je}function st(e){return e instanceof je?e.data:e instanceof rt||e instanceof tt||e instanceof nt?e:Je(e,"Unknown AbstractCrdt")}function ht(e){return e instanceof nt||e instanceof tt||e instanceof rt?e:new je(e)}function Mo(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:G(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 Uo(e,t){const n=e.updates;for(const[r,i]of li(t.updates))n[r]=i;return an(Ct({},t),{updates:n})}function Do(e,t){const n=e.updates;for(const[r,i]of li(t.updates))n[r]=i;return an(Ct({},t),{updates:n})}function zo(e,t){const n=e.updates;return an(Ct({},t),{updates:n.concat(t.updates)})}function Ho(e,t){return e?e.type==="LiveObject"&&t.type==="LiveObject"?Uo(e,t):e.type==="LiveMap"&&t.type==="LiveMap"?Do(e,t):e.type==="LiveList"&&t.type==="LiveList"?zo(e,t):t:t}function cr(e){const t=typeof e;return e==null||t==="string"||t==="boolean"||t==="number"||Array.isArray(e)||Yn(e)}function Yn(e){return e!==null&&typeof e=="object"&&Object.prototype.toString.call(e)==="[object Object]"}function ai(e,t=""){if(!cr)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(!cr(r))return{path:i,value:r};if(typeof r=="object"){const o=ai(r,i);if(o)return o}}return!1}function Ko(e){const t={};for(const[n,r]of e)t[n]=r;return t}function li(e){return Object.entries(e)}function ui(e){try{return JSON.parse(e)}catch{return}}function ci(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 Fo(e,t){return ti(e._getParentKeyOrThrow(),t._getParentKeyOrThrow())}var rt=class extends ln{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=Ue(t),i=ht(e[n]);i._setParentLink(this,r),this._items.push(i),t=r}}static _deserialize([e],t,n){const r=new rt;r._attach(e,n);const i=t.get(e);if(i===void 0)return r;for(const[o,s]of i){const a=ii([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(Fo),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=wt(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:ee(this,[ft(o,r)]),reverse:[]};{this._implicitlyDeletedItems.add(s),this._items[o]=r;const a=[ft(o,r)],l=this._detachItemAssociatedToSetOperation(e.deletedId);return l&&a.push(l),{modified:ee(this,a),reverse:[]}}}else{const s=[],a=this._detachItemAssociatedToSetOperation(e.deletedId);return a&&s.push(a),this._insertAndSort(r),s.push(Me(this._indexOfPosition(n),r)),{reverse:[],modified:ee(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:ee(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?ee(this,t):!1,reverse:[]};i!==-1&&(this._implicitlyDeletedItems.add(this._items[i]),this._items.splice(i,1),t.push($t(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(it(s,a,o)),{modified:t.length>0?ee(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:ee(this,[i===-1?Me(a,s):ft(a,s),...t]),reverse:[]}}else{i!==-1&&this._items.splice(i,1);const{newItem:a,newIndex:l}=this._createAttachItemAndSort(e,e.parentKey);return{modified:ee(this,[i===-1?Me(l,a):ft(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:ee(this,[Me(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:ee(this,[it(i,o,t)]),reverse:[]}}}else{const i=G(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:ee(this,[Me(o,i)]),reverse:[]}}else{r!==-1&&this._shiftItemPosition(r,n);const{newItem:o,newIndex:s}=this._createAttachItemAndSort(e,n);return{modified:ee(this,[Me(s,o)]),reverse:[]}}}}_applyInsertUndoRedo(e){var t;const{id:n,parentKey:r}=e,i=wt(e);if(((t=this._pool)==null?void 0:t.getNode(n))!==void 0)return{modified:!1};i._attach(n,G(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=Ue(l,u),i._setParentLink(this,s)}this._insertAndSort(i);const a=this._indexOfPosition(s);return{modified:ee(this,[Me(a,i)]),reverse:[{type:5,id:n}]}}_applySetUndoRedo(e){var t;const{id:n,parentKey:r}=e,i=wt(e);if(((t=this._pool)==null?void 0:t.getNode(n))!==void 0)return{modified:!1};this._unacknowledgedSets.set(r,G(e.opId));const o=this._indexOfPosition(r);i._attach(n,G(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(G(this._id),r,this._pool);yn(l,e.id);const u=[ft(o,i)],c=this._detachItemAssociatedToSetOperation(e.deletedId);return c&&u.push(c),{modified:ee(this,u),reverse:l}}else{this._insertAndSort(i),this._detachItemAssociatedToSetOperation(e.deletedId);const a=this._indexOfPosition(s);return{reverse:[{type:5,id:n}],modified:ee(this,[Me(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=G(e._parentKey),n=e._toOps(G(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:ee(this,[$t(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:ee(this,[Me(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:ee(this,[it(o,s,t)]),reverse:[]}}else{this._items[i]._setParentLink(this,Ue(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:ee(this,[it(o,s,t)]),reverse:[]}}}_applySetChildKeyAck(e,t){var n,r;const i=G(t._parentKey);if(this._implicitlyDeletedItems.has(t)){const o=this._indexOfPosition(e);return this._implicitlyDeletedItems.delete(t),o!==-1&&this._items[o]._setParentLink(this,Ue(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,Ue(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:ee(this,[it(o,a,t)]),reverse:[]}}}_applySetChildKeyUndoRedo(e,t){var n;const r=G(t._parentKey),i=this._items.indexOf(t),o=this._indexOfPosition(e);o!==-1&&this._items[o]._setParentLink(this,Ue(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:ee(this,[it(i,s,t)]),reverse:[{type:1,id:G(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:G(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=Ue(n,r),o=ht(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,ee(this,[Me(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=Ue(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,ee(this,[it(e,t,o)])]]);this._pool.dispatch([{type:1,id:G(o._id),opId:this._pool.generateOpId(),parentKey:i}],[{type:1,id:G(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(G(this._id),ee(this,[$t(e)])),this._pool.dispatch([{id:n,opId:this._pool.generateOpId(),type:5}],t._toOps(G(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(G(this._id),i._getParentKeyOrThrow())),n.push($t(0)))}this._items=[],this.invalidate();const r=new Map;r.set(G(this._id),ee(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=ht(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,ee(this,[ft(e,o)]));const l=o._toOps(this._id,r,this._pool);yn(l,i),this._unacknowledgedSets.set(r,G(l[0].opId));const u=n._toOps(this._id,r,void 0);yn(u,s),this._pool.dispatch(l,u,a)}}toArray(){return this._items.map(e=>st(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 st(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(st(t),n))}some(e){return this.toArray().some(e)}[Symbol.iterator](){return new Vo(this._items)}_createAttachItemAndSort(e,t){const n=wt(e);n._attach(e.id,G(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=Ue(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())}},Vo=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:st(e.value)}}};function ee(e,t){return{node:e,type:"LiveList",updates:t}}function ft(e,t){return{index:e,type:"set",item:t instanceof je?t.data:t}}function $t(e){return{index:e,type:"delete"}}function Me(e,t){return{index:e,type:"insert",item:t instanceof je?t.data:t}}function it(e,t,n){return{index:t,type:"move",previousIndex:e,item:n instanceof je?n.data:n}}function yn(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 Bo=["websocket:presence","websocket:storage","room:read","room:write","rooms:read","rooms:write"];function Xo(e){if(!Yn(e))return!1;const{iat:t,exp:n}=e;return typeof t=="number"&&typeof n=="number"}function Yo(e){const t=Date.now()/1e3;return t>e.exp-300||t<e.iat+300}function qo(e){return Bo.includes(e)}function fi(e){return Array.isArray(e)&&e.every(t=>typeof t=="string")}function hi(e){return typeof e.appId=="string"&&e.roomId===void 0&&fi(e.scopes)}function qn(e){return typeof e.appId=="string"&&typeof e.roomId=="string"&&typeof e.actor=="number"&&(e.id===void 0||typeof e.id=="string")&&fi(e.scopes)&&(e.maxConnectionsPerRoom===void 0||typeof e.maxConnectionsPerRoom=="number")}function jo(e){return hi(e)||qn(e)}function Go(e){const t=e.split(".");if(t.length!==3)throw new Error("Authentication error: invalid JWT token");const n=ui(ci(t[1]));if(n&&Xo(n))return n;throw new Error("Authentication error: missing JWT metadata")}function Jo(e){const t=Go(e);if(t&&qn(t))return bo(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 Wo(e){return Object.defineProperty(e,"count",{value:e.length,enumerable:!1}),Object.defineProperty(e,"toArray",{value:()=>e,enumerable:!1}),Xn(e)}function di(e){return e===null||typeof e=="string"||typeof e=="number"||typeof e=="boolean"}function pi(e){return Array.isArray(e)}function Zo(e){return!di(e)&&!pi(e)}z.__spreadValues=Ct;z.__spreadProps=an;z.__async=ko;z.deprecate=Eo;z.deprecateIf=xo;z.throwUsageError=Oo;z.errorIf=Io;z.assertNever=Je;z.nn=G;z.ClientMsgCode=jr;z.OpCode=Gr;z.CrdtType=Jr;z.isRootCrdt=So;z.isChildCrdt=Wr;z.ServerMsgCode=Zr;z.isRoomEventName=Po;z.WebsocketCloseCodes=Qr;z.LiveRegister=je;z.makePosition=Ue;z.comparePosition=ti;z.LiveList=rt;z.LiveMap=tt;z.LiveObject=nt;z.freeze=Xn;z.compact=Lo;z.compactObject=Co;z.isSameNodeOrChildOf=ri;z.isLiveNode=ve;z.isLiveList=oi;z.isLiveObject=si;z.getTreesDiffOperations=Mo;z.mergeStorageUpdates=Ho;z.isPlainObject=Yn;z.findNonSerializableValue=ai;z.tryParseJson=ui;z.b64decode=ci;z.isTokenExpired=Yo;z.isScope=qo;z.isAppOnlyAuthToken=hi;z.isRoomAuthToken=qn;z.isAuthToken=jo;z.parseRoomAuthToken=Jo;z.asArrayWithLegacyMethods=Wo;z.isJsonScalar=di;z.isJsonArray=pi;z.isJsonObject=Zo;Object.defineProperty(Re,"__esModule",{value:!0});var R=z;function Ve(){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 mi(e,t){let n=!1;const r=R.__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 un=class{constructor(){this._ev=Ve()}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()}},Qo=class extends un{constructor(e){super(),this._me=R.freeze.call(void 0,R.compactObject.call(void 0,e))}_toImmutable(){return this._me}patch(e){const t=this._me,n=mi(t,e);t!==n&&(this._me=R.freeze.call(void 0,n),this.invalidate())}};function es(e,t){return R.freeze.call(void 0,R.compactObject.call(void 0,R.__spreadProps.call(void 0,R.__spreadValues.call(void 0,{},e),{presence:t})))}var ts=class extends un{constructor(){super(),this._connections={},this._presences={},this._users={}}_toImmutable(){const e=R.compact.call(void 0,Object.keys(this._presences).map(t=>this.getUser(Number(t))));return R.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 es(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]=R.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]=R.freeze.call(void 0,R.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=mi(n,t);n!==r&&(this._presences[e]=R.freeze.call(void 0,r),this._invalidateUser(e))}},ns=class extends un{constructor(e){super(),this._value=R.freeze.call(void 0,R.compactObject.call(void 0,e))}_toImmutable(){return this._value}set(e){this._value=R.freeze.call(void 0,e),this.invalidate()}},rs=class extends un{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)}},wn=[250,500,1e3,2e3,4e3,8e3,1e4],bn=[2e3,3e4,6e4,3e5],is=3e4,os=2e3;function ss(e){let t=0;return()=>`${e}:${t++}`}function kn(e){return e.state==="open"||e.state==="connecting"}function as(e,t,n){var r;const i=h=>h(),o=(r=t.unstable_batchedUpdates)!=null?r:i,s={roomId:t.roomId,getNode:h=>e.nodes.get(h),addNode:(h,v)=>void e.nodes.set(h,v),deleteNode:h=>void e.nodes.delete(h),generateId:()=>`${_()}:${e.clock++}`,generateOpId:()=>`${_()}:${e.opClock++}`,dispatch(h,v,E){const A=e.activeBatch;A?(A.ops.push(...h),E.forEach((N,re)=>{A.updates.storageUpdates.set(re,R.mergeStorageUpdates.call(void 0,A.updates.storageUpdates.get(re),N))}),A.reverseOps.push(...v)):o(()=>{k(v,i),e.redoStack=[],tr(h),O({storageUpdates:E},i)})}},a={customEvent:Ve(),me:Ve(),others:Ve(),error:Ve(),connection:Ve(),storage:Ve(),history:Ve(),storageDidLoad:Ve()},l=n||{authenticate(h,v){const E=e.token,A=E!==null&&R.parseRoomAuthToken.call(void 0,E);if(A&&!R.isTokenExpired.call(void 0,A)){const N=v(E);J(A,N)}else return h(t.roomId).then(({token:N})=>{if(e.connection.current.state!=="authenticating")return;const re=R.parseRoomAuthToken.call(void 0,N),Q=v(N);J(re,Q),e.token=N}).catch(N=>te())},send(h){if(e.socket===null)throw new Error("Can't send message if socket is null");e.socket.send(JSON.stringify(h))},delayFlush(h){return setTimeout(Ce,h)},startHeartbeatInterval(){return setInterval(we,is)},schedulePongTimeout(){return setTimeout(Le,os)},scheduleReconnect(h){return setTimeout(V,h)}},u=new rs([e.connection,e.me],(h,v)=>kn(h)?{connectionId:h.id,id:h.userId,info:h.userInfo,presence:v}:null);function c(h,v){if(h.items.length===0)throw new Error("Internal error: cannot load storage without items");e.root?d(h.items,v):e.root=m(h.items);for(const E in e.initialStorage)e.root.get(E)===void 0&&e.root.set(E,e.initialStorage[E])}function p(h){const v=new Map;let E=null;for(const[A,N]of h)if(R.isRootCrdt.call(void 0,N))E=[A,N];else{const re=[A,N],Q=v.get(N.parentId);Q!==void 0?Q.push(re):v.set(N.parentId,[re])}if(E===null)throw new Error("Root can't be null");return[E,v]}function d(h,v){if(!e.root)return;const E=new Map;e.nodes.forEach((re,Q)=>{E.set(Q,re._serialize())});const A=R.getTreesDiffOperations.call(void 0,E,new Map(h)),N=P(A,!1);O(N.updates,v)}function m(h){const[v,E]=p(h);return R.LiveObject._deserialize(v,E,s)}function b(h,v){e.undoStack.length>=50&&e.undoStack.shift(),e.undoStack.push(h),S(v)}function k(h,v){e.pausedHistory!==null?e.pausedHistory.unshift(...h):b(h,v)}function O({storageUpdates:h=new Map,presence:v=!1,others:E=[]},A){A(()=>{if(E.length>0){const N=e.others.current;for(const re of E)a.others.notify({others:N,event:re})}if(v&&a.me.notify(e.me.current),h.size>0){const N=Array.from(h.values());a.storage.notify(N)}})}function _(){const h=e.connection.current;if(kn(h))return h.id;if(e.lastConnectionId!==null)return e.lastConnectionId;throw new Error("Internal. Tried to get connection id but connection was never open")}function P(h,v){const E={reverse:[],updates:{storageUpdates:new Map,presence:!1}},A=new Set;for(const N of h)if(N.type==="presence"){const re={type:"presence",data:{}};for(const Q in N.data)re.data[Q]=e.me.current[Q];if(e.me.patch(N.data),e.buffer.me===null)e.buffer.me={type:"partial",data:N.data};else for(const Q in N.data)e.buffer.me.data[Q]=N.data[Q];E.reverse.unshift(re),E.updates.presence=!0}else{let re;N.opId||(N.opId=s.generateOpId()),v?re=0:re=e.offlineOperations.delete(R.nn.call(void 0,N.opId))?2:1;const Q=I(N,re);if(Q.modified){const vn=Q.modified.node.parent.type==="HasParent"?R.nn.call(void 0,Q.modified.node.parent.node._id,"Expected parent node to have an ID"):void 0;(!vn||!A.has(vn))&&(E.updates.storageUpdates.set(R.nn.call(void 0,Q.modified.node._id),R.mergeStorageUpdates.call(void 0,E.updates.storageUpdates.get(R.nn.call(void 0,Q.modified.node._id)),Q.modified)),E.reverse.unshift(...Q.reverse)),(N.type===2||N.type===7||N.type===4)&&A.add(R.nn.call(void 0,Q.modified.node._id))}}return E}function I(h,v){switch(h.type){case 6:case 3:case 5:{const E=e.nodes.get(h.id);return E===void 0?{modified:!1}:E._apply(h,v===0)}case 1:{const E=e.nodes.get(h.id);return E===void 0?{modified:!1}:E.parent.type==="HasParent"&&R.isLiveList.call(void 0,E.parent.node)?E.parent.node._setChildKey(h.parentKey,E,v):{modified:!1}}case 4:case 2:case 7:case 8:{if(h.parentId===void 0)return{modified:!1};const E=e.nodes.get(h.parentId);return E===void 0?{modified:!1}:E._attachChild(h,v)}}}function y(h,v){return a.storage.subscribe(E=>{const A=E.filter(N=>R.isSameNodeOrChildOf.call(void 0,N.node,h));A.length>0&&v(A)})}function D(h,v){return a.storage.subscribe(E=>{for(const A of E)A.node._id===h._id&&v(A.node)})}function H(h,v,E){if(typeof h=="string"&&R.isRoomEventName.call(void 0,h)){if(typeof v!="function")throw new Error("Second argument must be a callback function");const A=v;switch(h){case"event":return a.customEvent.subscribe(A);case"my-presence":return a.me.subscribe(A);case"others":{const N=A;return a.others.subscribe(({others:re,event:Q})=>N(re,Q))}case"error":return a.error.subscribe(A);case"connection":return a.connection.subscribe(A);case"storage":return a.storage.subscribe(A);case"history":return a.history.subscribe(A);default:return R.assertNever.call(void 0,h,"Unknown event")}}if(v===void 0||typeof h=="function")if(typeof h=="function"){const A=h;return a.storage.subscribe(A)}else throw new Error("Please specify a listener callback");if(R.isLiveNode.call(void 0,h)){const A=h;return E!=null&&E.isDeep?y(A,v):D(A,v)}throw new Error(`"${h}" is not a valid event name`)}function C(){return e.connection.current.state}function V(){var h,v,E,A;if(e.connection.current.state!=="closed"&&e.connection.current.state!=="unavailable")return null;const N=hs(t.authentication,(v=(h=t.polyfills)==null?void 0:h.fetch)!=null?v:t.fetchPolyfill),re=fs(t.liveblocksServer,(A=(E=t.polyfills)==null?void 0:E.WebSocket)!=null?A:t.WebSocketPolyfill);oe({state:"authenticating"},o),l.authenticate(N,re)}function X(h,v){const E={};e.buffer.me===null&&(e.buffer.me={type:"partial",data:{}});for(const A in h){const N=h[A];N!==void 0&&(e.buffer.me.data[A]=N,E[A]=e.me.current[A])}e.me.patch(h),e.activeBatch?(v!=null&&v.addToHistory&&e.activeBatch.reverseOps.push({type:"presence",data:E}),e.activeBatch.updates.presence=!0):(Ce(),o(()=>{v!=null&&v.addToHistory&&k([{type:"presence",data:E}],i),O({presence:!0},i)}))}function J(h,v){v.addEventListener("message",W),v.addEventListener("open",xe),v.addEventListener("close",Z),v.addEventListener("error",ye),oe({state:"connecting",id:h.actor,userInfo:h.info,userId:h.id},o),e.idFactory=ss(h.actor),e.socket=v}function te(h){e.token=null,oe({state:"unavailable"},o),e.numberOfRetry++,e.timeoutHandles.reconnect=l.scheduleReconnect(se())}function ae(h){h==="visible"&&e.connection.current.state==="open"&&we()}function be(h){if(h.targetActor!==void 0){const E=e.others.getUser(h.actor);e.others.setOther(h.actor,h.data);const A=e.others.getUser(h.actor);if(E===void 0&&A!==void 0)return{type:"enter",user:A}}else e.others.patchOther(h.actor,h.data);const v=e.others.getUser(h.actor);if(v)return{type:"update",updates:h.data,user:v}}function f(h){const v=e.others.getUser(h.actor);return v?(e.others.removeConnection(h.actor),{type:"leave",user:v}):null}function T(h){for(const v in h.users){const E=h.users[v],A=Number(v);e.others.setConnection(A,E.id,E.info)}return{type:"reset"}}function w(){e.connection.current.state==="unavailable"&&ct()}function S(h){h(()=>{a.history.notify({canUndo:rr(),canRedo:ir()})})}function L(h){e.others.setConnection(h.actor,h.id,h.info),e.buffer.messages.push({type:100,data:e.me.current,targetActor:h.actor}),Ce();const v=e.others.getUser(h.actor);return v?{type:"enter",user:v}:void 0}function $(h){return R.isJsonObject.call(void 0,h)?h:null}function K(h){const v=R.tryParseJson.call(void 0,h);return v===void 0?null:R.isJsonArray.call(void 0,v)?R.compact.call(void 0,v.map(E=>$(E))):R.compact.call(void 0,[$(v)])}function W(h){if(h.data==="pong"){clearTimeout(e.timeoutHandles.pongTimeout);return}const v=K(h.data);if(v===null||v.length===0)return;const E={storageUpdates:new Map,others:[]};o(()=>{for(const A of v)switch(A.type){case 101:{const N=L(A);N&&E.others.push(N);break}case 100:{const N=be(A);N&&E.others.push(N);break}case 103:{a.customEvent.notify({connectionId:A.actor,event:A.event});break}case 102:{const N=f(A);N&&E.others.push(N);break}case 104:{E.others.push(T(A));break}case 200:{const N=new Map(e.offlineOperations);c(A,i),Wi(N,i),gn==null||gn(),a.storageDidLoad.notify();break}case 201:{P(A.ops,!1).updates.storageUpdates.forEach((re,Q)=>{E.storageUpdates.set(Q,R.mergeStorageUpdates.call(void 0,E.storageUpdates.get(Q),re))});break}}O(E,i)})}function Z(h){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(O({others:[{type:"reset"}]},i),h.code>=4e3&&h.code<=4100){oe({state:"failed"},i);const v=new cs(h.reason,h.code);a.error.notify(v);const E=se(!0);e.numberOfRetry++,oe({state:"unavailable"},i),e.timeoutHandles.reconnect=l.scheduleReconnect(E)}else if(h.code===4999)oe({state:"closed"},i);else{const v=se();e.numberOfRetry++,oe({state:"unavailable"},i),e.timeoutHandles.reconnect=l.scheduleReconnect(v)}})}function oe(h,v){e.connection.set(h),v(()=>{a.connection.notify(h.state)})}function se(h=!1){return h?bn[e.numberOfRetry<bn.length?e.numberOfRetry:bn.length-1]:wn[e.numberOfRetry<wn.length?e.numberOfRetry:wn.length-1]}function ye(){}function xe(){clearInterval(e.intervalHandles.heartbeat),e.intervalHandles.heartbeat=l.startHeartbeatInterval(),e.connection.current.state==="connecting"&&(oe(R.__spreadProps.call(void 0,R.__spreadValues.call(void 0,{},e.connection.current),{state:"open"}),o),e.numberOfRetry=0,e.lastConnectionId!==void 0&&(e.buffer.me={type:"full",data:R.__spreadValues.call(void 0,{},e.me.current)},Ce()),e.lastConnectionId=e.connection.current.id,e.root&&e.buffer.messages.push({type:200}),Ce())}function we(){e.socket!==null&&(clearTimeout(e.timeoutHandles.pongTimeout),e.timeoutHandles.pongTimeout=l.schedulePongTimeout(),e.socket.readyState===e.socket.OPEN&&e.socket.send("ping"))}function Le(){ct()}function ct(){e.socket&&(e.socket.removeEventListener("open",xe),e.socket.removeEventListener("message",W),e.socket.removeEventListener("close",Z),e.socket.removeEventListener("error",ye),e.socket.close(),e.socket=null),oe({state:"unavailable"},o),clearTimeout(e.timeoutHandles.pongTimeout),e.timeoutHandles.flush&&clearTimeout(e.timeoutHandles.flush),clearTimeout(e.timeoutHandles.reconnect),clearInterval(e.intervalHandles.heartbeat),V()}function Wi(h,v){if(h.size===0)return;const E=[],A=Array.from(h.values()),N=P(A,!0);E.push({type:201,ops:A}),O(N.updates,v),l.send(E)}function Ce(){const h=e.buffer.storageOperations;if(h.length>0&&h.forEach(A=>{e.offlineOperations.set(R.nn.call(void 0,A.opId),A)}),e.socket===null||e.socket.readyState!==e.socket.OPEN){e.buffer.storageOperations=[];return}const v=Date.now();if(v-e.lastFlushTime>t.throttleDelay){const A=Zi(e);if(A.length===0)return;l.send(A),e.buffer={messages:[],storageOperations:[],me:null},e.lastFlushTime=v}else e.timeoutHandles.flush!==null&&clearTimeout(e.timeoutHandles.flush),e.timeoutHandles.flush=l.delayFlush(t.throttleDelay-(v-e.lastFlushTime))}function Zi(h){const v=[];h.buffer.me&&v.push(h.buffer.me.type==="full"?{type:100,targetActor:-1,data:h.buffer.me.data}:{type:100,data:h.buffer.me.data});for(const E of h.buffer.messages)v.push(E);return h.buffer.storageOperations.length>0&&v.push({type:201,ops:h.buffer.storageOperations}),v}function Qi(){e.socket&&(e.socket.removeEventListener("open",xe),e.socket.removeEventListener("message",W),e.socket.removeEventListener("close",Z),e.socket.removeEventListener("error",ye),e.socket.close(),e.socket=null),o(()=>{oe({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(),O({others:[{type:"reset"}]},i),Object.values(a).forEach(h=>h.clear())})}function eo(){return e.me.current}function to(){return e.others.current}function no(h,v={shouldQueueEventIfNotReady:!1}){e.socket===null&&!v.shouldQueueEventIfNotReady||(e.buffer.messages.push({type:103,event:h}),Ce())}function tr(h){e.buffer.storageOperations.push(...h),Ce()}let _n=null,gn=null;function nr(){return _n===null&&(e.buffer.messages.push({type:200}),Ce(),_n=new Promise(h=>gn=h)),_n}function ro(){const h=e.root;return h!==void 0?h:(nr(),null)}function io(){return R.__async.call(void 0,this,null,function*(){return e.root?Promise.resolve({root:e.root}):(yield nr(),{root:R.nn.call(void 0,e.root)})})}function oo(){if(e.activeBatch)throw new Error("undo is not allowed during a batch");const h=e.undoStack.pop();if(h===void 0)return;e.pausedHistory=null;const v=P(h,!0);o(()=>{O(v.updates,i),e.redoStack.push(v.reverse),S(i)});for(const E of h)E.type!=="presence"&&e.buffer.storageOperations.push(E);Ce()}function rr(){return e.undoStack.length>0}function so(){if(e.activeBatch)throw new Error("redo is not allowed during a batch");const h=e.redoStack.pop();if(h===void 0)return;e.pausedHistory=null;const v=P(h,!0);o(()=>{O(v.updates,i),e.undoStack.push(v.reverse),S(i)});for(const E of h)E.type!=="presence"&&e.buffer.storageOperations.push(E);Ce()}function ir(){return e.redoStack.length>0}function ao(h){if(e.activeBatch)return h();let v;return o(()=>{e.activeBatch={ops:[],updates:{storageUpdates:new Map,presence:!1,others:[]},reverseOps:[]};try{v=h()}finally{const E=e.activeBatch;e.activeBatch=null,E.reverseOps.length>0&&k(E.reverseOps,i),E.ops.length>0&&(e.redoStack=[]),E.ops.length>0&&tr(E.ops),O(E.updates,i),Ce()}}),v}function lo(){e.pausedHistory=[]}function uo(){const h=e.pausedHistory;e.pausedHistory=null,h!==null&&h.length>0&&b(h,o)}function co(){e.socket&&(e.socket=null)}function fo(h){Z(h)}return{onClose:Z,onMessage:W,authenticationSuccess:J,heartbeat:we,onNavigatorOnline:w,simulateSocketClose:co,simulateSendCloseEvent:fo,onVisibilityChange:ae,getUndoStack:()=>e.undoStack,getItemsCount:()=>e.nodes.size,connect:V,disconnect:Qi,subscribe:H,updatePresence:X,broadcastEvent:no,batch:ao,undo:oo,redo:so,canUndo:rr,canRedo:ir,pauseHistory:lo,resumeHistory:uo,getStorage:io,getStorageSnapshot:ro,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:C,isSelfAware:()=>kn(e.connection.current),getSelf:()=>u.current,getPresence:eo,getOthers:to}}function ls(e,t){const n=new ts,r=new ns({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 Qo(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 us(e,t){const{initialPresence:n,initialStorage:r}=e,i=ls(typeof n=="function"?n(t.roomId):n,typeof r=="function"?r(t.roomId):r),o=as(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 cs=class extends Error{constructor(e,t){super(e),this.code=t}};function fs(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 hs(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=>fr(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=>fr(t||fetch,e.url,{room:n})}if(e.type==="custom")return n=>R.__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 fr(e,t,n){return R.__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 En(`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 En(`Expected a JSON response when doing a POST request on "${t}". ${s}`)}if(!R.isPlainObject.call(void 0,i)||typeof i.token!="string")throw new En(`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 En=class extends Error{constructor(e){super(e)}};function ds(e){const t=e,n=ps(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 p=r.get(a);if(p)return p.room;if(R.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."),p=us({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:ms(t,a)}),r.set(a,p),!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");go.atob=t.polyfills.atob}p.connect()}return p.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 ps(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 ms(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:_s(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 _s(e,t){return e.publicAuthorizeEndpoint?e.publicAuthorizeEndpoint.replace("{roomId}",t):`https://api.liveblocks.io/v2/rooms/${encodeURIComponent(t)}/public/authorize`}function gs(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 vs(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 ys(e,t){if(Object.is(e,t))return!0;const n=Array.isArray(e),r=Array.isArray(t);return n||r?!n||!r?!1:gs(e,t):vs(e,t)}Re.LiveList=R.LiveList;Re.LiveMap=R.LiveMap;Re.LiveObject=R.LiveObject;Re.createClient=ds;Re.shallow=ys;Re.LiveList;Re.LiveMap;const ws=Re.LiveObject,bs=Re.createClient;Re.shallow;const _i=Symbol(),gi=Symbol();function ks(e){let t;const n=e[2].default,r=zn(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)&&Hn(r,n,i,i[1],t?Fn(n,i[1],o,null):Kn(i[1]),null)},i(i){t||(M(r,i),t=!0)},o(i){B(r,i),t=!1},d(i){r&&r.d(i)}}}function Es(e,t,n){let{$$slots:r={},$$scope:i}=t,{client:o}=t;if(!o)throw new Error("LiveblocksProvider requires a client");return Br(_i,o),e.$$set=s=>{"client"in s&&n(0,o=s.client),"$$scope"in s&&n(1,i=s.$$scope)},[o,i,r]}class xs extends pe{constructor(t){super(),me(this,t,Es,ks,_e,{client:0})}}function Os(e){let t;const n=e[3].default,r=zn(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)&&Hn(r,n,i,i[2],t?Fn(n,i[2],o,null):Kn(i[2]),null)},i(i){t||(M(r,i),t=!0)},o(i){B(r,i),t=!1},d(i){r&&r.d(i)}}}function Is(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=Xr(_i);if(a){const l=a.enter(o,s());Br(gi,l),on(()=>{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 Ss extends pe{constructor(t){super(),me(this,t,Is,Os,_e,{id:0,defaultPresence:1})}}function Ps(e){let t,n;return{c(){t=Ie("svg"),n=Ie("path"),this.h()},l(r){t=Se(r,"svg",{class:!0,width:!0,viewBox:!0,fill:!0,xmlns:!0});var i=U(t);n=Se(i,"path",{d:!0,fill:!0}),U(n).forEach(x),i.forEach(x),this.h()},h(){g(n,"d","M0.91603 0.916054L7.09131 14.9234L8.89871 8.89873L14.9234 7.09133L0.91603 0.916054Z"),g(n,"fill","#FFB800"),g(t,"class",e[0]),g(t,"width","40"),g(t,"viewBox","0 0 15 15"),g(t,"fill","currentColor"),g(t,"xmlns","http://www.w3.org/2000/svg")},m(r,i){Y(r,t,i),F(t,n)},p(r,[i]){i&1&&g(t,"class",r[0])},i:ge,o:ge,d(r){r&&x(t)}}}function Ts(e,t,n){let{classList:r=""}=t;return e.$$set=i=>{"classList"in i&&n(0,r=i.classList)},[r]}class As extends pe{constructor(t){super(),me(this,t,Ts,Ps,_e,{classList:0})}}function hr(e){let t,n,r;return{c(){t=q("div"),n=Ze(e[2]),this.h()},l(i){t=j(i,"DIV",{class:!0,style:!0});var o=U(t);n=Qe(o,e[2]),o.forEach(x),this.h()},h(){g(t,"class","absolute right-0 text-4xl col-start-2 row-start-2"),g(t,"style",r=`text-shadow: 0px 5px 5px ${e[1]}`)},m(i,o){Y(i,t,o),F(t,n)},p(i,o){o&4&&sn(n,i[2]),o&2&&r!==(r=`text-shadow: 0px 5px 5px ${i[1]}`)&&g(t,"style",r)},d(i){i&&x(t)}}}function Ls(e){let t,n,r,i,o;n=new As({props:{classList:"block z-0 col-span-2 row-span-2"}});let s=e[2]&&hr(e);return{c(){t=q("div"),le(n.$$.fragment),r=he(),s&&s.c(),this.h()},l(a){t=j(a,"DIV",{class:!0,style:!0});var l=U(t);ue(n.$$.fragment,l),r=de(l),s&&s.l(l),l.forEach(x),this.h()},h(){g(t,"class","cursor svelte-14ka0w3"),g(t,"style",i=`transform: translateX(${e[3].x}px) translateY(${e[3].y}px) scale(${e[0].k});`)},m(a,l){Y(a,t,l),ce(n,t,null),F(t,r),s&&s.m(t,null),o=!0},p(a,[l]){a[2]?s?s.p(a,l):(s=hr(a),s.c(),s.m(t,null)):s&&(s.d(1),s=null),(!o||l&9&&i!==(i=`transform: translateX(${a[3].x}px) translateY(${a[3].y}px) scale(${a[0].k});`))&&g(t,"style",i)},i(a){o||(M(n.$$.fragment,a),o=!0)},o(a){B(n.$$.fragment,a),o=!1},d(a){a&&x(t),fe(n),s&&s.d()}}}function Cs(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 Ns extends pe{constructor(t){super(),me(this,t,Cs,Ls,_e,{transform:0,color:1,emoji:2,position:4})}}function Rs(e){let t,n,r;return{c(){t=Ie("svg"),n=Ie("path"),r=Ie("path"),this.h()},l(i){t=Se(i,"svg",{class:!0,width:!0,height:!0,viewBox:!0,fill:!0,xmlns:!0});var o=U(t);n=Se(o,"path",{d:!0,fill:!0}),U(n).forEach(x),r=Se(o,"path",{d:!0,fill:!0}),U(r).forEach(x),o.forEach(x),this.h()},h(){g(n,"d","M21 10.5C21 4.70101 16.299 0 10.5 0C4.70101 0 0 4.70101 0 10.5C0 16.299 4.70101 21 10.5 21C16.299 21 21 16.299 21 10.5Z"),g(n,"fill","white"),g(r,"d","M10.5006 17C9.6233 17 8.77136 16.8286 7.97021 16.4896C7.19572 16.1621 6.50122 15.6924 5.90448 15.0957C5.30774 14.499 4.83797 13.8046 4.5104 13.0302C4.1714 12.2291 4 11.3772 4 10.5C4 10.2474 4.20441 10.043 4.45708 10.043C4.70974 10.043 4.91415 10.2474 4.91415 10.5C4.91415 11.2541 5.06143 11.9854 5.35345 12.6747C5.63532 13.3399 6.0378 13.9379 6.55074 14.4508C7.06368 14.9637 7.66169 15.3674 8.32698 15.6479C9.01514 15.9387 9.74646 16.0859 10.5006 16.0859C11.2548 16.0859 11.9861 15.9387 12.6756 15.6467C13.3409 15.3648 13.9389 14.9624 14.4518 14.4495C14.9647 13.9366 15.3685 13.3387 15.6491 12.6734C15.9398 11.9854 16.0871 11.2541 16.0871 10.5C16.0871 9.7459 15.9398 9.01465 15.6478 8.32529C15.3669 7.66166 14.9604 7.05857 14.4505 6.54922C13.9417 6.03876 13.3384 5.63215 12.6743 5.35205C11.9861 5.06133 11.2548 4.91406 10.5006 4.91406C10.248 4.91406 10.0436 4.70967 10.0436 4.45703C10.0436 4.20439 10.248 4 10.5006 4C11.378 4 12.2299 4.17139 13.0311 4.51035C13.8055 4.83789 14.5 5.30762 15.0968 5.9043C15.6935 6.50098 16.162 7.19668 16.4896 7.96982C16.8286 8.7709 17 9.62275 17 10.5C17 11.3772 16.8286 12.2291 16.4896 13.0302C16.1633 13.8046 15.6935 14.499 15.0968 15.0957C14.5 15.6924 13.8043 16.1608 13.0311 16.4884C12.2299 16.8286 11.378 17 10.5006 17Z"),g(r,"fill","currentColor"),g(t,"class","animate-spin"),g(t,"width","51"),g(t,"height","51"),g(t,"viewBox","0 0 21 21"),g(t,"fill","none"),g(t,"xmlns","http://www.w3.org/2000/svg")},m(i,o){Y(i,t,o),F(t,n),F(t,r)},p:ge,i:ge,o:ge,d(i){i&&x(t)}}}class vi extends pe{constructor(t){super(),me(this,t,null,Rs,_e,{})}}function dr(e){let t,n,r;return n=new vi({}),{c(){t=q("div"),le(n.$$.fragment),this.h()},l(i){t=j(i,"DIV",{class:!0});var o=U(t);ue(n.$$.fragment,o),o.forEach(x),this.h()},h(){g(t,"class","absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2")},m(i,o){Y(i,t,o),ce(n,t,null),r=!0},i(i){r||(M(n.$$.fragment,i),r=!0)},o(i){B(n.$$.fragment,i),r=!1},d(i){i&&x(t),fe(n)}}}function $s(e){let t,n,r,i,o,s,a,l=e[2]&&dr();return{c(){t=q("div"),n=q("div"),r=q("div"),i=Ze(e[1]),o=he(),l&&l.c(),this.h()},l(u){t=j(u,"DIV",{class:!0,style:!0});var c=U(t);n=j(c,"DIV",{class:!0});var p=U(n);r=j(p,"DIV",{class:!0});var d=U(r);i=Qe(d,e[1]),d.forEach(x),p.forEach(x),o=de(c),l&&l.l(c),c.forEach(x),this.h()},h(){g(r,"class","font-bold text-xl text-[#EC8E65] text-center px-2 line-clamp-4"),g(n,"class","pointer-events-none touch-none"),g(t,"class","frame @apply absolute top-0 left-0 ring-8 ring-[#EC8E65] w-[512px] h-[512px]"),g(t,"style",s=`transform: translateX(${e[3].x}px) translateY(${e[3].y}px) scale(${e[0].k}); transform-origin: 0 0;`)},m(u,c){Y(u,t,c),F(t,n),F(n,r),F(r,i),F(t,o),l&&l.m(t,null),a=!0},p(u,[c]){(!a||c&2)&&sn(i,u[1]),u[2]?l?c&4&&M(l,1):(l=dr(),l.c(),M(l,1),l.m(t,null)):l&&(ze(),B(l,1,1,()=>{l=null}),He()),(!a||c&9&&s!==(s=`transform: translateX(${u[3].x}px) translateY(${u[3].y}px) scale(${u[0].k}); transform-origin: 0 0;`))&&g(t,"style",s)},i(u){a||(M(l),a=!0)},o(u){B(l),a=!1},d(u){u&&x(t),l&&l.d()}}}function Ms(e,t,n){let r,{transform:i}=t,{position:o={x:0,y:0}}=t,{prompt:s=""}=t,{isLoading:a=!1}=t;return e.$$set=l=>{"transform"in l&&n(0,i=l.transform),"position"in l&&n(4,o=l.position),"prompt"in l&&n(1,s=l.prompt),"isLoading"in l&&n(2,a=l.isLoading)},e.$$.update=()=>{e.$$.dirty&17&&n(3,r={x:i.applyX(o.x),y:i.applyY(o.y)})},[i,s,a,r,o]}class Us extends pe{constructor(t){super(),me(this,t,Ms,$s,_e,{transform:0,position:4,prompt:1,isLoading:2})}}function Ds(e){let t,n,r,i,o;return{c(){t=q("span"),n=Ze("+"),r=he(),i=q("span"),o=Ze("Prompt + Paint"),this.h()},l(s){t=j(s,"SPAN",{class:!0});var a=U(t);n=Qe(a,"+"),a.forEach(x),r=de(s),i=j(s,"SPAN",{});var l=U(i);o=Qe(l,"Prompt + Paint"),l.forEach(x),this.h()},h(){g(t,"class","rounded-sm h-6 w-6 flex justify-center items-center border-2 border-dashed border-violet-700 mr-2")},m(s,a){Y(s,t,a),F(t,n),Y(s,r,a),Y(s,i,a),F(i,o)},d(s){s&&x(t),s&&x(r),s&&x(i)}}}function zs(e){let t,n;return{c(){t=q("span"),n=Ze("paiting..."),this.h()},l(r){t=j(r,"SPAN",{class:!0});var i=U(t);n=Qe(i,"paiting..."),i.forEach(x),this.h()},h(){g(t,"class","font-mono")},m(r,i){Y(r,t,i),F(t,n)},d(r){r&&x(t)}}}function Hs(e){let t,n,r;function i(a,l){return a[0]?zs:Ds}let o=i(e),s=o(e);return{c(){t=q("button"),s.c(),this.h()},l(a){t=j(a,"BUTTON",{class:!0,title:!0});var l=U(t);s.l(l),l.forEach(x),this.h()},h(){t.disabled=e[0],g(t,"class","button-paint bg-violet-100 text-violet-900 min-w-[25ch]  svelte-mnpqkm"),g(t,"title","New Paint Frame")},m(a,l){Y(a,t,l),s.m(t,null),n||(r=Xe(t,"click",e[1]),n=!0)},p(a,[l]){o!==(o=i(a))&&(s.d(1),s=o(a),s&&(s.c(),s.m(t,null))),l&1&&(t.disabled=a[0])},i:ge,o:ge,d(a){a&&x(t),s.d(),n=!1,r()}}}function Ks(e,t,n){let{isLoading:r=!1}=t;function i(o){At.call(this,e,o)}return e.$$set=o=>{"isLoading"in o&&n(0,r=o.isLoading)},[r,i]}class yi extends pe{constructor(t){super(),me(this,t,Ks,Hs,_e,{isLoading:0})}}function Fs(e){let t,n;return{c(){t=Ie("svg"),n=Ie("path"),this.h()},l(r){t=Se(r,"svg",{class:!0,width:!0,height:!0,viewBox:!0,fill:!0,xmlns:!0});var i=U(t);n=Se(i,"path",{d:!0,stroke:!0,"stroke-width":!0,"stroke-linecap":!0,"stroke-linejoin":!0}),U(n).forEach(x),i.forEach(x),this.h()},h(){g(n,"d","M2.4 4.26667L1 5.66667L2.4 7.06667M4.26667 2.4L5.66667 1L7.06667 2.4M7.06667 8.93333L5.66667 10.3333L4.26667 8.93333M8.93333 4.26667L10.3333 5.66667L8.93333 7.06667M1 5.66667H10.3333M5.66667 1V10.3333"),g(n,"stroke","currentColor"),g(n,"stroke-width","0.933333"),g(n,"stroke-linecap","round"),g(n,"stroke-linejoin","round"),g(t,"class",e[0]),g(t,"width","20"),g(t,"height","20"),g(t,"viewBox","0 0 11 11"),g(t,"fill","none"),g(t,"xmlns","http://www.w3.org/2000/svg")},m(r,i){Y(r,t,i),F(t,n)},p(r,[i]){i&1&&g(t,"class",r[0])},i:ge,o:ge,d(r){r&&x(t)}}}function Vs(e,t,n){let{classList:r=""}=t;return e.$$set=i=>{"classList"in i&&n(0,r=i.classList)},[r]}class Bs extends pe{constructor(t){super(),me(this,t,Vs,Fs,_e,{classList:0})}}function Xs(e){let t,n,r,i,o,s;return n=new Bs({}),{c(){t=q("button"),le(n.$$.fragment),this.h()},l(a){t=j(a,"BUTTON",{class:!0,title:!0});var l=U(t);ue(n.$$.fragment,l),l.forEach(x),this.h()},h(){t.disabled=e[1],g(t,"class",r="bg-white rounded-full p-2 "+(e[0]?"text-blue-700":"text-gray-800")),g(t,"title","Enable Dragging")},m(a,l){Y(a,t,l),ce(n,t,null),i=!0,o||(s=Xe(t,"click",e[2]),o=!0)},p(a,[l]){(!i||l&2)&&(t.disabled=a[1]),(!i||l&1&&r!==(r="bg-white rounded-full p-2 "+(a[0]?"text-blue-700":"text-gray-800")))&&g(t,"class",r)},i(a){i||(M(n.$$.fragment,a),i=!0)},o(a){B(n.$$.fragment,a),i=!1},d(a){a&&x(t),fe(n),o=!1,s()}}}function Ys(e,t,n){let{isActive:r=!1}=t,{isLoading:i=!1}=t;function o(s){At.call(this,e,s)}return e.$$set=s=>{"isActive"in s&&n(0,r=s.isActive),"isLoading"in s&&n(1,i=s.isLoading)},[r,i,o]}class qs extends pe{constructor(t){super(),me(this,t,Ys,Xs,_e,{isActive:0,isLoading:1})}}function js(e){let t,n,r;return{c(){t=Ie("svg"),n=Ie("path"),r=Ie("path"),this.h()},l(i){t=Se(i,"svg",{class:!0,width:!0,height:!0,viewBox:!0,fill:!0,xmlns:!0});var o=U(t);n=Se(o,"path",{d:!0,stroke:!0,"stroke-width":!0}),U(n).forEach(x),r=Se(o,"path",{d:!0,stroke:!0,"stroke-width":!0,"stroke-linecap":!0,"stroke-linejoin":!0}),U(r).forEach(x),o.forEach(x),this.h()},h(){g(n,"d","M5.5 10C7.98528 10 10 7.98528 10 5.5C10 3.01472 7.98528 1 5.5 1C3.01472 1 1 3.01472 1 5.5C1 7.98528 3.01472 10 5.5 10Z"),g(n,"stroke","currentColor"),g(n,"stroke-width","0.899979"),g(r,"d","M7.07441 1.28369C5.36599 1.92179 4.14941 3.56879 4.14941 5.50019C4.14941 7.43137 5.36599 9.07837 7.07441 9.71669M8.42441 2.12519L4.14941 5.05019M9.32441 3.25019L4.37441 6.62519M9.77441 4.60019L5.04941 7.97519M9.77441 6.40019L5.94941 9.10019"),g(r,"stroke","currentColor"),g(r,"stroke-width","0.899979"),g(r,"stroke-linecap","round"),g(r,"stroke-linejoin","round"),g(t,"class",e[0]),g(t,"width","20"),g(t,"height","20"),g(t,"viewBox","0 0 11 11"),g(t,"fill","none"),g(t,"xmlns","http://www.w3.org/2000/svg")},m(i,o){Y(i,t,o),F(t,n),F(t,r)},p(i,[o]){o&1&&g(t,"class",i[0])},i:ge,o:ge,d(i){i&&x(t)}}}function Gs(e,t,n){let{classList:r=""}=t;return e.$$set=i=>{"classList"in i&&n(0,r=i.classList)},[r]}class Js extends pe{constructor(t){super(),me(this,t,Gs,js,_e,{classList:0})}}function Ws(e){let t,n,r,i,o,s;return n=new Js({}),{c(){t=q("button"),le(n.$$.fragment),this.h()},l(a){t=j(a,"BUTTON",{class:!0,title:!0});var l=U(t);ue(n.$$.fragment,l),l.forEach(x),this.h()},h(){t.disabled=e[1],g(t,"class",r="bg-white rounded-full p-2 "+(e[0]?"text-blue-700":"text-gray-800")),g(t,"title","Enable Masking")},m(a,l){Y(a,t,l),ce(n,t,null),i=!0,o||(s=Xe(t,"click",e[2]),o=!0)},p(a,[l]){(!i||l&2)&&(t.disabled=a[1]),(!i||l&1&&r!==(r="bg-white rounded-full p-2 "+(a[0]?"text-blue-700":"text-gray-800")))&&g(t,"class",r)},i(a){i||(M(n.$$.fragment,a),i=!0)},o(a){B(n.$$.fragment,a),i=!1},d(a){a&&x(t),fe(n),o=!1,s()}}}function Zs(e,t,n){let{isActive:r=!1}=t,{isLoading:i=!1}=t;function o(s){At.call(this,e,s)}return e.$$set=s=>{"isActive"in s&&n(0,r=s.isActive),"isLoading"in s&&n(1,i=s.isLoading)},[r,i,o]}class Qs extends pe{constructor(t){super(),me(this,t,Zs,Ws,_e,{isActive:0,isLoading:1})}}function ea(e){let t,n,r;return{c(){t=Ie("svg"),n=Ie("g"),r=Ie("path"),this.h()},l(i){t=Se(i,"svg",{class:!0,width:!0,height:!0,viewBox:!0,fill:!0,xmlns:!0});var o=U(t);n=Se(o,"g",{opacity:!0});var s=U(n);r=Se(s,"path",{d:!0,fill:!0,stroke:!0,"stroke-width":!0,"stroke-linejoin":!0}),U(r).forEach(x),s.forEach(x),o.forEach(x),this.h()},h(){g(r,"d","M6.33333 2.66667H2.27167L3.46733 1.47133L3 1L1 3L3 5L3.46733 4.52833L2.27267 3.33333H6.33333C6.86377 3.33333 7.37247 3.54405 7.74755 3.91912C8.12262 4.29419 8.33333 4.8029 8.33333 5.33333C8.33333 5.86377 8.12262 6.37247 7.74755 6.74755C7.37247 7.12262 6.86377 7.33333 6.33333 7.33333H3.66667V8H6.33333C7.04058 8 7.71885 7.71905 8.21895 7.21895C8.71905 6.71885 9 6.04058 9 5.33333C9 4.62609 8.71905 3.94781 8.21895 3.44772C7.71885 2.94762 7.04058 2.66667 6.33333 2.66667Z"),g(r,"fill","black"),g(r,"stroke","black"),g(r,"stroke-width","0.5"),g(r,"stroke-linejoin","round"),g(n,"opacity","0.5"),g(t,"class",e[0]),g(t,"width","20"),g(t,"height","19"),g(t,"viewBox","0 0 10 9"),g(t,"fill","none"),g(t,"xmlns","http://www.w3.org/2000/svg")},m(i,o){Y(i,t,o),F(t,n),F(n,r)},p(i,[o]){o&1&&g(t,"class",i[0])},i:ge,o:ge,d(i){i&&x(t)}}}function ta(e,t,n){let{classList:r=""}=t;return e.$$set=i=>{"classList"in i&&n(0,r=i.classList)},[r]}class na extends pe{constructor(t){super(),me(this,t,ta,ea,_e,{classList:0})}}function ra(e){let t,n,r,i,o,s;return n=new na({}),{c(){t=q("button"),le(n.$$.fragment),this.h()},l(a){t=j(a,"BUTTON",{class:!0,title:!0});var l=U(t);ue(n.$$.fragment,l),l.forEach(x),this.h()},h(){t.disabled=e[1],g(t,"class",r="bg-white rounded-full p-2 "+(e[0]?"text-blue-700":"text-gray-800")),g(t,"title","Clear Masking")},m(a,l){Y(a,t,l),ce(n,t,null),i=!0,o||(s=Xe(t,"click",e[2]),o=!0)},p(a,[l]){(!i||l&2)&&(t.disabled=a[1]),(!i||l&1&&r!==(r="bg-white rounded-full p-2 "+(a[0]?"text-blue-700":"text-gray-800")))&&g(t,"class",r)},i(a){i||(M(n.$$.fragment,a),i=!0)},o(a){B(n.$$.fragment,a),i=!1},d(a){a&&x(t),fe(n),o=!1,s()}}}function ia(e,t,n){let{isActive:r=!1}=t,{isLoading:i=!1}=t;function o(s){At.call(this,e,s)}return e.$$set=s=>{"isActive"in s&&n(0,r=s.isActive),"isLoading"in s&&n(1,i=s.isLoading)},[r,i,o]}class oa extends pe{constructor(t){super(),me(this,t,ia,ra,_e,{isActive:0,isLoading:1})}}var sa={value:()=>{}};function cn(){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 Xt(n)}function Xt(e){this._=e}function aa(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}})}Xt.prototype=cn.prototype={constructor:Xt,on:function(e,t){var n=this._,r=aa(e+"",n),i,o=-1,s=r.length;if(arguments.length<2){for(;++o<s;)if((i=(e=r[o]).type)&&(i=la(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]=pr(n[i],e.name,t);else if(t==null)for(i in n)n[i]=pr(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 Xt(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 la(e,t){for(var n=0,r=e.length,i;n<r;++n)if((i=e[n]).name===t)return i.value}function pr(e,t,n){for(var r=0,i=e.length;r<i;++r)if(e[r].name===t){e[r]=sa,e=e.slice(0,r).concat(e.slice(r+1));break}return n!=null&&e.push({name:t,value:n}),e}var Tn="http://www.w3.org/1999/xhtml";const mr={svg:"http://www.w3.org/2000/svg",xhtml:Tn,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function fn(e){var t=e+="",n=t.indexOf(":");return n>=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),mr.hasOwnProperty(t)?{space:mr[t],local:e}:e}function ua(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===Tn&&t.documentElement.namespaceURI===Tn?t.createElement(e):t.createElementNS(n,e)}}function ca(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function wi(e){var t=fn(e);return(t.local?ca:ua)(t)}function fa(){}function jn(e){return e==null?fa:function(){return this.querySelector(e)}}function ha(e){typeof e!="function"&&(e=jn(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 Pe(r,this._parents)}function da(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function pa(){return[]}function bi(e){return e==null?pa:function(){return this.querySelectorAll(e)}}function ma(e){return function(){return da(e.apply(this,arguments))}}function _a(e){typeof e=="function"?e=ma(e):e=bi(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 Pe(r,i)}function ki(e){return function(){return this.matches(e)}}function Ei(e){return function(t){return t.matches(e)}}var ga=Array.prototype.find;function va(e){return function(){return ga.call(this.children,e)}}function ya(){return this.firstElementChild}function wa(e){return this.select(e==null?ya:va(typeof e=="function"?e:Ei(e)))}var ba=Array.prototype.filter;function ka(){return Array.from(this.children)}function Ea(e){return function(){return ba.call(this.children,e)}}function xa(e){return this.selectAll(e==null?ka:Ea(typeof e=="function"?e:Ei(e)))}function Oa(e){typeof e!="function"&&(e=ki(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 Pe(r,this._parents)}function xi(e){return new Array(e.length)}function Ia(){return new Pe(this._enter||this._groups.map(xi),this._parents)}function Zt(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}Zt.prototype={constructor:Zt,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 Sa(e){return function(){return e}}function Pa(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 Zt(e,o[s]);for(;s<l;++s)(a=t[s])&&(i[s]=a)}function Ta(e,t,n,r,i,o,s){var a,l,u=new Map,c=t.length,p=o.length,d=new Array(c),m;for(a=0;a<c;++a)(l=t[a])&&(d[a]=m=s.call(l,l.__data__,a,t)+"",u.has(m)?i[a]=l:u.set(m,l));for(a=0;a<p;++a)m=s.call(e,o[a],a,o)+"",(l=u.get(m))?(r[a]=l,l.__data__=o[a],u.delete(m)):n[a]=new Zt(e,o[a]);for(a=0;a<c;++a)(l=t[a])&&u.get(d[a])===l&&(i[a]=l)}function Aa(e){return e.__data__}function La(e,t){if(!arguments.length)return Array.from(this,Aa);var n=t?Ta:Pa,r=this._parents,i=this._groups;typeof e!="function"&&(e=Sa(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],p=i[u],d=p.length,m=Ca(e.call(c,c&&c.__data__,u,r)),b=m.length,k=a[u]=new Array(b),O=s[u]=new Array(b),_=l[u]=new Array(d);n(c,p,k,O,_,m,t);for(var P=0,I=0,y,D;P<b;++P)if(y=k[P]){for(P>=I&&(I=P+1);!(D=O[I])&&++I<b;);y._next=D||null}}return s=new Pe(s,r),s._enter=a,s._exit=l,s}function Ca(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function Na(){return new Pe(this._exit||this._groups.map(xi),this._parents)}function Ra(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 $a(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],p=u.length,d=a[l]=new Array(p),m,b=0;b<p;++b)(m=u[b]||c[b])&&(d[b]=m);for(;l<i;++l)a[l]=n[l];return new Pe(a,this._parents)}function Ma(){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 Ua(e){e||(e=Da);function t(p,d){return p&&d?e(p.__data__,d.__data__):!p-!d}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 Pe(i,this._parents).order()}function Da(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function za(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function Ha(){return Array.from(this)}function Ka(){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 Fa(){let e=0;for(const t of this)++e;return e}function Va(){return!this.node()}function Ba(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 Xa(e){return function(){this.removeAttribute(e)}}function Ya(e){return function(){this.removeAttributeNS(e.space,e.local)}}function qa(e,t){return function(){this.setAttribute(e,t)}}function ja(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 Ja(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 Wa(e,t){var n=fn(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?Ya:Xa:typeof t=="function"?n.local?Ja:Ga:n.local?ja:qa)(n,t))}function Oi(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function Za(e){return function(){this.style.removeProperty(e)}}function Qa(e,t,n){return function(){this.style.setProperty(e,t,n)}}function el(e,t,n){return function(){var r=t.apply(this,arguments);r==null?this.style.removeProperty(e):this.style.setProperty(e,r,n)}}function tl(e,t,n){return arguments.length>1?this.each((t==null?Za:typeof t=="function"?el:Qa)(e,t,n==null?"":n)):_t(this.node(),e)}function _t(e,t){return e.style.getPropertyValue(t)||Oi(e).getComputedStyle(e,null).getPropertyValue(t)}function nl(e){return function(){delete this[e]}}function rl(e,t){return function(){this[e]=t}}function il(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function ol(e,t){return arguments.length>1?this.each((t==null?nl:typeof t=="function"?il:rl)(e,t)):this.node()[e]}function Ii(e){return e.trim().split(/^|\s+/)}function Gn(e){return e.classList||new Si(e)}function Si(e){this._node=e,this._names=Ii(e.getAttribute("class")||"")}Si.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 Pi(e,t){for(var n=Gn(e),r=-1,i=t.length;++r<i;)n.add(t[r])}function Ti(e,t){for(var n=Gn(e),r=-1,i=t.length;++r<i;)n.remove(t[r])}function sl(e){return function(){Pi(this,e)}}function al(e){return function(){Ti(this,e)}}function ll(e,t){return function(){(t.apply(this,arguments)?Pi:Ti)(this,e)}}function ul(e,t){var n=Ii(e+"");if(arguments.length<2){for(var r=Gn(this.node()),i=-1,o=n.length;++i<o;)if(!r.contains(n[i]))return!1;return!0}return this.each((typeof t=="function"?ll:t?sl:al)(n,t))}function cl(){this.textContent=""}function fl(e){return function(){this.textContent=e}}function hl(e){return function(){var t=e.apply(this,arguments);this.textContent=t==null?"":t}}function dl(e){return arguments.length?this.each(e==null?cl:(typeof e=="function"?hl:fl)(e)):this.node().textContent}function pl(){this.innerHTML=""}function ml(e){return function(){this.innerHTML=e}}function _l(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t==null?"":t}}function gl(e){return arguments.length?this.each(e==null?pl:(typeof e=="function"?_l:ml)(e)):this.node().innerHTML}function vl(){this.nextSibling&&this.parentNode.appendChild(this)}function yl(){return this.each(vl)}function wl(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function bl(){return this.each(wl)}function kl(e){var t=typeof e=="function"?e:wi(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function El(){return null}function xl(e,t){var n=typeof e=="function"?e:wi(e),r=t==null?El:typeof t=="function"?t:jn(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),r.apply(this,arguments)||null)})}function Ol(){var e=this.parentNode;e&&e.removeChild(this)}function Il(){return this.each(Ol)}function Sl(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function Pl(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function Tl(e){return this.select(e?Pl:Sl)}function Al(e){return arguments.length?this.property("__data__",e):this.node().__data__}function Ll(e){return function(t){e.call(this,t,this.__data__)}}function Cl(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 Nl(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 Rl(e,t,n){return function(){var r=this.__on,i,o=Ll(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 $l(e,t,n){var r=Cl(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?Rl:Nl,i=0;i<o;++i)this.each(a(r[i],t,n));return this}function Ai(e,t,n){var r=Oi(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 Ml(e,t){return function(){return Ai(this,e,t)}}function Ul(e,t){return function(){return Ai(this,e,t.apply(this,arguments))}}function Dl(e,t){return this.each((typeof t=="function"?Ul:Ml)(e,t))}function*zl(){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 Li=[null];function Pe(e,t){this._groups=e,this._parents=t}function Nt(){return new Pe([[document.documentElement]],Li)}function Hl(){return this}Pe.prototype=Nt.prototype={constructor:Pe,select:ha,selectAll:_a,selectChild:wa,selectChildren:xa,filter:Oa,data:La,enter:Ia,exit:Na,join:Ra,merge:$a,selection:Hl,order:Ma,sort:Ua,call:za,nodes:Ha,node:Ka,size:Fa,empty:Va,each:Ba,attr:Wa,style:tl,property:ol,classed:ul,text:dl,html:gl,raise:yl,lower:bl,append:kl,insert:xl,remove:Il,clone:Tl,datum:Al,on:$l,dispatch:Dl,[Symbol.iterator]:zl};function Ae(e){return typeof e=="string"?new Pe([[document.querySelector(e)]],[document.documentElement]):new Pe([[e]],Li)}function Kl(e){let t;for(;t=e.sourceEvent;)e=t;return e}function Be(e,t){if(e=Kl(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 Fl={passive:!1},xt={capture:!0,passive:!1};function xn(e){e.stopImmediatePropagation()}function dt(e){e.preventDefault(),e.stopImmediatePropagation()}function Ci(e){var t=e.document.documentElement,n=Ae(e).on("dragstart.drag",dt,xt);"onselectstart"in t?n.on("selectstart.drag",dt,xt):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect="none")}function Ni(e,t){var n=e.document.documentElement,r=Ae(e).on("dragstart.drag",null);t&&(r.on("click.drag",dt,xt),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 Mt=e=>()=>e;function An(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}})}An.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function Vl(e){return!e.ctrlKey&&!e.button}function Bl(){return this.parentNode}function Xl(e,t){return t==null?{x:e.x,y:e.y}:t}function Yl(){return navigator.maxTouchPoints||"ontouchstart"in this}function _r(){var e=Vl,t=Bl,n=Xl,r=Yl,i={},o=cn("start","drag","end"),s=0,a,l,u,c,p=0;function d(y){y.on("mousedown.drag",m).filter(r).on("touchstart.drag",O).on("touchmove.drag",_,Fl).on("touchend.drag touchcancel.drag",P).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function m(y,D){if(!(c||!e.call(this,y,D))){var H=I(this,t.call(this,y,D),y,D,"mouse");!H||(Ae(y.view).on("mousemove.drag",b,xt).on("mouseup.drag",k,xt),Ci(y.view),xn(y),u=!1,a=y.clientX,l=y.clientY,H("start",y))}}function b(y){if(dt(y),!u){var D=y.clientX-a,H=y.clientY-l;u=D*D+H*H>p}i.mouse("drag",y)}function k(y){Ae(y.view).on("mousemove.drag mouseup.drag",null),Ni(y.view,u),dt(y),i.mouse("end",y)}function O(y,D){if(!!e.call(this,y,D)){var H=y.changedTouches,C=t.call(this,y,D),V=H.length,X,J;for(X=0;X<V;++X)(J=I(this,C,y,D,H[X].identifier,H[X]))&&(xn(y),J("start",y,H[X]))}}function _(y){var D=y.changedTouches,H=D.length,C,V;for(C=0;C<H;++C)(V=i[D[C].identifier])&&(dt(y),V("drag",y,D[C]))}function P(y){var D=y.changedTouches,H=D.length,C,V;for(c&&clearTimeout(c),c=setTimeout(function(){c=null},500),C=0;C<H;++C)(V=i[D[C].identifier])&&(xn(y),V("end",y,D[C]))}function I(y,D,H,C,V,X){var J=o.copy(),te=Be(X||H,D),ae,be,f;if((f=n.call(y,new An("beforestart",{sourceEvent:H,target:d,identifier:V,active:s,x:te[0],y:te[1],dx:0,dy:0,dispatch:J}),C))!=null)return ae=f.x-te[0]||0,be=f.y-te[1]||0,function T(w,S,L){var $=te,K;switch(w){case"start":i[V]=T,K=s++;break;case"end":delete i[V],--s;case"drag":te=Be(L||S,D),K=s;break}J.call(w,y,new An(w,{sourceEvent:S,subject:f,target:d,identifier:V,active:K,x:te[0]+ae,y:te[1]+be,dx:te[0]-$[0],dy:te[1]-$[1],dispatch:J}),C)}}return d.filter=function(y){return arguments.length?(e=typeof y=="function"?y:Mt(!!y),d):e},d.container=function(y){return arguments.length?(t=typeof y=="function"?y:Mt(y),d):t},d.subject=function(y){return arguments.length?(n=typeof y=="function"?y:Mt(y),d):n},d.touchable=function(y){return arguments.length?(r=typeof y=="function"?y:Mt(!!y),d):r},d.on=function(){var y=o.on.apply(o,arguments);return y===o?d:y},d.clickDistance=function(y){return arguments.length?(p=(y=+y)*y,d):Math.sqrt(p)},d}function ql(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 jl(e,t){const n=Gl(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 Ut(e,t=32){return e%t<t/2?e-e%t:e+t-e%t}function Gl(e){return e?e.toString().toLowerCase().replace(/\s+/g,"-").replace(/[^\w\-]+/g,"").replace(/\-\-+/g,"-").replace(/^-+/,"").replace(/-+$/,""):""}function hn(){const e=Xr(gi);if(!e)throw new Error("Use RoomProvider as parent with id prop");return e}function dn(){const e=hn(),{subscribe:t,set:n}=et();function r(o){e.updatePresence(o)}const i=e.subscribe("my-presence",o=>{n(o)});return on(()=>{i()}),{subscribe:t,update:r}}function Jl(){const e=hn(),t=et(),n=e.subscribe("others",r=>{t.set(r)});return on(n),t}function Wl(){const e=hn(),t=et();async function n(){const{root:r}=await e.getStorage();t.set(r)}return n(),t}function Ri(e,t){const n=hn(),r=Wl(),i=et();let o=()=>{};const s=r.subscribe(a=>{!a||(a.get(e)||a.set(e,new ws(t)),i.set(a.get(e)),o(),o=n.subscribe(a.get(e),l=>{i.set(l)}))});return on(s),i}function Jn(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function $i(e,t){var n=Object.create(e.prototype);for(var r in t)n[r]=t[r];return n}function Rt(){}var Ot=.7,Qt=1/Ot,pt="\\s*([+-]?\\d+)\\s*",It="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",De="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",Zl=/^#([0-9a-f]{3,8})$/,Ql=new RegExp(`^rgb\\(${pt},${pt},${pt}\\)$`),eu=new RegExp(`^rgb\\(${De},${De},${De}\\)$`),tu=new RegExp(`^rgba\\(${pt},${pt},${pt},${It}\\)$`),nu=new RegExp(`^rgba\\(${De},${De},${De},${It}\\)$`),ru=new RegExp(`^hsl\\(${It},${De},${De}\\)$`),iu=new RegExp(`^hsla\\(${It},${De},${De},${It}\\)$`),gr={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};Jn(Rt,St,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:vr,formatHex:vr,formatHex8:ou,formatHsl:su,formatRgb:yr,toString:yr});function vr(){return this.rgb().formatHex()}function ou(){return this.rgb().formatHex8()}function su(){return Mi(this).formatHsl()}function yr(){return this.rgb().formatRgb()}function St(e){var t,n;return e=(e+"").trim().toLowerCase(),(t=Zl.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?wr(t):n===3?new Ee(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?Dt(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?Dt(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=Ql.exec(e))?new Ee(t[1],t[2],t[3],1):(t=eu.exec(e))?new Ee(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=tu.exec(e))?Dt(t[1],t[2],t[3],t[4]):(t=nu.exec(e))?Dt(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=ru.exec(e))?Er(t[1],t[2]/100,t[3]/100,1):(t=iu.exec(e))?Er(t[1],t[2]/100,t[3]/100,t[4]):gr.hasOwnProperty(e)?wr(gr[e]):e==="transparent"?new Ee(NaN,NaN,NaN,0):null}function wr(e){return new Ee(e>>16&255,e>>8&255,e&255,1)}function Dt(e,t,n,r){return r<=0&&(e=t=n=NaN),new Ee(e,t,n,r)}function au(e){return e instanceof Rt||(e=St(e)),e?(e=e.rgb(),new Ee(e.r,e.g,e.b,e.opacity)):new Ee}function Ln(e,t,n,r){return arguments.length===1?au(e):new Ee(e,t,n,r==null?1:r)}function Ee(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}Jn(Ee,Ln,$i(Rt,{brighter(e){return e=e==null?Qt:Math.pow(Qt,e),new Ee(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?Ot:Math.pow(Ot,e),new Ee(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new Ee(at(this.r),at(this.g),at(this.b),en(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:br,formatHex:br,formatHex8:lu,formatRgb:kr,toString:kr}));function br(){return`#${ot(this.r)}${ot(this.g)}${ot(this.b)}`}function lu(){return`#${ot(this.r)}${ot(this.g)}${ot(this.b)}${ot((isNaN(this.opacity)?1:this.opacity)*255)}`}function kr(){const e=en(this.opacity);return`${e===1?"rgb(":"rgba("}${at(this.r)}, ${at(this.g)}, ${at(this.b)}${e===1?")":`, ${e})`}`}function en(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function at(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function ot(e){return e=at(e),(e<16?"0":"")+e.toString(16)}function Er(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new Ne(e,t,n,r)}function Mi(e){if(e instanceof Ne)return new Ne(e.h,e.s,e.l,e.opacity);if(e instanceof Rt||(e=St(e)),!e)return new Ne;if(e instanceof Ne)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 Ne(s,a,l,e.opacity)}function uu(e,t,n,r){return arguments.length===1?Mi(e):new Ne(e,t,n,r==null?1:r)}function Ne(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}Jn(Ne,uu,$i(Rt,{brighter(e){return e=e==null?Qt:Math.pow(Qt,e),new Ne(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Ot:Math.pow(Ot,e),new Ne(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 Ee(On(e>=240?e-240:e+120,i,r),On(e,i,r),On(e<120?e+240:e-120,i,r),this.opacity)},clamp(){return new Ne(xr(this.h),zt(this.s),zt(this.l),en(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=en(this.opacity);return`${e===1?"hsl(":"hsla("}${xr(this.h)}, ${zt(this.s)*100}%, ${zt(this.l)*100}%${e===1?")":`, ${e})`}`}}));function xr(e){return e=(e||0)%360,e<0?e+360:e}function zt(e){return Math.max(0,Math.min(1,e||0))}function On(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 Ui=e=>()=>e;function cu(e,t){return function(n){return e+n*t}}function fu(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 hu(e){return(e=+e)==1?Di:function(t,n){return n-t?fu(t,n,e):Ui(isNaN(t)?n:t)}}function Di(e,t){var n=t-e;return n?cu(e,n):Ui(isNaN(e)?t:e)}const Or=function e(t){var n=hu(t);function r(i,o){var s=n((i=Ln(i)).r,(o=Ln(o)).r),a=n(i.g,o.g),l=n(i.b,o.b),u=Di(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 Ge(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}var Cn=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,In=new RegExp(Cn.source,"g");function du(e){return function(){return e}}function pu(e){return function(t){return e(t)+""}}function mu(e,t){var n=Cn.lastIndex=In.lastIndex=0,r,i,o,s=-1,a=[],l=[];for(e=e+"",t=t+"";(r=Cn.exec(e))&&(i=In.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:Ge(r,i)})),n=In.lastIndex;return n<t.length&&(o=t.slice(n),a[s]?a[s]+=o:a[++s]=o),a.length<2?l[0]?pu(l[0].x):du(t):(t=l.length,function(u){for(var c=0,p;c<t;++c)a[(p=l[c]).i]=p.x(u);return a.join("")})}var Ir=180/Math.PI,Nn={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function zi(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)*Ir,skewX:Math.atan(l)*Ir,scaleX:s,scaleY:a}}var Ht;function _u(e){const t=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return t.isIdentity?Nn:zi(t.a,t.b,t.c,t.d,t.e,t.f)}function gu(e){return e==null||(Ht||(Ht=document.createElementNS("http://www.w3.org/2000/svg","g")),Ht.setAttribute("transform",e),!(e=Ht.transform.baseVal.consolidate()))?Nn:(e=e.matrix,zi(e.a,e.b,e.c,e.d,e.e,e.f))}function Hi(e,t,n,r){function i(u){return u.length?u.pop()+" ":""}function o(u,c,p,d,m,b){if(u!==p||c!==d){var k=m.push("translate(",null,t,null,n);b.push({i:k-4,x:Ge(u,p)},{i:k-2,x:Ge(c,d)})}else(p||d)&&m.push("translate("+p+t+d+n)}function s(u,c,p,d){u!==c?(u-c>180?c+=360:c-u>180&&(u+=360),d.push({i:p.push(i(p)+"rotate(",null,r)-2,x:Ge(u,c)})):c&&p.push(i(p)+"rotate("+c+r)}function a(u,c,p,d){u!==c?d.push({i:p.push(i(p)+"skewX(",null,r)-2,x:Ge(u,c)}):c&&p.push(i(p)+"skewX("+c+r)}function l(u,c,p,d,m,b){if(u!==p||c!==d){var k=m.push(i(m)+"scale(",null,",",null,")");b.push({i:k-4,x:Ge(u,p)},{i:k-2,x:Ge(c,d)})}else(p!==1||d!==1)&&m.push(i(m)+"scale("+p+","+d+")")}return function(u,c){var p=[],d=[];return u=e(u),c=e(c),o(u.translateX,u.translateY,c.translateX,c.translateY,p,d),s(u.rotate,c.rotate,p,d),a(u.skewX,c.skewX,p,d),l(u.scaleX,u.scaleY,c.scaleX,c.scaleY,p,d),u=c=null,function(m){for(var b=-1,k=d.length,O;++b<k;)p[(O=d[b]).i]=O.x(m);return p.join("")}}}var vu=Hi(_u,"px, ","px)","deg)"),yu=Hi(gu,", ",")",")"),wu=1e-12;function Sr(e){return((e=Math.exp(e))+1/e)/2}function bu(e){return((e=Math.exp(e))-1/e)/2}function ku(e){return((e=Math.exp(2*e))-1)/(e+1)}const Eu=function e(t,n,r){function i(o,s){var a=o[0],l=o[1],u=o[2],c=s[0],p=s[1],d=s[2],m=c-a,b=p-l,k=m*m+b*b,O,_;if(k<wu)_=Math.log(d/u)/t,O=function(C){return[a+C*m,l+C*b,u*Math.exp(t*C*_)]};else{var P=Math.sqrt(k),I=(d*d-u*u+r*k)/(2*u*n*P),y=(d*d-u*u-r*k)/(2*d*n*P),D=Math.log(Math.sqrt(I*I+1)-I),H=Math.log(Math.sqrt(y*y+1)-y);_=(H-D)/t,O=function(C){var V=C*_,X=Sr(D),J=u/(n*P)*(X*ku(t*V+D)-bu(D));return[a+J*m,l+J*b,u*X/Sr(t*V+D)]}}return O.duration=_*1e3*t/Math.SQRT2,O}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 gt=0,bt=0,vt=0,Ki=1e3,tn,kt,nn=0,ut=0,pn=0,Pt=typeof performance=="object"&&performance.now?performance:Date,Fi=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function Wn(){return ut||(Fi(xu),ut=Pt.now()+pn)}function xu(){ut=0}function rn(){this._call=this._time=this._next=null}rn.prototype=Vi.prototype={constructor:rn,restart:function(e,t,n){if(typeof e!="function")throw new TypeError("callback is not a function");n=(n==null?Wn():+n)+(t==null?0:+t),!this._next&&kt!==this&&(kt?kt._next=this:tn=this,kt=this),this._call=e,this._time=n,Rn()},stop:function(){this._call&&(this._call=null,this._time=1/0,Rn())}};function Vi(e,t,n){var r=new rn;return r.restart(e,t,n),r}function Ou(){Wn(),++gt;for(var e=tn,t;e;)(t=ut-e._time)>=0&&e._call.call(void 0,t),e=e._next;--gt}function Pr(){ut=(nn=Pt.now())+pn,gt=bt=0;try{Ou()}finally{gt=0,Su(),ut=0}}function Iu(){var e=Pt.now(),t=e-nn;t>Ki&&(pn-=t,nn=e)}function Su(){for(var e,t=tn,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:tn=n);kt=e,Rn(r)}function Rn(e){if(!gt){bt&&(bt=clearTimeout(bt));var t=e-ut;t>24?(e<1/0&&(bt=setTimeout(Pr,e-Pt.now()-pn)),vt&&(vt=clearInterval(vt))):(vt||(nn=Pt.now(),vt=setInterval(Iu,Ki)),gt=1,Fi(Pr))}}function Tr(e,t,n){var r=new rn;return t=t==null?0:+t,r.restart(i=>{r.stop(),e(i+t)},t,n),r}var Pu=cn("start","end","cancel","interrupt"),Tu=[],Bi=0,Ar=1,$n=2,Yt=3,Lr=4,Mn=5,qt=6;function mn(e,t,n,r,i,o){var s=e.__transition;if(!s)e.__transition={};else if(n in s)return;Au(e,n,{name:t,index:r,group:i,on:Pu,tween:Tu,time:o.time,delay:o.delay,duration:o.duration,ease:o.ease,timer:null,state:Bi})}function Zn(e,t){var n=$e(e,t);if(n.state>Bi)throw new Error("too late; already scheduled");return n}function Ke(e,t){var n=$e(e,t);if(n.state>Yt)throw new Error("too late; already running");return n}function $e(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function Au(e,t,n){var r=e.__transition,i;r[t]=n,n.timer=Vi(o,0,n.time);function o(u){n.state=Ar,n.timer.restart(s,n.delay,n.time),n.delay<=u&&s(u-n.delay)}function s(u){var c,p,d,m;if(n.state!==Ar)return l();for(c in r)if(m=r[c],m.name===n.name){if(m.state===Yt)return Tr(s);m.state===Lr?(m.state=qt,m.timer.stop(),m.on.call("interrupt",e,e.__data__,m.index,m.group),delete r[c]):+c<t&&(m.state=qt,m.timer.stop(),m.on.call("cancel",e,e.__data__,m.index,m.group),delete r[c])}if(Tr(function(){n.state===Yt&&(n.state=Lr,n.timer.restart(a,n.delay,n.time),a(u))}),n.state=$n,n.on.call("start",e,e.__data__,n.index,n.group),n.state===$n){for(n.state=Yt,i=new Array(d=n.tween.length),c=0,p=-1;c<d;++c)(m=n.tween[c].value.call(e,e.__data__,n.index,n.group))&&(i[++p]=m);i.length=p+1}}function a(u){for(var c=u<n.duration?n.ease.call(null,u/n.duration):(n.timer.restart(l),n.state=Mn,1),p=-1,d=i.length;++p<d;)i[p].call(e,c);n.state===Mn&&(n.on.call("end",e,e.__data__,n.index,n.group),l())}function l(){n.state=qt,n.timer.stop(),delete r[t];for(var u in r)return;delete e.__transition}}function jt(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>$n&&r.state<Mn,r.state=qt,r.timer.stop(),r.on.call(i?"interrupt":"cancel",e,e.__data__,r.index,r.group),delete n[s]}o&&delete e.__transition}}function Lu(e){return this.each(function(){jt(this,e)})}function Cu(e,t){var n,r;return function(){var i=Ke(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 Nu(e,t,n){var r,i;if(typeof n!="function")throw new Error;return function(){var o=Ke(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 Ru(e,t){var n=this._id;if(e+="",arguments.length<2){for(var r=$e(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?Cu:Nu)(n,e,t))}function Qn(e,t,n){var r=e._id;return e.each(function(){var i=Ke(this,r);(i.value||(i.value={}))[t]=n.apply(this,arguments)}),function(i){return $e(i,r).value[t]}}function Xi(e,t){var n;return(typeof t=="number"?Ge:t instanceof St?Or:(n=St(t))?(t=n,Or):mu)(e,t)}function $u(e){return function(){this.removeAttribute(e)}}function Mu(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Uu(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 Du(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 zu(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 Hu(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 Ku(e,t){var n=fn(e),r=n==="transform"?yu:Xi;return this.attrTween(e,typeof t=="function"?(n.local?Hu:zu)(n,r,Qn(this,"attr."+e,t)):t==null?(n.local?Mu:$u)(n):(n.local?Du:Uu)(n,r,t))}function Fu(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function Vu(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function Bu(e,t){var n,r;function i(){var o=t.apply(this,arguments);return o!==r&&(n=(r=o)&&Vu(e,o)),n}return i._value=t,i}function Xu(e,t){var n,r;function i(){var o=t.apply(this,arguments);return o!==r&&(n=(r=o)&&Fu(e,o)),n}return i._value=t,i}function Yu(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=fn(e);return this.tween(n,(r.local?Bu:Xu)(r,t))}function qu(e,t){return function(){Zn(this,e).delay=+t.apply(this,arguments)}}function ju(e,t){return t=+t,function(){Zn(this,e).delay=t}}function Gu(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?qu:ju)(t,e)):$e(this.node(),t).delay}function Ju(e,t){return function(){Ke(this,e).duration=+t.apply(this,arguments)}}function Wu(e,t){return t=+t,function(){Ke(this,e).duration=t}}function Zu(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?Ju:Wu)(t,e)):$e(this.node(),t).duration}function Qu(e,t){if(typeof t!="function")throw new Error;return function(){Ke(this,e).ease=t}}function ec(e){var t=this._id;return arguments.length?this.each(Qu(t,e)):$e(this.node(),t).ease}function tc(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!="function")throw new Error;Ke(this,e).ease=n}}function nc(e){if(typeof e!="function")throw new Error;return this.each(tc(this._id,e))}function rc(e){typeof e!="function"&&(e=ki(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 qe(r,this._parents,this._name,this._id)}function ic(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,p=s[a]=new Array(c),d,m=0;m<c;++m)(d=l[m]||u[m])&&(p[m]=d);for(;a<r;++a)s[a]=t[a];return new qe(s,this._parents,this._name,this._id)}function oc(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 sc(e,t,n){var r,i,o=oc(t)?Zn:Ke;return function(){var s=o(this,e),a=s.on;a!==r&&(i=(r=a).copy()).on(t,n),s.on=i}}function ac(e,t){var n=this._id;return arguments.length<2?$e(this.node(),n).on.on(e):this.each(sc(n,e,t))}function lc(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function uc(){return this.on("end.remove",lc(this._id))}function cc(e){var t=this._name,n=this._id;typeof e!="function"&&(e=jn(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,p,d=0;d<l;++d)(c=a[d])&&(p=e.call(c,c.__data__,d,a))&&("__data__"in c&&(p.__data__=c.__data__),u[d]=p,mn(u[d],t,n,d,u,$e(c,n)));return new qe(o,this._parents,t,n)}function fc(e){var t=this._name,n=this._id;typeof e!="function"&&(e=bi(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,p=0;p<u;++p)if(c=l[p]){for(var d=e.call(c,c.__data__,p,l),m,b=$e(c,n),k=0,O=d.length;k<O;++k)(m=d[k])&&mn(m,t,n,k,d,b);o.push(d),s.push(c)}return new qe(o,s,t,n)}var hc=Nt.prototype.constructor;function dc(){return new hc(this._groups,this._parents)}function pc(e,t){var n,r,i;return function(){var o=_t(this,e),s=(this.style.removeProperty(e),_t(this,e));return o===s?null:o===n&&s===r?i:i=t(n=o,r=s)}}function Yi(e){return function(){this.style.removeProperty(e)}}function mc(e,t,n){var r,i=n+"",o;return function(){var s=_t(this,e);return s===i?null:s===r?o:o=t(r=s,n)}}function _c(e,t,n){var r,i,o;return function(){var s=_t(this,e),a=n(this),l=a+"";return a==null&&(l=a=(this.style.removeProperty(e),_t(this,e))),s===l?null:s===r&&l===i?o:(i=l,o=t(r=s,a))}}function gc(e,t){var n,r,i,o="style."+t,s="end."+o,a;return function(){var l=Ke(this,e),u=l.on,c=l.value[o]==null?a||(a=Yi(t)):void 0;(u!==n||i!==c)&&(r=(n=u).copy()).on(s,i=c),l.on=r}}function vc(e,t,n){var r=(e+="")=="transform"?vu:Xi;return t==null?this.styleTween(e,pc(e,r)).on("end.style."+e,Yi(e)):typeof t=="function"?this.styleTween(e,_c(e,r,Qn(this,"style."+e,t))).each(gc(this._id,e)):this.styleTween(e,mc(e,r,t),n).on("end.style."+e,null)}function yc(e,t,n){return function(r){this.style.setProperty(e,t.call(this,r),n)}}function wc(e,t,n){var r,i;function o(){var s=t.apply(this,arguments);return s!==i&&(r=(i=s)&&yc(e,s,n)),r}return o._value=t,o}function bc(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,wc(e,t,n==null?"":n))}function kc(e){return function(){this.textContent=e}}function Ec(e){return function(){var t=e(this);this.textContent=t==null?"":t}}function xc(e){return this.tween("text",typeof e=="function"?Ec(Qn(this,"text",e)):kc(e==null?"":e+""))}function Oc(e){return function(t){this.textContent=e.call(this,t)}}function Ic(e){var t,n;function r(){var i=e.apply(this,arguments);return i!==n&&(t=(n=i)&&Oc(i)),t}return r._value=e,r}function Sc(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,Ic(e))}function Pc(){for(var e=this._name,t=this._id,n=qi(),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=$e(l,t);mn(l,e,n,u,s,{time:c.time+c.delay+c.duration,delay:0,duration:c.duration,ease:c.ease})}return new qe(r,this._parents,e,n)}function Tc(){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=Ke(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 Ac=0;function qe(e,t,n,r){this._groups=e,this._parents=t,this._name=n,this._id=r}function qi(){return++Ac}var Fe=Nt.prototype;qe.prototype={constructor:qe,select:cc,selectAll:fc,selectChild:Fe.selectChild,selectChildren:Fe.selectChildren,filter:rc,merge:ic,selection:dc,transition:Pc,call:Fe.call,nodes:Fe.nodes,node:Fe.node,size:Fe.size,empty:Fe.empty,each:Fe.each,on:ac,attr:Ku,attrTween:Yu,style:vc,styleTween:bc,text:xc,textTween:Sc,remove:uc,tween:Ru,delay:Gu,duration:Zu,ease:ec,easeVarying:nc,end:Tc,[Symbol.iterator]:Fe[Symbol.iterator]};function Lc(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var Cc={time:null,delay:0,duration:250,ease:Lc};function Nc(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 Rc(e){var t,n;e instanceof qe?(t=e._id,e=e._name):(t=qi(),(n=Cc).time=Wn(),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])&&mn(l,e,t,u,s,n||Nc(l,t));return new qe(r,this._parents,e,t)}Nt.prototype.interrupt=Lu;Nt.prototype.transition=Rc;const Kt=e=>()=>e;function $c(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 Ye(e,t,n){this.k=e,this.x=t,this.y=n}Ye.prototype={constructor:Ye,scale:function(e){return e===1?this:new Ye(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new Ye(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 Tt=new Ye(1,0,0);Ye.prototype;function Sn(e){e.stopImmediatePropagation()}function yt(e){e.preventDefault(),e.stopImmediatePropagation()}function Mc(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function Uc(){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 Cr(){return this.__zoom||Tt}function Dc(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function zc(){return navigator.maxTouchPoints||"ontouchstart"in this}function Hc(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 Kc(){var e=Mc,t=Uc,n=Hc,r=Dc,i=zc,o=[0,1/0],s=[[-1/0,-1/0],[1/0,1/0]],a=250,l=Eu,u=cn("start","zoom","end"),c,p,d,m=500,b=150,k=0,O=10;function _(f){f.property("__zoom",Cr).on("wheel.zoom",V,{passive:!1}).on("mousedown.zoom",X).on("dblclick.zoom",J).filter(i).on("touchstart.zoom",te).on("touchmove.zoom",ae).on("touchend.zoom touchcancel.zoom",be).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}_.transform=function(f,T,w,S){var L=f.selection?f.selection():f;L.property("__zoom",Cr),f!==L?D(f,T,w,S):L.interrupt().each(function(){H(this,arguments).event(S).start().zoom(null,typeof T=="function"?T.apply(this,arguments):T).end()})},_.scaleBy=function(f,T,w,S){_.scaleTo(f,function(){var L=this.__zoom.k,$=typeof T=="function"?T.apply(this,arguments):T;return L*$},w,S)},_.scaleTo=function(f,T,w,S){_.transform(f,function(){var L=t.apply(this,arguments),$=this.__zoom,K=w==null?y(L):typeof w=="function"?w.apply(this,arguments):w,W=$.invert(K),Z=typeof T=="function"?T.apply(this,arguments):T;return n(I(P($,Z),K,W),L,s)},w,S)},_.translateBy=function(f,T,w,S){_.transform(f,function(){return n(this.__zoom.translate(typeof T=="function"?T.apply(this,arguments):T,typeof w=="function"?w.apply(this,arguments):w),t.apply(this,arguments),s)},null,S)},_.translateTo=function(f,T,w,S,L){_.transform(f,function(){var $=t.apply(this,arguments),K=this.__zoom,W=S==null?y($):typeof S=="function"?S.apply(this,arguments):S;return n(Tt.translate(W[0],W[1]).scale(K.k).translate(typeof T=="function"?-T.apply(this,arguments):-T,typeof w=="function"?-w.apply(this,arguments):-w),$,s)},S,L)};function P(f,T){return T=Math.max(o[0],Math.min(o[1],T)),T===f.k?f:new Ye(T,f.x,f.y)}function I(f,T,w){var S=T[0]-w[0]*f.k,L=T[1]-w[1]*f.k;return S===f.x&&L===f.y?f:new Ye(f.k,S,L)}function y(f){return[(+f[0][0]+ +f[1][0])/2,(+f[0][1]+ +f[1][1])/2]}function D(f,T,w,S){f.on("start.zoom",function(){H(this,arguments).event(S).start()}).on("interrupt.zoom end.zoom",function(){H(this,arguments).event(S).end()}).tween("zoom",function(){var L=this,$=arguments,K=H(L,$).event(S),W=t.apply(L,$),Z=w==null?y(W):typeof w=="function"?w.apply(L,$):w,oe=Math.max(W[1][0]-W[0][0],W[1][1]-W[0][1]),se=L.__zoom,ye=typeof T=="function"?T.apply(L,$):T,xe=l(se.invert(Z).concat(oe/se.k),ye.invert(Z).concat(oe/ye.k));return function(we){if(we===1)we=ye;else{var Le=xe(we),ct=oe/Le[2];we=new Ye(ct,Z[0]-Le[0]*ct,Z[1]-Le[1]*ct)}K.zoom(null,we)}})}function H(f,T,w){return!w&&f.__zooming||new C(f,T)}function C(f,T){this.that=f,this.args=T,this.active=0,this.sourceEvent=null,this.extent=t.apply(f,T),this.taps=0}C.prototype={event:function(f){return f&&(this.sourceEvent=f),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(f,T){return this.mouse&&f!=="mouse"&&(this.mouse[1]=T.invert(this.mouse[0])),this.touch0&&f!=="touch"&&(this.touch0[1]=T.invert(this.touch0[0])),this.touch1&&f!=="touch"&&(this.touch1[1]=T.invert(this.touch1[0])),this.that.__zoom=T,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(f){var T=Ae(this.that).datum();u.call(f,this.that,new $c(f,{sourceEvent:this.sourceEvent,target:_,type:f,transform:this.that.__zoom,dispatch:u}),T)}};function V(f,...T){if(!e.apply(this,arguments))return;var w=H(this,T).event(f),S=this.__zoom,L=Math.max(o[0],Math.min(o[1],S.k*Math.pow(2,r.apply(this,arguments)))),$=Be(f);if(w.wheel)(w.mouse[0][0]!==$[0]||w.mouse[0][1]!==$[1])&&(w.mouse[1]=S.invert(w.mouse[0]=$)),clearTimeout(w.wheel);else{if(S.k===L)return;w.mouse=[$,S.invert($)],jt(this),w.start()}yt(f),w.wheel=setTimeout(K,b),w.zoom("mouse",n(I(P(S,L),w.mouse[0],w.mouse[1]),w.extent,s));function K(){w.wheel=null,w.end()}}function X(f,...T){if(d||!e.apply(this,arguments))return;var w=f.currentTarget,S=H(this,T,!0).event(f),L=Ae(f.view).on("mousemove.zoom",Z,!0).on("mouseup.zoom",oe,!0),$=Be(f,w),K=f.clientX,W=f.clientY;Ci(f.view),Sn(f),S.mouse=[$,this.__zoom.invert($)],jt(this),S.start();function Z(se){if(yt(se),!S.moved){var ye=se.clientX-K,xe=se.clientY-W;S.moved=ye*ye+xe*xe>k}S.event(se).zoom("mouse",n(I(S.that.__zoom,S.mouse[0]=Be(se,w),S.mouse[1]),S.extent,s))}function oe(se){L.on("mousemove.zoom mouseup.zoom",null),Ni(se.view,S.moved),yt(se),S.event(se).end()}}function J(f,...T){if(!!e.apply(this,arguments)){var w=this.__zoom,S=Be(f.changedTouches?f.changedTouches[0]:f,this),L=w.invert(S),$=w.k*(f.shiftKey?.5:2),K=n(I(P(w,$),S,L),t.apply(this,T),s);yt(f),a>0?Ae(this).transition().duration(a).call(D,K,S,f):Ae(this).call(_.transform,K,S,f)}}function te(f,...T){if(!!e.apply(this,arguments)){var w=f.touches,S=w.length,L=H(this,T,f.changedTouches.length===S).event(f),$,K,W,Z;for(Sn(f),K=0;K<S;++K)W=w[K],Z=Be(W,this),Z=[Z,this.__zoom.invert(Z),W.identifier],L.touch0?!L.touch1&&L.touch0[2]!==Z[2]&&(L.touch1=Z,L.taps=0):(L.touch0=Z,$=!0,L.taps=1+!!c);c&&(c=clearTimeout(c)),$&&(L.taps<2&&(p=Z[0],c=setTimeout(function(){c=null},m)),jt(this),L.start())}}function ae(f,...T){if(!!this.__zooming){var w=H(this,T).event(f),S=f.changedTouches,L=S.length,$,K,W,Z;for(yt(f),$=0;$<L;++$)K=S[$],W=Be(K,this),w.touch0&&w.touch0[2]===K.identifier?w.touch0[0]=W:w.touch1&&w.touch1[2]===K.identifier&&(w.touch1[0]=W);if(K=w.that.__zoom,w.touch1){var oe=w.touch0[0],se=w.touch0[1],ye=w.touch1[0],xe=w.touch1[1],we=(we=ye[0]-oe[0])*we+(we=ye[1]-oe[1])*we,Le=(Le=xe[0]-se[0])*Le+(Le=xe[1]-se[1])*Le;K=P(K,Math.sqrt(we/Le)),W=[(oe[0]+ye[0])/2,(oe[1]+ye[1])/2],Z=[(se[0]+xe[0])/2,(se[1]+xe[1])/2]}else if(w.touch0)W=w.touch0[0],Z=w.touch0[1];else return;w.zoom("touch",n(I(K,W,Z),w.extent,s))}}function be(f,...T){if(!!this.__zooming){var w=H(this,T).event(f),S=f.changedTouches,L=S.length,$,K;for(Sn(f),d&&clearTimeout(d),d=setTimeout(function(){d=null},m),$=0;$<L;++$)K=S[$],w.touch0&&w.touch0[2]===K.identifier?delete w.touch0:w.touch1&&w.touch1[2]===K.identifier&&delete w.touch1;if(w.touch1&&!w.touch0&&(w.touch0=w.touch1,delete w.touch1),w.touch0)w.touch0[1]=this.__zoom.invert(w.touch0[0]);else if(w.end(),w.taps===2&&(K=Be(K,this),Math.hypot(p[0]-K[0],p[1]-K[1])<O)){var W=Ae(this).on("dblclick.zoom");W&&W.apply(this,arguments)}}}return _.wheelDelta=function(f){return arguments.length?(r=typeof f=="function"?f:Kt(+f),_):r},_.filter=function(f){return arguments.length?(e=typeof f=="function"?f:Kt(!!f),_):e},_.touchable=function(f){return arguments.length?(i=typeof f=="function"?f:Kt(!!f),_):i},_.extent=function(f){return arguments.length?(t=typeof f=="function"?f:Kt([[+f[0][0],+f[0][1]],[+f[1][0],+f[1][1]]]),_):t},_.scaleExtent=function(f){return arguments.length?(o[0]=+f[0],o[1]=+f[1],_):[o[0],o[1]]},_.translateExtent=function(f){return arguments.length?(s[0][0]=+f[0][0],s[1][0]=+f[1][0],s[0][1]=+f[0][1],s[1][1]=+f[1][1],_):[[s[0][0],s[0][1]],[s[1][0],s[1][1]]]},_.constrain=function(f){return arguments.length?(n=f,_):n},_.duration=function(f){return arguments.length?(a=+f,_):a},_.interpolate=function(f){return arguments.length?(l=f,_):l},_.on=function(){var f=u.on.apply(u,arguments);return f===u?_:f},_.clickDistance=function(f){return arguments.length?(k=(f=+f)*f,_):Math.sqrt(k)},_.tapDistance=function(f){return arguments.length?(O=+f,_):O},_}const Oe=et(""),Un=et(Tt),Gt=et(),Dn=et();var ie=(e=>(e.ready="ready",e.loading="loading",e.prompting="prompting",e.processing="processing",e.dragging="dragging",e.masking="masking",e))(ie||{});function Nr(e){let t,n,r;return{c(){t=q("div"),n=q("div"),r=Ze(e[6]),this.h()},l(i){t=j(i,"DIV",{class:!0});var o=U(t);n=j(o,"DIV",{class:!0});var s=U(n);r=Qe(s,e[6]),s.forEach(x),o.forEach(x),this.h()},h(){g(n,"class","font-bold text-xl text-[#387CFF] text-center px-2 line-clamp-4"),g(t,"class","pointer-events-none touch-none")},m(i,o){Y(i,t,o),F(t,n),F(n,r)},p(i,o){o&64&&sn(r,i[6])},d(i){i&&x(t)}}}function Rr(e){let t,n,r;return n=new vi({}),{c(){t=q("div"),le(n.$$.fragment),this.h()},l(i){t=j(i,"DIV",{class:!0});var o=U(t);ue(n.$$.fragment,o),o.forEach(x),this.h()},h(){g(t,"class","absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2")},m(i,o){Y(i,t,o),ce(n,t,null),r=!0},i(i){r||(M(n.$$.fragment,i),r=!0)},o(i){B(n.$$.fragment,i),r=!1},d(i){i&&x(t),fe(n)}}}function $r(e){let t,n,r,i,o,s,a,l,u,c,p,d;r=new yi({props:{isLoading:e[4]}}),r.$on("click",e[16]),a=new qs({props:{isLoading:e[4],isActive:e[2]}}),a.$on("click",e[10]),c=new Qs({props:{isLoading:e[4],isActive:!e[2]}}),c.$on("click",e[11]);let m=!e[2]&&Mr(e);return{c(){t=q("div"),n=q("div"),le(r.$$.fragment),i=he(),o=q("div"),s=q("div"),le(a.$$.fragment),l=he(),u=q("div"),le(c.$$.fragment),p=he(),m&&m.c(),this.h()},l(b){t=j(b,"DIV",{class:!0});var k=U(t);n=j(k,"DIV",{class:!0});var O=U(n);ue(r.$$.fragment,O),O.forEach(x),k.forEach(x),i=de(b),o=j(b,"DIV",{class:!0});var _=U(o);s=j(_,"DIV",{class:!0});var P=U(s);ue(a.$$.fragment,P),l=de(P),u=j(P,"DIV",{class:!0});var I=U(u);ue(c.$$.fragment,I),p=de(I),m&&m.l(I),I.forEach(x),P.forEach(x),_.forEach(x),this.h()},h(){g(n,"class","py-2"),g(t,"class","absolute top-full "),g(u,"class","flex bg-white rounded-full mt-3"),g(s,"class","px-2"),g(o,"class","absolute left-full bottom-0")},m(b,k){Y(b,t,k),F(t,n),ce(r,n,null),Y(b,i,k),Y(b,o,k),F(o,s),ce(a,s,null),F(s,l),F(s,u),ce(c,u,null),F(u,p),m&&m.m(u,null),d=!0},p(b,k){const O={};k&16&&(O.isLoading=b[4]),r.$set(O);const _={};k&16&&(_.isLoading=b[4]),k&4&&(_.isActive=b[2]),a.$set(_);const P={};k&16&&(P.isLoading=b[4]),k&4&&(P.isActive=!b[2]),c.$set(P),b[2]?m&&(ze(),B(m,1,1,()=>{m=null}),He()):m?(m.p(b,k),k&4&&M(m,1)):(m=Mr(b),m.c(),M(m,1),m.m(u,null))},i(b){d||(M(r.$$.fragment,b),M(a.$$.fragment,b),M(c.$$.fragment,b),M(m),d=!0)},o(b){B(r.$$.fragment,b),B(a.$$.fragment,b),B(c.$$.fragment,b),B(m),d=!1},d(b){b&&x(t),fe(r),b&&x(i),b&&x(o),fe(a),fe(c),m&&m.d()}}}function Mr(e){let t,n,r,i;return r=new oa({props:{isLoading:e[4]}}),r.$on("click",e[12]),{c(){t=q("span"),n=he(),le(r.$$.fragment),this.h()},l(o){t=j(o,"SPAN",{class:!0}),U(t).forEach(x),n=de(o),ue(r.$$.fragment,o),this.h()},h(){g(t,"class","border-gray-800 border-opacity-50 border-r-2 my-2")},m(o,s){Y(o,t,s),Y(o,n,s),ce(r,o,s),i=!0},p(o,s){const a={};s&16&&(a.isLoading=o[4]),r.$set(a)},i(o){i||(M(r.$$.fragment,o),i=!0)},o(o){B(r.$$.fragment,o),i=!1},d(o){o&&x(t),o&&x(n),fe(r,o)}}}function Fc(e){let t,n,r,i,o,s,a,l,u,c,p,d,m,b,k,O=e[6]&&Nr(e),_=e[4]&&Rr(),P=!e[3]&&$r(e);return{c(){t=q("div"),n=q("div"),r=q("div"),i=q("canvas"),s=he(),a=q("div"),O&&O.c(),l=he(),_&&_.c(),u=he(),P&&P.c(),p=he(),d=q("div"),this.h()},l(I){t=j(I,"DIV",{});var y=U(t);n=j(y,"DIV",{class:!0,style:!0});var D=U(n);r=j(D,"DIV",{class:!0});var H=U(r);i=j(H,"CANVAS",{class:!0,width:!0,height:!0}),U(i).forEach(x),s=de(H),a=j(H,"DIV",{class:!0});var C=U(a);O&&O.l(C),C.forEach(x),l=de(H),_&&_.l(H),u=de(H),P&&P.l(H),H.forEach(x),D.forEach(x),p=de(y),d=j(y,"DIV",{class:!0,style:!0}),U(d).forEach(x),y.forEach(x),this.h()},h(){g(i,"class",o=e[2]?"":"bg-white"),g(i,"width","512"),g(i,"height","512"),g(a,"class","pointer-events-none touch-none"),g(r,"class","frame svelte-xtgdq4"),g(n,"class","absolute top-0 left-0 pen svelte-xtgdq4"),g(n,"style",c=`transform: translateX(${e[5].x}px) translateY(${e[5].y}px) scale(${e[0].k}); transform-origin: 0 0;`),g(d,"class",m="absolute top-0 left-0 w-[512px] h-[512px] hand "+(e[2]?"block":"hidden")+" svelte-xtgdq4"),g(d,"style",b=`transform: translateX(${e[5].x}px) translateY(${e[5].y}px) scale(${e[0].k}); transform-origin: 0 0;`)},m(I,y){Y(I,t,y),F(t,n),F(n,r),F(r,i),e[15](i),F(r,s),F(r,a),O&&O.m(a,null),F(r,l),_&&_.m(r,null),F(r,u),P&&P.m(r,null),F(t,p),F(t,d),e[17](d),k=!0},p(I,[y]){(!k||y&4&&o!==(o=I[2]?"":"bg-white"))&&g(i,"class",o),I[6]?O?O.p(I,y):(O=Nr(I),O.c(),O.m(a,null)):O&&(O.d(1),O=null),I[4]?_?y&16&&M(_,1):(_=Rr(),_.c(),M(_,1),_.m(r,u)):_&&(ze(),B(_,1,1,()=>{_=null}),He()),I[3]?P&&(ze(),B(P,1,1,()=>{P=null}),He()):P?(P.p(I,y),y&8&&M(P,1)):(P=$r(I),P.c(),M(P,1),P.m(r,null)),(!k||y&33&&c!==(c=`transform: translateX(${I[5].x}px) translateY(${I[5].y}px) scale(${I[0].k}); transform-origin: 0 0;`))&&g(n,"style",c),(!k||y&4&&m!==(m="absolute top-0 left-0 w-[512px] h-[512px] hand "+(I[2]?"block":"hidden")+" svelte-xtgdq4"))&&g(d,"class",m),(!k||y&33&&b!==(b=`transform: translateX(${I[5].x}px) translateY(${I[5].y}px) scale(${I[0].k}); transform-origin: 0 0;`))&&g(d,"style",b)},i(I){k||(M(_),M(P),k=!0)},o(I){B(_),B(P),k=!1},d(I){I&&x(t),e[15](null),O&&O.d(),_&&_.d(),P&&P.d(),e[17](null)}}}function Vc(e,t,n){let r,i,o,s,a,l;Te(e,Dn,f=>n(7,s=f)),Te(e,Gt,f=>n(21,a=f));const u=dn();Te(e,u,f=>n(14,l=f));const c=Vn();let{transform:p}=t,d,m={x:768,y:768},b,k=!0,O=!1,_=0,P=0;function I(f){d.save(),d.clearRect(0,0,512,512),d.globalCompositeOperation="source-over",d.drawImage(a,f.x,f.y,512,512,0,0,512,512),d.restore()}function y(f){d.save(),d.globalCompositeOperation="destination-out",d.beginPath(),d.moveTo(f.lastx,f.lasty),d.lineTo(f.x,f.y),d.lineWidth=50,d.lineCap="round",d.strokeStyle="black",d.stroke(),d.restore()}Lt(()=>{d=s.getContext("2d"),Ae(b).call(C()).call(D),Ae(s).call(H()).call(D)});function D(f){function T(S){u.update({cursor:{x:p.invertX(S.clientX),y:p.invertY(S.clientY)}})}function w(){u.update({cursor:null})}return f.on("pointermove",T).on("pointerleave",w)}function H(){let f,T;function w(L){if(i)return;const $=L.x/p.k,K=L.y/p.k;f=$,T=K}function S(L){if(i)return;const $=L.x/p.k,K=L.y/p.k;y({x:$,y:K,lastx:f,lasty:T}),f=$,T=K}return _r().on("start",w).on("drag",S)}function C(){function f(S){if(i)return;const L=S.sourceEvent.target.getBoundingClientRect();S.sourceEvent instanceof TouchEvent?(_=S.sourceEvent.targetTouches[0].pageX-L.left,P=S.sourceEvent.targetTouches[0].pageY-L.top):(_=S.sourceEvent.pageX-L.left,P=S.sourceEvent.pageY-L.top),n(3,O=!0)}function T(S){if(i)return;const L=Ut(p.invertX(S.x-_)),$=Ut(p.invertY(S.y-P));n(13,m={x:L,y:$}),u.update({cursor:{x:p.invertX(S.x),y:p.invertY(S.y)}}),I({x:L,y:$})}function w(S){if(i)return;n(3,O=!1);const L=Ut(p.invertX(S.x-_)),$=Ut(p.invertY(S.y-P));I({x:L,y:$}),u.update({frame:{x:L,y:$}})}return _r().on("start",f).on("drag",T).on("end",w)}function V(){n(2,k=!0),u.update({status:ie.dragging})}function X(){n(2,k=!1),I(m),u.update({status:ie.masking})}function J(){I(m)}function te(f){Et[f?"unshift":"push"](()=>{s=f,Dn.set(s)})}const ae=()=>c("prompt");function be(f){Et[f?"unshift":"push"](()=>{b=f,n(1,b)})}return e.$$set=f=>{"transform"in f&&n(0,p=f.transform)},e.$$.update=()=>{e.$$.dirty&16384&&n(6,r=l==null?void 0:l.currentPrompt),e.$$.dirty&16384&&n(4,i=(l==null?void 0:l.status)===ie.loading||(l==null?void 0:l.status)===ie.prompting||!1),e.$$.dirty&8193&&n(5,o={x:p.applyX(m.x),y:p.applyY(m.y)})},[p,b,k,O,i,o,r,s,u,c,V,X,J,m,l,te,ae,be]}class Bc extends pe{constructor(t){super(),me(this,t,Vc,Fc,_e,{transform:0})}}const Xc="wss://spaces.huggingface.tech/huggingface-projects/stable-diffusion-multiplayer/gradio/queue/join",Yc="https://hf.space/embed/huggingface-projects/stable-diffusion-multiplayer/uploads";function qc(e){let t,n,r,i;const o=e[8].default,s=zn(o,e,e[7],null);return{c(){t=q("div"),n=q("canvas"),r=he(),s&&s.c(),this.h()},l(a){t=j(a,"DIV",{class:!0});var l=U(t);n=j(l,"CANVAS",{width:!0,height:!0,class:!0}),U(n).forEach(x),r=de(l),s&&s.l(l),l.forEach(x),this.h()},h(){g(n,"width",e[4]),g(n,"height",e[3]),g(n,"class","absolute top-0 left-0 bg-white svelte-6dcxg7"),g(t,"class","absolute top-0 left-0 right-0 bottom-0 overflow-hidden z-0 bg-gray-800")},m(a,l){Y(a,t,l),F(t,n),e[9](n),F(t,r),s&&s.m(t,null),e[10](t),i=!0},p(a,[l]){s&&s.p&&(!i||l&128)&&Hn(s,o,a,a[7],i?Fn(o,a[7],l,null):Kn(a[7]),null)},i(a){i||(M(s,a),i=!0)},o(a){B(s,a),i=!1},d(a){a&&x(t),e[9](null),s&&s.d(a),e[10](null)}}}function jc(e,t,n){let r,i,o;Te(e,Un,C=>n(12,r=C)),Te(e,Gt,C=>n(1,i=C));let{$$slots:s={},$$scope:a}=t;const l=dn(),u=Ri("promptImgStorage");Te(e,u,C=>n(6,o=C));const c=512*5,p=512*5;let d,m;const b=new Set;function k(C){return C?Object.values(C).sort((X,J)=>X.date-J.date).filter(({id:X})=>!b.has(X)):[]}let O=[];Lt(()=>{const V=(p+400)/(d.clientHeight>d.clientWidth?d.clientWidth:d.clientHeight),X=Kc().scaleExtent([1/V/2,3]).translateExtent([[-200,-200],[p+200,c+200]]).tapDistance(10).on("zoom",P),J=Ae(i.parentElement).call(X).call(X.transform,Tt).call(X.scaleTo,1/V).on("pointermove",I).on("pointerleave",y);m=i.getContext("2d");function te(){const ae=(p+400)/(d.clientHeight>d.clientWidth?d.clientWidth:d.clientHeight);J.call(X.transform,Tt),J.call(X.scaleTo,1/ae)}return window.addEventListener("resize",te),()=>{window.removeEventListener("resize",te)}});function _(C){Promise.all(C.map(({imgURL:V,position:X,id:J})=>new Promise(te=>{const ae=new Image;ae.crossOrigin="anonymous",ae.onload=()=>{const f={img:ae,position:X,id:J};m.drawImage(ae,X.x,X.y,ae.width,ae.height),te(f)};const be=V.split("/");ae.src=`${Yc}/${be.slice(3).join("/")}`}))).then(V=>{V.forEach(({img:X,position:J,id:te})=>{b.add(te),m.drawImage(X,J.x,J.y,X.width,X.height)})})}function P(C){const V=ke(Un,r=C.transform,r);ke(Gt,i.style.transform=`translate(${V.x}px, ${V.y}px) scale(${V.k})`,i)}function I(C){C.preventDefault();const V=r.invertX(C.clientX),X=r.invertY(C.clientY);l.update({cursor:{x:V,y:X}})}function y(){l.update({cursor:null})}function D(C){Et[C?"unshift":"push"](()=>{i=C,Gt.set(i)})}function H(C){Et[C?"unshift":"push"](()=>{d=C,n(0,d)})}return e.$$set=C=>{"$$scope"in C&&n(7,a=C.$$scope)},e.$$.update=()=>{e.$$.dirty&64&&n(5,O=k(o==null?void 0:o.toObject())),e.$$.dirty&32&&O&&_(O)},[d,i,u,c,p,O,o,a,s,D,H]}class Gc extends pe{constructor(t){super(),me(this,t,jc,qc,_e,{})}}function Jc(e){let t,n,r;return n=new yi({}),n.$on("click",e[1]),{c(){t=q("div"),le(n.$$.fragment),this.h()},l(i){t=j(i,"DIV",{class:!0});var o=U(t);ue(n.$$.fragment,o),o.forEach(x),this.h()},h(){g(t,"class","grid grid-cols-1 gap-3 w-max mx-auto")},m(i,o){Y(i,t,o),ce(n,t,null),r=!0},p:ge,i(i){r||(M(n.$$.fragment,i),r=!0)},o(i){B(n.$$.fragment,i),r=!1},d(i){i&&x(t),fe(n)}}}function Wc(e){const t=Vn(),n=i=>{i.key==="Enter"&&t("prompt")};return Lt(()=>(window.addEventListener("keyup",n),()=>{window.removeEventListener("keyup",n)})),[t,()=>t("prompt")]}class Zc extends pe{constructor(t){super(),me(this,t,Wc,Jc,_e,{})}}function Qc(e){let t,n,r,i,o,s,a,l;return{c(){t=q("form"),n=q("div"),r=q("input"),i=he(),o=q("button"),s=Ze("Paint"),this.h()},l(u){t=j(u,"FORM",{class:!0});var c=U(t);n=j(c,"DIV",{class:!0});var p=U(n);r=j(p,"INPUT",{class:!0,placeholder:!0,title:!0,type:!0,name:!0}),i=de(p),o=j(p,"BUTTON",{class:!0,type:!0});var d=U(o);s=Qe(d,"Paint"),d.forEach(x),p.forEach(x),c.forEach(x),this.h()},h(){g(r,"class","input svelte-1ayu15l"),g(r,"placeholder","Type a prompt..."),g(r,"title","Input prompt to generate image and obtain palette"),g(r,"type","text"),g(r,"name","prompt"),g(o,"class","font-mono border-l-2 pl-2"),g(o,"type","submit"),g(n,"class","flex bg-white rounded-2xl px-2 w-full max-w-md"),g(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(u,c){Y(u,t,c),F(t,n),F(n,r),e[5](r),F(n,i),F(n,o),F(o,s),a||(l=[Xe(r,"click",ho(e[4])),Xe(r,"input",e[2]),Xe(o,"click",or(e[1])),Xe(t,"submit",or(e[1])),Xe(t,"click",e[3])],a=!0)},p:ge,i:ge,o:ge,d(u){u&&x(t),e[5](null),a=!1,po(l)}}}function ef(e,t,n){const r=Vn();let i="",o;const s=dn(),a=k=>{k.key==="Escape"&&d()};Lt(()=>(o.focus(),i="",window.addEventListener("keyup",a),()=>{window.removeEventListener("keyup",a)}));let l;function u(k){clearTimeout(l),l=setTimeout(()=>{i=k,s.update({currentPrompt:i,status:ie.prompting})},100)}function c(){i.trim()!==""&&(console.log("Prompting with: ",i),r("paint"))}function p(k){const O=k.target;u(O.value)}function d(){s.update({currentPrompt:"",status:ie.ready}),r("close")}function m(k){At.call(this,e,k)}function b(k){Et[k?"unshift":"push"](()=>{o=k,n(0,o)})}return[o,c,p,d,m,b]}class tf extends pe{constructor(t){super(),me(this,t,ef,Qc,_e,{})}}var ji={},Gi={},er={exports:{}},ne=String,Ji=function(){return{isColorSupported:!1,reset:ne,bold:ne,dim:ne,italic:ne,underline:ne,inverse:ne,hidden:ne,strikethrough:ne,black:ne,red:ne,green:ne,yellow:ne,blue:ne,magenta:ne,cyan:ne,white:ne,gray:ne,bgBlack:ne,bgRed:ne,bgGreen:ne,bgYellow:ne,bgBlue:ne,bgMagenta:ne,bgCyan:ne,bgWhite:ne}};er.exports=Ji();er.exports.createColors=Ji;(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(er.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(p=>console.warn(l,"-",p)))}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])}}})(Gi);(function(e){Object.defineProperty(e,"__esModule",{value:!0}),Object.defineProperty(e,"default",{enumerable:!0,get:()=>i});const t=n(Gi);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}}})(ji);let Pn=ji;var nf=(Pn.__esModule?Pn:{default:Pn}).default;const Ft=Object.values(nf).filter(e=>typeof e=="object").map(e=>e[200]).slice(0,18),Vt=["\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 rf=(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 Ur(e,t,n){const r=e.slice();return r[16]=t[n].connectionId,r[17]=t[n].presence,r}function Dr(e){let t,n;return t=new tf({}),t.$on("paint",e[9]),t.$on("close",e[8]),{c(){le(t.$$.fragment)},l(r){ue(t.$$.fragment,r)},m(r,i){ce(t,r,i),n=!0},p:ge,i(r){n||(M(t.$$.fragment,r),n=!0)},o(r){B(t.$$.fragment,r),n=!1},d(r){fe(t,r)}}}function zr(e){let t=[],n=new Map,r,i,o=[...e[3]];const s=a=>a[16];for(let a=0;a<o.length;a+=1){let l=Ur(e,o,a),u=s(l);n.set(u,t[a]=Fr(u,l))}return{c(){for(let a=0;a<t.length;a+=1)t[a].c();r=We()},l(a){for(let l=0;l<t.length;l+=1)t[l].l(a);r=We()},m(a,l){for(let u=0;u<t.length;u+=1)t[u].m(a,l);Y(a,r,l),i=!0},p(a,l){l&12&&(o=[...a[3]],ze(),t=mo(t,l,s,1,a,o,n,r.parentNode,_o,Fr,r,Ur),He())},i(a){if(!i){for(let l=0;l<o.length;l+=1)M(t[l]);i=!0}},o(a){for(let l=0;l<t.length;l+=1)B(t[l]);i=!1},d(a){for(let l=0;l<t.length;l+=1)t[l].d(a);a&&x(r)}}}function Hr(e){var r,i,o;let t,n;return t=new Us({props:{isLoading:((r=e[17])==null?void 0:r.status)===ie.loading,position:(i=e[17])==null?void 0:i.frame,prompt:(o=e[17])==null?void 0:o.currentPrompt,transform:e[2]}}),{c(){le(t.$$.fragment)},l(s){ue(t.$$.fragment,s)},m(s,a){ce(t,s,a),n=!0},p(s,a){var u,c,p;const l={};a&8&&(l.isLoading=((u=s[17])==null?void 0:u.status)===ie.loading),a&8&&(l.position=(c=s[17])==null?void 0:c.frame),a&8&&(l.prompt=(p=s[17])==null?void 0:p.currentPrompt),a&4&&(l.transform=s[2]),t.$set(l)},i(s){n||(M(t.$$.fragment,s),n=!0)},o(s){B(t.$$.fragment,s),n=!1},d(s){fe(t,s)}}}function Kr(e){var r;let t,n;return t=new Ns({props:{emoji:Vt[1+e[16]%(Vt.length-1)],color:Ft[1+e[16]%(Ft.length-1)],position:(r=e[17])==null?void 0:r.cursor,transform:e[2]}}),{c(){le(t.$$.fragment)},l(i){ue(t.$$.fragment,i)},m(i,o){ce(t,i,o),n=!0},p(i,o){var a;const s={};o&8&&(s.emoji=Vt[1+i[16]%(Vt.length-1)]),o&8&&(s.color=Ft[1+i[16]%(Ft.length-1)]),o&8&&(s.position=(a=i[17])==null?void 0:a.cursor),o&4&&(s.transform=i[2]),t.$set(s)},i(i){n||(M(t.$$.fragment,i),n=!0)},o(i){B(t.$$.fragment,i),n=!1},d(i){fe(t,i)}}}function Fr(e,t){var l,u,c,p,d;let n,r,i,o,s=(((l=t[17])==null?void 0:l.status)===ie.loading||((u=t[17])==null?void 0:u.status)===ie.prompting||((c=t[17])==null?void 0:c.status)===ie.masking)&&((p=t[17])==null?void 0:p.frame)&&Hr(t),a=((d=t[17])==null?void 0:d.cursor)&&Kr(t);return{key:e,first:null,c(){n=We(),s&&s.c(),r=he(),a&&a.c(),i=We(),this.h()},l(m){n=We(),s&&s.l(m),r=de(m),a&&a.l(m),i=We(),this.h()},h(){this.first=n},m(m,b){Y(m,n,b),s&&s.m(m,b),Y(m,r,b),a&&a.m(m,b),Y(m,i,b),o=!0},p(m,b){var k,O,_,P,I;t=m,(((k=t[17])==null?void 0:k.status)===ie.loading||((O=t[17])==null?void 0:O.status)===ie.prompting||((_=t[17])==null?void 0:_.status)===ie.masking)&&((P=t[17])==null?void 0:P.frame)?s?(s.p(t,b),b&8&&M(s,1)):(s=Hr(t),s.c(),M(s,1),s.m(r.parentNode,r)):s&&(ze(),B(s,1,1,()=>{s=null}),He()),(I=t[17])!=null&&I.cursor?a?(a.p(t,b),b&8&&M(a,1)):(a=Kr(t),a.c(),M(a,1),a.m(i.parentNode,i)):a&&(ze(),B(a,1,1,()=>{a=null}),He())},i(m){o||(M(s),M(a),o=!0)},o(m){B(s),B(a),o=!1},d(m){m&&x(n),s&&s.d(m),m&&x(r),a&&a.d(m),m&&x(i)}}}function of(e){let t,n,r,i,o,s,a,l,u,c,p,d,m,b,k=e[0]&&Dr(e);s=new Gc({}),u=new Bc({props:{transform:e[2]}}),u.$on("prompt",e[7]);let O=e[3]&&zr(e);return m=new Zc({}),m.$on("prompt",e[7]),{c(){t=q("div"),n=Ze(e[1]),r=he(),k&&k.c(),i=he(),o=q("div"),le(s.$$.fragment),a=he(),l=q("main"),le(u.$$.fragment),c=he(),O&&O.c(),p=he(),d=q("div"),le(m.$$.fragment),this.h()},l(_){t=j(_,"DIV",{class:!0});var P=U(t);n=Qe(P,e[1]),P.forEach(x),r=de(_),k&&k.l(_),i=de(_),o=j(_,"DIV",{class:!0});var I=U(o);ue(s.$$.fragment,I),a=de(I),l=j(I,"MAIN",{class:!0});var y=U(l);ue(u.$$.fragment,y),c=de(y),O&&O.l(y),y.forEach(x),I.forEach(x),p=de(_),d=j(_,"DIV",{class:!0});var D=U(d);ue(m.$$.fragment,D),D.forEach(x),this.h()},h(){g(t,"class","text touch-none pointer-events-none"),g(l,"class","z-10 relative"),g(o,"class","fixed top-0 left-0 z-0 w-screen h-screen"),g(d,"class","fixed bottom-0 left-0 right-0 z-10 my-2")},m(_,P){Y(_,t,P),F(t,n),Y(_,r,P),k&&k.m(_,P),Y(_,i,P),Y(_,o,P),ce(s,o,null),F(o,a),F(o,l),ce(u,l,null),F(l,c),O&&O.m(l,null),Y(_,p,P),Y(_,d,P),ce(m,d,null),b=!0},p(_,[P]){(!b||P&2)&&sn(n,_[1]),_[0]?k?(k.p(_,P),P&1&&M(k,1)):(k=Dr(_),k.c(),M(k,1),k.m(i.parentNode,i)):k&&(ze(),B(k,1,1,()=>{k=null}),He());const I={};P&4&&(I.transform=_[2]),u.$set(I),_[3]?O?(O.p(_,P),P&8&&M(O,1)):(O=zr(_),O.c(),M(O,1),O.m(l,null)):O&&(ze(),B(O,1,1,()=>{O=null}),He())},i(_){b||(M(k),M(s.$$.fragment,_),M(u.$$.fragment,_),M(O),M(m.$$.fragment,_),b=!0)},o(_){B(k),B(s.$$.fragment,_),B(u.$$.fragment,_),B(O),B(m.$$.fragment,_),b=!1},d(_){_&&x(t),_&&x(r),k&&k.d(_),_&&x(i),_&&x(o),fe(s),fe(u),O&&O.d(),_&&x(p),_&&x(d),fe(m)}}}function sf({position:e}){return`${e.x}_${e.y}`}function af(e,t,n){let r,i,o,s,a,l,u;Te(e,Oe,I=>n(1,i=I)),Te(e,Dn,I=>n(13,s=I)),Te(e,Un,I=>n(2,l=I));const c=dn();Te(e,c,I=>n(10,a=I));const p=Jl();Te(e,p,I=>n(3,u=I));const d={cursor:null,frame:null,status:ie.dragging,currentPrompt:""};c.update(d);const m=Ri("promptImgStorage");Te(e,m,I=>n(12,o=I));let b=!1;function k(){r||(n(0,b=!0),c.update({status:ie.prompting}))}function O(){n(0,b=!1)}function _(){console.log("onPaint"),P(),n(0,b=!1)}async function P(){if(r)return;ke(Oe,i="Pending",i);const I=a.currentPrompt,y=a.frame;console.log("Generating...",I,y),c.update({status:ie.loading});const D=crypto.randomUUID(),H=s.toDataURL("image/png"),C={fn_index:0,data:[H,I,.75,7.5,40,"patchmatch"],session_hash:D};console.log("payload",C);const V=new WebSocket(Xc);V.onclose=X=>{X.wasClean||(ke(Oe,i="Error",i),c.update({status:ie.ready}))},V.onmessage=async function(X){try{const J=JSON.parse(X.data);switch(ke(Oe,i="",i),J.msg){case"send_data":ke(Oe,i="Sending Data",i),V.send(JSON.stringify(C));break;case"queue_full":ke(Oe,i="Queue full",i),V.close(),c.update({status:ie.ready});return;case"estimation":const{rank:te,queue_size:ae}=J;ke(Oe,i=`On queue ${te}/${ae}`,i);break;case"process_generating":ke(Oe,i=J.success?"Generating":"Error",i);break;case"process_completed":try{const be=J.output.data[0];if(J.output.data[1])throw new Error("Potential NFSW content, please try again");const T=await ql(be),w=await jl(T,I),S={prompt:I,imgURL:w,position:y,date:new Date().getTime(),id:rf()},L=sf(S);o.set(L,S),console.log(w),ke(Oe,i=J.success?"Complete":"Error",i),setTimeout(()=>{ke(Oe,i="",i)},2e3)}catch(be){const f=be;ke(Oe,i=f==null?void 0:f.message,i)}V.close(),c.update({status:ie.ready});return;case"process_starts":ke(Oe,i="Processing",i);break}}catch(J){console.error(J),ke(Oe,i="Error",i)}}}return e.$$.update=()=>{e.$$.dirty&1024&&(r=(a==null?void 0:a.status)===ie.loading||!1),e.$$.dirty&1024&&console.log(a.status)},[b,i,l,u,c,p,m,k,O,_,a]}class lf extends pe{constructor(t){super(),me(this,t,af,of,_e,{})}}function Vr(e){let t,n;return t=new xs({props:{client:e[2],$$slots:{default:[cf]},$$scope:{ctx:e}}}),{c(){le(t.$$.fragment)},l(r){ue(t.$$.fragment,r)},m(r,i){ce(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||(M(t.$$.fragment,r),n=!0)},o(r){B(t.$$.fragment,r),n=!1},d(r){fe(t,r)}}}function uf(e){let t,n;return t=new lf({}),{c(){le(t.$$.fragment)},l(r){ue(t.$$.fragment,r)},m(r,i){ce(t,r,i),n=!0},i(r){n||(M(t.$$.fragment,r),n=!0)},o(r){B(t.$$.fragment,r),n=!1},d(r){fe(t,r)}}}function cf(e){let t,n;return t=new Ss({props:{id:e[0],$$slots:{default:[uf]},$$scope:{ctx:e}}}),{c(){le(t.$$.fragment)},l(r){ue(t.$$.fragment,r)},m(r,i){ce(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||(M(t.$$.fragment,r),n=!0)},o(r){B(t.$$.fragment,r),n=!1},d(r){fe(t,r)}}}function ff(e){let t,n,r=e[1]&&Vr(e);return{c(){r&&r.c(),t=We()},l(i){r&&r.l(i),t=We()},m(i,o){r&&r.m(i,o),Y(i,t,o),n=!0},p(i,[o]){i[1]?r?(r.p(i,o),o&2&&M(r,1)):(r=Vr(i),r.c(),M(r,1),r.m(t.parentNode,t)):r&&(ze(),B(r,1,1,()=>{r=null}),He())},i(i){n||(M(r),n=!0)},o(i){B(r),n=!1},d(i){r&&r.d(i),i&&x(t)}}}const mf=!0;function hf(e,t,n){let r,i=!1,o;return Lt(()=>{document.addEventListener("wheel",s=>s.preventDefault(),{passive:!1}),n(0,r="multiplayer-SD"),n(2,o=bs({publicApiKey:"pk_test_JlUZGH3kQmhmZQiqU2l8eIi5"})),n(1,i=!0)}),[r,i,o]}class _f extends pe{constructor(t){super(),me(this,t,hf,ff,_e,{})}}export{_f as default,mf as prerender};