@mengine/medeo-client 2.1.1-dsl.25 → 2.1.1-dsl.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/README.md +5 -5
- package/dist/{dsl-DrQOG0a6.js → dsl-SmWJTQWV.js} +2117 -4
- package/dist/dsl.d.ts +1 -2
- package/dist/dsl.js +1 -2
- package/dist/{index-CmuDB_Gm.d.ts → index-B1Lqm_Z1.d.ts} +883 -5
- package/dist/{index-BOgr8p8C.d.ts → index-pULoWyd9.d.ts} +199 -2
- package/dist/index.d.ts +2 -4
- package/dist/index.js +803 -4
- package/dist/schemas.d.ts +21 -21
- package/dist/schemas.js +57 -21
- package/dist/testing.d.ts +1 -4
- package/dist/testing.js +27 -40
- package/package.json +5 -6
- package/dist/index-BGEcTwoD.d.ts +0 -202
- package/dist/legacy.d.ts +0 -1044
- package/dist/legacy.js +0 -4349
- package/dist/shared-iWnU2osE.js +0 -39
- package/dist/storage-evqvKS4B.js +0 -805
- package/dist/video-draft-types-DRGBN0we.js +0 -1551
- package/dist/video-draft-types-slnHaNs9.d.ts +0 -882
|
@@ -1,6 +1,337 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { sha256 } from "@noble/hashes/sha2.js";
|
|
2
2
|
import { Cursor, LoroDoc, LoroList, LoroMap, LoroMovableList, LoroText, LoroTree, isContainer, isContainerId } from "loro-crdt";
|
|
3
|
-
|
|
3
|
+
//#region ../medeo-dsl/src/ids.ts
|
|
4
|
+
function bytesToBase64url(bytes) {
|
|
5
|
+
let binary = "";
|
|
6
|
+
for (const byte of bytes) binary += String.fromCharCode(byte);
|
|
7
|
+
return btoa(binary).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, "");
|
|
8
|
+
}
|
|
9
|
+
function base64urlToBytes(value) {
|
|
10
|
+
if (!/^[A-Za-z0-9_-]+$/.test(value) || value.length % 4 === 1) throw new Error("Invalid base64url");
|
|
11
|
+
const bytes = Uint8Array.from(atob(value.replaceAll("-", "+").replaceAll("_", "/")), (c) => c.charCodeAt(0));
|
|
12
|
+
if (bytesToBase64url(bytes) !== value) throw new Error("Non-canonical base64url");
|
|
13
|
+
return bytes;
|
|
14
|
+
}
|
|
15
|
+
function tupleHash(tuple) {
|
|
16
|
+
return bytesToBase64url(sha256(new TextEncoder().encode(JSON.stringify(tuple))));
|
|
17
|
+
}
|
|
18
|
+
function resourceId(kind, system, key) {
|
|
19
|
+
return `${kind}:${tupleHash([system, key])}`;
|
|
20
|
+
}
|
|
21
|
+
function relationId(table, value) {
|
|
22
|
+
const v = value;
|
|
23
|
+
switch (table) {
|
|
24
|
+
case "voice-timbre-relations": return `voice-timbre:${tupleHash([v.recordingId, v.voiceId])}`;
|
|
25
|
+
case "derived-from-relations": return `derived-from:${tupleHash([v.entityId, v.sourceId])}`;
|
|
26
|
+
}
|
|
27
|
+
throw new Error(`Unknown relation table: ${table}`);
|
|
28
|
+
}
|
|
29
|
+
const defaultIdFactory = (kind) => `${kind}_${globalThis.crypto.randomUUID()}`;
|
|
30
|
+
const resourceKinds = {
|
|
31
|
+
"media-entities": "media",
|
|
32
|
+
"voice-entities": "voice"
|
|
33
|
+
};
|
|
34
|
+
/** A resource row's ID is derived from its locator, so one external resource is one entity. */
|
|
35
|
+
function assertResourceIdentity(table, id, value) {
|
|
36
|
+
const kind = resourceKinds[table];
|
|
37
|
+
if (kind && id !== resourceId(kind, value.system, value.key)) throw new Error("Resource identity does not match locator");
|
|
38
|
+
}
|
|
39
|
+
/** A relation row's ID is derived from its two ends. */
|
|
40
|
+
function assertRelationIdentity(table, id, value) {
|
|
41
|
+
if (id !== relationId(table, value)) throw new Error("Relation ID does not match endpoints");
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region ../medeo-dsl/src/fields.ts
|
|
45
|
+
const string = (v) => typeof v === "string";
|
|
46
|
+
const nonempty = (v) => string(v) && v.length > 0;
|
|
47
|
+
const finite = (v) => typeof v === "number" && Number.isFinite(v);
|
|
48
|
+
const fraction = (v) => finite(v) && v >= 0 && v <= 1;
|
|
49
|
+
const integer = (v) => typeof v === "number" && Number.isSafeInteger(v);
|
|
50
|
+
const nonnegative = (v) => integer(v) && v >= 0;
|
|
51
|
+
const positive = (v) => integer(v) && v > 0;
|
|
52
|
+
const oneOf = (...values) => (v) => values.includes(v);
|
|
53
|
+
const required = (check) => ({ check });
|
|
54
|
+
const optional$1 = (check) => ({
|
|
55
|
+
check,
|
|
56
|
+
optional: true
|
|
57
|
+
});
|
|
58
|
+
const reservedIds = [
|
|
59
|
+
"$cid",
|
|
60
|
+
"__proto__",
|
|
61
|
+
"constructor",
|
|
62
|
+
"prototype"
|
|
63
|
+
];
|
|
64
|
+
const id = (v) => nonempty(v) && !reservedIds.includes(v);
|
|
65
|
+
const cursor = (v) => v instanceof Cursor;
|
|
66
|
+
function isRecord(value) {
|
|
67
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) && !(value instanceof Cursor);
|
|
68
|
+
}
|
|
69
|
+
function assertId(value) {
|
|
70
|
+
if (!id(value)) throw new Error("Expected a nonempty, non-reserved ID");
|
|
71
|
+
}
|
|
72
|
+
function validLanguage(value) {
|
|
73
|
+
if (typeof value !== "string") return false;
|
|
74
|
+
if (/^x(?:-[a-z0-9]{1,8})+$/i.test(value)) return true;
|
|
75
|
+
try {
|
|
76
|
+
return value.length > 0 && Intl.getCanonicalLocales(value).length === 1;
|
|
77
|
+
} catch {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function object(fields) {
|
|
82
|
+
return (v) => {
|
|
83
|
+
try {
|
|
84
|
+
checkFields(v, fields);
|
|
85
|
+
return true;
|
|
86
|
+
} catch {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function checkFields(value, fields, partial = false) {
|
|
92
|
+
if (!isRecord(value)) throw new Error("Expected an object");
|
|
93
|
+
for (const key of Object.keys(value)) if (!Object.hasOwn(fields, key)) throw new Error(`Unknown field: ${key}`);
|
|
94
|
+
for (const [key, field] of Object.entries(fields)) {
|
|
95
|
+
if (partial && !Object.hasOwn(value, key)) continue;
|
|
96
|
+
const v = value[key];
|
|
97
|
+
if (v === void 0 && field.optional) continue;
|
|
98
|
+
if (!field.check(v)) throw new Error(`Invalid or missing field: ${key}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const styleFields = {
|
|
102
|
+
font: optional$1(object({
|
|
103
|
+
system: required(oneOf("font-library")),
|
|
104
|
+
key: required(nonempty)
|
|
105
|
+
})),
|
|
106
|
+
fontSize: optional$1(finite),
|
|
107
|
+
fontColor: optional$1(string),
|
|
108
|
+
fontWeight: optional$1(finite),
|
|
109
|
+
entranceAnimation: optional$1(string),
|
|
110
|
+
entranceAnimationDurationMs: optional$1(nonnegative),
|
|
111
|
+
strokeColor: optional$1(string),
|
|
112
|
+
strokeWidth: optional$1(finite),
|
|
113
|
+
positionX: optional$1(fraction),
|
|
114
|
+
positionY: optional$1(fraction)
|
|
115
|
+
};
|
|
116
|
+
const seqMarkerFields = {
|
|
117
|
+
inMs: required(nonnegative),
|
|
118
|
+
outMs: required(nonnegative),
|
|
119
|
+
rate: optional$1((v) => finite(v) && v > 0),
|
|
120
|
+
fillTimeline: optional$1(oneOf(true))
|
|
121
|
+
};
|
|
122
|
+
/** A sequence marker's own fields; the window being nonempty is checked where it is written. */
|
|
123
|
+
function assertSeqMarker(value) {
|
|
124
|
+
checkFields(value, seqMarkerFields);
|
|
125
|
+
}
|
|
126
|
+
const timeAnchorFields = {
|
|
127
|
+
to: required(id),
|
|
128
|
+
offsetMs: required(integer),
|
|
129
|
+
fallback_abs_ms: required(nonnegative)
|
|
130
|
+
};
|
|
131
|
+
/** A time anchor's own fields; what it points at is checked by `assertReferenceAdmitted`. */
|
|
132
|
+
function assertTimeAnchor(value) {
|
|
133
|
+
checkFields(value, timeAnchorFields);
|
|
134
|
+
}
|
|
135
|
+
const selectionFields = {
|
|
136
|
+
audioScriptId: required(id),
|
|
137
|
+
segmentId: required(id),
|
|
138
|
+
start: optional$1(cursor),
|
|
139
|
+
end: optional$1(cursor)
|
|
140
|
+
};
|
|
141
|
+
/** A whole segment, or a run inside it: both ends or neither. */
|
|
142
|
+
const segmentSelection = (fields) => (v) => object(fields)(v) && v.start === void 0 === (v.end === void 0);
|
|
143
|
+
function assertCaptionContent(value) {
|
|
144
|
+
if (!segmentSelection(selectionFields)(value)) throw new Error("Invalid segment selection");
|
|
145
|
+
}
|
|
146
|
+
const phonemeFields = {
|
|
147
|
+
...selectionFields,
|
|
148
|
+
phonemeScript: optional$1(nonempty)
|
|
149
|
+
};
|
|
150
|
+
/** D190: omitted pronunciation uses the selected source words; an authored pronunciation is never empty. */
|
|
151
|
+
function assertPhonemeScript(value) {
|
|
152
|
+
if (value !== void 0 && !nonempty(value)) throw new Error("phonemeScript must be nonempty when provided");
|
|
153
|
+
}
|
|
154
|
+
function assertPhoneme(value) {
|
|
155
|
+
if (!segmentSelection(phonemeFields)(value)) throw new Error("Invalid phoneme");
|
|
156
|
+
}
|
|
157
|
+
const segmentFields = {
|
|
158
|
+
id: required(id),
|
|
159
|
+
text: required(string),
|
|
160
|
+
startMs: optional$1(nonnegative),
|
|
161
|
+
endMs: optional$1(nonnegative)
|
|
162
|
+
};
|
|
163
|
+
/** A segment's time in the medium it was read off: both ends or neither, the end not before the start. */
|
|
164
|
+
const segment = (v) => {
|
|
165
|
+
if (!object(segmentFields)(v)) return false;
|
|
166
|
+
const { startMs, endMs } = v;
|
|
167
|
+
return startMs === void 0 ? endMs === void 0 : endMs !== void 0 && endMs >= startMs;
|
|
168
|
+
};
|
|
169
|
+
/** One segment as a script stores it; a segment added on its own is checked here, not with its row. */
|
|
170
|
+
function assertScriptSegment(value) {
|
|
171
|
+
if (!segment(value)) throw new Error("A segment is { id, text } with startMs and endMs both or neither, endMs not before startMs");
|
|
172
|
+
}
|
|
173
|
+
/** A script's segments: each with its own id, unique within the script. */
|
|
174
|
+
const segments = (v) => Array.isArray(v) && v.every(segment) && new Set(v.map((s) => s.id)).size === v.length;
|
|
175
|
+
const locator = {
|
|
176
|
+
system: required(oneOf("memota", "memota-speech")),
|
|
177
|
+
key: required(nonempty)
|
|
178
|
+
};
|
|
179
|
+
const entityFields = {
|
|
180
|
+
"timeline-entities": {},
|
|
181
|
+
"track-entities": {
|
|
182
|
+
role: required(oneOf("video_clip", "speech", "caption", "bgm")),
|
|
183
|
+
hidden: optional$1((v) => typeof v === "boolean")
|
|
184
|
+
},
|
|
185
|
+
"clip-entities": {
|
|
186
|
+
seqMarker: required(object(seqMarkerFields)),
|
|
187
|
+
volume: optional$1(finite),
|
|
188
|
+
source: required(id),
|
|
189
|
+
anchor: optional$1(object(timeAnchorFields))
|
|
190
|
+
},
|
|
191
|
+
"media-entities": {
|
|
192
|
+
...locator,
|
|
193
|
+
kind: required(oneOf("video", "audio", "voiceover-recording", "image")),
|
|
194
|
+
storageKey: optional$1(nonempty),
|
|
195
|
+
durationMs: optional$1(positive),
|
|
196
|
+
digest: optional$1(nonempty)
|
|
197
|
+
},
|
|
198
|
+
"audio-script-entities": {
|
|
199
|
+
segments: required(segments),
|
|
200
|
+
defaultLanguage: optional$1(validLanguage),
|
|
201
|
+
system: optional$1(oneOf("memota")),
|
|
202
|
+
key: optional$1(nonempty),
|
|
203
|
+
storageKey: optional$1(nonempty),
|
|
204
|
+
digest: optional$1(nonempty)
|
|
205
|
+
},
|
|
206
|
+
"phonetic-script-entities": {
|
|
207
|
+
phoneme: optional$1(segmentSelection(phonemeFields)),
|
|
208
|
+
system: optional$1(oneOf("memota")),
|
|
209
|
+
key: optional$1(nonempty),
|
|
210
|
+
storageKey: optional$1(nonempty),
|
|
211
|
+
digest: optional$1(nonempty)
|
|
212
|
+
},
|
|
213
|
+
"caption-entities": {
|
|
214
|
+
selection: optional$1(segmentSelection(selectionFields)),
|
|
215
|
+
text: optional$1(string),
|
|
216
|
+
style: optional$1(object(styleFields))
|
|
217
|
+
},
|
|
218
|
+
"voice-entities": {
|
|
219
|
+
system: required(oneOf("voice-library")),
|
|
220
|
+
key: required(nonempty),
|
|
221
|
+
name: optional$1(string)
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
const entityTables = Object.keys(entityFields);
|
|
225
|
+
/**
|
|
226
|
+
* Fields stored as one encoded string: written whole, never merged field by field. A patch to one
|
|
227
|
+
* is merged into the current value first, then the whole value is written.
|
|
228
|
+
*/
|
|
229
|
+
const atomicFields = {
|
|
230
|
+
"clip-entities": ["seqMarker", "anchor"],
|
|
231
|
+
"phonetic-script-entities": ["phoneme"],
|
|
232
|
+
"caption-entities": ["selection"]
|
|
233
|
+
};
|
|
234
|
+
const relationFields = {
|
|
235
|
+
"voice-timbre-relations": {
|
|
236
|
+
recordingId: required(id),
|
|
237
|
+
voiceId: required(id)
|
|
238
|
+
},
|
|
239
|
+
"derived-from-relations": {
|
|
240
|
+
entityId: required(id),
|
|
241
|
+
sourceId: required(id),
|
|
242
|
+
sourceDigest: optional$1(nonempty)
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
const relationTables = Object.keys(relationFields);
|
|
246
|
+
const fileFields = [
|
|
247
|
+
"system",
|
|
248
|
+
"key",
|
|
249
|
+
"storageKey",
|
|
250
|
+
"digest"
|
|
251
|
+
];
|
|
252
|
+
const phonemeScriptOf = (row) => isRecord(row.phoneme) ? row.phoneme.phonemeScript : void 0;
|
|
253
|
+
/**
|
|
254
|
+
* A PhoneticScript as a write leaves it: written for a segment (D181), and its phonemeScript is raw
|
|
255
|
+
* content stored as its file (D178) — with text the row names that file and its digest, without
|
|
256
|
+
* text it has no file, and rewritten text is a new file.
|
|
257
|
+
*/
|
|
258
|
+
function assertPhoneticScript(before, after) {
|
|
259
|
+
if (!isRecord(after.phoneme)) throw new Error("A PhoneticScript is written for a segment of its base script");
|
|
260
|
+
if (phonemeScriptOf(after) === void 0) {
|
|
261
|
+
if (fileFields.some((field) => after[field] !== void 0)) throw new Error("A PhoneticScript without text has no file");
|
|
262
|
+
} else if (after.system === void 0 || after.key === void 0 || after.digest === void 0) throw new Error("A PhoneticScript stores its phonemeScript as a file: name it by system and key with its digest");
|
|
263
|
+
if (before !== void 0 && phonemeScriptOf(after) !== phonemeScriptOf(before) && after.digest !== void 0 && after.digest === before.digest) throw new Error("A rewritten phonemeScript is stored again: write its new file");
|
|
264
|
+
}
|
|
265
|
+
/** A transcript names the file it was read from by system and key together; its facts come with that name. */
|
|
266
|
+
function assertTranscriptFile(row) {
|
|
267
|
+
if (row.system === void 0 !== (row.key === void 0)) throw new Error("A transcript names its transcription file by system and key");
|
|
268
|
+
if (row.key === void 0 && (row.storageKey !== void 0 || row.digest !== void 0)) throw new Error("A script without a transcription file has no file facts");
|
|
269
|
+
}
|
|
270
|
+
function assertEntity(table, value) {
|
|
271
|
+
checkFields(value, entityFields[table]);
|
|
272
|
+
if (table === "audio-script-entities") assertTranscriptFile(value);
|
|
273
|
+
if (table === "media-entities") {
|
|
274
|
+
if (value.kind === "image" && value.durationMs !== void 0) throw new Error("Image has no intrinsic duration");
|
|
275
|
+
if (value.kind !== "image" && !positive(value.durationMs)) throw new Error("Finite media requires durationMs");
|
|
276
|
+
if (["audio", "voiceover-recording"].includes(value.kind) && !nonempty(value.storageKey)) throw new Error("Audio requires storageKey");
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
/** Validate only touched fields, so an unrelated edit can proceed in a merged, invalid document. */
|
|
280
|
+
function assertEntityPatch(table, patch, current) {
|
|
281
|
+
if (!isRecord(patch)) throw new Error("Expected an entity patch");
|
|
282
|
+
if (table === "audio-script-entities" && Object.hasOwn(patch, "segments")) throw new Error("Change segments with segment mutations and edit their text through the Text adapter");
|
|
283
|
+
if (table === "caption-entities" && current.style !== void 0 && Object.hasOwn(patch, "style") && patch.style === void 0) throw new Error("Reset individual style fields; retain the style Map");
|
|
284
|
+
if (table === "caption-entities" && current.text !== void 0 && patch.text !== void 0) throw new Error("Edit Caption text through the Text adapter");
|
|
285
|
+
const next = patchRow(table, current, patch);
|
|
286
|
+
for (const key of Object.keys(patch)) {
|
|
287
|
+
const field = entityFields[table][key];
|
|
288
|
+
if (!field || !field.optional && next[key] === void 0 || next[key] !== void 0 && !field.check(next[key])) throw new Error(`Invalid patch field: ${key}`);
|
|
289
|
+
}
|
|
290
|
+
if (table === "audio-script-entities" && fileFields.some((field) => Object.hasOwn(patch, field))) {
|
|
291
|
+
if (current.key !== void 0 && (next.system !== current.system || next.key !== current.key)) throw new Error("A transcript's transcription file is fixed once named");
|
|
292
|
+
assertTranscriptFile(next);
|
|
293
|
+
}
|
|
294
|
+
if (table === "media-entities" || table === "voice-entities") {
|
|
295
|
+
for (const key of [
|
|
296
|
+
"system",
|
|
297
|
+
"key",
|
|
298
|
+
"kind"
|
|
299
|
+
]) if (Object.hasOwn(patch, key) && patch[key] !== current[key]) throw new Error(`Resource identity field is immutable: ${key}`);
|
|
300
|
+
}
|
|
301
|
+
if (table === "media-entities") {
|
|
302
|
+
if (Object.hasOwn(patch, "durationMs")) {
|
|
303
|
+
if (next.kind === "image" ? next.durationMs !== void 0 : !positive(next.durationMs)) throw new Error("durationMs must match the media kind");
|
|
304
|
+
}
|
|
305
|
+
if (Object.hasOwn(patch, "storageKey") && ["audio", "voiceover-recording"].includes(next.kind) && !nonempty(next.storageKey)) throw new Error("Audio requires storageKey");
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
function assertRelation(table, value) {
|
|
309
|
+
checkFields(value, relationFields[table]);
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* The row after a patch. An atomic field merges into its current value, so a partial patch keeps
|
|
313
|
+
* the rest of it; an unreadable stored value is replaced instead, so writing a whole value repairs it.
|
|
314
|
+
*/
|
|
315
|
+
function patchRow(table, current, patch) {
|
|
316
|
+
const next = mergeFields(current, patch);
|
|
317
|
+
for (const key of atomicFields[table] ?? []) {
|
|
318
|
+
const old = current[key];
|
|
319
|
+
const value = patch[key];
|
|
320
|
+
if (value !== void 0 && isRecord(old) && old.invalid === true) next[key] = isRecord(value) ? mergeFields({}, value) : value;
|
|
321
|
+
}
|
|
322
|
+
return next;
|
|
323
|
+
}
|
|
324
|
+
/** Undefined deletes; nested patches retain sibling fields and an existing empty style Map. */
|
|
325
|
+
function mergeFields(target, patch) {
|
|
326
|
+
const result = { ...target };
|
|
327
|
+
for (const [key, value] of Object.entries(patch)) {
|
|
328
|
+
if (reservedIds.includes(key)) throw new Error(`Reserved field: ${key}`);
|
|
329
|
+
if (value === void 0) delete result[key];
|
|
330
|
+
else result[key] = isRecord(value) ? mergeFields(isRecord(result[key]) ? result[key] : {}, value) : value;
|
|
331
|
+
}
|
|
332
|
+
return result;
|
|
333
|
+
}
|
|
334
|
+
//#endregion
|
|
4
335
|
//#region ../medeo-dsl/src/text.ts
|
|
5
336
|
function assertTextOffset(text, at) {
|
|
6
337
|
if (!Number.isSafeInteger(at) || at < 0 || at > text.length) throw new Error("Invalid UTF-16 text offset");
|
|
@@ -943,7 +1274,1544 @@ function replaceSourcePlan(s, clipId, input) {
|
|
|
943
1274
|
}
|
|
944
1275
|
}];
|
|
945
1276
|
}
|
|
946
|
-
|
|
1277
|
+
//#endregion
|
|
1278
|
+
//#region ../../node_modules/.pnpm/loro-mirror@2.3.3_patch_hash=a551a0e4aa4f61ec88b0d9e970a183b5ee2955107a2e0bb03b378bc510c2f395_loro-crdt@1.16.1/node_modules/loro-mirror/dist/schema/resolver.js
|
|
1279
|
+
function getMapFieldSchema(schema, key) {
|
|
1280
|
+
if (!schema) return void 0;
|
|
1281
|
+
if (Object.prototype.hasOwnProperty.call(schema.definition, key)) return schema.definition[key];
|
|
1282
|
+
if (schema.type === "loro-map" && "catchallType" in schema) return schema.catchallType;
|
|
1283
|
+
}
|
|
1284
|
+
function getChildSchema(schema, childKey) {
|
|
1285
|
+
if (!schema) return void 0;
|
|
1286
|
+
switch (schema.type) {
|
|
1287
|
+
case "schema":
|
|
1288
|
+
case "loro-map": return childKey === void 0 ? void 0 : getMapFieldSchema(schema, String(childKey));
|
|
1289
|
+
case "loro-list":
|
|
1290
|
+
case "loro-movable-list": return schema.itemSchema;
|
|
1291
|
+
case "loro-tree": return schema.nodeSchema;
|
|
1292
|
+
default: return;
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
function getChildContainerSchema(schema, childKey) {
|
|
1296
|
+
const childSchema = getChildSchema(schema, childKey);
|
|
1297
|
+
if (!childSchema) return void 0;
|
|
1298
|
+
switch (childSchema.type) {
|
|
1299
|
+
case "loro-map":
|
|
1300
|
+
case "loro-list":
|
|
1301
|
+
case "loro-movable-list":
|
|
1302
|
+
case "loro-text":
|
|
1303
|
+
case "loro-tree": return childSchema;
|
|
1304
|
+
default: return;
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
//#endregion
|
|
1308
|
+
//#region ../../node_modules/.pnpm/loro-mirror@2.3.3_patch_hash=a551a0e4aa4f61ec88b0d9e970a183b5ee2955107a2e0bb03b378bc510c2f395_loro-crdt@1.16.1/node_modules/loro-mirror/dist/constants.js
|
|
1309
|
+
const CID_KEY = "$cid";
|
|
1310
|
+
//#endregion
|
|
1311
|
+
//#region ../../node_modules/.pnpm/loro-mirror@2.3.3_patch_hash=a551a0e4aa4f61ec88b0d9e970a183b5ee2955107a2e0bb03b378bc510c2f395_loro-crdt@1.16.1/node_modules/loro-mirror/dist/core/container-inference.js
|
|
1312
|
+
function isPlainObjectValue(value) {
|
|
1313
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) && !(value instanceof Date) && !(value instanceof RegExp) && typeof value !== "function";
|
|
1314
|
+
}
|
|
1315
|
+
function inferContainerTypeFromValue$1(value, defaults) {
|
|
1316
|
+
switch (getContainerValueKind(value)) {
|
|
1317
|
+
case "map": return "Map";
|
|
1318
|
+
case "array": return defaults?.defaultMovableList ? "MovableList" : "List";
|
|
1319
|
+
case "string": return defaults?.defaultLoroText ? "Text" : void 0;
|
|
1320
|
+
default: return;
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
function inferSchemaContainerTypeFromValue(value, defaults) {
|
|
1324
|
+
switch (inferContainerTypeFromValue$1(value, defaults)) {
|
|
1325
|
+
case "Map": return "loro-map";
|
|
1326
|
+
case "List": return "loro-list";
|
|
1327
|
+
case "MovableList": return "loro-movable-list";
|
|
1328
|
+
case "Text": return "loro-text";
|
|
1329
|
+
default: return;
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
function matchesContainerType(containerType, value) {
|
|
1333
|
+
const kind = getContainerValueKind(value);
|
|
1334
|
+
switch (containerType) {
|
|
1335
|
+
case "Map": return kind === "map";
|
|
1336
|
+
case "List":
|
|
1337
|
+
case "MovableList":
|
|
1338
|
+
case "Tree": return kind === "array";
|
|
1339
|
+
case "Text": return kind === "string";
|
|
1340
|
+
default: return false;
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
function getContainerValueKind(value) {
|
|
1344
|
+
if (isPlainObjectValue(value)) return "map";
|
|
1345
|
+
if (Array.isArray(value)) return "array";
|
|
1346
|
+
if (typeof value === "string") return "string";
|
|
1347
|
+
return "other";
|
|
1348
|
+
}
|
|
1349
|
+
//#endregion
|
|
1350
|
+
//#region ../../node_modules/.pnpm/loro-mirror@2.3.3_patch_hash=a551a0e4aa4f61ec88b0d9e970a183b5ee2955107a2e0bb03b378bc510c2f395_loro-crdt@1.16.1/node_modules/loro-mirror/dist/core/utils.js
|
|
1351
|
+
/**
|
|
1352
|
+
* Utility functions for Loro Mirror core
|
|
1353
|
+
*/
|
|
1354
|
+
/**
|
|
1355
|
+
* Check if a schema has a transform.
|
|
1356
|
+
* Distinguishes between the .transform() builder method (function) and an actual
|
|
1357
|
+
* TransformDefinition object (with decode/encode functions).
|
|
1358
|
+
*/
|
|
1359
|
+
function hasTransform(schema) {
|
|
1360
|
+
if (schema === void 0) return false;
|
|
1361
|
+
const t = schema.transform;
|
|
1362
|
+
return t != null && typeof t === "object";
|
|
1363
|
+
}
|
|
1364
|
+
/**
|
|
1365
|
+
* Get the transform from a schema, or undefined if none exists.
|
|
1366
|
+
*/
|
|
1367
|
+
function getTransform(schema) {
|
|
1368
|
+
if (hasTransform(schema)) return schema.transform;
|
|
1369
|
+
}
|
|
1370
|
+
/**
|
|
1371
|
+
* Get the effective equality strategy for a transform.
|
|
1372
|
+
* Default: "reference-equality"
|
|
1373
|
+
*/
|
|
1374
|
+
function getEqualityStrategy(schema, strategyIfNotTransformable) {
|
|
1375
|
+
const transform = getTransform(schema);
|
|
1376
|
+
if (!transform) return strategyIfNotTransformable;
|
|
1377
|
+
return transform.isEqual ?? "reference-equality";
|
|
1378
|
+
}
|
|
1379
|
+
/**
|
|
1380
|
+
* Apply decode transform to a CRDT value.
|
|
1381
|
+
* Null/undefined pass through as-is - transform is only called for real values.
|
|
1382
|
+
*/
|
|
1383
|
+
function applyDecode(schema, crdtValue) {
|
|
1384
|
+
if (crdtValue === null || crdtValue === void 0) return crdtValue;
|
|
1385
|
+
const transform = getTransform(schema);
|
|
1386
|
+
return transform ? transform.decode(crdtValue) : crdtValue;
|
|
1387
|
+
}
|
|
1388
|
+
/**
|
|
1389
|
+
* Recursively decode JSON values using schema transforms.
|
|
1390
|
+
* Mutates in-place. Used for snapshot initialization where toJSON() skips decode.
|
|
1391
|
+
*/
|
|
1392
|
+
function decodeNestedJsonValues(json, schema) {
|
|
1393
|
+
if (json === null || json === void 0 || !schema) return json;
|
|
1394
|
+
switch (schema.type) {
|
|
1395
|
+
case "loro-map":
|
|
1396
|
+
if (!isObject(json)) return json;
|
|
1397
|
+
for (const key of Object.keys(json)) {
|
|
1398
|
+
const fieldSchema = getChildSchema(schema, key);
|
|
1399
|
+
json[key] = decodeNestedJsonValues(json[key], fieldSchema);
|
|
1400
|
+
}
|
|
1401
|
+
return json;
|
|
1402
|
+
case "loro-list":
|
|
1403
|
+
case "loro-movable-list": {
|
|
1404
|
+
if (!Array.isArray(json)) return json;
|
|
1405
|
+
const itemSchema = getChildSchema(schema);
|
|
1406
|
+
for (let i = 0; i < json.length; i++) json[i] = decodeNestedJsonValues(json[i], itemSchema);
|
|
1407
|
+
return json;
|
|
1408
|
+
}
|
|
1409
|
+
case "loro-tree": {
|
|
1410
|
+
if (!Array.isArray(json)) return json;
|
|
1411
|
+
const nodeSchema = getChildSchema(schema);
|
|
1412
|
+
const walk = (nodes) => {
|
|
1413
|
+
for (const node of nodes) if (node != null && typeof node == "object") {
|
|
1414
|
+
if ("data" in node && node.data !== void 0) node.data = decodeNestedJsonValues(node.data, nodeSchema);
|
|
1415
|
+
if ("children" in node && Array.isArray(node.children)) walk(node.children);
|
|
1416
|
+
}
|
|
1417
|
+
};
|
|
1418
|
+
walk(json);
|
|
1419
|
+
return json;
|
|
1420
|
+
}
|
|
1421
|
+
case "loro-text":
|
|
1422
|
+
case "ignore": return json;
|
|
1423
|
+
default: return applyDecode(schema, json);
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
/**
|
|
1427
|
+
* Apply encode transform to a domain value.
|
|
1428
|
+
* Null/undefined pass through as-is - transform is only called for real values.
|
|
1429
|
+
*/
|
|
1430
|
+
function applyEncode(schema, domainValue) {
|
|
1431
|
+
if (domainValue === null || domainValue === void 0) return domainValue;
|
|
1432
|
+
const transform = getTransform(schema);
|
|
1433
|
+
return transform ? transform.encode(domainValue) : domainValue;
|
|
1434
|
+
}
|
|
1435
|
+
/**
|
|
1436
|
+
* Check if two domain values are equal according to the schema's equality strategy.
|
|
1437
|
+
*
|
|
1438
|
+
* Reference equality is always checked first (performance optimization).
|
|
1439
|
+
* If refs match, returns true (no change).
|
|
1440
|
+
* If refs differ, behavior depends on isEqual setting.
|
|
1441
|
+
*/
|
|
1442
|
+
function valuesEqual(schema, oldValue, newValue, strategyIfNotTransformable) {
|
|
1443
|
+
if (oldValue === newValue) return true;
|
|
1444
|
+
const strategy = getEqualityStrategy(schema, strategyIfNotTransformable);
|
|
1445
|
+
if (strategy === "reference-equality") return false;
|
|
1446
|
+
else if (strategy === "encoded-value-equality") return applyEncode(schema, oldValue) === applyEncode(schema, newValue);
|
|
1447
|
+
else if (strategy === "deep-equality") return deepEqual(oldValue, newValue);
|
|
1448
|
+
else return strategy(oldValue, newValue);
|
|
1449
|
+
}
|
|
1450
|
+
function defineCidProperty(target, cid) {
|
|
1451
|
+
if (!isObject(target) || Object.prototype.hasOwnProperty.call(target, "$cid")) return;
|
|
1452
|
+
Object.defineProperty(target, CID_KEY, { value: cid });
|
|
1453
|
+
}
|
|
1454
|
+
/**
|
|
1455
|
+
* Restore the read-only `$cid` contract on a freshly produced state.
|
|
1456
|
+
*
|
|
1457
|
+
* `defineCidProperty` stamps `$cid` as `{ writable: false, enumerable: false,
|
|
1458
|
+
* configurable: false }`. Immer's `useStrictShallowCopy` preserves the descriptor, but it
|
|
1459
|
+
* deliberately rewrites every non-writable data property to `{ writable: true,
|
|
1460
|
+
* configurable: true }` so the draft stays mutable — which would leave `$cid` writable on
|
|
1461
|
+
* every object Immer copied, letting callers reassign a published `$cid`.
|
|
1462
|
+
*
|
|
1463
|
+
* Two things keep this proportional to what Immer actually copied rather than to the size
|
|
1464
|
+
* of the state:
|
|
1465
|
+
*
|
|
1466
|
+
* - `prev` is the state `produce` was called with, and Immer shares everything it did not
|
|
1467
|
+
* copy, so a subtree reference-equal to `prev` cannot have been touched.
|
|
1468
|
+
* - An already-locked `$cid` means this object was not copied this round, so its children
|
|
1469
|
+
* are the same references they were when it was last hardened and are locked too. This
|
|
1470
|
+
* is what makes a reorder cheap: moved items are shared references that land at a new
|
|
1471
|
+
* index, so `prev` no longer lines up with them, but they are still locked.
|
|
1472
|
+
*/
|
|
1473
|
+
function hardenCidDescriptors(next, prev, visited) {
|
|
1474
|
+
if (next === prev) return;
|
|
1475
|
+
if (Array.isArray(next)) {
|
|
1476
|
+
if ((visited ?? (visited = /* @__PURE__ */ new Set())).has(next)) return;
|
|
1477
|
+
visited.add(next);
|
|
1478
|
+
const prevArr = Array.isArray(prev) ? prev : void 0;
|
|
1479
|
+
for (let i = 0; i < next.length; i++) hardenCidDescriptors(next[i], prevArr?.[i], visited);
|
|
1480
|
+
return;
|
|
1481
|
+
}
|
|
1482
|
+
if (!isObject(next)) return;
|
|
1483
|
+
const descriptor = Object.getOwnPropertyDescriptor(next, CID_KEY);
|
|
1484
|
+
if (descriptor) {
|
|
1485
|
+
if (!descriptor.configurable) return;
|
|
1486
|
+
if ("value" in descriptor) Object.defineProperty(next, CID_KEY, {
|
|
1487
|
+
value: descriptor.value,
|
|
1488
|
+
writable: false,
|
|
1489
|
+
enumerable: false,
|
|
1490
|
+
configurable: false
|
|
1491
|
+
});
|
|
1492
|
+
}
|
|
1493
|
+
if ((visited ?? (visited = /* @__PURE__ */ new Set())).has(next)) return;
|
|
1494
|
+
visited.add(next);
|
|
1495
|
+
const prevObj = isObject(prev) ? prev : void 0;
|
|
1496
|
+
for (const key of Object.keys(next)) hardenCidDescriptors(next[key], prevObj?.[key], visited);
|
|
1497
|
+
}
|
|
1498
|
+
/**
|
|
1499
|
+
* Check if a value is an object
|
|
1500
|
+
*/
|
|
1501
|
+
function isObject(value) {
|
|
1502
|
+
return isPlainObjectValue(value);
|
|
1503
|
+
}
|
|
1504
|
+
const UNSAFE_KEYS = new Set([
|
|
1505
|
+
"__proto__",
|
|
1506
|
+
"constructor",
|
|
1507
|
+
"prototype"
|
|
1508
|
+
]);
|
|
1509
|
+
/**
|
|
1510
|
+
* Recursively removes undefined values from an object.
|
|
1511
|
+
* This treats undefined values as non-existent fields.
|
|
1512
|
+
* Preserves non-enumerable properties like $cid.
|
|
1513
|
+
* Returns the original object if no undefined values are found.
|
|
1514
|
+
* Protects against prototype pollution by skipping unsafe keys.
|
|
1515
|
+
*/
|
|
1516
|
+
function stripUndefined(value) {
|
|
1517
|
+
return stripUndefinedInner(value, 0, void 0);
|
|
1518
|
+
}
|
|
1519
|
+
/**
|
|
1520
|
+
* Depth at which we start recording the recursion path to detect cycles.
|
|
1521
|
+
*
|
|
1522
|
+
* This runs over the whole state on every `setState`, and tracking every node costs more
|
|
1523
|
+
* than the stripping itself. Mirror state is a tree whose depth follows the schema, so a
|
|
1524
|
+
* real state never gets near this; only a cycle recurses without bound. Once the path is
|
|
1525
|
+
* being recorded, any cycle revisits one of its own nodes within a single lap, so starting
|
|
1526
|
+
* late still terminates.
|
|
1527
|
+
*/
|
|
1528
|
+
const CYCLE_GUARD_DEPTH = 64;
|
|
1529
|
+
/**
|
|
1530
|
+
* Placeholder for a key that must not reach the rebuilt object: an unsafe key, or one whose
|
|
1531
|
+
* value is `undefined` and is therefore treated as a non-existent field.
|
|
1532
|
+
*/
|
|
1533
|
+
const DROPPED = Symbol("dropped");
|
|
1534
|
+
function stripUndefinedInner(value, depth, path) {
|
|
1535
|
+
if (value === void 0) return value;
|
|
1536
|
+
if (Array.isArray(value)) {
|
|
1537
|
+
if (depth >= CYCLE_GUARD_DEPTH) {
|
|
1538
|
+
if ((path ?? (path = /* @__PURE__ */ new Set())).has(value)) return value;
|
|
1539
|
+
path.add(value);
|
|
1540
|
+
}
|
|
1541
|
+
let hasChanges = false;
|
|
1542
|
+
const result = value.map((item) => {
|
|
1543
|
+
const stripped = stripUndefinedInner(item, depth + 1, path);
|
|
1544
|
+
if (stripped !== item) hasChanges = true;
|
|
1545
|
+
return stripped;
|
|
1546
|
+
});
|
|
1547
|
+
path?.delete(value);
|
|
1548
|
+
return hasChanges ? result : value;
|
|
1549
|
+
}
|
|
1550
|
+
if (isObject(value)) {
|
|
1551
|
+
if (depth >= CYCLE_GUARD_DEPTH) {
|
|
1552
|
+
if ((path ?? (path = /* @__PURE__ */ new Set())).has(value)) return value;
|
|
1553
|
+
path.add(value);
|
|
1554
|
+
}
|
|
1555
|
+
const keys = Object.keys(value);
|
|
1556
|
+
const strippedValues = Array.from({ length: keys.length });
|
|
1557
|
+
let changed = false;
|
|
1558
|
+
for (let i = 0; i < keys.length; i++) {
|
|
1559
|
+
const key = keys[i];
|
|
1560
|
+
if (UNSAFE_KEYS.has(key)) {
|
|
1561
|
+
strippedValues[i] = DROPPED;
|
|
1562
|
+
continue;
|
|
1563
|
+
}
|
|
1564
|
+
const val = value[key];
|
|
1565
|
+
if (val === void 0) {
|
|
1566
|
+
strippedValues[i] = DROPPED;
|
|
1567
|
+
changed = true;
|
|
1568
|
+
continue;
|
|
1569
|
+
}
|
|
1570
|
+
const stripped = stripUndefinedInner(val, depth + 1, path);
|
|
1571
|
+
strippedValues[i] = stripped;
|
|
1572
|
+
if (stripped !== val) changed = true;
|
|
1573
|
+
}
|
|
1574
|
+
path?.delete(value);
|
|
1575
|
+
if (!changed) return value;
|
|
1576
|
+
const result = Object.create(null);
|
|
1577
|
+
const allProps = Object.getOwnPropertyNames(value);
|
|
1578
|
+
for (const key of allProps) {
|
|
1579
|
+
if (UNSAFE_KEYS.has(key)) continue;
|
|
1580
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
1581
|
+
if (descriptor && !descriptor.enumerable) Object.defineProperty(result, key, descriptor);
|
|
1582
|
+
}
|
|
1583
|
+
for (let i = 0; i < keys.length; i++) {
|
|
1584
|
+
const val = strippedValues[i];
|
|
1585
|
+
if (val === DROPPED) continue;
|
|
1586
|
+
Object.defineProperty(result, keys[i], {
|
|
1587
|
+
value: val,
|
|
1588
|
+
writable: true,
|
|
1589
|
+
enumerable: true,
|
|
1590
|
+
configurable: true
|
|
1591
|
+
});
|
|
1592
|
+
}
|
|
1593
|
+
return result;
|
|
1594
|
+
}
|
|
1595
|
+
return value;
|
|
1596
|
+
}
|
|
1597
|
+
/**
|
|
1598
|
+
* Performs a deep equality check between two values
|
|
1599
|
+
*/
|
|
1600
|
+
function deepEqual(a, b) {
|
|
1601
|
+
if (a === b) return true;
|
|
1602
|
+
if (a === null || b === null || typeof a !== "object" && typeof a !== "function" || typeof b !== "object" && typeof b !== "function") return false;
|
|
1603
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
1604
|
+
if (a.length !== b.length) return false;
|
|
1605
|
+
for (let i = 0; i < a.length; i++) if (!deepEqual(a[i], b[i])) return false;
|
|
1606
|
+
return true;
|
|
1607
|
+
}
|
|
1608
|
+
if (a instanceof Date && b instanceof Date) return a.getTime() === b.getTime();
|
|
1609
|
+
if (a instanceof RegExp && b instanceof RegExp) return a.toString() === b.toString();
|
|
1610
|
+
if (!Array.isArray(a) && !Array.isArray(b)) {
|
|
1611
|
+
const keysA = Object.keys(a);
|
|
1612
|
+
const keysB = Object.keys(b);
|
|
1613
|
+
if (keysA.length !== keysB.length) return false;
|
|
1614
|
+
for (const key of keysA) {
|
|
1615
|
+
if (!Object.prototype.hasOwnProperty.call(b, key)) return false;
|
|
1616
|
+
if (!deepEqual(a[key], b[key])) return false;
|
|
1617
|
+
}
|
|
1618
|
+
return true;
|
|
1619
|
+
}
|
|
1620
|
+
return false;
|
|
1621
|
+
}
|
|
1622
|
+
/**
|
|
1623
|
+
* Recursively compare the `$cid` markers of two state trees.
|
|
1624
|
+
*
|
|
1625
|
+
* `deepEqual` only walks enumerable keys, so it cannot see `$cid` (which is stamped as a
|
|
1626
|
+
* non-enumerable descriptor). Used by `Mirror.checkStateConsistency` so that a tampered
|
|
1627
|
+
* or stale `$cid` is reported as a divergence instead of silently sitting in the state.
|
|
1628
|
+
* Only the markers are compared here; value equality is `deepEqual`'s job.
|
|
1629
|
+
*/
|
|
1630
|
+
function cidsEqual(a, b, seen) {
|
|
1631
|
+
if (a === b) return true;
|
|
1632
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
1633
|
+
if (a.length !== b.length) return false;
|
|
1634
|
+
if (markSeen(a, b, seen ?? (seen = /* @__PURE__ */ new Map())) === "seen") return true;
|
|
1635
|
+
for (let i = 0; i < a.length; i++) if (!cidsEqual(a[i], b[i], seen)) return false;
|
|
1636
|
+
return true;
|
|
1637
|
+
}
|
|
1638
|
+
if (!isObject(a) || !isObject(b)) return true;
|
|
1639
|
+
if (a["$cid"] !== b["$cid"]) return false;
|
|
1640
|
+
if (markSeen(a, b, seen ?? (seen = /* @__PURE__ */ new Map())) === "seen") return true;
|
|
1641
|
+
for (const key of Object.keys(a)) {
|
|
1642
|
+
if (!Object.prototype.hasOwnProperty.call(b, key)) continue;
|
|
1643
|
+
if (!cidsEqual(a[key], b[key], seen)) return false;
|
|
1644
|
+
}
|
|
1645
|
+
return true;
|
|
1646
|
+
}
|
|
1647
|
+
function markSeen(a, b, seen) {
|
|
1648
|
+
let partners = seen.get(a);
|
|
1649
|
+
if (!partners) {
|
|
1650
|
+
partners = /* @__PURE__ */ new Set();
|
|
1651
|
+
seen.set(a, partners);
|
|
1652
|
+
}
|
|
1653
|
+
if (partners.has(b)) return "seen";
|
|
1654
|
+
partners.add(b);
|
|
1655
|
+
return "new";
|
|
1656
|
+
}
|
|
1657
|
+
function containerIdToContainerType(containerId) {
|
|
1658
|
+
const parts = containerId.split(":");
|
|
1659
|
+
return parts[parts.length - 1];
|
|
1660
|
+
}
|
|
1661
|
+
function getRootContainerByType(doc, key, type) {
|
|
1662
|
+
if (type === "Text") return doc.getText(key);
|
|
1663
|
+
else if (type === "List") return doc.getList(key);
|
|
1664
|
+
else if (type === "MovableList") return doc.getMovableList(key);
|
|
1665
|
+
else if (type === "Map") return doc.getMap(key);
|
|
1666
|
+
else if (type === "Tree") return doc.getTree(key);
|
|
1667
|
+
else throw new Error();
|
|
1668
|
+
}
|
|
1669
|
+
function insertChildToMap(containerId, key, value, inferOptions) {
|
|
1670
|
+
const ct = tryInferContainerType(value, inferOptions);
|
|
1671
|
+
if (ct) return {
|
|
1672
|
+
container: containerId,
|
|
1673
|
+
key,
|
|
1674
|
+
value,
|
|
1675
|
+
kind: "insert-container",
|
|
1676
|
+
childContainerType: ct
|
|
1677
|
+
};
|
|
1678
|
+
return {
|
|
1679
|
+
container: containerId,
|
|
1680
|
+
key,
|
|
1681
|
+
value,
|
|
1682
|
+
kind: "insert"
|
|
1683
|
+
};
|
|
1684
|
+
}
|
|
1685
|
+
function tryUpdateToContainer(change, toUpdate, schema, inferOptions) {
|
|
1686
|
+
if (!toUpdate) return change;
|
|
1687
|
+
if (change.kind !== "insert" && change.kind !== "set") return change;
|
|
1688
|
+
const effectiveInferOptions = applySchemaToInferOptions(schema, inferOptions);
|
|
1689
|
+
const containerType = schema ? schemaToContainerType(schema) ?? tryInferContainerType(change.value, effectiveInferOptions) : tryInferContainerType(change.value, effectiveInferOptions);
|
|
1690
|
+
if (containerType == null || schema && hasTransform(schema)) {
|
|
1691
|
+
const encodedValue = applyEncode(schema, change.value);
|
|
1692
|
+
return encodedValue !== change.value ? {
|
|
1693
|
+
...change,
|
|
1694
|
+
value: encodedValue
|
|
1695
|
+
} : change;
|
|
1696
|
+
}
|
|
1697
|
+
if (change.kind === "insert") return {
|
|
1698
|
+
container: change.container,
|
|
1699
|
+
key: change.key,
|
|
1700
|
+
value: change.value,
|
|
1701
|
+
kind: "insert-container",
|
|
1702
|
+
childContainerType: containerType
|
|
1703
|
+
};
|
|
1704
|
+
if (change.kind === "set") return {
|
|
1705
|
+
container: change.container,
|
|
1706
|
+
key: change.key,
|
|
1707
|
+
value: change.value,
|
|
1708
|
+
kind: "set-container",
|
|
1709
|
+
childContainerType: containerType
|
|
1710
|
+
};
|
|
1711
|
+
return change;
|
|
1712
|
+
}
|
|
1713
|
+
function schemaToContainerType(schema) {
|
|
1714
|
+
const containerType = schema.getContainerType();
|
|
1715
|
+
return containerType === null ? void 0 : containerType;
|
|
1716
|
+
}
|
|
1717
|
+
function tryInferContainerType(value, defaults) {
|
|
1718
|
+
return inferContainerTypeFromValue$1(value, defaults);
|
|
1719
|
+
}
|
|
1720
|
+
function applySchemaToInferOptions(schema, base) {
|
|
1721
|
+
if (!schema || schema.type !== "any") return base;
|
|
1722
|
+
const next = { ...base };
|
|
1723
|
+
next.defaultLoroText = schema.options.defaultLoroText ?? false;
|
|
1724
|
+
if (schema.options.defaultMovableList !== void 0) next.defaultMovableList = schema.options.defaultMovableList;
|
|
1725
|
+
return next;
|
|
1726
|
+
}
|
|
1727
|
+
function isValueOfContainerType(containerType, value) {
|
|
1728
|
+
return matchesContainerType(containerType, value);
|
|
1729
|
+
}
|
|
1730
|
+
function inferContainerTypeFromValue(value, defaults) {
|
|
1731
|
+
return inferSchemaContainerTypeFromValue(value, defaults);
|
|
1732
|
+
}
|
|
1733
|
+
function isObjectLike(value) {
|
|
1734
|
+
return typeof value === "object";
|
|
1735
|
+
}
|
|
1736
|
+
function isArrayLike(value) {
|
|
1737
|
+
return Array.isArray(value);
|
|
1738
|
+
}
|
|
1739
|
+
function isStateAndSchemaOfType(values, stateGuard, schemaGuard) {
|
|
1740
|
+
return stateGuard(values.oldState) && stateGuard(values.newState) && (!values.schema || schemaGuard(values.schema));
|
|
1741
|
+
}
|
|
1742
|
+
function isTreeID(id) {
|
|
1743
|
+
if (!(typeof id === "string")) return false;
|
|
1744
|
+
return !!id.match(/[0-9]+@[0-9]+/);
|
|
1745
|
+
}
|
|
1746
|
+
/**
|
|
1747
|
+
* Stringify a value safely, handling non-JSON-serializable types.
|
|
1748
|
+
* Handles BigInt, Date, RegExp, functions, and custom objects.
|
|
1749
|
+
*/
|
|
1750
|
+
function safeStringify(value, indent = 2) {
|
|
1751
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
1752
|
+
function replacer(val) {
|
|
1753
|
+
if (val === null || val === void 0) return val;
|
|
1754
|
+
if (typeof val === "string" || typeof val === "number" || typeof val === "boolean") return val;
|
|
1755
|
+
if (typeof val === "bigint") return `[BigInt: ${val.toString()}]`;
|
|
1756
|
+
if (typeof val === "function") return `[Function: ${val.name || "anonymous"}]`;
|
|
1757
|
+
if (typeof val === "symbol") return `[Symbol: ${val.description || ""}]`;
|
|
1758
|
+
if (typeof val === "object") {
|
|
1759
|
+
if (seen.has(val)) return "[Circular]";
|
|
1760
|
+
seen.add(val);
|
|
1761
|
+
if (val instanceof Date) return `[Date: ${val.toISOString()}]`;
|
|
1762
|
+
if (val instanceof RegExp) return `[RegExp: ${val.toString()}]`;
|
|
1763
|
+
if (val instanceof Error) return `[Error: ${val.message}]`;
|
|
1764
|
+
if (Array.isArray(val)) return val.map(replacer);
|
|
1765
|
+
const result = {};
|
|
1766
|
+
for (const key of Object.keys(val)) result[key] = replacer(val[key]);
|
|
1767
|
+
return result;
|
|
1768
|
+
}
|
|
1769
|
+
return Object.prototype.toString.call(val);
|
|
1770
|
+
}
|
|
1771
|
+
return JSON.stringify(replacer(value), null, indent);
|
|
1772
|
+
}
|
|
1773
|
+
//#endregion
|
|
1774
|
+
//#region ../../node_modules/.pnpm/loro-mirror@2.3.3_patch_hash=a551a0e4aa4f61ec88b0d9e970a183b5ee2955107a2e0bb03b378bc510c2f395_loro-crdt@1.16.1/node_modules/loro-mirror/dist/schema/validators.js
|
|
1775
|
+
const schemaValidationCache = /* @__PURE__ */ new WeakMap();
|
|
1776
|
+
function isCacheableValue(value) {
|
|
1777
|
+
return typeof value === "object" && value !== null;
|
|
1778
|
+
}
|
|
1779
|
+
function isSchemaValidated(schema, value) {
|
|
1780
|
+
if (!isCacheableValue(value)) return false;
|
|
1781
|
+
return schemaValidationCache.get(value)?.has(schema) ?? false;
|
|
1782
|
+
}
|
|
1783
|
+
function markSchemaValidated(schema, value) {
|
|
1784
|
+
if (!isCacheableValue(value)) return;
|
|
1785
|
+
let cache = schemaValidationCache.get(value);
|
|
1786
|
+
if (!cache) {
|
|
1787
|
+
cache = /* @__PURE__ */ new WeakSet();
|
|
1788
|
+
schemaValidationCache.set(value, cache);
|
|
1789
|
+
}
|
|
1790
|
+
cache.add(schema);
|
|
1791
|
+
}
|
|
1792
|
+
/**
|
|
1793
|
+
* Type guard for LoroMapSchema
|
|
1794
|
+
*/
|
|
1795
|
+
function isLoroMapSchema(schema) {
|
|
1796
|
+
return !!schema && schema.type === "loro-map";
|
|
1797
|
+
}
|
|
1798
|
+
/**
|
|
1799
|
+
* Type guard for LoroListSchema
|
|
1800
|
+
*/
|
|
1801
|
+
function isLoroListSchema(schema) {
|
|
1802
|
+
return !!schema && schema.type === "loro-list";
|
|
1803
|
+
}
|
|
1804
|
+
function isListLikeSchema(schema) {
|
|
1805
|
+
return isLoroListSchema(schema) || isLoroMovableListSchema(schema);
|
|
1806
|
+
}
|
|
1807
|
+
function isLoroMovableListSchema(schema) {
|
|
1808
|
+
return !!schema && schema.type === "loro-movable-list";
|
|
1809
|
+
}
|
|
1810
|
+
/**
|
|
1811
|
+
* Type guard for RootSchemaType
|
|
1812
|
+
*/
|
|
1813
|
+
function isRootSchemaType(schema) {
|
|
1814
|
+
return !!schema && schema.type === "schema";
|
|
1815
|
+
}
|
|
1816
|
+
/**
|
|
1817
|
+
* Whether a schema subtree contains any `Ignore` field. Recursive schemas are
|
|
1818
|
+
* tolerated (each schema object is visited once).
|
|
1819
|
+
*/
|
|
1820
|
+
function schemaContainsIgnoreField(schema) {
|
|
1821
|
+
const visited = /* @__PURE__ */ new Set();
|
|
1822
|
+
const walk = (s) => {
|
|
1823
|
+
if (!s || visited.has(s)) return false;
|
|
1824
|
+
visited.add(s);
|
|
1825
|
+
if (s.type === "ignore") return true;
|
|
1826
|
+
switch (s.type) {
|
|
1827
|
+
case "schema":
|
|
1828
|
+
case "loro-map": {
|
|
1829
|
+
const record = s;
|
|
1830
|
+
return Object.values(record.definition).some(walk) || walk(record.catchallType);
|
|
1831
|
+
}
|
|
1832
|
+
case "loro-list":
|
|
1833
|
+
case "loro-movable-list": return walk(s.itemSchema);
|
|
1834
|
+
case "loro-tree": return walk(s.nodeSchema);
|
|
1835
|
+
default: return false;
|
|
1836
|
+
}
|
|
1837
|
+
};
|
|
1838
|
+
return walk(schema);
|
|
1839
|
+
}
|
|
1840
|
+
/**
|
|
1841
|
+
* Type guard for LoroTreeSchema
|
|
1842
|
+
*/
|
|
1843
|
+
function isLoroTreeSchema(schema) {
|
|
1844
|
+
return !!schema && schema.type === "loro-tree";
|
|
1845
|
+
}
|
|
1846
|
+
/**
|
|
1847
|
+
* Check if a schema is for a Loro container
|
|
1848
|
+
*/
|
|
1849
|
+
function isContainerSchema(schema) {
|
|
1850
|
+
return !!schema && (schema.type === "loro-map" || schema.type === "loro-list" || schema.type === "loro-text" || schema.type === "loro-movable-list" || schema.type === "loro-tree");
|
|
1851
|
+
}
|
|
1852
|
+
/**
|
|
1853
|
+
* Validate a value against a schema
|
|
1854
|
+
*
|
|
1855
|
+
* When `options.ignoreUnknownProperties` is true, the root schema check does
|
|
1856
|
+
* not reject properties missing from the schema definition — typically
|
|
1857
|
+
* written by peers on a newer schema version. (Nested map schemas never
|
|
1858
|
+
* reject undeclared properties.)
|
|
1859
|
+
*/
|
|
1860
|
+
function validateSchema(schema, value, options) {
|
|
1861
|
+
const errors = [];
|
|
1862
|
+
const actualType = schema.type;
|
|
1863
|
+
if (schema.options.required && (value === void 0 || value === null)) {
|
|
1864
|
+
errors.push("Value is required");
|
|
1865
|
+
return {
|
|
1866
|
+
valid: false,
|
|
1867
|
+
errors
|
|
1868
|
+
};
|
|
1869
|
+
}
|
|
1870
|
+
if (value === void 0 || value === null) return { valid: true };
|
|
1871
|
+
const useCache = !options?.ignoreUnknownProperties;
|
|
1872
|
+
if (useCache && isSchemaValidated(schema, value)) return { valid: true };
|
|
1873
|
+
switch (actualType) {
|
|
1874
|
+
case "any":
|
|
1875
|
+
if (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean" && value !== null && value !== void 0 && !Array.isArray(value) && !isObject(value)) errors.push("Value must be JSON-like");
|
|
1876
|
+
break;
|
|
1877
|
+
case "string":
|
|
1878
|
+
case "number":
|
|
1879
|
+
case "boolean":
|
|
1880
|
+
validateTransformablePrimitive(schema, value, actualType, errors);
|
|
1881
|
+
break;
|
|
1882
|
+
case "ignore": break;
|
|
1883
|
+
case "loro-text":
|
|
1884
|
+
if (typeof value !== "string") errors.push("Content must be a string");
|
|
1885
|
+
break;
|
|
1886
|
+
case "loro-map":
|
|
1887
|
+
if (!isObject(value)) errors.push("Value must be an object");
|
|
1888
|
+
else if (isLoroMapSchema(schema)) {
|
|
1889
|
+
for (const key in schema.definition) if (Object.prototype.hasOwnProperty.call(schema.definition, key)) {
|
|
1890
|
+
const propSchema = schema.definition[key];
|
|
1891
|
+
const propValue = value[key];
|
|
1892
|
+
const result = validateSchema(propSchema, propValue);
|
|
1893
|
+
if (!result.valid && result.errors) {
|
|
1894
|
+
const prefixedErrors = result.errors.map((err) => `${key}: ${err}`);
|
|
1895
|
+
errors.push(...prefixedErrors);
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1898
|
+
}
|
|
1899
|
+
break;
|
|
1900
|
+
case "loro-movable-list":
|
|
1901
|
+
case "loro-list":
|
|
1902
|
+
if (!Array.isArray(value)) errors.push("Value must be an array");
|
|
1903
|
+
else if (isLoroListSchema(schema) || isLoroMovableListSchema(schema)) {
|
|
1904
|
+
const itemSchema = schema.itemSchema;
|
|
1905
|
+
value.forEach((item, index) => {
|
|
1906
|
+
const result = validateSchema(itemSchema, item);
|
|
1907
|
+
if (!result.valid && result.errors) {
|
|
1908
|
+
const prefixedErrors = result.errors.map((err) => `Item ${index}: ${err}`);
|
|
1909
|
+
errors.push(...prefixedErrors);
|
|
1910
|
+
}
|
|
1911
|
+
});
|
|
1912
|
+
}
|
|
1913
|
+
break;
|
|
1914
|
+
case "loro-tree": {
|
|
1915
|
+
if (!Array.isArray(value)) {
|
|
1916
|
+
errors.push("Value must be an array of tree nodes");
|
|
1917
|
+
break;
|
|
1918
|
+
}
|
|
1919
|
+
if (!isLoroTreeSchema(schema)) {
|
|
1920
|
+
errors.push("Invalid tree schema");
|
|
1921
|
+
break;
|
|
1922
|
+
}
|
|
1923
|
+
const validateNode = (node, path) => {
|
|
1924
|
+
if (!isObject(node)) {
|
|
1925
|
+
errors.push(`${path}: Node must be an object`);
|
|
1926
|
+
return;
|
|
1927
|
+
}
|
|
1928
|
+
const n = node;
|
|
1929
|
+
if (n.id != null && typeof n.id !== "string") errors.push(`${path}: id must be a string if provided`);
|
|
1930
|
+
const dataResult = validateSchema(schema.nodeSchema, n.data);
|
|
1931
|
+
if (!dataResult.valid && dataResult.errors) errors.push(...dataResult.errors.map((e) => `${path}.data: ${e}`));
|
|
1932
|
+
if (!Array.isArray(n.children)) errors.push(`${path}: children must be an array`);
|
|
1933
|
+
else n.children.forEach((child, idx) => {
|
|
1934
|
+
validateNode(child, `${path}.children[${idx}]`);
|
|
1935
|
+
});
|
|
1936
|
+
};
|
|
1937
|
+
value.forEach((node, i) => {
|
|
1938
|
+
validateNode(node, `node[${i}]`);
|
|
1939
|
+
});
|
|
1940
|
+
break;
|
|
1941
|
+
}
|
|
1942
|
+
case "schema":
|
|
1943
|
+
if (!isObject(value)) errors.push("Value must be an object");
|
|
1944
|
+
else if (isRootSchemaType(schema)) if (!isObject(value)) errors.push("Value must be an object");
|
|
1945
|
+
else {
|
|
1946
|
+
for (const key in schema.definition) if (Object.prototype.hasOwnProperty.call(schema.definition, key)) {
|
|
1947
|
+
const propSchema = schema.definition[key];
|
|
1948
|
+
const propValue = value[key];
|
|
1949
|
+
const result = validateSchema(propSchema, propValue);
|
|
1950
|
+
if (!result.valid && result.errors) {
|
|
1951
|
+
const prefixedErrors = result.errors.map((err) => `${key}: ${err}`);
|
|
1952
|
+
errors.push(...prefixedErrors);
|
|
1953
|
+
}
|
|
1954
|
+
}
|
|
1955
|
+
for (const key in value) if (!Object.prototype.hasOwnProperty.call(schema.definition, key)) {
|
|
1956
|
+
if (options?.ignoreUnknownProperties) continue;
|
|
1957
|
+
errors.push(`Unknown property: ${key}`);
|
|
1958
|
+
}
|
|
1959
|
+
}
|
|
1960
|
+
else errors.push(`Should be a schema, but got ${actualType}`);
|
|
1961
|
+
break;
|
|
1962
|
+
default: errors.push(`Unknown schema type: ${actualType}`);
|
|
1963
|
+
}
|
|
1964
|
+
if (schema.options.validate && typeof schema.options.validate === "function") try {
|
|
1965
|
+
const customValidation = schema.options.validate(value);
|
|
1966
|
+
if (customValidation !== true) {
|
|
1967
|
+
const errorMessage = typeof customValidation === "string" ? customValidation : "Value failed custom validation";
|
|
1968
|
+
errors.push(errorMessage);
|
|
1969
|
+
}
|
|
1970
|
+
} catch (error) {
|
|
1971
|
+
errors.push(`Validation error: ${String(error)}`);
|
|
1972
|
+
}
|
|
1973
|
+
if (errors.length === 0) {
|
|
1974
|
+
if (useCache) markSchemaValidated(schema, value);
|
|
1975
|
+
return { valid: true };
|
|
1976
|
+
}
|
|
1977
|
+
return {
|
|
1978
|
+
valid: false,
|
|
1979
|
+
errors
|
|
1980
|
+
};
|
|
1981
|
+
}
|
|
1982
|
+
function validateTransformablePrimitive(schema, value, expectedType, errors) {
|
|
1983
|
+
const transform = getTransform(schema);
|
|
1984
|
+
if (transform) {
|
|
1985
|
+
if (transform.validate) try {
|
|
1986
|
+
const result = transform.validate(value);
|
|
1987
|
+
if (result !== true) errors.push(typeof result === "string" ? result : "Transform validation failed");
|
|
1988
|
+
} catch (error) {
|
|
1989
|
+
errors.push(`Transform validation error: ${String(error)}`);
|
|
1990
|
+
}
|
|
1991
|
+
if (transform.validateEncodedType) try {
|
|
1992
|
+
const encoded = applyEncode(schema, value);
|
|
1993
|
+
if (typeof encoded !== expectedType) errors.push(`Transform encode must return a ${expectedType}, got ${typeof encoded}`);
|
|
1994
|
+
} catch (error) {
|
|
1995
|
+
errors.push(`Transform encode validation error: ${String(error)}`);
|
|
1996
|
+
}
|
|
1997
|
+
} else if (typeof value !== expectedType) errors.push(`Value must be a ${expectedType}`);
|
|
1998
|
+
}
|
|
1999
|
+
/**
|
|
2000
|
+
* Get default value for a schema
|
|
2001
|
+
* Based on the schema type, it might return a plain value or a wrapped value
|
|
2002
|
+
*/
|
|
2003
|
+
function getDefaultValue(schema) {
|
|
2004
|
+
if ("defaultValue" in schema.options) return schema.options.defaultValue;
|
|
2005
|
+
switch (schema.type) {
|
|
2006
|
+
case "any": return;
|
|
2007
|
+
case "string":
|
|
2008
|
+
if (schema.options.required === false) return;
|
|
2009
|
+
if (getTransform(schema)) return;
|
|
2010
|
+
return "";
|
|
2011
|
+
case "number":
|
|
2012
|
+
if (schema.options.required === false) return;
|
|
2013
|
+
if (getTransform(schema)) return;
|
|
2014
|
+
return 0;
|
|
2015
|
+
case "boolean":
|
|
2016
|
+
if (schema.options.required === false) return;
|
|
2017
|
+
if (getTransform(schema)) return;
|
|
2018
|
+
return false;
|
|
2019
|
+
case "loro-text": {
|
|
2020
|
+
const value = schema.options.required ? "" : void 0;
|
|
2021
|
+
if (value === void 0) return void 0;
|
|
2022
|
+
return value;
|
|
2023
|
+
}
|
|
2024
|
+
case "loro-map":
|
|
2025
|
+
if (isLoroMapSchema(schema)) {
|
|
2026
|
+
const result = {};
|
|
2027
|
+
for (const key in schema.definition) if (Object.prototype.hasOwnProperty.call(schema.definition, key)) {
|
|
2028
|
+
const value = getDefaultValue(schema.definition[key]);
|
|
2029
|
+
if (value !== void 0) result[key] = value;
|
|
2030
|
+
}
|
|
2031
|
+
return result;
|
|
2032
|
+
}
|
|
2033
|
+
return {};
|
|
2034
|
+
case "loro-list": return [];
|
|
2035
|
+
case "loro-tree": {
|
|
2036
|
+
const value = schema.options.required ? [] : void 0;
|
|
2037
|
+
if (value === void 0) return void 0;
|
|
2038
|
+
return value;
|
|
2039
|
+
}
|
|
2040
|
+
case "schema":
|
|
2041
|
+
if (isRootSchemaType(schema)) {
|
|
2042
|
+
const result = {};
|
|
2043
|
+
for (const key in schema.definition) if (Object.prototype.hasOwnProperty.call(schema.definition, key)) {
|
|
2044
|
+
const value = getDefaultValue(schema.definition[key]);
|
|
2045
|
+
if (value !== void 0) result[key] = value;
|
|
2046
|
+
}
|
|
2047
|
+
return result;
|
|
2048
|
+
}
|
|
2049
|
+
return {};
|
|
2050
|
+
default: return;
|
|
2051
|
+
}
|
|
2052
|
+
}
|
|
2053
|
+
//#endregion
|
|
2054
|
+
//#region ../../node_modules/.pnpm/loro-mirror@2.3.3_patch_hash=a551a0e4aa4f61ec88b0d9e970a183b5ee2955107a2e0bb03b378bc510c2f395_loro-crdt@1.16.1/node_modules/loro-mirror/dist/schema/index.js
|
|
2055
|
+
/**
|
|
2056
|
+
* Create a schema definition
|
|
2057
|
+
*/
|
|
2058
|
+
function schema(definition, options) {
|
|
2059
|
+
return {
|
|
2060
|
+
type: "schema",
|
|
2061
|
+
definition,
|
|
2062
|
+
options: options || {},
|
|
2063
|
+
getContainerType() {
|
|
2064
|
+
return "Map";
|
|
2065
|
+
}
|
|
2066
|
+
};
|
|
2067
|
+
}
|
|
2068
|
+
/**
|
|
2069
|
+
* Define a string field
|
|
2070
|
+
*/
|
|
2071
|
+
schema.String = (function(options) {
|
|
2072
|
+
const baseSchema = {
|
|
2073
|
+
type: "string",
|
|
2074
|
+
options: options || {},
|
|
2075
|
+
getContainerType: () => {
|
|
2076
|
+
return null;
|
|
2077
|
+
}
|
|
2078
|
+
};
|
|
2079
|
+
return {
|
|
2080
|
+
...baseSchema,
|
|
2081
|
+
transform: (def) => ({
|
|
2082
|
+
...baseSchema,
|
|
2083
|
+
transform: def
|
|
2084
|
+
})
|
|
2085
|
+
};
|
|
2086
|
+
});
|
|
2087
|
+
/**
|
|
2088
|
+
* Define an any field (runtime-inferred by Mirror)
|
|
2089
|
+
*/
|
|
2090
|
+
schema.Any = function(options) {
|
|
2091
|
+
return {
|
|
2092
|
+
type: "any",
|
|
2093
|
+
options: options || {},
|
|
2094
|
+
getContainerType: () => {
|
|
2095
|
+
return null;
|
|
2096
|
+
}
|
|
2097
|
+
};
|
|
2098
|
+
};
|
|
2099
|
+
/**
|
|
2100
|
+
* Define a number field
|
|
2101
|
+
*/
|
|
2102
|
+
schema.Number = function(options) {
|
|
2103
|
+
const baseSchema = {
|
|
2104
|
+
type: "number",
|
|
2105
|
+
options: options || {},
|
|
2106
|
+
getContainerType: () => {
|
|
2107
|
+
return null;
|
|
2108
|
+
}
|
|
2109
|
+
};
|
|
2110
|
+
return {
|
|
2111
|
+
...baseSchema,
|
|
2112
|
+
transform: (def) => ({
|
|
2113
|
+
...baseSchema,
|
|
2114
|
+
transform: def
|
|
2115
|
+
})
|
|
2116
|
+
};
|
|
2117
|
+
};
|
|
2118
|
+
/**
|
|
2119
|
+
* Define a boolean field
|
|
2120
|
+
*/
|
|
2121
|
+
schema.Boolean = function(options) {
|
|
2122
|
+
const baseSchema = {
|
|
2123
|
+
type: "boolean",
|
|
2124
|
+
options: options || {},
|
|
2125
|
+
getContainerType: () => {
|
|
2126
|
+
return null;
|
|
2127
|
+
}
|
|
2128
|
+
};
|
|
2129
|
+
return {
|
|
2130
|
+
...baseSchema,
|
|
2131
|
+
transform: (def) => ({
|
|
2132
|
+
...baseSchema,
|
|
2133
|
+
transform: def
|
|
2134
|
+
})
|
|
2135
|
+
};
|
|
2136
|
+
};
|
|
2137
|
+
/**
|
|
2138
|
+
* Define a field to be ignored (not synced with Loro)
|
|
2139
|
+
*/
|
|
2140
|
+
schema.Ignore = function(options) {
|
|
2141
|
+
return {
|
|
2142
|
+
type: "ignore",
|
|
2143
|
+
options: options || {},
|
|
2144
|
+
getContainerType: () => {
|
|
2145
|
+
return null;
|
|
2146
|
+
}
|
|
2147
|
+
};
|
|
2148
|
+
};
|
|
2149
|
+
/**
|
|
2150
|
+
* Define a Loro map
|
|
2151
|
+
*/
|
|
2152
|
+
schema.LoroMap = function(definition, options) {
|
|
2153
|
+
const baseSchema = {
|
|
2154
|
+
type: "loro-map",
|
|
2155
|
+
definition,
|
|
2156
|
+
options: options || {},
|
|
2157
|
+
getContainerType: () => {
|
|
2158
|
+
return "Map";
|
|
2159
|
+
}
|
|
2160
|
+
};
|
|
2161
|
+
const schemaWithCatchall = {
|
|
2162
|
+
...baseSchema,
|
|
2163
|
+
catchall: (catchallSchema) => {
|
|
2164
|
+
return {
|
|
2165
|
+
...baseSchema,
|
|
2166
|
+
catchallType: catchallSchema,
|
|
2167
|
+
catchall: (newCatchallSchema) => {
|
|
2168
|
+
return {
|
|
2169
|
+
...baseSchema,
|
|
2170
|
+
catchallType: newCatchallSchema,
|
|
2171
|
+
catchall: schemaWithCatchall.catchall
|
|
2172
|
+
};
|
|
2173
|
+
}
|
|
2174
|
+
};
|
|
2175
|
+
}
|
|
2176
|
+
};
|
|
2177
|
+
return schemaWithCatchall;
|
|
2178
|
+
};
|
|
2179
|
+
/**
|
|
2180
|
+
* Create a dynamic record schema (like zod's z.record)
|
|
2181
|
+
*/
|
|
2182
|
+
schema.LoroMapRecord = function(valueSchema, options) {
|
|
2183
|
+
return {
|
|
2184
|
+
type: "loro-map",
|
|
2185
|
+
definition: {},
|
|
2186
|
+
catchallType: valueSchema,
|
|
2187
|
+
options: options || {},
|
|
2188
|
+
getContainerType: () => {
|
|
2189
|
+
return "Map";
|
|
2190
|
+
},
|
|
2191
|
+
catchall: (newCatchallSchema) => {
|
|
2192
|
+
return schema.LoroMapRecord(newCatchallSchema, options);
|
|
2193
|
+
}
|
|
2194
|
+
};
|
|
2195
|
+
};
|
|
2196
|
+
/**
|
|
2197
|
+
* Define a Loro list
|
|
2198
|
+
*/
|
|
2199
|
+
schema.LoroList = function(itemSchema, idSelector, options) {
|
|
2200
|
+
return {
|
|
2201
|
+
type: "loro-list",
|
|
2202
|
+
itemSchema,
|
|
2203
|
+
idSelector,
|
|
2204
|
+
options: options || {},
|
|
2205
|
+
getContainerType: () => {
|
|
2206
|
+
return "List";
|
|
2207
|
+
}
|
|
2208
|
+
};
|
|
2209
|
+
};
|
|
2210
|
+
schema.LoroMovableList = function(itemSchema, idSelector, options) {
|
|
2211
|
+
return {
|
|
2212
|
+
type: "loro-movable-list",
|
|
2213
|
+
itemSchema,
|
|
2214
|
+
idSelector,
|
|
2215
|
+
options: options || {},
|
|
2216
|
+
getContainerType: () => {
|
|
2217
|
+
return "MovableList";
|
|
2218
|
+
}
|
|
2219
|
+
};
|
|
2220
|
+
};
|
|
2221
|
+
/**
|
|
2222
|
+
* Define a Loro text field
|
|
2223
|
+
*/
|
|
2224
|
+
schema.LoroText = function(options) {
|
|
2225
|
+
return {
|
|
2226
|
+
type: "loro-text",
|
|
2227
|
+
options: options || {},
|
|
2228
|
+
getContainerType: () => {
|
|
2229
|
+
return "Text";
|
|
2230
|
+
}
|
|
2231
|
+
};
|
|
2232
|
+
};
|
|
2233
|
+
/**
|
|
2234
|
+
* Define a Loro tree
|
|
2235
|
+
*
|
|
2236
|
+
* Each tree node has a `data` map described by `nodeSchema`.
|
|
2237
|
+
*/
|
|
2238
|
+
schema.LoroTree = function(nodeSchema, options) {
|
|
2239
|
+
return {
|
|
2240
|
+
type: "loro-tree",
|
|
2241
|
+
nodeSchema,
|
|
2242
|
+
options: options || {},
|
|
2243
|
+
getContainerType() {
|
|
2244
|
+
return "Tree";
|
|
2245
|
+
}
|
|
2246
|
+
};
|
|
2247
|
+
};
|
|
2248
|
+
//#endregion
|
|
2249
|
+
//#region ../../node_modules/.pnpm/immer@10.2.0/node_modules/immer/dist/immer.mjs
|
|
2250
|
+
var NOTHING = Symbol.for("immer-nothing");
|
|
2251
|
+
var DRAFTABLE = Symbol.for("immer-draftable");
|
|
2252
|
+
var DRAFT_STATE = Symbol.for("immer-state");
|
|
2253
|
+
var errors = [
|
|
2254
|
+
function(plugin) {
|
|
2255
|
+
return `The plugin for '${plugin}' has not been loaded into Immer. To enable the plugin, import and call \`enable${plugin}()\` when initializing your application.`;
|
|
2256
|
+
},
|
|
2257
|
+
function(thing) {
|
|
2258
|
+
return `produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${thing}'`;
|
|
2259
|
+
},
|
|
2260
|
+
"This object has been frozen and should not be mutated",
|
|
2261
|
+
function(data) {
|
|
2262
|
+
return "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " + data;
|
|
2263
|
+
},
|
|
2264
|
+
"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.",
|
|
2265
|
+
"Immer forbids circular references",
|
|
2266
|
+
"The first or second argument to `produce` must be a function",
|
|
2267
|
+
"The third argument to `produce` must be a function or undefined",
|
|
2268
|
+
"First argument to `createDraft` must be a plain object, an array, or an immerable object",
|
|
2269
|
+
"First argument to `finishDraft` must be a draft returned by `createDraft`",
|
|
2270
|
+
function(thing) {
|
|
2271
|
+
return `'current' expects a draft, got: ${thing}`;
|
|
2272
|
+
},
|
|
2273
|
+
"Object.defineProperty() cannot be used on an Immer draft",
|
|
2274
|
+
"Object.setPrototypeOf() cannot be used on an Immer draft",
|
|
2275
|
+
"Immer only supports deleting array indices",
|
|
2276
|
+
"Immer only supports setting array indices and the 'length' property",
|
|
2277
|
+
function(thing) {
|
|
2278
|
+
return `'original' expects a draft, got: ${thing}`;
|
|
2279
|
+
}
|
|
2280
|
+
];
|
|
2281
|
+
function die(error, ...args) {
|
|
2282
|
+
{
|
|
2283
|
+
const e = errors[error];
|
|
2284
|
+
const msg = typeof e === "function" ? e.apply(null, args) : e;
|
|
2285
|
+
throw new Error(`[Immer] ${msg}`);
|
|
2286
|
+
}
|
|
2287
|
+
throw new Error(`[Immer] minified error nr: ${error}. Full error at: https://bit.ly/3cXEKWf`);
|
|
2288
|
+
}
|
|
2289
|
+
var getPrototypeOf = Object.getPrototypeOf;
|
|
2290
|
+
function isDraft(value) {
|
|
2291
|
+
return !!value && !!value[DRAFT_STATE];
|
|
2292
|
+
}
|
|
2293
|
+
function isDraftable(value) {
|
|
2294
|
+
if (!value) return false;
|
|
2295
|
+
return isPlainObject(value) || Array.isArray(value) || !!value[DRAFTABLE] || !!value.constructor?.[DRAFTABLE] || isMap(value) || isSet(value);
|
|
2296
|
+
}
|
|
2297
|
+
var objectCtorString = Object.prototype.constructor.toString();
|
|
2298
|
+
var cachedCtorStrings = /* @__PURE__ */ new WeakMap();
|
|
2299
|
+
function isPlainObject(value) {
|
|
2300
|
+
if (!value || typeof value !== "object") return false;
|
|
2301
|
+
const proto = Object.getPrototypeOf(value);
|
|
2302
|
+
if (proto === null || proto === Object.prototype) return true;
|
|
2303
|
+
const Ctor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor;
|
|
2304
|
+
if (Ctor === Object) return true;
|
|
2305
|
+
if (typeof Ctor !== "function") return false;
|
|
2306
|
+
let ctorString = cachedCtorStrings.get(Ctor);
|
|
2307
|
+
if (ctorString === void 0) {
|
|
2308
|
+
ctorString = Function.toString.call(Ctor);
|
|
2309
|
+
cachedCtorStrings.set(Ctor, ctorString);
|
|
2310
|
+
}
|
|
2311
|
+
return ctorString === objectCtorString;
|
|
2312
|
+
}
|
|
2313
|
+
function each(obj, iter, strict = true) {
|
|
2314
|
+
if (getArchtype(obj) === 0) (strict ? Reflect.ownKeys(obj) : Object.keys(obj)).forEach((key) => {
|
|
2315
|
+
iter(key, obj[key], obj);
|
|
2316
|
+
});
|
|
2317
|
+
else obj.forEach((entry, index) => iter(index, entry, obj));
|
|
2318
|
+
}
|
|
2319
|
+
function getArchtype(thing) {
|
|
2320
|
+
const state = thing[DRAFT_STATE];
|
|
2321
|
+
return state ? state.type_ : Array.isArray(thing) ? 1 : isMap(thing) ? 2 : isSet(thing) ? 3 : 0;
|
|
2322
|
+
}
|
|
2323
|
+
function has(thing, prop) {
|
|
2324
|
+
return getArchtype(thing) === 2 ? thing.has(prop) : Object.prototype.hasOwnProperty.call(thing, prop);
|
|
2325
|
+
}
|
|
2326
|
+
function set(thing, propOrOldValue, value) {
|
|
2327
|
+
const t = getArchtype(thing);
|
|
2328
|
+
if (t === 2) thing.set(propOrOldValue, value);
|
|
2329
|
+
else if (t === 3) thing.add(value);
|
|
2330
|
+
else thing[propOrOldValue] = value;
|
|
2331
|
+
}
|
|
2332
|
+
function is(x, y) {
|
|
2333
|
+
if (x === y) return x !== 0 || 1 / x === 1 / y;
|
|
2334
|
+
else return x !== x && y !== y;
|
|
2335
|
+
}
|
|
2336
|
+
function isMap(target) {
|
|
2337
|
+
return target instanceof Map;
|
|
2338
|
+
}
|
|
2339
|
+
function isSet(target) {
|
|
2340
|
+
return target instanceof Set;
|
|
2341
|
+
}
|
|
2342
|
+
function latest(state) {
|
|
2343
|
+
return state.copy_ || state.base_;
|
|
2344
|
+
}
|
|
2345
|
+
function shallowCopy(base, strict) {
|
|
2346
|
+
if (isMap(base)) return new Map(base);
|
|
2347
|
+
if (isSet(base)) return new Set(base);
|
|
2348
|
+
if (Array.isArray(base)) return Array.prototype.slice.call(base);
|
|
2349
|
+
const isPlain = isPlainObject(base);
|
|
2350
|
+
if (strict === true || strict === "class_only" && !isPlain) {
|
|
2351
|
+
const descriptors = Object.getOwnPropertyDescriptors(base);
|
|
2352
|
+
delete descriptors[DRAFT_STATE];
|
|
2353
|
+
let keys = Reflect.ownKeys(descriptors);
|
|
2354
|
+
for (let i = 0; i < keys.length; i++) {
|
|
2355
|
+
const key = keys[i];
|
|
2356
|
+
const desc = descriptors[key];
|
|
2357
|
+
if (desc.writable === false) {
|
|
2358
|
+
desc.writable = true;
|
|
2359
|
+
desc.configurable = true;
|
|
2360
|
+
}
|
|
2361
|
+
if (desc.get || desc.set) descriptors[key] = {
|
|
2362
|
+
configurable: true,
|
|
2363
|
+
writable: true,
|
|
2364
|
+
enumerable: desc.enumerable,
|
|
2365
|
+
value: base[key]
|
|
2366
|
+
};
|
|
2367
|
+
}
|
|
2368
|
+
return Object.create(getPrototypeOf(base), descriptors);
|
|
2369
|
+
} else {
|
|
2370
|
+
const proto = getPrototypeOf(base);
|
|
2371
|
+
if (proto !== null && isPlain) return { ...base };
|
|
2372
|
+
return Object.assign(Object.create(proto), base);
|
|
2373
|
+
}
|
|
2374
|
+
}
|
|
2375
|
+
function freeze(obj, deep = false) {
|
|
2376
|
+
if (isFrozen(obj) || isDraft(obj) || !isDraftable(obj)) return obj;
|
|
2377
|
+
if (getArchtype(obj) > 1) Object.defineProperties(obj, {
|
|
2378
|
+
set: dontMutateMethodOverride,
|
|
2379
|
+
add: dontMutateMethodOverride,
|
|
2380
|
+
clear: dontMutateMethodOverride,
|
|
2381
|
+
delete: dontMutateMethodOverride
|
|
2382
|
+
});
|
|
2383
|
+
Object.freeze(obj);
|
|
2384
|
+
if (deep) Object.values(obj).forEach((value) => freeze(value, true));
|
|
2385
|
+
return obj;
|
|
2386
|
+
}
|
|
2387
|
+
function dontMutateFrozenCollections() {
|
|
2388
|
+
die(2);
|
|
2389
|
+
}
|
|
2390
|
+
var dontMutateMethodOverride = { value: dontMutateFrozenCollections };
|
|
2391
|
+
function isFrozen(obj) {
|
|
2392
|
+
if (obj === null || typeof obj !== "object") return true;
|
|
2393
|
+
return Object.isFrozen(obj);
|
|
2394
|
+
}
|
|
2395
|
+
var plugins = {};
|
|
2396
|
+
function getPlugin(pluginKey) {
|
|
2397
|
+
const plugin = plugins[pluginKey];
|
|
2398
|
+
if (!plugin) die(0, pluginKey);
|
|
2399
|
+
return plugin;
|
|
2400
|
+
}
|
|
2401
|
+
var currentScope;
|
|
2402
|
+
function getCurrentScope() {
|
|
2403
|
+
return currentScope;
|
|
2404
|
+
}
|
|
2405
|
+
function createScope(parent_, immer_) {
|
|
2406
|
+
return {
|
|
2407
|
+
drafts_: [],
|
|
2408
|
+
parent_,
|
|
2409
|
+
immer_,
|
|
2410
|
+
canAutoFreeze_: true,
|
|
2411
|
+
unfinalizedDrafts_: 0
|
|
2412
|
+
};
|
|
2413
|
+
}
|
|
2414
|
+
function usePatchesInScope(scope, patchListener) {
|
|
2415
|
+
if (patchListener) {
|
|
2416
|
+
getPlugin("Patches");
|
|
2417
|
+
scope.patches_ = [];
|
|
2418
|
+
scope.inversePatches_ = [];
|
|
2419
|
+
scope.patchListener_ = patchListener;
|
|
2420
|
+
}
|
|
2421
|
+
}
|
|
2422
|
+
function revokeScope(scope) {
|
|
2423
|
+
leaveScope(scope);
|
|
2424
|
+
scope.drafts_.forEach(revokeDraft);
|
|
2425
|
+
scope.drafts_ = null;
|
|
2426
|
+
}
|
|
2427
|
+
function leaveScope(scope) {
|
|
2428
|
+
if (scope === currentScope) currentScope = scope.parent_;
|
|
2429
|
+
}
|
|
2430
|
+
function enterScope(immer2) {
|
|
2431
|
+
return currentScope = createScope(currentScope, immer2);
|
|
2432
|
+
}
|
|
2433
|
+
function revokeDraft(draft) {
|
|
2434
|
+
const state = draft[DRAFT_STATE];
|
|
2435
|
+
if (state.type_ === 0 || state.type_ === 1) state.revoke_();
|
|
2436
|
+
else state.revoked_ = true;
|
|
2437
|
+
}
|
|
2438
|
+
function processResult(result, scope) {
|
|
2439
|
+
scope.unfinalizedDrafts_ = scope.drafts_.length;
|
|
2440
|
+
const baseDraft = scope.drafts_[0];
|
|
2441
|
+
if (result !== void 0 && result !== baseDraft) {
|
|
2442
|
+
if (baseDraft[DRAFT_STATE].modified_) {
|
|
2443
|
+
revokeScope(scope);
|
|
2444
|
+
die(4);
|
|
2445
|
+
}
|
|
2446
|
+
if (isDraftable(result)) {
|
|
2447
|
+
result = finalize(scope, result);
|
|
2448
|
+
if (!scope.parent_) maybeFreeze(scope, result);
|
|
2449
|
+
}
|
|
2450
|
+
if (scope.patches_) getPlugin("Patches").generateReplacementPatches_(baseDraft[DRAFT_STATE].base_, result, scope.patches_, scope.inversePatches_);
|
|
2451
|
+
} else result = finalize(scope, baseDraft, []);
|
|
2452
|
+
revokeScope(scope);
|
|
2453
|
+
if (scope.patches_) scope.patchListener_(scope.patches_, scope.inversePatches_);
|
|
2454
|
+
return result !== NOTHING ? result : void 0;
|
|
2455
|
+
}
|
|
2456
|
+
function finalize(rootScope, value, path) {
|
|
2457
|
+
if (isFrozen(value)) return value;
|
|
2458
|
+
const useStrictIteration = rootScope.immer_.shouldUseStrictIteration();
|
|
2459
|
+
const state = value[DRAFT_STATE];
|
|
2460
|
+
if (!state) {
|
|
2461
|
+
each(value, (key, childValue) => finalizeProperty(rootScope, state, value, key, childValue, path), useStrictIteration);
|
|
2462
|
+
return value;
|
|
2463
|
+
}
|
|
2464
|
+
if (state.scope_ !== rootScope) return value;
|
|
2465
|
+
if (!state.modified_) {
|
|
2466
|
+
maybeFreeze(rootScope, state.base_, true);
|
|
2467
|
+
return state.base_;
|
|
2468
|
+
}
|
|
2469
|
+
if (!state.finalized_) {
|
|
2470
|
+
state.finalized_ = true;
|
|
2471
|
+
state.scope_.unfinalizedDrafts_--;
|
|
2472
|
+
const result = state.copy_;
|
|
2473
|
+
let resultEach = result;
|
|
2474
|
+
let isSet2 = false;
|
|
2475
|
+
if (state.type_ === 3) {
|
|
2476
|
+
resultEach = new Set(result);
|
|
2477
|
+
result.clear();
|
|
2478
|
+
isSet2 = true;
|
|
2479
|
+
}
|
|
2480
|
+
each(resultEach, (key, childValue) => finalizeProperty(rootScope, state, result, key, childValue, path, isSet2), useStrictIteration);
|
|
2481
|
+
maybeFreeze(rootScope, result, false);
|
|
2482
|
+
if (path && rootScope.patches_) getPlugin("Patches").generatePatches_(state, path, rootScope.patches_, rootScope.inversePatches_);
|
|
2483
|
+
}
|
|
2484
|
+
return state.copy_;
|
|
2485
|
+
}
|
|
2486
|
+
function finalizeProperty(rootScope, parentState, targetObject, prop, childValue, rootPath, targetIsSet) {
|
|
2487
|
+
if (childValue == null) return;
|
|
2488
|
+
if (typeof childValue !== "object" && !targetIsSet) return;
|
|
2489
|
+
const childIsFrozen = isFrozen(childValue);
|
|
2490
|
+
if (childIsFrozen && !targetIsSet) return;
|
|
2491
|
+
if (childValue === targetObject) die(5);
|
|
2492
|
+
if (isDraft(childValue)) {
|
|
2493
|
+
const res = finalize(rootScope, childValue, rootPath && parentState && parentState.type_ !== 3 && !has(parentState.assigned_, prop) ? rootPath.concat(prop) : void 0);
|
|
2494
|
+
set(targetObject, prop, res);
|
|
2495
|
+
if (isDraft(res)) rootScope.canAutoFreeze_ = false;
|
|
2496
|
+
else return;
|
|
2497
|
+
} else if (targetIsSet) targetObject.add(childValue);
|
|
2498
|
+
if (isDraftable(childValue) && !childIsFrozen) {
|
|
2499
|
+
if (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) return;
|
|
2500
|
+
if (parentState && parentState.base_ && parentState.base_[prop] === childValue && childIsFrozen) return;
|
|
2501
|
+
finalize(rootScope, childValue);
|
|
2502
|
+
if ((!parentState || !parentState.scope_.parent_) && typeof prop !== "symbol" && (isMap(targetObject) ? targetObject.has(prop) : Object.prototype.propertyIsEnumerable.call(targetObject, prop))) maybeFreeze(rootScope, childValue);
|
|
2503
|
+
}
|
|
2504
|
+
}
|
|
2505
|
+
function maybeFreeze(scope, value, deep = false) {
|
|
2506
|
+
if (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) freeze(value, deep);
|
|
2507
|
+
}
|
|
2508
|
+
function createProxyProxy(base, parent) {
|
|
2509
|
+
const isArray = Array.isArray(base);
|
|
2510
|
+
const state = {
|
|
2511
|
+
type_: isArray ? 1 : 0,
|
|
2512
|
+
scope_: parent ? parent.scope_ : getCurrentScope(),
|
|
2513
|
+
modified_: false,
|
|
2514
|
+
finalized_: false,
|
|
2515
|
+
assigned_: {},
|
|
2516
|
+
parent_: parent,
|
|
2517
|
+
base_: base,
|
|
2518
|
+
draft_: null,
|
|
2519
|
+
copy_: null,
|
|
2520
|
+
revoke_: null,
|
|
2521
|
+
isManual_: false
|
|
2522
|
+
};
|
|
2523
|
+
let target = state;
|
|
2524
|
+
let traps = objectTraps;
|
|
2525
|
+
if (isArray) {
|
|
2526
|
+
target = [state];
|
|
2527
|
+
traps = arrayTraps;
|
|
2528
|
+
}
|
|
2529
|
+
const { revoke, proxy } = Proxy.revocable(target, traps);
|
|
2530
|
+
state.draft_ = proxy;
|
|
2531
|
+
state.revoke_ = revoke;
|
|
2532
|
+
return proxy;
|
|
2533
|
+
}
|
|
2534
|
+
var objectTraps = {
|
|
2535
|
+
get(state, prop) {
|
|
2536
|
+
if (prop === DRAFT_STATE) return state;
|
|
2537
|
+
const source = latest(state);
|
|
2538
|
+
if (!has(source, prop)) return readPropFromProto(state, source, prop);
|
|
2539
|
+
const value = source[prop];
|
|
2540
|
+
if (state.finalized_ || !isDraftable(value)) return value;
|
|
2541
|
+
if (value === peek(state.base_, prop)) {
|
|
2542
|
+
prepareCopy(state);
|
|
2543
|
+
return state.copy_[prop] = createProxy(value, state);
|
|
2544
|
+
}
|
|
2545
|
+
return value;
|
|
2546
|
+
},
|
|
2547
|
+
has(state, prop) {
|
|
2548
|
+
return prop in latest(state);
|
|
2549
|
+
},
|
|
2550
|
+
ownKeys(state) {
|
|
2551
|
+
return Reflect.ownKeys(latest(state));
|
|
2552
|
+
},
|
|
2553
|
+
set(state, prop, value) {
|
|
2554
|
+
const desc = getDescriptorFromProto(latest(state), prop);
|
|
2555
|
+
if (desc?.set) {
|
|
2556
|
+
desc.set.call(state.draft_, value);
|
|
2557
|
+
return true;
|
|
2558
|
+
}
|
|
2559
|
+
if (!state.modified_) {
|
|
2560
|
+
const current2 = peek(latest(state), prop);
|
|
2561
|
+
const currentState = current2?.[DRAFT_STATE];
|
|
2562
|
+
if (currentState && currentState.base_ === value) {
|
|
2563
|
+
state.copy_[prop] = value;
|
|
2564
|
+
state.assigned_[prop] = false;
|
|
2565
|
+
return true;
|
|
2566
|
+
}
|
|
2567
|
+
if (is(value, current2) && (value !== void 0 || has(state.base_, prop))) return true;
|
|
2568
|
+
prepareCopy(state);
|
|
2569
|
+
markChanged(state);
|
|
2570
|
+
}
|
|
2571
|
+
if (state.copy_[prop] === value && (value !== void 0 || prop in state.copy_) || Number.isNaN(value) && Number.isNaN(state.copy_[prop])) return true;
|
|
2572
|
+
state.copy_[prop] = value;
|
|
2573
|
+
state.assigned_[prop] = true;
|
|
2574
|
+
return true;
|
|
2575
|
+
},
|
|
2576
|
+
deleteProperty(state, prop) {
|
|
2577
|
+
if (peek(state.base_, prop) !== void 0 || prop in state.base_) {
|
|
2578
|
+
state.assigned_[prop] = false;
|
|
2579
|
+
prepareCopy(state);
|
|
2580
|
+
markChanged(state);
|
|
2581
|
+
} else delete state.assigned_[prop];
|
|
2582
|
+
if (state.copy_) delete state.copy_[prop];
|
|
2583
|
+
return true;
|
|
2584
|
+
},
|
|
2585
|
+
getOwnPropertyDescriptor(state, prop) {
|
|
2586
|
+
const owner = latest(state);
|
|
2587
|
+
const desc = Reflect.getOwnPropertyDescriptor(owner, prop);
|
|
2588
|
+
if (!desc) return desc;
|
|
2589
|
+
return {
|
|
2590
|
+
writable: true,
|
|
2591
|
+
configurable: state.type_ !== 1 || prop !== "length",
|
|
2592
|
+
enumerable: desc.enumerable,
|
|
2593
|
+
value: owner[prop]
|
|
2594
|
+
};
|
|
2595
|
+
},
|
|
2596
|
+
defineProperty() {
|
|
2597
|
+
die(11);
|
|
2598
|
+
},
|
|
2599
|
+
getPrototypeOf(state) {
|
|
2600
|
+
return getPrototypeOf(state.base_);
|
|
2601
|
+
},
|
|
2602
|
+
setPrototypeOf() {
|
|
2603
|
+
die(12);
|
|
2604
|
+
}
|
|
2605
|
+
};
|
|
2606
|
+
var arrayTraps = {};
|
|
2607
|
+
each(objectTraps, (key, fn) => {
|
|
2608
|
+
arrayTraps[key] = function() {
|
|
2609
|
+
arguments[0] = arguments[0][0];
|
|
2610
|
+
return fn.apply(this, arguments);
|
|
2611
|
+
};
|
|
2612
|
+
});
|
|
2613
|
+
arrayTraps.deleteProperty = function(state, prop) {
|
|
2614
|
+
if (isNaN(parseInt(prop))) die(13);
|
|
2615
|
+
return arrayTraps.set.call(this, state, prop, void 0);
|
|
2616
|
+
};
|
|
2617
|
+
arrayTraps.set = function(state, prop, value) {
|
|
2618
|
+
if (prop !== "length" && isNaN(parseInt(prop))) die(14);
|
|
2619
|
+
return objectTraps.set.call(this, state[0], prop, value, state[0]);
|
|
2620
|
+
};
|
|
2621
|
+
function peek(draft, prop) {
|
|
2622
|
+
const state = draft[DRAFT_STATE];
|
|
2623
|
+
return (state ? latest(state) : draft)[prop];
|
|
2624
|
+
}
|
|
2625
|
+
function readPropFromProto(state, source, prop) {
|
|
2626
|
+
const desc = getDescriptorFromProto(source, prop);
|
|
2627
|
+
return desc ? `value` in desc ? desc.value : desc.get?.call(state.draft_) : void 0;
|
|
2628
|
+
}
|
|
2629
|
+
function getDescriptorFromProto(source, prop) {
|
|
2630
|
+
if (!(prop in source)) return void 0;
|
|
2631
|
+
let proto = getPrototypeOf(source);
|
|
2632
|
+
while (proto) {
|
|
2633
|
+
const desc = Object.getOwnPropertyDescriptor(proto, prop);
|
|
2634
|
+
if (desc) return desc;
|
|
2635
|
+
proto = getPrototypeOf(proto);
|
|
2636
|
+
}
|
|
2637
|
+
}
|
|
2638
|
+
function markChanged(state) {
|
|
2639
|
+
if (!state.modified_) {
|
|
2640
|
+
state.modified_ = true;
|
|
2641
|
+
if (state.parent_) markChanged(state.parent_);
|
|
2642
|
+
}
|
|
2643
|
+
}
|
|
2644
|
+
function prepareCopy(state) {
|
|
2645
|
+
if (!state.copy_) state.copy_ = shallowCopy(state.base_, state.scope_.immer_.useStrictShallowCopy_);
|
|
2646
|
+
}
|
|
2647
|
+
var Immer2 = class {
|
|
2648
|
+
constructor(config) {
|
|
2649
|
+
this.autoFreeze_ = true;
|
|
2650
|
+
this.useStrictShallowCopy_ = false;
|
|
2651
|
+
this.useStrictIteration_ = true;
|
|
2652
|
+
/**
|
|
2653
|
+
* The `produce` function takes a value and a "recipe function" (whose
|
|
2654
|
+
* return value often depends on the base state). The recipe function is
|
|
2655
|
+
* free to mutate its first argument however it wants. All mutations are
|
|
2656
|
+
* only ever applied to a __copy__ of the base state.
|
|
2657
|
+
*
|
|
2658
|
+
* Pass only a function to create a "curried producer" which relieves you
|
|
2659
|
+
* from passing the recipe function every time.
|
|
2660
|
+
*
|
|
2661
|
+
* Only plain objects and arrays are made mutable. All other objects are
|
|
2662
|
+
* considered uncopyable.
|
|
2663
|
+
*
|
|
2664
|
+
* Note: This function is __bound__ to its `Immer` instance.
|
|
2665
|
+
*
|
|
2666
|
+
* @param {any} base - the initial state
|
|
2667
|
+
* @param {Function} recipe - function that receives a proxy of the base state as first argument and which can be freely modified
|
|
2668
|
+
* @param {Function} patchListener - optional function that will be called with all the patches produced here
|
|
2669
|
+
* @returns {any} a new state, or the initial state if nothing was modified
|
|
2670
|
+
*/
|
|
2671
|
+
this.produce = (base, recipe, patchListener) => {
|
|
2672
|
+
if (typeof base === "function" && typeof recipe !== "function") {
|
|
2673
|
+
const defaultBase = recipe;
|
|
2674
|
+
recipe = base;
|
|
2675
|
+
const self = this;
|
|
2676
|
+
return function curriedProduce(base2 = defaultBase, ...args) {
|
|
2677
|
+
return self.produce(base2, (draft) => recipe.call(this, draft, ...args));
|
|
2678
|
+
};
|
|
2679
|
+
}
|
|
2680
|
+
if (typeof recipe !== "function") die(6);
|
|
2681
|
+
if (patchListener !== void 0 && typeof patchListener !== "function") die(7);
|
|
2682
|
+
let result;
|
|
2683
|
+
if (isDraftable(base)) {
|
|
2684
|
+
const scope = enterScope(this);
|
|
2685
|
+
const proxy = createProxy(base, void 0);
|
|
2686
|
+
let hasError = true;
|
|
2687
|
+
try {
|
|
2688
|
+
result = recipe(proxy);
|
|
2689
|
+
hasError = false;
|
|
2690
|
+
} finally {
|
|
2691
|
+
if (hasError) revokeScope(scope);
|
|
2692
|
+
else leaveScope(scope);
|
|
2693
|
+
}
|
|
2694
|
+
usePatchesInScope(scope, patchListener);
|
|
2695
|
+
return processResult(result, scope);
|
|
2696
|
+
} else if (!base || typeof base !== "object") {
|
|
2697
|
+
result = recipe(base);
|
|
2698
|
+
if (result === void 0) result = base;
|
|
2699
|
+
if (result === NOTHING) result = void 0;
|
|
2700
|
+
if (this.autoFreeze_) freeze(result, true);
|
|
2701
|
+
if (patchListener) {
|
|
2702
|
+
const p = [];
|
|
2703
|
+
const ip = [];
|
|
2704
|
+
getPlugin("Patches").generateReplacementPatches_(base, result, p, ip);
|
|
2705
|
+
patchListener(p, ip);
|
|
2706
|
+
}
|
|
2707
|
+
return result;
|
|
2708
|
+
} else die(1, base);
|
|
2709
|
+
};
|
|
2710
|
+
this.produceWithPatches = (base, recipe) => {
|
|
2711
|
+
if (typeof base === "function") return (state, ...args) => this.produceWithPatches(state, (draft) => base(draft, ...args));
|
|
2712
|
+
let patches, inversePatches;
|
|
2713
|
+
return [
|
|
2714
|
+
this.produce(base, recipe, (p, ip) => {
|
|
2715
|
+
patches = p;
|
|
2716
|
+
inversePatches = ip;
|
|
2717
|
+
}),
|
|
2718
|
+
patches,
|
|
2719
|
+
inversePatches
|
|
2720
|
+
];
|
|
2721
|
+
};
|
|
2722
|
+
if (typeof config?.autoFreeze === "boolean") this.setAutoFreeze(config.autoFreeze);
|
|
2723
|
+
if (typeof config?.useStrictShallowCopy === "boolean") this.setUseStrictShallowCopy(config.useStrictShallowCopy);
|
|
2724
|
+
if (typeof config?.useStrictIteration === "boolean") this.setUseStrictIteration(config.useStrictIteration);
|
|
2725
|
+
}
|
|
2726
|
+
createDraft(base) {
|
|
2727
|
+
if (!isDraftable(base)) die(8);
|
|
2728
|
+
if (isDraft(base)) base = current(base);
|
|
2729
|
+
const scope = enterScope(this);
|
|
2730
|
+
const proxy = createProxy(base, void 0);
|
|
2731
|
+
proxy[DRAFT_STATE].isManual_ = true;
|
|
2732
|
+
leaveScope(scope);
|
|
2733
|
+
return proxy;
|
|
2734
|
+
}
|
|
2735
|
+
finishDraft(draft, patchListener) {
|
|
2736
|
+
const state = draft && draft[DRAFT_STATE];
|
|
2737
|
+
if (!state || !state.isManual_) die(9);
|
|
2738
|
+
const { scope_: scope } = state;
|
|
2739
|
+
usePatchesInScope(scope, patchListener);
|
|
2740
|
+
return processResult(void 0, scope);
|
|
2741
|
+
}
|
|
2742
|
+
/**
|
|
2743
|
+
* Pass true to automatically freeze all copies created by Immer.
|
|
2744
|
+
*
|
|
2745
|
+
* By default, auto-freezing is enabled.
|
|
2746
|
+
*/
|
|
2747
|
+
setAutoFreeze(value) {
|
|
2748
|
+
this.autoFreeze_ = value;
|
|
2749
|
+
}
|
|
2750
|
+
/**
|
|
2751
|
+
* Pass true to enable strict shallow copy.
|
|
2752
|
+
*
|
|
2753
|
+
* By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.
|
|
2754
|
+
*/
|
|
2755
|
+
setUseStrictShallowCopy(value) {
|
|
2756
|
+
this.useStrictShallowCopy_ = value;
|
|
2757
|
+
}
|
|
2758
|
+
/**
|
|
2759
|
+
* Pass false to use faster iteration that skips non-enumerable properties
|
|
2760
|
+
* but still handles symbols for compatibility.
|
|
2761
|
+
*
|
|
2762
|
+
* By default, strict iteration is enabled (includes all own properties).
|
|
2763
|
+
*/
|
|
2764
|
+
setUseStrictIteration(value) {
|
|
2765
|
+
this.useStrictIteration_ = value;
|
|
2766
|
+
}
|
|
2767
|
+
shouldUseStrictIteration() {
|
|
2768
|
+
return this.useStrictIteration_;
|
|
2769
|
+
}
|
|
2770
|
+
applyPatches(base, patches) {
|
|
2771
|
+
let i;
|
|
2772
|
+
for (i = patches.length - 1; i >= 0; i--) {
|
|
2773
|
+
const patch = patches[i];
|
|
2774
|
+
if (patch.path.length === 0 && patch.op === "replace") {
|
|
2775
|
+
base = patch.value;
|
|
2776
|
+
break;
|
|
2777
|
+
}
|
|
2778
|
+
}
|
|
2779
|
+
if (i > -1) patches = patches.slice(i + 1);
|
|
2780
|
+
const applyPatchesImpl = getPlugin("Patches").applyPatches_;
|
|
2781
|
+
if (isDraft(base)) return applyPatchesImpl(base, patches);
|
|
2782
|
+
return this.produce(base, (draft) => applyPatchesImpl(draft, patches));
|
|
2783
|
+
}
|
|
2784
|
+
};
|
|
2785
|
+
function createProxy(value, parent) {
|
|
2786
|
+
const draft = isMap(value) ? getPlugin("MapSet").proxyMap_(value, parent) : isSet(value) ? getPlugin("MapSet").proxySet_(value, parent) : createProxyProxy(value, parent);
|
|
2787
|
+
(parent ? parent.scope_ : getCurrentScope()).drafts_.push(draft);
|
|
2788
|
+
return draft;
|
|
2789
|
+
}
|
|
2790
|
+
function current(value) {
|
|
2791
|
+
if (!isDraft(value)) die(10, value);
|
|
2792
|
+
return currentImpl(value);
|
|
2793
|
+
}
|
|
2794
|
+
function currentImpl(value) {
|
|
2795
|
+
if (!isDraftable(value) || isFrozen(value)) return value;
|
|
2796
|
+
const state = value[DRAFT_STATE];
|
|
2797
|
+
let copy;
|
|
2798
|
+
let strict = true;
|
|
2799
|
+
if (state) {
|
|
2800
|
+
if (!state.modified_) return state.base_;
|
|
2801
|
+
state.finalized_ = true;
|
|
2802
|
+
copy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_);
|
|
2803
|
+
strict = state.scope_.immer_.shouldUseStrictIteration();
|
|
2804
|
+
} else copy = shallowCopy(value, true);
|
|
2805
|
+
each(copy, (key, childValue) => {
|
|
2806
|
+
set(copy, key, currentImpl(childValue));
|
|
2807
|
+
}, strict);
|
|
2808
|
+
if (state) state.finalized_ = false;
|
|
2809
|
+
return copy;
|
|
2810
|
+
}
|
|
2811
|
+
var immer = new Immer2();
|
|
2812
|
+
immer.produce;
|
|
2813
|
+
var setAutoFreeze = /* @__PURE__ */ immer.setAutoFreeze.bind(immer);
|
|
2814
|
+
const produce = new Immer2({
|
|
947
2815
|
autoFreeze: false,
|
|
948
2816
|
useStrictShallowCopy: true
|
|
949
2817
|
}).produce;
|
|
@@ -3952,6 +5820,248 @@ function mergeInitialIntoBaseWithSchema(base, init, rootSchema) {
|
|
|
3952
5820
|
}
|
|
3953
5821
|
}
|
|
3954
5822
|
//#endregion
|
|
5823
|
+
//#region ../medeo-dsl/src/schema/codec.ts
|
|
5824
|
+
function isInvalidAtomic(value) {
|
|
5825
|
+
return typeof value === "object" && value !== null && "invalid" in value && value.invalid === true;
|
|
5826
|
+
}
|
|
5827
|
+
function codec(encode, decode) {
|
|
5828
|
+
return {
|
|
5829
|
+
encode: (v) => isInvalidAtomic(v) ? v.raw : encode(v),
|
|
5830
|
+
decode: (raw) => {
|
|
5831
|
+
try {
|
|
5832
|
+
return decode(raw);
|
|
5833
|
+
} catch (error) {
|
|
5834
|
+
return {
|
|
5835
|
+
invalid: true,
|
|
5836
|
+
raw,
|
|
5837
|
+
reason: String(error)
|
|
5838
|
+
};
|
|
5839
|
+
}
|
|
5840
|
+
}
|
|
5841
|
+
};
|
|
5842
|
+
}
|
|
5843
|
+
/** A Clip's time anchor; the Clip holding it is the anchored end. */
|
|
5844
|
+
const timeAnchorCodec = codec((v) => {
|
|
5845
|
+
assertTimeAnchor(v);
|
|
5846
|
+
return JSON.stringify({
|
|
5847
|
+
to: v.to,
|
|
5848
|
+
offsetMs: v.offsetMs,
|
|
5849
|
+
fallback_abs_ms: v.fallback_abs_ms
|
|
5850
|
+
});
|
|
5851
|
+
}, (raw) => {
|
|
5852
|
+
const v = JSON.parse(raw);
|
|
5853
|
+
assertTimeAnchor(v);
|
|
5854
|
+
return v;
|
|
5855
|
+
});
|
|
5856
|
+
/** A segment selection as stored: a run's Cursors as their native bytes in unpadded base64url. */
|
|
5857
|
+
function encodeSelection(v) {
|
|
5858
|
+
return {
|
|
5859
|
+
audioScriptId: v.audioScriptId,
|
|
5860
|
+
segmentId: v.segmentId,
|
|
5861
|
+
...v.start === void 0 || v.end === void 0 ? {} : {
|
|
5862
|
+
start: bytesToBase64url(v.start.encode()),
|
|
5863
|
+
end: bytesToBase64url(v.end.encode())
|
|
5864
|
+
}
|
|
5865
|
+
};
|
|
5866
|
+
}
|
|
5867
|
+
function decodeSelection(v) {
|
|
5868
|
+
if (!v || typeof v !== "object") throw new Error("Expected a segment selection");
|
|
5869
|
+
const { start, end, ...rest } = v;
|
|
5870
|
+
if (start === void 0 && end === void 0) return rest;
|
|
5871
|
+
if (typeof start !== "string" || typeof end !== "string") throw new Error("Expected encoded Cursor pair");
|
|
5872
|
+
return {
|
|
5873
|
+
...rest,
|
|
5874
|
+
start: Cursor.decode(base64urlToBytes(start)),
|
|
5875
|
+
end: Cursor.decode(base64urlToBytes(end))
|
|
5876
|
+
};
|
|
5877
|
+
}
|
|
5878
|
+
/** A Caption's selection. */
|
|
5879
|
+
const captionContentCodec = codec((v) => {
|
|
5880
|
+
assertCaptionContent(v);
|
|
5881
|
+
return JSON.stringify(encodeSelection(v));
|
|
5882
|
+
}, (raw) => {
|
|
5883
|
+
const value = decodeSelection(JSON.parse(raw));
|
|
5884
|
+
assertCaptionContent(value);
|
|
5885
|
+
return value;
|
|
5886
|
+
});
|
|
5887
|
+
/** A PhoneticScript's selection and what to synthesize for it, stored as one string so they move together. */
|
|
5888
|
+
const phonemeCodec = codec((v) => {
|
|
5889
|
+
assertPhoneme(v);
|
|
5890
|
+
return JSON.stringify({
|
|
5891
|
+
...encodeSelection(v),
|
|
5892
|
+
...v.phonemeScript === void 0 ? {} : { phonemeScript: v.phonemeScript }
|
|
5893
|
+
});
|
|
5894
|
+
}, (raw) => {
|
|
5895
|
+
const value = decodeSelection(JSON.parse(raw));
|
|
5896
|
+
assertPhoneme(value);
|
|
5897
|
+
return value;
|
|
5898
|
+
});
|
|
5899
|
+
/** A row-owned binding couples the selection, pronunciation and its immutable file in one LWW value. */
|
|
5900
|
+
const phoneticBindingCodec = codec((value) => {
|
|
5901
|
+
assertEntity("phonetic-script-entities", value);
|
|
5902
|
+
assertPhoneticScript(void 0, { ...value });
|
|
5903
|
+
return JSON.stringify({
|
|
5904
|
+
phoneme: JSON.parse(phonemeCodec.encode(value.phoneme)),
|
|
5905
|
+
system: value.system,
|
|
5906
|
+
key: value.key,
|
|
5907
|
+
storageKey: value.storageKey,
|
|
5908
|
+
digest: value.digest
|
|
5909
|
+
});
|
|
5910
|
+
}, (raw) => {
|
|
5911
|
+
const value = JSON.parse(raw);
|
|
5912
|
+
if (!isRecord(value)) throw new Error("Expected a PhoneticScript binding");
|
|
5913
|
+
const phoneme = phonemeCodec.decode(JSON.stringify(value.phoneme));
|
|
5914
|
+
if (isInvalidAtomic(phoneme)) throw new Error(phoneme.reason);
|
|
5915
|
+
const binding = {
|
|
5916
|
+
...value,
|
|
5917
|
+
phoneme
|
|
5918
|
+
};
|
|
5919
|
+
assertEntity("phonetic-script-entities", binding);
|
|
5920
|
+
assertPhoneticScript(void 0, binding);
|
|
5921
|
+
return binding;
|
|
5922
|
+
});
|
|
5923
|
+
/** A Clip's sequence marker is stored as one string, so it is taken or replaced whole. */
|
|
5924
|
+
const seqMarkerCodec = codec((v) => {
|
|
5925
|
+
assertSeqMarker(v);
|
|
5926
|
+
return JSON.stringify({
|
|
5927
|
+
inMs: v.inMs,
|
|
5928
|
+
outMs: v.outMs,
|
|
5929
|
+
...v.rate === void 0 ? {} : { rate: v.rate },
|
|
5930
|
+
...v.fillTimeline === void 0 ? {} : { fillTimeline: v.fillTimeline }
|
|
5931
|
+
});
|
|
5932
|
+
}, (raw) => {
|
|
5933
|
+
const v = JSON.parse(raw);
|
|
5934
|
+
assertSeqMarker(v);
|
|
5935
|
+
return v;
|
|
5936
|
+
});
|
|
5937
|
+
//#endregion
|
|
5938
|
+
//#region ../medeo-dsl/src/schema/loro-shape.ts
|
|
5939
|
+
const optional = { required: false };
|
|
5940
|
+
const mergeable = { mergeableMapChildContainers: true };
|
|
5941
|
+
const strings = (keys) => Object.fromEntries(keys.map((key) => [key, schema.String()]));
|
|
5942
|
+
const relation = (keys) => schema.LoroMapRecord(schema.LoroMap(strings(keys)), mergeable);
|
|
5943
|
+
const transform = (codec) => ({
|
|
5944
|
+
...codec,
|
|
5945
|
+
isEqual: "encoded-value-equality",
|
|
5946
|
+
validateEncodedType: true
|
|
5947
|
+
});
|
|
5948
|
+
/** One field stored as one encoded string, so it is taken or replaced whole. */
|
|
5949
|
+
const atomicValue = (codec) => schema.String().transform(transform(codec));
|
|
5950
|
+
const optionalAtomicValue = (codec) => schema.String(optional).transform(transform(codec));
|
|
5951
|
+
/**
|
|
5952
|
+
* Only direct children inherit mergeable identity. Text and ordinary entity rows keep normal
|
|
5953
|
+
* identities, so deleting a row also drops what a peer wrote into it concurrently: a relation an
|
|
5954
|
+
* entity holds at most one of is a field of that row and never outlives it.
|
|
5955
|
+
*/
|
|
5956
|
+
const medeoDslLoroShape = schema({
|
|
5957
|
+
"timeline-entities": schema.LoroMapRecord(schema.LoroMap({})),
|
|
5958
|
+
"track-entities": schema.LoroMapRecord(schema.LoroMap({
|
|
5959
|
+
role: schema.String(),
|
|
5960
|
+
hidden: schema.Boolean(optional)
|
|
5961
|
+
})),
|
|
5962
|
+
"clip-entities": schema.LoroMapRecord(schema.LoroMap({
|
|
5963
|
+
seqMarker: atomicValue(seqMarkerCodec),
|
|
5964
|
+
volume: schema.Number(optional),
|
|
5965
|
+
source: schema.String(),
|
|
5966
|
+
anchor: optionalAtomicValue(timeAnchorCodec)
|
|
5967
|
+
})),
|
|
5968
|
+
"media-entities": schema.LoroMapRecord(schema.LoroMap({
|
|
5969
|
+
kind: schema.String(),
|
|
5970
|
+
system: schema.String(),
|
|
5971
|
+
key: schema.String(),
|
|
5972
|
+
storageKey: schema.String(optional),
|
|
5973
|
+
durationMs: schema.Number(optional),
|
|
5974
|
+
digest: schema.String(optional)
|
|
5975
|
+
}), mergeable),
|
|
5976
|
+
"audio-script-entities": schema.LoroMapRecord(schema.LoroMap({
|
|
5977
|
+
segments: schema.LoroMovableList(schema.LoroMap({
|
|
5978
|
+
id: schema.String(),
|
|
5979
|
+
text: schema.LoroText(),
|
|
5980
|
+
startMs: schema.Number(optional),
|
|
5981
|
+
endMs: schema.Number(optional)
|
|
5982
|
+
}), (segment) => segment.id),
|
|
5983
|
+
defaultLanguage: schema.String(optional),
|
|
5984
|
+
system: schema.String(optional),
|
|
5985
|
+
key: schema.String(optional),
|
|
5986
|
+
storageKey: schema.String(optional),
|
|
5987
|
+
digest: schema.String(optional)
|
|
5988
|
+
})),
|
|
5989
|
+
"phonetic-script-entities": schema.LoroMapRecord(schema.LoroMap({ binding: atomicValue(phoneticBindingCodec) })),
|
|
5990
|
+
"caption-entities": schema.LoroMapRecord(schema.LoroMap({
|
|
5991
|
+
selection: optionalAtomicValue(captionContentCodec),
|
|
5992
|
+
text: schema.LoroText(optional),
|
|
5993
|
+
style: schema.LoroMap({
|
|
5994
|
+
font: schema.LoroMap({
|
|
5995
|
+
system: schema.String(),
|
|
5996
|
+
key: schema.String()
|
|
5997
|
+
}, optional),
|
|
5998
|
+
fontSize: schema.Number(optional),
|
|
5999
|
+
fontColor: schema.String(optional),
|
|
6000
|
+
fontWeight: schema.Number(optional),
|
|
6001
|
+
entranceAnimation: schema.String(optional),
|
|
6002
|
+
entranceAnimationDurationMs: schema.Number(optional),
|
|
6003
|
+
strokeColor: schema.String(optional),
|
|
6004
|
+
strokeWidth: schema.Number(optional),
|
|
6005
|
+
positionX: schema.Number(optional),
|
|
6006
|
+
positionY: schema.Number(optional)
|
|
6007
|
+
}, {
|
|
6008
|
+
...optional,
|
|
6009
|
+
...mergeable
|
|
6010
|
+
})
|
|
6011
|
+
}, mergeable)),
|
|
6012
|
+
"voice-entities": schema.LoroMapRecord(schema.LoroMap({
|
|
6013
|
+
system: schema.String(),
|
|
6014
|
+
key: schema.String(),
|
|
6015
|
+
name: schema.String(optional)
|
|
6016
|
+
}), mergeable),
|
|
6017
|
+
"contain-relations": schema.LoroTree(schema.LoroMap({ entityId: schema.String() })),
|
|
6018
|
+
"voice-timbre-relations": relation(["recordingId", "voiceId"]),
|
|
6019
|
+
"derived-from-relations": schema.LoroMapRecord(schema.LoroMap({
|
|
6020
|
+
entityId: schema.String(),
|
|
6021
|
+
sourceId: schema.String(),
|
|
6022
|
+
sourceDigest: schema.String(optional)
|
|
6023
|
+
}), mergeable)
|
|
6024
|
+
});
|
|
6025
|
+
//#endregion
|
|
6026
|
+
//#region ../medeo-dsl/src/schema/document-format.ts
|
|
6027
|
+
/** Format discrimination does not register containers or alter the document. */
|
|
6028
|
+
function documentFormat(doc) {
|
|
6029
|
+
const roots = doc.getShallowValue();
|
|
6030
|
+
const legacy = [
|
|
6031
|
+
"medeo",
|
|
6032
|
+
"timeline",
|
|
6033
|
+
"tracks",
|
|
6034
|
+
"part_library"
|
|
6035
|
+
].some((key) => Object.hasOwn(roots, key));
|
|
6036
|
+
const dsl = Object.keys(roots).some((key) => key.endsWith("-entities") || key.endsWith("-relations"));
|
|
6037
|
+
return legacy && dsl ? "mixed" : legacy ? "legacy" : dsl ? "dsl" : "unknown";
|
|
6038
|
+
}
|
|
6039
|
+
var UnsupportedDocumentFormatError = class extends Error {
|
|
6040
|
+
code = "unsupported_document_format";
|
|
6041
|
+
constructor(message = "Expected a new DSL document; legacy, mixed or uninitialized content is not supported") {
|
|
6042
|
+
super(message);
|
|
6043
|
+
this.name = "UnsupportedDocumentFormatError";
|
|
6044
|
+
}
|
|
6045
|
+
};
|
|
6046
|
+
/** Run after initial import, before opening an editable handle. Empty new documents still have one Timeline. */
|
|
6047
|
+
function assertDslDocument(doc) {
|
|
6048
|
+
if (documentFormat(doc) !== "dsl" || doc.getMap("timeline-entities").keys().length !== 1) throw new UnsupportedDocumentFormatError();
|
|
6049
|
+
assertPhoneticBindingFormat(doc);
|
|
6050
|
+
}
|
|
6051
|
+
/** This storage cutover has no field-per-fact reader or mixed-version write path. */
|
|
6052
|
+
function assertPhoneticBindingFormat(doc) {
|
|
6053
|
+
if (!Object.hasOwn(doc.getShallowValue(), "phonetic-script-entities")) return;
|
|
6054
|
+
const table = doc.getMap("phonetic-script-entities");
|
|
6055
|
+
for (const id of table.keys()) {
|
|
6056
|
+
const row = table.get(id);
|
|
6057
|
+
if (!isContainer(row) || row.kind() !== "Map" || row.keys().some((key) => key !== "binding") || typeof row.get("binding") !== "string") throw new UnsupportedDocumentFormatError("PhoneticScript storage requires one atomic binding; old DSL documents need explicit migration");
|
|
6058
|
+
}
|
|
6059
|
+
}
|
|
6060
|
+
//#endregion
|
|
6061
|
+
//#region ../medeo-dsl/src/schema/text-styles.ts
|
|
6062
|
+
/** How rich-text marks extend at their edges: a language runs on into text typed after it. */
|
|
6063
|
+
const textStyles = { language: { expand: "after" } };
|
|
6064
|
+
//#endregion
|
|
3955
6065
|
//#region src/dsl/document/phonetic-binding.ts
|
|
3956
6066
|
/**
|
|
3957
6067
|
* Actions and the transaction guard keep their domain-shaped rows. The native schema stores
|
|
@@ -6093,6 +8203,9 @@ function fromDraftStyle(style) {
|
|
|
6093
8203
|
};
|
|
6094
8204
|
}
|
|
6095
8205
|
//#endregion
|
|
8206
|
+
//#region src/dsl/projection/video-draft-types.ts
|
|
8207
|
+
const DEFAULT_UNIT_TIME_MS = 33.333;
|
|
8208
|
+
//#endregion
|
|
6096
8209
|
//#region src/dsl/projection/to-video-draft.ts
|
|
6097
8210
|
/** A content read view, not an archive of authoring identities, rich-text marks or provenance. */
|
|
6098
8211
|
function toVideoDraft(snapshot) {
|
|
@@ -6581,4 +8694,4 @@ function importedScript(id, text, mintSegment) {
|
|
|
6581
8694
|
};
|
|
6582
8695
|
}
|
|
6583
8696
|
//#endregion
|
|
6584
|
-
export {
|
|
8697
|
+
export { DslProjectionError as _, DslEditor as a, resourceId as b, UnsupportedDocumentFormatError as c, documentFormat as d, medeoDslLoroShape as f, resolveDslLayout as g, timeAnchorCodec as h, createInitialMedeoDsl as i, assertDslDocument as l, isInvalidAtomic as m, toVideoDraft as n, toAudioScriptViews as o, captionContentCodec as p, DEFAULT_UNIT_TIME_MS as r, MedeoDsl as s, fromVideoDraft as t, assertPhoneticBindingFormat as u, defaultIdFactory as v, tupleHash as x, relationId as y };
|