Spaces:
Runtime error
Runtime error
import{S as pe,i as me,s as _e,B as zn,C as Hn,D as Fn,E as Kn,f as H,t as q,H as Yr,I as qr,J as on,K as Se,L as Pe,m as $,h as x,n as g,b as B,F,A as we,k as X,v as ce,a as se,l as Y,w as fe,c as oe,x as he,y as de,q as Re,r as Me,u as At,g as Fe,d as Ke,M as Ze,N as Lt,G as Ie,O as Vn,o as Nt,P as Et,Q as Ee,R as ps,T as sr,U as ms,e as Qe,V as _s,W as gs}from"../../chunks/index-9b9f3ff6.js";import{w as et}from"../../chunks/index-8910d5bb.js";var vs=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},$e={},K={};Object.defineProperty(K,"__esModule",{value:!0});var ys=Object.defineProperty,ws=Object.defineProperties,bs=Object.getOwnPropertyDescriptors,Wt=Object.getOwnPropertySymbols,jr=Object.prototype.hasOwnProperty,Gr=Object.prototype.propertyIsEnumerable,or=(e,t,n)=>t in e?ys(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ct=(e,t)=>{for(var n in t||(t={}))jr.call(t,n)&&or(e,n,t[n]);if(Wt)for(var n of Wt(t))Gr.call(t,n)&&or(e,n,t[n]);return e},an=(e,t)=>ws(e,bs(t)),ks=(e,t)=>{var n={};for(var r in e)jr.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Wt)for(var r of Wt(e))t.indexOf(r)<0&&Gr.call(e,r)&&(n[r]=e[r]);return n},Es=(e,t,n)=>new Promise((r,i)=>{var s=l=>{try{o(n.next(l))}catch(u){i(u)}},a=l=>{try{o(n.throw(l))}catch(u){i(u)}},o=l=>l.done?r(l.value):Promise.resolve(l.value).then(s,a);o((n=n.apply(e,t)).next())});function xs(e,t=e){}function Os(e,t,n=t){}function Is(e){}function Ss(e,t){}function We(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||{}),Wr=(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))(Wr||{}),Zr=(e=>(e[e.OBJECT=0]="OBJECT",e[e.LIST=1]="LIST",e[e.MAP=2]="MAP",e[e.REGISTER=3]="REGISTER",e))(Zr||{});function Ps(e){return e.type===0&&!Qr(e)}function Qr(e){return e.parentId!==void 0&&e.parentKey!==void 0}var ei=(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))(ei||{});function Ts(e){return e==="my-presence"||e==="others"||e==="event"||e==="error"||e==="connection"||e==="history"}var ti=(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))(ti||{}),lt=32,Bn=126;function ze(e,t){return e!==void 0&&t!==void 0?Zt(ni(mt(e),mt(t))):e!==void 0?Ls(e):t!==void 0?As(t):Zt([lt+1])}function As(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 Zt(t)}function Ls(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 Zt(t)}function ni(e,t){let n=0;const r=[];for(;;){const i=e[n]||lt,s=t[n]||Bn;if(i>s)throw new Error(`Impossible to generate position between ${e} and ${t}`);if(i===s){r.push(i),n++;continue}if(s-i===1){r.push(i),r.push(...ni(e.slice(n+1),[]));break}const a=s+i>>1;r.push(a);break}return r}function mt(e){const t=[];for(let n=0;n<e.length;n++)t.push(e.charCodeAt(n));return t}function Zt(e){return String.fromCharCode(...e)}function ri(e,t){const n=mt(e),r=mt(t),i=Math.max(n.length,r.length);for(let s=0;s<i;s++){const a=n[s]===void 0?lt:n[s],o=r[s]===void 0?lt:r[s];if(a!==o)return a-o}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 We(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 We(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 We(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 We(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:We(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}},Ge=class extends ln{constructor(e){super(),this._data=e}get data(){return this._data}static _deserialize([e,t],n,r){const i=new Ge(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[s,a]of this._map)r.push(...a._toOps(this._id,s,n));return r}static _deserialize([e,t],n,r){const i=new tt;i._attach(e,r);const s=n.get(e);if(s===void 0)return i;for(const[a,o]of s){const l=oi([a,o],n,r);l._setParentLink(i,o.parentKey),i._map.set(o.parentKey,l),i.invalidate()}return i}_attach(e,t){super._attach(e,t);for(const[n,r]of this._map)ge(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,s=r,a=wt(e);if(this._pool.getNode(n)!==void 0)return{modified:!1};if(t===2){const u=this.unacknowledgedSet.get(s);if(u===i)return this.unacknowledgedSet.delete(s),{modified:!1};if(u!==void 0)return{modified:!1}}else t===1&&this.unacknowledgedSet.delete(s);const o=this._map.get(s);let l;if(o){const u=G(this._id);l=o._toOps(u,s),o._detach()}else l=[{type:5,id:n}];return a._setParentLink(this,s),a._attach(n,this._pool),this._map.set(s,a),this.invalidate(),{modified:{node:this,type:"LiveMap",updates:{[s]:{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[s,a]of this._map)a===e&&(this._map.delete(s),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 ot(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 s=new Map;s.set(this._id,{node:this,type:"LiveMap",updates:{[e]:{type:"update"}}});const a=r._toOps(this._id,e,this._pool);this.unacknowledgedSet.set(e,G(a[0].opId)),this._pool.dispatch(r._toOps(this._id,e,this._pool),n?n._toOps(this._id,e):[{type:5,id:i}],s)}}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=ot(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:ot(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&&ge(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=[],s=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(s);for(const[a,o]of this._map)ge(o)?i.push(...o._toOps(this._id,a,n)):s.data[a]=o;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,s]of r){const a=Rs([i,s],t,n);Xt(a)&&a._setParentLink(e,s.parentKey),e._map.set(s.parentKey,a),e.invalidate()}return e}_attach(e,t){super._attach(e,t);for(const[n,r]of this._map)ge(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,s=ii(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 a=G(this._id),o=this._map.get(i);let l;return ge(o)?(l=o._toOps(a,i),o._detach()):o===void 0?l=[{type:6,id:a,key:i}]:l=[{type:3,id:a,data:{[i]:o}}],this._map.set(i,s),this.invalidate(),Xt(s)&&(s._setParentLink(this,i),s._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[s,a]of this._map)a===e&&(this._map.delete(s),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())ge(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)ge(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=[],s={type:3,id:r,data:{}};i.push(s);for(const o in e.data){const l=this._map.get(o);ge(l)?(i.push(...l._toOps(r,o)),l._detach()):l!==void 0?s.data[o]=l:l===void 0&&i.push({type:6,id:r,key:o})}const a={};for(const o in e.data){const l=e.data[o];if(l===void 0)continue;if(t)this._propToLastUpdate.set(o,G(e.opId));else if(this._propToLastUpdate.get(o)===void 0)n=!0;else if(this._propToLastUpdate.get(o)===e.opId){this._propToLastUpdate.delete(o);continue}else continue;const u=this._map.get(o);ge(u)&&u._detach(),n=!0,a[o]={type:"update"},this._map.set(o,l),this.invalidate()}return Object.keys(s.data).length!==0&&i.unshift(s),n?{modified:{node:this,type:"LiveObject",updates:a},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 ge(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 Ks(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){ge(n)&&n._detach(),this._map.delete(t),this.invalidate();return}let r;ge(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);ge(c)&&c._detach(),ge(u)&&u._setParentLink(this,l),this._map.set(l,u),this.invalidate()}return}const t=[],n=[],r=this._pool.generateOpId(),i={},s={id:this._id,type:3,data:{}},a={};for(const l in e){const u=e[l];if(u===void 0)continue;const c=this._map.get(l);if(ge(c)?(n.push(...c._toOps(this._id,l)),c._detach()):c===void 0?n.push({type:6,id:this._id,key:l}):s.data[l]=c,ge(u)){u._setParentLink(this,l),u._attach(this._pool.generateId(),this._pool);const m=u._toOps(this._id,l,this._pool),h=m.find(_=>_.parentId===this._id);h&&this._propToLastUpdate.set(l,G(h.opId)),t.push(...m)}else i[l]=u,this._propToLastUpdate.set(l,r);this._map.set(l,u),this.invalidate(),a[l]={type:"update"}}Object.keys(s.data).length!==0&&n.unshift(s),Object.keys(i).length!==0&&t.unshift({opId:r,id:this._id,type:3,data:i});const o=new Map;o.set(this._id,{node:this,type:"LiveObject",updates:a}),this._pool.dispatch(t,n,o)}toImmutable(){return super.toImmutable()}_toImmutable(){const e={};for(const[t,n]of this._map)e[t]=Xt(n)?n.toImmutable():n;return e}},Xn=e=>e;function Ns(e){return e.filter(t=>t!=null)}function Cs(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(ii(e))}function ii(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 We(e,"Unknown creation Op")}}function si(e,t){return e===t?!0:e.parent.type==="HasParent"?si(e.parent.node,t):!1}function oi([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 Ge._deserialize([e,t],n,r);default:throw new Error("Unexpected CRDT type")}}function Rs([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 Xt(e){return ai(e)||Ms(e)||li(e)}function ge(e){return Xt(e)||$s(e)}function ai(e){return e instanceof rt}function Ms(e){return e instanceof tt}function li(e){return e instanceof nt}function $s(e){return e instanceof Ge}function ot(e){return e instanceof Ge?e.data:e instanceof rt||e instanceof tt||e instanceof nt?e:We(e,"Unknown AbstractCrdt")}function ht(e){return e instanceof nt||e instanceof tt||e instanceof rt?e:new Ge(e)}function Ds(e,t){const n=[];return e.forEach((r,i)=>{t.get(i)||n.push({type:5,id:i})}),t.forEach((r,i)=>{const s=e.get(i);if(s)r.type===0&&(s.type!==0||JSON.stringify(r.data)!==JSON.stringify(s.data))&&n.push({type:3,id:i,data:r.data}),r.parentKey!==s.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 Us(e,t){const n=e.updates;for(const[r,i]of ci(t.updates))n[r]=i;return an(Ct({},t),{updates:n})}function zs(e,t){const n=e.updates;for(const[r,i]of ci(t.updates))n[r]=i;return an(Ct({},t),{updates:n})}function Hs(e,t){const n=e.updates;return an(Ct({},t),{updates:n.concat(t.updates)})}function Fs(e,t){return e?e.type==="LiveObject"&&t.type==="LiveObject"?Us(e,t):e.type==="LiveMap"&&t.type==="LiveMap"?zs(e,t):e.type==="LiveList"&&t.type==="LiveList"?Hs(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 ui(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 s=ui(r,i);if(s)return s}}return!1}function Ks(e){const t={};for(const[n,r]of e)t[n]=r;return t}function ci(e){return Object.entries(e)}function fi(e){try{return JSON.parse(e)}catch{return}}function hi(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 Vs(e,t){return ri(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=ze(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[s,a]of i){const o=oi([s,a],t,n);o._setParentLink(r,a.parentKey),r._insertAndSort(o)}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 s of this._items)r.push(...s._toOps(this._id,s._getParentKeyOrThrow(),n));return r}_insertAndSort(e){this._items.push(e),this._sortItems()}_sortItems(){this._items.sort(Vs),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,s=this._indexOfPosition(n);if(s!==-1){const a=this._items[s];if(a._id===i)return a._detach(),this._items[s]=r,{modified:ee(this,[ft(s,r)]),reverse:[]};{this._implicitlyDeletedItems.add(a),this._items[s]=r;const o=[ft(s,r)],l=this._detachItemAssociatedToSetOperation(e.deletedId);return l&&o.push(l),{modified:ee(this,o),reverse:[]}}}else{const a=[],o=this._detachItemAssociatedToSetOperation(e.deletedId);return o&&a.push(o),this._insertAndSort(r),a.push(Ue(this._indexOfPosition(n),r)),{reverse:[],modified:ee(this,a)}}}_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),s=this._items.find(a=>a._id===e.id);if(s!==void 0){if(s._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 a=this._items.indexOf(s);s._setParentLink(this,e.parentKey),this._sortItems();const o=this._items.indexOf(s);return o!==a&&t.push(it(a,o,s)),{modified:t.length>0?ee(this,t):!1,reverse:[]}}else{const a=this._pool.getNode(e.id);if(a&&this._implicitlyDeletedItems.has(a)){a._setParentLink(this,e.parentKey),this._implicitlyDeletedItems.delete(a),this._insertAndSort(a);const o=this._items.indexOf(a);return{modified:ee(this,[i===-1?Ue(o,a):ft(o,a),...t]),reverse:[]}}else{i!==-1&&this._items.splice(i,1);const{newItem:o,newIndex:l}=this._createAttachItemAndSort(e,e.parentKey);return{modified:ee(this,[i===-1?Ue(l,o):ft(l,o),...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,[Ue(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 s=this._indexOfPosition(n);return s===i?{modified:!1}:{modified:ee(this,[it(i,s,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 s=this._indexOfPosition(n);return{modified:ee(this,[Ue(s,i)]),reverse:[]}}else{r!==-1&&this._shiftItemPosition(r,n);const{newItem:s,newIndex:a}=this._createAttachItemAndSort(e,n);return{modified:ee(this,[Ue(a,s)]),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 s=this._indexOfPosition(r);let a=r;if(s!==-1){const l=this._items[s]?this._items[s]._getParentKeyOrThrow():void 0,u=this._items[s+1]?this._items[s+1]._getParentKeyOrThrow():void 0;a=ze(l,u),i._setParentLink(this,a)}this._insertAndSort(i);const o=this._indexOfPosition(a);return{modified:ee(this,[Ue(o,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 s=this._indexOfPosition(r);i._attach(n,G(this._pool)),i._setParentLink(this,r);const a=r;if(s!==-1){const o=this._items[s];o._detach(),this._items[s]=i;const l=o._toOps(G(this._id),r,this._pool);yn(l,e.id);const u=[ft(s,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 o=this._indexOfPosition(a);return{reverse:[{type:5,id:n}],modified:ee(this,[Ue(o,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 s=this._items.indexOf(t);return{modified:ee(this,[Ue(s,t)]),reverse:[]}}const r=t._parentKey;if(e===r)return{modified:!1};const i=this._indexOfPosition(e);if(i===-1){const s=this._items.indexOf(t);t._setParentLink(this,e),this._sortItems();const a=this._items.indexOf(t);return a===s?{modified:!1}:{modified:ee(this,[it(s,a,t)]),reverse:[]}}else{this._items[i]._setParentLink(this,ze(e,(n=this._items[i+1])==null?void 0:n._getParentKeyOrThrow()));const s=this._items.indexOf(t);t._setParentLink(this,e),this._sortItems();const a=this._items.indexOf(t);return a===s?{modified:!1}:{modified:ee(this,[it(s,a,t)]),reverse:[]}}}_applySetChildKeyAck(e,t){var n,r;const i=G(t._parentKey);if(this._implicitlyDeletedItems.has(t)){const s=this._indexOfPosition(e);return this._implicitlyDeletedItems.delete(t),s!==-1&&this._items[s]._setParentLink(this,ze(e,(n=this._items[s+1])==null?void 0:n._getParentKeyOrThrow())),t._setParentLink(this,e),this._insertAndSort(t),{modified:!1}}else{if(e===i)return{modified:!1};const s=this._items.indexOf(t),a=this._indexOfPosition(e);a!==-1&&this._items[a]._setParentLink(this,ze(e,(r=this._items[a+1])==null?void 0:r._getParentKeyOrThrow())),t._setParentLink(this,e),this._sortItems();const o=this._items.indexOf(t);return s===o?{modified:!1}:{modified:ee(this,[it(s,o,t)]),reverse:[]}}}_applySetChildKeyUndoRedo(e,t){var n;const r=G(t._parentKey),i=this._items.indexOf(t),s=this._indexOfPosition(e);s!==-1&&this._items[s]._setParentLink(this,ze(e,(n=this._items[s+1])==null?void 0:n._getParentKeyOrThrow())),t._setParentLink(this,e),this._sortItems();const a=this._items.indexOf(t);return i===a?{modified:!1}:{modified:ee(this,[it(i,a,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=ze(n,r),s=ht(e);if(s._setParentLink(this,i),this._insertAndSort(s),this._pool&&this._id){const a=this._pool.generateId();s._attach(a,this._pool),this._pool.dispatch(s._toOps(this._id,i,this._pool),[{type:5,id:a}],new Map([[this._id,ee(this,[Ue(t,s)])]]))}}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=ze(n,r),s=this._items[e],a=s._getParentKeyOrThrow();if(s._setParentLink(this,i),this._sortItems(),this._pool&&this._id){const o=new Map([[this._id,ee(this,[it(e,t,s)])]]);this._pool.dispatch([{type:1,id:G(s._id),opId:this._pool.generateOpId(),parentKey:i}],[{type:1,id:G(s._id),parentKey:a}],o)}}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 s=i._id;s&&(e.push({type:5,id:s,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 s=ht(t);if(s._setParentLink(this,r),this._items[e]=s,this.invalidate(),this._pool&&this._id){const a=this._pool.generateId();s._attach(a,this._pool);const o=new Map;o.set(this._id,ee(this,[ft(e,s)]));const l=s._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,a),this._pool.dispatch(l,u,o)}}toArray(){return this._items.map(e=>ot(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 ot(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(ot(t),n))}some(e){return this.toArray().some(e)}[Symbol.iterator](){return new Bs(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=ze(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())}},Bs=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:ot(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 Ge?t.data:t}}function $t(e){return{index:e,type:"delete"}}function Ue(e,t){return{index:e,type:"insert",item:t instanceof Ge?t.data:t}}function it(e,t,n){return{index:t,type:"move",previousIndex:e,item:n instanceof Ge?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 Xs=["websocket:presence","websocket:storage","room:read","room:write","rooms:read","rooms:write"];function Ys(e){if(!Yn(e))return!1;const{iat:t,exp:n}=e;return typeof t=="number"&&typeof n=="number"}function qs(e){const t=Date.now()/1e3;return t>e.exp-300||t<e.iat+300}function js(e){return Xs.includes(e)}function di(e){return Array.isArray(e)&&e.every(t=>typeof t=="string")}function pi(e){return typeof e.appId=="string"&&e.roomId===void 0&&di(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")&&di(e.scopes)&&(e.maxConnectionsPerRoom===void 0||typeof e.maxConnectionsPerRoom=="number")}function Gs(e){return pi(e)||qn(e)}function Js(e){const t=e.split(".");if(t.length!==3)throw new Error("Authentication error: invalid JWT token");const n=fi(hi(t[1]));if(n&&Ys(n))return n;throw new Error("Authentication error: missing JWT metadata")}function Ws(e){const t=Js(e);if(t&&qn(t))return ks(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 Zs(e){return Object.defineProperty(e,"count",{value:e.length,enumerable:!1}),Object.defineProperty(e,"toArray",{value:()=>e,enumerable:!1}),Xn(e)}function mi(e){return e===null||typeof e=="string"||typeof e=="number"||typeof e=="boolean"}function _i(e){return Array.isArray(e)}function Qs(e){return!mi(e)&&!_i(e)}K.__spreadValues=Ct;K.__spreadProps=an;K.__async=Es;K.deprecate=xs;K.deprecateIf=Os;K.throwUsageError=Is;K.errorIf=Ss;K.assertNever=We;K.nn=G;K.ClientMsgCode=Jr;K.OpCode=Wr;K.CrdtType=Zr;K.isRootCrdt=Ps;K.isChildCrdt=Qr;K.ServerMsgCode=ei;K.isRoomEventName=Ts;K.WebsocketCloseCodes=ti;K.LiveRegister=Ge;K.makePosition=ze;K.comparePosition=ri;K.LiveList=rt;K.LiveMap=tt;K.LiveObject=nt;K.freeze=Xn;K.compact=Ns;K.compactObject=Cs;K.isSameNodeOrChildOf=si;K.isLiveNode=ge;K.isLiveList=ai;K.isLiveObject=li;K.getTreesDiffOperations=Ds;K.mergeStorageUpdates=Fs;K.isPlainObject=Yn;K.findNonSerializableValue=ui;K.tryParseJson=fi;K.b64decode=hi;K.isTokenExpired=qs;K.isScope=js;K.isAppOnlyAuthToken=pi;K.isRoomAuthToken=qn;K.isAuthToken=Gs;K.parseRoomAuthToken=Ws;K.asArrayWithLegacyMethods=Zs;K.isJsonScalar=mi;K.isJsonArray=_i;K.isJsonObject=Qs;Object.defineProperty($e,"__esModule",{value:!0});var U=K;function Xe(){const e=new Set,t=new Set;function n(a){return t.add(a),()=>t.delete(a)}function r(a){return e.add(a),()=>e.delete(a)}function i(a){e.forEach(o=>o(a)),e.clear(),t.forEach(o=>o(a))}function s(){e.clear(),t.clear()}return{notify:i,subscribe:n,subscribeOnce:r,clear:s,observable:{subscribe:n,subscribeOnce:r}}}function gi(e,t){let n=!1;const r=U.__spreadValues.call(void 0,{},e);return Object.keys(t).forEach(i=>{const s=i,a=t[s];r[s]!==a&&(a===void 0?delete r[s]:r[s]=a,n=!0)}),n?r:e}var un=class{constructor(){this._ev=Xe()}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()}},eo=class extends un{constructor(e){super(),this._me=U.freeze.call(void 0,U.compactObject.call(void 0,e))}_toImmutable(){return this._me}patch(e){const t=this._me,n=gi(t,e);t!==n&&(this._me=U.freeze.call(void 0,n),this.invalidate())}};function to(e,t){return U.freeze.call(void 0,U.compactObject.call(void 0,U.__spreadProps.call(void 0,U.__spreadValues.call(void 0,{},e),{presence:t})))}var no=class extends un{constructor(){super(),this._connections={},this._presences={},this._users={}}_toImmutable(){const e=U.compact.call(void 0,Object.keys(this._presences).map(t=>this.getUser(Number(t))));return U.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 to(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]=U.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]=U.freeze.call(void 0,U.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=gi(n,t);n!==r&&(this._presences[e]=U.freeze.call(void 0,r),this._invalidateUser(e))}},ro=class extends un{constructor(e){super(),this._value=U.freeze.call(void 0,U.compactObject.call(void 0,e))}_toImmutable(){return this._value}set(e){this._value=U.freeze.call(void 0,e),this.invalidate()}},io=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],so=3e4,oo=2e3;function ao(e){let t=0;return()=>`${e}:${t++}`}function kn(e){return e.state==="open"||e.state==="connecting"}function lo(e,t,n){var r;const i=f=>f(),s=(r=t.unstable_batchedUpdates)!=null?r:i,a={roomId:t.roomId,getNode:f=>e.nodes.get(f),addNode:(f,k)=>void e.nodes.set(f,k),deleteNode:f=>void e.nodes.delete(f),generateId:()=>`${d()}:${e.clock++}`,generateOpId:()=>`${d()}:${e.opClock++}`,dispatch(f,k,I){const T=e.activeBatch;T?(T.ops.push(...f),I.forEach((R,re)=>{T.updates.storageUpdates.set(re,U.mergeStorageUpdates.call(void 0,T.updates.storageUpdates.get(re),R))}),T.reverseOps.push(...k)):s(()=>{S(k,i),e.redoStack=[],tr(f),v({storageUpdates:I},i)})}},o={customEvent:Xe(),me:Xe(),others:Xe(),error:Xe(),connection:Xe(),storage:Xe(),history:Xe(),storageDidLoad:Xe()},l=n||{authenticate(f,k){const I=e.token,T=I!==null&&U.parseRoomAuthToken.call(void 0,I);if(T&&!U.isTokenExpired.call(void 0,T)){const R=k(I);J(T,R)}else return f(t.roomId).then(({token:R})=>{if(e.connection.current.state!=="authenticating")return;const re=U.parseRoomAuthToken.call(void 0,R),Q=k(R);J(re,Q),e.token=R}).catch(R=>te())},send(f){if(e.socket===null)throw new Error("Can't send message if socket is null");e.socket.send(JSON.stringify(f))},delayFlush(f){return setTimeout(Ne,f)},startHeartbeatInterval(){return setInterval(ye,so)},schedulePongTimeout(){return setTimeout(Le,oo)},scheduleReconnect(f){return setTimeout(V,f)}},u=new io([e.connection,e.me],(f,k)=>kn(f)?{connectionId:f.id,id:f.userId,info:f.userInfo,presence:k}:null);function c(f,k){if(f.items.length===0)throw new Error("Internal error: cannot load storage without items");e.root?h(f.items,k):e.root=_(f.items);for(const I in e.initialStorage)e.root.get(I)===void 0&&e.root.set(I,e.initialStorage[I])}function m(f){const k=new Map;let I=null;for(const[T,R]of f)if(U.isRootCrdt.call(void 0,R))I=[T,R];else{const re=[T,R],Q=k.get(R.parentId);Q!==void 0?Q.push(re):k.set(R.parentId,[re])}if(I===null)throw new Error("Root can't be null");return[I,k]}function h(f,k){if(!e.root)return;const I=new Map;e.nodes.forEach((re,Q)=>{I.set(Q,re._serialize())});const T=U.getTreesDiffOperations.call(void 0,I,new Map(f)),R=w(T,!1);v(R.updates,k)}function _(f){const[k,I]=m(f);return U.LiveObject._deserialize(k,I,a)}function P(f,k){e.undoStack.length>=50&&e.undoStack.shift(),e.undoStack.push(f),A(k)}function S(f,k){e.pausedHistory!==null?e.pausedHistory.unshift(...f):P(f,k)}function v({storageUpdates:f=new Map,presence:k=!1,others:I=[]},T){T(()=>{if(I.length>0){const R=e.others.current;for(const re of I)o.others.notify({others:R,event:re})}if(k&&o.me.notify(e.me.current),f.size>0){const R=Array.from(f.values());o.storage.notify(R)}})}function d(){const f=e.connection.current;if(kn(f))return f.id;if(e.lastConnectionId!==null)return e.lastConnectionId;throw new Error("Internal. Tried to get connection id but connection was never open")}function w(f,k){const I={reverse:[],updates:{storageUpdates:new Map,presence:!1}},T=new Set;for(const R of f)if(R.type==="presence"){const re={type:"presence",data:{}};for(const Q in R.data)re.data[Q]=e.me.current[Q];if(e.me.patch(R.data),e.buffer.me===null)e.buffer.me={type:"partial",data:R.data};else for(const Q in R.data)e.buffer.me.data[Q]=R.data[Q];I.reverse.unshift(re),I.updates.presence=!0}else{let re;R.opId||(R.opId=a.generateOpId()),k?re=0:re=e.offlineOperations.delete(U.nn.call(void 0,R.opId))?2:1;const Q=E(R,re);if(Q.modified){const vn=Q.modified.node.parent.type==="HasParent"?U.nn.call(void 0,Q.modified.node.parent.node._id,"Expected parent node to have an ID"):void 0;(!vn||!T.has(vn))&&(I.updates.storageUpdates.set(U.nn.call(void 0,Q.modified.node._id),U.mergeStorageUpdates.call(void 0,I.updates.storageUpdates.get(U.nn.call(void 0,Q.modified.node._id)),Q.modified)),I.reverse.unshift(...Q.reverse)),(R.type===2||R.type===7||R.type===4)&&T.add(U.nn.call(void 0,Q.modified.node._id))}}return I}function E(f,k){switch(f.type){case 6:case 3:case 5:{const I=e.nodes.get(f.id);return I===void 0?{modified:!1}:I._apply(f,k===0)}case 1:{const I=e.nodes.get(f.id);return I===void 0?{modified:!1}:I.parent.type==="HasParent"&&U.isLiveList.call(void 0,I.parent.node)?I.parent.node._setChildKey(f.parentKey,I,k):{modified:!1}}case 4:case 2:case 7:case 8:{if(f.parentId===void 0)return{modified:!1};const I=e.nodes.get(f.parentId);return I===void 0?{modified:!1}:I._attachChild(f,k)}}}function y(f,k){return o.storage.subscribe(I=>{const T=I.filter(R=>U.isSameNodeOrChildOf.call(void 0,R.node,f));T.length>0&&k(T)})}function D(f,k){return o.storage.subscribe(I=>{for(const T of I)T.node._id===f._id&&k(T.node)})}function M(f,k,I){if(typeof f=="string"&&U.isRoomEventName.call(void 0,f)){if(typeof k!="function")throw new Error("Second argument must be a callback function");const T=k;switch(f){case"event":return o.customEvent.subscribe(T);case"my-presence":return o.me.subscribe(T);case"others":{const R=T;return o.others.subscribe(({others:re,event:Q})=>R(re,Q))}case"error":return o.error.subscribe(T);case"connection":return o.connection.subscribe(T);case"storage":return o.storage.subscribe(T);case"history":return o.history.subscribe(T);default:return U.assertNever.call(void 0,f,"Unknown event")}}if(k===void 0||typeof f=="function")if(typeof f=="function"){const T=f;return o.storage.subscribe(T)}else throw new Error("Please specify a listener callback");if(U.isLiveNode.call(void 0,f)){const T=f;return I!=null&&I.isDeep?y(T,k):D(T,k)}throw new Error(`"${f}" is not a valid event name`)}function L(){return e.connection.current.state}function V(){var f,k,I,T;if(e.connection.current.state!=="closed"&&e.connection.current.state!=="unavailable")return null;const R=po(t.authentication,(k=(f=t.polyfills)==null?void 0:f.fetch)!=null?k:t.fetchPolyfill),re=ho(t.liveblocksServer,(T=(I=t.polyfills)==null?void 0:I.WebSocket)!=null?T:t.WebSocketPolyfill);ae({state:"authenticating"},s),l.authenticate(R,re)}function j(f,k){const I={};e.buffer.me===null&&(e.buffer.me={type:"partial",data:{}});for(const T in f){const R=f[T];R!==void 0&&(e.buffer.me.data[T]=R,I[T]=e.me.current[T])}e.me.patch(f),e.activeBatch?(k!=null&&k.addToHistory&&e.activeBatch.reverseOps.push({type:"presence",data:I}),e.activeBatch.updates.presence=!0):(Ne(),s(()=>{k!=null&&k.addToHistory&&S([{type:"presence",data:I}],i),v({presence:!0},i)}))}function J(f,k){k.addEventListener("message",W),k.addEventListener("open",Oe),k.addEventListener("close",Z),k.addEventListener("error",ve),ae({state:"connecting",id:f.actor,userInfo:f.info,userId:f.id},s),e.idFactory=ao(f.actor),e.socket=k}function te(f){e.token=null,ae({state:"unavailable"},s),e.numberOfRetry++,e.timeoutHandles.reconnect=l.scheduleReconnect(le())}function ue(f){f==="visible"&&e.connection.current.state==="open"&&ye()}function be(f){if(f.targetActor!==void 0){const I=e.others.getUser(f.actor);e.others.setOther(f.actor,f.data);const T=e.others.getUser(f.actor);if(I===void 0&&T!==void 0)return{type:"enter",user:T}}else e.others.patchOther(f.actor,f.data);const k=e.others.getUser(f.actor);if(k)return{type:"update",updates:f.data,user:k}}function p(f){const k=e.others.getUser(f.actor);return k?(e.others.removeConnection(f.actor),{type:"leave",user:k}):null}function O(f){for(const k in f.users){const I=f.users[k],T=Number(k);e.others.setConnection(T,I.id,I.info)}return{type:"reset"}}function b(){e.connection.current.state==="unavailable"&&ct()}function A(f){f(()=>{o.history.notify({canUndo:rr(),canRedo:ir()})})}function N(f){e.others.setConnection(f.actor,f.id,f.info),e.buffer.messages.push({type:100,data:e.me.current,targetActor:f.actor}),Ne();const k=e.others.getUser(f.actor);return k?{type:"enter",user:k}:void 0}function C(f){return U.isJsonObject.call(void 0,f)?f:null}function z(f){const k=U.tryParseJson.call(void 0,f);return k===void 0?null:U.isJsonArray.call(void 0,k)?U.compact.call(void 0,k.map(I=>C(I))):U.compact.call(void 0,[C(k)])}function W(f){if(f.data==="pong"){clearTimeout(e.timeoutHandles.pongTimeout);return}const k=z(f.data);if(k===null||k.length===0)return;const I={storageUpdates:new Map,others:[]};s(()=>{for(const T of k)switch(T.type){case 101:{const R=N(T);R&&I.others.push(R);break}case 100:{const R=be(T);R&&I.others.push(R);break}case 103:{o.customEvent.notify({connectionId:T.actor,event:T.event});break}case 102:{const R=p(T);R&&I.others.push(R);break}case 104:{I.others.push(O(T));break}case 200:{const R=new Map(e.offlineOperations);c(T,i),Qi(R,i),gn==null||gn(),o.storageDidLoad.notify();break}case 201:{w(T.ops,!1).updates.storageUpdates.forEach((re,Q)=>{I.storageUpdates.set(Q,U.mergeStorageUpdates.call(void 0,I.storageUpdates.get(Q),re))});break}}v(I,i)})}function Z(f){e.socket=null,clearTimeout(e.timeoutHandles.pongTimeout),clearInterval(e.intervalHandles.heartbeat),e.timeoutHandles.flush&&clearTimeout(e.timeoutHandles.flush),clearTimeout(e.timeoutHandles.reconnect),e.others.clearOthers(),s(()=>{if(v({others:[{type:"reset"}]},i),f.code>=4e3&&f.code<=4100){ae({state:"failed"},i);const k=new fo(f.reason,f.code);o.error.notify(k);const I=le(!0);e.numberOfRetry++,ae({state:"unavailable"},i),e.timeoutHandles.reconnect=l.scheduleReconnect(I)}else if(f.code===4999)ae({state:"closed"},i);else{const k=le();e.numberOfRetry++,ae({state:"unavailable"},i),e.timeoutHandles.reconnect=l.scheduleReconnect(k)}})}function ae(f,k){e.connection.set(f),k(()=>{o.connection.notify(f.state)})}function le(f=!1){return f?bn[e.numberOfRetry<bn.length?e.numberOfRetry:bn.length-1]:wn[e.numberOfRetry<wn.length?e.numberOfRetry:wn.length-1]}function ve(){}function Oe(){clearInterval(e.intervalHandles.heartbeat),e.intervalHandles.heartbeat=l.startHeartbeatInterval(),e.connection.current.state==="connecting"&&(ae(U.__spreadProps.call(void 0,U.__spreadValues.call(void 0,{},e.connection.current),{state:"open"}),s),e.numberOfRetry=0,e.lastConnectionId!==void 0&&(e.buffer.me={type:"full",data:U.__spreadValues.call(void 0,{},e.me.current)},Ne()),e.lastConnectionId=e.connection.current.id,e.root&&e.buffer.messages.push({type:200}),Ne())}function ye(){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",Oe),e.socket.removeEventListener("message",W),e.socket.removeEventListener("close",Z),e.socket.removeEventListener("error",ve),e.socket.close(),e.socket=null),ae({state:"unavailable"},s),clearTimeout(e.timeoutHandles.pongTimeout),e.timeoutHandles.flush&&clearTimeout(e.timeoutHandles.flush),clearTimeout(e.timeoutHandles.reconnect),clearInterval(e.intervalHandles.heartbeat),V()}function Qi(f,k){if(f.size===0)return;const I=[],T=Array.from(f.values()),R=w(T,!0);I.push({type:201,ops:T}),v(R.updates,k),l.send(I)}function Ne(){const f=e.buffer.storageOperations;if(f.length>0&&f.forEach(T=>{e.offlineOperations.set(U.nn.call(void 0,T.opId),T)}),e.socket===null||e.socket.readyState!==e.socket.OPEN){e.buffer.storageOperations=[];return}const k=Date.now();if(k-e.lastFlushTime>t.throttleDelay){const T=es(e);if(T.length===0)return;l.send(T),e.buffer={messages:[],storageOperations:[],me:null},e.lastFlushTime=k}else e.timeoutHandles.flush!==null&&clearTimeout(e.timeoutHandles.flush),e.timeoutHandles.flush=l.delayFlush(t.throttleDelay-(k-e.lastFlushTime))}function es(f){const k=[];f.buffer.me&&k.push(f.buffer.me.type==="full"?{type:100,targetActor:-1,data:f.buffer.me.data}:{type:100,data:f.buffer.me.data});for(const I of f.buffer.messages)k.push(I);return f.buffer.storageOperations.length>0&&k.push({type:201,ops:f.buffer.storageOperations}),k}function ts(){e.socket&&(e.socket.removeEventListener("open",Oe),e.socket.removeEventListener("message",W),e.socket.removeEventListener("close",Z),e.socket.removeEventListener("error",ve),e.socket.close(),e.socket=null),s(()=>{ae({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(),v({others:[{type:"reset"}]},i),Object.values(o).forEach(f=>f.clear())})}function ns(){return e.me.current}function rs(){return e.others.current}function is(f,k={shouldQueueEventIfNotReady:!1}){e.socket===null&&!k.shouldQueueEventIfNotReady||(e.buffer.messages.push({type:103,event:f}),Ne())}function tr(f){e.buffer.storageOperations.push(...f),Ne()}let _n=null,gn=null;function nr(){return _n===null&&(e.buffer.messages.push({type:200}),Ne(),_n=new Promise(f=>gn=f)),_n}function ss(){const f=e.root;return f!==void 0?f:(nr(),null)}function os(){return U.__async.call(void 0,this,null,function*(){return e.root?Promise.resolve({root:e.root}):(yield nr(),{root:U.nn.call(void 0,e.root)})})}function as(){if(e.activeBatch)throw new Error("undo is not allowed during a batch");const f=e.undoStack.pop();if(f===void 0)return;e.pausedHistory=null;const k=w(f,!0);s(()=>{v(k.updates,i),e.redoStack.push(k.reverse),A(i)});for(const I of f)I.type!=="presence"&&e.buffer.storageOperations.push(I);Ne()}function rr(){return e.undoStack.length>0}function ls(){if(e.activeBatch)throw new Error("redo is not allowed during a batch");const f=e.redoStack.pop();if(f===void 0)return;e.pausedHistory=null;const k=w(f,!0);s(()=>{v(k.updates,i),e.undoStack.push(k.reverse),A(i)});for(const I of f)I.type!=="presence"&&e.buffer.storageOperations.push(I);Ne()}function ir(){return e.redoStack.length>0}function us(f){if(e.activeBatch)return f();let k;return s(()=>{e.activeBatch={ops:[],updates:{storageUpdates:new Map,presence:!1,others:[]},reverseOps:[]};try{k=f()}finally{const I=e.activeBatch;e.activeBatch=null,I.reverseOps.length>0&&S(I.reverseOps,i),I.ops.length>0&&(e.redoStack=[]),I.ops.length>0&&tr(I.ops),v(I.updates,i),Ne()}}),k}function cs(){e.pausedHistory=[]}function fs(){const f=e.pausedHistory;e.pausedHistory=null,f!==null&&f.length>0&&P(f,s)}function hs(){e.socket&&(e.socket=null)}function ds(f){Z(f)}return{onClose:Z,onMessage:W,authenticationSuccess:J,heartbeat:ye,onNavigatorOnline:b,simulateSocketClose:hs,simulateSendCloseEvent:ds,onVisibilityChange:ue,getUndoStack:()=>e.undoStack,getItemsCount:()=>e.nodes.size,connect:V,disconnect:ts,subscribe:M,updatePresence:j,broadcastEvent:is,batch:us,undo:as,redo:ls,canUndo:rr,canRedo:ir,pauseHistory:cs,resumeHistory:fs,getStorage:os,getStorageSnapshot:ss,events:{customEvent:o.customEvent.observable,others:o.others.observable,me:o.me.observable,error:o.error.observable,connection:o.connection.observable,storage:o.storage.observable,history:o.history.observable,storageDidLoad:o.storageDidLoad.observable},getConnectionState:L,isSelfAware:()=>kn(e.connection.current),getSelf:()=>u.current,getPresence:ns,getOthers:rs}}function uo(e,t){const n=new no,r=new ro({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 eo(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 co(e,t){const{initialPresence:n,initialStorage:r}=e,i=uo(typeof n=="function"?n(t.roomId):n,typeof r=="function"?r(t.roomId):r),s=lo(i,t),a={id:t.roomId,getConnectionState:s.getConnectionState,isSelfAware:s.isSelfAware,getSelf:s.getSelf,subscribe:s.subscribe,getPresence:s.getPresence,updatePresence:s.updatePresence,getOthers:s.getOthers,broadcastEvent:s.broadcastEvent,getStorage:s.getStorage,getStorageSnapshot:s.getStorageSnapshot,events:s.events,batch:s.batch,history:{undo:s.undo,redo:s.redo,canUndo:s.canUndo,canRedo:s.canRedo,pause:s.pauseHistory,resume:s.resumeHistory},__INTERNAL_DO_NOT_USE:{simulateCloseWebsocket:s.simulateSocketClose,simulateSendCloseEvent:s.simulateSendCloseEvent}};return{connect:s.connect,disconnect:s.disconnect,onNavigatorOnline:s.onNavigatorOnline,onVisibilityChange:s.onVisibilityChange,room:a}}var fo=class extends Error{constructor(e,t){super(e),this.code=t}};function ho(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 po(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=>U.__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 U.__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(a){throw new En(`Expected a JSON response when doing a POST request on "${t}". ${a}`)}if(!U.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:s}=i;return{token:s}})}var En=class extends Error{constructor(e){super(e)}};function mo(e){const t=e,n=_o(e),r=new Map;function i(o){const l=r.get(o);return l?l.room:null}function s(o,l){var u,c;let m=r.get(o);if(m)return m.room;if(U.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."),m=co({initialPresence:(u=l.initialPresence)!=null?u:{},initialStorage:l.initialStorage},{roomId:o,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:go(t,o)}),r.set(o,m),!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");vs.atob=t.polyfills.atob}m.connect()}return m.room}function a(o){const l=r.get(o);l&&(l.disconnect(),r.delete(o))}return typeof window<"u"&&typeof window.addEventListener<"u"&&window.addEventListener("online",()=>{for(const[,o]of r)o.onNavigatorOnline()}),typeof document<"u"&&document.addEventListener("visibilitychange",()=>{for(const[,o]of r)o.onVisibilityChange(document.visibilityState)}),{getRoom:i,enter:s,leave:a}}function _o(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 go(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:vo(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 vo(e,t){return e.publicAuthorizeEndpoint?e.publicAuthorizeEndpoint.replace("{roomId}",t):`https://api.liveblocks.io/v2/rooms/${encodeURIComponent(t)}/public/authorize`}function yo(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 wo(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 bo(e,t){if(Object.is(e,t))return!0;const n=Array.isArray(e),r=Array.isArray(t);return n||r?!n||!r?!1:yo(e,t):wo(e,t)}$e.LiveList=U.LiveList;$e.LiveMap=U.LiveMap;$e.LiveObject=U.LiveObject;$e.createClient=mo;$e.shallow=bo;$e.LiveList;$e.LiveMap;const ko=$e.LiveObject,Eo=$e.createClient;$e.shallow;const vi=Symbol(),yi=Symbol();function xo(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,s){r&&r.m(i,s),t=!0},p(i,[s]){r&&r.p&&(!t||s&2)&&Hn(r,n,i,i[1],t?Kn(n,i[1],s,null):Fn(i[1]),null)},i(i){t||(H(r,i),t=!0)},o(i){q(r,i),t=!1},d(i){r&&r.d(i)}}}function Oo(e,t,n){let{$$slots:r={},$$scope:i}=t,{client:s}=t;if(!s)throw new Error("LiveblocksProvider requires a client");return Yr(vi,s),e.$$set=a=>{"client"in a&&n(0,s=a.client),"$$scope"in a&&n(1,i=a.$$scope)},[s,i,r]}class Io extends pe{constructor(t){super(),me(this,t,Oo,xo,_e,{client:0})}}function So(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,s){r&&r.m(i,s),t=!0},p(i,[s]){r&&r.p&&(!t||s&4)&&Hn(r,n,i,i[2],t?Kn(n,i[2],s,null):Fn(i[2]),null)},i(i){t||(H(r,i),t=!0)},o(i){q(r,i),t=!1},d(i){r&&r.d(i)}}}function Po(e,t,n){let{$$slots:r={},$$scope:i}=t,{id:s}=t,{defaultPresence:a=()=>({})}=t;if(!s)throw new Error("RoomProvider requires an id");const o=qr(vi);if(o){const l=o.enter(s,a());Yr(yi,l),on(()=>{o.leave(s)})}return e.$$set=l=>{"id"in l&&n(0,s=l.id),"defaultPresence"in l&&n(1,a=l.defaultPresence),"$$scope"in l&&n(2,i=l.$$scope)},[s,a,i,r]}class To extends pe{constructor(t){super(),me(this,t,Po,So,_e,{id:0,defaultPresence:1})}}function Ao(e){let t,n;return{c(){t=Se("svg"),n=Se("path"),this.h()},l(r){t=Pe(r,"svg",{class:!0,width:!0,viewBox:!0,fill:!0,xmlns:!0});var i=$(t);n=Pe(i,"path",{d:!0,fill:!0}),$(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){B(r,t,i),F(t,n)},p(r,[i]){i&1&&g(t,"class",r[0])},i:we,o:we,d(r){r&&x(t)}}}function Lo(e,t,n){let{classList:r=""}=t;return e.$$set=i=>{"classList"in i&&n(0,r=i.classList)},[r]}class No extends pe{constructor(t){super(),me(this,t,Lo,Ao,_e,{classList:0})}}function hr(e){let t,n,r;return{c(){t=X("div"),n=Re(e[2]),this.h()},l(i){t=Y(i,"DIV",{class:!0,style:!0});var s=$(t);n=Me(s,e[2]),s.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,s){B(i,t,s),F(t,n)},p(i,s){s&4&&At(n,i[2]),s&2&&r!==(r=`text-shadow: 0px 5px 5px ${i[1]}`)&&g(t,"style",r)},d(i){i&&x(t)}}}function Co(e){let t,n,r,i,s;n=new No({props:{classList:"block z-0 col-span-2 row-span-2"}});let a=e[2]&&hr(e);return{c(){t=X("div"),ce(n.$$.fragment),r=se(),a&&a.c(),this.h()},l(o){t=Y(o,"DIV",{class:!0,style:!0});var l=$(t);fe(n.$$.fragment,l),r=oe(l),a&&a.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(o,l){B(o,t,l),he(n,t,null),F(t,r),a&&a.m(t,null),s=!0},p(o,[l]){o[2]?a?a.p(o,l):(a=hr(o),a.c(),a.m(t,null)):a&&(a.d(1),a=null),(!s||l&9&&i!==(i=`transform: translateX(${o[3].x}px) translateY(${o[3].y}px) scale(${o[0].k});`))&&g(t,"style",i)},i(o){s||(H(n.$$.fragment,o),s=!0)},o(o){q(n.$$.fragment,o),s=!1},d(o){o&&x(t),de(n),a&&a.d()}}}function Ro(e,t,n){let r,{transform:i}=t,{color:s=""}=t,{emoji:a}=t,{position:o={x:0,y:0}}=t;return e.$$set=l=>{"transform"in l&&n(0,i=l.transform),"color"in l&&n(1,s=l.color),"emoji"in l&&n(2,a=l.emoji),"position"in l&&n(4,o=l.position)},e.$$.update=()=>{e.$$.dirty&17&&n(3,r={x:i.applyX(o.x),y:i.applyY(o.y)})},[i,s,a,r,o]}class Mo extends pe{constructor(t){super(),me(this,t,Ro,Co,_e,{transform:0,color:1,emoji:2,position:4})}}function $o(e){let t,n,r;return{c(){t=Se("svg"),n=Se("path"),r=Se("path"),this.h()},l(i){t=Pe(i,"svg",{class:!0,width:!0,height:!0,viewBox:!0,fill:!0,xmlns:!0});var s=$(t);n=Pe(s,"path",{d:!0,fill:!0}),$(n).forEach(x),r=Pe(s,"path",{d:!0,fill:!0}),$(r).forEach(x),s.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,s){B(i,t,s),F(t,n),F(t,r)},p:we,i:we,o:we,d(i){i&&x(t)}}}class wi extends pe{constructor(t){super(),me(this,t,null,$o,_e,{})}}function dr(e){let t,n,r;return n=new wi({}),{c(){t=X("div"),ce(n.$$.fragment),this.h()},l(i){t=Y(i,"DIV",{class:!0});var s=$(t);fe(n.$$.fragment,s),s.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,s){B(i,t,s),he(n,t,null),r=!0},i(i){r||(H(n.$$.fragment,i),r=!0)},o(i){q(n.$$.fragment,i),r=!1},d(i){i&&x(t),de(n)}}}function Do(e){let t,n,r,i,s,a,o,l=e[2]&&dr();return{c(){t=X("div"),n=X("div"),r=X("div"),i=Re(e[1]),s=se(),l&&l.c(),this.h()},l(u){t=Y(u,"DIV",{class:!0,style:!0});var c=$(t);n=Y(c,"DIV",{class:!0});var m=$(n);r=Y(m,"DIV",{class:!0});var h=$(r);i=Me(h,e[1]),h.forEach(x),m.forEach(x),s=oe(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",a=`transform: translateX(${e[3].x}px) translateY(${e[3].y}px) scale(${e[0].k}); transform-origin: 0 0;`)},m(u,c){B(u,t,c),F(t,n),F(n,r),F(r,i),F(t,s),l&&l.m(t,null),o=!0},p(u,[c]){(!o||c&2)&&At(i,u[1]),u[2]?l?c&4&&H(l,1):(l=dr(),l.c(),H(l,1),l.m(t,null)):l&&(Fe(),q(l,1,1,()=>{l=null}),Ke()),(!o||c&9&&a!==(a=`transform: translateX(${u[3].x}px) translateY(${u[3].y}px) scale(${u[0].k}); transform-origin: 0 0;`))&&g(t,"style",a)},i(u){o||(H(l),o=!0)},o(u){q(l),o=!1},d(u){u&&x(t),l&&l.d()}}}function Uo(e,t,n){let r,{transform:i}=t,{position:s={x:0,y:0}}=t,{prompt:a=""}=t,{isLoading:o=!1}=t;return e.$$set=l=>{"transform"in l&&n(0,i=l.transform),"position"in l&&n(4,s=l.position),"prompt"in l&&n(1,a=l.prompt),"isLoading"in l&&n(2,o=l.isLoading)},e.$$.update=()=>{e.$$.dirty&17&&n(3,r={x:i.applyX(s.x),y:i.applyY(s.y)})},[i,a,o,r,s]}class zo extends pe{constructor(t){super(),me(this,t,Uo,Do,_e,{transform:0,position:4,prompt:1,isLoading:2})}}function Ho(e){let t,n,r,i,s;return{c(){t=X("span"),n=Re("+"),r=se(),i=X("span"),s=Re("Prompt + Paint"),this.h()},l(a){t=Y(a,"SPAN",{class:!0});var o=$(t);n=Me(o,"+"),o.forEach(x),r=oe(a),i=Y(a,"SPAN",{});var l=$(i);s=Me(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(a,o){B(a,t,o),F(t,n),B(a,r,o),B(a,i,o),F(i,s)},d(a){a&&x(t),a&&x(r),a&&x(i)}}}function Fo(e){let t,n;return{c(){t=X("span"),n=Re("paiting...")},l(r){t=Y(r,"SPAN",{});var i=$(t);n=Me(i,"paiting..."),i.forEach(x)},m(r,i){B(r,t,i),F(t,n)},d(r){r&&x(t)}}}function Ko(e){let t,n,r;function i(o,l){return o[0]?Fo:Ho}let s=i(e),a=s(e);return{c(){t=X("button"),a.c(),this.h()},l(o){t=Y(o,"BUTTON",{class:!0,title:!0});var l=$(t);a.l(l),l.forEach(x),this.h()},h(){t.disabled=e[0],g(t,"class","button-paint svelte-nqbja5"),g(t,"title","New Paint Frame")},m(o,l){B(o,t,l),a.m(t,null),n||(r=Ze(t,"click",e[1]),n=!0)},p(o,[l]){s!==(s=i(o))&&(a.d(1),a=s(o),a&&(a.c(),a.m(t,null))),l&1&&(t.disabled=o[0])},i:we,o:we,d(o){o&&x(t),a.d(),n=!1,r()}}}function Vo(e,t,n){let{isLoading:r=!1}=t;function i(s){Lt.call(this,e,s)}return e.$$set=s=>{"isLoading"in s&&n(0,r=s.isLoading)},[r,i]}class bi extends pe{constructor(t){super(),me(this,t,Vo,Ko,_e,{isLoading:0})}}function Bo(e){let t,n;return{c(){t=Se("svg"),n=Se("path"),this.h()},l(r){t=Pe(r,"svg",{class:!0,width:!0,height:!0,viewBox:!0,fill:!0,xmlns:!0});var i=$(t);n=Pe(i,"path",{d:!0,stroke:!0,"stroke-width":!0,"stroke-linecap":!0,"stroke-linejoin":!0}),$(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","40"),g(t,"height","40"),g(t,"viewBox","0 0 11 11"),g(t,"fill","none"),g(t,"xmlns","http://www.w3.org/2000/svg")},m(r,i){B(r,t,i),F(t,n)},p(r,[i]){i&1&&g(t,"class",r[0])},i:we,o:we,d(r){r&&x(t)}}}function Xo(e,t,n){let{classList:r=""}=t;return e.$$set=i=>{"classList"in i&&n(0,r=i.classList)},[r]}class Yo extends pe{constructor(t){super(),me(this,t,Xo,Bo,_e,{classList:0})}}function qo(e){let t,n,r,i,s,a;return n=new Yo({}),{c(){t=X("button"),ce(n.$$.fragment),this.h()},l(o){t=Y(o,"BUTTON",{class:!0,title:!0});var l=$(t);fe(n.$$.fragment,l),l.forEach(x),this.h()},h(){t.disabled=e[1],g(t,"class",r=e[2]+" shadow-lg bg-white rounded-full disabled:opacity-50 "+(e[0]?"text-blue-700":"text-gray-800")),g(t,"title","Enable Dragging")},m(o,l){B(o,t,l),he(n,t,null),i=!0,s||(a=Ze(t,"click",e[3]),s=!0)},p(o,[l]){(!i||l&2)&&(t.disabled=o[1]),(!i||l&5&&r!==(r=o[2]+" shadow-lg bg-white rounded-full disabled:opacity-50 "+(o[0]?"text-blue-700":"text-gray-800")))&&g(t,"class",r)},i(o){i||(H(n.$$.fragment,o),i=!0)},o(o){q(n.$$.fragment,o),i=!1},d(o){o&&x(t),de(n),s=!1,a()}}}function jo(e,t,n){let{isActive:r=!1}=t,{isLoading:i=!1}=t,{className:s=""}=t;function a(o){Lt.call(this,e,o)}return e.$$set=o=>{"isActive"in o&&n(0,r=o.isActive),"isLoading"in o&&n(1,i=o.isLoading),"className"in o&&n(2,s=o.className)},[r,i,s,a]}class Go extends pe{constructor(t){super(),me(this,t,jo,qo,_e,{isActive:0,isLoading:1,className:2})}}function Jo(e){let t,n,r;return{c(){t=Se("svg"),n=Se("path"),r=Se("path"),this.h()},l(i){t=Pe(i,"svg",{class:!0,width:!0,height:!0,viewBox:!0,fill:!0,xmlns:!0});var s=$(t);n=Pe(s,"path",{d:!0,stroke:!0,"stroke-width":!0}),$(n).forEach(x),r=Pe(s,"path",{d:!0,stroke:!0,"stroke-width":!0,"stroke-linecap":!0,"stroke-linejoin":!0}),$(r).forEach(x),s.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","40"),g(t,"height","40"),g(t,"viewBox","0 0 11 11"),g(t,"fill","none"),g(t,"xmlns","http://www.w3.org/2000/svg")},m(i,s){B(i,t,s),F(t,n),F(t,r)},p(i,[s]){s&1&&g(t,"class",i[0])},i:we,o:we,d(i){i&&x(t)}}}function Wo(e,t,n){let{classList:r=""}=t;return e.$$set=i=>{"classList"in i&&n(0,r=i.classList)},[r]}class Zo extends pe{constructor(t){super(),me(this,t,Wo,Jo,_e,{classList:0})}}function Qo(e){let t,n,r,i,s,a;return n=new Zo({}),{c(){t=X("button"),ce(n.$$.fragment),this.h()},l(o){t=Y(o,"BUTTON",{class:!0,title:!0});var l=$(t);fe(n.$$.fragment,l),l.forEach(x),this.h()},h(){t.disabled=e[1],g(t,"class",r=e[2]+" rounded-full disabled:opacity-50 "+(e[0]?"text-blue-700":"text-gray-800")),g(t,"title","Enable Masking")},m(o,l){B(o,t,l),he(n,t,null),i=!0,s||(a=Ze(t,"click",e[3]),s=!0)},p(o,[l]){(!i||l&2)&&(t.disabled=o[1]),(!i||l&5&&r!==(r=o[2]+" rounded-full disabled:opacity-50 "+(o[0]?"text-blue-700":"text-gray-800")))&&g(t,"class",r)},i(o){i||(H(n.$$.fragment,o),i=!0)},o(o){q(n.$$.fragment,o),i=!1},d(o){o&&x(t),de(n),s=!1,a()}}}function ea(e,t,n){let{isActive:r=!1}=t,{isLoading:i=!1}=t,{className:s=""}=t;function a(o){Lt.call(this,e,o)}return e.$$set=o=>{"isActive"in o&&n(0,r=o.isActive),"isLoading"in o&&n(1,i=o.isLoading),"className"in o&&n(2,s=o.className)},[r,i,s,a]}class ta extends pe{constructor(t){super(),me(this,t,ea,Qo,_e,{isActive:0,isLoading:1,className:2})}}function na(e){let t,n,r;return{c(){t=Se("svg"),n=Se("g"),r=Se("path"),this.h()},l(i){t=Pe(i,"svg",{class:!0,width:!0,height:!0,viewBox:!0,fill:!0,xmlns:!0});var s=$(t);n=Pe(s,"g",{opacity:!0});var a=$(n);r=Pe(a,"path",{d:!0,fill:!0,stroke:!0,"stroke-width":!0,"stroke-linejoin":!0}),$(r).forEach(x),a.forEach(x),s.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","40"),g(t,"height","29"),g(t,"viewBox","0 0 10 9"),g(t,"fill","none"),g(t,"xmlns","http://www.w3.org/2000/svg")},m(i,s){B(i,t,s),F(t,n),F(n,r)},p(i,[s]){s&1&&g(t,"class",i[0])},i:we,o:we,d(i){i&&x(t)}}}function ra(e,t,n){let{classList:r=""}=t;return e.$$set=i=>{"classList"in i&&n(0,r=i.classList)},[r]}class ia extends pe{constructor(t){super(),me(this,t,ra,na,_e,{classList:0})}}function sa(e){let t,n,r,i,s,a;return n=new ia({}),{c(){t=X("button"),ce(n.$$.fragment),this.h()},l(o){t=Y(o,"BUTTON",{class:!0,title:!0});var l=$(t);fe(n.$$.fragment,l),l.forEach(x),this.h()},h(){t.disabled=e[1],g(t,"class",r=e[2]+" bg-white rounded-full disabled:opacity-50 bg-white rounded-full "+(e[0]?"text-blue-700":"text-gray-800")),g(t,"title","Clear Masking")},m(o,l){B(o,t,l),he(n,t,null),i=!0,s||(a=Ze(t,"click",e[3]),s=!0)},p(o,[l]){(!i||l&2)&&(t.disabled=o[1]),(!i||l&5&&r!==(r=o[2]+" bg-white rounded-full disabled:opacity-50 bg-white rounded-full "+(o[0]?"text-blue-700":"text-gray-800")))&&g(t,"class",r)},i(o){i||(H(n.$$.fragment,o),i=!0)},o(o){q(n.$$.fragment,o),i=!1},d(o){o&&x(t),de(n),s=!1,a()}}}function oa(e,t,n){let{isActive:r=!1}=t,{isLoading:i=!1}=t,{className:s=""}=t;function a(o){Lt.call(this,e,o)}return e.$$set=o=>{"isActive"in o&&n(0,r=o.isActive),"isLoading"in o&&n(1,i=o.isLoading),"className"in o&&n(2,s=o.className)},[r,i,s,a]}class aa extends pe{constructor(t){super(),me(this,t,oa,sa,_e,{isActive:0,isLoading:1,className:2})}}var la={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 Yt(n)}function Yt(e){this._=e}function ua(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}})}Yt.prototype=cn.prototype={constructor:Yt,on:function(e,t){var n=this._,r=ua(e+"",n),i,s=-1,a=r.length;if(arguments.length<2){for(;++s<a;)if((i=(e=r[s]).type)&&(i=ca(n[i],e.name)))return i;return}if(t!=null&&typeof t!="function")throw new Error("invalid callback: "+t);for(;++s<a;)if(i=(e=r[s]).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 Yt(e)},call:function(e,t){if((i=arguments.length-2)>0)for(var n=new Array(i),r=0,i,s;r<i;++r)n[r]=arguments[r+2];if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(s=this._[e],r=0,i=s.length;r<i;++r)s[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,s=r.length;i<s;++i)r[i].value.apply(t,n)}};function ca(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]=la,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 fa(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 ha(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function ki(e){var t=fn(e);return(t.local?ha:fa)(t)}function da(){}function jn(e){return e==null?da:function(){return this.querySelector(e)}}function pa(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 s=t[i],a=s.length,o=r[i]=new Array(a),l,u,c=0;c<a;++c)(l=s[c])&&(u=e.call(l,l.__data__,c,s))&&("__data__"in l&&(u.__data__=l.__data__),o[c]=u);return new Te(r,this._parents)}function ma(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function _a(){return[]}function Ei(e){return e==null?_a:function(){return this.querySelectorAll(e)}}function ga(e){return function(){return ma(e.apply(this,arguments))}}function va(e){typeof e=="function"?e=ga(e):e=Ei(e);for(var t=this._groups,n=t.length,r=[],i=[],s=0;s<n;++s)for(var a=t[s],o=a.length,l,u=0;u<o;++u)(l=a[u])&&(r.push(e.call(l,l.__data__,u,a)),i.push(l));return new Te(r,i)}function xi(e){return function(){return this.matches(e)}}function Oi(e){return function(t){return t.matches(e)}}var ya=Array.prototype.find;function wa(e){return function(){return ya.call(this.children,e)}}function ba(){return this.firstElementChild}function ka(e){return this.select(e==null?ba:wa(typeof e=="function"?e:Oi(e)))}var Ea=Array.prototype.filter;function xa(){return Array.from(this.children)}function Oa(e){return function(){return Ea.call(this.children,e)}}function Ia(e){return this.selectAll(e==null?xa:Oa(typeof e=="function"?e:Oi(e)))}function Sa(e){typeof e!="function"&&(e=xi(e));for(var t=this._groups,n=t.length,r=new Array(n),i=0;i<n;++i)for(var s=t[i],a=s.length,o=r[i]=[],l,u=0;u<a;++u)(l=s[u])&&e.call(l,l.__data__,u,s)&&o.push(l);return new Te(r,this._parents)}function Ii(e){return new Array(e.length)}function Pa(){return new Te(this._enter||this._groups.map(Ii),this._parents)}function Qt(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}Qt.prototype={constructor:Qt,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 Ta(e){return function(){return e}}function Aa(e,t,n,r,i,s){for(var a=0,o,l=t.length,u=s.length;a<u;++a)(o=t[a])?(o.__data__=s[a],r[a]=o):n[a]=new Qt(e,s[a]);for(;a<l;++a)(o=t[a])&&(i[a]=o)}function La(e,t,n,r,i,s,a){var o,l,u=new Map,c=t.length,m=s.length,h=new Array(c),_;for(o=0;o<c;++o)(l=t[o])&&(h[o]=_=a.call(l,l.__data__,o,t)+"",u.has(_)?i[o]=l:u.set(_,l));for(o=0;o<m;++o)_=a.call(e,s[o],o,s)+"",(l=u.get(_))?(r[o]=l,l.__data__=s[o],u.delete(_)):n[o]=new Qt(e,s[o]);for(o=0;o<c;++o)(l=t[o])&&u.get(h[o])===l&&(i[o]=l)}function Na(e){return e.__data__}function Ca(e,t){if(!arguments.length)return Array.from(this,Na);var n=t?La:Aa,r=this._parents,i=this._groups;typeof e!="function"&&(e=Ta(e));for(var s=i.length,a=new Array(s),o=new Array(s),l=new Array(s),u=0;u<s;++u){var c=r[u],m=i[u],h=m.length,_=Ra(e.call(c,c&&c.__data__,u,r)),P=_.length,S=o[u]=new Array(P),v=a[u]=new Array(P),d=l[u]=new Array(h);n(c,m,S,v,d,_,t);for(var w=0,E=0,y,D;w<P;++w)if(y=S[w]){for(w>=E&&(E=w+1);!(D=v[E])&&++E<P;);y._next=D||null}}return a=new Te(a,r),a._enter=o,a._exit=l,a}function Ra(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function Ma(){return new Te(this._exit||this._groups.map(Ii),this._parents)}function $a(e,t,n){var r=this.enter(),i=this,s=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?s.remove():n(s),r&&i?r.merge(i).order():i}function Da(e){for(var t=e.selection?e.selection():e,n=this._groups,r=t._groups,i=n.length,s=r.length,a=Math.min(i,s),o=new Array(i),l=0;l<a;++l)for(var u=n[l],c=r[l],m=u.length,h=o[l]=new Array(m),_,P=0;P<m;++P)(_=u[P]||c[P])&&(h[P]=_);for(;l<i;++l)o[l]=n[l];return new Te(o,this._parents)}function Ua(){for(var e=this._groups,t=-1,n=e.length;++t<n;)for(var r=e[t],i=r.length-1,s=r[i],a;--i>=0;)(a=r[i])&&(s&&a.compareDocumentPosition(s)^4&&s.parentNode.insertBefore(a,s),s=a);return this}function za(e){e||(e=Ha);function t(m,h){return m&&h?e(m.__data__,h.__data__):!m-!h}for(var n=this._groups,r=n.length,i=new Array(r),s=0;s<r;++s){for(var a=n[s],o=a.length,l=i[s]=new Array(o),u,c=0;c<o;++c)(u=a[c])&&(l[c]=u);l.sort(t)}return new Te(i,this._parents).order()}function Ha(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function Fa(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function Ka(){return Array.from(this)}function Va(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],i=0,s=r.length;i<s;++i){var a=r[i];if(a)return a}return null}function Ba(){let e=0;for(const t of this)++e;return e}function Xa(){return!this.node()}function Ya(e){for(var t=this._groups,n=0,r=t.length;n<r;++n)for(var i=t[n],s=0,a=i.length,o;s<a;++s)(o=i[s])&&e.call(o,o.__data__,s,i);return this}function qa(e){return function(){this.removeAttribute(e)}}function ja(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Ga(e,t){return function(){this.setAttribute(e,t)}}function Ja(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function Wa(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function Za(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 Qa(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?ja:qa:typeof t=="function"?n.local?Za:Wa:n.local?Ja:Ga)(n,t))}function Si(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function el(e){return function(){this.style.removeProperty(e)}}function tl(e,t,n){return function(){this.style.setProperty(e,t,n)}}function nl(e,t,n){return function(){var r=t.apply(this,arguments);r==null?this.style.removeProperty(e):this.style.setProperty(e,r,n)}}function rl(e,t,n){return arguments.length>1?this.each((t==null?el:typeof t=="function"?nl:tl)(e,t,n==null?"":n)):_t(this.node(),e)}function _t(e,t){return e.style.getPropertyValue(t)||Si(e).getComputedStyle(e,null).getPropertyValue(t)}function il(e){return function(){delete this[e]}}function sl(e,t){return function(){this[e]=t}}function ol(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function al(e,t){return arguments.length>1?this.each((t==null?il:typeof t=="function"?ol:sl)(e,t)):this.node()[e]}function Pi(e){return e.trim().split(/^|\s+/)}function Gn(e){return e.classList||new Ti(e)}function Ti(e){this._node=e,this._names=Pi(e.getAttribute("class")||"")}Ti.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 Ai(e,t){for(var n=Gn(e),r=-1,i=t.length;++r<i;)n.add(t[r])}function Li(e,t){for(var n=Gn(e),r=-1,i=t.length;++r<i;)n.remove(t[r])}function ll(e){return function(){Ai(this,e)}}function ul(e){return function(){Li(this,e)}}function cl(e,t){return function(){(t.apply(this,arguments)?Ai:Li)(this,e)}}function fl(e,t){var n=Pi(e+"");if(arguments.length<2){for(var r=Gn(this.node()),i=-1,s=n.length;++i<s;)if(!r.contains(n[i]))return!1;return!0}return this.each((typeof t=="function"?cl:t?ll:ul)(n,t))}function hl(){this.textContent=""}function dl(e){return function(){this.textContent=e}}function pl(e){return function(){var t=e.apply(this,arguments);this.textContent=t==null?"":t}}function ml(e){return arguments.length?this.each(e==null?hl:(typeof e=="function"?pl:dl)(e)):this.node().textContent}function _l(){this.innerHTML=""}function gl(e){return function(){this.innerHTML=e}}function vl(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t==null?"":t}}function yl(e){return arguments.length?this.each(e==null?_l:(typeof e=="function"?vl:gl)(e)):this.node().innerHTML}function wl(){this.nextSibling&&this.parentNode.appendChild(this)}function bl(){return this.each(wl)}function kl(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function El(){return this.each(kl)}function xl(e){var t=typeof e=="function"?e:ki(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function Ol(){return null}function Il(e,t){var n=typeof e=="function"?e:ki(e),r=t==null?Ol:typeof t=="function"?t:jn(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),r.apply(this,arguments)||null)})}function Sl(){var e=this.parentNode;e&&e.removeChild(this)}function Pl(){return this.each(Sl)}function Tl(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function Al(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function Ll(e){return this.select(e?Al:Tl)}function Nl(e){return arguments.length?this.property("__data__",e):this.node().__data__}function Cl(e){return function(t){e.call(this,t,this.__data__)}}function Rl(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 Ml(e){return function(){var t=this.__on;if(!!t){for(var n=0,r=-1,i=t.length,s;n<i;++n)s=t[n],(!e.type||s.type===e.type)&&s.name===e.name?this.removeEventListener(s.type,s.listener,s.options):t[++r]=s;++r?t.length=r:delete this.__on}}}function $l(e,t,n){return function(){var r=this.__on,i,s=Cl(t);if(r){for(var a=0,o=r.length;a<o;++a)if((i=r[a]).type===e.type&&i.name===e.name){this.removeEventListener(i.type,i.listener,i.options),this.addEventListener(i.type,i.listener=s,i.options=n),i.value=t;return}}this.addEventListener(e.type,s,n),i={type:e.type,name:e.name,value:t,listener:s,options:n},r?r.push(i):this.__on=[i]}}function Dl(e,t,n){var r=Rl(e+""),i,s=r.length,a;if(arguments.length<2){var o=this.node().__on;if(o){for(var l=0,u=o.length,c;l<u;++l)for(i=0,c=o[l];i<s;++i)if((a=r[i]).type===c.type&&a.name===c.name)return c.value}return}for(o=t?$l:Ml,i=0;i<s;++i)this.each(o(r[i],t,n));return this}function Ni(e,t,n){var r=Si(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 Ul(e,t){return function(){return Ni(this,e,t)}}function zl(e,t){return function(){return Ni(this,e,t.apply(this,arguments))}}function Hl(e,t){return this.each((typeof t=="function"?zl:Ul)(e,t))}function*Fl(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],i=0,s=r.length,a;i<s;++i)(a=r[i])&&(yield a)}var Ci=[null];function Te(e,t){this._groups=e,this._parents=t}function Rt(){return new Te([[document.documentElement]],Ci)}function Kl(){return this}Te.prototype=Rt.prototype={constructor:Te,select:pa,selectAll:va,selectChild:ka,selectChildren:Ia,filter:Sa,data:Ca,enter:Pa,exit:Ma,join:$a,merge:Da,selection:Kl,order:Ua,sort:za,call:Fa,nodes:Ka,node:Va,size:Ba,empty:Xa,each:Ya,attr:Qa,style:rl,property:al,classed:fl,text:ml,html:yl,raise:bl,lower:El,append:xl,insert:Il,remove:Pl,clone:Ll,datum:Nl,on:Dl,dispatch:Hl,[Symbol.iterator]:Fl};function Ae(e){return typeof e=="string"?new Te([[document.querySelector(e)]],[document.documentElement]):new Te([[e]],Ci)}function Vl(e){let t;for(;t=e.sourceEvent;)e=t;return e}function Ye(e,t){if(e=Vl(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 Bl={passive:!1},xt={capture:!0,passive:!1};function xn(e){e.stopImmediatePropagation()}function dt(e){e.preventDefault(),e.stopImmediatePropagation()}function Ri(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 Mi(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 Dt=e=>()=>e;function An(e,{sourceEvent:t,subject:n,target:r,identifier:i,active:s,x:a,y:o,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:s,enumerable:!0,configurable:!0},x:{value:a,enumerable:!0,configurable:!0},y:{value:o,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 Xl(e){return!e.ctrlKey&&!e.button}function Yl(){return this.parentNode}function ql(e,t){return t==null?{x:e.x,y:e.y}:t}function jl(){return navigator.maxTouchPoints||"ontouchstart"in this}function _r(){var e=Xl,t=Yl,n=ql,r=jl,i={},s=cn("start","drag","end"),a=0,o,l,u,c,m=0;function h(y){y.on("mousedown.drag",_).filter(r).on("touchstart.drag",v).on("touchmove.drag",d,Bl).on("touchend.drag touchcancel.drag",w).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function _(y,D){if(!(c||!e.call(this,y,D))){var M=E(this,t.call(this,y,D),y,D,"mouse");!M||(Ae(y.view).on("mousemove.drag",P,xt).on("mouseup.drag",S,xt),Ri(y.view),xn(y),u=!1,o=y.clientX,l=y.clientY,M("start",y))}}function P(y){if(dt(y),!u){var D=y.clientX-o,M=y.clientY-l;u=D*D+M*M>m}i.mouse("drag",y)}function S(y){Ae(y.view).on("mousemove.drag mouseup.drag",null),Mi(y.view,u),dt(y),i.mouse("end",y)}function v(y,D){if(!!e.call(this,y,D)){var M=y.changedTouches,L=t.call(this,y,D),V=M.length,j,J;for(j=0;j<V;++j)(J=E(this,L,y,D,M[j].identifier,M[j]))&&(xn(y),J("start",y,M[j]))}}function d(y){var D=y.changedTouches,M=D.length,L,V;for(L=0;L<M;++L)(V=i[D[L].identifier])&&(dt(y),V("drag",y,D[L]))}function w(y){var D=y.changedTouches,M=D.length,L,V;for(c&&clearTimeout(c),c=setTimeout(function(){c=null},500),L=0;L<M;++L)(V=i[D[L].identifier])&&(xn(y),V("end",y,D[L]))}function E(y,D,M,L,V,j){var J=s.copy(),te=Ye(j||M,D),ue,be,p;if((p=n.call(y,new An("beforestart",{sourceEvent:M,target:h,identifier:V,active:a,x:te[0],y:te[1],dx:0,dy:0,dispatch:J}),L))!=null)return ue=p.x-te[0]||0,be=p.y-te[1]||0,function O(b,A,N){var C=te,z;switch(b){case"start":i[V]=O,z=a++;break;case"end":delete i[V],--a;case"drag":te=Ye(N||A,D),z=a;break}J.call(b,y,new An(b,{sourceEvent:A,subject:p,target:h,identifier:V,active:z,x:te[0]+ue,y:te[1]+be,dx:te[0]-C[0],dy:te[1]-C[1],dispatch:J}),L)}}return h.filter=function(y){return arguments.length?(e=typeof y=="function"?y:Dt(!!y),h):e},h.container=function(y){return arguments.length?(t=typeof y=="function"?y:Dt(y),h):t},h.subject=function(y){return arguments.length?(n=typeof y=="function"?y:Dt(y),h):n},h.touchable=function(y){return arguments.length?(r=typeof y=="function"?y:Dt(!!y),h):r},h.on=function(){var y=s.on.apply(s,arguments);return y===s?h:y},h.clickDistance=function(y){return arguments.length?(m=(y=+y)*y,h):Math.sqrt(m)},h}function Gl(e){return new Promise(t=>{const n=new Image;n.onload=async()=>{const r=n.width,i=n.height,s=document.createElement("canvas");s.width=r,s.height=i,s.getContext("2d").drawImage(n,0,0,r,i);const o=await new Promise(l=>s.toBlob(l,"image/jpeg",.95));t(o)},n.src=e})}async function Jl(e,t,n){const r=Zl(t),i="uploadfile/",a=`color-palette-${crypto.randomUUID().split("-")[0]}-${r}-${n}.jpeg`,o=new File([e],a,{type:"image/jpeg"}),l=new FormData;l.append("file",o),console.log("uploading image",o);const c=await(await fetch(i,{method:"POST",body:l})).json();return console.log("uploaded images",c),c.filename}const Wl=512*5-512;function Ut(e,t=32){const n=e%t<t/2?e-e%t:e+t-e%t;return Math.max(0,Math.min(Math.round(n),Wl))}function Zl(e){return e?e.toString().toLowerCase().replace(/\s+/g,"-").replace(/[^\w\-]+/g,"").replace(/\-\-+/g,"-").replace(/^-+/,"").replace(/-+$/,""):""}function hn(){const e=qr(yi);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(s){e.updatePresence(s)}const i=e.subscribe("my-presence",s=>{n(s)});return on(()=>{i()}),{subscribe:t,update:r}}function Ql(){const e=hn(),t=et(),n=e.subscribe("others",r=>{t.set(r)});return on(n),t}function eu(){const e=hn(),t=et();async function n(){const{root:r}=await e.getStorage();t.set(r)}return n(),t}function $i(e,t){const n=hn(),r=eu(),i=et();let s=()=>{};const a=r.subscribe(o=>{!o||(o.get(e)||o.set(e,new ko(t)),i.set(o.get(e)),s(),s=n.subscribe(o.get(e),l=>{i.set(l)}))});return on(a),i}function Jn(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function Di(e,t){var n=Object.create(e.prototype);for(var r in t)n[r]=t[r];return n}function Mt(){}var Ot=.7,en=1/Ot,pt="\\s*([+-]?\\d+)\\s*",It="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",He="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",tu=/^#([0-9a-f]{3,8})$/,nu=new RegExp(`^rgb\\(${pt},${pt},${pt}\\)$`),ru=new RegExp(`^rgb\\(${He},${He},${He}\\)$`),iu=new RegExp(`^rgba\\(${pt},${pt},${pt},${It}\\)$`),su=new RegExp(`^rgba\\(${He},${He},${He},${It}\\)$`),ou=new RegExp(`^hsl\\(${It},${He},${He}\\)$`),au=new RegExp(`^hsla\\(${It},${He},${He},${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(Mt,St,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:vr,formatHex:vr,formatHex8:lu,formatHsl:uu,formatRgb:yr,toString:yr});function vr(){return this.rgb().formatHex()}function lu(){return this.rgb().formatHex8()}function uu(){return Ui(this).formatHsl()}function yr(){return this.rgb().formatRgb()}function St(e){var t,n;return e=(e+"").trim().toLowerCase(),(t=tu.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?wr(t):n===3?new xe(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?zt(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?zt(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=nu.exec(e))?new xe(t[1],t[2],t[3],1):(t=ru.exec(e))?new xe(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=iu.exec(e))?zt(t[1],t[2],t[3],t[4]):(t=su.exec(e))?zt(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=ou.exec(e))?Er(t[1],t[2]/100,t[3]/100,1):(t=au.exec(e))?Er(t[1],t[2]/100,t[3]/100,t[4]):gr.hasOwnProperty(e)?wr(gr[e]):e==="transparent"?new xe(NaN,NaN,NaN,0):null}function wr(e){return new xe(e>>16&255,e>>8&255,e&255,1)}function zt(e,t,n,r){return r<=0&&(e=t=n=NaN),new xe(e,t,n,r)}function cu(e){return e instanceof Mt||(e=St(e)),e?(e=e.rgb(),new xe(e.r,e.g,e.b,e.opacity)):new xe}function Ln(e,t,n,r){return arguments.length===1?cu(e):new xe(e,t,n,r==null?1:r)}function xe(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}Jn(xe,Ln,Di(Mt,{brighter(e){return e=e==null?en:Math.pow(en,e),new xe(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?Ot:Math.pow(Ot,e),new xe(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new xe(at(this.r),at(this.g),at(this.b),tn(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:fu,formatRgb:kr,toString:kr}));function br(){return`#${st(this.r)}${st(this.g)}${st(this.b)}`}function fu(){return`#${st(this.r)}${st(this.g)}${st(this.b)}${st((isNaN(this.opacity)?1:this.opacity)*255)}`}function kr(){const e=tn(this.opacity);return`${e===1?"rgb(":"rgba("}${at(this.r)}, ${at(this.g)}, ${at(this.b)}${e===1?")":`, ${e})`}`}function tn(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 st(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 Ce(e,t,n,r)}function Ui(e){if(e instanceof Ce)return new Ce(e.h,e.s,e.l,e.opacity);if(e instanceof Mt||(e=St(e)),!e)return new Ce;if(e instanceof Ce)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,i=Math.min(t,n,r),s=Math.max(t,n,r),a=NaN,o=s-i,l=(s+i)/2;return o?(t===s?a=(n-r)/o+(n<r)*6:n===s?a=(r-t)/o+2:a=(t-n)/o+4,o/=l<.5?s+i:2-s-i,a*=60):o=l>0&&l<1?0:a,new Ce(a,o,l,e.opacity)}function hu(e,t,n,r){return arguments.length===1?Ui(e):new Ce(e,t,n,r==null?1:r)}function Ce(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}Jn(Ce,hu,Di(Mt,{brighter(e){return e=e==null?en:Math.pow(en,e),new Ce(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Ot:Math.pow(Ot,e),new Ce(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 xe(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 Ce(xr(this.h),Ht(this.s),Ht(this.l),tn(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=tn(this.opacity);return`${e===1?"hsl(":"hsla("}${xr(this.h)}, ${Ht(this.s)*100}%, ${Ht(this.l)*100}%${e===1?")":`, ${e})`}`}}));function xr(e){return e=(e||0)%360,e<0?e+360:e}function Ht(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 zi=e=>()=>e;function du(e,t){return function(n){return e+n*t}}function pu(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 mu(e){return(e=+e)==1?Hi:function(t,n){return n-t?pu(t,n,e):zi(isNaN(t)?n:t)}}function Hi(e,t){var n=t-e;return n?du(e,n):zi(isNaN(e)?t:e)}const Or=function e(t){var n=mu(t);function r(i,s){var a=n((i=Ln(i)).r,(s=Ln(s)).r),o=n(i.g,s.g),l=n(i.b,s.b),u=Hi(i.opacity,s.opacity);return function(c){return i.r=a(c),i.g=o(c),i.b=l(c),i.opacity=u(c),i+""}}return r.gamma=e,r}(1);function Je(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}var Nn=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,In=new RegExp(Nn.source,"g");function _u(e){return function(){return e}}function gu(e){return function(t){return e(t)+""}}function vu(e,t){var n=Nn.lastIndex=In.lastIndex=0,r,i,s,a=-1,o=[],l=[];for(e=e+"",t=t+"";(r=Nn.exec(e))&&(i=In.exec(t));)(s=i.index)>n&&(s=t.slice(n,s),o[a]?o[a]+=s:o[++a]=s),(r=r[0])===(i=i[0])?o[a]?o[a]+=i:o[++a]=i:(o[++a]=null,l.push({i:a,x:Je(r,i)})),n=In.lastIndex;return n<t.length&&(s=t.slice(n),o[a]?o[a]+=s:o[++a]=s),o.length<2?l[0]?gu(l[0].x):_u(t):(t=l.length,function(u){for(var c=0,m;c<t;++c)o[(m=l[c]).i]=m.x(u);return o.join("")})}var Ir=180/Math.PI,Cn={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function Fi(e,t,n,r,i,s){var a,o,l;return(a=Math.sqrt(e*e+t*t))&&(e/=a,t/=a),(l=e*n+t*r)&&(n-=e*l,r-=t*l),(o=Math.sqrt(n*n+r*r))&&(n/=o,r/=o,l/=o),e*r<t*n&&(e=-e,t=-t,l=-l,a=-a),{translateX:i,translateY:s,rotate:Math.atan2(t,e)*Ir,skewX:Math.atan(l)*Ir,scaleX:a,scaleY:o}}var Ft;function yu(e){const t=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return t.isIdentity?Cn:Fi(t.a,t.b,t.c,t.d,t.e,t.f)}function wu(e){return e==null||(Ft||(Ft=document.createElementNS("http://www.w3.org/2000/svg","g")),Ft.setAttribute("transform",e),!(e=Ft.transform.baseVal.consolidate()))?Cn:(e=e.matrix,Fi(e.a,e.b,e.c,e.d,e.e,e.f))}function Ki(e,t,n,r){function i(u){return u.length?u.pop()+" ":""}function s(u,c,m,h,_,P){if(u!==m||c!==h){var S=_.push("translate(",null,t,null,n);P.push({i:S-4,x:Je(u,m)},{i:S-2,x:Je(c,h)})}else(m||h)&&_.push("translate("+m+t+h+n)}function a(u,c,m,h){u!==c?(u-c>180?c+=360:c-u>180&&(u+=360),h.push({i:m.push(i(m)+"rotate(",null,r)-2,x:Je(u,c)})):c&&m.push(i(m)+"rotate("+c+r)}function o(u,c,m,h){u!==c?h.push({i:m.push(i(m)+"skewX(",null,r)-2,x:Je(u,c)}):c&&m.push(i(m)+"skewX("+c+r)}function l(u,c,m,h,_,P){if(u!==m||c!==h){var S=_.push(i(_)+"scale(",null,",",null,")");P.push({i:S-4,x:Je(u,m)},{i:S-2,x:Je(c,h)})}else(m!==1||h!==1)&&_.push(i(_)+"scale("+m+","+h+")")}return function(u,c){var m=[],h=[];return u=e(u),c=e(c),s(u.translateX,u.translateY,c.translateX,c.translateY,m,h),a(u.rotate,c.rotate,m,h),o(u.skewX,c.skewX,m,h),l(u.scaleX,u.scaleY,c.scaleX,c.scaleY,m,h),u=c=null,function(_){for(var P=-1,S=h.length,v;++P<S;)m[(v=h[P]).i]=v.x(_);return m.join("")}}}var bu=Ki(yu,"px, ","px)","deg)"),ku=Ki(wu,", ",")",")"),Eu=1e-12;function Sr(e){return((e=Math.exp(e))+1/e)/2}function xu(e){return((e=Math.exp(e))-1/e)/2}function Ou(e){return((e=Math.exp(2*e))-1)/(e+1)}const Iu=function e(t,n,r){function i(s,a){var o=s[0],l=s[1],u=s[2],c=a[0],m=a[1],h=a[2],_=c-o,P=m-l,S=_*_+P*P,v,d;if(S<Eu)d=Math.log(h/u)/t,v=function(L){return[o+L*_,l+L*P,u*Math.exp(t*L*d)]};else{var w=Math.sqrt(S),E=(h*h-u*u+r*S)/(2*u*n*w),y=(h*h-u*u-r*S)/(2*h*n*w),D=Math.log(Math.sqrt(E*E+1)-E),M=Math.log(Math.sqrt(y*y+1)-y);d=(M-D)/t,v=function(L){var V=L*d,j=Sr(D),J=u/(n*w)*(j*Ou(t*V+D)-xu(D));return[o+J*_,l+J*P,u*j/Sr(t*V+D)]}}return v.duration=d*1e3*t/Math.SQRT2,v}return i.rho=function(s){var a=Math.max(.001,+s),o=a*a,l=o*o;return e(a,o,l)},i}(Math.SQRT2,2,4);var gt=0,bt=0,vt=0,Vi=1e3,nn,kt,rn=0,ut=0,pn=0,Pt=typeof performance=="object"&&performance.now?performance:Date,Bi=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function Wn(){return ut||(Bi(Su),ut=Pt.now()+pn)}function Su(){ut=0}function sn(){this._call=this._time=this._next=null}sn.prototype=Xi.prototype={constructor:sn,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:nn=this,kt=this),this._call=e,this._time=n,Rn()},stop:function(){this._call&&(this._call=null,this._time=1/0,Rn())}};function Xi(e,t,n){var r=new sn;return r.restart(e,t,n),r}function Pu(){Wn(),++gt;for(var e=nn,t;e;)(t=ut-e._time)>=0&&e._call.call(void 0,t),e=e._next;--gt}function Pr(){ut=(rn=Pt.now())+pn,gt=bt=0;try{Pu()}finally{gt=0,Au(),ut=0}}function Tu(){var e=Pt.now(),t=e-rn;t>Vi&&(pn-=t,rn=e)}function Au(){for(var e,t=nn,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:nn=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||(rn=Pt.now(),vt=setInterval(Tu,Vi)),gt=1,Bi(Pr))}}function Tr(e,t,n){var r=new sn;return t=t==null?0:+t,r.restart(i=>{r.stop(),e(i+t)},t,n),r}var Lu=cn("start","end","cancel","interrupt"),Nu=[],Yi=0,Ar=1,Mn=2,qt=3,Lr=4,$n=5,jt=6;function mn(e,t,n,r,i,s){var a=e.__transition;if(!a)e.__transition={};else if(n in a)return;Cu(e,n,{name:t,index:r,group:i,on:Lu,tween:Nu,time:s.time,delay:s.delay,duration:s.duration,ease:s.ease,timer:null,state:Yi})}function Zn(e,t){var n=De(e,t);if(n.state>Yi)throw new Error("too late; already scheduled");return n}function Ve(e,t){var n=De(e,t);if(n.state>qt)throw new Error("too late; already running");return n}function De(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function Cu(e,t,n){var r=e.__transition,i;r[t]=n,n.timer=Xi(s,0,n.time);function s(u){n.state=Ar,n.timer.restart(a,n.delay,n.time),n.delay<=u&&a(u-n.delay)}function a(u){var c,m,h,_;if(n.state!==Ar)return l();for(c in r)if(_=r[c],_.name===n.name){if(_.state===qt)return Tr(a);_.state===Lr?(_.state=jt,_.timer.stop(),_.on.call("interrupt",e,e.__data__,_.index,_.group),delete r[c]):+c<t&&(_.state=jt,_.timer.stop(),_.on.call("cancel",e,e.__data__,_.index,_.group),delete r[c])}if(Tr(function(){n.state===qt&&(n.state=Lr,n.timer.restart(o,n.delay,n.time),o(u))}),n.state=Mn,n.on.call("start",e,e.__data__,n.index,n.group),n.state===Mn){for(n.state=qt,i=new Array(h=n.tween.length),c=0,m=-1;c<h;++c)(_=n.tween[c].value.call(e,e.__data__,n.index,n.group))&&(i[++m]=_);i.length=m+1}}function o(u){for(var c=u<n.duration?n.ease.call(null,u/n.duration):(n.timer.restart(l),n.state=$n,1),m=-1,h=i.length;++m<h;)i[m].call(e,c);n.state===$n&&(n.on.call("end",e,e.__data__,n.index,n.group),l())}function l(){n.state=jt,n.timer.stop(),delete r[t];for(var u in r)return;delete e.__transition}}function Gt(e,t){var n=e.__transition,r,i,s=!0,a;if(!!n){t=t==null?null:t+"";for(a in n){if((r=n[a]).name!==t){s=!1;continue}i=r.state>Mn&&r.state<$n,r.state=jt,r.timer.stop(),r.on.call(i?"interrupt":"cancel",e,e.__data__,r.index,r.group),delete n[a]}s&&delete e.__transition}}function Ru(e){return this.each(function(){Gt(this,e)})}function Mu(e,t){var n,r;return function(){var i=Ve(this,e),s=i.tween;if(s!==n){r=n=s;for(var a=0,o=r.length;a<o;++a)if(r[a].name===t){r=r.slice(),r.splice(a,1);break}}i.tween=r}}function $u(e,t,n){var r,i;if(typeof n!="function")throw new Error;return function(){var s=Ve(this,e),a=s.tween;if(a!==r){i=(r=a).slice();for(var o={name:t,value:n},l=0,u=i.length;l<u;++l)if(i[l].name===t){i[l]=o;break}l===u&&i.push(o)}s.tween=i}}function Du(e,t){var n=this._id;if(e+="",arguments.length<2){for(var r=De(this.node(),n).tween,i=0,s=r.length,a;i<s;++i)if((a=r[i]).name===e)return a.value;return null}return this.each((t==null?Mu:$u)(n,e,t))}function Qn(e,t,n){var r=e._id;return e.each(function(){var i=Ve(this,r);(i.value||(i.value={}))[t]=n.apply(this,arguments)}),function(i){return De(i,r).value[t]}}function qi(e,t){var n;return(typeof t=="number"?Je:t instanceof St?Or:(n=St(t))?(t=n,Or):vu)(e,t)}function Uu(e){return function(){this.removeAttribute(e)}}function zu(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Hu(e,t,n){var r,i=n+"",s;return function(){var a=this.getAttribute(e);return a===i?null:a===r?s:s=t(r=a,n)}}function Fu(e,t,n){var r,i=n+"",s;return function(){var a=this.getAttributeNS(e.space,e.local);return a===i?null:a===r?s:s=t(r=a,n)}}function Ku(e,t,n){var r,i,s;return function(){var a,o=n(this),l;return o==null?void this.removeAttribute(e):(a=this.getAttribute(e),l=o+"",a===l?null:a===r&&l===i?s:(i=l,s=t(r=a,o)))}}function Vu(e,t,n){var r,i,s;return function(){var a,o=n(this),l;return o==null?void this.removeAttributeNS(e.space,e.local):(a=this.getAttributeNS(e.space,e.local),l=o+"",a===l?null:a===r&&l===i?s:(i=l,s=t(r=a,o)))}}function Bu(e,t){var n=fn(e),r=n==="transform"?ku:qi;return this.attrTween(e,typeof t=="function"?(n.local?Vu:Ku)(n,r,Qn(this,"attr."+e,t)):t==null?(n.local?zu:Uu)(n):(n.local?Fu:Hu)(n,r,t))}function Xu(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function Yu(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function qu(e,t){var n,r;function i(){var s=t.apply(this,arguments);return s!==r&&(n=(r=s)&&Yu(e,s)),n}return i._value=t,i}function ju(e,t){var n,r;function i(){var s=t.apply(this,arguments);return s!==r&&(n=(r=s)&&Xu(e,s)),n}return i._value=t,i}function Gu(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?qu:ju)(r,t))}function Ju(e,t){return function(){Zn(this,e).delay=+t.apply(this,arguments)}}function Wu(e,t){return t=+t,function(){Zn(this,e).delay=t}}function Zu(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?Ju:Wu)(t,e)):De(this.node(),t).delay}function Qu(e,t){return function(){Ve(this,e).duration=+t.apply(this,arguments)}}function ec(e,t){return t=+t,function(){Ve(this,e).duration=t}}function tc(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?Qu:ec)(t,e)):De(this.node(),t).duration}function nc(e,t){if(typeof t!="function")throw new Error;return function(){Ve(this,e).ease=t}}function rc(e){var t=this._id;return arguments.length?this.each(nc(t,e)):De(this.node(),t).ease}function ic(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!="function")throw new Error;Ve(this,e).ease=n}}function sc(e){if(typeof e!="function")throw new Error;return this.each(ic(this._id,e))}function oc(e){typeof e!="function"&&(e=xi(e));for(var t=this._groups,n=t.length,r=new Array(n),i=0;i<n;++i)for(var s=t[i],a=s.length,o=r[i]=[],l,u=0;u<a;++u)(l=s[u])&&e.call(l,l.__data__,u,s)&&o.push(l);return new je(r,this._parents,this._name,this._id)}function ac(e){if(e._id!==this._id)throw new Error;for(var t=this._groups,n=e._groups,r=t.length,i=n.length,s=Math.min(r,i),a=new Array(r),o=0;o<s;++o)for(var l=t[o],u=n[o],c=l.length,m=a[o]=new Array(c),h,_=0;_<c;++_)(h=l[_]||u[_])&&(m[_]=h);for(;o<r;++o)a[o]=t[o];return new je(a,this._parents,this._name,this._id)}function lc(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 uc(e,t,n){var r,i,s=lc(t)?Zn:Ve;return function(){var a=s(this,e),o=a.on;o!==r&&(i=(r=o).copy()).on(t,n),a.on=i}}function cc(e,t){var n=this._id;return arguments.length<2?De(this.node(),n).on.on(e):this.each(uc(n,e,t))}function fc(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function hc(){return this.on("end.remove",fc(this._id))}function dc(e){var t=this._name,n=this._id;typeof e!="function"&&(e=jn(e));for(var r=this._groups,i=r.length,s=new Array(i),a=0;a<i;++a)for(var o=r[a],l=o.length,u=s[a]=new Array(l),c,m,h=0;h<l;++h)(c=o[h])&&(m=e.call(c,c.__data__,h,o))&&("__data__"in c&&(m.__data__=c.__data__),u[h]=m,mn(u[h],t,n,h,u,De(c,n)));return new je(s,this._parents,t,n)}function pc(e){var t=this._name,n=this._id;typeof e!="function"&&(e=Ei(e));for(var r=this._groups,i=r.length,s=[],a=[],o=0;o<i;++o)for(var l=r[o],u=l.length,c,m=0;m<u;++m)if(c=l[m]){for(var h=e.call(c,c.__data__,m,l),_,P=De(c,n),S=0,v=h.length;S<v;++S)(_=h[S])&&mn(_,t,n,S,h,P);s.push(h),a.push(c)}return new je(s,a,t,n)}var mc=Rt.prototype.constructor;function _c(){return new mc(this._groups,this._parents)}function gc(e,t){var n,r,i;return function(){var s=_t(this,e),a=(this.style.removeProperty(e),_t(this,e));return s===a?null:s===n&&a===r?i:i=t(n=s,r=a)}}function ji(e){return function(){this.style.removeProperty(e)}}function vc(e,t,n){var r,i=n+"",s;return function(){var a=_t(this,e);return a===i?null:a===r?s:s=t(r=a,n)}}function yc(e,t,n){var r,i,s;return function(){var a=_t(this,e),o=n(this),l=o+"";return o==null&&(l=o=(this.style.removeProperty(e),_t(this,e))),a===l?null:a===r&&l===i?s:(i=l,s=t(r=a,o))}}function wc(e,t){var n,r,i,s="style."+t,a="end."+s,o;return function(){var l=Ve(this,e),u=l.on,c=l.value[s]==null?o||(o=ji(t)):void 0;(u!==n||i!==c)&&(r=(n=u).copy()).on(a,i=c),l.on=r}}function bc(e,t,n){var r=(e+="")=="transform"?bu:qi;return t==null?this.styleTween(e,gc(e,r)).on("end.style."+e,ji(e)):typeof t=="function"?this.styleTween(e,yc(e,r,Qn(this,"style."+e,t))).each(wc(this._id,e)):this.styleTween(e,vc(e,r,t),n).on("end.style."+e,null)}function kc(e,t,n){return function(r){this.style.setProperty(e,t.call(this,r),n)}}function Ec(e,t,n){var r,i;function s(){var a=t.apply(this,arguments);return a!==i&&(r=(i=a)&&kc(e,a,n)),r}return s._value=t,s}function xc(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,Ec(e,t,n==null?"":n))}function Oc(e){return function(){this.textContent=e}}function Ic(e){return function(){var t=e(this);this.textContent=t==null?"":t}}function Sc(e){return this.tween("text",typeof e=="function"?Ic(Qn(this,"text",e)):Oc(e==null?"":e+""))}function Pc(e){return function(t){this.textContent=e.call(this,t)}}function Tc(e){var t,n;function r(){var i=e.apply(this,arguments);return i!==n&&(t=(n=i)&&Pc(i)),t}return r._value=e,r}function Ac(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,Tc(e))}function Lc(){for(var e=this._name,t=this._id,n=Gi(),r=this._groups,i=r.length,s=0;s<i;++s)for(var a=r[s],o=a.length,l,u=0;u<o;++u)if(l=a[u]){var c=De(l,t);mn(l,e,n,u,a,{time:c.time+c.delay+c.duration,delay:0,duration:c.duration,ease:c.ease})}return new je(r,this._parents,e,n)}function Nc(){var e,t,n=this,r=n._id,i=n.size();return new Promise(function(s,a){var o={value:a},l={value:function(){--i===0&&s()}};n.each(function(){var u=Ve(this,r),c=u.on;c!==e&&(t=(e=c).copy(),t._.cancel.push(o),t._.interrupt.push(o),t._.end.push(l)),u.on=t}),i===0&&s()})}var Cc=0;function je(e,t,n,r){this._groups=e,this._parents=t,this._name=n,this._id=r}function Gi(){return++Cc}var Be=Rt.prototype;je.prototype={constructor:je,select:dc,selectAll:pc,selectChild:Be.selectChild,selectChildren:Be.selectChildren,filter:oc,merge:ac,selection:_c,transition:Lc,call:Be.call,nodes:Be.nodes,node:Be.node,size:Be.size,empty:Be.empty,each:Be.each,on:cc,attr:Bu,attrTween:Gu,style:bc,styleTween:xc,text:Sc,textTween:Ac,remove:hc,tween:Du,delay:Zu,duration:tc,ease:rc,easeVarying:sc,end:Nc,[Symbol.iterator]:Be[Symbol.iterator]};function Rc(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var Mc={time:null,delay:0,duration:250,ease:Rc};function $c(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 Dc(e){var t,n;e instanceof je?(t=e._id,e=e._name):(t=Gi(),(n=Mc).time=Wn(),e=e==null?null:e+"");for(var r=this._groups,i=r.length,s=0;s<i;++s)for(var a=r[s],o=a.length,l,u=0;u<o;++u)(l=a[u])&&mn(l,e,t,u,a,n||$c(l,t));return new je(r,this._parents,e,t)}Rt.prototype.interrupt=Ru;Rt.prototype.transition=Dc;const Kt=e=>()=>e;function Uc(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 qe(e,t,n){this.k=e,this.x=t,this.y=n}qe.prototype={constructor:qe,scale:function(e){return e===1?this:new qe(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new qe(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 qe(1,0,0);qe.prototype;function Sn(e){e.stopImmediatePropagation()}function yt(e){e.preventDefault(),e.stopImmediatePropagation()}function zc(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function Hc(){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 Nr(){return this.__zoom||Tt}function Fc(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function Kc(){return navigator.maxTouchPoints||"ontouchstart"in this}function Vc(e,t,n){var r=e.invertX(t[0][0])-n[0][0],i=e.invertX(t[1][0])-n[1][0],s=e.invertY(t[0][1])-n[0][1],a=e.invertY(t[1][1])-n[1][1];return e.translate(i>r?(r+i)/2:Math.min(0,r)||Math.max(0,i),a>s?(s+a)/2:Math.min(0,s)||Math.max(0,a))}function Bc(){var e=zc,t=Hc,n=Vc,r=Fc,i=Kc,s=[0,1/0],a=[[-1/0,-1/0],[1/0,1/0]],o=250,l=Iu,u=cn("start","zoom","end"),c,m,h,_=500,P=150,S=0,v=10;function d(p){p.property("__zoom",Nr).on("wheel.zoom",V,{passive:!1}).on("mousedown.zoom",j).on("dblclick.zoom",J).filter(i).on("touchstart.zoom",te).on("touchmove.zoom",ue).on("touchend.zoom touchcancel.zoom",be).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}d.transform=function(p,O,b,A){var N=p.selection?p.selection():p;N.property("__zoom",Nr),p!==N?D(p,O,b,A):N.interrupt().each(function(){M(this,arguments).event(A).start().zoom(null,typeof O=="function"?O.apply(this,arguments):O).end()})},d.scaleBy=function(p,O,b,A){d.scaleTo(p,function(){var N=this.__zoom.k,C=typeof O=="function"?O.apply(this,arguments):O;return N*C},b,A)},d.scaleTo=function(p,O,b,A){d.transform(p,function(){var N=t.apply(this,arguments),C=this.__zoom,z=b==null?y(N):typeof b=="function"?b.apply(this,arguments):b,W=C.invert(z),Z=typeof O=="function"?O.apply(this,arguments):O;return n(E(w(C,Z),z,W),N,a)},b,A)},d.translateBy=function(p,O,b,A){d.transform(p,function(){return n(this.__zoom.translate(typeof O=="function"?O.apply(this,arguments):O,typeof b=="function"?b.apply(this,arguments):b),t.apply(this,arguments),a)},null,A)},d.translateTo=function(p,O,b,A,N){d.transform(p,function(){var C=t.apply(this,arguments),z=this.__zoom,W=A==null?y(C):typeof A=="function"?A.apply(this,arguments):A;return n(Tt.translate(W[0],W[1]).scale(z.k).translate(typeof O=="function"?-O.apply(this,arguments):-O,typeof b=="function"?-b.apply(this,arguments):-b),C,a)},A,N)};function w(p,O){return O=Math.max(s[0],Math.min(s[1],O)),O===p.k?p:new qe(O,p.x,p.y)}function E(p,O,b){var A=O[0]-b[0]*p.k,N=O[1]-b[1]*p.k;return A===p.x&&N===p.y?p:new qe(p.k,A,N)}function y(p){return[(+p[0][0]+ +p[1][0])/2,(+p[0][1]+ +p[1][1])/2]}function D(p,O,b,A){p.on("start.zoom",function(){M(this,arguments).event(A).start()}).on("interrupt.zoom end.zoom",function(){M(this,arguments).event(A).end()}).tween("zoom",function(){var N=this,C=arguments,z=M(N,C).event(A),W=t.apply(N,C),Z=b==null?y(W):typeof b=="function"?b.apply(N,C):b,ae=Math.max(W[1][0]-W[0][0],W[1][1]-W[0][1]),le=N.__zoom,ve=typeof O=="function"?O.apply(N,C):O,Oe=l(le.invert(Z).concat(ae/le.k),ve.invert(Z).concat(ae/ve.k));return function(ye){if(ye===1)ye=ve;else{var Le=Oe(ye),ct=ae/Le[2];ye=new qe(ct,Z[0]-Le[0]*ct,Z[1]-Le[1]*ct)}z.zoom(null,ye)}})}function M(p,O,b){return!b&&p.__zooming||new L(p,O)}function L(p,O){this.that=p,this.args=O,this.active=0,this.sourceEvent=null,this.extent=t.apply(p,O),this.taps=0}L.prototype={event:function(p){return p&&(this.sourceEvent=p),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(p,O){return this.mouse&&p!=="mouse"&&(this.mouse[1]=O.invert(this.mouse[0])),this.touch0&&p!=="touch"&&(this.touch0[1]=O.invert(this.touch0[0])),this.touch1&&p!=="touch"&&(this.touch1[1]=O.invert(this.touch1[0])),this.that.__zoom=O,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(p){var O=Ae(this.that).datum();u.call(p,this.that,new Uc(p,{sourceEvent:this.sourceEvent,target:d,type:p,transform:this.that.__zoom,dispatch:u}),O)}};function V(p,...O){if(!e.apply(this,arguments))return;var b=M(this,O).event(p),A=this.__zoom,N=Math.max(s[0],Math.min(s[1],A.k*Math.pow(2,r.apply(this,arguments)))),C=Ye(p);if(b.wheel)(b.mouse[0][0]!==C[0]||b.mouse[0][1]!==C[1])&&(b.mouse[1]=A.invert(b.mouse[0]=C)),clearTimeout(b.wheel);else{if(A.k===N)return;b.mouse=[C,A.invert(C)],Gt(this),b.start()}yt(p),b.wheel=setTimeout(z,P),b.zoom("mouse",n(E(w(A,N),b.mouse[0],b.mouse[1]),b.extent,a));function z(){b.wheel=null,b.end()}}function j(p,...O){if(h||!e.apply(this,arguments))return;var b=p.currentTarget,A=M(this,O,!0).event(p),N=Ae(p.view).on("mousemove.zoom",Z,!0).on("mouseup.zoom",ae,!0),C=Ye(p,b),z=p.clientX,W=p.clientY;Ri(p.view),Sn(p),A.mouse=[C,this.__zoom.invert(C)],Gt(this),A.start();function Z(le){if(yt(le),!A.moved){var ve=le.clientX-z,Oe=le.clientY-W;A.moved=ve*ve+Oe*Oe>S}A.event(le).zoom("mouse",n(E(A.that.__zoom,A.mouse[0]=Ye(le,b),A.mouse[1]),A.extent,a))}function ae(le){N.on("mousemove.zoom mouseup.zoom",null),Mi(le.view,A.moved),yt(le),A.event(le).end()}}function J(p,...O){if(!!e.apply(this,arguments)){var b=this.__zoom,A=Ye(p.changedTouches?p.changedTouches[0]:p,this),N=b.invert(A),C=b.k*(p.shiftKey?.5:2),z=n(E(w(b,C),A,N),t.apply(this,O),a);yt(p),o>0?Ae(this).transition().duration(o).call(D,z,A,p):Ae(this).call(d.transform,z,A,p)}}function te(p,...O){if(!!e.apply(this,arguments)){var b=p.touches,A=b.length,N=M(this,O,p.changedTouches.length===A).event(p),C,z,W,Z;for(Sn(p),z=0;z<A;++z)W=b[z],Z=Ye(W,this),Z=[Z,this.__zoom.invert(Z),W.identifier],N.touch0?!N.touch1&&N.touch0[2]!==Z[2]&&(N.touch1=Z,N.taps=0):(N.touch0=Z,C=!0,N.taps=1+!!c);c&&(c=clearTimeout(c)),C&&(N.taps<2&&(m=Z[0],c=setTimeout(function(){c=null},_)),Gt(this),N.start())}}function ue(p,...O){if(!!this.__zooming){var b=M(this,O).event(p),A=p.changedTouches,N=A.length,C,z,W,Z;for(yt(p),C=0;C<N;++C)z=A[C],W=Ye(z,this),b.touch0&&b.touch0[2]===z.identifier?b.touch0[0]=W:b.touch1&&b.touch1[2]===z.identifier&&(b.touch1[0]=W);if(z=b.that.__zoom,b.touch1){var ae=b.touch0[0],le=b.touch0[1],ve=b.touch1[0],Oe=b.touch1[1],ye=(ye=ve[0]-ae[0])*ye+(ye=ve[1]-ae[1])*ye,Le=(Le=Oe[0]-le[0])*Le+(Le=Oe[1]-le[1])*Le;z=w(z,Math.sqrt(ye/Le)),W=[(ae[0]+ve[0])/2,(ae[1]+ve[1])/2],Z=[(le[0]+Oe[0])/2,(le[1]+Oe[1])/2]}else if(b.touch0)W=b.touch0[0],Z=b.touch0[1];else return;b.zoom("touch",n(E(z,W,Z),b.extent,a))}}function be(p,...O){if(!!this.__zooming){var b=M(this,O).event(p),A=p.changedTouches,N=A.length,C,z;for(Sn(p),h&&clearTimeout(h),h=setTimeout(function(){h=null},_),C=0;C<N;++C)z=A[C],b.touch0&&b.touch0[2]===z.identifier?delete b.touch0:b.touch1&&b.touch1[2]===z.identifier&&delete b.touch1;if(b.touch1&&!b.touch0&&(b.touch0=b.touch1,delete b.touch1),b.touch0)b.touch0[1]=this.__zoom.invert(b.touch0[0]);else if(b.end(),b.taps===2&&(z=Ye(z,this),Math.hypot(m[0]-z[0],m[1]-z[1])<v)){var W=Ae(this).on("dblclick.zoom");W&&W.apply(this,arguments)}}}return d.wheelDelta=function(p){return arguments.length?(r=typeof p=="function"?p:Kt(+p),d):r},d.filter=function(p){return arguments.length?(e=typeof p=="function"?p:Kt(!!p),d):e},d.touchable=function(p){return arguments.length?(i=typeof p=="function"?p:Kt(!!p),d):i},d.extent=function(p){return arguments.length?(t=typeof p=="function"?p:Kt([[+p[0][0],+p[0][1]],[+p[1][0],+p[1][1]]]),d):t},d.scaleExtent=function(p){return arguments.length?(s[0]=+p[0],s[1]=+p[1],d):[s[0],s[1]]},d.translateExtent=function(p){return arguments.length?(a[0][0]=+p[0][0],a[1][0]=+p[1][0],a[0][1]=+p[0][1],a[1][1]=+p[1][1],d):[[a[0][0],a[0][1]],[a[1][0],a[1][1]]]},d.constrain=function(p){return arguments.length?(n=p,d):n},d.duration=function(p){return arguments.length?(o=+p,d):o},d.interpolate=function(p){return arguments.length?(l=p,d):l},d.on=function(){var p=u.on.apply(u,arguments);return p===u?d:p},d.clickDistance=function(p){return arguments.length?(S=(p=+p)*p,d):Math.sqrt(S)},d.tapDistance=function(p){return arguments.length?(v=+p,d):v},d}const ke=et(""),Dn=et(Tt),Jt=et(),Un=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 Cr(e){let t,n,r;return{c(){t=X("div"),n=X("div"),r=Re(e[6]),this.h()},l(i){t=Y(i,"DIV",{class:!0});var s=$(t);n=Y(s,"DIV",{class:!0});var a=$(n);r=Me(a,e[6]),a.forEach(x),s.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,s){B(i,t,s),F(t,n),F(n,r)},p(i,s){s&64&&At(r,i[6])},d(i){i&&x(t)}}}function Rr(e){let t,n,r;return n=new wi({}),{c(){t=X("div"),ce(n.$$.fragment),this.h()},l(i){t=Y(i,"DIV",{class:!0});var s=$(t);fe(n.$$.fragment,s),s.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,s){B(i,t,s),he(n,t,null),r=!0},i(i){r||(H(n.$$.fragment,i),r=!0)},o(i){q(n.$$.fragment,i),r=!1},d(i){i&&x(t),de(n)}}}function Mr(e){let t,n,r,i,s,a,o,l,u,c,m,h,_,P,S;r=new bi({props:{isLoading:e[4]}}),r.$on("click",e[17]);let v=e[8]!==""&&$r(e);u=new Go({props:{className:"p-1",isLoading:e[4],isActive:e[1]}}),u.$on("click",e[11]),h=new ta({props:{isLoading:e[4],className:"p-1",isActive:!e[1]}}),h.$on("click",e[12]);let d=!e[1]&&Ur(e);return{c(){t=X("div"),n=X("div"),ce(r.$$.fragment),i=se(),v&&v.c(),a=se(),o=X("div"),l=X("div"),ce(u.$$.fragment),c=se(),m=X("div"),ce(h.$$.fragment),_=se(),d&&d.c(),this.h()},l(w){t=Y(w,"DIV",{class:!0,style:!0});var E=$(t);n=Y(E,"DIV",{class:!0});var y=$(n);fe(r.$$.fragment,y),y.forEach(x),i=oe(E),v&&v.l(E),E.forEach(x),a=oe(w),o=Y(w,"DIV",{class:!0,style:!0});var D=$(o);l=Y(D,"DIV",{class:!0});var M=$(l);fe(u.$$.fragment,M),c=oe(M),m=Y(M,"DIV",{class:!0});var L=$(m);fe(h.$$.fragment,L),_=oe(L),d&&d.l(L),L.forEach(x),M.forEach(x),D.forEach(x),this.h()},h(){g(n,"class","py-3"),g(t,"class","absolute top-full"),g(t,"style",s=`transform: scale(${Math.max(2-e[0].k,1)}); transform-origin: 0 0;`),g(m,"class","flex bg-white rounded-full mt-3 shadow-lg"),g(l,"class","mx-4"),g(o,"class","absolute left-full"),g(o,"style",P=`transform: scale(${Math.max(2-e[0].k,1)}); transform-origin: 0 0;`)},m(w,E){B(w,t,E),F(t,n),he(r,n,null),F(t,i),v&&v.m(t,null),B(w,a,E),B(w,o,E),F(o,l),he(u,l,null),F(l,c),F(l,m),he(h,m,null),F(m,_),d&&d.m(m,null),S=!0},p(w,E){const y={};E&16&&(y.isLoading=w[4]),r.$set(y),w[8]!==""?v?v.p(w,E):(v=$r(w),v.c(),v.m(t,null)):v&&(v.d(1),v=null),(!S||E&1&&s!==(s=`transform: scale(${Math.max(2-w[0].k,1)}); transform-origin: 0 0;`))&&g(t,"style",s);const D={};E&16&&(D.isLoading=w[4]),E&2&&(D.isActive=w[1]),u.$set(D);const M={};E&16&&(M.isLoading=w[4]),E&2&&(M.isActive=!w[1]),h.$set(M),w[1]?d&&(Fe(),q(d,1,1,()=>{d=null}),Ke()):d?(d.p(w,E),E&2&&H(d,1)):(d=Ur(w),d.c(),H(d,1),d.m(m,null)),(!S||E&1&&P!==(P=`transform: scale(${Math.max(2-w[0].k,1)}); transform-origin: 0 0;`))&&g(o,"style",P)},i(w){S||(H(r.$$.fragment,w),H(u.$$.fragment,w),H(h.$$.fragment,w),H(d),S=!0)},o(w){q(r.$$.fragment,w),q(u.$$.fragment,w),q(h.$$.fragment,w),q(d),S=!1},d(w){w&&x(t),de(r),v&&v.d(),w&&x(a),w&&x(o),de(u),de(h),d&&d.d()}}}function $r(e){let t,n,r,i,s=e[8]==="NFSW"&&Dr();return{c(){t=X("div"),s&&s.c(),n=se(),r=X("p"),i=Re(e[8]),this.h()},l(a){t=Y(a,"DIV",{class:!0});var o=$(t);s&&s.l(o),n=oe(o),r=Y(o,"P",{});var l=$(r);i=Me(l,e[8]),l.forEach(x),o.forEach(x),this.h()},h(){g(t,"class","p-3 bg-white rounded-lg font-mono")},m(a,o){B(a,t,o),s&&s.m(t,null),F(t,n),F(t,r),F(r,i)},p(a,o){a[8]==="NFSW"?s||(s=Dr(),s.c(),s.m(t,n)):s&&(s.d(1),s=null),o&256&&At(i,a[8])},d(a){a&&x(t),s&&s.d()}}}function Dr(e){let t,n,r,i,s;return{c(){t=X("h2"),n=Re("NSFW Alert"),r=se(),i=X("h3"),s=Re("Possible NSFW result detected, please try again"),this.h()},l(a){t=Y(a,"H2",{class:!0});var o=$(t);n=Me(o,"NSFW Alert"),o.forEach(x),r=oe(a),i=Y(a,"H3",{class:!0});var l=$(i);s=Me(l,"Possible NSFW result detected, please try again"),l.forEach(x),this.h()},h(){g(t,"class","text-red-500 text-2xl font-bold"),g(i,"class","text-red-500 text-lg")},m(a,o){B(a,t,o),F(t,n),B(a,r,o),B(a,i,o),F(i,s)},d(a){a&&x(t),a&&x(r),a&&x(i)}}}function Ur(e){let t,n,r,i;return r=new aa({props:{className:"p-1",isLoading:e[4]}}),r.$on("click",e[13]),{c(){t=X("span"),n=se(),ce(r.$$.fragment),this.h()},l(s){t=Y(s,"SPAN",{class:!0}),$(t).forEach(x),n=oe(s),fe(r.$$.fragment,s),this.h()},h(){g(t,"class","border-gray-800 border-opacity-50 border-r-2 my-2")},m(s,a){B(s,t,a),B(s,n,a),he(r,s,a),i=!0},p(s,a){const o={};a&16&&(o.isLoading=s[4]),r.$set(o)},i(s){i||(H(r.$$.fragment,s),i=!0)},o(s){q(r.$$.fragment,s),i=!1},d(s){s&&x(t),s&&x(n),de(r,s)}}}function Xc(e){let t,n,r,i,s,a,o,l,u,c,m,h,_,P,S,v=e[6]&&Cr(e),d=e[4]&&Rr(),w=!e[3]&&Mr(e);return{c(){t=X("div"),n=X("div"),r=X("div"),i=X("canvas"),a=se(),o=X("div"),v&&v.c(),l=se(),d&&d.c(),u=se(),w&&w.c(),m=se(),h=X("div"),this.h()},l(E){t=Y(E,"DIV",{});var y=$(t);n=Y(y,"DIV",{class:!0,style:!0});var D=$(n);r=Y(D,"DIV",{class:!0});var M=$(r);i=Y(M,"CANVAS",{class:!0,width:!0,height:!0}),$(i).forEach(x),a=oe(M),o=Y(M,"DIV",{class:!0});var L=$(o);v&&v.l(L),L.forEach(x),l=oe(M),d&&d.l(M),u=oe(M),w&&w.l(M),M.forEach(x),D.forEach(x),m=oe(y),h=Y(y,"DIV",{class:!0,style:!0}),$(h).forEach(x),y.forEach(x),this.h()},h(){g(i,"class",s=e[1]?"":"bg-white"),g(i,"width","512"),g(i,"height","512"),g(o,"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(h,"class",_="absolute top-0 left-0 w-[512px] h-[512px] ring-8 hand "+(e[1]?"block":"hidden")+" svelte-xtgdq4"),g(h,"style",P=`transform: translateX(${e[5].x}px) translateY(${e[5].y}px) scale(${e[0].k}); transform-origin: 0 0;`)},m(E,y){B(E,t,y),F(t,n),F(n,r),F(r,i),e[16](i),F(r,a),F(r,o),v&&v.m(o,null),F(r,l),d&&d.m(r,null),F(r,u),w&&w.m(r,null),F(t,m),F(t,h),e[18](h),S=!0},p(E,[y]){(!S||y&2&&s!==(s=E[1]?"":"bg-white"))&&g(i,"class",s),E[6]?v?v.p(E,y):(v=Cr(E),v.c(),v.m(o,null)):v&&(v.d(1),v=null),E[4]?d?y&16&&H(d,1):(d=Rr(),d.c(),H(d,1),d.m(r,u)):d&&(Fe(),q(d,1,1,()=>{d=null}),Ke()),E[3]?w&&(Fe(),q(w,1,1,()=>{w=null}),Ke()):w?(w.p(E,y),y&8&&H(w,1)):(w=Mr(E),w.c(),H(w,1),w.m(r,null)),(!S||y&33&&c!==(c=`transform: translateX(${E[5].x}px) translateY(${E[5].y}px) scale(${E[0].k}); transform-origin: 0 0;`))&&g(n,"style",c),(!S||y&2&&_!==(_="absolute top-0 left-0 w-[512px] h-[512px] ring-8 hand "+(E[1]?"block":"hidden")+" svelte-xtgdq4"))&&g(h,"class",_),(!S||y&33&&P!==(P=`transform: translateX(${E[5].x}px) translateY(${E[5].y}px) scale(${E[0].k}); transform-origin: 0 0;`))&&g(h,"style",P)},i(E){S||(H(d),H(w),S=!0)},o(E){q(d),q(w),S=!1},d(E){E&&x(t),e[16](null),v&&v.d(),d&&d.d(),w&&w.d(),e[18](null)}}}function Yc(e,t,n){let r,i,s,a,o,l,u;Ie(e,Un,O=>n(7,a=O)),Ie(e,Jt,O=>n(22,o=O)),Ie(e,ke,O=>n(8,u=O));const c=dn();Ie(e,c,O=>n(15,l=O));const m=Vn();let{transform:h}=t,_,P={x:768,y:768},S,v=!0,d=!1,w=0,E=0;function y(O){_.save(),_.clearRect(0,0,512,512),_.globalCompositeOperation="source-over",_.drawImage(o,O.x,O.y,512,512,0,0,512,512),_.restore()}function D(O){_.save(),_.globalCompositeOperation="destination-out",_.beginPath(),_.moveTo(O.lastx,O.lasty),_.lineTo(O.x,O.y),_.lineWidth=50,_.lineCap="round",_.strokeStyle="black",_.stroke(),_.restore()}Nt(()=>{_=a.getContext("2d"),Ae(S).call(V()).call(M),Ae(a).call(L()).call(M)});function M(O){function b(N){c.update({cursor:{x:h.invertX(N.clientX),y:h.invertY(N.clientY)}})}function A(){c.update({cursor:null})}return O.on("pointermove",b).on("pointerleave",A)}function L(){let O,b;function A(C){if(i)return;const z=C.x/h.k,W=C.y/h.k;O=z,b=W}function N(C){if(i)return;const z=C.x/h.k,W=C.y/h.k;D({x:z,y:W,lastx:O,lasty:b}),O=z,b=W}return _r().on("start",A).on("drag",N)}function V(){function O(N){if(i)return;const C=N.sourceEvent.target.getBoundingClientRect();typeof TouchEvent<"u"&&N.sourceEvent instanceof TouchEvent?(w=N.sourceEvent.targetTouches[0].pageX-C.left,E=N.sourceEvent.targetTouches[0].pageY-C.top):N.sourceEvent instanceof MouseEvent&&(w=N.sourceEvent.pageX-C.left,E=N.sourceEvent.pageY-C.top),n(3,d=!0)}function b(N){if(i)return;const C=Ut(h.invertX(N.x-w)),z=Ut(h.invertY(N.y-E));n(14,P={x:C,y:z}),c.update({cursor:{x:h.invertX(N.x),y:h.invertY(N.y)}}),y({x:C,y:z})}function A(N){if(i)return;n(3,d=!1);const C=Ut(h.invertX(N.x-w)),z=Ut(h.invertY(N.y-E));y({x:C,y:z}),c.update({frame:{x:C,y:z}})}return _r().on("start",O).on("drag",b).on("end",A)}function j(){n(1,v=!0),c.update({status:ie.dragging})}function J(){n(1,v=!1),y(P),c.update({status:ie.masking})}function te(){y(P)}function ue(O){Et[O?"unshift":"push"](()=>{a=O,Un.set(a)})}const be=()=>m("prompt");function p(O){Et[O?"unshift":"push"](()=>{S=O,n(2,S)})}return e.$$set=O=>{"transform"in O&&n(0,h=O.transform)},e.$$.update=()=>{e.$$.dirty&32768&&n(6,r=l==null?void 0:l.currentPrompt),e.$$.dirty&32768&&n(4,i=(l==null?void 0:l.status)===ie.loading||(l==null?void 0:l.status)===ie.prompting||!1),e.$$.dirty&32770&&!v&&l.status===ie.loading&&n(1,v=!0),e.$$.dirty&16385&&n(5,s={x:h.applyX(P.x),y:h.applyY(P.y)})},[h,v,S,d,i,s,r,a,u,c,m,j,J,te,P,l,ue,be,p]}class qc extends pe{constructor(t){super(),me(this,t,Yc,Xc,_e,{transform:0})}}const jc="wss://spaces.huggingface.tech/huggingface-projects/stable-diffusion-multiplayer/gradio/queue/join",Gc="https://d26smi9133w0oo.cloudfront.net/uploads";function Jc(e){let t,n,r,i;const s=e[8].default,a=zn(s,e,e[7],null);return{c(){t=X("div"),n=X("canvas"),r=se(),a&&a.c(),this.h()},l(o){t=Y(o,"DIV",{class:!0});var l=$(t);n=Y(l,"CANVAS",{width:!0,height:!0,class:!0}),$(n).forEach(x),r=oe(l),a&&a.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(o,l){B(o,t,l),F(t,n),e[9](n),F(t,r),a&&a.m(t,null),e[10](t),i=!0},p(o,[l]){a&&a.p&&(!i||l&128)&&Hn(a,s,o,o[7],i?Kn(s,o[7],l,null):Fn(o[7]),null)},i(o){i||(H(a,o),i=!0)},o(o){q(a,o),i=!1},d(o){o&&x(t),e[9](null),a&&a.d(o),e[10](null)}}}function Wc(e,t,n){let r,i,s;Ie(e,Dn,L=>n(12,r=L)),Ie(e,Jt,L=>n(1,i=L));let{$$slots:a={},$$scope:o}=t;const l=dn(),u=$i("promptImgStorage");Ie(e,u,L=>n(6,s=L));const c=512*5,m=512*5;let h,_;const P=new Set;function S(L){return L?Object.values(L).sort((j,J)=>j.date-J.date).filter(({id:j})=>!P.has(j)):[]}let v=[];Nt(()=>{const V=(m+400)/(h.clientHeight>h.clientWidth?h.clientWidth:h.clientHeight),j=Bc().scaleExtent([1/V/2,3]).translateExtent([[-200,-200],[m+200,c+200]]).tapDistance(10).on("zoom",w),J=Ae(i.parentElement).call(j).call(j.transform,Tt).call(j.scaleTo,1/V).on("pointermove",E).on("pointerleave",y);_=i.getContext("2d");function te(){const ue=(m+400)/(h.clientHeight>h.clientWidth?h.clientWidth:h.clientHeight);J.call(j.transform,Tt),J.call(j.scaleTo,1/ue)}return window.addEventListener("resize",te),()=>{window.removeEventListener("resize",te)}});function d(L){Promise.all(L.map(({imgURL:V,position:j,id:J})=>new Promise(te=>{const ue=new Image;ue.crossOrigin="anonymous",ue.onload=()=>{const be={img:ue,position:j,id:J};_.drawImage(ue,j.x,j.y,ue.width,ue.height),te(be)},ue.src=`${Gc}/${V}`}))).then(V=>{V.forEach(({img:j,position:J,id:te})=>{P.add(te),_.drawImage(j,J.x,J.y,j.width,j.height)})})}function w(L){const V=Ee(Dn,r=L.transform,r);Ee(Jt,i.style.transform=`translate(${V.x}px, ${V.y}px) scale(${V.k})`,i)}function E(L){L.preventDefault();const V=r.invertX(L.clientX),j=r.invertY(L.clientY);l.update({cursor:{x:V,y:j}})}function y(){l.update({cursor:null})}function D(L){Et[L?"unshift":"push"](()=>{i=L,Jt.set(i)})}function M(L){Et[L?"unshift":"push"](()=>{h=L,n(0,h)})}return e.$$set=L=>{"$$scope"in L&&n(7,o=L.$$scope)},e.$$.update=()=>{e.$$.dirty&64&&n(5,v=S(s==null?void 0:s.toObject())),e.$$.dirty&32&&v&&d(v)},[h,i,u,c,m,v,s,o,a,D,M]}class Zc extends pe{constructor(t){super(),me(this,t,Wc,Jc,_e,{})}}function Qc(e){let t,n,r;return n=new bi({props:{isLoading:e[0]}}),n.$on("click",e[2]),{c(){t=X("div"),ce(n.$$.fragment),this.h()},l(i){t=Y(i,"DIV",{class:!0});var s=$(t);fe(n.$$.fragment,s),s.forEach(x),this.h()},h(){g(t,"class","grid grid-cols-1 gap-3 w-max mx-auto")},m(i,s){B(i,t,s),he(n,t,null),r=!0},p(i,[s]){const a={};s&1&&(a.isLoading=i[0]),n.$set(a)},i(i){r||(H(n.$$.fragment,i),r=!0)},o(i){q(n.$$.fragment,i),r=!1},d(i){i&&x(t),de(n)}}}function ef(e,t,n){const r=Vn();let{isLoading:i=!1}=t;const s=o=>{o.key==="Enter"&&r("prompt")};Nt(()=>(window.addEventListener("keyup",s),()=>{window.removeEventListener("keyup",s)}));const a=()=>r("prompt");return e.$$set=o=>{"isLoading"in o&&n(0,i=o.isLoading)},[i,r,a]}class tf extends pe{constructor(t){super(),me(this,t,ef,Qc,_e,{isLoading:0})}}function nf(e){let t,n,r,i,s,a,o,l;return{c(){t=X("form"),n=X("div"),r=X("input"),i=se(),s=X("button"),a=Re("Paint"),this.h()},l(u){t=Y(u,"FORM",{class:!0});var c=$(t);n=Y(c,"DIV",{class:!0});var m=$(n);r=Y(m,"INPUT",{class:!0,placeholder:!0,title:!0,type:!0,name:!0}),i=oe(m),s=Y(m,"BUTTON",{class:!0,type:!0});var h=$(s);a=Me(h,"Paint"),h.forEach(x),m.forEach(x),c.forEach(x),this.h()},h(){r.value=e[0],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(s,"class","font-mono border-l-2 pl-2"),g(s,"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){B(u,t,c),F(t,n),F(n,r),e[6](r),F(n,i),F(n,s),F(s,a),o||(l=[Ze(r,"click",ps(e[5])),Ze(r,"input",e[3]),Ze(s,"click",sr(e[2])),Ze(t,"submit",sr(e[2]))],o=!0)},p(u,[c]){c&1&&r.value!==u[0]&&(r.value=u[0])},i:we,o:we,d(u){u&&x(t),e[6](null),o=!1,ms(l)}}}function rf(e,t,n){const r=Vn();let{initPrompt:i=""}=t,s,a;const o=dn(),l=v=>{v.key==="Escape"&&_(v)};Nt(()=>(a.focus(),a.addEventListener("focusout",_),n(0,s=i),window.addEventListener("keyup",l),()=>{window.removeEventListener("keyup",l),a.removeEventListener("focusout",_)}));let u;function c(v){clearTimeout(u),u=setTimeout(()=>{n(0,s=v),o.update({currentPrompt:s,status:ie.prompting})},100)}function m(){s.trim()!==""&&(console.log("Prompting with: ",s),r("paint"),r("close"))}function h(v){const d=v.target;c(d.value)}function _(v){!(v instanceof KeyboardEvent)&&(v==null?void 0:v.relatedTarget)!==null||(o.update({status:ie.ready}),r("close"))}function P(v){Lt.call(this,e,v)}function S(v){Et[v?"unshift":"push"](()=>{a=v,n(1,a)})}return e.$$set=v=>{"initPrompt"in v&&n(4,i=v.initPrompt)},[s,a,m,h,i,P,S]}class sf extends pe{constructor(t){super(),me(this,t,rf,nf,_e,{initPrompt:4})}}var Ji={},Wi={},er={exports:{}},ne=String,Zi=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=Zi();er.exports.createColors=Zi;(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:()=>a,default:()=>o});const n=r(er.exports);function r(l){return l&&l.__esModule?l:{default:l}}let i=new Set;function s(l,u,c){typeof process<"u"&&process.env.JEST_WORKER_ID||c&&i.has(c)||(c&&i.add(c),console.warn(""),u.forEach(m=>console.warn(l,"-",m)))}function a(l){return n.default.dim(l)}const o={info(l,u){s(n.default.bold(n.default.cyan("info")),...Array.isArray(l)?[l]:[u,l])},warn(l,u){s(n.default.bold(n.default.yellow("warn")),...Array.isArray(l)?[l]:[u,l])},risk(l,u){s(n.default.bold(n.default.magenta("risk")),...Array.isArray(l)?[l]:[u,l])}}})(Wi);(function(e){Object.defineProperty(e,"__esModule",{value:!0}),Object.defineProperty(e,"default",{enumerable:!0,get:()=>i});const t=n(Wi);function n(s){return s&&s.__esModule?s:{default:s}}function r({version:s,from:a,to:o}){t.default.warn(`${a}-color-renamed`,[`As of Tailwind CSS ${s}, \`${a}\` has been renamed to \`${o}\`.`,"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 of=(Pn.__esModule?Pn:{default:Pn}).default;const Vt=Object.values(of).filter(e=>typeof e=="object").map(e=>e[200]).slice(0,18),Bt=["\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 af=(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 zr(e,t,n){const r=e.slice();return r[16]=t[n].connectionId,r[17]=t[n].presence,r}function Hr(e){var r;let t,n;return t=new sf({props:{initPrompt:(r=e[0])==null?void 0:r.currentPrompt}}),t.$on("paint",e[11]),t.$on("close",e[10]),{c(){ce(t.$$.fragment)},l(i){fe(t.$$.fragment,i)},m(i,s){he(t,i,s),n=!0},p(i,s){var o;const a={};s&1&&(a.initPrompt=(o=i[0])==null?void 0:o.currentPrompt),t.$set(a)},i(i){n||(H(t.$$.fragment,i),n=!0)},o(i){q(t.$$.fragment,i),n=!1},d(i){de(t,i)}}}function Fr(e){let t=[],n=new Map,r,i,s=[...e[5]];const a=o=>o[16];for(let o=0;o<s.length;o+=1){let l=zr(e,s,o),u=a(l);n.set(u,t[o]=Br(u,l))}return{c(){for(let o=0;o<t.length;o+=1)t[o].c();r=Qe()},l(o){for(let l=0;l<t.length;l+=1)t[l].l(o);r=Qe()},m(o,l){for(let u=0;u<t.length;u+=1)t[u].m(o,l);B(o,r,l),i=!0},p(o,l){l&48&&(s=[...o[5]],Fe(),t=_s(t,l,a,1,o,s,n,r.parentNode,gs,Br,r,zr),Ke())},i(o){if(!i){for(let l=0;l<s.length;l+=1)H(t[l]);i=!0}},o(o){for(let l=0;l<t.length;l+=1)q(t[l]);i=!1},d(o){for(let l=0;l<t.length;l+=1)t[l].d(o);o&&x(r)}}}function Kr(e){var r,i,s;let t,n;return t=new zo({props:{isLoading:((r=e[17])==null?void 0:r.status)===ie.loading,position:(i=e[17])==null?void 0:i.frame,prompt:(s=e[17])==null?void 0:s.currentPrompt,transform:e[4]}}),{c(){ce(t.$$.fragment)},l(a){fe(t.$$.fragment,a)},m(a,o){he(t,a,o),n=!0},p(a,o){var u,c,m;const l={};o&32&&(l.isLoading=((u=a[17])==null?void 0:u.status)===ie.loading),o&32&&(l.position=(c=a[17])==null?void 0:c.frame),o&32&&(l.prompt=(m=a[17])==null?void 0:m.currentPrompt),o&16&&(l.transform=a[4]),t.$set(l)},i(a){n||(H(t.$$.fragment,a),n=!0)},o(a){q(t.$$.fragment,a),n=!1},d(a){de(t,a)}}}function Vr(e){var r;let t,n;return t=new Mo({props:{emoji:Bt[1+e[16]%(Bt.length-1)],color:Vt[1+e[16]%(Vt.length-1)],position:(r=e[17])==null?void 0:r.cursor,transform:e[4]}}),{c(){ce(t.$$.fragment)},l(i){fe(t.$$.fragment,i)},m(i,s){he(t,i,s),n=!0},p(i,s){var o;const a={};s&32&&(a.emoji=Bt[1+i[16]%(Bt.length-1)]),s&32&&(a.color=Vt[1+i[16]%(Vt.length-1)]),s&32&&(a.position=(o=i[17])==null?void 0:o.cursor),s&16&&(a.transform=i[4]),t.$set(a)},i(i){n||(H(t.$$.fragment,i),n=!0)},o(i){q(t.$$.fragment,i),n=!1},d(i){de(t,i)}}}function Br(e,t){var l,u,c,m,h;let n,r,i,s,a=(((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)&&((m=t[17])==null?void 0:m.frame)&&Kr(t),o=((h=t[17])==null?void 0:h.cursor)&&Vr(t);return{key:e,first:null,c(){n=Qe(),a&&a.c(),r=se(),o&&o.c(),i=Qe(),this.h()},l(_){n=Qe(),a&&a.l(_),r=oe(_),o&&o.l(_),i=Qe(),this.h()},h(){this.first=n},m(_,P){B(_,n,P),a&&a.m(_,P),B(_,r,P),o&&o.m(_,P),B(_,i,P),s=!0},p(_,P){var S,v,d,w,E;t=_,(((S=t[17])==null?void 0:S.status)===ie.loading||((v=t[17])==null?void 0:v.status)===ie.prompting||((d=t[17])==null?void 0:d.status)===ie.masking)&&((w=t[17])==null?void 0:w.frame)?a?(a.p(t,P),P&32&&H(a,1)):(a=Kr(t),a.c(),H(a,1),a.m(r.parentNode,r)):a&&(Fe(),q(a,1,1,()=>{a=null}),Ke()),(E=t[17])!=null&&E.cursor?o?(o.p(t,P),P&32&&H(o,1)):(o=Vr(t),o.c(),H(o,1),o.m(i.parentNode,i)):o&&(Fe(),q(o,1,1,()=>{o=null}),Ke())},i(_){s||(H(a),H(o),s=!0)},o(_){q(a),q(o),s=!1},d(_){_&&x(n),a&&a.d(_),_&&x(r),o&&o.d(_),_&&x(i)}}}function lf(e){let t,n,r,i,s,a,o,l,u,c,m,h,_,P,S=e[1]&&Hr(e);a=new Zc({}),u=new qc({props:{transform:e[4]}}),u.$on("prompt",e[9]);let v=e[5]&&Fr(e);return _=new tf({props:{isLoading:e[2]}}),_.$on("prompt",e[9]),{c(){t=X("div"),n=Re(e[3]),r=se(),S&&S.c(),i=se(),s=X("div"),ce(a.$$.fragment),o=se(),l=X("main"),ce(u.$$.fragment),c=se(),v&&v.c(),m=se(),h=X("div"),ce(_.$$.fragment),this.h()},l(d){t=Y(d,"DIV",{class:!0});var w=$(t);n=Me(w,e[3]),w.forEach(x),r=oe(d),S&&S.l(d),i=oe(d),s=Y(d,"DIV",{class:!0});var E=$(s);fe(a.$$.fragment,E),o=oe(E),l=Y(E,"MAIN",{class:!0});var y=$(l);fe(u.$$.fragment,y),c=oe(y),v&&v.l(y),y.forEach(x),E.forEach(x),m=oe(d),h=Y(d,"DIV",{class:!0});var D=$(h);fe(_.$$.fragment,D),D.forEach(x),this.h()},h(){g(t,"class","text touch-none pointer-events-none"),g(l,"class","z-10 relative"),g(s,"class","fixed top-0 left-0 z-0 w-screen h-screen"),g(h,"class","fixed bottom-0 left-0 right-0 z-10 my-2")},m(d,w){B(d,t,w),F(t,n),B(d,r,w),S&&S.m(d,w),B(d,i,w),B(d,s,w),he(a,s,null),F(s,o),F(s,l),he(u,l,null),F(l,c),v&&v.m(l,null),B(d,m,w),B(d,h,w),he(_,h,null),P=!0},p(d,[w]){(!P||w&8)&&At(n,d[3]),d[1]?S?(S.p(d,w),w&2&&H(S,1)):(S=Hr(d),S.c(),H(S,1),S.m(i.parentNode,i)):S&&(Fe(),q(S,1,1,()=>{S=null}),Ke());const E={};w&16&&(E.transform=d[4]),u.$set(E),d[5]?v?(v.p(d,w),w&32&&H(v,1)):(v=Fr(d),v.c(),H(v,1),v.m(l,null)):v&&(Fe(),q(v,1,1,()=>{v=null}),Ke());const y={};w&4&&(y.isLoading=d[2]),_.$set(y)},i(d){P||(H(S),H(a.$$.fragment,d),H(u.$$.fragment,d),H(v),H(_.$$.fragment,d),P=!0)},o(d){q(S),q(a.$$.fragment,d),q(u.$$.fragment,d),q(v),q(_.$$.fragment,d),P=!1},d(d){d&&x(t),d&&x(r),S&&S.d(d),d&&x(i),d&&x(s),de(a),de(u),v&&v.d(),d&&x(m),d&&x(h),de(_)}}}function uf(e){return`${e.x}_${e.y}`}function cf(e,t,n){let r,i,s,a,o,l,u;Ie(e,ke,E=>n(3,i=E)),Ie(e,Un,E=>n(13,a=E)),Ie(e,Dn,E=>n(4,l=E));const c=dn();Ie(e,c,E=>n(0,o=E));const m=Ql();Ie(e,m,E=>n(5,u=E));const h={cursor:null,frame:null,status:ie.dragging,currentPrompt:""};c.update(h);const _=$i("promptImgStorage");Ie(e,_,E=>n(12,s=E));let P=!1;function S(){!r&&!P&&(n(1,P=!0),c.update({status:ie.prompting}))}function v(){n(1,P=!1),console.log("close Modal")}function d(){console.log("onPaint"),w(),n(1,P=!1)}async function w(){if(r)return;Ee(ke,i="Pending",i);const E=o.currentPrompt,y=o.frame;console.log("Generating...",E,y),c.update({status:ie.loading});const D=crypto.randomUUID(),M=a.toDataURL("image/png"),L={fn_index:0,data:[M,E,.75,7.5,40,"patchmatch"],session_hash:D};console.log("payload",L);const V=new WebSocket(jc);V.onclose=j=>{j.wasClean||(Ee(ke,i="Error",i),c.update({status:ie.ready}))},V.onmessage=async function(j){try{const J=JSON.parse(j.data);switch(Ee(ke,i="",i),J.msg){case"send_data":Ee(ke,i="Sending Data",i),V.send(JSON.stringify(L));break;case"queue_full":Ee(ke,i="Queue full",i),V.close(),c.update({status:ie.ready});return;case"estimation":const{rank:te,queue_size:ue}=J;Ee(ke,i=`On queue ${te}/${ue}`,i);break;case"process_generating":Ee(ke,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("NFSW");const O=uf(y),b=await Gl(be),A=await Jl(b,E,O),N={prompt:E,imgURL:A,position:y,date:new Date().getTime(),id:af()};s.set(O,N),console.log(A),Ee(ke,i=J.success?"Complete":"Error",i),setTimeout(()=>{Ee(ke,i="",i)},2e3)}catch(be){const p=be;Ee(ke,i=p==null?void 0:p.message,i)}V.close(),c.update({status:ie.ready,currentPrompt:""});return;case"process_starts":Ee(ke,i="Processing",i);break}}catch(J){console.error(J),Ee(ke,i="Error",i)}}}return e.$$.update=()=>{e.$$.dirty&1&&n(2,r=(o==null?void 0:o.status)===ie.loading||!1)},[o,P,r,i,l,u,c,m,_,S,v,d]}class ff extends pe{constructor(t){super(),me(this,t,cf,lf,_e,{})}}function Xr(e){let t,n;return t=new Io({props:{client:e[2],$$slots:{default:[df]},$$scope:{ctx:e}}}),{c(){ce(t.$$.fragment)},l(r){fe(t.$$.fragment,r)},m(r,i){he(t,r,i),n=!0},p(r,i){const s={};i&4&&(s.client=r[2]),i&9&&(s.$$scope={dirty:i,ctx:r}),t.$set(s)},i(r){n||(H(t.$$.fragment,r),n=!0)},o(r){q(t.$$.fragment,r),n=!1},d(r){de(t,r)}}}function hf(e){let t,n;return t=new ff({}),{c(){ce(t.$$.fragment)},l(r){fe(t.$$.fragment,r)},m(r,i){he(t,r,i),n=!0},i(r){n||(H(t.$$.fragment,r),n=!0)},o(r){q(t.$$.fragment,r),n=!1},d(r){de(t,r)}}}function df(e){let t,n;return t=new To({props:{id:e[0],$$slots:{default:[hf]},$$scope:{ctx:e}}}),{c(){ce(t.$$.fragment)},l(r){fe(t.$$.fragment,r)},m(r,i){he(t,r,i),n=!0},p(r,i){const s={};i&1&&(s.id=r[0]),i&8&&(s.$$scope={dirty:i,ctx:r}),t.$set(s)},i(r){n||(H(t.$$.fragment,r),n=!0)},o(r){q(t.$$.fragment,r),n=!1},d(r){de(t,r)}}}function pf(e){let t,n,r=e[1]&&Xr(e);return{c(){r&&r.c(),t=Qe()},l(i){r&&r.l(i),t=Qe()},m(i,s){r&&r.m(i,s),B(i,t,s),n=!0},p(i,[s]){i[1]?r?(r.p(i,s),s&2&&H(r,1)):(r=Xr(i),r.c(),H(r,1),r.m(t.parentNode,t)):r&&(Fe(),q(r,1,1,()=>{r=null}),Ke())},i(i){n||(H(r),n=!0)},o(i){q(r),n=!1},d(i){r&&r.d(i),i&&x(t)}}}const vf=!0;function mf(e,t,n){let r,i=!1,s;return Nt(()=>{document.addEventListener("wheel",a=>a.preventDefault(),{passive:!1}),n(0,r="multiplayer-SD"),n(2,s=Eo({publicApiKey:"pk_test_JlUZGH3kQmhmZQiqU2l8eIi5"})),n(1,i=!0)}),[r,i,s]}class yf extends pe{constructor(t){super(),me(this,t,mf,pf,_e,{})}}export{yf as default,vf as prerender}; | |