document-model 1.0.34 → 1.0.36

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