document-model 1.0.24 → 1.0.26

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 (45) hide show
  1. package/dist/browser/document-model.cjs +1 -1
  2. package/dist/browser/document-model.js +2 -2
  3. package/dist/browser/document.cjs +1 -1
  4. package/dist/browser/document.js +2 -2
  5. package/dist/browser/index.cjs +1 -1
  6. package/dist/browser/index.js +3 -3
  7. package/dist/browser/internal/{index-sfNIE5tQ.js → index-IVF7gvRz.js} +16 -6
  8. package/dist/{node/internal/index-HgkfWSZk.js → browser/internal/index-JkTAMqR0.js} +1 -1
  9. package/dist/{node/internal/index-aihhQ-ya.js → browser/internal/index-ZuT5Pi3Z.js} +1 -1
  10. package/dist/browser/internal/{index-Xpydy6AU.js → index-gREVUw-G.js} +1 -1
  11. package/dist/browser/internal/object-1Edh7roc.js +1844 -0
  12. package/dist/browser/internal/object-v0zgcnse.js +6 -0
  13. package/dist/browser/src/document/schema/index.d.ts +2 -2
  14. package/dist/browser/src/document-model/custom/reducers/versioning.d.ts +4 -4
  15. package/dist/browser/vitest.config.d.ts +2 -0
  16. package/dist/node/document-model.cjs +1 -1
  17. package/dist/node/document-model.js +2 -2
  18. package/dist/node/document.cjs +1 -1
  19. package/dist/node/document.js +2 -2
  20. package/dist/node/index.cjs +1 -1
  21. package/dist/node/index.js +3 -3
  22. package/dist/{browser/internal/index-e4O5HJBs.js → node/internal/index-8_P5_maf.js} +1 -1
  23. package/dist/node/internal/{index-sNi-u40H.js → index-AWkBpPdl.js} +16 -6
  24. package/dist/node/internal/{index-PkGY1BML.js → index-VzErJ06c.js} +1 -1
  25. package/dist/{browser/internal/index-v3lMuqpK.js → node/internal/index-y-8qoZvC.js} +1 -1
  26. package/dist/node/internal/object-6KU11KDZ.js +843 -0
  27. package/dist/node/internal/object-YfG4E2oW.js +1 -0
  28. package/dist/node/src/document/schema/index.d.ts +2 -2
  29. package/dist/node/src/document-model/custom/reducers/versioning.d.ts +4 -4
  30. package/dist/node/vitest.config.d.ts +2 -0
  31. package/dist/src/document/actions/index.d.ts +3 -3
  32. package/dist/src/document/object.d.ts +63 -0
  33. package/dist/src/document/reducer.d.ts +16 -0
  34. package/dist/src/document/schema/types.d.ts +9 -12
  35. package/dist/src/document/types.d.ts +9 -0
  36. package/dist/src/document/utils/base.d.ts +7 -4
  37. package/dist/src/document/utils/index.d.ts +1 -0
  38. package/dist/test/document/undo-redo.test.d.ts +1 -0
  39. package/package.json +23 -17
  40. package/dist/browser/internal/object-U8CbkcSV.js +0 -6
  41. package/dist/browser/internal/object-YlWt1S0J.js +0 -1831
  42. package/dist/browser/jest.config.d.ts +0 -8
  43. package/dist/node/internal/object-Nz1iEXFy.js +0 -1
  44. package/dist/node/internal/object-T2hpMYZ4.js +0 -833
  45. package/dist/node/jest.config.d.ts +0 -8
@@ -1,833 +0,0 @@
1
- var mt = Object.defineProperty;
2
- var ut = (t, e, i) => e in t ? mt(t, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : t[e] = i;
3
- var w = (t, e, i) => (ut(t, typeof e != "symbol" ? e + "" : e, i), i);
4
- import dt from "json-stringify-deterministic";
5
- import { produce as M, castDraft as xt, castImmutable as gt, freeze as ft } from "immer";
6
- import { z as o } from "zod";
7
- import R from "jszip";
8
- import ht from "crypto";
9
- import E from "fs";
10
- import vt from "https";
11
- import { join as bt } from "path";
12
- const L = (t) => t != null, yt = o.any().refine((t) => L(t)), U = o.enum(["LOAD_STATE"]), J = o.enum(["PRUNE"]), $ = o.enum(["REDO"]), C = o.enum(["SET_NAME"]), B = o.enum(["UNDO"]);
13
- function jt() {
14
- return o.object({
15
- __typename: o.literal("Action").optional(),
16
- type: o.string()
17
- });
18
- }
19
- function g() {
20
- return o.literal("global").or(o.literal("local"));
21
- }
22
- function Z() {
23
- return o.union([
24
- H(),
25
- W(),
26
- G(),
27
- Q(),
28
- V()
29
- ]);
30
- }
31
- function wt() {
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()
38
- });
39
- }
40
- function H() {
41
- return o.object({
42
- input: o.lazy(() => N()),
43
- type: U,
44
- scope: g()
45
- });
46
- }
47
- function N() {
48
- return o.object({
49
- operations: o.number(),
50
- state: o.lazy(() => K())
51
- });
52
- }
53
- function K() {
54
- return o.object({
55
- data: o.unknown().nullish(),
56
- name: o.string()
57
- });
58
- }
59
- function St() {
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()
66
- });
67
- }
68
- function W() {
69
- return o.object({
70
- input: o.lazy(() => T()),
71
- type: J,
72
- scope: g()
73
- });
74
- }
75
- function T() {
76
- return o.object({
77
- end: o.number().nullish(),
78
- start: o.number().nullish()
79
- });
80
- }
81
- const A = o.number;
82
- function G() {
83
- return o.object({
84
- input: A(),
85
- type: $,
86
- scope: g()
87
- });
88
- }
89
- const z = o.string;
90
- function Q() {
91
- return o.object({
92
- input: z(),
93
- type: C,
94
- scope: o.literal("global")
95
- });
96
- }
97
- function Ot() {
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()
105
- });
106
- }
107
- const F = o.number;
108
- function V() {
109
- return o.object({
110
- input: F(),
111
- type: B,
112
- scope: g()
113
- });
114
- }
115
- const pe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
116
- __proto__: null,
117
- ActionSchema: jt,
118
- BaseActionSchema: Z,
119
- DocumentFileSchema: wt,
120
- LoadStateActionInputSchema: N,
121
- LoadStateActionSchema: H,
122
- LoadStateActionStateInputSchema: K,
123
- Load_StateSchema: U,
124
- OperationSchema: St,
125
- OperationScopeSchema: g,
126
- PruneActionInputSchema: T,
127
- PruneActionSchema: W,
128
- PruneSchema: J,
129
- RedoActionInputSchema: A,
130
- RedoActionSchema: G,
131
- RedoSchema: $,
132
- SetNameActionInputSchema: z,
133
- SetNameActionSchema: Q,
134
- SetNameOperationSchema: Ot,
135
- Set_NameSchema: C,
136
- UndoActionInputSchema: F,
137
- UndoActionSchema: V,
138
- UndoSchema: B,
139
- definedNonNullAnySchema: yt,
140
- isDefinedNonNullAny: L
141
- }, Symbol.toStringTag, { value: "Module" }));
142
- function _t(t, e) {
143
- return { ...t, name: e };
144
- }
145
- function kt(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
- ...O(
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
- ...O(
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 Et(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), c = n.slice(0, s), m = n.slice(p), u = O(
197
- t.initialState,
198
- {
199
- ...t.operations,
200
- [a]: c.concat(l)
201
- },
202
- i
203
- ), { name: d, state: r } = u, b = c.length, y = c.length ? c[c.length - 1].timestamp : m.length ? m[0].timestamp : (/* @__PURE__ */ new Date()).toISOString();
204
- return O(
205
- t.initialState,
206
- {
207
- ...t.operations,
208
- [a]: [
209
- ...c,
210
- {
211
- ...I(
212
- { name: d, state: r },
213
- l.length
214
- ),
215
- timestamp: y,
216
- index: b,
217
- hash: nt({ state: r }, "global")
218
- },
219
- ...m.map((D, j) => ({
220
- ...D,
221
- index: b + j + 1
222
- }))
223
- ]
224
- },
225
- i
226
- );
227
- }
228
- function Nt(t, e) {
229
- return {
230
- ...t,
231
- name: e.name,
232
- state: e.state ?? { global: {}, local: {} }
233
- };
234
- }
235
- const X = "SET_NAME", f = "UNDO", h = "REDO", v = "PRUNE", Y = "LOAD_STATE";
236
- function Tt(t) {
237
- return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
238
- }
239
- function _() {
240
- this._types = /* @__PURE__ */ Object.create(null), this._extensions = /* @__PURE__ */ Object.create(null);
241
- for (let t = 0; t < arguments.length; t++)
242
- this.define(arguments[t]);
243
- this.define = this.define.bind(this), this.getType = this.getType.bind(this), this.getExtension = this.getExtension.bind(this);
244
- }
245
- _.prototype.define = function(t, e) {
246
- for (let i in t) {
247
- let a = t[i].map(function(n) {
248
- return n.toLowerCase();
249
- });
250
- i = i.toLowerCase();
251
- for (let n = 0; n < a.length; n++) {
252
- const s = a[n];
253
- if (s[0] !== "*") {
254
- if (!e && s in this._types)
255
- throw new Error(
256
- '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 + '".'
257
- );
258
- this._types[s] = i;
259
- }
260
- }
261
- if (e || !this._extensions[i]) {
262
- const n = a[0];
263
- this._extensions[i] = n[0] !== "*" ? n : n.substr(1);
264
- }
265
- }
266
- };
267
- _.prototype.getType = function(t) {
268
- t = String(t);
269
- let e = t.replace(/^.*[/\\]/, "").toLowerCase(), i = e.replace(/^.*\./, "").toLowerCase(), a = e.length < t.length;
270
- return (i.length < e.length - 1 || !a) && this._types[i] || null;
271
- };
272
- _.prototype.getExtension = function(t) {
273
- return t = /^\s*([^;\s]*)/.test(t) && RegExp.$1, t && this._extensions[t.toLowerCase()] || null;
274
- };
275
- var At = _, zt = { "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 Ft = At;
277
- var It = new Ft(zt);
278
- const Mt = /* @__PURE__ */ Tt(It);
279
- function Pt(t, e, i) {
280
- const a = bt(t, e);
281
- return E.mkdirSync(t, { recursive: !0 }), new Promise((n, s) => {
282
- try {
283
- E.writeFile(a, i, {}, (p) => {
284
- p ? s(p) : n(a);
285
- });
286
- } catch (p) {
287
- s(p);
288
- }
289
- });
290
- }
291
- function tt(t) {
292
- return E.readFileSync(t);
293
- }
294
- function qt(t) {
295
- return new Promise((e, i) => {
296
- vt.get(t, (a) => {
297
- const n = [], s = a.headers["content-type"];
298
- a.on("data", (p) => {
299
- n.push(p);
300
- }), a.on("end", () => {
301
- e({ buffer: Buffer.concat(n), mimeType: s });
302
- });
303
- }).on("error", (a) => {
304
- i(a);
305
- });
306
- });
307
- }
308
- const Rt = async (t) => tt(t), k = (t, e = "sha1") => ht.createHash(e).update(t).digest("base64"), et = async (t) => {
309
- const e = new R(), { name: i, revision: a, documentType: n, created: s, lastModified: p } = t, l = {
310
- name: i,
311
- revision: a,
312
- documentType: n,
313
- created: s,
314
- lastModified: p
315
- };
316
- return e.file("header.json", JSON.stringify(l, null, 2)), e.file(
317
- "state.json",
318
- JSON.stringify(t.initialState || {}, null, 2)
319
- ), e.file("operations.json", JSON.stringify(t.operations, null, 2)), Object.keys(t.attachments).forEach((m) => {
320
- const { data: u, ...d } = t.attachments[m];
321
- e.file(m, u, {
322
- base64: !0,
323
- createFolders: !0,
324
- comment: JSON.stringify(d)
325
- });
326
- }), e;
327
- }, Lt = async (t, e, i, a) => {
328
- const s = await (await et(t)).generateAsync({
329
- type: "uint8array",
330
- streamFiles: !0
331
- }), p = a ?? t.name, l = `.${i}.zip`;
332
- return Pt(
333
- e,
334
- p.endsWith(l) ? p : `${p}${l}`,
335
- s
336
- );
337
- }, le = async (t, e) => {
338
- const a = await (await et(t)).generateAsync({ type: "blob" }), n = await e.createWritable();
339
- await n.write(a), await n.close();
340
- }, P = async (t, e) => {
341
- const i = tt(t);
342
- return Ut(i, e);
343
- }, Ut = async (t, e) => {
344
- const i = new R();
345
- return await i.loadAsync(t), Jt(i, e);
346
- };
347
- async function Jt(t, e) {
348
- const i = t.file("state.json");
349
- if (!i)
350
- throw new Error("Initial state not found");
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)
356
- throw new Error("Operations history not found");
357
- const c = JSON.parse(
358
- await l.async("string")
359
- );
360
- let m = ot(
361
- n,
362
- c,
363
- e,
364
- void 0,
365
- p
366
- );
367
- return p && (m = {
368
- ...m,
369
- ...p
370
- }), m;
371
- }
372
- function it(t) {
373
- const e = t.replace(/^.*\./, "") || void 0, i = t.replace(/^.*[/\\]/, "") || void 0;
374
- return { extension: e, fileName: i };
375
- }
376
- async function ce(t) {
377
- const { buffer: e, mimeType: i = "application/octet-stream" } = await qt(t), a = it(t), n = e.toString("base64");
378
- return {
379
- data: n,
380
- hash: k(n),
381
- mimeType: i,
382
- ...a
383
- };
384
- }
385
- async function re(t) {
386
- const e = await Rt(t), i = Mt.getType(t) || "application/octet-stream", a = it(t), n = e.toString("base64");
387
- return { data: n, hash: k(n), mimeType: i, ...a };
388
- }
389
- function $t(t, e) {
390
- const i = t.revision[e.scope];
391
- return [f, h, v].includes(e.type) ? i : i + 1;
392
- }
393
- function Ct(t, e) {
394
- return {
395
- ...t,
396
- revision: {
397
- ...t.revision,
398
- [e.scope]: $t(t, e)
399
- },
400
- lastModified: (/* @__PURE__ */ new Date()).toISOString()
401
- };
402
- }
403
- function Bt(t, e, i = 0) {
404
- if ([f, h, v].includes(e.type))
405
- return t;
406
- const { scope: a } = e, n = t.operations[a].slice(
407
- 0,
408
- t.revision[a]
409
- );
410
- return n.push({
411
- ...e,
412
- index: n.length,
413
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
414
- hash: "",
415
- scope: a,
416
- skip: i
417
- }), {
418
- ...t,
419
- operations: { ...t.operations, [a]: n }
420
- };
421
- }
422
- function Zt(t, e, i = 0) {
423
- let a = Bt(t, e, i);
424
- return a = Ct(a, e), a;
425
- }
426
- function Ht(t, e, i) {
427
- switch (Z().parse(e), e.type) {
428
- case X:
429
- return _t(t, e.input);
430
- case f:
431
- return kt(t, e, i);
432
- case h:
433
- return Dt(t, e, i);
434
- case v:
435
- return Et(t, e, i);
436
- case Y:
437
- return Nt(t, e.input.state);
438
- default:
439
- return t;
440
- }
441
- }
442
- function at(t, e, i, a, n = {}) {
443
- const {
444
- skip: s = 0
445
- } = n;
446
- let p = t;
447
- return q(e) && (p = Ht(p, e, i)), p = Zt(p, e, s), p = M(p, (l) => {
448
- const c = i(l.state, e, a);
449
- if (c)
450
- return xt({
451
- ...p,
452
- state: c
453
- });
454
- }), M(p, (l) => {
455
- if ([f, h, v].includes(e.type))
456
- return l;
457
- const c = e.scope || "global";
458
- l.operations[c][l.operations[c].length - 1].hash = nt(l, c), !q(e) && e.attachments && e.attachments.forEach((m) => {
459
- const { hash: u, ...d } = m;
460
- l.attachments[u] = {
461
- ...d
462
- };
463
- });
464
- });
465
- }
466
- function q(t) {
467
- return [X, f, h, v, Y].includes(t.type);
468
- }
469
- function x(t, e, i, a, n = "global") {
470
- if (!t)
471
- throw new Error("Empty action type");
472
- if (typeof t != "string")
473
- throw new Error(`Invalid action type: ${t}`);
474
- const s = { type: t, input: e, scope: n };
475
- i && (s.attachments = i);
476
- try {
477
- a == null || a().parse(s.input);
478
- } catch (p) {
479
- throw new Error(`Invalid action input: ${p}`);
480
- }
481
- return s;
482
- }
483
- function Kt(t, e = at) {
484
- return (i, a, n, s) => e(i, a, t, n, s);
485
- }
486
- const Wt = (t, e) => ({
487
- name: "",
488
- documentType: "",
489
- revision: {
490
- global: 0,
491
- local: 0
492
- },
493
- created: (/* @__PURE__ */ new Date()).toISOString(),
494
- lastModified: (/* @__PURE__ */ new Date()).toISOString(),
495
- attachments: {},
496
- ...t,
497
- state: (e == null ? void 0 : e(t == null ? void 0 : t.state)) ?? (t == null ? void 0 : t.state) ?? { global: {}, local: {} }
498
- }), Gt = (t, e) => {
499
- const i = Wt(
500
- t,
501
- e
502
- );
503
- return {
504
- ...i,
505
- initialState: i,
506
- operations: { global: [], local: [] }
507
- };
508
- }, nt = (t, e = "global") => k(dt(t.state[e])), me = (t, e = 1e3) => {
509
- const i = Math.random() * e;
510
- return k(`${(t ?? /* @__PURE__ */ new Date()).toISOString()}${i}`);
511
- };
512
- function S(t) {
513
- return gt(ft(t, !0));
514
- }
515
- function Qt(t) {
516
- const e = [...t];
517
- let i = 0, a = e.length > 0 ? e[e.length - 1].index : 0;
518
- const n = [];
519
- for (const s of e.reverse()) {
520
- if (i > 0) {
521
- const l = a - s.index;
522
- i -= l;
523
- }
524
- if (i < 0)
525
- throw new Error("Invalid operation index, missing operations");
526
- const p = {
527
- ignore: i > 0,
528
- operation: s
529
- };
530
- s.skip > 0 && (i = i + (s.skip + 1)), a = s.index, n.push(p);
531
- }
532
- return n.reverse();
533
- }
534
- function ue(t) {
535
- return Object.values(t).flatMap((e) => e).sort(
536
- (e, i) => new Date(e.timestamp).getTime() - new Date(i.timestamp).getTime()
537
- );
538
- }
539
- function Vt(t) {
540
- return Object.values(t).flatMap((e) => e).sort(
541
- (e, i) => new Date(e.operation.timestamp).getTime() - new Date(i.operation.timestamp).getTime()
542
- );
543
- }
544
- function O(t, e, i, a, n, s = at) {
545
- const p = Kt(i, s);
546
- return ot(
547
- t,
548
- e,
549
- p,
550
- a,
551
- n
552
- );
553
- }
554
- function ot(t, e, i, a, n) {
555
- const s = Gt(t), p = Object.keys(e).reduce((u, d) => {
556
- const r = d;
557
- return {
558
- ...u,
559
- [r]: e[r].slice(0, n == null ? void 0 : n.revision[r])
560
- };
561
- }, {}), l = Object.keys(p).reduce((u, d) => {
562
- const r = d;
563
- return {
564
- ...u,
565
- [r]: Qt(p[r])
566
- };
567
- }, {}), c = Vt(l).reduce(
568
- (u, { ignore: d, operation: r }) => d ? i(
569
- u,
570
- rt(r.scope),
571
- a,
572
- { skip: r.skip }
573
- ) : i(u, r, a),
574
- s
575
- ), m = Object.keys(
576
- c.operations
577
- ).reduce(
578
- (u, d) => {
579
- const r = d, b = n && n.revision[r] < e[r].length ? e[r].slice(n.revision[r]) : [];
580
- return {
581
- ...u,
582
- [r]: [
583
- ...c.operations[r].map((y, D) => {
584
- var j;
585
- return {
586
- ...y,
587
- timestamp: ((j = e[r][D]) == null ? void 0 : j.timestamp) ?? y.timestamp
588
- };
589
- }),
590
- ...b
591
- ]
592
- };
593
- },
594
- { global: [], local: [] }
595
- );
596
- return { ...c, operations: m };
597
- }
598
- const st = (t) => x(
599
- "SET_NAME",
600
- t,
601
- void 0,
602
- z,
603
- void 0
604
- ), pt = (t = 1, e = "global") => x(
605
- "UNDO",
606
- t,
607
- void 0,
608
- F,
609
- e
610
- ), lt = (t = 1, e = "global") => x(
611
- "REDO",
612
- t,
613
- void 0,
614
- A,
615
- e
616
- ), ct = (t, e, i = "global") => x(
617
- "PRUNE",
618
- { start: t, end: e },
619
- void 0,
620
- T,
621
- i
622
- ), I = (t, e) => x(
623
- "LOAD_STATE",
624
- { state: t, operations: e },
625
- void 0,
626
- N
627
- ), rt = (t = "global") => x(
628
- "NOOP",
629
- {},
630
- void 0,
631
- void 0,
632
- t
633
- ), de = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
634
- __proto__: null,
635
- loadState: I,
636
- noop: rt,
637
- prune: ct,
638
- redo: lt,
639
- setName: st,
640
- undo: pt
641
- }, Symbol.toStringTag, { value: "Module" }));
642
- class xe {
643
- /**
644
- * Constructs a BaseDocument instance with an initial state.
645
- * @param reducer - The reducer function that updates the state.
646
- * @param document - The initial state of the document.
647
- */
648
- constructor(e, i, a) {
649
- w(this, "_document");
650
- w(this, "_reducer");
651
- w(this, "_signalDispatch");
652
- this._reducer = e, this._document = i, this._signalDispatch = a;
653
- }
654
- /**
655
- * Dispatches an action to update the state of the document.
656
- * @param action - The action to dispatch.
657
- * @returns The Document instance.
658
- */
659
- dispatch(e, i) {
660
- return this._document = this._reducer(
661
- this._document,
662
- e,
663
- this._signalDispatch,
664
- i
665
- ), this;
666
- }
667
- /**
668
- * Saves the state of the document to a file.
669
- * @param path - The file path where the state should be saved.
670
- * @param extension - The file extension to use when saving the state.
671
- * @returns The file path where the state was saved.
672
- */
673
- saveToFile(e, i, a) {
674
- return Lt(this._document, e, i, a);
675
- }
676
- /**
677
- * Loads the state of the document from a file.
678
- * @param path - The file path where the state is stored.
679
- */
680
- async loadFromFile(e) {
681
- this._document = await P(e, this._reducer);
682
- }
683
- /**
684
- * Loads the state of the document from a file and returns it.
685
- * @param path - The file path where the state is stored.
686
- * @param reducer - The reducer function that updates the state.
687
- * @returns The state of the document.
688
- */
689
- static async stateFromFile(e, i) {
690
- return await P(e, i);
691
- }
692
- /**
693
- * Gets the current state of the document.
694
- */
695
- get state() {
696
- return S(this._document.state);
697
- }
698
- /**
699
- * Gets the list of operations performed on the document.
700
- */
701
- get operations() {
702
- return S(this._document.operations);
703
- }
704
- /**
705
- * Gets the name of the document.
706
- */
707
- get name() {
708
- return this._document.name;
709
- }
710
- /**
711
- * Gets the type of document.
712
- */
713
- get documentType() {
714
- return this._document.documentType;
715
- }
716
- /**
717
- * Gets the timestamp of the date the document was created.
718
- */
719
- get created() {
720
- return this._document.created;
721
- }
722
- /**
723
- * Gets the timestamp of the date the document was last modified.
724
- */
725
- get lastModified() {
726
- return this._document.lastModified;
727
- }
728
- /**
729
- * Gets the global revision number of the document.
730
- */
731
- get revision() {
732
- return this._document.revision.global;
733
- }
734
- getRevision(e) {
735
- return this._document.revision[e];
736
- }
737
- /**
738
- * Gets the initial state of the document.
739
- */
740
- get initialState() {
741
- return S(this._document.initialState);
742
- }
743
- /**
744
- * Returns the current document as an object
745
- */
746
- toDocument() {
747
- return S(this._document);
748
- }
749
- /**
750
- * Gets the attachment associated with the given key.
751
- * @param attachment - The key of the attachment to retrieve.
752
- */
753
- getAttachment(e) {
754
- return this._document.attachments[e];
755
- }
756
- /**
757
- * Sets the name of the document.
758
- * @param name - The new name of the document.
759
- */
760
- setName(e) {
761
- return this.dispatch(st(e)), this;
762
- }
763
- /**
764
- * Reverts a number of actions from the document.
765
- * @param count - The number of actions to revert.
766
- */
767
- undo(e) {
768
- return this.dispatch(pt(e)), this;
769
- }
770
- /**
771
- * Reapplies a number of actions to the document.
772
- * @param count - The number of actions to reapply.
773
- */
774
- redo(e) {
775
- return this.dispatch(lt(e)), this;
776
- }
777
- /**
778
- * Removes a range of operations from the document.
779
- * @param start - The starting index of the range to remove.
780
- * @param end - The ending index of the range to remove.
781
- */
782
- prune(e, i) {
783
- return this.dispatch(ct(e, i)), this;
784
- }
785
- /**
786
- * Loads a document state and a set of operations.
787
- * @param state - The state to load.
788
- * @param operations - The operations to apply to the document.
789
- */
790
- loadState(e, i) {
791
- return this.dispatch(I(e, i)), this;
792
- }
793
- }
794
- function ge(t, e) {
795
- e.forEach((i) => {
796
- Object.getOwnPropertyNames(i.prototype).forEach((a) => {
797
- Object.defineProperty(
798
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
799
- t.prototype,
800
- a,
801
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
802
- Object.getOwnPropertyDescriptor(i.prototype, a) || /* @__PURE__ */ Object.create(null)
803
- );
804
- });
805
- });
806
- }
807
- export {
808
- xe as B,
809
- Wt as a,
810
- Gt as b,
811
- Kt as c,
812
- le as d,
813
- Ut as e,
814
- x as f,
815
- ge as g,
816
- de as h,
817
- q as i,
818
- et as j,
819
- re as k,
820
- P as l,
821
- ce as m,
822
- nt as n,
823
- me as o,
824
- Qt as p,
825
- ot as q,
826
- S as r,
827
- Lt as s,
828
- O as t,
829
- Vt as u,
830
- ue as v,
831
- at as w,
832
- pe as z
833
- };