document-model 1.0.30 → 1.0.32

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 (34) hide show
  1. package/dist/browser/document-model.cjs +1 -1
  2. package/dist/browser/document-model.js +2 -2
  3. package/dist/browser/document.cjs +1 -1
  4. package/dist/browser/document.js +2 -2
  5. package/dist/browser/index.cjs +1 -1
  6. package/dist/browser/index.js +3 -3
  7. package/dist/browser/internal/{index-B-7drCvN.js → index-B7qIPXoz.js} +1 -1
  8. package/dist/browser/internal/{index-BFLtpklA.js → index-BFOiHt6I.js} +1 -1
  9. package/dist/{node/internal/index-BevT9mtU.js → browser/internal/index-BVR8cGlp.js} +1 -1
  10. package/dist/browser/internal/index-DtMGoFXU.js +40 -0
  11. package/dist/browser/internal/{object-DCxjKS4C.js → object-Diya-yJS.js} +297 -274
  12. package/dist/browser/internal/{object-g08kById.js → object-O_qdzVL-.js} +3 -2
  13. package/dist/browser/src/document/types.d.ts +7 -1
  14. package/dist/browser/src/document/utils/index.d.ts +1 -0
  15. package/dist/browser/src/document/utils/validation.d.ts +2 -0
  16. package/dist/node/document-model.cjs +1 -1
  17. package/dist/node/document-model.js +2 -2
  18. package/dist/node/document.cjs +1 -1
  19. package/dist/node/document.js +3 -3
  20. package/dist/node/index.cjs +1 -1
  21. package/dist/node/index.js +3 -3
  22. package/dist/{browser/internal/index-_gFM9c3z.js → node/internal/index-Bxw-tgFs.js} +1 -1
  23. package/dist/node/internal/{index-CbWnG-mj.js → index-C-NbJIDm.js} +1 -1
  24. package/dist/node/internal/{index-BNOB79wS.js → index-CsNA2GBY.js} +1 -1
  25. package/dist/node/internal/index-Ly6V0vGQ.js +40 -0
  26. package/dist/node/internal/object-DyU92wWO.js +2 -0
  27. package/dist/node/internal/{object-l76vs_od.js → object-usT57J9v.js} +289 -266
  28. package/dist/node/src/document/types.d.ts +7 -1
  29. package/dist/node/src/document/utils/index.d.ts +1 -0
  30. package/dist/node/src/document/utils/validation.d.ts +2 -0
  31. package/package.json +1 -1
  32. package/dist/browser/internal/index-FwxURTAn.js +0 -39
  33. package/dist/node/internal/index-JCxY4diP.js +0 -39
  34. package/dist/node/internal/object-DULiHJNK.js +0 -1
@@ -3,24 +3,24 @@ var wt = (e, t, i) => t in e ? bt(e, t, { enumerable: !0, configurable: !0, writ
3
3
  var E = (e, t, i) => (wt(e, typeof t != "symbol" ? t + "" : t, i), i);
4
4
  import { produce as k, castDraft as A, castImmutable as vt, freeze as yt } from "immer";
5
5
  import jt from "json-stringify-deterministic";
6
- import { z as p } from "zod";
6
+ import { z as c } from "zod";
7
7
  import Ot from "crypto";
8
8
  import z from "fs";
9
9
  import kt from "https";
10
10
  import { join as St } from "path";
11
11
  import B from "jszip";
12
- const Z = (e) => e != null, _t = p.any().refine((e) => Z(e)), H = p.enum(["LOAD_STATE"]), K = p.enum(["PRUNE"]), V = p.enum(["REDO"]), G = p.enum(["SET_NAME"]), Q = p.enum(["UNDO"]);
12
+ const Z = (e) => e != null, _t = c.any().refine((e) => Z(e)), H = c.enum(["LOAD_STATE"]), K = c.enum(["PRUNE"]), V = c.enum(["REDO"]), G = c.enum(["SET_NAME"]), Q = c.enum(["UNDO"]);
13
13
  function Et() {
14
- return p.object({
15
- __typename: p.literal("Action").optional(),
16
- type: p.string()
14
+ return c.object({
15
+ __typename: c.literal("Action").optional(),
16
+ type: c.string()
17
17
  });
18
18
  }
19
19
  function S() {
20
- return p.literal("global").or(p.literal("local"));
20
+ return c.literal("global").or(c.literal("local"));
21
21
  }
22
22
  function X() {
23
- return p.union([
23
+ return c.union([
24
24
  Y(),
25
25
  et(),
26
26
  it(),
@@ -29,90 +29,90 @@ function X() {
29
29
  ]);
30
30
  }
31
31
  function Dt() {
32
- return p.object({
33
- __typename: p.literal("DocumentFile").optional(),
34
- data: p.string(),
35
- extension: p.string().nullable(),
36
- fileName: p.string().nullable(),
37
- mimeType: p.string()
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
38
  });
39
39
  }
40
40
  function Y() {
41
- return p.object({
42
- input: p.lazy(() => P()),
41
+ return c.object({
42
+ input: c.lazy(() => P()),
43
43
  type: H,
44
44
  scope: S()
45
45
  });
46
46
  }
47
47
  function P() {
48
- return p.object({
49
- operations: p.number(),
50
- state: p.lazy(() => tt())
48
+ return c.object({
49
+ operations: c.number(),
50
+ state: c.lazy(() => tt())
51
51
  });
52
52
  }
53
53
  function tt() {
54
- return p.object({
55
- data: p.unknown().nullish(),
56
- name: p.string()
54
+ return c.object({
55
+ data: c.unknown().nullish(),
56
+ name: c.string()
57
57
  });
58
58
  }
59
59
  function Nt() {
60
- return p.object({
61
- __typename: p.literal("Operation").optional(),
62
- hash: p.string(),
63
- index: p.number(),
64
- timestamp: p.string().datetime(),
65
- type: p.string()
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
66
  });
67
67
  }
68
68
  function et() {
69
- return p.object({
70
- input: p.lazy(() => F()),
69
+ return c.object({
70
+ input: c.lazy(() => I()),
71
71
  type: K,
72
72
  scope: S()
73
73
  });
74
74
  }
75
- function F() {
76
- return p.object({
77
- end: p.number().nullish(),
78
- start: p.number().nullish()
75
+ function I() {
76
+ return c.object({
77
+ end: c.number().nullish(),
78
+ start: c.number().nullish()
79
79
  });
80
80
  }
81
- const I = p.number;
81
+ const F = c.number;
82
82
  function it() {
83
- return p.object({
84
- input: I(),
83
+ return c.object({
84
+ input: F(),
85
85
  type: V,
86
86
  scope: S()
87
87
  });
88
88
  }
89
- const R = p.string;
89
+ const R = c.string;
90
90
  function at() {
91
- return p.object({
91
+ return c.object({
92
92
  input: R(),
93
93
  type: G,
94
- scope: p.literal("global")
94
+ scope: c.literal("global")
95
95
  });
96
96
  }
97
97
  function Tt() {
98
- return p.object({
99
- __typename: p.literal("SetNameOperation").optional(),
100
- hash: p.string(),
101
- index: p.number(),
102
- input: p.string(),
103
- timestamp: p.string().datetime(),
104
- type: p.string()
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
105
  });
106
106
  }
107
- const q = p.number;
107
+ const q = c.number;
108
108
  function nt() {
109
- return p.object({
109
+ return c.object({
110
110
  input: q(),
111
111
  type: Q,
112
112
  scope: S()
113
113
  });
114
114
  }
115
- const de = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
115
+ const fe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
116
116
  __proto__: null,
117
117
  ActionSchema: Et,
118
118
  BaseActionSchema: X,
@@ -123,10 +123,10 @@ const de = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
123
123
  Load_StateSchema: H,
124
124
  OperationSchema: Nt,
125
125
  OperationScopeSchema: S,
126
- PruneActionInputSchema: F,
126
+ PruneActionInputSchema: I,
127
127
  PruneActionSchema: et,
128
128
  PruneSchema: K,
129
- RedoActionInputSchema: I,
129
+ RedoActionInputSchema: F,
130
130
  RedoActionSchema: it,
131
131
  RedoSchema: V,
132
132
  SetNameActionInputSchema: R,
@@ -146,93 +146,93 @@ function zt(e, t, i) {
146
146
  const a = {
147
147
  skip: i,
148
148
  document: e
149
- }, { scope: o } = t;
150
- return !o || t.skip === void 0 ? a : k(a, (c) => {
151
- const [n] = c.document.operations[o].slice(-1);
152
- t.skip && t.skip > 0 && (c.skip = t.skip), n.type === "NOOP" && t.index === n.index && c.skip > n.skip && c.document.operations[o].pop();
149
+ }, { scope: n } = t;
150
+ return !n || t.skip === void 0 ? a : k(a, (s) => {
151
+ const [o] = s.document.operations[n].slice(-1);
152
+ t.skip && t.skip > 0 && (s.skip = t.skip), o.type === "NOOP" && t.index === o.index && s.skip > o.skip && s.document.operations[n].pop();
153
153
  });
154
154
  }
155
155
  function Mt(e, t, i) {
156
- const { scope: a, input: o } = t;
156
+ const { scope: a, input: n } = t;
157
157
  return k({
158
158
  document: e,
159
159
  action: t,
160
160
  skip: i
161
- }, (n) => {
162
- if (n.document.operations[a].length < 1)
161
+ }, (o) => {
162
+ if (o.document.operations[a].length < 1)
163
163
  throw new Error(
164
164
  `Cannot undo: no operations in history for scope "${a}"`
165
165
  );
166
- if (o < 1)
166
+ if (n < 1)
167
167
  throw new Error(
168
168
  "Invalid UNDO action: input value must be greater than 0"
169
169
  );
170
- if (n.skip > 0)
170
+ if (o.skip > 0)
171
171
  throw new Error(
172
172
  "Cannot undo: skip value from reducer cannot be used with UNDO action"
173
173
  );
174
- const [s] = n.document.operations[a].slice(-1), r = s.type === "NOOP" && s.skip > 0;
175
- if (n.skip += o, r && (n.skip += s.skip, n.document.operations[a].pop()), n.document.operations[a].length < n.skip)
174
+ const [p] = o.document.operations[a].slice(-1), r = p.type === "NOOP" && p.skip > 0;
175
+ if (o.skip += n, r && (o.skip += p.skip, o.document.operations[a].pop()), o.document.operations[a].length < o.skip)
176
176
  throw new Error(
177
177
  "Cannot undo: you can't undo more operations than the ones in the scope history"
178
178
  );
179
- const l = n.document.operations[a].length - 1;
180
- let x = o, m = r ? l - s.skip : l;
181
- for (; x > 0 && m >= 0; ) {
182
- const d = n.document.operations[a][m];
183
- d.type === "NOOP" && d.skip > 0 ? (m = m - (d.skip + 1), n.skip += d.skip + 1) : (n.document.clipboard.push({ ...d }), x--, m--);
179
+ const l = o.document.operations[a].length - 1;
180
+ let f = n, m = r ? l - p.skip : l;
181
+ for (; f > 0 && m >= 0; ) {
182
+ const u = o.document.operations[a][m];
183
+ u.type === "NOOP" && u.skip > 0 ? (m = m - (u.skip + 1), o.skip += u.skip + 1) : (o.document.clipboard.push({ ...u }), f--, m--);
184
184
  }
185
- n.action = U(a);
185
+ o.action = U(a);
186
186
  });
187
187
  }
188
188
  function Pt(e, t, i) {
189
- const { scope: a, input: o } = t;
189
+ const { scope: a, input: n } = t;
190
190
  return k({
191
191
  document: e,
192
192
  action: t,
193
193
  skip: i
194
- }, (n) => {
195
- if (n.skip > 0)
194
+ }, (o) => {
195
+ if (o.skip > 0)
196
196
  throw new Error(
197
197
  "Cannot redo: skip value from reducer cannot be used with REDO action"
198
198
  );
199
- if (o > 1)
199
+ if (n > 1)
200
200
  throw new Error(
201
201
  "Cannot redo: you can only redo one operation at a time"
202
202
  );
203
- if (o < 1)
203
+ if (n < 1)
204
204
  throw new Error("Invalid REDO action: invalid redo input value");
205
- if (n.document.clipboard.length < 1)
205
+ if (o.document.clipboard.length < 1)
206
206
  throw new Error("Cannot redo: no operations in the clipboard");
207
- const s = n.document.clipboard.findLastIndex(
207
+ const p = o.document.clipboard.findLastIndex(
208
208
  (l) => l.scope === a
209
209
  );
210
- if (s < 0)
210
+ if (p < 0)
211
211
  throw new Error(
212
212
  `Cannot redo: no operations in clipboard for scope "${a}"`
213
213
  );
214
- const r = n.document.clipboard.splice(s, 1)[0];
215
- n.action = A({
214
+ const r = o.document.clipboard.splice(p, 1)[0];
215
+ o.action = A({
216
216
  type: r.type,
217
217
  scope: r.scope,
218
218
  input: r.input
219
219
  });
220
220
  });
221
221
  }
222
- function Ft(e, t, i) {
223
- const { scope: a } = t, o = e.operations[a];
222
+ function It(e, t, i) {
223
+ const { scope: a } = t, n = e.operations[a];
224
224
  let {
225
- input: { start: c, end: n }
225
+ input: { start: s, end: o }
226
226
  } = t;
227
- c = c || 0, n = n || o.length;
228
- const s = o.slice(c, n), r = o.slice(0, c), l = o.slice(n), x = M(
227
+ s = s || 0, o = o || n.length;
228
+ const p = n.slice(s, o), r = n.slice(0, s), l = n.slice(o), f = M(
229
229
  e.initialState,
230
230
  {
231
231
  ...e.operations,
232
- [a]: r.concat(s)
232
+ [a]: r.concat(p)
233
233
  },
234
234
  i
235
- ), { name: m, state: d } = x, u = r.length, j = r.length ? r[r.length - 1].timestamp : l.length ? l[0].timestamp : (/* @__PURE__ */ new Date()).toISOString();
235
+ ), { name: m, state: u } = f, d = r.length, j = r.length ? r[r.length - 1].timestamp : l.length ? l[0].timestamp : (/* @__PURE__ */ new Date()).toISOString();
236
236
  return M(
237
237
  e.initialState,
238
238
  {
@@ -241,23 +241,23 @@ function Ft(e, t, i) {
241
241
  ...r,
242
242
  {
243
243
  ...L(
244
- { name: m, state: d },
245
- s.length
244
+ { name: m, state: u },
245
+ p.length
246
246
  ),
247
247
  timestamp: j,
248
- index: u,
249
- hash: lt({ state: d }, "global")
248
+ index: d,
249
+ hash: lt({ state: u }, "global")
250
250
  },
251
251
  ...l.map((h, T) => ({
252
252
  ...h,
253
- index: u + T + 1
253
+ index: d + T + 1
254
254
  }))
255
255
  ]
256
256
  },
257
257
  i
258
258
  );
259
259
  }
260
- function It(e, t) {
260
+ function Ft(e, t) {
261
261
  return {
262
262
  ...e,
263
263
  name: t.name,
@@ -282,34 +282,34 @@ function Lt(e, t) {
282
282
  function Ut(e, t, i = 0) {
283
283
  if ([w, v, _].includes(t.type))
284
284
  return e;
285
- const { scope: a } = t, o = e.operations[a].slice(
285
+ const { scope: a } = t, n = e.operations[a].slice(
286
286
  0,
287
287
  e.revision[a]
288
288
  );
289
- return o.push({
289
+ return n.push({
290
290
  ...t,
291
- index: o.length,
291
+ index: n.length,
292
292
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
293
293
  hash: "",
294
294
  scope: a,
295
295
  skip: i
296
296
  }), {
297
297
  ...e,
298
- operations: { ...e.operations, [a]: o }
298
+ operations: { ...e.operations, [a]: n }
299
299
  };
300
300
  }
301
- function Ct(e, t, i = 0) {
301
+ function $t(e, t, i = 0) {
302
302
  let a = Ut(e, t, i);
303
303
  return a = Lt(a, t), a;
304
304
  }
305
- function $t(e, t, i) {
305
+ function Ct(e, t, i) {
306
306
  switch (X().parse(t), t.type) {
307
307
  case ot:
308
308
  return At(e, t.input);
309
309
  case _:
310
- return Ft(e, t, i);
310
+ return It(e, t, i);
311
311
  case st:
312
- return It(e, t.input.state);
312
+ return Ft(e, t.input.state);
313
313
  default:
314
314
  return e;
315
315
  }
@@ -324,48 +324,48 @@ function Jt(e, t, i) {
324
324
  return { document: e, action: t, skip: i };
325
325
  }
326
326
  }
327
- function pt(e, t, i, a, o = {}) {
328
- const { skip: c, ignoreSkipOperations: n = !1 } = o;
329
- let s = { ...t }, r = c || 0, l = e, x = [...e.clipboard];
330
- if (Ht(s)) {
331
- const { document: m, skip: d } = zt(l, s, r);
332
- r = d, l = m;
327
+ function pt(e, t, i, a, n = {}) {
328
+ const { skip: s, ignoreSkipOperations: o = !1 } = n;
329
+ let p = { ...t }, r = s || 0, l = e, f = [...e.clipboard];
330
+ if (Ht(p)) {
331
+ const { document: m, skip: u } = zt(l, p, r);
332
+ r = u, l = m;
333
333
  }
334
- if ($(s)) {
334
+ if (C(p)) {
335
335
  const {
336
336
  skip: m,
337
- action: d,
338
- document: u
339
- } = Jt(e, s, r);
340
- s = d, r = m, l = u, x = [...l.clipboard];
337
+ action: u,
338
+ document: d
339
+ } = Jt(e, p, r);
340
+ p = u, r = m, l = d, f = [...l.clipboard];
341
341
  }
342
- return J(s) && (l = $t(l, s, i)), r > 0 && !n && (l = M(
342
+ return J(p) && (l = Ct(l, p, i)), r > 0 && !o && (l = M(
343
343
  l.initialState,
344
344
  l.operations,
345
345
  i,
346
346
  void 0,
347
347
  void 0,
348
348
  void 0,
349
- { [s.scope]: r }
350
- )), l = Ct(l, s, r), l = k(l, (m) => {
351
- const d = i(
349
+ { [p.scope]: r }
350
+ )), l = $t(l, p, r), l = k(l, (m) => {
351
+ const u = i(
352
352
  m.state,
353
- s,
353
+ p,
354
354
  a
355
- ), u = $(t) ? [...x] : [];
356
- if (d)
355
+ ), d = C(t) ? [...f] : [];
356
+ if (u)
357
357
  return A({
358
358
  ...l,
359
- clipboard: [...u],
360
- state: d
359
+ clipboard: [...d],
360
+ state: u
361
361
  });
362
- m.clipboard = A([...u]);
362
+ m.clipboard = A([...d]);
363
363
  }), k(l, (m) => {
364
- if ([w, v, _].includes(s.type))
364
+ if ([w, v, _].includes(p.type))
365
365
  return m;
366
- const d = s.scope || "global";
367
- m.operations[d][m.operations[d].length - 1].hash = lt(m, d), !J(s) && s.attachments && s.attachments.forEach((u) => {
368
- const { hash: j, ...h } = u;
366
+ const u = p.scope || "global";
367
+ m.operations[u][m.operations[u].length - 1].hash = lt(m, u), !J(p) && p.attachments && p.attachments.forEach((d) => {
368
+ const { hash: j, ...h } = d;
369
369
  m.attachments[j] = {
370
370
  ...h
371
371
  };
@@ -374,13 +374,13 @@ function pt(e, t, i, a, o = {}) {
374
374
  }
375
375
  function Wt(e, t, i) {
376
376
  const a = St(e, t);
377
- return z.mkdirSync(e, { recursive: !0 }), new Promise((o, c) => {
377
+ return z.mkdirSync(e, { recursive: !0 }), new Promise((n, s) => {
378
378
  try {
379
- z.writeFile(a, i, {}, (n) => {
380
- n ? c(n) : o(a);
379
+ z.writeFile(a, i, {}, (o) => {
380
+ o ? s(o) : n(a);
381
381
  });
382
- } catch (n) {
383
- c(n);
382
+ } catch (o) {
383
+ s(o);
384
384
  }
385
385
  });
386
386
  }
@@ -390,11 +390,11 @@ function ct(e) {
390
390
  function Bt(e) {
391
391
  return new Promise((t, i) => {
392
392
  kt.get(e, (a) => {
393
- const o = [], c = a.headers["content-type"];
394
- a.on("data", (n) => {
395
- o.push(n);
393
+ const n = [], s = a.headers["content-type"];
394
+ a.on("data", (o) => {
395
+ n.push(o);
396
396
  }), a.on("end", () => {
397
- t({ buffer: Buffer.concat(o), mimeType: c });
397
+ t({ buffer: Buffer.concat(n), mimeType: s });
398
398
  });
399
399
  }).on("error", (a) => {
400
400
  i(a);
@@ -405,28 +405,28 @@ const Zt = async (e) => ct(e), N = (e, t = "sha1") => Ot.createHash(t).update(e)
405
405
  function Ht(e) {
406
406
  return e.type === Rt && e.skip !== void 0 && e.skip > 0 && e.hash !== void 0;
407
407
  }
408
- function $(e) {
408
+ function C(e) {
409
409
  return [w, v].includes(e.type);
410
410
  }
411
411
  function J(e) {
412
412
  return [ot, w, v, _, st].includes(e.type);
413
413
  }
414
- function y(e, t, i, a, o = "global") {
414
+ function y(e, t, i, a, n = "global") {
415
415
  if (!e)
416
416
  throw new Error("Empty action type");
417
417
  if (typeof e != "string")
418
418
  throw new Error(`Invalid action type: ${e}`);
419
- const c = { type: e, input: t, scope: o };
420
- i && (c.attachments = i);
419
+ const s = { type: e, input: t, scope: n };
420
+ i && (s.attachments = i);
421
421
  try {
422
- a == null || a().parse(c.input);
423
- } catch (n) {
424
- throw new Error(`Invalid action input: ${n}`);
422
+ a == null || a().parse(s.input);
423
+ } catch (o) {
424
+ throw new Error(`Invalid action input: ${o}`);
425
425
  }
426
- return c;
426
+ return s;
427
427
  }
428
428
  function Kt(e, t = pt) {
429
- return (i, a, o, c) => t(i, a, e, o, c);
429
+ return (i, a, n, s) => t(i, a, e, n, s);
430
430
  }
431
431
  const Vt = (e, t) => ({
432
432
  name: "",
@@ -451,7 +451,7 @@ const Vt = (e, t) => ({
451
451
  operations: { global: [], local: [] },
452
452
  clipboard: []
453
453
  };
454
- }, lt = (e, t = "global") => N(jt(e.state[t])), fe = (e, t = 1e3) => {
454
+ }, lt = (e, t = "global") => N(jt(e.state[t])), xe = (e, t = 1e3) => {
455
455
  const i = Math.random() * t;
456
456
  return N(`${(e ?? /* @__PURE__ */ new Date()).toISOString()}${i}`);
457
457
  };
@@ -460,28 +460,28 @@ function D(e) {
460
460
  }
461
461
  function Qt(e, t) {
462
462
  const i = [...e];
463
- let a = t || 0, o = i.length > 0 ? i[i.length - 1].index : 0;
464
- const c = [];
465
- for (const n of i.reverse()) {
463
+ let a = t || 0, n = i.length > 0 ? i[i.length - 1].index : 0;
464
+ const s = [];
465
+ for (const o of i.reverse()) {
466
466
  if (a > 0) {
467
- const l = o - n.index;
467
+ const l = n - o.index;
468
468
  a -= l;
469
469
  }
470
470
  if (a < 0)
471
471
  throw new Error("Invalid operation index, missing operations");
472
- const s = {
472
+ const p = {
473
473
  ignore: a > 0,
474
- operation: n
475
- }, r = n.skip > 0 ? n.skip + 1 : 0;
474
+ operation: o
475
+ }, r = o.skip > 0 ? o.skip + 1 : 0;
476
476
  if (r > 0 && r > a) {
477
477
  const l = r - a;
478
478
  a = a + l;
479
479
  }
480
- o = n.index, c.push(s);
480
+ n = o.index, s.push(p);
481
481
  }
482
- return c.reverse();
482
+ return s.reverse();
483
483
  }
484
- function xe(e) {
484
+ function ge(e) {
485
485
  return Object.values(e).flatMap((t) => t).sort(
486
486
  (t, i) => new Date(t.timestamp).getTime() - new Date(i.timestamp).getTime()
487
487
  );
@@ -491,58 +491,58 @@ function Xt(e) {
491
491
  (t, i) => new Date(t.operation.timestamp).getTime() - new Date(i.operation.timestamp).getTime()
492
492
  );
493
493
  }
494
- function M(e, t, i, a, o, c = pt, n = {}) {
495
- const s = Kt(i, c);
494
+ function M(e, t, i, a, n, s = pt, o = {}) {
495
+ const p = Kt(i, s);
496
496
  return rt(
497
497
  e,
498
498
  t,
499
- s,
499
+ p,
500
500
  a,
501
- o,
502
- n
501
+ n,
502
+ o
503
503
  );
504
504
  }
505
- function rt(e, t, i, a, o, c = {}) {
506
- const n = Gt(e), s = Object.keys(t).reduce((m, d) => {
507
- const u = d;
505
+ function rt(e, t, i, a, n, s = {}) {
506
+ const o = Gt(e), p = Object.keys(t).reduce((m, u) => {
507
+ const d = u;
508
508
  return {
509
509
  ...m,
510
- [u]: t[u].slice(0, o == null ? void 0 : o.revision[u])
510
+ [d]: t[d].slice(0, n == null ? void 0 : n.revision[d])
511
511
  };
512
- }, {}), r = Object.keys(s).reduce(
513
- (m, d) => {
514
- const u = d;
512
+ }, {}), r = Object.keys(p).reduce(
513
+ (m, u) => {
514
+ const d = u;
515
515
  return {
516
516
  ...m,
517
- [u]: Qt(
518
- s[u],
519
- c[u]
517
+ [d]: Qt(
518
+ p[d],
519
+ s[d]
520
520
  )
521
521
  };
522
522
  },
523
523
  {}
524
524
  ), l = Xt(r).reduce(
525
- (m, { ignore: d, operation: u }) => d ? i(m, U(u.scope), a, {
526
- skip: u.skip,
525
+ (m, { ignore: u, operation: d }) => u ? i(m, U(d.scope), a, {
526
+ skip: d.skip,
527
527
  ignoreSkipOperations: !0
528
- }) : i(m, u, a, {
529
- skip: u.skip,
528
+ }) : i(m, d, a, {
529
+ skip: d.skip,
530
530
  ignoreSkipOperations: !0
531
531
  }),
532
- n
533
- ), x = Object.keys(
532
+ o
533
+ ), f = Object.keys(
534
534
  l.operations
535
535
  ).reduce(
536
- (m, d) => {
537
- const u = d, j = o && o.revision[u] < t[u].length ? t[u].slice(o.revision[u]) : [];
536
+ (m, u) => {
537
+ const d = u, j = n && n.revision[d] < t[d].length ? t[d].slice(n.revision[d]) : [];
538
538
  return {
539
539
  ...m,
540
- [u]: [
541
- ...l.operations[u].map((h, T) => {
542
- var C;
540
+ [d]: [
541
+ ...l.operations[d].map((h, T) => {
542
+ var $;
543
543
  return {
544
544
  ...h,
545
- timestamp: ((C = t[u][T]) == null ? void 0 : C.timestamp) ?? h.timestamp
545
+ timestamp: (($ = t[d][T]) == null ? void 0 : $.timestamp) ?? h.timestamp
546
546
  };
547
547
  }),
548
548
  ...j
@@ -551,7 +551,7 @@ function rt(e, t, i, a, o, c = {}) {
551
551
  },
552
552
  { global: [], local: [] }
553
553
  );
554
- return { ...l, operations: x };
554
+ return { ...l, operations: f };
555
555
  }
556
556
  const mt = (e) => y(
557
557
  "SET_NAME",
@@ -559,40 +559,40 @@ const mt = (e) => y(
559
559
  void 0,
560
560
  R,
561
561
  void 0
562
- ), ut = (e = 1, t = "global") => y(
562
+ ), dt = (e = 1, t = "global") => y(
563
563
  "UNDO",
564
564
  e,
565
565
  void 0,
566
566
  q,
567
567
  t
568
- ), dt = (e = 1, t = "global") => y(
568
+ ), ut = (e = 1, t = "global") => y(
569
569
  "REDO",
570
570
  e,
571
571
  void 0,
572
- I,
572
+ F,
573
573
  t
574
574
  ), ft = (e, t, i = "global") => y(
575
575
  "PRUNE",
576
576
  { start: e, end: t },
577
577
  void 0,
578
- F,
578
+ I,
579
579
  i
580
580
  ), L = (e, t) => y(
581
581
  "LOAD_STATE",
582
582
  { state: e, operations: t },
583
583
  void 0,
584
584
  P
585
- ), U = (e = "global") => y("NOOP", {}, void 0, void 0, e), ge = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
585
+ ), U = (e = "global") => y("NOOP", {}, void 0, void 0, e), he = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
586
586
  __proto__: null,
587
587
  loadState: L,
588
588
  noop: U,
589
589
  prune: ft,
590
- redo: dt,
590
+ redo: ut,
591
591
  setName: mt,
592
- undo: ut
592
+ undo: dt
593
593
  }, Symbol.toStringTag, { value: "Module" })), xt = { "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"] };
594
594
  Object.freeze(xt);
595
- var f = function(e, t, i, a) {
595
+ var x = function(e, t, i, a) {
596
596
  if (i === "a" && !a)
597
597
  throw new TypeError("Private accessor was defined without a getter");
598
598
  if (typeof t == "function" ? e !== t || !a : !t.has(e))
@@ -606,18 +606,18 @@ class Yt {
606
606
  this.define(i);
607
607
  }
608
608
  define(t, i = !1) {
609
- for (let [a, o] of Object.entries(t)) {
610
- a = a.toLowerCase(), o = o.map((s) => s.toLowerCase()), f(this, g, "f").has(a) || f(this, g, "f").set(a, /* @__PURE__ */ new Set());
611
- const c = f(this, g, "f").get(a);
612
- let n = !0;
613
- for (let s of o) {
614
- const r = s.startsWith("*");
615
- if (s = r ? s.slice(1) : s, c == null || c.add(s), n && f(this, O, "f").set(a, s), n = !1, r)
609
+ for (let [a, n] of Object.entries(t)) {
610
+ a = a.toLowerCase(), n = n.map((p) => p.toLowerCase()), x(this, g, "f").has(a) || x(this, g, "f").set(a, /* @__PURE__ */ new Set());
611
+ const s = x(this, g, "f").get(a);
612
+ let o = !0;
613
+ for (let p of n) {
614
+ const r = p.startsWith("*");
615
+ if (p = r ? p.slice(1) : p, s == null || s.add(p), o && x(this, O, "f").set(a, p), o = !1, r)
616
616
  continue;
617
- const l = f(this, b, "f").get(s);
617
+ const l = x(this, b, "f").get(p);
618
618
  if (l && l != a && !i)
619
- throw new Error(`"${a} -> ${s}" conflicts with "${l} -> ${s}". Pass \`force=true\` to override this definition.`);
620
- f(this, b, "f").set(s, a);
619
+ throw new Error(`"${a} -> ${p}" conflicts with "${l} -> ${p}". Pass \`force=true\` to override this definition.`);
620
+ x(this, b, "f").set(p, a);
621
621
  }
622
622
  }
623
623
  return this;
@@ -625,114 +625,136 @@ class Yt {
625
625
  getType(t) {
626
626
  if (typeof t != "string")
627
627
  return null;
628
- const i = t.replace(/^.*[/\\]/, "").toLowerCase(), a = i.replace(/^.*\./, "").toLowerCase(), o = i.length < t.length;
629
- return !(a.length < i.length - 1) && o ? null : f(this, b, "f").get(a) ?? null;
628
+ const i = t.replace(/^.*[/\\]/, "").toLowerCase(), a = i.replace(/^.*\./, "").toLowerCase(), n = i.length < t.length;
629
+ return !(a.length < i.length - 1) && n ? null : x(this, b, "f").get(a) ?? null;
630
630
  }
631
631
  getExtension(t) {
632
632
  var i;
633
- return typeof t != "string" ? null : (t = (i = t == null ? void 0 : t.split) == null ? void 0 : i.call(t, ";")[0], (t && f(this, O, "f").get(t.trim().toLowerCase())) ?? null);
633
+ return typeof t != "string" ? null : (t = (i = t == null ? void 0 : t.split) == null ? void 0 : i.call(t, ";")[0], (t && x(this, O, "f").get(t.trim().toLowerCase())) ?? null);
634
634
  }
635
635
  getAllExtensions(t) {
636
- return typeof t != "string" ? null : f(this, g, "f").get(t.toLowerCase()) ?? null;
636
+ return typeof t != "string" ? null : x(this, g, "f").get(t.toLowerCase()) ?? null;
637
637
  }
638
638
  _freeze() {
639
639
  this.define = () => {
640
640
  throw new Error("define() not allowed for built-in Mime objects. See https://github.com/broofa/mime/blob/main/README.md#custom-mime-instances");
641
641
  }, Object.freeze(this);
642
- for (const t of f(this, g, "f").values())
642
+ for (const t of x(this, g, "f").values())
643
643
  Object.freeze(t);
644
644
  return this;
645
645
  }
646
646
  _getTestState() {
647
647
  return {
648
- types: f(this, b, "f"),
649
- extensions: f(this, O, "f")
648
+ types: x(this, b, "f"),
649
+ extensions: x(this, O, "f")
650
650
  };
651
651
  }
652
652
  }
653
653
  b = /* @__PURE__ */ new WeakMap(), O = /* @__PURE__ */ new WeakMap(), g = /* @__PURE__ */ new WeakMap();
654
- const te = new Yt(xt)._freeze(), gt = async (e) => {
655
- const t = new B(), { name: i, revision: a, documentType: o, created: c, lastModified: n } = e, s = {
654
+ const te = new Yt(xt)._freeze();
655
+ function ee(e) {
656
+ const t = [], i = Object.keys(e);
657
+ for (const a of i) {
658
+ const n = e[a].sort((s, o) => s.index - o.index);
659
+ for (let s = 0; s < n.length; s++)
660
+ n[s].index !== s && t.push({
661
+ message: `Invalid operation index ${n[s].index} at position ${s}`,
662
+ details: {
663
+ position: s,
664
+ operation: n[s],
665
+ scope: n[s].scope
666
+ }
667
+ });
668
+ }
669
+ return t;
670
+ }
671
+ const gt = async (e) => {
672
+ const t = new B(), { name: i, revision: a, documentType: n, created: s, lastModified: o } = e, p = {
656
673
  name: i,
657
674
  revision: a,
658
- documentType: o,
659
- created: c,
660
- lastModified: n
675
+ documentType: n,
676
+ created: s,
677
+ lastModified: o
661
678
  };
662
- return t.file("header.json", JSON.stringify(s, null, 2)), t.file(
679
+ return t.file("header.json", JSON.stringify(p, null, 2)), t.file(
663
680
  "state.json",
664
681
  JSON.stringify(e.initialState || {}, null, 2)
665
682
  ), t.file("operations.json", JSON.stringify(e.operations, null, 2)), Object.keys(e.attachments).forEach((l) => {
666
- const { data: x, ...m } = e.attachments[l];
667
- t.file(l, x, {
683
+ const { data: f, ...m } = e.attachments[l];
684
+ t.file(l, f, {
668
685
  base64: !0,
669
686
  createFolders: !0,
670
687
  comment: JSON.stringify(m)
671
688
  });
672
689
  }), t;
673
- }, ee = async (e, t, i, a) => {
674
- const c = await (await gt(e)).generateAsync({
690
+ }, ie = async (e, t, i, a) => {
691
+ const s = await (await gt(e)).generateAsync({
675
692
  type: "uint8array",
676
693
  streamFiles: !0
677
- }), n = a ?? e.name, s = `.${i}.zip`;
694
+ }), o = a ?? e.name, p = `.${i}.zip`;
678
695
  return Wt(
679
696
  t,
680
- n.endsWith(s) ? n : `${n}${s}`,
681
- c
697
+ o.endsWith(p) ? o : `${o}${p}`,
698
+ s
682
699
  );
683
- }, he = async (e, t) => {
684
- const a = await (await gt(e)).generateAsync({ type: "blob" }), o = await t.createWritable();
685
- await o.write(a), await o.close();
700
+ }, be = async (e, t) => {
701
+ const a = await (await gt(e)).generateAsync({ type: "blob" }), n = await t.createWritable();
702
+ await n.write(a), await n.close();
686
703
  }, W = async (e, t) => {
687
704
  const i = ct(e);
688
- return ie(i, t);
689
- }, ie = async (e, t) => {
705
+ return ae(i, t);
706
+ }, ae = async (e, t) => {
690
707
  const i = new B();
691
- return await i.loadAsync(e), ae(i, t);
708
+ return await i.loadAsync(e), ne(i, t);
692
709
  };
693
- async function ae(e, t) {
710
+ async function ne(e, t) {
694
711
  const i = e.file("state.json");
695
712
  if (!i)
696
713
  throw new Error("Initial state not found");
697
- const a = await i.async("string"), o = JSON.parse(a), c = e.file("header.json");
698
- let n;
699
- c && (n = JSON.parse(await c.async("string")));
700
- const s = e.file("operations.json");
701
- if (!s)
714
+ const a = await i.async("string"), n = JSON.parse(a), s = e.file("header.json");
715
+ let o;
716
+ s && (o = JSON.parse(await s.async("string")));
717
+ const p = e.file("operations.json");
718
+ if (!p)
702
719
  throw new Error("Operations history not found");
703
720
  const r = JSON.parse(
704
- await s.async("string")
705
- );
706
- let l = rt(
707
- o,
721
+ await p.async("string")
722
+ ), l = ee(r);
723
+ if (l.length) {
724
+ const m = l.map((u) => u.message);
725
+ throw new Error(m.join(`
726
+ `));
727
+ }
728
+ let f = rt(
729
+ n,
708
730
  r,
709
731
  t,
710
732
  void 0,
711
- n
733
+ o
712
734
  );
713
- return n && (l = {
714
- ...l,
715
- ...n
716
- }), l;
735
+ return o && (f = {
736
+ ...f,
737
+ ...o
738
+ }), f;
717
739
  }
718
740
  function ht(e) {
719
741
  const t = e.replace(/^.*\./, "") || void 0, i = e.replace(/^.*[/\\]/, "") || void 0;
720
742
  return { extension: t, fileName: i };
721
743
  }
722
- async function be(e) {
723
- const { buffer: t, mimeType: i = "application/octet-stream" } = await Bt(e), a = ht(e), o = t.toString("base64");
744
+ async function we(e) {
745
+ const { buffer: t, mimeType: i = "application/octet-stream" } = await Bt(e), a = ht(e), n = t.toString("base64");
724
746
  return {
725
- data: o,
726
- hash: N(o),
747
+ data: n,
748
+ hash: N(n),
727
749
  mimeType: i,
728
750
  ...a
729
751
  };
730
752
  }
731
- async function we(e) {
732
- const t = await Zt(e), i = te.getType(e) || "application/octet-stream", a = ht(e), o = t.toString("base64");
733
- return { data: o, hash: N(o), mimeType: i, ...a };
753
+ async function ve(e) {
754
+ const t = await Zt(e), i = te.getType(e) || "application/octet-stream", a = ht(e), n = t.toString("base64");
755
+ return { data: n, hash: N(n), mimeType: i, ...a };
734
756
  }
735
- class ve {
757
+ class ye {
736
758
  /**
737
759
  * Constructs a BaseDocument instance with an initial state.
738
760
  * @param reducer - The reducer function that updates the state.
@@ -764,7 +786,7 @@ class ve {
764
786
  * @returns The file path where the state was saved.
765
787
  */
766
788
  saveToFile(t, i, a) {
767
- return ee(this._document, t, i, a);
789
+ return ie(this._document, t, i, a);
768
790
  }
769
791
  /**
770
792
  * Loads the state of the document from a file.
@@ -858,14 +880,14 @@ class ve {
858
880
  * @param count - The number of actions to revert.
859
881
  */
860
882
  undo(t) {
861
- return this.dispatch(ut(t)), this;
883
+ return this.dispatch(dt(t)), this;
862
884
  }
863
885
  /**
864
886
  * Reapplies a number of actions to the document.
865
887
  * @param count - The number of actions to reapply.
866
888
  */
867
889
  redo(t) {
868
- return this.dispatch(dt(t)), this;
890
+ return this.dispatch(ut(t)), this;
869
891
  }
870
892
  /**
871
893
  * Removes a range of operations from the document.
@@ -884,7 +906,7 @@ class ve {
884
906
  return this.dispatch(L(t, i)), this;
885
907
  }
886
908
  }
887
- function ye(e, t) {
909
+ function je(e, t) {
888
910
  t.forEach((i) => {
889
911
  Object.getOwnPropertyNames(i.prototype).forEach((a) => {
890
912
  Object.defineProperty(
@@ -898,32 +920,33 @@ function ye(e, t) {
898
920
  });
899
921
  }
900
922
  export {
901
- de as A,
902
- ve as B,
923
+ Jt as A,
924
+ ye as B,
925
+ fe as C,
903
926
  Vt as a,
904
927
  Gt as b,
905
928
  Kt as c,
906
- he as d,
907
- ie as e,
929
+ be as d,
930
+ ae as e,
908
931
  y as f,
909
- ye as g,
910
- ge as h,
932
+ je as g,
933
+ he as h,
911
934
  J as i,
912
935
  gt as j,
913
- we as k,
936
+ ve as k,
914
937
  W as l,
915
- be as m,
938
+ we as m,
916
939
  lt as n,
917
- fe as o,
940
+ xe as o,
918
941
  Ht as p,
919
- $ as q,
942
+ C as q,
920
943
  Qt as r,
921
- ee as s,
944
+ ie as s,
922
945
  D as t,
923
946
  rt as u,
924
947
  M as v,
925
948
  Xt as w,
926
- xe as x,
927
- pt as y,
928
- Jt as z
949
+ ge as x,
950
+ ee as y,
951
+ pt as z
929
952
  };