@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.
- package/README.md +26 -1
- package/dist/compatibility.d.ts +1 -1
- package/dist/compatibility.js +3 -1
- package/dist/v2/geometry-outline.d.ts +23 -0
- package/dist/v2/geometry-outline.js +35 -0
- package/dist/v2/index.d.ts +10 -0
- package/dist/v2/index.js +11 -0
- package/dist/v2/layer-blocks.d.ts +11 -0
- package/dist/v2/layer-blocks.js +34 -0
- package/dist/v2/paint-css.d.ts +46 -0
- package/dist/v2/paint-css.js +109 -0
- package/dist/v2/schema.d.ts +1180 -0
- package/dist/v2/schema.js +433 -0
- package/dist/v2/upgrade/animations.d.ts +7 -0
- package/dist/v2/upgrade/animations.js +255 -0
- package/dist/v2/upgrade/box.d.ts +10 -0
- package/dist/v2/upgrade/box.js +119 -0
- package/dist/v2/upgrade/context.d.ts +42 -0
- package/dist/v2/upgrade/context.js +54 -0
- package/dist/v2/upgrade/effects.d.ts +25 -0
- package/dist/v2/upgrade/effects.js +204 -0
- package/dist/v2/upgrade/geometry.d.ts +9 -0
- package/dist/v2/upgrade/geometry.js +168 -0
- package/dist/v2/upgrade/gradient.d.ts +14 -0
- package/dist/v2/upgrade/gradient.js +79 -0
- package/dist/v2/upgrade/keys.d.ts +9 -0
- package/dist/v2/upgrade/keys.js +31 -0
- package/dist/v2/upgrade/mask.d.ts +7 -0
- package/dist/v2/upgrade/mask.js +64 -0
- package/dist/v2/upgrade/paints.d.ts +21 -0
- package/dist/v2/upgrade/paints.js +264 -0
- package/dist/v2/upgrade/root.d.ts +21 -0
- package/dist/v2/upgrade/root.js +94 -0
- package/dist/v2/upgrade/svg-paths.d.ts +38 -0
- package/dist/v2/upgrade/svg-paths.js +225 -0
- package/dist/v2/upgrade/text.d.ts +7 -0
- package/dist/v2/upgrade/text.js +132 -0
- package/dist/v2/upgrade/tree.d.ts +15 -0
- package/dist/v2/upgrade/tree.js +49 -0
- package/dist/v2/upgrade/variables.d.ts +8 -0
- package/dist/v2/upgrade/variables.js +24 -0
- package/dist/v2/upgrade/zones.d.ts +12 -0
- package/dist/v2/upgrade/zones.js +63 -0
- package/dist/v2/upgrade.d.ts +17 -0
- package/dist/v2/upgrade.js +143 -0
- package/dist/v2/version.d.ts +6 -0
- package/dist/v2/version.js +7 -0
- package/package.json +5 -1
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2026 Xue Studios LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { asObject } from "./context.js";
|
|
7
|
+
import { colorOf } from "./paints.js";
|
|
8
|
+
import { FILTER_PRESET_CSS } from "../../media-filters.js";
|
|
9
|
+
const finite = (value) => typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
|
10
|
+
/**
|
|
11
|
+
* The colour-filter fields, shared by the filter layer (a backdrop effect),
|
|
12
|
+
* the image layer and the image fill. 1.x percentages become factors; a value
|
|
13
|
+
* that changes nothing is not written.
|
|
14
|
+
*/
|
|
15
|
+
export function takeFilters(ctx, style, backdrop = false) {
|
|
16
|
+
// `fp` is the short name the filter layer was also read by.
|
|
17
|
+
const named = ctx.take(style, "filterPreset");
|
|
18
|
+
const short = ctx.take(style, "fp");
|
|
19
|
+
const preset = backdrop ? named || short : named;
|
|
20
|
+
const blur = finite(ctx.take(style, "filterBlur"));
|
|
21
|
+
const brightness = finite(ctx.take(style, "filterBrightness"));
|
|
22
|
+
const contrast = finite(ctx.take(style, "filterContrast"));
|
|
23
|
+
const saturate = finite(ctx.take(style, "filterSaturate"));
|
|
24
|
+
const hueRotate = finite(ctx.take(style, "filterHueRotate"));
|
|
25
|
+
const filters = {};
|
|
26
|
+
// Only a preset the 1.x table knew was painted; duotone, only behind a filter layer.
|
|
27
|
+
if (typeof preset === "string" && (Object.hasOwn(FILTER_PRESET_CSS, preset) || (backdrop && preset === "duotone")))
|
|
28
|
+
filters.preset = preset;
|
|
29
|
+
if (blur)
|
|
30
|
+
filters.blur = blur;
|
|
31
|
+
if (brightness !== undefined && brightness !== 100)
|
|
32
|
+
filters.brightness = brightness / 100;
|
|
33
|
+
if (contrast !== undefined && contrast !== 100)
|
|
34
|
+
filters.contrast = contrast / 100;
|
|
35
|
+
if (saturate !== undefined && saturate !== 100)
|
|
36
|
+
filters.saturate = saturate / 100;
|
|
37
|
+
if (hueRotate)
|
|
38
|
+
filters.hueRotate = hueRotate;
|
|
39
|
+
return Object.keys(filters).length > 0 ? filters : undefined;
|
|
40
|
+
}
|
|
41
|
+
function listedEffect(ctx, value, defaults = {}) {
|
|
42
|
+
const fx = asObject(value);
|
|
43
|
+
if (!fx || fx.enabled === false)
|
|
44
|
+
return undefined;
|
|
45
|
+
const tintOf = (fallbackColor, fallbackRole) => {
|
|
46
|
+
const role = fx.colorRole || fallbackRole;
|
|
47
|
+
const literal = typeof fx.color === "string" && fx.color ? fx.color : fallbackColor;
|
|
48
|
+
const color = typeof role === "string" && ctx.hasRole(role) ? (literal ? { var: role, fallback: literal } : { var: role }) : literal;
|
|
49
|
+
return color === undefined ? {} : { color: color };
|
|
50
|
+
};
|
|
51
|
+
const tint = tintOf(undefined, undefined);
|
|
52
|
+
switch (fx.type) {
|
|
53
|
+
case "drop-shadow": {
|
|
54
|
+
// An artistic text is an SVG: the text-shadow 1.x gave it painted nothing.
|
|
55
|
+
if (defaults.glyphsInSvg)
|
|
56
|
+
return undefined;
|
|
57
|
+
// 1.x drew a listed shadow 4px down, 12px soft and translucent black when unsaid.
|
|
58
|
+
const shadow = { kind: "shadow", y: 4, blur: 12, ...tintOf("rgba(0, 0, 0, 0.35)", defaults.shadowRole) };
|
|
59
|
+
for (const key of ["x", "y", "blur", "spread"]) {
|
|
60
|
+
const n = finite(fx[key]);
|
|
61
|
+
if (n !== undefined)
|
|
62
|
+
shadow[key] = key === "blur" ? Math.max(0, n) : n;
|
|
63
|
+
}
|
|
64
|
+
if (!shadow.x)
|
|
65
|
+
delete shadow.x;
|
|
66
|
+
return shadow;
|
|
67
|
+
}
|
|
68
|
+
case "glow": {
|
|
69
|
+
if (defaults.glyphsInSvg)
|
|
70
|
+
return undefined;
|
|
71
|
+
const glow = { kind: "glow", radius: finite(fx.radius) || 16, ...tintOf("#f59e0b", defaults.glowRole) };
|
|
72
|
+
const intensity = finite(fx.intensity);
|
|
73
|
+
if (intensity !== undefined)
|
|
74
|
+
glow.intensity = intensity;
|
|
75
|
+
return glow;
|
|
76
|
+
}
|
|
77
|
+
case "blur":
|
|
78
|
+
return { kind: "blur", radius: finite(fx.radius) ?? 8 };
|
|
79
|
+
case "color-grade": {
|
|
80
|
+
if (typeof fx.preset !== "string")
|
|
81
|
+
return undefined;
|
|
82
|
+
const intensity = finite(fx.intensity);
|
|
83
|
+
return { kind: "color-grade", preset: fx.preset, ...(intensity === undefined ? {} : { intensity }) };
|
|
84
|
+
}
|
|
85
|
+
case "texture": {
|
|
86
|
+
if (typeof fx.preset !== "string")
|
|
87
|
+
return undefined;
|
|
88
|
+
const texture = { kind: "texture", preset: fx.preset, ...tint };
|
|
89
|
+
const intensity = finite(fx.intensity);
|
|
90
|
+
const scale = finite(fx.scale);
|
|
91
|
+
if (intensity !== undefined)
|
|
92
|
+
texture.intensity = intensity;
|
|
93
|
+
if (typeof fx.blend === "string")
|
|
94
|
+
texture.blend = fx.blend;
|
|
95
|
+
if (scale !== undefined && scale !== 1)
|
|
96
|
+
texture.scale = scale;
|
|
97
|
+
return texture;
|
|
98
|
+
}
|
|
99
|
+
default:
|
|
100
|
+
ctx.note(`style.effects: unknown effect type "${String(fx.type)}"`);
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function listedEffects(ctx, value, defaults) {
|
|
105
|
+
return Array.isArray(value) ? value.map((fx) => listedEffect(ctx, fx, defaults)).filter((fx) => !!fx) : [];
|
|
106
|
+
}
|
|
107
|
+
export function convertEffects(ctx, slot, layer) {
|
|
108
|
+
const { style } = slot;
|
|
109
|
+
const effects = [];
|
|
110
|
+
// What the 1.x player painted, in its order: the neon first; then, when the
|
|
111
|
+
// layer has an effects list, that list alone; otherwise blur, grain, shadow.
|
|
112
|
+
const named = ctx.take(style, "effect");
|
|
113
|
+
const namedColor = colorOf(ctx, style, "effectColor", "effectColorRole");
|
|
114
|
+
const namedRadius = finite(ctx.take(style, "effectRadius"));
|
|
115
|
+
// Only the neon was ever drawn; the named "shadow" painted nothing.
|
|
116
|
+
if (named === "neon")
|
|
117
|
+
effects.push({ kind: "glow", radius: namedRadius ?? 16, color: namedColor ?? "#f59e0b" });
|
|
118
|
+
const list = ctx.take(style, "effects");
|
|
119
|
+
const hasList = Array.isArray(list) && list.length > 0;
|
|
120
|
+
// The six shadow fields travel on every layer; only `shadowEnabled` says they count.
|
|
121
|
+
const enabled = ctx.take(style, "shadowEnabled") === true && !hasList;
|
|
122
|
+
let enabledShadow;
|
|
123
|
+
const shadowColor = colorOf(ctx, style, "shadowColor", "shadowColorRole");
|
|
124
|
+
const blur = finite(ctx.take(style, "shadowBlur"));
|
|
125
|
+
const x = finite(ctx.take(style, "shadowOffsetX"));
|
|
126
|
+
const y = finite(ctx.take(style, "shadowOffsetY"));
|
|
127
|
+
const opacity = finite(ctx.take(style, "shadowOpacity"));
|
|
128
|
+
if (enabled) {
|
|
129
|
+
const shadow = { kind: "shadow" };
|
|
130
|
+
if (x)
|
|
131
|
+
shadow.x = x;
|
|
132
|
+
if (y)
|
|
133
|
+
shadow.y = y;
|
|
134
|
+
if (blur)
|
|
135
|
+
shadow.blur = blur;
|
|
136
|
+
if (shadowColor !== undefined)
|
|
137
|
+
shadow.color = shadowColor;
|
|
138
|
+
if (opacity !== undefined && opacity < 100)
|
|
139
|
+
shadow.opacity = Math.max(0, opacity) / 100;
|
|
140
|
+
enabledShadow = shadow;
|
|
141
|
+
}
|
|
142
|
+
const legacyBlur = finite(ctx.take(style, "layerBlur")) ?? finite(ctx.take(style, "blur"));
|
|
143
|
+
ctx.take(style, "blur");
|
|
144
|
+
if (hasList) {
|
|
145
|
+
effects.push(...listedEffects(ctx, list, {
|
|
146
|
+
shadowRole: style.shadowColorRole,
|
|
147
|
+
glowRole: style.effectColorRole,
|
|
148
|
+
glyphsInSvg: slot.type === "artistic-text",
|
|
149
|
+
}));
|
|
150
|
+
}
|
|
151
|
+
else if (legacyBlur && legacyBlur > 0)
|
|
152
|
+
effects.push({ kind: "blur", radius: legacyBlur });
|
|
153
|
+
// On a filter layer the colour filters act on what is behind it. On an
|
|
154
|
+
// image, or a shape filled with one, they belong to the image. On anything
|
|
155
|
+
// else 1.x painted nothing, so nothing is written.
|
|
156
|
+
const filters = takeFilters(ctx, style, slot.type === "filter");
|
|
157
|
+
if (slot.type === "filter")
|
|
158
|
+
effects.push({ kind: "backdrop", ...filters });
|
|
159
|
+
else if (filters) {
|
|
160
|
+
const paint = layer.fills?.find((p) => "kind" in p && p.kind === "image");
|
|
161
|
+
if (layer.image)
|
|
162
|
+
layer.image.filters = filters;
|
|
163
|
+
else if (paint && "kind" in paint && paint.kind === "image")
|
|
164
|
+
paint.filters = filters;
|
|
165
|
+
}
|
|
166
|
+
const grain = ctx.take(style, "grain") === true;
|
|
167
|
+
const intensity = finite(ctx.take(style, "grainIntensity"));
|
|
168
|
+
const size = finite(ctx.take(style, "grainSize"));
|
|
169
|
+
const blend = ctx.take(style, "grainBlend");
|
|
170
|
+
if (grain && !hasList) {
|
|
171
|
+
const fx = { kind: "grain" };
|
|
172
|
+
if (intensity !== undefined)
|
|
173
|
+
fx.intensity = intensity;
|
|
174
|
+
if (size !== undefined)
|
|
175
|
+
fx.size = size;
|
|
176
|
+
if (typeof blend === "string")
|
|
177
|
+
fx.blend = blend;
|
|
178
|
+
effects.push(fx);
|
|
179
|
+
}
|
|
180
|
+
if (enabledShadow)
|
|
181
|
+
effects.push(enabledShadow);
|
|
182
|
+
if (effects.length > 0)
|
|
183
|
+
layer.effects = effects;
|
|
184
|
+
}
|
|
185
|
+
/** Grain and effects declared for the whole canvas. */
|
|
186
|
+
export function canvasEffects(ctx, meta) {
|
|
187
|
+
const effects = listedEffects(ctx, ctx.take(meta, "effects"));
|
|
188
|
+
const grain = asObject(ctx.take(meta, "grain"));
|
|
189
|
+
if (grain && grain.enabled !== false) {
|
|
190
|
+
const fx = { kind: "grain" };
|
|
191
|
+
const intensity = finite(grain.intensity);
|
|
192
|
+
const frequency = finite(grain.baseFrequency);
|
|
193
|
+
if (intensity !== undefined)
|
|
194
|
+
fx.intensity = intensity;
|
|
195
|
+
if (frequency !== undefined)
|
|
196
|
+
fx.size = frequency;
|
|
197
|
+
if (typeof grain.blendMode === "string")
|
|
198
|
+
fx.blend = grain.blendMode;
|
|
199
|
+
if (typeof grain.color === "string")
|
|
200
|
+
fx.color = grain.color;
|
|
201
|
+
effects.push(fx);
|
|
202
|
+
}
|
|
203
|
+
return effects;
|
|
204
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2026 Xue Studios LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { type DraftLayer, type UpgradeContext, type V1Slot } from "./context.js";
|
|
7
|
+
/** `content` of a layer that is not a text: one value for every language, under "*" or the main one. */
|
|
8
|
+
export declare function mediaOf(ctx: UpgradeContext, slot: V1Slot): string | undefined;
|
|
9
|
+
export declare function convertGeometry(ctx: UpgradeContext, slot: V1Slot, layer: DraftLayer): void;
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2026 Xue Studios LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
// What a layer is made of: the figure of a shape, the corners, the source of
|
|
7
|
+
// an image. Also where `content` goes when the layer is not a text.
|
|
8
|
+
import { admits } from "../layer-blocks.js";
|
|
9
|
+
import { toCanvasUnits } from "./box.js";
|
|
10
|
+
import { asObject } from "./context.js";
|
|
11
|
+
import { drawsMarkup, svgToPaths } from "./svg-paths.js";
|
|
12
|
+
/** The 1.x name of a figure and the 2.0 geometry that has its own kind. */
|
|
13
|
+
const BASIC = {
|
|
14
|
+
rectangle: { kind: "rect" },
|
|
15
|
+
circle: { kind: "ellipse" },
|
|
16
|
+
line: { kind: "line" },
|
|
17
|
+
};
|
|
18
|
+
const viewBoxOf = (value) => {
|
|
19
|
+
const numbers = typeof value === "string" ? value.trim().split(/[\s,]+/).map(Number) : [];
|
|
20
|
+
return numbers.length === 4 && numbers.every(Number.isFinite) ? numbers : [0, 0, 24, 24];
|
|
21
|
+
};
|
|
22
|
+
/** `content` of a layer that is not a text: one value for every language, under "*" or the main one. */
|
|
23
|
+
export function mediaOf(ctx, slot) {
|
|
24
|
+
const content = ctx.take(slot.raw, "content");
|
|
25
|
+
if (typeof content === "string")
|
|
26
|
+
return content || undefined;
|
|
27
|
+
const map = asObject(content) ?? {};
|
|
28
|
+
const value = map["*"] ?? map[ctx.language] ?? Object.values(map).find((v) => typeof v === "string" && v !== "");
|
|
29
|
+
return typeof value === "string" && value !== "" ? value : undefined;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A picture with per-language exceptions. 1.x kept the principal under "*" and
|
|
33
|
+
* gave a language its own key, final even when empty.
|
|
34
|
+
*/
|
|
35
|
+
function imageSource(slot, value) {
|
|
36
|
+
const map = asObject(slot.raw.content);
|
|
37
|
+
if (!map || typeof map["*"] !== "string" || value === "oim:base")
|
|
38
|
+
return value;
|
|
39
|
+
const modes = {};
|
|
40
|
+
for (const [language, own] of Object.entries(map))
|
|
41
|
+
if (language !== "*" && typeof own === "string" && own !== value)
|
|
42
|
+
modes[language] = own;
|
|
43
|
+
return Object.keys(modes).length > 0 ? { value, modes } : value;
|
|
44
|
+
}
|
|
45
|
+
function pathsFromLayers(ctx, layers, viewBox) {
|
|
46
|
+
const paths = [];
|
|
47
|
+
for (const item of layers) {
|
|
48
|
+
const part = asObject(item);
|
|
49
|
+
if (!part || typeof part.d !== "string" || !part.d)
|
|
50
|
+
continue;
|
|
51
|
+
const entry = { d: part.d };
|
|
52
|
+
if (typeof part.fill === "string" && part.fill !== "none")
|
|
53
|
+
entry.fill = part.fill;
|
|
54
|
+
if (typeof part.stroke === "string" && part.stroke !== "none") {
|
|
55
|
+
entry.stroke = part.stroke;
|
|
56
|
+
entry.strokeWidth = typeof part.strokeWidth === "number" ? part.strokeWidth : 1;
|
|
57
|
+
}
|
|
58
|
+
if (typeof part.animationType === "string" && part.animationType !== "none") {
|
|
59
|
+
ctx.note(`style.svgLayers: per-path animation "${part.animationType}"`);
|
|
60
|
+
}
|
|
61
|
+
paths.push(entry);
|
|
62
|
+
}
|
|
63
|
+
return paths.length > 0 ? { kind: "paths", viewBox, paths } : undefined;
|
|
64
|
+
}
|
|
65
|
+
function shapeGeometry(ctx, slot, media) {
|
|
66
|
+
const { style } = slot;
|
|
67
|
+
// Ruling (13 Nov): the 1.x player drew only `geoShape`; a `geoType` alone painted the box.
|
|
68
|
+
const name = ctx.take(style, "geoShape");
|
|
69
|
+
ctx.take(style, "geoType");
|
|
70
|
+
const path = ctx.take(style, "svgPath");
|
|
71
|
+
const blob = ctx.take(style, "customBlobPath");
|
|
72
|
+
const viewBox = viewBoxOf(ctx.take(style, "svgViewBox"));
|
|
73
|
+
const rawXml = ctx.take(style, "svgRawXml");
|
|
74
|
+
const layers = ctx.take(style, "svgLayers");
|
|
75
|
+
// The decomposed layers carry the colours the author edited; the raw XML is the original.
|
|
76
|
+
if (Array.isArray(layers) && layers.length > 0) {
|
|
77
|
+
const fromLayers = pathsFromLayers(ctx, layers, viewBox);
|
|
78
|
+
if (fromLayers)
|
|
79
|
+
return fromLayers;
|
|
80
|
+
}
|
|
81
|
+
const xml = typeof rawXml === "string" && rawXml ? rawXml : drawsMarkup(slot) ? media : undefined;
|
|
82
|
+
if (xml) {
|
|
83
|
+
const parsed = svgToPaths(xml);
|
|
84
|
+
if (parsed.ok)
|
|
85
|
+
return { kind: "paths", ...parsed.value };
|
|
86
|
+
ctx.note(`style.svgRawXml: ${parsed.reason}`);
|
|
87
|
+
return { kind: "rect" };
|
|
88
|
+
}
|
|
89
|
+
const d = typeof path === "string" && path ? path : typeof blob === "string" && blob ? blob : undefined;
|
|
90
|
+
// The blob and the scribble draw their own path (1.x: customBlobPath first, then svgPath for the blob).
|
|
91
|
+
if (name === "scribble" && typeof blob === "string" && blob)
|
|
92
|
+
return { kind: "paths", viewBox: [0, 0, 100, 100], paths: [{ d: blob }] };
|
|
93
|
+
if (name === "blob" && typeof blob === "string" && blob)
|
|
94
|
+
return { kind: "paths", viewBox: [0, 0, 100, 100], paths: [{ d: blob }] };
|
|
95
|
+
if (d && (name === undefined || name === "custom" || name === "blob"))
|
|
96
|
+
return { kind: "paths", viewBox: name === "blob" ? [0, 0, 100, 100] : viewBox, paths: [{ d }] };
|
|
97
|
+
if (typeof name === "string" && name)
|
|
98
|
+
return BASIC[name] ?? { kind: "preset", name };
|
|
99
|
+
return { kind: "rect" };
|
|
100
|
+
}
|
|
101
|
+
const CORNER_KEYS = [
|
|
102
|
+
["borderRadiusTL", "borderTopLeftRadius"],
|
|
103
|
+
["borderRadiusTR", "borderTopRightRadius"],
|
|
104
|
+
["borderRadiusBR", "borderBottomRightRadius"],
|
|
105
|
+
["borderRadiusBL", "borderBottomLeftRadius"],
|
|
106
|
+
];
|
|
107
|
+
// The CSS shorthand order: one value for all, two for TL/BR and TR/BL, three for TL, TR/BL, BR.
|
|
108
|
+
const SHORTHAND = [[0, 0, 0, 0], [0, 1, 0, 1], [0, 1, 2, 1], [0, 1, 2, 3]];
|
|
109
|
+
function cornersOf(ctx, style) {
|
|
110
|
+
const W = ctx.canvas.width;
|
|
111
|
+
const raw = ctx.take(style, "borderRadius");
|
|
112
|
+
const tokens = typeof raw === "string" ? raw.trim().split(/\s+/) : [];
|
|
113
|
+
const shorthand = tokens.length > 1 && tokens.length <= 4 ? SHORTHAND[tokens.length - 1].map((i) => toCanvasUnits(tokens[i], W)) : [];
|
|
114
|
+
const all = tokens.length > 1 ? 0 : (toCanvasUnits(raw, W) ?? 0);
|
|
115
|
+
const each = CORNER_KEYS.map((keys, corner) => {
|
|
116
|
+
const values = keys.map((key) => toCanvasUnits(ctx.take(style, key), W));
|
|
117
|
+
return values.find((v) => v !== undefined) ?? shorthand[corner];
|
|
118
|
+
});
|
|
119
|
+
if (each.some((v) => v !== undefined)) {
|
|
120
|
+
const four = each.map((v) => Math.max(0, v ?? all));
|
|
121
|
+
return four.every((v) => v === four[0]) ? four[0] || undefined : four;
|
|
122
|
+
}
|
|
123
|
+
return all > 0 ? all : undefined;
|
|
124
|
+
}
|
|
125
|
+
export function convertGeometry(ctx, slot, layer) {
|
|
126
|
+
const { style } = slot;
|
|
127
|
+
const media = layer.type === "text" ? undefined : mediaOf(ctx, slot);
|
|
128
|
+
if (layer.type === "shape")
|
|
129
|
+
layer.geometry = shapeGeometry(ctx, slot, media);
|
|
130
|
+
// 1.x painted an SVG layer's fillColor into every figure of its drawing, fill="none"
|
|
131
|
+
// included: each path's fill becomes the layer's fill.
|
|
132
|
+
const first = layer.fills?.[0];
|
|
133
|
+
if (drawsMarkup(slot) && layer.geometry?.kind === "paths" && first && "kind" in first && first.kind === "color") {
|
|
134
|
+
for (const path of layer.geometry.paths)
|
|
135
|
+
path.fill = "currentColor";
|
|
136
|
+
}
|
|
137
|
+
else
|
|
138
|
+
for (const key of ["geoShape", "geoType", "svgPath", "customBlobPath", "svgViewBox", "svgRawXml", "svgLayers"])
|
|
139
|
+
ctx.take(style, key);
|
|
140
|
+
const corners = cornersOf(ctx, style);
|
|
141
|
+
if (corners !== undefined && admits(layer.type, "corners"))
|
|
142
|
+
layer.corners = corners;
|
|
143
|
+
const fit = ctx.take(style, "objectFit");
|
|
144
|
+
const crop = asObject(ctx.take(style, "imageCrop"));
|
|
145
|
+
if (layer.type === "image") {
|
|
146
|
+
// An image layer with no source of its own was baked into the PNG of the file.
|
|
147
|
+
layer.image = { src: imageSource(slot, media ?? "oim:base") };
|
|
148
|
+
if (typeof fit === "string" && fit !== "cover")
|
|
149
|
+
layer.image.fit = fit;
|
|
150
|
+
if (crop)
|
|
151
|
+
layer.image.crop = crop;
|
|
152
|
+
}
|
|
153
|
+
if (layer.type === "lottie" && media)
|
|
154
|
+
layer.lottie = { src: media };
|
|
155
|
+
if (ctx.take(style, "flipX") === true)
|
|
156
|
+
layer.box.flipX = true;
|
|
157
|
+
if (ctx.take(style, "flipY") === true)
|
|
158
|
+
layer.box.flipY = true;
|
|
159
|
+
const alt = asObject(ctx.take(style, "alt"));
|
|
160
|
+
const decorative = ctx.take(style, "decorative") === true;
|
|
161
|
+
if (admits(layer.type, "a11y") && ((alt && Object.keys(alt).length > 0) || decorative)) {
|
|
162
|
+
layer.a11y = {};
|
|
163
|
+
if (alt && Object.keys(alt).length > 0)
|
|
164
|
+
layer.a11y.alt = alt;
|
|
165
|
+
if (decorative)
|
|
166
|
+
layer.a11y.decorative = true;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2026 Xue Studios LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
export type Gradient = {
|
|
7
|
+
type: "linear" | "radial" | "conic";
|
|
8
|
+
angle?: number;
|
|
9
|
+
stops: {
|
|
10
|
+
color: string;
|
|
11
|
+
at?: number;
|
|
12
|
+
}[];
|
|
13
|
+
};
|
|
14
|
+
export declare function parseCssGradient(css: unknown): Gradient | null;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2026 Xue Studios LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
const SIDES = {
|
|
7
|
+
"to top": 0,
|
|
8
|
+
"to right": 90,
|
|
9
|
+
"to bottom": 180,
|
|
10
|
+
"to left": 270,
|
|
11
|
+
"to top right": 45,
|
|
12
|
+
"to bottom right": 135,
|
|
13
|
+
"to bottom left": 225,
|
|
14
|
+
"to top left": 315,
|
|
15
|
+
};
|
|
16
|
+
const COLOR = /^(#[0-9a-f]{3,8}|(?:rgb|rgba|hsl|hsla)\([^()]*\)|[a-z]+)$/i;
|
|
17
|
+
/** Splits on the commas that are not inside parentheses. */
|
|
18
|
+
function splitTopLevel(text) {
|
|
19
|
+
const parts = [];
|
|
20
|
+
let depth = 0;
|
|
21
|
+
let start = 0;
|
|
22
|
+
for (let i = 0; i < text.length; i++) {
|
|
23
|
+
const c = text[i];
|
|
24
|
+
if (c === "(")
|
|
25
|
+
depth++;
|
|
26
|
+
else if (c === ")")
|
|
27
|
+
depth--;
|
|
28
|
+
else if (c === "," && depth === 0) {
|
|
29
|
+
parts.push(text.slice(start, i).trim());
|
|
30
|
+
start = i + 1;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
parts.push(text.slice(start).trim());
|
|
34
|
+
return parts;
|
|
35
|
+
}
|
|
36
|
+
function parseStop(text) {
|
|
37
|
+
const match = /^(.*?)(?:\s+(-?[\d.]+)%)?$/.exec(text);
|
|
38
|
+
if (!match)
|
|
39
|
+
return null;
|
|
40
|
+
const color = match[1].trim();
|
|
41
|
+
if (!COLOR.test(color))
|
|
42
|
+
return null;
|
|
43
|
+
if (match[2] === undefined)
|
|
44
|
+
return { color };
|
|
45
|
+
const at = Number(match[2]) / 100;
|
|
46
|
+
return Number.isFinite(at) ? { color, at: Math.min(1, Math.max(0, at)) } : null;
|
|
47
|
+
}
|
|
48
|
+
export function parseCssGradient(css) {
|
|
49
|
+
if (typeof css !== "string")
|
|
50
|
+
return null;
|
|
51
|
+
const match = /^\s*(linear|radial|conic)-gradient\((.*)\)\s*$/is.exec(css);
|
|
52
|
+
if (!match)
|
|
53
|
+
return null;
|
|
54
|
+
const type = match[1].toLowerCase();
|
|
55
|
+
const parts = splitTopLevel(match[2]);
|
|
56
|
+
if (!parts || parts.some((p) => p === ""))
|
|
57
|
+
return null;
|
|
58
|
+
let angle;
|
|
59
|
+
const head = parts[0].toLowerCase();
|
|
60
|
+
const degrees = /^(?:from\s+)?(-?[\d.]+)deg$/.exec(head);
|
|
61
|
+
if (degrees) {
|
|
62
|
+
angle = Number(degrees[1]);
|
|
63
|
+
parts.shift();
|
|
64
|
+
}
|
|
65
|
+
else if (head in SIDES) {
|
|
66
|
+
angle = SIDES[head];
|
|
67
|
+
parts.shift();
|
|
68
|
+
}
|
|
69
|
+
else if (type === "radial" && /^(circle|ellipse)\b/.test(head)) {
|
|
70
|
+
parts.shift();
|
|
71
|
+
}
|
|
72
|
+
const stops = parts.map(parseStop);
|
|
73
|
+
if (stops.length < 2 || stops.some((s) => s === null))
|
|
74
|
+
return null;
|
|
75
|
+
const gradient = { type, stops: stops };
|
|
76
|
+
if (angle !== undefined && Number.isFinite(angle))
|
|
77
|
+
gradient.angle = angle;
|
|
78
|
+
return gradient;
|
|
79
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2026 Xue Studios LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
/** Declared in 1.x and dropped in 2.0: nobody wrote them, or they were CSS inside the file. */
|
|
7
|
+
export declare const RETIRED_STYLE_KEYS: readonly ["shader_fx", "outline", "verticalAlign"];
|
|
8
|
+
/** Carried by published files without being in the 1.x contract. Each one is converted. */
|
|
9
|
+
export declare const UNDECLARED_STYLE_KEYS: readonly ["geoType", "childIds", "parallax", "sceneLoop", "loopDepth", "svgLayers", "borderColor", "borderWidth", "letterSpacing", "bold", "italic", "underline", "color", "backgroundFit", "backgroundGenerative", "backgroundPatternType", "backgroundPatternDirection", "backgroundPatternScale", "backgroundPatternSpeed"];
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2026 Xue Studios LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
// The 1.x style keys that need saying out loud: the ones 2.0 drops on purpose,
|
|
7
|
+
// and the ones real files carry although the 1.x contract never declared them.
|
|
8
|
+
/** Declared in 1.x and dropped in 2.0: nobody wrote them, or they were CSS inside the file. */
|
|
9
|
+
export const RETIRED_STYLE_KEYS = ["shader_fx", "outline", "verticalAlign"];
|
|
10
|
+
/** Carried by published files without being in the 1.x contract. Each one is converted. */
|
|
11
|
+
export const UNDECLARED_STYLE_KEYS = [
|
|
12
|
+
"geoType",
|
|
13
|
+
"childIds",
|
|
14
|
+
"parallax",
|
|
15
|
+
"sceneLoop",
|
|
16
|
+
"loopDepth",
|
|
17
|
+
"svgLayers",
|
|
18
|
+
"borderColor",
|
|
19
|
+
"borderWidth",
|
|
20
|
+
"letterSpacing",
|
|
21
|
+
"bold",
|
|
22
|
+
"italic",
|
|
23
|
+
"underline",
|
|
24
|
+
"color",
|
|
25
|
+
"backgroundFit",
|
|
26
|
+
"backgroundGenerative",
|
|
27
|
+
"backgroundPatternType",
|
|
28
|
+
"backgroundPatternDirection",
|
|
29
|
+
"backgroundPatternScale",
|
|
30
|
+
"backgroundPatternSpeed",
|
|
31
|
+
];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2026 Xue Studios LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { type DraftLayer, type UpgradeContext, type V1Slot } from "./context.js";
|
|
7
|
+
export declare function convertMask(ctx: UpgradeContext, slot: V1Slot, layer: DraftLayer): void;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2026 Xue Studios LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { asObject } from "./context.js";
|
|
7
|
+
import { isColor } from "./paints.js";
|
|
8
|
+
const SHAPES = { rectangle: { kind: "rect" }, circle: { kind: "ellipse" }, line: { kind: "line" } };
|
|
9
|
+
export function convertMask(ctx, slot, layer) {
|
|
10
|
+
const { style } = slot;
|
|
11
|
+
const mode = ctx.take(style, "maskMode");
|
|
12
|
+
const feather = ctx.take(style, "maskFeather");
|
|
13
|
+
const coverage = ctx.take(style, "maskCoverage");
|
|
14
|
+
const shape = ctx.take(style, "maskShape");
|
|
15
|
+
const path = ctx.take(style, "maskSvgPath");
|
|
16
|
+
const cuts = ctx.take(style, "cuts");
|
|
17
|
+
const bgLiteral = ctx.take(style, "maskBgColor");
|
|
18
|
+
const bgRole = ctx.take(style, "maskBgColorRole");
|
|
19
|
+
const strokeLiteral = ctx.take(style, "maskStrokeColor");
|
|
20
|
+
const strokeRole = ctx.take(style, "maskStrokeColorRole");
|
|
21
|
+
const strokeWidth = ctx.take(style, "maskStrokeWidth");
|
|
22
|
+
// `maskCoverage: "canvas"` and `maskInvert: false` travel on every layer of
|
|
23
|
+
// 1.x; they only mean something on a mask.
|
|
24
|
+
// The player never drew an inverted mask, on a mask or anywhere else.
|
|
25
|
+
ctx.take(style, "maskInvert");
|
|
26
|
+
if (slot.type !== "mask")
|
|
27
|
+
return;
|
|
28
|
+
// Ruling (13 Nov): what the 1.x player drew wins.
|
|
29
|
+
const mask = {};
|
|
30
|
+
const cutout = mode === "cutout";
|
|
31
|
+
if (cutout)
|
|
32
|
+
mask.mode = "cutout";
|
|
33
|
+
if (typeof feather === "number" && feather > 0)
|
|
34
|
+
mask.feather = feather;
|
|
35
|
+
// It covered the whole canvas unless told to stay in its own box.
|
|
36
|
+
if (coverage === "container")
|
|
37
|
+
mask.scope = "group";
|
|
38
|
+
layer.mask = mask;
|
|
39
|
+
// The figure: a drawn path only when no named shape says otherwise; a circle when nothing does.
|
|
40
|
+
const name = typeof shape === "string" && shape ? shape : typeof style.geoShape === "string" ? style.geoShape : undefined;
|
|
41
|
+
const d = typeof path === "string" && path ? path : typeof style.svgPath === "string" && style.svgPath ? style.svgPath : undefined;
|
|
42
|
+
if (d && (!name || name === "custom"))
|
|
43
|
+
layer.geometry = { kind: "paths", viewBox: [0, 0, 100, 100], paths: [{ d }] };
|
|
44
|
+
else if (name && name !== "custom")
|
|
45
|
+
layer.geometry = SHAPES[name] ?? { kind: "preset", name };
|
|
46
|
+
else
|
|
47
|
+
layer.geometry = { kind: "ellipse" };
|
|
48
|
+
// Extra holes cut in the mask, each with its own box.
|
|
49
|
+
if (Array.isArray(cuts) && cuts.length > 0) {
|
|
50
|
+
layer.extensions = { ...layer.extensions, studio: { ...asObject(layer.extensions?.studio), maskCuts: cuts } };
|
|
51
|
+
}
|
|
52
|
+
// Only a window paints: its frame, and an outline over the silhouette, each with the player's own default colour.
|
|
53
|
+
if (cutout)
|
|
54
|
+
return;
|
|
55
|
+
const color = (role, literal, fallback) => {
|
|
56
|
+
const value = isColor(literal) ? literal : fallback;
|
|
57
|
+
return typeof role === "string" && ctx.hasRole(role) ? { var: role, fallback: value } : value;
|
|
58
|
+
};
|
|
59
|
+
layer.fills = [{ kind: "color", value: color(bgRole || style.fillColorRole, bgLiteral, "#38BDF8") }];
|
|
60
|
+
delete layer.strokes;
|
|
61
|
+
if (typeof strokeWidth === "number" && strokeWidth > 0) {
|
|
62
|
+
layer.strokes = [{ paint: { kind: "color", value: color(strokeRole || style.strokeColorRole, strokeLiteral, "#FFFFFF") }, width: strokeWidth }];
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2026 Xue Studios LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import type { Paint } from "../schema.js";
|
|
7
|
+
import { type DraftLayer, type UpgradeContext, type V1Object, type V1Slot } from "./context.js";
|
|
8
|
+
export type ColorValue = string | {
|
|
9
|
+
var: string;
|
|
10
|
+
fallback?: string;
|
|
11
|
+
};
|
|
12
|
+
export declare const isColor: (value: unknown) => value is string;
|
|
13
|
+
/**
|
|
14
|
+
* A colour and its role. A known role (a palette's, or one of the dynamic roles
|
|
15
|
+
* a host page can set) becomes a binding that keeps the literal as its fallback,
|
|
16
|
+
* which is what 1.x painted: `var(--oim-color-<role>, <literal>)`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function colorOf(ctx: UpgradeContext, owner: V1Object, key: string, roleKey?: string): ColorValue | undefined;
|
|
19
|
+
export declare function convertPaints(ctx: UpgradeContext, slot: V1Slot, layer: DraftLayer): void;
|
|
20
|
+
/** The background of the canvas, which 1.x kept in some twenty undeclared root keys. */
|
|
21
|
+
export declare function canvasFills(ctx: UpgradeContext, meta: V1Object): Paint[];
|