@vite-hub/comments 0.7.0 → 0.9.0
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/README.md +4 -10
- package/dist/anchor.d.ts +2 -2
- package/dist/anchor.js +0 -1
- package/dist/{client-files-lC6X7XyS.js → client-files-CMPJEd21.js} +0 -1
- package/dist/client-request-B1DCz3a9.js +29 -0
- package/dist/client.d.ts +21 -241
- package/dist/client.js +4 -425
- package/dist/database.d.ts +1 -2
- package/dist/database.js +1 -1
- package/dist/{define-BqPcuDhf.js → define-hs9Z38io.js} +1 -2
- package/dist/{errors-C0VwRHiy.js → errors-C5utwZ5H.js} +0 -24
- package/dist/{errors-CBvIpwbo.js → errors-DeSEHzRf.js} +0 -12
- package/dist/hosted/hosted-comments/frame.js +4 -1
- package/dist/hosted/hosted-comments/tools.js +71 -77
- package/dist/hosted/hosted-comments.js +1 -1
- package/dist/{index-D1T7RJ4R.d.ts → index-CbXek64X.d.ts} +5 -113
- package/dist/index.d.ts +5 -6
- package/dist/index.js +6 -23
- package/dist/{install-CqBWFmU7.js → install--HecUN5c.js} +8 -789
- package/dist/{install-9L4ASzUC.d.ts → install-C3CW6Vvw.d.ts} +6 -12
- package/dist/{installed-wUYjqk_k.js → installed-BqQKo6WC.js} +2 -7
- package/dist/{database-BuSNVwTx.js → migrate-cxoJK4JQ.js} +2 -64
- package/dist/{operations-Qt8ASQqW.d.ts → operations-D0EO1pzL.d.ts} +36 -8
- package/dist/{operations-kMPw-Cyb.js → operations-DHXmbtb3.js} +47 -75
- package/dist/operations.d.ts +3 -3
- package/dist/operations.js +2 -2
- package/dist/overlay/client-BszZKIf8.js +4 -0
- package/dist/overlay/overlay.js +50 -43
- package/dist/page/loader.js +37 -30
- package/dist/{page-2NzFladc.js → page-CJz1K67L.js} +25 -2
- package/dist/page-DRM1j84-.d.ts +32 -0
- package/dist/{page-tools-shared-BNw-aWEH.js → page-tools-shared-BCdvqA4S.js} +40 -2
- package/dist/{path-8yqMd8zR.js → path-sv8kjq3i.js} +0 -4
- package/dist/{plugin-ChOHe7vq.js → plugin-DczA2K-y.js} +9 -9
- package/dist/realtime.d.ts +7 -9
- package/dist/realtime.js +2 -4
- package/dist/{rpc-kkxzQ3Qy.js → rpc-51X1TWKb.js} +1 -1
- package/dist/{rpc-D-eqtyfh.d.ts → rpc-DZB3yU0z.d.ts} +1 -1
- package/dist/rpc.d.ts +1 -1
- package/dist/rpc.js +1 -1
- package/dist/runtime/auth.d.ts +1 -2
- package/dist/runtime/auth.js +1 -1
- package/dist/runtime/client-request-plugin.d.ts +2 -0
- package/dist/runtime/client-request-plugin.js +21 -0
- package/dist/runtime/console.js +2 -2
- package/dist/runtime/index.d.ts +6 -9
- package/dist/runtime/index.js +25 -175
- package/dist/{server-8o9u8leM.js → server-CAMs6viR.js} +1 -1
- package/dist/server.d.ts +12 -8
- package/dist/server.js +8 -7
- package/dist/{service-XT2A8YEF.js → service-DFMwCr60.js} +34 -42
- package/dist/{store-DvNTDNgn.d.ts → service-qaMuJ7UX.d.ts} +68 -2
- package/dist/{session-DGdFKWDB.js → session-1SI3_wLJ.js} +212 -66
- package/dist/{session-CN4irEqf.d.ts → session-CK3Rnjto.d.ts} +2 -3
- package/dist/{table-names-BIHjuEFK.js → table-names-DUmWROM4.js} +1 -3
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +1 -2
- package/dist/{tokens-Bx4lZ0yt.js → tokens-WRh__ppm.js} +0 -1
- package/dist/{types-BX3vH18p.d.ts → types-BmzTyGt-.d.ts} +4 -0
- package/dist/{define-B1jLSPe9.d.ts → types-VSVs4jIw.d.ts} +157 -4
- package/dist/vite.d.ts +3 -20
- package/dist/vite.js +15 -82
- package/package.json +8 -8
- package/dist/database-CPua6Q6_.d.ts +0 -573
- package/dist/overlay/client-CrnKCZXc.js +0 -4
- package/dist/overlay/dist-yIZmvSaU.js +0 -1
- package/dist/page-DE71P_gQ.d.ts +0 -11
- package/dist/request-origin-B-CPVAVk.js +0 -53
- package/dist/service-IvgrI4XM.d.ts +0 -71
- package/dist/types-l6GOb_yc.d.ts +0 -206
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
function e(e,...t){return typeof e==`function`?e(...t):e}var t=Error.captureStackTrace,n=class e extends Error{get why(){return this.message}constructor(n,r=e){super(n.why,{cause:n.cause}),this.code=this.name=n.code,this.docs=n.docs,this.fix=n.fix,this.sources=n.sources,this.data=n.data,t?.(this,r)}toJSON(){return{name:this.name,why:this.why,fix:this.fix,docs:this.docs,sources:this.sources,cause:this.cause,data:this.data,stack:this.stack}}};function r(e,t){return typeof e==`string`?`${e}/${t.toLowerCase()}`:e?.(t)}var i=e=>t=>t instanceof n&&e in t;function a(t){let a=t.reporters??[],o=Symbol(),s=Object.defineProperty({},"is",{value:i(o)}),{docsBase:c}=t;for(let i of Object.keys(t.codes)){let l=t.codes[i],u=l.docs===!1?void 0:l.docs||r(c,i),d=(t={},r={})=>{let s=new n({code:i,why:e(l.why,t),fix:e(l.fix,t),docs:u,cause:t.cause,sources:t.sources,data:e(l.data,t)},d);s[o]=1;for(let e of a)e(s,r);return s};d.is=e=>s.is(e)&&e.code===i,s[i]=d}return s}var o={why:({message:e})=>e===void 0?``:String(e)},s=a({docsBase:`https://vitehub.dev/docs/runtime/diagnostics`,codes:{RUNTIME_R0001:{...o,fix:"Pass `maxDepth` to `normalizeRuntimeDiagnosticError()` as an integer of 0 or more, or remove it to use the default."},RUNTIME_R0002:{...o,fix:"Pass `maxErrors` to `normalizeRuntimeDiagnosticError()` as an integer of 1 or more, or remove it to use the default."},RUNTIME_R0003:{...o,fix:"Pass `maxStringLength` to `normalizeRuntimeDiagnosticError()` as an integer of 64 or more, or remove it to use the default."},RUNTIME_R0004:{...o,fix:"Read the logs of the process that `vitehub drain` waited for to find why its drain failed, then fix that failure and run `vitehub drain` again."},RUNTIME_R0005:{...o,fix:"Read the logs of the process that the message names to find why it stopped, then start it again before you run `vitehub drain`."},RUNTIME_R0006:{...o,fix:"Pass `new ViteHubError()` a nonempty `code` and `message` string within the length limits, and plain JSON `details`."},RUNTIME_R0007:{...o,fix:"Give the execution authority a valid value for each of `credentials`, `environment`, `filesystem.access`, `filesystem.scope`, `isolation`, `network`, and `processes`."},RUNTIME_R0009:{...o,fix:"Set `intervalMs` of the process reconciler to a number of milliseconds from 1 to 2147483647."},RUNTIME_R0010:{...o,fix:"Give the process reconciler a `signal` other than `SIGKILL` or `SIGSTOP`, or set `signal: false`."},RUNTIME_R0011:{...o,fix:"Call `drain()` of the process reconciler after its callback returns, not from inside the callback."},RUNTIME_R0015:{...o,fix:"Pass the `Request` of a Fetchable handler, or the event of an H3 or Nitro route, to `getStandardContext()`."},RUNTIME_R0016:{...o,fix:"Return the body or a `Response` from the handler, in place of setting `~standard.res.body`."},RUNTIME_R0017:o,RUNTIME_R0018:o,RUNTIME_CONSOLE_PATH_INVALID:{why:({value:e})=>`${e} is not a Console path. Use a path that starts with one /, such as /agents/<agent>.`,fix:"Pass `hostedConsoleUrl()` a Console path that starts with one `/`, such as `/kv` or `/agents/<agent>/invocations/<id>`."},RUNTIME_CONSOLE_PROJECT_URL_INVALID:{why:({value:e})=>`${e} is not a project URL. Use the https:// origin of the app, with its base path if it has one.`,fix:"Pass `hostedConsoleUrl()` the `https://` origin of the app, or `http://localhost` in development, with its base path and without a user name or password."},RUNTIME_CONSOLE_URL_INVALID:{why:()=>"`VITEHUB_CONSOLE_URL` must be an https origin without a path, or an http origin on localhost.",fix:"Set `VITEHUB_CONSOLE_URL` on the server to the origin of your ViteHub Console, such as `https://console.example.com`, with no path, query, or user name. Then restart or deploy the server."},RUNTIME_DURATION_INVALID:{why:({option:e,value:t})=>`${e?`\`${e}\``:`The value`} is ${t}, which is not a duration. A duration is a string with a number of 0 or more and a unit, such as "30s", "5m", or "1 day".`,fix:({suggestion:e,unit:t=`milliseconds`,value:n})=>e?`Write the time as a string with a unit: ${n} ${t} is ${e}.`:'Write a number of 0 or more and one unit: `ms`, `s`, `m`, `h`, `d`, or `w`, or a long name such as `minutes` or `days`. For example `"30s"`, `"5m"`, or `"1 day"`.'},RUNTIME_EVENT_LOOP_WARNING_INVALID:{why:({value:e})=>`\`watchEventLoop()\` received \`afterMs: ${e}\`. The threshold must be a whole number of milliseconds of 100 or more.`,fix:"Pass a whole number of milliseconds of 100 or more, or omit `afterMs` to use the default of 10 000 ms."},RUNTIME_EXECUTION_BUDGET_AMOUNT_INVALID:{why:({counter:e})=>`[vitehub] Execution budget ${e} amount must be a finite non-negative number.`,fix:"Pass `consume()` and the `record*()` methods of the execution budget a finite number of 0 or more."},RUNTIME_EXECUTION_BUDGET_EXCEEDED:{why:({counter:e})=>`[vitehub] Execution budget exhausted for ${e}.`,fix:"Raise the `executionBudget` limit that `error.counter` names, such as `maxToolCalls`, `maxRetries`, `maxInputBytes`, or `maxOutputBytes`, or give the run less work."},RUNTIME_EXECUTION_BUDGET_LIMIT_INVALID:{why:()=>`[vitehub] Execution budget limits must be finite non-negative numbers.`,fix:"Set each limit of `executionBudget`, such as `maxToolCalls` or `maxOutputBytes`, to a finite number of 0 or more, or remove it."},RUNTIME_HIDDEN_ERROR:{why:()=>`The server failed. The error is not a ViteHub error, so its message and stack stay on the server.`,fix:"Read the server logs for the error. To send a code, a why, and a fix to the client, return a `ResultError` from `defineErrors()` and pass it to `toResponse()`."},RUNTIME_PUBLIC_URL_INVALID:{why:()=>"`VITEHUB_PUBLIC_URL` must be an http or https origin without a path.",fix:"Set `VITEHUB_PUBLIC_URL` on the server to the origin that serves the app, such as `https://shop.example.com`, with no path, query, or user name. Then restart or deploy the server."},RUNTIME_SERIALIZED_RESPONSE_INVALID:{why:()=>`Invalid serialized Response`,fix:"Pass `deserializeResponse()` the record that `serializeResponse()` returned, unchanged. Check it first with `isSerializedResponse()`."}}}),c=8,l=128,u=128,d=1024,f=16384,ee=128,te=16384,ne=256,re=new WeakMap;function p(){throw s.RUNTIME_R0006({message:`[vitehub] ViteHubError requires a valid public error contract.`})}function m(e){try{return Array.isArray(e)}catch{p()}}function h(e,t,n=!1){try{let r=Object.getOwnPropertyDescriptor(e,t);return r===void 0?void 0:((!(`value`in r)||n&&!r.enumerable)&&p(),r.value)}catch{p()}}function ie(e,t,n,r){if(t.nodes+=1,t.nodes>d&&p(),e===void 0&&r)return;if(e===null||typeof e==`boolean`||typeof e==`string`&&e.length<=f||typeof e==`number`&&Number.isFinite(e))return e;(typeof e!=`object`||n>c||t.ancestors.has(e))&&p();let i,a;try{i=Object.getPrototypeOf(e),a=Reflect.ownKeys(e)}catch{p()}t.ancestors.add(e);try{if(m(e)){let r=h(e,`length`);(!Number.isSafeInteger(r)||r<0||r>l||a.length!==r+1||!a.includes(`length`))&&p();let i=[];for(let o=0;o<r;o+=1){let r=String(o);a.includes(r)||p(),i.push(ie(h(e,r,!0),t,n+1,!1))}return Object.freeze(i)}i!==Object.prototype&&i!==null&&p(),(a.length>l||a.some(e=>typeof e!=`string`))&&p();let r={};for(let i of a)(i.length===0||i.length>u)&&p(),Object.defineProperty(r,i,{enumerable:!0,value:ie(h(e,i,!0),t,n+1,!0),writable:!0});return Object.freeze(r)}finally{t.ancestors.delete(e)}}function ae(e){if(e!==void 0)return(typeof e!=`object`||!e||m(e))&&p(),ie(e,{ancestors:new Set,nodes:0},0,!1)}function oe(e,t,n){(typeof e!=`string`||e.length===0||e.length>ee)&&p(),(typeof t!=`string`||t.length===0||t.length>te)&&p(),(typeof n!=`object`||!n||m(n))&&p();let r=h(n,`cause`),i=ae(h(n,`details`)),a=h(n,`requestId`);return a!==void 0&&(typeof a!=`string`||a.length===0||a.length>ne)&&p(),{cause:r,code:e,details:i,message:t,name:`ViteHubError`,requestId:a,shape:Object.freeze({code:e,...i===void 0?{}:{details:i},message:t,name:`ViteHubError`,...a===void 0?{}:{requestId:a}})}}var se=class extends Error{code;details;requestId;constructor(e,t,n={}){let r=oe(e,t,n);super(r.message,r.cause===void 0?void 0:{cause:r.cause}),this.name=`ViteHubError`,this.code=r.code,this.details=r.details,this.requestId=r.requestId;let i=this.toJSON.bind(this);Object.defineProperties(this,{code:{configurable:!0,enumerable:!0,value:r.code,writable:!1},details:{configurable:!0,enumerable:!0,value:r.details,writable:!1},message:{configurable:!0,enumerable:!1,value:r.message,writable:!1},name:{configurable:!1,enumerable:!1,value:r.name,writable:!1},requestId:{configurable:!0,enumerable:!0,value:r.requestId,writable:!1},toJSON:{configurable:!1,enumerable:!1,value:i,writable:!1}}),re.set(this,r.shape)}toJSON(){let e=re.get(this);if(e)return e;let t=oe(h(this,`code`),h(this,`message`),{details:h(this,`details`),requestId:h(this,`requestId`)});return re.set(this,t.shape),t.shape}};function ce(e){return e!==null&&Object(e)===e}function le(e){if(!ce(e))return!1;try{let t=Reflect.get(Error,`isError`);if(typeof t==`function`)return t(e)===!0;let n=globalThis.process?.getBuiltinModule?.(`node:util`)?.types?.isNativeError;return n?n(e):e instanceof Error||!(Symbol.toStringTag in e)&&Object.prototype.toString.call(e)===`[object Error]`}catch{return!1}}function ue(e){if(!le(e))return!1;try{let t=Reflect.get(e,`message`),n=Reflect.get(e,`code`),r=Reflect.get(e,`name`),i=Reflect.get(e,`why`),a=Reflect.get(e,`fix`),o=Reflect.get(e,`docs`),s=Reflect.get(e,`sources`);return typeof n==`string`&&n.length>0&&typeof r==`string`&&typeof t==`string`&&i===t&&(a===void 0||typeof a==`string`)&&(o===void 0||typeof o==`string`)&&(s===void 0||Array.isArray(s)&&s.every(e=>typeof e==`string`))&&typeof Reflect.get(e,`toJSON`)==`function`}catch{return!1}}var de=Symbol.for(`vitehub.runtime.resultError`);function fe(e){let t=t=>{let n=Object.getOwnPropertyDescriptor(e,t);return n?n.configurable===!0:Object.isExtensible(e)},r=t(`name`)&&t(`toJSON`)&&(Object.hasOwn(e,de)||Object.isExtensible(e))?e:new n({code:e.code,why:e.why,fix:e.fix,docs:e.docs,cause:e.cause,data:e.data,sources:e.sources});if(r!==e){r.stack=e.stack;let t=Reflect.get(e,`status`);typeof t==`number`&&Object.defineProperty(r,"status",{configurable:!0,value:t})}return Object.defineProperty(r,"name",{configurable:!0,value:r.code,writable:!0}),Object.defineProperty(r,de,{value:!0}),Object.defineProperty(r,"toJSON",{configurable:!0,value:()=>({code:r.code,docs:r.docs,fix:r.fix,name:r.name,why:r.why})}),r}function pe(e){let t=a({codes:e.codes,docsBase:e.docs}),n=new Set(Object.keys(e.codes)),r=Object.defineProperty({},"is",{value:e=>ue(e)&&n.has(e.code)});for(let i of n){let n=t[i],a=e.codes[i]?.status;r[i]=Object.assign(e=>{let t=fe(n(e));return a!==void 0&&Object.defineProperty(t,"status",{configurable:!0,enumerable:!1,value:a}),t},{is:e=>ue(e)&&e.code===i})}return r}var me=pe({docs:`https://vitehub.dev/docs/realtime/diagnostics`,codes:{REALTIME_DISABLED:{why:({action:e})=>`Realtime is disabled, so \`${e}()\` cannot run.`,fix:"Set `enabled` to `true` on `useRealtimeTiptap()` before you call the method."},REALTIME_DISCONNECTED:{why:({action:e})=>`The realtime document disconnected or changed during \`${e}()\`.`,fix:"Call the method again after the new document connects. Read `synced` to know when it is ready."},REALTIME_INVALID_DOCUMENT:{why:({action:e})=>`The room body does not fit the editor schema, so \`${e}()\` did not write it. Writing it would lose content.`,fix:`Keep editing until the document fits the editor extensions of the Realtime Definition, then call the method again. The room keeps the edits.`},REALTIME_INVALID_RESPONSE:{why:({action:e})=>`The realtime server answered \`${e}()\` with a response that the client cannot use.`,fix:"Use the same `@vite-hub/realtime` version on the client and the server, and build again."},REALTIME_MISSING_DOCUMENT:{why:({action:e})=>`\`${e}()\` needs a document, and \`documentId\` is empty.`,fix:"Pass a document path to `useRealtimeTiptap(definition, documentId)` before you call the method."},REALTIME_READ_ONLY:{why:({action:e})=>`The room is read-only, so \`${e}()\` cannot write the document.`,fix:"Read `readOnlyReason` of `useRealtimeTiptap()` for the reason. Do not offer save or publish while it is set."},REALTIME_REQUEST_FAILED:{why:({action:e,message:t,status:n})=>`The realtime \`${e}()\` request failed${n===void 0?``:` with HTTP ${n}`}${t?`: ${t}`:`.`}`,fix:"Read `error.why` for the server message, `error.data.status` for the HTTP status, and `error.cause` for a network error. Retry when the server is available again.",data:({status:e})=>({status:e})},REALTIME_SOURCE_CHANGED:{why:({action:e})=>`The server refused \`${e}()\` because the stored document changed outside the room.`,fix:"Tell the person that the stored document changed. Use `onReset()` to detect a room reset and read unsaved edits from the event's `previous` document."},REALTIME_SYNC_PENDING:{why:({action:e})=>`The room did not receive every edit of this client in time, so \`${e}()\` did not run. The composable tried 20 times.`,fix:"Call the method again when `synced` is true. When it keeps failing, check that the WebSocket stays connected."},REALTIME_ROOM_ABORTED:{why:`The request to the room stopped because its signal aborted.`,fix:`Nothing to fix when the caller stopped on purpose, such as a cancelled Agent run. Call again to ask once more.`},REALTIME_ROOM_CROWDED:{why:({count:e})=>`${e} browsers are in the room, and a request goes to one browser only.`,fix:`Give each browser its own room, such as a random id for each tab, so that one browser answers.`},REALTIME_ROOM_ELSEWHERE:{why:`No browser in this instance is in the room. With Redis or Postgres, the browser can be connected to another instance, and requests reach only the browsers of the same instance.`,fix:`Route the browser and the caller to the same instance, such as with sticky sessions, or run one Node instance.`},REALTIME_ROOM_EMPTY:{why:`No browser is in the room. The page is closed, or it has not joined yet.`,fix:`Open the page again. The request waits a few seconds for a browser to join before it gives up.`},REALTIME_ROOM_REFUSED:{why:({reason:e})=>`The browser could not answer: ${e}`,fix:"Read the reason. Add `room.onRequest(handler)` on the page, and keep each answer under 1 MiB."},REALTIME_ROOM_REQUESTS_OFF:{why:({definition:e})=>`The Realtime Definition "${e}" does not take requests.`,fix:'Define it with `defineRealtime({ access: "public", document: false, requests: true })`.'},REALTIME_ROOM_TIMEOUT:{why:({timeout:e})=>`The browser did not answer in ${e/1e3} seconds.`,fix:"Make the page answer sooner, or pass a longer `timeout` to `requestRealtimeRoom()`."},REALTIME_AWARENESS_OWNERSHIP_CONFLICT:{why:`A realtime awareness client id belongs to another peer.`,fix:`Let each editor tab use its own Yjs awareness client. Do not reuse a client id on two connections.`},REALTIME_AWARENESS_TOO_LARGE:{why:`Realtime awareness state exceeds the 8 MiB room quota.`,fix:`Keep less data in awareness state. Store large values in the document or in Workspace.`},REALTIME_DOCUMENT_TOO_LARGE:{why:`The realtime document exceeds the 8 MiB room quota.`,fix:`Split the document into smaller documents, or keep large assets in Workspace or Blob.`},REALTIME_INVALID_AWARENESS:{why:`A realtime awareness update has a state that is not a plain object.`,fix:"Set awareness state to a plain object, for example `awareness.setLocalStateField('user', { name })`."},REALTIME_TOO_MANY_AWARENESS_CLIENTS:{why:`One realtime peer sent more than 1,024 awareness clients.`,fix:`Use one awareness client for each editor tab.`},REALTIME_ROOM_WRITE_CONFLICT:{why:`Realtime room record compare-and-set failed.`,fix:`Connect again. Another Realtime instance changed the room at the same time. If it keeps failing, check that every instance uses the same Realtime bus.`},REALTIME_WRITE_REJECTED:{why:({problem:e,readOnly:t})=>e===`missing-state`?`Realtime update depends on state this room does not have.`:e===`status`?`Realtime document status is written by the server.`:t??`This realtime connection is read-only.`,fix:"Write only through a writable connection, and do not change the `status` map, which the server writes. A client that misses room state connects again to sync it."},REALTIME_DOCUMENT_CONFLICT:{why:({problem:e})=>e??`The stored document changed since the realtime room loaded it.`,fix:"Realtime re-seeds the room from the stored document. Listen to `onReset()` to recover text that the room did not save."},REALTIME_BLOB_ETAG_MISSING:{why:({pathname:e})=>`The Blob store returned no \`httpEtag\` for ${e}, so \`blobDocument()\` cannot save the file only if it is unchanged.`,fix:"Pass a ViteHub Blob store, such as `blob` from `vite-hub/blob`, whose `head()` returns `httpEtag` on every driver. A store of your own must return `httpEtag` from `head()` and accept `ifMatch` in `put()`."},REALTIME_INVALID_PERSISTENCE:{why:({name:e,reason:t})=>t===`below-debounce`?"Realtime `persistence.maxWait` must be at least `persistence.debounce`.":`Realtime \`persistence.${e}\` must be a non-negative number of milliseconds.`,fix:"Set `persistence: { debounce: 2_000, maxWait: 10_000 }`, or remove the option to use these defaults."},REALTIME_MISSING_ACCESS:{why:`The Realtime definition sets no access rule, so it does not say who can read and write its rooms.`,fix:'Set `authorize: true` to require a signed-in user, set `authorize()` to decide each request, or set `access: "public"` to let anyone read and write.'},REALTIME_INVALID_ACCESS:{why:({reason:e})=>e===`auth`?"The Realtime definition sets `auth`. Realtime replaced it with `authorize: true`, and an `authorize()` callback now also runs for signed-out callers.":e===`public-with-rule`?'The Realtime definition sets `access: "public"` together with `authorize`, so its access rule is not clear.':e===`not-public`?'The Realtime definition sets `access` to a value other than "public".':e===`not-authorize`?"The Realtime definition sets `authorize` to a value that is not `true` or a function.":"The Realtime definition sets `origins()` with `authorize: true` and no `identify()`. Only the Auth trusted-origin policy can allow a different origin to use the ViteHub Auth session.",fix:({reason:e})=>e===`auth`?"Replace `auth: true` with `authorize: true`. With an `authorize()` callback, remove `auth` and return `false` from the callback when `user` is `null`.":e===`origins-without-identify`?"Remove `origins()`, or add `identify()` that reads a credential the page sends on purpose, such as a ticket in `params`.":e===`not-authorize`?"Set `authorize: true` to require a signed-in user, or set `authorize()` to a function that returns `true` to allow.":'Use `access: "public"` alone for open rooms. To limit access, remove `access` and set `authorize`.'},REALTIME_CHECKPOINT_UNSUPPORTED:{why:"The Realtime definition sets `history.checkpoint`, but its document adapter has no `checkpoint()` method, so `history.checkpoint()` could never run.",fix:"Add `checkpoint(context, { digest, message, user })` to the document adapter, use `document: { workspace }`, or remove `history`."},REALTIME_INVALID_USER:{why:"The realtime identity needs a user `id` that is a non-empty string of at most 256 characters.",fix:"Return a user with an `id` from the Auth session or from `authorize()`."},REALTIME_MISSING_DIGEST:{why:({operation:e})=>e===`save`?`Realtime saves need Workspace file digests, and the Workspace Store did not return one.`:`Realtime checkpoints need a stored document, and the save returned no digest.`,fix:"Use a Workspace Store that returns file digests, or return `digest` from the document adapter `save()`."},REALTIME_INVALID_POSTGRES_URL:{why:"REALTIME_POSTGRES_URL is set, and it is not a `postgres://` or `postgresql://` URL.",fix:`Set REALTIME_POSTGRES_URL to a Postgres URL, or remove it so that Realtime uses the connection of the Default Database.`},REALTIME_MISSING_BUS_CONNECTION:{why:({driver:e})=>e===`redis`?`Realtime driver "redis" shares rooms through Redis, and REDIS_URL and a Redis KV_URL are not set.`:`Realtime driver "postgres" needs REALTIME_POSTGRES_URL or a Default Database that uses postgres.js.`,fix:'Set REDIS_URL for Redis. For Postgres, set REALTIME_POSTGRES_URL or use a Default Database with `dialect: "postgresql"` and no `driver` override. A Default Database with `driver: "node-postgres"` needs a separate REALTIME_POSTGRES_URL for the Postgres bus.'},REALTIME_MISSING_SHARED_BUS:{why:`This host runs each request in one of many function instances. Realtime must use Redis or Postgres to share rooms, but it found no bus connection.`,fix:'Set REDIS_URL, a Redis KV_URL, or REALTIME_POSTGRES_URL. Realtime can also use the Default Database with `dialect: "postgresql"` and no `driver` override.'},REALTIME_ROOM_LOCK_TIMEOUT:{why:`Realtime waited 30 seconds for the save lock of a room, and another instance still holds it.`,fix:"Make the document adapter `save()` finish in less than 30 seconds. Realtime tries the save again."},REALTIME_DRIVER_CONFLICT:{why:({driver:e,host:t})=>e===`memory`?`Realtime driver "memory" is single-process only, and the ${t} host runs more than one process.`:e===`cloudflare`?`Realtime driver "cloudflare" does not work with the ${t} host.`:`Realtime driver "${e}" needs a Node.js server, and the ${t} host does not run one.`,fix:'Set `realtime.driver` to "cloudflare" with a Cloudflare host. With the Node host, use "auto", "postgres", "redis", or "memory". With the Vercel host, use "auto", "postgres", or "redis".'},REALTIME_MISSING_DRIVER:{why:`Realtime production builds need one room driver, and ViteHub cannot select one for this deployment.`,fix:`Deploy with a Cloudflare host to use Durable Objects, or with the Node or Vercel host to share rooms through Postgres or Redis.`},REALTIME_RENAMED_AUTHORITY_KEY:{why:({value:e})=>`\`realtime.authority\` is ${e}. ViteHub renamed this key to \`driver\`, and it does not read \`authority\`, so Realtime would not use the driver you chose.`,fix:({value:e})=>`Set \`realtime: { driver: ${e} }\`.`}}}),g=Math.floor,he=Math.abs,ge=(e,t)=>e<t?e:t,_e=(e,t)=>e>t?e:t;Number.isNaN;var ve=Math.pow,ye=e=>e===0?1/e<0:e<0,be=2**53-1,xe=-(2**53-1),Se=Number.isInteger||(e=>typeof e==`number`&&isFinite(e)&&g(e)===e);Number.isNaN,Number.parseInt;var Ce=()=>new Set,we=e=>e[e.length-1],Te=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},_=Array.from,Ee=(e,t)=>{for(let n=0;n<e.length;n++)if(!t(e[n],n,e))return!1;return!0},De=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1},Oe=(e,t)=>{let n=Array(e);for(let r=0;r<e;r++)n[r]=t(r,n);return n},ke=Array.isArray,Ae=String.fromCharCode;String.fromCodePoint,Ae(65535);var je=e=>e.toLowerCase(),Me=/^\s*/g,Ne=e=>e.replace(Me,``),Pe=/([A-Z])/g,Fe=(e,t)=>Ne(e.replace(Pe,e=>`${t}${je(e)}`)),Ie=e=>{let t=unescape(encodeURIComponent(e)),n=t.length,r=new Uint8Array(n);for(let e=0;e<n;e++)r[e]=t.codePointAt(e);return r},Le=typeof TextEncoder<`u`?new TextEncoder:null,Re=Le?e=>Le.encode(e):Ie,ze=typeof TextDecoder>`u`?null:new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0});ze&&ze.decode(new Uint8Array).length===1&&(ze=null);var Be=(e,t)=>Oe(t,()=>e).join(``),v=e=>Error(e),y=()=>{throw v(`Method unimplemented`)},b=()=>{throw v(`Unexpected case`)},Ve=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},x=()=>new Ve,He=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t},S=e=>{let t=new Uint8Array(He(e)),n=0;for(let r=0;r<e.bufs.length;r++){let i=e.bufs[r];t.set(i,n),n+=i.length}return t.set(new Uint8Array(e.cbuf.buffer,0,e.cpos),n),t},Ue=(e,t)=>{let n=e.cbuf.length;n-e.cpos<t&&(e.bufs.push(new Uint8Array(e.cbuf.buffer,0,e.cpos)),e.cbuf=new Uint8Array(_e(n,t)*2),e.cpos=0)},C=(e,t)=>{let n=e.cbuf.length;e.cpos===n&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(n*2),e.cpos=0),e.cbuf[e.cpos++]=t},We=C,w=(e,t)=>{for(;t>127;)C(e,128|127&t),t=g(t/128);C(e,127&t)},Ge=(e,t)=>{let n=ye(t);for(n&&(t=-t),C(e,(t>63?128:0)|(n?64:0)|63&t),t=g(t/64);t>0;)C(e,(t>127?128:0)|127&t),t=g(t/128)},Ke=new Uint8Array(3e4),qe=Ke.length/3,T=Le&&Le.encodeInto?(e,t)=>{if(t.length<qe){let n=Le.encodeInto(t,Ke).written||0;w(e,n);for(let t=0;t<n;t++)C(e,Ke[t])}else E(e,Re(t))}:(e,t)=>{let n=unescape(encodeURIComponent(t)),r=n.length;w(e,r);for(let t=0;t<r;t++)C(e,n.codePointAt(t))},Je=(e,t)=>{let n=e.cbuf.length,r=e.cpos,i=ge(n-r,t.length),a=t.length-i;e.cbuf.set(t.subarray(0,i),r),e.cpos+=i,a>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(_e(n*2,a)),e.cbuf.set(t.subarray(i)),e.cpos=a)},E=(e,t)=>{w(e,t.byteLength),Je(e,t)},Ye=(e,t)=>{Ue(e,t);let n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},Xe=(e,t)=>Ye(e,4).setFloat32(0,t,!1),Ze=(e,t)=>Ye(e,8).setFloat64(0,t,!1),Qe=(e,t)=>Ye(e,8).setBigInt64(0,t,!1),$e=new DataView(new ArrayBuffer(4)),et=e=>($e.setFloat32(0,e),$e.getFloat32(0)===e),tt=(e,t)=>{switch(typeof t){case`string`:C(e,119),T(e,t);break;case`number`:Se(t)&&he(t)<=2147483647?(C(e,125),Ge(e,t)):et(t)?(C(e,124),Xe(e,t)):(C(e,123),Ze(e,t));break;case`bigint`:C(e,122),Qe(e,t);break;case`object`:if(t===null)C(e,126);else if(ke(t)){C(e,117),w(e,t.length);for(let n=0;n<t.length;n++)tt(e,t[n])}else if(t instanceof Uint8Array)C(e,116),E(e,t);else{C(e,118);let n=Object.keys(t);w(e,n.length);for(let r=0;r<n.length;r++){let i=n[r];T(e,i),tt(e,t[i])}}break;case`boolean`:C(e,t?120:121);break;default:C(e,127)}},nt=class extends Ve{constructor(e){super(),this.w=e,this.s=null,this.count=0}write(e){this.s===e?this.count++:(this.count>0&&w(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}},rt=e=>{e.count>0&&(Ge(e.encoder,e.count===1?e.s:-e.s),e.count>1&&w(e.encoder,e.count-2))},it=class{constructor(){this.encoder=new Ve,this.s=0,this.count=0}write(e){this.s===e?this.count++:(rt(this),this.count=1,this.s=e)}toUint8Array(){return rt(this),S(this.encoder)}},at=e=>{if(e.count>0){let t=e.diff*2+(e.count===1?0:1);Ge(e.encoder,t),e.count>1&&w(e.encoder,e.count-2)}},ot=class{constructor(){this.encoder=new Ve,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(at(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return at(this),S(this.encoder)}},st=class{constructor(){this.sarr=[],this.s=``,this.lensE=new it}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=``),this.lensE.write(e.length)}toUint8Array(){let e=new Ve;return this.sarr.push(this.s),this.s=``,T(e,this.sarr.join(``)),Je(e,this.lensE.toUint8Array()),S(e)}},ct=v(`Unexpected end of array`),lt=v(`Integer out of Range`),ut=(e,t,n)=>{if(t<0||n<0||t+n>e.length)throw ct;return new Uint8Array(e.buffer,e.byteOffset+t,n)},dt=(e,t,n)=>{if(t<0||n<0||t+n>e.length)throw ct;return new DataView(e.buffer,e.byteOffset+t,n)},ft=class{constructor(e){this.arr=e,this.pos=0}},D=e=>new ft(e),pt=e=>e.pos!==e.arr.length,mt=(e,t)=>{let n=ut(e.arr,e.pos,t);return e.pos+=t,n},O=e=>mt(e,k(e)),ht=e=>e.arr[e.pos++],k=e=>{let t=0,n=1,r=e.arr.length;for(;e.pos<r;){let r=e.arr[e.pos++];if(t+=(r&127)*n,n*=128,r<128)return t;if(t>be)throw lt}throw ct},gt=e=>{let t=e.arr[e.pos++],n=t&63,r=64,i=(t&64)>0?-1:1;if(!(t&128))return i*n;let a=e.arr.length;for(;e.pos<a;){if(t=e.arr[e.pos++],n+=(t&127)*r,r*=128,t<128)return i*n;if(n>be)throw lt}throw ct},A=ze?e=>ze.decode(O(e)):e=>{let t=k(e);if(t===0)return``;{let n=String.fromCodePoint(ht(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(ht(e));else for(;t>0;){let r=t<1e4?t:1e4,i=e.arr.subarray(e.pos,e.pos+r);e.pos+=r,n+=String.fromCodePoint.apply(null,i),t-=r}return decodeURIComponent(escape(n))}},_t=(e,t)=>{let n=dt(e.arr,e.pos,t);return e.pos+=t,n},vt=[e=>void 0,e=>null,gt,e=>_t(e,4).getFloat32(0,!1),e=>_t(e,8).getFloat64(0,!1),e=>_t(e,8).getBigInt64(0,!1),e=>!1,e=>!0,A,e=>{let t=k(e),n={};for(let r=0;r<t;r++){let t=A(e);n[t]=yt(e)}return n},e=>{let t=k(e),n=[];for(let r=0;r<t;r++)n.push(yt(e));return n},O],yt=e=>vt[127-ht(e)](e),bt=class extends ft{constructor(e,t){super(e),this.reader=t,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),this.count=pt(this)?k(this)+1:-1),this.count--,this.s}},xt=class extends ft{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=gt(this);let e=ye(this.s);this.count=1,e&&(this.s=-this.s,this.count=k(this)+2)}return this.count--,this.s}},St=class extends ft{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){let e=gt(this),t=e&1;this.diff=g(e/2),this.count=1,t&&(this.count=k(this)+2)}return this.s+=this.diff,this.count--,this.s}},Ct=class{constructor(e){this.decoder=new xt(e),this.str=A(this.decoder),this.spos=0}read(){let e=this.spos+this.decoder.read(),t=this.str.slice(this.spos,e);return this.spos=e,t}},wt={why:({message:e})=>e===void 0?``:String(e)},j=e=>({...wt,fix:e}),Tt=a({docsBase:`https://vitehub.dev/docs/workspace/diagnostics`,codes:{WORKSPACE_CONFLICT:{...wt,fix:({conditionalRemovalUnsupported:e})=>e?"Use a Store that supports conditional removal to keep the `ifDigest` check. Remove a file without `ifDigest` only if you intend to delete it even if it changed since you read it.":"Another write changed the file or ref after you read it. Read it again, apply your change to the new content, and retry with its new digest in `ifDigest` or its new head in `ifHead`. For a merge conflict or a publish that is in progress, do the step that the message names first."},WORKSPACE_FORBIDDEN:{why:`An Agent may not write past an edit lease that a person holds.`,fix:`Tell the person you work for who is editing the files, and try again after they finish. A developer allows overrides with operations({ overrideLeases: true }).`},WORKSPACE_HISTORY_FAILED:{why:({workspace:e})=>`The history operation of Workspace "${e}" failed.`,fix:"Read `error.cause` for the Store error. Check that the Store of the Workspace is reachable, then retry."},WORKSPACE_HISTORY_INVALID:{why:({problem:e})=>e===`empty-commit`?"The commit has no changes. Pass `put` or `delete`.":`The cursor belongs to one ref. Pass the same ref.`,fix:"Pass `put` or `delete` to `workspace.commit`, and pass a `cursor` only with the `ref` of the `workspace.history` call that returned it."},WORKSPACE_NOT_FOUND:{why:({id:e,path:t,problem:n,workspace:r})=>({path:`Revision ${e} has no path "${t}".`,revision:`The Workspace has no revision "${e}". Pull again without a base revision.`,target:`Workspace "${r}" has no ref or revision "${e}". Run \`vitehub workspace refs ${r}\` to list refs.`,workspace:`Unknown Workspace: ${r}.`})[n],fix:"Check the Workspace name, the ref or revision, and the path. `vitehub workspace refs <workspace>` lists the refs, and `vitehub workspace get <workspace> <ref>` lists the files. When a base revision is gone, pull again without it."},WORKSPACE_PATH_INVALID:{why:({path:e,problem:t})=>t===`reserved`?`The Workspace path ${e} uses a reserved name. ViteHub keeps \`.git\` at any depth for Git and \`.vitehub\` at the root for its own data. It also reserves their NTFS short names \`git~N\` and \`vitehu~N\`.`:`The Workspace path ${e} is not a relative path inside the Workspace root. It is empty or absolute, starts with a drive letter, has a NUL byte, or has a \`.\` or \`..\` part.`,fix:({problem:e})=>e===`reserved`?"Rename the file or folder, for example `.git/config` to `git/config`. No part of a Workspace path can be `.git` or `git~1`, and the first part cannot be `.vitehub` or `vitehu~1`.":"Pass a relative path inside the Workspace, for example `docs/guide.md`. Remove a leading `/` or drive letter, NUL bytes, and `.` or `..` parts. `error.details.path` has the path that the Workspace rejected."},WORKSPACE_SOURCE_READ_ONLY:{why:({path:e,source:t})=>t===void 0?`The Workspace path "${e}" belongs to a Source. Source paths are read-only: a write, removal, or move cannot change them.`:`The Workspace path "${e}" belongs to Source "${t}". Source paths are read-only: a write, removal, or move cannot change them.`,fix:"Write the file outside the Source mount, for example under `drafts/`. To change a Source file, change it where the Source reads it, such as its GitHub repository, its URL, or its local files. For a Source with `sync: true`, run `workspace.sync({ sources: ['handbook'] })` with its Source key in place of `handbook`."},WORKSPACE_CHECKOUT_CONFLICT:{why:({conflicted:e,workspace:t})=>`Workspace "${t}" has unresolved conflicts: ${e}.`,fix:"Edit each file and remove the conflict markers, or run `vitehub resolve` for a binary file. Then push again."},WORKSPACE_CHECKOUT_DIR:{why:({dir:e,workspace:t})=>e===void 0?`Workspace "${t}" is not checked out yet.`:`The checkout folder "${e}" must be a folder inside the project, not the project root.`,fix:"Pass `--dir` with a folder inside the project, such as `vitehub pull <workspace> --dir content`."},WORKSPACE_CHECKOUT_FAILED:{why:({message:e})=>e,fix:"Read the message. Run `vitehub status` to see the state of the checkout, then run the command again."},WORKSPACE_CHECKOUT_MISSING:{why:({workspace:e})=>e===void 0?`vitehub.lock has no checked-out Workspace.`:`Workspace "${e}" is not checked out.`,fix:"Run `vitehub pull <workspace> --dir <folder>` first."},WORKSPACE_CHECKOUT_OPTIONS:{why:({actual:e,expected:t,key:n,workspace:r})=>r===void 0?`This checkout uses ${t}, not "${e}".`:`Workspace "${r}" is checked out with ${n} "${t}", not "${e}".`,fix:"Edit `vitehub.lock` to change the `dir` or `ref` of the entry. To change the remote, remove the entry from `vitehub.lock` and pull into a new folder."},WORKSPACE_CHECKOUT_OVERLAP:{why:({dir:e,other:t,otherDir:n,workspace:r})=>`Workspace "${r}" folder "${e}" overlaps Workspace "${t}" folder "${n}".`,fix:`Use separate checkout folders that do not contain one another.`},WORKSPACE_CHECKOUT_PATH:{why:({other:e,path:t,problem:n})=>({excluded:`The path "${t}" is excluded from the checkout.`,"not-portable":`The path "${t}" has a component that is not portable between file systems.`,"not-relative":`The remote path "${t}" is not a relative Workspace path.`,reserved:`The top-level file name "${t}" is reserved by the operation input map.`,spelling:`The checkout paths "${e}" and "${t}" use different spellings for one file-system path, or replace a file with a directory.`})[n],fix:"Rename the path to a portable name that the checkout does not exclude, before you pull or push it. For two spellings of one path, rename one. For a file that a folder replaces, keep local edits elsewhere, remove the `vitehub.lock` entry, and pull into a new empty folder."},WORKSPACE_CHECKOUT_SYMLINK:{why:({path:e})=>e===`vitehub.lock`?`vitehub.lock is a symbolic link. A checkout reads and writes only a real lock file.`:`${e} is a symbolic link. A checkout reads and writes only real files and folders.`,fix:`Replace the symbolic link with a real folder or file, then try again.`},WORKSPACE_CHECKOUT_TOO_LARGE:{why:({largest:e,limit:t,size:n,workspace:r})=>`The push of Workspace "${r}" is ${n}, over the ${t} limit of one push.${e?` Largest files: ${e}.`:``}`,fix:`A push is one revision and sends each changed file whole, with binary files in base64. Keep large media in Blob, or add new files in smaller groups with a push after each group.`},WORKSPACE_CHECKOUT_USAGE:{why:({command:e,flag:t,problem:n})=>({flag:`Unknown flag --${t}.`,names:`${e} accepts at most one Workspace name.`,value:`--${t} needs a value.`})[n],fix:"Pass only the flags of the command, each with its value, and at most one Workspace name, for example `vitehub pull docs --dir content`."},WORKSPACE_LOCK_BUSY:{why:`Another vitehub command is writing vitehub.lock: vitehub.lock.lock exists.`,fix:"Wait for that command to finish and try again. If no vitehub command runs, delete `vitehub.lock.lock`."},WORKSPACE_LOCK_INVALID:{why:({problem:e})=>e===`json`?`vitehub.lock is not valid JSON.`:"vitehub.lock has no `version: 1` and `workspaces` object.",fix:"Fix the conflict in `vitehub.lock`, or delete the entry and pull again."},WORKSPACE_RENAMED_STORE_PROVIDER_KEY:{why:({provider:e})=>`The Workspace \`store\` sets \`provider: ${e}\`. ViteHub renamed this key to \`driver\`, and it does not read \`provider\`, so the Store would not be the one you chose.`,fix:({driver:e})=>`Set \`store: { driver: ${e} }\`.`},WORKSPACE_RENAMED_STORE_REPOSITORY_KEY:{why:()=>"The GitHub Workspace `store` sets `repository`. ViteHub renamed this key to `repo`, and it does not read `repository`, so the Store would use `VITEHUB_WORKSPACE_GITHUB_REPOSITORY` or no repository.",fix:()=>'Rename `repository` to `repo` in `store: { driver: "github" }`.'},WORKSPACE_UNKNOWN_STORE_DRIVER:{why:({driver:e,renamed:t})=>t?`The Workspace \`store.driver\` is ${e}. ViteHub renamed this driver to "${t}", and it does not read ${e}.`:`The Workspace \`store.driver\` ${e} is not a Workspace Store driver.`,fix:({renamed:e})=>e?`Set \`store: { driver: "${e}" }\`.`:'Set `store.driver` to "local", "memory", "github", "cloudflare", or "vercel", or pass a Store object.'},WORKSPACE_DEFAULT_REF_DELETE:{why:"`history.deleteRef()` cannot delete `main` or the ref that the Workspace working tree follows.",fix:"Delete another ref, such as the ref of one run. To remove files from the working ref, commit without them. To remove the whole Workspace history, call `delete()` on the Blob + Database Store."},WORKSPACE_POSTGRES_HISTORY_SCHEMA_MISSING:{why:`The Postgres Database for this Workspace is missing its history catalog table.`,fix:"Apply the migrations for `workspaceHistorySchema` from `vite-hub/workspace/blob-database/postgres`. For a ViteHub Database, add the schema to its Definition and run `vitehub database generate` and `vitehub database migrate`. With PGlite, stop the dev server before running `vitehub database migrate` and start it again afterward, because only one process can open the local PGlite folder at a time."},WORKSPACE_REGISTRY_LOAD_FAILED:{why:({reason:e,workspace:t})=>`The module of Workspace "${t}" did not load: ${e}`,fix:"Read `error.cause` for the first error. Make sure that the module of the Workspace loads without errors and exports its Definition: the default export of a file in `server/workspaces/`, or the export that the Vite plugin names in its Workspace contribution. Then restart the dev server or build again."},WORKSPACE_STORE_IN_WORKER_MEMORY:{why:`At least one Workspace in this Cloudflare build uses the default Memory Store. It keeps the files that the app writes in the memory of the Worker isolate. The files are lost when the isolate stops, and other isolates do not see them. Sources still read from the bundle.`,fix:'Set `workspace: { store: { driver: "cloudflare" } }` in `vitehub()` to keep the files in Cloudflare Artifacts, or use `{ driver: "github" }`. To keep the memory Store on purpose, set `store: { driver: "memory" }`, and the build does not print this notice.'},WORKSPACE_SOURCE_ACCESS_FAILED:{why:({source:e,workspace:t})=>`Source "${e}" of Workspace "${t}" cannot reach its data with the credentials of the build. The deployed app would fail on its first read.`,fix:"Read `error.cause` for the response of the provider. For a GitHub Source, check that `repo` and `ref` exist and that the token of the build (`auth`, `VITEHUB_GITHUB_TOKEN`, or `gh auth token`) can read the repository. Then build again."},WORKSPACE_R0069:j("Use a Store with retained history: `createBlobDatabaseWorkspaceStore()` or the `github` Store. Open the Workspace with a scope that grants the complete Workspace, not selected paths."),WORKSPACE_R0070:j("Pass a `limit` from 1 to 100, and pass a `cursor` only with the `ref` of the `history.list()` call that returned it."),WORKSPACE_R0071:j("Use a ref name with up to 128 letters, numbers, `_`, and `-`, joined by single `.` or `/`, for example `draft` or `team/review`. In a GitHub Store with `refs`, use `published` or `draft`, not the branch name."),WORKSPACE_R0072:j("Set the `repo` option of the GitHub Store or `VITEHUB_WORKSPACE_GITHUB_REPOSITORY`, for example `owner/repo`. Set the `token` option or `VITEHUB_GITHUB_TOKEN`."),WORKSPACE_R0073:j("Make the commit message or metadata shorter, as the message says. Remove each `Vitehub-Metadata:` line from the message, and pass the values in the `metadata` option."),WORKSPACE_R0001:j("Pass the path of a file or folder in the Workspace, for example `docs/guide.md`. The Workspace root itself cannot be written, moved, or deleted."),WORKSPACE_R0002:j("Enable at least one operation in `createWorkspaceTools(workspace, { operations })`, for example `{ operations: { read: true } }`."),WORKSPACE_R0003:j('Get write tools from `useWorkspace(name, { mode: "write" }).tools.write()`. Do not pass the result of `useWorkspace()` to `createWorkspaceTools()`. Or remove `write` from `operations`.'),WORKSPACE_B0001:j("Export the Workspace Definition from the file, for example `export default defineWorkspace({ ... })`. For a contributed Workspace, set `definition.export` to the name of the export."),WORKSPACE_B0002:j("Use `defineWorkspace()` in `server/workspaces/<name>.ts`. Move the `defineAgent()` call to `server/agents/<name>/agent.ts`."),WORKSPACE_B0003:j(`Rename or remove one of the definitions that the message lists. Each Workspace name has one definition.`),WORKSPACE_B0004:j("Set `vitehub.workspaces` in the plugin to an array of `{ name, definition: { module, export? }, reason? }` entries, or to a function that returns one. Set `module` to an absolute path, a `file:` URL, or a package specifier."),WORKSPACE_B0005:j('Set the Cloudflare Artifacts Store in the `workspace` config, for example `vitehub({ workspace: { store: { driver: "cloudflare", binding: "WORKSPACE_ARTIFACTS", namespace: "vitehub" } } })`, and remove `store` from the Workspace Definition. Or remove the import that the build cannot load from the Definition file, so that the build can read its `store`.'),WORKSPACE_R0004:j("Put a value after the option, for example `--timeout 30000` or `--url http://localhost:5173`."),WORKSPACE_R0005:j("Pass a whole number of milliseconds from 1 to 2147483647, for example `--timeout 30000`."),WORKSPACE_R0006:j("Pass a whole number of milliseconds from 1 to 2147483647, for example `--timeout 30000`."),WORKSPACE_R0007:j("Remove the option. `vitehub workspace dev --help` lists the options."),WORKSPACE_R0008:j("Put a command after `exec`, for example `vitehub workspace dev docs exec ls`."),WORKSPACE_R0009:j("Put `exec` before the command, for example `vitehub workspace dev docs exec ls -la`. Or omit the command to open the interactive command loop."),WORKSPACE_C0001:j('Set `workspace` to an object, for example `workspace: { store: { driver: "memory" } }`, or to `false`.'),WORKSPACE_C0002:j("Remove the option. The `workspace` config accepts `assets`, `projectRoot`, `root`, and `store`."),WORKSPACE_R0015:j("Remove the option. `defineWorkspace()` accepts `bindings`, `commit`, `hooks`, `loaders`, `plugins`, `rootDir`, `rules`, `sourceRootDir`, `sources`, and `store`."),WORKSPACE_R0016:j("Pass an object to `defineWorkspace()`, for example `defineWorkspace({ sources: {} })`."),WORKSPACE_R0017:j("Remove `name` from the Workspace Definition. The file name sets the Workspace name, for example `server/workspaces/docs.ts` defines `docs`."),WORKSPACE_R0018:j("Use fewer and shorter glob patterns with fewer `{a,b}` and `*` parts, for example `docs/**/*.md` in place of a list of patterns."),WORKSPACE_R0019:j("Use fewer and shorter glob patterns with fewer `{a,b}` and `*` parts, for example `docs/**/*.md` in place of a list of patterns."),WORKSPACE_R0020:j("Use fewer and shorter glob patterns with fewer `{a,b}` and `*` parts, for example `docs/**/*.md` in place of a list of patterns."),WORKSPACE_R0021:j("Remove `name` from the Workspace Definition. The file name sets the Workspace name, for example `server/workspaces/docs.ts` defines `docs`."),WORKSPACE_R0022:j('Pass the Workspace name as a non-empty string, for example `registerWorkspace("docs", definition)` or `registerWorkspacePlugin("docs", plugin)`.'),WORKSPACE_R0023:j('Set `maxBytes` to a number of bytes or to a string such as `"512kb"` or `"10mb"`.'),WORKSPACE_R0024:j('Give each Workspace plugin a non-empty string `id`, for example `{ id: "my-plugin", rules }`.'),WORKSPACE_R0025:j("Declare the target as a `url()` Source in the Workspace Definition, and make the Source visible in the Workspace scope."),WORKSPACE_R0026:j("Use a Store that supports rebase: `github` or `cloudflare`. Or do not call `rebase()` on this Workspace."),WORKSPACE_R0027:j("Set another `binding` in the Workspace `store` options, or set `namespace` to the namespace that Wrangler config already has for that binding."),WORKSPACE_R0028:j(`The client closed the Workspace Dev connection before the command finished. Run the command again and keep the connection open.`),WORKSPACE_R0029:j("Give each Cloudflare Artifacts namespace its own `binding` in the Workspace `store` options."),WORKSPACE_R0033:j(`Run the operation again. If it fails again, check the Blob store of the project in the Vercel dashboard.`),WORKSPACE_R0034:j('Pass the Workspace name, for example `createWorkspacePreparation({ workspace: "docs" })`.'),WORKSPACE_R0035:j('Pass Source keys of the Workspace as non-empty strings, for example `sources: ["handbook"]`, or omit `sources`.'),WORKSPACE_R0036:j("Set `retryDelayMs` to a number of milliseconds from 0 to 2147483647, or omit it to use 10000."),WORKSPACE_R0037:j('Set `materialize: "startup"` on the Sources to prepare, or pass their keys in `sources`.'),WORKSPACE_R0038:j("Check each Source that the message names: its URL, repository, or files, and its credentials. Without `requireNonEmpty`, an empty Source is ready."),WORKSPACE_R0039:j("`stop()` cancelled this preparation. Call `start()` again to prepare the Workspace."),WORKSPACE_R0040:j("Pass a non-empty command, for example `vitehub workspace dev docs exec ls`."),WORKSPACE_R0041:j('Pass a Workspace name, or a Workspace from `useWorkspace(name, { mode: "write" })`, that can start a Workspace Session.'),WORKSPACE_R0042:j(`This is a ViteHub bug. Report it at https://github.com/vite-hub/vitehub/issues with the message and your Workspace Definition.`),WORKSPACE_R0043:j(`This is a ViteHub bug. Report it at https://github.com/vite-hub/vitehub/issues with the message and your Workspace Definition.`),WORKSPACE_R0044:j("Make sure that the Workspace Session host can run `readlink` and can read the path in the message."),WORKSPACE_R0045:j("Set `executionAuthority` on the Workspace Session host. Use `unknownExecutionAuthority` from `@vite-hub/runtime` when the host cannot describe it."),WORKSPACE_C0003:j("Rename the Source key to one file name without `/` and without a `.json` ending, for example `issues`. ViteHub keeps the request descriptor at `.vitehub/sources/<key>.json`."),WORKSPACE_C0004:j('Set `mount` on the Source to a folder, for example `mount: "docs"`, or set `probeKeys`. A Workspace Scope grant needs paths, and a Source at the root has none.'),WORKSPACE_C0005:j('Use a Source helper so that the Source kind is explicit, for example `github({ repo: "owner/name" })`, `url({ url, workspacePath: "issues.json" })`, or `file({ path: "README.md" })`. A `{ source: { ... } }` wrapper does not help, because ViteHub reads the options in it the same way.'),WORKSPACE_C0006:j('Pass `path` or `workspacePath` to `file()`, for example `file({ path: "README.md" })`.'),WORKSPACE_C0007:j('When the URL has a query, set `path` on the Source config, for example `{ url, path: "issues.json" }`. Or use the `url()` helper with `workspacePath: "issues.json"`.'),WORKSPACE_R0046:j("Set `workspacePath` on the `url()` Source to read the response as a file. A request-only Source answers only `curl` Source requests."),WORKSPACE_R0047:j("Read the `url()` Source at its `workspacePath`. The Source has no other file."),WORKSPACE_R0048:j(`Read this Source in an Agent Invocation. The Agent runs the resolver with the Invocation context before it reads the Source. Outside an Invocation, the Source has no files.`),WORKSPACE_R0049:j('Set `responseType` to `"json"` or `"text"`.'),WORKSPACE_R0050:j('Set `method` to `"GET"`, `"HEAD"`, or `"POST"`.'),WORKSPACE_R0051:j("Use `query` for a fixed query or `querySchema` for a query that the Agent sets. Remove the other one, and remove the query from `url` when you use `querySchema`."),WORKSPACE_R0052:j("Use `body` for a fixed body or `bodySchema` for a body that the Agent sets. Remove the other one."),WORKSPACE_R0053:j('Set `method: "POST"` to send a body, or remove `body` and `bodySchema`.'),WORKSPACE_R0054:j("Pass a schema that has `~standard.jsonSchema.input()`, the Standard JSON Schema interface. Or use a fixed `query` or `body`."),WORKSPACE_R0055:j("Send the request with the method, URL, query, and body that the Source declares. Read `.vitehub/sources/<source>.json` in the Workspace to get them."),WORKSPACE_R0056:j("Send the request with the method, URL, query, and body that the Source declares. Read `.vitehub/sources/<source>.json` in the Workspace to get them."),WORKSPACE_R0057:j("Send the request with the method, URL, query, and body that the Source declares. Read `.vitehub/sources/<source>.json` in the Workspace to get them."),WORKSPACE_R0058:j("Send the request with the method, URL, query, and body that the Source declares. Read `.vitehub/sources/<source>.json` in the Workspace to get them."),WORKSPACE_R0059:j("Send the request with the method, URL, query, and body that the Source declares. Read `.vitehub/sources/<source>.json` in the Workspace to get them."),WORKSPACE_R0060:j(`Read this Source in an Agent Invocation. The Agent runs the resolver with the Invocation context before it reads the Source. Outside an Invocation, the Source has no files.`),WORKSPACE_R0061:j('Return `repo` from the `github()` resolver, for example `{ repo: "owner/name" }`, or start the Agent Invocation with a `pullRequest` context value.'),WORKSPACE_R0063:j("Use the URL of exactly one Source that the Workspace scope can see. Read `.vitehub/sources/<source>.json` in the Workspace and send the URL, method, query, and body that it declares."),WORKSPACE_R0064:j(`This is a ViteHub bug. Report it at https://github.com/vite-hub/vitehub/issues with the message and your Workspace Definition.`),WORKSPACE_R0065:j("The Cloudflare Artifacts Store keeps its Git checkout in memory. A Git step used the path in the message in a way that the error code rejects, for example `ENOENT` for a missing file. Run the operation again. If it fails again, report it at https://github.com/vite-hub/vitehub/issues with the message."),WORKSPACE_R0066:j("Connect a Blob store to the Vercel project so that it gets `BLOB_STORE_ID`. Off Vercel, set `BLOB_READ_WRITE_TOKEN`."),WORKSPACE_R0074:j(`The Workspace Store keeps no file revisions, so ViteHub cannot prove that the file at the path in the message is the one it started to remove. Check the file. If it must go, delete it in the Store itself, for example in its directory or bucket, because the Workspace rejects writes under a Source. Then run the Source operation again.`),WORKSPACE_R0075:j("Remove `read` from the rule. Workspace rules limit writes only, so `read: false` would not hide the files. Keep files that a reader must not see out of the Workspace, for example in another Workspace or in an Env secret."),WORKSPACE_R0076:j("Remove the option from the rule. A Workspace rule accepts `commit`, `maxBytes`, `mediaType`, `validate`, and `write`."),WORKSPACE_R0077:j('Pass the name of the history Database, `database: "history"`, or its Drizzle database, `database: () => useDatabase("history").db` with `import { useDatabase } from "vite-hub/database"`. The Database can be SQLite, libSQL, D1, or Postgres. A Database Definition from `defineDatabase()` is not a Drizzle database.')}});function Et(e,t={},n=`[vitehub] ${e.why}`){let r=new se(e.code,n,t);return Object.defineProperties(r,{docs:{configurable:!0,enumerable:!1,value:e.docs,writable:!1},fix:{configurable:!0,enumerable:!1,value:e.fix,writable:!1},why:{configurable:!0,enumerable:!1,value:e.why,writable:!1}})}function Dt(e,t=`not-relative`){let n=e.slice(0,4096);return Et(Tt.WORKSPACE_PATH_INVALID({path:JSON.stringify(n),problem:t}),{details:{path:n}})}function Ot(e){let t=e.toLowerCase().split(`:`,1)[0];return{normalized:t.replace(/[ .]+$/,``),isTraversal:/^(?:\.(?: +[. ]*)?|\.\.(?: +[. ]*)?)$/.test(t)}}function kt(e=``,t={}){let n=e.replace(/\\/g,`/`),r=n.replace(/^\/+/,``).replace(/\/+$/,``),i=r.split(`/`).filter(Boolean);if(!t.allowEmpty&&!r||n.startsWith(`/`)||/^[a-z]:/i.test(n)||n.includes(`\0`))throw Dt(e);let a=i.map((e,t)=>({classification:Ot(e),index:t,name:e.toLowerCase()}));if(a.some(({classification:e})=>e.isTraversal))throw Dt(e);if(a.some(({classification:e,index:n,name:r})=>{let i=e.normalized===`.git`||/^git~\d+$/.test(e.normalized)||n===0&&e.normalized===`.vitehub`||n===0&&/^vitehu~\d+$/.test(e.normalized),a=(e.normalized===`.git`||n===0&&e.normalized===`.vitehub`)&&r===e.normalized;return i&&(!t.allowReserved||!a)}))throw Dt(e,`reserved`);return r}var At=`@workspace`,jt=`ping`;function Mt(e){try{let t=JSON.parse(A(e));if(!t||typeof t!=`object`||!(`epoch`in t)||!(`type`in t)||typeof t.epoch!=`string`||!t.epoch)return;if(t.type===`session`&&`access`in t&&(t.access===`read`||t.access===`write`))return t.access===`read`&&`reason`in t&&(t.reason===`access`||t.reason===`document`||t.reason===`version`)?{type:`session`,access:t.access,epoch:t.epoch,reason:t.reason}:{type:`session`,access:t.access,epoch:t.epoch};if(t.type===`reset`&&`reason`in t&&(t.reason===`source-changed`||t.reason===`stale`))return{type:`reset`,epoch:t.epoch,reason:t.reason}}catch{}}function Nt(e){if(typeof e!=`string`||e.length===0||e.length>4096||e.includes(`\0`)||e.startsWith(`/`)||e.endsWith(`/`)||e.includes(`\\`)||e.includes(`//`)||/^[a-z]:/i.test(e))return!1;try{return kt(e)===e}catch{return!1}}function Pt(e){try{let t=JSON.parse(A(e));if((t.operation===`create`||t.operation===`delete`||t.operation===`update`)&&Nt(t.path))return{operation:t.operation,path:t.path};if(t.operation===`move`&&Nt(t.from)&&Nt(t.to))return{operation:t.operation,from:t.from,to:t.to}}catch{}}function Ft(e){let t=x();return w(t,4),T(t,JSON.stringify(e)),S(t)}function It(e){let t=x();return w(t,6),T(t,JSON.stringify(e)),S(t)}function Lt(e){try{let t=JSON.parse(A(e));if(t&&typeof t==`object`&&`kind`in t&&t.kind===`notice`)return{kind:`notice`,body:`body`in t?t.body:void 0};if(!t||typeof t!=`object`||!(`id`in t)||typeof t.id!=`string`||!t.id||t.id.length>128||!(`kind`in t))return;if(t.kind===`request`)return{kind:`request`,id:t.id,body:`body`in t?t.body:void 0};if(t.kind!==`answer`||!(`ok`in t))return;if(t.ok===!0)return{kind:`answer`,id:t.id,ok:!0,body:`body`in t?t.body:void 0};if(t.ok===!1&&`why`in t&&typeof t.why==`string`)return{kind:`answer`,id:t.id,ok:!1,why:t.why}}catch{}}function Rt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var M=Date.now;function zt(e,t=typeof __VITEHUB_APP_BASE_URL__>`u`?`/`:__VITEHUB_APP_BASE_URL__){return t===`/`?e:`${t.replace(/\/+$/,``)}${e}`}var Bt=15e3;function Vt(e){let t;e.on(`status`,({status:n})=>{clearInterval(t),t=void 0;let r=e.ws;if(n!==`connected`||!r)return;let i=r.onmessage;r.onmessage=function(t){if(t.data!==`pong`)return i?.call(this,t);e.ws===r&&(e.wsLastMessageReceived=M())},t=setInterval(()=>{e.ws===r&&r.readyState===r.OPEN&&r.send(jt)},Bt)})}function Ht(e){let{awareness:t}=e;t.on(`update`,({removed:n},r)=>{if(r===e)for(let e of n)e!==t.clientID&&t.meta.delete(e)})}var Ut=Object.freeze({body:`body`,fields:`fields`,status:`status`});function Wt(e){return typeof e==`string`?e:null}function Gt(e){let t=e.getMap(Ut.status),n=t.get(`issues`),r=t.get(`savedBy`),i={issues:Array.isArray(n)?n:[],savedBy:r&&!Array.isArray(r)&&r instanceof Object?r:null};return{digest:Wt(t.get(`digest`)),error:Wt(t.get(`error`)),issues:i.issues,savedAt:Wt(t.get(`savedAt`)),savedBy:i.savedBy}}var Kt=[`#E11D48`,`#D97706`,`#059669`,`#0891B2`,`#2563EB`,`#7C3AED`,`#C026D3`];function N(e){try{return String(e)===e}catch{return!1}}function qt(e){if(!N(e.id)||!e.id||e.id.length>256)throw me.REALTIME_INVALID_USER();let t=0;for(let n=0;n<e.id.length;n++)t=Math.imul(31,t)+e.id.charCodeAt(n)|0;let n=(N(e.name)&&e.name||N(e.email)&&e.email||`Anonymous`).slice(0,256),r={color:Kt[Math.abs(t)%Kt.length],id:e.id,name:n};return N(e.image)&&e.image&&e.image.length<=2048&&(r.image=e.image),r}function Jt(e){return Rt(e)?N(e.id)&&e.id.length>0&&e.id.length<=256&&N(e.name)&&e.name.length>0&&e.name.length<=256&&N(e.color)&&/^#[\da-f]{6}$/i.test(e.color)&&(e.image===void 0||N(e.image)&&e.image.length<=2048):!1}function Yt(e){let t=[];for(let[n,r]of e)if(Jt(r.user)){let{color:e,id:i,image:a,name:o}=r.user,s={color:e,id:i,name:o,clientId:n};a!==void 0&&(s.image=a),t.push(s)}return t}var P=()=>new Map,Xt=e=>{let t=P();return e.forEach((e,n)=>{t.set(n,e)}),t},F=(e,t,n)=>{let r=e.get(t);return r===void 0&&e.set(t,r=n()),r},Zt=(e,t)=>{let n=[];for(let[r,i]of e)n.push(t(i,r));return n},Qt=(e,t)=>{for(let[n,r]of e)if(t(r,n))return!0;return!1},$t=class{constructor(){this._observers=P()}on(e,t){return F(this._observers,e,Ce).add(t),t}once(e,t){let n=(...r)=>{this.off(e,n),t(...r)};this.on(e,n)}off(e,t){let n=this._observers.get(e);n!==void 0&&(n.delete(t),n.size===0&&this._observers.delete(e))}emit(e,t){return _((this._observers.get(e)||P()).values()).forEach(e=>e(...t))}destroy(){this._observers=P()}},en=class{constructor(){this._observers=P()}on(e,t){F(this._observers,e,Ce).add(t)}once(e,t){let n=(...r)=>{this.off(e,n),t(...r)};this.on(e,n)}off(e,t){let n=this._observers.get(e);n!==void 0&&(n.delete(t),n.size===0&&this._observers.delete(e))}emit(e,t){return _((this._observers.get(e)||P()).values()).forEach(e=>e(...t))}destroy(){this._observers=P()}},tn=Symbol(`Equality`),nn=(e,t)=>e===t||!!e?.[tn]?.(t)||!1,rn=e=>typeof e==`object`,an=Object.assign,on=Object.keys,sn=(e,t)=>{for(let n in e)t(e[n],n)},cn=(e,t)=>{let n=[];for(let r in e)n.push(t(e[r],r));return n},ln=e=>on(e).length,un=e=>{for(let t in e)return!1;return!0},dn=(e,t)=>{for(let n in e)if(!t(e[n],n))return!1;return!0},fn=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),pn=(e,t)=>e===t||ln(e)===ln(t)&&dn(e,(e,n)=>(e!==void 0||fn(t,n))&&nn(t[n],e)),mn=Object.freeze,hn=e=>{for(let t in e){let n=e[t];(typeof n==`object`||typeof n==`function`)&&hn(e[t])}return mn(e)},gn=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&gn(e,t,n+1)}},_n=e=>e,vn=(e,t)=>{if(e===t)return!0;if(e==null||t==null||e.constructor!==t.constructor&&(e.constructor||Object)!==(t.constructor||Object))return!1;if(e[tn]!=null)return e[tn](t);switch(e.constructor){case ArrayBuffer:e=new Uint8Array(e),t=new Uint8Array(t);case Uint8Array:if(e.byteLength!==t.byteLength)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;break;case Set:if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;break;case Map:if(e.size!==t.size)return!1;for(let n of e.keys())if(!t.has(n)||!vn(e.get(n),t.get(n)))return!1;break;case void 0:case Object:if(ln(e)!==ln(t))return!1;for(let n in e)if(!fn(e,n)||!vn(e[n],t[n]))return!1;break;case Array:if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!vn(e[n],t[n]))return!1;break;default:return!1}return!0},yn=(e,t)=>t.includes(e);crypto.subtle;var bn=crypto.getRandomValues.bind(crypto),xn=()=>bn(new Uint32Array(1))[0],Sn=`10000000-1000-4000-8000-100000000000`,Cn=()=>Sn.replace(/[018]/g,e=>(e^xn()&15>>e/4).toString(16)),wn=e=>new Promise(e);Promise.all.bind(Promise);var Tn=e=>e===void 0?null:e,En=new class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}},Dn=!0;try{typeof window<`u`&&typeof localStorage<`u`&&localStorage&&(En=localStorage,Dn=!1)}catch{}var On=En,kn=e=>Dn||addEventListener(`storage`,e),An=e=>Dn||removeEventListener(`storage`,e),I=typeof process<`u`&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<`u`?process:0)===`[object process]`,jn=typeof window<`u`&&typeof document<`u`&&!I;typeof navigator<`u`&&/Mac/.test(navigator.platform);var L,Mn=[],Nn=()=>{if(L===void 0){if(I){L=P();let e=process.argv,t=null;for(let n=0;n<e.length;n++){let r=e[n];r[0]===`-`?(t!==null&&L.set(t,``),t=r):t===null?Mn.push(r):(L.set(t,r),t=null)}t!==null&&L.set(t,``)}else typeof location==`object`?(L=P(),(location.search||`?`).slice(1).split(`&`).forEach(e=>{if(e.length!==0){let[t,n]=e.split(`=`);L.set(`--${Fe(t,`-`)}`,n),L.set(`-${Fe(t,`-`)}`,n)}})):L=P()}return L},Pn=e=>Nn().has(e),Fn=e=>Tn(I?{}[e.toUpperCase().replaceAll(`-`,`_`)]:On.getItem(e)),In=e=>Pn(`--`+e)||Fn(e)!==null,Ln=In(`production`),Rn=I&&yn({}.FORCE_COLOR,[`true`,`1`,`2`])||!Pn(`--no-colors`)&&!In(`no-color`)&&(!I||process.stdout.isTTY)&&(!I||Pn(`--color`)||Fn(`COLORTERM`)!==null||(Fn(`TERM`)||``).includes(`color`)),zn=e=>new Uint8Array(e),Bn=e=>new Uint8Array(e),Vn=e=>{let t=``;for(let n=0;n<e.byteLength;n++)t+=Ae(e[n]);return btoa(t)},Hn=e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString(`base64`),Un=e=>{let t=atob(e),n=zn(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n},Wn=e=>new Uint8Array(Buffer.from(e,`base64`)),Gn=jn?Vn:Hn,Kn=jn?Un:Wn,qn=e=>{let t=zn(e.byteLength);return t.set(e),t},Jn=class{constructor(e,t){this.left=e,this.right=t}},R=(e,t)=>new Jn(e,t),Yn=e=>e.next()>=.5,Xn=(e,t,n)=>g(e.next()*(n+1-t)+t),Zn=(e,t,n)=>g(e.next()*(n+1-t)+t),Qn=(e,t,n)=>Zn(e,t,n),$n=e=>Ae(Qn(e,97,122)),er=(e,t=0,n=20)=>{let r=Qn(e,t,n),i=``;for(let t=0;t<r;t++)i+=$n(e);return i},tr=(e,t)=>t[Qn(e,0,t.length-1)],nr=Symbol(`0schema`),rr=class{constructor(){this._rerrs=[]}extend(e,t,n,r=null){this._rerrs.push({path:e,expected:t,has:n,message:r})}toString(){let e=[];for(let t=this._rerrs.length-1;t>0;t--){let n=this._rerrs[t];e.push(Be(` `,(this._rerrs.length-t)*2)+`${n.path==null?``:`[${n.path}] `}${n.has} doesn't match ${n.expected}. ${n.message}`)}return e.join(`
|
|
2
|
+
`)}},ir=(e,t)=>e===t?!0:e==null||t==null||e.constructor!==t.constructor?!1:e[tn]?nn(e,t):ke(e)?Ee(e,e=>De(t,t=>ir(e,t))):rn(e)?dn(e,(e,n)=>ir(e,t[n])):!1,z=class{static _dilutes=!1;extends(e){let[t,n]=[this.shape,e.shape];return this.constructor._dilutes&&([n,t]=[t,n]),ir(t,n)}equals(e){return this.constructor===e.constructor&&vn(this.shape,e.shape)}[nr](){return!0}[tn](e){return this.equals(e)}validate(e){return this.check(e)}check(e,t){y()}get nullable(){return Fr(this,Xr)}get optional(){return new pr(this)}cast(e){return ei(e,this),e}expect(e){return ei(e,this),e}},ar=class extends z{constructor(e,t){super(),this.shape=e,this._c=t}check(e,t=void 0){let n=e?.constructor===this.shape&&(this._c==null||this._c(e));return!n&&t?.extend(null,this.shape.name,e?.constructor.name,e?.constructor===this.shape?`Check failed`:`Constructor match failed`),n}},B=(e,t=null)=>new ar(e,t);B(ar);var or=class extends z{constructor(e){super(),this.shape=e}check(e,t){let n=this.shape(e);return!n&&t?.extend(null,`custom prop`,e?.constructor.name,`failed to check custom prop`),n}},V=e=>new or(e);B(or);var sr=class extends z{constructor(e){super(),this.shape=e}check(e,t){let n=this.shape.some(t=>t===e);return!n&&t?.extend(null,this.shape.join(` | `),e.toString()),n}},cr=(...e)=>new sr(e),lr=B(sr),ur=RegExp.escape||(e=>e.replace(/[().|&,$^[\]]/g,e=>`\\`+e)),dr=e=>{if(Gr.check(e))return[ur(e)];if(lr.check(e))return e.shape.map(e=>e+``);if(Wr.check(e))return[`[+-]?\\d+.?\\d*`];if(Kr.check(e))return[`.*`];if(Ir.check(e))return e.shape.map(dr).flat(1);b()};B(class extends z{constructor(e){super(),this.shape=e,this._r=RegExp(`^`+e.map(dr).map(e=>`(${e.join(`|`)})`).join(``)+`$`)}check(e,t){let n=this._r.exec(e)!=null;return!n&&t?.extend(null,this._r.toString(),e.toString(),`String doesn't match string template.`),n}});var fr=Symbol(`optional`),pr=class extends z{constructor(e){super(),this.shape=e}check(e,t){let n=e===void 0||this.shape.check(e);return!n&&t?.extend(null,`undefined (optional)`,`()`),n}get[fr](){return!0}},mr=B(pr),hr=class extends z{check(e,t){return t?.extend(null,`never`,typeof e),!1}};new hr,B(hr);var gr=class e extends z{constructor(e,t=!1){super(),this.shape=e,this._isPartial=t}static _dilutes=!0;get partial(){return new e(this.shape,!0)}check(e,t){return e==null?(t?.extend(null,`object`,`null`),!1):dn(this.shape,(n,r)=>{let i=this._isPartial&&!fn(e,r)||n.check(e[r],t);return!i&&t?.extend(r.toString(),n.toString(),typeof e[r],`Object property does not match`),i})}},_r=e=>new gr(e),vr=B(gr),yr=V(e=>e!=null&&(e.constructor===Object||e.constructor==null)),br=class extends z{constructor(e,t){super(),this.shape={keys:e,values:t}}check(e,t){return e!=null&&dn(e,(n,r)=>{let i=this.shape.keys.check(r,t);return!i&&t?.extend(r+``,`Record`,typeof e,i?`Key doesn't match schema`:`Value doesn't match value`),i&&this.shape.values.check(n,t)})}},xr=(e,t)=>new br(e,t),Sr=B(br),Cr=class extends z{constructor(e){super(),this.shape=e}check(e,t){return e!=null&&dn(this.shape,(n,r)=>{let i=n.check(e[r],t);return!i&&t?.extend(r.toString(),`Tuple`,typeof n),i})}},wr=(...e)=>new Cr(e);B(Cr);var Tr=class extends z{constructor(e){super(),this.shape=e.length===1?e[0]:new Pr(e)}check(e,t){let n=ke(e)&&Ee(e,e=>this.shape.check(e));return!n&&t?.extend(null,`Array`,``),n}},Er=(...e)=>new Tr(e),Dr=B(Tr),Or=V(e=>ke(e)),kr=class extends z{constructor(e,t){super(),this.shape=e,this._c=t}check(e,t){let n=e instanceof this.shape&&(this._c==null||this._c(e));return!n&&t?.extend(null,this.shape.name,e?.constructor.name),n}},Ar=(e,t=null)=>new kr(e,t);B(kr);var jr=Ar(z),Mr=B(class extends z{constructor(e){super(),this.len=e.length-1,this.args=wr(...e.slice(-1)),this.res=e[this.len]}check(e,t){let n=e.constructor===Function&&e.length<=this.len;return!n&&t?.extend(null,`function`,typeof e),n}}),Nr=V(e=>typeof e==`function`);B(class extends z{constructor(e){super(),this.shape=e}check(e,t){let n=Ee(this.shape,n=>n.check(e,t));return!n&&t?.extend(null,`Intersectinon`,typeof e),n}},e=>e.shape.length>0);var Pr=class extends z{static _dilutes=!0;constructor(e){super(),this.shape=e}check(e,t){let n=De(this.shape,n=>n.check(e,t));return t?.extend(null,`Union`,typeof e),n}},Fr=(...e)=>e.findIndex(e=>Ir.check(e))>=0?Fr(...e.map(e=>$r(e)).map(e=>Ir.check(e)?e.shape:[e]).flat(1)):e.length===1?e[0]:new Pr(e),Ir=B(Pr),Lr=()=>!0,Rr=V(Lr),zr=B(or,e=>e.shape===Lr),Br=V(e=>typeof e==`bigint`),Vr=V(e=>e===Br),Hr=V(e=>typeof e==`symbol`);V(e=>e===Hr);var Ur=V(e=>typeof e==`number`),Wr=V(e=>e===Ur),Gr=V(e=>typeof e==`string`),Kr=V(e=>e===Gr),qr=V(e=>typeof e==`boolean`),Jr=V(e=>e===qr),Yr=cr(void 0);B(sr,e=>e.shape.length===1&&e.shape[0]===void 0),cr(void 0);var Xr=cr(null),Zr=B(sr,e=>e.shape.length===1&&e.shape[0]===null);B(Uint8Array),B(ar,e=>e.shape===Uint8Array);var Qr=Fr(Ur,Gr,Xr,Yr,Br,qr,Hr);(()=>{let e=Er(Rr),t=xr(Gr,Rr),n=Fr(Ur,Gr,Xr,qr,e,t);return e.shape=n,t.shape.values=n,n})();var $r=e=>{if(jr.check(e))return e;if(yr.check(e)){let t={};for(let n in e)t[n]=$r(e[n]);return _r(t)}if(Or.check(e))return Fr(...e.map($r));if(Qr.check(e))return cr(e);if(Nr.check(e))return B(e);b()},ei=Ln?()=>{}:(e,t)=>{let n=new rr;if(!t.check(e,n))throw v(`Expected value to be of type ${t.constructor.name}.\n${n.toString()}`)},ti=class{constructor(e){this.patterns=[],this.$state=e}if(e,t){return this.patterns.push({if:$r(e),h:t}),this}else(e){return this.if(Rr,e)}done(){return(e,t)=>{for(let n=0;n<this.patterns.length;n++){let r=this.patterns[n];if(r.if.check(e))return r.h(e,t)}throw v(`Unhandled pattern`)}}},ni=(e=>new ti(e))(Rr).if(Wr,(e,t)=>Xn(t,xe,be)).if(Kr,(e,t)=>er(t)).if(Jr,(e,t)=>Yn(t)).if(Vr,(e,t)=>BigInt(Xn(t,xe,be))).if(Ir,(e,t)=>ri(t,tr(t,e.shape))).if(vr,(e,t)=>{let n={};for(let r in e.shape){let i=e.shape[r];if(mr.check(i)){if(Yn(t))continue;i=i.shape}n[r]=ni(i,t)}return n}).if(Dr,(e,t)=>{let n=[],r=Zn(t,0,42);for(let i=0;i<r;i++)n.push(ri(t,e.shape));return n}).if(lr,(e,t)=>tr(t,e.shape)).if(Zr,(e,t)=>null).if(Mr,(e,t)=>{let n=ri(t,e.res);return()=>n}).if(zr,(e,t)=>ri(t,tr(t,[Ur,Gr,Xr,Yr,Br,qr,Er(Ur),xr(Fr(`a`,`b`,`c`),Ur)]))).if(Sr,(e,t)=>{let n={},r=Xn(t,0,3);for(let i=0;i<r;i++){let r=ri(t,e.shape.keys);n[r]=ri(t,e.shape.values)}return n}).done(),ri=(e,t)=>ni($r(t),e),ii=typeof document<`u`?document:{};V(e=>e.nodeType===li),typeof DOMParser<`u`&&new DOMParser,V(e=>e.nodeType===oi),V(e=>e.nodeType===si);var ai=e=>Zt(e,(e,t)=>`${t}:${e};`).join(``),oi=ii.ELEMENT_NODE,si=ii.TEXT_NODE;ii.CDATA_SECTION_NODE,ii.COMMENT_NODE;var ci=ii.DOCUMENT_NODE;ii.DOCUMENT_TYPE_NODE;var li=ii.DOCUMENT_FRAGMENT_NODE;V(e=>e.nodeType===ci);var H=Symbol,ui=H(),di=H(),fi=H(),pi=H(),mi=H(),hi=H(),gi=H(),_i=H(),vi=H(),yi=e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=0;for(;r<e.length;r++){let n=e[r];if(n===void 0)break;if(n.constructor===String||n.constructor===Number)t.push(n);else if(n.constructor===Object)break}for(r>0&&n.push(t.join(``));r<e.length;r++){let t=e[r];t instanceof Symbol||n.push(t)}return n};M();var bi={[ui]:R(`font-weight`,`bold`),[di]:R(`font-weight`,`normal`),[fi]:R(`color`,`blue`),[mi]:R(`color`,`green`),[pi]:R(`color`,`grey`),[hi]:R(`color`,`red`),[gi]:R(`color`,`purple`),[_i]:R(`color`,`orange`),[vi]:R(`color`,`black`)},xi=Rn?e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=P(),i=[],a=0;for(;a<e.length;a++){let i=e[a],o=bi[i];if(o!==void 0)r.set(o.left,o.right);else{if(i===void 0)break;if(i.constructor===String||i.constructor===Number){let e=ai(r);a>0||e.length>0?(t.push(`%c`+i),n.push(e)):t.push(i)}else break}}for(a>0&&(i=n,i.unshift(t.join(``)));a<e.length;a++){let t=e[a];t instanceof Symbol||i.push(t)}return i}:yi,Si=(...e)=>{console.log(...xi(e)),wi.forEach(t=>t.print(e))},Ci=(...e)=>{console.warn(...xi(e)),e.unshift(_i),wi.forEach(t=>t.print(e))},wi=Ce(),Ti=e=>({[Symbol.iterator](){return this},next:e}),Ei=(e,t)=>Ti(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),Di=(e,t)=>Ti(()=>{let{done:n,value:r}=e.next();return{done:n,value:n?void 0:t(r)}}),Oi=class{constructor(e,t){this.clock=e,this.len=t}},ki=class{constructor(){this.clients=new Map}},Ai=(e,t,n)=>t.clients.forEach((t,r)=>{let i=e.doc.store.clients.get(r);if(i!=null){let r=i[i.length-1],a=r.id.clock+r.length;for(let r=0,o=t[r];r<t.length&&o.clock<a;o=t[++r])Na(e,i,o.clock,o.len,n)}}),ji=(e,t)=>{let n=0,r=e.length-1;for(;n<=r;){let i=g((n+r)/2),a=e[i],o=a.clock;if(o<=t){if(t<o+a.len)return i;n=i+1}else r=i-1}return null},Mi=(e,t)=>{let n=e.clients.get(t.client);return n!==void 0&&ji(n,t.clock)!==null},Ni=e=>{e.clients.forEach(e=>{e.sort((e,t)=>e.clock-t.clock);let t,n;for(t=1,n=1;t<e.length;t++){let r=e[n-1],i=e[t];r.clock+r.len>=i.clock?e[n-1]=new Oi(r.clock,_e(r.len,i.clock+i.len-r.clock)):(n<t&&(e[n]=i),n++)}e.length=n})},Pi=e=>{let t=new ki;for(let n=0;n<e.length;n++)e[n].clients.forEach((r,i)=>{if(!t.clients.has(i)){let a=r.slice();for(let t=n+1;t<e.length;t++)Te(a,e[t].clients.get(i)||[]);t.clients.set(i,a)}});return Ni(t),t},Fi=(e,t,n,r)=>{F(e.clients,t,()=>[]).push(new Oi(n,r))},Ii=()=>new ki,Li=e=>{let t=Ii();return e.clients.forEach((e,n)=>{let r=[];for(let t=0;t<e.length;t++){let n=e[t];if(n.deleted){let i=n.id.clock,a=n.length;if(t+1<e.length)for(let n=e[t+1];t+1<e.length&&n.deleted;n=e[++t+1])a+=n.length;r.push(new Oi(i,a))}}r.length>0&&t.clients.set(n,r)}),t},Ri=(e,t)=>{w(e.restEncoder,t.clients.size),_(t.clients.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{e.resetDsCurVal(),w(e.restEncoder,t);let r=n.length;w(e.restEncoder,r);for(let t=0;t<r;t++){let r=n[t];e.writeDsClock(r.clock),e.writeDsLen(r.len)}})},zi=e=>{let t=new ki,n=k(e.restDecoder);for(let r=0;r<n;r++){e.resetDsCurVal();let n=k(e.restDecoder),r=k(e.restDecoder);if(r>0){let i=F(t.clients,n,()=>[]);for(let t=0;t<r;t++)i.push(new Oi(e.readDsClock(),e.readDsLen()))}}return t},Bi=(e,t,n)=>{let r=new ki,i=k(e.restDecoder);for(let a=0;a<i;a++){e.resetDsCurVal();let i=k(e.restDecoder),a=k(e.restDecoder),o=n.clients.get(i)||[],s=W(n,i);for(let n=0;n<a;n++){let n=e.readDsClock(),a=n+e.readDsLen();if(n<s){s<a&&Fi(r,i,s,a-s);let e=G(o,n),c=o[e];for(!c.deleted&&c.id.clock<n&&(o.splice(e+1,0,Rs(t,c,n-c.id.clock)),e++);e<o.length&&(c=o[e++],c.id.clock<a);)c.deleted||(a<c.id.clock+c.length&&o.splice(e,0,Rs(t,c,a-c.id.clock)),c.delete(t))}else Fi(r,i,n,a-n)}}if(r.clients.size>0){let e=new Xi;return w(e.restEncoder,0),Ri(e,r),e.toUint8Array()}return null},Vi=xn,Hi=class e extends $t{constructor({guid:e=Cn(),collectionid:t=null,gc:n=!0,gcFilter:r=()=>!0,meta:i=null,autoLoad:a=!1,shouldLoad:o=!0}={}){super(),this.gc=n,this.gcFilter=r,this.clientID=Vi(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new Ta,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=o,this.autoLoad=a,this.meta=i,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=wn(e=>{this.on(`load`,()=>{this.isLoaded=!0,e(this)})});let s=()=>wn(e=>{let t=n=>{(n===void 0||n===!0)&&(this.off(`sync`,t),e())};this.on(`sync`,t)});this.on(`sync`,e=>{e===!1&&this.isSynced&&(this.whenSynced=s()),this.isSynced=e===void 0||e===!0,this.isSynced&&!this.isLoaded&&this.emit(`load`,[this])}),this.whenSynced=s()}load(){let e=this._item;e!==null&&!this.shouldLoad&&K(e.parent.doc,e=>{e.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(_(this.subdocs).map(e=>e.guid))}transact(e,t=null){return K(this,e,t)}get(e,t=J){let n=F(this.share,e,()=>{let e=new t;return e._integrate(this,null),e}),r=n.constructor;if(t!==J&&r!==t){if(r===J){let r=new t;r._map=n._map,n._map.forEach(e=>{for(;e!==null;e=e.left)e.parent=r}),r._start=n._start;for(let e=r._start;e!==null;e=e.right)e.parent=r;return r._length=n._length,this.share.set(e,r),r._integrate(this,null),r}throw Error(`Type with the name ${e} has already been defined with a different constructor`)}return n}getArray(e=``){return this.get(e,jo)}getText(e=``){return this.get(e,Zo)}getMap(e=``){return this.get(e,Po)}getXmlElement(e=``){return this.get(e,ns)}getXmlFragment(e=``){return this.get(e,es)}toJSON(){let e={};return this.share.forEach((t,n)=>{e[n]=t.toJSON()}),e}destroy(){this.isDestroyed=!0,_(this.subdocs).forEach(e=>e.destroy());let t=this._item;if(t!==null){this._item=null;let n=t.content;n.doc=new e({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=t,K(t.parent.doc,e=>{let r=n.doc;t.deleted||e.subdocsAdded.add(r),e.subdocsRemoved.add(this)},null,!0)}this.emit(`destroyed`,[!0]),this.emit(`destroy`,[this]),super.destroy()}},Ui=class{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return k(this.restDecoder)}readDsLen(){return k(this.restDecoder)}},Wi=class extends Ui{readLeftID(){return U(k(this.restDecoder),k(this.restDecoder))}readRightID(){return U(k(this.restDecoder),k(this.restDecoder))}readClient(){return k(this.restDecoder)}readInfo(){return ht(this.restDecoder)}readString(){return A(this.restDecoder)}readParentInfo(){return k(this.restDecoder)===1}readTypeRef(){return k(this.restDecoder)}readLen(){return k(this.restDecoder)}readAny(){return yt(this.restDecoder)}readBuf(){return qn(O(this.restDecoder))}readJSON(){return JSON.parse(A(this.restDecoder))}readKey(){return A(this.restDecoder)}},Gi=class{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=k(this.restDecoder),this.dsCurrVal}readDsLen(){let e=k(this.restDecoder)+1;return this.dsCurrVal+=e,e}},Ki=class extends Gi{constructor(e){super(e),this.keys=[],k(e),this.keyClockDecoder=new St(O(e)),this.clientDecoder=new xt(O(e)),this.leftClockDecoder=new St(O(e)),this.rightClockDecoder=new St(O(e)),this.infoDecoder=new bt(O(e),ht),this.stringDecoder=new Ct(O(e)),this.parentInfoDecoder=new bt(O(e),ht),this.typeRefDecoder=new xt(O(e)),this.lenDecoder=new xt(O(e))}readLeftID(){return new ya(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new ya(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return this.parentInfoDecoder.read()===1}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return yt(this.restDecoder)}readBuf(){return O(this.restDecoder)}readJSON(){return yt(this.restDecoder)}readKey(){let e=this.keyClockDecoder.read();if(e<this.keys.length)return this.keys[e];{let e=this.stringDecoder.read();return this.keys.push(e),e}}},qi=class{constructor(){this.restEncoder=x()}toUint8Array(){return S(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){w(this.restEncoder,e)}writeDsLen(e){w(this.restEncoder,e)}},Ji=class extends qi{writeLeftID(e){w(this.restEncoder,e.client),w(this.restEncoder,e.clock)}writeRightID(e){w(this.restEncoder,e.client),w(this.restEncoder,e.clock)}writeClient(e){w(this.restEncoder,e)}writeInfo(e){We(this.restEncoder,e)}writeString(e){T(this.restEncoder,e)}writeParentInfo(e){w(this.restEncoder,+!!e)}writeTypeRef(e){w(this.restEncoder,e)}writeLen(e){w(this.restEncoder,e)}writeAny(e){tt(this.restEncoder,e)}writeBuf(e){E(this.restEncoder,e)}writeJSON(e){T(this.restEncoder,JSON.stringify(e))}writeKey(e){T(this.restEncoder,e)}},Yi=class{constructor(){this.restEncoder=x(),this.dsCurrVal=0}toUint8Array(){return S(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){let t=e-this.dsCurrVal;this.dsCurrVal=e,w(this.restEncoder,t)}writeDsLen(e){e===0&&b(),w(this.restEncoder,e-1),this.dsCurrVal+=e}},Xi=class extends Yi{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new ot,this.clientEncoder=new it,this.leftClockEncoder=new ot,this.rightClockEncoder=new ot,this.infoEncoder=new nt(We),this.stringEncoder=new st,this.parentInfoEncoder=new nt(We),this.typeRefEncoder=new it,this.lenEncoder=new it}toUint8Array(){let e=x();return w(e,0),E(e,this.keyClockEncoder.toUint8Array()),E(e,this.clientEncoder.toUint8Array()),E(e,this.leftClockEncoder.toUint8Array()),E(e,this.rightClockEncoder.toUint8Array()),E(e,S(this.infoEncoder)),E(e,this.stringEncoder.toUint8Array()),E(e,S(this.parentInfoEncoder)),E(e,this.typeRefEncoder.toUint8Array()),E(e,this.lenEncoder.toUint8Array()),Je(e,S(this.restEncoder)),S(e)}writeLeftID(e){this.clientEncoder.write(e.client),this.leftClockEncoder.write(e.clock)}writeRightID(e){this.clientEncoder.write(e.client),this.rightClockEncoder.write(e.clock)}writeClient(e){this.clientEncoder.write(e)}writeInfo(e){this.infoEncoder.write(e)}writeString(e){this.stringEncoder.write(e)}writeParentInfo(e){this.parentInfoEncoder.write(+!!e)}writeTypeRef(e){this.typeRefEncoder.write(e)}writeLen(e){this.lenEncoder.write(e)}writeAny(e){tt(this.restEncoder,e)}writeBuf(e){E(this.restEncoder,e)}writeJSON(e){tt(this.restEncoder,e)}writeKey(e){let t=this.keyMap.get(e);t===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(e)):this.keyClockEncoder.write(t)}},Zi=(e,t,n,r)=>{r=_e(r,t[0].id.clock);let i=G(t,r);w(e.restEncoder,t.length-i),e.writeClient(n),w(e.restEncoder,r);let a=t[i];a.write(e,r-a.id.clock);for(let n=i+1;n<t.length;n++)t[n].write(e,0)},Qi=(e,t,n)=>{let r=new Map;n.forEach((e,n)=>{W(t,n)>e&&r.set(n,e)}),Ea(t).forEach((e,t)=>{n.has(t)||r.set(t,0)}),w(e.restEncoder,r.size),_(r.entries()).sort((e,t)=>t[0]-e[0]).forEach(([n,r])=>{Zi(e,t.clients.get(n),n,r)})},$i=(e,t)=>{let n=P(),r=k(e.restDecoder);for(let i=0;i<r;i++){let r=k(e.restDecoder),i=Array(r),a=e.readClient(),o=k(e.restDecoder);n.set(a,{i:0,refs:i});for(let n=0;n<r;n++){let r=e.readInfo();switch(31&r){case 0:{let t=e.readLen();i[n]=new X(U(a,o),t),o+=t;break}case 10:{let t=k(e.restDecoder);i[n]=new $(U(a,o),t),o+=t;break}default:{let s=!(r&192),c=new Q(U(a,o),null,(r&128)==128?e.readLeftID():null,null,(r&64)==64?e.readRightID():null,s?e.readParentInfo()?t.get(e.readString()):e.readLeftID():null,s&&(r&32)==32?e.readString():null,zs(e,r));i[n]=c,o+=c.length}}}}return n},ea=(e,t,n)=>{let r=[],i=_(n.keys()).sort((e,t)=>e-t);if(i.length===0)return null;let a=()=>{if(i.length===0)return null;let e=n.get(i[i.length-1]);for(;e.refs.length===e.i;)if(i.pop(),i.length>0)e=n.get(i[i.length-1]);else return null;return e},o=a();if(o===null)return null;let s=new Ta,c=new Map,l=(e,t)=>{let n=c.get(e);(n==null||n>t)&&c.set(e,t)},u=o.refs[o.i++],d=new Map,f=()=>{for(let e of r){let t=e.id.client,r=n.get(t);r?(r.i--,s.clients.set(t,r.refs.slice(r.i)),n.delete(t),r.i=0,r.refs=[]):s.clients.set(t,[e]),i=i.filter(e=>e!==t)}r.length=0};for(;;){if(u.constructor!==$){let i=F(d,u.id.client,()=>W(t,u.id.client))-u.id.clock;if(i<0)r.push(u),l(u.id.client,u.id.clock-1),f();else{let a=u.getMissing(e,t);if(a!==null){r.push(u);let e=n.get(a)||{refs:[],i:0};if(e.refs.length===e.i)l(a,W(t,a)),f();else{u=e.refs[e.i++];continue}}else(i===0||i<u.length)&&(u.integrate(e,i),d.set(u.id.client,u.id.clock+u.length))}}if(r.length>0)u=r.pop();else if(o!==null&&o.i<o.refs.length)u=o.refs[o.i++];else{if(o=a(),o===null)break;u=o.refs[o.i++]}}if(s.clients.size>0){let e=new Xi;return Qi(e,s,new Map),w(e.restEncoder,0),{missing:c,update:e.toUint8Array()}}return null},ta=(e,t)=>Qi(e,t.doc.store,t.beforeState),na=(e,t,n,r=new Ki(e))=>K(t,e=>{e.local=!1;let t=!1,n=e.doc,i=n.store,a=ea(e,i,$i(r,n)),o=i.pendingStructs;if(o){for(let[e,n]of o.missing)if(n<W(i,e)){t=!0;break}if(a){for(let[e,t]of a.missing){let n=o.missing.get(e);(n==null||n>t)&&o.missing.set(e,t)}o.update=Ka([o.update,a.update])}}else i.pendingStructs=a;let s=Bi(r,e,i);if(i.pendingDs){let t=new Ki(D(i.pendingDs));k(t.restDecoder);let n=Bi(t,e,i);i.pendingDs=s&&n?Ka([s,n]):s||n}else i.pendingDs=s;if(t){let t=i.pendingStructs.update;i.pendingStructs=null,ra(e.doc,t)}},n,!1),ra=(e,t,n,r=Ki)=>{let i=D(t);na(i,e,n,new r(i))},ia=(e,t,n)=>ra(e,t,n,Wi),aa=(e,t,n=new Map)=>{Qi(e,t.store,n),Ri(e,Li(t.store))},oa=(e,t=new Uint8Array([0]),n=new Xi)=>{aa(n,e,la(t));let r=[n.toUint8Array()];if(e.store.pendingDs&&r.push(e.store.pendingDs),e.store.pendingStructs&&r.push(qa(e.store.pendingStructs.update,t)),r.length>1){if(n.constructor===Ji)return Wa(r.map((e,t)=>t===0?e:Qa(e)));if(n.constructor===Xi)return Ka(r)}return r[0]},sa=(e,t)=>oa(e,t,new Ji),ca=e=>{let t=new Map,n=k(e.restDecoder);for(let r=0;r<n;r++){let n=k(e.restDecoder),r=k(e.restDecoder);t.set(n,r)}return t},la=e=>ca(new Ui(D(e))),ua=(e,t)=>(w(e.restEncoder,t.size),_(t.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{w(e.restEncoder,t),w(e.restEncoder,n)}),e),da=(e,t)=>ua(e,Ea(t.store)),fa=(e,t=new Yi)=>(e instanceof Map?ua(t,e):da(t,e),t.toUint8Array()),pa=e=>fa(e,new qi),ma=class{constructor(){this.l=[]}},ha=()=>new ma,ga=(e,t)=>e.l.push(t),_a=(e,t)=>{let n=e.l,r=n.length;e.l=n.filter(e=>t!==e),r===e.l.length&&console.error(`[yjs] Tried to remove event handler that doesn't exist.`)},va=(e,t,n)=>gn(e.l,[t,n]),ya=class{constructor(e,t){this.client=e,this.clock=t}},ba=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,U=(e,t)=>new ya(e,t),xa=e=>{for(let[t,n]of e.doc.share.entries())if(n===e)return t;throw b()},Sa=class{constructor(e,t){this.ds=e,this.sv=t}};((e,t)=>new Sa(e,t))(Ii(),new Map);var Ca=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!Mi(t.ds,e.id),wa=(e,t)=>{let n=F(e.meta,wa,Ce),r=e.doc.store;n.has(t)||(t.sv.forEach((t,n)=>{t<W(r,n)&&Aa(e,U(n,t))}),Ai(e,t.ds,e=>{}),n.add(t))},Ta=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},Ea=e=>{let t=new Map;return e.clients.forEach((e,n)=>{let r=e[e.length-1];t.set(n,r.id.clock+r.length)}),t},W=(e,t)=>{let n=e.clients.get(t);if(n===void 0)return 0;let r=n[n.length-1];return r.id.clock+r.length},Da=(e,t)=>{let n=e.clients.get(t.id.client);if(n===void 0)n=[],e.clients.set(t.id.client,n);else{let e=n[n.length-1];if(e.id.clock+e.length!==t.id.clock)throw b()}n.push(t)},G=(e,t)=>{let n=0,r=e.length-1,i=e[r],a=i.id.clock;if(a===t)return r;let o=g(t/(a+i.length-1)*r);for(;n<=r;){if(i=e[o],a=i.id.clock,a<=t){if(t<a+i.length)return o;n=o+1}else r=o-1;o=g((n+r)/2)}throw b()},Oa=(e,t)=>{let n=e.clients.get(t.client);return n[G(n,t.clock)]},ka=(e,t,n)=>{let r=G(t,n),i=t[r];return i.id.clock<n&&i instanceof Q?(t.splice(r+1,0,Rs(e,i,n-i.id.clock)),r+1):r},Aa=(e,t)=>{let n=e.doc.store.clients.get(t.client);return n[ka(e,n,t.clock)]},ja=(e,t,n)=>{let r=t.clients.get(n.client),i=G(r,n.clock),a=r[i];return n.clock!==a.id.clock+a.length-1&&a.constructor!==X&&r.splice(i+1,0,Rs(e,a,n.clock-a.id.clock+1)),a},Ma=(e,t,n)=>{let r=e.clients.get(t.id.client);r[G(r,t.id.clock)]=n},Na=(e,t,n,r,i)=>{if(r===0)return;let a=n+r,o=ka(e,t,n),s;do s=t[o++],a<s.id.clock+s.length&&ka(e,t,a),i(s);while(o<t.length&&t[o].id.clock<a)},Pa=class{constructor(e,t,n){this.doc=e,this.deleteSet=new ki,this.beforeState=Ea(e.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=t,this.meta=new Map,this.local=n,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}},Fa=(e,t)=>t.deleteSet.clients.size===0&&!Qt(t.afterState,(e,n)=>t.beforeState.get(n)!==e)?!1:(Ni(t.deleteSet),ta(e,t),Ri(e,t.deleteSet),!0),Ia=(e,t,n)=>{let r=t._item;(r===null||r.id.clock<(e.beforeState.get(r.id.client)||0)&&!r.deleted)&&F(e.changed,t,Ce).add(n)},La=(e,t)=>{let n=e[t],r=e[t-1],i=t;for(;i>0&&r.deleted===n.deleted&&r.constructor===n.constructor&&r.mergeWith(n);n=r,r=e[--i-1])n instanceof Q&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,r);let a=t-i;return a&&e.splice(t+1-a,a),a},Ra=(e,t,n)=>{for(let[r,i]of e.clients.entries()){let e=t.clients.get(r);for(let r=i.length-1;r>=0;r--){let a=i[r],o=a.clock+a.len;for(let r=G(e,a.clock),i=e[r];r<e.length&&i.id.clock<o;i=e[++r]){let i=e[r];if(a.clock+a.len<=i.id.clock)break;i instanceof Q&&i.deleted&&!i.keep&&n(i)&&i.gc(t,!1)}}}},za=(e,t)=>{e.clients.forEach((e,n)=>{let r=t.clients.get(n);for(let t=e.length-1;t>=0;t--){let n=e[t],i=ge(r.length-1,1+G(r,n.clock+n.len-1));for(let e=i,t=r[e];e>0&&t.id.clock>=n.clock;t=r[e])e-=1+La(r,e)}})},Ba=(e,t)=>{if(t<e.length){let n=e[t],r=n.doc,i=r.store,a=n.deleteSet,o=n._mergeStructs;try{Ni(a),n.afterState=Ea(n.doc.store),r.emit(`beforeObserverCalls`,[n,r]);let e=[];n.changed.forEach((t,r)=>e.push(()=>{r._item!==null&&r._item.deleted||r._callObserver(n,t)})),e.push(()=>{n.changedParentTypes.forEach((t,r)=>{r._dEH.l.length>0&&(r._item===null||!r._item.deleted)&&e.push(()=>{t=t.filter(e=>e.target._item===null||!e.target._item.deleted),t.forEach(e=>{e.currentTarget=r,e._path=null}),t.sort((e,t)=>e.path.length-t.path.length),va(r._dEH,t,n)})}),e.push(()=>r.emit(`afterTransaction`,[n,r])),e.push(()=>{n._needFormattingCleanup&&Jo(n)})}),gn(e,[])}finally{r.gc&&Ra(a,i,r.gcFilter),za(a,i),n.afterState.forEach((e,t)=>{let r=n.beforeState.get(t)||0;if(r!==e){let e=i.clients.get(t),n=_e(G(e,r),1);for(let t=e.length-1;t>=n;)t-=1+La(e,t)}});for(let e=o.length-1;e>=0;e--){let{client:t,clock:n}=o[e].id,r=i.clients.get(t),a=G(r,n);a+1<r.length&&La(r,a+1)>1||a>0&&La(r,a)}if(!n.local&&n.afterState.get(r.clientID)!==n.beforeState.get(r.clientID)&&(Si(_i,ui,`[yjs] `,di,hi,`Changed the client-id because another client seems to be using it.`),r.clientID=Vi()),r.emit(`afterTransactionCleanup`,[n,r]),r._observers.has(`update`)){let e=new Ji;Fa(e,n)&&r.emit(`update`,[e.toUint8Array(),n.origin,r,n])}if(r._observers.has(`updateV2`)){let e=new Xi;Fa(e,n)&&r.emit(`updateV2`,[e.toUint8Array(),n.origin,r,n])}let{subdocsAdded:s,subdocsLoaded:c,subdocsRemoved:l}=n;(s.size>0||l.size>0||c.size>0)&&(s.forEach(e=>{e.clientID=r.clientID,e.collectionid??=r.collectionid,r.subdocs.add(e)}),l.forEach(e=>r.subdocs.delete(e)),r.emit(`subdocs`,[{loaded:c,added:s,removed:l},r,n]),l.forEach(e=>e.destroy())),e.length<=t+1?(r._transactionCleanups=[],r.emit(`afterAllTransactions`,[r,e])):Ba(e,t+1)}}},K=(e,t,n=null,r=!0)=>{let i=e._transactionCleanups,a=!1,o=null;e._transaction===null&&(a=!0,e._transaction=new Pa(e,n,r),i.push(e._transaction),i.length===1&&e.emit(`beforeAllTransactions`,[e]),e.emit(`beforeTransaction`,[e._transaction,e]));try{o=t(e._transaction)}finally{if(a){let t=e._transaction===i[0];e._transaction=null,t&&Ba(i,0)}}return o};function*Va(e){let t=k(e.restDecoder);for(let n=0;n<t;n++){let t=k(e.restDecoder),n=e.readClient(),r=k(e.restDecoder);for(let i=0;i<t;i++){let t=e.readInfo();if(t===10){let t=k(e.restDecoder);yield new $(U(n,r),t),r+=t}else if(31&t){let i=!(t&192),a=new Q(U(n,r),null,(t&128)==128?e.readLeftID():null,null,(t&64)==64?e.readRightID():null,i?e.readParentInfo()?e.readString():e.readLeftID():null,i&&(t&32)==32?e.readString():null,zs(e,t));yield a,r+=a.length}else{let t=e.readLen();yield new X(U(n,r),t),r+=t}}}}var Ha=class{constructor(e,t){this.gen=Va(e),this.curr=null,this.done=!1,this.filterSkips=t,this.next()}next(){do this.curr=this.gen.next().value||null;while(this.filterSkips&&this.curr!==null&&this.curr.constructor===$);return this.curr}},Ua=class{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}},Wa=e=>Ka(e,Wi,Ji),Ga=(e,t)=>{if(e.constructor===X){let{client:n,clock:r}=e.id;return new X(U(n,r+t),e.length-t)}if(e.constructor===$){let{client:n,clock:r}=e.id;return new $(U(n,r+t),e.length-t)}{let n=e,{client:r,clock:i}=n.id;return new Q(U(r,i+t),null,U(r,i+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},Ka=(e,t=Ki,n=Xi)=>{if(e.length===1)return e[0];let r=e.map(e=>new t(D(e))),i=r.map(e=>new Ha(e,!0)),a=null,o=new n,s=new Ua(o);for(;i=i.filter(e=>e.curr!==null),i.sort((e,t)=>{if(e.curr.id.client===t.curr.id.client){let n=e.curr.id.clock-t.curr.id.clock;return n===0?e.curr.constructor===t.curr.constructor?0:e.curr.constructor===$?1:-1:n}return t.curr.id.client-e.curr.id.client}),i.length!==0;){let e=i[0],t=e.curr.id.client;if(a!==null){let n=e.curr,r=!1;for(;n!==null&&n.id.clock+n.length<=a.struct.id.clock+a.struct.length&&n.id.client>=a.struct.id.client;)n=e.next(),r=!0;if(n===null||n.id.client!==t||r&&n.id.clock>a.struct.id.clock+a.struct.length)continue;if(t!==a.struct.id.client)Ya(s,a.struct,a.offset),a={struct:n,offset:0},e.next();else if(a.struct.id.clock+a.struct.length<n.id.clock){if(a.struct.constructor===$)a.struct.length=n.id.clock+n.length-a.struct.id.clock;else{Ya(s,a.struct,a.offset);let e=n.id.clock-a.struct.id.clock-a.struct.length;a={struct:new $(U(t,a.struct.id.clock+a.struct.length),e),offset:0}}}else{let t=a.struct.id.clock+a.struct.length-n.id.clock;t>0&&(a.struct.constructor===$?a.struct.length-=t:n=Ga(n,t)),a.struct.mergeWith(n)||(Ya(s,a.struct,a.offset),a={struct:n,offset:0},e.next())}}else a={struct:e.curr,offset:0},e.next();for(let n=e.curr;n!==null&&n.id.client===t&&n.id.clock===a.struct.id.clock+a.struct.length&&n.constructor!==$;n=e.next())Ya(s,a.struct,a.offset),a={struct:n,offset:0}}return a!==null&&(Ya(s,a.struct,a.offset),a=null),Xa(s),Ri(o,Pi(r.map(e=>zi(e)))),o.toUint8Array()},qa=(e,t,n=Ki,r=Xi)=>{let i=la(t),a=new r,o=new Ua(a),s=new n(D(e)),c=new Ha(s,!1);for(;c.curr;){let e=c.curr,t=e.id.client,n=i.get(t)||0;if(c.curr.constructor===$)c.next();else if(e.id.clock+e.length>n)for(Ya(o,e,_e(n-e.id.clock,0)),c.next();c.curr&&c.curr.id.client===t;)Ya(o,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===t&&c.curr.id.clock+c.curr.length<=n;)c.next()}return Xa(o),Ri(a,zi(s)),a.toUint8Array()},Ja=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:S(e.encoder.restEncoder)}),e.encoder.restEncoder=x(),e.written=0)},Ya=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&Ja(e),e.written===0&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),w(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},Xa=e=>{Ja(e);let t=e.encoder.restEncoder;w(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){let r=e.clientStructs[n];w(t,r.written),Je(t,r.restEncoder)}},Za=(e,t,n,r)=>{let i=new n(D(e)),a=new Ha(i,!1),o=new r,s=new Ua(o);for(let e=a.curr;e!==null;e=a.next())Ya(s,t(e),0);return Xa(s),Ri(o,zi(i)),o.toUint8Array()},Qa=e=>Za(e,_n,Ki,Ji),$a=`You must not compute changes after the event-handler fired.`,eo=class{constructor(e,t){this.target=e,this.currentTarget=e,this.transaction=t,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||=to(this.currentTarget,this.target)}deletes(e){return Mi(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw v($a);let e=new Map,t=this.target;this.transaction.changed.get(t).forEach(n=>{if(n!==null){let r=t._map.get(n),i,a;if(this.adds(r)){let e=r.left;for(;e!==null&&this.adds(e);)e=e.left;if(this.deletes(r)){if(e!==null&&this.deletes(e))i=`delete`,a=we(e.content.getContent());else return}else e!==null&&this.deletes(e)?(i=`update`,a=we(e.content.getContent())):(i=`add`,a=void 0)}else if(this.deletes(r))i=`delete`,a=we(r.content.getContent());else return;e.set(n,{action:i,oldValue:a})}}),this._keys=e}return this._keys}get delta(){return this.changes.delta}adds(e){return e.id.clock>=(this.transaction.beforeState.get(e.id.client)||0)}get changes(){let e=this._changes;if(e===null){if(this.transaction.doc._transactionCleanups.length===0)throw v($a);let t=this.target,n=Ce(),r=Ce(),i=[];if(e={added:n,deleted:r,delta:i,keys:this.keys},this.transaction.changed.get(t).has(null)){let e=null,a=()=>{e&&i.push(e)};for(let i=t._start;i!==null;i=i.right)i.deleted?this.deletes(i)&&!this.adds(i)&&((e===null||e.delete===void 0)&&(a(),e={delete:0}),e.delete+=i.length,r.add(i)):this.adds(i)?((e===null||e.insert===void 0)&&(a(),e={insert:[]}),e.insert=e.insert.concat(i.content.getContent()),n.add(i)):((e===null||e.retain===void 0)&&(a(),e={retain:0}),e.retain+=i.length);e!==null&&e.retain===void 0&&a()}this._changes=e}return e}},to=(e,t)=>{let n=[];for(;t._item!==null&&t!==e;){if(t._item.parentSub!==null)n.unshift(t._item.parentSub);else{let e=0,r=t._item.parent._start;for(;r!==t._item&&r!==null;)!r.deleted&&r.countable&&(e+=r.length),r=r.right;n.unshift(e)}t=t._item.parent}return n},q=()=>{Ci(`Invalid access: Add Yjs type to a document before reading data.`)},no=80,ro=0,io=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=ro++}},ao=e=>{e.timestamp=ro++},oo=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=ro++},so=(e,t,n)=>{if(e.length>=no){let r=e.reduce((e,t)=>e.timestamp<t.timestamp?e:t);return oo(r,t,n),r}{let r=new io(t,n);return e.push(r),r}},co=(e,t)=>{if(e._start===null||t===0||e._searchMarker===null)return null;let n=e._searchMarker.length===0?null:e._searchMarker.reduce((e,n)=>he(t-e.index)<he(t-n.index)?e:n),r=e._start,i=0;for(n!==null&&(r=n.p,i=n.index,ao(n));r.right!==null&&i<t;){if(!r.deleted&&r.countable){if(t<i+r.length)break;i+=r.length}r=r.right}for(;r.left!==null&&i>t;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);for(;r.left!==null&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);return n!==null&&he(n.index-i)<r.parent.length/no?(oo(n,r,i),n):so(e._searchMarker,r,i)},lo=(e,t,n)=>{for(let r=e.length-1;r>=0;r--){let i=e[r];if(n>0){let t=i.p;for(t.marker=!1;t&&(t.deleted||!t.countable);)t=t.left,t&&!t.deleted&&t.countable&&(i.index-=t.length);if(t===null||t.marker===!0){e.splice(r,1);continue}i.p=t,t.marker=!0}(t<i.index||n>0&&t===i.index)&&(i.index=_e(t,i.index+n))}},uo=(e,t,n)=>{let r=e,i=t.changedParentTypes;for(;F(i,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;va(r._eH,n,t)},J=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=ha(),this._dEH=ha(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw y()}clone(){throw y()}_write(e){}get _first(){let e=this._start;for(;e!==null&&e.deleted;)e=e.right;return e}_callObserver(e,t){!e.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(e){ga(this._eH,e)}observeDeep(e){ga(this._dEH,e)}unobserve(e){_a(this._eH,e)}unobserveDeep(e){_a(this._dEH,e)}toJSON(){}},fo=(e,t,n)=>{e.doc??q(),t<0&&(t=e._length+t),n<0&&(n=e._length+n);let r=n-t,i=[],a=e._start;for(;a!==null&&r>0;){if(a.countable&&!a.deleted){let e=a.content.getContent();if(e.length<=t)t-=e.length;else{for(let n=t;n<e.length&&r>0;n++)i.push(e[n]),r--;t=0}}a=a.right}return i},po=e=>{e.doc??q();let t=[],n=e._start;for(;n!==null;){if(n.countable&&!n.deleted){let e=n.content.getContent();for(let n=0;n<e.length;n++)t.push(e[n])}n=n.right}return t},mo=(e,t)=>{let n=0,r=e._start;for(e.doc??q();r!==null;){if(r.countable&&!r.deleted){let i=r.content.getContent();for(let r=0;r<i.length;r++)t(i[r],n++,e)}r=r.right}},ho=(e,t)=>{let n=[];return mo(e,(r,i)=>{n.push(t(r,i,e))}),n},go=e=>{let t=e._start,n=null,r=0;return{[Symbol.iterator](){return this},next:()=>{if(n===null){for(;t!==null&&t.deleted;)t=t.right;if(t===null)return{done:!0,value:void 0};n=t.content.getContent(),r=0,t=t.right}let e=n[r++];return n.length<=r&&(n=null),{done:!1,value:e}}}},_o=(e,t)=>{e.doc??q();let n=co(e,t),r=e._start;for(n!==null&&(r=n.p,t-=n.index);r!==null;r=r.right)if(!r.deleted&&r.countable){if(t<r.length)return r.content.getContent()[t];t-=r.length}},vo=(e,t,n,r)=>{let i=n,a=e.doc,o=a.clientID,s=a.store,c=n===null?t._start:n.right,l=[],u=()=>{l.length>0&&(i=new Q(U(o,W(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new ws(l)),i.integrate(e,0),l=[])};r.forEach(n=>{if(n===null)l.push(n);else switch(n.constructor){case Number:case Object:case Boolean:case Array:case String:l.push(n);break;default:switch(u(),n.constructor){case Uint8Array:case ArrayBuffer:i=new Q(U(o,W(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new ds(new Uint8Array(n))),i.integrate(e,0);break;case Hi:i=new Q(U(o,W(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new gs(n)),i.integrate(e,0);break;default:if(n instanceof J)i=new Q(U(o,W(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new Is(n)),i.integrate(e,0);else throw Error(`Unexpected content type in insert operation`)}}}),u()},yo=()=>v(`Length exceeded!`),bo=(e,t,n,r)=>{if(n>t._length)throw yo();if(n===0)return t._searchMarker&&lo(t._searchMarker,n,r.length),vo(e,t,null,r);let i=n,a=co(t,n),o=t._start;for(a!==null&&(o=a.p,n-=a.index,n===0&&(o=o.prev,n+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(n<=o.length){n<o.length&&Aa(e,U(o.id.client,o.id.clock+n));break}n-=o.length}return t._searchMarker&&lo(t._searchMarker,i,r.length),vo(e,t,o,r)},xo=(e,t,n)=>{let r=(t._searchMarker||[]).reduce((e,t)=>t.index>e.index?t:e,{index:0,p:t._start}).p;if(r)for(;r.right;)r=r.right;return vo(e,t,r,n)},So=(e,t,n,r)=>{if(r===0)return;let i=n,a=r,o=co(t,n),s=t._start;for(o!==null&&(s=o.p,n-=o.index);s!==null&&n>0;s=s.right)!s.deleted&&s.countable&&(n<s.length&&Aa(e,U(s.id.client,s.id.clock+n)),n-=s.length);for(;r>0&&s!==null;)s.deleted||(r<s.length&&Aa(e,U(s.id.client,s.id.clock+r)),s.delete(e),r-=s.length),s=s.right;if(r>0)throw yo();t._searchMarker&&lo(t._searchMarker,i,-a+r)},Co=(e,t,n)=>{let r=t._map.get(n);r!==void 0&&r.delete(e)},wo=(e,t,n,r)=>{let i=t._map.get(n)||null,a=e.doc,o=a.clientID,s;if(r==null)s=new ws([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:s=new ws([r]);break;case Uint8Array:s=new ds(r);break;case Hi:s=new gs(r);break;default:if(r instanceof J)s=new Is(r);else throw Error(`Unexpected content type`)}new Q(U(o,W(a.store,o)),i,i&&i.lastId,null,null,t,n,s).integrate(e,0)},To=(e,t)=>{e.doc??q();let n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},Eo=e=>{let t={};return e.doc??q(),e._map.forEach((e,n)=>{e.deleted||(t[n]=e.content.getContent()[e.length-1])}),t},Do=(e,t)=>{e.doc??q();let n=e._map.get(t);return n!==void 0&&!n.deleted},Oo=(e,t)=>{let n={};return e._map.forEach((e,r)=>{let i=e;for(;i!==null&&(!t.sv.has(i.id.client)||i.id.clock>=(t.sv.get(i.id.client)||0));)i=i.left;i!==null&&Ca(i,t)&&(n[r]=i.content.getContent()[i.length-1])}),n},ko=e=>(e.doc??q(),Ei(e._map.entries(),e=>!e[1].deleted)),Ao=class extends eo{},jo=class e extends J{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){let n=new e;return n.push(t),n}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(e=>e instanceof J?e.clone():e)),t}get length(){return this.doc??q(),this._length}_callObserver(e,t){super._callObserver(e,t),uo(this,e,new Ao(this,e))}insert(e,t){this.doc===null?this._prelimContent.splice(e,0,...t):K(this.doc,n=>{bo(n,this,e,t)})}push(e){this.doc===null?this._prelimContent.push(...e):K(this.doc,t=>{xo(t,this,e)})}unshift(e){this.insert(0,e)}delete(e,t=1){this.doc===null?this._prelimContent.splice(e,t):K(this.doc,n=>{So(n,this,e,t)})}get(e){return _o(this,e)}toArray(){return po(this)}slice(e=0,t=this.length){return fo(this,e,t)}toJSON(){return this.map(e=>e instanceof J?e.toJSON():e)}map(e){return ho(this,e)}forEach(e){mo(this,e)}[Symbol.iterator](){return go(this)}_write(e){e.writeTypeRef(ks)}},Mo=e=>new jo,No=class extends eo{constructor(e,t,n){super(e,t),this.keysChanged=n}},Po=class e extends J{constructor(e){super(),this._prelimContent=null,this._prelimContent=e===void 0?new Map:new Map(e)}_integrate(e,t){super._integrate(e,t),this._prelimContent.forEach((e,t)=>{this.set(t,e)}),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return this.forEach((e,n)=>{t.set(n,e instanceof J?e.clone():e)}),t}_callObserver(e,t){uo(this,e,new No(this,e,t))}toJSON(){this.doc??q();let e={};return this._map.forEach((t,n)=>{if(!t.deleted){let r=t.content.getContent()[t.length-1];e[n]=r instanceof J?r.toJSON():r}}),e}get size(){return[...ko(this)].length}keys(){return Di(ko(this),e=>e[0])}values(){return Di(ko(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return Di(ko(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??q(),this._map.forEach((t,n)=>{t.deleted||e(t.content.getContent()[t.length-1],n,this)})}[Symbol.iterator](){return this.entries()}delete(e){this.doc===null?this._prelimContent.delete(e):K(this.doc,t=>{Co(t,this,e)})}set(e,t){return this.doc===null?this._prelimContent.set(e,t):K(this.doc,n=>{wo(n,this,e,t)}),t}get(e){return To(this,e)}has(e){return Do(this,e)}clear(){this.doc===null?this._prelimContent.clear():K(this.doc,e=>{this.forEach(function(t,n,r){Co(e,r,n)})})}_write(e){e.writeTypeRef(As)}},Fo=e=>new Po,Y=(e,t)=>e===t||typeof e==`object`&&typeof t==`object`&&e&&t&&pn(e,t),Io=class{constructor(e,t,n,r){this.left=e,this.right=t,this.index=n,this.currentAttributes=r}forward(){switch(this.right===null&&b(),this.right.content.constructor){case Z:this.right.deleted||Bo(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length)}this.left=this.right,this.right=this.right.right}},Lo=(e,t,n)=>{for(;t.right!==null&&n>0;){switch(t.right.content.constructor){case Z:t.right.deleted||Bo(t.currentAttributes,t.right.content);break;default:t.right.deleted||(n<t.right.length&&Aa(e,U(t.right.id.client,t.right.id.clock+n)),t.index+=t.right.length,n-=t.right.length)}t.left=t.right,t.right=t.right.right}return t},Ro=(e,t,n,r)=>{let i=new Map,a=r?co(t,n):null;return a?Lo(e,new Io(a.p.left,a.p,a.index,i),n-a.index):Lo(e,new Io(null,t._start,0,i),n)},zo=(e,t,n,r)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===Z&&Y(r.get(n.right.content.key),n.right.content.value));)n.right.deleted||r.delete(n.right.content.key),n.forward();let i=e.doc,a=i.clientID;r.forEach((r,o)=>{let s=n.left,c=n.right,l=new Q(U(a,W(i.store,a)),s,s&&s.lastId,c,c&&c.id,t,null,new Z(o,r));l.integrate(e,0),n.right=l,n.forward()})},Bo=(e,t)=>{let{key:n,value:r}=t;r===null?e.delete(n):e.set(n,r)},Vo=(e,t)=>{for(;e.right!==null&&(e.right.deleted||e.right.content.constructor===Z&&Y(t[e.right.content.key]??null,e.right.content.value));)e.forward()},Ho=(e,t,n,r)=>{let i=e.doc,a=i.clientID,o=new Map;for(let s in r){let c=r[s],l=n.currentAttributes.get(s)??null;if(!Y(l,c)){o.set(s,l);let{left:r,right:u}=n;n.right=new Q(U(a,W(i.store,a)),r,r&&r.lastId,u,u&&u.id,t,null,new Z(s,c)),n.right.integrate(e,0),n.forward()}}return o},Uo=(e,t,n,r,i)=>{n.currentAttributes.forEach((e,t)=>{i[t]===void 0&&(i[t]=null)});let a=e.doc,o=a.clientID;Vo(n,i);let s=Ho(e,t,n,i),c=r.constructor===String?new Es(r):r instanceof J?new Is(r):new vs(r),{left:l,right:u,index:d}=n;t._searchMarker&&lo(t._searchMarker,n.index,c.getLength()),u=new Q(U(o,W(a.store,o)),l,l&&l.lastId,u,u&&u.id,t,null,c),u.integrate(e,0),n.right=u,n.index=d,n.forward(),zo(e,t,n,s)},Wo=(e,t,n,r,i)=>{let a=e.doc,o=a.clientID;Vo(n,i);let s=Ho(e,t,n,i);iterationLoop:for(;n.right!==null&&(r>0||s.size>0&&(n.right.deleted||n.right.content.constructor===Z));){if(!n.right.deleted)switch(n.right.content.constructor){case Z:{let{key:t,value:a}=n.right.content,o=i[t];if(o!==void 0){if(Y(o,a))s.delete(t);else{if(r===0)break iterationLoop;s.set(t,a)}n.right.delete(e)}else n.currentAttributes.set(t,a);break}default:r<n.right.length&&Aa(e,U(n.right.id.client,n.right.id.clock+r)),r-=n.right.length}n.forward()}if(r>0){let i=``;for(;r>0;r--)i+=`
|
|
3
|
+
`;n.right=new Q(U(o,W(a.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new Es(i)),n.right.integrate(e,0),n.forward()}zo(e,t,n,s)},Go=(e,t,n,r,i)=>{let a=t,o=P();for(;a&&(!a.countable||a.deleted);){if(!a.deleted&&a.content.constructor===Z){let e=a.content;o.set(e.key,e)}a=a.right}let s=0,c=!1;for(;t!==a;){if(n===t&&(c=!0),!t.deleted){let n=t.content;switch(n.constructor){case Z:{let{key:a,value:l}=n,u=r.get(a)??null;(o.get(a)!==n||u===l)&&(t.delete(e),s++,!c&&(i.get(a)??null)===l&&u!==l&&(u===null?i.delete(a):i.set(a,u))),!c&&!t.deleted&&Bo(i,n);break}}}t=t.right}return s},Ko=(e,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;let n=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===Z){let r=t.content.key;n.has(r)?t.delete(e):n.add(r)}t=t.left}},qo=e=>{let t=0;return K(e.doc,n=>{let r=e._start,i=e._start,a=P(),o=Xt(a);for(;i;){if(i.deleted===!1)switch(i.content.constructor){case Z:Bo(o,i.content);break;default:t+=Go(n,r,i,a,o),a=Xt(o),r=i}i=i.right}}),t},Jo=e=>{let t=new Set,n=e.doc;for(let[r,i]of e.afterState.entries()){let a=e.beforeState.get(r)||0;i!==a&&Na(e,n.store.clients.get(r),a,i,e=>{!e.deleted&&e.content.constructor===Z&&e.constructor!==X&&t.add(e.parent)})}K(n,n=>{Ai(e,e.deleteSet,e=>{if(e instanceof X||!e.parent._hasFormatting||t.has(e.parent))return;let r=e.parent;e.content.constructor===Z?t.add(r):Ko(n,e)});for(let e of t)qo(e)})},Yo=(e,t,n)=>{let r=n,i=Xt(t.currentAttributes),a=t.right;for(;n>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case Is:case vs:case Es:n<t.right.length&&Aa(e,U(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e)}t.forward()}a&&Go(e,a,t.right,i,t.currentAttributes);let o=(t.left||t.right).parent;return o._searchMarker&&lo(o._searchMarker,t.index,-r+n),t},Xo=class extends eo{constructor(e,t,n){super(e,t),this.childListChanged=!1,this.keysChanged=new Set,n.forEach(e=>{e===null?this.childListChanged=!0:this.keysChanged.add(e)})}get changes(){if(this._changes===null){let e={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=e}return this._changes}get delta(){if(this._delta===null){let e=this.target.doc,t=[];K(e,e=>{let n=new Map,r=new Map,i=this.target._start,a=null,o={},s=``,c=0,l=0,u=()=>{if(a!==null){let e=null;switch(a){case`delete`:l>0&&(e={delete:l}),l=0;break;case`insert`:(typeof s==`object`||s.length>0)&&(e={insert:s},n.size>0&&(e.attributes={},n.forEach((t,n)=>{t!==null&&(e.attributes[n]=t)}))),s=``;break;case`retain`:c>0&&(e={retain:c},un(o)||(e.attributes=an({},o))),c=0}e&&t.push(e),a=null}};for(;i!==null;){switch(i.content.constructor){case Is:case vs:this.adds(i)?this.deletes(i)||(u(),a=`insert`,s=i.content.getContent()[0],u()):this.deletes(i)?(a!==`delete`&&(u(),a=`delete`),l+=1):i.deleted||(a!==`retain`&&(u(),a=`retain`),c+=1);break;case Es:this.adds(i)?this.deletes(i)||(a!==`insert`&&(u(),a=`insert`),s+=i.content.str):this.deletes(i)?(a!==`delete`&&(u(),a=`delete`),l+=i.length):i.deleted||(a!==`retain`&&(u(),a=`retain`),c+=i.length);break;case Z:{let{key:t,value:s}=i.content;if(this.adds(i))this.deletes(i)||(Y(n.get(t)??null,s)?s!==null&&i.delete(e):(a===`retain`&&u(),Y(s,r.get(t)??null)?delete o[t]:o[t]=s));else if(this.deletes(i)){r.set(t,s);let e=n.get(t)??null;Y(e,s)||(a===`retain`&&u(),o[t]=e)}else if(!i.deleted){r.set(t,s);let n=o[t];n!==void 0&&(Y(n,s)?n!==null&&i.delete(e):(a===`retain`&&u(),s===null?delete o[t]:o[t]=s))}i.deleted||(a===`insert`&&u(),Bo(n,i.content));break}}i=i.right}for(u();t.length>0;){let e=t[t.length-1];if(e.retain!==void 0&&e.attributes===void 0)t.pop();else break}}),this._delta=t}return this._delta}},Zo=class e extends J{constructor(e){super(),this._pending=e===void 0?[]:[()=>this.insert(0,e)],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??q(),this._length}_integrate(e,t){super._integrate(e,t);try{this._pending.forEach(e=>e())}catch(e){console.error(e)}this._pending=null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}_callObserver(e,t){super._callObserver(e,t);let n=new Xo(this,e,t);uo(this,e,n),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??q();let e=``,t=this._start;for(;t!==null;)!t.deleted&&t.countable&&t.content.constructor===Es&&(e+=t.content.str),t=t.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:t=!0}={}){this.doc===null?this._pending.push(()=>this.applyDelta(e)):K(this.doc,n=>{let r=new Io(null,this._start,0,new Map);for(let i=0;i<e.length;i++){let a=e[i];if(a.insert!==void 0){let o=!t&&typeof a.insert==`string`&&i===e.length-1&&r.right===null&&a.insert.slice(-1)===`
|
|
4
|
+
`?a.insert.slice(0,-1):a.insert;(typeof o!=`string`||o.length>0)&&Uo(n,this,r,o,a.attributes||{})}else a.retain===void 0?a.delete!==void 0&&Yo(n,r,a.delete):Wo(n,this,r,a.retain,a.attributes||{})}})}toDelta(e,t,n){this.doc??q();let r=[],i=new Map,a=this.doc,o=``,s=this._start;function c(){if(o.length>0){let e={},t=!1;i.forEach((n,r)=>{t=!0,e[r]=n});let n={insert:o};t&&(n.attributes=e),r.push(n),o=``}}let l=()=>{for(;s!==null;){if(Ca(s,e)||t!==void 0&&Ca(s,t))switch(s.content.constructor){case Es:{let r=i.get(`ychange`);e!==void 0&&!Ca(s,e)?(r===void 0||r.user!==s.id.client||r.type!==`removed`)&&(c(),i.set(`ychange`,n?n(`removed`,s.id):{type:`removed`})):t!==void 0&&!Ca(s,t)?(r===void 0||r.user!==s.id.client||r.type!==`added`)&&(c(),i.set(`ychange`,n?n(`added`,s.id):{type:`added`})):r!==void 0&&(c(),i.delete(`ychange`)),o+=s.content.str;break}case Is:case vs:{c();let e={insert:s.content.getContent()[0]};if(i.size>0){let t={};e.attributes=t,i.forEach((e,n)=>{t[n]=e})}r.push(e);break}case Z:Ca(s,e)&&(c(),Bo(i,s.content))}s=s.right}c()};return e||t?K(a,n=>{e&&wa(n,e),t&&wa(n,t),l()},`cleanup`):l(),r}insert(e,t,n){if(t.length<=0)return;let r=this.doc;r===null?this._pending.push(()=>this.insert(e,t,n)):K(r,r=>{let i=Ro(r,this,e,!n);n||(n={},i.currentAttributes.forEach((e,t)=>{n[t]=e})),Uo(r,this,i,t,n)})}insertEmbed(e,t,n){let r=this.doc;r===null?this._pending.push(()=>this.insertEmbed(e,t,n||{})):K(r,r=>{let i=Ro(r,this,e,!n);Uo(r,this,i,t,n||{})})}delete(e,t){if(t===0)return;let n=this.doc;n===null?this._pending.push(()=>this.delete(e,t)):K(n,n=>{Yo(n,Ro(n,this,e,!0),t)})}format(e,t,n){if(t===0)return;let r=this.doc;r===null?this._pending.push(()=>this.format(e,t,n)):K(r,r=>{let i=Ro(r,this,e,!1);i.right!==null&&Wo(r,this,i,t,n)})}removeAttribute(e){this.doc===null?this._pending.push(()=>this.removeAttribute(e)):K(this.doc,t=>{Co(t,this,e)})}setAttribute(e,t){this.doc===null?this._pending.push(()=>this.setAttribute(e,t)):K(this.doc,n=>{wo(n,this,e,t)})}getAttribute(e){return To(this,e)}getAttributes(){return Eo(this)}_write(e){e.writeTypeRef(js)}},Qo=e=>new Zo,$o=class{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??q()}[Symbol.iterator](){return this}next(){let e=this._currentNode,t=e&&e.content&&e.content.type;if(e!==null&&(!this._firstCall||e.deleted||!this._filter(t)))do if(t=e.content.type,!e.deleted&&(t.constructor===ns||t.constructor===es)&&t._start!==null)e=t._start;else for(;e!==null;){let t=e.next;if(t!==null){e=t;break}e=e.parent===this._root?null:e.parent._item}while(e!==null&&(e.deleted||!this._filter(e.content.type)));return this._firstCall=!1,e===null?{value:void 0,done:!0}:(this._currentNode=e,{value:e.content.type,done:!1})}},es=class e extends J{constructor(){super(),this._prelimContent=[]}get firstChild(){let e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(e=>e instanceof J?e.clone():e)),t}get length(){return this.doc??q(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new $o(this,e)}querySelector(e){e=e.toUpperCase();let t=new $o(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e).next();return t.done?null:t.value}querySelectorAll(e){return e=e.toUpperCase(),_(new $o(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){uo(this,e,new is(this,t,e))}toString(){return ho(this,e=>e.toString()).join(``)}toJSON(){return this.toString()}toDOM(e=document,t={},n){let r=e.createDocumentFragment();return n!==void 0&&n._createAssociation(r,this),mo(this,i=>{r.insertBefore(i.toDOM(e,t,n),null)}),r}insert(e,t){this.doc===null?this._prelimContent.splice(e,0,...t):K(this.doc,n=>{bo(n,this,e,t)})}insertAfter(e,t){if(this.doc!==null)K(this.doc,n=>{let r=e&&e instanceof J?e._item:e;vo(n,this,r,t)});else{let n=this._prelimContent,r=e===null?0:n.findIndex(t=>t===e)+1;if(r===0&&e!==null)throw v(`Reference item not found`);n.splice(r,0,...t)}}delete(e,t=1){this.doc===null?this._prelimContent.splice(e,t):K(this.doc,n=>{So(n,this,e,t)})}toArray(){return po(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return _o(this,e)}slice(e=0,t=this.length){return fo(this,e,t)}forEach(e){mo(this,e)}_write(e){e.writeTypeRef(Ns)}},ts=e=>new es,ns=class e extends es{constructor(e=`UNDEFINED`){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,t){super._integrate(e,t),this._prelimAttrs.forEach((e,t)=>{this.setAttribute(t,e)}),this._prelimAttrs=null}_copy(){return new e(this.nodeName)}clone(){let t=new e(this.nodeName);return sn(this.getAttributes(),(e,n)=>{t.setAttribute(n,e)}),t.insert(0,this.toArray().map(e=>e instanceof J?e.clone():e)),t}toString(){let e=this.getAttributes(),t=[],n=[];for(let t in e)n.push(t);n.sort();let r=n.length;for(let i=0;i<r;i++){let r=n[i];t.push(r+`="`+e[r]+`"`)}let i=this.nodeName.toLocaleLowerCase();return`<${i}${t.length>0?` `+t.join(` `):``}>${super.toString()}</${i}>`}removeAttribute(e){this.doc===null?this._prelimAttrs.delete(e):K(this.doc,t=>{Co(t,this,e)})}setAttribute(e,t){this.doc===null?this._prelimAttrs.set(e,t):K(this.doc,n=>{wo(n,this,e,t)})}getAttribute(e){return To(this,e)}hasAttribute(e){return Do(this,e)}getAttributes(e){return e?Oo(this,e):Eo(this)}toDOM(e=document,t={},n){let r=e.createElement(this.nodeName),i=this.getAttributes();for(let e in i){let t=i[e];typeof t==`string`&&r.setAttribute(e,t)}return mo(this,i=>{r.appendChild(i.toDOM(e,t,n))}),n!==void 0&&n._createAssociation(r,this),r}_write(e){e.writeTypeRef(Ms),e.writeKey(this.nodeName)}},rs=e=>new ns(e.readKey()),is=class extends eo{constructor(e,t,n){super(e,n),this.childListChanged=!1,this.attributesChanged=new Set,t.forEach(e=>{e===null?this.childListChanged=!0:this.attributesChanged.add(e)})}},as=class e extends Po{constructor(e){super(),this.hookName=e}_copy(){return new e(this.hookName)}clone(){let t=new e(this.hookName);return this.forEach((e,n)=>{t.set(n,e)}),t}toDOM(e=document,t={},n){let r=t[this.hookName],i;return i=r===void 0?document.createElement(this.hookName):r.createDom(this),i.setAttribute(`data-yjs-hook`,this.hookName),n!==void 0&&n._createAssociation(i,this),i}_write(e){e.writeTypeRef(Ps),e.writeKey(this.hookName)}},os=e=>new as(e.readKey()),ss=class e extends Zo{get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}toDOM(e=document,t,n){let r=e.createTextNode(this.toString());return n!==void 0&&n._createAssociation(r,this),r}toString(){return this.toDelta().map(e=>{let t=[];for(let n in e.attributes){let r=[];for(let t in e.attributes[n])r.push({key:t,value:e.attributes[n][t]});r.sort((e,t)=>e.key<t.key?-1:1),t.push({nodeName:n,attrs:r})}t.sort((e,t)=>e.nodeName<t.nodeName?-1:1);let n=``;for(let e=0;e<t.length;e++){let r=t[e];n+=`<${r.nodeName}`;for(let e=0;e<r.attrs.length;e++){let t=r.attrs[e];n+=` ${t.key}="${t.value}"`}n+=`>`}n+=e.insert;for(let e=t.length-1;e>=0;e--)n+=`</${t[e].nodeName}>`;return n}).join(``)}toJSON(){return this.toString()}_write(e){e.writeTypeRef(Fs)}},cs=e=>new ss,ls=class{constructor(e,t){this.id=e,this.length=t}get deleted(){throw y()}mergeWith(e){return!1}write(e,t,n){throw y()}integrate(e,t){throw y()}},us=0,X=class extends ls{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,!0)}integrate(e,t){t>0&&(this.id.clock+=t,this.length-=t),Da(e.doc.store,this)}write(e,t){e.writeInfo(us),e.writeLen(this.length-t)}getMissing(e,t){return null}},ds=class e{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new e(this.content)}splice(e){throw y()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}},fs=e=>new ds(e.readBuf()),ps=class e{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.len)}splice(t){let n=new e(this.len-t);return this.len=t,n}mergeWith(e){return this.len+=e.len,!0}integrate(e,t){Fi(e.deleteSet,t.id.client,t.id.clock,this.len),t.markDeleted()}delete(e){}gc(e){}write(e,t){e.writeLen(this.len-t)}getRef(){return 1}},ms=e=>new ps(e.readLen()),hs=(e,t)=>new Hi({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1}),gs=class e{constructor(e){e._item&&console.error(`This document was already integrated as a sub-document. You should create a second instance instead with the same guid.`),this.doc=e;let t={};this.opts=t,e.gc||(t.gc=!1),e.autoLoad&&(t.autoLoad=!0),e.meta!==null&&(t.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new e(hs(this.doc.guid,this.opts))}splice(e){throw y()}mergeWith(e){return!1}integrate(e,t){this.doc._item=t,e.subdocsAdded.add(this.doc),this.doc.shouldLoad&&e.subdocsLoaded.add(this.doc)}delete(e){e.subdocsAdded.has(this.doc)?e.subdocsAdded.delete(this.doc):e.subdocsRemoved.add(this.doc)}gc(e){}write(e,t){e.writeString(this.doc.guid),e.writeAny(this.opts)}getRef(){return 9}},_s=e=>new gs(hs(e.readString(),e.readAny())),vs=class e{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new e(this.embed)}splice(e){throw y()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}},ys=e=>new vs(e.readJSON()),Z=class e{constructor(e,t){this.key=e,this.value=t}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.key,this.value)}splice(e){throw y()}mergeWith(e){return!1}integrate(e,t){let n=t.parent;n._searchMarker=null,n._hasFormatting=!0}delete(e){}gc(e){}write(e,t){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}},bs=e=>new Z(e.readKey(),e.readJSON()),xs=class e{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new e(this.arr)}splice(t){let n=new e(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){let n=this.arr.length;e.writeLen(n-t);for(let r=t;r<n;r++){let t=this.arr[r];e.writeString(t===void 0?`undefined`:JSON.stringify(t))}}getRef(){return 2}},Ss=e=>{let t=e.readLen(),n=[];for(let r=0;r<t;r++){let t=e.readString();t===`undefined`?n.push(void 0):n.push(JSON.parse(t))}return new xs(n)},Cs=Fn(`node_env`)===`development`,ws=class e{constructor(e){this.arr=e,Cs&&hn(e)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new e(this.arr)}splice(t){let n=new e(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){let n=this.arr.length;e.writeLen(n-t);for(let r=t;r<n;r++){let t=this.arr[r];e.writeAny(t)}}getRef(){return 8}},Ts=e=>{let t=e.readLen(),n=[];for(let r=0;r<t;r++)n.push(e.readAny());return new ws(n)},Es=class e{constructor(e){this.str=e}getLength(){return this.str.length}getContent(){return this.str.split(``)}isCountable(){return!0}copy(){return new e(this.str)}splice(t){let n=new e(this.str.slice(t));this.str=this.str.slice(0,t);let r=this.str.charCodeAt(t-1);return r>=55296&&r<=56319&&(this.str=this.str.slice(0,t-1)+`�`,n.str=`�`+n.str.slice(1)),n}mergeWith(e){return this.str+=e.str,!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeString(t===0?this.str:this.str.slice(t))}getRef(){return 4}},Ds=e=>new Es(e.readString()),Os=[Mo,Fo,Qo,rs,ts,os,cs],ks=0,As=1,js=2,Ms=3,Ns=4,Ps=5,Fs=6,Is=class e{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new e(this.type._copy())}splice(e){throw y()}mergeWith(e){return!1}integrate(e,t){this.type._integrate(e.doc,t)}delete(e){let t=this.type._start;for(;t!==null;)t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e),t=t.right;this.type._map.forEach(t=>{t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e)}),e.changed.delete(this.type)}gc(e){let t=this.type._start;for(;t!==null;)t.gc(e,!0),t=t.right;this.type._start=null,this.type._map.forEach(t=>{for(;t!==null;)t.gc(e,!0),t=t.left}),this.type._map=new Map}write(e,t){this.type._write(e)}getRef(){return 7}},Ls=e=>new Is(Os[e.readTypeRef()](e)),Rs=(e,t,n)=>{let{client:r,clock:i}=t.id,a=new Q(U(r,i+n),t,U(r,i+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&a.markDeleted(),t.keep&&(a.keep=!0),t.redone!==null&&(a.redone=U(t.redone.client,t.redone.clock+n)),t.right=a,a.right!==null&&(a.right.left=a),e._mergeStructs.push(a),a.parentSub!==null&&a.right===null&&a.parent._map.set(a.parentSub,a),t.length=n,a},Q=class e extends ls{constructor(e,t,n,r,i,a,o,s){super(e,s.getLength()),this.origin=n,this.left=t,this.right=r,this.rightOrigin=i,this.parent=a,this.parentSub=o,this.redone=null,this.content=s,this.info=this.content.isCountable()?2:0}set marker(e){(this.info&8)>0!==e&&(this.info^=8)}get marker(){return(this.info&8)>0}get keep(){return(this.info&1)>0}set keep(e){this.keep!==e&&(this.info^=1)}get countable(){return(this.info&2)>0}get deleted(){return(this.info&4)>0}set deleted(e){this.deleted!==e&&(this.info^=4)}markDeleted(){this.info|=4}getMissing(t,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=W(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=W(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===ya&&this.id.client!==this.parent.client&&this.parent.clock>=W(n,this.parent.client))return this.parent.client;if(this.origin&&=(this.left=ja(t,n,this.origin),this.left.lastId),this.rightOrigin&&=(this.right=Aa(t,this.rightOrigin),this.right.id),this.left&&this.left.constructor===X||this.right&&this.right.constructor===X)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===e?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===e&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===ya){let e=Oa(n,this.parent);this.parent=e.constructor===X?null:e.content.type}return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=ja(e,e.doc.store,U(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(t),this.length-=t),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let t=this.left,n;if(t!==null)n=t.right;else if(this.parentSub!==null)for(n=this.parent._map.get(this.parentSub)||null;n!==null&&n.left!==null;)n=n.left;else n=this.parent._start;let r=new Set,i=new Set;for(;n!==null&&n!==this.right;){if(i.add(n),r.add(n),ba(this.origin,n.origin)){if(n.id.client<this.id.client)t=n,r.clear();else if(ba(this.rightOrigin,n.rightOrigin))break}else if(n.origin!==null&&i.has(Oa(e.doc.store,n.origin)))r.has(Oa(e.doc.store,n.origin))||(t=n,r.clear());else break;n=n.right}this.left=t}if(this.left!==null){let e=this.left.right;this.right=e,this.left.right=this}else{let e;if(this.parentSub!==null)for(e=this.parent._map.get(this.parentSub)||null;e!==null&&e.left!==null;)e=e.left;else e=this.parent._start,this.parent._start=this;this.right=e}this.right===null?this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(e)):this.right.left=this,this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),Da(e.doc.store,this),this.content.integrate(e,this),Ia(e,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(e)}else new X(this.id,this.length).integrate(e,0)}get next(){let e=this.right;for(;e!==null&&e.deleted;)e=e.right;return e}get prev(){let e=this.left;for(;e!==null&&e.deleted;)e=e.left;return e}get lastId(){return this.length===1?this.id:U(this.id.client,this.id.clock+this.length-1)}mergeWith(e){if(this.constructor===e.constructor&&ba(e.origin,this.lastId)&&this.right===e&&ba(this.rightOrigin,e.rightOrigin)&&this.id.client===e.id.client&&this.id.clock+this.length===e.id.clock&&this.deleted===e.deleted&&this.redone===null&&e.redone===null&&this.content.constructor===e.content.constructor&&this.content.mergeWith(e.content)){let t=this.parent._searchMarker;return t&&t.forEach(t=>{t.p===e&&(t.p=this,!this.deleted&&this.countable&&(t.index-=this.length))}),e.keep&&(this.keep=!0),this.right=e.right,this.right!==null&&(this.right.left=this),this.length+=e.length,!0}return!1}delete(e){if(!this.deleted){let t=this.parent;this.countable&&this.parentSub===null&&(t._length-=this.length),this.markDeleted(),Fi(e.deleteSet,this.id.client,this.id.clock,this.length),Ia(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw b();this.content.gc(e),t?Ma(e,this,new X(this.id,this.length)):this.content=new ps(this.length)}write(e,t){let n=t>0?U(this.id.client,this.id.clock+t-1):this.origin,r=this.rightOrigin,i=this.parentSub,a=this.content.getRef()&31|(n===null?0:128)|(r===null?0:64)|(i===null?0:32);if(e.writeInfo(a),n!==null&&e.writeLeftID(n),r!==null&&e.writeRightID(r),n===null&&r===null){let t=this.parent;if(t._item!==void 0){let n=t._item;if(n===null){let n=xa(t);e.writeParentInfo(!0),e.writeString(n)}else e.writeParentInfo(!1),e.writeLeftID(n.id)}else t.constructor===String?(e.writeParentInfo(!0),e.writeString(t)):t.constructor===ya?(e.writeParentInfo(!1),e.writeLeftID(t)):b();i!==null&&e.writeString(i)}this.content.write(e,t)}},zs=(e,t)=>Bs[t&31](e),Bs=[()=>{b()},ms,Ss,fs,Ds,ys,bs,Ls,Ts,_s,()=>{b()}],Vs=10,$=class extends ls{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,!0)}integrate(e,t){b()}write(e,t){e.writeInfo(Vs),w(e.restEncoder,this.length-t)}getMissing(e,t){return null}},Hs=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:{},Us=`__ $YJS$ __`;Hs[Us]===!0&&console.error(`Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438`),Hs[Us]=!0;var Ws=3e4,Gs=class extends en{constructor(e){super(),this.doc=e,this.clientID=e.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{let e=M();this.getLocalState()!==null&&15e3<=e-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());let t=[];this.meta.forEach((n,r)=>{r!==this.clientID&&3e4<=e-n.lastUpdated&&this.states.has(r)&&t.push(r)}),t.length>0&&Ks(this,t,`timeout`)},g(Ws/10)),e.on(`destroy`,()=>{this.destroy()}),this.setLocalState({})}destroy(){this.emit(`destroy`,[this]),this.setLocalState(null),super.destroy(),clearInterval(this._checkInterval)}getLocalState(){return this.states.get(this.clientID)||null}setLocalState(e){let t=this.clientID,n=this.meta.get(t),r=n===void 0?0:n.clock+1,i=this.states.get(t);e===null?this.states.delete(t):this.states.set(t,e),this.meta.set(t,{clock:r,lastUpdated:M()});let a=[],o=[],s=[],c=[];e===null?c.push(t):i==null?e!=null&&a.push(t):(o.push(t),vn(i,e)||s.push(t)),(a.length>0||s.length>0||c.length>0)&&this.emit(`change`,[{added:a,updated:s,removed:c},`local`]),this.emit(`update`,[{added:a,updated:o,removed:c},`local`])}setLocalStateField(e,t){let n=this.getLocalState();n!==null&&this.setLocalState({...n,[e]:t})}getStates(){return this.states}},Ks=(e,t,n)=>{let r=[];for(let n=0;n<t.length;n++){let i=t[n];if(e.states.has(i)){if(e.states.delete(i),i===e.clientID){let t=e.meta.get(i);e.meta.set(i,{clock:t.clock+1,lastUpdated:M()})}r.push(i)}}r.length>0&&(e.emit(`change`,[{added:[],updated:[],removed:r},n]),e.emit(`update`,[{added:[],updated:[],removed:r},n]))},qs=(e,t,n=e.states)=>{let r=t.length,i=x();w(i,r);for(let a=0;a<r;a++){let r=t[a],o=n.get(r)||null,s=e.meta.get(r).clock;w(i,r),w(i,s),T(i,JSON.stringify(o))}return S(i)},Js=(e,t,n)=>{let r=D(t),i=M(),a=[],o=[],s=[],c=[],l=k(r);for(let t=0;t<l;t++){let t=k(r),n=k(r),l=JSON.parse(A(r)),u=e.meta.get(t),d=e.states.get(t),f=u===void 0?0:u.clock;(f<n||f===n&&l===null&&e.states.has(t))&&(l===null?t===e.clientID&&e.getLocalState()!=null?n++:e.states.delete(t):e.states.set(t,l),e.meta.set(t,{clock:n,lastUpdated:i}),u===void 0&&l!==null?a.push(t):u!==void 0&&l===null?c.push(t):l!==null&&(vn(l,d)||s.push(t),o.push(t)))}(a.length>0||s.length>0||c.length>0)&&e.emit(`change`,[{added:a,updated:s,removed:c},n]),(a.length>0||o.length>0||c.length>0)&&e.emit(`update`,[{added:a,updated:o,removed:c},n])},Ys=new Map,Xs=class{constructor(e){this.room=e,this.onmessage=null,this._onChange=t=>t.key===e&&this.onmessage!==null&&this.onmessage({data:Kn(t.newValue||``)}),kn(this._onChange)}postMessage(e){On.setItem(this.room,Gn(Bn(e)))}close(){An(this._onChange)}},Zs=typeof BroadcastChannel>`u`?Xs:BroadcastChannel,Qs=e=>F(Ys,e,()=>{let t=Ce(),n=new Zs(e);return n.onmessage=e=>t.forEach(t=>t(e.data,`broadcastchannel`)),{bc:n,subs:t}}),$s=(e,t)=>(Qs(e).subs.add(t),t),ec=(e,t)=>{let n=Qs(e),r=n.subs.delete(t);return r&&n.subs.size===0&&(n.bc.close(),Ys.delete(e)),r},tc=(e,t,n=null)=>{let r=Qs(e);r.bc.postMessage(t),r.subs.forEach(e=>e(t,n))},nc=(e,t)=>{w(e,0),E(e,pa(t))},rc=(e,t,n)=>{w(e,1),E(e,sa(t,n))},ic=(e,t,n)=>rc(t,n,O(e)),ac=(e,t,n,r)=>{try{ia(t,O(e),n)}catch(e){r?.(e),console.error(`Caught error while handling a Yjs update`,e)}},oc=(e,t)=>{w(e,2),E(e,t)},sc=ac,cc=(e,t,n,r,i)=>{let a=k(e);switch(a){case 0:ic(e,t,n);break;case 1:ac(e,n,r,i);break;case 2:sc(e,n,r,i);break;default:throw Error(`Unknown message type`)}return a},lc=(e,t,n)=>{k(e)===0&&n(t,A(e))},uc=e=>cn(e,(e,t)=>`${encodeURIComponent(t)}=${encodeURIComponent(e)}`).join(`&`),dc=[];dc[0]=(e,t,n,r,i)=>{w(e,0);let a=cc(t,e,n.doc,n);r&&a===1&&!n.synced&&(n.synced=!0)},dc[3]=(e,t,n,r,i)=>{w(e,1),E(e,qs(n.awareness,Array.from(n.awareness.getStates().keys())))},dc[1]=(e,t,n,r,i)=>{Js(n.awareness,O(t),n)},dc[2]=(e,t,n,r,i)=>{lc(t,n.doc,(e,t)=>pc(n,t))};var fc=3e4,pc=(e,t)=>console.warn(`Permission denied to access ${e.url}.\n${t}`),mc=(e,t,n)=>{let r=D(t),i=x(),a=k(r),o=e.messageHandlers[a];return o?o(i,r,e,n,a):console.error(`Unable to compute message`),i},hc=e=>!(e.code>=4400&&e.code<4500),gc=(e,t,n)=>{if(t!==null&&t===e.ws){e.emit(`connection-close`,[n,e]),e.ws=null,t.onmessage=null,t.onopen=null,t.onclose=null,t.onerror=()=>{},t.close(),e.wsconnecting=!1,e.wsconnected&&(e.wsconnected=!1,e.synced=!1,Ks(e.awareness,Array.from(e.awareness.getStates().keys()).filter(t=>t!==e.doc.clientID),e),e.emit(`status`,[{status:`disconnected`}])),e.wsUnsuccessfulReconnects++;let r=null;n!=null&&!e.shouldReconnect(n,e)&&(e.shouldConnect=!1,r={code:n.code,reason:n.reason}),setTimeout(_c,ge(ve(2,e.wsUnsuccessfulReconnects)*100,e.maxBackoffTime),e),r!==null&&e.emit(`closed`,[r,e])}},_c=e=>{if(e.shouldConnect&&e.ws===null){let t=new e._WS(e.url,e.protocols);t.binaryType=`arraybuffer`,e.ws=t,e.wsconnecting=!0,e.wsconnected=!1,e.synced=!1,t.onmessage=n=>{if(e.ws!==t)return;e.wsLastMessageReceived=M();let r=mc(e,new Uint8Array(n.data),!0);He(r)>1&&t.send(S(r))},t.onerror=n=>{e.ws===t&&e.emit(`connection-error`,[n,e])},t.onclose=n=>{gc(e,t,n)},t.onopen=()=>{if(e.ws!==t)return;e.wsLastMessageReceived=M(),e.wsconnecting=!1,e.wsconnected=!0,e.emit(`status`,[{status:`connected`}]);let n=x();if(w(n,0),nc(n,e.doc),t.send(S(n)),e.awareness.getLocalState()!==null){let n=x();w(n,1),E(n,qs(e.awareness,[e.doc.clientID])),t.send(S(n))}},e.emit(`status`,[{status:`connecting`}])}},vc=(e,t)=>{let n=e.ws;e.wsconnected&&n&&n.readyState===n.OPEN&&n.send(t),e.bcconnected&&tc(e.bcChannel,t,e)},yc=class extends $t{constructor(e,t,n,{connect:r=!0,awareness:i=new Gs(n),params:a={},protocols:o=[],WebSocketPolyfill:s=WebSocket,resyncInterval:c=-1,maxBackoffTime:l=2500,disableBc:u=!1,shouldReconnect:d=hc}={}){for(super();e[e.length-1]===`/`;)e=e.slice(0,e.length-1);this.serverUrl=e,this.bcChannel=e+`/`+t,this.maxBackoffTime=l,this.shouldReconnect=d,this.params=a,this.protocols=o,this.roomname=t,this.doc=n,this._WS=s,this.awareness=i,this.wsconnected=!1,this.wsconnecting=!1,this.bcconnected=!1,this.disableBc=u,this.wsUnsuccessfulReconnects=0,this.messageHandlers=dc.slice(),this._synced=!1,this.ws=null,this.wsLastMessageReceived=0,this.shouldConnect=r,this._resyncInterval=0,c>0&&(this._resyncInterval=setInterval(()=>{if(this.ws&&this.ws.readyState===WebSocket.OPEN){let e=x();w(e,0),nc(e,n),this.ws.send(S(e))}},c)),this._bcSubscriber=(e,t)=>{if(t!==this){let t=mc(this,new Uint8Array(e),!1);He(t)>1&&tc(this.bcChannel,S(t),this)}},this._updateHandler=(e,t)=>{if(t!==this){let t=x();w(t,0),oc(t,e),vc(this,S(t))}},this.doc.on(`update`,this._updateHandler),this._awarenessUpdateHandler=({added:e,updated:t,removed:n},r)=>{let a=e.concat(t).concat(n),o=x();w(o,1),E(o,qs(i,a)),vc(this,S(o))},this._exitHandler=()=>{Ks(this.awareness,[n.clientID],`app closed`)},I&&typeof process<`u`&&process.on(`exit`,this._exitHandler),i.on(`update`,this._awarenessUpdateHandler),this._checkInterval=setInterval(()=>{this.wsconnected&&fc<M()-this.wsLastMessageReceived&&gc(this,this.ws,null)},fc/10),r&&this.connect()}get url(){let e=uc(this.params);return this.serverUrl+`/`+this.roomname+(e.length===0?``:`?`+e)}get synced(){return this._synced}set synced(e){this._synced!==e&&(this._synced=e,e&&(this.wsUnsuccessfulReconnects=0),this.emit(`synced`,[e]),this.emit(`sync`,[e]))}destroy(){this._resyncInterval!==0&&clearInterval(this._resyncInterval),clearInterval(this._checkInterval),this.disconnect(),I&&typeof process<`u`&&process.off(`exit`,this._exitHandler),this.awareness.off(`update`,this._awarenessUpdateHandler),this.doc.off(`update`,this._updateHandler),super.destroy()}connectBc(){if(this.disableBc)return;this.bcconnected||=($s(this.bcChannel,this._bcSubscriber),!0);let e=x();w(e,0),nc(e,this.doc),tc(this.bcChannel,S(e),this);let t=x();w(t,0),rc(t,this.doc),tc(this.bcChannel,S(t),this);let n=x();w(n,3),tc(this.bcChannel,S(n),this);let r=x();w(r,1),E(r,qs(this.awareness,[this.doc.clientID])),tc(this.bcChannel,S(r),this)}disconnectBc(){let e=x();w(e,1),E(e,qs(this.awareness,[this.doc.clientID],new Map)),vc(this,S(e)),this.bcconnected&&=(ec(this.bcChannel,this._bcSubscriber),!1)}disconnect(){this.shouldConnect=!1,this.disconnectBc(),this.ws!==null&&gc(this,this.ws,null)}connect(){this.shouldConnect=!0,!this.wsconnected&&this.ws===null&&(_c(this),this.connectBc())}},bc=1047552;function xc(e,t,n={}){let r=new Set,i=new Set,a=new Set,o=[],s,c=`connecting`,l=!1,u=!1,d,f,ee=()=>{for(let e of r)e()},te=()=>{let t=n.origin?new URL(n.origin):window.location;return`${t.protocol===`https:`?`wss:`:`ws:`}//${t.host}${zt(`/_vitehub/realtime/${encodeURIComponent(e)}`,n.baseURL)}`},ne=t.split(`/`).map(encodeURIComponent).join(`/`),re={};function p(){l=!1,d=new Hi,f=new yc(te(),ne,d,{disableBc:!0,params:{...n.params,clientId:String(d.clientID)}});let e=f;Vt(e),e.messageHandlers[5]=(t,n)=>{let r=Mt(n);r&&(r.type===`session`?e.params.epoch=r.epoch:(e.destroy(),d.destroy(),u||(p(),ee())))},e.messageHandlers[6]=(t,n)=>{let r=Lt(n);if(r?.kind===`request`&&h(e,r.id,r.body),r?.kind===`notice`)for(let e of a)e(r.body)},e.awareness.off(`update`,e._awarenessUpdateHandler),e.awareness.on(`update`,({added:t,removed:n,updated:r})=>{let i=[...t,...r,...n].filter(t=>t===e.doc.clientID),a=e.ws;if(!i.length||!e.wsconnected||!a||a.readyState!==a.OPEN)return;let o=x();w(o,1),E(o,qs(e.awareness,i)),a.send(S(o))});let t=n.identity??{id:`guest:${d.clientID}`};Ht(e),e.awareness.setLocalState({...re,user:qt({...t,id:t.id||`guest:${d.clientID}`})}),e.awareness.on(`change`,ee),d.getMap(Ut.status).observe(ee),e.on(`sync`,t=>{f===e&&(l=t,ee())}),e.on(`status`,e=>{c=e.status,ee()})}p();let m;n.changes&&(m=new yc(te(),encodeURIComponent(At),new Hi,{disableBc:!0,params:{...n.params,workspace:`events`}}),m.awareness.setLocalState(null),Vt(m),m.messageHandlers[4]=(e,t)=>{let n=Pt(t);if(n)for(let e of i)e(n)},m.on(`status`,e=>{e.status===`connected`&&ie()}));async function h(e,t,n){let r=e=>It({kind:`answer`,id:t,ok:!1,why:e}),i;try{i=s?It({kind:`answer`,id:t,ok:!0,body:await s(n)}):r(`This page does not answer requests.`),i.byteLength>bc&&(i=r(`The answer has ${i.byteLength} bytes, over the 1 MiB limit.`))}catch(e){i=r(e instanceof Error?e.message:String(e))}let a=e.ws;e.wsconnected&&a&&a.readyState===a.OPEN&&a.send(Uint8Array.from(i))}function ie(){let e=m?.ws;if(m?.wsconnected&&e&&e.readyState===e.OPEN)for(;o.length;)e.send(Uint8Array.from(Ft(o.shift())))}return{get awareness(){return f.awareness},get clientId(){return d.clientID},people:()=>Yt(f.awareness.getStates()),states:()=>{let e=new Map(f.awareness.getStates());return e.delete(d.clientID),e},status:()=>c,saveStatus:()=>l?Gt(d):void 0,setLocal(e,t){if(t!==null){re[e]=t,f.awareness.setLocalStateField(e,t);return}delete re[e];let n=f.awareness.getLocalState();if(!n||!Object.hasOwn(n,e))return;let{[e]:r,...i}=n;f.awareness.setLocalState(i)},notify(e){m&&(o.push(e),ie())},onUpdate(e){return r.add(e),()=>r.delete(e)},onChange(e){return i.add(e),()=>i.delete(e)},onRequest(e){return s=e,()=>{s===e&&(s=void 0)}},onNotice(e){return a.add(e),()=>a.delete(e)},destroy(){u=!0,f.destroy(),d.destroy(),m?.destroy(),m?.doc.destroy(),r.clear(),i.clear(),a.clear(),s=void 0}}}export{xc as connectRealtimeRoom};
|