document-model 1.0.18 → 1.0.20

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 (52) hide show
  1. package/dist/browser/document/actions/creators.d.ts +4 -4
  2. package/dist/browser/document/actions/index.d.ts +4 -4
  3. package/dist/browser/document/object.d.ts +119 -13
  4. package/dist/browser/document/schema/types.d.ts +5 -4
  5. package/dist/browser/document/schema/zod.d.ts +14 -12
  6. package/dist/browser/document/types.d.ts +2 -5
  7. package/dist/browser/document/utils/base.d.ts +6 -2
  8. package/dist/browser/document-model/gen/schema/zod.d.ts +5 -3
  9. package/dist/browser/document-model/index.d.ts +3 -3
  10. package/dist/browser/document-model.cjs +1 -1
  11. package/dist/browser/document-model.js +2 -2
  12. package/dist/browser/document.cjs +1 -1
  13. package/dist/browser/document.js +6 -6
  14. package/dist/browser/index.cjs +1 -1
  15. package/dist/browser/index.js +4 -4
  16. package/dist/browser/internal/{index-10a12861.js → index-22f88bf2.js} +361 -357
  17. package/dist/browser/internal/index-3607fd07.js +34 -0
  18. package/dist/browser/internal/index-79fde5f3.js +1 -0
  19. package/dist/browser/internal/index-dda5d688.js +22 -0
  20. package/dist/browser/internal/object-32802eed.js +6 -0
  21. package/dist/browser/internal/object-d03c84c9.js +1779 -0
  22. package/dist/node/document/actions/creators.d.ts +4 -4
  23. package/dist/node/document/actions/index.d.ts +4 -4
  24. package/dist/node/document/object.d.ts +119 -13
  25. package/dist/node/document/schema/types.d.ts +5 -4
  26. package/dist/node/document/schema/zod.d.ts +14 -12
  27. package/dist/node/document/types.d.ts +2 -5
  28. package/dist/node/document/utils/base.d.ts +6 -2
  29. package/dist/node/document-model/gen/schema/zod.d.ts +5 -3
  30. package/dist/node/document-model/index.d.ts +3 -3
  31. package/dist/node/document-model.cjs +1 -1
  32. package/dist/node/document-model.js +3 -3
  33. package/dist/node/document.cjs +1 -1
  34. package/dist/node/document.js +5 -5
  35. package/dist/node/index.cjs +1 -1
  36. package/dist/node/index.js +4 -4
  37. package/dist/node/internal/{index-09364517.js → index-14279b3a.js} +362 -358
  38. package/dist/node/internal/index-4b25c8a5.js +1 -0
  39. package/dist/node/internal/index-bfc402ef.js +22 -0
  40. package/dist/node/internal/index-e02d7854.js +34 -0
  41. package/dist/node/internal/object-ac706c4a.js +1 -0
  42. package/dist/node/internal/{object-c32ea0a0.js → object-b97efc1b.js} +469 -402
  43. package/package.json +1 -1
  44. package/dist/browser/internal/index-2aee8ea9.js +0 -1
  45. package/dist/browser/internal/index-a1282d5c.js +0 -31
  46. package/dist/browser/internal/index-ec8cd58f.js +0 -22
  47. package/dist/browser/internal/object-24df9d92.js +0 -6
  48. package/dist/browser/internal/object-7e8eaff4.js +0 -1712
  49. package/dist/node/internal/index-284511b8.js +0 -22
  50. package/dist/node/internal/index-2d4783d9.js +0 -1
  51. package/dist/node/internal/index-5ef0c6b0.js +0 -31
  52. package/dist/node/internal/object-21f3d2ee.js +0 -1
@@ -1,157 +1,255 @@
1
- var at = Object.defineProperty;
2
- var ot = (t, e, i) => e in t ? at(t, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : t[e] = i;
3
- var x = (t, e, i) => (ot(t, typeof e != "symbol" ? e + "" : e, i), i);
4
- import nt from "json-stringify-deterministic";
5
- import { produce as N, castDraft as st, castImmutable as lt, freeze as pt } from "immer";
6
- import F from "jszip";
7
- import ct from "crypto";
8
- import w from "fs";
9
- import rt from "https";
10
- import { join as mt } from "path";
11
- import { z as n } from "zod";
12
- const P = (t) => t != null, ut = n.any().refine((t) => P(t)), q = n.enum(["LOAD_STATE"]), I = n.enum(["PRUNE"]), M = n.enum(["REDO"]), R = n.enum(["SET_NAME"]), L = n.enum(["UNDO"]);
13
- function dt() {
14
- return n.object({
15
- __typename: n.literal("Action").optional(),
16
- type: n.string()
1
+ var rt = Object.defineProperty;
2
+ var mt = (t, e, i) => e in t ? rt(t, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : t[e] = i;
3
+ var j = (t, e, i) => (mt(t, typeof e != "symbol" ? e + "" : e, i), i);
4
+ import ut from "json-stringify-deterministic";
5
+ import { produce as P, castDraft as dt, castImmutable as xt, freeze as gt } from "immer";
6
+ import { z as o } from "zod";
7
+ import M from "jszip";
8
+ import ft from "crypto";
9
+ import k from "fs";
10
+ import ht from "https";
11
+ import { join as bt } from "path";
12
+ const R = (t) => t != null, vt = o.any().refine((t) => R(t)), L = o.enum(["LOAD_STATE"]), U = o.enum(["PRUNE"]), J = o.enum(["REDO"]), $ = o.enum(["SET_NAME"]), C = o.enum(["UNDO"]);
13
+ function yt() {
14
+ return o.object({
15
+ __typename: o.literal("Action").optional(),
16
+ type: o.string()
17
17
  });
18
18
  }
19
- function U() {
20
- return n.union([
21
- J(),
22
- C(),
23
- B(),
19
+ function x() {
20
+ return o.literal("global").or(o.literal("local"));
21
+ }
22
+ function B() {
23
+ return o.union([
24
24
  Z(),
25
- H()
25
+ K(),
26
+ W(),
27
+ G(),
28
+ Q()
26
29
  ]);
27
30
  }
28
- function xt() {
29
- return n.object({
30
- __typename: n.literal("DocumentFile").optional(),
31
- data: n.string(),
32
- extension: n.string().nullable(),
33
- fileName: n.string().nullable(),
34
- mimeType: n.string()
31
+ function jt() {
32
+ return o.object({
33
+ __typename: o.literal("DocumentFile").optional(),
34
+ data: o.string(),
35
+ extension: o.string().nullable(),
36
+ fileName: o.string().nullable(),
37
+ mimeType: o.string()
35
38
  });
36
39
  }
37
- function J() {
38
- return n.object({
39
- input: n.lazy(() => S()),
40
- type: q,
41
- scope: n.literal("global")
40
+ function Z() {
41
+ return o.object({
42
+ input: o.lazy(() => E()),
43
+ type: L,
44
+ scope: x()
42
45
  });
43
46
  }
44
- function S() {
45
- return n.object({
46
- operations: n.number(),
47
- state: n.lazy(() => $())
47
+ function E() {
48
+ return o.object({
49
+ operations: o.number(),
50
+ state: o.lazy(() => H())
48
51
  });
49
52
  }
50
- function $() {
51
- return n.object({
52
- data: n.unknown().nullish(),
53
- name: n.string()
53
+ function H() {
54
+ return o.object({
55
+ data: o.unknown().nullish(),
56
+ name: o.string()
54
57
  });
55
58
  }
56
- function gt() {
57
- return n.object({
58
- __typename: n.literal("Operation").optional(),
59
- hash: n.string(),
60
- index: n.number(),
61
- timestamp: n.string().datetime(),
62
- type: n.string()
59
+ function wt() {
60
+ return o.object({
61
+ __typename: o.literal("Operation").optional(),
62
+ hash: o.string(),
63
+ index: o.number(),
64
+ timestamp: o.string().datetime(),
65
+ type: o.string()
63
66
  });
64
67
  }
65
- function C() {
66
- return n.object({
67
- input: n.lazy(() => _()),
68
- type: I,
69
- scope: n.literal("global")
68
+ function K() {
69
+ return o.object({
70
+ input: o.lazy(() => N()),
71
+ type: U,
72
+ scope: x()
70
73
  });
71
74
  }
72
- function _() {
73
- return n.object({
74
- end: n.number().nullish(),
75
- start: n.number().nullish()
75
+ function N() {
76
+ return o.object({
77
+ end: o.number().nullish(),
78
+ start: o.number().nullish()
76
79
  });
77
80
  }
78
- const O = n.number;
79
- function B() {
80
- return n.object({
81
- input: O(),
82
- type: M,
83
- scope: n.literal("global")
81
+ const A = o.number;
82
+ function W() {
83
+ return o.object({
84
+ input: A(),
85
+ type: J,
86
+ scope: x()
84
87
  });
85
88
  }
86
- const D = n.string;
87
- function Z() {
88
- return n.object({
89
- input: D(),
90
- type: R,
91
- scope: n.literal("global")
89
+ const T = o.string;
90
+ function G() {
91
+ return o.object({
92
+ input: T(),
93
+ type: $,
94
+ scope: o.literal("global")
92
95
  });
93
96
  }
94
- function ft() {
95
- return n.object({
96
- __typename: n.literal("SetNameOperation").optional(),
97
- hash: n.string(),
98
- index: n.number(),
99
- input: n.string(),
100
- timestamp: n.string().datetime(),
101
- type: n.string()
97
+ function St() {
98
+ return o.object({
99
+ __typename: o.literal("SetNameOperation").optional(),
100
+ hash: o.string(),
101
+ index: o.number(),
102
+ input: o.string(),
103
+ timestamp: o.string().datetime(),
104
+ type: o.string()
102
105
  });
103
106
  }
104
- const k = n.number;
105
- function H() {
106
- return n.object({
107
- input: k(),
108
- type: L,
109
- scope: n.literal("global")
107
+ const z = o.number;
108
+ function Q() {
109
+ return o.object({
110
+ input: z(),
111
+ type: C,
112
+ scope: x()
110
113
  });
111
114
  }
112
- const Xt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
115
+ const oe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
113
116
  __proto__: null,
114
- ActionSchema: dt,
115
- BaseActionSchema: U,
116
- DocumentFileSchema: xt,
117
- LoadStateActionInputSchema: S,
118
- LoadStateActionSchema: J,
119
- LoadStateActionStateInputSchema: $,
120
- Load_StateSchema: q,
121
- OperationSchema: gt,
122
- PruneActionInputSchema: _,
123
- PruneActionSchema: C,
124
- PruneSchema: I,
125
- RedoActionInputSchema: O,
126
- RedoActionSchema: B,
127
- RedoSchema: M,
128
- SetNameActionInputSchema: D,
129
- SetNameActionSchema: Z,
130
- SetNameOperationSchema: ft,
131
- Set_NameSchema: R,
132
- UndoActionInputSchema: k,
133
- UndoActionSchema: H,
134
- UndoSchema: L,
135
- definedNonNullAnySchema: ut,
136
- isDefinedNonNullAny: P
117
+ ActionSchema: yt,
118
+ BaseActionSchema: B,
119
+ DocumentFileSchema: jt,
120
+ LoadStateActionInputSchema: E,
121
+ LoadStateActionSchema: Z,
122
+ LoadStateActionStateInputSchema: H,
123
+ Load_StateSchema: L,
124
+ OperationSchema: wt,
125
+ OperationScopeSchema: x,
126
+ PruneActionInputSchema: N,
127
+ PruneActionSchema: K,
128
+ PruneSchema: U,
129
+ RedoActionInputSchema: A,
130
+ RedoActionSchema: W,
131
+ RedoSchema: J,
132
+ SetNameActionInputSchema: T,
133
+ SetNameActionSchema: G,
134
+ SetNameOperationSchema: St,
135
+ Set_NameSchema: $,
136
+ UndoActionInputSchema: z,
137
+ UndoActionSchema: Q,
138
+ UndoSchema: C,
139
+ definedNonNullAnySchema: vt,
140
+ isDefinedNonNullAny: R
137
141
  }, Symbol.toStringTag, { value: "Module" }));
138
- function ht(t) {
142
+ function Ot(t, e) {
143
+ return { ...t, name: e };
144
+ }
145
+ function _t(t, e, i) {
146
+ const { scope: a, input: n } = e, s = t.revision[e.scope], p = Math.min(n, s), l = t.operations[a].slice(
147
+ 0,
148
+ s - p
149
+ );
150
+ return {
151
+ ...S(
152
+ t.initialState,
153
+ {
154
+ ...t.operations,
155
+ [a]: l
156
+ },
157
+ i
158
+ ),
159
+ operations: t.operations,
160
+ revision: {
161
+ ...t.revision,
162
+ [a]: t.revision[a] - p
163
+ }
164
+ };
165
+ }
166
+ function Dt(t, e, i) {
167
+ const { scope: a, input: n } = e, s = t.operations[a].length - t.revision[a];
168
+ if (!s)
169
+ throw new Error("There is no UNDO operation to REDO");
170
+ const p = n < s ? n : s, l = t.operations[a].slice(
171
+ 0,
172
+ t.revision[a] + p
173
+ );
174
+ return {
175
+ ...S(
176
+ t.initialState,
177
+ {
178
+ ...t.operations,
179
+ [a]: l
180
+ },
181
+ i
182
+ ),
183
+ operations: t.operations,
184
+ revision: {
185
+ ...t.revision,
186
+ [a]: t.revision[a] + p
187
+ }
188
+ };
189
+ }
190
+ function kt(t, e, i) {
191
+ const { scope: a } = e, n = t.operations[a];
192
+ let {
193
+ input: { start: s, end: p }
194
+ } = e;
195
+ s = s || 0, p = p || n.length;
196
+ const l = n.slice(s, p), r = n.slice(0, s), c = n.slice(p), u = S(
197
+ t.initialState,
198
+ {
199
+ ...t.operations,
200
+ [a]: r.concat(l)
201
+ },
202
+ i
203
+ ), { name: m, state: v } = u, d = r.length, D = r.length ? r[r.length - 1].timestamp : c.length ? c[0].timestamp : (/* @__PURE__ */ new Date()).toISOString();
204
+ return S(
205
+ t.initialState,
206
+ {
207
+ ...t.operations,
208
+ [a]: [
209
+ ...r,
210
+ {
211
+ ...F(
212
+ { name: m, state: v },
213
+ l.length
214
+ ),
215
+ timestamp: D,
216
+ index: d,
217
+ hash: at({ state: v }, "global")
218
+ },
219
+ ...c.map((y, ct) => ({
220
+ ...y,
221
+ index: d + ct + 1
222
+ }))
223
+ ]
224
+ },
225
+ i
226
+ );
227
+ }
228
+ function Et(t, e) {
229
+ return {
230
+ ...t,
231
+ name: e.name,
232
+ state: e.state ?? { global: {}, local: {} }
233
+ };
234
+ }
235
+ const V = "SET_NAME", g = "UNDO", f = "REDO", h = "PRUNE", X = "LOAD_STATE";
236
+ function Nt(t) {
139
237
  return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
140
238
  }
141
- function h() {
239
+ function O() {
142
240
  this._types = /* @__PURE__ */ Object.create(null), this._extensions = /* @__PURE__ */ Object.create(null);
143
241
  for (let t = 0; t < arguments.length; t++)
144
242
  this.define(arguments[t]);
145
243
  this.define = this.define.bind(this), this.getType = this.getType.bind(this), this.getExtension = this.getExtension.bind(this);
146
244
  }
147
- h.prototype.define = function(t, e) {
245
+ O.prototype.define = function(t, e) {
148
246
  for (let i in t) {
149
- let a = t[i].map(function(o) {
150
- return o.toLowerCase();
247
+ let a = t[i].map(function(n) {
248
+ return n.toLowerCase();
151
249
  });
152
250
  i = i.toLowerCase();
153
- for (let o = 0; o < a.length; o++) {
154
- const s = a[o];
251
+ for (let n = 0; n < a.length; n++) {
252
+ const s = a[n];
155
253
  if (s[0] !== "*") {
156
254
  if (!e && s in this._types)
157
255
  throw new Error(
@@ -161,334 +259,240 @@ h.prototype.define = function(t, e) {
161
259
  }
162
260
  }
163
261
  if (e || !this._extensions[i]) {
164
- const o = a[0];
165
- this._extensions[i] = o[0] !== "*" ? o : o.substr(1);
262
+ const n = a[0];
263
+ this._extensions[i] = n[0] !== "*" ? n : n.substr(1);
166
264
  }
167
265
  }
168
266
  };
169
- h.prototype.getType = function(t) {
267
+ O.prototype.getType = function(t) {
170
268
  t = String(t);
171
269
  let e = t.replace(/^.*[/\\]/, "").toLowerCase(), i = e.replace(/^.*\./, "").toLowerCase(), a = e.length < t.length;
172
270
  return (i.length < e.length - 1 || !a) && this._types[i] || null;
173
271
  };
174
- h.prototype.getExtension = function(t) {
272
+ O.prototype.getExtension = function(t) {
175
273
  return t = /^\s*([^;\s]*)/.test(t) && RegExp.$1, t && this._extensions[t.toLowerCase()] || null;
176
274
  };
177
- var bt = h, vt = { "application/andrew-inset": ["ez"], "application/applixware": ["aw"], "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/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/cu-seeme": ["cu"], "application/dash+xml": ["mpd"], "application/davmount+xml": ["davmount"], "application/docbook+xml": ["dbk"], "application/dssc+der": ["dssc"], "application/dssc+xml": ["xdssc"], "application/ecmascript": ["es", "ecma"], "application/emma+xml": ["emma"], "application/emotionml+xml": ["emotionml"], "application/epub+zip": ["epub"], "application/exi": ["exi"], "application/express": ["exp"], "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", "mjs"], "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/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": ["mp4s", "m4p"], "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-signature": ["asc", "sig"], "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/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/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/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/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/avif": ["avif"], "image/bmp": ["bmp"], "image/cgm": ["cgm"], "image/dicom-rle": ["drle"], "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"], "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/mesh": ["msh", "mesh", "silo"], "model/mtl": ["mtl"], "model/obj": ["obj"], "model/step+xml": ["stpx"], "model/step+zip": ["stpz"], "model/step-xml+zip": ["stpxz"], "model/stl": ["stl"], "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/jsx": ["jsx"], "text/less": ["less"], "text/markdown": ["markdown", "md"], "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/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"] };
178
- let yt = bt;
179
- var jt = new yt(vt);
180
- const wt = /* @__PURE__ */ ht(jt);
181
- function St(t, e, i) {
182
- const a = mt(t, e);
183
- return w.mkdirSync(t, { recursive: !0 }), new Promise((o, s) => {
275
+ var At = O, Tt = { "application/andrew-inset": ["ez"], "application/applixware": ["aw"], "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/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/cu-seeme": ["cu"], "application/dash+xml": ["mpd"], "application/davmount+xml": ["davmount"], "application/docbook+xml": ["dbk"], "application/dssc+der": ["dssc"], "application/dssc+xml": ["xdssc"], "application/ecmascript": ["es", "ecma"], "application/emma+xml": ["emma"], "application/emotionml+xml": ["emotionml"], "application/epub+zip": ["epub"], "application/exi": ["exi"], "application/express": ["exp"], "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", "mjs"], "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/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": ["mp4s", "m4p"], "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-signature": ["asc", "sig"], "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/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/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/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/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/avif": ["avif"], "image/bmp": ["bmp"], "image/cgm": ["cgm"], "image/dicom-rle": ["drle"], "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"], "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/mesh": ["msh", "mesh", "silo"], "model/mtl": ["mtl"], "model/obj": ["obj"], "model/step+xml": ["stpx"], "model/step+zip": ["stpz"], "model/step-xml+zip": ["stpxz"], "model/stl": ["stl"], "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/jsx": ["jsx"], "text/less": ["less"], "text/markdown": ["markdown", "md"], "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/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"] };
276
+ let zt = At;
277
+ var Ft = new zt(Tt);
278
+ const Pt = /* @__PURE__ */ Nt(Ft);
279
+ function qt(t, e, i) {
280
+ const a = bt(t, e);
281
+ return k.mkdirSync(t, { recursive: !0 }), new Promise((n, s) => {
184
282
  try {
185
- w.writeFile(a, i, {}, (l) => {
186
- l ? s(l) : o(a);
283
+ k.writeFile(a, i, {}, (p) => {
284
+ p ? s(p) : n(a);
187
285
  });
188
- } catch (l) {
189
- s(l);
286
+ } catch (p) {
287
+ s(p);
190
288
  }
191
289
  });
192
290
  }
193
- function K(t) {
194
- return w.readFileSync(t);
291
+ function Y(t) {
292
+ return k.readFileSync(t);
195
293
  }
196
- function _t(t) {
294
+ function It(t) {
197
295
  return new Promise((e, i) => {
198
- rt.get(t, (a) => {
199
- const o = [], s = a.headers["content-type"];
200
- a.on("data", (l) => {
201
- o.push(l);
296
+ ht.get(t, (a) => {
297
+ const n = [], s = a.headers["content-type"];
298
+ a.on("data", (p) => {
299
+ n.push(p);
202
300
  }), a.on("end", () => {
203
- e({ buffer: Buffer.concat(o), mimeType: s });
301
+ e({ buffer: Buffer.concat(n), mimeType: s });
204
302
  });
205
303
  }).on("error", (a) => {
206
304
  i(a);
207
305
  });
208
306
  });
209
307
  }
210
- const Ot = async (t) => K(t), b = (t, e = "sha1") => ct.createHash(e).update(t).digest("base64"), W = async (t) => {
211
- const e = new F(), { name: i, revision: a, documentType: o, created: s, lastModified: l } = t, p = {
308
+ const Mt = async (t) => Y(t), _ = (t, e = "sha1") => ft.createHash(e).update(t).digest("base64"), tt = async (t) => {
309
+ const e = new M(), { name: i, revision: a, documentType: n, created: s, lastModified: p } = t, l = {
212
310
  name: i,
213
311
  revision: a,
214
- documentType: o,
312
+ documentType: n,
215
313
  created: s,
216
- lastModified: l
314
+ lastModified: p
217
315
  };
218
- return e.file("header.json", JSON.stringify(p, null, 2)), e.file(
316
+ return e.file("header.json", JSON.stringify(l, null, 2)), e.file(
219
317
  "state.json",
220
318
  JSON.stringify(t.initialState || {}, null, 2)
221
- ), e.file("operations.json", JSON.stringify(t.operations, null, 2)), Object.keys(t.attachments).forEach((m) => {
222
- const { data: r, ...j } = t.attachments[m];
223
- e.file(m, r, {
319
+ ), e.file("operations.json", JSON.stringify(t.operations, null, 2)), Object.keys(t.attachments).forEach((c) => {
320
+ const { data: u, ...m } = t.attachments[c];
321
+ e.file(c, u, {
224
322
  base64: !0,
225
323
  createFolders: !0,
226
- comment: JSON.stringify(j)
324
+ comment: JSON.stringify(m)
227
325
  });
228
326
  }), e;
229
- }, Dt = async (t, e, i, a) => {
230
- const s = await (await W(t)).generateAsync({
327
+ }, Rt = async (t, e, i, a) => {
328
+ const s = await (await tt(t)).generateAsync({
231
329
  type: "uint8array",
232
330
  streamFiles: !0
233
- }), l = a ?? t.name, p = `.${i}.zip`;
234
- return St(
331
+ }), p = a ?? t.name, l = `.${i}.zip`;
332
+ return qt(
235
333
  e,
236
- l.endsWith(p) ? l : `${l}${p}`,
334
+ p.endsWith(l) ? p : `${p}${l}`,
237
335
  s
238
336
  );
239
- }, Yt = async (t, e) => {
240
- const a = await (await W(t)).generateAsync({ type: "blob" }), o = await e.createWritable();
241
- await o.write(a), await o.close();
242
- }, A = async (t, e) => {
243
- const i = K(t);
244
- return kt(i, e);
245
- }, kt = async (t, e) => {
246
- const i = new F();
247
- return await i.loadAsync(t), Et(i, e);
337
+ }, se = async (t, e) => {
338
+ const a = await (await tt(t)).generateAsync({ type: "blob" }), n = await e.createWritable();
339
+ await n.write(a), await n.close();
340
+ }, q = async (t, e) => {
341
+ const i = Y(t);
342
+ return Lt(i, e);
343
+ }, Lt = async (t, e) => {
344
+ const i = new M();
345
+ return await i.loadAsync(t), Ut(i, e);
248
346
  };
249
- async function Et(t, e) {
347
+ async function Ut(t, e) {
250
348
  const i = t.file("state.json");
251
349
  if (!i)
252
350
  throw new Error("Initial state not found");
253
- const a = await i.async("string"), o = JSON.parse(a), s = t.file("header.json");
254
- let l = null;
255
- s && (l = JSON.parse(await s.async("string")));
256
- const p = t.file("operations.json");
257
- if (!p)
351
+ const a = await i.async("string"), n = JSON.parse(a), s = t.file("header.json");
352
+ let p;
353
+ s && (p = JSON.parse(await s.async("string")));
354
+ const l = t.file("operations.json");
355
+ if (!l)
258
356
  throw new Error("Operations history not found");
259
- const c = JSON.parse(
260
- await p.async("string")
261
- ), m = {
262
- ...o,
263
- ...l,
264
- initialState: o,
265
- operations: { global: [], local: [] },
266
- attachments: { ...o.attachments }
267
- };
268
- let r = c.global.concat(c.local).slice(0, l == null ? void 0 : l.revision).reduce(
269
- (j, it) => e(j, it),
270
- m
357
+ const r = JSON.parse(
358
+ await l.async("string")
271
359
  );
272
- return l && (r = {
273
- ...r,
274
- ...l,
275
- operations: {
276
- global: [
277
- ...r.operations.global,
278
- ...c.global.slice(l.revision)
279
- ],
280
- local: r.operations.local
281
- }
282
- }), r;
360
+ let c = nt(
361
+ n,
362
+ r,
363
+ e,
364
+ void 0,
365
+ p
366
+ );
367
+ return p && (c = {
368
+ ...c,
369
+ ...p
370
+ }), c;
283
371
  }
284
- function G(t) {
372
+ function et(t) {
285
373
  const e = t.replace(/^.*\./, "") || void 0, i = t.replace(/^.*[/\\]/, "") || void 0;
286
374
  return { extension: e, fileName: i };
287
375
  }
288
- async function te(t) {
289
- const { buffer: e, mimeType: i = "application/octet-stream" } = await _t(t), a = G(t), o = e.toString("base64");
376
+ async function pe(t) {
377
+ const { buffer: e, mimeType: i = "application/octet-stream" } = await It(t), a = et(t), n = e.toString("base64");
290
378
  return {
291
- data: o,
292
- hash: b(o),
379
+ data: n,
380
+ hash: _(n),
293
381
  mimeType: i,
294
382
  ...a
295
383
  };
296
384
  }
297
- async function ee(t) {
298
- const e = await Ot(t), i = wt.getType(t) || "application/octet-stream", a = G(t), o = e.toString("base64");
299
- return { data: o, hash: b(o), mimeType: i, ...a };
300
- }
301
- function f(t, e, i, a) {
302
- const o = $t(t), s = Ut(i);
303
- return e.global.concat(e.local).reduce(
304
- (l, p) => s(l, p, a),
305
- o
306
- );
385
+ async function le(t) {
386
+ const e = await Mt(t), i = Pt.getType(t) || "application/octet-stream", a = et(t), n = e.toString("base64");
387
+ return { data: n, hash: _(n), mimeType: i, ...a };
307
388
  }
308
- function Nt(t, e) {
309
- return { ...t, name: e };
389
+ function Jt(t, e) {
390
+ const i = t.revision[e.scope];
391
+ return [g, f, h].includes(e.type) ? i : i + 1;
310
392
  }
311
- function At(t, e, i) {
312
- const a = Math.min(e, t.revision), o = t.operations.global.slice(
313
- 0,
314
- t.revision - a
315
- );
316
- return {
317
- ...f(
318
- t.initialState,
319
- {
320
- global: o,
321
- local: t.operations.local
322
- },
323
- i
324
- ),
325
- operations: t.operations,
326
- revision: t.revision - a
327
- };
328
- }
329
- function Tt(t, e, i) {
330
- const a = t.operations.global.length - t.revision;
331
- if (!a)
332
- throw new Error("There is no UNDO operation to REDO");
333
- const o = e < a ? e : a, s = t.operations.global.slice(
334
- 0,
335
- t.revision + o
336
- );
337
- return {
338
- ...f(
339
- t.initialState,
340
- {
341
- global: s,
342
- local: t.operations.local
343
- },
344
- i
345
- ),
346
- operations: t.operations,
347
- revision: t.revision + o
348
- };
349
- }
350
- function zt(t, e, i, a) {
351
- e = e || 0, i = i || t.operations.global.length;
352
- const o = t.operations.global.slice(e, i), s = t.operations.global.slice(0, e), l = t.operations.global.slice(i), p = f(
353
- t.initialState,
354
- {
355
- global: s.concat(o),
356
- local: t.operations.local
357
- },
358
- a
359
- ), { name: c, state: m } = p;
360
- return f(
361
- t.initialState,
362
- {
363
- global: [
364
- ...s,
365
- E({ name: c, state: m }, o.length),
366
- ...l
367
- ],
368
- local: t.operations.local
369
- },
370
- a
371
- );
372
- }
373
- function Ft(t, e) {
393
+ function $t(t, e) {
374
394
  return {
375
395
  ...t,
376
- name: e.name,
377
- state: e.state ?? { global: {}, local: {} }
378
- };
379
- }
380
- const Q = "SET_NAME", v = "UNDO", y = "REDO", u = "PRUNE", V = "LOAD_STATE";
381
- function Pt(t, e) {
382
- return [v, y, u].includes(e.type) ? t.revision : t.revision + 1;
383
- }
384
- function qt(t, e) {
385
- return {
386
- ...t,
387
- revision: Pt(t, e),
396
+ revision: {
397
+ ...t.revision,
398
+ [e.scope]: Jt(t, e)
399
+ },
388
400
  lastModified: (/* @__PURE__ */ new Date()).toISOString()
389
401
  };
390
402
  }
391
- function It(t, e) {
392
- if ([v, y, u, u].includes(e.type))
403
+ function Ct(t, e) {
404
+ if ([g, f, h].includes(e.type))
393
405
  return t;
394
- const i = t.operations.global.slice(
406
+ const { scope: i } = e, a = t.operations[i].slice(
395
407
  0,
396
- t.revision
397
- ), a = t.operations.local.slice();
398
- return !e.scope || e.scope === "global" ? i.push({
399
- ...e,
400
- index: i.length,
401
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
402
- hash: "",
403
- scope: "global"
404
- }) : e.scope === "local" && a.push({
408
+ t.revision[i]
409
+ );
410
+ return a.push({
405
411
  ...e,
406
412
  index: a.length,
407
413
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
408
414
  hash: "",
409
- scope: "local"
415
+ scope: i
410
416
  }), {
411
417
  ...t,
412
- operations: {
413
- global: i,
414
- local: a
415
- }
418
+ operations: { ...t.operations, [i]: a }
416
419
  };
417
420
  }
418
- function Mt(t, e) {
419
- let i = It(t, e);
420
- return (!e.scope || e.scope === "global") && (i = qt(i, e)), i;
421
- }
422
- function Rt(t, e, i) {
423
- switch (U().parse(e), e.type) {
424
- case Q:
425
- return Nt(t, e.input);
426
- case v:
427
- return At(t, e.input, i);
428
- case y:
429
- return Tt(t, e.input, i);
430
- case u:
431
- return zt(
432
- t,
433
- e.input.start,
434
- e.input.end,
435
- i
436
- );
421
+ function Bt(t, e) {
422
+ let i = Ct(t, e);
423
+ return i = $t(i, e), i;
424
+ }
425
+ function Zt(t, e, i) {
426
+ switch (B().parse(e), e.type) {
437
427
  case V:
438
- return Ft(t, e.input.state);
428
+ return Ot(t, e.input);
429
+ case g:
430
+ return _t(t, e, i);
431
+ case f:
432
+ return Dt(t, e, i);
433
+ case h:
434
+ return kt(t, e, i);
435
+ case X:
436
+ return Et(t, e.input.state);
439
437
  default:
440
438
  return t;
441
439
  }
442
440
  }
443
- function Lt(t, e, i, a) {
444
- let o = t;
445
- return T(e) && (o = Rt(o, e, i)), o = Mt(o, e), o = N(o, (s) => {
446
- const l = i(s.state, e, a);
447
- if (l)
448
- return st({
449
- ...o,
450
- state: l
441
+ function it(t, e, i, a) {
442
+ let n = t;
443
+ return I(e) && (n = Zt(n, e, i)), n = Bt(n, e), n = P(n, (s) => {
444
+ const p = i(s.state, e, a);
445
+ if (p)
446
+ return dt({
447
+ ...n,
448
+ state: p
451
449
  });
452
- }), N(o, (s) => {
453
- !e.scope || e.scope === "global" ? s.operations.global[s.operations.global.length - 1].hash = z(s, "global") : e.scope === "local" && (s.operations.local[s.operations.local.length - 1].hash = z(s, "local")), !T(e) && e.attachments && e.attachments.forEach((l) => {
454
- const { hash: p, ...c } = l;
455
- s.attachments[p] = {
450
+ }), P(n, (s) => {
451
+ if ([g, f, h].includes(e.type))
452
+ return s;
453
+ const p = e.scope || "global";
454
+ s.operations[p][s.operations[p].length - 1].hash = at(s, p), !I(e) && e.attachments && e.attachments.forEach((l) => {
455
+ const { hash: r, ...c } = l;
456
+ s.attachments[r] = {
456
457
  ...c
457
458
  };
458
459
  });
459
460
  });
460
461
  }
461
- function T(t) {
462
- return [Q, v, y, u, V].includes(t.type);
462
+ function I(t) {
463
+ return [V, g, f, h, X].includes(t.type);
463
464
  }
464
- function d(t, e, i, a, o = "global") {
465
+ function b(t, e, i, a, n = "global") {
465
466
  if (!t)
466
467
  throw new Error("Empty action type");
467
468
  if (typeof t != "string")
468
469
  throw new Error(`Invalid action type: ${t}`);
469
- const s = { type: t, input: e, scope: o };
470
+ const s = { type: t, input: e, scope: n };
470
471
  i && (s.attachments = i);
471
472
  try {
472
473
  a == null || a().parse(s.input);
473
- } catch (l) {
474
- throw new Error(`Invalid action input: ${l}`);
474
+ } catch (p) {
475
+ throw new Error(`Invalid action input: ${p}`);
475
476
  }
476
477
  return s;
477
478
  }
478
- function Ut(t, e = Lt) {
479
- return (i, a, o) => e(i, a, t, o);
479
+ function Ht(t, e = it) {
480
+ return (i, a, n) => e(i, a, t, n);
480
481
  }
481
- const Jt = (t, e) => ({
482
+ const Kt = (t, e) => ({
482
483
  name: "",
483
484
  documentType: "",
484
- revision: 0,
485
+ revision: {
486
+ global: 0,
487
+ local: 0
488
+ },
485
489
  created: (/* @__PURE__ */ new Date()).toISOString(),
486
490
  lastModified: (/* @__PURE__ */ new Date()).toISOString(),
487
491
  attachments: {},
488
492
  ...t,
489
493
  state: (e == null ? void 0 : e(t == null ? void 0 : t.state)) ?? (t == null ? void 0 : t.state) ?? { global: {}, local: {} }
490
- }), $t = (t, e) => {
491
- const i = Jt(
494
+ }), Wt = (t, e) => {
495
+ const i = Kt(
492
496
  t,
493
497
  e
494
498
  );
@@ -497,50 +501,107 @@ const Jt = (t, e) => ({
497
501
  initialState: i,
498
502
  operations: { global: [], local: [] }
499
503
  };
500
- }, z = (t, e = "global") => b(
501
- nt(
502
- e === "local" ? t.state.local : t.state.global
503
- )
504
- ), ie = (t, e = 1e3) => {
504
+ }, at = (t, e = "global") => _(ut(t.state[e])), ce = (t, e = 1e3) => {
505
505
  const i = Math.random() * e;
506
- return b(`${(t ?? /* @__PURE__ */ new Date()).toISOString()}${i}`);
506
+ return _(`${(t ?? /* @__PURE__ */ new Date()).toISOString()}${i}`);
507
507
  };
508
- function g(t) {
509
- return lt(pt(t, !0));
508
+ function w(t) {
509
+ return xt(gt(t, !0));
510
+ }
511
+ function Gt(t) {
512
+ return Object.values(t).flatMap((e) => e).sort(
513
+ (e, i) => new Date(e.timestamp).getTime() - new Date(i.timestamp).getTime()
514
+ );
510
515
  }
511
- const X = (t) => d(
516
+ function S(t, e, i, a, n, s = it) {
517
+ const p = Ht(i, s);
518
+ return nt(
519
+ t,
520
+ e,
521
+ p,
522
+ a,
523
+ n
524
+ );
525
+ }
526
+ function nt(t, e, i, a, n) {
527
+ const s = Wt(t), p = Object.keys(e).reduce((c, u) => {
528
+ const m = u;
529
+ return {
530
+ ...c,
531
+ [m]: e[m].slice(0, n == null ? void 0 : n.revision[m])
532
+ };
533
+ }, {}), l = Gt(p).reduce(
534
+ (c, u) => i(c, u, a),
535
+ s
536
+ ), r = Object.keys(
537
+ l.operations
538
+ ).reduce(
539
+ (c, u) => {
540
+ const m = u, v = n && n.revision[m] < e[m].length ? e[m].slice(n.revision[m]) : [];
541
+ return {
542
+ ...c,
543
+ [m]: [
544
+ ...l.operations[m].map((d, D) => {
545
+ var y;
546
+ return {
547
+ ...d,
548
+ timestamp: ((y = e[m][D]) == null ? void 0 : y.timestamp) ?? d.timestamp
549
+ };
550
+ }),
551
+ ...v
552
+ ]
553
+ };
554
+ },
555
+ { global: [], local: [] }
556
+ );
557
+ return { ...l, operations: r };
558
+ }
559
+ const ot = (t) => b(
512
560
  "SET_NAME",
513
561
  t,
514
562
  void 0,
515
- D
516
- ), Y = (t = 1) => d("UNDO", t, void 0, k), tt = (t = 1) => d("REDO", t, void 0, O), et = (t, e) => d(
563
+ T
564
+ ), st = (t = 1, e = "global") => b(
565
+ "UNDO",
566
+ t,
567
+ void 0,
568
+ z,
569
+ e
570
+ ), pt = (t = 1, e = "global") => b(
571
+ "REDO",
572
+ t,
573
+ void 0,
574
+ A,
575
+ e
576
+ ), lt = (t, e, i = "global") => b(
517
577
  "PRUNE",
518
578
  { start: t, end: e },
519
579
  void 0,
520
- _
521
- ), E = (t, e) => d(
580
+ N,
581
+ i
582
+ ), F = (t, e) => b(
522
583
  "LOAD_STATE",
523
584
  { state: t, operations: e },
524
585
  void 0,
525
- S
526
- ), ae = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
586
+ E
587
+ ), re = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
527
588
  __proto__: null,
528
- loadState: E,
529
- prune: et,
530
- redo: tt,
531
- setName: X,
532
- undo: Y
589
+ loadState: F,
590
+ prune: lt,
591
+ redo: pt,
592
+ setName: ot,
593
+ undo: st
533
594
  }, Symbol.toStringTag, { value: "Module" }));
534
- class oe {
595
+ class me {
535
596
  /**
536
597
  * Constructs a BaseDocument instance with an initial state.
537
598
  * @param reducer - The reducer function that updates the state.
538
599
  * @param document - The initial state of the document.
539
600
  */
540
601
  constructor(e, i, a) {
541
- x(this, "_document");
542
- x(this, "_reducer");
543
- x(this, "_signalDispatch");
602
+ j(this, "_document");
603
+ j(this, "_reducer");
604
+ j(this, "_signalDispatch");
544
605
  this._reducer = e, this._document = i, this._signalDispatch = a;
545
606
  }
546
607
  /**
@@ -562,14 +623,14 @@ class oe {
562
623
  * @returns The file path where the state was saved.
563
624
  */
564
625
  saveToFile(e, i, a) {
565
- return Dt(this._document, e, i, a);
626
+ return Rt(this._document, e, i, a);
566
627
  }
567
628
  /**
568
629
  * Loads the state of the document from a file.
569
630
  * @param path - The file path where the state is stored.
570
631
  */
571
632
  async loadFromFile(e) {
572
- this._document = await A(e, this._reducer);
633
+ this._document = await q(e, this._reducer);
573
634
  }
574
635
  /**
575
636
  * Loads the state of the document from a file and returns it.
@@ -578,19 +639,19 @@ class oe {
578
639
  * @returns The state of the document.
579
640
  */
580
641
  static async stateFromFile(e, i) {
581
- return await A(e, i);
642
+ return await q(e, i);
582
643
  }
583
644
  /**
584
645
  * Gets the current state of the document.
585
646
  */
586
647
  get state() {
587
- return g(this._document.state);
648
+ return w(this._document.state);
588
649
  }
589
650
  /**
590
651
  * Gets the list of operations performed on the document.
591
652
  */
592
653
  get operations() {
593
- return g(this._document.operations);
654
+ return w(this._document.operations);
594
655
  }
595
656
  /**
596
657
  * Gets the name of the document.
@@ -617,22 +678,25 @@ class oe {
617
678
  return this._document.lastModified;
618
679
  }
619
680
  /**
620
- * Gets the revision number of the document.
681
+ * Gets the global revision number of the document.
621
682
  */
622
683
  get revision() {
623
- return this._document.revision;
684
+ return this._document.revision.global;
685
+ }
686
+ getRevision(e) {
687
+ return this._document.revision[e];
624
688
  }
625
689
  /**
626
690
  * Gets the initial state of the document.
627
691
  */
628
692
  get initialState() {
629
- return g(this._document.initialState);
693
+ return w(this._document.initialState);
630
694
  }
631
695
  /**
632
696
  * Returns the current document as an object
633
697
  */
634
698
  toDocument() {
635
- return g(this._document);
699
+ return w(this._document);
636
700
  }
637
701
  /**
638
702
  * Gets the attachment associated with the given key.
@@ -646,21 +710,21 @@ class oe {
646
710
  * @param name - The new name of the document.
647
711
  */
648
712
  setName(e) {
649
- return this.dispatch(X(e)), this;
713
+ return this.dispatch(ot(e)), this;
650
714
  }
651
715
  /**
652
716
  * Reverts a number of actions from the document.
653
717
  * @param count - The number of actions to revert.
654
718
  */
655
719
  undo(e) {
656
- return this.dispatch(Y(e)), this;
720
+ return this.dispatch(st(e)), this;
657
721
  }
658
722
  /**
659
723
  * Reapplies a number of actions to the document.
660
724
  * @param count - The number of actions to reapply.
661
725
  */
662
726
  redo(e) {
663
- return this.dispatch(tt(e)), this;
727
+ return this.dispatch(pt(e)), this;
664
728
  }
665
729
  /**
666
730
  * Removes a range of operations from the document.
@@ -668,7 +732,7 @@ class oe {
668
732
  * @param end - The ending index of the range to remove.
669
733
  */
670
734
  prune(e, i) {
671
- return this.dispatch(et(e, i)), this;
735
+ return this.dispatch(lt(e, i)), this;
672
736
  }
673
737
  /**
674
738
  * Loads a document state and a set of operations.
@@ -676,10 +740,10 @@ class oe {
676
740
  * @param operations - The operations to apply to the document.
677
741
  */
678
742
  loadState(e, i) {
679
- return this.dispatch(E(e, i)), this;
743
+ return this.dispatch(F(e, i)), this;
680
744
  }
681
745
  }
682
- function ne(t, e) {
746
+ function ue(t, e) {
683
747
  e.forEach((i) => {
684
748
  Object.getOwnPropertyNames(i.prototype).forEach((a) => {
685
749
  Object.defineProperty(
@@ -691,24 +755,27 @@ function ne(t, e) {
691
755
  });
692
756
  }
693
757
  export {
694
- oe as B,
695
- Jt as a,
696
- $t as b,
697
- Ut as c,
698
- Yt as d,
699
- kt as e,
700
- d as f,
701
- ne as g,
702
- ae as h,
703
- T as i,
704
- W as j,
705
- ee as k,
706
- A as l,
707
- te as m,
708
- z as n,
709
- ie as o,
710
- Lt as p,
711
- g as r,
712
- Dt as s,
713
- Xt as z
758
+ me as B,
759
+ Kt as a,
760
+ Wt as b,
761
+ Ht as c,
762
+ se as d,
763
+ Lt as e,
764
+ b as f,
765
+ ue as g,
766
+ re as h,
767
+ I as i,
768
+ tt as j,
769
+ le as k,
770
+ q as l,
771
+ pe as m,
772
+ at as n,
773
+ ce as o,
774
+ nt as p,
775
+ S as q,
776
+ w as r,
777
+ Rt as s,
778
+ Gt as t,
779
+ it as u,
780
+ oe as z
714
781
  };