document-model 1.0.27 → 1.0.29

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