document-model 1.0.55 → 1.1.0-debug.2

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 (74) hide show
  1. package/CHANGELOG.md +19 -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 +15 -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-CaJbS06G.js +2339 -0
  9. package/dist/browser/cjs/internal/index-CaJbS06G.js.map +1 -0
  10. package/dist/browser/cjs/internal/index-kKIg6qNB.js +44 -0
  11. package/dist/browser/cjs/internal/index-kKIg6qNB.js.map +1 -0
  12. package/dist/browser/cjs/internal/object-B6dSDhtS.js +4109 -0
  13. package/dist/browser/cjs/internal/object-B6dSDhtS.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 +10 -9
  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-B1lQN59e.js +2340 -0
  21. package/dist/browser/es/internal/index-B1lQN59e.js.map +1 -0
  22. package/dist/browser/es/internal/index-Bu0CkmrW.js +45 -0
  23. package/dist/browser/es/internal/index-Bu0CkmrW.js.map +1 -0
  24. package/dist/browser/es/internal/object-9mR1JlXD.js +4110 -0
  25. package/dist/browser/es/internal/object-9mR1JlXD.js.map +1 -0
  26. package/dist/browser/src/document/reducer.d.ts +13 -2
  27. package/dist/browser/src/document/utils/base.d.ts +1 -1
  28. package/dist/browser/src/document/utils/document-helpers.d.ts +53 -0
  29. package/dist/browser/src/document/utils/index.d.ts +1 -0
  30. package/dist/node/cjs/document-model.js +25 -1
  31. package/dist/node/cjs/document-model.js.map +1 -0
  32. package/dist/node/cjs/document.js +19 -1
  33. package/dist/node/cjs/document.js.map +1 -0
  34. package/dist/node/cjs/index.js +22 -1
  35. package/dist/node/cjs/index.js.map +1 -0
  36. package/dist/node/cjs/internal/index-AqiVmL0w.js +44 -0
  37. package/dist/node/cjs/internal/index-AqiVmL0w.js.map +1 -0
  38. package/dist/node/cjs/internal/index-ajqhOWQ1.js +2343 -0
  39. package/dist/node/cjs/internal/index-ajqhOWQ1.js.map +1 -0
  40. package/dist/node/cjs/internal/object-D_9h7jBN.js +2111 -0
  41. package/dist/node/cjs/internal/object-D_9h7jBN.js.map +1 -0
  42. package/dist/node/es/document-model.js +16 -15
  43. package/dist/node/es/document-model.js.map +1 -0
  44. package/dist/node/es/document.js +11 -10
  45. package/dist/node/es/document.js.map +1 -0
  46. package/dist/node/es/index.js +14 -12
  47. package/dist/node/es/index.js.map +1 -0
  48. package/dist/node/es/internal/index-Bh_09edy.js +2344 -0
  49. package/dist/node/es/internal/index-Bh_09edy.js.map +1 -0
  50. package/dist/node/es/internal/index-s6NFw7Kq.js +45 -0
  51. package/dist/node/es/internal/index-s6NFw7Kq.js.map +1 -0
  52. package/dist/node/es/internal/object-CbITi4iq.js +2112 -0
  53. package/dist/node/es/internal/object-CbITi4iq.js.map +1 -0
  54. package/dist/node/src/document/reducer.d.ts +13 -2
  55. package/dist/node/src/document/utils/base.d.ts +1 -1
  56. package/dist/node/src/document/utils/document-helpers.d.ts +53 -0
  57. package/dist/node/src/document/utils/index.d.ts +1 -0
  58. package/dist/src/document/reducer.d.ts +13 -2
  59. package/dist/src/document/utils/base.d.ts +1 -1
  60. package/dist/src/document/utils/document-helpers.d.ts +53 -0
  61. package/dist/src/document/utils/index.d.ts +1 -0
  62. package/package.json +7 -2
  63. package/dist/browser/cjs/internal/index-C_OFq7P5.js +0 -22
  64. package/dist/browser/cjs/internal/index-Dwhv4k_6.js +0 -1
  65. package/dist/browser/cjs/internal/object-CeLE3akL.js +0 -25
  66. package/dist/browser/es/internal/index-DvHnaqeu.js +0 -2104
  67. package/dist/browser/es/internal/index-Xcvn-MUq.js +0 -42
  68. package/dist/browser/es/internal/object-BDWVt0Zy.js +0 -2504
  69. package/dist/node/cjs/internal/index-Bi9yeV3W.js +0 -1
  70. package/dist/node/cjs/internal/index-GZsLKtHl.js +0 -22
  71. package/dist/node/cjs/internal/object-CnhDksx1.js +0 -20
  72. package/dist/node/es/internal/index-B6iEYnbQ.js +0 -42
  73. package/dist/node/es/internal/index-Chx4C-Xl.js +0 -2108
  74. package/dist/node/es/internal/object-CnV5hY_A.js +0 -1402
@@ -1,1402 +0,0 @@
1
- var Gt = Object.defineProperty;
2
- var Qt = (e, t, i) => t in e ? Gt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[t] = i;
3
- var nt = (e, t, i) => (Qt(e, typeof t != "symbol" ? t + "" : t, i), i);
4
- import { produce as G, castDraft as pt, castImmutable as Xt, freeze as Yt } from "immer";
5
- import { z as m } from "zod";
6
- import te from "crypto";
7
- import ct from "fs";
8
- import ee from "https";
9
- import { join as ie } from "path";
10
- import Ot from "jszip";
11
- const $t = (e) => e != null, ne = m.any().refine((e) => $t(e)), Et = m.enum(["LOAD_STATE"]), vt = m.enum(["PRUNE"]), Tt = m.enum(["REDO"]), _t = m.enum(["SET_NAME"]), kt = m.enum(["UNDO"]);
12
- function oe() {
13
- return m.object({
14
- __typename: m.literal("Action").optional(),
15
- type: m.string()
16
- });
17
- }
18
- function Q() {
19
- return m.literal("global").or(m.literal("local"));
20
- }
21
- function At() {
22
- return m.union([
23
- Nt(),
24
- Mt(),
25
- Pt(),
26
- It(),
27
- zt()
28
- ]);
29
- }
30
- function re() {
31
- return m.object({
32
- __typename: m.literal("DocumentFile").optional(),
33
- data: m.string(),
34
- extension: m.string().nullable(),
35
- fileName: m.string().nullable(),
36
- mimeType: m.string()
37
- });
38
- }
39
- function Nt() {
40
- return m.object({
41
- input: m.lazy(() => ut()),
42
- type: Et,
43
- scope: Q()
44
- });
45
- }
46
- function ut() {
47
- return m.object({
48
- operations: m.number(),
49
- state: m.lazy(() => Dt())
50
- });
51
- }
52
- function Dt() {
53
- return m.object({
54
- data: m.unknown().nullish(),
55
- name: m.string()
56
- });
57
- }
58
- function se() {
59
- return m.object({
60
- __typename: m.literal("Operation").optional(),
61
- hash: m.string(),
62
- index: m.number(),
63
- timestamp: m.string().datetime(),
64
- type: m.string()
65
- });
66
- }
67
- function Mt() {
68
- return m.object({
69
- input: m.lazy(() => ft()),
70
- type: vt,
71
- scope: Q()
72
- });
73
- }
74
- function ft() {
75
- return m.object({
76
- end: m.number().nullish(),
77
- start: m.number().nullish()
78
- });
79
- }
80
- const dt = m.number;
81
- function Pt() {
82
- return m.object({
83
- input: dt(),
84
- type: Tt,
85
- scope: Q()
86
- });
87
- }
88
- const gt = m.string;
89
- function It() {
90
- return m.object({
91
- input: gt(),
92
- type: _t,
93
- scope: m.literal("global")
94
- });
95
- }
96
- function ae() {
97
- return m.object({
98
- __typename: m.literal("SetNameOperation").optional(),
99
- hash: m.string(),
100
- index: m.number(),
101
- input: m.string(),
102
- timestamp: m.string().datetime(),
103
- type: m.string()
104
- });
105
- }
106
- const ht = m.number;
107
- function zt() {
108
- return m.object({
109
- input: ht(),
110
- type: kt,
111
- scope: Q()
112
- });
113
- }
114
- const We = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
115
- __proto__: null,
116
- ActionSchema: oe,
117
- BaseActionSchema: At,
118
- DocumentFileSchema: re,
119
- LoadStateActionInputSchema: ut,
120
- LoadStateActionSchema: Nt,
121
- LoadStateActionStateInputSchema: Dt,
122
- Load_StateSchema: Et,
123
- OperationSchema: se,
124
- OperationScopeSchema: Q,
125
- PruneActionInputSchema: ft,
126
- PruneActionSchema: Mt,
127
- PruneSchema: vt,
128
- RedoActionInputSchema: dt,
129
- RedoActionSchema: Pt,
130
- RedoSchema: Tt,
131
- SetNameActionInputSchema: gt,
132
- SetNameActionSchema: It,
133
- SetNameOperationSchema: ae,
134
- Set_NameSchema: _t,
135
- UndoActionInputSchema: ht,
136
- UndoActionSchema: zt,
137
- UndoSchema: kt,
138
- definedNonNullAnySchema: ne,
139
- isDefinedNonNullAny: $t
140
- }, Symbol.toStringTag, { value: "Module" }));
141
- function pe(e) {
142
- return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
143
- }
144
- var lt = { exports: {} };
145
- (function(e, t) {
146
- const { hasOwnProperty: i } = Object.prototype, n = E();
147
- n.configure = E, n.stringify = n, n.default = n, t.stringify = n, t.configure = E, e.exports = n;
148
- const a = /[\u0000-\u001f\u0022\u005c\ud800-\udfff]|[\ud800-\udbff](?![\udc00-\udfff])|(?:[^\ud800-\udbff]|^)[\udc00-\udfff]/;
149
- function s(c) {
150
- return c.length < 5e3 && !a.test(c) ? `"${c}"` : JSON.stringify(c);
151
- }
152
- function r(c) {
153
- if (c.length > 200)
154
- return c.sort();
155
- for (let u = 1; u < c.length; u++) {
156
- const y = c[u];
157
- let P = u;
158
- for (; P !== 0 && c[P - 1] > y; )
159
- c[P] = c[P - 1], P--;
160
- c[P] = y;
161
- }
162
- return c;
163
- }
164
- const l = Object.getOwnPropertyDescriptor(
165
- Object.getPrototypeOf(
166
- Object.getPrototypeOf(
167
- new Int8Array()
168
- )
169
- ),
170
- Symbol.toStringTag
171
- ).get;
172
- function p(c) {
173
- return l.call(c) !== void 0 && c.length !== 0;
174
- }
175
- function x(c, u, y) {
176
- c.length < y && (y = c.length);
177
- const P = u === "," ? "" : " ";
178
- let V = `"0":${P}${c[0]}`;
179
- for (let R = 1; R < y; R++)
180
- V += `${u}"${R}":${P}${c[R]}`;
181
- return V;
182
- }
183
- function b(c) {
184
- if (i.call(c, "circularValue")) {
185
- const u = c.circularValue;
186
- if (typeof u == "string")
187
- return `"${u}"`;
188
- if (u == null)
189
- return u;
190
- if (u === Error || u === 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 v(c, u) {
201
- let y;
202
- if (i.call(c, u) && (y = c[u], typeof y != "boolean"))
203
- throw new TypeError(`The "${u}" argument must be of type boolean`);
204
- return y === void 0 ? !0 : y;
205
- }
206
- function h(c, u) {
207
- let y;
208
- if (i.call(c, u)) {
209
- if (y = c[u], typeof y != "number")
210
- throw new TypeError(`The "${u}" argument must be of type number`);
211
- if (!Number.isInteger(y))
212
- throw new TypeError(`The "${u}" argument must be an integer`);
213
- if (y < 1)
214
- throw new RangeError(`The "${u}" argument must be >= 1`);
215
- }
216
- return y === void 0 ? 1 / 0 : y;
217
- }
218
- function O(c) {
219
- return c === 1 ? "1 item" : `${c} items`;
220
- }
221
- function $(c) {
222
- const u = /* @__PURE__ */ new Set();
223
- for (const y of c)
224
- (typeof y == "string" || typeof y == "number") && u.add(String(y));
225
- return u;
226
- }
227
- function D(c) {
228
- if (i.call(c, "strict")) {
229
- const u = c.strict;
230
- if (typeof u != "boolean")
231
- throw new TypeError('The "strict" argument must be of type boolean');
232
- if (u)
233
- return (y) => {
234
- let P = `Object can not safely be stringified. Received type ${typeof y}`;
235
- throw typeof y != "function" && (P += ` (${y.toString()})`), new Error(P);
236
- };
237
- }
238
- }
239
- function E(c) {
240
- c = { ...c };
241
- const u = D(c);
242
- u && (c.bigint === void 0 && (c.bigint = !1), "circularValue" in c || (c.circularValue = Error));
243
- const y = b(c), P = v(c, "bigint"), V = v(c, "deterministic"), R = h(c, "maximumDepth"), k = h(c, "maximumBreadth");
244
- function tt(I, o, f, w, g, S) {
245
- let d = o[I];
246
- switch (typeof d == "object" && d !== null && typeof d.toJSON == "function" && (d = d.toJSON(I)), d = w.call(o, I, d), typeof d) {
247
- case "string":
248
- return s(d);
249
- case "object": {
250
- if (d === null)
251
- return "null";
252
- if (f.indexOf(d) !== -1)
253
- return y;
254
- let j = "", _ = ",";
255
- const A = S;
256
- if (Array.isArray(d)) {
257
- if (d.length === 0)
258
- return "[]";
259
- if (R < f.length + 1)
260
- return '"[Array]"';
261
- f.push(d), g !== "" && (S += g, j += `
262
- ${S}`, _ = `,
263
- ${S}`);
264
- const F = Math.min(d.length, k);
265
- let C = 0;
266
- for (; C < F - 1; C++) {
267
- const it = tt(String(C), d, f, w, g, S);
268
- j += it !== void 0 ? it : "null", j += _;
269
- }
270
- const J = tt(String(C), d, f, w, g, S);
271
- if (j += J !== void 0 ? J : "null", d.length - 1 > k) {
272
- const it = d.length - k - 1;
273
- j += `${_}"... ${O(it)} not stringified"`;
274
- }
275
- return g !== "" && (j += `
276
- ${A}`), f.pop(), `[${j}]`;
277
- }
278
- let N = Object.keys(d);
279
- const M = N.length;
280
- if (M === 0)
281
- return "{}";
282
- if (R < f.length + 1)
283
- return '"[Object]"';
284
- let T = "", z = "";
285
- g !== "" && (S += g, _ = `,
286
- ${S}`, T = " ");
287
- const q = Math.min(M, k);
288
- V && !p(d) && (N = r(N)), f.push(d);
289
- for (let F = 0; F < q; F++) {
290
- const C = N[F], J = tt(C, d, f, w, g, S);
291
- J !== void 0 && (j += `${z}${s(C)}:${T}${J}`, z = _);
292
- }
293
- if (M > k) {
294
- const F = M - k;
295
- j += `${z}"...":${T}"${O(F)} not stringified"`, z = _;
296
- }
297
- return g !== "" && z.length > 1 && (j = `
298
- ${S}${j}
299
- ${A}`), f.pop(), `{${j}}`;
300
- }
301
- case "number":
302
- return isFinite(d) ? String(d) : u ? u(d) : "null";
303
- case "boolean":
304
- return d === !0 ? "true" : "false";
305
- case "undefined":
306
- return;
307
- case "bigint":
308
- if (P)
309
- return String(d);
310
- default:
311
- return u ? u(d) : void 0;
312
- }
313
- }
314
- function et(I, o, f, w, g, S) {
315
- switch (typeof o == "object" && o !== null && typeof o.toJSON == "function" && (o = o.toJSON(I)), typeof o) {
316
- case "string":
317
- return s(o);
318
- case "object": {
319
- if (o === null)
320
- return "null";
321
- if (f.indexOf(o) !== -1)
322
- return y;
323
- const d = S;
324
- let j = "", _ = ",";
325
- if (Array.isArray(o)) {
326
- if (o.length === 0)
327
- return "[]";
328
- if (R < f.length + 1)
329
- return '"[Array]"';
330
- f.push(o), g !== "" && (S += g, j += `
331
- ${S}`, _ = `,
332
- ${S}`);
333
- const M = Math.min(o.length, k);
334
- let T = 0;
335
- for (; T < M - 1; T++) {
336
- const q = et(String(T), o[T], f, w, g, S);
337
- j += q !== void 0 ? q : "null", j += _;
338
- }
339
- const z = et(String(T), o[T], f, w, g, S);
340
- if (j += z !== void 0 ? z : "null", o.length - 1 > k) {
341
- const q = o.length - k - 1;
342
- j += `${_}"... ${O(q)} not stringified"`;
343
- }
344
- return g !== "" && (j += `
345
- ${d}`), f.pop(), `[${j}]`;
346
- }
347
- f.push(o);
348
- let A = "";
349
- g !== "" && (S += g, _ = `,
350
- ${S}`, A = " ");
351
- let N = "";
352
- for (const M of w) {
353
- const T = et(M, o[M], f, w, g, S);
354
- T !== void 0 && (j += `${N}${s(M)}:${A}${T}`, N = _);
355
- }
356
- return g !== "" && N.length > 1 && (j = `
357
- ${S}${j}
358
- ${d}`), f.pop(), `{${j}}`;
359
- }
360
- case "number":
361
- return isFinite(o) ? String(o) : u ? u(o) : "null";
362
- case "boolean":
363
- return o === !0 ? "true" : "false";
364
- case "undefined":
365
- return;
366
- case "bigint":
367
- if (P)
368
- return String(o);
369
- default:
370
- return u ? u(o) : void 0;
371
- }
372
- }
373
- function W(I, o, f, w, g) {
374
- switch (typeof o) {
375
- case "string":
376
- return s(o);
377
- case "object": {
378
- if (o === null)
379
- return "null";
380
- if (typeof o.toJSON == "function") {
381
- if (o = o.toJSON(I), typeof o != "object")
382
- return W(I, o, f, w, g);
383
- if (o === null)
384
- return "null";
385
- }
386
- if (f.indexOf(o) !== -1)
387
- return y;
388
- const S = g;
389
- if (Array.isArray(o)) {
390
- if (o.length === 0)
391
- return "[]";
392
- if (R < f.length + 1)
393
- return '"[Array]"';
394
- f.push(o), g += w;
395
- let T = `
396
- ${g}`;
397
- const z = `,
398
- ${g}`, q = Math.min(o.length, k);
399
- let F = 0;
400
- for (; F < q - 1; F++) {
401
- const J = W(String(F), o[F], f, w, g);
402
- T += J !== void 0 ? J : "null", T += z;
403
- }
404
- const C = W(String(F), o[F], f, w, g);
405
- if (T += C !== void 0 ? C : "null", o.length - 1 > k) {
406
- const J = o.length - k - 1;
407
- T += `${z}"... ${O(J)} not stringified"`;
408
- }
409
- return T += `
410
- ${S}`, f.pop(), `[${T}]`;
411
- }
412
- let d = Object.keys(o);
413
- const j = d.length;
414
- if (j === 0)
415
- return "{}";
416
- if (R < f.length + 1)
417
- return '"[Object]"';
418
- g += w;
419
- const _ = `,
420
- ${g}`;
421
- let A = "", N = "", M = Math.min(j, k);
422
- p(o) && (A += x(o, _, k), d = d.slice(o.length), M -= o.length, N = _), V && (d = r(d)), f.push(o);
423
- for (let T = 0; T < M; T++) {
424
- const z = d[T], q = W(z, o[z], f, w, g);
425
- q !== void 0 && (A += `${N}${s(z)}: ${q}`, N = _);
426
- }
427
- if (j > k) {
428
- const T = j - k;
429
- A += `${N}"...": "${O(T)} not stringified"`, N = _;
430
- }
431
- return N !== "" && (A = `
432
- ${g}${A}
433
- ${S}`), f.pop(), `{${A}}`;
434
- }
435
- case "number":
436
- return isFinite(o) ? String(o) : u ? u(o) : "null";
437
- case "boolean":
438
- return o === !0 ? "true" : "false";
439
- case "undefined":
440
- return;
441
- case "bigint":
442
- if (P)
443
- return String(o);
444
- default:
445
- return u ? u(o) : void 0;
446
- }
447
- }
448
- function B(I, o, f) {
449
- switch (typeof o) {
450
- case "string":
451
- return s(o);
452
- case "object": {
453
- if (o === null)
454
- return "null";
455
- if (typeof o.toJSON == "function") {
456
- if (o = o.toJSON(I), typeof o != "object")
457
- return B(I, o, f);
458
- if (o === null)
459
- return "null";
460
- }
461
- if (f.indexOf(o) !== -1)
462
- return y;
463
- let w = "";
464
- if (Array.isArray(o)) {
465
- if (o.length === 0)
466
- return "[]";
467
- if (R < f.length + 1)
468
- return '"[Array]"';
469
- f.push(o);
470
- const _ = Math.min(o.length, k);
471
- let A = 0;
472
- for (; A < _ - 1; A++) {
473
- const M = B(String(A), o[A], f);
474
- w += M !== void 0 ? M : "null", w += ",";
475
- }
476
- const N = B(String(A), o[A], f);
477
- if (w += N !== void 0 ? N : "null", o.length - 1 > k) {
478
- const M = o.length - k - 1;
479
- w += `,"... ${O(M)} not stringified"`;
480
- }
481
- return f.pop(), `[${w}]`;
482
- }
483
- let g = Object.keys(o);
484
- const S = g.length;
485
- if (S === 0)
486
- return "{}";
487
- if (R < f.length + 1)
488
- return '"[Object]"';
489
- let d = "", j = Math.min(S, k);
490
- p(o) && (w += x(o, ",", k), g = g.slice(o.length), j -= o.length, d = ","), V && (g = r(g)), f.push(o);
491
- for (let _ = 0; _ < j; _++) {
492
- const A = g[_], N = B(A, o[A], f);
493
- N !== void 0 && (w += `${d}${s(A)}:${N}`, d = ",");
494
- }
495
- if (S > k) {
496
- const _ = S - k;
497
- w += `${d}"...":"${O(_)} not stringified"`;
498
- }
499
- return f.pop(), `{${w}}`;
500
- }
501
- case "number":
502
- return isFinite(o) ? String(o) : u ? u(o) : "null";
503
- case "boolean":
504
- return o === !0 ? "true" : "false";
505
- case "undefined":
506
- return;
507
- case "bigint":
508
- if (P)
509
- return String(o);
510
- default:
511
- return u ? u(o) : void 0;
512
- }
513
- }
514
- function Zt(I, o, f) {
515
- if (arguments.length > 1) {
516
- let w = "";
517
- if (typeof f == "number" ? w = " ".repeat(Math.min(f, 10)) : typeof f == "string" && (w = f.slice(0, 10)), o != null) {
518
- if (typeof o == "function")
519
- return tt("", { "": I }, [], o, w, "");
520
- if (Array.isArray(o))
521
- return et("", I, [], $(o), w, "");
522
- }
523
- if (w.length !== 0)
524
- return W("", I, [], w, "");
525
- }
526
- return B("", I, []);
527
- }
528
- return Zt;
529
- }
530
- })(lt, lt.exports);
531
- var ce = lt.exports;
532
- const rt = /* @__PURE__ */ pe(ce);
533
- rt.configure;
534
- function le(e, t) {
535
- return { ...e, name: t };
536
- }
537
- function me(e, t, i) {
538
- const n = {
539
- skip: i,
540
- document: e
541
- }, { scope: a } = t;
542
- return !a || t.skip === void 0 ? n : G(n, (s) => {
543
- const r = s.document.operations[a].at(-1);
544
- t.skip && t.skip > 0 && (s.skip = t.skip), r && r.type === "NOOP" && t.index === r.index && s.skip > r.skip && s.document.operations[a].pop();
545
- });
546
- }
547
- function ue(e, t, i) {
548
- const { scope: n, input: a } = t;
549
- return G({
550
- document: e,
551
- action: t,
552
- skip: i
553
- }, (r) => {
554
- if (r.document.operations[n].length < 1)
555
- throw new Error(
556
- `Cannot undo: no operations in history for scope "${n}"`
557
- );
558
- if (a < 1)
559
- throw new Error(
560
- "Invalid UNDO action: input value must be greater than 0"
561
- );
562
- if (r.skip > 0)
563
- throw new Error(
564
- "Cannot undo: skip value from reducer cannot be used with UNDO action"
565
- );
566
- const l = r.document.operations[n].at(-1), p = l && l.type === "NOOP" && l.skip > 0;
567
- if (r.skip += a, p) {
568
- r.skip += l.skip;
569
- const h = r.document.operations[n][r.document.operations[n].length - 2];
570
- h && l.index - h.index === 1 && r.document.operations[n].pop();
571
- }
572
- if (r.document.operations[n].length < r.skip)
573
- throw new Error(
574
- "Cannot undo: you can't undo more operations than the ones in the scope history"
575
- );
576
- const x = r.document.operations[n].length - 1;
577
- let b = a, v = p ? x - l.skip : x;
578
- for (; b > 0 && v >= 0; ) {
579
- const h = r.document.operations[n][v];
580
- if (!h) {
581
- b--, v--;
582
- continue;
583
- }
584
- h.type === "NOOP" && h.skip > 0 ? (v = v - (h.skip + 1), r.skip += h.skip + 1) : (r.document.clipboard.push({ ...h }), b--, v--);
585
- }
586
- r.action = yt(n);
587
- });
588
- }
589
- function fe(e, t, i) {
590
- const { scope: n, input: a } = t;
591
- return G({
592
- document: e,
593
- action: t,
594
- skip: i
595
- }, (r) => {
596
- if (r.skip > 0)
597
- throw new Error(
598
- "Cannot redo: skip value from reducer cannot be used with REDO action"
599
- );
600
- if (a > 1)
601
- throw new Error(
602
- "Cannot redo: you can only redo one operation at a time"
603
- );
604
- if (a < 1)
605
- throw new Error("Invalid REDO action: invalid redo input value");
606
- if (r.document.clipboard.length < 1)
607
- throw new Error("Cannot redo: no operations in the clipboard");
608
- const l = r.document.clipboard.findLastIndex(
609
- (x) => x.scope === n
610
- );
611
- if (l < 0)
612
- throw new Error(
613
- `Cannot redo: no operations in clipboard for scope "${n}"`
614
- );
615
- const p = r.document.clipboard.splice(l, 1)[0];
616
- r.action = pt({
617
- type: p.type,
618
- scope: p.scope,
619
- input: p.input
620
- });
621
- });
622
- }
623
- function de(e, t, i) {
624
- const { scope: n } = t, a = e.operations[n];
625
- let {
626
- input: { start: s, end: r }
627
- } = t;
628
- s = s || 0, r = r || a.length;
629
- const l = a.slice(s, r), p = a.slice(0, s), x = a.slice(r), b = mt(
630
- e.initialState,
631
- {
632
- ...e.operations,
633
- [n]: p.concat(l)
634
- },
635
- i
636
- ), { name: v, state: h } = b, O = p.length, $ = p.length ? p[p.length - 1].timestamp : x.length ? x[0].timestamp : (/* @__PURE__ */ new Date()).toISOString();
637
- return mt(
638
- e.initialState,
639
- {
640
- ...e.operations,
641
- [n]: [
642
- ...p,
643
- {
644
- ...bt(
645
- { name: v, state: h },
646
- l.length
647
- ),
648
- timestamp: $,
649
- index: O,
650
- hash: xt({ state: h }, "global")
651
- },
652
- ...x.map((D, E) => ({
653
- ...D,
654
- index: O + E + 1
655
- }))
656
- ]
657
- },
658
- i
659
- );
660
- }
661
- function ge(e, t) {
662
- return {
663
- ...e,
664
- name: t.name,
665
- state: t.state ?? { global: {}, local: {} }
666
- };
667
- }
668
- const Ft = "SET_NAME", X = "UNDO", Y = "REDO", st = "PRUNE", Rt = "LOAD_STATE", he = "NOOP";
669
- function xe(e, t) {
670
- let i;
671
- return "index" in t ? i = { ...t } : i = e.operations[t.scope].at(-1), ((i == null ? void 0 : i.index) ?? -1) + 1;
672
- }
673
- function be(e, t) {
674
- return {
675
- ...e,
676
- revision: {
677
- ...e.revision,
678
- [t.scope]: xe(e, t)
679
- },
680
- lastModified: (/* @__PURE__ */ new Date()).toISOString()
681
- };
682
- }
683
- function ye(e, t, i = 0) {
684
- if ([X, Y, st].includes(t.type))
685
- return e;
686
- const { scope: n } = t, a = e.operations[n].slice(
687
- 0,
688
- e.revision[n]
689
- ), s = [...a].pop();
690
- let r = ((s == null ? void 0 : s.index) ?? -1) + 1;
691
- if ("index" in t) {
692
- if (t.index > r + i)
693
- throw new Error(
694
- `Missing operations: expected ${r} with skip 0 or equivalent, got index ${t.index} with skip ${i}`
695
- );
696
- r = t.index;
697
- }
698
- return a.push({
699
- ...t,
700
- index: r,
701
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
702
- hash: "",
703
- scope: n,
704
- skip: i,
705
- error: void 0
706
- }), {
707
- ...e,
708
- operations: { ...e.operations, [n]: a }
709
- };
710
- }
711
- function we(e, t, i = 0) {
712
- let n = ye(e, t, i);
713
- return n = be(n, t), n;
714
- }
715
- function je(e, t, i) {
716
- switch (At().parse(t), t.type) {
717
- case Ft:
718
- return le(e, t.input);
719
- case st:
720
- return de(e, t, i);
721
- case Rt:
722
- return ge(e, t.input.state);
723
- default:
724
- return e;
725
- }
726
- }
727
- function Se(e, t, i) {
728
- switch (t.type) {
729
- case X:
730
- return ue(e, t, i);
731
- case Y:
732
- return fe(e, t, i);
733
- default:
734
- return { document: e, action: t, skip: i };
735
- }
736
- }
737
- function Lt(e, t, i, n, a = {}) {
738
- const { skip: s, ignoreSkipOperations: r = !1, reuseHash: l = !1 } = a;
739
- let p = { ...t }, x = s || 0, b = e, v = [...e.clipboard];
740
- if (ve(p)) {
741
- const { document: h, skip: O } = me(b, p, x);
742
- x = O, b = h;
743
- }
744
- if (wt(p)) {
745
- const {
746
- skip: h,
747
- action: O,
748
- document: $
749
- } = Se(e, p, x);
750
- p = O, x = h, b = $, v = [...b.clipboard];
751
- }
752
- if (jt(p) && (b = je(b, p, i)), x > 0 && !r) {
753
- let h = x;
754
- "index" in p && (h = Ne(
755
- b.operations[p.scope],
756
- p.index,
757
- x
758
- )), b = mt(
759
- b.initialState,
760
- b.operations,
761
- i,
762
- void 0,
763
- void 0,
764
- void 0,
765
- { [p.scope]: h }
766
- // TODO reuse hash?
767
- );
768
- }
769
- return b = we(b, p, x), b = G(b, (h) => {
770
- try {
771
- const O = i(
772
- h.state,
773
- p,
774
- n
775
- ), $ = wt(t) ? [...v] : [];
776
- if (O)
777
- return pt({
778
- ...b,
779
- clipboard: [...$],
780
- state: O
781
- });
782
- h.clipboard = pt([...$]);
783
- } catch (O) {
784
- const $ = b.operations[p.scope].length - 1;
785
- h.operations[p.scope][$].error = O.message;
786
- }
787
- }), G(b, (h) => {
788
- if ([X, Y, st].includes(p.type))
789
- return h;
790
- const O = p.scope || "global", $ = l && Object.prototype.hasOwnProperty.call(p, "hash") ? p.hash : xt(h, O);
791
- h.operations[O][h.operations[O].length - 1].hash = $, !jt(p) && p.attachments && p.attachments.forEach((D) => {
792
- const { hash: E, ...c } = D;
793
- h.attachments[E] = {
794
- ...c
795
- };
796
- });
797
- });
798
- }
799
- function Oe(e, t, i) {
800
- const n = ie(e, t);
801
- return ct.mkdirSync(e, { recursive: !0 }), new Promise((a, s) => {
802
- try {
803
- ct.writeFile(n, i, {}, (r) => {
804
- r ? s(r) : a(n);
805
- });
806
- } catch (r) {
807
- s(r);
808
- }
809
- });
810
- }
811
- function qt(e) {
812
- return ct.readFileSync(e);
813
- }
814
- function $e(e) {
815
- return new Promise((t, i) => {
816
- ee.get(e, (n) => {
817
- const a = [], s = n.headers["content-type"];
818
- n.on("data", (r) => {
819
- a.push(r);
820
- }), n.on("end", () => {
821
- t({ buffer: Buffer.concat(a), mimeType: s });
822
- });
823
- }).on("error", (n) => {
824
- i(n);
825
- });
826
- });
827
- }
828
- const Ee = async (e) => qt(e), at = (e, t = "sha1") => te.createHash(t).update(e).digest("base64");
829
- function ve(e) {
830
- return e.type === he && e.skip !== void 0 && e.skip > 0 && e.hash !== void 0;
831
- }
832
- function wt(e) {
833
- return [X, Y].includes(e.type);
834
- }
835
- function jt(e) {
836
- return [Ft, X, Y, st, Rt].includes(e.type);
837
- }
838
- function H(e, t, i, n, a = "global") {
839
- if (!e)
840
- throw new Error("Empty action type");
841
- if (typeof e != "string")
842
- throw new Error(`Invalid action type: ${JSON.stringify(e)}`);
843
- const s = { type: e, input: t, scope: a };
844
- i && (s.attachments = i);
845
- try {
846
- n == null || n().parse(s.input);
847
- } catch (r) {
848
- throw new Error(`Invalid action input: ${r}`);
849
- }
850
- return s;
851
- }
852
- function Te(e, t = Lt) {
853
- return (i, n, a, s) => t(i, n, e, a, s);
854
- }
855
- const _e = (e, t) => ({
856
- name: "",
857
- documentType: "",
858
- revision: {
859
- global: 0,
860
- local: 0
861
- },
862
- created: (/* @__PURE__ */ new Date()).toISOString(),
863
- lastModified: (/* @__PURE__ */ new Date()).toISOString(),
864
- attachments: {},
865
- ...e,
866
- state: (t == null ? void 0 : t(e == null ? void 0 : e.state)) ?? (e == null ? void 0 : e.state) ?? { global: {}, local: {} }
867
- }), ke = (e, t) => {
868
- const i = _e(
869
- e,
870
- t
871
- );
872
- return {
873
- ...i,
874
- initialState: i,
875
- operations: { global: [], local: [] },
876
- clipboard: []
877
- };
878
- }, xt = (e, t = "global") => at(rt(e.state[t] || "")), Be = (e, t = 1e3) => {
879
- const i = Math.random() * t;
880
- return at(`${(e ?? /* @__PURE__ */ new Date()).toISOString()}${i}`);
881
- };
882
- function ot(e) {
883
- return Xt(Yt(e, !0));
884
- }
885
- function Ae(e, t) {
886
- const i = [...e];
887
- let n = t || 0, a = i.length > 0 ? i[i.length - 1].index : 0;
888
- const s = [];
889
- for (const r of i.reverse()) {
890
- if (n > 0) {
891
- const x = a - r.index;
892
- n -= x;
893
- }
894
- if (n < 0)
895
- throw new Error("Invalid operation index, missing operations");
896
- const l = {
897
- ignore: n > 0,
898
- operation: r
899
- }, p = r.skip > 0 ? r.skip + 1 : 0;
900
- if (p > 0 && p > n) {
901
- const x = p - n;
902
- n = n + x;
903
- }
904
- a = r.index, s.push(l);
905
- }
906
- return s.reverse();
907
- }
908
- function Ne(e, t, i) {
909
- const n = e.slice().sort((l, p) => l.skip - p.skip).sort((l, p) => l.index - p.index);
910
- let a = i, s = 0, r = t;
911
- for (const l of n.reverse()) {
912
- const p = r - l.index;
913
- if (a = a - p, a > -1)
914
- s++, r = l.index;
915
- else
916
- break;
917
- }
918
- return s;
919
- }
920
- function Ze(e) {
921
- return Object.values(e).flatMap((t) => t).sort(
922
- (t, i) => new Date(t.timestamp).getTime() - new Date(i.timestamp).getTime()
923
- );
924
- }
925
- function De(e) {
926
- return Object.values(e).flatMap((t) => t).sort(
927
- (t, i) => new Date(t.operation.timestamp).getTime() - new Date(i.operation.timestamp).getTime()
928
- );
929
- }
930
- function mt(e, t, i, n, a, s = Lt, r = {}, l) {
931
- const p = Te(i, s);
932
- return Ct(
933
- e,
934
- t,
935
- p,
936
- n,
937
- a,
938
- r,
939
- l
940
- );
941
- }
942
- function Ct(e, t, i, n, a, s = {}, r) {
943
- const l = (r == null ? void 0 : r.checkHashes) ?? !0, p = ke(e), x = Object.keys(t).reduce(($, D) => {
944
- const E = D;
945
- return {
946
- ...$,
947
- [E]: Ae(
948
- t[E],
949
- s[E]
950
- )
951
- };
952
- }, {}), b = De(x), v = b.reduce(
953
- ($, { ignore: D, operation: E }) => D ? i($, yt(E.scope), n, {
954
- skip: E.skip,
955
- ignoreSkipOperations: !0
956
- // TODO: reuse hash?
957
- }) : i($, E, n, {
958
- skip: E.skip,
959
- ignoreSkipOperations: !0,
960
- reuseHash: !l
961
- }),
962
- p
963
- );
964
- if (!l)
965
- for (const $ of Object.keys(v.state))
966
- for (let D = b.length - 1; D >= 0; D--) {
967
- const { ignore: E, operation: c } = b[D];
968
- if (!(E || c.scope !== $)) {
969
- if (c.hash !== xt(v, $))
970
- throw new Error(`Hash mismatch for scope ${$}`);
971
- break;
972
- }
973
- }
974
- const h = Object.keys(
975
- v.operations
976
- ).reduce(
977
- ($, D) => {
978
- const E = D;
979
- return {
980
- ...$,
981
- [E]: [
982
- ...v.operations[E].map((c, u) => {
983
- var y;
984
- return {
985
- ...c,
986
- timestamp: ((y = t[E][u]) == null ? void 0 : y.timestamp) ?? c.timestamp
987
- };
988
- })
989
- ]
990
- };
991
- },
992
- { global: [], local: [] }
993
- ), O = Object.values(h).reduce(($, D) => {
994
- const E = D[D.length - 1];
995
- return (E == null ? void 0 : E.timestamp) > $ && ($ = E.timestamp), $;
996
- }, e.lastModified);
997
- return { ...v, operations: h, lastModified: O };
998
- }
999
- function Ge(e, t) {
1000
- return rt(e) === rt(t);
1001
- }
1002
- const Jt = (e) => H(
1003
- "SET_NAME",
1004
- e,
1005
- void 0,
1006
- gt,
1007
- void 0
1008
- ), Ut = (e = 1, t = "global") => H(
1009
- "UNDO",
1010
- e,
1011
- void 0,
1012
- ht,
1013
- t
1014
- ), Vt = (e = 1, t = "global") => H(
1015
- "REDO",
1016
- e,
1017
- void 0,
1018
- dt,
1019
- t
1020
- ), Kt = (e, t, i = "global") => H(
1021
- "PRUNE",
1022
- { start: e, end: t },
1023
- void 0,
1024
- ft,
1025
- i
1026
- ), bt = (e, t) => H(
1027
- "LOAD_STATE",
1028
- { state: e, operations: t },
1029
- void 0,
1030
- ut
1031
- ), yt = (e = "global") => H("NOOP", {}, void 0, void 0, e), Qe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1032
- __proto__: null,
1033
- loadState: bt,
1034
- noop: yt,
1035
- prune: Kt,
1036
- redo: Vt,
1037
- setName: Jt,
1038
- undo: Ut
1039
- }, Symbol.toStringTag, { value: "Module" })), Ht = { "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"] };
1040
- Object.freeze(Ht);
1041
- var L = function(e, t, i, n) {
1042
- if (i === "a" && !n)
1043
- throw new TypeError("Private accessor was defined without a getter");
1044
- if (typeof t == "function" ? e !== t || !n : !t.has(e))
1045
- throw new TypeError("Cannot read private member from an object whose class did not declare it");
1046
- return i === "m" ? n : i === "a" ? n.call(e) : n ? n.value : t.get(e);
1047
- }, K, Z, U;
1048
- class Me {
1049
- constructor(...t) {
1050
- K.set(this, /* @__PURE__ */ new Map()), Z.set(this, /* @__PURE__ */ new Map()), U.set(this, /* @__PURE__ */ new Map());
1051
- for (const i of t)
1052
- this.define(i);
1053
- }
1054
- define(t, i = !1) {
1055
- for (let [n, a] of Object.entries(t)) {
1056
- n = n.toLowerCase(), a = a.map((l) => l.toLowerCase()), L(this, U, "f").has(n) || L(this, U, "f").set(n, /* @__PURE__ */ new Set());
1057
- const s = L(this, U, "f").get(n);
1058
- let r = !0;
1059
- for (let l of a) {
1060
- const p = l.startsWith("*");
1061
- if (l = p ? l.slice(1) : l, s == null || s.add(l), r && L(this, Z, "f").set(n, l), r = !1, p)
1062
- continue;
1063
- const x = L(this, K, "f").get(l);
1064
- if (x && x != n && !i)
1065
- throw new Error(`"${n} -> ${l}" conflicts with "${x} -> ${l}". Pass \`force=true\` to override this definition.`);
1066
- L(this, K, "f").set(l, n);
1067
- }
1068
- }
1069
- return this;
1070
- }
1071
- getType(t) {
1072
- if (typeof t != "string")
1073
- return null;
1074
- const i = t.replace(/^.*[/\\]/, "").toLowerCase(), n = i.replace(/^.*\./, "").toLowerCase(), a = i.length < t.length;
1075
- return !(n.length < i.length - 1) && a ? null : L(this, K, "f").get(n) ?? null;
1076
- }
1077
- getExtension(t) {
1078
- var i;
1079
- return typeof t != "string" ? null : (t = (i = t == null ? void 0 : t.split) == null ? void 0 : i.call(t, ";")[0], (t && L(this, Z, "f").get(t.trim().toLowerCase())) ?? null);
1080
- }
1081
- getAllExtensions(t) {
1082
- return typeof t != "string" ? null : L(this, U, "f").get(t.toLowerCase()) ?? null;
1083
- }
1084
- _freeze() {
1085
- this.define = () => {
1086
- throw new Error("define() not allowed for built-in Mime objects. See https://github.com/broofa/mime/blob/main/README.md#custom-mime-instances");
1087
- }, Object.freeze(this);
1088
- for (const t of L(this, U, "f").values())
1089
- Object.freeze(t);
1090
- return this;
1091
- }
1092
- _getTestState() {
1093
- return {
1094
- types: L(this, K, "f"),
1095
- extensions: L(this, Z, "f")
1096
- };
1097
- }
1098
- }
1099
- K = /* @__PURE__ */ new WeakMap(), Z = /* @__PURE__ */ new WeakMap(), U = /* @__PURE__ */ new WeakMap();
1100
- const Pe = new Me(Ht)._freeze();
1101
- function Ie(e) {
1102
- const t = [], i = Object.keys(e);
1103
- for (const n of i) {
1104
- const a = e[n].sort((s, r) => s.index - r.index);
1105
- for (let s = 0; s < a.length; s++)
1106
- a[s].index !== s && t.push({
1107
- message: `Invalid operation index ${a[s].index} at position ${s}`,
1108
- details: {
1109
- position: s,
1110
- operation: a[s],
1111
- scope: a[s].scope
1112
- }
1113
- });
1114
- }
1115
- return t;
1116
- }
1117
- const Wt = async (e) => {
1118
- const t = new Ot(), { name: i, revision: n, documentType: a, created: s, lastModified: r } = e, l = {
1119
- name: i,
1120
- revision: n,
1121
- documentType: a,
1122
- created: s,
1123
- lastModified: r
1124
- };
1125
- return t.file("header.json", JSON.stringify(l, null, 2)), t.file(
1126
- "state.json",
1127
- JSON.stringify(e.initialState || {}, null, 2)
1128
- ), t.file("operations.json", JSON.stringify(e.operations, null, 2)), Object.keys(e.attachments).forEach((x) => {
1129
- const { data: b, ...v } = e.attachments[x];
1130
- t.file(x, b, {
1131
- base64: !0,
1132
- createFolders: !0,
1133
- comment: JSON.stringify(v)
1134
- });
1135
- }), t;
1136
- }, ze = async (e, t, i, n) => {
1137
- const s = await (await Wt(e)).generateAsync({
1138
- type: "uint8array",
1139
- streamFiles: !0
1140
- }), r = n ?? e.name, l = `.${i}.zip`;
1141
- return Oe(
1142
- t,
1143
- r.endsWith(l) ? r : `${r}${l}`,
1144
- s
1145
- );
1146
- }, Xe = async (e, t) => {
1147
- const n = await (await Wt(e)).generateAsync({ type: "blob" }), a = await t.createWritable();
1148
- await a.write(n), await a.close();
1149
- }, St = async (e, t, i) => {
1150
- const n = qt(e);
1151
- return Fe(n, t, i);
1152
- }, Fe = async (e, t, i) => {
1153
- const n = new Ot();
1154
- return await n.loadAsync(e), Re(n, t, i);
1155
- };
1156
- async function Re(e, t, i) {
1157
- const n = e.file("state.json");
1158
- if (!n)
1159
- throw new Error("Initial state not found");
1160
- const a = await n.async("string"), s = JSON.parse(a), r = e.file("header.json");
1161
- let l;
1162
- r && (l = JSON.parse(await r.async("string")));
1163
- const p = e.file("operations.json");
1164
- if (!p)
1165
- throw new Error("Operations history not found");
1166
- const x = JSON.parse(
1167
- await p.async("string")
1168
- ), b = Ie(x);
1169
- if (b.length) {
1170
- const h = b.map((O) => O.message);
1171
- throw new Error(h.join(`
1172
- `));
1173
- }
1174
- let v = Ct(
1175
- s,
1176
- x,
1177
- t,
1178
- void 0,
1179
- l,
1180
- {},
1181
- i
1182
- );
1183
- return l && (v = {
1184
- ...v,
1185
- ...l
1186
- }), v;
1187
- }
1188
- function Bt(e) {
1189
- const t = e.replace(/^.*\./, "") || void 0, i = e.replace(/^.*[/\\]/, "") || void 0;
1190
- return { extension: t, fileName: i };
1191
- }
1192
- async function Ye(e) {
1193
- const { buffer: t, mimeType: i = "application/octet-stream" } = await $e(e), n = Bt(e), a = t.toString("base64");
1194
- return {
1195
- data: a,
1196
- hash: at(a),
1197
- mimeType: i,
1198
- ...n
1199
- };
1200
- }
1201
- async function ti(e) {
1202
- const t = await Ee(e), i = Pe.getType(e) || "application/octet-stream", n = Bt(e), a = t.toString("base64");
1203
- return { data: a, hash: at(a), mimeType: i, ...n };
1204
- }
1205
- class ei {
1206
- /**
1207
- * Constructs a BaseDocument instance with an initial state.
1208
- * @param reducer - The reducer function that updates the state.
1209
- * @param document - The initial state of the document.
1210
- */
1211
- constructor(t, i, n) {
1212
- nt(this, "_document");
1213
- nt(this, "_reducer");
1214
- nt(this, "_signalDispatch");
1215
- this._reducer = t, this._document = i, this._signalDispatch = n;
1216
- }
1217
- /**
1218
- * Dispatches an action to update the state of the document.
1219
- * @param action - The action to dispatch.
1220
- * @returns The Document instance.
1221
- */
1222
- dispatch(t, i) {
1223
- return this._document = this._reducer(
1224
- this._document,
1225
- t,
1226
- this._signalDispatch,
1227
- i
1228
- ), this;
1229
- }
1230
- /**
1231
- * Saves the state of the document to a file.
1232
- * @param path - The file path where the state should be saved.
1233
- * @param extension - The file extension to use when saving the state.
1234
- * @returns The file path where the state was saved.
1235
- */
1236
- saveToFile(t, i, n) {
1237
- return ze(this._document, t, i, n);
1238
- }
1239
- /**
1240
- * Loads the state of the document from a file.
1241
- * @param path - The file path where the state is stored.
1242
- */
1243
- async loadFromFile(t) {
1244
- this._document = await St(t, this._reducer);
1245
- }
1246
- /**
1247
- * Loads the state of the document from a file and returns it.
1248
- * @param path - The file path where the state is stored.
1249
- * @param reducer - The reducer function that updates the state.
1250
- * @returns The state of the document.
1251
- */
1252
- static async stateFromFile(t, i) {
1253
- return await St(t, i);
1254
- }
1255
- /**
1256
- * Gets the current state of the document.
1257
- */
1258
- get state() {
1259
- return ot(this._document.state);
1260
- }
1261
- /**
1262
- * Gets the list of operations performed on the document.
1263
- */
1264
- get operations() {
1265
- return ot(this._document.operations);
1266
- }
1267
- /**
1268
- * Gets the name of the document.
1269
- */
1270
- get name() {
1271
- return this._document.name;
1272
- }
1273
- /**
1274
- * Gets the type of document.
1275
- */
1276
- get documentType() {
1277
- return this._document.documentType;
1278
- }
1279
- /**
1280
- * Gets the timestamp of the date the document was created.
1281
- */
1282
- get created() {
1283
- return this._document.created;
1284
- }
1285
- /**
1286
- * Gets the timestamp of the date the document was last modified.
1287
- */
1288
- get lastModified() {
1289
- return this._document.lastModified;
1290
- }
1291
- /**
1292
- * Gets the global revision number of the document.
1293
- */
1294
- get revision() {
1295
- return this._document.revision.global;
1296
- }
1297
- getRevision(t) {
1298
- return this._document.revision[t];
1299
- }
1300
- /**
1301
- * Gets the initial state of the document.
1302
- */
1303
- get initialState() {
1304
- return ot(this._document.initialState);
1305
- }
1306
- /**
1307
- * Returns the current document as an object
1308
- */
1309
- toDocument() {
1310
- return ot(this._document);
1311
- }
1312
- /**
1313
- * Gets the attachment associated with the given key.
1314
- * @param attachment - The key of the attachment to retrieve.
1315
- */
1316
- getAttachment(t) {
1317
- return this._document.attachments[t];
1318
- }
1319
- /**
1320
- * Sets the name of the document.
1321
- * @param name - The new name of the document.
1322
- */
1323
- setName(t) {
1324
- return this.dispatch(Jt(t)), this;
1325
- }
1326
- /**
1327
- * Reverts a number of actions from the document.
1328
- * @param count - The number of actions to revert.
1329
- */
1330
- undo(t) {
1331
- return this.dispatch(Ut(t)), this;
1332
- }
1333
- /**
1334
- * Reapplies a number of actions to the document.
1335
- * @param count - The number of actions to reapply.
1336
- */
1337
- redo(t) {
1338
- return this.dispatch(Vt(t)), this;
1339
- }
1340
- /**
1341
- * Removes a range of operations from the document.
1342
- * @param start - The starting index of the range to remove.
1343
- * @param end - The ending index of the range to remove.
1344
- */
1345
- prune(t, i) {
1346
- return this.dispatch(Kt(t, i)), this;
1347
- }
1348
- /**
1349
- * Loads a document state and a set of operations.
1350
- * @param state - The state to load.
1351
- * @param operations - The operations to apply to the document.
1352
- */
1353
- loadState(t, i) {
1354
- return this.dispatch(bt(t, i)), this;
1355
- }
1356
- }
1357
- function ii(e, t) {
1358
- t.forEach((i) => {
1359
- Object.getOwnPropertyNames(i.prototype).forEach((n) => {
1360
- Object.defineProperty(
1361
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
1362
- e.prototype,
1363
- n,
1364
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
1365
- Object.getOwnPropertyDescriptor(i.prototype, n) || /* @__PURE__ */ Object.create(null)
1366
- );
1367
- });
1368
- });
1369
- }
1370
- export {
1371
- Ie as A,
1372
- ei as B,
1373
- Lt as C,
1374
- Se as D,
1375
- We as E,
1376
- _e as a,
1377
- ke as b,
1378
- Te as c,
1379
- Xe as d,
1380
- Fe as e,
1381
- H as f,
1382
- ii as g,
1383
- Qe as h,
1384
- jt as i,
1385
- Ne as j,
1386
- Wt as k,
1387
- St as l,
1388
- ti as m,
1389
- Ye as n,
1390
- xt as o,
1391
- Be as p,
1392
- ve as q,
1393
- Ge as r,
1394
- ze as s,
1395
- wt as t,
1396
- Ae as u,
1397
- ot as v,
1398
- Ct as w,
1399
- mt as x,
1400
- De as y,
1401
- Ze as z
1402
- };