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