@nodetool-ai/image-editor 0.8.5 → 0.8.6

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.
@@ -0,0 +1,211 @@
1
+ /**
2
+ * One-shot compositing of a whole sketch document, for hosts without the
3
+ * live editor: the headless renderer behind `render_sketch` and
4
+ * `nodetool sketch render`.
5
+ *
6
+ * It does what the editor does across its hydration hook and Canvas2D
7
+ * runtime, in one pass: each layer's raster is decoded into a surface the
8
+ * size of its stored bounds (an image reference is fitted into it), then the
9
+ * stack is composited with the shared draw rules in `compose.ts`. The result
10
+ * is what the editor's PNG export produces for the same document.
11
+ *
12
+ * Decoding image bytes is the host's job, so this module stays free of any
13
+ * canvas library and of storage access.
14
+ */
15
+ import { decodeSketchLayerData } from "@nodetool-ai/protocol/api-schemas/sketch.js";
16
+ import { computeCompositeOffset, drawWithTransform, getAncestorGroupOpacityProduct, hasEnabledEffects, isLayerCompositeVisible, layerEffectsFilter, fitImageRect } from "./compose.js";
17
+ import { normalizeRenderDocument } from "./normalize.js";
18
+ function roundBounds(bounds) {
19
+ return {
20
+ x: Math.round(bounds.x),
21
+ y: Math.round(bounds.y),
22
+ width: Math.max(1, Math.round(bounds.width)),
23
+ height: Math.max(1, Math.round(bounds.height))
24
+ };
25
+ }
26
+ function describeError(error) {
27
+ const message = error instanceof Error ? error.message : String(error);
28
+ return message.trim() || "it failed with no message";
29
+ }
30
+ function context2d(surface) {
31
+ const ctx = surface.getContext("2d");
32
+ if (!ctx) {
33
+ throw new Error("The host canvas returned no 2D context.");
34
+ }
35
+ return ctx;
36
+ }
37
+ /**
38
+ * Decode one layer into a surface, the way the editor hydrates it: the
39
+ * layer's own serialized raster wins, else its image reference is fitted
40
+ * into the layer's content bounds.
41
+ */
42
+ async function hydrateLayer(layer, host) {
43
+ const fallback = roundBounds({
44
+ x: layer.contentBounds.x,
45
+ y: layer.contentBounds.y,
46
+ width: Math.max(1, layer.contentBounds.width),
47
+ height: Math.max(1, layer.contentBounds.height)
48
+ });
49
+ const source = layer.data || layer.imageReference?.uri || null;
50
+ const fit = layer.data ? undefined : layer.imageReference?.objectFit;
51
+ const decoded = decodeSketchLayerData(source, fallback.width, fallback.height);
52
+ const bounds = roundBounds(source && source.startsWith("ntlayer:")
53
+ ? decoded.bounds
54
+ : { ...fallback });
55
+ const surface = host.createSurface(bounds.width, bounds.height);
56
+ const empty = { hydrated: { surface, bounds, vectorSource: null } };
57
+ if (!decoded.image) {
58
+ return empty;
59
+ }
60
+ let image;
61
+ try {
62
+ image = await host.loadImage(decoded.image);
63
+ }
64
+ catch (error) {
65
+ return { ...empty, issue: `its image could not be loaded: ${describeError(error)}` };
66
+ }
67
+ const rect = fitImageRect(image.width, image.height, bounds.width, bounds.height, fit);
68
+ context2d(surface).drawImage(image, rect.x, rect.y, rect.width, rect.height);
69
+ if (layer.type !== "vector" || !decoded.image.startsWith("data:image/svg+xml")) {
70
+ return { hydrated: { surface, bounds, vectorSource: null } };
71
+ }
72
+ const scale = vectorScale(layer);
73
+ if (scale <= 1 || !host.loadVectorImage) {
74
+ return { hydrated: { surface, bounds, vectorSource: image } };
75
+ }
76
+ try {
77
+ const sharp = await host.loadVectorImage(decoded.image, Math.ceil(bounds.width * scale), Math.ceil(bounds.height * scale));
78
+ return { hydrated: { surface, bounds, vectorSource: sharp } };
79
+ }
80
+ catch {
81
+ // The stored-size image still draws, only softer.
82
+ return { hydrated: { surface, bounds, vectorSource: image } };
83
+ }
84
+ }
85
+ /** Largest supersampling a vector layer is redrawn at. */
86
+ const MAX_VECTOR_SCALE = 8;
87
+ /** How much a vector layer's transform magnifies it, capped. */
88
+ function vectorScale(layer) {
89
+ if (layer.transform.kind !== "affine") {
90
+ return 1;
91
+ }
92
+ const scale = Math.max(Math.abs(layer.transform.scaleX), Math.abs(layer.transform.scaleY));
93
+ return Number.isFinite(scale) ? Math.min(scale, MAX_VECTOR_SCALE) : 1;
94
+ }
95
+ /** The surface a layer is drawn from: its raster, or the raster with its effects applied. */
96
+ function effectSurface(layer, hydrated, host) {
97
+ if (!hasEnabledEffects(layer.effects) || !host.supportsFilter) {
98
+ return { surface: hydrated.surface, withEffects: false };
99
+ }
100
+ const filter = layerEffectsFilter(layer.effects);
101
+ if (!filter) {
102
+ return { surface: hydrated.surface, withEffects: false };
103
+ }
104
+ const { width, height } = hydrated.surface;
105
+ const out = host.createSurface(width, height);
106
+ const ctx = context2d(out);
107
+ ctx.filter = filter;
108
+ ctx.drawImage(hydrated.surface, 0, 0);
109
+ ctx.filter = "none";
110
+ return { surface: out, withEffects: true };
111
+ }
112
+ function drawLayer(ctx, doc, layer, hydrated, host, withOpacity) {
113
+ const { surface, withEffects } = effectSurface(layer, hydrated, host);
114
+ ctx.save();
115
+ if (withOpacity) {
116
+ ctx.globalAlpha =
117
+ layer.opacity * getAncestorGroupOpacityProduct(doc.layers, layer, null);
118
+ ctx.globalCompositeOperation = host.compositeOperation(layer.blendMode || "normal");
119
+ }
120
+ const offset = computeCompositeOffset(layer.transform, hydrated.bounds);
121
+ // The editor redraws a vector layer from its SVG only while the buffer it
122
+ // draws is the layer's own; an effect result is a plain raster.
123
+ const drawable = layer.type === "vector" && !withEffects && hydrated.vectorSource
124
+ ? hydrated.vectorSource
125
+ : surface;
126
+ drawWithTransform(ctx, surface, offset, layer.transform, drawable);
127
+ ctx.restore();
128
+ }
129
+ function outputSize(doc, options) {
130
+ const cw = Math.max(1, Math.round(doc.canvas.width));
131
+ const ch = Math.max(1, Math.round(doc.canvas.height));
132
+ const w = options.width && options.width > 0 ? options.width : undefined;
133
+ const h = options.height && options.height > 0 ? options.height : undefined;
134
+ if (w && h) {
135
+ return { width: Math.round(w), height: Math.round(h) };
136
+ }
137
+ if (w) {
138
+ return { width: Math.round(w), height: Math.max(1, Math.round((w * ch) / cw)) };
139
+ }
140
+ if (h) {
141
+ return { width: Math.max(1, Math.round((h * cw) / ch)), height: Math.round(h) };
142
+ }
143
+ return { width: cw, height: ch };
144
+ }
145
+ /**
146
+ * Render a persisted sketch document: the flattened composite by default, or
147
+ * one layer with `options.layerId`. `raw` is `ImageDocumentData` (with its
148
+ * `sketch` key) or the sketch document itself.
149
+ */
150
+ export async function renderSketchDocument(raw, host, options = {}) {
151
+ const doc = normalizeRenderDocument(raw);
152
+ const canvasWidth = Math.max(1, Math.round(doc.canvas.width));
153
+ const canvasHeight = Math.max(1, Math.round(doc.canvas.height));
154
+ const isolated = options.layerId ?? null;
155
+ if (isolated && !doc.layers.some((layer) => layer.id === isolated)) {
156
+ throw new Error(`The sketch has no layer ${isolated}.`);
157
+ }
158
+ const layerMap = new Map(doc.layers.map((layer) => [layer.id, layer]));
159
+ const reports = [];
160
+ const toDraw = [];
161
+ for (const layer of doc.layers) {
162
+ const report = {
163
+ id: layer.id,
164
+ name: layer.name,
165
+ type: layer.type,
166
+ drawn: false
167
+ };
168
+ reports.push(report);
169
+ const included = isolated
170
+ ? layer.id === isolated && layer.type !== "group"
171
+ : layer.type !== "group" &&
172
+ layer.type !== "mask" &&
173
+ isLayerCompositeVisible(doc.layers, layer, null, layerMap);
174
+ if (included) {
175
+ toDraw.push({ layer, report });
176
+ }
177
+ }
178
+ const hydrated = await Promise.all(toDraw.map(({ layer }) => hydrateLayer(layer, host)));
179
+ const flat = host.createSurface(canvasWidth, canvasHeight);
180
+ const flatCtx = context2d(flat);
181
+ flatCtx.clearRect(0, 0, canvasWidth, canvasHeight);
182
+ toDraw.forEach(({ layer, report }, index) => {
183
+ const entry = hydrated[index];
184
+ if (!entry) {
185
+ return;
186
+ }
187
+ drawLayer(flatCtx, doc, layer, entry.hydrated, host, !isolated);
188
+ report.drawn = entry.issue === undefined;
189
+ if (entry.issue) {
190
+ report.issue = entry.issue;
191
+ }
192
+ else if (hasEnabledEffects(layer.effects) && !host.supportsFilter) {
193
+ report.issue = "its effects were not applied: this canvas has no filter support";
194
+ }
195
+ });
196
+ const { width, height } = outputSize(doc, options);
197
+ if (width === canvasWidth && height === canvasHeight && !options.background) {
198
+ return { surface: flat, width, height, canvasWidth, canvasHeight, document: doc, layers: reports };
199
+ }
200
+ const out = host.createSurface(width, height);
201
+ const outCtx = context2d(out);
202
+ if (options.background) {
203
+ outCtx.fillStyle = options.background;
204
+ outCtx.fillRect(0, 0, width, height);
205
+ }
206
+ outCtx.imageSmoothingEnabled = true;
207
+ outCtx.imageSmoothingQuality = "high";
208
+ outCtx.drawImage(flat, 0, 0, canvasWidth, canvasHeight, 0, 0, width, height);
209
+ return { surface: out, width, height, canvasWidth, canvasHeight, document: doc, layers: reports };
210
+ }
211
+ //# sourceMappingURL=document.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document.js","sourceRoot":"","sources":["../../src/render/document.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,6CAA6C,CAAC;AACpF,OAAO,EACL,sBAAsB,EACtB,iBAAiB,EACjB,8BAA8B,EAC9B,iBAAiB,EACjB,uBAAuB,EACvB,kBAAkB,EAClB,YAAY,EACb,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AA6EzD,SAAS,WAAW,CAAC,MAAoB;IACvC,OAAO;QACL,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;QACvB,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;QACvB,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC5C,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;KAC/C,CAAC;AACJ,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACnC,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAA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EAAE,YAAY,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;IACrG,CAAC;IACD,MAAM,GAAG,GAAG,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC9C,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;IAC9B,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;QACvB,MAAM,CAAC,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC;QACtC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;IACvC,CAAC;IACD,MAAM,CAAC,qBAAqB,GAAG,IAAI,CAAC;IACpC,MAAM,CAAC,qBAAqB,GAAG,MAAM,CAAC;IACtC,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,WAAW,EAAE,YAAY,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;IAC7E,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;AACpG,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @nodetool-ai/image-editor/render — the sketch compositor.
3
+ *
4
+ * `compose.ts` holds the per-layer draw rules the editor's Canvas2D runtime
5
+ * composites with. `document.ts` runs them over a whole persisted document in
6
+ * one pass for a host without the editor, such as the headless renderer.
7
+ */
8
+ export * from "./types.js";
9
+ export * from "./normalize.js";
10
+ export * from "./compose.js";
11
+ export * from "./document.js";
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/render/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @nodetool-ai/image-editor/render — the sketch compositor.
3
+ *
4
+ * `compose.ts` holds the per-layer draw rules the editor's Canvas2D runtime
5
+ * composites with. `document.ts` runs them over a whole persisted document in
6
+ * one pass for a host without the editor, such as the headless renderer.
7
+ */
8
+ export * from "./types.js";
9
+ export * from "./normalize.js";
10
+ export * from "./compose.js";
11
+ export * from "./document.js";
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/render/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Load-boundary normalization of the layer fields that decide pixels.
3
+ *
4
+ * The web editor's `normalizeSketchDocument` calls `normalizeLayerTransform`
5
+ * and `normalizeLayerEffects` from here, and the headless renderer calls
6
+ * {@link normalizeRenderDocument}, which applies the same per-layer defaults.
7
+ * One set of migration rules means a legacy document renders the same in both.
8
+ */
9
+ import type { RenderDocument, RenderLayerEffect, RenderLayerTransform } from "./types.js";
10
+ /**
11
+ * Convert any legacy or unknown transform payload into the canonical union.
12
+ *
13
+ * - Canonical affine or quad payloads are cloned.
14
+ * - Legacy dual-quad payloads keep only their primary quad, as a perspective.
15
+ * - A known quad mode with a valid quad becomes a quad transform.
16
+ * - Anything else becomes an affine transform from whatever TRS fields are
17
+ * present, else identity. Matrix-only payloads are not recovered.
18
+ */
19
+ export declare function normalizeLayerTransform(raw: unknown): RenderLayerTransform;
20
+ /**
21
+ * Migrate legacy effect param names and drop unknown effect types, so every
22
+ * layer carries a valid `effects` array.
23
+ */
24
+ export declare function normalizeLayerEffects(raw: unknown): RenderLayerEffect[];
25
+ /**
26
+ * Normalize a persisted sketch document (`ImageDocumentData.sketch`, or the
27
+ * `ImageDocumentData` wrapper itself) into the shape the compositor reads,
28
+ * with the per-layer defaults the editor's `normalizeSketchDocument` applies.
29
+ */
30
+ export declare function normalizeRenderDocument(raw: unknown): RenderDocument;
31
+ //# sourceMappingURL=normalize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../src/render/normalize.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,cAAc,EAId,iBAAiB,EACjB,oBAAoB,EAIrB,MAAM,YAAY,CAAC;AAmEpB;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,OAAO,GAAG,oBAAoB,CAyB1E;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,OAAO,GAAG,iBAAiB,EAAE,CAqDvE;AA6BD;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,OAAO,GAAG,cAAc,CAuDpE"}
@@ -0,0 +1,228 @@
1
+ /**
2
+ * Load-boundary normalization of the layer fields that decide pixels.
3
+ *
4
+ * The web editor's `normalizeSketchDocument` calls `normalizeLayerTransform`
5
+ * and `normalizeLayerEffects` from here, and the headless renderer calls
6
+ * {@link normalizeRenderDocument}, which applies the same per-layer defaults.
7
+ * One set of migration rules means a legacy document renders the same in both.
8
+ */
9
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
10
+ const isNumber = (value) => typeof value === "number" && !Number.isNaN(value);
11
+ const isString = (value) => typeof value === "string";
12
+ function num(value, fallback) {
13
+ return isNumber(value) && Number.isFinite(value) ? value : fallback;
14
+ }
15
+ const QUAD_MODES = new Set([
16
+ "distort",
17
+ "skew",
18
+ "perspective",
19
+ "mesh-warp"
20
+ ]);
21
+ /** Map legacy quad-mode tags onto the current set; null when unknown. */
22
+ function migrateLegacyQuadMode(raw) {
23
+ if (QUAD_MODES.has(raw)) {
24
+ // SAFETY: QUAD_MODES holds only RenderQuadMode values and has() just matched raw.
25
+ return raw;
26
+ }
27
+ if (raw === "warp") {
28
+ return "distort";
29
+ }
30
+ if (raw === "perspective-distort" || raw === "perspective-dual") {
31
+ return "perspective";
32
+ }
33
+ return null;
34
+ }
35
+ function isQuadShape(value) {
36
+ return (Array.isArray(value) &&
37
+ value.length === 4 &&
38
+ value.every((point) => isRecord(point) &&
39
+ Number.isFinite(point["x"]) &&
40
+ Number.isFinite(point["y"])));
41
+ }
42
+ function quadTransform(mode, quad) {
43
+ return {
44
+ kind: "quad",
45
+ mode,
46
+ quad: [
47
+ { x: quad[0].x, y: quad[0].y },
48
+ { x: quad[1].x, y: quad[1].y },
49
+ { x: quad[2].x, y: quad[2].y },
50
+ { x: quad[3].x, y: quad[3].y }
51
+ ]
52
+ };
53
+ }
54
+ /**
55
+ * Convert any legacy or unknown transform payload into the canonical union.
56
+ *
57
+ * - Canonical affine or quad payloads are cloned.
58
+ * - Legacy dual-quad payloads keep only their primary quad, as a perspective.
59
+ * - A known quad mode with a valid quad becomes a quad transform.
60
+ * - Anything else becomes an affine transform from whatever TRS fields are
61
+ * present, else identity. Matrix-only payloads are not recovered.
62
+ */
63
+ export function normalizeLayerTransform(raw) {
64
+ const t = isRecord(raw) ? raw : {};
65
+ const affine = () => ({
66
+ kind: "affine",
67
+ x: num(t["x"], 0),
68
+ y: num(t["y"], 0),
69
+ scaleX: num(t["scaleX"], 1),
70
+ scaleY: num(t["scaleY"], 1),
71
+ rotation: num(t["rotation"], 0)
72
+ });
73
+ if (t["kind"] === "affine") {
74
+ return affine();
75
+ }
76
+ const quad = t["quad"];
77
+ const mode = t["mode"];
78
+ if ((t["kind"] === "dual-quad" || mode === "perspective-dual") && isQuadShape(quad)) {
79
+ return quadTransform("perspective", quad);
80
+ }
81
+ if (isString(mode) && isQuadShape(quad)) {
82
+ const migrated = migrateLegacyQuadMode(mode);
83
+ if (migrated) {
84
+ return quadTransform(migrated, quad);
85
+ }
86
+ }
87
+ return affine();
88
+ }
89
+ /**
90
+ * Migrate legacy effect param names and drop unknown effect types, so every
91
+ * layer carries a valid `effects` array.
92
+ */
93
+ export function normalizeLayerEffects(raw) {
94
+ if (!Array.isArray(raw)) {
95
+ return [];
96
+ }
97
+ const result = [];
98
+ for (const item of raw) {
99
+ if (!isRecord(item) || !isString(item["type"])) {
100
+ continue;
101
+ }
102
+ const enabled = item["enabled"] === true;
103
+ const params = isRecord(item["params"]) ? item["params"] : {};
104
+ const param = (key, legacy) => {
105
+ const value = params[key];
106
+ if (isNumber(value)) {
107
+ return value;
108
+ }
109
+ const old = legacy ? params[legacy] : undefined;
110
+ return isNumber(old) ? old : 0;
111
+ };
112
+ switch (item["type"]) {
113
+ case "brightness_contrast":
114
+ result.push({
115
+ type: "brightness_contrast",
116
+ enabled,
117
+ params: {
118
+ brightness: param("brightness"),
119
+ contrast: param("contrast")
120
+ }
121
+ });
122
+ break;
123
+ case "hue_saturation":
124
+ result.push({
125
+ type: "hue_saturation",
126
+ enabled,
127
+ params: {
128
+ hueDegrees: param("hueDegrees", "hue"),
129
+ saturation: param("saturation"),
130
+ lightness: param("lightness")
131
+ }
132
+ });
133
+ break;
134
+ case "exposure":
135
+ result.push({
136
+ type: "exposure",
137
+ enabled,
138
+ params: { exposureStops: param("exposureStops", "exposure") }
139
+ });
140
+ break;
141
+ default:
142
+ break;
143
+ }
144
+ }
145
+ return result;
146
+ }
147
+ const LAYER_TYPES = new Set([
148
+ "raster",
149
+ "mask",
150
+ "group",
151
+ "vector"
152
+ ]);
153
+ const IMAGE_FITS = new Set([
154
+ "fill",
155
+ "contain",
156
+ "cover"
157
+ ]);
158
+ function normalizeImageReference(raw) {
159
+ if (!isRecord(raw) || !isString(raw["uri"]) || !raw["uri"]) {
160
+ return null;
161
+ }
162
+ const fit = raw["objectFit"];
163
+ // SAFETY: IMAGE_FITS holds only RenderImageFit values and has() just matched fit.
164
+ return isString(fit) && IMAGE_FITS.has(fit)
165
+ ? { uri: raw["uri"], objectFit: fit }
166
+ : { uri: raw["uri"] };
167
+ }
168
+ /** Canvas size the editor falls back to when a document carries none. */
169
+ const DEFAULT_CANVAS_SIZE = 512;
170
+ /**
171
+ * Normalize a persisted sketch document (`ImageDocumentData.sketch`, or the
172
+ * `ImageDocumentData` wrapper itself) into the shape the compositor reads,
173
+ * with the per-layer defaults the editor's `normalizeSketchDocument` applies.
174
+ */
175
+ export function normalizeRenderDocument(raw) {
176
+ const root = isRecord(raw) && isRecord(raw["sketch"]) ? raw["sketch"] : raw;
177
+ const doc = isRecord(root) ? root : {};
178
+ const canvas = isRecord(doc["canvas"]) ? doc["canvas"] : {};
179
+ const width = num(canvas["width"], DEFAULT_CANVAS_SIZE);
180
+ const height = num(canvas["height"], DEFAULT_CANVAS_SIZE);
181
+ const rawLayers = Array.isArray(doc["layers"]) ? doc["layers"] : [];
182
+ const layers = [];
183
+ rawLayers.forEach((entry, index) => {
184
+ if (!isRecord(entry)) {
185
+ return;
186
+ }
187
+ const type = entry["type"];
188
+ const bounds = isRecord(entry["contentBounds"]) ? entry["contentBounds"] : {};
189
+ const data = entry["data"];
190
+ const parentId = entry["parentId"];
191
+ // SAFETY: LAYER_TYPES holds only RenderLayerType values and has() matches type first.
192
+ layers.push({
193
+ id: isString(entry["id"]) ? entry["id"] : `layer-${index}`,
194
+ name: isString(entry["name"]) ? entry["name"] : "",
195
+ type: isString(type) && LAYER_TYPES.has(type) ? type : "raster",
196
+ visible: entry["visible"] !== false,
197
+ opacity: num(entry["opacity"], 1),
198
+ blendMode: isString(entry["blendMode"]) ? entry["blendMode"] : "normal",
199
+ alphaLock: entry["alphaLock"] === true,
200
+ collapsed: entry["collapsed"] === true,
201
+ data: isString(data) && data ? data : null,
202
+ imageReference: normalizeImageReference(entry["imageReference"]),
203
+ transform: normalizeLayerTransform(entry["transform"]),
204
+ contentBounds: {
205
+ x: num(bounds["x"], 0),
206
+ y: num(bounds["y"], 0),
207
+ width: num(bounds["width"], width),
208
+ height: num(bounds["height"], height)
209
+ },
210
+ parentId: isString(parentId) && parentId ? parentId : null,
211
+ effects: normalizeLayerEffects(entry["effects"])
212
+ });
213
+ });
214
+ const maskLayerId = doc["maskLayerId"];
215
+ const background = canvas["backgroundColor"];
216
+ const renderCanvas = { width, height };
217
+ if (isString(background)) {
218
+ renderCanvas.backgroundColor = background;
219
+ }
220
+ return {
221
+ canvas: renderCanvas,
222
+ layers,
223
+ maskLayerId: isString(maskLayerId) && layers.some((layer) => layer.id === maskLayerId)
224
+ ? maskLayerId
225
+ : null
226
+ };
227
+ }
228
+ //# sourceMappingURL=normalize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize.js","sourceRoot":"","sources":["../../src/render/normalize.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAgBH,MAAM,QAAQ,GAAG,CAAC,KAAc,EAA0B,EAAE,CAC1D,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAEvE,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAmB,EAAE,CACnD,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAEpD,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC;AAEhF,SAAS,GAAG,CAAC,KAAc,EAAE,QAAgB;IAC3C,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC;AACtE,CAAC;AAED,MAAM,UAAU,GAAwB,IAAI,GAAG,CAAiB;IAC9D,SAAS;IACT,MAAM;IACN,aAAa;IACb,WAAW;CACZ,CAAC,CAAC;AAEH,yEAAyE;AACzE,SAAS,qBAAqB,CAAC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