document-model 1.0.41 → 1.0.43

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 (110) hide show
  1. package/dist/browser/document-model.cjs +1 -1
  2. package/dist/browser/document-model.js +14 -15
  3. package/dist/browser/document.cjs +1 -1
  4. package/dist/browser/document.js +9 -10
  5. package/dist/browser/index.cjs +1 -1
  6. package/dist/browser/index.js +6 -7
  7. package/dist/browser/internal/{index-BWV1Osza.js → index-CDcO7NCS.js} +3 -4
  8. package/dist/browser/internal/{index-BD_7XeO5.js → index-CfgX2mMt.js} +1 -1
  9. package/dist/browser/internal/{index-BxGRRPwY.js → index-DhzefrNj.js} +1 -1
  10. package/dist/{node/internal/index-LEexvgqj.js → browser/internal/index-EdTViyyq.js} +1 -1
  11. package/dist/browser/internal/object-BkewFVld.js +25 -0
  12. package/dist/browser/internal/object-CrDRbO7a.js +2492 -0
  13. package/dist/node/document-model.cjs +1 -1
  14. package/dist/node/document-model.js +15 -16
  15. package/dist/node/document.cjs +1 -1
  16. package/dist/node/document.js +9 -10
  17. package/dist/node/index.cjs +1 -1
  18. package/dist/node/index.js +7 -8
  19. package/dist/node/internal/{index-Dh0vfIdX.js → index-BWW7KbVk.js} +2 -2
  20. package/dist/node/internal/{index-DeKx7EaE.js → index-Cz8HaIxu.js} +3 -4
  21. package/dist/{browser/internal/index-BNBYVtaF.js → node/internal/index-D_LMFQg7.js} +1 -1
  22. package/dist/node/internal/{index-LD_vrQff.js → index-fctxJxHD.js} +1 -1
  23. package/dist/node/internal/object-BDRv-l-h.js +1390 -0
  24. package/dist/node/internal/object-Br6jYeW0.js +20 -0
  25. package/dist/src/document/actions/creators.d.ts +47 -0
  26. package/dist/src/document/actions/index.d.ts +14 -0
  27. package/dist/src/document/actions/types.d.ts +15 -0
  28. package/dist/src/document/index.d.ts +6 -0
  29. package/dist/src/document/object.d.ts +1140 -0
  30. package/dist/src/document/reducer.d.ts +32 -0
  31. package/dist/src/document/schema/index.d.ts +2 -0
  32. package/dist/src/document/schema/types.d.ts +176 -0
  33. package/dist/src/document/schema/zod.d.ts +113 -0
  34. package/dist/src/document/signal.d.ts +29 -0
  35. package/dist/src/document/types.d.ts +245 -0
  36. package/dist/src/document/utils/base.d.ts +80 -0
  37. package/dist/src/document/utils/browser.d.ts +10 -0
  38. package/dist/src/document/utils/file.d.ts +47 -0
  39. package/dist/src/document/utils/index.d.ts +4 -0
  40. package/dist/src/document/utils/node.d.ts +9 -0
  41. package/dist/src/document/utils/validation.d.ts +2 -0
  42. package/dist/src/document-model/custom/reducers/header.d.ts +2 -0
  43. package/dist/src/document-model/custom/reducers/module.d.ts +2 -0
  44. package/dist/src/document-model/custom/reducers/operation-error.d.ts +2 -0
  45. package/dist/src/document-model/custom/reducers/operation-example.d.ts +2 -0
  46. package/dist/src/document-model/custom/reducers/operation.d.ts +2 -0
  47. package/dist/src/document-model/custom/reducers/state.d.ts +2 -0
  48. package/dist/src/document-model/custom/reducers/versioning.d.ts +7 -0
  49. package/dist/src/document-model/custom/utils.d.ts +7 -0
  50. package/dist/src/document-model/gen/actions.d.ts +15 -0
  51. package/dist/src/document-model/gen/creators.d.ts +7 -0
  52. package/dist/src/document-model/gen/document-model.d.ts +2 -0
  53. package/dist/src/document-model/gen/header/actions.d.ts +9 -0
  54. package/dist/src/document-model/gen/header/creators.d.ts +8 -0
  55. package/dist/src/document-model/gen/header/object.d.ts +12 -0
  56. package/dist/src/document-model/gen/header/operations.d.ts +10 -0
  57. package/dist/src/document-model/gen/index.d.ts +5 -0
  58. package/dist/src/document-model/gen/module/actions.d.ts +8 -0
  59. package/dist/src/document-model/gen/module/creators.d.ts +7 -0
  60. package/dist/src/document-model/gen/module/object.d.ts +11 -0
  61. package/dist/src/document-model/gen/module/operations.d.ts +9 -0
  62. package/dist/src/document-model/gen/object.d.ts +28 -0
  63. package/dist/src/document-model/gen/operation/actions.d.ts +13 -0
  64. package/dist/src/document-model/gen/operation/creators.d.ts +12 -0
  65. package/dist/src/document-model/gen/operation/object.d.ts +16 -0
  66. package/dist/src/document-model/gen/operation/operations.d.ts +14 -0
  67. package/dist/src/document-model/gen/operation-error/actions.d.ts +10 -0
  68. package/dist/src/document-model/gen/operation-error/creators.d.ts +9 -0
  69. package/dist/src/document-model/gen/operation-error/object.d.ts +13 -0
  70. package/dist/src/document-model/gen/operation-error/operations.d.ts +11 -0
  71. package/dist/src/document-model/gen/operation-example/actions.d.ts +7 -0
  72. package/dist/src/document-model/gen/operation-example/creators.d.ts +6 -0
  73. package/dist/src/document-model/gen/operation-example/object.d.ts +10 -0
  74. package/dist/src/document-model/gen/operation-example/operations.d.ts +8 -0
  75. package/dist/src/document-model/gen/reducer.d.ts +5 -0
  76. package/dist/src/document-model/gen/schema/index.d.ts +2 -0
  77. package/dist/src/document-model/gen/schema/types.d.ts +453 -0
  78. package/dist/src/document-model/gen/schema/zod.d.ts +453 -0
  79. package/dist/src/document-model/gen/state/actions.d.ts +9 -0
  80. package/dist/src/document-model/gen/state/creators.d.ts +8 -0
  81. package/dist/src/document-model/gen/state/object.d.ts +12 -0
  82. package/dist/src/document-model/gen/state/operations.d.ts +10 -0
  83. package/dist/src/document-model/gen/types.d.ts +8 -0
  84. package/dist/src/document-model/gen/utils.d.ts +6 -0
  85. package/dist/src/document-model/gen/versioning/actions.d.ts +8 -0
  86. package/dist/src/document-model/gen/versioning/creators.d.ts +7 -0
  87. package/dist/src/document-model/gen/versioning/object.d.ts +11 -0
  88. package/dist/src/document-model/gen/versioning/operations.d.ts +9 -0
  89. package/dist/src/document-model/index.d.ts +80 -0
  90. package/dist/src/index.d.ts +25 -0
  91. package/dist/test/document/event-vs-command.test.d.ts +1 -0
  92. package/dist/test/document/local.test.d.ts +1 -0
  93. package/dist/test/document/object.test.d.ts +1 -0
  94. package/dist/test/document/prune.test.d.ts +1 -0
  95. package/dist/test/document/reducer.test.d.ts +1 -0
  96. package/dist/test/document/skip-operations.test.d.ts +1 -0
  97. package/dist/test/document/undo-redo.test.d.ts +1 -0
  98. package/dist/test/document/utils.test.d.ts +1 -0
  99. package/dist/test/document-model/object.test.d.ts +1 -0
  100. package/dist/test/document-model/skip-operations.test.d.ts +1 -0
  101. package/dist/test/document-model/validation.test.d.ts +1 -0
  102. package/dist/test/document-model/zip.test.d.ts +1 -0
  103. package/dist/test/helpers.d.ts +34 -0
  104. package/dist/vite.config.d.ts +2 -0
  105. package/dist/vitest.config.d.ts +2 -0
  106. package/package.json +3 -2
  107. package/dist/browser/internal/object-DHqlosWD.js +0 -7
  108. package/dist/browser/internal/object-StihF423.js +0 -1999
  109. package/dist/node/internal/object-CKxJA706.js +0 -2
  110. package/dist/node/internal/object-CudRLU4J.js +0 -998
@@ -1,998 +0,0 @@
1
- var vt = Object.defineProperty;
2
- var jt = (e, t, i) => t in e ? vt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[t] = i;
3
- var E = (e, t, i) => (jt(e, typeof t != "symbol" ? t + "" : t, i), i);
4
- import { produce as y, castDraft as A, castImmutable as yt, freeze as Ot } from "immer";
5
- import z from "json-stringify-deterministic";
6
- import { z as c } from "zod";
7
- import kt from "crypto";
8
- import M from "fs";
9
- import St from "https";
10
- import { join as _t } from "path";
11
- import Z from "jszip";
12
- const H = (e) => e != null, Et = c.any().refine((e) => H(e)), K = c.enum(["LOAD_STATE"]), V = c.enum(["PRUNE"]), G = c.enum(["REDO"]), Q = c.enum(["SET_NAME"]), X = c.enum(["UNDO"]);
13
- function Dt() {
14
- return c.object({
15
- __typename: c.literal("Action").optional(),
16
- type: c.string()
17
- });
18
- }
19
- function O() {
20
- return c.literal("global").or(c.literal("local"));
21
- }
22
- function Y() {
23
- return c.union([
24
- tt(),
25
- it(),
26
- nt(),
27
- at(),
28
- ot()
29
- ]);
30
- }
31
- function Nt() {
32
- return c.object({
33
- __typename: c.literal("DocumentFile").optional(),
34
- data: c.string(),
35
- extension: c.string().nullable(),
36
- fileName: c.string().nullable(),
37
- mimeType: c.string()
38
- });
39
- }
40
- function tt() {
41
- return c.object({
42
- input: c.lazy(() => P()),
43
- type: K,
44
- scope: O()
45
- });
46
- }
47
- function P() {
48
- return c.object({
49
- operations: c.number(),
50
- state: c.lazy(() => et())
51
- });
52
- }
53
- function et() {
54
- return c.object({
55
- data: c.unknown().nullish(),
56
- name: c.string()
57
- });
58
- }
59
- function Tt() {
60
- return c.object({
61
- __typename: c.literal("Operation").optional(),
62
- hash: c.string(),
63
- index: c.number(),
64
- timestamp: c.string().datetime(),
65
- type: c.string()
66
- });
67
- }
68
- function it() {
69
- return c.object({
70
- input: c.lazy(() => F()),
71
- type: V,
72
- scope: O()
73
- });
74
- }
75
- function F() {
76
- return c.object({
77
- end: c.number().nullish(),
78
- start: c.number().nullish()
79
- });
80
- }
81
- const R = c.number;
82
- function nt() {
83
- return c.object({
84
- input: R(),
85
- type: G,
86
- scope: O()
87
- });
88
- }
89
- const L = c.string;
90
- function at() {
91
- return c.object({
92
- input: L(),
93
- type: Q,
94
- scope: c.literal("global")
95
- });
96
- }
97
- function At() {
98
- return c.object({
99
- __typename: c.literal("SetNameOperation").optional(),
100
- hash: c.string(),
101
- index: c.number(),
102
- input: c.string(),
103
- timestamp: c.string().datetime(),
104
- type: c.string()
105
- });
106
- }
107
- const q = c.number;
108
- function ot() {
109
- return c.object({
110
- input: q(),
111
- type: X,
112
- scope: O()
113
- });
114
- }
115
- const ge = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
116
- __proto__: null,
117
- ActionSchema: Dt,
118
- BaseActionSchema: Y,
119
- DocumentFileSchema: Nt,
120
- LoadStateActionInputSchema: P,
121
- LoadStateActionSchema: tt,
122
- LoadStateActionStateInputSchema: et,
123
- Load_StateSchema: K,
124
- OperationSchema: Tt,
125
- OperationScopeSchema: O,
126
- PruneActionInputSchema: F,
127
- PruneActionSchema: it,
128
- PruneSchema: V,
129
- RedoActionInputSchema: R,
130
- RedoActionSchema: nt,
131
- RedoSchema: G,
132
- SetNameActionInputSchema: L,
133
- SetNameActionSchema: at,
134
- SetNameOperationSchema: At,
135
- Set_NameSchema: Q,
136
- UndoActionInputSchema: q,
137
- UndoActionSchema: ot,
138
- UndoSchema: X,
139
- definedNonNullAnySchema: Et,
140
- isDefinedNonNullAny: H
141
- }, Symbol.toStringTag, { value: "Module" }));
142
- function zt(e, t) {
143
- return { ...e, name: t };
144
- }
145
- function Mt(e, t, i) {
146
- const n = {
147
- skip: i,
148
- document: e
149
- }, { scope: o } = t;
150
- return !o || t.skip === void 0 ? n : y(n, (p) => {
151
- const [a] = p.document.operations[o].slice(-1);
152
- t.skip && t.skip > 0 && (p.skip = t.skip), a.type === "NOOP" && t.index === a.index && p.skip > a.skip && p.document.operations[o].pop();
153
- });
154
- }
155
- function It(e, t, i) {
156
- const { scope: n, input: o } = t;
157
- return y({
158
- document: e,
159
- action: t,
160
- skip: i
161
- }, (a) => {
162
- if (a.document.operations[n].length < 1)
163
- throw new Error(
164
- `Cannot undo: no operations in history for scope "${n}"`
165
- );
166
- if (o < 1)
167
- throw new Error(
168
- "Invalid UNDO action: input value must be greater than 0"
169
- );
170
- if (a.skip > 0)
171
- throw new Error(
172
- "Cannot undo: skip value from reducer cannot be used with UNDO action"
173
- );
174
- const [s] = a.document.operations[n].slice(-1), l = s.type === "NOOP" && s.skip > 0;
175
- if (a.skip += o, l) {
176
- a.skip += s.skip;
177
- const m = a.document.operations[n][a.document.operations[n].length - 2];
178
- m && s.index - m.index === 1 && a.document.operations[n].pop();
179
- }
180
- if (a.document.operations[n].length < a.skip)
181
- throw new Error(
182
- "Cannot undo: you can't undo more operations than the ones in the scope history"
183
- );
184
- const r = a.document.operations[n].length - 1;
185
- let x = o, d = l ? r - s.skip : r;
186
- for (; x > 0 && d >= 0; ) {
187
- const m = a.document.operations[n][d];
188
- if (!m) {
189
- x--, d--;
190
- continue;
191
- }
192
- m.type === "NOOP" && m.skip > 0 ? (d = d - (m.skip + 1), a.skip += m.skip + 1) : (a.document.clipboard.push({ ...m }), x--, d--);
193
- }
194
- a.action = U(n);
195
- });
196
- }
197
- function Pt(e, t, i) {
198
- const { scope: n, input: o } = t;
199
- return y({
200
- document: e,
201
- action: t,
202
- skip: i
203
- }, (a) => {
204
- if (a.skip > 0)
205
- throw new Error(
206
- "Cannot redo: skip value from reducer cannot be used with REDO action"
207
- );
208
- if (o > 1)
209
- throw new Error(
210
- "Cannot redo: you can only redo one operation at a time"
211
- );
212
- if (o < 1)
213
- throw new Error("Invalid REDO action: invalid redo input value");
214
- if (a.document.clipboard.length < 1)
215
- throw new Error("Cannot redo: no operations in the clipboard");
216
- const s = a.document.clipboard.findLastIndex(
217
- (r) => r.scope === n
218
- );
219
- if (s < 0)
220
- throw new Error(
221
- `Cannot redo: no operations in clipboard for scope "${n}"`
222
- );
223
- const l = a.document.clipboard.splice(s, 1)[0];
224
- a.action = A({
225
- type: l.type,
226
- scope: l.scope,
227
- input: l.input
228
- });
229
- });
230
- }
231
- function Ft(e, t, i) {
232
- const { scope: n } = t, o = e.operations[n];
233
- let {
234
- input: { start: p, end: a }
235
- } = t;
236
- p = p || 0, a = a || o.length;
237
- const s = o.slice(p, a), l = o.slice(0, p), r = o.slice(a), x = I(
238
- e.initialState,
239
- {
240
- ...e.operations,
241
- [n]: l.concat(s)
242
- },
243
- i
244
- ), { name: d, state: m } = x, f = l.length, u = l.length ? l[l.length - 1].timestamp : r.length ? r[0].timestamp : (/* @__PURE__ */ new Date()).toISOString();
245
- return I(
246
- e.initialState,
247
- {
248
- ...e.operations,
249
- [n]: [
250
- ...l,
251
- {
252
- ...$(
253
- { name: d, state: m },
254
- s.length
255
- ),
256
- timestamp: u,
257
- index: f,
258
- hash: lt({ state: m }, "global")
259
- },
260
- ...r.map((v, _) => ({
261
- ...v,
262
- index: f + _ + 1
263
- }))
264
- ]
265
- },
266
- i
267
- );
268
- }
269
- function Rt(e, t) {
270
- return {
271
- ...e,
272
- name: t.name,
273
- state: t.state ?? { global: {}, local: {} }
274
- };
275
- }
276
- const st = "SET_NAME", k = "UNDO", S = "REDO", N = "PRUNE", pt = "LOAD_STATE", Lt = "NOOP";
277
- function qt(e, t) {
278
- let i;
279
- return "index" in t ? i = { ...t } : i = e.operations[t.scope].slice(-1)[0], ((i == null ? void 0 : i.index) ?? -1) + 1;
280
- }
281
- function $t(e, t) {
282
- return {
283
- ...e,
284
- revision: {
285
- ...e.revision,
286
- [t.scope]: qt(e, t)
287
- },
288
- lastModified: (/* @__PURE__ */ new Date()).toISOString()
289
- };
290
- }
291
- function Ut(e, t, i = 0) {
292
- if ([k, S, N].includes(t.type))
293
- return e;
294
- const { scope: n } = t, o = e.operations[n].slice(
295
- 0,
296
- e.revision[n]
297
- ), p = [...o].pop();
298
- let a = ((p == null ? void 0 : p.index) ?? -1) + 1;
299
- if ("index" in t) {
300
- if (t.index > a + i)
301
- throw new Error(
302
- `Missing operations: expected ${a} with skip 0 or equivalent, got index ${t.index} with skip ${i}`
303
- );
304
- a = t.index;
305
- }
306
- return o.push({
307
- ...t,
308
- index: a,
309
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
310
- hash: "",
311
- scope: n,
312
- skip: i
313
- }), {
314
- ...e,
315
- operations: { ...e.operations, [n]: o }
316
- };
317
- }
318
- function Ct(e, t, i = 0) {
319
- let n = Ut(e, t, i);
320
- return n = $t(n, t), n;
321
- }
322
- function Jt(e, t, i) {
323
- switch (Y().parse(t), t.type) {
324
- case st:
325
- return zt(e, t.input);
326
- case N:
327
- return Ft(e, t, i);
328
- case pt:
329
- return Rt(e, t.input.state);
330
- default:
331
- return e;
332
- }
333
- }
334
- function Wt(e, t, i) {
335
- switch (t.type) {
336
- case k:
337
- return It(e, t, i);
338
- case S:
339
- return Pt(e, t, i);
340
- default:
341
- return { document: e, action: t, skip: i };
342
- }
343
- }
344
- function ct(e, t, i, n, o = {}) {
345
- const { skip: p, ignoreSkipOperations: a = !1 } = o;
346
- let s = { ...t }, l = p || 0, r = e, x = [...e.clipboard];
347
- if (Kt(s)) {
348
- const { document: d, skip: m } = Mt(r, s, l);
349
- l = m, r = d;
350
- }
351
- if (J(s)) {
352
- const {
353
- skip: d,
354
- action: m,
355
- document: f
356
- } = Wt(e, s, l);
357
- s = m, l = d, r = f, x = [...r.clipboard];
358
- }
359
- if (W(s) && (r = Jt(r, s, i)), l > 0 && !a) {
360
- let d = l;
361
- "index" in s && (d = Yt(
362
- r.operations[s.scope],
363
- s.index,
364
- l
365
- )), r = I(
366
- r.initialState,
367
- r.operations,
368
- i,
369
- void 0,
370
- void 0,
371
- void 0,
372
- { [s.scope]: d }
373
- );
374
- }
375
- return r = Ct(r, s, l), r = y(r, (d) => {
376
- const m = i(
377
- d.state,
378
- s,
379
- n
380
- ), f = J(t) ? [...x] : [];
381
- if (m)
382
- return A({
383
- ...r,
384
- clipboard: [...f],
385
- state: m
386
- });
387
- d.clipboard = A([...f]);
388
- }), y(r, (d) => {
389
- if ([k, S, N].includes(s.type))
390
- return d;
391
- const m = s.scope || "global";
392
- d.operations[m][d.operations[m].length - 1].hash = lt(d, m), !W(s) && s.attachments && s.attachments.forEach((f) => {
393
- const { hash: u, ...v } = f;
394
- d.attachments[u] = {
395
- ...v
396
- };
397
- });
398
- });
399
- }
400
- function Bt(e, t, i) {
401
- const n = _t(e, t);
402
- return M.mkdirSync(e, { recursive: !0 }), new Promise((o, p) => {
403
- try {
404
- M.writeFile(n, i, {}, (a) => {
405
- a ? p(a) : o(n);
406
- });
407
- } catch (a) {
408
- p(a);
409
- }
410
- });
411
- }
412
- function rt(e) {
413
- return M.readFileSync(e);
414
- }
415
- function Zt(e) {
416
- return new Promise((t, i) => {
417
- St.get(e, (n) => {
418
- const o = [], p = n.headers["content-type"];
419
- n.on("data", (a) => {
420
- o.push(a);
421
- }), n.on("end", () => {
422
- t({ buffer: Buffer.concat(o), mimeType: p });
423
- });
424
- }).on("error", (n) => {
425
- i(n);
426
- });
427
- });
428
- }
429
- const Ht = async (e) => rt(e), T = (e, t = "sha1") => kt.createHash(t).update(e).digest("base64");
430
- function Kt(e) {
431
- return e.type === Lt && e.skip !== void 0 && e.skip > 0 && e.hash !== void 0;
432
- }
433
- function J(e) {
434
- return [k, S].includes(e.type);
435
- }
436
- function W(e) {
437
- return [st, k, S, N, pt].includes(e.type);
438
- }
439
- function w(e, t, i, n, o = "global") {
440
- if (!e)
441
- throw new Error("Empty action type");
442
- if (typeof e != "string")
443
- throw new Error(`Invalid action type: ${e}`);
444
- const p = { type: e, input: t, scope: o };
445
- i && (p.attachments = i);
446
- try {
447
- n == null || n().parse(p.input);
448
- } catch (a) {
449
- throw new Error(`Invalid action input: ${a}`);
450
- }
451
- return p;
452
- }
453
- function Vt(e, t = ct) {
454
- return (i, n, o, p) => t(i, n, e, o, p);
455
- }
456
- const Gt = (e, t) => ({
457
- name: "",
458
- documentType: "",
459
- revision: {
460
- global: 0,
461
- local: 0
462
- },
463
- created: (/* @__PURE__ */ new Date()).toISOString(),
464
- lastModified: (/* @__PURE__ */ new Date()).toISOString(),
465
- attachments: {},
466
- ...e,
467
- state: (t == null ? void 0 : t(e == null ? void 0 : e.state)) ?? (e == null ? void 0 : e.state) ?? { global: {}, local: {} }
468
- }), Qt = (e, t) => {
469
- const i = Gt(
470
- e,
471
- t
472
- );
473
- return {
474
- ...i,
475
- initialState: i,
476
- operations: { global: [], local: [] },
477
- clipboard: []
478
- };
479
- }, lt = (e, t = "global") => T(z(e.state[t])), he = (e, t = 1e3) => {
480
- const i = Math.random() * t;
481
- return T(`${(e ?? /* @__PURE__ */ new Date()).toISOString()}${i}`);
482
- };
483
- function D(e) {
484
- return yt(Ot(e, !0));
485
- }
486
- function Xt(e, t) {
487
- const i = [...e];
488
- let n = t || 0, o = i.length > 0 ? i[i.length - 1].index : 0;
489
- const p = [];
490
- for (const a of i.reverse()) {
491
- if (n > 0) {
492
- const r = o - a.index;
493
- n -= r;
494
- }
495
- if (n < 0)
496
- throw new Error("Invalid operation index, missing operations");
497
- const s = {
498
- ignore: n > 0,
499
- operation: a
500
- }, l = a.skip > 0 ? a.skip + 1 : 0;
501
- if (l > 0 && l > n) {
502
- const r = l - n;
503
- n = n + r;
504
- }
505
- o = a.index, p.push(s);
506
- }
507
- return p.reverse();
508
- }
509
- function Yt(e, t, i) {
510
- const n = e.slice().sort((s, l) => s.skip - l.skip).sort((s, l) => s.index - l.index);
511
- let o = i, p = 0, a = t;
512
- for (const s of n.reverse()) {
513
- const l = a - s.index;
514
- if (o = o - l, o > -1)
515
- p++, a = s.index;
516
- else
517
- break;
518
- }
519
- return p;
520
- }
521
- function be(e) {
522
- return Object.values(e).flatMap((t) => t).sort(
523
- (t, i) => new Date(t.timestamp).getTime() - new Date(i.timestamp).getTime()
524
- );
525
- }
526
- function te(e) {
527
- return Object.values(e).flatMap((t) => t).sort(
528
- (t, i) => new Date(t.operation.timestamp).getTime() - new Date(i.operation.timestamp).getTime()
529
- );
530
- }
531
- function I(e, t, i, n, o, p = ct, a = {}) {
532
- const s = Vt(i, p);
533
- return mt(
534
- e,
535
- t,
536
- s,
537
- n,
538
- o,
539
- a
540
- );
541
- }
542
- function mt(e, t, i, n, o, p = {}) {
543
- const a = Qt(e), s = Object.keys(t).reduce((m, f) => {
544
- const u = f;
545
- return {
546
- ...m,
547
- [u]: t[u].slice(0, o == null ? void 0 : o.revision[u])
548
- };
549
- }, {}), l = Object.keys(s).reduce(
550
- (m, f) => {
551
- const u = f;
552
- return {
553
- ...m,
554
- [u]: Xt(
555
- s[u],
556
- p[u]
557
- )
558
- };
559
- },
560
- {}
561
- ), r = te(l).reduce(
562
- (m, { ignore: f, operation: u }) => f ? i(m, U(u.scope), n, {
563
- skip: u.skip,
564
- ignoreSkipOperations: !0
565
- }) : i(m, u, n, {
566
- skip: u.skip,
567
- ignoreSkipOperations: !0
568
- }),
569
- a
570
- ), x = Object.keys(
571
- r.operations
572
- ).reduce(
573
- (m, f) => {
574
- const u = f, v = o && o.revision[u] < t[u].length ? t[u].slice(o.revision[u]) : [];
575
- return {
576
- ...m,
577
- [u]: [
578
- ...r.operations[u].map((_, wt) => {
579
- var C;
580
- return {
581
- ..._,
582
- timestamp: ((C = t[u][wt]) == null ? void 0 : C.timestamp) ?? _.timestamp
583
- };
584
- }),
585
- ...v
586
- ]
587
- };
588
- },
589
- { global: [], local: [] }
590
- ), d = Object.values(x).reduce((m, f) => {
591
- for (const u of f)
592
- u.timestamp > m && (m = u.timestamp);
593
- return m;
594
- }, e.lastModified);
595
- return { ...r, operations: x, lastModified: d };
596
- }
597
- function we(e, t) {
598
- return z(e) === z(t);
599
- }
600
- const dt = (e) => w(
601
- "SET_NAME",
602
- e,
603
- void 0,
604
- L,
605
- void 0
606
- ), ut = (e = 1, t = "global") => w(
607
- "UNDO",
608
- e,
609
- void 0,
610
- q,
611
- t
612
- ), ft = (e = 1, t = "global") => w(
613
- "REDO",
614
- e,
615
- void 0,
616
- R,
617
- t
618
- ), xt = (e, t, i = "global") => w(
619
- "PRUNE",
620
- { start: e, end: t },
621
- void 0,
622
- F,
623
- i
624
- ), $ = (e, t) => w(
625
- "LOAD_STATE",
626
- { state: e, operations: t },
627
- void 0,
628
- P
629
- ), U = (e = "global") => w("NOOP", {}, void 0, void 0, e), ve = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
630
- __proto__: null,
631
- loadState: $,
632
- noop: U,
633
- prune: xt,
634
- redo: ft,
635
- setName: dt,
636
- undo: ut
637
- }, Symbol.toStringTag, { value: "Module" })), gt = { "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"] };
638
- Object.freeze(gt);
639
- var g = function(e, t, i, n) {
640
- if (i === "a" && !n)
641
- throw new TypeError("Private accessor was defined without a getter");
642
- if (typeof t == "function" ? e !== t || !n : !t.has(e))
643
- throw new TypeError("Cannot read private member from an object whose class did not declare it");
644
- return i === "m" ? n : i === "a" ? n.call(e) : n ? n.value : t.get(e);
645
- }, b, j, h;
646
- class ee {
647
- constructor(...t) {
648
- b.set(this, /* @__PURE__ */ new Map()), j.set(this, /* @__PURE__ */ new Map()), h.set(this, /* @__PURE__ */ new Map());
649
- for (const i of t)
650
- this.define(i);
651
- }
652
- define(t, i = !1) {
653
- for (let [n, o] of Object.entries(t)) {
654
- n = n.toLowerCase(), o = o.map((s) => s.toLowerCase()), g(this, h, "f").has(n) || g(this, h, "f").set(n, /* @__PURE__ */ new Set());
655
- const p = g(this, h, "f").get(n);
656
- let a = !0;
657
- for (let s of o) {
658
- const l = s.startsWith("*");
659
- if (s = l ? s.slice(1) : s, p == null || p.add(s), a && g(this, j, "f").set(n, s), a = !1, l)
660
- continue;
661
- const r = g(this, b, "f").get(s);
662
- if (r && r != n && !i)
663
- throw new Error(`"${n} -> ${s}" conflicts with "${r} -> ${s}". Pass \`force=true\` to override this definition.`);
664
- g(this, b, "f").set(s, n);
665
- }
666
- }
667
- return this;
668
- }
669
- getType(t) {
670
- if (typeof t != "string")
671
- return null;
672
- const i = t.replace(/^.*[/\\]/, "").toLowerCase(), n = i.replace(/^.*\./, "").toLowerCase(), o = i.length < t.length;
673
- return !(n.length < i.length - 1) && o ? null : g(this, b, "f").get(n) ?? null;
674
- }
675
- getExtension(t) {
676
- var i;
677
- return typeof t != "string" ? null : (t = (i = t == null ? void 0 : t.split) == null ? void 0 : i.call(t, ";")[0], (t && g(this, j, "f").get(t.trim().toLowerCase())) ?? null);
678
- }
679
- getAllExtensions(t) {
680
- return typeof t != "string" ? null : g(this, h, "f").get(t.toLowerCase()) ?? null;
681
- }
682
- _freeze() {
683
- this.define = () => {
684
- throw new Error("define() not allowed for built-in Mime objects. See https://github.com/broofa/mime/blob/main/README.md#custom-mime-instances");
685
- }, Object.freeze(this);
686
- for (const t of g(this, h, "f").values())
687
- Object.freeze(t);
688
- return this;
689
- }
690
- _getTestState() {
691
- return {
692
- types: g(this, b, "f"),
693
- extensions: g(this, j, "f")
694
- };
695
- }
696
- }
697
- b = /* @__PURE__ */ new WeakMap(), j = /* @__PURE__ */ new WeakMap(), h = /* @__PURE__ */ new WeakMap();
698
- const ie = new ee(gt)._freeze();
699
- function ne(e) {
700
- const t = [], i = Object.keys(e);
701
- for (const n of i) {
702
- const o = e[n].sort((p, a) => p.index - a.index);
703
- for (let p = 0; p < o.length; p++)
704
- o[p].index !== p && t.push({
705
- message: `Invalid operation index ${o[p].index} at position ${p}`,
706
- details: {
707
- position: p,
708
- operation: o[p],
709
- scope: o[p].scope
710
- }
711
- });
712
- }
713
- return t;
714
- }
715
- const ht = async (e) => {
716
- const t = new Z(), { name: i, revision: n, documentType: o, created: p, lastModified: a } = e, s = {
717
- name: i,
718
- revision: n,
719
- documentType: o,
720
- created: p,
721
- lastModified: a
722
- };
723
- return t.file("header.json", JSON.stringify(s, null, 2)), t.file(
724
- "state.json",
725
- JSON.stringify(e.initialState || {}, null, 2)
726
- ), t.file("operations.json", JSON.stringify(e.operations, null, 2)), Object.keys(e.attachments).forEach((r) => {
727
- const { data: x, ...d } = e.attachments[r];
728
- t.file(r, x, {
729
- base64: !0,
730
- createFolders: !0,
731
- comment: JSON.stringify(d)
732
- });
733
- }), t;
734
- }, ae = async (e, t, i, n) => {
735
- const p = await (await ht(e)).generateAsync({
736
- type: "uint8array",
737
- streamFiles: !0
738
- }), a = n ?? e.name, s = `.${i}.zip`;
739
- return Bt(
740
- t,
741
- a.endsWith(s) ? a : `${a}${s}`,
742
- p
743
- );
744
- }, je = async (e, t) => {
745
- const n = await (await ht(e)).generateAsync({ type: "blob" }), o = await t.createWritable();
746
- await o.write(n), await o.close();
747
- }, B = async (e, t) => {
748
- const i = rt(e);
749
- return oe(i, t);
750
- }, oe = async (e, t) => {
751
- const i = new Z();
752
- return await i.loadAsync(e), se(i, t);
753
- };
754
- async function se(e, t) {
755
- const i = e.file("state.json");
756
- if (!i)
757
- throw new Error("Initial state not found");
758
- const n = await i.async("string"), o = JSON.parse(n), p = e.file("header.json");
759
- let a;
760
- p && (a = JSON.parse(await p.async("string")));
761
- const s = e.file("operations.json");
762
- if (!s)
763
- throw new Error("Operations history not found");
764
- const l = JSON.parse(
765
- await s.async("string")
766
- ), r = ne(l);
767
- if (r.length) {
768
- const d = r.map((m) => m.message);
769
- throw new Error(d.join(`
770
- `));
771
- }
772
- let x = mt(
773
- o,
774
- l,
775
- t,
776
- void 0,
777
- a
778
- );
779
- return a && (x = {
780
- ...x,
781
- ...a
782
- }), x;
783
- }
784
- function bt(e) {
785
- const t = e.replace(/^.*\./, "") || void 0, i = e.replace(/^.*[/\\]/, "") || void 0;
786
- return { extension: t, fileName: i };
787
- }
788
- async function ye(e) {
789
- const { buffer: t, mimeType: i = "application/octet-stream" } = await Zt(e), n = bt(e), o = t.toString("base64");
790
- return {
791
- data: o,
792
- hash: T(o),
793
- mimeType: i,
794
- ...n
795
- };
796
- }
797
- async function Oe(e) {
798
- const t = await Ht(e), i = ie.getType(e) || "application/octet-stream", n = bt(e), o = t.toString("base64");
799
- return { data: o, hash: T(o), mimeType: i, ...n };
800
- }
801
- class ke {
802
- /**
803
- * Constructs a BaseDocument instance with an initial state.
804
- * @param reducer - The reducer function that updates the state.
805
- * @param document - The initial state of the document.
806
- */
807
- constructor(t, i, n) {
808
- E(this, "_document");
809
- E(this, "_reducer");
810
- E(this, "_signalDispatch");
811
- this._reducer = t, this._document = i, this._signalDispatch = n;
812
- }
813
- /**
814
- * Dispatches an action to update the state of the document.
815
- * @param action - The action to dispatch.
816
- * @returns The Document instance.
817
- */
818
- dispatch(t, i) {
819
- return this._document = this._reducer(
820
- this._document,
821
- t,
822
- this._signalDispatch,
823
- i
824
- ), this;
825
- }
826
- /**
827
- * Saves the state of the document to a file.
828
- * @param path - The file path where the state should be saved.
829
- * @param extension - The file extension to use when saving the state.
830
- * @returns The file path where the state was saved.
831
- */
832
- saveToFile(t, i, n) {
833
- return ae(this._document, t, i, n);
834
- }
835
- /**
836
- * Loads the state of the document from a file.
837
- * @param path - The file path where the state is stored.
838
- */
839
- async loadFromFile(t) {
840
- this._document = await B(t, this._reducer);
841
- }
842
- /**
843
- * Loads the state of the document from a file and returns it.
844
- * @param path - The file path where the state is stored.
845
- * @param reducer - The reducer function that updates the state.
846
- * @returns The state of the document.
847
- */
848
- static async stateFromFile(t, i) {
849
- return await B(t, i);
850
- }
851
- /**
852
- * Gets the current state of the document.
853
- */
854
- get state() {
855
- return D(this._document.state);
856
- }
857
- /**
858
- * Gets the list of operations performed on the document.
859
- */
860
- get operations() {
861
- return D(this._document.operations);
862
- }
863
- /**
864
- * Gets the name of the document.
865
- */
866
- get name() {
867
- return this._document.name;
868
- }
869
- /**
870
- * Gets the type of document.
871
- */
872
- get documentType() {
873
- return this._document.documentType;
874
- }
875
- /**
876
- * Gets the timestamp of the date the document was created.
877
- */
878
- get created() {
879
- return this._document.created;
880
- }
881
- /**
882
- * Gets the timestamp of the date the document was last modified.
883
- */
884
- get lastModified() {
885
- return this._document.lastModified;
886
- }
887
- /**
888
- * Gets the global revision number of the document.
889
- */
890
- get revision() {
891
- return this._document.revision.global;
892
- }
893
- getRevision(t) {
894
- return this._document.revision[t];
895
- }
896
- /**
897
- * Gets the initial state of the document.
898
- */
899
- get initialState() {
900
- return D(this._document.initialState);
901
- }
902
- /**
903
- * Returns the current document as an object
904
- */
905
- toDocument() {
906
- return D(this._document);
907
- }
908
- /**
909
- * Gets the attachment associated with the given key.
910
- * @param attachment - The key of the attachment to retrieve.
911
- */
912
- getAttachment(t) {
913
- return this._document.attachments[t];
914
- }
915
- /**
916
- * Sets the name of the document.
917
- * @param name - The new name of the document.
918
- */
919
- setName(t) {
920
- return this.dispatch(dt(t)), this;
921
- }
922
- /**
923
- * Reverts a number of actions from the document.
924
- * @param count - The number of actions to revert.
925
- */
926
- undo(t) {
927
- return this.dispatch(ut(t)), this;
928
- }
929
- /**
930
- * Reapplies a number of actions to the document.
931
- * @param count - The number of actions to reapply.
932
- */
933
- redo(t) {
934
- return this.dispatch(ft(t)), this;
935
- }
936
- /**
937
- * Removes a range of operations from the document.
938
- * @param start - The starting index of the range to remove.
939
- * @param end - The ending index of the range to remove.
940
- */
941
- prune(t, i) {
942
- return this.dispatch(xt(t, i)), this;
943
- }
944
- /**
945
- * Loads a document state and a set of operations.
946
- * @param state - The state to load.
947
- * @param operations - The operations to apply to the document.
948
- */
949
- loadState(t, i) {
950
- return this.dispatch($(t, i)), this;
951
- }
952
- }
953
- function Se(e, t) {
954
- t.forEach((i) => {
955
- Object.getOwnPropertyNames(i.prototype).forEach((n) => {
956
- Object.defineProperty(
957
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
958
- e.prototype,
959
- n,
960
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
961
- Object.getOwnPropertyDescriptor(i.prototype, n) || /* @__PURE__ */ Object.create(null)
962
- );
963
- });
964
- });
965
- }
966
- export {
967
- ne as A,
968
- ke as B,
969
- ct as C,
970
- Wt as D,
971
- ge as E,
972
- Gt as a,
973
- Qt as b,
974
- Vt as c,
975
- je as d,
976
- oe as e,
977
- w as f,
978
- Se as g,
979
- ve as h,
980
- W as i,
981
- Yt as j,
982
- ht as k,
983
- B as l,
984
- Oe as m,
985
- ye as n,
986
- lt as o,
987
- he as p,
988
- Kt as q,
989
- we as r,
990
- ae as s,
991
- J as t,
992
- Xt as u,
993
- D as v,
994
- mt as w,
995
- I as x,
996
- te as y,
997
- be as z
998
- };