diff --git "a/static/_app/immutable/components/pages/_page.svelte-2e084fa5.js" "b/static/_app/immutable/components/pages/_page.svelte-2e084fa5.js" deleted file mode 100644--- "a/static/_app/immutable/components/pages/_page.svelte-2e084fa5.js" +++ /dev/null @@ -1,3 +0,0 @@ -import{S as ge,i as ve,s as ye,C as Qt,D as en,E as tn,F as nn,f as R,t as z,I as Wn,J as Xn,K as Lt,L as X,M as G,m as O,h,n as c,b as Z,G as w,B as fe,k as j,w as ie,a as Q,l as V,x as se,c as ee,y as oe,z as ae,q as ue,r as ce,u as Fe,g as ke,d as Ie,N as je,O as ft,H as Ee,P as rn,o as st,Q as Qe,R as Ce,e as Me,T as Jr,U as Jt,V as Zr,W as Yr,X as Wr,Y as Xr}from"../../chunks/index-4b3edc7c.js";import{S as yn,r as Gr,d as Gn,P as sn,i as Et,T as Ut,a as xt,m as Zt,c as bt,l as Pe,b as Yt,e as qr,s as Wt,M as kt,f as Qr,E as ht,C as pt}from"../../chunks/constants-8a352b13.js";import{w as Ct}from"../../chunks/index-f611e2e3.js";import{p as ei}from"../../chunks/stores-d0567321.js";var ti=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function ni(e){var t=e.default;if(typeof t=="function"){var n=function(){return t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach(function(r){var i=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(n,r,i.get?i:{enumerable:!0,get:function(){return e[r]}})}),n}var Ne={},N={};Object.defineProperty(N,"__esModule",{value:!0});var ri=Object.defineProperty,ii=Object.defineProperties,si=Object.getOwnPropertyDescriptors,It=Object.getOwnPropertySymbols,qn=Object.prototype.hasOwnProperty,Qn=Object.prototype.propertyIsEnumerable,bn=(e,t,n)=>t in e?ri(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Je=(e,t)=>{for(var n in t||(t={}))qn.call(t,n)&&bn(e,n,t[n]);if(It)for(var n of It(t))Qn.call(t,n)&&bn(e,n,t[n]);return e},ot=(e,t)=>ii(e,si(t)),oi=(e,t)=>{var n={};for(var r in e)qn.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&It)for(var r of It(e))t.indexOf(r)<0&&Qn.call(e,r)&&(n[r]=e[r]);return n},on=(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 Ke(e,t){throw new Error(t)}function q(e,t="Expected value to be non-nullable"){return e}var er=(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))(er||{}),tr=(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))(tr||{}),nr=(e=>(e[e.OBJECT=0]="OBJECT",e[e.LIST=1]="LIST",e[e.MAP=2]="MAP",e[e.REGISTER=3]="REGISTER",e))(nr||{});function rr(e){return e.type===0&&!ir(e)}function ir(e){return e.parentId!==void 0&&e.parentKey!==void 0}var sr=(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))(sr||{});function ai(e){return e==="my-presence"||e==="others"||e==="event"||e==="error"||e==="connection"||e==="history"}var or=(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))(or||{});function wn(e,t){return Object.freeze({type:"HasParent",node:e,key:t})}var En=Object.freeze({type:"NoParent"});function kn(e){return Object.freeze({type:"Orphaned",oldKey:e})}var Pt=class{constructor(){this._parent=En}_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 Ke(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 Ke(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 Ke(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=wn(e,t);return;case"Orphaned":case"NoParent":{this._parent=wn(e,t);return}default:return Ke(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=kn(this.parent.key);break}case"NoParent":{this._parent=En;break}case"Orphaned":{this._parent=kn(this.parent.oldKey);break}default:Ke(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}},Ye=class extends Pt{constructor(e){super(),this._data=e}get data(){return this._data}static _deserialize([e,t],n,r){const i=new Ye(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:q(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}},et=32,an=126;function He(e,t){return e!==void 0&&t!==void 0?Ot(ar(it(e),it(t))):e!==void 0?ui(e):t!==void 0?li(t):Ot([et+1])}function li(e){const t=[],n=it(e);for(let r=0;rs)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(...ar(e.slice(n+1),[]));break}const a=s+i>>1;r.push(a);break}return r}function it(e){const t=[];for(let n=0;nt._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=ut(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:pe(this,[tt(s,r)]),reverse:[]};{this._implicitlyDeletedItems.add(a),this._items[s]=r;const o=[tt(s,r)],l=this._detachItemAssociatedToSetOperation(e.deletedId);return l&&o.push(l),{modified:pe(this,o),reverse:[]}}}else{const a=[],o=this._detachItemAssociatedToSetOperation(e.deletedId);return o&&a.push(o),this._insertAndSort(r),a.push(xe(this._indexOfPosition(n),r)),{reverse:[],modified:pe(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:pe(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?pe(this,t):!1,reverse:[]};i!==-1&&(this._implicitlyDeletedItems.add(this._items[i]),this._items.splice(i,1),t.push(mt(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(Xe(a,o,s)),{modified:t.length>0?pe(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:pe(this,[i===-1?xe(o,a):tt(o,a),...t]),reverse:[]}}else{i!==-1&&this._items.splice(i,1);const{newItem:o,newIndex:l}=this._createAttachItemAndSort(e,e.parentKey);return{modified:pe(this,[i===-1?xe(l,o):tt(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:pe(this,[xe(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:pe(this,[Xe(i,s,t)]),reverse:[]}}}else{const i=q(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:pe(this,[xe(s,i)]),reverse:[]}}else{r!==-1&&this._shiftItemPosition(r,n);const{newItem:s,newIndex:a}=this._createAttachItemAndSort(e,n);return{modified:pe(this,[xe(a,s)]),reverse:[]}}}}_applyInsertUndoRedo(e){var t,n,r;const{id:i,parentKey:s}=e,a=ut(e);if(((t=this._pool)==null?void 0:t.getNode(i))!==void 0)return{modified:!1};a._attach(i,q(this._pool)),a._setParentLink(this,s);const o=this._indexOfPosition(s);let l=s;if(o!==-1){const p=(n=this._items[o])==null?void 0:n._getParentKeyOrThrow(),y=(r=this._items[o+1])==null?void 0:r._getParentKeyOrThrow();l=He(p,y),a._setParentLink(this,l)}this._insertAndSort(a);const u=this._indexOfPosition(l);return{modified:pe(this,[xe(u,a)]),reverse:[{type:5,id:i}]}}_applySetUndoRedo(e){var t;const{id:n,parentKey:r}=e,i=ut(e);if(((t=this._pool)==null?void 0:t.getNode(n))!==void 0)return{modified:!1};this._unacknowledgedSets.set(r,q(e.opId));const s=this._indexOfPosition(r);i._attach(n,q(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(q(this._id),r,this._pool);Ht(l,e.id);const u=[tt(s,i)],p=this._detachItemAssociatedToSetOperation(e.deletedId);return p&&u.push(p),{modified:pe(this,u),reverse:l}}else{this._insertAndSort(i),this._detachItemAssociatedToSetOperation(e.deletedId);const o=this._indexOfPosition(a);return{reverse:[{type:5,id:n}],modified:pe(this,[xe(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=q(e._parentKey),n=e._toOps(q(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:pe(this,[mt(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:pe(this,[xe(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:pe(this,[Xe(s,a,t)]),reverse:[]}}else{this._items[i]._setParentLink(this,He(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:pe(this,[Xe(s,a,t)]),reverse:[]}}}_applySetChildKeyAck(e,t){var n,r;const i=q(t._parentKey);if(this._implicitlyDeletedItems.has(t)){const s=this._indexOfPosition(e);return this._implicitlyDeletedItems.delete(t),s!==-1&&this._items[s]._setParentLink(this,He(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,He(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:pe(this,[Xe(s,o,t)]),reverse:[]}}}_applySetChildKeyUndoRedo(e,t){var n;const r=q(t._parentKey),i=this._items.indexOf(t),s=this._indexOfPosition(e);s!==-1&&this._items[s]._setParentLink(this,He(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:pe(this,[Xe(i,a,t)]),reverse:[{type:1,id:q(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:q(this.parent.node._id,"Parent node expected to have ID"),parentKey:this.parent.key}}get length(){return this._items.length}push(e){var t;return(t=this._pool)==null||t.assertStorageIsWritable(),this.insert(e,this.length)}insert(e,t){var n;if((n=this._pool)==null||n.assertStorageIsWritable(),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 r=this._items[t-1]?this._items[t-1]._getParentKeyOrThrow():void 0,i=this._items[t]?this._items[t]._getParentKeyOrThrow():void 0,s=He(r,i),a=nt(e);if(a._setParentLink(this,s),this._insertAndSort(a),this._pool&&this._id){const o=this._pool.generateId();a._attach(o,this._pool),this._pool.dispatch(a._toOps(this._id,s,this._pool),[{type:5,id:o}],new Map([[this._id,pe(this,[xe(t,a)])]]))}}move(e,t){var n;if((n=this._pool)==null||n.assertStorageIsWritable(),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 r=null,i=null;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 n=this._items[e];if(n._detach(),this._items.splice(e,1),this.invalidate(),this._pool){const r=n._id;if(r){const i=new Map;i.set(q(this._id),pe(this,[mt(e)])),this._pool.dispatch([{id:r,opId:this._pool.generateOpId(),type:5}],n._toOps(q(this._id),n._getParentKeyOrThrow()),i)}}}clear(){var e;if((e=this._pool)==null||e.assertStorageIsWritable(),this._pool){const t=[],n=[],r=[];for(const s of this._items){s._detach();const a=s._id;a&&(t.push({type:5,id:a,opId:this._pool.generateOpId()}),n.push(...s._toOps(q(this._id),s._getParentKeyOrThrow())),r.push(mt(0)))}this._items=[],this.invalidate();const i=new Map;i.set(q(this._id),pe(this,r)),this._pool.dispatch(t,n,i)}else{for(const t of this._items)t._detach();this._items=[],this.invalidate()}}set(e,t){var n;if((n=this._pool)==null||n.assertStorageIsWritable(),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 r=this._items[e],i=r._getParentKeyOrThrow(),s=r._id;r._detach();const a=nt(t);if(a._setParentLink(this,i),this._items[e]=a,this.invalidate(),this._pool&&this._id){const o=this._pool.generateId();a._attach(o,this._pool);const l=new Map;l.set(this._id,pe(this,[tt(e,a)]));const u=a._toOps(this._id,i,this._pool);Ht(u,s),this._unacknowledgedSets.set(i,q(u[0].opId));const p=r._toOps(this._id,i,void 0);Ht(p,o),this._pool.dispatch(u,p,l)}}toArray(){return this._items.map(e=>Ge(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 Ge(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(Ge(t),n))}some(e){return this.toArray().some(e)}[Symbol.iterator](){return new fi(this._items)}_createAttachItemAndSort(e,t){const n=ut(e);n._attach(e.id,q(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=He(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())}},fi=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:Ge(e.value)}}};function pe(e,t){return{node:e,type:"LiveList",updates:t}}function tt(e,t){return{index:e,type:"set",item:t instanceof Ye?t.data:t}}function mt(e){return{index:e,type:"delete"}}function xe(e,t){return{index:e,type:"insert",item:t instanceof Ye?t.data:t}}function Xe(e,t,n){return{index:t,type:"move",previousIndex:e,item:n instanceof Ye?n.data:n}}function Ht(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 We=class extends Pt{constructor(e){if(super(),this.unacknowledgedSet=new Map,e){const t=[];for(const n of e){const r=nt(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 We;i._attach(e,r);const s=n.get(e);if(s===void 0)return i;for(const[a,o]of s){const l=fr([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)be(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=ut(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=q(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=q(this._id),n=q(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:q(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 Ge(t)}set(e,t){var n;(n=this._pool)==null||n.assertStorageIsWritable();const r=this._map.get(e);r&&r._detach();const i=nt(t);if(i._setParentLink(this,e),this._map.set(e,i),this.invalidate(),this._pool&&this._id){const s=this._pool.generateId();i._attach(s,this._pool);const a=new Map;a.set(this._id,{node:this,type:"LiveMap",updates:{[e]:{type:"update"}}});const o=i._toOps(this._id,e,this._pool);this.unacknowledgedSet.set(e,q(o[0].opId)),this._pool.dispatch(i._toOps(this._id,e,this._pool),r?r._toOps(this._id,e):[{type:5,id:s}],a)}}get size(){return this._map.size}has(e){return this._map.has(e)}delete(e){var t;(t=this._pool)==null||t.assertStorageIsWritable();const n=this._map.get(e);if(n===void 0)return!1;if(n._detach(),this._map.delete(e),this.invalidate(),this._pool&&n._id){const r=q(this._id),i=new Map;i.set(r,{node:this,type:"LiveMap",updates:{[e]:{type:"delete"}}}),this._pool.dispatch([{type:5,id:n._id,opId:this._pool.generateOpId()}],n._toOps(r,e),i)}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=Ge(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:Ge(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 De(e)}},Ue=class extends Pt{constructor(e={}){super(),this._propToLastUpdate=new Map;for(const t in e){const n=e[t];n!==void 0&&be(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)be(o)?i.push(...o._toOps(this._id,a,n)):s.data[a]=o;return i}static _deserialize([e,t],n,r){const i=new Ue(t.data);return i._attach(e,r),this._deserializeChildren(i,n,r)}static _deserializeChildren(e,t,n){const r=t.get(q(e._id));if(r===void 0)return e;for(const[i,s]of r){const a=di([i,s],t,n);wt(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)be(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=ur(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,q(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=q(this._id),o=this._map.get(i);let l;return be(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(),wt(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=q(this._id),n=q(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())be(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)be(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=q(this._id),i=[],s={type:3,id:r,data:{}};i.push(s);for(const o in e.data){const l=this._map.get(o);be(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,q(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);be(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=q(this._id);let i=[];return be(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 yi(this._map)}set(e,t){var n;(n=this._pool)==null||n.assertStorageIsWritable(),this.update({[e]:t})}get(e){return this._map.get(e)}delete(e){var t;(t=this._pool)==null||t.assertStorageIsWritable();const n=e,r=this._map.get(n);if(r===void 0)return;if(this._pool===void 0||this._id===void 0){be(r)&&r._detach(),this._map.delete(n),this.invalidate();return}let i;be(r)?(r._detach(),i=r._toOps(this._id,n)):i=[{type:3,data:{[n]:r},id:this._id}],this._map.delete(n),this.invalidate();const s=new Map;s.set(this._id,{node:this,type:"LiveObject",updates:{[e]:{type:"delete"}}}),this._pool.dispatch([{type:6,key:n,id:this._id,opId:this._pool.generateOpId()}],i,s)}update(e){var t;if((t=this._pool)==null||t.assertStorageIsWritable(),this._pool===void 0||this._id===void 0){for(const u in e){const p=e[u];if(p===void 0)continue;const y=this._map.get(u);be(y)&&y._detach(),be(p)&&p._setParentLink(this,u),this._map.set(u,p),this.invalidate()}return}const n=[],r=[],i=this._pool.generateOpId(),s={},a={id:this._id,type:3,data:{}},o={};for(const u in e){const p=e[u];if(p===void 0)continue;const y=this._map.get(u);if(be(y)?(r.push(...y._toOps(this._id,u)),y._detach()):y===void 0?r.push({type:6,id:this._id,key:u}):a.data[u]=y,be(p)){p._setParentLink(this,u),p._attach(this._pool.generateId(),this._pool);const g=p._toOps(this._id,u,this._pool),k=g.find(M=>M.parentId===this._id);k&&this._propToLastUpdate.set(u,q(k.opId)),n.push(...g)}else s[u]=p,this._propToLastUpdate.set(u,i);this._map.set(u,p),this.invalidate(),o[u]={type:"update"}}Object.keys(a.data).length!==0&&r.unshift(a),Object.keys(s).length!==0&&n.unshift({opId:i,id:this._id,type:3,data:s});const l=new Map;l.set(this._id,{node:this,type:"LiveObject",updates:o}),this._pool.dispatch(n,r,l)}toImmutable(){return super.toImmutable()}_toImmutable(){const e={};for(const[t,n]of this._map)e[t]=wt(n)?n.toImmutable():n;return e}},De=e=>e;function Xt(e){return e.filter(t=>t!=null)}function St(e){const t=Je({},e);return Object.keys(e).forEach(n=>{const r=n;t[r]===void 0&&delete t[r]}),t}function ut(e){return nt(ur(e))}function ur(e){switch(e.type){case 8:return e.data;case 4:return new Ue(e.data);case 7:return new We;case 2:return new Ve;default:return Ke(e,"Unknown creation Op")}}function cr(e,t){return e===t?!0:e.parent.type==="HasParent"?cr(e.parent.node,t):!1}function fr([e,t],n,r){switch(t.type){case 0:return Ue._deserialize([e,t],n,r);case 1:return Ve._deserialize([e,t],n,r);case 2:return We._deserialize([e,t],n,r);case 3:return Ye._deserialize([e,t],n,r);default:throw new Error("Unexpected CRDT type")}}function di([e,t],n,r){switch(t.type){case 0:return Ue._deserialize([e,t],n,r);case 1:return Ve._deserialize([e,t],n,r);case 2:return We._deserialize([e,t],n,r);case 3:return t.data;default:throw new Error("Unexpected CRDT type")}}function wt(e){return At(e)||hi(e)||ln(e)}function be(e){return wt(e)||pi(e)}function At(e){return e instanceof Ve}function hi(e){return e instanceof We}function ln(e){return e instanceof Ue}function pi(e){return e instanceof Ye}function Ge(e){return e instanceof Ye?e.data:e instanceof Ve||e instanceof We||e instanceof Ue?e:Ke(e,"Unknown AbstractCrdt")}function nt(e){return e instanceof Ue||e instanceof We||e instanceof Ve?e:new Ye(e)}function mi(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:q(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 _i(e,t){const n=e.updates;for(const[r,i]of dr(t.updates))n[r]=i;return ot(Je({},t),{updates:n})}function gi(e,t){const n=e.updates;for(const[r,i]of dr(t.updates))n[r]=i;return ot(Je({},t),{updates:n})}function vi(e,t){const n=e.updates;return ot(Je({},t),{updates:n.concat(t.updates)})}function jt(e,t){return e?e.type==="LiveObject"&&t.type==="LiveObject"?_i(e,t):e.type==="LiveMap"&&t.type==="LiveMap"?gi(e,t):e.type==="LiveList"&&t.type==="LiveList"?vi(e,t):t:t}function Ze(e){return e!==null&&typeof e=="object"&&Object.prototype.toString.call(e)==="[object Object]"}function yi(e){const t={};for(const[n,r]of e)t[n]=r;return t}function dr(e){return Object.entries(e)}function un(e){try{return JSON.parse(e)}catch{return}}function hr(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 bi(e){if(!Ze(e))return!1;const{iat:t,exp:n}=e;return typeof t=="number"&&typeof n=="number"}function wi(e){const t=Date.now()/1e3;return t>e.exp-300||ttypeof t=="string")}function mr(e){return typeof e.appId=="string"&&e.roomId===void 0&&pr(e.scopes)}function cn(e){return typeof e.appId=="string"&&typeof e.roomId=="string"&&typeof e.actor=="number"&&(e.id===void 0||typeof e.id=="string")&&pr(e.scopes)&&(e.maxConnectionsPerRoom===void 0||typeof e.maxConnectionsPerRoom=="number")}function Ei(e){return mr(e)||cn(e)}function ki(e){const t=e.split(".");if(t.length!==3)throw new Error("Authentication error: invalid JWT token");const n=un(hr(t[1]));if(n&&bi(n))return n;throw new Error("Authentication error: missing JWT metadata")}function In(e){const t=ki(e);if(t&&cn(t))return oi(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 Ii(e,t=e){}function Oi(e,t,n=t){}function Li(e){}function Ci(e,t){}function ze(){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 _r(e,t){let n=!1;const r=Je({},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 Tt=class{constructor(){this._ev=ze()}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()}},Pi=class extends Tt{constructor(e){super(),this._me=De(St(e))}_toImmutable(){return this._me}patch(e){const t=this._me,n=_r(t,e);t!==n&&(this._me=De(n),this.invalidate())}};function gr(e){return Object.defineProperty(e,"count",{value:e.length,enumerable:!1}),Object.defineProperty(e,"toArray",{value:()=>e,enumerable:!1}),De(e)}function Si(e,t){return De(St(ot(Je({},e),{presence:t})))}var Ai=class extends Tt{constructor(){super(),this._connections={},this._presences={},this._users={}}_toImmutable(){const e=Xt(Object.keys(this._presences).map(t=>this.getUser(Number(t))));return gr(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 Si(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,r){this._connections[e]=De({connectionId:e,id:t,info:n,isReadOnly:r}),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]=De(St(t)),this._connections[e]!==void 0&&this._invalidateUser(e)}patchOther(e,t){const n=this._presences[e];if(n===void 0)return;const r=_r(n,t);n!==r&&(this._presences[e]=De(r),this._invalidateUser(e))}};function vr(e){return e===null||typeof e=="string"||typeof e=="number"||typeof e=="boolean"}function fn(e){return Array.isArray(e)}function yr(e){return!vr(e)&&!fn(e)}var Ti=class extends Tt{constructor(e){super(),this._value=De(St(e))}_toImmutable(){return this._value}set(e){this._value=De(e),this.invalidate()}},Mi=class extends Tt{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)}},Vt=[250,500,1e3,2e3,4e3,8e3,1e4],zt=[2e3,3e4,6e4,3e5],$i=3e4,Ri=2e3;function Di(e){let t=0;return()=>`${e}:${t++}`}function _t(e){return e.state==="open"||e.state==="connecting"}function Ni(e,t,n){var r;const i=d=>d(),s=(r=t.unstable_batchedUpdates)!=null?r:i,a={roomId:t.roomId,getNode:d=>e.nodes.get(d),addNode:(d,P)=>void e.nodes.set(d,P),deleteNode:d=>void e.nodes.delete(d),generateId:()=>`${f()}:${e.clock++}`,generateOpId:()=>`${f()}:${e.opClock++}`,dispatch(d,P,A){const D=e.activeBatch;D?(D.ops.push(...d),A.forEach((K,_e)=>{D.updates.storageUpdates.set(_e,jt(D.updates.storageUpdates.get(_e),K))}),D.reverseOps.push(...P)):s(()=>{L(P,i),e.redoStack=[],mn(d),b({storageUpdates:A},i)})},assertStorageIsWritable:()=>{if(_t(e.connection.current)&&e.connection.current.isReadOnly)throw new Error("Cannot write to storage with a read only user, please ensure the user has write permissions")}},o={customEvent:ze(),me:ze(),others:ze(),error:ze(),connection:ze(),storage:ze(),history:ze(),storageDidLoad:ze()},l=n||{authenticate(d,P){const A=e.token,D=A!==null&&In(A);if(D&&!wi(D)){const K=P(A);te(D,K);return}else return d(t.roomId).then(({token:K})=>{if(e.connection.current.state!=="authenticating")return;const _e=In(K),he=P(K);te(_e,he),e.token=K}).catch(K=>re())},send(d){if(e.socket===null)throw new Error("Can't send message if socket is null");e.socket.send(JSON.stringify(d))},delayFlush(d){return setTimeout($e,d)},startHeartbeatInterval(){return setInterval(Ae,$i)},schedulePongTimeout(){return setTimeout(at,Ri)},scheduleReconnect(d){return setTimeout(B,d)}},u=new Mi([e.connection,e.me],(d,P)=>_t(d)?{connectionId:d.id,id:d.userId,info:d.userInfo,presence:P,isReadOnly:d.isReadOnly}:null);function p(d,P){if(d.items.length===0)throw new Error("Internal error: cannot load storage without items");e.root?g(d.items,P):e.root=k(d.items);for(const A in e.initialStorage)e.root.get(A)===void 0&&e.root.set(A,e.initialStorage[A])}function y(d){const P=new Map;let A=null;for(const[D,K]of d)if(rr(K))A=[D,K];else{const _e=[D,K],he=P.get(K.parentId);he!==void 0?he.push(_e):P.set(K.parentId,[_e])}if(A===null)throw new Error("Root can't be null");return[A,P]}function g(d,P){if(!e.root)return;const A=new Map;e.nodes.forEach((_e,he)=>{A.set(he,_e._serialize())});const D=mi(A,new Map(d)),K=_(D,!1);b(K.updates,P)}function k(d){const[P,A]=y(d);return Ue._deserialize(P,A,a)}function M(d,P){e.undoStack.length>=50&&e.undoStack.shift(),e.undoStack.push(d),U(P)}function L(d,P){e.pausedHistory!==null?e.pausedHistory.unshift(...d):M(d,P)}function b({storageUpdates:d=new Map,presence:P=!1,others:A=[]},D){D(()=>{if(A.length>0){const K=e.others.current;for(const _e of A)o.others.notify({others:K,event:_e})}if(P&&o.me.notify(e.me.current),d.size>0){const K=Array.from(d.values());o.storage.notify(K)}})}function f(){const d=e.connection.current;if(_t(d))return d.id;if(e.lastConnectionId!==null)return e.lastConnectionId;throw new Error("Internal. Tried to get connection id but connection was never open")}function _(d,P){const A={reverse:[],updates:{storageUpdates:new Map,presence:!1}},D=new Set;for(const K of d)if(K.type==="presence"){const _e={type:"presence",data:{}};for(const he in K.data)_e.data[he]=e.me.current[he];if(e.me.patch(K.data),e.buffer.me===null)e.buffer.me={type:"partial",data:K.data};else for(const he in K.data)e.buffer.me.data[he]=K.data[he];A.reverse.unshift(_e),A.updates.presence=!0}else{let _e;K.opId||(K.opId=a.generateOpId()),P?_e=0:_e=e.offlineOperations.delete(q(K.opId))?2:1;const he=E(K,_e);if(he.modified){const Nt=he.modified.node.parent.type==="HasParent"?q(he.modified.node.parent.node._id,"Expected parent node to have an ID"):void 0;(!Nt||!D.has(Nt))&&(A.updates.storageUpdates.set(q(he.modified.node._id),jt(A.updates.storageUpdates.get(q(he.modified.node._id)),he.modified)),A.reverse.unshift(...he.reverse)),(K.type===2||K.type===7||K.type===4)&&D.add(q(he.modified.node._id))}}return A}function E(d,P){switch(d.type){case 6:case 3:case 5:{const A=e.nodes.get(d.id);return A===void 0?{modified:!1}:A._apply(d,P===0)}case 1:{const A=e.nodes.get(d.id);return A===void 0?{modified:!1}:A.parent.type==="HasParent"&&At(A.parent.node)?A.parent.node._setChildKey(d.parentKey,A,P):{modified:!1}}case 4:case 2:case 7:case 8:{if(d.parentId===void 0)return{modified:!1};const A=e.nodes.get(d.parentId);return A===void 0?{modified:!1}:A._attachChild(d,P)}}}function m(d,P){return o.storage.subscribe(A=>{const D=A.filter(K=>cr(K.node,d));D.length>0&&P(D)})}function $(d,P){return o.storage.subscribe(A=>{for(const D of A)D.node._id===d._id&&P(D.node)})}function I(d,P,A){if(typeof d=="string"&&ai(d)){if(typeof P!="function")throw new Error("Second argument must be a callback function");const D=P;switch(d){case"event":return o.customEvent.subscribe(D);case"my-presence":return o.me.subscribe(D);case"others":{const K=D;return o.others.subscribe(({others:_e,event:he})=>K(_e,he))}case"error":return o.error.subscribe(D);case"connection":return o.connection.subscribe(D);case"storage":return o.storage.subscribe(D);case"history":return o.history.subscribe(D);default:return Ke(d,"Unknown event")}}if(P===void 0||typeof d=="function")if(typeof d=="function"){const D=d;return o.storage.subscribe(D)}else throw new Error("Please specify a listener callback");if(be(d)){const D=d;return A!=null&&A.isDeep?m(D,P):$(D,P)}throw new Error(`"${d}" is not a valid event name`)}function T(){return e.connection.current.state}function B(){var d,P,A,D;if(e.connection.current.state!=="closed"&&e.connection.current.state!=="unavailable")return;const K=Vi(t.authentication,(P=(d=t.polyfills)==null?void 0:d.fetch)!=null?P:t.fetchPolyfill),_e=ji(t.liveblocksServer,(D=(A=t.polyfills)==null?void 0:A.WebSocket)!=null?D:t.WebSocketPolyfill);le({state:"authenticating"},s),l.authenticate(K,_e)}function x(d,P){const A={};e.buffer.me===null&&(e.buffer.me={type:"partial",data:{}});for(const D in d){const K=d[D];K!==void 0&&(e.buffer.me.data[D]=K,A[D]=e.me.current[D])}e.me.patch(d),e.activeBatch?(P!=null&&P.addToHistory&&e.activeBatch.reverseOps.push({type:"presence",data:A}),e.activeBatch.updates.presence=!0):($e(),s(()=>{P!=null&&P.addToHistory&&L([{type:"presence",data:A}],i),b({presence:!0},i)}))}function J(d){return d.includes("room:read")&&d.includes("room:presence:write")&&!d.includes("room:write")}function te(d,P){P.addEventListener("message",de),P.addEventListener("open",Le),P.addEventListener("close",we),P.addEventListener("error",Se),le({state:"connecting",id:d.actor,userInfo:d.info,userId:d.id,isReadOnly:J(d.scopes)},s),e.idFactory=Di(d.actor),e.socket=P}function re(d){e.token=null,le({state:"unavailable"},s),e.numberOfRetry++,e.timeoutHandles.reconnect=l.scheduleReconnect(Oe())}function W(d){d==="visible"&&e.connection.current.state==="open"&&Ae()}function v(d){if(d.targetActor!==void 0){const A=e.others.getUser(d.actor);e.others.setOther(d.actor,d.data);const D=e.others.getUser(d.actor);if(A===void 0&&D!==void 0)return{type:"enter",user:D}}else e.others.patchOther(d.actor,d.data);const P=e.others.getUser(d.actor);if(P)return{type:"update",updates:d.data,user:P}}function S(d){const P=e.others.getUser(d.actor);return P?(e.others.removeConnection(d.actor),{type:"leave",user:P}):null}function C(d){for(const P in d.users){const A=d.users[P],D=Number(P);e.others.setConnection(D,A.id,A.info,J(A.scopes))}return{type:"reset"}}function H(){e.connection.current.state==="unavailable"&&pn()}function U(d){d(()=>{o.history.notify({canUndo:gn(),canRedo:vn()})})}function F(d){e.others.setConnection(d.actor,d.id,d.info,J(d.scopes)),e.buffer.messages.push({type:100,data:e.me.current,targetActor:d.actor}),$e();const P=e.others.getUser(d.actor);return P?{type:"enter",user:P}:void 0}function Y(d){return yr(d)?d:null}function ne(d){const P=un(d);return P===void 0?null:fn(P)?Xt(P.map(A=>Y(A))):Xt([Y(P)])}function de(d){if(d.data==="pong"){clearTimeout(e.timeoutHandles.pongTimeout);return}const P=ne(d.data);if(P===null||P.length===0)return;const A={storageUpdates:new Map,others:[]};s(()=>{for(const D of P)switch(D.type){case 101:{const K=F(D);K&&A.others.push(K);break}case 100:{const K=v(D);K&&A.others.push(K);break}case 103:{o.customEvent.notify({connectionId:D.actor,event:D.event});break}case 102:{const K=S(D);K&&A.others.push(K);break}case 104:{A.others.push(C(D));break}case 200:{const K=new Map(e.offlineOperations);p(D,i),Tr(K,i),Dt==null||Dt(),o.storageDidLoad.notify();break}case 201:{_(D.ops,!1).updates.storageUpdates.forEach((_e,he)=>{A.storageUpdates.set(he,jt(A.storageUpdates.get(he),_e))});break}}b(A,i)})}function we(d){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(b({others:[{type:"reset"}]},i),d.code>=4e3&&d.code<=4100){le({state:"failed"},i);const P=new Hi(d.reason,d.code);o.error.notify(P);const A=Oe(!0);e.numberOfRetry++,le({state:"unavailable"},i),e.timeoutHandles.reconnect=l.scheduleReconnect(A)}else if(d.code===4999)le({state:"closed"},i);else{const P=Oe();e.numberOfRetry++,le({state:"unavailable"},i),e.timeoutHandles.reconnect=l.scheduleReconnect(P)}})}function le(d,P){e.connection.set(d),P(()=>{o.connection.notify(d.state)})}function Oe(d=!1){return d?zt[e.numberOfRetry0&&d.forEach(D=>{e.offlineOperations.set(q(D.opId),D)}),e.socket===null||e.socket.readyState!==e.socket.OPEN){e.buffer.storageOperations=[];return}const P=Date.now();if(P-e.lastFlushTime>t.throttleDelay){const D=Mr(e);if(D.length===0)return;l.send(D),e.buffer={messages:[],storageOperations:[],me:null},e.lastFlushTime=P}else e.timeoutHandles.flush!==null&&clearTimeout(e.timeoutHandles.flush),e.timeoutHandles.flush=l.delayFlush(t.throttleDelay-(P-e.lastFlushTime))}function Mr(d){const P=[];d.buffer.me&&P.push(d.buffer.me.type==="full"?{type:100,targetActor:-1,data:d.buffer.me.data}:{type:100,data:d.buffer.me.data});for(const A of d.buffer.messages)P.push(A);return d.buffer.storageOperations.length>0&&P.push({type:201,ops:d.buffer.storageOperations}),P}function $r(){e.socket&&(e.socket.removeEventListener("open",Le),e.socket.removeEventListener("message",de),e.socket.removeEventListener("close",we),e.socket.removeEventListener("error",Se),e.socket.close(),e.socket=null),s(()=>{le({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(),b({others:[{type:"reset"}]},i),Object.values(o).forEach(d=>d.clear())})}function Rr(){return e.me.current}function Dr(){return e.others.current}function Nr(d,P={shouldQueueEventIfNotReady:!1}){e.socket===null&&!P.shouldQueueEventIfNotReady||(e.buffer.messages.push({type:103,event:d}),$e())}function mn(d){e.buffer.storageOperations.push(...d),$e()}let Rt=null,Dt=null;function _n(){return Rt===null&&(e.buffer.messages.push({type:200}),$e(),Rt=new Promise(d=>Dt=d)),Rt}function Ur(){const d=e.root;return d!==void 0?d:(_n(),null)}function xr(){return on(this,null,function*(){return e.root?Promise.resolve({root:e.root}):(yield _n(),{root:q(e.root)})})}function Hr(){if(e.activeBatch)throw new Error("undo is not allowed during a batch");const d=e.undoStack.pop();if(d===void 0)return;e.pausedHistory=null;const P=_(d,!0);s(()=>{b(P.updates,i),e.redoStack.push(P.reverse),U(i)});for(const A of d)A.type!=="presence"&&e.buffer.storageOperations.push(A);$e()}function gn(){return e.undoStack.length>0}function jr(){if(e.activeBatch)throw new Error("redo is not allowed during a batch");const d=e.redoStack.pop();if(d===void 0)return;e.pausedHistory=null;const P=_(d,!0);s(()=>{b(P.updates,i),e.undoStack.push(P.reverse),U(i)});for(const A of d)A.type!=="presence"&&e.buffer.storageOperations.push(A);$e()}function vn(){return e.redoStack.length>0}function Vr(d){if(e.activeBatch)return d();let P;return s(()=>{e.activeBatch={ops:[],updates:{storageUpdates:new Map,presence:!1,others:[]},reverseOps:[]};try{P=d()}finally{const A=e.activeBatch;e.activeBatch=null,A.reverseOps.length>0&&L(A.reverseOps,i),A.ops.length>0&&(e.redoStack=[]),A.ops.length>0&&mn(A.ops),b(A.updates,i),$e()}}),P}function zr(){e.pausedHistory=[]}function Br(){const d=e.pausedHistory;e.pausedHistory=null,d!==null&&d.length>0&&M(d,s)}function Kr(){e.socket&&(e.socket=null)}function Fr(d){we(d)}return{onClose:we,onMessage:de,authenticationSuccess:te,heartbeat:Ae,onNavigatorOnline:H,simulateSocketClose:Kr,simulateSendCloseEvent:Fr,onVisibilityChange:W,getUndoStack:()=>e.undoStack,getItemsCount:()=>e.nodes.size,connect:B,disconnect:$r,subscribe:I,updatePresence:x,broadcastEvent:Nr,batch:Vr,undo:Hr,redo:jr,canUndo:gn,canRedo:vn,pauseHistory:zr,resumeHistory:Br,getStorage:xr,getStorageSnapshot:Ur,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:T,isSelfAware:()=>_t(e.connection.current),getSelf:()=>u.current,getPresence:Rr,getOthers:Dr}}function Ui(e,t){const n=new Ai,r=new Ti({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 Pi(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 xi(e,t){const{initialPresence:n,initialStorage:r}=e,i=Ui(typeof n=="function"?n(t.roomId):n,typeof r=="function"?r(t.roomId):r),s=Ni(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 Hi=class extends Error{constructor(e,t){super(e),this.code=t}};function ji(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.5`)}function Vi(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=>On(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=>On(t||fetch,e.url,{room:n})}if(e.type==="custom")return n=>on(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 On(e,t,n){return on(this,null,function*(){const r=yield e(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!r.ok)throw new Bt(`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 Bt(`Expected a JSON response when doing a POST request on "${t}". ${a}`)}if(!Ze(i)||typeof i.token!="string")throw new Bt(`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 Bt=class extends Error{constructor(e){super(e)}};function zi(e){const t=e,n=Bi(e),r=new Map;function i(o){const l=r.get(o);return l?l.room:null}function s(o,l){var u,p;const y=l.shouldInitiallyConnect===void 0?!0:l.shouldInitiallyConnect;let g=r.get(o);if(g)return g.room;if(l.initialPresence===null||l.initialPresence,g=xi({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:Ki(t,o)}),r.set(o,g),y){if(typeof atob>"u"){if(((p=t.polyfills)==null?void 0:p.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");ti.atob=t.polyfills.atob}g.connect()}return g.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 Bi(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 Ki(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_. For more information: https://liveblocks.io/docs/api-reference/liveblocks-client#createClientPublicKey");return{type:"public",publicApiKey:n,url:Fi(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 Fi(e,t){return e.publicAuthorizeEndpoint?e.publicAuthorizeEndpoint.replace("{roomId}",t):`https://api.liveblocks.io/v2/rooms/${encodeURIComponent(t)}/public/authorize`}function br(e){const t={};for(const n in e){const r=e[n];r!==void 0&&(t[n]=Re(r))}return t}function Ji(e){return br(e.toObject())}function Zi(e){const t={};for(const[n,r]of e.entries())t[n]=Re(r);return t}function wr(e){return e.map(Re)}function Yi(e){return wr(e.toArray())}function Re(e){return e instanceof Ue?Ji(e):e instanceof Ve?Yi(e):e instanceof We?Zi(e):e instanceof Ye?e.data:Array.isArray(e)?wr(e):Ze(e)?br(e):e}function qe(e){if(Array.isArray(e))return new Ve(e.map(qe));if(Ze(e)){const t={};for(const n in e){const r=e[n];r!==void 0&&(t[n]=qe(r))}return new Ue(t)}else return e}function Wi(e,t,n){let r=0,i=t.length-1,s=n.length-1,a=t[0],o=n[0];e:{for(;a===o;){if(++r,r>i||r>s)break e;a=t[r],o=n[r]}for(a=t[i],o=n[s];a===o;){if(i--,s--,r>i||r>s)break e;a=t[i],o=n[s]}}if(r>i){if(r<=s)for(;r<=s;)e.insert(qe(n[r]),r),r++}else if(r>s){let l=r;for(;l<=i;)e.delete(r),l++}else{for(;r<=i&&r<=s;){a=t[r],o=n[r];const u=e.get(r);ln(u)&&Ze(a)&&Ze(o)?kr(u,a,o):e.set(r,qe(o)),r++}for(;r<=s;)e.insert(qe(n[r]),r),r++;let l=r;for(;l<=i;)e.delete(r),l++}}function Er(e,t,n,r){const i=e.get(t);if(r===void 0)e.delete(t);else if(i===void 0)e.set(t,qe(r));else{if(n===r)return;At(i)&&Array.isArray(n)&&Array.isArray(r)?Wi(i,n,r):ln(i)&&Ze(n)&&Ze(r)?kr(i,n,r):e.set(t,qe(r))}}function kr(e,t,n){const r={};for(const i in n)Er(e,i,t[i],n[i]);for(const i in t)n[i]===void 0&&e.delete(i);Object.keys(r).length>0&&e.update(r)}function Xi(e){const t=[];for(;e.parent.type==="HasParent";)At(e.parent.node)?t.push(e.parent.node._indexOfPosition(e.parent.key)):t.push(e.parent.key),e=e.parent.node;return t}function Gi(e,t){return t.reduce((n,r)=>qi(n,r),e)}function qi(e,t){const n=Xi(t.node);return Gt(e,n,t)}function Gt(e,t,n){var r,i,s,a;const o=t.pop();if(o===void 0)switch(n.type){case"LiveObject":{if(e===null||typeof e!="object"||Array.isArray(e))throw new Error("Internal: received update on LiveObject but state was not an object");const l=Object.assign({},e);for(const u in n.updates)if(((r=n.updates[u])==null?void 0:r.type)==="update"){const p=n.node.get(u);p!==void 0&&(l[u]=Re(p))}else((i=n.updates[u])==null?void 0:i.type)==="delete"&&delete l[u];return l}case"LiveList":{if(!Array.isArray(e))throw new Error("Internal: received update on LiveList but state was not an array");let l=e.map(u=>u);for(const u of n.updates)u.type==="set"?l=l.map((p,y)=>y===u.index?Re(u.item):p):u.type==="insert"?u.index===l.length?l.push(Re(u.item)):l=[...l.slice(0,u.index),Re(u.item),...l.slice(u.index)]:u.type==="delete"?l.splice(u.index,1):u.type==="move"&&(u.previousIndex>u.index?l=[...l.slice(0,u.index),Re(u.item),...l.slice(u.index,u.previousIndex),...l.slice(u.previousIndex+1)]:l=[...l.slice(0,u.previousIndex),...l.slice(u.previousIndex+1,u.index+1),Re(u.item),...l.slice(u.index+1)]);return l}case"LiveMap":{if(e===null||typeof e!="object"||Array.isArray(e))throw new Error("Internal: received update on LiveMap but state was not an object");const l=Object.assign({},e);for(const u in n.updates)if(((s=n.updates[u])==null?void 0:s.type)==="update"){const p=n.node.get(u);p!==void 0&&(l[u]=Re(p))}else((a=n.updates[u])==null?void 0:a.type)==="delete"&&delete l[u];return l}}if(Array.isArray(e)){const l=[...e];return l[o]=Gt(e[o],t,n),l}else if(e!==null&&typeof e=="object"){const l=e[o];return l===void 0?e:ot(Je({},e),{[o]:Gt(l,t,n)})}else return e}function Qi(e,t){if(e.length!==t.length)return!1;for(let n=0;nObject.prototype.hasOwnProperty.call(t,r)&&Object.is(e[r],t[r]))}function ts(e,t){if(Object.is(e,t))return!0;const n=Array.isArray(e),r=Array.isArray(t);return n||r?!n||!r?!1:Qi(e,t):es(e,t)}N.ClientMsgCode=er;N.CrdtType=nr;N.LiveList=Ve;N.LiveMap=We;N.LiveObject=Ue;N.OpCode=tr;N.ServerMsgCode=sr;N.WebsocketCloseCodes=or;N.asArrayWithLegacyMethods=gr;N.assertNever=Ke;N.b64decode=hr;N.comparePosition=lr;N.createClient=zi;N.deprecate=Ii;N.deprecateIf=Oi;N.errorIf=Ci;N.freeze=De;N.isAppOnlyAuthToken=mr;N.isAuthToken=Ei;N.isChildCrdt=ir;N.isJsonArray=fn;N.isJsonObject=yr;N.isJsonScalar=vr;N.isPlainObject=Ze;N.isRoomAuthToken=cn;N.isRootCrdt=rr;N.legacy_patchImmutableObject=Gi;N.lsonToJson=Re;N.makePosition=He;N.nn=q;N.patchLiveObjectKey=Er;N.shallow=ts;N.throwUsageError=Li;N.tryParseJson=un;const ns=N.ClientMsgCode,rs=N.CrdtType,is=N.LiveList,ss=N.LiveMap,os=N.LiveObject,as=N.OpCode,ls=N.ServerMsgCode,us=N.WebsocketCloseCodes,cs=N.asArrayWithLegacyMethods,fs=N.assertNever,ds=N.b64decode,hs=N.comparePosition,ps=N.createClient,ms=N.deprecate,_s=N.deprecateIf,gs=N.errorIf,vs=N.freeze,ys=N.isAppOnlyAuthToken,bs=N.isAuthToken,ws=N.isChildCrdt,Es=N.isJsonArray,ks=N.isJsonObject,Is=N.isJsonScalar,Os=N.isPlainObject,Ls=N.isRoomAuthToken,Cs=N.isRootCrdt,Ps=N.legacy_patchImmutableObject,Ss=N.lsonToJson,As=N.makePosition,Ts=N.nn,Ms=N.patchLiveObjectKey,$s=N.shallow,Rs=N.throwUsageError,Ds=N.tryParseJson,Ns=Object.freeze(Object.defineProperty({__proto__:null,default:N,ClientMsgCode:ns,CrdtType:rs,LiveList:is,LiveMap:ss,LiveObject:os,OpCode:as,ServerMsgCode:ls,WebsocketCloseCodes:us,asArrayWithLegacyMethods:cs,assertNever:fs,b64decode:ds,comparePosition:hs,createClient:ps,deprecate:ms,deprecateIf:_s,errorIf:gs,freeze:vs,isAppOnlyAuthToken:ys,isAuthToken:bs,isChildCrdt:ws,isJsonArray:Es,isJsonObject:ks,isJsonScalar:Is,isPlainObject:Os,isRoomAuthToken:Ls,isRootCrdt:Cs,legacy_patchImmutableObject:Ps,lsonToJson:Ss,makePosition:As,nn:Ts,patchLiveObjectKey:Ms,shallow:$s,throwUsageError:Rs,tryParseJson:Ds},Symbol.toStringTag,{value:"Module"})),Us=ni(Ns);Object.defineProperty(Ne,"__esModule",{value:!0});var dt=Us;Ne.LiveList=dt.LiveList;Ne.LiveMap=dt.LiveMap;Ne.LiveObject=dt.LiveObject;Ne.createClient=dt.createClient;Ne.shallow=dt.shallow;Ne.LiveList;Ne.LiveMap;const xs=Ne.LiveObject,Hs=Ne.createClient;Ne.shallow;const Ir=Symbol(),Or=Symbol();function js(e){let t;const n=e[2].default,r=Qt(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)&&en(r,n,i,i[1],t?nn(n,i[1],s,null):tn(i[1]),null)},i(i){t||(R(r,i),t=!0)},o(i){z(r,i),t=!1},d(i){r&&r.d(i)}}}function Vs(e,t,n){let{$$slots:r={},$$scope:i}=t,{client:s}=t;if(!s)throw new Error("LiveblocksProvider requires a client");return Wn(Ir,s),e.$$set=a=>{"client"in a&&n(0,s=a.client),"$$scope"in a&&n(1,i=a.$$scope)},[s,i,r]}class zs extends ge{constructor(t){super(),ve(this,t,Vs,js,ye,{client:0})}}function Bs(e){let t;const n=e[3].default,r=Qt(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)&&en(r,n,i,i[2],t?nn(n,i[2],s,null):tn(i[2]),null)},i(i){t||(R(r,i),t=!0)},o(i){z(r,i),t=!1},d(i){r&&r.d(i)}}}function Ks(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=Xn(Ir);if(o){const l=o.enter(s,a());Wn(Or,l),Lt(()=>{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 Fs extends ge{constructor(t){super(),ve(this,t,Ks,Bs,ye,{id:0,defaultPresence:1})}}function Js(e){let t,n;return{c(){t=X("svg"),n=X("path"),this.h()},l(r){t=G(r,"svg",{class:!0,width:!0,viewBox:!0,fill:!0,xmlns:!0});var i=O(t);n=G(i,"path",{d:!0,fill:!0}),O(n).forEach(h),i.forEach(h),this.h()},h(){c(n,"d","M0.91603 0.916054L7.09131 14.9234L8.89871 8.89873L14.9234 7.09133L0.91603 0.916054Z"),c(n,"fill","#FFB800"),c(t,"class",e[0]),c(t,"width","40"),c(t,"viewBox","0 0 15 15"),c(t,"fill","currentColor"),c(t,"xmlns","http://www.w3.org/2000/svg")},m(r,i){Z(r,t,i),w(t,n)},p(r,[i]){i&1&&c(t,"class",r[0])},i:fe,o:fe,d(r){r&&h(t)}}}function Zs(e,t,n){let{classList:r=""}=t;return e.$$set=i=>{"classList"in i&&n(0,r=i.classList)},[r]}class Ys extends ge{constructor(t){super(),ve(this,t,Zs,Js,ye,{classList:0})}}function Ln(e){let t,n,r;return{c(){t=j("div"),n=ue(e[2]),this.h()},l(i){t=V(i,"DIV",{class:!0,style:!0});var s=O(t);n=ce(s,e[2]),s.forEach(h),this.h()},h(){c(t,"class","absolute right-0 text-4xl col-start-2 row-start-2"),c(t,"style",r=`text-shadow: 0px 5px 5px ${e[1]}`)},m(i,s){Z(i,t,s),w(t,n)},p(i,s){s&4&&Fe(n,i[2]),s&2&&r!==(r=`text-shadow: 0px 5px 5px ${i[1]}`)&&c(t,"style",r)},d(i){i&&h(t)}}}function Ws(e){let t,n,r,i,s;n=new Ys({props:{classList:"block z-0 col-span-2 row-span-2"}});let a=e[2]&&Ln(e);return{c(){t=j("div"),ie(n.$$.fragment),r=Q(),a&&a.c(),this.h()},l(o){t=V(o,"DIV",{class:!0,style:!0});var l=O(t);se(n.$$.fragment,l),r=ee(l),a&&a.l(l),l.forEach(h),this.h()},h(){c(t,"class","cursor svelte-14ka0w3"),c(t,"style",i=`transform: translateX(${e[3].x}px) translateY(${e[3].y}px) scale(${e[0].k});`)},m(o,l){Z(o,t,l),oe(n,t,null),w(t,r),a&&a.m(t,null),s=!0},p(o,[l]){o[2]?a?a.p(o,l):(a=Ln(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});`))&&c(t,"style",i)},i(o){s||(R(n.$$.fragment,o),s=!0)},o(o){z(n.$$.fragment,o),s=!1},d(o){o&&h(t),ae(n),a&&a.d()}}}function Xs(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 Gs extends ge{constructor(t){super(),ve(this,t,Xs,Ws,ye,{transform:0,color:1,emoji:2,position:4})}}function qs(e){let t,n,r;return{c(){t=X("svg"),n=X("path"),r=X("path"),this.h()},l(i){t=G(i,"svg",{class:!0,width:!0,height:!0,viewBox:!0,fill:!0,xmlns:!0});var s=O(t);n=G(s,"path",{d:!0,fill:!0}),O(n).forEach(h),r=G(s,"path",{d:!0,fill:!0}),O(r).forEach(h),s.forEach(h),this.h()},h(){c(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"),c(n,"fill","white"),c(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"),c(r,"fill","currentColor"),c(t,"class","animate-spin"),c(t,"width","51"),c(t,"height","51"),c(t,"viewBox","0 0 21 21"),c(t,"fill","none"),c(t,"xmlns","http://www.w3.org/2000/svg")},m(i,s){Z(i,t,s),w(t,n),w(t,r)},p:fe,i:fe,o:fe,d(i){i&&h(t)}}}class Lr extends ge{constructor(t){super(),ve(this,t,null,qs,ye,{})}}function Cn(e){let t,n,r;return n=new Lr({}),{c(){t=j("div"),ie(n.$$.fragment),this.h()},l(i){t=V(i,"DIV",{class:!0});var s=O(t);se(n.$$.fragment,s),s.forEach(h),this.h()},h(){c(t,"class","absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2")},m(i,s){Z(i,t,s),oe(n,t,null),r=!0},i(i){r||(R(n.$$.fragment,i),r=!0)},o(i){z(n.$$.fragment,i),r=!1},d(i){i&&h(t),ae(n)}}}function Qs(e){let t,n,r,i,s,a,o,l=e[2]&&Cn();return{c(){t=j("div"),n=j("div"),r=j("div"),i=ue(e[1]),s=Q(),l&&l.c(),this.h()},l(u){t=V(u,"DIV",{class:!0,style:!0});var p=O(t);n=V(p,"DIV",{class:!0});var y=O(n);r=V(y,"DIV",{class:!0});var g=O(r);i=ce(g,e[1]),g.forEach(h),y.forEach(h),s=ee(p),l&&l.l(p),p.forEach(h),this.h()},h(){c(r,"class","font-bold text-xl text-[#EC8E65] text-center px-2 line-clamp-4"),c(n,"class","pointer-events-none touch-none"),c(t,"class","frame @apply absolute top-0 left-0 ring-8 ring-[#EC8E65] w-[512px] h-[512px]"),c(t,"style",a=`transform: translateX(${e[3].x}px) translateY(${e[3].y}px) scale(${e[0].k}); transform-origin: 0 0;`)},m(u,p){Z(u,t,p),w(t,n),w(n,r),w(r,i),w(t,s),l&&l.m(t,null),o=!0},p(u,[p]){(!o||p&2)&&Fe(i,u[1]),u[2]?l?p&4&&R(l,1):(l=Cn(),l.c(),R(l,1),l.m(t,null)):l&&(ke(),z(l,1,1,()=>{l=null}),Ie()),(!o||p&9&&a!==(a=`transform: translateX(${u[3].x}px) translateY(${u[3].y}px) scale(${u[0].k}); transform-origin: 0 0;`))&&c(t,"style",a)},i(u){o||(R(l),o=!0)},o(u){z(l),o=!1},d(u){u&&h(t),l&&l.d()}}}function eo(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 to extends ge{constructor(t){super(),ve(this,t,eo,Qs,ye,{transform:0,position:4,prompt:1,isLoading:2})}}function no(e){let t,n,r,i,s;return{c(){t=j("span"),n=ue("+"),r=Q(),i=j("span"),s=ue("Prompt + Paint"),this.h()},l(a){t=V(a,"SPAN",{class:!0});var o=O(t);n=ce(o,"+"),o.forEach(h),r=ee(a),i=V(a,"SPAN",{});var l=O(i);s=ce(l,"Prompt + Paint"),l.forEach(h),this.h()},h(){c(t,"class","rounded-sm h-4 w-4 flex justify-center items-center border-2 border-dashed border-violet-700 mr-2")},m(a,o){Z(a,t,o),w(t,n),Z(a,r,o),Z(a,i,o),w(i,s)},d(a){a&&h(t),a&&h(r),a&&h(i)}}}function ro(e){let t,n;return{c(){t=j("span"),n=ue("paiting...")},l(r){t=V(r,"SPAN",{});var i=O(t);n=ce(i,"paiting..."),i.forEach(h)},m(r,i){Z(r,t,i),w(t,n)},d(r){r&&h(t)}}}function io(e){let t,n,r,i;function s(l,u){return l[0]?ro:no}let a=s(e),o=a(e);return{c(){t=j("button"),o.c(),this.h()},l(l){t=V(l,"BUTTON",{class:!0,title:!0});var u=O(t);o.l(u),u.forEach(h),this.h()},h(){t.disabled=e[0],c(t,"class",n="button-paint "+(e[0]?"cursor-wait":"cursor-pointer")+" svelte-1r9tbxz"),c(t,"title","Prompt and Paint")},m(l,u){Z(l,t,u),o.m(t,null),r||(i=je(t,"click",e[1]),r=!0)},p(l,[u]){a!==(a=s(l))&&(o.d(1),o=a(l),o&&(o.c(),o.m(t,null))),u&1&&(t.disabled=l[0]),u&1&&n!==(n="button-paint "+(l[0]?"cursor-wait":"cursor-pointer")+" svelte-1r9tbxz")&&c(t,"class",n)},i:fe,o:fe,d(l){l&&h(t),o.d(),r=!1,i()}}}function so(e,t,n){let{isLoading:r=!1}=t;function i(s){ft.call(this,e,s)}return e.$$set=s=>{"isLoading"in s&&n(0,r=s.isLoading)},[r,i]}class Cr extends ge{constructor(t){super(),ve(this,t,so,io,ye,{isLoading:0})}}function oo(e){let t,n;return{c(){t=X("svg"),n=X("path"),this.h()},l(r){t=G(r,"svg",{class:!0,width:!0,height:!0,viewBox:!0,fill:!0,xmlns:!0});var i=O(t);n=G(i,"path",{d:!0,stroke:!0,"stroke-width":!0,"stroke-linecap":!0,"stroke-linejoin":!0}),O(n).forEach(h),i.forEach(h),this.h()},h(){c(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"),c(n,"stroke","currentColor"),c(n,"stroke-width","0.933333"),c(n,"stroke-linecap","round"),c(n,"stroke-linejoin","round"),c(t,"class",e[0]),c(t,"width","40"),c(t,"height","40"),c(t,"viewBox","0 0 11 11"),c(t,"fill","none"),c(t,"xmlns","http://www.w3.org/2000/svg")},m(r,i){Z(r,t,i),w(t,n)},p(r,[i]){i&1&&c(t,"class",r[0])},i:fe,o:fe,d(r){r&&h(t)}}}function ao(e,t,n){let{classList:r=""}=t;return e.$$set=i=>{"classList"in i&&n(0,r=i.classList)},[r]}class lo extends ge{constructor(t){super(),ve(this,t,ao,oo,ye,{classList:0})}}function uo(e){let t,n,r,i,s,a;return n=new lo({}),{c(){t=j("button"),ie(n.$$.fragment),this.h()},l(o){t=V(o,"BUTTON",{class:!0,title:!0});var l=O(t);se(n.$$.fragment,l),l.forEach(h),this.h()},h(){t.disabled=e[1],c(t,"class",r=e[2]+" shadow-lg bg-white rounded-full disabled:opacity-50 "+(e[0]?"text-blue-700":"text-gray-800")),c(t,"title","Drag to Move")},m(o,l){Z(o,t,l),oe(n,t,null),i=!0,s||(a=je(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")))&&c(t,"class",r)},i(o){i||(R(n.$$.fragment,o),i=!0)},o(o){z(n.$$.fragment,o),i=!1},d(o){o&&h(t),ae(n),s=!1,a()}}}function co(e,t,n){let{isActive:r=!1}=t,{isLoading:i=!1}=t,{className:s=""}=t;function a(o){ft.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 fo extends ge{constructor(t){super(),ve(this,t,co,uo,ye,{isActive:0,isLoading:1,className:2})}}function ho(e){let t,n;return{c(){t=X("svg"),n=X("path"),this.h()},l(r){t=G(r,"svg",{class:!0,width:!0,height:!0,viewBox:!0,fill:!0,xmlns:!0});var i=O(t);n=G(i,"path",{d:!0,fill:!0}),O(n).forEach(h),i.forEach(h),this.h()},h(){c(n,"d","M3.07066 9.3043L8.07078 4.30418L5.69582 1.92922L0.695701 6.92934C0.626865 6.99826 0.577967 7.08453 0.554193 7.17899L0 10L2.82047 9.44581C2.91516 9.42213 3.00179 9.37317 3.07066 9.3043V9.3043ZM9.68493 2.69003C9.88667 2.48823 10 2.21457 10 1.92922C10 1.64388 9.88667 1.37022 9.68493 1.16842L8.83158 0.315069C8.62978 0.11333 8.35612 0 8.07078 0C7.78543 0 7.51177 0.11333 7.30997 0.315069L6.45662 1.16842L8.83158 3.54338L9.68493 2.69003Z"),c(n,"fill","currentColor"),c(t,"class",e[0]),c(t,"width","40"),c(t,"height","40"),c(t,"viewBox","-2 -2 14 14"),c(t,"fill","none"),c(t,"xmlns","http://www.w3.org/2000/svg")},m(r,i){Z(r,t,i),w(t,n)},p(r,[i]){i&1&&c(t,"class",r[0])},i:fe,o:fe,d(r){r&&h(t)}}}function po(e,t,n){let{classList:r=""}=t;return e.$$set=i=>{"classList"in i&&n(0,r=i.classList)},[r]}class mo extends ge{constructor(t){super(),ve(this,t,po,ho,ye,{classList:0})}}function _o(e){let t,n,r,i,s,a;return n=new mo({}),{c(){t=j("button"),ie(n.$$.fragment),this.h()},l(o){t=V(o,"BUTTON",{class:!0,title:!0});var l=O(t);se(n.$$.fragment,l),l.forEach(h),this.h()},h(){t.disabled=e[1],c(t,"class",r=e[2]+" rounded-full disabled:opacity-50 "+(e[0]?"text-blue-700":"text-gray-800")),c(t,"title","Draw to Mask")},m(o,l){Z(o,t,l),oe(n,t,null),i=!0,s||(a=je(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")))&&c(t,"class",r)},i(o){i||(R(n.$$.fragment,o),i=!0)},o(o){z(n.$$.fragment,o),i=!1},d(o){o&&h(t),ae(n),s=!1,a()}}}function go(e,t,n){let{isActive:r=!1}=t,{isLoading:i=!1}=t,{className:s=""}=t;function a(o){ft.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 vo extends ge{constructor(t){super(),ve(this,t,go,_o,ye,{isActive:0,isLoading:1,className:2})}}function yo(e){let t,n,r;return{c(){t=X("svg"),n=X("g"),r=X("path"),this.h()},l(i){t=G(i,"svg",{class:!0,width:!0,height:!0,viewBox:!0,fill:!0,xmlns:!0});var s=O(t);n=G(s,"g",{opacity:!0});var a=O(n);r=G(a,"path",{d:!0,fill:!0,stroke:!0,"stroke-width":!0,"stroke-linejoin":!0}),O(r).forEach(h),a.forEach(h),s.forEach(h),this.h()},h(){c(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"),c(r,"fill","black"),c(r,"stroke","black"),c(r,"stroke-width","0.5"),c(r,"stroke-linejoin","round"),c(n,"opacity","0.5"),c(t,"class",e[0]),c(t,"width","40"),c(t,"height","29"),c(t,"viewBox","0 0 10 9"),c(t,"fill","none"),c(t,"xmlns","http://www.w3.org/2000/svg")},m(i,s){Z(i,t,s),w(t,n),w(n,r)},p(i,[s]){s&1&&c(t,"class",i[0])},i:fe,o:fe,d(i){i&&h(t)}}}function bo(e,t,n){let{classList:r=""}=t;return e.$$set=i=>{"classList"in i&&n(0,r=i.classList)},[r]}class wo extends ge{constructor(t){super(),ve(this,t,bo,yo,ye,{classList:0})}}function Eo(e){let t,n,r,i,s,a;return n=new wo({}),{c(){t=j("button"),ie(n.$$.fragment),this.h()},l(o){t=V(o,"BUTTON",{class:!0,title:!0});var l=O(t);se(n.$$.fragment,l),l.forEach(h),this.h()},h(){t.disabled=e[1],c(t,"class",r=e[2]+" bg-white rounded-full disabled:opacity-50 bg-white rounded-full "+(e[0]?"text-blue-700":"text-gray-800")),c(t,"title","Clear Masking")},m(o,l){Z(o,t,l),oe(n,t,null),i=!0,s||(a=je(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")))&&c(t,"class",r)},i(o){i||(R(n.$$.fragment,o),i=!0)},o(o){z(n.$$.fragment,o),i=!1},d(o){o&&h(t),ae(n),s=!1,a()}}}function ko(e,t,n){let{isActive:r=!1}=t,{isLoading:i=!1}=t,{className:s=""}=t;function a(o){ft.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 Io extends ge{constructor(t){super(),ve(this,t,ko,Eo,ye,{isActive:0,isLoading:1,className:2})}}function Te(e){return typeof e=="string"?new yn([[document.querySelector(e)]],[document.documentElement]):new yn([[e]],Gr)}function Oo(e){let t;for(;t=e.sourceEvent;)e=t;return e}function Be(e,t){if(e=Oo(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 Lo={passive:!1},ct={capture:!0,passive:!1};function Kt(e){e.stopImmediatePropagation()}function rt(e){e.preventDefault(),e.stopImmediatePropagation()}function Pr(e){var t=e.document.documentElement,n=Te(e).on("dragstart.drag",rt,ct);"onselectstart"in t?n.on("selectstart.drag",rt,ct):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect="none")}function Sr(e,t){var n=e.document.documentElement,r=Te(e).on("dragstart.drag",null);t&&(r.on("click.drag",rt,ct),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 gt=e=>()=>e;function qt(e,{sourceEvent:t,subject:n,target:r,identifier:i,active:s,x:a,y:o,dx:l,dy:u,dispatch:p}){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:p}})}qt.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function Co(e){return!e.ctrlKey&&!e.button}function Po(){return this.parentNode}function So(e,t){return t==null?{x:e.x,y:e.y}:t}function Ao(){return navigator.maxTouchPoints||"ontouchstart"in this}function Pn(){var e=Co,t=Po,n=So,r=Ao,i={},s=Gn("start","drag","end"),a=0,o,l,u,p,y=0;function g(m){m.on("mousedown.drag",k).filter(r).on("touchstart.drag",b).on("touchmove.drag",f,Lo).on("touchend.drag touchcancel.drag",_).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function k(m,$){if(!(p||!e.call(this,m,$))){var I=E(this,t.call(this,m,$),m,$,"mouse");!I||(Te(m.view).on("mousemove.drag",M,ct).on("mouseup.drag",L,ct),Pr(m.view),Kt(m),u=!1,o=m.clientX,l=m.clientY,I("start",m))}}function M(m){if(rt(m),!u){var $=m.clientX-o,I=m.clientY-l;u=$*$+I*I>y}i.mouse("drag",m)}function L(m){Te(m.view).on("mousemove.drag mouseup.drag",null),Sr(m.view,u),rt(m),i.mouse("end",m)}function b(m,$){if(!!e.call(this,m,$)){var I=m.changedTouches,T=t.call(this,m,$),B=I.length,x,J;for(x=0;x{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 Mo(e,t,n){const r=Ro(t),s=`color-palette-${crypto.randomUUID().split("-")[0]}-${r}-${n}.jpeg`,a=new File([e],s,{type:"image/jpeg"}),o=new FormData;return o.append("file",a),(await(await fetch(sn+"/uploadfile",{method:"POST",body:o})).json()).filename}const $o=512*5-512;function vt(e,t=32){const n=e%t{n(s)});return Lt(()=>{i()}),{subscribe:t,update:r}}function Do(){const e=Mt(),t=Ct(),n=e.subscribe("others",r=>{t.set(r)});return Lt(n),t}function No(){const e=Mt(),t=Ct();async function n(){const{root:r}=await e.getStorage();t.set(r)}return n(),t}function Ar(e,t){const n=Mt(),r=No(),i=Ct();let s=()=>{};const a=r.subscribe(o=>{!o||(o.get(e)||o.set(e,new xs(t)),i.set(o.get(e)),s(),s=n.subscribe(o.get(e),l=>{i.set(l)}))});return Lt(a),i}var Uo=1e-12;function Sn(e){return((e=Math.exp(e))+1/e)/2}function xo(e){return((e=Math.exp(e))-1/e)/2}function Ho(e){return((e=Math.exp(2*e))-1)/(e+1)}const jo=function e(t,n,r){function i(s,a){var o=s[0],l=s[1],u=s[2],p=a[0],y=a[1],g=a[2],k=p-o,M=y-l,L=k*k+M*M,b,f;if(L()=>e;function Vo(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 Ft(e){e.stopImmediatePropagation()}function lt(e){e.preventDefault(),e.stopImmediatePropagation()}function zo(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function Bo(){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 An(){return this.__zoom||Et}function Ko(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function Fo(){return navigator.maxTouchPoints||"ontouchstart"in this}function Jo(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 Zo(){var e=zo,t=Bo,n=Jo,r=Ko,i=Fo,s=[0,1/0],a=[[-1/0,-1/0],[1/0,1/0]],o=250,l=jo,u=Gn("start","zoom","end"),p,y,g,k=500,M=150,L=0,b=10;function f(v){v.property("__zoom",An).on("wheel.zoom",B,{passive:!1}).on("mousedown.zoom",x).on("dblclick.zoom",J).filter(i).on("touchstart.zoom",te).on("touchmove.zoom",re).on("touchend.zoom touchcancel.zoom",W).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}f.transform=function(v,S,C,H){var U=v.selection?v.selection():v;U.property("__zoom",An),v!==U?$(v,S,C,H):U.interrupt().each(function(){I(this,arguments).event(H).start().zoom(null,typeof S=="function"?S.apply(this,arguments):S).end()})},f.scaleBy=function(v,S,C,H){f.scaleTo(v,function(){var U=this.__zoom.k,F=typeof S=="function"?S.apply(this,arguments):S;return U*F},C,H)},f.scaleTo=function(v,S,C,H){f.transform(v,function(){var U=t.apply(this,arguments),F=this.__zoom,Y=C==null?m(U):typeof C=="function"?C.apply(this,arguments):C,ne=F.invert(Y),de=typeof S=="function"?S.apply(this,arguments):S;return n(E(_(F,de),Y,ne),U,a)},C,H)},f.translateBy=function(v,S,C,H){f.transform(v,function(){return n(this.__zoom.translate(typeof S=="function"?S.apply(this,arguments):S,typeof C=="function"?C.apply(this,arguments):C),t.apply(this,arguments),a)},null,H)},f.translateTo=function(v,S,C,H,U){f.transform(v,function(){var F=t.apply(this,arguments),Y=this.__zoom,ne=H==null?m(F):typeof H=="function"?H.apply(this,arguments):H;return n(Et.translate(ne[0],ne[1]).scale(Y.k).translate(typeof S=="function"?-S.apply(this,arguments):-S,typeof C=="function"?-C.apply(this,arguments):-C),F,a)},H,U)};function _(v,S){return S=Math.max(s[0],Math.min(s[1],S)),S===v.k?v:new Ut(S,v.x,v.y)}function E(v,S,C){var H=S[0]-C[0]*v.k,U=S[1]-C[1]*v.k;return H===v.x&&U===v.y?v:new Ut(v.k,H,U)}function m(v){return[(+v[0][0]+ +v[1][0])/2,(+v[0][1]+ +v[1][1])/2]}function $(v,S,C,H){v.on("start.zoom",function(){I(this,arguments).event(H).start()}).on("interrupt.zoom end.zoom",function(){I(this,arguments).event(H).end()}).tween("zoom",function(){var U=this,F=arguments,Y=I(U,F).event(H),ne=t.apply(U,F),de=C==null?m(ne):typeof C=="function"?C.apply(U,F):C,we=Math.max(ne[1][0]-ne[0][0],ne[1][1]-ne[0][1]),le=U.__zoom,Oe=typeof S=="function"?S.apply(U,F):S,Se=l(le.invert(de).concat(we/le.k),Oe.invert(de).concat(we/Oe.k));return function(Le){if(Le===1)Le=Oe;else{var Ae=Se(Le),at=we/Ae[2];Le=new Ut(at,de[0]-Ae[0]*at,de[1]-Ae[1]*at)}Y.zoom(null,Le)}})}function I(v,S,C){return!C&&v.__zooming||new T(v,S)}function T(v,S){this.that=v,this.args=S,this.active=0,this.sourceEvent=null,this.extent=t.apply(v,S),this.taps=0}T.prototype={event:function(v){return v&&(this.sourceEvent=v),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(v,S){return this.mouse&&v!=="mouse"&&(this.mouse[1]=S.invert(this.mouse[0])),this.touch0&&v!=="touch"&&(this.touch0[1]=S.invert(this.touch0[0])),this.touch1&&v!=="touch"&&(this.touch1[1]=S.invert(this.touch1[0])),this.that.__zoom=S,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(v){var S=Te(this.that).datum();u.call(v,this.that,new Vo(v,{sourceEvent:this.sourceEvent,target:f,type:v,transform:this.that.__zoom,dispatch:u}),S)}};function B(v,...S){if(!e.apply(this,arguments))return;var C=I(this,S).event(v),H=this.__zoom,U=Math.max(s[0],Math.min(s[1],H.k*Math.pow(2,r.apply(this,arguments)))),F=Be(v);if(C.wheel)(C.mouse[0][0]!==F[0]||C.mouse[0][1]!==F[1])&&(C.mouse[1]=H.invert(C.mouse[0]=F)),clearTimeout(C.wheel);else{if(H.k===U)return;C.mouse=[F,H.invert(F)],xt(this),C.start()}lt(v),C.wheel=setTimeout(Y,M),C.zoom("mouse",n(E(_(H,U),C.mouse[0],C.mouse[1]),C.extent,a));function Y(){C.wheel=null,C.end()}}function x(v,...S){if(g||!e.apply(this,arguments))return;var C=v.currentTarget,H=I(this,S,!0).event(v),U=Te(v.view).on("mousemove.zoom",de,!0).on("mouseup.zoom",we,!0),F=Be(v,C),Y=v.clientX,ne=v.clientY;Pr(v.view),Ft(v),H.mouse=[F,this.__zoom.invert(F)],xt(this),H.start();function de(le){if(lt(le),!H.moved){var Oe=le.clientX-Y,Se=le.clientY-ne;H.moved=Oe*Oe+Se*Se>L}H.event(le).zoom("mouse",n(E(H.that.__zoom,H.mouse[0]=Be(le,C),H.mouse[1]),H.extent,a))}function we(le){U.on("mousemove.zoom mouseup.zoom",null),Sr(le.view,H.moved),lt(le),H.event(le).end()}}function J(v,...S){if(!!e.apply(this,arguments)){var C=this.__zoom,H=Be(v.changedTouches?v.changedTouches[0]:v,this),U=C.invert(H),F=C.k*(v.shiftKey?.5:2),Y=n(E(_(C,F),H,U),t.apply(this,S),a);lt(v),o>0?Te(this).transition().duration(o).call($,Y,H,v):Te(this).call(f.transform,Y,H,v)}}function te(v,...S){if(!!e.apply(this,arguments)){var C=v.touches,H=C.length,U=I(this,S,v.changedTouches.length===H).event(v),F,Y,ne,de;for(Ft(v),Y=0;Y(e.ready="ready",e.loading="loading",e.prompting="prompting",e.processing="processing",e.dragging="dragging",e.masking="masking",e))(me||{});function Tn(e){let t,n,r;return{c(){t=j("div"),n=j("div"),r=ue(e[6]),this.h()},l(i){t=V(i,"DIV",{class:!0});var s=O(t);n=V(s,"DIV",{class:!0});var a=O(n);r=ce(a,e[6]),a.forEach(h),s.forEach(h),this.h()},h(){c(n,"class","font-bold text-xl text-[#387CFF] text-center px-2 line-clamp-4"),c(t,"class","pointer-events-none touch-none")},m(i,s){Z(i,t,s),w(t,n),w(n,r)},p(i,s){s&64&&Fe(r,i[6])},d(i){i&&h(t)}}}function Mn(e){let t,n,r;return n=new Lr({}),{c(){t=j("div"),ie(n.$$.fragment),this.h()},l(i){t=V(i,"DIV",{class:!0});var s=O(t);se(n.$$.fragment,s),s.forEach(h),this.h()},h(){c(t,"class","absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2")},m(i,s){Z(i,t,s),oe(n,t,null),r=!0},i(i){r||(R(n.$$.fragment,i),r=!0)},o(i){z(n.$$.fragment,i),r=!1},d(i){i&&h(t),ae(n)}}}function $n(e){let t,n,r,i,s,a,o,l,u,p,y,g,k,M,L;r=new Cr({props:{isLoading:e[4]}}),r.$on("click",e[17]);let b=e[8]!==""&&Rn(e);u=new fo({props:{className:"p-1",isLoading:e[4],isActive:e[1]}}),u.$on("click",e[11]),g=new vo({props:{isLoading:e[4],className:"p-1",isActive:!e[1]}}),g.$on("click",e[12]);let f=!e[1]&&Nn(e);return{c(){t=j("div"),n=j("div"),ie(r.$$.fragment),i=Q(),b&&b.c(),a=Q(),o=j("div"),l=j("div"),ie(u.$$.fragment),p=Q(),y=j("div"),ie(g.$$.fragment),k=Q(),f&&f.c(),this.h()},l(_){t=V(_,"DIV",{class:!0,style:!0});var E=O(t);n=V(E,"DIV",{class:!0});var m=O(n);se(r.$$.fragment,m),m.forEach(h),i=ee(E),b&&b.l(E),E.forEach(h),a=ee(_),o=V(_,"DIV",{class:!0,style:!0});var $=O(o);l=V($,"DIV",{class:!0});var I=O(l);se(u.$$.fragment,I),p=ee(I),y=V(I,"DIV",{class:!0});var T=O(y);se(g.$$.fragment,T),k=ee(T),f&&f.l(T),T.forEach(h),I.forEach(h),$.forEach(h),this.h()},h(){c(n,"class","py-3"),c(t,"class","absolute top-full"),c(t,"style",s=`transform: scale(${Math.max(2-e[0].k,1)}); transform-origin: 0 0;`),c(y,"class","flex bg-white rounded-full mt-3 shadow-lg"),c(l,"class","mx-4"),c(o,"class","absolute left-full"),c(o,"style",M=`transform: scale(${Math.max(2-e[0].k,1)}); transform-origin: 0 0;`)},m(_,E){Z(_,t,E),w(t,n),oe(r,n,null),w(t,i),b&&b.m(t,null),Z(_,a,E),Z(_,o,E),w(o,l),oe(u,l,null),w(l,p),w(l,y),oe(g,y,null),w(y,k),f&&f.m(y,null),L=!0},p(_,E){const m={};E&16&&(m.isLoading=_[4]),r.$set(m),_[8]!==""?b?b.p(_,E):(b=Rn(_),b.c(),b.m(t,null)):b&&(b.d(1),b=null),(!L||E&1&&s!==(s=`transform: scale(${Math.max(2-_[0].k,1)}); transform-origin: 0 0;`))&&c(t,"style",s);const $={};E&16&&($.isLoading=_[4]),E&2&&($.isActive=_[1]),u.$set($);const I={};E&16&&(I.isLoading=_[4]),E&2&&(I.isActive=!_[1]),g.$set(I),_[1]?f&&(ke(),z(f,1,1,()=>{f=null}),Ie()):f?(f.p(_,E),E&2&&R(f,1)):(f=Nn(_),f.c(),R(f,1),f.m(y,null)),(!L||E&1&&M!==(M=`transform: scale(${Math.max(2-_[0].k,1)}); transform-origin: 0 0;`))&&c(o,"style",M)},i(_){L||(R(r.$$.fragment,_),R(u.$$.fragment,_),R(g.$$.fragment,_),R(f),L=!0)},o(_){z(r.$$.fragment,_),z(u.$$.fragment,_),z(g.$$.fragment,_),z(f),L=!1},d(_){_&&h(t),ae(r),b&&b.d(),_&&h(a),_&&h(o),ae(u),ae(g),f&&f.d()}}}function Rn(e){let t,n,r,i,s=e[8]==="NFSW"&&Dn();return{c(){t=j("div"),s&&s.c(),n=Q(),r=j("p"),i=ue(e[8]),this.h()},l(a){t=V(a,"DIV",{class:!0});var o=O(t);s&&s.l(o),n=ee(o),r=V(o,"P",{});var l=O(r);i=ce(l,e[8]),l.forEach(h),o.forEach(h),this.h()},h(){c(t,"class","p-3 bg-white rounded-lg font-mono")},m(a,o){Z(a,t,o),s&&s.m(t,null),w(t,n),w(t,r),w(r,i)},p(a,o){a[8]==="NFSW"?s||(s=Dn(),s.c(),s.m(t,n)):s&&(s.d(1),s=null),o&256&&Fe(i,a[8])},d(a){a&&h(t),s&&s.d()}}}function Dn(e){let t,n,r,i,s;return{c(){t=j("h2"),n=ue("NSFW Alert"),r=Q(),i=j("h3"),s=ue("Possible NSFW result detected, please try again"),this.h()},l(a){t=V(a,"H2",{class:!0});var o=O(t);n=ce(o,"NSFW Alert"),o.forEach(h),r=ee(a),i=V(a,"H3",{class:!0});var l=O(i);s=ce(l,"Possible NSFW result detected, please try again"),l.forEach(h),this.h()},h(){c(t,"class","text-red-500 text-2xl font-bold"),c(i,"class","text-red-500 text-lg")},m(a,o){Z(a,t,o),w(t,n),Z(a,r,o),Z(a,i,o),w(i,s)},d(a){a&&h(t),a&&h(r),a&&h(i)}}}function Nn(e){let t,n,r,i;return r=new Io({props:{className:"p-1",isLoading:e[4]}}),r.$on("click",e[13]),{c(){t=j("span"),n=Q(),ie(r.$$.fragment),this.h()},l(s){t=V(s,"SPAN",{class:!0}),O(t).forEach(h),n=ee(s),se(r.$$.fragment,s),this.h()},h(){c(t,"class","border-gray-800 border-opacity-50 border-r-2 my-2")},m(s,a){Z(s,t,a),Z(s,n,a),oe(r,s,a),i=!0},p(s,a){const o={};a&16&&(o.isLoading=s[4]),r.$set(o)},i(s){i||(R(r.$$.fragment,s),i=!0)},o(s){z(r.$$.fragment,s),i=!1},d(s){s&&h(t),s&&h(n),ae(r,s)}}}function Yo(e){let t,n,r,i,s,a,o,l,u,p,y,g,k,M,L,b=e[6]&&Tn(e),f=e[4]&&Mn(),_=!e[3]&&$n(e);return{c(){t=j("div"),n=j("div"),r=j("div"),i=j("canvas"),a=Q(),o=j("div"),b&&b.c(),l=Q(),f&&f.c(),u=Q(),_&&_.c(),y=Q(),g=j("div"),this.h()},l(E){t=V(E,"DIV",{});var m=O(t);n=V(m,"DIV",{class:!0,style:!0});var $=O(n);r=V($,"DIV",{class:!0});var I=O(r);i=V(I,"CANVAS",{class:!0,width:!0,height:!0}),O(i).forEach(h),a=ee(I),o=V(I,"DIV",{class:!0});var T=O(o);b&&b.l(T),T.forEach(h),l=ee(I),f&&f.l(I),u=ee(I),_&&_.l(I),I.forEach(h),$.forEach(h),y=ee(m),g=V(m,"DIV",{class:!0,style:!0}),O(g).forEach(h),m.forEach(h),this.h()},h(){c(i,"class",s=e[1]?"":"bg-white"),c(i,"width","512"),c(i,"height","512"),c(o,"class","pointer-events-none touch-none"),c(r,"class","frame svelte-xtgdq4"),c(n,"class","absolute top-0 left-0 pen svelte-xtgdq4"),c(n,"style",p=`transform: translateX(${e[5].x}px) translateY(${e[5].y}px) scale(${e[0].k}); transform-origin: 0 0;`),c(g,"class",k="absolute top-0 left-0 w-[512px] h-[512px] ring-8 hand "+(e[1]?"block":"hidden")+" svelte-xtgdq4"),c(g,"style",M=`transform: translateX(${e[5].x}px) translateY(${e[5].y}px) scale(${e[0].k}); transform-origin: 0 0;`)},m(E,m){Z(E,t,m),w(t,n),w(n,r),w(r,i),e[16](i),w(r,a),w(r,o),b&&b.m(o,null),w(r,l),f&&f.m(r,null),w(r,u),_&&_.m(r,null),w(t,y),w(t,g),e[18](g),L=!0},p(E,[m]){(!L||m&2&&s!==(s=E[1]?"":"bg-white"))&&c(i,"class",s),E[6]?b?b.p(E,m):(b=Tn(E),b.c(),b.m(o,null)):b&&(b.d(1),b=null),E[4]?f?m&16&&R(f,1):(f=Mn(),f.c(),R(f,1),f.m(r,u)):f&&(ke(),z(f,1,1,()=>{f=null}),Ie()),E[3]?_&&(ke(),z(_,1,1,()=>{_=null}),Ie()):_?(_.p(E,m),m&8&&R(_,1)):(_=$n(E),_.c(),R(_,1),_.m(r,null)),(!L||m&33&&p!==(p=`transform: translateX(${E[5].x}px) translateY(${E[5].y}px) scale(${E[0].k}); transform-origin: 0 0;`))&&c(n,"style",p),(!L||m&2&&k!==(k="absolute top-0 left-0 w-[512px] h-[512px] ring-8 hand "+(E[1]?"block":"hidden")+" svelte-xtgdq4"))&&c(g,"class",k),(!L||m&33&&M!==(M=`transform: translateX(${E[5].x}px) translateY(${E[5].y}px) scale(${E[0].k}); transform-origin: 0 0;`))&&c(g,"style",M)},i(E){L||(R(f),R(_),L=!0)},o(E){z(f),z(_),L=!1},d(E){E&&h(t),e[16](null),b&&b.d(),f&&f.d(),_&&_.d(),e[18](null)}}}function Wo(e,t,n){let r,i,s,a,o,l,u;Ee(e,Zt,S=>n(7,a=S)),Ee(e,bt,S=>n(22,o=S)),Ee(e,Pe,S=>n(8,u=S));const p=$t();Ee(e,p,S=>n(15,l=S));const y=rn();let{transform:g}=t,k,M={x:768,y:768},L,b=!0,f=!1,_=0,E=0;function m(S){k.save(),k.clearRect(0,0,512,512),k.globalCompositeOperation="source-over",k.drawImage(o,S.x,S.y,512,512,0,0,512,512),k.restore()}function $(S){k.save(),k.globalCompositeOperation="destination-out",k.beginPath(),k.moveTo(S.lastx,S.lasty),k.lineTo(S.x,S.y),k.lineWidth=50,k.lineCap="round",k.strokeStyle="black",k.stroke(),k.restore()}st(()=>{k=a.getContext("2d"),Te(L).call(B()).call(I),Te(a).call(T()).call(I)});function I(S){function C(U){p.update({cursor:{x:g.invertX(U.clientX),y:g.invertY(U.clientY)}})}function H(){p.update({cursor:null})}return S.on("pointermove",C).on("pointerleave",H)}function T(){let S,C;function H(F){if(i)return;const Y=F.x/g.k,ne=F.y/g.k;S=Y,C=ne}function U(F){if(i)return;const Y=F.x/g.k,ne=F.y/g.k;$({x:Y,y:ne,lastx:S,lasty:C}),S=Y,C=ne}return Pn().on("start",H).on("drag",U)}function B(){function S(U){if(i)return;const F=U.sourceEvent.target.getBoundingClientRect();typeof TouchEvent<"u"&&U.sourceEvent instanceof TouchEvent?(_=U.sourceEvent.targetTouches[0].pageX-F.left,E=U.sourceEvent.targetTouches[0].pageY-F.top):U.sourceEvent instanceof MouseEvent&&(_=U.sourceEvent.pageX-F.left,E=U.sourceEvent.pageY-F.top),n(3,f=!0)}function C(U){if(i)return;const F=vt(g.invertX(U.x-_)),Y=vt(g.invertY(U.y-E));n(14,M={x:F,y:Y}),p.update({cursor:{x:g.invertX(U.x),y:g.invertY(U.y)}}),m({x:F,y:Y})}function H(U){if(i)return;n(3,f=!1);const F=vt(g.invertX(U.x-_)),Y=vt(g.invertY(U.y-E));m({x:F,y:Y}),p.update({frame:{x:F,y:Y}})}return Pn().on("start",S).on("drag",C).on("end",H)}function x(){n(1,b=!0),p.update({status:me.dragging})}function J(){n(1,b=!1),m(M),p.update({status:me.masking})}function te(){m(M)}function re(S){Qe[S?"unshift":"push"](()=>{a=S,Zt.set(a)})}const W=()=>y("prompt");function v(S){Qe[S?"unshift":"push"](()=>{L=S,n(2,L)})}return e.$$set=S=>{"transform"in S&&n(0,g=S.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)===me.loading||(l==null?void 0:l.status)===me.prompting||!1),e.$$.dirty&32770&&!b&&l.status===me.loading&&n(1,b=!0),e.$$.dirty&16385&&n(5,s={x:g.applyX(M.x),y:g.applyY(M.y)})},[g,b,L,f,i,s,r,a,u,p,y,x,J,te,M,l,re,W,v]}class Xo extends ge{constructor(t){super(),ve(this,t,Wo,Yo,ye,{transform:0})}}function Go(e){let t,n,r,i;const s=e[8].default,a=Qt(s,e,e[7],null);return{c(){t=j("div"),n=j("canvas"),r=Q(),a&&a.c(),this.h()},l(o){t=V(o,"DIV",{class:!0});var l=O(t);n=V(l,"CANVAS",{width:!0,height:!0,class:!0}),O(n).forEach(h),r=ee(l),a&&a.l(l),l.forEach(h),this.h()},h(){c(n,"width",e[4]),c(n,"height",e[3]),c(n,"class","absolute top-0 left-0 bg-white svelte-6dcxg7"),c(t,"class","absolute top-0 left-0 right-0 bottom-0 overflow-hidden z-0 bg-gray-800")},m(o,l){Z(o,t,l),w(t,n),e[9](n),w(t,r),a&&a.m(t,null),e[10](t),i=!0},p(o,[l]){a&&a.p&&(!i||l&128)&&en(a,s,o,o[7],i?nn(s,o[7],l,null):tn(o[7]),null)},i(o){i||(R(a,o),i=!0)},o(o){z(a,o),i=!1},d(o){o&&h(t),e[9](null),a&&a.d(o),e[10](null)}}}function qo(e,t,n){let r,i,s;Ee(e,Yt,T=>n(12,r=T)),Ee(e,bt,T=>n(1,i=T));let{$$slots:a={},$$scope:o}=t;const l=$t(),u=Ar("promptImgStorage");Ee(e,u,T=>n(6,s=T));const p=512*5,y=512*5;let g,k;const M=new Set;function L(T){return T?Object.values(T).sort((x,J)=>x.date-J.date).filter(({id:x})=>!M.has(x)):[]}let b=[];st(()=>{const B=(y+400)/(g.clientHeight>g.clientWidth?g.clientWidth:g.clientHeight),x=Zo().scaleExtent([1/B/2,3]).translateExtent([[-200,-200],[y+200,p+200]]).tapDistance(10).on("zoom",_),J=Te(i.parentElement).call(x).call(x.transform,Et).call(x.scaleTo,1/B).on("pointermove",E).on("pointerleave",m);k=i.getContext("2d");function te(){const re=(y+400)/(g.clientHeight>g.clientWidth?g.clientWidth:g.clientHeight);J.call(x.transform,Et),J.call(x.scaleTo,1/re)}return window.addEventListener("resize",te),()=>{window.removeEventListener("resize",te)}});function f(T){Promise.all(T.map(({imgURL:B,position:x,id:J})=>new Promise(te=>{const re=new Image;re.crossOrigin="anonymous",re.onload=()=>{const W={img:re,position:x,id:J};k.drawImage(re,x.x,x.y,re.width,re.height),te(W)},re.src=`${qr}/${B}`}))).then(B=>{B.forEach(({img:x,position:J,id:te})=>{M.add(te),k.drawImage(x,J.x,J.y,x.width,x.height)})})}function _(T){const B=Ce(Yt,r=T.transform,r);Ce(bt,i.style.transform=`translate(${B.x}px, ${B.y}px) scale(${B.k})`,i)}function E(T){T.preventDefault();const B=r.invertX(T.clientX),x=r.invertY(T.clientY);l.update({cursor:{x:B,y:x}})}function m(){l.update({cursor:null})}function $(T){Qe[T?"unshift":"push"](()=>{i=T,bt.set(i)})}function I(T){Qe[T?"unshift":"push"](()=>{g=T,n(0,g)})}return e.$$set=T=>{"$$scope"in T&&n(7,o=T.$$scope)},e.$$.update=()=>{e.$$.dirty&64&&n(5,b=L(s==null?void 0:s.toObject())),e.$$.dirty&32&&b&&f(b)},[g,i,u,p,y,b,s,o,a,$,I]}class Qo extends ge{constructor(t){super(),ve(this,t,qo,Go,ye,{})}}function ea(e){let t,n,r;return{c(){t=X("svg"),n=X("rect"),r=X("rect"),this.h()},l(i){t=G(i,"svg",{class:!0,height:!0,viewBox:!0,fill:!0,xmlns:!0});var s=O(t);n=G(s,"rect",{x:!0,y:!0,width:!0,height:!0,rx:!0,stroke:!0}),O(n).forEach(h),r=G(s,"rect",{x:!0,y:!0,width:!0,height:!0,rx:!0,fill:!0,stroke:!0}),O(r).forEach(h),s.forEach(h),this.h()},h(){c(n,"x","1"),c(n,"y","1"),c(n,"width","7"),c(n,"height","7"),c(n,"rx","1"),c(n,"stroke","#2F6DCB"),c(r,"x","3.05566"),c(r,"y","3.05566"),c(r,"width","2.88889"),c(r,"height","2.88889"),c(r,"rx","0.5"),c(r,"fill","#2F6DCB"),c(r,"stroke","#2F6DCB"),c(t,"class",e[0]),c(t,"height","15"),c(t,"viewBox","0 0 9 9"),c(t,"fill","none"),c(t,"xmlns","http://www.w3.org/2000/svg")},m(i,s){Z(i,t,s),w(t,n),w(t,r)},p(i,[s]){s&1&&c(t,"class",i[0])},i:fe,o:fe,d(i){i&&h(t)}}}function ta(e,t,n){let{classList:r=""}=t;return e.$$set=i=>{"classList"in i&&n(0,r=i.classList)},[r]}class dn extends ge{constructor(t){super(),ve(this,t,ta,ea,ye,{classList:0})}}function na(e){let t,n;return{c(){t=X("svg"),n=X("path"),this.h()},l(r){t=G(r,"svg",{class:!0,height:!0,viewBox:!0,fill:!0,xmlns:!0});var i=O(t);n=G(i,"path",{d:!0,fill:!0}),O(n).forEach(h),i.forEach(h),this.h()},h(){c(n,"d","M3.5 4.58599C3.74063 4.58599 3.94669 4.4961 4.11819 4.31633C4.2894 4.13687 4.375 3.92102 4.375 3.66879C4.375 3.41656 4.2894 3.20056 4.11819 3.02079C3.94669 2.84132 3.74063 2.75159 3.5 2.75159C3.25937 2.75159 3.05346 2.84132 2.88225 3.02079C2.71075 3.20056 2.625 3.41656 2.625 3.66879C2.625 3.92102 2.71075 4.13687 2.88225 4.31633C3.05346 4.4961 3.25937 4.58599 3.5 4.58599ZM3.5 7.95669C4.38958 7.10064 5.04948 6.32285 5.47969 5.62334C5.9099 4.92413 6.125 4.30318 6.125 3.76051C6.125 2.92739 5.87154 2.24515 5.36462 1.71378C4.858 1.18273 4.23646 0.917197 3.5 0.917197C2.76354 0.917197 2.14185 1.18273 1.63494 1.71378C1.12831 2.24515 0.875 2.92739 0.875 3.76051C0.875 4.30318 1.0901 4.92413 1.52031 5.62334C1.95052 6.32285 2.61042 7.10064 3.5 7.95669ZM3.5 9C3.44167 9 3.38333 8.98853 3.325 8.9656C3.26667 8.94267 3.21562 8.9121 3.17188 8.87389C2.10729 7.8879 1.3125 6.97269 0.7875 6.12825C0.2625 5.28352 0 4.49427 0 3.76051C0 2.61401 0.351896 1.70064 1.05569 1.02038C1.75919 0.340127 2.57396 0 3.5 0C4.42604 0 5.24081 0.340127 5.94431 1.02038C6.6481 1.70064 7 2.61401 7 3.76051C7 4.49427 6.7375 5.28352 6.2125 6.12825C5.6875 6.97269 4.89271 7.8879 3.82812 8.87389C3.78438 8.9121 3.73333 8.94267 3.675 8.9656C3.61667 8.98853 3.55833 9 3.5 9Z"),c(n,"fill","#338D4C"),c(t,"class",e[0]),c(t,"height","15"),c(t,"viewBox","0 0 7 9"),c(t,"fill","none"),c(t,"xmlns","http://www.w3.org/2000/svg")},m(r,i){Z(r,t,i),w(t,n)},p(r,[i]){i&1&&c(t,"class",r[0])},i:fe,o:fe,d(r){r&&h(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 ge{constructor(t){super(),ve(this,t,ra,na,ye,{classList:0})}}function sa(e){let t,n,r,i;return{c(){t=X("svg"),n=X("path"),r=X("path"),i=X("path"),this.h()},l(s){t=G(s,"svg",{class:!0,height:!0,viewBox:!0,fill:!0,xmlns:!0});var a=O(t);n=G(a,"path",{"fill-rule":!0,"clip-rule":!0,d:!0,fill:!0}),O(n).forEach(h),r=G(a,"path",{d:!0,fill:!0}),O(r).forEach(h),i=G(a,"path",{"fill-rule":!0,"clip-rule":!0,d:!0,fill:!0}),O(i).forEach(h),a.forEach(h),this.h()},h(){c(n,"fill-rule","evenodd"),c(n,"clip-rule","evenodd"),c(n,"d","M6.41113 3.73486C6.97158 4.11531 7.3643 4.63076 7.3643 5.31801V6.54526H8.59155C8.81654 6.54526 9.00063 6.36118 9.00063 6.13618V5.31801C9.00063 4.42621 7.5402 3.8985 6.41113 3.73486Z"),c(n,"fill","#DBAD37"),c(r,"d","M3.27305 3.27266C4.17677 3.27266 4.90938 2.54005 4.90938 1.63633C4.90938 0.732611 4.17677 0 3.27305 0C2.36933 0 1.63672 0.732611 1.63672 1.63633C1.63672 2.54005 2.36933 3.27266 3.27305 3.27266Z"),c(r,"fill","#DBAD37"),c(i,"fill-rule","evenodd"),c(i,"clip-rule","evenodd"),c(i,"d","M5.72716 3.27266C6.63124 3.27266 7.36349 2.54041 7.36349 1.63633C7.36349 0.732258 6.63124 0 5.72716 0C5.53489 0 5.3549 0.0409082 5.18308 0.0981798C5.53511 0.533533 5.72715 1.07646 5.72715 1.63633C5.72715 2.1962 5.53511 2.73913 5.18308 3.17448C5.3549 3.23176 5.53489 3.27266 5.72716 3.27266ZM3.27266 3.68175C2.18041 3.68175 0 4.22992 0 5.31808V6.13624C0 6.36124 0.184087 6.54533 0.409083 6.54533H6.13625C6.36124 6.54533 6.54533 6.36124 6.54533 6.13624V5.31808C6.54533 4.22992 4.36492 3.68175 3.27266 3.68175Z"),c(i,"fill","#DBAD37"),c(t,"class",e[0]),c(t,"height","15"),c(t,"viewBox","0 0 9 7"),c(t,"fill","none"),c(t,"xmlns","http://www.w3.org/2000/svg")},m(s,a){Z(s,t,a),w(t,n),w(t,r),w(t,i)},p(s,[a]){a&1&&c(t,"class",s[0])},i:fe,o:fe,d(s){s&&h(t)}}}function oa(e,t,n){let{classList:r=""}=t;return e.$$set=i=>{"classList"in i&&n(0,r=i.classList)},[r]}class hn extends ge{constructor(t){super(),ve(this,t,oa,sa,ye,{classList:0})}}function Un(e,t,n){const r=e.slice();return r[14]=t[n],r}function xn(e){let t,n,r,i,s,a,o,l,u,p,y=!e[4]&&Hn(e);const g=[la,aa],k=[];function M(L,b){return L[6]?0:1}return i=M(e),s=k[i]=g[i](e),{c(){t=j("div"),y&&y.c(),n=Q(),r=j("div"),s.c(),this.h()},l(L){t=V(L,"DIV",{class:!0,title:!0});var b=O(t);y&&y.l(b),n=ee(b),r=V(b,"DIV",{class:!0});var f=O(r);s.l(f),f.forEach(h),b.forEach(h),this.h()},h(){c(r,"class",a=e[0]?"cursor-wait":"cursor-pointer"),c(t,"class",o="text-xs md:text-sm bg-violet-100 text-violet-900 px-3 py-1 font-mono font-medium tracking-tight relative z-0 min-w-[25ch] "+(e[0]?"opacity-50":"")+" "+(e[4]?"rounded-xl":"rounded-b-xl")),c(t,"title","Choose a different room")},m(L,b){Z(L,t,b),y&&y.m(t,null),w(t,n),w(t,r),k[i].m(r,null),e[10](t),l=!0,u||(p=je(r,"click",e[9]),u=!0)},p(L,b){L[4]?y&&(ke(),z(y,1,1,()=>{y=null}),Ie()):y?(y.p(L,b),b&16&&R(y,1)):(y=Hn(L),y.c(),R(y,1),y.m(t,n));let f=i;i=M(L),i===f?k[i].p(L,b):(ke(),z(k[f],1,1,()=>{k[f]=null}),Ie(),s=k[i],s?s.p(L,b):(s=k[i]=g[i](L),s.c()),R(s,1),s.m(r,null)),(!l||b&1&&a!==(a=L[0]?"cursor-wait":"cursor-pointer"))&&c(r,"class",a),(!l||b&17&&o!==(o="text-xs md:text-sm bg-violet-100 text-violet-900 px-3 py-1 font-mono font-medium tracking-tight relative z-0 min-w-[25ch] "+(L[0]?"opacity-50":"")+" "+(L[4]?"rounded-xl":"rounded-b-xl")))&&c(t,"class",o)},i(L){l||(R(y),R(s),l=!0)},o(L){z(y),z(s),l=!1},d(L){L&&h(t),y&&y.d(),k[i].d(),e[10](null),u=!1,p()}}}function Hn(e){let t,n,r,i,s,a,o,l,u,p,y,g,k,M,L,b;i=new dn({}),u=new hn({});let f=e[1],_=[];for(let m=0;mz(_[m],1,1,()=>{_[m]=null});return{c(){t=j("div"),n=j("ul"),r=j("li"),ie(i.$$.fragment),s=Q(),a=j("span"),o=ue("room"),l=Q(),ie(u.$$.fragment),p=Q(),y=j("span"),g=ue("players"),k=Q();for(let m=0;m<_.length;m+=1)_[m].c();M=Q(),L=j("div"),this.h()},l(m){t=V(m,"DIV",{class:!0});var $=O(t);n=V($,"UL",{class:!0});var I=O(n);r=V(I,"LI",{class:!0});var T=O(r);se(i.$$.fragment,T),s=ee(T),a=V(T,"SPAN",{});var B=O(a);o=ce(B,"room"),B.forEach(h),l=ee(T),se(u.$$.fragment,T),p=ee(T),y=V(T,"SPAN",{});var x=O(y);g=ce(x,"players"),x.forEach(h),T.forEach(h),k=ee(I);for(let J=0;J<_.length;J+=1)_[J].l(I);I.forEach(h),M=ee($),L=V($,"DIV",{class:!0}),O(L).forEach(h),$.forEach(h),this.h()},h(){c(r,"class","grid-row gap-2 pb-3 sticky top-0 bg-violet-100 py-2 svelte-15fj2lr"),c(n,"class","relative overflow-scroll max-h-72"),c(L,"class","border-t-2 border-t-gray-400 border-opacity-50"),c(t,"class","absolute left-0 right-0 bottom-full rounded-t-xl bg-violet-100 px-1")},m(m,$){Z(m,t,$),w(t,n),w(n,r),oe(i,r,null),w(r,s),w(r,a),w(a,o),w(r,l),oe(u,r,null),w(r,p),w(r,y),w(y,g),w(n,k);for(let I=0;I<_.length;I+=1)_[I].m(n,null);w(t,M),w(t,L),b=!0},p(m,$){if($&134){f=m[1];let I;for(I=0;I{I=null}),Ie()),(!E||x&2)&&o!==(o=e[14].id+"")&&Fe(l,o),(!E||x&2)&&k!==(k=e[14].users_count+"")&&Fe(M,k),(!E||x&6&&f!==(f="grid-row gap-2 hover:bg-gray-300 "+(e[14].id===e[2]?"text-green-600":"")+" svelte-15fj2lr"))&&c(n,"class",f)},i(B){E||(R(I),E=!0)},o(B){z(I),E=!1},d(B){B&&h(t),I&&I.d(),m=!1,$()}}}function aa(e){let t,n,r,i,s,a,o,l,u,p;return n=new dn({}),a=new hn({}),{c(){t=j("div"),ie(n.$$.fragment),r=Q(),i=j("span"),s=ue(`Loading... - `),ie(a.$$.fragment),o=Q(),l=j("span"),u=ue("... / ..."),this.h()},l(y){t=V(y,"DIV",{class:!0});var g=O(t);se(n.$$.fragment,g),r=ee(g),i=V(g,"SPAN",{});var k=O(i);s=ce(k,`Loading... - `),se(a.$$.fragment,k),o=ee(k),l=V(k,"SPAN",{});var M=O(l);u=ce(M,"... / ..."),M.forEach(h),k.forEach(h),g.forEach(h),this.h()},h(){c(t,"class","grid-row gap-2 svelte-15fj2lr")},m(y,g){Z(y,t,g),oe(n,t,null),w(t,r),w(t,i),w(i,s),oe(a,i,null),w(i,o),w(i,l),w(l,u),p=!0},p:fe,i(y){p||(R(n.$$.fragment,y),R(a.$$.fragment,y),p=!0)},o(y){z(n.$$.fragment,y),z(a.$$.fragment,y),p=!1},d(y){y&&h(t),ae(n),ae(a)}}}function la(e){var f,_;let t,n,r,i,s,a=((f=e[6])==null?void 0:f.id)+"",o,l,u,p,y,g=((_=e[6])==null?void 0:_.users_count)+"",k,M,L,b;return n=new dn({}),u=new hn({}),{c(){t=j("div"),ie(n.$$.fragment),r=Q(),i=j("span"),s=ue("room "),o=ue(a),l=Q(),ie(u.$$.fragment),p=Q(),y=j("span"),k=ue(g),M=ue(" / "),L=ue(kt),this.h()},l(E){t=V(E,"DIV",{class:!0});var m=O(t);se(n.$$.fragment,m),r=ee(m),i=V(m,"SPAN",{});var $=O(i);s=ce($,"room "),o=ce($,a),$.forEach(h),l=ee(m),se(u.$$.fragment,m),p=ee(m),y=V(m,"SPAN",{});var I=O(y);k=ce(I,g),M=ce(I," / "),L=ce(I,kt),I.forEach(h),m.forEach(h),this.h()},h(){c(t,"class","grid-row gap-2 svelte-15fj2lr")},m(E,m){Z(E,t,m),oe(n,t,null),w(t,r),w(t,i),w(i,s),w(i,o),w(t,l),oe(u,t,null),w(t,p),w(t,y),w(y,k),w(y,M),w(y,L),b=!0},p(E,m){var $,I;(!b||m&64)&&a!==(a=(($=E[6])==null?void 0:$.id)+"")&&Fe(o,a),(!b||m&64)&&g!==(g=((I=E[6])==null?void 0:I.users_count)+"")&&Fe(k,g)},i(E){b||(R(n.$$.fragment,E),R(u.$$.fragment,E),b=!0)},o(E){z(n.$$.fragment,E),z(u.$$.fragment,E),b=!1},d(E){E&&h(t),ae(n),ae(u)}}}function ua(e){let t,n,r=e[5]&&xn(e);return{c(){r&&r.c(),t=Me()},l(i){r&&r.l(i),t=Me()},m(i,s){r&&r.m(i,s),Z(i,t,s),n=!0},p(i,[s]){i[5]?r?(r.p(i,s),s&32&&R(r,1)):(r=xn(i),r.c(),R(r,1),r.m(t.parentNode,t)):r&&(ke(),z(r,1,1,()=>{r=null}),Ie())},i(i){n||(R(r),n=!0)},o(i){z(r),n=!1},d(i){r&&r.d(i),i&&h(t)}}}function ca(e,t,n){let r,i,s,a;Ee(e,ei,f=>n(11,s=f)),Ee(e,Wt,f=>n(2,a=f));let{isLoading:o=!1}=t,l,u=[],p=!0;function y(f){l.contains(f.target)||n(4,p=!0)}st(()=>{g(),window.addEventListener("click",y,!0);const f=setInterval(g,3e3);return()=>{window.removeEventListener("click",y,!0),clearInterval(f)}});async function g(){n(1,u=await fetch(sn+"/rooms").then(f=>f.json()))}function k(f){Ce(Wt,a=f.id,a),n(4,p=!0),s.url.searchParams.set("roomid",f.room_id),window.location.search=`?${s.url.searchParams.toString()}`}const M=f=>k(f),L=()=>o?null:n(4,p=!p);function b(f){Qe[f?"unshift":"push"](()=>{l=f,n(3,l)})}return e.$$set=f=>{"isLoading"in f&&n(0,o=f.isLoading)},e.$$.update=()=>{e.$$.dirty&6&&n(6,r=u.find(f=>f.id===a)),e.$$.dirty&2&&n(5,i=u.length>0)},[o,u,a,l,p,i,r,k,M,L,b]}class fa extends ge{constructor(t){super(),ve(this,t,ca,ua,ye,{isLoading:0})}}function da(e){let t,n,r,i,s,a,o,l,u,p,y,g,k,M,L,b,f,_,E,m,$,I,T,B,x,J,te;return{c(){t=X("svg"),n=X("rect"),r=X("path"),i=X("path"),s=X("path"),a=X("path"),o=X("path"),l=X("path"),u=X("path"),p=X("path"),y=X("path"),g=X("path"),k=X("path"),M=X("path"),L=X("path"),b=X("path"),f=X("path"),_=X("path"),E=X("path"),m=X("path"),$=X("path"),I=X("path"),T=X("path"),B=X("defs"),x=X("radialGradient"),J=X("stop"),te=X("stop"),this.h()},l(re){t=G(re,"svg",{class:!0,width:!0,height:!0,viewBox:!0,fill:!0,xmlns:!0});var W=O(t);n=G(W,"rect",{opacity:!0,x:!0,y:!0,width:!0,height:!0,rx:!0,fill:!0,stroke:!0,"stroke-width":!0}),O(n).forEach(h),r=G(W,"path",{d:!0,fill:!0}),O(r).forEach(h),i=G(W,"path",{d:!0,fill:!0}),O(i).forEach(h),s=G(W,"path",{d:!0,fill:!0}),O(s).forEach(h),a=G(W,"path",{d:!0,fill:!0}),O(a).forEach(h),o=G(W,"path",{d:!0,fill:!0}),O(o).forEach(h),l=G(W,"path",{d:!0,fill:!0}),O(l).forEach(h),u=G(W,"path",{d:!0,fill:!0}),O(u).forEach(h),p=G(W,"path",{d:!0,fill:!0}),O(p).forEach(h),y=G(W,"path",{d:!0,fill:!0}),O(y).forEach(h),g=G(W,"path",{d:!0,fill:!0}),O(g).forEach(h),k=G(W,"path",{d:!0,fill:!0}),O(k).forEach(h),M=G(W,"path",{d:!0,fill:!0}),O(M).forEach(h),L=G(W,"path",{d:!0,fill:!0}),O(L).forEach(h),b=G(W,"path",{d:!0,fill:!0}),O(b).forEach(h),f=G(W,"path",{d:!0,fill:!0}),O(f).forEach(h),_=G(W,"path",{d:!0,fill:!0}),O(_).forEach(h),E=G(W,"path",{d:!0,fill:!0}),O(E).forEach(h),m=G(W,"path",{d:!0,fill:!0}),O(m).forEach(h),$=G(W,"path",{d:!0,fill:!0}),O($).forEach(h),I=G(W,"path",{d:!0,fill:!0}),O(I).forEach(h),T=G(W,"path",{"fill-rule":!0,"clip-rule":!0,d:!0,fill:!0}),O(T).forEach(h),B=G(W,"defs",{});var v=O(B);x=G(v,"radialGradient",{id:!0,cx:!0,cy:!0,r:!0,gradientUnits:!0,gradientTransform:!0});var S=O(x);J=G(S,"stop",{"stop-color":!0}),O(J).forEach(h),te=G(S,"stop",{offset:!0,"stop-color":!0}),O(te).forEach(h),S.forEach(h),v.forEach(h),W.forEach(h),this.h()},h(){c(n,"opacity","0.5"),c(n,"x","0.25"),c(n,"y","0.25"),c(n,"width","122.5"),c(n,"height","43.5"),c(n,"rx","6.75"),c(n,"fill","#1F2937"),c(n,"stroke","#3A4C64"),c(n,"stroke-width","0.5"),c(r,"d","M44.9102 16.8569H45.8514V14.778H47.1691C48.364 14.778 49.1497 14.0577 49.1497 12.9528C49.1497 11.8397 48.364 11.1277 47.1691 11.1277H44.9102V16.8569ZM47.0954 11.9461C47.7666 11.9461 48.1921 12.3308 48.1921 12.9528C48.1921 13.5667 47.7584 13.9595 47.0872 13.9595H45.8514V11.9461H47.0954Z"),c(r,"fill","#A3BAD9"),c(i,"d","M51.5649 16.9059C52.8417 16.9059 53.701 16.0465 53.701 14.7615C53.701 13.4847 52.8417 12.6172 51.5649 12.6172C50.2881 12.6172 49.4287 13.4847 49.4287 14.7615C49.4287 16.0465 50.2881 16.9059 51.5649 16.9059ZM51.5649 16.1529C50.8201 16.1529 50.3372 15.5718 50.3372 14.7615C50.3372 13.9513 50.8201 13.3702 51.5649 13.3702C52.3097 13.3702 52.8007 13.9513 52.8007 14.7615C52.8007 15.5718 52.3097 16.1529 51.5649 16.1529Z"),c(i,"fill","#A3BAD9"),c(s,"d","M55.233 16.857H56.1906L57.1073 14.0088L57.9912 16.857H58.9406L60.332 12.6665H59.4317L58.4414 15.8748L57.5247 12.6665H56.7144L55.7568 15.8748L54.7992 12.6665H53.8662L55.233 16.857Z"),c(s,"fill","#A3BAD9"),c(a,"d","M62.6424 16.9059C63.6818 16.9059 64.3857 16.2757 64.533 15.449H63.6491C63.5263 15.9156 63.1335 16.1856 62.5933 16.1856C61.8976 16.1856 61.4475 15.7191 61.4229 15.0071V14.9498H64.5821C64.5985 14.8352 64.6067 14.7206 64.6067 14.6142C64.5821 13.3865 63.7719 12.6172 62.5605 12.6172C61.3247 12.6172 60.498 13.4766 60.498 14.7697C60.498 16.0547 61.3247 16.9059 62.6424 16.9059ZM61.4556 14.3032C61.5211 13.7057 62.004 13.3292 62.5687 13.3292C63.1826 13.3292 63.6164 13.6812 63.69 14.3032H61.4556Z"),c(a,"fill","#A3BAD9"),c(o,"d","M67.4411 12.6665C66.7536 12.6665 66.418 12.9448 66.2052 13.2967L66.107 12.6665H65.3213V16.857H66.2052V14.7536C66.2052 14.107 66.4589 13.4931 67.2447 13.4931H67.6375V12.6665H67.4411Z"),c(o,"fill","#A3BAD9"),c(l,"d","M69.9725 16.9059C71.0119 16.9059 71.7158 16.2757 71.8631 15.449H70.9792C70.8564 15.9156 70.4635 16.1856 69.9234 16.1856C69.2277 16.1856 68.7775 15.7191 68.753 15.0071V14.9498H71.9122C71.9286 14.8352 71.9368 14.7206 71.9368 14.6142C71.9122 13.3865 71.1019 12.6172 69.8906 12.6172C68.6548 12.6172 67.8281 13.4766 67.8281 14.7697C67.8281 16.0547 68.6548 16.9059 69.9725 16.9059ZM68.7857 14.3032C68.8512 13.7057 69.3341 13.3292 69.8988 13.3292C70.5127 13.3292 70.9464 13.6812 71.0201 14.3032H68.7857Z"),c(l,"fill","#A3BAD9"),c(u,"d","M75.8352 13.2475C75.5651 12.8792 75.1149 12.6173 74.4765 12.6173C73.3391 12.6173 72.4961 13.4685 72.4961 14.7616C72.4961 16.1039 73.3391 16.906 74.4765 16.906C75.1395 16.906 75.5733 16.5949 75.8433 16.2266L75.9497 16.8569H76.7191V11.1277H75.8352V13.2475ZM74.6238 16.1612C73.8875 16.1612 73.4046 15.5883 73.4046 14.7616C73.4046 13.9432 73.8875 13.3702 74.6238 13.3702C75.3605 13.3702 75.8433 13.9432 75.8433 14.778C75.8433 15.5883 75.3605 16.1612 74.6238 16.1612Z"),c(u,"fill","#A3BAD9"),c(p,"d","M81.9193 12.6173C81.2727 12.6173 80.839 12.9119 80.5607 13.2884V11.1277H79.6768V16.8569H80.4461L80.5525 16.2512C80.8144 16.6277 81.2646 16.906 81.9193 16.906C83.0652 16.906 83.9 16.0466 83.9 14.7616C83.9 13.4112 83.0652 12.6173 81.9193 12.6173ZM81.772 16.1612C81.0354 16.1612 80.5525 15.5801 80.5525 14.7534C80.5525 13.9432 81.0354 13.3702 81.772 13.3702C82.5086 13.3702 82.9997 13.9432 82.9997 14.7616C82.9997 15.5883 82.5086 16.1612 81.772 16.1612Z"),c(p,"fill","#A3BAD9"),c(y,"d","M85.6277 16.8815L85.4641 17.2908C85.3331 17.6345 85.2513 17.7164 84.9075 17.7164H84.2855V18.4939H85.2349C85.8487 18.4939 86.0288 18.1911 86.2907 17.5117L88.1895 12.6665H87.2483L86.1106 15.8503L84.9402 12.6665H83.999L85.6277 16.8815Z"),c(y,"fill","#A3BAD9"),c(g,"d","M45.1162 32.4821H47.2144V22.0654H45.1162V32.4821Z"),c(g,"fill","#A3BAD9"),c(k,"d","M49.7329 24.0148C50.4175 24.0148 50.9532 23.5088 50.9532 22.8392C50.9532 22.1546 50.4175 21.6487 49.7329 21.6487C49.0484 21.6487 48.5127 22.1546 48.5127 22.8392C48.5127 23.5088 49.0484 24.0148 49.7329 24.0148ZM48.6764 32.482H50.7895V24.8332H48.6764V32.482Z"),c(k,"fill","#A3BAD9"),c(M,"d","M54.2461 32.4823H56.8503L59.6033 24.8335H57.4009L55.5854 30.3394L53.7402 24.8335H51.4932L54.2461 32.4823Z"),c(M,"fill","#A3BAD9"),c(L,"d","M63.718 32.5713C65.7567 32.5713 67.0811 31.3808 67.3192 29.8927H65.2507C65.0722 30.607 64.4769 30.979 63.6287 30.979C62.5722 30.979 61.8728 30.3243 61.8281 29.2379V29.1338H67.3787C67.4234 28.8957 67.4382 28.6427 67.4382 28.4195C67.4085 26.1725 65.8609 24.7439 63.5692 24.7439C61.2031 24.7439 59.6406 26.2915 59.6406 28.6725C59.6406 31.0385 61.1734 32.5713 63.718 32.5713ZM61.8728 27.7647C61.9918 26.857 62.6763 26.3064 63.5841 26.3064C64.5365 26.3064 65.1763 26.8272 65.3251 27.7647H61.8728Z"),c(L,"fill","#A3BAD9"),c(b,"d","M72.9898 24.744C71.9332 24.744 71.1891 25.1904 70.6832 25.8005V22.0654H68.585V32.4821H70.4153L70.6237 31.4404C71.1148 32.0952 71.8737 32.5714 72.9749 32.5714C75.0434 32.5714 76.5315 31.0089 76.5315 28.6428C76.5315 26.2172 75.0434 24.744 72.9898 24.744ZM72.5136 30.8601C71.3678 30.8601 70.6534 29.9523 70.6534 28.6428C70.6534 27.3482 71.3678 26.4553 72.5136 26.4553C73.6594 26.4553 74.4035 27.3482 74.4035 28.6577C74.4035 29.9672 73.6594 30.8601 72.5136 30.8601Z"),c(b,"fill","#A3BAD9"),c(f,"d","M77.6973 32.4821H79.7955V22.0654H77.6973V32.4821Z"),c(f,"fill","#A3BAD9"),c(_,"d","M84.9927 32.5713C87.4332 32.5713 89.0254 31.0237 89.0254 28.6576C89.0254 26.3064 87.4332 24.7439 84.9927 24.7439C82.5522 24.7439 80.96 26.3064 80.96 28.6576C80.96 31.0088 82.5522 32.5713 84.9927 32.5713ZM84.9927 30.86C83.8171 30.86 83.1028 29.9522 83.1028 28.6576C83.1028 27.3629 83.8171 26.4552 84.9927 26.4552C86.1683 26.4552 86.8975 27.3629 86.8975 28.6576C86.8975 29.9522 86.1683 30.86 84.9927 30.86Z"),c(_,"fill","#A3BAD9"),c(E,"d","M93.7816 32.5713C95.865 32.5713 97.2489 31.4254 97.5465 29.5951H95.3441C95.1953 30.3689 94.6447 30.86 93.8263 30.86C92.7251 30.86 92.0257 29.9671 92.0257 28.6576C92.0257 27.3629 92.7251 26.4552 93.8263 26.4552C94.6447 26.4552 95.1655 26.9314 95.3441 27.6903H97.5316C97.234 25.8748 95.9394 24.7439 93.856 24.7439C91.4304 24.7439 89.8828 26.2915 89.8828 28.6576C89.8828 31.0683 91.356 32.5713 93.7816 32.5713Z"),c(E,"fill","#A3BAD9"),c(m,"d","M98.6514 32.4821H100.75V30.622L101.895 29.3869L103.83 32.4821H106.256L103.354 27.8392L106.107 24.8333H103.741L100.75 28.0773V22.0654H98.6514V32.4821Z"),c(m,"fill","#A3BAD9"),c($,"d","M106.188 29.9375C106.277 31.5744 107.72 32.5714 109.848 32.5714C111.902 32.5714 113.33 31.6042 113.33 30.0863C113.33 28.3601 111.872 27.9583 110.116 27.7798C109.015 27.6458 108.36 27.5863 108.36 27.006C108.36 26.5149 108.896 26.2173 109.714 26.2173C110.562 26.2173 111.143 26.5893 111.202 27.1994H113.211C113.107 25.6369 111.693 24.7292 109.64 24.7292C107.676 24.7143 106.351 25.7113 106.351 27.2292C106.351 28.8065 107.735 29.2083 109.521 29.4167C110.756 29.5804 111.277 29.625 111.277 30.25C111.277 30.7857 110.741 31.0685 109.863 31.0685C108.836 31.0685 108.256 30.6071 108.182 29.9375H106.188Z"),c($,"fill","#A3BAD9"),c(I,"d","M32.4824 8.67236H11.649C10.0053 8.67236 8.67285 10.0048 8.67285 11.6486V32.4819C8.67285 34.1256 10.0053 35.4581 11.649 35.4581H32.4824C34.1261 35.4581 35.4586 34.1256 35.4586 32.4819V11.6486C35.4586 10.0048 34.1261 8.67236 32.4824 8.67236Z"),c(I,"fill","url(#paint0_radial_253_107)"),c(T,"fill-rule","evenodd"),c(T,"clip-rule","evenodd"),c(T,"d","M24.8953 17.78H15.0332L17.8712 20.7599V24.875L24.8953 17.78ZM19.2193 26.294H29.0814L26.2434 23.3141V19.199L19.2193 26.294Z"),c(T,"fill","white"),c(J,"stop-color","#FF0099"),c(te,"offset","1"),c(te,"stop-color","#FF7A00"),c(x,"id","paint0_radial_253_107"),c(x,"cx","0"),c(x,"cy","0"),c(x,"r","1"),c(x,"gradientUnits","userSpaceOnUse"),c(x,"gradientTransform","translate(4.7524 1.97593) rotate(45.3703) scale(40.7748 35.4976)"),c(t,"class",e[0]),c(t,"width","123"),c(t,"height","44"),c(t,"viewBox","0 0 123 44"),c(t,"fill","none"),c(t,"xmlns","http://www.w3.org/2000/svg")},m(re,W){Z(re,t,W),w(t,n),w(t,r),w(t,i),w(t,s),w(t,a),w(t,o),w(t,l),w(t,u),w(t,p),w(t,y),w(t,g),w(t,k),w(t,M),w(t,L),w(t,b),w(t,f),w(t,_),w(t,E),w(t,m),w(t,$),w(t,I),w(t,T),w(t,B),w(B,x),w(x,J),w(x,te)},p(re,[W]){W&1&&c(t,"class",re[0])},i:fe,o:fe,d(re){re&&h(t)}}}function ha(e,t,n){let{classList:r=""}=t;return e.$$set=i=>{"classList"in i&&n(0,r=i.classList)},[r]}class pa extends ge{constructor(t){super(),ve(this,t,ha,da,ye,{classList:0})}}function ma(e){let t,n,r,i,s,a,o,l;return n=new Cr({props:{isLoading:e[0]}}),n.$on("click",e[2]),i=new fa({props:{isLoading:e[0]}}),o=new pa({props:{classList:"max-h-8 md:max-h-fit"}}),{c(){t=j("div"),ie(n.$$.fragment),r=Q(),ie(i.$$.fragment),s=Q(),a=j("a"),ie(o.$$.fragment),this.h()},l(u){t=V(u,"DIV",{class:!0});var p=O(t);se(n.$$.fragment,p),r=ee(p),se(i.$$.fragment,p),s=ee(p),a=V(p,"A",{href:!0,target:!0,rel:!0,title:!0});var y=O(a);se(o.$$.fragment,y),y.forEach(h),p.forEach(h),this.h()},h(){c(a,"href","https://liveblocks.io"),c(a,"target","_blank"),c(a,"rel","noopener noreferrer"),c(a,"title","Multiplayer backend by LiveBlocks.io"),c(t,"class","grid grid-cols-1 gap-1 w-max mx-auto place-items-center")},m(u,p){Z(u,t,p),oe(n,t,null),w(t,r),oe(i,t,null),w(t,s),w(t,a),oe(o,a,null),l=!0},p(u,[p]){const y={};p&1&&(y.isLoading=u[0]),n.$set(y);const g={};p&1&&(g.isLoading=u[0]),i.$set(g)},i(u){l||(R(n.$$.fragment,u),R(i.$$.fragment,u),R(o.$$.fragment,u),l=!0)},o(u){z(n.$$.fragment,u),z(i.$$.fragment,u),z(o.$$.fragment,u),l=!1},d(u){u&&h(t),ae(n),ae(i),ae(o)}}}function _a(e,t,n){const r=rn();let{isLoading:i=!1}=t;const s=o=>{o.key==="Enter"&&r("prompt")};st(()=>(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 ga extends ge{constructor(t){super(),ve(this,t,_a,ma,ye,{isLoading:0})}}function va(e){let t,n,r,i,s,a,o,l;return{c(){t=j("form"),n=j("div"),r=j("input"),i=Q(),s=j("button"),a=ue("Paint"),this.h()},l(u){t=V(u,"FORM",{class:!0});var p=O(t);n=V(p,"DIV",{class:!0});var y=O(n);r=V(y,"INPUT",{class:!0,placeholder:!0,title:!0,type:!0,name:!0}),i=ee(y),s=V(y,"BUTTON",{class:!0,type:!0});var g=O(s);a=ce(g,"Paint"),g.forEach(h),y.forEach(h),p.forEach(h),this.h()},h(){r.value=e[0],c(r,"class","input svelte-1ayu15l"),c(r,"placeholder","Type a prompt..."),c(r,"title","Input prompt to generate image and obtain palette"),c(r,"type","text"),c(r,"name","prompt"),c(s,"class","font-mono border-l-2 pl-2"),c(s,"type","submit"),c(n,"class","flex bg-white rounded-2xl px-2 w-full max-w-md"),c(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,p){Z(u,t,p),w(t,n),w(n,r),e[7](r),w(n,i),w(n,s),w(s,a),e[8](n),o||(l=[je(r,"click",Zr(e[6])),je(r,"input",e[4]),je(s,"click",Jt(e[3])),je(t,"submit",Jt(e[3]))],o=!0)},p(u,[p]){p&1&&r.value!==u[0]&&(r.value=u[0])},i:fe,o:fe,d(u){u&&h(t),e[7](null),e[8](null),o=!1,Yr(l)}}}function ya(e,t,n){const r=rn();let{initPrompt:i=""}=t,s,a,o;const l=$t(),u=_=>{_.key==="Escape"&&(l.update({status:me.ready}),r("close"))};st(()=>(a.focus(),n(0,s=i),window.addEventListener("keyup",u),window.addEventListener("click",M,!0),()=>{window.removeEventListener("keyup",u),window.removeEventListener("click",M,!0)}));let p;function y(_){clearTimeout(p),p=setTimeout(()=>{n(0,s=_),l.update({currentPrompt:s,status:me.prompting})},100)}function g(){s.trim()!==""&&(r("paint"),r("close"))}function k(_){const E=_.target;y(E.value)}function M(_){o.contains(_.target)||(l.update({status:me.ready}),r("close"))}function L(_){ft.call(this,e,_)}function b(_){Qe[_?"unshift":"push"](()=>{a=_,n(1,a)})}function f(_){Qe[_?"unshift":"push"](()=>{o=_,n(2,o)})}return e.$$set=_=>{"initPrompt"in _&&n(5,i=_.initPrompt)},[s,a,o,g,k,i,L,b,f]}class ba extends ge{constructor(t){super(),ve(this,t,ya,va,ye,{initPrompt:5})}}let wa=(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 zn(e,t,n){const r=e.slice();return r[16]=t[n].connectionId,r[17]=t[n].presence,r}function Bn(e){var r;let t,n;return t=new ba({props:{initPrompt:(r=e[0])==null?void 0:r.currentPrompt}}),t.$on("paint",e[11]),t.$on("close",e[10]),{c(){ie(t.$$.fragment)},l(i){se(t.$$.fragment,i)},m(i,s){oe(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||(R(t.$$.fragment,i),n=!0)},o(i){z(t.$$.fragment,i),n=!1},d(i){ae(t,i)}}}function Kn(e){let t=[],n=new Map,r,i,s=[...e[5]];const a=o=>o[16];for(let o=0;o{a=null}),Ie()),(E=t[17])!=null&&E.cursor?o?(o.p(t,M),M&32&&R(o,1)):(o=Jn(t),o.c(),R(o,1),o.m(i.parentNode,i)):o&&(ke(),z(o,1,1,()=>{o=null}),Ie())},i(k){s||(R(a),R(o),s=!0)},o(k){z(a),z(o),s=!1},d(k){k&&h(n),a&&a.d(k),k&&h(r),o&&o.d(k),k&&h(i)}}}function Ea(e){let t,n,r,i,s,a,o,l,u,p,y,g,k,M,L=e[1]&&Bn(e);a=new Qo({}),u=new Xo({props:{transform:e[4]}}),u.$on("prompt",e[9]);let b=e[5]&&Kn(e);return k=new ga({props:{isLoading:e[2]}}),k.$on("prompt",e[9]),{c(){t=j("div"),n=ue(e[3]),r=Q(),L&&L.c(),i=Q(),s=j("div"),ie(a.$$.fragment),o=Q(),l=j("main"),ie(u.$$.fragment),p=Q(),b&&b.c(),y=Q(),g=j("div"),ie(k.$$.fragment),this.h()},l(f){t=V(f,"DIV",{class:!0});var _=O(t);n=ce(_,e[3]),_.forEach(h),r=ee(f),L&&L.l(f),i=ee(f),s=V(f,"DIV",{class:!0});var E=O(s);se(a.$$.fragment,E),o=ee(E),l=V(E,"MAIN",{class:!0});var m=O(l);se(u.$$.fragment,m),p=ee(m),b&&b.l(m),m.forEach(h),E.forEach(h),y=ee(f),g=V(f,"DIV",{class:!0});var $=O(g);se(k.$$.fragment,$),$.forEach(h),this.h()},h(){c(t,"class","text touch-none pointer-events-none"),c(l,"class","z-10 relative"),c(s,"class","fixed top-0 left-0 z-0 w-screen h-screen"),c(g,"class","fixed bottom-0 left-0 right-0 z-10 my-2")},m(f,_){Z(f,t,_),w(t,n),Z(f,r,_),L&&L.m(f,_),Z(f,i,_),Z(f,s,_),oe(a,s,null),w(s,o),w(s,l),oe(u,l,null),w(l,p),b&&b.m(l,null),Z(f,y,_),Z(f,g,_),oe(k,g,null),M=!0},p(f,[_]){(!M||_&8)&&Fe(n,f[3]),f[1]?L?(L.p(f,_),_&2&&R(L,1)):(L=Bn(f),L.c(),R(L,1),L.m(i.parentNode,i)):L&&(ke(),z(L,1,1,()=>{L=null}),Ie());const E={};_&16&&(E.transform=f[4]),u.$set(E),f[5]?b?(b.p(f,_),_&32&&R(b,1)):(b=Kn(f),b.c(),R(b,1),b.m(l,null)):b&&(ke(),z(b,1,1,()=>{b=null}),Ie());const m={};_&4&&(m.isLoading=f[2]),k.$set(m)},i(f){M||(R(L),R(a.$$.fragment,f),R(u.$$.fragment,f),R(b),R(k.$$.fragment,f),M=!0)},o(f){z(L),z(a.$$.fragment,f),z(u.$$.fragment,f),z(b),z(k.$$.fragment,f),M=!1},d(f){f&&h(t),f&&h(r),L&&L.d(f),f&&h(i),f&&h(s),ae(a),ae(u),b&&b.d(),f&&h(y),f&&h(g),ae(k)}}}function ka(e){return`${e.x}_${e.y}`}function Ia(e,t,n){let r,i,s,a,o,l,u;Ee(e,Pe,E=>n(3,i=E)),Ee(e,Zt,E=>n(13,a=E)),Ee(e,Yt,E=>n(4,l=E));const p=$t();Ee(e,p,E=>n(0,o=E));const y=Do();Ee(e,y,E=>n(5,u=E));const g={cursor:null,frame:null,status:me.dragging,currentPrompt:""};p.update(g);const k=Ar("promptImgStorage");Ee(e,k,E=>n(12,s=E));let M=!1;function L(){!r&&!M&&(n(1,M=!0),p.update({status:me.prompting}))}function b(){n(1,M=!1)}function f(){_(),n(1,M=!1)}async function _(){if(r)return;Ce(Pe,i="Pending",i);const E=o.currentPrompt,m=o.frame;console.log("Generating...",E,m),p.update({status:me.loading});const $=crypto.randomUUID(),I=a.toDataURL("image/png"),T={fn_index:0,data:[I,E,.75,7.5,35,"patchmatch"],session_hash:$},B=new WebSocket(Qr);B.onclose=x=>{x.wasClean||(Ce(Pe,i="Error",i),p.update({status:me.ready}))},B.onmessage=async function(x){try{const J=JSON.parse(x.data);switch(Ce(Pe,i="",i),J.msg){case"send_data":Ce(Pe,i="Sending Data",i),B.send(JSON.stringify(T));break;case"queue_full":Ce(Pe,i="Queue full",i),B.close(),p.update({status:me.ready});return;case"estimation":const{rank:te,queue_size:re}=J;Ce(Pe,i=`On queue ${te}/${re}`,i);break;case"process_generating":Ce(Pe,i=J.success?"Generating":"Error",i);break;case"process_completed":try{const W=J.output.data[0];if(J.output.data[1])throw new Error("NFSW");const S=ka(m),C=await To(W),H=await Mo(C,E,S),U={prompt:E,imgURL:H,position:m,date:new Date().getTime(),id:wa()};s.set(S,U),console.log(H),Ce(Pe,i=J.success?"Complete":"Error",i),setTimeout(()=>{Ce(Pe,i="",i)},2e3),p.update({status:me.ready,currentPrompt:""})}catch(W){const v=W;Ce(Pe,i=v==null?void 0:v.message,i),p.update({status:me.ready})}B.close();return;case"process_starts":Ce(Pe,i="Processing",i);break}}catch(J){console.error(J),Ce(Pe,i="Error",i)}}}return e.$$.update=()=>{e.$$.dirty&1&&n(2,r=(o==null?void 0:o.status)===me.loading||!1)},[o,M,r,i,l,u,p,y,k,L,b,f]}class Oa extends ge{constructor(t){super(),ve(this,t,Ia,Ea,ye,{})}}function Yn(e){let t,n;return t=new zs({props:{client:e[1],$$slots:{default:[Sa]},$$scope:{ctx:e}}}),{c(){ie(t.$$.fragment)},l(r){se(t.$$.fragment,r)},m(r,i){oe(t,r,i),n=!0},p(r,i){const s={};i&2&&(s.client=r[1]),i&68&&(s.$$scope={dirty:i,ctx:r}),t.$set(s)},i(r){n||(R(t.$$.fragment,r),n=!0)},o(r){z(t.$$.fragment,r),n=!1},d(r){ae(t,r)}}}function La(e){let t,n,r,i,s,a;return{c(){t=j("div"),n=j("h1"),r=ue("No room selected"),i=Q(),s=j("p"),a=ue("Please select a room in the URL"),this.h()},l(o){t=V(o,"DIV",{class:!0});var l=O(t);n=V(l,"H1",{class:!0});var u=O(n);r=ce(u,"No room selected"),u.forEach(h),i=ee(l),s=V(l,"P",{class:!0});var p=O(s);a=ce(p,"Please select a room in the URL"),p.forEach(h),l.forEach(h),this.h()},h(){c(n,"class","text-2xl font-bold"),c(s,"class","text-gray-500"),c(t,"class","flex flex-col items-center justify-center h-full")},m(o,l){Z(o,t,l),w(t,n),w(n,r),w(t,i),w(t,s),w(s,a)},p:fe,i:fe,o:fe,d(o){o&&h(t)}}}function Ca(e){let t,n;return t=new Fs({props:{id:e[2],$$slots:{default:[Pa]},$$scope:{ctx:e}}}),{c(){ie(t.$$.fragment)},l(r){se(t.$$.fragment,r)},m(r,i){oe(t,r,i),n=!0},p(r,i){const s={};i&4&&(s.id=r[2]),i&64&&(s.$$scope={dirty:i,ctx:r}),t.$set(s)},i(r){n||(R(t.$$.fragment,r),n=!0)},o(r){z(t.$$.fragment,r),n=!1},d(r){ae(t,r)}}}function Pa(e){let t,n;return t=new Oa({}),{c(){ie(t.$$.fragment)},l(r){se(t.$$.fragment,r)},m(r,i){oe(t,r,i),n=!0},i(r){n||(R(t.$$.fragment,r),n=!0)},o(r){z(t.$$.fragment,r),n=!1},d(r){ae(t,r)}}}function Sa(e){let t,n,r,i;const s=[Ca,La],a=[];function o(l,u){return l[2]?0:1}return t=o(e),n=a[t]=s[t](e),{c(){n.c(),r=Me()},l(l){n.l(l),r=Me()},m(l,u){a[t].m(l,u),Z(l,r,u),i=!0},p(l,u){let p=t;t=o(l),t===p?a[t].p(l,u):(ke(),z(a[p],1,1,()=>{a[p]=null}),Ie(),n=a[t],n?n.p(l,u):(n=a[t]=s[t](l),n.c()),R(n,1),n.m(r.parentNode,r))},i(l){i||(R(n),i=!0)},o(l){z(n),i=!1},d(l){a[t].d(l),l&&h(r)}}}function Aa(e){let t,n,r=e[0]&&Yn(e);return{c(){r&&r.c(),t=Me()},l(i){r&&r.l(i),t=Me()},m(i,s){r&&r.m(i,s),Z(i,t,s),n=!0},p(i,[s]){i[0]?r?(r.p(i,s),s&1&&R(r,1)):(r=Yn(i),r.c(),R(r,1),r.m(t.parentNode,t)):r&&(ke(),z(r,1,1,()=>{r=null}),Ie())},i(i){n||(R(r),n=!0)},o(i){z(r),n=!1},d(i){r&&r.d(i),i&&h(t)}}}const Na=!0;function Ta(e,t,n){let r,i;Ee(e,Wt,u=>n(4,i=u));let{data:s}=t,a=s.rooms,o=!1,l;return st(()=>{n(1,l=Hs({authEndpoint:sn+"/auth"})),n(0,o=!0)}),e.$$set=u=>{"data"in u&&n(3,s=u.data)},e.$$.update=()=>{var u;e.$$.dirty&16&&n(2,r=(u=a.find(p=>p.id===i))==null?void 0:u.room_id),e.$$.dirty&16&&console.log("ROOM ID",i)},[o,l,r,s,i]}class Ua extends ge{constructor(t){super(),ve(this,t,Ta,Aa,ye,{data:3})}}export{Ua as default,Na as prerender};