document-model 1.0.27 → 1.0.28

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 (31) hide show
  1. package/dist/browser/document-model.cjs +1 -1
  2. package/dist/browser/document-model.js +7 -8
  3. package/dist/browser/document.cjs +1 -1
  4. package/dist/browser/document.js +9 -13
  5. package/dist/browser/index.cjs +1 -1
  6. package/dist/browser/index.js +8 -13
  7. package/dist/{node/internal/index-2d55ed8c.js → browser/internal/index-FBdtB-Z0.js} +1 -1
  8. package/dist/{node/internal/index-78c035e1.js → browser/internal/index-MQO6aDba.js} +1 -1
  9. package/dist/browser/internal/{index-ff67644b.js → index-oR1tzXEU.js} +1 -1
  10. package/dist/browser/internal/{index-99f8b333.js → index-qiOnVXbI.js} +1 -1
  11. package/dist/browser/internal/object-P7bHOWu_.js +1912 -0
  12. package/dist/browser/internal/object-RV2GJjkF.js +6 -0
  13. package/dist/browser/vitest.config.d.ts +1 -1
  14. package/dist/node/document-model.cjs +1 -1
  15. package/dist/node/document-model.js +10 -11
  16. package/dist/node/document.cjs +1 -1
  17. package/dist/node/document.js +9 -17
  18. package/dist/node/index.cjs +1 -1
  19. package/dist/node/index.js +8 -17
  20. package/dist/{browser/internal/index-e019b5aa.js → node/internal/index-E6Dehju3.js} +1 -1
  21. package/dist/{browser/internal/index-df4df518.js → node/internal/index-Rc3pWGDQ.js} +1 -1
  22. package/dist/node/internal/{index-433d6a9b.js → index-r_Cve_NX.js} +1 -1
  23. package/dist/node/internal/{index-a46dcf07.js → index-uFGJxYP7.js} +1 -1
  24. package/dist/node/internal/object-51-uoy0f.js +1 -0
  25. package/dist/node/internal/object-qR4Tf50L.js +911 -0
  26. package/dist/node/vitest.config.d.ts +1 -1
  27. package/package.json +2 -2
  28. package/dist/browser/internal/object-4b5800c0.js +0 -1891
  29. package/dist/browser/internal/object-be1b0c52.js +0 -6
  30. package/dist/node/internal/object-305e4c59.js +0 -893
  31. package/dist/node/internal/object-ff6617a2.js +0 -1
@@ -1,1891 +0,0 @@
1
- var Ae = Object.defineProperty;
2
- var Se = (i, o, p) => o in i ? Ae(i, o, { enumerable: !0, configurable: !0, writable: !0, value: p }) : i[o] = p;
3
- var H = (i, o, p) => (Se(i, typeof o != "symbol" ? o + "" : o, p), p);
4
- import { produce as Y, castDraft as rt, castImmutable as Be, freeze as ke } from "immer";
5
- import je from "json-stringify-deterministic";
6
- import { z as g } from "zod";
7
- import jt from "jszip";
8
- const It = (i) => i != null, Ie = g.any().refine((i) => It(i)), Ut = g.enum(["LOAD_STATE"]), Ot = g.enum(["PRUNE"]), Tt = g.enum(["REDO"]), Dt = g.enum(["SET_NAME"]), Nt = g.enum(["UNDO"]);
9
- function Ue() {
10
- return g.object({
11
- __typename: g.literal("Action").optional(),
12
- type: g.string()
13
- });
14
- }
15
- function q() {
16
- return g.literal("global").or(g.literal("local"));
17
- }
18
- function Rt() {
19
- return g.union([
20
- Mt(),
21
- Lt(),
22
- zt(),
23
- qt(),
24
- $t()
25
- ]);
26
- }
27
- function Oe() {
28
- return g.object({
29
- __typename: g.literal("DocumentFile").optional(),
30
- data: g.string(),
31
- extension: g.string().nullable(),
32
- fileName: g.string().nullable(),
33
- mimeType: g.string()
34
- });
35
- }
36
- function Mt() {
37
- return g.object({
38
- input: g.lazy(() => at()),
39
- type: Ut,
40
- scope: q()
41
- });
42
- }
43
- function at() {
44
- return g.object({
45
- operations: g.number(),
46
- state: g.lazy(() => Ct())
47
- });
48
- }
49
- function Ct() {
50
- return g.object({
51
- data: g.unknown().nullish(),
52
- name: g.string()
53
- });
54
- }
55
- function Te() {
56
- return g.object({
57
- __typename: g.literal("Operation").optional(),
58
- hash: g.string(),
59
- index: g.number(),
60
- timestamp: g.string().datetime(),
61
- type: g.string()
62
- });
63
- }
64
- function Lt() {
65
- return g.object({
66
- input: g.lazy(() => pt()),
67
- type: Ot,
68
- scope: q()
69
- });
70
- }
71
- function pt() {
72
- return g.object({
73
- end: g.number().nullish(),
74
- start: g.number().nullish()
75
- });
76
- }
77
- const st = g.number;
78
- function zt() {
79
- return g.object({
80
- input: st(),
81
- type: Tt,
82
- scope: q()
83
- });
84
- }
85
- const ct = g.string;
86
- function qt() {
87
- return g.object({
88
- input: ct(),
89
- type: Dt,
90
- scope: g.literal("global")
91
- });
92
- }
93
- function De() {
94
- return g.object({
95
- __typename: g.literal("SetNameOperation").optional(),
96
- hash: g.string(),
97
- index: g.number(),
98
- input: g.string(),
99
- timestamp: g.string().datetime(),
100
- type: g.string()
101
- });
102
- }
103
- const lt = g.number;
104
- function $t() {
105
- return g.object({
106
- input: lt(),
107
- type: Nt,
108
- scope: q()
109
- });
110
- }
111
- const Dr = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
112
- __proto__: null,
113
- ActionSchema: Ue,
114
- BaseActionSchema: Rt,
115
- DocumentFileSchema: Oe,
116
- LoadStateActionInputSchema: at,
117
- LoadStateActionSchema: Mt,
118
- LoadStateActionStateInputSchema: Ct,
119
- Load_StateSchema: Ut,
120
- OperationSchema: Te,
121
- OperationScopeSchema: q,
122
- PruneActionInputSchema: pt,
123
- PruneActionSchema: Lt,
124
- PruneSchema: Ot,
125
- RedoActionInputSchema: st,
126
- RedoActionSchema: zt,
127
- RedoSchema: Tt,
128
- SetNameActionInputSchema: ct,
129
- SetNameActionSchema: qt,
130
- SetNameOperationSchema: De,
131
- Set_NameSchema: Dt,
132
- UndoActionInputSchema: lt,
133
- UndoActionSchema: $t,
134
- UndoSchema: Nt,
135
- definedNonNullAnySchema: Ie,
136
- isDefinedNonNullAny: It
137
- }, Symbol.toStringTag, { value: "Module" }));
138
- function Ne(i, o) {
139
- return { ...i, name: o };
140
- }
141
- function Re(i, o, p) {
142
- const { scope: c, input: u } = o;
143
- return Y({
144
- document: i,
145
- action: o,
146
- skip: p
147
- }, (l) => {
148
- if (l.document.operations[c].length < 1)
149
- throw new Error(
150
- `Cannot undo: no operations in history for scope "${c}"`
151
- );
152
- if (u < 1)
153
- throw new Error(
154
- "Invalid UNDO action: input value must be greater than 0"
155
- );
156
- if (l.skip > 0)
157
- throw new Error(
158
- "Cannot undo: skip value from reducer cannot be used with UNDO action"
159
- );
160
- const [a] = l.document.operations[c].slice(-1), x = a.type === "NOOP" && a.skip > 0;
161
- if (l.skip += u, x && (l.skip += a.skip, l.document.operations[c].pop()), l.document.operations[c].length < l.skip)
162
- throw new Error(
163
- "Cannot undo: you can't undo more operations than the ones in the scope history"
164
- );
165
- const d = l.document.operations[c].length - 1;
166
- let E = u, w = x ? d - a.skip : d;
167
- for (; E > 0 && w >= 0; ) {
168
- const v = l.document.operations[c][w];
169
- v.type === "NOOP" && v.skip > 0 ? (w = w - (v.skip + 1), l.skip += v.skip + 1) : (l.document.clipboard.push({ ...v }), E--, w--);
170
- }
171
- l.action = mt(c);
172
- });
173
- }
174
- function Me(i, o, p) {
175
- const { scope: c, input: u } = o;
176
- return Y({
177
- document: i,
178
- action: o,
179
- skip: p
180
- }, (l) => {
181
- if (l.skip > 0)
182
- throw new Error(
183
- "Cannot redo: skip value from reducer cannot be used with REDO action"
184
- );
185
- if (u > 1)
186
- throw new Error(
187
- "Cannot redo: you can only redo one operation at a time"
188
- );
189
- if (u < 1)
190
- throw new Error("Invalid REDO action: invalid redo input value");
191
- if (l.document.clipboard.length < 1)
192
- throw new Error("Cannot redo: no operations in the clipboard");
193
- const a = l.document.clipboard.findLastIndex(
194
- (d) => d.scope === c
195
- );
196
- if (a < 0)
197
- throw new Error(
198
- `Cannot redo: no operations in clipboard for scope "${c}"`
199
- );
200
- const x = l.document.clipboard.splice(a, 1)[0];
201
- l.action = rt({
202
- type: x.type,
203
- scope: x.scope,
204
- input: x.input
205
- });
206
- });
207
- }
208
- function Ce(i, o, p) {
209
- const { scope: c } = o, u = i.operations[c];
210
- let {
211
- input: { start: h, end: l }
212
- } = o;
213
- h = h || 0, l = l || u.length;
214
- const a = u.slice(h, l), x = u.slice(0, h), d = u.slice(l), E = ot(
215
- i.initialState,
216
- {
217
- ...i.operations,
218
- [c]: x.concat(a)
219
- },
220
- p
221
- ), { name: w, state: v } = E, y = x.length, U = x.length ? x[x.length - 1].timestamp : d.length ? d[0].timestamp : (/* @__PURE__ */ new Date()).toISOString();
222
- return ot(
223
- i.initialState,
224
- {
225
- ...i.operations,
226
- [c]: [
227
- ...x,
228
- {
229
- ...ht(
230
- { name: w, state: v },
231
- a.length
232
- ),
233
- timestamp: U,
234
- index: y,
235
- hash: Qt({ state: v }, "global")
236
- },
237
- ...d.map((j, z) => ({
238
- ...j,
239
- index: y + z + 1
240
- }))
241
- ]
242
- },
243
- p
244
- );
245
- }
246
- function Le(i, o) {
247
- return {
248
- ...i,
249
- name: o.name,
250
- state: o.state ?? { global: {}, local: {} }
251
- };
252
- }
253
- const Pt = "SET_NAME", M = "UNDO", C = "REDO", $ = "PRUNE", Jt = "LOAD_STATE";
254
- function ze(i, o) {
255
- const p = i.revision[o.scope];
256
- return [M, C, $].includes(o.type) ? p : p + 1;
257
- }
258
- function qe(i, o) {
259
- return {
260
- ...i,
261
- revision: {
262
- ...i.revision,
263
- [o.scope]: ze(i, o)
264
- },
265
- lastModified: (/* @__PURE__ */ new Date()).toISOString()
266
- };
267
- }
268
- function $e(i, o, p = 0) {
269
- if ([M, C, $].includes(o.type))
270
- return i;
271
- const { scope: c } = o, u = i.operations[c].slice(
272
- 0,
273
- i.revision[c]
274
- );
275
- return u.push({
276
- ...o,
277
- index: u.length,
278
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
279
- hash: "",
280
- scope: c,
281
- skip: p
282
- }), {
283
- ...i,
284
- operations: { ...i.operations, [c]: u }
285
- };
286
- }
287
- function Pe(i, o, p = 0) {
288
- let c = $e(i, o, p);
289
- return c = qe(c, o), c;
290
- }
291
- function Je(i, o, p) {
292
- switch (Rt().parse(o), o.type) {
293
- case Pt:
294
- return Ne(i, o.input);
295
- case $:
296
- return Ce(i, o, p);
297
- case Jt:
298
- return Le(i, o.input.state);
299
- default:
300
- return i;
301
- }
302
- }
303
- function We(i, o, p) {
304
- switch (o.type) {
305
- case M:
306
- return Re(i, o, p);
307
- case C:
308
- return Me(i, o, p);
309
- default:
310
- return { document: i, action: o, skip: p };
311
- }
312
- }
313
- function Wt(i, o, p, c, u = {}) {
314
- const { skip: h, ignoreSkipOperations: l = !1 } = u;
315
- let a = { ...o }, x = h || 0, d = i, E = [...i.clipboard];
316
- if (St(a)) {
317
- const {
318
- skip: w,
319
- action: v,
320
- document: y
321
- } = We(i, a, x);
322
- a = v, x = w, d = y, E = [...d.clipboard];
323
- }
324
- return Bt(a) && (d = Je(d, a, p)), x > 0 && !l && (d = ot(
325
- d.initialState,
326
- d.operations,
327
- p,
328
- void 0,
329
- void 0,
330
- void 0,
331
- { [a.scope]: x }
332
- )), d = Pe(d, a, x), d = Y(d, (w) => {
333
- const v = p(
334
- w.state,
335
- a,
336
- c
337
- ), y = St(o) ? [...E] : [];
338
- if (v)
339
- return rt({
340
- ...d,
341
- clipboard: [...y],
342
- state: v
343
- });
344
- w.clipboard = rt([...y]);
345
- }), Y(d, (w) => {
346
- if ([M, C, $].includes(a.type))
347
- return w;
348
- const v = a.scope || "global";
349
- w.operations[v][w.operations[v].length - 1].hash = Qt(w, v), !Bt(a) && a.attachments && a.attachments.forEach((y) => {
350
- const { hash: U, ...j } = y;
351
- w.attachments[U] = {
352
- ...j
353
- };
354
- });
355
- });
356
- }
357
- function Ht(i) {
358
- return i && i.__esModule && Object.prototype.hasOwnProperty.call(i, "default") ? i.default : i;
359
- }
360
- var it = { exports: {} };
361
- typeof Object.create == "function" ? it.exports = function(o, p) {
362
- p && (o.super_ = p, o.prototype = Object.create(p.prototype, {
363
- constructor: {
364
- value: o,
365
- enumerable: !1,
366
- writable: !0,
367
- configurable: !0
368
- }
369
- }));
370
- } : it.exports = function(o, p) {
371
- if (p) {
372
- o.super_ = p;
373
- var c = function() {
374
- };
375
- c.prototype = p.prototype, o.prototype = new c(), o.prototype.constructor = o;
376
- }
377
- };
378
- var He = it.exports, nt = { exports: {} }, Zt = {}, K = {};
379
- K.byteLength = Ke;
380
- K.toByteArray = Xe;
381
- K.fromByteArray = tr;
382
- var T = [], I = [], Ze = typeof Uint8Array < "u" ? Uint8Array : Array, et = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
383
- for (var R = 0, Ye = et.length; R < Ye; ++R)
384
- T[R] = et[R], I[et.charCodeAt(R)] = R;
385
- I["-".charCodeAt(0)] = 62;
386
- I["_".charCodeAt(0)] = 63;
387
- function Yt(i) {
388
- var o = i.length;
389
- if (o % 4 > 0)
390
- throw new Error("Invalid string. Length must be a multiple of 4");
391
- var p = i.indexOf("=");
392
- p === -1 && (p = o);
393
- var c = p === o ? 0 : 4 - p % 4;
394
- return [p, c];
395
- }
396
- function Ke(i) {
397
- var o = Yt(i), p = o[0], c = o[1];
398
- return (p + c) * 3 / 4 - c;
399
- }
400
- function Ve(i, o, p) {
401
- return (o + p) * 3 / 4 - p;
402
- }
403
- function Xe(i) {
404
- var o, p = Yt(i), c = p[0], u = p[1], h = new Ze(Ve(i, c, u)), l = 0, a = u > 0 ? c - 4 : c, x;
405
- for (x = 0; x < a; x += 4)
406
- o = I[i.charCodeAt(x)] << 18 | I[i.charCodeAt(x + 1)] << 12 | I[i.charCodeAt(x + 2)] << 6 | I[i.charCodeAt(x + 3)], h[l++] = o >> 16 & 255, h[l++] = o >> 8 & 255, h[l++] = o & 255;
407
- return u === 2 && (o = I[i.charCodeAt(x)] << 2 | I[i.charCodeAt(x + 1)] >> 4, h[l++] = o & 255), u === 1 && (o = I[i.charCodeAt(x)] << 10 | I[i.charCodeAt(x + 1)] << 4 | I[i.charCodeAt(x + 2)] >> 2, h[l++] = o >> 8 & 255, h[l++] = o & 255), h;
408
- }
409
- function Ge(i) {
410
- return T[i >> 18 & 63] + T[i >> 12 & 63] + T[i >> 6 & 63] + T[i & 63];
411
- }
412
- function Qe(i, o, p) {
413
- for (var c, u = [], h = o; h < p; h += 3)
414
- c = (i[h] << 16 & 16711680) + (i[h + 1] << 8 & 65280) + (i[h + 2] & 255), u.push(Ge(c));
415
- return u.join("");
416
- }
417
- function tr(i) {
418
- for (var o, p = i.length, c = p % 3, u = [], h = 16383, l = 0, a = p - c; l < a; l += h)
419
- u.push(Qe(i, l, l + h > a ? a : l + h));
420
- return c === 1 ? (o = i[p - 1], u.push(
421
- T[o >> 2] + T[o << 4 & 63] + "=="
422
- )) : c === 2 && (o = (i[p - 2] << 8) + i[p - 1], u.push(
423
- T[o >> 10] + T[o >> 4 & 63] + T[o << 2 & 63] + "="
424
- )), u.join("");
425
- }
426
- var ut = {};
427
- /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
428
- ut.read = function(i, o, p, c, u) {
429
- var h, l, a = u * 8 - c - 1, x = (1 << a) - 1, d = x >> 1, E = -7, w = p ? u - 1 : 0, v = p ? -1 : 1, y = i[o + w];
430
- for (w += v, h = y & (1 << -E) - 1, y >>= -E, E += a; E > 0; h = h * 256 + i[o + w], w += v, E -= 8)
431
- ;
432
- for (l = h & (1 << -E) - 1, h >>= -E, E += c; E > 0; l = l * 256 + i[o + w], w += v, E -= 8)
433
- ;
434
- if (h === 0)
435
- h = 1 - d;
436
- else {
437
- if (h === x)
438
- return l ? NaN : (y ? -1 : 1) * (1 / 0);
439
- l = l + Math.pow(2, c), h = h - d;
440
- }
441
- return (y ? -1 : 1) * l * Math.pow(2, h - c);
442
- };
443
- ut.write = function(i, o, p, c, u, h) {
444
- var l, a, x, d = h * 8 - u - 1, E = (1 << d) - 1, w = E >> 1, v = u === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0, y = c ? 0 : h - 1, U = c ? 1 : -1, j = o < 0 || o === 0 && 1 / o < 0 ? 1 : 0;
445
- for (o = Math.abs(o), isNaN(o) || o === 1 / 0 ? (a = isNaN(o) ? 1 : 0, l = E) : (l = Math.floor(Math.log(o) / Math.LN2), o * (x = Math.pow(2, -l)) < 1 && (l--, x *= 2), l + w >= 1 ? o += v / x : o += v * Math.pow(2, 1 - w), o * x >= 2 && (l++, x /= 2), l + w >= E ? (a = 0, l = E) : l + w >= 1 ? (a = (o * x - 1) * Math.pow(2, u), l = l + w) : (a = o * Math.pow(2, w - 1) * Math.pow(2, u), l = 0)); u >= 8; i[p + y] = a & 255, y += U, a /= 256, u -= 8)
446
- ;
447
- for (l = l << u | a, d += u; d > 0; i[p + y] = l & 255, y += U, l /= 256, d -= 8)
448
- ;
449
- i[p + y - U] |= j * 128;
450
- };
451
- /*!
452
- * The buffer module from node.js, for the browser.
453
- *
454
- * @author Feross Aboukhadijeh <https://feross.org>
455
- * @license MIT
456
- */
457
- (function(i) {
458
- var o = K, p = ut, c = typeof Symbol == "function" && typeof Symbol.for == "function" ? Symbol.for("nodejs.util.inspect.custom") : null;
459
- i.Buffer = a, i.SlowBuffer = pe, i.INSPECT_MAX_BYTES = 50;
460
- var u = 2147483647;
461
- i.kMaxLength = u, a.TYPED_ARRAY_SUPPORT = h(), !a.TYPED_ARRAY_SUPPORT && typeof console < "u" && typeof console.error == "function" && console.error(
462
- "This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."
463
- );
464
- function h() {
465
- try {
466
- var r = new Uint8Array(1), t = { foo: function() {
467
- return 42;
468
- } };
469
- return Object.setPrototypeOf(t, Uint8Array.prototype), Object.setPrototypeOf(r, t), r.foo() === 42;
470
- } catch {
471
- return !1;
472
- }
473
- }
474
- Object.defineProperty(a.prototype, "parent", {
475
- enumerable: !0,
476
- get: function() {
477
- if (a.isBuffer(this))
478
- return this.buffer;
479
- }
480
- }), Object.defineProperty(a.prototype, "offset", {
481
- enumerable: !0,
482
- get: function() {
483
- if (a.isBuffer(this))
484
- return this.byteOffset;
485
- }
486
- });
487
- function l(r) {
488
- if (r > u)
489
- throw new RangeError('The value "' + r + '" is invalid for option "size"');
490
- var t = new Uint8Array(r);
491
- return Object.setPrototypeOf(t, a.prototype), t;
492
- }
493
- function a(r, t, e) {
494
- if (typeof r == "number") {
495
- if (typeof t == "string")
496
- throw new TypeError(
497
- 'The "string" argument must be of type string. Received type number'
498
- );
499
- return w(r);
500
- }
501
- return x(r, t, e);
502
- }
503
- a.poolSize = 8192;
504
- function x(r, t, e) {
505
- if (typeof r == "string")
506
- return v(r, t);
507
- if (ArrayBuffer.isView(r))
508
- return U(r);
509
- if (r == null)
510
- throw new TypeError(
511
- "The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof r
512
- );
513
- if (O(r, ArrayBuffer) || r && O(r.buffer, ArrayBuffer) || typeof SharedArrayBuffer < "u" && (O(r, SharedArrayBuffer) || r && O(r.buffer, SharedArrayBuffer)))
514
- return j(r, t, e);
515
- if (typeof r == "number")
516
- throw new TypeError(
517
- 'The "value" argument must not be of type number. Received type number'
518
- );
519
- var n = r.valueOf && r.valueOf();
520
- if (n != null && n !== r)
521
- return a.from(n, t, e);
522
- var s = z(r);
523
- if (s)
524
- return s;
525
- if (typeof Symbol < "u" && Symbol.toPrimitive != null && typeof r[Symbol.toPrimitive] == "function")
526
- return a.from(
527
- r[Symbol.toPrimitive]("string"),
528
- t,
529
- e
530
- );
531
- throw new TypeError(
532
- "The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof r
533
- );
534
- }
535
- a.from = function(r, t, e) {
536
- return x(r, t, e);
537
- }, Object.setPrototypeOf(a.prototype, Uint8Array.prototype), Object.setPrototypeOf(a, Uint8Array);
538
- function d(r) {
539
- if (typeof r != "number")
540
- throw new TypeError('"size" argument must be of type number');
541
- if (r < 0)
542
- throw new RangeError('The value "' + r + '" is invalid for option "size"');
543
- }
544
- function E(r, t, e) {
545
- return d(r), r <= 0 ? l(r) : t !== void 0 ? typeof e == "string" ? l(r).fill(t, e) : l(r).fill(t) : l(r);
546
- }
547
- a.alloc = function(r, t, e) {
548
- return E(r, t, e);
549
- };
550
- function w(r) {
551
- return d(r), l(r < 0 ? 0 : N(r) | 0);
552
- }
553
- a.allocUnsafe = function(r) {
554
- return w(r);
555
- }, a.allocUnsafeSlow = function(r) {
556
- return w(r);
557
- };
558
- function v(r, t) {
559
- if ((typeof t != "string" || t === "") && (t = "utf8"), !a.isEncoding(t))
560
- throw new TypeError("Unknown encoding: " + t);
561
- var e = xt(r, t) | 0, n = l(e), s = n.write(r, t);
562
- return s !== e && (n = n.slice(0, s)), n;
563
- }
564
- function y(r) {
565
- for (var t = r.length < 0 ? 0 : N(r.length) | 0, e = l(t), n = 0; n < t; n += 1)
566
- e[n] = r[n] & 255;
567
- return e;
568
- }
569
- function U(r) {
570
- if (O(r, Uint8Array)) {
571
- var t = new Uint8Array(r);
572
- return j(t.buffer, t.byteOffset, t.byteLength);
573
- }
574
- return y(r);
575
- }
576
- function j(r, t, e) {
577
- if (t < 0 || r.byteLength < t)
578
- throw new RangeError('"offset" is outside of buffer bounds');
579
- if (r.byteLength < t + (e || 0))
580
- throw new RangeError('"length" is outside of buffer bounds');
581
- var n;
582
- return t === void 0 && e === void 0 ? n = new Uint8Array(r) : e === void 0 ? n = new Uint8Array(r, t) : n = new Uint8Array(r, t, e), Object.setPrototypeOf(n, a.prototype), n;
583
- }
584
- function z(r) {
585
- if (a.isBuffer(r)) {
586
- var t = N(r.length) | 0, e = l(t);
587
- return e.length === 0 || r.copy(e, 0, 0, t), e;
588
- }
589
- if (r.length !== void 0)
590
- return typeof r.length != "number" || tt(r.length) ? l(0) : y(r);
591
- if (r.type === "Buffer" && Array.isArray(r.data))
592
- return y(r.data);
593
- }
594
- function N(r) {
595
- if (r >= u)
596
- throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x" + u.toString(16) + " bytes");
597
- return r | 0;
598
- }
599
- function pe(r) {
600
- return +r != r && (r = 0), a.alloc(+r);
601
- }
602
- a.isBuffer = function(t) {
603
- return t != null && t._isBuffer === !0 && t !== a.prototype;
604
- }, a.compare = function(t, e) {
605
- if (O(t, Uint8Array) && (t = a.from(t, t.offset, t.byteLength)), O(e, Uint8Array) && (e = a.from(e, e.offset, e.byteLength)), !a.isBuffer(t) || !a.isBuffer(e))
606
- throw new TypeError(
607
- 'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
608
- );
609
- if (t === e)
610
- return 0;
611
- for (var n = t.length, s = e.length, f = 0, m = Math.min(n, s); f < m; ++f)
612
- if (t[f] !== e[f]) {
613
- n = t[f], s = e[f];
614
- break;
615
- }
616
- return n < s ? -1 : s < n ? 1 : 0;
617
- }, a.isEncoding = function(t) {
618
- switch (String(t).toLowerCase()) {
619
- case "hex":
620
- case "utf8":
621
- case "utf-8":
622
- case "ascii":
623
- case "latin1":
624
- case "binary":
625
- case "base64":
626
- case "ucs2":
627
- case "ucs-2":
628
- case "utf16le":
629
- case "utf-16le":
630
- return !0;
631
- default:
632
- return !1;
633
- }
634
- }, a.concat = function(t, e) {
635
- if (!Array.isArray(t))
636
- throw new TypeError('"list" argument must be an Array of Buffers');
637
- if (t.length === 0)
638
- return a.alloc(0);
639
- var n;
640
- if (e === void 0)
641
- for (e = 0, n = 0; n < t.length; ++n)
642
- e += t[n].length;
643
- var s = a.allocUnsafe(e), f = 0;
644
- for (n = 0; n < t.length; ++n) {
645
- var m = t[n];
646
- if (O(m, Uint8Array))
647
- f + m.length > s.length ? a.from(m).copy(s, f) : Uint8Array.prototype.set.call(
648
- s,
649
- m,
650
- f
651
- );
652
- else if (a.isBuffer(m))
653
- m.copy(s, f);
654
- else
655
- throw new TypeError('"list" argument must be an Array of Buffers');
656
- f += m.length;
657
- }
658
- return s;
659
- };
660
- function xt(r, t) {
661
- if (a.isBuffer(r))
662
- return r.length;
663
- if (ArrayBuffer.isView(r) || O(r, ArrayBuffer))
664
- return r.byteLength;
665
- if (typeof r != "string")
666
- throw new TypeError(
667
- 'The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type ' + typeof r
668
- );
669
- var e = r.length, n = arguments.length > 2 && arguments[2] === !0;
670
- if (!n && e === 0)
671
- return 0;
672
- for (var s = !1; ; )
673
- switch (t) {
674
- case "ascii":
675
- case "latin1":
676
- case "binary":
677
- return e;
678
- case "utf8":
679
- case "utf-8":
680
- return Q(r).length;
681
- case "ucs2":
682
- case "ucs-2":
683
- case "utf16le":
684
- case "utf-16le":
685
- return e * 2;
686
- case "hex":
687
- return e >>> 1;
688
- case "base64":
689
- return _t(r).length;
690
- default:
691
- if (s)
692
- return n ? -1 : Q(r).length;
693
- t = ("" + t).toLowerCase(), s = !0;
694
- }
695
- }
696
- a.byteLength = xt;
697
- function se(r, t, e) {
698
- var n = !1;
699
- if ((t === void 0 || t < 0) && (t = 0), t > this.length || ((e === void 0 || e > this.length) && (e = this.length), e <= 0) || (e >>>= 0, t >>>= 0, e <= t))
700
- return "";
701
- for (r || (r = "utf8"); ; )
702
- switch (r) {
703
- case "hex":
704
- return we(this, t, e);
705
- case "utf8":
706
- case "utf-8":
707
- return wt(this, t, e);
708
- case "ascii":
709
- return de(this, t, e);
710
- case "latin1":
711
- case "binary":
712
- return ge(this, t, e);
713
- case "base64":
714
- return me(this, t, e);
715
- case "ucs2":
716
- case "ucs-2":
717
- case "utf16le":
718
- case "utf-16le":
719
- return ye(this, t, e);
720
- default:
721
- if (n)
722
- throw new TypeError("Unknown encoding: " + r);
723
- r = (r + "").toLowerCase(), n = !0;
724
- }
725
- }
726
- a.prototype._isBuffer = !0;
727
- function D(r, t, e) {
728
- var n = r[t];
729
- r[t] = r[e], r[e] = n;
730
- }
731
- a.prototype.swap16 = function() {
732
- var t = this.length;
733
- if (t % 2 !== 0)
734
- throw new RangeError("Buffer size must be a multiple of 16-bits");
735
- for (var e = 0; e < t; e += 2)
736
- D(this, e, e + 1);
737
- return this;
738
- }, a.prototype.swap32 = function() {
739
- var t = this.length;
740
- if (t % 4 !== 0)
741
- throw new RangeError("Buffer size must be a multiple of 32-bits");
742
- for (var e = 0; e < t; e += 4)
743
- D(this, e, e + 3), D(this, e + 1, e + 2);
744
- return this;
745
- }, a.prototype.swap64 = function() {
746
- var t = this.length;
747
- if (t % 8 !== 0)
748
- throw new RangeError("Buffer size must be a multiple of 64-bits");
749
- for (var e = 0; e < t; e += 8)
750
- D(this, e, e + 7), D(this, e + 1, e + 6), D(this, e + 2, e + 5), D(this, e + 3, e + 4);
751
- return this;
752
- }, a.prototype.toString = function() {
753
- var t = this.length;
754
- return t === 0 ? "" : arguments.length === 0 ? wt(this, 0, t) : se.apply(this, arguments);
755
- }, a.prototype.toLocaleString = a.prototype.toString, a.prototype.equals = function(t) {
756
- if (!a.isBuffer(t))
757
- throw new TypeError("Argument must be a Buffer");
758
- return this === t ? !0 : a.compare(this, t) === 0;
759
- }, a.prototype.inspect = function() {
760
- var t = "", e = i.INSPECT_MAX_BYTES;
761
- return t = this.toString("hex", 0, e).replace(/(.{2})/g, "$1 ").trim(), this.length > e && (t += " ... "), "<Buffer " + t + ">";
762
- }, c && (a.prototype[c] = a.prototype.inspect), a.prototype.compare = function(t, e, n, s, f) {
763
- if (O(t, Uint8Array) && (t = a.from(t, t.offset, t.byteLength)), !a.isBuffer(t))
764
- throw new TypeError(
765
- 'The "target" argument must be one of type Buffer or Uint8Array. Received type ' + typeof t
766
- );
767
- if (e === void 0 && (e = 0), n === void 0 && (n = t ? t.length : 0), s === void 0 && (s = 0), f === void 0 && (f = this.length), e < 0 || n > t.length || s < 0 || f > this.length)
768
- throw new RangeError("out of range index");
769
- if (s >= f && e >= n)
770
- return 0;
771
- if (s >= f)
772
- return -1;
773
- if (e >= n)
774
- return 1;
775
- if (e >>>= 0, n >>>= 0, s >>>= 0, f >>>= 0, this === t)
776
- return 0;
777
- for (var m = f - s, b = n - e, _ = Math.min(m, b), F = this.slice(s, f), B = t.slice(e, n), A = 0; A < _; ++A)
778
- if (F[A] !== B[A]) {
779
- m = F[A], b = B[A];
780
- break;
781
- }
782
- return m < b ? -1 : b < m ? 1 : 0;
783
- };
784
- function dt(r, t, e, n, s) {
785
- if (r.length === 0)
786
- return -1;
787
- if (typeof e == "string" ? (n = e, e = 0) : e > 2147483647 ? e = 2147483647 : e < -2147483648 && (e = -2147483648), e = +e, tt(e) && (e = s ? 0 : r.length - 1), e < 0 && (e = r.length + e), e >= r.length) {
788
- if (s)
789
- return -1;
790
- e = r.length - 1;
791
- } else if (e < 0)
792
- if (s)
793
- e = 0;
794
- else
795
- return -1;
796
- if (typeof t == "string" && (t = a.from(t, n)), a.isBuffer(t))
797
- return t.length === 0 ? -1 : gt(r, t, e, n, s);
798
- if (typeof t == "number")
799
- return t = t & 255, typeof Uint8Array.prototype.indexOf == "function" ? s ? Uint8Array.prototype.indexOf.call(r, t, e) : Uint8Array.prototype.lastIndexOf.call(r, t, e) : gt(r, [t], e, n, s);
800
- throw new TypeError("val must be string, number or Buffer");
801
- }
802
- function gt(r, t, e, n, s) {
803
- var f = 1, m = r.length, b = t.length;
804
- if (n !== void 0 && (n = String(n).toLowerCase(), n === "ucs2" || n === "ucs-2" || n === "utf16le" || n === "utf-16le")) {
805
- if (r.length < 2 || t.length < 2)
806
- return -1;
807
- f = 2, m /= 2, b /= 2, e /= 2;
808
- }
809
- function _(Ft, At) {
810
- return f === 1 ? Ft[At] : Ft.readUInt16BE(At * f);
811
- }
812
- var F;
813
- if (s) {
814
- var B = -1;
815
- for (F = e; F < m; F++)
816
- if (_(r, F) === _(t, B === -1 ? 0 : F - B)) {
817
- if (B === -1 && (B = F), F - B + 1 === b)
818
- return B * f;
819
- } else
820
- B !== -1 && (F -= F - B), B = -1;
821
- } else
822
- for (e + b > m && (e = m - b), F = e; F >= 0; F--) {
823
- for (var A = !0, W = 0; W < b; W++)
824
- if (_(r, F + W) !== _(t, W)) {
825
- A = !1;
826
- break;
827
- }
828
- if (A)
829
- return F;
830
- }
831
- return -1;
832
- }
833
- a.prototype.includes = function(t, e, n) {
834
- return this.indexOf(t, e, n) !== -1;
835
- }, a.prototype.indexOf = function(t, e, n) {
836
- return dt(this, t, e, n, !0);
837
- }, a.prototype.lastIndexOf = function(t, e, n) {
838
- return dt(this, t, e, n, !1);
839
- };
840
- function ce(r, t, e, n) {
841
- e = Number(e) || 0;
842
- var s = r.length - e;
843
- n ? (n = Number(n), n > s && (n = s)) : n = s;
844
- var f = t.length;
845
- n > f / 2 && (n = f / 2);
846
- for (var m = 0; m < n; ++m) {
847
- var b = parseInt(t.substr(m * 2, 2), 16);
848
- if (tt(b))
849
- return m;
850
- r[e + m] = b;
851
- }
852
- return m;
853
- }
854
- function le(r, t, e, n) {
855
- return J(Q(t, r.length - e), r, e, n);
856
- }
857
- function ue(r, t, e, n) {
858
- return J(Ee(t), r, e, n);
859
- }
860
- function fe(r, t, e, n) {
861
- return J(_t(t), r, e, n);
862
- }
863
- function he(r, t, e, n) {
864
- return J(_e(t, r.length - e), r, e, n);
865
- }
866
- a.prototype.write = function(t, e, n, s) {
867
- if (e === void 0)
868
- s = "utf8", n = this.length, e = 0;
869
- else if (n === void 0 && typeof e == "string")
870
- s = e, n = this.length, e = 0;
871
- else if (isFinite(e))
872
- e = e >>> 0, isFinite(n) ? (n = n >>> 0, s === void 0 && (s = "utf8")) : (s = n, n = void 0);
873
- else
874
- throw new Error(
875
- "Buffer.write(string, encoding, offset[, length]) is no longer supported"
876
- );
877
- var f = this.length - e;
878
- if ((n === void 0 || n > f) && (n = f), t.length > 0 && (n < 0 || e < 0) || e > this.length)
879
- throw new RangeError("Attempt to write outside buffer bounds");
880
- s || (s = "utf8");
881
- for (var m = !1; ; )
882
- switch (s) {
883
- case "hex":
884
- return ce(this, t, e, n);
885
- case "utf8":
886
- case "utf-8":
887
- return le(this, t, e, n);
888
- case "ascii":
889
- case "latin1":
890
- case "binary":
891
- return ue(this, t, e, n);
892
- case "base64":
893
- return fe(this, t, e, n);
894
- case "ucs2":
895
- case "ucs-2":
896
- case "utf16le":
897
- case "utf-16le":
898
- return he(this, t, e, n);
899
- default:
900
- if (m)
901
- throw new TypeError("Unknown encoding: " + s);
902
- s = ("" + s).toLowerCase(), m = !0;
903
- }
904
- }, a.prototype.toJSON = function() {
905
- return {
906
- type: "Buffer",
907
- data: Array.prototype.slice.call(this._arr || this, 0)
908
- };
909
- };
910
- function me(r, t, e) {
911
- return t === 0 && e === r.length ? o.fromByteArray(r) : o.fromByteArray(r.slice(t, e));
912
- }
913
- function wt(r, t, e) {
914
- e = Math.min(r.length, e);
915
- for (var n = [], s = t; s < e; ) {
916
- var f = r[s], m = null, b = f > 239 ? 4 : f > 223 ? 3 : f > 191 ? 2 : 1;
917
- if (s + b <= e) {
918
- var _, F, B, A;
919
- switch (b) {
920
- case 1:
921
- f < 128 && (m = f);
922
- break;
923
- case 2:
924
- _ = r[s + 1], (_ & 192) === 128 && (A = (f & 31) << 6 | _ & 63, A > 127 && (m = A));
925
- break;
926
- case 3:
927
- _ = r[s + 1], F = r[s + 2], (_ & 192) === 128 && (F & 192) === 128 && (A = (f & 15) << 12 | (_ & 63) << 6 | F & 63, A > 2047 && (A < 55296 || A > 57343) && (m = A));
928
- break;
929
- case 4:
930
- _ = r[s + 1], F = r[s + 2], B = r[s + 3], (_ & 192) === 128 && (F & 192) === 128 && (B & 192) === 128 && (A = (f & 15) << 18 | (_ & 63) << 12 | (F & 63) << 6 | B & 63, A > 65535 && A < 1114112 && (m = A));
931
- }
932
- }
933
- m === null ? (m = 65533, b = 1) : m > 65535 && (m -= 65536, n.push(m >>> 10 & 1023 | 55296), m = 56320 | m & 1023), n.push(m), s += b;
934
- }
935
- return xe(n);
936
- }
937
- var yt = 4096;
938
- function xe(r) {
939
- var t = r.length;
940
- if (t <= yt)
941
- return String.fromCharCode.apply(String, r);
942
- for (var e = "", n = 0; n < t; )
943
- e += String.fromCharCode.apply(
944
- String,
945
- r.slice(n, n += yt)
946
- );
947
- return e;
948
- }
949
- function de(r, t, e) {
950
- var n = "";
951
- e = Math.min(r.length, e);
952
- for (var s = t; s < e; ++s)
953
- n += String.fromCharCode(r[s] & 127);
954
- return n;
955
- }
956
- function ge(r, t, e) {
957
- var n = "";
958
- e = Math.min(r.length, e);
959
- for (var s = t; s < e; ++s)
960
- n += String.fromCharCode(r[s]);
961
- return n;
962
- }
963
- function we(r, t, e) {
964
- var n = r.length;
965
- (!t || t < 0) && (t = 0), (!e || e < 0 || e > n) && (e = n);
966
- for (var s = "", f = t; f < e; ++f)
967
- s += Fe[r[f]];
968
- return s;
969
- }
970
- function ye(r, t, e) {
971
- for (var n = r.slice(t, e), s = "", f = 0; f < n.length - 1; f += 2)
972
- s += String.fromCharCode(n[f] + n[f + 1] * 256);
973
- return s;
974
- }
975
- a.prototype.slice = function(t, e) {
976
- var n = this.length;
977
- t = ~~t, e = e === void 0 ? n : ~~e, t < 0 ? (t += n, t < 0 && (t = 0)) : t > n && (t = n), e < 0 ? (e += n, e < 0 && (e = 0)) : e > n && (e = n), e < t && (e = t);
978
- var s = this.subarray(t, e);
979
- return Object.setPrototypeOf(s, a.prototype), s;
980
- };
981
- function S(r, t, e) {
982
- if (r % 1 !== 0 || r < 0)
983
- throw new RangeError("offset is not uint");
984
- if (r + t > e)
985
- throw new RangeError("Trying to access beyond buffer length");
986
- }
987
- a.prototype.readUintLE = a.prototype.readUIntLE = function(t, e, n) {
988
- t = t >>> 0, e = e >>> 0, n || S(t, e, this.length);
989
- for (var s = this[t], f = 1, m = 0; ++m < e && (f *= 256); )
990
- s += this[t + m] * f;
991
- return s;
992
- }, a.prototype.readUintBE = a.prototype.readUIntBE = function(t, e, n) {
993
- t = t >>> 0, e = e >>> 0, n || S(t, e, this.length);
994
- for (var s = this[t + --e], f = 1; e > 0 && (f *= 256); )
995
- s += this[t + --e] * f;
996
- return s;
997
- }, a.prototype.readUint8 = a.prototype.readUInt8 = function(t, e) {
998
- return t = t >>> 0, e || S(t, 1, this.length), this[t];
999
- }, a.prototype.readUint16LE = a.prototype.readUInt16LE = function(t, e) {
1000
- return t = t >>> 0, e || S(t, 2, this.length), this[t] | this[t + 1] << 8;
1001
- }, a.prototype.readUint16BE = a.prototype.readUInt16BE = function(t, e) {
1002
- return t = t >>> 0, e || S(t, 2, this.length), this[t] << 8 | this[t + 1];
1003
- }, a.prototype.readUint32LE = a.prototype.readUInt32LE = function(t, e) {
1004
- return t = t >>> 0, e || S(t, 4, this.length), (this[t] | this[t + 1] << 8 | this[t + 2] << 16) + this[t + 3] * 16777216;
1005
- }, a.prototype.readUint32BE = a.prototype.readUInt32BE = function(t, e) {
1006
- return t = t >>> 0, e || S(t, 4, this.length), this[t] * 16777216 + (this[t + 1] << 16 | this[t + 2] << 8 | this[t + 3]);
1007
- }, a.prototype.readIntLE = function(t, e, n) {
1008
- t = t >>> 0, e = e >>> 0, n || S(t, e, this.length);
1009
- for (var s = this[t], f = 1, m = 0; ++m < e && (f *= 256); )
1010
- s += this[t + m] * f;
1011
- return f *= 128, s >= f && (s -= Math.pow(2, 8 * e)), s;
1012
- }, a.prototype.readIntBE = function(t, e, n) {
1013
- t = t >>> 0, e = e >>> 0, n || S(t, e, this.length);
1014
- for (var s = e, f = 1, m = this[t + --s]; s > 0 && (f *= 256); )
1015
- m += this[t + --s] * f;
1016
- return f *= 128, m >= f && (m -= Math.pow(2, 8 * e)), m;
1017
- }, a.prototype.readInt8 = function(t, e) {
1018
- return t = t >>> 0, e || S(t, 1, this.length), this[t] & 128 ? (255 - this[t] + 1) * -1 : this[t];
1019
- }, a.prototype.readInt16LE = function(t, e) {
1020
- t = t >>> 0, e || S(t, 2, this.length);
1021
- var n = this[t] | this[t + 1] << 8;
1022
- return n & 32768 ? n | 4294901760 : n;
1023
- }, a.prototype.readInt16BE = function(t, e) {
1024
- t = t >>> 0, e || S(t, 2, this.length);
1025
- var n = this[t + 1] | this[t] << 8;
1026
- return n & 32768 ? n | 4294901760 : n;
1027
- }, a.prototype.readInt32LE = function(t, e) {
1028
- return t = t >>> 0, e || S(t, 4, this.length), this[t] | this[t + 1] << 8 | this[t + 2] << 16 | this[t + 3] << 24;
1029
- }, a.prototype.readInt32BE = function(t, e) {
1030
- return t = t >>> 0, e || S(t, 4, this.length), this[t] << 24 | this[t + 1] << 16 | this[t + 2] << 8 | this[t + 3];
1031
- }, a.prototype.readFloatLE = function(t, e) {
1032
- return t = t >>> 0, e || S(t, 4, this.length), p.read(this, t, !0, 23, 4);
1033
- }, a.prototype.readFloatBE = function(t, e) {
1034
- return t = t >>> 0, e || S(t, 4, this.length), p.read(this, t, !1, 23, 4);
1035
- }, a.prototype.readDoubleLE = function(t, e) {
1036
- return t = t >>> 0, e || S(t, 8, this.length), p.read(this, t, !0, 52, 8);
1037
- }, a.prototype.readDoubleBE = function(t, e) {
1038
- return t = t >>> 0, e || S(t, 8, this.length), p.read(this, t, !1, 52, 8);
1039
- };
1040
- function k(r, t, e, n, s, f) {
1041
- if (!a.isBuffer(r))
1042
- throw new TypeError('"buffer" argument must be a Buffer instance');
1043
- if (t > s || t < f)
1044
- throw new RangeError('"value" argument is out of bounds');
1045
- if (e + n > r.length)
1046
- throw new RangeError("Index out of range");
1047
- }
1048
- a.prototype.writeUintLE = a.prototype.writeUIntLE = function(t, e, n, s) {
1049
- if (t = +t, e = e >>> 0, n = n >>> 0, !s) {
1050
- var f = Math.pow(2, 8 * n) - 1;
1051
- k(this, t, e, n, f, 0);
1052
- }
1053
- var m = 1, b = 0;
1054
- for (this[e] = t & 255; ++b < n && (m *= 256); )
1055
- this[e + b] = t / m & 255;
1056
- return e + n;
1057
- }, a.prototype.writeUintBE = a.prototype.writeUIntBE = function(t, e, n, s) {
1058
- if (t = +t, e = e >>> 0, n = n >>> 0, !s) {
1059
- var f = Math.pow(2, 8 * n) - 1;
1060
- k(this, t, e, n, f, 0);
1061
- }
1062
- var m = n - 1, b = 1;
1063
- for (this[e + m] = t & 255; --m >= 0 && (b *= 256); )
1064
- this[e + m] = t / b & 255;
1065
- return e + n;
1066
- }, a.prototype.writeUint8 = a.prototype.writeUInt8 = function(t, e, n) {
1067
- return t = +t, e = e >>> 0, n || k(this, t, e, 1, 255, 0), this[e] = t & 255, e + 1;
1068
- }, a.prototype.writeUint16LE = a.prototype.writeUInt16LE = function(t, e, n) {
1069
- return t = +t, e = e >>> 0, n || k(this, t, e, 2, 65535, 0), this[e] = t & 255, this[e + 1] = t >>> 8, e + 2;
1070
- }, a.prototype.writeUint16BE = a.prototype.writeUInt16BE = function(t, e, n) {
1071
- return t = +t, e = e >>> 0, n || k(this, t, e, 2, 65535, 0), this[e] = t >>> 8, this[e + 1] = t & 255, e + 2;
1072
- }, a.prototype.writeUint32LE = a.prototype.writeUInt32LE = function(t, e, n) {
1073
- return t = +t, e = e >>> 0, n || k(this, t, e, 4, 4294967295, 0), this[e + 3] = t >>> 24, this[e + 2] = t >>> 16, this[e + 1] = t >>> 8, this[e] = t & 255, e + 4;
1074
- }, a.prototype.writeUint32BE = a.prototype.writeUInt32BE = function(t, e, n) {
1075
- return t = +t, e = e >>> 0, n || k(this, t, e, 4, 4294967295, 0), this[e] = t >>> 24, this[e + 1] = t >>> 16, this[e + 2] = t >>> 8, this[e + 3] = t & 255, e + 4;
1076
- }, a.prototype.writeIntLE = function(t, e, n, s) {
1077
- if (t = +t, e = e >>> 0, !s) {
1078
- var f = Math.pow(2, 8 * n - 1);
1079
- k(this, t, e, n, f - 1, -f);
1080
- }
1081
- var m = 0, b = 1, _ = 0;
1082
- for (this[e] = t & 255; ++m < n && (b *= 256); )
1083
- t < 0 && _ === 0 && this[e + m - 1] !== 0 && (_ = 1), this[e + m] = (t / b >> 0) - _ & 255;
1084
- return e + n;
1085
- }, a.prototype.writeIntBE = function(t, e, n, s) {
1086
- if (t = +t, e = e >>> 0, !s) {
1087
- var f = Math.pow(2, 8 * n - 1);
1088
- k(this, t, e, n, f - 1, -f);
1089
- }
1090
- var m = n - 1, b = 1, _ = 0;
1091
- for (this[e + m] = t & 255; --m >= 0 && (b *= 256); )
1092
- t < 0 && _ === 0 && this[e + m + 1] !== 0 && (_ = 1), this[e + m] = (t / b >> 0) - _ & 255;
1093
- return e + n;
1094
- }, a.prototype.writeInt8 = function(t, e, n) {
1095
- return t = +t, e = e >>> 0, n || k(this, t, e, 1, 127, -128), t < 0 && (t = 255 + t + 1), this[e] = t & 255, e + 1;
1096
- }, a.prototype.writeInt16LE = function(t, e, n) {
1097
- return t = +t, e = e >>> 0, n || k(this, t, e, 2, 32767, -32768), this[e] = t & 255, this[e + 1] = t >>> 8, e + 2;
1098
- }, a.prototype.writeInt16BE = function(t, e, n) {
1099
- return t = +t, e = e >>> 0, n || k(this, t, e, 2, 32767, -32768), this[e] = t >>> 8, this[e + 1] = t & 255, e + 2;
1100
- }, a.prototype.writeInt32LE = function(t, e, n) {
1101
- return t = +t, e = e >>> 0, n || k(this, t, e, 4, 2147483647, -2147483648), this[e] = t & 255, this[e + 1] = t >>> 8, this[e + 2] = t >>> 16, this[e + 3] = t >>> 24, e + 4;
1102
- }, a.prototype.writeInt32BE = function(t, e, n) {
1103
- return t = +t, e = e >>> 0, n || k(this, t, e, 4, 2147483647, -2147483648), t < 0 && (t = 4294967295 + t + 1), this[e] = t >>> 24, this[e + 1] = t >>> 16, this[e + 2] = t >>> 8, this[e + 3] = t & 255, e + 4;
1104
- };
1105
- function vt(r, t, e, n, s, f) {
1106
- if (e + n > r.length)
1107
- throw new RangeError("Index out of range");
1108
- if (e < 0)
1109
- throw new RangeError("Index out of range");
1110
- }
1111
- function bt(r, t, e, n, s) {
1112
- return t = +t, e = e >>> 0, s || vt(r, t, e, 4), p.write(r, t, e, n, 23, 4), e + 4;
1113
- }
1114
- a.prototype.writeFloatLE = function(t, e, n) {
1115
- return bt(this, t, e, !0, n);
1116
- }, a.prototype.writeFloatBE = function(t, e, n) {
1117
- return bt(this, t, e, !1, n);
1118
- };
1119
- function Et(r, t, e, n, s) {
1120
- return t = +t, e = e >>> 0, s || vt(r, t, e, 8), p.write(r, t, e, n, 52, 8), e + 8;
1121
- }
1122
- a.prototype.writeDoubleLE = function(t, e, n) {
1123
- return Et(this, t, e, !0, n);
1124
- }, a.prototype.writeDoubleBE = function(t, e, n) {
1125
- return Et(this, t, e, !1, n);
1126
- }, a.prototype.copy = function(t, e, n, s) {
1127
- if (!a.isBuffer(t))
1128
- throw new TypeError("argument should be a Buffer");
1129
- if (n || (n = 0), !s && s !== 0 && (s = this.length), e >= t.length && (e = t.length), e || (e = 0), s > 0 && s < n && (s = n), s === n || t.length === 0 || this.length === 0)
1130
- return 0;
1131
- if (e < 0)
1132
- throw new RangeError("targetStart out of bounds");
1133
- if (n < 0 || n >= this.length)
1134
- throw new RangeError("Index out of range");
1135
- if (s < 0)
1136
- throw new RangeError("sourceEnd out of bounds");
1137
- s > this.length && (s = this.length), t.length - e < s - n && (s = t.length - e + n);
1138
- var f = s - n;
1139
- return this === t && typeof Uint8Array.prototype.copyWithin == "function" ? this.copyWithin(e, n, s) : Uint8Array.prototype.set.call(
1140
- t,
1141
- this.subarray(n, s),
1142
- e
1143
- ), f;
1144
- }, a.prototype.fill = function(t, e, n, s) {
1145
- if (typeof t == "string") {
1146
- if (typeof e == "string" ? (s = e, e = 0, n = this.length) : typeof n == "string" && (s = n, n = this.length), s !== void 0 && typeof s != "string")
1147
- throw new TypeError("encoding must be a string");
1148
- if (typeof s == "string" && !a.isEncoding(s))
1149
- throw new TypeError("Unknown encoding: " + s);
1150
- if (t.length === 1) {
1151
- var f = t.charCodeAt(0);
1152
- (s === "utf8" && f < 128 || s === "latin1") && (t = f);
1153
- }
1154
- } else
1155
- typeof t == "number" ? t = t & 255 : typeof t == "boolean" && (t = Number(t));
1156
- if (e < 0 || this.length < e || this.length < n)
1157
- throw new RangeError("Out of range index");
1158
- if (n <= e)
1159
- return this;
1160
- e = e >>> 0, n = n === void 0 ? this.length : n >>> 0, t || (t = 0);
1161
- var m;
1162
- if (typeof t == "number")
1163
- for (m = e; m < n; ++m)
1164
- this[m] = t;
1165
- else {
1166
- var b = a.isBuffer(t) ? t : a.from(t, s), _ = b.length;
1167
- if (_ === 0)
1168
- throw new TypeError('The value "' + t + '" is invalid for argument "value"');
1169
- for (m = 0; m < n - e; ++m)
1170
- this[m + e] = b[m % _];
1171
- }
1172
- return this;
1173
- };
1174
- var ve = /[^+/0-9A-Za-z-_]/g;
1175
- function be(r) {
1176
- if (r = r.split("=")[0], r = r.trim().replace(ve, ""), r.length < 2)
1177
- return "";
1178
- for (; r.length % 4 !== 0; )
1179
- r = r + "=";
1180
- return r;
1181
- }
1182
- function Q(r, t) {
1183
- t = t || 1 / 0;
1184
- for (var e, n = r.length, s = null, f = [], m = 0; m < n; ++m) {
1185
- if (e = r.charCodeAt(m), e > 55295 && e < 57344) {
1186
- if (!s) {
1187
- if (e > 56319) {
1188
- (t -= 3) > -1 && f.push(239, 191, 189);
1189
- continue;
1190
- } else if (m + 1 === n) {
1191
- (t -= 3) > -1 && f.push(239, 191, 189);
1192
- continue;
1193
- }
1194
- s = e;
1195
- continue;
1196
- }
1197
- if (e < 56320) {
1198
- (t -= 3) > -1 && f.push(239, 191, 189), s = e;
1199
- continue;
1200
- }
1201
- e = (s - 55296 << 10 | e - 56320) + 65536;
1202
- } else
1203
- s && (t -= 3) > -1 && f.push(239, 191, 189);
1204
- if (s = null, e < 128) {
1205
- if ((t -= 1) < 0)
1206
- break;
1207
- f.push(e);
1208
- } else if (e < 2048) {
1209
- if ((t -= 2) < 0)
1210
- break;
1211
- f.push(
1212
- e >> 6 | 192,
1213
- e & 63 | 128
1214
- );
1215
- } else if (e < 65536) {
1216
- if ((t -= 3) < 0)
1217
- break;
1218
- f.push(
1219
- e >> 12 | 224,
1220
- e >> 6 & 63 | 128,
1221
- e & 63 | 128
1222
- );
1223
- } else if (e < 1114112) {
1224
- if ((t -= 4) < 0)
1225
- break;
1226
- f.push(
1227
- e >> 18 | 240,
1228
- e >> 12 & 63 | 128,
1229
- e >> 6 & 63 | 128,
1230
- e & 63 | 128
1231
- );
1232
- } else
1233
- throw new Error("Invalid code point");
1234
- }
1235
- return f;
1236
- }
1237
- function Ee(r) {
1238
- for (var t = [], e = 0; e < r.length; ++e)
1239
- t.push(r.charCodeAt(e) & 255);
1240
- return t;
1241
- }
1242
- function _e(r, t) {
1243
- for (var e, n, s, f = [], m = 0; m < r.length && !((t -= 2) < 0); ++m)
1244
- e = r.charCodeAt(m), n = e >> 8, s = e % 256, f.push(s), f.push(n);
1245
- return f;
1246
- }
1247
- function _t(r) {
1248
- return o.toByteArray(be(r));
1249
- }
1250
- function J(r, t, e, n) {
1251
- for (var s = 0; s < n && !(s + e >= t.length || s >= r.length); ++s)
1252
- t[s + e] = r[s];
1253
- return s;
1254
- }
1255
- function O(r, t) {
1256
- return r instanceof t || r != null && r.constructor != null && r.constructor.name != null && r.constructor.name === t.name;
1257
- }
1258
- function tt(r) {
1259
- return r !== r;
1260
- }
1261
- var Fe = function() {
1262
- for (var r = "0123456789abcdef", t = new Array(256), e = 0; e < 16; ++e)
1263
- for (var n = e * 16, s = 0; s < 16; ++s)
1264
- t[n + s] = r[e] + r[s];
1265
- return t;
1266
- }();
1267
- })(Zt);
1268
- /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
1269
- (function(i, o) {
1270
- var p = Zt, c = p.Buffer;
1271
- function u(l, a) {
1272
- for (var x in l)
1273
- a[x] = l[x];
1274
- }
1275
- c.from && c.alloc && c.allocUnsafe && c.allocUnsafeSlow ? i.exports = p : (u(p, o), o.Buffer = h);
1276
- function h(l, a, x) {
1277
- return c(l, a, x);
1278
- }
1279
- h.prototype = Object.create(c.prototype), u(c, h), h.from = function(l, a, x) {
1280
- if (typeof l == "number")
1281
- throw new TypeError("Argument must not be a number");
1282
- return c(l, a, x);
1283
- }, h.alloc = function(l, a, x) {
1284
- if (typeof l != "number")
1285
- throw new TypeError("Argument must be a number");
1286
- var d = c(l);
1287
- return a !== void 0 ? typeof x == "string" ? d.fill(a, x) : d.fill(a) : d.fill(0), d;
1288
- }, h.allocUnsafe = function(l) {
1289
- if (typeof l != "number")
1290
- throw new TypeError("Argument must be a number");
1291
- return c(l);
1292
- }, h.allocUnsafeSlow = function(l) {
1293
- if (typeof l != "number")
1294
- throw new TypeError("Argument must be a number");
1295
- return p.SlowBuffer(l);
1296
- };
1297
- })(nt, nt.exports);
1298
- var Kt = nt.exports, Vt = Kt.Buffer;
1299
- function V(i, o) {
1300
- this._block = Vt.alloc(i), this._finalSize = o, this._blockSize = i, this._len = 0;
1301
- }
1302
- V.prototype.update = function(i, o) {
1303
- typeof i == "string" && (o = o || "utf8", i = Vt.from(i, o));
1304
- for (var p = this._block, c = this._blockSize, u = i.length, h = this._len, l = 0; l < u; ) {
1305
- for (var a = h % c, x = Math.min(u - l, c - a), d = 0; d < x; d++)
1306
- p[a + d] = i[l + d];
1307
- h += x, l += x, h % c === 0 && this._update(p);
1308
- }
1309
- return this._len += u, this;
1310
- };
1311
- V.prototype.digest = function(i) {
1312
- var o = this._len % this._blockSize;
1313
- this._block[o] = 128, this._block.fill(0, o + 1), o >= this._finalSize && (this._update(this._block), this._block.fill(0));
1314
- var p = this._len * 8;
1315
- if (p <= 4294967295)
1316
- this._block.writeUInt32BE(p, this._blockSize - 4);
1317
- else {
1318
- var c = (p & 4294967295) >>> 0, u = (p - c) / 4294967296;
1319
- this._block.writeUInt32BE(u, this._blockSize - 8), this._block.writeUInt32BE(c, this._blockSize - 4);
1320
- }
1321
- this._update(this._block);
1322
- var h = this._hash();
1323
- return i ? h.toString(i) : h;
1324
- };
1325
- V.prototype._update = function() {
1326
- throw new Error("_update must be implemented by subclass");
1327
- };
1328
- var er = V, rr = He, Xt = er, ir = Kt.Buffer, nr = [
1329
- 1518500249,
1330
- 1859775393,
1331
- -1894007588,
1332
- -899497514
1333
- ], or = new Array(80);
1334
- function P() {
1335
- this.init(), this._w = or, Xt.call(this, 64, 56);
1336
- }
1337
- rr(P, Xt);
1338
- P.prototype.init = function() {
1339
- return this._a = 1732584193, this._b = 4023233417, this._c = 2562383102, this._d = 271733878, this._e = 3285377520, this;
1340
- };
1341
- function ar(i) {
1342
- return i << 1 | i >>> 31;
1343
- }
1344
- function pr(i) {
1345
- return i << 5 | i >>> 27;
1346
- }
1347
- function sr(i) {
1348
- return i << 30 | i >>> 2;
1349
- }
1350
- function cr(i, o, p, c) {
1351
- return i === 0 ? o & p | ~o & c : i === 2 ? o & p | o & c | p & c : o ^ p ^ c;
1352
- }
1353
- P.prototype._update = function(i) {
1354
- for (var o = this._w, p = this._a | 0, c = this._b | 0, u = this._c | 0, h = this._d | 0, l = this._e | 0, a = 0; a < 16; ++a)
1355
- o[a] = i.readInt32BE(a * 4);
1356
- for (; a < 80; ++a)
1357
- o[a] = ar(o[a - 3] ^ o[a - 8] ^ o[a - 14] ^ o[a - 16]);
1358
- for (var x = 0; x < 80; ++x) {
1359
- var d = ~~(x / 20), E = pr(p) + cr(d, c, u, h) + l + o[x] + nr[d] | 0;
1360
- l = h, h = u, u = sr(c), c = p, p = E;
1361
- }
1362
- this._a = p + this._a | 0, this._b = c + this._b | 0, this._c = u + this._c | 0, this._d = h + this._d | 0, this._e = l + this._e | 0;
1363
- };
1364
- P.prototype._hash = function() {
1365
- var i = ir.allocUnsafe(20);
1366
- return i.writeInt32BE(this._a | 0, 0), i.writeInt32BE(this._b | 0, 4), i.writeInt32BE(this._c | 0, 8), i.writeInt32BE(this._d | 0, 12), i.writeInt32BE(this._e | 0, 16), i;
1367
- };
1368
- var lr = P;
1369
- const ur = /* @__PURE__ */ Ht(lr), ft = new Error("File system not available.");
1370
- function fr(i, o, p) {
1371
- throw ft;
1372
- }
1373
- function Gt(i) {
1374
- throw ft;
1375
- }
1376
- function hr(i) {
1377
- throw ft;
1378
- }
1379
- const mr = async (i) => Gt();
1380
- function xr(i) {
1381
- let o = "";
1382
- for (let p = 0; p < i.length; p += 2)
1383
- o += String.fromCharCode(parseInt(i.substr(p, 2), 16));
1384
- return btoa(o);
1385
- }
1386
- const X = (i, o = "sha1") => {
1387
- if (o !== "sha1")
1388
- throw new Error("Only sha1 algorithm is available.");
1389
- const p = new ur();
1390
- return xr(p.update(i).digest("hex"));
1391
- };
1392
- function St(i) {
1393
- return [M, C].includes(i.type);
1394
- }
1395
- function Bt(i) {
1396
- return [Pt, M, C, $, Jt].includes(i.type);
1397
- }
1398
- function L(i, o, p, c, u = "global") {
1399
- if (!i)
1400
- throw new Error("Empty action type");
1401
- if (typeof i != "string")
1402
- throw new Error(`Invalid action type: ${i}`);
1403
- const h = { type: i, input: o, scope: u };
1404
- p && (h.attachments = p);
1405
- try {
1406
- c == null || c().parse(h.input);
1407
- } catch (l) {
1408
- throw new Error(`Invalid action input: ${l}`);
1409
- }
1410
- return h;
1411
- }
1412
- function dr(i, o = Wt) {
1413
- return (p, c, u, h) => o(p, c, i, u, h);
1414
- }
1415
- const gr = (i, o) => ({
1416
- name: "",
1417
- documentType: "",
1418
- revision: {
1419
- global: 0,
1420
- local: 0
1421
- },
1422
- created: (/* @__PURE__ */ new Date()).toISOString(),
1423
- lastModified: (/* @__PURE__ */ new Date()).toISOString(),
1424
- attachments: {},
1425
- ...i,
1426
- state: (o == null ? void 0 : o(i == null ? void 0 : i.state)) ?? (i == null ? void 0 : i.state) ?? { global: {}, local: {} }
1427
- }), wr = (i, o) => {
1428
- const p = gr(
1429
- i,
1430
- o
1431
- );
1432
- return {
1433
- ...p,
1434
- initialState: p,
1435
- operations: { global: [], local: [] },
1436
- clipboard: []
1437
- };
1438
- }, Qt = (i, o = "global") => X(je(i.state[o])), Nr = (i, o = 1e3) => {
1439
- const p = Math.random() * o;
1440
- return X(`${(i ?? /* @__PURE__ */ new Date()).toISOString()}${p}`);
1441
- };
1442
- function Z(i) {
1443
- return Be(ke(i, !0));
1444
- }
1445
- function yr(i, o) {
1446
- const p = [...i];
1447
- let c = o || 0, u = p.length > 0 ? p[p.length - 1].index : 0;
1448
- const h = [];
1449
- for (const l of p.reverse()) {
1450
- if (c > 0) {
1451
- const d = u - l.index;
1452
- c -= d;
1453
- }
1454
- if (c < 0)
1455
- throw new Error("Invalid operation index, missing operations");
1456
- const a = {
1457
- ignore: c > 0,
1458
- operation: l
1459
- }, x = l.skip > 0 ? l.skip + 1 : 0;
1460
- if (x > 0 && x > c) {
1461
- const d = x - c;
1462
- c = c + d;
1463
- }
1464
- u = l.index, h.push(a);
1465
- }
1466
- return h.reverse();
1467
- }
1468
- function Rr(i) {
1469
- return Object.values(i).flatMap((o) => o).sort(
1470
- (o, p) => new Date(o.timestamp).getTime() - new Date(p.timestamp).getTime()
1471
- );
1472
- }
1473
- function vr(i) {
1474
- return Object.values(i).flatMap((o) => o).sort(
1475
- (o, p) => new Date(o.operation.timestamp).getTime() - new Date(p.operation.timestamp).getTime()
1476
- );
1477
- }
1478
- function ot(i, o, p, c, u, h = Wt, l = {}) {
1479
- const a = dr(p, h);
1480
- return te(
1481
- i,
1482
- o,
1483
- a,
1484
- c,
1485
- u,
1486
- l
1487
- );
1488
- }
1489
- function te(i, o, p, c, u, h = {}) {
1490
- const l = wr(i), a = Object.keys(o).reduce((w, v) => {
1491
- const y = v;
1492
- return {
1493
- ...w,
1494
- [y]: o[y].slice(0, u == null ? void 0 : u.revision[y])
1495
- };
1496
- }, {}), x = Object.keys(a).reduce(
1497
- (w, v) => {
1498
- const y = v;
1499
- return {
1500
- ...w,
1501
- [y]: yr(
1502
- a[y],
1503
- h[y]
1504
- )
1505
- };
1506
- },
1507
- {}
1508
- ), d = vr(x).reduce(
1509
- (w, { ignore: v, operation: y }) => v ? p(w, mt(y.scope), c, {
1510
- skip: y.skip,
1511
- ignoreSkipOperations: !0
1512
- }) : p(w, y, c, {
1513
- skip: y.skip,
1514
- ignoreSkipOperations: !0
1515
- }),
1516
- l
1517
- ), E = Object.keys(
1518
- d.operations
1519
- ).reduce(
1520
- (w, v) => {
1521
- const y = v, U = u && u.revision[y] < o[y].length ? o[y].slice(u.revision[y]) : [];
1522
- return {
1523
- ...w,
1524
- [y]: [
1525
- ...d.operations[y].map((j, z) => {
1526
- var N;
1527
- return {
1528
- ...j,
1529
- timestamp: ((N = o[y][z]) == null ? void 0 : N.timestamp) ?? j.timestamp
1530
- };
1531
- }),
1532
- ...U
1533
- ]
1534
- };
1535
- },
1536
- { global: [], local: [] }
1537
- );
1538
- return { ...d, operations: E };
1539
- }
1540
- const ee = (i) => L(
1541
- "SET_NAME",
1542
- i,
1543
- void 0,
1544
- ct,
1545
- void 0
1546
- ), re = (i = 1, o = "global") => L(
1547
- "UNDO",
1548
- i,
1549
- void 0,
1550
- lt,
1551
- o
1552
- ), ie = (i = 1, o = "global") => L(
1553
- "REDO",
1554
- i,
1555
- void 0,
1556
- st,
1557
- o
1558
- ), ne = (i, o, p = "global") => L(
1559
- "PRUNE",
1560
- { start: i, end: o },
1561
- void 0,
1562
- pt,
1563
- p
1564
- ), ht = (i, o) => L(
1565
- "LOAD_STATE",
1566
- { state: i, operations: o },
1567
- void 0,
1568
- at
1569
- ), mt = (i = "global") => L("NOOP", {}, void 0, void 0, i), Mr = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1570
- __proto__: null,
1571
- loadState: ht,
1572
- noop: mt,
1573
- prune: ne,
1574
- redo: ie,
1575
- setName: ee,
1576
- undo: re
1577
- }, Symbol.toStringTag, { value: "Module" }));
1578
- function G() {
1579
- this._types = /* @__PURE__ */ Object.create(null), this._extensions = /* @__PURE__ */ Object.create(null);
1580
- for (let i = 0; i < arguments.length; i++)
1581
- this.define(arguments[i]);
1582
- this.define = this.define.bind(this), this.getType = this.getType.bind(this), this.getExtension = this.getExtension.bind(this);
1583
- }
1584
- G.prototype.define = function(i, o) {
1585
- for (let p in i) {
1586
- let c = i[p].map(function(u) {
1587
- return u.toLowerCase();
1588
- });
1589
- p = p.toLowerCase();
1590
- for (let u = 0; u < c.length; u++) {
1591
- const h = c[u];
1592
- if (h[0] !== "*") {
1593
- if (!o && h in this._types)
1594
- throw new Error(
1595
- 'Attempt to change mapping for "' + h + '" extension from "' + this._types[h] + '" to "' + p + '". Pass `force=true` to allow this, otherwise remove "' + h + '" from the list of extensions for "' + p + '".'
1596
- );
1597
- this._types[h] = p;
1598
- }
1599
- }
1600
- if (o || !this._extensions[p]) {
1601
- const u = c[0];
1602
- this._extensions[p] = u[0] !== "*" ? u : u.substr(1);
1603
- }
1604
- }
1605
- };
1606
- G.prototype.getType = function(i) {
1607
- i = String(i);
1608
- let o = i.replace(/^.*[/\\]/, "").toLowerCase(), p = o.replace(/^.*\./, "").toLowerCase(), c = o.length < i.length;
1609
- return (p.length < o.length - 1 || !c) && this._types[p] || null;
1610
- };
1611
- G.prototype.getExtension = function(i) {
1612
- return i = /^\s*([^;\s]*)/.test(i) && RegExp.$1, i && this._extensions[i.toLowerCase()] || null;
1613
- };
1614
- var br = G, Er = { "application/andrew-inset": ["ez"], "application/applixware": ["aw"], "application/atom+xml": ["atom"], "application/atomcat+xml": ["atomcat"], "application/atomdeleted+xml": ["atomdeleted"], "application/atomsvc+xml": ["atomsvc"], "application/atsc-dwd+xml": ["dwd"], "application/atsc-held+xml": ["held"], "application/atsc-rsat+xml": ["rsat"], "application/bdoc": ["bdoc"], "application/calendar+xml": ["xcs"], "application/ccxml+xml": ["ccxml"], "application/cdfx+xml": ["cdfx"], "application/cdmi-capability": ["cdmia"], "application/cdmi-container": ["cdmic"], "application/cdmi-domain": ["cdmid"], "application/cdmi-object": ["cdmio"], "application/cdmi-queue": ["cdmiq"], "application/cu-seeme": ["cu"], "application/dash+xml": ["mpd"], "application/davmount+xml": ["davmount"], "application/docbook+xml": ["dbk"], "application/dssc+der": ["dssc"], "application/dssc+xml": ["xdssc"], "application/ecmascript": ["es", "ecma"], "application/emma+xml": ["emma"], "application/emotionml+xml": ["emotionml"], "application/epub+zip": ["epub"], "application/exi": ["exi"], "application/express": ["exp"], "application/fdt+xml": ["fdt"], "application/font-tdpfr": ["pfr"], "application/geo+json": ["geojson"], "application/gml+xml": ["gml"], "application/gpx+xml": ["gpx"], "application/gxf": ["gxf"], "application/gzip": ["gz"], "application/hjson": ["hjson"], "application/hyperstudio": ["stk"], "application/inkml+xml": ["ink", "inkml"], "application/ipfix": ["ipfix"], "application/its+xml": ["its"], "application/java-archive": ["jar", "war", "ear"], "application/java-serialized-object": ["ser"], "application/java-vm": ["class"], "application/javascript": ["js", "mjs"], "application/json": ["json", "map"], "application/json5": ["json5"], "application/jsonml+json": ["jsonml"], "application/ld+json": ["jsonld"], "application/lgr+xml": ["lgr"], "application/lost+xml": ["lostxml"], "application/mac-binhex40": ["hqx"], "application/mac-compactpro": ["cpt"], "application/mads+xml": ["mads"], "application/manifest+json": ["webmanifest"], "application/marc": ["mrc"], "application/marcxml+xml": ["mrcx"], "application/mathematica": ["ma", "nb", "mb"], "application/mathml+xml": ["mathml"], "application/mbox": ["mbox"], "application/mediaservercontrol+xml": ["mscml"], "application/metalink+xml": ["metalink"], "application/metalink4+xml": ["meta4"], "application/mets+xml": ["mets"], "application/mmt-aei+xml": ["maei"], "application/mmt-usd+xml": ["musd"], "application/mods+xml": ["mods"], "application/mp21": ["m21", "mp21"], "application/mp4": ["mp4s", "m4p"], "application/msword": ["doc", "dot"], "application/mxf": ["mxf"], "application/n-quads": ["nq"], "application/n-triples": ["nt"], "application/node": ["cjs"], "application/octet-stream": ["bin", "dms", "lrf", "mar", "so", "dist", "distz", "pkg", "bpk", "dump", "elc", "deploy", "exe", "dll", "deb", "dmg", "iso", "img", "msi", "msp", "msm", "buffer"], "application/oda": ["oda"], "application/oebps-package+xml": ["opf"], "application/ogg": ["ogx"], "application/omdoc+xml": ["omdoc"], "application/onenote": ["onetoc", "onetoc2", "onetmp", "onepkg"], "application/oxps": ["oxps"], "application/p2p-overlay+xml": ["relo"], "application/patch-ops-error+xml": ["xer"], "application/pdf": ["pdf"], "application/pgp-encrypted": ["pgp"], "application/pgp-signature": ["asc", "sig"], "application/pics-rules": ["prf"], "application/pkcs10": ["p10"], "application/pkcs7-mime": ["p7m", "p7c"], "application/pkcs7-signature": ["p7s"], "application/pkcs8": ["p8"], "application/pkix-attr-cert": ["ac"], "application/pkix-cert": ["cer"], "application/pkix-crl": ["crl"], "application/pkix-pkipath": ["pkipath"], "application/pkixcmp": ["pki"], "application/pls+xml": ["pls"], "application/postscript": ["ai", "eps", "ps"], "application/provenance+xml": ["provx"], "application/pskc+xml": ["pskcxml"], "application/raml+yaml": ["raml"], "application/rdf+xml": ["rdf", "owl"], "application/reginfo+xml": ["rif"], "application/relax-ng-compact-syntax": ["rnc"], "application/resource-lists+xml": ["rl"], "application/resource-lists-diff+xml": ["rld"], "application/rls-services+xml": ["rs"], "application/route-apd+xml": ["rapd"], "application/route-s-tsid+xml": ["sls"], "application/route-usd+xml": ["rusd"], "application/rpki-ghostbusters": ["gbr"], "application/rpki-manifest": ["mft"], "application/rpki-roa": ["roa"], "application/rsd+xml": ["rsd"], "application/rss+xml": ["rss"], "application/rtf": ["rtf"], "application/sbml+xml": ["sbml"], "application/scvp-cv-request": ["scq"], "application/scvp-cv-response": ["scs"], "application/scvp-vp-request": ["spq"], "application/scvp-vp-response": ["spp"], "application/sdp": ["sdp"], "application/senml+xml": ["senmlx"], "application/sensml+xml": ["sensmlx"], "application/set-payment-initiation": ["setpay"], "application/set-registration-initiation": ["setreg"], "application/shf+xml": ["shf"], "application/sieve": ["siv", "sieve"], "application/smil+xml": ["smi", "smil"], "application/sparql-query": ["rq"], "application/sparql-results+xml": ["srx"], "application/srgs": ["gram"], "application/srgs+xml": ["grxml"], "application/sru+xml": ["sru"], "application/ssdl+xml": ["ssdl"], "application/ssml+xml": ["ssml"], "application/swid+xml": ["swidtag"], "application/tei+xml": ["tei", "teicorpus"], "application/thraud+xml": ["tfi"], "application/timestamped-data": ["tsd"], "application/toml": ["toml"], "application/trig": ["trig"], "application/ttml+xml": ["ttml"], "application/ubjson": ["ubj"], "application/urc-ressheet+xml": ["rsheet"], "application/urc-targetdesc+xml": ["td"], "application/voicexml+xml": ["vxml"], "application/wasm": ["wasm"], "application/widget": ["wgt"], "application/winhlp": ["hlp"], "application/wsdl+xml": ["wsdl"], "application/wspolicy+xml": ["wspolicy"], "application/xaml+xml": ["xaml"], "application/xcap-att+xml": ["xav"], "application/xcap-caps+xml": ["xca"], "application/xcap-diff+xml": ["xdf"], "application/xcap-el+xml": ["xel"], "application/xcap-ns+xml": ["xns"], "application/xenc+xml": ["xenc"], "application/xhtml+xml": ["xhtml", "xht"], "application/xliff+xml": ["xlf"], "application/xml": ["xml", "xsl", "xsd", "rng"], "application/xml-dtd": ["dtd"], "application/xop+xml": ["xop"], "application/xproc+xml": ["xpl"], "application/xslt+xml": ["*xsl", "xslt"], "application/xspf+xml": ["xspf"], "application/xv+xml": ["mxml", "xhvml", "xvml", "xvm"], "application/yang": ["yang"], "application/yin+xml": ["yin"], "application/zip": ["zip"], "audio/3gpp": ["*3gpp"], "audio/adpcm": ["adp"], "audio/amr": ["amr"], "audio/basic": ["au", "snd"], "audio/midi": ["mid", "midi", "kar", "rmi"], "audio/mobile-xmf": ["mxmf"], "audio/mp3": ["*mp3"], "audio/mp4": ["m4a", "mp4a"], "audio/mpeg": ["mpga", "mp2", "mp2a", "mp3", "m2a", "m3a"], "audio/ogg": ["oga", "ogg", "spx", "opus"], "audio/s3m": ["s3m"], "audio/silk": ["sil"], "audio/wav": ["wav"], "audio/wave": ["*wav"], "audio/webm": ["weba"], "audio/xm": ["xm"], "font/collection": ["ttc"], "font/otf": ["otf"], "font/ttf": ["ttf"], "font/woff": ["woff"], "font/woff2": ["woff2"], "image/aces": ["exr"], "image/apng": ["apng"], "image/avif": ["avif"], "image/bmp": ["bmp"], "image/cgm": ["cgm"], "image/dicom-rle": ["drle"], "image/emf": ["emf"], "image/fits": ["fits"], "image/g3fax": ["g3"], "image/gif": ["gif"], "image/heic": ["heic"], "image/heic-sequence": ["heics"], "image/heif": ["heif"], "image/heif-sequence": ["heifs"], "image/hej2k": ["hej2"], "image/hsj2": ["hsj2"], "image/ief": ["ief"], "image/jls": ["jls"], "image/jp2": ["jp2", "jpg2"], "image/jpeg": ["jpeg", "jpg", "jpe"], "image/jph": ["jph"], "image/jphc": ["jhc"], "image/jpm": ["jpm"], "image/jpx": ["jpx", "jpf"], "image/jxr": ["jxr"], "image/jxra": ["jxra"], "image/jxrs": ["jxrs"], "image/jxs": ["jxs"], "image/jxsc": ["jxsc"], "image/jxsi": ["jxsi"], "image/jxss": ["jxss"], "image/ktx": ["ktx"], "image/ktx2": ["ktx2"], "image/png": ["png"], "image/sgi": ["sgi"], "image/svg+xml": ["svg", "svgz"], "image/t38": ["t38"], "image/tiff": ["tif", "tiff"], "image/tiff-fx": ["tfx"], "image/webp": ["webp"], "image/wmf": ["wmf"], "message/disposition-notification": ["disposition-notification"], "message/global": ["u8msg"], "message/global-delivery-status": ["u8dsn"], "message/global-disposition-notification": ["u8mdn"], "message/global-headers": ["u8hdr"], "message/rfc822": ["eml", "mime"], "model/3mf": ["3mf"], "model/gltf+json": ["gltf"], "model/gltf-binary": ["glb"], "model/iges": ["igs", "iges"], "model/mesh": ["msh", "mesh", "silo"], "model/mtl": ["mtl"], "model/obj": ["obj"], "model/step+xml": ["stpx"], "model/step+zip": ["stpz"], "model/step-xml+zip": ["stpxz"], "model/stl": ["stl"], "model/vrml": ["wrl", "vrml"], "model/x3d+binary": ["*x3db", "x3dbz"], "model/x3d+fastinfoset": ["x3db"], "model/x3d+vrml": ["*x3dv", "x3dvz"], "model/x3d+xml": ["x3d", "x3dz"], "model/x3d-vrml": ["x3dv"], "text/cache-manifest": ["appcache", "manifest"], "text/calendar": ["ics", "ifb"], "text/coffeescript": ["coffee", "litcoffee"], "text/css": ["css"], "text/csv": ["csv"], "text/html": ["html", "htm", "shtml"], "text/jade": ["jade"], "text/jsx": ["jsx"], "text/less": ["less"], "text/markdown": ["markdown", "md"], "text/mathml": ["mml"], "text/mdx": ["mdx"], "text/n3": ["n3"], "text/plain": ["txt", "text", "conf", "def", "list", "log", "in", "ini"], "text/richtext": ["rtx"], "text/rtf": ["*rtf"], "text/sgml": ["sgml", "sgm"], "text/shex": ["shex"], "text/slim": ["slim", "slm"], "text/spdx": ["spdx"], "text/stylus": ["stylus", "styl"], "text/tab-separated-values": ["tsv"], "text/troff": ["t", "tr", "roff", "man", "me", "ms"], "text/turtle": ["ttl"], "text/uri-list": ["uri", "uris", "urls"], "text/vcard": ["vcard"], "text/vtt": ["vtt"], "text/xml": ["*xml"], "text/yaml": ["yaml", "yml"], "video/3gpp": ["3gp", "3gpp"], "video/3gpp2": ["3g2"], "video/h261": ["h261"], "video/h263": ["h263"], "video/h264": ["h264"], "video/iso.segment": ["m4s"], "video/jpeg": ["jpgv"], "video/jpm": ["*jpm", "jpgm"], "video/mj2": ["mj2", "mjp2"], "video/mp2t": ["ts"], "video/mp4": ["mp4", "mp4v", "mpg4"], "video/mpeg": ["mpeg", "mpg", "mpe", "m1v", "m2v"], "video/ogg": ["ogv"], "video/quicktime": ["qt", "mov"], "video/webm": ["webm"] };
1615
- let _r = br;
1616
- var Fr = new _r(Er);
1617
- const Ar = /* @__PURE__ */ Ht(Fr), oe = async (i) => {
1618
- const o = new jt(), { name: p, revision: c, documentType: u, created: h, lastModified: l } = i, a = {
1619
- name: p,
1620
- revision: c,
1621
- documentType: u,
1622
- created: h,
1623
- lastModified: l
1624
- };
1625
- return o.file("header.json", JSON.stringify(a, null, 2)), o.file(
1626
- "state.json",
1627
- JSON.stringify(i.initialState || {}, null, 2)
1628
- ), o.file("operations.json", JSON.stringify(i.operations, null, 2)), Object.keys(i.attachments).forEach((d) => {
1629
- const { data: E, ...w } = i.attachments[d];
1630
- o.file(d, E, {
1631
- base64: !0,
1632
- createFolders: !0,
1633
- comment: JSON.stringify(w)
1634
- });
1635
- }), o;
1636
- }, Sr = async (i, o, p, c) => {
1637
- await (await oe(i)).generateAsync({
1638
- type: "uint8array",
1639
- streamFiles: !0
1640
- });
1641
- const h = c ?? i.name, l = `.${p}.zip`;
1642
- return fr(
1643
- o,
1644
- h.endsWith(l) ? h : `${h}${l}`
1645
- );
1646
- }, Cr = async (i, o) => {
1647
- const c = await (await oe(i)).generateAsync({ type: "blob" }), u = await o.createWritable();
1648
- await u.write(c), await u.close();
1649
- }, kt = async (i, o) => {
1650
- const p = Gt();
1651
- return Br(p, o);
1652
- }, Br = async (i, o) => {
1653
- const p = new jt();
1654
- return await p.loadAsync(i), kr(p, o);
1655
- };
1656
- async function kr(i, o) {
1657
- const p = i.file("state.json");
1658
- if (!p)
1659
- throw new Error("Initial state not found");
1660
- const c = await p.async("string"), u = JSON.parse(c), h = i.file("header.json");
1661
- let l;
1662
- h && (l = JSON.parse(await h.async("string")));
1663
- const a = i.file("operations.json");
1664
- if (!a)
1665
- throw new Error("Operations history not found");
1666
- const x = JSON.parse(
1667
- await a.async("string")
1668
- );
1669
- let d = te(
1670
- u,
1671
- x,
1672
- o,
1673
- void 0,
1674
- l
1675
- );
1676
- return l && (d = {
1677
- ...d,
1678
- ...l
1679
- }), d;
1680
- }
1681
- function ae(i) {
1682
- const o = i.replace(/^.*\./, "") || void 0, p = i.replace(/^.*[/\\]/, "") || void 0;
1683
- return { extension: o, fileName: p };
1684
- }
1685
- async function Lr(i) {
1686
- const { buffer: o, mimeType: p = "application/octet-stream" } = await hr(), c = ae(i), u = o.toString("base64");
1687
- return {
1688
- data: u,
1689
- hash: X(u),
1690
- mimeType: p,
1691
- ...c
1692
- };
1693
- }
1694
- async function zr(i) {
1695
- const o = await mr(), p = Ar.getType(i) || "application/octet-stream", c = ae(i), u = o.toString("base64");
1696
- return { data: u, hash: X(u), mimeType: p, ...c };
1697
- }
1698
- class qr {
1699
- /**
1700
- * Constructs a BaseDocument instance with an initial state.
1701
- * @param reducer - The reducer function that updates the state.
1702
- * @param document - The initial state of the document.
1703
- */
1704
- constructor(o, p, c) {
1705
- H(this, "_document");
1706
- H(this, "_reducer");
1707
- H(this, "_signalDispatch");
1708
- this._reducer = o, this._document = p, this._signalDispatch = c;
1709
- }
1710
- /**
1711
- * Dispatches an action to update the state of the document.
1712
- * @param action - The action to dispatch.
1713
- * @returns The Document instance.
1714
- */
1715
- dispatch(o, p) {
1716
- return this._document = this._reducer(
1717
- this._document,
1718
- o,
1719
- this._signalDispatch,
1720
- p
1721
- ), this;
1722
- }
1723
- /**
1724
- * Saves the state of the document to a file.
1725
- * @param path - The file path where the state should be saved.
1726
- * @param extension - The file extension to use when saving the state.
1727
- * @returns The file path where the state was saved.
1728
- */
1729
- saveToFile(o, p, c) {
1730
- return Sr(this._document, o, p, c);
1731
- }
1732
- /**
1733
- * Loads the state of the document from a file.
1734
- * @param path - The file path where the state is stored.
1735
- */
1736
- async loadFromFile(o) {
1737
- this._document = await kt(o, this._reducer);
1738
- }
1739
- /**
1740
- * Loads the state of the document from a file and returns it.
1741
- * @param path - The file path where the state is stored.
1742
- * @param reducer - The reducer function that updates the state.
1743
- * @returns The state of the document.
1744
- */
1745
- static async stateFromFile(o, p) {
1746
- return await kt(o, p);
1747
- }
1748
- /**
1749
- * Gets the current state of the document.
1750
- */
1751
- get state() {
1752
- return Z(this._document.state);
1753
- }
1754
- /**
1755
- * Gets the list of operations performed on the document.
1756
- */
1757
- get operations() {
1758
- return Z(this._document.operations);
1759
- }
1760
- /**
1761
- * Gets the name of the document.
1762
- */
1763
- get name() {
1764
- return this._document.name;
1765
- }
1766
- /**
1767
- * Gets the type of document.
1768
- */
1769
- get documentType() {
1770
- return this._document.documentType;
1771
- }
1772
- /**
1773
- * Gets the timestamp of the date the document was created.
1774
- */
1775
- get created() {
1776
- return this._document.created;
1777
- }
1778
- /**
1779
- * Gets the timestamp of the date the document was last modified.
1780
- */
1781
- get lastModified() {
1782
- return this._document.lastModified;
1783
- }
1784
- /**
1785
- * Gets the global revision number of the document.
1786
- */
1787
- get revision() {
1788
- return this._document.revision.global;
1789
- }
1790
- getRevision(o) {
1791
- return this._document.revision[o];
1792
- }
1793
- /**
1794
- * Gets the initial state of the document.
1795
- */
1796
- get initialState() {
1797
- return Z(this._document.initialState);
1798
- }
1799
- /**
1800
- * Returns the current document as an object
1801
- */
1802
- toDocument() {
1803
- return Z(this._document);
1804
- }
1805
- /**
1806
- * Gets the attachment associated with the given key.
1807
- * @param attachment - The key of the attachment to retrieve.
1808
- */
1809
- getAttachment(o) {
1810
- return this._document.attachments[o];
1811
- }
1812
- /**
1813
- * Sets the name of the document.
1814
- * @param name - The new name of the document.
1815
- */
1816
- setName(o) {
1817
- return this.dispatch(ee(o)), this;
1818
- }
1819
- /**
1820
- * Reverts a number of actions from the document.
1821
- * @param count - The number of actions to revert.
1822
- */
1823
- undo(o) {
1824
- return this.dispatch(re(o)), this;
1825
- }
1826
- /**
1827
- * Reapplies a number of actions to the document.
1828
- * @param count - The number of actions to reapply.
1829
- */
1830
- redo(o) {
1831
- return this.dispatch(ie(o)), this;
1832
- }
1833
- /**
1834
- * Removes a range of operations from the document.
1835
- * @param start - The starting index of the range to remove.
1836
- * @param end - The ending index of the range to remove.
1837
- */
1838
- prune(o, p) {
1839
- return this.dispatch(ne(o, p)), this;
1840
- }
1841
- /**
1842
- * Loads a document state and a set of operations.
1843
- * @param state - The state to load.
1844
- * @param operations - The operations to apply to the document.
1845
- */
1846
- loadState(o, p) {
1847
- return this.dispatch(ht(o, p)), this;
1848
- }
1849
- }
1850
- function $r(i, o) {
1851
- o.forEach((p) => {
1852
- Object.getOwnPropertyNames(p.prototype).forEach((c) => {
1853
- Object.defineProperty(
1854
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
1855
- i.prototype,
1856
- c,
1857
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
1858
- Object.getOwnPropertyDescriptor(p.prototype, c) || /* @__PURE__ */ Object.create(null)
1859
- );
1860
- });
1861
- });
1862
- }
1863
- export {
1864
- qr as B,
1865
- gr as a,
1866
- wr as b,
1867
- dr as c,
1868
- Cr as d,
1869
- Br as e,
1870
- L as f,
1871
- $r as g,
1872
- Mr as h,
1873
- Bt as i,
1874
- oe as j,
1875
- zr as k,
1876
- kt as l,
1877
- Lr as m,
1878
- Qt as n,
1879
- Nr as o,
1880
- St as p,
1881
- yr as q,
1882
- Z as r,
1883
- Sr as s,
1884
- te as t,
1885
- ot as u,
1886
- vr as v,
1887
- Rr as w,
1888
- Wt as x,
1889
- We as y,
1890
- Dr as z
1891
- };