document-model 1.0.18 → 1.0.19

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