@zeniai/web-cockpit-ui 2.1.28-dev → 2.1.29-dev
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{CreditAgentRoutes-rOrW9028.js → CreditAgentRoutes-CJNFBcEe.js} +1 -1
- package/dist/assets/{Preview-8nQ6vXxR.js → Preview-BYWawOzA.js} +1 -1
- package/dist/assets/{ScreenRoutes-9MfV_NZf.js → ScreenRoutes-BaoB1CLL.js} +3 -3
- package/dist/assets/{SignInScreen-CzeYKCeh.js → SignInScreen-BRc-uqFm.js} +1 -1
- package/dist/assets/{analytics-D8DiA4u3.js → analytics-_nt0PAe8.js} +1 -1
- package/dist/assets/{analyticsHelper-C62zhkJP.js → analyticsHelper-CZKAdqek.js} +1 -1
- package/dist/assets/{core-Cuh6I06m.js → core-D6kjq7H7.js} +1 -1
- package/dist/assets/{dash.all.min-ePqSQXI_.js → dash.all.min-wN1yOg4O.js} +1 -1
- package/dist/assets/{empty-CwpRf8bd.js → empty-ByhcQsU1.js} +1 -1
- package/dist/assets/{empty-DG42zO_g.js → empty-CLGJf2aj.js} +1 -1
- package/dist/assets/{epic-jXSWptso.js → epic-D47CUR3D.js} +1 -1
- package/dist/assets/{index-C1u8VU1q.js → index-1kJG7WjD.js} +1 -1
- package/dist/assets/{index-sjmGzj3F.js → index-5WbtXOGV.js} +1 -1
- package/dist/assets/{index-m7Xk7Vks.js → index-C7LnNjly.js} +5 -5
- package/dist/assets/{index-C44eMUVC.js → index-CYMxLCvF.js} +1 -1
- package/dist/assets/{index-CnLtsIvu.js → index-DHUjgUfa.js} +1 -1
- package/dist/assets/{index-D_3UY_2D.js → index-DUbhL4F9.js} +2 -2
- package/dist/assets/{index-C1hBXkGt.js → index-sXYo_CUa.js} +1 -1
- package/dist/assets/{lexical-CFC3xkZg.js → lexical-Cd3Stee4.js} +1 -1
- package/dist/assets/{liveblocks-BDTsCL52.js → liveblocks-Dr8S9esK.js} +1 -1
- package/dist/assets/{lottie-BFyEgU6v.js → lottie-BPkoCwgf.js} +1 -1
- package/dist/assets/{mui-ln_7hj-c.js → mui-CLdwr8bx.js} +1 -1
- package/dist/assets/{react-D5cb8C_A.js → react-B32Ugh00.js} +1 -1
- package/dist/assets/{react-CpqSXHZF.js → react-BiMUhwYk.js} +1 -1
- package/dist/assets/{react-W1YfeIH_.js → react-C3HqYBMv.js} +1 -1
- package/dist/assets/{react-C3Atqjhw.js → react-I4Ff6M2d.js} +1 -1
- package/dist/assets/{react-Ca9coxvu.js → react-ICwtg96X.js} +1 -1
- package/dist/assets/{react-PWLbInDT.js → react-KorIE_Ig.js} +1 -1
- package/dist/assets/{react-k_Y5aGGv.js → react-L6dCNj3u.js} +2 -2
- package/dist/assets/{react-B0uKQH5d.js → react-vMyEEZYa.js} +1 -1
- package/dist/assets/{recharts-C9QKLUlV.js → recharts-CsuorXwT.js} +1 -1
- package/dist/assets/{sentry-Sh5ZJVdi.js → sentry-DaRU1nYW.js} +1 -1
- package/dist/assets/{url-DJ8qhkgs.js → url-Ba6A87jJ.js} +1 -1
- package/dist/assets/{url-C8LV-VlG.js → url-BlWJ1YgH.js} +1 -1
- package/dist/assets/{utils-BJM0N5OL.js → utils-DuDQ7xn1.js} +1 -1
- package/dist/assets/{zeni-epic-state-DAlg8WD-.js → zeni-epic-state-IF19fPBA.js} +3 -3
- package/dist/index.html +1 -1
- package/package.json +4 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as WC,a as f,c as tu,R as Oi,g as zC,b as Re}from"./sentry-
|
|
1
|
+
import{r as WC,a as f,c as tu,R as Oi,g as zC,b as Re}from"./sentry-DaRU1nYW.js";import{r as hs,R as KC}from"./core-D6kjq7H7.js";import{t as GC,d as qC}from"./recharts-CsuorXwT.js";(function(){try{var e=typeof window<"u"?window:typeof Dr<"u"?Dr:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="84ac0537-2322-4ec8-adff-8e521b838fc8",e._sentryDebugIdIdentifier="sentry-dbid-84ac0537-2322-4ec8-adff-8e521b838fc8")}catch{}})();var fa={exports:{}},To={};var Bl;function YC(){if(Bl)return To;Bl=1;var e=WC(),t=Symbol.for("react.element"),n=Symbol.for("react.fragment"),r=Object.prototype.hasOwnProperty,o=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,s={key:!0,ref:!0,__self:!0,__source:!0};function i(a,u,c){var d,l={},m=null,g=null;c!==void 0&&(m=""+c),u.key!==void 0&&(m=""+u.key),u.ref!==void 0&&(g=u.ref);for(d in u)r.call(u,d)&&!s.hasOwnProperty(d)&&(l[d]=u[d]);if(a&&a.defaultProps)for(d in u=a.defaultProps,u)l[d]===void 0&&(l[d]=u[d]);return{$$typeof:t,type:a,key:m,ref:g,props:l,_owner:o.current}}return To.Fragment=n,To.jsx=i,To.jsxs=i,To}var Fl;function JC(){return Fl||(Fl=1,fa.exports=YC()),fa.exports}var h=JC(),ZC="@liveblocks/react",XC="3.22.0",QC="esm";function p4(e){const[t,n]=f.useState(!1);return f.useEffect(()=>{n(!0)},[]),h.jsx(f.Suspense,{fallback:e.fallback,children:t?typeof e.children=="function"?e.children():e.children:e.fallback})}var e1=Object.defineProperty,t1=(e,t)=>{for(var n in t)e1(e,n,{get:t[n],enumerable:!0})},n1="@liveblocks/core",Ti="3.22.0",r1="esm",Rs=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof tu<"u"?tu:{},o1="https://liveblocks.io/docs/errors/dupes",s1=" ";function i1(e){console.error(e)}function Yu(e,t,n){const r=Symbol.for(e),o=`${t} (${n})`;if(!Rs[r])Rs[r]=o;else if(Rs[r]!==o){const s=[`Multiple copies of Liveblocks are being loaded in your project. This will cause issues! See ${o1+s1}`,"","Conflicts:",`- ${e} ${Rs[r]} (already loaded)`,`- ${e} ${o} (trying to load this now)`].join(`
|
|
2
2
|
`);i1(s)}}function Ne(){const e=new Set;function t(i){return e.add(i),()=>e.delete(i)}function n(i){const a=t(u=>(a(),i(u)));return a}async function r(i){let a;return new Promise(u=>{a=t(c=>{(i===void 0||i(c))&&u(c)})}).finally(()=>a?.())}function o(i){let a=!1;for(const u of e)u(i),a=!0;return a}function s(){return e.size}return{notify:o,subscribe:t,subscribeOnce:n,count:s,waitUntil:r,dispose(){e.clear()},observable:{subscribe:t,subscribeOnce:n,waitUntil:r}}}function a1(){const e=Ne();let t=null;function n(){t=[]}function r(){if(t!==null){for(const s of t)e.notify(s);t=null}}function o(s){return t!==null?(t.push(s),!1):e.notify(s)}return{...e,notify:o,pause:n,unpause:r,dispose(){e.dispose(),t!==null&&(t.length=0)}}}var hn=(e=>e);function Ft(e){throw new Error(e)}function Ju(e){return Object.entries(e)}function u1(e){return Object.keys(e)}function c1(e,t){return typeof t<"u"?Object.create(e,t):Object.create(e)}function Sn(e){try{return JSON.parse(e)}catch{return}}function ao(e){return JSON.parse(JSON.stringify(e))}function l1(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 nu(e){return e.filter(t=>t!=null)}function ps(e){const t={...e};return Object.keys(e).forEach(n=>{const r=n;t[r]===void 0&&delete t[r]}),t}function d1(e){return new Promise(t=>setTimeout(t,e))}async function Pl(e,t,n){let r;const o=new Promise((s,i)=>{r=setTimeout(()=>{i(new Error(n))},t)});return Promise.race([e,o]).finally(()=>clearTimeout(r))}function Ml(e){let t=null;return()=>(t===null&&(t=e().catch(n=>{throw setTimeout(()=>{t=null},5e3),n})),t)}function Lh(e,t){for(let n=e.length-1;n>=0;n--)if(t(e[n],n,e))return n;return-1}function f1(e,t){const n=[],r=[];let o=0;for(const s of e)t(s,o++)?n.push(s):r.push(s);return[n,r]}var or=Symbol("kSinks"),ii=Symbol("kTrigger"),Yr=null,fr=null;function Ze(e){if(Yr!==null){e();return}Yr=new Set;try{e()}finally{for(const t of Yr)t[ii]();Yr=null}}function Zu(e){Yr||Ft("Expected to be in an active batch"),Yr.add(e)}function Uh(e,t){let n=!1;const r={...e};return Object.keys(t).forEach(o=>{const s=o,i=t[s];r[s]!==i&&(i===void 0?delete r[s]:r[s]=i,n=!0)}),n?r:e}var Xu=class{equals;#e;[or];constructor(e){this.equals=e??Object.is,this.#e=Ne(),this[or]=new Set,this.get=this.get.bind(this),this.subscribe=this.subscribe.bind(this),this.subscribeOnce=this.subscribeOnce.bind(this)}dispose(){this.#e.dispose(),this.#e="(disposed)",this.equals="(disposed)"}get hasWatchers(){if(this.#e.count()>0)return!0;for(const e of this[or])if(e.hasWatchers)return!0;return!1}[ii](){this.#e.notify();for(const e of this[or])Zu(e)}subscribe(e){return this.#e.count()===0&&this.get(),this.#e.subscribe(e)}subscribeOnce(e){const t=this.subscribe(()=>(t(),e()));return t}waitUntil(){throw new Error("waitUntil not supported on Signals")}markSinksDirty(){for(const e of this[or])e.markDirty()}addSink(e){this[or].add(e)}removeSink(e){this[or].delete(e)}asReadonly(){return this}},St=class extends Xu{#e;constructor(e,t){super(t),this.#e=hn(e)}dispose(){super.dispose(),this.#e="(disposed)"}get(){return fr?.add(this),this.#e}set(e){Ze(()=>{typeof e=="function"&&(e=e(this.#e)),this.equals(this.#e,e)||(this.#e=hn(e),this.markSinksDirty(),Zu(this))})}},h1=class extends St{constructor(e){super(hn(ps(e)))}set(){throw new Error("Don't call .set() directly, use .patch()")}patch(e){super.set(t=>Uh(t,e))}},p1=Symbol(),je=class ru extends Xu{#e;#t;#n;#r;#o;static from(...t){const n=t.pop();if(typeof n!="function"&&Ft("Invalid .from() call, last argument expected to be a function"),typeof t[t.length-1]=="function"){const r=n,o=t.pop();return new ru(t,o,r)}else{const r=n;return new ru(t,r)}}constructor(t,n,r){super(r),this.#t=!0,this.#e=p1,this.#r=t,this.#n=new Set,this.#o=n}dispose(){for(const t of this.#n)t.removeSink(this);this.#e="(disposed)",this.#n="(disposed)",this.#r="(disposed)",this.#o="(disposed)"}get isDirty(){return this.#t}#s(){const t=fr;let n;fr=new Set;try{n=this.#o(...this.#r.map(r=>r.get()))}finally{const r=this.#n;this.#n=new Set;for(const o of fr)this.#n.add(o),r.delete(o);for(const o of r)o.removeSink(this);for(const o of this.#n)o.addSink(this);fr=t}return this.#t=!1,this.equals(this.#e,n)?!1:(this.#e=n,!0)}markDirty(){this.#t||(this.#t=!0,this.markSinksDirty())}get(){return this.#t&&this.#s(),fr?.add(this),this.#e}[ii](){if(!this.hasWatchers)return;this.#s()&&super[ii]()}},xt=class extends Xu{#e;constructor(e){super(),this.#e=e}dispose(){super.dispose(),this.#e="(disposed)"}get(){return fr?.add(this),this.#e}mutate(e){Ze(()=>{const t=e?e(this.#e):!0;t!==null&&typeof t=="object"&&"then"in t&&Ft("MutableSignal.mutate() does not support async callbacks"),t!==!1&&(this.markSinksDirty(),Zu(this))})}};function _l(e,t,n){let r=0,o=e.length;for(;r<o;){const s=r+(o-r>>1);n(t,e[s])?o=s:r=s+1}return r}var zn=class Mo{#e;#t;constructor(t,n){this.#t=n,this.#e=t}static with(t){return Mo.fromAlreadySorted([],t)}static from(t,n){const r=new Mo([],n);for(const o of t)r.add(o);return r}static fromAlreadySorted(t,n){return new Mo(t,n)}clone(){return new Mo(this.#e.slice(),this.#t)}add(t){const n=_l(this.#e,t,this.#t);return this.#e.splice(n,0,t),n}clear(){const t=this.#e.length>0;return this.#e.length=0,t}removeBy(t,n=Number.POSITIVE_INFINITY){let r=0;for(let o=0;o<this.#e.length;o++)if(t(this.#e[o])){if(this.#e.splice(o,1),r++,r>=n)break;o--}return r>0}remove(t){const n=this.#e.indexOf(t);return n>=0?(this.#e.splice(n,1),!0):!1}removeAt(t){if(t<0||t>=this.#e.length)return;const[n]=this.#e.splice(t,1);return n}reposition(t){const n=this.#e.indexOf(t);if(n<0)throw new Error("Cannot reposition item that is not in the list");const r=this.#e[n-1],o=this.#e[n+1],s=r===void 0||this.#t(r,t),i=o===void 0||this.#t(t,o);if(s&&i)return n;let a=n;for(;a>0&&this.#t(t,this.#e[a-1]);)this.#e[a]=this.#e[a-1],a--;if(a<n)return this.#e[a]=t,a;for(;a<this.#e.length-1&&!this.#t(t,this.#e[a+1]);)this.#e[a]=this.#e[a+1],a++;return a!==n&&(this.#e[a]=t),a}at(t){return this.#e[t]}get length(){return this.#e.length}includes(t){for(let n=_l(this.#e,t,this.#t)-1;n>=0&&!this.#t(this.#e[n],t);n--)if(this.#e[n]===t)return!0;return!1}*filter(t){for(const n of this.#e)t(n)&&(yield n)}*findAllRight(t){for(let n=this.#e.length-1;n>=0;n--){const r=this.#e[n];t(r,n)&&(yield r)}}[Symbol.iterator](){return this.#e[Symbol.iterator]()}*iterReversed(){for(let t=this.#e.length-1;t>=0;t--)yield this.#e[t]}find(t,n){const r=this.findIndex(t,n);return r>-1?this.#e.at(r):void 0}findIndex(t,n=0){for(let r=Math.max(0,n);r<this.#e.length;r++)if(t(this.#e[r],r))return r;return-1}findRight(t,n){const r=this.findIndexRight(t,n);return r>-1?this.#e.at(r):void 0}findIndexRight(t,n=this.#e.length-1){for(let r=Math.min(n,this.#e.length-1);r>=0;r--)if(t(this.#e[r],r))return r;return-1}get rawArray(){return this.#e}},m1=class{#e;#t;signal;constructor(){this.#e=new Map,this.#t=zn.from([],(e,t)=>{const n=t.lastMessageAt??t.createdAt,r=e.lastMessageAt??e.createdAt;return n<r?!0:n===r?t.id<e.id:!1}),this.signal=new xt(this)}getEvenIfDeleted(e){return this.signal.get(),this.#e.get(e)}markDeleted(e){const t=this.#e.get(e);t===void 0||t.deletedAt!==void 0||this.upsert({...t,deletedAt:new Date().toISOString()})}upsert(e){this.signal.mutate(()=>{const t=this.#e.get(e.id);if(t!==void 0){if(t.deletedAt!==void 0)return!1;this.#t.remove(t),this.#e.delete(t.id)}return e.deletedAt===void 0&&this.#t.add(e),this.#e.set(e.id,e),!0})}findMany(e){return Array.from(this.#t.filter(t=>{if(e.metadata===void 0)return!0;for(const[n,r]of Object.entries(e.metadata))if(r===null){if(n in t.metadata)return!1}else if(typeof r=="string"){if(t.metadata[n]!==r)return!1}else{const o=t.metadata[n];if(!Array.isArray(o)||!r.every(s=>o.includes(s)))return!1}return!0}))}};function ou(e){const t=e.editedAt?new Date(e.editedAt):void 0,n=new Date(e.createdAt),r=e.reactions.map(o=>({...o,createdAt:new Date(o.createdAt)}));if(e.body)return{...e,reactions:r,createdAt:n,editedAt:t};{const o=new Date(e.deletedAt);return{...e,reactions:r,createdAt:n,editedAt:t,deletedAt:o}}}function _n(e){const t=new Date(e.createdAt),n=new Date(e.updatedAt),r=e.comments.map(o=>ou(o));return{...e,createdAt:t,updatedAt:n,comments:r}}function g1(e){return{...e,createdAt:new Date(e.createdAt)}}function sr(e){const t=new Date(e.notifiedAt),n=e.readAt?new Date(e.readAt):null;if("activities"in e){const r=e.activities.map(o=>({...o,createdAt:new Date(o.createdAt)}));return{...e,notifiedAt:t,readAt:n,activities:r}}return{...e,notifiedAt:t,readAt:n}}function kn(e){const t=new Date(e.createdAt);return{...e,createdAt:t}}function ha(e){const t=new Date(e.deletedAt);return{...e,deletedAt:t}}function pa(e){const t=new Date(e.deletedAt);return{...e,deletedAt:t}}function ma(e){const t=new Date(e.deletedAt);return{...e,deletedAt:t}}function kl(e){const t=new Date(e.createdAt),n=new Date(e.updatedAt),r=e.members.map(o=>({...o,addedAt:new Date(o.addedAt)}));return{...e,createdAt:t,updatedAt:n,members:r}}function Je(e,t){throw new Error(t)}function ge(e,t="Expected value to be non-nullable"){return e}var Vt={};t1(Vt,{error:()=>Jn,errorWithTitle:()=>Wh,warn:()=>ft,warnWithTitle:()=>C1});var $h="background:#0e0d12;border-radius:9999px;color:#fff;padding:3px 7px;font-family:sans-serif;font-weight:600;",v1="font-weight:600";function Hh(e){return typeof window>"u"?console[e]:((t,...n)=>console[e]("%cLiveblocks",$h,t,...n))}var ft=Hh("warn"),Jn=Hh("error");function Vh(e){return typeof window>"u"?console[e]:((t,n,...r)=>console[e](`%cLiveblocks%c ${t}`,$h,v1,n,...r))}var C1=Vh("warn"),Wh=Vh("error");function E1(e){return e!=null}function lt(e){return e!==null&&typeof e=="object"&&Object.prototype.toString.call(e)==="[object Object]"}function su(e){return lt(e)&&typeof e.startsWith=="string"}function iu(e){return lt(e)&&(typeof e.lt=="number"||typeof e.gt=="number"||typeof e.lte=="number"||typeof e.gte=="number")}var uo=class zh extends Error{response;details;constructor(t,n,r){super(t),this.name="HttpError",this.response=n,this.details=r}static async fromResponse(t){let n;try{n=await t.text()}catch{}const r=n?Sn(n):void 0;let o;lt(r)&&(o=r);let s="";s||=typeof o?.message=="string"?o.message:"",s||=typeof o?.error=="string"?o.error:"",r===void 0&&(s||=n||""),s||=t.statusText;let i;try{i=new URL(t.url).pathname}catch{}s+=i!==void 0?` (got status ${t.status} from ${i})`:` (got status ${t.status})`;const a=o;return new zh(s,t,a)}get status(){return this.response.status}},y1=e=>e instanceof uo&&e.status>=400&&e.status<500;async function Uo(e,t,n,r=y1){const o=n.length>0?n[n.length-1]:0;let s=0;for(;;){s++;try{return await e()}catch(a){if(r(a))throw a;if(s>=t)throw new Error(`Failed after ${t} attempts: ${String(a)}`)}const i=n[s-1]??o;ft(`Attempt ${s} was unsuccessful. Retrying in ${i} milliseconds.`),await d1(i)}}function Kh(){let e,t;return[new Promise((r,o)=>{e=r,t=o}),e,t]}function Jr(){const[e,t,n]=Kh();return{promise:e,resolve:t,reject:n}}function b1(e,t){return t!==null&&typeof t=="object"&&!Array.isArray(t)?Object.keys(t).sort().reduce((n,r)=>(n[r]=t[r],n),{}):t}function Zn(e){return JSON.stringify(e,b1)}function co(e){try{return JSON.stringify(e)}catch(t){throw console.error(`Could not stringify: ${t.message}`),console.error(e),t}}var w1=50,D1=class{input;resolve;reject;promise;constructor(e){this.input=e;const{promise:t,resolve:n,reject:r}=Jr();this.promise=t,this.resolve=n,this.reject=r}},mr=class{#e=[];#t;#n;#r;#o;error=!1;constructor(e,t){this.#t=e,this.#n=t.size??w1,this.#r=t.delay}#s(){this.#o!==void 0&&(clearTimeout(this.#o),this.#o=void 0)}#i(){this.#e.length===this.#n?this.#u():this.#e.length===1&&(this.#s(),this.#o=setTimeout(()=>{this.#u()},this.#r))}async#u(){if(this.#e.length===0)return;const e=this.#e.splice(0),t=e.map(n=>n.input);try{const n=await this.#t(t);this.error=!1,e.forEach((r,o)=>{const s=n?.[o];Array.isArray(n)?e.length!==n.length?r.reject(new Error(`Callback must return an array of the same length as the number of provided items. Expected ${e.length}, but got ${n.length}.`)):s instanceof Error?r.reject(s):r.resolve(s):r.reject(new Error("Callback must return an array."))})}catch(n){this.error=!0,e.forEach(r=>{r.reject(n)})}}get(e){const t=this.#e.find(r=>Zn(r.input)===Zn(e));if(t)return t.promise;const n=new D1(e);return this.#e.push(n),this.#i(),n.promise}clear(){this.#e=[],this.error=!1,this.#s()}};function $o(e){const t=new xt(new Map);function n(d){return Zn(d)}function r(d){t.mutate(l=>{if(Array.isArray(d))for(const m of d)l.set(m.key,m.state);else l.set(d.key,d.state)})}function o(d){t.mutate(l=>{if(Array.isArray(d))for(const m of d)l.delete(n(m));else l.clear()})}async function s(d){const l=n(d);if(!t.get().has(l))try{r({key:l,state:{isLoading:!0}});const g=await e.get(d);r({key:l,state:{isLoading:!1,data:g}})}catch(g){r({key:l,state:{isLoading:!1,error:g}})}}function i(d){r(d.map(l=>({key:n(l[0]),state:{isLoading:!1,data:l[1]}})))}function a(d){const l=n(d);return t.get().get(l)}function u(d){const l=n(d);return t.get().get(l)?.data}function c(){return[...t.get().keys()]}return{subscribe:t.subscribe,enqueue:s,setData:i,getItemState:a,getData:u,invalidate:o,batch:e,_cacheKeys:c}}function A1(e,t){const n=[];for(let r=0,o=e.length;r<o;r+=t)n.push(e.slice(r,r+t));return n}var it=(e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce((t,n)=>t+=(n&=63)<36?n.toString(36):n<62?(n-26).toString(36).toUpperCase():n<63?"_":"-",""),S1="th",x1="cm",O1="at";function Qu(e){return`${e}_${it()}`}function Gh(){return Qu(S1)}function ai(){return Qu(x1)}function qh(){return Qu(O1)}var Le=class extends Map{#e;constructor(e,t){super(t),this.#e=e}getOrCreate(e,t){if(super.has(e))return super.get(e);{const r=(t??this.#e??Ft("DefaultMap used without a factory function"))(e);return this.set(e,r),r}}},T1=/^[a-zA-Z_][a-zA-Z0-9_]*$/;function Nr(e){let t=[];const n=Object.entries(e),r=[],o=[],s=[];return n.forEach(([i,a])=>{if(!T1.test(i))throw new Error("Key must only contain letters, numbers, _");Ll(a)?r.push([i,a]):lt(a)&&(su(a)||iu(a)?o.push([i,a]):s.push([i,a]))}),t=[...Nl(r),...jl(o)],s.forEach(([i,a])=>{const u=Object.entries(a),c=[],d=[];u.forEach(([l,m])=>{if(R1(l))throw new Error("Key cannot be empty");Ll(m)?c.push([Ul(i,l),m]):(su(m)||iu(m))&&d.push([Ul(i,l),m])}),t=[...t,...Nl(c),...jl(d)]}),t.map(({key:i,operator:a,value:u})=>`${i}${a}${Yh(u)}`).join(" ")}var Nl=e=>{const t=[];return e.forEach(([n,r])=>{t.push({key:n,operator:":",value:r})}),t},jl=e=>{const t=[];return e.forEach(([n,r])=>{"startsWith"in r&&typeof r.startsWith=="string"&&t.push({key:n,operator:"^",value:r.startsWith}),"lt"in r&&typeof r.lt=="number"&&t.push({key:n,operator:"<",value:r.lt}),"gt"in r&&typeof r.gt=="number"&&t.push({key:n,operator:">",value:r.gt}),"gte"in r&&typeof r.gte=="number"&&t.push({key:n,operator:">=",value:r.gte}),"lte"in r&&typeof r.lte=="number"&&t.push({key:n,operator:"<=",value:r.lte})}),t},Ll=e=>typeof e=="string"||typeof e=="number"||typeof e=="boolean"||e===null,Ul=(e,t)=>t?`${e}[${Yh(t)}]`:e,R1=e=>!e||e.toString().trim()==="";function Yh(e){const t=JSON.stringify(e);return typeof e!="string"||t.includes("'")?t:`'${t.slice(1,-1).replace(/\\"/g,'"')}'`}var au="https://localhost:9999",Jh=/^[a-zA-Z][a-zA-Z\d+\-.]*?:/,I1=/\/(?:(?:\?|#).*)?$/;function B1(e){const t=new URLSearchParams;for(const[n,r]of Object.entries(e))r!=null&&t.set(n,r.toString());return t}function F1(e,t,n){const r=new URL(t,e);return n!==void 0&&(r.search=(n instanceof URLSearchParams?n:B1(n)).toString()),r.toString()}function Ae(e,...t){return e.reduce((n,r,o)=>n+encodeURIComponent(t[o-1]??"")+r)}function ec(e){if(e.startsWith("www.")&&(e="https://"+e),e==="#")return e;try{const t=Jh.test(e),n=new URL(e,t?void 0:au);if(n.protocol!=="http:"&&n.protocol!=="https:")return null;const r=I1.test(e),o=(t?n.origin:"")+(n.pathname==="/"?r?"/":"":r&&!n.pathname.endsWith("/")?n.pathname+"/":n.pathname)+n.search+n.hash;return o!==""?o:null}catch{return null}}function P1(e,t,n){const r=Jh.test(e),o=new URL(e,r?void 0:au);return!o.hash&&n!==void 0&&(o.hash=`#${n}`),r?o.href:o.href.replace(au,"")}function M1(e){try{return new URL(e),!0}catch{return!1}}function $t(e){return e==="private"?"comments:private":e==="public"?"comments:public":"comments"}function _1({baseUrl:e,authManager:t,fetchPolyfill:n}){const r=new k1(e,n);async function o(O){const k=await r.get(Ae`/v2/c/rooms/${O.roomId}/threads/delta`,await t.getAuthValue({roomId:O.roomId,resource:"comments",access:"read"}),{since:O.since.toISOString()},{signal:O.signal});return{threads:{updated:k.data.map(_n),deleted:k.deletedThreads.map(ha)},inboxNotifications:{updated:k.inboxNotifications.map(sr),deleted:k.deletedInboxNotifications.map(pa)},subscriptions:{updated:k.subscriptions.map(kn),deleted:k.deletedSubscriptions.map(ma)},requestedAt:new Date(k.meta.requestedAt),permissionHints:k.meta.permissionHints}}async function s(O){let k;O.query&&(k=Nr(O.query));const ne=50;try{const re=await r.get(Ae`/v2/c/rooms/${O.roomId}/threads`,await t.getAuthValue({roomId:O.roomId,resource:$t(O.query?.visibility),access:"read"}),{cursor:O.cursor,query:k,limit:ne});return{threads:re.data.map(_n),inboxNotifications:re.inboxNotifications.map(sr),subscriptions:re.subscriptions.map(kn),nextCursor:re.meta.nextCursor,requestedAt:new Date(re.meta.requestedAt),permissionHints:re.meta.permissionHints}}catch(re){if(re instanceof uo&&re.status===404)return{threads:[],inboxNotifications:[],subscriptions:[],nextCursor:null,requestedAt:new Date(Date.now()-360*60*1e3),permissionHints:{}};throw re}}async function i(O,k){return await r.get(Ae`/v2/c/rooms/${O.roomId}/threads/comments/search`,await t.getAuthValue({roomId:O.roomId,resource:"comments",access:"read"}),{text:O.query.text,query:Nr({threadMetadata:O.query.threadMetadata,threadResolved:O.query.threadResolved,hasAttachments:O.query.hasAttachments,hasMentions:O.query.hasMentions})},{signal:k?.signal})}async function a(O){const k=O.commentId??ai(),ne=O.threadId??Gh(),re=await r.post(Ae`/v2/c/rooms/${O.roomId}/threads`,await t.getAuthValue({roomId:O.roomId,resource:$t(O.visibility??"public"),access:"write"}),{id:ne,visibility:O.visibility,comment:{id:k,body:O.body,metadata:O.commentMetadata,attachmentIds:O.attachmentIds},metadata:O.metadata});return _n(re)}async function u(O){await r.delete(Ae`/v2/c/rooms/${O.roomId}/threads/${O.threadId}`,await t.getAuthValue({roomId:O.roomId,resource:$t(O.visibility),access:"write"}))}async function c(O){const k=await r.rawGet(Ae`/v2/c/rooms/${O.roomId}/thread-with-notification/${O.threadId}`,await t.getAuthValue({roomId:O.roomId,resource:"comments",access:"read"}));if(k.ok){const ne=await k.json();return{thread:_n(ne.thread),inboxNotification:ne.inboxNotification?sr(ne.inboxNotification):void 0,subscription:ne.subscription?kn(ne.subscription):void 0}}else{if(k.status===404)return{thread:void 0,inboxNotification:void 0,subscription:void 0};throw new Error(`There was an error while getting thread ${O.threadId}.`)}}async function d(O){return await r.post(Ae`/v2/c/rooms/${O.roomId}/threads/${O.threadId}/metadata`,await t.getAuthValue({roomId:O.roomId,resource:$t(O.visibility),access:"write"}),O.metadata)}async function l(O){return await r.post(Ae`/v2/c/rooms/${O.roomId}/threads/${O.threadId}/comments/${O.commentId}/metadata`,await t.getAuthValue({roomId:O.roomId,resource:$t(O.visibility),access:"write"}),O.metadata)}async function m(O){const k=O.commentId??ai(),ne=await r.post(Ae`/v2/c/rooms/${O.roomId}/threads/${O.threadId}/comments`,await t.getAuthValue({roomId:O.roomId,resource:$t(O.visibility),access:"write"}),{id:k,body:O.body,metadata:O.metadata,attachmentIds:O.attachmentIds});return ou(ne)}async function g(O){const k=await r.post(Ae`/v2/c/rooms/${O.roomId}/threads/${O.threadId}/comments/${O.commentId}`,await t.getAuthValue({roomId:O.roomId,resource:$t(O.visibility),access:"write"}),{body:O.body,attachmentIds:O.attachmentIds,metadata:O.metadata});return ou(k)}async function v(O){await r.delete(Ae`/v2/c/rooms/${O.roomId}/threads/${O.threadId}/comments/${O.commentId}`,await t.getAuthValue({roomId:O.roomId,resource:$t(O.visibility),access:"write"}))}async function C(O){const k=await r.post(Ae`/v2/c/rooms/${O.roomId}/threads/${O.threadId}/comments/${O.commentId}/reactions`,await t.getAuthValue({roomId:O.roomId,resource:$t(O.visibility),access:"write"}),{emoji:O.emoji});return g1(k)}async function p(O){await r.delete(Ae`/v2/c/rooms/${O.roomId}/threads/${O.threadId}/comments/${O.commentId}/reactions/${O.emoji}`,await t.getAuthValue({roomId:O.roomId,resource:$t(O.visibility),access:"write"}))}async function D(O){await r.post(Ae`/v2/c/rooms/${O.roomId}/threads/${O.threadId}/mark-as-resolved`,await t.getAuthValue({roomId:O.roomId,resource:$t(O.visibility),access:"write"}))}async function w(O){await r.post(Ae`/v2/c/rooms/${O.roomId}/threads/${O.threadId}/mark-as-unresolved`,await t.getAuthValue({roomId:O.roomId,resource:$t(O.visibility),access:"write"}))}async function b(O){const k=await r.post(Ae`/v2/c/rooms/${O.roomId}/threads/${O.threadId}/subscribe`,await t.getAuthValue({roomId:O.roomId,resource:"comments",access:"read"}));return kn(k)}async function y(O){await r.post(Ae`/v2/c/rooms/${O.roomId}/threads/${O.threadId}/unsubscribe`,await t.getAuthValue({roomId:O.roomId,resource:"comments",access:"read"}))}async function A(O){const k=O.roomId,ne=O.signal,re=O.attachment,he=ne?new DOMException(`Upload of attachment ${O.attachment.id} was aborted.`,"AbortError"):void 0;if(ne?.aborted)throw he;const Ie=He=>{if(ne?.aborted)throw he;if(He instanceof uo&&He.status===413)throw He;return!1},Fe=5*1024*1024,Xe=10,ht=[2e3,2e3,2e3,2e3,2e3,2e3,2e3,2e3,2e3,2e3];function Gt(He){const pt=[];let mt=0;for(;mt<He.size;){const Ve=Math.min(mt+Fe,He.size);pt.push({partNumber:pt.length+1,part:He.slice(mt,Ve)}),mt=Ve}return pt}if(re.size<=Fe)return Uo(async()=>r.putBlob(Ae`/v2/c/rooms/${k}/attachments/${re.id}/upload/${re.name}`,await t.getAuthValue({roomId:k,resource:"comments",access:"write"}),re.file,{fileSize:re.size},{signal:ne}),Xe,ht,Ie);{let He;const pt=[],mt=await Uo(async()=>r.post(Ae`/v2/c/rooms/${k}/attachments/${re.id}/multipart/${re.name}`,await t.getAuthValue({roomId:k,resource:"comments",access:"write"}),void 0,{signal:ne},{fileSize:re.size}),Xe,ht,Ie);try{He=mt.uploadId;const Ve=Gt(re.file);if(ne?.aborted)throw he;const Mt=A1(Ve,5);for(const qt of Mt){const vt=[];for(const{part:rn,partNumber:on}of qt)vt.push(Uo(async()=>r.putBlob(Ae`/v2/c/rooms/${k}/attachments/${re.id}/multipart/${mt.uploadId}/${String(on)}`,await t.getAuthValue({roomId:k,resource:"comments",access:"write"}),rn,void 0,{signal:ne}),Xe,ht,Ie));pt.push(...await Promise.all(vt))}if(ne?.aborted)throw he;const gt=pt.sort((qt,vt)=>qt.partNumber-vt.partNumber);return r.post(Ae`/v2/c/rooms/${k}/attachments/${re.id}/multipart/${He}/complete`,await t.getAuthValue({roomId:k,resource:"comments",access:"write"}),{parts:gt},{signal:ne})}catch(Ve){if(He&&Ve?.name&&(Ve.name==="AbortError"||Ve.name==="TimeoutError"))try{await r.rawDelete(Ae`/v2/c/rooms/${k}/attachments/${re.id}/multipart/${He}`,await t.getAuthValue({roomId:k,resource:"comments",access:"write"}))}catch{}throw Ve}}}const T=new Le(O=>{const k=new mr(async ne=>{const re=ne.flat(),{urls:he}=await r.post(Ae`/v2/c/rooms/${O}/attachments/presigned-urls`,await t.getAuthValue({roomId:O,resource:"comments",access:"read"}),{attachmentIds:re});return he.map(Ie=>Ie??new Error("There was an error while getting this attachment's URL"))},{delay:50});return $o(k)});function S(O){return T.getOrCreate(O)}function P(O){return S(O.roomId).batch.get(O.attachmentId)}async function L(O){return r.get(Ae`/v2/c/rooms/${O.roomId}/subscription-settings`,await t.getAuthValue({roomId:O.roomId,resource:"comments",access:"read"}),void 0,{signal:O.signal})}async function F(O){return r.post(Ae`/v2/c/rooms/${O.roomId}/subscription-settings`,await t.getAuthValue({roomId:O.roomId,resource:"comments",access:"read"}),O.settings)}const M=new Le(O=>new mr(async k=>{const ne=k.flat();return await r.post(Ae`/v2/c/rooms/${O}/inbox-notifications/read`,await t.getAuthValue({roomId:O,resource:"comments",access:"read"}),{inboxNotificationIds:ne}),ne},{delay:50}));async function N(O){return M.getOrCreate(O.roomId).get(O.inboxNotificationId)}async function _(O){if(O.mention.kind!=="user"&&O.mention.kind!=="group")return Je(O.mention,"Unexpected mention kind");await r.rawPost(Ae`/v2/c/rooms/${O.roomId}/text-mentions`,await t.getAuthValue({roomId:O.roomId,resource:"storage",access:"write"}),{userId:O.mention.kind==="user"?O.mention.id:void 0,groupId:O.mention.kind==="group"?O.mention.id:void 0,userIds:O.mention.kind==="group"?O.mention.userIds:void 0,mentionId:O.mentionId})}async function I(O){await r.rawDelete(Ae`/v2/c/rooms/${O.roomId}/text-mentions/${O.mentionId}`,await t.getAuthValue({roomId:O.roomId,resource:"storage",access:"write"}))}async function j(O){return r.rawGet(Ae`/v2/c/rooms/${O.roomId}/versions/${O.versionId}/storage`,await t.getAuthValue({roomId:O.roomId,resource:"storage",access:"read"}))}async function z(O){return r.rawGet(Ae`/v2/c/rooms/${O.roomId}/versions/${O.versionId}/yjs`,await t.getAuthValue({roomId:O.roomId,resource:"storage",access:"read"}))}async function Y(O){await r.rawPost(Ae`/v2/c/rooms/${O.roomId}/versions`,await t.getAuthValue({roomId:O.roomId,resource:"storage",access:"write"}))}async function oe(O){await r.delete(Ae`/v2/c/rooms/${O.roomId}/versions/${O.versionId}`,await t.getAuthValue({roomId:O.roomId,resource:"storage",access:"write"}))}async function G(O){await r.rawPost(Ae`/v2/c/rooms/${O.roomId}/text-metadata`,await t.getAuthValue({roomId:O.roomId,resource:"storage",access:"read"}),{type:O.type,rootKey:O.rootKey})}async function Z(O){const k=await r.post(Ae`/v2/c/rooms/${O.roomId}/ai/contextual-prompt`,await t.getAuthValue({roomId:O.roomId,resource:"storage",access:"read"}),{prompt:O.prompt,context:{beforeSelection:O.context.beforeSelection,selection:O.context.selection,afterSelection:O.context.afterSelection},previous:O.previous},{signal:O.signal});if(!k||k.content.length===0)throw new Error("No content returned from server");return k.content[0].text}async function le(O){const k=await r.get(Ae`/v2/c/rooms/${O.roomId}/versions`,await t.getAuthValue({roomId:O.roomId,resource:"storage",access:"read"}));return{versions:k.versions.map(({createdAt:ne,...re})=>({createdAt:new Date(ne),...re})),requestedAt:new Date(k.meta.requestedAt)}}async function de(O){const k=await r.get(Ae`/v2/c/rooms/${O.roomId}/versions/delta`,await t.getAuthValue({roomId:O.roomId,resource:"storage",access:"read"}),{since:O.since.toISOString()},{signal:O.signal});return{versions:k.versions.map(({createdAt:ne,...re})=>({createdAt:new Date(ne),...re})),requestedAt:new Date(k.meta.requestedAt)}}async function ue(O){return await(await r.rawGet(Ae`/v2/c/rooms/${O.roomId}/storage`,await t.getAuthValue({roomId:O.roomId,resource:"storage",access:"read"}))).json()}async function ee(O){let ne;O?.query&&(ne=Nr(O.query));const re=await r.get(Ae`/v2/c/inbox-notifications`,await t.getAuthValue({resource:"personal",access:"write"}),{cursor:O?.cursor,limit:50,query:ne}),he=re.groups.map(kl);return xe.setData(he.map(Ie=>[Ie.id,Ie])),{inboxNotifications:re.inboxNotifications.map(sr),threads:re.threads.map(_n),subscriptions:re.subscriptions.map(kn),nextCursor:re.meta.nextCursor,requestedAt:new Date(re.meta.requestedAt)}}async function te(O){let k;O?.query&&(k=Nr(O.query));const ne=await r.get(Ae`/v2/c/inbox-notifications/delta`,await t.getAuthValue({resource:"personal",access:"write"}),{since:O.since.toISOString(),query:k},{signal:O.signal});return{inboxNotifications:{updated:ne.inboxNotifications.map(sr),deleted:ne.deletedInboxNotifications.map(pa)},threads:{updated:ne.threads.map(_n),deleted:ne.deletedThreads.map(ha)},subscriptions:{updated:ne.subscriptions.map(kn),deleted:ne.deletedSubscriptions.map(ma)},requestedAt:new Date(ne.meta.requestedAt)}}async function R(O){let k;O?.query&&(k=Nr(O.query));const{count:ne}=await r.get(Ae`/v2/c/inbox-notifications/count`,await t.getAuthValue({resource:"personal",access:"write"}),{query:k},{signal:O?.signal});return ne}async function q(){await r.post(Ae`/v2/c/inbox-notifications/read`,await t.getAuthValue({resource:"personal",access:"write"}),{inboxNotificationIds:"all"})}async function J(O){await r.post(Ae`/v2/c/inbox-notifications/read`,await t.getAuthValue({resource:"personal",access:"write"}),{inboxNotificationIds:O})}const X=new mr(async O=>{const k=O.flat();return await J(k),k},{delay:50});async function ie(O){await X.get(O)}async function ae(){await r.delete(Ae`/v2/c/inbox-notifications`,await t.getAuthValue({resource:"personal",access:"write"}))}async function we(O){await r.delete(Ae`/v2/c/inbox-notifications/${O}`,await t.getAuthValue({resource:"personal",access:"write"}))}async function Se(O){return r.get(Ae`/v2/c/notification-settings`,await t.getAuthValue({resource:"personal",access:"write"}),void 0,{signal:O?.signal})}async function me(O){return r.post(Ae`/v2/c/notification-settings`,await t.getAuthValue({resource:"personal",access:"write"}),O)}async function fe(O){let k;O?.query&&(k=Nr(O.query));const re=await r.get(Ae`/v2/c/threads`,await t.getAuthValue({resource:"personal",access:"write"}),{cursor:O?.cursor,query:k,limit:50});return{threads:re.threads.map(_n),inboxNotifications:re.inboxNotifications.map(sr),subscriptions:re.subscriptions.map(kn),nextCursor:re.meta.nextCursor,requestedAt:new Date(re.meta.requestedAt),permissionHints:re.meta.permissionHints}}async function ye(O){const k=await r.get(Ae`/v2/c/threads/delta`,await t.getAuthValue({resource:"personal",access:"write"}),{since:O.since.toISOString()},{signal:O.signal});return{threads:{updated:k.threads.map(_n),deleted:k.deletedThreads.map(ha)},inboxNotifications:{updated:k.inboxNotifications.map(sr),deleted:k.deletedInboxNotifications.map(pa)},subscriptions:{updated:k.subscriptions.map(kn),deleted:k.deletedSubscriptions.map(ma)},requestedAt:new Date(k.meta.requestedAt),permissionHints:k.meta.permissionHints}}const be=new mr(async O=>{const k=O.flat(),{groups:ne}=await r.post(Ae`/v2/c/groups/find`,await t.getAuthValue({resource:"personal",access:"write"}),{groupIds:k}),re=new Map;for(const he of ne)re.set(he.id,kl(he));return k.map(he=>re.get(he))},{delay:50}),xe=$o(be);function ke(O){return be.get(O)}async function Me(O){const{metadata:k}=await r.get(Ae`/v2/c/urls/metadata`,await t.getAuthValue({resource:"personal",access:"write"}),{url:O});return k}return{getThreads:s,getThreadsSince:o,searchComments:i,createThread:a,getThread:c,deleteThread:u,editThreadMetadata:d,createComment:m,editComment:g,editCommentMetadata:l,deleteComment:v,addReaction:C,removeReaction:p,markThreadAsResolved:D,markThreadAsUnresolved:w,subscribeToThread:b,unsubscribeFromThread:y,markRoomInboxNotificationAsRead:N,getSubscriptionSettings:L,updateSubscriptionSettings:F,createTextMention:_,deleteTextMention:I,fetchStorageHistoryVersion:j,fetchYjsHistoryVersion:z,createVersionHistorySnapshot:Y,deleteHistoryVersion:oe,reportTextEditor:G,listHistoryVersions:le,listHistoryVersionsSince:de,getAttachmentUrl:P,uploadAttachment:A,getOrCreateAttachmentUrlsStore:S,streamStorage:ue,getInboxNotifications:ee,getInboxNotificationsSince:te,getUnreadInboxNotificationsCount:R,markAllInboxNotificationsAsRead:q,markInboxNotificationAsRead:ie,deleteAllInboxNotifications:ae,deleteInboxNotification:we,getNotificationSettings:Se,updateNotificationSettings:me,getUserThreads_experimental:fe,getUserThreadsSince_experimental:ye,groupsStore:xe,getGroup:ke,executeContextualPrompt:Z,getUrlMetadata:Me}}function tc(e){return e.type==="public"?e.publicApiKey:e.token.raw}var k1=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}async#n(e,t,n,r){e.startsWith("/v2/c/")||Ft("This client can only be used to make /v2/c/* requests");const o=F1(this.#e,e,r),s=await this.#t(o,{...n,headers:{"Content-Type":"application/json; charset=utf-8",...n?.headers,Authorization:`Bearer ${tc(t)}`,"X-LB-Client":Ti}}),i=s.headers.get("X-LB-Warn");if(i){const a=n?.method?.toUpperCase()??"GET",u=`${i} (${a} ${e})`;s.ok?ft(u):Jn(u)}return s}async#r(e,t,n,r){const o=await this.#n(e,t,n,r);if(!o.ok)throw await uo.fromResponse(o);let s;try{s=await o.json()}catch{s={}}return s}async rawGet(e,t,n,r){return await this.#n(e,t,r,n)}async rawPost(e,t,n){return await this.#n(e,t,{method:"POST",body:co(n)})}async rawDelete(e,t){return await this.#n(e,t,{method:"DELETE"})}async get(e,t,n,r){return await this.#r(e,t,r,n)}async post(e,t,n,r,o){return await this.#r(e,t,{...r,method:"POST",body:co(n)},o)}async delete(e,t){return await this.#r(e,t,{method:"DELETE"})}async putBlob(e,t,n,r,o){return await this.#r(e,t,{...o,method:"PUT",headers:{"Content-Type":"application/octet-stream"},body:n},r)}},gr=Symbol("fsm.ignore");function N1(e,t){if(e===t)return[0,0];const n=e.split("."),r=t.split("."),o=Math.min(n.length,r.length);let s=0;for(;s<o&&n[s]===r[s];s++);const i=n.length-s,a=r.length-s;return[i,a]}function j1(e,t){const n=e.split(".");if(t<1||t>n.length+1)throw new Error("Invalid number of levels");const r=[];t>n.length&&r.push("*");for(let o=n.length-t+1;o<n.length;o++){const s=n.slice(0,o);s.length>0&&r.push(s.join(".")+".*")}return r.push(e),r}var L1=class{#e;constructor(e){this.#e=e}get current(){return this.#e}allowPatching(e){const t=this;let n=!0;const r={...this.#e,patch(o){if(n){t.#e=Object.assign({},t.#e,o);for(const s of Object.entries(o)){const[i,a]=s;i!=="patch"&&(this[i]=a)}}else throw new Error("Can no longer patch stale context")}};e(r),n=!1}},U1=1,Zh=class{id;#e;#t;#n;#r;#o;#s;events;#i;#u;#a;#l;get#f(){const e=this.#n.values()[Symbol.iterator]().next();if(e.done)throw new Error("No states defined yet");return e.value}get currentState(){if(this.#r===null)throw this.#e===0?new Error("Not started yet"):new Error("Already stopped");return this.#r}start(){if(this.#e!==0)throw new Error("State machine has already started");return this.#e=1,this.#r=this.#f,this.#p(null),this}stop(){if(this.#e!==1)throw new Error("Cannot stop a state machine that hasn't started yet");this.#h(null),this.#e=2,this.#r=null}constructor(e){this.id=U1++,this.#e=0,this.#r=null,this.#n=new Set,this.#a=new Map,this.#i=[],this.#u=[],this.#l=new Set,this.#o=new Map,this.#t=new L1(e),this.#s={didReceiveEvent:Ne(),willTransition:Ne(),didIgnoreUnexpectedEvent:Ne(),willExitState:Ne(),didEnterState:Ne(),didExitState:Ne()},this.events={didReceiveEvent:this.#s.didReceiveEvent.observable,willTransition:this.#s.willTransition.observable,didIgnoreUnexpectedEvent:this.#s.didIgnoreUnexpectedEvent.observable,willExitState:this.#s.willExitState.observable,didEnterState:this.#s.didEnterState.observable,didExitState:this.#s.didExitState.observable}}get context(){return this.#t.current}addState(e){if(this.#e!==0)throw new Error("Already started");return this.#n.add(e),this}onEnter(e,t){if(this.#e!==0)throw new Error("Already started");if(this.#a.has(e))throw new Error(`enter/exit function for ${e} already exists`);return this.#a.set(e,t),this}onEnterAsync(e,t,n,r,o){return this.onEnter(e,()=>{const s=new AbortController,i=s.signal,a=o?setTimeout(()=>{const c=new Error("Timed out");this.#d({type:"ASYNC_ERROR",reason:c},r)},o):void 0;let u=!1;return t(this.#t.current,i).then(c=>{i.aborted||(u=!0,this.#d({type:"ASYNC_OK",data:c},n))},c=>{i.aborted||(u=!0,this.#d({type:"ASYNC_ERROR",reason:c},r))}),()=>{clearTimeout(a),u||s.abort()}})}#m(e){const t=[];if(e==="*")for(const n of this.#n)t.push(n);else if(e.endsWith(".*")){const n=e.slice(0,-1);for(const r of this.#n)r.startsWith(n)&&t.push(r)}else{const n=e;this.#n.has(n)&&t.push(n)}if(t.length===0)throw new Error(`No states match ${JSON.stringify(e)}`);return t}addTransitions(e,t){if(this.#e!==0)throw new Error("Already started");for(const n of this.#m(e)){let r=this.#o.get(n);r===void 0&&(r=new Map,this.#o.set(n,r));for(const[o,s]of Object.entries(t)){if(r.has(o))throw new Error(`Trying to set transition "${o}" on "${n}" (via "${e}"), but a transition already exists there.`);const i=s;if(this.#l.add(o),i!==void 0)if(i===gr)r.set(o,gr);else{const a=typeof i=="function"?i:()=>i;r.set(o,a)}}}return this}addTimedTransition(e,t,n){return this.onEnter(e,()=>{const r=typeof t=="function"?t(this.#t.current):t,o=setTimeout(()=>{this.#d({type:"TIMER"},n)},r);return()=>{clearTimeout(o)}})}#g(e){return this.#o.get(this.currentState)?.get(e)}#h(e){this.#s.willExitState.notify(this.currentState);const t=performance.now(),n=this.currentState.split(".");this.#t.allowPatching(r=>{e=e??this.#i.length;for(let o=0;o<e;o++){this.#i.pop()?.(r);const s=this.#u.pop();if(s!==void 0&&this.#s.didExitState.count()>0){const i=this.#u.length;if(i===0)continue;const a=i===n.length?this.currentState:`${n.slice(0,i).join(".")}.*`;this.#s.didExitState.notify({state:a,durationMs:t-s})}}})}#p(e){const t=j1(this.currentState,e??this.currentState.split(".").length+1),n=performance.now();this.#t.allowPatching(r=>{for(const o of t){const i=this.#a.get(o)?.(r);typeof i=="function"?this.#i.push(i):this.#i.push(null),this.#u.push(n)}}),this.#s.didEnterState.notify(this.currentState)}send(e){if(!this.#l.has(e.type))throw new Error(`Invalid event ${JSON.stringify(e.type)}`);if(this.#e===2)return;const t=this.#g(e.type);if(t!==gr){if(t!==void 0)return this.#d(e,t);this.#s.didIgnoreUnexpectedEvent.notify(e)}}#d(e,t){this.#s.didReceiveEvent.notify(e);const n=this.currentState,o=(typeof t=="function"?t:()=>t)(e,this.#t.current);let s,i;if(o===gr)return;if(typeof o=="string"?s=o:(s=o.target,i=Array.isArray(o.effect)?o.effect:[o.effect]),!this.#n.has(s))throw new Error(`Invalid next state name: ${JSON.stringify(s)}`);this.#s.willTransition.notify({from:n,to:s});const[a,u]=N1(this.currentState,s);if(a>0&&this.#h(a),this.#r=s,i!==void 0){const c=i;this.#t.allowPatching(d=>{for(const l of c)typeof l=="function"?l(d,e):d.patch(l)})}u>0&&this.#p(u)}},Ee=Object.freeze({UPDATE_PRESENCE:100,USER_JOINED:101,USER_LEFT:102,BROADCASTED_EVENT:103,ROOM_STATE:104,STORAGE_STATE_V7:200,STORAGE_CHUNK:210,STORAGE_STREAM_END:211,UPDATE_STORAGE:201,UPDATE_YDOC:300,THREAD_CREATED:400,THREAD_DELETED:407,THREAD_METADATA_UPDATED:401,THREAD_UPDATED:408,COMMENT_CREATED:402,COMMENT_EDITED:403,COMMENT_DELETED:404,COMMENT_REACTION_ADDED:405,COMMENT_REACTION_REMOVED:406,COMMENT_METADATA_UPDATED:409,FEEDS_LIST:500,FEEDS_ADDED:501,FEEDS_UPDATED:502,FEED_DELETED:503,FEED_MESSAGES_LIST:504,FEED_MESSAGES_ADDED:505,FEED_MESSAGES_UPDATED:506,FEED_MESSAGES_DELETED:507,FEED_REQUEST_FAILED:508,REJECT_STORAGE_OP:299});function $l(e){return e===4999||e>=4e3&&e<4100}function $1(e){return e>=4100&&e<4200}function Hl(e){return e===1013||e>=4200&&e<4300}function H1(e){return e==="initial"||e==="disconnected"}function Xh(e){const t=e.currentState;switch(t){case"@ok.connected":case"@ok.awaiting-pong":return"connected";case"@idle.initial":return"initial";case"@auth.busy":case"@auth.backoff":case"@connecting.busy":case"@connecting.backoff":case"@idle.zombie":return e.context.successCount>0?"reconnecting":"connecting";case"@idle.failed":return"disconnected";default:return Je(t,"Unknown state")}}var Qh=[250,500,1e3,2e3,4e3,8e3,1e4],Is=Qh[0]-1,V1=[2e3,3e4,6e4,3e5],W1=3e4,z1=2e3,K1=1e4,G1=2e4,xn=class extends Error{constructor(e){super(e)}};function ep(e,t){return t.find(n=>n>e)??t[t.length-1]}function jr(e){e.patch({backoffDelay:ep(e.backoffDelay,Qh)})}function Vl(e){e.patch({backoffDelay:ep(e.backoffDelay,V1)})}function Wl(e){e.patch({successCount:0})}function Kr(e,t){const n=e===2?Jn:e===1?ft:(()=>{});return()=>{n(t)}}function zl(e){const t="Connection to Liveblocks websocket server";return n=>{tp(e)?ft(`${t} closed prematurely (code: ${e.code}). Retrying in ${n.backoffDelay}ms.`):ft(`${t} could not be established.`,e)}}function ga(e){const t=[`code: ${e.code}`];return e.reason&&t.push(`reason: ${e.reason}`),n=>{ft(`Connection to Liveblocks websocket server closed (${t.join(", ")}). Retrying in ${n.backoffDelay}ms.`)}}var q1=Kr(1,"Connection to WebSocket closed permanently. Won't retry.");function tp(e){return!(e instanceof Error)&&e.type==="close"}function Y1(e){function t(...r){ft(`[FSM #${e.id}]`,...r)}const n=[e.events.didReceiveEvent.subscribe(r=>t(`Event ${r.type}`)),e.events.willTransition.subscribe(({from:r,to:o})=>t("Transitioning",r,"→",o)),e.events.didExitState.subscribe(({state:r,durationMs:o})=>t(`Exited ${r} after ${o.toFixed(0)}ms`)),e.events.didIgnoreUnexpectedEvent.subscribe(r=>t("Ignored unexpected event",r.type,r,"(no transition declared)"))];return()=>{for(const r of n)r()}}function J1(e){const t=Ne(),n=Ne(),r=Ne();let o=null;const s=e.events.didEnterState.subscribe(()=>{const i=Xh(e);i!==o&&t.notify(i),o==="connected"&&i!=="connected"?r.notify():o!=="connected"&&i==="connected"&&n.notify(),o=i});return{statusDidChange:t.observable,didConnect:n.observable,didDisconnect:r.observable,unsubscribe:s}}var Bs=e=>t=>t.patch(e);function Z1(e,t){const n=a1();n.pause();const r=Ne();function o(w,b){return()=>{r.notify({message:w,code:b})}}const s={successCount:0,authValue:null,socket:null,backoffDelay:Is},i=new Zh(s).addState("@idle.initial").addState("@idle.failed").addState("@idle.zombie").addState("@auth.busy").addState("@auth.backoff").addState("@connecting.busy").addState("@connecting.backoff").addState("@ok.connected").addState("@ok.awaiting-pong");i.addTransitions("*",{RECONNECT:{target:"@auth.backoff",effect:[jr,Wl]},DISCONNECT:"@idle.initial"}),i.onEnter("@idle.*",Wl).addTransitions("@idle.*",{CONNECT:(w,b)=>b.authValue!==null?"@connecting.busy":"@auth.busy"}),i.addTransitions("@auth.backoff",{NAVIGATOR_ONLINE:{target:"@auth.busy",effect:Bs({backoffDelay:Is})}}).addTimedTransition("@auth.backoff",w=>w.backoffDelay,"@auth.busy").onEnterAsync("@auth.busy",()=>Pl(e.authenticate(),K1,"Timed out during auth"),w=>({target:"@connecting.busy",effect:Bs({authValue:w.data})}),w=>w.reason instanceof xn?{target:"@idle.failed",effect:[Kr(2,w.reason.message),o(w.reason.message,-1)]}:{target:"@auth.backoff",effect:[jr,Kr(2,`Authentication failed: ${w.reason instanceof Error?w.reason.message:String(w.reason)}`)]});const a=w=>i.send({type:"EXPLICIT_SOCKET_ERROR",event:w}),u=w=>i.send({type:"EXPLICIT_SOCKET_CLOSE",event:w}),c=w=>{i.send({type:"ALIVE"}),w.data!=="pong"&&n.notify(w)};function d(w){w&&(w.removeEventListener("error",a),w.removeEventListener("close",u),w.removeEventListener("message",c),w.close())}i.addTransitions("@connecting.backoff",{NAVIGATOR_ONLINE:{target:"@connecting.busy",effect:Bs({backoffDelay:Is})}}).addTimedTransition("@connecting.backoff",w=>w.backoffDelay,"@connecting.busy").onEnterAsync("@connecting.busy",async(w,b)=>{const y=performance.now();let A=null,T=null,S=null;const P=new Promise((L,F)=>{if(w.authValue===null)throw new Error("No auth authValue");const M=e.createSocket(w.authValue);S=M;function N(z){T=z,M.removeEventListener("message",c),F(z)}const[_,I]=Kh();t.waitForActorId||I();function j(z){if(Sn(z.data)?.type===Ee.ROOM_STATE){if(t.enableDebugLogging&&A!==null){const oe=performance.now()-A;ft(`[FSM #${i.id}] Socket open → ROOM_STATE: ${oe.toFixed(0)}ms`)}I()}}M.addEventListener("message",c),t.waitForActorId&&M.addEventListener("message",j),M.addEventListener("error",N),M.addEventListener("close",N),M.addEventListener("open",()=>{if(A=performance.now(),t.enableDebugLogging){const Y=A-y;ft(`[FSM #${i.id}] Socket epoch → open: ${Y.toFixed(0)}ms`)}M.addEventListener("error",a),M.addEventListener("close",u);const z=()=>{M.removeEventListener("error",N),M.removeEventListener("close",N),M.removeEventListener("message",j)};_.then(()=>{L([M,z])})})});return Pl(P,G1,"Timed out during websocket connection").then(([L,F])=>{if(F(),b.aborted)throw new Error("Aborted");if(T)throw T;return L}).catch(L=>{throw d(S),L})},w=>({target:"@ok.connected",effect:Bs({socket:w.data,backoffDelay:Is})}),w=>{const b=w.reason;if(b instanceof xn)return{target:"@idle.failed",effect:[Kr(2,b.message),o(b.message,-1)]};if(tp(b)){if(b.code===4109)return"@auth.busy";if(Hl(b.code))return{target:"@connecting.backoff",effect:[Vl,zl(b)]};if($l(b.code))return{target:"@idle.failed",effect:[Kr(2,b.reason),o(b.reason,b.code)]}}return{target:"@auth.backoff",effect:[jr,zl(b)]}}).addTransitions("@connecting.busy",{ALIVE:gr});const l={target:"@ok.awaiting-pong",effect:w=>{w.socket?.send("ping")}},m=()=>(typeof document<"u"?document:void 0)?.visibilityState==="hidden"&&e.canZombie()?"@idle.zombie":l;if(i.addTimedTransition("@ok.connected",W1,m).addTransitions("@ok.connected",{NAVIGATOR_OFFLINE:m,WINDOW_GOT_FOCUS:l,ALIVE:gr}),i.addTransitions("@idle.zombie",{WINDOW_GOT_FOCUS:"@connecting.backoff"}),i.onEnter("@ok.*",w=>{w.patch({successCount:w.successCount+1});const b=setTimeout(n.unpause,0);return y=>{d(y.socket),y.patch({socket:null}),clearTimeout(b),n.pause()}}).addTransitions("@ok.awaiting-pong",{ALIVE:"@ok.connected"}).addTimedTransition("@ok.awaiting-pong",z1,{target:"@connecting.busy",effect:Kr(1,"Received no pong from server, assume implicit connection loss.")}).addTransitions("@ok.*",{EXPLICIT_SOCKET_ERROR:(w,b)=>b.socket?.readyState===1?gr:{target:"@connecting.backoff",effect:jr},EXPLICIT_SOCKET_CLOSE:w=>$l(w.event.code)?{target:"@idle.failed",effect:[q1,o(w.event.reason,w.event.code)]}:$1(w.event.code)?w.event.code===4109?"@auth.busy":{target:"@auth.backoff",effect:[jr,ga(w.event)]}:Hl(w.event.code)?{target:"@connecting.backoff",effect:[Vl,ga(w.event)]}:{target:"@connecting.backoff",effect:[jr,ga(w.event)]}}),typeof document<"u"){const w=typeof document<"u"?document:void 0,b=typeof window<"u"?window:void 0,y=b??w;i.onEnter("*",A=>{function T(){i.send({type:"NAVIGATOR_OFFLINE"})}function S(){i.send({type:"NAVIGATOR_ONLINE"})}function P(){w?.visibilityState==="visible"&&i.send({type:"WINDOW_GOT_FOCUS"})}return b?.addEventListener("online",S),b?.addEventListener("offline",T),y?.addEventListener("visibilitychange",P),()=>{y?.removeEventListener("visibilitychange",P),b?.removeEventListener("online",S),b?.removeEventListener("offline",T),d(A.socket)}})}const g=[],{statusDidChange:v,didConnect:C,didDisconnect:p,unsubscribe:D}=J1(i);return g.push(D),t.enableDebugLogging&&g.push(Y1(i)),i.start(),{machine:i,cleanups:g,events:{statusDidChange:v,didConnect:C,didDisconnect:p,onMessage:n.observable,onConnectionError:r.observable}}}var np=class{#e;#t;events;constructor(e,t=!1,n=!0){const{machine:r,events:o,cleanups:s}=Z1(e,{waitForActorId:n,enableDebugLogging:t});this.#e=r,this.events=o,this.#t=s}getStatus(){try{return Xh(this.#e)}catch{return"initial"}}get authValue(){return this.#e.context.authValue}connect(){this.#e.send({type:"CONNECT"})}reconnect(){this.#e.send({type:"RECONNECT"})}disconnect(){this.#e.send({type:"DISCONNECT"})}destroy(){this.#e.stop();let e;for(;e=this.#t.pop();)e()}send(e){const t=this.#e.context?.socket;t===null?ft("Cannot send: not connected yet",e):t.readyState!==1?ft("Cannot send: WebSocket no longer open",e):t.send(e)}_privateSendMachineEvent(e){this.#e.send(e)}},Ce=Symbol(),Kl=Object.freeze({}),X1=Array.from(new Set("null")),Q1=Array.from(new Set("true")),eE=Array.from(new Set("false")),tE=Array.from(new Set("nulltruefalse"));function va(e,t){const n=e[e.length-1];return t.includes(n)?e.slice(0,-1):e}var nE=class{#e="";#t;#n=0;#r=!1;#o=-1;#s=-1;#i=[];constructor(e=""){this.append(e)}get source(){return this.#e}get json(){return this.#t===void 0&&(this.#t=this.#f()),this.#t}get#u(){return this.#o>=0}append(e){e&&(this.#e===""&&(e=e.trimStart()),this.#e+=e,this.#t=void 0)}#a(e){if(this.#u)return"";const t=e.charAt(e.length-1);if(t==="")return"";if(t==="-")return"0";if(!tE.includes(t))return"";if(X1.includes(t)){if(e.endsWith("nul"))return"l";if(e.endsWith("nu"))return"ll";if(e.endsWith("n"))return"ull"}if(Q1.includes(t)){if(e.endsWith("tru"))return"e";if(e.endsWith("tr"))return"ue";if(e.endsWith("t"))return"rue"}if(eE.includes(t)){if(e.endsWith("fals"))return"e";if(e.endsWith("fal"))return"se";if(e.endsWith("fa"))return"lse";if(e.endsWith("f"))return"alse"}return""}#l(){const e=this.#e.slice(this.#n);for(let t=0;t<e.length;t++){const n=e[t],r=this.#n+t;this.#u?this.#r?this.#r=!1:n==="\\"?this.#r=!0:n==='"'&&(this.#s=this.#o,this.#o=-1):n==='"'?this.#o=r:n==="{"?this.#i.push("}"):n==="["?this.#i.push("]"):n==="}"&&this.#i.length>0&&this.#i[this.#i.length-1]==="}"?this.#i.pop():n==="]"&&this.#i.length>0&&this.#i[this.#i.length-1]==="]"&&this.#i.pop()}this.#n=this.#e.length}#f(){this.#l();let e=this.#e;if(e.charAt(0)!=="{")return Kl;if(e.endsWith("}")){const n=Sn(e);if(n)return n}this.#u&&(this.#r&&(e=e.slice(0,-1)),e+='"'),e=e.trimEnd(),e=va(e,",."),e=e+this.#a(e);const t=this.#i.reduceRight((n,r)=>n+r,"");{const n=Sn(e+t);if(n)return n}return this.#u?e=e.slice(0,this.#o):(e=va(e,":"),e.endsWith('"')&&(e=e.slice(0,this.#s))),e=va(e,","),e+=t,Sn(e)??Kl}};function rE(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!Object.is(e[n],t[n]))return!1;return!0}function oE(e,t){if(!lt(e)||!lt(t))return!1;const n=Object.keys(e);return n.length!==Object.keys(t).length?!1:n.every(r=>Object.prototype.hasOwnProperty.call(t,r)&&Object.is(e[r],t[r]))}function at(e,t){if(Object.is(e,t))return!0;const n=Array.isArray(e),r=Array.isArray(t);return n||r?!n||!r?!1:rE(e,t):oE(e,t)}function Gr(e,t){if(!lt(e)||!lt(t))return at(e,t);const n=Object.keys(e);return n.length!==Object.keys(t).length?!1:n.every(r=>Object.prototype.hasOwnProperty.call(t,r)&&at(e[r],t[r]))}var sE=class{#e;#t;#n;#r;#o;#s;constructor(e,t,n){this.#r=e,this.#o=t,this.#s=n,this.#e=new Map,this.#t=new Le(()=>new Set),this.#n=zn.with(n)}get(e){return this.#e.get(e)}getOrThrow(e){return this.get(e)??Ft(`Item with id ${e} not found`)}get sorted(){return this.#n}getParentId(e){const t=this.getOrThrow(e);return this.#o(t)}getParent(e){const t=this.getParentId(e);return t?this.getOrThrow(t):null}getChildren(e){const t=this.#t.get(e);return t?Array.from(t).map(n=>this.#e.get(n)):[]}*walkUp(e,t){let n=e;do{const r=this.getOrThrow(n);(!t||t(r))&&(yield r),n=this.#o(r)}while(n!==null)}*walkLeft(e,t){const n=this.getOrThrow(e),r=zn.from(this.getSiblings(e),this.#s);for(const o of r.iterReversed())this.#s(n,o)||(!t||t(o))&&(yield o)}*walkRight(e,t){const n=this.getOrThrow(e),r=zn.from(this.getSiblings(e),this.#s);for(const o of r)this.#s(o,n)||(!t||t(o))&&(yield o)}*walkDown(e,t){const n=zn.from(this.getChildren(e),this.#s).rawArray;for(let r=n.length-1;r>=0;r--){const o=n[r];yield*this.walkDown(this.#r(o),t),(!t||t(o))&&(yield o)}}getSiblings(e){const t=this.getOrThrow(e),n=this.getParentId(e);return this.getChildren(n).filter(r=>r!==t)}[Symbol.iterator](){return this.#n[Symbol.iterator]()}upsert(e){const t=this.#r(e),n=this.#e.get(t);if(n){if(this.#o(n)!==this.#o(e))throw new Error("Cannot upsert parent ID changes that change the tree structure. Remove the entry first, and recreate it");this.#n.remove(n)}this.#e.set(t,e),this.#n.add(e);const r=this.#o(e);this.#t.getOrCreate(r).add(t)}remove(e){const t=this.#e.get(e);if(!t)return!1;if(this.#t.get(e))throw new Error(`Cannot remove item '${e}' while it still has children. Remove children first.`);const r=this.#o(t),o=this.#t.get(r);return o&&(o.delete(e),o.size===0&&this.#t.delete(r)),this.#n.remove(t),this.#t.delete(e),this.#e.delete(e),!0}clear(){return this.#e.size===0?!1:(this.#t.clear(),this.#e.clear(),this.#n.clear(),!0)}},iE=4e3,aE=class{#e;#t;#n;constructor(){this.#e=new Set,this.#t=new Le(()=>new Map),this.#n=void 0}registerLayer(e){const t=e;return this.#e.has(t)&&Ft(`Layer '${t}' already exists, provide a unique layer id`),this.#e.add(t),t}deregisterLayer(e){this.#e.delete(e);let t=!1;for(const[n,r]of this.#t)r.delete(e)&&(t=!0),r.size===0&&this.#t.delete(n);t&&this.invalidate()}get(){return this.#n??=this.#r()}invalidate(){this.#n=void 0}#r(){return Array.from(this.#t.values()).flatMap(e=>Array.from(e.values()).slice(-1).filter(E1))}updateKnowledge(e,t,n){this.#e.has(e)||Ft(`Unknown layer key: ${e}`),this.#t.getOrCreate(t).set(e,n),this.invalidate()}};function uE(){const e=new Le(r=>new aE);function t(r){return e.getOrCreate(r??Ho)}function n(r){const o=e.getOrCreate(Ho).get(),s=e.get(r)?.get()??[];return[...o,...s]}return{getKnowledgeStack:t,getKnowledgeForChat:n}}function Ca(){return new Date().toISOString()}var Ho=Symbol("*");function cE(){const e=new Le(i=>new Le(a=>new St(void 0))),t=new Le(i=>{const[a,u]=Sn(i);return je.from(()=>(u!==void 0?e.getOrCreate(u).getOrCreate(a):void 0)?.get()??e.getOrCreate(Ho).getOrCreate(a).get())});function n(i,a){const u=JSON.stringify(a!==void 0?[i,a]:[i]);return t.getOrCreate(u)}function r(i,a,u){if(!a.execute&&!a.render)throw new Error("A tool definition must have an execute() function, a render() function, or both.");const c=u??Ho;return e.getOrCreate(c).getOrCreate(i).set(a),()=>o(c,i)}function o(i,a){const u=e.get(i);if(u===void 0)return;const c=u.get(a);c!==void 0&&c.set(void 0)}function s(i){const a=e.get(Ho),u=e.get(i);return Array.from([...a?.entries()??[],...u?.entries()??[]]).flatMap(([c,d])=>{const l=d.get();return l&&(l.enabled??!0)?[{name:c,description:l.description,parameters:l.parameters}]:[]})}return{getToolDescriptions:s,getToolΣ:n,registerTool:r}}function lE(e,t){const n=new Set,r=new Set,o=new Le(y=>new xt(new sE(A=>A.id,A=>A.parentId,(A,T)=>A.createdAt<T.createdAt))),s=new xt(new Map);function i(y,A,T,S){const P=`ms_${it()}`,L=Ca();return d(A==="user"?{id:P,chatId:y,role:A,parentId:T,createdAt:L,content:S,_optimistic:!0}:{id:P,chatId:y,role:A,parentId:T,createdAt:L,status:"generating",contentSoFar:[],copilotId:S,_optimistic:!0}),P}function a(y){Ze(()=>{for(const A of y)d(A)})}function u(y,A){const T=o.get(y);if(!T)return;const S=T.get().get(A);!S||S.deletedAt||(S.role==="assistant"&&S.status!=="completed"?d({...S,deletedAt:Ca(),contentSoFar:[]}):d({...S,deletedAt:Ca(),content:[]}))}function c(y){const A=o.get(y);A!==void 0&&A.mutate(T=>T.clear())}function d(y){Ze(()=>{if(o.getOrCreate(y.chatId).mutate(T=>T.upsert(y)),y.role==="assistant"&&y.status==="generating"?s.mutate(T=>{T.set(y.id,structuredClone(y))}):s.mutate(T=>{T.delete(y.id)}),y.role==="assistant"&&y.status==="awaiting-tool"){if(n.has(y.id))for(const T of y.contentSoFar.filter(S=>S.type==="tool-invocation"&&S.stage==="executing")){if(!r.has(T.invocationId))r.add(T.invocationId);else continue;const S=e.getToolΣ(T.name,y.chatId).get()?.execute;S&&(async()=>{const P=await S(T.args,{name:T.name,invocationId:T.invocationId});return await t(y.chatId,y.id,T.invocationId,P??{data:{}},{copilotId:y.copilotId})})().catch(P=>{Jn(`Error trying to respond to tool-call: ${String(P)} (in execute())`)})}}else y.role==="assistant"&&y.status==="generating"||n.delete(y.id)})}function l(y,A){s.mutate(T=>{const S=T.get(y);return S===void 0?!1:(pE(S.contentSoFar,A),T.set(y,S),!0)})}function*m(){for(const y of o.values())for(const A of y.get())A.role==="assistant"&&A.status==="generating"&&!A._optimistic&&(yield A)}function g(){Ze(()=>{s.mutate(y=>{let A=!1;for(const[T,S]of y)S._optimistic||(y.delete(T),A=!0);return A}),a(Array.from(m()).map(y=>({...y,status:"failed",errorReason:"Lost connection"})))})}function v(y){for(const A of o.values()){const T=A.get().get(y);if(T)return T}}function C(y){const A=y.next();return A.done?void 0:A.value}function p(y,A){function T(F){if(!F.deletedAt)return!0;for(const M of y.walkDown(F.id,N=>!N.deletedAt))return!0;return!1}function S(F){const M=[];let N=null;for(const _ of y.walkUp(F.id)){const I=C(y.walkLeft(_.id,T))?.id??null,j=C(y.walkRight(_.id,T))?.id??null;if(!_.deletedAt||I||j){const z={..._,navigation:{parent:null,prev:I,next:j}};N!==null&&(N.navigation.parent=z.id),N=z,M.push(z)}}return M.reverse()}function P(){const F=y.sorted.findRight(M=>!M.deletedAt);return F?S(F):[]}if(A===null)return P();const L=y.get(A);if(!L)return P();for(const F of y.walkUp(L.id)){for(const M of y.walkDown(F.id,N=>!N.deletedAt))return S(M);if(!F.deletedAt)return S(F)}return P()}const D=new Le(y=>new Le(A=>{const T=je.from(()=>{const S=o.getOrCreate(y).get();return p(S,A)},Gr);return je.from(()=>{const S=s.get();return T.get().map(P=>{if(P.role!=="assistant"||P.status!=="generating")return P;const L=S.get(P.id);return L===void 0?P:{...P,contentSoFar:L.contentSoFar}})},at)}));function w(y,A){return D.getOrCreate(y).getOrCreate(A||null)}function b(y){return o.getOrCreate(y).get().sorted.findRight(S=>S.role==="assistant"&&!S.deletedAt)?.copilotId}return{getMessageById:v,getChatMessagesForBranchΣ:w,getLastUsedCopilotId:b,createOptimistically:i,upsert:d,upsertMany:a,remove:u,removeByChatId:c,addDelta:l,failAllPending:g,markMine(y){n.add(y)},*getAutoExecutingMessageIds(){for(const y of n){const A=v(y);A?.role==="assistant"&&A.status==="awaiting-tool"&&A.contentSoFar.some(S=>S.type==="tool-invocation"&&S.stage==="executing"?typeof e.getToolΣ(S.name,A.chatId).get()?.execute=="function":!1)&&(yield A.id)}}}}function dE(){const e=new m1;function t(i){Ze(()=>{for(const a of i)e.upsert(a)})}function n(i){e.upsert(i)}function r(i){e.markDeleted(i)}function o(i){return e.getEvenIfDeleted(i)}function s(i){return e.signal.get().findMany(i)}return{getChatById:o,findMany:s,upsert:n,upsertMany:t,markDeleted:r}}function fE(e){const t=new np(e.delegates,e.enableDebugLogging,!1),n=dE(),r=cE(),o=uE(),s=lE(r,F),i={staticSessionInfoSig:new St(null),dynamicSessionInfoSig:new St(null),pendingCmds:new Map,chatsStore:n,messagesStore:s,toolsStore:r,knowledgeStore:o},a=new St("initial"),u=25;let c=[],d=null;function l(){const _=c;c=[],d!==null&&(clearTimeout(d),d=null),Ze(()=>{for(const{id:I,delta:j}of _)i.messagesStore.addDelta(I,j)})}function m(_,I){c.push({id:_,delta:I}),d===null&&(d=setTimeout(l,u))}let g;function v(_){const I=t.authValue;if(I!==null){const j=tc(I);if(j!==g)if(g=j,I.type==="secret"){const z=I.token.parsed;i.staticSessionInfoSig.set({userId:z.uid,userInfo:z.ui})}else i.staticSessionInfoSig.set({userId:void 0,userInfo:void 0})}a.set(_)}let C;function p(_){_==="reconnecting"?C=setTimeout(()=>{},e.lostConnectionTimeout):clearTimeout(C)}function D(){}function w(){l()}function b(_){if(typeof _.data!="string")return;const I=Sn(_.data);if(!I)return;const j="cmdId"in I?I.cmdId:I.event==="cmd-failed"?I.failedCmdId:void 0,z=i.pendingCmds.get(j);if(j&&!z){ft("Ignoring unexpected command response. Already timed out, or not for us?",I);return}if("event"in I)if(I.event==="delta"){const{id:Y,delta:oe}=I;m(Y,oe)}else Ze(()=>{switch(l(),I.event){case"cmd-failed":z?.reject(new Error(I.error));break;case"settle":{i.messagesStore.upsert(I.message);break}case"warning":ft(I.message);break;case"error":Jn(I.error);break;case"rebooted":i.messagesStore.failAllPending();break;case"sync":for(const Y of I["-messages"]??[])i.messagesStore.remove(Y.chatId,Y.id);for(const Y of I["-chats"]??[])i.chatsStore.markDeleted(Y),i.messagesStore.removeByChatId(Y);for(const Y of I.clear??[])i.messagesStore.removeByChatId(Y);I.chats&&i.chatsStore.upsertMany(I.chats),I.messages&&i.messagesStore.upsertMany(I.messages);break;default:return Je(I,"Unhandled case")}});else switch(I.cmd){case"get-chats":i.chatsStore.upsertMany(I.chats);break;case"get-or-create-chat":i.chatsStore.upsert(I.chat);break;case"delete-chat":i.chatsStore.markDeleted(I.chatId),i.messagesStore.removeByChatId(I.chatId);break;case"get-message-tree":i.chatsStore.upsert(I.chat),i.messagesStore.upsertMany(I.messages);break;case"delete-message":i.messagesStore.remove(I.chatId,I.messageId);break;case"clear-chat":i.messagesStore.removeByChatId(I.chatId);break;case"ask-in-chat":I.sourceMessage&&i.messagesStore.upsert(I.sourceMessage),i.messagesStore.upsert(I.targetMessage);break;case"abort-ai":break;case"set-tool-result":I.ok&&i.messagesStore.upsert(I.message);break;default:return Je(I,"Unhandled case")}z?.resolve(I)}t.events.onMessage.subscribe(b),t.events.statusDidChange.subscribe(v),t.events.statusDidChange.subscribe(p),t.events.didConnect.subscribe(D),t.events.didDisconnect.subscribe(w),t.events.onConnectionError.subscribe(({message:_,code:I})=>{});function y(){t.getStatus()==="initial"&&t.connect()}async function A(_){y(),t.getStatus()!=="connected"&&await t.events.didConnect.waitUntil();const{promise:I,resolve:j,reject:z}=Jr(),Y=AbortSignal.timeout(iE);Y.addEventListener("abort",()=>z(Y.reason),{once:!0});const oe=it(7);return i.pendingCmds.set(oe,{resolve:j,reject:z}),T({..._,cmdId:oe}),I.finally(()=>{i.pendingCmds.delete(oe)}).catch(G=>{throw Jn(G.message),G})}function T(_){t.send(JSON.stringify({..._}))}function S(_={}){return A({cmd:"get-chats",cursor:_.cursor,query:_.query})}function P(_,I){return A({cmd:"get-or-create-chat",id:_,options:I})}function L(_){return A({cmd:"get-message-tree",chatId:_})}async function F(_,I,j,z,Y){const oe=i.knowledgeStore.getKnowledgeForChat(_),G=i.toolsStore.getToolDescriptions(_),Z=await A({cmd:"set-tool-result",chatId:_,messageId:I,invocationId:j,result:z,generationOptions:{copilotId:Y?.copilotId,stream:Y?.stream,timeout:Y?.timeout,knowledge:oe.length>0?oe:void 0,tools:G.length>0?G:void 0}});Z.ok&&s.markMine(Z.message.id)}function M(){for(const _ of i.messagesStore.getAutoExecutingMessageIds())A({cmd:"abort-ai",messageId:_}).catch(()=>{})}return(typeof window<"u"?window:void 0)?.addEventListener("beforeunload",M,{once:!0}),Object.defineProperty({[Ce]:{context:i},connectInitially:y,disconnect:()=>t.disconnect(),getChats:S,getOrCreateChat:P,deleteChat:_=>A({cmd:"delete-chat",chatId:_}),getMessageTree:L,deleteMessage:(_,I)=>A({cmd:"delete-message",chatId:_,messageId:I}),clearChat:_=>A({cmd:"clear-chat",chatId:_}),askUserMessageInChat:async(_,I,j,z)=>{const Y=i.knowledgeStore.getKnowledgeForChat(_),oe=z?.knowledge||[],G=[...Y,...oe],Z=i.toolsStore.getToolDescriptions(_);return s.markMine(j),await A({cmd:"ask-in-chat",chatId:_,sourceMessage:I,targetMessageId:j,generationOptions:{copilotId:z?.copilotId,stream:z?.stream,timeout:z?.timeout,knowledge:G.length>0?G:void 0,tools:Z.length>0?Z:void 0}})},abort:_=>A({cmd:"abort-ai",messageId:_}),setToolResult:F,getStatus:()=>t.getStatus(),signals:{getChatMessagesForBranchΣ:i.messagesStore.getChatMessagesForBranchΣ,getToolΣ:i.toolsStore.getToolΣ,statusΣ:a},getChatById:i.chatsStore.getChatById,queryChats:i.chatsStore.findMany,getLastUsedCopilotId:i.messagesStore.getLastUsedCopilotId,registerKnowledgeLayer:(_,I)=>{const j=i.knowledgeStore.getKnowledgeStack(I),z=j.registerLayer(_);return{layerKey:z,deregister:()=>j.deregisterLayer(z)}},updateKnowledge:(_,I,j,z)=>{i.knowledgeStore.getKnowledgeStack(z).updateKnowledge(_,j??it(),I)},registerTool:i.toolsStore.registerTool},Ce,{enumerable:!1})}function hE(e,t){return n=>{const r=t??(typeof WebSocket>"u"?void 0:WebSocket);if(r===void 0)throw new xn("To use Liveblocks client in a non-DOM environment, you need to provide a WebSocket polyfill.");const o=new URL(e);if(o.protocol=o.protocol==="http:"?"ws":"wss",o.pathname="/ai/v7",n.type==="secret")o.searchParams.set("tok",n.token.raw);else{if(n.type==="public")throw new Error("Public key not supported with AI Copilots");return Je(n,"Unhandled case")}return o.searchParams.set("version",Ti),new r(o.toString())}}function Gl(e,t,n,r){const o=Lh(e,s=>s.type===t.type&&n(s)===n(t));o>-1?e[o]=t:(uu(e[e.length-1],r),e.push(t))}function uu(e,t){e?.type==="reasoning"&&(e.endedAt??=t)}function pE(e,t){if(t===null)return;const n=e.filter(i=>i.type!=="sources"),r=e.filter(i=>i.type==="sources").flatMap(i=>i.sources),o=new Date().toISOString(),s=n[n.length-1];switch(t.type){case"text-delta":s?.type==="text"?s.text+=t.textDelta:(uu(s,o),n.push({type:"text",text:t.textDelta}));break;case"reasoning-delta":s?.type==="reasoning"?s.text+=t.textDelta:(uu(s,o),n.push({type:"reasoning",text:t.textDelta,startedAt:o}));break;case"tool-stream":{const i=mE(t.invocationId,t.name);n.push(i);break}case"tool-delta":{s?.type==="tool-invocation"&&s.stage==="receiving"&&s.__appendDelta?.(t.delta);break}case"tool-invocation":Gl(n,t,i=>i.invocationId,o);break;case"retrieval":Gl(n,t,i=>i.id,o);break;case"source":{r.push(t);break}default:return Je(t,"Unhandled case")}r.length>0&&n.push({type:"sources",sources:r}),e.length=0,e.push(...n)}function mE(e,t,n=""){const r=new nE(n);return{type:"tool-invocation",stage:"receiving",invocationId:e,name:t,get partialArgsText(){return r.source},get partialArgs(){return r.json},__appendDelta(o){r.append(o)}}}var Qe={Read:"*:read",Write:"*:write",RoomWrite:"room:write",RoomRead:"room:read",StorageRead:"storage:read",StorageWrite:"storage:write",StorageNone:"storage:none",CommentsWrite:"comments:write",CommentsRead:"comments:read",CommentsNone:"comments:none",CommentsPublicWrite:"comments:public:write",CommentsPublicRead:"comments:public:read",CommentsPublicNone:"comments:public:none",CommentsPrivateWrite:"comments:private:write",CommentsPrivateRead:"comments:private:read",CommentsPrivateNone:"comments:private:none",FeedsRead:"feeds:read",FeedsWrite:"feeds:write",FeedsNone:"feeds:none",LegacyRoomPresenceWrite:"room:presence:write"},gE=["none","read","write"],hr={none:0,read:1,write:2},vE={room:{read:[Qe.Read,Qe.RoomRead],write:[Qe.Write,Qe.RoomWrite]},storage:{write:[Qe.StorageWrite],read:[Qe.StorageRead],none:[Qe.StorageNone]},comments:{write:[Qe.CommentsWrite],read:[Qe.CommentsRead],none:[Qe.CommentsNone]},"comments:public":{write:[Qe.CommentsPublicWrite],read:[Qe.CommentsPublicRead],none:[Qe.CommentsPublicNone]},"comments:private":{write:[Qe.CommentsPrivateWrite],read:[Qe.CommentsPrivateRead],none:[Qe.CommentsPrivateNone]},feeds:{write:[Qe.FeedsWrite],read:[Qe.FeedsRead],none:[Qe.FeedsNone]}},CE={room:"none",storage:"none",comments:"none","comments:public":"none","comments:private":"none",feeds:"none",personal:"none"},EE="room",rp=["storage","comments","comments:public","comments:private","feeds"],yE=new Set(Object.values(Qe));function bE(e){return yE.has(e)}function ql(e,t){const n=vE[t];let r;for(const o of gE){const s=n[o];s!==void 0&&s.some(i=>e.includes(i))&&(r=o)}return r}function op(e){const t={},n=ql(e,EE);n!==void 0&&(t.room=n);for(const r of rp){const o=ql(e,r);o!==void 0&&(t[r]=o)}return t}function sp(e){const t=e.room;if(t===void 0)return{...CE};const n=e.comments??t;return{room:t,storage:e.storage??t,comments:n,"comments:public":e["comments:public"]??n,"comments:private":e["comments:private"]??n,feeds:e.feeds??t,personal:"write"}}function nc(e){return sp(op(e))}function Yn(e,t,n){const r=hr[n];if(t==="comments")return Math.max(hr[e.comments??"none"],hr[e["comments:public"]??"none"],hr[e["comments:private"]??"none"])>=r;const o=e[t]??"none";return hr[o]>=r}function wE(e,t){const n=e.filter(s=>AE(s.pattern,t));if(n.length===0)return;const r={},o={};for(const s of n){const i=op(s.scopes),a=SE(s.pattern);i.room!==void 0&&(r.room=Yl(r.room??"none",i.room));for(const u of rp){const c=DE(i,u);if(c===void 0)continue;const d=o[u]??-1;a>d?(r[u]=c,o[u]=a):a===d&&(r[u]=Yl(r[u]??"none",c))}}return sp(r)}function rc(e){if(!Array.isArray(e))throw new Error("Permission list must be an array");const t=[];for(const n of e){if(!bE(n))throw new Error(`Not a valid permission: ${n}`);t.push(n)}return t}function DE(e,t){return e[t]??(xE(t)?e.comments:void 0)}function Yl(e,t){return hr[t]>hr[e]?t:e}function AE(e,t){return e.includes("*")?t.startsWith(e.replace("*","")):e===t}function SE(e){return e.replace("*","").length}function xE(e){return e.startsWith("comments:")}function OE(e){return lt(e)&&(e.k==="acc"||e.k==="id")}function Jl(e){const t=e.split(".");if(t.length!==3)throw new Error("Authentication error: invalid JWT token");const n=Sn(l1(t[1]));if(!(n&&OE(n)))throw new Error("Authentication error: expected a valid 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");return{raw:e,parsed:n}}var TE=[400,401,403,404,405,410,412,414,422,431,451];function RE(e,t){const n=PE(e),r=new Set,o=[],s=new Map;function i(){r.clear(),o.length=0,s.clear()}function a(d){const l=Math.ceil(Date.now()/1e3);for(let m=o.length-1;m>=0;m--){const g=o[m];if(g.expiresAt<=l){o.splice(m,1);continue}if(FE(g,d))return g.token}}async function u(d){const l=e.polyfills?.fetch??(typeof window>"u"?void 0:window.fetch);if(n.type==="private"){if(l===void 0)throw new xn("To use Liveblocks client in a non-DOM environment with a url as auth endpoint, you need to provide a fetch polyfill.");const m=await ME(l,n.url,{room:d.roomId}),g=Jl(m.token);if(r.has(g.raw)){const v=a(d);if(v?.raw===g.raw)return v;throw new xn("The same Liveblocks auth token was issued from the backend before. Caching Liveblocks tokens is not supported.")}return t?.(g.parsed),g}if(n.type==="custom"){const m=await n.callback(d.roomId);if(m&&typeof m=="object"){if(typeof m.token=="string"){const g=Jl(m.token);return t?.(g.parsed),g}else if(typeof m.error=="string"){const g=`Authentication failed: ${"reason"in m&&typeof m.reason=="string"?m.reason:"Forbidden"}`;throw m.error==="forbidden"?new xn(g):new Error(g)}}throw new Error('Your authentication callback function should return a token, but it did not. Hint: the return value should look like: { token: "..." }')}throw new Error("Unexpected authentication type. Must be private or custom.")}async function c(d){if(n.type==="public")return{type:"public",publicApiKey:n.publicApiKey};const l=a(d);if(l!==void 0)return{type:"secret",token:l};let m;const g=IE(d);g!==void 0?(m=s.get(g),m===void 0&&(m=u(d),s.set(g,m))):(m=s.get("liveblocks-user-token"),m===void 0&&(m=u(d),s.set("liveblocks-user-token",m)));try{const v=await m,p=Math.floor(Date.now()/1e3)+(v.parsed.exp-v.parsed.iat)-30;r.add(v.raw);const D=BE(v,p);return o.push(D),{type:"secret",token:v}}finally{g!==void 0?s.delete(g):s.delete("liveblocks-user-token")}}return{reset:i,getAuthValue:c}}function IE(e){if(e.roomId!==void 0)return`${e.roomId}:${e.resource}:${e.access}`}function BE(e,t){return e.parsed.k==="acc"?{token:e,expiresAt:t,permissions:Object.entries(e.parsed.perms).map(([n,r])=>({pattern:n,scopes:rc(r)}))}:{token:e,expiresAt:t}}function FE(e,t){if(e.token.parsed.k==="id"||t.resource==="personal")return!0;if(t.roomId===void 0)return!1;const n=wE(e.permissions??[],t.roomId);return n===void 0?!1:Yn(n,t.resource,t.access)}function PE(e){const{publicApiKey:t,authEndpoint:n}=e;if(n!==void 0&&t!==void 0)throw new Error("You cannot simultaneously use `publicApiKey` and `authEndpoint` options. Please pick one and leave the other option unspecified. For more information: https://liveblocks.io/docs/api-reference/liveblocks-client#createClient");if(typeof t=="string"){if(t.startsWith("sk_"))throw new Error("Invalid `publicApiKey` option. The value you passed is a secret key, which should not be used from the client. Please only ever pass a public key here. For more information: https://liveblocks.io/docs/api-reference/liveblocks-client#createClientPublicKey");if(!t.startsWith("pk_"))throw new Error("Invalid key. Please use the public key format: pk_<public key>. For more information: https://liveblocks.io/docs/api-reference/liveblocks-client#createClientPublicKey");return{type:"public",publicApiKey:t}}if(typeof n=="string")return{type:"private",url:n};if(typeof n=="function")return{type:"custom",callback:n};throw n!==void 0?new Error("The `authEndpoint` option 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. Please provide either a `publicApiKey` or `authEndpoint` option. They cannot both be empty. For more information: https://liveblocks.io/docs/api-reference/liveblocks-client#createClient")}async function ME(e,t,n){const r=await e(t,{method:"POST",headers:{"Content-Type":"application/json"},body:co(n)});if(!r.ok){const i=`${(await r.text()).trim()||"reason not provided in auth response"} (${r.status} returned by POST ${t})`;throw TE.includes(r.status)?new xn(`Unauthorized: ${i}`):new Error(`Failed to authenticate: ${i}`)}let o;try{o=await r.json()}catch(i){throw new Error(`Expected a JSON response when doing a POST request on "${t}". ${String(i)}`)}if(!lt(o)||typeof o.token!="string")throw new Error(`Expected a JSON response of the form \`{ token: "..." }\` when doing a POST request on "${t}", but got ${co(o)}`);const{token:s}=o;return{token:s}}var _E="https://api.liveblocks.io",mn="@",ve=Object.freeze({INIT:0,SET_PARENT_KEY:1,CREATE_LIST:2,UPDATE_OBJECT:3,CREATE_OBJECT:4,DELETE_CRDT:5,DELETE_OBJECT_KEY:6,CREATE_MAP:7,CREATE_REGISTER:8});function kE(e){return e.type===ve.DELETE_CRDT&&e.id==="ACK"}function Zl(e){return e.type===ve.CREATE_OBJECT||e.type===ve.CREATE_REGISTER||e.type===ve.CREATE_MAP||e.type===ve.CREATE_LIST}var qe=Object.freeze({OBJECT:0,LIST:1,MAP:2,REGISTER:3});function NE(e){return e[0]==="root"}function ip(e){return e[1].type===qe.OBJECT}function ap(e){return e[1].type===qe.LIST}function up(e){return e[1].type===qe.MAP}function cp(e){return e[1].type===qe.REGISTER}function jE(e){return e[0]==="root"}function*LE(e){for(const t of e){if(jE(t)){yield[t[0],{type:qe.OBJECT,data:t[1]}];continue}switch(t[1]){case qe.OBJECT:yield[t[0],{type:qe.OBJECT,parentId:t[2],parentKey:t[3],data:t[4]}];break;case qe.LIST:yield[t[0],{type:qe.LIST,parentId:t[2],parentKey:t[3]}];break;case qe.MAP:yield[t[0],{type:qe.MAP,parentId:t[2],parentKey:t[3]}];break;case qe.REGISTER:yield[t[0],{type:qe.REGISTER,parentId:t[2],parentKey:t[3],data:t[4]}];break}}}var yt=32,Xn=126,lp=Xn-yt+1,Ri=oc(0),Qr=oc(1),UE=Ri+oc(-1);function oc(e){const t=yt+(e<0?lp+e:e);if(t<yt||t>Xn)throw new Error(`Invalid n value: ${e}`);return String.fromCharCode(t)}function sn(e,t){return e!==void 0&&t!==void 0?VE(e,t):e!==void 0?HE(e):t!==void 0?$E(t):Qr}function $E(e){const t=e.length-1;for(let n=0;n<=t;n++){const r=e.charCodeAt(n);if(!(r<=yt))return n===t?r===yt+1?e.substring(0,n)+UE:e.substring(0,n)+String.fromCharCode(r-1):e.substring(0,n+1)}return Qr}var Fs=2,Ea=3;function HE(e){for(let o=0;o<e.length;o++){const s=e.charCodeAt(o);if(s<yt||s>Xn)return e+Qr}for(;e.length>1&&e.charCodeAt(e.length-1)===yt;)e=e.slice(0,-1);if(e.length===0||e===Ri)return Qr;let t=Fs;e.length>Fs&&(t=Fs+Math.ceil((e.length-Fs)/Ea)*Ea);const n=Xl(e,t);if(n!==null)return n;t+=Ea;const r=Xl(e,t);return r!==null?r:e+Qr}function Xl(e,t){const n=[];for(let s=0;s<t;s++)s<e.length?n.push(e.charCodeAt(s)-yt):n.push(0);let r=1;for(let s=t-1;s>=0&&r;s--){const i=n[s]+r;i>=lp?(n[s]=0,r=1):(n[s]=i,r=0)}if(r)return null;let o="";for(const s of n)o+=String.fromCharCode(s+yt);for(;o.length>1&&o.charCodeAt(o.length-1)===yt;)o=o.slice(0,-1);return o}function VE(e,t){if(e<t)return cu(e,t);if(e>t)return cu(t,e);throw new Error("Cannot compute value between two equal positions")}function cu(e,t){let n=0;const r=e.length,o=t.length;for(;;){const s=n<r?e.charCodeAt(n):yt,i=n<o?t.charCodeAt(n):Xn;if(s===i){n++;continue}if(i-s===1){const a=n+1;let u=e.substring(0,a);u.length<a&&(u+=Ri.repeat(a-u.length));const c=e.substring(a);return u+cu(c,"")}else return WE(e,n)+String.fromCharCode(i+s>>1)}}function WE(e,t){return t<e.length?e.substring(0,t):e+Ri.repeat(t-e.length)}var zE=yt+1;function KE(e){if(e==="")return!1;const t=e.length-1,n=e.charCodeAt(t);if(n<zE||n>Xn)return!1;for(let r=0;r<t;r++){const o=e.charCodeAt(r);if(o<yt||o>Xn)return!1}return!0}function GE(e){const t=[];for(let n=0;n<e.length;n++){const r=e.charCodeAt(n);t.push(r<yt?yt:r>Xn?Xn:r)}for(;t.length>0&&t[t.length-1]===yt;)t.length--;return t.length>0?String.fromCharCode(...t):Qr}function Yo(e){return KE(e)?e:GE(e)}var dp=class{#e=new Map;#t=new Map;#n=new Map;#r=new Set;#o(e,t){return`${e}
|
|
3
3
|
${t}`}get size(){return this.#e.size}add(e){if(this.#e.set(e.opId,e),Zl(e)){const t=this.#o(e.parentId,e.parentKey);let n=this.#t.get(t);n===void 0&&(n=new Map,this.#t.set(t,n)),n.set(e.opId,e);let r=this.#n.get(e.parentId);r===void 0&&(r=new Map,this.#n.set(e.parentId,r)),r.set(e.opId,e)}}delete(e){const t=this.#e.get(e);if(t!==void 0&&(this.#e.delete(e),this.#r.delete(e),Zl(t))){const n=this.#o(t.parentId,t.parentKey),r=this.#t.get(n);r?.delete(e),r!==void 0&&r.size===0&&this.#t.delete(n);const o=this.#n.get(t.parentId);o?.delete(e),o!==void 0&&o.size===0&&this.#n.delete(t.parentId)}}getByParentIdAndKey(e,t){return this.#t.get(this.#o(e,t))?.values()??[]}getByParentId(e){return this.#n.get(e)?.values()??[]}values(){return this.#e.values()}isPossiblyStored(e){return this.#r.has(e)}markAllAsPossiblyStored(){for(const e of this.#e.keys())this.#r.add(e)}};function fp(e){const{getCurrentConnectionId:t,onDispatch:n,isStorageWritable:r=()=>!0,unacknowledgedOps:o=new dp}=e;let s=0,i=0;const a=new Map;return{nodes:a,getNode:u=>a.get(u),addNode:(u,c)=>{a.set(u,c)},deleteNode:u=>{a.delete(u)},generateId:()=>`${t()}:${s++}`,generateOpId:()=>`${t()}:${i++}`,dispatch(u,c,d){n?.(u,c,d)},assertStorageIsWritable:()=>{if(!r())throw new Error("Cannot write to storage with a read only user, please ensure the user has write permissions")},unacknowledgedOps:o}}function Ql(e,t,n=Yo(t)){return Object.freeze({type:"HasParent",node:e,key:t,pos:n})}var ed=Object.freeze({type:"NoParent"});function qE(e,t=Yo(e)){return Object.freeze({type:"Orphaned",oldKey:e,oldPos:t})}var Ii=class{#e;#t;#n=ed;_getParentKeyOrThrow(){switch(this.parent.type){case"HasParent":return this.parent.key;case"NoParent":throw new Error("Parent key is missing");case"Orphaned":return this.parent.oldKey;default:return Je(this.parent,"Unknown state")}}get _parentPos(){switch(this.parent.type){case"HasParent":return this.parent.pos;case"NoParent":throw new Error("Parent key is missing");case"Orphaned":return this.parent.oldPos;default:return Je(this.parent,"Unknown state")}}get _pool(){return this.#e}get _id(){return this.#t}get parent(){return this.#n}get _parentKey(){switch(this.parent.type){case"HasParent":return this.parent.key;case"NoParent":return null;case"Orphaned":return this.parent.oldKey;default:return Je(this.parent,"Unknown state")}}_apply(e,t){return e.type===ve.DELETE_CRDT?this.parent.type==="HasParent"?this.parent.node._detachChild(this):{modified:!1}:{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.#n=Ql(e,t);return;case"Orphaned":case"NoParent":{this.#n=Ql(e,t);return}default:return Je(this.parent,"Unknown state")}}_attach(e,t){if(this.#t||this.#e)throw new Error("Cannot attach node: already attached");t.addNode(e,this),this.#t=e,this.#e=t}_detach(){switch(this.#e&&this.#t&&this.#e.deleteNode(this.#t),this.parent.type){case"HasParent":{this.#n=qE(this.parent.key,this.parent.pos);break}case"NoParent":{this.#n=ed;break}case"Orphaned":break;default:Je(this.parent,"Unknown state")}this.#e=void 0}_toOpsWithOpId(e,t,n){return this._toOps(e,t).map(r=>({opId:n.generateOpId(),...r}))}#r;#o;#s;invalidate(){(this.#r!==void 0||this.#s!==void 0)&&(this.#r=void 0,this.#s=void 0,this.parent.type==="HasParent"&&this.parent.node.invalidate())}toTreeNode(e){return(this.#s===void 0||this.#o!==e)&&(this.#o=e,this.#s=this._toTreeNode(e)),this.#s}hasCache(e){return this.#r!==void 0&&this.#r===e}toJSON(){return this.#r===void 0&&(this.#r=this._toJSON()),this.#r}},Bn=class hp extends Ii{#e;constructor(t){super(),this.#e=t}get data(){return this.#e}static _deserialize([t,n],r,o){const s=new hp(n.data);return s._attach(t,o),s}_toOps(t,n){if(this._id===void 0)throw new Error("Cannot serialize register if parentId or parentKey is undefined");return[{type:ve.CREATE_REGISTER,id:this._id,parentId:t,parentKey:n,data:this.data}]}_serialize(){if(this.parent.type!=="HasParent")throw new Error("Cannot serialize LiveRegister if parent is missing");return{type:qe.REGISTER,parentId:ge(this.parent.node._id,"Parent node expected to have ID"),parentKey:this.parent.key,data:this.data}}_attachChild(t){throw new Error("Method not implemented.")}_detachChild(t){throw new Error("Method not implemented.")}_apply(t,n){return super._apply(t,n)}_toTreeNode(t){return{type:"Json",id:this._id??it(),key:t,payload:this.#e}}_toJSON(){return this.#e}clone(){return ao(this.data)}};function YE(e,t){return e._parentPos<t._parentPos}var nr=class lu extends Ii{#e;#t;constructor(t){super(),this.#t=new WeakSet;const n=[];let r;for(const o of t){const s=sn(r),i=eo(o);i._setParentLink(this,s),n.push(i),r=s}this.#e=zn.fromAlreadySorted(n,YE)}static _deserialize([t,n],r,o){const s=new lu([]);s._attach(t,o);const i=r.get(t);if(i===void 0)return s;for(const a of i){const u=a[1],c=vp(a,r,o);c._setParentLink(s,u.parentKey),s.#n(c)}return s}_toOps(t,n){if(this._id===void 0)throw new Error("Cannot serialize item is not attached");const r=[],o={id:this._id,type:ve.CREATE_LIST,parentId:t,parentKey:n};r.push(o);for(const s of this.#e){const i=s._getParentKeyOrThrow(),a=Ro(s._toOps(this._id,i),"set");for(const u of a)r.push(u)}return r}#n(t){const n=this.#e.add(t);return this.invalidate(),n}#r(t,n){t._setParentLink(this,n),this.#e.reposition(t),this.invalidate()}#o(t,n){const r=ge(this.#e.at(t));this.#r(r,n)}_indexOfPosition(t){return this.#e.findIndex(n=>n._getParentKeyOrThrow()===t)}#s(t){if(this._pool===void 0||this._id===void 0)return;let n;for(const r of this._pool.unacknowledgedOps.getByParentIdAndKey(this._id,t))r.intent==="set"&&(n=r.opId);return n}_attach(t,n){super._attach(t,n);for(const r of this.#e)r._attach(n.generateId(),n)}_detach(){super._detach();for(const t of this.#e)t._detach()}#i(t){if(this._pool===void 0)throw new Error("Can't attach child if managed pool is not present");const{id:n,parentKey:r}=t,o=_o(t);o._attach(n,this._pool),o._setParentLink(this,r);const s=t.deletedId,i=this._indexOfPosition(r);if(i!==-1){const a=ge(this.#e.removeAt(i));if(a._id===s)return a._detach(),this.#e.add(o),{modified:$e(this,[Lr(i,o)]),reverse:[]};{this.#t.add(a),this.#e.remove(a),this.#e.add(o);const u=[Lr(i,o)],c=this.#a(t.deletedId);return c&&u.push(c),{modified:$e(this,u),reverse:[]}}}else{const a=[],u=this.#a(t.deletedId);return u&&a.push(u),this.#n(o),a.push(Yt(this._indexOfPosition(r),o)),{reverse:[],modified:$e(this,a)}}}#u(t){if(this._pool===void 0)throw new Error("Can't attach child if managed pool is not present");const n=[],r=this.#a(t.deletedId);r&&n.push(r);const o=this.#s(t.parentKey);if(o!==void 0&&o!==t.opId)return n.length===0?{modified:!1}:{modified:$e(this,n),reverse:[]};const s=this._indexOfPosition(t.parentKey),i=this.#e.find(a=>a._id===t.id);if(i!==void 0){if(i._parentKey===t.parentKey)return{modified:n.length>0?$e(this,n):!1,reverse:[]};if(s!==-1){const c=ge(this.#e.removeAt(s));this.#t.add(c),n.push(Ps(s,c))}const a=this.#e.findIndex(c=>c===i);this.#r(i,t.parentKey);const u=this.#e.findIndex(c=>c===i);return u!==a&&n.push(Nn(a,u,i)),{modified:n.length>0?$e(this,n):!1,reverse:[]}}else{const a=this._pool.getNode(t.id);if(a&&this.#t.has(a)){a._setParentLink(this,t.parentKey),this.#t.delete(a);const u=this.#n(a);return{modified:$e(this,[s===-1?Yt(u,a):Lr(u,a),...n]),reverse:[]}}else{if(s!==-1){const d=ge(this.#e.removeAt(s));this.#t.add(d)}const{newItem:u,newIndex:c}=this.#v(t,t.parentKey);return{modified:$e(this,[s===-1?Yt(c,u):Lr(c,u),...n]),reverse:[]}}}}#a(t){if(t===void 0||this._pool===void 0)return null;const n=this._pool.getNode(t);if(n===void 0)return null;const r=this._detachChild(n);return r.modified===!1?null:r.modified.updates[0]}#l(t){if(this._pool===void 0)throw new Error("Can't attach child if managed pool is not present");const n=Yo(t.parentKey),r=this._indexOfPosition(n);r!==-1&&this.#C(r,n);const{newItem:o,newIndex:s}=this.#v(t,n),i=this.#m(n);return{modified:$e(this,[Yt(s,o),...i]),reverse:[]}}*#f(){if(!(this._pool===void 0||this._id===void 0))for(const t of this._pool.unacknowledgedOps.getByParentId(this._id)){if(t.intent!=="push"||this._pool.unacknowledgedOps.isPossiblyStored(t.opId))continue;const n=this._pool.getNode(t.id);n!==void 0&&this.#e.includes(n)&&(yield n)}}#m(t){const n=new Set(this.#f());if(n.size===0)return[];let r;for(const i of n){const a=i._parentPos;(r===void 0||a<r)&&(r=a)}if(t<ge(r))return[];let o;for(const i of this.#e)n.has(i)||(o=i._parentPos);const s=[];for(const i of n){const a=this.#e.findIndex(c=>c===i);o=sn(o),this.#r(i,o);const u=this.#e.findIndex(c=>c===i);u!==a&&s.push(Nn(a,u,i))}return s}#g(t){const n=this.#e.find(s=>s._id===t.id),r=Yo(t.parentKey),o=this._indexOfPosition(r);if(n){if(n._parentKey===r)return{modified:!1};{const s=this.#e.findIndex(a=>a===n);o!==-1&&this.#C(o,r),this.#r(n,r);const i=this._indexOfPosition(r);return i===s?{modified:!1}:{modified:$e(this,[Nn(s,i,n)]),reverse:[]}}}else{const s=ge(this._pool).getNode(t.id);if(s&&this.#t.has(s)){s._setParentLink(this,r),this.#t.delete(s),this.#n(s);const i=this._indexOfPosition(r);return{modified:$e(this,[Yt(i,s)]),reverse:[]}}else{o!==-1&&this.#C(o,r);const{newItem:i,newIndex:a}=this.#v(t,r);return{modified:$e(this,[Yt(a,i)]),reverse:[]}}}}#h(t){const{id:n,parentKey:r}=t,o=_o(t);if(this._pool?.getNode(n)!==void 0)return{modified:!1};o._attach(n,ge(this._pool)),o._setParentLink(this,r);const s=this._indexOfPosition(r);let i=r;if(s!==-1){const u=this.#e.at(s)?._parentPos,c=this.#e.at(s+1)?._parentPos;i=sn(u,c),o._setParentLink(this,i)}this.#n(o);const a=this._indexOfPosition(i);return{modified:$e(this,[Yt(a,o)]),reverse:[{type:ve.DELETE_CRDT,id:n}]}}#p(t){const{id:n,parentKey:r}=t,o=_o(t);if(this._pool?.getNode(n)!==void 0)return{modified:!1};const s=this._indexOfPosition(r);o._attach(n,ge(this._pool)),o._setParentLink(this,r);const i=r;if(s!==-1){const a=this.#e.at(s);a._detach(),this.#e.remove(a),this.#e.add(o);const u=Ro(a._toOps(ge(this._id),r),"set",t.id),c=[Lr(s,o)],d=this.#a(t.deletedId);return d&&c.push(d),{modified:$e(this,c),reverse:u}}else{this.#n(o),this.#a(t.deletedId);const a=this._indexOfPosition(i);return{reverse:[{type:ve.DELETE_CRDT,id:n}],modified:$e(this,[Yt(a,o)])}}}_attachChild(t,n){if(this._pool===void 0)throw new Error("Can't attach child if managed pool is not present");let r;return t.intent==="set"?n===1?r=this.#i(t):n===2?r=this.#u(t):r=this.#p(t):n===1?r=this.#l(t):n===2?r=this.#g(t):r=this.#h(t),r.modified!==!1&&this.invalidate(),r}_detachChild(t){if(t){const n=ge(t._parentKey),r=t._toOps(ge(this._id),n),o=this.#e.findIndex(i=>i===t);if(o===-1)return{modified:!1};const s=this.#e.at(o);return this.#e.remove(t),this.invalidate(),t._detach(),{modified:$e(this,[Ps(o,s)]),reverse:r}}return{modified:!1}}#d(t,n){if(this.#t.has(n)){this.#t.delete(n),n._setParentLink(this,t);const s=this.#n(n);return{modified:$e(this,[Yt(s,n)]),reverse:[]}}const r=n._parentKey;if(t===r)return{modified:!1};const o=this._indexOfPosition(t);if(o===-1){const s=this.#e.findIndex(a=>a===n);this.#r(n,t);const i=this.#e.findIndex(a=>a===n);return i===s?{modified:!1}:{modified:$e(this,[Nn(s,i,n)]),reverse:[]}}else{this.#o(o,sn(t,this.#e.at(o+1)?._parentPos));const s=this.#e.findIndex(a=>a===n);this.#r(n,t);const i=this.#e.findIndex(a=>a===n);return i===s?{modified:!1}:{modified:$e(this,[Nn(s,i,n)]),reverse:[]}}}#y(t,n){const r=ge(n._parentKey);if(this.#t.has(n)){const o=this._indexOfPosition(t);if(this.#t.delete(n),o!==-1){const i=this.#e.at(o);i._setParentLink(this,sn(t,this.#e.at(o+1)?._parentPos)),this.#e.reposition(i)}n._setParentLink(this,t);const s=this.#n(n);return{modified:$e(this,[Yt(s,n)]),reverse:[]}}else{if(t===r)return{modified:!1};const o=this.#e.findIndex(a=>a===n),s=this._indexOfPosition(t);s!==-1&&this.#o(s,sn(t,this.#e.at(s+1)?._parentPos)),this.#r(n,t);const i=this.#e.findIndex(a=>a===n);return o===i?{modified:!1}:{modified:$e(this,[Nn(o,i,n)]),reverse:[]}}}#b(t,n){const r=ge(n._parentKey),o=this.#e.findIndex(u=>u===n),s=this._indexOfPosition(t);let i=t;s!==-1&&(i=sn(t,this.#e.at(s+1)?._parentPos)),this.#r(n,i);const a=this.#e.findIndex(u=>u===n);return o===a?{modified:!1}:{modified:$e(this,[Nn(o,a,n)]),reverse:[{type:ve.SET_PARENT_KEY,id:ge(n._id),parentKey:r}]}}_setChildKey(t,n,r){return r===1?this.#d(t,n):r===2?this.#y(t,n):this.#b(t,n)}_apply(t,n){return super._apply(t,n)}_serialize(){if(this.parent.type!=="HasParent")throw new Error("Cannot serialize LiveList if parent is missing");return{type:qe.LIST,parentId:ge(this.parent.node._id,"Parent node expected to have ID"),parentKey:this.parent.key}}get length(){return this.#e.length}push(t){return this.#E(t,this.length,"push")}insert(t,n){return this.#E(t,n,"insert")}#E(t,n,r){if(this._pool?.assertStorageIsWritable(),n<0||n>this.#e.length)throw new Error(`Cannot insert list item at index "${n}". index should be between 0 and ${this.#e.length}`);const o=this.#e.at(n-1)?._parentPos,s=this.#e.at(n)?._parentPos,i=sn(o,s),a=eo(t);if(a._setParentLink(this,i),this.#n(a),this._pool&&this._id){const u=this._pool.generateId();a._attach(u,this._pool);const c=a._toOpsWithOpId(this._id,i,this._pool);this._pool.dispatch(r==="push"?Ro(c,"push"):c,[{type:ve.DELETE_CRDT,id:u}],new Map([[this._id,$e(this,[Yt(n,a)])]]))}}move(t,n){if(this._pool?.assertStorageIsWritable(),n<0)throw new Error("targetIndex cannot be less than 0");if(n>=this.#e.length)throw new Error("targetIndex cannot be greater or equal than the list length");if(t<0)throw new Error("index cannot be less than 0");if(t>=this.#e.length)throw new Error("index cannot be greater or equal than the list length");let r=null,o=null;t<n?(o=n===this.#e.length-1?void 0:this.#e.at(n+1)?._parentPos,r=this.#e.at(n)._parentPos):(o=this.#e.at(n)._parentPos,r=n===0?void 0:this.#e.at(n-1)?._parentPos);const s=sn(r,o),i=this.#e.at(t),a=i._getParentKeyOrThrow();if(this.#o(t,s),this._pool&&this._id){const u=new Map([[this._id,$e(this,[Nn(t,n,i)])]]);this._pool.dispatch([{type:ve.SET_PARENT_KEY,id:ge(i._id),opId:this._pool.generateOpId(),parentKey:s}],[{type:ve.SET_PARENT_KEY,id:ge(i._id),parentKey:a}],u)}}delete(t){if(this._pool?.assertStorageIsWritable(),t<0||t>=this.#e.length)throw new Error(`Cannot delete list item at index "${t}". index should be between 0 and ${this.#e.length-1}`);const n=this.#e.at(t);if(n._detach(),this.#e.remove(n),this.invalidate(),this._pool){const r=n._id;if(r){const o=new Map;o.set(ge(this._id),$e(this,[Ps(t,n)])),this._pool.dispatch([{id:r,opId:this._pool.generateOpId(),type:ve.DELETE_CRDT}],n._toOps(ge(this._id),n._getParentKeyOrThrow()),o)}}}clear(){if(this._pool?.assertStorageIsWritable(),this._pool){const t=[],n=[],r=[];for(const s of this.#e){s._detach();const i=s._id;i&&(t.push({type:ve.DELETE_CRDT,id:i,opId:this._pool.generateOpId()}),n.push(...s._toOps(ge(this._id),s._getParentKeyOrThrow())),r.push(Ps(0,s)))}this.#e.clear(),this.invalidate();const o=new Map;o.set(ge(this._id),$e(this,r)),this._pool.dispatch(t,n,o)}else{for(const t of this.#e)t._detach();this.#e.clear(),this.invalidate()}}set(t,n){if(this._pool?.assertStorageIsWritable(),t<0||t>=this.#e.length)throw new Error(`Cannot set list item at index "${t}". index should be between 0 and ${this.#e.length-1}`);const r=this.#e.at(t),o=r._getParentKeyOrThrow(),s=r._id;r._detach();const i=eo(n);if(i._setParentLink(this,o),this.#e.remove(r),this.#e.add(i),this.invalidate(),this._pool&&this._id){const a=this._pool.generateId();i._attach(a,this._pool);const u=new Map;u.set(this._id,$e(this,[Lr(t,i)]));const c=Ro(i._toOpsWithOpId(this._id,o,this._pool),"set",s),d=Ro(r._toOps(this._id,o),"set",a);this._pool.dispatch(c,d,u)}}#c(t){return pr(t)}every(t){return this.#e.rawArray.every((n,r)=>t(this.#c(n),r))}filter(t){const n=[];return this.#e.rawArray.forEach((r,o)=>{const s=this.#c(r);t(s,o)&&n.push(s)}),n}find(t){for(const[n,r]of this.#e.rawArray.entries()){const o=this.#c(r);if(t(o,n))return o}}findIndex(t){return this.#e.rawArray.findIndex((n,r)=>t(this.#c(n),r))}forEach(t){this.#e.rawArray.forEach((n,r)=>t(this.#c(n),r))}get(t){const n=this.#e.at(t);return n!==void 0?this.#c(n):void 0}indexOf(t,n){return this.#e.rawArray.findIndex((r,o)=>o>=(n??0)&&this.#c(r)===t)}lastIndexOf(t,n){const r=this.#e.rawArray;for(let o=n??r.length-1;o>=0;o--)if(this.#c(r[o])===t)return o;return-1}map(t){return this.#e.rawArray.map((n,r)=>t(this.#c(n),r))}some(t){return this.#e.rawArray.some((n,r)=>t(this.#c(n),r))}*[Symbol.iterator](){for(const t of this.#e)yield this.#c(t)}#v(t,n){const r=_o(t);r._attach(t.id,ge(this._pool)),r._setParentLink(this,n),this.#n(r);const o=this._indexOfPosition(n);return{newItem:r,newIndex:o}}#C(t,n){const r=sn(n,this.#e.length>t+1?this.#e.at(t+1)?._parentPos:void 0);this.#o(t,r)}_toTreeNode(t){const n=[];let r=0;for(const o of this.#e)n.push(o.toTreeNode(r.toString())),r++;return{type:"LiveList",id:this._id??it(),key:t,payload:n}}toJSON(){return super.toJSON()}_toJSON(){const t=Array.from(this.#e,n=>n.toJSON());return hn(t)}clone(){return new lu(Array.from(this.#e,t=>t.clone()))}};function $e(e,t){return{node:e,type:"LiveList",updates:t}}function Lr(e,t){return{index:e,type:"set",item:t instanceof Bn?t.data:t}}function Ps(e,t){return{type:"delete",index:e,deletedItem:t instanceof Bn?t.data:t}}function Yt(e,t){return{index:e,type:"insert",item:t instanceof Bn?t.data:t}}function Nn(e,t,n){return{type:"move",index:t,item:n instanceof Bn?n.data:n,previousIndex:e}}function Ro(e,t,n){return e.map((r,o)=>o===0?{...r,intent:t,deletedId:n}:r)}var Ir=class du extends Ii{#e;#t;constructor(t){if(super(),this.#t=new Map,t){const n=[];for(const[r,o]of t){const s=eo(o);s._setParentLink(this,r),n.push([r,s])}this.#e=new Map(n)}else this.#e=new Map}_toOps(t,n){if(this._id===void 0)throw new Error("Cannot serialize item is not attached");const r=[],o={id:this._id,type:ve.CREATE_MAP,parentId:t,parentKey:n};r.push(o);for(const[s,i]of this.#e)for(const a of i._toOps(this._id,s))r.push(a);return r}static _deserialize([t,n],r,o){const s=new du;s._attach(t,o);const i=r.get(t);if(i===void 0)return s;for(const a of i){const u=a[1],c=vp(a,r,o);c._setParentLink(s,u.parentKey),s.#e.set(u.parentKey,c),s.invalidate()}return s}_attach(t,n){super._attach(t,n);for(const[r,o]of this.#e)et(o)&&o._attach(n.generateId(),n)}_attachChild(t,n){if(this._pool===void 0)throw new Error("Can't attach child if managed pool is not present");const{id:r,parentKey:o,opId:s}=t,i=o,a=_o(t);if(this._pool.getNode(r)!==void 0)return{modified:!1};if(n===2){const d=this.#t.get(i);if(d===s)return this.#t.delete(i),{modified:!1};if(d!==void 0)return{modified:!1}}else n===1&&this.#t.delete(i);const u=this.#e.get(i);let c;if(u){const d=ge(this._id);c=u._toOps(d,i),u._detach()}else c=[{type:ve.DELETE_CRDT,id:r}];return a._setParentLink(this,i),a._attach(r,this._pool),this.#e.set(i,a),this.invalidate(),{modified:{node:this,type:"LiveMap",updates:{[i]:{type:"update"}}},reverse:c}}_detach(){super._detach();for(const t of this.#e.values())t._detach()}_detachChild(t){const n=ge(this._id),r=ge(t._parentKey),o=t._toOps(n,r);for(const[i,a]of this.#e)a===t&&(this.#e.delete(i),this.invalidate());return t._detach(),{modified:{node:this,type:"LiveMap",updates:{[r]:{type:"delete",deletedItem:pr(t)}}},reverse:o}}_serialize(){if(this.parent.type!=="HasParent")throw new Error("Cannot serialize LiveMap if parent is missing");return{type:qe.MAP,parentId:ge(this.parent.node._id,"Parent node expected to have ID"),parentKey:this.parent.key}}get(t){const n=this.#e.get(t);if(n!==void 0)return pr(n)}set(t,n){this._pool?.assertStorageIsWritable();const r=this.#e.get(t);r&&r._detach();const o=eo(n);if(o._setParentLink(this,t),this.#e.set(t,o),this.invalidate(),this._pool&&this._id){const s=this._pool.generateId();o._attach(s,this._pool);const i=new Map;i.set(this._id,{node:this,type:"LiveMap",updates:{[t]:{type:"update"}}});const a=o._toOpsWithOpId(this._id,t,this._pool);this.#t.set(t,ge(a[0].opId)),this._pool.dispatch(a,r?r._toOps(this._id,t):[{type:ve.DELETE_CRDT,id:s}],i)}}get size(){return this.#e.size}has(t){return this.#e.has(t)}delete(t){this._pool?.assertStorageIsWritable();const n=this.#e.get(t);if(n===void 0)return!1;if(n._detach(),this.#e.delete(t),this.invalidate(),this._pool&&n._id){const r=ge(this._id),o=new Map;o.set(r,{node:this,type:"LiveMap",updates:{[t]:{type:"delete",deletedItem:pr(n)}}}),this._pool.dispatch([{type:ve.DELETE_CRDT,id:n._id,opId:this._pool.generateOpId()}],n._toOps(r,t),o)}return!0}entries(){const t=this.#e.entries();return{[Symbol.iterator](){return this},next(){const n=t.next();if(n.done)return{done:!0,value:void 0};const o=n.value[0],s=pr(n.value[1]);return{value:[o,s]}}}}[Symbol.iterator](){return this.entries()}keys(){return this.#e.keys()}values(){const t=this.#e.values();return{[Symbol.iterator](){return this},next(){const n=t.next();return n.done?{done:!0,value:void 0}:{value:pr(n.value)}}}}forEach(t){for(const n of this)t(n[1],n[0],this)}_toTreeNode(t){return{type:"LiveMap",id:this._id??it(),key:t,payload:Array.from(this.#e.entries()).map(([n,r])=>r.toTreeNode(n))}}toJSON(){return super.toJSON()}_toJSON(){const t={};for(const[n,r]of this.#e)t[n]=r.toJSON();return hn(t)}clone(){return new du(Array.from(this.#e).map(([t,n])=>[t,n.clone()]))}};function Sr(e,t){if(Array.isArray(e))return new nr(e.map(n=>Sr(n,t)));if(lt(e)){const n={},r={};for(const s in e){const i=e[s];if(i===void 0)continue;const a=lt(t)?t[s]:t;a===!1?r[s]=i:a==="atomic"?n[s]=i:n[s]=Sr(i,a)}const o=new Fn(n);for(const s in r)o.setLocal(s,r[s]);return o}else return e}function pp(e,t,n){return ic(e)&<(t)?fu(e,t,"full",n):sc(e)&&Array.isArray(t)?ZE(e,t,n):Cp(e)&<(t)?JE():Sr(t,n)}function JE(e,t){throw new Error("Reconciling a LiveMap is not supported yet")}function fu(e,t,n,r){const o=e.keys();for(const s in t){o.delete(s);const i=t[s];if(i===void 0){n==="full"&&e.delete(s);continue}const a=lt(r)?r[s]:r;if(a===!1)e.setLocal(s,i);else if(a==="atomic")e.get(s)!==i&&e.set(s,i);else{const u=e.get(s);if(u===void 0)e.set(s,Sr(i,a));else if(Kn(u)){const c=pp(u,i,a);c!==u&&e.set(s,c)}else u!==i&&e.set(s,Sr(i,a))}}if(n==="full")for(const s of o)e.delete(s);return e}function ZE(e,t,n){const r=e.length,o=t.length;for(let s=0;s<Math.min(r,o);s++){const i=e.get(s),a=t[s];if(Kn(i)){const u=pp(i,a,n);u!==i&&e.set(s,u)}else i!==a&&e.set(s,Sr(a,n))}for(let s=r;s<o;s++)e.push(Sr(t[s],n));for(let s=r-1;s>=o;s--)e.delete(s);return e}var ya=128*1024,Fn=class cr extends Ii{#e;#t=new Map;#n;static detectLargeObjects=!1;static#r(t){const n=new Map;let r=null;for(const o of t)if(NE(o))r=o[1];else{const s=o[1],i=n.get(s.parentId);i!==void 0?i.push(o):n.set(s.parentId,[o])}if(r===null)throw new Error("Root can't be null");return[r,n]}static _fromItems(t,n){const[r,o]=cr.#r(t);return cr._deserialize(["root",r],o,n)}constructor(t={}){super(),this.#n=new Map;const n=ps(t);for(const r of Object.keys(n)){const o=n[r];et(o)&&o._setParentLink(this,r)}this.#e=new Map(Object.entries(n))}_toOps(t,n){if(this._id===void 0)throw new Error("Cannot serialize item is not attached");const r=[],o={type:ve.CREATE_OBJECT,id:this._id,parentId:t,parentKey:n,data:{}};r.push(o);for(const[s,i]of this.#e)if(et(i))for(const a of i._toOps(this._id,s))r.push(a);else o.data[s]=i;return r}static _deserialize([t,n],r,o){const s=new cr(n.data);return s._attach(t,o),this._deserializeChildren(s,r,o)}static _deserializeChildren(t,n,r){const o=n.get(ge(t._id));if(o===void 0)return t;for(const s of o){const i=QE(s,n,r),a=s[1];Kn(i)&&i._setParentLink(t,a.parentKey),t.#e.set(a.parentKey,i),t.invalidate()}return t}_attach(t,n){super._attach(t,n);for(const[r,o]of this.#e)et(o)&&o._attach(n.generateId(),n)}_attachChild(t,n){if(this._pool===void 0)throw new Error("Can't attach child if managed pool is not present");const{id:r,opId:o,parentKey:s}=t,i=mp(t);if(this._pool.getNode(r)!==void 0)return this.#n.get(s)===o&&this.#n.delete(s),{modified:!1};if(n===0)this.#n.set(s,ge(o));else if(this.#n.get(s)!==void 0)return this.#n.get(s)===o?(this.#n.delete(s),{modified:!1}):{modified:!1};const a=ge(this._id),u=this.#e.get(s);let c;return et(u)?(c=u._toOps(a,s),u._detach()):u===void 0?c=[{type:ve.DELETE_OBJECT_KEY,id:a,key:s}]:c=[{type:ve.UPDATE_OBJECT,id:a,data:{[s]:u}}],this.#t.delete(s),this.#e.set(s,i),this.invalidate(),Kn(i)&&(i._setParentLink(this,s),i._attach(r,this._pool)),{reverse:c,modified:{node:this,type:"LiveObject",updates:{[s]:{type:"update"}}}}}_detachChild(t){if(t){const n=ge(this._id),r=ge(t._parentKey),o=t._toOps(n,r),s=pr(t);for(const[a,u]of this.#e)u===t&&(this.#e.delete(a),this.invalidate());return t._detach(),{modified:{node:this,type:"LiveObject",updates:{[r]:{type:"delete",deletedItem:s}}},reverse:o}}return{modified:!1}}_detach(){super._detach();for(const t of this.#e.values())et(t)&&t._detach()}_apply(t,n){return t.type===ve.UPDATE_OBJECT?this.#o(t,n):t.type===ve.DELETE_OBJECT_KEY?this.#s(t,n):super._apply(t,n)}_serialize(){const t={};for(const[n,r]of this.#e)et(r)||(t[n]=r);return this.parent.type==="HasParent"&&this.parent.node._id?{type:qe.OBJECT,parentId:this.parent.node._id,parentKey:this.parent.key,data:t}:{type:qe.OBJECT,data:t}}#o(t,n){let r=!1;const o=ge(this._id),s=[],i={type:ve.UPDATE_OBJECT,id:o,data:{}};for(const u in t.data){const c=this.#e.get(u);if(et(c)){for(const d of c._toOps(o,u))s.push(d);c._detach()}else c!==void 0?i.data[u]=c:c===void 0&&s.push({type:ve.DELETE_OBJECT_KEY,id:o,key:u})}const a={};for(const u in t.data){const c=t.data[u];if(c===void 0)continue;if(n)this.#n.set(u,ge(t.opId));else if(this.#n.get(u)===void 0)r=!0;else if(this.#n.get(u)===t.opId){this.#n.delete(u);continue}else continue;const d=this.#e.get(u);et(d)&&d._detach(),r=!0,a[u]={type:"update"},this.#t.delete(u),this.#e.set(u,c),this.invalidate()}return Object.keys(i.data).length!==0&&s.unshift(i),r?{modified:{node:this,type:"LiveObject",updates:a},reverse:s}:{modified:!1}}#s(t,n){const r=t.key,o=this.#e.get(r);if(o===void 0)return{modified:!1};if(!n&&this.#n.get(r)!==void 0)return{modified:!1};const s=ge(this._id);let i=[];return et(o)?(i=o._toOps(s,t.key),o._detach()):o!==void 0&&(i=[{type:ve.UPDATE_OBJECT,id:s,data:{[r]:o}}]),this.#t.delete(r),this.#e.delete(r),this.invalidate(),{modified:{node:this,type:"LiveObject",updates:{[t.key]:{type:"delete",deletedItem:o}}},reverse:i}}keys(){const t=new Set(this.#e.keys());for(const n of this.#t.keys())t.add(n);return t}set(t,n){this.update({[t]:n})}setLocal(t,n){this._pool?.assertStorageIsWritable();const r=this.#i(t);if(this.#t.set(t,n),this.invalidate(),this._pool!==void 0&&this._id!==void 0){const o=r?.[0]??[],s=r?.[1]??[],i=r?.[2]??new Map,a=i.get(this._id);i.set(this._id,{node:this,type:"LiveObject",updates:{...a?.updates,[t]:{type:"update"}}}),this._pool.dispatch(o,s,i)}}get(t){return this.#t.has(t)?this.#t.get(t):this.#e.get(t)}#i(t){this._pool?.assertStorageIsWritable();const n=t;if(this.#t.has(n)&&!this.#e.has(n)){const a=this.#t.get(n);if(this.#t.delete(n),this.invalidate(),this._pool!==void 0&&this._id!==void 0){const u=new Map;return u.set(this._id,{node:this,type:"LiveObject",updates:{[n]:{type:"delete",deletedItem:a}}}),[[],[],u]}return null}this.#t.delete(n);const r=this.#e.get(n);if(r===void 0)return null;if(this._pool===void 0||this._id===void 0)return et(r)&&r._detach(),this.#e.delete(n),this.invalidate(),null;const o=[{type:ve.DELETE_OBJECT_KEY,key:n,id:this._id,opId:this._pool.generateOpId()}];let s;et(r)?(r._detach(),s=r._toOps(this._id,n)):s=[{type:ve.UPDATE_OBJECT,data:{[n]:r},id:this._id}],this.#e.delete(n),this.invalidate();const i=new Map;return i.set(this._id,{node:this,type:"LiveObject",updates:{[t]:{type:"delete",deletedItem:r}}}),[o,s,i]}delete(t){const n=this.#i(t);if(n){const[r,o,s]=n;this._pool?.dispatch(r,o,s)}}update(t){if(this._pool?.assertStorageIsWritable(),cr.detectLargeObjects){const c={};for(const[m,g]of this.#e)et(g)||(c[m]=g);for(const m of Object.keys(t)){const g=t[m];g!==void 0&&(et(g)||(c[m]=g))}const d=JSON.stringify(c);if(d.length*4>ya){const m=new TextEncoder().encode(d).length;if(m>ya)throw new Error(`LiveObject size exceeded limit: ${m} bytes > ${ya} bytes. See https://liveblocks.io/docs/pricing/limits#Other-limits`)}}if(this._pool===void 0||this._id===void 0){for(const c in t){const d=t[c];if(d===void 0)continue;const l=this.#e.get(c);et(l)&&l._detach(),et(d)&&d._setParentLink(this,c),this.#t.delete(c),this.#e.set(c,d),this.invalidate()}return}const n=[],r=[],o=this._pool.generateOpId(),s={},i={id:this._id,type:ve.UPDATE_OBJECT,data:{}},a={};for(const c in t){const d=t[c];if(d===void 0)continue;const l=this.#e.get(c);if(l!==d){if(et(l)){for(const m of l._toOps(this._id,c))r.push(m);l._detach()}else l===void 0?r.push({type:ve.DELETE_OBJECT_KEY,id:this._id,key:c}):i.data[c]=l;if(et(d)){d._setParentLink(this,c),d._attach(this._pool.generateId(),this._pool);const m=d._toOpsWithOpId(this._id,c,this._pool),g=m.find(v=>v.parentId===this._id);g&&this.#n.set(c,ge(g.opId));for(const v of m)n.push(v)}else s[c]=d,this.#n.set(c,o);this.#t.delete(c),this.#e.set(c,d),this.invalidate(),a[c]={type:"update"}}}if(Object.keys(i.data).length!==0&&r.unshift(i),Object.keys(s).length!==0&&n.unshift({opId:o,id:this._id,type:ve.UPDATE_OBJECT,data:s}),n.length===0&&r.length===0&&Object.keys(a).length===0)return;const u=new Map;u.set(this._id,{node:this,type:"LiveObject",updates:a}),this._pool.dispatch(n,r,u)}static from(t,n){if(!lt(t))throw new Error("Expected a JSON object");const r=new cr({});return r.reconcile(t,n),r}reconcile(t,n){if(!this.hasCache(t)){if(!lt(t))throw new Error("Reconciling the document root expects a plain object value");fu(this,t,"full",n)}}reconcilePartially(t,n){if(!lt(t))throw new Error("Reconciling the document root expects a plain object value");fu(this,t,"partial",n)}toTreeNode(t){return super.toTreeNode(t)}_toTreeNode(t){const n=this._id??it();return{type:"LiveObject",id:n,key:t,payload:Array.from(this.#e.entries()).map(([r,o])=>et(o)?o.toTreeNode(r):{type:"Json",id:`${n}:${r}`,key:r,payload:o})}}toJSON(){return super.toJSON()}_toJSON(){const t={};for(const[n,r]of this.#e)t[n]=Kn(r)?r.toJSON():r;for(const[n,r]of this.#t)t[n]=r;return hn(t)}clone(){const t=new cr(Object.fromEntries(Array.from(this.#e).map(([n,r])=>[n,Kn(r)?r.clone():ao(r)])));for(const[n,r]of this.#t)t.#t.set(n,ao(r));return t}};function _o(e){return eo(mp(e))}function mp(e){switch(e.type){case ve.CREATE_REGISTER:return e.data;case ve.CREATE_OBJECT:return new Fn(e.data);case ve.CREATE_MAP:return new Ir;case ve.CREATE_LIST:return new nr([]);default:return Je(e,"Unknown creation Op")}}function gp(e,t){return e===t?!0:e.parent.type==="HasParent"?gp(e.parent.node,t):!1}function XE(e){const t=fp({getCurrentConnectionId:()=>{throw new Error("Cannot mutate a historic storage version: it is a read-only snapshot")}});return Fn._fromItems(e,t)}function vp(e,t,n){if(ip(e))return Fn._deserialize(e,t,n);if(ap(e))return nr._deserialize(e,t,n);if(up(e))return Ir._deserialize(e,t,n);if(cp(e))return Bn._deserialize(e,t,n);throw new Error("Unexpected CRDT type")}function QE(e,t,n){if(ip(e))return Fn._deserialize(e,t,n);if(ap(e))return nr._deserialize(e,t,n);if(up(e))return Ir._deserialize(e,t,n);if(cp(e))return e[1].data;throw new Error("Unexpected CRDT type")}function Kn(e){return sc(e)||Cp(e)||ic(e)}function et(e){return Kn(e)||ey(e)}function sc(e){return e instanceof nr}function Cp(e){return e instanceof Ir}function ic(e){return e instanceof Fn}function ey(e){return e instanceof Bn}function ty(e){return e===void 0?void 0:Kn(e)?e.clone():ao(e)}function pr(e){return e instanceof Bn?e.data:e instanceof nr||e instanceof Ir||e instanceof Fn?e:Je(e,"Unknown AbstractCrdt")}function eo(e){return e instanceof Fn||e instanceof Ir||e instanceof nr?e:new Bn(e)}function ny(e){const t=Array.from(e.nodes.values(),n=>{const r=n.parent,o=r.type==="HasParent"?r.node._id??"?":r.type==="Orphaned"?"<orphaned>":"-";let s;return n instanceof Bn?s=co(n.data):n instanceof nr?s="<LiveList>":n instanceof Ir?s="<LiveMap>":s="<LiveObject>",{id:ge(n._id),parentId:o,key:n._parentKey??"",value:s}});return t.sort((n,r)=>n.parentId!==r.parentId?n.parentId<r.parentId?-1:1:n.key!==r.key?n.key<r.key?-1:1:0),t.map(n=>` ${n.id} parent=${n.parentId} key=${n.key||"—"} ${n.value}`).join(`
|
|
4
4
|
`)}function hu(e,t){if(e===t)return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;if(Array.isArray(e)||Array.isArray(t)){if(!Array.isArray(e)||!Array.isArray(t)||e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(!hu(e[r],t[r]))return!1;return!0}const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!hu(e[r],t[r]))return!1;return!0}function ry(e,t){const n=[];e.forEach((s,i)=>{t.get(i)||n.push({type:ve.DELETE_CRDT,id:i})});const r=new Set;function o(s,i){if(r.has(s))return;r.add(s);const a=i.parentId;if(a!==void 0&&!e.has(a)){const u=t.get(a);u!==void 0&&o(a,u)}switch(i.type){case qe.REGISTER:n.push({type:ve.CREATE_REGISTER,id:s,parentId:i.parentId,parentKey:i.parentKey,data:i.data});break;case qe.LIST:n.push({type:ve.CREATE_LIST,id:s,parentId:i.parentId,parentKey:i.parentKey});break;case qe.OBJECT:if(i.parentId===void 0||i.parentKey===void 0)throw new Error("Internal error. Cannot serialize storage root into an operation");n.push({type:ve.CREATE_OBJECT,id:s,parentId:i.parentId,parentKey:i.parentKey,data:i.data});break;case qe.MAP:n.push({type:ve.CREATE_MAP,id:s,parentId:i.parentId,parentKey:i.parentKey});break}}return t.forEach((s,i)=>{const a=e.get(i);if(a){if(s.type===qe.OBJECT)if(a.type!==qe.OBJECT)n.push({type:ve.UPDATE_OBJECT,id:i,data:s.data});else{const u=new Map;for(const c of Object.keys(s.data)){const d=s.data[c];d!==void 0&&!hu(d,a.data[c])&&u.set(c,d)}u.size>0&&n.push({type:ve.UPDATE_OBJECT,id:i,data:Object.fromEntries(u)});for(const c of Object.keys(a.data))c in s.data||n.push({type:ve.DELETE_OBJECT_KEY,id:i,key:c})}s.parentKey!==a.parentKey&&n.push({type:ve.SET_PARENT_KEY,id:i,parentKey:ge(s.parentKey,"Parent key must not be missing")})}else o(i,s)}),n}function oy(e,t){const n=e.updates;for(const[r,o]of Ju(t.updates))n[r]=o;return{...t,updates:n}}function sy(e,t){const n=e.updates;for(const[r,o]of Ju(t.updates))n[r]=o;return{...t,updates:n}}function iy(e,t){const n=e.updates;return{...t,updates:n.concat(t.updates)}}function ba(e,t){return e===void 0?t:e.type==="LiveObject"&&t.type==="LiveObject"?oy(e,t):e.type==="LiveMap"&&t.type==="LiveMap"?sy(e,t):e.type==="LiveList"&&t.type==="LiveList"?iy(e,t):t}var ay=Ne();ay.observable;function wa(e,t,n=t){typeof e=="function"&&e()}var Vo=Symbol("notification-settings-plain");function ui(e){const t=["email","slack","teams","webPush"],n={[Vo]:{value:e,enumerable:!1}};for(const r of t)n[r]={enumerable:!0,get(){const o=this[Vo][r];return typeof o>"u"?(Jn(`In order to use the '${r}' channel, please set up your project first. For more information: https://liveblocks.io/docs/errors/enable-a-notification-channel`),null):o}};return c1(null,n)}function uy(e,t){const n=ui({...e[Vo]});for(const r of u1(t)){const o=t[r];if(o!==void 0){const s=Object.fromEntries(Ju(o).filter(([,i])=>i!==void 0));n[Vo][r]={...n[Vo][r],...s}}}return n}var jn="12px",cy=(e="bottom-right")=>{if(typeof document>"u"||document.getElementById("liveblocks-badge"))return;const t=document.createElement("div");switch(t.id="liveblocks-badge",t.style.position="fixed",t.style.opacity="0",t.style.transition="opacity 300ms",t.style.zIndex="9999",e){case"top-right":t.style.top=jn,t.style.right=jn;break;case"bottom-right":t.style.bottom=jn,t.style.right=jn;break;case"bottom-left":t.style.bottom=jn,t.style.left=jn;break;case"top-left":t.style.top=jn,t.style.left=jn;break}t.onmouseenter=()=>{const v=document.getElementById("liveblocks-badge-hide-button");v&&(v.style.opacity="0.3")},t.onmouseleave=()=>{const v=document.getElementById("liveblocks-badge-hide-button");v&&(v.style.opacity="0")};const n=document.createElement("a");n.href="https://lblcks.io/badge",n.target="_blank",n.rel="noopener noreferrer",n.title="Liveblocks";const r=document.createElementNS("http://www.w3.org/2000/svg","svg");r.setAttribute("width","111"),r.setAttribute("height","38"),r.setAttribute("viewBox","0 0 111 38"),r.setAttribute("fill","none");const o=document.createElementNS("http://www.w3.org/2000/svg","rect");o.setAttribute("x","1"),o.setAttribute("y","1"),o.setAttribute("width","109"),o.setAttribute("height","36"),o.setAttribute("rx","8"),o.setAttribute("fill","white"),r.appendChild(o);const s=document.createElementNS("http://www.w3.org/2000/svg","rect");s.setAttribute("x","0.5"),s.setAttribute("y","0.5"),s.setAttribute("width","110"),s.setAttribute("height","37"),s.setAttribute("rx","8.5"),s.setAttribute("stroke","black"),s.setAttribute("stroke-opacity","0.1"),r.appendChild(s);const i=document.createElementNS("http://www.w3.org/2000/svg","path");i.setAttribute("d","M39.8256 18.0832H38L38.0005 28.9009H39.8256V18.0832ZM43.213 21.1757H41.3879V28.9009H43.213V21.1757ZM43.213 18H41.3879V19.9688H43.213V18ZM45.8916 21.1757H43.9302L46.6915 28.9009H48.7283L51.4896 21.1757H49.5581L48.4039 24.8348C48.3739 24.93 48.2657 25.3024 48.0795 25.9511L47.7099 27.1959C47.4914 26.406 47.2626 25.6189 47.0237 24.8348L45.8916 21.1757ZM58.9659 23.59C58.8147 23.0721 58.5934 22.6317 58.3014 22.2694C57.9743 21.8628 57.5598 21.5482 57.0571 21.3268C56.5589 21.1004 56.0058 20.9877 55.3973 20.9877C54.2407 20.9877 53.3152 21.3495 52.6212 22.0735C52.275 22.4476 52.0103 22.8896 51.844 23.3715C51.6731 23.8691 51.5876 24.4199 51.5876 25.0233C51.5876 26.3157 51.9322 27.3142 52.6217 28.0184C53.3203 28.7323 54.2509 29.0894 55.4125 29.0894C56.4083 29.0894 57.2151 28.8658 57.8342 28.4181C58.453 27.9704 58.8628 27.3068 59.0638 26.4266L57.2834 26.2908C57.198 26.7685 57.0016 27.1257 56.6948 27.3618C56.3879 27.5933 55.9555 27.7093 55.3973 27.7093C54.1201 27.7093 53.4663 26.9899 53.4363 25.5514H59.1844L59.1922 25.295C59.1922 24.6763 59.1165 24.108 58.9659 23.59ZM53.8434 23.0471C54.1654 22.5943 54.6834 22.3679 55.3973 22.3679C55.7443 22.3679 56.0363 22.4155 56.2725 22.5111C56.509 22.6067 56.7128 22.7601 56.8837 22.9713C57.0167 23.1352 57.1189 23.3218 57.1855 23.5221C57.2605 23.731 57.3062 23.9493 57.3213 24.1708H53.451C53.4964 23.7231 53.6271 23.3484 53.8434 23.0471ZM66.2836 21.4779C65.7656 21.1406 65.1673 20.9724 64.4885 20.9724H64.4875C63.995 20.9724 63.5449 21.0727 63.1374 21.2742C62.7364 21.4696 62.3931 21.7659 62.1412 22.1341V18.0832H60.316V28.9009H62.1416V27.8373C62.373 28.2195 62.7008 28.5342 63.0921 28.7499C63.4996 28.9763 63.9497 29.0894 64.4422 29.0894C65.1266 29.0894 65.7324 28.9259 66.2614 28.5992C66.7891 28.2726 67.1989 27.8045 67.4905 27.1959C67.7871 26.5823 67.9359 25.8634 67.9359 25.0386C67.9359 24.2337 67.7895 23.5248 67.4984 22.9113C67.2115 22.2926 66.8066 21.8148 66.2836 21.4779ZM65.5064 27.0828C65.2148 27.5254 64.7172 27.7463 64.0125 27.7463C63.3786 27.7463 62.9013 27.5175 62.5797 27.0601C62.2576 26.6026 62.0968 25.9336 62.0968 25.0534C62.0968 24.2032 62.24 23.5397 62.5265 23.0619C62.8185 22.579 63.3088 22.3378 63.9978 22.3378C64.7019 22.3378 65.2023 22.5592 65.499 23.0013C65.7961 23.4389 65.944 24.1181 65.944 25.0386C65.944 25.9585 65.7985 26.6401 65.5064 27.0828ZM70.901 18.0832H69.0754V28.9009H70.901V18.0832ZM73.8582 28.6066C74.452 28.9286 75.1558 29.0894 75.9708 29.0894C76.7554 29.0894 77.4444 28.9208 78.0377 28.5844C78.6268 28.2569 79.1068 27.7637 79.4183 27.1659C79.745 26.5523 79.9086 25.843 79.9086 25.0386C79.9086 24.2642 79.7478 23.5697 79.4257 22.9565C79.117 22.3516 78.6404 21.8487 78.0529 21.508C77.4592 21.161 76.7652 20.9872 75.9708 20.9872C75.171 20.9872 74.4719 21.161 73.8735 21.508C73.2876 21.8472 72.811 22.3471 72.5002 22.9486C72.1837 23.5572 72.0252 24.254 72.0252 25.0386C72.0252 25.8735 72.181 26.5948 72.4929 27.2033C72.7962 27.798 73.2722 28.2871 73.8582 28.6066ZM77.4869 27.0906C77.18 27.5231 76.6746 27.7393 75.9708 27.7393C75.493 27.7393 75.1082 27.6437 74.8166 27.4524C74.5246 27.2565 74.3134 26.9621 74.1826 26.5699C74.0518 26.1725 73.9867 25.6619 73.9867 25.0381C73.9867 24.1029 74.1401 23.419 74.4469 22.9866C74.7588 22.5541 75.2667 22.3378 75.9708 22.3378C76.6699 22.3378 77.1727 22.5541 77.4795 22.9866C77.7914 23.419 77.9471 24.1029 77.9471 25.0386C77.9471 25.9738 77.7937 26.6576 77.4869 27.0906ZM82.3982 28.6066C82.9869 28.9286 83.6883 29.0894 84.5033 29.0894C85.1369 29.0894 85.7029 28.9791 86.2005 28.7577C86.6989 28.5364 87.1031 28.2272 87.4152 27.8299C87.7279 27.4249 87.9329 26.9471 88.0109 26.4414L86.2534 26.2607C86.1328 26.7431 85.9316 27.1031 85.6497 27.3392C85.3683 27.5757 84.9857 27.694 84.5033 27.694C84.0103 27.694 83.6232 27.5933 83.3413 27.3918C83.0598 27.1858 82.8635 26.8919 82.7531 26.5093C82.6422 26.1221 82.5872 25.6318 82.5872 25.0386C82.5872 24.455 82.6422 23.9722 82.7531 23.59C82.8635 23.2028 83.0571 22.9062 83.3339 22.6997C83.6157 22.4884 84.0053 22.3831 84.5033 22.3831C85.0362 22.3831 85.4312 22.5314 85.6877 22.8281C85.949 23.1196 86.1354 23.5193 86.2456 24.0276L87.9735 23.718C87.8078 22.8932 87.4326 22.232 86.8491 21.7344C86.2708 21.2363 85.489 20.9877 84.5033 20.9877C83.6985 20.9877 83.0021 21.1587 82.4134 21.5006C81.8322 21.8351 81.3625 22.3337 81.0633 22.9339C80.7514 23.5424 80.5952 24.2439 80.5952 25.0386C80.5952 25.8781 80.7486 26.6026 81.0554 27.2112C81.3673 27.8197 81.8151 28.285 82.3982 28.6066ZM90.8104 26.0343L91.6627 25.2192L93.9257 28.9009H96.0308L92.8999 24.0498L95.9328 21.1757H93.5634L90.8104 23.9976V18.0832H88.9845V28.9009H90.8104V26.0343ZM97.6304 28.8103C98.1436 28.9965 98.7142 29.0894 99.3428 29.0894C100.303 29.0894 101.095 28.8981 101.719 28.5165C102.348 28.1339 102.663 27.5101 102.663 26.6451C102.663 26.0818 102.516 25.6392 102.225 25.3176C101.933 24.9905 101.586 24.7566 101.184 24.6157C100.786 24.4702 100.245 24.3219 99.562 24.1707C99.1642 24.0853 98.8502 24.0049 98.6188 23.9295C98.3873 23.8538 98.201 23.7558 98.0604 23.6352C97.925 23.5141 97.8567 23.3584 97.8567 23.1676C97.8567 22.8858 97.9824 22.6723 98.2338 22.5263C98.4853 22.3803 98.7973 22.3073 99.1694 22.3073C99.6619 22.3073 100.047 22.4255 100.324 22.6621C100.605 22.8987 100.756 23.2531 100.776 23.7258L102.466 23.4467C102.385 22.5817 102.046 21.9556 101.447 21.568C100.854 21.1812 100.095 20.9872 99.1694 20.9872C98.6258 20.9872 98.1236 21.0699 97.6607 21.2362C97.2029 21.397 96.8335 21.6511 96.5517 21.9986C96.27 22.3451 96.1294 22.7827 96.1294 23.3109C96.1294 23.7988 96.25 24.1934 96.4911 24.4951C96.7368 24.8001 97.0527 25.0408 97.4118 25.1965C97.7838 25.3578 98.2512 25.5112 98.8147 25.6567L99.2828 25.7699C99.5949 25.844 99.9044 25.9295 100.211 26.0264C100.421 26.092 100.595 26.1826 100.731 26.2981C100.867 26.4136 100.935 26.5647 100.935 26.7509C100.935 27.0776 100.799 27.3294 100.527 27.505C100.261 27.6815 99.8708 27.7693 99.3583 27.7693C98.8347 27.7693 98.4176 27.6385 98.1055 27.377C97.7941 27.1154 97.6355 26.7384 97.6304 26.2454L95.9109 26.4413C95.9302 27.0351 96.094 27.5304 96.4009 27.9278C96.7129 28.3252 97.1223 28.619 97.6304 28.8103Z"),i.setAttribute("fill","black"),r.appendChild(i);const a=document.createElementNS("http://www.w3.org/2000/svg","path");a.setAttribute("d","M37.6392 15V9.18182H39.7131C40.1657 9.18182 40.5407 9.2642 40.8381 9.42898C41.1354 9.59375 41.358 9.81913 41.5057 10.1051C41.6534 10.3892 41.7273 10.7093 41.7273 11.0653C41.7273 11.4233 41.6525 11.7453 41.5028 12.0312C41.3551 12.3153 41.1316 12.5407 40.8324 12.7074C40.535 12.8722 40.161 12.9545 39.7102 12.9545H38.2841V12.2102H39.6307C39.9167 12.2102 40.1487 12.161 40.3267 12.0625C40.5047 11.9621 40.6354 11.8258 40.7188 11.6534C40.8021 11.4811 40.8438 11.285 40.8438 11.0653C40.8438 10.8456 40.8021 10.6506 40.7188 10.4801C40.6354 10.3097 40.5038 10.1761 40.3239 10.0795C40.1458 9.98295 39.911 9.93466 39.6193 9.93466H38.517V15H37.6392ZM44.4716 15.0881C44.0625 15.0881 43.7055 14.9943 43.4006 14.8068C43.0956 14.6193 42.8589 14.357 42.6903 14.0199C42.5218 13.6828 42.4375 13.2888 42.4375 12.8381C42.4375 12.3854 42.5218 11.9896 42.6903 11.6506C42.8589 11.3116 43.0956 11.0483 43.4006 10.8608C43.7055 10.6733 44.0625 10.5795 44.4716 10.5795C44.8807 10.5795 45.2377 10.6733 45.5426 10.8608C45.8475 11.0483 46.0843 11.3116 46.2528 11.6506C46.4214 11.9896 46.5057 12.3854 46.5057 12.8381C46.5057 13.2888 46.4214 13.6828 46.2528 14.0199C46.0843 14.357 45.8475 14.6193 45.5426 14.8068C45.2377 14.9943 44.8807 15.0881 44.4716 15.0881ZM44.4744 14.375C44.7396 14.375 44.9593 14.3049 45.1335 14.1648C45.3078 14.0246 45.4366 13.8381 45.5199 13.6051C45.6051 13.3722 45.6477 13.1155 45.6477 12.8352C45.6477 12.5568 45.6051 12.3011 45.5199 12.0682C45.4366 11.8333 45.3078 11.6449 45.1335 11.5028C44.9593 11.3608 44.7396 11.2898 44.4744 11.2898C44.2074 11.2898 43.9858 11.3608 43.8097 11.5028C43.6354 11.6449 43.5057 11.8333 43.4205 12.0682C43.3371 12.3011 43.2955 12.5568 43.2955 12.8352C43.2955 13.1155 43.3371 13.3722 43.4205 13.6051C43.5057 13.8381 43.6354 14.0246 43.8097 14.1648C43.9858 14.3049 44.2074 14.375 44.4744 14.375ZM48.267 15L46.983 10.6364H47.8608L48.7159 13.8409H48.7585L49.6165 10.6364H50.4943L51.3466 13.8267H51.3892L52.2386 10.6364H53.1165L51.8352 15H50.9688L50.0824 11.8494H50.017L49.1307 15H48.267ZM55.6705 15.0881C55.2405 15.0881 54.8703 14.9962 54.5597 14.8125C54.2509 14.6269 54.0123 14.3665 53.8438 14.0312C53.6771 13.6941 53.5938 13.2992 53.5938 12.8466C53.5938 12.3996 53.6771 12.0057 53.8438 11.6648C54.0123 11.3239 54.2472 11.0578 54.5483 10.8665C54.8513 10.6752 55.2055 10.5795 55.6108 10.5795C55.857 10.5795 56.0956 10.6203 56.3267 10.7017C56.5578 10.7831 56.7652 10.911 56.9489 11.0852C57.1326 11.2595 57.2775 11.4858 57.3835 11.7642C57.4896 12.0407 57.5426 12.3769 57.5426 12.7727V13.0739H54.0739V12.4375H56.7102C56.7102 12.214 56.6648 12.0161 56.5739 11.8438C56.483 11.6695 56.3551 11.5322 56.1903 11.4318C56.0275 11.3314 55.8362 11.2812 55.6165 11.2812C55.3778 11.2812 55.1695 11.34 54.9915 11.4574C54.8153 11.5729 54.679 11.7244 54.5824 11.9119C54.4877 12.0975 54.4403 12.2992 54.4403 12.517V13.0142C54.4403 13.3059 54.4915 13.554 54.5938 13.7585C54.6979 13.9631 54.8428 14.1193 55.0284 14.2273C55.214 14.3333 55.4309 14.3864 55.679 14.3864C55.84 14.3864 55.9867 14.3636 56.1193 14.3182C56.2519 14.2708 56.3665 14.2008 56.4631 14.108C56.5597 14.0152 56.6335 13.9006 56.6847 13.7642L57.4886 13.9091C57.4242 14.1458 57.3087 14.3532 57.142 14.5312C56.9773 14.7074 56.7699 14.8447 56.5199 14.9432C56.2718 15.0398 55.9886 15.0881 55.6705 15.0881ZM58.4851 15V10.6364H59.3061V11.3295H59.3516C59.4311 11.0947 59.5713 10.91 59.772 10.7756C59.9747 10.6392 60.2038 10.571 60.4595 10.571C60.5125 10.571 60.575 10.5729 60.647 10.5767C60.7209 10.5805 60.7786 10.5852 60.8203 10.5909V11.4034C60.7862 11.3939 60.7256 11.3835 60.6385 11.3722C60.5514 11.3589 60.4643 11.3523 60.3771 11.3523C60.1764 11.3523 59.9974 11.3949 59.8402 11.4801C59.6849 11.5634 59.5618 11.6799 59.4709 11.8295C59.38 11.9773 59.3345 12.1458 59.3345 12.3352V15H58.4851ZM63.2798 15.0881C62.8499 15.0881 62.4796 14.9962 62.169 14.8125C61.8603 14.6269 61.6217 14.3665 61.4531 14.0312C61.2865 13.6941 61.2031 13.2992 61.2031 12.8466C61.2031 12.3996 61.2865 12.0057 61.4531 11.6648C61.6217 11.3239 61.8565 11.0578 62.1577 10.8665C62.4607 10.6752 62.8149 10.5795 63.2202 10.5795C63.4664 10.5795 63.705 10.6203 63.9361 10.7017C64.1671 10.7831 64.3745 10.911 64.5582 11.0852C64.742 11.2595 64.8868 11.4858 64.9929 11.7642C65.099 12.0407 65.152 12.3769 65.152 12.7727V13.0739H61.6832V12.4375H64.3196C64.3196 12.214 64.2741 12.0161 64.1832 11.8438C64.0923 11.6695 63.9645 11.5322 63.7997 11.4318C63.6368 11.3314 63.4455 11.2812 63.2259 11.2812C62.9872 11.2812 62.7789 11.34 62.6009 11.4574C62.4247 11.5729 62.2884 11.7244 62.1918 11.9119C62.0971 12.0975 62.0497 12.2992 62.0497 12.517V13.0142C62.0497 13.3059 62.1009 13.554 62.2031 13.7585C62.3073 13.9631 62.4522 14.1193 62.6378 14.2273C62.8234 14.3333 63.0402 14.3864 63.2884 14.3864C63.4493 14.3864 63.5961 14.3636 63.7287 14.3182C63.8613 14.2708 63.9759 14.2008 64.0724 14.108C64.169 14.0152 64.2429 13.9006 64.294 13.7642L65.098 13.9091C65.0336 14.1458 64.9181 14.3532 64.7514 14.5312C64.5866 14.7074 64.3793 14.8447 64.1293 14.9432C63.8812 15.0398 63.598 15.0881 63.2798 15.0881ZM67.728 15.0852C67.3757 15.0852 67.0613 14.9953 66.7848 14.8153C66.5102 14.6335 66.2943 14.375 66.1371 14.0398C65.9818 13.7027 65.9041 13.2983 65.9041 12.8267C65.9041 12.3551 65.9827 11.9517 66.1399 11.6165C66.299 11.2812 66.5168 11.0246 66.7933 10.8466C67.0698 10.6686 67.3833 10.5795 67.7337 10.5795C68.0045 10.5795 68.2223 10.625 68.3871 10.7159C68.5537 10.8049 68.6825 10.9091 68.7734 11.0284C68.8662 11.1477 68.9382 11.2528 68.9893 11.3438H69.0405V9.18182H69.8899V15H69.0604V14.321H68.9893C68.9382 14.4138 68.8643 14.5199 68.7678 14.6392C68.6731 14.7585 68.5424 14.8627 68.3757 14.9517C68.209 15.0407 67.9931 15.0852 67.728 15.0852ZM67.9155 14.3608C68.1598 14.3608 68.3662 14.2964 68.5348 14.1676C68.7053 14.0369 68.834 13.8561 68.9212 13.625C69.0102 13.3939 69.0547 13.125 69.0547 12.8182C69.0547 12.5152 69.0111 12.25 68.924 12.0227C68.8369 11.7955 68.709 11.6184 68.5405 11.4915C68.3719 11.3646 68.1636 11.3011 67.9155 11.3011C67.6598 11.3011 67.4467 11.3674 67.2763 11.5C67.1058 11.6326 66.977 11.8134 66.8899 12.0426C66.8047 12.2718 66.7621 12.5303 66.7621 12.8182C66.7621 13.1098 66.8056 13.3722 66.8928 13.6051C66.9799 13.8381 67.1087 14.0227 67.2791 14.1591C67.4515 14.2936 67.6636 14.3608 67.9155 14.3608ZM73.2876 15V9.18182H74.1371V11.3438H74.1882C74.2375 11.2528 74.3085 11.1477 74.4013 11.0284C74.4941 10.9091 74.6229 10.8049 74.7876 10.7159C74.9524 10.625 75.1702 10.5795 75.4411 10.5795C75.7933 10.5795 76.1077 10.6686 76.3842 10.8466C76.6607 11.0246 76.8776 11.2812 77.0348 11.6165C77.1939 11.9517 77.2734 12.3551 77.2734 12.8267C77.2734 13.2983 77.1948 13.7027 77.0376 14.0398C76.8804 14.375 76.6645 14.6335 76.3899 14.8153C76.1153 14.9953 75.8018 15.0852 75.4496 15.0852C75.1844 15.0852 74.9676 15.0407 74.799 14.9517C74.6323 14.8627 74.5017 14.7585 74.407 14.6392C74.3123 14.5199 74.2393 14.4138 74.1882 14.321H74.1172V15H73.2876ZM74.12 12.8182C74.12 13.125 74.1645 13.3939 74.2536 13.625C74.3426 13.8561 74.4714 14.0369 74.6399 14.1676C74.8085 14.2964 75.0149 14.3608 75.2592 14.3608C75.513 14.3608 75.7251 14.2936 75.8956 14.1591C76.0661 14.0227 76.1948 13.8381 76.282 13.6051C76.371 13.3722 76.4155 13.1098 76.4155 12.8182C76.4155 12.5303 76.3719 12.2718 76.2848 12.0426C76.1996 11.8134 76.0708 11.6326 75.8984 11.5C75.728 11.3674 75.5149 11.3011 75.2592 11.3011C75.013 11.3011 74.8047 11.3646 74.6342 11.4915C74.4657 11.6184 74.3378 11.7955 74.2507 12.0227C74.1636 12.25 74.12 12.5152 74.12 12.8182ZM78.6158 16.6364C78.4889 16.6364 78.3733 16.6259 78.2692 16.6051C78.165 16.5862 78.0874 16.5653 78.0362 16.5426L78.2408 15.8466C78.3961 15.8883 78.5343 15.9063 78.6555 15.9006C78.7768 15.8949 78.8838 15.8494 78.9766 15.7642C79.0713 15.679 79.1546 15.5398 79.2266 15.3466L79.3317 15.0568L77.7351 10.6364H78.6442L79.7493 14.0227H79.7947L80.8999 10.6364H81.8118L80.0135 15.5824C79.9302 15.8097 79.8241 16.0019 79.6953 16.1591C79.5665 16.3182 79.4131 16.4375 79.2351 16.517C79.0571 16.5966 78.8506 16.6364 78.6158 16.6364Z"),a.setAttribute("fill","black"),a.setAttribute("fill-opacity","0.5"),r.appendChild(a);const u=document.createElementNS("http://www.w3.org/2000/svg","rect");u.setAttribute("x","7"),u.setAttribute("y","7"),u.setAttribute("width","24"),u.setAttribute("height","24"),u.setAttribute("rx","3"),u.setAttribute("fill","black"),r.appendChild(u);const c=document.createElementNS("http://www.w3.org/2000/svg","path");c.setAttribute("fill-rule","evenodd"),c.setAttribute("clip-rule","evenodd"),c.setAttribute("d","M22.0455 15H12.2273L15.1364 17.9091V21.9091L22.0455 15Z"),c.setAttribute("fill","white"),r.appendChild(c);const d=document.createElementNS("http://www.w3.org/2000/svg","path");d.setAttribute("fill-rule","evenodd"),d.setAttribute("clip-rule","evenodd"),d.setAttribute("d","M16.9546 22.9999H26.7728L23.8637 20.0908V16.0908L16.9546 22.9999Z"),d.setAttribute("fill","white"),r.appendChild(d),n.appendChild(r),t.appendChild(n);const l=document.createElement("button");l.id="liveblocks-badge-hide-button",l.style.position="absolute",l.style.top="0",l.style.right="0",l.style.border="none",l.style.padding="0",l.style.margin="0",l.style.background="none",l.style.font="inherit",l.style.cursor="pointer",l.style.outline="none",l.style.setProperty("-webkit-appearance","none"),l.style.setProperty("-moz-appearance","none"),l.style.setProperty("appearance","none"),l.style.opacity="0",l.onclick=()=>{const v=document.getElementById("liveblocks-badge");v&&(v.style.display="none")},l.onmouseenter=()=>{l.style.opacity="0.5"},l.onmouseleave=()=>{l.style.opacity="0.3"};const m=document.createElementNS("http://www.w3.org/2000/svg","svg");m.setAttribute("width","18"),m.setAttribute("height","18"),m.setAttribute("viewBox","0 0 18 18"),m.setAttribute("fill","none");const g=document.createElementNS("http://www.w3.org/2000/svg","path");g.setAttribute("d","M6 6L9 9M12 12L9 9M9 9L12 6M9 9L6 12"),g.setAttribute("stroke","black"),m.appendChild(g),l.appendChild(m),t.appendChild(l),document.body.appendChild(t),requestAnimationFrame(()=>{requestAnimationFrame(()=>{t.style.opacity="1"})})},Da=class{#e;#t;#n;#r;constructor(){this.#e={},this.#t=0,this.#n=1,this.#r=0}get length(){return this.#r}*[Symbol.iterator](){const e=this.#r,t=this.#t;for(let n=0;n<e;n++)yield this.#e[t+n]}push(e){const t=Array.isArray(e)?e:[e];this.#n>Number.MAX_SAFE_INTEGER-t.length-1&&Ft("Deque full");for(const n of t)this.#e[this.#n++-1]=n;this.#r+=t.length}pop(){if(this.#r<1)return;this.#n--;const e=this.#e[this.#n-1];return delete this.#e[this.#n-1],this.#r--,e}pushLeft(e){const t=Array.isArray(e)?e:[e];this.#t<Number.MIN_SAFE_INTEGER+t.length&&Ft("Deque full");for(let n=t.length-1;n>=0;n--)this.#e[--this.#t]=t[n];this.#r+=t.length}popLeft(){if(this.#r<1)return;const e=this.#e[this.#t];return delete this.#e[this.#t],this.#t++,this.#r--,e}};function ly(e){return e===null||typeof e=="string"||typeof e=="number"||typeof e=="boolean"}function Ep(e){return Array.isArray(e)}function dy(e){return!ly(e)&&!Ep(e)}function fy(){let e=0,t=0,n;function r(){n=[],e=performance.now(),t=e}function o(i=performance.now()){n.push(i-t),t=i}function s(){const i=performance.now();return o(i),{total:i-e,laps:n}}return{start:r,lap:o,stop:s}}var rt=Object.freeze({UPDATE_PRESENCE:100,BROADCAST_EVENT:103,FETCH_STORAGE:200,UPDATE_STORAGE:201,FETCH_YDOC:300,UPDATE_YDOC:301,FETCH_FEEDS:510,FETCH_FEED_MESSAGES:511,ADD_FEED:512,UPDATE_FEED:513,DELETE_FEED:514,ADD_FEED_MESSAGE:515,UPDATE_FEED_MESSAGE:516,DELETE_FEED_MESSAGE:517});function hy(e,t){const{connectionId:n,id:r,info:o,access:s}=e,{canWrite:i,canComment:a}=s;return hn(ps({connectionId:n,id:r,info:o,canWrite:i,canComment:a,isReadOnly:!i,presence:t}))}var py=class{#e;#t;signal;constructor(){this.#e=new xt({connections:new Map,presences:new Map}),this.signal=je.from(this.#e,e=>nu(Array.from(this.#e.get().presences.keys()).map(t=>this.getUser(Number(t))))),this.#t=new Map}get(){return this.signal.get()}connectionIds(){return this.#e.get().connections.keys()}clearOthers(){this.#e.mutate(e=>{e.connections.clear(),e.presences.clear(),this.#t.clear()})}#n(e){const t=this.#e.get(),n=t.connections.get(e),r=t.presences.get(e);if(n!==void 0&&r!==void 0)return hy(n,r)}getUser(e){const t=this.#t.get(e);if(t)return t;const n=this.#n(e);if(n)return this.#t.set(e,n),n}#r(e){this.#t.delete(e)}setConnection(e,t,n,r){this.#e.mutate(o=>(o.connections.set(e,hn({connectionId:e,id:t,info:n,access:r})),o.presences.has(e)?this.#r(e):!1))}removeConnection(e){this.#e.mutate(t=>{t.connections.delete(e),t.presences.delete(e),this.#r(e)})}setOther(e,t){this.#e.mutate(n=>(n.presences.set(e,hn(ps(t))),n.connections.has(e)?this.#r(e):!1))}patchOther(e,t){this.#e.mutate(n=>{const r=n.presences.get(e);if(r===void 0)return!1;const o=Uh(r,t);return r===o?!1:(n.presences.set(e,hn(o)),this.#r(e))})}},pu=class yp extends Error{context;constructor(t,n,r){super(t,{cause:r}),this.context=n,this.name="LiveblocksError"}get roomId(){return this.context.roomId}get code(){return this.context.code}static from(t,n){return new yp(my(t),t,n)}};function my(e){switch(e.type){case"ROOM_CONNECTION_ERROR":switch(e.code){case 4001:return"Not allowed to connect to the room";case 4005:return"Room is already full";case 4006:return"Kicked out of the room, because the room ID changed";default:return"Could not connect to the room"}case"AI_CONNECTION_ERROR":return e.code===4001?"Not allowed to connect to ai":"Could not connect to the room";case"CREATE_THREAD_ERROR":return"Could not create new thread";case"DELETE_THREAD_ERROR":return"Could not delete thread";case"EDIT_THREAD_METADATA_ERROR":return"Could not edit thread metadata";case"EDIT_COMMENT_METADATA_ERROR":return"Could not edit comment metadata";case"MARK_THREAD_AS_RESOLVED_ERROR":return"Could not mark thread as resolved";case"MARK_THREAD_AS_UNRESOLVED_ERROR":return"Could not mark thread as unresolved";case"SUBSCRIBE_TO_THREAD_ERROR":return"Could not subscribe to thread";case"UNSUBSCRIBE_FROM_THREAD_ERROR":return"Could not unsubscribe from thread";case"CREATE_COMMENT_ERROR":return"Could not create new comment";case"EDIT_COMMENT_ERROR":return"Could not edit comment";case"DELETE_COMMENT_ERROR":return"Could not delete comment";case"ADD_REACTION_ERROR":return"Could not add reaction";case"REMOVE_REACTION_ERROR":return"Could not remove reaction";case"MARK_INBOX_NOTIFICATION_AS_READ_ERROR":return"Could not mark inbox notification as read";case"DELETE_INBOX_NOTIFICATION_ERROR":return"Could not delete inbox notification";case"MARK_ALL_INBOX_NOTIFICATIONS_AS_READ_ERROR":return"Could not mark all inbox notifications as read";case"DELETE_ALL_INBOX_NOTIFICATIONS_ERROR":return"Could not delete all inbox notifications";case"UPDATE_ROOM_SUBSCRIPTION_SETTINGS_ERROR":return"Could not update room subscription settings";case"UPDATE_NOTIFICATION_SETTINGS_ERROR":return"Could not update notification settings";case"LARGE_MESSAGE_ERROR":return"Could not send large message";case"FEED_REQUEST_ERROR":return e.reason??"Feed request failed";default:return Je(e,"Unhandled case")}}var Aa=5e3;function td(e){const t=rc(e),n=nc(t);return{canWrite:Yn(n,"storage","write"),canComment:Yn(n,"comments","write")}}function gy(e){let t=0;return()=>`${e}:${t++}`}function nd(e,t){return{type:"User",id:`${t.connectionId}`,key:e,payload:{connectionId:t.connectionId,id:t.id,info:t.info,presence:t.presence,isReadOnly:!t.canWrite}}}function vy(){const e=typeof document<"u"?document:void 0,t={current:null};function n(){e?.visibilityState==="hidden"?t.current=t.current??Date.now():t.current=null}return e?.addEventListener("visibilitychange",n),[t,()=>{e?.removeEventListener("visibilitychange",n)}]}function Cy(){let e=new Map;return{append(t){for(const[n,r]of t)e.set(n,r)},take(){const t=e;return e=new Map,t}}}function Ey(e){const t=new Set,n=e.get("root");for(const r in n?.data)t.add(r);for(const r of e.values())r.parentId==="root"&&t.add(r.parentKey);return t}function yy(e,t){const n=t.roomId,r=e.initialPresence,o=e.initialStorage,s=t.roomHttpClient,[i,a]=vy(),u={...t.delegates,canZombie(){return t.backgroundKeepAliveTimeout!==void 0&&i.current!==null&&Date.now()>i.current+t.backgroundKeepAliveTimeout&&aa.getStatus()!=="synchronizing"&&la.getStatus()!=="synchronizing"}},c=new np(u,t.enableDebugLogging),d=new dp,l={buffer:{flushTimerID:void 0,lastFlushedAt:0,presenceUpdates:{type:"full",data:r},messages:[],storageOperations:[]},staticSessionInfoSig:new St(null),dynamicSessionInfoSig:new St(null),myPresence:new h1(r),others:new py,initialStorage:o,idFactory:null,yjsProvider:void 0,yjsProviderDidChange:Ne(),pool:fp({getCurrentConnectionId:X,onDispatch:A,isStorageWritable:T,unacknowledgedOps:d}),root:void 0,undoStack:[],redoStack:[],pausedHistory:null,activeBatch:null,unacknowledgedOps:d},m=Cy(),g=t.enableDebugLogging?fy():void 0;let v;function C(x){const U=c.authValue;if(U!==null){const H=tc(U);if(H!==v)if(v=H,U.type==="secret"){const V=U.token.parsed;l.staticSessionInfoSig.set({userId:V.uid,userInfo:V.ui})}else l.staticSessionInfoSig.set({userId:void 0,userInfo:void 0})}S.status.notify(x),le()}let p,D=!1;function w(x){x==="reconnecting"?p=setTimeout(()=>{S.lostConnection.notify("lost"),D=!0,l.others.clearOthers(),J({others:[{type:"reset"}]})},t.lostConnectionTimeout):(clearTimeout(p),D&&(x==="disconnected"?S.lostConnection.notify("failed"):S.lostConnection.notify("restored"),D=!1))}function b(){l.buffer.presenceUpdates={type:"full",data:{...l.myPresence.get()}},pt!==null&&bl(),Fe()}function y(){clearTimeout(l.buffer.flushTimerID),l.unacknowledgedOps.markAllAsPossiblyStored()}c.events.onMessage.subscribe(Ie),c.events.statusDidChange.subscribe(C),c.events.statusDidChange.subscribe(w),c.events.didConnect.subscribe(b),c.events.didDisconnect.subscribe(y),c.events.onConnectionError.subscribe(({message:x,code:U})=>{const H="ROOM_CONNECTION_ERROR",V=new pu(x,{type:H,code:U,roomId:n});t.errorEventSource.notify(V)});function A(x,U,H){if(l.activeBatch){for(const V of x)l.activeBatch.ops.push(V);for(const[V,Q]of H)l.activeBatch.updates.storageUpdates.set(V,ba(l.activeBatch.updates.storageUpdates.get(V),Q));l.activeBatch.reverseOps.pushLeft(U)}else U.length>0&&q(U),x.length>0&&(l.redoStack.length=0,He(x)),J({storageUpdates:H})}function T(){const x=l.dynamicSessionInfoSig.get()?.permissionMatrix;return x!==void 0?Yn(x,"storage","write"):!0}const S={status:Ne(),lostConnection:Ne(),customEvent:Ne(),self:Ne(),myPresence:Ne(),others:Ne(),storageBatch:Ne(),history:Ne(),storageDidLoad:Ne(),storageStatus:Ne(),ydoc:Ne(),comments:Ne(),feeds:Ne(),roomWillDestroy:Ne()};async function P(x,U){return s.createTextMention({roomId:n,mentionId:x,mention:U})}async function L(x){return s.deleteTextMention({roomId:n,mentionId:x})}async function F(x,U){await s.reportTextEditor({roomId:n,type:x,rootKey:U})}async function M(){return s.listHistoryVersions({roomId:n})}async function N(x){return s.listHistoryVersionsSince({roomId:n,since:x.since,signal:x.signal})}async function _(x){return s.fetchStorageHistoryVersion({roomId:n,versionId:x})}async function I(x){return s.fetchYjsHistoryVersion({roomId:n,versionId:x})}async function j(){return s.createVersionHistorySnapshot({roomId:n})}async function z(x){return s.deleteHistoryVersion({roomId:n,versionId:x})}async function Y(x){return s.executeContextualPrompt({roomId:n,...x})}function oe(x){c.send(co(x))}const G=je.from(l.staticSessionInfoSig,l.dynamicSessionInfoSig,l.myPresence,(x,U,H)=>{if(x===null||U===null)return null;{const V=Yn(U.permissionMatrix,"storage","write");return{connectionId:U.actor,id:x.userId,info:x.userInfo,presence:H,canWrite:V,canComment:Yn(U.permissionMatrix,"comments","write")}}});let Z;function le(){const x=G.get();x!==null&&x!==Z&&(S.self.notify(x),Z=x)}const de=je.from(G,x=>x!==null?nd("Me",x):null);function ue(x){const U=new Map;for(const[H,V]of l.pool.nodes)U.set(H,V._serialize());return ry(U,x)}function ee(x){if(x.size===0)throw new Error("Internal error: cannot load storage without items");if(l.root!==void 0){const Q=ae(ue(x));J(Q.updates)}else l.root=Fn._fromItems(x,l.pool);const U=G.get()?.canWrite??!0,H=Ey(x),V=l.root;Sl(()=>{for(const Q in l.initialStorage)H.has(Q)||(U?V.set(Q,ty(l.initialStorage[Q])):ft(`Attempted to populate missing storage key '${Q}', but current user has no write access`))})}function te(x){if(l.root===void 0)throw new Error("Cannot reconcile storage before it is loaded");const U=ue(new Map(x));if(U.length===0)return;const H=ie(U);H.reverse.length>0&&q(H.reverse),l.redoStack.length=0;for(const V of H.opsToEmit)l.buffer.storageOperations.push(V);J(H.updates),Me(),Fe()}function R(x){l.undoStack.length>=50&&l.undoStack.shift(),l.undoStack.push(x),Me()}function q(x){l.pausedHistory!==null?l.pausedHistory.pushLeft(x):R(x)}function J(x){const U=x.storageUpdates,H=x.others;if(H!==void 0&&H.length>0){const V=l.others.get();for(const Q of H)S.others.notify({...Q,others:V})}if((x.presence??!1)&&(le(),S.myPresence.notify(l.myPresence.get())),U!==void 0&&U.size>0){const V=Array.from(U.values());S.storageBatch.notify(V)}Ts()}function X(){const x=l.dynamicSessionInfoSig.get();if(x)return x.actor;throw new Error("Internal. Tried to get connection id but connection was never open")}function ie(x){const[U,H]=f1(x,Ue=>Ue.type==="presence"),V=H.map(Ue=>Ue.opId===void 0?{...Ue,opId:l.pool.generateOpId()}:Ue),{reverse:Q,updates:De}=we(U,V,!0);return{opsToEmit:V,reverse:Q,updates:De}}function ae(x){return we([],x,!1)}function we(x,U,H){const V={reverse:new Da,storageUpdates:new Map,presence:!1};for(const De of x){const Ue={type:"presence",data:{}};for(const ze in De.data)Ue.data[ze]=l.myPresence.get()[ze];if(l.myPresence.patch(De.data),l.buffer.presenceUpdates===null)l.buffer.presenceUpdates={type:"partial",data:De.data};else for(const ze in De.data)l.buffer.presenceUpdates.data[ze]=De.data[ze];V.reverse.pushLeft(Ue),V.presence=!0}const Q=new Set;for(const De of U){let Ue;H?Ue=0:De.opId!==void 0?(l.unacknowledgedOps.delete(De.opId),Ue=2):Ue=1;const ze=Se(De,Ue);if(ze.modified){const _t=ze.modified.node._id;_t&&Q.has(_t)||(V.storageUpdates.set(ge(ze.modified.node._id),ba(V.storageUpdates.get(ge(ze.modified.node._id)),ze.modified)),V.reverse.pushLeft(ze.reverse)),(De.type===ve.CREATE_LIST||De.type===ve.CREATE_MAP||De.type===ve.CREATE_OBJECT)&&Q.add(De.id)}}return{reverse:Array.from(V.reverse),updates:{storageUpdates:V.storageUpdates,presence:V.presence}}}function Se(x,U){if(kE(x))return{modified:!1};switch(x.type){case ve.DELETE_OBJECT_KEY:case ve.UPDATE_OBJECT:case ve.DELETE_CRDT:{const H=l.pool.nodes.get(x.id);return H===void 0?{modified:!1}:H._apply(x,U===0)}case ve.SET_PARENT_KEY:{const H=l.pool.nodes.get(x.id);return H===void 0?{modified:!1}:H.parent.type==="HasParent"&&sc(H.parent.node)?H.parent.node._setChildKey(Yo(x.parentKey),H,U):{modified:!1}}case ve.CREATE_OBJECT:case ve.CREATE_LIST:case ve.CREATE_MAP:case ve.CREATE_REGISTER:{if(x.parentId===void 0)return{modified:!1};const H=l.pool.nodes.get(x.parentId);return H===void 0?{modified:!1}:H._attachChild(x,U)}default:return{modified:!1}}}function me(x,U){const H={};l.buffer.presenceUpdates===null&&(l.buffer.presenceUpdates={type:"partial",data:{}});for(const V in x){const Q=x[V];Q!==void 0&&(l.buffer.presenceUpdates.data[V]=Q,H[V]=l.myPresence.get()[V])}l.myPresence.patch(x),l.activeBatch?(U?.addToHistory&&l.activeBatch.reverseOps.pushLeft({type:"presence",data:H}),l.activeBatch.updates.presence=!0):(Fe(),U?.addToHistory&&q([{type:"presence",data:H}]),J({presence:!0}))}function fe(x){if(x.targetActor!==void 0){const H=l.others.getUser(x.actor);l.others.setOther(x.actor,x.data);const V=l.others.getUser(x.actor);if(H===void 0&&V!==void 0)return{type:"enter",user:V}}else l.others.patchOther(x.actor,x.data);const U=l.others.getUser(x.actor);if(U)return{type:"update",updates:x.data,user:U}}function ye(x){const U=l.others.getUser(x.actor);return U?(l.others.removeConnection(x.actor),{type:"leave",user:U}):null}function be(x){l.dynamicSessionInfoSig.set({actor:x.actor,nonce:x.nonce,permissionMatrix:nc(rc(x.scopes)),meta:x.meta}),l.idFactory=gy(x.actor),le(),x.meta.showBrand===!0&&cy(t.badgeLocation??"bottom-right");for(const U of l.others.connectionIds())x.users[U]===void 0&&l.others.removeConnection(U);for(const U in x.users){const H=x.users[U],V=Number(U);l.others.setConnection(V,H.id,H.info,td(H.scopes))}return{type:"reset"}}function xe(){return l.undoStack.length>0}function ke(){return l.redoStack.length>0}function Me(){ia>0||S.history.notify({canUndo:xe(),canRedo:ke()})}function O(x){l.others.setConnection(x.actor,x.id,x.info,td(x.scopes)),l.buffer.messages.push({type:rt.UPDATE_PRESENCE,data:l.myPresence.get(),targetActor:x.actor}),Fe();const U=l.others.getUser(x.actor);return U?{type:"enter",user:U}:void 0}function k(x){return dy(x)?x:null}function ne(x){const U=Sn(x);return U===void 0?null:Ep(U)?nu(U.map(H=>k(H))):nu([k(U)])}function re(x){if(x.length===0)return;const U=[],H=ie(x);U.push({type:rt.UPDATE_STORAGE,ops:H.opsToEmit}),J(H.updates),oe(U)}function he(x){return x.type===Ee.FEED_REQUEST_FAILED}function Ie(x){if(typeof x.data!="string")return;const U=ne(x.data);if(U===null||U.length===0)return;const H={storageUpdates:new Map,others:[]};for(const V of U)switch(V.type){case Ee.USER_JOINED:{const Q=O(V);Q&&H.others.push(Q);break}case Ee.UPDATE_PRESENCE:{const Q=fe(V);Q&&H.others.push(Q);break}case Ee.BROADCASTED_EVENT:{const Q=l.others.get();S.customEvent.notify({connectionId:V.actor,user:V.actor<0?null:Q.find(De=>De.connectionId===V.actor)??null,event:V.event});break}case Ee.USER_LEFT:{const Q=ye(V);Q&&H.others.push(Q);break}case Ee.UPDATE_YDOC:{S.ydoc.notify(V);break}case Ee.ROOM_STATE:{H.others.push(be(V));break}case Ee.STORAGE_CHUNK:g?.lap(),m.append(LE(V.nodes));break;case Ee.STORAGE_STREAM_END:{const Q=g?.stop();if(Q){const De=ze=>`${ze.toFixed(1)}ms`,Ue=Q.laps.slice(1);ft(`Storage chunk arrival: ${[`total=${De(Q.total)}`,`first=${De(Q.laps[0])}`,`rest.n=${Ue.length}`,`rest.avg=${De(Ue.reduce((ze,_t)=>ze+_t,0)/Ue.length)}`,`rest.max=${De(Ue.reduce((ze,_t)=>Math.max(ze,_t),0))}`].join(", ")}`)}sC(m.take());break}case Ee.UPDATE_STORAGE:{const Q=ae(V.ops);for(const[De,Ue]of Q.updates.storageUpdates)H.storageUpdates.set(De,ba(H.storageUpdates.get(De),Ue));break}case Ee.REJECT_STORAGE_OP:{Wh("Storage mutation rejection error",V.reason);break}case Ee.THREAD_CREATED:case Ee.THREAD_DELETED:case Ee.THREAD_METADATA_UPDATED:case Ee.THREAD_UPDATED:case Ee.COMMENT_REACTION_ADDED:case Ee.COMMENT_REACTION_REMOVED:case Ee.COMMENT_CREATED:case Ee.COMMENT_EDITED:case Ee.COMMENT_DELETED:case Ee.COMMENT_METADATA_UPDATED:{S.comments.notify(V);break}case Ee.FEEDS_LIST:{const Q=V,De=Ve.get(Q.requestId);De&&(De.resolve({feeds:Q.feeds,nextCursor:Q.nextCursor}),Ve.delete(Q.requestId)),S.feeds.notify(Q);break}case Ee.FEEDS_ADDED:{const Q=V;S.feeds.notify(Q),on(Q);break}case Ee.FEEDS_UPDATED:{const Q=V;S.feeds.notify(Q),on(Q);break}case Ee.FEED_DELETED:{S.feeds.notify(V),on(V);break}case Ee.FEED_MESSAGES_LIST:{const Q=V,De=Mt.get(Q.requestId);De&&(De.resolve({messages:Q.messages,nextCursor:Q.nextCursor}),Mt.delete(Q.requestId)),S.feeds.notify(Q);break}case Ee.FEED_MESSAGES_ADDED:{const Q=V;S.feeds.notify(Q),on(Q);break}case Ee.FEED_MESSAGES_UPDATED:{const Q=V;S.feeds.notify(Q),on(Q);break}case Ee.FEED_MESSAGES_DELETED:{S.feeds.notify(V),on(V);break}case Ee.FEED_REQUEST_FAILED:{if(!he(V))break;const{requestId:Q,code:De,reason:Ue}=V,ze=new pu(Ue??"Feed request failed",{type:"FEED_REQUEST_ERROR",roomId:n,requestId:Q,code:De,reason:Ue});if(gt.has(Q))vt(Q,"error",ze);else if(Ve.has(Q)){const _t=Ve.get(Q);Ve.delete(Q),_t?.reject(ze)}else if(Mt.has(Q)){const _t=Mt.get(Q);Mt.delete(Q),_t?.reject(ze)}S.feeds.notify(V);break}case Ee.STORAGE_STATE_V7:}J(H)}function Fe(){const x=l.buffer.storageOperations;if(x.length>0){for(const V of x)l.unacknowledgedOps.add(V);Ts()}if(c.getStatus()!=="connected"){l.buffer.storageOperations=[];return}const U=Date.now(),H=U-l.buffer.lastFlushedAt;if(H>=t.throttleDelay){const V=Xe();if(V.length===0)return;oe(V),l.buffer={flushTimerID:void 0,lastFlushedAt:U,messages:[],storageOperations:[],presenceUpdates:null}}else clearTimeout(l.buffer.flushTimerID),l.buffer.flushTimerID=setTimeout(Fe,t.throttleDelay-H)}function Xe(){const x=[];l.buffer.presenceUpdates&&x.push(l.buffer.presenceUpdates.type==="full"?{type:rt.UPDATE_PRESENCE,targetActor:-1,data:l.buffer.presenceUpdates.data}:{type:rt.UPDATE_PRESENCE,data:l.buffer.presenceUpdates.data});for(const U of l.buffer.messages)x.push(U);return l.buffer.storageOperations.length>0&&x.push({type:rt.UPDATE_STORAGE,ops:l.buffer.storageOperations}),x}function ht(x,U,H){const V={type:rt.UPDATE_YDOC,update:x,guid:U,v2:H};l.buffer.messages.push(V),S.ydoc.notify(V),Fe()}function Gt(x,U={shouldQueueEventIfNotReady:!1}){c.getStatus()!=="connected"&&!U.shouldQueueEventIfNotReady||(l.buffer.messages.push({type:rt.BROADCAST_EVENT,event:x}),Fe())}function He(x){const{storageOperations:U}=l.buffer;for(const H of x)U.push(H);Fe()}let pt=null,mt=null;const Ve=new Map,Mt=new Map,gt=new Map,qt=new Map;function vt(x,U,H){const V=gt.get(x);if(V!==void 0){if(clearTimeout(V.timeoutId),gt.delete(x),V.kind==="add-message"&&!V.expectedClientMessageId){const Q=qt.get(V.feedId);if(Q!==void 0){const De=Q.indexOf(x);De>=0&&Q.splice(De,1),Q.length===0&&qt.delete(V.feedId)}}U==="ok"?V.resolve():V.reject(H??new Error("Feed mutation failed"))}}function rn(x,U,H,V){const{promise:Q,resolve:De,reject:Ue}=Jr(),ze=setTimeout(()=>{gt.has(x)&&vt(x,"error",new Error("Feed mutation timeout"))},Aa);if(gt.set(x,{resolve:De,reject:Ue,timeoutId:ze,kind:U,feedId:H,messageId:V?.messageId,expectedClientMessageId:V?.expectedClientMessageId}),U==="add-message"&&V?.expectedClientMessageId===void 0){const _t=qt.get(H)??[];_t.push(x),qt.set(H,_t)}return Q}function on(x){switch(x.type){case Ee.FEEDS_ADDED:{for(const U of x.feeds)for(const[H,V]of[...gt])if(V.kind==="add-feed"&&V.feedId===U.feedId){vt(H,"ok");break}break}case Ee.FEEDS_UPDATED:{for(const U of x.feeds)for(const[H,V]of[...gt])V.kind==="update-feed"&&V.feedId===U.feedId&&vt(H,"ok");break}case Ee.FEED_DELETED:{for(const[U,H]of[...gt])if(H.kind==="delete-feed"&&H.feedId===x.feedId){vt(U,"ok");break}break}case Ee.FEED_MESSAGES_ADDED:{for(const U of x.messages){let H=!1;for(const[V,Q]of[...gt])if(Q.kind==="add-message"&&Q.feedId===x.feedId&&Q.expectedClientMessageId===U.id){vt(V,"ok"),H=!0;break}if(!H){const Q=qt.get(x.feedId)?.[0];if(Q!==void 0){const De=gt.get(Q);De?.kind==="add-message"&&De.expectedClientMessageId===void 0&&vt(Q,"ok")}}}break}case Ee.FEED_MESSAGES_UPDATED:{for(const U of x.messages)for(const[H,V]of[...gt])V.kind==="update-message"&&V.feedId===x.feedId&&V.messageId===U.id&&vt(H,"ok");break}case Ee.FEED_MESSAGES_DELETED:{for(const U of x.messageIds)for(const[H,V]of[...gt])V.kind==="delete-message"&&V.feedId===x.feedId&&V.messageId===U&&vt(H,"ok");break}}}function sC(x){const U=[...l.unacknowledgedOps.values()];ee(x),re(U),mt?.(),Ts(),S.storageDidLoad.notify()}function bl(){const x=l.buffer.messages;x.some(U=>U.type===rt.FETCH_STORAGE)||(x.push({type:rt.FETCH_STORAGE}),m.take(),g?.start())}function wl(){return pt===null&&(bl(),Fe(),pt=new Promise(x=>{mt=x}),Ts()),pt}function sa(){const x=l.root;return x!==void 0?x:(wl(),null)}async function Dl(){return l.root!==void 0?Promise.resolve({root:l.root}):(await wl(),{root:ge(l.root)})}function iC(x,U,H){l.buffer.messages.find(V=>V.type===rt.FETCH_YDOC&&V.vector===x&&V.guid===U&&V.v2===H)||l.buffer.messages.push({type:rt.FETCH_YDOC,vector:x,guid:U,v2:H}),Fe()}async function aC(x){const U=it(),{promise:H,resolve:V,reject:Q}=Jr();Ve.set(U,{resolve:V,reject:Q});const De={type:rt.FETCH_FEEDS,requestId:U,cursor:x?.cursor,since:x?.since,limit:x?.limit,metadata:x?.metadata};return l.buffer.messages.push(De),Fe(),setTimeout(()=>{Ve.has(U)&&(Ve.delete(U),Q(new Error("Feeds fetch timeout")))},Aa),H}async function uC(x,U){const H=it(),{promise:V,resolve:Q,reject:De}=Jr();Mt.set(H,{resolve:Q,reject:De});const Ue={type:rt.FETCH_FEED_MESSAGES,requestId:H,feedId:x,cursor:U?.cursor,since:U?.since,limit:U?.limit};return l.buffer.messages.push(Ue),Fe(),setTimeout(()=>{Mt.has(H)&&(Mt.delete(H),De(new Error("Feed messages fetch timeout")))},Aa),V}function cC(x,U){const H=it(),V=rn(H,"add-feed",x),Q={type:rt.ADD_FEED,requestId:H,feedId:x,metadata:U?.metadata,createdAt:U?.createdAt};return l.buffer.messages.push(Q),Fe(),V}function lC(x,U){const H=it(),V=rn(H,"update-feed",x),Q={type:rt.UPDATE_FEED,requestId:H,feedId:x,metadata:U};return l.buffer.messages.push(Q),Fe(),V}function dC(x){const U=it(),H=rn(U,"delete-feed",x),V={type:rt.DELETE_FEED,requestId:U,feedId:x};return l.buffer.messages.push(V),Fe(),H}function fC(x,U,H){const V=it(),Q=rn(V,"add-message",x,{expectedClientMessageId:H?.id}),De={type:rt.ADD_FEED_MESSAGE,requestId:V,feedId:x,data:U,id:H?.id,createdAt:H?.createdAt};return l.buffer.messages.push(De),Fe(),Q}function hC(x,U,H,V){const Q=it(),De=rn(Q,"update-message",x,{messageId:U}),Ue={type:rt.UPDATE_FEED_MESSAGE,requestId:Q,feedId:x,messageId:U,data:H,updatedAt:V?.updatedAt};return l.buffer.messages.push(Ue),Fe(),De}function pC(x,U){const H=it(),V=rn(H,"delete-message",x,{messageId:U}),Q={type:rt.DELETE_FEED_MESSAGE,requestId:H,feedId:x,messageId:U};return l.buffer.messages.push(Q),Fe(),V}function mC(){if(l.activeBatch)throw new Error("undo is not allowed during a batch");const x=l.undoStack.pop();if(x===void 0)return;l.pausedHistory=null;const U=ie(x);J(U.updates),l.redoStack.push(U.reverse),Me();for(const H of U.opsToEmit)l.buffer.storageOperations.push(H);Fe()}function gC(){if(l.activeBatch)throw new Error("redo is not allowed during a batch");const x=l.redoStack.pop();if(x===void 0)return;l.pausedHistory=null;const U=ie(x);J(U.updates),l.undoStack.push(U.reverse),Me();for(const H of U.opsToEmit)l.buffer.storageOperations.push(H);Fe()}function vC(){l.undoStack.length=0,l.redoStack.length=0}function CC(x){if(l.activeBatch)return x();let U;l.activeBatch={ops:[],updates:{storageUpdates:new Map,presence:!1,others:[]},reverseOps:new Da,scheduleHistoryResume:!1};try{U=x()}finally{const H=l.activeBatch;l.activeBatch=null,H.reverseOps.length>0&&q(Array.from(H.reverseOps)),H.scheduleHistoryResume&&Al(),H.ops.length>0&&(l.redoStack.length=0),H.ops.length>0&&He(H.ops),J(H.updates),Fe()}return U}function EC(){l.pausedHistory===null&&(l.pausedHistory=new Da)}function Al(){const x=l.pausedHistory;l.pausedHistory=null,x!==null&&x.length>0&&R(Array.from(x))}function yC(){if(l.activeBatch!==null){l.activeBatch.scheduleHistoryResume=!0;return}Al()}let ia=0;function Sl(x){const U=l.undoStack,H=l.redoStack,V=[],Q=[];l.undoStack=V,l.redoStack=Q,ia++;try{return x()}finally{if(ia--,l.undoStack!==V||l.redoStack!==Q)throw new Error("unexpected stack swap during history.disable()");l.undoStack=U,l.redoStack=H}}const aa=t.createSyncSource();function ua(){return l.root===void 0?pt===null?"not-loaded":"loading":l.unacknowledgedOps.size===0?"synchronized":"synchronizing"}let xl=ua();function Ts(){const x=ua();xl!==x&&(xl=x,S.storageStatus.notify(x)),aa.setSyncStatus(x==="synchronizing"?"synchronizing":"synchronized")}function Ol(){return G.get()!==null}async function bC(){for(;!Ol();){const{promise:x,resolve:U}=Jr(),H=ca.self.subscribeOnce(U),V=ca.status.subscribeOnce(U);await x,H(),V()}}function Tl(){return sa()!==null}async function wC(){for(;!Tl();)await Dl()}const DC=je.from(l.others.signal,x=>x.map((U,H)=>nd(`Other ${H}`,U))),ca={status:S.status.observable,lostConnection:S.lostConnection.observable,customEvent:S.customEvent.observable,others:S.others.observable,self:S.self.observable,myPresence:S.myPresence.observable,storageBatch:S.storageBatch.observable,history:S.history.observable,storageDidLoad:S.storageDidLoad.observable,storageStatus:S.storageStatus.observable,ydoc:S.ydoc.observable,comments:S.comments.observable,feeds:S.feeds.observable,roomWillDestroy:S.roomWillDestroy.observable};async function AC(x){return s.getThreadsSince({roomId:n,since:x.since,signal:x.signal})}async function SC(x){return s.getThreads({roomId:n,query:x?.query,cursor:x?.cursor})}async function xC(x){return s.getThread({roomId:n,threadId:x})}async function OC(x){return s.createThread({roomId:n,threadId:x.threadId,commentId:x.commentId,visibility:x.visibility,metadata:x.metadata,body:x.body,commentMetadata:x.commentMetadata,attachmentIds:x.attachmentIds})}async function TC(x){return s.deleteThread({roomId:n,threadId:x})}async function RC({metadata:x,threadId:U}){return s.editThreadMetadata({roomId:n,threadId:U,metadata:x})}async function IC({threadId:x,commentId:U,metadata:H}){return s.editCommentMetadata({roomId:n,threadId:x,commentId:U,metadata:H})}async function BC(x){return s.markThreadAsResolved({roomId:n,threadId:x})}async function FC(x){return s.markThreadAsUnresolved({roomId:n,threadId:x})}async function PC(x){return s.subscribeToThread({roomId:n,threadId:x})}async function MC(x){return s.unsubscribeFromThread({roomId:n,threadId:x})}async function _C(x){return s.createComment({roomId:n,threadId:x.threadId,commentId:x.commentId,body:x.body,metadata:x.metadata,attachmentIds:x.attachmentIds})}async function kC(x){return s.editComment({roomId:n,threadId:x.threadId,commentId:x.commentId,body:x.body,metadata:x.metadata,attachmentIds:x.attachmentIds})}async function NC({threadId:x,commentId:U}){return s.deleteComment({roomId:n,threadId:x,commentId:U})}async function jC({threadId:x,commentId:U,emoji:H}){return s.addReaction({roomId:n,threadId:x,commentId:U,emoji:H})}async function LC({threadId:x,commentId:U,emoji:H}){return await s.removeReaction({roomId:n,threadId:x,commentId:U,emoji:H})}function UC(x){return{type:"localAttachment",status:"idle",id:qh(),name:x.name,size:x.size,mimeType:x.type,file:x}}async function $C(x,U={}){return s.uploadAttachment({roomId:n,attachment:x,signal:U.signal})}function HC(x){return s.getAttachmentUrl({roomId:n,attachmentId:x})}function Rl(x){return s.getSubscriptionSettings({roomId:n,signal:x?.signal})}function Il(x){return s.updateSubscriptionSettings({roomId:n,settings:x})}async function VC(x){await s.markRoomInboxNotificationAsRead({roomId:n,inboxNotificationId:x})}const la=t.createSyncSource();function da(x){return la.setSyncStatus(x==="synchronizing"||x==="loading"?"synchronizing":"synchronized")}return Object.defineProperty({[Ce]:{get presenceBuffer(){return ao(l.buffer.presenceUpdates?.data??null)},get undoStack(){return ao(l.undoStack)},get nodeCount(){return l.pool.nodes.size},getYjsProvider(){return l.yjsProvider},setYjsProvider(x){l.yjsProvider?.off("status",da),l.yjsProvider=x,x?.on("status",da),l.yjsProviderDidChange.notify()},yjsProviderDidChange:l.yjsProviderDidChange.observable,reportTextEditor:F,getPermissionMatrix:()=>l.dynamicSessionInfoSig.get()?.permissionMatrix,createTextMention:P,deleteTextMention:L,listHistoryVersions:M,listHistoryVersionsSince:N,fetchStorageHistoryVersion:_,fetchYjsHistoryVersion:I,liveObjectFromNodeStream:XE,reconcileStorageWithNodes:te,createVersionHistorySnapshot:j,deleteHistoryVersion:z,executeContextualPrompt:Y,getSelf_forDevTools:()=>de.get(),getOthers_forDevTools:()=>DC.get(),simulate:{explicitClose:x=>c._privateSendMachineEvent({type:"EXPLICIT_SOCKET_CLOSE",event:x}),rawSend:x=>c.send(x),incomingMessage:x=>Ie(new MessageEvent("message",{data:x}))},attachmentUrlsStore:s.getOrCreateAttachmentUrlsStore(n)},id:n,subscribe:by(n,S,t.errorEventSource),connect:()=>c.connect(),reconnect:()=>c.reconnect(),disconnect:()=>c.disconnect(),_dump:()=>{const x=l.pool.nodes.size;return`Room "${n}" (${x} node${x===1?"":"s"}):
|