document-model 1.1.0-experimental.4 → 1.1.0-experimental.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/browser/cjs/document-model.js +21 -1
  3. package/dist/browser/cjs/document-model.js.map +1 -0
  4. package/dist/browser/cjs/document.js +18 -1
  5. package/dist/browser/cjs/document.js.map +1 -0
  6. package/dist/browser/cjs/index.js +18 -1
  7. package/dist/browser/cjs/index.js.map +1 -0
  8. package/dist/browser/cjs/internal/index-NVU298uP.js +49 -0
  9. package/dist/browser/cjs/internal/index-NVU298uP.js.map +1 -0
  10. package/dist/browser/cjs/internal/index-mGRVNAlq.js +2339 -0
  11. package/dist/browser/cjs/internal/index-mGRVNAlq.js.map +1 -0
  12. package/dist/browser/cjs/internal/object-Br60UD-O.js +4345 -0
  13. package/dist/browser/cjs/internal/object-Br60UD-O.js.map +1 -0
  14. package/dist/browser/es/document-model.js +16 -15
  15. package/dist/browser/es/document-model.js.map +1 -0
  16. package/dist/browser/es/document.js +13 -11
  17. package/dist/browser/es/document.js.map +1 -0
  18. package/dist/browser/es/index.js +13 -11
  19. package/dist/browser/es/index.js.map +1 -0
  20. package/dist/browser/es/internal/index-CUIVdtOX.js +2340 -0
  21. package/dist/browser/es/internal/index-CUIVdtOX.js.map +1 -0
  22. package/dist/browser/es/internal/index-DrVs-I4f.js +50 -0
  23. package/dist/browser/es/internal/index-DrVs-I4f.js.map +1 -0
  24. package/dist/browser/es/internal/object-CRn9ifD4.js +4346 -0
  25. package/dist/browser/es/internal/object-CRn9ifD4.js.map +1 -0
  26. package/dist/browser/src/document/object.d.ts +55 -5
  27. package/dist/browser/src/document/reducer.d.ts +13 -0
  28. package/dist/browser/src/document/types.d.ts +4 -0
  29. package/dist/browser/src/document/utils/base.d.ts +2 -1
  30. package/dist/browser/src/document/utils/document-helpers.d.ts +9 -0
  31. package/dist/node/cjs/document-model.js +25 -1
  32. package/dist/node/cjs/document-model.js.map +1 -0
  33. package/dist/node/cjs/document.js +22 -1
  34. package/dist/node/cjs/document.js.map +1 -0
  35. package/dist/node/cjs/index.js +22 -1
  36. package/dist/node/cjs/index.js.map +1 -0
  37. package/dist/node/cjs/internal/index-CUe2eK-w.js +49 -0
  38. package/dist/node/cjs/internal/index-CUe2eK-w.js.map +1 -0
  39. package/dist/node/cjs/internal/index-CXEcxd1A.js +2343 -0
  40. package/dist/node/cjs/internal/index-CXEcxd1A.js.map +1 -0
  41. package/dist/node/cjs/internal/object-BWoRFP9b.js +2347 -0
  42. package/dist/node/cjs/internal/object-BWoRFP9b.js.map +1 -0
  43. package/dist/node/es/document-model.js +15 -14
  44. package/dist/node/es/document-model.js.map +1 -0
  45. package/dist/node/es/document.js +13 -11
  46. package/dist/node/es/document.js.map +1 -0
  47. package/dist/node/es/index.js +13 -11
  48. package/dist/node/es/index.js.map +1 -0
  49. package/dist/node/es/internal/index-BrOKDV9w.js +50 -0
  50. package/dist/node/es/internal/index-BrOKDV9w.js.map +1 -0
  51. package/dist/node/es/internal/index-BzOhAlo9.js +2344 -0
  52. package/dist/node/es/internal/index-BzOhAlo9.js.map +1 -0
  53. package/dist/node/es/internal/object-tOQPLlfl.js +2348 -0
  54. package/dist/node/es/internal/object-tOQPLlfl.js.map +1 -0
  55. package/dist/node/src/document/object.d.ts +55 -5
  56. package/dist/node/src/document/reducer.d.ts +13 -0
  57. package/dist/node/src/document/types.d.ts +4 -0
  58. package/dist/node/src/document/utils/base.d.ts +2 -1
  59. package/dist/node/src/document/utils/document-helpers.d.ts +9 -0
  60. package/dist/src/document/object.d.ts +55 -5
  61. package/dist/src/document/reducer.d.ts +13 -0
  62. package/dist/src/document/types.d.ts +4 -0
  63. package/dist/src/document/utils/base.d.ts +2 -1
  64. package/dist/src/document/utils/document-helpers.d.ts +9 -0
  65. package/package.json +3 -1
  66. package/dist/browser/cjs/internal/index-BLpgsifL.js +0 -1
  67. package/dist/browser/cjs/internal/index-BTG_-qY6.js +0 -22
  68. package/dist/browser/cjs/internal/object-BHB7lY3H.js +0 -25
  69. package/dist/browser/es/internal/index-2Qq00NLA.js +0 -46
  70. package/dist/browser/es/internal/index-BD2hB9El.js +0 -2104
  71. package/dist/browser/es/internal/object-BW-G4r5m.js +0 -2798
  72. package/dist/node/cjs/internal/index-B31DqWHj.js +0 -1
  73. package/dist/node/cjs/internal/index-BBm_wnUa.js +0 -22
  74. package/dist/node/cjs/internal/object-CxVzP-Xe.js +0 -20
  75. package/dist/node/es/internal/index-BPCSW4M1.js +0 -2108
  76. package/dist/node/es/internal/index-C7I4OGkU.js +0 -46
  77. package/dist/node/es/internal/object-C-_SkpQ0.js +0 -1696
@@ -1,1696 +0,0 @@
1
- var ce = Object.defineProperty;
2
- var le = (t, e, i) => e in t ? ce(t, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : t[e] = i;
3
- var st = (t, e, i) => (le(t, typeof e != "symbol" ? e + "" : e, i), i);
4
- import { produce as pt, castDraft as at, castImmutable as me, freeze as ue } from "immer";
5
- import { z as f } from "zod";
6
- import Dt from "jszip";
7
- import fe from "crypto";
8
- import ut from "fs";
9
- import de from "https";
10
- import { join as ge } from "path";
11
- const Tt = (t) => t != null, he = f.any().refine((t) => Tt(t)), _t = f.enum(["LOAD_STATE"]), vt = f.enum(["PRUNE"]), Nt = f.enum(["REDO"]), It = f.enum(["SET_NAME"]), At = f.enum(["UNDO"]);
12
- function xe() {
13
- return f.object({
14
- __typename: f.literal("Action").optional(),
15
- type: f.string()
16
- });
17
- }
18
- function Y() {
19
- return f.literal("global").or(f.literal("local"));
20
- }
21
- function Pt() {
22
- return f.union([
23
- Mt(),
24
- Rt(),
25
- Ct(),
26
- Ft(),
27
- Lt()
28
- ]);
29
- }
30
- function ye() {
31
- return f.object({
32
- __typename: f.literal("DocumentFile").optional(),
33
- data: f.string(),
34
- extension: f.string().nullable(),
35
- fileName: f.string().nullable(),
36
- mimeType: f.string()
37
- });
38
- }
39
- function Mt() {
40
- return f.object({
41
- input: f.lazy(() => ht()),
42
- type: _t,
43
- scope: Y()
44
- });
45
- }
46
- function ht() {
47
- return f.object({
48
- operations: f.number(),
49
- state: f.lazy(() => zt())
50
- });
51
- }
52
- function zt() {
53
- return f.object({
54
- data: f.unknown().nullish(),
55
- name: f.string()
56
- });
57
- }
58
- function be() {
59
- return f.object({
60
- __typename: f.literal("Operation").optional(),
61
- hash: f.string(),
62
- index: f.number(),
63
- timestamp: f.string().datetime(),
64
- type: f.string()
65
- });
66
- }
67
- function Rt() {
68
- return f.object({
69
- input: f.lazy(() => xt()),
70
- type: vt,
71
- scope: Y()
72
- });
73
- }
74
- function xt() {
75
- return f.object({
76
- end: f.number().nullish(),
77
- start: f.number().nullish()
78
- });
79
- }
80
- const yt = f.number;
81
- function Ct() {
82
- return f.object({
83
- input: yt(),
84
- type: Nt,
85
- scope: Y()
86
- });
87
- }
88
- const bt = f.string;
89
- function Ft() {
90
- return f.object({
91
- input: bt(),
92
- type: It,
93
- scope: f.literal("global")
94
- });
95
- }
96
- function we() {
97
- return f.object({
98
- __typename: f.literal("SetNameOperation").optional(),
99
- hash: f.string(),
100
- index: f.number(),
101
- input: f.string(),
102
- timestamp: f.string().datetime(),
103
- type: f.string()
104
- });
105
- }
106
- const wt = f.number;
107
- function Lt() {
108
- return f.object({
109
- input: wt(),
110
- type: At,
111
- scope: Y()
112
- });
113
- }
114
- const ci = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
115
- __proto__: null,
116
- ActionSchema: xe,
117
- BaseActionSchema: Pt,
118
- DocumentFileSchema: ye,
119
- LoadStateActionInputSchema: ht,
120
- LoadStateActionSchema: Mt,
121
- LoadStateActionStateInputSchema: zt,
122
- Load_StateSchema: _t,
123
- OperationSchema: be,
124
- OperationScopeSchema: Y,
125
- PruneActionInputSchema: xt,
126
- PruneActionSchema: Rt,
127
- PruneSchema: vt,
128
- RedoActionInputSchema: yt,
129
- RedoActionSchema: Ct,
130
- RedoSchema: Nt,
131
- SetNameActionInputSchema: bt,
132
- SetNameActionSchema: Ft,
133
- SetNameOperationSchema: we,
134
- Set_NameSchema: It,
135
- UndoActionInputSchema: wt,
136
- UndoActionSchema: Lt,
137
- UndoSchema: At,
138
- definedNonNullAnySchema: he,
139
- isDefinedNonNullAny: Tt
140
- }, Symbol.toStringTag, { value: "Module" }));
141
- function Oe(t) {
142
- return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
143
- }
144
- var ft = { exports: {} };
145
- (function(t, e) {
146
- const { hasOwnProperty: i } = Object.prototype, n = C();
147
- n.configure = C, n.stringify = n, n.default = n, e.stringify = n, e.configure = C, t.exports = n;
148
- const o = /[\u0000-\u001f\u0022\u005c\ud800-\udfff]|[\ud800-\udbff](?![\udc00-\udfff])|(?:[^\ud800-\udbff]|^)[\udc00-\udfff]/;
149
- function a(c) {
150
- return c.length < 5e3 && !o.test(c) ? `"${c}"` : JSON.stringify(c);
151
- }
152
- function r(c) {
153
- if (c.length > 200)
154
- return c.sort();
155
- for (let l = 1; l < c.length; l++) {
156
- const u = c[l];
157
- let D = l;
158
- for (; D !== 0 && c[D - 1] > u; )
159
- c[D] = c[D - 1], D--;
160
- c[D] = u;
161
- }
162
- return c;
163
- }
164
- const p = Object.getOwnPropertyDescriptor(
165
- Object.getPrototypeOf(
166
- Object.getPrototypeOf(
167
- new Int8Array()
168
- )
169
- ),
170
- Symbol.toStringTag
171
- ).get;
172
- function m(c) {
173
- return p.call(c) !== void 0 && c.length !== 0;
174
- }
175
- function d(c, l, u) {
176
- c.length < u && (u = c.length);
177
- const D = l === "," ? "" : " ";
178
- let F = `"0":${D}${c[0]}`;
179
- for (let M = 1; M < u; M++)
180
- F += `${l}"${M}":${D}${c[M]}`;
181
- return F;
182
- }
183
- function h(c) {
184
- if (i.call(c, "circularValue")) {
185
- const l = c.circularValue;
186
- if (typeof l == "string")
187
- return `"${l}"`;
188
- if (l == null)
189
- return l;
190
- if (l === Error || l === TypeError)
191
- return {
192
- toString() {
193
- throw new TypeError("Converting circular structure to JSON");
194
- }
195
- };
196
- throw new TypeError('The "circularValue" argument must be of type string or the value null or undefined');
197
- }
198
- return '"[Circular]"';
199
- }
200
- function b(c, l) {
201
- let u;
202
- if (i.call(c, l) && (u = c[l], typeof u != "boolean"))
203
- throw new TypeError(`The "${l}" argument must be of type boolean`);
204
- return u === void 0 ? !0 : u;
205
- }
206
- function w(c, l) {
207
- let u;
208
- if (i.call(c, l)) {
209
- if (u = c[l], typeof u != "number")
210
- throw new TypeError(`The "${l}" argument must be of type number`);
211
- if (!Number.isInteger(u))
212
- throw new TypeError(`The "${l}" argument must be an integer`);
213
- if (u < 1)
214
- throw new RangeError(`The "${l}" argument must be >= 1`);
215
- }
216
- return u === void 0 ? 1 / 0 : u;
217
- }
218
- function N(c) {
219
- return c === 1 ? "1 item" : `${c} items`;
220
- }
221
- function $(c) {
222
- const l = /* @__PURE__ */ new Set();
223
- for (const u of c)
224
- (typeof u == "string" || typeof u == "number") && l.add(String(u));
225
- return l;
226
- }
227
- function P(c) {
228
- if (i.call(c, "strict")) {
229
- const l = c.strict;
230
- if (typeof l != "boolean")
231
- throw new TypeError('The "strict" argument must be of type boolean');
232
- if (l)
233
- return (u) => {
234
- let D = `Object can not safely be stringified. Received type ${typeof u}`;
235
- throw typeof u != "function" && (D += ` (${u.toString()})`), new Error(D);
236
- };
237
- }
238
- }
239
- function C(c) {
240
- c = { ...c };
241
- const l = P(c);
242
- l && (c.bigint === void 0 && (c.bigint = !1), "circularValue" in c || (c.circularValue = Error));
243
- const u = h(c), D = b(c, "bigint"), F = b(c, "deterministic"), M = w(c, "maximumDepth"), T = w(c, "maximumBreadth");
244
- function it(A, s, g, O, y, j) {
245
- let x = s[A];
246
- switch (typeof x == "object" && x !== null && typeof x.toJSON == "function" && (x = x.toJSON(A)), x = O.call(s, A, x), typeof x) {
247
- case "string":
248
- return a(x);
249
- case "object": {
250
- if (x === null)
251
- return "null";
252
- if (g.indexOf(x) !== -1)
253
- return u;
254
- let S = "", k = ",";
255
- const _ = j;
256
- if (Array.isArray(x)) {
257
- if (x.length === 0)
258
- return "[]";
259
- if (M < g.length + 1)
260
- return '"[Array]"';
261
- g.push(x), y !== "" && (j += y, S += `
262
- ${j}`, k = `,
263
- ${j}`);
264
- const R = Math.min(x.length, T);
265
- let U = 0;
266
- for (; U < R - 1; U++) {
267
- const ot = it(String(U), x, g, O, y, j);
268
- S += ot !== void 0 ? ot : "null", S += k;
269
- }
270
- const J = it(String(U), x, g, O, y, j);
271
- if (S += J !== void 0 ? J : "null", x.length - 1 > T) {
272
- const ot = x.length - T - 1;
273
- S += `${k}"... ${N(ot)} not stringified"`;
274
- }
275
- return y !== "" && (S += `
276
- ${_}`), g.pop(), `[${S}]`;
277
- }
278
- let v = Object.keys(x);
279
- const I = v.length;
280
- if (I === 0)
281
- return "{}";
282
- if (M < g.length + 1)
283
- return '"[Object]"';
284
- let E = "", z = "";
285
- y !== "" && (j += y, k = `,
286
- ${j}`, E = " ");
287
- const q = Math.min(I, T);
288
- F && !m(x) && (v = r(v)), g.push(x);
289
- for (let R = 0; R < q; R++) {
290
- const U = v[R], J = it(U, x, g, O, y, j);
291
- J !== void 0 && (S += `${z}${a(U)}:${E}${J}`, z = k);
292
- }
293
- if (I > T) {
294
- const R = I - T;
295
- S += `${z}"...":${E}"${N(R)} not stringified"`, z = k;
296
- }
297
- return y !== "" && z.length > 1 && (S = `
298
- ${j}${S}
299
- ${_}`), g.pop(), `{${S}}`;
300
- }
301
- case "number":
302
- return isFinite(x) ? String(x) : l ? l(x) : "null";
303
- case "boolean":
304
- return x === !0 ? "true" : "false";
305
- case "undefined":
306
- return;
307
- case "bigint":
308
- if (D)
309
- return String(x);
310
- default:
311
- return l ? l(x) : void 0;
312
- }
313
- }
314
- function nt(A, s, g, O, y, j) {
315
- switch (typeof s == "object" && s !== null && typeof s.toJSON == "function" && (s = s.toJSON(A)), typeof s) {
316
- case "string":
317
- return a(s);
318
- case "object": {
319
- if (s === null)
320
- return "null";
321
- if (g.indexOf(s) !== -1)
322
- return u;
323
- const x = j;
324
- let S = "", k = ",";
325
- if (Array.isArray(s)) {
326
- if (s.length === 0)
327
- return "[]";
328
- if (M < g.length + 1)
329
- return '"[Array]"';
330
- g.push(s), y !== "" && (j += y, S += `
331
- ${j}`, k = `,
332
- ${j}`);
333
- const I = Math.min(s.length, T);
334
- let E = 0;
335
- for (; E < I - 1; E++) {
336
- const q = nt(String(E), s[E], g, O, y, j);
337
- S += q !== void 0 ? q : "null", S += k;
338
- }
339
- const z = nt(String(E), s[E], g, O, y, j);
340
- if (S += z !== void 0 ? z : "null", s.length - 1 > T) {
341
- const q = s.length - T - 1;
342
- S += `${k}"... ${N(q)} not stringified"`;
343
- }
344
- return y !== "" && (S += `
345
- ${x}`), g.pop(), `[${S}]`;
346
- }
347
- g.push(s);
348
- let _ = "";
349
- y !== "" && (j += y, k = `,
350
- ${j}`, _ = " ");
351
- let v = "";
352
- for (const I of O) {
353
- const E = nt(I, s[I], g, O, y, j);
354
- E !== void 0 && (S += `${v}${a(I)}:${_}${E}`, v = k);
355
- }
356
- return y !== "" && v.length > 1 && (S = `
357
- ${j}${S}
358
- ${x}`), g.pop(), `{${S}}`;
359
- }
360
- case "number":
361
- return isFinite(s) ? String(s) : l ? l(s) : "null";
362
- case "boolean":
363
- return s === !0 ? "true" : "false";
364
- case "undefined":
365
- return;
366
- case "bigint":
367
- if (D)
368
- return String(s);
369
- default:
370
- return l ? l(s) : void 0;
371
- }
372
- }
373
- function G(A, s, g, O, y) {
374
- switch (typeof s) {
375
- case "string":
376
- return a(s);
377
- case "object": {
378
- if (s === null)
379
- return "null";
380
- if (typeof s.toJSON == "function") {
381
- if (s = s.toJSON(A), typeof s != "object")
382
- return G(A, s, g, O, y);
383
- if (s === null)
384
- return "null";
385
- }
386
- if (g.indexOf(s) !== -1)
387
- return u;
388
- const j = y;
389
- if (Array.isArray(s)) {
390
- if (s.length === 0)
391
- return "[]";
392
- if (M < g.length + 1)
393
- return '"[Array]"';
394
- g.push(s), y += O;
395
- let E = `
396
- ${y}`;
397
- const z = `,
398
- ${y}`, q = Math.min(s.length, T);
399
- let R = 0;
400
- for (; R < q - 1; R++) {
401
- const J = G(String(R), s[R], g, O, y);
402
- E += J !== void 0 ? J : "null", E += z;
403
- }
404
- const U = G(String(R), s[R], g, O, y);
405
- if (E += U !== void 0 ? U : "null", s.length - 1 > T) {
406
- const J = s.length - T - 1;
407
- E += `${z}"... ${N(J)} not stringified"`;
408
- }
409
- return E += `
410
- ${j}`, g.pop(), `[${E}]`;
411
- }
412
- let x = Object.keys(s);
413
- const S = x.length;
414
- if (S === 0)
415
- return "{}";
416
- if (M < g.length + 1)
417
- return '"[Object]"';
418
- y += O;
419
- const k = `,
420
- ${y}`;
421
- let _ = "", v = "", I = Math.min(S, T);
422
- m(s) && (_ += d(s, k, T), x = x.slice(s.length), I -= s.length, v = k), F && (x = r(x)), g.push(s);
423
- for (let E = 0; E < I; E++) {
424
- const z = x[E], q = G(z, s[z], g, O, y);
425
- q !== void 0 && (_ += `${v}${a(z)}: ${q}`, v = k);
426
- }
427
- if (S > T) {
428
- const E = S - T;
429
- _ += `${v}"...": "${N(E)} not stringified"`, v = k;
430
- }
431
- return v !== "" && (_ = `
432
- ${y}${_}
433
- ${j}`), g.pop(), `{${_}}`;
434
- }
435
- case "number":
436
- return isFinite(s) ? String(s) : l ? l(s) : "null";
437
- case "boolean":
438
- return s === !0 ? "true" : "false";
439
- case "undefined":
440
- return;
441
- case "bigint":
442
- if (D)
443
- return String(s);
444
- default:
445
- return l ? l(s) : void 0;
446
- }
447
- }
448
- function Z(A, s, g) {
449
- switch (typeof s) {
450
- case "string":
451
- return a(s);
452
- case "object": {
453
- if (s === null)
454
- return "null";
455
- if (typeof s.toJSON == "function") {
456
- if (s = s.toJSON(A), typeof s != "object")
457
- return Z(A, s, g);
458
- if (s === null)
459
- return "null";
460
- }
461
- if (g.indexOf(s) !== -1)
462
- return u;
463
- let O = "";
464
- if (Array.isArray(s)) {
465
- if (s.length === 0)
466
- return "[]";
467
- if (M < g.length + 1)
468
- return '"[Array]"';
469
- g.push(s);
470
- const k = Math.min(s.length, T);
471
- let _ = 0;
472
- for (; _ < k - 1; _++) {
473
- const I = Z(String(_), s[_], g);
474
- O += I !== void 0 ? I : "null", O += ",";
475
- }
476
- const v = Z(String(_), s[_], g);
477
- if (O += v !== void 0 ? v : "null", s.length - 1 > T) {
478
- const I = s.length - T - 1;
479
- O += `,"... ${N(I)} not stringified"`;
480
- }
481
- return g.pop(), `[${O}]`;
482
- }
483
- let y = Object.keys(s);
484
- const j = y.length;
485
- if (j === 0)
486
- return "{}";
487
- if (M < g.length + 1)
488
- return '"[Object]"';
489
- let x = "", S = Math.min(j, T);
490
- m(s) && (O += d(s, ",", T), y = y.slice(s.length), S -= s.length, x = ","), F && (y = r(y)), g.push(s);
491
- for (let k = 0; k < S; k++) {
492
- const _ = y[k], v = Z(_, s[_], g);
493
- v !== void 0 && (O += `${x}${a(_)}:${v}`, x = ",");
494
- }
495
- if (j > T) {
496
- const k = j - T;
497
- O += `${x}"...":"${N(k)} not stringified"`;
498
- }
499
- return g.pop(), `{${O}}`;
500
- }
501
- case "number":
502
- return isFinite(s) ? String(s) : l ? l(s) : "null";
503
- case "boolean":
504
- return s === !0 ? "true" : "false";
505
- case "undefined":
506
- return;
507
- case "bigint":
508
- if (D)
509
- return String(s);
510
- default:
511
- return l ? l(s) : void 0;
512
- }
513
- }
514
- function pe(A, s, g) {
515
- if (arguments.length > 1) {
516
- let O = "";
517
- if (typeof g == "number" ? O = " ".repeat(Math.min(g, 10)) : typeof g == "string" && (O = g.slice(0, 10)), s != null) {
518
- if (typeof s == "function")
519
- return it("", { "": A }, [], s, O, "");
520
- if (Array.isArray(s))
521
- return nt("", A, [], $(s), O, "");
522
- }
523
- if (O.length !== 0)
524
- return G("", A, [], O, "");
525
- }
526
- return Z("", A, []);
527
- }
528
- return pe;
529
- }
530
- })(ft, ft.exports);
531
- var Se = ft.exports;
532
- const K = /* @__PURE__ */ Oe(Se);
533
- K.configure;
534
- function je(t, e) {
535
- return { ...t, name: e };
536
- }
537
- function Ee(t, e, i) {
538
- const { scope: n, input: o } = e;
539
- return pt({
540
- document: t,
541
- action: e,
542
- skip: i
543
- }, (r) => {
544
- if (r.document.operations[n].length < 1)
545
- throw new Error(
546
- `Cannot undo: no operations in history for scope "${n}"`
547
- );
548
- if (o < 1)
549
- throw new Error(
550
- "Invalid UNDO action: input value must be greater than 0"
551
- );
552
- if (r.skip > 0)
553
- throw new Error(
554
- "Cannot undo: skip value from reducer cannot be used with UNDO action"
555
- );
556
- const p = r.document.operations[n].at(-1), m = p && p.type === "NOOP" && p.skip > 0;
557
- if (r.skip += o, m) {
558
- r.skip += p.skip;
559
- const w = r.document.operations[n][r.document.operations[n].length - 2];
560
- w && p.index - w.index === 1 && r.document.operations[n].pop();
561
- }
562
- if (r.document.operations[n].length < r.skip)
563
- throw new Error(
564
- "Cannot undo: you can't undo more operations than the ones in the scope history"
565
- );
566
- const d = r.document.operations[n].length - 1;
567
- let h = o, b = m ? d - p.skip : d;
568
- for (; h > 0 && b >= 0; ) {
569
- const w = r.document.operations[n][b];
570
- if (!w) {
571
- h--, b--;
572
- continue;
573
- }
574
- w.type === "NOOP" && w.skip > 0 ? (b = b - (w.skip + 1), r.skip += w.skip + 1) : (r.document.clipboard.push({ ...w }), h--, b--);
575
- }
576
- r.action = ae(n);
577
- });
578
- }
579
- function $e(t, e, i) {
580
- const { scope: n, input: o } = e;
581
- return pt({
582
- document: t,
583
- action: e,
584
- skip: i
585
- }, (r) => {
586
- if (r.skip > 0)
587
- throw new Error(
588
- "Cannot redo: skip value from reducer cannot be used with REDO action"
589
- );
590
- if (o > 1)
591
- throw new Error(
592
- "Cannot redo: you can only redo one operation at a time"
593
- );
594
- if (o < 1)
595
- throw new Error("Invalid REDO action: invalid redo input value");
596
- if (r.document.clipboard.length < 1)
597
- throw new Error("Cannot redo: no operations in the clipboard");
598
- const p = r.document.clipboard.findLastIndex(
599
- (d) => d.scope === n
600
- );
601
- if (p < 0)
602
- throw new Error(
603
- `Cannot redo: no operations in clipboard for scope "${n}"`
604
- );
605
- const m = r.document.clipboard.splice(p, 1)[0];
606
- r.action = at({
607
- type: m.type,
608
- scope: m.scope,
609
- input: m.input
610
- });
611
- });
612
- }
613
- function ke(t, e, i) {
614
- const { scope: n } = e, o = t.operations[n];
615
- let {
616
- input: { start: a, end: r }
617
- } = e;
618
- a = a || 0, r = r || o.length;
619
- const p = o.slice(a, r), m = o.slice(0, a), d = o.slice(r), h = gt(
620
- t.initialState,
621
- {
622
- ...t.operations,
623
- [n]: m.concat(p)
624
- },
625
- i
626
- ), { name: b, state: w } = h, N = m.length, $ = m.length ? m[m.length - 1].timestamp : d.length ? d[0].timestamp : (/* @__PURE__ */ new Date()).toISOString();
627
- return gt(
628
- t.initialState,
629
- {
630
- ...t.operations,
631
- [n]: [
632
- ...m,
633
- {
634
- ...Et(
635
- { name: b, state: w },
636
- p.length
637
- ),
638
- timestamp: $,
639
- index: N,
640
- hash: jt({ state: w }, "global")
641
- },
642
- ...d.map((P, C) => ({
643
- ...P,
644
- index: N + C + 1
645
- }))
646
- ]
647
- },
648
- i
649
- );
650
- }
651
- function De(t, e) {
652
- return {
653
- ...t,
654
- name: e.name,
655
- state: e.state ?? { global: {}, local: {} }
656
- };
657
- }
658
- const qt = "SET_NAME", tt = "UNDO", et = "REDO", ct = "PRUNE", Ut = "LOAD_STATE", Te = "NOOP", Jt = { "application/andrew-inset": ["ez"], "application/appinstaller": ["appinstaller"], "application/applixware": ["aw"], "application/appx": ["appx"], "application/appxbundle": ["appxbundle"], "application/atom+xml": ["atom"], "application/atomcat+xml": ["atomcat"], "application/atomdeleted+xml": ["atomdeleted"], "application/atomsvc+xml": ["atomsvc"], "application/atsc-dwd+xml": ["dwd"], "application/atsc-held+xml": ["held"], "application/atsc-rsat+xml": ["rsat"], "application/automationml-aml+xml": ["aml"], "application/automationml-amlx+zip": ["amlx"], "application/bdoc": ["bdoc"], "application/calendar+xml": ["xcs"], "application/ccxml+xml": ["ccxml"], "application/cdfx+xml": ["cdfx"], "application/cdmi-capability": ["cdmia"], "application/cdmi-container": ["cdmic"], "application/cdmi-domain": ["cdmid"], "application/cdmi-object": ["cdmio"], "application/cdmi-queue": ["cdmiq"], "application/cpl+xml": ["cpl"], "application/cu-seeme": ["cu"], "application/cwl": ["cwl"], "application/dash+xml": ["mpd"], "application/dash-patch+xml": ["mpp"], "application/davmount+xml": ["davmount"], "application/docbook+xml": ["dbk"], "application/dssc+der": ["dssc"], "application/dssc+xml": ["xdssc"], "application/ecmascript": ["ecma"], "application/emma+xml": ["emma"], "application/emotionml+xml": ["emotionml"], "application/epub+zip": ["epub"], "application/exi": ["exi"], "application/express": ["exp"], "application/fdf": ["fdf"], "application/fdt+xml": ["fdt"], "application/font-tdpfr": ["pfr"], "application/geo+json": ["geojson"], "application/gml+xml": ["gml"], "application/gpx+xml": ["gpx"], "application/gxf": ["gxf"], "application/gzip": ["gz"], "application/hjson": ["hjson"], "application/hyperstudio": ["stk"], "application/inkml+xml": ["ink", "inkml"], "application/ipfix": ["ipfix"], "application/its+xml": ["its"], "application/java-archive": ["jar", "war", "ear"], "application/java-serialized-object": ["ser"], "application/java-vm": ["class"], "application/javascript": ["*js"], "application/json": ["json", "map"], "application/json5": ["json5"], "application/jsonml+json": ["jsonml"], "application/ld+json": ["jsonld"], "application/lgr+xml": ["lgr"], "application/lost+xml": ["lostxml"], "application/mac-binhex40": ["hqx"], "application/mac-compactpro": ["cpt"], "application/mads+xml": ["mads"], "application/manifest+json": ["webmanifest"], "application/marc": ["mrc"], "application/marcxml+xml": ["mrcx"], "application/mathematica": ["ma", "nb", "mb"], "application/mathml+xml": ["mathml"], "application/mbox": ["mbox"], "application/media-policy-dataset+xml": ["mpf"], "application/mediaservercontrol+xml": ["mscml"], "application/metalink+xml": ["metalink"], "application/metalink4+xml": ["meta4"], "application/mets+xml": ["mets"], "application/mmt-aei+xml": ["maei"], "application/mmt-usd+xml": ["musd"], "application/mods+xml": ["mods"], "application/mp21": ["m21", "mp21"], "application/mp4": ["*mp4", "*mpg4", "mp4s", "m4p"], "application/msix": ["msix"], "application/msixbundle": ["msixbundle"], "application/msword": ["doc", "dot"], "application/mxf": ["mxf"], "application/n-quads": ["nq"], "application/n-triples": ["nt"], "application/node": ["cjs"], "application/octet-stream": ["bin", "dms", "lrf", "mar", "so", "dist", "distz", "pkg", "bpk", "dump", "elc", "deploy", "exe", "dll", "deb", "dmg", "iso", "img", "msi", "msp", "msm", "buffer"], "application/oda": ["oda"], "application/oebps-package+xml": ["opf"], "application/ogg": ["ogx"], "application/omdoc+xml": ["omdoc"], "application/onenote": ["onetoc", "onetoc2", "onetmp", "onepkg"], "application/oxps": ["oxps"], "application/p2p-overlay+xml": ["relo"], "application/patch-ops-error+xml": ["xer"], "application/pdf": ["pdf"], "application/pgp-encrypted": ["pgp"], "application/pgp-keys": ["asc"], "application/pgp-signature": ["sig", "*asc"], "application/pics-rules": ["prf"], "application/pkcs10": ["p10"], "application/pkcs7-mime": ["p7m", "p7c"], "application/pkcs7-signature": ["p7s"], "application/pkcs8": ["p8"], "application/pkix-attr-cert": ["ac"], "application/pkix-cert": ["cer"], "application/pkix-crl": ["crl"], "application/pkix-pkipath": ["pkipath"], "application/pkixcmp": ["pki"], "application/pls+xml": ["pls"], "application/postscript": ["ai", "eps", "ps"], "application/provenance+xml": ["provx"], "application/pskc+xml": ["pskcxml"], "application/raml+yaml": ["raml"], "application/rdf+xml": ["rdf", "owl"], "application/reginfo+xml": ["rif"], "application/relax-ng-compact-syntax": ["rnc"], "application/resource-lists+xml": ["rl"], "application/resource-lists-diff+xml": ["rld"], "application/rls-services+xml": ["rs"], "application/route-apd+xml": ["rapd"], "application/route-s-tsid+xml": ["sls"], "application/route-usd+xml": ["rusd"], "application/rpki-ghostbusters": ["gbr"], "application/rpki-manifest": ["mft"], "application/rpki-roa": ["roa"], "application/rsd+xml": ["rsd"], "application/rss+xml": ["rss"], "application/rtf": ["rtf"], "application/sbml+xml": ["sbml"], "application/scvp-cv-request": ["scq"], "application/scvp-cv-response": ["scs"], "application/scvp-vp-request": ["spq"], "application/scvp-vp-response": ["spp"], "application/sdp": ["sdp"], "application/senml+xml": ["senmlx"], "application/sensml+xml": ["sensmlx"], "application/set-payment-initiation": ["setpay"], "application/set-registration-initiation": ["setreg"], "application/shf+xml": ["shf"], "application/sieve": ["siv", "sieve"], "application/smil+xml": ["smi", "smil"], "application/sparql-query": ["rq"], "application/sparql-results+xml": ["srx"], "application/sql": ["sql"], "application/srgs": ["gram"], "application/srgs+xml": ["grxml"], "application/sru+xml": ["sru"], "application/ssdl+xml": ["ssdl"], "application/ssml+xml": ["ssml"], "application/swid+xml": ["swidtag"], "application/tei+xml": ["tei", "teicorpus"], "application/thraud+xml": ["tfi"], "application/timestamped-data": ["tsd"], "application/toml": ["toml"], "application/trig": ["trig"], "application/ttml+xml": ["ttml"], "application/ubjson": ["ubj"], "application/urc-ressheet+xml": ["rsheet"], "application/urc-targetdesc+xml": ["td"], "application/voicexml+xml": ["vxml"], "application/wasm": ["wasm"], "application/watcherinfo+xml": ["wif"], "application/widget": ["wgt"], "application/winhlp": ["hlp"], "application/wsdl+xml": ["wsdl"], "application/wspolicy+xml": ["wspolicy"], "application/xaml+xml": ["xaml"], "application/xcap-att+xml": ["xav"], "application/xcap-caps+xml": ["xca"], "application/xcap-diff+xml": ["xdf"], "application/xcap-el+xml": ["xel"], "application/xcap-ns+xml": ["xns"], "application/xenc+xml": ["xenc"], "application/xfdf": ["xfdf"], "application/xhtml+xml": ["xhtml", "xht"], "application/xliff+xml": ["xlf"], "application/xml": ["xml", "xsl", "xsd", "rng"], "application/xml-dtd": ["dtd"], "application/xop+xml": ["xop"], "application/xproc+xml": ["xpl"], "application/xslt+xml": ["*xsl", "xslt"], "application/xspf+xml": ["xspf"], "application/xv+xml": ["mxml", "xhvml", "xvml", "xvm"], "application/yang": ["yang"], "application/yin+xml": ["yin"], "application/zip": ["zip"], "audio/3gpp": ["*3gpp"], "audio/aac": ["adts", "aac"], "audio/adpcm": ["adp"], "audio/amr": ["amr"], "audio/basic": ["au", "snd"], "audio/midi": ["mid", "midi", "kar", "rmi"], "audio/mobile-xmf": ["mxmf"], "audio/mp3": ["*mp3"], "audio/mp4": ["m4a", "mp4a"], "audio/mpeg": ["mpga", "mp2", "mp2a", "mp3", "m2a", "m3a"], "audio/ogg": ["oga", "ogg", "spx", "opus"], "audio/s3m": ["s3m"], "audio/silk": ["sil"], "audio/wav": ["wav"], "audio/wave": ["*wav"], "audio/webm": ["weba"], "audio/xm": ["xm"], "font/collection": ["ttc"], "font/otf": ["otf"], "font/ttf": ["ttf"], "font/woff": ["woff"], "font/woff2": ["woff2"], "image/aces": ["exr"], "image/apng": ["apng"], "image/avci": ["avci"], "image/avcs": ["avcs"], "image/avif": ["avif"], "image/bmp": ["bmp", "dib"], "image/cgm": ["cgm"], "image/dicom-rle": ["drle"], "image/dpx": ["dpx"], "image/emf": ["emf"], "image/fits": ["fits"], "image/g3fax": ["g3"], "image/gif": ["gif"], "image/heic": ["heic"], "image/heic-sequence": ["heics"], "image/heif": ["heif"], "image/heif-sequence": ["heifs"], "image/hej2k": ["hej2"], "image/hsj2": ["hsj2"], "image/ief": ["ief"], "image/jls": ["jls"], "image/jp2": ["jp2", "jpg2"], "image/jpeg": ["jpeg", "jpg", "jpe"], "image/jph": ["jph"], "image/jphc": ["jhc"], "image/jpm": ["jpm", "jpgm"], "image/jpx": ["jpx", "jpf"], "image/jxr": ["jxr"], "image/jxra": ["jxra"], "image/jxrs": ["jxrs"], "image/jxs": ["jxs"], "image/jxsc": ["jxsc"], "image/jxsi": ["jxsi"], "image/jxss": ["jxss"], "image/ktx": ["ktx"], "image/ktx2": ["ktx2"], "image/png": ["png"], "image/sgi": ["sgi"], "image/svg+xml": ["svg", "svgz"], "image/t38": ["t38"], "image/tiff": ["tif", "tiff"], "image/tiff-fx": ["tfx"], "image/webp": ["webp"], "image/wmf": ["wmf"], "message/disposition-notification": ["disposition-notification"], "message/global": ["u8msg"], "message/global-delivery-status": ["u8dsn"], "message/global-disposition-notification": ["u8mdn"], "message/global-headers": ["u8hdr"], "message/rfc822": ["eml", "mime"], "model/3mf": ["3mf"], "model/gltf+json": ["gltf"], "model/gltf-binary": ["glb"], "model/iges": ["igs", "iges"], "model/jt": ["jt"], "model/mesh": ["msh", "mesh", "silo"], "model/mtl": ["mtl"], "model/obj": ["obj"], "model/prc": ["prc"], "model/step+xml": ["stpx"], "model/step+zip": ["stpz"], "model/step-xml+zip": ["stpxz"], "model/stl": ["stl"], "model/u3d": ["u3d"], "model/vrml": ["wrl", "vrml"], "model/x3d+binary": ["*x3db", "x3dbz"], "model/x3d+fastinfoset": ["x3db"], "model/x3d+vrml": ["*x3dv", "x3dvz"], "model/x3d+xml": ["x3d", "x3dz"], "model/x3d-vrml": ["x3dv"], "text/cache-manifest": ["appcache", "manifest"], "text/calendar": ["ics", "ifb"], "text/coffeescript": ["coffee", "litcoffee"], "text/css": ["css"], "text/csv": ["csv"], "text/html": ["html", "htm", "shtml"], "text/jade": ["jade"], "text/javascript": ["js", "mjs"], "text/jsx": ["jsx"], "text/less": ["less"], "text/markdown": ["md", "markdown"], "text/mathml": ["mml"], "text/mdx": ["mdx"], "text/n3": ["n3"], "text/plain": ["txt", "text", "conf", "def", "list", "log", "in", "ini"], "text/richtext": ["rtx"], "text/rtf": ["*rtf"], "text/sgml": ["sgml", "sgm"], "text/shex": ["shex"], "text/slim": ["slim", "slm"], "text/spdx": ["spdx"], "text/stylus": ["stylus", "styl"], "text/tab-separated-values": ["tsv"], "text/troff": ["t", "tr", "roff", "man", "me", "ms"], "text/turtle": ["ttl"], "text/uri-list": ["uri", "uris", "urls"], "text/vcard": ["vcard"], "text/vtt": ["vtt"], "text/wgsl": ["wgsl"], "text/xml": ["*xml"], "text/yaml": ["yaml", "yml"], "video/3gpp": ["3gp", "3gpp"], "video/3gpp2": ["3g2"], "video/h261": ["h261"], "video/h263": ["h263"], "video/h264": ["h264"], "video/iso.segment": ["m4s"], "video/jpeg": ["jpgv"], "video/jpm": ["*jpm", "*jpgm"], "video/mj2": ["mj2", "mjp2"], "video/mp2t": ["ts"], "video/mp4": ["mp4", "mp4v", "mpg4"], "video/mpeg": ["mpeg", "mpg", "mpe", "m1v", "m2v"], "video/ogg": ["ogv"], "video/quicktime": ["qt", "mov"], "video/webm": ["webm"] };
659
- Object.freeze(Jt);
660
- var L = function(t, e, i, n) {
661
- if (i === "a" && !n)
662
- throw new TypeError("Private accessor was defined without a getter");
663
- if (typeof e == "function" ? t !== e || !n : !e.has(t))
664
- throw new TypeError("Cannot read private member from an object whose class did not declare it");
665
- return i === "m" ? n : i === "a" ? n.call(t) : n ? n.value : e.get(t);
666
- }, B, Q, X;
667
- class _e {
668
- constructor(...e) {
669
- B.set(this, /* @__PURE__ */ new Map()), Q.set(this, /* @__PURE__ */ new Map()), X.set(this, /* @__PURE__ */ new Map());
670
- for (const i of e)
671
- this.define(i);
672
- }
673
- define(e, i = !1) {
674
- for (let [n, o] of Object.entries(e)) {
675
- n = n.toLowerCase(), o = o.map((p) => p.toLowerCase()), L(this, X, "f").has(n) || L(this, X, "f").set(n, /* @__PURE__ */ new Set());
676
- const a = L(this, X, "f").get(n);
677
- let r = !0;
678
- for (let p of o) {
679
- const m = p.startsWith("*");
680
- if (p = m ? p.slice(1) : p, a == null || a.add(p), r && L(this, Q, "f").set(n, p), r = !1, m)
681
- continue;
682
- const d = L(this, B, "f").get(p);
683
- if (d && d != n && !i)
684
- throw new Error(`"${n} -> ${p}" conflicts with "${d} -> ${p}". Pass \`force=true\` to override this definition.`);
685
- L(this, B, "f").set(p, n);
686
- }
687
- }
688
- return this;
689
- }
690
- getType(e) {
691
- if (typeof e != "string")
692
- return null;
693
- const i = e.replace(/^.*[/\\]/, "").toLowerCase(), n = i.replace(/^.*\./, "").toLowerCase(), o = i.length < e.length;
694
- return !(n.length < i.length - 1) && o ? null : L(this, B, "f").get(n) ?? null;
695
- }
696
- getExtension(e) {
697
- var i;
698
- return typeof e != "string" ? null : (e = (i = e == null ? void 0 : e.split) == null ? void 0 : i.call(e, ";")[0], (e && L(this, Q, "f").get(e.trim().toLowerCase())) ?? null);
699
- }
700
- getAllExtensions(e) {
701
- return typeof e != "string" ? null : L(this, X, "f").get(e.toLowerCase()) ?? null;
702
- }
703
- _freeze() {
704
- this.define = () => {
705
- throw new Error("define() not allowed for built-in Mime objects. See https://github.com/broofa/mime/blob/main/README.md#custom-mime-instances");
706
- }, Object.freeze(this);
707
- for (const e of L(this, X, "f").values())
708
- Object.freeze(e);
709
- return this;
710
- }
711
- _getTestState() {
712
- return {
713
- types: L(this, B, "f"),
714
- extensions: L(this, Q, "f")
715
- };
716
- }
717
- }
718
- B = /* @__PURE__ */ new WeakMap(), Q = /* @__PURE__ */ new WeakMap(), X = /* @__PURE__ */ new WeakMap();
719
- const ve = new _e(Jt)._freeze();
720
- function Ne(t, e, i) {
721
- const n = ge(t, e);
722
- return ut.mkdirSync(t, { recursive: !0 }), new Promise((o, a) => {
723
- try {
724
- ut.writeFile(n, i, {}, (r) => {
725
- r ? a(r) : o(n);
726
- });
727
- } catch (r) {
728
- a(r);
729
- }
730
- });
731
- }
732
- function Vt(t) {
733
- return ut.readFileSync(t);
734
- }
735
- function Ie(t) {
736
- return new Promise((e, i) => {
737
- de.get(t, (n) => {
738
- const o = [], a = n.headers["content-type"];
739
- n.on("data", (r) => {
740
- o.push(r);
741
- }), n.on("end", () => {
742
- e({ buffer: Buffer.concat(o), mimeType: a });
743
- });
744
- }).on("error", (n) => {
745
- i(n);
746
- });
747
- });
748
- }
749
- const Ae = async (t) => Vt(t), lt = (t, e = "sha1") => fe.createHash(e).update(t).digest("base64");
750
- function Pe(t) {
751
- const e = [], i = Object.keys(t);
752
- for (const n of i) {
753
- const o = t[n].sort((a, r) => a.index - r.index);
754
- for (let a = 0; a < o.length; a++)
755
- o[a].index !== a && e.push({
756
- message: `Invalid operation index ${o[a].index} at position ${a}`,
757
- details: {
758
- position: a,
759
- operation: o[a],
760
- scope: o[a].scope
761
- }
762
- });
763
- }
764
- return e;
765
- }
766
- const Ht = async (t) => {
767
- const e = new Dt(), { name: i, revision: n, documentType: o, created: a, lastModified: r } = t, p = {
768
- name: i,
769
- revision: n,
770
- documentType: o,
771
- created: a,
772
- lastModified: r
773
- };
774
- return e.file("header.json", JSON.stringify(p, null, 2)), e.file(
775
- "state.json",
776
- JSON.stringify(t.initialState || {}, null, 2)
777
- ), e.file("operations.json", JSON.stringify(t.operations, null, 2)), Object.keys(t.attachments).forEach((d) => {
778
- const { data: h, ...b } = t.attachments[d];
779
- e.file(d, h, {
780
- base64: !0,
781
- createFolders: !0,
782
- comment: JSON.stringify(b)
783
- });
784
- }), e;
785
- }, Me = async (t, e, i, n) => {
786
- const a = await (await Ht(t)).generateAsync({
787
- type: "uint8array",
788
- streamFiles: !0
789
- }), r = n ?? t.name, p = `.${i}.zip`;
790
- return Ne(
791
- e,
792
- r.endsWith(p) ? r : `${r}${p}`,
793
- a
794
- );
795
- }, li = async (t, e) => {
796
- const n = await (await Ht(t)).generateAsync({ type: "blob" }), o = await e.createWritable();
797
- await o.write(n), await o.close();
798
- }, $t = async (t, e, i) => {
799
- const n = Vt(t);
800
- return ze(n, e, i);
801
- }, ze = async (t, e, i) => {
802
- const n = new Dt();
803
- return await n.loadAsync(t), Re(n, e, i);
804
- };
805
- async function Re(t, e, i) {
806
- const n = t.file("state.json");
807
- if (!n)
808
- throw new Error("Initial state not found");
809
- const o = await n.async("string"), a = JSON.parse(o), r = t.file("header.json");
810
- let p;
811
- r && (p = JSON.parse(await r.async("string")));
812
- const m = t.file("operations.json");
813
- if (!m)
814
- throw new Error("Operations history not found");
815
- const d = JSON.parse(
816
- await m.async("string")
817
- ), h = Pe(d);
818
- if (h.length) {
819
- const w = h.map((N) => N.message);
820
- throw new Error(w.join(`
821
- `));
822
- }
823
- let b = ee(
824
- a,
825
- d,
826
- e,
827
- void 0,
828
- p,
829
- {},
830
- i
831
- );
832
- return p && (b = {
833
- ...b,
834
- ...p
835
- }), b;
836
- }
837
- function Xt(t) {
838
- const e = t.replace(/^.*\./, "") || void 0, i = t.replace(/^.*[/\\]/, "") || void 0;
839
- return { extension: e, fileName: i };
840
- }
841
- async function mi(t) {
842
- const { buffer: e, mimeType: i = "application/octet-stream" } = await Ie(t), n = Xt(t), o = e.toString("base64");
843
- return {
844
- data: o,
845
- hash: lt(o),
846
- mimeType: i,
847
- ...n
848
- };
849
- }
850
- async function ui(t) {
851
- const e = await Ae(t), i = ve.getType(t) || "application/octet-stream", n = Xt(t), o = e.toString("base64");
852
- return { data: o, hash: lt(o), mimeType: i, ...n };
853
- }
854
- var Bt = /* @__PURE__ */ ((t) => (t.UNEXPECTED_INDEX = "UNEXPECTED_INDEX", t))(Bt || {}), Kt = /* @__PURE__ */ ((t) => (t.DUPLICATED_INDEX = "DUPLICATED_INDEX", t.MISSING_INDEX = "MISSING_INDEX", t))(Kt || {});
855
- function Ot(t) {
856
- const e = [];
857
- let i = -1;
858
- for (const n of t) {
859
- const o = n.index - n.skip;
860
- o !== i + 1 && e.push({
861
- operation: {
862
- index: n.index,
863
- skip: n.skip
864
- },
865
- issue: "UNEXPECTED_INDEX",
866
- category: o > i + 1 ? "MISSING_INDEX" : "DUPLICATED_INDEX",
867
- message: `Expected index ${i + 1} with skip 0 or equivalent, got index ${n.index} with skip ${n.skip}`
868
- }), i = n.index;
869
- }
870
- return e;
871
- }
872
- function V(t) {
873
- var n, o, a;
874
- const e = [];
875
- let i = t.length - 1;
876
- for (; i > -1; ) {
877
- e.unshift(t[i]);
878
- const r = (((n = t[i]) == null ? void 0 : n.index) || 0) - (((o = t[i]) == null ? void 0 : o.skip) || 0) - 1;
879
- let p = i - 1;
880
- for (; p > -1 && (((a = t[p]) == null ? void 0 : a.index) || 0) > r; )
881
- p--;
882
- i = p;
883
- }
884
- return e;
885
- }
886
- function Ce(t) {
887
- const e = [...t], i = e[e.length - 1];
888
- return i && (i.type === "NOOP" ? e.push({
889
- ...i,
890
- index: i.index,
891
- type: "NOOP",
892
- skip: Zt(t)
893
- }) : e.push({
894
- type: "NOOP",
895
- index: i.index + 1,
896
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
897
- input: {},
898
- skip: 1,
899
- scope: i.scope,
900
- hash: i.hash
901
- })), e;
902
- }
903
- function H(t) {
904
- return t.slice().sort((e, i) => e.skip - i.skip).sort((e, i) => e.index - i.index);
905
- }
906
- const Fe = (t, e, i) => [...e, ...i].sort(
907
- (n, o) => new Date(n.timestamp).getTime() - new Date(o.timestamp).getTime()
908
- ).map((n, o) => ({
909
- ...n,
910
- index: t.index + o,
911
- skip: o === 0 ? t.skip : 0
912
- })), Le = (t, e, i) => [...e, ...i].sort(
913
- (n, o) => new Date(n.timestamp).getTime() - new Date(o.timestamp).getTime()
914
- ).sort((n, o) => n.index - o.index).map((n, o) => ({
915
- ...n,
916
- index: t.index + o,
917
- skip: o === 0 ? t.skip : 0
918
- }));
919
- function St(t, e) {
920
- return K(t) === K(e);
921
- }
922
- function qe(t, e) {
923
- const i = V(H(t.slice())), n = V(H(e.slice()));
924
- if (i.length < 1)
925
- return [n, []];
926
- const o = [];
927
- let a = !1;
928
- for (; n.length > 0; ) {
929
- const r = n[0];
930
- let p = i.shift();
931
- for (; p && Wt(p, r); )
932
- o.push(p), p = i.shift();
933
- if (p ? a || (St(p, r) ? (n.shift(), o.push(p)) : (i.unshift(p), a = !0)) : a = !0, a) {
934
- let m = n.shift();
935
- for (; m; )
936
- o.push(m), m = n.shift();
937
- }
938
- }
939
- if (!a) {
940
- let r = i.shift();
941
- for (; r; )
942
- o.push(r), r = i.shift();
943
- }
944
- return [V(o), i];
945
- }
946
- function Wt(t, e) {
947
- return t.index < e.index || t.index === e.index && t.skip < e.skip;
948
- }
949
- function Gt(t, e) {
950
- const i = [], n = [], o = [], a = Math.max(
951
- t.length,
952
- e.length
953
- );
954
- let r = !1;
955
- for (let p = 0; p < a; p++) {
956
- const m = t[p], d = e[p];
957
- m && d ? !r && St(m, d) ? i.push(m) : (r = !0, n.push(m), o.push(d)) : m ? n.push(m) : d && o.push(d);
958
- }
959
- return [i, n, o];
960
- }
961
- function Ue(t, e, i) {
962
- const [n, o, a] = Gt(
963
- V(t),
964
- V(e)
965
- ), r = mt(n), p = 1 + Math.max(
966
- r,
967
- mt(o),
968
- mt(a)
969
- ), m = i(
970
- {
971
- index: p,
972
- skip: p - (r + 1)
973
- },
974
- o,
975
- a
976
- );
977
- return n.concat(m);
978
- }
979
- function mt(t) {
980
- const e = t[t.length - 1];
981
- return e ? e.index : -1;
982
- }
983
- function Zt(t) {
984
- var n, o, a;
985
- if (t.length < 1)
986
- return -1;
987
- const e = V(t);
988
- let i = (((n = e[e.length - 1]) == null ? void 0 : n.skip) || 0) + 1;
989
- return e.length > 1 && (i += ((o = e[e.length - 2]) == null ? void 0 : o.skip) || 0), (((a = e[e.length - 1]) == null ? void 0 : a.index) || -1) < i ? -1 : i;
990
- }
991
- const Je = (t) => Ot(
992
- V(H(t))
993
- ), Ve = (t) => t.reduce((i, n) => {
994
- var o;
995
- return i[n.scope] || (i[n.scope] = []), (o = i[n.scope]) == null || o.push(n), i;
996
- }, {}), He = (t, e) => {
997
- var m;
998
- const i = {
999
- integrityIssues: [],
1000
- validOperations: [],
1001
- invalidOperations: [],
1002
- duplicatedOperations: []
1003
- }, n = H(t), o = H(e), a = Ot([
1004
- ...n,
1005
- ...o
1006
- ]), p = (m = [...a.filter(
1007
- (d) => d.category === "MISSING_INDEX"
1008
- /* MISSING_INDEX */
1009
- )].sort((d, h) => h.operation.index - d.operation.index).pop()) == null ? void 0 : m.operation;
1010
- for (const d of o) {
1011
- if (p && d.index >= p.index) {
1012
- i.invalidOperations.push(d);
1013
- continue;
1014
- }
1015
- if (a.some((b) => b.operation.index === d.index && b.operation.skip === d.skip && b.category === "DUPLICATED_INDEX")) {
1016
- i.duplicatedOperations.push(d);
1017
- continue;
1018
- }
1019
- i.validOperations.push(d);
1020
- }
1021
- return i.integrityIssues.push(...a), i;
1022
- };
1023
- function Xe(t, e) {
1024
- return t.filter((i) => !e.some((n) => i.type === "NOOP" && i.skip === 0 && i.index === n.index || i.index === n.index && i.skip === n.skip && i.scope === n.scope && i.hash === n.hash && i.type === n.type));
1025
- }
1026
- function Qt(t, e) {
1027
- const [i] = H(t).slice(-1), n = (i == null ? void 0 : i.index) ?? -1, o = n + 1, a = {
1028
- ...e,
1029
- index: e.index ?? o
1030
- };
1031
- if (a.index < n)
1032
- throw new Error(
1033
- `The skip header operation index must be greater than or equal to ${n}`
1034
- );
1035
- return (V(
1036
- H([...t, a])
1037
- ) || []).slice(0, -1);
1038
- }
1039
- function dt(t) {
1040
- return {
1041
- ...Object.entries(t).reduce(
1042
- (i, n) => {
1043
- const [o, a] = n;
1044
- return {
1045
- ...i,
1046
- [o]: V(H(a))
1047
- };
1048
- },
1049
- {}
1050
- )
1051
- };
1052
- }
1053
- const fi = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1054
- __proto__: null,
1055
- IntegrityIssueSubType: Kt,
1056
- IntegrityIssueType: Bt,
1057
- addUndo: Ce,
1058
- attachBranch: qe,
1059
- checkCleanedOperationsIntegrity: Ot,
1060
- checkOperationsIntegrity: Je,
1061
- garbageCollect: V,
1062
- garbageCollectDocumentOperations: dt,
1063
- groupOperationsByScope: Ve,
1064
- merge: Ue,
1065
- nextSkipNumber: Zt,
1066
- operationsAreEqual: St,
1067
- precedes: Wt,
1068
- prepareOperations: He,
1069
- removeExistingOperations: Xe,
1070
- reshuffleByTimestamp: Fe,
1071
- reshuffleByTimestampAndIndex: Le,
1072
- skipHeaderOperations: Qt,
1073
- sortOperations: H,
1074
- split: Gt
1075
- }, Symbol.toStringTag, { value: "Module" }));
1076
- function Be(t, e) {
1077
- let i;
1078
- return "index" in e ? i = { ...e } : i = t.operations[e.scope].at(-1), ((i == null ? void 0 : i.index) ?? -1) + 1;
1079
- }
1080
- function Yt(t, e) {
1081
- return {
1082
- ...t,
1083
- revision: {
1084
- ...t.revision,
1085
- [e.scope]: Be(t, e)
1086
- },
1087
- lastModified: (/* @__PURE__ */ new Date()).toISOString()
1088
- };
1089
- }
1090
- function Ke(t, e, i = 0) {
1091
- if ([tt, et, ct].includes(e.type))
1092
- return t;
1093
- const { scope: n } = e, o = t.operations[n].slice(), a = o.at(-1);
1094
- let r = ((a == null ? void 0 : a.index) ?? -1) + 1;
1095
- if ("index" in e) {
1096
- if (e.index - i > r)
1097
- throw new Error(
1098
- `Missing operations: expected ${r} with skip 0 or equivalent, got index ${e.index} with skip ${i}`
1099
- );
1100
- r = e.index;
1101
- }
1102
- return o.push({
1103
- ...e,
1104
- index: r,
1105
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1106
- hash: "",
1107
- scope: n,
1108
- skip: i,
1109
- error: void 0
1110
- }), {
1111
- ...t,
1112
- operations: { ...t.operations, [n]: o }
1113
- };
1114
- }
1115
- function We(t, e, i = 0) {
1116
- let n = Ke(t, e, i);
1117
- return n = Yt(n, e), n;
1118
- }
1119
- function Ge(t, e, i) {
1120
- switch (Pt().parse(e), e.type) {
1121
- case qt:
1122
- return je(t, e.input);
1123
- case ct:
1124
- return ke(t, e, i);
1125
- case Ut:
1126
- return De(t, e.input.state);
1127
- default:
1128
- return t;
1129
- }
1130
- }
1131
- function di(t, e, i) {
1132
- switch (e.type) {
1133
- case tt:
1134
- return Ee(t, e, i);
1135
- case et:
1136
- return $e(t, e, i);
1137
- default:
1138
- return { document: t, action: e, skip: i };
1139
- }
1140
- }
1141
- function Ze(t, e, i, n, o = !1, a = ie) {
1142
- const r = e.scope, p = t.operations[r].at(-1);
1143
- if (!p)
1144
- return t;
1145
- const m = dt(
1146
- {
1147
- ...t.operations,
1148
- [r]: Qt(
1149
- t.operations[r],
1150
- p
1151
- )
1152
- }
1153
- );
1154
- let d;
1155
- const h = m[r].at(-1);
1156
- if (o && (h != null && h.resultingState))
1157
- d = a(
1158
- h.resultingState
1159
- );
1160
- else {
1161
- const { state: b } = gt(
1162
- t.initialState,
1163
- m,
1164
- i,
1165
- void 0,
1166
- void 0,
1167
- void 0,
1168
- void 0,
1169
- {
1170
- reuseHash: !0,
1171
- reuseOperationResultingState: o,
1172
- operationResultingStateParser: a
1173
- }
1174
- );
1175
- d = b[r];
1176
- }
1177
- return {
1178
- ...t,
1179
- state: {
1180
- ...t.state,
1181
- [r]: d
1182
- },
1183
- operations: dt({
1184
- ...t.operations
1185
- })
1186
- };
1187
- }
1188
- function te(t, e, i, n, o = {}) {
1189
- const {
1190
- skip: a,
1191
- ignoreSkipOperations: r = !1,
1192
- reuseHash: p = !1,
1193
- reuseOperationResultingState: m = !1,
1194
- operationResultingStateParser: d
1195
- } = o, h = { ...e }, b = a || 0;
1196
- let w = { ...t };
1197
- const N = !r && (b > 0 || "index" in h && h.skip > 0);
1198
- return kt(h) && (w = Ge(w, h, i)), w = We(w, h, b), N && (w = Ze(
1199
- w,
1200
- h,
1201
- i,
1202
- b,
1203
- m,
1204
- d
1205
- )), w = pt(w, ($) => {
1206
- try {
1207
- const P = i(
1208
- $.state,
1209
- h,
1210
- n
1211
- );
1212
- if (P)
1213
- return at({
1214
- ...w,
1215
- // clipboard: [...clipboardValue],
1216
- state: P
1217
- });
1218
- } catch (P) {
1219
- const C = w.operations[h.scope].length - 1;
1220
- $.operations[h.scope][C].error = P.message, $.operations[h.scope][C].skip = 0, N && ($.state = at({ ...t.state }), $.operations = at({
1221
- ...t.operations,
1222
- [h.scope]: [
1223
- ...t.operations[h.scope],
1224
- {
1225
- ...$.operations[h.scope][C]
1226
- }
1227
- ]
1228
- }));
1229
- }
1230
- }), pt(w, ($) => {
1231
- if ([tt, et, ct].includes(h.type))
1232
- return $;
1233
- const P = h.scope || "global", C = p && Object.prototype.hasOwnProperty.call(h, "hash") ? h.hash : jt($, P), c = $.operations[P].at(-1);
1234
- c && (c.hash = C, m && (c.resultingState = $.state[P]), !kt(h) && h.attachments && h.attachments.forEach((l) => {
1235
- const { hash: u, ...D } = l;
1236
- $.attachments[u] = {
1237
- ...D
1238
- };
1239
- }));
1240
- });
1241
- }
1242
- function gi(t) {
1243
- return t.type === Te && t.skip !== void 0 && t.skip > 0 && t.hash !== void 0;
1244
- }
1245
- function hi(t) {
1246
- return [tt, et].includes(t.type);
1247
- }
1248
- function kt(t) {
1249
- return [qt, tt, et, ct, Ut].includes(t.type);
1250
- }
1251
- function W(t, e, i, n, o = "global") {
1252
- if (!t)
1253
- throw new Error("Empty action type");
1254
- if (typeof t != "string")
1255
- throw new Error(`Invalid action type: ${JSON.stringify(t)}`);
1256
- const a = { type: t, input: e, scope: o };
1257
- i && (a.attachments = i);
1258
- try {
1259
- n == null || n().parse(a.input);
1260
- } catch (r) {
1261
- throw new Error(`Invalid action input: ${r}`);
1262
- }
1263
- return a;
1264
- }
1265
- function Qe(t, e = te) {
1266
- return (i, n, o, a) => e(i, n, t, o, a);
1267
- }
1268
- const Ye = (t, e) => ({
1269
- name: "",
1270
- documentType: "",
1271
- revision: {
1272
- global: 0,
1273
- local: 0
1274
- },
1275
- created: (/* @__PURE__ */ new Date()).toISOString(),
1276
- lastModified: (/* @__PURE__ */ new Date()).toISOString(),
1277
- attachments: {},
1278
- ...t,
1279
- state: (e == null ? void 0 : e(t == null ? void 0 : t.state)) ?? (t == null ? void 0 : t.state) ?? { global: {}, local: {} }
1280
- }), ti = (t, e) => {
1281
- const i = Ye(
1282
- t,
1283
- e
1284
- );
1285
- return {
1286
- ...i,
1287
- initialState: i,
1288
- operations: { global: [], local: [] },
1289
- clipboard: []
1290
- };
1291
- }, jt = (t, e = "global") => lt(K(t.state[e] || "")), xi = (t, e = 1e3) => {
1292
- const i = Math.random() * e;
1293
- return lt(`${(t ?? /* @__PURE__ */ new Date()).toISOString()}${i}`);
1294
- };
1295
- function rt(t) {
1296
- return me(ue(t, !0));
1297
- }
1298
- function yi(t, e) {
1299
- const i = [...t];
1300
- let n = e || 0, o = i.length > 0 ? i[i.length - 1].index : 0;
1301
- const a = [];
1302
- for (const r of i.reverse()) {
1303
- if (n > 0) {
1304
- const d = o - r.index;
1305
- n -= d;
1306
- }
1307
- if (n < 0)
1308
- throw new Error("Invalid operation index, missing operations");
1309
- const p = {
1310
- ignore: n > 0,
1311
- operation: r
1312
- }, m = r.skip > 0 ? r.skip + 1 : 0;
1313
- if (m > 0 && m > n) {
1314
- const d = m - n;
1315
- n = n + d;
1316
- }
1317
- o = r.index, a.push(p);
1318
- }
1319
- return a.reverse();
1320
- }
1321
- function bi(t, e, i) {
1322
- const n = t.slice().sort((p, m) => p.skip - m.skip).sort((p, m) => p.index - m.index);
1323
- let o = i, a = 0, r = e;
1324
- for (const p of n.reverse()) {
1325
- const m = r - p.index;
1326
- if (o = o - m, o > -1)
1327
- a++, r = p.index;
1328
- else
1329
- break;
1330
- }
1331
- return a;
1332
- }
1333
- function wi(t) {
1334
- return Object.values(t).flatMap((e) => e).sort(
1335
- (e, i) => new Date(e.timestamp).getTime() - new Date(i.timestamp).getTime()
1336
- );
1337
- }
1338
- function Oi(t) {
1339
- return Object.values(t).flatMap((e) => e).sort(
1340
- (e, i) => new Date(e.operation.timestamp).getTime() - new Date(i.operation.timestamp).getTime()
1341
- );
1342
- }
1343
- function gt(t, e, i, n, o, a = te, r = {}, p) {
1344
- const m = Qe(i, a);
1345
- return ee(
1346
- t,
1347
- e,
1348
- m,
1349
- n,
1350
- o,
1351
- r,
1352
- p
1353
- );
1354
- }
1355
- function ee(t, e, i, n, o, a = {}, r) {
1356
- const {
1357
- checkHashes: p = !0,
1358
- reuseOperationResultingState: m,
1359
- operationResultingStateParser: d = ie
1360
- } = r || {};
1361
- let h = t;
1362
- const b = [], w = {
1363
- global: [],
1364
- local: []
1365
- };
1366
- if (m)
1367
- for (const [c, l] of Object.entries(e)) {
1368
- const u = l.findLastIndex(
1369
- (F) => !!F.resultingState
1370
- );
1371
- if (u < 0) {
1372
- b.push(...l);
1373
- continue;
1374
- }
1375
- const D = l[u];
1376
- try {
1377
- const F = d(
1378
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-unnecessary-type-assertion
1379
- D.resultingState
1380
- );
1381
- h = {
1382
- ...h,
1383
- state: {
1384
- ...h.state,
1385
- // TODO how to deal with attachments?
1386
- [c]: F
1387
- }
1388
- }, w[c].push(
1389
- ...l.slice(0, u + 1)
1390
- ), b.push(...l.slice(u + 1));
1391
- } catch {
1392
- b.push(...l);
1393
- }
1394
- }
1395
- else
1396
- b.push(...Object.values(e).flat());
1397
- const N = ti(h);
1398
- N.initialState = t, N.operations = w;
1399
- let $ = N;
1400
- if (b.length)
1401
- $ = b.reduce((c, l) => i(c, l, n, {
1402
- skip: l.skip,
1403
- ignoreSkipOperations: !0,
1404
- reuseHash: !p
1405
- }), N);
1406
- else
1407
- for (const c of Object.values(w)) {
1408
- const l = c.at(-1);
1409
- l && ($ = Yt($, l));
1410
- }
1411
- if (!p)
1412
- for (const c of Object.keys($.state))
1413
- for (let l = b.length - 1; l >= 0; l--) {
1414
- const u = b[l];
1415
- if (u.scope === c) {
1416
- if (u.hash !== jt($, c))
1417
- throw new Error(`Hash mismatch for scope ${c}`);
1418
- break;
1419
- }
1420
- }
1421
- const P = Object.keys(
1422
- $.operations
1423
- ).reduce(
1424
- (c, l) => {
1425
- const u = l;
1426
- return {
1427
- ...c,
1428
- [u]: [
1429
- ...$.operations[u].map((D, F) => {
1430
- var M;
1431
- return {
1432
- ...D,
1433
- timestamp: ((M = e[u][F]) == null ? void 0 : M.timestamp) ?? D.timestamp
1434
- };
1435
- })
1436
- ]
1437
- };
1438
- },
1439
- { global: [], local: [] }
1440
- ), C = Object.values(P).reduce((c, l) => {
1441
- const u = l[l.length - 1];
1442
- return (u == null ? void 0 : u.timestamp) > c && (c = u.timestamp), c;
1443
- }, t.lastModified);
1444
- return { ...$, operations: P, lastModified: C };
1445
- }
1446
- function Si(t, e) {
1447
- return K(t) === K(e);
1448
- }
1449
- function ie(t) {
1450
- const e = typeof t;
1451
- if (e === "string")
1452
- return JSON.parse(t);
1453
- if (e === "object")
1454
- return t;
1455
- throw new Error(`Providing resulting state is of type: ${e}`);
1456
- }
1457
- const ne = (t) => W(
1458
- "SET_NAME",
1459
- t,
1460
- void 0,
1461
- bt,
1462
- void 0
1463
- ), oe = (t = 1, e = "global") => W(
1464
- "UNDO",
1465
- t,
1466
- void 0,
1467
- wt,
1468
- e
1469
- ), se = (t = 1, e = "global") => W(
1470
- "REDO",
1471
- t,
1472
- void 0,
1473
- yt,
1474
- e
1475
- ), re = (t, e, i = "global") => W(
1476
- "PRUNE",
1477
- { start: t, end: e },
1478
- void 0,
1479
- xt,
1480
- i
1481
- ), Et = (t, e) => W(
1482
- "LOAD_STATE",
1483
- { state: t, operations: e },
1484
- void 0,
1485
- ht
1486
- ), ae = (t = "global") => W("NOOP", {}, void 0, void 0, t), ji = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1487
- __proto__: null,
1488
- loadState: Et,
1489
- noop: ae,
1490
- prune: re,
1491
- redo: se,
1492
- setName: ne,
1493
- undo: oe
1494
- }, Symbol.toStringTag, { value: "Module" }));
1495
- class Ei {
1496
- /**
1497
- * Constructs a BaseDocument instance with an initial state.
1498
- * @param reducer - The reducer function that updates the state.
1499
- * @param document - The initial state of the document.
1500
- */
1501
- constructor(e, i, n) {
1502
- st(this, "_document");
1503
- st(this, "_reducer");
1504
- st(this, "_signalDispatch");
1505
- this._reducer = e, this._document = i, this._signalDispatch = n;
1506
- }
1507
- /**
1508
- * Dispatches an action to update the state of the document.
1509
- * @param action - The action to dispatch.
1510
- * @returns The Document instance.
1511
- */
1512
- dispatch(e, i) {
1513
- return this._document = this._reducer(
1514
- this._document,
1515
- e,
1516
- this._signalDispatch,
1517
- i
1518
- ), this;
1519
- }
1520
- /**
1521
- * Saves the state of the document to a file.
1522
- * @param path - The file path where the state should be saved.
1523
- * @param extension - The file extension to use when saving the state.
1524
- * @returns The file path where the state was saved.
1525
- */
1526
- saveToFile(e, i, n) {
1527
- return Me(this._document, e, i, n);
1528
- }
1529
- /**
1530
- * Loads the state of the document from a file.
1531
- * @param path - The file path where the state is stored.
1532
- */
1533
- async loadFromFile(e) {
1534
- this._document = await $t(e, this._reducer);
1535
- }
1536
- /**
1537
- * Loads the state of the document from a file and returns it.
1538
- * @param path - The file path where the state is stored.
1539
- * @param reducer - The reducer function that updates the state.
1540
- * @returns The state of the document.
1541
- */
1542
- static async stateFromFile(e, i) {
1543
- return await $t(e, i);
1544
- }
1545
- /**
1546
- * Gets the current state of the document.
1547
- */
1548
- get state() {
1549
- return rt(this._document.state);
1550
- }
1551
- /**
1552
- * Gets the list of operations performed on the document.
1553
- */
1554
- get operations() {
1555
- return rt(this._document.operations);
1556
- }
1557
- /**
1558
- * Gets the name of the document.
1559
- */
1560
- get name() {
1561
- return this._document.name;
1562
- }
1563
- /**
1564
- * Gets the type of document.
1565
- */
1566
- get documentType() {
1567
- return this._document.documentType;
1568
- }
1569
- /**
1570
- * Gets the timestamp of the date the document was created.
1571
- */
1572
- get created() {
1573
- return this._document.created;
1574
- }
1575
- /**
1576
- * Gets the timestamp of the date the document was last modified.
1577
- */
1578
- get lastModified() {
1579
- return this._document.lastModified;
1580
- }
1581
- /**
1582
- * Gets the global revision number of the document.
1583
- */
1584
- get revision() {
1585
- return this._document.revision.global;
1586
- }
1587
- getRevision(e) {
1588
- return this._document.revision[e];
1589
- }
1590
- /**
1591
- * Gets the initial state of the document.
1592
- */
1593
- get initialState() {
1594
- return rt(this._document.initialState);
1595
- }
1596
- /**
1597
- * Returns the current document as an object
1598
- */
1599
- toDocument() {
1600
- return rt(this._document);
1601
- }
1602
- /**
1603
- * Gets the attachment associated with the given key.
1604
- * @param attachment - The key of the attachment to retrieve.
1605
- */
1606
- getAttachment(e) {
1607
- return this._document.attachments[e];
1608
- }
1609
- /**
1610
- * Sets the name of the document.
1611
- * @param name - The new name of the document.
1612
- */
1613
- setName(e) {
1614
- return this.dispatch(ne(e)), this;
1615
- }
1616
- /**
1617
- * Reverts a number of actions from the document.
1618
- * @param count - The number of actions to revert.
1619
- */
1620
- undo(e) {
1621
- return this.dispatch(oe(e)), this;
1622
- }
1623
- /**
1624
- * Reapplies a number of actions to the document.
1625
- * @param count - The number of actions to reapply.
1626
- */
1627
- redo(e) {
1628
- return this.dispatch(se(e)), this;
1629
- }
1630
- /**
1631
- * Removes a range of operations from the document.
1632
- * @param start - The starting index of the range to remove.
1633
- * @param end - The ending index of the range to remove.
1634
- */
1635
- prune(e, i) {
1636
- return this.dispatch(re(e, i)), this;
1637
- }
1638
- /**
1639
- * Loads a document state and a set of operations.
1640
- * @param state - The state to load.
1641
- * @param operations - The operations to apply to the document.
1642
- */
1643
- loadState(e, i) {
1644
- return this.dispatch(Et(e, i)), this;
1645
- }
1646
- }
1647
- function $i(t, e) {
1648
- e.forEach((i) => {
1649
- Object.getOwnPropertyNames(i.prototype).forEach((n) => {
1650
- Object.defineProperty(
1651
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
1652
- t.prototype,
1653
- n,
1654
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
1655
- Object.getOwnPropertyDescriptor(i.prototype, n) || /* @__PURE__ */ Object.create(null)
1656
- );
1657
- });
1658
- });
1659
- }
1660
- export {
1661
- Oi as A,
1662
- Ei as B,
1663
- wi as C,
1664
- Pe as D,
1665
- te as E,
1666
- di as F,
1667
- We as G,
1668
- Yt as H,
1669
- ci as I,
1670
- Ye as a,
1671
- ti as b,
1672
- Qe as c,
1673
- li as d,
1674
- ze as e,
1675
- W as f,
1676
- $i as g,
1677
- ji as h,
1678
- kt as i,
1679
- bi as j,
1680
- Ht as k,
1681
- $t as l,
1682
- fi as m,
1683
- ui as n,
1684
- mi as o,
1685
- jt as p,
1686
- xi as q,
1687
- gi as r,
1688
- Me as s,
1689
- Si as t,
1690
- hi as u,
1691
- yi as v,
1692
- ie as w,
1693
- rt as x,
1694
- ee as y,
1695
- gt as z
1696
- };