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