document-model 1.0.25 → 1.0.27

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 (40) 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-TAPWNyA9.js → index-99f8b333.js} +16 -6
  8. package/dist/{node/internal/index-FmPDtpIY.js → browser/internal/index-df4df518.js} +1 -1
  9. package/dist/{node/internal/index-lh4jt_0f.js → browser/internal/index-e019b5aa.js} +1 -1
  10. package/dist/browser/internal/{index-3haD_DrE.js → index-ff67644b.js} +1 -1
  11. package/dist/browser/internal/{object-jGU_rY7z.js → object-4b5800c0.js} +348 -352
  12. package/dist/browser/internal/{object-1BuggAcr.js → object-be1b0c52.js} +2 -2
  13. package/dist/browser/src/document/schema/index.d.ts +2 -2
  14. package/dist/browser/src/document/schema/types.d.ts +8 -12
  15. package/dist/browser/src/document/signal.d.ts +1 -0
  16. package/dist/browser/src/document/utils/index.d.ts +1 -0
  17. package/dist/browser/src/document-model/custom/reducers/versioning.d.ts +4 -4
  18. package/dist/browser/vitest.config.d.ts +2 -0
  19. package/dist/node/document-model.cjs +1 -1
  20. package/dist/node/document-model.js +3 -3
  21. package/dist/node/document.cjs +1 -1
  22. package/dist/node/document.js +3 -3
  23. package/dist/node/index.cjs +1 -1
  24. package/dist/node/index.js +4 -4
  25. package/dist/{browser/internal/index-7bSWIChK.js → node/internal/index-2d55ed8c.js} +1 -1
  26. package/dist/node/internal/{index-pZl431ni.js → index-433d6a9b.js} +1 -1
  27. package/dist/{browser/internal/index-DQNkZhvL.js → node/internal/index-78c035e1.js} +1 -1
  28. package/dist/node/internal/{index-GpOpKG2W.js → index-a46dcf07.js} +17 -7
  29. package/dist/node/internal/{object-evJm9vYN.js → object-305e4c59.js} +244 -248
  30. package/dist/node/internal/object-ff6617a2.js +1 -0
  31. package/dist/node/src/document/schema/index.d.ts +2 -2
  32. package/dist/node/src/document/schema/types.d.ts +8 -12
  33. package/dist/node/src/document/signal.d.ts +1 -0
  34. package/dist/node/src/document/utils/index.d.ts +1 -0
  35. package/dist/node/src/document-model/custom/reducers/versioning.d.ts +4 -4
  36. package/dist/node/vitest.config.d.ts +2 -0
  37. package/package.json +23 -17
  38. package/dist/browser/jest.config.d.ts +0 -8
  39. package/dist/node/internal/object-pZF_UDWv.js +0 -1
  40. package/dist/node/jest.config.d.ts +0 -8
@@ -4,11 +4,11 @@ var j = (t, e, i) => (ft(t, typeof e != "symbol" ? e + "" : e, i), i);
4
4
  import { produce as S, castDraft as D, castImmutable as gt, freeze as ht } from "immer";
5
5
  import bt from "json-stringify-deterministic";
6
6
  import { z as s } from "zod";
7
- import $ from "jszip";
8
7
  import vt from "crypto";
9
8
  import N from "fs";
10
9
  import yt from "https";
11
10
  import { join as wt } from "path";
11
+ import $ from "jszip";
12
12
  const J = (t) => t != null, jt = s.any().refine((t) => J(t)), B = s.enum(["LOAD_STATE"]), Z = s.enum(["PRUNE"]), H = s.enum(["REDO"]), K = s.enum(["SET_NAME"]), W = s.enum(["UNDO"]);
13
13
  function Ot() {
14
14
  return s.object({
@@ -236,7 +236,7 @@ function At(t, e, i) {
236
236
  ),
237
237
  timestamp: v,
238
238
  index: r,
239
- hash: ct({ state: d }, "global")
239
+ hash: st({ state: d }, "global")
240
240
  },
241
241
  ...l.map((f, E) => ({
242
242
  ...f,
@@ -255,174 +255,21 @@ function Tt(t, e) {
255
255
  };
256
256
  }
257
257
  const it = "SET_NAME", g = "UNDO", h = "REDO", w = "PRUNE", at = "LOAD_STATE";
258
- function zt(t) {
259
- return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
260
- }
261
- function k() {
262
- this._types = /* @__PURE__ */ Object.create(null), this._extensions = /* @__PURE__ */ Object.create(null);
263
- for (let t = 0; t < arguments.length; t++)
264
- this.define(arguments[t]);
265
- this.define = this.define.bind(this), this.getType = this.getType.bind(this), this.getExtension = this.getExtension.bind(this);
266
- }
267
- k.prototype.define = function(t, e) {
268
- for (let i in t) {
269
- let a = t[i].map(function(n) {
270
- return n.toLowerCase();
271
- });
272
- i = i.toLowerCase();
273
- for (let n = 0; n < a.length; n++) {
274
- const p = a[n];
275
- if (p[0] !== "*") {
276
- if (!e && p in this._types)
277
- throw new Error(
278
- 'Attempt to change mapping for "' + p + '" extension from "' + this._types[p] + '" to "' + i + '". Pass `force=true` to allow this, otherwise remove "' + p + '" from the list of extensions for "' + i + '".'
279
- );
280
- this._types[p] = i;
281
- }
282
- }
283
- if (e || !this._extensions[i]) {
284
- const n = a[0];
285
- this._extensions[i] = n[0] !== "*" ? n : n.substr(1);
286
- }
287
- }
288
- };
289
- k.prototype.getType = function(t) {
290
- t = String(t);
291
- let e = t.replace(/^.*[/\\]/, "").toLowerCase(), i = e.replace(/^.*\./, "").toLowerCase(), a = e.length < t.length;
292
- return (i.length < e.length - 1 || !a) && this._types[i] || null;
293
- };
294
- k.prototype.getExtension = function(t) {
295
- return t = /^\s*([^;\s]*)/.test(t) && RegExp.$1, t && this._extensions[t.toLowerCase()] || null;
296
- };
297
- var It = k, Ft = { "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"] };
298
- let Rt = It;
299
- var Pt = new Rt(Ft);
300
- const Mt = /* @__PURE__ */ zt(Pt);
301
- function qt(t, e, i) {
302
- const a = wt(t, e);
303
- return N.mkdirSync(t, { recursive: !0 }), new Promise((n, p) => {
304
- try {
305
- N.writeFile(a, i, {}, (o) => {
306
- o ? p(o) : n(a);
307
- });
308
- } catch (o) {
309
- p(o);
310
- }
311
- });
312
- }
313
- function nt(t) {
314
- return N.readFileSync(t);
315
- }
316
- function Lt(t) {
317
- return new Promise((e, i) => {
318
- yt.get(t, (a) => {
319
- const n = [], p = a.headers["content-type"];
320
- a.on("data", (o) => {
321
- n.push(o);
322
- }), a.on("end", () => {
323
- e({ buffer: Buffer.concat(n), mimeType: p });
324
- });
325
- }).on("error", (a) => {
326
- i(a);
327
- });
328
- });
329
- }
330
- const Ut = async (t) => nt(t), _ = (t, e = "sha1") => vt.createHash(e).update(t).digest("base64"), ot = async (t) => {
331
- const e = new $(), { name: i, revision: a, documentType: n, created: p, lastModified: o } = t, c = {
332
- name: i,
333
- revision: a,
334
- documentType: n,
335
- created: p,
336
- lastModified: o
337
- };
338
- return e.file("header.json", JSON.stringify(c, null, 2)), e.file(
339
- "state.json",
340
- JSON.stringify(t.initialState || {}, null, 2)
341
- ), e.file("operations.json", JSON.stringify(t.operations, null, 2)), Object.keys(t.attachments).forEach((l) => {
342
- const { data: x, ...m } = t.attachments[l];
343
- e.file(l, x, {
344
- base64: !0,
345
- createFolders: !0,
346
- comment: JSON.stringify(m)
347
- });
348
- }), e;
349
- }, Ct = async (t, e, i, a) => {
350
- const p = await (await ot(t)).generateAsync({
351
- type: "uint8array",
352
- streamFiles: !0
353
- }), o = a ?? t.name, c = `.${i}.zip`;
354
- return qt(
355
- e,
356
- o.endsWith(c) ? o : `${o}${c}`,
357
- p
358
- );
359
- }, me = async (t, e) => {
360
- const a = await (await ot(t)).generateAsync({ type: "blob" }), n = await e.createWritable();
361
- await n.write(a), await n.close();
362
- }, L = async (t, e) => {
363
- const i = nt(t);
364
- return $t(i, e);
365
- }, $t = async (t, e) => {
366
- const i = new $();
367
- return await i.loadAsync(t), Jt(i, e);
368
- };
369
- async function Jt(t, e) {
370
- const i = t.file("state.json");
371
- if (!i)
372
- throw new Error("Initial state not found");
373
- const a = await i.async("string"), n = JSON.parse(a), p = t.file("header.json");
374
- let o;
375
- p && (o = JSON.parse(await p.async("string")));
376
- const c = t.file("operations.json");
377
- if (!c)
378
- throw new Error("Operations history not found");
379
- const u = JSON.parse(
380
- await c.async("string")
381
- );
382
- let l = lt(
383
- n,
384
- u,
385
- e,
386
- void 0,
387
- o
388
- );
389
- return o && (l = {
390
- ...l,
391
- ...o
392
- }), l;
393
- }
394
- function st(t) {
395
- const e = t.replace(/^.*\./, "") || void 0, i = t.replace(/^.*[/\\]/, "") || void 0;
396
- return { extension: e, fileName: i };
397
- }
398
- async function ue(t) {
399
- const { buffer: e, mimeType: i = "application/octet-stream" } = await Lt(t), a = st(t), n = e.toString("base64");
400
- return {
401
- data: n,
402
- hash: _(n),
403
- mimeType: i,
404
- ...a
405
- };
406
- }
407
- async function de(t) {
408
- const e = await Ut(t), i = Mt.getType(t) || "application/octet-stream", a = st(t), n = e.toString("base64");
409
- return { data: n, hash: _(n), mimeType: i, ...a };
410
- }
411
- function Bt(t, e) {
258
+ function zt(t, e) {
412
259
  const i = t.revision[e.scope];
413
260
  return [g, h, w].includes(e.type) ? i : i + 1;
414
261
  }
415
- function Zt(t, e) {
262
+ function It(t, e) {
416
263
  return {
417
264
  ...t,
418
265
  revision: {
419
266
  ...t.revision,
420
- [e.scope]: Bt(t, e)
267
+ [e.scope]: zt(t, e)
421
268
  },
422
269
  lastModified: (/* @__PURE__ */ new Date()).toISOString()
423
270
  };
424
271
  }
425
- function Ht(t, e, i = 0) {
272
+ function Ft(t, e, i = 0) {
426
273
  if ([g, h, w].includes(e.type))
427
274
  return t;
428
275
  const { scope: a } = e, n = t.operations[a].slice(
@@ -441,11 +288,11 @@ function Ht(t, e, i = 0) {
441
288
  operations: { ...t.operations, [a]: n }
442
289
  };
443
290
  }
444
- function Kt(t, e, i = 0) {
445
- let a = Ht(t, e, i);
446
- return a = Zt(a, e), a;
291
+ function Rt(t, e, i = 0) {
292
+ let a = Ft(t, e, i);
293
+ return a = It(a, e), a;
447
294
  }
448
- function Wt(t, e, i) {
295
+ function Pt(t, e, i) {
449
296
  switch (V().parse(e), e.type) {
450
297
  case it:
451
298
  return Et(t, e.input);
@@ -457,7 +304,7 @@ function Wt(t, e, i) {
457
304
  return t;
458
305
  }
459
306
  }
460
- function Vt(t, e, i) {
307
+ function Mt(t, e, i) {
461
308
  switch (e.type) {
462
309
  case g:
463
310
  return Dt(t, e, i);
@@ -467,18 +314,18 @@ function Vt(t, e, i) {
467
314
  return { document: t, action: e, skip: i };
468
315
  }
469
316
  }
470
- function pt(t, e, i, a, n = {}) {
317
+ function nt(t, e, i, a, n = {}) {
471
318
  const { skip: p, ignoreSkipOperations: o = !1 } = n;
472
319
  let c = { ...e }, u = p || 0, l = t, x = [...t.clipboard];
473
- if (U(c)) {
320
+ if (L(c)) {
474
321
  const {
475
322
  skip: m,
476
323
  action: d,
477
324
  document: r
478
- } = Vt(t, c, u);
325
+ } = Mt(t, c, u);
479
326
  c = d, u = m, l = r, x = [...l.clipboard];
480
327
  }
481
- return C(c) && (l = Wt(l, c, i)), u > 0 && !o && (l = A(
328
+ return U(c) && (l = Pt(l, c, i)), u > 0 && !o && (l = A(
482
329
  l.initialState,
483
330
  l.operations,
484
331
  i,
@@ -486,12 +333,12 @@ function pt(t, e, i, a, n = {}) {
486
333
  void 0,
487
334
  void 0,
488
335
  { [c.scope]: u }
489
- )), l = Kt(l, c, u), l = S(l, (m) => {
336
+ )), l = Rt(l, c, u), l = S(l, (m) => {
490
337
  const d = i(
491
338
  m.state,
492
339
  c,
493
340
  a
494
- ), r = U(e) ? [...x] : [];
341
+ ), r = L(e) ? [...x] : [];
495
342
  if (d)
496
343
  return D({
497
344
  ...l,
@@ -503,7 +350,7 @@ function pt(t, e, i, a, n = {}) {
503
350
  if ([g, h, w].includes(c.type))
504
351
  return m;
505
352
  const d = c.scope || "global";
506
- m.operations[d][m.operations[d].length - 1].hash = ct(m, d), !C(c) && c.attachments && c.attachments.forEach((r) => {
353
+ m.operations[d][m.operations[d].length - 1].hash = st(m, d), !U(c) && c.attachments && c.attachments.forEach((r) => {
507
354
  const { hash: v, ...f } = r;
508
355
  m.attachments[v] = {
509
356
  ...f
@@ -511,10 +358,40 @@ function pt(t, e, i, a, n = {}) {
511
358
  });
512
359
  });
513
360
  }
514
- function U(t) {
361
+ function qt(t, e, i) {
362
+ const a = wt(t, e);
363
+ return N.mkdirSync(t, { recursive: !0 }), new Promise((n, p) => {
364
+ try {
365
+ N.writeFile(a, i, {}, (o) => {
366
+ o ? p(o) : n(a);
367
+ });
368
+ } catch (o) {
369
+ p(o);
370
+ }
371
+ });
372
+ }
373
+ function ot(t) {
374
+ return N.readFileSync(t);
375
+ }
376
+ function Lt(t) {
377
+ return new Promise((e, i) => {
378
+ yt.get(t, (a) => {
379
+ const n = [], p = a.headers["content-type"];
380
+ a.on("data", (o) => {
381
+ n.push(o);
382
+ }), a.on("end", () => {
383
+ e({ buffer: Buffer.concat(n), mimeType: p });
384
+ });
385
+ }).on("error", (a) => {
386
+ i(a);
387
+ });
388
+ });
389
+ }
390
+ const Ut = async (t) => ot(t), k = (t, e = "sha1") => vt.createHash(e).update(t).digest("base64");
391
+ function L(t) {
515
392
  return [g, h].includes(t.type);
516
393
  }
517
- function C(t) {
394
+ function U(t) {
518
395
  return [it, g, h, w, at].includes(t.type);
519
396
  }
520
397
  function b(t, e, i, a, n = "global") {
@@ -531,10 +408,10 @@ function b(t, e, i, a, n = "global") {
531
408
  }
532
409
  return p;
533
410
  }
534
- function Gt(t, e = pt) {
411
+ function Ct(t, e = nt) {
535
412
  return (i, a, n, p) => e(i, a, t, n, p);
536
413
  }
537
- const Qt = (t, e) => ({
414
+ const $t = (t, e) => ({
538
415
  name: "",
539
416
  documentType: "",
540
417
  revision: {
@@ -546,8 +423,8 @@ const Qt = (t, e) => ({
546
423
  attachments: {},
547
424
  ...t,
548
425
  state: (e == null ? void 0 : e(t == null ? void 0 : t.state)) ?? (t == null ? void 0 : t.state) ?? { global: {}, local: {} }
549
- }), Xt = (t, e) => {
550
- const i = Qt(
426
+ }), Jt = (t, e) => {
427
+ const i = $t(
551
428
  t,
552
429
  e
553
430
  );
@@ -557,14 +434,14 @@ const Qt = (t, e) => ({
557
434
  operations: { global: [], local: [] },
558
435
  clipboard: []
559
436
  };
560
- }, ct = (t, e = "global") => _(bt(t.state[e])), xe = (t, e = 1e3) => {
437
+ }, st = (t, e = "global") => k(bt(t.state[e])), me = (t, e = 1e3) => {
561
438
  const i = Math.random() * e;
562
- return _(`${(t ?? /* @__PURE__ */ new Date()).toISOString()}${i}`);
439
+ return k(`${(t ?? /* @__PURE__ */ new Date()).toISOString()}${i}`);
563
440
  };
564
441
  function O(t) {
565
442
  return gt(ht(t, !0));
566
443
  }
567
- function Yt(t, e) {
444
+ function Bt(t, e) {
568
445
  const i = [...t];
569
446
  let a = e || 0, n = i.length > 0 ? i[i.length - 1].index : 0;
570
447
  const p = [];
@@ -587,19 +464,19 @@ function Yt(t, e) {
587
464
  }
588
465
  return p.reverse();
589
466
  }
590
- function fe(t) {
467
+ function ue(t) {
591
468
  return Object.values(t).flatMap((e) => e).sort(
592
469
  (e, i) => new Date(e.timestamp).getTime() - new Date(i.timestamp).getTime()
593
470
  );
594
471
  }
595
- function te(t) {
472
+ function Zt(t) {
596
473
  return Object.values(t).flatMap((e) => e).sort(
597
474
  (e, i) => new Date(e.operation.timestamp).getTime() - new Date(i.operation.timestamp).getTime()
598
475
  );
599
476
  }
600
- function A(t, e, i, a, n, p = pt, o = {}) {
601
- const c = Gt(i, p);
602
- return lt(
477
+ function A(t, e, i, a, n, p = nt, o = {}) {
478
+ const c = Ct(i, p);
479
+ return pt(
603
480
  t,
604
481
  e,
605
482
  c,
@@ -608,31 +485,33 @@ function A(t, e, i, a, n, p = pt, o = {}) {
608
485
  o
609
486
  );
610
487
  }
611
- function lt(t, e, i, a, n, p = {}) {
612
- const o = Xt(t), c = Object.keys(e).reduce((m, d) => {
488
+ function pt(t, e, i, a, n, p = {}) {
489
+ const o = Jt(t), c = Object.keys(e).reduce((m, d) => {
613
490
  const r = d;
614
491
  return {
615
492
  ...m,
616
493
  [r]: e[r].slice(0, n == null ? void 0 : n.revision[r])
617
494
  };
618
- }, {}), u = Object.keys(c).reduce((m, d) => {
619
- const r = d;
620
- return {
621
- ...m,
622
- [r]: Yt(c[r], p[r])
623
- };
624
- }, {}), l = te(u).reduce(
625
- (m, { ignore: d, operation: r }) => d ? i(
626
- m,
627
- M(r.scope),
628
- a,
629
- { skip: r.skip, ignoreSkipOperations: !0 }
630
- ) : i(
631
- m,
632
- r,
633
- a,
634
- { skip: r.skip, ignoreSkipOperations: !0 }
635
- ),
495
+ }, {}), u = Object.keys(c).reduce(
496
+ (m, d) => {
497
+ const r = d;
498
+ return {
499
+ ...m,
500
+ [r]: Bt(
501
+ c[r],
502
+ p[r]
503
+ )
504
+ };
505
+ },
506
+ {}
507
+ ), l = Zt(u).reduce(
508
+ (m, { ignore: d, operation: r }) => d ? i(m, M(r.scope), a, {
509
+ skip: r.skip,
510
+ ignoreSkipOperations: !0
511
+ }) : i(m, r, a, {
512
+ skip: r.skip,
513
+ ignoreSkipOperations: !0
514
+ }),
636
515
  o
637
516
  ), x = Object.keys(
638
517
  l.operations
@@ -657,25 +536,25 @@ function lt(t, e, i, a, n, p = {}) {
657
536
  );
658
537
  return { ...l, operations: x };
659
538
  }
660
- const rt = (t) => b(
539
+ const ct = (t) => b(
661
540
  "SET_NAME",
662
541
  t,
663
542
  void 0,
664
543
  F,
665
544
  void 0
666
- ), mt = (t = 1, e = "global") => b(
545
+ ), lt = (t = 1, e = "global") => b(
667
546
  "UNDO",
668
547
  t,
669
548
  void 0,
670
549
  R,
671
550
  e
672
- ), ut = (t = 1, e = "global") => b(
551
+ ), rt = (t = 1, e = "global") => b(
673
552
  "REDO",
674
553
  t,
675
554
  void 0,
676
555
  I,
677
556
  e
678
- ), dt = (t, e, i = "global") => b(
557
+ ), mt = (t, e, i = "global") => b(
679
558
  "PRUNE",
680
559
  { start: t, end: e },
681
560
  void 0,
@@ -686,21 +565,138 @@ const rt = (t) => b(
686
565
  { state: t, operations: e },
687
566
  void 0,
688
567
  T
689
- ), M = (t = "global") => b(
690
- "NOOP",
691
- {},
692
- void 0,
693
- void 0,
694
- t
695
- ), ge = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
568
+ ), M = (t = "global") => b("NOOP", {}, void 0, void 0, t), de = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
696
569
  __proto__: null,
697
570
  loadState: P,
698
571
  noop: M,
699
- prune: dt,
700
- redo: ut,
701
- setName: rt,
702
- undo: mt
572
+ prune: mt,
573
+ redo: rt,
574
+ setName: ct,
575
+ undo: lt
703
576
  }, Symbol.toStringTag, { value: "Module" }));
577
+ function Ht(t) {
578
+ return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
579
+ }
580
+ function _() {
581
+ this._types = /* @__PURE__ */ Object.create(null), this._extensions = /* @__PURE__ */ Object.create(null);
582
+ for (let t = 0; t < arguments.length; t++)
583
+ this.define(arguments[t]);
584
+ this.define = this.define.bind(this), this.getType = this.getType.bind(this), this.getExtension = this.getExtension.bind(this);
585
+ }
586
+ _.prototype.define = function(t, e) {
587
+ for (let i in t) {
588
+ let a = t[i].map(function(n) {
589
+ return n.toLowerCase();
590
+ });
591
+ i = i.toLowerCase();
592
+ for (let n = 0; n < a.length; n++) {
593
+ const p = a[n];
594
+ if (p[0] !== "*") {
595
+ if (!e && p in this._types)
596
+ throw new Error(
597
+ 'Attempt to change mapping for "' + p + '" extension from "' + this._types[p] + '" to "' + i + '". Pass `force=true` to allow this, otherwise remove "' + p + '" from the list of extensions for "' + i + '".'
598
+ );
599
+ this._types[p] = i;
600
+ }
601
+ }
602
+ if (e || !this._extensions[i]) {
603
+ const n = a[0];
604
+ this._extensions[i] = n[0] !== "*" ? n : n.substr(1);
605
+ }
606
+ }
607
+ };
608
+ _.prototype.getType = function(t) {
609
+ t = String(t);
610
+ let e = t.replace(/^.*[/\\]/, "").toLowerCase(), i = e.replace(/^.*\./, "").toLowerCase(), a = e.length < t.length;
611
+ return (i.length < e.length - 1 || !a) && this._types[i] || null;
612
+ };
613
+ _.prototype.getExtension = function(t) {
614
+ return t = /^\s*([^;\s]*)/.test(t) && RegExp.$1, t && this._extensions[t.toLowerCase()] || null;
615
+ };
616
+ var Kt = _, Wt = { "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"] };
617
+ let Vt = Kt;
618
+ var Gt = new Vt(Wt);
619
+ const Qt = /* @__PURE__ */ Ht(Gt), ut = async (t) => {
620
+ const e = new $(), { name: i, revision: a, documentType: n, created: p, lastModified: o } = t, c = {
621
+ name: i,
622
+ revision: a,
623
+ documentType: n,
624
+ created: p,
625
+ lastModified: o
626
+ };
627
+ return e.file("header.json", JSON.stringify(c, null, 2)), e.file(
628
+ "state.json",
629
+ JSON.stringify(t.initialState || {}, null, 2)
630
+ ), e.file("operations.json", JSON.stringify(t.operations, null, 2)), Object.keys(t.attachments).forEach((l) => {
631
+ const { data: x, ...m } = t.attachments[l];
632
+ e.file(l, x, {
633
+ base64: !0,
634
+ createFolders: !0,
635
+ comment: JSON.stringify(m)
636
+ });
637
+ }), e;
638
+ }, Xt = async (t, e, i, a) => {
639
+ const p = await (await ut(t)).generateAsync({
640
+ type: "uint8array",
641
+ streamFiles: !0
642
+ }), o = a ?? t.name, c = `.${i}.zip`;
643
+ return qt(
644
+ e,
645
+ o.endsWith(c) ? o : `${o}${c}`,
646
+ p
647
+ );
648
+ }, xe = async (t, e) => {
649
+ const a = await (await ut(t)).generateAsync({ type: "blob" }), n = await e.createWritable();
650
+ await n.write(a), await n.close();
651
+ }, C = async (t, e) => {
652
+ const i = ot(t);
653
+ return Yt(i, e);
654
+ }, Yt = async (t, e) => {
655
+ const i = new $();
656
+ return await i.loadAsync(t), te(i, e);
657
+ };
658
+ async function te(t, e) {
659
+ const i = t.file("state.json");
660
+ if (!i)
661
+ throw new Error("Initial state not found");
662
+ const a = await i.async("string"), n = JSON.parse(a), p = t.file("header.json");
663
+ let o;
664
+ p && (o = JSON.parse(await p.async("string")));
665
+ const c = t.file("operations.json");
666
+ if (!c)
667
+ throw new Error("Operations history not found");
668
+ const u = JSON.parse(
669
+ await c.async("string")
670
+ );
671
+ let l = pt(
672
+ n,
673
+ u,
674
+ e,
675
+ void 0,
676
+ o
677
+ );
678
+ return o && (l = {
679
+ ...l,
680
+ ...o
681
+ }), l;
682
+ }
683
+ function dt(t) {
684
+ const e = t.replace(/^.*\./, "") || void 0, i = t.replace(/^.*[/\\]/, "") || void 0;
685
+ return { extension: e, fileName: i };
686
+ }
687
+ async function fe(t) {
688
+ const { buffer: e, mimeType: i = "application/octet-stream" } = await Lt(t), a = dt(t), n = e.toString("base64");
689
+ return {
690
+ data: n,
691
+ hash: k(n),
692
+ mimeType: i,
693
+ ...a
694
+ };
695
+ }
696
+ async function ge(t) {
697
+ const e = await Ut(t), i = Qt.getType(t) || "application/octet-stream", a = dt(t), n = e.toString("base64");
698
+ return { data: n, hash: k(n), mimeType: i, ...a };
699
+ }
704
700
  class he {
705
701
  /**
706
702
  * Constructs a BaseDocument instance with an initial state.
@@ -733,14 +729,14 @@ class he {
733
729
  * @returns The file path where the state was saved.
734
730
  */
735
731
  saveToFile(e, i, a) {
736
- return Ct(this._document, e, i, a);
732
+ return Xt(this._document, e, i, a);
737
733
  }
738
734
  /**
739
735
  * Loads the state of the document from a file.
740
736
  * @param path - The file path where the state is stored.
741
737
  */
742
738
  async loadFromFile(e) {
743
- this._document = await L(e, this._reducer);
739
+ this._document = await C(e, this._reducer);
744
740
  }
745
741
  /**
746
742
  * Loads the state of the document from a file and returns it.
@@ -749,7 +745,7 @@ class he {
749
745
  * @returns The state of the document.
750
746
  */
751
747
  static async stateFromFile(e, i) {
752
- return await L(e, i);
748
+ return await C(e, i);
753
749
  }
754
750
  /**
755
751
  * Gets the current state of the document.
@@ -820,21 +816,21 @@ class he {
820
816
  * @param name - The new name of the document.
821
817
  */
822
818
  setName(e) {
823
- return this.dispatch(rt(e)), this;
819
+ return this.dispatch(ct(e)), this;
824
820
  }
825
821
  /**
826
822
  * Reverts a number of actions from the document.
827
823
  * @param count - The number of actions to revert.
828
824
  */
829
825
  undo(e) {
830
- return this.dispatch(mt(e)), this;
826
+ return this.dispatch(lt(e)), this;
831
827
  }
832
828
  /**
833
829
  * Reapplies a number of actions to the document.
834
830
  * @param count - The number of actions to reapply.
835
831
  */
836
832
  redo(e) {
837
- return this.dispatch(ut(e)), this;
833
+ return this.dispatch(rt(e)), this;
838
834
  }
839
835
  /**
840
836
  * Removes a range of operations from the document.
@@ -842,7 +838,7 @@ class he {
842
838
  * @param end - The ending index of the range to remove.
843
839
  */
844
840
  prune(e, i) {
845
- return this.dispatch(dt(e, i)), this;
841
+ return this.dispatch(mt(e, i)), this;
846
842
  }
847
843
  /**
848
844
  * Loads a document state and a set of operations.
@@ -868,30 +864,30 @@ function be(t, e) {
868
864
  }
869
865
  export {
870
866
  he as B,
871
- Qt as a,
872
- Xt as b,
873
- Gt as c,
874
- me as d,
875
- $t as e,
867
+ $t as a,
868
+ Jt as b,
869
+ Ct as c,
870
+ xe as d,
871
+ Yt as e,
876
872
  b as f,
877
873
  be as g,
878
- ge as h,
879
- C as i,
880
- ot as j,
881
- de as k,
882
- L as l,
883
- ue as m,
884
- ct as n,
885
- xe as o,
886
- U as p,
887
- Yt as q,
874
+ de as h,
875
+ U as i,
876
+ ut as j,
877
+ ge as k,
878
+ C as l,
879
+ fe as m,
880
+ st as n,
881
+ me as o,
882
+ L as p,
883
+ Bt as q,
888
884
  O as r,
889
- Ct as s,
890
- lt as t,
885
+ Xt as s,
886
+ pt as t,
891
887
  A as u,
892
- te as v,
893
- fe as w,
894
- pt as x,
895
- Vt as y,
888
+ Zt as v,
889
+ ue as w,
890
+ nt as x,
891
+ Mt as y,
896
892
  re as z
897
893
  };