document-model 1.1.0-debug.2 → 1.1.0-experimental.2

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 (140) hide show
  1. package/dist/browser/cjs/document-model.js +1 -21
  2. package/dist/browser/cjs/document.js +1 -15
  3. package/dist/browser/cjs/index.js +1 -18
  4. package/dist/browser/cjs/internal/index-DLodkpOq.js +22 -0
  5. package/dist/browser/cjs/internal/index-azT4DEce.js +1 -0
  6. package/dist/browser/cjs/internal/object-CMr-_AP8.js +25 -0
  7. package/dist/browser/es/document-model.js +15 -16
  8. package/dist/browser/es/document.js +9 -10
  9. package/dist/browser/es/index.js +11 -13
  10. package/dist/browser/es/internal/index-BzNpRs2a.js +44 -0
  11. package/dist/browser/es/internal/index-CL_1ivGq.js +2104 -0
  12. package/dist/browser/es/internal/object-FFc9n_3I.js +2789 -0
  13. package/dist/browser/src/document/object.d.ts +35 -0
  14. package/dist/browser/src/document/types.d.ts +6 -0
  15. package/dist/browser/src/document/utils/base.d.ts +5 -4
  16. package/dist/browser/src/document/utils/document-helpers.d.ts +1 -1
  17. package/dist/browser/src/document/utils/index.d.ts +1 -1
  18. package/dist/node/cjs/document-model.js +1 -25
  19. package/dist/node/cjs/document.js +1 -19
  20. package/dist/node/cjs/index.js +1 -22
  21. package/dist/node/cjs/internal/index-CPeTtUsk.js +22 -0
  22. package/dist/node/cjs/internal/index-CTavCc1t.js +1 -0
  23. package/dist/node/cjs/internal/object-DhI24-1e.js +20 -0
  24. package/dist/node/es/document-model.js +14 -15
  25. package/dist/node/es/document.js +9 -10
  26. package/dist/node/es/index.js +11 -13
  27. package/dist/node/es/internal/index-8lUz8qED.js +44 -0
  28. package/dist/node/es/internal/index-A880In4b.js +2108 -0
  29. package/dist/node/es/internal/object-C9n9Ijnt.js +1687 -0
  30. package/dist/node/src/document/object.d.ts +35 -0
  31. package/dist/node/src/document/types.d.ts +6 -0
  32. package/dist/node/src/document/utils/base.d.ts +5 -4
  33. package/dist/node/src/document/utils/document-helpers.d.ts +1 -1
  34. package/dist/node/src/document/utils/index.d.ts +1 -1
  35. package/package.json +1 -1
  36. package/CHANGELOG.md +0 -19
  37. package/dist/browser/cjs/document-model.js.map +0 -1
  38. package/dist/browser/cjs/document.js.map +0 -1
  39. package/dist/browser/cjs/index.js.map +0 -1
  40. package/dist/browser/cjs/internal/index-CaJbS06G.js +0 -2339
  41. package/dist/browser/cjs/internal/index-CaJbS06G.js.map +0 -1
  42. package/dist/browser/cjs/internal/index-kKIg6qNB.js +0 -44
  43. package/dist/browser/cjs/internal/index-kKIg6qNB.js.map +0 -1
  44. package/dist/browser/cjs/internal/object-B6dSDhtS.js +0 -4109
  45. package/dist/browser/cjs/internal/object-B6dSDhtS.js.map +0 -1
  46. package/dist/browser/es/document-model.js.map +0 -1
  47. package/dist/browser/es/document.js.map +0 -1
  48. package/dist/browser/es/index.js.map +0 -1
  49. package/dist/browser/es/internal/index-B1lQN59e.js +0 -2340
  50. package/dist/browser/es/internal/index-B1lQN59e.js.map +0 -1
  51. package/dist/browser/es/internal/index-Bu0CkmrW.js +0 -45
  52. package/dist/browser/es/internal/index-Bu0CkmrW.js.map +0 -1
  53. package/dist/browser/es/internal/object-9mR1JlXD.js +0 -4110
  54. package/dist/browser/es/internal/object-9mR1JlXD.js.map +0 -1
  55. package/dist/node/cjs/document-model.js.map +0 -1
  56. package/dist/node/cjs/document.js.map +0 -1
  57. package/dist/node/cjs/index.js.map +0 -1
  58. package/dist/node/cjs/internal/index-AqiVmL0w.js +0 -44
  59. package/dist/node/cjs/internal/index-AqiVmL0w.js.map +0 -1
  60. package/dist/node/cjs/internal/index-ajqhOWQ1.js +0 -2343
  61. package/dist/node/cjs/internal/index-ajqhOWQ1.js.map +0 -1
  62. package/dist/node/cjs/internal/object-D_9h7jBN.js +0 -2111
  63. package/dist/node/cjs/internal/object-D_9h7jBN.js.map +0 -1
  64. package/dist/node/es/document-model.js.map +0 -1
  65. package/dist/node/es/document.js.map +0 -1
  66. package/dist/node/es/index.js.map +0 -1
  67. package/dist/node/es/internal/index-Bh_09edy.js +0 -2344
  68. package/dist/node/es/internal/index-Bh_09edy.js.map +0 -1
  69. package/dist/node/es/internal/index-s6NFw7Kq.js +0 -45
  70. package/dist/node/es/internal/index-s6NFw7Kq.js.map +0 -1
  71. package/dist/node/es/internal/object-CbITi4iq.js +0 -2112
  72. package/dist/node/es/internal/object-CbITi4iq.js.map +0 -1
  73. package/dist/src/document/actions/creators.d.ts +0 -47
  74. package/dist/src/document/actions/index.d.ts +0 -14
  75. package/dist/src/document/actions/types.d.ts +0 -15
  76. package/dist/src/document/index.d.ts +0 -6
  77. package/dist/src/document/object.d.ts +0 -1175
  78. package/dist/src/document/reducer.d.ts +0 -43
  79. package/dist/src/document/schema/index.d.ts +0 -2
  80. package/dist/src/document/schema/types.d.ts +0 -176
  81. package/dist/src/document/schema/zod.d.ts +0 -113
  82. package/dist/src/document/signal.d.ts +0 -29
  83. package/dist/src/document/types.d.ts +0 -249
  84. package/dist/src/document/utils/base.d.ts +0 -85
  85. package/dist/src/document/utils/document-helpers.d.ts +0 -53
  86. package/dist/src/document/utils/file.d.ts +0 -48
  87. package/dist/src/document/utils/index.d.ts +0 -5
  88. package/dist/src/document/utils/node.d.ts +0 -9
  89. package/dist/src/document/utils/validation.d.ts +0 -2
  90. package/dist/src/document-model/custom/reducers/header.d.ts +0 -2
  91. package/dist/src/document-model/custom/reducers/module.d.ts +0 -2
  92. package/dist/src/document-model/custom/reducers/operation-error.d.ts +0 -2
  93. package/dist/src/document-model/custom/reducers/operation-example.d.ts +0 -2
  94. package/dist/src/document-model/custom/reducers/operation.d.ts +0 -2
  95. package/dist/src/document-model/custom/reducers/state.d.ts +0 -2
  96. package/dist/src/document-model/custom/reducers/versioning.d.ts +0 -7
  97. package/dist/src/document-model/custom/utils.d.ts +0 -7
  98. package/dist/src/document-model/gen/actions.d.ts +0 -15
  99. package/dist/src/document-model/gen/creators.d.ts +0 -7
  100. package/dist/src/document-model/gen/document-model.d.ts +0 -2
  101. package/dist/src/document-model/gen/header/actions.d.ts +0 -9
  102. package/dist/src/document-model/gen/header/creators.d.ts +0 -8
  103. package/dist/src/document-model/gen/header/object.d.ts +0 -12
  104. package/dist/src/document-model/gen/header/operations.d.ts +0 -10
  105. package/dist/src/document-model/gen/index.d.ts +0 -5
  106. package/dist/src/document-model/gen/module/actions.d.ts +0 -8
  107. package/dist/src/document-model/gen/module/creators.d.ts +0 -7
  108. package/dist/src/document-model/gen/module/object.d.ts +0 -11
  109. package/dist/src/document-model/gen/module/operations.d.ts +0 -9
  110. package/dist/src/document-model/gen/object.d.ts +0 -28
  111. package/dist/src/document-model/gen/operation/actions.d.ts +0 -13
  112. package/dist/src/document-model/gen/operation/creators.d.ts +0 -12
  113. package/dist/src/document-model/gen/operation/object.d.ts +0 -16
  114. package/dist/src/document-model/gen/operation/operations.d.ts +0 -14
  115. package/dist/src/document-model/gen/operation-error/actions.d.ts +0 -10
  116. package/dist/src/document-model/gen/operation-error/creators.d.ts +0 -9
  117. package/dist/src/document-model/gen/operation-error/object.d.ts +0 -13
  118. package/dist/src/document-model/gen/operation-error/operations.d.ts +0 -11
  119. package/dist/src/document-model/gen/operation-example/actions.d.ts +0 -7
  120. package/dist/src/document-model/gen/operation-example/creators.d.ts +0 -6
  121. package/dist/src/document-model/gen/operation-example/object.d.ts +0 -10
  122. package/dist/src/document-model/gen/operation-example/operations.d.ts +0 -8
  123. package/dist/src/document-model/gen/reducer.d.ts +0 -5
  124. package/dist/src/document-model/gen/schema/index.d.ts +0 -2
  125. package/dist/src/document-model/gen/schema/types.d.ts +0 -453
  126. package/dist/src/document-model/gen/schema/zod.d.ts +0 -453
  127. package/dist/src/document-model/gen/state/actions.d.ts +0 -9
  128. package/dist/src/document-model/gen/state/creators.d.ts +0 -8
  129. package/dist/src/document-model/gen/state/object.d.ts +0 -12
  130. package/dist/src/document-model/gen/state/operations.d.ts +0 -10
  131. package/dist/src/document-model/gen/types.d.ts +0 -8
  132. package/dist/src/document-model/gen/utils.d.ts +0 -6
  133. package/dist/src/document-model/gen/versioning/actions.d.ts +0 -8
  134. package/dist/src/document-model/gen/versioning/creators.d.ts +0 -7
  135. package/dist/src/document-model/gen/versioning/object.d.ts +0 -11
  136. package/dist/src/document-model/gen/versioning/operations.d.ts +0 -9
  137. package/dist/src/document-model/index.d.ts +0 -80
  138. package/dist/src/index.d.ts +0 -25
  139. package/dist/vite.config.d.ts +0 -2
  140. package/dist/vitest.config.d.ts +0 -2
@@ -0,0 +1,1687 @@
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) {
1091
+ if ([tt, et, ct].includes(e.type))
1092
+ return t;
1093
+ const { scope: i } = e, o = t.operations[i].slice(), a = o.at(-1);
1094
+ let r = ((a == null ? void 0 : a.index) ?? -1) + 1;
1095
+ if ("index" in e) {
1096
+ if (e.index - n > r)
1097
+ throw new Error(
1098
+ `Missing operations: expected ${r} with skip 0 or equivalent, got index ${e.index} with skip ${n}`
1099
+ );
1100
+ r = e.index;
1101
+ }
1102
+ return o.push({
1103
+ ...e,
1104
+ index: r,
1105
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1106
+ hash: "",
1107
+ scope: i,
1108
+ skip: n,
1109
+ error: void 0
1110
+ }), {
1111
+ ...t,
1112
+ operations: { ...t.operations, [i]: o }
1113
+ };
1114
+ }
1115
+ function We(t, e, n = 0) {
1116
+ let i = Ke(t, e, n);
1117
+ return i = Be(i, e), i;
1118
+ }
1119
+ function Ge(t, e, n) {
1120
+ switch (Pt().parse(e), e.type) {
1121
+ case qt:
1122
+ return Se(t, e.input);
1123
+ case ct:
1124
+ return $e(t, e, n);
1125
+ case Ut:
1126
+ return ke(t, e.input.state);
1127
+ default:
1128
+ return t;
1129
+ }
1130
+ }
1131
+ function gn(t, e, n) {
1132
+ switch (e.type) {
1133
+ case tt:
1134
+ return je(t, e, n);
1135
+ case et:
1136
+ return Ee(t, e, n);
1137
+ default:
1138
+ return { document: t, action: e, skip: n };
1139
+ }
1140
+ }
1141
+ function Ze(t, e, n, i, o = !1, a = ee) {
1142
+ const r = e.scope, p = t.operations[r].at(-1);
1143
+ if (!p)
1144
+ return t;
1145
+ const m = dt(
1146
+ {
1147
+ ...t.operations,
1148
+ [r]: Qt(
1149
+ t.operations[r],
1150
+ p
1151
+ )
1152
+ }
1153
+ );
1154
+ let d;
1155
+ const h = m[r].at(-1);
1156
+ if (o && (h != null && h.resultingState))
1157
+ d = a(
1158
+ h.resultingState
1159
+ );
1160
+ else {
1161
+ const { state: b } = gt(
1162
+ t.initialState,
1163
+ m,
1164
+ n,
1165
+ void 0,
1166
+ void 0,
1167
+ void 0,
1168
+ void 0,
1169
+ {
1170
+ reuseHash: !0,
1171
+ reuseOperationResultingState: o,
1172
+ operationResultingStateParser: a
1173
+ }
1174
+ );
1175
+ d = b[r];
1176
+ }
1177
+ return {
1178
+ ...t,
1179
+ state: {
1180
+ ...t.state,
1181
+ [r]: d
1182
+ },
1183
+ operations: dt({
1184
+ ...t.operations
1185
+ })
1186
+ };
1187
+ }
1188
+ function Yt(t, e, n, i, o = {}) {
1189
+ const {
1190
+ skip: a,
1191
+ ignoreSkipOperations: r = !1,
1192
+ reuseHash: p = !1,
1193
+ reuseOperationResultingState: m = !1,
1194
+ operationResultingStateParser: d
1195
+ } = o, h = { ...e }, b = a || 0;
1196
+ let O = { ...t };
1197
+ const v = !r && (b > 0 || "index" in h && h.skip > 0);
1198
+ return kt(h) && (O = Ge(O, h, n)), O = We(O, h, b), v && (O = Ze(
1199
+ O,
1200
+ h,
1201
+ n,
1202
+ b,
1203
+ m,
1204
+ d
1205
+ )), O = pt(O, (T) => {
1206
+ try {
1207
+ const P = n(
1208
+ T.state,
1209
+ h,
1210
+ i
1211
+ );
1212
+ if (P)
1213
+ return at({
1214
+ ...O,
1215
+ // clipboard: [...clipboardValue],
1216
+ state: P
1217
+ });
1218
+ } catch (P) {
1219
+ const C = O.operations[h.scope].length - 1;
1220
+ T.operations[h.scope][C].error = P.message, T.operations[h.scope][C].skip = 0, v && (T.state = at({ ...t.state }), T.operations = at({
1221
+ ...t.operations,
1222
+ [h.scope]: [
1223
+ ...t.operations[h.scope],
1224
+ {
1225
+ ...T.operations[h.scope][C]
1226
+ }
1227
+ ]
1228
+ }));
1229
+ }
1230
+ }), pt(O, (T) => {
1231
+ if ([tt, et, ct].includes(h.type))
1232
+ return T;
1233
+ const P = h.scope || "global", C = p && Object.prototype.hasOwnProperty.call(h, "hash") ? h.hash : jt(T, P);
1234
+ T.operations[P][T.operations[P].length - 1].hash = C, !kt(h) && h.attachments && h.attachments.forEach((c) => {
1235
+ const { hash: l, ...u } = c;
1236
+ T.attachments[l] = {
1237
+ ...u
1238
+ };
1239
+ });
1240
+ });
1241
+ }
1242
+ function hn(t) {
1243
+ return t.type === De && t.skip !== void 0 && t.skip > 0 && t.hash !== void 0;
1244
+ }
1245
+ function xn(t) {
1246
+ return [tt, et].includes(t.type);
1247
+ }
1248
+ function kt(t) {
1249
+ return [qt, tt, et, ct, Ut].includes(t.type);
1250
+ }
1251
+ function W(t, e, n, i, o = "global") {
1252
+ if (!t)
1253
+ throw new Error("Empty action type");
1254
+ if (typeof t != "string")
1255
+ throw new Error(`Invalid action type: ${JSON.stringify(t)}`);
1256
+ const a = { type: t, input: e, scope: o };
1257
+ n && (a.attachments = n);
1258
+ try {
1259
+ i == null || i().parse(a.input);
1260
+ } catch (r) {
1261
+ throw new Error(`Invalid action input: ${r}`);
1262
+ }
1263
+ return a;
1264
+ }
1265
+ function Qe(t, e = Yt) {
1266
+ return (n, i, o, a) => e(n, i, t, o, a);
1267
+ }
1268
+ const Ye = (t, e) => ({
1269
+ name: "",
1270
+ documentType: "",
1271
+ revision: {
1272
+ global: 0,
1273
+ local: 0
1274
+ },
1275
+ created: (/* @__PURE__ */ new Date()).toISOString(),
1276
+ lastModified: (/* @__PURE__ */ new Date()).toISOString(),
1277
+ attachments: {},
1278
+ ...t,
1279
+ state: (e == null ? void 0 : e(t == null ? void 0 : t.state)) ?? (t == null ? void 0 : t.state) ?? { global: {}, local: {} }
1280
+ }), tn = (t, e) => {
1281
+ const n = Ye(
1282
+ t,
1283
+ e
1284
+ );
1285
+ return {
1286
+ ...n,
1287
+ initialState: n,
1288
+ operations: { global: [], local: [] },
1289
+ clipboard: []
1290
+ };
1291
+ }, jt = (t, e = "global") => lt(K(t.state[e] || "")), yn = (t, e = 1e3) => {
1292
+ const n = Math.random() * e;
1293
+ return lt(`${(t ?? /* @__PURE__ */ new Date()).toISOString()}${n}`);
1294
+ };
1295
+ function rt(t) {
1296
+ return le(me(t, !0));
1297
+ }
1298
+ function bn(t, e) {
1299
+ const n = [...t];
1300
+ let i = e || 0, o = n.length > 0 ? n[n.length - 1].index : 0;
1301
+ const a = [];
1302
+ for (const r of n.reverse()) {
1303
+ if (i > 0) {
1304
+ const d = o - r.index;
1305
+ i -= d;
1306
+ }
1307
+ if (i < 0)
1308
+ throw new Error("Invalid operation index, missing operations");
1309
+ const p = {
1310
+ ignore: i > 0,
1311
+ operation: r
1312
+ }, m = r.skip > 0 ? r.skip + 1 : 0;
1313
+ if (m > 0 && m > i) {
1314
+ const d = m - i;
1315
+ i = i + d;
1316
+ }
1317
+ o = r.index, a.push(p);
1318
+ }
1319
+ return a.reverse();
1320
+ }
1321
+ function wn(t, e, n) {
1322
+ const i = t.slice().sort((p, m) => p.skip - m.skip).sort((p, m) => p.index - m.index);
1323
+ let o = n, a = 0, r = e;
1324
+ for (const p of i.reverse()) {
1325
+ const m = r - p.index;
1326
+ if (o = o - m, o > -1)
1327
+ a++, r = p.index;
1328
+ else
1329
+ break;
1330
+ }
1331
+ return a;
1332
+ }
1333
+ function On(t) {
1334
+ return Object.values(t).flatMap((e) => e).sort(
1335
+ (e, n) => new Date(e.timestamp).getTime() - new Date(n.timestamp).getTime()
1336
+ );
1337
+ }
1338
+ function Sn(t) {
1339
+ return Object.values(t).flatMap((e) => e).sort(
1340
+ (e, n) => new Date(e.operation.timestamp).getTime() - new Date(n.operation.timestamp).getTime()
1341
+ );
1342
+ }
1343
+ function gt(t, e, n, i, o, a = Yt, r = {}, p) {
1344
+ const m = Qe(n, a);
1345
+ return te(
1346
+ t,
1347
+ e,
1348
+ m,
1349
+ i,
1350
+ o,
1351
+ r,
1352
+ p
1353
+ );
1354
+ }
1355
+ function te(t, e, n, i, o, a = {}, r) {
1356
+ const {
1357
+ checkHashes: p = !0,
1358
+ reuseOperationResultingState: m,
1359
+ operationResultingStateParser: d = ee
1360
+ } = r || {};
1361
+ let h = t;
1362
+ const b = [], O = {
1363
+ global: [],
1364
+ local: []
1365
+ };
1366
+ if (m)
1367
+ for (const [c, l] of Object.entries(e)) {
1368
+ const u = l.findLastIndex(
1369
+ (F) => !!F.resultingState
1370
+ );
1371
+ if (u < 0) {
1372
+ b.push(...l);
1373
+ continue;
1374
+ }
1375
+ const _ = l[u];
1376
+ try {
1377
+ const F = d(
1378
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-unnecessary-type-assertion
1379
+ _.resultingState
1380
+ );
1381
+ h = {
1382
+ ...h,
1383
+ state: {
1384
+ ...h.state,
1385
+ // TODO how to deal with attachments?
1386
+ [c]: F
1387
+ }
1388
+ }, O[c].push(
1389
+ ...l.slice(0, u + 1)
1390
+ ), b.push(...l.slice(u + 1));
1391
+ } catch {
1392
+ b.push(...l);
1393
+ }
1394
+ }
1395
+ else
1396
+ b.push(...Object.values(e).flat());
1397
+ const v = tn(h);
1398
+ v.initialState = t, v.operations = O;
1399
+ const T = b.reduce((c, l) => n(c, l, i, {
1400
+ skip: l.skip,
1401
+ ignoreSkipOperations: !0,
1402
+ reuseHash: !p
1403
+ }), v);
1404
+ if (!p)
1405
+ for (const c of Object.keys(T.state))
1406
+ for (let l = b.length - 1; l >= 0; l--) {
1407
+ const u = b[l];
1408
+ if (u.scope === c) {
1409
+ if (u.hash !== jt(T, c))
1410
+ throw new Error(`Hash mismatch for scope ${c}`);
1411
+ break;
1412
+ }
1413
+ }
1414
+ const P = Object.keys(
1415
+ T.operations
1416
+ ).reduce(
1417
+ (c, l) => {
1418
+ const u = l;
1419
+ return {
1420
+ ...c,
1421
+ [u]: [
1422
+ ...T.operations[u].map((_, F) => {
1423
+ var M;
1424
+ return {
1425
+ ..._,
1426
+ timestamp: ((M = e[u][F]) == null ? void 0 : M.timestamp) ?? _.timestamp
1427
+ };
1428
+ })
1429
+ ]
1430
+ };
1431
+ },
1432
+ { global: [], local: [] }
1433
+ ), C = Object.values(P).reduce((c, l) => {
1434
+ const u = l[l.length - 1];
1435
+ return (u == null ? void 0 : u.timestamp) > c && (c = u.timestamp), c;
1436
+ }, t.lastModified);
1437
+ return { ...T, operations: P, lastModified: C };
1438
+ }
1439
+ function jn(t, e) {
1440
+ return K(t) === K(e);
1441
+ }
1442
+ function ee(t) {
1443
+ const e = typeof t;
1444
+ if (e === "string")
1445
+ return JSON.parse(t);
1446
+ if (e === "object")
1447
+ return t;
1448
+ throw new Error(`Providing resulting state is of type: ${e}`);
1449
+ }
1450
+ const ne = (t) => W(
1451
+ "SET_NAME",
1452
+ t,
1453
+ void 0,
1454
+ bt,
1455
+ void 0
1456
+ ), ie = (t = 1, e = "global") => W(
1457
+ "UNDO",
1458
+ t,
1459
+ void 0,
1460
+ wt,
1461
+ e
1462
+ ), oe = (t = 1, e = "global") => W(
1463
+ "REDO",
1464
+ t,
1465
+ void 0,
1466
+ yt,
1467
+ e
1468
+ ), se = (t, e, n = "global") => W(
1469
+ "PRUNE",
1470
+ { start: t, end: e },
1471
+ void 0,
1472
+ xt,
1473
+ n
1474
+ ), Et = (t, e) => W(
1475
+ "LOAD_STATE",
1476
+ { state: t, operations: e },
1477
+ void 0,
1478
+ ht
1479
+ ), re = (t = "global") => W("NOOP", {}, void 0, void 0, t), En = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1480
+ __proto__: null,
1481
+ loadState: Et,
1482
+ noop: re,
1483
+ prune: se,
1484
+ redo: oe,
1485
+ setName: ne,
1486
+ undo: ie
1487
+ }, Symbol.toStringTag, { value: "Module" }));
1488
+ class $n {
1489
+ /**
1490
+ * Constructs a BaseDocument instance with an initial state.
1491
+ * @param reducer - The reducer function that updates the state.
1492
+ * @param document - The initial state of the document.
1493
+ */
1494
+ constructor(e, n, i) {
1495
+ st(this, "_document");
1496
+ st(this, "_reducer");
1497
+ st(this, "_signalDispatch");
1498
+ this._reducer = e, this._document = n, this._signalDispatch = i;
1499
+ }
1500
+ /**
1501
+ * Dispatches an action to update the state of the document.
1502
+ * @param action - The action to dispatch.
1503
+ * @returns The Document instance.
1504
+ */
1505
+ dispatch(e, n) {
1506
+ return this._document = this._reducer(
1507
+ this._document,
1508
+ e,
1509
+ this._signalDispatch,
1510
+ n
1511
+ ), this;
1512
+ }
1513
+ /**
1514
+ * Saves the state of the document to a file.
1515
+ * @param path - The file path where the state should be saved.
1516
+ * @param extension - The file extension to use when saving the state.
1517
+ * @returns The file path where the state was saved.
1518
+ */
1519
+ saveToFile(e, n, i) {
1520
+ return Pe(this._document, e, n, i);
1521
+ }
1522
+ /**
1523
+ * Loads the state of the document from a file.
1524
+ * @param path - The file path where the state is stored.
1525
+ */
1526
+ async loadFromFile(e) {
1527
+ this._document = await $t(e, this._reducer);
1528
+ }
1529
+ /**
1530
+ * Loads the state of the document from a file and returns it.
1531
+ * @param path - The file path where the state is stored.
1532
+ * @param reducer - The reducer function that updates the state.
1533
+ * @returns The state of the document.
1534
+ */
1535
+ static async stateFromFile(e, n) {
1536
+ return await $t(e, n);
1537
+ }
1538
+ /**
1539
+ * Gets the current state of the document.
1540
+ */
1541
+ get state() {
1542
+ return rt(this._document.state);
1543
+ }
1544
+ /**
1545
+ * Gets the list of operations performed on the document.
1546
+ */
1547
+ get operations() {
1548
+ return rt(this._document.operations);
1549
+ }
1550
+ /**
1551
+ * Gets the name of the document.
1552
+ */
1553
+ get name() {
1554
+ return this._document.name;
1555
+ }
1556
+ /**
1557
+ * Gets the type of document.
1558
+ */
1559
+ get documentType() {
1560
+ return this._document.documentType;
1561
+ }
1562
+ /**
1563
+ * Gets the timestamp of the date the document was created.
1564
+ */
1565
+ get created() {
1566
+ return this._document.created;
1567
+ }
1568
+ /**
1569
+ * Gets the timestamp of the date the document was last modified.
1570
+ */
1571
+ get lastModified() {
1572
+ return this._document.lastModified;
1573
+ }
1574
+ /**
1575
+ * Gets the global revision number of the document.
1576
+ */
1577
+ get revision() {
1578
+ return this._document.revision.global;
1579
+ }
1580
+ getRevision(e) {
1581
+ return this._document.revision[e];
1582
+ }
1583
+ /**
1584
+ * Gets the initial state of the document.
1585
+ */
1586
+ get initialState() {
1587
+ return rt(this._document.initialState);
1588
+ }
1589
+ /**
1590
+ * Returns the current document as an object
1591
+ */
1592
+ toDocument() {
1593
+ return rt(this._document);
1594
+ }
1595
+ /**
1596
+ * Gets the attachment associated with the given key.
1597
+ * @param attachment - The key of the attachment to retrieve.
1598
+ */
1599
+ getAttachment(e) {
1600
+ return this._document.attachments[e];
1601
+ }
1602
+ /**
1603
+ * Sets the name of the document.
1604
+ * @param name - The new name of the document.
1605
+ */
1606
+ setName(e) {
1607
+ return this.dispatch(ne(e)), this;
1608
+ }
1609
+ /**
1610
+ * Reverts a number of actions from the document.
1611
+ * @param count - The number of actions to revert.
1612
+ */
1613
+ undo(e) {
1614
+ return this.dispatch(ie(e)), this;
1615
+ }
1616
+ /**
1617
+ * Reapplies a number of actions to the document.
1618
+ * @param count - The number of actions to reapply.
1619
+ */
1620
+ redo(e) {
1621
+ return this.dispatch(oe(e)), this;
1622
+ }
1623
+ /**
1624
+ * Removes a range of operations from the document.
1625
+ * @param start - The starting index of the range to remove.
1626
+ * @param end - The ending index of the range to remove.
1627
+ */
1628
+ prune(e, n) {
1629
+ return this.dispatch(se(e, n)), this;
1630
+ }
1631
+ /**
1632
+ * Loads a document state and a set of operations.
1633
+ * @param state - The state to load.
1634
+ * @param operations - The operations to apply to the document.
1635
+ */
1636
+ loadState(e, n) {
1637
+ return this.dispatch(Et(e, n)), this;
1638
+ }
1639
+ }
1640
+ function kn(t, e) {
1641
+ e.forEach((n) => {
1642
+ Object.getOwnPropertyNames(n.prototype).forEach((i) => {
1643
+ Object.defineProperty(
1644
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
1645
+ t.prototype,
1646
+ i,
1647
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
1648
+ Object.getOwnPropertyDescriptor(n.prototype, i) || /* @__PURE__ */ Object.create(null)
1649
+ );
1650
+ });
1651
+ });
1652
+ }
1653
+ export {
1654
+ Sn as A,
1655
+ $n as B,
1656
+ On as C,
1657
+ Ae as D,
1658
+ Yt as E,
1659
+ gn as F,
1660
+ ln as G,
1661
+ Ye as a,
1662
+ tn as b,
1663
+ Qe as c,
1664
+ mn as d,
1665
+ Me as e,
1666
+ W as f,
1667
+ kn as g,
1668
+ En as h,
1669
+ kt as i,
1670
+ wn as j,
1671
+ Xt as k,
1672
+ $t as l,
1673
+ dn as m,
1674
+ fn as n,
1675
+ un as o,
1676
+ jt as p,
1677
+ yn as q,
1678
+ hn as r,
1679
+ Pe as s,
1680
+ jn as t,
1681
+ xn as u,
1682
+ bn as v,
1683
+ ee as w,
1684
+ rt as x,
1685
+ te as y,
1686
+ gt as z
1687
+ };