@pixerate/editor 0.154.0 → 0.156.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/dist/animation-editor/index.cjs +60 -61
- package/dist/animation-editor/index.js +5 -6
- package/dist/{brushstrokeRender-YAZVQUXY.cjs → brushstrokeRender-5WANQIG4.cjs} +10 -10
- package/dist/{brushstrokeRender-EUDQTDYS.js → brushstrokeRender-Q4LI22QV.js} +3 -3
- package/dist/canvas/index.cjs +23 -24
- package/dist/canvas/index.js +3 -4
- package/dist/chart/index.cjs +2 -3
- package/dist/chart/index.js +1 -2
- package/dist/{chunk-AGZ47XY2.js → chunk-2N2QPO3H.js} +6 -2
- package/dist/{chunk-NMXPOKF3.js → chunk-45XXVHVG.js} +1 -1
- package/dist/{chunk-FLOGD3QB.js → chunk-6UPGM3JB.js} +2 -2
- package/dist/{chunk-6FUAHCVI.cjs → chunk-7NW46N7I.cjs} +16 -16
- package/dist/{chunk-ORDXMBD4.js → chunk-A5UCR2TO.js} +10 -3
- package/dist/{chunk-PI45JMP7.cjs → chunk-CD7PLU77.cjs} +81 -81
- package/dist/{chunk-LRRCMRSL.cjs → chunk-EBDCRTZI.cjs} +20 -16
- package/dist/{chunk-OLCYQLFE.js → chunk-EL5PAHNP.js} +1 -1
- package/dist/{chunk-PUC43JPT.cjs → chunk-EYVVIZJ3.cjs} +1 -1
- package/dist/{chunk-BXMIBMVG.cjs → chunk-JGKCC5OF.cjs} +65 -58
- package/dist/chunk-M4MIZPQI.cjs +393 -0
- package/dist/{chunk-LIXLD433.cjs → chunk-MHEXLG3M.cjs} +35 -35
- package/dist/chunk-NHLYK3AX.js +393 -0
- package/dist/{chunk-RHXW4TA5.cjs → chunk-QMI5HZWA.cjs} +7 -7
- package/dist/{chunk-XFDQEAOS.cjs → chunk-RQCMSEM5.cjs} +2 -2
- package/dist/{chunk-BCY22GBH.js → chunk-SDHZG5TF.js} +1 -1
- package/dist/{chunk-HVX35M2I.cjs → chunk-WI7QJA7A.cjs} +2 -2
- package/dist/{chunk-UILRJQFD.js → chunk-WNAAWLZ5.js} +1 -1
- package/dist/{chunk-4J4MC3F5.js → chunk-YXOW456B.js} +1 -1
- package/dist/{chunk-Y64YPIFT.js → chunk-ZQWLWDZI.js} +1 -1
- package/dist/diagram/index.cjs +2 -3
- package/dist/diagram/index.js +1 -2
- package/dist/image-editor/controller.d.cts +8 -0
- package/dist/image-editor/controller.d.ts +8 -0
- package/dist/image-editor/editorDocument.d.cts +16 -0
- package/dist/image-editor/editorDocument.d.ts +16 -0
- package/dist/image-editor/index.cjs +787 -737
- package/dist/image-editor/index.d.cts +1 -0
- package/dist/image-editor/index.d.ts +1 -0
- package/dist/image-editor/index.js +56 -6
- package/dist/index.cjs +4 -5
- package/dist/index.js +2 -3
- package/dist/paint/grain.d.cts +7 -0
- package/dist/paint/grain.d.ts +7 -0
- package/dist/paint/index.cjs +3 -3
- package/dist/paint/index.js +2 -2
- package/dist/paint-editor/controller.d.cts +38 -0
- package/dist/paint-editor/controller.d.ts +38 -0
- package/dist/paint-editor/document.d.cts +8 -0
- package/dist/paint-editor/document.d.ts +8 -0
- package/dist/paint-editor/editorDocument.d.cts +17 -0
- package/dist/paint-editor/editorDocument.d.ts +17 -0
- package/dist/paint-editor/index.cjs +476 -273
- package/dist/paint-editor/index.d.cts +1 -0
- package/dist/paint-editor/index.d.ts +1 -0
- package/dist/paint-editor/index.js +216 -13
- package/dist/paint-editor/paper.d.cts +8 -0
- package/dist/paint-editor/paper.d.ts +8 -0
- package/dist/paint-editor/stencils.d.cts +2 -0
- package/dist/paint-editor/stencils.d.ts +2 -0
- package/dist/paint-editor/wet.d.cts +1 -0
- package/dist/paint-editor/wet.d.ts +1 -0
- package/dist/parameters/index.cjs +2 -3
- package/dist/parameters/index.js +1 -2
- package/dist/persistence/assets.d.cts +51 -0
- package/dist/persistence/assets.d.ts +51 -0
- package/dist/persistence/editorDocument.d.cts +12 -0
- package/dist/persistence/editorDocument.d.ts +12 -0
- package/dist/persistence/index.cjs +32 -8
- package/dist/persistence/index.d.cts +1 -0
- package/dist/persistence/index.d.ts +1 -0
- package/dist/persistence/index.js +34 -10
- package/dist/spreadsheet/index.cjs +3 -4
- package/dist/spreadsheet/index.js +2 -3
- package/dist/tokens/index.cjs +3 -4
- package/dist/tokens/index.js +2 -3
- package/dist/vector/index.cjs +952 -953
- package/dist/vector/index.js +5 -6
- package/dist/video-editor/index.cjs +2 -3
- package/dist/video-editor/index.js +1 -2
- package/package.json +1 -1
- package/skills/pixerate-image-editor/SKILL.md +16 -24
- package/skills/pixerate-image-editor/references/smart-objects.md +28 -0
- package/skills/pixerate-paint-editor/SKILL.md +26 -6
- package/dist/chunk-5H2C3QSF.cjs +0 -134
- package/dist/chunk-GNV54DLO.js +0 -134
- package/dist/chunk-L5OWG2NA.cjs +0 -135
- package/dist/chunk-WHKNYFM2.js +0 -135
|
@@ -0,0 +1,393 @@
|
|
|
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; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunk2BSBFBOAcjs = require('./chunk-2BSBFBOA.cjs');
|
|
5
|
+
|
|
6
|
+
// src/persistence/assets.ts
|
|
7
|
+
var EDITOR_ASSET_PREFIX = "pixerate-asset:";
|
|
8
|
+
var REF = /pixerate-asset:[0-9a-z]+-[0-9a-z]+(?:~[0-9]+)?/g;
|
|
9
|
+
var BASE64 = /^[A-Za-z0-9+/=\r\n]+$/;
|
|
10
|
+
function isInlineAsset(value) {
|
|
11
|
+
if (value.startsWith("data:")) return value.length >= 512;
|
|
12
|
+
return value.length >= 4096 && BASE64.test(value);
|
|
13
|
+
}
|
|
14
|
+
function hash53(text) {
|
|
15
|
+
let h1 = 3735928559;
|
|
16
|
+
let h2 = 1103547991;
|
|
17
|
+
for (let i = 0; i < text.length; i++) {
|
|
18
|
+
const c = text.charCodeAt(i);
|
|
19
|
+
h1 = Math.imul(h1 ^ c, 2654435761);
|
|
20
|
+
h2 = Math.imul(h2 ^ c, 1597334677);
|
|
21
|
+
}
|
|
22
|
+
h1 = Math.imul(h1 ^ h1 >>> 16, 2246822507) ^ Math.imul(h2 ^ h2 >>> 13, 3266489909);
|
|
23
|
+
h2 = Math.imul(h2 ^ h2 >>> 16, 2246822507) ^ Math.imul(h1 ^ h1 >>> 13, 3266489909);
|
|
24
|
+
return 4294967296 * (2097151 & h2) + (h1 >>> 0);
|
|
25
|
+
}
|
|
26
|
+
function createEditorAssetRegistry() {
|
|
27
|
+
const byRef = /* @__PURE__ */ new Map();
|
|
28
|
+
const byData = /* @__PURE__ */ new Map();
|
|
29
|
+
return {
|
|
30
|
+
put(data) {
|
|
31
|
+
const known = byData.get(data);
|
|
32
|
+
if (known) return known;
|
|
33
|
+
const base = `${EDITOR_ASSET_PREFIX}${data.length.toString(36)}-${hash53(data).toString(36)}`;
|
|
34
|
+
let ref = base;
|
|
35
|
+
for (let n = 1; byRef.has(ref) && byRef.get(ref) !== data; n++) ref = `${base}~${n}`;
|
|
36
|
+
byRef.set(ref, data);
|
|
37
|
+
byData.set(data, ref);
|
|
38
|
+
return ref;
|
|
39
|
+
},
|
|
40
|
+
get: (ref) => byRef.get(ref),
|
|
41
|
+
has: (ref) => byRef.has(ref),
|
|
42
|
+
set(ref, data) {
|
|
43
|
+
byRef.set(ref, data);
|
|
44
|
+
byData.set(data, ref);
|
|
45
|
+
},
|
|
46
|
+
get size() {
|
|
47
|
+
return byRef.size;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function externalizeAssets(value, registry) {
|
|
52
|
+
const walk = (v) => {
|
|
53
|
+
if (typeof v === "string") return isInlineAsset(v) ? registry.put(v) : v;
|
|
54
|
+
if (Array.isArray(v)) return v.map(walk);
|
|
55
|
+
if (v && typeof v === "object") {
|
|
56
|
+
const out = {};
|
|
57
|
+
for (const [k, x] of Object.entries(v)) out[k] = walk(x);
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
60
|
+
return v;
|
|
61
|
+
};
|
|
62
|
+
return walk(value);
|
|
63
|
+
}
|
|
64
|
+
function collectAssetRefs(value) {
|
|
65
|
+
const text = typeof value === "string" ? value : _nullishCoalesce(JSON.stringify(value), () => ( ""));
|
|
66
|
+
return [...new Set(_nullishCoalesce(text.match(REF), () => ( [])))];
|
|
67
|
+
}
|
|
68
|
+
function internalizeAssets(value, registry) {
|
|
69
|
+
const missing = collectAssetRefs(value).filter((ref) => !registry.has(ref));
|
|
70
|
+
if (missing.length) {
|
|
71
|
+
throw new Error(
|
|
72
|
+
`The document refers to ${missing.length} asset${missing.length === 1 ? "" : "s"} that ${missing.length === 1 ? "is" : "are"} not loaded (${missing.slice(0, 3).join(", ")}${missing.length > 3 ? ", \u2026" : ""}). Pass a document from get_*_document in this session, or open it from storage so its assets are read first.`
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
const walk = (v) => {
|
|
76
|
+
if (typeof v === "string") return v.startsWith(EDITOR_ASSET_PREFIX) && registry.has(v) ? registry.get(v) : v;
|
|
77
|
+
if (Array.isArray(v)) return v.map(walk);
|
|
78
|
+
if (v && typeof v === "object") {
|
|
79
|
+
const out = {};
|
|
80
|
+
for (const [k, x] of Object.entries(v)) out[k] = walk(x);
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
83
|
+
return v;
|
|
84
|
+
};
|
|
85
|
+
return walk(value);
|
|
86
|
+
}
|
|
87
|
+
var persisted = /* @__PURE__ */ new WeakMap();
|
|
88
|
+
var assetKey = (ref, options) => `${_nullishCoalesce(options.prefix, () => ( "pixerate.assets:"))}${ref.slice(EDITOR_ASSET_PREFIX.length)}`;
|
|
89
|
+
async function persistEditorAssets(storage, registry, document, options = {}) {
|
|
90
|
+
const written = _nullishCoalesce(persisted.get(storage), () => ( /* @__PURE__ */ new Set()));
|
|
91
|
+
persisted.set(storage, written);
|
|
92
|
+
for (const ref of collectAssetRefs(document)) {
|
|
93
|
+
const key = assetKey(ref, options);
|
|
94
|
+
if (written.has(key)) continue;
|
|
95
|
+
const data = registry.get(ref);
|
|
96
|
+
if (data === void 0) continue;
|
|
97
|
+
await storage.set(key, data);
|
|
98
|
+
written.add(key);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
async function preloadEditorAssets(storage, registry, document, options = {}) {
|
|
102
|
+
const missing = [];
|
|
103
|
+
for (const ref of collectAssetRefs(document)) {
|
|
104
|
+
if (registry.has(ref)) continue;
|
|
105
|
+
const data = await storage.get(assetKey(ref, options));
|
|
106
|
+
if (data === null) missing.push(ref);
|
|
107
|
+
else registry.set(ref, data);
|
|
108
|
+
}
|
|
109
|
+
return missing;
|
|
110
|
+
}
|
|
111
|
+
function withEditorAssets(storage, registry, options = {}) {
|
|
112
|
+
return {
|
|
113
|
+
kind: storage.kind,
|
|
114
|
+
get available() {
|
|
115
|
+
return storage.available;
|
|
116
|
+
},
|
|
117
|
+
async get(key) {
|
|
118
|
+
const value = await storage.get(key);
|
|
119
|
+
if (value !== null && value.includes(EDITOR_ASSET_PREFIX)) await preloadEditorAssets(storage, registry, value, options);
|
|
120
|
+
return value;
|
|
121
|
+
},
|
|
122
|
+
async set(key, value) {
|
|
123
|
+
if (value.includes(EDITOR_ASSET_PREFIX)) await persistEditorAssets(storage, registry, value, options);
|
|
124
|
+
await storage.set(key, value);
|
|
125
|
+
},
|
|
126
|
+
remove: (key) => storage.remove(key)
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// src/persistence/migrate.ts
|
|
131
|
+
function hasLoadProblems(report) {
|
|
132
|
+
return report.problems.length > 0 || report.readOnly !== null;
|
|
133
|
+
}
|
|
134
|
+
function createLoadReport(partial = {}) {
|
|
135
|
+
return {
|
|
136
|
+
migratedFrom: null,
|
|
137
|
+
version: null,
|
|
138
|
+
problems: [],
|
|
139
|
+
readOnly: null,
|
|
140
|
+
unknownKeys: [],
|
|
141
|
+
...partial
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
145
|
+
var deepClone = (value) => typeof structuredClone === "function" ? structuredClone(value) : JSON.parse(JSON.stringify(value));
|
|
146
|
+
function toObject(json) {
|
|
147
|
+
let value = json;
|
|
148
|
+
if (typeof json === "string") {
|
|
149
|
+
try {
|
|
150
|
+
value = JSON.parse(json);
|
|
151
|
+
} catch (e) {
|
|
152
|
+
return void 0;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return isObject(value) ? _chunk2BSBFBOAcjs.stripPrototypeKeys.call(void 0, deepClone(value)) : void 0;
|
|
156
|
+
}
|
|
157
|
+
function migrateDocument(json, options) {
|
|
158
|
+
const versionKey = _nullishCoalesce(options.versionKey, () => ( "version"));
|
|
159
|
+
const target = options.currentVersion;
|
|
160
|
+
const original = toObject(json);
|
|
161
|
+
if (!original) {
|
|
162
|
+
return {
|
|
163
|
+
doc: { [versionKey]: target },
|
|
164
|
+
report: createLoadReport({
|
|
165
|
+
readOnly: { kind: "invalid", message: "document is not a JSON object" }
|
|
166
|
+
})
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
const raw = original[versionKey];
|
|
170
|
+
const found = typeof raw === "number" && Number.isInteger(raw) && raw >= 0 ? raw : null;
|
|
171
|
+
const from = _nullishCoalesce(_nullishCoalesce(found, () => ( options.missingVersion)), () => ( target));
|
|
172
|
+
const report = createLoadReport({ version: found });
|
|
173
|
+
if (from > target) {
|
|
174
|
+
report.readOnly = {
|
|
175
|
+
kind: "newerVersion",
|
|
176
|
+
version: from,
|
|
177
|
+
supported: target,
|
|
178
|
+
message: `document has version ${from}, newer than the supported ${target}`
|
|
179
|
+
};
|
|
180
|
+
return { doc: original, report };
|
|
181
|
+
}
|
|
182
|
+
if (from === target) {
|
|
183
|
+
original[versionKey] = target;
|
|
184
|
+
return { doc: original, report };
|
|
185
|
+
}
|
|
186
|
+
let doc = deepClone(original);
|
|
187
|
+
for (let step = from; step < target; step++) {
|
|
188
|
+
const fn = _optionalChain([options, 'access', _ => _.steps, 'optionalAccess', _2 => _2[step]]);
|
|
189
|
+
if (!fn) {
|
|
190
|
+
report.readOnly = {
|
|
191
|
+
kind: "migrationFailed",
|
|
192
|
+
from: step,
|
|
193
|
+
message: `no migration step from version ${step}`
|
|
194
|
+
};
|
|
195
|
+
return { doc: original, report };
|
|
196
|
+
}
|
|
197
|
+
try {
|
|
198
|
+
doc = _nullishCoalesce(fn(doc), () => ( doc));
|
|
199
|
+
} catch (error) {
|
|
200
|
+
report.readOnly = {
|
|
201
|
+
kind: "migrationFailed",
|
|
202
|
+
from: step,
|
|
203
|
+
message: `migration from version ${step} failed: ${error instanceof Error ? error.message : String(error)}`
|
|
204
|
+
};
|
|
205
|
+
return { doc: original, report };
|
|
206
|
+
}
|
|
207
|
+
doc[versionKey] = step + 1;
|
|
208
|
+
}
|
|
209
|
+
report.migratedFrom = from;
|
|
210
|
+
return { doc, report };
|
|
211
|
+
}
|
|
212
|
+
function loadSections(doc, sections, options = {}) {
|
|
213
|
+
const source = isObject(doc) ? doc : {};
|
|
214
|
+
const ignore = new Set(_nullishCoalesce(options.ignore, () => ( ["version"])));
|
|
215
|
+
const value = {};
|
|
216
|
+
const problems = [];
|
|
217
|
+
for (const key of Object.keys(sections)) {
|
|
218
|
+
const spec = sections[key];
|
|
219
|
+
const fallback = () => typeof spec.defaults === "function" ? spec.defaults() : spec.defaults;
|
|
220
|
+
if (!Object.prototype.hasOwnProperty.call(source, key)) {
|
|
221
|
+
value[key] = fallback();
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
try {
|
|
225
|
+
const parsed = spec.parse(source[key]);
|
|
226
|
+
if (parsed === void 0) throw new Error("invalid value");
|
|
227
|
+
value[key] = parsed;
|
|
228
|
+
} catch (error) {
|
|
229
|
+
problems.push({
|
|
230
|
+
section: key,
|
|
231
|
+
message: error instanceof Error ? error.message : String(error)
|
|
232
|
+
});
|
|
233
|
+
value[key] = fallback();
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
const unknown = {};
|
|
237
|
+
for (const key of Object.keys(source)) {
|
|
238
|
+
if (!(key in sections) && !ignore.has(key) && !_chunk2BSBFBOAcjs.isUnsafeJsonKey.call(void 0, key)) unknown[key] = source[key];
|
|
239
|
+
}
|
|
240
|
+
return { value, problems, unknown };
|
|
241
|
+
}
|
|
242
|
+
function loadDocument(json, sections, options) {
|
|
243
|
+
const { doc, report } = migrateDocument(json, options);
|
|
244
|
+
const ignore = _nullishCoalesce(options.ignore, () => ( [_nullishCoalesce(options.versionKey, () => ( "version"))]));
|
|
245
|
+
const result = loadSections(_optionalChain([report, 'access', _3 => _3.readOnly, 'optionalAccess', _4 => _4.kind]) === "invalid" ? {} : doc, sections, {
|
|
246
|
+
ignore
|
|
247
|
+
});
|
|
248
|
+
report.problems = result.problems;
|
|
249
|
+
report.unknownKeys = Object.keys(result.unknown);
|
|
250
|
+
return { ...result, report };
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// src/persistence/editorDocument.ts
|
|
254
|
+
var EditorDocumentLoadError = class extends Error {
|
|
255
|
+
/** The `LoadReport` when the input was a file that could not be migrated. */
|
|
256
|
+
|
|
257
|
+
constructor(message, report) {
|
|
258
|
+
super(message);
|
|
259
|
+
this.name = "EditorDocumentLoadError";
|
|
260
|
+
this.report = report;
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
var EDITOR_DOCUMENT_FORMAT = "pixerate.editor-document";
|
|
264
|
+
var KIND = /^[a-z][a-z0-9_]*$/;
|
|
265
|
+
function isEditorDocumentFile(value) {
|
|
266
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
267
|
+
const v = value;
|
|
268
|
+
return v.format === EDITOR_DOCUMENT_FORMAT && typeof v.kind === "string" && typeof v.formatVersion === "number" && "document" in v;
|
|
269
|
+
}
|
|
270
|
+
function toEditorDocumentFile(doc, name) {
|
|
271
|
+
return {
|
|
272
|
+
format: EDITOR_DOCUMENT_FORMAT,
|
|
273
|
+
kind: doc.kind,
|
|
274
|
+
formatVersion: doc.formatVersion,
|
|
275
|
+
...name ? { name } : {},
|
|
276
|
+
document: doc.getDocument()
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
function serializeEditorDocument(doc, options = {}) {
|
|
280
|
+
return JSON.stringify(toEditorDocumentFile(doc, options.name), null, options.space);
|
|
281
|
+
}
|
|
282
|
+
function parseEditorDocument(text, options = {}) {
|
|
283
|
+
let value;
|
|
284
|
+
try {
|
|
285
|
+
value = _chunk2BSBFBOAcjs.stripPrototypeKeys.call(void 0, JSON.parse(text));
|
|
286
|
+
} catch (error) {
|
|
287
|
+
throw new EditorDocumentLoadError(`The file is not valid JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
288
|
+
}
|
|
289
|
+
if (!isEditorDocumentFile(value)) {
|
|
290
|
+
throw new EditorDocumentLoadError(`The file is not a saved editor document (expected "format": "${EDITOR_DOCUMENT_FORMAT}").`);
|
|
291
|
+
}
|
|
292
|
+
if (options.kind && value.kind !== options.kind) {
|
|
293
|
+
throw new EditorDocumentLoadError(`The file is a ${value.kind} document, not a ${options.kind} document.`);
|
|
294
|
+
}
|
|
295
|
+
return value;
|
|
296
|
+
}
|
|
297
|
+
function defineEditorDocument(spec) {
|
|
298
|
+
if (!KIND.test(spec.kind)) throw new Error(`Editor document kind "${spec.kind}" must match ${KIND}.`);
|
|
299
|
+
const formatVersion = _nullishCoalesce(spec.formatVersion, () => ( 1));
|
|
300
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
301
|
+
let revision = 0;
|
|
302
|
+
let unsubscribe = null;
|
|
303
|
+
let connected = false;
|
|
304
|
+
const connect = () => {
|
|
305
|
+
if (unsubscribe) return;
|
|
306
|
+
if (connected) revision++;
|
|
307
|
+
connected = true;
|
|
308
|
+
unsubscribe = spec.subscribe(() => {
|
|
309
|
+
revision++;
|
|
310
|
+
listeners.forEach((listener) => {
|
|
311
|
+
try {
|
|
312
|
+
listener();
|
|
313
|
+
} catch (error) {
|
|
314
|
+
console.error(`[${spec.kind} document] Error in change listener:`, error);
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
};
|
|
319
|
+
connect();
|
|
320
|
+
const unwrap = (input) => {
|
|
321
|
+
if (!isEditorDocumentFile(input)) return { document: input, report: createLoadReport({ version: formatVersion }) };
|
|
322
|
+
if (input.kind !== spec.kind) throw new EditorDocumentLoadError(`This is a ${input.kind} document; it cannot be opened in the ${spec.kind} editor.`);
|
|
323
|
+
const steps = Object.fromEntries(
|
|
324
|
+
Object.entries(_nullishCoalesce(spec.migrations, () => ( {}))).map(([v, step]) => [v, (w) => ({ ...w, document: step(w.document) })])
|
|
325
|
+
);
|
|
326
|
+
const { doc, report } = migrateDocument(
|
|
327
|
+
{ formatVersion: input.formatVersion, document: input.document },
|
|
328
|
+
{ currentVersion: formatVersion, versionKey: "formatVersion", steps }
|
|
329
|
+
);
|
|
330
|
+
if (report.readOnly) throw new EditorDocumentLoadError(`Cannot open the ${spec.kind} document: ${report.readOnly.message}.`, report);
|
|
331
|
+
return { document: doc.document, report };
|
|
332
|
+
};
|
|
333
|
+
return {
|
|
334
|
+
kind: spec.kind,
|
|
335
|
+
formatVersion,
|
|
336
|
+
recordsLoads: spec.recordsLoads !== false,
|
|
337
|
+
getDocument: () => spec.assets ? externalizeAssets(spec.get(), spec.assets) : spec.get(),
|
|
338
|
+
loadDocument(input, options = {}) {
|
|
339
|
+
const { document, report } = unwrap(input);
|
|
340
|
+
if (document === void 0 || document === null) throw new EditorDocumentLoadError(`No ${spec.kind} document was given.`);
|
|
341
|
+
try {
|
|
342
|
+
const result = spec.load(spec.assets ? internalizeAssets(document, spec.assets) : document, { history: _nullishCoalesce(options.history, () => ( "reset")) });
|
|
343
|
+
if (_optionalChain([result, 'optionalAccess', _5 => _5.problems, 'optionalAccess', _6 => _6.length])) report.problems.push(...result.problems);
|
|
344
|
+
} catch (error) {
|
|
345
|
+
if (error instanceof EditorDocumentLoadError) throw error;
|
|
346
|
+
throw new EditorDocumentLoadError(error instanceof Error ? error.message : String(error));
|
|
347
|
+
}
|
|
348
|
+
return report;
|
|
349
|
+
},
|
|
350
|
+
revision: () => {
|
|
351
|
+
connect();
|
|
352
|
+
return revision;
|
|
353
|
+
},
|
|
354
|
+
subscribe(listener) {
|
|
355
|
+
connect();
|
|
356
|
+
listeners.add(listener);
|
|
357
|
+
return () => {
|
|
358
|
+
listeners.delete(listener);
|
|
359
|
+
};
|
|
360
|
+
},
|
|
361
|
+
history: spec.history,
|
|
362
|
+
...spec.assets ? { assets: spec.assets } : {},
|
|
363
|
+
readOnly: () => _nullishCoalesce(_optionalChain([spec, 'access', _7 => _7.readOnly, 'optionalCall', _8 => _8()]), () => ( false)),
|
|
364
|
+
destroy() {
|
|
365
|
+
_optionalChain([unsubscribe, 'optionalCall', _9 => _9()]);
|
|
366
|
+
unsubscribe = null;
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
exports.EDITOR_ASSET_PREFIX = EDITOR_ASSET_PREFIX; exports.isInlineAsset = isInlineAsset; exports.createEditorAssetRegistry = createEditorAssetRegistry; exports.externalizeAssets = externalizeAssets; exports.collectAssetRefs = collectAssetRefs; exports.internalizeAssets = internalizeAssets; exports.persistEditorAssets = persistEditorAssets; exports.preloadEditorAssets = preloadEditorAssets; exports.withEditorAssets = withEditorAssets; exports.hasLoadProblems = hasLoadProblems; exports.createLoadReport = createLoadReport; exports.migrateDocument = migrateDocument; exports.loadSections = loadSections; exports.loadDocument = loadDocument; exports.EditorDocumentLoadError = EditorDocumentLoadError; exports.EDITOR_DOCUMENT_FORMAT = EDITOR_DOCUMENT_FORMAT; exports.isEditorDocumentFile = isEditorDocumentFile; exports.toEditorDocumentFile = toEditorDocumentFile; exports.serializeEditorDocument = serializeEditorDocument; exports.parseEditorDocument = parseEditorDocument; exports.defineEditorDocument = defineEditorDocument;
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
var
|
|
21
|
+
var _chunkQMI5HZWAcjs = require('./chunk-QMI5HZWA.cjs');
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
|
|
@@ -37,7 +37,7 @@ var lerpP = (a, b, t) => [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t];
|
|
|
37
37
|
var toP = (v) => [v.x, v.y];
|
|
38
38
|
var mapP = (m, p) => [m[0] * p[0] + m[2] * p[1] + m[4], m[1] * p[0] + m[3] * p[1] + m[5]];
|
|
39
39
|
var curvesOf = (c) => Math.max(0, (c.pts.length - 1) / 3) | 0;
|
|
40
|
-
function subpathToMorphContour(sp, m =
|
|
40
|
+
function subpathToMorphContour(sp, m = _chunkQMI5HZWAcjs.IDENTITY_MATRIX) {
|
|
41
41
|
const n = sp.anchors.length;
|
|
42
42
|
if (!n) return null;
|
|
43
43
|
const first = mapP(m, toP(sp.anchors[0]));
|
|
@@ -67,8 +67,8 @@ function isStraight(p0, p1, p2, p3) {
|
|
|
67
67
|
const u2 = along(p2);
|
|
68
68
|
return off(p1) < tol && off(p2) < tol && u1 >= -1e-9 && u1 <= 1 + 1e-9 && u2 >= -1e-9 && u2 <= 1 + 1e-9;
|
|
69
69
|
}
|
|
70
|
-
function morphContourToSubpath(c, m =
|
|
71
|
-
const pts =
|
|
70
|
+
function morphContourToSubpath(c, m = _chunkQMI5HZWAcjs.IDENTITY_MATRIX, closed = c.closed) {
|
|
71
|
+
const pts = _chunkQMI5HZWAcjs.isIdentityMatrix.call(void 0, m) ? c.pts : c.pts.map((p) => mapP(m, p));
|
|
72
72
|
const curves = curvesOf(c);
|
|
73
73
|
const dropLast = closed && c.closed && curves > 0;
|
|
74
74
|
const count = dropLast ? curves : curves + 1;
|
|
@@ -84,7 +84,7 @@ function morphContourToSubpath(c, m = _chunkRHXW4TA5cjs.IDENTITY_MATRIX, closed
|
|
|
84
84
|
anchors[(k + 1) % count].in = { x: p2[0], y: p2[1] };
|
|
85
85
|
}
|
|
86
86
|
for (const a of anchors) {
|
|
87
|
-
const type =
|
|
87
|
+
const type = _chunkQMI5HZWAcjs.inferAnchorType.call(void 0, a);
|
|
88
88
|
if (type !== "corner") a.type = type;
|
|
89
89
|
}
|
|
90
90
|
const isClosed = closed && curves > 0;
|
|
@@ -267,7 +267,7 @@ function bestStart(fixed, free, useShapeContext) {
|
|
|
267
267
|
return best;
|
|
268
268
|
}
|
|
269
269
|
function placeIn(c, from, to) {
|
|
270
|
-
const b =
|
|
270
|
+
const b = _chunkQMI5HZWAcjs.unionBounds.call(void 0, [boundsOfPoints(c.pts)]);
|
|
271
271
|
const p = b ? [b.x + b.width / 2, b.y + b.height / 2] : c.pts[0];
|
|
272
272
|
if (!from || !to) return p;
|
|
273
273
|
const fx = from.width > 0 ? (p[0] - from.x) / from.width : 0.5;
|
|
@@ -456,7 +456,7 @@ function interpolateVectorColor(a, b, t) {
|
|
|
456
456
|
}
|
|
457
457
|
function resampleGradientStops(g, offsets) {
|
|
458
458
|
return offsets.map((offset) => {
|
|
459
|
-
const s =
|
|
459
|
+
const s = _chunkQMI5HZWAcjs.sampleVectorGradient.call(void 0, g, offset);
|
|
460
460
|
return s.opacity < 1 ? { offset, color: s.color, opacity: Math.round(s.opacity * 1e4) / 1e4 } : { offset, color: s.color };
|
|
461
461
|
});
|
|
462
462
|
}
|
|
@@ -467,11 +467,11 @@ function lerpAngle(a, b, t) {
|
|
|
467
467
|
var lerpPoint = (a, b, t) => ({ x: lerpN(a.x, b.x, t), y: lerpN(a.y, b.y, t) });
|
|
468
468
|
var sameColourModel = (a, b) => (_nullishCoalesce(a.interpolation, () => ( "srgb"))) === (_nullishCoalesce(b.interpolation, () => ( "srgb"))) && (_nullishCoalesce(a.smoothness, () => ( 0))) === (_nullishCoalesce(b.smoothness, () => ( 0)));
|
|
469
469
|
function lerpStops(a, b, t) {
|
|
470
|
-
let stopsA =
|
|
471
|
-
let stopsB =
|
|
470
|
+
let stopsA = _chunkQMI5HZWAcjs.sortedVectorGradientStops.call(void 0, a);
|
|
471
|
+
let stopsB = _chunkQMI5HZWAcjs.sortedVectorGradientStops.call(void 0, b);
|
|
472
472
|
const resampled = stopsA.length !== stopsB.length || !sameColourModel(a, b);
|
|
473
473
|
if (resampled) {
|
|
474
|
-
const offs = [...
|
|
474
|
+
const offs = [..._chunkQMI5HZWAcjs.expandVectorGradientStops.call(void 0, a), ..._chunkQMI5HZWAcjs.expandVectorGradientStops.call(void 0, b), ...stopsA, ...stopsB].map((s) => s.offset).filter(Number.isFinite).sort((x, y) => x - y);
|
|
475
475
|
const common = offs.filter((o, i) => i === 0 || o - offs[i - 1] > 1e-4);
|
|
476
476
|
stopsA = resampleGradientStops(a, common);
|
|
477
477
|
stopsB = resampleGradientStops(b, common);
|
|
@@ -498,8 +498,8 @@ function lerpGradient(a, b, t) {
|
|
|
498
498
|
}
|
|
499
499
|
if (near.spread && near.spread !== "pad") out.spread = near.spread;
|
|
500
500
|
if (near.strokeMode && near.strokeMode !== "within") out.strokeMode = near.strokeMode;
|
|
501
|
-
const ea =
|
|
502
|
-
const eb =
|
|
501
|
+
const ea = _chunkQMI5HZWAcjs.hasExplicitGradientGeometry.call(void 0, a);
|
|
502
|
+
const eb = _chunkQMI5HZWAcjs.hasExplicitGradientGeometry.call(void 0, b);
|
|
503
503
|
if (!ea && !eb) {
|
|
504
504
|
if (a.angle !== void 0 || b.angle !== void 0 || a.type === "linear" || a.type === "reflected") {
|
|
505
505
|
const fallback = a.type === "linear" || a.type === "reflected" ? 180 : 90;
|
|
@@ -512,10 +512,10 @@ function lerpGradient(a, b, t) {
|
|
|
512
512
|
}
|
|
513
513
|
return out;
|
|
514
514
|
}
|
|
515
|
-
const pa =
|
|
516
|
-
const pb =
|
|
515
|
+
const pa = _chunkQMI5HZWAcjs.vectorGradientPoints.call(void 0, a);
|
|
516
|
+
const pb = _chunkQMI5HZWAcjs.vectorGradientPoints.call(void 0, b);
|
|
517
517
|
if (pa.units !== pb.units) {
|
|
518
|
-
const src =
|
|
518
|
+
const src = _chunkQMI5HZWAcjs.explicitVectorGradient.call(void 0, near);
|
|
519
519
|
return { ...src, stops: out.stops, ...out.interpolation ? { interpolation: out.interpolation } : {}, ...out.smoothness ? { smoothness: out.smoothness } : {} };
|
|
520
520
|
}
|
|
521
521
|
out.start = lerpPoint(pa.start, pb.start, t);
|
|
@@ -535,14 +535,14 @@ function solidLike(color, like) {
|
|
|
535
535
|
function interpolateVectorPaint(a, b, t) {
|
|
536
536
|
if (t <= 0) return a;
|
|
537
537
|
if (t >= 1) return b;
|
|
538
|
-
const pa =
|
|
539
|
-
const pb =
|
|
538
|
+
const pa = _chunkQMI5HZWAcjs.hasPaint.call(void 0, a);
|
|
539
|
+
const pb = _chunkQMI5HZWAcjs.hasPaint.call(void 0, b);
|
|
540
540
|
if (!pa && !pb) return t < 0.5 ? a : b;
|
|
541
541
|
if (typeof a === "string" && pa && typeof b === "string" && pb) return interpolateVectorColor(a, b, t);
|
|
542
542
|
if (!pa && typeof b === "string") return interpolateVectorColor("transparent", b, t);
|
|
543
543
|
if (!pb && typeof a === "string") return interpolateVectorColor(a, "transparent", t);
|
|
544
|
-
const ga = pa &&
|
|
545
|
-
const gb = pb &&
|
|
544
|
+
const ga = pa && _chunkQMI5HZWAcjs.isVectorGradient.call(void 0, a) ? a : null;
|
|
545
|
+
const gb = pb && _chunkQMI5HZWAcjs.isVectorGradient.call(void 0, b) ? b : null;
|
|
546
546
|
if (ga && gb) return _nullishCoalesce(lerpGradient(ga, gb, t), () => ( (t < 0.5 ? a : b)));
|
|
547
547
|
if (gb) return _nullishCoalesce(lerpGradient(solidLike(pa ? a : null, gb), gb, t), () => ( b));
|
|
548
548
|
if (ga) return _nullishCoalesce(lerpGradient(ga, solidLike(pb ? b : null, ga), t), () => ( a));
|
|
@@ -553,8 +553,8 @@ function interpolateWidthProfiles(a, b, t) {
|
|
|
553
553
|
const at = [..._nullishCoalesce(a, () => ( [])), ..._nullishCoalesce(b, () => ( [])), { t: 0 }, { t: 1 }].map((p) => p.t).sort((x, y) => x - y);
|
|
554
554
|
const ts = at.filter((v, i) => i === 0 || v - at[i - 1] > 1e-6);
|
|
555
555
|
return ts.map((pos) => {
|
|
556
|
-
const x =
|
|
557
|
-
const y =
|
|
556
|
+
const x = _chunkQMI5HZWAcjs.widthProfileAt.call(void 0, a, pos);
|
|
557
|
+
const y = _chunkQMI5HZWAcjs.widthProfileAt.call(void 0, b, pos);
|
|
558
558
|
return { t: pos, left: lerpN(x.left, y.left, t), right: lerpN(x.right, y.right, t) };
|
|
559
559
|
});
|
|
560
560
|
}
|
|
@@ -597,7 +597,7 @@ function reversedStyle(s) {
|
|
|
597
597
|
out.endArrow = s.startArrow;
|
|
598
598
|
out.startArrowScale = s.endArrowScale;
|
|
599
599
|
out.endArrowScale = s.startArrowScale;
|
|
600
|
-
if (_optionalChain([s, 'access', _6 => _6.strokeWidthProfile, 'optionalAccess', _7 => _7.length])) out.strokeWidthProfile =
|
|
600
|
+
if (_optionalChain([s, 'access', _6 => _6.strokeWidthProfile, 'optionalAccess', _7 => _7.length])) out.strokeWidthProfile = _chunkQMI5HZWAcjs.reverseWidthProfile.call(void 0, s.strokeWidthProfile);
|
|
601
601
|
for (const k of ["startArrow", "endArrow", "startArrowScale", "endArrowScale"]) if (out[k] === void 0) delete out[k];
|
|
602
602
|
return out;
|
|
603
603
|
}
|
|
@@ -623,19 +623,19 @@ function styleOf(n) {
|
|
|
623
623
|
return out;
|
|
624
624
|
}
|
|
625
625
|
function contoursOf(node, m) {
|
|
626
|
-
return
|
|
626
|
+
return _chunkQMI5HZWAcjs.expandVectorCorners.call(void 0, node.subpaths).map((sp) => subpathToMorphContour(sp, m)).filter((c) => !!c);
|
|
627
627
|
}
|
|
628
|
-
function preparePathMorph(a, b, options, ma =
|
|
628
|
+
function preparePathMorph(a, b, options, ma = _chunkQMI5HZWAcjs.nodeMatrix.call(void 0, a), mb = _chunkQMI5HZWAcjs.nodeMatrix.call(void 0, b)) {
|
|
629
629
|
const corr = correspondMorphContours(contoursOf(a, ma), contoursOf(b, mb), options);
|
|
630
630
|
const sim = procrustes(corr.a, corr.b);
|
|
631
631
|
const styleA = styleOf(a);
|
|
632
632
|
const styleB = corr.reversed ? reversedStyle(styleOf(b)) : styleOf(b);
|
|
633
|
-
const rigid = !
|
|
633
|
+
const rigid = !_chunkQMI5HZWAcjs.isIdentityMatrix.call(void 0, ma) || !_chunkQMI5HZWAcjs.isIdentityMatrix.call(void 0, mb);
|
|
634
634
|
const id = _nullishCoalesce(options.id, () => ( a.id));
|
|
635
635
|
return (t) => {
|
|
636
636
|
const contours = interpolateMorphContours(corr.a, corr.b, t, { linear: options.linear, rigidity: options.rigidity, similarity: sim });
|
|
637
|
-
const m = rigid ? interpolateRigidMatrix(ma, mb, t) :
|
|
638
|
-
const back = rigid ?
|
|
637
|
+
const m = rigid ? interpolateRigidMatrix(ma, mb, t) : _chunkQMI5HZWAcjs.IDENTITY_MATRIX;
|
|
638
|
+
const back = rigid ? _chunkQMI5HZWAcjs.invertMatrix.call(void 0, m) : _chunkQMI5HZWAcjs.IDENTITY_MATRIX;
|
|
639
639
|
const subpaths = contours.map((c, k) => {
|
|
640
640
|
const closed = t <= 0 ? corr.a[k].closed : t >= 1 ? corr.b[k].closed : corr.a[k].closed && corr.b[k].closed;
|
|
641
641
|
return morphContourToSubpath({ closed: corr.a[k].closed && corr.b[k].closed, pts: c.pts }, back, closed);
|
|
@@ -643,14 +643,14 @@ function preparePathMorph(a, b, options, ma = _chunkRHXW4TA5cjs.nodeMatrix.call(
|
|
|
643
643
|
const node = { id, type: "path", subpaths, ...interpolateVectorStyle(styleA, styleB, t) };
|
|
644
644
|
const opacity = lerpN(_nullishCoalesce(a.opacity, () => ( 1)), _nullishCoalesce(b.opacity, () => ( 1)), t);
|
|
645
645
|
if (opacity < 1) node.opacity = opacity;
|
|
646
|
-
if (rigid && !
|
|
646
|
+
if (rigid && !_chunkQMI5HZWAcjs.isIdentityMatrix.call(void 0, m)) node.transform = m;
|
|
647
647
|
return node;
|
|
648
648
|
};
|
|
649
649
|
}
|
|
650
|
-
function flattenPaths(node, parent =
|
|
651
|
-
const m =
|
|
650
|
+
function flattenPaths(node, parent = _chunkQMI5HZWAcjs.IDENTITY_MATRIX) {
|
|
651
|
+
const m = _chunkQMI5HZWAcjs.multiplyMatrices.call(void 0, _chunkQMI5HZWAcjs.nodeMatrix.call(void 0, node), parent);
|
|
652
652
|
if (node.type === "path") return [{ path: node, m, opacity: 1 }];
|
|
653
|
-
if (node.type === "text" || node.type === "instance") return flattenPaths(
|
|
653
|
+
if (node.type === "text" || node.type === "instance") return flattenPaths(_chunkQMI5HZWAcjs.expandVectorAppearance.call(void 0, node), parent);
|
|
654
654
|
const o = _nullishCoalesce(node.opacity, () => ( 1));
|
|
655
655
|
return node.children.filter((c) => c.visible !== false).flatMap((c) => flattenPaths(c, m)).map((e) => ({ ...e, opacity: e.opacity * o }));
|
|
656
656
|
}
|
|
@@ -672,8 +672,8 @@ function createVectorMorph(a, b, options = {}) {
|
|
|
672
672
|
}
|
|
673
673
|
const pa = flattenPaths(a);
|
|
674
674
|
const pb = flattenPaths(b);
|
|
675
|
-
const ba =
|
|
676
|
-
const bb =
|
|
675
|
+
const ba = _chunkQMI5HZWAcjs.unionBounds.call(void 0, pa.map((e) => placedBounds(e.path, e.m)));
|
|
676
|
+
const bb = _chunkQMI5HZWAcjs.unionBounds.call(void 0, pb.map((e) => placedBounds(e.path, e.m)));
|
|
677
677
|
const id = _nullishCoalesce(options.id, () => ( a.id));
|
|
678
678
|
const parts = [];
|
|
679
679
|
const opacities = [];
|
|
@@ -685,10 +685,10 @@ function createVectorMorph(a, b, options = {}) {
|
|
|
685
685
|
parts.push(preparePathMorph(x.path, y.path, sub, x.m, y.m));
|
|
686
686
|
opacities.push([x.opacity, y.opacity]);
|
|
687
687
|
} else if (x) {
|
|
688
|
-
parts.push(preparePathMorph(x.path, collapsedPath(x.path, x.m, ba, bb), sub, x.m,
|
|
688
|
+
parts.push(preparePathMorph(x.path, collapsedPath(x.path, x.m, ba, bb), sub, x.m, _chunkQMI5HZWAcjs.IDENTITY_MATRIX));
|
|
689
689
|
opacities.push([x.opacity, x.opacity]);
|
|
690
690
|
} else if (y) {
|
|
691
|
-
parts.push(preparePathMorph(collapsedPath(y.path, y.m, bb, ba), y.path, sub,
|
|
691
|
+
parts.push(preparePathMorph(collapsedPath(y.path, y.m, bb, ba), y.path, sub, _chunkQMI5HZWAcjs.IDENTITY_MATRIX, y.m));
|
|
692
692
|
opacities.push([y.opacity, y.opacity]);
|
|
693
693
|
}
|
|
694
694
|
}
|