@pixerate/editor 0.23.0 → 0.25.0
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 +167 -2
- package/THIRD_PARTY_NOTICES.md +80 -0
- package/dist/agent/index.cjs +10 -8
- package/dist/agent/index.cjs.map +1 -1
- package/dist/agent/index.d.cts +4 -3
- package/dist/agent/index.d.ts +4 -3
- package/dist/agent/index.js +4 -2
- package/dist/agent/index.js.map +1 -1
- package/dist/canvas/index.cjs +4437 -411
- package/dist/canvas/index.cjs.map +1 -1
- package/dist/canvas/index.d.cts +934 -4
- package/dist/canvas/index.d.ts +934 -4
- package/dist/canvas/index.js +4309 -283
- package/dist/canvas/index.js.map +1 -1
- package/dist/chunk-4BVP64JJ.cjs +1406 -0
- package/dist/chunk-4BVP64JJ.cjs.map +1 -0
- package/dist/chunk-664LQYFJ.js +115 -0
- package/dist/chunk-664LQYFJ.js.map +1 -0
- package/dist/chunk-7WISYZFO.cjs +740 -0
- package/dist/chunk-7WISYZFO.cjs.map +1 -0
- package/dist/chunk-AL6JMGWW.cjs +783 -0
- package/dist/chunk-AL6JMGWW.cjs.map +1 -0
- package/dist/chunk-BVP3TSLH.cjs +69 -0
- package/dist/chunk-BVP3TSLH.cjs.map +1 -0
- package/dist/{chunk-RIKBJLS2.cjs → chunk-C7P22VIP.cjs} +2001 -279
- package/dist/chunk-C7P22VIP.cjs.map +1 -0
- package/dist/chunk-D6FH2YAX.cjs +131 -0
- package/dist/chunk-D6FH2YAX.cjs.map +1 -0
- package/dist/chunk-ECCCYKGL.js +740 -0
- package/dist/chunk-ECCCYKGL.js.map +1 -0
- package/dist/{chunk-4SUNJZWB.cjs → chunk-FD4LPFAE.cjs} +48 -200
- package/dist/chunk-FD4LPFAE.cjs.map +1 -0
- package/dist/{chunk-QBJ22YZR.js → chunk-FH6F67DN.js} +1999 -277
- package/dist/chunk-FH6F67DN.js.map +1 -0
- package/dist/{chunk-OYXSKQFR.js → chunk-FPENXAEJ.js} +35 -187
- package/dist/chunk-FPENXAEJ.js.map +1 -0
- package/dist/chunk-HLIMTC6N.js +1 -0
- package/dist/chunk-HLIMTC6N.js.map +1 -0
- package/dist/chunk-HRMEDT2L.js +1406 -0
- package/dist/chunk-HRMEDT2L.js.map +1 -0
- package/dist/{chunk-QGHGJ56O.js → chunk-IXHSYOVY.js} +2518 -122
- package/dist/chunk-IXHSYOVY.js.map +1 -0
- package/dist/chunk-MKA3AHLV.cjs +256 -0
- package/dist/chunk-MKA3AHLV.cjs.map +1 -0
- package/dist/chunk-NAXVVS5I.js +783 -0
- package/dist/chunk-NAXVVS5I.js.map +1 -0
- package/dist/chunk-O5RYH2PG.js +69 -0
- package/dist/chunk-O5RYH2PG.js.map +1 -0
- package/dist/chunk-OXSV64JX.js +689 -0
- package/dist/chunk-OXSV64JX.js.map +1 -0
- package/dist/chunk-P3RQ5UJE.cjs +689 -0
- package/dist/chunk-P3RQ5UJE.cjs.map +1 -0
- package/dist/chunk-P6ODPZ4W.js +256 -0
- package/dist/chunk-P6ODPZ4W.js.map +1 -0
- package/dist/chunk-PL4JB3BF.cjs +1 -0
- package/dist/chunk-PL4JB3BF.cjs.map +1 -0
- package/dist/{chunk-GVSMRPHB.cjs → chunk-PO6A6QQH.cjs} +2607 -211
- package/dist/chunk-PO6A6QQH.cjs.map +1 -0
- package/dist/{chunk-JJDLPEWL.js → chunk-QGYDWPRM.js} +2 -2
- package/dist/chunk-RR7F5GUM.js +5726 -0
- package/dist/chunk-RR7F5GUM.js.map +1 -0
- package/dist/chunk-TNNJXF46.cjs +115 -0
- package/dist/chunk-TNNJXF46.cjs.map +1 -0
- package/dist/chunk-U5HZSFCS.js +131 -0
- package/dist/chunk-U5HZSFCS.js.map +1 -0
- package/dist/{chunk-MJZBNWG7.js → chunk-UAKDG62Z.js} +309 -581
- package/dist/chunk-UAKDG62Z.js.map +1 -0
- package/dist/{chunk-CL37JGFW.cjs → chunk-V3CHHWOE.cjs} +4 -4
- package/dist/{chunk-CL37JGFW.cjs.map → chunk-V3CHHWOE.cjs.map} +1 -1
- package/dist/chunk-WSQKHXW7.cjs +5726 -0
- package/dist/chunk-WSQKHXW7.cjs.map +1 -0
- package/dist/{chunk-AA4ZEVCC.cjs → chunk-X4N4WUKB.cjs} +336 -608
- package/dist/chunk-X4N4WUKB.cjs.map +1 -0
- package/dist/commands/index.cjs +74 -1
- package/dist/commands/index.cjs.map +1 -1
- package/dist/commands/index.d.cts +38 -353
- package/dist/commands/index.d.ts +38 -353
- package/dist/commands/index.js +73 -0
- package/dist/commands/index.js.map +1 -1
- package/dist/comment-store-BEMgVlAA.d.cts +135 -0
- package/dist/comment-store-BEMgVlAA.d.ts +135 -0
- package/dist/compare/index.cjs +15 -0
- package/dist/compare/index.cjs.map +1 -0
- package/dist/compare/index.d.cts +58 -0
- package/dist/compare/index.d.ts +58 -0
- package/dist/compare/index.js +15 -0
- package/dist/compare/index.js.map +1 -0
- package/dist/controller-BIJiNoVs.d.cts +1842 -0
- package/dist/controller-BIJiNoVs.d.ts +1842 -0
- package/dist/documents-CHT1U5Vs.d.ts +86 -0
- package/dist/documents-Gp7wb0Me.d.cts +86 -0
- package/dist/extensions/index.cjs +100 -5
- package/dist/extensions/index.cjs.map +1 -1
- package/dist/extensions/index.d.cts +16 -4
- package/dist/extensions/index.d.ts +16 -4
- package/dist/extensions/index.js +100 -5
- package/dist/generation/index.cjs +2317 -0
- package/dist/generation/index.cjs.map +1 -0
- package/dist/generation/index.d.cts +1015 -0
- package/dist/generation/index.d.ts +1015 -0
- package/dist/generation/index.js +2317 -0
- package/dist/generation/index.js.map +1 -0
- package/dist/grammar/index.cjs +48 -3
- package/dist/grammar/index.cjs.map +1 -1
- package/dist/grammar/index.d.cts +322 -100
- package/dist/grammar/index.d.ts +322 -100
- package/dist/grammar/index.js +54 -9
- package/dist/image-editor/index.cjs +4392 -481
- package/dist/image-editor/index.cjs.map +1 -1
- package/dist/image-editor/index.d.cts +1249 -97
- package/dist/image-editor/index.d.ts +1249 -97
- package/dist/image-editor/index.js +4281 -370
- package/dist/image-editor/index.js.map +1 -1
- package/dist/index-7a6bHTLy.d.ts +1754 -0
- package/dist/index-Csd5qI8u.d.cts +1754 -0
- package/dist/index.cjs +1682 -99
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +118 -21
- package/dist/index.d.ts +118 -21
- package/dist/index.js +1630 -47
- package/dist/index.js.map +1 -1
- package/dist/mention-text-CDnCFd3c.d.cts +53 -0
- package/dist/mention-text-CDnCFd3c.d.ts +53 -0
- package/dist/migrate-iTlm3a8h.d.cts +112 -0
- package/dist/migrate-iTlm3a8h.d.ts +112 -0
- package/dist/model-C1zApQM8.d.cts +219 -0
- package/dist/model-C1zApQM8.d.ts +219 -0
- package/dist/persistence/index.cjs +676 -0
- package/dist/persistence/index.cjs.map +1 -0
- package/dist/persistence/index.d.cts +230 -0
- package/dist/persistence/index.d.ts +230 -0
- package/dist/persistence/index.js +676 -0
- package/dist/persistence/index.js.map +1 -0
- package/dist/{registry-D5-R90p0.d.cts → registry-BDe-vlv3.d.ts} +2 -40
- package/dist/{registry-GJI4gToU.d.ts → registry-CEgwXED1.d.cts} +12 -1
- package/dist/{registry-GJI4gToU.d.cts → registry-CEgwXED1.d.ts} +12 -1
- package/dist/registry-D32LpIc4.d.cts +354 -0
- package/dist/{registry-D5-R90p0.d.ts → registry-DnzpgY27.d.cts} +2 -40
- package/dist/registry-evKTP4ls.d.ts +354 -0
- package/dist/schema-DYDGdYL9.d.cts +41 -0
- package/dist/schema-DYDGdYL9.d.ts +41 -0
- package/dist/serializers/index.cjs +12 -3
- package/dist/serializers/index.cjs.map +1 -1
- package/dist/serializers/index.d.cts +40 -12
- package/dist/serializers/index.d.ts +40 -12
- package/dist/serializers/index.js +12 -3
- package/dist/sourcemap-C8AH3MBQ.d.cts +91 -0
- package/dist/sourcemap-DA1Evhrv.d.ts +91 -0
- package/dist/spreadsheet/index.cjs +161 -3
- package/dist/spreadsheet/index.cjs.map +1 -1
- package/dist/spreadsheet/index.d.cts +611 -20
- package/dist/spreadsheet/index.d.ts +611 -20
- package/dist/spreadsheet/index.js +168 -10
- package/dist/storage-BpFfspHm.d.cts +120 -0
- package/dist/storage-BpFfspHm.d.ts +120 -0
- package/dist/tokens/index.cjs +115 -0
- package/dist/tokens/index.cjs.map +1 -0
- package/dist/tokens/index.d.cts +212 -0
- package/dist/tokens/index.d.ts +212 -0
- package/dist/tokens/index.js +115 -0
- package/dist/tokens/index.js.map +1 -0
- package/dist/{tokens-CyLZmIei.d.cts → tokens-D7yXvUU6.d.cts} +15 -2
- package/dist/{tokens-CyLZmIei.d.ts → tokens-D7yXvUU6.d.ts} +15 -2
- package/dist/{track-changes-BSF58RK0.d.cts → track-changes-D_VAPELi.d.cts} +110 -144
- package/dist/{track-changes-BSF58RK0.d.ts → track-changes-Db_fGEvx.d.ts} +110 -144
- package/package.json +21 -1
- package/dist/chunk-4SUNJZWB.cjs.map +0 -1
- package/dist/chunk-AA4ZEVCC.cjs.map +0 -1
- package/dist/chunk-AXV2ZW34.cjs +0 -118
- package/dist/chunk-AXV2ZW34.cjs.map +0 -1
- package/dist/chunk-B2ZRLN4S.js +0 -118
- package/dist/chunk-B2ZRLN4S.js.map +0 -1
- package/dist/chunk-GVSMRPHB.cjs.map +0 -1
- package/dist/chunk-K3R5NG2D.js +0 -3100
- package/dist/chunk-K3R5NG2D.js.map +0 -1
- package/dist/chunk-MJZBNWG7.js.map +0 -1
- package/dist/chunk-OYXSKQFR.js.map +0 -1
- package/dist/chunk-QBJ22YZR.js.map +0 -1
- package/dist/chunk-QGHGJ56O.js.map +0 -1
- package/dist/chunk-RIKBJLS2.cjs.map +0 -1
- package/dist/chunk-XDMXXC4Z.cjs +0 -3100
- package/dist/chunk-XDMXXC4Z.cjs.map +0 -1
- package/dist/controller-pePCJLT1.d.cts +0 -959
- package/dist/controller-pePCJLT1.d.ts +0 -959
- package/dist/index-CCr_z9kF.d.cts +0 -899
- package/dist/index-Ck6ajwXh.d.ts +0 -899
- /package/dist/{chunk-JJDLPEWL.js.map → chunk-QGYDWPRM.js.map} +0 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/persistence/migrate.ts
|
|
2
|
+
function hasLoadProblems(report) {
|
|
3
|
+
return report.problems.length > 0 || report.readOnly !== null;
|
|
4
|
+
}
|
|
5
|
+
function createLoadReport(partial = {}) {
|
|
6
|
+
return {
|
|
7
|
+
migratedFrom: null,
|
|
8
|
+
version: null,
|
|
9
|
+
problems: [],
|
|
10
|
+
readOnly: null,
|
|
11
|
+
unknownKeys: [],
|
|
12
|
+
...partial
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
16
|
+
var deepClone = (value) => typeof structuredClone === "function" ? structuredClone(value) : JSON.parse(JSON.stringify(value));
|
|
17
|
+
function toObject(json) {
|
|
18
|
+
let value = json;
|
|
19
|
+
if (typeof json === "string") {
|
|
20
|
+
try {
|
|
21
|
+
value = JSON.parse(json);
|
|
22
|
+
} catch (e) {
|
|
23
|
+
return void 0;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return isObject(value) ? deepClone(value) : void 0;
|
|
27
|
+
}
|
|
28
|
+
function migrateDocument(json, options) {
|
|
29
|
+
const versionKey = _nullishCoalesce(options.versionKey, () => ( "version"));
|
|
30
|
+
const target = options.currentVersion;
|
|
31
|
+
const original = toObject(json);
|
|
32
|
+
if (!original) {
|
|
33
|
+
return {
|
|
34
|
+
doc: { [versionKey]: target },
|
|
35
|
+
report: createLoadReport({
|
|
36
|
+
readOnly: { kind: "invalid", message: "document is not a JSON object" }
|
|
37
|
+
})
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const raw = original[versionKey];
|
|
41
|
+
const found = typeof raw === "number" && Number.isInteger(raw) && raw >= 0 ? raw : null;
|
|
42
|
+
const from = _nullishCoalesce(_nullishCoalesce(found, () => ( options.missingVersion)), () => ( target));
|
|
43
|
+
const report = createLoadReport({ version: found });
|
|
44
|
+
if (from > target) {
|
|
45
|
+
report.readOnly = {
|
|
46
|
+
kind: "newerVersion",
|
|
47
|
+
version: from,
|
|
48
|
+
supported: target,
|
|
49
|
+
message: `document has version ${from}, newer than the supported ${target}`
|
|
50
|
+
};
|
|
51
|
+
return { doc: original, report };
|
|
52
|
+
}
|
|
53
|
+
if (from === target) {
|
|
54
|
+
original[versionKey] = target;
|
|
55
|
+
return { doc: original, report };
|
|
56
|
+
}
|
|
57
|
+
let doc = deepClone(original);
|
|
58
|
+
for (let step = from; step < target; step++) {
|
|
59
|
+
const fn = _optionalChain([options, 'access', _ => _.steps, 'optionalAccess', _2 => _2[step]]);
|
|
60
|
+
if (!fn) {
|
|
61
|
+
report.readOnly = {
|
|
62
|
+
kind: "migrationFailed",
|
|
63
|
+
from: step,
|
|
64
|
+
message: `no migration step from version ${step}`
|
|
65
|
+
};
|
|
66
|
+
return { doc: original, report };
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
doc = _nullishCoalesce(fn(doc), () => ( doc));
|
|
70
|
+
} catch (error) {
|
|
71
|
+
report.readOnly = {
|
|
72
|
+
kind: "migrationFailed",
|
|
73
|
+
from: step,
|
|
74
|
+
message: `migration from version ${step} failed: ${error instanceof Error ? error.message : String(error)}`
|
|
75
|
+
};
|
|
76
|
+
return { doc: original, report };
|
|
77
|
+
}
|
|
78
|
+
doc[versionKey] = step + 1;
|
|
79
|
+
}
|
|
80
|
+
report.migratedFrom = from;
|
|
81
|
+
return { doc, report };
|
|
82
|
+
}
|
|
83
|
+
function loadSections(doc, sections, options = {}) {
|
|
84
|
+
const source = isObject(doc) ? doc : {};
|
|
85
|
+
const ignore = new Set(_nullishCoalesce(options.ignore, () => ( ["version"])));
|
|
86
|
+
const value = {};
|
|
87
|
+
const problems = [];
|
|
88
|
+
for (const key of Object.keys(sections)) {
|
|
89
|
+
const spec = sections[key];
|
|
90
|
+
const fallback = () => typeof spec.defaults === "function" ? spec.defaults() : spec.defaults;
|
|
91
|
+
if (!Object.prototype.hasOwnProperty.call(source, key)) {
|
|
92
|
+
value[key] = fallback();
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
const parsed = spec.parse(source[key]);
|
|
97
|
+
if (parsed === void 0) throw new Error("invalid value");
|
|
98
|
+
value[key] = parsed;
|
|
99
|
+
} catch (error) {
|
|
100
|
+
problems.push({
|
|
101
|
+
section: key,
|
|
102
|
+
message: error instanceof Error ? error.message : String(error)
|
|
103
|
+
});
|
|
104
|
+
value[key] = fallback();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const unknown = {};
|
|
108
|
+
for (const key of Object.keys(source)) {
|
|
109
|
+
if (!(key in sections) && !ignore.has(key)) unknown[key] = source[key];
|
|
110
|
+
}
|
|
111
|
+
return { value, problems, unknown };
|
|
112
|
+
}
|
|
113
|
+
function loadDocument(json, sections, options) {
|
|
114
|
+
const { doc, report } = migrateDocument(json, options);
|
|
115
|
+
const ignore = _nullishCoalesce(options.ignore, () => ( [_nullishCoalesce(options.versionKey, () => ( "version"))]));
|
|
116
|
+
const result = loadSections(_optionalChain([report, 'access', _3 => _3.readOnly, 'optionalAccess', _4 => _4.kind]) === "invalid" ? {} : doc, sections, {
|
|
117
|
+
ignore
|
|
118
|
+
});
|
|
119
|
+
report.problems = result.problems;
|
|
120
|
+
report.unknownKeys = Object.keys(result.unknown);
|
|
121
|
+
return { ...result, report };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
exports.hasLoadProblems = hasLoadProblems; exports.createLoadReport = createLoadReport; exports.migrateDocument = migrateDocument; exports.loadSections = loadSections; exports.loadDocument = loadDocument;
|
|
131
|
+
//# sourceMappingURL=chunk-D6FH2YAX.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/editor/editor/packages/core/dist/chunk-D6FH2YAX.cjs","../src/persistence/migrate.ts"],"names":[],"mappings":"AAAA;ACmCO,SAAS,eAAA,CAAgB,MAAA,EAA6B;AAC3D,EAAA,OAAO,MAAA,CAAO,QAAA,CAAS,OAAA,EAAS,EAAA,GAAK,MAAA,CAAO,SAAA,IAAa,IAAA;AAC3D;AAEO,SAAS,gBAAA,CAAiB,QAAA,EAA+B,CAAC,CAAA,EAAe;AAC9E,EAAA,OAAO;AAAA,IACL,YAAA,EAAc,IAAA;AAAA,IACd,OAAA,EAAS,IAAA;AAAA,IACT,QAAA,EAAU,CAAC,CAAA;AAAA,IACX,QAAA,EAAU,IAAA;AAAA,IACV,WAAA,EAAa,CAAC,CAAA;AAAA,IACd,GAAG;AAAA,EACL,CAAA;AACF;AA2BA,IAAM,SAAA,EAAW,CAAC,KAAA,EAAA,GAChB,OAAO,MAAA,IAAU,SAAA,GAAY,MAAA,IAAU,KAAA,GAAQ,CAAC,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA;AAErE,IAAM,UAAA,EAAY,CAAI,KAAA,EAAA,GACpB,OAAO,gBAAA,IAAoB,WAAA,EACvB,eAAA,CAAgB,KAAK,EAAA,EACpB,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,SAAA,CAAU,KAAK,CAAC,CAAA;AAGvC,SAAS,QAAA,CAAS,IAAA,EAAuC;AACvD,EAAA,IAAI,MAAA,EAAQ,IAAA;AACZ,EAAA,GAAA,CAAI,OAAO,KAAA,IAAS,QAAA,EAAU;AAC5B,IAAA,IAAI;AACF,MAAA,MAAA,EAAQ,IAAA,CAAK,KAAA,CAAM,IAAI,CAAA;AAAA,IACzB,EAAA,UAAQ;AACN,MAAA,OAAO,KAAA,CAAA;AAAA,IACT;AAAA,EACF;AACA,EAAA,OAAO,QAAA,CAAS,KAAK,EAAA,EAAI,SAAA,CAAU,KAAK,EAAA,EAAI,KAAA,CAAA;AAC9C;AAaO,SAAS,eAAA,CAAgB,IAAA,EAAe,OAAA,EAAwC;AACrF,EAAA,MAAM,WAAA,mBAAa,OAAA,CAAQ,UAAA,UAAc,WAAA;AACzC,EAAA,MAAM,OAAA,EAAS,OAAA,CAAQ,cAAA;AACvB,EAAA,MAAM,SAAA,EAAW,QAAA,CAAS,IAAI,CAAA;AAC9B,EAAA,GAAA,CAAI,CAAC,QAAA,EAAU;AACb,IAAA,OAAO;AAAA,MACL,GAAA,EAAK,EAAE,CAAC,UAAU,CAAA,EAAG,OAAO,CAAA;AAAA,MAC5B,MAAA,EAAQ,gBAAA,CAAiB;AAAA,QACvB,QAAA,EAAU,EAAE,IAAA,EAAM,SAAA,EAAW,OAAA,EAAS,gCAAgC;AAAA,MACxE,CAAC;AAAA,IACH,CAAA;AAAA,EACF;AACA,EAAA,MAAM,IAAA,EAAM,QAAA,CAAS,UAAU,CAAA;AAC/B,EAAA,MAAM,MAAA,EAAQ,OAAO,IAAA,IAAQ,SAAA,GAAY,MAAA,CAAO,SAAA,CAAU,GAAG,EAAA,GAAK,IAAA,GAAO,EAAA,EAAI,IAAA,EAAM,IAAA;AACnF,EAAA,MAAM,KAAA,oCAAO,KAAA,UAAS,OAAA,CAAQ,gBAAA,UAAkB,QAAA;AAChD,EAAA,MAAM,OAAA,EAAS,gBAAA,CAAiB,EAAE,OAAA,EAAS,MAAM,CAAC,CAAA;AAElD,EAAA,GAAA,CAAI,KAAA,EAAO,MAAA,EAAQ;AACjB,IAAA,MAAA,CAAO,SAAA,EAAW;AAAA,MAChB,IAAA,EAAM,cAAA;AAAA,MACN,OAAA,EAAS,IAAA;AAAA,MACT,SAAA,EAAW,MAAA;AAAA,MACX,OAAA,EAAS,CAAA,qBAAA,EAAwB,IAAI,CAAA,2BAAA,EAA8B,MAAM,CAAA;AAAA,IAAA;AAE3E,IAAA;AAA+B,EAAA;AAEjC,EAAA;AACE,IAAA;AACA,IAAA;AAA+B,EAAA;AAGjC,EAAA;AACA,EAAA;AACE,IAAA;AACA,IAAA;AACE,MAAA;AAAkB,QAAA;AACV,QAAA;AACA,QAAA;AACyC,MAAA;AAEjD,MAAA;AAA+B,IAAA;AAEjC,IAAA;AACE,MAAA;AAAiB,IAAA;AAEjB,MAAA;AAAkB,QAAA;AACV,QAAA;AACA,QAAA;AAGN,MAAA;AAGF,MAAA;AAA+B,IAAA;AAEjC,IAAA;AAAyB,EAAA;AAE3B,EAAA;AACA,EAAA;AACF;AA8BO;AAKL,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACE,IAAA;AACA,IAAA;AAIA,IAAA;AACE,MAAA;AACA,MAAA;AAAA,IAAA;AAEF,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AAAa,IAAA;AAEb,MAAA;AAAc,QAAA;AACH,QAAA;AACqD,MAAA;AAEhE,MAAA;AAAsB,IAAA;AACxB,EAAA;AAEF,EAAA;AACA,EAAA;AACE,IAAA;AAAqE,EAAA;AAEvE,EAAA;AACF;AAYO;AAKL,EAAA;AACA,EAAA;AACA,EAAA;AAAsF,IAAA;AACpF,EAAA;AAEF,EAAA;AACA,EAAA;AACA,EAAA;AACF;ADvIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/editor/editor/packages/core/dist/chunk-D6FH2YAX.cjs","sourcesContent":[null,"// Portions ported from craft-libs-main/crates/settings/src/migrate.rs, src/document.rs and\n// src/error.rs (MIT OR Apache-2.0, © ArtCraft Team and contributors). See THIRD_PARTY_NOTICES.md.\n\n/** A section whose stored value did not fit; its defaults were used instead. */\nexport interface SectionProblem {\n /** Top-level key of the section. */\n section: string;\n message: string;\n}\n\n/** Why a loaded document must not be written back. */\nexport type ReadOnlyReason =\n | { kind: \"newerVersion\"; version: number; supported: number; message: string }\n | { kind: \"migrationFailed\"; from: number; message: string }\n | { kind: \"invalid\"; message: string };\n\n/** What happened while loading a document. Nothing in here is fatal. */\nexport interface LoadReport {\n /** Set when the document was upgraded step by step from this older version. */\n migratedFrom: number | null;\n /** The version found in the input (`null` when it had none). */\n version: number | null;\n /** Sections replaced by their defaults (see `loadSections`). */\n problems: SectionProblem[];\n /**\n * Set when the document must not be saved over: written by a newer build,\n * a migration step failed, or the input was not an object. Show the values,\n * but never overwrite the stored document.\n */\n readOnly: ReadOnlyReason | null;\n /** Top-level keys this build does not know; kept in `unknown` so a save can write them back. */\n unknownKeys: string[];\n}\n\n/** True when something should be shown to the user. */\nexport function hasLoadProblems(report: LoadReport): boolean {\n return report.problems.length > 0 || report.readOnly !== null;\n}\n\nexport function createLoadReport(partial: Partial<LoadReport> = {}): LoadReport {\n return {\n migratedFrom: null,\n version: null,\n problems: [],\n readOnly: null,\n unknownKeys: [],\n ...partial,\n };\n}\n\nexport type JsonObject = Record<string, unknown>;\n\n/** One migration step: turns a document at version `from` into version `from + 1`. */\nexport type MigrationStep = (doc: JsonObject) => JsonObject | void;\n\nexport interface MigrateOptions {\n /** The version this build writes. */\n currentVersion: number;\n /** Steps keyed by the version they start from. */\n steps?: Record<number, MigrationStep>;\n /** Key holding the version (default `\"version\"`). */\n versionKey?: string;\n /**\n * Version assumed when the key is missing (default: `currentVersion`, i.e. a\n * hand-written document is taken as current and the key is added).\n */\n missingVersion?: number;\n}\n\nexport interface MigrateResult {\n /** The migrated document (a deep copy; the input is never modified). */\n doc: JsonObject;\n report: LoadReport;\n}\n\nconst isObject = (value: unknown): value is JsonObject =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\nconst deepClone = <T>(value: T): T =>\n typeof structuredClone === \"function\"\n ? structuredClone(value)\n : (JSON.parse(JSON.stringify(value)) as T);\n\n/** Parses a JSON string, or deep-copies an object. `undefined` when it is not an object. */\nfunction toObject(json: unknown): JsonObject | undefined {\n let value = json;\n if (typeof json === \"string\") {\n try {\n value = JSON.parse(json);\n } catch {\n return undefined;\n }\n }\n return isObject(value) ? deepClone(value) : undefined;\n}\n\n/**\n * Brings a stored document up to `currentVersion` by running one step per\n * version (`steps[v]` turns version `v` into `v + 1`).\n *\n * - Missing version: taken as `missingVersion` (default current); the key is added.\n * - Newer than `currentVersion`: left alone and reported `readOnly` (never overwrite\n * a file written by a newer build).\n * - A missing or throwing step: the document is returned as it was before\n * migrating and reported `readOnly`.\n * - Keys the steps do not touch are preserved.\n */\nexport function migrateDocument(json: unknown, options: MigrateOptions): MigrateResult {\n const versionKey = options.versionKey ?? \"version\";\n const target = options.currentVersion;\n const original = toObject(json);\n if (!original) {\n return {\n doc: { [versionKey]: target },\n report: createLoadReport({\n readOnly: { kind: \"invalid\", message: \"document is not a JSON object\" },\n }),\n };\n }\n const raw = original[versionKey];\n const found = typeof raw === \"number\" && Number.isInteger(raw) && raw >= 0 ? raw : null;\n const from = found ?? options.missingVersion ?? target;\n const report = createLoadReport({ version: found });\n\n if (from > target) {\n report.readOnly = {\n kind: \"newerVersion\",\n version: from,\n supported: target,\n message: `document has version ${from}, newer than the supported ${target}`,\n };\n return { doc: original, report };\n }\n if (from === target) {\n original[versionKey] = target;\n return { doc: original, report };\n }\n\n let doc = deepClone(original);\n for (let step = from; step < target; step++) {\n const fn = options.steps?.[step];\n if (!fn) {\n report.readOnly = {\n kind: \"migrationFailed\",\n from: step,\n message: `no migration step from version ${step}`,\n };\n return { doc: original, report };\n }\n try {\n doc = fn(doc) ?? doc;\n } catch (error) {\n report.readOnly = {\n kind: \"migrationFailed\",\n from: step,\n message: `migration from version ${step} failed: ${\n error instanceof Error ? error.message : String(error)\n }`,\n };\n // Never hand back half-migrated values.\n return { doc: original, report };\n }\n doc[versionKey] = step + 1;\n }\n report.migratedFrom = from;\n return { doc, report };\n}\n\n/** How one top-level section is read. */\nexport interface SectionSpec<V> {\n /** Validates / converts the stored value; throw (or return `undefined`) to reject it. */\n parse: (value: unknown) => V | undefined;\n /** Used when the section is missing or rejected. */\n defaults: V | (() => V);\n}\n\nexport type SectionSpecs<T> = { [K in keyof T]: SectionSpec<T[K]> };\n\nexport interface LoadSectionsOptions {\n /** Keys that are neither sections nor unknown (default `[\"version\"]`). */\n ignore?: string[];\n}\n\nexport interface LoadSectionsResult<T> {\n value: T;\n /** Sections that were present but rejected (missing ones are not problems). */\n problems: SectionProblem[];\n /** Top-level keys not described by `sections`; write them back to keep them. */\n unknown: JsonObject;\n}\n\n/**\n * Reads `doc` one top-level section at a time: a section that does not parse\n * is reported and replaced by its defaults, every other section is kept. This\n * keeps one bad value (e.g. a renamed enum) from resetting the whole document.\n */\nexport function loadSections<T>(\n doc: unknown,\n sections: SectionSpecs<T>,\n options: LoadSectionsOptions = {},\n): LoadSectionsResult<T> {\n const source = isObject(doc) ? doc : {};\n const ignore = new Set(options.ignore ?? [\"version\"]);\n const value = {} as T;\n const problems: SectionProblem[] = [];\n for (const key of Object.keys(sections) as (keyof T & string)[]) {\n const spec = sections[key];\n const fallback = () =>\n typeof spec.defaults === \"function\"\n ? (spec.defaults as () => T[typeof key])()\n : spec.defaults;\n if (!Object.prototype.hasOwnProperty.call(source, key)) {\n value[key] = fallback();\n continue;\n }\n try {\n const parsed = spec.parse(source[key]);\n if (parsed === undefined) throw new Error(\"invalid value\");\n value[key] = parsed;\n } catch (error) {\n problems.push({\n section: key,\n message: error instanceof Error ? error.message : String(error),\n });\n value[key] = fallback();\n }\n }\n const unknown: JsonObject = {};\n for (const key of Object.keys(source)) {\n if (!(key in sections) && !ignore.has(key)) unknown[key] = source[key];\n }\n return { value, problems, unknown };\n}\n\nexport interface LoadDocumentOptions extends MigrateOptions, LoadSectionsOptions {}\n\nexport interface LoadDocumentResult<T> extends LoadSectionsResult<T> {\n report: LoadReport;\n}\n\n/**\n * `migrateDocument` followed by `loadSections`, with one `LoadReport`\n * (`problems` and `unknownKeys` filled in).\n */\nexport function loadDocument<T>(\n json: unknown,\n sections: SectionSpecs<T>,\n options: LoadDocumentOptions,\n): LoadDocumentResult<T> {\n const { doc, report } = migrateDocument(json, options);\n const ignore = options.ignore ?? [options.versionKey ?? \"version\"];\n const result = loadSections(report.readOnly?.kind === \"invalid\" ? {} : doc, sections, {\n ignore,\n });\n report.problems = result.problems;\n report.unknownKeys = Object.keys(result.unknown);\n return { ...result, report };\n}\n"]}
|