@oim-media/core 1.27.9 → 1.27.11

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.
Files changed (48) hide show
  1. package/README.md +26 -1
  2. package/dist/compatibility.d.ts +1 -1
  3. package/dist/compatibility.js +3 -1
  4. package/dist/v2/geometry-outline.d.ts +23 -0
  5. package/dist/v2/geometry-outline.js +35 -0
  6. package/dist/v2/index.d.ts +10 -0
  7. package/dist/v2/index.js +11 -0
  8. package/dist/v2/layer-blocks.d.ts +11 -0
  9. package/dist/v2/layer-blocks.js +34 -0
  10. package/dist/v2/paint-css.d.ts +46 -0
  11. package/dist/v2/paint-css.js +109 -0
  12. package/dist/v2/schema.d.ts +1180 -0
  13. package/dist/v2/schema.js +433 -0
  14. package/dist/v2/upgrade/animations.d.ts +7 -0
  15. package/dist/v2/upgrade/animations.js +255 -0
  16. package/dist/v2/upgrade/box.d.ts +10 -0
  17. package/dist/v2/upgrade/box.js +119 -0
  18. package/dist/v2/upgrade/context.d.ts +42 -0
  19. package/dist/v2/upgrade/context.js +54 -0
  20. package/dist/v2/upgrade/effects.d.ts +25 -0
  21. package/dist/v2/upgrade/effects.js +204 -0
  22. package/dist/v2/upgrade/geometry.d.ts +9 -0
  23. package/dist/v2/upgrade/geometry.js +168 -0
  24. package/dist/v2/upgrade/gradient.d.ts +14 -0
  25. package/dist/v2/upgrade/gradient.js +79 -0
  26. package/dist/v2/upgrade/keys.d.ts +9 -0
  27. package/dist/v2/upgrade/keys.js +31 -0
  28. package/dist/v2/upgrade/mask.d.ts +7 -0
  29. package/dist/v2/upgrade/mask.js +64 -0
  30. package/dist/v2/upgrade/paints.d.ts +21 -0
  31. package/dist/v2/upgrade/paints.js +264 -0
  32. package/dist/v2/upgrade/root.d.ts +21 -0
  33. package/dist/v2/upgrade/root.js +94 -0
  34. package/dist/v2/upgrade/svg-paths.d.ts +38 -0
  35. package/dist/v2/upgrade/svg-paths.js +225 -0
  36. package/dist/v2/upgrade/text.d.ts +7 -0
  37. package/dist/v2/upgrade/text.js +132 -0
  38. package/dist/v2/upgrade/tree.d.ts +15 -0
  39. package/dist/v2/upgrade/tree.js +49 -0
  40. package/dist/v2/upgrade/variables.d.ts +8 -0
  41. package/dist/v2/upgrade/variables.js +24 -0
  42. package/dist/v2/upgrade/zones.d.ts +12 -0
  43. package/dist/v2/upgrade/zones.js +63 -0
  44. package/dist/v2/upgrade.d.ts +17 -0
  45. package/dist/v2/upgrade.js +143 -0
  46. package/dist/v2/version.d.ts +6 -0
  47. package/dist/v2/version.js +7 -0
  48. package/package.json +5 -1
@@ -0,0 +1,255 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2026 Xue Studios LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ // Five ways of moving things in 1.x (`animation`, `textAnimation*`, `reveal`,
7
+ // `states`, `trim*`) become one list. What reacts to the pointer by showing or
8
+ // hiding other layers is not animation: it goes to `interactions`.
9
+ import { admits } from "../layer-blocks.js";
10
+ import { asObject } from "./context.js";
11
+ const finite = (value) => typeof value === "number" && Number.isFinite(value) ? value : undefined;
12
+ /** The letter each property has in a 1.x keyframe, and its value at rest. */
13
+ const KEYFRAME_PROPERTIES = [
14
+ ["o", "opacity", 1],
15
+ ["s", "scale", 1],
16
+ ["r", "rotation", 0],
17
+ ["x", "x", 0],
18
+ ["y", "y", 0],
19
+ ["b", "blur", 0],
20
+ ];
21
+ /** What 1.x wrote into one `transform`: a frame that left one out drew it at rest. */
22
+ const IN_TRANSFORM = new Set(["x", "y", "scale", "rotation"]);
23
+ /**
24
+ * 1.x keyframes carry every property at once, in seconds. Each property that
25
+ * ever leaves its rest value becomes a track, with time from 0 to 1. Position,
26
+ * scale and rotation take every frame (at rest where the frame is silent, as
27
+ * 1.x drew it); opacity and blur take only the frames that name them.
28
+ */
29
+ function tracksOf(keyframes, duration) {
30
+ const frames = keyframes.map(asObject).filter((f) => !!f && finite(f.t) !== undefined);
31
+ // 1.x ran a timeline only from two keyframes up.
32
+ if (frames.length < 2)
33
+ return [];
34
+ const tracks = [];
35
+ for (const [letter, property, rest] of KEYFRAME_PROPERTIES) {
36
+ const named = frames.filter((f) => finite(f[letter]) !== undefined);
37
+ if (!named.some((f) => f[letter] !== rest))
38
+ continue;
39
+ const own = IN_TRANSFORM.has(property) ? frames : named;
40
+ const points = own.map((f) => {
41
+ const point = { t: Math.min(1, Math.max(0, f.t / duration)), v: finite(f[letter]) ?? rest };
42
+ if (f.e !== undefined)
43
+ point.e = f.e;
44
+ return point;
45
+ });
46
+ // A lone opacity or blur keyframe: the browser ran to it from the layer's own value, and back.
47
+ if (points.length === 1) {
48
+ const at = points[0].t;
49
+ if (at > 0)
50
+ points.unshift({ t: 0, v: rest });
51
+ if (at < 1)
52
+ points.push({ t: 1, v: rest });
53
+ }
54
+ tracks.push({ property, keyframes: points });
55
+ }
56
+ return tracks;
57
+ }
58
+ const TEXT_TARGET = { "rise-words": "words", "reveal-mask": "lines" };
59
+ /**
60
+ * The look a layer takes under the pointer. Each track runs from the layer's
61
+ * own value to the state's, which 1.x set outright (it did not add to it).
62
+ * Only hover: 1.x never drew the look of `active`.
63
+ */
64
+ function hoverLook(ctx, state, layer) {
65
+ const tracks = [];
66
+ const to = (property, own, target) => {
67
+ if (target !== own)
68
+ tracks.push({ property, keyframes: [{ t: 0, v: own }, { t: 1, v: target }] });
69
+ };
70
+ const scale = finite(state.scale);
71
+ // 1.x wrote the scale as a percentage; a value of 10 or less is an old multiplier.
72
+ if (scale !== undefined)
73
+ to("scale", 1, scale > 10 ? scale / 100 : scale);
74
+ const rotation = finite(state.rotation);
75
+ if (rotation !== undefined)
76
+ to("rotation", layer.box.rotation ?? 0, rotation);
77
+ const opacity = finite(state.opacity);
78
+ if (opacity !== undefined)
79
+ to("opacity", layer.opacity ?? 1, opacity / 100);
80
+ // No track can carry a colour.
81
+ if (state.color)
82
+ ctx.note("style.states.hover.color: a hover colour is not carried to 2.0");
83
+ if (tracks.length === 0)
84
+ return undefined;
85
+ // In milliseconds, as the editor wrote it (the 1.x player read it as seconds).
86
+ // None of its own: the player's transition decides (0).
87
+ return { on: "hover", tracks, duration: Math.max(0, finite(state.transitionDuration) ?? 0) };
88
+ }
89
+ const ACTIONS = new Set(["show", "hide", "toggle", "setText", "play"]);
90
+ function stateInteraction(state, on) {
91
+ const actions = (Array.isArray(state.actions) ? state.actions : [])
92
+ .map(asObject)
93
+ .filter((a) => !!a && typeof a.target === "string" && typeof a.type === "string" && ACTIONS.has(a.type))
94
+ .map((a) => ({ type: a.type, target: a.target, ...(typeof a.value === "string" ? { value: a.value } : {}) }));
95
+ return actions.length > 0 ? { on, actions } : undefined;
96
+ }
97
+ export function convertAnimations(ctx, slot, layer) {
98
+ const { raw, style } = slot;
99
+ const animations = [];
100
+ const interactions = [];
101
+ const animation = asObject(ctx.take(style, "animation"));
102
+ if (animation) {
103
+ const said = finite(animation.duration);
104
+ const delay = finite(animation.delay);
105
+ // A timeline with no duration of its own ran for 8 seconds, and never waited:
106
+ // the delay was the named loop's alone.
107
+ const seconds = said || 8;
108
+ const tracks = Array.isArray(animation.keyframes) && seconds > 0 ? tracksOf(animation.keyframes, seconds) : [];
109
+ // Keyframes loop for ever unless an action starts them, which is how every player runs them.
110
+ if (tracks.length > 0)
111
+ animations.push({ on: animation.trigger === "action" ? "action" : "loop", tracks, duration: seconds * 1000 });
112
+ if (typeof animation.loop === "string" && animation.loop !== "none" && animation.loop !== "custom") {
113
+ // No duration of its own: the preset decides it (0).
114
+ animations.push({ on: "loop", preset: animation.loop, duration: said && said > 0 ? said * 1000 : 0, ...(delay && delay > 0 ? { delay: delay * 1000 } : {}) });
115
+ }
116
+ if (typeof animation.hover === "string" && animation.hover !== "none" && animation.hover !== "custom") {
117
+ animations.push({ on: "hover", preset: animation.hover, duration: 200 });
118
+ }
119
+ // Raw CSS inside the file, retired in 1.9.0: no player applies it.
120
+ for (const key of ["custom_loop_css", "custom_keyframes", "custom_hover_css"]) {
121
+ if (animation[key])
122
+ ctx.note(`style.animation.${key}: raw CSS is not carried to 2.0`);
123
+ }
124
+ }
125
+ const textType = ctx.take(style, "textAnimationType");
126
+ const speed = finite(ctx.take(style, "textAnimationSpeed"));
127
+ const textDelay = finite(ctx.take(style, "textAnimationDelay"));
128
+ const intensity = finite(ctx.take(style, "textAnimationIntensity"));
129
+ const cursor = ctx.take(style, "typewriterCursor");
130
+ if (layer.type === "text" && typeof textType === "string" && textType && textType !== "none") {
131
+ const params = {};
132
+ if (speed !== undefined)
133
+ params.speed = speed;
134
+ if (intensity !== undefined)
135
+ params.intensity = intensity;
136
+ // The typewriter drew its cursor unless told not to: a `false` must survive.
137
+ if (typeof cursor === "boolean")
138
+ params.cursor = cursor;
139
+ animations.push({
140
+ on: "load",
141
+ target: TEXT_TARGET[textType] ?? "chars",
142
+ preset: textType,
143
+ ...(Object.keys(params).length > 0 ? { params } : {}),
144
+ // The length of a text entrance depends on its text; the preset decides it.
145
+ duration: 0,
146
+ ...(textDelay ? { delay: textDelay * 1000 } : {}),
147
+ });
148
+ }
149
+ const reveal = asObject(ctx.take(style, "reveal"));
150
+ if (reveal && typeof reveal.effect === "string") {
151
+ animations.push({
152
+ on: "enter",
153
+ preset: reveal.effect,
154
+ duration: finite(reveal.duration) ?? 300,
155
+ ...(reveal.easing !== undefined ? { easing: reveal.easing } : {}),
156
+ });
157
+ }
158
+ const trimStart = finite(ctx.take(style, "trimStart"));
159
+ const trimEnd = finite(ctx.take(style, "trimEnd"));
160
+ const trimDuration = finite(ctx.take(style, "trimDuration"));
161
+ // 1.x trimmed only markup it drew itself (an SVG, or HTML) that had a stroke
162
+ // width, and only when the trim hid something or was animated.
163
+ const share = (percent) => Math.min(1, Math.max(0, percent / 100));
164
+ const start = share(trimStart ?? 0);
165
+ const end = share(trimEnd ?? 100);
166
+ const seconds = Math.max(0, trimDuration ?? 0);
167
+ const content = raw.content;
168
+ const texts = typeof content === "string" ? [content] : Object.values(asObject(content) ?? {});
169
+ const drawn = slot.type !== "image" && texts.some((t) => typeof t === "string" && /(<|&lt;)svg|<span|<div|<a|<img/i.test(t));
170
+ if (layer.type === "shape" && layer.geometry && drawn && style.strokeWidth) {
171
+ // The trim at rest lives in the geometry: it is drawn even where nothing animates.
172
+ if (start > 0 || end < 1)
173
+ layer.geometry.trim = { ...(start > 0 ? { start } : {}), ...(end < 1 ? { end } : {}) };
174
+ // Drawn over time: the stroke grows from its start to its end at rest.
175
+ if (seconds > 0) {
176
+ animations.push({ on: "load", duration: seconds * 1000, tracks: [{ property: "trimEnd", keyframes: [{ t: 0, v: start }, { t: 1, v: end }] }] });
177
+ }
178
+ }
179
+ // The slot's own states won over the style's, and counted only on a layer marked interactive.
180
+ const ownStates = asObject(ctx.take(raw, "states"));
181
+ const states = ownStates ?? asObject(ctx.take(style, "states")) ?? {};
182
+ const interactive = raw.isInteractive === true || style.isInteractive === true;
183
+ ctx.take(raw, "isInteractive");
184
+ for (const [name, on] of [["hover", "hover"], ["active", "press"]]) {
185
+ const state = asObject(states[name]);
186
+ if (!state)
187
+ continue;
188
+ const look = interactive && on === "hover" ? hoverLook(ctx, state, layer) : undefined;
189
+ if (look)
190
+ animations.push(look);
191
+ // 1.x ran a state's actions only on a layer marked interactive.
192
+ const acts = interactive ? stateInteraction(state, on) : undefined;
193
+ if (acts)
194
+ interactions.push(acts);
195
+ }
196
+ const interaction = asObject(ctx.take(raw, "interaction"));
197
+ const target = asObject(interaction?.target);
198
+ if (interaction?.action_type === "toggle_elements" && target) {
199
+ const ids = (list) => (Array.isArray(list) ? list.filter((id) => typeof id === "string") : []);
200
+ const actions = [
201
+ ...ids(target.show_slots).map((id) => ({ type: "show", target: id })),
202
+ ...ids(target.hide_slots).map((id) => ({ type: "hide", target: id })),
203
+ ];
204
+ if (actions.length > 0)
205
+ interactions.push({ on: "press", actions });
206
+ }
207
+ // The flag only said "this layer reacts"; the interactions themselves say it now.
208
+ ctx.take(style, "isInteractive");
209
+ // 1.x moved a layer two ways. Only the endless scroll is carried; the parallax
210
+ // that followed the pointer is retired (Decision, 13 Nov).
211
+ const parallax = asObject(ctx.take(raw, "parallax")) ?? asObject(ctx.take(style, "parallax"));
212
+ ctx.take(style, "parallax");
213
+ if (parallax && parallax.enabled !== false) {
214
+ const inf = asObject(parallax.infinite) ?? {};
215
+ // The same reading as the 1.x player: a loop that is off is zero speed.
216
+ const speed = inf.enabled === false ? 0
217
+ : finite(parallax.speedPxSec) ?? finite(inf.speedPxSec) ?? finite(inf.speed_px_sec)
218
+ ?? (parallax.mode === "infinite_horizontal" ? finite(parallax.speed) ?? 20 : 0);
219
+ const pick = (...values) => values.find((v) => v !== undefined);
220
+ const direction = pick(parallax.direction, inf.direction);
221
+ const mirror = pick(parallax.mirror, parallax.seamlessTile, inf.mirror, inf.seamlessTile, inf.seamless_tile);
222
+ const pauseOnHover = pick(parallax.pauseOnHover, inf.pauseOnHover, inf.pause_on_hover);
223
+ if (speed !== 0) {
224
+ layer.motion = {
225
+ loop: {
226
+ speedPxSec: Math.min(500, Math.max(-500, speed)),
227
+ ...(direction === "left_to_right" || direction === "right_to_left" ? { direction } : {}),
228
+ ...(mirror !== undefined ? { mirror: !!mirror } : {}),
229
+ ...(pauseOnHover !== undefined ? { pauseOnHover: !!pauseOnHover } : {}),
230
+ },
231
+ };
232
+ }
233
+ else if (parallax.mode !== "infinite_horizontal") {
234
+ ctx.retire(raw.parallax !== undefined ? raw : style, "parallax");
235
+ }
236
+ }
237
+ // The player read these only to clip the group; its looping children clip it now.
238
+ ctx.retire(style, "sceneLoop");
239
+ // The flag only marked what clips; in 2.0 a loop clips by itself.
240
+ ctx.retire(raw, "isParallaxGroup");
241
+ ctx.retire(style, "isParallaxGroup");
242
+ ctx.retire(raw, "is_parallax_group");
243
+ ctx.retire(style, "loopDepth");
244
+ // What only a video layer used.
245
+ ctx.retire(raw, "tracking_data");
246
+ // Whatever is left of a CSS animation string is not a moving pattern (the
247
+ // fill converter took that one): raw CSS, which 2.0 does not carry.
248
+ const css = ctx.take(style, "cssAnimation");
249
+ if (typeof css === "string" && css && !/^background-animation-/.test(css))
250
+ ctx.note("style.cssAnimation: raw CSS is not carried to 2.0");
251
+ if (animations.length > 0)
252
+ layer.animations = animations;
253
+ if (interactions.length > 0 && admits(layer.type, "interactions"))
254
+ layer.interactions = interactions;
255
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2026 Xue Studios LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import type { DraftLayer, UpgradeContext, V1Slot } from "./context.js";
7
+ /** A 1.x length (number, "92.5cqw", "120px", "50%") in canvas units; undefined when it says nothing. */
8
+ export declare function toCanvasUnits(value: unknown, canvasWidth: number): number | undefined;
9
+ /** Position, size, rotation, opacity, visibility and blend. Defaults are not written. */
10
+ export declare function convertBox(ctx: UpgradeContext, slot: V1Slot, layer: DraftLayer): void;
@@ -0,0 +1,119 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2026 Xue Studios LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { resolveNumericDimension } from "../../dimensions.js";
7
+ const BLEND_MODES = new Set(["multiply", "screen", "overlay", "darken", "lighten", "color-dodge", "color-burn", "difference"]);
8
+ /** A 1.x length (number, "92.5cqw", "120px", "50%") in canvas units; undefined when it says nothing. */
9
+ export function toCanvasUnits(value, canvasWidth) {
10
+ if (typeof value !== "number" && typeof value !== "string")
11
+ return undefined;
12
+ const resolved = resolveNumericDimension(value, canvasWidth);
13
+ return resolved !== null && Number.isFinite(resolved) ? resolved : undefined;
14
+ }
15
+ const finite = (value) => typeof value === "number" && Number.isFinite(value) ? value : undefined;
16
+ // The layer types the player sizes as a shape (`isGeoLike` in the 1.x engine).
17
+ const SHAPE_TYPES = new Set(["geo", "shape", "draw", "filter", "container", "mask", "artistic-text"]);
18
+ const DEFAULT_SIDE = 0.1; // 10cqw, what the player gives a shape or an image with no size
19
+ /**
20
+ * A 1.x style length as the player painted it, in canvas units. Every length is
21
+ * painted against the canvas width (cqw) except a percentage, which CSS takes
22
+ * from the container's own axis. Undefined for what the player does not size.
23
+ */
24
+ function paintedLength(value, axis, W) {
25
+ if (value === undefined || value === null || value === "")
26
+ return undefined;
27
+ if (typeof value === "number")
28
+ return Number.isFinite(value) && axis > 0 ? (value / axis) * W : undefined;
29
+ const text = String(value).trim();
30
+ const n = parseFloat(text);
31
+ if (!Number.isFinite(n))
32
+ return undefined;
33
+ if (text.endsWith("cqw"))
34
+ return (n / 100) * W;
35
+ if (text.endsWith("%"))
36
+ return (n / 100) * axis;
37
+ if (text.endsWith("px"))
38
+ return n;
39
+ return /^-?[\d.]+$/.test(text) && axis > 0 ? (n / axis) * W : undefined;
40
+ }
41
+ const hasContent = (content) => typeof content === "string" ? content !== "" : !!content && typeof content === "object" && Object.values(content).some((v) => typeof v === "string" && v !== "");
42
+ /** Position, size, rotation, opacity, visibility and blend. Defaults are not written. */
43
+ export function convertBox(ctx, slot, layer) {
44
+ const { raw, style } = slot;
45
+ const { width: W, height: H } = ctx.canvas;
46
+ // The player reads a position as a fraction when neither axis passes 1.
47
+ const position = ctx.take(raw, "position");
48
+ const [px, py] = Array.isArray(position) ? position : [];
49
+ let fx = finite(px) ?? 0;
50
+ let fy = finite(py) ?? 0;
51
+ if (fx > 1 || fy > 1) {
52
+ fx /= 100;
53
+ fy /= 100;
54
+ }
55
+ const widthPx = finite(ctx.take(raw, "width_px"));
56
+ const heightPx = finite(ctx.take(raw, "height_px"));
57
+ const widthPercent = finite(ctx.take(raw, "widthPercent"));
58
+ const heightPercent = finite(ctx.take(raw, "heightPercent"));
59
+ const styleWidth = ctx.take(style, "width");
60
+ const styleHeight = ctx.take(style, "height");
61
+ // The reference box the player centres on: measured against each axis.
62
+ const ref = (px, percent, value, axis) => px ?? (percent !== undefined ? (percent / 100) * axis : (toCanvasUnits(value, axis) ?? 0));
63
+ const wRef = ref(widthPx, widthPercent, styleWidth, W);
64
+ const hRef = ref(heightPx, heightPercent, styleHeight, H);
65
+ // The box it painted: the branches of the player's sizing, in its order.
66
+ const type = String(raw.type ?? "text");
67
+ const isShape = SHAPE_TYPES.has(type) && !(type === "mask" && style.maskMode === "cutout");
68
+ const isBackground = raw.is_background_pattern === true || raw.id === "background-pattern-slot";
69
+ const content = hasContent(raw.content);
70
+ const fromStyle = [paintedLength(styleWidth, W, W), paintedLength(styleHeight, H, W)];
71
+ const fromFields = [
72
+ widthPx ?? (widthPercent !== undefined ? (widthPercent / 100) * W : undefined),
73
+ heightPx !== undefined ? (heightPx / W) * W : heightPercent !== undefined ? (heightPercent / 100) * W : undefined,
74
+ ];
75
+ let size;
76
+ if (fromStyle[0] !== undefined && fromStyle[1] !== undefined)
77
+ size = fromStyle;
78
+ else if (fromFields[0] !== undefined && fromFields[1] !== undefined && (isShape || type === "image" || !content))
79
+ size = fromFields;
80
+ else if (type === "image" || (isShape && !content) || isBackground || type === "pattern") {
81
+ size = [0, 1].map((i) => fromFields[i] ?? fromStyle[i] ?? DEFAULT_SIDE * W);
82
+ }
83
+ else
84
+ size = [undefined, undefined];
85
+ const align = style.textAlign ?? raw.align ?? "left";
86
+ const pull = (span) => (align === "center" ? span / 2 : align === "right" ? span : 0);
87
+ const anchorX = fx * W + pull(wRef);
88
+ const anchorY = fy * H + hRef / 2;
89
+ const [width, height] = size;
90
+ if (width === undefined || height === undefined) {
91
+ if (type !== "text" && !content) {
92
+ // Nothing to fit (a group): keep the reference box its wrapper is built from.
93
+ layer.box = { x: fx * W, y: fy * H, width: Math.max(0, wRef), height: Math.max(0, hRef) };
94
+ }
95
+ else {
96
+ // Fitted to its content in 1.x: the point it was pinned at, and the
97
+ // reference width when it had one (an endless loop measures by it).
98
+ layer.box = { x: anchorX, y: anchorY, anchor: align === "center" ? "center" : align === "right" ? "right" : "left" };
99
+ if (wRef > 0)
100
+ layer.box.width = wRef;
101
+ }
102
+ }
103
+ else {
104
+ layer.box = { x: anchorX - pull(width), y: anchorY - height / 2, width: Math.max(0, width), height: Math.max(0, height) };
105
+ }
106
+ const rotation = finite(ctx.take(style, "rotation"));
107
+ if (rotation)
108
+ layer.box.rotation = rotation;
109
+ const opacity = finite(ctx.take(style, "opacity"));
110
+ if (opacity !== undefined && opacity < 100)
111
+ layer.opacity = Math.max(0, opacity) / 100;
112
+ // 1.x hid the layer when either the style or the slot itself said so.
113
+ const hiddenSlot = ctx.take(raw, "isVisible") === false;
114
+ if (ctx.take(style, "isVisible") === false || hiddenSlot)
115
+ layer.visible = false;
116
+ const blend = ctx.take(style, "blendMode");
117
+ if (typeof blend === "string" && BLEND_MODES.has(blend))
118
+ layer.blend = blend;
119
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2026 Xue Studios LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import type { Layer } from "../schema.js";
7
+ export type V1Object = Record<string, unknown>;
8
+ /** A 1.x slot with its aliases already resolved. */
9
+ export type V1Slot = {
10
+ raw: V1Object;
11
+ style: V1Object;
12
+ type: string;
13
+ };
14
+ export type DraftLayer = Layer;
15
+ export type UpgradeContext = {
16
+ canvas: {
17
+ width: number;
18
+ height: number;
19
+ };
20
+ /** The main language: the one a bare string of content belongs to. */
21
+ language: string;
22
+ /** Whether the document's palettes define this colour role. */
23
+ hasRole(role: string): boolean;
24
+ /** Lets `finish` see this object. `label` prefixes its keys in the reports. */
25
+ register(owner: V1Object, label: string): void;
26
+ /** Reads a key AND marks it as converted. */
27
+ take<T = unknown>(owner: V1Object, key: string): T | undefined;
28
+ /** Marks a key as dropped on purpose. */
29
+ retire(owner: V1Object, key: string): void;
30
+ /** Reports something that could not be converted, with its reason. */
31
+ note(path: string): void;
32
+ finish(): {
33
+ retired: string[];
34
+ unhandled: string[];
35
+ };
36
+ };
37
+ export declare function createContext(canvas: {
38
+ width: number;
39
+ height: number;
40
+ }, language: string, roles?: ReadonlySet<string>): UpgradeContext;
41
+ /** A plain object, or nothing. */
42
+ export declare function asObject(value: unknown): V1Object | undefined;
@@ -0,0 +1,54 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2026 Xue Studios LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { isValidDynamicColorRole } from "../../dynamic-colors.js";
7
+ export function createContext(canvas, language, roles = new Set()) {
8
+ const labels = new Map();
9
+ const taken = new Map();
10
+ const retired = new Set();
11
+ const notes = new Set();
12
+ const mark = (owner, key) => {
13
+ let keys = taken.get(owner);
14
+ if (!keys)
15
+ taken.set(owner, (keys = new Set()));
16
+ keys.add(key);
17
+ };
18
+ return {
19
+ canvas,
20
+ language,
21
+ // A host page can set the eight dynamic roles even when the file has no palettes.
22
+ hasRole: (role) => roles.has(role) || isValidDynamicColorRole(role),
23
+ register(owner, label) {
24
+ labels.set(owner, label);
25
+ },
26
+ take(owner, key) {
27
+ mark(owner, key);
28
+ return owner[key];
29
+ },
30
+ retire(owner, key) {
31
+ mark(owner, key);
32
+ if (owner[key] !== undefined)
33
+ retired.add(`${labels.get(owner) ?? "?"}.${key}`);
34
+ },
35
+ note(path) {
36
+ notes.add(path);
37
+ },
38
+ finish() {
39
+ const unhandled = new Set(notes);
40
+ for (const [owner, label] of labels) {
41
+ const keys = taken.get(owner);
42
+ for (const key of Object.keys(owner)) {
43
+ if (owner[key] !== undefined && !keys?.has(key))
44
+ unhandled.add(`${label}.${key}`);
45
+ }
46
+ }
47
+ return { retired: [...retired].sort(), unhandled: [...unhandled].sort() };
48
+ },
49
+ };
50
+ }
51
+ /** A plain object, or nothing. */
52
+ export function asObject(value) {
53
+ return value !== null && typeof value === "object" && !Array.isArray(value) ? value : undefined;
54
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2026 Xue Studios LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import type { Effect } from "../schema.js";
7
+ import { type DraftLayer, type UpgradeContext, type V1Object, type V1Slot } from "./context.js";
8
+ type Filters = {
9
+ preset?: string;
10
+ blur?: number;
11
+ brightness?: number;
12
+ contrast?: number;
13
+ saturate?: number;
14
+ hueRotate?: number;
15
+ };
16
+ /**
17
+ * The colour-filter fields, shared by the filter layer (a backdrop effect),
18
+ * the image layer and the image fill. 1.x percentages become factors; a value
19
+ * that changes nothing is not written.
20
+ */
21
+ export declare function takeFilters(ctx: UpgradeContext, style: V1Object, backdrop?: boolean): Filters | undefined;
22
+ export declare function convertEffects(ctx: UpgradeContext, slot: V1Slot, layer: DraftLayer): void;
23
+ /** Grain and effects declared for the whole canvas. */
24
+ export declare function canvasEffects(ctx: UpgradeContext, meta: V1Object): Effect[];
25
+ export {};