@vite-hub/comments 0.1.0 → 0.3.1

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.
Files changed (87) hide show
  1. package/README.md +79 -31
  2. package/dist/anchor.d.ts +7 -4
  3. package/dist/anchor.js +10 -5
  4. package/dist/client-diagnostics-CcFpkbAk.js +40 -0
  5. package/dist/client.d.ts +78 -3
  6. package/dist/client.js +198 -13
  7. package/dist/{console-BIz9t2cO.d.ts → console-h4KlhIik.d.ts} +97 -8
  8. package/dist/context-BqIsmYP1.js +61 -0
  9. package/dist/database/postgres.d.ts +738 -347
  10. package/dist/database/postgres.js +28 -7
  11. package/dist/{database-Cb2xjC1V.d.ts → database-CA1aHKN7.d.ts} +675 -276
  12. package/dist/database.d.ts +6 -98
  13. package/dist/database.js +2 -3
  14. package/dist/define-43mMR39K.js +89 -0
  15. package/dist/define-B3TF9zzn.d.ts +204 -0
  16. package/dist/errors-4gelGVmK.js +57 -0
  17. package/dist/errors-C6qptPoG.js +135 -0
  18. package/dist/errors-CyQyKAvy.d.ts +185 -0
  19. package/dist/fold-name-B7Zb3-MF.js +7 -0
  20. package/dist/{identity-3qtVC4rF.js → identity-CBOzgxSf.js} +7 -2
  21. package/dist/index-DNhy69Wt.d.ts +83 -0
  22. package/dist/index.d.ts +7 -7
  23. package/dist/index.js +196 -5
  24. package/dist/install-BcMPgPk_.js +1154 -0
  25. package/dist/install-W9ghhGoh.d.ts +36 -0
  26. package/dist/installed-B-PfERBU.js +30 -0
  27. package/dist/invariant-D8_xBqmZ.js +22 -0
  28. package/dist/migrate-B0k_0swk.d.ts +54 -0
  29. package/dist/migrate-BDQ8xqUs.js +289 -0
  30. package/dist/object-Da1zyPCR.js +11 -0
  31. package/dist/{operations-0B0QTVWX.d.ts → operations-D4A1Fcgf.d.ts} +37 -15
  32. package/dist/operations-DMMIfYPW.js +1159 -0
  33. package/dist/operations-GLeOqgMt.d.ts +257 -0
  34. package/dist/operations.d.ts +3 -7
  35. package/dist/operations.js +3 -2
  36. package/dist/overlay/client-DmsSMOzi.js +4 -0
  37. package/dist/overlay/dist-BoHMOFax.js +14 -0
  38. package/dist/overlay/dist-yIZmvSaU.js +1 -0
  39. package/dist/overlay/overlay.js +183 -177
  40. package/dist/page/loader.js +138 -18
  41. package/dist/{page-BuroSMXO.js → page-B41ozN63.js} +8 -6
  42. package/dist/{page-BtXADR6d.d.ts → page-DtbMOEMd.d.ts} +6 -5
  43. package/dist/page-tools-shared-NHUjKI8E.js +117 -0
  44. package/dist/path--zk6PEMz.js +18 -0
  45. package/dist/plugin-PS8PMYus.js +74 -0
  46. package/dist/realtime.d.ts +6 -12
  47. package/dist/realtime.js +23 -24
  48. package/dist/rpc-HBcWtg0T.d.ts +17 -0
  49. package/dist/rpc-RKPAusHp.js +153 -0
  50. package/dist/rpc.d.ts +2 -29
  51. package/dist/rpc.js +2 -75
  52. package/dist/runtime/auth.d.ts +5 -3
  53. package/dist/runtime/auth.js +8 -5
  54. package/dist/runtime/console.d.ts +1 -1
  55. package/dist/runtime/console.js +26 -21
  56. package/dist/runtime/index.d.ts +108 -60
  57. package/dist/runtime/index.js +684 -236
  58. package/dist/{server-BomGg3Gb.js → server-D8k-0GXe.js} +16 -7
  59. package/dist/server.d.ts +14 -88
  60. package/dist/server.js +7 -326
  61. package/dist/service-CFVm23k7.d.ts +158 -0
  62. package/dist/service-GHhhyQj4.js +609 -0
  63. package/dist/session-DVx-1Tym.d.ts +14 -0
  64. package/dist/session-EkudzUmm.js +503 -0
  65. package/dist/testing.d.ts +1 -1
  66. package/dist/testing.js +14 -2
  67. package/dist/tokens-DSbwkVSy.js +58 -0
  68. package/dist/types-BIS0hCEl.d.ts +124 -0
  69. package/dist/types-CZujrMFd.d.ts +322 -0
  70. package/dist/vite.d.ts +91 -87
  71. package/dist/vite.js +535 -796
  72. package/package.json +24 -27
  73. package/dist/database-BSnVrwHn.js +0 -60
  74. package/dist/database-C-ktS9Do.js +0 -95
  75. package/dist/define-BzW2Ychn.d.ts +0 -46
  76. package/dist/define-Cbhl6QVJ.js +0 -32
  77. package/dist/errors-BAQYcy3_.d.ts +0 -89
  78. package/dist/errors-DeD6wTCl.js +0 -77
  79. package/dist/h3-v1-request-DDGXJ9E7.js +0 -166
  80. package/dist/index-DklG2Etf.d.ts +0 -111
  81. package/dist/operations-NZG5dB8y.js +0 -732
  82. package/dist/page-tools-shared-D-amu6sx.js +0 -53
  83. package/dist/plugin-QElKQYkA.js +0 -725
  84. package/dist/request-DVc3M_AG.js +0 -14
  85. package/dist/src-CRTwnaEG.js +0 -1362
  86. package/dist/types-Cj8K7Vx7.d.ts +0 -176
  87. package/dist/types-Un2dcJWD.d.ts +0 -288
@@ -0,0 +1,257 @@
1
+ import { C as CommentUploadInput, S as CommentThread, T as CommentUsersInput, b as CommentStatusInput, c as CommentCreateInput, g as CommentMessage, h as CommentListQuery, i as CommentAttachment, l as CommentDeleteInput, n as CommentActor, p as CommentGetInput, s as CommentContext, u as CommentEditInput, v as CommentReplyInput, w as CommentUser } from "./types-CZujrMFd.js";
2
+ import { f as CommentsPolicyGate, g as CommentsUser } from "./define-B3TF9zzn.js";
3
+ import { i as CommentsRuntime, t as CommentsAttachmentBody } from "./service-CFVm23k7.js";
4
+ import { t as AnyOperation } from "./operations-D4A1Fcgf.js";
5
+ import * as v from "valibot";
6
+ //#region src/operations-core/operations.d.ts
7
+ declare const anchor: v.UnionSchema<[v.StrictObjectSchema<{
8
+ readonly kind: v.LiteralSchema<"page", undefined>;
9
+ }, undefined>, v.StrictObjectSchema<{
10
+ readonly field: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 512, undefined>]>, undefined>;
11
+ readonly kind: v.LiteralSchema<"element", undefined>;
12
+ readonly label: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 200, undefined>]>, undefined>;
13
+ readonly page: v.OptionalSchema<v.StrictObjectSchema<{
14
+ readonly x: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 1000, undefined>]>;
15
+ readonly y: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 1000000, undefined>]>;
16
+ }, undefined>, undefined>;
17
+ readonly selector: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 2048, undefined>]>;
18
+ readonly viewport: v.OptionalSchema<v.StrictObjectSchema<{
19
+ readonly width: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 100000, undefined>]>;
20
+ }, undefined>, undefined>;
21
+ readonly x: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 1000, undefined>]>;
22
+ readonly y: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 1000, undefined>]>;
23
+ }, undefined>, v.StrictObjectSchema<{
24
+ readonly exact: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 2000, undefined>]>;
25
+ readonly kind: v.LiteralSchema<"text", undefined>;
26
+ readonly prefix: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 2000, undefined>]>;
27
+ readonly selector: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 2048, undefined>]>;
28
+ readonly suffix: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 2000, undefined>]>;
29
+ }, undefined>, v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
30
+ readonly height: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 1, undefined>, v.MaxValueAction<number, 1000, undefined>]>;
31
+ readonly kind: v.LiteralSchema<"area", undefined>;
32
+ readonly selector: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 2048, undefined>]>;
33
+ readonly width: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 1, undefined>, v.MaxValueAction<number, 1000, undefined>]>;
34
+ readonly x: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 1000, undefined>]>;
35
+ readonly y: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 1000, undefined>]>;
36
+ }, undefined>, v.CheckAction<{
37
+ height: number;
38
+ kind: "area";
39
+ selector: string;
40
+ width: number;
41
+ x: number;
42
+ y: number;
43
+ }, "An area must stay inside the element box: x + width and y + height are at most 1000.">]>, v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
44
+ readonly height: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 1, undefined>, v.MaxValueAction<number, 1000, undefined>]>, undefined>;
45
+ readonly kind: v.LiteralSchema<"image", undefined>;
46
+ readonly selector: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 2048, undefined>]>;
47
+ readonly width: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 1, undefined>, v.MaxValueAction<number, 1000, undefined>]>, undefined>;
48
+ readonly x: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 1000, undefined>]>;
49
+ readonly y: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 1000, undefined>]>;
50
+ }, undefined>, v.CheckAction<{
51
+ height?: number | undefined;
52
+ kind: "image";
53
+ selector: string;
54
+ width?: number | undefined;
55
+ x: number;
56
+ y: number;
57
+ }, "An image area needs width and height together.">, v.CheckAction<{
58
+ height?: number | undefined;
59
+ kind: "image";
60
+ selector: string;
61
+ width?: number | undefined;
62
+ x: number;
63
+ y: number;
64
+ }, "An image area must stay inside the element box.">]>], undefined>;
65
+ /** The anchor that `comments.create` takes, for the overlay API, which reads its input itself. */
66
+ declare const commentAnchorSchema: typeof anchor;
67
+ /**
68
+ * Who calls a comment action, as the transport that received it checked: the operation RPC, the CLI, and MCP through
69
+ * the Console's access check, or the overlay API through the session of its request.
70
+ */
71
+ interface CommentsCaller {
72
+ runtime: CommentsRuntime;
73
+ /** The signed-in user, or null. A guest is null here; the request headers name it. */
74
+ user: CommentsUser | null;
75
+ actor?: CommentActor;
76
+ /** What the transport checked before, for the default policy. */
77
+ gate: CommentsPolicyGate;
78
+ /** The Console admitted the caller to its Comments section. `authorize` gets it as `console`. */
79
+ console?: boolean;
80
+ /** The request, for the guest headers of an anonymous writer. */
81
+ request?: Request;
82
+ waitUntil?: (task: Promise<unknown>) => void;
83
+ }
84
+ /** The inputs of the comment actions, for transports that read their input themselves, such as the overlay API. */
85
+ declare const commentInputSchemas: {
86
+ readonly attachment: v.StrictObjectSchema<{
87
+ readonly key: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 500, undefined>]>;
88
+ }, undefined>;
89
+ readonly create: v.StrictObjectSchema<{
90
+ readonly anchor: v.UnionSchema<[v.StrictObjectSchema<{
91
+ readonly kind: v.LiteralSchema<"page", undefined>;
92
+ }, undefined>, v.StrictObjectSchema<{
93
+ readonly field: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 512, undefined>]>, undefined>;
94
+ readonly kind: v.LiteralSchema<"element", undefined>;
95
+ readonly label: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 200, undefined>]>, undefined>;
96
+ readonly page: v.OptionalSchema<v.StrictObjectSchema<{
97
+ readonly x: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 1000, undefined>]>;
98
+ readonly y: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 1000000, undefined>]>;
99
+ }, undefined>, undefined>;
100
+ readonly selector: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 2048, undefined>]>;
101
+ readonly viewport: v.OptionalSchema<v.StrictObjectSchema<{
102
+ readonly width: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 100000, undefined>]>;
103
+ }, undefined>, undefined>;
104
+ readonly x: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 1000, undefined>]>;
105
+ readonly y: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 1000, undefined>]>;
106
+ }, undefined>, v.StrictObjectSchema<{
107
+ readonly exact: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 2000, undefined>]>;
108
+ readonly kind: v.LiteralSchema<"text", undefined>;
109
+ readonly prefix: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 2000, undefined>]>;
110
+ readonly selector: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 2048, undefined>]>;
111
+ readonly suffix: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 2000, undefined>]>;
112
+ }, undefined>, v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
113
+ readonly height: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 1, undefined>, v.MaxValueAction<number, 1000, undefined>]>;
114
+ readonly kind: v.LiteralSchema<"area", undefined>;
115
+ readonly selector: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 2048, undefined>]>;
116
+ readonly width: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 1, undefined>, v.MaxValueAction<number, 1000, undefined>]>;
117
+ readonly x: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 1000, undefined>]>;
118
+ readonly y: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 1000, undefined>]>;
119
+ }, undefined>, v.CheckAction<{
120
+ height: number;
121
+ kind: "area";
122
+ selector: string;
123
+ width: number;
124
+ x: number;
125
+ y: number;
126
+ }, "An area must stay inside the element box: x + width and y + height are at most 1000.">]>, v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
127
+ readonly height: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 1, undefined>, v.MaxValueAction<number, 1000, undefined>]>, undefined>;
128
+ readonly kind: v.LiteralSchema<"image", undefined>;
129
+ readonly selector: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 2048, undefined>]>;
130
+ readonly width: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 1, undefined>, v.MaxValueAction<number, 1000, undefined>]>, undefined>;
131
+ readonly x: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 1000, undefined>]>;
132
+ readonly y: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 1000, undefined>]>;
133
+ }, undefined>, v.CheckAction<{
134
+ height?: number | undefined;
135
+ kind: "image";
136
+ selector: string;
137
+ width?: number | undefined;
138
+ x: number;
139
+ y: number;
140
+ }, "An image area needs width and height together.">, v.CheckAction<{
141
+ height?: number | undefined;
142
+ kind: "image";
143
+ selector: string;
144
+ width?: number | undefined;
145
+ x: number;
146
+ y: number;
147
+ }, "An image area must stay inside the element box.">]>], undefined>;
148
+ readonly attachments: v.OptionalSchema<v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 500, undefined>]>, undefined>, v.MaxLengthAction<string[], 10, undefined>]>, undefined>;
149
+ readonly body: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 10000, undefined>]>;
150
+ readonly mentions: v.OptionalSchema<v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 100, undefined>]>, undefined>, v.MaxLengthAction<string[], 20, undefined>]>, undefined>;
151
+ readonly metadata: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.UnionSchema<[v.StringSchema<undefined>, v.NumberSchema<undefined>, v.BooleanSchema<undefined>, v.NullSchema<undefined>], undefined>, undefined>, undefined>;
152
+ readonly requestId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 200, undefined>]>, undefined>;
153
+ readonly revision: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
154
+ readonly subject: v.StrictObjectSchema<{
155
+ readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 500, undefined>]>;
156
+ readonly kind: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 40, undefined>]>;
157
+ }, undefined>;
158
+ }, undefined>;
159
+ readonly delete: v.StrictObjectSchema<{
160
+ readonly messageId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 100, undefined>]>, undefined>;
161
+ readonly threadId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 100, undefined>]>;
162
+ }, undefined>;
163
+ readonly edit: v.StrictObjectSchema<{
164
+ readonly body: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 10000, undefined>]>;
165
+ readonly mentions: v.OptionalSchema<v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 100, undefined>]>, undefined>, v.MaxLengthAction<string[], 20, undefined>]>, undefined>;
166
+ readonly messageId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 100, undefined>]>;
167
+ readonly threadId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 100, undefined>]>;
168
+ }, undefined>;
169
+ readonly get: v.UnionSchema<[v.StrictObjectSchema<{
170
+ readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 100, undefined>]>;
171
+ }, undefined>, v.StrictObjectSchema<{
172
+ readonly n: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>;
173
+ readonly scope: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 200, undefined>]>;
174
+ }, undefined>], undefined>;
175
+ readonly list: v.StrictObjectSchema<{
176
+ readonly before: v.OptionalSchema<v.StrictObjectSchema<{
177
+ readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 100, undefined>]>;
178
+ readonly updatedAt: v.NumberSchema<undefined>;
179
+ }, undefined>, undefined>;
180
+ readonly limit: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>, v.MaxValueAction<number, 500, undefined>]>, undefined>;
181
+ readonly mentions: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
182
+ readonly mine: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
183
+ readonly page: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.DescriptionAction<string, "A path such as /pricing, or a full URL of the page.">, v.TransformAction<string, string>, v.CheckAction<string, "A page is an app path that starts with one \"/\", such as \"/pricing\", without \"?\" or \"#\", or a full http(s) URL of the page.">, v.TransformAction<string, string>]>, undefined>;
184
+ readonly revision: v.OptionalSchema<v.StrictObjectSchema<{
185
+ readonly lte: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
186
+ }, undefined>, undefined>;
187
+ readonly status: v.OptionalSchema<v.PicklistSchema<["open", "resolved"], undefined>, undefined>;
188
+ readonly subject: v.OptionalSchema<v.StrictObjectSchema<{
189
+ readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 500, undefined>]>;
190
+ readonly kind: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 40, undefined>]>;
191
+ }, undefined>, undefined>;
192
+ readonly subjectKind: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 40, undefined>]>, undefined>;
193
+ }, undefined>;
194
+ readonly reply: v.StrictObjectSchema<{
195
+ readonly attachments: v.OptionalSchema<v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 500, undefined>]>, undefined>, v.MaxLengthAction<string[], 10, undefined>]>, undefined>;
196
+ readonly body: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 10000, undefined>]>;
197
+ readonly mentions: v.OptionalSchema<v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 100, undefined>]>, undefined>, v.MaxLengthAction<string[], 20, undefined>]>, undefined>;
198
+ readonly threadId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 100, undefined>]>;
199
+ }, undefined>;
200
+ readonly status: v.StrictObjectSchema<{
201
+ readonly threadId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 100, undefined>]>;
202
+ }, undefined>;
203
+ readonly upload: v.StrictObjectSchema<{
204
+ readonly data: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
205
+ readonly name: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 200, undefined>]>;
206
+ readonly subject: v.OptionalSchema<v.StrictObjectSchema<{
207
+ readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 500, undefined>]>;
208
+ readonly kind: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 40, undefined>]>;
209
+ }, undefined>, undefined>;
210
+ readonly type: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 100, undefined>]>;
211
+ }, undefined>;
212
+ readonly users: v.StrictObjectSchema<{
213
+ readonly limit: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>, v.MaxValueAction<number, 10, undefined>]>, undefined>;
214
+ readonly query: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 100, undefined>]>;
215
+ readonly subject: v.OptionalSchema<v.StrictObjectSchema<{
216
+ readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 500, undefined>]>;
217
+ readonly kind: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 40, undefined>]>;
218
+ }, undefined>, undefined>;
219
+ readonly threadId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 100, undefined>]>, undefined>;
220
+ }, undefined>;
221
+ };
222
+ /**
223
+ * The comment actions behind every surface. The operations (RPC, CLI, MCP) and the overlay API call the same
224
+ * functions, so one policy, one set of checks, and one set of errors serve them all. Each one checks `authorize` for
225
+ * its caller; the input must have passed `commentInputSchemas`.
226
+ */
227
+ declare const commentActions: {
228
+ list(input: CommentListQuery, who: CommentsCaller): Promise<CommentThread[]>;
229
+ get(input: CommentGetInput, who: CommentsCaller): Promise<CommentThread | null>;
230
+ /** `context` is the page context that the overlay read and its transport checked. */
231
+ create(input: CommentCreateInput & {
232
+ context?: CommentContext;
233
+ }, who: CommentsCaller): Promise<CommentThread>;
234
+ /** `allowResolved`: the operations keep a reply box on resolved threads, and a reply keeps the thread resolved. */
235
+ reply(input: CommentReplyInput, who: CommentsCaller, options?: {
236
+ allowResolved?: boolean;
237
+ }): Promise<{
238
+ thread: CommentThread;
239
+ message: CommentMessage;
240
+ }>;
241
+ edit(input: CommentEditInput, who: CommentsCaller): Promise<CommentThread>;
242
+ delete(input: CommentDeleteInput, who: CommentsCaller): Promise<CommentThread | null>;
243
+ setStatus(input: CommentStatusInput, who: CommentsCaller, status: "open" | "resolved"): Promise<CommentThread>;
244
+ /** `minimum`: the shortest query that gets suggestions. The operations ask for two characters. */
245
+ users(input: CommentUsersInput, who: CommentsCaller, options?: {
246
+ minimum?: number;
247
+ }): Promise<CommentUser[]>;
248
+ upload(input: CommentUploadInput, who: CommentsCaller): Promise<CommentAttachment>;
249
+ /** The file of an attachment key, for a caller who may read a thread whose messages list it. */
250
+ attachment(input: {
251
+ key: string;
252
+ }, who: CommentsCaller): Promise<CommentsAttachmentBody>;
253
+ };
254
+ /** The comment operations. The Console, the CLI, MCP, and the comments client call them. */
255
+ declare const commentsOperations: readonly AnyOperation[];
256
+ //#endregion
257
+ export { commentsOperations as a, commentInputSchemas as i, commentActions as n, commentAnchorSchema as r, CommentsCaller as t };
@@ -1,7 +1,3 @@
1
- import { t as AnyOperation } from "./operations-0B0QTVWX.js";
2
- //#region src/operations-core/operations.d.ts
3
- /** Longest message, in characters. */
4
- export declare const maximumCommentBodyLength = 10000;
5
- /** The comment operations. The Console, the CLI, MCP, and the comments client call them. */
6
- export declare const commentsOperations: readonly AnyOperation[];
7
- //#endregion
1
+ import { a as maximumCommentBodyLength } from "./service-CFVm23k7.js";
2
+ import { a as commentsOperations, i as commentInputSchemas, n as commentActions, r as commentAnchorSchema, t as CommentsCaller } from "./operations-GLeOqgMt.js";
3
+ export { CommentsCaller, commentActions, commentAnchorSchema, commentInputSchemas, commentsOperations, maximumCommentBodyLength };
@@ -1,2 +1,3 @@
1
- import { n as maximumCommentBodyLength, t as commentsOperations } from "./operations-NZG5dB8y.js";
2
- export { commentsOperations, maximumCommentBodyLength };
1
+ import { i as commentsOperations, n as commentAnchorSchema, r as commentInputSchemas, t as commentActions } from "./operations-DMMIfYPW.js";
2
+ import { u as maximumCommentBodyLength } from "./service-GHhhyQj4.js";
3
+ export { commentActions, commentAnchorSchema, commentInputSchemas, commentsOperations, maximumCommentBodyLength };
@@ -0,0 +1,4 @@
1
+ import{n as e,t}from"./dist-yIZmvSaU.js";var n={why:({message:e})=>e===void 0?``:String(e)},r={RUNTIME_R0001:{...n,fix:"Pass `maxDepth` to `normalizeRuntimeDiagnosticError()` as an integer of 0 or more, or remove it to use the default."},RUNTIME_R0002:{...n,fix:"Pass `maxErrors` to `normalizeRuntimeDiagnosticError()` as an integer of 1 or more, or remove it to use the default."},RUNTIME_R0003:{...n,fix:"Pass `maxStringLength` to `normalizeRuntimeDiagnosticError()` as an integer of 64 or more, or remove it to use the default."},RUNTIME_R0004:{...n,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:{...n,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:{...n,fix:"Pass `new ViteHubError()` a nonempty `code` and `message` string within the length limits, and plain JSON `details`."},RUNTIME_R0007:{...n,fix:"Give the execution authority a valid value for each of `credentials`, `environment`, `filesystem.access`, `filesystem.scope`, `isolation`, `network`, and `processes`."},RUNTIME_R0009:{...n,fix:"Set `intervalMs` of the process reconciler to a number of milliseconds from 1 to 2147483647."},RUNTIME_R0010:{...n,fix:"Give the process reconciler a `signal` other than `SIGKILL` or `SIGSTOP`, or set `signal: false`."},RUNTIME_R0011:{...n,fix:"Call `drain()` of the process reconciler after its callback returns, not from inside the callback."},RUNTIME_R0015:{...n,fix:"Pass the `Request` of a Fetchable handler, or the event of an H3 or Nitro route, to `getStandardContext()`."},RUNTIME_R0016:{...n,fix:"Return the body or a `Response` from the handler, in place of setting `~standard.res.body`."},RUNTIME_R0017:n,RUNTIME_R0018:n,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_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_SERIALIZED_RESPONSE_INVALID:{why:()=>`Invalid serialized Response`,fix:"Pass `deserializeResponse()` the record that `serializeResponse()` returned, unchanged. Check it first with `isSerializedResponse()`."}},i=e({docsBase:`https://vitehub.dev/docs/development/diagnostics`,codes:r});function a(e){return e!==null&&Object(e)===e}var o=8,s=128,c=128,l=1024,u=16384,d=128,f=16384,ee=256,te=new WeakMap;function p(){throw i.RUNTIME_R0006({message:`[vitehub] ViteHubError requires a valid public error contract.`})}function ne(e){try{return Array.isArray(e)}catch{p()}}function m(e,t,n=!1){try{let r=Object.getOwnPropertyDescriptor(e,t);return r===void 0?void 0:((!(`value`in r)||n&&!r.enumerable)&&p(),r.value)}catch{p()}}function re(e,t,n,r){if(t.nodes+=1,t.nodes>l&&p(),e===void 0&&r)return;if(e===null||typeof e==`boolean`||typeof e==`string`&&e.length<=u||typeof e==`number`&&Number.isFinite(e))return e;(typeof e!=`object`||n>o||t.ancestors.has(e))&&p();let i,a;try{i=Object.getPrototypeOf(e),a=Reflect.ownKeys(e)}catch{p()}t.ancestors.add(e);try{if(ne(e)){let r=m(e,`length`);(!Number.isSafeInteger(r)||r<0||r>s||a.length!==r+1||!a.includes(`length`))&&p();let i=[];for(let o=0;o<r;o+=1){let r=String(o);a.includes(r)||p(),i.push(re(m(e,r,!0),t,n+1,!1))}return Object.freeze(i)}i!==Object.prototype&&i!==null&&p(),(a.length>s||a.some(e=>typeof e!=`string`))&&p();let r={};for(let i of a)(i.length===0||i.length>c)&&p(),Object.defineProperty(r,i,{enumerable:!0,value:re(m(e,i,!0),t,n+1,!0),writable:!0});return Object.freeze(r)}finally{t.ancestors.delete(e)}}function ie(e){if(e!==void 0)return(typeof e!=`object`||!e||ne(e))&&p(),re(e,{ancestors:new Set,nodes:0},0,!1)}function ae(e,t,n){(typeof e!=`string`||e.length===0||e.length>d)&&p(),(typeof t!=`string`||t.length===0||t.length>f)&&p(),(typeof n!=`object`||!n||ne(n))&&p();let r=m(n,`cause`),i=ie(m(n,`details`)),a=m(n,`requestId`);return a!==void 0&&(typeof a!=`string`||a.length===0||a.length>ee)&&p(),{cause:r,code:e,details:i,message:t,name:`ViteHubError`,requestId:a,shape:Object.freeze({code:e,...i===void 0?{}:{details:i},message:t,name:`ViteHubError`,...a===void 0?{}:{requestId:a}})}}var oe=class extends Error{code;details;requestId;constructor(e,t,n={}){let r=ae(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}}),te.set(this,r.shape)}toJSON(){let e=te.get(this);if(e)return e;let t=ae(m(this,`code`),m(this,`message`),{details:m(this,`details`),requestId:m(this,`requestId`)});return te.set(this,t.shape),t.shape}};function se(e){if(!a(e))return!1;try{let t=Reflect.get(Error,`isError`);if(!(typeof t==`function`?t(e)===!0:e instanceof Error||!(Symbol.toStringTag in e)&&Object.prototype.toString.call(e)===`[object Error]`))return!1;let n=Reflect.get(e,`message`),r=Reflect.get(e,`code`),i=Reflect.get(e,`name`),a=Reflect.get(e,`why`),o=Reflect.get(e,`fix`),s=Reflect.get(e,`docs`),c=Reflect.get(e,`sources`);return typeof r==`string`&&r.length>0&&typeof i==`string`&&typeof n==`string`&&a===n&&(o===void 0||typeof o==`string`)&&(s===void 0||typeof s==`string`)&&(c===void 0||Array.isArray(c)&&c.every(e=>typeof e==`string`))&&typeof Reflect.get(e,`toJSON`)==`function`}catch{return!1}}function ce(e){let n=t=>{let n=Object.getOwnPropertyDescriptor(e,t);return n?n.configurable===!0:Object.isExtensible(e)},r=n(`name`)&&n(`toJSON`)?e:new t({code:e.code,why:e.why,fix:e.fix,docs:e.docs,cause:e.cause,data:e.data,sources:e.sources});return r!==e&&(r.stack=e.stack),Object.defineProperty(r,"name",{configurable:!0,value:r.code,writable:!0}),Object.defineProperty(r,"toJSON",{configurable:!0,value:()=>({code:r.code,docs:r.docs,fix:r.fix,name:r.name,why:r.why})}),r}function le(t){let n=e({codes:t.codes,docsBase:t.docs}),r=new Set(Object.keys(t.codes)),i=Object.defineProperty({},"is",{value:e=>se(e)&&r.has(e.code)});for(let e of r){let t=n[e];i[e]=Object.assign(e=>ce(t(e)),{is:t=>se(t)&&t.code===e})}return i}var ue=le({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_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_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, and `error.cause` for a network error. Retry when the server is available again."},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 `auth: true` to require a signed-in user, add `authorize()` to decide each request, or set `access: "public"` to let anyone read and write.'},REALTIME_INVALID_ACCESS:{why:({reason:e})=>e===`public-with-rule`?'The Realtime definition sets `access: "public"` together with `auth` or `authorize()`, so its access rule is not clear.':e===`not-public`?'The Realtime definition sets `access` to a value other than "public".':"The Realtime definition sets `origins()` with `auth: true` and no `identify()`. The ViteHub Auth session is a cookie, so ViteHub accepts it only from the app's own origin.",fix:({reason:e})=>e===`origins-without-identify`?"Remove `origins()`, or add `identify()` that reads a credential the page sends on purpose, such as a ticket in `params`.":'Use `access: "public"` alone for open rooms. To limit access, remove `access` and set `auth: true` or `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 is not set.`:`Realtime driver "postgres" shares rooms through Postgres, and the app has no Postgres Default Database and no REALTIME_POSTGRES_URL.`,fix:'Set REDIS_URL for Redis. For Postgres, define the Default Database with `dialect: "postgresql"`, or set REALTIME_POSTGRES_URL. Or set `realtime.driver` to "auto".'},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".'},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 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.`}}}),h=Math.floor,de=Math.abs,fe=(e,t)=>e<t?e:t,pe=(e,t)=>e>t?e:t;Number.isNaN;var me=Math.pow,he=e=>e===0?1/e<0:e<0,ge=2**53-1,_e=-(2**53-1),ve=Number.isInteger||(e=>typeof e==`number`&&isFinite(e)&&h(e)===e);Number.isNaN,Number.parseInt;var ye=()=>new Set,be=e=>e[e.length-1],xe=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},g=Array.from,Se=(e,t)=>{for(let n=0;n<e.length;n++)if(!t(e[n],n,e))return!1;return!0},Ce=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1},we=(e,t)=>{let n=Array(e);for(let r=0;r<e;r++)n[r]=t(r,n);return n},Te=Array.isArray,Ee=String.fromCharCode;String.fromCodePoint,Ee(65535);var De=e=>e.toLowerCase(),Oe=/^\s*/g,ke=e=>e.replace(Oe,``),Ae=/([A-Z])/g,je=(e,t)=>ke(e.replace(Ae,e=>`${t}${De(e)}`)),Me=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},Ne=typeof TextEncoder<`u`?new TextEncoder:null,Pe=Ne?e=>Ne.encode(e):Me,Fe=typeof TextDecoder>`u`?null:new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0});Fe&&Fe.decode(new Uint8Array).length===1&&(Fe=null);var Ie=(e,t)=>we(t,()=>e).join(``),_=e=>Error(e),v=()=>{throw _(`Method unimplemented`)},y=()=>{throw _(`Unexpected case`)},Le=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},b=()=>new Le,Re=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t},x=e=>{let t=new Uint8Array(Re(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},ze=(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(pe(n,t)*2),e.cpos=0)},S=(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},Be=S,C=(e,t)=>{for(;t>127;)S(e,128|127&t),t=h(t/128);S(e,127&t)},Ve=(e,t)=>{let n=he(t);for(n&&(t=-t),S(e,(t>63?128:0)|(n?64:0)|63&t),t=h(t/64);t>0;)S(e,(t>127?128:0)|127&t),t=h(t/128)},He=new Uint8Array(3e4),Ue=He.length/3,w=Ne&&Ne.encodeInto?(e,t)=>{if(t.length<Ue){let n=Ne.encodeInto(t,He).written||0;C(e,n);for(let t=0;t<n;t++)S(e,He[t])}else T(e,Pe(t))}:(e,t)=>{let n=unescape(encodeURIComponent(t)),r=n.length;C(e,r);for(let t=0;t<r;t++)S(e,n.codePointAt(t))},We=(e,t)=>{let n=e.cbuf.length,r=e.cpos,i=fe(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(pe(n*2,a)),e.cbuf.set(t.subarray(i)),e.cpos=a)},T=(e,t)=>{C(e,t.byteLength),We(e,t)},Ge=(e,t)=>{ze(e,t);let n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},Ke=(e,t)=>Ge(e,4).setFloat32(0,t,!1),qe=(e,t)=>Ge(e,8).setFloat64(0,t,!1),Je=(e,t)=>Ge(e,8).setBigInt64(0,t,!1),Ye=new DataView(new ArrayBuffer(4)),Xe=e=>(Ye.setFloat32(0,e),Ye.getFloat32(0)===e),Ze=(e,t)=>{switch(typeof t){case`string`:S(e,119),w(e,t);break;case`number`:ve(t)&&de(t)<=2147483647?(S(e,125),Ve(e,t)):Xe(t)?(S(e,124),Ke(e,t)):(S(e,123),qe(e,t));break;case`bigint`:S(e,122),Je(e,t);break;case`object`:if(t===null)S(e,126);else if(Te(t)){S(e,117),C(e,t.length);for(let n=0;n<t.length;n++)Ze(e,t[n])}else if(t instanceof Uint8Array)S(e,116),T(e,t);else{S(e,118);let n=Object.keys(t);C(e,n.length);for(let r=0;r<n.length;r++){let i=n[r];w(e,i),Ze(e,t[i])}}break;case`boolean`:S(e,t?120:121);break;default:S(e,127)}},Qe=class extends Le{constructor(e){super(),this.w=e,this.s=null,this.count=0}write(e){this.s===e?this.count++:(this.count>0&&C(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}},$e=e=>{e.count>0&&(Ve(e.encoder,e.count===1?e.s:-e.s),e.count>1&&C(e.encoder,e.count-2))},et=class{constructor(){this.encoder=new Le,this.s=0,this.count=0}write(e){this.s===e?this.count++:($e(this),this.count=1,this.s=e)}toUint8Array(){return $e(this),x(this.encoder)}},tt=e=>{if(e.count>0){let t=e.diff*2+(e.count===1?0:1);Ve(e.encoder,t),e.count>1&&C(e.encoder,e.count-2)}},nt=class{constructor(){this.encoder=new Le,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(tt(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return tt(this),x(this.encoder)}},rt=class{constructor(){this.sarr=[],this.s=``,this.lensE=new et}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 Le;return this.sarr.push(this.s),this.s=``,w(e,this.sarr.join(``)),We(e,this.lensE.toUint8Array()),x(e)}},it=_(`Unexpected end of array`),at=_(`Integer out of Range`),ot=(e,t,n)=>{if(t<0||n<0||t+n>e.length)throw it;return new Uint8Array(e.buffer,e.byteOffset+t,n)},st=(e,t,n)=>{if(t<0||n<0||t+n>e.length)throw it;return new DataView(e.buffer,e.byteOffset+t,n)},ct=class{constructor(e){this.arr=e,this.pos=0}},E=e=>new ct(e),lt=e=>e.pos!==e.arr.length,ut=(e,t)=>{let n=ot(e.arr,e.pos,t);return e.pos+=t,n},D=e=>ut(e,O(e)),dt=e=>e.arr[e.pos++],O=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>ge)throw at}throw it},ft=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>ge)throw at}throw it},k=Fe?e=>Fe.decode(D(e)):e=>{let t=O(e);if(t===0)return``;{let n=String.fromCodePoint(dt(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(dt(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))}},pt=(e,t)=>{let n=st(e.arr,e.pos,t);return e.pos+=t,n},mt=[e=>void 0,e=>null,ft,e=>pt(e,4).getFloat32(0,!1),e=>pt(e,8).getFloat64(0,!1),e=>pt(e,8).getBigInt64(0,!1),e=>!1,e=>!0,k,e=>{let t=O(e),n={};for(let r=0;r<t;r++){let t=k(e);n[t]=ht(e)}return n},e=>{let t=O(e),n=[];for(let r=0;r<t;r++)n.push(ht(e));return n},D],ht=e=>mt[127-dt(e)](e),gt=class extends ct{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=lt(this)?O(this)+1:-1),this.count--,this.s}},_t=class extends ct{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=ft(this);let e=he(this.s);this.count=1,e&&(this.s=-this.s,this.count=O(this)+2)}return this.count--,this.s}},vt=class extends ct{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){let e=ft(this),t=e&1;this.diff=h(e/2),this.count=1,t&&(this.count=O(this)+2)}return this.s+=this.diff,this.count--,this.s}},yt=class{constructor(e){this.decoder=new _t(e),this.str=k(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}};function bt(e){let t=e.slice(0,4096);return new oe(`WORKSPACE_PATH_INVALID`,`[vitehub] Workspace path escapes the workspace root: ${JSON.stringify(t)}.`,{details:{path:t}})}function xt(e){let t=e.toLowerCase().split(`:`,1)[0];return{normalized:t.replace(/[ .]+$/,``),isTraversal:/^(?:\.(?: +[. ]*)?|\.\.(?: +[. ]*)?)$/.test(t)}}function St(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`)||i.some((e,n)=>{let r=e.toLowerCase(),i=xt(e),a=i.normalized===`.git`||/^git~\d+$/.test(i.normalized)||n===0&&i.normalized===`.vitehub`||n===0&&/^vitehu~\d+$/.test(i.normalized),o=(i.normalized===`.git`||n===0&&i.normalized===`.vitehub`)&&r===i.normalized;return i.isTraversal||a&&(!t.allowReserved||!o)}))throw bt(e);return r}var Ct=`@workspace`,wt=`ping`;function Tt(e){try{let t=JSON.parse(k(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 Et(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 St(e)===e}catch{return!1}}function Dt(e){try{let t=JSON.parse(k(e));if((t.operation===`create`||t.operation===`delete`||t.operation===`update`)&&Et(t.path))return{operation:t.operation,path:t.path};if(t.operation===`move`&&Et(t.from)&&Et(t.to))return{operation:t.operation,from:t.from,to:t.to}}catch{}}function Ot(e){let t=b();return C(t,4),w(t,JSON.stringify(e)),x(t)}function kt(e){let t=b();return C(t,6),w(t,JSON.stringify(e)),x(t)}function At(e){try{let t=JSON.parse(k(e));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 jt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var A=Date.now;function Mt(e,t=typeof __VITEHUB_APP_BASE_URL__>`u`?`/`:__VITEHUB_APP_BASE_URL__){return t===`/`?e:`${t.replace(/\/+$/,``)}${e}`}var Nt=15e3;function Pt(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=A())},t=setInterval(()=>{e.ws===r&&r.readyState===r.OPEN&&r.send(wt)},Nt)})}var Ft=Object.freeze({body:`body`,fields:`fields`,status:`status`});function It(e){return typeof e==`string`?e:null}function Lt(e){let t=e.getMap(Ft.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:It(t.get(`digest`)),error:It(t.get(`error`)),issues:i.issues,savedAt:It(t.get(`savedAt`)),savedBy:i.savedBy}}var Rt=[`#E11D48`,`#D97706`,`#059669`,`#0891B2`,`#2563EB`,`#7C3AED`,`#C026D3`];function j(e){try{return String(e)===e}catch{return!1}}function zt(e){if(!j(e.id)||!e.id||e.id.length>256)throw ue.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=(j(e.name)&&e.name||j(e.email)&&e.email||`Anonymous`).slice(0,256),r={color:Rt[Math.abs(t)%Rt.length],id:e.id,name:n};return j(e.image)&&e.image&&e.image.length<=2048&&(r.image=e.image),r}function Bt(e){return jt(e)?j(e.id)&&e.id.length>0&&e.id.length<=256&&j(e.name)&&e.name.length>0&&e.name.length<=256&&j(e.color)&&/^#[\da-f]{6}$/i.test(e.color)&&(e.image===void 0||j(e.image)&&e.image.length<=2048):!1}function Vt(e){let t=[];for(let[n,r]of e)if(Bt(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 M=()=>new Map,Ht=e=>{let t=M();return e.forEach((e,n)=>{t.set(n,e)}),t},N=(e,t,n)=>{let r=e.get(t);return r===void 0&&e.set(t,r=n()),r},Ut=(e,t)=>{let n=[];for(let[r,i]of e)n.push(t(i,r));return n},Wt=(e,t)=>{for(let[n,r]of e)if(t(r,n))return!0;return!1},Gt=class{constructor(){this._observers=M()}on(e,t){return N(this._observers,e,ye).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 g((this._observers.get(e)||M()).values()).forEach(e=>e(...t))}destroy(){this._observers=M()}},Kt=class{constructor(){this._observers=M()}on(e,t){N(this._observers,e,ye).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 g((this._observers.get(e)||M()).values()).forEach(e=>e(...t))}destroy(){this._observers=M()}},qt=Symbol(`Equality`),Jt=(e,t)=>e===t||!!e?.[qt]?.(t)||!1,Yt=e=>typeof e==`object`,Xt=Object.assign,Zt=Object.keys,Qt=(e,t)=>{for(let n in e)t(e[n],n)},$t=(e,t)=>{let n=[];for(let r in e)n.push(t(e[r],r));return n},en=e=>Zt(e).length,tn=e=>{for(let t in e)return!1;return!0},nn=(e,t)=>{for(let n in e)if(!t(e[n],n))return!1;return!0},rn=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),an=(e,t)=>e===t||en(e)===en(t)&&nn(e,(e,n)=>(e!==void 0||rn(t,n))&&Jt(t[n],e)),on=Object.freeze,sn=e=>{for(let t in e){let n=e[t];(typeof n==`object`||typeof n==`function`)&&sn(e[t])}return on(e)},cn=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&cn(e,t,n+1)}},ln=e=>e,un=(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[qt]!=null)return e[qt](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)||!un(e.get(n),t.get(n)))return!1;break;case void 0:case Object:if(en(e)!==en(t))return!1;for(let n in e)if(!rn(e,n)||!un(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(!un(e[n],t[n]))return!1;break;default:return!1}return!0},dn=(e,t)=>t.includes(e);crypto.subtle;var fn=crypto.getRandomValues.bind(crypto),pn=()=>fn(new Uint32Array(1))[0],mn=`10000000-1000-4000-8000-100000000000`,hn=()=>mn.replace(/[018]/g,e=>(e^pn()&15>>e/4).toString(16)),gn=e=>new Promise(e);Promise.all.bind(Promise);var _n=e=>e===void 0?null:e,vn=new class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}},yn=!0;try{typeof localStorage<`u`&&localStorage&&(vn=localStorage,yn=!1)}catch{}var bn=vn,xn=e=>yn||addEventListener(`storage`,e),Sn=e=>yn||removeEventListener(`storage`,e),P=typeof process<`u`&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<`u`?process:0)===`[object process]`,Cn=typeof window<`u`&&typeof document<`u`&&!P;typeof navigator<`u`&&/Mac/.test(navigator.platform);var F,wn=[],Tn=()=>{if(F===void 0){if(P){F=M();let e=process.argv,t=null;for(let n=0;n<e.length;n++){let r=e[n];r[0]===`-`?(t!==null&&F.set(t,``),t=r):t===null?wn.push(r):(F.set(t,r),t=null)}t!==null&&F.set(t,``)}else typeof location==`object`?(F=M(),(location.search||`?`).slice(1).split(`&`).forEach(e=>{if(e.length!==0){let[t,n]=e.split(`=`);F.set(`--${je(t,`-`)}`,n),F.set(`-${je(t,`-`)}`,n)}})):F=M()}return F},En=e=>Tn().has(e),Dn=e=>_n(P?{}[e.toUpperCase().replaceAll(`-`,`_`)]:bn.getItem(e)),On=e=>En(`--`+e)||Dn(e)!==null,kn=On(`production`),An=P&&dn({}.FORCE_COLOR,[`true`,`1`,`2`])||!En(`--no-colors`)&&!On(`no-color`)&&(!P||process.stdout.isTTY)&&(!P||En(`--color`)||Dn(`COLORTERM`)!==null||(Dn(`TERM`)||``).includes(`color`)),jn=e=>new Uint8Array(e),Mn=e=>new Uint8Array(e),Nn=e=>{let t=``;for(let n=0;n<e.byteLength;n++)t+=Ee(e[n]);return btoa(t)},Pn=e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString(`base64`),Fn=e=>{let t=atob(e),n=jn(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n},In=e=>new Uint8Array(Buffer.from(e,`base64`)),Ln=Cn?Nn:Pn,Rn=Cn?Fn:In,zn=e=>{let t=jn(e.byteLength);return t.set(e),t},Bn=class{constructor(e,t){this.left=e,this.right=t}},I=(e,t)=>new Bn(e,t),Vn=e=>e.next()>=.5,Hn=(e,t,n)=>h(e.next()*(n+1-t)+t),Un=(e,t,n)=>h(e.next()*(n+1-t)+t),Wn=(e,t,n)=>Un(e,t,n),Gn=e=>Ee(Wn(e,97,122)),Kn=(e,t=0,n=20)=>{let r=Wn(e,t,n),i=``;for(let t=0;t<r;t++)i+=Gn(e);return i},qn=(e,t)=>t[Wn(e,0,t.length-1)],Jn=Symbol(`0schema`),Yn=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(Ie(` `,(this._rerrs.length-t)*2)+`${n.path==null?``:`[${n.path}] `}${n.has} doesn't match ${n.expected}. ${n.message}`)}return e.join(`
2
+ `)}},Xn=(e,t)=>e===t?!0:e==null||t==null||e.constructor!==t.constructor?!1:e[qt]?Jt(e,t):Te(e)?Se(e,e=>Ce(t,t=>Xn(e,t))):Yt(e)?nn(e,(e,n)=>Xn(e,t[n])):!1,L=class{static _dilutes=!1;extends(e){let[t,n]=[this.shape,e.shape];return this.constructor._dilutes&&([n,t]=[t,n]),Xn(t,n)}equals(e){return this.constructor===e.constructor&&un(this.shape,e.shape)}[Jn](){return!0}[qt](e){return this.equals(e)}validate(e){return this.check(e)}check(e,t){v()}get nullable(){return Dr(this,Hr)}get optional(){return new ar(this)}cast(e){return Kr(e,this),e}expect(e){return Kr(e,this),e}},Zn=class extends L{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}},R=(e,t=null)=>new Zn(e,t);R(Zn);var Qn=class extends L{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}},z=e=>new Qn(e);R(Qn);var $n=class extends L{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}},er=(...e)=>new $n(e),tr=R($n),nr=RegExp.escape||(e=>e.replace(/[().|&,$^[\]]/g,e=>`\\`+e)),rr=e=>{if(Lr.check(e))return[nr(e)];if(tr.check(e))return e.shape.map(e=>e+``);if(Ir.check(e))return[`[+-]?\\d+.?\\d*`];if(Rr.check(e))return[`.*`];if(Or.check(e))return e.shape.map(rr).flat(1);y()};R(class extends L{constructor(e){super(),this.shape=e,this._r=RegExp(`^`+e.map(rr).map(e=>`(${e.join(`|`)})`).join(``)+`$`)}check(e,t){let n=this._r.exec(e)!=null;return!n&&t?.extend(null,this._r.toString(),e.toString(),`String doesn't match string template.`),n}});var ir=Symbol(`optional`),ar=class extends L{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[ir](){return!0}},or=R(ar),sr=class extends L{check(e,t){return t?.extend(null,`never`,typeof e),!1}};new sr,R(sr);var cr=class e extends L{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):nn(this.shape,(n,r)=>{let i=this._isPartial&&!rn(e,r)||n.check(e[r],t);return!i&&t?.extend(r.toString(),n.toString(),typeof e[r],`Object property does not match`),i})}},lr=e=>new cr(e),ur=R(cr),dr=z(e=>e!=null&&(e.constructor===Object||e.constructor==null)),fr=class extends L{constructor(e,t){super(),this.shape={keys:e,values:t}}check(e,t){return e!=null&&nn(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)})}},pr=(e,t)=>new fr(e,t),mr=R(fr),hr=class extends L{constructor(e){super(),this.shape=e}check(e,t){return e!=null&&nn(this.shape,(n,r)=>{let i=n.check(e[r],t);return!i&&t?.extend(r.toString(),`Tuple`,typeof n),i})}},gr=(...e)=>new hr(e);R(hr);var _r=class extends L{constructor(e){super(),this.shape=e.length===1?e[0]:new Er(e)}check(e,t){let n=Te(e)&&Se(e,e=>this.shape.check(e));return!n&&t?.extend(null,`Array`,``),n}},vr=(...e)=>new _r(e),yr=R(_r),br=z(e=>Te(e)),xr=class extends L{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}},Sr=(e,t=null)=>new xr(e,t);R(xr);var Cr=Sr(L),wr=R(class extends L{constructor(e){super(),this.len=e.length-1,this.args=gr(...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}}),Tr=z(e=>typeof e==`function`);R(class extends L{constructor(e){super(),this.shape=e}check(e,t){let n=Se(this.shape,n=>n.check(e,t));return!n&&t?.extend(null,`Intersectinon`,typeof e),n}},e=>e.shape.length>0);var Er=class extends L{static _dilutes=!0;constructor(e){super(),this.shape=e}check(e,t){let n=Ce(this.shape,n=>n.check(e,t));return t?.extend(null,`Union`,typeof e),n}},Dr=(...e)=>e.findIndex(e=>Or.check(e))>=0?Dr(...e.map(e=>Gr(e)).map(e=>Or.check(e)?e.shape:[e]).flat(1)):e.length===1?e[0]:new Er(e),Or=R(Er),kr=()=>!0,Ar=z(kr),jr=R(Qn,e=>e.shape===kr),Mr=z(e=>typeof e==`bigint`),Nr=z(e=>e===Mr),Pr=z(e=>typeof e==`symbol`);z(e=>e===Pr);var Fr=z(e=>typeof e==`number`),Ir=z(e=>e===Fr),Lr=z(e=>typeof e==`string`),Rr=z(e=>e===Lr),zr=z(e=>typeof e==`boolean`),Br=z(e=>e===zr),Vr=er(void 0);R($n,e=>e.shape.length===1&&e.shape[0]===void 0),er(void 0);var Hr=er(null),Ur=R($n,e=>e.shape.length===1&&e.shape[0]===null);R(Uint8Array),R(Zn,e=>e.shape===Uint8Array);var Wr=Dr(Fr,Lr,Hr,Vr,Mr,zr,Pr);(()=>{let e=vr(Ar),t=pr(Lr,Ar),n=Dr(Fr,Lr,Hr,zr,e,t);return e.shape=n,t.shape.values=n,n})();var Gr=e=>{if(Cr.check(e))return e;if(dr.check(e)){let t={};for(let n in e)t[n]=Gr(e[n]);return lr(t)}if(br.check(e))return Dr(...e.map(Gr));if(Wr.check(e))return er(e);if(Tr.check(e))return R(e);y()},Kr=kn?()=>{}:(e,t)=>{let n=new Yn;if(!t.check(e,n))throw _(`Expected value to be of type ${t.constructor.name}.\n${n.toString()}`)},qr=class{constructor(e){this.patterns=[],this.$state=e}if(e,t){return this.patterns.push({if:Gr(e),h:t}),this}else(e){return this.if(Ar,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 _(`Unhandled pattern`)}}},Jr=(e=>new qr(e))(Ar).if(Ir,(e,t)=>Hn(t,_e,ge)).if(Rr,(e,t)=>Kn(t)).if(Br,(e,t)=>Vn(t)).if(Nr,(e,t)=>BigInt(Hn(t,_e,ge))).if(Or,(e,t)=>Yr(t,qn(t,e.shape))).if(ur,(e,t)=>{let n={};for(let r in e.shape){let i=e.shape[r];if(or.check(i)){if(Vn(t))continue;i=i.shape}n[r]=Jr(i,t)}return n}).if(yr,(e,t)=>{let n=[],r=Un(t,0,42);for(let i=0;i<r;i++)n.push(Yr(t,e.shape));return n}).if(tr,(e,t)=>qn(t,e.shape)).if(Ur,(e,t)=>null).if(wr,(e,t)=>{let n=Yr(t,e.res);return()=>n}).if(jr,(e,t)=>Yr(t,qn(t,[Fr,Lr,Hr,Vr,Mr,zr,vr(Fr),pr(Dr(`a`,`b`,`c`),Fr)]))).if(mr,(e,t)=>{let n={},r=Hn(t,0,3);for(let i=0;i<r;i++){let r=Yr(t,e.shape.keys);n[r]=Yr(t,e.shape.values)}return n}).done(),Yr=(e,t)=>Jr(Gr(t),e),Xr=typeof document<`u`?document:{};z(e=>e.nodeType===ti),typeof DOMParser<`u`&&new DOMParser,z(e=>e.nodeType===Qr),z(e=>e.nodeType===$r);var Zr=e=>Ut(e,(e,t)=>`${t}:${e};`).join(``),Qr=Xr.ELEMENT_NODE,$r=Xr.TEXT_NODE;Xr.CDATA_SECTION_NODE,Xr.COMMENT_NODE;var ei=Xr.DOCUMENT_NODE;Xr.DOCUMENT_TYPE_NODE;var ti=Xr.DOCUMENT_FRAGMENT_NODE;z(e=>e.nodeType===ei);var B=Symbol,ni=B(),ri=B(),ii=B(),ai=B(),oi=B(),si=B(),ci=B(),li=B(),ui=B(),di=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};A();var fi={[ni]:I(`font-weight`,`bold`),[ri]:I(`font-weight`,`normal`),[ii]:I(`color`,`blue`),[oi]:I(`color`,`green`),[ai]:I(`color`,`grey`),[si]:I(`color`,`red`),[ci]:I(`color`,`purple`),[li]:I(`color`,`orange`),[ui]:I(`color`,`black`)},pi=An?e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=M(),i=[],a=0;for(;a<e.length;a++){let i=e[a],o=fi[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=Zr(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}:di,mi=(...e)=>{console.log(...pi(e)),gi.forEach(t=>t.print(e))},hi=(...e)=>{console.warn(...pi(e)),e.unshift(li),gi.forEach(t=>t.print(e))},gi=ye(),_i=e=>({[Symbol.iterator](){return this},next:e}),vi=(e,t)=>_i(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),yi=(e,t)=>_i(()=>{let{done:n,value:r}=e.next();return{done:n,value:n?void 0:t(r)}}),bi=class{constructor(e,t){this.clock=e,this.len=t}},xi=class{constructor(){this.clients=new Map}},Si=(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])wa(e,i,o.clock,o.len,n)}}),Ci=(e,t)=>{let n=0,r=e.length-1;for(;n<=r;){let i=h((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},wi=(e,t)=>{let n=e.clients.get(t.client);return n!==void 0&&Ci(n,t.clock)!==null},Ti=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 bi(r.clock,pe(r.len,i.clock+i.len-r.clock)):(n<t&&(e[n]=i),n++)}e.length=n})},Ei=e=>{let t=new xi;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++)xe(a,e[t].clients.get(i)||[]);t.clients.set(i,a)}});return Ti(t),t},Di=(e,t,n,r)=>{N(e.clients,t,()=>[]).push(new bi(n,r))},Oi=()=>new xi,ki=e=>{let t=Oi();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 bi(i,a))}}r.length>0&&t.clients.set(n,r)}),t},Ai=(e,t)=>{C(e.restEncoder,t.clients.size),g(t.clients.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{e.resetDsCurVal(),C(e.restEncoder,t);let r=n.length;C(e.restEncoder,r);for(let t=0;t<r;t++){let r=n[t];e.writeDsClock(r.clock),e.writeDsLen(r.len)}})},ji=e=>{let t=new xi,n=O(e.restDecoder);for(let r=0;r<n;r++){e.resetDsCurVal();let n=O(e.restDecoder),r=O(e.restDecoder);if(r>0){let i=N(t.clients,n,()=>[]);for(let t=0;t<r;t++)i.push(new bi(e.readDsClock(),e.readDsLen()))}}return t},Mi=(e,t,n)=>{let r=new xi,i=O(e.restDecoder);for(let a=0;a<i;a++){e.resetDsCurVal();let i=O(e.restDecoder),a=O(e.restDecoder),o=n.clients.get(i)||[],s=H(n,i);for(let n=0;n<a;n++){let n=e.readDsClock(),a=n+e.readDsLen();if(n<s){s<a&&Di(r,i,s,a-s);let e=U(o,n),c=o[e];for(!c.deleted&&c.id.clock<n&&(o.splice(e+1,0,Os(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,Os(t,c,a-c.id.clock)),c.delete(t))}else Di(r,i,n,a-n)}}if(r.clients.size>0){let e=new Hi;return C(e.restEncoder,0),Ai(e,r),e.toUint8Array()}return null},Ni=pn,Pi=class e extends Gt{constructor({guid:e=hn(),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=Ni(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new _a,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=gn(e=>{this.on(`load`,()=>{this.isLoaded=!0,e(this)})});let s=()=>gn(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&&G(e.parent.doc,e=>{e.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(g(this.subdocs).map(e=>e.guid))}transact(e,t=null){return G(this,e,t)}get(e,t=J){let n=N(this.share,e,()=>{let e=new t;return e._integrate(this,null),e}),r=n.constructor;if(t!==J&&r!==t){if(r===J){let r=new t;r._map=n._map,n._map.forEach(e=>{for(;e!==null;e=e.left)e.parent=r}),r._start=n._start;for(let e=r._start;e!==null;e=e.right)e.parent=r;return r._length=n._length,this.share.set(e,r),r._integrate(this,null),r}throw Error(`Type with the name ${e} has already been defined with a different constructor`)}return n}getArray(e=``){return this.get(e,xo)}getText(e=``){return this.get(e,Vo)}getMap(e=``){return this.get(e,wo)}getXmlElement(e=``){return this.get(e,Ko)}getXmlFragment(e=``){return this.get(e,Wo)}toJSON(){let e={};return this.share.forEach((t,n)=>{e[n]=t.toJSON()}),e}destroy(){this.isDestroyed=!0,g(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,G(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()}},Fi=class{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return O(this.restDecoder)}readDsLen(){return O(this.restDecoder)}},Ii=class extends Fi{readLeftID(){return V(O(this.restDecoder),O(this.restDecoder))}readRightID(){return V(O(this.restDecoder),O(this.restDecoder))}readClient(){return O(this.restDecoder)}readInfo(){return dt(this.restDecoder)}readString(){return k(this.restDecoder)}readParentInfo(){return O(this.restDecoder)===1}readTypeRef(){return O(this.restDecoder)}readLen(){return O(this.restDecoder)}readAny(){return ht(this.restDecoder)}readBuf(){return zn(D(this.restDecoder))}readJSON(){return JSON.parse(k(this.restDecoder))}readKey(){return k(this.restDecoder)}},Li=class{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=O(this.restDecoder),this.dsCurrVal}readDsLen(){let e=O(this.restDecoder)+1;return this.dsCurrVal+=e,e}},Ri=class extends Li{constructor(e){super(e),this.keys=[],O(e),this.keyClockDecoder=new vt(D(e)),this.clientDecoder=new _t(D(e)),this.leftClockDecoder=new vt(D(e)),this.rightClockDecoder=new vt(D(e)),this.infoDecoder=new gt(D(e),dt),this.stringDecoder=new yt(D(e)),this.parentInfoDecoder=new gt(D(e),dt),this.typeRefDecoder=new _t(D(e)),this.lenDecoder=new _t(D(e))}readLeftID(){return new da(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new da(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 ht(this.restDecoder)}readBuf(){return D(this.restDecoder)}readJSON(){return ht(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}}},zi=class{constructor(){this.restEncoder=b()}toUint8Array(){return x(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){C(this.restEncoder,e)}writeDsLen(e){C(this.restEncoder,e)}},Bi=class extends zi{writeLeftID(e){C(this.restEncoder,e.client),C(this.restEncoder,e.clock)}writeRightID(e){C(this.restEncoder,e.client),C(this.restEncoder,e.clock)}writeClient(e){C(this.restEncoder,e)}writeInfo(e){Be(this.restEncoder,e)}writeString(e){w(this.restEncoder,e)}writeParentInfo(e){C(this.restEncoder,+!!e)}writeTypeRef(e){C(this.restEncoder,e)}writeLen(e){C(this.restEncoder,e)}writeAny(e){Ze(this.restEncoder,e)}writeBuf(e){T(this.restEncoder,e)}writeJSON(e){w(this.restEncoder,JSON.stringify(e))}writeKey(e){w(this.restEncoder,e)}},Vi=class{constructor(){this.restEncoder=b(),this.dsCurrVal=0}toUint8Array(){return x(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){let t=e-this.dsCurrVal;this.dsCurrVal=e,C(this.restEncoder,t)}writeDsLen(e){e===0&&y(),C(this.restEncoder,e-1),this.dsCurrVal+=e}},Hi=class extends Vi{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new nt,this.clientEncoder=new et,this.leftClockEncoder=new nt,this.rightClockEncoder=new nt,this.infoEncoder=new Qe(Be),this.stringEncoder=new rt,this.parentInfoEncoder=new Qe(Be),this.typeRefEncoder=new et,this.lenEncoder=new et}toUint8Array(){let e=b();return C(e,0),T(e,this.keyClockEncoder.toUint8Array()),T(e,this.clientEncoder.toUint8Array()),T(e,this.leftClockEncoder.toUint8Array()),T(e,this.rightClockEncoder.toUint8Array()),T(e,x(this.infoEncoder)),T(e,this.stringEncoder.toUint8Array()),T(e,x(this.parentInfoEncoder)),T(e,this.typeRefEncoder.toUint8Array()),T(e,this.lenEncoder.toUint8Array()),We(e,x(this.restEncoder)),x(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){Ze(this.restEncoder,e)}writeBuf(e){T(this.restEncoder,e)}writeJSON(e){Ze(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)}},Ui=(e,t,n,r)=>{r=pe(r,t[0].id.clock);let i=U(t,r);C(e.restEncoder,t.length-i),e.writeClient(n),C(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)},Wi=(e,t,n)=>{let r=new Map;n.forEach((e,n)=>{H(t,n)>e&&r.set(n,e)}),va(t).forEach((e,t)=>{n.has(t)||r.set(t,0)}),C(e.restEncoder,r.size),g(r.entries()).sort((e,t)=>t[0]-e[0]).forEach(([n,r])=>{Ui(e,t.clients.get(n),n,r)})},Gi=(e,t)=>{let n=M(),r=O(e.restDecoder);for(let i=0;i<r;i++){let r=O(e.restDecoder),i=Array(r),a=e.readClient(),o=O(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(V(a,o),t),o+=t;break}case 10:{let t=O(e.restDecoder);i[n]=new $(V(a,o),t),o+=t;break}default:{let s=!(r&192),c=new Q(V(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,ks(e,r));i[n]=c,o+=c.length}}}}return n},Ki=(e,t,n)=>{let r=[],i=g(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 _a,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=N(d,u.id.client,()=>H(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,H(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 Hi;return Wi(e,s,new Map),C(e.restEncoder,0),{missing:c,update:e.toUint8Array()}}return null},qi=(e,t)=>Wi(e,t.doc.store,t.beforeState),Ji=(e,t,n,r=new Ri(e))=>G(t,e=>{e.local=!1;let t=!1,n=e.doc,i=n.store,a=Ki(e,i,Gi(r,n)),o=i.pendingStructs;if(o){for(let[e,n]of o.missing)if(n<H(i,e)){t=!0;break}if(a){for(let[e,t]of a.missing){let n=o.missing.get(e);(n==null||n>t)&&o.missing.set(e,t)}o.update=La([o.update,a.update])}}else i.pendingStructs=a;let s=Mi(r,e,i);if(i.pendingDs){let t=new Ri(E(i.pendingDs));O(t.restDecoder);let n=Mi(t,e,i);i.pendingDs=s&&n?La([s,n]):s||n}else i.pendingDs=s;if(t){let t=i.pendingStructs.update;i.pendingStructs=null,Yi(e.doc,t)}},n,!1),Yi=(e,t,n,r=Ri)=>{let i=E(t);Ji(i,e,n,new r(i))},Xi=(e,t,n)=>Yi(e,t,n,Ii),Zi=(e,t,n=new Map)=>{Wi(e,t.store,n),Ai(e,ki(t.store))},Qi=(e,t=new Uint8Array([0]),n=new Hi)=>{Zi(n,e,ta(t));let r=[n.toUint8Array()];if(e.store.pendingDs&&r.push(e.store.pendingDs),e.store.pendingStructs&&r.push(Ra(e.store.pendingStructs.update,t)),r.length>1){if(n.constructor===Bi)return Fa(r.map((e,t)=>t===0?e:Ha(e)));if(n.constructor===Hi)return La(r)}return r[0]},$i=(e,t)=>Qi(e,t,new Bi),ea=e=>{let t=new Map,n=O(e.restDecoder);for(let r=0;r<n;r++){let n=O(e.restDecoder),r=O(e.restDecoder);t.set(n,r)}return t},ta=e=>ea(new Fi(E(e))),na=(e,t)=>(C(e.restEncoder,t.size),g(t.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{C(e.restEncoder,t),C(e.restEncoder,n)}),e),ra=(e,t)=>na(e,va(t.store)),ia=(e,t=new Vi)=>(e instanceof Map?na(t,e):ra(t,e),t.toUint8Array()),aa=e=>ia(e,new zi),oa=class{constructor(){this.l=[]}},sa=()=>new oa,ca=(e,t)=>e.l.push(t),la=(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.`)},ua=(e,t,n)=>cn(e.l,[t,n]),da=class{constructor(e,t){this.client=e,this.clock=t}},fa=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,V=(e,t)=>new da(e,t),pa=e=>{for(let[t,n]of e.doc.share.entries())if(n===e)return t;throw y()},ma=class{constructor(e,t){this.ds=e,this.sv=t}};((e,t)=>new ma(e,t))(Oi(),new Map);var ha=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!wi(t.ds,e.id),ga=(e,t)=>{let n=N(e.meta,ga,ye),r=e.doc.store;n.has(t)||(t.sv.forEach((t,n)=>{t<H(r,n)&&W(e,V(n,t))}),Si(e,t.ds,e=>{}),n.add(t))},_a=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},va=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},H=(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},ya=(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 y()}n.push(t)},U=(e,t)=>{let n=0,r=e.length-1,i=e[r],a=i.id.clock;if(a===t)return r;let o=h(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=h((n+r)/2)}throw y()},ba=(e,t)=>{let n=e.clients.get(t.client);return n[U(n,t.clock)]},xa=(e,t,n)=>{let r=U(t,n),i=t[r];return i.id.clock<n&&i instanceof Q?(t.splice(r+1,0,Os(e,i,n-i.id.clock)),r+1):r},W=(e,t)=>{let n=e.doc.store.clients.get(t.client);return n[xa(e,n,t.clock)]},Sa=(e,t,n)=>{let r=t.clients.get(n.client),i=U(r,n.clock),a=r[i];return n.clock!==a.id.clock+a.length-1&&a.constructor!==X&&r.splice(i+1,0,Os(e,a,n.clock-a.id.clock+1)),a},Ca=(e,t,n)=>{let r=e.clients.get(t.id.client);r[U(r,t.id.clock)]=n},wa=(e,t,n,r,i)=>{if(r===0)return;let a=n+r,o=xa(e,t,n),s;do s=t[o++],a<s.id.clock+s.length&&xa(e,t,a),i(s);while(o<t.length&&t[o].id.clock<a)},Ta=class{constructor(e,t,n){this.doc=e,this.deleteSet=new xi,this.beforeState=va(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}},Ea=(e,t)=>t.deleteSet.clients.size===0&&!Wt(t.afterState,(e,n)=>t.beforeState.get(n)!==e)?!1:(Ti(t.deleteSet),qi(e,t),Ai(e,t.deleteSet),!0),Da=(e,t,n)=>{let r=t._item;(r===null||r.id.clock<(e.beforeState.get(r.id.client)||0)&&!r.deleted)&&N(e.changed,t,ye).add(n)},Oa=(e,t)=>{let n=e[t],r=e[t-1],i=t;for(;i>0;n=r,r=e[--i-1]){if(r.deleted===n.deleted&&r.constructor===n.constructor&&r.mergeWith(n)){n instanceof Q&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,r);continue}break}let a=t-i;return a&&e.splice(t+1-a,a),a},ka=(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=U(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)}}}},Aa=(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=fe(r.length-1,1+U(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+Oa(r,e)}})},ja=(e,t)=>{if(t<e.length){let n=e[t],r=n.doc,i=r.store,a=n.deleteSet,o=n._mergeStructs;try{Ti(a),n.afterState=va(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),ua(r._dEH,t,n)})}),e.push(()=>r.emit(`afterTransaction`,[n,r])),e.push(()=>{n._needFormattingCleanup&&Ro(n)})}),cn(e,[])}finally{r.gc&&ka(a,i,r.gcFilter),Aa(a,i),n.afterState.forEach((e,t)=>{let r=n.beforeState.get(t)||0;if(r!==e){let e=i.clients.get(t),n=pe(U(e,r),1);for(let t=e.length-1;t>=n;)t-=1+Oa(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=U(r,n);a+1<r.length&&Oa(r,a+1)>1||a>0&&Oa(r,a)}if(!n.local&&n.afterState.get(r.clientID)!==n.beforeState.get(r.clientID)&&(mi(li,ni,`[yjs] `,ri,si,`Changed the client-id because another client seems to be using it.`),r.clientID=Ni()),r.emit(`afterTransactionCleanup`,[n,r]),r._observers.has(`update`)){let e=new Bi;Ea(e,n)&&r.emit(`update`,[e.toUint8Array(),n.origin,r,n])}if(r._observers.has(`updateV2`)){let e=new Hi;Ea(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])):ja(e,t+1)}}},G=(e,t,n=null,r=!0)=>{let i=e._transactionCleanups,a=!1,o=null;e._transaction===null&&(a=!0,e._transaction=new Ta(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&&ja(i,0)}}return o};function*Ma(e){let t=O(e.restDecoder);for(let n=0;n<t;n++){let t=O(e.restDecoder),n=e.readClient(),r=O(e.restDecoder);for(let i=0;i<t;i++){let t=e.readInfo();if(t===10){let t=O(e.restDecoder);yield new $(V(n,r),t),r+=t}else if(31&t){let i=!(t&192),a=new Q(V(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,ks(e,t));yield a,r+=a.length}else{let t=e.readLen();yield new X(V(n,r),t),r+=t}}}}var Na=class{constructor(e,t){this.gen=Ma(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}},Pa=class{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}},Fa=e=>La(e,Ii,Bi),Ia=(e,t)=>{if(e.constructor===X){let{client:n,clock:r}=e.id;return new X(V(n,r+t),e.length-t)}if(e.constructor===$){let{client:n,clock:r}=e.id;return new $(V(n,r+t),e.length-t)}{let n=e,{client:r,clock:i}=n.id;return new Q(V(r,i+t),null,V(r,i+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},La=(e,t=Ri,n=Hi)=>{if(e.length===1)return e[0];let r=e.map(e=>new t(E(e))),i=r.map(e=>new Na(e,!0)),a=null,o=new n,s=new Pa(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)K(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{K(s,a.struct,a.offset);let e=n.id.clock-a.struct.id.clock-a.struct.length;a={struct:new $(V(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=Ia(n,t)),a.struct.mergeWith(n)||(K(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())K(s,a.struct,a.offset),a={struct:n,offset:0}}return a!==null&&(K(s,a.struct,a.offset),a=null),Ba(s),Ai(o,Ei(r.map(e=>ji(e)))),o.toUint8Array()},Ra=(e,t,n=Ri,r=Hi)=>{let i=ta(t),a=new r,o=new Pa(a),s=new n(E(e)),c=new Na(s,!1);for(;c.curr;){let e=c.curr,t=e.id.client,n=i.get(t)||0;if(c.curr.constructor===$){c.next();continue}if(e.id.clock+e.length>n)for(K(o,e,pe(n-e.id.clock,0)),c.next();c.curr&&c.curr.id.client===t;)K(o,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===t&&c.curr.id.clock+c.curr.length<=n;)c.next()}return Ba(o),Ai(a,ji(s)),a.toUint8Array()},za=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:x(e.encoder.restEncoder)}),e.encoder.restEncoder=b(),e.written=0)},K=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&za(e),e.written===0&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),C(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},Ba=e=>{za(e);let t=e.encoder.restEncoder;C(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){let r=e.clientStructs[n];C(t,r.written),We(t,r.restEncoder)}},Va=(e,t,n,r)=>{let i=new n(E(e)),a=new Na(i,!1),o=new r,s=new Pa(o);for(let e=a.curr;e!==null;e=a.next())K(s,t(e),0);return Ba(s),Ai(o,ji(i)),o.toUint8Array()},Ha=e=>Va(e,ln,Ri,Bi),Ua=`You must not compute changes after the event-handler fired.`,Wa=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||=Ga(this.currentTarget,this.target)}deletes(e){return wi(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw _(Ua);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=be(e.content.getContent());else return}else e!==null&&this.deletes(e)?(i=`update`,a=be(e.content.getContent())):(i=`add`,a=void 0)}else if(this.deletes(r))i=`delete`,a=be(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 _(Ua);let t=this.target,n=ye(),r=ye(),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}},Ga=(e,t)=>{let n=[];for(;t._item!==null&&t!==e;){if(t._item.parentSub!==null)n.unshift(t._item.parentSub);else{let e=0,r=t._item.parent._start;for(;r!==t._item&&r!==null;)!r.deleted&&r.countable&&(e+=r.length),r=r.right;n.unshift(e)}t=t._item.parent}return n},q=()=>{hi(`Invalid access: Add Yjs type to a document before reading data.`)},Ka=80,qa=0,Ja=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=qa++}},Ya=e=>{e.timestamp=qa++},Xa=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=qa++},Za=(e,t,n)=>{if(e.length>=Ka){let r=e.reduce((e,t)=>e.timestamp<t.timestamp?e:t);return Xa(r,t,n),r}{let r=new Ja(t,n);return e.push(r),r}},Qa=(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)=>de(t-e.index)<de(t-n.index)?e:n),r=e._start,i=0;for(n!==null&&(r=n.p,i=n.index,Ya(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&&de(n.index-i)<r.parent.length/Ka?(Xa(n,r,i),n):Za(e._searchMarker,r,i)},$a=(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=pe(t,i.index+n))}},eo=(e,t,n)=>{let r=e,i=t.changedParentTypes;for(;N(i,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;ua(r._eH,n,t)},J=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=sa(),this._dEH=sa(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw v()}clone(){throw v()}_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){ca(this._eH,e)}observeDeep(e){ca(this._dEH,e)}unobserve(e){la(this._eH,e)}unobserveDeep(e){la(this._dEH,e)}toJSON(){}},to=(e,t,n)=>{e.doc??q(),t<0&&(t=e._length+t),n<0&&(n=e._length+n);let r=n-t,i=[],a=e._start;for(;a!==null&&r>0;){if(a.countable&&!a.deleted){let e=a.content.getContent();if(e.length<=t)t-=e.length;else{for(let n=t;n<e.length&&r>0;n++)i.push(e[n]),r--;t=0}}a=a.right}return i},no=e=>{e.doc??q();let t=[],n=e._start;for(;n!==null;){if(n.countable&&!n.deleted){let e=n.content.getContent();for(let n=0;n<e.length;n++)t.push(e[n])}n=n.right}return t},ro=(e,t)=>{let n=0,r=e._start;for(e.doc??q();r!==null;){if(r.countable&&!r.deleted){let i=r.content.getContent();for(let r=0;r<i.length;r++)t(i[r],n++,e)}r=r.right}},io=(e,t)=>{let n=[];return ro(e,(r,i)=>{n.push(t(r,i,e))}),n},ao=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}}}},oo=(e,t)=>{e.doc??q();let n=Qa(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}},so=(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(V(o,H(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new ms(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(V(o,H(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new ts(new Uint8Array(n))),i.integrate(e,0);break;case Pi:i=new Q(V(o,H(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new os(n)),i.integrate(e,0);break;default:if(n instanceof J)i=new Q(V(o,H(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new Es(n)),i.integrate(e,0);else throw Error(`Unexpected content type in insert operation`)}}}),u()},co=()=>_(`Length exceeded!`),lo=(e,t,n,r)=>{if(n>t._length)throw co();if(n===0)return t._searchMarker&&$a(t._searchMarker,n,r.length),so(e,t,null,r);let i=n,a=Qa(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&&W(e,V(o.id.client,o.id.clock+n));break}n-=o.length}return t._searchMarker&&$a(t._searchMarker,i,r.length),so(e,t,o,r)},uo=(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 so(e,t,r,n)},fo=(e,t,n,r)=>{if(r===0)return;let i=n,a=r,o=Qa(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&&W(e,V(s.id.client,s.id.clock+n)),n-=s.length);for(;r>0&&s!==null;)s.deleted||(r<s.length&&W(e,V(s.id.client,s.id.clock+r)),s.delete(e),r-=s.length),s=s.right;if(r>0)throw co();t._searchMarker&&$a(t._searchMarker,i,-a+r)},po=(e,t,n)=>{let r=t._map.get(n);r!==void 0&&r.delete(e)},mo=(e,t,n,r)=>{let i=t._map.get(n)||null,a=e.doc,o=a.clientID,s;if(r==null)s=new ms([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:s=new ms([r]);break;case Uint8Array:s=new ts(r);break;case Pi:s=new os(r);break;default:if(r instanceof J)s=new Es(r);else throw Error(`Unexpected content type`)}new Q(V(o,H(a.store,o)),i,i&&i.lastId,null,null,t,n,s).integrate(e,0)},ho=(e,t)=>{e.doc??q();let n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},go=e=>{let t={};return e.doc??q(),e._map.forEach((e,n)=>{e.deleted||(t[n]=e.content.getContent()[e.length-1])}),t},_o=(e,t)=>{e.doc??q();let n=e._map.get(t);return n!==void 0&&!n.deleted},vo=(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&&ha(i,t)&&(n[r]=i.content.getContent()[i.length-1])}),n},yo=e=>(e.doc??q(),vi(e._map.entries(),e=>!e[1].deleted)),bo=class extends Wa{},xo=class e extends J{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){let n=new e;return n.push(t),n}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(e=>e instanceof J?e.clone():e)),t}get length(){return this.doc??q(),this._length}_callObserver(e,t){super._callObserver(e,t),eo(this,e,new bo(this,e))}insert(e,t){this.doc===null?this._prelimContent.splice(e,0,...t):G(this.doc,n=>{lo(n,this,e,t)})}push(e){this.doc===null?this._prelimContent.push(...e):G(this.doc,t=>{uo(t,this,e)})}unshift(e){this.insert(0,e)}delete(e,t=1){this.doc===null?this._prelimContent.splice(e,t):G(this.doc,n=>{fo(n,this,e,t)})}get(e){return oo(this,e)}toArray(){return no(this)}slice(e=0,t=this.length){return to(this,e,t)}toJSON(){return this.map(e=>e instanceof J?e.toJSON():e)}map(e){return io(this,e)}forEach(e){ro(this,e)}[Symbol.iterator](){return ao(this)}_write(e){e.writeTypeRef(ys)}},So=e=>new xo,Co=class extends Wa{constructor(e,t,n){super(e,t),this.keysChanged=n}},wo=class e extends J{constructor(e){super(),this._prelimContent=null,this._prelimContent=e===void 0?new Map:new Map(e)}_integrate(e,t){super._integrate(e,t),this._prelimContent.forEach((e,t)=>{this.set(t,e)}),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return this.forEach((e,n)=>{t.set(n,e instanceof J?e.clone():e)}),t}_callObserver(e,t){eo(this,e,new Co(this,e,t))}toJSON(){this.doc??q();let e={};return this._map.forEach((t,n)=>{if(!t.deleted){let r=t.content.getContent()[t.length-1];e[n]=r instanceof J?r.toJSON():r}}),e}get size(){return[...yo(this)].length}keys(){return yi(yo(this),e=>e[0])}values(){return yi(yo(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return yi(yo(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??q(),this._map.forEach((t,n)=>{t.deleted||e(t.content.getContent()[t.length-1],n,this)})}[Symbol.iterator](){return this.entries()}delete(e){this.doc===null?this._prelimContent.delete(e):G(this.doc,t=>{po(t,this,e)})}set(e,t){return this.doc===null?this._prelimContent.set(e,t):G(this.doc,n=>{mo(n,this,e,t)}),t}get(e){return ho(this,e)}has(e){return _o(this,e)}clear(){this.doc===null?this._prelimContent.clear():G(this.doc,e=>{this.forEach(function(t,n,r){po(e,r,n)})})}_write(e){e.writeTypeRef(bs)}},To=e=>new wo,Y=(e,t)=>e===t||typeof e==`object`&&typeof t==`object`&&e&&t&&an(e,t),Eo=class{constructor(e,t,n,r){this.left=e,this.right=t,this.index=n,this.currentAttributes=r}forward(){switch(this.right===null&&y(),this.right.content.constructor){case Z:this.right.deleted||Ao(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length)}this.left=this.right,this.right=this.right.right}},Do=(e,t,n)=>{for(;t.right!==null&&n>0;){switch(t.right.content.constructor){case Z:t.right.deleted||Ao(t.currentAttributes,t.right.content);break;default:t.right.deleted||(n<t.right.length&&W(e,V(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},Oo=(e,t,n,r)=>{let i=new Map,a=r?Qa(t,n):null;return a?Do(e,new Eo(a.p.left,a.p,a.index,i),n-a.index):Do(e,new Eo(null,t._start,0,i),n)},ko=(e,t,n,r)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===Z&&Y(r.get(n.right.content.key),n.right.content.value));)n.right.deleted||r.delete(n.right.content.key),n.forward();let i=e.doc,a=i.clientID;r.forEach((r,o)=>{let s=n.left,c=n.right,l=new Q(V(a,H(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()})},Ao=(e,t)=>{let{key:n,value:r}=t;r===null?e.delete(n):e.set(n,r)},jo=(e,t)=>{for(;e.right!==null&&(e.right.deleted||e.right.content.constructor===Z&&Y(t[e.right.content.key]??null,e.right.content.value));)e.forward()},Mo=(e,t,n,r)=>{let i=e.doc,a=i.clientID,o=new Map;for(let s in r){let c=r[s],l=n.currentAttributes.get(s)??null;if(!Y(l,c)){o.set(s,l);let{left:r,right:u}=n;n.right=new Q(V(a,H(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},No=(e,t,n,r,i)=>{n.currentAttributes.forEach((e,t)=>{i[t]===void 0&&(i[t]=null)});let a=e.doc,o=a.clientID;jo(n,i);let s=Mo(e,t,n,i),c=r.constructor===String?new gs(r):r instanceof J?new Es(r):new cs(r),{left:l,right:u,index:d}=n;t._searchMarker&&$a(t._searchMarker,n.index,c.getLength()),u=new Q(V(o,H(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(),ko(e,t,n,s)},Po=(e,t,n,r,i)=>{let a=e.doc,o=a.clientID;jo(n,i);let s=Mo(e,t,n,i);iterationLoop:for(;n.right!==null&&(r>0||s.size>0&&(n.right.deleted||n.right.content.constructor===Z));){if(!n.right.deleted)switch(n.right.content.constructor){case Z:{let{key:t,value:a}=n.right.content,o=i[t];if(o!==void 0){if(Y(o,a))s.delete(t);else{if(r===0)break iterationLoop;s.set(t,a)}n.right.delete(e)}else n.currentAttributes.set(t,a);break}default:r<n.right.length&&W(e,V(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(V(o,H(a.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new gs(i)),n.right.integrate(e,0),n.forward()}ko(e,t,n,s)},Fo=(e,t,n,r,i)=>{let a=t,o=M();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&&Ao(i,n);break}}}t=t.right}return s},Io=(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}},Lo=e=>{let t=0;return G(e.doc,n=>{let r=e._start,i=e._start,a=M(),o=Ht(a);for(;i;){if(i.deleted===!1)switch(i.content.constructor){case Z:Ao(o,i.content);break;default:t+=Fo(n,r,i,a,o),a=Ht(o),r=i}i=i.right}}),t},Ro=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&&wa(e,n.store.clients.get(r),a,i,e=>{!e.deleted&&e.content.constructor===Z&&e.constructor!==X&&t.add(e.parent)})}G(n,n=>{Si(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):Io(n,e)});for(let e of t)Lo(e)})},zo=(e,t,n)=>{let r=n,i=Ht(t.currentAttributes),a=t.right;for(;n>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case Es:case cs:case gs:n<t.right.length&&W(e,V(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e)}t.forward()}a&&Fo(e,a,t.right,i,t.currentAttributes);let o=(t.left||t.right).parent;return o._searchMarker&&$a(o._searchMarker,t.index,-r+n),t},Bo=class extends Wa{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=[];G(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},tn(o)||(e.attributes=Xt({},o))),c=0}e&&t.push(e),a=null}};for(;i!==null;){switch(i.content.constructor){case Es:case cs: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 gs:this.adds(i)?this.deletes(i)||(a!==`insert`&&(u(),a=`insert`),s+=i.content.str):this.deletes(i)?(a!==`delete`&&(u(),a=`delete`),l+=i.length):i.deleted||(a!==`retain`&&(u(),a=`retain`),c+=i.length);break;case Z:{let{key:t,value:s}=i.content;if(this.adds(i))this.deletes(i)||(Y(n.get(t)??null,s)?s!==null&&i.delete(e):(a===`retain`&&u(),Y(s,r.get(t)??null)?delete o[t]:o[t]=s));else if(this.deletes(i)){r.set(t,s);let e=n.get(t)??null;Y(e,s)||(a===`retain`&&u(),o[t]=e)}else if(!i.deleted){r.set(t,s);let n=o[t];n!==void 0&&(Y(n,s)?n!==null&&i.delete(e):(a===`retain`&&u(),s===null?delete o[t]:o[t]=s))}i.deleted||(a===`insert`&&u(),Ao(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}},Vo=class e extends J{constructor(e){super(),this._pending=e===void 0?[]:[()=>this.insert(0,e)],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??q(),this._length}_integrate(e,t){super._integrate(e,t);try{this._pending.forEach(e=>e())}catch(e){console.error(e)}this._pending=null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}_callObserver(e,t){super._callObserver(e,t);let n=new Bo(this,e,t);eo(this,e,n),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??q();let e=``,t=this._start;for(;t!==null;)!t.deleted&&t.countable&&t.content.constructor===gs&&(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)):G(this.doc,n=>{let r=new Eo(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)&&No(n,this,r,o,a.attributes||{})}else a.retain===void 0?a.delete!==void 0&&zo(n,r,a.delete):Po(n,this,r,a.retain,a.attributes||{})}})}toDelta(e,t,n){this.doc??q();let r=[],i=new Map,a=this.doc,o=``,s=this._start;function c(){if(o.length>0){let e={},t=!1;i.forEach((n,r)=>{t=!0,e[r]=n});let n={insert:o};t&&(n.attributes=e),r.push(n),o=``}}let l=()=>{for(;s!==null;){if(ha(s,e)||t!==void 0&&ha(s,t))switch(s.content.constructor){case gs:{let r=i.get(`ychange`);e!==void 0&&!ha(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&&!ha(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 Es:case cs:{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:ha(s,e)&&(c(),Ao(i,s.content))}s=s.right}c()};return e||t?G(a,n=>{e&&ga(n,e),t&&ga(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)):G(r,r=>{let i=Oo(r,this,e,!n);n||(n={},i.currentAttributes.forEach((e,t)=>{n[t]=e})),No(r,this,i,t,n)})}insertEmbed(e,t,n){let r=this.doc;r===null?this._pending.push(()=>this.insertEmbed(e,t,n||{})):G(r,r=>{let i=Oo(r,this,e,!n);No(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)):G(n,n=>{zo(n,Oo(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)):G(r,r=>{let i=Oo(r,this,e,!1);i.right!==null&&Po(r,this,i,t,n)})}removeAttribute(e){this.doc===null?this._pending.push(()=>this.removeAttribute(e)):G(this.doc,t=>{po(t,this,e)})}setAttribute(e,t){this.doc===null?this._pending.push(()=>this.setAttribute(e,t)):G(this.doc,n=>{mo(n,this,e,t)})}getAttribute(e){return ho(this,e)}getAttributes(){return go(this)}_write(e){e.writeTypeRef(xs)}},Ho=e=>new Vo,Uo=class{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??q()}[Symbol.iterator](){return this}next(){let e=this._currentNode,t=e&&e.content&&e.content.type;if(e!==null&&(!this._firstCall||e.deleted||!this._filter(t)))do if(t=e.content.type,!e.deleted&&(t.constructor===Ko||t.constructor===Wo)&&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})}},Wo=class e extends J{constructor(){super(),this._prelimContent=[]}get firstChild(){let e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(e=>e instanceof J?e.clone():e)),t}get length(){return this.doc??q(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new Uo(this,e)}querySelector(e){e=e.toUpperCase();let t=new Uo(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e).next();return t.done?null:t.value}querySelectorAll(e){return e=e.toUpperCase(),g(new Uo(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){eo(this,e,new Jo(this,t,e))}toString(){return io(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),ro(this,i=>{r.insertBefore(i.toDOM(e,t,n),null)}),r}insert(e,t){this.doc===null?this._prelimContent.splice(e,0,...t):G(this.doc,n=>{lo(n,this,e,t)})}insertAfter(e,t){if(this.doc!==null)G(this.doc,n=>{let r=e&&e instanceof J?e._item:e;so(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 _(`Reference item not found`);n.splice(r,0,...t)}}delete(e,t=1){this.doc===null?this._prelimContent.splice(e,t):G(this.doc,n=>{fo(n,this,e,t)})}toArray(){return no(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return oo(this,e)}slice(e=0,t=this.length){return to(this,e,t)}forEach(e){ro(this,e)}_write(e){e.writeTypeRef(Cs)}},Go=e=>new Wo,Ko=class e extends Wo{constructor(e=`UNDEFINED`){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,t){super._integrate(e,t),this._prelimAttrs.forEach((e,t)=>{this.setAttribute(t,e)}),this._prelimAttrs=null}_copy(){return new e(this.nodeName)}clone(){let t=new e(this.nodeName);return Qt(this.getAttributes(),(e,n)=>{t.setAttribute(n,e)}),t.insert(0,this.toArray().map(e=>e instanceof J?e.clone():e)),t}toString(){let e=this.getAttributes(),t=[],n=[];for(let t in e)n.push(t);n.sort();let r=n.length;for(let i=0;i<r;i++){let r=n[i];t.push(r+`="`+e[r]+`"`)}let i=this.nodeName.toLocaleLowerCase();return`<${i}${t.length>0?` `+t.join(` `):``}>${super.toString()}</${i}>`}removeAttribute(e){this.doc===null?this._prelimAttrs.delete(e):G(this.doc,t=>{po(t,this,e)})}setAttribute(e,t){this.doc===null?this._prelimAttrs.set(e,t):G(this.doc,n=>{mo(n,this,e,t)})}getAttribute(e){return ho(this,e)}hasAttribute(e){return _o(this,e)}getAttributes(e){return e?vo(this,e):go(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 ro(this,i=>{r.appendChild(i.toDOM(e,t,n))}),n!==void 0&&n._createAssociation(r,this),r}_write(e){e.writeTypeRef(Ss),e.writeKey(this.nodeName)}},qo=e=>new Ko(e.readKey()),Jo=class extends Wa{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)})}},Yo=class e extends wo{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(ws),e.writeKey(this.hookName)}},Xo=e=>new Yo(e.readKey()),Zo=class e extends Vo{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(Ts)}},Qo=e=>new Zo,$o=class{constructor(e,t){this.id=e,this.length=t}get deleted(){throw v()}mergeWith(e){return!1}write(e,t,n){throw v()}integrate(e,t){throw v()}},es=0,X=class extends $o{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),ya(e.doc.store,this)}write(e,t){e.writeInfo(es),e.writeLen(this.length-t)}getMissing(e,t){return null}},ts=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 v()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}},ns=e=>new ts(e.readBuf()),rs=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){Di(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}},is=e=>new rs(e.readLen()),as=(e,t)=>new Pi({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1}),os=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(as(this.doc.guid,this.opts))}splice(e){throw v()}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}},ss=e=>new os(as(e.readString(),e.readAny())),cs=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 v()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}},ls=e=>new cs(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 v()}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}},us=e=>new Z(e.readKey(),e.readJSON()),ds=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}},fs=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 ds(n)},ps=Dn(`node_env`)===`development`,ms=class e{constructor(e){this.arr=e,ps&&sn(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}},hs=e=>{let t=e.readLen(),n=[];for(let r=0;r<t;r++)n.push(e.readAny());return new ms(n)},gs=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}},_s=e=>new gs(e.readString()),vs=[So,To,Ho,qo,Go,Xo,Qo],ys=0,bs=1,xs=2,Ss=3,Cs=4,ws=5,Ts=6,Es=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 v()}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}},Ds=e=>new Es(vs[e.readTypeRef()](e)),Os=(e,t,n)=>{let{client:r,clock:i}=t.id,a=new Q(V(r,i+n),t,V(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=V(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 $o{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>=H(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=H(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===da&&this.id.client!==this.parent.client&&this.parent.clock>=H(n,this.parent.client))return this.parent.client;if(this.origin&&=(this.left=Sa(t,n,this.origin),this.left.lastId),this.rightOrigin&&=(this.right=W(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===da){let e=ba(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=Sa(e,e.doc.store,V(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),fa(this.origin,n.origin)){if(n.id.client<this.id.client)t=n,r.clear();else if(fa(this.rightOrigin,n.rightOrigin))break}else if(n.origin!==null&&i.has(ba(e.doc.store,n.origin)))r.has(ba(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),ya(e.doc.store,this),this.content.integrate(e,this),Da(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:V(this.id.client,this.id.clock+this.length-1)}mergeWith(e){if(this.constructor===e.constructor&&fa(e.origin,this.lastId)&&this.right===e&&fa(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(),Di(e.deleteSet,this.id.client,this.id.clock,this.length),Da(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw y();this.content.gc(e),t?Ca(e,this,new X(this.id,this.length)):this.content=new rs(this.length)}write(e,t){let n=t>0?V(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=pa(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===da?(e.writeParentInfo(!1),e.writeLeftID(t)):y();i!==null&&e.writeString(i)}this.content.write(e,t)}},ks=(e,t)=>As[t&31](e),As=[()=>{y()},is,fs,ns,_s,ls,us,Ds,hs,ss,()=>{y()}],js=10,$=class extends $o{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,!0)}integrate(e,t){y()}write(e,t){e.writeInfo(js),C(e.restEncoder,this.length-t)}getMissing(e,t){return null}},Ms=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:{},Ns=`__ $YJS$ __`;Ms[Ns]===!0&&console.error(`Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438`),Ms[Ns]=!0;var Ps=3e4,Fs=class extends Kt{constructor(e){super(),this.doc=e,this.clientID=e.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{let e=A();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&&Is(this,t,`timeout`)},h(Ps/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:A()});let a=[],o=[],s=[],c=[];e===null?c.push(t):i==null?e!=null&&a.push(t):(o.push(t),un(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}},Is=(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:A()})}r.push(i)}}r.length>0&&(e.emit(`change`,[{added:[],updated:[],removed:r},n]),e.emit(`update`,[{added:[],updated:[],removed:r},n]))},Ls=(e,t,n=e.states)=>{let r=t.length,i=b();C(i,r);for(let a=0;a<r;a++){let r=t[a],o=n.get(r)||null,s=e.meta.get(r).clock;C(i,r),C(i,s),w(i,JSON.stringify(o))}return x(i)},Rs=(e,t,n)=>{let r=E(t),i=A(),a=[],o=[],s=[],c=[],l=O(r);for(let t=0;t<l;t++){let t=O(r),n=O(r),l=JSON.parse(k(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&&(un(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])},zs=new Map,Bs=class{constructor(e){this.room=e,this.onmessage=null,this._onChange=t=>t.key===e&&this.onmessage!==null&&this.onmessage({data:Rn(t.newValue||``)}),xn(this._onChange)}postMessage(e){bn.setItem(this.room,Ln(Mn(e)))}close(){Sn(this._onChange)}},Vs=typeof BroadcastChannel>`u`?Bs:BroadcastChannel,Hs=e=>N(zs,e,()=>{let t=ye(),n=new Vs(e);return n.onmessage=e=>t.forEach(t=>t(e.data,`broadcastchannel`)),{bc:n,subs:t}}),Us=(e,t)=>(Hs(e).subs.add(t),t),Ws=(e,t)=>{let n=Hs(e),r=n.subs.delete(t);return r&&n.subs.size===0&&(n.bc.close(),zs.delete(e)),r},Gs=(e,t,n=null)=>{let r=Hs(e);r.bc.postMessage(t),r.subs.forEach(e=>e(t,n))},Ks=(e,t)=>{C(e,0),T(e,aa(t))},qs=(e,t,n)=>{C(e,1),T(e,$i(t,n))},Js=(e,t,n)=>qs(t,n,D(e)),Ys=(e,t,n,r)=>{try{Xi(t,D(e),n)}catch(e){r?.(e),console.error(`Caught error while handling a Yjs update`,e)}},Xs=(e,t)=>{C(e,2),T(e,t)},Zs=Ys,Qs=(e,t,n,r,i)=>{let a=O(e);switch(a){case 0:Js(e,t,n);break;case 1:Ys(e,n,r,i);break;case 2:Zs(e,n,r,i);break;default:throw Error(`Unknown message type`)}return a},$s=(e,t,n)=>{O(e)===0&&n(t,k(e))},ec=e=>$t(e,(e,t)=>`${encodeURIComponent(t)}=${encodeURIComponent(e)}`).join(`&`),tc=[];tc[0]=(e,t,n,r,i)=>{C(e,0);let a=Qs(t,e,n.doc,n);r&&a===1&&!n.synced&&(n.synced=!0)},tc[3]=(e,t,n,r,i)=>{C(e,1),T(e,Ls(n.awareness,Array.from(n.awareness.getStates().keys())))},tc[1]=(e,t,n,r,i)=>{Rs(n.awareness,D(t),n)},tc[2]=(e,t,n,r,i)=>{$s(t,n.doc,(e,t)=>rc(n,t))};var nc=3e4,rc=(e,t)=>console.warn(`Permission denied to access ${e.url}.\n${t}`),ic=(e,t,n)=>{let r=E(t),i=b(),a=O(r),o=e.messageHandlers[a];return o?o(i,r,e,n,a):console.error(`Unable to compute message`),i},ac=e=>!(e.code>=4400&&e.code<4500),oc=(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,Is(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(sc,fe(me(2,e.wsUnsuccessfulReconnects)*100,e.maxBackoffTime),e),r!==null&&e.emit(`closed`,[r,e])}},sc=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=A();let r=ic(e,new Uint8Array(n.data),!0);Re(r)>1&&t.send(x(r))},t.onerror=n=>{e.ws===t&&e.emit(`connection-error`,[n,e])},t.onclose=n=>{oc(e,t,n)},t.onopen=()=>{if(e.ws!==t)return;e.wsLastMessageReceived=A(),e.wsconnecting=!1,e.wsconnected=!0,e.emit(`status`,[{status:`connected`}]);let n=b();if(C(n,0),Ks(n,e.doc),t.send(x(n)),e.awareness.getLocalState()!==null){let n=b();C(n,1),T(n,Ls(e.awareness,[e.doc.clientID])),t.send(x(n))}},e.emit(`status`,[{status:`connecting`}])}},cc=(e,t)=>{let n=e.ws;e.wsconnected&&n&&n.readyState===n.OPEN&&n.send(t),e.bcconnected&&Gs(e.bcChannel,t,e)},lc=class extends Gt{constructor(e,t,n,{connect:r=!0,awareness:i=new Fs(n),params:a={},protocols:o=[],WebSocketPolyfill:s=WebSocket,resyncInterval:c=-1,maxBackoffTime:l=2500,disableBc:u=!1,shouldReconnect:d=ac}={}){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=tc.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=b();C(e,0),Ks(e,n),this.ws.send(x(e))}},c)),this._bcSubscriber=(e,t)=>{if(t!==this){let t=ic(this,new Uint8Array(e),!1);Re(t)>1&&Gs(this.bcChannel,x(t),this)}},this._updateHandler=(e,t)=>{if(t!==this){let t=b();C(t,0),Xs(t,e),cc(this,x(t))}},this.doc.on(`update`,this._updateHandler),this._awarenessUpdateHandler=({added:e,updated:t,removed:n},r)=>{let a=e.concat(t).concat(n),o=b();C(o,1),T(o,Ls(i,a)),cc(this,x(o))},this._exitHandler=()=>{Is(this.awareness,[n.clientID],`app closed`)},P&&typeof process<`u`&&process.on(`exit`,this._exitHandler),i.on(`update`,this._awarenessUpdateHandler),this._checkInterval=setInterval(()=>{this.wsconnected&&nc<A()-this.wsLastMessageReceived&&oc(this,this.ws,null)},nc/10),r&&this.connect()}get url(){let e=ec(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(),P&&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||=(Us(this.bcChannel,this._bcSubscriber),!0);let e=b();C(e,0),Ks(e,this.doc),Gs(this.bcChannel,x(e),this);let t=b();C(t,0),qs(t,this.doc),Gs(this.bcChannel,x(t),this);let n=b();C(n,3),Gs(this.bcChannel,x(n),this);let r=b();C(r,1),T(r,Ls(this.awareness,[this.doc.clientID])),Gs(this.bcChannel,x(r),this)}disconnectBc(){let e=b();C(e,1),T(e,Ls(this.awareness,[this.doc.clientID],new Map)),cc(this,x(e)),this.bcconnected&&=(Ws(this.bcChannel,this._bcSubscriber),!1)}disconnect(){this.shouldConnect=!1,this.disconnectBc(),this.ws!==null&&oc(this,this.ws,null)}connect(){this.shouldConnect=!0,!this.wsconnected&&this.ws===null&&(sc(this),this.connectBc())}},uc=1047552;function dc(e,t,n={}){let r=new Set,i=new Set,a=[],o,s=`connecting`,c=!1,l=!1,u,d,f=()=>{for(let e of r)e()},ee=()=>{let t=n.origin?new URL(n.origin):window.location;return`${t.protocol===`https:`?`wss:`:`ws:`}//${t.host}${Mt(`/api/_vitehub/realtime/${encodeURIComponent(e)}`,n.baseURL)}`},te=t.split(`/`).map(encodeURIComponent).join(`/`),p={};function ne(){c=!1,u=new Pi,d=new lc(ee(),te,u,{disableBc:!0,params:{...n.params,clientId:String(u.clientID)}});let e=d;Pt(e),e.messageHandlers[5]=(t,n)=>{let r=Tt(n);if(r){if(r.type===`session`){e.params.epoch=r.epoch;return}e.destroy(),u.destroy(),!l&&(ne(),f())}},e.messageHandlers[6]=(t,n)=>{let r=At(n);r?.kind===`request`&&re(e,r.id,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=b();C(o,1),T(o,Ls(e.awareness,i)),a.send(x(o))});let t=n.identity??{id:`guest:${u.clientID}`};e.awareness.setLocalState({...p,user:zt({...t,id:t.id||`guest:${u.clientID}`})}),e.awareness.on(`change`,f),u.getMap(Ft.status).observe(f),e.on(`sync`,t=>{d===e&&(c=t,f())}),e.on(`status`,e=>{s=e.status,f()})}ne();let m;n.changes&&(m=new lc(ee(),encodeURIComponent(Ct),new Pi,{disableBc:!0,params:{...n.params,workspace:`events`}}),m.awareness.setLocalState(null),Pt(m),m.messageHandlers[4]=(e,t)=>{let n=Dt(t);if(n)for(let e of i)e(n)},m.on(`status`,e=>{e.status===`connected`&&ie()}));async function re(e,t,n){let r=e=>kt({kind:`answer`,id:t,ok:!1,why:e}),i;try{i=o?kt({kind:`answer`,id:t,ok:!0,body:await o(n)}):r(`This page does not answer requests.`),i.byteLength>uc&&(i=r(`The answer has ${i.byteLength} bytes, over the 1 MiB limit.`))}catch(e){i=r(e instanceof Error?e.message:String(e))}let a=e.ws;e.wsconnected&&a&&a.readyState===a.OPEN&&a.send(Uint8Array.from(i))}function ie(){let e=m?.ws;if(m?.wsconnected&&e&&e.readyState===e.OPEN)for(;a.length;)e.send(Uint8Array.from(Ot(a.shift())))}return{get awareness(){return d.awareness},get clientId(){return u.clientID},people:()=>Vt(d.awareness.getStates()),states:()=>{let e=new Map(d.awareness.getStates());return e.delete(u.clientID),e},status:()=>s,saveStatus:()=>c?Lt(u):void 0,setLocal(e,t){t===null?delete p[e]:p[e]=t,d.awareness.setLocalStateField(e,t)},notify(e){m&&(a.push(e),ie())},onUpdate(e){return r.add(e),()=>r.delete(e)},onChange(e){return i.add(e),()=>i.delete(e)},onRequest(e){return o=e,()=>{o===e&&(o=void 0)}},destroy(){l=!0,d.destroy(),u.destroy(),m?.destroy(),m?.doc.destroy(),r.clear(),i.clear(),o=void 0}}}export{dc as connectRealtimeRoom};