document-model 1.1.0-experimental.3 → 1.1.0-experimental.5

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 (142) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/dist/browser/cjs/document-model.js +21 -1
  3. package/dist/browser/cjs/document-model.js.map +1 -0
  4. package/dist/browser/cjs/document.js +18 -1
  5. package/dist/browser/cjs/document.js.map +1 -0
  6. package/dist/browser/cjs/index.js +18 -1
  7. package/dist/browser/cjs/index.js.map +1 -0
  8. package/dist/browser/cjs/internal/index-1o9ymQ-0.js +2339 -0
  9. package/dist/browser/cjs/internal/index-1o9ymQ-0.js.map +1 -0
  10. package/dist/browser/cjs/internal/index-BUtd0hAV.js +49 -0
  11. package/dist/browser/cjs/internal/index-BUtd0hAV.js.map +1 -0
  12. package/dist/browser/cjs/internal/object-D19DRCyd.js +4351 -0
  13. package/dist/browser/cjs/internal/object-D19DRCyd.js.map +1 -0
  14. package/dist/browser/es/document-model.js +16 -15
  15. package/dist/browser/es/document-model.js.map +1 -0
  16. package/dist/browser/es/document.js +13 -9
  17. package/dist/browser/es/document.js.map +1 -0
  18. package/dist/browser/es/index.js +13 -11
  19. package/dist/browser/es/index.js.map +1 -0
  20. package/dist/browser/es/internal/index-Chr1cTqP.js +50 -0
  21. package/dist/browser/es/internal/index-Chr1cTqP.js.map +1 -0
  22. package/dist/browser/es/internal/index-D-FR4sw9.js +2340 -0
  23. package/dist/browser/es/internal/index-D-FR4sw9.js.map +1 -0
  24. package/dist/browser/es/internal/object-BXimXhmt.js +4352 -0
  25. package/dist/browser/es/internal/object-BXimXhmt.js.map +1 -0
  26. package/dist/browser/src/document/actions/index.d.ts +2 -2
  27. package/dist/browser/src/document/object.d.ts +55 -5
  28. package/dist/browser/src/document/reducer.d.ts +30 -0
  29. package/dist/browser/src/document/types.d.ts +4 -0
  30. package/dist/browser/src/document/utils/base.d.ts +4 -3
  31. package/dist/browser/src/document/utils/document-helpers.d.ts +9 -0
  32. package/dist/node/cjs/document-model.js +25 -1
  33. package/dist/node/cjs/document-model.js.map +1 -0
  34. package/dist/node/cjs/document.js +22 -1
  35. package/dist/node/cjs/document.js.map +1 -0
  36. package/dist/node/cjs/index.js +22 -1
  37. package/dist/node/cjs/index.js.map +1 -0
  38. package/dist/node/cjs/internal/index-CPkAfk27.js +49 -0
  39. package/dist/node/cjs/internal/index-CPkAfk27.js.map +1 -0
  40. package/dist/node/cjs/internal/index-Vr62psRC.js +2343 -0
  41. package/dist/node/cjs/internal/index-Vr62psRC.js.map +1 -0
  42. package/dist/node/cjs/internal/object-Bur9CrCb.js +2353 -0
  43. package/dist/node/cjs/internal/object-Bur9CrCb.js.map +1 -0
  44. package/dist/node/es/document-model.js +15 -14
  45. package/dist/node/es/document-model.js.map +1 -0
  46. package/dist/node/es/document.js +13 -9
  47. package/dist/node/es/document.js.map +1 -0
  48. package/dist/node/es/index.js +13 -11
  49. package/dist/node/es/index.js.map +1 -0
  50. package/dist/node/es/internal/index-C1HCcE55.js +2344 -0
  51. package/dist/node/es/internal/index-C1HCcE55.js.map +1 -0
  52. package/dist/node/es/internal/index-CWmk_0Sq.js +50 -0
  53. package/dist/node/es/internal/index-CWmk_0Sq.js.map +1 -0
  54. package/dist/node/es/internal/object-BqsV7nYl.js +2354 -0
  55. package/dist/node/es/internal/object-BqsV7nYl.js.map +1 -0
  56. package/dist/node/src/document/actions/index.d.ts +2 -2
  57. package/dist/node/src/document/object.d.ts +55 -5
  58. package/dist/node/src/document/reducer.d.ts +30 -0
  59. package/dist/node/src/document/types.d.ts +4 -0
  60. package/dist/node/src/document/utils/base.d.ts +4 -3
  61. package/dist/node/src/document/utils/document-helpers.d.ts +9 -0
  62. package/dist/src/document/actions/creators.d.ts +47 -0
  63. package/dist/src/document/actions/index.d.ts +14 -0
  64. package/dist/src/document/actions/types.d.ts +15 -0
  65. package/dist/src/document/index.d.ts +6 -0
  66. package/dist/src/document/object.d.ts +1260 -0
  67. package/dist/src/document/reducer.d.ts +73 -0
  68. package/dist/src/document/schema/index.d.ts +2 -0
  69. package/dist/src/document/schema/types.d.ts +176 -0
  70. package/dist/src/document/schema/zod.d.ts +113 -0
  71. package/dist/src/document/signal.d.ts +29 -0
  72. package/dist/src/document/types.d.ts +259 -0
  73. package/dist/src/document/utils/base.d.ts +87 -0
  74. package/dist/src/document/utils/document-helpers.d.ts +62 -0
  75. package/dist/src/document/utils/file.d.ts +48 -0
  76. package/dist/src/document/utils/index.d.ts +5 -0
  77. package/dist/src/document/utils/node.d.ts +9 -0
  78. package/dist/src/document/utils/validation.d.ts +2 -0
  79. package/dist/src/document-model/custom/reducers/header.d.ts +2 -0
  80. package/dist/src/document-model/custom/reducers/module.d.ts +2 -0
  81. package/dist/src/document-model/custom/reducers/operation-error.d.ts +2 -0
  82. package/dist/src/document-model/custom/reducers/operation-example.d.ts +2 -0
  83. package/dist/src/document-model/custom/reducers/operation.d.ts +2 -0
  84. package/dist/src/document-model/custom/reducers/state.d.ts +2 -0
  85. package/dist/src/document-model/custom/reducers/versioning.d.ts +7 -0
  86. package/dist/src/document-model/custom/utils.d.ts +7 -0
  87. package/dist/src/document-model/gen/actions.d.ts +15 -0
  88. package/dist/src/document-model/gen/creators.d.ts +7 -0
  89. package/dist/src/document-model/gen/document-model.d.ts +2 -0
  90. package/dist/src/document-model/gen/header/actions.d.ts +9 -0
  91. package/dist/src/document-model/gen/header/creators.d.ts +8 -0
  92. package/dist/src/document-model/gen/header/object.d.ts +12 -0
  93. package/dist/src/document-model/gen/header/operations.d.ts +10 -0
  94. package/dist/src/document-model/gen/index.d.ts +5 -0
  95. package/dist/src/document-model/gen/module/actions.d.ts +8 -0
  96. package/dist/src/document-model/gen/module/creators.d.ts +7 -0
  97. package/dist/src/document-model/gen/module/object.d.ts +11 -0
  98. package/dist/src/document-model/gen/module/operations.d.ts +9 -0
  99. package/dist/src/document-model/gen/object.d.ts +28 -0
  100. package/dist/src/document-model/gen/operation/actions.d.ts +13 -0
  101. package/dist/src/document-model/gen/operation/creators.d.ts +12 -0
  102. package/dist/src/document-model/gen/operation/object.d.ts +16 -0
  103. package/dist/src/document-model/gen/operation/operations.d.ts +14 -0
  104. package/dist/src/document-model/gen/operation-error/actions.d.ts +10 -0
  105. package/dist/src/document-model/gen/operation-error/creators.d.ts +9 -0
  106. package/dist/src/document-model/gen/operation-error/object.d.ts +13 -0
  107. package/dist/src/document-model/gen/operation-error/operations.d.ts +11 -0
  108. package/dist/src/document-model/gen/operation-example/actions.d.ts +7 -0
  109. package/dist/src/document-model/gen/operation-example/creators.d.ts +6 -0
  110. package/dist/src/document-model/gen/operation-example/object.d.ts +10 -0
  111. package/dist/src/document-model/gen/operation-example/operations.d.ts +8 -0
  112. package/dist/src/document-model/gen/reducer.d.ts +5 -0
  113. package/dist/src/document-model/gen/schema/index.d.ts +2 -0
  114. package/dist/src/document-model/gen/schema/types.d.ts +453 -0
  115. package/dist/src/document-model/gen/schema/zod.d.ts +453 -0
  116. package/dist/src/document-model/gen/state/actions.d.ts +9 -0
  117. package/dist/src/document-model/gen/state/creators.d.ts +8 -0
  118. package/dist/src/document-model/gen/state/object.d.ts +12 -0
  119. package/dist/src/document-model/gen/state/operations.d.ts +10 -0
  120. package/dist/src/document-model/gen/types.d.ts +8 -0
  121. package/dist/src/document-model/gen/utils.d.ts +6 -0
  122. package/dist/src/document-model/gen/versioning/actions.d.ts +8 -0
  123. package/dist/src/document-model/gen/versioning/creators.d.ts +7 -0
  124. package/dist/src/document-model/gen/versioning/object.d.ts +11 -0
  125. package/dist/src/document-model/gen/versioning/operations.d.ts +9 -0
  126. package/dist/src/document-model/index.d.ts +80 -0
  127. package/dist/src/index.d.ts +25 -0
  128. package/dist/vite.config.d.ts +2 -0
  129. package/dist/vitest.config.d.ts +2 -0
  130. package/package.json +3 -1
  131. package/dist/browser/cjs/internal/index-DMRH7zDy.js +0 -1
  132. package/dist/browser/cjs/internal/index-dwAOfmBp.js +0 -22
  133. package/dist/browser/cjs/internal/object-C-PazS9q.js +0 -25
  134. package/dist/browser/es/internal/index-BVJxzkIs.js +0 -44
  135. package/dist/browser/es/internal/index-DQztOVJu.js +0 -2104
  136. package/dist/browser/es/internal/object-iTBekDVP.js +0 -2800
  137. package/dist/node/cjs/internal/index-BNFVmPew.js +0 -22
  138. package/dist/node/cjs/internal/index-FvRO8SnG.js +0 -1
  139. package/dist/node/cjs/internal/object-Xvr4kDQj.js +0 -20
  140. package/dist/node/es/internal/index-BIrQOTP_.js +0 -44
  141. package/dist/node/es/internal/index-DOpbr_uw.js +0 -2108
  142. package/dist/node/es/internal/object-C2s2eZ08.js +0 -1698
@@ -1,1698 +0,0 @@
1
- var pe = Object.defineProperty;
2
- var ce = (t, e, n) => e in t ? pe(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
- var st = (t, e, n) => (ce(t, typeof e != "symbol" ? e + "" : e, n), n);
4
- import { produce as pt, castDraft as at, castImmutable as le, freeze as me } from "immer";
5
- import { z as f } from "zod";
6
- import Dt from "jszip";
7
- import ue from "crypto";
8
- import ut from "fs";
9
- import fe from "https";
10
- import { join as de } from "path";
11
- const Tt = (t) => t != null, ge = f.any().refine((t) => Tt(t)), _t = f.enum(["LOAD_STATE"]), Nt = f.enum(["PRUNE"]), vt = f.enum(["REDO"]), It = f.enum(["SET_NAME"]), At = f.enum(["UNDO"]);
12
- function he() {
13
- return f.object({
14
- __typename: f.literal("Action").optional(),
15
- type: f.string()
16
- });
17
- }
18
- function Y() {
19
- return f.literal("global").or(f.literal("local"));
20
- }
21
- function Pt() {
22
- return f.union([
23
- Mt(),
24
- Rt(),
25
- Ct(),
26
- Ft(),
27
- Lt()
28
- ]);
29
- }
30
- function xe() {
31
- return f.object({
32
- __typename: f.literal("DocumentFile").optional(),
33
- data: f.string(),
34
- extension: f.string().nullable(),
35
- fileName: f.string().nullable(),
36
- mimeType: f.string()
37
- });
38
- }
39
- function Mt() {
40
- return f.object({
41
- input: f.lazy(() => ht()),
42
- type: _t,
43
- scope: Y()
44
- });
45
- }
46
- function ht() {
47
- return f.object({
48
- operations: f.number(),
49
- state: f.lazy(() => zt())
50
- });
51
- }
52
- function zt() {
53
- return f.object({
54
- data: f.unknown().nullish(),
55
- name: f.string()
56
- });
57
- }
58
- function ye() {
59
- return f.object({
60
- __typename: f.literal("Operation").optional(),
61
- hash: f.string(),
62
- index: f.number(),
63
- timestamp: f.string().datetime(),
64
- type: f.string()
65
- });
66
- }
67
- function Rt() {
68
- return f.object({
69
- input: f.lazy(() => xt()),
70
- type: Nt,
71
- scope: Y()
72
- });
73
- }
74
- function xt() {
75
- return f.object({
76
- end: f.number().nullish(),
77
- start: f.number().nullish()
78
- });
79
- }
80
- const yt = f.number;
81
- function Ct() {
82
- return f.object({
83
- input: yt(),
84
- type: vt,
85
- scope: Y()
86
- });
87
- }
88
- const bt = f.string;
89
- function Ft() {
90
- return f.object({
91
- input: bt(),
92
- type: It,
93
- scope: f.literal("global")
94
- });
95
- }
96
- function be() {
97
- return f.object({
98
- __typename: f.literal("SetNameOperation").optional(),
99
- hash: f.string(),
100
- index: f.number(),
101
- input: f.string(),
102
- timestamp: f.string().datetime(),
103
- type: f.string()
104
- });
105
- }
106
- const wt = f.number;
107
- function Lt() {
108
- return f.object({
109
- input: wt(),
110
- type: At,
111
- scope: Y()
112
- });
113
- }
114
- const ln = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
115
- __proto__: null,
116
- ActionSchema: he,
117
- BaseActionSchema: Pt,
118
- DocumentFileSchema: xe,
119
- LoadStateActionInputSchema: ht,
120
- LoadStateActionSchema: Mt,
121
- LoadStateActionStateInputSchema: zt,
122
- Load_StateSchema: _t,
123
- OperationSchema: ye,
124
- OperationScopeSchema: Y,
125
- PruneActionInputSchema: xt,
126
- PruneActionSchema: Rt,
127
- PruneSchema: Nt,
128
- RedoActionInputSchema: yt,
129
- RedoActionSchema: Ct,
130
- RedoSchema: vt,
131
- SetNameActionInputSchema: bt,
132
- SetNameActionSchema: Ft,
133
- SetNameOperationSchema: be,
134
- Set_NameSchema: It,
135
- UndoActionInputSchema: wt,
136
- UndoActionSchema: Lt,
137
- UndoSchema: At,
138
- definedNonNullAnySchema: ge,
139
- isDefinedNonNullAny: Tt
140
- }, Symbol.toStringTag, { value: "Module" }));
141
- function we(t) {
142
- return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
143
- }
144
- var ft = { exports: {} };
145
- (function(t, e) {
146
- const { hasOwnProperty: n } = Object.prototype, i = C();
147
- i.configure = C, i.stringify = i, i.default = i, e.stringify = i, e.configure = C, t.exports = i;
148
- const o = /[\u0000-\u001f\u0022\u005c\ud800-\udfff]|[\ud800-\udbff](?![\udc00-\udfff])|(?:[^\ud800-\udbff]|^)[\udc00-\udfff]/;
149
- function a(c) {
150
- return c.length < 5e3 && !o.test(c) ? `"${c}"` : JSON.stringify(c);
151
- }
152
- function r(c) {
153
- if (c.length > 200)
154
- return c.sort();
155
- for (let l = 1; l < c.length; l++) {
156
- const u = c[l];
157
- let _ = l;
158
- for (; _ !== 0 && c[_ - 1] > u; )
159
- c[_] = c[_ - 1], _--;
160
- c[_] = u;
161
- }
162
- return c;
163
- }
164
- const p = Object.getOwnPropertyDescriptor(
165
- Object.getPrototypeOf(
166
- Object.getPrototypeOf(
167
- new Int8Array()
168
- )
169
- ),
170
- Symbol.toStringTag
171
- ).get;
172
- function m(c) {
173
- return p.call(c) !== void 0 && c.length !== 0;
174
- }
175
- function d(c, l, u) {
176
- c.length < u && (u = c.length);
177
- const _ = l === "," ? "" : " ";
178
- let F = `"0":${_}${c[0]}`;
179
- for (let M = 1; M < u; M++)
180
- F += `${l}"${M}":${_}${c[M]}`;
181
- return F;
182
- }
183
- function h(c) {
184
- if (n.call(c, "circularValue")) {
185
- const l = c.circularValue;
186
- if (typeof l == "string")
187
- return `"${l}"`;
188
- if (l == null)
189
- return l;
190
- if (l === Error || l === TypeError)
191
- return {
192
- toString() {
193
- throw new TypeError("Converting circular structure to JSON");
194
- }
195
- };
196
- throw new TypeError('The "circularValue" argument must be of type string or the value null or undefined');
197
- }
198
- return '"[Circular]"';
199
- }
200
- function b(c, l) {
201
- let u;
202
- if (n.call(c, l) && (u = c[l], typeof u != "boolean"))
203
- throw new TypeError(`The "${l}" argument must be of type boolean`);
204
- return u === void 0 ? !0 : u;
205
- }
206
- function O(c, l) {
207
- let u;
208
- if (n.call(c, l)) {
209
- if (u = c[l], typeof u != "number")
210
- throw new TypeError(`The "${l}" argument must be of type number`);
211
- if (!Number.isInteger(u))
212
- throw new TypeError(`The "${l}" argument must be an integer`);
213
- if (u < 1)
214
- throw new RangeError(`The "${l}" argument must be >= 1`);
215
- }
216
- return u === void 0 ? 1 / 0 : u;
217
- }
218
- function v(c) {
219
- return c === 1 ? "1 item" : `${c} items`;
220
- }
221
- function T(c) {
222
- const l = /* @__PURE__ */ new Set();
223
- for (const u of c)
224
- (typeof u == "string" || typeof u == "number") && l.add(String(u));
225
- return l;
226
- }
227
- function P(c) {
228
- if (n.call(c, "strict")) {
229
- const l = c.strict;
230
- if (typeof l != "boolean")
231
- throw new TypeError('The "strict" argument must be of type boolean');
232
- if (l)
233
- return (u) => {
234
- let _ = `Object can not safely be stringified. Received type ${typeof u}`;
235
- throw typeof u != "function" && (_ += ` (${u.toString()})`), new Error(_);
236
- };
237
- }
238
- }
239
- function C(c) {
240
- c = { ...c };
241
- const l = P(c);
242
- l && (c.bigint === void 0 && (c.bigint = !1), "circularValue" in c || (c.circularValue = Error));
243
- const u = h(c), _ = b(c, "bigint"), F = b(c, "deterministic"), M = O(c, "maximumDepth"), k = O(c, "maximumBreadth");
244
- function nt(A, s, g, w, y, j) {
245
- let x = s[A];
246
- switch (typeof x == "object" && x !== null && typeof x.toJSON == "function" && (x = x.toJSON(A)), x = w.call(s, A, x), typeof x) {
247
- case "string":
248
- return a(x);
249
- case "object": {
250
- if (x === null)
251
- return "null";
252
- if (g.indexOf(x) !== -1)
253
- return u;
254
- let S = "", $ = ",";
255
- const D = j;
256
- if (Array.isArray(x)) {
257
- if (x.length === 0)
258
- return "[]";
259
- if (M < g.length + 1)
260
- return '"[Array]"';
261
- g.push(x), y !== "" && (j += y, S += `
262
- ${j}`, $ = `,
263
- ${j}`);
264
- const R = Math.min(x.length, k);
265
- let U = 0;
266
- for (; U < R - 1; U++) {
267
- const ot = nt(String(U), x, g, w, y, j);
268
- S += ot !== void 0 ? ot : "null", S += $;
269
- }
270
- const J = nt(String(U), x, g, w, y, j);
271
- if (S += J !== void 0 ? J : "null", x.length - 1 > k) {
272
- const ot = x.length - k - 1;
273
- S += `${$}"... ${v(ot)} not stringified"`;
274
- }
275
- return y !== "" && (S += `
276
- ${D}`), g.pop(), `[${S}]`;
277
- }
278
- let N = Object.keys(x);
279
- const I = N.length;
280
- if (I === 0)
281
- return "{}";
282
- if (M < g.length + 1)
283
- return '"[Object]"';
284
- let E = "", z = "";
285
- y !== "" && (j += y, $ = `,
286
- ${j}`, E = " ");
287
- const q = Math.min(I, k);
288
- F && !m(x) && (N = r(N)), g.push(x);
289
- for (let R = 0; R < q; R++) {
290
- const U = N[R], J = nt(U, x, g, w, y, j);
291
- J !== void 0 && (S += `${z}${a(U)}:${E}${J}`, z = $);
292
- }
293
- if (I > k) {
294
- const R = I - k;
295
- S += `${z}"...":${E}"${v(R)} not stringified"`, z = $;
296
- }
297
- return y !== "" && z.length > 1 && (S = `
298
- ${j}${S}
299
- ${D}`), g.pop(), `{${S}}`;
300
- }
301
- case "number":
302
- return isFinite(x) ? String(x) : l ? l(x) : "null";
303
- case "boolean":
304
- return x === !0 ? "true" : "false";
305
- case "undefined":
306
- return;
307
- case "bigint":
308
- if (_)
309
- return String(x);
310
- default:
311
- return l ? l(x) : void 0;
312
- }
313
- }
314
- function it(A, s, g, w, y, j) {
315
- switch (typeof s == "object" && s !== null && typeof s.toJSON == "function" && (s = s.toJSON(A)), typeof s) {
316
- case "string":
317
- return a(s);
318
- case "object": {
319
- if (s === null)
320
- return "null";
321
- if (g.indexOf(s) !== -1)
322
- return u;
323
- const x = j;
324
- let S = "", $ = ",";
325
- if (Array.isArray(s)) {
326
- if (s.length === 0)
327
- return "[]";
328
- if (M < g.length + 1)
329
- return '"[Array]"';
330
- g.push(s), y !== "" && (j += y, S += `
331
- ${j}`, $ = `,
332
- ${j}`);
333
- const I = Math.min(s.length, k);
334
- let E = 0;
335
- for (; E < I - 1; E++) {
336
- const q = it(String(E), s[E], g, w, y, j);
337
- S += q !== void 0 ? q : "null", S += $;
338
- }
339
- const z = it(String(E), s[E], g, w, y, j);
340
- if (S += z !== void 0 ? z : "null", s.length - 1 > k) {
341
- const q = s.length - k - 1;
342
- S += `${$}"... ${v(q)} not stringified"`;
343
- }
344
- return y !== "" && (S += `
345
- ${x}`), g.pop(), `[${S}]`;
346
- }
347
- g.push(s);
348
- let D = "";
349
- y !== "" && (j += y, $ = `,
350
- ${j}`, D = " ");
351
- let N = "";
352
- for (const I of w) {
353
- const E = it(I, s[I], g, w, y, j);
354
- E !== void 0 && (S += `${N}${a(I)}:${D}${E}`, N = $);
355
- }
356
- return y !== "" && N.length > 1 && (S = `
357
- ${j}${S}
358
- ${x}`), g.pop(), `{${S}}`;
359
- }
360
- case "number":
361
- return isFinite(s) ? String(s) : l ? l(s) : "null";
362
- case "boolean":
363
- return s === !0 ? "true" : "false";
364
- case "undefined":
365
- return;
366
- case "bigint":
367
- if (_)
368
- return String(s);
369
- default:
370
- return l ? l(s) : void 0;
371
- }
372
- }
373
- function G(A, s, g, w, y) {
374
- switch (typeof s) {
375
- case "string":
376
- return a(s);
377
- case "object": {
378
- if (s === null)
379
- return "null";
380
- if (typeof s.toJSON == "function") {
381
- if (s = s.toJSON(A), typeof s != "object")
382
- return G(A, s, g, w, y);
383
- if (s === null)
384
- return "null";
385
- }
386
- if (g.indexOf(s) !== -1)
387
- return u;
388
- const j = y;
389
- if (Array.isArray(s)) {
390
- if (s.length === 0)
391
- return "[]";
392
- if (M < g.length + 1)
393
- return '"[Array]"';
394
- g.push(s), y += w;
395
- let E = `
396
- ${y}`;
397
- const z = `,
398
- ${y}`, q = Math.min(s.length, k);
399
- let R = 0;
400
- for (; R < q - 1; R++) {
401
- const J = G(String(R), s[R], g, w, y);
402
- E += J !== void 0 ? J : "null", E += z;
403
- }
404
- const U = G(String(R), s[R], g, w, y);
405
- if (E += U !== void 0 ? U : "null", s.length - 1 > k) {
406
- const J = s.length - k - 1;
407
- E += `${z}"... ${v(J)} not stringified"`;
408
- }
409
- return E += `
410
- ${j}`, g.pop(), `[${E}]`;
411
- }
412
- let x = Object.keys(s);
413
- const S = x.length;
414
- if (S === 0)
415
- return "{}";
416
- if (M < g.length + 1)
417
- return '"[Object]"';
418
- y += w;
419
- const $ = `,
420
- ${y}`;
421
- let D = "", N = "", I = Math.min(S, k);
422
- m(s) && (D += d(s, $, k), x = x.slice(s.length), I -= s.length, N = $), F && (x = r(x)), g.push(s);
423
- for (let E = 0; E < I; E++) {
424
- const z = x[E], q = G(z, s[z], g, w, y);
425
- q !== void 0 && (D += `${N}${a(z)}: ${q}`, N = $);
426
- }
427
- if (S > k) {
428
- const E = S - k;
429
- D += `${N}"...": "${v(E)} not stringified"`, N = $;
430
- }
431
- return N !== "" && (D = `
432
- ${y}${D}
433
- ${j}`), g.pop(), `{${D}}`;
434
- }
435
- case "number":
436
- return isFinite(s) ? String(s) : l ? l(s) : "null";
437
- case "boolean":
438
- return s === !0 ? "true" : "false";
439
- case "undefined":
440
- return;
441
- case "bigint":
442
- if (_)
443
- return String(s);
444
- default:
445
- return l ? l(s) : void 0;
446
- }
447
- }
448
- function Z(A, s, g) {
449
- switch (typeof s) {
450
- case "string":
451
- return a(s);
452
- case "object": {
453
- if (s === null)
454
- return "null";
455
- if (typeof s.toJSON == "function") {
456
- if (s = s.toJSON(A), typeof s != "object")
457
- return Z(A, s, g);
458
- if (s === null)
459
- return "null";
460
- }
461
- if (g.indexOf(s) !== -1)
462
- return u;
463
- let w = "";
464
- if (Array.isArray(s)) {
465
- if (s.length === 0)
466
- return "[]";
467
- if (M < g.length + 1)
468
- return '"[Array]"';
469
- g.push(s);
470
- const $ = Math.min(s.length, k);
471
- let D = 0;
472
- for (; D < $ - 1; D++) {
473
- const I = Z(String(D), s[D], g);
474
- w += I !== void 0 ? I : "null", w += ",";
475
- }
476
- const N = Z(String(D), s[D], g);
477
- if (w += N !== void 0 ? N : "null", s.length - 1 > k) {
478
- const I = s.length - k - 1;
479
- w += `,"... ${v(I)} not stringified"`;
480
- }
481
- return g.pop(), `[${w}]`;
482
- }
483
- let y = Object.keys(s);
484
- const j = y.length;
485
- if (j === 0)
486
- return "{}";
487
- if (M < g.length + 1)
488
- return '"[Object]"';
489
- let x = "", S = Math.min(j, k);
490
- m(s) && (w += d(s, ",", k), y = y.slice(s.length), S -= s.length, x = ","), F && (y = r(y)), g.push(s);
491
- for (let $ = 0; $ < S; $++) {
492
- const D = y[$], N = Z(D, s[D], g);
493
- N !== void 0 && (w += `${x}${a(D)}:${N}`, x = ",");
494
- }
495
- if (j > k) {
496
- const $ = j - k;
497
- w += `${x}"...":"${v($)} not stringified"`;
498
- }
499
- return g.pop(), `{${w}}`;
500
- }
501
- case "number":
502
- return isFinite(s) ? String(s) : l ? l(s) : "null";
503
- case "boolean":
504
- return s === !0 ? "true" : "false";
505
- case "undefined":
506
- return;
507
- case "bigint":
508
- if (_)
509
- return String(s);
510
- default:
511
- return l ? l(s) : void 0;
512
- }
513
- }
514
- function ae(A, s, g) {
515
- if (arguments.length > 1) {
516
- let w = "";
517
- if (typeof g == "number" ? w = " ".repeat(Math.min(g, 10)) : typeof g == "string" && (w = g.slice(0, 10)), s != null) {
518
- if (typeof s == "function")
519
- return nt("", { "": A }, [], s, w, "");
520
- if (Array.isArray(s))
521
- return it("", A, [], T(s), w, "");
522
- }
523
- if (w.length !== 0)
524
- return G("", A, [], w, "");
525
- }
526
- return Z("", A, []);
527
- }
528
- return ae;
529
- }
530
- })(ft, ft.exports);
531
- var Oe = ft.exports;
532
- const K = /* @__PURE__ */ we(Oe);
533
- K.configure;
534
- function Se(t, e) {
535
- return { ...t, name: e };
536
- }
537
- function je(t, e, n) {
538
- const { scope: i, input: o } = e;
539
- return pt({
540
- document: t,
541
- action: e,
542
- skip: n
543
- }, (r) => {
544
- if (r.document.operations[i].length < 1)
545
- throw new Error(
546
- `Cannot undo: no operations in history for scope "${i}"`
547
- );
548
- if (o < 1)
549
- throw new Error(
550
- "Invalid UNDO action: input value must be greater than 0"
551
- );
552
- if (r.skip > 0)
553
- throw new Error(
554
- "Cannot undo: skip value from reducer cannot be used with UNDO action"
555
- );
556
- const p = r.document.operations[i].at(-1), m = p && p.type === "NOOP" && p.skip > 0;
557
- if (r.skip += o, m) {
558
- r.skip += p.skip;
559
- const O = r.document.operations[i][r.document.operations[i].length - 2];
560
- O && p.index - O.index === 1 && r.document.operations[i].pop();
561
- }
562
- if (r.document.operations[i].length < r.skip)
563
- throw new Error(
564
- "Cannot undo: you can't undo more operations than the ones in the scope history"
565
- );
566
- const d = r.document.operations[i].length - 1;
567
- let h = o, b = m ? d - p.skip : d;
568
- for (; h > 0 && b >= 0; ) {
569
- const O = r.document.operations[i][b];
570
- if (!O) {
571
- h--, b--;
572
- continue;
573
- }
574
- O.type === "NOOP" && O.skip > 0 ? (b = b - (O.skip + 1), r.skip += O.skip + 1) : (r.document.clipboard.push({ ...O }), h--, b--);
575
- }
576
- r.action = re(i);
577
- });
578
- }
579
- function Ee(t, e, n) {
580
- const { scope: i, input: o } = e;
581
- return pt({
582
- document: t,
583
- action: e,
584
- skip: n
585
- }, (r) => {
586
- if (r.skip > 0)
587
- throw new Error(
588
- "Cannot redo: skip value from reducer cannot be used with REDO action"
589
- );
590
- if (o > 1)
591
- throw new Error(
592
- "Cannot redo: you can only redo one operation at a time"
593
- );
594
- if (o < 1)
595
- throw new Error("Invalid REDO action: invalid redo input value");
596
- if (r.document.clipboard.length < 1)
597
- throw new Error("Cannot redo: no operations in the clipboard");
598
- const p = r.document.clipboard.findLastIndex(
599
- (d) => d.scope === i
600
- );
601
- if (p < 0)
602
- throw new Error(
603
- `Cannot redo: no operations in clipboard for scope "${i}"`
604
- );
605
- const m = r.document.clipboard.splice(p, 1)[0];
606
- r.action = at({
607
- type: m.type,
608
- scope: m.scope,
609
- input: m.input
610
- });
611
- });
612
- }
613
- function $e(t, e, n) {
614
- const { scope: i } = e, o = t.operations[i];
615
- let {
616
- input: { start: a, end: r }
617
- } = e;
618
- a = a || 0, r = r || o.length;
619
- const p = o.slice(a, r), m = o.slice(0, a), d = o.slice(r), h = gt(
620
- t.initialState,
621
- {
622
- ...t.operations,
623
- [i]: m.concat(p)
624
- },
625
- n
626
- ), { name: b, state: O } = h, v = m.length, T = m.length ? m[m.length - 1].timestamp : d.length ? d[0].timestamp : (/* @__PURE__ */ new Date()).toISOString();
627
- return gt(
628
- t.initialState,
629
- {
630
- ...t.operations,
631
- [i]: [
632
- ...m,
633
- {
634
- ...Et(
635
- { name: b, state: O },
636
- p.length
637
- ),
638
- timestamp: T,
639
- index: v,
640
- hash: jt({ state: O }, "global")
641
- },
642
- ...d.map((P, C) => ({
643
- ...P,
644
- index: v + C + 1
645
- }))
646
- ]
647
- },
648
- n
649
- );
650
- }
651
- function ke(t, e) {
652
- return {
653
- ...t,
654
- name: e.name,
655
- state: e.state ?? { global: {}, local: {} }
656
- };
657
- }
658
- const qt = "SET_NAME", tt = "UNDO", et = "REDO", ct = "PRUNE", Ut = "LOAD_STATE", De = "NOOP", Jt = { "application/andrew-inset": ["ez"], "application/appinstaller": ["appinstaller"], "application/applixware": ["aw"], "application/appx": ["appx"], "application/appxbundle": ["appxbundle"], "application/atom+xml": ["atom"], "application/atomcat+xml": ["atomcat"], "application/atomdeleted+xml": ["atomdeleted"], "application/atomsvc+xml": ["atomsvc"], "application/atsc-dwd+xml": ["dwd"], "application/atsc-held+xml": ["held"], "application/atsc-rsat+xml": ["rsat"], "application/automationml-aml+xml": ["aml"], "application/automationml-amlx+zip": ["amlx"], "application/bdoc": ["bdoc"], "application/calendar+xml": ["xcs"], "application/ccxml+xml": ["ccxml"], "application/cdfx+xml": ["cdfx"], "application/cdmi-capability": ["cdmia"], "application/cdmi-container": ["cdmic"], "application/cdmi-domain": ["cdmid"], "application/cdmi-object": ["cdmio"], "application/cdmi-queue": ["cdmiq"], "application/cpl+xml": ["cpl"], "application/cu-seeme": ["cu"], "application/cwl": ["cwl"], "application/dash+xml": ["mpd"], "application/dash-patch+xml": ["mpp"], "application/davmount+xml": ["davmount"], "application/docbook+xml": ["dbk"], "application/dssc+der": ["dssc"], "application/dssc+xml": ["xdssc"], "application/ecmascript": ["ecma"], "application/emma+xml": ["emma"], "application/emotionml+xml": ["emotionml"], "application/epub+zip": ["epub"], "application/exi": ["exi"], "application/express": ["exp"], "application/fdf": ["fdf"], "application/fdt+xml": ["fdt"], "application/font-tdpfr": ["pfr"], "application/geo+json": ["geojson"], "application/gml+xml": ["gml"], "application/gpx+xml": ["gpx"], "application/gxf": ["gxf"], "application/gzip": ["gz"], "application/hjson": ["hjson"], "application/hyperstudio": ["stk"], "application/inkml+xml": ["ink", "inkml"], "application/ipfix": ["ipfix"], "application/its+xml": ["its"], "application/java-archive": ["jar", "war", "ear"], "application/java-serialized-object": ["ser"], "application/java-vm": ["class"], "application/javascript": ["*js"], "application/json": ["json", "map"], "application/json5": ["json5"], "application/jsonml+json": ["jsonml"], "application/ld+json": ["jsonld"], "application/lgr+xml": ["lgr"], "application/lost+xml": ["lostxml"], "application/mac-binhex40": ["hqx"], "application/mac-compactpro": ["cpt"], "application/mads+xml": ["mads"], "application/manifest+json": ["webmanifest"], "application/marc": ["mrc"], "application/marcxml+xml": ["mrcx"], "application/mathematica": ["ma", "nb", "mb"], "application/mathml+xml": ["mathml"], "application/mbox": ["mbox"], "application/media-policy-dataset+xml": ["mpf"], "application/mediaservercontrol+xml": ["mscml"], "application/metalink+xml": ["metalink"], "application/metalink4+xml": ["meta4"], "application/mets+xml": ["mets"], "application/mmt-aei+xml": ["maei"], "application/mmt-usd+xml": ["musd"], "application/mods+xml": ["mods"], "application/mp21": ["m21", "mp21"], "application/mp4": ["*mp4", "*mpg4", "mp4s", "m4p"], "application/msix": ["msix"], "application/msixbundle": ["msixbundle"], "application/msword": ["doc", "dot"], "application/mxf": ["mxf"], "application/n-quads": ["nq"], "application/n-triples": ["nt"], "application/node": ["cjs"], "application/octet-stream": ["bin", "dms", "lrf", "mar", "so", "dist", "distz", "pkg", "bpk", "dump", "elc", "deploy", "exe", "dll", "deb", "dmg", "iso", "img", "msi", "msp", "msm", "buffer"], "application/oda": ["oda"], "application/oebps-package+xml": ["opf"], "application/ogg": ["ogx"], "application/omdoc+xml": ["omdoc"], "application/onenote": ["onetoc", "onetoc2", "onetmp", "onepkg"], "application/oxps": ["oxps"], "application/p2p-overlay+xml": ["relo"], "application/patch-ops-error+xml": ["xer"], "application/pdf": ["pdf"], "application/pgp-encrypted": ["pgp"], "application/pgp-keys": ["asc"], "application/pgp-signature": ["sig", "*asc"], "application/pics-rules": ["prf"], "application/pkcs10": ["p10"], "application/pkcs7-mime": ["p7m", "p7c"], "application/pkcs7-signature": ["p7s"], "application/pkcs8": ["p8"], "application/pkix-attr-cert": ["ac"], "application/pkix-cert": ["cer"], "application/pkix-crl": ["crl"], "application/pkix-pkipath": ["pkipath"], "application/pkixcmp": ["pki"], "application/pls+xml": ["pls"], "application/postscript": ["ai", "eps", "ps"], "application/provenance+xml": ["provx"], "application/pskc+xml": ["pskcxml"], "application/raml+yaml": ["raml"], "application/rdf+xml": ["rdf", "owl"], "application/reginfo+xml": ["rif"], "application/relax-ng-compact-syntax": ["rnc"], "application/resource-lists+xml": ["rl"], "application/resource-lists-diff+xml": ["rld"], "application/rls-services+xml": ["rs"], "application/route-apd+xml": ["rapd"], "application/route-s-tsid+xml": ["sls"], "application/route-usd+xml": ["rusd"], "application/rpki-ghostbusters": ["gbr"], "application/rpki-manifest": ["mft"], "application/rpki-roa": ["roa"], "application/rsd+xml": ["rsd"], "application/rss+xml": ["rss"], "application/rtf": ["rtf"], "application/sbml+xml": ["sbml"], "application/scvp-cv-request": ["scq"], "application/scvp-cv-response": ["scs"], "application/scvp-vp-request": ["spq"], "application/scvp-vp-response": ["spp"], "application/sdp": ["sdp"], "application/senml+xml": ["senmlx"], "application/sensml+xml": ["sensmlx"], "application/set-payment-initiation": ["setpay"], "application/set-registration-initiation": ["setreg"], "application/shf+xml": ["shf"], "application/sieve": ["siv", "sieve"], "application/smil+xml": ["smi", "smil"], "application/sparql-query": ["rq"], "application/sparql-results+xml": ["srx"], "application/sql": ["sql"], "application/srgs": ["gram"], "application/srgs+xml": ["grxml"], "application/sru+xml": ["sru"], "application/ssdl+xml": ["ssdl"], "application/ssml+xml": ["ssml"], "application/swid+xml": ["swidtag"], "application/tei+xml": ["tei", "teicorpus"], "application/thraud+xml": ["tfi"], "application/timestamped-data": ["tsd"], "application/toml": ["toml"], "application/trig": ["trig"], "application/ttml+xml": ["ttml"], "application/ubjson": ["ubj"], "application/urc-ressheet+xml": ["rsheet"], "application/urc-targetdesc+xml": ["td"], "application/voicexml+xml": ["vxml"], "application/wasm": ["wasm"], "application/watcherinfo+xml": ["wif"], "application/widget": ["wgt"], "application/winhlp": ["hlp"], "application/wsdl+xml": ["wsdl"], "application/wspolicy+xml": ["wspolicy"], "application/xaml+xml": ["xaml"], "application/xcap-att+xml": ["xav"], "application/xcap-caps+xml": ["xca"], "application/xcap-diff+xml": ["xdf"], "application/xcap-el+xml": ["xel"], "application/xcap-ns+xml": ["xns"], "application/xenc+xml": ["xenc"], "application/xfdf": ["xfdf"], "application/xhtml+xml": ["xhtml", "xht"], "application/xliff+xml": ["xlf"], "application/xml": ["xml", "xsl", "xsd", "rng"], "application/xml-dtd": ["dtd"], "application/xop+xml": ["xop"], "application/xproc+xml": ["xpl"], "application/xslt+xml": ["*xsl", "xslt"], "application/xspf+xml": ["xspf"], "application/xv+xml": ["mxml", "xhvml", "xvml", "xvm"], "application/yang": ["yang"], "application/yin+xml": ["yin"], "application/zip": ["zip"], "audio/3gpp": ["*3gpp"], "audio/aac": ["adts", "aac"], "audio/adpcm": ["adp"], "audio/amr": ["amr"], "audio/basic": ["au", "snd"], "audio/midi": ["mid", "midi", "kar", "rmi"], "audio/mobile-xmf": ["mxmf"], "audio/mp3": ["*mp3"], "audio/mp4": ["m4a", "mp4a"], "audio/mpeg": ["mpga", "mp2", "mp2a", "mp3", "m2a", "m3a"], "audio/ogg": ["oga", "ogg", "spx", "opus"], "audio/s3m": ["s3m"], "audio/silk": ["sil"], "audio/wav": ["wav"], "audio/wave": ["*wav"], "audio/webm": ["weba"], "audio/xm": ["xm"], "font/collection": ["ttc"], "font/otf": ["otf"], "font/ttf": ["ttf"], "font/woff": ["woff"], "font/woff2": ["woff2"], "image/aces": ["exr"], "image/apng": ["apng"], "image/avci": ["avci"], "image/avcs": ["avcs"], "image/avif": ["avif"], "image/bmp": ["bmp", "dib"], "image/cgm": ["cgm"], "image/dicom-rle": ["drle"], "image/dpx": ["dpx"], "image/emf": ["emf"], "image/fits": ["fits"], "image/g3fax": ["g3"], "image/gif": ["gif"], "image/heic": ["heic"], "image/heic-sequence": ["heics"], "image/heif": ["heif"], "image/heif-sequence": ["heifs"], "image/hej2k": ["hej2"], "image/hsj2": ["hsj2"], "image/ief": ["ief"], "image/jls": ["jls"], "image/jp2": ["jp2", "jpg2"], "image/jpeg": ["jpeg", "jpg", "jpe"], "image/jph": ["jph"], "image/jphc": ["jhc"], "image/jpm": ["jpm", "jpgm"], "image/jpx": ["jpx", "jpf"], "image/jxr": ["jxr"], "image/jxra": ["jxra"], "image/jxrs": ["jxrs"], "image/jxs": ["jxs"], "image/jxsc": ["jxsc"], "image/jxsi": ["jxsi"], "image/jxss": ["jxss"], "image/ktx": ["ktx"], "image/ktx2": ["ktx2"], "image/png": ["png"], "image/sgi": ["sgi"], "image/svg+xml": ["svg", "svgz"], "image/t38": ["t38"], "image/tiff": ["tif", "tiff"], "image/tiff-fx": ["tfx"], "image/webp": ["webp"], "image/wmf": ["wmf"], "message/disposition-notification": ["disposition-notification"], "message/global": ["u8msg"], "message/global-delivery-status": ["u8dsn"], "message/global-disposition-notification": ["u8mdn"], "message/global-headers": ["u8hdr"], "message/rfc822": ["eml", "mime"], "model/3mf": ["3mf"], "model/gltf+json": ["gltf"], "model/gltf-binary": ["glb"], "model/iges": ["igs", "iges"], "model/jt": ["jt"], "model/mesh": ["msh", "mesh", "silo"], "model/mtl": ["mtl"], "model/obj": ["obj"], "model/prc": ["prc"], "model/step+xml": ["stpx"], "model/step+zip": ["stpz"], "model/step-xml+zip": ["stpxz"], "model/stl": ["stl"], "model/u3d": ["u3d"], "model/vrml": ["wrl", "vrml"], "model/x3d+binary": ["*x3db", "x3dbz"], "model/x3d+fastinfoset": ["x3db"], "model/x3d+vrml": ["*x3dv", "x3dvz"], "model/x3d+xml": ["x3d", "x3dz"], "model/x3d-vrml": ["x3dv"], "text/cache-manifest": ["appcache", "manifest"], "text/calendar": ["ics", "ifb"], "text/coffeescript": ["coffee", "litcoffee"], "text/css": ["css"], "text/csv": ["csv"], "text/html": ["html", "htm", "shtml"], "text/jade": ["jade"], "text/javascript": ["js", "mjs"], "text/jsx": ["jsx"], "text/less": ["less"], "text/markdown": ["md", "markdown"], "text/mathml": ["mml"], "text/mdx": ["mdx"], "text/n3": ["n3"], "text/plain": ["txt", "text", "conf", "def", "list", "log", "in", "ini"], "text/richtext": ["rtx"], "text/rtf": ["*rtf"], "text/sgml": ["sgml", "sgm"], "text/shex": ["shex"], "text/slim": ["slim", "slm"], "text/spdx": ["spdx"], "text/stylus": ["stylus", "styl"], "text/tab-separated-values": ["tsv"], "text/troff": ["t", "tr", "roff", "man", "me", "ms"], "text/turtle": ["ttl"], "text/uri-list": ["uri", "uris", "urls"], "text/vcard": ["vcard"], "text/vtt": ["vtt"], "text/wgsl": ["wgsl"], "text/xml": ["*xml"], "text/yaml": ["yaml", "yml"], "video/3gpp": ["3gp", "3gpp"], "video/3gpp2": ["3g2"], "video/h261": ["h261"], "video/h263": ["h263"], "video/h264": ["h264"], "video/iso.segment": ["m4s"], "video/jpeg": ["jpgv"], "video/jpm": ["*jpm", "*jpgm"], "video/mj2": ["mj2", "mjp2"], "video/mp2t": ["ts"], "video/mp4": ["mp4", "mp4v", "mpg4"], "video/mpeg": ["mpeg", "mpg", "mpe", "m1v", "m2v"], "video/ogg": ["ogv"], "video/quicktime": ["qt", "mov"], "video/webm": ["webm"] };
659
- Object.freeze(Jt);
660
- var L = function(t, e, n, i) {
661
- if (n === "a" && !i)
662
- throw new TypeError("Private accessor was defined without a getter");
663
- if (typeof e == "function" ? t !== e || !i : !e.has(t))
664
- throw new TypeError("Cannot read private member from an object whose class did not declare it");
665
- return n === "m" ? i : n === "a" ? i.call(t) : i ? i.value : e.get(t);
666
- }, B, Q, H;
667
- class Te {
668
- constructor(...e) {
669
- B.set(this, /* @__PURE__ */ new Map()), Q.set(this, /* @__PURE__ */ new Map()), H.set(this, /* @__PURE__ */ new Map());
670
- for (const n of e)
671
- this.define(n);
672
- }
673
- define(e, n = !1) {
674
- for (let [i, o] of Object.entries(e)) {
675
- i = i.toLowerCase(), o = o.map((p) => p.toLowerCase()), L(this, H, "f").has(i) || L(this, H, "f").set(i, /* @__PURE__ */ new Set());
676
- const a = L(this, H, "f").get(i);
677
- let r = !0;
678
- for (let p of o) {
679
- const m = p.startsWith("*");
680
- if (p = m ? p.slice(1) : p, a == null || a.add(p), r && L(this, Q, "f").set(i, p), r = !1, m)
681
- continue;
682
- const d = L(this, B, "f").get(p);
683
- if (d && d != i && !n)
684
- throw new Error(`"${i} -> ${p}" conflicts with "${d} -> ${p}". Pass \`force=true\` to override this definition.`);
685
- L(this, B, "f").set(p, i);
686
- }
687
- }
688
- return this;
689
- }
690
- getType(e) {
691
- if (typeof e != "string")
692
- return null;
693
- const n = e.replace(/^.*[/\\]/, "").toLowerCase(), i = n.replace(/^.*\./, "").toLowerCase(), o = n.length < e.length;
694
- return !(i.length < n.length - 1) && o ? null : L(this, B, "f").get(i) ?? null;
695
- }
696
- getExtension(e) {
697
- var n;
698
- return typeof e != "string" ? null : (e = (n = e == null ? void 0 : e.split) == null ? void 0 : n.call(e, ";")[0], (e && L(this, Q, "f").get(e.trim().toLowerCase())) ?? null);
699
- }
700
- getAllExtensions(e) {
701
- return typeof e != "string" ? null : L(this, H, "f").get(e.toLowerCase()) ?? null;
702
- }
703
- _freeze() {
704
- this.define = () => {
705
- throw new Error("define() not allowed for built-in Mime objects. See https://github.com/broofa/mime/blob/main/README.md#custom-mime-instances");
706
- }, Object.freeze(this);
707
- for (const e of L(this, H, "f").values())
708
- Object.freeze(e);
709
- return this;
710
- }
711
- _getTestState() {
712
- return {
713
- types: L(this, B, "f"),
714
- extensions: L(this, Q, "f")
715
- };
716
- }
717
- }
718
- B = /* @__PURE__ */ new WeakMap(), Q = /* @__PURE__ */ new WeakMap(), H = /* @__PURE__ */ new WeakMap();
719
- const _e = new Te(Jt)._freeze();
720
- function Ne(t, e, n) {
721
- const i = de(t, e);
722
- return ut.mkdirSync(t, { recursive: !0 }), new Promise((o, a) => {
723
- try {
724
- ut.writeFile(i, n, {}, (r) => {
725
- r ? a(r) : o(i);
726
- });
727
- } catch (r) {
728
- a(r);
729
- }
730
- });
731
- }
732
- function Vt(t) {
733
- return ut.readFileSync(t);
734
- }
735
- function ve(t) {
736
- return new Promise((e, n) => {
737
- fe.get(t, (i) => {
738
- const o = [], a = i.headers["content-type"];
739
- i.on("data", (r) => {
740
- o.push(r);
741
- }), i.on("end", () => {
742
- e({ buffer: Buffer.concat(o), mimeType: a });
743
- });
744
- }).on("error", (i) => {
745
- n(i);
746
- });
747
- });
748
- }
749
- const Ie = async (t) => Vt(t), lt = (t, e = "sha1") => ue.createHash(e).update(t).digest("base64");
750
- function Ae(t) {
751
- const e = [], n = Object.keys(t);
752
- for (const i of n) {
753
- const o = t[i].sort((a, r) => a.index - r.index);
754
- for (let a = 0; a < o.length; a++)
755
- o[a].index !== a && e.push({
756
- message: `Invalid operation index ${o[a].index} at position ${a}`,
757
- details: {
758
- position: a,
759
- operation: o[a],
760
- scope: o[a].scope
761
- }
762
- });
763
- }
764
- return e;
765
- }
766
- const Xt = async (t) => {
767
- const e = new Dt(), { name: n, revision: i, documentType: o, created: a, lastModified: r } = t, p = {
768
- name: n,
769
- revision: i,
770
- documentType: o,
771
- created: a,
772
- lastModified: r
773
- };
774
- return e.file("header.json", JSON.stringify(p, null, 2)), e.file(
775
- "state.json",
776
- JSON.stringify(t.initialState || {}, null, 2)
777
- ), e.file("operations.json", JSON.stringify(t.operations, null, 2)), Object.keys(t.attachments).forEach((d) => {
778
- const { data: h, ...b } = t.attachments[d];
779
- e.file(d, h, {
780
- base64: !0,
781
- createFolders: !0,
782
- comment: JSON.stringify(b)
783
- });
784
- }), e;
785
- }, Pe = async (t, e, n, i) => {
786
- const a = await (await Xt(t)).generateAsync({
787
- type: "uint8array",
788
- streamFiles: !0
789
- }), r = i ?? t.name, p = `.${n}.zip`;
790
- return Ne(
791
- e,
792
- r.endsWith(p) ? r : `${r}${p}`,
793
- a
794
- );
795
- }, mn = async (t, e) => {
796
- const i = await (await Xt(t)).generateAsync({ type: "blob" }), o = await e.createWritable();
797
- await o.write(i), await o.close();
798
- }, $t = async (t, e, n) => {
799
- const i = Vt(t);
800
- return Me(i, e, n);
801
- }, Me = async (t, e, n) => {
802
- const i = new Dt();
803
- return await i.loadAsync(t), ze(i, e, n);
804
- };
805
- async function ze(t, e, n) {
806
- const i = t.file("state.json");
807
- if (!i)
808
- throw new Error("Initial state not found");
809
- const o = await i.async("string"), a = JSON.parse(o), r = t.file("header.json");
810
- let p;
811
- r && (p = JSON.parse(await r.async("string")));
812
- const m = t.file("operations.json");
813
- if (!m)
814
- throw new Error("Operations history not found");
815
- const d = JSON.parse(
816
- await m.async("string")
817
- ), h = Ae(d);
818
- if (h.length) {
819
- const O = h.map((v) => v.message);
820
- throw new Error(O.join(`
821
- `));
822
- }
823
- let b = te(
824
- a,
825
- d,
826
- e,
827
- void 0,
828
- p,
829
- {},
830
- n
831
- );
832
- return p && (b = {
833
- ...b,
834
- ...p
835
- }), b;
836
- }
837
- function Ht(t) {
838
- const e = t.replace(/^.*\./, "") || void 0, n = t.replace(/^.*[/\\]/, "") || void 0;
839
- return { extension: e, fileName: n };
840
- }
841
- async function un(t) {
842
- const { buffer: e, mimeType: n = "application/octet-stream" } = await ve(t), i = Ht(t), o = e.toString("base64");
843
- return {
844
- data: o,
845
- hash: lt(o),
846
- mimeType: n,
847
- ...i
848
- };
849
- }
850
- async function fn(t) {
851
- const e = await Ie(t), n = _e.getType(t) || "application/octet-stream", i = Ht(t), o = e.toString("base64");
852
- return { data: o, hash: lt(o), mimeType: n, ...i };
853
- }
854
- var Bt = /* @__PURE__ */ ((t) => (t.UNEXPECTED_INDEX = "UNEXPECTED_INDEX", t))(Bt || {}), Kt = /* @__PURE__ */ ((t) => (t.DUPLICATED_INDEX = "DUPLICATED_INDEX", t.MISSING_INDEX = "MISSING_INDEX", t))(Kt || {});
855
- function Ot(t) {
856
- const e = [];
857
- let n = -1;
858
- for (const i of t) {
859
- const o = i.index - i.skip;
860
- o !== n + 1 && e.push({
861
- operation: {
862
- index: i.index,
863
- skip: i.skip
864
- },
865
- issue: "UNEXPECTED_INDEX",
866
- category: o > n + 1 ? "MISSING_INDEX" : "DUPLICATED_INDEX",
867
- message: `Expected index ${n + 1} with skip 0 or equivalent, got index ${i.index} with skip ${i.skip}`
868
- }), n = i.index;
869
- }
870
- return e;
871
- }
872
- function V(t) {
873
- var i, o, a;
874
- const e = [];
875
- let n = t.length - 1;
876
- for (; n > -1; ) {
877
- e.unshift(t[n]);
878
- const r = (((i = t[n]) == null ? void 0 : i.index) || 0) - (((o = t[n]) == null ? void 0 : o.skip) || 0) - 1;
879
- let p = n - 1;
880
- for (; p > -1 && (((a = t[p]) == null ? void 0 : a.index) || 0) > r; )
881
- p--;
882
- n = p;
883
- }
884
- return e;
885
- }
886
- function Re(t) {
887
- const e = [...t], n = e[e.length - 1];
888
- return n && (n.type === "NOOP" ? e.push({
889
- ...n,
890
- index: n.index,
891
- type: "NOOP",
892
- skip: Zt(t)
893
- }) : e.push({
894
- type: "NOOP",
895
- index: n.index + 1,
896
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
897
- input: {},
898
- skip: 1,
899
- scope: n.scope,
900
- hash: n.hash
901
- })), e;
902
- }
903
- function X(t) {
904
- return t.slice().sort((e, n) => e.skip - n.skip).sort((e, n) => e.index - n.index);
905
- }
906
- const Ce = (t, e, n) => [...e, ...n].sort(
907
- (i, o) => new Date(i.timestamp).getTime() - new Date(o.timestamp).getTime()
908
- ).map((i, o) => ({
909
- ...i,
910
- index: t.index + o,
911
- skip: o === 0 ? t.skip : 0
912
- })), Fe = (t, e, n) => [...e, ...n].sort(
913
- (i, o) => new Date(i.timestamp).getTime() - new Date(o.timestamp).getTime()
914
- ).sort((i, o) => i.index - o.index).map((i, o) => ({
915
- ...i,
916
- index: t.index + o,
917
- skip: o === 0 ? t.skip : 0
918
- }));
919
- function St(t, e) {
920
- return K(t) === K(e);
921
- }
922
- function Le(t, e) {
923
- const n = V(X(t.slice())), i = V(X(e.slice()));
924
- if (n.length < 1)
925
- return [i, []];
926
- const o = [];
927
- let a = !1;
928
- for (; i.length > 0; ) {
929
- const r = i[0];
930
- let p = n.shift();
931
- for (; p && Wt(p, r); )
932
- o.push(p), p = n.shift();
933
- if (p ? a || (St(p, r) ? (i.shift(), o.push(p)) : (n.unshift(p), a = !0)) : a = !0, a) {
934
- let m = i.shift();
935
- for (; m; )
936
- o.push(m), m = i.shift();
937
- }
938
- }
939
- if (!a) {
940
- let r = n.shift();
941
- for (; r; )
942
- o.push(r), r = n.shift();
943
- }
944
- return [V(o), n];
945
- }
946
- function Wt(t, e) {
947
- return t.index < e.index || t.index === e.index && t.skip < e.skip;
948
- }
949
- function Gt(t, e) {
950
- const n = [], i = [], o = [], a = Math.max(
951
- t.length,
952
- e.length
953
- );
954
- let r = !1;
955
- for (let p = 0; p < a; p++) {
956
- const m = t[p], d = e[p];
957
- m && d ? !r && St(m, d) ? n.push(m) : (r = !0, i.push(m), o.push(d)) : m ? i.push(m) : d && o.push(d);
958
- }
959
- return [n, i, o];
960
- }
961
- function qe(t, e, n) {
962
- const [i, o, a] = Gt(
963
- V(t),
964
- V(e)
965
- ), r = mt(i), p = 1 + Math.max(
966
- r,
967
- mt(o),
968
- mt(a)
969
- ), m = n(
970
- {
971
- index: p,
972
- skip: p - (r + 1)
973
- },
974
- o,
975
- a
976
- );
977
- return i.concat(m);
978
- }
979
- function mt(t) {
980
- const e = t[t.length - 1];
981
- return e ? e.index : -1;
982
- }
983
- function Zt(t) {
984
- var i, o, a;
985
- if (t.length < 1)
986
- return -1;
987
- const e = V(t);
988
- let n = (((i = e[e.length - 1]) == null ? void 0 : i.skip) || 0) + 1;
989
- return e.length > 1 && (n += ((o = e[e.length - 2]) == null ? void 0 : o.skip) || 0), (((a = e[e.length - 1]) == null ? void 0 : a.index) || -1) < n ? -1 : n;
990
- }
991
- const Ue = (t) => Ot(
992
- V(X(t))
993
- ), Je = (t) => t.reduce((n, i) => {
994
- var o;
995
- return n[i.scope] || (n[i.scope] = []), (o = n[i.scope]) == null || o.push(i), n;
996
- }, {}), Ve = (t, e) => {
997
- var m;
998
- const n = {
999
- integrityIssues: [],
1000
- validOperations: [],
1001
- invalidOperations: [],
1002
- duplicatedOperations: []
1003
- }, i = X(t), o = X(e), a = Ot([
1004
- ...i,
1005
- ...o
1006
- ]), p = (m = [...a.filter(
1007
- (d) => d.category === "MISSING_INDEX"
1008
- /* MISSING_INDEX */
1009
- )].sort((d, h) => h.operation.index - d.operation.index).pop()) == null ? void 0 : m.operation;
1010
- for (const d of o) {
1011
- if (p && d.index >= p.index) {
1012
- n.invalidOperations.push(d);
1013
- continue;
1014
- }
1015
- if (a.some((b) => b.operation.index === d.index && b.operation.skip === d.skip && b.category === "DUPLICATED_INDEX")) {
1016
- n.duplicatedOperations.push(d);
1017
- continue;
1018
- }
1019
- n.validOperations.push(d);
1020
- }
1021
- return n.integrityIssues.push(...a), n;
1022
- };
1023
- function Xe(t, e) {
1024
- return t.filter((n) => !e.some((i) => n.type === "NOOP" && n.skip === 0 && n.index === i.index || n.index === i.index && n.skip === i.skip && n.scope === i.scope && n.hash === i.hash && n.type === i.type));
1025
- }
1026
- function Qt(t, e) {
1027
- const [n] = X(t).slice(-1), i = (n == null ? void 0 : n.index) ?? -1, o = i + 1, a = {
1028
- ...e,
1029
- index: e.index ?? o
1030
- };
1031
- if (a.index < i)
1032
- throw new Error(
1033
- `The skip header operation index must be greater than or equal to ${i}`
1034
- );
1035
- return (V(
1036
- X([...t, a])
1037
- ) || []).slice(0, -1);
1038
- }
1039
- function dt(t) {
1040
- return {
1041
- ...Object.entries(t).reduce(
1042
- (n, i) => {
1043
- const [o, a] = i;
1044
- return {
1045
- ...n,
1046
- [o]: V(X(a))
1047
- };
1048
- },
1049
- {}
1050
- )
1051
- };
1052
- }
1053
- const dn = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1054
- __proto__: null,
1055
- IntegrityIssueSubType: Kt,
1056
- IntegrityIssueType: Bt,
1057
- addUndo: Re,
1058
- attachBranch: Le,
1059
- checkCleanedOperationsIntegrity: Ot,
1060
- checkOperationsIntegrity: Ue,
1061
- garbageCollect: V,
1062
- garbageCollectDocumentOperations: dt,
1063
- groupOperationsByScope: Je,
1064
- merge: qe,
1065
- nextSkipNumber: Zt,
1066
- operationsAreEqual: St,
1067
- precedes: Wt,
1068
- prepareOperations: Ve,
1069
- removeExistingOperations: Xe,
1070
- reshuffleByTimestamp: Ce,
1071
- reshuffleByTimestampAndIndex: Fe,
1072
- skipHeaderOperations: Qt,
1073
- sortOperations: X,
1074
- split: Gt
1075
- }, Symbol.toStringTag, { value: "Module" }));
1076
- function He(t, e) {
1077
- let n;
1078
- return "index" in e ? n = { ...e } : n = t.operations[e.scope].at(-1), ((n == null ? void 0 : n.index) ?? -1) + 1;
1079
- }
1080
- function Be(t, e) {
1081
- return {
1082
- ...t,
1083
- revision: {
1084
- ...t.revision,
1085
- [e.scope]: He(t, e)
1086
- },
1087
- lastModified: (/* @__PURE__ */ new Date()).toISOString()
1088
- };
1089
- }
1090
- function Ke(t, e, n = 0, i = !1) {
1091
- if ([tt, et, ct].includes(e.type))
1092
- return t;
1093
- const { scope: o } = e, a = t.operations[o].slice(), r = a.at(-1);
1094
- let p = ((r == null ? void 0 : r.index) ?? -1) + 1;
1095
- if ("index" in e) {
1096
- if (e.index - n > p)
1097
- throw new Error(
1098
- `Missing operations: expected ${p} with skip 0 or equivalent, got index ${e.index} with skip ${n}`
1099
- );
1100
- p = e.index;
1101
- }
1102
- const m = {
1103
- ...e,
1104
- index: p,
1105
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1106
- hash: "",
1107
- scope: o,
1108
- skip: n,
1109
- error: void 0
1110
- };
1111
- return i && (m.resultingState = t.state[o]), a.push(m), {
1112
- ...t,
1113
- operations: { ...t.operations, [o]: a }
1114
- };
1115
- }
1116
- function We(t, e, n = 0, i = !1) {
1117
- let o = Ke(
1118
- t,
1119
- e,
1120
- n,
1121
- i
1122
- );
1123
- return o = Be(o, e), o;
1124
- }
1125
- function Ge(t, e, n) {
1126
- switch (Pt().parse(e), e.type) {
1127
- case qt:
1128
- return Se(t, e.input);
1129
- case ct:
1130
- return $e(t, e, n);
1131
- case Ut:
1132
- return ke(t, e.input.state);
1133
- default:
1134
- return t;
1135
- }
1136
- }
1137
- function gn(t, e, n) {
1138
- switch (e.type) {
1139
- case tt:
1140
- return je(t, e, n);
1141
- case et:
1142
- return Ee(t, e, n);
1143
- default:
1144
- return { document: t, action: e, skip: n };
1145
- }
1146
- }
1147
- function Ze(t, e, n, i, o = !1, a = ee) {
1148
- const r = e.scope, p = t.operations[r].at(-1);
1149
- if (!p)
1150
- return t;
1151
- const m = dt(
1152
- {
1153
- ...t.operations,
1154
- [r]: Qt(
1155
- t.operations[r],
1156
- p
1157
- )
1158
- }
1159
- );
1160
- let d;
1161
- const h = m[r].at(-1);
1162
- if (o && (h != null && h.resultingState))
1163
- d = a(
1164
- h.resultingState
1165
- );
1166
- else {
1167
- const { state: b } = gt(
1168
- t.initialState,
1169
- m,
1170
- n,
1171
- void 0,
1172
- void 0,
1173
- void 0,
1174
- void 0,
1175
- {
1176
- reuseHash: !0,
1177
- reuseOperationResultingState: o,
1178
- operationResultingStateParser: a
1179
- }
1180
- );
1181
- d = b[r];
1182
- }
1183
- return {
1184
- ...t,
1185
- state: {
1186
- ...t.state,
1187
- [r]: d
1188
- },
1189
- operations: dt({
1190
- ...t.operations
1191
- })
1192
- };
1193
- }
1194
- function Yt(t, e, n, i, o = {}) {
1195
- const {
1196
- skip: a,
1197
- ignoreSkipOperations: r = !1,
1198
- reuseHash: p = !1,
1199
- reuseOperationResultingState: m = !1,
1200
- operationResultingStateParser: d
1201
- } = o, h = { ...e }, b = a || 0;
1202
- let O = { ...t };
1203
- const v = !r && (b > 0 || "index" in h && h.skip > 0);
1204
- return kt(h) && (O = Ge(O, h, n)), O = We(
1205
- O,
1206
- h,
1207
- b,
1208
- m
1209
- ), v && (O = Ze(
1210
- O,
1211
- h,
1212
- n,
1213
- b,
1214
- m,
1215
- d
1216
- )), O = pt(O, (T) => {
1217
- try {
1218
- const P = n(
1219
- T.state,
1220
- h,
1221
- i
1222
- );
1223
- if (P)
1224
- return at({
1225
- ...O,
1226
- // clipboard: [...clipboardValue],
1227
- state: P
1228
- });
1229
- } catch (P) {
1230
- const C = O.operations[h.scope].length - 1;
1231
- T.operations[h.scope][C].error = P.message, T.operations[h.scope][C].skip = 0, v && (T.state = at({ ...t.state }), T.operations = at({
1232
- ...t.operations,
1233
- [h.scope]: [
1234
- ...t.operations[h.scope],
1235
- {
1236
- ...T.operations[h.scope][C]
1237
- }
1238
- ]
1239
- }));
1240
- }
1241
- }), pt(O, (T) => {
1242
- if ([tt, et, ct].includes(h.type))
1243
- return T;
1244
- const P = h.scope || "global", C = p && Object.prototype.hasOwnProperty.call(h, "hash") ? h.hash : jt(T, P);
1245
- T.operations[P][T.operations[P].length - 1].hash = C, !kt(h) && h.attachments && h.attachments.forEach((c) => {
1246
- const { hash: l, ...u } = c;
1247
- T.attachments[l] = {
1248
- ...u
1249
- };
1250
- });
1251
- });
1252
- }
1253
- function hn(t) {
1254
- return t.type === De && t.skip !== void 0 && t.skip > 0 && t.hash !== void 0;
1255
- }
1256
- function xn(t) {
1257
- return [tt, et].includes(t.type);
1258
- }
1259
- function kt(t) {
1260
- return [qt, tt, et, ct, Ut].includes(t.type);
1261
- }
1262
- function W(t, e, n, i, o = "global") {
1263
- if (!t)
1264
- throw new Error("Empty action type");
1265
- if (typeof t != "string")
1266
- throw new Error(`Invalid action type: ${JSON.stringify(t)}`);
1267
- const a = { type: t, input: e, scope: o };
1268
- n && (a.attachments = n);
1269
- try {
1270
- i == null || i().parse(a.input);
1271
- } catch (r) {
1272
- throw new Error(`Invalid action input: ${r}`);
1273
- }
1274
- return a;
1275
- }
1276
- function Qe(t, e = Yt) {
1277
- return (n, i, o, a) => e(n, i, t, o, a);
1278
- }
1279
- const Ye = (t, e) => ({
1280
- name: "",
1281
- documentType: "",
1282
- revision: {
1283
- global: 0,
1284
- local: 0
1285
- },
1286
- created: (/* @__PURE__ */ new Date()).toISOString(),
1287
- lastModified: (/* @__PURE__ */ new Date()).toISOString(),
1288
- attachments: {},
1289
- ...t,
1290
- state: (e == null ? void 0 : e(t == null ? void 0 : t.state)) ?? (t == null ? void 0 : t.state) ?? { global: {}, local: {} }
1291
- }), tn = (t, e) => {
1292
- const n = Ye(
1293
- t,
1294
- e
1295
- );
1296
- return {
1297
- ...n,
1298
- initialState: n,
1299
- operations: { global: [], local: [] },
1300
- clipboard: []
1301
- };
1302
- }, jt = (t, e = "global") => lt(K(t.state[e] || "")), yn = (t, e = 1e3) => {
1303
- const n = Math.random() * e;
1304
- return lt(`${(t ?? /* @__PURE__ */ new Date()).toISOString()}${n}`);
1305
- };
1306
- function rt(t) {
1307
- return le(me(t, !0));
1308
- }
1309
- function bn(t, e) {
1310
- const n = [...t];
1311
- let i = e || 0, o = n.length > 0 ? n[n.length - 1].index : 0;
1312
- const a = [];
1313
- for (const r of n.reverse()) {
1314
- if (i > 0) {
1315
- const d = o - r.index;
1316
- i -= d;
1317
- }
1318
- if (i < 0)
1319
- throw new Error("Invalid operation index, missing operations");
1320
- const p = {
1321
- ignore: i > 0,
1322
- operation: r
1323
- }, m = r.skip > 0 ? r.skip + 1 : 0;
1324
- if (m > 0 && m > i) {
1325
- const d = m - i;
1326
- i = i + d;
1327
- }
1328
- o = r.index, a.push(p);
1329
- }
1330
- return a.reverse();
1331
- }
1332
- function wn(t, e, n) {
1333
- const i = t.slice().sort((p, m) => p.skip - m.skip).sort((p, m) => p.index - m.index);
1334
- let o = n, a = 0, r = e;
1335
- for (const p of i.reverse()) {
1336
- const m = r - p.index;
1337
- if (o = o - m, o > -1)
1338
- a++, r = p.index;
1339
- else
1340
- break;
1341
- }
1342
- return a;
1343
- }
1344
- function On(t) {
1345
- return Object.values(t).flatMap((e) => e).sort(
1346
- (e, n) => new Date(e.timestamp).getTime() - new Date(n.timestamp).getTime()
1347
- );
1348
- }
1349
- function Sn(t) {
1350
- return Object.values(t).flatMap((e) => e).sort(
1351
- (e, n) => new Date(e.operation.timestamp).getTime() - new Date(n.operation.timestamp).getTime()
1352
- );
1353
- }
1354
- function gt(t, e, n, i, o, a = Yt, r = {}, p) {
1355
- const m = Qe(n, a);
1356
- return te(
1357
- t,
1358
- e,
1359
- m,
1360
- i,
1361
- o,
1362
- r,
1363
- p
1364
- );
1365
- }
1366
- function te(t, e, n, i, o, a = {}, r) {
1367
- const {
1368
- checkHashes: p = !0,
1369
- reuseOperationResultingState: m,
1370
- operationResultingStateParser: d = ee
1371
- } = r || {};
1372
- let h = t;
1373
- const b = [], O = {
1374
- global: [],
1375
- local: []
1376
- };
1377
- if (m)
1378
- for (const [c, l] of Object.entries(e)) {
1379
- const u = l.findLastIndex(
1380
- (F) => !!F.resultingState
1381
- );
1382
- if (u < 0) {
1383
- b.push(...l);
1384
- continue;
1385
- }
1386
- const _ = l[u];
1387
- try {
1388
- const F = d(
1389
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-unnecessary-type-assertion
1390
- _.resultingState
1391
- );
1392
- h = {
1393
- ...h,
1394
- state: {
1395
- ...h.state,
1396
- // TODO how to deal with attachments?
1397
- [c]: F
1398
- }
1399
- }, O[c].push(
1400
- ...l.slice(0, u + 1)
1401
- ), b.push(...l.slice(u + 1));
1402
- } catch {
1403
- b.push(...l);
1404
- }
1405
- }
1406
- else
1407
- b.push(...Object.values(e).flat());
1408
- const v = tn(h);
1409
- v.initialState = t, v.operations = O;
1410
- const T = b.reduce((c, l) => n(c, l, i, {
1411
- skip: l.skip,
1412
- ignoreSkipOperations: !0,
1413
- reuseHash: !p
1414
- }), v);
1415
- if (!p)
1416
- for (const c of Object.keys(T.state))
1417
- for (let l = b.length - 1; l >= 0; l--) {
1418
- const u = b[l];
1419
- if (u.scope === c) {
1420
- if (u.hash !== jt(T, c))
1421
- throw new Error(`Hash mismatch for scope ${c}`);
1422
- break;
1423
- }
1424
- }
1425
- const P = Object.keys(
1426
- T.operations
1427
- ).reduce(
1428
- (c, l) => {
1429
- const u = l;
1430
- return {
1431
- ...c,
1432
- [u]: [
1433
- ...T.operations[u].map((_, F) => {
1434
- var M;
1435
- return {
1436
- ..._,
1437
- timestamp: ((M = e[u][F]) == null ? void 0 : M.timestamp) ?? _.timestamp
1438
- };
1439
- })
1440
- ]
1441
- };
1442
- },
1443
- { global: [], local: [] }
1444
- ), C = Object.values(P).reduce((c, l) => {
1445
- const u = l[l.length - 1];
1446
- return (u == null ? void 0 : u.timestamp) > c && (c = u.timestamp), c;
1447
- }, t.lastModified);
1448
- return { ...T, operations: P, lastModified: C };
1449
- }
1450
- function jn(t, e) {
1451
- return K(t) === K(e);
1452
- }
1453
- function ee(t) {
1454
- const e = typeof t;
1455
- if (e === "string")
1456
- return JSON.parse(t);
1457
- if (e === "object")
1458
- return t;
1459
- throw new Error(`Providing resulting state is of type: ${e}`);
1460
- }
1461
- const ne = (t) => W(
1462
- "SET_NAME",
1463
- t,
1464
- void 0,
1465
- bt,
1466
- void 0
1467
- ), ie = (t = 1, e = "global") => W(
1468
- "UNDO",
1469
- t,
1470
- void 0,
1471
- wt,
1472
- e
1473
- ), oe = (t = 1, e = "global") => W(
1474
- "REDO",
1475
- t,
1476
- void 0,
1477
- yt,
1478
- e
1479
- ), se = (t, e, n = "global") => W(
1480
- "PRUNE",
1481
- { start: t, end: e },
1482
- void 0,
1483
- xt,
1484
- n
1485
- ), Et = (t, e) => W(
1486
- "LOAD_STATE",
1487
- { state: t, operations: e },
1488
- void 0,
1489
- ht
1490
- ), re = (t = "global") => W("NOOP", {}, void 0, void 0, t), En = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1491
- __proto__: null,
1492
- loadState: Et,
1493
- noop: re,
1494
- prune: se,
1495
- redo: oe,
1496
- setName: ne,
1497
- undo: ie
1498
- }, Symbol.toStringTag, { value: "Module" }));
1499
- class $n {
1500
- /**
1501
- * Constructs a BaseDocument instance with an initial state.
1502
- * @param reducer - The reducer function that updates the state.
1503
- * @param document - The initial state of the document.
1504
- */
1505
- constructor(e, n, i) {
1506
- st(this, "_document");
1507
- st(this, "_reducer");
1508
- st(this, "_signalDispatch");
1509
- this._reducer = e, this._document = n, this._signalDispatch = i;
1510
- }
1511
- /**
1512
- * Dispatches an action to update the state of the document.
1513
- * @param action - The action to dispatch.
1514
- * @returns The Document instance.
1515
- */
1516
- dispatch(e, n) {
1517
- return this._document = this._reducer(
1518
- this._document,
1519
- e,
1520
- this._signalDispatch,
1521
- n
1522
- ), this;
1523
- }
1524
- /**
1525
- * Saves the state of the document to a file.
1526
- * @param path - The file path where the state should be saved.
1527
- * @param extension - The file extension to use when saving the state.
1528
- * @returns The file path where the state was saved.
1529
- */
1530
- saveToFile(e, n, i) {
1531
- return Pe(this._document, e, n, i);
1532
- }
1533
- /**
1534
- * Loads the state of the document from a file.
1535
- * @param path - The file path where the state is stored.
1536
- */
1537
- async loadFromFile(e) {
1538
- this._document = await $t(e, this._reducer);
1539
- }
1540
- /**
1541
- * Loads the state of the document from a file and returns it.
1542
- * @param path - The file path where the state is stored.
1543
- * @param reducer - The reducer function that updates the state.
1544
- * @returns The state of the document.
1545
- */
1546
- static async stateFromFile(e, n) {
1547
- return await $t(e, n);
1548
- }
1549
- /**
1550
- * Gets the current state of the document.
1551
- */
1552
- get state() {
1553
- return rt(this._document.state);
1554
- }
1555
- /**
1556
- * Gets the list of operations performed on the document.
1557
- */
1558
- get operations() {
1559
- return rt(this._document.operations);
1560
- }
1561
- /**
1562
- * Gets the name of the document.
1563
- */
1564
- get name() {
1565
- return this._document.name;
1566
- }
1567
- /**
1568
- * Gets the type of document.
1569
- */
1570
- get documentType() {
1571
- return this._document.documentType;
1572
- }
1573
- /**
1574
- * Gets the timestamp of the date the document was created.
1575
- */
1576
- get created() {
1577
- return this._document.created;
1578
- }
1579
- /**
1580
- * Gets the timestamp of the date the document was last modified.
1581
- */
1582
- get lastModified() {
1583
- return this._document.lastModified;
1584
- }
1585
- /**
1586
- * Gets the global revision number of the document.
1587
- */
1588
- get revision() {
1589
- return this._document.revision.global;
1590
- }
1591
- getRevision(e) {
1592
- return this._document.revision[e];
1593
- }
1594
- /**
1595
- * Gets the initial state of the document.
1596
- */
1597
- get initialState() {
1598
- return rt(this._document.initialState);
1599
- }
1600
- /**
1601
- * Returns the current document as an object
1602
- */
1603
- toDocument() {
1604
- return rt(this._document);
1605
- }
1606
- /**
1607
- * Gets the attachment associated with the given key.
1608
- * @param attachment - The key of the attachment to retrieve.
1609
- */
1610
- getAttachment(e) {
1611
- return this._document.attachments[e];
1612
- }
1613
- /**
1614
- * Sets the name of the document.
1615
- * @param name - The new name of the document.
1616
- */
1617
- setName(e) {
1618
- return this.dispatch(ne(e)), this;
1619
- }
1620
- /**
1621
- * Reverts a number of actions from the document.
1622
- * @param count - The number of actions to revert.
1623
- */
1624
- undo(e) {
1625
- return this.dispatch(ie(e)), this;
1626
- }
1627
- /**
1628
- * Reapplies a number of actions to the document.
1629
- * @param count - The number of actions to reapply.
1630
- */
1631
- redo(e) {
1632
- return this.dispatch(oe(e)), this;
1633
- }
1634
- /**
1635
- * Removes a range of operations from the document.
1636
- * @param start - The starting index of the range to remove.
1637
- * @param end - The ending index of the range to remove.
1638
- */
1639
- prune(e, n) {
1640
- return this.dispatch(se(e, n)), this;
1641
- }
1642
- /**
1643
- * Loads a document state and a set of operations.
1644
- * @param state - The state to load.
1645
- * @param operations - The operations to apply to the document.
1646
- */
1647
- loadState(e, n) {
1648
- return this.dispatch(Et(e, n)), this;
1649
- }
1650
- }
1651
- function kn(t, e) {
1652
- e.forEach((n) => {
1653
- Object.getOwnPropertyNames(n.prototype).forEach((i) => {
1654
- Object.defineProperty(
1655
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
1656
- t.prototype,
1657
- i,
1658
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
1659
- Object.getOwnPropertyDescriptor(n.prototype, i) || /* @__PURE__ */ Object.create(null)
1660
- );
1661
- });
1662
- });
1663
- }
1664
- export {
1665
- Sn as A,
1666
- $n as B,
1667
- On as C,
1668
- Ae as D,
1669
- Yt as E,
1670
- gn as F,
1671
- ln as G,
1672
- Ye as a,
1673
- tn as b,
1674
- Qe as c,
1675
- mn as d,
1676
- Me as e,
1677
- W as f,
1678
- kn as g,
1679
- En as h,
1680
- kt as i,
1681
- wn as j,
1682
- Xt as k,
1683
- $t as l,
1684
- dn as m,
1685
- fn as n,
1686
- un as o,
1687
- jt as p,
1688
- yn as q,
1689
- hn as r,
1690
- Pe as s,
1691
- jn as t,
1692
- xn as u,
1693
- bn as v,
1694
- ee as w,
1695
- rt as x,
1696
- te as y,
1697
- gt as z
1698
- };