@vite-hub/comments 0.8.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/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.d.ts +2 -2
- package/dist/client.js +2 -5
- package/dist/database.js +1 -1
- package/dist/{define-C-LUOouq.js → define-hs9Z38io.js} +0 -1
- package/dist/hosted/hosted-comments/frame.js +4 -4
- package/dist/hosted/hosted-comments/tools.js +59 -56
- package/dist/{index-d6NsDxu9.d.ts → index-CbXek64X.d.ts} +2 -2
- package/dist/index.d.ts +4 -4
- package/dist/index.js +3 -6
- package/dist/{install-BueV_fJY.js → install--HecUN5c.js} +2 -19
- package/dist/{install-F-_O7zDr.d.ts → install-C3CW6Vvw.d.ts} +4 -4
- package/dist/{migrate-oseJAYbm.js → migrate-cxoJK4JQ.js} +0 -18
- package/dist/{operations-jaihyWw2.d.ts → operations-D0EO1pzL.d.ts} +3 -7
- package/dist/{operations-0llC5kKO.js → operations-DHXmbtb3.js} +3 -30
- package/dist/operations.d.ts +2 -2
- package/dist/operations.js +2 -2
- package/dist/overlay/client-BszZKIf8.js +4 -0
- package/dist/overlay/overlay.js +38 -35
- package/dist/page/loader.js +14 -11
- package/dist/{page-CDhmXO-y.js → page-CJz1K67L.js} +1 -1
- package/dist/{page-BgvzzsJb.d.ts → page-DRM1j84-.d.ts} +1 -1
- package/dist/{path-8yqMd8zR.js → path-sv8kjq3i.js} +0 -4
- package/dist/{plugin-DGUqlc3C.js → plugin-DczA2K-y.js} +3 -3
- package/dist/realtime.d.ts +5 -5
- package/dist/realtime.js +2 -2
- 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 -1
- package/dist/runtime/console.js +2 -2
- package/dist/runtime/index.d.ts +6 -6
- package/dist/runtime/index.js +8 -30
- package/dist/server.d.ts +7 -7
- package/dist/server.js +6 -6
- package/dist/{service-DaMq8TBw.js → service-DFMwCr60.js} +2 -12
- package/dist/{service-CMVA_Ryv.d.ts → service-qaMuJ7UX.d.ts} +2 -2
- package/dist/{session-B7GDrqsK.js → session-1SI3_wLJ.js} +11 -30
- package/dist/{session-EzQqBeE8.d.ts → session-CK3Rnjto.d.ts} +2 -2
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +0 -1
- 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/{types-qzJKgWYS.d.ts → types-VSVs4jIw.d.ts} +1 -1
- package/dist/vite.d.ts +3 -3
- package/dist/vite.js +2 -33
- package/package.json +7 -7
- package/dist/overlay/client-ZBsUybIe.js +0 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var e=Object.defineProperty,t=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(e){throw n=[e],e}},n=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],enumerable:!0});return n||e(r,Symbol.toStringTag,{value:`Module`}),r};function r(e,...t){return typeof e==`function`?e(...t):e}function i(e,t){return typeof e==`string`?`${e}/${t.toLowerCase()}`:e?.(t)}function a(e){let t=e.reporters??[],n=Symbol(),a=Object.defineProperty({},"is",{value:c(n)}),{docsBase:o}=e;for(let c of Object.keys(e.codes)){let l=e.codes[c],u=l.docs===!1?void 0:l.docs||i(o,c),d=(e={},i={})=>{let a=new s({code:c,why:r(l.why,e),fix:r(l.fix,e),docs:u,cause:e.cause,sources:e.sources,data:r(l.data,e)},d);a[n]=1;for(let e of t)e(a,i);return a};d.is=e=>a.is(e)&&e.code===c,a[c]=d}return a}var o,s,c,l=t((()=>{o=Error.captureStackTrace,s=class e extends Error{get why(){return this.message}constructor(t,n=e){super(t.why,{cause:t.cause}),this.code=this.name=t.code,this.docs=t.docs,this.fix=t.fix,this.sources=t.sources,this.data=t.data,o?.(this,n)}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}}},c=e=>t=>t instanceof s&&e in t}));l();var u=a({docsBase:`https://vitehub.dev/docs/comments/diagnostics`,codes:{COMMENTS_HOSTED_CONFLICT:{why:`This page runs the app's own Comments, so the Hosted Comments script does not start its overlay.`,fix:"Remove the Hosted Comments script, or keep it and set `comments: { overlay: false }` to turn off the app's overlay. See https://vitehub.dev/docs/comments/configure#add-hosted-comments"},COMMENTS_OUTBOX_ACCOUNT_CHANGED:{why:`The current author is not the author of this queued comment.`,fix:`Sign in as the original author and retry the outbox.`},COMMENTS_OUTBOX_RESOLVE_BLOCKED:{why:`Queued delivery must resume before the thread can close.`,fix:`Go online, then retry or dismiss any blocked comments and resolve the thread again.`},COMMENTS_OUTBOX_SENDING:{why:`The server may already have this comment, so the draft cannot change.`,fix:`Wait for delivery to finish, then edit or delete the server copy.`},COMMENTS_OVERLAY_ELEMENT_TAKEN:{why:({name:e})=>`Another script defined the <${e}> element, so this Comments overlay cannot start.`,fix:`Load one Comments overlay script on the page. Remove the other script that defines the element.`},COMMENTS_R0001:{why:({target:e})=>`createAnchor() found nothing to anchor to for ${e}.`,fix:`Pass an element, a non-empty selection, or a point that is over an element of the page.`},COMMENTS_R0013:{why:`The comments request did not get an answer from the server.`,fix:`Check the connection and the app URL, then try again.`},COMMENTS_R0015:{why:`The comment list kept changing while its pages were loading.`,fix:`Refresh again. The previous cache is kept until two complete scans agree.`}}});function d(e){let{code:t,details:n,fix:r,retryAfter:i,status:a,why:o}=e,c=t.startsWith(`COMMENTS_`)?`https://vitehub.dev/docs/comments/diagnostics/${t.toLowerCase()}`:void 0;return Object.assign(new s({code:t,why:o,...r?{fix:r}:{},...c?{docs:c}:{}}),{status:a,...n?{details:n}:{},...i===void 0?{}:{retryAfter:i}})}function f(e,t,n){return Object.assign(u.COMMENTS_R0013(t===void 0?{}:{cause:t}),{status:e,...n===void 0?{}:{retryAfter:n}})}var ee=`/_vitehub/comments`,te=`hosted-comments`;function ne(e){return`projects/${encodeURIComponent(e)}`}var re={type:`ended`},ie=`x-vitehub-comments-outbox-account`,p=new WeakMap;async function ae(e){let t=new Uint8Array(await e.arrayBuffer()),n=``;for(let e=0;e<t.length;e+=32768)n+=String.fromCharCode(...t.subarray(e,e+32768));return btoa(n)}function oe(e){if(e instanceof File&&e.name)return e.name;let t=/^[a-z]+\/([a-z0-9]+)/i.exec(e.type)?.[1];return t?`file.${t}`:`file`}async function se(e,t,n,r){let i=[];for(let a of e){let e=await n({name:oe(a),type:a.type||`application/octet-stream`,data:await ae(a),...t?{subject:t}:{}});await r?.(e.key),i.push(e.key)}return i}async function ce(e,{files:t,outbox:n},r,i){if(!t?.length)return e;try{return{...e,attachments:[...e.attachments??[],...await se(t,r,i,n?.uploaded)]}}catch(e){throw n&&p.set(n,{cause:e}),e}}function le(e,t=Date.now()){let n=e.headers.get(`retry-after`)?.trim();if(!n)return;if(/^\d+$/.test(n))return Number(n)*1e3;let r=Date.parse(n);return Number.isNaN(r)?void 0:Math.max(0,r-t)}function ue(e){return Object(e)===e&&!Array.isArray(e)}function de(e,t=``){return`${t.replace(/\/+$/,``)}${ee}/attachments/${e.split(`/`).map(e=>encodeURIComponent(e)).join(`/`)}`}function fe(e={}){let t=e.route??`${(e.base??``).replace(/\/+$/,``)}/_vitehub/comments`;return async(n,r={})=>{let i=e.fetch??globalThis.fetch,a=new Headers(typeof e.headers==`function`?await e.headers():e.headers);for(let[e,t]of new Headers(r.headers))a.set(e,t);r.body!==void 0&&!a.has(`content-type`)&&a.set(`content-type`,`application/json`);let o=typeof e.guest==`function`?e.guest():e.guest;o&&(a.set(`x-vitehub-comments-guest-id`,o.id),a.set(`x-vitehub-comments-guest-name`,encodeURIComponent(o.name)));let s;try{s=await i(`${t}${n}`,{...r,headers:a,credentials:e.credentials??`same-origin`,cache:`no-store`})}catch(e){throw f(0,e)}let c=await s.json().catch(()=>void 0),l=le(s);if(ue(c)&&ue(c.error)){let{code:e,why:t,fix:n}=c.error;throw typeof e!=`string`||typeof t!=`string`?f(s.status,void 0,l):d({code:e,why:t,...typeof n==`string`?{fix:n}:{},...l===void 0?{}:{retryAfter:l},status:s.status})}if(ue(c)&&`data`in c){let t={data:c.data,people:Array.isArray(c.people)?c.people:[],...ue(c.thread)?{thread:c.thread}:{}};return e.onAnswer?.(t),t}throw f(s.status,void 0,l)}}function pe(e){let t=new URLSearchParams;return e.page!==void 0&&t.set(`page`,e.page),e.subject?(t.set(`subjectKind`,e.subject.kind),t.set(`subjectId`,e.subject.id)):e.subjectKind&&t.set(`subjectKind`,e.subjectKind),e.status&&t.set(`status`,e.status),e.mine!==void 0&&t.set(`mine`,String(e.mine)),e.mentions!==void 0&&t.set(`mentions`,String(e.mentions)),e.revision&&t.set(`revision`,String(e.revision.lte)),e.limit!==void 0&&t.set(`limit`,String(e.limit)),e.before&&(t.set(`beforeId`,e.before.id),t.set(`beforeUpdatedAt`,String(e.before.updatedAt))),t}var me=e=>`/threads/${encodeURIComponent(e)}`,he=(e,t)=>({method:`POST`,...e===void 0?{}:{body:JSON.stringify(e)},...t===void 0?{}:{headers:{[ie]:encodeURIComponent(t)}}});function ge(e={}){let t=fe(e),n=(e.base??``).replace(/\/+$/,``),r=async(e,n)=>(await t(`/attachments`,he(e,n))).data;return{async list(e){return(await t(`/threads?${pe(e)}`)).data},async get(e){let n=`threadId`in e?me(e.threadId):`/scopes/${encodeURIComponent(e.scope)}/threads/${e.n}`;return(await t(n)).data},async create({files:e,outbox:n,...i}){let a=await ce(i,{files:e,outbox:n},i.subject,e=>r(e,n?.account));return(await t(`/threads`,he(a,n?.account))).data},async reply({threadId:e,subject:n,files:i,outbox:a,...o}){let s=await ce(o,{files:i,outbox:a},n,e=>r(e,a?.account)),c=await t(`${me(e)}/comments`,he(s,a?.account));if(!c.thread)throw f(200);return c.thread},async edit({threadId:e,messageId:n,...r}){return(await t(`${me(e)}/comments/${encodeURIComponent(n)}`,{method:`PATCH`,body:JSON.stringify(r)})).data},async delete({threadId:e,messageId:n}){let r=n===void 0?me(e):`${me(e)}/comments/${encodeURIComponent(n)}`;return(await t(r,{method:`DELETE`})).data},async resolve({threadId:e}){return(await t(`${me(e)}/resolve`,he())).data},async reopen({threadId:e}){return(await t(`${me(e)}/reopen`,he())).data},async users({query:e,limit:n,threadId:r,subject:i}){let a=new URLSearchParams({q:e});return n!==void 0&&a.set(`limit`,String(n)),r===void 0?i&&(a.set(`subjectKind`,i.kind),a.set(`subjectId`,i.id)):a.set(`thread`,r),(await t(`/people?${a}`)).data},upload:e=>r(e),attachmentUrl:e=>de(e,n)}}var _e=[`session`,`list`,`get`,`create`,`reply`,`resolve`,`reopen`,`redeem`];function ve(e){if(typeof e!=`object`||!e)return!1;let t=Reflect.get(e,`id`),n=Reflect.get(e,`method`);return typeof t==`number`&&Number.isSafeInteger(t)&&_e.some(e=>e===n)}var ye=`changed`,be=`modulepreload`,xe=function(e,t){return new URL(e,t).href},Se={},Ce=function(e){return e.pathname.endsWith(`.css`)},we=function(e,t,n){if(t in e)return e[t];let r=n();if(!r){e[t]=void 0;return}let i=r.then(()=>{e[t]=void 0},n=>{throw e[t]=void 0,n});return e[t]=i,i},Te=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e,i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?new URL(import.meta.resolve(e)):new URL(e,import.meta.url)}r=o(t.map(t=>{t=xe(t,n);let r=s(t),i=Ce(r);return we(Se,r.href,()=>{if(e===void 0){e={all:new Set,styles:new Set};let t=document.getElementsByTagName(`link`);for(let n=t.length-1;n>=0;n--){let r=t[n];e.all.add(r.href),r.rel===`stylesheet`&&e.styles.add(r.href)}}if((i?e.styles:e.all).has(r.href))return;let t=document.createElement(`link`);if(t.rel=i?`stylesheet`:be,i||(t.as=`script`),t.crossOrigin=``,t.href=r.href,a&&t.setAttribute(`nonce`,a),document.head.appendChild(t),i)return new Promise((e,n)=>{let i=a=>{t.removeEventListener(`load`,i),t.removeEventListener(`error`,i),a.type===`error`?n(Error(`Unable to preload CSS for ${r}`)):e(a)};t.addEventListener(`load`,i),t.addEventListener(`error`,i)})})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},m,Ee,De,Oe=t((()=>{l(),m={why:({message:e})=>e===void 0?``:String(e)},Ee={RUNTIME_R0001:{...m,fix:"Pass `maxDepth` to `normalizeRuntimeDiagnosticError()` as an integer of 0 or more, or remove it to use the default."},RUNTIME_R0002:{...m,fix:"Pass `maxErrors` to `normalizeRuntimeDiagnosticError()` as an integer of 1 or more, or remove it to use the default."},RUNTIME_R0003:{...m,fix:"Pass `maxStringLength` to `normalizeRuntimeDiagnosticError()` as an integer of 64 or more, or remove it to use the default."},RUNTIME_R0004:{...m,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:{...m,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:{...m,fix:"Pass `new ViteHubError()` a nonempty `code` and `message` string within the length limits, and plain JSON `details`."},RUNTIME_R0007:{...m,fix:"Give the execution authority a valid value for each of `credentials`, `environment`, `filesystem.access`, `filesystem.scope`, `isolation`, `network`, and `processes`."},RUNTIME_R0009:{...m,fix:"Set `intervalMs` of the process reconciler to a number of milliseconds from 1 to 2147483647."},RUNTIME_R0010:{...m,fix:"Give the process reconciler a `signal` other than `SIGKILL` or `SIGSTOP`, or set `signal: false`."},RUNTIME_R0011:{...m,fix:"Call `drain()` of the process reconciler after its callback returns, not from inside the callback."},RUNTIME_R0015:{...m,fix:"Pass the `Request` of a Fetchable handler, or the event of an H3 or Nitro route, to `getStandardContext()`."},RUNTIME_R0016:{...m,fix:"Return the body or a `Response` from the handler, in place of setting `~standard.res.body`."},RUNTIME_R0017:m,RUNTIME_R0018:m,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_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()`."}},De=a({docsBase:`https://vitehub.dev/docs/runtime/diagnostics`,codes:Ee})}));function h(){throw De.RUNTIME_R0006({message:`[vitehub] ViteHubError requires a valid public error contract.`})}function ke(e){try{return Array.isArray(e)}catch{h()}}function g(e,t,n=!1){try{let r=Object.getOwnPropertyDescriptor(e,t);return r===void 0?void 0:((!(`value`in r)||n&&!r.enumerable)&&h(),r.value)}catch{h()}}function Ae(e,t,n,r){if(t.nodes+=1,t.nodes>Ie&&h(),e===void 0&&r)return;if(e===null||typeof e==`boolean`||typeof e==`string`&&e.length<=Le||typeof e==`number`&&Number.isFinite(e))return e;(typeof e!=`object`||n>Ne||t.ancestors.has(e))&&h();let i,a;try{i=Object.getPrototypeOf(e),a=Reflect.ownKeys(e)}catch{h()}t.ancestors.add(e);try{if(ke(e)){let r=g(e,`length`);(!Number.isSafeInteger(r)||r<0||r>Pe||a.length!==r+1||!a.includes(`length`))&&h();let i=[];for(let o=0;o<r;o+=1){let r=String(o);a.includes(r)||h(),i.push(Ae(g(e,r,!0),t,n+1,!1))}return Object.freeze(i)}i!==Object.prototype&&i!==null&&h(),(a.length>Pe||a.some(e=>typeof e!=`string`))&&h();let r={};for(let i of a)(i.length===0||i.length>Fe)&&h(),Object.defineProperty(r,i,{enumerable:!0,value:Ae(g(e,i,!0),t,n+1,!0),writable:!0});return Object.freeze(r)}finally{t.ancestors.delete(e)}}function je(e){if(e!==void 0)return(typeof e!=`object`||!e||ke(e))&&h(),Ae(e,{ancestors:new Set,nodes:0},0,!1)}function Me(e,t,n){(typeof e!=`string`||e.length===0||e.length>Re)&&h(),(typeof t!=`string`||t.length===0||t.length>ze)&&h(),(typeof n!=`object`||!n||ke(n))&&h();let r=g(n,`cause`),i=je(g(n,`details`)),a=g(n,`requestId`);return a!==void 0&&(typeof a!=`string`||a.length===0||a.length>Be)&&h(),{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 Ne,Pe,Fe,Ie,Le,Re,ze,Be,Ve,He,Ue=t((()=>{Oe(),Ne=8,Pe=128,Fe=128,Ie=1024,Le=16384,Re=128,ze=16384,Be=256,Ve=new WeakMap,He=class extends Error{code;details;requestId;constructor(e,t,n={}){let r=Me(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}}),Ve.set(this,r.shape)}toJSON(){let e=Ve.get(this);if(e)return e;let t=Me(g(this,`code`),g(this,`message`),{details:g(this,`details`),requestId:g(this,`requestId`)});return Ve.set(this,t.shape),t.shape}}}));function We(e){return e!==null&&Object(e)===e}function Ge(e){if(!We(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}}var Ke=t((()=>{}));function qe(e){if(!Ge(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 Je=t((()=>{Ke()}));function Ye(e){let t=t=>{let n=Object.getOwnPropertyDescriptor(e,t);return n?n.configurable===!0:Object.isExtensible(e)},n=t(`name`)&&t(`toJSON`)&&(Object.hasOwn(e,Ze)||Object.isExtensible(e))?e:new s({code:e.code,why:e.why,fix:e.fix,docs:e.docs,cause:e.cause,data:e.data,sources:e.sources});if(n!==e){n.stack=e.stack;let t=Reflect.get(e,`status`);typeof t==`number`&&Object.defineProperty(n,"status",{configurable:!0,value:t})}return Object.defineProperty(n,"name",{configurable:!0,value:n.code,writable:!0}),Object.defineProperty(n,Ze,{value:!0}),Object.defineProperty(n,"toJSON",{configurable:!0,value:()=>({code:n.code,docs:n.docs,fix:n.fix,name:n.name,why:n.why})}),n}function Xe(e){let t=a({codes:e.codes,docsBase:e.docs}),n=new Set(Object.keys(e.codes)),r=Object.defineProperty({},"is",{value:e=>qe(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=Ye(n(e));return a!==void 0&&Object.defineProperty(t,"status",{configurable:!0,enumerable:!1,value:a}),t},{is:e=>qe(e)&&e.code===i})}return r}var Ze,Qe=t((()=>{Je(),l(),Ze=Symbol.for(`vitehub.runtime.resultError`)})),$e=t((()=>{Ue(),Qe()})),et,tt=t((()=>{$e(),et=Xe({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} }\`, or run \`npx @vite-hub/codemods driver-key\` to rename it in every config file.`}}})})),nt=t((()=>{})),_,rt,it,at,ot,st,ct=t((()=>{_=Math.floor,rt=Math.abs,it=(e,t)=>e<t?e:t,at=(e,t)=>e>t?e:t,Number.isNaN,ot=Math.pow,st=e=>e===0?1/e<0:e<0})),lt,ut,dt,ft=t((()=>{ct(),lt=2**53-1,ut=-(2**53-1),dt=Number.isInteger||(e=>typeof e==`number`&&isFinite(e)&&_(e)===e),Number.isNaN,Number.parseInt})),pt,mt=t((()=>{pt=()=>new Set})),ht,gt,v,_t,vt,yt,bt,xt=t((()=>{ht=e=>e[e.length-1],gt=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},v=Array.from,_t=(e,t)=>{for(let n=0;n<e.length;n++)if(!t(e[n],n,e))return!1;return!0},vt=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1},yt=(e,t)=>{let n=Array(e);for(let r=0;r<e;r++)n[r]=t(r,n);return n},bt=Array.isArray})),St,Ct,wt,Tt,Et,Dt,Ot,kt,At,jt,Mt,Nt,Pt=t((()=>{xt(),St=String.fromCharCode,String.fromCodePoint,St(65535),Ct=e=>e.toLowerCase(),wt=/^\s*/g,Tt=e=>e.replace(wt,``),Et=/([A-Z])/g,Dt=(e,t)=>Tt(e.replace(Et,e=>`${t}${Ct(e)}`)),Ot=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},kt=typeof TextEncoder<`u`?new TextEncoder:null,At=e=>kt.encode(e),jt=kt?At:Ot,Mt=typeof TextDecoder>`u`?null:new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0}),Mt&&Mt.decode(new Uint8Array).length===1&&(Mt=null),Nt=(e,t)=>yt(t,()=>e).join(``)})),y,b,x,Ft=t((()=>{y=e=>Error(e),b=()=>{throw y(`Method unimplemented`)},x=()=>{throw y(`Unexpected case`)}})),It,S,Lt,C,Rt,w,zt,T,Bt,Vt,Ht,Ut,Wt,E,Gt,D,Kt,qt,Jt,Yt,Xt,Zt,Qt,$t,en,tn,nn,rn,an,on=t((()=>{ct(),ft(),nt(),Pt(),xt(),It=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},S=()=>new It,Lt=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t},C=e=>{let t=new Uint8Array(Lt(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},Rt=(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(at(n,t)*2),e.cpos=0)},w=(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},zt=w,T=(e,t)=>{for(;t>127;)w(e,128|127&t),t=_(t/128);w(e,127&t)},Bt=(e,t)=>{let n=st(t);for(n&&(t=-t),w(e,(t>63?128:0)|(n?64:0)|63&t),t=_(t/64);t>0;)w(e,(t>127?128:0)|127&t),t=_(t/128)},Vt=new Uint8Array(3e4),Ht=Vt.length/3,Ut=(e,t)=>{if(t.length<Ht){let n=kt.encodeInto(t,Vt).written||0;T(e,n);for(let t=0;t<n;t++)w(e,Vt[t])}else D(e,jt(t))},Wt=(e,t)=>{let n=unescape(encodeURIComponent(t)),r=n.length;T(e,r);for(let t=0;t<r;t++)w(e,n.codePointAt(t))},E=kt&&kt.encodeInto?Ut:Wt,Gt=(e,t)=>{let n=e.cbuf.length,r=e.cpos,i=it(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(at(n*2,a)),e.cbuf.set(t.subarray(i)),e.cpos=a)},D=(e,t)=>{T(e,t.byteLength),Gt(e,t)},Kt=(e,t)=>{Rt(e,t);let n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},qt=(e,t)=>Kt(e,4).setFloat32(0,t,!1),Jt=(e,t)=>Kt(e,8).setFloat64(0,t,!1),Yt=(e,t)=>Kt(e,8).setBigInt64(0,t,!1),Xt=new DataView(new ArrayBuffer(4)),Zt=e=>(Xt.setFloat32(0,e),Xt.getFloat32(0)===e),Qt=(e,t)=>{switch(typeof t){case`string`:w(e,119),E(e,t);break;case`number`:dt(t)&&rt(t)<=2147483647?(w(e,125),Bt(e,t)):Zt(t)?(w(e,124),qt(e,t)):(w(e,123),Jt(e,t));break;case`bigint`:w(e,122),Yt(e,t);break;case`object`:if(t===null)w(e,126);else if(bt(t)){w(e,117),T(e,t.length);for(let n=0;n<t.length;n++)Qt(e,t[n])}else if(t instanceof Uint8Array)w(e,116),D(e,t);else{w(e,118);let n=Object.keys(t);T(e,n.length);for(let r=0;r<n.length;r++){let i=n[r];E(e,i),Qt(e,t[i])}}break;case`boolean`:w(e,t?120:121);break;default:w(e,127)}},$t=class extends It{constructor(e){super(),this.w=e,this.s=null,this.count=0}write(e){this.s===e?this.count++:(this.count>0&&T(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}},en=e=>{e.count>0&&(Bt(e.encoder,e.count===1?e.s:-e.s),e.count>1&&T(e.encoder,e.count-2))},tn=class{constructor(){this.encoder=new It,this.s=0,this.count=0}write(e){this.s===e?this.count++:(en(this),this.count=1,this.s=e)}toUint8Array(){return en(this),C(this.encoder)}},nn=e=>{if(e.count>0){let t=e.diff*2+(e.count===1?0:1);Bt(e.encoder,t),e.count>1&&T(e.encoder,e.count-2)}},rn=class{constructor(){this.encoder=new It,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(nn(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return nn(this),C(this.encoder)}},an=class{constructor(){this.sarr=[],this.s=``,this.lensE=new tn}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 It;return this.sarr.push(this.s),this.s=``,E(e,this.sarr.join(``)),Gt(e,this.lensE.toUint8Array()),C(e)}}})),sn,cn,ln,un,dn,fn,pn,mn,O,hn,k,gn,_n,vn,A,yn,bn,xn,Sn,Cn,wn,Tn,En,Dn,On,kn=t((()=>{nt(),ct(),ft(),Pt(),Ft(),sn=y(`Unexpected end of array`),cn=y(`Integer out of Range`),ln=(e,t,n)=>{if(t<0||n<0||t+n>e.length)throw sn;return new Uint8Array(e.buffer,e.byteOffset+t,n)},un=(e,t,n)=>{if(t<0||n<0||t+n>e.length)throw sn;return new DataView(e.buffer,e.byteOffset+t,n)},dn=class{constructor(e){this.arr=e,this.pos=0}},fn=e=>new dn(e),pn=e=>e.pos!==e.arr.length,mn=(e,t)=>{let n=ln(e.arr,e.pos,t);return e.pos+=t,n},O=e=>mn(e,k(e)),hn=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>lt)throw cn}throw sn},gn=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>lt)throw cn}throw sn},_n=e=>{let t=k(e);if(t===0)return``;{let n=String.fromCodePoint(hn(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(hn(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))}},vn=e=>Mt.decode(O(e)),A=Mt?vn:_n,yn=(e,t)=>{let n=un(e.arr,e.pos,t);return e.pos+=t,n},bn=e=>yn(e,4).getFloat32(0,!1),xn=e=>yn(e,8).getFloat64(0,!1),Sn=e=>yn(e,8).getBigInt64(0,!1),Cn=[e=>void 0,e=>null,gn,bn,xn,Sn,e=>!1,e=>!0,A,e=>{let t=k(e),n={};for(let r=0;r<t;r++){let t=A(e);n[t]=wn(e)}return n},e=>{let t=k(e),n=[];for(let r=0;r<t;r++)n.push(wn(e));return n},O],wn=e=>Cn[127-hn(e)](e),Tn=class extends dn{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=pn(this)?k(this)+1:-1),this.count--,this.s}},En=class extends dn{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=gn(this);let e=st(this.s);this.count=1,e&&(this.s=-this.s,this.count=k(this)+2)}return this.count--,this.s}},Dn=class extends dn{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){let e=gn(this),t=e&1;this.diff=_(e/2),this.count=1,t&&(this.count=k(this)+2)}return this.s+=this.diff,this.count--,this.s}},On=class{constructor(e){this.decoder=new En(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}}})),An,j,jn,Mn=t((()=>{l(),An={why:({message:e})=>e===void 0?``:String(e)},j=e=>({...An,fix:e}),jn=a({docsBase:`https://vitehub.dev/docs/workspace/diagnostics`,codes:{WORKSPACE_CONFLICT:{...An,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} }\`, or run \`npx @vite-hub/codemods driver-key\` to rename it in every config file.`},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" }`, or run `vitehub migrate` to rename it in every file.'},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}" }\`, or run \`npx @vite-hub/codemods driver-key\` to rename it in every config file.`:'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 Nn(e,t={},n=`[vitehub] ${e.why}`){let r=new He(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 Pn(e,t=`not-relative`){let n=e.slice(0,4096);return Nn(jn.WORKSPACE_PATH_INVALID({path:JSON.stringify(n),problem:t}),{details:{path:n}})}function Fn(e){let t=e.toLowerCase().split(`:`,1)[0];return{normalized:t.replace(/[ .]+$/,``),isTraversal:/^(?:\.(?: +[. ]*)?|\.\.(?: +[. ]*)?)$/.test(t)}}function In(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 Pn(e);let a=i.map((e,t)=>({classification:Fn(e),index:t,name:e.toLowerCase()}));if(a.some(({classification:e})=>e.isTraversal))throw Pn(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 Pn(e,`reserved`);return r}var Ln=t((()=>{Mn(),$e()}));function Rn(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 zn(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 In(e)===e}catch{return!1}}function Bn(e){try{let t=JSON.parse(A(e));if((t.operation===`create`||t.operation===`delete`||t.operation===`update`)&&zn(t.path))return{operation:t.operation,path:t.path};if(t.operation===`move`&&zn(t.from)&&zn(t.to))return{operation:t.operation,from:t.from,to:t.to}}catch{}}function Vn(e){let t=S();return T(t,4),E(t,JSON.stringify(e)),C(t)}function Hn(e){let t=S();return T(t,6),E(t,JSON.stringify(e)),C(t)}function Un(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 Wn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var Gn,Kn,qn=t((()=>{kn(),on(),Ln(),Gn=`@workspace`,Kn=`ping`})),M,Jn=t((()=>{M=Date.now}));function Yn(e,t=typeof __VITEHUB_APP_BASE_URL__>`u`?`/`:__VITEHUB_APP_BASE_URL__){return t===`/`?e:`${t.replace(/\/+$/,``)}${e}`}function Xn(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(Kn)},Zn)})}var Zn,Qn=t((()=>{qn(),Jn(),Zn=15e3}));function $n(e){return typeof e==`string`?e:null}function er(e){let t=e.getMap(tr.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:$n(t.get(`digest`)),error:$n(t.get(`error`)),issues:i.issues,savedAt:$n(t.get(`savedAt`)),savedBy:i.savedBy}}var tr,nr=t((()=>{tr=Object.freeze({body:`body`,fields:`fields`,status:`status`})}));function rr(e){try{return String(e)===e}catch{return!1}}function ir(e){if(!rr(e.id)||!e.id||e.id.length>256)throw et.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=(rr(e.name)&&e.name||rr(e.email)&&e.email||`Anonymous`).slice(0,256),r={color:sr[Math.abs(t)%sr.length],id:e.id,name:n};return rr(e.image)&&e.image&&e.image.length<=2048&&(r.image=e.image),r}function ar(e){return Wn(e)?rr(e.id)&&e.id.length>0&&e.id.length<=256&&rr(e.name)&&e.name.length>0&&e.name.length<=256&&rr(e.color)&&/^#[\da-f]{6}$/i.test(e.color)&&(e.image===void 0||rr(e.image)&&e.image.length<=2048):!1}function or(e){let t=[];for(let[n,r]of e)if(ar(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 sr,cr=t((()=>{qn(),tt(),sr=[`#E11D48`,`#D97706`,`#059669`,`#0891B2`,`#2563EB`,`#7C3AED`,`#C026D3`]})),N,lr,P,ur,dr,fr=t((()=>{N=()=>new Map,lr=e=>{let t=N();return e.forEach((e,n)=>{t.set(n,e)}),t},P=(e,t,n)=>{let r=e.get(t);return r===void 0&&e.set(t,r=n()),r},ur=(e,t)=>{let n=[];for(let[r,i]of e)n.push(t(i,r));return n},dr=(e,t)=>{for(let[n,r]of e)if(t(r,n))return!0;return!1}})),pr,mr,hr=t((()=>{fr(),mt(),xt(),pr=class{constructor(){this._observers=N()}on(e,t){return P(this._observers,e,pt).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 v((this._observers.get(e)||N()).values()).forEach(e=>e(...t))}destroy(){this._observers=N()}},mr=class{constructor(){this._observers=N()}on(e,t){P(this._observers,e,pt).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 v((this._observers.get(e)||N()).values()).forEach(e=>e(...t))}destroy(){this._observers=N()}}})),gr,_r,vr=t((()=>{gr=Symbol(`Equality`),_r=(e,t)=>e===t||!!e?.[gr]?.(t)||!1})),yr,br,xr,Sr,Cr,wr,Tr,Er,Dr,Or,kr,Ar,jr=t((()=>{vr(),yr=e=>typeof e==`object`,br=Object.assign,xr=Object.keys,Sr=(e,t)=>{for(let n in e)t(e[n],n)},Cr=(e,t)=>{let n=[];for(let r in e)n.push(t(e[r],r));return n},wr=e=>xr(e).length,Tr=e=>{for(let t in e)return!1;return!0},Er=(e,t)=>{for(let n in e)if(!t(e[n],n))return!1;return!0},Dr=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),Or=(e,t)=>e===t||wr(e)===wr(t)&&Er(e,(e,n)=>(e!==void 0||Dr(t,n))&&_r(t[n],e)),kr=Object.freeze,Ar=e=>{for(let t in e){let n=e[t];(typeof n==`object`||typeof n==`function`)&&Ar(e[t])}return kr(e)}})),Mr,Nr,Pr,Fr,Ir=t((()=>{jr(),vr(),Mr=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&Mr(e,t,n+1)}},Nr=e=>e,Pr=(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[gr]!=null)return e[gr](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)||!Pr(e.get(n),t.get(n)))return!1;break;case void 0:case Object:if(wr(e)!==wr(t))return!1;for(let n in e)if(!Dr(e,n)||!Pr(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(!Pr(e[n],t[n]))return!1;break;default:return!1}return!0},Fr=(e,t)=>t.includes(e)})),Lr,Rr=t((()=>{crypto.subtle,Lr=crypto.getRandomValues.bind(crypto)})),zr,Br,Vr,Hr=t((()=>{Rr(),zr=()=>Lr(new Uint32Array(1))[0],Br=`10000000-1000-4000-8000-100000000000`,Vr=()=>Br.replace(/[018]/g,e=>(e^zr()&15>>e/4).toString(16))})),Ur,Wr=t((()=>{Ur=e=>new Promise(e),Promise.all.bind(Promise)})),Gr,Kr=t((()=>{Gr=e=>e===void 0?null:e})),qr,Jr,Yr,Xr,Zr,Qr,$r=t((()=>{qr=class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}},Jr=new qr,Yr=!0;try{typeof window<`u`&&typeof localStorage<`u`&&localStorage&&(Jr=localStorage,Yr=!1)}catch{}Xr=Jr,Zr=e=>Yr||addEventListener(`storage`,e),Qr=e=>Yr||removeEventListener(`storage`,e)})),F,ei,I,ti,ni,ri,ii,ai,oi,si,ci,li=t((()=>{fr(),Pt(),Kr(),$r(),Ir(),F=typeof process<`u`&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<`u`?process:0)===`[object process]`,ei=typeof window<`u`&&typeof document<`u`&&!F,typeof navigator<`u`&&/Mac/.test(navigator.platform),ti=[],ni=()=>{if(I===void 0){if(F){I=N();let e=process.argv,t=null;for(let n=0;n<e.length;n++){let r=e[n];r[0]===`-`?(t!==null&&I.set(t,``),t=r):t===null?ti.push(r):(I.set(t,r),t=null)}t!==null&&I.set(t,``)}else typeof location==`object`?(I=N(),(location.search||`?`).slice(1).split(`&`).forEach(e=>{if(e.length!==0){let[t,n]=e.split(`=`);I.set(`--${Dt(t,`-`)}`,n),I.set(`-${Dt(t,`-`)}`,n)}})):I=N()}return I},ri=e=>ni().has(e),ii=e=>Gr(F?{}[e.toUpperCase().replaceAll(`-`,`_`)]:Xr.getItem(e)),ai=e=>ri(`--`+e)||ii(e)!==null,oi=ai(`production`),si=F&&Fr({}.FORCE_COLOR,[`true`,`1`,`2`]),ci=si||!ri(`--no-colors`)&&!ai(`no-color`)&&(!F||process.stdout.isTTY)&&(!F||ri(`--color`)||ii(`COLORTERM`)!==null||(ii(`TERM`)||``).includes(`color`))})),ui,di,fi,pi,mi,hi,gi,_i,vi,yi=t((()=>{Pt(),li(),ui=e=>new Uint8Array(e),di=e=>new Uint8Array(e),fi=e=>{let t=``;for(let n=0;n<e.byteLength;n++)t+=St(e[n]);return btoa(t)},pi=e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString(`base64`),mi=e=>{let t=atob(e),n=ui(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n},hi=e=>new Uint8Array(Buffer.from(e,`base64`)),gi=ei?fi:pi,_i=ei?mi:hi,vi=e=>{let t=ui(e.byteLength);return t.set(e),t}})),bi,L,xi=t((()=>{bi=class{constructor(e,t){this.left=e,this.right=t}},L=(e,t)=>new bi(e,t)})),Si,Ci,wi,Ti,Ei,Di,Oi,ki=t((()=>{Pt(),ct(),Si=e=>e.next()>=.5,Ci=(e,t,n)=>_(e.next()*(n+1-t)+t),wi=(e,t,n)=>_(e.next()*(n+1-t)+t),Ti=(e,t,n)=>wi(e,t,n),Ei=e=>St(Ti(e,97,122)),Di=(e,t=0,n=20)=>{let r=Ti(e,t,n),i=``;for(let t=0;t<r;t++)i+=Ei(e);return i},Oi=(e,t)=>t[Ti(e,0,t.length-1)]})),Ai,ji,Mi,R,Ni,z,Pi,B,Fi,Ii,Li,Ri,zi,Bi,Vi,Hi,Ui,Wi,Gi,Ki,qi,Ji,Yi,Xi,Zi,Qi,$i,ea,ta,na,ra,ia,aa,oa,sa,ca,la,ua,da,fa,pa,ma,ha,ga,_a,va,ya,ba,xa,Sa,Ca,wa,Ta,Ea,Da,Oa,ka,Aa,ja,Ma,Na,Pa,Fa,Ia=t((()=>{jr(),xt(),Ft(),li(),vr(),Ir(),Pt(),ki(),ft(),Ai=Symbol(`0schema`),ji=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(Nt(` `,(this._rerrs.length-t)*2)+`${n.path==null?``:`[${n.path}] `}${n.has} doesn't match ${n.expected}. ${n.message}`)}return e.join(`
|
|
2
|
-
`)}},Mi=(e,t)=>e===t?!0:e==null||t==null||e.constructor!==t.constructor?!1:e[gr]?_r(e,t):bt(e)?_t(e,e=>vt(t,t=>Mi(e,t))):yr(e)?Er(e,(e,n)=>Mi(e,t[n])):!1,R=class{static _dilutes=!1;extends(e){let[t,n]=[this.shape,e.shape];return this.constructor._dilutes&&([n,t]=[t,n]),Mi(t,n)}equals(e){return this.constructor===e.constructor&&Pr(this.shape,e.shape)}[Ai](){return!0}[gr](e){return this.equals(e)}validate(e){return this.check(e)}check(e,t){b()}get nullable(){return fa(this,Da)}get optional(){return new Hi(this)}cast(e){return ja(e,this),e}expect(e){return ja(e,this),e}},Ni=class extends R{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}},z=(e,t=null)=>new Ni(e,t),z(Ni),Pi=class extends R{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}},B=e=>new Pi(e),z(Pi),Fi=class extends R{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}},Ii=(...e)=>new Fi(e),Li=z(Fi),Ri=RegExp.escape||(e=>e.replace(/[().|&,$^[\]]/g,e=>`\\`+e)),zi=e=>{if(Sa.check(e))return[Ri(e)];if(Li.check(e))return e.shape.map(e=>e+``);if(xa.check(e))return[`[+-]?\\d+.?\\d*`];if(Ca.check(e))return[`.*`];if(pa.check(e))return e.shape.map(zi).flat(1);x()},Bi=class extends R{constructor(e){super(),this.shape=e,this._r=RegExp(`^`+e.map(zi).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}},z(Bi),Vi=Symbol(`optional`),Hi=class extends R{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[Vi](){return!0}},Ui=z(Hi),Wi=class extends R{check(e,t){return t?.extend(null,`never`,typeof e),!1}},new Wi,z(Wi),Gi=class e extends R{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):Er(this.shape,(n,r)=>{let i=this._isPartial&&!Dr(e,r)||n.check(e[r],t);return!i&&t?.extend(r.toString(),n.toString(),typeof e[r],`Object property does not match`),i})}},Ki=e=>new Gi(e),qi=z(Gi),Ji=B(e=>e!=null&&(e.constructor===Object||e.constructor==null)),Yi=class extends R{constructor(e,t){super(),this.shape={keys:e,values:t}}check(e,t){return e!=null&&Er(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)})}},Xi=(e,t)=>new Yi(e,t),Zi=z(Yi),Qi=class extends R{constructor(e){super(),this.shape=e}check(e,t){return e!=null&&Er(this.shape,(n,r)=>{let i=n.check(e[r],t);return!i&&t?.extend(r.toString(),`Tuple`,typeof n),i})}},$i=(...e)=>new Qi(e),z(Qi),ea=class extends R{constructor(e){super(),this.shape=e.length===1?e[0]:new da(e)}check(e,t){let n=bt(e)&&_t(e,e=>this.shape.check(e));return!n&&t?.extend(null,`Array`,``),n}},ta=(...e)=>new ea(e),na=z(ea),ra=B(e=>bt(e)),ia=class extends R{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}},aa=(e,t=null)=>new ia(e,t),z(ia),oa=aa(R),sa=class extends R{constructor(e){super(),this.len=e.length-1,this.args=$i(...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}},ca=z(sa),la=B(e=>typeof e==`function`),ua=class extends R{constructor(e){super(),this.shape=e}check(e,t){let n=_t(this.shape,n=>n.check(e,t));return!n&&t?.extend(null,`Intersectinon`,typeof e),n}},z(ua,e=>e.shape.length>0),da=class extends R{static _dilutes=!0;constructor(e){super(),this.shape=e}check(e,t){let n=vt(this.shape,n=>n.check(e,t));return t?.extend(null,`Union`,typeof e),n}},fa=(...e)=>e.findIndex(e=>pa.check(e))>=0?fa(...e.map(e=>Aa(e)).map(e=>pa.check(e)?e.shape:[e]).flat(1)):e.length===1?e[0]:new da(e),pa=z(da),ma=()=>!0,ha=B(ma),ga=z(Pi,e=>e.shape===ma),_a=B(e=>typeof e==`bigint`),va=B(e=>e===_a),ya=B(e=>typeof e==`symbol`),B(e=>e===ya),ba=B(e=>typeof e==`number`),xa=B(e=>e===ba),Sa=B(e=>typeof e==`string`),Ca=B(e=>e===Sa),wa=B(e=>typeof e==`boolean`),Ta=B(e=>e===wa),Ea=Ii(void 0),z(Fi,e=>e.shape.length===1&&e.shape[0]===void 0),Ii(void 0),Da=Ii(null),Oa=z(Fi,e=>e.shape.length===1&&e.shape[0]===null),z(Uint8Array),z(Ni,e=>e.shape===Uint8Array),ka=fa(ba,Sa,Da,Ea,_a,wa,ya),(()=>{let e=ta(ha),t=Xi(Sa,ha),n=fa(ba,Sa,Da,wa,e,t);return e.shape=n,t.shape.values=n,n})(),Aa=e=>{if(oa.check(e))return e;if(Ji.check(e)){let t={};for(let n in e)t[n]=Aa(e[n]);return Ki(t)}if(ra.check(e))return fa(...e.map(Aa));if(ka.check(e))return Ii(e);if(la.check(e))return z(e);x()},ja=oi?()=>{}:(e,t)=>{let n=new ji;if(!t.check(e,n))throw y(`Expected value to be of type ${t.constructor.name}.\n${n.toString()}`)},Ma=class{constructor(e){this.patterns=[],this.$state=e}if(e,t){return this.patterns.push({if:Aa(e),h:t}),this}else(e){return this.if(ha,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 y(`Unhandled pattern`)}}},Na=e=>new Ma(e),Pa=Na(ha).if(xa,(e,t)=>Ci(t,ut,lt)).if(Ca,(e,t)=>Di(t)).if(Ta,(e,t)=>Si(t)).if(va,(e,t)=>BigInt(Ci(t,ut,lt))).if(pa,(e,t)=>Fa(t,Oi(t,e.shape))).if(qi,(e,t)=>{let n={};for(let r in e.shape){let i=e.shape[r];if(Ui.check(i)){if(Si(t))continue;i=i.shape}n[r]=Pa(i,t)}return n}).if(na,(e,t)=>{let n=[],r=wi(t,0,42);for(let i=0;i<r;i++)n.push(Fa(t,e.shape));return n}).if(Li,(e,t)=>Oi(t,e.shape)).if(Oa,(e,t)=>null).if(ca,(e,t)=>{let n=Fa(t,e.res);return()=>n}).if(ga,(e,t)=>Fa(t,Oi(t,[ba,Sa,Da,Ea,_a,wa,ta(ba),Xi(fa(`a`,`b`,`c`),ba)]))).if(Zi,(e,t)=>{let n={},r=Ci(t,0,3);for(let i=0;i<r;i++){let r=Fa(t,e.shape.keys);n[r]=Fa(t,e.shape.values)}return n}).done(),Fa=(e,t)=>Pa(Aa(t),e)})),La,Ra,za,Ba,Va,Ha,Ua=t((()=>{fr(),Ia(),La=typeof document<`u`?document:{},B(e=>e.nodeType===Ha),typeof DOMParser<`u`&&new DOMParser,B(e=>e.nodeType===za),B(e=>e.nodeType===Ba),Ra=e=>ur(e,(e,t)=>`${t}:${e};`).join(``),za=La.ELEMENT_NODE,Ba=La.TEXT_NODE,La.CDATA_SECTION_NODE,La.COMMENT_NODE,Va=La.DOCUMENT_NODE,La.DOCUMENT_TYPE_NODE,Ha=La.DOCUMENT_FRAGMENT_NODE,B(e=>e.nodeType===Va)})),V,Wa=t((()=>{V=Symbol})),Ga,Ka,qa,Ja,Ya,Xa,Za,Qa,$a,eo,to=t((()=>{Wa(),Jn(),Ga=V(),Ka=V(),qa=V(),Ja=V(),Ya=V(),Xa=V(),Za=V(),Qa=V(),$a=V(),eo=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()})),no,ro,io,ao,oo,so,co=t((()=>{li(),mt(),xi(),Ua(),fr(),to(),no={[Ga]:L(`font-weight`,`bold`),[Ka]:L(`font-weight`,`normal`),[qa]:L(`color`,`blue`),[Ya]:L(`color`,`green`),[Ja]:L(`color`,`grey`),[Xa]:L(`color`,`red`),[Za]:L(`color`,`purple`),[Qa]:L(`color`,`orange`),[$a]:L(`color`,`black`)},ro=e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=N(),i=[],a=0;for(;a<e.length;a++){let i=e[a],o=no[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=Ra(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},io=ci?ro:eo,ao=(...e)=>{console.log(...io(e)),so.forEach(t=>t.print(e))},oo=(...e)=>{console.warn(...io(e)),e.unshift(Qa),so.forEach(t=>t.print(e))},so=pt()})),lo,uo,fo,po=t((()=>{lo=e=>({[Symbol.iterator](){return this},next:e}),uo=(e,t)=>lo(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),fo=(e,t)=>lo(()=>{let{done:n,value:r}=e.next();return{done:n,value:n?void 0:t(r)}})}));function*mo(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 $(H(n,r),t),r+=t}else if(31&t){let i=!(t&192),a=new Q(H(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,Tl(e,t));yield a,r+=a.length}else{let t=e.readLen();yield new X(H(n,r),t),r+=t}}}}var ho,go,_o,vo,yo,bo,xo,So,Co,wo,To,Eo,Do,Oo,ko,Ao,jo,Mo,No,Po,Fo,Io,Lo,Ro,zo,Bo,Vo,Ho,Uo,Wo,Go,Ko,qo,Jo,Yo,Xo,Zo,Qo,$o,es,ts,ns,rs,is,as,os,ss,H,cs,ls,us,ds,fs,ps,ms,U,hs,W,gs,_s,vs,G,ys,bs,xs,Ss,Cs,ws,Ts,Es,Ds,Os,K,ks,As,js,Ms,Ns,Ps,Fs,q,Is,Ls,Rs,zs,Bs,Vs,J,Hs,Us,Ws,Gs,Ks,qs,Js,Ys,Xs,Y,Zs,Qs,$s,ec,tc,nc,rc,ic,ac,oc,sc,cc,lc,uc,dc,fc,pc,mc,hc,gc,_c,vc,yc,bc,xc,Sc,Cc,wc,Tc,Ec,Dc,Oc,kc,Ac,jc,Mc,Nc,Pc,Fc,Ic,Lc,Rc,zc,Bc,Vc,Hc,Uc,Wc,Gc,Kc,qc,Jc,Yc,Xc,X,Zc,Qc,$c,el,tl,nl,rl,il,al,Z,ol,sl,cl,ll,ul,dl,fl,pl,ml,hl,gl,_l,vl,yl,bl,xl,Sl,Cl,wl,Q,Tl,El,Dl,$,Ol,kl,Al=t((()=>{hr(),xt(),ct(),fr(),on(),kn(),Hr(),Wr(),yi(),Ft(),nt(),Ir(),mt(),co(),po(),jr(),li(),ho=class{constructor(e,t){this.clock=e,this.len=t}},go=class{constructor(){this.clients=new Map}},_o=(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])xs(e,i,o.clock,o.len,n)}}),vo=(e,t)=>{let n=0,r=e.length-1;for(;n<=r;){let i=_((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},yo=(e,t)=>{let n=e.clients.get(t.client);return n!==void 0&&vo(n,t.clock)!==null},bo=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 ho(r.clock,at(r.len,i.clock+i.len-r.clock)):(n<t&&(e[n]=i),n++)}e.length=n})},xo=e=>{let t=new go;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++)gt(a,e[t].clients.get(i)||[]);t.clients.set(i,a)}});return bo(t),t},So=(e,t,n,r)=>{P(e.clients,t,()=>[]).push(new ho(n,r))},Co=()=>new go,wo=e=>{let t=Co();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 ho(i,a))}}r.length>0&&t.clients.set(n,r)}),t},To=(e,t)=>{T(e.restEncoder,t.clients.size),v(t.clients.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{e.resetDsCurVal(),T(e.restEncoder,t);let r=n.length;T(e.restEncoder,r);for(let t=0;t<r;t++){let r=n[t];e.writeDsClock(r.clock),e.writeDsLen(r.len)}})},Eo=e=>{let t=new go,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=P(t.clients,n,()=>[]);for(let t=0;t<r;t++)i.push(new ho(e.readDsClock(),e.readDsLen()))}}return t},Do=(e,t,n)=>{let r=new go,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=U(n,i);for(let n=0;n<a;n++){let n=e.readDsClock(),a=n+e.readDsLen();if(n<s){s<a&&So(r,i,s,a-s);let e=W(o,n),c=o[e];for(!c.deleted&&c.id.clock<n&&(o.splice(e+1,0,wl(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,wl(t,c,a-c.id.clock)),c.delete(t))}else So(r,i,n,a-n)}}if(r.clients.size>0){let e=new Lo;return T(e.restEncoder,0),To(e,r),e.toUint8Array()}return null},Oo=zr,ko=class e extends pr{constructor({guid:e=Vr(),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=Oo(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new ps,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=Ur(e=>{this.on(`load`,()=>{this.isLoaded=!0,e(this)})});let s=()=>Ur(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(v(this.subdocs).map(e=>e.guid))}transact(e,t=null){return K(this,e,t)}get(e,t=Y){let n=P(this.share,e,()=>{let e=new t;return e._integrate(this,null),e}),r=n.constructor;if(t!==Y&&r!==t){if(r===Y){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,gc)}getText(e=``){return this.get(e,Lc)}getMap(e=``){return this.get(e,yc)}getXmlElement(e=``){return this.get(e,Hc)}getXmlFragment(e=``){return this.get(e,Bc)}toJSON(){let e={};return this.share.forEach((t,n)=>{e[n]=t.toJSON()}),e}destroy(){this.isDestroyed=!0,v(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()}},Ao=class{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return k(this.restDecoder)}readDsLen(){return k(this.restDecoder)}},jo=class extends Ao{readLeftID(){return H(k(this.restDecoder),k(this.restDecoder))}readRightID(){return H(k(this.restDecoder),k(this.restDecoder))}readClient(){return k(this.restDecoder)}readInfo(){return hn(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 wn(this.restDecoder)}readBuf(){return vi(O(this.restDecoder))}readJSON(){return JSON.parse(A(this.restDecoder))}readKey(){return A(this.restDecoder)}},Mo=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}},No=class extends Mo{constructor(e){super(e),this.keys=[],k(e),this.keyClockDecoder=new Dn(O(e)),this.clientDecoder=new En(O(e)),this.leftClockDecoder=new Dn(O(e)),this.rightClockDecoder=new Dn(O(e)),this.infoDecoder=new Tn(O(e),hn),this.stringDecoder=new On(O(e)),this.parentInfoDecoder=new Tn(O(e),hn),this.typeRefDecoder=new En(O(e)),this.lenDecoder=new En(O(e))}readLeftID(){return new os(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new os(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 wn(this.restDecoder)}readBuf(){return O(this.restDecoder)}readJSON(){return wn(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}}},Po=class{constructor(){this.restEncoder=S()}toUint8Array(){return C(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){T(this.restEncoder,e)}writeDsLen(e){T(this.restEncoder,e)}},Fo=class extends Po{writeLeftID(e){T(this.restEncoder,e.client),T(this.restEncoder,e.clock)}writeRightID(e){T(this.restEncoder,e.client),T(this.restEncoder,e.clock)}writeClient(e){T(this.restEncoder,e)}writeInfo(e){zt(this.restEncoder,e)}writeString(e){E(this.restEncoder,e)}writeParentInfo(e){T(this.restEncoder,+!!e)}writeTypeRef(e){T(this.restEncoder,e)}writeLen(e){T(this.restEncoder,e)}writeAny(e){Qt(this.restEncoder,e)}writeBuf(e){D(this.restEncoder,e)}writeJSON(e){E(this.restEncoder,JSON.stringify(e))}writeKey(e){E(this.restEncoder,e)}},Io=class{constructor(){this.restEncoder=S(),this.dsCurrVal=0}toUint8Array(){return C(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){let t=e-this.dsCurrVal;this.dsCurrVal=e,T(this.restEncoder,t)}writeDsLen(e){e===0&&x(),T(this.restEncoder,e-1),this.dsCurrVal+=e}},Lo=class extends Io{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new rn,this.clientEncoder=new tn,this.leftClockEncoder=new rn,this.rightClockEncoder=new rn,this.infoEncoder=new $t(zt),this.stringEncoder=new an,this.parentInfoEncoder=new $t(zt),this.typeRefEncoder=new tn,this.lenEncoder=new tn}toUint8Array(){let e=S();return T(e,0),D(e,this.keyClockEncoder.toUint8Array()),D(e,this.clientEncoder.toUint8Array()),D(e,this.leftClockEncoder.toUint8Array()),D(e,this.rightClockEncoder.toUint8Array()),D(e,C(this.infoEncoder)),D(e,this.stringEncoder.toUint8Array()),D(e,C(this.parentInfoEncoder)),D(e,this.typeRefEncoder.toUint8Array()),D(e,this.lenEncoder.toUint8Array()),Gt(e,C(this.restEncoder)),C(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){Qt(this.restEncoder,e)}writeBuf(e){D(this.restEncoder,e)}writeJSON(e){Qt(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)}},Ro=(e,t,n,r)=>{r=at(r,t[0].id.clock);let i=W(t,r);T(e.restEncoder,t.length-i),e.writeClient(n),T(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)},zo=(e,t,n)=>{let r=new Map;n.forEach((e,n)=>{U(t,n)>e&&r.set(n,e)}),ms(t).forEach((e,t)=>{n.has(t)||r.set(t,0)}),T(e.restEncoder,r.size),v(r.entries()).sort((e,t)=>t[0]-e[0]).forEach(([n,r])=>{Ro(e,t.clients.get(n),n,r)})},Bo=(e,t)=>{let n=N(),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(H(a,o),t),o+=t;break}case 10:{let t=k(e.restDecoder);i[n]=new $(H(a,o),t),o+=t;break}default:{let s=!(r&192),c=new Q(H(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,Tl(e,r));i[n]=c,o+=c.length}}}}return n},Vo=(e,t,n)=>{let r=[],i=v(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 ps,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=P(d,u.id.client,()=>U(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,U(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 Lo;return zo(e,s,new Map),T(e.restEncoder,0),{missing:c,update:e.toUint8Array()}}return null},Ho=(e,t)=>zo(e,t.doc.store,t.beforeState),Uo=(e,t,n,r=new No(e))=>K(t,e=>{e.local=!1;let t=!1,n=e.doc,i=n.store,a=Bo(r,n),o=Vo(e,i,a),s=i.pendingStructs;if(s){for(let[e,n]of s.missing)if(n<U(i,e)){t=!0;break}if(o){for(let[e,t]of o.missing){let n=s.missing.get(e);(n==null||n>t)&&s.missing.set(e,t)}s.update=Ns([s.update,o.update])}}else i.pendingStructs=o;let c=Do(r,e,i);if(i.pendingDs){let t=new No(fn(i.pendingDs));k(t.restDecoder);let n=Do(t,e,i);i.pendingDs=c&&n?Ns([c,n]):c||n}else i.pendingDs=c;if(t){let t=i.pendingStructs.update;i.pendingStructs=null,Wo(e.doc,t)}},n,!1),Wo=(e,t,n,r=No)=>{let i=fn(t);Uo(i,e,n,new r(i))},Go=(e,t,n)=>Wo(e,t,n,jo),Ko=(e,t,n=new Map)=>{zo(e,t.store,n),To(e,wo(t.store))},qo=(e,t=new Uint8Array([0]),n=new Lo)=>{let r=Xo(t);Ko(n,e,r);let i=[n.toUint8Array()];if(e.store.pendingDs&&i.push(e.store.pendingDs),e.store.pendingStructs&&i.push(Ps(e.store.pendingStructs.update,t)),i.length>1){if(n.constructor===Fo)return js(i.map((e,t)=>t===0?e:Rs(e)));if(n.constructor===Lo)return Ns(i)}return i[0]},Jo=(e,t)=>qo(e,t,new Fo),Yo=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},Xo=e=>Yo(new Ao(fn(e))),Zo=(e,t)=>(T(e.restEncoder,t.size),v(t.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{T(e.restEncoder,t),T(e.restEncoder,n)}),e),Qo=(e,t)=>Zo(e,ms(t.store)),$o=(e,t=new Io)=>(e instanceof Map?Zo(t,e):Qo(t,e),t.toUint8Array()),es=e=>$o(e,new Po),ts=class{constructor(){this.l=[]}},ns=()=>new ts,rs=(e,t)=>e.l.push(t),is=(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.`)},as=(e,t,n)=>Mr(e.l,[t,n]),os=class{constructor(e,t){this.client=e,this.clock=t}},ss=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,H=(e,t)=>new os(e,t),cs=e=>{for(let[t,n]of e.doc.share.entries())if(n===e)return t;throw x()},ls=class{constructor(e,t){this.ds=e,this.sv=t}},us=(e,t)=>new ls(e,t),us(Co(),new Map),ds=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!yo(t.ds,e.id),fs=(e,t)=>{let n=P(e.meta,fs,pt),r=e.doc.store;n.has(t)||(t.sv.forEach((t,n)=>{t<U(r,n)&&G(e,H(n,t))}),_o(e,t.ds,e=>{}),n.add(t))},ps=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},ms=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},U=(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},hs=(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 x()}n.push(t)},W=(e,t)=>{let n=0,r=e.length-1,i=e[r],a=i.id.clock;if(a===t)return r;let o=_(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=_((n+r)/2)}throw x()},gs=(e,t)=>{let n=e.clients.get(t.client);return n[W(n,t.clock)]},_s=gs,vs=(e,t,n)=>{let r=W(t,n),i=t[r];return i.id.clock<n&&i instanceof Q?(t.splice(r+1,0,wl(e,i,n-i.id.clock)),r+1):r},G=(e,t)=>{let n=e.doc.store.clients.get(t.client);return n[vs(e,n,t.clock)]},ys=(e,t,n)=>{let r=t.clients.get(n.client),i=W(r,n.clock),a=r[i];return n.clock!==a.id.clock+a.length-1&&a.constructor!==X&&r.splice(i+1,0,wl(e,a,n.clock-a.id.clock+1)),a},bs=(e,t,n)=>{let r=e.clients.get(t.id.client);r[W(r,t.id.clock)]=n},xs=(e,t,n,r,i)=>{if(r===0)return;let a=n+r,o=vs(e,t,n),s;do s=t[o++],a<s.id.clock+s.length&&vs(e,t,a),i(s);while(o<t.length&&t[o].id.clock<a)},Ss=class{constructor(e,t,n){this.doc=e,this.deleteSet=new go,this.beforeState=ms(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}},Cs=(e,t)=>t.deleteSet.clients.size===0&&!dr(t.afterState,(e,n)=>t.beforeState.get(n)!==e)?!1:(bo(t.deleteSet),Ho(e,t),To(e,t.deleteSet),!0),ws=(e,t,n)=>{let r=t._item;(r===null||r.id.clock<(e.beforeState.get(r.id.client)||0)&&!r.deleted)&&P(e.changed,t,pt).add(n)},Ts=(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},Es=(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=W(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)}}}},Ds=(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=it(r.length-1,1+W(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+Ts(r,e)}})},Os=(e,t)=>{if(t<e.length){let n=e[t],r=n.doc,i=r.store,a=n.deleteSet,o=n._mergeStructs;try{bo(a),n.afterState=ms(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),as(r._dEH,t,n)})}),e.push(()=>r.emit(`afterTransaction`,[n,r])),e.push(()=>{n._needFormattingCleanup&&Pc(n)})}),Mr(e,[])}finally{r.gc&&Es(a,i,r.gcFilter),Ds(a,i),n.afterState.forEach((e,t)=>{let r=n.beforeState.get(t)||0;if(r!==e){let e=i.clients.get(t),n=at(W(e,r),1);for(let t=e.length-1;t>=n;)t-=1+Ts(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=W(r,n);a+1<r.length&&Ts(r,a+1)>1||a>0&&Ts(r,a)}if(!n.local&&n.afterState.get(r.clientID)!==n.beforeState.get(r.clientID)&&(ao(Qa,Ga,`[yjs] `,Ka,Xa,`Changed the client-id because another client seems to be using it.`),r.clientID=Oo()),r.emit(`afterTransactionCleanup`,[n,r]),r._observers.has(`update`)){let e=new Fo;Cs(e,n)&&r.emit(`update`,[e.toUint8Array(),n.origin,r,n])}if(r._observers.has(`updateV2`)){let e=new Lo;Cs(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])):Os(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 Ss(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&&Os(i,0)}}return o},ks=class{constructor(e,t){this.gen=mo(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}},As=class{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}},js=e=>Ns(e,jo,Fo),Ms=(e,t)=>{if(e.constructor===X){let{client:n,clock:r}=e.id;return new X(H(n,r+t),e.length-t)}if(e.constructor===$){let{client:n,clock:r}=e.id;return new $(H(n,r+t),e.length-t)}{let n=e,{client:r,clock:i}=n.id;return new Q(H(r,i+t),null,H(r,i+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},Ns=(e,t=No,n=Lo)=>{if(e.length===1)return e[0];let r=e.map(e=>new t(fn(e))),i=r.map(e=>new ks(e,!0)),a=null,o=new n,s=new As(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)q(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{q(s,a.struct,a.offset);let e=n.id.clock-a.struct.id.clock-a.struct.length;a={struct:new $(H(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=Ms(n,t)),a.struct.mergeWith(n)||(q(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())q(s,a.struct,a.offset),a={struct:n,offset:0}}a!==null&&(q(s,a.struct,a.offset),a=null),Is(s);let c=r.map(e=>Eo(e)),l=xo(c);return To(o,l),o.toUint8Array()},Ps=(e,t,n=No,r=Lo)=>{let i=Xo(t),a=new r,o=new As(a),s=new n(fn(e)),c=new ks(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(q(o,e,at(n-e.id.clock,0)),c.next();c.curr&&c.curr.id.client===t;)q(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()}Is(o);let l=Eo(s);return To(a,l),a.toUint8Array()},Fs=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:C(e.encoder.restEncoder)}),e.encoder.restEncoder=S(),e.written=0)},q=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&Fs(e),e.written===0&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),T(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},Is=e=>{Fs(e);let t=e.encoder.restEncoder;T(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){let r=e.clientStructs[n];T(t,r.written),Gt(t,r.restEncoder)}},Ls=(e,t,n,r)=>{let i=new n(fn(e)),a=new ks(i,!1),o=new r,s=new As(o);for(let e=a.curr;e!==null;e=a.next())q(s,t(e),0);Is(s);let c=Eo(i);return To(o,c),o.toUint8Array()},Rs=e=>Ls(e,Nr,No,Fo),zs=`You must not compute changes after the event-handler fired.`,Bs=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||=Vs(this.currentTarget,this.target)}deletes(e){return yo(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw y(zs);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=ht(e.content.getContent());else return}else e!==null&&this.deletes(e)?(i=`update`,a=ht(e.content.getContent())):(i=`add`,a=void 0)}else if(this.deletes(r))i=`delete`,a=ht(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 y(zs);let t=this.target,n=pt(),r=pt(),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}},Vs=(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},J=()=>{oo(`Invalid access: Add Yjs type to a document before reading data.`)},Hs=80,Us=0,Ws=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=Us++}},Gs=e=>{e.timestamp=Us++},Ks=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=Us++},qs=(e,t,n)=>{if(e.length>=Hs){let r=e.reduce((e,t)=>e.timestamp<t.timestamp?e:t);return Ks(r,t,n),r}{let r=new Ws(t,n);return e.push(r),r}},Js=(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)=>rt(t-e.index)<rt(t-n.index)?e:n),r=e._start,i=0;for(n!==null&&(r=n.p,i=n.index,Gs(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&&rt(n.index-i)<r.parent.length/Hs?(Ks(n,r,i),n):qs(e._searchMarker,r,i)},Ys=(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=at(t,i.index+n))}},Xs=(e,t,n)=>{let r=e,i=t.changedParentTypes;for(;P(i,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;as(r._eH,n,t)},Y=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=ns(),this._dEH=ns(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw b()}clone(){throw b()}_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){rs(this._eH,e)}observeDeep(e){rs(this._dEH,e)}unobserve(e){is(this._eH,e)}unobserveDeep(e){is(this._dEH,e)}toJSON(){}},Zs=(e,t,n)=>{e.doc??J(),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},Qs=e=>{e.doc??J();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},$s=(e,t)=>{let n=0,r=e._start;for(e.doc??J();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}},ec=(e,t)=>{let n=[];return $s(e,(r,i)=>{n.push(t(r,i,e))}),n},tc=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}}}},nc=(e,t)=>{e.doc??J();let n=Js(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}},rc=(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(H(o,U(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new ul(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(H(o,U(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new Zc(new Uint8Array(n))),i.integrate(e,0);break;case ko:i=new Q(H(o,U(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new nl(n)),i.integrate(e,0);break;default:if(n instanceof Y)i=new Q(H(o,U(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new Sl(n)),i.integrate(e,0);else throw Error(`Unexpected content type in insert operation`)}}}),u()},ic=()=>y(`Length exceeded!`),ac=(e,t,n,r)=>{if(n>t._length)throw ic();if(n===0)return t._searchMarker&&Ys(t._searchMarker,n,r.length),rc(e,t,null,r);let i=n,a=Js(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&&G(e,H(o.id.client,o.id.clock+n));break}n-=o.length}return t._searchMarker&&Ys(t._searchMarker,i,r.length),rc(e,t,o,r)},oc=(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 rc(e,t,r,n)},sc=(e,t,n,r)=>{if(r===0)return;let i=n,a=r,o=Js(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&&G(e,H(s.id.client,s.id.clock+n)),n-=s.length);for(;r>0&&s!==null;)s.deleted||(r<s.length&&G(e,H(s.id.client,s.id.clock+r)),s.delete(e),r-=s.length),s=s.right;if(r>0)throw ic();t._searchMarker&&Ys(t._searchMarker,i,-a+r)},cc=(e,t,n)=>{let r=t._map.get(n);r!==void 0&&r.delete(e)},lc=(e,t,n,r)=>{let i=t._map.get(n)||null,a=e.doc,o=a.clientID,s;if(r==null)s=new ul([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:s=new ul([r]);break;case Uint8Array:s=new Zc(r);break;case ko:s=new nl(r);break;default:if(r instanceof Y)s=new Sl(r);else throw Error(`Unexpected content type`)}new Q(H(o,U(a.store,o)),i,i&&i.lastId,null,null,t,n,s).integrate(e,0)},uc=(e,t)=>{e.doc??J();let n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},dc=e=>{let t={};return e.doc??J(),e._map.forEach((e,n)=>{e.deleted||(t[n]=e.content.getContent()[e.length-1])}),t},fc=(e,t)=>{e.doc??J();let n=e._map.get(t);return n!==void 0&&!n.deleted},pc=(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&&ds(i,t)&&(n[r]=i.content.getContent()[i.length-1])}),n},mc=e=>(e.doc??J(),uo(e._map.entries(),e=>!e[1].deleted)),hc=class extends Bs{},gc=class e extends Y{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 Y?e.clone():e)),t}get length(){return this.doc??J(),this._length}_callObserver(e,t){super._callObserver(e,t),Xs(this,e,new hc(this,e))}insert(e,t){this.doc===null?this._prelimContent.splice(e,0,...t):K(this.doc,n=>{ac(n,this,e,t)})}push(e){this.doc===null?this._prelimContent.push(...e):K(this.doc,t=>{oc(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=>{sc(n,this,e,t)})}get(e){return nc(this,e)}toArray(){return Qs(this)}slice(e=0,t=this.length){return Zs(this,e,t)}toJSON(){return this.map(e=>e instanceof Y?e.toJSON():e)}map(e){return ec(this,e)}forEach(e){$s(this,e)}[Symbol.iterator](){return tc(this)}_write(e){e.writeTypeRef(hl)}},_c=e=>new gc,vc=class extends Bs{constructor(e,t,n){super(e,t),this.keysChanged=n}},yc=class e extends Y{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 Y?e.clone():e)}),t}_callObserver(e,t){Xs(this,e,new vc(this,e,t))}toJSON(){this.doc??J();let e={};return this._map.forEach((t,n)=>{if(!t.deleted){let r=t.content.getContent()[t.length-1];e[n]=r instanceof Y?r.toJSON():r}}),e}get size(){return[...mc(this)].length}keys(){return fo(mc(this),e=>e[0])}values(){return fo(mc(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return fo(mc(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??J(),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=>{cc(t,this,e)})}set(e,t){return this.doc===null?this._prelimContent.set(e,t):K(this.doc,n=>{lc(n,this,e,t)}),t}get(e){return uc(this,e)}has(e){return fc(this,e)}clear(){this.doc===null?this._prelimContent.clear():K(this.doc,e=>{this.forEach(function(t,n,r){cc(e,r,n)})})}_write(e){e.writeTypeRef(gl)}},bc=e=>new yc,xc=(e,t)=>e===t||typeof e==`object`&&typeof t==`object`&&e&&t&&Or(e,t),Sc=class{constructor(e,t,n,r){this.left=e,this.right=t,this.index=n,this.currentAttributes=r}forward(){switch(this.right===null&&x(),this.right.content.constructor){case Z:this.right.deleted||Ec(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length)}this.left=this.right,this.right=this.right.right}},Cc=(e,t,n)=>{for(;t.right!==null&&n>0;){switch(t.right.content.constructor){case Z:t.right.deleted||Ec(t.currentAttributes,t.right.content);break;default:t.right.deleted||(n<t.right.length&&G(e,H(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},wc=(e,t,n,r)=>{let i=new Map,a=r?Js(t,n):null;if(a){let t=new Sc(a.p.left,a.p,a.index,i);return Cc(e,t,n-a.index)}{let r=new Sc(null,t._start,0,i);return Cc(e,r,n)}},Tc=(e,t,n,r)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===Z&&xc(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(H(a,U(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()})},Ec=(e,t)=>{let{key:n,value:r}=t;r===null?e.delete(n):e.set(n,r)},Dc=(e,t)=>{for(;e.right!==null&&(e.right.deleted||e.right.content.constructor===Z&&xc(t[e.right.content.key]??null,e.right.content.value));)e.forward()},Oc=(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(!xc(l,c)){o.set(s,l);let{left:r,right:u}=n;n.right=new Q(H(a,U(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},kc=(e,t,n,r,i)=>{n.currentAttributes.forEach((e,t)=>{i[t]===void 0&&(i[t]=null)});let a=e.doc,o=a.clientID;Dc(n,i);let s=Oc(e,t,n,i),c=r.constructor===String?new fl(r):r instanceof Y?new Sl(r):new il(r),{left:l,right:u,index:d}=n;t._searchMarker&&Ys(t._searchMarker,n.index,c.getLength()),u=new Q(H(o,U(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(),Tc(e,t,n,s)},Ac=(e,t,n,r,i)=>{let a=e.doc,o=a.clientID;Dc(n,i);let s=Oc(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(xc(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&&G(e,H(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(H(o,U(a.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new
|
|
4
|
-
`?a.insert.slice(0,-1):a.insert;(typeof o!=`string`||o.length>0)&&kc(n,this,r,o,a.attributes||{})}else a.retain===void 0?a.delete!==void 0&&Fc(n,r,a.delete):Ac(n,this,r,a.retain,a.attributes||{})}})}toDelta(e,t,n){this.doc??J();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(ds(s,e)||t!==void 0&&ds(s,t))switch(s.content.constructor){case fl:{let r=i.get(`ychange`);e!==void 0&&!ds(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&&!ds(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 Sl:case il:{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:ds(s,e)&&(c(),Ec(i,s.content))}s=s.right}c()};return e||t?K(a,n=>{e&&fs(n,e),t&&fs(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=wc(r,this,e,!n);n||(n={},i.currentAttributes.forEach((e,t)=>{n[t]=e})),kc(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=wc(r,this,e,!n);kc(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=>{Fc(n,wc(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=wc(r,this,e,!1);i.right!==null&&Ac(r,this,i,t,n)})}removeAttribute(e){this.doc===null?this._pending.push(()=>this.removeAttribute(e)):K(this.doc,t=>{cc(t,this,e)})}setAttribute(e,t){this.doc===null?this._pending.push(()=>this.setAttribute(e,t)):K(this.doc,n=>{lc(n,this,e,t)})}getAttribute(e){return uc(this,e)}getAttributes(){return dc(this)}_write(e){e.writeTypeRef(_l)}},Rc=e=>new Lc,zc=class{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??J()}[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===Hc||t.constructor===Bc)&&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})}},Bc=class e extends Y{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 Y?e.clone():e)),t}get length(){return this.doc??J(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new zc(this,e)}querySelector(e){e=e.toUpperCase();let t=new zc(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e).next();return t.done?null:t.value}querySelectorAll(e){return e=e.toUpperCase(),v(new zc(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){Xs(this,e,new Wc(this,t,e))}toString(){return ec(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),$s(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=>{ac(n,this,e,t)})}insertAfter(e,t){if(this.doc!==null)K(this.doc,n=>{let r=e&&e instanceof Y?e._item:e;rc(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 y(`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=>{sc(n,this,e,t)})}toArray(){return Qs(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return nc(this,e)}slice(e=0,t=this.length){return Zs(this,e,t)}forEach(e){$s(this,e)}_write(e){e.writeTypeRef(yl)}},Vc=e=>new Bc,Hc=class e extends Bc{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),n=this.getAttributes();return Sr(n,(e,n)=>{t.setAttribute(n,e)}),t.insert(0,this.toArray().map(e=>e instanceof Y?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=>{cc(t,this,e)})}setAttribute(e,t){this.doc===null?this._prelimAttrs.set(e,t):K(this.doc,n=>{lc(n,this,e,t)})}getAttribute(e){return uc(this,e)}hasAttribute(e){return fc(this,e)}getAttributes(e){return e?pc(this,e):dc(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 $s(this,i=>{r.appendChild(i.toDOM(e,t,n))}),n!==void 0&&n._createAssociation(r,this),r}_write(e){e.writeTypeRef(vl),e.writeKey(this.nodeName)}},Uc=e=>new Hc(e.readKey()),Wc=class extends Bs{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)})}},Gc=class e extends yc{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(bl),e.writeKey(this.hookName)}},Kc=e=>new Gc(e.readKey()),qc=class e extends Lc{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(xl)}},Jc=e=>new qc,Yc=class{constructor(e,t){this.id=e,this.length=t}get deleted(){throw b()}mergeWith(e){return!1}write(e,t,n){throw b()}integrate(e,t){throw b()}},Xc=0,X=class extends Yc{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),hs(e.doc.store,this)}write(e,t){e.writeInfo(Xc),e.writeLen(this.length-t)}getMissing(e,t){return null}},Zc=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 b()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}},Qc=e=>new Zc(e.readBuf()),$c=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){So(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}},el=e=>new $c(e.readLen()),tl=(e,t)=>new ko({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1}),nl=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(tl(this.doc.guid,this.opts))}splice(e){throw b()}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}},rl=e=>new nl(tl(e.readString(),e.readAny())),il=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 b()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}},al=e=>new il(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 b()}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}},ol=e=>new Z(e.readKey(),e.readJSON()),sl=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}},cl=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 sl(n)},ll=ii(`node_env`)===`development`,ul=class e{constructor(e){this.arr=e,ll&&Ar(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}},dl=e=>{let t=e.readLen(),n=[];for(let r=0;r<t;r++)n.push(e.readAny());return new ul(n)},fl=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}},pl=e=>new fl(e.readString()),ml=[_c,bc,Rc,Uc,Vc,Kc,Jc],hl=0,gl=1,_l=2,vl=3,yl=4,bl=5,xl=6,Sl=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 b()}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}},Cl=e=>new Sl(ml[e.readTypeRef()](e)),wl=(e,t,n)=>{let{client:r,clock:i}=t.id,a=new Q(H(r,i+n),t,H(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=H(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 Yc{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>=U(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=U(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===os&&this.id.client!==this.parent.client&&this.parent.clock>=U(n,this.parent.client))return this.parent.client;if(this.origin&&=(this.left=ys(t,n,this.origin),this.left.lastId),this.rightOrigin&&=(this.right=G(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===os){let e=_s(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=ys(e,e.doc.store,H(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),ss(this.origin,n.origin)){if(n.id.client<this.id.client)t=n,r.clear();else if(ss(this.rightOrigin,n.rightOrigin))break}else if(n.origin!==null&&i.has(_s(e.doc.store,n.origin)))r.has(_s(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),hs(e.doc.store,this),this.content.integrate(e,this),ws(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:H(this.id.client,this.id.clock+this.length-1)}mergeWith(e){if(this.constructor===e.constructor&&ss(e.origin,this.lastId)&&this.right===e&&ss(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(),So(e.deleteSet,this.id.client,this.id.clock,this.length),ws(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw x();this.content.gc(e),t?bs(e,this,new X(this.id,this.length)):this.content=new $c(this.length)}write(e,t){let n=t>0?H(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=cs(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===os?(e.writeParentInfo(!1),e.writeLeftID(t)):x();i!==null&&e.writeString(i)}this.content.write(e,t)}},Tl=(e,t)=>El[t&31](e),El=[()=>{x()},el,cl,Qc,pl,al,ol,Cl,dl,rl,()=>{x()}],Dl=10,$=class extends Yc{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,!0)}integrate(e,t){x()}write(e,t){e.writeInfo(Dl),T(e.restEncoder,this.length-t)}getMissing(e,t){return null}},Ol=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:{},kl=`__ $YJS$ __`,Ol[kl]===!0&&console.error(`Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438`),Ol[kl]=!0})),jl,Ml,Nl,Pl,Fl,Il=t((()=>{on(),kn(),Jn(),ct(),hr(),Ir(),jl=3e4,Ml=class extends mr{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&&Nl(this,t,`timeout`)},_(jl/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),Pr(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}},Nl=(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]))},Pl=(e,t,n=e.states)=>{let r=t.length,i=S();T(i,r);for(let a=0;a<r;a++){let r=t[a],o=n.get(r)||null,s=e.meta.get(r).clock;T(i,r),T(i,s),E(i,JSON.stringify(o))}return C(i)},Fl=(e,t,n)=>{let r=fn(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&&(Pr(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])}})),Ll,Rl,zl,Bl,Vl,Hl,Ul,Wl=t((()=>{fr(),mt(),yi(),$r(),Ll=new Map,Rl=class{constructor(e){this.room=e,this.onmessage=null,this._onChange=t=>t.key===e&&this.onmessage!==null&&this.onmessage({data:_i(t.newValue||``)}),Zr(this._onChange)}postMessage(e){Xr.setItem(this.room,gi(di(e)))}close(){Qr(this._onChange)}},zl=typeof BroadcastChannel>`u`?Rl:BroadcastChannel,Bl=e=>P(Ll,e,()=>{let t=pt(),n=new zl(e);return n.onmessage=e=>t.forEach(t=>t(e.data,`broadcastchannel`)),{bc:n,subs:t}}),Vl=(e,t)=>(Bl(e).subs.add(t),t),Hl=(e,t)=>{let n=Bl(e),r=n.subs.delete(t);return r&&n.subs.size===0&&(n.bc.close(),Ll.delete(e)),r},Ul=(e,t,n=null)=>{let r=Bl(e);r.bc.postMessage(t),r.subs.forEach(e=>e(t,n))}})),Gl,Kl,ql,Jl,Yl,Xl,Zl,Ql=t((()=>{on(),kn(),Al(),Gl=(e,t)=>{T(e,0);let n=es(t);D(e,n)},Kl=(e,t,n)=>{T(e,1),D(e,Jo(t,n))},ql=(e,t,n)=>Kl(t,n,O(e)),Jl=(e,t,n,r)=>{try{Go(t,O(e),n)}catch(e){r?.(e),console.error(`Caught error while handling a Yjs update`,e)}},Yl=(e,t)=>{T(e,2),D(e,t)},Xl=Jl,Zl=(e,t,n,r,i)=>{let a=k(e);switch(a){case 0:ql(e,t,n);break;case 1:Jl(e,n,r,i);break;case 2:Xl(e,n,r,i);break;default:throw Error(`Unknown message type`)}return a}})),$l,eu=t((()=>{kn(),$l=(e,t,n)=>{k(e)===0&&n(t,A(e))}})),tu,nu=t((()=>{jr(),tu=e=>Cr(e,(e,t)=>`${encodeURIComponent(t)}=${encodeURIComponent(e)}`).join(`&`)})),ru,iu,au,ou,su,cu,lu,uu,du,fu=t((()=>{Wl(),Jn(),on(),kn(),Ql(),eu(),Il(),hr(),ct(),nu(),li(),ru=[],ru[0]=(e,t,n,r,i)=>{T(e,0);let a=Zl(t,e,n.doc,n);r&&a===1&&!n.synced&&(n.synced=!0)},ru[3]=(e,t,n,r,i)=>{T(e,1),D(e,Pl(n.awareness,Array.from(n.awareness.getStates().keys())))},ru[1]=(e,t,n,r,i)=>{Fl(n.awareness,O(t),n)},ru[2]=(e,t,n,r,i)=>{$l(t,n.doc,(e,t)=>au(n,t))},iu=3e4,au=(e,t)=>console.warn(`Permission denied to access ${e.url}.\n${t}`),ou=(e,t,n)=>{let r=fn(t),i=S(),a=k(r),o=e.messageHandlers[a];return o?o(i,r,e,n,a):console.error(`Unable to compute message`),i},su=e=>!(e.code>=4400&&e.code<4500),cu=(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,Nl(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(lu,it(ot(2,e.wsUnsuccessfulReconnects)*100,e.maxBackoffTime),e),r!==null&&e.emit(`closed`,[r,e])}},lu=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=ou(e,new Uint8Array(n.data),!0);Lt(r)>1&&t.send(C(r))},t.onerror=n=>{e.ws===t&&e.emit(`connection-error`,[n,e])},t.onclose=n=>{cu(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=S();if(T(n,0),Gl(n,e.doc),t.send(C(n)),e.awareness.getLocalState()!==null){let n=S();T(n,1),D(n,Pl(e.awareness,[e.doc.clientID])),t.send(C(n))}},e.emit(`status`,[{status:`connecting`}])}},uu=(e,t)=>{let n=e.ws;e.wsconnected&&n&&n.readyState===n.OPEN&&n.send(t),e.bcconnected&&Ul(e.bcChannel,t,e)},du=class extends pr{constructor(e,t,n,{connect:r=!0,awareness:i=new Ml(n),params:a={},protocols:o=[],WebSocketPolyfill:s=WebSocket,resyncInterval:c=-1,maxBackoffTime:l=2500,disableBc:u=!1,shouldReconnect:d=su}={}){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=ru.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=S();T(e,0),Gl(e,n),this.ws.send(C(e))}},c)),this._bcSubscriber=(e,t)=>{if(t!==this){let t=ou(this,new Uint8Array(e),!1);Lt(t)>1&&Ul(this.bcChannel,C(t),this)}},this._updateHandler=(e,t)=>{if(t!==this){let t=S();T(t,0),Yl(t,e),uu(this,C(t))}},this.doc.on(`update`,this._updateHandler),this._awarenessUpdateHandler=({added:e,updated:t,removed:n},r)=>{let a=e.concat(t).concat(n),o=S();T(o,1),D(o,Pl(i,a)),uu(this,C(o))},this._exitHandler=()=>{Nl(this.awareness,[n.clientID],`app closed`)},F&&typeof process<`u`&&process.on(`exit`,this._exitHandler),i.on(`update`,this._awarenessUpdateHandler),this._checkInterval=setInterval(()=>{this.wsconnected&&iu<M()-this.wsLastMessageReceived&&cu(this,this.ws,null)},iu/10),r&&this.connect()}get url(){let e=tu(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(),F&&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||=(Vl(this.bcChannel,this._bcSubscriber),!0);let e=S();T(e,0),Gl(e,this.doc),Ul(this.bcChannel,C(e),this);let t=S();T(t,0),Kl(t,this.doc),Ul(this.bcChannel,C(t),this);let n=S();T(n,3),Ul(this.bcChannel,C(n),this);let r=S();T(r,1),D(r,Pl(this.awareness,[this.doc.clientID])),Ul(this.bcChannel,C(r),this)}disconnectBc(){let e=S();T(e,1),D(e,Pl(this.awareness,[this.doc.clientID],new Map)),uu(this,C(e)),this.bcconnected&&=(Hl(this.bcChannel,this._bcSubscriber),!1)}disconnect(){this.shouldConnect=!1,this.disconnectBc(),this.ws!==null&&cu(this,this.ws,null)}connect(){this.shouldConnect=!0,!this.wsconnected&&this.ws===null&&(lu(this),this.connectBc())}}})),pu=n({connectRealtimeRoom:()=>mu});function mu(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}${Yn(`/_vitehub/realtime/${encodeURIComponent(e)}`,n.baseURL)}`},ne=t.split(`/`).map(encodeURIComponent).join(`/`),re={};function ie(){l=!1,d=new ko,f=new du(te(),ne,d,{disableBc:!0,params:{...n.params,clientId:String(d.clientID)}});let e=f;Xn(e),e.messageHandlers[5]=(t,n)=>{let r=Rn(n);r&&(r.type===`session`?e.params.epoch=r.epoch:(e.destroy(),d.destroy(),u||(ie(),ee())))},e.messageHandlers[6]=(t,n)=>{let r=Un(n);if(r?.kind===`request`&&ae(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=S();T(o,1),D(o,Pl(e.awareness,i)),a.send(C(o))});let t=n.identity??{id:`guest:${d.clientID}`};e.awareness.setLocalState({...re,user:ir({...t,id:t.id||`guest:${d.clientID}`})}),e.awareness.on(`change`,ee),d.getMap(tr.status).observe(ee),e.on(`sync`,t=>{f===e&&(l=t,ee())}),e.on(`status`,e=>{c=e.status,ee()})}ie();let p;n.changes&&(p=new du(te(),encodeURIComponent(Gn),new ko,{disableBc:!0,params:{...n.params,workspace:`events`}}),p.awareness.setLocalState(null),Xn(p),p.messageHandlers[4]=(e,t)=>{let n=Bn(t);if(n)for(let e of i)e(n)},p.on(`status`,e=>{e.status===`connected`&&oe()}));async function ae(e,t,n){let r=e=>Hn({kind:`answer`,id:t,ok:!1,why:e}),i;try{i=s?Hn({kind:`answer`,id:t,ok:!0,body:await s(n)}):r(`This page does not answer requests.`),i.byteLength>hu&&(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 oe(){let e=p?.ws;if(p?.wsconnected&&e&&e.readyState===e.OPEN)for(;o.length;)e.send(Uint8Array.from(Vn(o.shift())))}return{get awareness(){return f.awareness},get clientId(){return d.clientID},people:()=>or(f.awareness.getStates()),states:()=>{let e=new Map(f.awareness.getStates());return e.delete(d.clientID),e},status:()=>c,saveStatus:()=>l?er(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){p&&(o.push(e),oe())},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(),p?.destroy(),p?.doc.destroy(),r.clear(),i.clear(),a.clear(),s=void 0}}}var hu,gu=t((()=>{Qn(),nr(),cr(),qn(),on(),Il(),fu(),Al(),hu=1047552}));l();var _u=new Map;function vu(e){try{return sessionStorage.getItem(e)??void 0}catch{return _u.get(e)}}function yu(e,t){t===void 0?_u.delete(e):_u.set(e,t);try{t===void 0?sessionStorage.removeItem(e):sessionStorage.setItem(e,t)}catch{}}function bu(e){return btoa(String.fromCharCode(...e)).replaceAll(`+`,`-`).replaceAll(`/`,`_`).replace(/=+$/,``)}function xu(e){if(typeof e!=`object`||!e||Array.isArray(e))throw f(400);return{...e}}function Su(e){let t=xu(e);for(let e of[`files`,`outbox`,`attachments`])delete t[e];return t}function Cu(e){if(typeof e!=`string`||e.length===0)throw f(400);return e}function wu(e){let t=typeof e==`object`&&e?Reflect.get(e,`subject`):void 0;if(typeof t!=`object`||!t)return;let n=Reflect.get(t,`kind`),r=Reflect.get(t,`id`);return typeof n==`string`&&typeof r==`string`?{kind:n,id:r}:void 0}function Tu(e){let t=e instanceof s?e:f(0,e),n=Reflect.get(t,`status`);return{code:t.code,why:t.message,...t.fix?{fix:t.fix}:{},status:typeof n==`number`?n:0}}async function Eu(e,t){let n={user:e.user,can:{read:e.can.read,comment:e.can.comment,resolve:e.can.resolve,delete:!1,change:!1},realtime:!1,attachments:!1,presence:!1,content:!1,...e.subject?{subject:e.subject}:{},...e.revision===void 0?{}:{revision:e.revision}};return e.user?n:{...n,signIn:{provider:`console`,url:await t()}}}function Du(e,t){let n=`/comments/${encodeURIComponent(t)}`,r=`vitehub-comments:${t}:token`,i=`vitehub-comments:${t}:verifier`,a=()=>{let e=vu(r);return e?{authorization:`Bearer ${e}`}:{}},o,s,c,l=0;function u(e){if(Reflect.get(Object(e),`type`)===re.type){yu(r,void 0),d(void 0),o?.postMessage({event:ye});return}let t=wu(e);t&&c&&t.kind===c.kind&&t.id===c.id&&o?.postMessage({event:ye})}async function d(e){let n=vu(r);c=e?.subject;let i=e?.realtime&&e.user&&n?ne(t):void 0;if(s&&s.room===i&&s.token===n||(s?.leave(),s=void 0,!i||!n))return;let a={room:i,token:n,leave:()=>{}};s=a;let o=await Te(()=>Promise.resolve().then(()=>(gu(),pu)),void 0,import.meta.url).catch(()=>void 0);if(!o||s!==a)return;let l=o.connectRealtimeRoom(te,i,{baseURL:`/`,params:{token:n}});l.onNotice(u),a.leave=()=>l.destroy()}async function ee(){let e=vu(i);e||(e=bu(crypto.getRandomValues(new Uint8Array(32))),yu(i,e));let t=bu(new Uint8Array(await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(e))));return`${location.origin}${n}/authorize?challenge=${t}`}let ie=()=>Eu({user:null,can:{read:!1,comment:!1,resolve:!1},realtime:!1,content:!1},ee);async function p(e){let t=++l,i=vu(r);if(!i)return d(void 0),await ie();let a=()=>t===l&&vu(r)===i,o=fe({route:`${n}/api`,headers:{authorization:`Bearer ${i}`},credentials:`omit`});try{let t=(await o(`/session?page=${encodeURIComponent(e)}`)).data;return a()&&d(t),await Eu(t,ee)}catch(e){if(Reflect.get(Object(e),`status`)!==401)throw e;return a()&&(yu(r,void 0),d(void 0)),await ie()}}async function ae(e){let t=vu(i);if(!t)return!1;let a=await fetch(`${n}/redeem`,{method:`POST`,credentials:`omit`,cache:`no-store`,headers:{"content-type":`application/json`},body:JSON.stringify({code:e,verifier:t})}).catch(e=>{throw f(0,e)}),o=await a.json().catch(()=>void 0),s=typeof o==`object`&&o?Reflect.get(o,`token`):void 0;if(!a.ok||typeof s!=`string`||!s)throw f(a.status);return yu(r,s),yu(i,void 0),!0}function oe(e,t){let{input:n}=e;switch(e.method){case`session`:return p(Cu(n));case`redeem`:return ae(Cu(n));case`list`:return t.list(xu(n));case`get`:return t.get(xu(n));case`create`:return t.create(Su(n));case`reply`:return t.reply(Su(n));case`resolve`:return t.resolve({threadId:Cu(xu(n).threadId)});case`reopen`:return t.reopen({threadId:Cu(xu(n).threadId)})}}async function se(e){let t=[],r=ge({route:`${n}/api`,headers:a,credentials:`omit`,onAnswer:e=>t.push(...e.people)});try{return{id:e.id,ok:!0,value:await oe(e,r),people:t}}catch(t){return{id:e.id,ok:!1,error:Tu(t)}}}addEventListener(`message`,t=>{if(o||t.origin!==e||t.source!==parent||t.data===null||typeof t.data!=`object`||Reflect.get(t.data,`type`)!==`vitehub-comments:connect`)return;let[n]=t.ports;n&&(o=n,n.addEventListener(`message`,e=>{ve(e.data)&&se(e.data).then(e=>n.postMessage(e))}),n.start(),n.postMessage({event:`ready`}))})}var{origin:Ou,project:ku}=document.documentElement.dataset;Ou&&ku&&parent!==window&&Du(Ou,ku);
|
|
1
|
+
var e=Object.defineProperty,t=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(e){throw n=[e],e}},n=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],enumerable:!0});return n||e(r,Symbol.toStringTag,{value:`Module`}),r};function r(e,...t){return typeof e==`function`?e(...t):e}function i(e,t){return typeof e==`string`?`${e}/${t.toLowerCase()}`:e?.(t)}function a(e){let t=e.reporters??[],n=Symbol(),a=Object.defineProperty({},"is",{value:c(n)}),{docsBase:o}=e;for(let c of Object.keys(e.codes)){let l=e.codes[c],u=l.docs===!1?void 0:l.docs||i(o,c),d=(e={},i={})=>{let a=new s({code:c,why:r(l.why,e),fix:r(l.fix,e),docs:u,cause:e.cause,sources:e.sources,data:r(l.data,e)},d);a[n]=1;for(let e of t)e(a,i);return a};d.is=e=>a.is(e)&&e.code===c,a[c]=d}return a}var o,s,c,l=t((()=>{o=Error.captureStackTrace,s=class e extends Error{get why(){return this.message}constructor(t,n=e){super(t.why,{cause:t.cause}),this.code=this.name=t.code,this.docs=t.docs,this.fix=t.fix,this.sources=t.sources,this.data=t.data,o?.(this,n)}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}}},c=e=>t=>t instanceof s&&e in t}));l();var u=a({docsBase:`https://vitehub.dev/docs/comments/diagnostics`,codes:{COMMENTS_HOSTED_CONFLICT:{why:`This page runs the app's own Comments, so the Hosted Comments script does not start its overlay.`,fix:"Remove the Hosted Comments script, or keep it and set `comments: { overlay: false }` to turn off the app's overlay. See https://vitehub.dev/docs/comments/configure#add-hosted-comments"},COMMENTS_OUTBOX_ACCOUNT_CHANGED:{why:`The current author is not the author of this queued comment.`,fix:`Sign in as the original author and retry the outbox.`},COMMENTS_OUTBOX_RESOLVE_BLOCKED:{why:`Queued delivery must resume before the thread can close.`,fix:`Go online, then retry or dismiss any blocked comments and resolve the thread again.`},COMMENTS_OUTBOX_SENDING:{why:`The server may already have this comment, so the draft cannot change.`,fix:`Wait for delivery to finish, then edit or delete the server copy.`},COMMENTS_OVERLAY_ELEMENT_TAKEN:{why:({name:e})=>`Another script defined the <${e}> element, so this Comments overlay cannot start.`,fix:`Load one Comments overlay script on the page. Remove the other script that defines the element.`},COMMENTS_R0001:{why:({target:e})=>`createAnchor() found nothing to anchor to for ${e}.`,fix:`Pass an element, a non-empty selection, or a point that is over an element of the page.`},COMMENTS_R0013:{why:`The comments request did not get an answer from the server.`,fix:`Check the connection and the app URL, then try again.`},COMMENTS_R0015:{why:`The comment list kept changing while its pages were loading.`,fix:`Refresh again. The previous cache is kept until two complete scans agree.`}}});function d(e){let{code:t,details:n,fix:r,retryAfter:i,status:a,why:o}=e,c=t.startsWith(`COMMENTS_`)?`https://vitehub.dev/docs/comments/diagnostics/${t.toLowerCase()}`:void 0;return Object.assign(new s({code:t,why:o,...r?{fix:r}:{},...c?{docs:c}:{}}),{status:a,...n?{details:n}:{},...i===void 0?{}:{retryAfter:i}})}function f(e,t,n){return Object.assign(u.COMMENTS_R0013(t===void 0?{}:{cause:t}),{status:e,...n===void 0?{}:{retryAfter:n}})}var ee=`/_vitehub/comments`,te=`hosted-comments`;function ne(e){return`projects/${encodeURIComponent(e)}`}var re={type:`ended`},ie=`x-vitehub-comments-outbox-account`,p=new WeakMap;async function ae(e){let t=new Uint8Array(await e.arrayBuffer()),n=``;for(let e=0;e<t.length;e+=32768)n+=String.fromCharCode(...t.subarray(e,e+32768));return btoa(n)}function oe(e){if(e instanceof File&&e.name)return e.name;let t=/^[a-z]+\/([a-z0-9]+)/i.exec(e.type)?.[1];return t?`file.${t}`:`file`}async function se(e,t,n,r){let i=[];for(let a of e){let e=await n({name:oe(a),type:a.type||`application/octet-stream`,data:await ae(a),...t?{subject:t}:{}});await r?.(e.key),i.push(e.key)}return i}async function ce(e,{files:t,outbox:n},r,i){if(!t?.length)return e;try{return{...e,attachments:[...e.attachments??[],...await se(t,r,i,n?.uploaded)]}}catch(e){throw n&&p.set(n,{cause:e}),e}}function le(e,t=Date.now()){let n=e.headers.get(`retry-after`)?.trim();if(!n)return;if(/^\d+$/.test(n))return Number(n)*1e3;let r=Date.parse(n);return Number.isNaN(r)?void 0:Math.max(0,r-t)}function ue(e){return Object(e)===e&&!Array.isArray(e)}function de(e,t=``){return`${t.replace(/\/+$/,``)}${ee}/attachments/${e.split(`/`).map(e=>encodeURIComponent(e)).join(`/`)}`}function fe(e={}){let t=e.route??`${(e.base??``).replace(/\/+$/,``)}/_vitehub/comments`;return async(n,r={})=>{let i=e.fetch??globalThis.fetch,a=new Headers(typeof e.headers==`function`?await e.headers():e.headers);for(let[e,t]of new Headers(r.headers))a.set(e,t);r.body!==void 0&&!a.has(`content-type`)&&a.set(`content-type`,`application/json`);let o=typeof e.guest==`function`?e.guest():e.guest;o&&(a.set(`x-vitehub-comments-guest-id`,o.id),a.set(`x-vitehub-comments-guest-name`,encodeURIComponent(o.name)));let s;try{s=await i(`${t}${n}`,{...r,headers:a,credentials:e.credentials??`same-origin`,cache:`no-store`})}catch(e){throw f(0,e)}let c=await s.json().catch(()=>void 0),l=le(s);if(ue(c)&&ue(c.error)){let{code:e,why:t,fix:n}=c.error;throw typeof e!=`string`||typeof t!=`string`?f(s.status,void 0,l):d({code:e,why:t,...typeof n==`string`?{fix:n}:{},...l===void 0?{}:{retryAfter:l},status:s.status})}if(ue(c)&&`data`in c){let t={data:c.data,people:Array.isArray(c.people)?c.people:[],...ue(c.thread)?{thread:c.thread}:{}};return e.onAnswer?.(t),t}throw f(s.status,void 0,l)}}function pe(e){let t=new URLSearchParams;return e.page!==void 0&&t.set(`page`,e.page),e.subject?(t.set(`subjectKind`,e.subject.kind),t.set(`subjectId`,e.subject.id)):e.subjectKind&&t.set(`subjectKind`,e.subjectKind),e.status&&t.set(`status`,e.status),e.mine!==void 0&&t.set(`mine`,String(e.mine)),e.mentions!==void 0&&t.set(`mentions`,String(e.mentions)),e.revision&&t.set(`revision`,String(e.revision.lte)),e.limit!==void 0&&t.set(`limit`,String(e.limit)),e.before&&(t.set(`beforeId`,e.before.id),t.set(`beforeUpdatedAt`,String(e.before.updatedAt))),t}var me=e=>`/threads/${encodeURIComponent(e)}`,he=(e,t)=>({method:`POST`,...e===void 0?{}:{body:JSON.stringify(e)},...t===void 0?{}:{headers:{[ie]:encodeURIComponent(t)}}});function ge(e={}){let t=fe(e),n=(e.base??``).replace(/\/+$/,``),r=async(e,n)=>(await t(`/attachments`,he(e,n))).data;return{async list(e){return(await t(`/threads?${pe(e)}`)).data},async get(e){let n=`threadId`in e?me(e.threadId):`/scopes/${encodeURIComponent(e.scope)}/threads/${e.n}`;return(await t(n)).data},async create({files:e,outbox:n,...i}){let a=await ce(i,{files:e,outbox:n},i.subject,e=>r(e,n?.account));return(await t(`/threads`,he(a,n?.account))).data},async reply({threadId:e,subject:n,files:i,outbox:a,...o}){let s=await ce(o,{files:i,outbox:a},n,e=>r(e,a?.account)),c=await t(`${me(e)}/comments`,he(s,a?.account));if(!c.thread)throw f(200);return c.thread},async edit({threadId:e,messageId:n,...r}){return(await t(`${me(e)}/comments/${encodeURIComponent(n)}`,{method:`PATCH`,body:JSON.stringify(r)})).data},async delete({threadId:e,messageId:n}){let r=n===void 0?me(e):`${me(e)}/comments/${encodeURIComponent(n)}`;return(await t(r,{method:`DELETE`})).data},async resolve({threadId:e}){return(await t(`${me(e)}/resolve`,he())).data},async reopen({threadId:e}){return(await t(`${me(e)}/reopen`,he())).data},async users({query:e,limit:n,threadId:r,subject:i}){let a=new URLSearchParams({q:e});return n!==void 0&&a.set(`limit`,String(n)),r===void 0?i&&(a.set(`subjectKind`,i.kind),a.set(`subjectId`,i.id)):a.set(`thread`,r),(await t(`/people?${a}`)).data},upload:e=>r(e),attachmentUrl:e=>de(e,n)}}var _e=[`session`,`list`,`get`,`create`,`reply`,`resolve`,`reopen`,`redeem`];function ve(e){if(typeof e!=`object`||!e)return!1;let t=Reflect.get(e,`id`),n=Reflect.get(e,`method`);return typeof t==`number`&&Number.isSafeInteger(t)&&_e.some(e=>e===n)}var ye=`changed`,be=`modulepreload`,xe=function(e,t){return new URL(e,t).href},Se={},Ce=function(e){return e.pathname.endsWith(`.css`)},we=function(e,t,n){if(t in e)return e[t];let r=n();if(!r){e[t]=void 0;return}let i=r.then(()=>{e[t]=void 0},n=>{throw e[t]=void 0,n});return e[t]=i,i},Te=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e,i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?new URL(import.meta.resolve(e)):new URL(e,import.meta.url)}r=o(t.map(t=>{t=xe(t,n);let r=s(t),i=Ce(r);return we(Se,r.href,()=>{if(e===void 0){e={all:new Set,styles:new Set};let t=document.getElementsByTagName(`link`);for(let n=t.length-1;n>=0;n--){let r=t[n];e.all.add(r.href),r.rel===`stylesheet`&&e.styles.add(r.href)}}if((i?e.styles:e.all).has(r.href))return;let t=document.createElement(`link`);if(t.rel=i?`stylesheet`:be,i||(t.as=`script`),t.crossOrigin=``,t.href=r.href,a&&t.setAttribute(`nonce`,a),document.head.appendChild(t),i)return new Promise((e,n)=>{let i=a=>{t.removeEventListener(`load`,i),t.removeEventListener(`error`,i),a.type===`error`?n(Error(`Unable to preload CSS for ${r}`)):e(a)};t.addEventListener(`load`,i),t.addEventListener(`error`,i)})})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},m,Ee,De,Oe=t((()=>{l(),m={why:({message:e})=>e===void 0?``:String(e)},Ee={RUNTIME_R0001:{...m,fix:"Pass `maxDepth` to `normalizeRuntimeDiagnosticError()` as an integer of 0 or more, or remove it to use the default."},RUNTIME_R0002:{...m,fix:"Pass `maxErrors` to `normalizeRuntimeDiagnosticError()` as an integer of 1 or more, or remove it to use the default."},RUNTIME_R0003:{...m,fix:"Pass `maxStringLength` to `normalizeRuntimeDiagnosticError()` as an integer of 64 or more, or remove it to use the default."},RUNTIME_R0004:{...m,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:{...m,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:{...m,fix:"Pass `new ViteHubError()` a nonempty `code` and `message` string within the length limits, and plain JSON `details`."},RUNTIME_R0007:{...m,fix:"Give the execution authority a valid value for each of `credentials`, `environment`, `filesystem.access`, `filesystem.scope`, `isolation`, `network`, and `processes`."},RUNTIME_R0009:{...m,fix:"Set `intervalMs` of the process reconciler to a number of milliseconds from 1 to 2147483647."},RUNTIME_R0010:{...m,fix:"Give the process reconciler a `signal` other than `SIGKILL` or `SIGSTOP`, or set `signal: false`."},RUNTIME_R0011:{...m,fix:"Call `drain()` of the process reconciler after its callback returns, not from inside the callback."},RUNTIME_R0015:{...m,fix:"Pass the `Request` of a Fetchable handler, or the event of an H3 or Nitro route, to `getStandardContext()`."},RUNTIME_R0016:{...m,fix:"Return the body or a `Response` from the handler, in place of setting `~standard.res.body`."},RUNTIME_R0017:m,RUNTIME_R0018:m,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()`."}},De=a({docsBase:`https://vitehub.dev/docs/runtime/diagnostics`,codes:Ee})}));function h(){throw De.RUNTIME_R0006({message:`[vitehub] ViteHubError requires a valid public error contract.`})}function ke(e){try{return Array.isArray(e)}catch{h()}}function g(e,t,n=!1){try{let r=Object.getOwnPropertyDescriptor(e,t);return r===void 0?void 0:((!(`value`in r)||n&&!r.enumerable)&&h(),r.value)}catch{h()}}function Ae(e,t,n,r){if(t.nodes+=1,t.nodes>Ie&&h(),e===void 0&&r)return;if(e===null||typeof e==`boolean`||typeof e==`string`&&e.length<=Le||typeof e==`number`&&Number.isFinite(e))return e;(typeof e!=`object`||n>Ne||t.ancestors.has(e))&&h();let i,a;try{i=Object.getPrototypeOf(e),a=Reflect.ownKeys(e)}catch{h()}t.ancestors.add(e);try{if(ke(e)){let r=g(e,`length`);(!Number.isSafeInteger(r)||r<0||r>Pe||a.length!==r+1||!a.includes(`length`))&&h();let i=[];for(let o=0;o<r;o+=1){let r=String(o);a.includes(r)||h(),i.push(Ae(g(e,r,!0),t,n+1,!1))}return Object.freeze(i)}i!==Object.prototype&&i!==null&&h(),(a.length>Pe||a.some(e=>typeof e!=`string`))&&h();let r={};for(let i of a)(i.length===0||i.length>Fe)&&h(),Object.defineProperty(r,i,{enumerable:!0,value:Ae(g(e,i,!0),t,n+1,!0),writable:!0});return Object.freeze(r)}finally{t.ancestors.delete(e)}}function je(e){if(e!==void 0)return(typeof e!=`object`||!e||ke(e))&&h(),Ae(e,{ancestors:new Set,nodes:0},0,!1)}function Me(e,t,n){(typeof e!=`string`||e.length===0||e.length>Re)&&h(),(typeof t!=`string`||t.length===0||t.length>ze)&&h(),(typeof n!=`object`||!n||ke(n))&&h();let r=g(n,`cause`),i=je(g(n,`details`)),a=g(n,`requestId`);return a!==void 0&&(typeof a!=`string`||a.length===0||a.length>Be)&&h(),{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 Ne,Pe,Fe,Ie,Le,Re,ze,Be,Ve,He,Ue=t((()=>{Oe(),Ne=8,Pe=128,Fe=128,Ie=1024,Le=16384,Re=128,ze=16384,Be=256,Ve=new WeakMap,He=class extends Error{code;details;requestId;constructor(e,t,n={}){let r=Me(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}}),Ve.set(this,r.shape)}toJSON(){let e=Ve.get(this);if(e)return e;let t=Me(g(this,`code`),g(this,`message`),{details:g(this,`details`),requestId:g(this,`requestId`)});return Ve.set(this,t.shape),t.shape}}}));function We(e){return e!==null&&Object(e)===e}function Ge(e){if(!We(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}}var Ke=t((()=>{}));function qe(e){if(!Ge(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 Je=t((()=>{Ke()}));function Ye(e){let t=t=>{let n=Object.getOwnPropertyDescriptor(e,t);return n?n.configurable===!0:Object.isExtensible(e)},n=t(`name`)&&t(`toJSON`)&&(Object.hasOwn(e,Ze)||Object.isExtensible(e))?e:new s({code:e.code,why:e.why,fix:e.fix,docs:e.docs,cause:e.cause,data:e.data,sources:e.sources});if(n!==e){n.stack=e.stack;let t=Reflect.get(e,`status`);typeof t==`number`&&Object.defineProperty(n,"status",{configurable:!0,value:t})}return Object.defineProperty(n,"name",{configurable:!0,value:n.code,writable:!0}),Object.defineProperty(n,Ze,{value:!0}),Object.defineProperty(n,"toJSON",{configurable:!0,value:()=>({code:n.code,docs:n.docs,fix:n.fix,name:n.name,why:n.why})}),n}function Xe(e){let t=a({codes:e.codes,docsBase:e.docs}),n=new Set(Object.keys(e.codes)),r=Object.defineProperty({},"is",{value:e=>qe(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=Ye(n(e));return a!==void 0&&Object.defineProperty(t,"status",{configurable:!0,enumerable:!1,value:a}),t},{is:e=>qe(e)&&e.code===i})}return r}var Ze,Qe=t((()=>{Je(),l(),Ze=Symbol.for(`vitehub.runtime.resultError`)})),$e=t((()=>{Ue(),Qe()})),et,tt=t((()=>{$e(),et=Xe({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} }\`.`}}})})),nt=t((()=>{})),_,rt,it,at,ot,st,ct=t((()=>{_=Math.floor,rt=Math.abs,it=(e,t)=>e<t?e:t,at=(e,t)=>e>t?e:t,Number.isNaN,ot=Math.pow,st=e=>e===0?1/e<0:e<0})),lt,ut,dt,ft=t((()=>{ct(),lt=2**53-1,ut=-(2**53-1),dt=Number.isInteger||(e=>typeof e==`number`&&isFinite(e)&&_(e)===e),Number.isNaN,Number.parseInt})),pt,mt=t((()=>{pt=()=>new Set})),ht,gt,v,_t,vt,yt,bt,xt=t((()=>{ht=e=>e[e.length-1],gt=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},v=Array.from,_t=(e,t)=>{for(let n=0;n<e.length;n++)if(!t(e[n],n,e))return!1;return!0},vt=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1},yt=(e,t)=>{let n=Array(e);for(let r=0;r<e;r++)n[r]=t(r,n);return n},bt=Array.isArray})),St,Ct,wt,Tt,Et,Dt,Ot,kt,At,jt,Mt,Nt,Pt=t((()=>{xt(),St=String.fromCharCode,String.fromCodePoint,St(65535),Ct=e=>e.toLowerCase(),wt=/^\s*/g,Tt=e=>e.replace(wt,``),Et=/([A-Z])/g,Dt=(e,t)=>Tt(e.replace(Et,e=>`${t}${Ct(e)}`)),Ot=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},kt=typeof TextEncoder<`u`?new TextEncoder:null,At=e=>kt.encode(e),jt=kt?At:Ot,Mt=typeof TextDecoder>`u`?null:new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0}),Mt&&Mt.decode(new Uint8Array).length===1&&(Mt=null),Nt=(e,t)=>yt(t,()=>e).join(``)})),y,b,x,Ft=t((()=>{y=e=>Error(e),b=()=>{throw y(`Method unimplemented`)},x=()=>{throw y(`Unexpected case`)}})),It,S,Lt,C,Rt,w,zt,T,Bt,Vt,Ht,Ut,Wt,E,Gt,D,Kt,qt,Jt,Yt,Xt,Zt,Qt,$t,en,tn,nn,rn,an,on=t((()=>{ct(),ft(),nt(),Pt(),xt(),It=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},S=()=>new It,Lt=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t},C=e=>{let t=new Uint8Array(Lt(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},Rt=(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(at(n,t)*2),e.cpos=0)},w=(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},zt=w,T=(e,t)=>{for(;t>127;)w(e,128|127&t),t=_(t/128);w(e,127&t)},Bt=(e,t)=>{let n=st(t);for(n&&(t=-t),w(e,(t>63?128:0)|(n?64:0)|63&t),t=_(t/64);t>0;)w(e,(t>127?128:0)|127&t),t=_(t/128)},Vt=new Uint8Array(3e4),Ht=Vt.length/3,Ut=(e,t)=>{if(t.length<Ht){let n=kt.encodeInto(t,Vt).written||0;T(e,n);for(let t=0;t<n;t++)w(e,Vt[t])}else D(e,jt(t))},Wt=(e,t)=>{let n=unescape(encodeURIComponent(t)),r=n.length;T(e,r);for(let t=0;t<r;t++)w(e,n.codePointAt(t))},E=kt&&kt.encodeInto?Ut:Wt,Gt=(e,t)=>{let n=e.cbuf.length,r=e.cpos,i=it(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(at(n*2,a)),e.cbuf.set(t.subarray(i)),e.cpos=a)},D=(e,t)=>{T(e,t.byteLength),Gt(e,t)},Kt=(e,t)=>{Rt(e,t);let n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},qt=(e,t)=>Kt(e,4).setFloat32(0,t,!1),Jt=(e,t)=>Kt(e,8).setFloat64(0,t,!1),Yt=(e,t)=>Kt(e,8).setBigInt64(0,t,!1),Xt=new DataView(new ArrayBuffer(4)),Zt=e=>(Xt.setFloat32(0,e),Xt.getFloat32(0)===e),Qt=(e,t)=>{switch(typeof t){case`string`:w(e,119),E(e,t);break;case`number`:dt(t)&&rt(t)<=2147483647?(w(e,125),Bt(e,t)):Zt(t)?(w(e,124),qt(e,t)):(w(e,123),Jt(e,t));break;case`bigint`:w(e,122),Yt(e,t);break;case`object`:if(t===null)w(e,126);else if(bt(t)){w(e,117),T(e,t.length);for(let n=0;n<t.length;n++)Qt(e,t[n])}else if(t instanceof Uint8Array)w(e,116),D(e,t);else{w(e,118);let n=Object.keys(t);T(e,n.length);for(let r=0;r<n.length;r++){let i=n[r];E(e,i),Qt(e,t[i])}}break;case`boolean`:w(e,t?120:121);break;default:w(e,127)}},$t=class extends It{constructor(e){super(),this.w=e,this.s=null,this.count=0}write(e){this.s===e?this.count++:(this.count>0&&T(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}},en=e=>{e.count>0&&(Bt(e.encoder,e.count===1?e.s:-e.s),e.count>1&&T(e.encoder,e.count-2))},tn=class{constructor(){this.encoder=new It,this.s=0,this.count=0}write(e){this.s===e?this.count++:(en(this),this.count=1,this.s=e)}toUint8Array(){return en(this),C(this.encoder)}},nn=e=>{if(e.count>0){let t=e.diff*2+(e.count===1?0:1);Bt(e.encoder,t),e.count>1&&T(e.encoder,e.count-2)}},rn=class{constructor(){this.encoder=new It,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(nn(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return nn(this),C(this.encoder)}},an=class{constructor(){this.sarr=[],this.s=``,this.lensE=new tn}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 It;return this.sarr.push(this.s),this.s=``,E(e,this.sarr.join(``)),Gt(e,this.lensE.toUint8Array()),C(e)}}})),sn,cn,ln,un,dn,fn,pn,mn,O,hn,k,gn,_n,vn,A,yn,bn,xn,Sn,Cn,wn,Tn,En,Dn,On,kn=t((()=>{nt(),ct(),ft(),Pt(),Ft(),sn=y(`Unexpected end of array`),cn=y(`Integer out of Range`),ln=(e,t,n)=>{if(t<0||n<0||t+n>e.length)throw sn;return new Uint8Array(e.buffer,e.byteOffset+t,n)},un=(e,t,n)=>{if(t<0||n<0||t+n>e.length)throw sn;return new DataView(e.buffer,e.byteOffset+t,n)},dn=class{constructor(e){this.arr=e,this.pos=0}},fn=e=>new dn(e),pn=e=>e.pos!==e.arr.length,mn=(e,t)=>{let n=ln(e.arr,e.pos,t);return e.pos+=t,n},O=e=>mn(e,k(e)),hn=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>lt)throw cn}throw sn},gn=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>lt)throw cn}throw sn},_n=e=>{let t=k(e);if(t===0)return``;{let n=String.fromCodePoint(hn(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(hn(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))}},vn=e=>Mt.decode(O(e)),A=Mt?vn:_n,yn=(e,t)=>{let n=un(e.arr,e.pos,t);return e.pos+=t,n},bn=e=>yn(e,4).getFloat32(0,!1),xn=e=>yn(e,8).getFloat64(0,!1),Sn=e=>yn(e,8).getBigInt64(0,!1),Cn=[e=>void 0,e=>null,gn,bn,xn,Sn,e=>!1,e=>!0,A,e=>{let t=k(e),n={};for(let r=0;r<t;r++){let t=A(e);n[t]=wn(e)}return n},e=>{let t=k(e),n=[];for(let r=0;r<t;r++)n.push(wn(e));return n},O],wn=e=>Cn[127-hn(e)](e),Tn=class extends dn{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=pn(this)?k(this)+1:-1),this.count--,this.s}},En=class extends dn{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=gn(this);let e=st(this.s);this.count=1,e&&(this.s=-this.s,this.count=k(this)+2)}return this.count--,this.s}},Dn=class extends dn{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){let e=gn(this),t=e&1;this.diff=_(e/2),this.count=1,t&&(this.count=k(this)+2)}return this.s+=this.diff,this.count--,this.s}},On=class{constructor(e){this.decoder=new En(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}}})),An,j,jn,Mn=t((()=>{l(),An={why:({message:e})=>e===void 0?``:String(e)},j=e=>({...An,fix:e}),jn=a({docsBase:`https://vitehub.dev/docs/workspace/diagnostics`,codes:{WORKSPACE_CONFLICT:{...An,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 Nn(e,t={},n=`[vitehub] ${e.why}`){let r=new He(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 Pn(e,t=`not-relative`){let n=e.slice(0,4096);return Nn(jn.WORKSPACE_PATH_INVALID({path:JSON.stringify(n),problem:t}),{details:{path:n}})}function Fn(e){let t=e.toLowerCase().split(`:`,1)[0];return{normalized:t.replace(/[ .]+$/,``),isTraversal:/^(?:\.(?: +[. ]*)?|\.\.(?: +[. ]*)?)$/.test(t)}}function In(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 Pn(e);let a=i.map((e,t)=>({classification:Fn(e),index:t,name:e.toLowerCase()}));if(a.some(({classification:e})=>e.isTraversal))throw Pn(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 Pn(e,`reserved`);return r}var Ln=t((()=>{Mn(),$e()}));function Rn(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 zn(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 In(e)===e}catch{return!1}}function Bn(e){try{let t=JSON.parse(A(e));if((t.operation===`create`||t.operation===`delete`||t.operation===`update`)&&zn(t.path))return{operation:t.operation,path:t.path};if(t.operation===`move`&&zn(t.from)&&zn(t.to))return{operation:t.operation,from:t.from,to:t.to}}catch{}}function Vn(e){let t=S();return T(t,4),E(t,JSON.stringify(e)),C(t)}function Hn(e){let t=S();return T(t,6),E(t,JSON.stringify(e)),C(t)}function Un(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 Wn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var Gn,Kn,qn=t((()=>{kn(),on(),Ln(),Gn=`@workspace`,Kn=`ping`})),M,Jn=t((()=>{M=Date.now}));function Yn(e,t=typeof __VITEHUB_APP_BASE_URL__>`u`?`/`:__VITEHUB_APP_BASE_URL__){return t===`/`?e:`${t.replace(/\/+$/,``)}${e}`}function Xn(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(Kn)},Qn)})}function Zn(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 Qn,$n=t((()=>{qn(),Jn(),Qn=15e3}));function er(e){return typeof e==`string`?e:null}function tr(e){let t=e.getMap(nr.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:er(t.get(`digest`)),error:er(t.get(`error`)),issues:i.issues,savedAt:er(t.get(`savedAt`)),savedBy:i.savedBy}}var nr,rr=t((()=>{nr=Object.freeze({body:`body`,fields:`fields`,status:`status`})}));function ir(e){try{return String(e)===e}catch{return!1}}function ar(e){if(!ir(e.id)||!e.id||e.id.length>256)throw et.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=(ir(e.name)&&e.name||ir(e.email)&&e.email||`Anonymous`).slice(0,256),r={color:cr[Math.abs(t)%cr.length],id:e.id,name:n};return ir(e.image)&&e.image&&e.image.length<=2048&&(r.image=e.image),r}function or(e){return Wn(e)?ir(e.id)&&e.id.length>0&&e.id.length<=256&&ir(e.name)&&e.name.length>0&&e.name.length<=256&&ir(e.color)&&/^#[\da-f]{6}$/i.test(e.color)&&(e.image===void 0||ir(e.image)&&e.image.length<=2048):!1}function sr(e){let t=[];for(let[n,r]of e)if(or(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 cr,lr=t((()=>{qn(),tt(),cr=[`#E11D48`,`#D97706`,`#059669`,`#0891B2`,`#2563EB`,`#7C3AED`,`#C026D3`]})),N,ur,P,dr,fr,pr=t((()=>{N=()=>new Map,ur=e=>{let t=N();return e.forEach((e,n)=>{t.set(n,e)}),t},P=(e,t,n)=>{let r=e.get(t);return r===void 0&&e.set(t,r=n()),r},dr=(e,t)=>{let n=[];for(let[r,i]of e)n.push(t(i,r));return n},fr=(e,t)=>{for(let[n,r]of e)if(t(r,n))return!0;return!1}})),mr,hr,gr=t((()=>{pr(),mt(),xt(),mr=class{constructor(){this._observers=N()}on(e,t){return P(this._observers,e,pt).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 v((this._observers.get(e)||N()).values()).forEach(e=>e(...t))}destroy(){this._observers=N()}},hr=class{constructor(){this._observers=N()}on(e,t){P(this._observers,e,pt).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 v((this._observers.get(e)||N()).values()).forEach(e=>e(...t))}destroy(){this._observers=N()}}})),_r,vr,yr=t((()=>{_r=Symbol(`Equality`),vr=(e,t)=>e===t||!!e?.[_r]?.(t)||!1})),br,xr,Sr,Cr,wr,Tr,Er,Dr,Or,kr,Ar,jr,Mr=t((()=>{yr(),br=e=>typeof e==`object`,xr=Object.assign,Sr=Object.keys,Cr=(e,t)=>{for(let n in e)t(e[n],n)},wr=(e,t)=>{let n=[];for(let r in e)n.push(t(e[r],r));return n},Tr=e=>Sr(e).length,Er=e=>{for(let t in e)return!1;return!0},Dr=(e,t)=>{for(let n in e)if(!t(e[n],n))return!1;return!0},Or=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),kr=(e,t)=>e===t||Tr(e)===Tr(t)&&Dr(e,(e,n)=>(e!==void 0||Or(t,n))&&vr(t[n],e)),Ar=Object.freeze,jr=e=>{for(let t in e){let n=e[t];(typeof n==`object`||typeof n==`function`)&&jr(e[t])}return Ar(e)}})),Nr,Pr,Fr,Ir,Lr=t((()=>{Mr(),yr(),Nr=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&Nr(e,t,n+1)}},Pr=e=>e,Fr=(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[_r]!=null)return e[_r](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)||!Fr(e.get(n),t.get(n)))return!1;break;case void 0:case Object:if(Tr(e)!==Tr(t))return!1;for(let n in e)if(!Or(e,n)||!Fr(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(!Fr(e[n],t[n]))return!1;break;default:return!1}return!0},Ir=(e,t)=>t.includes(e)})),Rr,zr=t((()=>{crypto.subtle,Rr=crypto.getRandomValues.bind(crypto)})),Br,Vr,Hr,Ur=t((()=>{zr(),Br=()=>Rr(new Uint32Array(1))[0],Vr=`10000000-1000-4000-8000-100000000000`,Hr=()=>Vr.replace(/[018]/g,e=>(e^Br()&15>>e/4).toString(16))})),Wr,Gr=t((()=>{Wr=e=>new Promise(e),Promise.all.bind(Promise)})),Kr,qr=t((()=>{Kr=e=>e===void 0?null:e})),Jr,Yr,Xr,Zr,Qr,$r,ei=t((()=>{Jr=class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}},Yr=new Jr,Xr=!0;try{typeof window<`u`&&typeof localStorage<`u`&&localStorage&&(Yr=localStorage,Xr=!1)}catch{}Zr=Yr,Qr=e=>Xr||addEventListener(`storage`,e),$r=e=>Xr||removeEventListener(`storage`,e)})),F,ti,I,ni,ri,ii,ai,oi,si,ci,li,ui=t((()=>{pr(),Pt(),qr(),ei(),Lr(),F=typeof process<`u`&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<`u`?process:0)===`[object process]`,ti=typeof window<`u`&&typeof document<`u`&&!F,typeof navigator<`u`&&/Mac/.test(navigator.platform),ni=[],ri=()=>{if(I===void 0){if(F){I=N();let e=process.argv,t=null;for(let n=0;n<e.length;n++){let r=e[n];r[0]===`-`?(t!==null&&I.set(t,``),t=r):t===null?ni.push(r):(I.set(t,r),t=null)}t!==null&&I.set(t,``)}else typeof location==`object`?(I=N(),(location.search||`?`).slice(1).split(`&`).forEach(e=>{if(e.length!==0){let[t,n]=e.split(`=`);I.set(`--${Dt(t,`-`)}`,n),I.set(`-${Dt(t,`-`)}`,n)}})):I=N()}return I},ii=e=>ri().has(e),ai=e=>Kr(F?{}[e.toUpperCase().replaceAll(`-`,`_`)]:Zr.getItem(e)),oi=e=>ii(`--`+e)||ai(e)!==null,si=oi(`production`),ci=F&&Ir({}.FORCE_COLOR,[`true`,`1`,`2`]),li=ci||!ii(`--no-colors`)&&!oi(`no-color`)&&(!F||process.stdout.isTTY)&&(!F||ii(`--color`)||ai(`COLORTERM`)!==null||(ai(`TERM`)||``).includes(`color`))})),di,fi,pi,mi,hi,gi,_i,vi,yi,bi=t((()=>{Pt(),ui(),di=e=>new Uint8Array(e),fi=e=>new Uint8Array(e),pi=e=>{let t=``;for(let n=0;n<e.byteLength;n++)t+=St(e[n]);return btoa(t)},mi=e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString(`base64`),hi=e=>{let t=atob(e),n=di(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n},gi=e=>new Uint8Array(Buffer.from(e,`base64`)),_i=ti?pi:mi,vi=ti?hi:gi,yi=e=>{let t=di(e.byteLength);return t.set(e),t}})),xi,L,Si=t((()=>{xi=class{constructor(e,t){this.left=e,this.right=t}},L=(e,t)=>new xi(e,t)})),Ci,wi,Ti,Ei,Di,Oi,ki,Ai=t((()=>{Pt(),ct(),Ci=e=>e.next()>=.5,wi=(e,t,n)=>_(e.next()*(n+1-t)+t),Ti=(e,t,n)=>_(e.next()*(n+1-t)+t),Ei=(e,t,n)=>Ti(e,t,n),Di=e=>St(Ei(e,97,122)),Oi=(e,t=0,n=20)=>{let r=Ei(e,t,n),i=``;for(let t=0;t<r;t++)i+=Di(e);return i},ki=(e,t)=>t[Ei(e,0,t.length-1)]})),ji,Mi,Ni,R,Pi,z,Fi,B,Ii,Li,Ri,zi,Bi,Vi,Hi,Ui,Wi,Gi,Ki,qi,Ji,Yi,Xi,Zi,Qi,$i,ea,ta,na,ra,ia,aa,oa,sa,ca,la,ua,da,fa,pa,ma,ha,ga,_a,va,ya,ba,xa,Sa,Ca,wa,Ta,Ea,Da,Oa,ka,Aa,ja,Ma,Na,Pa,Fa,Ia,La=t((()=>{Mr(),xt(),Ft(),ui(),yr(),Lr(),Pt(),Ai(),ft(),ji=Symbol(`0schema`),Mi=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(Nt(` `,(this._rerrs.length-t)*2)+`${n.path==null?``:`[${n.path}] `}${n.has} doesn't match ${n.expected}. ${n.message}`)}return e.join(`
|
|
2
|
+
`)}},Ni=(e,t)=>e===t?!0:e==null||t==null||e.constructor!==t.constructor?!1:e[_r]?vr(e,t):bt(e)?_t(e,e=>vt(t,t=>Ni(e,t))):br(e)?Dr(e,(e,n)=>Ni(e,t[n])):!1,R=class{static _dilutes=!1;extends(e){let[t,n]=[this.shape,e.shape];return this.constructor._dilutes&&([n,t]=[t,n]),Ni(t,n)}equals(e){return this.constructor===e.constructor&&Fr(this.shape,e.shape)}[ji](){return!0}[_r](e){return this.equals(e)}validate(e){return this.check(e)}check(e,t){b()}get nullable(){return pa(this,Oa)}get optional(){return new Ui(this)}cast(e){return Ma(e,this),e}expect(e){return Ma(e,this),e}},Pi=class extends R{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}},z=(e,t=null)=>new Pi(e,t),z(Pi),Fi=class extends R{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}},B=e=>new Fi(e),z(Fi),Ii=class extends R{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}},Li=(...e)=>new Ii(e),Ri=z(Ii),zi=RegExp.escape||(e=>e.replace(/[().|&,$^[\]]/g,e=>`\\`+e)),Bi=e=>{if(Ca.check(e))return[zi(e)];if(Ri.check(e))return e.shape.map(e=>e+``);if(Sa.check(e))return[`[+-]?\\d+.?\\d*`];if(wa.check(e))return[`.*`];if(ma.check(e))return e.shape.map(Bi).flat(1);x()},Vi=class extends R{constructor(e){super(),this.shape=e,this._r=RegExp(`^`+e.map(Bi).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}},z(Vi),Hi=Symbol(`optional`),Ui=class extends R{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[Hi](){return!0}},Wi=z(Ui),Gi=class extends R{check(e,t){return t?.extend(null,`never`,typeof e),!1}},new Gi,z(Gi),Ki=class e extends R{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):Dr(this.shape,(n,r)=>{let i=this._isPartial&&!Or(e,r)||n.check(e[r],t);return!i&&t?.extend(r.toString(),n.toString(),typeof e[r],`Object property does not match`),i})}},qi=e=>new Ki(e),Ji=z(Ki),Yi=B(e=>e!=null&&(e.constructor===Object||e.constructor==null)),Xi=class extends R{constructor(e,t){super(),this.shape={keys:e,values:t}}check(e,t){return e!=null&&Dr(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)})}},Zi=(e,t)=>new Xi(e,t),Qi=z(Xi),$i=class extends R{constructor(e){super(),this.shape=e}check(e,t){return e!=null&&Dr(this.shape,(n,r)=>{let i=n.check(e[r],t);return!i&&t?.extend(r.toString(),`Tuple`,typeof n),i})}},ea=(...e)=>new $i(e),z($i),ta=class extends R{constructor(e){super(),this.shape=e.length===1?e[0]:new fa(e)}check(e,t){let n=bt(e)&&_t(e,e=>this.shape.check(e));return!n&&t?.extend(null,`Array`,``),n}},na=(...e)=>new ta(e),ra=z(ta),ia=B(e=>bt(e)),aa=class extends R{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}},oa=(e,t=null)=>new aa(e,t),z(aa),sa=oa(R),ca=class extends R{constructor(e){super(),this.len=e.length-1,this.args=ea(...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}},la=z(ca),ua=B(e=>typeof e==`function`),da=class extends R{constructor(e){super(),this.shape=e}check(e,t){let n=_t(this.shape,n=>n.check(e,t));return!n&&t?.extend(null,`Intersectinon`,typeof e),n}},z(da,e=>e.shape.length>0),fa=class extends R{static _dilutes=!0;constructor(e){super(),this.shape=e}check(e,t){let n=vt(this.shape,n=>n.check(e,t));return t?.extend(null,`Union`,typeof e),n}},pa=(...e)=>e.findIndex(e=>ma.check(e))>=0?pa(...e.map(e=>ja(e)).map(e=>ma.check(e)?e.shape:[e]).flat(1)):e.length===1?e[0]:new fa(e),ma=z(fa),ha=()=>!0,ga=B(ha),_a=z(Fi,e=>e.shape===ha),va=B(e=>typeof e==`bigint`),ya=B(e=>e===va),ba=B(e=>typeof e==`symbol`),B(e=>e===ba),xa=B(e=>typeof e==`number`),Sa=B(e=>e===xa),Ca=B(e=>typeof e==`string`),wa=B(e=>e===Ca),Ta=B(e=>typeof e==`boolean`),Ea=B(e=>e===Ta),Da=Li(void 0),z(Ii,e=>e.shape.length===1&&e.shape[0]===void 0),Li(void 0),Oa=Li(null),ka=z(Ii,e=>e.shape.length===1&&e.shape[0]===null),z(Uint8Array),z(Pi,e=>e.shape===Uint8Array),Aa=pa(xa,Ca,Oa,Da,va,Ta,ba),(()=>{let e=na(ga),t=Zi(Ca,ga),n=pa(xa,Ca,Oa,Ta,e,t);return e.shape=n,t.shape.values=n,n})(),ja=e=>{if(sa.check(e))return e;if(Yi.check(e)){let t={};for(let n in e)t[n]=ja(e[n]);return qi(t)}if(ia.check(e))return pa(...e.map(ja));if(Aa.check(e))return Li(e);if(ua.check(e))return z(e);x()},Ma=si?()=>{}:(e,t)=>{let n=new Mi;if(!t.check(e,n))throw y(`Expected value to be of type ${t.constructor.name}.\n${n.toString()}`)},Na=class{constructor(e){this.patterns=[],this.$state=e}if(e,t){return this.patterns.push({if:ja(e),h:t}),this}else(e){return this.if(ga,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 y(`Unhandled pattern`)}}},Pa=e=>new Na(e),Fa=Pa(ga).if(Sa,(e,t)=>wi(t,ut,lt)).if(wa,(e,t)=>Oi(t)).if(Ea,(e,t)=>Ci(t)).if(ya,(e,t)=>BigInt(wi(t,ut,lt))).if(ma,(e,t)=>Ia(t,ki(t,e.shape))).if(Ji,(e,t)=>{let n={};for(let r in e.shape){let i=e.shape[r];if(Wi.check(i)){if(Ci(t))continue;i=i.shape}n[r]=Fa(i,t)}return n}).if(ra,(e,t)=>{let n=[],r=Ti(t,0,42);for(let i=0;i<r;i++)n.push(Ia(t,e.shape));return n}).if(Ri,(e,t)=>ki(t,e.shape)).if(ka,(e,t)=>null).if(la,(e,t)=>{let n=Ia(t,e.res);return()=>n}).if(_a,(e,t)=>Ia(t,ki(t,[xa,Ca,Oa,Da,va,Ta,na(xa),Zi(pa(`a`,`b`,`c`),xa)]))).if(Qi,(e,t)=>{let n={},r=wi(t,0,3);for(let i=0;i<r;i++){let r=Ia(t,e.shape.keys);n[r]=Ia(t,e.shape.values)}return n}).done(),Ia=(e,t)=>Fa(ja(t),e)})),Ra,za,Ba,Va,Ha,Ua,Wa=t((()=>{pr(),La(),Ra=typeof document<`u`?document:{},B(e=>e.nodeType===Ua),typeof DOMParser<`u`&&new DOMParser,B(e=>e.nodeType===Ba),B(e=>e.nodeType===Va),za=e=>dr(e,(e,t)=>`${t}:${e};`).join(``),Ba=Ra.ELEMENT_NODE,Va=Ra.TEXT_NODE,Ra.CDATA_SECTION_NODE,Ra.COMMENT_NODE,Ha=Ra.DOCUMENT_NODE,Ra.DOCUMENT_TYPE_NODE,Ua=Ra.DOCUMENT_FRAGMENT_NODE,B(e=>e.nodeType===Ha)})),V,Ga=t((()=>{V=Symbol})),Ka,qa,Ja,Ya,Xa,Za,Qa,$a,eo,to,no=t((()=>{Ga(),Jn(),Ka=V(),qa=V(),Ja=V(),Ya=V(),Xa=V(),Za=V(),Qa=V(),$a=V(),eo=V(),to=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()})),ro,io,ao,oo,so,co,lo=t((()=>{ui(),mt(),Si(),Wa(),pr(),no(),ro={[Ka]:L(`font-weight`,`bold`),[qa]:L(`font-weight`,`normal`),[Ja]:L(`color`,`blue`),[Xa]:L(`color`,`green`),[Ya]:L(`color`,`grey`),[Za]:L(`color`,`red`),[Qa]:L(`color`,`purple`),[$a]:L(`color`,`orange`),[eo]:L(`color`,`black`)},io=e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=N(),i=[],a=0;for(;a<e.length;a++){let i=e[a],o=ro[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=za(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},ao=li?io:to,oo=(...e)=>{console.log(...ao(e)),co.forEach(t=>t.print(e))},so=(...e)=>{console.warn(...ao(e)),e.unshift($a),co.forEach(t=>t.print(e))},co=pt()})),uo,fo,po,mo=t((()=>{uo=e=>({[Symbol.iterator](){return this},next:e}),fo=(e,t)=>uo(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),po=(e,t)=>uo(()=>{let{done:n,value:r}=e.next();return{done:n,value:n?void 0:t(r)}})}));function*ho(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 $(H(n,r),t),r+=t}else if(31&t){let i=!(t&192),a=new Q(H(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,El(e,t));yield a,r+=a.length}else{let t=e.readLen();yield new X(H(n,r),t),r+=t}}}}var go,_o,vo,yo,bo,xo,So,Co,wo,To,Eo,Do,Oo,ko,Ao,jo,Mo,No,Po,Fo,Io,Lo,Ro,zo,Bo,Vo,Ho,Uo,Wo,Go,Ko,qo,Jo,Yo,Xo,Zo,Qo,$o,es,ts,ns,rs,is,as,os,ss,cs,H,ls,us,ds,fs,ps,ms,hs,U,gs,W,_s,vs,ys,G,bs,xs,Ss,Cs,ws,Ts,Es,Ds,Os,ks,K,As,js,Ms,Ns,Ps,Fs,Is,q,Ls,Rs,zs,Bs,Vs,Hs,J,Us,Ws,Gs,Ks,qs,Js,Ys,Xs,Zs,Y,Qs,$s,ec,tc,nc,rc,ic,ac,oc,sc,cc,lc,uc,dc,fc,pc,mc,hc,gc,_c,vc,yc,bc,xc,Sc,Cc,wc,Tc,Ec,Dc,Oc,kc,Ac,jc,Mc,Nc,Pc,Fc,Ic,Lc,Rc,zc,Bc,Vc,Hc,Uc,Wc,Gc,Kc,qc,Jc,Yc,Xc,Zc,X,Qc,$c,el,tl,nl,rl,il,al,ol,Z,sl,cl,ll,ul,dl,fl,pl,ml,hl,gl,_l,vl,yl,bl,xl,Sl,Cl,wl,Tl,Q,El,Dl,Ol,$,kl,Al,jl=t((()=>{gr(),xt(),ct(),pr(),on(),kn(),Ur(),Gr(),bi(),Ft(),nt(),Lr(),mt(),lo(),mo(),Mr(),ui(),go=class{constructor(e,t){this.clock=e,this.len=t}},_o=class{constructor(){this.clients=new Map}},vo=(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])Ss(e,i,o.clock,o.len,n)}}),yo=(e,t)=>{let n=0,r=e.length-1;for(;n<=r;){let i=_((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},bo=(e,t)=>{let n=e.clients.get(t.client);return n!==void 0&&yo(n,t.clock)!==null},xo=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 go(r.clock,at(r.len,i.clock+i.len-r.clock)):(n<t&&(e[n]=i),n++)}e.length=n})},So=e=>{let t=new _o;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++)gt(a,e[t].clients.get(i)||[]);t.clients.set(i,a)}});return xo(t),t},Co=(e,t,n,r)=>{P(e.clients,t,()=>[]).push(new go(n,r))},wo=()=>new _o,To=e=>{let t=wo();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 go(i,a))}}r.length>0&&t.clients.set(n,r)}),t},Eo=(e,t)=>{T(e.restEncoder,t.clients.size),v(t.clients.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{e.resetDsCurVal(),T(e.restEncoder,t);let r=n.length;T(e.restEncoder,r);for(let t=0;t<r;t++){let r=n[t];e.writeDsClock(r.clock),e.writeDsLen(r.len)}})},Do=e=>{let t=new _o,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=P(t.clients,n,()=>[]);for(let t=0;t<r;t++)i.push(new go(e.readDsClock(),e.readDsLen()))}}return t},Oo=(e,t,n)=>{let r=new _o,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=U(n,i);for(let n=0;n<a;n++){let n=e.readDsClock(),a=n+e.readDsLen();if(n<s){s<a&&Co(r,i,s,a-s);let e=W(o,n),c=o[e];for(!c.deleted&&c.id.clock<n&&(o.splice(e+1,0,Tl(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,Tl(t,c,a-c.id.clock)),c.delete(t))}else Co(r,i,n,a-n)}}if(r.clients.size>0){let e=new Ro;return T(e.restEncoder,0),Eo(e,r),e.toUint8Array()}return null},ko=Br,Ao=class e extends mr{constructor({guid:e=Hr(),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=ko(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new ms,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=Wr(e=>{this.on(`load`,()=>{this.isLoaded=!0,e(this)})});let s=()=>Wr(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(v(this.subdocs).map(e=>e.guid))}transact(e,t=null){return K(this,e,t)}get(e,t=Y){let n=P(this.share,e,()=>{let e=new t;return e._integrate(this,null),e}),r=n.constructor;if(t!==Y&&r!==t){if(r===Y){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,_c)}getText(e=``){return this.get(e,Rc)}getMap(e=``){return this.get(e,bc)}getXmlElement(e=``){return this.get(e,Uc)}getXmlFragment(e=``){return this.get(e,Vc)}toJSON(){let e={};return this.share.forEach((t,n)=>{e[n]=t.toJSON()}),e}destroy(){this.isDestroyed=!0,v(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()}},jo=class{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return k(this.restDecoder)}readDsLen(){return k(this.restDecoder)}},Mo=class extends jo{readLeftID(){return H(k(this.restDecoder),k(this.restDecoder))}readRightID(){return H(k(this.restDecoder),k(this.restDecoder))}readClient(){return k(this.restDecoder)}readInfo(){return hn(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 wn(this.restDecoder)}readBuf(){return yi(O(this.restDecoder))}readJSON(){return JSON.parse(A(this.restDecoder))}readKey(){return A(this.restDecoder)}},No=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}},Po=class extends No{constructor(e){super(e),this.keys=[],k(e),this.keyClockDecoder=new Dn(O(e)),this.clientDecoder=new En(O(e)),this.leftClockDecoder=new Dn(O(e)),this.rightClockDecoder=new Dn(O(e)),this.infoDecoder=new Tn(O(e),hn),this.stringDecoder=new On(O(e)),this.parentInfoDecoder=new Tn(O(e),hn),this.typeRefDecoder=new En(O(e)),this.lenDecoder=new En(O(e))}readLeftID(){return new ss(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new ss(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 wn(this.restDecoder)}readBuf(){return O(this.restDecoder)}readJSON(){return wn(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}}},Fo=class{constructor(){this.restEncoder=S()}toUint8Array(){return C(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){T(this.restEncoder,e)}writeDsLen(e){T(this.restEncoder,e)}},Io=class extends Fo{writeLeftID(e){T(this.restEncoder,e.client),T(this.restEncoder,e.clock)}writeRightID(e){T(this.restEncoder,e.client),T(this.restEncoder,e.clock)}writeClient(e){T(this.restEncoder,e)}writeInfo(e){zt(this.restEncoder,e)}writeString(e){E(this.restEncoder,e)}writeParentInfo(e){T(this.restEncoder,+!!e)}writeTypeRef(e){T(this.restEncoder,e)}writeLen(e){T(this.restEncoder,e)}writeAny(e){Qt(this.restEncoder,e)}writeBuf(e){D(this.restEncoder,e)}writeJSON(e){E(this.restEncoder,JSON.stringify(e))}writeKey(e){E(this.restEncoder,e)}},Lo=class{constructor(){this.restEncoder=S(),this.dsCurrVal=0}toUint8Array(){return C(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){let t=e-this.dsCurrVal;this.dsCurrVal=e,T(this.restEncoder,t)}writeDsLen(e){e===0&&x(),T(this.restEncoder,e-1),this.dsCurrVal+=e}},Ro=class extends Lo{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new rn,this.clientEncoder=new tn,this.leftClockEncoder=new rn,this.rightClockEncoder=new rn,this.infoEncoder=new $t(zt),this.stringEncoder=new an,this.parentInfoEncoder=new $t(zt),this.typeRefEncoder=new tn,this.lenEncoder=new tn}toUint8Array(){let e=S();return T(e,0),D(e,this.keyClockEncoder.toUint8Array()),D(e,this.clientEncoder.toUint8Array()),D(e,this.leftClockEncoder.toUint8Array()),D(e,this.rightClockEncoder.toUint8Array()),D(e,C(this.infoEncoder)),D(e,this.stringEncoder.toUint8Array()),D(e,C(this.parentInfoEncoder)),D(e,this.typeRefEncoder.toUint8Array()),D(e,this.lenEncoder.toUint8Array()),Gt(e,C(this.restEncoder)),C(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){Qt(this.restEncoder,e)}writeBuf(e){D(this.restEncoder,e)}writeJSON(e){Qt(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)}},zo=(e,t,n,r)=>{r=at(r,t[0].id.clock);let i=W(t,r);T(e.restEncoder,t.length-i),e.writeClient(n),T(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)},Bo=(e,t,n)=>{let r=new Map;n.forEach((e,n)=>{U(t,n)>e&&r.set(n,e)}),hs(t).forEach((e,t)=>{n.has(t)||r.set(t,0)}),T(e.restEncoder,r.size),v(r.entries()).sort((e,t)=>t[0]-e[0]).forEach(([n,r])=>{zo(e,t.clients.get(n),n,r)})},Vo=(e,t)=>{let n=N(),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(H(a,o),t),o+=t;break}case 10:{let t=k(e.restDecoder);i[n]=new $(H(a,o),t),o+=t;break}default:{let s=!(r&192),c=new Q(H(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,El(e,r));i[n]=c,o+=c.length}}}}return n},Ho=(e,t,n)=>{let r=[],i=v(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 ms,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=P(d,u.id.client,()=>U(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,U(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 Ro;return Bo(e,s,new Map),T(e.restEncoder,0),{missing:c,update:e.toUint8Array()}}return null},Uo=(e,t)=>Bo(e,t.doc.store,t.beforeState),Wo=(e,t,n,r=new Po(e))=>K(t,e=>{e.local=!1;let t=!1,n=e.doc,i=n.store,a=Vo(r,n),o=Ho(e,i,a),s=i.pendingStructs;if(s){for(let[e,n]of s.missing)if(n<U(i,e)){t=!0;break}if(o){for(let[e,t]of o.missing){let n=s.missing.get(e);(n==null||n>t)&&s.missing.set(e,t)}s.update=Ps([s.update,o.update])}}else i.pendingStructs=o;let c=Oo(r,e,i);if(i.pendingDs){let t=new Po(fn(i.pendingDs));k(t.restDecoder);let n=Oo(t,e,i);i.pendingDs=c&&n?Ps([c,n]):c||n}else i.pendingDs=c;if(t){let t=i.pendingStructs.update;i.pendingStructs=null,Go(e.doc,t)}},n,!1),Go=(e,t,n,r=Po)=>{let i=fn(t);Wo(i,e,n,new r(i))},Ko=(e,t,n)=>Go(e,t,n,Mo),qo=(e,t,n=new Map)=>{Bo(e,t.store,n),Eo(e,To(t.store))},Jo=(e,t=new Uint8Array([0]),n=new Ro)=>{let r=Zo(t);qo(n,e,r);let i=[n.toUint8Array()];if(e.store.pendingDs&&i.push(e.store.pendingDs),e.store.pendingStructs&&i.push(Fs(e.store.pendingStructs.update,t)),i.length>1){if(n.constructor===Io)return Ms(i.map((e,t)=>t===0?e:zs(e)));if(n.constructor===Ro)return Ps(i)}return i[0]},Yo=(e,t)=>Jo(e,t,new Io),Xo=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},Zo=e=>Xo(new jo(fn(e))),Qo=(e,t)=>(T(e.restEncoder,t.size),v(t.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{T(e.restEncoder,t),T(e.restEncoder,n)}),e),$o=(e,t)=>Qo(e,hs(t.store)),es=(e,t=new Lo)=>(e instanceof Map?Qo(t,e):$o(t,e),t.toUint8Array()),ts=e=>es(e,new Fo),ns=class{constructor(){this.l=[]}},rs=()=>new ns,is=(e,t)=>e.l.push(t),as=(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.`)},os=(e,t,n)=>Nr(e.l,[t,n]),ss=class{constructor(e,t){this.client=e,this.clock=t}},cs=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,H=(e,t)=>new ss(e,t),ls=e=>{for(let[t,n]of e.doc.share.entries())if(n===e)return t;throw x()},us=class{constructor(e,t){this.ds=e,this.sv=t}},ds=(e,t)=>new us(e,t),ds(wo(),new Map),fs=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!bo(t.ds,e.id),ps=(e,t)=>{let n=P(e.meta,ps,pt),r=e.doc.store;n.has(t)||(t.sv.forEach((t,n)=>{t<U(r,n)&&G(e,H(n,t))}),vo(e,t.ds,e=>{}),n.add(t))},ms=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},hs=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},U=(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},gs=(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 x()}n.push(t)},W=(e,t)=>{let n=0,r=e.length-1,i=e[r],a=i.id.clock;if(a===t)return r;let o=_(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=_((n+r)/2)}throw x()},_s=(e,t)=>{let n=e.clients.get(t.client);return n[W(n,t.clock)]},vs=_s,ys=(e,t,n)=>{let r=W(t,n),i=t[r];return i.id.clock<n&&i instanceof Q?(t.splice(r+1,0,Tl(e,i,n-i.id.clock)),r+1):r},G=(e,t)=>{let n=e.doc.store.clients.get(t.client);return n[ys(e,n,t.clock)]},bs=(e,t,n)=>{let r=t.clients.get(n.client),i=W(r,n.clock),a=r[i];return n.clock!==a.id.clock+a.length-1&&a.constructor!==X&&r.splice(i+1,0,Tl(e,a,n.clock-a.id.clock+1)),a},xs=(e,t,n)=>{let r=e.clients.get(t.id.client);r[W(r,t.id.clock)]=n},Ss=(e,t,n,r,i)=>{if(r===0)return;let a=n+r,o=ys(e,t,n),s;do s=t[o++],a<s.id.clock+s.length&&ys(e,t,a),i(s);while(o<t.length&&t[o].id.clock<a)},Cs=class{constructor(e,t,n){this.doc=e,this.deleteSet=new _o,this.beforeState=hs(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}},ws=(e,t)=>t.deleteSet.clients.size===0&&!fr(t.afterState,(e,n)=>t.beforeState.get(n)!==e)?!1:(xo(t.deleteSet),Uo(e,t),Eo(e,t.deleteSet),!0),Ts=(e,t,n)=>{let r=t._item;(r===null||r.id.clock<(e.beforeState.get(r.id.client)||0)&&!r.deleted)&&P(e.changed,t,pt).add(n)},Es=(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},Ds=(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=W(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)}}}},Os=(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=it(r.length-1,1+W(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+Es(r,e)}})},ks=(e,t)=>{if(t<e.length){let n=e[t],r=n.doc,i=r.store,a=n.deleteSet,o=n._mergeStructs;try{xo(a),n.afterState=hs(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),os(r._dEH,t,n)})}),e.push(()=>r.emit(`afterTransaction`,[n,r])),e.push(()=>{n._needFormattingCleanup&&Fc(n)})}),Nr(e,[])}finally{r.gc&&Ds(a,i,r.gcFilter),Os(a,i),n.afterState.forEach((e,t)=>{let r=n.beforeState.get(t)||0;if(r!==e){let e=i.clients.get(t),n=at(W(e,r),1);for(let t=e.length-1;t>=n;)t-=1+Es(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=W(r,n);a+1<r.length&&Es(r,a+1)>1||a>0&&Es(r,a)}if(!n.local&&n.afterState.get(r.clientID)!==n.beforeState.get(r.clientID)&&(oo($a,Ka,`[yjs] `,qa,Za,`Changed the client-id because another client seems to be using it.`),r.clientID=ko()),r.emit(`afterTransactionCleanup`,[n,r]),r._observers.has(`update`)){let e=new Io;ws(e,n)&&r.emit(`update`,[e.toUint8Array(),n.origin,r,n])}if(r._observers.has(`updateV2`)){let e=new Ro;ws(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])):ks(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 Cs(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&&ks(i,0)}}return o},As=class{constructor(e,t){this.gen=ho(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}},js=class{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}},Ms=e=>Ps(e,Mo,Io),Ns=(e,t)=>{if(e.constructor===X){let{client:n,clock:r}=e.id;return new X(H(n,r+t),e.length-t)}if(e.constructor===$){let{client:n,clock:r}=e.id;return new $(H(n,r+t),e.length-t)}{let n=e,{client:r,clock:i}=n.id;return new Q(H(r,i+t),null,H(r,i+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},Ps=(e,t=Po,n=Ro)=>{if(e.length===1)return e[0];let r=e.map(e=>new t(fn(e))),i=r.map(e=>new As(e,!0)),a=null,o=new n,s=new js(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)q(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{q(s,a.struct,a.offset);let e=n.id.clock-a.struct.id.clock-a.struct.length;a={struct:new $(H(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=Ns(n,t)),a.struct.mergeWith(n)||(q(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())q(s,a.struct,a.offset),a={struct:n,offset:0}}a!==null&&(q(s,a.struct,a.offset),a=null),Ls(s);let c=r.map(e=>Do(e)),l=So(c);return Eo(o,l),o.toUint8Array()},Fs=(e,t,n=Po,r=Ro)=>{let i=Zo(t),a=new r,o=new js(a),s=new n(fn(e)),c=new As(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(q(o,e,at(n-e.id.clock,0)),c.next();c.curr&&c.curr.id.client===t;)q(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()}Ls(o);let l=Do(s);return Eo(a,l),a.toUint8Array()},Is=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:C(e.encoder.restEncoder)}),e.encoder.restEncoder=S(),e.written=0)},q=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&Is(e),e.written===0&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),T(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},Ls=e=>{Is(e);let t=e.encoder.restEncoder;T(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){let r=e.clientStructs[n];T(t,r.written),Gt(t,r.restEncoder)}},Rs=(e,t,n,r)=>{let i=new n(fn(e)),a=new As(i,!1),o=new r,s=new js(o);for(let e=a.curr;e!==null;e=a.next())q(s,t(e),0);Ls(s);let c=Do(i);return Eo(o,c),o.toUint8Array()},zs=e=>Rs(e,Pr,Po,Io),Bs=`You must not compute changes after the event-handler fired.`,Vs=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||=Hs(this.currentTarget,this.target)}deletes(e){return bo(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw y(Bs);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=ht(e.content.getContent());else return}else e!==null&&this.deletes(e)?(i=`update`,a=ht(e.content.getContent())):(i=`add`,a=void 0)}else if(this.deletes(r))i=`delete`,a=ht(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 y(Bs);let t=this.target,n=pt(),r=pt(),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}},Hs=(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},J=()=>{so(`Invalid access: Add Yjs type to a document before reading data.`)},Us=80,Ws=0,Gs=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=Ws++}},Ks=e=>{e.timestamp=Ws++},qs=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=Ws++},Js=(e,t,n)=>{if(e.length>=Us){let r=e.reduce((e,t)=>e.timestamp<t.timestamp?e:t);return qs(r,t,n),r}{let r=new Gs(t,n);return e.push(r),r}},Ys=(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)=>rt(t-e.index)<rt(t-n.index)?e:n),r=e._start,i=0;for(n!==null&&(r=n.p,i=n.index,Ks(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&&rt(n.index-i)<r.parent.length/Us?(qs(n,r,i),n):Js(e._searchMarker,r,i)},Xs=(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=at(t,i.index+n))}},Zs=(e,t,n)=>{let r=e,i=t.changedParentTypes;for(;P(i,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;os(r._eH,n,t)},Y=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=rs(),this._dEH=rs(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw b()}clone(){throw b()}_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){is(this._eH,e)}observeDeep(e){is(this._dEH,e)}unobserve(e){as(this._eH,e)}unobserveDeep(e){as(this._dEH,e)}toJSON(){}},Qs=(e,t,n)=>{e.doc??J(),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},$s=e=>{e.doc??J();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},ec=(e,t)=>{let n=0,r=e._start;for(e.doc??J();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}},tc=(e,t)=>{let n=[];return ec(e,(r,i)=>{n.push(t(r,i,e))}),n},nc=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}}}},rc=(e,t)=>{e.doc??J();let n=Ys(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}},ic=(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(H(o,U(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new dl(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(H(o,U(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new Qc(new Uint8Array(n))),i.integrate(e,0);break;case Ao:i=new Q(H(o,U(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new rl(n)),i.integrate(e,0);break;default:if(n instanceof Y)i=new Q(H(o,U(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new Cl(n)),i.integrate(e,0);else throw Error(`Unexpected content type in insert operation`)}}}),u()},ac=()=>y(`Length exceeded!`),oc=(e,t,n,r)=>{if(n>t._length)throw ac();if(n===0)return t._searchMarker&&Xs(t._searchMarker,n,r.length),ic(e,t,null,r);let i=n,a=Ys(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&&G(e,H(o.id.client,o.id.clock+n));break}n-=o.length}return t._searchMarker&&Xs(t._searchMarker,i,r.length),ic(e,t,o,r)},sc=(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 ic(e,t,r,n)},cc=(e,t,n,r)=>{if(r===0)return;let i=n,a=r,o=Ys(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&&G(e,H(s.id.client,s.id.clock+n)),n-=s.length);for(;r>0&&s!==null;)s.deleted||(r<s.length&&G(e,H(s.id.client,s.id.clock+r)),s.delete(e),r-=s.length),s=s.right;if(r>0)throw ac();t._searchMarker&&Xs(t._searchMarker,i,-a+r)},lc=(e,t,n)=>{let r=t._map.get(n);r!==void 0&&r.delete(e)},uc=(e,t,n,r)=>{let i=t._map.get(n)||null,a=e.doc,o=a.clientID,s;if(r==null)s=new dl([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:s=new dl([r]);break;case Uint8Array:s=new Qc(r);break;case Ao:s=new rl(r);break;default:if(r instanceof Y)s=new Cl(r);else throw Error(`Unexpected content type`)}new Q(H(o,U(a.store,o)),i,i&&i.lastId,null,null,t,n,s).integrate(e,0)},dc=(e,t)=>{e.doc??J();let n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},fc=e=>{let t={};return e.doc??J(),e._map.forEach((e,n)=>{e.deleted||(t[n]=e.content.getContent()[e.length-1])}),t},pc=(e,t)=>{e.doc??J();let n=e._map.get(t);return n!==void 0&&!n.deleted},mc=(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&&fs(i,t)&&(n[r]=i.content.getContent()[i.length-1])}),n},hc=e=>(e.doc??J(),fo(e._map.entries(),e=>!e[1].deleted)),gc=class extends Vs{},_c=class e extends Y{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 Y?e.clone():e)),t}get length(){return this.doc??J(),this._length}_callObserver(e,t){super._callObserver(e,t),Zs(this,e,new gc(this,e))}insert(e,t){this.doc===null?this._prelimContent.splice(e,0,...t):K(this.doc,n=>{oc(n,this,e,t)})}push(e){this.doc===null?this._prelimContent.push(...e):K(this.doc,t=>{sc(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=>{cc(n,this,e,t)})}get(e){return rc(this,e)}toArray(){return $s(this)}slice(e=0,t=this.length){return Qs(this,e,t)}toJSON(){return this.map(e=>e instanceof Y?e.toJSON():e)}map(e){return tc(this,e)}forEach(e){ec(this,e)}[Symbol.iterator](){return nc(this)}_write(e){e.writeTypeRef(gl)}},vc=e=>new _c,yc=class extends Vs{constructor(e,t,n){super(e,t),this.keysChanged=n}},bc=class e extends Y{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 Y?e.clone():e)}),t}_callObserver(e,t){Zs(this,e,new yc(this,e,t))}toJSON(){this.doc??J();let e={};return this._map.forEach((t,n)=>{if(!t.deleted){let r=t.content.getContent()[t.length-1];e[n]=r instanceof Y?r.toJSON():r}}),e}get size(){return[...hc(this)].length}keys(){return po(hc(this),e=>e[0])}values(){return po(hc(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return po(hc(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??J(),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=>{lc(t,this,e)})}set(e,t){return this.doc===null?this._prelimContent.set(e,t):K(this.doc,n=>{uc(n,this,e,t)}),t}get(e){return dc(this,e)}has(e){return pc(this,e)}clear(){this.doc===null?this._prelimContent.clear():K(this.doc,e=>{this.forEach(function(t,n,r){lc(e,r,n)})})}_write(e){e.writeTypeRef(_l)}},xc=e=>new bc,Sc=(e,t)=>e===t||typeof e==`object`&&typeof t==`object`&&e&&t&&kr(e,t),Cc=class{constructor(e,t,n,r){this.left=e,this.right=t,this.index=n,this.currentAttributes=r}forward(){switch(this.right===null&&x(),this.right.content.constructor){case Z:this.right.deleted||Dc(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length)}this.left=this.right,this.right=this.right.right}},wc=(e,t,n)=>{for(;t.right!==null&&n>0;){switch(t.right.content.constructor){case Z:t.right.deleted||Dc(t.currentAttributes,t.right.content);break;default:t.right.deleted||(n<t.right.length&&G(e,H(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},Tc=(e,t,n,r)=>{let i=new Map,a=r?Ys(t,n):null;if(a){let t=new Cc(a.p.left,a.p,a.index,i);return wc(e,t,n-a.index)}{let r=new Cc(null,t._start,0,i);return wc(e,r,n)}},Ec=(e,t,n,r)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===Z&&Sc(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(H(a,U(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()})},Dc=(e,t)=>{let{key:n,value:r}=t;r===null?e.delete(n):e.set(n,r)},Oc=(e,t)=>{for(;e.right!==null&&(e.right.deleted||e.right.content.constructor===Z&&Sc(t[e.right.content.key]??null,e.right.content.value));)e.forward()},kc=(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(!Sc(l,c)){o.set(s,l);let{left:r,right:u}=n;n.right=new Q(H(a,U(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},Ac=(e,t,n,r,i)=>{n.currentAttributes.forEach((e,t)=>{i[t]===void 0&&(i[t]=null)});let a=e.doc,o=a.clientID;Oc(n,i);let s=kc(e,t,n,i),c=r.constructor===String?new pl(r):r instanceof Y?new Cl(r):new al(r),{left:l,right:u,index:d}=n;t._searchMarker&&Xs(t._searchMarker,n.index,c.getLength()),u=new Q(H(o,U(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(),Ec(e,t,n,s)},jc=(e,t,n,r,i)=>{let a=e.doc,o=a.clientID;Oc(n,i);let s=kc(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(Sc(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&&G(e,H(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(H(o,U(a.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new pl(i)),n.right.integrate(e,0),n.forward()}Ec(e,t,n,s)},Mc=(e,t,n,r,i)=>{let a=t,o=N();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&&Dc(i,n);break}}}t=t.right}return s},Nc=(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}},Pc=e=>{let t=0;return K(e.doc,n=>{let r=e._start,i=e._start,a=N(),o=ur(a);for(;i;){if(i.deleted===!1)switch(i.content.constructor){case Z:Dc(o,i.content);break;default:t+=Mc(n,r,i,a,o),a=ur(o),r=i}i=i.right}}),t},Fc=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&&Ss(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=>{vo(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):Nc(n,e)});for(let e of t)Pc(e)})},Ic=(e,t,n)=>{let r=n,i=ur(t.currentAttributes),a=t.right;for(;n>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case Cl:case al:case pl:n<t.right.length&&G(e,H(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e)}t.forward()}a&&Mc(e,a,t.right,i,t.currentAttributes);let o=(t.left||t.right).parent;return o._searchMarker&&Xs(o._searchMarker,t.index,-r+n),t},Lc=class extends Vs{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},Er(o)||(e.attributes=xr({},o))),c=0}e&&t.push(e),a=null}};for(;i!==null;){switch(i.content.constructor){case Cl:case al: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 pl: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)){if(!this.deletes(i)){let c=n.get(t)??null;Sc(c,s)?s!==null&&i.delete(e):(a===`retain`&&u(),Sc(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;Sc(e,s)||(a===`retain`&&u(),o[t]=e)}else if(!i.deleted){r.set(t,s);let n=o[t];n!==void 0&&(Sc(n,s)?n!==null&&i.delete(e):(a===`retain`&&u(),s===null?delete o[t]:o[t]=s))}i.deleted||(a===`insert`&&u(),Dc(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}},Rc=class e extends Y{constructor(e){super(),this._pending=e===void 0?[]:[()=>this.insert(0,e)],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??J(),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 Lc(this,e,t);Zs(this,e,n),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??J();let e=``,t=this._start;for(;t!==null;)!t.deleted&&t.countable&&t.content.constructor===pl&&(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 Cc(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)&&Ac(n,this,r,o,a.attributes||{})}else a.retain===void 0?a.delete!==void 0&&Ic(n,r,a.delete):jc(n,this,r,a.retain,a.attributes||{})}})}toDelta(e,t,n){this.doc??J();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(fs(s,e)||t!==void 0&&fs(s,t))switch(s.content.constructor){case pl:{let r=i.get(`ychange`);e!==void 0&&!fs(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&&!fs(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 Cl:case al:{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:fs(s,e)&&(c(),Dc(i,s.content))}s=s.right}c()};return e||t?K(a,n=>{e&&ps(n,e),t&&ps(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=Tc(r,this,e,!n);n||(n={},i.currentAttributes.forEach((e,t)=>{n[t]=e})),Ac(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=Tc(r,this,e,!n);Ac(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=>{Ic(n,Tc(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=Tc(r,this,e,!1);i.right!==null&&jc(r,this,i,t,n)})}removeAttribute(e){this.doc===null?this._pending.push(()=>this.removeAttribute(e)):K(this.doc,t=>{lc(t,this,e)})}setAttribute(e,t){this.doc===null?this._pending.push(()=>this.setAttribute(e,t)):K(this.doc,n=>{uc(n,this,e,t)})}getAttribute(e){return dc(this,e)}getAttributes(){return fc(this)}_write(e){e.writeTypeRef(vl)}},zc=e=>new Rc,Bc=class{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??J()}[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===Uc||t.constructor===Vc)&&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})}},Vc=class e extends Y{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 Y?e.clone():e)),t}get length(){return this.doc??J(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new Bc(this,e)}querySelector(e){e=e.toUpperCase();let t=new Bc(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e).next();return t.done?null:t.value}querySelectorAll(e){return e=e.toUpperCase(),v(new Bc(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){Zs(this,e,new Gc(this,t,e))}toString(){return tc(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),ec(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=>{oc(n,this,e,t)})}insertAfter(e,t){if(this.doc!==null)K(this.doc,n=>{let r=e&&e instanceof Y?e._item:e;ic(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 y(`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=>{cc(n,this,e,t)})}toArray(){return $s(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return rc(this,e)}slice(e=0,t=this.length){return Qs(this,e,t)}forEach(e){ec(this,e)}_write(e){e.writeTypeRef(bl)}},Hc=e=>new Vc,Uc=class e extends Vc{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),n=this.getAttributes();return Cr(n,(e,n)=>{t.setAttribute(n,e)}),t.insert(0,this.toArray().map(e=>e instanceof Y?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=>{lc(t,this,e)})}setAttribute(e,t){this.doc===null?this._prelimAttrs.set(e,t):K(this.doc,n=>{uc(n,this,e,t)})}getAttribute(e){return dc(this,e)}hasAttribute(e){return pc(this,e)}getAttributes(e){return e?mc(this,e):fc(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 ec(this,i=>{r.appendChild(i.toDOM(e,t,n))}),n!==void 0&&n._createAssociation(r,this),r}_write(e){e.writeTypeRef(yl),e.writeKey(this.nodeName)}},Wc=e=>new Uc(e.readKey()),Gc=class extends Vs{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)})}},Kc=class e extends bc{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(xl),e.writeKey(this.hookName)}},qc=e=>new Kc(e.readKey()),Jc=class e extends Rc{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(Sl)}},Yc=e=>new Jc,Xc=class{constructor(e,t){this.id=e,this.length=t}get deleted(){throw b()}mergeWith(e){return!1}write(e,t,n){throw b()}integrate(e,t){throw b()}},Zc=0,X=class extends Xc{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),gs(e.doc.store,this)}write(e,t){e.writeInfo(Zc),e.writeLen(this.length-t)}getMissing(e,t){return null}},Qc=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 b()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}},$c=e=>new Qc(e.readBuf()),el=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){Co(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}},tl=e=>new el(e.readLen()),nl=(e,t)=>new Ao({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1}),rl=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(nl(this.doc.guid,this.opts))}splice(e){throw b()}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}},il=e=>new rl(nl(e.readString(),e.readAny())),al=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 b()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}},ol=e=>new al(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 b()}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}},sl=e=>new Z(e.readKey(),e.readJSON()),cl=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}},ll=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 cl(n)},ul=ai(`node_env`)===`development`,dl=class e{constructor(e){this.arr=e,ul&&jr(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}},fl=e=>{let t=e.readLen(),n=[];for(let r=0;r<t;r++)n.push(e.readAny());return new dl(n)},pl=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}},ml=e=>new pl(e.readString()),hl=[vc,xc,zc,Wc,Hc,qc,Yc],gl=0,_l=1,vl=2,yl=3,bl=4,xl=5,Sl=6,Cl=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 b()}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}},wl=e=>new Cl(hl[e.readTypeRef()](e)),Tl=(e,t,n)=>{let{client:r,clock:i}=t.id,a=new Q(H(r,i+n),t,H(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=H(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 Xc{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>=U(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=U(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===ss&&this.id.client!==this.parent.client&&this.parent.clock>=U(n,this.parent.client))return this.parent.client;if(this.origin&&=(this.left=bs(t,n,this.origin),this.left.lastId),this.rightOrigin&&=(this.right=G(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===ss){let e=vs(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=bs(e,e.doc.store,H(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),cs(this.origin,n.origin)){if(n.id.client<this.id.client)t=n,r.clear();else if(cs(this.rightOrigin,n.rightOrigin))break}else if(n.origin!==null&&i.has(vs(e.doc.store,n.origin)))r.has(vs(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),gs(e.doc.store,this),this.content.integrate(e,this),Ts(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:H(this.id.client,this.id.clock+this.length-1)}mergeWith(e){if(this.constructor===e.constructor&&cs(e.origin,this.lastId)&&this.right===e&&cs(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(),Co(e.deleteSet,this.id.client,this.id.clock,this.length),Ts(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw x();this.content.gc(e),t?xs(e,this,new X(this.id,this.length)):this.content=new el(this.length)}write(e,t){let n=t>0?H(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=ls(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===ss?(e.writeParentInfo(!1),e.writeLeftID(t)):x();i!==null&&e.writeString(i)}this.content.write(e,t)}},El=(e,t)=>Dl[t&31](e),Dl=[()=>{x()},tl,ll,$c,ml,ol,sl,wl,fl,il,()=>{x()}],Ol=10,$=class extends Xc{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,!0)}integrate(e,t){x()}write(e,t){e.writeInfo(Ol),T(e.restEncoder,this.length-t)}getMissing(e,t){return null}},kl=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:{},Al=`__ $YJS$ __`,kl[Al]===!0&&console.error(`Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438`),kl[Al]=!0})),Ml,Nl,Pl,Fl,Il,Ll=t((()=>{on(),kn(),Jn(),ct(),gr(),Lr(),Ml=3e4,Nl=class extends hr{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&&Pl(this,t,`timeout`)},_(Ml/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),Fr(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}},Pl=(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]))},Fl=(e,t,n=e.states)=>{let r=t.length,i=S();T(i,r);for(let a=0;a<r;a++){let r=t[a],o=n.get(r)||null,s=e.meta.get(r).clock;T(i,r),T(i,s),E(i,JSON.stringify(o))}return C(i)},Il=(e,t,n)=>{let r=fn(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&&(Fr(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])}})),Rl,zl,Bl,Vl,Hl,Ul,Wl,Gl=t((()=>{pr(),mt(),bi(),ei(),Rl=new Map,zl=class{constructor(e){this.room=e,this.onmessage=null,this._onChange=t=>t.key===e&&this.onmessage!==null&&this.onmessage({data:vi(t.newValue||``)}),Qr(this._onChange)}postMessage(e){Zr.setItem(this.room,_i(fi(e)))}close(){$r(this._onChange)}},Bl=typeof BroadcastChannel>`u`?zl:BroadcastChannel,Vl=e=>P(Rl,e,()=>{let t=pt(),n=new Bl(e);return n.onmessage=e=>t.forEach(t=>t(e.data,`broadcastchannel`)),{bc:n,subs:t}}),Hl=(e,t)=>(Vl(e).subs.add(t),t),Ul=(e,t)=>{let n=Vl(e),r=n.subs.delete(t);return r&&n.subs.size===0&&(n.bc.close(),Rl.delete(e)),r},Wl=(e,t,n=null)=>{let r=Vl(e);r.bc.postMessage(t),r.subs.forEach(e=>e(t,n))}})),Kl,ql,Jl,Yl,Xl,Zl,Ql,$l=t((()=>{on(),kn(),jl(),Kl=(e,t)=>{T(e,0);let n=ts(t);D(e,n)},ql=(e,t,n)=>{T(e,1),D(e,Yo(t,n))},Jl=(e,t,n)=>ql(t,n,O(e)),Yl=(e,t,n,r)=>{try{Ko(t,O(e),n)}catch(e){r?.(e),console.error(`Caught error while handling a Yjs update`,e)}},Xl=(e,t)=>{T(e,2),D(e,t)},Zl=Yl,Ql=(e,t,n,r,i)=>{let a=k(e);switch(a){case 0:Jl(e,t,n);break;case 1:Yl(e,n,r,i);break;case 2:Zl(e,n,r,i);break;default:throw Error(`Unknown message type`)}return a}})),eu,tu=t((()=>{kn(),eu=(e,t,n)=>{k(e)===0&&n(t,A(e))}})),nu,ru=t((()=>{Mr(),nu=e=>wr(e,(e,t)=>`${encodeURIComponent(t)}=${encodeURIComponent(e)}`).join(`&`)})),iu,au,ou,su,cu,lu,uu,du,fu,pu=t((()=>{Gl(),Jn(),on(),kn(),$l(),tu(),Ll(),gr(),ct(),ru(),ui(),iu=[],iu[0]=(e,t,n,r,i)=>{T(e,0);let a=Ql(t,e,n.doc,n);r&&a===1&&!n.synced&&(n.synced=!0)},iu[3]=(e,t,n,r,i)=>{T(e,1),D(e,Fl(n.awareness,Array.from(n.awareness.getStates().keys())))},iu[1]=(e,t,n,r,i)=>{Il(n.awareness,O(t),n)},iu[2]=(e,t,n,r,i)=>{eu(t,n.doc,(e,t)=>ou(n,t))},au=3e4,ou=(e,t)=>console.warn(`Permission denied to access ${e.url}.\n${t}`),su=(e,t,n)=>{let r=fn(t),i=S(),a=k(r),o=e.messageHandlers[a];return o?o(i,r,e,n,a):console.error(`Unable to compute message`),i},cu=e=>!(e.code>=4400&&e.code<4500),lu=(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,Pl(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(uu,it(ot(2,e.wsUnsuccessfulReconnects)*100,e.maxBackoffTime),e),r!==null&&e.emit(`closed`,[r,e])}},uu=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=su(e,new Uint8Array(n.data),!0);Lt(r)>1&&t.send(C(r))},t.onerror=n=>{e.ws===t&&e.emit(`connection-error`,[n,e])},t.onclose=n=>{lu(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=S();if(T(n,0),Kl(n,e.doc),t.send(C(n)),e.awareness.getLocalState()!==null){let n=S();T(n,1),D(n,Fl(e.awareness,[e.doc.clientID])),t.send(C(n))}},e.emit(`status`,[{status:`connecting`}])}},du=(e,t)=>{let n=e.ws;e.wsconnected&&n&&n.readyState===n.OPEN&&n.send(t),e.bcconnected&&Wl(e.bcChannel,t,e)},fu=class extends mr{constructor(e,t,n,{connect:r=!0,awareness:i=new Nl(n),params:a={},protocols:o=[],WebSocketPolyfill:s=WebSocket,resyncInterval:c=-1,maxBackoffTime:l=2500,disableBc:u=!1,shouldReconnect:d=cu}={}){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=iu.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=S();T(e,0),Kl(e,n),this.ws.send(C(e))}},c)),this._bcSubscriber=(e,t)=>{if(t!==this){let t=su(this,new Uint8Array(e),!1);Lt(t)>1&&Wl(this.bcChannel,C(t),this)}},this._updateHandler=(e,t)=>{if(t!==this){let t=S();T(t,0),Xl(t,e),du(this,C(t))}},this.doc.on(`update`,this._updateHandler),this._awarenessUpdateHandler=({added:e,updated:t,removed:n},r)=>{let a=e.concat(t).concat(n),o=S();T(o,1),D(o,Fl(i,a)),du(this,C(o))},this._exitHandler=()=>{Pl(this.awareness,[n.clientID],`app closed`)},F&&typeof process<`u`&&process.on(`exit`,this._exitHandler),i.on(`update`,this._awarenessUpdateHandler),this._checkInterval=setInterval(()=>{this.wsconnected&&au<M()-this.wsLastMessageReceived&&lu(this,this.ws,null)},au/10),r&&this.connect()}get url(){let e=nu(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(),F&&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||=(Hl(this.bcChannel,this._bcSubscriber),!0);let e=S();T(e,0),Kl(e,this.doc),Wl(this.bcChannel,C(e),this);let t=S();T(t,0),ql(t,this.doc),Wl(this.bcChannel,C(t),this);let n=S();T(n,3),Wl(this.bcChannel,C(n),this);let r=S();T(r,1),D(r,Fl(this.awareness,[this.doc.clientID])),Wl(this.bcChannel,C(r),this)}disconnectBc(){let e=S();T(e,1),D(e,Fl(this.awareness,[this.doc.clientID],new Map)),du(this,C(e)),this.bcconnected&&=(Ul(this.bcChannel,this._bcSubscriber),!1)}disconnect(){this.shouldConnect=!1,this.disconnectBc(),this.ws!==null&&lu(this,this.ws,null)}connect(){this.shouldConnect=!0,!this.wsconnected&&this.ws===null&&(uu(this),this.connectBc())}}})),mu=n({connectRealtimeRoom:()=>hu});function hu(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}${Yn(`/_vitehub/realtime/${encodeURIComponent(e)}`,n.baseURL)}`},ne=t.split(`/`).map(encodeURIComponent).join(`/`),re={};function ie(){l=!1,d=new Ao,f=new fu(te(),ne,d,{disableBc:!0,params:{...n.params,clientId:String(d.clientID)}});let e=f;Xn(e),e.messageHandlers[5]=(t,n)=>{let r=Rn(n);r&&(r.type===`session`?e.params.epoch=r.epoch:(e.destroy(),d.destroy(),u||(ie(),ee())))},e.messageHandlers[6]=(t,n)=>{let r=Un(n);if(r?.kind===`request`&&ae(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=S();T(o,1),D(o,Fl(e.awareness,i)),a.send(C(o))});let t=n.identity??{id:`guest:${d.clientID}`};Zn(e),e.awareness.setLocalState({...re,user:ar({...t,id:t.id||`guest:${d.clientID}`})}),e.awareness.on(`change`,ee),d.getMap(nr.status).observe(ee),e.on(`sync`,t=>{f===e&&(l=t,ee())}),e.on(`status`,e=>{c=e.status,ee()})}ie();let p;n.changes&&(p=new fu(te(),encodeURIComponent(Gn),new Ao,{disableBc:!0,params:{...n.params,workspace:`events`}}),p.awareness.setLocalState(null),Xn(p),p.messageHandlers[4]=(e,t)=>{let n=Bn(t);if(n)for(let e of i)e(n)},p.on(`status`,e=>{e.status===`connected`&&oe()}));async function ae(e,t,n){let r=e=>Hn({kind:`answer`,id:t,ok:!1,why:e}),i;try{i=s?Hn({kind:`answer`,id:t,ok:!0,body:await s(n)}):r(`This page does not answer requests.`),i.byteLength>gu&&(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 oe(){let e=p?.ws;if(p?.wsconnected&&e&&e.readyState===e.OPEN)for(;o.length;)e.send(Uint8Array.from(Vn(o.shift())))}return{get awareness(){return f.awareness},get clientId(){return d.clientID},people:()=>sr(f.awareness.getStates()),states:()=>{let e=new Map(f.awareness.getStates());return e.delete(d.clientID),e},status:()=>c,saveStatus:()=>l?tr(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){p&&(o.push(e),oe())},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(),p?.destroy(),p?.doc.destroy(),r.clear(),i.clear(),a.clear(),s=void 0}}}var gu,_u=t((()=>{$n(),rr(),lr(),qn(),on(),Ll(),pu(),jl(),gu=1047552}));l();var vu=new Map;function yu(e){try{return sessionStorage.getItem(e)??void 0}catch{return vu.get(e)}}function bu(e,t){t===void 0?vu.delete(e):vu.set(e,t);try{t===void 0?sessionStorage.removeItem(e):sessionStorage.setItem(e,t)}catch{}}function xu(e){return btoa(String.fromCharCode(...e)).replaceAll(`+`,`-`).replaceAll(`/`,`_`).replace(/=+$/,``)}function Su(e){if(typeof e!=`object`||!e||Array.isArray(e))throw f(400);return{...e}}function Cu(e){let t=Su(e);for(let e of[`files`,`outbox`,`attachments`])delete t[e];return t}function wu(e){if(typeof e!=`string`||e.length===0)throw f(400);return e}function Tu(e){let t=typeof e==`object`&&e?Reflect.get(e,`subject`):void 0;if(typeof t!=`object`||!t)return;let n=Reflect.get(t,`kind`),r=Reflect.get(t,`id`);return typeof n==`string`&&typeof r==`string`?{kind:n,id:r}:void 0}function Eu(e){let t=e instanceof s?e:f(0,e),n=Reflect.get(t,`status`);return{code:t.code,why:t.message,...t.fix?{fix:t.fix}:{},status:typeof n==`number`?n:0}}async function Du(e,t){let n={user:e.user,can:{read:e.can.read,comment:e.can.comment,resolve:e.can.resolve,delete:!1,change:!1},realtime:!1,attachments:!1,presence:!1,content:!1,...e.subject?{subject:e.subject}:{},...e.revision===void 0?{}:{revision:e.revision}};return e.user?n:{...n,signIn:{provider:`console`,url:await t()}}}function Ou(e,t){let n=`/comments/${encodeURIComponent(t)}`,r=`vitehub-comments:${t}:token`,i=`vitehub-comments:${t}:verifier`,a=()=>{let e=yu(r);return e?{authorization:`Bearer ${e}`}:{}},o,s,c,l=0;function u(e){if(Reflect.get(Object(e),`type`)===re.type){bu(r,void 0),d(void 0),o?.postMessage({event:ye});return}let t=Tu(e);t&&c&&t.kind===c.kind&&t.id===c.id&&o?.postMessage({event:ye})}async function d(e){let n=yu(r);c=e?.subject;let i=e?.realtime&&e.user&&n?ne(t):void 0;if(s&&s.room===i&&s.token===n||(s?.leave(),s=void 0,!i||!n))return;let a={room:i,token:n,leave:()=>{}};s=a;let o=await Te(()=>Promise.resolve().then(()=>(_u(),mu)),void 0,import.meta.url).catch(()=>void 0);if(!o||s!==a)return;let l=o.connectRealtimeRoom(te,i,{baseURL:`/`,params:{token:n}});l.onNotice(u),a.leave=()=>l.destroy()}async function ee(){let e=yu(i);e||(e=xu(crypto.getRandomValues(new Uint8Array(32))),bu(i,e));let t=xu(new Uint8Array(await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(e))));return`${location.origin}${n}/authorize?challenge=${t}`}let ie=()=>Du({user:null,can:{read:!1,comment:!1,resolve:!1},realtime:!1,content:!1},ee);async function p(e){let t=++l,i=yu(r);if(!i)return d(void 0),await ie();let a=()=>t===l&&yu(r)===i,o=fe({route:`${n}/api`,headers:{authorization:`Bearer ${i}`},credentials:`omit`});try{let t=(await o(`/session?page=${encodeURIComponent(e)}`)).data;return a()&&d(t),await Du(t,ee)}catch(e){if(Reflect.get(Object(e),`status`)!==401)throw e;return a()&&(bu(r,void 0),d(void 0)),await ie()}}async function ae(e){let t=yu(i);if(!t)return!1;let a=await fetch(`${n}/redeem`,{method:`POST`,credentials:`omit`,cache:`no-store`,headers:{"content-type":`application/json`},body:JSON.stringify({code:e,verifier:t})}).catch(e=>{throw f(0,e)}),o=await a.json().catch(()=>void 0),s=typeof o==`object`&&o?Reflect.get(o,`token`):void 0;if(!a.ok||typeof s!=`string`||!s)throw f(a.status);return bu(r,s),bu(i,void 0),!0}function oe(e,t){let{input:n}=e;switch(e.method){case`session`:return p(wu(n));case`redeem`:return ae(wu(n));case`list`:return t.list(Su(n));case`get`:return t.get(Su(n));case`create`:return t.create(Cu(n));case`reply`:return t.reply(Cu(n));case`resolve`:return t.resolve({threadId:wu(Su(n).threadId)});case`reopen`:return t.reopen({threadId:wu(Su(n).threadId)})}}async function se(e){let t=[],r=ge({route:`${n}/api`,headers:a,credentials:`omit`,onAnswer:e=>t.push(...e.people)});try{return{id:e.id,ok:!0,value:await oe(e,r),people:t}}catch(t){return{id:e.id,ok:!1,error:Eu(t)}}}addEventListener(`message`,t=>{if(o||t.origin!==e||t.source!==parent||t.data===null||typeof t.data!=`object`||Reflect.get(t.data,`type`)!==`vitehub-comments:connect`)return;let[n]=t.ports;n&&(o=n,n.addEventListener(`message`,e=>{ve(e.data)&&se(e.data).then(e=>n.postMessage(e))}),n.start(),n.postMessage({event:`ready`}))})}var{origin:ku,project:Au}=document.documentElement.dataset;ku&&Au&&parent!==window&&Ou(ku,Au);
|