import{H as tt,I as gn,S as ze,i as Fe,s as Ve,J as nt,K as it,m as x,h as U,n as E,b as oe,F as R,A as rt,G as xe,k as V,q as Ke,a as ce,l as J,r as He,c as de,L as st,u as bn,f as C,g as ge,t as $,d as be,M as On,N as wn,e as re,O as En,P as In,v as gt,w as bt,x as Ot,y as wt,o as kn}from"../../chunks/index-1f793c88.js";import{w as Je}from"../../chunks/index-b3d11e3e.js";const Pn=Je(!1),Sn=crypto.randomUUID(),Et=Je(JSON.parse(localStorage.user||JSON.stringify(Sn)));Et.subscribe(e=>localStorage.user=JSON.stringify(e));var Tn=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},K={},v={};Object.defineProperty(v,"__esModule",{value:!0});var An=Object.defineProperty,Ln=Object.defineProperties,Rn=Object.getOwnPropertyDescriptors,ve=Object.getOwnPropertySymbols,It=Object.prototype.hasOwnProperty,kt=Object.prototype.propertyIsEnumerable,ot=(e,t,n)=>t in e?An(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,he=(e,t)=>{for(var n in t||(t={}))It.call(t,n)&&ot(e,n,t[n]);if(ve)for(var n of ve(t))kt.call(t,n)&&ot(e,n,t[n]);return e},Oe=(e,t)=>Ln(e,Rn(t)),Un=(e,t)=>{var n={};for(var i in e)It.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(e!=null&&ve)for(var i of ve(e))t.indexOf(i)<0&&kt.call(e,i)&&(n[i]=e[i]);return n},Nn=(e,t,n)=>new Promise((i,s)=>{var r=c=>{try{a(n.next(c))}catch(u){s(u)}},l=c=>{try{a(n.throw(c))}catch(u){s(u)}},a=c=>c.done?i(c.value):Promise.resolve(c.value).then(r,l);a((n=n.apply(e,t)).next())});function Cn(e,t=e){}function Dn(e,t,n=t){}function Mn(e){}function xn(e,t){}function W(e,t){throw new Error(t)}function y(e,t="Expected value to be non-nullable"){return e}var Pt=(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))(Pt||{}),St=(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))(St||{}),Tt=(e=>(e[e.OBJECT=0]="OBJECT",e[e.LIST=1]="LIST",e[e.MAP=2]="MAP",e[e.REGISTER=3]="REGISTER",e))(Tt||{});function Kn(e){return e.type===0&&!At(e)}function At(e){return e.parentId!==void 0&&e.parentKey!==void 0}var Lt=(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))(Lt||{});function Hn(e){return e==="my-presence"||e==="others"||e==="event"||e==="error"||e==="connection"||e==="history"}var Rt=(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))(Rt||{}),te=32,Be=126;function F(e,t){return e!==void 0&&t!==void 0?ye(Ut(ae(e),ae(t))):e!==void 0?zn(e):t!==void 0?jn(t):ye([te+1])}function jn(e){const t=[],n=ae(e);for(let i=0;ir)throw new Error(`Impossible to generate position between ${e} and ${t}`);if(s===r){i.push(s),n++;continue}if(r-s===1){i.push(s),i.push(...Ut(e.slice(n+1),[]));break}const l=r+s>>1;i.push(l);break}return i}function ae(e){const t=[];for(let n=0;nb.parentId===this._id);I&&this._propToLastUpdate.set(c,y(I.opId)),t.push(...m)}else s[c]=u,this._propToLastUpdate.set(c,i);this._map.set(c,u),this.invalidate(),l[c]={type:"update"}}Object.keys(r.data).length!==0&&n.unshift(r),Object.keys(s).length!==0&&t.unshift({opId:i,id:this._id,type:3,data:s});const a=new Map;a.set(this._id,{node:this,type:"LiveObject",updates:l}),this._pool.dispatch(t,n,a)}toImmutable(){return super.toImmutable()}_toImmutable(){const e={};for(const[t,n]of this._map)e[t]=me(n)?n.toImmutable():n;return e}},$e=e=>e;function Fn(e){return e.filter(t=>t!=null)}function Vn(e){const t=he({},e);return Object.keys(e).forEach(n=>{const i=n;t[i]===void 0&&delete t[i]}),t}function ue(e){return se(Ct(e))}function Ct(e){switch(e.type){case 8:return e.data;case 4:return new q(e.data);case 7:return new X;case 2:return new Q;default:return W(e,"Unknown creation Op")}}function Dt(e,t){return e===t?!0:e.parent.type==="HasParent"?Dt(e.parent.node,t):!1}function Mt([e,t],n,i){switch(t.type){case 0:return q._deserialize([e,t],n,i);case 1:return Q._deserialize([e,t],n,i);case 2:return X._deserialize([e,t],n,i);case 3:return G._deserialize([e,t],n,i);default:throw new Error("Unexpected CRDT type")}}function Jn([e,t],n,i){switch(t.type){case 0:return q._deserialize([e,t],n,i);case 1:return Q._deserialize([e,t],n,i);case 2:return X._deserialize([e,t],n,i);case 3:return t.data;default:throw new Error("Unexpected CRDT type")}}function me(e){return xt(e)||Bn(e)||Kt(e)}function L(e){return me(e)||$n(e)}function xt(e){return e instanceof Q}function Bn(e){return e instanceof X}function Kt(e){return e instanceof q}function $n(e){return e instanceof G}function ee(e){return e instanceof G?e.data:e instanceof Q||e instanceof X||e instanceof q?e:W(e,"Unknown AbstractCrdt")}function se(e){return e instanceof q||e instanceof X||e instanceof Q?e:new G(e)}function Gn(e,t){const n=[];return e.forEach((i,s)=>{t.get(s)||n.push({type:5,id:s})}),t.forEach((i,s)=>{const r=e.get(s);if(r)i.type===0&&(r.type!==0||JSON.stringify(i.data)!==JSON.stringify(r.data))&&n.push({type:3,id:s,data:i.data}),i.parentKey!==r.parentKey&&n.push({type:1,id:s,parentKey:y(i.parentKey,"Parent key must not be missing")});else switch(i.type){case 3:n.push({type:8,id:s,parentId:i.parentId,parentKey:i.parentKey,data:i.data});break;case 1:n.push({type:2,id:s,parentId:i.parentId,parentKey:i.parentKey});break;case 0:n.push(i.parentId?{type:4,id:s,parentId:i.parentId,parentKey:i.parentKey,data:i.data}:{type:4,id:s,data:i.data});break;case 2:n.push({type:7,id:s,parentId:i.parentId,parentKey:i.parentKey});break}}),n}function Yn(e,t){const n=e.updates;for(const[i,s]of jt(t.updates))n[i]=s;return Oe(he({},t),{updates:n})}function Wn(e,t){const n=e.updates;for(const[i,s]of jt(t.updates))n[i]=s;return Oe(he({},t),{updates:n})}function Xn(e,t){const n=e.updates;return Oe(he({},t),{updates:n.concat(t.updates)})}function qn(e,t){return e?e.type==="LiveObject"&&t.type==="LiveObject"?Yn(e,t):e.type==="LiveMap"&&t.type==="LiveMap"?Wn(e,t):e.type==="LiveList"&&t.type==="LiveList"?Xn(e,t):t:t}function dt(e){const t=typeof e;return e==null||t==="string"||t==="boolean"||t==="number"||Array.isArray(e)||Ge(e)}function Ge(e){return e!==null&&typeof e=="object"&&Object.prototype.toString.call(e)==="[object Object]"}function Ht(e,t=""){if(!dt)return{path:t||"root",value:e};if(typeof e!="object"||e===null)return!1;for(const[n,i]of Object.entries(e)){const s=t?t+"."+n:n;if(!dt(i))return{path:s,value:i};if(typeof i=="object"){const r=Ht(i,s);if(r)return r}}return!1}function Qn(e){const t={};for(const[n,i]of e)t[n]=i;return t}function jt(e){return Object.entries(e)}function zt(e){try{return JSON.parse(e)}catch{return}}function Ft(e){try{const t=e.replace(/-/g,"+").replace(/_/g,"/");return decodeURIComponent(atob(t).split("").map(function(i){return"%"+("00"+i.charCodeAt(0).toString(16)).slice(-2)}).join(""))}catch{return atob(e)}}function Zn(e,t){return Nt(e._getParentKeyOrThrow(),t._getParentKeyOrThrow())}var Q=class extends we{constructor(e=[]){super(),this._items=[],this._implicitlyDeletedItems=new WeakSet,this._unacknowledgedSets=new Map;let 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,i=ue(e);i._attach(t,this._pool),i._setParentLink(this,n);const s=e.deletedId,r=this._indexOfPosition(n);if(r!==-1){const l=this._items[r];if(l._id===s)return l._detach(),this._items[r]=i,{modified:w(this,[ie(r,i)]),reverse:[]};{this._implicitlyDeletedItems.add(l),this._items[r]=i;const a=[ie(r,i)],c=this._detachItemAssociatedToSetOperation(e.deletedId);return c&&a.push(c),{modified:w(this,a),reverse:[]}}}else{const l=[],a=this._detachItemAssociatedToSetOperation(e.deletedId);return a&&l.push(a),this._insertAndSort(i),l.push(z(this._indexOfPosition(n),i)),{reverse:[],modified:w(this,l)}}}_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 i=this._unacknowledgedSets.get(e.parentKey);if(i!==void 0){if(i!==e.opId)return t.length===0?{modified:!1}:{modified:w(this,t),reverse:[]};this._unacknowledgedSets.delete(e.parentKey)}const s=this._indexOfPosition(e.parentKey),r=this._items.find(l=>l._id===e.id);if(r!==void 0){if(r._parentKey===e.parentKey)return{modified:t.length>0?w(this,t):!1,reverse:[]};s!==-1&&(this._implicitlyDeletedItems.add(this._items[s]),this._items.splice(s,1),t.push(_e(s)));const l=this._items.indexOf(r);r._setParentLink(this,e.parentKey),this._sortItems();const a=this._items.indexOf(r);return a!==l&&t.push(Z(l,a,r)),{modified:t.length>0?w(this,t):!1,reverse:[]}}else{const l=this._pool.getNode(e.id);if(l&&this._implicitlyDeletedItems.has(l)){l._setParentLink(this,e.parentKey),this._implicitlyDeletedItems.delete(l),this._insertAndSort(l);const a=this._items.indexOf(l);return{modified:w(this,[s===-1?z(a,l):ie(a,l),...t]),reverse:[]}}else{s!==-1&&this._items.splice(s,1);const{newItem:a,newIndex:c}=this._createAttachItemAndSort(e,e.parentKey);return{modified:w(this,[s===-1?z(c,a):ie(c,a),...t]),reverse:[]}}}}_detachItemAssociatedToSetOperation(e){if(e===void 0||this._pool===void 0)return null;const t=this._pool.getNode(e);if(t===void 0)return null;const n=this._detachChild(t);return n.modified===!1?null:n.modified.updates[0]}_applyRemoteInsert(e){if(this._pool===void 0)throw new Error("Can't attach child if managed pool is not present");const t=e.parentKey,n=this._indexOfPosition(t);n!==-1&&this._shiftItemPosition(n,t);const{newItem:i,newIndex:s}=this._createAttachItemAndSort(e,t);return{modified:w(this,[z(s,i)]),reverse:[]}}_applyInsertAck(e){const t=this._items.find(s=>s._id===e.id),n=e.parentKey,i=this._indexOfPosition(n);if(t){if(t._parentKey===n)return{modified:!1};{const s=this._items.indexOf(t);i!==-1&&this._shiftItemPosition(i,n),t._setParentLink(this,n),this._sortItems();const r=this._indexOfPosition(n);return r===s?{modified:!1}:{modified:w(this,[Z(s,r,t)]),reverse:[]}}}else{const s=y(this._pool).getNode(e.id);if(s&&this._implicitlyDeletedItems.has(s)){s._setParentLink(this,n),this._implicitlyDeletedItems.delete(s),this._insertAndSort(s);const r=this._indexOfPosition(n);return{modified:w(this,[z(r,s)]),reverse:[]}}else{i!==-1&&this._shiftItemPosition(i,n);const{newItem:r,newIndex:l}=this._createAttachItemAndSort(e,n);return{modified:w(this,[z(l,r)]),reverse:[]}}}}_applyInsertUndoRedo(e){var t;const{id:n,parentKey:i}=e,s=ue(e);if(((t=this._pool)==null?void 0:t.getNode(n))!==void 0)return{modified:!1};s._attach(n,y(this._pool)),s._setParentLink(this,i);const r=this._indexOfPosition(i);let l=i;if(r!==-1){const c=this._items[r]?this._items[r]._getParentKeyOrThrow():void 0,u=this._items[r+1]?this._items[r+1]._getParentKeyOrThrow():void 0;l=F(c,u),s._setParentLink(this,l)}this._insertAndSort(s);const a=this._indexOfPosition(l);return{modified:w(this,[z(a,s)]),reverse:[{type:5,id:n}]}}_applySetUndoRedo(e){var t;const{id:n,parentKey:i}=e,s=ue(e);if(((t=this._pool)==null?void 0:t.getNode(n))!==void 0)return{modified:!1};this._unacknowledgedSets.set(i,y(e.opId));const r=this._indexOfPosition(i);s._attach(n,y(this._pool)),s._setParentLink(this,i);const l=i;if(r!==-1){const a=this._items[r];a._detach(),this._items[r]=s;const c=a._toOps(y(this._id),i,this._pool);Ue(c,e.id);const u=[ie(r,s)],g=this._detachItemAssociatedToSetOperation(e.deletedId);return g&&u.push(g),{modified:w(this,u),reverse:c}}else{this._insertAndSort(s),this._detachItemAssociatedToSetOperation(e.deletedId);const a=this._indexOfPosition(l);return{reverse:[{type:5,id:n}],modified:w(this,[z(a,s)])}}}_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=y(e._parentKey),n=e._toOps(y(this._id),t,this._pool),i=this._items.indexOf(e);return i===-1?{modified:!1}:(this._items.splice(i,1),this.invalidate(),e._detach(),{modified:w(this,[_e(i)]),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 r=this._items.indexOf(t);return{modified:w(this,[z(r,t)]),reverse:[]}}const i=t._parentKey;if(e===i)return{modified:!1};const s=this._indexOfPosition(e);if(s===-1){const r=this._items.indexOf(t);t._setParentLink(this,e),this._sortItems();const l=this._items.indexOf(t);return l===r?{modified:!1}:{modified:w(this,[Z(r,l,t)]),reverse:[]}}else{this._items[s]._setParentLink(this,F(e,(n=this._items[s+1])==null?void 0:n._getParentKeyOrThrow()));const r=this._items.indexOf(t);t._setParentLink(this,e),this._sortItems();const l=this._items.indexOf(t);return l===r?{modified:!1}:{modified:w(this,[Z(r,l,t)]),reverse:[]}}}_applySetChildKeyAck(e,t){var n,i;const s=y(t._parentKey);if(this._implicitlyDeletedItems.has(t)){const r=this._indexOfPosition(e);return this._implicitlyDeletedItems.delete(t),r!==-1&&this._items[r]._setParentLink(this,F(e,(n=this._items[r+1])==null?void 0:n._getParentKeyOrThrow())),t._setParentLink(this,e),this._insertAndSort(t),{modified:!1}}else{if(e===s)return{modified:!1};const r=this._items.indexOf(t),l=this._indexOfPosition(e);l!==-1&&this._items[l]._setParentLink(this,F(e,(i=this._items[l+1])==null?void 0:i._getParentKeyOrThrow())),t._setParentLink(this,e),this._sortItems();const a=this._items.indexOf(t);return r===a?{modified:!1}:{modified:w(this,[Z(r,a,t)]),reverse:[]}}}_applySetChildKeyUndoRedo(e,t){var n;const i=y(t._parentKey),s=this._items.indexOf(t),r=this._indexOfPosition(e);r!==-1&&this._items[r]._setParentLink(this,F(e,(n=this._items[r+1])==null?void 0:n._getParentKeyOrThrow())),t._setParentLink(this,e),this._sortItems();const l=this._items.indexOf(t);return s===l?{modified:!1}:{modified:w(this,[Z(s,l,t)]),reverse:[{type:1,id:y(t._id),parentKey:i}]}}_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:y(this.parent.node._id,"Parent node expected to have ID"),parentKey:this.parent.key}}get length(){return this._items.length}push(e){return this.insert(e,this.length)}insert(e,t){if(t<0||t>this._items.length)throw new Error(`Cannot insert list item at index "${t}". index should be between 0 and ${this._items.length}`);const n=this._items[t-1]?this._items[t-1]._getParentKeyOrThrow():void 0,i=this._items[t]?this._items[t]._getParentKeyOrThrow():void 0,s=F(n,i),r=se(e);if(r._setParentLink(this,s),this._insertAndSort(r),this._pool&&this._id){const l=this._pool.generateId();r._attach(l,this._pool),this._pool.dispatch(r._toOps(this._id,s,this._pool),[{type:5,id:l}],new Map([[this._id,w(this,[z(t,r)])]]))}}move(e,t){if(t<0)throw new Error("targetIndex cannot be less than 0");if(t>=this._items.length)throw new Error("targetIndex cannot be greater or equal than the list length");if(e<0)throw new Error("index cannot be less than 0");if(e>=this._items.length)throw new Error("index cannot be greater or equal than the list length");let n=null,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 t=this._items[e];if(t._detach(),this._items.splice(e,1),this.invalidate(),this._pool){const n=t._id;if(n){const i=new Map;i.set(y(this._id),w(this,[_e(e)])),this._pool.dispatch([{id:n,opId:this._pool.generateOpId(),type:5}],t._toOps(y(this._id),t._getParentKeyOrThrow()),i)}}}clear(){if(this._pool){const e=[],t=[],n=[];for(const s of this._items){s._detach();const r=s._id;r&&(e.push({type:5,id:r,opId:this._pool.generateOpId()}),t.push(...s._toOps(y(this._id),s._getParentKeyOrThrow())),n.push(_e(0)))}this._items=[],this.invalidate();const i=new Map;i.set(y(this._id),w(this,n)),this._pool.dispatch(e,t,i)}else{for(const e of this._items)e._detach();this._items=[],this.invalidate()}}set(e,t){if(e<0||e>=this._items.length)throw new Error(`Cannot set list item at index "${e}". index should be between 0 and ${this._items.length-1}`);const n=this._items[e],i=n._getParentKeyOrThrow(),s=n._id;n._detach();const r=se(t);if(r._setParentLink(this,i),this._items[e]=r,this.invalidate(),this._pool&&this._id){const l=this._pool.generateId();r._attach(l,this._pool);const a=new Map;a.set(this._id,w(this,[ie(e,r)]));const c=r._toOps(this._id,i,this._pool);Ue(c,s),this._unacknowledgedSets.set(i,y(c[0].opId));const u=n._toOps(this._id,i,void 0);Ue(u,l),this._pool.dispatch(c,u,a)}}toArray(){return this._items.map(e=>ee(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 ee(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(ee(t),n))}some(e){return this.toArray().some(e)}[Symbol.iterator](){return new ei(this._items)}_createAttachItemAndSort(e,t){const n=ue(e);n._attach(e.id,y(this._pool)),n._setParentLink(this,t),this._insertAndSort(n);const i=this._indexOfPosition(t);return{newItem:n,newIndex:i}}_shiftItemPosition(e,t){var n;const i=F(t,this._items.length>e+1?(n=this._items[e+1])==null?void 0:n._getParentKeyOrThrow():void 0);this._items[e]._setParentLink(this,i)}toImmutable(){return super.toImmutable()}_toImmutable(){return this._items.map(t=>t.toImmutable())}},ei=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:ee(e.value)}}};function w(e,t){return{node:e,type:"LiveList",updates:t}}function ie(e,t){return{index:e,type:"set",item:t instanceof G?t.data:t}}function _e(e){return{index:e,type:"delete"}}function z(e,t){return{index:e,type:"insert",item:t instanceof G?t.data:t}}function Z(e,t,n){return{index:t,type:"move",previousIndex:e,item:n instanceof G?n.data:n}}function Ue(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 ti=["websocket:presence","websocket:storage","room:read","room:write","rooms:read","rooms:write"];function ni(e){if(!Ge(e))return!1;const{iat:t,exp:n}=e;return typeof t=="number"&&typeof n=="number"}function ii(e){const t=Date.now()/1e3;return t>e.exp-300||ttypeof t=="string")}function Jt(e){return typeof e.appId=="string"&&e.roomId===void 0&&Vt(e.scopes)}function Ye(e){return typeof e.appId=="string"&&typeof e.roomId=="string"&&typeof e.actor=="number"&&(e.id===void 0||typeof e.id=="string")&&Vt(e.scopes)&&(e.maxConnectionsPerRoom===void 0||typeof e.maxConnectionsPerRoom=="number")}function si(e){return Jt(e)||Ye(e)}function oi(e){const t=e.split(".");if(t.length!==3)throw new Error("Authentication error: invalid JWT token");const n=zt(Ft(t[1]));if(n&&ni(n))return n;throw new Error("Authentication error: missing JWT metadata")}function ai(e){const t=oi(e);if(t&&Ye(t))return Un(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 li(e){return Object.defineProperty(e,"count",{value:e.length,enumerable:!1}),Object.defineProperty(e,"toArray",{value:()=>e,enumerable:!1}),$e(e)}function Bt(e){return e===null||typeof e=="string"||typeof e=="number"||typeof e=="boolean"}function $t(e){return Array.isArray(e)}function ci(e){return!Bt(e)&&!$t(e)}v.__spreadValues=he;v.__spreadProps=Oe;v.__async=Nn;v.deprecate=Cn;v.deprecateIf=Dn;v.throwUsageError=Mn;v.errorIf=xn;v.assertNever=W;v.nn=y;v.ClientMsgCode=Pt;v.OpCode=St;v.CrdtType=Tt;v.isRootCrdt=Kn;v.isChildCrdt=At;v.ServerMsgCode=Lt;v.isRoomEventName=Hn;v.WebsocketCloseCodes=Rt;v.LiveRegister=G;v.makePosition=F;v.comparePosition=Nt;v.LiveList=Q;v.LiveMap=X;v.LiveObject=q;v.freeze=$e;v.compact=Fn;v.compactObject=Vn;v.isSameNodeOrChildOf=Dt;v.isLiveNode=L;v.isLiveList=xt;v.isLiveObject=Kt;v.getTreesDiffOperations=Gn;v.mergeStorageUpdates=qn;v.isPlainObject=Ge;v.findNonSerializableValue=Ht;v.tryParseJson=zt;v.b64decode=Ft;v.isTokenExpired=ii;v.isScope=ri;v.isAppOnlyAuthToken=Jt;v.isRoomAuthToken=Ye;v.isAuthToken=si;v.parseRoomAuthToken=ai;v.asArrayWithLegacyMethods=li;v.isJsonScalar=Bt;v.isJsonArray=$t;v.isJsonObject=ci;Object.defineProperty(K,"__esModule",{value:!0});var _=v;function B(){const e=new Set,t=new Set;function n(l){return t.add(l),()=>t.delete(l)}function i(l){return e.add(l),()=>e.delete(l)}function s(l){e.forEach(a=>a(l)),e.clear(),t.forEach(a=>a(l))}function r(){e.clear(),t.clear()}return{notify:s,subscribe:n,subscribeOnce:i,clear:r,observable:{subscribe:n,subscribeOnce:i}}}function Gt(e,t){let n=!1;const i=_.__spreadValues.call(void 0,{},e);return Object.keys(t).forEach(s=>{const r=s,l=t[r];i[r]!==l&&(l===void 0?delete i[r]:i[r]=l,n=!0)}),n?i:e}var Ee=class{constructor(){this._ev=B()}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()}},di=class extends Ee{constructor(e){super(),this._me=_.freeze.call(void 0,_.compactObject.call(void 0,e))}_toImmutable(){return this._me}patch(e){const t=this._me,n=Gt(t,e);t!==n&&(this._me=_.freeze.call(void 0,n),this.invalidate())}};function ui(e,t){return _.freeze.call(void 0,_.compactObject.call(void 0,_.__spreadProps.call(void 0,_.__spreadValues.call(void 0,{},e),{presence:t})))}var hi=class extends Ee{constructor(){super(),this._connections={},this._presences={},this._users={}}_toImmutable(){const e=_.compact.call(void 0,Object.keys(this._presences).map(t=>this.getUser(Number(t))));return _.asArrayWithLegacyMethods.call(void 0,e)}clearOthers(){this._connections={},this._presences={},this._users={},this.invalidate()}_getUser(e){const t=this._connections[e],n=this._presences[e];if(t!==void 0&&n!==void 0)return ui(t,n)}getUser(e){const t=this._users[e];if(t)return t;const n=this._getUser(e);if(n)return this._users[e]=n,n}_invalidateUser(e){this._users[e]!==void 0&&delete this._users[e],this.invalidate()}setConnection(e,t,n){this._connections[e]=_.freeze.call(void 0,{connectionId:e,id:t,info:n}),this._presences[e]!==void 0&&this._invalidateUser(e)}removeConnection(e){delete this._connections[e],delete this._presences[e],this._invalidateUser(e)}setOther(e,t){this._presences[e]=_.freeze.call(void 0,_.compactObject.call(void 0,t)),this._connections[e]!==void 0&&this._invalidateUser(e)}patchOther(e,t){const n=this._presences[e];if(n===void 0)return;const i=Gt(n,t);n!==i&&(this._presences[e]=_.freeze.call(void 0,i),this._invalidateUser(e))}},fi=class extends Ee{constructor(e){super(),this._value=_.freeze.call(void 0,_.compactObject.call(void 0,e))}_toImmutable(){return this._value}set(e){this._value=_.freeze.call(void 0,e),this.invalidate()}},pi=class extends Ee{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)}},Ne=[250,500,1e3,2e3,4e3,8e3,1e4],Ce=[2e3,3e4,6e4,3e5],_i=3e4,mi=2e3;function vi(e){let t=0;return()=>`${e}:${t++}`}function De(e){return e.state==="open"||e.state==="connecting"}function yi(e,t,n){const i={roomId:t.roomId,getNode:o=>e.nodes.get(o),addNode:(o,d)=>void e.nodes.set(o,d),deleteNode:o=>void e.nodes.delete(o),generateId:()=>`${N()}:${e.clock++}`,generateOpId:()=>`${N()}:${e.opClock++}`,dispatch(o,d,h){const f=e.activeBatch;f?(f.ops.push(...o),h.forEach((p,S)=>{f.updates.storageUpdates.set(S,_.mergeStorageUpdates.call(void 0,f.updates.storageUpdates.get(S),p))}),f.reverseOps.push(...d)):(I(d),e.redoStack=[],qe(o),b({storageUpdates:h}))}},s={customEvent:B(),me:B(),others:B(),error:B(),connection:B(),storage:B(),history:B(),storageDidLoad:B()},r=n||{authenticate(o,d){const h=e.token,f=h!==null&&_.parseRoomAuthToken.call(void 0,h);if(f&&!_.isTokenExpired.call(void 0,f)){const p=d(h);ne(f,p)}else return o(t.roomId).then(({token:p})=>{if(e.connection.current.state!=="authenticating")return;const S=_.parseRoomAuthToken.call(void 0,p),k=d(p);ne(S,k),e.token=p}).catch(p=>Yt())},send(o){if(e.socket===null)throw new Error("Can't send message if socket is null");e.socket.send(JSON.stringify(o))},delayFlush(o){return setTimeout(M,o)},startHeartbeatInterval(){return setInterval(Te,_i)},schedulePongTimeout(){return setTimeout(nn,mi)},scheduleReconnect(o){return setTimeout(H,o)}},l=new pi([e.connection,e.me],(o,d)=>De(o)?{connectionId:o.id,id:o.userId,info:o.userInfo,presence:d}:null);function a(o){if(o.items.length===0)throw new Error("Internal error: cannot load storage without items");e.root?u(o.items):e.root=g(o.items);for(const d in e.initialStorage)e.root.get(d)===void 0&&e.root.set(d,e.initialStorage[d])}function c(o){const d=new Map;let h=null;for(const[f,p]of o)if(_.isRootCrdt.call(void 0,p))h=[f,p];else{const S=[f,p],k=d.get(p.parentId);k!==void 0?k.push(S):d.set(p.parentId,[S])}if(h===null)throw new Error("Root can't be null");return[h,d]}function u(o){if(!e.root)return;const d=new Map;e.nodes.forEach((p,S)=>{d.set(S,p._serialize())});const h=_.getTreesDiffOperations.call(void 0,d,new Map(o)),f=A(h,!1);b(f.updates)}function g(o){const[d,h]=c(o);return _.LiveObject._deserialize(d,h,i)}function m(o){e.undoStack.length>=50&&e.undoStack.shift(),e.undoStack.push(o),Ie()}function I(o){e.pausedHistory!==null?e.pausedHistory.unshift(...o):m(o)}function b({storageUpdates:o=new Map,presence:d=!1,others:h=[]}){if(h.length>0){const f=e.others.current;for(const p of h)s.others.notify({others:f,event:p})}if(d&&s.me.notify(e.me.current),o.size>0){const f=Array.from(o.values());s.storage.notify(f)}}function N(){const o=e.connection.current;if(De(o))return o.id;if(e.lastConnectionId!==null)return e.lastConnectionId;throw new Error("Internal. Tried to get connection id but connection was never open")}function A(o,d){const h={reverse:[],updates:{storageUpdates:new Map,presence:!1}},f=new Set;for(const p of o)if(p.type==="presence"){const S={type:"presence",data:{}};for(const k in p.data)S.data[k]=e.me.current[k];if(e.me.patch(p.data),e.buffer.me===null)e.buffer.me={type:"partial",data:p.data};else for(const k in p.data)e.buffer.me.data[k]=p.data[k];h.reverse.unshift(S),h.updates.presence=!0}else{let S;p.opId||(p.opId=i.generateOpId()),d?S=0:S=e.offlineOperations.delete(_.nn.call(void 0,p.opId))?2:1;const k=O(p,S);if(k.modified){const Re=k.modified.node.parent.type==="HasParent"?_.nn.call(void 0,k.modified.node.parent.node._id,"Expected parent node to have an ID"):void 0;(!Re||!f.has(Re))&&(h.updates.storageUpdates.set(_.nn.call(void 0,k.modified.node._id),_.mergeStorageUpdates.call(void 0,h.updates.storageUpdates.get(_.nn.call(void 0,k.modified.node._id)),k.modified)),h.reverse.unshift(...k.reverse)),(p.type===2||p.type===7||p.type===4)&&f.add(_.nn.call(void 0,k.modified.node._id))}}return h}function O(o,d){switch(o.type){case 6:case 3:case 5:{const h=e.nodes.get(o.id);return h===void 0?{modified:!1}:h._apply(o,d===0)}case 1:{const h=e.nodes.get(o.id);return h===void 0?{modified:!1}:h.parent.type==="HasParent"&&_.isLiveList.call(void 0,h.parent.node)?h.parent.node._setChildKey(o.parentKey,h,d):{modified:!1}}case 4:case 2:case 7:case 8:{if(o.parentId===void 0)return{modified:!1};const h=e.nodes.get(o.parentId);return h===void 0?{modified:!1}:h._attachChild(o,d)}}}function P(o,d){return s.storage.subscribe(h=>{const f=h.filter(p=>_.isSameNodeOrChildOf.call(void 0,p.node,o));f.length>0&&d(f)})}function T(o,d){return s.storage.subscribe(h=>{for(const f of h)f.node._id===o._id&&d(f.node)})}function D(o,d,h){if(typeof o=="string"&&_.isRoomEventName.call(void 0,o)){if(typeof d!="function")throw new Error("Second argument must be a callback function");const f=d;switch(o){case"event":return s.customEvent.subscribe(f);case"my-presence":return s.me.subscribe(f);case"others":{const p=f;return s.others.subscribe(({others:S,event:k})=>p(S,k))}case"error":return s.error.subscribe(f);case"connection":return s.connection.subscribe(f);case"storage":return s.storage.subscribe(f);case"history":return s.history.subscribe(f);default:return _.assertNever.call(void 0,o,"Unknown event")}}if(d===void 0||typeof o=="function")if(typeof o=="function"){const f=o;return s.storage.subscribe(f)}else throw new Error("Please specify a listener callback");if(_.isLiveNode.call(void 0,o)){const f=o;return h!=null&&h.isDeep?P(f,d):T(f,d)}throw new Error(`"${o}" is not a valid event name`)}function Y(){return e.connection.current.state}function H(){var o,d,h,f;if(e.connection.current.state!=="closed"&&e.connection.current.state!=="unavailable")return null;const p=Ei(t.authentication,(d=(o=t.polyfills)==null?void 0:o.fetch)!=null?d:t.fetchPolyfill),S=wi(t.liveblocksServer,(f=(h=t.polyfills)==null?void 0:h.WebSocket)!=null?f:t.WebSocketPolyfill);j({state:"authenticating"}),r.authenticate(p,S)}function fe(o,d){const h={};e.buffer.me===null&&(e.buffer.me={type:"partial",data:{}});for(const f in o){const p=o[f];p!==void 0&&(e.buffer.me.data[f]=p,h[f]=e.me.current[f])}e.me.patch(o),e.activeBatch?(d!=null&&d.addToHistory&&e.activeBatch.reverseOps.push({type:"presence",data:h}),e.activeBatch.updates.presence=!0):(M(),d!=null&&d.addToHistory&&I([{type:"presence",data:h}]),b({presence:!0}))}function ne(o,d){d.addEventListener("message",pe),d.addEventListener("open",Se),d.addEventListener("close",le),d.addEventListener("error",Pe),j({state:"connecting",id:o.actor,userInfo:o.info,userId:o.id}),e.idFactory=vi(o.actor),e.socket=d}function Yt(o){e.token=null,j({state:"unavailable"}),e.numberOfRetry++,e.timeoutHandles.reconnect=r.scheduleReconnect(ke())}function Wt(o){o==="visible"&&e.connection.current.state==="open"&&Te()}function Xt(o){if(o.targetActor!==void 0){const h=e.others.getUser(o.actor);e.others.setOther(o.actor,o.data);const f=e.others.getUser(o.actor);if(h===void 0&&f!==void 0)return{type:"enter",user:f}}else e.others.patchOther(o.actor,o.data);const d=e.others.getUser(o.actor);if(d)return{type:"update",updates:o.data,user:d}}function qt(o){const d=e.others.getUser(o.actor);return d?(e.others.removeConnection(o.actor),{type:"leave",user:d}):null}function Qt(o){for(const d in o.users){const h=o.users[d],f=Number(d);e.others.setConnection(f,h.id,h.info)}return{type:"reset"}}function Zt(){e.connection.current.state==="unavailable"&&Xe()}function Ie(){s.history.notify({canUndo:Ze(),canRedo:et()})}function en(o){e.others.setConnection(o.actor,o.id,o.info),e.buffer.messages.push({type:100,data:e.me.current,targetActor:o.actor}),M();const d=e.others.getUser(o.actor);return d?{type:"enter",user:d}:void 0}function We(o){return _.isJsonObject.call(void 0,o)?o:null}function tn(o){const d=_.tryParseJson.call(void 0,o);return d===void 0?null:_.isJsonArray.call(void 0,d)?_.compact.call(void 0,d.map(h=>We(h))):_.compact.call(void 0,[We(d)])}function pe(o){if(o.data==="pong"){clearTimeout(e.timeoutHandles.pongTimeout);return}const d=tn(o.data);if(d===null||d.length===0)return;const h={storageUpdates:new Map,others:[]};for(const f of d)switch(f.type){case 101:{const p=en(f);p&&h.others.push(p);break}case 100:{const p=Xt(f);p&&h.others.push(p);break}case 103:{s.customEvent.notify({connectionId:f.actor,event:f.event});break}case 102:{const p=qt(f);p&&h.others.push(p);break}case 104:{h.others.push(Qt(f));break}case 200:{const p=new Map(e.offlineOperations);a(f),rn(p),Le==null||Le(),s.storageDidLoad.notify();break}case 201:{A(f.ops,!1).updates.storageUpdates.forEach((S,k)=>{h.storageUpdates.set(k,_.mergeStorageUpdates.call(void 0,h.storageUpdates.get(k),S))});break}}b(h)}function le(o){if(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(),b({others:[{type:"reset"}]}),o.code>=4e3&&o.code<=4100){j({state:"failed"});const d=new Oi(o.reason,o.code);s.error.notify(d);const h=ke(!0);e.numberOfRetry++,j({state:"unavailable"}),e.timeoutHandles.reconnect=r.scheduleReconnect(h)}else if(o.code===4999)j({state:"closed"});else{const d=ke();e.numberOfRetry++,j({state:"unavailable"}),e.timeoutHandles.reconnect=r.scheduleReconnect(d)}}function j(o){e.connection.set(o),s.connection.notify(o.state)}function ke(o=!1){return o?Ce[e.numberOfRetry0&&o.forEach(f=>{e.offlineOperations.set(_.nn.call(void 0,f.opId),f)}),e.socket===null||e.socket.readyState!==e.socket.OPEN){e.buffer.storageOperations=[];return}const d=Date.now();if(d-e.lastFlushTime>t.throttleDelay){const f=sn(e);if(f.length===0)return;r.send(f),e.buffer={messages:[],storageOperations:[],me:null},e.lastFlushTime=d}else e.timeoutHandles.flush!==null&&clearTimeout(e.timeoutHandles.flush),e.timeoutHandles.flush=r.delayFlush(t.throttleDelay-(d-e.lastFlushTime))}function sn(o){const d=[];o.buffer.me&&d.push(o.buffer.me.type==="full"?{type:100,targetActor:-1,data:o.buffer.me.data}:{type:100,data:o.buffer.me.data});for(const h of o.buffer.messages)d.push(h);return o.buffer.storageOperations.length>0&&d.push({type:201,ops:o.buffer.storageOperations}),d}function on(){e.socket&&(e.socket.removeEventListener("open",Se),e.socket.removeEventListener("message",pe),e.socket.removeEventListener("close",le),e.socket.removeEventListener("error",Pe),e.socket.close(),e.socket=null),j({state:"closed"}),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"}]}),Object.values(s).forEach(o=>o.clear())}function an(){return e.me.current}function ln(){return e.others.current}function cn(o,d={shouldQueueEventIfNotReady:!1}){e.socket===null&&!d.shouldQueueEventIfNotReady||(e.buffer.messages.push({type:103,event:o}),M())}function qe(o){e.buffer.storageOperations.push(...o),M()}let Ae=null,Le=null;function Qe(){return Ae===null&&(e.buffer.messages.push({type:200}),M(),Ae=new Promise(o=>Le=o)),Ae}function dn(){const o=e.root;return o!==void 0?o:(Qe(),null)}function un(){return _.__async.call(void 0,this,null,function*(){return e.root?Promise.resolve({root:e.root}):(yield Qe(),{root:_.nn.call(void 0,e.root)})})}function hn(){if(e.activeBatch)throw new Error("undo is not allowed during a batch");const o=e.undoStack.pop();if(o===void 0)return;e.pausedHistory=null;const d=A(o,!0);b(d.updates),e.redoStack.push(d.reverse),Ie();for(const h of o)h.type!=="presence"&&e.buffer.storageOperations.push(h);M()}function Ze(){return e.undoStack.length>0}function fn(){if(e.activeBatch)throw new Error("redo is not allowed during a batch");const o=e.redoStack.pop();if(o===void 0)return;e.pausedHistory=null;const d=A(o,!0);b(d.updates),e.undoStack.push(d.reverse),Ie();for(const h of o)h.type!=="presence"&&e.buffer.storageOperations.push(h);M()}function et(){return e.redoStack.length>0}function pn(o){if(e.activeBatch)return o();e.activeBatch={ops:[],updates:{storageUpdates:new Map,presence:!1,others:[]},reverseOps:[]};try{return o()}finally{const d=e.activeBatch;e.activeBatch=null,d.reverseOps.length>0&&I(d.reverseOps),d.ops.length>0&&(e.redoStack=[]),d.ops.length>0&&qe(d.ops),b(d.updates),M()}}function _n(){e.pausedHistory=[]}function mn(){const o=e.pausedHistory;e.pausedHistory=null,o!==null&&o.length>0&&m(o)}function vn(){e.socket&&(e.socket=null)}function yn(o){le(o)}return{onClose:le,onMessage:pe,authenticationSuccess:ne,heartbeat:Te,onNavigatorOnline:Zt,simulateSocketClose:vn,simulateSendCloseEvent:yn,onVisibilityChange:Wt,getUndoStack:()=>e.undoStack,getItemsCount:()=>e.nodes.size,connect:H,disconnect:on,subscribe:D,updatePresence:fe,broadcastEvent:cn,batch:pn,undo:hn,redo:fn,canUndo:Ze,canRedo:et,pauseHistory:_n,resumeHistory:mn,getStorage:un,getStorageSnapshot:dn,events:{customEvent:s.customEvent.observable,others:s.others.observable,me:s.me.observable,error:s.error.observable,connection:s.connection.observable,storage:s.storage.observable,history:s.history.observable,storageDidLoad:s.storageDidLoad.observable},getConnectionState:Y,isSelfAware:()=>De(e.connection.current),getSelf:()=>l.current,getPresence:an,getOthers:ln}}function gi(e,t){const n=new hi,i=new fi({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:i,me:new di(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 bi(e,t){const{initialPresence:n,initialStorage:i}=e,s=gi(typeof n=="function"?n(t.roomId):n,typeof i=="function"?i(t.roomId):i),r=yi(s,t),l={id:t.roomId,getConnectionState:r.getConnectionState,isSelfAware:r.isSelfAware,getSelf:r.getSelf,subscribe:r.subscribe,getPresence:r.getPresence,updatePresence:r.updatePresence,getOthers:r.getOthers,broadcastEvent:r.broadcastEvent,getStorage:r.getStorage,getStorageSnapshot:r.getStorageSnapshot,events:r.events,batch:r.batch,history:{undo:r.undo,redo:r.redo,canUndo:r.canUndo,canRedo:r.canRedo,pause:r.pauseHistory,resume:r.resumeHistory},__INTERNAL_DO_NOT_USE:{simulateCloseWebsocket:r.simulateSocketClose,simulateSendCloseEvent:r.simulateSendCloseEvent}};return{connect:r.connect,disconnect:r.disconnect,onNavigatorOnline:r.onNavigatorOnline,onVisibilityChange:r.onVisibilityChange,room:l}}var Oi=class extends Error{constructor(e,t){super(e),this.code=t}};function wi(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 i=>new n(`${e}/?token=${i}&version=0.18.2`)}function Ei(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=>ut(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=>ut(t||fetch,e.url,{room:n})}if(e.type==="custom")return n=>_.__async.call(void 0,this,null,function*(){const i=yield e.callback(n);if(!i||!i.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 i});throw new Error("Internal error. Unexpected authentication type")}function ut(e,t,n){return _.__async.call(void 0,this,null,function*(){const i=yield e(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!i.ok)throw new Me(`Expected a status 200 but got ${i.status} when doing a POST request on "${t}"`);let s;try{s=yield i.json()}catch(l){throw new Me(`Expected a JSON response when doing a POST request on "${t}". ${l}`)}if(!_.isPlainObject.call(void 0,s)||typeof s.token!="string")throw new Me(`Expected a JSON response of the form \`{ token: "..." }\` when doing a POST request on "${t}", but got ${JSON.stringify(s)}`);const{token:r}=s;return{token:r}})}var Me=class extends Error{constructor(e){super(e)}};function Ii(e){const t=e,n=ki(e),i=new Map;function s(a){const c=i.get(a);return c?c.room:null}function r(a,c){var u,g;let m=i.get(a);if(m)return m.room;if(_.deprecateIf.call(void 0,c.initialPresence===null||c.initialPresence===void 0,"Please provide an initial presence value for the current user when entering the room."),m=bi({initialPresence:(u=c.initialPresence)!=null?u:{},initialStorage:c.initialStorage},{roomId:a,throttleDelay:n,polyfills:t.polyfills,WebSocketPolyfill:t.WebSocketPolyfill,fetchPolyfill:t.fetchPolyfill,liveblocksServer:(t==null?void 0:t.liveblocksServer)||"wss://api.liveblocks.io/v6",authentication:Pi(t,a)}),i.set(a,m),!c.DO_NOT_USE_withoutConnecting){if(typeof atob>"u"){if(((g=t.polyfills)==null?void 0:g.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");Tn.atob=t.polyfills.atob}m.connect()}return m.room}function l(a){const c=i.get(a);c&&(c.disconnect(),i.delete(a))}return typeof window<"u"&&typeof window.addEventListener<"u"&&window.addEventListener("online",()=>{for(const[,a]of i)a.onNavigatorOnline()}),typeof document<"u"&&document.addEventListener("visibilitychange",()=>{for(const[,a]of i)a.onVisibilityChange(document.visibilityState)}),{getRoom:s,enter:r,leave:l}}function ki(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 Pi(e,t){const{publicApiKey:n,authEndpoint:i}=e;if(i!==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:Si(e,t)}}if(typeof i=="string")return{type:"private",url:i};if(typeof i=="function")return{type:"custom",callback:i};throw i!==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 Si(e,t){return e.publicAuthorizeEndpoint?e.publicAuthorizeEndpoint.replace("{roomId}",t):`https://api.liveblocks.io/v2/rooms/${encodeURIComponent(t)}/public/authorize`}function Ti(e,t){if(e.length!==t.length)return!1;for(let n=0;nObject.prototype.hasOwnProperty.call(t,i)&&Object.is(e[i],t[i]))}function Li(e,t){if(Object.is(e,t))return!0;const n=Array.isArray(e),i=Array.isArray(t);return n||i?!n||!i?!1:Ti(e,t):Ai(e,t)}K.LiveList=_.LiveList;K.LiveMap=_.LiveMap;K.LiveObject=_.LiveObject;K.createClient=Ii;K.shallow=Li;K.LiveList;K.LiveMap;K.LiveObject;const Ri=K.createClient;K.shallow;function ht(e){return Object.prototype.toString.call(e)==="[object Date]"}function je(e,t,n,i){if(typeof n=="number"||ht(n)){const s=i-n,r=(n-t)/(e.dt||1/60),l=e.opts.stiffness*s,a=e.opts.damping*r,c=(l-a)*e.inv_mass,u=(r+c)*e.dt;return Math.abs(u)je(e,t[r],n[r],i[r]));if(typeof n=="object"){const s={};for(const r in n)s[r]=je(e,t[r],n[r],i[r]);return s}else throw new Error(`Cannot spring ${typeof n} values`)}}function Ui(e,t={}){const n=Je(e),{stiffness:i=.15,damping:s=.8,precision:r=.01}=t;let l,a,c,u=e,g=e,m=1,I=0,b=!1;function N(O,P={}){g=O;const T=c={};if(e==null||P.hard||A.stiffness>=1&&A.damping>=1)return b=!0,l=tt(),u=O,n.set(e=g),Promise.resolve();if(P.soft){const D=P.soft===!0?.5:+P.soft;I=1/(D*60),m=0}return a||(l=tt(),b=!1,a=gn(D=>{if(b)return b=!1,a=null,!1;m=Math.min(m+I,1);const Y={inv_mass:m,opts:A,settled:!0,dt:(D-l)*60/1e3},H=je(Y,u,e,g);return l=D,u=e,n.set(e=H),Y.settled&&(a=null),!Y.settled})),new Promise(D=>{a.promise.then(()=>{T===c&&D()})})}const A={set:N,update:(O,P)=>N(O(g,e),P),subscribe:n.subscribe,stiffness:i,damping:s,precision:r};return A}function Ni(e){let t,n,i;return{c(){t=nt("svg"),n=nt("path"),this.h()},l(s){t=it(s,"svg",{class:!0,fill:!0,height:!0,style:!0,viewBox:!0,width:!0,xmlns:!0});var r=x(t);n=it(r,"path",{d:!0,fill:!0}),x(n).forEach(U),r.forEach(U),this.h()},h(){E(n,"d","M5.65376 12.3673H5.46026L5.31717 12.4976L0.500002 16.8829L0.500002 1.19841L11.7841 12.3673H5.65376Z"),E(n,"fill",e[0]),E(t,"class","cursor svelte-141kyoc"),E(t,"fill","none"),E(t,"height","36"),E(t,"style",i=`transform: translateX(${e[1].x}px) translateY(${e[1].y}px)`),E(t,"viewBox","0 0 24 36"),E(t,"width","24"),E(t,"xmlns","http://www.w3.org/2000/svg")},m(s,r){oe(s,t,r),R(t,n)},p(s,[r]){r&1&&E(n,"fill",s[0]),r&2&&i!==(i=`transform: translateX(${s[1].x}px) translateY(${s[1].y}px)`)&&E(t,"style",i)},i:rt,o:rt,d(s){s&&U(t)}}}function Ci(e,t,n){let i,{color:s=""}=t,{x:r=0}=t,{y:l=0}=t;const a=Ui({x:r,y:l},{stiffness:.07,damping:.35});return xe(e,a,c=>n(1,i=c)),e.$$set=c=>{"color"in c&&n(0,s=c.color),"x"in c&&n(3,r=c.x),"y"in c&&n(4,l=c.y)},e.$$.update=()=>{e.$$.dirty&24&&a.set({x:r,y:l})},[s,i,a,r,l]}class Di extends ze{constructor(t){super(),Fe(this,t,Ci,Ni,Ve,{color:0,x:3,y:4})}}function ft(e,t,n){const i=e.slice();return i[8]=t[n].connectionId,i[9]=t[n].presence,i}function pt(e){let t=[],n=new Map,i,s,r=[...e[1]];const l=a=>a[8];for(let a=0;a{r=null}),be())},i(a){s||(C(r),s=!0)},o(a){$(r),s=!1},d(a){a&&U(n),r&&r.d(a),a&&U(i)}}}function Mi(e){var g;let t,n,i=(g=e[0])!=null&&g.cursor?`${e[0].cursor.x} \xD7 ${e[0].cursor.y}`:"Move your cursor to broadcast its position to other people in the room.",s,r,l,a,c,u=e[1]&&pt(e);return{c(){t=V("main"),n=V("div"),s=Ke(i),r=ce(),u&&u.c(),this.h()},l(m){t=J(m,"MAIN",{class:!0});var I=x(t);n=J(I,"DIV",{class:!0});var b=x(n);s=He(b,i),b.forEach(U),r=de(I),u&&u.l(I),I.forEach(U),this.h()},h(){E(n,"class","text svelte-zg8xt2"),E(t,"class","svelte-zg8xt2")},m(m,I){oe(m,t,I),R(t,n),R(n,s),R(t,r),u&&u.m(t,null),l=!0,a||(c=[st(t,"pointerleave",e[3]),st(t,"pointermove",e[2])],a=!0)},p(m,[I]){var b;(!l||I&1)&&i!==(i=(b=m[0])!=null&&b.cursor?`${m[0].cursor.x} \xD7 ${m[0].cursor.y}`:"Move your cursor to broadcast its position to other people in the room.")&&bn(s,i),m[1]?u?(u.p(m,I),I&2&&C(u,1)):(u=pt(m),u.c(),C(u,1),u.m(t,null)):u&&(ge(),$(u,1,1,()=>{u=null}),be())},i(m){l||(C(u),l=!0)},o(m){$(u),l=!1},d(m){m&&U(t),u&&u.d(),a=!1,On(c)}}}function xi(e,t,n){let{room:i}=t,s=i.getPresence(),r=i.getOthers();const l=i.subscribe("my-presence",m=>{n(0,s=m)}),a=i.subscribe("others",m=>{n(1,r=m)});wn(()=>{l(),a()});function c(m){m.preventDefault(),i.updatePresence({cursor:{x:Math.round(m.clientX),y:Math.round(m.clientY)}})}function u(){i.updatePresence({cursor:null})}const g=["#E57373","#9575CD","#4FC3F7","#81C784","#FFF176","#FF8A65","#F06292","#7986CB"];return e.$$set=m=>{"room"in m&&n(5,i=m.room)},[s,r,c,u,g,i]}class Ki extends ze{constructor(t){super(),Fe(this,t,xi,Mi,Ve,{room:5})}}function vt(e){let t,n;return t=new Ki({props:{room:e[0]}}),{c(){gt(t.$$.fragment)},l(i){bt(t.$$.fragment,i)},m(i,s){Ot(t,i,s),n=!0},p(i,s){const r={};s&1&&(r.room=i[0]),t.$set(r)},i(i){n||(C(t.$$.fragment,i),n=!0)},o(i){$(t.$$.fragment,i),n=!1},d(i){wt(t,i)}}}function Hi(e){let t,n,i,s,r,l,a,c,u,g,m,I,b,N,A,O=e[0]&&vt(e);return{c(){t=V("div"),n=V("h1"),i=Ke("Stable Diffussion Outpainting Multiplayer"),s=ce(),r=V("p"),l=ce(),a=V("div"),c=V("form"),u=V("input"),g=ce(),m=V("button"),I=Ke("Create Palette"),b=ce(),N=V("div"),O&&O.c(),this.h()},l(P){t=J(P,"DIV",{class:!0});var T=x(t);n=J(T,"H1",{class:!0});var D=x(n);i=He(D,"Stable Diffussion Outpainting Multiplayer"),D.forEach(U),s=de(T),r=J(T,"P",{class:!0}),x(r).forEach(U),l=de(T),a=J(T,"DIV",{class:!0});var Y=x(a);c=J(Y,"FORM",{class:!0});var H=x(c);u=J(H,"INPUT",{class:!0,placeholder:!0,title:!0,type:!0,name:!0}),g=de(H),m=J(H,"BUTTON",{class:!0,title:!0});var fe=x(m);I=He(fe,"Create Palette"),fe.forEach(U),H.forEach(U),Y.forEach(U),b=de(T),N=J(T,"DIV",{class:!0});var ne=x(N);O&&O.l(ne),ne.forEach(U),T.forEach(U),this.h()},h(){E(n,"class","text-3xl font-bold leading-normal"),E(r,"class","text-sm"),E(u,"class","input svelte-zbscw1"),E(u,"placeholder","A photo of a beautiful sunset in San Francisco"),E(u,"title","Input prompt to generate image and obtain palette"),E(u,"type","text"),E(u,"name","prompt"),u.disabled=e[1],E(m,"class","button svelte-zbscw1"),m.disabled=e[1],E(m,"title","Generate Palette"),E(c,"class","grid grid-cols-6"),E(a,"class","relative top-0 z-50 bg-white dark:bg-black py-3"),E(N,"class","relative"),E(t,"class","max-w-screen-md mx-auto px-3 py-8 relative z-0")},m(P,T){oe(P,t,T),R(t,n),R(n,i),R(t,s),R(t,r),R(t,l),R(t,a),R(a,c),R(c,u),R(c,g),R(c,m),R(m,I),R(t,b),R(t,N),O&&O.m(N,null),A=!0},p(P,[T]){(!A||T&2)&&(u.disabled=P[1]),(!A||T&2)&&(m.disabled=P[1]),P[0]?O?(O.p(P,T),T&1&&C(O,1)):(O=vt(P),O.c(),C(O,1),O.m(N,null)):O&&(ge(),$(O,1,1,()=>{O=null}),be())},i(P){A||(C(O),A=!0)},o(P){$(O),A=!1},d(P){P&&U(t),O&&O.d()}}}let yt="sveltekit-live-cursors";function ji(e,t,n){let i,s;xe(e,Et,a=>n(2,i=a)),xe(e,Pn,a=>n(1,s=a));let r,l;return kn(()=>(r=Ri({publicApiKey:"pk_live_6o9jIg1m7lFJp5kc7HgYgE3S"}),n(0,l=r.enter(yt,{initialPresence:{cursor:null},initialStorage:{}})),console.log("room",l),()=>{r&&l&&r.leave(yt)})),e.$$.update=()=>{e.$$.dirty&4&&console.log("whoami",i)},[l,s,i]}class Vi extends ze{constructor(t){super(),Fe(this,t,ji,Hi,Ve,{})}}export{Vi as default};