@kokimoki/app 1.0.6 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/kokimoki.min.d.ts +348 -0
- package/dist/kokimoki.min.js +2 -0
- package/dist/kokimoki.min.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +11 -2
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import TypedEventEmitter from 'typed-emitter';
|
|
2
|
+
import * as Y from 'yjs';
|
|
3
|
+
|
|
4
|
+
interface Paginated<T> {
|
|
5
|
+
items: T[];
|
|
6
|
+
total: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
type KokimokiClientEvents = {
|
|
10
|
+
connected: () => void;
|
|
11
|
+
disconnected: () => void;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
interface Upload {
|
|
15
|
+
id: string;
|
|
16
|
+
appId: string;
|
|
17
|
+
clientId: string;
|
|
18
|
+
createdAt: Date;
|
|
19
|
+
name: string;
|
|
20
|
+
url: string;
|
|
21
|
+
size: number;
|
|
22
|
+
mimeType: string;
|
|
23
|
+
completed: boolean;
|
|
24
|
+
tags: string[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface FieldOptions {
|
|
28
|
+
label?: string;
|
|
29
|
+
}
|
|
30
|
+
declare abstract class Field<T> {
|
|
31
|
+
readonly options: FieldOptions;
|
|
32
|
+
constructor(options: FieldOptions);
|
|
33
|
+
abstract get value(): T;
|
|
34
|
+
abstract get schema(): any;
|
|
35
|
+
}
|
|
36
|
+
declare class BooleanField extends Field<boolean> {
|
|
37
|
+
value: boolean;
|
|
38
|
+
constructor(value: boolean, options?: FieldOptions);
|
|
39
|
+
get schema(): {
|
|
40
|
+
type: string;
|
|
41
|
+
default: boolean;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
declare class ConstField<T extends string> extends Field<string extends T ? never : T> {
|
|
45
|
+
value: string extends T ? never : T;
|
|
46
|
+
constructor(value: string extends T ? never : T, options?: FieldOptions);
|
|
47
|
+
get schema(): {
|
|
48
|
+
const: string extends T ? never : T;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
declare class ImageField extends Field<string> {
|
|
52
|
+
value: string;
|
|
53
|
+
constructor(value: string, options?: FieldOptions);
|
|
54
|
+
get schema(): {
|
|
55
|
+
type: string;
|
|
56
|
+
default: string;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
declare class TextField extends Field<string> {
|
|
60
|
+
value: string;
|
|
61
|
+
constructor(value: string, options?: FieldOptions);
|
|
62
|
+
get schema(): {
|
|
63
|
+
type: string;
|
|
64
|
+
default: string;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
declare class EnumField<T extends Record<string, string>> extends Field<keyof T> {
|
|
68
|
+
enumValues: T;
|
|
69
|
+
value: keyof T;
|
|
70
|
+
constructor(enumValues: T, value: keyof T, options?: FieldOptions);
|
|
71
|
+
get schema(): {
|
|
72
|
+
enum: string[];
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
declare class IntegerField extends Field<number> {
|
|
76
|
+
value: number;
|
|
77
|
+
constructor(value: number, options?: FieldOptions);
|
|
78
|
+
get schema(): {
|
|
79
|
+
type: string;
|
|
80
|
+
default: number;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
declare class FloatField extends Field<number> {
|
|
84
|
+
value: number;
|
|
85
|
+
constructor(value: number, options?: FieldOptions);
|
|
86
|
+
get schema(): {
|
|
87
|
+
type: string;
|
|
88
|
+
default: number;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
declare class FormGroup<T extends Record<string, Field<any>>, O extends Record<string, Field<any>>> extends Field<{
|
|
92
|
+
[key in keyof T]: T[key]["value"];
|
|
93
|
+
} & Partial<{
|
|
94
|
+
[key in keyof O]: O[key]["value"];
|
|
95
|
+
}>> {
|
|
96
|
+
requiredFields: T;
|
|
97
|
+
optionalFields: O;
|
|
98
|
+
constructor(requiredFields: T, optionalFields?: O, options?: FieldOptions);
|
|
99
|
+
get value(): {
|
|
100
|
+
[key in keyof T]: T[key]["value"];
|
|
101
|
+
} & Partial<{
|
|
102
|
+
[key in keyof O]: O[key]["value"];
|
|
103
|
+
}>;
|
|
104
|
+
get schema(): {
|
|
105
|
+
type: string;
|
|
106
|
+
properties: any;
|
|
107
|
+
required: string[];
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
declare class FormArray<T> extends Field<T[]> {
|
|
111
|
+
private factory;
|
|
112
|
+
value: Field<T>["value"][];
|
|
113
|
+
constructor(factory: () => Field<T>, value: Field<T>["value"][], options?: FieldOptions);
|
|
114
|
+
get schema(): {
|
|
115
|
+
type: string;
|
|
116
|
+
items: any;
|
|
117
|
+
default: T[];
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
declare class Form<R extends Record<string, Field<any>>, O extends Record<string, Field<any>>> extends FormGroup<R, O> {
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
declare namespace KokimokiSchema {
|
|
124
|
+
abstract class Generic<T> {
|
|
125
|
+
abstract get defaultValue(): T;
|
|
126
|
+
abstract set defaultValue(value: T);
|
|
127
|
+
}
|
|
128
|
+
class Number extends Generic<number> {
|
|
129
|
+
defaultValue: number;
|
|
130
|
+
constructor(defaultValue?: number);
|
|
131
|
+
}
|
|
132
|
+
function number(defaultValue?: number): Number;
|
|
133
|
+
class String extends Generic<string> {
|
|
134
|
+
defaultValue: string;
|
|
135
|
+
constructor(defaultValue?: string);
|
|
136
|
+
}
|
|
137
|
+
function string(defaultValue?: string): String;
|
|
138
|
+
class Boolean extends Generic<boolean> {
|
|
139
|
+
defaultValue: boolean;
|
|
140
|
+
constructor(defaultValue?: boolean);
|
|
141
|
+
}
|
|
142
|
+
function boolean(defaultValue?: boolean): Boolean;
|
|
143
|
+
class Struct<Data extends Record<string, Generic<unknown>>> extends Generic<{
|
|
144
|
+
[key in keyof Data]: Data[key]["defaultValue"];
|
|
145
|
+
}> {
|
|
146
|
+
fields: Data;
|
|
147
|
+
constructor(fields: Data);
|
|
148
|
+
get defaultValue(): {
|
|
149
|
+
[key in keyof Data]: Data[key]["defaultValue"];
|
|
150
|
+
};
|
|
151
|
+
set defaultValue(value: {
|
|
152
|
+
[key in keyof Data]: Data[key]["defaultValue"];
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
function struct<Data extends Record<string, Generic<unknown>>>(schema: Data): Struct<Data>;
|
|
156
|
+
class Dict<T extends Generic<unknown>> {
|
|
157
|
+
schema: T;
|
|
158
|
+
defaultValue: {
|
|
159
|
+
[key: string]: T["defaultValue"];
|
|
160
|
+
};
|
|
161
|
+
constructor(schema: T, defaultValue?: {
|
|
162
|
+
[key: string]: T["defaultValue"];
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
function dict<T extends Generic<unknown>>(schema: T, defaultValue?: {
|
|
166
|
+
[key: string]: T["defaultValue"];
|
|
167
|
+
}): Dict<T>;
|
|
168
|
+
class List<T extends Generic<unknown>> extends Generic<T["defaultValue"][]> {
|
|
169
|
+
schema: T;
|
|
170
|
+
defaultValue: T["defaultValue"][];
|
|
171
|
+
constructor(schema: T, defaultValue?: T["defaultValue"][]);
|
|
172
|
+
}
|
|
173
|
+
function list<T extends Generic<unknown>>(schema: T, defaultValue?: T["defaultValue"][]): List<T>;
|
|
174
|
+
/**
|
|
175
|
+
* Nullable
|
|
176
|
+
*/
|
|
177
|
+
class Nullable<T extends Generic<unknown>> extends Generic<T["defaultValue"] | null> {
|
|
178
|
+
schema: T;
|
|
179
|
+
defaultValue: T["defaultValue"] | null;
|
|
180
|
+
constructor(schema: T, defaultValue: T["defaultValue"] | null);
|
|
181
|
+
}
|
|
182
|
+
function nullable<T extends Generic<unknown>>(schema: T, defaultValue?: T["defaultValue"] | null): Nullable<T>;
|
|
183
|
+
class StringEnum<T extends readonly string[]> extends Generic<string> {
|
|
184
|
+
readonly options: T;
|
|
185
|
+
defaultValue: T[number];
|
|
186
|
+
constructor(options: T, defaultValue: T[number]);
|
|
187
|
+
}
|
|
188
|
+
function stringEnum<T extends readonly string[]>(options: T, defaultValue: T[number]): StringEnum<T>;
|
|
189
|
+
class StringConst<T extends string> extends Generic<string> {
|
|
190
|
+
readonly defaultValue: T;
|
|
191
|
+
constructor(defaultValue: T);
|
|
192
|
+
}
|
|
193
|
+
function stringConst<T extends string>(defaultValue: T): StringConst<T>;
|
|
194
|
+
class AnyOf<T extends readonly Generic<unknown>[]> extends Generic<T[number]["defaultValue"]> {
|
|
195
|
+
readonly schemas: T;
|
|
196
|
+
defaultValue: T[number]["defaultValue"];
|
|
197
|
+
constructor(schemas: T, defaultValue: T[number]["defaultValue"]);
|
|
198
|
+
}
|
|
199
|
+
function anyOf<T extends readonly Generic<unknown>[]>(schemas: T, defaultValue: T[number]["defaultValue"]): AnyOf<T>;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
declare enum RoomSubscriptionMode {
|
|
203
|
+
Read = "r",
|
|
204
|
+
Write = "w",
|
|
205
|
+
ReadWrite = "b"
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
declare class KokimokiStore<T extends KokimokiSchema.Generic<unknown>> {
|
|
209
|
+
readonly roomName: string;
|
|
210
|
+
readonly mode: RoomSubscriptionMode;
|
|
211
|
+
readonly doc: Y.Doc;
|
|
212
|
+
readonly proxy: T["defaultValue"];
|
|
213
|
+
readonly root: T["defaultValue"];
|
|
214
|
+
readonly defaultValue: T["defaultValue"];
|
|
215
|
+
readonly docRoot: Y.Map<unknown>;
|
|
216
|
+
constructor(roomName: string, schema: T, mode?: RoomSubscriptionMode);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
declare class KokimokiQueue<Req extends KokimokiSchema.Generic<unknown>> extends KokimokiStore<KokimokiSchema.Dict<KokimokiSchema.Struct<{
|
|
220
|
+
timestamp: KokimokiSchema.Number;
|
|
221
|
+
payload: Req;
|
|
222
|
+
}>>> {
|
|
223
|
+
readonly payloadSchema: Req;
|
|
224
|
+
private _emitter;
|
|
225
|
+
readonly on: <E extends "messages">(event: E, listener: {
|
|
226
|
+
messages: (messages: {
|
|
227
|
+
id: string;
|
|
228
|
+
payload: Req["defaultValue"];
|
|
229
|
+
}[]) => void;
|
|
230
|
+
}[E]) => TypedEventEmitter<{
|
|
231
|
+
messages: (messages: {
|
|
232
|
+
id: string;
|
|
233
|
+
payload: Req["defaultValue"];
|
|
234
|
+
}[]) => void;
|
|
235
|
+
}>;
|
|
236
|
+
readonly off: <E extends "messages">(event: E, listener: {
|
|
237
|
+
messages: (messages: {
|
|
238
|
+
id: string;
|
|
239
|
+
payload: Req["defaultValue"];
|
|
240
|
+
}[]) => void;
|
|
241
|
+
}[E]) => TypedEventEmitter<{
|
|
242
|
+
messages: (messages: {
|
|
243
|
+
id: string;
|
|
244
|
+
payload: Req["defaultValue"];
|
|
245
|
+
}[]) => void;
|
|
246
|
+
}>;
|
|
247
|
+
constructor(roomName: string, payloadSchema: Req, mode: RoomSubscriptionMode);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
declare class KokimokiTransaction {
|
|
251
|
+
private kmClient;
|
|
252
|
+
private _clones;
|
|
253
|
+
private _updates;
|
|
254
|
+
private _consumeMessagesInRooms;
|
|
255
|
+
constructor(kmClient: KokimokiClient<any>);
|
|
256
|
+
private _parseTarget;
|
|
257
|
+
private _parsePath;
|
|
258
|
+
private _getClone;
|
|
259
|
+
get<T>(target: T): T;
|
|
260
|
+
set<T>(target: T, value: T): void;
|
|
261
|
+
delete<T>(target: T): void;
|
|
262
|
+
push<T>(target: T[], value: T): void;
|
|
263
|
+
queueMessage<T>(queue: KokimokiQueue<KokimokiSchema.Generic<T>>, payload: T): void;
|
|
264
|
+
consumeMessage<T>(queue: KokimokiQueue<KokimokiSchema.Generic<T>>, messageId: string): void;
|
|
265
|
+
getUpdates(): Promise<{
|
|
266
|
+
updates: {
|
|
267
|
+
roomName: string;
|
|
268
|
+
update: Uint8Array;
|
|
269
|
+
}[];
|
|
270
|
+
consumedMessages: Set<string>;
|
|
271
|
+
}>;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
declare const KokimokiClient_base: new () => TypedEventEmitter<KokimokiClientEvents>;
|
|
275
|
+
declare class KokimokiClient<ClientContextT = any> extends KokimokiClient_base {
|
|
276
|
+
readonly host: string;
|
|
277
|
+
readonly appId: string;
|
|
278
|
+
readonly code: string;
|
|
279
|
+
private _wsUrl;
|
|
280
|
+
private _apiUrl;
|
|
281
|
+
private _id?;
|
|
282
|
+
private _token?;
|
|
283
|
+
private _apiHeaders?;
|
|
284
|
+
private _serverTimeOffset;
|
|
285
|
+
private _clientContext?;
|
|
286
|
+
private _ws?;
|
|
287
|
+
private _subscriptionsByName;
|
|
288
|
+
private _subscriptionsByHash;
|
|
289
|
+
private _subscribeReqPromises;
|
|
290
|
+
private _transactionPromises;
|
|
291
|
+
private _connected;
|
|
292
|
+
private _connectPromise?;
|
|
293
|
+
private _messageId;
|
|
294
|
+
private _reconnectTimeout;
|
|
295
|
+
private _pingInterval;
|
|
296
|
+
constructor(host: string, appId: string, code?: string);
|
|
297
|
+
get id(): string;
|
|
298
|
+
get token(): string;
|
|
299
|
+
get apiUrl(): string;
|
|
300
|
+
get apiHeaders(): Headers;
|
|
301
|
+
get clientContext(): ClientContextT & ({} | null);
|
|
302
|
+
get connected(): boolean;
|
|
303
|
+
get ws(): WebSocket;
|
|
304
|
+
connect(): Promise<void>;
|
|
305
|
+
private handleInitMessage;
|
|
306
|
+
private handleBinaryMessage;
|
|
307
|
+
private handleErrorMessage;
|
|
308
|
+
private handleSubscribeResMessage;
|
|
309
|
+
private handleRoomUpdateMessage;
|
|
310
|
+
serverTimestamp(): number;
|
|
311
|
+
patchRoomState(room: string, update: Uint8Array): Promise<any>;
|
|
312
|
+
private createUpload;
|
|
313
|
+
private uploadChunks;
|
|
314
|
+
private completeUpload;
|
|
315
|
+
upload(name: string, blob: Blob, tags?: string[]): Promise<Upload>;
|
|
316
|
+
updateUpload(id: string, update: {
|
|
317
|
+
tags?: string[];
|
|
318
|
+
}): Promise<Upload>;
|
|
319
|
+
listUploads(filter?: {
|
|
320
|
+
clientId?: string;
|
|
321
|
+
mimeTypes?: string[];
|
|
322
|
+
tags?: string[];
|
|
323
|
+
}, skip?: number, limit?: number): Promise<Paginated<Upload>>;
|
|
324
|
+
deleteUpload(id: string): Promise<{
|
|
325
|
+
acknowledged: boolean;
|
|
326
|
+
deletedCount: number;
|
|
327
|
+
}>;
|
|
328
|
+
exposeScriptingContext(context: any): Promise<void>;
|
|
329
|
+
private sendSubscriptionReq;
|
|
330
|
+
join<T extends KokimokiSchema.Generic<unknown>>(store: KokimokiStore<T>): Promise<void>;
|
|
331
|
+
transact(handler: (t: KokimokiTransaction) => void): Promise<void>;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
declare class RoomSubscription {
|
|
335
|
+
private kmClient;
|
|
336
|
+
readonly store: KokimokiStore<any>;
|
|
337
|
+
private _joined;
|
|
338
|
+
private _roomHash?;
|
|
339
|
+
private _onDisconnect;
|
|
340
|
+
constructor(kmClient: KokimokiClient, store: KokimokiStore<any>);
|
|
341
|
+
get roomName(): string;
|
|
342
|
+
get roomHash(): number;
|
|
343
|
+
get joined(): boolean;
|
|
344
|
+
applyInitialResponse(roomHash: number, initialUpdate?: Uint8Array): Promise<void>;
|
|
345
|
+
close(): void;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
export { BooleanField, ConstField, EnumField, Field, type FieldOptions, FloatField, Form, FormArray, FormGroup, ImageField, IntegerField, KokimokiClient, type KokimokiClientEvents, KokimokiQueue, KokimokiSchema, KokimokiStore, type Paginated, RoomSubscription, RoomSubscriptionMode, TextField, type Upload };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var kokimoki=function(t){"use strict";const e={};class n{options;constructor(t){this.options=t}}class r extends n{requiredFields;optionalFields;constructor(t,n={},r=e){super(r),this.requiredFields=t,this.optionalFields=n}get value(){const t=Object.entries(this.requiredFields).reduce(((t,[e,n])=>(t[e]=n.value,t)),{});return Object.entries(this.optionalFields).forEach((([e,n])=>{void 0!==n.value&&(t[e]=n.value)})),t}get schema(){const t={};return Object.entries(this.requiredFields).forEach((([e,n])=>{t[e]=n.schema})),Object.entries(this.optionalFields).forEach((([e,n])=>{t[e]=n.schema})),{type:"object",properties:t,required:Object.keys(this.requiredFields)}}}function s(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var i,o={exports:{}},c="object"==typeof Reflect?Reflect:null,l=c&&"function"==typeof c.apply?c.apply:function(t,e,n){return Function.prototype.apply.call(t,e,n)};i=c&&"function"==typeof c.ownKeys?c.ownKeys:Object.getOwnPropertySymbols?function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:function(t){return Object.getOwnPropertyNames(t)};var h=Number.isNaN||function(t){return t!=t};function a(){a.init.call(this)}o.exports=a,o.exports.once=function(t,e){return new Promise((function(n,r){function s(n){t.removeListener(e,i),r(n)}function i(){"function"==typeof t.removeListener&&t.removeListener("error",s),n([].slice.call(arguments))}b(t,e,i,{once:!0}),"error"!==e&&function(t,e,n){"function"==typeof t.on&&b(t,"error",e,n)}(t,s,{once:!0})}))},a.EventEmitter=a,a.prototype._events=void 0,a.prototype._eventsCount=0,a.prototype._maxListeners=void 0;var u=10;function d(t){if("function"!=typeof t)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}function f(t){return void 0===t._maxListeners?a.defaultMaxListeners:t._maxListeners}function g(t,e,n,r){var s,i,o,c;if(d(n),void 0===(i=t._events)?(i=t._events=Object.create(null),t._eventsCount=0):(void 0!==i.newListener&&(t.emit("newListener",e,n.listener?n.listener:n),i=t._events),o=i[e]),void 0===o)o=i[e]=n,++t._eventsCount;else if("function"==typeof o?o=i[e]=r?[n,o]:[o,n]:r?o.unshift(n):o.push(n),(s=f(t))>0&&o.length>s&&!o.warned){o.warned=!0;var l=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");l.name="MaxListenersExceededWarning",l.emitter=t,l.type=e,l.count=o.length,c=l,console&&console.warn&&console.warn(c)}return t}function p(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function w(t,e,n){var r={fired:!1,wrapFn:void 0,target:t,type:e,listener:n},s=p.bind(r);return s.listener=n,r.wrapFn=s,s}function m(t,e,n){var r=t._events;if(void 0===r)return[];var s=r[e];return void 0===s?[]:"function"==typeof s?n?[s.listener||s]:[s]:n?function(t){for(var e=new Array(t.length),n=0;n<e.length;++n)e[n]=t[n].listener||t[n];return e}(s):_(s,s.length)}function y(t){var e=this._events;if(void 0!==e){var n=e[t];if("function"==typeof n)return 1;if(void 0!==n)return n.length}return 0}function _(t,e){for(var n=new Array(e),r=0;r<e;++r)n[r]=t[r];return n}function b(t,e,n,r){if("function"==typeof t.on)r.once?t.once(e,n):t.on(e,n);else{if("function"!=typeof t.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof t);t.addEventListener(e,(function s(i){r.once&&t.removeEventListener(e,s),n(i)}))}}Object.defineProperty(a,"defaultMaxListeners",{enumerable:!0,get:function(){return u},set:function(t){if("number"!=typeof t||t<0||h(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");u=t}}),a.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},a.prototype.setMaxListeners=function(t){if("number"!=typeof t||t<0||h(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this},a.prototype.getMaxListeners=function(){return f(this)},a.prototype.emit=function(t){for(var e=[],n=1;n<arguments.length;n++)e.push(arguments[n]);var r="error"===t,s=this._events;if(void 0!==s)r=r&&void 0===s.error;else if(!r)return!1;if(r){var i;if(e.length>0&&(i=e[0]),i instanceof Error)throw i;var o=new Error("Unhandled error."+(i?" ("+i.message+")":""));throw o.context=i,o}var c=s[t];if(void 0===c)return!1;if("function"==typeof c)l(c,this,e);else{var h=c.length,a=_(c,h);for(n=0;n<h;++n)l(a[n],this,e)}return!0},a.prototype.addListener=function(t,e){return g(this,t,e,!1)},a.prototype.on=a.prototype.addListener,a.prototype.prependListener=function(t,e){return g(this,t,e,!0)},a.prototype.once=function(t,e){return d(e),this.on(t,w(this,t,e)),this},a.prototype.prependOnceListener=function(t,e){return d(e),this.prependListener(t,w(this,t,e)),this},a.prototype.removeListener=function(t,e){var n,r,s,i,o;if(d(e),void 0===(r=this._events))return this;if(void 0===(n=r[t]))return this;if(n===e||n.listener===e)0==--this._eventsCount?this._events=Object.create(null):(delete r[t],r.removeListener&&this.emit("removeListener",t,n.listener||e));else if("function"!=typeof n){for(s=-1,i=n.length-1;i>=0;i--)if(n[i]===e||n[i].listener===e){o=n[i].listener,s=i;break}if(s<0)return this;0===s?n.shift():function(t,e){for(;e+1<t.length;e++)t[e]=t[e+1];t.pop()}(n,s),1===n.length&&(r[t]=n[0]),void 0!==r.removeListener&&this.emit("removeListener",t,o||e)}return this},a.prototype.off=a.prototype.removeListener,a.prototype.removeAllListeners=function(t){var e,n,r;if(void 0===(n=this._events))return this;if(void 0===n.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==n[t]&&(0==--this._eventsCount?this._events=Object.create(null):delete n[t]),this;if(0===arguments.length){var s,i=Object.keys(n);for(r=0;r<i.length;++r)"removeListener"!==(s=i[r])&&this.removeAllListeners(s);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(e=n[t]))this.removeListener(t,e);else if(void 0!==e)for(r=e.length-1;r>=0;r--)this.removeListener(t,e[r]);return this},a.prototype.listeners=function(t){return m(this,t,!0)},a.prototype.rawListeners=function(t){return m(this,t,!1)},a.listenerCount=function(t,e){return"function"==typeof t.listenerCount?t.listenerCount(e):y.call(t,e)},a.prototype.listenerCount=y,a.prototype.eventNames=function(){return this._eventsCount>0?i(this._events):[]};var k=s(o.exports);const v=()=>new Map,S=t=>{const e=v();return t.forEach(((t,n)=>{e.set(n,t)})),e},C=(t,e,n)=>{let r=t.get(e);return void 0===r&&t.set(e,r=n()),r},E=()=>new Set,D=t=>t[t.length-1],O=(t,e)=>{for(let n=0;n<e.length;n++)t.push(e[n])},x=Array.from,A=Array.isArray;class I{constructor(){this._observers=v()}on(t,e){C(this._observers,t,E).add(e)}once(t,e){const n=(...r)=>{this.off(t,n),e(...r)};this.on(t,n)}off(t,e){const n=this._observers.get(t);void 0!==n&&(n.delete(e),0===n.size&&this._observers.delete(t))}emit(t,e){return x((this._observers.get(t)||v()).values()).forEach((t=>t(...e)))}destroy(){this._observers=v()}}const M=Math.floor,L=Math.abs,R=(t,e)=>t<e?t:e,j=(t,e)=>t>e?t:e,P=t=>0!==t?t<0:1/t<0,U=/^\s*/g,N=/([A-Z])/g,T=(t,e)=>(t=>t.replace(U,""))(t.replace(N,(t=>`${e}${(t=>t.toLowerCase())(t)}`))),V="undefined"!=typeof TextEncoder?new TextEncoder:null,K=V?t=>V.encode(t):t=>{const e=unescape(encodeURIComponent(t)),n=e.length,r=new Uint8Array(n);for(let t=0;t<n;t++)r[t]=e.codePointAt(t);return r};let F="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});F&&1===F.decode(new Uint8Array).length&&(F=null);const $=t=>void 0===t?null:t;let W=new class{constructor(){this.map=new Map}setItem(t,e){this.map.set(t,e)}getItem(t){return this.map.get(t)}},B=!0;try{"undefined"!=typeof localStorage&&(W=localStorage,B=!1)}catch(t){}const H=W,J=Object.assign,q=Object.keys,z=t=>q(t).length,G=(t,e)=>t===e||z(t)===z(e)&&((t,e)=>{for(const n in t)if(!e(t[n],n))return!1;return!0})(t,((t,n)=>(void 0!==t||((t,e)=>Object.prototype.hasOwnProperty.call(t,e))(e,n))&&e[n]===t)),Y=(t,e,n=0)=>{try{for(;n<t.length;n++)t[n](...e)}finally{n<t.length&&Y(t,e,n+1)}},X=t=>t,Q="undefined"!=typeof process&&process.release&&/node|io\.js/.test(process.release.name);let Z;const tt=t=>(()=>{if(void 0===Z)if(Q){Z=v();const t=process.argv;let e=null;for(let n=0;n<t.length;n++){const r=t[n];"-"===r[0]?(null!==e&&Z.set(e,""),e=r):null!==e&&(Z.set(e,r),e=null)}null!==e&&Z.set(e,"")}else"object"==typeof location?(Z=v(),(location.search||"?").slice(1).split("&").forEach((t=>{if(0!==t.length){const[e,n]=t.split("=");Z.set(`--${T(e,"-")}`,n),Z.set(`-${T(e,"-")}`,n)}}))):Z=v();return Z})().has(t),et=t=>$(Q?process.env[t.toUpperCase()]:H.getItem(t));var nt;tt("--"+(nt="production"))||et(nt);const rt=Q&&(st=process.env.FORCE_COLOR,["true","1","2"].includes(st));var st;const it=!tt("no-colors")&&(!Q||process.stdout.isTTY||rt)&&(!Q||tt("color")||rt||null!==et("COLORTERM")||(et("TERM")||"").includes("color")),ot=64,ct=128,lt=127,ht=Number.MAX_SAFE_INTEGER,at=Number.isInteger||(t=>"number"==typeof t&&isFinite(t)&&M(t)===t),ut=t=>new Error(t),dt=()=>{throw ut("Method unimplemented")},ft=()=>{throw ut("Unexpected case")},gt=ut("Unexpected end of array"),pt=ut("Integer out of Range");class wt{constructor(t){this.arr=t,this.pos=0}}const mt=t=>new wt(t),yt=t=>((t,e)=>{const n=It(t.arr.buffer,t.pos+t.arr.byteOffset,e);return t.pos+=e,n})(t,bt(t)),_t=t=>t.arr[t.pos++],bt=t=>{let e=0,n=1;const r=t.arr.length;for(;t.pos<r;){const r=t.arr[t.pos++];if(e+=(r<)*n,n*=128,r<ct)return e;if(e>ht)throw pt}throw gt},kt=t=>{let e=t.arr[t.pos++],n=63&e,r=64;const s=(e&ot)>0?-1:1;if(0==(e&ct))return s*n;const i=t.arr.length;for(;t.pos<i;){if(e=t.arr[t.pos++],n+=(e<)*r,r*=128,e<ct)return s*n;if(n>ht)throw pt}throw gt},vt=F?t=>F.decode(yt(t)):t=>{let e=bt(t);if(0===e)return"";{let n=String.fromCodePoint(_t(t));if(--e<100)for(;e--;)n+=String.fromCodePoint(_t(t));else for(;e>0;){const r=e<1e4?e:1e4,s=t.arr.subarray(t.pos,t.pos+r);t.pos+=r,n+=String.fromCodePoint.apply(null,s),e-=r}return decodeURIComponent(escape(n))}},St=(t,e)=>{const n=new DataView(t.arr.buffer,t.arr.byteOffset+t.pos,e);return t.pos+=e,n},Ct=[t=>{},t=>null,kt,t=>St(t,4).getFloat32(0,!1),t=>St(t,8).getFloat64(0,!1),t=>St(t,8).getBigInt64(0,!1),t=>!1,t=>!0,vt,t=>{const e=bt(t),n={};for(let r=0;r<e;r++){n[vt(t)]=Et(t)}return n},t=>{const e=bt(t),n=[];for(let r=0;r<e;r++)n.push(Et(t));return n},yt],Et=t=>Ct[127-_t(t)](t);class Dt extends wt{constructor(t,e){super(t),this.reader=e,this.s=null,this.count=0}read(){var t;return 0===this.count&&(this.s=this.reader(this),(t=this).pos!==t.arr.length?this.count=bt(this)+1:this.count=-1),this.count--,this.s}}class Ot extends wt{constructor(t){super(t),this.s=0,this.count=0}read(){if(0===this.count){this.s=kt(this);const t=P(this.s);this.count=1,t&&(this.s=-this.s,this.count=bt(this)+2)}return this.count--,this.s}}class xt extends wt{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(0===this.count){const t=kt(this),e=1&t;this.diff=M(t/2),this.count=1,e&&(this.count=bt(this)+2)}return this.s+=this.diff,this.count--,this.s}}class At{constructor(t){this.decoder=new Ot(t),this.str=vt(this.decoder),this.spos=0}read(){const t=this.spos+this.decoder.read(),e=this.str.slice(this.spos,t);return this.spos=t,e}}const It=(t,e,n)=>new Uint8Array(t,e,n),Mt=t=>{const e=(n=t.byteLength,new Uint8Array(n));var n;return e.set(t),e};class Lt{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const Rt=()=>new Lt,jt=t=>{const e=new Uint8Array((t=>{let e=t.cpos;for(let n=0;n<t.bufs.length;n++)e+=t.bufs[n].length;return e})(t));let n=0;for(let r=0;r<t.bufs.length;r++){const s=t.bufs[r];e.set(s,n),n+=s.length}return e.set(It(t.cbuf.buffer,0,t.cpos),n),e},Pt=(t,e)=>{const n=t.cbuf.length;t.cpos===n&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(2*n),t.cpos=0),t.cbuf[t.cpos++]=e},Ut=Pt,Nt=(t,e)=>{for(;e>lt;)Pt(t,ct|lt&e),e=M(e/128);Pt(t,lt&e)},Tt=(t,e)=>{const n=P(e);for(n&&(e=-e),Pt(t,(e>63?ct:0)|(n?ot:0)|63&e),e=M(e/64);e>0;)Pt(t,(e>lt?ct:0)|lt&e),e=M(e/128)},Vt=new Uint8Array(3e4),Kt=Vt.length/3,Ft=V&&V.encodeInto?(t,e)=>{if(e.length<Kt){const n=V.encodeInto(e,Vt).written||0;Nt(t,n);for(let e=0;e<n;e++)Pt(t,Vt[e])}else Wt(t,K(e))}:(t,e)=>{const n=unescape(encodeURIComponent(e)),r=n.length;Nt(t,r);for(let e=0;e<r;e++)Pt(t,n.codePointAt(e))},$t=(t,e)=>{const n=t.cbuf.length,r=t.cpos,s=R(n-r,e.length),i=e.length-s;t.cbuf.set(e.subarray(0,s),r),t.cpos+=s,i>0&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(j(2*n,i)),t.cbuf.set(e.subarray(s)),t.cpos=i)},Wt=(t,e)=>{Nt(t,e.byteLength),$t(t,e)},Bt=(t,e)=>{((t,e)=>{const n=t.cbuf.length;n-t.cpos<e&&(t.bufs.push(It(t.cbuf.buffer,0,t.cpos)),t.cbuf=new Uint8Array(2*j(n,e)),t.cpos=0)})(t,e);const n=new DataView(t.cbuf.buffer,t.cpos,e);return t.cpos+=e,n},Ht=new DataView(new ArrayBuffer(4)),Jt=(t,e)=>{switch(typeof e){case"string":Pt(t,119),Ft(t,e);break;case"number":at(e)&&L(e)<=2147483647?(Pt(t,125),Tt(t,e)):(n=e,Ht.setFloat32(0,n),Ht.getFloat32(0)===n?(Pt(t,124),((t,e)=>{Bt(t,4).setFloat32(0,e,!1)})(t,e)):(Pt(t,123),((t,e)=>{Bt(t,8).setFloat64(0,e,!1)})(t,e)));break;case"bigint":Pt(t,122),((t,e)=>{Bt(t,8).setBigInt64(0,e,!1)})(t,e);break;case"object":if(null===e)Pt(t,126);else if(A(e)){Pt(t,117),Nt(t,e.length);for(let n=0;n<e.length;n++)Jt(t,e[n])}else if(e instanceof Uint8Array)Pt(t,116),Wt(t,e);else{Pt(t,118);const n=Object.keys(e);Nt(t,n.length);for(let r=0;r<n.length;r++){const s=n[r];Ft(t,s),Jt(t,e[s])}}break;case"boolean":Pt(t,e?120:121);break;default:Pt(t,127)}var n};class qt extends Lt{constructor(t){super(),this.w=t,this.s=null,this.count=0}write(t){this.s===t?this.count++:(this.count>0&&Nt(this,this.count-1),this.count=1,this.w(this,t),this.s=t)}}const zt=t=>{t.count>0&&(Tt(t.encoder,1===t.count?t.s:-t.s),t.count>1&&Nt(t.encoder,t.count-2))};class Gt{constructor(){this.encoder=new Lt,this.s=0,this.count=0}write(t){this.s===t?this.count++:(zt(this),this.count=1,this.s=t)}toUint8Array(){return zt(this),jt(this.encoder)}}const Yt=t=>{if(t.count>0){const e=2*t.diff+(1===t.count?0:1);Tt(t.encoder,e),t.count>1&&Nt(t.encoder,t.count-2)}};class Xt{constructor(){this.encoder=new Lt,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(Yt(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return Yt(this),jt(this.encoder)}}class Qt{constructor(){this.sarr=[],this.s="",this.lensE=new Gt}write(t){this.s+=t,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(t.length)}toUint8Array(){const t=new Lt;return this.sarr.push(this.s),this.s="",Ft(t,this.sarr.join("")),$t(t,this.lensE.toUint8Array()),jt(t)}}const Zt=crypto.getRandomValues.bind(crypto),te=()=>Zt(new Uint32Array(1))[0],ee=[1e7]+-1e3+-4e3+-8e3+-1e11,ne=()=>ee.replace(/[018]/g,(t=>(t^te()&15>>t/4).toString(16))),re=t=>new Promise(t);Promise.all.bind(Promise);class se{constructor(t,e){this.left=t,this.right=e}}const ie=(t,e)=>new se(t,e);"undefined"!=typeof DOMParser&&new DOMParser;const oe=Symbol,ce=oe(),le=oe(),he=oe(),ae=oe(),ue=oe(),de=oe(),fe=oe(),ge=oe(),pe=oe(),we={[ce]:ie("font-weight","bold"),[le]:ie("font-weight","normal"),[he]:ie("color","blue"),[ue]:ie("color","green"),[ae]:ie("color","grey"),[de]:ie("color","red"),[fe]:ie("color","purple"),[ge]:ie("color","orange"),[pe]:ie("color","black")},me=it?t=>{const e=[],n=[],r=v();let s=[],i=0;for(;i<t.length;i++){const s=t[i],o=we[s];if(void 0!==o)r.set(o.left,o.right);else{if(s.constructor!==String&&s.constructor!==Number)break;{const t=((t,e)=>{const n=[];for(const[r,s]of t)n.push(e(s,r));return n})(r,((t,e)=>`${e}:${t};`)).join("");i>0||t.length>0?(e.push("%c"+s),n.push(t)):e.push(s)}}}for(i>0&&(s=n,s.unshift(e.join("")));i<t.length;i++){const e=t[i];e instanceof Symbol||s.push(e)}return s}:t=>{const e=[];let n=0;for(;n<t.length;n++){const r=t[n];r.constructor===String||r.constructor===Number||r.constructor===Object&&e.push(JSON.stringify(r))}return e},ye=E(),_e=t=>({[Symbol.iterator](){return this},next:t}),be=(t,e)=>_e((()=>{const{done:n,value:r}=t.next();return{done:n,value:n?void 0:e(r)}}));class ke{constructor(t,e){this.clock=t,this.len=e}}class ve{constructor(){this.clients=new Map}}const Se=(t,e,n)=>e.clients.forEach(((e,r)=>{const s=t.doc.store.clients.get(r);for(let r=0;r<e.length;r++){const i=e[r];fn(t,s,i.clock,i.len,n)}})),Ce=(t,e)=>{const n=t.clients.get(e.client);return void 0!==n&&null!==((t,e)=>{let n=0,r=t.length-1;for(;n<=r;){const s=M((n+r)/2),i=t[s],o=i.clock;if(o<=e){if(e<o+i.len)return s;n=s+1}else r=s-1}return null})(n,e.clock)},Ee=t=>{t.clients.forEach((t=>{let e,n;for(t.sort(((t,e)=>t.clock-e.clock)),e=1,n=1;e<t.length;e++){const r=t[n-1],s=t[e];r.clock+r.len>=s.clock?r.len=j(r.len,s.clock+s.len-r.clock):(n<e&&(t[n]=s),n++)}t.length=n}))},De=(t,e,n,r)=>{C(t.clients,e,(()=>[])).push(new ke(n,r))},Oe=t=>{const e=new ve;return t.clients.forEach(((t,n)=>{const r=[];for(let e=0;e<t.length;e++){const n=t[e];if(n.deleted){const s=n.id.clock;let i=n.length;if(e+1<t.length)for(let n=t[e+1];e+1<t.length&&n.deleted;n=t[1+ ++e])i+=n.length;r.push(new ke(s,i))}}r.length>0&&e.clients.set(n,r)})),e},xe=(t,e)=>{Nt(t.restEncoder,e.clients.size),x(e.clients.entries()).sort(((t,e)=>e[0]-t[0])).forEach((([e,n])=>{t.resetDsCurVal(),Nt(t.restEncoder,e);const r=n.length;Nt(t.restEncoder,r);for(let e=0;e<r;e++){const r=n[e];t.writeDsClock(r.clock),t.writeDsLen(r.len)}}))},Ae=t=>{const e=new ve,n=bt(t.restDecoder);for(let r=0;r<n;r++){t.resetDsCurVal();const n=bt(t.restDecoder),r=bt(t.restDecoder);if(r>0){const s=C(e.clients,n,(()=>[]));for(let e=0;e<r;e++)s.push(new ke(t.readDsClock(),t.readDsLen()))}}return e},Ie=(t,e,n)=>{const r=new ve,s=bt(t.restDecoder);for(let i=0;i<s;i++){t.resetDsCurVal();const s=bt(t.restDecoder),i=bt(t.restDecoder),o=n.clients.get(s)||[],c=on(n,s);for(let n=0;n<i;n++){const n=t.readDsClock(),i=n+t.readDsLen();if(n<c){c<i&&De(r,s,c,i-c);let t=ln(o,n),l=o[t];for(!l.deleted&&l.id.clock<n&&(o.splice(t+1,0,zr(e,l,n-l.id.clock)),t++);t<o.length&&(l=o[t++],l.id.clock<i);)l.deleted||(i<l.id.clock+l.length&&o.splice(t,0,zr(e,l,i-l.id.clock)),l.delete(e))}else De(r,s,n,i-n)}}if(r.clients.size>0){const t=new Ke;return Nt(t.restEncoder,0),xe(t,r),t.toUint8Array()}return null},Me=te;class Le extends I{constructor({guid:t=ne(),collectionid:e=null,gc:n=!0,gcFilter:r=(()=>!0),meta:s=null,autoLoad:i=!1,shouldLoad:o=!0}={}){super(),this.gc=n,this.gcFilter=r,this.clientID=Me(),this.guid=t,this.collectionid=e,this.share=new Map,this.store=new rn,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=o,this.autoLoad=i,this.meta=s,this.isLoaded=!1,this.isSynced=!1,this.whenLoaded=re((t=>{this.on("load",(()=>{this.isLoaded=!0,t(this)}))}));const c=()=>re((t=>{const e=n=>{void 0!==n&&!0!==n||(this.off("sync",e),t())};this.on("sync",e)}));this.on("sync",(t=>{!1===t&&this.isSynced&&(this.whenSynced=c()),this.isSynced=void 0===t||!0===t,this.isLoaded||this.emit("load",[])})),this.whenSynced=c()}load(){const t=this._item;null===t||this.shouldLoad||_n(t.parent.doc,(t=>{t.subdocsLoaded.add(this)}),null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(x(this.subdocs).map((t=>t.guid)))}transact(t,e=null){return _n(this,t,e)}get(t,e=Vn){const n=C(this.share,t,(()=>{const t=new e;return t._integrate(this,null),t})),r=n.constructor;if(e!==Vn&&r!==e){if(r===Vn){const r=new e;r._map=n._map,n._map.forEach((t=>{for(;null!==t;t=t.left)t.parent=r})),r._start=n._start;for(let t=r._start;null!==t;t=t.right)t.parent=r;return r._length=n._length,this.share.set(t,r),r._integrate(this,null),r}throw new Error(`Type with the name ${t} has already been defined with a different constructor`)}return n}getArray(t=""){return this.get(t,rr)}getText(t=""){return this.get(t,kr)}getMap(t=""){return this.get(t,ir)}getXmlFragment(t=""){return this.get(t,Sr)}toJSON(){const t={};return this.share.forEach(((e,n)=>{t[n]=e.toJSON()})),t}destroy(){x(this.subdocs).forEach((t=>t.destroy()));const t=this._item;if(null!==t){this._item=null;const e=t.content;e.doc=new Le({guid:this.guid,...e.opts,shouldLoad:!1}),e.doc._item=t,_n(t.parent.doc,(n=>{const r=e.doc;t.deleted||n.subdocsAdded.add(r),n.subdocsRemoved.add(this)}),null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}on(t,e){super.on(t,e)}off(t,e){super.off(t,e)}}class Re{constructor(t){this.restDecoder=t}resetDsCurVal(){}readDsClock(){return bt(this.restDecoder)}readDsLen(){return bt(this.restDecoder)}}class je extends Re{readLeftID(){return tn(bt(this.restDecoder),bt(this.restDecoder))}readRightID(){return tn(bt(this.restDecoder),bt(this.restDecoder))}readClient(){return bt(this.restDecoder)}readInfo(){return _t(this.restDecoder)}readString(){return vt(this.restDecoder)}readParentInfo(){return 1===bt(this.restDecoder)}readTypeRef(){return bt(this.restDecoder)}readLen(){return bt(this.restDecoder)}readAny(){return Et(this.restDecoder)}readBuf(){return Mt(yt(this.restDecoder))}readJSON(){return JSON.parse(vt(this.restDecoder))}readKey(){return vt(this.restDecoder)}}class Pe{constructor(t){this.dsCurrVal=0,this.restDecoder=t}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=bt(this.restDecoder),this.dsCurrVal}readDsLen(){const t=bt(this.restDecoder)+1;return this.dsCurrVal+=t,t}}class Ue extends Pe{constructor(t){super(t),this.keys=[],bt(t),this.keyClockDecoder=new xt(yt(t)),this.clientDecoder=new Ot(yt(t)),this.leftClockDecoder=new xt(yt(t)),this.rightClockDecoder=new xt(yt(t)),this.infoDecoder=new Dt(yt(t),_t),this.stringDecoder=new At(yt(t)),this.parentInfoDecoder=new Dt(yt(t),_t),this.typeRefDecoder=new Ot(yt(t)),this.lenDecoder=new Ot(yt(t))}readLeftID(){return new Qe(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Qe(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return 1===this.parentInfoDecoder.read()}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return Et(this.restDecoder)}readBuf(){return yt(this.restDecoder)}readJSON(){return Et(this.restDecoder)}readKey(){const t=this.keyClockDecoder.read();if(t<this.keys.length)return this.keys[t];{const t=this.stringDecoder.read();return this.keys.push(t),t}}}class Ne{constructor(){this.restEncoder=Rt()}toUint8Array(){return jt(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){Nt(this.restEncoder,t)}writeDsLen(t){Nt(this.restEncoder,t)}}class Te extends Ne{writeLeftID(t){Nt(this.restEncoder,t.client),Nt(this.restEncoder,t.clock)}writeRightID(t){Nt(this.restEncoder,t.client),Nt(this.restEncoder,t.clock)}writeClient(t){Nt(this.restEncoder,t)}writeInfo(t){Ut(this.restEncoder,t)}writeString(t){Ft(this.restEncoder,t)}writeParentInfo(t){Nt(this.restEncoder,t?1:0)}writeTypeRef(t){Nt(this.restEncoder,t)}writeLen(t){Nt(this.restEncoder,t)}writeAny(t){Jt(this.restEncoder,t)}writeBuf(t){Wt(this.restEncoder,t)}writeJSON(t){Ft(this.restEncoder,JSON.stringify(t))}writeKey(t){Ft(this.restEncoder,t)}}class Ve{constructor(){this.restEncoder=Rt(),this.dsCurrVal=0}toUint8Array(){return jt(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){const e=t-this.dsCurrVal;this.dsCurrVal=t,Nt(this.restEncoder,e)}writeDsLen(t){0===t&&ft(),Nt(this.restEncoder,t-1),this.dsCurrVal+=t}}class Ke extends Ve{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Xt,this.clientEncoder=new Gt,this.leftClockEncoder=new Xt,this.rightClockEncoder=new Xt,this.infoEncoder=new qt(Ut),this.stringEncoder=new Qt,this.parentInfoEncoder=new qt(Ut),this.typeRefEncoder=new Gt,this.lenEncoder=new Gt}toUint8Array(){const t=Rt();return Nt(t,0),Wt(t,this.keyClockEncoder.toUint8Array()),Wt(t,this.clientEncoder.toUint8Array()),Wt(t,this.leftClockEncoder.toUint8Array()),Wt(t,this.rightClockEncoder.toUint8Array()),Wt(t,jt(this.infoEncoder)),Wt(t,this.stringEncoder.toUint8Array()),Wt(t,jt(this.parentInfoEncoder)),Wt(t,this.typeRefEncoder.toUint8Array()),Wt(t,this.lenEncoder.toUint8Array()),$t(t,jt(this.restEncoder)),jt(t)}writeLeftID(t){this.clientEncoder.write(t.client),this.leftClockEncoder.write(t.clock)}writeRightID(t){this.clientEncoder.write(t.client),this.rightClockEncoder.write(t.clock)}writeClient(t){this.clientEncoder.write(t)}writeInfo(t){this.infoEncoder.write(t)}writeString(t){this.stringEncoder.write(t)}writeParentInfo(t){this.parentInfoEncoder.write(t?1:0)}writeTypeRef(t){this.typeRefEncoder.write(t)}writeLen(t){this.lenEncoder.write(t)}writeAny(t){Jt(this.restEncoder,t)}writeBuf(t){Wt(this.restEncoder,t)}writeJSON(t){Jt(this.restEncoder,t)}writeKey(t){const e=this.keyMap.get(t);void 0===e?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(t)):this.keyClockEncoder.write(e)}}const Fe=(t,e,n)=>{const r=new Map;n.forEach(((t,n)=>{on(e,n)>t&&r.set(n,t)})),sn(e).forEach(((t,e)=>{n.has(e)||r.set(e,0)})),Nt(t.restEncoder,r.size),x(r.entries()).sort(((t,e)=>e[0]-t[0])).forEach((([n,r])=>{((t,e,n,r)=>{r=j(r,e[0].id.clock);const s=ln(e,r);Nt(t.restEncoder,e.length-s),t.writeClient(n),Nt(t.restEncoder,r);const i=e[s];i.write(t,r-i.id.clock);for(let n=s+1;n<e.length;n++)e[n].write(t,0)})(t,e.clients.get(n),n,r)}))},$e=(t,e,n,r=new Ue(t))=>_n(e,(t=>{t.local=!1;let e=!1;const n=t.doc,s=n.store,i=((t,e)=>{const n=v(),r=bt(t.restDecoder);for(let s=0;s<r;s++){const r=bt(t.restDecoder),s=new Array(r),i=t.readClient();let o=bt(t.restDecoder);n.set(i,{i:0,refs:s});for(let n=0;n<r;n++){const r=t.readInfo();switch(31&r){case 0:{const e=t.readLen();s[n]=new Ar(tn(i,o),e),o+=e;break}case 10:{const e=bt(t.restDecoder);s[n]=new Qr(tn(i,o),e),o+=e;break}default:{const c=0==(192&r),l=new Gr(tn(i,o),null,(r&ct)===ct?t.readLeftID():null,null,(r&ot)===ot?t.readRightID():null,c?t.readParentInfo()?e.get(t.readString()):t.readLeftID():null,c&&32==(32&r)?t.readString():null,Yr(t,r));s[n]=l,o+=l.length}}}}return n})(r,n),o=((t,e,n)=>{const r=[];let s=x(n.keys()).sort(((t,e)=>t-e));if(0===s.length)return null;const i=()=>{if(0===s.length)return null;let t=n.get(s[s.length-1]);for(;t.refs.length===t.i;){if(s.pop(),!(s.length>0))return null;t=n.get(s[s.length-1])}return t};let o=i();if(null===o&&0===r.length)return null;const c=new rn,l=new Map,h=(t,e)=>{const n=l.get(t);(null==n||n>e)&&l.set(t,e)};let a=o.refs[o.i++];const u=new Map,d=()=>{for(const t of r){const e=t.id.client,r=n.get(e);r?(r.i--,c.clients.set(e,r.refs.slice(r.i)),n.delete(e),r.i=0,r.refs=[]):c.clients.set(e,[t]),s=s.filter((t=>t!==e))}r.length=0};for(;;){if(a.constructor!==Qr){const s=C(u,a.id.client,(()=>on(e,a.id.client)))-a.id.clock;if(s<0)r.push(a),h(a.id.client,a.id.clock-1),d();else{const i=a.getMissing(t,e);if(null!==i){r.push(a);const t=n.get(i)||{refs:[],i:0};if(t.refs.length!==t.i){a=t.refs[t.i++];continue}h(i,on(e,i)),d()}else(0===s||s<a.length)&&(a.integrate(t,s),u.set(a.id.client,a.id.clock+a.length))}}if(r.length>0)a=r.pop();else if(null!==o&&o.i<o.refs.length)a=o.refs[o.i++];else{if(o=i(),null===o)break;a=o.refs[o.i++]}}if(c.clients.size>0){const t=new Ke;return Fe(t,c,new Map),Nt(t.restEncoder,0),{missing:l,update:t.toUint8Array()}}return null})(t,s,i),c=s.pendingStructs;if(c){for(const[t,n]of c.missing)if(n<on(s,t)){e=!0;break}if(o){for(const[t,e]of o.missing){const n=c.missing.get(t);(null==n||n>e)&&c.missing.set(t,e)}c.update=Cn([c.update,o.update])}}else s.pendingStructs=o;const l=Ie(r,t,s);if(s.pendingDs){const e=new Ue(mt(s.pendingDs));bt(e.restDecoder);const n=Ie(e,t,s);s.pendingDs=l&&n?Cn([l,n]):l||n}else s.pendingDs=l;if(e){const e=s.pendingStructs.update;s.pendingStructs=null,We(t.doc,e)}}),n,!1),We=(t,e,n,r=Ue)=>{const s=mt(e);$e(s,t,n,new r(s))},Be=(t,e,n)=>We(t,e,n,je),He=(t,e=new Uint8Array([0]),n=new Ke)=>{((t,e,n=new Map)=>{Fe(t,e.store,n),xe(t,Oe(e.store))})(n,t,Je(e));const r=[n.toUint8Array()];if(t.store.pendingDs&&r.push(t.store.pendingDs),t.store.pendingStructs&&r.push(En(t.store.pendingStructs.update,e)),r.length>1){if(n.constructor===Te)return vn(r.map(((t,e)=>0===e?t:An(t))));if(n.constructor===Ke)return Cn(r)}return r[0]},Je=t=>(t=>{const e=new Map,n=bt(t.restDecoder);for(let r=0;r<n;r++){const n=bt(t.restDecoder),r=bt(t.restDecoder);e.set(n,r)}return e})(new Re(mt(t)));class qe{constructor(){this.l=[]}}const ze=()=>new qe,Ge=(t,e)=>t.l.push(e),Ye=(t,e)=>{const n=t.l,r=n.length;t.l=n.filter((t=>e!==t)),r===t.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},Xe=(t,e,n)=>Y(t.l,[e,n]);class Qe{constructor(t,e){this.client=t,this.clock=e}}const Ze=(t,e)=>t===e||null!==t&&null!==e&&t.client===e.client&&t.clock===e.clock,tn=(t,e)=>new Qe(t,e),en=(t,e)=>void 0===e?!t.deleted:e.sv.has(t.id.client)&&(e.sv.get(t.id.client)||0)>t.id.clock&&!Ce(e.ds,t.id),nn=(t,e)=>{const n=C(t.meta,nn,E),r=t.doc.store;n.has(e)||(e.sv.forEach(((e,n)=>{e<on(r,n)&&un(t,tn(n,e))})),Se(t,e.ds,(t=>{})),n.add(e))};class rn{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const sn=t=>{const e=new Map;return t.clients.forEach(((t,n)=>{const r=t[t.length-1];e.set(n,r.id.clock+r.length)})),e},on=(t,e)=>{const n=t.clients.get(e);if(void 0===n)return 0;const r=n[n.length-1];return r.id.clock+r.length},cn=(t,e)=>{let n=t.clients.get(e.id.client);if(void 0===n)n=[],t.clients.set(e.id.client,n);else{const t=n[n.length-1];if(t.id.clock+t.length!==e.id.clock)throw ft()}n.push(e)},ln=(t,e)=>{let n=0,r=t.length-1,s=t[r],i=s.id.clock;if(i===e)return r;let o=M(e/(i+s.length-1)*r);for(;n<=r;){if(s=t[o],i=s.id.clock,i<=e){if(e<i+s.length)return o;n=o+1}else r=o-1;o=M((n+r)/2)}throw ft()},hn=(t,e)=>{const n=t.clients.get(e.client);return n[ln(n,e.clock)]},an=(t,e,n)=>{const r=ln(e,n),s=e[r];return s.id.clock<n&&s instanceof Gr?(e.splice(r+1,0,zr(t,s,n-s.id.clock)),r+1):r},un=(t,e)=>{const n=t.doc.store.clients.get(e.client);return n[an(t,n,e.clock)]},dn=(t,e,n)=>{const r=e.clients.get(n.client),s=ln(r,n.clock),i=r[s];return n.clock!==i.id.clock+i.length-1&&i.constructor!==Ar&&r.splice(s+1,0,zr(t,i,n.clock-i.id.clock+1)),i},fn=(t,e,n,r,s)=>{if(0===r)return;const i=n+r;let o,c=an(t,e,n);do{o=e[c++],i<o.id.clock+o.length&&an(t,e,i),s(o)}while(c<e.length&&e[c].id.clock<i)};class gn{constructor(t,e,n){this.doc=t,this.deleteSet=new ve,this.beforeState=sn(t.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=e,this.meta=new Map,this.local=n,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}}const pn=(t,e)=>!(0===e.deleteSet.clients.size&&!((t,e)=>{for(const[n,r]of t)if(e(r,n))return!0;return!1})(e.afterState,((t,n)=>e.beforeState.get(n)!==t)))&&(Ee(e.deleteSet),((t,e)=>{Fe(t,e.doc.store,e.beforeState)})(t,e),xe(t,e.deleteSet),!0),wn=(t,e,n)=>{const r=e._item;(null===r||r.id.clock<(t.beforeState.get(r.id.client)||0)&&!r.deleted)&&C(t.changed,e,E).add(n)},mn=(t,e)=>{let n=t[e],r=t[e-1],s=e;for(;s>0&&(r.deleted===n.deleted&&r.constructor===n.constructor&&r.mergeWith(n));n=r,r=t[--s-1])n instanceof Gr&&null!==n.parentSub&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,r);const i=e-s;return i&&t.splice(e+1-i,i),i},yn=(t,e)=>{if(e<t.length){const n=t[e],r=n.doc,s=r.store,i=n.deleteSet,o=n._mergeStructs;try{Ee(i),n.afterState=sn(n.doc.store),r.emit("beforeObserverCalls",[n,r]);const t=[];n.changed.forEach(((e,r)=>t.push((()=>{null!==r._item&&r._item.deleted||r._callObserver(n,e)})))),t.push((()=>{n.changedParentTypes.forEach(((t,e)=>{e._dEH.l.length>0&&(null===e._item||!e._item.deleted)&&((t=t.filter((t=>null===t.target._item||!t.target._item.deleted))).forEach((t=>{t.currentTarget=e,t._path=null})),t.sort(((t,e)=>t.path.length-e.path.length)),Xe(e._dEH,t,n))}))})),t.push((()=>r.emit("afterTransaction",[n,r]))),Y(t,[]),n._needFormattingCleanup&&yr(n)}finally{r.gc&&((t,e,n)=>{for(const[r,s]of t.clients.entries()){const t=e.clients.get(r);for(let r=s.length-1;r>=0;r--){const i=s[r],o=i.clock+i.len;for(let r=ln(t,i.clock),s=t[r];r<t.length&&s.id.clock<o;s=t[++r]){const s=t[r];if(i.clock+i.len<=s.id.clock)break;s instanceof Gr&&s.deleted&&!s.keep&&n(s)&&s.gc(e,!1)}}}})(i,s,r.gcFilter),((t,e)=>{t.clients.forEach(((t,n)=>{const r=e.clients.get(n);for(let e=t.length-1;e>=0;e--){const n=t[e];for(let t=R(r.length-1,1+ln(r,n.clock+n.len-1)),e=r[t];t>0&&e.id.clock>=n.clock;e=r[t])t-=1+mn(r,t)}}))})(i,s),n.afterState.forEach(((t,e)=>{const r=n.beforeState.get(e)||0;if(r!==t){const t=s.clients.get(e),n=j(ln(t,r),1);for(let e=t.length-1;e>=n;)e-=1+mn(t,e)}}));for(let t=o.length-1;t>=0;t--){const{client:e,clock:n}=o[t].id,r=s.clients.get(e),i=ln(r,n);i+1<r.length&&mn(r,i+1)>1||i>0&&mn(r,i)}if(n.local||n.afterState.get(r.clientID)===n.beforeState.get(r.clientID)||(((...t)=>{console.log(...me(t)),ye.forEach((e=>e.print(t)))})(ge,ce,"[yjs] ",le,de,"Changed the client-id because another client seems to be using it."),r.clientID=Me()),r.emit("afterTransactionCleanup",[n,r]),r._observers.has("update")){const t=new Te;pn(t,n)&&r.emit("update",[t.toUint8Array(),n.origin,r,n])}if(r._observers.has("updateV2")){const t=new Ke;pn(t,n)&&r.emit("updateV2",[t.toUint8Array(),n.origin,r,n])}const{subdocsAdded:c,subdocsLoaded:l,subdocsRemoved:h}=n;(c.size>0||h.size>0||l.size>0)&&(c.forEach((t=>{t.clientID=r.clientID,null==t.collectionid&&(t.collectionid=r.collectionid),r.subdocs.add(t)})),h.forEach((t=>r.subdocs.delete(t))),r.emit("subdocs",[{loaded:l,added:c,removed:h},r,n]),h.forEach((t=>t.destroy()))),t.length<=e+1?(r._transactionCleanups=[],r.emit("afterAllTransactions",[r,t])):yn(t,e+1)}}},_n=(t,e,n=null,r=!0)=>{const s=t._transactionCleanups;let i=!1,o=null;null===t._transaction&&(i=!0,t._transaction=new gn(t,n,r),s.push(t._transaction),1===s.length&&t.emit("beforeAllTransactions",[t]),t.emit("beforeTransaction",[t._transaction,t]));try{o=e(t._transaction)}finally{if(i){const e=t._transaction===s[0];t._transaction=null,e&&yn(s,0)}}return o};class bn{constructor(t,e){this.gen=function*(t){const e=bt(t.restDecoder);for(let n=0;n<e;n++){const e=bt(t.restDecoder),n=t.readClient();let r=bt(t.restDecoder);for(let s=0;s<e;s++){const e=t.readInfo();if(10===e){const e=bt(t.restDecoder);yield new Qr(tn(n,r),e),r+=e}else if(0!=(31&e)){const s=0==(192&e),i=new Gr(tn(n,r),null,(e&ct)===ct?t.readLeftID():null,null,(e&ot)===ot?t.readRightID():null,s?t.readParentInfo()?t.readString():t.readLeftID():null,s&&32==(32&e)?t.readString():null,Yr(t,e));yield i,r+=i.length}else{const e=t.readLen();yield new Ar(tn(n,r),e),r+=e}}}}(t),this.curr=null,this.done=!1,this.filterSkips=e,this.next()}next(){do{this.curr=this.gen.next().value||null}while(this.filterSkips&&null!==this.curr&&this.curr.constructor===Qr);return this.curr}}class kn{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}}const vn=t=>Cn(t,je,Te),Sn=(t,e)=>{if(t.constructor===Ar){const{client:n,clock:r}=t.id;return new Ar(tn(n,r+e),t.length-e)}if(t.constructor===Qr){const{client:n,clock:r}=t.id;return new Qr(tn(n,r+e),t.length-e)}{const n=t,{client:r,clock:s}=n.id;return new Gr(tn(r,s+e),null,tn(r,s+e-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(e))}},Cn=(t,e=Ue,n=Ke)=>{if(1===t.length)return t[0];const r=t.map((t=>new e(mt(t))));let s=r.map((t=>new bn(t,!0))),i=null;const o=new n,c=new kn(o);for(;s=s.filter((t=>null!==t.curr)),s.sort(((t,e)=>{if(t.curr.id.client===e.curr.id.client){const n=t.curr.id.clock-e.curr.id.clock;return 0===n?t.curr.constructor===e.curr.constructor?0:t.curr.constructor===Qr?1:-1:n}return e.curr.id.client-t.curr.id.client})),0!==s.length;){const t=s[0],e=t.curr.id.client;if(null!==i){let n=t.curr,r=!1;for(;null!==n&&n.id.clock+n.length<=i.struct.id.clock+i.struct.length&&n.id.client>=i.struct.id.client;)n=t.next(),r=!0;if(null===n||n.id.client!==e||r&&n.id.clock>i.struct.id.clock+i.struct.length)continue;if(e!==i.struct.id.client)On(c,i.struct,i.offset),i={struct:n,offset:0},t.next();else if(i.struct.id.clock+i.struct.length<n.id.clock)if(i.struct.constructor===Qr)i.struct.length=n.id.clock+n.length-i.struct.id.clock;else{On(c,i.struct,i.offset);const t=n.id.clock-i.struct.id.clock-i.struct.length;i={struct:new Qr(tn(e,i.struct.id.clock+i.struct.length),t),offset:0}}else{const e=i.struct.id.clock+i.struct.length-n.id.clock;e>0&&(i.struct.constructor===Qr?i.struct.length-=e:n=Sn(n,e)),i.struct.mergeWith(n)||(On(c,i.struct,i.offset),i={struct:n,offset:0},t.next())}}else i={struct:t.curr,offset:0},t.next();for(let n=t.curr;null!==n&&n.id.client===e&&n.id.clock===i.struct.id.clock+i.struct.length&&n.constructor!==Qr;n=t.next())On(c,i.struct,i.offset),i={struct:n,offset:0}}null!==i&&(On(c,i.struct,i.offset),i=null),xn(c);const l=(t=>{const e=new ve;for(let n=0;n<t.length;n++)t[n].clients.forEach(((r,s)=>{if(!e.clients.has(s)){const i=r.slice();for(let e=n+1;e<t.length;e++)O(i,t[e].clients.get(s)||[]);e.clients.set(s,i)}}));return Ee(e),e})(r.map((t=>Ae(t))));return xe(o,l),o.toUint8Array()},En=(t,e,n=Ue,r=Ke)=>{const s=Je(e),i=new r,o=new kn(i),c=new n(mt(t)),l=new bn(c,!1);for(;l.curr;){const t=l.curr,e=t.id.client,n=s.get(e)||0;if(l.curr.constructor!==Qr)if(t.id.clock+t.length>n)for(On(o,t,j(n-t.id.clock,0)),l.next();l.curr&&l.curr.id.client===e;)On(o,l.curr,0),l.next();else for(;l.curr&&l.curr.id.client===e&&l.curr.id.clock+l.curr.length<=n;)l.next();else l.next()}xn(o);const h=Ae(c);return xe(i,h),i.toUint8Array()},Dn=t=>{t.written>0&&(t.clientStructs.push({written:t.written,restEncoder:jt(t.encoder.restEncoder)}),t.encoder.restEncoder=Rt(),t.written=0)},On=(t,e,n)=>{t.written>0&&t.currClient!==e.id.client&&Dn(t),0===t.written&&(t.currClient=e.id.client,t.encoder.writeClient(e.id.client),Nt(t.encoder.restEncoder,e.id.clock+n)),e.write(t.encoder,n),t.written++},xn=t=>{Dn(t);const e=t.encoder.restEncoder;Nt(e,t.clientStructs.length);for(let n=0;n<t.clientStructs.length;n++){const r=t.clientStructs[n];Nt(e,r.written),$t(e,r.restEncoder)}},An=t=>((t,e,n,r)=>{const s=new n(mt(t)),i=new bn(s,!1),o=new r,c=new kn(o);for(let t=i.curr;null!==t;t=i.next())On(c,e(t),0);xn(c);const l=Ae(s);return xe(o,l),o.toUint8Array()})(t,X,Ue,Te),In="You must not compute changes after the event-handler fired.";class Mn{constructor(t,e){this.target=t,this.currentTarget=t,this.transaction=e,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=Ln(this.currentTarget,this.target))}deletes(t){return Ce(this.transaction.deleteSet,t.id)}get keys(){if(null===this._keys){if(0===this.transaction.doc._transactionCleanups.length)throw ut(In);const t=new Map,e=this.target;this.transaction.changed.get(e).forEach((n=>{if(null!==n){const r=e._map.get(n);let s,i;if(this.adds(r)){let t=r.left;for(;null!==t&&this.adds(t);)t=t.left;if(this.deletes(r)){if(null===t||!this.deletes(t))return;s="delete",i=D(t.content.getContent())}else null!==t&&this.deletes(t)?(s="update",i=D(t.content.getContent())):(s="add",i=void 0)}else{if(!this.deletes(r))return;s="delete",i=D(r.content.getContent())}t.set(n,{action:s,oldValue:i})}})),this._keys=t}return this._keys}get delta(){return this.changes.delta}adds(t){return t.id.clock>=(this.transaction.beforeState.get(t.id.client)||0)}get changes(){let t=this._changes;if(null===t){if(0===this.transaction.doc._transactionCleanups.length)throw ut(In);const e=this.target,n=E(),r=E(),s=[];t={added:n,deleted:r,delta:s,keys:this.keys};if(this.transaction.changed.get(e).has(null)){let t=null;const i=()=>{t&&s.push(t)};for(let s=e._start;null!==s;s=s.right)s.deleted?this.deletes(s)&&!this.adds(s)&&(null!==t&&void 0!==t.delete||(i(),t={delete:0}),t.delete+=s.length,r.add(s)):this.adds(s)?(null!==t&&void 0!==t.insert||(i(),t={insert:[]}),t.insert=t.insert.concat(s.content.getContent()),n.add(s)):(null!==t&&void 0!==t.retain||(i(),t={retain:0}),t.retain+=s.length);null!==t&&void 0===t.retain&&i()}this._changes=t}return t}}const Ln=(t,e)=>{const n=[];for(;null!==e._item&&e!==t;){if(null!==e._item.parentSub)n.unshift(e._item.parentSub);else{let t=0,r=e._item.parent._start;for(;r!==e._item&&null!==r;)r.deleted||t++,r=r.right;n.unshift(t)}e=e._item.parent}return n};let Rn=0;class jn{constructor(t,e){t.marker=!0,this.p=t,this.index=e,this.timestamp=Rn++}}const Pn=(t,e,n)=>{t.p.marker=!1,t.p=e,e.marker=!0,t.index=n,t.timestamp=Rn++},Un=(t,e)=>{if(null===t._start||0===e||null===t._searchMarker)return null;const n=0===t._searchMarker.length?null:t._searchMarker.reduce(((t,n)=>L(e-t.index)<L(e-n.index)?t:n));let r=t._start,s=0;for(null!==n&&(r=n.p,s=n.index,(t=>{t.timestamp=Rn++})(n));null!==r.right&&s<e;){if(!r.deleted&&r.countable){if(e<s+r.length)break;s+=r.length}r=r.right}for(;null!==r.left&&s>e;)r=r.left,!r.deleted&&r.countable&&(s-=r.length);for(;null!==r.left&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(s-=r.length);return null!==n&&L(n.index-s)<r.parent.length/80?(Pn(n,r,s),n):((t,e,n)=>{if(t.length>=80){const r=t.reduce(((t,e)=>t.timestamp<e.timestamp?t:e));return Pn(r,e,n),r}{const r=new jn(e,n);return t.push(r),r}})(t._searchMarker,r,s)},Nn=(t,e,n)=>{for(let r=t.length-1;r>=0;r--){const s=t[r];if(n>0){let e=s.p;for(e.marker=!1;e&&(e.deleted||!e.countable);)e=e.left,e&&!e.deleted&&e.countable&&(s.index-=e.length);if(null===e||!0===e.marker){t.splice(r,1);continue}s.p=e,e.marker=!0}(e<s.index||n>0&&e===s.index)&&(s.index=j(e,s.index+n))}},Tn=(t,e,n)=>{const r=t,s=e.changedParentTypes;for(;C(s,t,(()=>[])).push(n),null!==t._item;)t=t._item.parent;Xe(r._eH,n,e)};class Vn{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=ze(),this._dEH=ze(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,e){this.doc=t,this._item=e}_copy(){throw dt()}clone(){throw dt()}_write(t){}get _first(){let t=this._start;for(;null!==t&&t.deleted;)t=t.right;return t}_callObserver(t,e){!t.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(t){Ge(this._eH,t)}observeDeep(t){Ge(this._dEH,t)}unobserve(t){Ye(this._eH,t)}unobserveDeep(t){Ye(this._dEH,t)}toJSON(){}}const Kn=(t,e,n)=>{e<0&&(e=t._length+e),n<0&&(n=t._length+n);let r=n-e;const s=[];let i=t._start;for(;null!==i&&r>0;){if(i.countable&&!i.deleted){const t=i.content.getContent();if(t.length<=e)e-=t.length;else{for(let n=e;n<t.length&&r>0;n++)s.push(t[n]),r--;e=0}}i=i.right}return s},Fn=t=>{const e=[];let n=t._start;for(;null!==n;){if(n.countable&&!n.deleted){const t=n.content.getContent();for(let n=0;n<t.length;n++)e.push(t[n])}n=n.right}return e},$n=(t,e)=>{let n=0,r=t._start;for(;null!==r;){if(r.countable&&!r.deleted){const s=r.content.getContent();for(let r=0;r<s.length;r++)e(s[r],n++,t)}r=r.right}},Wn=(t,e)=>{const n=[];return $n(t,((r,s)=>{n.push(e(r,s,t))})),n},Bn=t=>{let e=t._start,n=null,r=0;return{[Symbol.iterator](){return this},next:()=>{if(null===n){for(;null!==e&&e.deleted;)e=e.right;if(null===e)return{done:!0,value:void 0};n=e.content.getContent(),r=0,e=e.right}const t=n[r++];return n.length<=r&&(n=null),{done:!1,value:t}}}},Hn=(t,e)=>{const n=Un(t,e);let r=t._start;for(null!==n&&(r=n.p,e-=n.index);null!==r;r=r.right)if(!r.deleted&&r.countable){if(e<r.length)return r.content.getContent()[e];e-=r.length}},Jn=(t,e,n,r)=>{let s=n;const i=t.doc,o=i.clientID,c=i.store,l=null===n?e._start:n.right;let h=[];const a=()=>{h.length>0&&(s=new Gr(tn(o,on(c,o)),s,s&&s.lastId,l,l&&l.id,e,null,new Nr(h)),s.integrate(t,0),h=[])};r.forEach((n=>{if(null===n)h.push(n);else switch(n.constructor){case Number:case Object:case Boolean:case Array:case String:h.push(n);break;default:switch(a(),n.constructor){case Uint8Array:case ArrayBuffer:s=new Gr(tn(o,on(c,o)),s,s&&s.lastId,l,l&&l.id,e,null,new Ir(new Uint8Array(n))),s.integrate(t,0);break;case Le:s=new Gr(tn(o,on(c,o)),s,s&&s.lastId,l,l&&l.id,e,null,new Rr(n)),s.integrate(t,0);break;default:if(!(n instanceof Vn))throw new Error("Unexpected content type in insert operation");s=new Gr(tn(o,on(c,o)),s,s&&s.lastId,l,l&&l.id,e,null,new qr(n)),s.integrate(t,0)}}})),a()},qn=ut("Length exceeded!"),zn=(t,e,n,r)=>{if(n>e._length)throw qn;if(0===n)return e._searchMarker&&Nn(e._searchMarker,n,r.length),Jn(t,e,null,r);const s=n,i=Un(e,n);let o=e._start;for(null!==i&&(o=i.p,0===(n-=i.index)&&(o=o.prev,n+=o&&o.countable&&!o.deleted?o.length:0));null!==o;o=o.right)if(!o.deleted&&o.countable){if(n<=o.length){n<o.length&&un(t,tn(o.id.client,o.id.clock+n));break}n-=o.length}return e._searchMarker&&Nn(e._searchMarker,s,r.length),Jn(t,e,o,r)},Gn=(t,e,n,r)=>{if(0===r)return;const s=n,i=r,o=Un(e,n);let c=e._start;for(null!==o&&(c=o.p,n-=o.index);null!==c&&n>0;c=c.right)!c.deleted&&c.countable&&(n<c.length&&un(t,tn(c.id.client,c.id.clock+n)),n-=c.length);for(;r>0&&null!==c;)c.deleted||(r<c.length&&un(t,tn(c.id.client,c.id.clock+r)),c.delete(t),r-=c.length),c=c.right;if(r>0)throw qn;e._searchMarker&&Nn(e._searchMarker,s,-i+r)},Yn=(t,e,n)=>{const r=e._map.get(n);void 0!==r&&r.delete(t)},Xn=(t,e,n,r)=>{const s=e._map.get(n)||null,i=t.doc,o=i.clientID;let c;if(null==r)c=new Nr([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:c=new Nr([r]);break;case Uint8Array:c=new Ir(r);break;case Le:c=new Rr(r);break;default:if(!(r instanceof Vn))throw new Error("Unexpected content type");c=new qr(r)}new Gr(tn(o,on(i.store,o)),s,s&&s.lastId,null,null,e,n,c).integrate(t,0)},Qn=(t,e)=>{const n=t._map.get(e);return void 0===n||n.deleted?void 0:n.content.getContent()[n.length-1]},Zn=t=>{const e={};return t._map.forEach(((t,n)=>{t.deleted||(e[n]=t.content.getContent()[t.length-1])})),e},tr=(t,e)=>{const n=t._map.get(e);return void 0!==n&&!n.deleted},er=t=>{return e=t.entries(),n=t=>!t[1].deleted,_e((()=>{let t;do{t=e.next()}while(!t.done&&!n(t.value));return t}));var e,n};class nr extends Mn{constructor(t,e){super(t,e),this._transaction=e}}class rr extends Vn{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){const e=new rr;return e.push(t),e}_integrate(t,e){super._integrate(t,e),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new rr}clone(){const t=new rr;return t.insert(0,this.toArray().map((t=>t instanceof Vn?t.clone():t))),t}get length(){return null===this._prelimContent?this._length:this._prelimContent.length}_callObserver(t,e){super._callObserver(t,e),Tn(this,t,new nr(this,t))}insert(t,e){null!==this.doc?_n(this.doc,(n=>{zn(n,this,t,e)})):this._prelimContent.splice(t,0,...e)}push(t){null!==this.doc?_n(this.doc,(e=>{((t,e,n)=>{let r=(e._searchMarker||[]).reduce(((t,e)=>e.index>t.index?e:t),{index:0,p:e._start}).p;if(r)for(;r.right;)r=r.right;Jn(t,e,r,n)})(e,this,t)})):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,e=1){null!==this.doc?_n(this.doc,(n=>{Gn(n,this,t,e)})):this._prelimContent.splice(t,e)}get(t){return Hn(this,t)}toArray(){return Fn(this)}slice(t=0,e=this.length){return Kn(this,t,e)}toJSON(){return this.map((t=>t instanceof Vn?t.toJSON():t))}map(t){return Wn(this,t)}forEach(t){$n(this,t)}[Symbol.iterator](){return Bn(this)}_write(t){t.writeTypeRef(Kr)}}class sr extends Mn{constructor(t,e,n){super(t,e),this.keysChanged=n}}class ir extends Vn{constructor(t){super(),this._prelimContent=null,this._prelimContent=void 0===t?new Map:new Map(t)}_integrate(t,e){super._integrate(t,e),this._prelimContent.forEach(((t,e)=>{this.set(e,t)})),this._prelimContent=null}_copy(){return new ir}clone(){const t=new ir;return this.forEach(((e,n)=>{t.set(n,e instanceof Vn?e.clone():e)})),t}_callObserver(t,e){Tn(this,t,new sr(this,t,e))}toJSON(){const t={};return this._map.forEach(((e,n)=>{if(!e.deleted){const r=e.content.getContent()[e.length-1];t[n]=r instanceof Vn?r.toJSON():r}})),t}get size(){return[...er(this._map)].length}keys(){return be(er(this._map),(t=>t[0]))}values(){return be(er(this._map),(t=>t[1].content.getContent()[t[1].length-1]))}entries(){return be(er(this._map),(t=>[t[0],t[1].content.getContent()[t[1].length-1]]))}forEach(t){this._map.forEach(((e,n)=>{e.deleted||t(e.content.getContent()[e.length-1],n,this)}))}[Symbol.iterator](){return this.entries()}delete(t){null!==this.doc?_n(this.doc,(e=>{Yn(e,this,t)})):this._prelimContent.delete(t)}set(t,e){return null!==this.doc?_n(this.doc,(n=>{Xn(n,this,t,e)})):this._prelimContent.set(t,e),e}get(t){return Qn(this,t)}has(t){return tr(this,t)}clear(){null!==this.doc?_n(this.doc,(t=>{this.forEach((function(e,n,r){Yn(t,r,n)}))})):this._prelimContent.clear()}_write(t){t.writeTypeRef(Fr)}}const or=(t,e)=>t===e||"object"==typeof t&&"object"==typeof e&&t&&e&&G(t,e);class cr{constructor(t,e,n,r){this.left=t,this.right=e,this.index=n,this.currentAttributes=r}forward(){if(null===this.right&&ft(),this.right.content.constructor===Pr)this.right.deleted||ur(this.currentAttributes,this.right.content);else this.right.deleted||(this.index+=this.right.length);this.left=this.right,this.right=this.right.right}}const lr=(t,e,n)=>{for(;null!==e.right&&n>0;){if(e.right.content.constructor===Pr)e.right.deleted||ur(e.currentAttributes,e.right.content);else e.right.deleted||(n<e.right.length&&un(t,tn(e.right.id.client,e.right.id.clock+n)),e.index+=e.right.length,n-=e.right.length);e.left=e.right,e.right=e.right.right}return e},hr=(t,e,n)=>{const r=new Map,s=Un(e,n);if(s){const e=new cr(s.p.left,s.p,s.index,r);return lr(t,e,n-s.index)}{const s=new cr(null,e._start,0,r);return lr(t,s,n)}},ar=(t,e,n,r)=>{for(;null!==n.right&&(!0===n.right.deleted||n.right.content.constructor===Pr&&or(r.get(n.right.content.key),n.right.content.value));)n.right.deleted||r.delete(n.right.content.key),n.forward();const s=t.doc,i=s.clientID;r.forEach(((r,o)=>{const c=n.left,l=n.right,h=new Gr(tn(i,on(s.store,i)),c,c&&c.lastId,l,l&&l.id,e,null,new Pr(o,r));h.integrate(t,0),n.right=h,n.forward()}))},ur=(t,e)=>{const{key:n,value:r}=e;null===r?t.delete(n):t.set(n,r)},dr=(t,e)=>{for(;null!==t.right&&(t.right.deleted||t.right.content.constructor===Pr&&or(e[t.right.content.key]||null,t.right.content.value));)t.forward()},fr=(t,e,n,r)=>{const s=t.doc,i=s.clientID,o=new Map;for(const c in r){const l=r[c],h=n.currentAttributes.get(c)||null;if(!or(h,l)){o.set(c,h);const{left:r,right:a}=n;n.right=new Gr(tn(i,on(s.store,i)),r,r&&r.lastId,a,a&&a.id,e,null,new Pr(c,l)),n.right.integrate(t,0),n.forward()}}return o},gr=(t,e,n,r,s)=>{n.currentAttributes.forEach(((t,e)=>{void 0===s[e]&&(s[e]=null)}));const i=t.doc,o=i.clientID;dr(n,s);const c=fr(t,e,n,s),l=r.constructor===String?new Tr(r):r instanceof Vn?new qr(r):new jr(r);let{left:h,right:a,index:u}=n;e._searchMarker&&Nn(e._searchMarker,n.index,l.getLength()),a=new Gr(tn(o,on(i.store,o)),h,h&&h.lastId,a,a&&a.id,e,null,l),a.integrate(t,0),n.right=a,n.index=u,n.forward(),ar(t,e,n,c)},pr=(t,e,n,r,s)=>{const i=t.doc,o=i.clientID;dr(n,s);const c=fr(t,e,n,s);t:for(;null!==n.right&&(r>0||c.size>0&&(n.right.deleted||n.right.content.constructor===Pr));){if(!n.right.deleted)switch(n.right.content.constructor){case Pr:{const{key:e,value:i}=n.right.content,o=s[e];if(void 0!==o){if(or(o,i))c.delete(e);else{if(0===r)break t;c.set(e,i)}n.right.delete(t)}else n.currentAttributes.set(e,i);break}default:r<n.right.length&&un(t,tn(n.right.id.client,n.right.id.clock+r)),r-=n.right.length}n.forward()}if(r>0){let s="";for(;r>0;r--)s+="\n";n.right=new Gr(tn(o,on(i.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,e,null,new Tr(s)),n.right.integrate(t,0),n.forward()}ar(t,e,n,c)},wr=(t,e,n,r,s)=>{let i=e;const o=v();for(;i&&(!i.countable||i.deleted);){if(!i.deleted&&i.content.constructor===Pr){const t=i.content;o.set(t.key,t)}i=i.right}let c=0,l=!1;for(;e!==i;){if(n===e&&(l=!0),!e.deleted){const n=e.content;switch(n.constructor){case Pr:{const{key:i,value:h}=n,a=r.get(i)||null;o.get(i)===n&&a!==h||(e.delete(t),c++,l||(s.get(i)||null)!==h||a===h||(null===a?s.delete(i):s.set(i,a))),l||e.deleted||ur(s,n);break}}}e=e.right}return c},mr=t=>{let e=0;return _n(t.doc,(n=>{let r=t._start,s=t._start,i=v();const o=S(i);for(;s;){if(!1===s.deleted)if(s.content.constructor===Pr)ur(o,s.content);else e+=wr(n,r,s,i,o),i=S(o),r=s;s=s.right}})),e},yr=t=>{const e=new Set,n=t.doc;for(const[r,s]of t.afterState.entries()){const i=t.beforeState.get(r)||0;s!==i&&fn(t,n.store.clients.get(r),i,s,(t=>{t.deleted||t.content.constructor!==Pr||t.constructor===Ar||e.add(t.parent)}))}_n(n,(n=>{Se(t,t.deleteSet,(t=>{if(t instanceof Ar||!t.parent._hasFormatting||e.has(t.parent))return;const r=t.parent;t.content.constructor===Pr?e.add(r):((t,e)=>{for(;e&&e.right&&(e.right.deleted||!e.right.countable);)e=e.right;const n=new Set;for(;e&&(e.deleted||!e.countable);){if(!e.deleted&&e.content.constructor===Pr){const r=e.content.key;n.has(r)?e.delete(t):n.add(r)}e=e.left}})(n,t)}));for(const t of e)mr(t)}))},_r=(t,e,n)=>{const r=n,s=S(e.currentAttributes),i=e.right;for(;n>0&&null!==e.right;){if(!1===e.right.deleted)switch(e.right.content.constructor){case qr:case jr:case Tr:n<e.right.length&&un(t,tn(e.right.id.client,e.right.id.clock+n)),n-=e.right.length,e.right.delete(t)}e.forward()}i&&wr(t,i,e.right,s,e.currentAttributes);const o=(e.left||e.right).parent;return o._searchMarker&&Nn(o._searchMarker,e.index,-r+n),e};class br extends Mn{constructor(t,e,n){super(t,e),this.childListChanged=!1,this.keysChanged=new Set,n.forEach((t=>{null===t?this.childListChanged=!0:this.keysChanged.add(t)}))}get changes(){if(null===this._changes){const t={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=t}return this._changes}get delta(){if(null===this._delta){const t=this.target.doc,e=[];_n(t,(t=>{const n=new Map,r=new Map;let s=this.target._start,i=null;const o={};let c="",l=0,h=0;const a=()=>{if(null!==i){let t=null;switch(i){case"delete":h>0&&(t={delete:h}),h=0;break;case"insert":("object"==typeof c||c.length>0)&&(t={insert:c},n.size>0&&(t.attributes={},n.forEach(((e,n)=>{null!==e&&(t.attributes[n]=e)})))),c="";break;case"retain":l>0&&(t={retain:l},(t=>{for(const e in t)return!1;return!0})(o)||(t.attributes=J({},o))),l=0}t&&e.push(t),i=null}};for(;null!==s;){switch(s.content.constructor){case qr:case jr:this.adds(s)?this.deletes(s)||(a(),i="insert",c=s.content.getContent()[0],a()):this.deletes(s)?("delete"!==i&&(a(),i="delete"),h+=1):s.deleted||("retain"!==i&&(a(),i="retain"),l+=1);break;case Tr:this.adds(s)?this.deletes(s)||("insert"!==i&&(a(),i="insert"),c+=s.content.str):this.deletes(s)?("delete"!==i&&(a(),i="delete"),h+=s.length):s.deleted||("retain"!==i&&(a(),i="retain"),l+=s.length);break;case Pr:{const{key:e,value:c}=s.content;if(this.adds(s)){if(!this.deletes(s)){const l=n.get(e)||null;or(l,c)?null!==c&&s.delete(t):("retain"===i&&a(),or(c,r.get(e)||null)?delete o[e]:o[e]=c)}}else if(this.deletes(s)){r.set(e,c);const t=n.get(e)||null;or(t,c)||("retain"===i&&a(),o[e]=t)}else if(!s.deleted){r.set(e,c);const n=o[e];void 0!==n&&(or(n,c)?null!==n&&s.delete(t):("retain"===i&&a(),null===c?delete o[e]:o[e]=c))}s.deleted||("insert"===i&&a(),ur(n,s.content));break}}s=s.right}for(a();e.length>0;){const t=e[e.length-1];if(void 0===t.retain||void 0!==t.attributes)break;e.pop()}})),this._delta=e}return this._delta}}class kr extends Vn{constructor(t){super(),this._pending=void 0!==t?[()=>this.insert(0,t)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this._length}_integrate(t,e){super._integrate(t,e);try{this._pending.forEach((t=>t()))}catch(t){console.error(t)}this._pending=null}_copy(){return new kr}clone(){const t=new kr;return t.applyDelta(this.toDelta()),t}_callObserver(t,e){super._callObserver(t,e);const n=new br(this,t,e);Tn(this,t,n),!t.local&&this._hasFormatting&&(t._needFormattingCleanup=!0)}toString(){let t="",e=this._start;for(;null!==e;)!e.deleted&&e.countable&&e.content.constructor===Tr&&(t+=e.content.str),e=e.right;return t}toJSON(){return this.toString()}applyDelta(t,{sanitize:e=!0}={}){null!==this.doc?_n(this.doc,(n=>{const r=new cr(null,this._start,0,new Map);for(let s=0;s<t.length;s++){const i=t[s];if(void 0!==i.insert){const o=e||"string"!=typeof i.insert||s!==t.length-1||null!==r.right||"\n"!==i.insert.slice(-1)?i.insert:i.insert.slice(0,-1);("string"!=typeof o||o.length>0)&&gr(n,this,r,o,i.attributes||{})}else void 0!==i.retain?pr(n,this,r,i.retain,i.attributes||{}):void 0!==i.delete&&_r(n,r,i.delete)}})):this._pending.push((()=>this.applyDelta(t)))}toDelta(t,e,n){const r=[],s=new Map,i=this.doc;let o="",c=this._start;function l(){if(o.length>0){const t={};let e=!1;s.forEach(((n,r)=>{e=!0,t[r]=n}));const n={insert:o};e&&(n.attributes=t),r.push(n),o=""}}const h=()=>{for(;null!==c;){if(en(c,t)||void 0!==e&&en(c,e))switch(c.content.constructor){case Tr:{const r=s.get("ychange");void 0===t||en(c,t)?void 0===e||en(c,e)?void 0!==r&&(l(),s.delete("ychange")):void 0!==r&&r.user===c.id.client&&"added"===r.type||(l(),s.set("ychange",n?n("added",c.id):{type:"added"})):void 0!==r&&r.user===c.id.client&&"removed"===r.type||(l(),s.set("ychange",n?n("removed",c.id):{type:"removed"})),o+=c.content.str;break}case qr:case jr:{l();const t={insert:c.content.getContent()[0]};if(s.size>0){const e={};t.attributes=e,s.forEach(((t,n)=>{e[n]=t}))}r.push(t);break}case Pr:en(c,t)&&(l(),ur(s,c.content))}c=c.right}l()};return t||e?_n(i,(n=>{t&&nn(n,t),e&&nn(n,e),h()}),"cleanup"):h(),r}insert(t,e,n){if(e.length<=0)return;const r=this.doc;null!==r?_n(r,(r=>{const s=hr(r,this,t);n||(n={},s.currentAttributes.forEach(((t,e)=>{n[e]=t}))),gr(r,this,s,e,n)})):this._pending.push((()=>this.insert(t,e,n)))}insertEmbed(t,e,n={}){const r=this.doc;null!==r?_n(r,(r=>{const s=hr(r,this,t);gr(r,this,s,e,n)})):this._pending.push((()=>this.insertEmbed(t,e,n)))}delete(t,e){if(0===e)return;const n=this.doc;null!==n?_n(n,(n=>{_r(n,hr(n,this,t),e)})):this._pending.push((()=>this.delete(t,e)))}format(t,e,n){if(0===e)return;const r=this.doc;null!==r?_n(r,(r=>{const s=hr(r,this,t);null!==s.right&&pr(r,this,s,e,n)})):this._pending.push((()=>this.format(t,e,n)))}removeAttribute(t){null!==this.doc?_n(this.doc,(e=>{Yn(e,this,t)})):this._pending.push((()=>this.removeAttribute(t)))}setAttribute(t,e){null!==this.doc?_n(this.doc,(n=>{Xn(n,this,t,e)})):this._pending.push((()=>this.setAttribute(t,e)))}getAttribute(t){return Qn(this,t)}getAttributes(){return Zn(this)}_write(t){t.writeTypeRef($r)}}class vr{constructor(t,e=(()=>!0)){this._filter=e,this._root=t,this._currentNode=t._start,this._firstCall=!0}[Symbol.iterator](){return this}next(){let t=this._currentNode,e=t&&t.content&&t.content.type;if(null!==t&&(!this._firstCall||t.deleted||!this._filter(e)))do{if(e=t.content.type,t.deleted||e.constructor!==Cr&&e.constructor!==Sr||null===e._start)for(;null!==t;){if(null!==t.right){t=t.right;break}t=t.parent===this._root?null:t.parent._item}else t=e._start}while(null!==t&&(t.deleted||!this._filter(t.content.type)));return this._firstCall=!1,null===t?{value:void 0,done:!0}:(this._currentNode=t,{value:t.content.type,done:!1})}}class Sr extends Vn{constructor(){super(),this._prelimContent=[]}get firstChild(){const t=this._first;return t?t.content.getContent()[0]:null}_integrate(t,e){super._integrate(t,e),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Sr}clone(){const t=new Sr;return t.insert(0,this.toArray().map((t=>t instanceof Vn?t.clone():t))),t}get length(){return null===this._prelimContent?this._length:this._prelimContent.length}createTreeWalker(t){return new vr(this,t)}querySelector(t){t=t.toUpperCase();const e=new vr(this,(e=>e.nodeName&&e.nodeName.toUpperCase()===t)).next();return e.done?null:e.value}querySelectorAll(t){return t=t.toUpperCase(),x(new vr(this,(e=>e.nodeName&&e.nodeName.toUpperCase()===t)))}_callObserver(t,e){Tn(this,t,new Er(this,e,t))}toString(){return Wn(this,(t=>t.toString())).join("")}toJSON(){return this.toString()}toDOM(t=document,e={},n){const r=t.createDocumentFragment();return void 0!==n&&n._createAssociation(r,this),$n(this,(s=>{r.insertBefore(s.toDOM(t,e,n),null)})),r}insert(t,e){null!==this.doc?_n(this.doc,(n=>{zn(n,this,t,e)})):this._prelimContent.splice(t,0,...e)}insertAfter(t,e){if(null!==this.doc)_n(this.doc,(n=>{const r=t&&t instanceof Vn?t._item:t;Jn(n,this,r,e)}));else{const n=this._prelimContent,r=null===t?0:n.findIndex((e=>e===t))+1;if(0===r&&null!==t)throw ut("Reference item not found");n.splice(r,0,...e)}}delete(t,e=1){null!==this.doc?_n(this.doc,(n=>{Gn(n,this,t,e)})):this._prelimContent.splice(t,e)}toArray(){return Fn(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return Hn(this,t)}slice(t=0,e=this.length){return Kn(this,t,e)}forEach(t){$n(this,t)}_write(t){t.writeTypeRef(Br)}}class Cr extends Sr{constructor(t="UNDEFINED"){super(),this.nodeName=t,this._prelimAttrs=new Map}get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_integrate(t,e){super._integrate(t,e),this._prelimAttrs.forEach(((t,e)=>{this.setAttribute(e,t)})),this._prelimAttrs=null}_copy(){return new Cr(this.nodeName)}clone(){const t=new Cr(this.nodeName);return((t,e)=>{for(const n in t)e(t[n],n)})(this.getAttributes(),((e,n)=>{"string"==typeof e&&t.setAttribute(n,e)})),t.insert(0,this.toArray().map((t=>t instanceof Vn?t.clone():t))),t}toString(){const t=this.getAttributes(),e=[],n=[];for(const e in t)n.push(e);n.sort();const r=n.length;for(let s=0;s<r;s++){const r=n[s];e.push(r+'="'+t[r]+'"')}const s=this.nodeName.toLocaleLowerCase();return`<${s}${e.length>0?" "+e.join(" "):""}>${super.toString()}</${s}>`}removeAttribute(t){null!==this.doc?_n(this.doc,(e=>{Yn(e,this,t)})):this._prelimAttrs.delete(t)}setAttribute(t,e){null!==this.doc?_n(this.doc,(n=>{Xn(n,this,t,e)})):this._prelimAttrs.set(t,e)}getAttribute(t){return Qn(this,t)}hasAttribute(t){return tr(this,t)}getAttributes(){return Zn(this)}toDOM(t=document,e={},n){const r=t.createElement(this.nodeName),s=this.getAttributes();for(const t in s){const e=s[t];"string"==typeof e&&r.setAttribute(t,e)}return $n(this,(s=>{r.appendChild(s.toDOM(t,e,n))})),void 0!==n&&n._createAssociation(r,this),r}_write(t){t.writeTypeRef(Wr),t.writeKey(this.nodeName)}}class Er extends Mn{constructor(t,e,n){super(t,n),this.childListChanged=!1,this.attributesChanged=new Set,e.forEach((t=>{null===t?this.childListChanged=!0:this.attributesChanged.add(t)}))}}class Dr extends ir{constructor(t){super(),this.hookName=t}_copy(){return new Dr(this.hookName)}clone(){const t=new Dr(this.hookName);return this.forEach(((e,n)=>{t.set(n,e)})),t}toDOM(t=document,e={},n){const r=e[this.hookName];let s;return s=void 0!==r?r.createDom(this):document.createElement(this.hookName),s.setAttribute("data-yjs-hook",this.hookName),void 0!==n&&n._createAssociation(s,this),s}_write(t){t.writeTypeRef(Hr),t.writeKey(this.hookName)}}class Or extends kr{get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_copy(){return new Or}clone(){const t=new Or;return t.applyDelta(this.toDelta()),t}toDOM(t=document,e,n){const r=t.createTextNode(this.toString());return void 0!==n&&n._createAssociation(r,this),r}toString(){return this.toDelta().map((t=>{const e=[];for(const n in t.attributes){const r=[];for(const e in t.attributes[n])r.push({key:e,value:t.attributes[n][e]});r.sort(((t,e)=>t.key<e.key?-1:1)),e.push({nodeName:n,attrs:r})}e.sort(((t,e)=>t.nodeName<e.nodeName?-1:1));let n="";for(let t=0;t<e.length;t++){const r=e[t];n+=`<${r.nodeName}`;for(let t=0;t<r.attrs.length;t++){const e=r.attrs[t];n+=` ${e.key}="${e.value}"`}n+=">"}n+=t.insert;for(let t=e.length-1;t>=0;t--)n+=`</${e[t].nodeName}>`;return n})).join("")}toJSON(){return this.toString()}_write(t){t.writeTypeRef(Jr)}}class xr{constructor(t,e){this.id=t,this.length=e}get deleted(){throw dt()}mergeWith(t){return!1}write(t,e,n){throw dt()}integrate(t,e){throw dt()}}class Ar extends xr{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor===t.constructor&&(this.length+=t.length,!0)}integrate(t,e){e>0&&(this.id.clock+=e,this.length-=e),cn(t.doc.store,this)}write(t,e){t.writeInfo(0),t.writeLen(this.length-e)}getMissing(t,e){return null}}class Ir{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new Ir(this.content)}splice(t){throw dt()}mergeWith(t){return!1}integrate(t,e){}delete(t){}gc(t){}write(t,e){t.writeBuf(this.content)}getRef(){return 3}}class Mr{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new Mr(this.len)}splice(t){const e=new Mr(this.len-t);return this.len=t,e}mergeWith(t){return this.len+=t.len,!0}integrate(t,e){De(t.deleteSet,e.id.client,e.id.clock,this.len),e.markDeleted()}delete(t){}gc(t){}write(t,e){t.writeLen(this.len-e)}getRef(){return 1}}const Lr=(t,e)=>new Le({guid:t,...e,shouldLoad:e.shouldLoad||e.autoLoad||!1});class Rr{constructor(t){t._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=t;const e={};this.opts=e,t.gc||(e.gc=!1),t.autoLoad&&(e.autoLoad=!0),null!==t.meta&&(e.meta=t.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new Rr(Lr(this.doc.guid,this.opts))}splice(t){throw dt()}mergeWith(t){return!1}integrate(t,e){this.doc._item=e,t.subdocsAdded.add(this.doc),this.doc.shouldLoad&&t.subdocsLoaded.add(this.doc)}delete(t){t.subdocsAdded.has(this.doc)?t.subdocsAdded.delete(this.doc):t.subdocsRemoved.add(this.doc)}gc(t){}write(t,e){t.writeString(this.doc.guid),t.writeAny(this.opts)}getRef(){return 9}}class jr{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new jr(this.embed)}splice(t){throw dt()}mergeWith(t){return!1}integrate(t,e){}delete(t){}gc(t){}write(t,e){t.writeJSON(this.embed)}getRef(){return 5}}class Pr{constructor(t,e){this.key=t,this.value=e}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new Pr(this.key,this.value)}splice(t){throw dt()}mergeWith(t){return!1}integrate(t,e){const n=e.parent;n._searchMarker=null,n._hasFormatting=!0}delete(t){}gc(t){}write(t,e){t.writeKey(this.key),t.writeJSON(this.value)}getRef(){return 6}}class Ur{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Ur(this.arr)}splice(t){const e=new Ur(this.arr.slice(t));return this.arr=this.arr.slice(0,t),e}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,e){}delete(t){}gc(t){}write(t,e){const n=this.arr.length;t.writeLen(n-e);for(let r=e;r<n;r++){const e=this.arr[r];t.writeString(void 0===e?"undefined":JSON.stringify(e))}}getRef(){return 2}}class Nr{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Nr(this.arr)}splice(t){const e=new Nr(this.arr.slice(t));return this.arr=this.arr.slice(0,t),e}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,e){}delete(t){}gc(t){}write(t,e){const n=this.arr.length;t.writeLen(n-e);for(let r=e;r<n;r++){const e=this.arr[r];t.writeAny(e)}}getRef(){return 8}}class Tr{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new Tr(this.str)}splice(t){const e=new Tr(this.str.slice(t));this.str=this.str.slice(0,t);const n=this.str.charCodeAt(t-1);return n>=55296&&n<=56319&&(this.str=this.str.slice(0,t-1)+"�",e.str="�"+e.str.slice(1)),e}mergeWith(t){return this.str+=t.str,!0}integrate(t,e){}delete(t){}gc(t){}write(t,e){t.writeString(0===e?this.str:this.str.slice(e))}getRef(){return 4}}const Vr=[t=>new rr,t=>new ir,t=>new kr,t=>new Cr(t.readKey()),t=>new Sr,t=>new Dr(t.readKey()),t=>new Or],Kr=0,Fr=1,$r=2,Wr=3,Br=4,Hr=5,Jr=6;class qr{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new qr(this.type._copy())}splice(t){throw dt()}mergeWith(t){return!1}integrate(t,e){this.type._integrate(t.doc,e)}delete(t){let e=this.type._start;for(;null!==e;)e.deleted?e.id.clock<(t.beforeState.get(e.id.client)||0)&&t._mergeStructs.push(e):e.delete(t),e=e.right;this.type._map.forEach((e=>{e.deleted?e.id.clock<(t.beforeState.get(e.id.client)||0)&&t._mergeStructs.push(e):e.delete(t)})),t.changed.delete(this.type)}gc(t){let e=this.type._start;for(;null!==e;)e.gc(t,!0),e=e.right;this.type._start=null,this.type._map.forEach((e=>{for(;null!==e;)e.gc(t,!0),e=e.left})),this.type._map=new Map}write(t,e){this.type._write(t)}getRef(){return 7}}const zr=(t,e,n)=>{const{client:r,clock:s}=e.id,i=new Gr(tn(r,s+n),e,tn(r,s+n-1),e.right,e.rightOrigin,e.parent,e.parentSub,e.content.splice(n));return e.deleted&&i.markDeleted(),e.keep&&(i.keep=!0),null!==e.redone&&(i.redone=tn(e.redone.client,e.redone.clock+n)),e.right=i,null!==i.right&&(i.right.left=i),t._mergeStructs.push(i),null!==i.parentSub&&null===i.right&&i.parent._map.set(i.parentSub,i),e.length=n,i};class Gr extends xr{constructor(t,e,n,r,s,i,o,c){super(t,c.getLength()),this.origin=n,this.left=e,this.right=r,this.rightOrigin=s,this.parent=i,this.parentSub=o,this.redone=null,this.content=c,this.info=this.content.isCountable()?2:0}set marker(t){(8&this.info)>0!==t&&(this.info^=8)}get marker(){return(8&this.info)>0}get keep(){return(1&this.info)>0}set keep(t){this.keep!==t&&(this.info^=1)}get countable(){return(2&this.info)>0}get deleted(){return(4&this.info)>0}set deleted(t){this.deleted!==t&&(this.info^=4)}markDeleted(){this.info|=4}getMissing(t,e){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=on(e,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=on(e,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Qe&&this.id.client!==this.parent.client&&this.parent.clock>=on(e,this.parent.client))return this.parent.client;if(this.origin&&(this.left=dn(t,e,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=un(t,this.rightOrigin),this.rightOrigin=this.right.id),(this.left&&this.left.constructor===Ar||this.right&&this.right.constructor===Ar)&&(this.parent=null),this.parent){if(this.parent.constructor===Qe){const t=hn(e,this.parent);t.constructor===Ar?this.parent=null:this.parent=t.content.type}}else this.left&&this.left.constructor===Gr&&(this.parent=this.left.parent,this.parentSub=this.left.parentSub),this.right&&this.right.constructor===Gr&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);return null}integrate(t,e){if(e>0&&(this.id.clock+=e,this.left=dn(t,t.doc.store,tn(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(e),this.length-=e),this.parent){if(!this.left&&(!this.right||null!==this.right.left)||this.left&&this.left.right!==this.right){let e,n=this.left;if(null!==n)e=n.right;else if(null!==this.parentSub)for(e=this.parent._map.get(this.parentSub)||null;null!==e&&null!==e.left;)e=e.left;else e=this.parent._start;const r=new Set,s=new Set;for(;null!==e&&e!==this.right;){if(s.add(e),r.add(e),Ze(this.origin,e.origin)){if(e.id.client<this.id.client)n=e,r.clear();else if(Ze(this.rightOrigin,e.rightOrigin))break}else{if(null===e.origin||!s.has(hn(t.doc.store,e.origin)))break;r.has(hn(t.doc.store,e.origin))||(n=e,r.clear())}e=e.right}this.left=n}if(null!==this.left){const t=this.left.right;this.right=t,this.left.right=this}else{let t;if(null!==this.parentSub)for(t=this.parent._map.get(this.parentSub)||null;null!==t&&null!==t.left;)t=t.left;else t=this.parent._start,this.parent._start=this;this.right=t}null!==this.right?this.right.left=this:null!==this.parentSub&&(this.parent._map.set(this.parentSub,this),null!==this.left&&this.left.delete(t)),null===this.parentSub&&this.countable&&!this.deleted&&(this.parent._length+=this.length),cn(t.doc.store,this),this.content.integrate(t,this),wn(t,this.parent,this.parentSub),(null!==this.parent._item&&this.parent._item.deleted||null!==this.parentSub&&null!==this.right)&&this.delete(t)}else new Ar(this.id,this.length).integrate(t,0)}get next(){let t=this.right;for(;null!==t&&t.deleted;)t=t.right;return t}get prev(){let t=this.left;for(;null!==t&&t.deleted;)t=t.left;return t}get lastId(){return 1===this.length?this.id:tn(this.id.client,this.id.clock+this.length-1)}mergeWith(t){if(this.constructor===t.constructor&&Ze(t.origin,this.lastId)&&this.right===t&&Ze(this.rightOrigin,t.rightOrigin)&&this.id.client===t.id.client&&this.id.clock+this.length===t.id.clock&&this.deleted===t.deleted&&null===this.redone&&null===t.redone&&this.content.constructor===t.content.constructor&&this.content.mergeWith(t.content)){const e=this.parent._searchMarker;return e&&e.forEach((e=>{e.p===t&&(e.p=this,!this.deleted&&this.countable&&(e.index-=this.length))})),t.keep&&(this.keep=!0),this.right=t.right,null!==this.right&&(this.right.left=this),this.length+=t.length,!0}return!1}delete(t){if(!this.deleted){const e=this.parent;this.countable&&null===this.parentSub&&(e._length-=this.length),this.markDeleted(),De(t.deleteSet,this.id.client,this.id.clock,this.length),wn(t,e,this.parentSub),this.content.delete(t)}}gc(t,e){if(!this.deleted)throw ft();this.content.gc(t),e?((t,e,n)=>{const r=t.clients.get(e.id.client);r[ln(r,e.id.clock)]=n})(t,this,new Ar(this.id,this.length)):this.content=new Mr(this.length)}write(t,e){const n=e>0?tn(this.id.client,this.id.clock+e-1):this.origin,r=this.rightOrigin,s=this.parentSub,i=31&this.content.getRef()|(null===n?0:ct)|(null===r?0:ot)|(null===s?0:32);if(t.writeInfo(i),null!==n&&t.writeLeftID(n),null!==r&&t.writeRightID(r),null===n&&null===r){const e=this.parent;if(void 0!==e._item){const n=e._item;if(null===n){const n=(t=>{for(const[e,n]of t.doc.share.entries())if(n===t)return e;throw ft()})(e);t.writeParentInfo(!0),t.writeString(n)}else t.writeParentInfo(!1),t.writeLeftID(n.id)}else e.constructor===String?(t.writeParentInfo(!0),t.writeString(e)):e.constructor===Qe?(t.writeParentInfo(!1),t.writeLeftID(e)):ft();null!==s&&t.writeString(s)}this.content.write(t,e)}}const Yr=(t,e)=>Xr[31&e](t),Xr=[()=>{ft()},t=>new Mr(t.readLen()),t=>{const e=t.readLen(),n=[];for(let r=0;r<e;r++){const e=t.readString();"undefined"===e?n.push(void 0):n.push(JSON.parse(e))}return new Ur(n)},t=>new Ir(t.readBuf()),t=>new Tr(t.readString()),t=>new jr(t.readJSON()),t=>new Pr(t.readKey(),t.readJSON()),t=>new qr(Vr[t.readTypeRef()](t)),t=>{const e=t.readLen(),n=[];for(let r=0;r<e;r++)n.push(t.readAny());return new Nr(n)},t=>new Rr(Lr(t.readString(),t.readAny())),()=>{ft()}];class Qr extends xr{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor===t.constructor&&(this.length+=t.length,!0)}integrate(t,e){ft()}write(t,e){t.writeInfo(10),Nt(t.restEncoder,this.length-e)}getMissing(t,e){return null}}const Zr="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},ts="__ $YJS$ __";!0===Zr[ts]&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438"),Zr[ts]=!0;const es=Symbol(),ns=Object.getPrototypeOf,rs=new WeakMap,ss=t=>(t=>t&&(rs.has(t)?rs.get(t):ns(t)===Object.prototype||ns(t)===Array.prototype))(t)&&t[es]||null,is=(t,e=!0)=>{rs.set(t,e)},os=t=>"object"==typeof t&&null!==t,cs=new WeakMap,ls=new WeakSet,[hs]=((t=Object.is,e=((t,e)=>new Proxy(t,e)),n=(t=>os(t)&&!ls.has(t)&&(Array.isArray(t)||!(Symbol.iterator in t))&&!(t instanceof WeakMap)&&!(t instanceof WeakSet)&&!(t instanceof Error)&&!(t instanceof Number)&&!(t instanceof Date)&&!(t instanceof String)&&!(t instanceof RegExp)&&!(t instanceof ArrayBuffer)),r=(t=>{switch(t.status){case"fulfilled":return t.value;case"rejected":throw t.reason;default:throw t}}),s=new WeakMap,i=((t,e,n=r)=>{const o=s.get(t);if((null==o?void 0:o[0])===e)return o[1];const c=Array.isArray(t)?[]:Object.create(Object.getPrototypeOf(t));return is(c,!0),s.set(t,[e,c]),Reflect.ownKeys(t).forEach((e=>{if(Object.getOwnPropertyDescriptor(c,e))return;const r=Reflect.get(t,e),{enumerable:s}=Reflect.getOwnPropertyDescriptor(t,e),o={value:r,enumerable:s,configurable:!0};if(ls.has(r))is(r,!1);else if(r instanceof Promise)delete o.value,o.get=()=>n(r);else if(cs.has(r)){const[t,e]=cs.get(r);o.value=i(t,e(),n)}Object.defineProperty(c,e,o)})),Object.preventExtensions(c)}),o=new WeakMap,c=[1,1],l=(r=>{if(!os(r))throw new Error("object required");const s=o.get(r);if(s)return s;let h=c[0];const a=new Set,u=(t,e=++c[0])=>{h!==e&&(h=e,a.forEach((n=>n(t,e))))};let d=c[1];const f=t=>(e,n)=>{const r=[...e];r[1]=[t,...r[1]],u(r,n)},g=new Map,p=t=>{var e;const n=g.get(t);n&&(g.delete(t),null==(e=n[1])||e.call(n))},w=Array.isArray(r)?[]:Object.create(Object.getPrototypeOf(r)),m={deleteProperty(t,e){const n=Reflect.get(t,e);p(e);const r=Reflect.deleteProperty(t,e);return r&&u(["delete",[e],n]),r},set(e,r,s,i){const c=Reflect.has(e,r),h=Reflect.get(e,r,i);if(c&&(t(h,s)||o.has(s)&&t(h,o.get(s))))return!0;p(r),os(s)&&(s=ss(s)||s);let d=s;if(s instanceof Promise)s.then((t=>{s.status="fulfilled",s.value=t,u(["resolve",[r],t])})).catch((t=>{s.status="rejected",s.reason=t,u(["reject",[r],t])}));else{!cs.has(s)&&n(s)&&(d=l(s));const t=!ls.has(d)&&cs.get(d);t&&((t,e)=>{if(g.has(t))throw new Error("prop listener already exists");if(a.size){const n=e[3](f(t));g.set(t,[e,n])}else g.set(t,[e])})(r,t)}return Reflect.set(e,r,d,i),u(["set",[r],s,h]),!0}},y=e(w,m);o.set(r,y);const _=[w,(t=++c[1])=>(d===t||a.size||(d=t,g.forEach((([e])=>{const n=e[1](t);n>h&&(h=n)}))),h),i,t=>{a.add(t),1===a.size&&g.forEach((([t,e],n)=>{if(e)throw new Error("remove already exists");const r=t[3](f(n));g.set(n,[t,r])}));return()=>{a.delete(t),0===a.size&&g.forEach((([t,e],n)=>{e&&(e(),g.set(n,[t]))}))}}];return cs.set(y,_),Reflect.ownKeys(r).forEach((t=>{const e=Object.getOwnPropertyDescriptor(r,t);"value"in e&&(y[t]=r[t],delete e.value,delete e.writable),Object.defineProperty(w,t,e)})),y}))=>[l,cs,ls,t,e,n,r,s,i,o,c])();function as(t={}){return hs(t)}function us(t){const e=cs.get(t);return null==e?void 0:e[1]()}var ds=function t(e,n){if(e===n)return!0;if(e&&n&&"object"==typeof e&&"object"==typeof n){if(e.constructor!==n.constructor)return!1;var r,s,i;if(Array.isArray(e)){if((r=e.length)!=n.length)return!1;for(s=r;0!=s--;)if(!t(e[s],n[s]))return!1;return!0}if(e.constructor===RegExp)return e.source===n.source&&e.flags===n.flags;if(e.valueOf!==Object.prototype.valueOf)return e.valueOf()===n.valueOf();if(e.toString!==Object.prototype.toString)return e.toString()===n.toString();if((r=(i=Object.keys(e)).length)!==Object.keys(n).length)return!1;for(s=r;0!=s--;)if(!Object.prototype.hasOwnProperty.call(n,i[s]))return!1;for(s=r;0!=s--;){var o=i[s];if(!t(e[o],n[o]))return!1}return!0}return e!=e&&n!=n},fs=s(ds);const gs=t=>"object"==typeof t&&null!==t&&void 0!==us(t),ps=t=>Array.isArray(t)&&void 0!==us(t),ws=(t,e,n)=>{t?t.transact(n,e.transactionOrigin):n()},ms=t=>{if(ps(t)){const e=new rr;return e.insert(0,t.map(ms).filter((t=>null!=t))),e}if(gs(t)){const e=new ir;return Object.entries(t).forEach((([t,n])=>{const r=ms(n);void 0!==r&&e.set(t,r)})),e}if(null===(e=t)||"string"==typeof e||"number"==typeof e||"boolean"==typeof e)return t;var e},ys=t=>t instanceof Vn?t.toJSON():t,_s=(t,e,n)=>{let r=t,s=e;for(let t=0;t<n.length;t+=1){const e=n[t];if(s instanceof ir){if(!r)break;r=r[e],s=s.get(e)}else if(s instanceof rr){if(!r)break;const t=Number(e);r=r[e],s=s.get(t)}else r=null,s=null}return{p:r,y:s}};function bs(t,e,n={}){ps(t),!gs(t)||ps(t),function(t,e){gs(t)&&e instanceof ir&&e.forEach(((e,n)=>{fs(t[n],ys(e))||(t[n]=ys(e))})),ps(t)&&e instanceof rr&&e.forEach(((e,n)=>{fs(t[n],ys(e))||vs(e,t,n)}))}(t,e),function(t,e,n){ws(e.doc,n,(()=>{gs(t)&&e instanceof ir&&Object.entries(t).forEach((([t,n])=>{const r=e.get(t);fs(n,ys(r))||ks(n,e,t)})),ps(t)&&e instanceof rr&&t.forEach(((t,n)=>{const r=e.get(n);fs(t,ys(r))||ks(t,e,n)}))}))}(t,e,n),ps(t)&&e instanceof rr&&t.splice(e.length);const r=function(t,e,n){return function(t,e,n){const r=cs.get(t);let s;r||console.warn("Please use proxy object");const i=[],o=r[3];let c=!1;const l=o((t=>{i.push(t),n?e(i.splice(0)):s||(s=Promise.resolve().then((()=>{s=void 0,c&&e(i.splice(0))})))}));return c=!0,()=>{c=!1,l()}}(t,(r=>{ws(e.doc,n,(()=>{r.forEach((n=>{const s=n[1].slice(0,-1),i=n[1][n[1].length-1],o=_s(t,e,s);if(o.y instanceof ir){if("delete"===n[0])o.y.delete(i);else if("set"===n[0]){const t=o.p[i],e=o.y.get(i);fs(ys(e),t)||ks(t,o.y,i)}}else if(o.y instanceof rr){if(fs(ys(o.y),o.p))return;(t=>{const e=t.flatMap((t=>{if("resolve"===t[0]||"reject"===t[0])return[];const e=Number(t[1][t[1].length-1]);return Number.isFinite(e)?[[t[0],e,t[2],t[3]]]:[]})),n=(t,n)=>{let r=0,s=null;for(;t+r+1<e.length;){if(("set"===e[t+r+1][0]||"insert"===e[t+r+1][0])&&e[t+r+1][1]<n&&e[t+r+1][3]===e[t][2])return r+1;if(null!==s||"set"!==e[t+r+1][0]&&"insert"!==e[t+r+1][0]||e[t+r+1][1]!==n-(r+1)||void 0!==e[t+r+1][3])if(null===s&&t+r+1<e.length&&"set"===e[t+r+1][0]&&void 0!==e[t+r+1][3])s=[t+r+1,e[t+r+1][1]],r+=1;else{if(null===s||"set"!==e[t+r+1][0]||e[t+r+1][1]!==s[1]+(r+1-s[0])||void 0===e[t+r+1][3])return null;r+=1}else r+=1}return null},r=(t,n)=>{let r=0;for(;t+r+1<e.length&&"delete"===e[t+r+1][0]&&e[t+r+1][1]===n-(r+1);)r+=1;return r};let s=0;for(;s<e.length;)if("set"!==e[s][0]&&"insert"!==e[s][0]||void 0!==e[s][3])if(s>0&&"delete"===e[s][0]){const t=e[s][1],n=r(s,t);if("set"===e[s-1][0]&&e[s-1][1]===t-(n+1)&&e[s-1][2]===e[s][2]){const r=["delete",t-(n+1),e[s-1][3],void 0];e.splice(s-1,2),e.splice(s-1+n,0,r),s-=1}else s+=1}else s+=1;else{const t=n(s,e[s][1]);null!==t?(e.splice(s+t,1,["insert",e[s+t][1],e[s+t][2],void 0]),e.splice(s,1)):s+=1}return e})(r).forEach((t=>{const e=t[1];if("delete"===t[0])return void(o.y.length>e&&o.y.delete(e,1));const n=o.p[e];void 0!==n&&("set"===t[0]?(o.y.length>e&&o.y.delete(e,1),ks(n,o.y,e)):"insert"===t[0]&&ks(n,o.y,e))}))}}))}))}))}(t,e,n),s=function(t,e){const n=n=>{n.forEach((n=>{const r=_s(e,t,n.path);if(r.y instanceof ir)n.changes.keys.forEach(((t,e)=>{"delete"===t.action?delete r.p[e]:vs(r.y.get(e),r.p,e)}));else if(r.y instanceof rr){if(fs(r.p,ys(r.y)))return;let t=0;n.changes.delta.forEach((e=>{e.retain&&(t+=e.retain),e.delete&&r.p.splice(t,e.delete),e.insert&&(Array.isArray(e.insert)?e.insert.forEach(((e,n)=>{vs(e,r.p,t+n)})):vs(e.insert,r.p,t),t+=e.insert.length)}))}}))};return t.observeDeep(n),()=>{t.unobserveDeep(n)}}(e,t);return()=>{r(),s()}}function ks(t,e,n){const r=ms(t);e instanceof ir&&"string"==typeof n?e.set(n,r):e instanceof rr&&"number"==typeof n&&e.insert(n,[r])}function vs(t,e,n){gs(e)&&"string"==typeof n?e[n]=ys(t):ps(e)&&"number"==typeof n&&e.splice(n,0,ys(t))}class Ss{kmClient;_clones=new Map;_updates=new Map;_consumeMessagesInRooms=new Set;constructor(t){this.kmClient=t}_parseTarget(t){return t()}_parsePath(t,e){for(let n=0;n<e.length-1;n++)e[n]in t||(t[e[n]]={}),t=t[e[n]];return{obj:t,key:e[e.length-1]}}_getClone(t,e){if(!this._clones.has(t)){const n=new Le,r=n.getMap("root");Be(n,((t,e)=>He(t,e,new Te))(e));const s=as(),i=bs(s,r);n.on("update",(e=>{if(this._updates.has(t)){const n=this._updates.get(t),r=vn([n,e]);this._updates.set(t,r)}else this._updates.set(t,e)})),this._clones.set(t,{docClone:n,proxyClone:s,unbindProxy:i})}return this._clones.get(t)}get(t){const{roomName:e,doc:n,path:r}=this._parseTarget(t),{proxyClone:s}=this._getClone(e,n),{obj:i,key:o}=this._parsePath(s,r);return i[o]}set(t,e){const{roomName:n,doc:r,path:s}=this._parseTarget(t),{proxyClone:i}=this._getClone(n,r),{obj:o,key:c}=this._parsePath(i,s);o[c]=e}delete(t){const{roomName:e,doc:n,path:r}=this._parseTarget(t),{proxyClone:s}=this._getClone(e,n),{obj:i,key:o}=this._parsePath(s,r);delete i[o]}push(t,e){const{roomName:n,doc:r,path:s}=this._parseTarget(t),{proxyClone:i}=this._getClone(n,r),{obj:o,key:c}=this._parsePath(i,s);c in o||(o[c]=[]),o[c].push(e)}queueMessage(t,e){const n=Math.random().toString(36);this.set(t.root[n],{timestamp:this.kmClient.serverTimestamp(),payload:e})}consumeMessage(t,e){if(!t.proxy[e])throw new Error(`Message ${e} does not exist or has already been consumed`);this.delete(t.root[e]),this._consumeMessagesInRooms.add(t.roomName)}async getUpdates(){return await new Promise((t=>setTimeout((()=>{for(const{unbindProxy:t}of this._clones.values())t();const e=Array.from(this._updates.entries()).map((([t,e])=>({roomName:t,update:e})));t({updates:e,consumedMessages:this._consumeMessagesInRooms})}))))}}var Cs,Es;!function(t){t[t.SubscribeReq=1]="SubscribeReq",t[t.SubscribeRes=2]="SubscribeRes",t[t.Transaction=3]="Transaction",t[t.RoomUpdate=4]="RoomUpdate",t[t.Error=5]="Error",t[t.Ping=6]="Ping",t[t.Pong=7]="Pong"}(Cs||(Cs={}));class Ds{_parts=[];writeInt32(t){const e=new Uint8Array(4);new DataView(e.buffer).setInt32(0,t,!0),this._parts.push(e)}writeUint32(t){const e=new Uint8Array(4);new DataView(e.buffer).setUint32(0,t,!0),this._parts.push(e)}writeString(t){this.writeInt32(t.length);const e=new Uint8Array(t.length);for(let n=0;n<t.length;n++)e[n]=t.charCodeAt(n);this._parts.push(e)}writeChar(t){const e=new Uint8Array(1);e[0]=t.charCodeAt(0),this._parts.push(e)}writeUint8Array(t){this.writeInt32(t.byteLength),this._parts.push(t)}getBuffer(){const t=this._parts.reduce(((t,e)=>t+e.byteLength),0),e=new ArrayBuffer(t);let n=0;for(const t of this._parts){new Uint8Array(e,n).set(t),n+=t.byteLength}return e}}class Os{buffer;_view;_offset=0;constructor(t){this.buffer=t,this._view=new DataView(t)}readInt32(){const t=this._view.getInt32(this._offset,!0);return this._offset+=4,t}readUint32(){const t=this._view.getUint32(this._offset,!0);return this._offset+=4,t}readString(){const t=this.readInt32();let e="";for(let n=0;n<t;n++)e+=String.fromCharCode(this._view.getUint8(this._offset++));return e}readUint8Array(){const t=this.readInt32(),e=new Uint8Array(this.buffer,this._offset,t);return this._offset+=t,e}get end(){return this._offset===this.buffer.byteLength}}t.RoomSubscriptionMode=void 0,(Es=t.RoomSubscriptionMode||(t.RoomSubscriptionMode={})).Read="r",Es.Write="w",Es.ReadWrite="b";class xs{kmClient;store;_joined=!1;_roomHash;_onDisconnect=()=>{this._joined=!1};constructor(t,e){this.kmClient=t,this.store=e,t.on("disconnected",this._onDisconnect)}get roomName(){return this.store.roomName}get roomHash(){if(!this._roomHash)throw new Error("Room not joined");return this._roomHash}get joined(){return this._joined}async applyInitialResponse(e,n){this._roomHash=e,n&&Be(this.store.doc,n,this),this.store.mode===t.RoomSubscriptionMode.ReadWrite&&await this.kmClient.transact((t=>{for(const e in this.store.defaultValue)this.store.proxy.hasOwnProperty(e)||t.set(this.store.root[e],this.store.defaultValue[e])})),this._joined=!0}close(){this.kmClient.off("disconnected",this._onDisconnect)}}function As(t,e){const n=t.slice();return n.push(e),n}t.KokimokiSchema=void 0,function(t){class e{}t.Generic=e;class n extends e{defaultValue;constructor(t=0){super(),this.defaultValue=t}}t.Number=n,t.number=function(t=0){return new n(t)};class r extends e{defaultValue;constructor(t=""){super(),this.defaultValue=t}}t.String=r,t.string=function(t=""){return new r(t)};class s extends e{defaultValue;constructor(t=!1){super(),this.defaultValue=t}}t.Boolean=s,t.boolean=function(t=!1){return new s(t)};class i extends e{fields;constructor(t){super(),this.fields=t}get defaultValue(){return Object.entries(this.fields).reduce(((t,[e,n])=>(t[e]=n.defaultValue,t)),{})}set defaultValue(t){for(const[e,n]of Object.entries(this.fields))n.defaultValue=t[e]}}t.Struct=i,t.struct=function(t){return new i(t)};class o{schema;defaultValue;constructor(t,e={}){this.schema=t,this.defaultValue=e}}t.Dict=o,t.dict=function(t,e={}){return new o(t,e)};class c extends e{schema;defaultValue;constructor(t,e=[]){super(),this.schema=t,this.defaultValue=e}}t.List=c,t.list=function(t,e=[]){return new c(t,e)};class l extends e{schema;defaultValue;constructor(t,e){super(),this.schema=t,this.defaultValue=e}}t.Nullable=l,t.nullable=function(t,e=null){return new l(t,e)};class h extends e{options;defaultValue;constructor(t,e){super(),this.options=t,this.defaultValue=e}}t.StringEnum=h,t.stringEnum=function(t,e){return new h(t,e)};class a extends e{defaultValue;constructor(t){super(),this.defaultValue=t}}t.StringConst=a,t.stringConst=function(t){return new a(t)};class u extends e{schemas;defaultValue;constructor(t,e){super(),this.schemas=t,this.defaultValue=e}}t.AnyOf=u,t.anyOf=function(t,e){return new u(t,e)}}(t.KokimokiSchema||(t.KokimokiSchema={}));const Is=["apply","construct","defineProperty","deleteProperty","enumerate","get","getOwnPropertyDescriptor","getPrototypeOf","has","isExtensible","ownKeys","preventExtensions","set","setPrototypeOf"],Ms={get:1,set:1,deleteProperty:1,has:1,defineProperty:1,getOwnPropertyDescriptor:1};function Ls(t,e,n){let r=[],s={};return void 0!==n&&void 0!==n.path&&(r=n.path.split(".")),void 0!==n&&void 0!==n.userData&&(s=n.userData),function n(r,i){const o={rootTarget:t,path:i};Object.assign(o,s);const c={};for(const r of Is){const s=Ms[r],l=e[r];void 0!==l&&(c[r]=void 0!==s?function(){const e=arguments[s];return o.nest=function(r){return void 0===r&&(r=t),n(r,As(i,e))},l.apply(o,arguments)}:function(){return o.nest=function(t){return void 0===t&&(t={}),n(t,i)},l.apply(o,arguments)})}return new Proxy(r,c)}(t,r)}class Rs{roomName;mode;doc;proxy;root;defaultValue;docRoot;constructor(e,n,r=t.RoomSubscriptionMode.ReadWrite){this.roomName=e,this.mode=r,this.doc=new Le,this.docRoot=this.doc.getMap("root"),this.proxy=as(),bs(this.proxy,this.docRoot);const s=this;this.root=new Ls(this.proxy,{get(){return this.nest((function(){}))},apply(){let t=s.proxy;for(let e=0;e<this.path.length-1;e++)t=t[this.path[e]];return{roomName:s.roomName,doc:s.doc,path:this.path,obj:t,key:this.path[this.path.length-1]}}}),this.defaultValue=n.defaultValue}}return t.BooleanField=class extends n{value;constructor(t,n=e){super(n),this.value=t}get schema(){return{type:"boolean",default:this.value}}},t.ConstField=class extends n{value;constructor(t,n=e){super(n),this.value=t}get schema(){return{const:this.value}}},t.EnumField=class extends n{enumValues;value;constructor(t,n,r=e){super(r),this.enumValues=t,this.value=n}get schema(){return{enum:Object.keys(this.enumValues)}}},t.Field=n,t.FloatField=class extends n{value;constructor(t,n=e){super(n),this.value=t}get schema(){return{type:"number",default:this.value}}},t.Form=class extends r{},t.FormArray=class extends n{factory;value;constructor(t,n,r=e){super(r),this.factory=t,this.value=n}get schema(){return{type:"array",items:this.factory().schema,default:this.value}}},t.FormGroup=r,t.ImageField=class extends n{value;constructor(t,n=e){super(n),this.value=t}get schema(){return{type:"string",default:this.value}}},t.IntegerField=class extends n{value;constructor(t,n=e){super(n),this.value=t}get schema(){return{type:"integer",default:this.value}}},t.KokimokiClient=class extends k{host;appId;code;_wsUrl;_apiUrl;_id;_token;_apiHeaders;_serverTimeOffset=0;_clientContext;_ws;_subscriptionsByName=new Map;_subscriptionsByHash=new Map;_subscribeReqPromises=new Map;_transactionPromises=new Map;_connected=!1;_connectPromise;_messageId=0;_reconnectTimeout=0;_pingInterval;constructor(t,e,n=""){super(),this.host=t,this.appId=e,this.code=n;const r=-1===this.host.indexOf(":");this._wsUrl=`ws${r?"s":""}://${this.host}`,this._apiUrl=`http${r?"s":""}://${this.host}`;const s=new Ds;s.writeInt32(Cs.Ping);const i=s.getBuffer();this._pingInterval=setInterval((()=>{this.connected&&this.ws.send(i)}),5e3)}get id(){if(!this._id)throw new Error("Client not connected");return this._id}get token(){if(!this._token)throw new Error("Client not connected");return this._token}get apiUrl(){if(!this._apiUrl)throw new Error("Client not connected");return this._apiUrl}get apiHeaders(){if(!this._apiHeaders)throw new Error("Client not connected");return this._apiHeaders}get clientContext(){if(void 0===this._clientContext)throw new Error("Client not connected");return this._clientContext}get connected(){return this._connected}get ws(){if(!this._ws)throw new Error("Not connected");return this._ws}async connect(){if(this._connectPromise)return await this._connectPromise;this._ws=new WebSocket(`${this._wsUrl}/apps/${this.appId}?clientVersion=1.0.8`),this._ws.binaryType="arraybuffer",window&&(window.__KOKIMOKI_WS__||(window.__KOKIMOKI_WS__={}),this.appId in window.__KOKIMOKI_WS__&&window.__KOKIMOKI_WS__[this.appId].close(),window.__KOKIMOKI_WS__[this.appId]=this._ws),this._connectPromise=new Promise((t=>{let e=localStorage.getItem("KM_TOKEN");this.ws.onopen=()=>{this.ws.send(JSON.stringify({type:"auth",code:this.code,token:e}))},this.ws.onclose=()=>{this._connected=!1,this._connectPromise=void 0,this._ws.onmessage=null,this._ws=void 0,window&&window.__KOKIMOKI_WS__&&delete window.__KOKIMOKI_WS__[this.appId],this._subscribeReqPromises.clear(),this._transactionPromises.clear(),console.log(`[Kokimoki] Connection lost, attempting to reconnect in ${this._reconnectTimeout} seconds...`),setTimeout((async()=>await this.connect()),1e3*this._reconnectTimeout),this._reconnectTimeout=Math.min(3,this._reconnectTimeout+1),this.emit("disconnected")},this.ws.onmessage=e=>{if(console.log(`Received WS message: ${e.data}`),"string"!=typeof e.data)this.handleBinaryMessage(e.data);else{const n=JSON.parse(e.data);if("init"===n.type)this.handleInitMessage(n),t()}}})),await this._connectPromise,this._connected=!0,console.log(`[Kokimoki] Client id: ${this.id}`),console.log("[Kokimoki] Client context:",this.clientContext);const t=Array.from(this._subscriptionsByName.keys()).map((t=>`"${t}"`));t.length&&console.log(`[Kokimoki] Restoring subscriptions: ${t}`);for(const t of this._subscriptionsByName.values())try{await this.join(t.store)}catch(e){console.error(`[Kokimoki] Failed to restore subscription for "${t.roomName}":`,e)}this._reconnectTimeout=0,this.emit("connected")}handleInitMessage(t){localStorage.setItem("KM_TOKEN",t.clientToken),this._id=t.clientId,this._token=t.appToken,this._clientContext=t.clientContext,this._apiHeaders=new Headers({Authorization:`Bearer ${this.token}`,"Content-Type":"application/json"})}handleBinaryMessage(t){const e=new Os(t);switch(e.readInt32()){case Cs.SubscribeRes:this.handleSubscribeResMessage(e);break;case Cs.RoomUpdate:this.handleRoomUpdateMessage(e);break;case Cs.Error:this.handleErrorMessage(e);break;case Cs.Pong:{const t=e.readInt32(),n=e.readInt32();this._serverTimeOffset=Date.now()-1e3*t-n;break}}}handleErrorMessage(t){const e=t.readInt32(),n=t.readString(),r=this._subscribeReqPromises.get(e),s=this._transactionPromises.get(e);r?(this._subscribeReqPromises.delete(e),r.reject(n)):s?(this._transactionPromises.delete(e),s.reject(n)):console.warn(`Received error for unknown request ${e}: ${n}`)}handleSubscribeResMessage(t){const e=t.readInt32(),n=t.readUint32(),r=this._subscribeReqPromises.get(e);r&&(this._subscribeReqPromises.delete(e),t.end?r.resolve(n):r.resolve(n,t.readUint8Array()))}handleRoomUpdateMessage(t){const e=t.readInt32(),n=t.readUint32();if(!t.end){const e=this._subscriptionsByHash.get(n);e?Be(e.store.doc,t.readUint8Array(),this):console.warn(`Received update for unknown room ${n}`)}for(const[t,{resolve:n}]of this._transactionPromises.entries())e>=t&&(this._transactionPromises.delete(t),n())}serverTimestamp(){return Date.now()-this._serverTimeOffset}async patchRoomState(t,e){const n=await fetch(`${this._apiUrl}/rooms/${t}`,{method:"PATCH",headers:this.apiHeaders,body:e});return await n.json()}async createUpload(t,e,n){const r=await fetch(`${this._apiUrl}/uploads`,{method:"POST",headers:this.apiHeaders,body:JSON.stringify({name:t,size:e.size,mimeType:e.type,tags:n})});return await r.json()}async uploadChunks(t,e,n){return await Promise.all(n.map((async(n,r)=>{const s=r*e,i=Math.min(s+e,t.size),o=t.slice(s,i),c=await fetch(n,{method:"PUT",body:o});return JSON.parse(c.headers.get("ETag")||'""')})))}async completeUpload(t,e){const n=await fetch(`${this._apiUrl}/uploads/${t}`,{method:"PUT",headers:this.apiHeaders,body:JSON.stringify({etags:e})});return await n.json()}async upload(t,e,n=[]){const{id:r,chunkSize:s,urls:i}=await this.createUpload(t,e,n),o=await this.uploadChunks(e,s,i);return await this.completeUpload(r,o)}async updateUpload(t,e){const n=await fetch(`${this._apiUrl}/uploads/${t}`,{method:"PUT",headers:this.apiHeaders,body:JSON.stringify(e)});return await n.json()}async listUploads(t={},e=0,n=100){const r=new URL("/uploads",this._apiUrl);r.searchParams.set("skip",e.toString()),r.searchParams.set("limit",n.toString()),t.clientId&&r.searchParams.set("clientId",t.clientId),t.mimeTypes&&r.searchParams.set("mimeTypes",t.mimeTypes.join()),t.tags&&r.searchParams.set("tags",t.tags.join());const s=await fetch(r.href,{headers:this.apiHeaders});return await s.json()}async deleteUpload(t){const e=await fetch(`${this._apiUrl}/uploads/${t}`,{method:"DELETE",headers:this.apiHeaders});return await e.json()}async exposeScriptingContext(t){window.KM_SCRIPTING_CONTEXT=t,window.dispatchEvent(new CustomEvent("km:scriptingContextExposed"))}async sendSubscriptionReq(t,e){const n=++this._messageId;return await new Promise(((r,s)=>{this._subscribeReqPromises.set(n,{resolve:(t,e)=>{r({roomHash:t,initialUpdate:e})},reject:s});const i=new Ds;i.writeInt32(Cs.SubscribeReq),i.writeInt32(n),i.writeString(t),i.writeChar(e),this.ws.send(i.getBuffer())}))}async join(t){let e=this._subscriptionsByName.get(t.roomName);if(e||(e=new xs(this,t),this._subscriptionsByName.set(t.roomName,e)),!e.joined){const n=await this.sendSubscriptionReq(t.roomName,t.mode);this._subscriptionsByHash.set(n.roomHash,e),await e.applyInitialResponse(n.roomHash,n.initialUpdate)}}async transact(t){if(!this._connected)throw new Error("Client not connected");const e=new Ss(this);t(e);const{updates:n,consumedMessages:r}=await e.getUpdates();if(!n.length)return;const s=new Ds;s.writeInt32(Cs.Transaction);const i=++this._messageId;s.writeInt32(i),s.writeInt32(r.size);for(const t of r){const e=this._subscriptionsByName.get(t);if(!e)throw new Error(`Cannot consume message in "${t}" because it hasn't been joined`);s.writeUint32(e.roomHash)}for(const{roomName:t,update:e}of n){const n=this._subscriptionsByName.get(t);if(!n)throw new Error(`Cannot send update to "${t}" because it hasn't been joined`);s.writeUint32(n.roomHash),s.writeUint8Array(e)}const o=s.getBuffer();await new Promise(((t,e)=>{this._transactionPromises.set(i,{resolve:t,reject:e});try{this.ws.send(o)}catch(t){throw console.log("Failed to send update to server:",t),t}}))}},t.KokimokiQueue=class extends Rs{payloadSchema;_emitter=new k;on=this._emitter.on.bind(this._emitter);off=this._emitter.off.bind(this._emitter);constructor(e,n,r){super(`/q/${e}`,t.KokimokiSchema.dict(t.KokimokiSchema.struct({timestamp:t.KokimokiSchema.number(),payload:n})),r),this.payloadSchema=n;const s=new Set;this.doc.on("update",(()=>{const t=[];for(const e in this.proxy)s.has(e)||(s.add(e),t.push({id:e,payload:this.proxy[e].payload}));t.length>0&&this._emitter.emit("messages",t)}))}},t.KokimokiStore=Rs,t.RoomSubscription=xs,t.TextField=class extends n{value;constructor(t,n=e){super(n),this.value=t}get schema(){return{type:"string",default:this.value}}},t}({});
|
|
2
|
+
//# sourceMappingURL=kokimoki.min.js.map
|