document-model 1.0.27 → 1.0.29
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/browser/internal/index-4yGxwwIy.js +39 -0
- package/dist/browser/internal/{index-ff67644b.js → index-6HdjP6FJ.js} +1 -1
- package/dist/browser/internal/index-Gq2HRApL.js +1 -0
- package/dist/browser/internal/{index-99f8b333.js → index-kzWsCI12.js} +1 -1
- package/dist/browser/internal/object--K2azKgq.js +1930 -0
- package/dist/browser/internal/object-fOI-wxeh.js +6 -0
- package/dist/browser/src/document/actions/index.d.ts +5 -1
- package/dist/browser/src/document/actions/types.d.ts +1 -0
- package/dist/browser/src/document/utils/base.d.ts +1 -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/node/internal/{index-433d6a9b.js → index--hPewdfH.js} +1 -1
- package/dist/node/internal/index-e6AVyWY1.js +39 -0
- package/dist/node/internal/index-ibrN7Oyd.js +1 -0
- package/dist/node/internal/{index-a46dcf07.js → index-tC838AtY.js} +1 -1
- package/dist/node/internal/object-5_-Z2kaF.js +929 -0
- package/dist/node/internal/object-Mr9Iw0Mk.js +1 -0
- package/dist/node/src/document/actions/index.d.ts +5 -1
- package/dist/node/src/document/actions/types.d.ts +1 -0
- package/dist/node/src/document/utils/base.d.ts +1 -0
- package/dist/node/vitest.config.d.ts +1 -1
- package/package.json +2 -2
- package/dist/browser/internal/index-df4df518.js +0 -38
- package/dist/browser/internal/index-e019b5aa.js +0 -1
- package/dist/browser/internal/object-4b5800c0.js +0 -1891
- package/dist/browser/internal/object-be1b0c52.js +0 -6
- package/dist/node/internal/index-2d55ed8c.js +0 -38
- package/dist/node/internal/index-78c035e1.js +0 -1
- package/dist/node/internal/object-305e4c59.js +0 -893
- package/dist/node/internal/object-ff6617a2.js +0 -1
|
@@ -1,893 +0,0 @@
|
|
|
1
|
-
var xt = Object.defineProperty;
|
|
2
|
-
var ft = (t, e, i) => e in t ? xt(t, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : t[e] = i;
|
|
3
|
-
var j = (t, e, i) => (ft(t, typeof e != "symbol" ? e + "" : e, i), i);
|
|
4
|
-
import { produce as S, castDraft as D, castImmutable as gt, freeze as ht } from "immer";
|
|
5
|
-
import bt from "json-stringify-deterministic";
|
|
6
|
-
import { z as s } from "zod";
|
|
7
|
-
import vt from "crypto";
|
|
8
|
-
import N from "fs";
|
|
9
|
-
import yt from "https";
|
|
10
|
-
import { join as wt } from "path";
|
|
11
|
-
import $ from "jszip";
|
|
12
|
-
const J = (t) => t != null, jt = s.any().refine((t) => J(t)), B = s.enum(["LOAD_STATE"]), Z = s.enum(["PRUNE"]), H = s.enum(["REDO"]), K = s.enum(["SET_NAME"]), W = s.enum(["UNDO"]);
|
|
13
|
-
function Ot() {
|
|
14
|
-
return s.object({
|
|
15
|
-
__typename: s.literal("Action").optional(),
|
|
16
|
-
type: s.string()
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
function y() {
|
|
20
|
-
return s.literal("global").or(s.literal("local"));
|
|
21
|
-
}
|
|
22
|
-
function V() {
|
|
23
|
-
return s.union([
|
|
24
|
-
G(),
|
|
25
|
-
X(),
|
|
26
|
-
Y(),
|
|
27
|
-
tt(),
|
|
28
|
-
et()
|
|
29
|
-
]);
|
|
30
|
-
}
|
|
31
|
-
function St() {
|
|
32
|
-
return s.object({
|
|
33
|
-
__typename: s.literal("DocumentFile").optional(),
|
|
34
|
-
data: s.string(),
|
|
35
|
-
extension: s.string().nullable(),
|
|
36
|
-
fileName: s.string().nullable(),
|
|
37
|
-
mimeType: s.string()
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
function G() {
|
|
41
|
-
return s.object({
|
|
42
|
-
input: s.lazy(() => T()),
|
|
43
|
-
type: B,
|
|
44
|
-
scope: y()
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
function T() {
|
|
48
|
-
return s.object({
|
|
49
|
-
operations: s.number(),
|
|
50
|
-
state: s.lazy(() => Q())
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
function Q() {
|
|
54
|
-
return s.object({
|
|
55
|
-
data: s.unknown().nullish(),
|
|
56
|
-
name: s.string()
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
function kt() {
|
|
60
|
-
return s.object({
|
|
61
|
-
__typename: s.literal("Operation").optional(),
|
|
62
|
-
hash: s.string(),
|
|
63
|
-
index: s.number(),
|
|
64
|
-
timestamp: s.string().datetime(),
|
|
65
|
-
type: s.string()
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
function X() {
|
|
69
|
-
return s.object({
|
|
70
|
-
input: s.lazy(() => z()),
|
|
71
|
-
type: Z,
|
|
72
|
-
scope: y()
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
function z() {
|
|
76
|
-
return s.object({
|
|
77
|
-
end: s.number().nullish(),
|
|
78
|
-
start: s.number().nullish()
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
const I = s.number;
|
|
82
|
-
function Y() {
|
|
83
|
-
return s.object({
|
|
84
|
-
input: I(),
|
|
85
|
-
type: H,
|
|
86
|
-
scope: y()
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
const F = s.string;
|
|
90
|
-
function tt() {
|
|
91
|
-
return s.object({
|
|
92
|
-
input: F(),
|
|
93
|
-
type: K,
|
|
94
|
-
scope: s.literal("global")
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
function _t() {
|
|
98
|
-
return s.object({
|
|
99
|
-
__typename: s.literal("SetNameOperation").optional(),
|
|
100
|
-
hash: s.string(),
|
|
101
|
-
index: s.number(),
|
|
102
|
-
input: s.string(),
|
|
103
|
-
timestamp: s.string().datetime(),
|
|
104
|
-
type: s.string()
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
const R = s.number;
|
|
108
|
-
function et() {
|
|
109
|
-
return s.object({
|
|
110
|
-
input: R(),
|
|
111
|
-
type: W,
|
|
112
|
-
scope: y()
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
const re = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
116
|
-
__proto__: null,
|
|
117
|
-
ActionSchema: Ot,
|
|
118
|
-
BaseActionSchema: V,
|
|
119
|
-
DocumentFileSchema: St,
|
|
120
|
-
LoadStateActionInputSchema: T,
|
|
121
|
-
LoadStateActionSchema: G,
|
|
122
|
-
LoadStateActionStateInputSchema: Q,
|
|
123
|
-
Load_StateSchema: B,
|
|
124
|
-
OperationSchema: kt,
|
|
125
|
-
OperationScopeSchema: y,
|
|
126
|
-
PruneActionInputSchema: z,
|
|
127
|
-
PruneActionSchema: X,
|
|
128
|
-
PruneSchema: Z,
|
|
129
|
-
RedoActionInputSchema: I,
|
|
130
|
-
RedoActionSchema: Y,
|
|
131
|
-
RedoSchema: H,
|
|
132
|
-
SetNameActionInputSchema: F,
|
|
133
|
-
SetNameActionSchema: tt,
|
|
134
|
-
SetNameOperationSchema: _t,
|
|
135
|
-
Set_NameSchema: K,
|
|
136
|
-
UndoActionInputSchema: R,
|
|
137
|
-
UndoActionSchema: et,
|
|
138
|
-
UndoSchema: W,
|
|
139
|
-
definedNonNullAnySchema: jt,
|
|
140
|
-
isDefinedNonNullAny: J
|
|
141
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
142
|
-
function Et(t, e) {
|
|
143
|
-
return { ...t, name: e };
|
|
144
|
-
}
|
|
145
|
-
function Dt(t, e, i) {
|
|
146
|
-
const { scope: a, input: n } = e;
|
|
147
|
-
return S({
|
|
148
|
-
document: t,
|
|
149
|
-
action: e,
|
|
150
|
-
skip: i
|
|
151
|
-
}, (o) => {
|
|
152
|
-
if (o.document.operations[a].length < 1)
|
|
153
|
-
throw new Error(
|
|
154
|
-
`Cannot undo: no operations in history for scope "${a}"`
|
|
155
|
-
);
|
|
156
|
-
if (n < 1)
|
|
157
|
-
throw new Error(
|
|
158
|
-
"Invalid UNDO action: input value must be greater than 0"
|
|
159
|
-
);
|
|
160
|
-
if (o.skip > 0)
|
|
161
|
-
throw new Error(
|
|
162
|
-
"Cannot undo: skip value from reducer cannot be used with UNDO action"
|
|
163
|
-
);
|
|
164
|
-
const [c] = o.document.operations[a].slice(-1), u = c.type === "NOOP" && c.skip > 0;
|
|
165
|
-
if (o.skip += n, u && (o.skip += c.skip, o.document.operations[a].pop()), o.document.operations[a].length < o.skip)
|
|
166
|
-
throw new Error(
|
|
167
|
-
"Cannot undo: you can't undo more operations than the ones in the scope history"
|
|
168
|
-
);
|
|
169
|
-
const l = o.document.operations[a].length - 1;
|
|
170
|
-
let x = n, m = u ? l - c.skip : l;
|
|
171
|
-
for (; x > 0 && m >= 0; ) {
|
|
172
|
-
const d = o.document.operations[a][m];
|
|
173
|
-
d.type === "NOOP" && d.skip > 0 ? (m = m - (d.skip + 1), o.skip += d.skip + 1) : (o.document.clipboard.push({ ...d }), x--, m--);
|
|
174
|
-
}
|
|
175
|
-
o.action = M(a);
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
function Nt(t, e, i) {
|
|
179
|
-
const { scope: a, input: n } = e;
|
|
180
|
-
return S({
|
|
181
|
-
document: t,
|
|
182
|
-
action: e,
|
|
183
|
-
skip: i
|
|
184
|
-
}, (o) => {
|
|
185
|
-
if (o.skip > 0)
|
|
186
|
-
throw new Error(
|
|
187
|
-
"Cannot redo: skip value from reducer cannot be used with REDO action"
|
|
188
|
-
);
|
|
189
|
-
if (n > 1)
|
|
190
|
-
throw new Error(
|
|
191
|
-
"Cannot redo: you can only redo one operation at a time"
|
|
192
|
-
);
|
|
193
|
-
if (n < 1)
|
|
194
|
-
throw new Error("Invalid REDO action: invalid redo input value");
|
|
195
|
-
if (o.document.clipboard.length < 1)
|
|
196
|
-
throw new Error("Cannot redo: no operations in the clipboard");
|
|
197
|
-
const c = o.document.clipboard.findLastIndex(
|
|
198
|
-
(l) => l.scope === a
|
|
199
|
-
);
|
|
200
|
-
if (c < 0)
|
|
201
|
-
throw new Error(
|
|
202
|
-
`Cannot redo: no operations in clipboard for scope "${a}"`
|
|
203
|
-
);
|
|
204
|
-
const u = o.document.clipboard.splice(c, 1)[0];
|
|
205
|
-
o.action = D({
|
|
206
|
-
type: u.type,
|
|
207
|
-
scope: u.scope,
|
|
208
|
-
input: u.input
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
function At(t, e, i) {
|
|
213
|
-
const { scope: a } = e, n = t.operations[a];
|
|
214
|
-
let {
|
|
215
|
-
input: { start: p, end: o }
|
|
216
|
-
} = e;
|
|
217
|
-
p = p || 0, o = o || n.length;
|
|
218
|
-
const c = n.slice(p, o), u = n.slice(0, p), l = n.slice(o), x = A(
|
|
219
|
-
t.initialState,
|
|
220
|
-
{
|
|
221
|
-
...t.operations,
|
|
222
|
-
[a]: u.concat(c)
|
|
223
|
-
},
|
|
224
|
-
i
|
|
225
|
-
), { name: m, state: d } = x, r = u.length, v = u.length ? u[u.length - 1].timestamp : l.length ? l[0].timestamp : (/* @__PURE__ */ new Date()).toISOString();
|
|
226
|
-
return A(
|
|
227
|
-
t.initialState,
|
|
228
|
-
{
|
|
229
|
-
...t.operations,
|
|
230
|
-
[a]: [
|
|
231
|
-
...u,
|
|
232
|
-
{
|
|
233
|
-
...P(
|
|
234
|
-
{ name: m, state: d },
|
|
235
|
-
c.length
|
|
236
|
-
),
|
|
237
|
-
timestamp: v,
|
|
238
|
-
index: r,
|
|
239
|
-
hash: st({ state: d }, "global")
|
|
240
|
-
},
|
|
241
|
-
...l.map((f, E) => ({
|
|
242
|
-
...f,
|
|
243
|
-
index: r + E + 1
|
|
244
|
-
}))
|
|
245
|
-
]
|
|
246
|
-
},
|
|
247
|
-
i
|
|
248
|
-
);
|
|
249
|
-
}
|
|
250
|
-
function Tt(t, e) {
|
|
251
|
-
return {
|
|
252
|
-
...t,
|
|
253
|
-
name: e.name,
|
|
254
|
-
state: e.state ?? { global: {}, local: {} }
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
const it = "SET_NAME", g = "UNDO", h = "REDO", w = "PRUNE", at = "LOAD_STATE";
|
|
258
|
-
function zt(t, e) {
|
|
259
|
-
const i = t.revision[e.scope];
|
|
260
|
-
return [g, h, w].includes(e.type) ? i : i + 1;
|
|
261
|
-
}
|
|
262
|
-
function It(t, e) {
|
|
263
|
-
return {
|
|
264
|
-
...t,
|
|
265
|
-
revision: {
|
|
266
|
-
...t.revision,
|
|
267
|
-
[e.scope]: zt(t, e)
|
|
268
|
-
},
|
|
269
|
-
lastModified: (/* @__PURE__ */ new Date()).toISOString()
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
function Ft(t, e, i = 0) {
|
|
273
|
-
if ([g, h, w].includes(e.type))
|
|
274
|
-
return t;
|
|
275
|
-
const { scope: a } = e, n = t.operations[a].slice(
|
|
276
|
-
0,
|
|
277
|
-
t.revision[a]
|
|
278
|
-
);
|
|
279
|
-
return n.push({
|
|
280
|
-
...e,
|
|
281
|
-
index: n.length,
|
|
282
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
283
|
-
hash: "",
|
|
284
|
-
scope: a,
|
|
285
|
-
skip: i
|
|
286
|
-
}), {
|
|
287
|
-
...t,
|
|
288
|
-
operations: { ...t.operations, [a]: n }
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
function Rt(t, e, i = 0) {
|
|
292
|
-
let a = Ft(t, e, i);
|
|
293
|
-
return a = It(a, e), a;
|
|
294
|
-
}
|
|
295
|
-
function Pt(t, e, i) {
|
|
296
|
-
switch (V().parse(e), e.type) {
|
|
297
|
-
case it:
|
|
298
|
-
return Et(t, e.input);
|
|
299
|
-
case w:
|
|
300
|
-
return At(t, e, i);
|
|
301
|
-
case at:
|
|
302
|
-
return Tt(t, e.input.state);
|
|
303
|
-
default:
|
|
304
|
-
return t;
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
function Mt(t, e, i) {
|
|
308
|
-
switch (e.type) {
|
|
309
|
-
case g:
|
|
310
|
-
return Dt(t, e, i);
|
|
311
|
-
case h:
|
|
312
|
-
return Nt(t, e, i);
|
|
313
|
-
default:
|
|
314
|
-
return { document: t, action: e, skip: i };
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
function nt(t, e, i, a, n = {}) {
|
|
318
|
-
const { skip: p, ignoreSkipOperations: o = !1 } = n;
|
|
319
|
-
let c = { ...e }, u = p || 0, l = t, x = [...t.clipboard];
|
|
320
|
-
if (L(c)) {
|
|
321
|
-
const {
|
|
322
|
-
skip: m,
|
|
323
|
-
action: d,
|
|
324
|
-
document: r
|
|
325
|
-
} = Mt(t, c, u);
|
|
326
|
-
c = d, u = m, l = r, x = [...l.clipboard];
|
|
327
|
-
}
|
|
328
|
-
return U(c) && (l = Pt(l, c, i)), u > 0 && !o && (l = A(
|
|
329
|
-
l.initialState,
|
|
330
|
-
l.operations,
|
|
331
|
-
i,
|
|
332
|
-
void 0,
|
|
333
|
-
void 0,
|
|
334
|
-
void 0,
|
|
335
|
-
{ [c.scope]: u }
|
|
336
|
-
)), l = Rt(l, c, u), l = S(l, (m) => {
|
|
337
|
-
const d = i(
|
|
338
|
-
m.state,
|
|
339
|
-
c,
|
|
340
|
-
a
|
|
341
|
-
), r = L(e) ? [...x] : [];
|
|
342
|
-
if (d)
|
|
343
|
-
return D({
|
|
344
|
-
...l,
|
|
345
|
-
clipboard: [...r],
|
|
346
|
-
state: d
|
|
347
|
-
});
|
|
348
|
-
m.clipboard = D([...r]);
|
|
349
|
-
}), S(l, (m) => {
|
|
350
|
-
if ([g, h, w].includes(c.type))
|
|
351
|
-
return m;
|
|
352
|
-
const d = c.scope || "global";
|
|
353
|
-
m.operations[d][m.operations[d].length - 1].hash = st(m, d), !U(c) && c.attachments && c.attachments.forEach((r) => {
|
|
354
|
-
const { hash: v, ...f } = r;
|
|
355
|
-
m.attachments[v] = {
|
|
356
|
-
...f
|
|
357
|
-
};
|
|
358
|
-
});
|
|
359
|
-
});
|
|
360
|
-
}
|
|
361
|
-
function qt(t, e, i) {
|
|
362
|
-
const a = wt(t, e);
|
|
363
|
-
return N.mkdirSync(t, { recursive: !0 }), new Promise((n, p) => {
|
|
364
|
-
try {
|
|
365
|
-
N.writeFile(a, i, {}, (o) => {
|
|
366
|
-
o ? p(o) : n(a);
|
|
367
|
-
});
|
|
368
|
-
} catch (o) {
|
|
369
|
-
p(o);
|
|
370
|
-
}
|
|
371
|
-
});
|
|
372
|
-
}
|
|
373
|
-
function ot(t) {
|
|
374
|
-
return N.readFileSync(t);
|
|
375
|
-
}
|
|
376
|
-
function Lt(t) {
|
|
377
|
-
return new Promise((e, i) => {
|
|
378
|
-
yt.get(t, (a) => {
|
|
379
|
-
const n = [], p = a.headers["content-type"];
|
|
380
|
-
a.on("data", (o) => {
|
|
381
|
-
n.push(o);
|
|
382
|
-
}), a.on("end", () => {
|
|
383
|
-
e({ buffer: Buffer.concat(n), mimeType: p });
|
|
384
|
-
});
|
|
385
|
-
}).on("error", (a) => {
|
|
386
|
-
i(a);
|
|
387
|
-
});
|
|
388
|
-
});
|
|
389
|
-
}
|
|
390
|
-
const Ut = async (t) => ot(t), k = (t, e = "sha1") => vt.createHash(e).update(t).digest("base64");
|
|
391
|
-
function L(t) {
|
|
392
|
-
return [g, h].includes(t.type);
|
|
393
|
-
}
|
|
394
|
-
function U(t) {
|
|
395
|
-
return [it, g, h, w, at].includes(t.type);
|
|
396
|
-
}
|
|
397
|
-
function b(t, e, i, a, n = "global") {
|
|
398
|
-
if (!t)
|
|
399
|
-
throw new Error("Empty action type");
|
|
400
|
-
if (typeof t != "string")
|
|
401
|
-
throw new Error(`Invalid action type: ${t}`);
|
|
402
|
-
const p = { type: t, input: e, scope: n };
|
|
403
|
-
i && (p.attachments = i);
|
|
404
|
-
try {
|
|
405
|
-
a == null || a().parse(p.input);
|
|
406
|
-
} catch (o) {
|
|
407
|
-
throw new Error(`Invalid action input: ${o}`);
|
|
408
|
-
}
|
|
409
|
-
return p;
|
|
410
|
-
}
|
|
411
|
-
function Ct(t, e = nt) {
|
|
412
|
-
return (i, a, n, p) => e(i, a, t, n, p);
|
|
413
|
-
}
|
|
414
|
-
const $t = (t, e) => ({
|
|
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
|
-
...t,
|
|
425
|
-
state: (e == null ? void 0 : e(t == null ? void 0 : t.state)) ?? (t == null ? void 0 : t.state) ?? { global: {}, local: {} }
|
|
426
|
-
}), Jt = (t, e) => {
|
|
427
|
-
const i = $t(
|
|
428
|
-
t,
|
|
429
|
-
e
|
|
430
|
-
);
|
|
431
|
-
return {
|
|
432
|
-
...i,
|
|
433
|
-
initialState: i,
|
|
434
|
-
operations: { global: [], local: [] },
|
|
435
|
-
clipboard: []
|
|
436
|
-
};
|
|
437
|
-
}, st = (t, e = "global") => k(bt(t.state[e])), me = (t, e = 1e3) => {
|
|
438
|
-
const i = Math.random() * e;
|
|
439
|
-
return k(`${(t ?? /* @__PURE__ */ new Date()).toISOString()}${i}`);
|
|
440
|
-
};
|
|
441
|
-
function O(t) {
|
|
442
|
-
return gt(ht(t, !0));
|
|
443
|
-
}
|
|
444
|
-
function Bt(t, e) {
|
|
445
|
-
const i = [...t];
|
|
446
|
-
let a = e || 0, n = i.length > 0 ? i[i.length - 1].index : 0;
|
|
447
|
-
const p = [];
|
|
448
|
-
for (const o of i.reverse()) {
|
|
449
|
-
if (a > 0) {
|
|
450
|
-
const l = n - o.index;
|
|
451
|
-
a -= l;
|
|
452
|
-
}
|
|
453
|
-
if (a < 0)
|
|
454
|
-
throw new Error("Invalid operation index, missing operations");
|
|
455
|
-
const c = {
|
|
456
|
-
ignore: a > 0,
|
|
457
|
-
operation: o
|
|
458
|
-
}, u = o.skip > 0 ? o.skip + 1 : 0;
|
|
459
|
-
if (u > 0 && u > a) {
|
|
460
|
-
const l = u - a;
|
|
461
|
-
a = a + l;
|
|
462
|
-
}
|
|
463
|
-
n = o.index, p.push(c);
|
|
464
|
-
}
|
|
465
|
-
return p.reverse();
|
|
466
|
-
}
|
|
467
|
-
function ue(t) {
|
|
468
|
-
return Object.values(t).flatMap((e) => e).sort(
|
|
469
|
-
(e, i) => new Date(e.timestamp).getTime() - new Date(i.timestamp).getTime()
|
|
470
|
-
);
|
|
471
|
-
}
|
|
472
|
-
function Zt(t) {
|
|
473
|
-
return Object.values(t).flatMap((e) => e).sort(
|
|
474
|
-
(e, i) => new Date(e.operation.timestamp).getTime() - new Date(i.operation.timestamp).getTime()
|
|
475
|
-
);
|
|
476
|
-
}
|
|
477
|
-
function A(t, e, i, a, n, p = nt, o = {}) {
|
|
478
|
-
const c = Ct(i, p);
|
|
479
|
-
return pt(
|
|
480
|
-
t,
|
|
481
|
-
e,
|
|
482
|
-
c,
|
|
483
|
-
a,
|
|
484
|
-
n,
|
|
485
|
-
o
|
|
486
|
-
);
|
|
487
|
-
}
|
|
488
|
-
function pt(t, e, i, a, n, p = {}) {
|
|
489
|
-
const o = Jt(t), c = Object.keys(e).reduce((m, d) => {
|
|
490
|
-
const r = d;
|
|
491
|
-
return {
|
|
492
|
-
...m,
|
|
493
|
-
[r]: e[r].slice(0, n == null ? void 0 : n.revision[r])
|
|
494
|
-
};
|
|
495
|
-
}, {}), u = Object.keys(c).reduce(
|
|
496
|
-
(m, d) => {
|
|
497
|
-
const r = d;
|
|
498
|
-
return {
|
|
499
|
-
...m,
|
|
500
|
-
[r]: Bt(
|
|
501
|
-
c[r],
|
|
502
|
-
p[r]
|
|
503
|
-
)
|
|
504
|
-
};
|
|
505
|
-
},
|
|
506
|
-
{}
|
|
507
|
-
), l = Zt(u).reduce(
|
|
508
|
-
(m, { ignore: d, operation: r }) => d ? i(m, M(r.scope), a, {
|
|
509
|
-
skip: r.skip,
|
|
510
|
-
ignoreSkipOperations: !0
|
|
511
|
-
}) : i(m, r, a, {
|
|
512
|
-
skip: r.skip,
|
|
513
|
-
ignoreSkipOperations: !0
|
|
514
|
-
}),
|
|
515
|
-
o
|
|
516
|
-
), x = Object.keys(
|
|
517
|
-
l.operations
|
|
518
|
-
).reduce(
|
|
519
|
-
(m, d) => {
|
|
520
|
-
const r = d, v = n && n.revision[r] < e[r].length ? e[r].slice(n.revision[r]) : [];
|
|
521
|
-
return {
|
|
522
|
-
...m,
|
|
523
|
-
[r]: [
|
|
524
|
-
...l.operations[r].map((f, E) => {
|
|
525
|
-
var q;
|
|
526
|
-
return {
|
|
527
|
-
...f,
|
|
528
|
-
timestamp: ((q = e[r][E]) == null ? void 0 : q.timestamp) ?? f.timestamp
|
|
529
|
-
};
|
|
530
|
-
}),
|
|
531
|
-
...v
|
|
532
|
-
]
|
|
533
|
-
};
|
|
534
|
-
},
|
|
535
|
-
{ global: [], local: [] }
|
|
536
|
-
);
|
|
537
|
-
return { ...l, operations: x };
|
|
538
|
-
}
|
|
539
|
-
const ct = (t) => b(
|
|
540
|
-
"SET_NAME",
|
|
541
|
-
t,
|
|
542
|
-
void 0,
|
|
543
|
-
F,
|
|
544
|
-
void 0
|
|
545
|
-
), lt = (t = 1, e = "global") => b(
|
|
546
|
-
"UNDO",
|
|
547
|
-
t,
|
|
548
|
-
void 0,
|
|
549
|
-
R,
|
|
550
|
-
e
|
|
551
|
-
), rt = (t = 1, e = "global") => b(
|
|
552
|
-
"REDO",
|
|
553
|
-
t,
|
|
554
|
-
void 0,
|
|
555
|
-
I,
|
|
556
|
-
e
|
|
557
|
-
), mt = (t, e, i = "global") => b(
|
|
558
|
-
"PRUNE",
|
|
559
|
-
{ start: t, end: e },
|
|
560
|
-
void 0,
|
|
561
|
-
z,
|
|
562
|
-
i
|
|
563
|
-
), P = (t, e) => b(
|
|
564
|
-
"LOAD_STATE",
|
|
565
|
-
{ state: t, operations: e },
|
|
566
|
-
void 0,
|
|
567
|
-
T
|
|
568
|
-
), M = (t = "global") => b("NOOP", {}, void 0, void 0, t), de = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
569
|
-
__proto__: null,
|
|
570
|
-
loadState: P,
|
|
571
|
-
noop: M,
|
|
572
|
-
prune: mt,
|
|
573
|
-
redo: rt,
|
|
574
|
-
setName: ct,
|
|
575
|
-
undo: lt
|
|
576
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
577
|
-
function Ht(t) {
|
|
578
|
-
return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
|
|
579
|
-
}
|
|
580
|
-
function _() {
|
|
581
|
-
this._types = /* @__PURE__ */ Object.create(null), this._extensions = /* @__PURE__ */ Object.create(null);
|
|
582
|
-
for (let t = 0; t < arguments.length; t++)
|
|
583
|
-
this.define(arguments[t]);
|
|
584
|
-
this.define = this.define.bind(this), this.getType = this.getType.bind(this), this.getExtension = this.getExtension.bind(this);
|
|
585
|
-
}
|
|
586
|
-
_.prototype.define = function(t, e) {
|
|
587
|
-
for (let i in t) {
|
|
588
|
-
let a = t[i].map(function(n) {
|
|
589
|
-
return n.toLowerCase();
|
|
590
|
-
});
|
|
591
|
-
i = i.toLowerCase();
|
|
592
|
-
for (let n = 0; n < a.length; n++) {
|
|
593
|
-
const p = a[n];
|
|
594
|
-
if (p[0] !== "*") {
|
|
595
|
-
if (!e && p in this._types)
|
|
596
|
-
throw new Error(
|
|
597
|
-
'Attempt to change mapping for "' + p + '" extension from "' + this._types[p] + '" to "' + i + '". Pass `force=true` to allow this, otherwise remove "' + p + '" from the list of extensions for "' + i + '".'
|
|
598
|
-
);
|
|
599
|
-
this._types[p] = i;
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
if (e || !this._extensions[i]) {
|
|
603
|
-
const n = a[0];
|
|
604
|
-
this._extensions[i] = n[0] !== "*" ? n : n.substr(1);
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
};
|
|
608
|
-
_.prototype.getType = function(t) {
|
|
609
|
-
t = String(t);
|
|
610
|
-
let e = t.replace(/^.*[/\\]/, "").toLowerCase(), i = e.replace(/^.*\./, "").toLowerCase(), a = e.length < t.length;
|
|
611
|
-
return (i.length < e.length - 1 || !a) && this._types[i] || null;
|
|
612
|
-
};
|
|
613
|
-
_.prototype.getExtension = function(t) {
|
|
614
|
-
return t = /^\s*([^;\s]*)/.test(t) && RegExp.$1, t && this._extensions[t.toLowerCase()] || null;
|
|
615
|
-
};
|
|
616
|
-
var Kt = _, Wt = { "application/andrew-inset": ["ez"], "application/applixware": ["aw"], "application/atom+xml": ["atom"], "application/atomcat+xml": ["atomcat"], "application/atomdeleted+xml": ["atomdeleted"], "application/atomsvc+xml": ["atomsvc"], "application/atsc-dwd+xml": ["dwd"], "application/atsc-held+xml": ["held"], "application/atsc-rsat+xml": ["rsat"], "application/bdoc": ["bdoc"], "application/calendar+xml": ["xcs"], "application/ccxml+xml": ["ccxml"], "application/cdfx+xml": ["cdfx"], "application/cdmi-capability": ["cdmia"], "application/cdmi-container": ["cdmic"], "application/cdmi-domain": ["cdmid"], "application/cdmi-object": ["cdmio"], "application/cdmi-queue": ["cdmiq"], "application/cu-seeme": ["cu"], "application/dash+xml": ["mpd"], "application/davmount+xml": ["davmount"], "application/docbook+xml": ["dbk"], "application/dssc+der": ["dssc"], "application/dssc+xml": ["xdssc"], "application/ecmascript": ["es", "ecma"], "application/emma+xml": ["emma"], "application/emotionml+xml": ["emotionml"], "application/epub+zip": ["epub"], "application/exi": ["exi"], "application/express": ["exp"], "application/fdt+xml": ["fdt"], "application/font-tdpfr": ["pfr"], "application/geo+json": ["geojson"], "application/gml+xml": ["gml"], "application/gpx+xml": ["gpx"], "application/gxf": ["gxf"], "application/gzip": ["gz"], "application/hjson": ["hjson"], "application/hyperstudio": ["stk"], "application/inkml+xml": ["ink", "inkml"], "application/ipfix": ["ipfix"], "application/its+xml": ["its"], "application/java-archive": ["jar", "war", "ear"], "application/java-serialized-object": ["ser"], "application/java-vm": ["class"], "application/javascript": ["js", "mjs"], "application/json": ["json", "map"], "application/json5": ["json5"], "application/jsonml+json": ["jsonml"], "application/ld+json": ["jsonld"], "application/lgr+xml": ["lgr"], "application/lost+xml": ["lostxml"], "application/mac-binhex40": ["hqx"], "application/mac-compactpro": ["cpt"], "application/mads+xml": ["mads"], "application/manifest+json": ["webmanifest"], "application/marc": ["mrc"], "application/marcxml+xml": ["mrcx"], "application/mathematica": ["ma", "nb", "mb"], "application/mathml+xml": ["mathml"], "application/mbox": ["mbox"], "application/mediaservercontrol+xml": ["mscml"], "application/metalink+xml": ["metalink"], "application/metalink4+xml": ["meta4"], "application/mets+xml": ["mets"], "application/mmt-aei+xml": ["maei"], "application/mmt-usd+xml": ["musd"], "application/mods+xml": ["mods"], "application/mp21": ["m21", "mp21"], "application/mp4": ["mp4s", "m4p"], "application/msword": ["doc", "dot"], "application/mxf": ["mxf"], "application/n-quads": ["nq"], "application/n-triples": ["nt"], "application/node": ["cjs"], "application/octet-stream": ["bin", "dms", "lrf", "mar", "so", "dist", "distz", "pkg", "bpk", "dump", "elc", "deploy", "exe", "dll", "deb", "dmg", "iso", "img", "msi", "msp", "msm", "buffer"], "application/oda": ["oda"], "application/oebps-package+xml": ["opf"], "application/ogg": ["ogx"], "application/omdoc+xml": ["omdoc"], "application/onenote": ["onetoc", "onetoc2", "onetmp", "onepkg"], "application/oxps": ["oxps"], "application/p2p-overlay+xml": ["relo"], "application/patch-ops-error+xml": ["xer"], "application/pdf": ["pdf"], "application/pgp-encrypted": ["pgp"], "application/pgp-signature": ["asc", "sig"], "application/pics-rules": ["prf"], "application/pkcs10": ["p10"], "application/pkcs7-mime": ["p7m", "p7c"], "application/pkcs7-signature": ["p7s"], "application/pkcs8": ["p8"], "application/pkix-attr-cert": ["ac"], "application/pkix-cert": ["cer"], "application/pkix-crl": ["crl"], "application/pkix-pkipath": ["pkipath"], "application/pkixcmp": ["pki"], "application/pls+xml": ["pls"], "application/postscript": ["ai", "eps", "ps"], "application/provenance+xml": ["provx"], "application/pskc+xml": ["pskcxml"], "application/raml+yaml": ["raml"], "application/rdf+xml": ["rdf", "owl"], "application/reginfo+xml": ["rif"], "application/relax-ng-compact-syntax": ["rnc"], "application/resource-lists+xml": ["rl"], "application/resource-lists-diff+xml": ["rld"], "application/rls-services+xml": ["rs"], "application/route-apd+xml": ["rapd"], "application/route-s-tsid+xml": ["sls"], "application/route-usd+xml": ["rusd"], "application/rpki-ghostbusters": ["gbr"], "application/rpki-manifest": ["mft"], "application/rpki-roa": ["roa"], "application/rsd+xml": ["rsd"], "application/rss+xml": ["rss"], "application/rtf": ["rtf"], "application/sbml+xml": ["sbml"], "application/scvp-cv-request": ["scq"], "application/scvp-cv-response": ["scs"], "application/scvp-vp-request": ["spq"], "application/scvp-vp-response": ["spp"], "application/sdp": ["sdp"], "application/senml+xml": ["senmlx"], "application/sensml+xml": ["sensmlx"], "application/set-payment-initiation": ["setpay"], "application/set-registration-initiation": ["setreg"], "application/shf+xml": ["shf"], "application/sieve": ["siv", "sieve"], "application/smil+xml": ["smi", "smil"], "application/sparql-query": ["rq"], "application/sparql-results+xml": ["srx"], "application/srgs": ["gram"], "application/srgs+xml": ["grxml"], "application/sru+xml": ["sru"], "application/ssdl+xml": ["ssdl"], "application/ssml+xml": ["ssml"], "application/swid+xml": ["swidtag"], "application/tei+xml": ["tei", "teicorpus"], "application/thraud+xml": ["tfi"], "application/timestamped-data": ["tsd"], "application/toml": ["toml"], "application/trig": ["trig"], "application/ttml+xml": ["ttml"], "application/ubjson": ["ubj"], "application/urc-ressheet+xml": ["rsheet"], "application/urc-targetdesc+xml": ["td"], "application/voicexml+xml": ["vxml"], "application/wasm": ["wasm"], "application/widget": ["wgt"], "application/winhlp": ["hlp"], "application/wsdl+xml": ["wsdl"], "application/wspolicy+xml": ["wspolicy"], "application/xaml+xml": ["xaml"], "application/xcap-att+xml": ["xav"], "application/xcap-caps+xml": ["xca"], "application/xcap-diff+xml": ["xdf"], "application/xcap-el+xml": ["xel"], "application/xcap-ns+xml": ["xns"], "application/xenc+xml": ["xenc"], "application/xhtml+xml": ["xhtml", "xht"], "application/xliff+xml": ["xlf"], "application/xml": ["xml", "xsl", "xsd", "rng"], "application/xml-dtd": ["dtd"], "application/xop+xml": ["xop"], "application/xproc+xml": ["xpl"], "application/xslt+xml": ["*xsl", "xslt"], "application/xspf+xml": ["xspf"], "application/xv+xml": ["mxml", "xhvml", "xvml", "xvm"], "application/yang": ["yang"], "application/yin+xml": ["yin"], "application/zip": ["zip"], "audio/3gpp": ["*3gpp"], "audio/adpcm": ["adp"], "audio/amr": ["amr"], "audio/basic": ["au", "snd"], "audio/midi": ["mid", "midi", "kar", "rmi"], "audio/mobile-xmf": ["mxmf"], "audio/mp3": ["*mp3"], "audio/mp4": ["m4a", "mp4a"], "audio/mpeg": ["mpga", "mp2", "mp2a", "mp3", "m2a", "m3a"], "audio/ogg": ["oga", "ogg", "spx", "opus"], "audio/s3m": ["s3m"], "audio/silk": ["sil"], "audio/wav": ["wav"], "audio/wave": ["*wav"], "audio/webm": ["weba"], "audio/xm": ["xm"], "font/collection": ["ttc"], "font/otf": ["otf"], "font/ttf": ["ttf"], "font/woff": ["woff"], "font/woff2": ["woff2"], "image/aces": ["exr"], "image/apng": ["apng"], "image/avif": ["avif"], "image/bmp": ["bmp"], "image/cgm": ["cgm"], "image/dicom-rle": ["drle"], "image/emf": ["emf"], "image/fits": ["fits"], "image/g3fax": ["g3"], "image/gif": ["gif"], "image/heic": ["heic"], "image/heic-sequence": ["heics"], "image/heif": ["heif"], "image/heif-sequence": ["heifs"], "image/hej2k": ["hej2"], "image/hsj2": ["hsj2"], "image/ief": ["ief"], "image/jls": ["jls"], "image/jp2": ["jp2", "jpg2"], "image/jpeg": ["jpeg", "jpg", "jpe"], "image/jph": ["jph"], "image/jphc": ["jhc"], "image/jpm": ["jpm"], "image/jpx": ["jpx", "jpf"], "image/jxr": ["jxr"], "image/jxra": ["jxra"], "image/jxrs": ["jxrs"], "image/jxs": ["jxs"], "image/jxsc": ["jxsc"], "image/jxsi": ["jxsi"], "image/jxss": ["jxss"], "image/ktx": ["ktx"], "image/ktx2": ["ktx2"], "image/png": ["png"], "image/sgi": ["sgi"], "image/svg+xml": ["svg", "svgz"], "image/t38": ["t38"], "image/tiff": ["tif", "tiff"], "image/tiff-fx": ["tfx"], "image/webp": ["webp"], "image/wmf": ["wmf"], "message/disposition-notification": ["disposition-notification"], "message/global": ["u8msg"], "message/global-delivery-status": ["u8dsn"], "message/global-disposition-notification": ["u8mdn"], "message/global-headers": ["u8hdr"], "message/rfc822": ["eml", "mime"], "model/3mf": ["3mf"], "model/gltf+json": ["gltf"], "model/gltf-binary": ["glb"], "model/iges": ["igs", "iges"], "model/mesh": ["msh", "mesh", "silo"], "model/mtl": ["mtl"], "model/obj": ["obj"], "model/step+xml": ["stpx"], "model/step+zip": ["stpz"], "model/step-xml+zip": ["stpxz"], "model/stl": ["stl"], "model/vrml": ["wrl", "vrml"], "model/x3d+binary": ["*x3db", "x3dbz"], "model/x3d+fastinfoset": ["x3db"], "model/x3d+vrml": ["*x3dv", "x3dvz"], "model/x3d+xml": ["x3d", "x3dz"], "model/x3d-vrml": ["x3dv"], "text/cache-manifest": ["appcache", "manifest"], "text/calendar": ["ics", "ifb"], "text/coffeescript": ["coffee", "litcoffee"], "text/css": ["css"], "text/csv": ["csv"], "text/html": ["html", "htm", "shtml"], "text/jade": ["jade"], "text/jsx": ["jsx"], "text/less": ["less"], "text/markdown": ["markdown", "md"], "text/mathml": ["mml"], "text/mdx": ["mdx"], "text/n3": ["n3"], "text/plain": ["txt", "text", "conf", "def", "list", "log", "in", "ini"], "text/richtext": ["rtx"], "text/rtf": ["*rtf"], "text/sgml": ["sgml", "sgm"], "text/shex": ["shex"], "text/slim": ["slim", "slm"], "text/spdx": ["spdx"], "text/stylus": ["stylus", "styl"], "text/tab-separated-values": ["tsv"], "text/troff": ["t", "tr", "roff", "man", "me", "ms"], "text/turtle": ["ttl"], "text/uri-list": ["uri", "uris", "urls"], "text/vcard": ["vcard"], "text/vtt": ["vtt"], "text/xml": ["*xml"], "text/yaml": ["yaml", "yml"], "video/3gpp": ["3gp", "3gpp"], "video/3gpp2": ["3g2"], "video/h261": ["h261"], "video/h263": ["h263"], "video/h264": ["h264"], "video/iso.segment": ["m4s"], "video/jpeg": ["jpgv"], "video/jpm": ["*jpm", "jpgm"], "video/mj2": ["mj2", "mjp2"], "video/mp2t": ["ts"], "video/mp4": ["mp4", "mp4v", "mpg4"], "video/mpeg": ["mpeg", "mpg", "mpe", "m1v", "m2v"], "video/ogg": ["ogv"], "video/quicktime": ["qt", "mov"], "video/webm": ["webm"] };
|
|
617
|
-
let Vt = Kt;
|
|
618
|
-
var Gt = new Vt(Wt);
|
|
619
|
-
const Qt = /* @__PURE__ */ Ht(Gt), ut = async (t) => {
|
|
620
|
-
const e = new $(), { name: i, revision: a, documentType: n, created: p, lastModified: o } = t, c = {
|
|
621
|
-
name: i,
|
|
622
|
-
revision: a,
|
|
623
|
-
documentType: n,
|
|
624
|
-
created: p,
|
|
625
|
-
lastModified: o
|
|
626
|
-
};
|
|
627
|
-
return e.file("header.json", JSON.stringify(c, null, 2)), e.file(
|
|
628
|
-
"state.json",
|
|
629
|
-
JSON.stringify(t.initialState || {}, null, 2)
|
|
630
|
-
), e.file("operations.json", JSON.stringify(t.operations, null, 2)), Object.keys(t.attachments).forEach((l) => {
|
|
631
|
-
const { data: x, ...m } = t.attachments[l];
|
|
632
|
-
e.file(l, x, {
|
|
633
|
-
base64: !0,
|
|
634
|
-
createFolders: !0,
|
|
635
|
-
comment: JSON.stringify(m)
|
|
636
|
-
});
|
|
637
|
-
}), e;
|
|
638
|
-
}, Xt = async (t, e, i, a) => {
|
|
639
|
-
const p = await (await ut(t)).generateAsync({
|
|
640
|
-
type: "uint8array",
|
|
641
|
-
streamFiles: !0
|
|
642
|
-
}), o = a ?? t.name, c = `.${i}.zip`;
|
|
643
|
-
return qt(
|
|
644
|
-
e,
|
|
645
|
-
o.endsWith(c) ? o : `${o}${c}`,
|
|
646
|
-
p
|
|
647
|
-
);
|
|
648
|
-
}, xe = async (t, e) => {
|
|
649
|
-
const a = await (await ut(t)).generateAsync({ type: "blob" }), n = await e.createWritable();
|
|
650
|
-
await n.write(a), await n.close();
|
|
651
|
-
}, C = async (t, e) => {
|
|
652
|
-
const i = ot(t);
|
|
653
|
-
return Yt(i, e);
|
|
654
|
-
}, Yt = async (t, e) => {
|
|
655
|
-
const i = new $();
|
|
656
|
-
return await i.loadAsync(t), te(i, e);
|
|
657
|
-
};
|
|
658
|
-
async function te(t, e) {
|
|
659
|
-
const i = t.file("state.json");
|
|
660
|
-
if (!i)
|
|
661
|
-
throw new Error("Initial state not found");
|
|
662
|
-
const a = await i.async("string"), n = JSON.parse(a), p = t.file("header.json");
|
|
663
|
-
let o;
|
|
664
|
-
p && (o = JSON.parse(await p.async("string")));
|
|
665
|
-
const c = t.file("operations.json");
|
|
666
|
-
if (!c)
|
|
667
|
-
throw new Error("Operations history not found");
|
|
668
|
-
const u = JSON.parse(
|
|
669
|
-
await c.async("string")
|
|
670
|
-
);
|
|
671
|
-
let l = pt(
|
|
672
|
-
n,
|
|
673
|
-
u,
|
|
674
|
-
e,
|
|
675
|
-
void 0,
|
|
676
|
-
o
|
|
677
|
-
);
|
|
678
|
-
return o && (l = {
|
|
679
|
-
...l,
|
|
680
|
-
...o
|
|
681
|
-
}), l;
|
|
682
|
-
}
|
|
683
|
-
function dt(t) {
|
|
684
|
-
const e = t.replace(/^.*\./, "") || void 0, i = t.replace(/^.*[/\\]/, "") || void 0;
|
|
685
|
-
return { extension: e, fileName: i };
|
|
686
|
-
}
|
|
687
|
-
async function fe(t) {
|
|
688
|
-
const { buffer: e, mimeType: i = "application/octet-stream" } = await Lt(t), a = dt(t), n = e.toString("base64");
|
|
689
|
-
return {
|
|
690
|
-
data: n,
|
|
691
|
-
hash: k(n),
|
|
692
|
-
mimeType: i,
|
|
693
|
-
...a
|
|
694
|
-
};
|
|
695
|
-
}
|
|
696
|
-
async function ge(t) {
|
|
697
|
-
const e = await Ut(t), i = Qt.getType(t) || "application/octet-stream", a = dt(t), n = e.toString("base64");
|
|
698
|
-
return { data: n, hash: k(n), mimeType: i, ...a };
|
|
699
|
-
}
|
|
700
|
-
class he {
|
|
701
|
-
/**
|
|
702
|
-
* Constructs a BaseDocument instance with an initial state.
|
|
703
|
-
* @param reducer - The reducer function that updates the state.
|
|
704
|
-
* @param document - The initial state of the document.
|
|
705
|
-
*/
|
|
706
|
-
constructor(e, i, a) {
|
|
707
|
-
j(this, "_document");
|
|
708
|
-
j(this, "_reducer");
|
|
709
|
-
j(this, "_signalDispatch");
|
|
710
|
-
this._reducer = e, this._document = i, this._signalDispatch = a;
|
|
711
|
-
}
|
|
712
|
-
/**
|
|
713
|
-
* Dispatches an action to update the state of the document.
|
|
714
|
-
* @param action - The action to dispatch.
|
|
715
|
-
* @returns The Document instance.
|
|
716
|
-
*/
|
|
717
|
-
dispatch(e, i) {
|
|
718
|
-
return this._document = this._reducer(
|
|
719
|
-
this._document,
|
|
720
|
-
e,
|
|
721
|
-
this._signalDispatch,
|
|
722
|
-
i
|
|
723
|
-
), this;
|
|
724
|
-
}
|
|
725
|
-
/**
|
|
726
|
-
* Saves the state of the document to a file.
|
|
727
|
-
* @param path - The file path where the state should be saved.
|
|
728
|
-
* @param extension - The file extension to use when saving the state.
|
|
729
|
-
* @returns The file path where the state was saved.
|
|
730
|
-
*/
|
|
731
|
-
saveToFile(e, i, a) {
|
|
732
|
-
return Xt(this._document, e, i, a);
|
|
733
|
-
}
|
|
734
|
-
/**
|
|
735
|
-
* Loads the state of the document from a file.
|
|
736
|
-
* @param path - The file path where the state is stored.
|
|
737
|
-
*/
|
|
738
|
-
async loadFromFile(e) {
|
|
739
|
-
this._document = await C(e, this._reducer);
|
|
740
|
-
}
|
|
741
|
-
/**
|
|
742
|
-
* Loads the state of the document from a file and returns it.
|
|
743
|
-
* @param path - The file path where the state is stored.
|
|
744
|
-
* @param reducer - The reducer function that updates the state.
|
|
745
|
-
* @returns The state of the document.
|
|
746
|
-
*/
|
|
747
|
-
static async stateFromFile(e, i) {
|
|
748
|
-
return await C(e, i);
|
|
749
|
-
}
|
|
750
|
-
/**
|
|
751
|
-
* Gets the current state of the document.
|
|
752
|
-
*/
|
|
753
|
-
get state() {
|
|
754
|
-
return O(this._document.state);
|
|
755
|
-
}
|
|
756
|
-
/**
|
|
757
|
-
* Gets the list of operations performed on the document.
|
|
758
|
-
*/
|
|
759
|
-
get operations() {
|
|
760
|
-
return O(this._document.operations);
|
|
761
|
-
}
|
|
762
|
-
/**
|
|
763
|
-
* Gets the name of the document.
|
|
764
|
-
*/
|
|
765
|
-
get name() {
|
|
766
|
-
return this._document.name;
|
|
767
|
-
}
|
|
768
|
-
/**
|
|
769
|
-
* Gets the type of document.
|
|
770
|
-
*/
|
|
771
|
-
get documentType() {
|
|
772
|
-
return this._document.documentType;
|
|
773
|
-
}
|
|
774
|
-
/**
|
|
775
|
-
* Gets the timestamp of the date the document was created.
|
|
776
|
-
*/
|
|
777
|
-
get created() {
|
|
778
|
-
return this._document.created;
|
|
779
|
-
}
|
|
780
|
-
/**
|
|
781
|
-
* Gets the timestamp of the date the document was last modified.
|
|
782
|
-
*/
|
|
783
|
-
get lastModified() {
|
|
784
|
-
return this._document.lastModified;
|
|
785
|
-
}
|
|
786
|
-
/**
|
|
787
|
-
* Gets the global revision number of the document.
|
|
788
|
-
*/
|
|
789
|
-
get revision() {
|
|
790
|
-
return this._document.revision.global;
|
|
791
|
-
}
|
|
792
|
-
getRevision(e) {
|
|
793
|
-
return this._document.revision[e];
|
|
794
|
-
}
|
|
795
|
-
/**
|
|
796
|
-
* Gets the initial state of the document.
|
|
797
|
-
*/
|
|
798
|
-
get initialState() {
|
|
799
|
-
return O(this._document.initialState);
|
|
800
|
-
}
|
|
801
|
-
/**
|
|
802
|
-
* Returns the current document as an object
|
|
803
|
-
*/
|
|
804
|
-
toDocument() {
|
|
805
|
-
return O(this._document);
|
|
806
|
-
}
|
|
807
|
-
/**
|
|
808
|
-
* Gets the attachment associated with the given key.
|
|
809
|
-
* @param attachment - The key of the attachment to retrieve.
|
|
810
|
-
*/
|
|
811
|
-
getAttachment(e) {
|
|
812
|
-
return this._document.attachments[e];
|
|
813
|
-
}
|
|
814
|
-
/**
|
|
815
|
-
* Sets the name of the document.
|
|
816
|
-
* @param name - The new name of the document.
|
|
817
|
-
*/
|
|
818
|
-
setName(e) {
|
|
819
|
-
return this.dispatch(ct(e)), this;
|
|
820
|
-
}
|
|
821
|
-
/**
|
|
822
|
-
* Reverts a number of actions from the document.
|
|
823
|
-
* @param count - The number of actions to revert.
|
|
824
|
-
*/
|
|
825
|
-
undo(e) {
|
|
826
|
-
return this.dispatch(lt(e)), this;
|
|
827
|
-
}
|
|
828
|
-
/**
|
|
829
|
-
* Reapplies a number of actions to the document.
|
|
830
|
-
* @param count - The number of actions to reapply.
|
|
831
|
-
*/
|
|
832
|
-
redo(e) {
|
|
833
|
-
return this.dispatch(rt(e)), this;
|
|
834
|
-
}
|
|
835
|
-
/**
|
|
836
|
-
* Removes a range of operations from the document.
|
|
837
|
-
* @param start - The starting index of the range to remove.
|
|
838
|
-
* @param end - The ending index of the range to remove.
|
|
839
|
-
*/
|
|
840
|
-
prune(e, i) {
|
|
841
|
-
return this.dispatch(mt(e, i)), this;
|
|
842
|
-
}
|
|
843
|
-
/**
|
|
844
|
-
* Loads a document state and a set of operations.
|
|
845
|
-
* @param state - The state to load.
|
|
846
|
-
* @param operations - The operations to apply to the document.
|
|
847
|
-
*/
|
|
848
|
-
loadState(e, i) {
|
|
849
|
-
return this.dispatch(P(e, i)), this;
|
|
850
|
-
}
|
|
851
|
-
}
|
|
852
|
-
function be(t, e) {
|
|
853
|
-
e.forEach((i) => {
|
|
854
|
-
Object.getOwnPropertyNames(i.prototype).forEach((a) => {
|
|
855
|
-
Object.defineProperty(
|
|
856
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
857
|
-
t.prototype,
|
|
858
|
-
a,
|
|
859
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
|
|
860
|
-
Object.getOwnPropertyDescriptor(i.prototype, a) || /* @__PURE__ */ Object.create(null)
|
|
861
|
-
);
|
|
862
|
-
});
|
|
863
|
-
});
|
|
864
|
-
}
|
|
865
|
-
export {
|
|
866
|
-
he as B,
|
|
867
|
-
$t as a,
|
|
868
|
-
Jt as b,
|
|
869
|
-
Ct as c,
|
|
870
|
-
xe as d,
|
|
871
|
-
Yt as e,
|
|
872
|
-
b as f,
|
|
873
|
-
be as g,
|
|
874
|
-
de as h,
|
|
875
|
-
U as i,
|
|
876
|
-
ut as j,
|
|
877
|
-
ge as k,
|
|
878
|
-
C as l,
|
|
879
|
-
fe as m,
|
|
880
|
-
st as n,
|
|
881
|
-
me as o,
|
|
882
|
-
L as p,
|
|
883
|
-
Bt as q,
|
|
884
|
-
O as r,
|
|
885
|
-
Xt as s,
|
|
886
|
-
pt as t,
|
|
887
|
-
A as u,
|
|
888
|
-
Zt as v,
|
|
889
|
-
ue as w,
|
|
890
|
-
nt as x,
|
|
891
|
-
Mt as y,
|
|
892
|
-
re as z
|
|
893
|
-
};
|